@useago/sdk 1.0.11 → 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,542 +1,781 @@
1
- import { t as mt, u as ht } from "./AgoClient-QcTtrN7u.js";
2
- import { r as xt, t as bt } from "./createFormCollector-CFt1_QSL.js";
3
- import { t as vt } from "./createConversationSession-CR-71aLR.js";
4
- var yt = {
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 q(r) {
12
- return r.replace(/[&<>"']/g, (o) => yt[o]);
167
+ function ne(t) {
168
+ return t.replace(/[&<>"']/g, (o) => Zt[o]);
13
169
  }
14
- function Pe(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 Ze = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', le = "";
19
- function G(r) {
20
- const o = [], a = (u) => (o.push(u), `${le}${o.length - 1}${le}`);
21
- let n = r;
22
- return n = n.replace(/`([^`]+)`/g, (u, s) => a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Ze}">${q(s)}</code>`)), n = n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (u, s, v) => {
23
- const p = Pe(v);
24
- return p ? a(`<img alt="${q(s)}" src="${q(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : u;
25
- }), n = n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (u, s, v) => {
26
- const p = Pe(v);
27
- return p ? a(`<a href="${q(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${G(s)}</a>`) : u;
28
- }), n = q(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(`${le}(\\d+)${le}`, "g"), (u, s) => o[Number(s)]), 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 N(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 Qe = /^ {0,3}([-*_])( *\1){2,} *$/, Je = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, et = /^ {0,3}(```+|~~~+)/, ce = /^ {0,3}>\s?/, V = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Ct = [
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
- ], Se = (r) => r.match(/^\s*/)?.[0].length ?? 0;
42
- function wt(r) {
43
- return r.trim() === "" || Qe.test(r) || Je.test(r) || et.test(r) || ce.test(r) || V.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 tt(r) {
46
- const o = r[0].match(V), a = o[1].length, n = /\d/.test(o[2]), u = N(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 s = 0;
53
- for (; s < r.length; ) {
54
- const v = r[s].match(V), p = [];
55
- for (s++; s < r.length && Se(r[s]) > a; )
56
- p.push(r[s]), s++;
57
- const b = N("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 = v[3].match(/^\[([ xX])\]\s+(.*)$/);
62
- d ? (b.style.listStyleType = "none", b.style.marginLeft = "-20px", b.innerHTML = `<span style="margin-right:6px">${d[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${G(d[2])}`) : b.innerHTML = G(v[3]), p.filter((g) => V.test(g)).length > 0 && b.appendChild(tt(p.filter((g) => g.trim() !== ""))), u.appendChild(b);
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 u;
220
+ return v;
65
221
  }
66
- function Et(r) {
67
- const o = (p) => p.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((b) => b.trim()), a = N("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 = N("table", {
226
+ }), r = D("table", {
71
227
  borderCollapse: "collapse",
72
228
  width: "100%",
73
229
  fontSize: "13px"
74
- }), u = document.createElement("thead"), s = document.createElement("tr");
75
- for (const p of o(r[0])) s.appendChild(N("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
- }, G(p)));
82
- u.appendChild(s), n.appendChild(u);
83
- const v = document.createElement("tbody");
84
- for (const p of r.slice(2)) {
237
+ }, ee(u)));
238
+ v.appendChild(a), r.appendChild(v);
239
+ const C = document.createElement("tbody");
240
+ for (const u of t.slice(2)) {
85
241
  const b = document.createElement("tr");
86
- for (const d of o(p)) b.appendChild(N("td", {
242
+ for (const s of o(u)) b.appendChild(D("td", {
87
243
  border: "1px solid #dee3e8",
88
244
  padding: "6px 10px"
89
- }, G(d)));
90
- v.appendChild(b);
245
+ }, ee(s)));
246
+ C.appendChild(b);
91
247
  }
92
- return n.appendChild(v), a.appendChild(n), a;
248
+ return r.appendChild(C), i.appendChild(r), i;
93
249
  }
94
- var St = (r) => !!r && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);
95
- function Re(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 s = a[n];
102
- if (s.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 v = s.match(et);
107
- if (v) {
108
- const d = v[1][0], g = [];
109
- for (n++; n < a.length && !new RegExp(`^ {0,3}${d === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(a[n]); )
110
- g.push(a[n]), n++;
111
- n++;
112
- const B = N("pre", { margin: "0 0 8px 0" });
113
- B.appendChild(N("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: Ze,
276
+ fontFamily: pt,
121
277
  whiteSpace: "pre"
122
- }, q(g.join(`
123
- `)))), o.appendChild(B);
278
+ }, ne(m.join(`
279
+ `)))), o.appendChild(R);
124
280
  continue;
125
281
  }
126
- if (Qe.test(s)) {
127
- o.appendChild(N("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 = s.match(Je);
135
- if (p) {
136
- const d = p[1].length;
137
- o.appendChild(N(`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: Ct[d - 1],
295
+ fontSize: Jt[s - 1],
140
296
  fontWeight: "600",
141
297
  lineHeight: "1.3"
142
- }, G(p[2]))), n++;
298
+ }, ee(u[2]))), r++;
143
299
  continue;
144
300
  }
145
- if (ce.test(s)) {
146
- const d = [];
147
- for (; n < a.length && ce.test(a[n]); )
148
- d.push(a[n].replace(ce, "")), n++;
149
- const g = N("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
- g.appendChild(Re(d.join(`
157
- `))), o.appendChild(g);
312
+ m.appendChild(Te(s.join(`
313
+ `))), o.appendChild(m);
158
314
  continue;
159
315
  }
160
- if (s.includes("|") && St(a[n + 1])) {
161
- const d = [s, 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(Et(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 (V.test(s)) {
168
- const d = [], g = Se(s);
169
- for (; n < a.length && a[n].trim() !== ""; )
170
- if (V.test(a[n]) || Se(a[n]) > g)
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(tt(d));
329
+ o.appendChild(gt(s));
174
330
  continue;
175
331
  }
176
- const b = [s];
177
- for (n++; n < a.length && !wt(a[n]); )
178
- b.push(a[n]), n++;
179
- o.appendChild(N("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
- }, b.map((d) => G(d)).join("<br>")));
338
+ }, b.map((s) => ee(s)).join("<br>")));
183
339
  }
184
- const u = o.lastElementChild;
185
- return u && (u.style.marginBottom = "0"), o;
340
+ const v = o.lastElementChild;
341
+ return v && (v.style.marginBottom = "0"), o;
186
342
  }
187
- var _e = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', je = {
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
- }, pe = "var(--ago-brand-color, #03182f)", ke = "var(--ago-brand-text-color, #fff)", Rt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Xe = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", Ke = "var(--ago-messages-background, #fbfbfb)", de = "var(--ago-text-color, #30373e)", _t = "var(--ago-muted-text-color, #6b6d6f)", O = "var(--ago-border-color, #dee3e8)", we = "var(--ago-accent-color, #1b5fc4)", qe = "var(--ago-agent-bubble-background, #f1f3f5)", kt = "var(--ago-radius, 16px)", Ee = "var(--ago-message-radius, 16px)", At = "var(--ago-message-radius, 20px)";
203
- function It(r, o) {
204
- if (o)
205
- for (const a of Object.keys(je)) {
206
- const n = o[a];
207
- n != null && r.style.setProperty(je[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 E(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 x(r = {}) {
214
- const o = document.createElement("div");
215
- return E(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;
578
+ }
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;
216
584
  }
217
- var Ve = "Form submitted.";
218
- function Nt(r) {
219
- if (typeof r == "string") return r || null;
220
- if (!r || typeof r != "object") return null;
221
- const o = r;
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 Ye = "ago-chat-widget-keyframes";
232
- function $t() {
233
- if (typeof document > "u" || document.getElementById(Ye)) return;
234
- const r = document.createElement("style");
235
- r.id = Ye, 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 Lt(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 Mt(r, o) {
243
- const { title: a = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: u = "Type a message...", allowFiles: s = !1, height: v = 500, placement: p = "inline", width: b = 400, defaultOpen: d = !1, logoUrl: g, showAgentName: B = !1, agentBubble: $ = !1, bubbleStyle: L = "default", showHeader: Y = !0, theme: te, loadThreads: Z = !1, forms: m, formSubmittedMessage: y = Ve, onFollowUpClick: P, onMessageSent: ne, onMessageReceived: D, onFormSubmitted: oe, onFormError: Q } = o, re = 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, Ae = re.message, Ie = re.mode ?? "static", nt = "speed" in re && re.speed || 45;
247
- if (!o.client && !o.config?.baseUrl) throw new ht("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
248
- const h = o.client ?? new mt(o.config), Ne = Lt(r), j = p === "left" || p === "right", ot = j && (o.launcher ?? !0);
249
- let X = j ? d : !0;
250
- const fe = o.persistConversation, ae = fe ? vt(fe === !0 ? {} : fe) : void 0;
251
- let T = o.conversationId ?? ae?.getLastActiveThread() ?? void 0, l = [], F = !1, J = null, M;
252
- const $e = [];
253
- function rt(e) {
254
- if (typeof y == "function") {
255
- const i = y(e);
256
- if (typeof i == "string" && i) return i;
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 = Nt(e);
259
- return t || (typeof y == "string" ? y : Ve);
621
+ const n = ln(e);
622
+ return n || (typeof f == "string" ? f : lt);
260
623
  }
261
- const se = [], K = x({
624
+ const pe = [], d = x({
262
625
  display: "flex",
263
626
  flexDirection: "column",
264
- height: j ? "100%" : typeof v == "number" ? `${v}px` : v,
265
- border: `1px solid ${O}`,
266
- borderRadius: kt,
627
+ height: z ? "100%" : typeof C == "number" ? `${C}px` : C,
628
+ border: `1px solid ${$}`,
629
+ borderRadius: Kt,
267
630
  overflow: "hidden",
268
- backgroundColor: ee,
269
- fontFamily: _e,
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
- K.className = "ago-chat-widget", It(K, te);
274
- let z;
275
- if (Y) {
276
- if (z = x({
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
- borderBottom: `1px solid ${O}`,
279
- backgroundColor: Rt,
280
- color: Xe,
641
+ borderBottom: `1px solid ${$}`,
642
+ backgroundColor: Vt,
643
+ color: rt,
281
644
  display: "flex",
282
645
  alignItems: "center",
283
646
  gap: "10px"
284
- }), z.className = "ago-chat-widget__header", g) {
285
- const t = document.createElement("img");
286
- t.src = g, t.alt = "Logo", E(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
- }), z.appendChild(t);
652
+ }), H.appendChild(n);
290
653
  }
291
654
  const e = document.createElement("h3");
292
- if (e.textContent = a, E(e, {
655
+ if (e.textContent = i, y(e, {
293
656
  margin: "0",
294
657
  fontSize: "15px",
295
658
  fontWeight: "600"
296
- }), z.appendChild(e), j) {
297
- const t = document.createElement("button");
298
- t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", E(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: Xe,
665
+ color: rt,
303
666
  fontSize: "22px",
304
667
  lineHeight: "1",
305
668
  cursor: "pointer",
306
669
  padding: "0 2px"
307
- }), t.addEventListener("click", () => ye()), z.appendChild(t);
670
+ }), n.addEventListener("click", () => Ie()), H.appendChild(n);
308
671
  }
309
672
  }
310
- const R = x({
673
+ const _ = x({
311
674
  flex: "1",
312
675
  overflow: "auto",
313
676
  padding: "16px",
314
- backgroundColor: Ke
677
+ backgroundColor: dt
315
678
  });
316
- R.className = "ago-chat-widget__messages", R.setAttribute("role", "log"), R.setAttribute("aria-live", "polite"), R.setAttribute("aria-relevant", "additions text"), R.setAttribute("aria-atomic", "false");
317
- const { inputRow: at, setDisabled: st, focus: ue } = Tt({
318
- placeholder: u,
319
- allowFiles: s,
320
- onSend: (e, t) => {
321
- he(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
- $t(), K.append(...z ? [z] : [], R, at);
325
- let ie = K, U, _;
326
- const ge = p === "left" ? "left" : "right";
327
- if (j && (U = x({
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
- [ge]: "0",
694
+ [me]: "0",
332
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", E(K, {
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
- [ge === "left" ? "borderRight" : "borderLeft"]: `1px solid ${O}`
345
- }), U.appendChild(K), ie = U), ot) {
346
- if (_ = document.createElement("button"), _.type = "button", _.className = "ago-chat-widget-launcher", _.setAttribute("aria-label", `Open ${a}`), E(_, {
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
- [ge]: "20px",
712
+ [me]: "20px",
350
713
  width: "56px",
351
714
  height: "56px",
352
715
  borderRadius: "50%",
353
716
  border: "none",
354
- backgroundColor: pe,
355
- color: ke,
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: _e
363
- }), g) {
725
+ fontFamily: ye
726
+ }), m) {
364
727
  const e = document.createElement("img");
365
- e.src = g, e.alt = "", E(e, {
728
+ e.src = m, e.alt = "", y(e, {
366
729
  width: "26px",
367
730
  height: "26px",
368
731
  objectFit: "contain"
369
- }), _.appendChild(e);
370
- } else _.appendChild(ut());
371
- _.addEventListener("click", () => ve());
732
+ }), L.appendChild(e);
733
+ } else L.appendChild(sn());
734
+ L.addEventListener("click", () => _e());
372
735
  }
373
- Ne.appendChild(ie), _ && Ne.appendChild(_), be();
374
- const Le = P !== !1, Te = P === !1 ? void 0 : P ?? ((e) => {
375
- he(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 it(e, t, i = !0) {
378
- const c = e.role === "user", f = L === "imessage", w = x({
379
- display: "flex",
380
- flexDirection: "column",
381
- alignItems: c ? "flex-end" : "flex-start",
382
- marginBottom: f && !i ? "2px" : "16px"
383
- });
384
- if (w.className = `ago-message ago-message--${e.role}`, !c && B && e.agent) {
385
- const C = x({
386
- fontSize: "13px",
387
- fontWeight: "500",
388
- color: de,
389
- marginBottom: "6px",
390
- padding: "0 4px"
391
- });
392
- C.className = "ago-message__agent", C.textContent = e.agent.displayName || e.agent.name, w.appendChild(C);
393
- }
394
- if (!c && e.sources && e.sources.length > 0) {
395
- const C = x({
396
- display: "grid",
397
- gridTemplateColumns: "1fr 1fr",
398
- gap: "6px",
399
- marginBottom: "10px",
400
- width: "100%",
401
- maxWidth: "85%"
402
- });
403
- C.className = "ago-message__sources", e.sources.forEach((S, I) => {
404
- const W = S.url ? document.createElement("a") : document.createElement("div");
405
- S.url && W instanceof HTMLAnchorElement && (W.href = S.url, W.target = "_blank", W.rel = "noopener noreferrer"), E(W, {
406
- display: "flex",
407
- alignItems: "center",
408
- gap: "8px",
409
- padding: "8px 10px",
410
- border: `1px solid ${O}`,
411
- borderRadius: "8px",
412
- backgroundColor: ee,
413
- textDecoration: "none",
414
- color: de,
415
- fontSize: "12px",
416
- overflow: "hidden"
417
- });
418
- const Ge = x({
419
- flexShrink: "0",
420
- width: "18px",
421
- height: "18px",
422
- borderRadius: "3px",
423
- border: `1px solid ${we}`,
424
- color: we,
425
- fontSize: "11px",
426
- fontWeight: "500",
427
- display: "flex",
428
- alignItems: "center",
429
- justifyContent: "center",
430
- backgroundColor: "#f0f4ff"
431
- });
432
- Ge.textContent = String(I + 1);
433
- const Ce = x({
434
- overflow: "hidden",
435
- textOverflow: "ellipsis",
436
- whiteSpace: "nowrap"
437
- });
438
- Ce.textContent = S.title, Ce.title = S.title, W.append(Ge, Ce), C.appendChild(W);
439
- }), w.appendChild(C);
440
- }
441
- const A = c || $ || f, H = x({
442
- maxWidth: f || c ? "75%" : A ? "85%" : "100%",
443
- padding: A ? "10px 14px" : "2px 8px",
444
- borderRadius: f ? At : A ? Ee : "0",
445
- backgroundColor: c ? pe : A ? qe : "transparent",
446
- color: c ? ke : de,
447
- wordBreak: "break-word",
448
- fontSize: "16px",
449
- lineHeight: "1.6"
450
- });
451
- if (H.className = "ago-message__content", f && i) {
452
- H.style.position = "relative";
453
- const C = x({
454
- position: "absolute",
455
- zIndex: "0",
456
- bottom: "-2px",
457
- width: "20px",
458
- height: "20px",
459
- background: c ? pe : qe
460
- });
461
- C.className = "ago-message__tail";
462
- const S = x({
463
- position: "absolute",
464
- zIndex: "1",
465
- bottom: "-2px",
466
- width: "10px",
467
- height: "20px",
468
- background: Ke
469
- });
470
- S.className = "ago-message__tail-mask", c ? (C.style.right = "-8px", C.style.borderBottomLeftRadius = "16px 14px", S.style.right = "-10px", S.style.borderBottomLeftRadius = "10px") : (C.style.left = "-7px", C.style.borderBottomRightRadius = "16px 14px", S.style.left = "-10px", S.style.borderBottomRightRadius = "10px"), H.append(C, S);
471
- }
472
- if (e.content ? H.appendChild(Re(e.content)) : e.status === "IN_PROGRESS" && H.appendChild(gt()), w.appendChild(H), t && e.followUpReplies && e.followUpReplies.length > 0) {
473
- const C = x({
474
- display: "flex",
475
- flexWrap: "wrap",
476
- gap: "8px",
477
- marginTop: "10px"
478
- });
479
- C.className = "ago-message__followups";
480
- for (const S of e.followUpReplies) {
481
- const I = document.createElement("button");
482
- I.type = "button", I.className = "ago-message__followup-btn", I.textContent = S, I.disabled = !Le, E(I, {
483
- minHeight: "36px",
484
- padding: "6px 14px",
485
- fontSize: "14px",
486
- borderRadius: Ee,
487
- border: `1px solid ${O}`,
488
- backgroundColor: ee,
489
- color: de,
490
- cursor: Le ? "pointer" : "default",
491
- transition: "border-color 0.15s"
492
- }), Te && I.addEventListener("click", () => Te(S)), I.addEventListener("mouseenter", () => {
493
- I.style.borderColor = we;
494
- }), I.addEventListener("mouseleave", () => {
495
- I.style.borderColor = O;
496
- }), C.appendChild(I);
497
- }
498
- w.appendChild(C);
499
- }
500
- return w;
501
- }
502
- function lt(e) {
503
- const t = x({
504
- display: "flex",
505
- alignItems: "center",
506
- gap: "8px",
507
- padding: "10px 14px",
508
- backgroundColor: "#f0fdf4",
509
- color: "#15803d",
510
- borderRadius: Ee,
511
- marginTop: "8px",
512
- fontSize: "13px",
513
- border: "1px solid #bbf7d0"
514
- });
515
- t.className = "ago-form-notice", t.setAttribute("role", "status");
516
- const i = document.createElement("span");
517
- i.textContent = "✓", i.setAttribute("aria-hidden", "true"), E(i, { fontWeight: "700" });
518
- const c = document.createElement("span");
519
- return c.textContent = e, t.append(i, c), t;
520
- }
521
- function k() {
522
- if (R.replaceChildren(), l.length === 0) {
523
- if (Ie === "static") {
524
- const t = x({
752
+ function N() {
753
+ if (_.replaceChildren(), p.length === 0) {
754
+ if (Me === "static") {
755
+ const n = x({
525
756
  textAlign: "center",
526
- color: _t,
757
+ color: ct,
527
758
  padding: "24px 16px",
528
759
  fontSize: "16px",
529
760
  lineHeight: "1.5"
530
761
  });
531
- t.appendChild(Re(Ae)), R.appendChild(t);
762
+ n.appendChild(Te(Oe)), _.appendChild(n);
532
763
  }
533
- } else l.forEach((t, i) => {
534
- const c = i === l.length - 1 || l[i + 1].role !== t.role;
535
- R.appendChild(it(t, i === 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
+ }));
536
775
  });
537
- for (const t of $e) R.appendChild(lt(t));
538
- if (J) {
539
- const t = x({
776
+ for (const n of He) _.appendChild(rn(n));
777
+ if (ie) {
778
+ const n = x({
540
779
  padding: "10px 14px",
541
780
  backgroundColor: "#fef2f2",
542
781
  color: "#dc2626",
@@ -545,37 +784,37 @@ function Mt(r, o) {
545
784
  fontSize: "13px",
546
785
  border: "1px solid #fecaca"
547
786
  });
548
- t.setAttribute("role", "alert"), t.textContent = J, R.appendChild(t);
787
+ n.setAttribute("role", "alert"), n.textContent = ie, _.appendChild(n);
549
788
  }
550
- R.scrollTop = R.scrollHeight;
551
- const e = l[l.length - 1];
552
- st(F && e?.role === "assistant" && e.status === "IN_PROGRESS");
553
- }
554
- function dt() {
555
- for (let e = l.length - 1; e >= 0; e--) {
556
- const t = l[e];
557
- 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;
558
797
  }
559
798
  }
560
- const Oe = (e) => {
561
- T || (T = e.conversationId);
562
- }, Be = (e) => {
563
- const t = dt();
564
- t && (t.content += e.content, k());
565
- }, De = (e) => {
566
- const t = l.findIndex((i) => i.id === e.id || i.role === "assistant" && i.status === "IN_PROGRESS");
567
- t >= 0 ? l[t] = e : l.push(e), k(), ue();
568
- }, Me = (e) => {
569
- const t = l.findIndex((i) => i.id === e.id || i.role === "assistant" && i.status === "IN_PROGRESS");
570
- t >= 0 ? l[t] = e : l.push(e), F = !1, k(), e.status === "DONE" && D?.({
799
+ const We = (e) => {
800
+ P || (P = e.conversationId);
801
+ }, Ue = (e) => {
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?.({
571
810
  id: e.id,
572
811
  content: e.content
573
812
  });
574
- }, He = (e) => {
575
- J = e.error, F = !1, l = l.filter((t) => !t.id.startsWith("temp-")), k();
813
+ }, Ve = (e) => {
814
+ ie = e.error, Y = !1, p = p.filter((n) => !n.id.startsWith("temp-")), N();
576
815
  };
577
- function ct(e) {
578
- const t = {
816
+ function kt(e) {
817
+ const n = {
579
818
  id: `ago-intro-${Date.now()}`,
580
819
  conversationId: "",
581
820
  content: "",
@@ -583,266 +822,275 @@ function Mt(r, o) {
583
822
  status: "IN_PROGRESS",
584
823
  createdAt: /* @__PURE__ */ new Date()
585
824
  };
586
- l.push(t), k();
587
- const i = e.match(/\S+\s*/g) ?? [e];
588
- let c = 0;
589
- M = setInterval(() => {
590
- if (c >= i.length) {
591
- clearInterval(M), M = void 0, t.status = "DONE", k();
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();
592
831
  return;
593
832
  }
594
- t.content += i[c], c++, k();
595
- }, nt);
596
- }
597
- h.on("message:start", Oe), h.on("message:chunk", Be), h.on("message:answer-complete", De), h.on("message:complete", Me), h.on("message:error", He);
598
- const Fe = (e) => oe?.(e), ze = (e) => Q?.(e);
599
- oe && h.on("form:submitted", Fe), Q && h.on("form:error", ze);
600
- const me = [];
601
- let Ue = !1;
602
- const We = (e) => {
603
- if (Ue) return;
604
- me.push(e.install(h));
605
- let t = e.store.get().submitted;
606
- const i = e.store.subscribe((c) => {
607
- c.submitted && !t && ($e.push(rt(c.submitResult)), k()), 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;
608
847
  });
609
- me.push(i);
848
+ Re.push(c);
610
849
  };
611
- for (const e of m ?? []) e.schema != null ? We(bt(e)) : xt(h, e).then((t) => We(t)).catch(() => {
850
+ for (const e of l ?? []) e.schema != null ? Qe(Ut(e)) : Wt(E, e).then((n) => Qe(n)).catch(() => {
612
851
  });
613
- async function he(e, t) {
614
- const i = e.trim();
615
- if (!i && !t?.length || F) return;
616
- if (ne?.(i), F = !0, J = null, M) {
617
- clearInterval(M), M = void 0;
618
- const f = l.find((w) => w.id.startsWith("ago-intro-"));
619
- f && !f.content ? l = l.filter((w) => w !== f) : f && (f.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");
620
859
  }
621
- const c = Date.now();
622
- l.push({
623
- id: `temp-user-${c}`,
624
- conversationId: T || "",
625
- content: i,
860
+ const S = Date.now();
861
+ p.push({
862
+ id: `temp-user-${S}`,
863
+ conversationId: P || "",
864
+ content: c,
626
865
  role: "user",
627
866
  status: "DONE",
867
+ attachments: n && n.length > 0 ? Dt(n) : void 0,
628
868
  createdAt: /* @__PURE__ */ new Date()
629
- }), l.push({
630
- id: `temp-assistant-${c}`,
631
- conversationId: T || "",
869
+ }), p.push({
870
+ id: `temp-assistant-${S}`,
871
+ conversationId: P || "",
632
872
  content: "",
633
873
  role: "assistant",
634
874
  status: "IN_PROGRESS",
635
875
  createdAt: /* @__PURE__ */ new Date()
636
- }), k();
876
+ }), N();
637
877
  try {
638
- const f = await h.sendMessage(i, {
639
- conversationId: T,
640
- files: t
878
+ const w = await E.sendMessage(c, {
879
+ conversationId: P,
880
+ files: n
641
881
  });
642
- f.conversationId && (T || (T = f.conversationId), ae?.setActiveThread(f.conversationId, f.createdAt));
643
- const w = l.find((A) => A.id === `temp-user-${c}`);
644
- if (w && (w.id = `user-${c}`, w.conversationId = f.conversationId), !l.some((A) => A.id === f.id)) {
645
- const A = l.findIndex((H) => H.id === `temp-assistant-${c}`);
646
- A >= 0 ? l[A] = f : l.push(f);
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);
647
887
  }
648
- l = l.filter((A) => !A.id.startsWith("temp-")), F = !1, k(), Z && xe();
649
- } catch (f) {
650
- J = f instanceof Error ? f.message : "Failed to send message", F = !1, l = l.filter((w) => !w.id.startsWith("temp-")), k();
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();
651
891
  }
652
892
  }
653
- async function xe() {
893
+ async function Ae() {
654
894
  try {
655
- const e = await h.getConversations();
656
- se.splice(0, se.length, ...e);
895
+ const e = await E.getConversations();
896
+ pe.splice(0, pe.length, ...e);
657
897
  } catch {
658
898
  }
659
- return se;
899
+ return pe;
660
900
  }
661
- async function pt(e) {
901
+ async function At(e) {
662
902
  try {
663
- const t = (await h.getConversation(e))?.messages ?? [];
664
- t.length > 0 && l.length === 0 && (l = t, k());
903
+ const n = (await E.getConversation(e))?.messages ?? [];
904
+ n.length > 0 && p.length === 0 && (p = n, N());
665
905
  } catch {
666
- l.length === 0 && (ae?.clear(), T = void 0);
906
+ p.length === 0 && (ce?.clear(), P = void 0);
667
907
  }
668
908
  }
669
- return k(), ue(), T ? pt(T) : Ie === "streaming" && ct(Ae), Z && xe(), {
670
- client: h,
671
- element: ie,
672
- sendMessage: he,
673
- ...j ? {
674
- open: ve,
675
- close: ye,
676
- toggle: ft
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
677
917
  } : {},
678
- session: ae,
679
- threads: se,
680
- refreshThreads: xe,
918
+ session: ce,
919
+ threads: pe,
920
+ refreshThreads: Ae,
681
921
  destroy() {
682
- M && clearInterval(M), h.off("message:start", Oe), h.off("message:chunk", Be), h.off("message:answer-complete", De), h.off("message:complete", Me), h.off("message:error", He), oe && h.off("form:submitted", Fe), Q && h.off("form:error", ze), Ue = !0, me.forEach((e) => e()), ie.remove(), _?.remove(), o.client || h.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();
683
923
  }
684
924
  };
685
- function be() {
686
- if (!U) return;
687
- const e = p === "left" ? "translateX(-100%)" : "translateX(100%)";
688
- U.style.transform = X ? "translateX(0)" : e, U.setAttribute("aria-hidden", X ? "false" : "true"), _ && (_.style.display = X ? "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");
933
+ }
934
+ function _e() {
935
+ te = !0, he(), fe(), j?.();
936
+ }
937
+ function Ie() {
938
+ te = !1, he(), Be?.();
939
+ }
940
+ function _t() {
941
+ te ? Ie() : _e();
942
+ }
943
+ function It() {
944
+ z ? _e() : be();
945
+ }
946
+ function $t() {
947
+ z ? Ie() : le();
948
+ }
949
+ function Lt() {
950
+ z ? _t() : K ? le() : be();
689
951
  }
690
- function ve() {
691
- X = !0, be(), ue();
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);
692
954
  }
693
- function ye() {
694
- X = !1, be();
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;
695
975
  }
696
- function ft() {
697
- X ? ye() : ve();
976
+ function xe() {
977
+ d.style.setProperty("--ago-vh", `${Je()}px`);
698
978
  }
699
- function ut() {
700
- const e = "http://www.w3.org/2000/svg", t = document.createElementNS(e, "svg");
701
- t.setAttribute("width", "26"), t.setAttribute("height", "26"), t.setAttribute("viewBox", "0 0 24 24"), t.setAttribute("fill", "none");
702
- const i = document.createElementNS(e, "path");
703
- 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"), t.appendChild(i), t;
979
+ function et() {
980
+ _.scrollTop = _.scrollHeight;
704
981
  }
705
- function gt() {
982
+ function Tt() {
706
983
  const e = x({
707
- display: "flex",
708
- gap: "4px",
709
- padding: "4px 0"
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
710
997
  });
711
- for (let t = 0; t < 3; t++) {
712
- const i = x({
713
- width: "6px",
714
- height: "6px",
715
- borderRadius: "50%",
716
- backgroundColor: "#b5bfc8",
717
- animation: "ago-pulse 1.2s ease-in-out infinite",
718
- animationDelay: `${t * 0.2}s`
719
- });
720
- e.appendChild(i);
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);
721
1039
  }
722
- return e;
1040
+ return e(), Promise.resolve();
723
1041
  }
724
- }
725
- function Tt(r) {
726
- let o = [];
727
- const a = document.createElement("form");
728
- E(a, {
729
- display: "flex",
730
- flexDirection: "column",
731
- gap: "8px",
732
- padding: "12px",
733
- borderTop: `1px solid ${O}`,
734
- backgroundColor: ee
735
- }), a.className = "ago-chat-input";
736
- const n = x({
737
- display: "flex",
738
- flexWrap: "wrap",
739
- gap: "6px"
740
- }), u = x({
741
- display: "flex",
742
- gap: "8px",
743
- alignItems: "flex-end"
744
- }), s = document.createElement("textarea");
745
- s.placeholder = r.placeholder, s.setAttribute("aria-label", r.placeholder), s.rows = 1, E(s, {
746
- flex: "1",
747
- resize: "none",
748
- boxSizing: "border-box",
749
- padding: "10px 12px",
750
- border: `1px solid ${O}`,
751
- borderRadius: "12px",
752
- fontSize: "16px",
753
- fontFamily: _e,
754
- lineHeight: "1.4",
755
- maxHeight: "110px",
756
- overflowY: "hidden"
757
- });
758
- const v = () => {
759
- s.style.height = "auto";
760
- const y = Math.min(s.scrollHeight + 2, 110);
761
- s.style.height = `${y}px`, s.style.overflowY = s.scrollHeight + 2 > 110 ? "auto" : "hidden";
762
- };
763
- s.addEventListener("input", () => {
764
- v(), B();
765
- });
766
- 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>', 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>', d = document.createElement("button");
767
- d.type = "submit", d.setAttribute("aria-label", "Send"), d.innerHTML = p, E(d, {
768
- flexShrink: "0",
769
- width: "40px",
770
- height: "40px",
771
- padding: "0",
772
- border: "none",
773
- borderRadius: "50%",
774
- backgroundColor: pe,
775
- color: ke,
776
- display: "flex",
777
- alignItems: "center",
778
- justifyContent: "center",
779
- cursor: "pointer"
780
- });
781
- let g = !1;
782
- const B = () => {
783
- const m = s.value.trim() !== "" || o.length > 0, y = g || !m;
784
- d.disabled = y, d.innerHTML = g ? b : p, d.style.opacity = y && !g ? "0.5" : "1", d.style.cursor = y ? "default" : "pointer";
785
- };
786
- let $ = null, L = null;
787
- r.allowFiles && ($ = document.createElement("input"), $.type = "file", $.multiple = !0, E($, { display: "none" }), L = document.createElement("button"), L.type = "button", L.setAttribute("aria-label", "Attach file"), L.textContent = "📎", E(L, {
788
- padding: "10px 12px",
789
- border: `1px solid ${O}`,
790
- borderRadius: "12px",
791
- backgroundColor: ee,
792
- cursor: "pointer",
793
- fontSize: "14px"
794
- }), L.addEventListener("click", () => $?.click()), $.addEventListener("change", () => {
795
- o = [...o, ...Array.from($?.files ?? [])], Y();
796
- }));
797
- function Y() {
798
- n.replaceChildren(), o.forEach((m, y) => {
799
- const P = x({
800
- display: "flex",
801
- alignItems: "center",
802
- gap: "4px",
803
- padding: "4px 8px",
804
- backgroundColor: "#f0f4ff",
805
- border: `1px solid ${O}`,
806
- borderRadius: "8px",
807
- fontSize: "12px"
808
- }), ne = document.createElement("span");
809
- ne.textContent = m.name;
810
- const D = document.createElement("button");
811
- D.type = "button", D.setAttribute("aria-label", `Remove ${m.name}`), D.textContent = "×", E(D, {
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",
812
1052
  border: "none",
813
- background: "transparent",
814
- cursor: "pointer",
815
- fontSize: "14px",
816
- lineHeight: "1"
817
- }), D.addEventListener("click", () => {
818
- o = o.filter((oe, Q) => Q !== y), Y();
819
- }), P.append(ne, D), n.appendChild(P);
820
- }), B();
821
- }
822
- const te = () => {
823
- const m = s.value, y = o;
824
- return s.value = "", v(), o = [], Y(), {
825
- content: m,
826
- files: y
827
- };
828
- }, Z = () => {
829
- const { content: m, files: y } = te();
830
- (m.trim() || y.length > 0) && r.onSend(m.trim(), y.length > 0 ? y : void 0);
831
- };
832
- return a.addEventListener("submit", (m) => {
833
- m.preventDefault(), Z();
834
- }), s.addEventListener("keydown", (m) => {
835
- m.key === "Enter" && !m.shiftKey && (m.preventDefault(), Z());
836
- }), L && u.appendChild(L), u.append(s, d), $ && a.appendChild($), a.append(n, u), B(), {
837
- inputRow: a,
838
- getValueAndClear: te,
839
- setDisabled: (m) => {
840
- s.disabled = m, g = m, B();
841
- },
842
- focus: () => s.focus()
843
- };
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
+ }
844
1092
  }
845
1093
  export {
846
- Mt as mountChatWidget,
847
- Re as renderMarkdown
1094
+ mn as mountChatWidget,
1095
+ Te as renderMarkdown
848
1096
  };