@useago/sdk 1.0.9 → 1.0.10

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