@trillet-ai/web-sdk 1.9.2 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{chunk-3MH6DJZ6.js → chunk-CVTVHUNZ.js} +12 -5
- package/dist/chunk-CVTVHUNZ.js.map +1 -0
- package/dist/{chunk-FSJ42TKR.js → chunk-IASKK2IK.js} +155 -23
- package/dist/chunk-IASKK2IK.js.map +1 -0
- package/dist/index.d.ts +34 -1
- package/dist/index.js +2 -2
- package/dist/server.d.ts +5 -1
- package/dist/server.js +1 -1
- package/dist/widget/index.d.ts +192 -46
- package/dist/widget/index.js +1513 -766
- package/dist/widget/index.js.map +1 -1
- package/dist/widget.umd.js +489 -410
- package/dist/widget.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3MH6DJZ6.js.map +0 -1
- package/dist/chunk-FSJ42TKR.js.map +0 -1
package/dist/widget/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TrilletAgent
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import
|
|
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
|
-
|
|
101
|
-
const
|
|
102
|
-
const
|
|
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
|
-
|
|
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,494 +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:
|
|
166
|
-
bottom:
|
|
217
|
+
right: 20px;
|
|
218
|
+
bottom: 20px;
|
|
167
219
|
z-index: 2147483000;
|
|
168
220
|
|
|
169
|
-
|
|
170
|
-
--
|
|
171
|
-
--
|
|
172
|
-
--
|
|
173
|
-
--
|
|
174
|
-
--
|
|
175
|
-
--
|
|
176
|
-
--
|
|
177
|
-
--
|
|
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:
|
|
180
|
-
font-size:
|
|
181
|
-
line-height: 1.
|
|
182
|
-
color: var(--
|
|
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
|
-
/* ----
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
:host([placement="bottom
|
|
191
|
-
:host([placement="
|
|
192
|
-
:host([placement="
|
|
193
|
-
:host([placement="top
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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
|
-
|
|
212
|
-
.tw-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
font-size:
|
|
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;
|
|
286
|
+
cursor: pointer;
|
|
287
|
+
transition: background 0.15s ease, filter 0.15s ease, border-color 0.15s ease;
|
|
288
|
+
}
|
|
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;
|
|
223
308
|
cursor: pointer;
|
|
224
|
-
box-shadow: var(--trillet-shadow);
|
|
225
|
-
transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
|
|
226
|
-
}
|
|
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;
|
|
237
|
-
}
|
|
238
|
-
.tw-launcher .tw-launcher-orb-avatar {
|
|
239
|
-
background: none;
|
|
240
|
-
background-size: cover;
|
|
241
|
-
background-position: center;
|
|
242
|
-
animation: none;
|
|
243
|
-
}
|
|
244
|
-
.tw-launcher-copy {
|
|
245
|
-
display: flex;
|
|
246
|
-
flex-direction: column;
|
|
247
|
-
align-items: flex-start;
|
|
248
|
-
line-height: 1.15;
|
|
249
|
-
text-align: left;
|
|
250
|
-
}
|
|
251
|
-
.tw-launcher-state {
|
|
252
|
-
font-size: 11px;
|
|
253
|
-
font-weight: 500;
|
|
254
|
-
opacity: 0.92;
|
|
255
|
-
}
|
|
256
|
-
/* Voice calls stay on this control: connecting, then hang up. */
|
|
257
|
-
.tw-launcher.tw-hangup { background: #e5484d; }
|
|
258
|
-
.tw-launcher.tw-listening {
|
|
259
|
-
box-shadow: var(--trillet-shadow), 0 0 0 3px rgba(255, 255, 255, 0.45);
|
|
260
|
-
}
|
|
261
|
-
.tw-launcher.tw-speaking {
|
|
262
|
-
box-shadow: var(--trillet-shadow), 0 0 0 4px rgba(255, 255, 255, 0.8);
|
|
263
|
-
}
|
|
264
|
-
.tw-launcher.tw-speaking .tw-launcher-orb {
|
|
265
|
-
animation: tw-orb-rotate 4.5s linear infinite, tw-bob 0.7s ease-in-out infinite alternate;
|
|
266
309
|
}
|
|
267
|
-
.tw-
|
|
268
|
-
.tw-
|
|
269
|
-
|
|
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);
|
|
270
318
|
}
|
|
271
|
-
.tw-
|
|
272
|
-
.tw-launcher:disabled:hover { transform: none; box-shadow: var(--trillet-shadow); }
|
|
319
|
+
.tw-icon-btn.tw-muted { color: var(--tw-danger); border-color: var(--tw-danger); }
|
|
273
320
|
|
|
274
|
-
/*
|
|
275
|
-
.tw-
|
|
276
|
-
display: flex;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
gap:
|
|
280
|
-
|
|
281
|
-
:
|
|
282
|
-
|
|
283
|
-
:
|
|
284
|
-
:host([placement="top"]) .tw-inline { align-items: center; }
|
|
285
|
-
.tw-inline-hint {
|
|
286
|
-
max-width: 304px;
|
|
287
|
-
padding: 8px 12px;
|
|
288
|
-
border-radius: 10px;
|
|
289
|
-
background: var(--trillet-surface);
|
|
290
|
-
color: var(--trillet-on-surface);
|
|
291
|
-
border: 1px solid var(--trillet-border);
|
|
292
|
-
box-shadow: var(--trillet-shadow);
|
|
293
|
-
font-size: 12px;
|
|
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;
|
|
294
331
|
font-weight: 600;
|
|
332
|
+
cursor: pointer;
|
|
295
333
|
}
|
|
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; }
|
|
296
341
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
border-radius: 16px;
|
|
304
|
-
box-shadow: var(--trillet-shadow);
|
|
305
|
-
overflow: hidden;
|
|
306
|
-
display: flex;
|
|
307
|
-
flex-direction: column;
|
|
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);
|
|
308
348
|
}
|
|
309
|
-
.tw-
|
|
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; }
|
|
310
353
|
|
|
311
|
-
.tw-
|
|
312
|
-
display: flex;
|
|
354
|
+
.tw-link-btn {
|
|
355
|
+
display: inline-flex;
|
|
313
356
|
align-items: center;
|
|
314
|
-
gap:
|
|
315
|
-
|
|
316
|
-
|
|
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;
|
|
317
364
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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 {
|
|
321
372
|
display: flex;
|
|
322
373
|
align-items: center;
|
|
323
|
-
gap:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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;
|
|
332
383
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
.tw-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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;
|
|
396
|
+
}
|
|
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;
|
|
339
409
|
white-space: nowrap;
|
|
340
410
|
overflow: hidden;
|
|
341
411
|
text-overflow: ellipsis;
|
|
342
|
-
max-width: 120px;
|
|
343
412
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
.tw-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
font-size:
|
|
351
|
-
|
|
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);
|
|
352
445
|
white-space: nowrap;
|
|
353
446
|
overflow: hidden;
|
|
354
447
|
text-overflow: ellipsis;
|
|
355
448
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
width:
|
|
362
|
-
|
|
363
|
-
|
|
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 {
|
|
364
466
|
display: inline-flex;
|
|
365
467
|
align-items: center;
|
|
366
468
|
justify-content: center;
|
|
367
|
-
|
|
368
|
-
|
|
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;
|
|
369
476
|
}
|
|
370
|
-
.tw-
|
|
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)); }
|
|
371
481
|
|
|
372
|
-
.
|
|
373
|
-
|
|
482
|
+
/* Terms dialog keeps a small card. */
|
|
483
|
+
.tw-card {
|
|
374
484
|
display: flex;
|
|
375
485
|
flex-direction: column;
|
|
376
|
-
align-items: center;
|
|
377
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);
|
|
378
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); }
|
|
379
497
|
|
|
380
|
-
/* ----
|
|
381
|
-
.tw-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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 {
|
|
385
514
|
display: flex;
|
|
386
515
|
align-items: center;
|
|
387
|
-
|
|
516
|
+
gap: 10px;
|
|
517
|
+
padding: 12px 10px 12px 14px;
|
|
518
|
+
border-bottom: 1px solid var(--tw-line);
|
|
388
519
|
}
|
|
389
|
-
|
|
390
|
-
.tw-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
background: radial-gradient(circle, var(--trillet-orb-2), transparent 70%);
|
|
397
|
-
opacity: 0.5;
|
|
398
|
-
filter: blur(10px);
|
|
399
|
-
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;
|
|
400
527
|
}
|
|
401
|
-
.tw-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
|
|
410
|
-
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;
|
|
411
536
|
}
|
|
412
|
-
|
|
413
|
-
.tw-orb::after {
|
|
537
|
+
.tw-status.tw-online::before {
|
|
414
538
|
content: '';
|
|
415
|
-
|
|
416
|
-
|
|
539
|
+
width: 6px;
|
|
540
|
+
height: 6px;
|
|
417
541
|
border-radius: 50%;
|
|
418
|
-
background:
|
|
419
|
-
}
|
|
420
|
-
/* When an avatar image is provided, show it instead of the gradient. */
|
|
421
|
-
.tw-orb.tw-orb-avatar {
|
|
422
|
-
background: none;
|
|
423
|
-
background-size: cover;
|
|
424
|
-
background-position: center;
|
|
425
|
-
animation: none;
|
|
426
|
-
}
|
|
427
|
-
.tw-orb.tw-orb-avatar::after { display: none; }
|
|
428
|
-
|
|
429
|
-
@keyframes tw-orb-rotate { to { transform: rotate(360deg); } }
|
|
430
|
-
@keyframes tw-aura {
|
|
431
|
-
0%, 100% { transform: scale(1); opacity: 0.4; }
|
|
432
|
-
50% { transform: scale(1.16); opacity: 0.66; }
|
|
542
|
+
background: var(--tw-online);
|
|
433
543
|
}
|
|
544
|
+
.tw-brand-logo { height: 22px; max-width: 72px; object-fit: contain; }
|
|
545
|
+
.tw-header-actions { display: flex; gap: 2px; }
|
|
434
546
|
|
|
435
|
-
|
|
436
|
-
.tw-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
border: 2px solid var(--trillet-orb-1);
|
|
443
|
-
animation: tw-pulse 1.4s ease-out infinite;
|
|
444
|
-
}
|
|
445
|
-
@keyframes tw-pulse {
|
|
446
|
-
0% { transform: scale(0.85); opacity: 0.7; }
|
|
447
|
-
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;
|
|
448
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; }
|
|
449
560
|
|
|
450
|
-
/*
|
|
451
|
-
.tw-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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;
|
|
457
571
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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;
|
|
462
580
|
}
|
|
463
|
-
.tw-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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);
|
|
467
587
|
}
|
|
468
|
-
|
|
469
|
-
.tw-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
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);
|
|
474
593
|
}
|
|
475
|
-
.tw-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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;
|
|
479
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; }
|
|
480
604
|
|
|
481
|
-
|
|
482
|
-
/* The checkbox is a light-DOM node projected in via <slot name="recaptcha"> \u2014 it can't
|
|
483
|
-
render directly in the shadow root (reCAPTCHA v2 hangs there). ::slotted targets that
|
|
484
|
-
projected node. The checkbox iframe is a fixed 304x78; scale it down on narrow panels
|
|
485
|
-
so it doesn't overflow. */
|
|
486
|
-
.tw-recaptcha-slot {
|
|
605
|
+
.tw-suggestions {
|
|
487
606
|
display: flex;
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
display: flex;
|
|
493
|
-
justify-content: center;
|
|
607
|
+
flex-wrap: wrap;
|
|
608
|
+
justify-content: flex-end;
|
|
609
|
+
gap: 6px;
|
|
610
|
+
padding: 2px 14px 10px;
|
|
494
611
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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;
|
|
500
621
|
}
|
|
622
|
+
.tw-suggestion:hover { border-color: var(--tw-accent); color: var(--tw-accent); }
|
|
501
623
|
|
|
502
|
-
|
|
503
|
-
.tw-controls {
|
|
624
|
+
.tw-composer {
|
|
504
625
|
display: flex;
|
|
505
|
-
align-items:
|
|
506
|
-
gap:
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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;
|
|
513
634
|
}
|
|
514
|
-
.tw-
|
|
515
|
-
.tw-
|
|
635
|
+
.tw-composer:focus-within { border-color: var(--tw-accent); }
|
|
636
|
+
.tw-text-input {
|
|
637
|
+
flex: 1;
|
|
638
|
+
min-width: 0;
|
|
516
639
|
border: none;
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
font-size: 14px;
|
|
520
|
-
font-weight: 600;
|
|
521
|
-
cursor: pointer;
|
|
522
|
-
background: var(--trillet-accent);
|
|
523
|
-
color: #fff;
|
|
524
|
-
transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
|
|
525
|
-
}
|
|
526
|
-
.tw-primary-btn:hover { opacity: 0.92; }
|
|
527
|
-
.tw-primary-btn.tw-danger { background: #e5484d; }
|
|
528
|
-
.tw-primary-btn.tw-secondary {
|
|
640
|
+
outline: none;
|
|
641
|
+
resize: none;
|
|
529
642
|
background: transparent;
|
|
530
|
-
color: var(--
|
|
531
|
-
|
|
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;
|
|
532
649
|
}
|
|
533
|
-
.tw-
|
|
534
|
-
.tw-
|
|
535
|
-
|
|
536
|
-
|
|
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;
|
|
537
656
|
border: none;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
font-weight: 500;
|
|
542
|
-
cursor: pointer;
|
|
543
|
-
padding: 2px 6px;
|
|
544
|
-
text-decoration: underline;
|
|
545
|
-
text-underline-offset: 2px;
|
|
546
|
-
}
|
|
547
|
-
.tw-switch-btn:hover { color: var(--trillet-accent); }
|
|
548
|
-
.tw-mic-btn {
|
|
549
|
-
border: 1px solid var(--trillet-border);
|
|
550
|
-
background: var(--trillet-surface);
|
|
551
|
-
color: var(--trillet-on-surface);
|
|
552
|
-
border-radius: 50%;
|
|
553
|
-
width: 42px;
|
|
554
|
-
height: 42px;
|
|
555
|
-
cursor: pointer;
|
|
657
|
+
border-radius: 8px;
|
|
658
|
+
background: var(--tw-accent);
|
|
659
|
+
color: var(--tw-on-accent);
|
|
556
660
|
display: inline-flex;
|
|
557
661
|
align-items: center;
|
|
558
662
|
justify-content: center;
|
|
559
|
-
|
|
663
|
+
cursor: pointer;
|
|
560
664
|
}
|
|
561
|
-
.tw-
|
|
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; }
|
|
562
668
|
|
|
563
|
-
|
|
564
|
-
.tw-text-input-row {
|
|
669
|
+
.tw-voice-bar {
|
|
565
670
|
display: flex;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
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);
|
|
572
676
|
border-radius: 10px;
|
|
573
|
-
|
|
574
|
-
font-size: 14px;
|
|
575
|
-
font-family: inherit;
|
|
576
|
-
color: var(--trillet-on-surface);
|
|
577
|
-
background: var(--trillet-surface);
|
|
578
|
-
outline: none;
|
|
677
|
+
background: var(--tw-raised);
|
|
579
678
|
}
|
|
580
|
-
.tw-text
|
|
581
|
-
.tw-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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;
|
|
589
690
|
}
|
|
590
691
|
|
|
591
|
-
|
|
592
|
-
.tw-transcript {
|
|
593
|
-
width: 100%;
|
|
594
|
-
max-height: 200px;
|
|
595
|
-
overflow-y: auto;
|
|
692
|
+
.tw-chat-footer {
|
|
596
693
|
display: flex;
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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);
|
|
602
711
|
}
|
|
603
712
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
.tw-
|
|
609
|
-
|
|
610
|
-
|
|
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;
|
|
611
734
|
overflow-y: auto;
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
border-top: 1px solid var(--trillet-border);
|
|
615
|
-
border-radius: 12px;
|
|
616
|
-
margin-top: 0;
|
|
617
|
-
background: rgba(0, 0, 0, 0.015);
|
|
618
|
-
scroll-behavior: smooth;
|
|
735
|
+
font-size: 14px;
|
|
736
|
+
color: var(--tw-muted);
|
|
619
737
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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;
|
|
627
747
|
}
|
|
628
|
-
.tw-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
748
|
+
.tw-terms .tw-secondary-btn { height: 40px; }
|
|
749
|
+
|
|
750
|
+
/* ---- Feedback ---- */
|
|
751
|
+
.tw-feedback {
|
|
752
|
+
display: flex;
|
|
753
|
+
align-items: center;
|
|
754
|
+
gap: 2px;
|
|
632
755
|
font-size: 13px;
|
|
633
|
-
|
|
634
|
-
word-break: break-word;
|
|
756
|
+
color: var(--tw-muted);
|
|
635
757
|
}
|
|
636
|
-
.tw-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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; }
|
|
641
771
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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); }
|
|
647
777
|
}
|
|
648
778
|
|
|
779
|
+
.tw-enter { animation: tw-rise 0.2s ease-out both; }
|
|
780
|
+
|
|
649
781
|
.tw-hidden { display: none !important; }
|
|
650
782
|
`
|
|
651
783
|
);
|
|
@@ -697,6 +829,85 @@ async function renderRecaptchaCheckbox(options) {
|
|
|
697
829
|
});
|
|
698
830
|
}
|
|
699
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
|
+
|
|
700
911
|
// src/widget/TrilletWidgetElement.ts
|
|
701
912
|
var TrilletWidgetElement = class extends HTMLElement {
|
|
702
913
|
constructor() {
|
|
@@ -717,6 +928,13 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
717
928
|
// True while tearing down one modality and reconnecting in the other, so lifecycle
|
|
718
929
|
// events (call-start/conversationStarted) aren't re-emitted for an internal switch.
|
|
719
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;
|
|
720
938
|
// maxCallDuration countdown (UX only — see startConversation()).
|
|
721
939
|
this.durationTimer = null;
|
|
722
940
|
this.remainingSeconds = null;
|
|
@@ -735,6 +953,25 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
735
953
|
this.recaptchaSolved = false;
|
|
736
954
|
this.recaptchaSlot = null;
|
|
737
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 = "";
|
|
738
975
|
this.root = this.attachShadow({ mode: "open" });
|
|
739
976
|
this.styleEl = document.createElement("style");
|
|
740
977
|
this.styleEl.textContent = WIDGET_STYLES;
|
|
@@ -747,11 +984,37 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
747
984
|
return OBSERVED_ATTRIBUTES;
|
|
748
985
|
}
|
|
749
986
|
connectedCallback() {
|
|
750
|
-
this.
|
|
987
|
+
this.refreshConfig();
|
|
988
|
+
void this.loadRemoteConfig();
|
|
989
|
+
}
|
|
990
|
+
refreshConfig() {
|
|
991
|
+
this.config = configFromElement(this, this.remote);
|
|
751
992
|
this.syncActiveMode();
|
|
752
993
|
this.applyTheme();
|
|
753
994
|
this.render();
|
|
754
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
|
+
}
|
|
755
1018
|
disconnectedCallback() {
|
|
756
1019
|
this.clearDurationTimer();
|
|
757
1020
|
this.teardownAgent();
|
|
@@ -759,10 +1022,25 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
759
1022
|
}
|
|
760
1023
|
attributeChangedCallback() {
|
|
761
1024
|
if (!this.isConnected) return;
|
|
762
|
-
this.
|
|
763
|
-
this.
|
|
764
|
-
|
|
765
|
-
|
|
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");
|
|
766
1044
|
}
|
|
767
1045
|
// ---- Public element API ----------------------------------------------------
|
|
768
1046
|
/**
|
|
@@ -771,7 +1049,8 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
771
1049
|
*/
|
|
772
1050
|
async startConversation(modality) {
|
|
773
1051
|
if (this.state === "connecting" || this.state === "live") return;
|
|
774
|
-
|
|
1052
|
+
const chat = this.config.mode === "text" || this.config.mode === "both" && modality !== "voice";
|
|
1053
|
+
if (chat) {
|
|
775
1054
|
this.open = true;
|
|
776
1055
|
}
|
|
777
1056
|
if (this.needsRecaptcha()) {
|
|
@@ -794,13 +1073,6 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
794
1073
|
this.endConversation();
|
|
795
1074
|
}
|
|
796
1075
|
// ---- Modality helpers ------------------------------------------------------
|
|
797
|
-
/**
|
|
798
|
-
* Voice embeds run entirely on the floating control. Text and `both` still need
|
|
799
|
-
* the conversation panel.
|
|
800
|
-
*/
|
|
801
|
-
isInlineVoice() {
|
|
802
|
-
return this.config.mode === "voice";
|
|
803
|
-
}
|
|
804
1076
|
/** The concrete modality to run for the current session (`both` -> activeMode). */
|
|
805
1077
|
resolvedMode() {
|
|
806
1078
|
var _a;
|
|
@@ -827,32 +1099,72 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
827
1099
|
this.agent = null;
|
|
828
1100
|
}
|
|
829
1101
|
/**
|
|
830
|
-
* Switch
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
* duration timer are preserved across the switch; no lifecycle events fire (it's one
|
|
834
|
-
* 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.
|
|
835
1105
|
*/
|
|
836
1106
|
async switchModality() {
|
|
837
|
-
if (this.config.mode !== "both" || this.state !== "live") return;
|
|
838
|
-
const
|
|
839
|
-
this.
|
|
840
|
-
this.
|
|
841
|
-
this.
|
|
842
|
-
|
|
843
|
-
|
|
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);
|
|
844
1145
|
}
|
|
845
1146
|
// ---- Credential resolution + call lifecycle --------------------------------
|
|
846
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";
|
|
847
1155
|
if (modality) this.activeMode = modality;
|
|
848
1156
|
const mode = this.resolvedMode();
|
|
1157
|
+
const session = this.config.mode === "both" ? "multimodal" : mode;
|
|
1158
|
+
this.notice = null;
|
|
849
1159
|
if (!this.switching) this.display = null;
|
|
850
1160
|
this.setState("connecting");
|
|
851
1161
|
try {
|
|
852
1162
|
const agent = new TrilletAgent({
|
|
853
1163
|
agentId: this.config.agentId,
|
|
854
1164
|
workspaceId: this.config.workspaceId,
|
|
855
|
-
|
|
1165
|
+
apiBaseUrl: this.config.apiBase,
|
|
1166
|
+
mode: session,
|
|
1167
|
+
startWithVoice: session === "multimodal" && mode === "voice",
|
|
856
1168
|
variables: this.config.variables
|
|
857
1169
|
});
|
|
858
1170
|
this.agent = agent;
|
|
@@ -860,7 +1172,7 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
860
1172
|
if (this.config.signedUrlEndpoint || this.getRoomDetails) {
|
|
861
1173
|
let details;
|
|
862
1174
|
if (this.getRoomDetails) {
|
|
863
|
-
details = await this.getRoomDetails();
|
|
1175
|
+
details = await this.getRoomDetails({ mode, session });
|
|
864
1176
|
} else {
|
|
865
1177
|
const res = await fetch(this.config.signedUrlEndpoint, {
|
|
866
1178
|
method: "GET",
|
|
@@ -887,12 +1199,16 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
887
1199
|
}
|
|
888
1200
|
wireAgentEvents(agent) {
|
|
889
1201
|
agent.on("connected", (details) => {
|
|
890
|
-
var _a;
|
|
1202
|
+
var _a, _b;
|
|
891
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;
|
|
892
1205
|
const wasSwitching = this.switching;
|
|
893
1206
|
this.setState("live");
|
|
894
1207
|
this.startDurationTimer(!wasSwitching);
|
|
895
1208
|
this.switching = false;
|
|
1209
|
+
if (this.pendingMessage) {
|
|
1210
|
+
this.pendingTimer = setTimeout(() => this.flushPending(), 25e3);
|
|
1211
|
+
}
|
|
896
1212
|
});
|
|
897
1213
|
agent.on("disconnected", () => {
|
|
898
1214
|
this.endLocalCall();
|
|
@@ -900,32 +1216,43 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
900
1216
|
agent.on("error", (error) => {
|
|
901
1217
|
this.handleError(error);
|
|
902
1218
|
});
|
|
903
|
-
agent.on("
|
|
904
|
-
this.
|
|
905
|
-
this.render();
|
|
906
|
-
});
|
|
907
|
-
agent.on("assistantStoppedSpeaking", () => {
|
|
1219
|
+
agent.on("modalityChanged", (side) => {
|
|
1220
|
+
this.activeMode = side;
|
|
908
1221
|
this.speaking = false;
|
|
1222
|
+
this.dispatch("modality", side);
|
|
909
1223
|
this.render();
|
|
910
1224
|
});
|
|
1225
|
+
agent.on("audioData", (samples) => this.setLevel(samples));
|
|
1226
|
+
agent.on("assistantStartedSpeaking", () => this.setSpeaking(true));
|
|
1227
|
+
agent.on("assistantStoppedSpeaking", () => this.setSpeaking(false));
|
|
911
1228
|
agent.on("transcriptUpdate", (transcripts) => {
|
|
912
|
-
this.transcripts = transcripts;
|
|
913
|
-
this.
|
|
914
|
-
|
|
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();
|
|
915
1235
|
});
|
|
916
1236
|
}
|
|
917
1237
|
endLocalCall() {
|
|
918
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
|
+
}
|
|
919
1242
|
this.clearDurationTimer();
|
|
920
1243
|
this.speaking = false;
|
|
921
1244
|
this.dispatch("call-end", this.elapsedSeconds);
|
|
922
1245
|
this.dispatch("conversationEnded", this.elapsedSeconds);
|
|
923
1246
|
this.setState("ended");
|
|
924
1247
|
this.agent = null;
|
|
1248
|
+
this.pendingMessage = null;
|
|
1249
|
+
if (this.pendingTimer) clearTimeout(this.pendingTimer);
|
|
1250
|
+
this.pendingTimer = null;
|
|
925
1251
|
if (this.config.mode === "both") this.activeMode = null;
|
|
926
1252
|
}
|
|
927
1253
|
handleError(error) {
|
|
928
1254
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1255
|
+
this.errorText = friendlyError(err);
|
|
929
1256
|
this.clearDurationTimer();
|
|
930
1257
|
this.speaking = false;
|
|
931
1258
|
this.switching = false;
|
|
@@ -966,6 +1293,7 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
966
1293
|
// ---- State + DOM events ----------------------------------------------------
|
|
967
1294
|
setState(state) {
|
|
968
1295
|
const prev = this.state;
|
|
1296
|
+
if (state === "connecting") this.errorText = null;
|
|
969
1297
|
this.state = state;
|
|
970
1298
|
if (state === "live" && prev !== "live" && !this.switching) {
|
|
971
1299
|
this.dispatch("call-start", void 0);
|
|
@@ -978,16 +1306,21 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
978
1306
|
}
|
|
979
1307
|
// ---- Theming ----------------------------------------------------------------
|
|
980
1308
|
applyTheme() {
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
this.style.setProperty("--
|
|
984
|
-
this.
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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;
|
|
991
1324
|
}
|
|
992
1325
|
// ---- Rendering --------------------------------------------------------------
|
|
993
1326
|
formatTime(total) {
|
|
@@ -995,23 +1328,22 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
995
1328
|
const s = total % 60;
|
|
996
1329
|
return `${m}:${s.toString().padStart(2, "0")}`;
|
|
997
1330
|
}
|
|
1331
|
+
/** The line under the agent's name in the header. */
|
|
998
1332
|
statusText() {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
return this.speaking ? this.config.speakingText : this.config.listeningText;
|
|
1004
|
-
case "ended":
|
|
1005
|
-
return "Call ended";
|
|
1006
|
-
default:
|
|
1007
|
-
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();
|
|
1008
1337
|
}
|
|
1338
|
+
if (this.state === "live") return "Online";
|
|
1339
|
+
return this.config.brand.name || "Online";
|
|
1009
1340
|
}
|
|
1010
1341
|
renderStatus() {
|
|
1011
1342
|
const statusEl = this.root.querySelector(".tw-status");
|
|
1012
1343
|
if (statusEl) statusEl.textContent = this.statusText();
|
|
1013
|
-
|
|
1014
|
-
|
|
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
|
+
});
|
|
1015
1347
|
}
|
|
1016
1348
|
timerText() {
|
|
1017
1349
|
if (this.state !== "live") return "";
|
|
@@ -1020,109 +1352,329 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1020
1352
|
}
|
|
1021
1353
|
return this.formatTime(this.elapsedSeconds);
|
|
1022
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
|
+
}
|
|
1023
1367
|
render() {
|
|
1024
1368
|
this.container.replaceChildren();
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
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";
|
|
1028
1380
|
}
|
|
1029
|
-
if (
|
|
1030
|
-
|
|
1031
|
-
|
|
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() || "";
|
|
1411
|
+
}
|
|
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 = "") {
|
|
1421
|
+
const btn = document.createElement("button");
|
|
1422
|
+
btn.type = "button";
|
|
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;
|
|
1032
1442
|
}
|
|
1033
|
-
|
|
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;
|
|
1483
|
+
this.render();
|
|
1484
|
+
});
|
|
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;
|
|
1034
1515
|
}
|
|
1035
1516
|
/**
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
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.
|
|
1039
1524
|
*/
|
|
1040
|
-
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
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) {
|
|
1049
1626
|
const slot = document.createElement("slot");
|
|
1050
1627
|
slot.setAttribute("name", "recaptcha");
|
|
1051
1628
|
slot.className = "tw-recaptcha-slot";
|
|
1052
|
-
|
|
1629
|
+
stack.insertBefore(slot, bar);
|
|
1053
1630
|
this.ensureRecaptchaSlot();
|
|
1054
1631
|
}
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
orb.className = "tw-launcher-orb";
|
|
1060
|
-
if (this.config.avatar) {
|
|
1061
|
-
orb.classList.add("tw-launcher-orb-avatar");
|
|
1062
|
-
orb.style.backgroundImage = `url("${this.config.avatar}")`;
|
|
1632
|
+
const feedback = idle ? this.renderFeedback() : null;
|
|
1633
|
+
if (feedback) {
|
|
1634
|
+
feedback.classList.add("tw-bar-note");
|
|
1635
|
+
stack.insertBefore(feedback, bar);
|
|
1063
1636
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
stateLabel.className = "tw-launcher-state";
|
|
1081
|
-
stateLabel.textContent = activity;
|
|
1082
|
-
copy.appendChild(label);
|
|
1083
|
-
copy.appendChild(stateLabel);
|
|
1084
|
-
btn.setAttribute("aria-label", `${this.config.endCallText}. ${activity}`);
|
|
1085
|
-
btn.addEventListener("click", () => {
|
|
1086
|
-
this.endConversation();
|
|
1087
|
-
});
|
|
1088
|
-
} else {
|
|
1089
|
-
label.textContent = this.config.actionText || this.config.startCallText;
|
|
1090
|
-
btn.disabled = showGate;
|
|
1091
|
-
btn.setAttribute("aria-label", label.textContent);
|
|
1092
|
-
btn.addEventListener("click", () => {
|
|
1093
|
-
if (this.state === "connecting" || this.state === "live") return;
|
|
1094
|
-
if (this.needsRecaptcha()) return;
|
|
1095
|
-
void this.beginCall();
|
|
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);
|
|
1096
1653
|
});
|
|
1654
|
+
row.appendChild(chip);
|
|
1097
1655
|
}
|
|
1098
|
-
|
|
1099
|
-
btn.appendChild(copy);
|
|
1100
|
-
wrap.appendChild(btn);
|
|
1101
|
-
return wrap;
|
|
1656
|
+
stack.insertBefore(row, bar);
|
|
1102
1657
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
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;
|
|
1112
1670
|
}
|
|
1113
|
-
|
|
1114
|
-
const label = document.createElement("span");
|
|
1115
|
-
label.textContent = this.config.actionText || this.config.startCallText;
|
|
1116
|
-
btn.appendChild(label);
|
|
1117
|
-
btn.addEventListener("click", () => {
|
|
1118
|
-
this.open = true;
|
|
1119
|
-
this.render();
|
|
1120
|
-
});
|
|
1121
|
-
return btn;
|
|
1671
|
+
this.render();
|
|
1122
1672
|
}
|
|
1123
1673
|
renderPanel() {
|
|
1124
1674
|
const panel = document.createElement("div");
|
|
1125
1675
|
panel.className = `tw-panel${this.config.variant === "expanded" ? " tw-expanded" : ""}`;
|
|
1676
|
+
panel.setAttribute("role", "dialog");
|
|
1677
|
+
panel.setAttribute("aria-label", this.headerTitle() || "Chat");
|
|
1126
1678
|
panel.appendChild(this.renderHeader());
|
|
1127
1679
|
panel.appendChild(this.renderBody());
|
|
1128
1680
|
return panel;
|
|
@@ -1131,90 +1683,70 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1131
1683
|
* The header title identifying who the user is talking to. Each identity value is
|
|
1132
1684
|
* code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
|
|
1133
1685
|
* config value takes precedence over the corresponding backend `display.*` value
|
|
1134
|
-
* (which only arrives on `connected`), falling back to it when unset.
|
|
1135
|
-
*
|
|
1136
|
-
* effectiveCallFlow = config.callFlowName ?? display.call_flow_name
|
|
1137
|
-
* effectiveWorkspace = config.workspaceName ?? display.workspace_name
|
|
1138
|
-
* title = effectiveAgent || effectiveCallFlow || effectiveWorkspace || ''
|
|
1139
|
-
* Because the overrides are static config, the title can render pre-call. Note:
|
|
1140
|
-
* `brand.name` is intentionally NOT part of this chain — it renders in the brand
|
|
1141
|
-
* 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.
|
|
1142
1688
|
*/
|
|
1143
1689
|
headerTitle() {
|
|
1144
|
-
var _a, _b, _c, _d
|
|
1145
|
-
const
|
|
1146
|
-
const
|
|
1147
|
-
const
|
|
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;
|
|
1148
1695
|
return effectiveAgent || effectiveCallFlow || effectiveWorkspace || "";
|
|
1149
1696
|
}
|
|
1150
1697
|
renderHeader() {
|
|
1151
1698
|
const header = document.createElement("div");
|
|
1152
1699
|
header.className = "tw-header";
|
|
1153
|
-
if (this.
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
if (this.config.brand.logo) {
|
|
1157
|
-
const logo = document.createElement("img");
|
|
1158
|
-
logo.className = "tw-brand-logo";
|
|
1159
|
-
logo.src = this.config.brand.logo;
|
|
1160
|
-
logo.alt = this.config.brand.name || "";
|
|
1161
|
-
brand.appendChild(logo);
|
|
1162
|
-
}
|
|
1163
|
-
if (this.config.brand.name) {
|
|
1164
|
-
const brandLabel = document.createElement("span");
|
|
1165
|
-
brandLabel.className = "tw-brand-name";
|
|
1166
|
-
brandLabel.textContent = this.config.brand.name;
|
|
1167
|
-
brandLabel.title = this.config.brand.name;
|
|
1168
|
-
brand.appendChild(brandLabel);
|
|
1169
|
-
}
|
|
1170
|
-
header.appendChild(brand);
|
|
1171
|
-
}
|
|
1700
|
+
if (!this.bodyShowsLargeAvatar()) header.appendChild(this.buildAvatar("sm"));
|
|
1701
|
+
const who = document.createElement("div");
|
|
1702
|
+
who.className = "tw-who";
|
|
1172
1703
|
const name = document.createElement("div");
|
|
1173
1704
|
name.className = "tw-header-title";
|
|
1174
|
-
const title = this.
|
|
1705
|
+
const title = this.config.agentName || this.speakerName();
|
|
1175
1706
|
name.textContent = title;
|
|
1176
1707
|
if (title) name.title = title;
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
const collapseBtn = document.createElement("button");
|
|
1191
|
-
collapseBtn.className = "tw-icon-btn";
|
|
1192
|
-
collapseBtn.type = "button";
|
|
1193
|
-
collapseBtn.title = this.config.collapseText;
|
|
1194
|
-
collapseBtn.textContent = "\u2921";
|
|
1195
|
-
collapseBtn.addEventListener("click", () => {
|
|
1196
|
-
this.config = { ...this.config, variant: "compact" };
|
|
1197
|
-
this.render();
|
|
1198
|
-
});
|
|
1199
|
-
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);
|
|
1200
1721
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
closeBtn.title = "Close";
|
|
1206
|
-
closeBtn.textContent = "\u2715";
|
|
1207
|
-
closeBtn.addEventListener("click", () => {
|
|
1208
|
-
if (this.state === "live" || this.state === "connecting") {
|
|
1209
|
-
this.endConversation();
|
|
1210
|
-
}
|
|
1722
|
+
const actions = document.createElement("div");
|
|
1723
|
+
actions.className = "tw-header-actions";
|
|
1724
|
+
actions.appendChild(
|
|
1725
|
+
this.iconButton(ICONS.minimize, "Minimize", () => {
|
|
1211
1726
|
this.open = false;
|
|
1212
1727
|
this.render();
|
|
1213
|
-
})
|
|
1214
|
-
|
|
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
|
+
);
|
|
1215
1738
|
}
|
|
1739
|
+
header.appendChild(actions);
|
|
1216
1740
|
return header;
|
|
1217
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
|
+
}
|
|
1218
1750
|
/** True when a `both` widget is idle/ended with no modality chosen yet. */
|
|
1219
1751
|
isBothPreCall() {
|
|
1220
1752
|
return this.config.mode === "both" && this.activeMode === null && (this.state === "idle" || this.state === "ended");
|
|
@@ -1225,43 +1757,38 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1225
1757
|
return Boolean(this.config.recaptchaSiteKey) && !this.recaptchaSolved;
|
|
1226
1758
|
}
|
|
1227
1759
|
/**
|
|
1228
|
-
* The pre-call gate shown in the panel:
|
|
1760
|
+
* The pre-call gate shown in the panel: prompt, the reCAPTCHA checkbox, and a
|
|
1229
1761
|
* disabled start button. The button enables once the checkbox is solved.
|
|
1230
1762
|
*
|
|
1231
1763
|
* The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
|
|
1232
1764
|
* shadow root (its anchor iframe never finishes initializing), so the actual widget
|
|
1233
1765
|
* is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
|
|
1234
1766
|
* to this slot. It therefore *displays* here inside the panel while its DOM home
|
|
1235
|
-
* stays in the light tree, where reCAPTCHA works.
|
|
1236
|
-
* isolate.local.html (case C).
|
|
1767
|
+
* stays in the light tree, where reCAPTCHA works.
|
|
1237
1768
|
*/
|
|
1238
1769
|
renderRecaptchaGate(body) {
|
|
1239
|
-
body.
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
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);
|
|
1244
1776
|
const slot = document.createElement("slot");
|
|
1245
1777
|
slot.setAttribute("name", "recaptcha");
|
|
1246
1778
|
slot.className = "tw-recaptcha-slot";
|
|
1247
1779
|
body.appendChild(slot);
|
|
1248
|
-
const controls = document.createElement("div");
|
|
1249
|
-
controls.className = "tw-controls";
|
|
1250
1780
|
const startBtn = document.createElement("button");
|
|
1251
1781
|
startBtn.className = "tw-primary-btn";
|
|
1252
1782
|
startBtn.type = "button";
|
|
1253
1783
|
startBtn.textContent = this.config.startCallText;
|
|
1254
1784
|
startBtn.disabled = true;
|
|
1255
|
-
|
|
1256
|
-
body.appendChild(controls);
|
|
1785
|
+
body.appendChild(startBtn);
|
|
1257
1786
|
this.ensureRecaptchaSlot();
|
|
1258
1787
|
}
|
|
1259
1788
|
/**
|
|
1260
1789
|
* Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox
|
|
1261
|
-
* into it.
|
|
1262
|
-
*
|
|
1263
|
-
* <slot> element, but this node (and its iframe) persists in the light DOM untouched,
|
|
1264
|
-
* 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.
|
|
1265
1792
|
*/
|
|
1266
1793
|
ensureRecaptchaSlot() {
|
|
1267
1794
|
const siteKey = this.config.recaptchaSiteKey;
|
|
@@ -1280,8 +1807,6 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1280
1807
|
this.removeRecaptchaSlot();
|
|
1281
1808
|
this.render();
|
|
1282
1809
|
},
|
|
1283
|
-
// A solved checkbox expires after ~2 minutes. Google resets its own widget UI in
|
|
1284
|
-
// place, and the slot is still showing, so the visitor can just re-tick it.
|
|
1285
1810
|
onExpired: () => {
|
|
1286
1811
|
this.recaptchaSolved = false;
|
|
1287
1812
|
}
|
|
@@ -1312,111 +1837,136 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1312
1837
|
this.renderBothEntry(body);
|
|
1313
1838
|
return body;
|
|
1314
1839
|
}
|
|
1315
|
-
if (this.resolvedMode() === "text") {
|
|
1840
|
+
if (this.resolvedMode() === "text" || this.config.mode === "both") {
|
|
1316
1841
|
this.renderTextBody(body);
|
|
1317
1842
|
} else {
|
|
1318
1843
|
this.renderVoiceBody(body);
|
|
1319
1844
|
}
|
|
1320
1845
|
return body;
|
|
1321
1846
|
}
|
|
1322
|
-
/**
|
|
1323
|
-
buildOrb() {
|
|
1324
|
-
const orbWrap = document.createElement("div");
|
|
1325
|
-
orbWrap.className = "tw-orb-wrap";
|
|
1326
|
-
if (this.state === "connecting") orbWrap.classList.add("tw-connecting");
|
|
1327
|
-
if (this.state === "live") orbWrap.classList.add("tw-listening");
|
|
1328
|
-
if (this.state === "live" && this.speaking) orbWrap.classList.add("tw-speaking");
|
|
1329
|
-
const orb = document.createElement("div");
|
|
1330
|
-
orb.className = "tw-orb";
|
|
1331
|
-
if (this.config.avatar) {
|
|
1332
|
-
orb.classList.add("tw-orb-avatar");
|
|
1333
|
-
orb.style.backgroundImage = `url("${this.config.avatar}")`;
|
|
1334
|
-
}
|
|
1335
|
-
orbWrap.appendChild(orb);
|
|
1336
|
-
return orbWrap;
|
|
1337
|
-
}
|
|
1338
|
-
/** 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. */
|
|
1339
1848
|
renderBothEntry(body) {
|
|
1340
|
-
body.
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
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);
|
|
1360
1874
|
}
|
|
1361
|
-
/** Voice
|
|
1875
|
+
/** Voice call: the agent's presence (ring follows their voice), status, controls. */
|
|
1362
1876
|
renderVoiceBody(body) {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
status
|
|
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");
|
|
1367
1887
|
body.appendChild(status);
|
|
1368
1888
|
const timer = document.createElement("div");
|
|
1369
1889
|
timer.className = "tw-timer";
|
|
1370
1890
|
timer.textContent = this.timerText();
|
|
1371
1891
|
body.appendChild(timer);
|
|
1372
1892
|
body.appendChild(this.renderControls());
|
|
1373
|
-
const switchBtn = this.renderSwitchButton();
|
|
1374
|
-
if (switchBtn) body.appendChild(switchBtn);
|
|
1375
1893
|
}
|
|
1376
|
-
/** Text/chat UI: conversation thread + message input.
|
|
1894
|
+
/** Text/chat UI: conversation thread + message input. */
|
|
1377
1895
|
renderTextBody(body) {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
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);
|
|
1384
1906
|
}
|
|
1385
1907
|
body.appendChild(this.renderControls());
|
|
1386
1908
|
return;
|
|
1387
1909
|
}
|
|
1388
|
-
if (this.state === "connecting") {
|
|
1389
|
-
const status = document.createElement("div");
|
|
1390
|
-
status.className = "tw-status";
|
|
1391
|
-
status.textContent = "Connecting\u2026";
|
|
1392
|
-
body.appendChild(status);
|
|
1393
|
-
}
|
|
1394
1910
|
body.appendChild(this.renderTranscript());
|
|
1395
|
-
|
|
1396
|
-
|
|
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;
|
|
1397
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";
|
|
1398
1945
|
const endBtn = document.createElement("button");
|
|
1399
|
-
endBtn.className = "tw-
|
|
1946
|
+
endBtn.className = "tw-link-btn tw-end-chat";
|
|
1400
1947
|
endBtn.type = "button";
|
|
1401
|
-
endBtn.textContent = this.config.endCallText;
|
|
1948
|
+
endBtn.textContent = this.config.mode === "text" ? this.config.endCallText : "End conversation";
|
|
1402
1949
|
endBtn.disabled = this.state === "connecting";
|
|
1403
1950
|
endBtn.addEventListener("click", () => this.endConversation());
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
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;
|
|
1420
1970
|
}
|
|
1421
1971
|
renderControls() {
|
|
1422
1972
|
const controls = document.createElement("div");
|
|
@@ -1425,91 +1975,278 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
1425
1975
|
const startBtn = document.createElement("button");
|
|
1426
1976
|
startBtn.className = "tw-primary-btn";
|
|
1427
1977
|
startBtn.type = "button";
|
|
1428
|
-
|
|
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);
|
|
1429
1983
|
startBtn.addEventListener("click", () => {
|
|
1430
1984
|
void this.beginCall();
|
|
1431
1985
|
});
|
|
1432
1986
|
controls.appendChild(startBtn);
|
|
1433
1987
|
return controls;
|
|
1434
1988
|
}
|
|
1435
|
-
if (this.resolvedMode() === "voice"
|
|
1436
|
-
const micBtn =
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
+
() => {
|
|
1442
2037
|
var _a;
|
|
1443
2038
|
this.micEnabled = !this.micEnabled;
|
|
1444
2039
|
(_a = this.agent) == null ? void 0 : _a.toggleMicrophone(this.micEnabled);
|
|
1445
2040
|
this.render();
|
|
1446
|
-
}
|
|
1447
|
-
|
|
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
|
+
);
|
|
1448
2057
|
}
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
endBtn.textContent = this.config.endCallText;
|
|
1453
|
-
endBtn.disabled = this.state === "connecting";
|
|
1454
|
-
endBtn.addEventListener("click", () => this.endConversation());
|
|
1455
|
-
controls.appendChild(endBtn);
|
|
1456
|
-
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;
|
|
1457
2061
|
}
|
|
1458
2062
|
renderTextInput() {
|
|
1459
|
-
const row = document.createElement("
|
|
1460
|
-
row.className = "tw-
|
|
1461
|
-
const input = document.createElement("
|
|
2063
|
+
const row = document.createElement("form");
|
|
2064
|
+
row.className = "tw-composer";
|
|
2065
|
+
const input = document.createElement("textarea");
|
|
1462
2066
|
input.className = "tw-text-input";
|
|
1463
|
-
input.
|
|
1464
|
-
input.placeholder =
|
|
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
|
+
};
|
|
1465
2081
|
const send = () => {
|
|
1466
2082
|
var _a;
|
|
1467
2083
|
const text = input.value.trim();
|
|
1468
|
-
if (!text) return;
|
|
1469
|
-
|
|
2084
|
+
if (!text || this.state !== "live") return;
|
|
2085
|
+
this.draft = "";
|
|
1470
2086
|
input.value = "";
|
|
2087
|
+
syncState();
|
|
2088
|
+
void ((_a = this.agent) == null ? void 0 : _a.sendTextMessage(text));
|
|
1471
2089
|
};
|
|
2090
|
+
input.addEventListener("input", () => {
|
|
2091
|
+
this.draft = input.value;
|
|
2092
|
+
syncState();
|
|
2093
|
+
});
|
|
1472
2094
|
input.addEventListener("keydown", (e) => {
|
|
1473
|
-
if (e.key === "Enter")
|
|
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();
|
|
1474
2103
|
});
|
|
1475
|
-
const sendBtn = document.createElement("button");
|
|
1476
|
-
sendBtn.className = "tw-send-btn";
|
|
1477
|
-
sendBtn.type = "button";
|
|
1478
|
-
sendBtn.textContent = "Send";
|
|
1479
|
-
sendBtn.addEventListener("click", send);
|
|
1480
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
|
+
}
|
|
1481
2110
|
row.appendChild(sendBtn);
|
|
2111
|
+
requestAnimationFrame(syncState);
|
|
2112
|
+
if (this.state === "live") requestAnimationFrame(() => input.focus({ preventScroll: true }));
|
|
1482
2113
|
return row;
|
|
1483
2114
|
}
|
|
1484
|
-
/**
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
const msg = document.createElement("div");
|
|
1502
|
-
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") {
|
|
1503
2132
|
msg.textContent = t.text;
|
|
1504
|
-
|
|
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);
|
|
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);
|
|
1505
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);
|
|
1506
2169
|
}
|
|
1507
2170
|
requestAnimationFrame(() => {
|
|
1508
2171
|
wrap.scrollTop = wrap.scrollHeight;
|
|
1509
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);
|
|
1510
2204
|
return wrap;
|
|
1511
2205
|
}
|
|
1512
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
|
+
};
|
|
1513
2250
|
|
|
1514
2251
|
// src/widget/register.ts
|
|
1515
2252
|
var TRILLET_WIDGET_TAG = "trillet-widget";
|
|
@@ -1565,6 +2302,16 @@ var TrilletWidget = (props) => {
|
|
|
1565
2302
|
setAttr(el, "expand-text", props.expandText);
|
|
1566
2303
|
setAttr(el, "collapse-text", props.collapseText);
|
|
1567
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);
|
|
1568
2315
|
const vars = (_b = props.variables) != null ? _b : props.dynamicVariables;
|
|
1569
2316
|
setAttr(el, "variables", vars ? JSON.stringify(vars) : void 0);
|
|
1570
2317
|
setAttr(el, "max-call-duration", props.maxCallDuration);
|