@useago/sdk 1.0.0 → 1.0.1

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