@useago/sdk 0.4.2 → 0.4.4

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,94 +1,116 @@
1
- import { t as re } from "./AgoClient-rvTz2thR.js";
2
- import { t as ae } from "./createFormCollector-BwvkKi48.js";
3
- import { t as ie } from "./createConversationSession-D9FesBQS.js";
4
- var Y = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
5
- function x(s, n) {
6
- Object.assign(s.style, n);
1
+ import { t as ge } from "./AgoClient-rvTz2thR.js";
2
+ import { t as ue } from "./createFormCollector-D4-yZh1i.js";
3
+ import { t as xe } from "./createConversationSession-XkiOGAUT.js";
4
+ var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', Z = {
5
+ font: "--ago-font",
6
+ radius: "--ago-radius",
7
+ messageRadius: "--ago-message-radius",
8
+ brand: "--ago-brand-color",
9
+ brandText: "--ago-brand-text-color",
10
+ headerBg: "--ago-header-background",
11
+ headerText: "--ago-header-text-color",
12
+ panelBg: "--ago-panel-background",
13
+ messagesBg: "--ago-messages-background",
14
+ text: "--ago-text-color",
15
+ mutedText: "--ago-muted-text-color",
16
+ border: "--ago-border-color",
17
+ accent: "--ago-accent-color"
18
+ }, ne = "var(--ago-brand-color, #03182f)", re = "var(--ago-brand-text-color, #fff)", me = "var(--ago-header-background, var(--ago-brand-color, #03182f))", he = "var(--ago-header-text-color, #e8f0fe)", L = "var(--ago-panel-background, #fff)", be = "var(--ago-messages-background, #fbfbfb)", H = "var(--ago-text-color, #30373e)", ve = "var(--ago-muted-text-color, #6b6d6f)", E = "var(--ago-border-color, #dee3e8)", K = "var(--ago-accent-color, #1b5fc4)", Ce = "var(--ago-radius, 16px)", ee = "var(--ago-message-radius, 16px)";
19
+ function ye(i, o) {
20
+ if (o)
21
+ for (const g of Object.keys(Z)) {
22
+ const w = o[g];
23
+ w != null && i.style.setProperty(Z[g], w);
24
+ }
25
+ }
26
+ function m(i, o) {
27
+ Object.assign(i.style, o);
7
28
  }
