@useago/sdk 0.4.6 → 0.4.7

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,49 +1,49 @@
1
- import { t as ke } from "./AgoClient-rvTz2thR.js";
2
- import { t as $e } from "./createFormCollector-DON4vdJV.js";
3
- import { t as Ie } from "./createConversationSession-D-eq8VIo.js";
4
- var Te = {
1
+ import { t as Ie } from "./AgoClient-BrYhSO5M.js";
2
+ import { t as Te } from "./createFormCollector-CPS2phYq.js";
3
+ import { t as Ne } from "./createConversationSession-Dmqd80DX.js";
4
+ var Oe = {
5
5
  "&": "&",
6
6
  "<": "&lt;",
7
7
  ">": "&gt;",
8
8
  '"': "&quot;",
9
9
  "'": "&#39;"
10
10
  };
11
- function M(o) {
12
- return o.replace(/[&<>"']/g, (n) => Te[n]);
11
+ function H(o) {
12
+ return o.replace(/[&<>"']/g, (n) => Oe[n]);
13
13
  }
14
- function se(o) {
14
+ function de(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 ce = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', G = "";
19
- function N(o) {
20
- const n = [], r = (g) => (n.push(g), `${G}${n.length - 1}${G}`);
18
+ var ge = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', j = "";
19
+ function L(o) {
20
+ const n = [], r = (g) => (n.push(g), `${j}${n.length - 1}${j}`);
21
21
  let e = o;
22
- return e = e.replace(/`([^`]+)`/g, (g, a) => r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ce}">${M(a)}</code>`)), e = e.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (g, a, d) => {
23
- const s = se(d);
24
- return s ? r(`<img alt="${M(a)}" src="${M(s)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : g;
25
- }), e = e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (g, a, d) => {
26
- const s = se(d);
27
- return s ? r(`<a href="${M(s)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${N(a)}</a>`) : g;
28
- }), e = M(e), e = e.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>"), e = e.replace(new RegExp(`${G}(\\d+)${G}`, "g"), (g, a) => n[Number(a)]), e;
22
+ return e = e.replace(/`([^`]+)`/g, (g, a) => r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ge}">${H(a)}</code>`)), e = e.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (g, a, p) => {
23
+ const i = de(p);
24
+ return i ? r(`<img alt="${H(a)}" src="${H(i)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : g;
25
+ }), e = e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (g, a, p) => {
26
+ const i = de(p);
27
+ return i ? r(`<a href="${H(i)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${L(a)}</a>`) : g;
28
+ }), e = H(e), e = e.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>"), e = e.replace(new RegExp(`${j}(\\d+)${j}`, "g"), (g, a) => n[Number(a)]), e;
29
29
  }
30
- function y(o, n, r) {
30
+ function w(o, n, r) {
31
31
  const e = document.createElement(o);
32
32
  return Object.assign(e.style, n), r !== void 0 && (e.innerHTML = r), e;
33
33
  }
34
- var pe = /^ {0,3}([-*_])( *\1){2,} *$/, fe = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, ge = /^ {0,3}(```+|~~~+)/, X = /^ {0,3}>\s?/, H = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Le = [
34
+ var ue = /^ {0,3}([-*_])( *\1){2,} *$/, me = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, he = /^ {0,3}(```+|~~~+)/, K = /^ {0,3}>\s?/, B = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, Ae = [
35
35
  "20px",
36
36
  "18px",
37
37
  "16px",
38
38
  "15px",
39
39
  "14px",
40
40
  "13px"
41
- ], Z = (o) => o.match(/^\s*/)?.[0].length ?? 0;
42
- function Ae(o) {
43
- return o.trim() === "" || pe.test(o) || fe.test(o) || ge.test(o) || X.test(o) || H.test(o);
41
+ ], J = (o) => o.match(/^\s*/)?.[0].length ?? 0;
42
+ function Le(o) {
43
+ return o.trim() === "" || ue.test(o) || me.test(o) || he.test(o) || K.test(o) || B.test(o);
44
44
  }
45
- function ue(o) {
46
- const n = o[0].match(H), r = n[1].length, e = /\d/.test(n[2]), g = y(e ? "ol" : "ul", {
45
+ function xe(o) {
46
+ const n = o[0].match(B), r = n[1].length, e = /\d/.test(n[2]), g = w(e ? "ol" : "ul", {
47
47
  margin: "0 0 8px 0",
48
48
  paddingLeft: "20px",
49
49
  listStyleType: e ? "decimal" : "disc",
@@ -51,48 +51,48 @@ function ue(o) {
51
51
  });
52
52
  let a = 0;
53
53
  for (; a < o.length; ) {
54
- const d = o[a].match(H), s = [];
55
- for (a++; a < o.length && Z(o[a]) > r; )
56
- s.push(o[a]), a++;
57
- const c = y("li", {
54
+ const p = o[a].match(B), i = [];
55
+ for (a++; a < o.length && J(o[a]) > r; )
56
+ i.push(o[a]), a++;
57
+ const f = w("li", {
58
58
  display: "list-item",
59
59
  margin: "2px 0",
60
60
  lineHeight: "1.6"
61
- }), l = d[3].match(/^\[([ xX])\]\s+(.*)$/);
62
- l ? (c.style.listStyleType = "none", c.style.marginLeft = "-20px", c.innerHTML = `<span style="margin-right:6px">${l[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${N(l[2])}`) : c.innerHTML = N(d[3]), s.filter((h) => H.test(h)).length > 0 && c.appendChild(ue(s.filter((h) => h.trim() !== ""))), g.appendChild(c);
61
+ }), d = p[3].match(/^\[([ xX])\]\s+(.*)$/);
62
+ d ? (f.style.listStyleType = "none", f.style.marginLeft = "-20px", f.innerHTML = `<span style="margin-right:6px">${d[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${L(d[2])}`) : f.innerHTML = L(p[3]), i.filter((b) => B.test(b)).length > 0 && f.appendChild(xe(i.filter((b) => b.trim() !== ""))), g.appendChild(f);
63
63
  }
64
64
  return g;
65
65
  }
66
- function Ne(o) {
67
- const n = (s) => s.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((c) => c.trim()), r = y("div", {
66
+ function De(o) {
67
+ const n = (i) => i.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((f) => f.trim()), r = w("div", {
68
68
  overflowX: "auto",
69
69
  margin: "0 0 8px 0"
70
- }), e = y("table", {
70
+ }), e = w("table", {
71
71
  borderCollapse: "collapse",
72
72
  width: "100%",
73
73
  fontSize: "13px"
74
74
  }), g = document.createElement("thead"), a = document.createElement("tr");
75
- for (const s of n(o[0])) a.appendChild(y("th", {
75
+ for (const i of n(o[0])) a.appendChild(w("th", {
76
76
  border: "1px solid #dee3e8",
77
77
  padding: "6px 10px",
78
78
  textAlign: "left",
79
79
  backgroundColor: "#f5f7fa",
80
80
  fontWeight: "600"
81
- }, N(s)));
81
+ }, L(i)));
82
82
  g.appendChild(a), e.appendChild(g);
83
- const d = document.createElement("tbody");
84
- for (const s of o.slice(2)) {
85
- const c = document.createElement("tr");
86
- for (const l of n(s)) c.appendChild(y("td", {
83
+ const p = document.createElement("tbody");
84
+ for (const i of o.slice(2)) {
85
+ const f = document.createElement("tr");
86
+ for (const d of n(i)) f.appendChild(w("td", {
87
87
  border: "1px solid #dee3e8",
88
88
  padding: "6px 10px"
89
- }, N(l)));
90
- d.appendChild(c);
89
+ }, L(d)));
90
+ p.appendChild(f);
91
91
  }
92
- return e.appendChild(d), r.appendChild(e), r;
92
+ return e.appendChild(p), r.appendChild(e), r;
93
93
  }
94
- var Oe = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
95
- function me(o) {
94
+ var Me = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
95
+ function be(o) {
96
96
  const n = document.createDocumentFragment(), r = o.replace(/\r\n?/g, `
97
97
  `).split(`
98
98
  `);
@@ -103,88 +103,88 @@ function me(o) {
103
103
  e++;
104
104
  continue;
105
105
  }
106
- const d = a.match(ge);
107
- if (d) {
108
- const l = d[1][0], h = [];
109
- for (e++; e < r.length && !new RegExp(`^ {0,3}${l === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(r[e]); )
110
- h.push(r[e]), e++;
106
+ const p = a.match(he);
107
+ if (p) {
108
+ const d = p[1][0], b = [];
109
+ for (e++; e < r.length && !new RegExp(`^ {0,3}${d === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(r[e]); )
110
+ b.push(r[e]), e++;
111
111
  e++;
112
- const T = y("pre", { margin: "0 0 8px 0" });
113
- T.appendChild(y("code", {
112
+ const N = w("pre", { margin: "0 0 8px 0" });
113
+ N.appendChild(w("code", {
114
114
  display: "block",
115
115
  background: "#f5f5f5",
116
116
  padding: "8px 12px",
117
117
  borderRadius: "6px",
118
118
  fontSize: "13px",
119
119
  overflowX: "auto",
120
- fontFamily: ce,
120
+ fontFamily: ge,
121
121
  whiteSpace: "pre"
122
- }, M(h.join(`
123
- `)))), n.appendChild(T);
122
+ }, H(b.join(`
123
+ `)))), n.appendChild(N);
124
124
  continue;
125
125
  }
126
- if (pe.test(a)) {
127
- n.appendChild(y("hr", {
126
+ if (ue.test(a)) {
127
+ n.appendChild(w("hr", {
128
128
  border: "none",
129
129
  borderTop: "1px solid #dee3e8",
130
130
  margin: "12px 0"
131
131
  })), e++;
132
132
  continue;
133
133
  }
134
- const s = a.match(fe);
135
- if (s) {
136
- const l = s[1].length;
137
- n.appendChild(y(`h${l}`, {
134
+ const i = a.match(me);
135
+ if (i) {
136
+ const d = i[1].length;
137
+ n.appendChild(w(`h${d}`, {
138
138
  margin: "16px 0 8px 0",
139
- fontSize: Le[l - 1],
139
+ fontSize: Ae[d - 1],
140
140
  fontWeight: "600",
141
141
  lineHeight: "1.3"
142
- }, N(s[2]))), e++;
142
+ }, L(i[2]))), e++;
143
143
  continue;
144
144
  }
145
- if (X.test(a)) {
146
- const l = [];
147
- for (; e < r.length && X.test(r[e]); )
148
- l.push(r[e].replace(X, "")), e++;
149
- const h = y("blockquote", {
145
+ if (K.test(a)) {
146
+ const d = [];
147
+ for (; e < r.length && K.test(r[e]); )
148
+ d.push(r[e].replace(K, "")), e++;
149
+ const b = w("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
- h.appendChild(me(l.join(`
157
- `))), n.appendChild(h);
156
+ b.appendChild(be(d.join(`
157
+ `))), n.appendChild(b);
158
158
  continue;
159
159
  }
160
- if (a.includes("|") && Oe(r[e + 1])) {
161
- const l = [a, r[e + 1]];
160
+ if (a.includes("|") && Me(r[e + 1])) {
161
+ const d = [a, r[e + 1]];
162
162
  for (e += 2; e < r.length && r[e].includes("|") && r[e].trim(); )
163
- l.push(r[e]), e++;
164
- n.appendChild(Ne(l));
163
+ d.push(r[e]), e++;
164
+ n.appendChild(De(d));
165
165
  continue;
166
166
  }
167
- if (H.test(a)) {
168
- const l = [], h = Z(a);
167
+ if (B.test(a)) {
168
+ const d = [], b = J(a);
169
169
  for (; e < r.length && r[e].trim() !== ""; )
170
- if (H.test(r[e]) || Z(r[e]) > h)
171
- l.push(r[e]), e++;
170
+ if (B.test(r[e]) || J(r[e]) > b)
171
+ d.push(r[e]), e++;
172
172
  else break;
173
- n.appendChild(ue(l));
173
+ n.appendChild(xe(d));
174
174
  continue;
175
175
  }
176
- const c = [a];
177
- for (e++; e < r.length && !Ae(r[e]); )
178
- c.push(r[e]), e++;
179
- n.appendChild(y("p", {
176
+ const f = [a];
177
+ for (e++; e < r.length && !Le(r[e]); )
178
+ f.push(r[e]), e++;
179
+ n.appendChild(w("p", {
180
180
  margin: "0 0 8px 0",
181
181
  lineHeight: "1.6"
182
- }, c.map((l) => N(l)).join("<br>")));
182
+ }, f.map((d) => L(d)).join("<br>")));
183
183
  }
184
184
  const g = n.lastElementChild;
185
185
  return g && (g.style.marginBottom = "0"), n;
186
186
  }
187
- var he = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ie = {
187
+ var Ce = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ce = {
188
188
  font: "--ago-font",
189
189
  radius: "--ago-radius",
190
190
  messageRadius: "--ago-message-radius",
@@ -198,109 +198,109 @@ var he = '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
- }, xe = "var(--ago-brand-color, #03182f)", be = "var(--ago-brand-text-color, #fff)", De = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Me = "var(--ago-header-text-color, #e8f0fe)", z = "var(--ago-panel-background, #fff)", He = "var(--ago-messages-background, #fbfbfb)", j = "var(--ago-text-color, #30373e)", Be = "var(--ago-muted-text-color, #6b6d6f)", k = "var(--ago-border-color, #dee3e8)", Y = "var(--ago-accent-color, #1b5fc4)", ze = "var(--ago-radius, 16px)", le = "var(--ago-message-radius, 16px)";
202
- function Ue(o, n) {
201
+ }, ve = "var(--ago-brand-color, #03182f)", Ee = "var(--ago-brand-text-color, #fff)", He = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Be = "var(--ago-header-text-color, #e8f0fe)", z = "var(--ago-panel-background, #fff)", Ue = "var(--ago-messages-background, #fbfbfb)", X = "var(--ago-text-color, #30373e)", ze = "var(--ago-muted-text-color, #6b6d6f)", $ = "var(--ago-border-color, #dee3e8)", Z = "var(--ago-accent-color, #1b5fc4)", Fe = "var(--ago-radius, 16px)", pe = "var(--ago-message-radius, 16px)";
202
+ function We(o, n) {
203
203
  if (n)
204
- for (const r of Object.keys(ie)) {
204
+ for (const r of Object.keys(ce)) {
205
205
  const e = n[r];
206
- e != null && o.style.setProperty(ie[r], e);
206
+ e != null && o.style.setProperty(ce[r], e);
207
207
  }
208
208
  }
209
- function E(o, n) {
209
+ function R(o, n) {
210
210
  Object.assign(o.style, n);
211
211
  }
212
- function C(o = {}) {
212
+ function x(o = {}) {
213
213
  const n = document.createElement("div");
214
- return E(n, o), n;
214
+ return R(n, o), n;
215
215
  }
216
- var de = "ago-chat-widget-keyframes";
217
- function Fe() {
218
- if (typeof document > "u" || document.getElementById(de)) return;
216
+ var fe = "ago-chat-widget-keyframes";
217
+ function Pe() {
218
+ if (typeof document > "u" || document.getElementById(fe)) return;
219
219
  const o = document.createElement("style");
220
- o.id = de, 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 = fe, 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 We(o) {
222
+ function Ge(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 Ke(o, n) {
228
- const { title: r = "Chat", welcomeMessage: e = "Hello! How can I help you today?", placeholder: g = "Type a message...", allowFiles: a = !1, height: d = 500, logoUrl: s, showAgentName: c = !1, theme: l, loadThreads: h = !1, forms: T, onFollowUpClick: m, onMessageSent: R, onMessageReceived: U } = n;
227
+ function Ve(o, n) {
228
+ const { title: r = "Chat", welcomeMessage: e = "Hello! How can I help you today?", placeholder: g = "Type a message...", allowFiles: a = !1, height: p = 500, logoUrl: i, showAgentName: f = !1, theme: d, loadThreads: b = !1, forms: N, onFollowUpClick: u, onMessageSent: _, onMessageReceived: F } = n;
229
229
  if (!n.client && !n.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
230
- const x = n.client ?? new ke(n.config), L = We(o), F = n.persistConversation, O = F ? Ie(F === !0 ? {} : F) : void 0;
231
- let w = n.conversationId ?? O?.getLastActiveThread() ?? void 0, p = [], A = !1, B = null;
232
- const W = [], D = C({
230
+ const h = n.client ?? new Ie(n.config), O = Ge(o), W = n.persistConversation, D = W ? Ne(W === !0 ? {} : W) : void 0;
231
+ let S = n.conversationId ?? D?.getLastActiveThread() ?? void 0, l = [], I = !1, U = null;
232
+ const P = [], M = x({
233
233
  display: "flex",
234
234
  flexDirection: "column",
235
- height: typeof d == "number" ? `${d}px` : d,
236
- border: `1px solid ${k}`,
237
- borderRadius: ze,
235
+ height: typeof p == "number" ? `${p}px` : p,
236
+ border: `1px solid ${$}`,
237
+ borderRadius: Fe,
238
238
  overflow: "hidden",
239
239
  backgroundColor: z,
240
- fontFamily: he,
240
+ fontFamily: Ce,
241
241
  textAlign: "left",
242
242
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
243
243
  });
244
- D.className = "ago-chat-widget", Ue(D, l);
245
- const P = C({
244
+ M.className = "ago-chat-widget", We(M, d);
245
+ const G = x({
246
246
  padding: "14px 16px",
247
- borderBottom: `1px solid ${k}`,
248
- backgroundColor: De,
249
- color: Me,
247
+ borderBottom: `1px solid ${$}`,
248
+ backgroundColor: He,
249
+ color: Be,
250
250
  display: "flex",
251
251
  alignItems: "center",
252
252
  gap: "10px"
253
253
  });
254
- if (P.className = "ago-chat-widget__header", s) {
254
+ if (G.className = "ago-chat-widget__header", i) {
255
255
  const t = document.createElement("img");
256
- t.src = s, t.alt = "Logo", E(t, {
256
+ t.src = i, t.alt = "Logo", R(t, {
257
257
  height: "24px",
258
258
  width: "auto"
259
- }), P.appendChild(t);
259
+ }), G.appendChild(t);
260
260
  }
261
- const K = document.createElement("h3");
262
- K.textContent = r, E(K, {
261
+ const q = document.createElement("h3");
262
+ q.textContent = r, R(q, {
263
263
  margin: "0",
264
264
  fontSize: "15px",
265
265
  fontWeight: "600"
266
- }), P.appendChild(K);
267
- const $ = C({
266
+ }), G.appendChild(q);
267
+ const T = x({
268
268
  flex: "1",
269
269
  overflow: "auto",
270
270
  padding: "16px",
271
- backgroundColor: He
271
+ backgroundColor: Ue
272
272
  });
273
- $.className = "ago-chat-widget__messages";
274
- const { inputRow: Ce, setDisabled: ve, focus: ye } = Pe({
273
+ T.className = "ago-chat-widget__messages";
274
+ const { inputRow: ye, setDisabled: we, focus: Re } = je({
275
275
  placeholder: g,
276
276
  allowFiles: a,
277
- onSend: (t, i) => {
278
- q(t, i);
277
+ onSend: (t, s) => {
278
+ V(t, s);
279
279
  }
280
280
  });
281
- Fe(), D.append(P, $, Ce), L.appendChild(D);
282
- const J = m !== !1, ee = m === !1 ? void 0 : m ?? ((t) => {
283
- q(t);
281
+ Pe(), M.append(G, T, ye), O.appendChild(M);
282
+ const ee = u !== !1, te = u === !1 ? void 0 : u ?? ((t) => {
283
+ V(t);
284
284
  });
285
- function Ee(t) {
286
- const i = t.role === "user", b = C({
285
+ function Se(t, s) {
286
+ const c = t.role === "user", y = x({
287
287
  display: "flex",
288
288
  flexDirection: "column",
289
- alignItems: i ? "flex-end" : "flex-start",
289
+ alignItems: c ? "flex-end" : "flex-start",
290
290
  marginBottom: "16px"
291
291
  });
292
- if (b.className = `ago-message ago-message--${t.role}`, !i && c && t.agent) {
293
- const f = C({
292
+ if (y.className = `ago-message ago-message--${t.role}`, !c && f && t.agent) {
293
+ const m = x({
294
294
  fontSize: "13px",
295
295
  fontWeight: "500",
296
- color: j,
296
+ color: X,
297
297
  marginBottom: "6px",
298
298
  padding: "0 4px"
299
299
  });
300
- f.className = "ago-message__agent", f.textContent = t.agent.displayName || t.agent.name, b.appendChild(f);
300
+ m.className = "ago-message__agent", m.textContent = t.agent.displayName || t.agent.name, y.appendChild(m);
301
301
  }
302
- if (!i && t.sources && t.sources.length > 0) {
303
- const f = C({
302
+ if (!c && t.sources && t.sources.length > 0) {
303
+ const m = x({
304
304
  display: "grid",
305
305
  gridTemplateColumns: "1fr 1fr",
306
306
  gap: "6px",
@@ -308,28 +308,28 @@ function Ke(o, n) {
308
308
  width: "100%",
309
309
  maxWidth: "85%"
310
310
  });
311
- f.className = "ago-message__sources", t.sources.forEach((v, u) => {
312
- const _ = v.url ? document.createElement("a") : document.createElement("div");
313
- v.url && _ instanceof HTMLAnchorElement && (_.href = v.url, _.target = "_blank", _.rel = "noopener noreferrer"), E(_, {
311
+ m.className = "ago-message__sources", t.sources.forEach((C, E) => {
312
+ const A = C.url ? document.createElement("a") : document.createElement("div");
313
+ C.url && A instanceof HTMLAnchorElement && (A.href = C.url, A.target = "_blank", A.rel = "noopener noreferrer"), R(A, {
314
314
  display: "flex",
315
315
  alignItems: "center",
316
316
  gap: "8px",
317
317
  padding: "8px 10px",
318
- border: `1px solid ${k}`,
318
+ border: `1px solid ${$}`,
319
319
  borderRadius: "8px",
320
320
  backgroundColor: z,
321
321
  textDecoration: "none",
322
- color: j,
322
+ color: X,
323
323
  fontSize: "12px",
324
324
  overflow: "hidden"
325
325
  });
326
- const ae = C({
326
+ const le = x({
327
327
  flexShrink: "0",
328
328
  width: "18px",
329
329
  height: "18px",
330
330
  borderRadius: "3px",
331
- border: `1px solid ${Y}`,
332
- color: Y,
331
+ border: `1px solid ${Z}`,
332
+ color: Z,
333
333
  fontSize: "11px",
334
334
  fontWeight: "500",
335
335
  display: "flex",
@@ -337,67 +337,76 @@ function Ke(o, n) {
337
337
  justifyContent: "center",
338
338
  backgroundColor: "#f0f4ff"
339
339
  });
340
- ae.textContent = String(u + 1);
341
- const Q = C({
340
+ le.textContent = String(E + 1);
341
+ const Y = x({
342
342
  overflow: "hidden",
343
343
  textOverflow: "ellipsis",
344
344
  whiteSpace: "nowrap"
345
345
  });
346
- Q.textContent = v.title, Q.title = v.title, _.append(ae, Q), f.appendChild(_);
347
- }), b.appendChild(f);
346
+ Y.textContent = C.title, Y.title = C.title, A.append(le, Y), m.appendChild(A);
347
+ }), y.appendChild(m);
348
348
  }
349
- const S = C({
350
- maxWidth: i ? "75%" : "100%",
351
- padding: i ? "10px 14px" : "2px 8px",
352
- borderRadius: i ? le : "0",
353
- backgroundColor: i ? xe : "transparent",
354
- color: i ? be : j,
349
+ const v = x({
350
+ maxWidth: c ? "75%" : "100%",
351
+ padding: c ? "10px 14px" : "2px 8px",
352
+ borderRadius: c ? pe : "0",
353
+ backgroundColor: c ? ve : "transparent",
354
+ color: c ? Ee : X,
355
355
  wordBreak: "break-word",
356
356
  fontSize: "14px",
357
357
  lineHeight: "1.6"
358
358
  });
359
- if (S.className = "ago-message__content", t.content ? S.appendChild(me(t.content)) : t.status === "IN_PROGRESS" && S.appendChild(_e()), b.appendChild(S), t.followUpReplies && t.followUpReplies.length > 0) {
360
- const f = C({
359
+ if (v.className = "ago-message__content", t.content ? v.appendChild(be(t.content)) : t.status === "IN_PROGRESS" && v.appendChild(ie()), y.appendChild(v), s && I && t.role === "assistant" && t.status === "DONE" && !(t.followUpReplies && t.followUpReplies.length > 0)) {
360
+ const m = x({
361
+ marginTop: "10px",
362
+ paddingLeft: "8px"
363
+ });
364
+ m.className = "ago-message__followups-loading", m.appendChild(ie()), y.appendChild(m);
365
+ }
366
+ if (s && t.followUpReplies && t.followUpReplies.length > 0) {
367
+ const m = x({
361
368
  display: "flex",
362
369
  flexWrap: "wrap",
363
370
  gap: "8px",
364
371
  marginTop: "10px"
365
372
  });
366
- f.className = "ago-message__followups";
367
- for (const v of t.followUpReplies) {
368
- const u = document.createElement("button");
369
- u.type = "button", u.className = "ago-message__followup-btn", u.textContent = v, u.disabled = !J, E(u, {
373
+ m.className = "ago-message__followups";
374
+ for (const C of t.followUpReplies) {
375
+ const E = document.createElement("button");
376
+ E.type = "button", E.className = "ago-message__followup-btn", E.textContent = C, E.disabled = !ee, R(E, {
370
377
  padding: "6px 14px",
371
378
  fontSize: "13px",
372
- borderRadius: le,
373
- border: `1px solid ${k}`,
379
+ borderRadius: pe,
380
+ border: `1px solid ${$}`,
374
381
  backgroundColor: z,
375
- color: j,
376
- cursor: J ? "pointer" : "default",
382
+ color: X,
383
+ cursor: ee ? "pointer" : "default",
377
384
  transition: "border-color 0.15s"
378
- }), ee && u.addEventListener("click", () => ee(v)), u.addEventListener("mouseenter", () => {
379
- u.style.borderColor = Y;
380
- }), u.addEventListener("mouseleave", () => {
381
- u.style.borderColor = k;
382
- }), f.appendChild(u);
385
+ }), te && E.addEventListener("click", () => te(C)), E.addEventListener("mouseenter", () => {
386
+ E.style.borderColor = Z;
387
+ }), E.addEventListener("mouseleave", () => {
388
+ E.style.borderColor = $;
389
+ }), m.appendChild(E);
383
390
  }
384
- b.appendChild(f);
391
+ y.appendChild(m);
385
392
  }
386
- return b;
393
+ return y;
387
394
  }
388
- function I() {
389
- if ($.replaceChildren(), p.length === 0) {
390
- const t = C({
395
+ function k() {
396
+ if (T.replaceChildren(), l.length === 0) {
397
+ const s = x({
391
398
  textAlign: "center",
392
- color: Be,
399
+ color: ze,
393
400
  padding: "24px 16px",
394
401
  fontSize: "14px",
395
402
  lineHeight: "1.5"
396
403
  });
397
- t.textContent = e, $.appendChild(t);
398
- } else for (const t of p) $.appendChild(Ee(t));
399
- if (B) {
400
- const t = C({
404
+ s.textContent = e, T.appendChild(s);
405
+ } else l.forEach((s, c) => {
406
+ T.appendChild(Se(s, c === l.length - 1));
407
+ });
408
+ if (U) {
409
+ const s = x({
401
410
  padding: "10px 14px",
402
411
  backgroundColor: "#fef2f2",
403
412
  color: "#dc2626",
@@ -406,218 +415,223 @@ function Ke(o, n) {
406
415
  fontSize: "13px",
407
416
  border: "1px solid #fecaca"
408
417
  });
409
- t.textContent = B, $.appendChild(t);
418
+ s.textContent = U, T.appendChild(s);
410
419
  }
411
- $.scrollTop = $.scrollHeight, ve(A);
420
+ T.scrollTop = T.scrollHeight;
421
+ const t = l[l.length - 1];
422
+ we(I && t?.role === "assistant" && t.status === "IN_PROGRESS");
412
423
  }
413
- function we() {
414
- for (let t = p.length - 1; t >= 0; t--) {
415
- const i = p[t];
416
- if (i.role === "assistant" && i.status === "IN_PROGRESS") return i;
424
+ function _e() {
425
+ for (let t = l.length - 1; t >= 0; t--) {
426
+ const s = l[t];
427
+ if (s.role === "assistant" && s.status === "IN_PROGRESS") return s;
417
428
  }
418
429
  }
419
- const te = (t) => {
420
- w || (w = t.conversationId);
421
- }, ne = (t) => {
422
- const i = we();
423
- i && (i.content += t.content, I());
430
+ const ne = (t) => {
431
+ S || (S = t.conversationId);
424
432
  }, oe = (t) => {
425
- const i = p.findIndex((b) => b.id === t.id || b.role === "assistant" && b.status === "IN_PROGRESS");
426
- i >= 0 ? p[i] = t : p.push(t), A = !1, I(), t.status === "DONE" && U?.({
433
+ const s = _e();
434
+ s && (s.content += t.content, k());
435
+ }, re = (t) => {
436
+ const s = l.findIndex((c) => c.id === t.id || c.role === "assistant" && c.status === "IN_PROGRESS");
437
+ s >= 0 ? l[s] = t : l.push(t), k();
438
+ }, ae = (t) => {
439
+ const s = l.findIndex((c) => c.id === t.id || c.role === "assistant" && c.status === "IN_PROGRESS");
440
+ s >= 0 ? l[s] = t : l.push(t), I = !1, k(), t.status === "DONE" && F?.({
427
441
  id: t.id,
428
442
  content: t.content
429
443
  });
430
- }, re = (t) => {
431
- B = t.error, A = !1, p = p.filter((i) => !i.id.startsWith("temp-")), I();
444
+ }, se = (t) => {
445
+ U = t.error, I = !1, l = l.filter((s) => !s.id.startsWith("temp-")), k();
432
446
  };
433
- x.on("message:start", te), x.on("message:chunk", ne), x.on("message:complete", oe), x.on("message:error", re);
434
- const Se = (T ?? []).map((t) => $e(t).install(x));
435
- async function q(t, i) {
436
- const b = t.trim();
437
- if (!b && !i?.length || A) return;
438
- R?.(b), A = !0, B = null;
439
- const S = Date.now();
440
- p.push({
441
- id: `temp-user-${S}`,
442
- conversationId: w || "",
443
- content: b,
447
+ h.on("message:start", ne), h.on("message:chunk", oe), h.on("message:answer-complete", re), h.on("message:complete", ae), h.on("message:error", se);
448
+ const ke = (N ?? []).map((t) => Te(t).install(h));
449
+ async function V(t, s) {
450
+ const c = t.trim();
451
+ if (!c && !s?.length || I) return;
452
+ _?.(c), I = !0, U = null;
453
+ const y = Date.now();
454
+ l.push({
455
+ id: `temp-user-${y}`,
456
+ conversationId: S || "",
457
+ content: c,
444
458
  role: "user",
445
459
  status: "DONE",
446
460
  createdAt: /* @__PURE__ */ new Date()
447
- }), p.push({
448
- id: `temp-assistant-${S}`,
449
- conversationId: w || "",
461
+ }), l.push({
462
+ id: `temp-assistant-${y}`,
463
+ conversationId: S || "",
450
464
  content: "",
451
465
  role: "assistant",
452
466
  status: "IN_PROGRESS",
453
467
  createdAt: /* @__PURE__ */ new Date()
454
- }), I();
468
+ }), k();
455
469
  try {
456
- const f = await x.sendMessage(b, {
457
- conversationId: w,
458
- files: i
470
+ const v = await h.sendMessage(c, {
471
+ conversationId: S,
472
+ files: s
459
473
  });
460
- f.conversationId && (w || (w = f.conversationId), O?.setActiveThread(f.conversationId, f.createdAt));
461
- const v = p.find((u) => u.id === `temp-user-${S}`);
462
- if (v && (v.id = `user-${S}`, v.conversationId = f.conversationId), !p.some((u) => u.id === f.id)) {
463
- const u = p.findIndex((_) => _.id === `temp-assistant-${S}`);
464
- u >= 0 ? p[u] = f : p.push(f);
474
+ v.conversationId && (S || (S = v.conversationId), D?.setActiveThread(v.conversationId, v.createdAt));
475
+ const m = l.find((C) => C.id === `temp-user-${y}`);
476
+ if (m && (m.id = `user-${y}`, m.conversationId = v.conversationId), !l.some((C) => C.id === v.id)) {
477
+ const C = l.findIndex((E) => E.id === `temp-assistant-${y}`);
478
+ C >= 0 ? l[C] = v : l.push(v);
465
479
  }
466
- p = p.filter((u) => !u.id.startsWith("temp-")), A = !1, I(), h && V();
467
- } catch (f) {
468
- B = f instanceof Error ? f.message : "Failed to send message", A = !1, p = p.filter((v) => !v.id.startsWith("temp-")), I();
480
+ l = l.filter((C) => !C.id.startsWith("temp-")), I = !1, k(), b && Q();
481
+ } catch (v) {
482
+ U = v instanceof Error ? v.message : "Failed to send message", I = !1, l = l.filter((m) => !m.id.startsWith("temp-")), k();
469
483
  }
470
484
  }
471
- async function V() {
485
+ async function Q() {
472
486
  try {
473
- const t = await x.getConversations();
474
- W.splice(0, W.length, ...t);
487
+ const t = await h.getConversations();
488
+ P.splice(0, P.length, ...t);
475
489
  } catch {
476
490
  }
477
- return W;
491
+ return P;
478
492
  }
479
- async function Re(t) {
493
+ async function $e(t) {
480
494
  try {
481
- const i = (await x.getConversation(t))?.messages ?? [];
482
- i.length > 0 && p.length === 0 && (p = i, I());
495
+ const s = (await h.getConversation(t))?.messages ?? [];
496
+ s.length > 0 && l.length === 0 && (l = s, k());
483
497
  } catch {
484
- p.length === 0 && (O?.clear(), w = void 0);
498
+ l.length === 0 && (D?.clear(), S = void 0);
485
499
  }
486
500
  }
487
- return I(), ye(), w && Re(w), h && V(), {
488
- client: x,
489
- element: D,
490
- sendMessage: q,
491
- session: O,
492
- threads: W,
493
- refreshThreads: V,
501
+ return k(), Re(), S && $e(S), b && Q(), {
502
+ client: h,
503
+ element: M,
504
+ sendMessage: V,
505
+ session: D,
506
+ threads: P,
507
+ refreshThreads: Q,
494
508
  destroy() {
495
- x.off("message:start", te), x.off("message:chunk", ne), x.off("message:complete", oe), x.off("message:error", re), Se.forEach((t) => t()), D.remove(), n.client || x.destroy();
509
+ h.off("message:start", ne), h.off("message:chunk", oe), h.off("message:answer-complete", re), h.off("message:complete", ae), h.off("message:error", se), ke.forEach((t) => t()), M.remove(), n.client || h.destroy();
496
510
  }
497
511
  };
498
- function _e() {
499
- const t = C({
512
+ function ie() {
513
+ const t = x({
500
514
  display: "flex",
501
515
  gap: "4px",
502
516
  padding: "4px 0"
503
517
  });
504
- for (let i = 0; i < 3; i++) {
505
- const b = C({
518
+ for (let s = 0; s < 3; s++) {
519
+ const c = x({
506
520
  width: "6px",
507
521
  height: "6px",
508
522
  borderRadius: "50%",
509
523
  backgroundColor: "#b5bfc8",
510
524
  animation: "ago-pulse 1.2s ease-in-out infinite",
511
- animationDelay: `${i * 0.2}s`
525
+ animationDelay: `${s * 0.2}s`
512
526
  });
513
- t.appendChild(b);
527
+ t.appendChild(c);
514
528
  }
515
529
  return t;
516
530
  }
517
531
  }
518
- function Pe(o) {
532
+ function je(o) {
519
533
  let n = [];
520
534
  const r = document.createElement("form");
521
- E(r, {
535
+ R(r, {
522
536
  display: "flex",
523
537
  flexDirection: "column",
524
538
  gap: "8px",
525
539
  padding: "12px",
526
- borderTop: `1px solid ${k}`,
540
+ borderTop: `1px solid ${$}`,
527
541
  backgroundColor: z
528
542
  }), r.className = "ago-chat-input";
529
- const e = C({
543
+ const e = x({
530
544
  display: "flex",
531
545
  flexWrap: "wrap",
532
546
  gap: "6px"
533
- }), g = C({
547
+ }), g = x({
534
548
  display: "flex",
535
549
  gap: "8px",
536
550
  alignItems: "flex-end"
537
551
  }), a = document.createElement("textarea");
538
- a.placeholder = o.placeholder, a.rows = 1, E(a, {
552
+ a.placeholder = o.placeholder, a.rows = 1, R(a, {
539
553
  flex: "1",
540
554
  resize: "none",
541
555
  padding: "10px 12px",
542
- border: `1px solid ${k}`,
556
+ border: `1px solid ${$}`,
543
557
  borderRadius: "12px",
544
558
  fontSize: "14px",
545
- fontFamily: he,
559
+ fontFamily: Ce,
546
560
  lineHeight: "1.4",
547
561
  maxHeight: "120px",
548
562
  outline: "none"
549
563
  });
550
- const d = document.createElement("button");
551
- d.type = "submit", d.textContent = "Send", E(d, {
564
+ const p = document.createElement("button");
565
+ p.type = "submit", p.textContent = "Send", R(p, {
552
566
  padding: "10px 16px",
553
567
  border: "none",
554
568
  borderRadius: "12px",
555
- backgroundColor: xe,
556
- color: be,
569
+ backgroundColor: ve,
570
+ color: Ee,
557
571
  fontSize: "14px",
558
572
  fontWeight: "500",
559
573
  cursor: "pointer"
560
574
  });
561
- let s = null, c = null;
562
- o.allowFiles && (s = document.createElement("input"), s.type = "file", s.multiple = !0, E(s, { display: "none" }), c = document.createElement("button"), c.type = "button", c.textContent = "📎", E(c, {
575
+ let i = null, f = null;
576
+ o.allowFiles && (i = document.createElement("input"), i.type = "file", i.multiple = !0, R(i, { display: "none" }), f = document.createElement("button"), f.type = "button", f.textContent = "📎", R(f, {
563
577
  padding: "10px 12px",
564
- border: `1px solid ${k}`,
578
+ border: `1px solid ${$}`,
565
579
  borderRadius: "12px",
566
580
  backgroundColor: z,
567
581
  cursor: "pointer",
568
582
  fontSize: "14px"
569
- }), c.addEventListener("click", () => s?.click()), s.addEventListener("change", () => {
570
- n = [...n, ...Array.from(s?.files ?? [])], l();
583
+ }), f.addEventListener("click", () => i?.click()), i.addEventListener("change", () => {
584
+ n = [...n, ...Array.from(i?.files ?? [])], d();
571
585
  }));
572
- function l() {
573
- e.replaceChildren(), n.forEach((m, R) => {
574
- const U = C({
586
+ function d() {
587
+ e.replaceChildren(), n.forEach((u, _) => {
588
+ const F = x({
575
589
  display: "flex",
576
590
  alignItems: "center",
577
591
  gap: "4px",
578
592
  padding: "4px 8px",
579
593
  backgroundColor: "#f0f4ff",
580
- border: `1px solid ${k}`,
594
+ border: `1px solid ${$}`,
581
595
  borderRadius: "8px",
582
596
  fontSize: "12px"
583
- }), x = document.createElement("span");
584
- x.textContent = m.name;
585
- const L = document.createElement("button");
586
- L.type = "button", L.textContent = "×", E(L, {
597
+ }), h = document.createElement("span");
598
+ h.textContent = u.name;
599
+ const O = document.createElement("button");
600
+ O.type = "button", O.textContent = "×", R(O, {
587
601
  border: "none",
588
602
  background: "transparent",
589
603
  cursor: "pointer",
590
604
  fontSize: "14px",
591
605
  lineHeight: "1"
592
- }), L.addEventListener("click", () => {
593
- n = n.filter((F, O) => O !== R), l();
594
- }), U.append(x, L), e.appendChild(U);
606
+ }), O.addEventListener("click", () => {
607
+ n = n.filter((W, D) => D !== _), d();
608
+ }), F.append(h, O), e.appendChild(F);
595
609
  });
596
610
  }
597
- const h = () => {
598
- const m = a.value, R = n;
599
- return a.value = "", n = [], l(), {
600
- content: m,
601
- files: R
611
+ const b = () => {
612
+ const u = a.value, _ = n;
613
+ return a.value = "", n = [], d(), {
614
+ content: u,
615
+ files: _
602
616
  };
603
- }, T = () => {
604
- const { content: m, files: R } = h();
605
- (m.trim() || R.length > 0) && o.onSend(m.trim(), R.length > 0 ? R : void 0);
617
+ }, N = () => {
618
+ const { content: u, files: _ } = b();
619
+ (u.trim() || _.length > 0) && o.onSend(u.trim(), _.length > 0 ? _ : void 0);
606
620
  };
607
- return r.addEventListener("submit", (m) => {
608
- m.preventDefault(), T();
609
- }), a.addEventListener("keydown", (m) => {
610
- m.key === "Enter" && !m.shiftKey && (m.preventDefault(), T());
611
- }), c && g.appendChild(c), g.append(a, d), s && r.appendChild(s), r.append(e, g), {
621
+ return r.addEventListener("submit", (u) => {
622
+ u.preventDefault(), N();
623
+ }), a.addEventListener("keydown", (u) => {
624
+ u.key === "Enter" && !u.shiftKey && (u.preventDefault(), N());
625
+ }), f && g.appendChild(f), g.append(a, p), i && r.appendChild(i), r.append(e, g), {
612
626
  inputRow: r,
613
- getValueAndClear: h,
614
- setDisabled: (m) => {
615
- a.disabled = m, d.disabled = m, d.style.opacity = m ? "0.6" : "1", d.style.cursor = m ? "not-allowed" : "pointer";
627
+ getValueAndClear: b,
628
+ setDisabled: (u) => {
629
+ a.disabled = u, p.disabled = u, p.style.opacity = u ? "0.6" : "1", p.style.cursor = u ? "not-allowed" : "pointer";
616
630
  },
617
631
  focus: () => a.focus()
618
632
  };
619
633
  }
620
634
  export {
621
- Ke as mountChatWidget,
622
- me as renderMarkdown
635
+ Ve as mountChatWidget,
636
+ be as renderMarkdown
623
637
  };