@trillet-ai/web-sdk 1.9.2 → 1.11.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.
@@ -2,10 +2,110 @@ import * as React from 'react';
2
2
  import { TrilletRoomDetails } from '../server.js';
3
3
  import { T as Transcript } from '../TranscriptManager-Bh-JJm_m.js';
4
4
 
5
+ /**
6
+ * Built-in widget copy per language.
7
+ *
8
+ * Every visitor-facing string the widget renders on its own lives here, so a site in
9
+ * German, French or Italian gets a fully localised widget without setting a dozen
10
+ * text attributes. Explicit text attributes and the saved dashboard design still win
11
+ * over these defaults (see configFromElement).
12
+ */
13
+ declare const WIDGET_LANGUAGES: readonly ["en", "de", "fr", "it"];
14
+ type WidgetLanguage = (typeof WIDGET_LANGUAGES)[number];
15
+ interface WidgetCopy {
16
+ startCallText: string;
17
+ startChatText: string;
18
+ endCallText: string;
19
+ endChatText: string;
20
+ endConversationText: string;
21
+ messageText: string;
22
+ callLabel: string;
23
+ chatLabel: string;
24
+ switchToTextText: string;
25
+ switchToVoiceText: string;
26
+ listeningText: string;
27
+ speakingText: string;
28
+ expandText: string;
29
+ collapseText: string;
30
+ recaptchaText: string;
31
+ inputPlaceholder: string;
32
+ askAnything: string;
33
+ /** `{name}` is replaced with the agent or brand name. */
34
+ askNamed: string;
35
+ chooseModePrompt: string;
36
+ talkToUs: string;
37
+ connecting: string;
38
+ online: string;
39
+ callEnded: string;
40
+ chatEnded: string;
41
+ startNewChat: string;
42
+ backToChat: string;
43
+ /** `{name}` is replaced with the agent or brand name. */
44
+ chatWithNamed: string;
45
+ chat: string;
46
+ send: string;
47
+ close: string;
48
+ typing: string;
49
+ muteMic: string;
50
+ unmuteMic: string;
51
+ terms: string;
52
+ termsTitle: string;
53
+ termsAccept: string;
54
+ termsDecline: string;
55
+ feedbackQuestion: string;
56
+ feedbackThanks: string;
57
+ errorNotEnabled: string;
58
+ errorUnavailable: string;
59
+ errorTooMany: string;
60
+ errorGeneric: string;
61
+ feedbackGood: string;
62
+ feedbackBad: string;
63
+ openChat: string;
64
+ minimize: string;
65
+ typeInstead: string;
66
+ showConversation: string;
67
+ talkInstead: string;
68
+ }
69
+
5
70
  type WidgetVariant = 'compact' | 'expanded';
6
71
  type WidgetVariantInput = WidgetVariant | 'tiny' | 'full';
7
72
  type WidgetMode = 'voice' | 'text' | 'both';
8
73
  type WidgetPlacement = 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right';