8
- function c(s = {}) {
9
- const n = document.createElement("div");
10
- return x(n, s), n;
29
+ function c(i = {}) {
30
+ const o = document.createElement("div");
31
+ return m(o, i), o;
11
32
  }
12
- var V = "ago-chat-widget-keyframes";
13
- function se() {
14
- if (typeof document > "u" || document.getElementById(V)) return;
15
- const s = document.createElement("style");
16
- s.id = V, s.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(s);
33
+ var te = "ago-chat-widget-keyframes";
34
+ function Ee() {
35
+ if (typeof document > "u" || document.getElementById(te)) return;
36
+ const i = document.createElement("style");
37
+ i.id = te, i.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(i);
17
38
  }
18
- function le(s) {
19
- const n = typeof s == "string" ? document.querySelector(s) : s;
20
- if (!n) throw new Error(`mountChatWidget: target "${String(s)}" not found.`);
21
- return n;
39
+ function we(i) {
40
+ const o = typeof i == "string" ? document.querySelector(i) : i;
41
+ if (!o) throw new Error(`mountChatWidget: target "${String(i)}" not found.`);
42
+ return o;
22
43
  }
23
- function ue(s, n) {
24
- const { title: v = "Chat", welcomeMessage: _ = "Hello! How can I help you today?", placeholder: N = "Type a message...", allowFiles: g = !1, height: m = 500, logoUrl: f, showAgentName: b = !1, loadThreads: I = !1, forms: A, onFollowUpClick: R, onMessageSent: i, onMessageReceived: C } = n;
25
- if (!n.client && !n.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
26
- const l = n.client ?? new re(n.config), L = le(s), y = n.persistConversation, D = y ? ie(y === !0 ? {} : y) : void 0;
27
- let u = n.conversationId ?? D?.getLastActiveThread() ?? void 0, o = [], k = !1, z = null;
28
- const T = [], W = c({
44
+ function Ie(i, o) {
45
+ const { title: g = "Chat", welcomeMessage: w = "Hello! How can I help you today?", placeholder: O = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: v = !1, theme: T, loadThreads: D = !1, forms: B, onFollowUpClick: s, onMessageSent: C, onMessageReceived: $ } = o;
46
+ if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
47
+ const l = o.client ?? new ge(o.config), k = we(i), U = o.persistConversation, I = U ? xe(U === !0 ? {} : U) : void 0;
48
+ let h = o.conversationId ?? I?.getLastActiveThread() ?? void 0, n = [], _ = !1, N = null;
49
+ const M = [], A = c({
29
50
  display: "flex",
30
51
  flexDirection: "column",
31
- height: typeof m == "number" ? `${m}px` : m,
32
- border: "1px solid #dee3e8",
33
- borderRadius: "16px",
52
+ height: typeof x == "number" ? `${x}px` : x,
53
+ border: `1px solid ${E}`,
54
+ borderRadius: Ce,
34
55
  overflow: "hidden",
35
- backgroundColor: "#fff",
36
- fontFamily: Y,
56
+ backgroundColor: L,
57
+ fontFamily: oe,
58
+ textAlign: "left",
37
59
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
38
60
  });
39
- W.className = "ago-chat-widget";
40
- const F = c({
61
+ A.className = "ago-chat-widget", ye(A, T);
62
+ const z = c({
41
63
  padding: "14px 16px",
42
- borderBottom: "1px solid #dee3e8",
43
- backgroundColor: "#03182f",
44
- color: "#e8f0fe",
64
+ borderBottom: `1px solid ${E}`,
65
+ backgroundColor: me,
66
+ color: he,
45
67
  display: "flex",
46
68
  alignItems: "center",
47
69
  gap: "10px"
48
70
  });
49
- if (F.className = "ago-chat-widget__header", f) {
71
+ if (z.className = "ago-chat-widget__header", f) {
50
72
  const e = document.createElement("img");
51
- e.src = f, e.alt = "Logo", x(e, {
73
+ e.src = f, e.alt = "Logo", m(e, {
52
74
  height: "24px",
53
75
  width: "auto"
54
- }), F.appendChild(e);
76
+ }), z.appendChild(e);
55
77
  }
56
- const M = document.createElement("h3");
57
- M.textContent = v, x(M, {
78
+ const W = document.createElement("h3");
79
+ W.textContent = g, m(W, {
58
80
  margin: "0",
59
81
  fontSize: "15px",
60
82
  fontWeight: "600"
61
- }), F.appendChild(M);
62
- const E = c({
83
+ }), z.appendChild(W);
84
+ const R = c({
63
85
  flex: "1",
64
86
  overflow: "auto",
65
87
  padding: "16px",
66
- backgroundColor: "#fbfbfb"
88
+ backgroundColor: be
67
89
  });
68
- E.className = "ago-chat-widget__messages";
69
- const { inputRow: J, setDisabled: Q, focus: X } = de({
70
- placeholder: N,
71
- allowFiles: g,
90
+ R.className = "ago-chat-widget__messages";
91
+ const { inputRow: ae, setDisabled: se, focus: ie } = Re({
92
+ placeholder: O,
93
+ allowFiles: u,
72
94
  onSend: (e, t) => {
73
- H(e, t);
95
+ F(e, t);
74
96
  }
75
97
  });
76
- se(), W.append(F, E, J), L.appendChild(W);
77
- const O = R !== !1, $ = R === !1 ? void 0 : R ?? ((e) => {
78
- H(e);
98
+ Ee(), A.append(z, R, ae), k.appendChild(A);
99
+ const X = s !== !1, j = s === !1 ? void 0 : s ?? ((e) => {
100
+ F(e);
79
101
  });
80
- function Z(e) {
102
+ function le(e) {
81
103
  const t = e.role === "user", d = c({
82
104
  display: "flex",
83
105
  flexDirection: "column",
84
106
  alignItems: t ? "flex-end" : "flex-start",
85
107
  marginBottom: "16px"
86
108
  });
87
- if (d.className = `ago-message ago-message--${e.role}`, !t && b && e.agent) {
109
+ if (d.className = `ago-message ago-message--${e.role}`, !t && v && e.agent) {
88
110
  const r = c({
89
111
  fontSize: "13px",
90
112
  fontWeight: "500",
91
- color: "#30373e",
113
+ color: H,
92
114
  marginBottom: "6px",
93
115
  padding: "0 4px"
94
116
  });
@@ -104,27 +126,27 @@ function ue(s, n) {
104
126
  maxWidth: "85%"
105
127
  });
106
128
  r.className = "ago-message__sources", e.sources.forEach((p, a) => {
107
- const w = p.url ? document.createElement("a") : document.createElement("div");
108
- p.url && w instanceof HTMLAnchorElement && (w.href = p.url, w.target = "_blank", w.rel = "noopener noreferrer"), x(w, {
129
+ const y = p.url ? document.createElement("a") : document.createElement("div");
130
+ p.url && y instanceof HTMLAnchorElement && (y.href = p.url, y.target = "_blank", y.rel = "noopener noreferrer"), m(y, {
109
131
  display: "flex",
110
132
  alignItems: "center",
111
133
  gap: "8px",
112
134
  padding: "8px 10px",
113
- border: "1px solid #dee3e8",
135
+ border: `1px solid ${E}`,
114
136
  borderRadius: "8px",
115
- backgroundColor: "#fff",
137
+ backgroundColor: L,
116
138
  textDecoration: "none",
117
- color: "#30373e",
139
+ color: H,
118
140
  fontSize: "12px",
119
141
  overflow: "hidden"
120
142
  });
121
- const q = c({
143
+ const Q = c({
122
144
  flexShrink: "0",
123
145
  width: "18px",
124
146
  height: "18px",
125
147
  borderRadius: "3px",
126
- border: "1px solid #1b5fc4",
127
- color: "#1b5fc4",
148
+ border: `1px solid ${K}`,
149
+ color: K,
128
150
  fontSize: "11px",
129
151
  fontWeight: "500",
130
152
  display: "flex",
@@ -132,27 +154,27 @@ function ue(s, n) {
132
154
  justifyContent: "center",
133
155
  backgroundColor: "#f0f4ff"
134
156
  });
135
- q.textContent = String(a + 1);
136
- const B = c({
157
+ Q.textContent = String(a + 1);
158
+ const P = c({
137
159
  overflow: "hidden",
138
160
  textOverflow: "ellipsis",
139
161
  whiteSpace: "nowrap"
140
162
  });
141
- B.textContent = p.title, B.title = p.title, w.append(q, B), r.appendChild(w);
163
+ P.textContent = p.title, P.title = p.title, y.append(Q, P), r.appendChild(y);
142
164
  }), d.appendChild(r);
143
165
  }
144
- const h = c({
166
+ const b = c({
145
167
  maxWidth: t ? "75%" : "100%",
146
168
  padding: t ? "10px 14px" : "2px 8px",
147
- borderRadius: t ? "16px" : "0",
148
- backgroundColor: t ? "#03182f" : "transparent",
149
- color: t ? "#fff" : "#30373e",
169
+ borderRadius: t ? ee : "0",
170
+ backgroundColor: t ? ne : "transparent",
171
+ color: t ? re : H,
150
172
  wordBreak: "break-word",
151
173
  fontSize: "14px",
152
174
  lineHeight: "1.6",
153
175
  whiteSpace: "pre-wrap"
154
176
  });
155
- if (h.className = "ago-message__content", e.content ? h.textContent = e.content : e.status === "IN_PROGRESS" && h.appendChild(oe()), d.appendChild(h), e.followUpReplies && e.followUpReplies.length > 0) {
177
+ if (b.className = "ago-message__content", e.content ? b.textContent = e.content : e.status === "IN_PROGRESS" && b.appendChild(fe()), d.appendChild(b), e.followUpReplies && e.followUpReplies.length > 0) {
156
178
  const r = c({
157
179
  display: "flex",
158
180
  flexWrap: "wrap",
@@ -162,19 +184,19 @@ function ue(s, n) {
162
184
  r.className = "ago-message__followups";
163
185
  for (const p of e.followUpReplies) {
164
186
  const a = document.createElement("button");
165
- a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !O, x(a, {
187
+ a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !X, m(a, {
166
188
  padding: "6px 14px",
167
189
  fontSize: "13px",
168
- borderRadius: "16px",
169
- border: "1px solid #dee3e8",
170
- backgroundColor: "#fff",
171
- color: "#30373e",
172
- cursor: O ? "pointer" : "default",
190
+ borderRadius: ee,
191
+ border: `1px solid ${E}`,
192
+ backgroundColor: L,
193
+ color: H,
194
+ cursor: X ? "pointer" : "default",
173
195
  transition: "border-color 0.15s"
174
- }), $ && a.addEventListener("click", () => $(p)), a.addEventListener("mouseenter", () => {
175
- a.style.borderColor = "#1b5fc4";
196
+ }), j && a.addEventListener("click", () => j(p)), a.addEventListener("mouseenter", () => {
197
+ a.style.borderColor = K;
176
198
  }), a.addEventListener("mouseleave", () => {
177
- a.style.borderColor = "#dee3e8";
199
+ a.style.borderColor = E;
178
200
  }), r.appendChild(a);
179
201
  }
180
202
  d.appendChild(r);
@@ -182,17 +204,17 @@ function ue(s, n) {
182
204
  return d;
183
205
  }
184
206
  function S() {
185
- if (E.replaceChildren(), o.length === 0) {
207
+ if (R.replaceChildren(), n.length === 0) {
186
208
  const e = c({
187
209
  textAlign: "center",
188
- color: "#6b6d6f",
210
+ color: ve,
189
211
  padding: "24px 16px",
190
212
  fontSize: "14px",
191
213
  lineHeight: "1.5"
192
214
  });
193
- e.textContent = _, E.appendChild(e);
194
- } else for (const e of o) E.appendChild(Z(e));
195
- if (z) {
215
+ e.textContent = w, R.appendChild(e);
216
+ } else for (const e of n) R.appendChild(le(e));
217
+ if (N) {
196
218
  const e = c({
197
219
  padding: "10px 14px",
198
220
  backgroundColor: "#fef2f2",
@@ -202,47 +224,47 @@ function ue(s, n) {
202
224
  fontSize: "13px",
203
225
  border: "1px solid #fecaca"
204
226
  });
205
- e.textContent = z, E.appendChild(e);
227
+ e.textContent = N, R.appendChild(e);
206
228
  }
207
- E.scrollTop = E.scrollHeight, Q(k);
229
+ R.scrollTop = R.scrollHeight, se(_);
208
230
  }
209
- function ee() {
210
- for (let e = o.length - 1; e >= 0; e--) {
211
- const t = o[e];
231
+ function de() {
232
+ for (let e = n.length - 1; e >= 0; e--) {
233
+ const t = n[e];
212
234
  if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
213
235
  }
214
236
  }
215
- const P = (e) => {
216
- u || (u = e.conversationId);
217
- }, G = (e) => {
218
- const t = ee();
237
+ const V = (e) => {
238
+ h || (h = e.conversationId);
239
+ }, q = (e) => {
240
+ const t = de();
219
241
  t && (t.content += e.content, S());
220
- }, K = (e) => {
221
- const t = o.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
222
- t >= 0 ? o[t] = e : o.push(e), k = !1, S(), e.status === "DONE" && C?.({
242
+ }, Y = (e) => {
243
+ const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
244
+ t >= 0 ? n[t] = e : n.push(e), _ = !1, S(), e.status === "DONE" && $?.({
223
245
  id: e.id,
224
246
  content: e.content
225
247
  });
226
- }, j = (e) => {
227
- z = e.error, k = !1, o = o.filter((t) => !t.id.startsWith("temp-")), S();
248
+ }, J = (e) => {
249
+ N = e.error, _ = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
228
250
  };
229
- l.on("message:start", P), l.on("message:chunk", G), l.on("message:complete", K), l.on("message:error", j);
230
- const te = (A ?? []).map((e) => ae(e).install(l));
231
- async function H(e, t) {
251
+ l.on("message:start", V), l.on("message:chunk", q), l.on("message:complete", Y), l.on("message:error", J);
252
+ const ce = (B ?? []).map((e) => ue(e).install(l));
253
+ async function F(e, t) {
232
254
  const d = e.trim();
233
- if (!d && !t?.length || k) return;
234
- i?.(d), k = !0, z = null;
235
- const h = Date.now();
236
- o.push({
237
- id: `temp-user-${h}`,
238
- conversationId: u || "",
255
+ if (!d && !t?.length || _) return;
256
+ C?.(d), _ = !0, N = null;
257
+ const b = Date.now();
258
+ n.push({
259
+ id: `temp-user-${b}`,
260
+ conversationId: h || "",
239
261
  content: d,
240
262
  role: "user",
241
263
  status: "DONE",
242
264
  createdAt: /* @__PURE__ */ new Date()
243
- }), o.push({
244
- id: `temp-assistant-${h}`,
245
- conversationId: u || "",
265
+ }), n.push({
266
+ id: `temp-assistant-${b}`,
267
+ conversationId: h || "",
246
268
  content: "",
247
269
  role: "assistant",
248
270
  status: "IN_PROGRESS",
@@ -250,48 +272,48 @@ function ue(s, n) {
250
272
  }), S();
251
273
  try {
252
274
  const r = await l.sendMessage(d, {
253
- conversationId: u,
275
+ conversationId: h,
254
276
  files: t
255
277
  });
256
- r.conversationId && (u || (u = r.conversationId), D?.setActiveThread(r.conversationId, r.createdAt));
257
- const p = o.find((a) => a.id === `temp-user-${h}`);
258
- if (p && (p.id = `user-${h}`, p.conversationId = r.conversationId), !o.some((a) => a.id === r.id)) {
259
- const a = o.findIndex((w) => w.id === `temp-assistant-${h}`);
260
- a >= 0 ? o[a] = r : o.push(r);
278
+ r.conversationId && (h || (h = r.conversationId), I?.setActiveThread(r.conversationId, r.createdAt));
279
+ const p = n.find((a) => a.id === `temp-user-${b}`);
280
+ if (p && (p.id = `user-${b}`, p.conversationId = r.conversationId), !n.some((a) => a.id === r.id)) {
281
+ const a = n.findIndex((y) => y.id === `temp-assistant-${b}`);
282
+ a >= 0 ? n[a] = r : n.push(r);
261
283
  }
262
- o = o.filter((a) => !a.id.startsWith("temp-")), k = !1, S(), I && U();
284
+ n = n.filter((a) => !a.id.startsWith("temp-")), _ = !1, S(), D && G();
263
285
  } catch (r) {
264
- z = r instanceof Error ? r.message : "Failed to send message", k = !1, o = o.filter((p) => !p.id.startsWith("temp-")), S();
286
+ N = r instanceof Error ? r.message : "Failed to send message", _ = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
265
287
  }
266
288
  }
267
- async function U() {
289
+ async function G() {
268
290
  try {
269
291
  const e = await l.getConversations();
270
- T.splice(0, T.length, ...e);
292
+ M.splice(0, M.length, ...e);
271
293
  } catch {
272
294
  }
273
- return T;
295
+ return M;
274
296
  }
275
- async function ne(e) {
297
+ async function pe(e) {
276
298
  try {
277
299
  const t = (await l.getConversation(e))?.messages ?? [];
278
- t.length > 0 && o.length === 0 && (o = t, S());
300
+ t.length > 0 && n.length === 0 && (n = t, S());
279
301
  } catch {
280
- o.length === 0 && (D?.clear(), u = void 0);
302
+ n.length === 0 && (I?.clear(), h = void 0);
281
303
  }
282
304
  }
283
- return S(), X(), u && ne(u), I && U(), {
305
+ return S(), ie(), h && pe(h), D && G(), {
284
306
  client: l,
285
- element: W,
286
- sendMessage: H,
287
- session: D,
288
- threads: T,
289
- refreshThreads: U,
307
+ element: A,
308
+ sendMessage: F,
309
+ session: I,
310
+ threads: M,
311
+ refreshThreads: G,
290
312
  destroy() {
291
- l.off("message:start", P), l.off("message:chunk", G), l.off("message:complete", K), l.off("message:error", j), te.forEach((e) => e()), W.remove(), n.client || l.destroy();
313
+ l.off("message:start", V), l.off("message:chunk", q), l.off("message:complete", Y), l.off("message:error", J), ce.forEach((e) => e()), A.remove(), o.client || l.destroy();
292
314
  }
293
315
  };
294
- function oe() {
316
+ function fe() {
295
317
  const e = c({
296
318
  display: "flex",
297
319
  gap: "4px",
@@ -311,108 +333,108 @@ function ue(s, n) {
311
333
  return e;
312
334
  }
313
335
  }
314
- function de(s) {
315
- let n = [];
316
- const v = document.createElement("form");
317
- x(v, {
336
+ function Re(i) {
337
+ let o = [];
338
+ const g = document.createElement("form");
339
+ m(g, {
318
340
  display: "flex",
319
341
  flexDirection: "column",
320
342
  gap: "8px",
321
343
  padding: "12px",
322
- borderTop: "1px solid #dee3e8",
323
- backgroundColor: "#fff"
324
- }), v.className = "ago-chat-input";
325
- const _ = c({
344
+ borderTop: `1px solid ${E}`,
345
+ backgroundColor: L
346
+ }), g.className = "ago-chat-input";
347
+ const w = c({
326
348
  display: "flex",
327
349
  flexWrap: "wrap",
328
350
  gap: "6px"
329
- }), N = c({
351
+ }), O = c({
330
352
  display: "flex",
331
353
  gap: "8px",
332
354
  alignItems: "flex-end"
333
- }), g = document.createElement("textarea");
334
- g.placeholder = s.placeholder, g.rows = 1, x(g, {
355
+ }), u = document.createElement("textarea");
356
+ u.placeholder = i.placeholder, u.rows = 1, m(u, {
335
357
  flex: "1",
336
358
  resize: "none",
337
359
  padding: "10px 12px",
338
- border: "1px solid #dee3e8",
360
+ border: `1px solid ${E}`,
339
361
  borderRadius: "12px",
340
362
  fontSize: "14px",
341
- fontFamily: Y,
363
+ fontFamily: oe,
342
364
  lineHeight: "1.4",
343
365
  maxHeight: "120px",
344
366
  outline: "none"
345
367
  });
346
- const m = document.createElement("button");
347
- m.type = "submit", m.textContent = "Send", x(m, {
368
+ const x = document.createElement("button");
369
+ x.type = "submit", x.textContent = "Send", m(x, {
348
370
  padding: "10px 16px",
349
371
  border: "none",
350
372
  borderRadius: "12px",
351
- backgroundColor: "#03182f",
352
- color: "#fff",
373
+ backgroundColor: ne,
374
+ color: re,
353
375
  fontSize: "14px",
354
376
  fontWeight: "500",
355
377
  cursor: "pointer"
356
378
  });
357
- let f = null, b = null;
358
- s.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, x(f, { display: "none" }), b = document.createElement("button"), b.type = "button", b.textContent = "📎", x(b, {
379
+ let f = null, v = null;
380
+ i.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, m(f, { display: "none" }), v = document.createElement("button"), v.type = "button", v.textContent = "📎", m(v, {
359
381
  padding: "10px 12px",
360
- border: "1px solid #dee3e8",
382
+ border: `1px solid ${E}`,
361
383
  borderRadius: "12px",
362
- backgroundColor: "#fff",
384
+ backgroundColor: L,
363
385
  cursor: "pointer",
364
386
  fontSize: "14px"
365
- }), b.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
366
- n = [...n, ...Array.from(f?.files ?? [])], I();
387
+ }), v.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
388
+ o = [...o, ...Array.from(f?.files ?? [])], T();
367
389
  }));
368
- function I() {
369
- _.replaceChildren(), n.forEach((i, C) => {
370
- const l = c({
390
+ function T() {
391
+ w.replaceChildren(), o.forEach((s, C) => {
392
+ const $ = c({
371
393
  display: "flex",
372
394
  alignItems: "center",
373
395
  gap: "4px",
374
396
  padding: "4px 8px",
375
397
  backgroundColor: "#f0f4ff",
376
- border: "1px solid #dee3e8",
398
+ border: `1px solid ${E}`,
377
399
  borderRadius: "8px",
378
400
  fontSize: "12px"
379
- }), L = document.createElement("span");
380
- L.textContent = i.name;
381
- const y = document.createElement("button");
382
- y.type = "button", y.textContent = "×", x(y, {
401
+ }), l = document.createElement("span");
402
+ l.textContent = s.name;
403
+ const k = document.createElement("button");
404
+ k.type = "button", k.textContent = "×", m(k, {
383
405
  border: "none",
384
406
  background: "transparent",
385
407
  cursor: "pointer",
386
408
  fontSize: "14px",
387
409
  lineHeight: "1"
388
- }), y.addEventListener("click", () => {
389
- n = n.filter((D, u) => u !== C), I();
390
- }), l.append(L, y), _.appendChild(l);
410
+ }), k.addEventListener("click", () => {
411
+ o = o.filter((U, I) => I !== C), T();
412
+ }), $.append(l, k), w.appendChild($);
391
413
  });
392
414
  }
393
- const A = () => {
394
- const i = g.value, C = n;
395
- return g.value = "", n = [], I(), {
396
- content: i,
415
+ const D = () => {
416
+ const s = u.value, C = o;
417
+ return u.value = "", o = [], T(), {
418
+ content: s,
397
419
  files: C
398
420
  };
399
- }, R = () => {
400
- const { content: i, files: C } = A();
401
- (i.trim() || C.length > 0) && s.onSend(i.trim(), C.length > 0 ? C : void 0);
421
+ }, B = () => {
422
+ const { content: s, files: C } = D();
423
+ (s.trim() || C.length > 0) && i.onSend(s.trim(), C.length > 0 ? C : void 0);
402
424
  };
403
- return v.addEventListener("submit", (i) => {
404
- i.preventDefault(), R();
405
- }), g.addEventListener("keydown", (i) => {
406
- i.key === "Enter" && !i.shiftKey && (i.preventDefault(), R());
407
- }), b && N.appendChild(b), N.append(g, m), f && v.appendChild(f), v.append(_, N), {
408
- inputRow: v,
409
- getValueAndClear: A,
410
- setDisabled: (i) => {
411
- g.disabled = i, m.disabled = i, m.style.opacity = i ? "0.6" : "1", m.style.cursor = i ? "not-allowed" : "pointer";
425
+ return g.addEventListener("submit", (s) => {
426
+ s.preventDefault(), B();
427
+ }), u.addEventListener("keydown", (s) => {
428
+ s.key === "Enter" && !s.shiftKey && (s.preventDefault(), B());
429
+ }), v && O.appendChild(v), O.append(u, x), f && g.appendChild(f), g.append(w, O), {
430
+ inputRow: g,
431
+ getValueAndClear: D,
432
+ setDisabled: (s) => {
433
+ u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
412
434
  },
413
- focus: () => g.focus()
435
+ focus: () => u.focus()
414
436
  };
415
437
  }
416
438
  export {
417
- ue as mountChatWidget
439
+ Ie as mountChatWidget
418
440
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useago/sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "JavaScript SDK for AGO Chat integration",
5
5
  "type": "module",
6
6
  "sideEffects": false,