@squadico/chatbot 1.3.0 → 1.5.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.
Files changed (113) hide show
  1. package/README.md +110 -20
  2. package/dist/answer-CDGrP8YE.js +1193 -0
  3. package/dist/answer-CDGrP8YE.js.map +1 -0
  4. package/dist/answer-DRaV2dVt.cjs +8 -0
  5. package/dist/answer-DRaV2dVt.cjs.map +1 -0
  6. package/dist/chatbot-widgets.global.js +4 -0
  7. package/dist/chatbot-widgets.global.js.map +1 -0
  8. package/dist/chatbot.global.js +12 -7
  9. package/dist/chatbot.global.js.map +1 -1
  10. package/dist/components/ChatbotWidget.d.ts.map +1 -1
  11. package/dist/components/MessageList.d.ts +4 -1
  12. package/dist/components/MessageList.d.ts.map +1 -1
  13. package/dist/components/RichText.d.ts +6 -4
  14. package/dist/components/RichText.d.ts.map +1 -1
  15. package/dist/element.d.ts.map +1 -1
  16. package/dist/extras-ClIRRLqo.js +604 -0
  17. package/dist/extras-ClIRRLqo.js.map +1 -0
  18. package/dist/extras-lsCe4xgN.cjs +4 -0
  19. package/dist/extras-lsCe4xgN.cjs.map +1 -0
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -2
  24. package/dist/jsx.d.ts +41 -0
  25. package/dist/jsx.d.ts.map +1 -1
  26. package/dist/lib/client.d.ts +8 -4
  27. package/dist/lib/client.d.ts.map +1 -1
  28. package/dist/lib/conversation.d.ts +5 -1
  29. package/dist/lib/conversation.d.ts.map +1 -1
  30. package/dist/lib/i18n.d.ts +20 -0
  31. package/dist/lib/i18n.d.ts.map +1 -1
  32. package/dist/lib/useChat.d.ts +6 -0
  33. package/dist/lib/useChat.d.ts.map +1 -1
  34. package/dist/react.cjs +1 -1
  35. package/dist/react.cjs.map +1 -1
  36. package/dist/react.d.ts.map +1 -1
  37. package/dist/react.js +2 -2
  38. package/dist/react.js.map +1 -1
  39. package/dist/src-BWDC0W4O.js +2005 -0
  40. package/dist/src-BWDC0W4O.js.map +1 -0
  41. package/dist/src-DvrmRR89.cjs +7 -0
  42. package/dist/src-DvrmRR89.cjs.map +1 -0
  43. package/dist/types.d.ts +16 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/widgets/approval/SqcApproval.d.ts +17 -0
  46. package/dist/widgets/approval/SqcApproval.d.ts.map +1 -0
  47. package/dist/widgets/approval/name.d.ts +3 -0
  48. package/dist/widgets/approval/name.d.ts.map +1 -0
  49. package/dist/widgets/chart/SqcChart.d.ts +19 -0
  50. package/dist/widgets/chart/SqcChart.d.ts.map +1 -0
  51. package/dist/widgets/chart/draw.d.ts +31 -0
  52. package/dist/widgets/chart/draw.d.ts.map +1 -0
  53. package/dist/widgets/chart/png.d.ts +10 -0
  54. package/dist/widgets/chart/png.d.ts.map +1 -0
  55. package/dist/widgets/chart/read.d.ts +11 -0
  56. package/dist/widgets/chart/read.d.ts.map +1 -0
  57. package/dist/widgets/chart/strings.d.ts +32 -0
  58. package/dist/widgets/chart/strings.d.ts.map +1 -0
  59. package/dist/widgets/choices/SqcChoices.d.ts +17 -0
  60. package/dist/widgets/choices/SqcChoices.d.ts.map +1 -0
  61. package/dist/widgets/confirm/SqcConfirm.d.ts +12 -0
  62. package/dist/widgets/confirm/SqcConfirm.d.ts.map +1 -0
  63. package/dist/widgets/define.d.ts +8 -0
  64. package/dist/widgets/define.d.ts.map +1 -0
  65. package/dist/widgets/element.d.ts +26 -0
  66. package/dist/widgets/element.d.ts.map +1 -0
  67. package/dist/widgets/extras-loader.d.ts +21 -0
  68. package/dist/widgets/extras-loader.d.ts.map +1 -0
  69. package/dist/widgets/extras.d.ts +3 -0
  70. package/dist/widgets/extras.d.ts.map +1 -0
  71. package/dist/widgets/extras.global.d.ts +2 -0
  72. package/dist/widgets/extras.global.d.ts.map +1 -0
  73. package/dist/widgets/form/SqcForm.d.ts +14 -0
  74. package/dist/widgets/form/SqcForm.d.ts.map +1 -0
  75. package/dist/widgets/form/reply.d.ts +7 -0
  76. package/dist/widgets/form/reply.d.ts.map +1 -0
  77. package/dist/widgets/i18n.d.ts +4 -0
  78. package/dist/widgets/i18n.d.ts.map +1 -0
  79. package/dist/widgets/index.d.ts +10 -0
  80. package/dist/widgets/index.d.ts.map +1 -0
  81. package/dist/widgets/inline.d.ts +11 -0
  82. package/dist/widgets/inline.d.ts.map +1 -0
  83. package/dist/widgets/live.d.ts +12 -0
  84. package/dist/widgets/live.d.ts.map +1 -0
  85. package/dist/widgets/names.d.ts +10 -0
  86. package/dist/widgets/names.d.ts.map +1 -0
  87. package/dist/widgets/parse/answer.d.ts +11 -0
  88. package/dist/widgets/parse/answer.d.ts.map +1 -0
  89. package/dist/widgets/parse/confirm.d.ts +19 -0
  90. package/dist/widgets/parse/confirm.d.ts.map +1 -0
  91. package/dist/widgets/parse/form.d.ts +6 -0
  92. package/dist/widgets/parse/form.d.ts.map +1 -0
  93. package/dist/widgets/styles.d.ts +3 -0
  94. package/dist/widgets/styles.d.ts.map +1 -0
  95. package/dist/widgets/table/SqcTable.d.ts +16 -0
  96. package/dist/widgets/table/SqcTable.d.ts.map +1 -0
  97. package/dist/widgets/types.d.ts +68 -0
  98. package/dist/widgets/types.d.ts.map +1 -0
  99. package/dist/widgets.cjs +1 -0
  100. package/dist/widgets.js +3 -0
  101. package/package.json +7 -2
  102. package/dist/components/Approval.d.ts +0 -37
  103. package/dist/components/Approval.d.ts.map +0 -1
  104. package/dist/components/Choices.d.ts +0 -27
  105. package/dist/components/Choices.d.ts.map +0 -1
  106. package/dist/components/Confirm.d.ts +0 -16
  107. package/dist/components/Confirm.d.ts.map +0 -1
  108. package/dist/lib/confirm.d.ts +0 -17
  109. package/dist/lib/confirm.d.ts.map +0 -1
  110. package/dist/src-DcJyi601.cjs +0 -8
  111. package/dist/src-DcJyi601.cjs.map +0 -1
  112. package/dist/src-Nh5rZvti.js +0 -2710
  113. package/dist/src-Nh5rZvti.js.map +0 -1
