@useago/sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.js CHANGED
@@ -1,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, u as Ke } from "./AgoClient-bQozE6-A.js";
2
+ import { r as qe, t as Ve } from "./createFormCollector-D-TpSd9x.js";
3
+ import { t as Qe } from "./createConversationSession-BbK3ou1k.js";
4
+ var Ye = {
5
5
  "&": "&",
6
6
  "<": "&lt;",
7
7
  ">": "&gt;",
8
8
  '"': "&quot;",
9
9
  "'": "&#39;"
10
10
  };
11
- function H(o) {
12
- return o.replace(/[&<>"']/g, (n) => Oe[n]);
11
+ function U(o) {
12
+ return o.replace(/[&<>"']/g, (n) => Ye[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 Ne = '"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:${Ne}">${U(i)}</code>`)), t = t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (u, i, f) => {
23
+ const s = ke(f);
24
+ return s ? r(`<img alt="${U(i)}" src="${U(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="${U(s)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${M(i)}</a>`) : u;
28
+ }), t = U(t), t = t.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), t = t.replace(new RegExp(`${Q}(\\d+)${Q}`, "g"), (u, i) => n[Number(i)]), t;
29
29
  }
30
- 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+(.*)$/, Ze = [
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
+ ], pe = (o) => o.match(/^\s*/)?.[0].length ?? 0;
42
+ function Je(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 && pe(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((h) => P.test(h)).length > 0 && p.appendChild(Me(s.filter((h) => h.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 et(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 tt = (o) => !!o && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);
95
+ function fe(o) {
96
96
  const n = document.createDocumentFragment(), r = o.replace(/\r\n?/g, `
97
97
  `).split(`
98
98
  `);
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], h = [];
109
+ for (t++; t < r.length && !new RegExp(`^ {0,3}${c === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(r[t]); )
110
+ h.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: Ne,
121
121
  whiteSpace: "pre"
122
- }, H(b.join(`
123
- `)))), n.appendChild(N);
122
+ }, U(h.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: Ze[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 h = R("blockquote", {
150
150
  borderLeft: "4px solid #dee3e8",
151
151
  paddingLeft: "12px",
152
152
  margin: "0 0 8px 0",
153
153
  fontStyle: "italic",
154
154
  color: "#6b6d6f"
155
155
  });
156
- b.appendChild(be(d.join(`
157
- `))), n.appendChild(b);
156
+ h.appendChild(fe(c.join(`
157
+ `))), n.appendChild(h);
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("|") && tt(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(et(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 = [], h = pe(i);
169
+ for (; t < r.length && r[t].trim() !== ""; )
170
+ if (P.test(r[t]) || pe(r[t]) > h)
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 && !Je(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 ue = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', $e = {
188
188
  font: "--ago-font",
189
189
  radius: "--ago-radius",
190
190
  messageRadius: "--ago-message-radius",
@@ -198,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
+ }, ge = "var(--ago-brand-color, #03182f)", he = "var(--ago-brand-text-color, #fff)", nt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", Ie = "var(--ago-header-text-color, #e8f0fe)", j = "var(--ago-panel-background, #fff)", ot = "var(--ago-messages-background, #fbfbfb)", Y = "var(--ago-text-color, #30373e)", rt = "var(--ago-muted-text-color, #6b6d6f)", $ = "var(--ago-border-color, #dee3e8)", ce = "var(--ago-accent-color, #1b5fc4)", at = "var(--ago-radius, 16px)", Ae = "var(--ago-message-radius, 16px)";
202
+ function it(o, n) {
203
203
  if (n)
204
- 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
212
  function x(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 Le = "ago-chat-widget-keyframes";
217
+ function st() {
218
+ if (typeof document > "u" || document.getElementById(Le)) return;
219
219
  const o = document.createElement("style");
220
- o.id = 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 = Le, o.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(o);
221
221
  }
222
- function Ge(o) {
222
+ function lt(o) {
223
223
  const n = typeof o == "string" ? document.querySelector(o) : o;
224
224
  if (!n) throw new Error(`mountChatWidget: target "${String(o)}" not found.`);
225
225
  return n;
226
226
  }
227
- function 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
- 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({
227
+ function ut(o, n) {
228
+ const { title: r = "Chat", welcomeMessage: t = "Hello! How can I help you today?", placeholder: u = "Type a message...", allowFiles: i = !1, height: f = 500, placement: s = "inline", width: p = 400, defaultOpen: c = !1, logoUrl: h, showAgentName: L = !1, theme: m, loadThreads: _ = !1, forms: X, onFollowUpClick: B, onMessageSent: N, onMessageReceived: me } = n;
229
+ if (!n.client && !n.config?.baseUrl) throw new Ke("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
230
+ const g = n.client ?? new Xe(n.config), xe = lt(o), z = s === "left" || s === "right", Be = z && (n.launcher ?? !0);
231
+ let H = z ? c : !0;
232
+ const J = n.persistConversation, K = J ? Qe(J === !0 ? {} : J) : void 0;
233
+ let k = n.conversationId ?? K?.getLastActiveThread() ?? void 0, d = [], O = !1, W = null;
234
+ const q = [], F = x({
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: at,
238
240
  overflow: "hidden",
239
- backgroundColor: z,
240
- fontFamily: Ce,
241
+ backgroundColor: j,
242
+ fontFamily: ue,
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);
246
+ F.className = "ago-chat-widget", it(F, m);
245
247
  const G = x({
246
248
  padding: "14px 16px",
247
249
  borderBottom: `1px solid ${$}`,
248
- backgroundColor: He,
249
- color: Be,
250
+ backgroundColor: nt,
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", h) {
257
+ const e = document.createElement("img");
258
+ e.src = h, 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", () => le()), G.appendChild(e);
280
+ }
281
+ const A = x({
268
282
  flex: "1",
269
283
  overflow: "auto",
270
284
  padding: "16px",
271
- backgroundColor: Ue
285
+ backgroundColor: ot
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
+ A.className = "ago-chat-widget__messages";
288
+ const { inputRow: ze, setDisabled: He, focus: te } = dt({
289
+ placeholder: u,
290
+ allowFiles: i,
291
+ onSend: (e, a) => {
292
+ re(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
+ st(), F.append(G, A, ze);
296
+ let V = F, T, E;
297
+ const ne = s === "left" ? "left" : "right";
298
+ if (z && (T = x({
299
+ position: "fixed",
300
+ top: "0",
301
+ bottom: "0",
302
+ [ne]: "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(F, {
310
+ height: "100%",
311
+ width: "100%",
312
+ borderRadius: "0",
313
+ border: "none",
314
+ boxShadow: "none",
315
+ [ne === "left" ? "borderRight" : "borderLeft"]: `1px solid ${$}`
316
+ }), T.appendChild(F), V = T), Be) {
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
+ [ne]: "20px",
321
+ width: "56px",
322
+ height: "56px",
323
+ borderRadius: "50%",
324
+ border: "none",
325
+ backgroundColor: ge,
326
+ color: he,
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: ue
334
+ }), h) {
335
+ const e = document.createElement("img");
336
+ e.src = h, e.alt = "", y(e, {
337
+ width: "26px",
338
+ height: "26px",
339
+ objectFit: "contain"
340
+ }), E.appendChild(e);
341
+ } else E.appendChild(Ge());
342
+ E.addEventListener("click", () => se());
343
+ }
344
+ xe.appendChild(V), E && xe.appendChild(E), ie();
345
+ const be = B !== !1, Ce = B === !1 ? void 0 : B ?? ((e) => {
346
+ re(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 = x({
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 b = x({
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
+ b.className = "ago-message__agent", b.textContent = e.agent.displayName || e.agent.name, S.appendChild(b);
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 b = x({
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
+ b.className = "ago-message__sources", e.sources.forEach((C, w) => {
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 = x({
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 ${ce}`,
395
+ color: ce,
333
396
  fontSize: "11px",
334
397
  fontWeight: "500",
335
398
  display: "flex",
@@ -337,76 +400,69 @@ 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(w + 1);
404
+ const de = x({
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
+ de.textContent = C.title, de.title = C.title, D.append(_e, de), b.appendChild(D);
410
+ }), S.appendChild(b);
348
411
  }
349
412
  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,
413
+ maxWidth: l ? "75%" : "100%",
414
+ padding: l ? "10px 14px" : "2px 8px",
415
+ borderRadius: l ? Ae : "0",
416
+ backgroundColor: l ? ge : "transparent",
417
+ color: l ? he : 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({
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({
422
+ if (v.className = "ago-message__content", e.content ? v.appendChild(fe(e.content)) : e.status === "IN_PROGRESS" && v.appendChild(je()), S.appendChild(v), a && e.followUpReplies && e.followUpReplies.length > 0) {
423
+ const b = x({
368
424
  display: "flex",
369
425
  flexWrap: "wrap",
370
426
  gap: "8px",
371
427
  marginTop: "10px"
372
428
  });
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, {
429
+ b.className = "ago-message__followups";
430
+ for (const C of e.followUpReplies) {
431
+ const w = document.createElement("button");
432
+ w.type = "button", w.className = "ago-message__followup-btn", w.textContent = C, w.disabled = !be, y(w, {
377
433
  padding: "6px 14px",
378
- fontSize: "13px",
379
- borderRadius: pe,
434
+ fontSize: "14px",
435
+ borderRadius: Ae,
380
436
  border: `1px solid ${$}`,
381
- backgroundColor: z,
382
- color: X,
383
- cursor: ee ? "pointer" : "default",
437
+ backgroundColor: j,
438
+ color: Y,
439
+ cursor: be ? "pointer" : "default",
384
440
  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);
441
+ }), Ce && w.addEventListener("click", () => Ce(C)), w.addEventListener("mouseenter", () => {
442
+ w.style.borderColor = ce;
443
+ }), w.addEventListener("mouseleave", () => {
444
+ w.style.borderColor = $;
445
+ }), b.appendChild(w);
390
446
  }
391
- y.appendChild(m);
447
+ S.appendChild(b);
392
448
  }
393
- return y;
449
+ return S;
394
450
  }
395
- function k() {
396
- if (T.replaceChildren(), l.length === 0) {
397
- const s = x({
451
+ function I() {
452
+ if (A.replaceChildren(), d.length === 0) {
453
+ const a = x({
398
454
  textAlign: "center",
399
- color: ze,
455
+ color: rt,
400
456
  padding: "24px 16px",
401
457
  fontSize: "14px",
402
458
  lineHeight: "1.5"
403
459
  });
404
- s.textContent = e, T.appendChild(s);
405
- } else l.forEach((s, c) => {
406
- T.appendChild(Se(s, c === l.length - 1));
460
+ a.appendChild(fe(t)), A.appendChild(a);
461
+ } else d.forEach((a, l) => {
462
+ A.appendChild(Fe(a, l === d.length - 1));
407
463
  });
408
- if (U) {
409
- const s = x({
464
+ if (W) {
465
+ const a = x({
410
466
  padding: "10px 14px",
411
467
  backgroundColor: "#fef2f2",
412
468
  color: "#dc2626",
@@ -415,177 +471,207 @@ function Ve(o, n) {
415
471
  fontSize: "13px",
416
472
  border: "1px solid #fecaca"
417
473
  });
418
- s.textContent = U, T.appendChild(s);
474
+ a.textContent = W, A.appendChild(a);
419
475
  }
420
- T.scrollTop = T.scrollHeight;
421
- const t = l[l.length - 1];
422
- we(I && t?.role === "assistant" && t.status === "IN_PROGRESS");
476
+ A.scrollTop = A.scrollHeight;
477
+ const e = d[d.length - 1];
478
+ He(O && e?.role === "assistant" && e.status === "IN_PROGRESS");
423
479
  }
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;
480
+ function Ue() {
481
+ for (let e = d.length - 1; e >= 0; e--) {
482
+ const a = d[e];
483
+ if (a.role === "assistant" && a.status === "IN_PROGRESS") return a;
428
484
  }
429
485
  }
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
486
+ const ve = (e) => {
487
+ k || (k = e.conversationId);
488
+ }, we = (e) => {
489
+ const a = Ue();
490
+ a && (a.content += e.content, I());
491
+ }, ye = (e) => {
492
+ const a = d.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
493
+ a >= 0 ? d[a] = e : d.push(e), I(), te();
494
+ }, Ee = (e) => {
495
+ const a = d.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
496
+ a >= 0 ? d[a] = e : d.push(e), O = !1, I(), e.status === "DONE" && me?.({
497
+ id: e.id,
498
+ content: e.content
443
499
  });
444
- }, se = (t) => {
445
- U = t.error, I = !1, l = l.filter((s) => !s.id.startsWith("temp-")), k();
500
+ }, Se = (e) => {
501
+ W = e.error, O = !1, d = d.filter((a) => !a.id.startsWith("temp-")), I();
446
502
  };
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,
503
+ g.on("message:start", ve), g.on("message:chunk", we), g.on("message:answer-complete", ye), g.on("message:complete", Ee), g.on("message:error", Se);
504
+ const oe = [];
505
+ let Re = !1;
506
+ for (const e of X ?? []) e.schema != null ? oe.push(Ve(e).install(g)) : qe(g, e).then((a) => {
507
+ Re || oe.push(a.install(g));
508
+ }).catch(() => {
509
+ });
510
+ async function re(e, a) {
511
+ const l = e.trim();
512
+ if (!l && !a?.length || O) return;
513
+ N?.(l), O = !0, W = null;
514
+ const S = Date.now();
515
+ d.push({
516
+ id: `temp-user-${S}`,
517
+ conversationId: k || "",
518
+ content: l,
458
519
  role: "user",
459
520
  status: "DONE",
460
521
  createdAt: /* @__PURE__ */ new Date()
461
- }), l.push({
462
- id: `temp-assistant-${y}`,
463
- conversationId: S || "",
522
+ }), d.push({
523
+ id: `temp-assistant-${S}`,
524
+ conversationId: k || "",
464
525
  content: "",
465
526
  role: "assistant",
466
527
  status: "IN_PROGRESS",
467
528
  createdAt: /* @__PURE__ */ new Date()
468
- }), k();
529
+ }), I();
469
530
  try {
470
- const v = await h.sendMessage(c, {
471
- conversationId: S,
472
- files: s
531
+ const v = await g.sendMessage(l, {
532
+ conversationId: k,
533
+ files: a
473
534
  });
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);
535
+ v.conversationId && (k || (k = v.conversationId), K?.setActiveThread(v.conversationId, v.createdAt));
536
+ const b = d.find((C) => C.id === `temp-user-${S}`);
537
+ if (b && (b.id = `user-${S}`, b.conversationId = v.conversationId), !d.some((C) => C.id === v.id)) {
538
+ const C = d.findIndex((w) => w.id === `temp-assistant-${S}`);
539
+ C >= 0 ? d[C] = v : d.push(v);
479
540
  }
480
- l = l.filter((C) => !C.id.startsWith("temp-")), I = !1, k(), b && Q();
541
+ d = d.filter((C) => !C.id.startsWith("temp-")), O = !1, I(), _ && ae();
481
542
  } catch (v) {
482
- U = v instanceof Error ? v.message : "Failed to send message", I = !1, l = l.filter((m) => !m.id.startsWith("temp-")), k();
543
+ W = v instanceof Error ? v.message : "Failed to send message", O = !1, d = d.filter((b) => !b.id.startsWith("temp-")), I();
483
544
  }
484
545
  }
485
- async function Q() {
546
+ async function ae() {
486
547
  try {
487
- const t = await h.getConversations();
488
- P.splice(0, P.length, ...t);
548
+ const e = await g.getConversations();
549
+ q.splice(0, q.length, ...e);
489
550
  } catch {
490
551
  }
491
- return P;
552
+ return q;
492
553
  }
493
- async function $e(t) {
554
+ async function Pe(e) {
494
555
  try {
495
- const s = (await h.getConversation(t))?.messages ?? [];
496
- s.length > 0 && l.length === 0 && (l = s, k());
556
+ const a = (await g.getConversation(e))?.messages ?? [];
557
+ a.length > 0 && d.length === 0 && (d = a, I());
497
558
  } catch {
498
- l.length === 0 && (D?.clear(), S = void 0);
559
+ d.length === 0 && (K?.clear(), k = void 0);
499
560
  }
500
561
  }
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,
562
+ return I(), te(), k && Pe(k), _ && ae(), {
563
+ client: g,
564
+ element: V,
565
+ sendMessage: re,
566
+ ...z ? {
567
+ open: se,
568
+ close: le,
569
+ toggle: We
570
+ } : {},
571
+ session: K,
572
+ threads: q,
573
+ refreshThreads: ae,
508
574
  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();
575
+ g.off("message:start", ve), g.off("message:chunk", we), g.off("message:answer-complete", ye), g.off("message:complete", Ee), g.off("message:error", Se), Re = !0, oe.forEach((e) => e()), V.remove(), E?.remove(), n.client || g.destroy();
510
576
  }
511
577
  };
512
578
  function ie() {
513
- const t = x({
579
+ if (!T) return;
580
+ const e = s === "left" ? "translateX(-100%)" : "translateX(100%)";
581
+ T.style.transform = H ? "translateX(0)" : e, T.setAttribute("aria-hidden", H ? "false" : "true"), E && (E.style.display = H ? "none" : "flex");
582
+ }
583
+ function se() {
584
+ H = !0, ie(), te();
585
+ }
586
+ function le() {
587
+ H = !1, ie();
588
+ }
589
+ function We() {
590
+ H ? le() : se();
591
+ }
592
+ function Ge() {
593
+ const e = "http://www.w3.org/2000/svg", a = document.createElementNS(e, "svg");
594
+ a.setAttribute("width", "26"), a.setAttribute("height", "26"), a.setAttribute("viewBox", "0 0 24 24"), a.setAttribute("fill", "none");
595
+ const l = document.createElementNS(e, "path");
596
+ return l.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), l.setAttribute("stroke", "currentColor"), l.setAttribute("stroke-width", "2"), l.setAttribute("stroke-linecap", "round"), l.setAttribute("stroke-linejoin", "round"), a.appendChild(l), a;
597
+ }
598
+ function je() {
599
+ const e = x({
514
600
  display: "flex",
515
601
  gap: "4px",
516
602
  padding: "4px 0"
517
603
  });
518
- for (let s = 0; s < 3; s++) {
519
- const c = x({
604
+ for (let a = 0; a < 3; a++) {
605
+ const l = x({
520
606
  width: "6px",
521
607
  height: "6px",
522
608
  borderRadius: "50%",
523
609
  backgroundColor: "#b5bfc8",
524
610
  animation: "ago-pulse 1.2s ease-in-out infinite",
525
- animationDelay: `${s * 0.2}s`
611
+ animationDelay: `${a * 0.2}s`
526
612
  });
527
- t.appendChild(c);
613
+ e.appendChild(l);
528
614
  }
529
- return t;
615
+ return e;
530
616
  }
531
617
  }
532
- function je(o) {
618
+ function dt(o) {
533
619
  let n = [];
534
620
  const r = document.createElement("form");
535
- R(r, {
621
+ y(r, {
536
622
  display: "flex",
537
623
  flexDirection: "column",
538
624
  gap: "8px",
539
625
  padding: "12px",
540
626
  borderTop: `1px solid ${$}`,
541
- backgroundColor: z
627
+ backgroundColor: j
542
628
  }), r.className = "ago-chat-input";
543
- const e = x({
629
+ const t = x({
544
630
  display: "flex",
545
631
  flexWrap: "wrap",
546
632
  gap: "6px"
547
- }), g = x({
633
+ }), u = x({
548
634
  display: "flex",
549
635
  gap: "8px",
550
636
  alignItems: "flex-end"
551
- }), a = document.createElement("textarea");
552
- a.placeholder = o.placeholder, a.rows = 1, R(a, {
637
+ }), i = document.createElement("textarea");
638
+ i.placeholder = o.placeholder, i.rows = 1, y(i, {
553
639
  flex: "1",
554
640
  resize: "none",
555
641
  padding: "10px 12px",
556
642
  border: `1px solid ${$}`,
557
643
  borderRadius: "12px",
558
644
  fontSize: "14px",
559
- fontFamily: Ce,
645
+ fontFamily: ue,
560
646
  lineHeight: "1.4",
561
647
  maxHeight: "120px",
562
648
  outline: "none"
563
649
  });
564
- const p = document.createElement("button");
565
- p.type = "submit", p.textContent = "Send", R(p, {
650
+ const f = document.createElement("button");
651
+ f.type = "submit", f.textContent = "Send", y(f, {
566
652
  padding: "10px 16px",
567
653
  border: "none",
568
654
  borderRadius: "12px",
569
- backgroundColor: ve,
570
- color: Ee,
655
+ backgroundColor: ge,
656
+ color: he,
571
657
  fontSize: "14px",
572
658
  fontWeight: "500",
573
659
  cursor: "pointer"
574
660
  });
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, {
661
+ let s = null, p = null;
662
+ 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
663
  padding: "10px 12px",
578
664
  border: `1px solid ${$}`,
579
665
  borderRadius: "12px",
580
- backgroundColor: z,
666
+ backgroundColor: j,
581
667
  cursor: "pointer",
582
668
  fontSize: "14px"
583
- }), f.addEventListener("click", () => i?.click()), i.addEventListener("change", () => {
584
- n = [...n, ...Array.from(i?.files ?? [])], d();
669
+ }), p.addEventListener("click", () => s?.click()), s.addEventListener("change", () => {
670
+ n = [...n, ...Array.from(s?.files ?? [])], c();
585
671
  }));
586
- function d() {
587
- e.replaceChildren(), n.forEach((u, _) => {
588
- const F = x({
672
+ function c() {
673
+ t.replaceChildren(), n.forEach((m, _) => {
674
+ const X = x({
589
675
  display: "flex",
590
676
  alignItems: "center",
591
677
  gap: "4px",
@@ -594,44 +680,44 @@ function je(o) {
594
680
  border: `1px solid ${$}`,
595
681
  borderRadius: "8px",
596
682
  fontSize: "12px"
597
- }), h = document.createElement("span");
598
- h.textContent = u.name;
599
- const O = document.createElement("button");
600
- O.type = "button", O.textContent = "×", R(O, {
683
+ }), B = document.createElement("span");
684
+ B.textContent = m.name;
685
+ const N = document.createElement("button");
686
+ N.type = "button", N.textContent = "×", y(N, {
601
687
  border: "none",
602
688
  background: "transparent",
603
689
  cursor: "pointer",
604
690
  fontSize: "14px",
605
691
  lineHeight: "1"
606
- }), O.addEventListener("click", () => {
607
- n = n.filter((W, D) => D !== _), d();
608
- }), F.append(h, O), e.appendChild(F);
692
+ }), N.addEventListener("click", () => {
693
+ n = n.filter((me, g) => g !== _), c();
694
+ }), X.append(B, N), t.appendChild(X);
609
695
  });
610
696
  }
611
- const b = () => {
612
- const u = a.value, _ = n;
613
- return a.value = "", n = [], d(), {
614
- content: u,
697
+ const h = () => {
698
+ const m = i.value, _ = n;
699
+ return i.value = "", n = [], c(), {
700
+ content: m,
615
701
  files: _
616
702
  };
617
- }, N = () => {
618
- const { content: u, files: _ } = b();
619
- (u.trim() || _.length > 0) && o.onSend(u.trim(), _.length > 0 ? _ : void 0);
703
+ }, L = () => {
704
+ const { content: m, files: _ } = h();
705
+ (m.trim() || _.length > 0) && o.onSend(m.trim(), _.length > 0 ? _ : void 0);
620
706
  };
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), {
707
+ return r.addEventListener("submit", (m) => {
708
+ m.preventDefault(), L();
709
+ }), i.addEventListener("keydown", (m) => {
710
+ m.key === "Enter" && !m.shiftKey && (m.preventDefault(), L());
711
+ }), p && u.appendChild(p), u.append(i, f), s && r.appendChild(s), r.append(t, u), {
626
712
  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";
713
+ getValueAndClear: h,
714
+ setDisabled: (m) => {
715
+ i.disabled = m, f.disabled = m, f.style.opacity = m ? "0.6" : "1", f.style.cursor = m ? "not-allowed" : "pointer";
630
716
  },
631
- focus: () => a.focus()
717
+ focus: () => i.focus()
632
718
  };
633
719
  }
634
720
  export {
635
- Ve as mountChatWidget,
636
- be as renderMarkdown
721
+ ut as mountChatWidget,
722
+ fe as renderMarkdown
637
723
  };