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