@useago/sdk 1.0.1 → 1.0.2

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,45 +1,45 @@
1
- import { t as Xe } from "./AgoClient-CZYNL25R.js";
2
- import { r as Ke, t as qe } from "./createFormCollector-Bk0DRhUf.js";
3
- import { t as Ve } from "./createConversationSession-Bmqj2rSS.js";
4
- var Qe = {
1
+ import { t as Xe, u as Ke } from "./AgoClient-bQozE6-A.js";
2
+ import { r as qe, t as Ve } from "./createFormCollector-D-TpSd9x.js";
3
+ import { t as Qe } from "./createConversationSession-BbK3ou1k.js";
4
+ var Ye = {
5
5
  "&": "&",
6
6
  "<": "&lt;",
7
7
  ">": "&gt;",
8
8
  '"': "&quot;",
9
9
  "'": "&#39;"
10
10
  };
11
- function F(o) {
12
- return o.replace(/[&<>"']/g, (n) => Qe[n]);
11
+ function U(o) {
12
+ return o.replace(/[&<>"']/g, (n) => Ye[n]);
13
13
  }
14
14
  function ke(o) {
15
15
  const n = o.trim();
16
16
  return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n) || !/^[a-z][a-z0-9+.-]*:/i.test(n) ? n : null;
17
17
  }
18
- var Le = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Q = "";
18
+ var Ne = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Q = "";
19
19
  function M(o) {
20
20
  const n = [], r = (u) => (n.push(u), `${Q}${n.length - 1}${Q}`);
21
21
  let t = o;
22
- return t = t.replace(/`([^`]+)`/g, (u, i) => r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Le}">${F(i)}</code>`)), t = t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (u, i, f) => {
22
+ return t = t.replace(/`([^`]+)`/g, (u, i) => r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Ne}">${U(i)}</code>`)), t = t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (u, i, f) => {
23
23
  const s = ke(f);
24
- return s ? r(`<img alt="${F(i)}" src="${F(s)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : u;
24
+ return s ? r(`<img alt="${U(i)}" src="${U(s)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : u;
25
25
  }), t = t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (u, i, f) => {
26
26
  const s = ke(f);
27
- return s ? r(`<a href="${F(s)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${M(i)}</a>`) : u;
28
- }), t = F(t), t = t.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>"), t = t.replace(new RegExp(`${Q}(\\d+)${Q}`, "g"), (u, i) => n[Number(i)]), t;
27
+ return s ? r(`<a href="${U(s)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${M(i)}</a>`) : u;
28
+ }), t = U(t), t = t.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>"), t = t.replace(new RegExp(`${Q}(\\d+)${Q}`, "g"), (u, i) => n[Number(i)]), t;
29
29
  }
30
30
  function R(o, n, r) {
31
31
  const t = document.createElement(o);
32
32
  return Object.assign(t.style, n), r !== void 0 && (t.innerHTML = r), t;
33
33
  }
34
- var Oe = /^ {0,3}([-*_])( *\1){2,} *$/, Te = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, De = /^ {0,3}(```+|~~~+)/, Z = /^ {0,3}>\s?/, P = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Ye = [
34
+ var Oe = /^ {0,3}([-*_])( *\1){2,} *$/, Te = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, De = /^ {0,3}(```+|~~~+)/, Z = /^ {0,3}>\s?/, P = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Ze = [
35
35
  "20px",
36
36
  "18px",
37
37
  "16px",
38
38
  "15px",
39
39
  "14px",
40
40
  "13px"
41
- ], ce = (o) => o.match(/^\s*/)?.[0].length ?? 0;
42
- function Ze(o) {
41
+ ], pe = (o) => o.match(/^\s*/)?.[0].length ?? 0;
42
+ function Je(o) {
43
43
  return o.trim() === "" || Oe.test(o) || Te.test(o) || De.test(o) || Z.test(o) || P.test(o);
44
44
  }
