@trillet-ai/web-sdk 1.9.1 → 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.
@@ -173,13 +266,22 @@ declare class TrilletWidgetElement extends HTMLElement {
173
266
  /** Tear down the current agent cleanly: detach listeners, end the call, drop the ref. */
174
267
  private teardownAgent;
175
268
  /**
176
- * Switch modality mid-session (mode="both"). Because the core binds `mode` at
177
- * construction, this ends the current `TrilletAgent` and constructs a fresh one in
178
- * the other modality, rejoining via the same credential path. Transcripts and the
179
- * duration timer are preserved across the switch; no lifecycle events fire (it's one
180
- * 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.
181
272
  */
182
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;
183
285
  private beginCall;
184
286
  private wireAgentEvents;
185
287
  private endLocalCall;
@@ -190,77 +292,132 @@ declare class TrilletWidgetElement extends HTMLElement {
190
292
  private dispatch;
191
293
  private applyTheme;
192
294
  private formatTime;
295
+ /** The line under the agent's name in the header. */
193
296
  private statusText;
194
297
  private renderStatus;
195
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;
196
305
  private render;
197
- private renderLauncher;
306
+ /** Avatar style: an explicit choice, else the image when one is set, else the orb. */
307
+ private avatarStyle;
308
+ /**
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).
312
+ */
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;
198
349
  private renderPanel;
199
350
  /**
200
351
  * The header title identifying who the user is talking to. Each identity value is
201
352
  * code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
202
353
  * config value takes precedence over the corresponding backend `display.*` value
203
- * (which only arrives on `connected`), falling back to it when unset. Resolution:
204
- * effectiveAgent = config.agentName ?? display.agent_name
205
- * effectiveCallFlow = config.callFlowName ?? display.call_flow_name
206
- * effectiveWorkspace = config.workspaceName ?? display.workspace_name
207
- * title = effectiveAgent || effectiveCallFlow || effectiveWorkspace || ''
208
- * Because the overrides are static config, the title can render pre-call. Note:
209
- * `brand.name` is intentionally NOT part of this chain — it renders in the brand
210
- * 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.
211
356
  */
212
357
  private headerTitle;
213
358
  private renderHeader;
359
+ /** Start, call and gate screens centre a large avatar in the body. */
360
+ private bodyShowsLargeAvatar;
214
361
  /** True when a `both` widget is idle/ended with no modality chosen yet. */
215
362
  private isBothPreCall;
216
363
  /** True when a site key is configured and this session has not solved it yet. */
217
364
  private needsRecaptcha;
218
365
  /**
219
- * 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
220
367
  * disabled start button. The button enables once the checkbox is solved.
221
368
  *
222
369
  * The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
223
370
  * shadow root (its anchor iframe never finishes initializing), so the actual widget
224
371
  * is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
225
372
  * to this slot. It therefore *displays* here inside the panel while its DOM home
226
- * stays in the light tree, where reCAPTCHA works. Verified via examples/recaptcha-
227
- * isolate.local.html (case C).
373
+ * stays in the light tree, where reCAPTCHA works.
228
374
  */
229
375
  private renderRecaptchaGate;
230
376
  /**
231
377
  * Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox
232
- * into it. The node is a child of the host element with `slot="recaptcha"`, so it is
233
- * projected into the gate's <slot>. Idempotent: every widget re-render recreates the
234
- * <slot> element, but this node (and its iframe) persists in the light DOM untouched,
235
- * 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.
236
380
  */
237
381
  private ensureRecaptchaSlot;
238
382
  /** Remove the slotted light-DOM checkbox node. Safe to call when none exists. */
239
383
  private removeRecaptchaSlot;
240
384
  private renderBody;
241
- /** Build the animated gradient orb (or avatar image) reflecting the current state. */
242
- private buildOrb;
243
- /** 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. */
244
386
  private renderBothEntry;
245
- /** 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. */
246
388
  private renderVoiceBody;
247
- /** Text/chat UI: conversation thread + message input. Never an orb or "listening" state. */
389
+ /** Text/chat UI: conversation thread + message input. */
248
390
  private renderTextBody;
249
- /** In mode="both" during a live session, a control to switch to the other modality. */
250
- private renderSwitchButton;
391
+ /** Starter questions, shown until the visitor has said something. */
392
+ private renderSuggestions;
251
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;
252
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;
253
411
  /**
254
- * The chat thread for text mode. This is a fixed-height, internally scrolling
255
- * window (like a normal website chatbot): the container is rendered at its full
256
- * height as soon as the chat opens — empty until messages arrive — and messages
257
- * accumulate + scroll inside it, so the panel's overall height stays stable.
258
- * 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.
259
414
  */
415
+ private updateThread;
416
+ /** The chat thread: a fixed-height window that scrolls internally. */
260
417
  private renderTranscript;
261
418
  }
262
419
 
263
420
  declare const TRILLET_WIDGET_TAG = "trillet-widget";
264
421
  declare function registerTrilletWidget(tag?: string): void;
265
422
 
266
- 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 };