@helpai/elements 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1001 @@
1
+ # Configuration reference
2
+
3
+ Every option you can pass to `init(...)` / `mount(...)` / set via
4
+ `data-*` attributes / set via web-component attributes.
5
+
6
+ Group-by-group walkthrough with realistic examples. For an at-a-glance
7
+ lookup, see [API reference](./api-reference.md).
8
+
9
+ ---
10
+
11
+ ## How options arrive
12
+
13
+ Options resolve in this order (highest priority wins):
14
+
15
+ 1. **Options you pass to `init()`** — always win.
16
+ 2. **Server-pushed settings** — your Help AI dashboard settings for this
17
+ deployment. Fill in anything you left unset.
18
+ 3. **Built-in defaults** — sensible fallbacks shipped with the widget.
19
+
20
+ This means you can:
21
+
22
+ - Hardcode `publicKey` in code, tune the rest from the dashboard.
23
+ - Ship all config in `init()` and ignore the dashboard.
24
+ - Override a specific field (e.g., force `theme: "dark"`) while letting
25
+ the dashboard control everything else.
26
+
27
+ ### Canonical option shape
28
+
29
+ Embed identity, routing, context, endpoint overrides, storage, and callbacks stay
30
+ at the top level. Serializable widget settings are grouped by ownership:
31
+
32
+ | Section | Fields described in this guide |
33
+ | -------------- | ------------------------------------------------------------------------------------ |
34
+ | `presentation` | `mode`, `iframe`, `position`, `size` |
35
+ | `behavior` | `startMinimized`, `responseMode`, transcript visibility, feedback, suggestion policy |
36
+ | `header` | `actions` |
37
+ | `composer` | `sendButton`, `attachments` |
38
+ | `feedback` | `sound`, `haptics` |
39
+ | `i18n` | `locale`, `defaultLocale`, `availableLocales`, `strings` |
40
+ | `footer` | `composerDisclaimer`, `poweredBy` |
41
+
42
+ The flat HTML attributes remain intentionally short (`data-mode`, `data-actions`,
43
+ and so on); the attribute parser maps them into this nested JavaScript shape.
44
+
45
+ ---
46
+
47
+ ## Required
48
+
49
+ ### `publicKey`
50
+
51
+ `string` · required for authenticated browser deployments
52
+
53
+ Your deployment's public key from the Help AI dashboard. Looks like
54
+ `agent_pk_...`.
55
+
56
+ ```ts
57
+ init({ publicKey: 'agent_pk_abc123...', aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000' });
58
+ ```
59
+
60
+ The public key authorizes the public widget surface. Pair it with that same
61
+ deployment's `aiAgentDeploymentId`; the backend requires both values to match.
62
+ Intentional guest mode omits the key but still supplies the deployment ID.
63
+ There is no per-end-user token — see
64
+ [`userContext`](#usercontext) below.
65
+
66
+ ### `aiAgentDeploymentId`
67
+
68
+ `string` · required for browser deployments
69
+
70
+ The deployment UUID from the same Dashboard → Deployments install panel as the
71
+ public key. It selects the exact agent/configuration and acts as a
72
+ defense-in-depth match for authenticated mounts. Send it on every browser
73
+ mount; also send the public key unless guest mode is intentional.
74
+
75
+ ---
76
+
77
+ ## Identity + routing
78
+
79
+ ### `widgetId`
80
+
81
+ `string` · default: `"default"`
82
+
83
+ A name you pick for this widget instance. Matters when you run more
84
+ than one widget on a page — each widgetId gets its own chat thread,
85
+ settings, and storage.
86
+
87
+ ```ts
88
+ init({ widgetId: 'support', publicKey: SUPPORT_KEY, aiAgentDeploymentId: SUPPORT_DEPLOYMENT_ID });
89
+ init({ widgetId: 'sales', publicKey: SALES_KEY, aiAgentDeploymentId: SALES_DEPLOYMENT_ID });
90
+ ```
91
+
92
+ See [Recipes § Multiple widgets](./recipes.md#multiple-widgets-on-one-page).
93
+
94
+ ### `baseUrl`
95
+
96
+ `string` · default: `https://help.ai`
97
+
98
+ The MAIN site origin the widget calls — the API modules derive from it
99
+ (agent API at `${baseUrl}/api/agent`, data API at `${baseUrl}/api/data`).
100
+ Override if you use:
101
+
102
+ - A custom domain (`your-company.com`).
103
+ - A local dev backend.
104
+
105
+ ### `userContext`
106
+
107
+ `object | undefined`
108
+
109
+ Host-asserted information about the end user, passed to the AI as
110
+ **context only — never an authentication credential.** The backend does
111
+ not register or authenticate these users. Optional — omit it for
112
+ anonymous chats. Recommended for logged-in users so the AI has context.
113
+
114
+ ```ts
115
+ init({
116
+ publicKey: 'agent_pk_...',
117
+ aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000',
118
+ userContext: {
119
+ id: 'user_42', // your user id
120
+ email: 'jane@help.ai',
121
+ name: 'Jane Doe',
122
+ plan: 'pro',
123
+ role: 'admin',
124
+ phone: '+15551234567',
125
+ seats: 12, // arbitrary custom scalar field
126
+ },
127
+ });
128
+ ```
129
+
130
+ A flat object. Recognised fields (all optional):
131
+
132
+ - `id` — your user's stable identifier.
133
+ - `email` — for personalization.
134
+ - `name` — for personalization (also drives the Home tab greeting,
135
+ e.g. "Hi Jane 👋").
136
+ - `plan` — subscription / pricing tier (e.g. `"pro"`).
137
+ - `role` — the user's role on your site (e.g. `"admin"`).
138
+ - `phone` — phone number.
139
+
140
+ Plus any arbitrary custom scalar fields (`string | number | boolean`) —
141
+ account age, feature flags, etc.
142
+
143
+ Because this is untrusted external input, it is sanitized client-side
144
+ before it leaves the page: non-scalar values are dropped, reserved keys
145
+ (`visitorId`, `conversationId`, `conversationId`, `jwt`, `token`, `authorization`,
146
+ `password`) are stripped, a malformed `email` is dropped, strings are
147
+ trimmed and capped at 1024 chars, max 50 keys. Sanitization warns to the
148
+ debug log and never throws.
149
+
150
+ > **This is YOUR site's logged-in user — not the widget's own visitor.**
151
+ > The widget independently mints and persists an anonymous
152
+ > `visitorId` / `conversationId` for the device; `userContext` never overrides
153
+ > those. Setting `userContext` simply attaches your context to the same
154
+ > visitor.
155
+
156
+ ### `pageContext`
157
+
158
+ `object | undefined`
159
+
160
+ Host-asserted context about the page/visit (separate from `userContext`),
161
+ so the AI can adapt to where the visitor is — a pricing visitor is not a
162
+ docs reader is not a help-desk ticket.
163
+
164
+ ```ts
165
+ init({
166
+ publicKey: 'agent_pk_...',
167
+ aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000',
168
+ pageContext: {
169
+ area: 'pricing', // host-defined surface
170
+ path: '/pricing/enterprise',
171
+ title: 'Enterprise plans',
172
+ // url auto-filled from location.href when omitted
173
+ },
174
+ });
175
+ ```
176
+
177
+ Recognised fields (all optional):
178
+
179
+ - `area` — host-defined surface the visitor is on. Free-form string;
180
+ suggested values: `home`, `docs`, `help-desk`, `support`, `pricing`,
181
+ `checkout`, `orders`, `account`, `blog` (any string accepted).
182
+ - `url` — full page URL. Auto-filled from the host page's
183
+ `location.href` when omitted.
184
+ - `path` — page path, e.g. `/pricing/enterprise`.
185
+ - `title` — page title.
186
+
187
+ Plus arbitrary custom scalar fields. Sanitized client-side with the same
188
+ rules as `userContext`.
189
+
190
+ > **On the wire:** `userContext` + `pageContext` are bundled into one
191
+ > `context` field — `base64url(JSON.stringify({ user, page }))` — sent on
192
+ > **every** request (body for POSTs, `?context=` for GETs), so the backend
193
+ > always has the visitor's latest context as they navigate. base64url is
194
+ > encoding, **not encryption** (the transport is already TLS); it just keeps
195
+ > PII out of plaintext access logs / the devtools network tab.
196
+
197
+ ### Setting context after login / on navigation
198
+
199
+ In a typical SPA the visitor is anonymous on first load and logs in
200
+ later. Update context dynamically via the instance handle. The new context
201
+ rides the **next** request automatically (no reconnect) — and a
202
+ `setUserContext` identity change additionally re-personalizes the greeting,
203
+ keeping the **same** visitor/conversation so the conversation is continuous:
204
+
205
+ ```ts
206
+ const widget = HelpAI.init({ publicKey: 'agent_pk_...', aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000' });
207
+
208
+ // after your app authenticates the user:
209
+ widget.setUserContext({
210
+ id: 'user_42',
211
+ email: 'jane@help.ai',
212
+ name: 'Jane Doe',
213
+ plan: 'pro',
214
+ });
215
+
216
+ // on SPA navigation:
217
+ widget.setPageContext({ area: 'checkout', path: '/checkout' });
218
+
219
+ // on logout:
220
+ widget.clearUserContext();
221
+ ```
222
+
223
+ You can also seed context at load time via `data-user-*` /
224
+ `data-page-*` tag attributes — see [Installation](./installation.md) and
225
+ the framework recipes in [`frameworks.md`](./frameworks.md).
226
+
227
+ ---
228
+
229
+ ## Rendering
230
+
231
+ ### `presentation.mode`
232
+
233
+ `"floating" | "inline" | "standalone" | "modal" | "drawer" | "page"` · default: `"floating"`
234
+
235
+ How the widget renders on the page.
236
+
237
+ - **`"floating"`** (default) — floating chat bubble in a corner.
238
+ Clicking opens the panel. Best for marketing sites, support chat.
239
+ - **`"inline"`** — a block element that fills its parent container. No
240
+ bubble, no popover. Best for in-app assistants, sidebar chats.
241
+ - **`"standalone"`** — full viewport. The dedicated chat tab; renders
242
+ the full module surface (no sidebar).
243
+ - **`"modal"`** — a centered dialog over a backdrop. The host opens it
244
+ (no launcher); call `open()` from your own trigger.
245
+ - **`"drawer"`** — docks to a screen edge; the launcher becomes a
246
+ vertical edge tab.
247
+ - **`"page"`** — full-viewport split: a conversation **sidebar** plus
248
+ the module surface in the main area.
249
+
250
+ `target` controls where every mode's shadow host is inserted. It is most
251
+ important for `inline` / `standalone` / `page`; overlay modes remain
252
+ viewport-positioned even when their host is inserted under a custom target.
253
+ See `../features/modes.md` for the full behavior matrix.
254
+
255
+ ```ts
256
+ init({ presentation: { mode: 'inline' }, target: document.getElementById('chat')! });
257
+ ```
258
+
259
+ ### `target`
260
+
261
+ `HTMLElement | undefined`
262
+
263
+ Where to insert the widget's shadow host. Recommended for `inline` /
264
+ `standalone` / `page` modes. Floating, drawer, and modal hosts also use
265
+ it, while their panels remain viewport-positioned. Defaults to `<body>`.
266
+
267
+ ### `presentation.iframe`
268
+
269
+ `boolean` · default: `false`
270
+
271
+ Wrap the widget in a same-origin iframe for strict JS + CSS isolation.
272
+ Useful when the host page has aggressive global scripts that mangle
273
+ `window.*` or inject hostile CSS.
274
+
275
+ ```ts
276
+ init({ presentation: { mode: 'floating', iframe: true }, publicKey: 'agent_pk_...', aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000' });
277
+ ```
278
+
279
+ Composes with any `mode`. Default is `false` — shadow DOM alone is
280
+ enough for 95% of deployments. [Security § Iframe isolation](./security-privacy.md#iframe-isolation).
281
+
282
+ ### `presentation.position`
283
+
284
+ `"bottom-right" | "bottom-left" | "top-right" | "top-left"` · default: `"bottom-right"`
285
+
286
+ Launcher corner. Only applies in `floating` mode.
287
+
288
+ ```ts
289
+ init({ presentation: { position: 'bottom-left' } });
290
+ ```
291
+
292
+ ### `behavior.startMinimized`
293
+
294
+ `boolean` · default: `true`
295
+
296
+ Whether the floating panel starts closed (showing only the launcher).
297
+ Only applies in `floating` mode.
298
+
299
+ ```ts
300
+ // Start open on every fresh page load
301
+ init({ behavior: { startMinimized: false } });
302
+ ```
303
+
304
+ User's last open/close choice is remembered per device — so even with
305
+ `behavior.startMinimized: false`, closing the widget and reloading keeps it
306
+ closed.
307
+
308
+ ---
309
+
310
+ ## Theming
311
+
312
+ ### `theme`
313
+
314
+ `"auto" | "light" | "dark" | ThemeOverrides` · default: `"auto"`
315
+
316
+ Three forms:
317
+
318
+ **1. Preset mode:**
319
+
320
+ ```ts
321
+ init({ theme: 'auto' }); // follows OS prefers-color-scheme
322
+ init({ theme: 'light' }); // force light
323
+ init({ theme: 'dark' }); // force dark
324
+ ```
325
+
326
+ **2. Color overrides (stays in auto mode):**
327
+
328
+ ```ts
329
+ init({
330
+ theme: {
331
+ accent: '#ff3e00', // primary brand color
332
+ accentText: '#ffffff', // text on the accent color
333
+ radius: '12px', // corner rounding
334
+ fontFamily: 'Inter, system-ui, sans-serif',
335
+ },
336
+ });
337
+ ```
338
+
339
+ **3. Both at once** — not supported in one call, but users can pick a
340
+ mode via the header picker regardless of palette overrides.
341
+
342
+ End users can flip the theme via the header picker. Their choice is
343
+ persisted per device + synced cross-device.
344
+
345
+ Full customization guide: [Theming](./theming.md).
346
+
347
+ ---
348
+
349
+ ## Sizing
350
+
351
+ ### `presentation.size`
352
+
353
+ `SizeOptions | undefined`
354
+
355
+ Control the panel's dimensions across three tiers:
356
+
357
+ ```ts
358
+ init({
359
+ presentation: {
360
+ size: {
361
+ // Normal tier (default panel size)
362
+ width: '420px',
363
+ height: '640px',
364
+
365
+ // Expanded tier (when user clicks the ⤢ button)
366
+ expanded: { width: '80vw', height: '80vh' },
367
+
368
+ // User drag-resize
369
+ resize: {
370
+ enabled: true,
371
+ minWidth: '360px',
372
+ maxWidth: '900px',
373
+ minHeight: '480px',
374
+ maxHeight: '90vh',
375
+ },
376
+
377
+ // First-render pick
378
+ initialSize: 'auto', // auto / normal / expanded / fullscreen
379
+ autoSizeBreakpoint: 900, // "auto" → expanded if viewport ≥ 900px
380
+ },
381
+ },
382
+ });
383
+ ```
384
+
385
+ ### Size tiers
386
+
387
+ - **Normal** — `width`/`height` or mode-specific CSS defaults.
388
+ - **Expanded** — ⤢ header button, configurable dimensions.
389
+ - **Fullscreen** — ⛶ header button, always 100vw × 100vh.
390
+
391
+ ### Drag-resize
392
+
393
+ `presentation.size.resize.enabled: true` shows a corner grip on the panel. Users drag
394
+ it to resize; dimensions persist per device + sync cross-device.
395
+ `presentation.size.resize.minWidth` etc. clamp the drag range.
396
+
397
+ ### `presentation.size.initialSize`
398
+
399
+ Which tier to open at on the user's **first** mount. After that, user
400
+ interactions own the size.
401
+
402
+ - `"normal"` — force the normal tier.
403
+ - `"expanded"` — open roomy.
404
+ - `"fullscreen"` — open full-screen.
405
+ - `"auto"` (default) — `fullscreen` below 640 px, `normal` from 640 px
406
+ to `autoSizeBreakpoint`, then `expanded` on wider viewports.
407
+
408
+ ---
409
+
410
+ ## Launcher
411
+
412
+ ### `launcher`
413
+
414
+ `LauncherOptions | undefined` · only applies in `presentation.mode: "floating"`
415
+
416
+ The FAB and its nudges.
417
+
418
+ ```ts
419
+ init({
420
+ launcher: {
421
+ variant: 'pill', // circle / pill / bar / minimal
422
+ size: 'md', // sm / md / lg
423
+ label: 'Ask us anything',
424
+ icon: 'chat', // chat / message / bubbles / spark / wand / bot / help / lifebuoy / headset / search / sparkles / concierge / wave / raw SVG
425
+ hidden: false, // true = no FAB
426
+
427
+ // Unified pre-engagement bubble (optional). Same component
428
+ // for greetings, nudges, onboarding tips — pick the
429
+ // visuals + dismissal lifecycle for the use case.
430
+ callout: {
431
+ text: '👋 Hi! Need any help?',
432
+ shape: 'pill', // pill / bubble / callout
433
+ position: 'auto', // auto / horizontal / vertical
434
+ delayMs: 1200,
435
+ autoDismissMs: 0,
436
+ animated: true,
437
+ persistent: true, // true (default) = re-show on every visit
438
+ // false = dismiss-once, hidden across visits
439
+ },
440
+ },
441
+ });
442
+ ```
443
+
444
+ Variants + callout fully explained in
445
+ [Theming § Launcher](./theming.md#launcher).
446
+
447
+ ### `launcher.hidden`
448
+
449
+ Hide the launcher FAB entirely. Use when you want to trigger the widget
450
+ from your own UI:
451
+
452
+ ```ts
453
+ const chat = init({ launcher: { hidden: true } });
454
+ document.getElementById('my-custom-chat-button').onclick = () => chat.open();
455
+ ```
456
+
457
+ ---
458
+
459
+ ## Header actions
460
+
461
+ ### `header.actions`
462
+
463
+ `ActionName[]` · per-mode defaults
464
+
465
+ The list is a flat enabled set. `history` and `close` render as dedicated
466
+ buttons; the rest live in the ⋯ menu in a fixed internal order. Unlisted actions
467
+ are hidden, so input order does not choose placement.
468
+
469
+ ```ts
470
+ init({
471
+ header: {
472
+ actions: ['theme', 'textSize', 'history', 'close', 'clear', 'fullscreen', 'popOut', 'sound', 'language'],
473
+ },
474
+ });
475
+ ```
476
+
477
+ Available actions:
478
+
479
+ | Name | What it does |
480
+ | ------------ | --------------------------------------------------------------------------- |
481
+ | `clear` | Start a new conversation (trash icon) |
482
+ | `expand` | Toggle normal ↔ expanded tier (⤢) |
483
+ | `fullscreen` | Toggle normal ↔ fullscreen (⛶) |
484
+ | `popOut` | Open the active conversation in `behavior.popOutUrl` |
485
+ | `sound` | Toggle notification sounds (switch-style) |
486
+ | `history` | Toggle the chat history pane |
487
+ | `language` | Open the language picker (renders as globe icon or inline rows in overflow) |
488
+ | `theme` | Open the theme picker (auto/light/dark) |
489
+ | `textSize` | Cycle the conversation text size |
490
+ | `close` | Close the panel (X) |
491
+
492
+ `popOut` renders only when `behavior.popOutUrl` is configured. The new tab
493
+ receives `chat`, `widgetId`, `public_key` (when present), and
494
+ `ai_agent_deployment_id` query parameters so it can resume the same thread.
495
+
496
+ Per-mode defaults and visibility rules are maintained in
497
+ Header actions.
498
+
499
+ > `header.actions` is always a complete replacement for the per-mode default;
500
+ > arrays are never merged. An explicit client list wins over the server list.
501
+
502
+ ---
503
+
504
+ ## Composer
505
+
506
+ ### `composer.sendButton`
507
+
508
+ Send-button chrome.
509
+
510
+ ```ts
511
+ init({
512
+ composer: {
513
+ sendButton: {
514
+ shape: 'pill', // circle / square / pill
515
+ icon: 'arrowUp', // arrowUp / paperPlane / send / chevron
516
+ variant: 'filled', // filled / outline / ghost
517
+ },
518
+ },
519
+ });
520
+ ```
521
+
522
+ 3 shapes × 4 icons × 3 variants = 36 combinations. Pick what matches
523
+ your brand.
524
+
525
+ ---
526
+
527
+ ## Footer
528
+
529
+ ### `footer.composerDisclaimer`
530
+
531
+ Small grey text below the textarea. Classic "AI can make mistakes"
532
+ pattern.
533
+
534
+ ```ts
535
+ init({ footer: { composerDisclaimer: 'AI can make mistakes. Check important info.' } });
536
+ ```
537
+
538
+ Empty / omitted = no disclaimer shown.
539
+
540
+ ### `footer.poweredBy`
541
+
542
+ Attribution row below the disclaimer. Defaults to the active
543
+ brand: `Powered by <BRAND.displayName>` linking to `BRAND.siteUrl`
544
+ (e.g. `Powered by Help AI` → `https://help.ai` for `@helpai/elements`).
545
+ Override fields per-deployment when you want different copy or to add a logo;
546
+ omit fields to inherit the brand defaults.
547
+
548
+ ```ts
549
+ init({
550
+ footer: {
551
+ poweredBy: {
552
+ text: 'Powered by Acme', // overrides brand default
553
+ href: 'https://acme.com', // overrides brand default
554
+ logoUrl: 'https://yoursite.com/helpai-logo.svg',
555
+ },
556
+ },
557
+ });
558
+ ```
559
+
560
+ To opt out of the attribution entirely, pass an empty `text` (and no
561
+ logo): `footer: { poweredBy: { text: "" } }` collapses the element.
562
+
563
+ ---
564
+
565
+ ## Attachments + features
566
+
567
+ ### `composer.attachments`
568
+
569
+ Client-side limits. Server enforces its own — these are to give users
570
+ fast feedback before upload.
571
+
572
+ ```ts
573
+ init({
574
+ composer: {
575
+ attachments: {
576
+ maxBytes: 10 * 1024 * 1024, // 10 MB, default
577
+ maxCount: 10, // default
578
+ accept: 'image/*,application/pdf', // comma-separated MIME globs
579
+ },
580
+ },
581
+ });
582
+ ```
583
+
584
+ ### `features.disableFileUpload`
585
+
586
+ `boolean` · default: `false`
587
+
588
+ Turn OFF file uploads — hide the paperclip button and reject drag-drop / paste.
589
+ Unset/`false` = enabled (default); set `true` to disable attachments entirely.
590
+
591
+ ### `features.enableOperatorRequest`
592
+
593
+ `boolean` · default: `false`
594
+
595
+ Opt IN **operator control** — exposes a "Talk to a person" control in the
596
+ composer and the connected-to-operator states (a status banner while the conversation
597
+ is routed to the operator, and operator reply bubbles). This is a **positive opt-in**
598
+ for a new capability (unlike the `disable*` flags): unset/`false` = off (default), `true` = on.
599
+
600
+ Every deployment holds one long-lived `GET /pai/stream-resume`; this flag does not gate
601
+ the stream. It only exposes the visitor's `request-operator` control. AI replies, operator
602
+ replies, and control-state changes continue to arrive on the resume channel and deduplicate
603
+ by message id whether the request control is visible or not. The composer stays open while
604
+ operator-routed so the visitor can keep typing. Operator requests require backend support.
605
+
606
+ ```ts
607
+ init({ features: { enableOperatorRequest: true } });
608
+ ```
609
+
610
+ ### `features.voice`
611
+
612
+ `"local" | "server" | "disabled"` · default: `"local"`
613
+
614
+ How voice input works:
615
+
616
+ - `"local"` — uses the browser's Web Speech API. Zero upload, free,
617
+ quality varies by browser.
618
+ - `"server"` — records audio via `MediaRecorder`, uploads to
619
+ `/pai/transcribe-audio`, receives text. Consistent quality, uses your
620
+ upload quota.
621
+ - `"disabled"` — hides the mic button entirely.
622
+
623
+ ## Messenger modules
624
+
625
+ ### `modules`
626
+
627
+ Turns the panel into an Intercom-style **messenger** with a bottom tab
628
+ bar. `modules` is an **ordered array of up to 4 tabs**; each tab picks a UI
629
+ `layout`, the content collections it shows (`contentCollectionIds`), and a
630
+ translatable `label`. The surface renders in
631
+ **every** mode (in `page` mode it fills the main area beside the sidebar). With nothing set, just the **chat** shows —
632
+ today's single-chat widget, no tab bar.
633
+
634
+ ```ts
635
+ init({
636
+ publicKey: 'agent_pk_...',
637
+ aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000',
638
+ modules: [
639
+ { label: 'tabHome', layout: 'home', contentCollectionIds: [GUIDES_ID], greetingText: 'Hi {name} 👋', brandName: 'Acme' }, // "Popular articles" = the collections' pinned items
640
+ { label: 'tabConversations', layout: 'chat' }, // the conversation
641
+ { id: 'help', label: 'tabHelp', layout: 'help', contentCollectionIds: [GUIDES_ID, BILLING_ID] },
642
+ { id: 'news', label: 'tabNews', layout: 'news', contentCollectionIds: [NEWS_ID] },
643
+ ],
644
+ });
645
+ ```
646
+
647
+ | Field | Required | Meaning |
648
+ | ---------------------- | -------- | -------------------------------------------------------------------------------------------------- |
649
+ | `label` | yes | Tab label — an i18n key (e.g. `tabHome`) or literal; translated via `i18n.strings`. |
650
+ | `layout` | yes | `chat` (the conversation), `home`, `help`, or `news`. |
651
+ | `contentCollectionIds` | no | Content collection ids (UUIDv7, max 20) this tab shows, in order; Help sections follow this order. |
652
+ | `id` | no | Stable id for nav + last-tab memory (defaults to the first `contentCollectionIds`, else `layout`). |
653
+ | home extras | no | `greetingText` (supports `{name}`), `hideSearchBar`, `brandName`, … (`home` layout only). |
654
+
655
+ - **Order is the array order** (left → right). One tab → no tab bar; zero
656
+ tabs (`[]`) → an empty state.
657
+ - The first tab is the first-open default; the widget then remembers the
658
+ user's last tab (per device).
659
+ - The deployment can also push `modules` from the dashboard via the
660
+ handshake (`config.modules`); your `init({ modules })` wins (replace-whole).
661
+
662
+ Each tab's content is fetched lazily from `GET /content` (data-api) on first open.
663
+ Full behavior + wire contract:
664
+ `features/messenger-modules.md`.
665
+
666
+ ---
667
+
668
+ ## Response mode
669
+
670
+ ### `behavior.responseMode`
671
+
672
+ `"streaming" | "buffered"` · default: `"streaming"`
673
+
674
+ - `"streaming"` — paint replies token-by-token as they arrive. Default.
675
+ - `"buffered"` — show a neutral loading indicator until the reply
676
+ finishes, then render it whole. The backend always streams; this is a
677
+ client-rendering choice. Useful when token-by-token feels stuttery.
678
+
679
+ ### `behavior.disableMessageFeedback`
680
+
681
+ `boolean` · default: `false`
682
+
683
+ Turn OFF the 👍/👎 feedback controls under each rateable reply (AI or operator) — unset/`false` shows them (default). While
684
+ shown, a choice fires the [`messageFeedback`](./events-and-hooks.md) event and is sent to the backend.
685
+
686
+ ```ts
687
+ init({ behavior: { disableMessageFeedback: true } }); // hide the controls
688
+ ```
689
+
690
+ ### `behavior.autoSendSuggestions`
691
+
692
+ `boolean` · default: `false`
693
+
694
+ Controls what tapping a suggestion chip does. Unset/`false` (default) **fills the composer** with the chip's
695
+ text so the visitor can edit before sending; `true` **sends** it immediately.
696
+
697
+ ```ts
698
+ init({ behavior: { autoSendSuggestions: true } }); // send on tap instead of filling
699
+ ```
700
+
701
+ ---
702
+
703
+ ## Internationalization
704
+
705
+ ### `i18n.locale`
706
+
707
+ `string | undefined`
708
+
709
+ Force a specific BCP-47 locale, overriding the visitor's browser
710
+ setting.
711
+
712
+ ```ts
713
+ init({ i18n: { locale: 'fr-CA' } });
714
+ ```
715
+
716
+ ### `i18n.defaultLocale`
717
+
718
+ `"auto" | string` · default: `"auto"`
719
+
720
+ Initial / fallback locale when the user hasn't picked one.
721
+
722
+ - `"auto"` — sniff `navigator.language`.
723
+ - Explicit tag (e.g., `"es-MX"`) — force that one.
724
+
725
+ ### `i18n.availableLocales`
726
+
727
+ `string[]` · optional
728
+
729
+ Locales offered in the language switcher. Omission defaults to the active
730
+ locale as a one-entry list; zero or one entries hide the picker.
731
+
732
+ ```ts
733
+ init({
734
+ i18n: {
735
+ availableLocales: ['en', 'fr', 'es', 'de'],
736
+ defaultLocale: 'auto',
737
+ },
738
+ });
739
+ ```
740
+
741
+ ### `i18n.strings`
742
+
743
+ Per-key overrides for any UI string. Two shapes:
744
+
745
+ **Flat** (applies to active locale):
746
+
747
+ ```ts
748
+ init({
749
+ i18n: {
750
+ strings: {
751
+ send: 'Go',
752
+ composerPlaceholder: 'Ask me anything…',
753
+ newConversation: 'Start fresh',
754
+ },
755
+ },
756
+ });
757
+ ```
758
+
759
+ **Nested** (per-locale):
760
+
761
+ ```ts
762
+ init({
763
+ i18n: {
764
+ strings: {
765
+ en: { send: 'Go' },
766
+ fr: { send: 'Envoyer' },
767
+ es: { send: 'Enviar' },
768
+ },
769
+ },
770
+ });
771
+ ```
772
+
773
+ Full key list: [i18n](./theming.md#internationalization) or
774
+ `src/i18n/strings.ts` in the source.
775
+
776
+ ---
777
+
778
+ ## Sound + haptics
779
+
780
+ ### `feedback.sound`
781
+
782
+ Notification sounds.
783
+
784
+ ```ts
785
+ init({
786
+ feedback: {
787
+ sound: {
788
+ enabled: true, // default
789
+ volume: 0.3, // 0..1, default 0.3
790
+ events: {
791
+ messageReceived: true, // built-in synth tone
792
+ messageSent: true,
793
+ error: 'https://cdn.your-site.com/error.mp3', // custom audio file
794
+ voiceStart: false, // silence this one
795
+ voiceStop: false,
796
+ },
797
+ },
798
+ },
799
+ });
800
+ ```
801
+
802
+ Per-event values:
803
+
804
+ - `true` — use the built-in synthesized tone.
805
+ - `false` — silence this event.
806
+ - `"url"` — URL to a custom audio file (decoded once + cached).
807
+
808
+ End users can mute via the sound action in the header. Their choice
809
+ is remembered.
810
+
811
+ ### `feedback.haptics`
812
+
813
+ Tactile feedback on touch devices.
814
+
815
+ ```ts
816
+ init({
817
+ feedback: {
818
+ haptics: {
819
+ enabled: true, // default: true on touch devices
820
+ events: {
821
+ messageSent: [6], // single 6ms tap
822
+ error: [10, 50, 10], // two taps with a 50ms pause
823
+ },
824
+ },
825
+ },
826
+ });
827
+ ```
828
+
829
+ Per-event values:
830
+
831
+ - `true` — default pattern.
832
+ - `false` — silence.
833
+ - number — single vibration of N ms.
834
+ - number[] — alternating `[vibrate, pause, vibrate, …]`.
835
+
836
+ iOS: WebKit only supports a single tick; arrays are flattened.
837
+
838
+ ---
839
+
840
+ ## Callbacks (shortcut for events)
841
+
842
+ Quick inline callbacks for common events. Same as calling `.on(...)`
843
+ on the returned instance.
844
+
845
+ ```ts
846
+ init({
847
+ publicKey: 'agent_pk_...',
848
+ aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000',
849
+ onMessage: (msg) => console.log(msg),
850
+ onOpen: () => console.log('opened'),
851
+ onClose: () => console.log('closed'),
852
+ onError: (err) => Sentry.captureException(err),
853
+ });
854
+ ```
855
+
856
+ For richer event handling, see [Events & hooks](./events-and-hooks.md).
857
+
858
+ ---
859
+
860
+ ## Storage
861
+
862
+ ### `storage`
863
+
864
+ `ChatWidgetOptions["storage"]`
865
+
866
+ Custom synchronous storage adapter. Default is `localStorage`. Swap for:
867
+
868
+ - `sessionStorage`.
869
+ - Encrypted wrapper.
870
+ - In-memory shim (for environments without `localStorage`).
871
+
872
+ ```ts
873
+ import type { ChatWidgetOptions } from '@helpai/elements';
874
+
875
+ type StorageAdapter = NonNullable<ChatWidgetOptions['storage']>;
876
+
877
+ const myStorage: StorageAdapter = {
878
+ get: (key) => sessionStorage.getItem(key),
879
+ set: (key, value) => sessionStorage.setItem(key, value),
880
+ remove: (key) => sessionStorage.removeItem(key),
881
+ };
882
+
883
+ init({ publicKey: 'agent_pk_...', aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000', storage: myStorage });
884
+ ```
885
+
886
+ The adapter also receives `draft.<conversationId>` keys containing exact
887
+ unsent textarea text and owns their storage, retention, and privacy behavior.
888
+ The widget itself does not include drafts in Help AI network requests before
889
+ Send. Use an encrypted adapter when same-origin plaintext storage is not
890
+ acceptable; an in-memory adapter disables reload restoration.
891
+
892
+ Full adapter contract: [Security & privacy § custom storage](./security-privacy.md#custom-storage).
893
+
894
+ ---
895
+
896
+ ## Runtime changes
897
+
898
+ You can change most options after mount via `chat.update(...)`:
899
+
900
+ ```ts
901
+ const chat = init({ publicKey: 'agent_pk_...', aiAgentDeploymentId: '01900000-0000-7000-8000-000000000000' });
902
+
903
+ // Later — flip to dark mode
904
+ chat.update({ theme: 'dark' });
905
+
906
+ // Or change the launcher label
907
+ chat.update({ launcher: { variant: 'pill', label: 'New message!' } });
908
+ ```
909
+
910
+ `update()` is a **shallow merge** at the top level. Nested objects are
911
+ replaced, not merged:
912
+
913
+ ```ts
914
+ chat.update({ presentation: { size: { expanded: { width: '800px' } } } });
915
+ // This replaces the whole `presentation` section — mode, iframe, and the other size fields are gone!
916
+
917
+ // Keep the current section in your application state and spread each nested level you preserve:
918
+ chat.update({
919
+ presentation: {
920
+ ...currentPresentation,
921
+ size: {
922
+ ...currentPresentation.size,
923
+ expanded: { width: '800px' },
924
+ },
925
+ },
926
+ });
927
+ ```
928
+
929
+ The `publicKey`, `widgetId`, `presentation.mode`, and `presentation.iframe` can't change at runtime
930
+ — they require a full remount (`destroy()` + `mount()`).
931
+
932
+ ---
933
+
934
+ ## Putting it all together — full example
935
+
936
+ ```ts
937
+ import { init } from '@helpai/elements';
938
+
939
+ const chat = init({
940
+ // Identity
941
+ publicKey: process.env.NEXT_PUBLIC_HELPAI_KEY!,
942
+ aiAgentDeploymentId: process.env.NEXT_PUBLIC_HELPAI_DEPLOYMENT_ID!,
943
+ widgetId: 'support',
944
+ userContext: { id: currentUser.id, email: currentUser.email, name: currentUser.name },
945
+ pageContext: { area: 'support', path: location.pathname },
946
+
947
+ // Presentation + behavior
948
+ presentation: {
949
+ mode: 'floating',
950
+ position: 'bottom-right',
951
+ size: {
952
+ expanded: { width: '720px', height: '85vh' },
953
+ resize: { enabled: true, minWidth: '360px', maxWidth: '900px' },
954
+ initialSize: 'auto',
955
+ autoSizeBreakpoint: 1024,
956
+ },
957
+ },
958
+ behavior: { startMinimized: true },
959
+ theme: { accent: '#ff3e00', radius: '12px' },
960
+
961
+ // Launcher
962
+ launcher: {
963
+ variant: 'pill',
964
+ label: 'Ask us anything',
965
+ icon: 'chat',
966
+ callout: { text: 'Hey there 👋', delayMs: 2000 },
967
+ },
968
+
969
+ // i18n
970
+ i18n: {
971
+ availableLocales: ['en', 'fr', 'es'],
972
+ defaultLocale: 'auto',
973
+ strings: {
974
+ en: { composerPlaceholder: 'Ask about anything…' },
975
+ fr: { composerPlaceholder: 'Demandez-moi…' },
976
+ },
977
+ },
978
+
979
+ // Feedback
980
+ feedback: { sound: { enabled: true, volume: 0.25 } },
981
+
982
+ // Footer
983
+ footer: {
984
+ composerDisclaimer: 'AI-generated answers may contain mistakes.',
985
+ poweredBy: { text: 'Powered by Help AI', href: 'https://help.ai' },
986
+ },
987
+
988
+ // Events
989
+ onMessage: (m) => analytics.track('chat_message', m),
990
+ onError: (err) => Sentry.captureException(err),
991
+ });
992
+ ```
993
+
994
+ ---
995
+
996
+ ## Not covered here
997
+
998
+ - **Events** → [Events & hooks](./events-and-hooks.md)
999
+ - **Theming deep-dive** → [Theming](./theming.md)
1000
+ - **Framework-specific wiring** → [Frameworks](./frameworks.md)
1001
+ - **Backend API** → Backend contract (internal)