@@ -0,0 +1,2005 @@
1
+ import { C as e, D as t, E as n, S as r, T as i, a, b as o, d as s, f as c, g as l, h as u, i as d, m as f, n as p, p as m, r as h, s as g, t as _, w as v, x as y, y as b } from "./answer-CDGrP8YE.js";
2
+ //#region src/lib/context.ts
3
+ var x = /* @__PURE__ */ new Set(["sessionId"]);
4
+ function S(e) {
5
+ if (typeof e == "string") return e.length > 0 ? { id: e } : void 0;
6
+ if (!e || typeof e != "object" || Array.isArray(e)) return;
7
+ let { id: t, name: n } = e;
8
+ if (typeof t == "string" && t.length !== 0) return typeof n == "string" && n.length > 0 ? {
9
+ id: t,
10
+ name: n
11
+ } : { id: t };
12
+ }
13
+ function C(e) {
14
+ let t = S(e);
15
+ if (t) return t.name ?? t.id;
16
+ }
17
+ function w(e) {
18
+ return !!e && typeof e == "object" && !Array.isArray(e);
19
+ }
20
+ function T(e) {
21
+ let t = {};
22
+ for (let [n, r] of Object.entries(e)) {
23
+ if (x.has(n) || !w(r)) {
24
+ t[n] = r;
25
+ continue;
26
+ }
27
+ let e = S(r);
28
+ e && (t[`${n}Id`] = e.id, e.name && (t[`${n}Name`] = e.name));
29
+ }
30
+ return t;
31
+ }
32
+ //#endregion
33
+ //#region src/lib/openState.ts
34
+ var E = "squadico-chatbot:open";
35
+ function D() {
36
+ try {
37
+ if (typeof sessionStorage > "u") return;
38
+ let e = sessionStorage.getItem(E);
39
+ return e === "1" || e !== "0" && void 0;
40
+ } catch {
41
+ return;
42
+ }
43
+ }
44
+ function O(e) {
45
+ try {
46
+ if (typeof sessionStorage > "u") return;
47
+ sessionStorage.setItem(E, e ? "1" : "0");
48
+ } catch {}
49
+ }
50
+ function k(e, t) {
51
+ return t === !1 ? e ?? !1 : D() ?? e ?? !1;
52
+ }
53
+ //#endregion
54
+ //#region src/lib/rail.ts
55
+ function ee(e, t) {
56
+ for (let t = e.length - 1; t >= 0; --t) {
57
+ let n = e[t];
58
+ if (n.role === "assistant" && n.agent) return n.agent.handle;
59
+ }
60
+ return t;
61
+ }
62
+ function A(e, t, n) {
63
+ return !t || t === n || e.trimStart().startsWith("@") ? e : `@${t} ${e}`;
64
+ }
65
+ //#endregion
66
+ //#region src/lib/uid.ts
67
+ function j() {
68
+ let e = globalThis.crypto;
69
+ if (e && typeof e.randomUUID == "function") return e.randomUUID();
70
+ let t = /* @__PURE__ */ new Uint8Array(16);
71
+ if (e && typeof e.getRandomValues == "function") e.getRandomValues(t);
72
+ else for (let e = 0; e < 16; e++) t[e] = Math.floor(Math.random() * 256);
73
+ t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
74
+ let n = [];
75
+ for (let e = 0; e < 16; e++) n.push(t[e].toString(16).padStart(2, "0"));
76
+ return n.slice(0, 4).join("") + "-" + n.slice(4, 6).join("") + "-" + n.slice(6, 8).join("") + "-" + n.slice(8, 10).join("") + "-" + n.slice(10, 16).join("");
77
+ }
78
+ //#endregion
79
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
80
+ function M(e) {
81
+ "@babel/helpers - typeof";
82
+ return M = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
83
+ return typeof e;
84
+ } : function(e) {
85
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
86
+ }, M(e);
87
+ }
88
+ //#endregion
89
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
90
+ function N(e, t) {
91
+ if (M(e) != "object" || !e) return e;
92
+ var n = e[Symbol.toPrimitive];
93
+ if (n !== void 0) {
94
+ var r = n.call(e, t || "default");
95
+ if (M(r) != "object") return r;
96
+ throw TypeError("@@toPrimitive must return a primitive value.");
97
+ }
98
+ return (t === "string" ? String : Number)(e);
99
+ }
100
+ //#endregion
101
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
102
+ function P(e) {
103
+ var t = N(e, "string");
104
+ return M(t) == "symbol" ? t : t + "";
105
+ }
106
+ //#endregion
107
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
108
+ function F(e, t, n) {
109
+ return (t = P(t)) in e ? Object.defineProperty(e, t, {
110
+ value: n,
111
+ enumerable: !0,
112
+ configurable: !0,
113
+ writable: !0
114
+ }) : e[t] = n, e;
115
+ }
116
+ //#endregion
117
+ //#region src/lib/client.ts
118
+ var I = "https://api.squadico.com", L = 2e4, R = class extends Error {
119
+ constructor(e, t, n) {
120
+ super(e), F(this, "status", void 0), F(this, "code", void 0), this.name = "ChatHttpError", this.status = t, this.code = n;
121
+ }
122
+ };
123
+ function z(e, t) {
124
+ return `${e.replace(/\/+$/, "")}${t}`;
125
+ }
126
+ function B(e, t) {
127
+ return {
128
+ "Content-Type": "application/json",
129
+ Accept: "text/event-stream, application/json",
130
+ ...e ? { "X-Visitor-Token": e } : {},
131
+ ...t ? { "X-Subject-Token": t } : {}
132
+ };
133
+ }
134
+ function te(e) {
135
+ if (!e || typeof e != "object") return;
136
+ let { loc: t, msg: n } = e;
137
+ if (typeof n != "string" || !n) return;
138
+ let r = (Array.isArray(t) ? t.filter((e) => typeof e == "string") : []).at(-1);
139
+ return r && r !== "body" ? `${r}: ${n}` : n;
140
+ }
141
+ async function V(e) {
142
+ let t = "", n;
143
+ try {
144
+ let r = await e.text();
145
+ if (r) try {
146
+ let e = JSON.parse(r), i = e.detail ?? e.message;
147
+ if (Array.isArray(i)) {
148
+ let e = i.map((e) => te(e) ?? (typeof e == "string" ? e : void 0)).filter((e) => e !== void 0);
149
+ t = e.length > 0 ? e.join(", ") : r;
150
+ } else t = typeof i == "string" ? i : r;
151
+ n = typeof e.code == "string" ? e.code : void 0;
152
+ } catch {
153
+ t = r;
154
+ }
155
+ } catch {}
156
+ return new R(t || `The API answered ${e.status}`, e.status, n);
157
+ }
158
+ function H(e, t) {
159
+ if (!e || typeof e != "object") return;
160
+ let n = e;
161
+ if (!(typeof n.handle != "string" || !n.handle)) return {
162
+ handle: n.handle,
163
+ name: typeof n.name == "string" ? n.name : n.handle,
164
+ avatarUrl: typeof n.avatar_url == "string" && n.avatar_url ? z(t, n.avatar_url) : void 0,
165
+ color: typeof n.color == "string" ? n.color : void 0
166
+ };
167
+ }
168
+ function U(e, t) {
169
+ return (Array.isArray(e) ? e : []).map((e) => H(e, t)).filter((e) => e !== void 0);
170
+ }
171
+ var W = [
172
+ "knowledge",
173
+ "skill",
174
+ "delegation",
175
+ "tool"
176
+ ];
177
+ function G(e) {
178
+ return W.find((t) => t === e) ?? "tool";
179
+ }
180
+ function K(e) {
181
+ if (!e || typeof e != "object") return;
182
+ let t = e;
183
+ if (!(typeof t.tool_call_id != "string" || !t.tool_call_id)) return {
184
+ toolCallId: t.tool_call_id,
185
+ tool: typeof t.tool == "string" ? t.tool : "",
186
+ arguments: t.arguments && typeof t.arguments == "object" ? t.arguments : {}
187
+ };
188
+ }
189
+ var q = /* @__PURE__ */ new Set(["user", "assistant"]);
190
+ function J(e, t) {
191
+ if (typeof e.role != "string" || !q.has(e.role) || typeof e.content != "string" || !e.content) return null;
192
+ let n = typeof e.created_at == "string" ? Date.parse(e.created_at) : NaN;
193
+ return {
194
+ id: typeof e.id == "string" && e.id ? e.id : j(),
195
+ role: e.role,
196
+ content: e.content,
197
+ createdAt: Number.isNaN(n) ? Date.now() : n,
198
+ agent: H(e.agent, t),
199
+ attachments: Y(e.attachments),
200
+ authorName: e.kind === "human" && typeof e.author_name == "string" && e.author_name ? e.author_name : void 0
201
+ };
202
+ }
203
+ function Y(e) {
204
+ if (!Array.isArray(e)) return;
205
+ let t = e.map((e) => X(e)).filter((e) => e !== null);
206
+ return t.length > 0 ? t : void 0;
207
+ }
208
+ function X(e) {
209
+ if (!e || typeof e != "object") return null;
210
+ let { id: t, kind: n, filename: r, content_type: i } = e;
211
+ return typeof t != "string" || !t || typeof r != "string" || !r ? null : {
212
+ id: t,
213
+ kind: n === "image" || n === "chart" ? n : "document",
214
+ filename: r,
215
+ contentType: typeof i == "string" ? i : "application/octet-stream"
216
+ };
217
+ }
218
+ async function ne(e) {
219
+ let t = e.agent ? `?agent=${encodeURIComponent(e.agent)}` : "", n = await fetch(z(e.apiUrl, `/public/applications/${encodeURIComponent(e.embedKey)}${t}`), {
220
+ method: "GET",
221
+ headers: B(),
222
+ signal: e.signal
223
+ });
224
+ if (!n.ok) throw await V(n);
225
+ let r = await n.json();
226
+ return {
227
+ welcomeMessage: typeof r.welcome_message == "string" && r.welcome_message ? r.welcome_message : void 0,
228
+ agent: H(r.agent, e.apiUrl),
229
+ handles: U(r.handles, e.apiUrl),
230
+ agentHandle: typeof r.agent_handle == "string" && r.agent_handle ? r.agent_handle : void 0,
231
+ branding: r.branding === !0
232
+ };
233
+ }
234
+ async function re(e) {
235
+ let t = await fetch(z(e.apiUrl, `/public/applications/${encodeURIComponent(e.embedKey)}/conversations`), {
236
+ method: "POST",
237
+ headers: B(),
238
+ body: JSON.stringify({
239
+ ...e.user ? { user: e.user } : {},
240
+ ...e.agent ? { agent: e.agent } : {}
241
+ }),
242
+ signal: e.signal
243
+ });
244
+ if (!t.ok) throw await V(t);
245
+ let n = await t.json();
246
+ if (typeof n.id != "string" || typeof n.visitor_token != "string") throw new R("The API opened a conversation without an id or a token");
247
+ let r = (Array.isArray(n.messages) ? n.messages : []).map((t) => J(t, e.apiUrl)).filter((e) => e !== null);
248
+ return {
249
+ conversationId: n.id,
250
+ visitorToken: n.visitor_token,
251
+ agentName: typeof n.agent_name == "string" ? n.agent_name : "",
252
+ agentSlug: typeof n.agent_slug == "string" ? n.agent_slug : "",
253
+ welcomeMessage: typeof n.welcome_message == "string" && n.welcome_message ? n.welcome_message : void 0,
254
+ messages: r,
255
+ handles: U(n.handles, e.apiUrl),
256
+ agentHandle: typeof n.agent_handle == "string" && n.agent_handle ? n.agent_handle : void 0,
257
+ withHuman: typeof n.handling == "string" && n.handling !== "agents",
258
+ branding: n.branding === !0
259
+ };
260
+ }
261
+ async function ie(e) {
262
+ let t = await fetch(z(e.apiUrl, `/public/conversations/${encodeURIComponent(e.conversationId)}`), {
263
+ method: "GET",
264
+ headers: B(e.visitorToken),
265
+ signal: e.signal
266
+ });
267
+ if (!t.ok) throw await V(t);
268
+ let n = await t.json();
269
+ if (typeof n.id != "string") throw new R("The API replayed a conversation without an id");
270
+ return {
271
+ conversationId: n.id,
272
+ visitorToken: e.visitorToken,
273
+ agentName: typeof n.agent_name == "string" ? n.agent_name : "",
274
+ agentSlug: typeof n.agent_slug == "string" ? n.agent_slug : "",
275
+ welcomeMessage: typeof n.welcome_message == "string" && n.welcome_message ? n.welcome_message : void 0,
276
+ messages: (Array.isArray(n.messages) ? n.messages : []).map((t) => J(t, e.apiUrl)).filter((e) => e !== null),
277
+ handles: U(n.handles, e.apiUrl),
278
+ agentHandle: typeof n.agent_handle == "string" && n.agent_handle ? n.agent_handle : void 0,
279
+ withHuman: typeof n.handling == "string" && n.handling !== "agents",
280
+ branding: n.branding === !0
281
+ };
282
+ }
283
+ async function ae(e) {
284
+ let t = new FormData();
285
+ t.append("file", e.file);
286
+ let n = await fetch(Z(e), {
287
+ method: "POST",
288
+ headers: { "X-Visitor-Token": e.visitorToken },
289
+ body: t,
290
+ signal: e.signal
291
+ });
292
+ if (!n.ok) throw await V(n);
293
+ let r = X(await n.json());
294
+ if (!r) throw new R("The upload could not be read", n.status);
295
+ return r;
296
+ }
297
+ async function oe(e) {
298
+ let t = await fetch(`${Z(e)}/${encodeURIComponent(e.attachmentId)}`, {
299
+ method: "DELETE",
300
+ headers: { "X-Visitor-Token": e.visitorToken },
301
+ signal: e.signal
302
+ });
303
+ if (!t.ok) throw await V(t);
304
+ }
305
+ async function se(e) {
306
+ let t = await fetch(`${Z(e)}/${encodeURIComponent(e.attachmentId)}/content`, {
307
+ headers: { "X-Visitor-Token": e.visitorToken },
308
+ signal: e.signal
309
+ });
310
+ if (!t.ok) throw await V(t);
311
+ return t.blob();
312
+ }
313
+ function Z(e) {
314
+ return z(e.apiUrl, `/public/conversations/${encodeURIComponent(e.conversationId)}/attachments`);
315
+ }
316
+ async function ce(e) {
317
+ return le(z(e.apiUrl, `/public/conversations/${encodeURIComponent(e.conversationId)}/messages`), {
318
+ content: e.message,
319
+ attachment_ids: e.attachmentIds ?? [],
320
+ ...e.context && Object.keys(e.context).length > 0 ? { context: e.context } : {}
321
+ }, e);
322
+ }
323
+ async function Q(e) {
324
+ return le(z(e.apiUrl, `/public/conversations/${encodeURIComponent(e.conversationId)}/approvals`), {
325
+ tool_call_id: e.toolCallId,
326
+ approved: e.approved
327
+ }, e);
328
+ }
329
+ async function le(e, t, n) {
330
+ let r = await fetch(e, {
331
+ method: "POST",
332
+ headers: B(n.visitorToken, n.subjectToken),
333
+ body: JSON.stringify({
334
+ ...t,
335
+ widgets: 1
336
+ }),
337
+ signal: n.signal
338
+ });
339
+ if (!r.ok) throw await V(r);
340
+ if (!r.body) throw new R("Answer with no stream body");
341
+ let i = r.body.getReader(), a = new TextDecoder(), o = "", s = "", c = "", l, u, d = { answer: "" };
342
+ try {
343
+ for (;;) {
344
+ let { value: e, done: t } = await i.read();
345
+ if (t) break;
346
+ o += a.decode(e, { stream: !0 });
347
+ let r = o.split("\n");
348
+ o = r.pop() ?? "";
349
+ for (let e of r) {
350
+ let t = e.trim();
351
+ if (!t) {
352
+ s = "";
353
+ continue;
354
+ }
355
+ if (t.startsWith("event:")) {
356
+ s = t.slice(6).trim();
357
+ continue;
358
+ }
359
+ if (!t.startsWith("data:")) continue;
360
+ let r = t.slice(5).trim();
361
+ if (!r) continue;
362
+ let i;
363
+ try {
364
+ i = JSON.parse(r);
365
+ } catch {
366
+ continue;
367
+ }
368
+ s === "token" && typeof i.text == "string" ? (c += i.text, n.onToken(i.text)) : s === "progress" ? n.onProgress?.(G(i.activity)) : s === "done" ? (d.answer = typeof i.content == "string" ? i.content : c, d.agent = H(i.agent, n.apiUrl), typeof i.unknown_handle == "string" && i.unknown_handle && (d.unknownHandle = i.unknown_handle, d.offered = U(i.handles, n.apiUrl))) : s === "handoff" ? (typeof i.to_agent_name == "string" && (u = i.to_agent_name), c = "") : s === "escalated" ? d.withHuman = !0 : s === "held" ? (d.held = !0, d.withHuman = !0) : s === "approval_required" ? d.approval = K(i) : s === "error" && (l = typeof i.detail == "string" ? i.detail : "The turn failed");
369
+ }
370
+ if (l) break;
371
+ }
372
+ } finally {
373
+ i.cancel().catch(() => void 0);
374
+ }
375
+ if (l) throw new R(l);
376
+ return !d.answer && !d.approval && (d.answer = c), u && !d.agent && (d.authorName = u), d;
377
+ }
378
+ //#endregion
379
+ //#region src/lib/conversation.ts
380
+ var $ = "squadico-chatbot:conversation";
381
+ function ue() {
382
+ try {
383
+ if (typeof sessionStorage > "u") return;
384
+ let e = sessionStorage.getItem($);
385
+ if (!e) return;
386
+ let t = JSON.parse(e);
387
+ return !t.sessionId || !t.visitorToken || !t.embedKey ? void 0 : {
388
+ sessionId: t.sessionId,
389
+ visitorToken: t.visitorToken,
390
+ embedKey: t.embedKey,
391
+ user: typeof t.user == "string" ? t.user : void 0,
392
+ scope: typeof t.scope == "string" ? t.scope : void 0
393
+ };
394
+ } catch {
395
+ return;
396
+ }
397
+ }
398
+ function de(e) {
399
+ try {
400
+ if (typeof sessionStorage > "u") return;
401
+ sessionStorage.setItem($, JSON.stringify(e));
402
+ } catch {}
403
+ }
404
+ function fe() {
405
+ try {
406
+ if (typeof sessionStorage > "u") return;
407
+ sessionStorage.removeItem($);
408
+ } catch {}
409
+ }
410
+ function pe(e, { embedKey: t, user: n, scope: r }) {
411
+ return e.embedKey === t && e.user === n && e.scope === r;
412
+ }
413
+ //#endregion
414
+ //#region src/lib/useChat.ts
415
+ async function me(e) {
416
+ if (e) try {
417
+ return await e() || void 0;
418
+ } catch {
419
+ return;
420
+ }
421
+ }
422
+ var he = "preview-welcome";
423
+ function ge(e, t) {
424
+ return e === void 0 && t === void 0 ? void 0 : JSON.stringify([e, t]);
425
+ }
426
+ function _e(e) {
427
+ let t = e instanceof R ? e.status : void 0;
428
+ return t === 415 ? "unsupported" : t === 413 ? "tooLarge" : t === 409 ? "tooMany" : t === 422 ? "unreadable" : "failed";
429
+ }
430
+ var ve = 5e3;
431
+ function ye(e) {
432
+ return e instanceof R && e.code === "conversation_retired";
433
+ }
434
+ function be(t) {
435
+ let [n, r] = e([]), [a, s] = e(!1), [c, l] = e(""), [u, d] = e(0), [f, p] = e([]), [m, h] = e(""), [g, _] = e(""), [x, S] = e(null), [C, w] = e(!1), [E, D] = e(!1), [O, k] = e([]), [ee, A] = e([]), [M, N] = e(null), P = o(null), F = o(t);
436
+ F.current = t;
437
+ let I = o(null), L = o(null), z = o(null), B = o(null), te = o(void 0), V = t.greeting, H = y(() => V ? {
438
+ id: "greeting",
439
+ role: "assistant",
440
+ content: V,
441
+ createdAt: Date.now()
442
+ } : null, [V]), U = i((e) => {
443
+ F.current.onEvent?.(e);
444
+ }, []), W = i((e, t) => {
445
+ r((n) => n.map((n) => n.id === e ? {
446
+ ...n,
447
+ ...t
448
+ } : n));
449
+ }, []), G = i((e, t) => {
450
+ let n = e instanceof R ? e.status : void 0, r = e instanceof Error ? e.message : String(e), i = (F.current.locale ?? b(void 0)).t.error;
451
+ t && W(t, {
452
+ content: i,
453
+ streaming: !1,
454
+ error: !0,
455
+ activity: void 0
456
+ }), U({
457
+ type: "chatbot-error",
458
+ message: r,
459
+ status: n,
460
+ sessionId: L.current?.sessionId ?? ""
461
+ }), typeof console < "u" && console.error("[squadico-chatbot]", r);
462
+ }, [U, W]), K = i(() => {
463
+ let e = F.current;
464
+ if (!e.embedKey) throw new R("No embed key: nothing says which application to open");
465
+ return {
466
+ opts: e,
467
+ apiUrl: e.apiUrl ?? "https://api.squadico.com",
468
+ embedKey: e.embedKey,
469
+ claim: e.user,
470
+ scope: e.scope
471
+ };
472
+ }, []), q = i((e, t) => {
473
+ let n = {
474
+ sessionId: t.conversationId,
475
+ visitorToken: t.visitorToken
476
+ };
477
+ return L.current = n, te.current = ge(e.claim?.id, e.scope), de({
478
+ ...n,
479
+ embedKey: e.embedKey,
480
+ user: e.claim?.id,
481
+ scope: e.scope
482
+ }), l(t.conversationId), p(t.handles), h(e.opts.agent && t.agentHandle ? t.agentHandle : ""), _(t.agentHandle ?? ""), w(!!t.withHuman), D(t.branding), r((e) => [...t.messages, ...e.filter((e) => e.id !== he)]), n;
483
+ }, []), J = i((e) => {
484
+ if (z.current) return z.current;
485
+ let t = ue();
486
+ if (!t || !pe(t, {
487
+ embedKey: e.embedKey,
488
+ user: e.claim?.id,
489
+ scope: e.scope
490
+ })) return Promise.resolve(null);
491
+ let n = ie({
492
+ apiUrl: e.apiUrl,
493
+ conversationId: t.sessionId,
494
+ visitorToken: t.visitorToken
495
+ }).then((t) => q(e, t)).catch(() => (fe(), null)).finally(() => {
496
+ z.current = null;
497
+ });
498
+ return z.current = n, n;
499
+ }, [q]), Y = i(async () => {
500
+ if (L.current) return L.current;
501
+ if (I.current) return I.current;
502
+ let e = K(), t = J(e).then((t) => t ?? re({
503
+ apiUrl: e.apiUrl,
504
+ embedKey: e.embedKey,
505
+ user: e.claim,
506
+ agent: e.opts.agent
507
+ }).then((t) => q(e, t)));
508
+ I.current = t;
509
+ try {
510
+ return await t;
511
+ } finally {
512
+ I.current = null;
513
+ }
514
+ }, [
515
+ q,
516
+ J,
517
+ K
518
+ ]), X = i(() => {
519
+ if (L.current || I.current || B.current) return;
520
+ let e;
521
+ try {
522
+ e = K();
523
+ } catch (e) {
524
+ G(e);
525
+ return;
526
+ }
527
+ let t = J(e).then(async (t) => {
528
+ if (t || L.current || I.current) return;
529
+ let n = await ne({
530
+ apiUrl: e.apiUrl,
531
+ embedKey: e.embedKey,
532
+ agent: e.opts.agent
533
+ });
534
+ if (L.current || I.current) return;
535
+ p(n.handles), h(e.opts.agent && n.agentHandle ? n.agentHandle : ""), _(n.agentHandle ?? ""), D(n.branding);
536
+ let i = n.welcomeMessage;
537
+ i && r((e) => e.length > 0 ? e : [{
538
+ id: he,
539
+ role: "assistant",
540
+ content: i,
541
+ createdAt: Date.now(),
542
+ agent: n.agent
543
+ }]);
544
+ });
545
+ B.current = t, t.catch((e) => {
546
+ B.current = null, G(e);
547
+ });
548
+ }, [
549
+ G,
550
+ J,
551
+ K
552
+ ]), Z = i((e, t, { retry: n = !1, carried: i = [] } = {}) => {
553
+ if (P.current) return;
554
+ let a = new AbortController();
555
+ P.current = a, s(!0), S(null);
556
+ let o = j();
557
+ r((t) => [
558
+ ...t,
559
+ {
560
+ id: j(),
561
+ role: "user",
562
+ content: e,
563
+ createdAt: Date.now(),
564
+ attachments: i.length > 0 ? i : void 0
565
+ },
566
+ {
567
+ id: o,
568
+ role: "assistant",
569
+ content: "",
570
+ createdAt: Date.now(),
571
+ streaming: !0
572
+ }
573
+ ]), (async () => {
574
+ let i = await Y();
575
+ U({
576
+ type: "chatbot-message",
577
+ role: "user",
578
+ content: e,
579
+ sessionId: i.sessionId
580
+ });
581
+ let s = "", c = (e) => {
582
+ s += e, W(o, {
583
+ content: s,
584
+ activity: void 0
585
+ });
586
+ }, l = (e) => {
587
+ s || W(o, { activity: e });
588
+ }, u;
589
+ try {
590
+ u = await t(i, c, a.signal, l);
591
+ } catch (e) {
592
+ if (!ye(e) || (fe(), L.current = null, I.current = null, !n)) throw e;
593
+ i = await Y(), s = "", W(o, {
594
+ content: "",
595
+ activity: void 0
596
+ }), u = await t(i, c, a.signal, l);
597
+ }
598
+ if (u.withHuman && w(!0), u.held) {
599
+ r((e) => e.filter((e) => e.id !== o));
600
+ return;
601
+ }
602
+ W(o, {
603
+ content: u.answer,
604
+ streaming: !1,
605
+ activity: void 0,
606
+ agent: u.agent,
607
+ authorName: u.authorName,
608
+ approval: u.approval,
609
+ unknownHandle: u.unknownHandle,
610
+ offered: u.offered
611
+ }), S(u.approval ?? null), U({
612
+ type: "chatbot-message",
613
+ role: "assistant",
614
+ content: u.answer,
615
+ sessionId: i.sessionId,
616
+ agent: u.agent?.handle
617
+ });
618
+ })().catch((e) => {
619
+ if (a.signal.aborted) {
620
+ W(o, {
621
+ streaming: !1,
622
+ activity: void 0
623
+ });
624
+ return;
625
+ }
626
+ G(e, o);
627
+ }).finally(() => {
628
+ P.current = null, s(!1);
629
+ });
630
+ }, [
631
+ Y,
632
+ U,
633
+ G,
634
+ W
635
+ ]), le = i((e) => {
636
+ let t = e.trim();
637
+ if (!t && O.length === 0) return;
638
+ let n = O;
639
+ k([]), N(null), Z(t, async (e, r, i, a) => ce({
640
+ subjectToken: await me(F.current.getSubjectToken),
641
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
642
+ conversationId: e.sessionId,
643
+ visitorToken: e.visitorToken,
644
+ message: t,
645
+ attachmentIds: n.map((e) => e.id),
646
+ context: F.current.context ? T(F.current.context) : void 0,
647
+ onToken: r,
648
+ onProgress: a,
649
+ signal: i
650
+ }), {
651
+ retry: !0,
652
+ carried: n
653
+ });
654
+ }, [O, Z]), $ = i((e) => {
655
+ N(null), A((t) => [...t, e.name]), Y().then((t) => ae({
656
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
657
+ conversationId: t.sessionId,
658
+ visitorToken: t.visitorToken,
659
+ file: e
660
+ })).then((e) => k((t) => [...t, e])).catch((e) => N(_e(e))).finally(() => A((t) => {
661
+ let n = t.indexOf(e.name);
662
+ return n < 0 ? t : [...t.slice(0, n), ...t.slice(n + 1)];
663
+ }));
664
+ }, [Y]), be = i((e) => {
665
+ k((t) => t.filter((t) => t.id !== e));
666
+ let t = L.current;
667
+ t && oe({
668
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
669
+ conversationId: t.sessionId,
670
+ visitorToken: t.visitorToken,
671
+ attachmentId: e
672
+ }).catch(() => {});
673
+ }, []), xe = i(async (e) => {
674
+ let t = L.current;
675
+ if (!t) throw new R("No conversation to read that file from");
676
+ return se({
677
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
678
+ conversationId: t.sessionId,
679
+ visitorToken: t.visitorToken,
680
+ attachmentId: e
681
+ });
682
+ }, []), Se = i((e, t) => {
683
+ let n = x;
684
+ n && Z(t, async (t, r, i, a) => Q({
685
+ subjectToken: await me(F.current.getSubjectToken),
686
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
687
+ conversationId: t.sessionId,
688
+ visitorToken: t.visitorToken,
689
+ toolCallId: n.toolCallId,
690
+ approved: e,
691
+ onToken: r,
692
+ onProgress: a,
693
+ signal: i
694
+ }));
695
+ }, [x, Z]), Ce = i(() => {
696
+ P.current?.abort(), P.current = null, s(!1);
697
+ }, []), we = i(() => {
698
+ P.current?.abort(), P.current = null, L.current = null, I.current = null, z.current = null, B.current = null, te.current = void 0, fe(), s(!1), S(null), w(!1), l(""), d((e) => e + 1), h(""), _(""), r([]), U({
699
+ type: "chatbot-reset",
700
+ sessionId: ""
701
+ });
702
+ }, [U]), Te = t.humanPollMs ?? ve;
703
+ v(() => {
704
+ if (!C || !c) return;
705
+ let e = setInterval(() => {
706
+ let e = L.current;
707
+ !e || P.current || ie({
708
+ apiUrl: F.current.apiUrl ?? "https://api.squadico.com",
709
+ conversationId: e.sessionId,
710
+ visitorToken: e.visitorToken
711
+ }).then((e) => {
712
+ r(e.messages), w(!!e.withHuman);
713
+ }).catch(() => {});
714
+ }, Te);
715
+ return () => clearInterval(e);
716
+ }, [
717
+ C,
718
+ c,
719
+ Te
720
+ ]);
721
+ let Ee = ge(t.user?.id, t.scope);
722
+ return v(() => {
723
+ L.current && te.current !== Ee && we();
724
+ }, [Ee, we]), {
725
+ messages: y(() => n.length === 0 && H ? [H] : n, [H, n]),
726
+ busy: a,
727
+ sessionId: c,
728
+ resets: u,
729
+ handles: f,
730
+ addressee: m,
731
+ agentHandle: g,
732
+ approval: x,
733
+ withHuman: C,
734
+ branding: E,
735
+ start: X,
736
+ send: le,
737
+ attachments: O,
738
+ uploading: ee,
739
+ attachmentError: M,
740
+ attach: $,
741
+ detach: be,
742
+ loadAttachment: xe,
743
+ decide: Se,
744
+ stop: Ce,
745
+ reset: we
746
+ };
747
+ }
748
+ //#endregion
749
+ //#region src/components/Avatar.tsx
750
+ function xe({ name: t, color: n, url: r, size: i = 16 }) {
751
+ let [a, o] = e(void 0), s = !!r && a !== r;
752
+ return /* @__PURE__ */ l("span", {
753
+ class: "sqc-avatar",
754
+ "aria-hidden": "true",
755
+ style: {
756
+ width: `${i}px`,
757
+ height: `${i}px`,
758
+ fontSize: `${Math.round(i * .45)}px`,
759
+ borderRadius: `${Math.round(i * .25)}px`,
760
+ ...s || !n ? {} : { backgroundColor: n }
761
+ },
762
+ children: s ? /* @__PURE__ */ l("img", {
763
+ src: r,
764
+ alt: "",
765
+ onError: () => o(r)
766
+ }) : Se(t)
767
+ });
768
+ }
769
+ function Se(e) {
770
+ let t = Array.from(e.trim())[0];
771
+ return t ? t.toLocaleUpperCase() : "?";
772
+ }
773
+ //#endregion
774
+ //#region src/components/AgentRail.tsx
775
+ function Ce({ handles: e, active: t, disabled: n, onPick: r, label: i }) {
776
+ return /* @__PURE__ */ l("nav", {
777
+ class: "sqc-rail",
778
+ "aria-label": i,
779
+ children: e.map((e) => /* @__PURE__ */ l("button", {
780
+ type: "button",
781
+ class: "sqc-rail__item",
782
+ "aria-label": e.name,
783
+ "aria-pressed": e.handle === t,
784
+ "data-tip": e.name,
785
+ disabled: n,
786
+ onClick: () => r(e.handle),
787
+ children: [/* @__PURE__ */ l(xe, {
788
+ name: e.name,
789
+ color: e.color,
790
+ url: e.avatarUrl,
791
+ size: 40
792
+ }), /* @__PURE__ */ l("span", {
793
+ class: "sqc-rail__label",
794
+ "aria-hidden": "true",
795
+ children: we(e.handle)
796
+ })]
797
+ }, e.handle))
798
+ });
799
+ }
800
+ function we(e) {
801
+ let t = e.split(/[-_]/)[0] ?? e;
802
+ return t.charAt(0).toUpperCase() + t.slice(1);
803
+ }
804
+ //#endregion
805
+ //#region src/components/Composer.tsx
806
+ var Te = 132, Ee = "image/png,image/jpeg,image/gif,image/webp,application/pdf,.docx,.txt,.md,.csv,.json", De = /^[a-zA-Z0-9_-]*$/;
807
+ function Oe(e, t) {
808
+ let n = e.slice(0, t), r = n.lastIndexOf("@");
809
+ if (r < 0 || r > 0 && !/\s/.test(n[r - 1] ?? "")) return null;
810
+ let i = n.slice(r + 1);
811
+ return De.test(i) ? {
812
+ start: r,
813
+ query: i
814
+ } : null;
815
+ }
816
+ function ke({ placeholder: n, locale: r, busy: a, autoFocus: s, handles: c, addressee: u, attachments: d = [], uploading: f = [], attachmentError: p, onAttach: m, onDetach: h, onSend: g, onStop: _ }) {
817
+ let [b, x] = e(""), [S, C] = e(null), [w, T] = e(0), [E, D] = e(!1), O = o(null), k = o(null), ee = !!m, A = f.length > 0, j = y(() => {
818
+ if (!S || !c || c.length === 0) return [];
819
+ let e = S.query.toLowerCase();
820
+ return c.filter((t) => t.handle.startsWith(e));
821
+ }, [c, S]), M = j.length > 0, N = i(() => {
822
+ let e = O.current;
823
+ if (!e) return;
824
+ e.style.height = "auto";
825
+ let t = e.scrollHeight > Te;
826
+ e.style.height = `${Math.min(e.scrollHeight, Te)}px`, e.style.overflowY = t ? "auto" : "hidden";
827
+ }, []);
828
+ v(() => {
829
+ s && O.current?.focus(), N();
830
+ }, [s, N]), v(() => {
831
+ u && (x((e) => e || `@${u} `), requestAnimationFrame(N));
832
+ }, [u, N]);
833
+ let P = i((e) => {
834
+ C(Oe(e.value, e.selectionStart ?? e.value.length)), T(0);
835
+ }, []), F = i((e) => {
836
+ let t = O.current;
837
+ if (!t || !S) return;
838
+ let n = t.selectionStart ?? t.value.length, r = `${b.slice(0, S.start)}@${e} ${b.slice(n)}`, i = S.start + e.length + 2;
839
+ x(r), C(null), requestAnimationFrame(() => {
840
+ t.focus(), t.setSelectionRange(i, i), N();
841
+ });
842
+ }, [
843
+ N,
844
+ S,
845
+ b
846
+ ]), I = i((e) => {
847
+ if (!(!m || !e)) for (let t of Array.from(e)) m(t);
848
+ }, [m]), R = i(() => {
849
+ let e = b.trim();
850
+ !e && d.length === 0 || a || A || (g(e), x(""), C(null), requestAnimationFrame(N));
851
+ }, [
852
+ d.length,
853
+ a,
854
+ N,
855
+ g,
856
+ b,
857
+ A
858
+ ]), z = i((e) => {
859
+ if (M && !e.isComposing) {
860
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
861
+ e.preventDefault();
862
+ let t = e.key === "ArrowDown" ? 1 : j.length - 1;
863
+ T((e) => (e + t) % j.length);
864
+ return;
865
+ }
866
+ if (e.key === "Enter" || e.key === "Tab") {
867
+ e.preventDefault(), F((j[w] ?? j[0]).handle);
868
+ return;
869
+ }
870
+ if (e.key === "Escape") {
871
+ e.preventDefault(), e.stopPropagation(), C(null);
872
+ return;
873
+ }
874
+ }
875
+ e.key === "Enter" && !e.shiftKey && !e.isComposing && (e.preventDefault(), R());
876
+ }, [
877
+ w,
878
+ j,
879
+ F,
880
+ M,
881
+ R
882
+ ]), B = L - b.length;
883
+ return /* @__PURE__ */ l("form", {
884
+ class: `sqc-composer${E ? " sqc-composer--dropping" : ""}`,
885
+ onSubmit: (e) => {
886
+ e.preventDefault(), R();
887
+ },
888
+ onDragOver: (e) => {
889
+ ee && (e.preventDefault(), D(!0));
890
+ },
891
+ onDragLeave: () => D(!1),
892
+ onDrop: (e) => {
893
+ ee && (e.preventDefault(), D(!1), I(e.dataTransfer?.files ?? null));
894
+ },
895
+ children: [
896
+ (d.length > 0 || A || p) && /* @__PURE__ */ l("div", {
897
+ class: "sqc-attachments",
898
+ children: [
899
+ d.map((e) => /* @__PURE__ */ l("span", {
900
+ class: "sqc-chip",
901
+ "data-kind": e.kind,
902
+ children: [/* @__PURE__ */ l("span", {
903
+ class: "sqc-chip__name",
904
+ children: e.filename
905
+ }), /* @__PURE__ */ l("button", {
906
+ type: "button",
907
+ class: "sqc-chip__remove",
908
+ "aria-label": r.t.composer.remove.replace("{name}", e.filename),
909
+ onClick: () => h?.(e.id),
910
+ children: "×"
911
+ })]
912
+ }, e.id)),
913
+ f.map((e) => /* @__PURE__ */ l("span", {
914
+ class: "sqc-chip sqc-chip--waiting",
915
+ children: /* @__PURE__ */ l("span", {
916
+ class: "sqc-chip__name",
917
+ children: e
918
+ })
919
+ }, e)),
920
+ p && /* @__PURE__ */ l("p", {
921
+ class: "sqc-attachments__error",
922
+ role: "status",
923
+ children: p
924
+ })
925
+ ]
926
+ }),
927
+ /* @__PURE__ */ l("div", {
928
+ class: "sqc-composer__field",
929
+ children: [
930
+ M && /* @__PURE__ */ l("ul", {
931
+ class: "sqc-mentions",
932
+ role: "listbox",
933
+ "aria-label": r.t.handles.picker,
934
+ children: j.map((e, t) => /* @__PURE__ */ l("li", {
935
+ role: "option",
936
+ "aria-selected": t === w,
937
+ class: `sqc-mention${t === w ? " sqc-mention--active" : ""}`,
938
+ onMouseDown: (e) => e.preventDefault(),
939
+ onMouseEnter: () => T(t),
940
+ onClick: () => F(e.handle),
941
+ children: [
942
+ /* @__PURE__ */ l("span", {
943
+ class: "sqc-mention__icon",
944
+ children: /* @__PURE__ */ l(xe, {
945
+ name: e.name,
946
+ color: e.color,
947
+ url: e.avatarUrl,
948
+ size: 18
949
+ })
950
+ }),
951
+ /* @__PURE__ */ l("span", {
952
+ class: "sqc-mention__handle",
953
+ children: ["@", e.handle]
954
+ }),
955
+ /* @__PURE__ */ l("span", {
956
+ class: "sqc-mention__name",
957
+ children: e.name
958
+ })
959
+ ]
960
+ }, e.handle))
961
+ }),
962
+ /* @__PURE__ */ l("textarea", {
963
+ ref: O,
964
+ class: "sqc-composer__input",
965
+ rows: 1,
966
+ value: b,
967
+ placeholder: n,
968
+ maxLength: L,
969
+ "aria-label": r.t.composer.label,
970
+ onInput: (e) => {
971
+ x(e.currentTarget.value), P(e.currentTarget), N();
972
+ },
973
+ onKeyDown: z,
974
+ onClick: (e) => P(e.currentTarget),
975
+ onPaste: (e) => {
976
+ let t = e.clipboardData?.files;
977
+ !ee || !t || t.length === 0 || (e.preventDefault(), I(t));
978
+ }
979
+ }),
980
+ B <= 200 && /* @__PURE__ */ l("span", {
981
+ class: "sqc-composer__count",
982
+ "aria-live": "polite",
983
+ children: B
984
+ })
985
+ ]
986
+ }),
987
+ ee && /* @__PURE__ */ l(t, { children: [/* @__PURE__ */ l("input", {
988
+ ref: k,
989
+ type: "file",
990
+ multiple: !0,
991
+ accept: Ee,
992
+ class: "sqc-file-input",
993
+ onChange: (e) => {
994
+ I(e.currentTarget.files), e.currentTarget.value = "";
995
+ }
996
+ }), /* @__PURE__ */ l("button", {
997
+ type: "button",
998
+ class: "sqc-btn sqc-btn--attach",
999
+ onClick: () => k.current?.click(),
1000
+ "aria-label": r.t.composer.attach,
1001
+ title: r.t.composer.attachTitle,
1002
+ children: /* @__PURE__ */ l("svg", {
1003
+ viewBox: "0 0 24 24",
1004
+ fill: "none",
1005
+ stroke: "currentColor",
1006
+ "stroke-width": "1.9",
1007
+ "stroke-linecap": "round",
1008
+ "stroke-linejoin": "round",
1009
+ "aria-hidden": "true",
1010
+ children: /* @__PURE__ */ l("path", { d: "M21 11.5l-8.8 8.8a5 5 0 01-7.1-7.1l9-9a3.3 3.3 0 014.7 4.7l-9 9a1.6 1.6 0 01-2.3-2.3l8.3-8.3" })
1011
+ })
1012
+ })] }),
1013
+ a ? /* @__PURE__ */ l("button", {
1014
+ type: "button",
1015
+ class: "sqc-btn sqc-btn--stop",
1016
+ onClick: _,
1017
+ "aria-label": r.t.composer.stop,
1018
+ title: r.t.composer.stopTitle,
1019
+ children: /* @__PURE__ */ l("svg", {
1020
+ viewBox: "0 0 24 24",
1021
+ "aria-hidden": "true",
1022
+ children: /* @__PURE__ */ l("rect", {
1023
+ x: "7",
1024
+ y: "7",
1025
+ width: "10",
1026
+ height: "10",
1027
+ rx: "2",
1028
+ fill: "currentColor"
1029
+ })
1030
+ })
1031
+ }) : /* @__PURE__ */ l("button", {
1032
+ type: "submit",
1033
+ class: "sqc-btn sqc-btn--send",
1034
+ disabled: !b.trim() && d.length === 0 || A,
1035
+ "aria-label": r.t.composer.send,
1036
+ title: r.t.composer.sendTitle,
1037
+ children: /* @__PURE__ */ l("svg", {
1038
+ viewBox: "0 0 24 24",
1039
+ fill: "none",
1040
+ stroke: "currentColor",
1041
+ "stroke-width": "1.9",
1042
+ "stroke-linecap": "round",
1043
+ "stroke-linejoin": "round",
1044
+ "aria-hidden": "true",
1045
+ children: /* @__PURE__ */ l("path", { d: "M5 12l14-7-5 14-2.5-5.5L5 12z" })
1046
+ })
1047
+ })
1048
+ ]
1049
+ });
1050
+ }
1051
+ //#endregion
1052
+ //#region src/components/RichText.tsx
1053
+ var Ae = /^(\s*)[-*•]\s+/, je = /^(\s*)\d+[.)]\s+/, Me = /^\s{0,3}(#{1,6})\s+(.+?)#*\s*$/, Ne = /^\s*([-*_])(?:\s*\1){2,}\s*$/, Pe = /^\s*>\s?(.*)$/, Fe = /^\s*```/;
1054
+ function Ie(e, t, n, r) {
1055
+ let i = e[t].ordered, a = [], o = t;
1056
+ for (; o < e.length && e[o].depth >= n;) {
1057
+ let t = e[o];
1058
+ if (t.depth === n && t.ordered !== i) break;
1059
+ if (t.depth > n) {
1060
+ let [n, i] = Ie(e, o, t.depth, `${r}-${o}`), s = a[a.length - 1];
1061
+ s ? s.nested.push(n) : a.push({
1062
+ key: `${r}-${o}`,
1063
+ text: null,
1064
+ nested: [n]
1065
+ }), o = i;
1066
+ continue;
1067
+ }
1068
+ a.push({
1069
+ key: `${r}-${o}`,
1070
+ text: t.text,
1071
+ nested: []
1072
+ }), o += 1;
1073
+ }
1074
+ let s = a.map((e) => /* @__PURE__ */ l("li", { children: [e.text === null ? null : g(e.text, e.key), e.nested] }, e.key));
1075
+ return [l(i ? "ol" : "ul", { children: s }, r), o];
1076
+ }
1077
+ function Le(e) {
1078
+ let t = e.split("\n"), n = [], r = [], i = [], a = [], o = () => {
1079
+ if (!r.length) return;
1080
+ let e = `p${n.length}`;
1081
+ n.push(/* @__PURE__ */ l("p", { children: g(r.join("\n"), e) }, e)), r = [];
1082
+ }, s = () => {
1083
+ if (!i.length) return;
1084
+ let e = 0;
1085
+ for (; e < i.length;) {
1086
+ let t = `l${n.length}`, [r, a] = Ie(i, e, i[e].depth, t);
1087
+ n.push(r), e = a;
1088
+ }
1089
+ i = [];
1090
+ }, c = () => {
1091
+ if (!a.length) return;
1092
+ let e = `q${n.length}`;
1093
+ n.push(/* @__PURE__ */ l("blockquote", { children: g(a.join("\n"), e) }, e)), a = [];
1094
+ }, u = () => {
1095
+ o(), s(), c();
1096
+ };
1097
+ for (let e = 0; e < t.length; e += 1) {
1098
+ let d = t[e];
1099
+ if (Fe.test(d)) {
1100
+ u();
1101
+ let r = [];
1102
+ for (e += 1; e < t.length && !Fe.test(t[e]);) r.push(t[e]), e += 1;
1103
+ let i = `c${n.length}`;
1104
+ n.push(/* @__PURE__ */ l("pre", { children: /* @__PURE__ */ l("code", { children: r.join("\n") }) }, i));
1105
+ continue;
1106
+ }
1107
+ if (!d.trim()) {
1108
+ u();
1109
+ continue;
1110
+ }
1111
+ let f = Me.exec(d);
1112
+ if (f) {
1113
+ u();
1114
+ let e = f[1].length, t = e <= 2 ? "h3" : e === 3 ? "h4" : "h5", r = `h${n.length}`;
1115
+ n.push(/* @__PURE__ */ l(t, { children: g(f[2], r) }, r));
1116
+ continue;
1117
+ }
1118
+ if (Ne.test(d)) {
1119
+ u(), n.push(/* @__PURE__ */ l("hr", {}, `r${n.length}`));
1120
+ continue;
1121
+ }
1122
+ let p = Pe.exec(d);
1123
+ if (p) {
1124
+ o(), s(), a.push(p[1]);
1125
+ continue;
1126
+ }
1127
+ let m = Ae.exec(d), h = m ? null : je.exec(d), _ = m ?? h;
1128
+ if (_) {
1129
+ o(), c(), i.push({
1130
+ depth: _[1].replace(/\t/g, " ").length,
1131
+ ordered: !!h,
1132
+ text: d.slice(_[0].length)
1133
+ });
1134
+ continue;
1135
+ }
1136
+ s(), c(), r.push(d);
1137
+ }
1138
+ return u(), n;
1139
+ }
1140
+ function Re(e) {
1141
+ let t = o(null), { form: n, locked: i, language: a } = e;
1142
+ return r(() => {
1143
+ h();
1144
+ }, []), r(() => {
1145
+ t.current && Object.assign(t.current, {
1146
+ form: n,
1147
+ locked: i,
1148
+ language: a
1149
+ });
1150
+ }, [
1151
+ n,
1152
+ i,
1153
+ a
1154
+ ]), /* @__PURE__ */ l("sqc-form", {
1155
+ ref: t,
1156
+ children: n.fields.map((e) => /* @__PURE__ */ l("p", { children: e.label }, e.name))
1157
+ });
1158
+ }
1159
+ function ze(e, n, r) {
1160
+ switch (e.kind) {
1161
+ case "markdown": return /* @__PURE__ */ l(t, { children: Le(e.text) });
1162
+ case "table": return /* @__PURE__ */ l("sqc-table", {
1163
+ table: {
1164
+ header: e.header,
1165
+ rows: e.rows
1166
+ },
1167
+ locked: r,
1168
+ language: n.code
1169
+ });
1170
+ case "choices": return /* @__PURE__ */ l("sqc-choices", {
1171
+ options: e.options,
1172
+ multiple: e.multiple,
1173
+ checked: e.checked,
1174
+ locked: r,
1175
+ language: n.code
1176
+ });
1177
+ case "form": return /* @__PURE__ */ l(Re, {
1178
+ form: e.form,
1179
+ locked: r,
1180
+ language: n.code
1181
+ });
1182
+ }
1183
+ }
1184
+ function Be({ text: e, locale: n, live: r, confirmable: i }) {
1185
+ let { blocks: a, confirm: o } = _(e, n.code, i === !0), s = !r;
1186
+ return /* @__PURE__ */ l(t, { children: [a.map((e, r) => /* @__PURE__ */ l(t, { children: ze(e, n, s) }, `b${r}`)), o && /* @__PURE__ */ l("sqc-confirm", {
1187
+ locked: s,
1188
+ language: n.code
1189
+ })] });
1190
+ }
1191
+ //#endregion
1192
+ //#region src/components/MessageList.tsx
1193
+ var Ve = 80;
1194
+ function He({ at: e, locale: t }) {
1195
+ let n = new Date(e);
1196
+ return /* @__PURE__ */ l("time", {
1197
+ class: "sqc-msg__time",
1198
+ dateTime: n.toISOString(),
1199
+ children: n.toLocaleTimeString(t.tag, {
1200
+ hour: "2-digit",
1201
+ minute: "2-digit"
1202
+ })
1203
+ });
1204
+ }
1205
+ function Ue(e) {
1206
+ let { call: t, locked: n, locale: i } = e, a = i.code, s = o(null);
1207
+ r(() => {
1208
+ h();
1209
+ }, [t, n]), r(() => {
1210
+ s.current && Object.assign(s.current, {
1211
+ call: t,
1212
+ locked: n,
1213
+ language: a
1214
+ });
1215
+ }, [
1216
+ t,
1217
+ n,
1218
+ a
1219
+ ]);
1220
+ let c = (e) => (t) => t.currentTarget?.dispatchEvent(new CustomEvent("sqc-decision", {
1221
+ detail: { approved: e },
1222
+ bubbles: !0,
1223
+ composed: !0
1224
+ })), { yes: u, no: f } = i.t.confirm;
1225
+ return /* @__PURE__ */ l("sqc-approval", {
1226
+ ref: s,
1227
+ children: [
1228
+ t && /* @__PURE__ */ l("p", { children: d(t.tool) }),
1229
+ /* @__PURE__ */ l("button", {
1230
+ type: "button",
1231
+ disabled: n,
1232
+ onClick: c(!0),
1233
+ children: u
1234
+ }),
1235
+ /* @__PURE__ */ l("button", {
1236
+ type: "button",
1237
+ disabled: n,
1238
+ onClick: c(!1),
1239
+ children: f
1240
+ })
1241
+ ]
1242
+ });
1243
+ }
1244
+ function We({ file: t, load: n }) {
1245
+ let [r, i] = e(null);
1246
+ return v(() => {
1247
+ let e = null, r = !0;
1248
+ return n(t.id).then((t) => {
1249
+ r && (e = URL.createObjectURL(t), i(e));
1250
+ }).catch(() => {}), () => {
1251
+ r = !1, e && URL.revokeObjectURL(e);
1252
+ };
1253
+ }, [t.id, n]), r ? /* @__PURE__ */ l("img", {
1254
+ class: "sqc-attachment__image",
1255
+ src: r,
1256
+ alt: t.filename
1257
+ }) : /* @__PURE__ */ l("span", {
1258
+ class: "sqc-chip sqc-chip--waiting",
1259
+ children: t.filename
1260
+ });
1261
+ }
1262
+ function Ge(e) {
1263
+ let { file: t, load: n, language: i } = e, a = o(null), s = y(() => n(t.id).then((e) => e.text()).catch(() => ""), [t.id, n]);
1264
+ return r(() => {
1265
+ h();
1266
+ }, []), r(() => {
1267
+ a.current && Object.assign(a.current, {
1268
+ body: s,
1269
+ filename: t.filename,
1270
+ language: i
1271
+ });
1272
+ }, [
1273
+ s,
1274
+ t.filename,
1275
+ i
1276
+ ]), /* @__PURE__ */ l("sqc-chart", {
1277
+ class: "sqc-attachment__chart",
1278
+ ref: a,
1279
+ children: t.filename
1280
+ });
1281
+ }
1282
+ function Ke({ files: e, load: t, language: n }) {
1283
+ return e.length === 0 || !t ? null : /* @__PURE__ */ l("div", {
1284
+ class: "sqc-attachments sqc-attachments--sent",
1285
+ children: e.map((e) => e.kind === "image" ? /* @__PURE__ */ l(We, {
1286
+ file: e,
1287
+ load: t
1288
+ }, e.id) : e.kind === "chart" ? /* @__PURE__ */ l(Ge, {
1289
+ file: e,
1290
+ load: t,
1291
+ language: n
1292
+ }, e.id) : /* @__PURE__ */ l("span", {
1293
+ class: "sqc-chip",
1294
+ "data-kind": "document",
1295
+ children: /* @__PURE__ */ l("span", {
1296
+ class: "sqc-chip__name",
1297
+ children: e.filename
1298
+ })
1299
+ }, e.id))
1300
+ });
1301
+ }
1302
+ function qe({ message: e, locale: t, assistantName: n, live: r, onDecide: i, onLoadAttachment: a }) {
1303
+ let o = e.streaming && !e.content, s = !!e.approval;
1304
+ return /* @__PURE__ */ l("div", {
1305
+ class: `sqc-msg sqc-msg--${e.role}${e.error ? " sqc-msg--error" : ""}`,
1306
+ children: [e.role === "assistant" && /* @__PURE__ */ l("div", {
1307
+ class: "sqc-msg__who",
1308
+ children: [e.agent ? /* @__PURE__ */ l(xe, {
1309
+ name: e.agent.name,
1310
+ color: e.agent.color,
1311
+ url: e.agent.avatarUrl
1312
+ }) : /* @__PURE__ */ l(Ye, {}), e.authorName ?? e.agent?.name ?? n]
1313
+ }), /* @__PURE__ */ l("div", {
1314
+ class: "sqc-msg__bubble",
1315
+ children: [o ? /* @__PURE__ */ l("span", {
1316
+ class: "sqc-waiting",
1317
+ children: [/* @__PURE__ */ l("span", {
1318
+ class: "sqc-typing",
1319
+ "aria-label": t.t.typing,
1320
+ children: [
1321
+ /* @__PURE__ */ l("i", {}),
1322
+ /* @__PURE__ */ l("i", {}),
1323
+ /* @__PURE__ */ l("i", {})
1324
+ ]
1325
+ }), e.activity && /* @__PURE__ */ l("span", {
1326
+ class: "sqc-activity",
1327
+ role: "status",
1328
+ children: t.t.activity[e.activity]
1329
+ })]
1330
+ }) : /* @__PURE__ */ l("div", {
1331
+ class: "sqc-msg__body",
1332
+ children: [
1333
+ /* @__PURE__ */ l(Be, {
1334
+ text: e.content,
1335
+ locale: t,
1336
+ live: r,
1337
+ confirmable: e.role === "assistant" && !s && !e.streaming && !e.error
1338
+ }),
1339
+ e.streaming && /* @__PURE__ */ l("span", {
1340
+ class: "sqc-caret",
1341
+ "aria-hidden": "true"
1342
+ }),
1343
+ s && /* @__PURE__ */ l(Ue, {
1344
+ locale: t,
1345
+ call: e.content.trim() === "" ? e.approval : void 0,
1346
+ locked: !i
1347
+ }),
1348
+ e.unknownHandle && !e.streaming && /* @__PURE__ */ l(Je, {
1349
+ message: e,
1350
+ locale: t
1351
+ }),
1352
+ /* @__PURE__ */ l(Ke, {
1353
+ files: e.attachments ?? [],
1354
+ load: a,
1355
+ language: t.code
1356
+ })
1357
+ ]
1358
+ }), !o && /* @__PURE__ */ l(He, {
1359
+ at: e.createdAt,
1360
+ locale: t
1361
+ })]
1362
+ })]
1363
+ });
1364
+ }
1365
+ function Je({ message: e, locale: n }) {
1366
+ let r = e.offered ?? [];
1367
+ return /* @__PURE__ */ l("p", {
1368
+ class: "sqc-msg__unaddressed",
1369
+ children: [
1370
+ /* @__PURE__ */ l("span", { children: n.t.handles.unknown }),
1371
+ " ",
1372
+ /* @__PURE__ */ l("code", { children: ["@", e.unknownHandle] }),
1373
+ r.length > 0 && /* @__PURE__ */ l(t, { children: [
1374
+ " ",
1375
+ /* @__PURE__ */ l("span", { children: n.t.handles.instead }),
1376
+ " ",
1377
+ r.map((e) => /* @__PURE__ */ l("code", { children: ["@", e.handle] }, e.handle))
1378
+ ] })
1379
+ ]
1380
+ });
1381
+ }
1382
+ function Ye() {
1383
+ return /* @__PURE__ */ l("svg", {
1384
+ viewBox: "0 0 24 24",
1385
+ fill: "none",
1386
+ stroke: "currentColor",
1387
+ "stroke-width": "2",
1388
+ "stroke-linecap": "round",
1389
+ "stroke-linejoin": "round",
1390
+ "aria-hidden": "true",
1391
+ children: /* @__PURE__ */ l("path", { d: "M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719" })
1392
+ });
1393
+ }
1394
+ function Xe({ messages: e, locale: t, assistantName: n, suggestions: i, showSuggestions: a, busy: s, withHuman: c, onSuggestion: u, onChoice: d, onDecide: f, onCompose: m, onLoadAttachment: h }) {
1395
+ let g = o(null), _ = o(!0);
1396
+ r(() => {
1397
+ let e = g.current;
1398
+ e && _.current && (e.scrollTop = e.scrollHeight);
1399
+ }, [e]);
1400
+ let y = o({
1401
+ onChoice: d,
1402
+ onCompose: m
1403
+ });
1404
+ y.current = {
1405
+ onChoice: d,
1406
+ onCompose: m
1407
+ }, v(() => {
1408
+ let e = g.current;
1409
+ if (!e) return;
1410
+ let t = (e) => {
1411
+ e.stopPropagation();
1412
+ let t = e.detail?.text;
1413
+ typeof t == "string" && y.current.onChoice(t);
1414
+ }, n = (e) => {
1415
+ e.stopPropagation(), y.current.onCompose?.();
1416
+ };
1417
+ return e.addEventListener("sqc-reply", t), e.addEventListener("sqc-compose", n), () => {
1418
+ e.removeEventListener("sqc-reply", t), e.removeEventListener("sqc-compose", n);
1419
+ };
1420
+ }, []);
1421
+ let b = e[e.length - 1], x = !s && b?.role === "assistant" && !!b.approval, S = o({
1422
+ onDecide: f,
1423
+ decidable: x,
1424
+ locale: t
1425
+ });
1426
+ return S.current = {
1427
+ onDecide: f,
1428
+ decidable: x,
1429
+ locale: t
1430
+ }, v(() => {
1431
+ let e = g.current;
1432
+ if (!e) return;
1433
+ let t = (e) => {
1434
+ e.stopPropagation();
1435
+ let t = e.detail?.approved, n = S.current;
1436
+ if (typeof t != "boolean" || !n.decidable) return;
1437
+ let { yes: r, no: i } = n.locale.t.confirm;
1438
+ n.onDecide(t, t ? r : i);
1439
+ };
1440
+ return e.addEventListener("sqc-decision", t), () => e.removeEventListener("sqc-decision", t);
1441
+ }, []), v(() => {
1442
+ let e = g.current;
1443
+ if (!e) return;
1444
+ let t = () => {
1445
+ _.current = e.scrollHeight - e.scrollTop - e.clientHeight < Ve;
1446
+ };
1447
+ return e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t);
1448
+ }, []), /* @__PURE__ */ l("div", {
1449
+ class: "sqc-messages",
1450
+ ref: g,
1451
+ role: "log",
1452
+ "aria-live": "polite",
1453
+ "aria-atomic": "false",
1454
+ children: [
1455
+ e.map((r, i) => /* @__PURE__ */ l(qe, {
1456
+ message: r,
1457
+ locale: t,
1458
+ assistantName: n,
1459
+ live: !s && p(i, e),
1460
+ onDecide: !s && r.role === "assistant" && i === e.length - 1 ? f : void 0,
1461
+ onLoadAttachment: h
1462
+ }, r.id)),
1463
+ c && /* @__PURE__ */ l("p", {
1464
+ class: "sqc-with-human",
1465
+ role: "status",
1466
+ children: t.t.withHuman
1467
+ }),
1468
+ a && i && i.length > 0 && /* @__PURE__ */ l("div", {
1469
+ class: "sqc-suggestions",
1470
+ children: i.map((e) => /* @__PURE__ */ l("button", {
1471
+ type: "button",
1472
+ class: "sqc-suggestion",
1473
+ onClick: () => u(e),
1474
+ children: e
1475
+ }, e))
1476
+ })
1477
+ ]
1478
+ });
1479
+ }
1480
+ //#endregion
1481
+ //#region src/components/ChatbotWidget.tsx
1482
+ var Ze = { width: "min(392px, 100vw)" }, Qe = /* @__PURE__ */ new Set(["sessionId"]);
1483
+ function $e(e) {
1484
+ let t = e.replace(/Id$|Ref$/, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim().toLowerCase();
1485
+ return t ? t.charAt(0).toUpperCase() + t.slice(1) : e;
1486
+ }
1487
+ function et(e) {
1488
+ if (!e) return [];
1489
+ let t = [];
1490
+ for (let [n, r] of Object.entries(e)) {
1491
+ if (Qe.has(n) || typeof r != "string" && !w(r)) continue;
1492
+ let e = C(r);
1493
+ e && t.push({
1494
+ label: $e(n),
1495
+ value: e
1496
+ });
1497
+ }
1498
+ return t;
1499
+ }
1500
+ function tt(e, t) {
1501
+ return e?.trim() ? e : t;
1502
+ }
1503
+ function nt(t) {
1504
+ let [n, r] = e(!1);
1505
+ return v(() => {
1506
+ if (t !== "auto" || typeof matchMedia != "function") return;
1507
+ let e = matchMedia("(prefers-color-scheme: dark)");
1508
+ r(e.matches);
1509
+ let n = (e) => r(e.matches);
1510
+ return e.addEventListener("change", n), () => e.removeEventListener("change", n);
1511
+ }, [t]), t === "dark" ? "dark" : t === "light" ? "light" : n ? "dark" : "light";
1512
+ }
1513
+ function rt(t) {
1514
+ a();
1515
+ let n = t.persistOpen ?? !0, [s, c] = e(() => k(t.defaultOpen, n)), [u, d] = e(!1), [f, p] = e(!1), m = o(null), h = o(null), g = nt(t.theme ?? "light"), _ = y(() => b(t.locale), [t.locale]), x = _.t, S = tt(t.heading, x.heading), C = tt(t.assistantName, x.assistant), w = tt(t.greeting, x.greeting), T = t.onEvent, { send: E, reset: D, decide: j, stop: M, start: N, resets: P, busy: F, messages: I, withHuman: L, branding: R, sessionId: z, handles: B, addressee: te, agentHandle: V, attachments: H, uploading: U, attachmentError: W, attach: G, detach: K, loadAttachment: q } = be({
1516
+ embedKey: t.embedKey,
1517
+ user: t.user,
1518
+ scope: t.scope,
1519
+ getSubjectToken: t.getSubjectToken,
1520
+ agent: t.agent,
1521
+ context: t.context,
1522
+ greeting: w,
1523
+ locale: _,
1524
+ onEvent: T
1525
+ });
1526
+ v(() => {
1527
+ !s && I.some((e) => e.role === "assistant" && e.id !== "greeting") && p(!0);
1528
+ }, [I, s]);
1529
+ let J = o(s);
1530
+ J.current = s;
1531
+ let Y = i(() => {
1532
+ p(!1), !J.current && (J.current = !0, c(!0), n && O(!0), T?.({
1533
+ type: "chatbot-open",
1534
+ sessionId: z
1535
+ }));
1536
+ }, [
1537
+ T,
1538
+ n,
1539
+ z
1540
+ ]), X = i(() => {
1541
+ J.current && (J.current = !1, c(!1), n && O(!1), T?.({
1542
+ type: "chatbot-close",
1543
+ sessionId: z
1544
+ }), h.current?.focus());
1545
+ }, [
1546
+ T,
1547
+ n,
1548
+ z
1549
+ ]);
1550
+ v(() => {
1551
+ s && N();
1552
+ }, [
1553
+ s,
1554
+ P,
1555
+ N
1556
+ ]);
1557
+ let ne = B.length >= 2, re = ee(I, V || void 0), [ie, ae] = e(void 0), oe = o(void 0), se = i((e) => {
1558
+ oe.current = e, ae(e);
1559
+ }, []);
1560
+ v(() => {
1561
+ oe.current = void 0, ae(void 0);
1562
+ }, [re]);
1563
+ let Z = i((e) => {
1564
+ d(!0), E(ne ? A(e, oe.current, re) : e);
1565
+ }, [
1566
+ E,
1567
+ ne,
1568
+ re
1569
+ ]), ce = i(() => {
1570
+ d(!1), p(!1), D();
1571
+ }, [D]), Q = o({
1572
+ openPanel: Y,
1573
+ closePanel: X,
1574
+ send: Z,
1575
+ reset: ce,
1576
+ sessionId: z
1577
+ });
1578
+ Q.current = {
1579
+ openPanel: Y,
1580
+ closePanel: X,
1581
+ send: Z,
1582
+ reset: ce,
1583
+ sessionId: z
1584
+ };
1585
+ let le = o({
1586
+ open: () => Q.current.openPanel(),
1587
+ close: () => Q.current.closePanel(),
1588
+ toggle: () => J.current ? Q.current.closePanel() : Q.current.openPanel(),
1589
+ reset: () => Q.current.reset(),
1590
+ send: (e) => {
1591
+ Q.current.openPanel(), Q.current.send(e);
1592
+ },
1593
+ isOpen: () => J.current,
1594
+ sessionId: () => Q.current.sessionId
1595
+ }), $ = t.bind;
1596
+ r(() => ($?.(le.current), () => $?.(null)), [$]), v(() => {
1597
+ if (!s) return;
1598
+ let e = (e) => {
1599
+ e.key === "Escape" && (e.stopPropagation(), X());
1600
+ };
1601
+ return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
1602
+ }, [X, s]);
1603
+ let ue = y(() => I.some((e) => e.id !== "greeting"), [I]), de = y(() => et(t.context), [t.context]), fe = {
1604
+ ...t.accent ? { "--sqc-accent": t.accent } : {},
1605
+ "--sqc-width": t.width ?? Ze.width
1606
+ };
1607
+ return /* @__PURE__ */ l("div", {
1608
+ class: "sqc",
1609
+ "data-theme": g,
1610
+ "data-position": t.position ?? "bottom-right",
1611
+ "data-layout": t.layout ?? "sidebar",
1612
+ "data-open": s ? "true" : "false",
1613
+ style: fe,
1614
+ children: [/* @__PURE__ */ l("button", {
1615
+ ref: h,
1616
+ type: "button",
1617
+ class: "sqc-launcher",
1618
+ "aria-label": S,
1619
+ "aria-expanded": s,
1620
+ "aria-haspopup": "dialog",
1621
+ onClick: Y,
1622
+ children: [/* @__PURE__ */ l("span", {
1623
+ class: "sqc-launcher__icon",
1624
+ children: /* @__PURE__ */ l("slot", {
1625
+ name: "launcher-icon",
1626
+ class: "sqc-slot-icon",
1627
+ children: /* @__PURE__ */ l(Ye, {})
1628
+ })
1629
+ }), f && /* @__PURE__ */ l("span", {
1630
+ class: "sqc-launcher__badge",
1631
+ "aria-hidden": "true"
1632
+ })]
1633
+ }), /* @__PURE__ */ l("aside", {
1634
+ ref: m,
1635
+ class: "sqc-panel",
1636
+ role: "dialog",
1637
+ "aria-modal": "false",
1638
+ "aria-label": S,
1639
+ ...s ? {} : { inert: !0 },
1640
+ children: [/* @__PURE__ */ l("header", {
1641
+ class: "sqc-header",
1642
+ children: [
1643
+ /* @__PURE__ */ l("span", {
1644
+ class: "sqc-header__icon",
1645
+ "aria-hidden": "true",
1646
+ children: /* @__PURE__ */ l(Ye, {})
1647
+ }),
1648
+ /* @__PURE__ */ l("div", {
1649
+ class: "sqc-header__titles",
1650
+ children: [/* @__PURE__ */ l("p", {
1651
+ class: "sqc-header__heading",
1652
+ children: S
1653
+ }), /* @__PURE__ */ l("p", {
1654
+ class: "sqc-header__sub",
1655
+ children: tt(t.subheading, x.subheading)
1656
+ })]
1657
+ }),
1658
+ /* @__PURE__ */ l("button", {
1659
+ type: "button",
1660
+ class: "sqc-icon-btn",
1661
+ onClick: ce,
1662
+ "aria-label": x.newConversation,
1663
+ "data-tip": x.newConversation,
1664
+ children: /* @__PURE__ */ l("svg", {
1665
+ viewBox: "0 0 24 24",
1666
+ fill: "none",
1667
+ stroke: "currentColor",
1668
+ "stroke-width": "1.8",
1669
+ children: /* @__PURE__ */ l("path", {
1670
+ d: "M20 12a8 8 0 1 1-2.6-5.9M20 4v4h-4",
1671
+ "stroke-linecap": "round"
1672
+ })
1673
+ })
1674
+ }),
1675
+ /* @__PURE__ */ l("button", {
1676
+ type: "button",
1677
+ class: "sqc-icon-btn",
1678
+ onClick: X,
1679
+ "aria-label": x.close,
1680
+ "data-tip": x.closeTitle,
1681
+ children: /* @__PURE__ */ l("svg", {
1682
+ viewBox: "0 0 24 24",
1683
+ fill: "none",
1684
+ stroke: "currentColor",
1685
+ "stroke-width": "1.8",
1686
+ children: /* @__PURE__ */ l("path", {
1687
+ d: "M6 6l12 12M18 6L6 18",
1688
+ "stroke-linecap": "round"
1689
+ })
1690
+ })
1691
+ })
1692
+ ]
1693
+ }), /* @__PURE__ */ l("div", {
1694
+ class: "sqc-panel__body",
1695
+ children: [ne && /* @__PURE__ */ l(Ce, {
1696
+ handles: B,
1697
+ active: ie ?? re,
1698
+ disabled: L,
1699
+ onPick: se,
1700
+ label: x.handles.rail
1701
+ }), /* @__PURE__ */ l("div", {
1702
+ class: "sqc-panel__main",
1703
+ children: [
1704
+ (t.showContext ?? !0) && de.length > 0 && /* @__PURE__ */ l("div", {
1705
+ class: "sqc-context",
1706
+ "aria-label": x.context.region,
1707
+ children: de.map((e) => /* @__PURE__ */ l("span", {
1708
+ class: "sqc-chip",
1709
+ title: `${e.label}: ${e.value}`,
1710
+ children: [/* @__PURE__ */ l("b", { children: e.label }), e.value]
1711
+ }, e.label))
1712
+ }),
1713
+ /* @__PURE__ */ l(Xe, {
1714
+ messages: I,
1715
+ locale: _,
1716
+ assistantName: C,
1717
+ suggestions: t.suggestions,
1718
+ showSuggestions: !u && !ue,
1719
+ busy: F,
1720
+ withHuman: L,
1721
+ onSuggestion: Z,
1722
+ onChoice: Z,
1723
+ onDecide: j,
1724
+ onCompose: () => m.current?.querySelector(".sqc-composer__input")?.focus(),
1725
+ onLoadAttachment: q
1726
+ }),
1727
+ /* @__PURE__ */ l(ke, {
1728
+ placeholder: tt(t.placeholder, x.placeholder),
1729
+ locale: _,
1730
+ busy: F,
1731
+ autoFocus: s,
1732
+ handles: B,
1733
+ addressee: te,
1734
+ attachments: H,
1735
+ uploading: U,
1736
+ attachmentError: W ? x.attachments[W] : void 0,
1737
+ onAttach: G,
1738
+ onDetach: K,
1739
+ onSend: Z,
1740
+ onStop: M
1741
+ }),
1742
+ /* @__PURE__ */ l("p", {
1743
+ class: "sqc-hint",
1744
+ children: x.hint
1745
+ }),
1746
+ R && /* @__PURE__ */ l("p", {
1747
+ class: "sqc-powered",
1748
+ children: /* @__PURE__ */ l("a", {
1749
+ href: "https://squadico.com",
1750
+ target: "_blank",
1751
+ rel: "noopener noreferrer",
1752
+ children: x.poweredBy
1753
+ })
1754
+ })
1755
+ ]
1756
+ })]
1757
+ })]
1758
+ })]
1759
+ });
1760
+ }
1761
+ //#endregion
1762
+ //#region src/styles.css?inline
1763
+ var it = ":host{--sqc-width:min(392px, 100vw);--sqc-height:640px;--sqc-z:2147480000;--sqc-radius:16px;--sqc-font-family:\"Plus Jakarta Sans\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif;--sqc-font-heading:var(--sqc-font-family);z-index:var(--sqc-z);pointer-events:none;font-family:var(--sqc-font-family);-webkit-font-smoothing:antialiased;text-align:left;font-size:14px;line-height:1.5;display:block;position:fixed;top:0;bottom:0;left:0;right:0;margin:0!important}:host([hidden]){display:none}.sqc{--sqc-neutral-50:#f8fafc;--sqc-neutral-100:#f1f5f9;--sqc-neutral-200:#e2e8f0;--sqc-neutral-300:#cbd5e1;--sqc-neutral-400:#94a3b8;--sqc-neutral-500:#64748b;--sqc-neutral-600:#475569;--sqc-neutral-900:#0f172a;--sqc-error-50:#fff1f2;--sqc-error-100:#ffe4e6;--sqc-error-600:#e11d48;--sqc-accent-default:#000;--sqc-accent-color:var(--sqc-accent,var(--sqc-accent-default));--sqc-on-accent:#fff;--sqc-accent-hover:color-mix(in oklab, var(--sqc-accent-color) 84%, var(--sqc-on-accent));--sqc-accent-fg:var(--sqc-accent,var(--sqc-text));--sqc-bg:#fff;--sqc-surface:var(--sqc-neutral-50);--sqc-selected:var(--sqc-neutral-100);--sqc-border:var(--sqc-neutral-200);--sqc-border-strong:var(--sqc-neutral-300);--sqc-text:var(--sqc-neutral-900);--sqc-text-muted:var(--sqc-neutral-500);--sqc-link:#2563eb;--sqc-bubble-user:var(--sqc-accent-color);--sqc-bubble-user-text:var(--sqc-on-accent);--sqc-code-bg:var(--sqc-neutral-100);--sqc-disabled:var(--sqc-neutral-300);--sqc-shadow:0 10px 15px -3px #0f172a1a, 0 4px 6px -4px #0f172a1a;--sqc-shadow-bottom:0 6px 8px -6px #0f172a2e;--sqc-focus:0 0 0 2px var(--sqc-bg), 0 0 0 4px #0f172a4d;--sqc-focus-input:0 0 0 3px #0f172a1a;--sqc-danger:var(--sqc-error-600);color:var(--sqc-text);position:absolute;top:0;bottom:0;left:0;right:0}.sqc[data-theme=dark]{--sqc-neutral-50:#172033;--sqc-neutral-100:#1e293b;--sqc-neutral-200:#334155;--sqc-neutral-300:#475569;--sqc-neutral-400:#64748b;--sqc-neutral-500:#94a3b8;--sqc-neutral-600:#cbd5e1;--sqc-neutral-900:#f8fafc;--sqc-error-50:#2a0a12;--sqc-error-100:#4c0519;--sqc-error-600:#fb7185;--sqc-accent-default:#fff;--sqc-on-accent:#0f172a;--sqc-bg:#0f172a;--sqc-link:#60a5fa;--sqc-code-bg:#020617;--sqc-shadow:0 10px 24px -4px #0000008c;--sqc-shadow-bottom:0 6px 8px -6px #0000008c;--sqc-focus:0 0 0 2px var(--sqc-bg), 0 0 0 4px #f8fafc59;--sqc-focus-input:0 0 0 3px #f8fafc1f}@supports (color:oklch(from red l c h)){.sqc{--sqc-on-accent:oklch(from var(--sqc-accent-color) clamp(.208, (.62 - l) * 1000, 1) 0 0)}}.sqc *,.sqc :before,.sqc :after{box-sizing:border-box}.sqc-launcher{background:var(--sqc-accent-color);width:56px;height:56px;color:var(--sqc-on-accent);cursor:pointer;pointer-events:auto;box-shadow:var(--sqc-shadow);border:none;border-radius:50%;place-items:center;padding:0;transition:transform .18s,opacity .18s,background .18s,box-shadow .18s;display:grid;position:absolute;bottom:24px;right:24px}.sqc[data-position=bottom-left] .sqc-launcher{left:24px;right:auto}.sqc-launcher:hover{background:var(--sqc-accent-hover);transform:scale(1.06)}.sqc-launcher:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc[data-open=true] .sqc-launcher{opacity:0;pointer-events:none;transform:scale(.5)}.sqc-launcher__icon svg{width:26px;height:26px;display:block}.sqc-slot-icon::slotted(*){justify-content:center;align-items:center;width:26px;height:26px;display:inline-flex}.sqc-launcher__badge{background:var(--sqc-error-600);border:2px solid var(--sqc-bg);border-radius:50%;width:12px;height:12px;position:absolute;top:6px;right:6px}.sqc-panel{width:var(--sqc-width);background:var(--sqc-bg);border-left:1px solid var(--sqc-border);box-shadow:var(--sqc-shadow);pointer-events:auto;visibility:hidden;flex-direction:column;transition:transform .26s cubic-bezier(.22,1,.36,1),visibility 0s linear .26s;display:flex;position:absolute;top:0;bottom:0;right:0;transform:translate(100%)}.sqc-panel__body{flex:1;min-height:0;display:flex}.sqc-panel__main{flex-direction:column;flex:1;min-width:0;min-height:0;display:flex}.sqc-rail{border-right:1px solid var(--sqc-border);background:color-mix(in oklab, var(--sqc-accent-color) 7%, var(--sqc-bg));flex-direction:column;flex-shrink:0;align-items:stretch;gap:6px;width:72px;padding:12px 0;display:flex;overflow:visible}.sqc-rail__item{color:var(--sqc-text-muted);font:inherit;cursor:pointer;background:0 0;border:0;flex-direction:column;align-items:center;gap:4px;padding:4px 0;display:flex;position:relative}.sqc-rail__label{white-space:nowrap;text-overflow:ellipsis;max-width:64px;font-size:10.5px;font-weight:500;line-height:1.2;overflow:hidden}.sqc-rail__item:hover,.sqc-rail__item[aria-pressed=true]{color:var(--sqc-text)}.sqc-rail__item[aria-pressed=true] .sqc-rail__label{font-weight:600}.sqc-rail__item .sqc-avatar{transition:box-shadow .15s}.sqc-rail__item[aria-pressed=true] .sqc-avatar{box-shadow:0 0 0 2px var(--sqc-bg), 0 0 0 4px var(--sqc-accent-color)}.sqc-rail__item:before{content:\"\";background:var(--sqc-text);border-radius:0 4px 4px 0;width:4px;height:0;transition:height .15s;position:absolute;top:24px;left:0;transform:translateY(-50%)}.sqc-rail__item:hover:before{height:12px}.sqc-rail__item[aria-pressed=true]:before{height:32px}.sqc-rail__item:focus-visible{outline:2px solid var(--sqc-accent-color);outline-offset:-2px;border-radius:8px}.sqc-rail__item:disabled{cursor:not-allowed;opacity:.5}.sqc-rail__item[data-tip]:after{content:attr(data-tip);z-index:2;background:var(--sqc-text);color:var(--sqc-bg);white-space:nowrap;pointer-events:none;opacity:0;border-radius:6px;padding:4px 8px;font-size:12px;font-weight:500;transition:opacity .12s;position:absolute;top:24px;left:calc(100% + 6px);transform:translateY(-50%)}.sqc-rail__item[data-tip]:hover:after{opacity:1}.sqc-rail__item[data-tip]:focus-visible:after{opacity:1}.sqc[data-open=true] .sqc-panel{visibility:visible;transition:transform .26s cubic-bezier(.22,1,.36,1),visibility;transform:translate(0)}.sqc[data-layout=floating] .sqc-panel{max-width:calc(100% - 48px);height:var(--sqc-height);border:1px solid var(--sqc-border);border-radius:var(--sqc-radius);opacity:0;transform-origin:100% 100%;max-height:calc(100% - 48px);transition:transform .22s cubic-bezier(.22,1,.36,1),opacity .22s,visibility 0s linear .22s;top:auto;bottom:24px;right:24px;overflow:hidden;transform:translateY(16px)scale(.96)}.sqc[data-layout=floating][data-position=bottom-left] .sqc-panel{transform-origin:0 100%;left:24px;right:auto}.sqc[data-layout=floating][data-open=true] .sqc-panel{opacity:1;transition:transform .22s cubic-bezier(.22,1,.36,1),opacity .22s,visibility;transform:none}.sqc-header{background:var(--sqc-bg);color:var(--sqc-text);border-bottom:1px solid var(--sqc-border);flex-shrink:0;align-items:center;gap:8px;padding:13px 12px 13px 16px;display:flex}.sqc-header__icon{color:var(--sqc-accent-fg);flex-shrink:0;place-items:center;display:grid}.sqc-header__icon svg{width:17px;height:17px;display:block}.sqc-header__titles{flex:1;min-width:0}.sqc-header__heading,.sqc-header__sub{text-overflow:ellipsis;white-space:nowrap;margin:0;overflow:hidden}.sqc-header__heading{font-family:var(--sqc-font-heading);letter-spacing:-.2px;font-size:15px;font-weight:700}.sqc-header__sub{color:var(--sqc-text-muted);font-size:12px}.sqc-icon-btn{width:26px;height:26px;color:var(--sqc-text-muted);cursor:pointer;background:0 0;border:none;border-radius:8px;flex-shrink:0;place-items:center;transition:background .15s;display:grid}.sqc-icon-btn:hover{background:var(--sqc-surface);color:var(--sqc-text)}.sqc-icon-btn:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc-icon-btn svg{width:16px;height:16px}.sqc-icon-btn[data-tip]{position:relative}.sqc-icon-btn[data-tip]:after{content:attr(data-tip);z-index:6;background:var(--sqc-text);color:var(--sqc-bg);font-family:var(--sqc-font-family);white-space:nowrap;pointer-events:none;opacity:0;border-radius:8px;padding:4px 8px;font-size:11px;font-weight:500;line-height:1.3;transition:opacity .12s .15s;position:absolute;top:calc(100% + 6px);right:0}.sqc-icon-btn[data-tip]:hover:after{opacity:1}.sqc-icon-btn[data-tip]:focus-visible:after{opacity:1}.sqc-history-pop{z-index:5;position:absolute;top:54px;left:0;right:0}.sqc-history{background:var(--sqc-bg);max-height:320px;box-shadow:var(--sqc-shadow-bottom);flex-direction:column;display:flex;overflow-y:auto}.sqc-history__empty{color:var(--sqc-text-muted);text-align:center;margin:0;padding:14px 16px;font-size:12px}.sqc-history__item{border:none;border-bottom:1px solid var(--sqc-border);width:100%;color:var(--sqc-text);text-align:left;cursor:pointer;background:0 0;flex-direction:column;gap:2px;padding:10px 16px;transition:background .15s;display:flex}.sqc-history__item:last-child{border-bottom:none}.sqc-history__item:hover{background:var(--sqc-surface)}.sqc-history__item:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc-history__item[aria-current=true]{background:var(--sqc-selected)}.sqc-history__item[aria-current=true] .sqc-history__title{color:var(--sqc-text);font-weight:600}.sqc-history__title{text-overflow:ellipsis;white-space:nowrap;font-size:13px;overflow:hidden}.sqc-history__date{color:var(--sqc-text-muted);font-size:11px}.sqc-context{background:var(--sqc-selected);border:1px solid var(--sqc-border);color:var(--sqc-text);border-radius:12px;flex-wrap:wrap;flex-shrink:0;align-items:center;gap:8px;margin:12px 16px 4px;padding:8px 11px;font-size:12px;display:flex}.sqc-chip{text-overflow:ellipsis;white-space:nowrap;align-items:baseline;gap:4px;max-width:100%;display:inline-flex;overflow:hidden}.sqc-chip b{font-weight:600}.sqc-chip:not(:last-child):after{content:\"·\";opacity:.5;margin-left:4px}.sqc-messages{overscroll-behavior:contain;background:var(--sqc-bg);scrollbar-width:thin;scrollbar-color:var(--sqc-neutral-300) transparent;flex-direction:column;flex:1;gap:13px;min-height:0;padding:12px 16px;display:flex;overflow-y:auto}.sqc-messages::-webkit-scrollbar{width:6px}.sqc-messages::-webkit-scrollbar-thumb{background:var(--sqc-neutral-300);border-radius:99px}.sqc-msg{flex-direction:column;max-width:93%;font-size:13.5px;display:flex}.sqc-msg--assistant{align-self:stretch}.sqc-msg--user{align-self:flex-end}.sqc-msg__who{color:var(--sqc-text-muted);align-items:center;gap:6px;margin-bottom:4px;font-size:11px;font-weight:500;display:flex}.sqc-msg__who svg{width:12px;height:12px;color:var(--sqc-accent-fg);flex-shrink:0}.sqc-avatar{background:var(--sqc-accent-color);color:var(--sqc-on-accent);-webkit-user-select:none;user-select:none;flex-shrink:0;justify-content:center;align-items:center;font-weight:600;line-height:1;display:inline-flex;overflow:hidden}.sqc-avatar img{object-fit:cover;width:100%;height:100%}.sqc-msg__unaddressed{color:var(--sqc-text-muted);margin:8px 0 0;font-size:11.5px;line-height:1.5}.sqc-msg__unaddressed code{background:var(--sqc-code-bg);color:var(--sqc-text);border-radius:4px;margin-right:4px;padding:1px 4px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px}.sqc-msg--user .sqc-msg__bubble{background:var(--sqc-bubble-user);color:var(--sqc-bubble-user-text);border-radius:var(--sqc-radius) var(--sqc-radius) 4px var(--sqc-radius);padding:9px 13px}.sqc-msg--error .sqc-msg__bubble{background:var(--sqc-error-50);color:var(--sqc-error-600);border:1px solid var(--sqc-error-100);border-radius:12px;padding:11px}.sqc-msg__body{overflow-wrap:anywhere}.sqc-msg--assistant .sqc-msg__body{font-size:14px;line-height:1.6}.sqc-msg__body>:first-child{margin-top:0}.sqc-msg__body>:last-child{margin-bottom:0}.sqc-msg__body p{white-space:pre-wrap;margin:0 0 8px}.sqc-msg__body ul,.sqc-msg__body ol{margin:0 0 8px;padding-left:20px}.sqc-msg__body li{margin-bottom:3px}.sqc-msg__body code{background:var(--sqc-code-bg);border-radius:4px;padding:1px 4px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.85em}.sqc-msg--user .sqc-msg__body code{background:#ffffff38}.sqc-msg__body pre{background:var(--sqc-code-bg);border-radius:8px;margin:0 0 8px;padding:9px 11px;overflow-x:auto}.sqc-msg__body pre code{background:0 0;padding:0}.sqc-msg__body a{color:inherit;text-underline-offset:2px;text-decoration:underline}.sqc-msg--assistant .sqc-msg__body a{color:var(--sqc-link);text-decoration:none}.sqc-msg--assistant .sqc-msg__body a:hover{text-decoration:underline}.sqc-msg__body h3,.sqc-msg__body h4,.sqc-msg__body h5,.sqc-msg__body h6{font-family:var(--sqc-font-heading);letter-spacing:-.2px;margin:12px 0 6px;font-weight:700;line-height:1.3}.sqc-msg__body h3{font-size:1.05em}.sqc-msg__body h4{font-size:1em}.sqc-msg__body h5,.sqc-msg__body h6{font-size:.94em}.sqc-msg__body ul ul,.sqc-msg__body ul ol,.sqc-msg__body ol ul,.sqc-msg__body ol ol{margin:3px 0 0}.sqc-msg__body blockquote{border-left:2px solid var(--sqc-border-strong);color:var(--sqc-text-muted);white-space:pre-wrap;margin:0 0 8px;padding:2px 0 2px 10px}.sqc-msg--user .sqc-msg__body blockquote{color:inherit;opacity:.85;border-left-color:#ffffff73}.sqc-msg__body hr{border:0;border-top:1px solid var(--sqc-border);margin:10px 0}.sqc-msg--user .sqc-msg__body hr{border-top-color:#ffffff4d}.sqc-msg__body del{opacity:.7}.sqc-selection{flex-direction:column;gap:10px;margin:2px 0;display:flex}.sqc-selection__question{flex-direction:column;gap:2px;display:flex}.sqc-selection__ask{font-family:var(--sqc-font-family);color:var(--sqc-text);margin:0;font-size:13px;font-weight:600}.sqc-selection__actions{display:flex}.sqc-selection__validate{height:32px;font-family:var(--sqc-font-family);color:var(--sqc-on-accent);background:var(--sqc-accent-color);cursor:pointer;border:1px solid #0000;border-radius:12px;flex:auto;justify-content:center;align-items:center;padding:0 12px;font-size:13px;font-weight:600;transition:filter .12s,background .12s;display:inline-flex}.sqc-selection__validate:hover:not(:disabled){background:var(--sqc-accent-hover)}.sqc-selection__validate:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc-selection__validate:disabled{cursor:not-allowed;color:#fff;background:var(--sqc-disabled)}.sqc-selection__hint{font-family:var(--sqc-font-family);color:var(--sqc-text-muted);margin:0;font-size:11.5px}.sqc-msg__time{color:var(--sqc-text-muted);font-variant-numeric:tabular-nums;margin-top:3px;font-size:10px;display:block}.sqc-msg--user .sqc-msg__time{color:#ffffffb3;text-align:right}.sqc-caret{vertical-align:text-bottom;background:currentColor;width:2px;height:1em;margin-left:2px;animation:1s step-end infinite sqc-blink;display:inline-block}@keyframes sqc-blink{0%,to{opacity:1}50%{opacity:0}}.sqc-typing{gap:3px;padding:2px 0;display:inline-flex}.sqc-typing i{background:var(--sqc-neutral-400);border-radius:50%;width:5px;height:5px;animation:1.2s infinite sqc-pulse}.sqc-typing i:nth-child(2){animation-delay:.2s}.sqc-typing i:nth-child(3){animation-delay:.4s}.sqc-waiting{align-items:center;gap:8px;display:inline-flex}.sqc-activity{color:var(--sqc-text-muted);font-size:12px}@keyframes sqc-pulse{0%,60%,to{opacity:.25}30%{opacity:1}}.sqc-suggestions{flex-direction:column;gap:7px;display:flex}.sqc-suggestion{border:1px solid var(--sqc-border);background:var(--sqc-bg);width:100%;color:var(--sqc-text);font-family:var(--sqc-font-family);cursor:pointer;text-align:left;border-radius:12px;align-items:center;gap:8px;padding:8px 11px;font-size:12.5px;transition:background .15s,border-color .15s;display:flex}.sqc-suggestion:before{content:\"\";background:var(--sqc-accent-fg);border-radius:50%;flex:none;width:5px;height:5px}.sqc-suggestion:hover{background:var(--sqc-surface);border-color:var(--sqc-border-strong)}.sqc-suggestion:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc-composer{border-top:1px solid var(--sqc-border);background:var(--sqc-bg);flex-wrap:wrap;flex-shrink:0;align-items:flex-end;gap:8px;padding:12px 14px;display:flex}.sqc-composer--dropping{outline:2px dashed var(--sqc-accent-color);outline-offset:-4px}.sqc-attachments{flex-wrap:wrap;flex-basis:100%;gap:6px;display:flex}.sqc-attachments--sent{margin-top:8px}.sqc-chip{border:1px solid var(--sqc-border);background:var(--sqc-selected);max-width:100%;color:var(--sqc-text);border-radius:999px;align-items:center;gap:4px;padding:3px 4px 3px 10px;font-size:12px;display:inline-flex}.sqc-chip--waiting{opacity:.6;padding-right:10px}.sqc-chip__name{text-overflow:ellipsis;white-space:nowrap;max-width:180px;overflow:hidden}.sqc-chip__remove{width:18px;height:18px;color:var(--sqc-text-muted);cursor:pointer;background:0 0;border:0;border-radius:999px;justify-content:center;align-items:center;padding:0;font-size:14px;line-height:1;display:inline-flex}.sqc-chip__remove:hover{background:var(--sqc-selected);color:var(--sqc-text)}.sqc-attachments__error{color:var(--sqc-error-600);flex-basis:100%;margin:0;font-size:12px}.sqc-attachment__image{border-radius:12px;max-width:100%;max-height:180px;display:block}.sqc-attachment__chart{flex-basis:100%;min-width:0}.sqc-file-input{display:none}.sqc-btn--attach{color:var(--sqc-text-muted);background:0 0}.sqc-btn--attach:hover{background:var(--sqc-selected);color:var(--sqc-text)}.sqc-composer__field{flex:1;min-width:0;position:relative}.sqc-composer__input{border:1px solid var(--sqc-border-strong);background:var(--sqc-bg);width:100%;min-height:38px;max-height:132px;color:var(--sqc-text);font-family:var(--sqc-font-family);resize:none;border-radius:12px;outline:none;padding:9px 12px;font-size:13.5px;line-height:1.4;transition:border-color .15s,box-shadow .15s;display:block;overflow-y:hidden}.sqc-composer__input::placeholder{color:var(--sqc-neutral-400)}.sqc-composer__input:focus{border-color:var(--sqc-text);box-shadow:var(--sqc-focus-input)}.sqc-mentions{z-index:2;border:1px solid var(--sqc-border);background:var(--sqc-bg);max-height:184px;box-shadow:var(--sqc-shadow);scrollbar-width:thin;border-radius:12px;margin:0;padding:4px;list-style:none;position:absolute;bottom:calc(100% + 6px);left:0;right:0;overflow-y:auto}.sqc-mention{cursor:pointer;color:var(--sqc-text);border-radius:8px;align-items:baseline;gap:6px;padding:6px 8px;font-size:12.5px;display:flex}.sqc-mention--active{background:var(--sqc-neutral-100)}.sqc-mention__icon{flex-shrink:0}.sqc-mention__handle{font-weight:600}.sqc-mention__name{text-overflow:ellipsis;white-space:nowrap;color:var(--sqc-text-muted);overflow:hidden}.sqc-composer__count{color:var(--sqc-text-muted);pointer-events:none;font-variant-numeric:tabular-nums;font-size:10px;position:absolute;bottom:4px;right:8px}.sqc-btn{cursor:pointer;border:none;border-radius:12px;flex-shrink:0;place-items:center;width:38px;height:38px;transition:background .15s,opacity .15s;display:grid}.sqc-btn svg{width:17px;height:17px}.sqc-btn--send{background:var(--sqc-accent-color);color:var(--sqc-on-accent)}.sqc-btn--send:hover:not(:disabled){background:var(--sqc-accent-hover)}.sqc-btn--send:disabled{background:var(--sqc-disabled);color:#fff;cursor:not-allowed}.sqc-btn--stop{background:var(--sqc-bg);color:var(--sqc-text);border:1px solid var(--sqc-border)}.sqc-btn--stop:hover{border-color:var(--sqc-border-strong);background:var(--sqc-surface)}.sqc-btn:focus-visible{box-shadow:var(--sqc-focus);outline:none}.sqc-hint{padding:0 16px max(9px, env(safe-area-inset-bottom));color:var(--sqc-text-muted);text-align:center;flex-shrink:0;margin:0;font-size:10.5px;line-height:1.35}.sqc-powered{padding:0 16px max(9px, env(safe-area-inset-bottom));text-align:center;flex-shrink:0;margin:0;font-size:10.5px;line-height:1.35}.sqc-powered a{color:var(--sqc-text-muted);text-decoration:none}.sqc-powered a:hover{text-decoration:underline}@media (max-width:520px){.sqc{--sqc-width:100vw}.sqc-panel{border-left:none}.sqc-launcher{bottom:16px;right:16px}.sqc[data-position=bottom-left] .sqc-launcher{left:16px}.sqc[data-layout=floating] .sqc-panel,.sqc[data-layout=floating][data-position=bottom-left] .sqc-panel{border:none;border-radius:0;max-width:none;height:auto;max-height:none;top:0;bottom:0;left:0;right:0}}@media (prefers-reduced-motion:reduce){.sqc-launcher,.sqc-panel,.sqc-btn,.sqc-suggestion,.sqc-choice,.sqc-confirm__btn,.sqc-icon-btn,.sqc-icon-btn[data-tip]:after,.sqc-rail__item:before,.sqc-rail__item[data-tip]:after,.sqc-rail__item .sqc-avatar{transition:none}.sqc-typing i,.sqc-caret{animation:none}}.sqc-with-human{border:1px solid var(--sqc-border);background:var(--sqc-selected);color:var(--sqc-neutral-600);border-radius:12px;margin:8px 0 0;padding:8px 12px;font-size:13px}", at = "squadico-chatbot", ot = [
1764
+ "embed-key",
1765
+ "context",
1766
+ "user",
1767
+ "agent",
1768
+ "heading",
1769
+ "subheading",
1770
+ "assistant-name",
1771
+ "placeholder",
1772
+ "greeting",
1773
+ "suggestions",
1774
+ "width",
1775
+ "accent",
1776
+ "theme",
1777
+ "position",
1778
+ "layout",
1779
+ "open",
1780
+ "persist-open",
1781
+ "show-context",
1782
+ "locale"
1783
+ ], st;
1784
+ function ct() {
1785
+ if (st !== void 0) return st;
1786
+ try {
1787
+ let e = new CSSStyleSheet();
1788
+ e.replaceSync(it), st = e;
1789
+ } catch {
1790
+ st = null;
1791
+ }
1792
+ return st;
1793
+ }
1794
+ function lt(e, t) {
1795
+ typeof console < "u" && console.warn(`[${at}] ${e}`, t ?? "");
1796
+ }
1797
+ function ut(e) {
1798
+ if (!(!e || !e.trim())) try {
1799
+ let t = JSON.parse(e);
1800
+ if (t && typeof t == "object" && !Array.isArray(t)) {
1801
+ let e = t;
1802
+ if (typeof e.id == "string" && e.id) return {
1803
+ id: e.id,
1804
+ name: typeof e.name == "string" && e.name ? e.name : void 0,
1805
+ digest: typeof e.digest == "string" && e.digest ? e.digest : void 0
1806
+ };
1807
+ }
1808
+ lt("the \"user\" attribute needs an object with an id", e);
1809
+ } catch (e) {
1810
+ lt("the \"user\" attribute is not valid JSON", e);
1811
+ }
1812
+ }
1813
+ function dt(e) {
1814
+ if (!(!e || !e.trim())) try {
1815
+ let t = JSON.parse(e);
1816
+ if (t && typeof t == "object" && !Array.isArray(t)) return t;
1817
+ lt("the `context` attribute must be a JSON object", e);
1818
+ } catch (e) {
1819
+ lt("the `context` attribute is not valid JSON", e);
1820
+ }
1821
+ }
1822
+ function ft(e) {
1823
+ if (!(!e || !e.trim())) {
1824
+ if (e.trim().startsWith("[")) try {
1825
+ let t = JSON.parse(e);
1826
+ if (Array.isArray(t)) return t.map(String);
1827
+ } catch (e) {
1828
+ lt("the `suggestions` attribute is not valid JSON", e);
1829
+ return;
1830
+ }
1831
+ return e.split("|").map((e) => e.trim()).filter(Boolean);
1832
+ }
1833
+ }
1834
+ function pt(e) {
1835
+ if (e !== null) return e !== "false" && e !== "0";
1836
+ }
1837
+ function mt(e) {
1838
+ return e === "dark" || e === "light" || e === "auto" ? e : void 0;
1839
+ }
1840
+ function ht(e) {
1841
+ return e === "bottom-left" || e === "bottom-right" ? e : void 0;
1842
+ }
1843
+ function gt(e) {
1844
+ return e === "floating" || e === "sidebar" ? e : void 0;
1845
+ }
1846
+ var _t = [
1847
+ "context",
1848
+ "embedKey",
1849
+ "user",
1850
+ "scope",
1851
+ "getSubjectToken",
1852
+ "agent"
1853
+ ];
1854
+ function vt() {
1855
+ var e, t, r, i, a, o, d, p, h, g, _, v, y, b, x;
1856
+ return t = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakSet(), b = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), e = class extends HTMLElement {
1857
+ constructor() {
1858
+ super(), u(this, y), f(this, t, void 0), f(this, r, null), f(this, i, !1), f(this, a, !1), f(this, o, ""), f(this, d, void 0), f(this, p, void 0), f(this, h, void 0), f(this, g, void 0), f(this, _, void 0), f(this, v, void 0), f(this, b, (e) => {
1859
+ let { type: t, ...n } = e;
1860
+ s(o, this, n.sessionId), this.dispatchEvent(new CustomEvent(t, {
1861
+ detail: n,
1862
+ bubbles: !0,
1863
+ composed: !0
1864
+ }));
1865
+ }), f(this, x, (e) => {
1866
+ s(r, this, e), e && s(o, this, e.sessionId());
1867
+ });
1868
+ let e = this.attachShadow({ mode: "open" }), n = ct();
1869
+ if (n) e.adoptedStyleSheets = [n];
1870
+ else {
1871
+ let t = document.createElement("style");
1872
+ t.textContent = it, e.append(t);
1873
+ }
1874
+ s(t, this, document.createElement("div")), e.append(c(t, this));
1875
+ for (let e of _t) {
1876
+ if (!Object.hasOwn(this, e)) continue;
1877
+ let t = this[e];
1878
+ delete this[e], this[e] = t;
1879
+ }
1880
+ }
1881
+ connectedCallback() {
1882
+ s(a, this, !0), m(y, this, C).call(this);
1883
+ }
1884
+ disconnectedCallback() {
1885
+ s(a, this, !1), n(null, c(t, this)), s(r, this, null);
1886
+ }
1887
+ attributeChangedCallback(e, t, n) {
1888
+ if (t !== n) {
1889
+ if (e === "open" && c(r, this)) {
1890
+ pt(n) ? c(r, this).open() : c(r, this).close();
1891
+ return;
1892
+ }
1893
+ m(y, this, S).call(this);
1894
+ }
1895
+ }
1896
+ get context() {
1897
+ return c(d, this) ?? dt(this.getAttribute("context"));
1898
+ }
1899
+ set context(e) {
1900
+ s(d, this, e), m(y, this, S).call(this);
1901
+ }
1902
+ get embedKey() {
1903
+ return c(v, this) ?? this.getAttribute("embed-key") ?? void 0;
1904
+ }
1905
+ set embedKey(e) {
1906
+ s(v, this, e), m(y, this, S).call(this);
1907
+ }
1908
+ get scope() {
1909
+ return c(h, this);
1910
+ }
1911
+ set scope(e) {
1912
+ s(h, this, e), m(y, this, S).call(this);
1913
+ }
1914
+ get user() {
1915
+ return c(p, this) ?? ut(this.getAttribute("user"));
1916
+ }
1917
+ set user(e) {
1918
+ s(p, this, e), m(y, this, S).call(this);
1919
+ }
1920
+ get getSubjectToken() {
1921
+ return c(g, this);
1922
+ }
1923
+ set getSubjectToken(e) {
1924
+ s(g, this, e), m(y, this, S).call(this);
1925
+ }
1926
+ get agent() {
1927
+ return c(_, this) ?? this.getAttribute("agent") ?? void 0;
1928
+ }
1929
+ set agent(e) {
1930
+ s(_, this, e), m(y, this, S).call(this);
1931
+ }
1932
+ get open() {
1933
+ return c(r, this)?.isOpen() ?? pt(this.getAttribute("open")) ?? !1;
1934
+ }
1935
+ set open(e) {
1936
+ e ? this.openChat() : this.closeChat();
1937
+ }
1938
+ get sessionId() {
1939
+ return c(r, this)?.sessionId() ?? c(o, this);
1940
+ }
1941
+ openChat() {
1942
+ c(r, this)?.open();
1943
+ }
1944
+ closeChat() {
1945
+ c(r, this)?.close();
1946
+ }
1947
+ toggleChat() {
1948
+ c(r, this)?.toggle();
1949
+ }
1950
+ reset() {
1951
+ c(r, this)?.reset();
1952
+ }
1953
+ sendMessage(e) {
1954
+ if (!c(r, this)) {
1955
+ lt("sendMessage() called before the component was mounted — ignored");
1956
+ return;
1957
+ }
1958
+ c(r, this).send(e);
1959
+ }
1960
+ }, F(e, "observedAttributes", ot), e;
1961
+ function S() {
1962
+ c(i, this) || !c(a, this) || (s(i, this, !0), queueMicrotask(() => {
1963
+ s(i, this, !1), c(a, this) && m(y, this, C).call(this);
1964
+ }));
1965
+ }
1966
+ function C() {
1967
+ let e = (e) => this.getAttribute(e) ?? void 0;
1968
+ n(/* @__PURE__ */ l(rt, {
1969
+ embedKey: this.embedKey,
1970
+ context: this.context,
1971
+ user: this.user,
1972
+ scope: this.scope,
1973
+ getSubjectToken: this.getSubjectToken,
1974
+ agent: this.agent,
1975
+ heading: e("heading"),
1976
+ subheading: e("subheading"),
1977
+ assistantName: e("assistant-name"),
1978
+ placeholder: e("placeholder"),
1979
+ greeting: e("greeting"),
1980
+ suggestions: ft(this.getAttribute("suggestions")),
1981
+ width: e("width"),
1982
+ accent: e("accent"),
1983
+ theme: mt(this.getAttribute("theme")),
1984
+ position: ht(this.getAttribute("position")),
1985
+ layout: gt(this.getAttribute("layout")),
1986
+ defaultOpen: pt(this.getAttribute("open")) ?? !1,
1987
+ persistOpen: pt(this.getAttribute("persist-open")) ?? !0,
1988
+ showContext: pt(this.getAttribute("show-context")) ?? !0,
1989
+ locale: e("locale"),
1990
+ onEvent: c(b, this),
1991
+ bind: c(x, this)
1992
+ }), c(t, this));
1993
+ }
1994
+ }
1995
+ var yt;
1996
+ function bt(e = at) {
1997
+ typeof window > "u" || typeof HTMLElement > "u" || (yt ?? (yt = vt()), window.customElements.get(e) || window.customElements.define(e, yt));
1998
+ }
1999
+ //#endregion
2000
+ //#region src/index.ts
2001
+ bt();
2002
+ //#endregion
2003
+ export { L as a, R as i, bt as n, k as o, I as r, at as t };
2004
+
2005
+ //# sourceMappingURL=src-BWDC0W4O.js.map