@trillet-ai/web-sdk 1.10.0 → 1.12.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.
@@ -5,20 +5,244 @@ import {
5
5
  apiUrl
6
6
  } from "../chunk-CVTVHUNZ.js";
7
7
 
8
- // src/widget/config.ts
9
- var DEFAULT_COPY = {
10
- startCallText: "Start a call",
11
- endCallText: "End call",
12
- messageText: "Message",
13
- switchToTextText: "Switch to text mode",
14
- switchToVoiceText: "Switch to voice mode",
15
- listeningText: "Listening\u2026",
16
- speakingText: "Speaking\u2026",
17
- expandText: "Expand",
18
- collapseText: "Collapse",
19
- recaptchaText: "Verify you are human to start",
20
- inputPlaceholder: "Type a message\u2026"
8
+ // src/widget/i18n.ts
9
+ var WIDGET_LANGUAGES = ["en", "de", "fr", "it"];
10
+ var WIDGET_COPY = {
11
+ en: {
12
+ startCallText: "Start a call",
13
+ startChatText: "Start chat",
14
+ endCallText: "End call",
15
+ endChatText: "End chat",
16
+ endConversationText: "End conversation",
17
+ messageText: "Message",
18
+ callLabel: "Call",
19
+ chatLabel: "Chat",
20
+ switchToTextText: "Switch to text mode",
21
+ switchToVoiceText: "Switch to voice mode",
22
+ listeningText: "Listening\u2026",
23
+ speakingText: "Speaking\u2026",
24
+ expandText: "Expand",
25
+ collapseText: "Collapse",
26
+ recaptchaText: "Verify you are human to start",
27
+ inputPlaceholder: "Type a message\u2026",
28
+ askAnything: "Ask anything\u2026",
29
+ askNamed: "Ask {name} anything\u2026",
30
+ chooseModePrompt: "How would you like to talk?",
31
+ talkToUs: "Talk to us now",
32
+ connecting: "Connecting\u2026",
33
+ online: "Online",
34
+ callEnded: "Call ended",
35
+ chatEnded: "This chat has ended.",
36
+ startNewChat: "Start a new chat",
37
+ startOver: "Start over",
38
+ backToChat: "Back to chat",
39
+ chatWithNamed: "Chat with {name}",
40
+ chat: "Chat",
41
+ send: "Send",
42
+ close: "Close",
43
+ typing: "Typing",
44
+ muteMic: "Mute microphone",
45
+ unmuteMic: "Unmute microphone",
46
+ terms: "Terms",
47
+ termsTitle: "Before we start",
48
+ termsAccept: "Agree and continue",
49
+ termsDecline: "Not now",
50
+ feedbackQuestion: "How was this conversation?",
51
+ feedbackThanks: "Thanks for the feedback.",
52
+ errorNotEnabled: "Chat is not enabled on this website.",
53
+ errorUnavailable: "Chat is not available right now.",
54
+ errorTooMany: "Too many chats right now. Please try again shortly.",
55
+ errorGeneric: "Could not connect. Please try again.",
56
+ feedbackGood: "Good",
57
+ feedbackBad: "Not good",
58
+ openChat: "Open the chat",
59
+ minimize: "Minimize",
60
+ typeInstead: "Type instead",
61
+ showConversation: "Show the conversation",
62
+ talkInstead: "Talk instead",
63
+ continueText: "Continue",
64
+ fieldRequired: "This field is required."
65
+ },
66
+ de: {
67
+ startCallText: "Anruf starten",
68
+ startChatText: "Chat starten",
69
+ endCallText: "Anruf beenden",
70
+ endChatText: "Chat beenden",
71
+ endConversationText: "Gespr\xE4ch beenden",
72
+ messageText: "Nachricht",
73
+ callLabel: "Anrufen",
74
+ chatLabel: "Chat",
75
+ switchToTextText: "Zum Textmodus wechseln",
76
+ switchToVoiceText: "Zum Sprachmodus wechseln",
77
+ listeningText: "H\xF6rt zu\u2026",
78
+ speakingText: "Spricht\u2026",
79
+ expandText: "Erweitern",
80
+ collapseText: "Verkleinern",
81
+ recaptchaText: "Bitte best\xE4tigen Sie, dass Sie ein Mensch sind",
82
+ inputPlaceholder: "Nachricht eingeben\u2026",
83
+ askAnything: "Stellen Sie Ihre Frage\u2026",
84
+ askNamed: "Ihre Frage an {name}\u2026",
85
+ chooseModePrompt: "Wie m\xF6chten Sie mit uns sprechen?",
86
+ talkToUs: "Jetzt mit uns sprechen",
87
+ connecting: "Verbindung wird hergestellt\u2026",
88
+ online: "Online",
89
+ callEnded: "Anruf beendet",
90
+ chatEnded: "Dieser Chat wurde beendet.",
91
+ startNewChat: "Neuen Chat starten",
92
+ startOver: "Neu starten",
93
+ backToChat: "Zur\xFCck zum Chat",
94
+ chatWithNamed: "Chat mit {name}",
95
+ chat: "Chat",
96
+ send: "Senden",
97
+ close: "Ausblenden",
98
+ typing: "Schreibt",
99
+ muteMic: "Mikrofon stummschalten",
100
+ unmuteMic: "Mikrofon einschalten",
101
+ terms: "Nutzungsbedingungen",
102
+ termsTitle: "Bevor wir beginnen",
103
+ termsAccept: "Zustimmen und fortfahren",
104
+ termsDecline: "Nicht jetzt",
105
+ feedbackQuestion: "Wie war dieses Gespr\xE4ch?",
106
+ feedbackThanks: "Danke f\xFCr Ihr Feedback.",
107
+ errorNotEnabled: "Der Chat ist auf dieser Website nicht aktiviert.",
108
+ errorUnavailable: "Der Chat ist im Moment nicht verf\xFCgbar.",
109
+ errorTooMany: "Gerade sind zu viele Chats aktiv. Bitte versuchen Sie es gleich nochmals.",
110
+ errorGeneric: "Verbindung fehlgeschlagen. Bitte versuchen Sie es nochmals.",
111
+ feedbackGood: "Gut",
112
+ feedbackBad: "Nicht gut",
113
+ openChat: "Chat \xF6ffnen",
114
+ minimize: "Minimieren",
115
+ typeInstead: "Lieber schreiben",
116
+ showConversation: "Gespr\xE4ch anzeigen",
117
+ talkInstead: "Lieber sprechen",
118
+ continueText: "Weiter",
119
+ fieldRequired: "Dieses Feld ist erforderlich."
120
+ },
121
+ fr: {
122
+ startCallText: "D\xE9marrer un appel",
123
+ startChatText: "D\xE9marrer le chat",
124
+ endCallText: "Terminer l'appel",
125
+ endChatText: "Terminer le chat",
126
+ endConversationText: "Terminer la conversation",
127
+ messageText: "Message",
128
+ callLabel: "Appeler",
129
+ chatLabel: "Chat",
130
+ switchToTextText: "Passer au mode texte",
131
+ switchToVoiceText: "Passer au mode vocal",
132
+ listeningText: "\xC9coute\u2026",
133
+ speakingText: "Parle\u2026",
134
+ expandText: "Agrandir",
135
+ collapseText: "R\xE9duire",
136
+ recaptchaText: "Veuillez confirmer que vous \xEAtes humain",
137
+ inputPlaceholder: "\xC9crivez un message\u2026",
138
+ askAnything: "Posez votre question\u2026",
139
+ askNamed: "Votre question pour {name}\u2026",
140
+ chooseModePrompt: "Comment souhaitez-vous \xE9changer ?",
141
+ talkToUs: "Parlez-nous maintenant",
142
+ connecting: "Connexion\u2026",
143
+ online: "En ligne",
144
+ callEnded: "Appel termin\xE9",
145
+ chatEnded: "Ce chat est termin\xE9.",
146
+ startNewChat: "D\xE9marrer un nouveau chat",
147
+ startOver: "Recommencer",
148
+ backToChat: "Retour au chat",
149
+ chatWithNamed: "Chat avec {name}",
150
+ chat: "Chat",
151
+ send: "Envoyer",
152
+ close: "Fermer",
153
+ typing: "En train d'\xE9crire",
154
+ muteMic: "Couper le micro",
155
+ unmuteMic: "Activer le micro",
156
+ terms: "Conditions",
157
+ termsTitle: "Avant de commencer",
158
+ termsAccept: "Accepter et continuer",
159
+ termsDecline: "Pas maintenant",
160
+ feedbackQuestion: "Comment s\u2019est pass\xE9e cette conversation ?",
161
+ feedbackThanks: "Merci pour votre retour.",
162
+ errorNotEnabled: "Le chat n'est pas activ\xE9 sur ce site.",
163
+ errorUnavailable: "Le chat n'est pas disponible pour le moment.",
164
+ errorTooMany: "Trop de chats en cours. Veuillez r\xE9essayer dans un instant.",
165
+ errorGeneric: "Connexion impossible. Veuillez r\xE9essayer.",
166
+ feedbackGood: "Bien",
167
+ feedbackBad: "Pas bien",
168
+ openChat: "Ouvrir le chat",
169
+ minimize: "R\xE9duire",
170
+ typeInstead: "\xC9crire plut\xF4t",
171
+ showConversation: "Afficher la conversation",
172
+ talkInstead: "Parler plut\xF4t",
173
+ continueText: "Continuer",
174
+ fieldRequired: "Ce champ est obligatoire."
175
+ },
176
+ it: {
177
+ startCallText: "Avvia una chiamata",
178
+ startChatText: "Avvia la chat",
179
+ endCallText: "Termina la chiamata",
180
+ endChatText: "Termina la chat",
181
+ endConversationText: "Termina la conversazione",
182
+ messageText: "Messaggio",
183
+ callLabel: "Chiama",
184
+ chatLabel: "Chat",
185
+ switchToTextText: "Passa alla modalit\xE0 testo",
186
+ switchToVoiceText: "Passa alla modalit\xE0 vocale",
187
+ listeningText: "In ascolto\u2026",
188
+ speakingText: "Sta parlando\u2026",
189
+ expandText: "Espandi",
190
+ collapseText: "Riduci",
191
+ recaptchaText: "Confermi di non essere un robot",
192
+ inputPlaceholder: "Scriva un messaggio\u2026",
193
+ askAnything: "Faccia la sua domanda\u2026",
194
+ askNamed: "La sua domanda per {name}\u2026",
195
+ chooseModePrompt: "Come preferisce comunicare?",
196
+ talkToUs: "Parli con noi ora",
197
+ connecting: "Connessione in corso\u2026",
198
+ online: "Online",
199
+ callEnded: "Chiamata terminata",
200
+ chatEnded: "Questa chat \xE8 terminata.",
201
+ startNewChat: "Avvia una nuova chat",
202
+ startOver: "Ricomincia",
203
+ backToChat: "Torna alla chat",
204
+ chatWithNamed: "Chat con {name}",
205
+ chat: "Chat",
206
+ send: "Invia",
207
+ close: "Chiudi",
208
+ typing: "Sta scrivendo",
209
+ muteMic: "Disattiva microfono",
210
+ unmuteMic: "Attiva microfono",
211
+ terms: "Condizioni",
212
+ termsTitle: "Prima di iniziare",
213
+ termsAccept: "Accetta e continua",
214
+ termsDecline: "Non ora",
215
+ feedbackQuestion: "Com\u2019\xE8 andata questa conversazione?",
216
+ feedbackThanks: "Grazie per il feedback.",
217
+ errorNotEnabled: "La chat non \xE8 attiva su questo sito.",
218
+ errorUnavailable: "La chat non \xE8 disponibile al momento.",
219
+ errorTooMany: "Troppe chat in corso. Riprovi tra poco.",
220
+ errorGeneric: "Connessione non riuscita. Riprovi.",
221
+ feedbackGood: "Bene",
222
+ feedbackBad: "Non bene",
223
+ openChat: "Apri la chat",
224
+ minimize: "Riduci a icona",
225
+ typeInstead: "Preferisco scrivere",
226
+ showConversation: "Mostra la conversazione",
227
+ talkInstead: "Preferisco parlare",
228
+ continueText: "Continua",
229
+ fieldRequired: "Questo campo \xE8 obbligatorio."
230
+ }
21
231
  };
232
+ function normalizeLanguage(tag) {
233
+ if (!tag) return null;
234
+ const base = tag.trim().toLowerCase().split(/[-_]/)[0];
235
+ return WIDGET_LANGUAGES.includes(base) ? base : null;
236
+ }
237
+ function resolveLanguage(attr, remote, pageLang) {
238
+ var _a, _b, _c;
239
+ return (_c = (_b = (_a = normalizeLanguage(attr)) != null ? _a : normalizeLanguage(remote)) != null ? _b : normalizeLanguage(pageLang)) != null ? _c : "en";
240
+ }
241
+ function fillName(template, name) {
242
+ return template.replace("{name}", name);
243
+ }
244
+
245
+ // src/widget/config.ts
22
246
  var OBSERVED_ATTRIBUTES = [
23
247
  "agent-id",
24
248
  "signed-url-endpoint",
@@ -50,6 +274,8 @@ var OBSERVED_ATTRIBUTES = [
50
274
  "action-text",
51
275
  "start-call-text",
52
276
  "end-call-text",
277
+ "end-chat-text",
278
+ "language",
53
279
  "message-text",
54
280
  "call-label",
55
281
  "chat-label",
@@ -64,6 +290,10 @@ var OBSERVED_ATTRIBUTES = [
64
290
  "variables",
65
291
  "dynamic-variables",
66
292
  // convai alias -> variables
293
+ // The variable *definitions* (preset/ask-user specs) rendered as a pre-call form —
294
+ // distinct from `variables`/`dynamic-variables` above, which carry the final
295
+ // key/value map sent into the call.
296
+ "dynamic-variable-defs",
67
297
  "max-call-duration",
68
298
  "recaptcha-site-key",
69
299
  "disable-banner",
@@ -103,6 +333,35 @@ var HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
103
333
  function hexOrUndefined(value) {
104
334
  return value && HEX.test(value.trim()) ? value.trim() : void 0;
105
335
  }
336
+ function splitDynamicVariableDefs(defs) {
337
+ var _a;
338
+ const presets = {};
339
+ const prompts = [];
340
+ for (const def of defs) {
341
+ if (!def || typeof def.key !== "string" || !def.key) continue;
342
+ if (def.mode === "prompt") {
343
+ prompts.push({
344
+ key: def.key,
345
+ label: def.label || void 0,
346
+ placeholder: def.placeholder || void 0,
347
+ required: Boolean(def.required)
348
+ });
349
+ } else {
350
+ presets[def.key] = (_a = def.value) != null ? _a : "";
351
+ }
352
+ }
353
+ return { presets, prompts };
354
+ }
355
+ function parseDynamicVariableDefsAttr(value) {
356
+ if (!value) return void 0;
357
+ try {
358
+ const parsed = JSON.parse(value);
359
+ if (Array.isArray(parsed)) return splitDynamicVariableDefs(parsed);
360
+ } catch (e) {
361
+ console.warn("[trillet-widget] Failed to parse dynamic-variable-defs:", value);
362
+ }
363
+ return void 0;
364
+ }
106
365
  function parsePromptsAttr(value) {
107
366
  if (value === null) return void 0;
108
367
  const trimmed = value.trim();
@@ -131,7 +390,7 @@ function resolveVariant(raw) {
131
390
  }
132
391
  }
133
392
  function configFromElement(el, remote) {
134
- var _a, _b;
393
+ var _a, _b, _c, _d, _e, _f;
135
394
  const r = remote || {};
136
395
  const get = (name, fallback) => {
137
396
  var _a2;
@@ -142,9 +401,12 @@ function configFromElement(el, remote) {
142
401
  const mode = modeRaw === "text" ? "text" : modeRaw === "both" ? "both" : "voice";
143
402
  const placementRaw = get("placement", r.placement);
144
403
  const placement = PLACEMENTS.includes(placementRaw) ? placementRaw : "bottom-right";
404
+ const pageLang = typeof document !== "undefined" ? (_a = document.documentElement) == null ? void 0 : _a.lang : null;
405
+ const language = resolveLanguage(el.getAttribute("language"), r.language, pageLang);
406
+ const copy = WIDGET_COPY[language];
145
407
  const isText = mode === "text";
146
- const startDefault = r.startCallText || (isText ? "Start chat" : DEFAULT_COPY.startCallText);
147
- const endDefault = isText ? "End chat" : DEFAULT_COPY.endCallText;
408
+ const startDefault = r.startCallText || (isText ? copy.startChatText : copy.startCallText);
409
+ const endDefault = isText ? get("end-chat-text") || copy.endChatText : copy.endCallText;
148
410
  const brand = {};
149
411
  const brandLogo = get("brand-logo", r.brandLogo);
150
412
  const brandColor = get("brand-color", r.brandColor);
@@ -157,6 +419,7 @@ function configFromElement(el, remote) {
157
419
  const orbColor2 = get("avatar-orb-color-2", r.orbColor2) || void 0;
158
420
  const styleRaw = get("avatar-style", r.avatarStyle);
159
421
  const avatarStyle = styleRaw === "orb" || styleRaw === "image" || styleRaw === "initials" ? styleRaw : void 0;
422
+ const defs = (_b = parseDynamicVariableDefsAttr(el.getAttribute("dynamic-variable-defs"))) != null ? _b : Array.isArray(r.dynamicVariables) ? splitDynamicVariableDefs(r.dynamicVariables) : void 0;
160
423
  return {
161
424
  agentId: get("agent-id") || "",
162
425
  signedUrlEndpoint: get("signed-url-endpoint") || void 0,
@@ -176,22 +439,24 @@ function configFromElement(el, remote) {
176
439
  variant,
177
440
  placement,
178
441
  dismissible: parseBoolAttr(get("dismissible")),
442
+ language,
443
+ copy,
179
444
  actionText: get("action-text", r.launcherText) || void 0,
180
445
  startCallText: get("start-call-text") || startDefault,
181
446
  endCallText: get("end-call-text") || endDefault,
182
- messageText: get("message-text", r.messageText) || DEFAULT_COPY.messageText,
183
- callLabel: get("call-label") || "Call",
184
- chatLabel: get("chat-label") || "Chat",
185
- switchToTextText: get("switch-to-text-text") || DEFAULT_COPY.switchToTextText,
186
- switchToVoiceText: get("switch-to-voice-text") || DEFAULT_COPY.switchToVoiceText,
187
- listeningText: get("listening-text") || DEFAULT_COPY.listeningText,
188
- speakingText: get("speaking-text") || DEFAULT_COPY.speakingText,
189
- expandText: get("expand-text") || DEFAULT_COPY.expandText,
190
- collapseText: get("collapse-text") || DEFAULT_COPY.collapseText,
191
- recaptchaText: get("recaptcha-text") || DEFAULT_COPY.recaptchaText,
447
+ messageText: get("message-text", r.messageText) || copy.messageText,
448
+ callLabel: get("call-label") || copy.callLabel,
449
+ chatLabel: get("chat-label") || copy.chatLabel,
450
+ switchToTextText: get("switch-to-text-text") || copy.switchToTextText,
451
+ switchToVoiceText: get("switch-to-voice-text") || copy.switchToVoiceText,
452
+ listeningText: get("listening-text") || copy.listeningText,
453
+ speakingText: get("speaking-text") || copy.speakingText,
454
+ expandText: get("expand-text") || copy.expandText,
455
+ collapseText: get("collapse-text") || copy.collapseText,
456
+ recaptchaText: get("recaptcha-text") || copy.recaptchaText,
192
457
  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 : [],
458
+ inputPlaceholder: get("input-placeholder", r.inputPlaceholder) || copy.inputPlaceholder,
459
+ suggestedPrompts: (_d = (_c = parsePromptsAttr(el.getAttribute("suggested-prompts"))) != null ? _c : r.suggestedPrompts) != null ? _d : [],
195
460
  theme: get("theme", r.theme) === "dark" ? "dark" : "light",
196
461
  backgroundColor: hexOrUndefined(get("bg-color", r.backgroundColor)),
197
462
  textColor: hexOrUndefined(get("text-color", r.textColor)),
@@ -201,6 +466,8 @@ function configFromElement(el, remote) {
201
466
  mode,
202
467
  // convai `dynamic-variables` is an alias of our `variables`.
203
468
  variables: parseJsonAttr(get("variables") || get("dynamic-variables")),
469
+ dynamicVariablePresets: (_e = defs == null ? void 0 : defs.presets) != null ? _e : {},
470
+ dynamicVariablePrompts: (_f = defs == null ? void 0 : defs.prompts) != null ? _f : [],
204
471
  maxCallDuration: parseNumberAttr(get("max-call-duration")),
205
472
  recaptchaSiteKey: get("recaptcha-site-key") || void 0,
206
473
  disableBanner: parseBoolAttr(get("disable-banner")),
@@ -693,6 +960,7 @@ svg { display: block; flex-shrink: 0; }
693
960
  display: flex;
694
961
  align-items: center;
695
962
  justify-content: flex-end;
963
+ gap: 12px;
696
964
  min-height: 30px;
697
965
  padding: 2px 14px 6px;
698
966
  }
@@ -747,6 +1015,33 @@ svg { display: block; flex-shrink: 0; }
747
1015
  }
748
1016
  .tw-terms .tw-secondary-btn { height: 40px; }
749
1017
 
1018
+ /* ---- Pre-call dynamic-variables form ---- */
1019
+ .tw-variables-form { width: 320px; }
1020
+ .tw-field { display: flex; flex-direction: column; gap: 4px; }
1021
+ .tw-field-label { font-size: 13px; font-weight: 500; color: var(--tw-muted); }
1022
+ .tw-field-input {
1023
+ height: 38px;
1024
+ padding: 0 10px;
1025
+ border: 1px solid var(--tw-line);
1026
+ border-radius: 8px;
1027
+ background: var(--tw-surface);
1028
+ color: var(--tw-ink);
1029
+ font: inherit;
1030
+ font-size: 14px;
1031
+ }
1032
+ .tw-field-input:focus-visible { outline: none; border-color: var(--tw-accent); }
1033
+ .tw-field-error { margin: 0; font-size: 12px; color: var(--tw-danger); }
1034
+ .tw-variables-form .tw-pill {
1035
+ flex: 1;
1036
+ height: 40px;
1037
+ border: none;
1038
+ border-radius: 8px;
1039
+ background: var(--tw-accent);
1040
+ color: var(--tw-on-accent);
1041
+ font-weight: 600;
1042
+ cursor: pointer;
1043
+ }
1044
+
750
1045
  /* ---- Feedback ---- */
751
1046
  .tw-feedback {
752
1047
  display: flex;
@@ -959,6 +1254,9 @@ var TrilletWidgetElement = class extends HTMLElement {
959
1254
  // Inline notice in the chat (e.g. microphone refused). Cleared on the next switch.
960
1255
  this.notice = null;
961
1256
  this.switchingSide = false;
1257
+ // Bumped on every start/reset so a slow credential failure from a conversation the
1258
+ // visitor has already moved on from cannot disturb the current one.
1259
+ this.callGeneration = 0;
962
1260
  this.smoothedLevel = 0;
963
1261
  // ---- Terms gate + feedback --------------------------------------------------
964
1262
  this.showTerms = false;
@@ -967,6 +1265,13 @@ var TrilletWidgetElement = class extends HTMLElement {
967
1265
  this.feedbackState = "hidden";
968
1266
  // Fallback when storage is blocked: accepted for the life of this page.
969
1267
  this.termsAcceptedThisPage = false;
1268
+ // ---- Pre-call dynamic-variables form ----------------------------------------
1269
+ this.showVariablesForm = false;
1270
+ // null = not collected yet, which is what gates beginCall when prompts are
1271
+ // configured; {} once submitted, even with every field left blank. Cleared by
1272
+ // startOver(), so a fresh conversation asks again — every restart path runs through
1273
+ // startOver(), so in practice the visitor is asked once per conversation.
1274
+ this.dynamicVariableValues = null;
970
1275
  this.askFocused = false;
971
1276
  // Last start/connection failure, shown instead of the "ended" line.
972
1277
  this.errorText = null;
@@ -1064,6 +1369,39 @@ var TrilletWidgetElement = class extends HTMLElement {
1064
1369
  var _a;
1065
1370
  (_a = this.agent) == null ? void 0 : _a.endCall();
1066
1371
  }
1372
+ /**
1373
+ * Fully reset: tear down any live session (without dispatching its end-of-call
1374
+ * events — this isn't "the conversation ended", it's "forget it happened"), wipe the
1375
+ * transcript, and start a brand new one. Reachable at any time, live or already
1376
+ * ended — unlike {@link endConversation}, which keeps the transcript visible, this
1377
+ * always lands back in a fresh pre-call state so quick-question suggestions and the
1378
+ * dynamic-variables form (if configured) reappear.
1379
+ */
1380
+ startOver(modality) {
1381
+ this.callGeneration += 1;
1382
+ this.clearDurationTimer();
1383
+ this.teardownAgent();
1384
+ if (this.pendingTimer) clearTimeout(this.pendingTimer);
1385
+ this.pendingTimer = null;
1386
+ this.pendingMessage = null;
1387
+ this.transcripts = [];
1388
+ this.notice = null;
1389
+ this.errorText = null;
1390
+ this.feedbackState = "hidden";
1391
+ this.speaking = false;
1392
+ this.callId = null;
1393
+ this.display = null;
1394
+ this.dynamicVariableValues = null;
1395
+ this.state = "idle";
1396
+ if (this.config.mode === "both") {
1397
+ this.activeMode = modality != null ? modality : null;
1398
+ if (!modality) {
1399
+ this.render();
1400
+ return;
1401
+ }
1402
+ }
1403
+ void this.beginCall(modality);
1404
+ }
1067
1405
  /** @deprecated Use {@link startConversation}. Kept as a thin alias for back-compat. */
1068
1406
  startCall() {
1069
1407
  return this.startConversation();
@@ -1151,12 +1489,19 @@ var TrilletWidgetElement = class extends HTMLElement {
1151
1489
  this.render();
1152
1490
  return;
1153
1491
  }
1492
+ if (this.config.dynamicVariablePrompts.length > 0 && !this.dynamicVariableValues) {
1493
+ this.pendingStart = modality != null ? modality : this.resolvedMode();
1494
+ this.showVariablesForm = true;
1495
+ this.render();
1496
+ return;
1497
+ }
1154
1498
  this.feedbackState = "hidden";
1155
1499
  if (modality) this.activeMode = modality;
1156
1500
  const mode = this.resolvedMode();
1157
1501
  const session = this.config.mode === "both" ? "multimodal" : mode;
1158
1502
  this.notice = null;
1159
1503
  if (!this.switching) this.display = null;
1504
+ const generation = ++this.callGeneration;
1160
1505
  this.setState("connecting");
1161
1506
  try {
1162
1507
  const agent = new TrilletAgent({
@@ -1165,7 +1510,13 @@ var TrilletWidgetElement = class extends HTMLElement {
1165
1510
  apiBaseUrl: this.config.apiBase,
1166
1511
  mode: session,
1167
1512
  startWithVoice: session === "multimodal" && mode === "voice",
1168
- variables: this.config.variables
1513
+ // Presets, then what the visitor just told us, then an explicit `variables`/
1514
+ // `dynamic-variables` attribute (power-user override) wins over both.
1515
+ variables: {
1516
+ ...this.config.dynamicVariablePresets,
1517
+ ...this.dynamicVariableValues,
1518
+ ...this.config.variables
1519
+ }
1169
1520
  });
1170
1521
  this.agent = agent;
1171
1522
  this.wireAgentEvents(agent);
@@ -1194,6 +1545,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1194
1545
  );
1195
1546
  }
1196
1547
  } catch (error) {
1548
+ if (generation !== this.callGeneration) return;
1197
1549
  this.handleError(error);
1198
1550
  }
1199
1551
  }
@@ -1252,7 +1604,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1252
1604
  }
1253
1605
  handleError(error) {
1254
1606
  const err = error instanceof Error ? error : new Error(String(error));
1255
- this.errorText = friendlyError(err);
1607
+ this.errorText = friendlyError(err, this.config.copy);
1256
1608
  this.clearDurationTimer();
1257
1609
  this.speaking = false;
1258
1610
  this.switching = false;
@@ -1330,13 +1682,13 @@ var TrilletWidgetElement = class extends HTMLElement {
1330
1682
  }
1331
1683
  /** The line under the agent's name in the header. */
1332
1684
  statusText() {
1333
- if (this.state === "connecting") return "Connecting\u2026";
1685
+ if (this.state === "connecting") return this.config.copy.connecting;
1334
1686
  if (this.state === "live" && this.resolvedMode() === "voice") {
1335
1687
  const activity = this.speaking ? this.config.speakingText : this.config.listeningText;
1336
1688
  return `${activity} ${this.timerText()}`.trim();
1337
1689
  }
1338
- if (this.state === "live") return "Online";
1339
- return this.config.brand.name || "Online";
1690
+ if (this.state === "live") return this.config.copy.online;
1691
+ return this.config.brand.name || this.config.copy.online;
1340
1692
  }
1341
1693
  renderStatus() {
1342
1694
  const statusEl = this.root.querySelector(".tw-status");
@@ -1371,6 +1723,9 @@ var TrilletWidgetElement = class extends HTMLElement {
1371
1723
  if (this.showTerms) {
1372
1724
  view = "terms";
1373
1725
  el = this.renderTerms();
1726
+ } else if (this.showVariablesForm) {
1727
+ view = "variables";
1728
+ el = this.renderVariablesForm();
1374
1729
  } else if (this.open) {
1375
1730
  view = "panel";
1376
1731
  el = this.renderPanel();
@@ -1445,10 +1800,10 @@ var TrilletWidgetElement = class extends HTMLElement {
1445
1800
  const card = document.createElement("div");
1446
1801
  card.className = "tw-card tw-terms";
1447
1802
  card.setAttribute("role", "dialog");
1448
- card.setAttribute("aria-label", "Terms");
1803
+ card.setAttribute("aria-label", this.config.copy.terms);
1449
1804
  const title = document.createElement("div");
1450
1805
  title.className = "tw-card-title";
1451
- title.textContent = "Before we start";
1806
+ title.textContent = this.config.copy.termsTitle;
1452
1807
  card.appendChild(title);
1453
1808
  const body = document.createElement("div");
1454
1809
  body.className = "tw-terms-body tw-md";
@@ -1459,7 +1814,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1459
1814
  const accept = document.createElement("button");
1460
1815
  accept.type = "button";
1461
1816
  accept.className = "tw-pill";
1462
- accept.textContent = "Agree and continue";
1817
+ accept.textContent = this.config.copy.termsAccept;
1463
1818
  accept.addEventListener("click", () => {
1464
1819
  try {
1465
1820
  window.localStorage.setItem(this.termsKey(), "1");
@@ -1475,7 +1830,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1475
1830
  const decline = document.createElement("button");
1476
1831
  decline.type = "button";
1477
1832
  decline.className = "tw-secondary-btn";
1478
- decline.textContent = "Not now";
1833
+ decline.textContent = this.config.copy.termsDecline;
1479
1834
  decline.addEventListener("click", () => {
1480
1835
  this.showTerms = false;
1481
1836
  this.pendingStart = null;
@@ -1487,17 +1842,107 @@ var TrilletWidgetElement = class extends HTMLElement {
1487
1842
  card.appendChild(row);
1488
1843
  return card;
1489
1844
  }
1845
+ renderVariablesForm() {
1846
+ const card = document.createElement("div");
1847
+ card.className = "tw-card tw-variables-form";
1848
+ card.setAttribute("role", "dialog");
1849
+ card.setAttribute("aria-label", this.config.copy.continueText);
1850
+ const title = document.createElement("div");
1851
+ title.className = "tw-card-title";
1852
+ title.textContent = this.headerTitle() || this.config.copy.chooseModePrompt;
1853
+ card.appendChild(title);
1854
+ const entries = [];
1855
+ const submit = document.createElement("button");
1856
+ submit.type = "button";
1857
+ submit.className = "tw-pill";
1858
+ submit.textContent = this.config.copy.continueText;
1859
+ submit.addEventListener("click", () => {
1860
+ var _a;
1861
+ const values = {};
1862
+ let valid = true;
1863
+ for (const entry of entries) {
1864
+ const value = entry.input.value.trim();
1865
+ const missing = entry.required && !value;
1866
+ entry.err.hidden = !missing;
1867
+ entry.input.setAttribute("aria-invalid", missing ? "true" : "false");
1868
+ if (missing) {
1869
+ valid = false;
1870
+ continue;
1871
+ }
1872
+ if (value) values[entry.key] = value;
1873
+ }
1874
+ if (!valid) {
1875
+ (_a = entries.find((entry) => !entry.err.hidden)) == null ? void 0 : _a.input.focus();
1876
+ return;
1877
+ }
1878
+ this.dynamicVariableValues = values;
1879
+ this.showVariablesForm = false;
1880
+ const start = this.pendingStart;
1881
+ this.pendingStart = null;
1882
+ if (start === "text") this.open = true;
1883
+ void this.beginCall(start != null ? start : void 0);
1884
+ });
1885
+ this.config.dynamicVariablePrompts.forEach((prompt, index) => {
1886
+ const field = document.createElement("div");
1887
+ field.className = "tw-field";
1888
+ const inputId = `tw-var-${index}`;
1889
+ const errId = `tw-var-err-${index}`;
1890
+ const label = document.createElement("label");
1891
+ label.className = "tw-field-label";
1892
+ label.htmlFor = inputId;
1893
+ label.textContent = prompt.label || prompt.key;
1894
+ field.appendChild(label);
1895
+ const input = document.createElement("input");
1896
+ input.type = "text";
1897
+ input.id = inputId;
1898
+ input.className = "tw-field-input";
1899
+ if (prompt.placeholder) input.placeholder = prompt.placeholder;
1900
+ if (prompt.required) input.required = true;
1901
+ input.setAttribute("aria-describedby", errId);
1902
+ input.addEventListener("keydown", (event) => {
1903
+ if (event.key === "Enter") {
1904
+ event.preventDefault();
1905
+ submit.click();
1906
+ }
1907
+ });
1908
+ field.appendChild(input);
1909
+ const err = document.createElement("p");
1910
+ err.className = "tw-field-error";
1911
+ err.id = errId;
1912
+ err.textContent = this.config.copy.fieldRequired;
1913
+ err.hidden = true;
1914
+ field.appendChild(err);
1915
+ card.appendChild(field);
1916
+ entries.push({ key: prompt.key, required: Boolean(prompt.required), input, err });
1917
+ });
1918
+ const row = document.createElement("div");
1919
+ row.className = "tw-card-actions";
1920
+ row.appendChild(submit);
1921
+ const decline = document.createElement("button");
1922
+ decline.type = "button";
1923
+ decline.className = "tw-secondary-btn";
1924
+ decline.textContent = this.config.copy.termsDecline;
1925
+ decline.addEventListener("click", () => {
1926
+ this.showVariablesForm = false;
1927
+ this.pendingStart = null;
1928
+ this.open = false;
1929
+ this.render();
1930
+ });
1931
+ row.appendChild(decline);
1932
+ card.appendChild(row);
1933
+ return card;
1934
+ }
1490
1935
  /** "How was this conversation?" thumbs, once, after a conversation ends. */
1491
1936
  renderFeedback() {
1492
1937
  if (this.feedbackState === "hidden") return null;
1493
1938
  const row = document.createElement("div");
1494
1939
  row.className = "tw-feedback";
1495
1940
  if (this.feedbackState === "sent") {
1496
- row.textContent = "Thanks for the feedback.";
1941
+ row.textContent = this.config.copy.feedbackThanks;
1497
1942
  return row;
1498
1943
  }
1499
1944
  const label = document.createElement("span");
1500
- label.textContent = "How was this conversation?";
1945
+ label.textContent = this.config.copy.feedbackQuestion;
1501
1946
  row.appendChild(label);
1502
1947
  const send = (rating) => {
1503
1948
  this.feedbackState = "sent";
@@ -1509,8 +1954,8 @@ var TrilletWidgetElement = class extends HTMLElement {
1509
1954
  }).catch(() => void 0);
1510
1955
  this.dispatch("feedback", rating);
1511
1956
  };
1512
- row.appendChild(this.iconButton(ICONS.thumbUp, "Good", () => send("up")));
1513
- row.appendChild(this.iconButton(ICONS.thumbDown, "Not good", () => send("down")));
1957
+ row.appendChild(this.iconButton(ICONS.thumbUp, this.config.copy.feedbackGood, () => send("up")));
1958
+ row.appendChild(this.iconButton(ICONS.thumbDown, this.config.copy.feedbackBad, () => send("down")));
1514
1959
  return row;
1515
1960
  }
1516
1961
  /**
@@ -1550,10 +1995,10 @@ var TrilletWidgetElement = class extends HTMLElement {
1550
1995
  const back = document.createElement("button");
1551
1996
  back.type = "button";
1552
1997
  back.className = "tw-ask-label";
1553
- back.textContent = name ? `Chat with ${name}` : "Back to chat";
1998
+ back.textContent = name ? fillName(this.config.copy.chatWithNamed, name) : this.config.copy.backToChat;
1554
1999
  back.addEventListener("click", () => this.openPanel());
1555
2000
  bar.appendChild(back);
1556
- bar.appendChild(this.iconButton(ICONS.chat, "Open the chat", () => this.openPanel(), "tw-sq tw-sq-accent"));
2001
+ bar.appendChild(this.iconButton(ICONS.chat, this.config.copy.openChat, () => this.openPanel(), "tw-sq tw-sq-accent"));
1557
2002
  stack.appendChild(bar);
1558
2003
  return stack;
1559
2004
  }
@@ -1578,11 +2023,11 @@ var TrilletWidgetElement = class extends HTMLElement {
1578
2023
  const input = document.createElement("input");
1579
2024
  input.className = "tw-ask-input";
1580
2025
  input.type = "text";
1581
- input.placeholder = this.config.greeting || (name ? `Ask ${name} anything\u2026` : "Ask anything\u2026");
2026
+ input.placeholder = this.config.greeting || (name ? fillName(this.config.copy.askNamed, name) : this.config.copy.askAnything);
1582
2027
  input.setAttribute("aria-label", input.placeholder);
1583
2028
  input.value = this.draft;
1584
2029
  input.disabled = gated;
1585
- const send = this.iconButton(ICONS.send, "Send", () => void 0, "tw-sq tw-sq-accent");
2030
+ const send = this.iconButton(ICONS.send, this.config.copy.send, () => void 0, "tw-sq tw-sq-accent");
1586
2031
  send.type = "submit";
1587
2032
  const sync = () => {
1588
2033
  send.disabled = gated || !input.value.trim();
@@ -1656,15 +2101,16 @@ var TrilletWidgetElement = class extends HTMLElement {
1656
2101
  stack.insertBefore(row, bar);
1657
2102
  }
1658
2103
  /**
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.
2104
+ * Open the panel. A text-only widget with no prior conversation starts the chat
2105
+ * straight away, so the agent's welcome is already there when the panel opens, like
2106
+ * any website chat. `both` waits for the visitor to pick call or message. Reopening
2107
+ * never clears anything on its own — an ended conversation's transcript stays put
2108
+ * until the visitor explicitly starts over (see {@link startOver}).
1662
2109
  */
1663
2110
  openPanel() {
1664
2111
  this.open = true;
1665
- const idle = this.state === "idle" || this.state === "ended";
1666
- if (this.config.mode === "text" && idle && !this.needsRecaptcha()) {
1667
- this.transcripts = [];
2112
+ const fresh = this.state === "idle" && this.transcripts.length === 0;
2113
+ if (this.config.mode === "text" && fresh && !this.needsRecaptcha()) {
1668
2114
  void this.beginCall("text");
1669
2115
  return;
1670
2116
  }
@@ -1674,7 +2120,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1674
2120
  const panel = document.createElement("div");
1675
2121
  panel.className = `tw-panel${this.config.variant === "expanded" ? " tw-expanded" : ""}`;
1676
2122
  panel.setAttribute("role", "dialog");
1677
- panel.setAttribute("aria-label", this.headerTitle() || "Chat");
2123
+ panel.setAttribute("aria-label", this.headerTitle() || this.config.copy.chat);
1678
2124
  panel.appendChild(this.renderHeader());
1679
2125
  panel.appendChild(this.renderBody());
1680
2126
  return panel;
@@ -1722,14 +2168,14 @@ var TrilletWidgetElement = class extends HTMLElement {
1722
2168
  const actions = document.createElement("div");
1723
2169
  actions.className = "tw-header-actions";
1724
2170
  actions.appendChild(
1725
- this.iconButton(ICONS.minimize, "Minimize", () => {
2171
+ this.iconButton(ICONS.minimize, this.config.copy.minimize, () => {
1726
2172
  this.open = false;
1727
2173
  this.render();
1728
2174
  })
1729
2175
  );
1730
2176
  if (this.config.dismissible) {
1731
2177
  actions.appendChild(
1732
- this.iconButton(ICONS.close, "Close", () => {
2178
+ this.iconButton(ICONS.close, this.config.copy.close, () => {
1733
2179
  if (this.state === "live" || this.state === "connecting") this.endConversation();
1734
2180
  this.open = false;
1735
2181
  this.render();
@@ -1747,9 +2193,14 @@ var TrilletWidgetElement = class extends HTMLElement {
1747
2193
  if (this.config.mode !== "both" && this.resolvedMode() === "voice") return true;
1748
2194
  return this.state === "idle" && this.transcripts.length === 0;
1749
2195
  }
1750
- /** True when a `both` widget is idle/ended with no modality chosen yet. */
2196
+ /**
2197
+ * True when a `both` widget is idle/ended with no modality chosen and nothing to
2198
+ * show. A finished conversation keeps its thread on screen instead, so ending a call
2199
+ * never hides what was said; the choose-how-to-talk entry comes back only once the
2200
+ * visitor starts over.
2201
+ */
1751
2202
  isBothPreCall() {
1752
- return this.config.mode === "both" && this.activeMode === null && (this.state === "idle" || this.state === "ended");
2203
+ return this.config.mode === "both" && this.activeMode === null && this.transcripts.length === 0 && (this.state === "idle" || this.state === "ended");
1753
2204
  }
1754
2205
  // ---- BYO reCAPTCHA gate ----------------------------------------------------
1755
2206
  /** True when a site key is configured and this session has not solved it yet. */
@@ -1850,7 +2301,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1850
2301
  body.appendChild(this.buildAvatar("lg"));
1851
2302
  const prompt = document.createElement("p");
1852
2303
  prompt.className = "tw-prompt";
1853
- prompt.textContent = this.config.greeting || "How would you like to talk?";
2304
+ prompt.textContent = this.config.greeting || this.config.copy.chooseModePrompt;
1854
2305
  body.appendChild(prompt);
1855
2306
  const choices = document.createElement("div");
1856
2307
  choices.className = "tw-choices";
@@ -1862,10 +2313,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1862
2313
  const span = document.createElement("span");
1863
2314
  span.textContent = text;
1864
2315
  btn.appendChild(span);
1865
- btn.addEventListener("click", () => {
1866
- if (modality === "text") this.transcripts = [];
1867
- void this.beginCall(modality);
1868
- });
2316
+ btn.addEventListener("click", () => this.startOver(modality));
1869
2317
  return btn;
1870
2318
  };
1871
2319
  choices.appendChild(choice(ICONS.phone, this.config.startCallText, "voice", true));
@@ -1879,10 +2327,10 @@ var TrilletWidgetElement = class extends HTMLElement {
1879
2327
  body.appendChild(this.buildAvatar("lg"));
1880
2328
  const status = document.createElement("p");
1881
2329
  status.className = "tw-prompt";
1882
- if (this.state === "connecting") status.textContent = "Connecting\u2026";
2330
+ if (this.state === "connecting") status.textContent = this.config.copy.connecting;
1883
2331
  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";
2332
+ else if (this.state === "ended") status.textContent = (_a = this.errorText) != null ? _a : this.config.copy.callEnded;
2333
+ else status.textContent = this.config.actionText || this.config.copy.talkToUs;
1886
2334
  if (this.errorText && this.state !== "live") status.classList.add("tw-error-text");
1887
2335
  body.appendChild(status);
1888
2336
  const timer = document.createElement("div");
@@ -1914,17 +2362,17 @@ var TrilletWidgetElement = class extends HTMLElement {
1914
2362
  const footer2 = document.createElement("div");
1915
2363
  footer2.className = "tw-chat-ended";
1916
2364
  const status = document.createElement("span");
1917
- status.textContent = (_a = this.errorText) != null ? _a : "This chat has ended.";
2365
+ status.textContent = (_a = this.errorText) != null ? _a : this.config.copy.chatEnded;
1918
2366
  if (this.errorText) status.classList.add("tw-error-text");
1919
2367
  footer2.appendChild(status);
1920
2368
  const restart = document.createElement("button");
1921
2369
  restart.type = "button";
1922
2370
  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
- });
2371
+ restart.textContent = this.config.copy.startNewChat;
2372
+ restart.addEventListener(
2373
+ "click",
2374
+ () => this.startOver(this.config.mode === "both" ? void 0 : this.resolvedMode())
2375
+ );
1928
2376
  footer2.appendChild(restart);
1929
2377
  body.appendChild(footer2);
1930
2378
  const feedback = this.renderFeedback();
@@ -1945,10 +2393,17 @@ var TrilletWidgetElement = class extends HTMLElement {
1945
2393
  const endBtn = document.createElement("button");
1946
2394
  endBtn.className = "tw-link-btn tw-end-chat";
1947
2395
  endBtn.type = "button";
1948
- endBtn.textContent = this.config.mode === "text" ? this.config.endCallText : "End conversation";
2396
+ endBtn.textContent = this.config.mode === "text" ? this.config.endCallText : this.config.copy.endConversationText;
1949
2397
  endBtn.disabled = this.state === "connecting";
1950
2398
  endBtn.addEventListener("click", () => this.endConversation());
1951
2399
  footer.appendChild(endBtn);
2400
+ const startOverBtn = document.createElement("button");
2401
+ startOverBtn.className = "tw-link-btn";
2402
+ startOverBtn.type = "button";
2403
+ startOverBtn.textContent = this.config.copy.startOver;
2404
+ startOverBtn.disabled = this.state === "connecting";
2405
+ startOverBtn.addEventListener("click", () => this.startOver(this.resolvedMode()));
2406
+ footer.appendChild(startOverBtn);
1952
2407
  body.appendChild(footer);
1953
2408
  }
1954
2409
  /** Starter questions, shown until the visitor has said something. */
@@ -1978,18 +2433,16 @@ var TrilletWidgetElement = class extends HTMLElement {
1978
2433
  const isText = this.resolvedMode() === "text";
1979
2434
  startBtn.innerHTML = isText ? ICONS.chat : ICONS.phone;
1980
2435
  const span = document.createElement("span");
1981
- span.textContent = isText ? "Start chat" : this.config.startCallText;
2436
+ span.textContent = isText ? this.config.copy.startChatText : this.config.startCallText;
1982
2437
  startBtn.appendChild(span);
1983
- startBtn.addEventListener("click", () => {
1984
- void this.beginCall();
1985
- });
2438
+ startBtn.addEventListener("click", () => this.startOver());
1986
2439
  controls.appendChild(startBtn);
1987
2440
  return controls;
1988
2441
  }
1989
2442
  if (this.resolvedMode() === "voice") {
1990
2443
  const micBtn = this.iconButton(
1991
2444
  this.micEnabled ? ICONS.mic : ICONS.micOff,
1992
- this.micEnabled ? "Mute microphone" : "Unmute microphone",
2445
+ this.micEnabled ? this.config.copy.muteMic : this.config.copy.unmuteMic,
1993
2446
  () => {
1994
2447
  var _a;
1995
2448
  this.micEnabled = !this.micEnabled;
@@ -2022,7 +2475,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2022
2475
  text.className = "tw-callbar-text";
2023
2476
  const activity = document.createElement("div");
2024
2477
  activity.className = "tw-callbar-activity";
2025
- activity.textContent = connecting ? "Connecting\u2026" : this.speaking ? this.config.speakingText : this.config.listeningText;
2478
+ activity.textContent = connecting ? this.config.copy.connecting : this.speaking ? this.config.speakingText : this.config.listeningText;
2026
2479
  const meta = document.createElement("div");
2027
2480
  meta.className = "tw-callbar-meta tw-timer";
2028
2481
  const name = this.speakerName();
@@ -2032,7 +2485,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2032
2485
  bar.appendChild(text);
2033
2486
  const mute = this.iconButton(
2034
2487
  this.micEnabled ? ICONS.mic : ICONS.micOff,
2035
- this.micEnabled ? "Mute microphone" : "Unmute microphone",
2488
+ this.micEnabled ? this.config.copy.muteMic : this.config.copy.unmuteMic,
2036
2489
  () => {
2037
2490
  var _a;
2038
2491
  this.micEnabled = !this.micEnabled;
@@ -2044,12 +2497,12 @@ var TrilletWidgetElement = class extends HTMLElement {
2044
2497
  mute.disabled = connecting;
2045
2498
  bar.appendChild(mute);
2046
2499
  if (inPanel) {
2047
- const back = this.iconButton(ICONS.keyboard, "Type instead", () => void this.switchModality(), "tw-sq tw-sq-quiet");
2500
+ const back = this.iconButton(ICONS.keyboard, this.config.copy.typeInstead, () => void this.switchModality(), "tw-sq tw-sq-quiet");
2048
2501
  back.disabled = this.switchingSide || connecting;
2049
2502
  bar.appendChild(back);
2050
2503
  } else if (this.config.mode === "both") {
2051
2504
  bar.appendChild(
2052
- this.iconButton(ICONS.chat, "Show the conversation", () => {
2505
+ this.iconButton(ICONS.chat, this.config.copy.showConversation, () => {
2053
2506
  this.open = true;
2054
2507
  this.render();
2055
2508
  }, "tw-sq tw-sq-quiet")
@@ -2071,7 +2524,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2071
2524
  const sendBtn = document.createElement("button");
2072
2525
  sendBtn.className = "tw-send-btn";
2073
2526
  sendBtn.type = "submit";
2074
- sendBtn.setAttribute("aria-label", "Send");
2527
+ sendBtn.setAttribute("aria-label", this.config.copy.send);
2075
2528
  sendBtn.innerHTML = ICONS.send;
2076
2529
  const syncState = () => {
2077
2530
  sendBtn.disabled = this.state !== "live" || !input.value.trim();
@@ -2103,7 +2556,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2103
2556
  });
2104
2557
  row.appendChild(input);
2105
2558
  if (this.config.mode === "both") {
2106
- const mic = this.iconButton(ICONS.phone, "Talk instead", () => void this.switchModality(), "tw-composer-mic");
2559
+ const mic = this.iconButton(ICONS.phone, this.config.copy.talkInstead, () => void this.switchModality(), "tw-composer-mic");
2107
2560
  mic.disabled = this.state !== "live" || this.switchingSide;
2108
2561
  row.appendChild(mic);
2109
2562
  }
@@ -2163,7 +2616,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2163
2616
  } else if (this.isAwaitingReply()) {
2164
2617
  const typing = document.createElement("div");
2165
2618
  typing.className = "tw-msg tw-assistant tw-typing";
2166
- typing.setAttribute("aria-label", "Typing");
2619
+ typing.setAttribute("aria-label", this.config.copy.typing);
2167
2620
  typing.innerHTML = "<span></span><span></span><span></span>";
2168
2621
  wrap.appendChild(typing);
2169
2622
  }
@@ -2204,13 +2657,13 @@ var TrilletWidgetElement = class extends HTMLElement {
2204
2657
  return wrap;
2205
2658
  }
2206
2659
  };
2207
- function friendlyError(err) {
2660
+ function friendlyError(err, copy) {
2208
2661
  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.";
2662
+ if (/Origin not allowed/i.test(msg)) return copy.errorNotEnabled;
2663
+ if (/Public access/i.test(msg)) return copy.errorUnavailable;
2664
+ if (/Too many/i.test(msg)) return copy.errorTooMany;
2665
+ if (/Insufficient funds/i.test(msg)) return copy.errorUnavailable;
2666
+ return copy.errorGeneric;
2214
2667
  }
2215
2668
  var DEFAULT_ACCENT = "#0062e9";
2216
2669
  function readableOn(hex) {
@@ -2294,6 +2747,8 @@ var TrilletWidget = (props) => {
2294
2747
  setAttr(el, "action-text", props.actionText);
2295
2748
  setAttr(el, "start-call-text", props.startCallText);
2296
2749
  setAttr(el, "end-call-text", props.endCallText);
2750
+ setAttr(el, "end-chat-text", props.endChatText);
2751
+ setAttr(el, "language", props.language);
2297
2752
  setAttr(el, "message-text", props.messageText);
2298
2753
  setAttr(el, "switch-to-text-text", props.switchToTextText);
2299
2754
  setAttr(el, "switch-to-voice-text", props.switchToVoiceText);