@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.
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  TrilletAgent
3
- } from "../chunk-FSJ42TKR.js";
4
- import "../chunk-3MH6DJZ6.js";
3
+ } from "../chunk-IASKK2IK.js";
4
+ import {
5
+ apiUrl
6
+ } from "../chunk-CVTVHUNZ.js";
5
7
 
6
8
  // src/widget/config.ts
7
- var DEFAULT_ORB_COLOR_1 = "#2792dc";
8
- var DEFAULT_ORB_COLOR_2 = "#9ce6e6";
9
9
  var DEFAULT_COPY = {
10
10
  startCallText: "Start a call",
11
11
  endCallText: "End call",
@@ -16,16 +16,29 @@ var DEFAULT_COPY = {
16
16
  speakingText: "Speaking\u2026",
17
17
  expandText: "Expand",
18
18
  collapseText: "Collapse",
19
- recaptchaText: "Verify you are human to start"
19
+ recaptchaText: "Verify you are human to start",
20
+ inputPlaceholder: "Type a message\u2026"
20
21
  };
21
22
  var OBSERVED_ATTRIBUTES = [
22
23
  "agent-id",
23
24
  "signed-url-endpoint",
24
25
  "workspace-id",
26
+ "api-base",
27
+ "remote-config",
28
+ "greeting",
29
+ "input-placeholder",
30
+ "suggested-prompts",
31
+ "theme",
32
+ "bg-color",
33
+ "text-color",
34
+ "btn-text-color",
35
+ "terms",
36
+ "feedback",
25
37
  "agent-name",
26
38
  "call-flow-name",
27
39
  "workspace-name",
28
40
  "avatar",
41
+ "avatar-style",
29
42
  "avatar-image-url",
30
43
  // convai alias -> avatar
31
44
  "orb-color",
@@ -38,6 +51,8 @@ var OBSERVED_ATTRIBUTES = [
38
51
  "start-call-text",
39
52
  "end-call-text",
40
53
  "message-text",
54
+ "call-label",
55
+ "chat-label",
41
56
  "switch-to-text-text",
42
57
  "switch-to-voice-text",
43
58
  "listening-text",
@@ -84,6 +99,25 @@ function parseNumberAttr(value) {
84
99
  const n = Number(value);
85
100
  return Number.isFinite(n) ? n : void 0;
86
101
  }
102
+ var HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
103
+ function hexOrUndefined(value) {
104
+ return value && HEX.test(value.trim()) ? value.trim() : void 0;
105
+ }
106
+ function parsePromptsAttr(value) {
107
+ if (value === null) return void 0;
108
+ const trimmed = value.trim();
109
+ if (!trimmed) return [];
110
+ if (trimmed.startsWith("[")) {
111
+ try {
112
+ const parsed = JSON.parse(trimmed);
113
+ if (Array.isArray(parsed)) return parsed.map(String).map((p) => p.trim()).filter(Boolean);
114
+ } catch (e) {
115
+ console.warn("[trillet-widget] Failed to parse suggested-prompts:", value);
116
+ }
117
+ return [];
118
+ }
119
+ return trimmed.split("|").map((p) => p.trim()).filter(Boolean);
120
+ }
87
121
  function resolveVariant(raw) {
88
122
  switch (raw) {
89
123
  case "expanded":
@@ -96,46 +130,58 @@ function resolveVariant(raw) {
96
130
  return "compact";
97
131
  }
98
132
  }
99
- function configFromElement(el) {
100
- const get = (name) => el.getAttribute(name);
101
- const variant = resolveVariant(get("variant"));
102
- const modeRaw = get("mode");
133
+ function configFromElement(el, remote) {
134
+ var _a, _b;
135
+ const r = remote || {};
136
+ const get = (name, fallback) => {
137
+ var _a2;
138
+ return (_a2 = el.getAttribute(name)) != null ? _a2 : fallback || null;
139
+ };
140
+ const variant = resolveVariant(get("variant", r.variant));
141
+ const modeRaw = get("mode", r.mode);
103
142
  const mode = modeRaw === "text" ? "text" : modeRaw === "both" ? "both" : "voice";
104
- const placementRaw = get("placement");
143
+ const placementRaw = get("placement", r.placement);
105
144
  const placement = PLACEMENTS.includes(placementRaw) ? placementRaw : "bottom-right";
106
145
  const isText = mode === "text";
107
- const startDefault = isText ? "Start chat" : DEFAULT_COPY.startCallText;
146
+ const startDefault = r.startCallText || (isText ? "Start chat" : DEFAULT_COPY.startCallText);
108
147
  const endDefault = isText ? "End chat" : DEFAULT_COPY.endCallText;
109
148
  const brand = {};
110
- const brandLogo = get("brand-logo");
111
- const brandColor = get("brand-color");
112
- const brandName = get("brand-name");
149
+ const brandLogo = get("brand-logo", r.brandLogo);
150
+ const brandColor = get("brand-color", r.brandColor);
151
+ const brandName = get("brand-name", r.brandName);
113
152
  if (brandLogo) brand.logo = brandLogo;
114
153
  if (brandColor) brand.primaryColor = brandColor;
115
154
  if (brandName) brand.name = brandName;
116
155
  const orbColor = get("orb-color") || void 0;
117
- const orbColor1 = get("avatar-orb-color-1") || orbColor || void 0;
118
- const orbColor2 = get("avatar-orb-color-2") || void 0;
156
+ const orbColor1 = get("avatar-orb-color-1", r.orbColor1) || orbColor || void 0;
157
+ const orbColor2 = get("avatar-orb-color-2", r.orbColor2) || void 0;
158
+ const styleRaw = get("avatar-style", r.avatarStyle);
159
+ const avatarStyle = styleRaw === "orb" || styleRaw === "image" || styleRaw === "initials" ? styleRaw : void 0;
119
160
  return {
120
161
  agentId: get("agent-id") || "",
121
162
  signedUrlEndpoint: get("signed-url-endpoint") || void 0,
122
163
  workspaceId: get("workspace-id") || void 0,
164
+ apiBase: get("api-base") || void 0,
165
+ remoteConfig: get("remote-config") !== "false",
123
166
  // Header identity overrides — empty string/absent => treated as "not set".
124
- agentName: get("agent-name") || void 0,
167
+ agentName: get("agent-name", r.title) || void 0,
125
168
  callFlowName: get("call-flow-name") || void 0,
126
169
  workspaceName: get("workspace-name") || void 0,
127
170
  // convai `avatar-image-url` is an alias of our `avatar`.
128
- avatar: get("avatar") || get("avatar-image-url") || void 0,
171
+ avatarStyle,
172
+ avatar: get("avatar") || get("avatar-image-url") || r.avatar || void 0,
129
173
  orbColor,
130
174
  orbColor1,
131
175
  orbColor2,
132
176
  variant,
133
177
  placement,
134
178
  dismissible: parseBoolAttr(get("dismissible")),
135
- actionText: get("action-text") || void 0,
179
+ actionText: get("action-text", r.launcherText) || void 0,
136
180
  startCallText: get("start-call-text") || startDefault,
137
181
  endCallText: get("end-call-text") || endDefault,
138
- messageText: get("message-text") || DEFAULT_COPY.messageText,
182
+ messageText: get("message-text", r.messageText) || DEFAULT_COPY.messageText,
183
+ callLabel: get("call-label") || "Call",
184
+ chatLabel: get("chat-label") || "Chat",
139
185
  switchToTextText: get("switch-to-text-text") || DEFAULT_COPY.switchToTextText,
140
186
  switchToVoiceText: get("switch-to-voice-text") || DEFAULT_COPY.switchToVoiceText,
141
187
  listeningText: get("listening-text") || DEFAULT_COPY.listeningText,
@@ -143,6 +189,15 @@ function configFromElement(el) {
143
189
  expandText: get("expand-text") || DEFAULT_COPY.expandText,
144
190
  collapseText: get("collapse-text") || DEFAULT_COPY.collapseText,
145
191
  recaptchaText: get("recaptcha-text") || DEFAULT_COPY.recaptchaText,
192
+ greeting: get("greeting", r.greeting) || void 0,
193
+ inputPlaceholder: get("input-placeholder", r.inputPlaceholder) || DEFAULT_COPY.inputPlaceholder,
194
+ suggestedPrompts: (_b = (_a = parsePromptsAttr(el.getAttribute("suggested-prompts"))) != null ? _a : r.suggestedPrompts) != null ? _b : [],
195
+ theme: get("theme", r.theme) === "dark" ? "dark" : "light",
196
+ backgroundColor: hexOrUndefined(get("bg-color", r.backgroundColor)),
197
+ textColor: hexOrUndefined(get("text-color", r.textColor)),
198
+ buttonTextColor: hexOrUndefined(get("btn-text-color", r.buttonTextColor)),
199
+ termsText: get("terms", r.termsText) || void 0,
200
+ feedback: get("feedback", r.feedback) === "end" ? "end" : "none",
146
201
  mode,
147
202
  // convai `dynamic-variables` is an alias of our `variables`.
148
203
  variables: parseJsonAttr(get("variables") || get("dynamic-variables")),
@@ -158,442 +213,571 @@ var WIDGET_STYLES = (
158
213
  /* css */
159
214
  `
160
215
  :host {
161
- /* Positioning: default bottom-right. The host can override by setting
162
- position-related CSS on the trillet-widget element directly, or via the
163
- placement attribute (see :host([placement=...]) rules below). */
164
216
  position: fixed;
165
- right: 24px;
166
- bottom: 24px;
217
+ right: 20px;
218
+ bottom: 20px;
167
219
  z-index: 2147483000;
168
220
 
169
- /* Theming tokens (overridden at runtime via setProperty). */
170
- --trillet-accent: #2792dc;
171
- --trillet-orb-1: #2792dc;
172
- --trillet-orb-2: #9ce6e6;
173
- --trillet-surface: #ffffff;
174
- --trillet-on-surface: #0b0b0f;
175
- --trillet-muted: #6b7280;
176
- --trillet-border: rgba(0, 0, 0, 0.08);
177
- --trillet-shadow: 0 12px 48px rgba(0, 0, 0, 0.20);
221
+ --tw-accent: #0062e9;
222
+ --tw-on-accent: #ffffff;
223
+ --tw-surface: #ffffff;
224
+ --tw-raised: #f7f9fc;
225
+ --tw-ink: #1e293b;
226
+ --tw-muted: #64748b;
227
+ --tw-line: #e2e8f0;
228
+ --tw-danger: #dc2626;
229
+ --tw-online: #16a34a;
230
+ --tw-orb-1: #0062e9;
231
+ --tw-orb-2: #27a3fd;
232
+ --tw-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 12px 32px -6px rgba(15, 23, 42, 0.14);
233
+ --tw-level: 0;
178
234
 
179
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
180
- font-size: 14px;
181
- line-height: 1.4;
182
- color: var(--trillet-on-surface);
235
+ font-family: inherit;
236
+ font-size: 15px;
237
+ line-height: 1.5;
238
+ color: var(--tw-ink);
239
+ -webkit-font-smoothing: antialiased;
240
+ }
241
+
242
+ :host([data-theme="dark"]) {
243
+ --tw-surface: #0f1b2d;
244
+ --tw-raised: #172437;
245
+ --tw-ink: #e8edf4;
246
+ --tw-muted: #94a3b8;
247
+ --tw-line: #23324a;
248
+ --tw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -8px rgba(0, 0, 0, 0.55);
183
249
  }
184
250
 
185
251
  :host([hidden]) { display: none; }
186
252
 
187
- /* ---- placement attribute (fixed positioning on the host element) ----
188
- Kept in the shadow stylesheet (low specificity) so raw CSS on the
189
- trillet-widget element still overrides it. */
190
- :host([placement="bottom-right"]) { top: auto; bottom: 24px; left: auto; right: 24px; }
191
- :host([placement="bottom-left"]) { top: auto; bottom: 24px; right: auto; left: 24px; }
192
- :host([placement="bottom"]) { top: auto; bottom: 24px; left: 50%; right: auto; transform: translateX(-50%); }
193
- :host([placement="top-right"]) { bottom: auto; top: 24px; left: auto; right: 24px; }
194
- :host([placement="top-left"]) { bottom: auto; top: 24px; right: auto; left: 24px; }
195
- :host([placement="top"]) { bottom: auto; top: 24px; left: 50%; right: auto; transform: translateX(-50%); }
253
+ /* ---- Placement (fixed on the host; raw CSS on the element still wins) ---- */
254
+ :host([data-placement="bottom-right"]) { top: auto; bottom: 20px; left: auto; right: 20px; }
255
+ :host([data-placement="bottom-left"]) { top: auto; bottom: 20px; right: auto; left: 20px; }
256
+ :host([data-placement="bottom"]) { top: auto; bottom: 20px; left: 50%; right: auto; transform: translateX(-50%); }
257
+ :host([data-placement="top-right"]) { bottom: auto; top: 20px; left: auto; right: 20px; }
258
+ :host([data-placement="top-left"]) { bottom: auto; top: 20px; right: auto; left: 20px; }
259
+ :host([data-placement="top"]) { bottom: auto; top: 20px; left: 50%; right: auto; transform: translateX(-50%); }
196
260
 
197
261
  * { box-sizing: border-box; }
198
-
199
- .tw-root {
200
- display: flex;
201
- flex-direction: column;
202
- align-items: flex-end;
203
- gap: 12px;
262
+ button { font: inherit; color: inherit; }
263
+ button:focus-visible, textarea:focus-visible, a:focus-visible {
264
+ outline: 2px solid var(--tw-accent);
265
+ outline-offset: 2px;
204
266
  }
205
- /* Left/center placements align the launcher + card accordingly. */
206
- :host([placement="bottom-left"]) .tw-root,
207
- :host([placement="top-left"]) .tw-root { align-items: flex-start; }
208
- :host([placement="bottom"]) .tw-root,
209
- :host([placement="top"]) .tw-root { align-items: center; }
267
+ svg { display: block; flex-shrink: 0; }
210
268
 
211
- /* ---- Floating launcher ---- */
212
- .tw-launcher {
269
+ .tw-root { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
270
+ :host([data-placement$="left"]) .tw-root { align-items: flex-start; }
271
+ :host([data-placement="bottom"]) .tw-root, :host([data-placement="top"]) .tw-root { align-items: center; }
272
+
273
+ /* ---- Buttons ---- */
274
+ .tw-btn {
213
275
  display: inline-flex;
214
276
  align-items: center;
215
- gap: 10px;
216
- padding: 12px 18px;
217
- border: none;
218
- border-radius: 999px;
219
- background: var(--trillet-accent);
220
- color: #fff;
221
- font-size: 14px;
277
+ justify-content: center;
278
+ gap: 8px;
279
+ height: 40px;
280
+ padding: 0 16px;
281
+ border-radius: 8px;
282
+ border: 1px solid transparent;
283
+ font-size: 15px;
222
284
  font-weight: 600;
285
+ white-space: nowrap;
223
286
  cursor: pointer;
224
- box-shadow: var(--trillet-shadow);
225
- transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
287
+ transition: background 0.15s ease, filter 0.15s ease, border-color 0.15s ease;
226
288
  }
227
- .tw-launcher:hover { transform: translateY(-1px); box-shadow: 0 16px 52px rgba(0, 0, 0, 0.26); }
228
- .tw-launcher:active { transform: translateY(0); }
229
- .tw-launcher .tw-launcher-orb {
230
- width: 20px;
231
- height: 20px;
232
- border-radius: 50%;
233
- background:
234
- conic-gradient(from 0deg, var(--trillet-orb-1), var(--trillet-orb-2), var(--trillet-orb-1));
235
- box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.6);
236
- animation: tw-orb-rotate 8s linear infinite;
289
+ .tw-btn svg { width: 17px; height: 17px; }
290
+ .tw-btn:disabled { opacity: 0.55; cursor: default; }
291
+ .tw-btn-primary { background: var(--tw-accent); color: var(--tw-on-accent); }
292
+ .tw-btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
293
+ .tw-btn-secondary { background: var(--tw-surface); color: var(--tw-ink); border-color: var(--tw-line); }
294
+ .tw-btn-secondary:hover:not(:disabled) { background: var(--tw-raised); }
295
+ .tw-btn-danger { background: var(--tw-danger); color: #fff; }
296
+ .tw-btn-danger:hover:not(:disabled) { filter: brightness(1.07); }
297
+
298
+ .tw-icon-btn {
299
+ width: 32px;
300
+ height: 32px;
301
+ border: none;
302
+ border-radius: 8px;
303
+ background: transparent;
304
+ color: var(--tw-muted);
305
+ display: inline-flex;
306
+ align-items: center;
307
+ justify-content: center;
308
+ cursor: pointer;
237
309
  }
238
- .tw-launcher .tw-launcher-orb-avatar {
239
- background: none;
240
- background-size: cover;
241
- background-position: center;
242
- animation: none;
310
+ .tw-icon-btn svg { width: 18px; height: 18px; }
311
+ .tw-icon-btn:hover:not(:disabled) { background: var(--tw-raised); color: var(--tw-ink); }
312
+ .tw-icon-btn:disabled { opacity: 0.45; cursor: default; }
313
+ .tw-icon-btn.tw-btn-icon {
314
+ width: 40px;
315
+ height: 40px;
316
+ border: 1px solid var(--tw-line);
317
+ color: var(--tw-ink);
243
318
  }
319
+ .tw-icon-btn.tw-muted { color: var(--tw-danger); border-color: var(--tw-danger); }
244
320
 
245
- /* ---- Panel ---- */
246
- .tw-panel {
247
- width: 320px;
248
- max-width: calc(100vw - 32px);
249
- background: var(--trillet-surface);
250
- border: 1px solid var(--trillet-border);
251
- border-radius: 16px;
252
- box-shadow: var(--trillet-shadow);
253
- overflow: hidden;
254
- display: flex;
255
- flex-direction: column;
321
+ /* Full-width buttons on the panel's centred screens. */
322
+ .tw-primary-btn, .tw-secondary-btn {
323
+ display: inline-flex;
324
+ align-items: center;
325
+ justify-content: center;
326
+ gap: 8px;
327
+ height: 42px;
328
+ padding: 0 18px;
329
+ border-radius: 8px;
330
+ font-size: 15px;
331
+ font-weight: 600;
332
+ cursor: pointer;
256
333
  }
257
- .tw-panel.tw-expanded { width: 380px; }
334
+ .tw-primary-btn svg, .tw-secondary-btn svg { width: 17px; height: 17px; }
335
+ .tw-primary-btn { border: none; background: var(--tw-accent); color: var(--tw-on-accent); }
336
+ .tw-primary-btn:hover:not(:disabled) { filter: brightness(1.07); }
337
+ .tw-primary-btn:disabled { opacity: 0.5; cursor: default; }
338
+ .tw-secondary-btn { border: 1px solid var(--tw-line); background: var(--tw-surface); color: var(--tw-ink); }
339
+ .tw-secondary-btn:hover:not(:disabled) { background: var(--tw-raised); }
340
+ .tw-secondary-btn.tw-small { height: 34px; padding: 0 12px; font-size: 14px; }
258
341
 
259
- .tw-header {
260
- display: flex;
342
+ .tw-round-btn {
343
+ width: 48px;
344
+ height: 48px;
345
+ border-radius: 50%;
346
+ border: 1px solid var(--tw-line);
347
+ color: var(--tw-ink);
348
+ }
349
+ .tw-round-btn svg { width: 20px; height: 20px; }
350
+ .tw-round-btn.tw-small-round { width: 36px; height: 36px; }
351
+ .tw-round-btn.tw-small-round svg { width: 17px; height: 17px; }
352
+ .tw-round-btn.tw-end-btn { background: var(--tw-danger); border-color: var(--tw-danger); color: #fff; }
353
+
354
+ .tw-link-btn {
355
+ display: inline-flex;
261
356
  align-items: center;
262
- gap: 10px;
263
- padding: 14px 16px;
264
- border-bottom: 1px solid var(--trillet-border);
357
+ gap: 6px;
358
+ border: none;
359
+ background: transparent;
360
+ color: var(--tw-muted);
361
+ font-size: 13px;
362
+ padding: 4px 2px;
363
+ cursor: pointer;
265
364
  }
266
- /* Brand slot: customer logo + optional small brand label, stacked. Subordinate to
267
- the identity title. */
268
- .tw-brand {
365
+ .tw-link-btn:hover:not(:disabled) { color: var(--tw-ink); }
366
+ .tw-link-btn:disabled { opacity: 0.5; cursor: default; }
367
+
368
+ /* ---- Ask bar: the resting widget (input-first) ---- */
369
+ .tw-bar-stack { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
370
+ :host([data-placement$="left"]) .tw-bar-stack { align-items: flex-start; }
371
+ .tw-ask, .tw-callbar {
269
372
  display: flex;
270
373
  align-items: center;
271
- gap: 6px;
272
- min-width: 0;
273
- flex-shrink: 0;
374
+ gap: 8px;
375
+ width: 320px;
376
+ max-width: calc(100vw - 24px);
377
+ padding: 6px 6px 6px 10px;
378
+ background: var(--tw-surface);
379
+ border: 1px solid var(--tw-line);
380
+ border-radius: 12px;
381
+ box-shadow: var(--tw-shadow);
382
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
274
383
  }
275
- .tw-brand-logo {
276
- width: 28px;
277
- height: 28px;
278
- border-radius: 8px;
279
- object-fit: cover;
384
+ .tw-ask:focus-within { border-color: var(--tw-accent); }
385
+ .tw-ask-form { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; margin: 0; }
386
+ .tw-ask-input {
387
+ flex: 1;
388
+ min-width: 0;
389
+ border: none;
390
+ outline: none;
391
+ background: transparent;
392
+ color: var(--tw-ink);
393
+ font: inherit;
394
+ font-size: 15px;
395
+ padding: 6px 4px;
280
396
  }
281
- /* Small customer brand label (brand.name). Visually subordinate to the identity
282
- title \u2014 lighter weight, muted color, smaller. Never used as the header title. */
283
- .tw-brand-name {
284
- font-weight: 500;
285
- font-size: 12px;
286
- color: var(--trillet-muted);
397
+ .tw-ask-input::placeholder { color: var(--tw-muted); }
398
+ .tw-ask-input:focus-visible { outline: none; }
399
+ .tw-ask-label {
400
+ flex: 1;
401
+ min-width: 0;
402
+ border: none;
403
+ background: transparent;
404
+ text-align: left;
405
+ font-size: 15px;
406
+ padding: 6px 4px;
407
+ color: var(--tw-ink);
408
+ cursor: pointer;
287
409
  white-space: nowrap;
288
410
  overflow: hidden;
289
411
  text-overflow: ellipsis;
290
- max-width: 120px;
291
412
  }
292
- /* Header title identifying who the user is talking to (agent / call flow /
293
- workspace name). The primary header identity; truncates long names cleanly. */
294
- .tw-header-title {
295
- flex: 1;
296
- min-width: 0;
297
- font-weight: 600;
298
- font-size: 14px;
299
- color: var(--trillet-on-surface);
413
+ .tw-ask-suggestions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 320px; }
414
+ :host([data-placement$="left"]) .tw-ask-suggestions { justify-content: flex-start; }
415
+ .tw-ask-suggestions .tw-suggestion { box-shadow: var(--tw-shadow); }
416
+ .tw-bar-note {
417
+ max-width: 320px;
418
+ padding: 7px 12px;
419
+ font-size: 13px;
420
+ background: var(--tw-surface);
421
+ border: 1px solid var(--tw-line);
422
+ border-radius: 10px;
423
+ box-shadow: var(--tw-shadow);
424
+ }
425
+
426
+ /* Square icon actions. accent = send / call, quiet = mic etc., danger = hang up. */
427
+ .tw-icon-btn.tw-sq { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
428
+ .tw-icon-btn.tw-sq svg { width: 17px; height: 17px; }
429
+ .tw-icon-btn.tw-sq-accent, .tw-icon-btn.tw-sq-accent:hover:not(:disabled) { background: var(--tw-accent); color: var(--tw-on-accent); }
430
+ .tw-icon-btn.tw-sq-accent:hover:not(:disabled) { filter: brightness(1.08); }
431
+ .tw-icon-btn.tw-sq-accent:disabled { opacity: 0.35; }
432
+ .tw-icon-btn.tw-sq-quiet { color: var(--tw-ink); }
433
+ .tw-icon-btn.tw-sq-danger, .tw-icon-btn.tw-sq-danger:hover:not(:disabled) { background: var(--tw-danger); color: #fff; }
434
+ .tw-icon-btn.tw-sq-danger:hover:not(:disabled) { filter: brightness(1.08); }
435
+ .tw-icon-btn.tw-sq.tw-muted { color: var(--tw-danger); }
436
+
437
+ /* ---- Call bar ---- */
438
+ .tw-callbar { gap: 10px; padding-left: 12px; }
439
+ .tw-callbar-inline { width: auto; margin: 0 12px; box-shadow: none; animation: none; }
440
+ .tw-callbar-text { flex: 1; min-width: 0; }
441
+ .tw-callbar-activity { font-size: 14px; font-weight: 600; line-height: 1.25; }
442
+ .tw-callbar-meta {
443
+ font-size: 12px;
444
+ color: var(--tw-muted);
300
445
  white-space: nowrap;
301
446
  overflow: hidden;
302
447
  text-overflow: ellipsis;
303
448
  }
304
- .tw-icon-btn {
305
- border: none;
306
- background: transparent;
307
- color: var(--trillet-muted);
308
- cursor: pointer;
309
- width: 28px;
310
- height: 28px;
311
- border-radius: 8px;
449
+
450
+ /* The waveform: five bars whose height follows the agent's live voice level. */
451
+ .tw-wave { display: inline-flex; align-items: center; gap: 3px; height: 24px; flex-shrink: 0; }
452
+ .tw-wave i {
453
+ display: block;
454
+ width: 3px;
455
+ border-radius: 2px;
456
+ background: var(--tw-accent);
457
+ height: calc(5px + var(--tw-level) * 19px);
458
+ transition: height 0.08s linear;
459
+ }
460
+ .tw-wave i:nth-child(1), .tw-wave i:nth-child(5) { height: calc(4px + var(--tw-level) * 9px); }
461
+ .tw-wave i:nth-child(2), .tw-wave i:nth-child(4) { height: calc(5px + var(--tw-level) * 15px); }
462
+ .tw-wave:not(.tw-wave-speaking) i { opacity: 0.55; }
463
+
464
+ /* ---- Mark: who the visitor talks to ---- */
465
+ .tw-mark {
312
466
  display: inline-flex;
313
467
  align-items: center;
314
468
  justify-content: center;
315
- font-size: 16px;
316
- line-height: 1;
469
+ flex-shrink: 0;
470
+ border-radius: 7px;
471
+ background: var(--tw-accent);
472
+ color: var(--tw-on-accent);
473
+ font-weight: 600;
474
+ background-size: cover;
475
+ background-position: center;
317
476
  }
318
- .tw-icon-btn:hover { background: rgba(0, 0, 0, 0.05); }
477
+ .tw-mark-sm { width: 24px; height: 24px; font-size: 11px; border-radius: 6px; }
478
+ .tw-mark-md { width: 26px; height: 26px; font-size: 12px; }
479
+ .tw-mark-lg { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; }
480
+ .tw-mark-orb { background: linear-gradient(135deg, var(--tw-orb-1), var(--tw-orb-2)); }
319
481
 
320
- .tw-body {
321
- padding: 20px 16px;
482
+ /* Terms dialog keeps a small card. */
483
+ .tw-card {
322
484
  display: flex;
323
485
  flex-direction: column;
324
- align-items: center;
325
486
  gap: 14px;
487
+ max-width: calc(100vw - 24px);
488
+ padding: 16px;
489
+ background: var(--tw-surface);
490
+ border: 1px solid var(--tw-line);
491
+ border-radius: 12px;
492
+ box-shadow: var(--tw-shadow);
326
493
  }
494
+ .tw-card-title { font-size: 15px; font-weight: 600; }
495
+ .tw-card-actions { display: flex; gap: 8px; }
496
+ .tw-inline-hint { font-size: 13px; color: var(--tw-muted); }
327
497
 
328
- /* ---- Animated 2-color gradient orb / avatar ---- */
329
- .tw-orb-wrap {
330
- position: relative;
331
- width: 96px;
332
- height: 96px;
498
+ /* ---- Panel ---- */
499
+ .tw-panel {
500
+ width: 380px;
501
+ height: min(600px, calc(100vh - 40px));
502
+ max-width: calc(100vw - 24px);
503
+ display: flex;
504
+ flex-direction: column;
505
+ background: var(--tw-surface);
506
+ border: 1px solid var(--tw-line);
507
+ border-radius: 14px;
508
+ box-shadow: var(--tw-shadow);
509
+ overflow: hidden;
510
+ }
511
+ .tw-panel.tw-expanded { width: 420px; height: min(680px, calc(100vh - 40px)); }
512
+
513
+ .tw-header {
333
514
  display: flex;
334
515
  align-items: center;
335
- justify-content: center;
516
+ gap: 10px;
517
+ padding: 12px 10px 12px 14px;
518
+ border-bottom: 1px solid var(--tw-line);
336
519
  }
337
- /* Soft aura behind the orb (breathes gently; stronger while speaking). */
338
- .tw-orb-wrap::before {
339
- content: '';
340
- position: absolute;
341
- width: 78px;
342
- height: 78px;
343
- border-radius: 50%;
344
- background: radial-gradient(circle, var(--trillet-orb-2), transparent 70%);
345
- opacity: 0.5;
346
- filter: blur(10px);
347
- animation: tw-aura 3.2s ease-in-out infinite;
520
+ .tw-who { flex: 1; min-width: 0; }
521
+ .tw-header-title {
522
+ font-size: 15px;
523
+ font-weight: 600;
524
+ white-space: nowrap;
525
+ overflow: hidden;
526
+ text-overflow: ellipsis;
348
527
  }
349
- .tw-orb {
350
- position: relative;
351
- width: 72px;
352
- height: 72px;
353
- border-radius: 50%;
354
- background:
355
- radial-gradient(circle at 30% 28%, var(--trillet-orb-2), transparent 58%),
356
- conic-gradient(from 0deg, var(--trillet-orb-1), var(--trillet-orb-2), var(--trillet-orb-1));
357
- box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
358
- animation: tw-orb-rotate 9s linear infinite;
528
+ .tw-status {
529
+ display: flex;
530
+ align-items: center;
531
+ gap: 6px;
532
+ font-size: 13px;
533
+ color: var(--tw-muted);
534
+ white-space: nowrap;
535
+ font-variant-numeric: tabular-nums;
359
536
  }
360
- /* Glossy highlight so the orb reads as a 3D sphere, not a flat disc. */
361
- .tw-orb::after {
537
+ .tw-status.tw-online::before {
362
538
  content: '';
363
- position: absolute;
364
- inset: 0;
539
+ width: 6px;
540
+ height: 6px;
365
541
  border-radius: 50%;
366
- background: radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.55), transparent 46%);
542
+ background: var(--tw-online);
367
543
  }
368
- /* When an avatar image is provided, show it instead of the gradient. */
369
- .tw-orb.tw-orb-avatar {
370
- background: none;
371
- background-size: cover;
372
- background-position: center;
373
- animation: none;
374
- }
375
- .tw-orb.tw-orb-avatar::after { display: none; }
544
+ .tw-brand-logo { height: 22px; max-width: 72px; object-fit: contain; }
545
+ .tw-header-actions { display: flex; gap: 2px; }
376
546
 
377
- @keyframes tw-orb-rotate { to { transform: rotate(360deg); } }
378
- @keyframes tw-aura {
379
- 0%, 100% { transform: scale(1); opacity: 0.4; }
380
- 50% { transform: scale(1.16); opacity: 0.66; }
381
- }
382
-
383
- /* Connecting: a pulsing ring around the orb. */
384
- .tw-orb-wrap.tw-connecting::after {
385
- content: '';
386
- position: absolute;
387
- width: 72px;
388
- height: 72px;
389
- border-radius: 50%;
390
- border: 2px solid var(--trillet-orb-1);
391
- animation: tw-pulse 1.4s ease-out infinite;
392
- }
393
- @keyframes tw-pulse {
394
- 0% { transform: scale(0.85); opacity: 0.7; }
395
- 100% { transform: scale(1.3); opacity: 0; }
547
+ .tw-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
548
+ .tw-center-body {
549
+ align-items: center;
550
+ justify-content: center;
551
+ gap: 12px;
552
+ padding: 24px;
553
+ text-align: center;
396
554
  }
555
+ .tw-prompt { margin: 4px 0 0; font-size: 16px; font-weight: 600; max-width: 260px; }
556
+ .tw-timer { font-size: 13px; color: var(--tw-muted); font-variant-numeric: tabular-nums; }
557
+ .tw-error-text { color: var(--tw-danger); }
558
+ .tw-choices, .tw-controls { display: flex; gap: 8px; width: 100%; justify-content: center; }
559
+ .tw-choices { flex-direction: column; max-width: 240px; margin-top: 4px; }
397
560
 
398
- /* Listening (live, not speaking): a slow calm breathe. */
399
- .tw-orb-wrap.tw-listening .tw-orb {
400
- animation: tw-orb-rotate 9s linear infinite, tw-breathe 3.6s ease-in-out infinite;
401
- }
402
- @keyframes tw-breathe {
403
- 0%, 100% { transform: scale(1); }
404
- 50% { transform: scale(1.03); }
561
+ /* ---- Chat ---- */
562
+ .tw-chat {
563
+ flex: 1;
564
+ min-height: 0;
565
+ overflow-y: auto;
566
+ display: flex;
567
+ flex-direction: column;
568
+ gap: 8px;
569
+ padding: 16px 14px 8px;
570
+ scroll-behavior: smooth;
405
571
  }
406
-
407
- /* Speaking: faster rotation + stronger bob, and a livelier aura. */
408
- .tw-orb-wrap.tw-speaking .tw-orb {
409
- animation: tw-orb-rotate 4.5s linear infinite, tw-bob 0.7s ease-in-out infinite alternate;
572
+ .tw-msg {
573
+ max-width: 84%;
574
+ padding: 8px 12px;
575
+ border-radius: 10px;
576
+ font-size: 15px;
577
+ line-height: 1.5;
578
+ white-space: pre-wrap;
579
+ overflow-wrap: anywhere;
410
580
  }
411
- .tw-orb-wrap.tw-speaking::before { animation: tw-aura 1.2s ease-in-out infinite; }
412
- @keyframes tw-bob {
413
- from { transform: scale(1); }
414
- to { transform: scale(1.08); }
581
+ .tw-msg.tw-run { margin-top: -2px; }
582
+ .tw-msg.tw-assistant {
583
+ align-self: flex-start;
584
+ background: var(--tw-raised);
585
+ border: 1px solid var(--tw-line);
586
+ color: var(--tw-ink);
415
587
  }
416
-
417
- .tw-status {
418
- font-size: 13px;
419
- color: var(--trillet-muted);
420
- min-height: 18px;
421
- text-align: center;
588
+ .tw-msg-label { font-size: 11px; color: var(--tw-muted); margin-bottom: 1px; }
589
+ .tw-msg.tw-user {
590
+ align-self: flex-end;
591
+ background: var(--tw-accent);
592
+ color: var(--tw-on-accent);
422
593
  }
423
- .tw-timer {
424
- font-size: 12px;
425
- color: var(--trillet-muted);
426
- font-variant-numeric: tabular-nums;
594
+ .tw-msg.tw-typing { display: inline-flex; gap: 4px; padding: 12px 13px; }
595
+ .tw-msg.tw-typing span {
596
+ width: 6px;
597
+ height: 6px;
598
+ border-radius: 50%;
599
+ background: var(--tw-muted);
600
+ animation: tw-typing 1.2s infinite ease-in-out;
427
601
  }
602
+ .tw-msg.tw-typing span:nth-child(2) { animation-delay: 0.15s; }
603
+ .tw-msg.tw-typing span:nth-child(3) { animation-delay: 0.3s; }
428
604
 
429
- /* ---- BYO reCAPTCHA gate ---- */
430
- /* The checkbox is a light-DOM node projected in via <slot name="recaptcha"> \u2014 it can't
431
- render directly in the shadow root (reCAPTCHA v2 hangs there). ::slotted targets that
432
- projected node. The checkbox iframe is a fixed 304x78; scale it down on narrow panels
433
- so it doesn't overflow. */
434
- .tw-recaptcha-slot {
435
- display: flex;
436
- justify-content: center;
437
- width: 100%;
438
- }
439
- ::slotted(.tw-recaptcha-mount) {
605
+ .tw-suggestions {
440
606
  display: flex;
441
- justify-content: center;
607
+ flex-wrap: wrap;
608
+ justify-content: flex-end;
609
+ gap: 6px;
610
+ padding: 2px 14px 10px;
442
611
  }
443
- @media (max-width: 340px) {
444
- ::slotted(.tw-recaptcha-mount) {
445
- transform: scale(0.85);
446
- transform-origin: center top;
447
- }
612
+ .tw-suggestion {
613
+ border: 1px solid var(--tw-line);
614
+ background: var(--tw-surface);
615
+ color: var(--tw-ink);
616
+ border-radius: 8px;
617
+ padding: 6px 11px;
618
+ font-size: 14px;
619
+ text-align: left;
620
+ cursor: pointer;
448
621
  }
622
+ .tw-suggestion:hover { border-color: var(--tw-accent); color: var(--tw-accent); }
449
623
 
450
- /* ---- Controls ---- */
451
- .tw-controls {
624
+ .tw-composer {
452
625
  display: flex;
453
- align-items: center;
454
- gap: 10px;
455
- width: 100%;
456
- justify-content: center;
457
- }
458
- .tw-controls.tw-controls-stack {
459
- flex-direction: column;
460
- gap: 8px;
626
+ align-items: flex-end;
627
+ gap: 6px;
628
+ margin: 0 12px;
629
+ padding: 5px 5px 5px 12px;
630
+ border: 1px solid var(--tw-line);
631
+ border-radius: 10px;
632
+ background: var(--tw-surface);
633
+ transition: border-color 0.15s ease;
461
634
  }
462
- .tw-controls-stack .tw-primary-btn { width: 100%; }
463
- .tw-primary-btn {
635
+ .tw-composer:focus-within { border-color: var(--tw-accent); }
636
+ .tw-text-input {
637
+ flex: 1;
638
+ min-width: 0;
464
639
  border: none;
465
- border-radius: 999px;
466
- padding: 11px 20px;
467
- font-size: 14px;
468
- font-weight: 600;
469
- cursor: pointer;
470
- background: var(--trillet-accent);
471
- color: #fff;
472
- transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
473
- }
474
- .tw-primary-btn:hover { opacity: 0.92; }
475
- .tw-primary-btn.tw-danger { background: #e5484d; }
476
- .tw-primary-btn.tw-secondary {
640
+ outline: none;
641
+ resize: none;
477
642
  background: transparent;
478
- color: var(--trillet-accent);
479
- border: 1px solid var(--trillet-border);
643
+ color: var(--tw-ink);
644
+ font: inherit;
645
+ font-size: 15px;
646
+ line-height: 1.4;
647
+ padding: 7px 0;
648
+ max-height: 112px;
480
649
  }
481
- .tw-primary-btn.tw-secondary:hover { background: rgba(0, 0, 0, 0.03); opacity: 1; }
482
- .tw-primary-btn:disabled { opacity: 0.6; cursor: default; }
483
- /* Subtle modality switch affordance (mode="both"). */
484
- .tw-switch-btn {
650
+ .tw-text-input:focus-visible { outline: none; }
651
+ .tw-text-input::placeholder { color: var(--tw-muted); }
652
+ .tw-send-btn {
653
+ width: 34px;
654
+ height: 34px;
655
+ flex-shrink: 0;
485
656
  border: none;
486
- background: none;
487
- color: var(--trillet-muted);
488
- font-size: 12px;
489
- font-weight: 500;
490
- cursor: pointer;
491
- padding: 2px 6px;
492
- text-decoration: underline;
493
- text-underline-offset: 2px;
494
- }
495
- .tw-switch-btn:hover { color: var(--trillet-accent); }
496
- .tw-mic-btn {
497
- border: 1px solid var(--trillet-border);
498
- background: var(--trillet-surface);
499
- color: var(--trillet-on-surface);
500
- border-radius: 50%;
501
- width: 42px;
502
- height: 42px;
503
- cursor: pointer;
657
+ border-radius: 8px;
658
+ background: var(--tw-accent);
659
+ color: var(--tw-on-accent);
504
660
  display: inline-flex;
505
661
  align-items: center;
506
662
  justify-content: center;
507
- font-size: 18px;
663
+ cursor: pointer;
508
664
  }
509
- .tw-mic-btn.tw-muted { color: #e5484d; border-color: #e5484d; }
665
+ .tw-send-btn svg { width: 17px; height: 17px; }
666
+ .tw-send-btn:disabled { opacity: 0.35; cursor: default; }
667
+ .tw-composer .tw-composer-mic { width: 34px; height: 34px; }
510
668
 
511
- /* ---- Text mode ---- */
512
- .tw-text-input-row {
669
+ .tw-voice-bar {
513
670
  display: flex;
514
- gap: 8px;
515
- width: 100%;
516
- }
517
- .tw-text-input {
518
- flex: 1;
519
- border: 1px solid var(--trillet-border);
671
+ align-items: center;
672
+ gap: 10px;
673
+ margin: 0 12px;
674
+ padding: 8px 8px 8px 10px;
675
+ border: 1px solid var(--tw-line);
520
676
  border-radius: 10px;
521
- padding: 9px 12px;
522
- font-size: 14px;
523
- font-family: inherit;
524
- color: var(--trillet-on-surface);
525
- background: var(--trillet-surface);
526
- outline: none;
677
+ background: var(--tw-raised);
527
678
  }
528
- .tw-text-input:focus { border-color: var(--trillet-accent); }
529
- .tw-send-btn {
530
- border: none;
531
- border-radius: 10px;
532
- padding: 0 14px;
533
- background: var(--trillet-accent);
534
- color: #fff;
535
- font-weight: 600;
536
- cursor: pointer;
679
+ .tw-voice-bar-text { flex: 1; min-width: 0; }
680
+ .tw-voice-bar-activity { font-size: 14px; font-weight: 600; }
681
+ .tw-voice-bar .tw-timer { font-size: 12px; }
682
+
683
+ .tw-notice {
684
+ margin: 0 12px 8px;
685
+ padding: 8px 12px;
686
+ border-radius: 8px;
687
+ border: 1px solid color-mix(in srgb, var(--tw-danger) 35%, var(--tw-line));
688
+ background: color-mix(in srgb, var(--tw-danger) 6%, var(--tw-surface));
689
+ font-size: 13px;
537
690
  }
538
691
 
539
- /* ---- Transcript ---- */
540
- .tw-transcript {
541
- width: 100%;
542
- max-height: 200px;
543
- overflow-y: auto;
692
+ .tw-chat-footer {
544
693
  display: flex;
545
- flex-direction: column;
546
- gap: 8px;
547
- padding-top: 4px;
548
- border-top: 1px solid var(--trillet-border);
549
- margin-top: 4px;
694
+ align-items: center;
695
+ justify-content: flex-end;
696
+ min-height: 30px;
697
+ padding: 2px 14px 6px;
698
+ }
699
+ .tw-chat-ended {
700
+ display: flex;
701
+ align-items: center;
702
+ justify-content: space-between;
703
+ gap: 10px;
704
+ margin: 4px 12px 12px;
705
+ padding: 10px 12px;
706
+ border-radius: 10px;
707
+ border: 1px solid var(--tw-line);
708
+ background: var(--tw-raised);
709
+ font-size: 14px;
710
+ color: var(--tw-muted);
550
711
  }
551
712
 
552
- /* ---- Chat window (text mode) ----
553
- A fixed-height, internally scrolling thread so the panel does NOT grow as
554
- messages arrive. Height is a sensible fixed value, capped to the viewport on
555
- short screens. Rendered (empty) as soon as the chat opens. */
556
- .tw-chat {
557
- height: min(380px, 60vh);
558
- max-height: none;
713
+ .tw-recaptcha-slot { display: flex; justify-content: center; }
714
+
715
+ /* ---- Markdown in agent messages / terms ---- */
716
+ .tw-md { white-space: normal; }
717
+ .tw-md p { margin: 0; }
718
+ .tw-md p + p, .tw-md p + ul, .tw-md p + ol, .tw-md ul + p, .tw-md ol + p { margin-top: 8px; }
719
+ .tw-md ul, .tw-md ol { margin: 0; padding-left: 20px; }
720
+ .tw-md li + li { margin-top: 2px; }
721
+ .tw-md a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
722
+ .tw-md code {
723
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
724
+ font-size: 0.88em;
725
+ padding: 1px 4px;
726
+ border-radius: 4px;
727
+ background: color-mix(in srgb, var(--tw-ink) 7%, transparent);
728
+ }
729
+
730
+ /* ---- Terms gate ---- */
731
+ .tw-terms { width: 320px; }
732
+ .tw-terms-body {
733
+ max-height: 220px;
559
734
  overflow-y: auto;
560
- padding: 10px;
561
- border: 1px solid var(--trillet-border);
562
- border-top: 1px solid var(--trillet-border);
563
- border-radius: 12px;
564
- margin-top: 0;
565
- background: rgba(0, 0, 0, 0.015);
566
- scroll-behavior: smooth;
735
+ font-size: 14px;
736
+ color: var(--tw-muted);
567
737
  }
568
- /* Faint empty state so the open (message-less) chat doesn't read as broken. */
569
- .tw-chat-empty {
570
- margin: auto;
571
- color: var(--trillet-muted);
572
- opacity: 0.45;
573
- font-size: 20px;
574
- letter-spacing: 2px;
738
+ .tw-terms .tw-pill {
739
+ flex: 1;
740
+ height: 40px;
741
+ border: none;
742
+ border-radius: 8px;
743
+ background: var(--tw-accent);
744
+ color: var(--tw-on-accent);
745
+ font-weight: 600;
746
+ cursor: pointer;
575
747
  }
576
- .tw-msg {
577
- padding: 8px 12px;
578
- border-radius: 12px;
579
- max-width: 85%;
748
+ .tw-terms .tw-secondary-btn { height: 40px; }
749
+
750
+ /* ---- Feedback ---- */
751
+ .tw-feedback {
752
+ display: flex;
753
+ align-items: center;
754
+ gap: 2px;
580
755
  font-size: 13px;
581
- white-space: pre-wrap;
582
- word-break: break-word;
756
+ color: var(--tw-muted);
583
757
  }
584
- .tw-msg.tw-user {
585
- align-self: flex-end;
586
- background: var(--trillet-accent);
587
- color: #fff;
588
- border-bottom-right-radius: 4px;
758
+ .tw-feedback span { margin-right: 6px; }
759
+ .tw-body .tw-feedback { padding: 0 14px 12px; }
760
+
761
+ /* ---- Motion ---- */
762
+ @keyframes tw-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
763
+ @keyframes tw-breathe { 0%, 100% { transform: scale(1.04); } 50% { transform: scale(1.16); } }
764
+ @keyframes tw-typing { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
765
+ @keyframes tw-spin { to { transform: rotate(360deg); } }
766
+ .tw-spin { transform-origin: 12px 12px; animation: tw-spin 0.9s linear infinite; }
767
+
768
+ @media (prefers-reduced-motion: reduce) {
769
+ .tw-enter, .tw-msg.tw-typing span, .tw-spin { animation: none; }
770
+ .tw-wave i { transition: none; }
589
771
  }
590
- .tw-msg.tw-assistant {
591
- align-self: flex-start;
592
- background: rgba(0, 0, 0, 0.05);
593
- color: var(--trillet-on-surface);
594
- border-bottom-left-radius: 4px;
772
+
773
+ /* Phones: the open panel takes the screen width. */
774
+ @media (max-width: 480px) {
775
+ :host { right: 12px; bottom: 12px; }
776
+ .tw-panel, .tw-panel.tw-expanded { width: calc(100vw - 24px); height: calc(100vh - 24px); }
595
777
  }
596
778
 
779
+ .tw-enter { animation: tw-rise 0.2s ease-out both; }
780
+
597
781
  .tw-hidden { display: none !important; }
598
782
  `
599
783
  );
@@ -645,6 +829,85 @@ async function renderRecaptchaCheckbox(options) {
645
829
  });
646
830
  }
647
831
 
832
+ // src/widget/markdown.ts
833
+ var INLINE = /(\*\*[^*\n]+\*\*|\*[^*\n]+\*|`[^`\n]+`|\[[^\]\n]+\]\((?:https?:\/\/)[^)\s]+\)|https?:\/\/[^\s<]+[^\s<.,;:!?)\]])/g;
834
+ function safeHref(raw) {
835
+ try {
836
+ const url = new URL(raw);
837
+ return url.protocol === "https:" || url.protocol === "http:" ? url.toString() : null;
838
+ } catch (e) {
839
+ return null;
840
+ }
841
+ }
842
+ function link(text, href) {
843
+ const safe = safeHref(href);
844
+ if (!safe) return document.createTextNode(text);
845
+ const a = document.createElement("a");
846
+ a.href = safe;
847
+ a.target = "_blank";
848
+ a.rel = "noopener noreferrer nofollow";
849
+ a.textContent = text;
850
+ return a;
851
+ }
852
+ function appendInline(parent, text) {
853
+ var _a;
854
+ let last = 0;
855
+ for (const match of text.matchAll(INLINE)) {
856
+ const token = match[0];
857
+ const index = (_a = match.index) != null ? _a : 0;
858
+ if (index > last) parent.appendChild(document.createTextNode(text.slice(last, index)));
859
+ if (token.startsWith("**")) {
860
+ const strong = document.createElement("strong");
861
+ strong.textContent = token.slice(2, -2);
862
+ parent.appendChild(strong);
863
+ } else if (token.startsWith("`")) {
864
+ const code = document.createElement("code");
865
+ code.textContent = token.slice(1, -1);
866
+ parent.appendChild(code);
867
+ } else if (token.startsWith("[")) {
868
+ const label = token.slice(1, token.indexOf("]("));
869
+ const href = token.slice(token.indexOf("](") + 2, -1);
870
+ parent.appendChild(link(label, href));
871
+ } else if (token.startsWith("*")) {
872
+ const em = document.createElement("em");
873
+ em.textContent = token.slice(1, -1);
874
+ parent.appendChild(em);
875
+ } else {
876
+ parent.appendChild(link(token, token));
877
+ }
878
+ last = index + token.length;
879
+ }
880
+ if (last < text.length) parent.appendChild(document.createTextNode(text.slice(last)));
881
+ }
882
+ function renderMarkdown(source) {
883
+ const fragment = document.createDocumentFragment();
884
+ const blocks = source.replace(/\r\n/g, "\n").split(/\n{2,}/);
885
+ for (const block of blocks) {
886
+ const lines = block.split("\n").filter((l) => l.trim() !== "");
887
+ if (!lines.length) continue;
888
+ const bullet = /^\s*[-*•]\s+/;
889
+ const numbered = /^\s*\d+[.)]\s+/;
890
+ if (lines.every((l) => bullet.test(l)) || lines.every((l) => numbered.test(l))) {
891
+ const ordered = numbered.test(lines[0]);
892
+ const list = document.createElement(ordered ? "ol" : "ul");
893
+ for (const line of lines) {
894
+ const li = document.createElement("li");
895
+ appendInline(li, line.replace(ordered ? numbered : bullet, ""));
896
+ list.appendChild(li);
897
+ }
898
+ fragment.appendChild(list);
899
+ continue;
900
+ }
901
+ const p = document.createElement("p");
902
+ lines.forEach((line, i) => {
903
+ if (i > 0) p.appendChild(document.createElement("br"));
904
+ appendInline(p, line);
905
+ });
906
+ fragment.appendChild(p);
907
+ }
908
+ return fragment;
909
+ }
910
+
648
911
  // src/widget/TrilletWidgetElement.ts
649
912
  var TrilletWidgetElement = class extends HTMLElement {
650
913
  constructor() {
@@ -665,6 +928,13 @@ var TrilletWidgetElement = class extends HTMLElement {
665
928
  // True while tearing down one modality and reconnecting in the other, so lifecycle
666
929
  // events (call-start/conversationStarted) aren't re-emitted for an internal switch.
667
930
  this.switching = false;
931
+ // Dashboard design (Widget designer), fetched on mount unless remote-config="false".
932
+ // Attributes always win over it; see configFromElement.
933
+ this.remote = null;
934
+ this.remoteDisplay = null;
935
+ this.remoteLoadedFor = null;
936
+ // A suggested prompt clicked before the chat finished connecting; sent on connect.
937
+ this.pendingMessage = null;
668
938
  // maxCallDuration countdown (UX only — see startConversation()).
669
939
  this.durationTimer = null;
670
940
  this.remainingSeconds = null;
@@ -683,6 +953,25 @@ var TrilletWidgetElement = class extends HTMLElement {
683
953
  this.recaptchaSolved = false;
684
954
  this.recaptchaSlot = null;
685
955
  this.recaptchaWidgetId = null;
956
+ this.pendingTimer = null;
957
+ // Which top-level view is on screen; the entrance animation only plays on a change.
958
+ this.lastView = null;
959
+ // Inline notice in the chat (e.g. microphone refused). Cleared on the next switch.
960
+ this.notice = null;
961
+ this.switchingSide = false;
962
+ this.smoothedLevel = 0;
963
+ // ---- Terms gate + feedback --------------------------------------------------
964
+ this.showTerms = false;
965
+ this.pendingStart = null;
966
+ this.callId = null;
967
+ this.feedbackState = "hidden";
968
+ // Fallback when storage is blocked: accepted for the life of this page.
969
+ this.termsAcceptedThisPage = false;
970
+ this.askFocused = false;
971
+ // Last start/connection failure, shown instead of the "ended" line.
972
+ this.errorText = null;
973
+ // Half-typed message, kept across full re-renders (connecting -> live, etc.).
974
+ this.draft = "";
686
975
  this.root = this.attachShadow({ mode: "open" });
687
976
  this.styleEl = document.createElement("style");
688
977
  this.styleEl.textContent = WIDGET_STYLES;
@@ -695,11 +984,37 @@ var TrilletWidgetElement = class extends HTMLElement {
695
984
  return OBSERVED_ATTRIBUTES;
696
985
  }
697
986
  connectedCallback() {
698
- this.config = configFromElement(this);
987
+ this.refreshConfig();
988
+ void this.loadRemoteConfig();
989
+ }
990
+ refreshConfig() {
991
+ this.config = configFromElement(this, this.remote);
699
992
  this.syncActiveMode();
700
993
  this.applyTheme();
701
994
  this.render();
702
995
  }
996
+ /**
997
+ * Fetch the design saved in the dashboard. Best-effort: on any failure the widget
998
+ * keeps rendering from its attributes, exactly as before this existed.
999
+ */
1000
+ async loadRemoteConfig() {
1001
+ var _a, _b;
1002
+ const { agentId, remoteConfig, apiBase } = this.config;
1003
+ if (!remoteConfig || !agentId || this.remoteLoadedFor === agentId) return;
1004
+ this.remoteLoadedFor = agentId;
1005
+ try {
1006
+ const url = `${apiUrl("/v1/api/web-call/public/widget-config", apiBase)}?agent_id=${encodeURIComponent(agentId)}`;
1007
+ const res = await fetch(url, { headers: { Accept: "application/json" } });
1008
+ if (!res.ok) return;
1009
+ const data = await res.json();
1010
+ if (this.config.agentId !== agentId) return;
1011
+ this.remote = (_a = data.widget) != null ? _a : null;
1012
+ this.remoteDisplay = (_b = data.display) != null ? _b : null;
1013
+ if (this.state === "idle") this.refreshConfig();
1014
+ } catch (error) {
1015
+ console.warn("[trillet-widget] Could not load widget design; using attributes only", error);
1016
+ }
1017
+ }
703
1018
  disconnectedCallback() {
704
1019
  this.clearDurationTimer();
705
1020
  this.teardownAgent();
@@ -707,10 +1022,25 @@ var TrilletWidgetElement = class extends HTMLElement {
707
1022
  }
708
1023
  attributeChangedCallback() {
709
1024
  if (!this.isConnected) return;
710
- this.config = configFromElement(this);
711
- this.syncActiveMode();
712
- this.applyTheme();
713
- this.render();
1025
+ this.refreshConfig();
1026
+ void this.loadRemoteConfig();
1027
+ }
1028
+ /**
1029
+ * Send a chat message as the visitor (text sessions). Opens and starts the chat
1030
+ * first when needed; the message is delivered as soon as the session connects.
1031
+ */
1032
+ async sendMessage(text) {
1033
+ var _a;
1034
+ const message = text.trim();
1035
+ if (!message) return;
1036
+ if (this.state === "live" && (this.resolvedMode() === "text" || this.config.mode === "both")) {
1037
+ await ((_a = this.agent) == null ? void 0 : _a.sendTextMessage(message));
1038
+ return;
1039
+ }
1040
+ if (this.config.mode === "voice") return;
1041
+ if (this.state === "idle" || this.state === "ended") this.transcripts = [];
1042
+ this.pendingMessage = message;
1043
+ if (this.state !== "connecting") await this.startConversation("text");
714
1044
  }
715
1045
  // ---- Public element API ----------------------------------------------------
716
1046
  /**
@@ -719,7 +1049,10 @@ var TrilletWidgetElement = class extends HTMLElement {
719
1049
  */
720
1050
  async startConversation(modality) {
721
1051
  if (this.state === "connecting" || this.state === "live") return;
722
- this.open = true;
1052
+ const chat = this.config.mode === "text" || this.config.mode === "both" && modality !== "voice";
1053
+ if (chat) {
1054
+ this.open = true;
1055
+ }
723
1056
  if (this.needsRecaptcha()) {
724
1057
  this.render();
725
1058
  return;
@@ -766,32 +1099,72 @@ var TrilletWidgetElement = class extends HTMLElement {
766
1099
  this.agent = null;
767
1100
  }
768
1101
  /**
769
- * Switch modality mid-session (mode="both"). Because the core binds `mode` at
770
- * construction, this ends the current `TrilletAgent` and constructs a fresh one in
771
- * the other modality, rejoining via the same credential path. Transcripts and the
772
- * duration timer are preserved across the switch; no lifecycle events fire (it's one
773
- * conversation from the consumer's perspective).
1102
+ * Switch between typing and talking (mode="both"). Same session, same conversation:
1103
+ * the SDK turns the mic on/off and asks the agent to turn its speech on/off. If the
1104
+ * mic is refused, the conversation simply stays in text and says why.
774
1105
  */
775
1106
  async switchModality() {
776
- if (this.config.mode !== "both" || this.state !== "live") return;
777
- const target = this.resolvedMode() === "voice" ? "text" : "voice";
778
- this.switching = true;
779
- this.clearDurationTimer();
780
- this.speaking = false;
781
- this.teardownAgent();
782
- await this.beginCall(target);
1107
+ if (this.config.mode !== "both" || this.state !== "live" || !this.agent) return;
1108
+ const toVoice = this.resolvedMode() === "text";
1109
+ this.notice = null;
1110
+ this.switchingSide = true;
1111
+ this.render();
1112
+ try {
1113
+ await this.agent.setVoiceEnabled(toVoice);
1114
+ } catch (error) {
1115
+ console.warn("[trillet-widget] Could not switch modality", error);
1116
+ this.notice = toVoice ? "Could not turn on your microphone. Check the browser permission and try again." : "Could not switch back to typing. Please try again.";
1117
+ } finally {
1118
+ this.switchingSide = false;
1119
+ this.render();
1120
+ }
1121
+ }
1122
+ /**
1123
+ * Listening <-> Speaking flips several times a second at turn edges. Patch the few
1124
+ * nodes that show it instead of re-rendering, which would rebuild (and flash) the UI.
1125
+ */
1126
+ setSpeaking(speaking) {
1127
+ if (this.speaking === speaking) return;
1128
+ this.speaking = speaking;
1129
+ const activity = speaking ? this.config.speakingText : this.config.listeningText;
1130
+ this.root.querySelectorAll(".tw-callbar-activity").forEach((el) => {
1131
+ el.textContent = activity;
1132
+ });
1133
+ this.root.querySelectorAll(".tw-wave").forEach((el) => el.classList.toggle("tw-wave-speaking", speaking));
1134
+ this.root.querySelectorAll(".tw-mark").forEach((el) => el.classList.toggle("tw-speaking", speaking));
1135
+ const status = this.root.querySelector(".tw-header .tw-status");
1136
+ if (status) status.textContent = this.statusText();
1137
+ }
1138
+ /** Send the message typed before the chat started (once). */
1139
+ flushPending() {
1140
+ if (this.pendingTimer) clearTimeout(this.pendingTimer);
1141
+ this.pendingTimer = null;
1142
+ const queued = this.pendingMessage;
1143
+ this.pendingMessage = null;
1144
+ if (queued && this.agent && this.state === "live") void this.agent.sendTextMessage(queued);
783
1145
  }
784
1146
  // ---- Credential resolution + call lifecycle --------------------------------
785
1147
  async beginCall(modality) {
1148
+ if (this.config.termsText && !this.termsAccepted()) {
1149
+ this.pendingStart = modality != null ? modality : this.resolvedMode();
1150
+ this.showTerms = true;
1151
+ this.render();
1152
+ return;
1153
+ }
1154
+ this.feedbackState = "hidden";
786
1155
  if (modality) this.activeMode = modality;
787
1156
  const mode = this.resolvedMode();
1157
+ const session = this.config.mode === "both" ? "multimodal" : mode;
1158
+ this.notice = null;
788
1159
  if (!this.switching) this.display = null;
789
1160
  this.setState("connecting");
790
1161
  try {
791
1162
  const agent = new TrilletAgent({
792
1163
  agentId: this.config.agentId,
793
1164
  workspaceId: this.config.workspaceId,
794
- mode,
1165
+ apiBaseUrl: this.config.apiBase,
1166
+ mode: session,
1167
+ startWithVoice: session === "multimodal" && mode === "voice",
795
1168
  variables: this.config.variables
796
1169
  });
797
1170
  this.agent = agent;
@@ -799,7 +1172,7 @@ var TrilletWidgetElement = class extends HTMLElement {
799
1172
  if (this.config.signedUrlEndpoint || this.getRoomDetails) {
800
1173
  let details;
801
1174
  if (this.getRoomDetails) {
802
- details = await this.getRoomDetails();
1175
+ details = await this.getRoomDetails({ mode, session });
803
1176
  } else {
804
1177
  const res = await fetch(this.config.signedUrlEndpoint, {
805
1178
  method: "GET",
@@ -826,12 +1199,16 @@ var TrilletWidgetElement = class extends HTMLElement {
826
1199
  }
827
1200
  wireAgentEvents(agent) {
828
1201
  agent.on("connected", (details) => {
829
- var _a;
1202
+ var _a, _b;
830
1203
  this.display = (_a = details == null ? void 0 : details.display) != null ? _a : null;
1204
+ this.callId = (_b = details == null ? void 0 : details.callId) != null ? _b : null;
831
1205
  const wasSwitching = this.switching;
832
1206
  this.setState("live");
833
1207
  this.startDurationTimer(!wasSwitching);
834
1208
  this.switching = false;
1209
+ if (this.pendingMessage) {
1210
+ this.pendingTimer = setTimeout(() => this.flushPending(), 25e3);
1211
+ }
835
1212
  });
836
1213
  agent.on("disconnected", () => {
837
1214
  this.endLocalCall();
@@ -839,32 +1216,45 @@ var TrilletWidgetElement = class extends HTMLElement {
839
1216
  agent.on("error", (error) => {
840
1217
  this.handleError(error);
841
1218
  });
842
- agent.on("assistantStartedSpeaking", () => {
843
- this.speaking = true;
844
- this.render();
845
- });
846
- agent.on("assistantStoppedSpeaking", () => {
1219
+ agent.on("modalityChanged", (side) => {
1220
+ this.activeMode = side;
847
1221
  this.speaking = false;
1222
+ this.dispatch("modality", side);
848
1223
  this.render();
849
1224
  });
1225
+ agent.on("audioData", (samples) => this.setLevel(samples));
1226
+ agent.on("assistantStartedSpeaking", () => this.setSpeaking(true));
1227
+ agent.on("assistantStoppedSpeaking", () => this.setSpeaking(false));
850
1228
  agent.on("transcriptUpdate", (transcripts) => {
851
- this.transcripts = transcripts;
852
- this.dispatch("transcript", transcripts);
853
- this.render();
1229
+ this.transcripts = [...transcripts];
1230
+ if (this.pendingMessage && transcripts.some((t) => t.role === "assistant" && !t.toolUsed)) {
1231
+ this.flushPending();
1232
+ }
1233
+ this.dispatch("transcript", this.transcripts);
1234
+ if (!this.updateThread()) this.render();
854
1235
  });
855
1236
  }
856
1237
  endLocalCall() {
857
1238
  if (this.state === "ended" || this.state === "idle") return;
1239
+ if (this.config.feedback === "end" && this.callId && this.elapsedSeconds >= 5) {
1240
+ this.feedbackState = "ask";
1241
+ }
858
1242
  this.clearDurationTimer();
1243
+ this.speaking = false;
859
1244
  this.dispatch("call-end", this.elapsedSeconds);
860
1245
  this.dispatch("conversationEnded", this.elapsedSeconds);
861
1246
  this.setState("ended");
862
1247
  this.agent = null;
1248
+ this.pendingMessage = null;
1249
+ if (this.pendingTimer) clearTimeout(this.pendingTimer);
1250
+ this.pendingTimer = null;
863
1251
  if (this.config.mode === "both") this.activeMode = null;
864
1252
  }
865
1253
  handleError(error) {
866
1254
  const err = error instanceof Error ? error : new Error(String(error));
1255
+ this.errorText = friendlyError(err);
867
1256
  this.clearDurationTimer();
1257
+ this.speaking = false;
868
1258
  this.switching = false;
869
1259
  this.dispatch("error", err);
870
1260
  this.agent = null;
@@ -903,6 +1293,7 @@ var TrilletWidgetElement = class extends HTMLElement {
903
1293
  // ---- State + DOM events ----------------------------------------------------
904
1294
  setState(state) {
905
1295
  const prev = this.state;
1296
+ if (state === "connecting") this.errorText = null;
906
1297
  this.state = state;
907
1298
  if (state === "live" && prev !== "live" && !this.switching) {
908
1299
  this.dispatch("call-start", void 0);
@@ -915,16 +1306,21 @@ var TrilletWidgetElement = class extends HTMLElement {
915
1306
  }
916
1307
  // ---- Theming ----------------------------------------------------------------
917
1308
  applyTheme() {
918
- const orb1 = this.config.orbColor1 || DEFAULT_ORB_COLOR_1;
919
- const orb2 = this.config.orbColor2 || DEFAULT_ORB_COLOR_2;
920
- this.style.setProperty("--trillet-orb-1", orb1);
921
- this.style.setProperty("--trillet-orb-2", orb2);
922
- const accent = this.config.brand.primaryColor || this.config.orbColor1;
923
- if (accent) {
924
- this.style.setProperty("--trillet-accent", accent);
925
- } else {
926
- this.style.removeProperty("--trillet-accent");
927
- }
1309
+ const accent = this.config.brand.primaryColor || this.config.orbColor1 || DEFAULT_ACCENT;
1310
+ this.style.setProperty("--tw-accent", accent);
1311
+ this.style.setProperty("--tw-on-accent", readableOn(accent));
1312
+ const custom = this.config.backgroundColor || this.config.textColor;
1313
+ const setOrClear = (name, value) => value ? this.style.setProperty(name, value) : this.style.removeProperty(name);
1314
+ setOrClear("--tw-surface", this.config.backgroundColor);
1315
+ setOrClear("--tw-ink", this.config.textColor);
1316
+ setOrClear("--tw-raised", custom ? "color-mix(in srgb, var(--tw-ink) 7%, var(--tw-surface))" : void 0);
1317
+ setOrClear("--tw-line", custom ? "color-mix(in srgb, var(--tw-ink) 14%, var(--tw-surface))" : void 0);
1318
+ setOrClear("--tw-muted", custom ? "color-mix(in srgb, var(--tw-ink) 62%, var(--tw-surface))" : void 0);
1319
+ if (this.config.buttonTextColor) this.style.setProperty("--tw-on-accent", this.config.buttonTextColor);
1320
+ this.style.setProperty("--tw-orb-1", this.config.orbColor1 || accent);
1321
+ this.style.setProperty("--tw-orb-2", this.config.orbColor2 || "#27a3fd");
1322
+ this.dataset.placement = this.config.placement;
1323
+ this.dataset.theme = this.config.theme;
928
1324
  }
929
1325
  // ---- Rendering --------------------------------------------------------------
930
1326
  formatTime(total) {
@@ -932,23 +1328,22 @@ var TrilletWidgetElement = class extends HTMLElement {
932
1328
  const s = total % 60;
933
1329
  return `${m}:${s.toString().padStart(2, "0")}`;
934
1330
  }
1331
+ /** The line under the agent's name in the header. */
935
1332
  statusText() {
936
- switch (this.state) {
937
- case "connecting":
938
- return "Connecting\u2026";
939
- case "live":
940
- return this.speaking ? this.config.speakingText : this.config.listeningText;
941
- case "ended":
942
- return "Call ended";
943
- default:
944
- return this.config.actionText || "";
1333
+ if (this.state === "connecting") return "Connecting\u2026";
1334
+ if (this.state === "live" && this.resolvedMode() === "voice") {
1335
+ const activity = this.speaking ? this.config.speakingText : this.config.listeningText;
1336
+ return `${activity} ${this.timerText()}`.trim();
945
1337
  }
1338
+ if (this.state === "live") return "Online";
1339
+ return this.config.brand.name || "Online";
946
1340
  }
947
1341
  renderStatus() {
948
1342
  const statusEl = this.root.querySelector(".tw-status");
949
1343
  if (statusEl) statusEl.textContent = this.statusText();
950
- const timerEl = this.root.querySelector(".tw-timer");
951
- if (timerEl) timerEl.textContent = this.timerText();
1344
+ this.root.querySelectorAll(".tw-timer").forEach((el) => {
1345
+ el.textContent = el.classList.contains("tw-callbar-meta") ? [this.speakerName(), this.timerText()].filter(Boolean).join(" \xB7 ") : this.timerText();
1346
+ });
952
1347
  }
953
1348
  timerText() {
954
1349
  if (this.state !== "live") return "";
@@ -957,37 +1352,329 @@ var TrilletWidgetElement = class extends HTMLElement {
957
1352
  }
958
1353
  return this.formatTime(this.elapsedSeconds);
959
1354
  }
1355
+ /**
1356
+ * Agent voice level (0..1) from the live audio. Written straight to a CSS variable
1357
+ * on the host, so the presence ring moves with the real voice without re-rendering.
1358
+ */
1359
+ setLevel(samples) {
1360
+ let sum = 0;
1361
+ for (let i = 0; i < samples.length; i += 1) sum += samples[i] * samples[i];
1362
+ const rms = Math.sqrt(sum / (samples.length || 1));
1363
+ const level = Math.min(1, rms * 6);
1364
+ this.smoothedLevel = this.smoothedLevel * 0.7 + level * 0.3;
1365
+ this.style.setProperty("--tw-level", this.smoothedLevel.toFixed(3));
1366
+ }
960
1367
  render() {
961
1368
  this.container.replaceChildren();
962
- if (!this.open) {
963
- this.container.appendChild(this.renderLauncher());
964
- return;
1369
+ let view;
1370
+ let el;
1371
+ if (this.showTerms) {
1372
+ view = "terms";
1373
+ el = this.renderTerms();
1374
+ } else if (this.open) {
1375
+ view = "panel";
1376
+ el = this.renderPanel();
1377
+ } else {
1378
+ el = this.renderCard();
1379
+ view = el.querySelector(".tw-callbar") ? "callbar" : "bar";
965
1380
  }
966
- this.container.appendChild(this.renderPanel());
1381
+ if (view !== this.lastView) el.classList.add("tw-enter");
1382
+ this.lastView = view;
1383
+ this.container.appendChild(el);
1384
+ }
1385
+ // ---- Shared building blocks ---------------------------------------------------
1386
+ /** Avatar style: an explicit choice, else the image when one is set, else the orb. */
1387
+ avatarStyle() {
1388
+ const chosen = this.config.avatarStyle;
1389
+ if (chosen === "image" && !this.config.avatar) return "orb";
1390
+ if (chosen) return chosen;
1391
+ return this.config.avatar ? "image" : "orb";
1392
+ }
1393
+ /**
1394
+ * The mark: who the visitor is talking to, as a small rounded tile. A gradient in
1395
+ * the brand colours (default), the business's image, or initials. While the agent
1396
+ * speaks on a call, the tile breathes with the voice level (--tw-level).
1397
+ */
1398
+ buildAvatar(size) {
1399
+ const mark = document.createElement("span");
1400
+ const style = this.avatarStyle();
1401
+ mark.className = `tw-mark tw-mark-${size} tw-mark-${style}`;
1402
+ mark.setAttribute("aria-hidden", "true");
1403
+ if (this.state === "live" && this.resolvedMode() === "voice") mark.classList.add("tw-voice-live");
1404
+ if (style === "image") mark.style.backgroundImage = `url("${this.config.avatar}")`;
1405
+ else if (style === "initials") mark.textContent = initials(this.speakerName());
1406
+ return mark;
1407
+ }
1408
+ /** The name shown to visitors: business name, else the agent/flow name. */
1409
+ speakerName() {
1410
+ return this.config.brand.name || this.headerTitle() || "";
967
1411
  }
968
- renderLauncher() {
1412
+ /** Live voice level as five bars (heights follow --tw-level). */
1413
+ buildWave() {
1414
+ const wave = document.createElement("span");
1415
+ wave.className = `tw-wave${this.speaking ? " tw-wave-speaking" : ""}`;
1416
+ wave.setAttribute("aria-hidden", "true");
1417
+ for (let n = 0; n < 5; n += 1) wave.appendChild(document.createElement("i"));
1418
+ return wave;
1419
+ }
1420
+ iconButton(icon, label, onClick, extraClass = "") {
969
1421
  const btn = document.createElement("button");
970
- btn.className = "tw-launcher";
971
1422
  btn.type = "button";
972
- const orb = document.createElement("span");
973
- orb.className = "tw-launcher-orb";
974
- if (this.config.avatar) {
975
- orb.classList.add("tw-launcher-orb-avatar");
976
- orb.style.backgroundImage = `url("${this.config.avatar}")`;
1423
+ btn.className = `tw-icon-btn ${extraClass}`.trim();
1424
+ btn.title = label;
1425
+ btn.setAttribute("aria-label", label);
1426
+ btn.innerHTML = icon;
1427
+ btn.addEventListener("click", onClick);
1428
+ return btn;
1429
+ }
1430
+ /** Acceptance is remembered per agent and per version of the text. */
1431
+ termsKey() {
1432
+ let hash = 0;
1433
+ for (const ch of this.config.termsText || "") hash = hash * 31 + ch.charCodeAt(0) | 0;
1434
+ return `trillet-terms:${this.config.agentId}:${hash}`;
1435
+ }
1436
+ termsAccepted() {
1437
+ if (this.termsAcceptedThisPage) return true;
1438
+ try {
1439
+ return window.localStorage.getItem(this.termsKey()) === "1";
1440
+ } catch (e) {
1441
+ return false;
977
1442
  }
978
- btn.appendChild(orb);
979
- const label = document.createElement("span");
980
- label.textContent = this.config.actionText || this.config.startCallText;
981
- btn.appendChild(label);
982
- btn.addEventListener("click", () => {
983
- this.open = true;
1443
+ }
1444
+ renderTerms() {
1445
+ const card = document.createElement("div");
1446
+ card.className = "tw-card tw-terms";
1447
+ card.setAttribute("role", "dialog");
1448
+ card.setAttribute("aria-label", "Terms");
1449
+ const title = document.createElement("div");
1450
+ title.className = "tw-card-title";
1451
+ title.textContent = "Before we start";
1452
+ card.appendChild(title);
1453
+ const body = document.createElement("div");
1454
+ body.className = "tw-terms-body tw-md";
1455
+ body.appendChild(renderMarkdown(this.config.termsText || ""));
1456
+ card.appendChild(body);
1457
+ const row = document.createElement("div");
1458
+ row.className = "tw-card-actions";
1459
+ const accept = document.createElement("button");
1460
+ accept.type = "button";
1461
+ accept.className = "tw-pill";
1462
+ accept.textContent = "Agree and continue";
1463
+ accept.addEventListener("click", () => {
1464
+ try {
1465
+ window.localStorage.setItem(this.termsKey(), "1");
1466
+ } catch (e) {
1467
+ }
1468
+ this.termsAcceptedThisPage = true;
1469
+ this.showTerms = false;
1470
+ const start = this.pendingStart;
1471
+ this.pendingStart = null;
1472
+ if (start === "text") this.open = true;
1473
+ void this.beginCall(start != null ? start : void 0);
1474
+ });
1475
+ const decline = document.createElement("button");
1476
+ decline.type = "button";
1477
+ decline.className = "tw-secondary-btn";
1478
+ decline.textContent = "Not now";
1479
+ decline.addEventListener("click", () => {
1480
+ this.showTerms = false;
1481
+ this.pendingStart = null;
1482
+ this.open = false;
984
1483
  this.render();
985
1484
  });
986
- return btn;
1485
+ row.appendChild(accept);
1486
+ row.appendChild(decline);
1487
+ card.appendChild(row);
1488
+ return card;
1489
+ }
1490
+ /** "How was this conversation?" thumbs, once, after a conversation ends. */
1491
+ renderFeedback() {
1492
+ if (this.feedbackState === "hidden") return null;
1493
+ const row = document.createElement("div");
1494
+ row.className = "tw-feedback";
1495
+ if (this.feedbackState === "sent") {
1496
+ row.textContent = "Thanks for the feedback.";
1497
+ return row;
1498
+ }
1499
+ const label = document.createElement("span");
1500
+ label.textContent = "How was this conversation?";
1501
+ row.appendChild(label);
1502
+ const send = (rating) => {
1503
+ this.feedbackState = "sent";
1504
+ this.render();
1505
+ fetch(apiUrl("/v1/api/web-call/public/feedback", this.config.apiBase), {
1506
+ method: "POST",
1507
+ headers: { "Content-Type": "application/json" },
1508
+ body: JSON.stringify({ call_id: this.callId, rating })
1509
+ }).catch(() => void 0);
1510
+ this.dispatch("feedback", rating);
1511
+ };
1512
+ row.appendChild(this.iconButton(ICONS.thumbUp, "Good", () => send("up")));
1513
+ row.appendChild(this.iconButton(ICONS.thumbDown, "Not good", () => send("down")));
1514
+ return row;
1515
+ }
1516
+ /**
1517
+ * The ask bar: the widget's resting state.
1518
+ *
1519
+ * [mark] Ask Firelink anything… (mic) (send)
1520
+ *
1521
+ * Input-first: typing + Enter opens the chat with that message already sent; the
1522
+ * mic starts a call and the bar becomes the call bar. Voice-only shows "Talk to …"
1523
+ * with a call button; chat-only drops the mic.
1524
+ */
1525
+ renderCard() {
1526
+ const idle = this.state === "idle" || this.state === "ended";
1527
+ const live = this.state === "live";
1528
+ const voiceLive = live && this.resolvedMode() === "voice";
1529
+ const voiceStarting = this.state === "connecting" && this.resolvedMode() === "voice";
1530
+ const gated = this.needsRecaptcha() && idle;
1531
+ const stack = document.createElement("div");
1532
+ stack.className = "tw-bar-stack";
1533
+ if (voiceLive || voiceStarting) {
1534
+ stack.appendChild(this.renderVoiceBar(false));
1535
+ return stack;
1536
+ }
1537
+ if (this.errorText && idle) {
1538
+ const err = document.createElement("div");
1539
+ err.className = "tw-bar-note tw-error-text";
1540
+ err.textContent = this.errorText;
1541
+ stack.appendChild(err);
1542
+ }
1543
+ const bar = document.createElement("div");
1544
+ bar.className = "tw-ask";
1545
+ bar.appendChild(this.buildAvatar("md"));
1546
+ const name = this.speakerName();
1547
+ const canChat = this.config.mode !== "voice";
1548
+ const canTalk = this.config.mode !== "text";
1549
+ if (live || this.state === "connecting") {
1550
+ const back = document.createElement("button");
1551
+ back.type = "button";
1552
+ back.className = "tw-ask-label";
1553
+ back.textContent = name ? `Chat with ${name}` : "Back to chat";
1554
+ back.addEventListener("click", () => this.openPanel());
1555
+ bar.appendChild(back);
1556
+ bar.appendChild(this.iconButton(ICONS.chat, "Open the chat", () => this.openPanel(), "tw-sq tw-sq-accent"));
1557
+ stack.appendChild(bar);
1558
+ return stack;
1559
+ }
1560
+ if (!canChat) {
1561
+ const label = document.createElement("button");
1562
+ label.type = "button";
1563
+ label.className = "tw-ask-label";
1564
+ label.textContent = this.config.greeting || (name ? `Talk to ${name}` : this.config.startCallText);
1565
+ label.disabled = gated;
1566
+ label.addEventListener("click", () => {
1567
+ if (!this.needsRecaptcha()) void this.beginCall("voice");
1568
+ });
1569
+ bar.appendChild(label);
1570
+ const call = this.iconButton(ICONS.phone, this.config.actionText || this.config.startCallText, () => {
1571
+ if (!this.needsRecaptcha()) void this.beginCall("voice");
1572
+ }, "tw-sq tw-sq-accent");
1573
+ call.disabled = gated;
1574
+ bar.appendChild(call);
1575
+ } else {
1576
+ const form = document.createElement("form");
1577
+ form.className = "tw-ask-form";
1578
+ const input = document.createElement("input");
1579
+ input.className = "tw-ask-input";
1580
+ input.type = "text";
1581
+ input.placeholder = this.config.greeting || (name ? `Ask ${name} anything\u2026` : "Ask anything\u2026");
1582
+ input.setAttribute("aria-label", input.placeholder);
1583
+ input.value = this.draft;
1584
+ input.disabled = gated;
1585
+ const send = this.iconButton(ICONS.send, "Send", () => void 0, "tw-sq tw-sq-accent");
1586
+ send.type = "submit";
1587
+ const sync = () => {
1588
+ send.disabled = gated || !input.value.trim();
1589
+ };
1590
+ input.addEventListener("input", () => {
1591
+ this.draft = input.value;
1592
+ sync();
1593
+ });
1594
+ input.addEventListener("focus", () => {
1595
+ this.askFocused = true;
1596
+ this.renderAskSuggestions(stack, bar);
1597
+ });
1598
+ input.addEventListener("blur", () => {
1599
+ this.askFocused = false;
1600
+ setTimeout(() => {
1601
+ var _a;
1602
+ if (!this.askFocused) (_a = stack.querySelector(".tw-ask-suggestions")) == null ? void 0 : _a.remove();
1603
+ }, 150);
1604
+ });
1605
+ form.addEventListener("submit", (e) => {
1606
+ e.preventDefault();
1607
+ const text = input.value.trim();
1608
+ if (!text || this.needsRecaptcha()) return;
1609
+ this.draft = "";
1610
+ void this.sendMessage(text);
1611
+ });
1612
+ form.appendChild(input);
1613
+ if (canTalk) {
1614
+ const call = this.iconButton(ICONS.phone, this.config.actionText || this.config.startCallText, () => {
1615
+ if (!this.needsRecaptcha()) void this.beginCall("voice");
1616
+ }, "tw-sq tw-sq-quiet");
1617
+ call.disabled = gated;
1618
+ form.appendChild(call);
1619
+ }
1620
+ form.appendChild(send);
1621
+ sync();
1622
+ bar.appendChild(form);
1623
+ }
1624
+ stack.appendChild(bar);
1625
+ if (gated) {
1626
+ const slot = document.createElement("slot");
1627
+ slot.setAttribute("name", "recaptcha");
1628
+ slot.className = "tw-recaptcha-slot";
1629
+ stack.insertBefore(slot, bar);
1630
+ this.ensureRecaptchaSlot();
1631
+ }
1632
+ const feedback = idle ? this.renderFeedback() : null;
1633
+ if (feedback) {
1634
+ feedback.classList.add("tw-bar-note");
1635
+ stack.insertBefore(feedback, bar);
1636
+ }
1637
+ return stack;
1638
+ }
1639
+ /** Suggested questions just above the ask bar while it has focus. */
1640
+ renderAskSuggestions(stack, bar) {
1641
+ if (!this.config.suggestedPrompts.length || stack.querySelector(".tw-ask-suggestions")) return;
1642
+ const row = document.createElement("div");
1643
+ row.className = "tw-ask-suggestions";
1644
+ for (const prompt of this.config.suggestedPrompts) {
1645
+ const chip = document.createElement("button");
1646
+ chip.type = "button";
1647
+ chip.className = "tw-suggestion";
1648
+ chip.textContent = prompt;
1649
+ chip.addEventListener("mousedown", (e) => {
1650
+ e.preventDefault();
1651
+ this.askFocused = false;
1652
+ void this.sendMessage(prompt);
1653
+ });
1654
+ row.appendChild(chip);
1655
+ }
1656
+ stack.insertBefore(row, bar);
1657
+ }
1658
+ /**
1659
+ * Open the panel. A text-only widget starts the chat straight away, so the agent's
1660
+ * welcome is already there when the panel opens, like any website chat. `both`
1661
+ * waits for the visitor to pick call or message.
1662
+ */
1663
+ openPanel() {
1664
+ this.open = true;
1665
+ const idle = this.state === "idle" || this.state === "ended";
1666
+ if (this.config.mode === "text" && idle && !this.needsRecaptcha()) {
1667
+ this.transcripts = [];
1668
+ void this.beginCall("text");
1669
+ return;
1670
+ }
1671
+ this.render();
987
1672
  }
988
1673
  renderPanel() {
989
1674
  const panel = document.createElement("div");
990
1675
  panel.className = `tw-panel${this.config.variant === "expanded" ? " tw-expanded" : ""}`;
1676
+ panel.setAttribute("role", "dialog");
1677
+ panel.setAttribute("aria-label", this.headerTitle() || "Chat");
991
1678
  panel.appendChild(this.renderHeader());
992
1679
  panel.appendChild(this.renderBody());
993
1680
  return panel;
@@ -996,90 +1683,70 @@ var TrilletWidgetElement = class extends HTMLElement {
996
1683
  * The header title identifying who the user is talking to. Each identity value is
997
1684
  * code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
998
1685
  * config value takes precedence over the corresponding backend `display.*` value
999
- * (which only arrives on `connected`), falling back to it when unset. Resolution:
1000
- * effectiveAgent = config.agentName ?? display.agent_name
1001
- * effectiveCallFlow = config.callFlowName ?? display.call_flow_name
1002
- * effectiveWorkspace = config.workspaceName ?? display.workspace_name
1003
- * title = effectiveAgent || effectiveCallFlow || effectiveWorkspace || ''
1004
- * Because the overrides are static config, the title can render pre-call. Note:
1005
- * `brand.name` is intentionally NOT part of this chain — it renders in the brand
1006
- * slot only.
1686
+ * (which only arrives on `connected`), falling back to it when unset. `brand.name`
1687
+ * is intentionally NOT part of this chain; it renders as the status line pre-call.
1007
1688
  */
1008
1689
  headerTitle() {
1009
- var _a, _b, _c, _d, _e, _f;
1010
- const effectiveAgent = (_b = this.config.agentName) != null ? _b : (_a = this.display) == null ? void 0 : _a.agent_name;
1011
- const effectiveCallFlow = (_d = this.config.callFlowName) != null ? _d : (_c = this.display) == null ? void 0 : _c.call_flow_name;
1012
- const effectiveWorkspace = (_f = this.config.workspaceName) != null ? _f : (_e = this.display) == null ? void 0 : _e.workspace_name;
1690
+ var _a, _b, _c, _d;
1691
+ const display = (_a = this.display) != null ? _a : this.remoteDisplay;
1692
+ const effectiveAgent = (_b = this.config.agentName) != null ? _b : display == null ? void 0 : display.agent_name;
1693
+ const effectiveCallFlow = (_c = this.config.callFlowName) != null ? _c : display == null ? void 0 : display.call_flow_name;
1694
+ const effectiveWorkspace = (_d = this.config.workspaceName) != null ? _d : display == null ? void 0 : display.workspace_name;
1013
1695
  return effectiveAgent || effectiveCallFlow || effectiveWorkspace || "";
1014
1696
  }
1015
1697
  renderHeader() {
1016
1698
  const header = document.createElement("div");
1017
1699
  header.className = "tw-header";
1018
- if (this.config.brand.logo || this.config.brand.name) {
1019
- const brand = document.createElement("div");
1020
- brand.className = "tw-brand";
1021
- if (this.config.brand.logo) {
1022
- const logo = document.createElement("img");
1023
- logo.className = "tw-brand-logo";
1024
- logo.src = this.config.brand.logo;
1025
- logo.alt = this.config.brand.name || "";
1026
- brand.appendChild(logo);
1027
- }
1028
- if (this.config.brand.name) {
1029
- const brandLabel = document.createElement("span");
1030
- brandLabel.className = "tw-brand-name";
1031
- brandLabel.textContent = this.config.brand.name;
1032
- brandLabel.title = this.config.brand.name;
1033
- brand.appendChild(brandLabel);
1034
- }
1035
- header.appendChild(brand);
1036
- }
1700
+ if (!this.bodyShowsLargeAvatar()) header.appendChild(this.buildAvatar("sm"));
1701
+ const who = document.createElement("div");
1702
+ who.className = "tw-who";
1037
1703
  const name = document.createElement("div");
1038
1704
  name.className = "tw-header-title";
1039
- const title = this.headerTitle();
1705
+ const title = this.config.agentName || this.speakerName();
1040
1706
  name.textContent = title;
1041
1707
  if (title) name.title = title;
1042
- header.appendChild(name);
1043
- if (this.config.variant === "compact") {
1044
- const expandBtn = document.createElement("button");
1045
- expandBtn.className = "tw-icon-btn";
1046
- expandBtn.type = "button";
1047
- expandBtn.title = this.config.expandText;
1048
- expandBtn.textContent = "\u2922";
1049
- expandBtn.addEventListener("click", () => {
1050
- this.config = { ...this.config, variant: "expanded" };
1051
- this.render();
1052
- });
1053
- header.appendChild(expandBtn);
1054
- } else {
1055
- const collapseBtn = document.createElement("button");
1056
- collapseBtn.className = "tw-icon-btn";
1057
- collapseBtn.type = "button";
1058
- collapseBtn.title = this.config.collapseText;
1059
- collapseBtn.textContent = "\u2921";
1060
- collapseBtn.addEventListener("click", () => {
1061
- this.config = { ...this.config, variant: "compact" };
1062
- this.render();
1063
- });
1064
- header.appendChild(collapseBtn);
1708
+ const status = document.createElement("div");
1709
+ status.className = "tw-status";
1710
+ if (this.state === "live") status.classList.add("tw-online");
1711
+ status.textContent = this.statusText();
1712
+ who.appendChild(name);
1713
+ who.appendChild(status);
1714
+ header.appendChild(who);
1715
+ if (this.config.brand.logo) {
1716
+ const logo = document.createElement("img");
1717
+ logo.className = "tw-brand-logo";
1718
+ logo.src = this.config.brand.logo;
1719
+ logo.alt = this.config.brand.name || "";
1720
+ header.appendChild(logo);
1065
1721
  }
1066
- if (this.config.dismissible) {
1067
- const closeBtn = document.createElement("button");
1068
- closeBtn.className = "tw-icon-btn";
1069
- closeBtn.type = "button";
1070
- closeBtn.title = "Close";
1071
- closeBtn.textContent = "\u2715";
1072
- closeBtn.addEventListener("click", () => {
1073
- if (this.state === "live" || this.state === "connecting") {
1074
- this.endConversation();
1075
- }
1722
+ const actions = document.createElement("div");
1723
+ actions.className = "tw-header-actions";
1724
+ actions.appendChild(
1725
+ this.iconButton(ICONS.minimize, "Minimize", () => {
1076
1726
  this.open = false;
1077
1727
  this.render();
1078
- });
1079
- header.appendChild(closeBtn);
1728
+ })
1729
+ );
1730
+ if (this.config.dismissible) {
1731
+ actions.appendChild(
1732
+ this.iconButton(ICONS.close, "Close", () => {
1733
+ if (this.state === "live" || this.state === "connecting") this.endConversation();
1734
+ this.open = false;
1735
+ this.render();
1736
+ })
1737
+ );
1080
1738
  }
1739
+ header.appendChild(actions);
1081
1740
  return header;
1082
1741
  }
1742
+ /** Start, call and gate screens centre a large avatar in the body. */
1743
+ bodyShowsLargeAvatar() {
1744
+ const idle = this.state === "idle" || this.state === "ended";
1745
+ if (this.needsRecaptcha() && idle) return true;
1746
+ if (this.isBothPreCall()) return true;
1747
+ if (this.config.mode !== "both" && this.resolvedMode() === "voice") return true;
1748
+ return this.state === "idle" && this.transcripts.length === 0;
1749
+ }
1083
1750
  /** True when a `both` widget is idle/ended with no modality chosen yet. */
1084
1751
  isBothPreCall() {
1085
1752
  return this.config.mode === "both" && this.activeMode === null && (this.state === "idle" || this.state === "ended");
@@ -1090,43 +1757,38 @@ var TrilletWidgetElement = class extends HTMLElement {
1090
1757
  return Boolean(this.config.recaptchaSiteKey) && !this.recaptchaSolved;
1091
1758
  }
1092
1759
  /**
1093
- * The pre-call gate shown in the panel: orb, prompt, the reCAPTCHA checkbox, and a
1760
+ * The pre-call gate shown in the panel: prompt, the reCAPTCHA checkbox, and a
1094
1761
  * disabled start button. The button enables once the checkbox is solved.
1095
1762
  *
1096
1763
  * The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
1097
1764
  * shadow root (its anchor iframe never finishes initializing), so the actual widget
1098
1765
  * is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
1099
1766
  * to this slot. It therefore *displays* here inside the panel while its DOM home
1100
- * stays in the light tree, where reCAPTCHA works. Verified via examples/recaptcha-
1101
- * isolate.local.html (case C).
1767
+ * stays in the light tree, where reCAPTCHA works.
1102
1768
  */
1103
1769
  renderRecaptchaGate(body) {
1104
- body.appendChild(this.buildOrb());
1105
- const status = document.createElement("div");
1106
- status.className = "tw-status";
1107
- status.textContent = this.config.recaptchaText;
1108
- body.appendChild(status);
1770
+ body.classList.add("tw-center-body");
1771
+ body.appendChild(this.buildAvatar("lg"));
1772
+ const prompt = document.createElement("p");
1773
+ prompt.className = "tw-prompt";
1774
+ prompt.textContent = this.config.recaptchaText;
1775
+ body.appendChild(prompt);
1109
1776
  const slot = document.createElement("slot");
1110
1777
  slot.setAttribute("name", "recaptcha");
1111
1778
  slot.className = "tw-recaptcha-slot";
1112
1779
  body.appendChild(slot);
1113
- const controls = document.createElement("div");
1114
- controls.className = "tw-controls";
1115
1780
  const startBtn = document.createElement("button");
1116
1781
  startBtn.className = "tw-primary-btn";
1117
1782
  startBtn.type = "button";
1118
1783
  startBtn.textContent = this.config.startCallText;
1119
1784
  startBtn.disabled = true;
1120
- controls.appendChild(startBtn);
1121
- body.appendChild(controls);
1785
+ body.appendChild(startBtn);
1122
1786
  this.ensureRecaptchaSlot();
1123
1787
  }
1124
1788
  /**
1125
1789
  * Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox
1126
- * into it. The node is a child of the host element with `slot="recaptcha"`, so it is
1127
- * projected into the gate's <slot>. Idempotent: every widget re-render recreates the
1128
- * <slot> element, but this node (and its iframe) persists in the light DOM untouched,
1129
- * so the checkbox is rendered exactly once and re-projects automatically.
1790
+ * into it. Idempotent: every re-render recreates the <slot>, but this node (and its
1791
+ * iframe) persists in the light DOM untouched, so the checkbox renders exactly once.
1130
1792
  */
1131
1793
  ensureRecaptchaSlot() {
1132
1794
  const siteKey = this.config.recaptchaSiteKey;
@@ -1145,8 +1807,6 @@ var TrilletWidgetElement = class extends HTMLElement {
1145
1807
  this.removeRecaptchaSlot();
1146
1808
  this.render();
1147
1809
  },
1148
- // A solved checkbox expires after ~2 minutes. Google resets its own widget UI in
1149
- // place, and the slot is still showing, so the visitor can just re-tick it.
1150
1810
  onExpired: () => {
1151
1811
  this.recaptchaSolved = false;
1152
1812
  }
@@ -1177,111 +1837,136 @@ var TrilletWidgetElement = class extends HTMLElement {
1177
1837
  this.renderBothEntry(body);
1178
1838
  return body;
1179
1839
  }
1180
- if (this.resolvedMode() === "text") {
1840
+ if (this.resolvedMode() === "text" || this.config.mode === "both") {
1181
1841
  this.renderTextBody(body);
1182
1842
  } else {
1183
1843
  this.renderVoiceBody(body);
1184
1844
  }
1185
1845
  return body;
1186
1846
  }
1187
- /** Build the animated gradient orb (or avatar image) reflecting the current state. */
1188
- buildOrb() {
1189
- const orbWrap = document.createElement("div");
1190
- orbWrap.className = "tw-orb-wrap";
1191
- if (this.state === "connecting") orbWrap.classList.add("tw-connecting");
1192
- if (this.state === "live") orbWrap.classList.add("tw-listening");
1193
- if (this.state === "live" && this.speaking) orbWrap.classList.add("tw-speaking");
1194
- const orb = document.createElement("div");
1195
- orb.className = "tw-orb";
1196
- if (this.config.avatar) {
1197
- orb.classList.add("tw-orb-avatar");
1198
- orb.style.backgroundImage = `url("${this.config.avatar}")`;
1199
- }
1200
- orbWrap.appendChild(orb);
1201
- return orbWrap;
1202
- }
1203
- /** Pre-call panel for mode="both": orb + "Start a call" (voice) and "Message" (text). */
1847
+ /** Pre-call panel for mode="both": the visitor picks how to talk. */
1204
1848
  renderBothEntry(body) {
1205
- body.appendChild(this.buildOrb());
1206
- const controls = document.createElement("div");
1207
- controls.className = "tw-controls tw-controls-stack";
1208
- const callBtn = document.createElement("button");
1209
- callBtn.className = "tw-primary-btn";
1210
- callBtn.type = "button";
1211
- callBtn.textContent = this.config.startCallText;
1212
- callBtn.addEventListener("click", () => {
1213
- void this.beginCall("voice");
1214
- });
1215
- controls.appendChild(callBtn);
1216
- const msgBtn = document.createElement("button");
1217
- msgBtn.className = "tw-primary-btn tw-secondary";
1218
- msgBtn.type = "button";
1219
- msgBtn.textContent = this.config.messageText;
1220
- msgBtn.addEventListener("click", () => {
1221
- void this.beginCall("text");
1222
- });
1223
- controls.appendChild(msgBtn);
1224
- body.appendChild(controls);
1849
+ body.classList.add("tw-center-body");
1850
+ body.appendChild(this.buildAvatar("lg"));
1851
+ const prompt = document.createElement("p");
1852
+ prompt.className = "tw-prompt";
1853
+ prompt.textContent = this.config.greeting || "How would you like to talk?";
1854
+ body.appendChild(prompt);
1855
+ const choices = document.createElement("div");
1856
+ choices.className = "tw-choices";
1857
+ const choice = (icon, text, modality, primary) => {
1858
+ const btn = document.createElement("button");
1859
+ btn.type = "button";
1860
+ btn.className = primary ? "tw-primary-btn" : "tw-secondary-btn";
1861
+ btn.innerHTML = icon;
1862
+ const span = document.createElement("span");
1863
+ span.textContent = text;
1864
+ btn.appendChild(span);
1865
+ btn.addEventListener("click", () => {
1866
+ if (modality === "text") this.transcripts = [];
1867
+ void this.beginCall(modality);
1868
+ });
1869
+ return btn;
1870
+ };
1871
+ choices.appendChild(choice(ICONS.phone, this.config.startCallText, "voice", true));
1872
+ choices.appendChild(choice(ICONS.chat, this.config.messageText, "text", false));
1873
+ body.appendChild(choices);
1225
1874
  }
1226
- /** Voice UI: orb + spoken status + timer + mic/end controls. Never a text input. */
1875
+ /** Voice call: the agent's presence (ring follows their voice), status, controls. */
1227
1876
  renderVoiceBody(body) {
1228
- body.appendChild(this.buildOrb());
1229
- const status = document.createElement("div");
1230
- status.className = "tw-status";
1231
- status.textContent = this.statusText();
1877
+ var _a;
1878
+ body.classList.add("tw-center-body", "tw-voice-body");
1879
+ body.appendChild(this.buildAvatar("lg"));
1880
+ const status = document.createElement("p");
1881
+ status.className = "tw-prompt";
1882
+ if (this.state === "connecting") status.textContent = "Connecting\u2026";
1883
+ else if (this.state === "live") status.textContent = this.speaking ? this.config.speakingText : this.config.listeningText;
1884
+ else if (this.state === "ended") status.textContent = (_a = this.errorText) != null ? _a : "Call ended";
1885
+ else status.textContent = this.config.actionText || "Talk to us now";
1886
+ if (this.errorText && this.state !== "live") status.classList.add("tw-error-text");
1232
1887
  body.appendChild(status);
1233
1888
  const timer = document.createElement("div");
1234
1889
  timer.className = "tw-timer";
1235
1890
  timer.textContent = this.timerText();
1236
1891
  body.appendChild(timer);
1237
1892
  body.appendChild(this.renderControls());
1238
- const switchBtn = this.renderSwitchButton();
1239
- if (switchBtn) body.appendChild(switchBtn);
1240
1893
  }
1241
- /** Text/chat UI: conversation thread + message input. Never an orb or "listening" state. */
1894
+ /** Text/chat UI: conversation thread + message input. */
1242
1895
  renderTextBody(body) {
1243
- if (this.state === "idle" || this.state === "ended") {
1244
- if (this.state === "ended") {
1245
- const status = document.createElement("div");
1246
- status.className = "tw-status";
1247
- status.textContent = "Chat ended";
1248
- body.appendChild(status);
1896
+ var _a;
1897
+ body.classList.add("tw-chat-body");
1898
+ if (this.state === "idle" && this.transcripts.length === 0) {
1899
+ body.classList.add("tw-center-body");
1900
+ body.appendChild(this.buildAvatar("lg"));
1901
+ if (this.errorText) {
1902
+ const err = document.createElement("p");
1903
+ err.className = "tw-prompt tw-error-text";
1904
+ err.textContent = this.errorText;
1905
+ body.appendChild(err);
1249
1906
  }
1250
1907
  body.appendChild(this.renderControls());
1251
1908
  return;
1252
1909
  }
1253
- if (this.state === "connecting") {
1254
- const status = document.createElement("div");
1255
- status.className = "tw-status";
1256
- status.textContent = "Connecting\u2026";
1257
- body.appendChild(status);
1258
- }
1259
1910
  body.appendChild(this.renderTranscript());
1260
- if (this.state === "live") {
1261
- body.appendChild(this.renderTextInput());
1911
+ const suggestions = this.renderSuggestions();
1912
+ if (suggestions) body.appendChild(suggestions);
1913
+ if (this.state === "ended" || this.state === "idle") {
1914
+ const footer2 = document.createElement("div");
1915
+ footer2.className = "tw-chat-ended";
1916
+ const status = document.createElement("span");
1917
+ status.textContent = (_a = this.errorText) != null ? _a : "This chat has ended.";
1918
+ if (this.errorText) status.classList.add("tw-error-text");
1919
+ footer2.appendChild(status);
1920
+ const restart = document.createElement("button");
1921
+ restart.type = "button";
1922
+ restart.className = "tw-secondary-btn tw-small";
1923
+ restart.textContent = "Start a new chat";
1924
+ restart.addEventListener("click", () => {
1925
+ this.transcripts = [];
1926
+ void this.beginCall("text");
1927
+ });
1928
+ footer2.appendChild(restart);
1929
+ body.appendChild(footer2);
1930
+ const feedback = this.renderFeedback();
1931
+ if (feedback) body.appendChild(feedback);
1932
+ return;
1262
1933
  }
1934
+ if (this.notice) {
1935
+ const notice = document.createElement("p");
1936
+ notice.className = "tw-notice";
1937
+ notice.setAttribute("role", "status");
1938
+ notice.textContent = this.notice;
1939
+ body.appendChild(notice);
1940
+ }
1941
+ const talking = this.config.mode === "both" && this.resolvedMode() === "voice";
1942
+ body.appendChild(talking ? this.renderVoiceBar(true) : this.renderTextInput());
1943
+ const footer = document.createElement("div");
1944
+ footer.className = "tw-chat-footer";
1263
1945
  const endBtn = document.createElement("button");
1264
- endBtn.className = "tw-primary-btn tw-danger";
1946
+ endBtn.className = "tw-link-btn tw-end-chat";
1265
1947
  endBtn.type = "button";
1266
- endBtn.textContent = this.config.endCallText;
1948
+ endBtn.textContent = this.config.mode === "text" ? this.config.endCallText : "End conversation";
1267
1949
  endBtn.disabled = this.state === "connecting";
1268
1950
  endBtn.addEventListener("click", () => this.endConversation());
1269
- body.appendChild(endBtn);
1270
- const switchBtn = this.renderSwitchButton();
1271
- if (switchBtn) body.appendChild(switchBtn);
1272
- }
1273
- /** In mode="both" during a live session, a control to switch to the other modality. */
1274
- renderSwitchButton() {
1275
- if (this.config.mode !== "both" || this.state !== "live") return null;
1276
- const toText = this.resolvedMode() === "voice";
1277
- const btn = document.createElement("button");
1278
- btn.className = "tw-switch-btn";
1279
- btn.type = "button";
1280
- btn.textContent = toText ? this.config.switchToTextText : this.config.switchToVoiceText;
1281
- btn.addEventListener("click", () => {
1282
- void this.switchModality();
1283
- });
1284
- return btn;
1951
+ footer.appendChild(endBtn);
1952
+ body.appendChild(footer);
1953
+ }
1954
+ /** Starter questions, shown until the visitor has said something. */
1955
+ renderSuggestions() {
1956
+ const prompts = this.config.suggestedPrompts;
1957
+ const visitorHasSpoken = this.transcripts.some((t) => t.role === "user");
1958
+ if (!prompts.length || visitorHasSpoken || this.state === "ended") return null;
1959
+ const row = document.createElement("div");
1960
+ row.className = "tw-suggestions";
1961
+ for (const prompt of prompts) {
1962
+ const chip = document.createElement("button");
1963
+ chip.type = "button";
1964
+ chip.className = "tw-suggestion";
1965
+ chip.textContent = prompt;
1966
+ chip.addEventListener("click", () => void this.sendMessage(prompt));
1967
+ row.appendChild(chip);
1968
+ }
1969
+ return row;
1285
1970
  }
1286
1971
  renderControls() {
1287
1972
  const controls = document.createElement("div");
@@ -1290,91 +1975,278 @@ var TrilletWidgetElement = class extends HTMLElement {
1290
1975
  const startBtn = document.createElement("button");
1291
1976
  startBtn.className = "tw-primary-btn";
1292
1977
  startBtn.type = "button";
1293
- startBtn.textContent = this.config.startCallText;
1978
+ const isText = this.resolvedMode() === "text";
1979
+ startBtn.innerHTML = isText ? ICONS.chat : ICONS.phone;
1980
+ const span = document.createElement("span");
1981
+ span.textContent = isText ? "Start chat" : this.config.startCallText;
1982
+ startBtn.appendChild(span);
1294
1983
  startBtn.addEventListener("click", () => {
1295
1984
  void this.beginCall();
1296
1985
  });
1297
1986
  controls.appendChild(startBtn);
1298
1987
  return controls;
1299
1988
  }
1300
- if (this.resolvedMode() === "voice" && this.state === "live") {
1301
- const micBtn = document.createElement("button");
1302
- micBtn.className = `tw-mic-btn${this.micEnabled ? "" : " tw-muted"}`;
1303
- micBtn.type = "button";
1304
- micBtn.title = this.micEnabled ? "Mute microphone" : "Unmute microphone";
1305
- micBtn.textContent = this.micEnabled ? "\u{1F399}" : "\u{1F507}";
1306
- micBtn.addEventListener("click", () => {
1989
+ if (this.resolvedMode() === "voice") {
1990
+ const micBtn = this.iconButton(
1991
+ this.micEnabled ? ICONS.mic : ICONS.micOff,
1992
+ this.micEnabled ? "Mute microphone" : "Unmute microphone",
1993
+ () => {
1994
+ var _a;
1995
+ this.micEnabled = !this.micEnabled;
1996
+ (_a = this.agent) == null ? void 0 : _a.toggleMicrophone(this.micEnabled);
1997
+ this.render();
1998
+ },
1999
+ `tw-round-btn${this.micEnabled ? "" : " tw-muted"}`
2000
+ );
2001
+ micBtn.disabled = this.state !== "live";
2002
+ controls.appendChild(micBtn);
2003
+ const endBtn = this.iconButton(ICONS.hangup, this.config.endCallText, () => this.endConversation(), "tw-round-btn tw-end-btn");
2004
+ endBtn.disabled = this.state === "connecting";
2005
+ controls.appendChild(endBtn);
2006
+ }
2007
+ return controls;
2008
+ }
2009
+ /**
2010
+ * The call bar. Resting (floating) it replaces the ask bar during a call; inside the
2011
+ * chat panel it replaces the composer on the voice side of a type-or-talk chat.
2012
+ *
2013
+ * ||||| Speaking (mic) (💬 / ⌨) (end)
2014
+ * Firelink · 0:42
2015
+ */
2016
+ renderVoiceBar(inPanel) {
2017
+ const bar = document.createElement("div");
2018
+ bar.className = inPanel ? "tw-callbar tw-callbar-inline" : "tw-callbar";
2019
+ const connecting = this.state === "connecting";
2020
+ bar.appendChild(this.buildWave());
2021
+ const text = document.createElement("div");
2022
+ text.className = "tw-callbar-text";
2023
+ const activity = document.createElement("div");
2024
+ activity.className = "tw-callbar-activity";
2025
+ activity.textContent = connecting ? "Connecting\u2026" : this.speaking ? this.config.speakingText : this.config.listeningText;
2026
+ const meta = document.createElement("div");
2027
+ meta.className = "tw-callbar-meta tw-timer";
2028
+ const name = this.speakerName();
2029
+ meta.textContent = [name, this.timerText()].filter(Boolean).join(" \xB7 ");
2030
+ text.appendChild(activity);
2031
+ text.appendChild(meta);
2032
+ bar.appendChild(text);
2033
+ const mute = this.iconButton(
2034
+ this.micEnabled ? ICONS.mic : ICONS.micOff,
2035
+ this.micEnabled ? "Mute microphone" : "Unmute microphone",
2036
+ () => {
1307
2037
  var _a;
1308
2038
  this.micEnabled = !this.micEnabled;
1309
2039
  (_a = this.agent) == null ? void 0 : _a.toggleMicrophone(this.micEnabled);
1310
2040
  this.render();
1311
- });
1312
- controls.appendChild(micBtn);
2041
+ },
2042
+ `tw-sq tw-sq-quiet${this.micEnabled ? "" : " tw-muted"}`
2043
+ );
2044
+ mute.disabled = connecting;
2045
+ bar.appendChild(mute);
2046
+ if (inPanel) {
2047
+ const back = this.iconButton(ICONS.keyboard, "Type instead", () => void this.switchModality(), "tw-sq tw-sq-quiet");
2048
+ back.disabled = this.switchingSide || connecting;
2049
+ bar.appendChild(back);
2050
+ } else if (this.config.mode === "both") {
2051
+ bar.appendChild(
2052
+ this.iconButton(ICONS.chat, "Show the conversation", () => {
2053
+ this.open = true;
2054
+ this.render();
2055
+ }, "tw-sq tw-sq-quiet")
2056
+ );
1313
2057
  }
1314
- const endBtn = document.createElement("button");
1315
- endBtn.className = "tw-primary-btn tw-danger";
1316
- endBtn.type = "button";
1317
- endBtn.textContent = this.config.endCallText;
1318
- endBtn.disabled = this.state === "connecting";
1319
- endBtn.addEventListener("click", () => this.endConversation());
1320
- controls.appendChild(endBtn);
1321
- return controls;
2058
+ const end = this.iconButton(ICONS.hangup, this.config.endCallText, () => this.endConversation(), "tw-sq tw-sq-danger");
2059
+ bar.appendChild(end);
2060
+ return bar;
1322
2061
  }
1323
2062
  renderTextInput() {
1324
- const row = document.createElement("div");
1325
- row.className = "tw-text-input-row";
1326
- const input = document.createElement("input");
2063
+ const row = document.createElement("form");
2064
+ row.className = "tw-composer";
2065
+ const input = document.createElement("textarea");
1327
2066
  input.className = "tw-text-input";
1328
- input.type = "text";
1329
- input.placeholder = "Type a message\u2026";
2067
+ input.rows = 1;
2068
+ input.placeholder = this.config.inputPlaceholder;
2069
+ input.value = this.draft;
2070
+ input.setAttribute("aria-label", this.config.inputPlaceholder);
2071
+ const sendBtn = document.createElement("button");
2072
+ sendBtn.className = "tw-send-btn";
2073
+ sendBtn.type = "submit";
2074
+ sendBtn.setAttribute("aria-label", "Send");
2075
+ sendBtn.innerHTML = ICONS.send;
2076
+ const syncState = () => {
2077
+ sendBtn.disabled = this.state !== "live" || !input.value.trim();
2078
+ input.style.height = "auto";
2079
+ input.style.height = `${Math.min(input.scrollHeight, 112)}px`;
2080
+ };
1330
2081
  const send = () => {
1331
2082
  var _a;
1332
2083
  const text = input.value.trim();
1333
- if (!text) return;
1334
- void ((_a = this.agent) == null ? void 0 : _a.sendTextMessage(text));
2084
+ if (!text || this.state !== "live") return;
2085
+ this.draft = "";
1335
2086
  input.value = "";
2087
+ syncState();
2088
+ void ((_a = this.agent) == null ? void 0 : _a.sendTextMessage(text));
1336
2089
  };
2090
+ input.addEventListener("input", () => {
2091
+ this.draft = input.value;
2092
+ syncState();
2093
+ });
1337
2094
  input.addEventListener("keydown", (e) => {
1338
- if (e.key === "Enter") send();
2095
+ if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
2096
+ e.preventDefault();
2097
+ send();
2098
+ }
2099
+ });
2100
+ row.addEventListener("submit", (e) => {
2101
+ e.preventDefault();
2102
+ send();
1339
2103
  });
1340
- const sendBtn = document.createElement("button");
1341
- sendBtn.className = "tw-send-btn";
1342
- sendBtn.type = "button";
1343
- sendBtn.textContent = "Send";
1344
- sendBtn.addEventListener("click", send);
1345
2104
  row.appendChild(input);
2105
+ if (this.config.mode === "both") {
2106
+ const mic = this.iconButton(ICONS.phone, "Talk instead", () => void this.switchModality(), "tw-composer-mic");
2107
+ mic.disabled = this.state !== "live" || this.switchingSide;
2108
+ row.appendChild(mic);
2109
+ }
1346
2110
  row.appendChild(sendBtn);
2111
+ requestAnimationFrame(syncState);
2112
+ if (this.state === "live") requestAnimationFrame(() => input.focus({ preventScroll: true }));
1347
2113
  return row;
1348
2114
  }
1349
- /**
1350
- * The chat thread for text mode. This is a fixed-height, internally scrolling
1351
- * window (like a normal website chatbot): the container is rendered at its full
1352
- * height as soon as the chat opens — empty until messages arrive — and messages
1353
- * accumulate + scroll inside it, so the panel's overall height stays stable.
1354
- * Auto-scrolls to the newest message after each render.
1355
- */
1356
- renderTranscript() {
1357
- const wrap = document.createElement("div");
1358
- wrap.className = "tw-transcript tw-chat";
1359
- if (this.transcripts.length === 0) {
1360
- const empty = document.createElement("div");
1361
- empty.className = "tw-chat-empty";
1362
- empty.textContent = this.state === "connecting" ? "" : "\u2026";
1363
- wrap.appendChild(empty);
1364
- } else {
1365
- for (const t of this.transcripts) {
1366
- const msg = document.createElement("div");
1367
- msg.className = `tw-msg ${t.role === "user" ? "tw-user" : "tw-assistant"}`;
2115
+ /** The agent's reply as it streams in (not yet final), if any. */
2116
+ streamingReply() {
2117
+ var _a, _b;
2118
+ const partials = (_b = (_a = this.agent) == null ? void 0 : _a.getCurrentTranscript()) != null ? _b : {};
2119
+ return Object.entries(partials).filter(([identity]) => identity.startsWith("agent")).map(([, text]) => text).join(" ").trim();
2120
+ }
2121
+ /** Fill a chat thread element with the current messages. */
2122
+ fillThread(wrap) {
2123
+ wrap.replaceChildren();
2124
+ let previousRole = null;
2125
+ for (const t of this.transcripts) {
2126
+ if (t.toolUsed) continue;
2127
+ const msg = document.createElement("div");
2128
+ msg.className = `tw-msg ${t.role === "user" ? "tw-user" : "tw-assistant"}`;
2129
+ if (previousRole === t.role) msg.classList.add("tw-run");
2130
+ previousRole = t.role;
2131
+ if (t.role === "user") {
1368
2132
  msg.textContent = t.text;
1369
- wrap.appendChild(msg);
2133
+ } else {
2134
+ if (!msg.classList.contains("tw-run") && this.speakerName()) {
2135
+ const who = document.createElement("div");
2136
+ who.className = "tw-msg-label";
2137
+ who.textContent = this.speakerName();
2138
+ msg.appendChild(who);
2139
+ }
2140
+ const body = document.createElement("div");
2141
+ body.className = "tw-md";
2142
+ body.appendChild(renderMarkdown(t.text));
2143
+ msg.appendChild(body);
1370
2144
  }
2145
+ wrap.appendChild(msg);
2146
+ }
2147
+ const streaming = this.streamingReply();
2148
+ if (streaming) {
2149
+ const msg = document.createElement("div");
2150
+ msg.className = "tw-msg tw-assistant tw-streaming";
2151
+ if (previousRole === "assistant") msg.classList.add("tw-run");
2152
+ else if (this.speakerName()) {
2153
+ const who = document.createElement("div");
2154
+ who.className = "tw-msg-label";
2155
+ who.textContent = this.speakerName();
2156
+ msg.appendChild(who);
2157
+ }
2158
+ const body = document.createElement("div");
2159
+ body.className = "tw-md";
2160
+ body.appendChild(renderMarkdown(streaming));
2161
+ msg.appendChild(body);
2162
+ wrap.appendChild(msg);
2163
+ } else if (this.isAwaitingReply()) {
2164
+ const typing = document.createElement("div");
2165
+ typing.className = "tw-msg tw-assistant tw-typing";
2166
+ typing.setAttribute("aria-label", "Typing");
2167
+ typing.innerHTML = "<span></span><span></span><span></span>";
2168
+ wrap.appendChild(typing);
1371
2169
  }
1372
2170
  requestAnimationFrame(() => {
1373
2171
  wrap.scrollTop = wrap.scrollHeight;
1374
2172
  });
2173
+ }
2174
+ /** Connecting, or the visitor spoke last and the agent hasn't started answering. */
2175
+ isAwaitingReply() {
2176
+ if (this.state === "connecting" || this.pendingMessage) return true;
2177
+ if (this.state !== "live") return false;
2178
+ const last = [...this.transcripts].reverse().find((t) => !t.toolUsed);
2179
+ return (last == null ? void 0 : last.role) === "user";
2180
+ }
2181
+ /**
2182
+ * Patch just the chat thread (and starter questions) in place. Returns false when
2183
+ * there is no text thread on screen, in which case the caller does a full render.
2184
+ */
2185
+ updateThread() {
2186
+ if (!this.open) return false;
2187
+ const thread = this.root.querySelector(".tw-chat");
2188
+ if (!thread) return false;
2189
+ this.fillThread(thread);
2190
+ const existing = this.root.querySelector(".tw-suggestions");
2191
+ const next = this.renderSuggestions();
2192
+ if (existing && !next) existing.remove();
2193
+ const status = this.root.querySelector(".tw-status");
2194
+ if (status) status.textContent = this.statusText();
2195
+ return true;
2196
+ }
2197
+ /** The chat thread: a fixed-height window that scrolls internally. */
2198
+ renderTranscript() {
2199
+ const wrap = document.createElement("div");
2200
+ wrap.className = "tw-chat";
2201
+ wrap.setAttribute("role", "log");
2202
+ wrap.setAttribute("aria-live", "polite");
2203
+ this.fillThread(wrap);
1375
2204
  return wrap;
1376
2205
  }
1377
2206
  };
2207
+ function friendlyError(err) {
2208
+ const msg = err.message || "";
2209
+ if (/Origin not allowed/i.test(msg)) return "Chat is not enabled on this website.";
2210
+ if (/Public access/i.test(msg)) return "Chat is not available right now.";
2211
+ if (/Too many/i.test(msg)) return "Too many chats right now. Please try again shortly.";
2212
+ if (/Insufficient funds/i.test(msg)) return "Chat is not available right now.";
2213
+ return "Could not connect. Please try again.";
2214
+ }
2215
+ var DEFAULT_ACCENT = "#0062e9";
2216
+ function readableOn(hex) {
2217
+ const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
2218
+ if (!m) return "#ffffff";
2219
+ const full = m[1].length === 3 ? m[1].split("").map((c) => c + c).join("") : m[1];
2220
+ const channel = (i) => {
2221
+ const v = parseInt(full.slice(i, i + 2), 16) / 255;
2222
+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
2223
+ };
2224
+ const lum = 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
2225
+ const contrastWhite = 1.05 / (lum + 0.05);
2226
+ const contrastInk = (lum + 0.05) / 0.06;
2227
+ return contrastWhite >= contrastInk ? "#ffffff" : "#16181d";
2228
+ }
2229
+ function initials(name) {
2230
+ const words = name.trim().split(/\s+/).filter((w) => /[a-z0-9]/i.test(w));
2231
+ if (!words.length) return "";
2232
+ const letters = words.length === 1 ? words[0].slice(0, 1) : words[0][0] + words[1][0];
2233
+ return letters.toUpperCase();
2234
+ }
2235
+ var svg = (body) => `<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${body}</svg>`;
2236
+ var ICONS = {
2237
+ chat: svg('<path d="M20 12.5a7.5 7.5 0 0 1-11.2 6.5L4 20l1.1-4.3A7.5 7.5 0 1 1 20 12.5Z"/>'),
2238
+ phone: svg('<path d="M5 4h3l1.6 4-2 1.3a11 11 0 0 0 5.1 5.1l1.3-2 4 1.6v3a2 2 0 0 1-2.2 2A16 16 0 0 1 3 6.2 2 2 0 0 1 5 4Z"/>'),
2239
+ hangup: svg('<path d="M3.5 13.5c4.7-4 12.3-4 17 0l-1.6 2.6-3.4-1.2v-2.5a10 10 0 0 0-7 0v2.5l-3.4 1.2Z"/>'),
2240
+ mic: svg('<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21"/>'),
2241
+ micOff: svg('<path d="M15 10V6a3 3 0 0 0-5.7-1.3M9 9v2a3 3 0 0 0 4.6 2.5M5.5 11a6.5 6.5 0 0 0 10.4 5.2M18.5 11a6.4 6.4 0 0 1-.6 2.6M12 17.5V21M4 4l16 16"/>'),
2242
+ send: svg('<path d="M12 19V5M5.5 11.5 12 5l6.5 6.5"/>'),
2243
+ minimize: svg('<path d="m6 9 6 6 6-6"/>'),
2244
+ thumbUp: svg('<path d="M7 11v9H4v-9h3Zm0 0 4-7a2 2 0 0 1 2 2v3h5a2 2 0 0 1 2 2.3l-1.2 6A2 2 0 0 1 16.8 19H7"/>'),
2245
+ thumbDown: svg('<path d="M17 13V4h3v9h-3Zm0 0-4 7a2 2 0 0 1-2-2v-3H6a2 2 0 0 1-2-2.3l1.2-6A2 2 0 0 1 7.2 5H17"/>'),
2246
+ keyboard: svg('<rect x="3" y="6" width="18" height="12" rx="2"/><path d="M7 10h.01M11 10h.01M15 10h.01M7 14h10"/>'),
2247
+ close: svg('<path d="M6 6l12 12M18 6 6 18"/>'),
2248
+ spinner: svg('<path d="M12 3a9 9 0 1 0 9 9" class="tw-spin"/>')
2249
+ };
1378
2250
 
1379
2251
  // src/widget/register.ts
1380
2252
  var TRILLET_WIDGET_TAG = "trillet-widget";
@@ -1430,6 +2302,16 @@ var TrilletWidget = (props) => {
1430
2302
  setAttr(el, "expand-text", props.expandText);
1431
2303
  setAttr(el, "collapse-text", props.collapseText);
1432
2304
  setAttr(el, "mode", props.mode);
2305
+ setAttr(el, "api-base", props.apiBase);
2306
+ setAttr(el, "remote-config", props.remoteConfig === false ? "false" : void 0);
2307
+ setAttr(el, "greeting", props.greeting);
2308
+ setAttr(el, "input-placeholder", props.inputPlaceholder);
2309
+ setAttr(
2310
+ el,
2311
+ "suggested-prompts",
2312
+ props.suggestedPrompts ? JSON.stringify(props.suggestedPrompts) : void 0
2313
+ );
2314
+ setAttr(el, "theme", props.theme);
1433
2315
  const vars = (_b = props.variables) != null ? _b : props.dynamicVariables;
1434
2316
  setAttr(el, "variables", vars ? JSON.stringify(vars) : void 0);
1435
2317
  setAttr(el, "max-call-duration", props.maxCallDuration);