45
45
  function Me(o) {
@@ -52,18 +52,18 @@ function Me(o) {
52
52
  let i = 0;
53
53
  for (; i < o.length; ) {
54
54
  const f = o[i].match(P), s = [];
55
- for (i++; i < o.length && ce(o[i]) > r; )
55
+ for (i++; i < o.length && pe(o[i]) > r; )
56
56
  s.push(o[i]), i++;
57
57
  const p = R("li", {
58
58
  display: "list-item",
59
59
  margin: "2px 0",
60
60
  lineHeight: "1.6"
61
61
  }), c = f[3].match(/^\[([ xX])\]\s+(.*)$/);
62
- c ? (p.style.listStyleType = "none", p.style.marginLeft = "-20px", p.innerHTML = `<span style="margin-right:6px">${c[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${M(c[2])}`) : p.innerHTML = M(f[3]), s.filter((m) => P.test(m)).length > 0 && p.appendChild(Me(s.filter((m) => m.trim() !== ""))), u.appendChild(p);
62
+ c ? (p.style.listStyleType = "none", p.style.marginLeft = "-20px", p.innerHTML = `<span style="margin-right:6px">${c[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${M(c[2])}`) : p.innerHTML = M(f[3]), s.filter((h) => P.test(h)).length > 0 && p.appendChild(Me(s.filter((h) => h.trim() !== ""))), u.appendChild(p);
63
63
  }
64
64
  return u;
65
65
  }
66
- function Je(o) {
66
+ function et(o) {
67
67
  const n = (s) => s.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((p) => p.trim()), r = R("div", {
68
68
  overflowX: "auto",
69
69
  margin: "0 0 8px 0"
@@ -91,8 +91,8 @@ function Je(o) {
91
91
  }
92
92
  return t.appendChild(f), r.appendChild(t), r;
93
93
  }
94
- var et = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
95
- function Be(o) {
94
+ var tt = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
95
+ function fe(o) {
96
96
  const n = document.createDocumentFragment(), r = o.replace(/\r\n?/g, `
97
97
  `).split(`
98
98
  `);
@@ -105,9 +105,9 @@ function Be(o) {
105
105
  }
106
106
  const f = i.match(De);
107
107
  if (f) {
108
- const c = f[1][0], m = [];
108
+ const c = f[1][0], h = [];
109
109
  for (t++; t < r.length && !new RegExp(`^ {0,3}${c === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(r[t]); )
110
- m.push(r[t]), t++;
110
+ h.push(r[t]), t++;
111
111
  t++;
112
112
  const L = R("pre", { margin: "0 0 8px 0" });
113
113
  L.appendChild(R("code", {
@@ -117,9 +117,9 @@ function Be(o) {
117
117
  borderRadius: "6px",
118
118
  fontSize: "13px",
119
119
  overflowX: "auto",
120
- fontFamily: Le,
120
+ fontFamily: Ne,
121
121
  whiteSpace: "pre"
122
- }, F(m.join(`
122
+ }, U(h.join(`
123
123
  `)))), n.appendChild(L);
124
124
  continue;
125
125
  }
@@ -136,7 +136,7 @@ function Be(o) {
136
136
  const c = s[1].length;
137
137
  n.appendChild(R(`h${c}`, {
138
138
  margin: "16px 0 8px 0",
139
- fontSize: Ye[c - 1],
139
+ fontSize: Ze[c - 1],
140
140
  fontWeight: "600",
141
141
  lineHeight: "1.3"
142
142
  }, M(s[2]))), t++;
@@ -146,35 +146,35 @@ function Be(o) {
146
146
  const c = [];
147
147
  for (; t < r.length && Z.test(r[t]); )
148
148
  c.push(r[t].replace(Z, "")), t++;
149
- const m = R("blockquote", {
149
+ const h = R("blockquote", {
150
150
  borderLeft: "4px solid #dee3e8",
151
151
  paddingLeft: "12px",
152
152
  margin: "0 0 8px 0",
153
153
  fontStyle: "italic",
154
154
  color: "#6b6d6f"
155
155
  });
156
- m.appendChild(Be(c.join(`
157
- `))), n.appendChild(m);
156
+ h.appendChild(fe(c.join(`
157
+ `))), n.appendChild(h);
158
158
  continue;
159
159
  }
160
- if (i.includes("|") && et(r[t + 1])) {
160
+ if (i.includes("|") && tt(r[t + 1])) {
161
161
  const c = [i, r[t + 1]];
162
162
  for (t += 2; t < r.length && r[t].includes("|") && r[t].trim(); )
163
163
  c.push(r[t]), t++;
164
- n.appendChild(Je(c));
164
+ n.appendChild(et(c));
165
165
  continue;
166
166
  }
167
167
  if (P.test(i)) {
168
- const c = [], m = ce(i);
168
+ const c = [], h = pe(i);
169
169
  for (; t < r.length && r[t].trim() !== ""; )
170
- if (P.test(r[t]) || ce(r[t]) > m)
170
+ if (P.test(r[t]) || pe(r[t]) > h)
171
171
  c.push(r[t]), t++;
172
172
  else break;
173
173
  n.appendChild(Me(c));
174
174
  continue;
175
175
  }
176
176
  const p = [i];
177
- for (t++; t < r.length && !Ze(r[t]); )
177
+ for (t++; t < r.length && !Je(r[t]); )
178
178
  p.push(r[t]), t++;
179
179
  n.appendChild(R("p", {
180
180
  margin: "0 0 8px 0",
@@ -184,7 +184,7 @@ function Be(o) {
184
184
  const u = n.lastElementChild;
185
185
  return u && (u.style.marginBottom = "0"), n;
186
186
  }
187
- var pe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', $e = {
187
+ var ue = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', $e = {
188
188
  font: "--ago-font",
189
189
  radius: "--ago-radius",
190
190
  messageRadius: "--ago-message-radius",
@@ -198,8 +198,8 @@ var pe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "S
198
198
  mutedText: "--ago-muted-text-color",
199
199
  border: "--ago-border-color",
200
200
  accent: "--ago-accent-color"
201
- }, fe = "var(--ago-brand-color, #03182f)", ue = "var(--ago-brand-text-color, #fff)", tt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Ie = "var(--ago-header-text-color, #e8f0fe)", j = "var(--ago-panel-background, #fff)", nt = "var(--ago-messages-background, #fbfbfb)", Y = "var(--ago-text-color, #30373e)", ot = "var(--ago-muted-text-color, #6b6d6f)", $ = "var(--ago-border-color, #dee3e8)", de = "var(--ago-accent-color, #1b5fc4)", rt = "var(--ago-radius, 16px)", Ae = "var(--ago-message-radius, 16px)";
202
- function at(o, n) {
201
+ }, ge = "var(--ago-brand-color, #03182f)", he = "var(--ago-brand-text-color, #fff)", nt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Ie = "var(--ago-header-text-color, #e8f0fe)", j = "var(--ago-panel-background, #fff)", ot = "var(--ago-messages-background, #fbfbfb)", Y = "var(--ago-text-color, #30373e)", rt = "var(--ago-muted-text-color, #6b6d6f)", $ = "var(--ago-border-color, #dee3e8)", ce = "var(--ago-accent-color, #1b5fc4)", at = "var(--ago-radius, 16px)", Ae = "var(--ago-message-radius, 16px)";
202
+ function it(o, n) {
203
203
  if (n)
204
204
  for (const r of Object.keys($e)) {
205
205
  const t = n[r];
@@ -209,53 +209,53 @@ function at(o, n) {
209
209
  function y(o, n) {
210
210
  Object.assign(o.style, n);
211
211
  }
212
- function b(o = {}) {
212
+ function x(o = {}) {
213
213
  const n = document.createElement("div");
214
214
  return y(n, o), n;
215
215
  }
216
- var Ne = "ago-chat-widget-keyframes";
217
- function it() {
218
- if (typeof document > "u" || document.getElementById(Ne)) return;
216
+ var Le = "ago-chat-widget-keyframes";
217
+ function st() {
218
+ if (typeof document > "u" || document.getElementById(Le)) return;
219
219
  const o = document.createElement("style");
220
- o.id = Ne, o.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(o);
220
+ o.id = Le, o.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(o);
221
221
  }
222
- function st(o) {
222
+ function lt(o) {
223
223
  const n = typeof o == "string" ? document.querySelector(o) : o;
224
224
  if (!n) throw new Error(`mountChatWidget: target "${String(o)}" not found.`);
225
225
  return n;
226
226
  }
227
- function ft(o, n) {
228
- const { title: r = "Chat", welcomeMessage: t = "Hello! How can I help you today?", placeholder: u = "Type a message...", allowFiles: i = !1, height: f = 500, placement: s = "inline", width: p = 400, defaultOpen: c = !1, logoUrl: m, showAgentName: L = !1, theme: x, loadThreads: _ = !1, forms: X, onFollowUpClick: B, onMessageSent: O, onMessageReceived: ge } = n;
229
- if (!n.client && !n.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
230
- const h = n.client ?? new Xe(n.config), he = st(o), z = s === "left" || s === "right", ze = z && (n.launcher ?? !0);
227
+ function ut(o, n) {
228
+ const { title: r = "Chat", welcomeMessage: t = "Hello! How can I help you today?", placeholder: u = "Type a message...", allowFiles: i = !1, height: f = 500, placement: s = "inline", width: p = 400, defaultOpen: c = !1, logoUrl: h, showAgentName: L = !1, theme: m, loadThreads: _ = !1, forms: X, onFollowUpClick: B, onMessageSent: N, onMessageReceived: me } = n;
229
+ if (!n.client && !n.config?.baseUrl) throw new Ke("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
230
+ const g = n.client ?? new Xe(n.config), xe = lt(o), z = s === "left" || s === "right", Be = z && (n.launcher ?? !0);
231
231
  let H = z ? c : !0;
232
- const J = n.persistConversation, K = J ? Ve(J === !0 ? {} : J) : void 0;
233
- let k = n.conversationId ?? K?.getLastActiveThread() ?? void 0, d = [], A = !1, W = null;
234
- const q = [], U = b({
232
+ const J = n.persistConversation, K = J ? Qe(J === !0 ? {} : J) : void 0;
233
+ let k = n.conversationId ?? K?.getLastActiveThread() ?? void 0, d = [], O = !1, W = null;
234
+ const q = [], F = x({
235
235
  display: "flex",
236
236
  flexDirection: "column",
237
237
  height: z ? "100%" : typeof f == "number" ? `${f}px` : f,
238
238
  border: `1px solid ${$}`,
239
- borderRadius: rt,
239
+ borderRadius: at,
240
240
  overflow: "hidden",
241
241
  backgroundColor: j,
242
- fontFamily: pe,
242
+ fontFamily: ue,
243
243
  textAlign: "left",
244
244
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
245
245
  });
246
- U.className = "ago-chat-widget", at(U, x);
247
- const G = b({
246
+ F.className = "ago-chat-widget", it(F, m);
247
+ const G = x({
248
248
  padding: "14px 16px",
249
249
  borderBottom: `1px solid ${$}`,
250
- backgroundColor: tt,
250
+ backgroundColor: nt,
251
251
  color: Ie,
252
252
  display: "flex",
253
253
  alignItems: "center",
254
254
  gap: "10px"
255
255
  });
256
- if (G.className = "ago-chat-widget__header", m) {
256
+ if (G.className = "ago-chat-widget__header", h) {
257
257
  const e = document.createElement("img");
258
- e.src = m, e.alt = "Logo", y(e, {
258
+ e.src = h, e.alt = "Logo", y(e, {
259
259
  height: "24px",
260
260
  width: "auto"
261
261
  }), G.appendChild(e);
@@ -276,94 +276,94 @@ function ft(o, n) {
276
276
  lineHeight: "1",
277
277
  cursor: "pointer",
278
278
  padding: "0 2px"
279
- }), e.addEventListener("click", () => se()), G.appendChild(e);
279
+ }), e.addEventListener("click", () => le()), G.appendChild(e);
280
280
  }
281
- const N = b({
281
+ const A = x({
282
282
  flex: "1",
283
283
  overflow: "auto",
284
284
  padding: "16px",
285
- backgroundColor: nt
285
+ backgroundColor: ot
286
286
  });
287
- N.className = "ago-chat-widget__messages";
288
- const { inputRow: He, setDisabled: Ue, focus: me } = lt({
287
+ A.className = "ago-chat-widget__messages";
288
+ const { inputRow: ze, setDisabled: He, focus: te } = dt({
289
289
  placeholder: u,
290
290
  allowFiles: i,
291
291
  onSend: (e, a) => {
292
- oe(e, a);
292
+ re(e, a);
293
293
  }
294
294
  });
295
- it(), U.append(G, N, He);
296
- let V = U, T, E;
297
- const te = s === "left" ? "left" : "right";
298
- if (z && (T = b({
295
+ st(), F.append(G, A, ze);
296
+ let V = F, T, E;
297
+ const ne = s === "left" ? "left" : "right";
298
+ if (z && (T = x({
299
299
  position: "fixed",
300
300
  top: "0",
301
301
  bottom: "0",
302
- [te]: "0",
302
+ [ne]: "0",
303
303
  width: typeof p == "number" ? `${p}px` : p,
304
304
  maxWidth: "100vw",
305
305
  display: "flex",
306
306
  zIndex: "2147483000",
307
307
  transition: "transform 0.3s ease",
308
308
  boxShadow: "rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"
309
- }), T.className = "ago-chat-widget-panel", y(U, {
309
+ }), T.className = "ago-chat-widget-panel", y(F, {
310
310
  height: "100%",
311
311
  width: "100%",
312
312
  borderRadius: "0",
313
313
  border: "none",
314
314
  boxShadow: "none",
315
- [te === "left" ? "borderRight" : "borderLeft"]: `1px solid ${$}`
316
- }), T.appendChild(U), V = T), ze) {
315
+ [ne === "left" ? "borderRight" : "borderLeft"]: `1px solid ${$}`
316
+ }), T.appendChild(F), V = T), Be) {
317
317
  if (E = document.createElement("button"), E.type = "button", E.className = "ago-chat-widget-launcher", E.setAttribute("aria-label", `Open ${r}`), y(E, {
318
318
  position: "fixed",
319
319
  bottom: "20px",
320
- [te]: "20px",
320
+ [ne]: "20px",
321
321
  width: "56px",
322
322
  height: "56px",
323
323
  borderRadius: "50%",
324
324
  border: "none",
325
- backgroundColor: fe,
326
- color: ue,
325
+ backgroundColor: ge,
326
+ color: he,
327
327
  cursor: "pointer",
328
328
  display: "flex",
329
329
  alignItems: "center",
330
330
  justifyContent: "center",
331
331
  zIndex: "2147483000",
332
332
  boxShadow: "rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",
333
- fontFamily: pe
334
- }), m) {
333
+ fontFamily: ue
334
+ }), h) {
335
335
  const e = document.createElement("img");
336
- e.src = m, e.alt = "", y(e, {
336
+ e.src = h, e.alt = "", y(e, {
337
337
  width: "26px",
338
338
  height: "26px",
339
339
  objectFit: "contain"
340
340
  }), E.appendChild(e);
341
- } else E.appendChild(je());
342
- E.addEventListener("click", () => ie());
341
+ } else E.appendChild(Ge());
342
+ E.addEventListener("click", () => se());
343
343
  }
344
- he.appendChild(V), E && he.appendChild(E), ae();
345
- const xe = B !== !1, be = B === !1 ? void 0 : B ?? ((e) => {
346
- oe(e);
344
+ xe.appendChild(V), E && xe.appendChild(E), ie();
345
+ const be = B !== !1, Ce = B === !1 ? void 0 : B ?? ((e) => {
346
+ re(e);
347
347
  });
348
348
  function Fe(e, a) {
349
- const l = e.role === "user", S = b({
349
+ const l = e.role === "user", S = x({
350
350
  display: "flex",
351
351
  flexDirection: "column",
352
352
  alignItems: l ? "flex-end" : "flex-start",
353
353
  marginBottom: "16px"
354
354
  });
355
355
  if (S.className = `ago-message ago-message--${e.role}`, !l && L && e.agent) {
356
- const g = b({
356
+ const b = x({
357
357
  fontSize: "13px",
358
358
  fontWeight: "500",
359
359
  color: Y,
360
360
  marginBottom: "6px",
361
361
  padding: "0 4px"
362
362
  });
363
- g.className = "ago-message__agent", g.textContent = e.agent.displayName || e.agent.name, S.appendChild(g);
363
+ b.className = "ago-message__agent", b.textContent = e.agent.displayName || e.agent.name, S.appendChild(b);
364
364
  }
365
365
  if (!l && e.sources && e.sources.length > 0) {
366
- const g = b({
366
+ const b = x({
367
367
  display: "grid",
368
368
  gridTemplateColumns: "1fr 1fr",
369
369
  gap: "6px",
@@ -371,7 +371,7 @@ function ft(o, n) {
371
371
  width: "100%",
372
372
  maxWidth: "85%"
373
373
  });
374
- g.className = "ago-message__sources", e.sources.forEach((C, v) => {
374
+ b.className = "ago-message__sources", e.sources.forEach((C, w) => {
375
375
  const D = C.url ? document.createElement("a") : document.createElement("div");
376
376
  C.url && D instanceof HTMLAnchorElement && (D.href = C.url, D.target = "_blank", D.rel = "noopener noreferrer"), y(D, {
377
377
  display: "flex",
@@ -386,13 +386,13 @@ function ft(o, n) {
386
386
  fontSize: "12px",
387
387
  overflow: "hidden"
388
388
  });
389
- const _e = b({
389
+ const _e = x({
390
390
  flexShrink: "0",
391
391
  width: "18px",
392
392
  height: "18px",
393
393
  borderRadius: "3px",
394
- border: `1px solid ${de}`,
395
- color: de,
394
+ border: `1px solid ${ce}`,
395
+ color: ce,
396
396
  fontSize: "11px",
397
397
  fontWeight: "500",
398
398
  display: "flex",
@@ -400,76 +400,69 @@ function ft(o, n) {
400
400
  justifyContent: "center",
401
401
  backgroundColor: "#f0f4ff"
402
402
  });
403
- _e.textContent = String(v + 1);
404
- const le = b({
403
+ _e.textContent = String(w + 1);
404
+ const de = x({
405
405
  overflow: "hidden",
406
406
  textOverflow: "ellipsis",
407
407
  whiteSpace: "nowrap"
408
408
  });
409
- le.textContent = C.title, le.title = C.title, D.append(_e, le), g.appendChild(D);
410
- }), S.appendChild(g);
409
+ de.textContent = C.title, de.title = C.title, D.append(_e, de), b.appendChild(D);
410
+ }), S.appendChild(b);
411
411
  }
412
- const w = b({
412
+ const v = x({
413
413
  maxWidth: l ? "75%" : "100%",
414
414
  padding: l ? "10px 14px" : "2px 8px",
415
415
  borderRadius: l ? Ae : "0",
416
- backgroundColor: l ? fe : "transparent",
417
- color: l ? ue : Y,
416
+ backgroundColor: l ? ge : "transparent",
417
+ color: l ? he : Y,
418
418
  wordBreak: "break-word",
419
419
  fontSize: "14px",
420
420
  lineHeight: "1.6"
421
421
  });
422
- if (w.className = "ago-message__content", e.content ? w.appendChild(Be(e.content)) : e.status === "IN_PROGRESS" && w.appendChild(Re()), S.appendChild(w), a && A && e.role === "assistant" && e.status === "DONE" && !(e.followUpReplies && e.followUpReplies.length > 0)) {
423
- const g = b({
424
- marginTop: "10px",
425
- paddingLeft: "8px"
426
- });
427
- g.className = "ago-message__followups-loading", g.appendChild(Re()), S.appendChild(g);
428
- }
429
- if (a && e.followUpReplies && e.followUpReplies.length > 0) {
430
- const g = b({
422
+ if (v.className = "ago-message__content", e.content ? v.appendChild(fe(e.content)) : e.status === "IN_PROGRESS" && v.appendChild(je()), S.appendChild(v), a && e.followUpReplies && e.followUpReplies.length > 0) {
423
+ const b = x({
431
424
  display: "flex",
432
425
  flexWrap: "wrap",
433
426
  gap: "8px",
434
427
  marginTop: "10px"
435
428
  });
436
- g.className = "ago-message__followups";
429
+ b.className = "ago-message__followups";
437
430
  for (const C of e.followUpReplies) {
438
- const v = document.createElement("button");
439
- v.type = "button", v.className = "ago-message__followup-btn", v.textContent = C, v.disabled = !xe, y(v, {
431
+ const w = document.createElement("button");
432
+ w.type = "button", w.className = "ago-message__followup-btn", w.textContent = C, w.disabled = !be, y(w, {
440
433
  padding: "6px 14px",
441
- fontSize: "13px",
434
+ fontSize: "14px",
442
435
  borderRadius: Ae,
443
436
  border: `1px solid ${$}`,
444
437
  backgroundColor: j,
445
438
  color: Y,
446
- cursor: xe ? "pointer" : "default",
439
+ cursor: be ? "pointer" : "default",
447
440
  transition: "border-color 0.15s"
448
- }), be && v.addEventListener("click", () => be(C)), v.addEventListener("mouseenter", () => {
449
- v.style.borderColor = de;
450
- }), v.addEventListener("mouseleave", () => {
451
- v.style.borderColor = $;
452
- }), g.appendChild(v);
441
+ }), Ce && w.addEventListener("click", () => Ce(C)), w.addEventListener("mouseenter", () => {
442
+ w.style.borderColor = ce;
443
+ }), w.addEventListener("mouseleave", () => {
444
+ w.style.borderColor = $;
445
+ }), b.appendChild(w);
453
446
  }
454
- S.appendChild(g);
447
+ S.appendChild(b);
455
448
  }
456
449
  return S;
457
450
  }
458
451
  function I() {
459
- if (N.replaceChildren(), d.length === 0) {
460
- const a = b({
452
+ if (A.replaceChildren(), d.length === 0) {
453
+ const a = x({
461
454
  textAlign: "center",
462
- color: ot,
455
+ color: rt,
463
456
  padding: "24px 16px",
464
457
  fontSize: "14px",
465
458
  lineHeight: "1.5"
466
459
  });
467
- a.textContent = t, N.appendChild(a);
460
+ a.appendChild(fe(t)), A.appendChild(a);
468
461
  } else d.forEach((a, l) => {
469
- N.appendChild(Fe(a, l === d.length - 1));
462
+ A.appendChild(Fe(a, l === d.length - 1));
470
463
  });
471
464
  if (W) {
472
- const a = b({
465
+ const a = x({
473
466
  padding: "10px 14px",
474
467
  backgroundColor: "#fef2f2",
475
468
  color: "#dc2626",
@@ -478,46 +471,46 @@ function ft(o, n) {
478
471
  fontSize: "13px",
479
472
  border: "1px solid #fecaca"
480
473
  });
481
- a.textContent = W, N.appendChild(a);
474
+ a.textContent = W, A.appendChild(a);
482
475
  }
483
- N.scrollTop = N.scrollHeight;
476
+ A.scrollTop = A.scrollHeight;
484
477
  const e = d[d.length - 1];
485
- Ue(A && e?.role === "assistant" && e.status === "IN_PROGRESS");
478
+ He(O && e?.role === "assistant" && e.status === "IN_PROGRESS");
486
479
  }
487
- function Pe() {
480
+ function Ue() {
488
481
  for (let e = d.length - 1; e >= 0; e--) {
489
482
  const a = d[e];
490
483
  if (a.role === "assistant" && a.status === "IN_PROGRESS") return a;
491
484
  }
492
485
  }
493
- const Ce = (e) => {
486
+ const ve = (e) => {
494
487
  k || (k = e.conversationId);
495
488
  }, we = (e) => {
496
- const a = Pe();
489
+ const a = Ue();
497
490
  a && (a.content += e.content, I());
498
- }, ve = (e) => {
499
- const a = d.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
500
- a >= 0 ? d[a] = e : d.push(e), I();
501
491
  }, ye = (e) => {
502
492
  const a = d.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
503
- a >= 0 ? d[a] = e : d.push(e), A = !1, I(), e.status === "DONE" && ge?.({
493
+ a >= 0 ? d[a] = e : d.push(e), I(), te();
494
+ }, Ee = (e) => {
495
+ const a = d.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
496
+ a >= 0 ? d[a] = e : d.push(e), O = !1, I(), e.status === "DONE" && me?.({
504
497
  id: e.id,
505
498
  content: e.content
506
499
  });
507
- }, Ee = (e) => {
508
- W = e.error, A = !1, d = d.filter((a) => !a.id.startsWith("temp-")), I();
500
+ }, Se = (e) => {
501
+ W = e.error, O = !1, d = d.filter((a) => !a.id.startsWith("temp-")), I();
509
502
  };
510
- h.on("message:start", Ce), h.on("message:chunk", we), h.on("message:answer-complete", ve), h.on("message:complete", ye), h.on("message:error", Ee);
511
- const ne = [];
512
- let Se = !1;
513
- for (const e of X ?? []) e.schema != null ? ne.push(qe(e).install(h)) : Ke(h, e).then((a) => {
514
- Se || ne.push(a.install(h));
503
+ g.on("message:start", ve), g.on("message:chunk", we), g.on("message:answer-complete", ye), g.on("message:complete", Ee), g.on("message:error", Se);
504
+ const oe = [];
505
+ let Re = !1;
506
+ for (const e of X ?? []) e.schema != null ? oe.push(Ve(e).install(g)) : qe(g, e).then((a) => {
507
+ Re || oe.push(a.install(g));
515
508
  }).catch(() => {
516
509
  });
517
- async function oe(e, a) {
510
+ async function re(e, a) {
518
511
  const l = e.trim();
519
- if (!l && !a?.length || A) return;
520
- O?.(l), A = !0, W = null;
512
+ if (!l && !a?.length || O) return;
513
+ N?.(l), O = !0, W = null;
521
514
  const S = Date.now();
522
515
  d.push({
523
516
  id: `temp-user-${S}`,
@@ -535,81 +528,81 @@ function ft(o, n) {
535
528
  createdAt: /* @__PURE__ */ new Date()
536
529
  }), I();
537
530
  try {
538
- const w = await h.sendMessage(l, {
531
+ const v = await g.sendMessage(l, {
539
532
  conversationId: k,
540
533
  files: a
541
534
  });
542
- w.conversationId && (k || (k = w.conversationId), K?.setActiveThread(w.conversationId, w.createdAt));
543
- const g = d.find((C) => C.id === `temp-user-${S}`);
544
- if (g && (g.id = `user-${S}`, g.conversationId = w.conversationId), !d.some((C) => C.id === w.id)) {
545
- const C = d.findIndex((v) => v.id === `temp-assistant-${S}`);
546
- C >= 0 ? d[C] = w : d.push(w);
535
+ v.conversationId && (k || (k = v.conversationId), K?.setActiveThread(v.conversationId, v.createdAt));
536
+ const b = d.find((C) => C.id === `temp-user-${S}`);
537
+ if (b && (b.id = `user-${S}`, b.conversationId = v.conversationId), !d.some((C) => C.id === v.id)) {
538
+ const C = d.findIndex((w) => w.id === `temp-assistant-${S}`);
539
+ C >= 0 ? d[C] = v : d.push(v);
547
540
  }
548
- d = d.filter((C) => !C.id.startsWith("temp-")), A = !1, I(), _ && re();
549
- } catch (w) {
550
- W = w instanceof Error ? w.message : "Failed to send message", A = !1, d = d.filter((g) => !g.id.startsWith("temp-")), I();
541
+ d = d.filter((C) => !C.id.startsWith("temp-")), O = !1, I(), _ && ae();
542
+ } catch (v) {
543
+ W = v instanceof Error ? v.message : "Failed to send message", O = !1, d = d.filter((b) => !b.id.startsWith("temp-")), I();
551
544
  }
552
545
  }
553
- async function re() {
546
+ async function ae() {
554
547
  try {
555
- const e = await h.getConversations();
548
+ const e = await g.getConversations();
556
549
  q.splice(0, q.length, ...e);
557
550
  } catch {
558
551
  }
559
552
  return q;
560
553
  }
561
- async function We(e) {
554
+ async function Pe(e) {
562
555
  try {
563
- const a = (await h.getConversation(e))?.messages ?? [];
556
+ const a = (await g.getConversation(e))?.messages ?? [];
564
557
  a.length > 0 && d.length === 0 && (d = a, I());
565
558
  } catch {
566
559
  d.length === 0 && (K?.clear(), k = void 0);
567
560
  }
568
561
  }
569
- return I(), me(), k && We(k), _ && re(), {
570
- client: h,
562
+ return I(), te(), k && Pe(k), _ && ae(), {
563
+ client: g,
571
564
  element: V,
572
- sendMessage: oe,
565
+ sendMessage: re,
573
566
  ...z ? {
574
- open: ie,
575
- close: se,
576
- toggle: Ge
567
+ open: se,
568
+ close: le,
569
+ toggle: We
577
570
  } : {},
578
571
  session: K,
579
572
  threads: q,
580
- refreshThreads: re,
573
+ refreshThreads: ae,
581
574
  destroy() {
582
- h.off("message:start", Ce), h.off("message:chunk", we), h.off("message:answer-complete", ve), h.off("message:complete", ye), h.off("message:error", Ee), Se = !0, ne.forEach((e) => e()), V.remove(), E?.remove(), n.client || h.destroy();
575
+ g.off("message:start", ve), g.off("message:chunk", we), g.off("message:answer-complete", ye), g.off("message:complete", Ee), g.off("message:error", Se), Re = !0, oe.forEach((e) => e()), V.remove(), E?.remove(), n.client || g.destroy();
583
576
  }
584
577
  };
585
- function ae() {
578
+ function ie() {
586
579
  if (!T) return;
587
580
  const e = s === "left" ? "translateX(-100%)" : "translateX(100%)";
588
581
  T.style.transform = H ? "translateX(0)" : e, T.setAttribute("aria-hidden", H ? "false" : "true"), E && (E.style.display = H ? "none" : "flex");
589
582
  }
590
- function ie() {
591
- H = !0, ae(), me();
592
- }
593
583
  function se() {
594
- H = !1, ae();
584
+ H = !0, ie(), te();
595
585
  }
596
- function Ge() {
597
- H ? se() : ie();
586
+ function le() {
587
+ H = !1, ie();
598
588
  }
599
- function je() {
589
+ function We() {
590
+ H ? le() : se();
591
+ }
592
+ function Ge() {
600
593
  const e = "http://www.w3.org/2000/svg", a = document.createElementNS(e, "svg");
601
594
  a.setAttribute("width", "26"), a.setAttribute("height", "26"), a.setAttribute("viewBox", "0 0 24 24"), a.setAttribute("fill", "none");
602
595
  const l = document.createElementNS(e, "path");
603
596
  return l.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"), l.setAttribute("stroke", "currentColor"), l.setAttribute("stroke-width", "2"), l.setAttribute("stroke-linecap", "round"), l.setAttribute("stroke-linejoin", "round"), a.appendChild(l), a;
604
597
  }
605
- function Re() {
606
- const e = b({
598
+ function je() {
599
+ const e = x({
607
600
  display: "flex",
608
601
  gap: "4px",
609
602
  padding: "4px 0"
610
603
  });
611
604
  for (let a = 0; a < 3; a++) {
612
- const l = b({
605
+ const l = x({
613
606
  width: "6px",
614
607
  height: "6px",
615
608
  borderRadius: "50%",
@@ -622,7 +615,7 @@ function ft(o, n) {
622
615
  return e;
623
616
  }
624
617
  }
625
- function lt(o) {
618
+ function dt(o) {
626
619
  let n = [];
627
620
  const r = document.createElement("form");
628
621
  y(r, {
@@ -633,11 +626,11 @@ function lt(o) {
633
626
  borderTop: `1px solid ${$}`,
634
627
  backgroundColor: j
635
628
  }), r.className = "ago-chat-input";
636
- const t = b({
629
+ const t = x({
637
630
  display: "flex",
638
631
  flexWrap: "wrap",
639
632
  gap: "6px"
640
- }), u = b({
633
+ }), u = x({
641
634
  display: "flex",
642
635
  gap: "8px",
643
636
  alignItems: "flex-end"
@@ -649,7 +642,7 @@ function lt(o) {
649
642
  border: `1px solid ${$}`,
650
643
  borderRadius: "12px",
651
644
  fontSize: "14px",
652
- fontFamily: pe,
645
+ fontFamily: ue,
653
646
  lineHeight: "1.4",
654
647
  maxHeight: "120px",
655
648
  outline: "none"
@@ -659,8 +652,8 @@ function lt(o) {
659
652
  padding: "10px 16px",
660
653
  border: "none",
661
654
  borderRadius: "12px",
662
- backgroundColor: fe,
663
- color: ue,
655
+ backgroundColor: ge,
656
+ color: he,
664
657
  fontSize: "14px",
665
658
  fontWeight: "500",
666
659
  cursor: "pointer"
@@ -677,8 +670,8 @@ function lt(o) {
677
670
  n = [...n, ...Array.from(s?.files ?? [])], c();
678
671
  }));
679
672
  function c() {
680
- t.replaceChildren(), n.forEach((x, _) => {
681
- const X = b({
673
+ t.replaceChildren(), n.forEach((m, _) => {
674
+ const X = x({
682
675
  display: "flex",
683
676
  alignItems: "center",
684
677
  gap: "4px",
@@ -688,43 +681,43 @@ function lt(o) {
688
681
  borderRadius: "8px",
689
682
  fontSize: "12px"
690
683
  }), B = document.createElement("span");
691
- B.textContent = x.name;
692
- const O = document.createElement("button");
693
- O.type = "button", O.textContent = "×", y(O, {
684
+ B.textContent = m.name;
685
+ const N = document.createElement("button");
686
+ N.type = "button", N.textContent = "×", y(N, {
694
687
  border: "none",
695
688
  background: "transparent",
696
689
  cursor: "pointer",
697
690
  fontSize: "14px",
698
691
  lineHeight: "1"
699
- }), O.addEventListener("click", () => {
700
- n = n.filter((ge, h) => h !== _), c();
701
- }), X.append(B, O), t.appendChild(X);
692
+ }), N.addEventListener("click", () => {
693
+ n = n.filter((me, g) => g !== _), c();
694
+ }), X.append(B, N), t.appendChild(X);
702
695
  });
703
696
  }
704
- const m = () => {
705
- const x = i.value, _ = n;
697
+ const h = () => {
698
+ const m = i.value, _ = n;
706
699
  return i.value = "", n = [], c(), {
707
- content: x,
700
+ content: m,
708
701
  files: _
709
702
  };
710
703
  }, L = () => {
711
- const { content: x, files: _ } = m();
712
- (x.trim() || _.length > 0) && o.onSend(x.trim(), _.length > 0 ? _ : void 0);
704
+ const { content: m, files: _ } = h();
705
+ (m.trim() || _.length > 0) && o.onSend(m.trim(), _.length > 0 ? _ : void 0);
713
706
  };
714
- return r.addEventListener("submit", (x) => {
715
- x.preventDefault(), L();
716
- }), i.addEventListener("keydown", (x) => {
717
- x.key === "Enter" && !x.shiftKey && (x.preventDefault(), L());
707
+ return r.addEventListener("submit", (m) => {
708
+ m.preventDefault(), L();
709
+ }), i.addEventListener("keydown", (m) => {
710
+ m.key === "Enter" && !m.shiftKey && (m.preventDefault(), L());
718
711
  }), p && u.appendChild(p), u.append(i, f), s && r.appendChild(s), r.append(t, u), {
719
712
  inputRow: r,
720
- getValueAndClear: m,
721
- setDisabled: (x) => {
722
- i.disabled = x, f.disabled = x, f.style.opacity = x ? "0.6" : "1", f.style.cursor = x ? "not-allowed" : "pointer";
713
+ getValueAndClear: h,
714
+ setDisabled: (m) => {
715
+ i.disabled = m, f.disabled = m, f.style.opacity = m ? "0.6" : "1", f.style.cursor = m ? "not-allowed" : "pointer";
723
716
  },
724
717
  focus: () => i.focus()
725
718
  };
726
719
  }
727
720
  export {
728
- ft as mountChatWidget,
729
- Be as renderMarkdown
721
+ ut as mountChatWidget,
722
+ fe as renderMarkdown
730
723
  };