74
+ type WidgetTheme = 'light' | 'dark';
75
+ /**
76
+ * The design saved in the Trillet dashboard (Widget designer), served by
77
+ * GET /v1/api/web-call/public/widget-config. Every key is optional; HTML attributes
78
+ * on the element always win over these, so an existing embed keeps rendering exactly
79
+ * as written.
80
+ */
81
+ type AvatarStyle = 'orb' | 'image' | 'initials';
82
+ interface RemoteWidgetConfig {
83
+ avatarStyle?: AvatarStyle | null;
84
+ orbColor1?: string | null;
85
+ orbColor2?: string | null;
86
+ backgroundColor?: string | null;
87
+ textColor?: string | null;
88
+ buttonTextColor?: string | null;
89
+ termsText?: string | null;
90
+ feedback?: 'none' | 'end' | null;
91
+ mode?: WidgetMode;
92
+ placement?: WidgetPlacement;
93
+ variant?: WidgetVariant;
94
+ theme?: WidgetTheme;
95
+ brandColor?: string | null;
96
+ brandName?: string | null;
97
+ brandLogo?: string | null;
98
+ avatar?: string | null;
99
+ title?: string | null;
100
+ launcherText?: string | null;
101
+ greeting?: string | null;
102
+ inputPlaceholder?: string | null;
103
+ startCallText?: string | null;
104
+ messageText?: string | null;
105
+ suggestedPrompts?: string[];
106
+ /** Widget UI language (en | de | fr | it). Absent: the host page's <html lang>. */
107
+ language?: string | null;
108
+ }
9
109
  interface WidgetBrand {
10
110
  logo?: string;
11
111
  primaryColor?: string;
@@ -19,9 +119,15 @@ interface WidgetConfig {
19
119
  agentId: string;
20
120
  signedUrlEndpoint?: string;
21
121
  workspaceId?: string;
122
+ /** API host override (whitelabel API domain, or a local backend in development). */
123
+ apiBase?: string;
124
+ /** Load the dashboard design on mount (default true; `remote-config="false"` opts out). */
125
+ remoteConfig: boolean;
22
126
  agentName?: string;
23
127
  callFlowName?: string;
24
128
  workspaceName?: string;
129
+ /** 'orb' (animated gradient, default), 'image' (avatar URL) or 'initials'. */
130
+ avatarStyle?: AvatarStyle;
25
131
  avatar?: string;
26
132
  /** Legacy single accent/orb color; alias of orbColor1. */
27
133
  orbColor?: string;
@@ -32,10 +138,16 @@ interface WidgetConfig {
32
138
  variant: WidgetVariant;
33
139
  placement: WidgetPlacement;
34
140
  dismissible: boolean;
141
+ /** Resolved UI language and its built-in copy (see ./i18n). */
142
+ language: WidgetLanguage;
143
+ copy: WidgetCopy;
35
144
  actionText?: string;
36
145
  startCallText: string;
37
146
  endCallText: string;
38
147
  messageText: string;
148
+ /** Mode "both" launcher: the two halves of the Call | Chat button. */
149
+ callLabel: string;
150
+ chatLabel: string;
39
151
  switchToTextText: string;
40
152
  switchToVoiceText: string;
41
153
  listeningText: string;
@@ -43,6 +155,20 @@ interface WidgetConfig {
43
155
  expandText: string;
44
156
  collapseText: string;
45
157
  recaptchaText: string;
158
+ /** Short line shown next to the closed launcher, and under the chat header. */
159
+ greeting?: string;
160
+ inputPlaceholder: string;
161
+ /** Tap-to-send starter questions, shown until the visitor sends a message. */
162
+ suggestedPrompts: string[];
163
+ theme: WidgetTheme;
164
+ /** Colour overrides on top of the theme. Button colour is brand.primaryColor. */
165
+ backgroundColor?: string;
166
+ textColor?: string;
167
+ buttonTextColor?: string;
168
+ /** Markdown the visitor must accept before their first conversation. */
169
+ termsText?: string;
170
+ /** 'end': ask for a thumbs up/down when a conversation ends. */
171
+ feedback: 'none' | 'end';
46
172
  mode: WidgetMode;
47
173
  variables?: Record<string, unknown>;
48
174
  maxCallDuration?: number;
@@ -63,8 +189,17 @@ interface WidgetConfig {
63
189
  interface TrilletWidgetProps {
64
190
  agentId: string;
65
191
  signedUrlEndpoint?: string;
66
- /** JS-only: invoked at call-start to mint room details (cannot be an HTML attribute). */
67
- getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
192
+ /**
193
+ * JS-only: invoked at call-start to mint room details (cannot be an HTML attribute).
194
+ * Receives the modality being started, so you can mint a voice or a text session.
195
+ */
196
+ getRoomDetails?: (context: {
197
+ mode: 'voice' | 'text';
198
+ }) => Promise<TrilletRoomDetails> | TrilletRoomDetails;
199
+ /** API host override (whitelabel API domain, or a local backend in development). */
200
+ apiBase?: string;
201
+ /** Load the design saved in the Trillet dashboard (default true). */
202
+ remoteConfig?: boolean;
68
203
  /** JS-only: static pre-minted room details. */
69
204
  roomDetails?: TrilletRoomDetails;
70
205
  workspaceId?: string;
@@ -87,6 +222,10 @@ interface TrilletWidgetProps {
87
222
  actionText?: string;
88
223
  startCallText?: string;
89
224
  endCallText?: string;
225
+ /** Label for ending a text chat (default from `language`, e.g. "End chat" / "Chat beenden"). */
226
+ endChatText?: string;
227
+ /** UI language for the built-in labels: en | de | fr | it. Default: the page's <html lang>. */
228
+ language?: string;
90
229
  /** Label for the text/chat entry point in mode="both" (default "Message"). */
91
230
  messageText?: string;
92
231
  switchToTextText?: string;
@@ -97,6 +236,13 @@ interface TrilletWidgetProps {
97
236
  collapseText?: string;
98
237
  /** Copy shown above the reCAPTCHA checkbox, when `recaptchaSiteKey` is set. */
99
238
  recaptchaText?: string;
239
+ /** Short line shown beside the closed launcher. */
240
+ greeting?: string;
241
+ /** Placeholder in the chat message box. */
242
+ inputPlaceholder?: string;
243
+ /** Tap-to-send starter questions for text chats. */
244
+ suggestedPrompts?: string[];
245
+ theme?: WidgetTheme;
100
246
  /** "voice" | "text" | "both" (multimodal, user-switchable). */
101
247
  mode?: WidgetMode;
102
248
  variables?: Record<string, unknown>;
@@ -128,6 +274,7 @@ interface TrilletWidgetProps {
128
274
  declare const TrilletWidget: React.FC<TrilletWidgetProps>;
129
275
 
130
276
  type ActiveMode = 'voice' | 'text';
277
+ type SessionMode = 'voice' | 'text' | 'multimodal';
131
278
  declare class TrilletWidgetElement extends HTMLElement {
132
279
  static get observedAttributes(): readonly string[];
133
280
  private root;
@@ -141,7 +288,16 @@ declare class TrilletWidgetElement extends HTMLElement {
141
288
  private display;
142
289
  private activeMode;
143
290
  private switching;
144
- getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
291
+ private remote;
292
+ private remoteDisplay;
293
+ private remoteLoadedFor;
294
+ private pendingMessage;
295
+ getRoomDetails?: (context: {
296
+ /** The side the conversation starts on. */
297
+ mode: ActiveMode;
298
+ /** Session type to mint: `multimodal` for mode="both" (type or talk). */
299
+ session: SessionMode;
300
+ }) => Promise<TrilletRoomDetails> | TrilletRoomDetails;
145
301
  roomDetails?: TrilletRoomDetails;
146
302
  private durationTimer;
147
303
  private remainingSeconds;
@@ -153,8 +309,19 @@ declare class TrilletWidgetElement extends HTMLElement {
153
309
  private container;
154
310
  constructor();
155
311
  connectedCallback(): void;
312
+ private refreshConfig;
313
+ /**
314
+ * Fetch the design saved in the dashboard. Best-effort: on any failure the widget
315
+ * keeps rendering from its attributes, exactly as before this existed.
316
+ */
317
+ private loadRemoteConfig;
156
318
  disconnectedCallback(): void;
157
319
  attributeChangedCallback(): void;
320
+ /**
321
+ * Send a chat message as the visitor (text sessions). Opens and starts the chat
322
+ * first when needed; the message is delivered as soon as the session connects.
323
+ */
324
+ sendMessage(text: string): Promise<void>;
158
325
  /**
159
326
  * Imperatively start a conversation. Primary headless API (convai-aligned).
160
327
  * @param modality - optional; only used in `mode="both"` to pick voice vs text.
@@ -166,11 +333,6 @@ declare class TrilletWidgetElement extends HTMLElement {
166
333
  startCall(): Promise<void>;
167
334
  /** @deprecated Use {@link endConversation}. Kept as a thin alias for back-compat. */
168
335
  endCall(): void;
169
- /**
170
- * Voice embeds run entirely on the floating control. Text and `both` still need
171
- * the conversation panel.
172
- */
173
- private isInlineVoice;
174
336
  /** The concrete modality to run for the current session (`both` -> activeMode). */
175
337
  private resolvedMode;
176
338
  /** Keep activeMode consistent with the configured mode. */
@@ -178,13 +340,22 @@ declare class TrilletWidgetElement extends HTMLElement {
178
340
  /** Tear down the current agent cleanly: detach listeners, end the call, drop the ref. */
179
341
  private teardownAgent;
180
342
  /**
181
- * Switch modality mid-session (mode="both"). Because the core binds `mode` at
182
- * construction, this ends the current `TrilletAgent` and constructs a fresh one in
183
- * the other modality, rejoining via the same credential path. Transcripts and the
184
- * duration timer are preserved across the switch; no lifecycle events fire (it's one
185
- * conversation from the consumer's perspective).
343
+ * Switch between typing and talking (mode="both"). Same session, same conversation:
344
+ * the SDK turns the mic on/off and asks the agent to turn its speech on/off. If the
345
+ * mic is refused, the conversation simply stays in text and says why.
186
346
  */
187
347
  private switchModality;
348
+ private pendingTimer;
349
+ /**
350
+ * Listening <-> Speaking flips several times a second at turn edges. Patch the few
351
+ * nodes that show it instead of re-rendering, which would rebuild (and flash) the UI.
352
+ */
353
+ private setSpeaking;
354
+ private lastView;
355
+ /** Send the message typed before the chat started (once). */
356
+ private flushPending;
357
+ private notice;
358
+ private switchingSide;
188
359
  private beginCall;
189
360
  private wireAgentEvents;
190
361
  private endLocalCall;
@@ -195,83 +366,132 @@ declare class TrilletWidgetElement extends HTMLElement {
195
366
  private dispatch;
196
367
  private applyTheme;
197
368
  private formatTime;
369
+ /** The line under the agent's name in the header. */
198
370
  private statusText;
199
371
  private renderStatus;
200
372
  private timerText;
373
+ /**
374
+ * Agent voice level (0..1) from the live audio. Written straight to a CSS variable
375
+ * on the host, so the presence ring moves with the real voice without re-rendering.
376
+ */
377
+ private setLevel;
378
+ private smoothedLevel;
201
379
  private render;
380
+ /** Avatar style: an explicit choice, else the image when one is set, else the orb. */
381
+ private avatarStyle;
382
+ /**
383
+ * The mark: who the visitor is talking to, as a small rounded tile. A gradient in
384
+ * the brand colours (default), the business's image, or initials. While the agent
385
+ * speaks on a call, the tile breathes with the voice level (--tw-level).
386
+ */
387
+ private buildAvatar;
388
+ /** The name shown to visitors: business name, else the agent/flow name. */
389
+ private speakerName;
390
+ /** Live voice level as five bars (heights follow --tw-level). */
391
+ private buildWave;
392
+ private iconButton;
393
+ private showTerms;
394
+ private pendingStart;
395
+ private callId;
396
+ private feedbackState;
397
+ /** Acceptance is remembered per agent and per version of the text. */
398
+ private termsKey;
399
+ private termsAccepted;
400
+ private termsAcceptedThisPage;
401
+ private renderTerms;
402
+ /** "How was this conversation?" thumbs, once, after a conversation ends. */
403
+ private renderFeedback;
404
+ /**
405
+ * The ask bar: the widget's resting state.
406
+ *
407
+ * [mark] Ask Firelink anything… (mic) (send)
408
+ *
409
+ * Input-first: typing + Enter opens the chat with that message already sent; the
410
+ * mic starts a call and the bar becomes the call bar. Voice-only shows "Talk to …"
411
+ * with a call button; chat-only drops the mic.
412
+ */
413
+ private renderCard;
414
+ private askFocused;
415
+ /** Suggested questions just above the ask bar while it has focus. */
416
+ private renderAskSuggestions;
202
417
  /**
203
- * Voice chrome: one floating control. Idle/ended starts the call. Connecting
204
- * shows progress on that same control. Live turns it into hang up and reflects
205
- * listening vs speaking. No panel.
418
+ * Open the panel. A text-only widget starts the chat straight away, so the agent's
419
+ * welcome is already there when the panel opens, like any website chat. `both`
420
+ * waits for the visitor to pick call or message.
206
421
  */
207
- private renderInlineVoice;
208
- private renderLauncher;
422
+ private openPanel;
209
423
  private renderPanel;
210
424
  /**
211
425
  * The header title identifying who the user is talking to. Each identity value is
212
426
  * code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
213
427
  * config value takes precedence over the corresponding backend `display.*` value
214
- * (which only arrives on `connected`), falling back to it when unset. Resolution:
215
- * effectiveAgent = config.agentName ?? display.agent_name
216
- * effectiveCallFlow = config.callFlowName ?? display.call_flow_name
217
- * effectiveWorkspace = config.workspaceName ?? display.workspace_name
218
- * title = effectiveAgent || effectiveCallFlow || effectiveWorkspace || ''
219
- * Because the overrides are static config, the title can render pre-call. Note:
220
- * `brand.name` is intentionally NOT part of this chain — it renders in the brand
221
- * slot only.
428
+ * (which only arrives on `connected`), falling back to it when unset. `brand.name`
429
+ * is intentionally NOT part of this chain; it renders as the status line pre-call.
222
430
  */
223
431
  private headerTitle;
224
432
  private renderHeader;
433
+ /** Start, call and gate screens centre a large avatar in the body. */
434
+ private bodyShowsLargeAvatar;
225
435
  /** True when a `both` widget is idle/ended with no modality chosen yet. */
226
436
  private isBothPreCall;
227
437
  /** True when a site key is configured and this session has not solved it yet. */
228
438
  private needsRecaptcha;
229
439
  /**
230
- * The pre-call gate shown in the panel: orb, prompt, the reCAPTCHA checkbox, and a
440
+ * The pre-call gate shown in the panel: prompt, the reCAPTCHA checkbox, and a
231
441
  * disabled start button. The button enables once the checkbox is solved.
232
442
  *
233
443
  * The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
234
444
  * shadow root (its anchor iframe never finishes initializing), so the actual widget
235
445
  * is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
236
446
  * to this slot. It therefore *displays* here inside the panel while its DOM home
237
- * stays in the light tree, where reCAPTCHA works. Verified via examples/recaptcha-
238
- * isolate.local.html (case C).
447
+ * stays in the light tree, where reCAPTCHA works.
239
448
  */
240
449
  private renderRecaptchaGate;
241
450
  /**
242
451
  * Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox
243
- * into it. The node is a child of the host element with `slot="recaptcha"`, so it is
244
- * projected into the gate's <slot>. Idempotent: every widget re-render recreates the
245
- * <slot> element, but this node (and its iframe) persists in the light DOM untouched,
246
- * so the checkbox is rendered exactly once and re-projects automatically.
452
+ * into it. Idempotent: every re-render recreates the <slot>, but this node (and its
453
+ * iframe) persists in the light DOM untouched, so the checkbox renders exactly once.
247
454
  */
248
455
  private ensureRecaptchaSlot;
249
456
  /** Remove the slotted light-DOM checkbox node. Safe to call when none exists. */
250
457
  private removeRecaptchaSlot;
251
458
  private renderBody;
252
- /** Build the animated gradient orb (or avatar image) reflecting the current state. */
253
- private buildOrb;
254
- /** Pre-call panel for mode="both": orb + "Start a call" (voice) and "Message" (text). */
459
+ /** Pre-call panel for mode="both": the visitor picks how to talk. */
255
460
  private renderBothEntry;
256
- /** Voice UI: orb + spoken status + timer + mic/end controls. Never a text input. */
461
+ /** Voice call: the agent's presence (ring follows their voice), status, controls. */
257
462
  private renderVoiceBody;
258
- /** Text/chat UI: conversation thread + message input. Never an orb or "listening" state. */
463
+ /** Text/chat UI: conversation thread + message input. */
259
464
  private renderTextBody;
260
- /** In mode="both" during a live session, a control to switch to the other modality. */
261
- private renderSwitchButton;
465
+ /** Starter questions, shown until the visitor has said something. */
466
+ private renderSuggestions;
262
467
  private renderControls;
468
+ /**
469
+ * The call bar. Resting (floating) it replaces the ask bar during a call; inside the
470
+ * chat panel it replaces the composer on the voice side of a type-or-talk chat.
471
+ *
472
+ * ||||| Speaking (mic) (💬 / ⌨) (end)
473
+ * Firelink · 0:42
474
+ */
475
+ private renderVoiceBar;
476
+ private errorText;
477
+ private draft;
263
478
  private renderTextInput;
479
+ /** The agent's reply as it streams in (not yet final), if any. */
480
+ private streamingReply;
481
+ /** Fill a chat thread element with the current messages. */
482
+ private fillThread;
483
+ /** Connecting, or the visitor spoke last and the agent hasn't started answering. */
484
+ private isAwaitingReply;
264
485
  /**
265
- * The chat thread for text mode. This is a fixed-height, internally scrolling
266
- * window (like a normal website chatbot): the container is rendered at its full
267
- * height as soon as the chat opens — empty until messages arrive — and messages
268
- * accumulate + scroll inside it, so the panel's overall height stays stable.
269
- * Auto-scrolls to the newest message after each render.
486
+ * Patch just the chat thread (and starter questions) in place. Returns false when
487
+ * there is no text thread on screen, in which case the caller does a full render.
270
488
  */
489
+ private updateThread;
490
+ /** The chat thread: a fixed-height window that scrolls internally. */
271
491
  private renderTranscript;
272
492
  }
273
493
 
274
494
  declare const TRILLET_WIDGET_TAG = "trillet-widget";
275
495
  declare function registerTrilletWidget(tag?: string): void;
276
496
 
277
- export { TRILLET_WIDGET_TAG, TrilletWidget, TrilletWidgetElement, type TrilletWidgetProps, type WidgetBrand, type WidgetConfig, type WidgetMode, type WidgetPlacement, type WidgetVariant, type WidgetVariantInput, registerTrilletWidget };
497
+ export { type RemoteWidgetConfig, TRILLET_WIDGET_TAG, TrilletWidget, TrilletWidgetElement, type TrilletWidgetProps, type WidgetBrand, type WidgetConfig, type WidgetMode, type WidgetPlacement, type WidgetTheme, type WidgetVariant, type WidgetVariantInput, registerTrilletWidget };