@trillet-ai/web-sdk 1.9.2 → 1.10.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.
@@ -6,6 +6,39 @@ type WidgetVariant = 'compact' | 'expanded';
6
6
  type WidgetVariantInput = WidgetVariant | 'tiny' | 'full';
7
7
  type WidgetMode = 'voice' | 'text' | 'both';
8
8
  type WidgetPlacement = 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right';
9
+ type WidgetTheme = 'light' | 'dark';
10
+ /**
11
+ * The design saved in the Trillet dashboard (Widget designer), served by
12
+ * GET /v1/api/web-call/public/widget-config. Every key is optional; HTML attributes
13
+ * on the element always win over these, so an existing embed keeps rendering exactly
14
+ * as written.
15
+ */
16
+ type AvatarStyle = 'orb' | 'image' | 'initials';
17
+ interface RemoteWidgetConfig {
18
+ avatarStyle?: AvatarStyle | null;
19
+ orbColor1?: string | null;
20
+ orbColor2?: string | null;
21
+ backgroundColor?: string | null;
22
+ textColor?: string | null;
23
+ buttonTextColor?: string | null;
24
+ termsText?: string | null;
25
+ feedback?: 'none' | 'end' | null;
26
+ mode?: WidgetMode;
27
+ placement?: WidgetPlacement;
28
+ variant?: WidgetVariant;
29
+ theme?: WidgetTheme;
30
+ brandColor?: string | null;
31
+ brandName?: string | null;
32
+ brandLogo?: string | null;
33
+ avatar?: string | null;
34
+ title?: string | null;
35
+ launcherText?: string | null;
36
+ greeting?: string | null;
37
+ inputPlaceholder?: string | null;
38
+ startCallText?: string | null;
39
+ messageText?: string | null;
40
+ suggestedPrompts?: string[];
41
+ }
9
42
  interface WidgetBrand {
10
43
  logo?: string;
11
44
  primaryColor?: string;
@@ -19,9 +52,15 @@ interface WidgetConfig {
19
52
  agentId: string;
20
53
  signedUrlEndpoint?: string;
21
54
  workspaceId?: string;
55
+ /** API host override (whitelabel API domain, or a local backend in development). */
56
+ apiBase?: string;
57
+ /** Load the dashboard design on mount (default true; `remote-config="false"` opts out). */
58
+ remoteConfig: boolean;
22
59
  agentName?: string;
23
60
  callFlowName?: string;
24
61
  workspaceName?: string;
62
+ /** 'orb' (animated gradient, default), 'image' (avatar URL) or 'initials'. */
63
+ avatarStyle?: AvatarStyle;
25
64
  avatar?: string;
26
65
  /** Legacy single accent/orb color; alias of orbColor1. */
27
66
  orbColor?: string;
@@ -36,6 +75,9 @@ interface WidgetConfig {
36
75
  startCallText: string;
37
76
  endCallText: string;
38
77
  messageText: string;
78
+ /** Mode "both" launcher: the two halves of the Call | Chat button. */
79
+ callLabel: string;
80
+ chatLabel: string;
39
81
  switchToTextText: string;
40
82
  switchToVoiceText: string;
41
83
  listeningText: string;
@@ -43,6 +85,20 @@ interface WidgetConfig {
43
85
  expandText: string;
44
86
  collapseText: string;
45
87
  recaptchaText: string;
88
+ /** Short line shown next to the closed launcher, and under the chat header. */
89
+ greeting?: string;
90
+ inputPlaceholder: string;
91
+ /** Tap-to-send starter questions, shown until the visitor sends a message. */
92
+ suggestedPrompts: string[];
93
+ theme: WidgetTheme;
94
+ /** Colour overrides on top of the theme. Button colour is brand.primaryColor. */
95
+ backgroundColor?: string;
96
+ textColor?: string;
97
+ buttonTextColor?: string;
98
+ /** Markdown the visitor must accept before their first conversation. */
99
+ termsText?: string;
100
+ /** 'end': ask for a thumbs up/down when a conversation ends. */
101
+ feedback: 'none' | 'end';
46
102
  mode: WidgetMode;
47
103
  variables?: Record<string, unknown>;
48
104
  maxCallDuration?: number;
@@ -63,8 +119,17 @@ interface WidgetConfig {
63
119
  interface TrilletWidgetProps {
64
120
  agentId: string;
65
121
  signedUrlEndpoint?: string;
66
- /** JS-only: invoked at call-start to mint room details (cannot be an HTML attribute). */
67
- getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
122
+ /**
123
+ * JS-only: invoked at call-start to mint room details (cannot be an HTML attribute).
124
+ * Receives the modality being started, so you can mint a voice or a text session.
125
+ */
126
+ getRoomDetails?: (context: {
127
+ mode: 'voice' | 'text';
128
+ }) => Promise<TrilletRoomDetails> | TrilletRoomDetails;
129
+ /** API host override (whitelabel API domain, or a local backend in development). */
130
+ apiBase?: string;
131
+ /** Load the design saved in the Trillet dashboard (default true). */
132
+ remoteConfig?: boolean;
68
133
  /** JS-only: static pre-minted room details. */
69
134
  roomDetails?: TrilletRoomDetails;
70
135
  workspaceId?: string;
@@ -97,6 +162,13 @@ interface TrilletWidgetProps {
97
162
  collapseText?: string;
98
163
  /** Copy shown above the reCAPTCHA checkbox, when `recaptchaSiteKey` is set. */
99
164
  recaptchaText?: string;
165
+ /** Short line shown beside the closed launcher. */
166
+ greeting?: string;
167
+ /** Placeholder in the chat message box. */
168
+ inputPlaceholder?: string;
169
+ /** Tap-to-send starter questions for text chats. */
170
+ suggestedPrompts?: string[];
171
+ theme?: WidgetTheme;
100
172
  /** "voice" | "text" | "both" (multimodal, user-switchable). */
101
173
  mode?: WidgetMode;
102
174
  variables?: Record<string, unknown>;
@@ -128,6 +200,7 @@ interface TrilletWidgetProps {
128
200
  declare const TrilletWidget: React.FC<TrilletWidgetProps>;
129
201
 
130
202
  type ActiveMode = 'voice' | 'text';
203
+ type SessionMode = 'voice' | 'text' | 'multimodal';
131
204
  declare class TrilletWidgetElement extends HTMLElement {
132
205
  static get observedAttributes(): readonly string[];
133
206
  private root;
@@ -141,7 +214,16 @@ declare class TrilletWidgetElement extends HTMLElement {
141
214
  private display;
142
215
  private activeMode;
143
216
  private switching;
144
- getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
217
+ private remote;
218
+ private remoteDisplay;
219
+ private remoteLoadedFor;
220
+ private pendingMessage;
221
+ getRoomDetails?: (context: {
222
+ /** The side the conversation starts on. */
223
+ mode: ActiveMode;
224
+ /** Session type to mint: `multimodal` for mode="both" (type or talk). */
225
+ session: SessionMode;
226
+ }) => Promise<TrilletRoomDetails> | TrilletRoomDetails;
145
227
  roomDetails?: TrilletRoomDetails;
146
228
  private durationTimer;
147
229
  private remainingSeconds;
@@ -153,8 +235,19 @@ declare class TrilletWidgetElement extends HTMLElement {
153
235
  private container;
154
236
  constructor();
155
237
  connectedCallback(): void;
238
+ private refreshConfig;
239
+ /**
240
+ * Fetch the design saved in the dashboard. Best-effort: on any failure the widget
241
+ * keeps rendering from its attributes, exactly as before this existed.
242
+ */
243
+ private loadRemoteConfig;
156
244
  disconnectedCallback(): void;
157
245
  attributeChangedCallback(): void;
246
+ /**
247
+ * Send a chat message as the visitor (text sessions). Opens and starts the chat
248
+ * first when needed; the message is delivered as soon as the session connects.
249
+ */
250
+ sendMessage(text: string): Promise<void>;
158
251
  /**
159
252
  * Imperatively start a conversation. Primary headless API (convai-aligned).
160
253
  * @param modality - optional; only used in `mode="both"` to pick voice vs text.
@@ -166,11 +259,6 @@ declare class TrilletWidgetElement extends HTMLElement {
166
259
  startCall(): Promise<void>;
167
260
  /** @deprecated Use {@link endConversation}. Kept as a thin alias for back-compat. */
168
261
  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
262
  /** The concrete modality to run for the current session (`both` -> activeMode). */
175
263
  private resolvedMode;
176
264
  /** Keep activeMode consistent with the configured mode. */
@@ -178,13 +266,22 @@ declare class TrilletWidgetElement extends HTMLElement {
178
266
  /** Tear down the current agent cleanly: detach listeners, end the call, drop the ref. */
179
267
  private teardownAgent;
180
268
  /**
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).
269
+ * Switch between typing and talking (mode="both"). Same session, same conversation:
270
+ * the SDK turns the mic on/off and asks the agent to turn its speech on/off. If the
271
+ * mic is refused, the conversation simply stays in text and says why.
186
272
  */
187
273
  private switchModality;
274
+ private pendingTimer;
275
+ /**
276
+ * Listening <-> Speaking flips several times a second at turn edges. Patch the few
277
+ * nodes that show it instead of re-rendering, which would rebuild (and flash) the UI.
278
+ */
279
+ private setSpeaking;
280
+ private lastView;
281
+ /** Send the message typed before the chat started (once). */
282
+ private flushPending;
283
+ private notice;
284
+ private switchingSide;
188
285
  private beginCall;
189
286
  private wireAgentEvents;
190
287
  private endLocalCall;
@@ -195,83 +292,132 @@ declare class TrilletWidgetElement extends HTMLElement {
195
292
  private dispatch;
196
293
  private applyTheme;
197
294
  private formatTime;
295
+ /** The line under the agent's name in the header. */
198
296
  private statusText;
199
297
  private renderStatus;
200
298
  private timerText;
299
+ /**
300
+ * Agent voice level (0..1) from the live audio. Written straight to a CSS variable
301
+ * on the host, so the presence ring moves with the real voice without re-rendering.
302
+ */
303
+ private setLevel;
304
+ private smoothedLevel;
201
305
  private render;
306
+ /** Avatar style: an explicit choice, else the image when one is set, else the orb. */
307
+ private avatarStyle;
202
308
  /**
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.
309
+ * The mark: who the visitor is talking to, as a small rounded tile. A gradient in
310
+ * the brand colours (default), the business's image, or initials. While the agent
311
+ * speaks on a call, the tile breathes with the voice level (--tw-level).
206
312
  */
207
- private renderInlineVoice;
208
- private renderLauncher;
313
+ private buildAvatar;
314
+ /** The name shown to visitors: business name, else the agent/flow name. */
315
+ private speakerName;
316
+ /** Live voice level as five bars (heights follow --tw-level). */
317
+ private buildWave;
318
+ private iconButton;
319
+ private showTerms;
320
+ private pendingStart;
321
+ private callId;
322
+ private feedbackState;
323
+ /** Acceptance is remembered per agent and per version of the text. */
324
+ private termsKey;
325
+ private termsAccepted;
326
+ private termsAcceptedThisPage;
327
+ private renderTerms;
328
+ /** "How was this conversation?" thumbs, once, after a conversation ends. */
329
+ private renderFeedback;
330
+ /**
331
+ * The ask bar: the widget's resting state.
332
+ *
333
+ * [mark] Ask Firelink anything… (mic) (send)
334
+ *
335
+ * Input-first: typing + Enter opens the chat with that message already sent; the
336
+ * mic starts a call and the bar becomes the call bar. Voice-only shows "Talk to …"
337
+ * with a call button; chat-only drops the mic.
338
+ */
339
+ private renderCard;
340
+ private askFocused;
341
+ /** Suggested questions just above the ask bar while it has focus. */
342
+ private renderAskSuggestions;
343
+ /**
344
+ * Open the panel. A text-only widget starts the chat straight away, so the agent's
345
+ * welcome is already there when the panel opens, like any website chat. `both`
346
+ * waits for the visitor to pick call or message.
347
+ */
348
+ private openPanel;
209
349
  private renderPanel;
210
350
  /**
211
351
  * The header title identifying who the user is talking to. Each identity value is
212
352
  * code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
213
353
  * 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.
354
+ * (which only arrives on `connected`), falling back to it when unset. `brand.name`
355
+ * is intentionally NOT part of this chain; it renders as the status line pre-call.
222
356
  */
223
357
  private headerTitle;
224
358
  private renderHeader;
359
+ /** Start, call and gate screens centre a large avatar in the body. */
360
+ private bodyShowsLargeAvatar;
225
361
  /** True when a `both` widget is idle/ended with no modality chosen yet. */
226
362
  private isBothPreCall;
227
363
  /** True when a site key is configured and this session has not solved it yet. */
228
364
  private needsRecaptcha;
229
365
  /**
230
- * The pre-call gate shown in the panel: orb, prompt, the reCAPTCHA checkbox, and a
366
+ * The pre-call gate shown in the panel: prompt, the reCAPTCHA checkbox, and a
231
367
  * disabled start button. The button enables once the checkbox is solved.
232
368
  *
233
369
  * The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
234
370
  * shadow root (its anchor iframe never finishes initializing), so the actual widget
235
371
  * is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
236
372
  * 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).
373
+ * stays in the light tree, where reCAPTCHA works.
239
374
  */
240
375
  private renderRecaptchaGate;
241
376
  /**
242
377
  * 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.
378
+ * into it. Idempotent: every re-render recreates the <slot>, but this node (and its
379
+ * iframe) persists in the light DOM untouched, so the checkbox renders exactly once.
247
380
  */
248
381
  private ensureRecaptchaSlot;
249
382
  /** Remove the slotted light-DOM checkbox node. Safe to call when none exists. */
250
383
  private removeRecaptchaSlot;
251
384
  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). */
385
+ /** Pre-call panel for mode="both": the visitor picks how to talk. */
255
386
  private renderBothEntry;
256
- /** Voice UI: orb + spoken status + timer + mic/end controls. Never a text input. */
387
+ /** Voice call: the agent's presence (ring follows their voice), status, controls. */
257
388
  private renderVoiceBody;
258
- /** Text/chat UI: conversation thread + message input. Never an orb or "listening" state. */
389
+ /** Text/chat UI: conversation thread + message input. */
259
390
  private renderTextBody;
260
- /** In mode="both" during a live session, a control to switch to the other modality. */
261
- private renderSwitchButton;
391
+ /** Starter questions, shown until the visitor has said something. */
392
+ private renderSuggestions;
262
393
  private renderControls;
394
+ /**
395
+ * The call bar. Resting (floating) it replaces the ask bar during a call; inside the
396
+ * chat panel it replaces the composer on the voice side of a type-or-talk chat.
397
+ *
398
+ * ||||| Speaking (mic) (💬 / ⌨) (end)
399
+ * Firelink · 0:42
400
+ */
401
+ private renderVoiceBar;
402
+ private errorText;
403
+ private draft;
263
404
  private renderTextInput;
405
+ /** The agent's reply as it streams in (not yet final), if any. */
406
+ private streamingReply;
407
+ /** Fill a chat thread element with the current messages. */
408
+ private fillThread;
409
+ /** Connecting, or the visitor spoke last and the agent hasn't started answering. */
410
+ private isAwaitingReply;
264
411
  /**
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.
412
+ * Patch just the chat thread (and starter questions) in place. Returns false when
413
+ * there is no text thread on screen, in which case the caller does a full render.
270
414
  */
415
+ private updateThread;
416
+ /** The chat thread: a fixed-height window that scrolls internally. */
271
417
  private renderTranscript;
272
418
  }
273
419
 
274
420
  declare const TRILLET_WIDGET_TAG = "trillet-widget";
275
421
  declare function registerTrilletWidget(tag?: string): void;
276
422
 
277
- export { TRILLET_WIDGET_TAG, TrilletWidget, TrilletWidgetElement, type TrilletWidgetProps, type WidgetBrand, type WidgetConfig, type WidgetMode, type WidgetPlacement, type WidgetVariant, type WidgetVariantInput, registerTrilletWidget };
423
+ 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 };