@useago/sdk 1.2.0 → 1.3.0

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