@locdo.tech/botiq-chat-sdk 0.5.0 → 0.7.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,2195 @@
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, m = a.imageInput === !0 ? !0 : void 0, h = a.richMessages === !0 ? !0 : void 0, g = {
94
+ ...c ? { pageActions: c } : {},
95
+ ...u ? { contactInfo: u } : {},
96
+ ...f ? { proactive: f } : {},
97
+ ...p ? { status: p } : {},
98
+ ...m ? { imageInput: m } : {},
99
+ ...h ? { richMessages: h } : {}
100
+ };
101
+ return !a.design?.colors || !a.design?.layout || !a.design?.content || !l(a.design) ? {
102
+ name: o,
103
+ design: t,
104
+ widgetLanguage: s,
105
+ ...g
106
+ } : {
107
+ name: o,
108
+ design: a.design,
109
+ widgetLanguage: s,
110
+ ...g
111
+ };
112
+ }
113
+ function p(t) {
114
+ return {
115
+ apiKey: t.apiKey,
116
+ apiUrl: e
117
+ };
118
+ }
119
+ //#endregion
120
+ //#region src/core/session.ts
121
+ var m = "botiq:sessionId", h = "botiq:sessionId:", g = "botiq:history:", _ = "botiq:visitorId", v = 10;
122
+ function y() {
123
+ try {
124
+ let e = localStorage.getItem(m);
125
+ localStorage.removeItem(m), e && localStorage.removeItem(g + e);
126
+ } catch {}
127
+ }
128
+ function b(e) {
129
+ try {
130
+ let t = h + e, n = localStorage.getItem(t);
131
+ return n || (n = crypto.randomUUID(), localStorage.setItem(t, n)), n;
132
+ } catch {
133
+ return crypto.randomUUID();
134
+ }
135
+ }
136
+ function x(e, t) {
137
+ try {
138
+ let n = localStorage.getItem(`${g}${e}:${t}`);
139
+ return n ? JSON.parse(n) : [];
140
+ } catch {
141
+ return [];
142
+ }
143
+ }
144
+ function S(e, t, n) {
145
+ try {
146
+ let r = [...x(e, t), ...n].slice(-v);
147
+ localStorage.setItem(`${g}${e}:${t}`, JSON.stringify(r));
148
+ } catch {}
149
+ }
150
+ function C() {
151
+ try {
152
+ let e = localStorage.getItem(_);
153
+ return e || (e = crypto.randomUUID(), localStorage.setItem(_, e)), e;
154
+ } catch {
155
+ return crypto.randomUUID();
156
+ }
157
+ }
158
+ function w() {
159
+ return crypto.randomUUID();
160
+ }
161
+ //#endregion
162
+ //#region src/core/action-registry.ts
163
+ var T = /^[a-z][a-z0-9_]{2,40}$/, E = new Set([
164
+ "low",
165
+ "medium",
166
+ "high"
167
+ ]), D = new class {
168
+ actions = /* @__PURE__ */ new Map();
169
+ declarativeRunner;
170
+ constructor(e) {
171
+ this.declarativeRunner = e;
172
+ }
173
+ validate(e) {
174
+ if (!T.test(e.name)) throw Error(`Invalid action name: "${e.name}"`);
175
+ if (!E.has(e.riskLevel)) throw Error(`Invalid riskLevel: ${e.riskLevel}`);
176
+ if (typeof e.description != "string" || e.description.length < 5) throw Error(`description ≥5 chars required for ${e.name}`);
177
+ }
178
+ seed(e) {
179
+ for (let t of e) try {
180
+ this.validate(t), this.actions.set(t.name, {
181
+ ...t,
182
+ kind: "declarative"
183
+ });
184
+ } catch (e) {
185
+ console.warn("[BotIQ] skipped invalid page action: " + e.message);
186
+ }
187
+ }
188
+ register(e) {
189
+ for (let t of e) {
190
+ if (this.validate(t), typeof t.execute != "function") throw Error(`execute must be a function for ${t.name}`);
191
+ this.actions.set(t.name, {
192
+ ...t,
193
+ kind: "js"
194
+ });
195
+ }
196
+ }
197
+ has(e) {
198
+ return this.actions.has(e);
199
+ }
200
+ get(e) {
201
+ return this.actions.get(e);
202
+ }
203
+ getDefinitions() {
204
+ return Array.from(this.actions.values()).map((e) => ({
205
+ name: e.name,
206
+ description: e.description,
207
+ riskLevel: e.riskLevel,
208
+ params: e.params
209
+ }));
210
+ }
211
+ setDeclarativeRunner(e) {
212
+ this.declarativeRunner = e;
213
+ }
214
+ async execute(e, t) {
215
+ let n = this.actions.get(e);
216
+ if (!n) throw Error(`Action "${e}" not registered`);
217
+ if (n.kind === "js") {
218
+ await n.execute(t);
219
+ return;
220
+ }
221
+ if (!this.declarativeRunner) throw Error("No declarative runner configured");
222
+ await this.declarativeRunner(n, t);
223
+ }
224
+ }();
225
+ //#endregion
226
+ //#region src/core/api.ts
227
+ async function O(e, t, n) {
228
+ try {
229
+ let r = new URLSearchParams({ visitorId: n }), i = await fetch(`${e}/widget/conversations?${r.toString()}`, {
230
+ method: "GET",
231
+ headers: {
232
+ "X-Api-Key": t,
233
+ "X-Visitor-Id": n
234
+ },
235
+ referrerPolicy: "no-referrer-when-downgrade"
236
+ });
237
+ if (!i.ok) return [];
238
+ let a = await i.json();
239
+ return Array.isArray(a.conversations) ? a.conversations : [];
240
+ } catch {
241
+ return [];
242
+ }
243
+ }
244
+ async function k(e, t, n, r, i) {
245
+ let a = i?.imageUploadError ?? "Image upload failed. Please try again.";
246
+ try {
247
+ let o = new FormData(), s = n.type === "image/webp" ? ".webp" : ".jpg";
248
+ o.append("file", n, `image${s}`);
249
+ let c = await fetch(`${e}/widget/upload`, {
250
+ method: "POST",
251
+ headers: {
252
+ "X-Api-Key": t,
253
+ ...r ? { "X-Visitor-Id": r } : {}
254
+ },
255
+ referrerPolicy: "no-referrer-when-downgrade",
256
+ body: o
257
+ });
258
+ if (!c.ok) return c.status === 403 ? {
259
+ ok: !1,
260
+ error: i?.imageUploadPlanError ?? a
261
+ } : c.status === 413 ? {
262
+ ok: !1,
263
+ error: i?.imageUploadTooLarge ?? a
264
+ } : c.status === 429 ? {
265
+ ok: !1,
266
+ error: i?.imageUploadRateLimit ?? a
267
+ } : {
268
+ ok: !1,
269
+ error: a
270
+ };
271
+ let l = await c.json();
272
+ return l.url ? {
273
+ ok: !0,
274
+ url: l.url
275
+ } : {
276
+ ok: !1,
277
+ error: a
278
+ };
279
+ } catch {
280
+ return {
281
+ ok: !1,
282
+ error: a
283
+ };
284
+ }
285
+ }
286
+ async function ee(e, t, n, r, i, a, o, s) {
287
+ try {
288
+ let c = D.getDefinitions(), l = await fetch(`${e}/widget/chat`, {
289
+ method: "POST",
290
+ headers: {
291
+ "Content-Type": "application/json",
292
+ "X-Api-Key": t,
293
+ ...o ? { "X-Visitor-Id": o } : {}
294
+ },
295
+ referrerPolicy: "no-referrer-when-downgrade",
296
+ body: JSON.stringify({
297
+ sessionId: n,
298
+ message: r,
299
+ history: i,
300
+ ...c.length > 0 ? { availableActions: c } : {},
301
+ ...s?.length ? { attachments: s } : {}
302
+ })
303
+ });
304
+ if (!l.ok) return l.status === 401 ? {
305
+ reply: a.errorAuth,
306
+ error: !0
307
+ } : l.status === 403 ? {
308
+ reply: a.errorForbidden,
309
+ error: !0
310
+ } : l.status === 429 ? {
311
+ reply: a.errorQuota,
312
+ error: !0
313
+ } : {
314
+ reply: a.errorGeneric,
315
+ error: !0
316
+ };
317
+ let u = await l.json(), d = Array.isArray(u.blocks) && u.blocks.length > 0 ? u.blocks : void 0;
318
+ return {
319
+ reply: u.reply || a.errorMessage,
320
+ pageAction: u.pageAction,
321
+ blocks: d
322
+ };
323
+ } catch {
324
+ return {
325
+ reply: a.errorMessage,
326
+ error: !0
327
+ };
328
+ }
329
+ }
330
+ var A = {
331
+ messages: [],
332
+ hasMore: !1
333
+ };
334
+ function te(e) {
335
+ if (!e || typeof e != "object") return !1;
336
+ let t = e;
337
+ return typeof t.id == "string" && (t.role === "user" || t.role === "assistant") && typeof t.content == "string";
338
+ }
339
+ async function j(e, t, n, r, i, a) {
340
+ try {
341
+ let o = new URLSearchParams({
342
+ sessionId: n,
343
+ limit: String(i)
344
+ });
345
+ r && o.set("before", r);
346
+ let s = await fetch(`${e}/widget/messages?${o.toString()}`, {
347
+ method: "GET",
348
+ headers: {
349
+ "X-Api-Key": t,
350
+ ...a ? { "X-Visitor-Id": a } : {}
351
+ },
352
+ referrerPolicy: "no-referrer-when-downgrade"
353
+ });
354
+ if (!s.ok) return A;
355
+ let c = await s.json();
356
+ return {
357
+ messages: Array.isArray(c.messages) ? c.messages.filter(te) : [],
358
+ hasMore: c.hasMore === !0,
359
+ escalated: c.escalated === !0
360
+ };
361
+ } catch {
362
+ return A;
363
+ }
364
+ }
365
+ function M(e, t, n, r, i) {
366
+ return j(e, t, n, void 0, r, i);
367
+ }
368
+ function ne(e, t, n, r, i, a) {
369
+ return j(e, t, n, r, i, a);
370
+ }
371
+ //#endregion
372
+ //#region src/core/state.ts
373
+ var N = {
374
+ messages: [],
375
+ isLoading: !1,
376
+ isOpen: !1,
377
+ loadingOlder: !1,
378
+ view: "home",
379
+ unreadCount: 0,
380
+ conversations: [],
381
+ currentSessionId: "",
382
+ escalated: !1,
383
+ pendingAttachment: null,
384
+ isUploading: !1,
385
+ uploadError: null
386
+ }, P = /* @__PURE__ */ new Set();
387
+ function F() {
388
+ return N;
389
+ }
390
+ function I(e) {
391
+ Object.assign(N, e);
392
+ let t = {
393
+ ...N,
394
+ messages: [...N.messages],
395
+ conversations: [...N.conversations]
396
+ };
397
+ P.forEach((e) => e(t));
398
+ }
399
+ function re(e) {
400
+ return P.add(e), () => P.delete(e);
401
+ }
402
+ //#endregion
403
+ //#region src/core/upload.ts
404
+ var L = new Set([
405
+ "image/jpeg",
406
+ "image/png",
407
+ "image/webp"
408
+ ]), R = 25 * 1024 * 1024, z = 5 * 1024 * 1024, B = 1600, ie = .85, ae = .65;
409
+ function oe(e) {
410
+ return L.has(e);
411
+ }
412
+ function se(e) {
413
+ return oe(e.type) ? e.size > R ? {
414
+ ok: !1,
415
+ error: "Image too large (max 25 MB before compression)."
416
+ } : { ok: !0 } : {
417
+ ok: !1,
418
+ error: "Unsupported image type. Please use JPEG, PNG, or WebP."
419
+ };
420
+ }
421
+ function ce(e, t) {
422
+ let n = Math.max(e, t);
423
+ if (n <= B) return {
424
+ width: e,
425
+ height: t
426
+ };
427
+ let r = B / n;
428
+ return {
429
+ width: Math.floor(e * r),
430
+ height: Math.floor(t * r)
431
+ };
432
+ }
433
+ function le(e) {
434
+ let t = se(e);
435
+ return t.ok ? new Promise((t, n) => {
436
+ let r = new Image(), i = URL.createObjectURL(e);
437
+ r.onload = () => {
438
+ URL.revokeObjectURL(i);
439
+ let { width: a, height: o } = ce(r.naturalWidth, r.naturalHeight), s = document.createElement("canvas");
440
+ s.width = a, s.height = o;
441
+ let c = s.getContext("2d");
442
+ if (!c) {
443
+ n(/* @__PURE__ */ Error("Canvas 2D context not available"));
444
+ return;
445
+ }
446
+ c.drawImage(r, 0, 0, a, o);
447
+ let l = e.type === "image/webp" ? "image/webp" : "image/jpeg";
448
+ s.toBlob((e) => {
449
+ if (!e) {
450
+ n(/* @__PURE__ */ Error("Canvas toBlob returned null"));
451
+ return;
452
+ }
453
+ if (e.size <= z) {
454
+ t({
455
+ blob: e,
456
+ mimeType: l
457
+ });
458
+ return;
459
+ }
460
+ s.toBlob((e) => {
461
+ if (!e) {
462
+ n(/* @__PURE__ */ Error("Canvas toBlob (fallback quality) returned null"));
463
+ return;
464
+ }
465
+ if (e.size > z) {
466
+ n(/* @__PURE__ */ Error("Image too large after compression (> 5 MB). Try a smaller image."));
467
+ return;
468
+ }
469
+ t({
470
+ blob: e,
471
+ mimeType: l
472
+ });
473
+ }, l, ae);
474
+ }, l, ie);
475
+ }, r.onerror = () => {
476
+ URL.revokeObjectURL(i), n(/* @__PURE__ */ Error("Failed to load image"));
477
+ }, r.src = i;
478
+ }) : Promise.reject(Error(t.error));
479
+ }
480
+ //#endregion
481
+ //#region src/core/styles.ts
482
+ var V = {
483
+ inter: {
484
+ url: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
485
+ family: "'Inter', system-ui, -apple-system, sans-serif"
486
+ },
487
+ "plus-jakarta": {
488
+ url: "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap",
489
+ family: "'Plus Jakarta Sans', system-ui, -apple-system, sans-serif"
490
+ },
491
+ nunito: {
492
+ url: "https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600&display=swap",
493
+ family: "'Nunito', system-ui, -apple-system, sans-serif"
494
+ },
495
+ raleway: {
496
+ url: "https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600&display=swap",
497
+ family: "'Raleway', system-ui, -apple-system, sans-serif"
498
+ },
499
+ playfair: {
500
+ url: "https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600&display=swap",
501
+ family: "'Playfair Display', Georgia, serif"
502
+ }
503
+ };
504
+ function H(e, t) {
505
+ if (!t) return e;
506
+ let n = t.angle ?? 135;
507
+ return t.type === "linear" ? `linear-gradient(${n}deg, ${t.from}, ${t.to})` : `radial-gradient(circle, ${t.from}, ${t.to})`;
508
+ }
509
+ function ue(e) {
510
+ 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, "");
511
+ }
512
+ function de(e) {
513
+ let t = e?.bubbleOpen ?? "none", n = e?.typingIndicator ?? "dots-bounce";
514
+ 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");
515
+ }
516
+ var fe = "\n/* ── Rich Blocks ─────────────────────────── */\n.biq-blocks {\n margin-top: 8px;\n display: flex;\n flex-direction: column;\n gap: 8px;\n max-width: 100%;\n}\n\n/* ── Shared button style ─────────────────── */\n.biq-btn {\n display: inline-block;\n padding: 7px 14px;\n border-radius: 18px;\n font: inherit;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n transition: filter .15s, opacity .15s;\n text-decoration: none;\n border: 1.5px solid #F97316;\n background: transparent;\n color: #F97316;\n line-height: 1.3;\n white-space: nowrap;\n}\n.biq-btn:hover { filter: brightness(1.15); }\n.biq-btn--send { background: #F97316; color: #fff; }\n.biq-btn--send:hover { filter: brightness(0.9); }\n.biq-btn--url { background: transparent; color: #F97316; }\n.biq-btn--page_action { border-style: dashed; }\n\n/* ── Card ────────────────────────────────── */\n.biq-card {\n background: #1A1A1A;\n border: 1px solid #2D2D2D;\n border-radius: 12px;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n min-width: 0;\n text-decoration: none;\n color: inherit;\n transition: border-color .15s;\n}\n.biq-card--link:hover { border-color: #F97316; }\n\n.biq-card-img {\n width: 100%;\n max-height: 160px;\n object-fit: cover;\n display: block;\n}\n\n.biq-card-title {\n font-size: 14px;\n font-weight: 600;\n color: #fff;\n padding: 10px 12px 2px;\n line-height: 1.3;\n}\n\n.biq-card-subtitle {\n font-size: 12px;\n color: #9CA3AF;\n padding: 0 12px 6px;\n line-height: 1.4;\n}\n\n.biq-card-price {\n font-size: 14px;\n font-weight: 600;\n color: #F97316;\n padding: 4px 12px 8px;\n}\n\n.biq-card-btns {\n display: flex;\n flex-wrap: wrap;\n gap: 6px;\n padding: 0 10px 10px;\n}\n\n/* ── Carousel ────────────────────────────── */\n.biq-carousel {\n display: flex;\n flex-direction: row;\n gap: 10px;\n overflow-x: auto;\n padding-bottom: 4px;\n scrollbar-width: thin;\n scrollbar-color: #2D2D2D transparent;\n /* Snap cards into position on scroll */\n scroll-snap-type: x mandatory;\n}\n.biq-carousel::-webkit-scrollbar { height: 4px; }\n.biq-carousel::-webkit-scrollbar-track { background: transparent; }\n.biq-carousel::-webkit-scrollbar-thumb { background: #2D2D2D; border-radius: 2px; }\n\n.biq-carousel .biq-card {\n flex: 0 0 200px;\n scroll-snap-align: start;\n max-width: 200px;\n}\n\n/* ── Quick Replies ───────────────────────── */\n.biq-quick-replies {\n display: flex;\n flex-wrap: wrap;\n gap: 6px;\n margin-top: 4px;\n}\n\n.biq-qr-pill {\n padding: 5px 14px;\n border-radius: 20px;\n border: 1.5px solid #F97316;\n background: transparent;\n color: #F97316;\n font: inherit;\n font-size: 13px;\n cursor: pointer;\n transition: background .15s, color .15s;\n white-space: nowrap;\n}\n.biq-qr-pill:hover { background: #F97316; color: #fff; }\n\n/* ── Buttons block ───────────────────────── */\n.biq-buttons {\n display: flex;\n flex-wrap: wrap;\n gap: 6px;\n margin-top: 4px;\n}\n", pe = "\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";
517
+ function me(e) {
518
+ let { colors: t, layout: n, font: r, gradient: i, animation: a, customCSS: o, whiteLabel: s } = e, c = V[r] ?? V.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 = H(t.primary, i), h = H(t.header, i), g = H(t.userBubble, i), _ = s ? ".botiq-badge { display: none !important; }" : "";
519
+ return `
520
+ @import url('${c.url}');
521
+
522
+ :host {
523
+ position: fixed;
524
+ bottom: 24px;
525
+ ${u}
526
+ z-index: 2147483647;
527
+ display: block;
528
+ font-family: ${c.family};
529
+ --color-primary: ${t.primary};
530
+ --color-header: ${t.header};
531
+ --color-user: ${t.userBubble};
532
+ --color-bot: ${t.botBubble};
533
+ --color-bg: ${t.background};
534
+ --color-text: ${t.text};
535
+ --color-input-bg: ${t.inputBackground};
536
+ --gray-50: #1A1A1A;
537
+ --gray-100: #222222;
538
+ --gray-200: #2D2D2D;
539
+ --gray-400: #9CA3AF;
540
+ --shadow-sm: 0 2px 8px rgba(0,0,0,.4);
541
+ --shadow-md: 0 8px 32px rgba(0,0,0,.5);
542
+ --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
543
+ --radius-bubble: ${l};
544
+ --radius-msg: 18px;
545
+ --chat-w: ${n.width}px;
546
+ --chat-h: ${p};
547
+ }
548
+
549
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
550
+
551
+ /* ── Bubble ─────────────────────────────── */
552
+ .bubble {
553
+ width: 56px;
554
+ height: 56px;
555
+ border-radius: var(--radius-bubble);
556
+ background: ${m};
557
+ border: none;
558
+ cursor: pointer;
559
+ display: flex;
560
+ align-items: center;
561
+ justify-content: center;
562
+ box-shadow: var(--shadow-md);
563
+ transition: transform .2s ease, box-shadow .2s ease;
564
+ outline: none;
565
+ position: relative;
566
+ }
567
+
568
+ .bubble:hover { transform: scale(1.08); box-shadow: var(--shadow-lg); }
569
+ .bubble:active { transform: scale(0.96); }
570
+
571
+ .bubble svg { width: 26px; height: 26px; fill: #fff; transition: opacity .15s; }
572
+ .bubble .icon-chat { opacity: 1; }
573
+ .bubble .icon-close { opacity: 0; position: absolute; }
574
+ .bubble.open .icon-chat { opacity: 0; }
575
+ .bubble.open .icon-close { opacity: 1; }
576
+
577
+ .unread-badge {
578
+ position: absolute;
579
+ top: -2px;
580
+ right: -2px;
581
+ min-width: 18px;
582
+ height: 18px;
583
+ padding: 0 5px;
584
+ border-radius: 9px;
585
+ background: #EF4444;
586
+ color: #fff;
587
+ font-size: 11px;
588
+ font-weight: 600;
589
+ display: flex;
590
+ align-items: center;
591
+ justify-content: center;
592
+ pointer-events: none;
593
+ }
594
+
595
+ /* ── Chat Window ────────────────────────── */
596
+ .chat-window {
597
+ position: absolute;
598
+ bottom: 72px;
599
+ ${f}
600
+ width: var(--chat-w);
601
+ height: var(--chat-h);
602
+ background: var(--color-bg);
603
+ border-radius: 20px;
604
+ box-shadow: var(--shadow-lg);
605
+ display: flex;
606
+ flex-direction: column;
607
+ overflow: hidden;
608
+ transform-origin: ${d};
609
+ transform: scale(.94) translateY(8px);
610
+ opacity: 0;
611
+ pointer-events: none;
612
+ transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
613
+ }
614
+
615
+ .chat-window.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }
616
+
617
+ /* ── Header ─────────────────────────────── */
618
+ .chat-header {
619
+ background: ${h};
620
+ padding: 16px 16px 14px;
621
+ display: flex;
622
+ align-items: center;
623
+ gap: 10px;
624
+ flex-shrink: 0;
625
+ }
626
+
627
+ .avatar {
628
+ width: 36px;
629
+ height: 36px;
630
+ border-radius: 50%;
631
+ background: rgba(255,255,255,.2);
632
+ display: flex;
633
+ align-items: center;
634
+ justify-content: center;
635
+ flex-shrink: 0;
636
+ overflow: hidden;
637
+ }
638
+
639
+ .avatar svg { width: 20px; height: 20px; fill: #fff; }
640
+
641
+ .header-text { flex: 1; min-width: 0; }
642
+
643
+ .bot-name {
644
+ color: #fff;
645
+ font-weight: 600;
646
+ font-size: 15px;
647
+ line-height: 1.2;
648
+ display: block;
649
+ white-space: nowrap;
650
+ overflow: hidden;
651
+ text-overflow: ellipsis;
652
+ }
653
+
654
+ .bot-status { color: rgba(255,255,255,.75); font-size: 12px; display: block; margin-top: 1px; }
655
+
656
+ .close-btn {
657
+ width: 30px;
658
+ height: 30px;
659
+ border-radius: 50%;
660
+ background: rgba(255,255,255,.15);
661
+ border: none;
662
+ cursor: pointer;
663
+ color: #fff;
664
+ font-size: 18px;
665
+ display: flex;
666
+ align-items: center;
667
+ justify-content: center;
668
+ flex-shrink: 0;
669
+ transition: background .15s;
670
+ }
671
+ .close-btn:hover { background: rgba(255,255,255,.25); }
672
+
673
+ /* ── Chat body + panels ─────────────────── */
674
+ .chat-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
675
+
676
+ .panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
677
+ .panel.active { display: flex; }
678
+
679
+ /* ── Bottom nav ─────────────────────────── */
680
+ .bottom-nav {
681
+ display: flex;
682
+ border-top: 1px solid var(--gray-100);
683
+ flex-shrink: 0;
684
+ background: var(--color-bg);
685
+ }
686
+
687
+ .nav-btn {
688
+ flex: 1;
689
+ background: transparent;
690
+ border: none;
691
+ color: var(--gray-400);
692
+ font: inherit;
693
+ font-size: 12px;
694
+ padding: 10px;
695
+ cursor: pointer;
696
+ transition: color .15s;
697
+ }
698
+
699
+ .nav-btn:hover { color: var(--color-text); }
700
+ .nav-btn.active { color: var(--color-primary); }
701
+
702
+ /* ── Messages list panel ────────────────── */
703
+ .msg-list { flex: 1; overflow-y: auto; }
704
+
705
+ .msg-list-item {
706
+ display: flex;
707
+ align-items: flex-start;
708
+ gap: 10px;
709
+ width: 100%;
710
+ text-align: left;
711
+ padding: 12px 16px;
712
+ background: transparent;
713
+ border: none;
714
+ border-bottom: 1px solid var(--gray-100);
715
+ cursor: pointer;
716
+ font: inherit;
717
+ }
718
+
719
+ .msg-list-item:hover { background: var(--gray-50); }
720
+
721
+ .msg-list-avatar {
722
+ flex-shrink: 0;
723
+ width: 36px;
724
+ height: 36px;
725
+ border-radius: 50%;
726
+ overflow: hidden;
727
+ background: var(--color-primary);
728
+ display: flex;
729
+ align-items: center;
730
+ justify-content: center;
731
+ }
732
+
733
+ .msg-list-body {
734
+ flex: 1;
735
+ min-width: 0;
736
+ display: flex;
737
+ flex-direction: column;
738
+ gap: 2px;
739
+ }
740
+
741
+ .msg-list-title {
742
+ color: var(--color-text);
743
+ font-weight: 600;
744
+ font-size: 14px;
745
+ }
746
+
747
+ .msg-list-preview {
748
+ color: var(--gray-400);
749
+ font-size: 12px;
750
+ white-space: nowrap;
751
+ overflow: hidden;
752
+ text-overflow: ellipsis;
753
+ }
754
+
755
+ .msg-list-time { color: var(--gray-400); font-size: 10px; }
756
+
757
+ .msg-list-badge { color: var(--color-primary); font-size: 10px; }
758
+
759
+ .msg-list-empty {
760
+ padding: 24px;
761
+ text-align: center;
762
+ color: var(--gray-400);
763
+ font-size: 13px;
764
+ }
765
+
766
+ .msg-list-new {
767
+ margin: 10px 16px;
768
+ padding: 10px;
769
+ border-radius: 10px;
770
+ border: 1.5px solid var(--color-primary);
771
+ background: transparent;
772
+ color: var(--color-primary);
773
+ cursor: pointer;
774
+ font: inherit;
775
+ width: calc(100% - 32px);
776
+ }
777
+
778
+ .msg-list-new:hover { background: var(--color-primary); color: #fff; }
779
+
780
+ /* ── Home panel ─────────────────────────── */
781
+ .home-greeting {
782
+ font-size: 20px;
783
+ font-weight: 600;
784
+ color: var(--color-text);
785
+ padding: 24px 18px 8px;
786
+ }
787
+
788
+ .home-start {
789
+ margin: 8px 18px;
790
+ padding: 14px;
791
+ border-radius: 12px;
792
+ border: 1.5px solid var(--color-primary);
793
+ background: transparent;
794
+ color: var(--color-primary);
795
+ text-align: left;
796
+ cursor: pointer;
797
+ font: inherit;
798
+ font-size: 14px;
799
+ font-weight: 500;
800
+ transition: background .15s, color .15s;
801
+ }
802
+
803
+ .home-start:hover { background: var(--color-primary); color: #fff; }
804
+
805
+ .home-status { margin: 8px 18px; font-size: 12px; }
806
+ .home-status--online { color: #16A34A; }
807
+ .home-status--offline { color: var(--gray-400); }
808
+
809
+ /* ── Home recent conversations ──────────────── */
810
+ .home-recent-label {
811
+ margin: 16px 18px 6px;
812
+ font-size: 11px;
813
+ font-weight: 600;
814
+ text-transform: uppercase;
815
+ letter-spacing: .06em;
816
+ color: var(--gray-400);
817
+ }
818
+
819
+ .home-recent-item {
820
+ display: flex;
821
+ align-items: center;
822
+ gap: 10px;
823
+ width: 100%;
824
+ padding: 10px 18px;
825
+ background: transparent;
826
+ border: none;
827
+ border-bottom: 1px solid var(--gray-100);
828
+ cursor: pointer;
829
+ font: inherit;
830
+ text-align: left;
831
+ }
832
+
833
+ .home-recent-item:hover { background: var(--gray-50); }
834
+
835
+ .home-recent-avatar {
836
+ flex-shrink: 0;
837
+ width: 32px;
838
+ height: 32px;
839
+ border-radius: 50%;
840
+ overflow: hidden;
841
+ background: var(--color-primary);
842
+ display: flex;
843
+ align-items: center;
844
+ justify-content: center;
845
+ }
846
+
847
+ .home-recent-body { flex: 1; min-width: 0; }
848
+
849
+ .home-recent-title {
850
+ color: var(--color-text);
851
+ font-size: 13px;
852
+ font-weight: 500;
853
+ white-space: nowrap;
854
+ overflow: hidden;
855
+ text-overflow: ellipsis;
856
+ }
857
+
858
+ .home-recent-preview {
859
+ color: var(--gray-400);
860
+ font-size: 12px;
861
+ white-space: nowrap;
862
+ overflow: hidden;
863
+ text-overflow: ellipsis;
864
+ }
865
+
866
+ .home-recent-time { color: var(--gray-400); font-size: 10px; flex-shrink: 0; }
867
+
868
+ /* ── Messages ───────────────────────────── */
869
+ .messages {
870
+ flex: 1;
871
+ overflow-y: auto;
872
+ padding: 16px 14px;
873
+ display: flex;
874
+ flex-direction: column;
875
+ gap: 10px;
876
+ scroll-behavior: smooth;
877
+ }
878
+
879
+ .messages::-webkit-scrollbar { width: 4px; }
880
+ .messages::-webkit-scrollbar-track { background: transparent; }
881
+ .messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }
882
+
883
+ .message { display: flex; flex-direction: column; max-width: 82%; }
884
+ .message.user { align-self: flex-end; align-items: flex-end; }
885
+ .message.assistant { align-self: flex-start; align-items: flex-start; max-width: 92%; }
886
+
887
+ .message-bubble {
888
+ padding: 10px 14px;
889
+ border-radius: var(--radius-msg);
890
+ font-size: 14px;
891
+ line-height: 1.5;
892
+ white-space: normal;
893
+ word-break: break-word;
894
+ overflow-x: auto;
895
+ }
896
+
897
+ /* ── Markdown inline elements ───────────────────────── */
898
+ .message-bubble strong { font-weight: 600; }
899
+ .message-bubble em { font-style: italic; }
900
+ .message-bubble a { color: var(--color-primary); text-decoration: underline; word-break: break-all; }
901
+ .message-bubble code {
902
+ font-family: monospace;
903
+ font-size: 12px;
904
+ padding: 1px 5px;
905
+ border-radius: 4px;
906
+ background: rgba(255,255,255,.1);
907
+ white-space: pre-wrap;
908
+ }
909
+ .message-bubble del { text-decoration: line-through; opacity: .7; }
910
+
911
+ /* ── Markdown headings ───────────────────────────────── */
912
+ /* Kept modest — the chat bubble is small, so headings are only slightly
913
+ larger than body text, never document-sized. */
914
+ .message-bubble h1,
915
+ .message-bubble h2,
916
+ .message-bubble h3,
917
+ .message-bubble h4,
918
+ .message-bubble h5,
919
+ .message-bubble h6 {
920
+ margin: 8px 0 4px;
921
+ font-weight: 600;
922
+ line-height: 1.3;
923
+ color: #fff;
924
+ }
925
+ .message-bubble h1 { font-size: 16px; }
926
+ .message-bubble h2 { font-size: 15px; }
927
+ .message-bubble h3 { font-size: 14px; }
928
+ .message-bubble h4,
929
+ .message-bubble h5,
930
+ .message-bubble h6 { font-size: 13px; }
931
+ .message-bubble :first-child { margin-top: 0; }
932
+
933
+ /* ── Markdown horizontal rule ────────────────────────── */
934
+ .message-bubble hr {
935
+ border: 0;
936
+ height: 1px;
937
+ background: rgba(255,255,255,.15);
938
+ margin: 8px 0;
939
+ }
940
+
941
+ /* ── Markdown tables ─────────────────────────────────── */
942
+ .message-bubble table {
943
+ border-collapse: collapse;
944
+ min-width: 100%;
945
+ font-size: 12.5px;
946
+ display: block;
947
+ overflow-x: auto;
948
+ margin: 4px 0;
949
+ }
950
+ .message-bubble th,
951
+ .message-bubble td {
952
+ border: 1px solid rgba(255,255,255,.15);
953
+ padding: 5px 10px;
954
+ text-align: left;
955
+ }
956
+ .message-bubble th { background: rgba(255,255,255,.08); font-weight: 600; white-space: nowrap; }
957
+ .message-bubble td { white-space: normal; }
958
+ .message-bubble tr:nth-child(even) td { background: rgba(255,255,255,.04); }
959
+
960
+ /* ── Markdown lists ──────────────────────────────────── */
961
+ .message-bubble ul,
962
+ .message-bubble ol { padding-left: 18px; margin: 2px 0; }
963
+ .message-bubble li { margin: 2px 0; }
964
+
965
+ .message.user .message-bubble {
966
+ background: ${g};
967
+ color: #fff;
968
+ border-bottom-right-radius: 4px;
969
+ white-space: pre-wrap;
970
+ }
971
+
972
+ .message.assistant .message-bubble {
973
+ background: var(--color-bot);
974
+ color: var(--color-text);
975
+ border-bottom-left-radius: 4px;
976
+ }
977
+
978
+ /* ── Message Metadata + Day Separators ──── */
979
+ .msg-meta {
980
+ font-size: 10px;
981
+ color: var(--gray-400);
982
+ margin-top: 3px;
983
+ padding: 0 2px;
984
+ }
985
+ .day-sep {
986
+ display: flex;
987
+ align-items: center;
988
+ justify-content: center;
989
+ margin: 6px 0 2px;
990
+ }
991
+ .day-sep span {
992
+ font-size: 10px;
993
+ color: var(--gray-400);
994
+ background: var(--gray-50);
995
+ padding: 2px 10px;
996
+ border-radius: 10px;
997
+ }
998
+
999
+ /* ── Error Bubble + Retry Button ────────── */
1000
+ .message.error .message-bubble { border: 1px solid #DC2626; }
1001
+ .retry-btn {
1002
+ margin-top: 4px;
1003
+ align-self: flex-start;
1004
+ font-size: 12px;
1005
+ font-family: inherit;
1006
+ color: var(--color-primary);
1007
+ background: transparent;
1008
+ border: 1px solid var(--color-primary);
1009
+ border-radius: 12px;
1010
+ padding: 3px 10px;
1011
+ cursor: pointer;
1012
+ }
1013
+ .retry-btn:hover { background: var(--color-primary); color: #fff; }
1014
+ .msg-contact { font-size: 11px; color: var(--gray-400); margin-top: 3px; }
1015
+
1016
+ /* ── Typing Indicator ───────────────────── */
1017
+ .typing {
1018
+ display: flex;
1019
+ align-items: center;
1020
+ gap: 4px;
1021
+ padding: 12px 14px;
1022
+ background: var(--color-bot);
1023
+ border-radius: var(--radius-msg);
1024
+ border-bottom-left-radius: 4px;
1025
+ align-self: flex-start;
1026
+ width: fit-content;
1027
+ }
1028
+
1029
+ .typing span {
1030
+ width: 7px;
1031
+ height: 7px;
1032
+ border-radius: 50%;
1033
+ background: var(--color-primary);
1034
+ opacity: 0.5;
1035
+ animation: bounce 1.2s infinite ease-in-out;
1036
+ }
1037
+
1038
+ .typing span:nth-child(2) { animation-delay: .2s; }
1039
+ .typing span:nth-child(3) { animation-delay: .4s; }
1040
+
1041
+ @keyframes bounce {
1042
+ 0%, 60%, 100% { transform: translateY(0); }
1043
+ 30% { transform: translateY(-6px); }
1044
+ }
1045
+
1046
+ /* ── Empty / Greeting State ─────────────── */
1047
+ .empty-state {
1048
+ flex: 1;
1049
+ display: flex;
1050
+ flex-direction: column;
1051
+ align-items: center;
1052
+ justify-content: center;
1053
+ gap: 8px;
1054
+ color: var(--gray-400);
1055
+ font-size: 13px;
1056
+ text-align: center;
1057
+ padding: 24px;
1058
+ }
1059
+
1060
+ .empty-state svg { width: 40px; height: 40px; fill: var(--gray-200); margin-bottom: 4px; }
1061
+ .empty-state .greeting { color: var(--color-text); font-size: 13px; opacity: 0.7; }
1062
+
1063
+ /* ── Suggestion Chips ───────────────────── */
1064
+ .chips {
1065
+ display: flex;
1066
+ flex-wrap: wrap;
1067
+ gap: 6px;
1068
+ justify-content: center;
1069
+ margin-top: 4px;
1070
+ }
1071
+
1072
+ .chip {
1073
+ padding: 5px 12px;
1074
+ border-radius: 16px;
1075
+ border: 1.5px solid var(--color-primary);
1076
+ color: var(--color-primary);
1077
+ background: transparent;
1078
+ font-size: 12px;
1079
+ font-family: inherit;
1080
+ cursor: pointer;
1081
+ transition: background .15s, color .15s;
1082
+ }
1083
+
1084
+ .chip:hover {
1085
+ background: var(--color-primary);
1086
+ color: #fff;
1087
+ }
1088
+
1089
+ /* ── Handoff Banner ─────────────────────── */
1090
+ .handoff-banner {
1091
+ margin: 6px 14px;
1092
+ padding: 6px 10px;
1093
+ border-radius: 8px;
1094
+ background: rgba(249,115,22,.12);
1095
+ color: var(--color-primary);
1096
+ font-size: 12px;
1097
+ text-align: center;
1098
+ }
1099
+
1100
+ /* ── Footer / Input ─────────────────────── */
1101
+ .chat-footer {
1102
+ border-top: 1px solid var(--gray-100);
1103
+ padding: 10px 12px;
1104
+ background: var(--color-bg);
1105
+ flex-shrink: 0;
1106
+ }
1107
+
1108
+ .input-row { display: flex; align-items: flex-end; gap: 8px; }
1109
+
1110
+ /* Subtle attribution — half-opacity, hover lifts to full. Doesn't steal focus
1111
+ from tenant branding but reminds the customer this is powered by BotIQ. */
1112
+ .botiq-badge {
1113
+ display: block;
1114
+ text-align: center;
1115
+ font-size: 10px;
1116
+ font-weight: 400;
1117
+ color: var(--color-text);
1118
+ opacity: 0.4;
1119
+ text-decoration: none;
1120
+ margin-top: 6px;
1121
+ letter-spacing: 0.02em;
1122
+ transition: opacity .15s;
1123
+ }
1124
+ .botiq-badge:hover { opacity: 0.85; }
1125
+ .botiq-badge-name { font-weight: 600; color: var(--color-primary); }
1126
+
1127
+ .input {
1128
+ flex: 1;
1129
+ min-height: 38px;
1130
+ max-height: 100px;
1131
+ border: 1.5px solid var(--gray-200);
1132
+ border-radius: 12px;
1133
+ padding: 9px 12px;
1134
+ font-family: inherit;
1135
+ font-size: 14px;
1136
+ color: var(--color-text);
1137
+ resize: none;
1138
+ outline: none;
1139
+ background: var(--color-input-bg);
1140
+ line-height: 1.4;
1141
+ overflow-y: auto;
1142
+ transition: border-color .15s;
1143
+ }
1144
+
1145
+ .input:focus { border-color: var(--color-primary); background: var(--color-input-bg); }
1146
+ .input::placeholder { color: var(--gray-400); }
1147
+
1148
+ .send-btn {
1149
+ width: 38px;
1150
+ height: 38px;
1151
+ border-radius: 10px;
1152
+ background: ${m};
1153
+ border: none;
1154
+ cursor: pointer;
1155
+ display: flex;
1156
+ align-items: center;
1157
+ justify-content: center;
1158
+ flex-shrink: 0;
1159
+ transition: filter .15s, transform .1s;
1160
+ }
1161
+
1162
+ .send-btn:hover { filter: brightness(0.88); }
1163
+ .send-btn:active { transform: scale(0.94); }
1164
+ .send-btn:disabled { background: var(--gray-200); cursor: not-allowed; filter: none; }
1165
+ .send-btn svg { width: 18px; height: 18px; fill: #fff; }
1166
+
1167
+ /* ── Attach Button ──────────────────────── */
1168
+ .attach-btn {
1169
+ width: 34px; height: 38px;
1170
+ background: transparent; border: none; cursor: pointer;
1171
+ color: var(--gray-400); flex-shrink: 0;
1172
+ display: flex; align-items: center; justify-content: center;
1173
+ border-radius: 8px; transition: color .15s, background .15s;
1174
+ }
1175
+ .attach-btn:hover { color: var(--color-primary); background: rgba(249,115,22,.08); }
1176
+ .attach-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
1177
+
1178
+ /* ── Attach Preview Slot ────────────────── */
1179
+ .attach-preview-slot {
1180
+ margin-bottom: 6px;
1181
+ }
1182
+
1183
+ .attach-preview {
1184
+ display: flex;
1185
+ align-items: center;
1186
+ gap: 8px;
1187
+ padding: 6px 8px;
1188
+ background: var(--gray-50);
1189
+ border: 1px solid var(--gray-200);
1190
+ border-radius: 10px;
1191
+ position: relative;
1192
+ }
1193
+
1194
+ .attach-preview-img {
1195
+ width: 48px;
1196
+ height: 48px;
1197
+ object-fit: cover;
1198
+ border-radius: 6px;
1199
+ flex-shrink: 0;
1200
+ }
1201
+
1202
+ .attach-preview-img--uploading {
1203
+ opacity: 0.5;
1204
+ }
1205
+
1206
+ .attach-preview-status {
1207
+ font-size: 12px;
1208
+ color: var(--gray-400);
1209
+ flex: 1;
1210
+ }
1211
+
1212
+ .attach-preview-error {
1213
+ font-size: 12px;
1214
+ color: #DC2626;
1215
+ flex: 1;
1216
+ }
1217
+
1218
+ .attach-preview-remove {
1219
+ width: 22px; height: 22px;
1220
+ border-radius: 50%;
1221
+ background: var(--gray-200);
1222
+ border: none;
1223
+ cursor: pointer;
1224
+ color: var(--color-text);
1225
+ font-size: 14px;
1226
+ line-height: 1;
1227
+ display: flex; align-items: center; justify-content: center;
1228
+ flex-shrink: 0;
1229
+ transition: background .15s;
1230
+ }
1231
+ .attach-preview-remove:hover { background: #DC2626; color: #fff; }
1232
+
1233
+ .emoji-btn {
1234
+ width: 34px; height: 38px;
1235
+ background: transparent; border: none; cursor: pointer;
1236
+ font-size: 18px; line-height: 1; flex-shrink: 0;
1237
+ }
1238
+ .emoji-panel {
1239
+ display: grid;
1240
+ grid-template-columns: repeat(8, 1fr);
1241
+ gap: 2px;
1242
+ margin-top: 8px;
1243
+ max-height: 140px;
1244
+ overflow-y: auto;
1245
+ }
1246
+ .emoji-panel[hidden] { display: none; }
1247
+ .emoji-item {
1248
+ background: transparent; border: none; cursor: pointer;
1249
+ font-size: 18px; padding: 4px; border-radius: 6px;
1250
+ }
1251
+ .emoji-item:hover { background: var(--gray-100); }
1252
+
1253
+ ${_}
1254
+ ${de(a)}
1255
+ ${o ? ue(o) : ""}
1256
+ ${pe}
1257
+ ${fe}
1258
+ @media (max-width: 480px) {
1259
+ :host { bottom: 0; right: 0; left: 0; }
1260
+ .chat-window {
1261
+ width: 100vw;
1262
+ height: 100dvh;
1263
+ bottom: 0;
1264
+ right: 0;
1265
+ left: 0;
1266
+ border-radius: 0;
1267
+ }
1268
+ .bubble { position: fixed; bottom: 16px; right: 16px; }
1269
+ }
1270
+ `;
1271
+ }
1272
+ //#endregion
1273
+ //#region src/core/timeago.ts
1274
+ function U(e) {
1275
+ return String(e).padStart(2, "0");
1276
+ }
1277
+ function W(e, t, n) {
1278
+ let r = Math.max(0, Math.floor((t - e) / 1e3));
1279
+ if (r < 60) return n === "vi" ? "vừa xong" : "just now";
1280
+ let i = Math.floor(r / 60);
1281
+ if (i < 60) return n === "vi" ? `${i} phút` : `${i} min`;
1282
+ let a = new Date(e);
1283
+ return `${U(a.getHours())}:${U(a.getMinutes())}`;
1284
+ }
1285
+ function he(e, t, n) {
1286
+ let r = (e) => {
1287
+ let t = new Date(e);
1288
+ return new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime();
1289
+ }, i = Math.round((r(t) - r(e)) / 864e5);
1290
+ if (i <= 0) return n === "vi" ? "Hôm nay" : "Today";
1291
+ if (i === 1) return n === "vi" ? "Hôm qua" : "Yesterday";
1292
+ let a = new Date(e);
1293
+ return `${U(a.getDate())}/${U(a.getMonth() + 1)}/${a.getFullYear()}`;
1294
+ }
1295
+ //#endregion
1296
+ //#region src/core/views.ts
1297
+ function G(e) {
1298
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1299
+ }
1300
+ function ge(e, t, n, r = "") {
1301
+ let i = `<button class="msg-list-new" type="button">+ ${G(t.newConversation)}</button>`;
1302
+ return e.length === 0 ? `<div class="msg-list-empty">${G(t.noConversations)}</div>${i}` : `<div class="msg-list">${e.map((e) => {
1303
+ let i = e.lastMessageAt ? Date.parse(e.lastMessageAt) : n, a = Number.isFinite(i) ? W(i, n, "vi") : "", o = e.escalated ? `<span class="msg-list-badge">${G(t.waitingForHuman)}</span>` : "";
1304
+ return `<button class="msg-list-item" type="button" data-session="${G(e.sessionId)}">
1305
+ ${r ? `<div class="msg-list-avatar">${r}</div>` : ""}
1306
+ <div class="msg-list-body">
1307
+ <span class="msg-list-title">${G(e.title)}</span>
1308
+ <span class="msg-list-preview">${G(e.preview)}</span>
1309
+ <span class="msg-list-time">${G(a)}</span>${o}
1310
+ </div>
1311
+ </button>`;
1312
+ }).join("")}</div>${i}`;
1313
+ }
1314
+ function _e(e, t, n = [], r = "", i = Date.now()) {
1315
+ let a = e.status !== "offline", o = a ? t.statusOnline : t.statusPaused, s = G(e.design.content.greeting || t.homeGreeting), c = "";
1316
+ if (n.length > 0) {
1317
+ let e = n.slice(0, 3).map((e) => {
1318
+ let t = e.lastMessageAt ? Date.parse(e.lastMessageAt) : i, n = Number.isFinite(t) ? W(t, i, "vi") : "";
1319
+ return `<button class="home-recent-item" type="button" data-session="${G(e.sessionId)}">
1320
+ ${r ? `<div class="home-recent-avatar">${r}</div>` : ""}
1321
+ <div class="home-recent-body">
1322
+ <div class="home-recent-title">${G(e.title)}</div>
1323
+ <div class="home-recent-preview">${G(e.preview)}</div>
1324
+ </div>
1325
+ <span class="home-recent-time">${G(n)}</span>
1326
+ </button>`;
1327
+ }).join("");
1328
+ c = `<div class="home-recent-label">${G(t.recentMessages)}</div>${e}`;
1329
+ }
1330
+ return `
1331
+ <div class="home-greeting">${s}</div>
1332
+ <button class="home-start" type="button">${G(t.startConversation)} ›</button>
1333
+ ${c}
1334
+ <div class="home-status home-status--${a ? "online" : "offline"}">● ${G(o)}</div>
1335
+ `;
1336
+ }
1337
+ //#endregion
1338
+ //#region src/core/assets.ts
1339
+ var ve = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABL8SURBVHhe7ZsJjJzlecchbZo2aRPwScFAfM29s3N9M9/cO7O7c+zOzr0ze8ze3tN7+1yvD8Be29iYmEIrlaIaRIIIDW1URRE9BFFpAlXLYZNKxFLVVL1Q0yZSgCJhw7963u/7Zr95dyCtuuuDzCP99V0z7/c8v/d5nvedlX3LLTWrWc1qVrOa1axmNatZzWpWs5rV7Jrbc8899/nz588bz5w5lz219ODCyROnHz3xwNLTS8dPPk868cDSN5aOn3rs5ImTB8+ePps7f/a8kb7Dj/NLZadPn/7yw2cfzj146syF+48ev7y4cARHD9+PI4v3Y3HhGBYOHMHB/YeZ6Hxx4SiOLN7HRM+P37d0+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H/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=";
1340
+ //#endregion
1341
+ //#region src/core/history-pager.ts
1342
+ function K() {
1343
+ return {
1344
+ oldestCursor: null,
1345
+ hasMore: !1,
1346
+ cursorReady: !1
1347
+ };
1348
+ }
1349
+ function ye(e) {
1350
+ return {
1351
+ oldestCursor: e.messages[0]?.id ?? null,
1352
+ hasMore: e.hasMore,
1353
+ cursorReady: e.messages.length > 0
1354
+ };
1355
+ }
1356
+ function be(e, t) {
1357
+ return {
1358
+ oldestCursor: t.messages[0]?.id ?? e.oldestCursor,
1359
+ hasMore: t.hasMore,
1360
+ cursorReady: e.cursorReady
1361
+ };
1362
+ }
1363
+ function xe(e, t) {
1364
+ return e.cursorReady && e.hasMore && !t && e.oldestCursor !== null;
1365
+ }
1366
+ function Se(e, t, n) {
1367
+ return e + (n - t);
1368
+ }
1369
+ //#endregion
1370
+ //#region src/core/confirm-dialog.ts
1371
+ function q(e) {
1372
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
1373
+ }
1374
+ function Ce(e, t) {
1375
+ 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…";
1376
+ return new Promise((o) => {
1377
+ let s = document.createElement("div");
1378
+ s.className = "botiq-confirm-overlay", s.innerHTML = `
1379
+ <div class="botiq-confirm-dialog" role="dialog" aria-modal="true">
1380
+ <div class="botiq-confirm-header">${q(t.title)}</div>
1381
+ <div class="botiq-confirm-body">
1382
+ <div class="botiq-confirm-reason">${q(t.reason)}</div>
1383
+ <pre class="botiq-confirm-params">${q(t.paramsDisplay)}</pre>
1384
+ </div>
1385
+ <div class="botiq-confirm-actions">
1386
+ <button class="botiq-confirm-yes" data-risk="${t.riskLevel}" type="button">${q(n)}</button>
1387
+ <button class="botiq-confirm-no" type="button">${q(r)}</button>
1388
+ </div>
1389
+ ${t.autoConfirmAfterSec ? `<div class="botiq-confirm-countdown">${q(i)}<span class="botiq-confirm-secs">${t.autoConfirmAfterSec}</span>${q(a)}</div>` : ""}
1390
+ </div>`, e.appendChild(s);
1391
+ let c = !1, l = null, u = (t) => {
1392
+ c || (c = !0, l && clearInterval(l), e.removeChild(s), o(t));
1393
+ };
1394
+ if (s.querySelector(".botiq-confirm-yes").addEventListener("click", () => u(!0)), s.querySelector(".botiq-confirm-no").addEventListener("click", () => u(!1)), t.autoConfirmAfterSec && t.autoConfirmAfterSec > 0) {
1395
+ let e = t.autoConfirmAfterSec, n = s.querySelector(".botiq-confirm-secs");
1396
+ l = setInterval(() => {
1397
+ --e, n && (n.textContent = String(e)), e <= 0 && u(!0);
1398
+ }, 1e3);
1399
+ }
1400
+ });
1401
+ }
1402
+ //#endregion
1403
+ //#region src/core/emoji.ts
1404
+ function we(e, t) {
1405
+ let n = e.selectionStart ?? e.value.length, r = e.selectionEnd ?? e.value.length;
1406
+ 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 }));
1407
+ }
1408
+ var J = null;
1409
+ async function Te() {
1410
+ return J || (J = (await import("./emoji-data-DWiYsBZI.js")).EMOJIS, J);
1411
+ }
1412
+ function Ee(e) {
1413
+ let t = document.createElement("button");
1414
+ t.type = "button", t.className = "emoji-btn", t.setAttribute("aria-label", "Emoji"), t.textContent = "🙂";
1415
+ let n = document.createElement("div");
1416
+ n.className = "emoji-panel", n.hidden = !0;
1417
+ let r = !1;
1418
+ return t.addEventListener("click", async () => {
1419
+ if (!r) {
1420
+ let t = await Te();
1421
+ for (let r of t) {
1422
+ let t = document.createElement("button");
1423
+ t.type = "button", t.className = "emoji-item", t.textContent = r, t.addEventListener("click", () => {
1424
+ e(r), n.hidden = !0;
1425
+ }), n.appendChild(t);
1426
+ }
1427
+ r = !0;
1428
+ }
1429
+ n.hidden = !n.hidden;
1430
+ }), {
1431
+ button: t,
1432
+ panel: n
1433
+ };
1434
+ }
1435
+ //#endregion
1436
+ //#region src/core/blocks-renderer.ts
1437
+ function Y(e) {
1438
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
1439
+ }
1440
+ function X(e) {
1441
+ return /^https?:\/\//i.test(e) ? e : "";
1442
+ }
1443
+ function De(e) {
1444
+ let t = Y(e.label), n = Y(e.value), r = Y(e.action);
1445
+ if (e.action === "url") {
1446
+ let n = X(e.value);
1447
+ return n ? `<a class="biq-btn biq-btn--url" href="${Y(n)}" target="_blank" rel="noopener noreferrer">${t}</a>` : "";
1448
+ }
1449
+ return `<button class="biq-btn biq-btn--${r}" type="button" data-action="${r}" data-value="${n}">${t}</button>`;
1450
+ }
1451
+ function Oe(e) {
1452
+ let t = `${e.imageUrl ? (() => {
1453
+ let t = X(e.imageUrl);
1454
+ return t ? `<img class="biq-card-img" src="${Y(t)}" alt="" loading="lazy" />` : "";
1455
+ })() : ""}${`<div class="biq-card-title">${Y(e.title)}</div>`}${e.subtitle ? `<div class="biq-card-subtitle">${Y(e.subtitle)}</div>` : ""}${e.price ? `<div class="biq-card-price">${Y(e.price)}</div>` : ""}${e.buttons && e.buttons.length > 0 ? `<div class="biq-card-btns">${e.buttons.map(De).join("")}</div>` : ""}`;
1456
+ if (e.url) {
1457
+ let n = X(e.url);
1458
+ if (n) return `<a class="biq-card biq-card--link" href="${Y(n)}" target="_blank" rel="noopener noreferrer">${t}</a>`;
1459
+ }
1460
+ return `<div class="biq-card">${t}</div>`;
1461
+ }
1462
+ function ke(e) {
1463
+ return `<div class="biq-carousel">${e.cards.map(Oe).join("")}</div>`;
1464
+ }
1465
+ function Ae(e) {
1466
+ return `<div class="biq-quick-replies">${e.replies.map((e) => {
1467
+ let t = Y(e.label);
1468
+ return `<button class="biq-qr-pill" type="button" data-qr="1" data-value="${Y(e.value)}">${t}</button>`;
1469
+ }).join("")}</div>`;
1470
+ }
1471
+ function je(e) {
1472
+ return `<div class="biq-buttons">${e.buttons.map(De).join("")}</div>`;
1473
+ }
1474
+ function Me(e) {
1475
+ return !e || e.length === 0 ? "" : e.map((e) => {
1476
+ switch (e.type) {
1477
+ case "card": return Oe(e);
1478
+ case "carousel": return ke(e);
1479
+ case "quick_replies": return Ae(e);
1480
+ case "buttons": return je(e);
1481
+ default: return "";
1482
+ }
1483
+ }).join("");
1484
+ }
1485
+ //#endregion
1486
+ //#region src/core/ui.ts
1487
+ var Ne = "https://bot-q-frontend.vercel.app/", Pe = "<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>", Fe = "<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>", Ie = `<img src="${ve}" alt="" style="width:100%;height:100%;object-fit:cover;border-radius:50%" />`, Le = "<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>", Re = "<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>", ze = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48\"/>\n</svg>";
1488
+ function Be(e) {
1489
+ if (!e || e.type === "icon") return Ie;
1490
+ 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%">${Z(e.value)}</span>`;
1491
+ if (e.type === "initials") {
1492
+ let t = e.bgColor ?? "#F97316";
1493
+ 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">${Z(e.value.slice(0, 2).toUpperCase())}</div>`;
1494
+ }
1495
+ return e.type === "image" ? `<img src="${Z(e.value)}" style="width:100%;height:100%;object-fit:cover;border-radius:50%" alt="" />` : Ie;
1496
+ }
1497
+ function Z(e) {
1498
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
1499
+ }
1500
+ function Q(e) {
1501
+ let t = [];
1502
+ 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;
1503
+ }
1504
+ function Ve(e) {
1505
+ return /^\|[\s\-:|]+\|$/.test(e);
1506
+ }
1507
+ function He(e) {
1508
+ return e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim());
1509
+ }
1510
+ function Ue(e, t) {
1511
+ return e ? `<div class="handoff-banner">⏳ ${Z(t.waitingForHuman)}</div>` : "";
1512
+ }
1513
+ function We(e) {
1514
+ return e <= 0 ? "" : `<span class="unread-badge">${e > 9 ? "9+" : String(e)}</span>`;
1515
+ }
1516
+ function Ge(e) {
1517
+ let t = Z(e).replace(/\x00/g, "").split("\n"), n = [], r = 0;
1518
+ for (; r < t.length;) {
1519
+ let e = t[r].trim();
1520
+ if (e.startsWith("|") && e.endsWith("|")) {
1521
+ let e = [];
1522
+ for (; r < t.length && t[r].trim().startsWith("|") && t[r].trim().endsWith("|");) e.push(t[r].trim()), r++;
1523
+ let i = e.findIndex(Ve), a = i > 0 ? e.slice(0, i) : [], o = i >= 0 ? e.slice(i + 1) : e, s = "<table>";
1524
+ a.length > 0 && (s += "<thead>" + a.map((e) => "<tr>" + He(e).map((e) => `<th>${Q(e)}</th>`).join("") + "</tr>").join("") + "</thead>"), o.length > 0 && (s += "<tbody>" + o.map((e) => "<tr>" + He(e).map((e) => `<td>${Q(e)}</td>`).join("") + "</tr>").join("") + "</tbody>"), s += "</table>", n.push(s);
1525
+ continue;
1526
+ }
1527
+ if (/^-{3,}$/.test(e)) {
1528
+ n.push("<hr>"), r++;
1529
+ continue;
1530
+ }
1531
+ let i = e.match(/^(#{1,6})\s+(.*)$/);
1532
+ if (i) {
1533
+ let e = i[1].length;
1534
+ n.push(`<h${e}>${Q(i[2])}</h${e}>`), r++;
1535
+ continue;
1536
+ }
1537
+ if (/^[-*]\s/.test(e)) {
1538
+ let e = [];
1539
+ for (; r < t.length && /^\s*[-*]\s/.test(t[r]);) e.push(t[r].trim().replace(/^[-*]\s+/, "")), r++;
1540
+ n.push("<ul>" + e.map((e) => `<li>${Q(e)}</li>`).join("") + "</ul>");
1541
+ continue;
1542
+ }
1543
+ if (/^\d+\.\s/.test(e)) {
1544
+ let e = [];
1545
+ for (; r < t.length && /^\s*\d+\.\s/.test(t[r]);) e.push(t[r].trim().replace(/^\d+\.\s+/, "")), r++;
1546
+ n.push("<ol>" + e.map((e) => `<li>${Q(e)}</li>`).join("") + "</ol>");
1547
+ continue;
1548
+ }
1549
+ if (e === "") {
1550
+ n.push("<br>"), r++;
1551
+ continue;
1552
+ }
1553
+ n.push(Q(e)), n.push("<br>"), r++;
1554
+ }
1555
+ for (; n.length > 0 && n[n.length - 1] === "<br>";) n.pop();
1556
+ return n.join("");
1557
+ }
1558
+ function Ke(e, t) {
1559
+ let { strings: n, content: r, botName: i, lang: a, now: o, contactInfo: s, richMessages: c } = t;
1560
+ if (e.messages.length === 0 && !e.isLoading) {
1561
+ let e = r.suggestionChips.length > 0 ? `<div class="chips">${r.suggestionChips.map((e) => `<button class="chip">${Z(e)}</button>`).join("")}</div>` : "";
1562
+ return `
1563
+ <div class="empty-state">
1564
+ ${Re}
1565
+ <span class="greeting">${Z(r.greeting || n.defaultGreeting)}</span>
1566
+ ${e}
1567
+ </div>
1568
+ `;
1569
+ }
1570
+ let l = "", u = e.messages.map((e) => {
1571
+ let t = e.ts ?? o, r = he(t, o, a), u = r === l ? "" : `<div class="day-sep"><span>${Z(r)}</span></div>`;
1572
+ l = r;
1573
+ let d = e.role === "assistant" ? Ge(e.content) : Z(e.content), f = e.role === "assistant" && !e.error ? `<div class="msg-meta">${Z(i)} · ${Z(W(t, o, a))}</div>` : "", p = e.error ? `<button class="retry-btn" type="button">↻ ${Z(n.retry)}</button>` : "", m = e.error && s ? `<div class="msg-contact">${Z(s)}</div>` : "", h = c && e.role === "assistant" && !e.error && e.blocks && e.blocks.length > 0 ? `<div class="biq-blocks">${Me(e.blocks)}</div>` : "";
1574
+ return `${u}<div class="${`message ${e.role}${e.error ? " error" : ""}`}"><div class="message-bubble">${d}</div>${p}${m}${f}${h}</div>`;
1575
+ }).join(""), d = e.loadingOlder ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "", f = e.isLoading ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "";
1576
+ return d + u + f;
1577
+ }
1578
+ function qe(e, t, n, r) {
1579
+ let { name: i, design: a } = t, o, s, c, l, u, d, f, p, m, h, g, _, v = null, y = null, b = null, { content: x } = a, S = t.imageInput === !0, C = Be(a.avatar), w = null;
1580
+ function T(e) {
1581
+ e.setAttribute("data-position", a.layout.position), o = e.attachShadow({ mode: "closed" });
1582
+ let w = document.createElement("style");
1583
+ w.textContent = me(a), o.appendChild(w), s = document.createElement("button"), s.className = "bubble", s.setAttribute("aria-label", n.ariaOpenChat), s.innerHTML = `
1584
+ <span class="icon-chat">${Pe}</span>
1585
+ <span class="icon-close">${Fe}</span>
1586
+ <span class="unread-badge-slot"></span>
1587
+ `, 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 = `
1588
+ <div class="chat-header">
1589
+ <div class="avatar">${Be(a.avatar)}</div>
1590
+ <div class="header-text">
1591
+ <span class="bot-name">${Z(i)}</span>
1592
+ <span class="bot-status">${Z(n.statusOnline)}</span>
1593
+ </div>
1594
+ <button class="close-btn" aria-label="${Z(n.ariaCloseChat)}">×</button>
1595
+ </div>
1596
+ <div class="chat-body">
1597
+ <div class="panel panel-home"></div>
1598
+ <div class="panel panel-messages"></div>
1599
+ <div class="panel panel-conversation">
1600
+ <div class="messages" id="messages-container" role="log" aria-live="polite" aria-atomic="false"></div>
1601
+ <div class="handoff-slot"></div>
1602
+ <div class="chat-footer">
1603
+ <div class="attach-preview-slot"></div>
1604
+ <div class="input-row">
1605
+ ${S ? `<button class="attach-btn" type="button" aria-label="${Z(n.imageAttach)}">${ze}</button>` : ""}
1606
+ <textarea
1607
+ class="input"
1608
+ placeholder="${Z(x.placeholder || n.inputPlaceholder)}"
1609
+ rows="1"
1610
+ maxlength="2000"
1611
+ aria-label="Message input"
1612
+ ></textarea>
1613
+ <button class="send-btn" aria-label="${Z(n.ariaSendMessage)}">
1614
+ ${Le}
1615
+ </button>
1616
+ </div>
1617
+ <a class="botiq-badge" href="${Ne}" target="_blank" rel="noopener noreferrer">
1618
+ ${Z(n.poweredBy)} <span class="botiq-badge-name">BotIQ</span>
1619
+ </a>
1620
+ </div>
1621
+ </div>
1622
+ </div>
1623
+ <div class="bottom-nav">
1624
+ <button class="nav-btn" data-view="home">⌂ ${Z(n.navHome)}</button>
1625
+ <button class="nav-btn" data-view="messages">💬 ${Z(n.navMessages)}</button>
1626
+ </div>
1627
+ `, 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 = _e(t, n, [], C), l.querySelector(".home-start")?.addEventListener("click", () => {
1628
+ r.onNewConversation();
1629
+ }), f = c.querySelector(".nav-btn[data-view=\"home\"]"), p = c.querySelector(".nav-btn[data-view=\"messages\"]"), c.querySelectorAll(".nav-btn").forEach((e) => {
1630
+ e.addEventListener("click", () => {
1631
+ let t = e.dataset.view;
1632
+ r.onNavigate(t);
1633
+ });
1634
+ }), m = c.querySelector("#messages-container"), h = c.querySelector(".handoff-slot");
1635
+ let T = null;
1636
+ m.addEventListener("scroll", () => {
1637
+ m.scrollTop <= 48 && !T && (T = setTimeout(() => {
1638
+ T = null;
1639
+ }, 150), r.onScrollTop());
1640
+ }), g = c.querySelector(".input"), _ = c.querySelector(".send-btn"), g.addEventListener("input", () => {
1641
+ g.style.height = "auto", g.style.height = Math.min(g.scrollHeight, 100) + "px";
1642
+ }), g.addEventListener("keydown", (e) => {
1643
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), E());
1644
+ }), _.addEventListener("click", E);
1645
+ let D = c.querySelector(".input-row"), { button: O, panel: k } = Ee((e) => {
1646
+ we(g, e), g.focus();
1647
+ });
1648
+ D.insertBefore(O, _), c.querySelector(".chat-footer").appendChild(k), y = c.querySelector(".attach-preview-slot"), S && (v = c.querySelector(".attach-btn"), v && (b = document.createElement("input"), b.type = "file", b.accept = "image/jpeg,image/png,image/webp", b.style.display = "none", b.setAttribute("aria-hidden", "true"), o.appendChild(b), v.addEventListener("click", () => {
1649
+ b?.click();
1650
+ }), b.addEventListener("change", () => {
1651
+ let e = b?.files?.[0];
1652
+ e && r.onAttachImage && (r.onAttachImage(e), b && (b.value = ""));
1653
+ }))), o.appendChild(c);
1654
+ }
1655
+ function E() {
1656
+ let e = g.value.trim();
1657
+ !e && !y?.querySelector(".attach-preview") || _.disabled || (g.value = "", g.style.height = "auto", r.onSend(e));
1658
+ }
1659
+ function D(e) {
1660
+ let a = m.scrollHeight - m.scrollTop - m.clientHeight < 80, o = m.scrollTop, s = m.scrollHeight;
1661
+ m.innerHTML = Ke(e, {
1662
+ strings: n,
1663
+ content: x,
1664
+ botName: i,
1665
+ lang: t.widgetLanguage,
1666
+ now: Date.now(),
1667
+ contactInfo: t.contactInfo,
1668
+ richMessages: t.richMessages
1669
+ }), m.querySelectorAll(".chip").forEach((e) => {
1670
+ e.addEventListener("click", () => r.onSend(e.textContent ?? ""));
1671
+ }), m.querySelectorAll(".retry-btn").forEach((e) => {
1672
+ e.addEventListener("click", () => r.onRetry());
1673
+ }), m.querySelectorAll(".biq-btn[data-action=\"send\"]").forEach((e) => {
1674
+ e.addEventListener("click", () => {
1675
+ let t = e.dataset.value ?? "";
1676
+ if (t) {
1677
+ r.onSend(t);
1678
+ let n = e.closest(".biq-blocks");
1679
+ n && (n.style.pointerEvents = "none", n.style.opacity = "0.5");
1680
+ }
1681
+ });
1682
+ }), m.querySelectorAll(".biq-btn[data-action=\"page_action\"]").forEach((e) => {
1683
+ e.addEventListener("click", () => {
1684
+ let t = e.dataset.value ?? "";
1685
+ if (t && r.onBlockPageAction) {
1686
+ let n = e.closest(".biq-blocks");
1687
+ n && (n.style.pointerEvents = "none", n.style.opacity = "0.5"), r.onBlockPageAction(t);
1688
+ }
1689
+ });
1690
+ }), m.querySelectorAll(".biq-qr-pill[data-qr=\"1\"]").forEach((e) => {
1691
+ e.addEventListener("click", () => {
1692
+ let t = e.dataset.value ?? "";
1693
+ if (t) {
1694
+ r.onSend(t);
1695
+ let n = e.closest(".biq-quick-replies");
1696
+ n && (n.style.display = "none");
1697
+ }
1698
+ });
1699
+ }), a ? m.scrollTop = m.scrollHeight : m.scrollTop = Se(o, s, m.scrollHeight);
1700
+ }
1701
+ function O(e) {
1702
+ 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));
1703
+ let i = s.querySelector(".unread-badge-slot");
1704
+ if (i && (i.innerHTML = We(e.unreadCount)), _.disabled = e.isLoading || e.isUploading, y && S) if (e.pendingAttachment) {
1705
+ let t = e.pendingAttachment, i = e.isUploading, a = e.uploadError;
1706
+ y.innerHTML = `
1707
+ <div class="attach-preview">
1708
+ <img
1709
+ src="${Z(t.previewUrl)}"
1710
+ alt="Preview"
1711
+ class="attach-preview-img${i ? " attach-preview-img--uploading" : ""}"
1712
+ />
1713
+ ${i ? `<span class="attach-preview-status">${Z(n.imageUploading)}</span>` : ""}
1714
+ ${a ? `<span class="attach-preview-error">${Z(a)}</span>` : ""}
1715
+ ${i ? "" : `<button class="attach-preview-remove" type="button" aria-label="${Z(n.imageRemove)}">×</button>`}
1716
+ </div>
1717
+ `, y.querySelector(".attach-preview-remove")?.addEventListener("click", () => {
1718
+ r.onRemoveAttachment?.();
1719
+ });
1720
+ } else y.innerHTML = "";
1721
+ if (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 === "home" && e.conversations !== w) {
1722
+ w = e.conversations;
1723
+ let i = Date.now();
1724
+ l.innerHTML = _e(t, n, e.conversations, C, i), l.querySelector(".home-start")?.addEventListener("click", () => {
1725
+ r.onNewConversation();
1726
+ }), l.querySelectorAll(".home-recent-item").forEach((e) => {
1727
+ e.addEventListener("click", () => {
1728
+ let t = e.dataset.session;
1729
+ t && r.onOpenConversation(t);
1730
+ });
1731
+ });
1732
+ }
1733
+ e.view === "conversation" && (D(e), h.innerHTML = Ue(e.escalated, n)), e.view === "messages" && (u.innerHTML = ge(e.conversations, n, Date.now(), C), u.querySelectorAll(".msg-list-item").forEach((e) => {
1734
+ e.addEventListener("click", () => {
1735
+ let t = e.dataset.session;
1736
+ t && r.onOpenConversation(t);
1737
+ });
1738
+ }), u.querySelector(".msg-list-new")?.addEventListener("click", () => {
1739
+ r.onNewConversation();
1740
+ }));
1741
+ }
1742
+ function k(e) {
1743
+ return Ce(o, {
1744
+ ...e,
1745
+ labels: {
1746
+ confirm: n.confirmYes,
1747
+ cancel: n.confirmNo,
1748
+ countdownPrefix: n.confirmCountdownPrefix,
1749
+ countdownSuffix: n.confirmCountdownSuffix
1750
+ }
1751
+ });
1752
+ }
1753
+ return {
1754
+ mount: T,
1755
+ update: O,
1756
+ confirmAction: k
1757
+ };
1758
+ }
1759
+ //#endregion
1760
+ //#region src/i18n/vi.ts
1761
+ var Je = {
1762
+ statusOnline: "Trực tuyến",
1763
+ statusPaused: "Tạm ngừng",
1764
+ navHome: "Trang chủ",
1765
+ navMessages: "Tin nhắn",
1766
+ homeGreeting: "Xin chào 👋",
1767
+ startConversation: "Bắt đầu trò chuyện",
1768
+ newConversation: "Cuộc trò chuyện mới",
1769
+ noConversations: "Chưa có cuộc trò chuyện nào",
1770
+ waitingForHuman: "Đang chờ nhân viên…",
1771
+ inputPlaceholder: "Nhắn tin...",
1772
+ defaultGreeting: "Xin chào! Tôi có thể giúp gì cho bạn?",
1773
+ errorMessage: "Xin lỗi, không thể kết nối. Vui lòng thử lại.",
1774
+ errorAuth: "API key không hợp lệ.",
1775
+ errorForbidden: "Widget không được phép trên trang này.",
1776
+ errorQuota: "Bot đã đạt giới hạn tin nhắn tháng này.",
1777
+ errorGeneric: "Đang gặp sự cố kỹ thuật, vui lòng liên hệ trực tiếp.",
1778
+ typingIndicator: "Đang soạn tin...",
1779
+ quotaExceeded: "Bot đã hết lượt chat tháng này.",
1780
+ trialExpired: "Dịch vụ tạm dừng. Vui lòng liên hệ hỗ trợ.",
1781
+ poweredBy: "Powered by",
1782
+ ariaOpenChat: "Mở khung chat",
1783
+ ariaCloseChat: "Đóng khung chat",
1784
+ ariaSendMessage: "Gửi tin nhắn",
1785
+ actionDone: "✓ Đã thực hiện.",
1786
+ actionCancelled: "Đã huỷ. Bạn cần gì khác không?",
1787
+ actionUnavailable: "Hành động không khả dụng.",
1788
+ actionError: "Có lỗi khi thực hiện.",
1789
+ confirmYes: "Đồng ý",
1790
+ confirmNo: "Huỷ",
1791
+ confirmCountdownPrefix: "Tự động xác nhận sau ",
1792
+ confirmCountdownSuffix: "s…",
1793
+ retry: "Thử lại",
1794
+ recentMessages: "Tin nhắn gần đây",
1795
+ imageAttach: "Đính kèm ảnh",
1796
+ imageRemove: "Xóa ảnh",
1797
+ imageUploading: "Đang tải ảnh…",
1798
+ imageUploadPlanError: "Gói hiện tại không hỗ trợ gửi ảnh.",
1799
+ imageUploadTooLarge: "Ảnh quá lớn (tối đa 5 MB sau khi nén).",
1800
+ imageUploadRateLimit: "Gửi quá nhanh. Vui lòng thử lại.",
1801
+ imageUploadError: "Tải ảnh thất bại. Vui lòng thử lại."
1802
+ }, Ye = {
1803
+ statusOnline: "Online",
1804
+ statusPaused: "Paused",
1805
+ navHome: "Home",
1806
+ navMessages: "Messages",
1807
+ homeGreeting: "Hi there 👋",
1808
+ startConversation: "Start a conversation",
1809
+ newConversation: "New conversation",
1810
+ noConversations: "No conversations yet",
1811
+ waitingForHuman: "Waiting for a teammate…",
1812
+ inputPlaceholder: "Type a message...",
1813
+ defaultGreeting: "Hello! How can I help you?",
1814
+ errorMessage: "Sorry, something went wrong. Please try again.",
1815
+ errorAuth: "Invalid API key.",
1816
+ errorForbidden: "Widget is not allowed on this page.",
1817
+ errorQuota: "This bot has reached its monthly message limit.",
1818
+ errorGeneric: "Technical issue, please contact us directly.",
1819
+ typingIndicator: "Typing...",
1820
+ quotaExceeded: "This bot has reached its monthly chat limit.",
1821
+ trialExpired: "Service paused. Please contact support.",
1822
+ poweredBy: "Powered by",
1823
+ ariaOpenChat: "Open chat",
1824
+ ariaCloseChat: "Close chat",
1825
+ ariaSendMessage: "Send message",
1826
+ actionDone: "✓ Done.",
1827
+ actionCancelled: "Cancelled. Anything else?",
1828
+ actionUnavailable: "Action unavailable.",
1829
+ actionError: "Something went wrong.",
1830
+ confirmYes: "Confirm",
1831
+ confirmNo: "Cancel",
1832
+ confirmCountdownPrefix: "Auto-confirming in ",
1833
+ confirmCountdownSuffix: "s…",
1834
+ retry: "Retry",
1835
+ recentMessages: "Recent messages",
1836
+ imageAttach: "Attach image",
1837
+ imageRemove: "Remove image",
1838
+ imageUploading: "Uploading image…",
1839
+ imageUploadPlanError: "Your plan does not support image sending.",
1840
+ imageUploadTooLarge: "Image too large (max 5 MB after compression).",
1841
+ imageUploadRateLimit: "Too many requests. Please try again.",
1842
+ imageUploadError: "Image upload failed. Please try again."
1843
+ };
1844
+ //#endregion
1845
+ //#region src/i18n/index.ts
1846
+ function Xe(e) {
1847
+ return e === "en" ? Ye : Je;
1848
+ }
1849
+ //#endregion
1850
+ //#region src/core/declarative-executor.ts
1851
+ var Ze = /^[a-zA-Z0-9_-]*$/;
1852
+ function Qe(e, t) {
1853
+ return e.replace(/\{([a-zA-Z][a-zA-Z0-9_]*)\}/g, (e, n) => {
1854
+ let r = t[n], i = r == null ? "" : String(r);
1855
+ if (!Ze.test(i)) throw Error(`Unsafe param value for "${n}"`);
1856
+ return i;
1857
+ });
1858
+ }
1859
+ function $e(e, t) {
1860
+ let n = typeof location < "u" ? location.origin : "https://placeholder.local", r, i;
1861
+ try {
1862
+ r = new URL(e, n), i = new URL(t.replace(/\{[a-zA-Z][a-zA-Z0-9_]*\}/g, "x"), n);
1863
+ } catch {
1864
+ throw Error("Invalid navigation URL");
1865
+ }
1866
+ if (!/^https?:$/.test(r.protocol)) throw Error("Navigation must be http(s)");
1867
+ if (r.origin !== i.origin) throw Error("Navigation origin not allowed");
1868
+ }
1869
+ async function et(e, t) {
1870
+ let n = e.config;
1871
+ if (e.operation === "click") {
1872
+ let e = Qe(String(n.selectorTemplate ?? ""), t), r = document.querySelector(e);
1873
+ if (!r) throw Error(`No element for selector: ${e}`);
1874
+ r.click();
1875
+ return;
1876
+ }
1877
+ if (e.operation === "fill") {
1878
+ let e = Array.isArray(n.fields) ? n.fields : [];
1879
+ for (let n of e) {
1880
+ let e = document.querySelector(n.selector);
1881
+ if (!e) throw Error(`No element for selector: ${n.selector}`);
1882
+ e.value = String(t[n.param] ?? ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 }));
1883
+ }
1884
+ return;
1885
+ }
1886
+ if (e.operation === "navigate") {
1887
+ let e = String(n.urlTemplate ?? ""), r = Qe(e, t);
1888
+ $e(r, e), location.assign(r);
1889
+ return;
1890
+ }
1891
+ throw Error(`Unknown operation: ${String(e.operation)}`);
1892
+ }
1893
+ //#endregion
1894
+ //#region src/core/page-action-executor.ts
1895
+ async function tt(e, t) {
1896
+ let n = t.registry.get(e.actionName);
1897
+ if (!n) return {
1898
+ status: "unknown",
1899
+ message: `Action "${e.actionName}" chưa được đăng ký.`
1900
+ };
1901
+ if (n.riskLevel !== "low" && !await t.confirm({
1902
+ title: n.description,
1903
+ reason: e.reason,
1904
+ paramsDisplay: JSON.stringify(e.params, null, 2),
1905
+ riskLevel: n.riskLevel,
1906
+ autoConfirmAfterSec: n.riskLevel === "medium" ? 10 : null
1907
+ })) return { status: "cancelled" };
1908
+ try {
1909
+ return await t.registry.execute(e.actionName, e.params), { status: "executed" };
1910
+ } catch (e) {
1911
+ return {
1912
+ status: "error",
1913
+ message: e instanceof Error ? e.message : "unknown error"
1914
+ };
1915
+ }
1916
+ }
1917
+ //#endregion
1918
+ //#region src/builds/npm/index.ts
1919
+ var $ = 10;
1920
+ function nt(e) {
1921
+ if (D.setDeclarativeRunner(et), 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;
1922
+ let t = p(e);
1923
+ y();
1924
+ let n = t.apiKey.slice(-16), r = C(), i = b(n), a = x(n, i);
1925
+ I({
1926
+ messages: a,
1927
+ view: "home",
1928
+ currentSessionId: i
1929
+ });
1930
+ let o = K(), s = document.createElement("div");
1931
+ document.body.appendChild(s);
1932
+ let c = () => void 0, l = !1, u = Xe(void 0), d = null, m = null, h = null, g = null;
1933
+ function _() {
1934
+ g ||= setTimeout(async () => {
1935
+ if (g = null, !(!F().escalated || !F().isOpen)) try {
1936
+ let e = await M(t.apiUrl, t.apiKey, F().currentSessionId, $, r);
1937
+ e.messages.length > 0 && I({ messages: e.messages.map(j) }), I({ escalated: e.escalated === !0 });
1938
+ } catch {} finally {
1939
+ F().escalated && F().isOpen && _();
1940
+ }
1941
+ }, 1e4);
1942
+ }
1943
+ f(t.apiKey, t.apiUrl).then((e) => {
1944
+ if (l) return;
1945
+ if (e === null) {
1946
+ console.warn("[BotIQ] Widget not authorised on this origin — skipped mount"), s.remove();
1947
+ return;
1948
+ }
1949
+ h = e, u = Xe(e.widgetLanguage), e.pageActions?.length && D.seed(e.pageActions);
1950
+ let n = qe(t, e, u, {
1951
+ onSend: oe,
1952
+ onToggle: H,
1953
+ onScrollTop: P,
1954
+ onRetry: ce,
1955
+ onNavigate: E,
1956
+ onOpenConversation: te,
1957
+ onNewConversation: A,
1958
+ onAttachImage: ie,
1959
+ onRemoveAttachment: ae,
1960
+ onBlockPageAction: V
1961
+ });
1962
+ d = n, n.mount(s), c = re((e) => n.update(e)), n.update(F()), e.proactive?.enabled && (m = setTimeout(() => {
1963
+ if (F().isOpen) return;
1964
+ let t = w();
1965
+ I({
1966
+ messages: [{
1967
+ role: "assistant",
1968
+ content: e.proactive.message,
1969
+ ts: Date.now()
1970
+ }],
1971
+ view: "conversation",
1972
+ currentSessionId: t,
1973
+ unreadCount: F().unreadCount + 1
1974
+ });
1975
+ }, e.proactive.delayMs ?? 8e3)), a.length > 0 && N(i);
1976
+ });
1977
+ let v = !1;
1978
+ async function T() {
1979
+ if (!v) {
1980
+ v = !0;
1981
+ try {
1982
+ I({ conversations: await O(t.apiUrl, t.apiKey, r) });
1983
+ } finally {
1984
+ v = !1;
1985
+ }
1986
+ }
1987
+ }
1988
+ function E(e) {
1989
+ I({ view: e }), (e === "home" || e === "messages") && T();
1990
+ }
1991
+ function A() {
1992
+ I({
1993
+ view: "conversation",
1994
+ currentSessionId: w(),
1995
+ messages: [],
1996
+ escalated: !1
1997
+ }), o = K();
1998
+ }
1999
+ function te(e) {
2000
+ I({
2001
+ view: "conversation",
2002
+ currentSessionId: e,
2003
+ messages: x(n, e)
2004
+ }), o = K(), N(e);
2005
+ }
2006
+ function j(e) {
2007
+ let t = Date.parse(e.createdAt);
2008
+ return {
2009
+ role: e.role,
2010
+ content: e.content,
2011
+ ...Number.isFinite(t) ? { ts: t } : {},
2012
+ ...h?.richMessages && e.blocks?.length ? { blocks: e.blocks } : {}
2013
+ };
2014
+ }
2015
+ async function N(e) {
2016
+ let n = await M(t.apiUrl, t.apiKey, e, $, r);
2017
+ n.messages.length > 0 && (o = ye(n), I({ messages: n.messages.map(j) })), I({ escalated: n.escalated === !0 }), F().escalated && _();
2018
+ }
2019
+ async function P() {
2020
+ if (xe(o, F().loadingOlder)) {
2021
+ I({ loadingOlder: !0 });
2022
+ try {
2023
+ let e = F().currentSessionId, n = await ne(t.apiUrl, t.apiKey, e, o.oldestCursor, $);
2024
+ n.messages.length > 0 && I({ messages: [...n.messages.map(j), ...F().messages] }), o = be(o, n);
2025
+ } finally {
2026
+ I({ loadingOlder: !1 });
2027
+ }
2028
+ }
2029
+ }
2030
+ let L = "", R = null, z = null;
2031
+ async function B(e, i, a) {
2032
+ let o = F().currentSessionId, s = x(n, o).length === 0 && F().messages.filter((e) => e.role === "user").length === 1;
2033
+ I({ isLoading: !0 });
2034
+ try {
2035
+ let c = i && a ? [{
2036
+ url: i,
2037
+ mimeType: a
2038
+ }] : void 0, l = await ee(t.apiUrl, t.apiKey, o, e, F().messages.filter((e) => !e.error), u, r, c), f = {
2039
+ role: "assistant",
2040
+ content: l.reply,
2041
+ ts: Date.now(),
2042
+ ...l.error ? { error: !0 } : {},
2043
+ ...h?.richMessages && l.blocks?.length ? { blocks: l.blocks } : {}
2044
+ };
2045
+ if (I({
2046
+ messages: [...F().messages, f],
2047
+ isLoading: !1
2048
+ }), l.error || S(n, o, [f]), !l.error && s && T(), l.error || M(t.apiUrl, t.apiKey, o, $, r).then((e) => {
2049
+ I({ escalated: e.escalated === !0 }), F().escalated && _();
2050
+ }), !l.error && l.pageAction && d) {
2051
+ let e = d;
2052
+ try {
2053
+ let t = await tt(l.pageAction, {
2054
+ registry: D,
2055
+ confirm: (t) => e.confirmAction(t)
2056
+ });
2057
+ if (!d) return;
2058
+ let r = {
2059
+ role: "assistant",
2060
+ content: t.status === "executed" ? u.actionDone : t.status === "cancelled" ? u.actionCancelled : t.status === "unknown" ? `⚠ ${t.message ?? u.actionUnavailable}` : `⚠ ${t.message ?? u.actionError}`,
2061
+ ts: Date.now()
2062
+ };
2063
+ I({ messages: [...F().messages, r] }), S(n, o, [r]);
2064
+ } catch {
2065
+ if (!d) return;
2066
+ let e = {
2067
+ role: "assistant",
2068
+ content: u.actionError,
2069
+ ts: Date.now()
2070
+ };
2071
+ I({ messages: [...F().messages, e] }), S(n, o, [e]);
2072
+ }
2073
+ }
2074
+ } catch {
2075
+ I({ isLoading: !1 });
2076
+ }
2077
+ }
2078
+ async function ie(e) {
2079
+ let t = se(e);
2080
+ if (!t.ok) {
2081
+ I({ uploadError: t.error });
2082
+ return;
2083
+ }
2084
+ I({ uploadError: null });
2085
+ try {
2086
+ let { blob: t, mimeType: n } = await le(e), r = F().pendingAttachment;
2087
+ r && URL.revokeObjectURL(r.previewUrl), I({
2088
+ pendingAttachment: {
2089
+ blob: t,
2090
+ previewUrl: URL.createObjectURL(t),
2091
+ mimeType: n
2092
+ },
2093
+ uploadError: null
2094
+ });
2095
+ } catch {
2096
+ I({ uploadError: u.imageUploadError });
2097
+ }
2098
+ }
2099
+ function ae() {
2100
+ let e = F().pendingAttachment;
2101
+ e && URL.revokeObjectURL(e.previewUrl), I({
2102
+ pendingAttachment: null,
2103
+ uploadError: null
2104
+ });
2105
+ }
2106
+ async function oe(e) {
2107
+ if (F().isLoading || F().isUploading) return;
2108
+ let i = F().pendingAttachment;
2109
+ if (!e && !i) return;
2110
+ I({ uploadError: null }), L = e, R = null, z = null;
2111
+ let a = F().currentSessionId, o = {
2112
+ role: "user",
2113
+ content: e,
2114
+ ts: Date.now()
2115
+ };
2116
+ if (I({ messages: [...F().messages, o] }), S(n, a, [o]), i) {
2117
+ I({
2118
+ isUploading: !0,
2119
+ uploadError: null
2120
+ });
2121
+ let e = await k(t.apiUrl, t.apiKey, i.blob, r, u);
2122
+ if (I({ isUploading: !1 }), !e.ok) {
2123
+ I({ uploadError: e.error });
2124
+ let t = F().messages;
2125
+ I({ messages: t.slice(0, -1) });
2126
+ return;
2127
+ }
2128
+ R = e.url, z = i.mimeType, URL.revokeObjectURL(i.previewUrl), I({
2129
+ pendingAttachment: null,
2130
+ uploadError: null
2131
+ });
2132
+ }
2133
+ await B(e, R ?? void 0, z ?? void 0);
2134
+ }
2135
+ function ce() {
2136
+ if (F().isLoading || !L) return;
2137
+ let e = F().messages;
2138
+ I({ messages: e.length > 0 && e[e.length - 1].error ? e.slice(0, -1) : e }), B(L, R ?? void 0, z ?? void 0);
2139
+ }
2140
+ async function V(e) {
2141
+ if (!d) return;
2142
+ if (!D.has(e)) {
2143
+ let e = {
2144
+ role: "assistant",
2145
+ content: `⚠ ${u.actionUnavailable}`,
2146
+ ts: Date.now()
2147
+ };
2148
+ I({ messages: [...F().messages, e] });
2149
+ return;
2150
+ }
2151
+ let t = d;
2152
+ try {
2153
+ let n = await tt({
2154
+ actionName: e,
2155
+ params: {},
2156
+ reason: ""
2157
+ }, {
2158
+ registry: D,
2159
+ confirm: (e) => t.confirmAction(e)
2160
+ });
2161
+ if (!d) return;
2162
+ let r = {
2163
+ role: "assistant",
2164
+ content: n.status === "executed" ? u.actionDone : n.status === "cancelled" ? u.actionCancelled : n.status === "unknown" ? `⚠ ${n.message ?? u.actionUnavailable}` : `⚠ ${n.message ?? u.actionError}`,
2165
+ ts: Date.now()
2166
+ };
2167
+ I({ messages: [...F().messages, r] });
2168
+ } catch {
2169
+ if (!d) return;
2170
+ let e = {
2171
+ role: "assistant",
2172
+ content: u.actionError,
2173
+ ts: Date.now()
2174
+ };
2175
+ I({ messages: [...F().messages, e] });
2176
+ }
2177
+ }
2178
+ function H() {
2179
+ let e = !F().isOpen, t = F().view;
2180
+ I({
2181
+ isOpen: e,
2182
+ ...e ? { unreadCount: 0 } : {}
2183
+ }), e && t === "home" && T();
2184
+ }
2185
+ return () => {
2186
+ l = !0, d = null, c(), m && clearTimeout(m), g &&= (clearTimeout(g), null);
2187
+ let e = F().pendingAttachment;
2188
+ e && URL.revokeObjectURL(e.previewUrl), I({
2189
+ pendingAttachment: null,
2190
+ uploadError: null
2191
+ }), s.remove();
2192
+ };
2193
+ }
2194
+ //#endregion
2195
+ export { nt as t };