@useago/sdk 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.js CHANGED
@@ -1,614 +1,782 @@
1
- import { a as yt, i as wt, m as Et, o as St, s as Rt, t as _t } from "./AgoClient-Cwx_eYSu.js";
2
- import { r as kt, t as At } from "./createFormCollector-CyWisAkI.js";
3
- import { t as It } from "./createConversationSession-B3h567tt.js";
4
- var Nt = {
1
+ import { a as Ut, i as Wt, m as Gt, o as Vt, s as jt, t as qt } from "./AgoClient-Cwx_eYSu.js";
2
+ import { r as Kt, t as Xt } from "./createFormCollector-CyWisAkI.js";
3
+ import { t as Qt } from "./createConversationSession-B3h567tt.js";
4
+ var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Ee = `var(--ago-font, ${Yt})`, lt = {
5
+ font: "--ago-font",
6
+ radius: "--ago-radius",
7
+ messageRadius: "--ago-message-radius",
8
+ brand: "--ago-brand-color",
9
+ brandText: "--ago-brand-text-color",
10
+ headerBg: "--ago-header-background",
11
+ headerText: "--ago-header-text-color",
12
+ panelBg: "--ago-panel-background",
13
+ messagesBg: "--ago-messages-background",
14
+ text: "--ago-text-color",
15
+ mutedText: "--ago-muted-text-color",
16
+ border: "--ago-border-color",
17
+ accent: "--ago-accent-color",
18
+ agentBubbleBg: "--ago-agent-bubble-background"
19
+ }, Re = "var(--ago-brand-color, #03182f)", ke = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", dt = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", mt = "var(--ago-messages-background, #fbfbfb)", J = "var(--ago-text-color, #30373e)", gt = "var(--ago-muted-text-color, #6b6d6f)", L = "var(--ago-border-color, #dee3e8)", Be = "var(--ago-accent-color, #1b5fc4)", ct = "var(--ago-agent-bubble-background, #f1f3f5)", Jt = "var(--ago-radius, 16px)", Me = "var(--ago-message-radius, 16px)", en = "var(--ago-message-radius, 20px)";
20
+ function tn(n, o) {
21
+ if (o)
22
+ for (const i of Object.keys(lt)) {
23
+ const r = o[i];
24
+ r != null && n.style.setProperty(lt[i], r);
25
+ }
26
+ }
27
+ function v(n, o) {
28
+ Object.assign(n.style, o);
29
+ }
30
+ function h(n = {}) {
31
+ const o = document.createElement("div");
32
+ return v(o, n), o;
33
+ }
34
+ var pt = "ago-chat-widget-keyframes";
35
+ function nn() {
36
+ if (typeof document > "u" || document.getElementById(pt)) return;
37
+ const n = document.createElement("style");
38
+ n.id = pt, n.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(n);
39
+ }
40
+ function on(n) {
41
+ let o = [];
42
+ const i = document.createElement("form");
43
+ v(i, {
44
+ display: "flex",
45
+ flexDirection: "column",
46
+ gap: "8px",
47
+ padding: "12px",
48
+ borderTop: `1px solid ${L}`,
49
+ backgroundColor: ee
50
+ }), i.className = "ago-chat-input";
51
+ const r = h({
52
+ display: "flex",
53
+ flexWrap: "wrap",
54
+ gap: "6px"
55
+ }), b = h({
56
+ display: "flex",
57
+ gap: "8px",
58
+ alignItems: "flex-end"
59
+ }), a = document.createElement("textarea");
60
+ a.placeholder = n.placeholder, a.setAttribute("aria-label", n.placeholder), a.rows = 1, v(a, {
61
+ flex: "1",
62
+ resize: "none",
63
+ boxSizing: "border-box",
64
+ padding: "10px 12px",
65
+ border: `1px solid ${L}`,
66
+ borderRadius: "12px",
67
+ fontSize: "16px",
68
+ fontFamily: Ee,
69
+ lineHeight: "1.4",
70
+ maxHeight: "110px",
71
+ overflowY: "hidden"
72
+ });
73
+ const C = () => {
74
+ a.style.height = "auto";
75
+ const c = Math.min(a.scrollHeight + 2, 110);
76
+ a.style.height = `${c}px`, a.style.overflowY = a.scrollHeight + 2 > 110 ? "auto" : "hidden";
77
+ };
78
+ a.addEventListener("input", () => {
79
+ C(), A();
80
+ });
81
+ const m = '<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>', x = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>', p = document.createElement("button");
82
+ p.type = "submit", p.setAttribute("aria-label", "Send"), p.innerHTML = m, v(p, {
83
+ flexShrink: "0",
84
+ width: "40px",
85
+ height: "40px",
86
+ padding: "0",
87
+ border: "none",
88
+ borderRadius: "50%",
89
+ backgroundColor: Re,
90
+ color: ke,
91
+ display: "flex",
92
+ alignItems: "center",
93
+ justifyContent: "center",
94
+ cursor: "pointer"
95
+ });
96
+ let f = !1;
97
+ const A = () => {
98
+ const s = a.value.trim() !== "" || o.length > 0, c = f || !s;
99
+ p.disabled = c, p.innerHTML = f ? x : m, p.style.opacity = c && !f ? "0.5" : "1", p.style.cursor = c ? "default" : "pointer";
100
+ };
101
+ let R = null, _ = null;
102
+ n.allowFiles && (R = document.createElement("input"), R.type = "file", R.multiple = !0, v(R, { display: "none" }), _ = document.createElement("button"), _.type = "button", _.setAttribute("aria-label", "Attach file"), _.textContent = "📎", v(_, {
103
+ padding: "10px 12px",
104
+ border: `1px solid ${L}`,
105
+ borderRadius: "12px",
106
+ backgroundColor: ee,
107
+ cursor: "pointer",
108
+ fontSize: "14px"
109
+ }), _.addEventListener("click", () => R?.click()), R.addEventListener("change", () => {
110
+ o = [...o, ...Array.from(R?.files ?? [])], Y();
111
+ }));
112
+ function Y() {
113
+ r.replaceChildren(), o.forEach((s, c) => {
114
+ const y = h({
115
+ display: "flex",
116
+ alignItems: "center",
117
+ gap: "4px",
118
+ padding: "4px 8px",
119
+ backgroundColor: "#f0f4ff",
120
+ border: `1px solid ${L}`,
121
+ borderRadius: "8px",
122
+ fontSize: "12px"
123
+ }), T = document.createElement("span");
124
+ T.textContent = s.name;
125
+ const k = document.createElement("button");
126
+ k.type = "button", k.setAttribute("aria-label", `Remove ${s.name}`), k.textContent = "×", v(k, {
127
+ border: "none",
128
+ background: "transparent",
129
+ cursor: "pointer",
130
+ fontSize: "14px",
131
+ lineHeight: "1"
132
+ }), k.addEventListener("click", () => {
133
+ o = o.filter((G, V) => V !== c), Y();
134
+ }), y.append(T, k), r.appendChild(y);
135
+ }), A();
136
+ }
137
+ const O = () => {
138
+ const s = a.value, c = o;
139
+ return a.value = "", C(), o = [], Y(), {
140
+ content: s,
141
+ files: c
142
+ };
143
+ }, g = () => {
144
+ const { content: s, files: c } = O();
145
+ (s.trim() || c.length > 0) && n.onSend(s.trim(), c.length > 0 ? c : void 0);
146
+ };
147
+ return i.addEventListener("submit", (s) => {
148
+ s.preventDefault(), g();
149
+ }), a.addEventListener("keydown", (s) => {
150
+ s.key === "Enter" && !s.shiftKey && (s.preventDefault(), g());
151
+ }), _ && b.appendChild(_), b.append(a, p), R && i.appendChild(R), i.append(r, b), A(), {
152
+ inputRow: i,
153
+ getValueAndClear: O,
154
+ setDisabled: (s) => {
155
+ a.disabled = s, f = s, A();
156
+ },
157
+ focus: () => a.focus()
158
+ };
159
+ }
160
+ var rn = {
5
161
  "&": "&amp;",
6
162
  "<": "&lt;",
7
163
  ">": "&gt;",
8
164
  '"': "&quot;",
9
165
  "'": "&#39;"
10
166
  };
11
- function Z(r) {
12
- return r.replace(/[&<>"']/g, (o) => Nt[o]);
167
+ function ie(n) {
168
+ return n.replace(/[&<>"']/g, (o) => rn[o]);
13
169
  }
14
- function Ve(r) {
15
- const o = r.trim();
170
+ function ft(n) {
171
+ const o = n.trim();
16
172
  return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o) || !/^[a-z][a-z0-9+.-]*:/i.test(o) ? o : null;
17
173
  }
18
- var ot = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', ue = "";
19
- function j(r) {
20
- const o = [], a = (m) => (o.push(m), `${ue}${o.length - 1}${ue}`);
21
- let n = r;
22
- return n = n.replace(/`([^`]+)`/g, (m, i) => a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ot}">${Z(i)}</code>`)), n = n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, i, E) => {
23
- const p = Ve(E);
24
- return p ? a(`<img alt="${Z(i)}" src="${Z(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : m;
25
- }), n = n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, i, E) => {
26
- const p = Ve(E);
27
- return p ? a(`<a href="${Z(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${j(i)}</a>`) : m;
28
- }), n = Z(n), n = n.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), n = n.replace(new RegExp(`${ue}(\\d+)${ue}`, "g"), (m, i) => o[Number(i)]), n;
174
+ var ht = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Ce = "";
175
+ function te(n) {
176
+ const o = [], i = (b) => (o.push(b), `${Ce}${o.length - 1}${Ce}`);
177
+ let r = n;
178
+ return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ht}">${ie(a)}</code>`)), r = r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (b, a, C) => {
179
+ const m = ft(C);
180
+ return m ? i(`<img alt="${ie(a)}" src="${ie(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : b;
181
+ }), r = r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (b, a, C) => {
182
+ const m = ft(C);
183
+ return m ? i(`<a href="${ie(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`) : b;
184
+ }), r = ie(r), r = r.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), r = r.replace(new RegExp(`${Ce}(\\d+)${Ce}`, "g"), (b, a) => o[Number(a)]), r;
29
185
  }
