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