@locdo.tech/botiq-chat-sdk 0.4.0 → 0.6.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.
@@ -0,0 +1,1667 @@
1
+ //#region src/core/config.ts
2
+ var e = "https://bot-q-backend.vercel.app", t = {
3
+ colors: {
4
+ primary: "#F97316",
5
+ header: "#F97316",
6
+ userBubble: "#F97316",
7
+ botBubble: "#1A1A1A",
8
+ background: "#000000",
9
+ text: "#FFFFFF",
10
+ inputBackground: "#1A1A1A"
11
+ },
12
+ layout: {
13
+ position: "bottom-right",
14
+ buttonShape: "circle",
15
+ width: 400,
16
+ height: 640
17
+ },
18
+ content: {
19
+ greeting: "",
20
+ suggestionChips: [],
21
+ placeholder: ""
22
+ },
23
+ font: "inter"
24
+ }, n = {
25
+ name: "BotIQ",
26
+ design: t,
27
+ widgetLanguage: "vi"
28
+ }, r = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/, i = new Set(["bottom-right", "bottom-left"]), a = new Set(["circle", "square"]), o = new Set([
29
+ "inter",
30
+ "plus-jakarta",
31
+ "poppins",
32
+ "nunito",
33
+ "dm-sans",
34
+ "raleway",
35
+ "lato",
36
+ "playfair"
37
+ ]), s = new Set([
38
+ "none",
39
+ "fade",
40
+ "slide-up",
41
+ "bounce"
42
+ ]), c = new Set([
43
+ "dots-bounce",
44
+ "dots-pulse",
45
+ "bar"
46
+ ]);
47
+ function l(e) {
48
+ let t = e.colors;
49
+ if (t.inputBackground ||= "#1A1A1A", ![
50
+ t.primary,
51
+ t.header,
52
+ t.userBubble,
53
+ t.botBubble,
54
+ t.background,
55
+ t.text,
56
+ t.inputBackground
57
+ ].every((e) => typeof e == "string" && r.test(e)) || !i.has(e.layout.position) || !a.has(e.layout.buttonShape) || !o.has(e.font)) return !1;
58
+ let { width: n, height: l } = e.layout;
59
+ if (!Number.isFinite(n) || n < 280 || n > 800 || !Number.isFinite(l) || l < 200 || l > 900 || e.layout.fillHeight !== void 0 && typeof e.layout.fillHeight != "boolean") return !1;
60
+ if (e.gradient) {
61
+ let t = e.gradient;
62
+ if (t.type !== "linear" && t.type !== "radial" || !r.test(t.from) || !r.test(t.to) || t.angle !== void 0 && (!Number.isFinite(t.angle) || t.angle < 0 || t.angle > 360)) return !1;
63
+ }
64
+ return !(e.animation && (!s.has(e.animation.bubbleOpen) || !c.has(e.animation.typingIndicator)) || e.customCSS !== void 0 && (typeof e.customCSS != "string" || e.customCSS.length > 8e3));
65
+ }
66
+ var u = 8e3;
67
+ function d(e, t) {
68
+ return fetch(`${t}/widget/meta`, {
69
+ headers: { "X-Api-Key": e },
70
+ referrerPolicy: "no-referrer-when-downgrade",
71
+ signal: AbortSignal.timeout(u)
72
+ });
73
+ }
74
+ async function f(e, r) {
75
+ let i;
76
+ try {
77
+ i = await d(e, r);
78
+ } catch {
79
+ try {
80
+ i = await d(e, r);
81
+ } catch {
82
+ return n;
83
+ }
84
+ }
85
+ if (i.status === 401 || i.status === 403) return null;
86
+ if (!i.ok) return n;
87
+ let a;
88
+ try {
89
+ a = await i.json();
90
+ } catch {
91
+ return n;
92
+ }
93
+ let o = typeof a.name == "string" && a.name.length > 0 ? a.name : n.name, s = a.widgetLanguage === "en" ? "en" : "vi", c = Array.isArray(a.pageActions) ? a.pageActions : void 0, u = typeof a.contactInfo == "string" ? a.contactInfo : void 0, f = a.proactive && typeof a.proactive == "object" ? a.proactive : void 0, p = a.status === "offline" ? "offline" : a.status === "online" ? "online" : void 0;
94
+ return !a.design?.colors || !a.design?.layout || !a.design?.content || !l(a.design) ? {
95
+ name: o,
96
+ design: t,
97
+ widgetLanguage: s,
98
+ ...c ? { pageActions: c } : {},
99
+ ...u ? { contactInfo: u } : {},
100
+ ...f ? { proactive: f } : {},
101
+ ...p ? { status: p } : {}
102
+ } : {
103
+ name: o,
104
+ design: a.design,
105
+ widgetLanguage: s,
106
+ ...c ? { pageActions: c } : {},
107
+ ...u ? { contactInfo: u } : {},
108
+ ...f ? { proactive: f } : {},
109
+ ...p ? { status: p } : {}
110
+ };
111
+ }
112
+ function p(t) {
113
+ return {
114
+ apiKey: t.apiKey,
115
+ apiUrl: e
116
+ };
117
+ }
118
+ //#endregion
119
+ //#region src/core/session.ts
120
+ var m = "botiq:sessionId", h = "botiq:sessionId:", g = "botiq:history:", _ = "botiq:visitorId", v = 10;
121
+ function y() {
122
+ try {
123
+ let e = localStorage.getItem(m);
124
+ localStorage.removeItem(m), e && localStorage.removeItem(g + e);
125
+ } catch {}
126
+ }
127
+ function b(e) {
128
+ try {
129
+ let t = h + e, n = localStorage.getItem(t);
130
+ return n || (n = crypto.randomUUID(), localStorage.setItem(t, n)), n;
131
+ } catch {
132
+ return crypto.randomUUID();
133
+ }
134
+ }
135
+ function x(e, t) {
136
+ try {
137
+ let n = localStorage.getItem(`${g}${e}:${t}`);
138
+ return n ? JSON.parse(n) : [];
139
+ } catch {
140
+ return [];
141
+ }
142
+ }
143
+ function S(e, t, n) {
144
+ try {
145
+ let r = [...x(e, t), ...n].slice(-v);
146
+ localStorage.setItem(`${g}${e}:${t}`, JSON.stringify(r));
147
+ } catch {}
148
+ }
149
+ function C() {
150
+ try {
151
+ let e = localStorage.getItem(_);
152
+ return e || (e = crypto.randomUUID(), localStorage.setItem(_, e)), e;
153
+ } catch {
154
+ return crypto.randomUUID();
155
+ }
156
+ }
157
+ function w() {
158
+ return crypto.randomUUID();
159
+ }
160
+ //#endregion
161
+ //#region src/core/action-registry.ts
162
+ var T = /^[a-z][a-z0-9_]{2,40}$/, E = new Set([
163
+ "low",
164
+ "medium",
165
+ "high"
166
+ ]), D = new class {
167
+ actions = /* @__PURE__ */ new Map();
168
+ declarativeRunner;
169
+ constructor(e) {
170
+ this.declarativeRunner = e;
171
+ }
172
+ validate(e) {
173
+ if (!T.test(e.name)) throw Error(`Invalid action name: "${e.name}"`);
174
+ if (!E.has(e.riskLevel)) throw Error(`Invalid riskLevel: ${e.riskLevel}`);
175
+ if (typeof e.description != "string" || e.description.length < 5) throw Error(`description ≥5 chars required for ${e.name}`);
176
+ }
177
+ seed(e) {
178
+ for (let t of e) try {
179
+ this.validate(t), this.actions.set(t.name, {
180
+ ...t,
181
+ kind: "declarative"
182
+ });
183
+ } catch (e) {
184
+ console.warn("[BotIQ] skipped invalid page action: " + e.message);
185
+ }
186
+ }
187
+ register(e) {
188
+ for (let t of e) {
189
+ if (this.validate(t), typeof t.execute != "function") throw Error(`execute must be a function for ${t.name}`);
190
+ this.actions.set(t.name, {
191
+ ...t,
192
+ kind: "js"
193
+ });
194
+ }
195
+ }
196
+ has(e) {
197
+ return this.actions.has(e);
198
+ }
199
+ get(e) {
200
+ return this.actions.get(e);
201
+ }
202
+ getDefinitions() {
203
+ return Array.from(this.actions.values()).map((e) => ({
204
+ name: e.name,
205
+ description: e.description,
206
+ riskLevel: e.riskLevel,
207
+ params: e.params
208
+ }));
209
+ }
210
+ setDeclarativeRunner(e) {
211
+ this.declarativeRunner = e;
212
+ }
213
+ async execute(e, t) {
214
+ let n = this.actions.get(e);
215
+ if (!n) throw Error(`Action "${e}" not registered`);
216
+ if (n.kind === "js") {
217
+ await n.execute(t);
218
+ return;
219
+ }
220
+ if (!this.declarativeRunner) throw Error("No declarative runner configured");
221
+ await this.declarativeRunner(n, t);
222
+ }
223
+ }();
224
+ //#endregion
225
+ //#region src/core/api.ts
226
+ async function ee(e, t, n) {
227
+ try {
228
+ let r = new URLSearchParams({ visitorId: n }), i = await fetch(`${e}/widget/conversations?${r.toString()}`, {
229
+ method: "GET",
230
+ headers: {
231
+ "X-Api-Key": t,
232
+ "X-Visitor-Id": n
233
+ },
234
+ referrerPolicy: "no-referrer-when-downgrade"
235
+ });
236
+ if (!i.ok) return [];
237
+ let a = await i.json();
238
+ return Array.isArray(a.conversations) ? a.conversations : [];
239
+ } catch {
240
+ return [];
241
+ }
242
+ }
243
+ async function te(e, t, n, r, i, a, o) {
244
+ try {
245
+ let s = D.getDefinitions(), c = await fetch(`${e}/widget/chat`, {
246
+ method: "POST",
247
+ headers: {
248
+ "Content-Type": "application/json",
249
+ "X-Api-Key": t,
250
+ ...o ? { "X-Visitor-Id": o } : {}
251
+ },
252
+ referrerPolicy: "no-referrer-when-downgrade",
253
+ body: JSON.stringify({
254
+ sessionId: n,
255
+ message: r,
256
+ history: i,
257
+ ...s.length > 0 ? { availableActions: s } : {}
258
+ })
259
+ });
260
+ if (!c.ok) return c.status === 401 ? {
261
+ reply: a.errorAuth,
262
+ error: !0
263
+ } : c.status === 403 ? {
264
+ reply: a.errorForbidden,
265
+ error: !0
266
+ } : c.status === 429 ? {
267
+ reply: a.errorQuota,
268
+ error: !0
269
+ } : {
270
+ reply: a.errorGeneric,
271
+ error: !0
272
+ };
273
+ let l = await c.json();
274
+ return {
275
+ reply: l.reply || a.errorMessage,
276
+ pageAction: l.pageAction
277
+ };
278
+ } catch {
279
+ return {
280
+ reply: a.errorMessage,
281
+ error: !0
282
+ };
283
+ }
284
+ }
285
+ var O = {
286
+ messages: [],
287
+ hasMore: !1
288
+ };
289
+ function k(e) {
290
+ if (!e || typeof e != "object") return !1;
291
+ let t = e;
292
+ return typeof t.id == "string" && (t.role === "user" || t.role === "assistant") && typeof t.content == "string";
293
+ }
294
+ async function A(e, t, n, r, i, a) {
295
+ try {
296
+ let o = new URLSearchParams({
297
+ sessionId: n,
298
+ limit: String(i)
299
+ });
300
+ r && o.set("before", r);
301
+ let s = await fetch(`${e}/widget/messages?${o.toString()}`, {
302
+ method: "GET",
303
+ headers: {
304
+ "X-Api-Key": t,
305
+ ...a ? { "X-Visitor-Id": a } : {}
306
+ },
307
+ referrerPolicy: "no-referrer-when-downgrade"
308
+ });
309
+ if (!s.ok) return O;
310
+ let c = await s.json();
311
+ return {
312
+ messages: Array.isArray(c.messages) ? c.messages.filter(k) : [],
313
+ hasMore: c.hasMore === !0,
314
+ escalated: c.escalated === !0
315
+ };
316
+ } catch {
317
+ return O;
318
+ }
319
+ }
320
+ function j(e, t, n, r, i) {
321
+ return A(e, t, n, void 0, r, i);
322
+ }
323
+ function ne(e, t, n, r, i, a) {
324
+ return A(e, t, n, r, i, a);
325
+ }
326
+ //#endregion
327
+ //#region src/core/state.ts
328
+ var M = {
329
+ messages: [],
330
+ isLoading: !1,
331
+ isOpen: !1,
332
+ loadingOlder: !1,
333
+ view: "home",
334
+ unreadCount: 0,
335
+ conversations: [],
336
+ currentSessionId: "",
337
+ escalated: !1
338
+ }, N = /* @__PURE__ */ new Set();
339
+ function P() {
340
+ return M;
341
+ }
342
+ function F(e) {
343
+ Object.assign(M, e);
344
+ let t = {
345
+ ...M,
346
+ messages: [...M.messages],
347
+ conversations: [...M.conversations]
348
+ };
349
+ N.forEach((e) => e(t));
350
+ }
351
+ function re(e) {
352
+ return N.add(e), () => N.delete(e);
353
+ }
354
+ //#endregion
355
+ //#region src/core/styles.ts
356
+ var I = {
357
+ inter: {
358
+ url: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
359
+ family: "'Inter', system-ui, -apple-system, sans-serif"
360
+ },
361
+ "plus-jakarta": {
362
+ url: "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap",
363
+ family: "'Plus Jakarta Sans', system-ui, -apple-system, sans-serif"
364
+ },
365
+ nunito: {
366
+ url: "https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600&display=swap",
367
+ family: "'Nunito', system-ui, -apple-system, sans-serif"
368
+ },
369
+ raleway: {
370
+ url: "https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600&display=swap",
371
+ family: "'Raleway', system-ui, -apple-system, sans-serif"
372
+ },
373
+ playfair: {
374
+ url: "https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600&display=swap",
375
+ family: "'Playfair Display', Georgia, serif"
376
+ }
377
+ };
378
+ function L(e, t) {
379
+ if (!t) return e;
380
+ let n = t.angle ?? 135;
381
+ return t.type === "linear" ? `linear-gradient(${n}deg, ${t.from}, ${t.to})` : `radial-gradient(circle, ${t.from}, ${t.to})`;
382
+ }
383
+ function R(e) {
384
+ return e.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\\[0-9a-fA-F]{1,6}\s?/g, "x").replace(/@import\b[^;]*;?/gi, "").replace(/url\s*\(\s*["']?\s*(?!data:)[^)]*["']?\s*\)/gi, "url(\"\")").replace(/expression\s*\(/gi, "expression_(").replace(/javascript\s*:/gi, "blocked:").replace(/-moz-binding\s*:/gi, "").replace(/\bbehavior\s*:/gi, "");
385
+ }
386
+ function ie(e) {
387
+ let t = e?.bubbleOpen ?? "none", n = e?.typingIndicator ?? "dots-bounce";
388
+ return [t === "fade" ? "@keyframes biq-open-fade { from { opacity: 0; } to { opacity: 1; } }\n.chat-window.open { animation: biq-open-fade .22s ease forwards; }" : t === "slide-up" ? "@keyframes biq-open-slide { from { opacity: 0; transform: scale(1) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }\n.chat-window.open { animation: biq-open-slide .25s cubic-bezier(.22,1,.36,1) forwards; }" : t === "bounce" ? "@keyframes biq-open-bounce { 0% { opacity: 0; transform: scale(.85) translateY(8px); } 60% { transform: scale(1.03) translateY(-3px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }\n.chat-window.open { animation: biq-open-bounce .35s cubic-bezier(.34,1.56,.64,1) forwards; }" : "", n === "dots-pulse" ? "@keyframes biq-pulse { 0%, 100% { opacity: 0.3; transform: scale(1); } 50% { opacity: 1; transform: scale(1.3); } }\n.typing span { animation: biq-pulse 1.2s infinite ease-in-out; }" : n === "bar" ? ".typing { gap: 3px; align-items: flex-end; }\n.typing span { width: 3px; height: 14px; border-radius: 2px; animation: biq-bar 1s infinite ease-in-out; }\n.typing span:nth-child(1) { animation-delay: 0s; }\n.typing span:nth-child(2) { animation-delay: .15s; height: 20px; }\n.typing span:nth-child(3) { animation-delay: .3s; }\n@keyframes biq-bar { 0%, 100% { transform: scaleY(.4); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }" : ""].filter(Boolean).join("\n");
389
+ }
390
+ var ae = "\n.botiq-confirm-overlay { position:absolute; inset:0; background:rgba(0,0,0,.7);\n display:flex; align-items:center; justify-content:center; z-index:999; }\n.botiq-confirm-dialog { background:#1A1A1A; border:1px solid #2D2D2D; border-radius:12px;\n padding:16px; max-width:320px; color:#fff; font-size:14px; }\n.botiq-confirm-header { font-weight:600; margin-bottom:8px; }\n.botiq-confirm-reason { color:#9CA3AF; margin-bottom:8px; }\n.botiq-confirm-params { background:#0a0a0a; padding:8px; border-radius:6px; font-size:12px;\n max-height:120px; overflow:auto; white-space:pre-wrap; }\n.botiq-confirm-actions { display:flex; gap:8px; margin-top:12px; }\n.botiq-confirm-yes { flex:1; padding:8px 12px; border-radius:6px; border:none;\n background:#F97316; color:#fff; cursor:pointer; }\n.botiq-confirm-yes[data-risk=\"high\"] { background:#DC2626; }\n.botiq-confirm-no { flex:1; padding:8px 12px; border-radius:6px; background:transparent;\n border:1px solid #2D2D2D; color:#fff; cursor:pointer; }\n.botiq-confirm-countdown { margin-top:8px; font-size:12px; color:#9CA3AF; }\n";
391
+ function oe(e) {
392
+ let { colors: t, layout: n, font: r, gradient: i, animation: a, customCSS: o, whiteLabel: s } = e, c = I[r] ?? I.inter, l = n.buttonShape === "square" ? "14px" : "50%", u = n.position === "bottom-left" ? "right: auto; left: 24px;" : "right: 24px;", d = n.position === "bottom-left" ? "bottom left" : "bottom right", f = n.position === "bottom-left" ? "right: auto; left: 0;" : "right: 0;", p = n.fillHeight ? `min(${n.height}px, calc(100dvh - 48px))` : `${n.height}px`, m = L(t.primary, i), h = L(t.header, i), g = L(t.userBubble, i), _ = s ? ".botiq-badge { display: none !important; }" : "";
393
+ return `
394
+ @import url('${c.url}');
395
+
396
+ :host {
397
+ position: fixed;
398
+ bottom: 24px;
399
+ ${u}
400
+ z-index: 2147483647;
401
+ display: block;
402
+ font-family: ${c.family};
403
+ --color-primary: ${t.primary};
404
+ --color-header: ${t.header};
405
+ --color-user: ${t.userBubble};
406
+ --color-bot: ${t.botBubble};
407
+ --color-bg: ${t.background};
408
+ --color-text: ${t.text};
409
+ --color-input-bg: ${t.inputBackground};
410
+ --gray-50: #1A1A1A;
411
+ --gray-100: #222222;
412
+ --gray-200: #2D2D2D;
413
+ --gray-400: #9CA3AF;
414
+ --shadow-sm: 0 2px 8px rgba(0,0,0,.4);
415
+ --shadow-md: 0 8px 32px rgba(0,0,0,.5);
416
+ --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
417
+ --radius-bubble: ${l};
418
+ --radius-msg: 18px;
419
+ --chat-w: ${n.width}px;
420
+ --chat-h: ${p};
421
+ }
422
+
423
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
424
+
425
+ /* ── Bubble ─────────────────────────────── */
426
+ .bubble {
427
+ width: 56px;
428
+ height: 56px;
429
+ border-radius: var(--radius-bubble);
430
+ background: ${m};
431
+ border: none;
432
+ cursor: pointer;
433
+ display: flex;
434
+ align-items: center;
435
+ justify-content: center;
436
+ box-shadow: var(--shadow-md);
437
+ transition: transform .2s ease, box-shadow .2s ease;
438
+ outline: none;
439
+ position: relative;
440
+ }
441
+
442
+ .bubble:hover { transform: scale(1.08); box-shadow: var(--shadow-lg); }
443
+ .bubble:active { transform: scale(0.96); }
444
+
445
+ .bubble svg { width: 26px; height: 26px; fill: #fff; transition: opacity .15s; }
446
+ .bubble .icon-chat { opacity: 1; }
447
+ .bubble .icon-close { opacity: 0; position: absolute; }
448
+ .bubble.open .icon-chat { opacity: 0; }
449
+ .bubble.open .icon-close { opacity: 1; }
450
+
451
+ .unread-badge {
452
+ position: absolute;
453
+ top: -2px;
454
+ right: -2px;
455
+ min-width: 18px;
456
+ height: 18px;
457
+ padding: 0 5px;
458
+ border-radius: 9px;
459
+ background: #EF4444;
460
+ color: #fff;
461
+ font-size: 11px;
462
+ font-weight: 600;
463
+ display: flex;
464
+ align-items: center;
465
+ justify-content: center;
466
+ pointer-events: none;
467
+ }
468
+
469
+ /* ── Chat Window ────────────────────────── */
470
+ .chat-window {
471
+ position: absolute;
472
+ bottom: 72px;
473
+ ${f}
474
+ width: var(--chat-w);
475
+ height: var(--chat-h);
476
+ background: var(--color-bg);
477
+ border-radius: 20px;
478
+ box-shadow: var(--shadow-lg);
479
+ display: flex;
480
+ flex-direction: column;
481
+ overflow: hidden;
482
+ transform-origin: ${d};
483
+ transform: scale(.94) translateY(8px);
484
+ opacity: 0;
485
+ pointer-events: none;
486
+ transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
487
+ }
488
+
489
+ .chat-window.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }
490
+
491
+ /* ── Header ─────────────────────────────── */
492
+ .chat-header {
493
+ background: ${h};
494
+ padding: 16px 16px 14px;
495
+ display: flex;
496
+ align-items: center;
497
+ gap: 10px;
498
+ flex-shrink: 0;
499
+ }
500
+
501
+ .avatar {
502
+ width: 36px;
503
+ height: 36px;
504
+ border-radius: 50%;
505
+ background: rgba(255,255,255,.2);
506
+ display: flex;
507
+ align-items: center;
508
+ justify-content: center;
509
+ flex-shrink: 0;
510
+ overflow: hidden;
511
+ }
512
+
513
+ .avatar svg { width: 20px; height: 20px; fill: #fff; }
514
+
515
+ .header-text { flex: 1; min-width: 0; }
516
+
517
+ .bot-name {
518
+ color: #fff;
519
+ font-weight: 600;
520
+ font-size: 15px;
521
+ line-height: 1.2;
522
+ display: block;
523
+ white-space: nowrap;
524
+ overflow: hidden;
525
+ text-overflow: ellipsis;
526
+ }
527
+
528
+ .bot-status { color: rgba(255,255,255,.75); font-size: 12px; display: block; margin-top: 1px; }
529
+
530
+ .close-btn {
531
+ width: 30px;
532
+ height: 30px;
533
+ border-radius: 50%;
534
+ background: rgba(255,255,255,.15);
535
+ border: none;
536
+ cursor: pointer;
537
+ color: #fff;
538
+ font-size: 18px;
539
+ display: flex;
540
+ align-items: center;
541
+ justify-content: center;
542
+ flex-shrink: 0;
543
+ transition: background .15s;
544
+ }
545
+ .close-btn:hover { background: rgba(255,255,255,.25); }
546
+
547
+ /* ── Chat body + panels ─────────────────── */
548
+ .chat-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
549
+
550
+ .panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
551
+ .panel.active { display: flex; }
552
+
553
+ /* ── Bottom nav ─────────────────────────── */
554
+ .bottom-nav {
555
+ display: flex;
556
+ border-top: 1px solid var(--gray-100);
557
+ flex-shrink: 0;
558
+ background: var(--color-bg);
559
+ }
560
+
561
+ .nav-btn {
562
+ flex: 1;
563
+ background: transparent;
564
+ border: none;
565
+ color: var(--gray-400);
566
+ font: inherit;
567
+ font-size: 12px;
568
+ padding: 10px;
569
+ cursor: pointer;
570
+ transition: color .15s;
571
+ }
572
+
573
+ .nav-btn:hover { color: var(--color-text); }
574
+ .nav-btn.active { color: var(--color-primary); }
575
+
576
+ /* ── Messages list panel ────────────────── */
577
+ .msg-list { flex: 1; overflow-y: auto; }
578
+
579
+ .msg-list-item {
580
+ display: grid;
581
+ width: 100%;
582
+ text-align: left;
583
+ gap: 2px;
584
+ padding: 12px 16px;
585
+ background: transparent;
586
+ border: none;
587
+ border-bottom: 1px solid var(--gray-100);
588
+ cursor: pointer;
589
+ font: inherit;
590
+ }
591
+
592
+ .msg-list-item:hover { background: var(--gray-50); }
593
+
594
+ .msg-list-title {
595
+ color: var(--color-text);
596
+ font-weight: 600;
597
+ font-size: 14px;
598
+ }
599
+
600
+ .msg-list-preview {
601
+ color: var(--gray-400);
602
+ font-size: 12px;
603
+ white-space: nowrap;
604
+ overflow: hidden;
605
+ text-overflow: ellipsis;
606
+ }
607
+
608
+ .msg-list-time { color: var(--gray-400); font-size: 10px; }
609
+
610
+ .msg-list-badge { color: #F97316; font-size: 10px; }
611
+
612
+ .msg-list-empty {
613
+ padding: 24px;
614
+ text-align: center;
615
+ color: var(--gray-400);
616
+ font-size: 13px;
617
+ }
618
+
619
+ .msg-list-new {
620
+ margin: 10px 16px;
621
+ padding: 10px;
622
+ border-radius: 10px;
623
+ border: 1.5px solid var(--color-primary);
624
+ background: transparent;
625
+ color: var(--color-primary);
626
+ cursor: pointer;
627
+ font: inherit;
628
+ width: calc(100% - 32px);
629
+ }
630
+
631
+ .msg-list-new:hover { background: var(--color-primary); color: #fff; }
632
+
633
+ /* ── Home panel ─────────────────────────── */
634
+ .home-greeting {
635
+ font-size: 20px;
636
+ font-weight: 600;
637
+ color: var(--color-text);
638
+ padding: 24px 18px 8px;
639
+ }
640
+
641
+ .home-start {
642
+ margin: 8px 18px;
643
+ padding: 14px;
644
+ border-radius: 12px;
645
+ border: 1px solid var(--gray-200);
646
+ background: var(--gray-50);
647
+ color: var(--color-text);
648
+ text-align: left;
649
+ cursor: pointer;
650
+ font: inherit;
651
+ font-size: 14px;
652
+ transition: background .15s, border-color .15s;
653
+ }
654
+
655
+ .home-start:hover { background: var(--gray-100); border-color: var(--color-primary); }
656
+
657
+ .home-status { margin: 8px 18px; font-size: 12px; }
658
+ .home-status--online { color: #16A34A; }
659
+ .home-status--offline { color: var(--gray-400); }
660
+
661
+ /* ── Messages ───────────────────────────── */
662
+ .messages {
663
+ flex: 1;
664
+ overflow-y: auto;
665
+ padding: 16px 14px;
666
+ display: flex;
667
+ flex-direction: column;
668
+ gap: 10px;
669
+ scroll-behavior: smooth;
670
+ }
671
+
672
+ .messages::-webkit-scrollbar { width: 4px; }
673
+ .messages::-webkit-scrollbar-track { background: transparent; }
674
+ .messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }
675
+
676
+ .message { display: flex; flex-direction: column; max-width: 82%; }
677
+ .message.user { align-self: flex-end; align-items: flex-end; }
678
+ .message.assistant { align-self: flex-start; align-items: flex-start; max-width: 92%; }
679
+
680
+ .message-bubble {
681
+ padding: 10px 14px;
682
+ border-radius: var(--radius-msg);
683
+ font-size: 14px;
684
+ line-height: 1.5;
685
+ white-space: normal;
686
+ word-break: break-word;
687
+ overflow-x: auto;
688
+ }
689
+
690
+ /* ── Markdown inline elements ───────────────────────── */
691
+ .message-bubble strong { font-weight: 600; }
692
+ .message-bubble em { font-style: italic; }
693
+ .message-bubble a { color: var(--color-primary); text-decoration: underline; word-break: break-all; }
694
+ .message-bubble code {
695
+ font-family: monospace;
696
+ font-size: 12px;
697
+ padding: 1px 5px;
698
+ border-radius: 4px;
699
+ background: rgba(255,255,255,.1);
700
+ white-space: pre-wrap;
701
+ }
702
+ .message-bubble del { text-decoration: line-through; opacity: .7; }
703
+
704
+ /* ── Markdown headings ───────────────────────────────── */
705
+ /* Kept modest — the chat bubble is small, so headings are only slightly
706
+ larger than body text, never document-sized. */
707
+ .message-bubble h1,
708
+ .message-bubble h2,
709
+ .message-bubble h3,
710
+ .message-bubble h4,
711
+ .message-bubble h5,
712
+ .message-bubble h6 {
713
+ margin: 8px 0 4px;
714
+ font-weight: 600;
715
+ line-height: 1.3;
716
+ color: #fff;
717
+ }
718
+ .message-bubble h1 { font-size: 16px; }
719
+ .message-bubble h2 { font-size: 15px; }
720
+ .message-bubble h3 { font-size: 14px; }
721
+ .message-bubble h4,
722
+ .message-bubble h5,
723
+ .message-bubble h6 { font-size: 13px; }
724
+ .message-bubble :first-child { margin-top: 0; }
725
+
726
+ /* ── Markdown horizontal rule ────────────────────────── */
727
+ .message-bubble hr {
728
+ border: 0;
729
+ height: 1px;
730
+ background: rgba(255,255,255,.15);
731
+ margin: 8px 0;
732
+ }
733
+
734
+ /* ── Markdown tables ─────────────────────────────────── */
735
+ .message-bubble table {
736
+ border-collapse: collapse;
737
+ min-width: 100%;
738
+ font-size: 12.5px;
739
+ display: block;
740
+ overflow-x: auto;
741
+ margin: 4px 0;
742
+ }
743
+ .message-bubble th,
744
+ .message-bubble td {
745
+ border: 1px solid rgba(255,255,255,.15);
746
+ padding: 5px 10px;
747
+ text-align: left;
748
+ }
749
+ .message-bubble th { background: rgba(255,255,255,.08); font-weight: 600; white-space: nowrap; }
750
+ .message-bubble td { white-space: normal; }
751
+ .message-bubble tr:nth-child(even) td { background: rgba(255,255,255,.04); }
752
+
753
+ /* ── Markdown lists ──────────────────────────────────── */
754
+ .message-bubble ul,
755
+ .message-bubble ol { padding-left: 18px; margin: 2px 0; }
756
+ .message-bubble li { margin: 2px 0; }
757
+
758
+ .message.user .message-bubble {
759
+ background: ${g};
760
+ color: #fff;
761
+ border-bottom-right-radius: 4px;
762
+ white-space: pre-wrap;
763
+ }
764
+
765
+ .message.assistant .message-bubble {
766
+ background: var(--color-bot);
767
+ color: var(--color-text);
768
+ border-bottom-left-radius: 4px;
769
+ }
770
+
771
+ /* ── Message Metadata + Day Separators ──── */
772
+ .msg-meta {
773
+ font-size: 10px;
774
+ color: var(--gray-400);
775
+ margin-top: 3px;
776
+ padding: 0 2px;
777
+ }
778
+ .day-sep {
779
+ display: flex;
780
+ align-items: center;
781
+ justify-content: center;
782
+ margin: 6px 0 2px;
783
+ }
784
+ .day-sep span {
785
+ font-size: 10px;
786
+ color: var(--gray-400);
787
+ background: var(--gray-50);
788
+ padding: 2px 10px;
789
+ border-radius: 10px;
790
+ }
791
+
792
+ /* ── Error Bubble + Retry Button ────────── */
793
+ .message.error .message-bubble { border: 1px solid #DC2626; }
794
+ .retry-btn {
795
+ margin-top: 4px;
796
+ align-self: flex-start;
797
+ font-size: 12px;
798
+ font-family: inherit;
799
+ color: var(--color-primary);
800
+ background: transparent;
801
+ border: 1px solid var(--color-primary);
802
+ border-radius: 12px;
803
+ padding: 3px 10px;
804
+ cursor: pointer;
805
+ }
806
+ .retry-btn:hover { background: var(--color-primary); color: #fff; }
807
+ .msg-contact { font-size: 11px; color: var(--gray-400); margin-top: 3px; }
808
+
809
+ /* ── Typing Indicator ───────────────────── */
810
+ .typing {
811
+ display: flex;
812
+ align-items: center;
813
+ gap: 4px;
814
+ padding: 12px 14px;
815
+ background: var(--color-bot);
816
+ border-radius: var(--radius-msg);
817
+ border-bottom-left-radius: 4px;
818
+ align-self: flex-start;
819
+ width: fit-content;
820
+ }
821
+
822
+ .typing span {
823
+ width: 7px;
824
+ height: 7px;
825
+ border-radius: 50%;
826
+ background: var(--color-primary);
827
+ opacity: 0.5;
828
+ animation: bounce 1.2s infinite ease-in-out;
829
+ }
830
+
831
+ .typing span:nth-child(2) { animation-delay: .2s; }
832
+ .typing span:nth-child(3) { animation-delay: .4s; }
833
+
834
+ @keyframes bounce {
835
+ 0%, 60%, 100% { transform: translateY(0); }
836
+ 30% { transform: translateY(-6px); }
837
+ }
838
+
839
+ /* ── Empty / Greeting State ─────────────── */
840
+ .empty-state {
841
+ flex: 1;
842
+ display: flex;
843
+ flex-direction: column;
844
+ align-items: center;
845
+ justify-content: center;
846
+ gap: 8px;
847
+ color: var(--gray-400);
848
+ font-size: 13px;
849
+ text-align: center;
850
+ padding: 24px;
851
+ }
852
+
853
+ .empty-state svg { width: 40px; height: 40px; fill: var(--gray-200); margin-bottom: 4px; }
854
+ .empty-state .greeting { color: var(--color-text); font-size: 13px; opacity: 0.7; }
855
+
856
+ /* ── Suggestion Chips ───────────────────── */
857
+ .chips {
858
+ display: flex;
859
+ flex-wrap: wrap;
860
+ gap: 6px;
861
+ justify-content: center;
862
+ margin-top: 4px;
863
+ }
864
+
865
+ .chip {
866
+ padding: 5px 12px;
867
+ border-radius: 16px;
868
+ border: 1.5px solid var(--color-primary);
869
+ color: var(--color-primary);
870
+ background: transparent;
871
+ font-size: 12px;
872
+ font-family: inherit;
873
+ cursor: pointer;
874
+ transition: background .15s, color .15s;
875
+ }
876
+
877
+ .chip:hover {
878
+ background: var(--color-primary);
879
+ color: #fff;
880
+ }
881
+
882
+ /* ── Handoff Banner ─────────────────────── */
883
+ .handoff-banner {
884
+ margin: 6px 14px;
885
+ padding: 6px 10px;
886
+ border-radius: 8px;
887
+ background: rgba(249,115,22,.12);
888
+ color: var(--color-primary);
889
+ font-size: 12px;
890
+ text-align: center;
891
+ }
892
+
893
+ /* ── Footer / Input ─────────────────────── */
894
+ .chat-footer {
895
+ border-top: 1px solid var(--gray-100);
896
+ padding: 10px 12px;
897
+ background: var(--color-bg);
898
+ flex-shrink: 0;
899
+ }
900
+
901
+ .input-row { display: flex; align-items: flex-end; gap: 8px; }
902
+
903
+ /* Subtle attribution — half-opacity, hover lifts to full. Doesn't steal focus
904
+ from tenant branding but reminds the customer this is powered by BotIQ. */
905
+ .botiq-badge {
906
+ display: block;
907
+ text-align: center;
908
+ font-size: 10px;
909
+ font-weight: 400;
910
+ color: var(--color-text);
911
+ opacity: 0.4;
912
+ text-decoration: none;
913
+ margin-top: 6px;
914
+ letter-spacing: 0.02em;
915
+ transition: opacity .15s;
916
+ }
917
+ .botiq-badge:hover { opacity: 0.85; }
918
+ .botiq-badge-name { font-weight: 600; color: var(--color-primary); }
919
+
920
+ .input {
921
+ flex: 1;
922
+ min-height: 38px;
923
+ max-height: 100px;
924
+ border: 1.5px solid var(--gray-200);
925
+ border-radius: 12px;
926
+ padding: 9px 12px;
927
+ font-family: inherit;
928
+ font-size: 14px;
929
+ color: var(--color-text);
930
+ resize: none;
931
+ outline: none;
932
+ background: var(--color-input-bg);
933
+ line-height: 1.4;
934
+ overflow-y: auto;
935
+ transition: border-color .15s;
936
+ }
937
+
938
+ .input:focus { border-color: var(--color-primary); background: var(--color-input-bg); }
939
+ .input::placeholder { color: var(--gray-400); }
940
+
941
+ .send-btn {
942
+ width: 38px;
943
+ height: 38px;
944
+ border-radius: 10px;
945
+ background: ${m};
946
+ border: none;
947
+ cursor: pointer;
948
+ display: flex;
949
+ align-items: center;
950
+ justify-content: center;
951
+ flex-shrink: 0;
952
+ transition: filter .15s, transform .1s;
953
+ }
954
+
955
+ .send-btn:hover { filter: brightness(0.88); }
956
+ .send-btn:active { transform: scale(0.94); }
957
+ .send-btn:disabled { background: var(--gray-200); cursor: not-allowed; filter: none; }
958
+ .send-btn svg { width: 18px; height: 18px; fill: #fff; }
959
+
960
+ .emoji-btn {
961
+ width: 34px; height: 38px;
962
+ background: transparent; border: none; cursor: pointer;
963
+ font-size: 18px; line-height: 1; flex-shrink: 0;
964
+ }
965
+ .emoji-panel {
966
+ display: grid;
967
+ grid-template-columns: repeat(8, 1fr);
968
+ gap: 2px;
969
+ margin-top: 8px;
970
+ max-height: 140px;
971
+ overflow-y: auto;
972
+ }
973
+ .emoji-panel[hidden] { display: none; }
974
+ .emoji-item {
975
+ background: transparent; border: none; cursor: pointer;
976
+ font-size: 18px; padding: 4px; border-radius: 6px;
977
+ }
978
+ .emoji-item:hover { background: var(--gray-100); }
979
+
980
+ ${_}
981
+ ${ie(a)}
982
+ ${o ? R(o) : ""}
983
+ ${ae}
984
+ @media (max-width: 480px) {
985
+ :host { bottom: 0; right: 0; left: 0; }
986
+ .chat-window {
987
+ width: 100vw;
988
+ height: 100dvh;
989
+ bottom: 0;
990
+ right: 0;
991
+ left: 0;
992
+ border-radius: 0;
993
+ }
994
+ .bubble { position: fixed; bottom: 16px; right: 16px; }
995
+ }
996
+ `;
997
+ }
998
+ //#endregion
999
+ //#region src/core/timeago.ts
1000
+ function z(e) {
1001
+ return String(e).padStart(2, "0");
1002
+ }
1003
+ function B(e, t, n) {
1004
+ let r = Math.max(0, Math.floor((t - e) / 1e3));
1005
+ if (r < 60) return n === "vi" ? "vừa xong" : "just now";
1006
+ let i = Math.floor(r / 60);
1007
+ if (i < 60) return n === "vi" ? `${i} phút` : `${i} min`;
1008
+ let a = new Date(e);
1009
+ return `${z(a.getHours())}:${z(a.getMinutes())}`;
1010
+ }
1011
+ function se(e, t, n) {
1012
+ let r = (e) => {
1013
+ let t = new Date(e);
1014
+ return new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime();
1015
+ }, i = Math.round((r(t) - r(e)) / 864e5);
1016
+ if (i <= 0) return n === "vi" ? "Hôm nay" : "Today";
1017
+ if (i === 1) return n === "vi" ? "Hôm qua" : "Yesterday";
1018
+ let a = new Date(e);
1019
+ return `${z(a.getDate())}/${z(a.getMonth() + 1)}/${a.getFullYear()}`;
1020
+ }
1021
+ //#endregion
1022
+ //#region src/core/views.ts
1023
+ function V(e) {
1024
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1025
+ }
1026
+ function ce(e, t, n) {
1027
+ let r = `<button class="msg-list-new" type="button">+ ${V(t.newConversation)}</button>`;
1028
+ return e.length === 0 ? `<div class="msg-list-empty">${V(t.noConversations)}</div>${r}` : `<div class="msg-list">${e.map((e) => {
1029
+ let r = e.lastMessageAt ? Date.parse(e.lastMessageAt) : n, i = Number.isFinite(r) ? B(r, n, "vi") : "", a = e.escalated ? `<span class="msg-list-badge">${V(t.waitingForHuman)}</span>` : "";
1030
+ return `<button class="msg-list-item" type="button" data-session="${V(e.sessionId)}">
1031
+ <span class="msg-list-title">${V(e.title)}</span>
1032
+ <span class="msg-list-preview">${V(e.preview)}</span>
1033
+ <span class="msg-list-time">${V(i)}</span>${a}
1034
+ </button>`;
1035
+ }).join("")}</div>${r}`;
1036
+ }
1037
+ function le(e, t) {
1038
+ let n = e.status !== "offline", r = n ? t.statusOnline : t.statusPaused;
1039
+ return `
1040
+ <div class="home-greeting">${V(e.design.content.greeting || t.homeGreeting)}</div>
1041
+ <button class="home-start" type="button">${V(t.startConversation)} ›</button>
1042
+ <div class="home-status home-status--${n ? "online" : "offline"}">● ${V(r)}</div>
1043
+ `;
1044
+ }
1045
+ //#endregion
1046
+ //#region src/core/assets.ts
1047
+ var ue = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABL8SURBVHhe7ZsJjJzlecchbZo2aRPwScFAfM29s3N9M9/cO7O7c+zOzr0ze8ze3tN7+1yvD8Be29iYmEIrlaIaRIIIDW1URRE9BFFpAlXLYZNKxFLVVL1Q0yZSgCJhw7963u/7Zr95dyCtuuuDzCP99V0z7/c8v/d5nvedlX3LLTWrWc1qVrOa1axmNatZzWpWs5rV7Jrbc8899/nz588bz5w5lz219ODCyROnHz3xwNLTS8dPPk868cDSN5aOn3rs5ImTB8+ePps7f/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9STwo9fUnP3NCrzU8zvt/I9itRn3ddylIJUAJ3HImLkOtzEDKrorPyuAEm5uJzq1mGSBdc1lbCUudmeospO2SCJPeRH/z+xXe+RvCTJtNXzTqzS+VwdQ7YakXGByS+vyTZCPJwGgfR6Jz5Zqelz/7CRm8QgSS7fdM3zOZTF/k/b6hTKfTfcmgNfwFBUpOKzCUUlRfVxOVqgKs3P9keMp5eawq4JTv2NUALQIMWtMLuttuW/t/+7IaptPpPq/XGp60mO3MeZtZgvZ/lQKcla5VhKXOUX7GgFMmyuXPxGApkyFBtJht0O3Q/KH/Ri3bTzOdRjdXZ6j7gAUqZ94vEkEiWErGKQCV7FsBUMlai9weWHaK7JlJX/eBUWOc4f26qUy3XWfVa/Qv1tfZpIAVCHUSLHVWKQAJlnrxUJe+GiAPXylrS70NBo3hxe33bL85/6trNTNoDf0GrfHt+jorrHJJW2RgCkT1Od/v1M9XlLJZKlmL2QqdVndZp9EM8e//TNgdd9zxG5odmnG91vBGnbEe1noHKz+bauHgAarPy6DZfalcLfUOmAxm6HWGN3Ua3fjmzZtv7FV2lexWzbZtMcNO3RN6reEfDHoT6owWWM0SUALG9pO0kqt+kRC8+jo76kxWGPRm2hD/k3aH5sLWe7a2XLe/qFxv27Jlyxd23HWvc+s9Wye0O7SP63fq/1KzQ3tJu1P3j3qt8V91Wv2/aXZqf6zdqb2k1ehf0mzXXNh277aZrVu2em+7WbYl18MIrOYrX/nNrV/+8m/deeedv84/r1nNalazmtWsZjWrWc1qVrNfXvsfj+EYlqVWv8UAAAAASUVORK5CYII=";
1048
+ //#endregion
1049
+ //#region src/core/history-pager.ts
1050
+ function H() {
1051
+ return {
1052
+ oldestCursor: null,
1053
+ hasMore: !1,
1054
+ cursorReady: !1
1055
+ };
1056
+ }
1057
+ function U(e) {
1058
+ return {
1059
+ oldestCursor: e.messages[0]?.id ?? null,
1060
+ hasMore: e.hasMore,
1061
+ cursorReady: e.messages.length > 0
1062
+ };
1063
+ }
1064
+ function de(e, t) {
1065
+ return {
1066
+ oldestCursor: t.messages[0]?.id ?? e.oldestCursor,
1067
+ hasMore: t.hasMore,
1068
+ cursorReady: e.cursorReady
1069
+ };
1070
+ }
1071
+ function fe(e, t) {
1072
+ return e.cursorReady && e.hasMore && !t && e.oldestCursor !== null;
1073
+ }
1074
+ function pe(e, t, n) {
1075
+ return e + (n - t);
1076
+ }
1077
+ //#endregion
1078
+ //#region src/core/confirm-dialog.ts
1079
+ function W(e) {
1080
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
1081
+ }
1082
+ function me(e, t) {
1083
+ let n = t.labels?.confirm ?? "Đồng ý", r = t.labels?.cancel ?? "Huỷ", i = t.labels?.countdownPrefix ?? "Tự động xác nhận sau ", a = t.labels?.countdownSuffix ?? "s…";
1084
+ return new Promise((o) => {
1085
+ let s = document.createElement("div");
1086
+ s.className = "botiq-confirm-overlay", s.innerHTML = `
1087
+ <div class="botiq-confirm-dialog" role="dialog" aria-modal="true">
1088
+ <div class="botiq-confirm-header">${W(t.title)}</div>
1089
+ <div class="botiq-confirm-body">
1090
+ <div class="botiq-confirm-reason">${W(t.reason)}</div>
1091
+ <pre class="botiq-confirm-params">${W(t.paramsDisplay)}</pre>
1092
+ </div>
1093
+ <div class="botiq-confirm-actions">
1094
+ <button class="botiq-confirm-yes" data-risk="${t.riskLevel}" type="button">${W(n)}</button>
1095
+ <button class="botiq-confirm-no" type="button">${W(r)}</button>
1096
+ </div>
1097
+ ${t.autoConfirmAfterSec ? `<div class="botiq-confirm-countdown">${W(i)}<span class="botiq-confirm-secs">${t.autoConfirmAfterSec}</span>${W(a)}</div>` : ""}
1098
+ </div>`, e.appendChild(s);
1099
+ let c = !1, l = null, u = (t) => {
1100
+ c || (c = !0, l && clearInterval(l), e.removeChild(s), o(t));
1101
+ };
1102
+ if (s.querySelector(".botiq-confirm-yes").addEventListener("click", () => u(!0)), s.querySelector(".botiq-confirm-no").addEventListener("click", () => u(!1)), t.autoConfirmAfterSec && t.autoConfirmAfterSec > 0) {
1103
+ let e = t.autoConfirmAfterSec, n = s.querySelector(".botiq-confirm-secs");
1104
+ l = setInterval(() => {
1105
+ --e, n && (n.textContent = String(e)), e <= 0 && u(!0);
1106
+ }, 1e3);
1107
+ }
1108
+ });
1109
+ }
1110
+ //#endregion
1111
+ //#region src/core/emoji.ts
1112
+ function he(e, t) {
1113
+ let n = e.selectionStart ?? e.value.length, r = e.selectionEnd ?? e.value.length;
1114
+ e.value = e.value.slice(0, n) + t + e.value.slice(r), e.selectionStart = e.selectionEnd = n + t.length, e.dispatchEvent(new Event("input", { bubbles: !0 }));
1115
+ }
1116
+ var G = null;
1117
+ async function ge() {
1118
+ return G || (G = (await import("./emoji-data-DWiYsBZI.js")).EMOJIS, G);
1119
+ }
1120
+ function _e(e) {
1121
+ let t = document.createElement("button");
1122
+ t.type = "button", t.className = "emoji-btn", t.setAttribute("aria-label", "Emoji"), t.textContent = "🙂";
1123
+ let n = document.createElement("div");
1124
+ n.className = "emoji-panel", n.hidden = !0;
1125
+ let r = !1;
1126
+ return t.addEventListener("click", async () => {
1127
+ if (!r) {
1128
+ let t = await ge();
1129
+ for (let r of t) {
1130
+ let t = document.createElement("button");
1131
+ t.type = "button", t.className = "emoji-item", t.textContent = r, t.addEventListener("click", () => {
1132
+ e(r), n.hidden = !0;
1133
+ }), n.appendChild(t);
1134
+ }
1135
+ r = !0;
1136
+ }
1137
+ n.hidden = !n.hidden;
1138
+ }), {
1139
+ button: t,
1140
+ panel: n
1141
+ };
1142
+ }
1143
+ //#endregion
1144
+ //#region src/core/ui.ts
1145
+ var ve = "https://bot-q-frontend.vercel.app/", ye = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2z\"/>\n</svg>", be = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\"/>\n</svg>", K = `<img src="${ue}" alt="" style="width:100%;height:100%;object-fit:cover;border-radius:50%" />`, xe = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n</svg>", Se = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2zm-2 10H6v-2h12v2zm0-3H6V7h12v2z\"/>\n</svg>";
1146
+ function Ce(e) {
1147
+ if (!e || e.type === "icon") return K;
1148
+ if (e.type === "emoji") return `<span style="font-size:22px;line-height:1;display:flex;align-items:center;justify-content:center;width:100%;height:100%">${q(e.value)}</span>`;
1149
+ if (e.type === "initials") {
1150
+ let t = e.bgColor ?? "#F97316";
1151
+ return `<div style="width:100%;height:100%;border-radius:50%;background:${/^#[0-9A-Fa-f]{3,6}$/.test(t) ? t : "#F97316"};display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#fff">${q(e.value.slice(0, 2).toUpperCase())}</div>`;
1152
+ }
1153
+ return e.type === "image" ? `<img src="${q(e.value)}" style="width:100%;height:100%;object-fit:cover;border-radius:50%" alt="" />` : K;
1154
+ }
1155
+ function q(e) {
1156
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
1157
+ }
1158
+ function J(e) {
1159
+ let t = [];
1160
+ return e = e.replace(/`([^`]+)`/g, (e, n) => (t.push(`<code>${n}</code>`), `\x00CODE${t.length - 1}\x00`)), e = e.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), e = e.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), e = e.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "<em>$1</em>"), e = e.replace(/~~(.+?)~~/g, "<del>$1</del>"), e = e.replace(/__(.+?)__/g, "<strong>$1</strong>"), e = e.replace(/(^|\s)_(?!_)(.+?)_(?!_)(?=\s|$)/g, "$1<em>$2</em>"), e = e.replace(/\[([^\]]+)\]\(([^()]*(?:\([^()]*\))*[^()]*)\)/g, (e, t, n) => /^https?:\/\//.test(n) ? `<a href="${n}" target="_blank" rel="noopener noreferrer">${t}</a>` : t), e = e.replace(/\x00CODE(\d+)\x00/g, (e, n) => t[Number(n)]), e;
1161
+ }
1162
+ function we(e) {
1163
+ return /^\|[\s\-:|]+\|$/.test(e);
1164
+ }
1165
+ function Y(e) {
1166
+ return e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim());
1167
+ }
1168
+ function Te(e, t) {
1169
+ return e ? `<div class="handoff-banner">⏳ ${q(t.waitingForHuman)}</div>` : "";
1170
+ }
1171
+ function Ee(e) {
1172
+ return e <= 0 ? "" : `<span class="unread-badge">${e > 9 ? "9+" : String(e)}</span>`;
1173
+ }
1174
+ function De(e) {
1175
+ let t = q(e).replace(/\x00/g, "").split("\n"), n = [], r = 0;
1176
+ for (; r < t.length;) {
1177
+ let e = t[r].trim();
1178
+ if (e.startsWith("|") && e.endsWith("|")) {
1179
+ let e = [];
1180
+ for (; r < t.length && t[r].trim().startsWith("|") && t[r].trim().endsWith("|");) e.push(t[r].trim()), r++;
1181
+ let i = e.findIndex(we), a = i > 0 ? e.slice(0, i) : [], o = i >= 0 ? e.slice(i + 1) : e, s = "<table>";
1182
+ a.length > 0 && (s += "<thead>" + a.map((e) => "<tr>" + Y(e).map((e) => `<th>${J(e)}</th>`).join("") + "</tr>").join("") + "</thead>"), o.length > 0 && (s += "<tbody>" + o.map((e) => "<tr>" + Y(e).map((e) => `<td>${J(e)}</td>`).join("") + "</tr>").join("") + "</tbody>"), s += "</table>", n.push(s);
1183
+ continue;
1184
+ }
1185
+ if (/^-{3,}$/.test(e)) {
1186
+ n.push("<hr>"), r++;
1187
+ continue;
1188
+ }
1189
+ let i = e.match(/^(#{1,6})\s+(.*)$/);
1190
+ if (i) {
1191
+ let e = i[1].length;
1192
+ n.push(`<h${e}>${J(i[2])}</h${e}>`), r++;
1193
+ continue;
1194
+ }
1195
+ if (/^[-*]\s/.test(e)) {
1196
+ let e = [];
1197
+ for (; r < t.length && /^\s*[-*]\s/.test(t[r]);) e.push(t[r].trim().replace(/^[-*]\s+/, "")), r++;
1198
+ n.push("<ul>" + e.map((e) => `<li>${J(e)}</li>`).join("") + "</ul>");
1199
+ continue;
1200
+ }
1201
+ if (/^\d+\.\s/.test(e)) {
1202
+ let e = [];
1203
+ for (; r < t.length && /^\s*\d+\.\s/.test(t[r]);) e.push(t[r].trim().replace(/^\d+\.\s+/, "")), r++;
1204
+ n.push("<ol>" + e.map((e) => `<li>${J(e)}</li>`).join("") + "</ol>");
1205
+ continue;
1206
+ }
1207
+ if (e === "") {
1208
+ n.push("<br>"), r++;
1209
+ continue;
1210
+ }
1211
+ n.push(J(e)), n.push("<br>"), r++;
1212
+ }
1213
+ for (; n.length > 0 && n[n.length - 1] === "<br>";) n.pop();
1214
+ return n.join("");
1215
+ }
1216
+ function Oe(e, t) {
1217
+ let { strings: n, content: r, botName: i, lang: a, now: o, contactInfo: s } = t;
1218
+ if (e.messages.length === 0 && !e.isLoading) {
1219
+ let e = r.suggestionChips.length > 0 ? `<div class="chips">${r.suggestionChips.map((e) => `<button class="chip">${q(e)}</button>`).join("")}</div>` : "";
1220
+ return `
1221
+ <div class="empty-state">
1222
+ ${Se}
1223
+ <span class="greeting">${q(r.greeting || n.defaultGreeting)}</span>
1224
+ ${e}
1225
+ </div>
1226
+ `;
1227
+ }
1228
+ let c = "", l = e.messages.map((e) => {
1229
+ let t = e.ts ?? o, r = se(t, o, a), l = r === c ? "" : `<div class="day-sep"><span>${q(r)}</span></div>`;
1230
+ c = r;
1231
+ let u = e.role === "assistant" ? De(e.content) : q(e.content), d = e.role === "assistant" && !e.error ? `<div class="msg-meta">${q(i)} · ${q(B(t, o, a))}</div>` : "", f = e.error ? `<button class="retry-btn" type="button">↻ ${q(n.retry)}</button>` : "", p = e.error && s ? `<div class="msg-contact">${q(s)}</div>` : "";
1232
+ return `${l}<div class="${`message ${e.role}${e.error ? " error" : ""}`}"><div class="message-bubble">${u}</div>${f}${p}${d}</div>`;
1233
+ }).join(""), u = e.loadingOlder ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "", d = e.isLoading ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "";
1234
+ return u + l + d;
1235
+ }
1236
+ function ke(e, t, n, r) {
1237
+ let { name: i, design: a } = t, o, s, c, l, u, d, f, p, m, h, g, _, { content: v } = a;
1238
+ function y(e) {
1239
+ e.setAttribute("data-position", a.layout.position), o = e.attachShadow({ mode: "closed" });
1240
+ let y = document.createElement("style");
1241
+ y.textContent = oe(a), o.appendChild(y), s = document.createElement("button"), s.className = "bubble", s.setAttribute("aria-label", n.ariaOpenChat), s.innerHTML = `
1242
+ <span class="icon-chat">${ye}</span>
1243
+ <span class="icon-close">${be}</span>
1244
+ <span class="unread-badge-slot"></span>
1245
+ `, s.addEventListener("click", () => r.onToggle()), o.appendChild(s), c = document.createElement("div"), c.className = "chat-window", c.setAttribute("role", "dialog"), c.setAttribute("aria-label", `${i} chat`), c.innerHTML = `
1246
+ <div class="chat-header">
1247
+ <div class="avatar">${Ce(a.avatar)}</div>
1248
+ <div class="header-text">
1249
+ <span class="bot-name">${q(i)}</span>
1250
+ <span class="bot-status">${q(n.statusOnline)}</span>
1251
+ </div>
1252
+ <button class="close-btn" aria-label="${q(n.ariaCloseChat)}">×</button>
1253
+ </div>
1254
+ <div class="chat-body">
1255
+ <div class="panel panel-home"></div>
1256
+ <div class="panel panel-messages"></div>
1257
+ <div class="panel panel-conversation">
1258
+ <div class="messages" id="messages-container" role="log" aria-live="polite" aria-atomic="false"></div>
1259
+ <div class="handoff-slot"></div>
1260
+ <div class="chat-footer">
1261
+ <div class="input-row">
1262
+ <textarea
1263
+ class="input"
1264
+ placeholder="${q(v.placeholder || n.inputPlaceholder)}"
1265
+ rows="1"
1266
+ maxlength="2000"
1267
+ aria-label="Message input"
1268
+ ></textarea>
1269
+ <button class="send-btn" aria-label="${q(n.ariaSendMessage)}">
1270
+ ${xe}
1271
+ </button>
1272
+ </div>
1273
+ <a class="botiq-badge" href="${ve}" target="_blank" rel="noopener noreferrer">
1274
+ ${q(n.poweredBy)} <span class="botiq-badge-name">BotIQ</span>
1275
+ </a>
1276
+ </div>
1277
+ </div>
1278
+ </div>
1279
+ <div class="bottom-nav">
1280
+ <button class="nav-btn" data-view="home">⌂ ${q(n.navHome)}</button>
1281
+ <button class="nav-btn" data-view="messages">💬 ${q(n.navMessages)}</button>
1282
+ </div>
1283
+ `, c.querySelector(".close-btn").addEventListener("click", () => r.onToggle()), l = c.querySelector(".panel-home"), u = c.querySelector(".panel-messages"), d = c.querySelector(".panel-conversation"), l.innerHTML = le(t, n), l.querySelector(".home-start")?.addEventListener("click", () => {
1284
+ r.onNewConversation();
1285
+ }), f = c.querySelector(".nav-btn[data-view=\"home\"]"), p = c.querySelector(".nav-btn[data-view=\"messages\"]"), c.querySelectorAll(".nav-btn").forEach((e) => {
1286
+ e.addEventListener("click", () => {
1287
+ let t = e.dataset.view;
1288
+ r.onNavigate(t);
1289
+ });
1290
+ }), m = c.querySelector("#messages-container"), h = c.querySelector(".handoff-slot");
1291
+ let x = null;
1292
+ m.addEventListener("scroll", () => {
1293
+ m.scrollTop <= 48 && !x && (x = setTimeout(() => {
1294
+ x = null;
1295
+ }, 150), r.onScrollTop());
1296
+ }), g = c.querySelector(".input"), _ = c.querySelector(".send-btn"), g.addEventListener("input", () => {
1297
+ g.style.height = "auto", g.style.height = Math.min(g.scrollHeight, 100) + "px";
1298
+ }), g.addEventListener("keydown", (e) => {
1299
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), b());
1300
+ }), _.addEventListener("click", b);
1301
+ let S = c.querySelector(".input-row"), { button: C, panel: w } = _e((e) => {
1302
+ he(g, e), g.focus();
1303
+ });
1304
+ S.insertBefore(C, _), c.querySelector(".chat-footer").appendChild(w), o.appendChild(c);
1305
+ }
1306
+ function b() {
1307
+ let e = g.value.trim();
1308
+ !e || _.disabled || (g.value = "", g.style.height = "auto", r.onSend(e));
1309
+ }
1310
+ function x(e) {
1311
+ let a = m.scrollHeight - m.scrollTop - m.clientHeight < 80, o = m.scrollTop, s = m.scrollHeight;
1312
+ m.innerHTML = Oe(e, {
1313
+ strings: n,
1314
+ content: v,
1315
+ botName: i,
1316
+ lang: t.widgetLanguage,
1317
+ now: Date.now(),
1318
+ contactInfo: t.contactInfo
1319
+ }), m.querySelectorAll(".chip").forEach((e) => {
1320
+ e.addEventListener("click", () => r.onSend(e.textContent ?? ""));
1321
+ }), m.querySelectorAll(".retry-btn").forEach((e) => {
1322
+ e.addEventListener("click", () => r.onRetry());
1323
+ }), a ? m.scrollTop = m.scrollHeight : m.scrollTop = pe(o, s, m.scrollHeight);
1324
+ }
1325
+ function S(e) {
1326
+ e.isOpen ? (c.classList.add("open"), s.classList.add("open"), s.setAttribute("aria-label", n.ariaCloseChat), e.view === "conversation" && requestAnimationFrame(() => g.focus())) : (c.classList.remove("open"), s.classList.remove("open"), s.setAttribute("aria-label", n.ariaOpenChat));
1327
+ let t = s.querySelector(".unread-badge-slot");
1328
+ t && (t.innerHTML = Ee(e.unreadCount)), _.disabled = e.isLoading, c.dataset.view = e.view, l.classList.toggle("active", e.view === "home"), u.classList.toggle("active", e.view === "messages"), d.classList.toggle("active", e.view === "conversation"), f.classList.toggle("active", e.view === "home"), p.classList.toggle("active", e.view === "messages"), e.view === "conversation" && (x(e), h.innerHTML = Te(e.escalated, n)), e.view === "messages" && (u.innerHTML = ce(e.conversations, n, Date.now()), u.querySelectorAll(".msg-list-item").forEach((e) => {
1329
+ e.addEventListener("click", () => {
1330
+ let t = e.dataset.session;
1331
+ t && r.onOpenConversation(t);
1332
+ });
1333
+ }), u.querySelector(".msg-list-new")?.addEventListener("click", () => {
1334
+ r.onNewConversation();
1335
+ }));
1336
+ }
1337
+ function C(e) {
1338
+ return me(o, {
1339
+ ...e,
1340
+ labels: {
1341
+ confirm: n.confirmYes,
1342
+ cancel: n.confirmNo,
1343
+ countdownPrefix: n.confirmCountdownPrefix,
1344
+ countdownSuffix: n.confirmCountdownSuffix
1345
+ }
1346
+ });
1347
+ }
1348
+ return {
1349
+ mount: y,
1350
+ update: S,
1351
+ confirmAction: C
1352
+ };
1353
+ }
1354
+ //#endregion
1355
+ //#region src/i18n/vi.ts
1356
+ var Ae = {
1357
+ statusOnline: "Trực tuyến",
1358
+ statusPaused: "Tạm ngừng",
1359
+ navHome: "Trang chủ",
1360
+ navMessages: "Tin nhắn",
1361
+ homeGreeting: "Xin chào 👋",
1362
+ startConversation: "Bắt đầu trò chuyện",
1363
+ newConversation: "Cuộc trò chuyện mới",
1364
+ noConversations: "Chưa có cuộc trò chuyện nào",
1365
+ waitingForHuman: "Đang chờ nhân viên…",
1366
+ inputPlaceholder: "Nhắn tin...",
1367
+ defaultGreeting: "Xin chào! Tôi có thể giúp gì cho bạn?",
1368
+ errorMessage: "Xin lỗi, không thể kết nối. Vui lòng thử lại.",
1369
+ errorAuth: "API key không hợp lệ.",
1370
+ errorForbidden: "Widget không được phép trên trang này.",
1371
+ errorQuota: "Bot đã đạt giới hạn tin nhắn tháng này.",
1372
+ errorGeneric: "Đang gặp sự cố kỹ thuật, vui lòng liên hệ trực tiếp.",
1373
+ typingIndicator: "Đang soạn tin...",
1374
+ quotaExceeded: "Bot đã hết lượt chat tháng này.",
1375
+ trialExpired: "Dịch vụ tạm dừng. Vui lòng liên hệ hỗ trợ.",
1376
+ poweredBy: "Powered by",
1377
+ ariaOpenChat: "Mở khung chat",
1378
+ ariaCloseChat: "Đóng khung chat",
1379
+ ariaSendMessage: "Gửi tin nhắn",
1380
+ actionDone: "✓ Đã thực hiện.",
1381
+ actionCancelled: "Đã huỷ. Bạn cần gì khác không?",
1382
+ actionUnavailable: "Hành động không khả dụng.",
1383
+ actionError: "Có lỗi khi thực hiện.",
1384
+ confirmYes: "Đồng ý",
1385
+ confirmNo: "Huỷ",
1386
+ confirmCountdownPrefix: "Tự động xác nhận sau ",
1387
+ confirmCountdownSuffix: "s…",
1388
+ retry: "Thử lại"
1389
+ }, X = {
1390
+ statusOnline: "Online",
1391
+ statusPaused: "Paused",
1392
+ navHome: "Home",
1393
+ navMessages: "Messages",
1394
+ homeGreeting: "Hi there 👋",
1395
+ startConversation: "Start a conversation",
1396
+ newConversation: "New conversation",
1397
+ noConversations: "No conversations yet",
1398
+ waitingForHuman: "Waiting for a teammate…",
1399
+ inputPlaceholder: "Type a message...",
1400
+ defaultGreeting: "Hello! How can I help you?",
1401
+ errorMessage: "Sorry, something went wrong. Please try again.",
1402
+ errorAuth: "Invalid API key.",
1403
+ errorForbidden: "Widget is not allowed on this page.",
1404
+ errorQuota: "This bot has reached its monthly message limit.",
1405
+ errorGeneric: "Technical issue, please contact us directly.",
1406
+ typingIndicator: "Typing...",
1407
+ quotaExceeded: "This bot has reached its monthly chat limit.",
1408
+ trialExpired: "Service paused. Please contact support.",
1409
+ poweredBy: "Powered by",
1410
+ ariaOpenChat: "Open chat",
1411
+ ariaCloseChat: "Close chat",
1412
+ ariaSendMessage: "Send message",
1413
+ actionDone: "✓ Done.",
1414
+ actionCancelled: "Cancelled. Anything else?",
1415
+ actionUnavailable: "Action unavailable.",
1416
+ actionError: "Something went wrong.",
1417
+ confirmYes: "Confirm",
1418
+ confirmNo: "Cancel",
1419
+ confirmCountdownPrefix: "Auto-confirming in ",
1420
+ confirmCountdownSuffix: "s…",
1421
+ retry: "Retry"
1422
+ };
1423
+ //#endregion
1424
+ //#region src/i18n/index.ts
1425
+ function Z(e) {
1426
+ return e === "en" ? X : Ae;
1427
+ }
1428
+ //#endregion
1429
+ //#region src/core/declarative-executor.ts
1430
+ var je = /^[a-zA-Z0-9_-]*$/;
1431
+ function Q(e, t) {
1432
+ return e.replace(/\{([a-zA-Z][a-zA-Z0-9_]*)\}/g, (e, n) => {
1433
+ let r = t[n], i = r == null ? "" : String(r);
1434
+ if (!je.test(i)) throw Error(`Unsafe param value for "${n}"`);
1435
+ return i;
1436
+ });
1437
+ }
1438
+ function Me(e, t) {
1439
+ let n = typeof location < "u" ? location.origin : "https://placeholder.local", r, i;
1440
+ try {
1441
+ r = new URL(e, n), i = new URL(t.replace(/\{[a-zA-Z][a-zA-Z0-9_]*\}/g, "x"), n);
1442
+ } catch {
1443
+ throw Error("Invalid navigation URL");
1444
+ }
1445
+ if (!/^https?:$/.test(r.protocol)) throw Error("Navigation must be http(s)");
1446
+ if (r.origin !== i.origin) throw Error("Navigation origin not allowed");
1447
+ }
1448
+ async function Ne(e, t) {
1449
+ let n = e.config;
1450
+ if (e.operation === "click") {
1451
+ let e = Q(String(n.selectorTemplate ?? ""), t), r = document.querySelector(e);
1452
+ if (!r) throw Error(`No element for selector: ${e}`);
1453
+ r.click();
1454
+ return;
1455
+ }
1456
+ if (e.operation === "fill") {
1457
+ let e = Array.isArray(n.fields) ? n.fields : [];
1458
+ for (let n of e) {
1459
+ let e = document.querySelector(n.selector);
1460
+ if (!e) throw Error(`No element for selector: ${n.selector}`);
1461
+ e.value = String(t[n.param] ?? ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 }));
1462
+ }
1463
+ return;
1464
+ }
1465
+ if (e.operation === "navigate") {
1466
+ let e = String(n.urlTemplate ?? ""), r = Q(e, t);
1467
+ Me(r, e), location.assign(r);
1468
+ return;
1469
+ }
1470
+ throw Error(`Unknown operation: ${String(e.operation)}`);
1471
+ }
1472
+ //#endregion
1473
+ //#region src/core/page-action-executor.ts
1474
+ async function Pe(e, t) {
1475
+ let n = t.registry.get(e.actionName);
1476
+ if (!n) return {
1477
+ status: "unknown",
1478
+ message: `Action "${e.actionName}" chưa được đăng ký.`
1479
+ };
1480
+ if (n.riskLevel !== "low" && !await t.confirm({
1481
+ title: n.description,
1482
+ reason: e.reason,
1483
+ paramsDisplay: JSON.stringify(e.params, null, 2),
1484
+ riskLevel: n.riskLevel,
1485
+ autoConfirmAfterSec: n.riskLevel === "medium" ? 10 : null
1486
+ })) return { status: "cancelled" };
1487
+ try {
1488
+ return await t.registry.execute(e.actionName, e.params), { status: "executed" };
1489
+ } catch (e) {
1490
+ return {
1491
+ status: "error",
1492
+ message: e instanceof Error ? e.message : "unknown error"
1493
+ };
1494
+ }
1495
+ }
1496
+ //#endregion
1497
+ //#region src/builds/npm/index.ts
1498
+ var $ = 10;
1499
+ function Fe(e) {
1500
+ if (D.setDeclarativeRunner(Ne), typeof window < "u" && (window.botiq = window.botiq ?? {}, window.botiq.registerActions = (e) => D.register(e)), !e.apiKey) return console.warn("[BotIQ] apiKey is required"), () => void 0;
1501
+ let t = p(e);
1502
+ y();
1503
+ let n = t.apiKey.slice(-16), r = C(), i = b(n), a = x(n, i);
1504
+ F({
1505
+ messages: a,
1506
+ view: "home",
1507
+ currentSessionId: i
1508
+ });
1509
+ let o = H(), s = document.createElement("div");
1510
+ document.body.appendChild(s);
1511
+ let c = () => void 0, l = !1, u = Z(void 0), d = null, m = null, h = null;
1512
+ function g() {
1513
+ h ||= setTimeout(async () => {
1514
+ if (h = null, !(!P().escalated || !P().isOpen)) try {
1515
+ let e = await j(t.apiUrl, t.apiKey, P().currentSessionId, $, r);
1516
+ e.messages.length > 0 && F({ messages: e.messages.map(O) }), F({ escalated: e.escalated === !0 });
1517
+ } catch {} finally {
1518
+ P().escalated && P().isOpen && g();
1519
+ }
1520
+ }, 1e4);
1521
+ }
1522
+ f(t.apiKey, t.apiUrl).then((e) => {
1523
+ if (l) return;
1524
+ if (e === null) {
1525
+ console.warn("[BotIQ] Widget not authorised on this origin — skipped mount"), s.remove();
1526
+ return;
1527
+ }
1528
+ u = Z(e.widgetLanguage), e.pageActions?.length && D.seed(e.pageActions);
1529
+ let n = ke(t, e, u, {
1530
+ onSend: I,
1531
+ onToggle: R,
1532
+ onScrollTop: A,
1533
+ onRetry: L,
1534
+ onNavigate: v,
1535
+ onOpenConversation: E,
1536
+ onNewConversation: T
1537
+ });
1538
+ d = n, n.mount(s), c = re((e) => n.update(e)), n.update(P()), e.proactive?.enabled && (m = setTimeout(() => {
1539
+ if (P().isOpen) return;
1540
+ let t = {
1541
+ role: "assistant",
1542
+ content: e.proactive.message,
1543
+ ts: Date.now()
1544
+ };
1545
+ F({
1546
+ messages: [...P().messages, t],
1547
+ view: "conversation",
1548
+ unreadCount: P().unreadCount + 1
1549
+ });
1550
+ }, e.proactive.delayMs ?? 8e3)), a.length > 0 && k(i);
1551
+ });
1552
+ async function _() {
1553
+ F({ conversations: await ee(t.apiUrl, t.apiKey, r) });
1554
+ }
1555
+ function v(e) {
1556
+ F({ view: e }), e === "messages" && _();
1557
+ }
1558
+ function T() {
1559
+ F({
1560
+ view: "conversation",
1561
+ currentSessionId: w(),
1562
+ messages: [],
1563
+ escalated: !1
1564
+ }), o = H();
1565
+ }
1566
+ function E(e) {
1567
+ F({
1568
+ view: "conversation",
1569
+ currentSessionId: e,
1570
+ messages: x(n, e)
1571
+ }), o = H(), k(e);
1572
+ }
1573
+ function O(e) {
1574
+ let t = Date.parse(e.createdAt);
1575
+ return {
1576
+ role: e.role,
1577
+ content: e.content,
1578
+ ...Number.isFinite(t) ? { ts: t } : {}
1579
+ };
1580
+ }
1581
+ async function k(e) {
1582
+ let n = await j(t.apiUrl, t.apiKey, e, $, r);
1583
+ n.messages.length > 0 && (o = U(n), F({ messages: n.messages.map(O) })), F({ escalated: n.escalated === !0 }), P().escalated && g();
1584
+ }
1585
+ async function A() {
1586
+ if (fe(o, P().loadingOlder)) {
1587
+ F({ loadingOlder: !0 });
1588
+ try {
1589
+ let e = P().currentSessionId, n = await ne(t.apiUrl, t.apiKey, e, o.oldestCursor, $);
1590
+ n.messages.length > 0 && F({ messages: [...n.messages.map(O), ...P().messages] }), o = de(o, n);
1591
+ } finally {
1592
+ F({ loadingOlder: !1 });
1593
+ }
1594
+ }
1595
+ }
1596
+ let M = "";
1597
+ async function N(e) {
1598
+ let i = P().currentSessionId, a = x(n, i).length === 0 && P().messages.filter((e) => e.role === "user").length === 1;
1599
+ F({ isLoading: !0 });
1600
+ try {
1601
+ let o = await te(t.apiUrl, t.apiKey, i, e, P().messages.filter((e) => !e.error), u, r), s = {
1602
+ role: "assistant",
1603
+ content: o.reply,
1604
+ ts: Date.now(),
1605
+ ...o.error ? { error: !0 } : {}
1606
+ };
1607
+ if (F({
1608
+ messages: [...P().messages, s],
1609
+ isLoading: !1
1610
+ }), o.error || S(n, i, [s]), !o.error && a && _(), o.error || j(t.apiUrl, t.apiKey, i, $, r).then((e) => {
1611
+ F({ escalated: e.escalated === !0 }), P().escalated && g();
1612
+ }), !o.error && o.pageAction && d) {
1613
+ let e = d;
1614
+ try {
1615
+ let t = await Pe(o.pageAction, {
1616
+ registry: D,
1617
+ confirm: (t) => e.confirmAction(t)
1618
+ });
1619
+ if (!d) return;
1620
+ let r = {
1621
+ role: "assistant",
1622
+ content: t.status === "executed" ? u.actionDone : t.status === "cancelled" ? u.actionCancelled : t.status === "unknown" ? `⚠ ${t.message ?? u.actionUnavailable}` : `⚠ ${t.message ?? u.actionError}`,
1623
+ ts: Date.now()
1624
+ };
1625
+ F({ messages: [...P().messages, r] }), S(n, i, [r]);
1626
+ } catch {
1627
+ if (!d) return;
1628
+ let e = {
1629
+ role: "assistant",
1630
+ content: u.actionError,
1631
+ ts: Date.now()
1632
+ };
1633
+ F({ messages: [...P().messages, e] }), S(n, i, [e]);
1634
+ }
1635
+ }
1636
+ } catch {
1637
+ F({ isLoading: !1 });
1638
+ }
1639
+ }
1640
+ async function I(e) {
1641
+ if (P().isLoading) return;
1642
+ M = e;
1643
+ let t = P().currentSessionId, r = {
1644
+ role: "user",
1645
+ content: e,
1646
+ ts: Date.now()
1647
+ };
1648
+ F({ messages: [...P().messages, r] }), S(n, t, [r]), await N(e);
1649
+ }
1650
+ function L() {
1651
+ if (P().isLoading || !M) return;
1652
+ let e = P().messages;
1653
+ F({ messages: e.length > 0 && e[e.length - 1].error ? e.slice(0, -1) : e }), N(M);
1654
+ }
1655
+ function R() {
1656
+ let e = !P().isOpen;
1657
+ F({
1658
+ isOpen: e,
1659
+ ...e ? { unreadCount: 0 } : {}
1660
+ });
1661
+ }
1662
+ return () => {
1663
+ l = !0, d = null, c(), m && clearTimeout(m), h &&= (clearTimeout(h), null), s.remove();
1664
+ };
1665
+ }
1666
+ //#endregion
1667
+ export { Fe as t };