30
- function L(r, o, a) {
31
- const n = document.createElement(r);
32
- return Object.assign(n.style, o), a !== void 0 && (n.innerHTML = a), n;
186
+ function M(n, o, i) {
187
+ const r = document.createElement(n);
188
+ return Object.assign(r.style, o), i !== void 0 && (r.innerHTML = i), r;
33
189
  }
34
- var rt = /^ {0,3}([-*_])( *\1){2,} *$/, at = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, it = /^ {0,3}(```+|~~~+)/, ge = /^ {0,3}>\s?/, J = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, $t = [
190
+ var xt = /^ {0,3}([-*_])( *\1){2,} *$/, bt = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, vt = /^ {0,3}(```+|~~~+)/, Se = /^ {0,3}>\s?/, ae = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, an = [
35
191
  "20px",
36
192
  "18px",
37
193
  "16px",
38
194
  "15px",
39
195
  "14px",
40
196
  "13px"
41
- ], Ne = (r) => r.match(/^\s*/)?.[0].length ?? 0;
42
- function Lt(r) {
43
- return r.trim() === "" || rt.test(r) || at.test(r) || it.test(r) || ge.test(r) || J.test(r);
197
+ ], Oe = (n) => n.match(/^\s*/)?.[0].length ?? 0;
198
+ function sn(n) {
199
+ return n.trim() === "" || xt.test(n) || bt.test(n) || vt.test(n) || Se.test(n) || ae.test(n);
44
200
  }
45
- function st(r) {
46
- const o = r[0].match(J), a = o[1].length, n = /\d/.test(o[2]), m = L(n ? "ol" : "ul", {
201
+ function yt(n) {
202
+ const o = n[0].match(ae), i = o[1].length, r = /\d/.test(o[2]), b = M(r ? "ol" : "ul", {
47
203
  margin: "0 0 8px 0",
48
204
  paddingLeft: "20px",
49
- listStyleType: n ? "decimal" : "disc",
205
+ listStyleType: r ? "decimal" : "disc",
50
206
  listStylePosition: "outside"
51
207
  });
52
- let i = 0;
53
- for (; i < r.length; ) {
54
- const E = r[i].match(J), p = [];
55
- for (i++; i < r.length && Ne(r[i]) > a; )
56
- p.push(r[i]), i++;
57
- const C = L("li", {
208
+ let a = 0;
209
+ for (; a < n.length; ) {
210
+ const C = n[a].match(ae), m = [];
211
+ for (a++; a < n.length && Oe(n[a]) > i; )
212
+ m.push(n[a]), a++;
213
+ const x = M("li", {
58
214
  display: "list-item",
59
215
  margin: "2px 0",
60
216
  lineHeight: "1.6"
61
- }), d = E[3].match(/^\[([ xX])\]\s+(.*)$/);
62
- d ? (C.style.listStyleType = "none", C.style.marginLeft = "-20px", C.innerHTML = `<span style="margin-right:6px">${d[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${j(d[2])}`) : C.innerHTML = j(E[3]), p.filter((x) => J.test(x)).length > 0 && C.appendChild(st(p.filter((x) => x.trim() !== ""))), m.appendChild(C);
217
+ }), p = C[3].match(/^\[([ xX])\]\s+(.*)$/);
218
+ p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => ae.test(f)).length > 0 && x.appendChild(yt(m.filter((f) => f.trim() !== ""))), b.appendChild(x);
63
219
  }
64
- return m;
220
+ return b;
65
221
  }
66
- function Tt(r) {
67
- const o = (p) => p.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((C) => C.trim()), a = L("div", {
222
+ function ln(n) {
223
+ const o = (m) => m.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((x) => x.trim()), i = M("div", {
68
224
  overflowX: "auto",
69
225
  margin: "0 0 8px 0"
70
- }), n = L("table", {
226
+ }), r = M("table", {
71
227
  borderCollapse: "collapse",
72
228
  width: "100%",
73
229
  fontSize: "13px"
74
- }), m = document.createElement("thead"), i = document.createElement("tr");
75
- for (const p of o(r[0])) i.appendChild(L("th", {
230
+ }), b = document.createElement("thead"), a = document.createElement("tr");
231
+ for (const m of o(n[0])) a.appendChild(M("th", {
76
232
  border: "1px solid #dee3e8",
77
233
  padding: "6px 10px",
78
234
  textAlign: "left",
79
235
  backgroundColor: "#f5f7fa",
80
236
  fontWeight: "600"
81
- }, j(p)));
82
- m.appendChild(i), n.appendChild(m);
83
- const E = document.createElement("tbody");
84
- for (const p of r.slice(2)) {
85
- const C = document.createElement("tr");
86
- for (const d of o(p)) C.appendChild(L("td", {
237
+ }, te(m)));
238
+ b.appendChild(a), r.appendChild(b);
239
+ const C = document.createElement("tbody");
240
+ for (const m of n.slice(2)) {
241
+ const x = document.createElement("tr");
242
+ for (const p of o(m)) x.appendChild(M("td", {
87
243
  border: "1px solid #dee3e8",
88
244
  padding: "6px 10px"
89
- }, j(d)));
90
- E.appendChild(C);
245
+ }, te(p)));
246
+ C.appendChild(x);
91
247
  }
92
- return n.appendChild(E), a.appendChild(n), a;
248
+ return r.appendChild(C), i.appendChild(r), i;
93
249
  }
94
- var Ot = (r) => !!r && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);
95
- function $e(r) {
96
- const o = document.createDocumentFragment(), a = r.replace(/\r\n?/g, `
250
+ var dn = (n) => !!n && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);
251
+ function De(n) {
252
+ const o = document.createDocumentFragment(), i = n.replace(/\r\n?/g, `
97
253
  `).split(`
98
254
  `);
99
- let n = 0;
100
- for (; n < a.length; ) {
101
- const i = a[n];
102
- if (i.trim() === "") {
103
- n++;
255
+ let r = 0;
256
+ for (; r < i.length; ) {
257
+ const a = i[r];
258
+ if (a.trim() === "") {
259
+ r++;
104
260
  continue;
105
261
  }
106
- const E = i.match(it);
107
- if (E) {
108
- const d = E[1][0], x = [];
109
- for (n++; n < a.length && !new RegExp(`^ {0,3}${d === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(a[n]); )
110
- x.push(a[n]), n++;
111
- n++;
112
- const B = L("pre", { margin: "0 0 8px 0" });
113
- B.appendChild(L("code", {
262
+ const C = a.match(vt);
263
+ if (C) {
264
+ const p = C[1][0], f = [];
265
+ for (r++; r < i.length && !new RegExp(`^ {0,3}${p === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(i[r]); )
266
+ f.push(i[r]), r++;
267
+ r++;
268
+ const A = M("pre", { margin: "0 0 8px 0" });
269
+ A.appendChild(M("code", {
114
270
  display: "block",
115
271
  background: "#f5f5f5",
116
272
  padding: "8px 12px",
117
273
  borderRadius: "6px",
118
274
  fontSize: "13px",
119
275
  overflowX: "auto",
120
- fontFamily: ot,
276
+ fontFamily: ht,
121
277
  whiteSpace: "pre"
122
- }, Z(x.join(`
123
- `)))), o.appendChild(B);
278
+ }, ie(f.join(`
279
+ `)))), o.appendChild(A);
124
280
  continue;
125
281
  }
126
- if (rt.test(i)) {
127
- o.appendChild(L("hr", {
282
+ if (xt.test(a)) {
283
+ o.appendChild(M("hr", {
128
284
  border: "none",
129
285
  borderTop: "1px solid #dee3e8",
130
286
  margin: "12px 0"
131
- })), n++;
287
+ })), r++;
132
288
  continue;
133
289
  }
134
- const p = i.match(at);
135
- if (p) {
136
- const d = p[1].length;
137
- o.appendChild(L(`h${d}`, {
290
+ const m = a.match(bt);
291
+ if (m) {
292
+ const p = m[1].length;
293
+ o.appendChild(M(`h${p}`, {
138
294
  margin: "16px 0 8px 0",
139
- fontSize: $t[d - 1],
295
+ fontSize: an[p - 1],
140
296
  fontWeight: "600",
141
297
  lineHeight: "1.3"
142
- }, j(p[2]))), n++;
298
+ }, te(m[2]))), r++;
143
299
  continue;
144
300
  }
145
- if (ge.test(i)) {
146
- const d = [];
147
- for (; n < a.length && ge.test(a[n]); )
148
- d.push(a[n].replace(ge, "")), n++;
149
- const x = L("blockquote", {
301
+ if (Se.test(a)) {
302
+ const p = [];
303
+ for (; r < i.length && Se.test(i[r]); )
304
+ p.push(i[r].replace(Se, "")), r++;
305
+ const f = M("blockquote", {
150
306
  borderLeft: "4px solid #dee3e8",
151
307
  paddingLeft: "12px",
152
308
  margin: "0 0 8px 0",
153
309
  fontStyle: "italic",
154
310
  color: "#6b6d6f"
155
311
  });
156
- x.appendChild($e(d.join(`
157
- `))), o.appendChild(x);
312
+ f.appendChild(De(p.join(`
313
+ `))), o.appendChild(f);
158
314
  continue;
159
315
  }
160
- if (i.includes("|") && Ot(a[n + 1])) {
161
- const d = [i, a[n + 1]];
162
- for (n += 2; n < a.length && a[n].includes("|") && a[n].trim(); )
163
- d.push(a[n]), n++;
164
- o.appendChild(Tt(d));
316
+ if (a.includes("|") && dn(i[r + 1])) {
317
+ const p = [a, i[r + 1]];
318
+ for (r += 2; r < i.length && i[r].includes("|") && i[r].trim(); )
319
+ p.push(i[r]), r++;
320
+ o.appendChild(ln(p));
165
321
  continue;
166
322
  }
167
- if (J.test(i)) {
168
- const d = [], x = Ne(i);
169
- for (; n < a.length && a[n].trim() !== ""; )
170
- if (J.test(a[n]) || Ne(a[n]) > x)
171
- d.push(a[n]), n++;
323
+ if (ae.test(a)) {
324
+ const p = [], f = Oe(a);
325
+ for (; r < i.length && i[r].trim() !== ""; )
326
+ if (ae.test(i[r]) || Oe(i[r]) > f)
327
+ p.push(i[r]), r++;
172
328
  else break;
173
- o.appendChild(st(d));
329
+ o.appendChild(yt(p));
174
330
  continue;
175
331
  }
176
- const C = [i];
177
- for (n++; n < a.length && !Lt(a[n]); )
178
- C.push(a[n]), n++;
179
- o.appendChild(L("p", {
332
+ const x = [a];
333
+ for (r++; r < i.length && !sn(i[r]); )
334
+ x.push(i[r]), r++;
335
+ o.appendChild(M("p", {
180
336
  margin: "0 0 8px 0",
181
337
  lineHeight: "1.6"
182
- }, C.map((d) => j(d)).join("<br>")));
338
+ }, x.map((p) => te(p)).join("<br>")));
183
339
  }
184
- const m = o.lastElementChild;
185
- return m && (m.style.marginBottom = "0"), o;
340
+ const b = o.lastElementChild;
341
+ return b && (b.style.marginBottom = "0"), o;
186
342
  }
187
- var Le = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', Ye = {
188
- font: "--ago-font",
189
- radius: "--ago-radius",
190
- messageRadius: "--ago-message-radius",
191
- brand: "--ago-brand-color",
192
- brandText: "--ago-brand-text-color",
193
- headerBg: "--ago-header-background",
194
- headerText: "--ago-header-text-color",
195
- panelBg: "--ago-panel-background",
196
- messagesBg: "--ago-messages-background",
197
- text: "--ago-text-color",
198
- mutedText: "--ago-muted-text-color",
199
- border: "--ago-border-color",
200
- accent: "--ago-accent-color",
201
- agentBubbleBg: "--ago-agent-bubble-background"
202
- }, me = "var(--ago-brand-color, #03182f)", he = "var(--ago-brand-text-color, #fff)", Dt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Ze = "var(--ago-header-text-color, #e8f0fe)", Q = "var(--ago-panel-background, #fff)", Qe = "var(--ago-messages-background, #fbfbfb)", ae = "var(--ago-text-color, #30373e)", Je = "var(--ago-muted-text-color, #6b6d6f)", $ = "var(--ago-border-color, #dee3e8)", Ae = "var(--ago-accent-color, #1b5fc4)", et = "var(--ago-agent-bubble-background, #f1f3f5)", Bt = "var(--ago-radius, 16px)", Ie = "var(--ago-message-radius, 16px)", Mt = "var(--ago-message-radius, 20px)";
203
- function zt(r, o) {
204
- if (o)
205
- for (const a of Object.keys(Ye)) {
206
- const n = o[a];
207
- n != null && r.style.setProperty(Ye[a], n);
343
+ function cn(n, o) {
344
+ const { isLast: i, isLastOfBlock: r, bubbleStyle: b, showAgentName: a, agentBubble: C, followUpEnabled: m, followUpHandler: x, isMobile: p } = o, f = n.role === "user", A = b === "imessage", R = h({
345
+ display: "flex",
346
+ flexDirection: "column",
347
+ alignItems: f ? "flex-end" : "flex-start",
348
+ marginBottom: A && !r ? "2px" : "16px"
349
+ });
350
+ if (R.className = `ago-message ago-message--${n.role}`, !f && a && n.agent) {
351
+ const g = h({
352
+ fontSize: "13px",
353
+ fontWeight: "500",
354
+ color: J,
355
+ marginBottom: "6px",
356
+ padding: "0 4px"
357
+ });
358
+ g.className = "ago-message__agent", g.textContent = n.agent.displayName || n.agent.name, R.appendChild(g);
359
+ }
360
+ if (!f && n.sources && n.sources.length > 0) {
361
+ const g = h({
362
+ display: "grid",
363
+ gridTemplateColumns: "1fr 1fr",
364
+ gap: "6px",
365
+ marginBottom: "10px",
366
+ width: "100%",
367
+ maxWidth: "85%"
368
+ });
369
+ g.className = "ago-message__sources", n.sources.forEach((s, c) => {
370
+ const y = s.url ? document.createElement("a") : document.createElement("div");
371
+ s.url && y instanceof HTMLAnchorElement && (y.href = s.url, y.target = "_blank", y.rel = "noopener noreferrer"), v(y, {
372
+ display: "flex",
373
+ alignItems: "center",
374
+ gap: "8px",
375
+ padding: "8px 10px",
376
+ border: `1px solid ${L}`,
377
+ borderRadius: "8px",
378
+ backgroundColor: ee,
379
+ textDecoration: "none",
380
+ color: J,
381
+ fontSize: "12px",
382
+ overflow: "hidden"
383
+ });
384
+ const T = h({
385
+ flexShrink: "0",
386
+ width: "18px",
387
+ height: "18px",
388
+ borderRadius: "3px",
389
+ border: `1px solid ${Be}`,
390
+ color: Be,
391
+ fontSize: "11px",
392
+ fontWeight: "500",
393
+ display: "flex",
394
+ alignItems: "center",
395
+ justifyContent: "center",
396
+ backgroundColor: "#f0f4ff"
397
+ });
398
+ T.textContent = String(c + 1);
399
+ const k = h({
400
+ overflow: "hidden",
401
+ textOverflow: "ellipsis",
402
+ whiteSpace: "nowrap"
403
+ });
404
+ k.textContent = s.title, k.title = s.title, y.append(T, k), g.appendChild(y);
405
+ }), R.appendChild(g);
406
+ }
407
+ if (n.attachments && n.attachments.length > 0) {
408
+ const g = h({
409
+ display: "flex",
410
+ flexWrap: "wrap",
411
+ gap: "6px",
412
+ marginBottom: "6px",
413
+ justifyContent: f ? "flex-end" : "flex-start",
414
+ maxWidth: "75%"
415
+ });
416
+ g.className = "ago-message__attachments";
417
+ for (const s of n.attachments) {
418
+ const c = jt(s.url);
419
+ if (Ut(s) && c) {
420
+ const B = document.createElement("a");
421
+ B.href = c, B.target = "_blank", B.rel = "noopener noreferrer", v(B, {
422
+ display: "inline-block",
423
+ textDecoration: "none"
424
+ });
425
+ const j = document.createElement("img");
426
+ j.src = c, j.alt = s.name, j.loading = "lazy", v(j, {
427
+ maxWidth: "180px",
428
+ maxHeight: "160px",
429
+ objectFit: "cover",
430
+ borderRadius: "10px",
431
+ border: `1px solid ${L}`,
432
+ display: "block"
433
+ }), B.appendChild(j), g.appendChild(B);
434
+ continue;
435
+ }
436
+ const y = c ? document.createElement("a") : document.createElement("div");
437
+ c && y instanceof HTMLAnchorElement && (y.href = c, y.target = "_blank", y.rel = "noopener noreferrer"), v(y, {
438
+ display: "inline-flex",
439
+ alignItems: "center",
440
+ gap: "8px",
441
+ padding: "8px 12px",
442
+ borderRadius: "10px",
443
+ border: `1px solid ${L}`,
444
+ backgroundColor: f ? "rgba(255,255,255,0.12)" : ee,
445
+ color: f ? ke : J,
446
+ fontSize: "13px",
447
+ textDecoration: "none",
448
+ maxWidth: "220px"
449
+ });
450
+ const T = document.createElement("span");
451
+ T.textContent = "📄", T.setAttribute("aria-hidden", "true"), v(T, {
452
+ fontSize: "16px",
453
+ lineHeight: "1",
454
+ flexShrink: "0"
455
+ });
456
+ const k = h({
457
+ display: "flex",
458
+ flexDirection: "column",
459
+ minWidth: "0"
460
+ }), G = h({
461
+ overflow: "hidden",
462
+ textOverflow: "ellipsis",
463
+ whiteSpace: "nowrap",
464
+ maxWidth: "160px"
465
+ });
466
+ G.textContent = s.name, G.title = s.name, k.appendChild(G);
467
+ const V = Vt(s.fileSize);
468
+ if (V) {
469
+ const B = h({
470
+ fontSize: "11px",
471
+ color: gt
472
+ });
473
+ B.textContent = V, k.appendChild(B);
474
+ }
475
+ y.append(T, k), g.appendChild(y);
476
+ }
477
+ R.appendChild(g);
478
+ }
479
+ const _ = f || C || A, Y = !!n.content || n.status === "IN_PROGRESS", O = h({
480
+ maxWidth: _ ? A || f ? p ? "88%" : "75%" : p ? "92%" : "85%" : "100%",
481
+ padding: _ ? "10px 14px" : "2px 8px",
482
+ borderRadius: A ? en : _ ? Me : "0",
483
+ backgroundColor: f ? Re : _ ? ct : "transparent",
484
+ color: f ? ke : J,
485
+ overflowWrap: "break-word",
486
+ textWrap: "pretty",
487
+ fontSize: "16px",
488
+ lineHeight: "1.6"
489
+ });
490
+ if (O.className = "ago-message__content", A && r) {
491
+ O.style.position = "relative";
492
+ const g = h({
493
+ position: "absolute",
494
+ zIndex: "0",
495
+ bottom: "-2px",
496
+ width: "20px",
497
+ height: "20px",
498
+ background: f ? Re : ct
499
+ });
500
+ g.className = "ago-message__tail";
501
+ const s = h({
502
+ position: "absolute",
503
+ zIndex: "1",
504
+ bottom: "-2px",
505
+ width: "10px",
506
+ height: "20px",
507
+ background: mt
508
+ });
509
+ s.className = "ago-message__tail-mask", f ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", s.style.right = "-10px", s.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", s.style.left = "-10px", s.style.borderBottomRightRadius = "10px"), O.append(g, s);
510
+ }
511
+ if (n.content ? O.appendChild(De(n.content)) : n.status === "IN_PROGRESS" && O.appendChild(fn()), Y && R.appendChild(O), i && n.followUpReplies && n.followUpReplies.length > 0) {
512
+ const g = h({
513
+ display: "flex",
514
+ flexWrap: "wrap",
515
+ gap: "8px",
516
+ marginTop: "10px"
517
+ });
518
+ g.className = "ago-message__followups";
519
+ for (const s of n.followUpReplies) {
520
+ const c = document.createElement("button");
521
+ c.type = "button", c.className = "ago-message__followup-btn", c.textContent = s, c.disabled = !m, v(c, {
522
+ minHeight: "36px",
523
+ padding: "6px 14px",
524
+ fontSize: "14px",
525
+ borderRadius: Me,
526
+ border: `1px solid ${L}`,
527
+ backgroundColor: ee,
528
+ color: J,
529
+ cursor: m ? "pointer" : "default",
530
+ transition: "border-color 0.15s"
531
+ }), x && c.addEventListener("click", () => x(s)), c.addEventListener("mouseenter", () => {
532
+ c.style.borderColor = Be;
533
+ }), c.addEventListener("mouseleave", () => {
534
+ c.style.borderColor = L;
535
+ }), g.appendChild(c);
208
536
  }
537
+ R.appendChild(g);
538
+ }
539
+ return R;
209
540
  }
210
- function w(r, o) {
211
- Object.assign(r.style, o);
541
+ function pn(n) {
542
+ const o = h({
543
+ display: "flex",
544
+ alignItems: "center",
545
+ gap: "8px",
546
+ padding: "10px 14px",
547
+ backgroundColor: "#f0fdf4",
548
+ color: "#15803d",
549
+ borderRadius: Me,
550
+ marginTop: "8px",
551
+ fontSize: "13px",
552
+ border: "1px solid #bbf7d0"
553
+ });
554
+ o.className = "ago-form-notice", o.setAttribute("role", "status");
555
+ const i = document.createElement("span");
556
+ i.textContent = "✓", i.setAttribute("aria-hidden", "true"), v(i, { fontWeight: "700" });
557
+ const r = document.createElement("span");
558
+ return r.textContent = n, o.append(i, r), o;
212
559
  }
213
- function f(r = {}) {
214
- const o = document.createElement("div");
215
- return w(o, r), o;
560
+ function fn() {
561
+ const n = h({
562
+ display: "flex",
563
+ gap: "4px",
564
+ padding: "4px 0"
565
+ });
566
+ for (let o = 0; o < 3; o++) {
567
+ const i = h({
568
+ width: "6px",
569
+ height: "6px",
570
+ borderRadius: "50%",
571
+ backgroundColor: "#b5bfc8",
572
+ animation: "ago-pulse 1.2s ease-in-out infinite",
573
+ animationDelay: `${o * 0.2}s`
574
+ });
575
+ n.appendChild(i);
576
+ }
577
+ return n;
578
+ }
579
+ function un() {
580
+ const n = "http://www.w3.org/2000/svg", o = document.createElementNS(n, "svg");
581
+ o.setAttribute("width", "26"), o.setAttribute("height", "26"), o.setAttribute("viewBox", "0 0 24 24"), o.setAttribute("fill", "none");
582
+ const i = document.createElementNS(n, "path");
583
+ return i.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), o.appendChild(i), o;
216
584
  }
217
- var tt = "Form submitted.";
218
- function Ft(r) {
219
- if (typeof r == "string") return r || null;
220
- if (!r || typeof r != "object") return null;
221
- const o = r;
585
+ var ut = "Form submitted.";
586
+ function mn(n) {
587
+ if (typeof n == "string") return n || null;
588
+ if (!n || typeof n != "object") return null;
589
+ const o = n;
222
590
  if (typeof o.message == "string" && o.message) return o.message;
223
- const a = o.result;
224
- if (typeof a == "string" && a) return a;
225
- if (a && typeof a == "object") {
226
- const n = a.message;
227
- if (typeof n == "string" && n) return n;
591
+ const i = o.result;
592
+ if (typeof i == "string" && i) return i;
593
+ if (i && typeof i == "object") {
594
+ const r = i.message;
595
+ if (typeof r == "string" && r) return r;
228
596
  }
229
597
  return null;
230
598
  }
231
- var nt = "ago-chat-widget-keyframes";
232
- function Ht() {
233
- if (typeof document > "u" || document.getElementById(nt)) return;
234
- const r = document.createElement("style");
235
- r.id = nt, r.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(r);
236
- }
237
- function Wt(r) {
238
- const o = typeof r == "string" ? document.querySelector(r) : r;
239
- if (!o) throw new Error(`mountChatWidget: target "${String(r)}" not found.`);
599
+ var gn = 0;
600
+ function hn(n) {
601
+ const o = typeof n == "string" ? document.querySelector(n) : n;
602
+ if (!o) throw new Error(`mountChatWidget: target "${String(n)}" not found.`);
240
603
  return o;
241
604
  }
242
- function Xt(r, o) {
243
- const { title: a = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: m = "Type a message...", allowFiles: i = !1, height: E = 500, placement: p = "inline", width: C = 400, defaultOpen: d = !1, logoUrl: x, showAgentName: B = !1, agentBubble: T = !1, bubbleStyle: O = "default", showHeader: ee = !0, theme: ie, loadThreads: te = !1, forms: b, formSubmittedMessage: S = tt, onFollowUpClick: X, onMessageSent: se, onMessageReceived: z, onFormSubmitted: le, onFormError: ne } = o, de = typeof n == "string" ? {
244
- message: n,
605
+ function yn(n, o) {
606
+ const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: O, loadThreads: g = !1, forms: s, formSubmittedMessage: c = ut, onFollowUpClick: y, onMessageSent: T, onMessageReceived: k, onFormSubmitted: G, onFormError: V, onOpen: B, onClose: j } = o, ne = typeof r == "string" ? {
607
+ message: r,
245
608
  mode: "static"
246
- } : n, Te = de.message, Oe = de.mode ?? "static", lt = "speed" in de && de.speed || 45;
247
- if (!o.client && !o.config?.baseUrl) throw new Et("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
248
- const v = o.client ?? new _t(o.config), De = Wt(r), K = p === "left" || p === "right", dt = K && (o.launcher ?? !0);
249
- let q = K ? d : !0;
250
- const xe = o.persistConversation, ce = xe ? It(xe === !0 ? {} : xe) : void 0;
251
- let D = o.conversationId ?? ce?.getLastActiveThread() ?? void 0, l = [], H = !1, oe = null, F;
252
- const Be = [];
253
- function ct(e) {
254
- if (typeof S == "function") {
255
- const s = S(e);
256
- if (typeof s == "string" && s) return s;
609
+ } : r, ze = ne.message, Fe = ne.mode ?? "static", wt = "speed" in ne && ne.speed || 45, He = "followUpReplies" in ne && ne.followUpReplies || void 0;
610
+ if (!o.client && !o.config?.baseUrl) throw new Gt("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
611
+ const E = o.client ?? new qt(o.config), Pe = hn(n), D = m === "left" || m === "right", Ct = D && (o.launcher ?? !0);
612
+ let oe = D ? p : !0;
613
+ const Et = o.mobile?.breakpoint ?? 768, St = o.mobile?.trigger ?? "focus", Ue = typeof window < "u" && !!window.matchMedia, z = Ue ? window.matchMedia(`(max-width: ${Et}px)`) : void 0, Rt = Ue ? window.matchMedia("(prefers-reduced-motion: reduce)") : void 0, se = !D && !!z, Ae = o.persistConversation, ue = Ae ? Qt(Ae === !0 ? {} : Ae) : void 0;
614
+ let P = o.conversationId ?? ue?.getLastActiveThread() ?? void 0, u = [], Z = !1, le = null, q;
615
+ const We = [];
616
+ function kt(e) {
617
+ if (typeof c == "function") {
618
+ const l = c(e);
619
+ if (typeof l == "string" && l) return l;
257
620
  }
258
- const t = Ft(e);
259
- return t || (typeof S == "string" ? S : tt);
621
+ const t = mn(e);
622
+ return t || (typeof c == "string" ? c : ut);
260
623
  }
261
- const pe = [], V = f({
624
+ const me = [], d = h({
262
625
  display: "flex",
263
626
  flexDirection: "column",
264
- height: K ? "100%" : typeof E == "number" ? `${E}px` : E,
265
- border: `1px solid ${$}`,
266
- borderRadius: Bt,
627
+ height: D ? "100%" : typeof C == "number" ? `${C}px` : C,
628
+ border: `1px solid ${L}`,
629
+ borderRadius: Jt,
267
630
  overflow: "hidden",
268
- backgroundColor: Q,
269
- fontFamily: Le,
631
+ backgroundColor: ee,
632
+ fontFamily: Ee,
270
633
  textAlign: "left",
271
634
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
272
635
  });
273
- V.className = "ago-chat-widget", zt(V, ie);
274
- let W;
275
- if (ee) {
276
- if (W = f({
636
+ d.className = "ago-chat-widget", tn(d, O);
637
+ let F;
638
+ if (Y) {
639
+ if (F = h({
277
640
  padding: "14px 16px",
278
- borderBottom: `1px solid ${$}`,
279
- backgroundColor: Dt,
280
- color: Ze,
641
+ borderBottom: `1px solid ${L}`,
642
+ backgroundColor: Zt,
643
+ color: dt,
281
644
  display: "flex",
282
645
  alignItems: "center",
283
646
  gap: "10px"
284
- }), W.className = "ago-chat-widget__header", x) {
647
+ }), F.className = "ago-chat-widget__header", f) {
285
648
  const t = document.createElement("img");
286
- t.src = x, t.alt = "Logo", w(t, {
649
+ t.src = f, t.alt = "Logo", v(t, {
287
650
  height: "24px",
288
651
  width: "auto"
289
- }), W.appendChild(t);
652
+ }), F.appendChild(t);
290
653
  }
291
654
  const e = document.createElement("h3");
292
- if (e.textContent = a, w(e, {
655
+ if (e.textContent = i, v(e, {
293
656
  margin: "0",
294
657
  fontSize: "15px",
295
658
  fontWeight: "600"
296
- }), W.appendChild(e), K) {
659
+ }), F.appendChild(e), D) {
297
660
  const t = document.createElement("button");
298
- t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", w(t, {
661
+ t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", v(t, {
299
662
  marginLeft: "auto",
300
663
  background: "transparent",
301
664
  border: "none",
302
- color: Ze,
665
+ color: dt,
303
666
  fontSize: "22px",
304
667
  lineHeight: "1",
305
668
  cursor: "pointer",
306
669
  padding: "0 2px"
307
- }), t.addEventListener("click", () => Re()), W.appendChild(t);
670
+ }), t.addEventListener("click", () => Te()), F.appendChild(t);
308
671
  }
309
672
  }
310
- const k = f({
673
+ const I = h({
311
674
  flex: "1",
312
675
  overflow: "auto",
313
676
  padding: "16px",
314
- backgroundColor: Qe
677
+ backgroundColor: mt
315
678
  });
316
- k.className = "ago-chat-widget__messages", k.setAttribute("role", "log"), k.setAttribute("aria-live", "polite"), k.setAttribute("aria-relevant", "additions text"), k.setAttribute("aria-atomic", "false");
317
- const { inputRow: pt, setDisabled: ft, focus: be } = Ut({
318
- placeholder: m,
319
- allowFiles: i,
679
+ I.className = "ago-chat-widget__messages", I.setAttribute("role", "log"), I.setAttribute("aria-live", "polite"), I.setAttribute("aria-relevant", "additions text"), I.setAttribute("aria-atomic", "false");
680
+ const { inputRow: _e, setDisabled: At, focus: ge } = on({
681
+ placeholder: b,
682
+ allowFiles: a,
320
683
  onSend: (e, t) => {
321
- ye(e, t);
684
+ $e(e, t);
322
685
  }
323
686
  });
324
- Ht(), V.append(...W ? [W] : [], k, pt);
325
- let fe = V, U, A;
326
- const ve = p === "left" ? "left" : "right";
327
- if (K && (U = f({
687
+ nn(), d.append(...F ? [F] : [], I, _e);
688
+ let he = d, U, N;
689
+ const xe = m === "left" ? "left" : "right";
690
+ if (D && (U = h({
328
691
  position: "fixed",
329
692
  top: "0",
330
693
  bottom: "0",
331
- [ve]: "0",
332
- width: typeof C == "number" ? `${C}px` : C,
694
+ [xe]: "0",
695
+ width: typeof x == "number" ? `${x}px` : x,
333
696
  maxWidth: "100vw",
334
697
  display: "flex",
335
698
  zIndex: "2147483000",
336
699
  transition: "transform 0.3s ease",
337
700
  boxShadow: "rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"
338
- }), U.className = "ago-chat-widget-panel", w(V, {
701
+ }), U.className = "ago-chat-widget-panel", v(d, {
339
702
  height: "100%",
340
703
  width: "100%",
341
704
  borderRadius: "0",
342
705
  border: "none",
343
706
  boxShadow: "none",
344
- [ve === "left" ? "borderRight" : "borderLeft"]: `1px solid ${$}`
345
- }), U.appendChild(V), fe = U), dt) {
346
- if (A = document.createElement("button"), A.type = "button", A.className = "ago-chat-widget-launcher", A.setAttribute("aria-label", `Open ${a}`), w(A, {
707
+ [xe === "left" ? "borderRight" : "borderLeft"]: `1px solid ${L}`
708
+ }), U.appendChild(d), he = U), Ct) {
709
+ if (N = document.createElement("button"), N.type = "button", N.className = "ago-chat-widget-launcher", N.setAttribute("aria-label", `Open ${i}`), v(N, {
347
710
  position: "fixed",
348
711
  bottom: "20px",
349
- [ve]: "20px",
712
+ [xe]: "20px",
350
713
  width: "56px",
351
714
  height: "56px",
352
715
  borderRadius: "50%",
353
716
  border: "none",
354
- backgroundColor: me,
355
- color: he,
717
+ backgroundColor: Re,
718
+ color: ke,
356
719
  cursor: "pointer",
357
720
  display: "flex",
358
721
  alignItems: "center",
359
722
  justifyContent: "center",
360
723
  zIndex: "2147483000",
361
724
  boxShadow: "rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",
362
- fontFamily: Le
363
- }), x) {
725
+ fontFamily: Ee
726
+ }), f) {
364
727
  const e = document.createElement("img");
365
- e.src = x, e.alt = "", w(e, {
728
+ e.src = f, e.alt = "", v(e, {
366
729
  width: "26px",
367
730
  height: "26px",
368
731
  objectFit: "contain"
369
- }), A.appendChild(e);
370
- } else A.appendChild(vt());
371
- A.addEventListener("click", () => Se());
732
+ }), N.appendChild(e);
733
+ } else N.appendChild(un());
734
+ N.addEventListener("click", () => Ne());
372
735
  }
373
- De.appendChild(fe), A && De.appendChild(A), Ee();
374
- const Me = X !== !1, ze = X === !1 ? void 0 : X ?? ((e) => {
375
- ye(e);
736
+ const de = se ? `ago-vt-${++gn}` : "", Ge = 52;
737
+ let K = !1, ce = 0, re = 0, H, pe, X;
738
+ const be = {
739
+ height: d.style.height,
740
+ border: d.style.border,
741
+ borderRadius: d.style.borderRadius,
742
+ boxShadow: d.style.boxShadow
743
+ };
744
+ Pe.appendChild(he), N && Pe.appendChild(N), ve(), se && (H = Ft(), d.insertBefore(H, d.firstChild), pe = document.createElement("style"), pe.id = de, pe.textContent = `::view-transition-group(${de}),::view-transition-group(${de}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`, document.head.appendChild(pe), St === "focus" && (d.addEventListener("pointerdown", (e) => {
745
+ K || !z?.matches || _e.contains(e.target) && (e.preventDefault(), we());
746
+ }, !0), d.addEventListener("focusin", (e) => {
747
+ z?.matches && _e.contains(e.target) && we();
748
+ })), document.addEventListener("keydown", et)), z && z.addEventListener("change", tt);
749
+ const _t = y !== !1, It = y === !1 ? void 0 : y ?? ((e) => {
750
+ $e(e);
376
751
  });
377
- function ut(e, t, s = !0) {
378
- const c = e.role === "user", u = O === "imessage", R = f({
379
- display: "flex",
380
- flexDirection: "column",
381
- alignItems: c ? "flex-end" : "flex-start",
382
- marginBottom: u && !s ? "2px" : "16px"
383
- });
384
- if (R.className = `ago-message ago-message--${e.role}`, !c && B && e.agent) {
385
- const g = f({
386
- fontSize: "13px",
387
- fontWeight: "500",
388
- color: ae,
389
- marginBottom: "6px",
390
- padding: "0 4px"
391
- });
392
- g.className = "ago-message__agent", g.textContent = e.agent.displayName || e.agent.name, R.appendChild(g);
393
- }
394
- if (!c && e.sources && e.sources.length > 0) {
395
- const g = f({
396
- display: "grid",
397
- gridTemplateColumns: "1fr 1fr",
398
- gap: "6px",
399
- marginBottom: "10px",
400
- width: "100%",
401
- maxWidth: "85%"
402
- });
403
- g.className = "ago-message__sources", e.sources.forEach((h, y) => {
404
- const _ = h.url ? document.createElement("a") : document.createElement("div");
405
- h.url && _ instanceof HTMLAnchorElement && (_.href = h.url, _.target = "_blank", _.rel = "noopener noreferrer"), w(_, {
406
- display: "flex",
407
- alignItems: "center",
408
- gap: "8px",
409
- padding: "8px 10px",
410
- border: `1px solid ${$}`,
411
- borderRadius: "8px",
412
- backgroundColor: Q,
413
- textDecoration: "none",
414
- color: ae,
415
- fontSize: "12px",
416
- overflow: "hidden"
417
- });
418
- const G = f({
419
- flexShrink: "0",
420
- width: "18px",
421
- height: "18px",
422
- borderRadius: "3px",
423
- border: `1px solid ${Ae}`,
424
- color: Ae,
425
- fontSize: "11px",
426
- fontWeight: "500",
427
- display: "flex",
428
- alignItems: "center",
429
- justifyContent: "center",
430
- backgroundColor: "#f0f4ff"
431
- });
432
- G.textContent = String(y + 1);
433
- const P = f({
434
- overflow: "hidden",
435
- textOverflow: "ellipsis",
436
- whiteSpace: "nowrap"
437
- });
438
- P.textContent = h.title, P.title = h.title, _.append(G, P), g.appendChild(_);
439
- }), R.appendChild(g);
440
- }
441
- if (e.attachments && e.attachments.length > 0) {
442
- const g = f({
443
- display: "flex",
444
- flexWrap: "wrap",
445
- gap: "6px",
446
- marginBottom: "6px",
447
- justifyContent: c ? "flex-end" : "flex-start",
448
- maxWidth: "75%"
449
- });
450
- g.className = "ago-message__attachments";
451
- for (const h of e.attachments) {
452
- const y = Rt(h.url);
453
- if (yt(h) && y) {
454
- const M = document.createElement("a");
455
- M.href = y, M.target = "_blank", M.rel = "noopener noreferrer", w(M, {
456
- display: "inline-block",
457
- textDecoration: "none"
458
- });
459
- const re = document.createElement("img");
460
- re.src = y, re.alt = h.name, re.loading = "lazy", w(re, {
461
- maxWidth: "180px",
462
- maxHeight: "160px",
463
- objectFit: "cover",
464
- borderRadius: "10px",
465
- border: `1px solid ${$}`,
466
- display: "block"
467
- }), M.appendChild(re), g.appendChild(M);
468
- continue;
469
- }
470
- const _ = y ? document.createElement("a") : document.createElement("div");
471
- y && _ instanceof HTMLAnchorElement && (_.href = y, _.target = "_blank", _.rel = "noopener noreferrer"), w(_, {
472
- display: "inline-flex",
473
- alignItems: "center",
474
- gap: "8px",
475
- padding: "8px 12px",
476
- borderRadius: "10px",
477
- border: `1px solid ${$}`,
478
- backgroundColor: c ? "rgba(255,255,255,0.12)" : Q,
479
- color: c ? he : ae,
480
- fontSize: "13px",
481
- textDecoration: "none",
482
- maxWidth: "220px"
483
- });
484
- const G = document.createElement("span");
485
- G.textContent = "📄", G.setAttribute("aria-hidden", "true"), w(G, {
486
- fontSize: "16px",
487
- lineHeight: "1",
488
- flexShrink: "0"
489
- });
490
- const P = f({
491
- display: "flex",
492
- flexDirection: "column",
493
- minWidth: "0"
494
- }), ke = f({
495
- overflow: "hidden",
496
- textOverflow: "ellipsis",
497
- whiteSpace: "nowrap",
498
- maxWidth: "160px"
499
- });
500
- ke.textContent = h.name, ke.title = h.name, P.appendChild(ke);
501
- const qe = St(h.fileSize);
502
- if (qe) {
503
- const M = f({
504
- fontSize: "11px",
505
- color: Je
506
- });
507
- M.textContent = qe, P.appendChild(M);
508
- }
509
- _.append(G, P), g.appendChild(_);
510
- }
511
- R.appendChild(g);
512
- }
513
- const N = c || T || u, _e = !!e.content || e.status === "IN_PROGRESS", Y = f({
514
- maxWidth: u || c ? "75%" : N ? "85%" : "100%",
515
- padding: N ? "10px 14px" : "2px 8px",
516
- borderRadius: u ? Mt : N ? Ie : "0",
517
- backgroundColor: c ? me : N ? et : "transparent",
518
- color: c ? he : ae,
519
- wordBreak: "break-word",
520
- fontSize: "16px",
521
- lineHeight: "1.6"
522
- });
523
- if (Y.className = "ago-message__content", u && s) {
524
- Y.style.position = "relative";
525
- const g = f({
526
- position: "absolute",
527
- zIndex: "0",
528
- bottom: "-2px",
529
- width: "20px",
530
- height: "20px",
531
- background: c ? me : et
532
- });
533
- g.className = "ago-message__tail";
534
- const h = f({
535
- position: "absolute",
536
- zIndex: "1",
537
- bottom: "-2px",
538
- width: "10px",
539
- height: "20px",
540
- background: Qe
541
- });
542
- h.className = "ago-message__tail-mask", c ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", h.style.right = "-10px", h.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", h.style.left = "-10px", h.style.borderBottomRightRadius = "10px"), Y.append(g, h);
543
- }
544
- if (e.content ? Y.appendChild($e(e.content)) : e.status === "IN_PROGRESS" && Y.appendChild(Ct()), _e && R.appendChild(Y), t && e.followUpReplies && e.followUpReplies.length > 0) {
545
- const g = f({
546
- display: "flex",
547
- flexWrap: "wrap",
548
- gap: "8px",
549
- marginTop: "10px"
550
- });
551
- g.className = "ago-message__followups";
552
- for (const h of e.followUpReplies) {
553
- const y = document.createElement("button");
554
- y.type = "button", y.className = "ago-message__followup-btn", y.textContent = h, y.disabled = !Me, w(y, {
555
- minHeight: "36px",
556
- padding: "6px 14px",
557
- fontSize: "14px",
558
- borderRadius: Ie,
559
- border: `1px solid ${$}`,
560
- backgroundColor: Q,
561
- color: ae,
562
- cursor: Me ? "pointer" : "default",
563
- transition: "border-color 0.15s"
564
- }), ze && y.addEventListener("click", () => ze(h)), y.addEventListener("mouseenter", () => {
565
- y.style.borderColor = Ae;
566
- }), y.addEventListener("mouseleave", () => {
567
- y.style.borderColor = $;
568
- }), g.appendChild(y);
569
- }
570
- R.appendChild(g);
571
- }
572
- return R;
573
- }
574
- function gt(e) {
575
- const t = f({
576
- display: "flex",
577
- alignItems: "center",
578
- gap: "8px",
579
- padding: "10px 14px",
580
- backgroundColor: "#f0fdf4",
581
- color: "#15803d",
582
- borderRadius: Ie,
583
- marginTop: "8px",
584
- fontSize: "13px",
585
- border: "1px solid #bbf7d0"
586
- });
587
- t.className = "ago-form-notice", t.setAttribute("role", "status");
588
- const s = document.createElement("span");
589
- s.textContent = "✓", s.setAttribute("aria-hidden", "true"), w(s, { fontWeight: "700" });
590
- const c = document.createElement("span");
591
- return c.textContent = e, t.append(s, c), t;
592
- }
593
- function I() {
594
- if (k.replaceChildren(), l.length === 0) {
595
- if (Oe === "static") {
596
- const t = f({
752
+ function $() {
753
+ if (I.replaceChildren(), u.length === 0) {
754
+ if (Fe === "static") {
755
+ const t = h({
597
756
  textAlign: "center",
598
- color: Je,
757
+ color: gt,
599
758
  padding: "24px 16px",
600
759
  fontSize: "16px",
601
760
  lineHeight: "1.5"
602
761
  });
603
- t.appendChild($e(Te)), k.appendChild(t);
762
+ t.appendChild(De(ze)), I.appendChild(t);
604
763
  }
605
- } else l.forEach((t, s) => {
606
- const c = s === l.length - 1 || l[s + 1].role !== t.role;
607
- k.appendChild(ut(t, s === l.length - 1, c));
764
+ } else u.forEach((t, l) => {
765
+ const S = l === u.length - 1 || u[l + 1].role !== t.role;
766
+ I.appendChild(cn(t, {
767
+ isLast: l === u.length - 1,
768
+ isLastOfBlock: S,
769
+ bubbleStyle: _,
770
+ showAgentName: A,
771
+ agentBubble: R,
772
+ followUpEnabled: _t,
773
+ followUpHandler: It,
774
+ isMobile: !!z?.matches
775
+ }));
608
776
  });
609
- for (const t of Be) k.appendChild(gt(t));
610
- if (oe) {
611
- const t = f({
777
+ for (const t of We) I.appendChild(pn(t));
778
+ if (le) {
779
+ const t = h({
612
780
  padding: "10px 14px",
613
781
  backgroundColor: "#fef2f2",
614
782
  color: "#dc2626",
@@ -617,36 +785,36 @@ function Xt(r, o) {
617
785
  fontSize: "13px",
618
786
  border: "1px solid #fecaca"
619
787
  });
620
- t.setAttribute("role", "alert"), t.textContent = oe, k.appendChild(t);
788
+ t.setAttribute("role", "alert"), t.textContent = le, I.appendChild(t);
621
789
  }
622
- k.scrollTop = k.scrollHeight;
623
- const e = l[l.length - 1];
624
- ft(H && e?.role === "assistant" && e.status === "IN_PROGRESS");
790
+ I.scrollTop = I.scrollHeight;
791
+ const e = u[u.length - 1];
792
+ At(Z && e?.role === "assistant" && e.status === "IN_PROGRESS");
625
793
  }
626
- function mt() {
627
- for (let e = l.length - 1; e >= 0; e--) {
628
- const t = l[e];
794
+ function $t() {
795
+ for (let e = u.length - 1; e >= 0; e--) {
796
+ const t = u[e];
629
797
  if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
630
798
  }
631
799
  }
632
- const Fe = (e) => {
633
- D || (D = e.conversationId);
634
- }, He = (e) => {
635
- const t = mt();
636
- t && (t.content += e.content, I());
637
- }, We = (e) => {
638
- const t = l.findIndex((s) => s.id === e.id || s.role === "assistant" && s.status === "IN_PROGRESS");
639
- t >= 0 ? l[t] = e : l.push(e), I(), be();
640
- }, Ue = (e) => {
641
- const t = l.findIndex((s) => s.id === e.id || s.role === "assistant" && s.status === "IN_PROGRESS");
642
- t >= 0 ? l[t] = e : l.push(e), H = !1, I(), e.status === "DONE" && z?.({
800
+ const Ve = (e) => {
801
+ P || (P = e.conversationId);
802
+ }, je = (e) => {
803
+ const t = $t();
804
+ t && (t.content += e.content, $());
805
+ }, qe = (e) => {
806
+ const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
807
+ t >= 0 ? u[t] = e : u.push(e), $(), ge();
808
+ }, Ke = (e) => {
809
+ const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
810
+ t >= 0 ? u[t] = e : u.push(e), Z = !1, $(), e.status === "DONE" && k?.({
643
811
  id: e.id,
644
812
  content: e.content
645
813
  });
646
- }, Ge = (e) => {
647
- oe = e.error, H = !1, l = l.filter((t) => !t.id.startsWith("temp-")), I();
814
+ }, Xe = (e) => {
815
+ le = e.error, Z = !1, u = u.filter((t) => !t.id.startsWith("temp-")), $();
648
816
  };
649
- function ht(e) {
817
+ function Lt(e) {
650
818
  const t = {
651
819
  id: `ago-intro-${Date.now()}`,
652
820
  conversationId: "",
@@ -655,267 +823,287 @@ function Xt(r, o) {
655
823
  status: "IN_PROGRESS",
656
824
  createdAt: /* @__PURE__ */ new Date()
657
825
  };
658
- l.push(t), I();
659
- const s = e.match(/\S+\s*/g) ?? [e];
660
- let c = 0;
661
- F = setInterval(() => {
662
- if (c >= s.length) {
663
- clearInterval(F), F = void 0, t.status = "DONE", I();
826
+ u.push(t), $();
827
+ const l = e.match(/\S+\s*/g) ?? [e];
828
+ let S = 0;
829
+ q = setInterval(() => {
830
+ if (S >= l.length) {
831
+ clearInterval(q), q = void 0, t.status = "DONE", He && (t.followUpReplies = He), $();
664
832
  return;
665
833
  }
666
- t.content += s[c], c++, I();
667
- }, lt);
668
- }
669
- v.on("message:start", Fe), v.on("message:chunk", He), v.on("message:answer-complete", We), v.on("message:complete", Ue), v.on("message:error", Ge);
670
- const Pe = (e) => le?.(e), je = (e) => ne?.(e);
671
- le && v.on("form:submitted", Pe), ne && v.on("form:error", je);
672
- const Ce = [];
673
- let Xe = !1;
674
- const Ke = (e) => {
675
- if (Xe) return;
676
- Ce.push(e.install(v));
834
+ t.content += l[S], S++, $();
835
+ }, wt);
836
+ }
837
+ E.on("message:start", Ve), E.on("message:chunk", je), E.on("message:answer-complete", qe), E.on("message:complete", Ke), E.on("message:error", Xe);
838
+ const Qe = (e) => G?.(e), Ye = (e) => V?.(e);
839
+ G && E.on("form:submitted", Qe), V && E.on("form:error", Ye);
840
+ const Ie = [];
841
+ let Ze = !1;
842
+ const Je = (e) => {
843
+ if (Ze) return;
844
+ Ie.push(e.install(E));
677
845
  let t = e.store.get().submitted;
678
- const s = e.store.subscribe((c) => {
679
- c.submitted && !t && (Be.push(ct(c.submitResult)), I()), t = c.submitted;
846
+ const l = e.store.subscribe((S) => {
847
+ S.submitted && !t && (We.push(kt(S.submitResult)), $()), t = S.submitted;
680
848
  });
681
- Ce.push(s);
849
+ Ie.push(l);
682
850
  };
683
- for (const e of b ?? []) e.schema != null ? Ke(At(e)) : kt(v, e).then((t) => Ke(t)).catch(() => {
851
+ for (const e of s ?? []) e.schema != null ? Je(Xt(e)) : Kt(E, e).then((t) => Je(t)).catch(() => {
684
852
  });
685
- async function ye(e, t) {
686
- const s = e.trim();
687
- if (!s && !t?.length || H) return;
688
- if (se?.(s), H = !0, oe = null, F) {
689
- clearInterval(F), F = void 0;
690
- const u = l.find((R) => R.id.startsWith("ago-intro-"));
691
- u && !u.content ? l = l.filter((R) => R !== u) : u && (u.status = "DONE");
853
+ async function $e(e, t) {
854
+ const l = e.trim();
855
+ if (!l && !t?.length || Z) return;
856
+ if (T?.(l), Z = !0, le = null, q) {
857
+ clearInterval(q), q = void 0;
858
+ const w = u.find((W) => W.id.startsWith("ago-intro-"));
859
+ w && !w.content ? u = u.filter((W) => W !== w) : w && (w.status = "DONE");
692
860
  }
693
- const c = Date.now();
694
- l.push({
695
- id: `temp-user-${c}`,
696
- conversationId: D || "",
697
- content: s,
861
+ const S = Date.now();
862
+ u.push({
863
+ id: `temp-user-${S}`,
864
+ conversationId: P || "",
865
+ content: l,
698
866
  role: "user",
699
867
  status: "DONE",
700
- attachments: t && t.length > 0 ? wt(t) : void 0,
868
+ attachments: t && t.length > 0 ? Wt(t) : void 0,
701
869
  createdAt: /* @__PURE__ */ new Date()
702
- }), l.push({
703
- id: `temp-assistant-${c}`,
704
- conversationId: D || "",
870
+ }), u.push({
871
+ id: `temp-assistant-${S}`,
872
+ conversationId: P || "",
705
873
  content: "",
706
874
  role: "assistant",
707
875
  status: "IN_PROGRESS",
708
876
  createdAt: /* @__PURE__ */ new Date()
709
- }), I();
877
+ }), $();
710
878
  try {
711
- const u = await v.sendMessage(s, {
712
- conversationId: D,
879
+ const w = await E.sendMessage(l, {
880
+ conversationId: P,
713
881
  files: t
714
882
  });
715
- u.conversationId && (D || (D = u.conversationId), ce?.setActiveThread(u.conversationId, u.createdAt));
716
- const R = l.find((N) => N.id === `temp-user-${c}`);
717
- if (R && (R.id = `user-${c}`, R.conversationId = u.conversationId), !l.some((N) => N.id === u.id)) {
718
- const N = l.findIndex((_e) => _e.id === `temp-assistant-${c}`);
719
- N >= 0 ? l[N] = u : l.push(u);
883
+ w.conversationId && (P || (P = w.conversationId), ue?.setActiveThread(w.conversationId, w.createdAt));
884
+ const W = u.find((Q) => Q.id === `temp-user-${S}`);
885
+ if (W && (W.id = `user-${S}`, W.conversationId = w.conversationId), !u.some((Q) => Q.id === w.id)) {
886
+ const Q = u.findIndex((Pt) => Pt.id === `temp-assistant-${S}`);
887
+ Q >= 0 ? u[Q] = w : u.push(w);
720
888
  }
721
- l = l.filter((N) => !N.id.startsWith("temp-")), H = !1, I(), te && we();
722
- } catch (u) {
723
- oe = u instanceof Error ? u.message : "Failed to send message", H = !1, l = l.filter((R) => !R.id.startsWith("temp-")), I();
889
+ u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g && Le();
890
+ } catch (w) {
891
+ le = w instanceof Error ? w.message : "Failed to send message", Z = !1, u = u.filter((W) => !W.id.startsWith("temp-")), $();
724
892
  }
725
893
  }
726
- async function we() {
894
+ async function Le() {
727
895
  try {
728
- const e = await v.getConversations();
729
- pe.splice(0, pe.length, ...e);
896
+ const e = await E.getConversations();
897
+ me.splice(0, me.length, ...e);
730
898
  } catch {
731
899
  }
732
- return pe;
900
+ return me;
733
901
  }
734
- async function xt(e) {
902
+ async function Nt(e) {
735
903
  try {
736
- const t = (await v.getConversation(e))?.messages ?? [];
737
- t.length > 0 && l.length === 0 && (l = t, I());
904
+ const t = (await E.getConversation(e))?.messages ?? [];
905
+ t.length > 0 && u.length === 0 && (u = t, $());
738
906
  } catch {
739
- l.length === 0 && (ce?.clear(), D = void 0);
907
+ u.length === 0 && (ue?.clear(), P = void 0);
740
908
  }
741
909
  }
742
- return I(), be(), D ? xt(D) : Oe === "streaming" && ht(Te), te && we(), {
743
- client: v,
744
- element: fe,
745
- sendMessage: ye,
746
- ...K ? {
747
- open: Se,
748
- close: Re,
749
- toggle: bt
910
+ return $(), se && z?.matches || ge(), P ? Nt(P) : Fe === "streaming" && Lt(ze), g && Le(), {
911
+ client: E,
912
+ element: he,
913
+ sendMessage: $e,
914
+ ...D || se ? {
915
+ open: Bt,
916
+ close: Mt,
917
+ toggle: Ot
750
918
  } : {},
751
- session: ce,
752
- threads: pe,
753
- refreshThreads: we,
919
+ session: ue,
920
+ threads: me,
921
+ refreshThreads: Le,
754
922
  destroy() {
755
- F && clearInterval(F), v.off("message:start", Fe), v.off("message:chunk", He), v.off("message:answer-complete", We), v.off("message:complete", Ue), v.off("message:error", Ge), le && v.off("form:submitted", Pe), ne && v.off("form:error", je), Xe = !0, Ce.forEach((e) => e()), fe.remove(), A?.remove(), o.client || v.destroy();
923
+ q && clearInterval(q), E.off("message:start", Ve), E.off("message:chunk", je), E.off("message:answer-complete", qe), E.off("message:complete", Ke), E.off("message:error", Xe), G && E.off("form:submitted", Qe), V && E.off("form:error", Ye), Ze = !0, Ie.forEach((e) => e()), he.remove(), N?.remove(), H?.remove(), pe?.remove(), X?.remove(), z?.removeEventListener("change", tt), se && (document.removeEventListener("keydown", et), rt(), document.documentElement.style.removeProperty("overflow")), o.client || E.destroy();
756
924
  }
757
925
  };
758
- function Ee() {
926
+ function ve() {
759
927
  if (!U) return;
760
- const e = p === "left" ? "translateX(-100%)" : "translateX(100%)";
761
- U.style.transform = q ? "translateX(0)" : e, U.setAttribute("aria-hidden", q ? "false" : "true"), A && (A.style.display = q ? "none" : "flex");
928
+ {
929
+ const t = xe === "left" ? "border-right" : "border-left";
930
+ z?.matches ? (U.style.width = "100%", d.style.borderRadius = "0", d.style.removeProperty(t)) : (U.style.width = typeof x == "number" ? `${x}px` : x, d.style.setProperty(t, `1px solid ${L}`));
931
+ }
932
+ const e = m === "left" ? "translateX(-100%)" : "translateX(100%)";
933
+ U.style.transform = oe ? "translateX(0)" : e, U.setAttribute("aria-hidden", oe ? "false" : "true"), N && (N.style.display = oe ? "none" : "flex");
762
934
  }
763
- function Se() {
764
- q = !0, Ee(), be();
935
+ function Ne() {
936
+ oe = !0, ve(), ge(), B?.();
765
937
  }
766
- function Re() {
767
- q = !1, Ee();
938
+ function Te() {
939
+ oe = !1, ve(), j?.();
768
940
  }
769
- function bt() {
770
- q ? Re() : Se();
941
+ function Tt() {
942
+ oe ? Te() : Ne();
771
943
  }
772
- function vt() {
773
- const e = "http://www.w3.org/2000/svg", t = document.createElementNS(e, "svg");
774
- t.setAttribute("width", "26"), t.setAttribute("height", "26"), t.setAttribute("viewBox", "0 0 24 24"), t.setAttribute("fill", "none");
775
- const s = document.createElementNS(e, "path");
776
- return s.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), s.setAttribute("stroke", "currentColor"), s.setAttribute("stroke-width", "2"), s.setAttribute("stroke-linecap", "round"), s.setAttribute("stroke-linejoin", "round"), t.appendChild(s), t;
944
+ function Bt() {
945
+ D ? Ne() : we();
777
946
  }
778
- function Ct() {
779
- const e = f({
780
- display: "flex",
781
- gap: "4px",
782
- padding: "4px 0"
947
+ function Mt() {
948
+ D ? Te() : fe();
949
+ }
950
+ function Ot() {
951
+ D ? Tt() : K ? fe() : we();
952
+ }
953
+ function Dt() {
954
+ return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((e) => e.getClientRects().length > 0);
955
+ }
956
+ function et(e) {
957
+ if (!K) return;
958
+ if (e.key === "Escape") {
959
+ fe();
960
+ return;
961
+ }
962
+ if (e.key !== "Tab") return;
963
+ const t = Dt();
964
+ if (t.length === 0) {
965
+ e.preventDefault();
966
+ return;
967
+ }
968
+ const l = t[0], S = t[t.length - 1], w = document.activeElement;
969
+ e.shiftKey && (w === l || !d.contains(w)) ? (e.preventDefault(), S.focus()) : !e.shiftKey && (w === S || !d.contains(w)) && (e.preventDefault(), l.focus());
970
+ }
971
+ function tt(e) {
972
+ D ? ve() : !e.matches && K && fe(), $();
973
+ }
974
+ function nt() {
975
+ return window.visualViewport?.height ?? window.innerHeight;
976
+ }
977
+ function ot() {
978
+ const e = window.visualViewport, t = e?.offsetTop ?? 0, l = e?.height ?? ce, S = Math.min(0, t + l - ce);
979
+ d.style.top = `${S}px`, H && (H.style.top = `${t}px`);
980
+ }
981
+ function ye() {
982
+ re || (re = requestAnimationFrame(() => {
983
+ re = 0, ot();
984
+ }));
985
+ }
986
+ function zt() {
987
+ window.visualViewport?.addEventListener("resize", ye), window.visualViewport?.addEventListener("scroll", ye);
988
+ }
989
+ function rt() {
990
+ window.visualViewport?.removeEventListener("resize", ye), window.visualViewport?.removeEventListener("scroll", ye), re && (cancelAnimationFrame(re), re = 0);
991
+ }
992
+ function it() {
993
+ I.scrollTop = I.scrollHeight;
994
+ }
995
+ function Ft() {
996
+ const e = h({
997
+ position: "fixed",
998
+ top: "0",
999
+ left: "0",
1000
+ right: "0",
1001
+ height: `calc(${Ge}px + env(safe-area-inset-top))`,
1002
+ display: "none",
1003
+ alignItems: "center",
1004
+ justifyContent: "space-between",
1005
+ padding: "env(safe-area-inset-top) 14px 0",
1006
+ backgroundColor: ee,
1007
+ borderBottom: `1px solid ${L}`,
1008
+ zIndex: "2147483001",
1009
+ fontFamily: Ee
783
1010
  });
784
- for (let t = 0; t < 3; t++) {
785
- const s = f({
786
- width: "6px",
787
- height: "6px",
788
- borderRadius: "50%",
789
- backgroundColor: "#b5bfc8",
790
- animation: "ago-pulse 1.2s ease-in-out infinite",
791
- animationDelay: `${t * 0.2}s`
792
- });
793
- e.appendChild(s);
1011
+ if (e.className = "ago-chat-widget-mobile-bar", f) {
1012
+ const l = document.createElement("img");
1013
+ l.src = f, l.alt = "", v(l, {
1014
+ height: "28px",
1015
+ width: "auto"
1016
+ }), e.appendChild(l);
1017
+ } else if (i) {
1018
+ const l = document.createElement("span");
1019
+ l.textContent = i, v(l, {
1020
+ fontSize: "15px",
1021
+ fontWeight: "600",
1022
+ color: J,
1023
+ overflow: "hidden",
1024
+ whiteSpace: "nowrap",
1025
+ textOverflow: "ellipsis"
1026
+ }), e.appendChild(l);
1027
+ } else e.appendChild(h({}));
1028
+ const t = document.createElement("button");
1029
+ return t.type = "button", t.setAttribute("aria-label", "Close"), t.textContent = "×", v(t, {
1030
+ border: "none",
1031
+ background: "transparent",
1032
+ fontSize: "26px",
1033
+ lineHeight: "1",
1034
+ color: J,
1035
+ cursor: "pointer",
1036
+ padding: "4px 8px"
1037
+ }), t.addEventListener("click", () => {
1038
+ fe();
1039
+ }), e.appendChild(t), e;
1040
+ }
1041
+ function Ht() {
1042
+ return typeof document.startViewTransition == "function" && !Rt?.matches && !!z?.matches;
1043
+ }
1044
+ function at(e) {
1045
+ const t = document;
1046
+ if (Ht() && t.startViewTransition) {
1047
+ d.style.setProperty("view-transition-name", de), H?.style.setProperty("view-transition-name", `${de}-bar`);
1048
+ const l = () => {
1049
+ d.style.removeProperty("view-transition-name"), H?.style.removeProperty("view-transition-name");
1050
+ };
1051
+ return t.startViewTransition(e).finished.then(l, l);
794
1052
  }
795
- return e;
1053
+ return e(), Promise.resolve();
796
1054
  }
797
- }
798
- function Ut(r) {
799
- let o = [];
800
- const a = document.createElement("form");
801
- w(a, {
802
- display: "flex",
803
- flexDirection: "column",
804
- gap: "8px",
805
- padding: "12px",
806
- borderTop: `1px solid ${$}`,
807
- backgroundColor: Q
808
- }), a.className = "ago-chat-input";
809
- const n = f({
810
- display: "flex",
811
- flexWrap: "wrap",
812
- gap: "6px"
813
- }), m = f({
814
- display: "flex",
815
- gap: "8px",
816
- alignItems: "flex-end"
817
- }), i = document.createElement("textarea");
818
- i.placeholder = r.placeholder, i.setAttribute("aria-label", r.placeholder), i.rows = 1, w(i, {
819
- flex: "1",
820
- resize: "none",
821
- boxSizing: "border-box",
822
- padding: "10px 12px",
823
- border: `1px solid ${$}`,
824
- borderRadius: "12px",
825
- fontSize: "16px",
826
- fontFamily: Le,
827
- lineHeight: "1.4",
828
- maxHeight: "110px",
829
- overflowY: "hidden"
830
- });
831
- const E = () => {
832
- i.style.height = "auto";
833
- const S = Math.min(i.scrollHeight + 2, 110);
834
- i.style.height = `${S}px`, i.style.overflowY = i.scrollHeight + 2 > 110 ? "auto" : "hidden";
835
- };
836
- i.addEventListener("input", () => {
837
- E(), B();
838
- });
839
- const p = '<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>', C = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>', d = document.createElement("button");
840
- d.type = "submit", d.setAttribute("aria-label", "Send"), d.innerHTML = p, w(d, {
841
- flexShrink: "0",
842
- width: "40px",
843
- height: "40px",
844
- padding: "0",
845
- border: "none",
846
- borderRadius: "50%",
847
- backgroundColor: me,
848
- color: he,
849
- display: "flex",
850
- alignItems: "center",
851
- justifyContent: "center",
852
- cursor: "pointer"
853
- });
854
- let x = !1;
855
- const B = () => {
856
- const b = i.value.trim() !== "" || o.length > 0, S = x || !b;
857
- d.disabled = S, d.innerHTML = x ? C : p, d.style.opacity = S && !x ? "0.5" : "1", d.style.cursor = S ? "default" : "pointer";
858
- };
859
- let T = null, O = null;
860
- r.allowFiles && (T = document.createElement("input"), T.type = "file", T.multiple = !0, w(T, { display: "none" }), O = document.createElement("button"), O.type = "button", O.setAttribute("aria-label", "Attach file"), O.textContent = "📎", w(O, {
861
- padding: "10px 12px",
862
- border: `1px solid ${$}`,
863
- borderRadius: "12px",
864
- backgroundColor: Q,
865
- cursor: "pointer",
866
- fontSize: "14px"
867
- }), O.addEventListener("click", () => T?.click()), T.addEventListener("change", () => {
868
- o = [...o, ...Array.from(T?.files ?? [])], ee();
869
- }));
870
- function ee() {
871
- n.replaceChildren(), o.forEach((b, S) => {
872
- const X = f({
873
- display: "flex",
874
- alignItems: "center",
875
- gap: "4px",
876
- padding: "4px 8px",
877
- backgroundColor: "#f0f4ff",
878
- border: `1px solid ${$}`,
879
- borderRadius: "8px",
880
- fontSize: "12px"
881
- }), se = document.createElement("span");
882
- se.textContent = b.name;
883
- const z = document.createElement("button");
884
- z.type = "button", z.setAttribute("aria-label", `Remove ${b.name}`), z.textContent = "×", w(z, {
1055
+ function st(e) {
1056
+ if (e)
1057
+ X && d.parentElement?.insertBefore(X, d), v(d, {
1058
+ position: "fixed",
1059
+ top: "0",
1060
+ left: "0",
1061
+ right: "0",
1062
+ bottom: "0",
1063
+ height: "var(--ago-vh, 100dvh)",
1064
+ zIndex: "2147483000",
885
1065
  border: "none",
886
- background: "transparent",
887
- cursor: "pointer",
888
- fontSize: "14px",
889
- lineHeight: "1"
890
- }), z.addEventListener("click", () => {
891
- o = o.filter((le, ne) => ne !== S), ee();
892
- }), X.append(se, z), n.appendChild(X);
893
- }), B();
894
- }
895
- const ie = () => {
896
- const b = i.value, S = o;
897
- return i.value = "", E(), o = [], ee(), {
898
- content: b,
899
- files: S
900
- };
901
- }, te = () => {
902
- const { content: b, files: S } = ie();
903
- (b.trim() || S.length > 0) && r.onSend(b.trim(), S.length > 0 ? S : void 0);
904
- };
905
- return a.addEventListener("submit", (b) => {
906
- b.preventDefault(), te();
907
- }), i.addEventListener("keydown", (b) => {
908
- b.key === "Enter" && !b.shiftKey && (b.preventDefault(), te());
909
- }), O && m.appendChild(O), m.append(i, d), T && a.appendChild(T), a.append(n, m), B(), {
910
- inputRow: a,
911
- getValueAndClear: ie,
912
- setDisabled: (b) => {
913
- i.disabled = b, x = b, B();
914
- },
915
- focus: () => i.focus()
916
- };
1066
+ borderRadius: "0",
1067
+ boxShadow: "none",
1068
+ paddingTop: `calc(${Ge}px + env(safe-area-inset-top))`,
1069
+ paddingBottom: "env(safe-area-inset-bottom)"
1070
+ }), d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-label", i), document.documentElement.style.overflow = "hidden", F && (F.style.display = "none"), H && (H.style.display = "flex");
1071
+ else {
1072
+ X?.remove(), X = void 0;
1073
+ for (const t of [
1074
+ "position",
1075
+ "top",
1076
+ "left",
1077
+ "right",
1078
+ "bottom",
1079
+ "z-index",
1080
+ "padding-top",
1081
+ "padding-bottom"
1082
+ ]) d.style.removeProperty(t);
1083
+ d.style.height = be.height, d.style.border = be.border, d.style.borderRadius = be.borderRadius, d.style.boxShadow = be.boxShadow, d.removeAttribute("role"), d.removeAttribute("aria-modal"), d.removeAttribute("aria-label"), document.documentElement.style.removeProperty("overflow"), F && (F.style.display = "flex"), H && (H.style.display = "none");
1084
+ }
1085
+ }
1086
+ function we() {
1087
+ if (K || !z?.matches) return Promise.resolve();
1088
+ const e = d.getBoundingClientRect();
1089
+ if (e.height >= nt() * 0.8) return Promise.resolve();
1090
+ K = !0, X = h({
1091
+ width: `${e.width}px`,
1092
+ height: `${e.height}px`
1093
+ }), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce = nt(), d.style.setProperty("--ago-vh", `${ce}px`), ot(), zt();
1094
+ const t = at(() => st(!0));
1095
+ return t.then(() => {
1096
+ it(), ge();
1097
+ }), it(), B?.(), t;
1098
+ }
1099
+ function fe() {
1100
+ if (!K) return Promise.resolve();
1101
+ K = !1, rt(), d.querySelector("textarea")?.blur();
1102
+ const e = at(() => st(!1));
1103
+ return e.then(() => d.style.removeProperty("--ago-vh")), ce = 0, j?.(), e;
1104
+ }
917
1105
  }
918
1106
  export {
919
- Xt as mountChatWidget,
920
- $e as renderMarkdown
1107
+ yn as mountChatWidget,
1108
+ De as renderMarkdown
921
1109
  };