Angular Elements build that publishes the @sinequa/agent library as browser
custom elements, so the new agent UI can be embedded in non-Angular hosts (a CMS, a React
app, a plain HTML page). It is the agent-library counterpart of sba/web-component,
which does the same for the legacy @sinequa/assistant library.
| Element | Wraps | Key properties | Notes |
|---|---|---|---|
<sq-agent> |
AgentInjector |
instanceId (required), chatId, activeAgent, staticFilters, preappliedFilters, userPrompt, enabled |
The main, self-contained chat (input, messages, tool cards, toolbars). activeAgent boots (or switches to) that agent; staticFilters is an invisible Enterprise Search scope; preappliedFilters seeds the Enterprise Search selection on every fresh session and agent change; userPrompt prefills the composer on fresh sessions. The two filter properties take a filter object or an array of filters and must be set as properties (an attribute string is ignored). The agent-lifecycle event reports the moments that re-time them. |
<sq-saved-chats> |
SavedChatComponent |
instanceId, activeChatId, searchText, readonly |
Saved-conversations list. Emits sq-chat-selected. |
<sq-saved-chats-dialog> |
SavedChatsDialogComponent |
instanceId, open |
Searchable modal. Set open = true to show; the element resets open to false on every close (Escape, outside click, close button, chat selection) and emits sq-dialog-closed. |
<sq-settings> |
SettingsComponent |
debug |
Appearance / language / debug / logout menu. Instance-agnostic. The logout entry dispatches agent-logout (see Events). |
All properties are set imperatively on the DOM element (e.g. el.instanceId = 'chatSearchInstance'),
which is how Angular Elements maps component inputs. Boolean inputs (enabled, readonly, open,
debug) also work as HTML attributes with the native convention: presence means true
(<sq-saved-chats readonly>), the string "false" means false.
npm ci --legacy-peer-deps
npm run buildOutput lands in dist/agent-element/browser/. The relevant artifacts for a host page are:
main.js: registers the custom elements (loaded as an ES module)polyfills.js: Angular polyfills (if emitted)styles.css: the compiled Tailwind + theme stylesheet (required for correct rendering)atomic.js: the@sinequa/atomicruntime SDK, copied by thepostbuildstep. Optional: the demo host does not use it (config/auth go through the bootstrap options); it is available for hosts that want to drive atomic directly (note: separate instance from the elements bundle)assets/: fonts, logos, and the Transloco translation files (assets/i18n/…)
outputHashing is disabled so filenames are stable and can be referenced directly by a host page.
Before serving, configure the demo for your backend:
- In
vite/vite.config.ts, setAPI_URLto your Sinequa backend (the proxy target for/api,/endpoints,/xdownload,/auth/redirect). - In
src/index.html, set the demo constants:APP_NAME: the Sinequa application name (must match the backend app).INSTANCE_ID: the agent instance id (a key in the app-customization "agents" JSON).STATIC_BEARER_TOKEN: a bearer token for local dev (exchanged for a CSRF web token). Leave empty to use the interactivelogin()/ OAuth flow instead.
cd vite && npm install && cd .. # one-time: install the Vite harness deps
npm startThis builds and then serves dist/agent-element/browser/ with Vite over HTTPS on
https://localhost:4200, proxying /api, /endpoints (SignalR websocket), /xdownload, and
/auth/redirect to the backend configured in vite/vite.config.ts
(defaults to http://localhost).
The agent library reads its runtime config from @sinequa/atomic's global config, and its
per-instance configuration from the Sinequa server's app-customization JSON.
Important: one atomic instance. The elements bundle (main.js) contains its own bundled copy
of @sinequa/atomic. It is a different module instance from the standalone atomic.js, with
independent global-config and token state. So the host must not call setGlobalConfig / login
on atomic.js and expect the elements to see it. Instead, the host passes its config to the
bootstrap, and the bundle configures + authenticates on its own instance.
main.ts does not auto-bootstrap; it exposes window.__bootstrapSinequaAgentElements(options) and
dispatches a sq-agent-elements-loaded event once ready. The bootstrap performs, in order:
setGlobalConfig → authenticate → createApplication → register elements.
The bootstrap is memoized: the first call wins and every later call returns the same promise (its options are ignored), so re-entrant hosts cannot re-authenticate or create a second Angular application. A rejected bootstrap clears the memo, so the host can retry after, e.g., a bad token. Loading two copies of the bundle on one page fails fast with a descriptive error.
bootstrapAgentElements(options) options:
| Option | Required | Purpose |
|---|---|---|
app |
yes | Sinequa application name (must match the backend app). |
token |
no | Static bearer token for local dev; exchanged for a CSRF web token. |
backendUrl |
no | Backend URL. Omit for same-origin (dev-server proxy) setups. |
oauthProvider / samlProvider |
no | Provider for the interactive login() flow (used when no token). |
useCredentials |
no | Send credentials with requests. |
Minimal host flow (see src/index.html for a complete example):
<script type="module">
// Wait for main.js to register the bootstrap, then run it.
if (!window.__bootstrapSinequaAgentElements) {
await new Promise(r => document.addEventListener('sq-agent-elements-loaded', r, { once: true }));
}
await window.__bootstrapSinequaAgentElements({ app: 'agent', token: '<bearer-token>' });
const agent = document.createElement('sq-agent');
agent.instanceId = 'chatSearchInstance';
document.body.appendChild(agent);
</script>app and instanceId must match the backend app and an entry in its app-customization "agents"
JSON, respectively. The host does not need to import atomic.js (the copied SDK bundle remains
available for hosts that want to drive atomic directly, but it is a separate instance from the
elements).
The Agent communicates with the host via bubbling DOM CustomEvents (there are no Angular
@Outputs). The demo host page re-implements the toast/clipboard UX that the Angular demo gets from
host directives by listening for these:
| Event | Direction | Detail |
|---|---|---|
agent-new-chat |
host → agent | { instanceId }: resets the conversation. Dispatch on document. |
agent-retry-connection |
host → agent | { instanceId }: soft reconnect. |
sq-chat-selected |
<sq-saved-chats> → host |
the selected SavedChat. Typically sets chatId on <sq-agent>. |
sq-dialog-closed |
<sq-saved-chats-dialog> → host |
no detail. Fired on every close; the element has already reset its own open property. |
agent-logout |
<sq-settings> → host |
no detail. The bundle clears the Sinequa session itself in response (not cancelable; best-effort server-side cookie deletion when useCredentials is true, so avoid hard-navigating synchronously); the host handles post-logout UX (redirect, messaging). |
agent-connection-lost / agent-reconnecting / agent-reconnected |
agent → host | { instanceId, … } connection lifecycle. |
agent-error |
agent → host | { id, error?, errorMessage? }. |
agent-saved-chat |
agent / <sq-saved-chats> → host |
{ id, instanceId, chatId?, error?, errorMessage? }. |
agent-lifecycle |
agent → host | { id, instanceId, … } session moments: NEW_CHAT_STARTED (chatId; the library has consumed preappliedFilters and userPrompt, clear userPrompt here for the next session), SAVED_CHAT_LOADING (chatId), AGENT_SWITCHED (agentName, previousAgentName?, requestedAgentName?, reason). The counterpart of the agent-new-chat / agent-switch-agent commands and of the activeAgent property. |
agent-switch-agent |
host → agent | { instanceId, agentName }: requests a switch (confirmed by agent-lifecycle AGENT_SWITCHED, refused on agent-error). Dispatch on document. |
sq-agent-elements-loaded |
bundle → host | no detail. Fired once at script load, when the bootstrap global is available. |
sinequa-set-language |
host → elements | { lang }: switches the UI language at runtime. |
sinequa-language-changed |
elements → host | { lang }: confirmation, fired on document after the active language actually changed (via the event above or the <sq-settings> language dialog). |
Translation files ship as build assets under assets/i18n/. The base language files
(en/fr/de/ja.json) are committed and hold the demo host page's own labels; the scoped
translations from @sinequa/agent and @sinequa/atomic-angular are extracted by the
prebuild / prewatch steps (transloco-scoped-libs, configured in
transloco.config.ts) and are git-ignored.
- Zoneless. The build has no
zone.jspolyfill and usesprovideZonelessChangeDetection(), matching the library's signal-based design. If custom elements fail to re-render, addzone.jstopolyfillsinangular.jsonand dropprovideZonelessChangeDetection()fromsrc/main.ts. - Light DOM. The elements render in the light DOM (no Shadow DOM); the emitted
styles.cssprovides the Tailwind utilities and theme variables the library templates rely on. - Theme. The host owns the light/dark theme: the elements follow the
darkclass on<html>and never apply the user's saved theme at startup. A pick made insq-settingsis saved and applied immediately, but it is only restored on reload if the host applies it itself.