@useago/sdk 0.4.1 → 0.4.3

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.
Files changed (35) hide show
  1. package/dist/{AgoClient-B6PsfMeg.cjs → AgoClient-D4EL6nva.cjs} +3 -3
  2. package/dist/{AgoClient-BerJvssl.js → AgoClient-rvTz2thR.js} +19 -14
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +15 -0
  5. package/dist/angular.d.ts +15 -0
  6. package/dist/angular.js +1 -1
  7. package/dist/{createConversationSession-CLZvxyuu.js → createConversationSession-D9FesBQS.js} +1 -1
  8. package/dist/{createConversationSession-D3K5Gf1k.cjs → createConversationSession-DtaeA418.cjs} +1 -1
  9. package/dist/{createFormCollector-CD1rqRG4.js → createFormCollector-BwvkKi48.js} +32 -29
  10. package/dist/createFormCollector-Wb8Rr-U2.cjs +1 -0
  11. package/dist/{createMockClient-tVsApEAh.js → createMockClient-DwdxNwEn.js} +4 -2
  12. package/dist/createMockClient-zHQ0cjUH.cjs +1 -0
  13. package/dist/devtools.cjs +5 -4
  14. package/dist/devtools.d.cts +15 -0
  15. package/dist/devtools.d.ts +15 -0
  16. package/dist/devtools.js +35 -31
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +15 -0
  19. package/dist/index.d.ts +15 -0
  20. package/dist/index.js +4 -4
  21. package/dist/react.cjs +1 -1
  22. package/dist/react.d.cts +15 -0
  23. package/dist/react.d.ts +15 -0
  24. package/dist/react.js +3 -3
  25. package/dist/vue.cjs +1 -1
  26. package/dist/vue.d.cts +15 -0
  27. package/dist/vue.d.ts +15 -0
  28. package/dist/vue.js +1 -1
  29. package/dist/widget.cjs +1 -1
  30. package/dist/widget.d.cts +50 -0
  31. package/dist/widget.d.ts +50 -0
  32. package/dist/widget.js +203 -183
  33. package/package.json +1 -1
  34. package/dist/createFormCollector-D1FfiSgA.cjs +0 -1
  35. package/dist/createMockClient-DMFGIOtc.cjs +0 -1
package/dist/widget.js CHANGED
@@ -1,94 +1,114 @@
1
- import { t as re } from "./AgoClient-BerJvssl.js";
2
- import { t as ae } from "./createFormCollector-CD1rqRG4.js";
3
- import { t as ie } from "./createConversationSession-CLZvxyuu.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-BwvkKi48.js";
3
+ import { t as xe } from "./createConversationSession-D9FesBQS.js";
4
+ var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ee = {
5
+ font: "--ago-font",
6
+ radius: "--ago-radius",
7
+ brand: "--ago-brand-color",
8
+ brandText: "--ago-brand-text-color",
9
+ headerBg: "--ago-header-background",
10
+ headerText: "--ago-header-text-color",
11
+ panelBg: "--ago-panel-background",
12
+ messagesBg: "--ago-messages-background",
13
+ text: "--ago-text-color",
14
+ mutedText: "--ago-muted-text-color",
15
+ border: "--ago-border-color",
16
+ accent: "--ago-accent-color"
17
+ }, 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)", X = "var(--ago-radius, 16px)";
18
+ function Ce(i, o) {
19
+ if (o)
20
+ for (const g of Object.keys(ee)) {
21
+ const w = o[g];
22
+ w != null && i.style.setProperty(ee[g], w);
23
+ }
24
+ }
25
+ function m(i, o) {
26
+ Object.assign(i.style, o);
7
27
  }
8
- function c(s = {}) {
9
- const n = document.createElement("div");
10
- return x(n, s), n;
28
+ function c(i = {}) {
29
+ const o = document.createElement("div");
30
+ return m(o, i), o;
11
31
  }
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);
32
+ var te = "ago-chat-widget-keyframes";
33
+ function ye() {
34
+ if (typeof document > "u" || document.getElementById(te)) return;
35
+ const i = document.createElement("style");
36
+ 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
37
  }
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;
38
+ function Ee(i) {
39
+ const o = typeof i == "string" ? document.querySelector(i) : i;
40
+ if (!o) throw new Error(`mountChatWidget: target "${String(i)}" not found.`);
41
+ return o;
22
42
  }
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({
43
+ function _e(i, o) {
44
+ const { title: g = "Chat", welcomeMessage: w = "Hello! How can I help you today?", placeholder: T = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: v = !1, theme: A, loadThreads: D = !1, forms: B, onFollowUpClick: s, onMessageSent: C, onMessageReceived: $ } = o;
45
+ if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
46
+ const l = o.client ?? new ge(o.config), k = Ee(i), U = o.persistConversation, I = U ? xe(U === !0 ? {} : U) : void 0;
47
+ let h = o.conversationId ?? I?.getLastActiveThread() ?? void 0, n = [], _ = !1, N = null;
48
+ const M = [], O = c({
29
49
  display: "flex",
30
50
  flexDirection: "column",
31
- height: typeof m == "number" ? `${m}px` : m,
32
- border: "1px solid #dee3e8",
33
- borderRadius: "16px",
51
+ height: typeof x == "number" ? `${x}px` : x,
52
+ border: `1px solid ${E}`,
53
+ borderRadius: X,
34
54
  overflow: "hidden",
35
- backgroundColor: "#fff",
36
- fontFamily: Y,
55
+ backgroundColor: L,
56
+ fontFamily: oe,
37
57
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
38
58
  });
39
- W.className = "ago-chat-widget";
40
- const F = c({
59
+ O.className = "ago-chat-widget", Ce(O, A);
60
+ const z = c({
41
61
  padding: "14px 16px",
42
- borderBottom: "1px solid #dee3e8",
43
- backgroundColor: "#03182f",
44
- color: "#e8f0fe",
62
+ borderBottom: `1px solid ${E}`,
63
+ backgroundColor: me,
64
+ color: he,
45
65
  display: "flex",
46
66
  alignItems: "center",
47
67
  gap: "10px"
48
68
  });
49
- if (F.className = "ago-chat-widget__header", f) {
69
+ if (z.className = "ago-chat-widget__header", f) {
50
70
  const e = document.createElement("img");
51
- e.src = f, e.alt = "Logo", x(e, {
71
+ e.src = f, e.alt = "Logo", m(e, {
52
72
  height: "24px",
53
73
  width: "auto"
54
- }), F.appendChild(e);
74
+ }), z.appendChild(e);
55
75
  }
56
- const M = document.createElement("h3");
57
- M.textContent = v, x(M, {
76
+ const W = document.createElement("h3");
77
+ W.textContent = g, m(W, {
58
78
  margin: "0",
59
79
  fontSize: "15px",
60
80
  fontWeight: "600"
61
- }), F.appendChild(M);
62
- const E = c({
81
+ }), z.appendChild(W);
82
+ const R = c({
63
83
  flex: "1",
64
84
  overflow: "auto",
65
85
  padding: "16px",
66
- backgroundColor: "#fbfbfb"
86
+ backgroundColor: be
67
87
  });
68
- E.className = "ago-chat-widget__messages";
69
- const { inputRow: J, setDisabled: Q, focus: X } = de({
70
- placeholder: N,
71
- allowFiles: g,
88
+ R.className = "ago-chat-widget__messages";
89
+ const { inputRow: ae, setDisabled: se, focus: ie } = we({
90
+ placeholder: T,
91
+ allowFiles: u,
72
92
  onSend: (e, t) => {
73
- H(e, t);
93
+ F(e, t);
74
94
  }
75
95
  });
76
- se(), W.append(F, E, J), L.appendChild(W);
77
- const O = R !== !1, $ = R === !1 ? void 0 : R ?? ((e) => {
78
- H(e);
96
+ ye(), O.append(z, R, ae), k.appendChild(O);
97
+ const j = s !== !1, V = s === !1 ? void 0 : s ?? ((e) => {
98
+ F(e);
79
99
  });
80
- function Z(e) {
100
+ function le(e) {
81
101
  const t = e.role === "user", d = c({
82
102
  display: "flex",
83
103
  flexDirection: "column",
84
104
  alignItems: t ? "flex-end" : "flex-start",
85
105
  marginBottom: "16px"
86
106
  });
87
- if (d.className = `ago-message ago-message--${e.role}`, !t && b && e.agent) {
107
+ if (d.className = `ago-message ago-message--${e.role}`, !t && v && e.agent) {
88
108
  const r = c({
89
109
  fontSize: "13px",
90
110
  fontWeight: "500",
91
- color: "#30373e",
111
+ color: H,
92
112
  marginBottom: "6px",
93
113
  padding: "0 4px"
94
114
  });
@@ -104,27 +124,27 @@ function ue(s, n) {
104
124
  maxWidth: "85%"
105
125
  });
106
126
  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, {
127
+ const y = p.url ? document.createElement("a") : document.createElement("div");
128
+ p.url && y instanceof HTMLAnchorElement && (y.href = p.url, y.target = "_blank", y.rel = "noopener noreferrer"), m(y, {
109
129
  display: "flex",
110
130
  alignItems: "center",
111
131
  gap: "8px",
112
132
  padding: "8px 10px",
113
- border: "1px solid #dee3e8",
133
+ border: `1px solid ${E}`,
114
134
  borderRadius: "8px",
115
- backgroundColor: "#fff",
135
+ backgroundColor: L,
116
136
  textDecoration: "none",
117
- color: "#30373e",
137
+ color: H,
118
138
  fontSize: "12px",
119
139
  overflow: "hidden"
120
140
  });
121
- const q = c({
141
+ const Z = c({
122
142
  flexShrink: "0",
123
143
  width: "18px",
124
144
  height: "18px",
125
145
  borderRadius: "3px",
126
- border: "1px solid #1b5fc4",
127
- color: "#1b5fc4",
146
+ border: `1px solid ${K}`,
147
+ color: K,
128
148
  fontSize: "11px",
129
149
  fontWeight: "500",
130
150
  display: "flex",
@@ -132,27 +152,27 @@ function ue(s, n) {
132
152
  justifyContent: "center",
133
153
  backgroundColor: "#f0f4ff"
134
154
  });
135
- q.textContent = String(a + 1);
136
- const B = c({
155
+ Z.textContent = String(a + 1);
156
+ const P = c({
137
157
  overflow: "hidden",
138
158
  textOverflow: "ellipsis",
139
159
  whiteSpace: "nowrap"
140
160
  });
141
- B.textContent = p.title, B.title = p.title, w.append(q, B), r.appendChild(w);
161
+ P.textContent = p.title, P.title = p.title, y.append(Z, P), r.appendChild(y);
142
162
  }), d.appendChild(r);
143
163
  }
144
- const h = c({
164
+ const b = c({
145
165
  maxWidth: t ? "75%" : "100%",
146
166
  padding: t ? "10px 14px" : "2px 8px",
147
- borderRadius: t ? "16px" : "0",
148
- backgroundColor: t ? "#03182f" : "transparent",
149
- color: t ? "#fff" : "#30373e",
167
+ borderRadius: t ? X : "0",
168
+ backgroundColor: t ? ne : "transparent",
169
+ color: t ? re : H,
150
170
  wordBreak: "break-word",
151
171
  fontSize: "14px",
152
172
  lineHeight: "1.6",
153
173
  whiteSpace: "pre-wrap"
154
174
  });
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) {
175
+ 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
176
  const r = c({
157
177
  display: "flex",
158
178
  flexWrap: "wrap",
@@ -162,19 +182,19 @@ function ue(s, n) {
162
182
  r.className = "ago-message__followups";
163
183
  for (const p of e.followUpReplies) {
164
184
  const a = document.createElement("button");
165
- a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !O, x(a, {
185
+ a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !j, m(a, {
166
186
  padding: "6px 14px",
167
187
  fontSize: "13px",
168
- borderRadius: "16px",
169
- border: "1px solid #dee3e8",
170
- backgroundColor: "#fff",
171
- color: "#30373e",
172
- cursor: O ? "pointer" : "default",
188
+ borderRadius: X,
189
+ border: `1px solid ${E}`,
190
+ backgroundColor: L,
191
+ color: H,
192
+ cursor: j ? "pointer" : "default",
173
193
  transition: "border-color 0.15s"
174
- }), $ && a.addEventListener("click", () => $(p)), a.addEventListener("mouseenter", () => {
175
- a.style.borderColor = "#1b5fc4";
194
+ }), V && a.addEventListener("click", () => V(p)), a.addEventListener("mouseenter", () => {
195
+ a.style.borderColor = K;
176
196
  }), a.addEventListener("mouseleave", () => {
177
- a.style.borderColor = "#dee3e8";
197
+ a.style.borderColor = E;
178
198
  }), r.appendChild(a);
179
199
  }
180
200
  d.appendChild(r);
@@ -182,17 +202,17 @@ function ue(s, n) {
182
202
  return d;
183
203
  }
184
204
  function S() {
185
- if (E.replaceChildren(), o.length === 0) {
205
+ if (R.replaceChildren(), n.length === 0) {
186
206
  const e = c({
187
207
  textAlign: "center",
188
- color: "#6b6d6f",
208
+ color: ve,
189
209
  padding: "24px 16px",
190
210
  fontSize: "14px",
191
211
  lineHeight: "1.5"
192
212
  });
193
- e.textContent = _, E.appendChild(e);
194
- } else for (const e of o) E.appendChild(Z(e));
195
- if (z) {
213
+ e.textContent = w, R.appendChild(e);
214
+ } else for (const e of n) R.appendChild(le(e));
215
+ if (N) {
196
216
  const e = c({
197
217
  padding: "10px 14px",
198
218
  backgroundColor: "#fef2f2",
@@ -202,47 +222,47 @@ function ue(s, n) {
202
222
  fontSize: "13px",
203
223
  border: "1px solid #fecaca"
204
224
  });
205
- e.textContent = z, E.appendChild(e);
225
+ e.textContent = N, R.appendChild(e);
206
226
  }
207
- E.scrollTop = E.scrollHeight, Q(k);
227
+ R.scrollTop = R.scrollHeight, se(_);
208
228
  }
209
- function ee() {
210
- for (let e = o.length - 1; e >= 0; e--) {
211
- const t = o[e];
229
+ function de() {
230
+ for (let e = n.length - 1; e >= 0; e--) {
231
+ const t = n[e];
212
232
  if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
213
233
  }
214
234
  }
215
- const P = (e) => {
216
- u || (u = e.conversationId);
217
- }, G = (e) => {
218
- const t = ee();
235
+ const q = (e) => {
236
+ h || (h = e.conversationId);
237
+ }, Y = (e) => {
238
+ const t = de();
219
239
  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?.({
240
+ }, J = (e) => {
241
+ const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
242
+ t >= 0 ? n[t] = e : n.push(e), _ = !1, S(), e.status === "DONE" && $?.({
223
243
  id: e.id,
224
244
  content: e.content
225
245
  });
226
- }, j = (e) => {
227
- z = e.error, k = !1, o = o.filter((t) => !t.id.startsWith("temp-")), S();
246
+ }, Q = (e) => {
247
+ N = e.error, _ = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
228
248
  };
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) {
249
+ l.on("message:start", q), l.on("message:chunk", Y), l.on("message:complete", J), l.on("message:error", Q);
250
+ const ce = (B ?? []).map((e) => ue(e).install(l));
251
+ async function F(e, t) {
232
252
  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 || "",
253
+ if (!d && !t?.length || _) return;
254
+ C?.(d), _ = !0, N = null;
255
+ const b = Date.now();
256
+ n.push({
257
+ id: `temp-user-${b}`,
258
+ conversationId: h || "",
239
259
  content: d,
240
260
  role: "user",
241
261
  status: "DONE",
242
262
  createdAt: /* @__PURE__ */ new Date()
243
- }), o.push({
244
- id: `temp-assistant-${h}`,
245
- conversationId: u || "",
263
+ }), n.push({
264
+ id: `temp-assistant-${b}`,
265
+ conversationId: h || "",
246
266
  content: "",
247
267
  role: "assistant",
248
268
  status: "IN_PROGRESS",
@@ -250,48 +270,48 @@ function ue(s, n) {
250
270
  }), S();
251
271
  try {
252
272
  const r = await l.sendMessage(d, {
253
- conversationId: u,
273
+ conversationId: h,
254
274
  files: t
255
275
  });
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);
276
+ r.conversationId && (h || (h = r.conversationId), I?.setActiveThread(r.conversationId, r.createdAt));
277
+ const p = n.find((a) => a.id === `temp-user-${b}`);
278
+ if (p && (p.id = `user-${b}`, p.conversationId = r.conversationId), !n.some((a) => a.id === r.id)) {
279
+ const a = n.findIndex((y) => y.id === `temp-assistant-${b}`);
280
+ a >= 0 ? n[a] = r : n.push(r);
261
281
  }
262
- o = o.filter((a) => !a.id.startsWith("temp-")), k = !1, S(), I && U();
282
+ n = n.filter((a) => !a.id.startsWith("temp-")), _ = !1, S(), D && G();
263
283
  } catch (r) {
264
- z = r instanceof Error ? r.message : "Failed to send message", k = !1, o = o.filter((p) => !p.id.startsWith("temp-")), S();
284
+ N = r instanceof Error ? r.message : "Failed to send message", _ = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
265
285
  }
266
286
  }
267
- async function U() {
287
+ async function G() {
268
288
  try {
269
289
  const e = await l.getConversations();
270
- T.splice(0, T.length, ...e);
290
+ M.splice(0, M.length, ...e);
271
291
  } catch {
272
292
  }
273
- return T;
293
+ return M;
274
294
  }
275
- async function ne(e) {
295
+ async function pe(e) {
276
296
  try {
277
297
  const t = (await l.getConversation(e))?.messages ?? [];
278
- t.length > 0 && o.length === 0 && (o = t, S());
298
+ t.length > 0 && n.length === 0 && (n = t, S());
279
299
  } catch {
280
- o.length === 0 && (D?.clear(), u = void 0);
300
+ n.length === 0 && (I?.clear(), h = void 0);
281
301
  }
282
302
  }
283
- return S(), X(), u && ne(u), I && U(), {
303
+ return S(), ie(), h && pe(h), D && G(), {
284
304
  client: l,
285
- element: W,
286
- sendMessage: H,
287
- session: D,
288
- threads: T,
289
- refreshThreads: U,
305
+ element: O,
306
+ sendMessage: F,
307
+ session: I,
308
+ threads: M,
309
+ refreshThreads: G,
290
310
  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();
311
+ l.off("message:start", q), l.off("message:chunk", Y), l.off("message:complete", J), l.off("message:error", Q), ce.forEach((e) => e()), O.remove(), o.client || l.destroy();
292
312
  }
293
313
  };
294
- function oe() {
314
+ function fe() {
295
315
  const e = c({
296
316
  display: "flex",
297
317
  gap: "4px",
@@ -311,108 +331,108 @@ function ue(s, n) {
311
331
  return e;
312
332
  }
313
333
  }
314
- function de(s) {
315
- let n = [];
316
- const v = document.createElement("form");
317
- x(v, {
334
+ function we(i) {
335
+ let o = [];
336
+ const g = document.createElement("form");
337
+ m(g, {
318
338
  display: "flex",
319
339
  flexDirection: "column",
320
340
  gap: "8px",
321
341
  padding: "12px",
322
- borderTop: "1px solid #dee3e8",
323
- backgroundColor: "#fff"
324
- }), v.className = "ago-chat-input";
325
- const _ = c({
342
+ borderTop: `1px solid ${E}`,
343
+ backgroundColor: L
344
+ }), g.className = "ago-chat-input";
345
+ const w = c({
326
346
  display: "flex",
327
347
  flexWrap: "wrap",
328
348
  gap: "6px"
329
- }), N = c({
349
+ }), T = c({
330
350
  display: "flex",
331
351
  gap: "8px",
332
352
  alignItems: "flex-end"
333
- }), g = document.createElement("textarea");
334
- g.placeholder = s.placeholder, g.rows = 1, x(g, {
353
+ }), u = document.createElement("textarea");
354
+ u.placeholder = i.placeholder, u.rows = 1, m(u, {
335
355
  flex: "1",
336
356
  resize: "none",
337
357
  padding: "10px 12px",
338
- border: "1px solid #dee3e8",
358
+ border: `1px solid ${E}`,
339
359
  borderRadius: "12px",
340
360
  fontSize: "14px",
341
- fontFamily: Y,
361
+ fontFamily: oe,
342
362
  lineHeight: "1.4",
343
363
  maxHeight: "120px",
344
364
  outline: "none"
345
365
  });
346
- const m = document.createElement("button");
347
- m.type = "submit", m.textContent = "Send", x(m, {
366
+ const x = document.createElement("button");
367
+ x.type = "submit", x.textContent = "Send", m(x, {
348
368
  padding: "10px 16px",
349
369
  border: "none",
350
370
  borderRadius: "12px",
351
- backgroundColor: "#03182f",
352
- color: "#fff",
371
+ backgroundColor: ne,
372
+ color: re,
353
373
  fontSize: "14px",
354
374
  fontWeight: "500",
355
375
  cursor: "pointer"
356
376
  });
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, {
377
+ let f = null, v = null;
378
+ 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
379
  padding: "10px 12px",
360
- border: "1px solid #dee3e8",
380
+ border: `1px solid ${E}`,
361
381
  borderRadius: "12px",
362
- backgroundColor: "#fff",
382
+ backgroundColor: L,
363
383
  cursor: "pointer",
364
384
  fontSize: "14px"
365
- }), b.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
366
- n = [...n, ...Array.from(f?.files ?? [])], I();
385
+ }), v.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
386
+ o = [...o, ...Array.from(f?.files ?? [])], A();
367
387
  }));
368
- function I() {
369
- _.replaceChildren(), n.forEach((i, C) => {
370
- const l = c({
388
+ function A() {
389
+ w.replaceChildren(), o.forEach((s, C) => {
390
+ const $ = c({
371
391
  display: "flex",
372
392
  alignItems: "center",
373
393
  gap: "4px",
374
394
  padding: "4px 8px",
375
395
  backgroundColor: "#f0f4ff",
376
- border: "1px solid #dee3e8",
396
+ border: `1px solid ${E}`,
377
397
  borderRadius: "8px",
378
398
  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, {
399
+ }), l = document.createElement("span");
400
+ l.textContent = s.name;
401
+ const k = document.createElement("button");
402
+ k.type = "button", k.textContent = "×", m(k, {
383
403
  border: "none",
384
404
  background: "transparent",
385
405
  cursor: "pointer",
386
406
  fontSize: "14px",
387
407
  lineHeight: "1"
388
- }), y.addEventListener("click", () => {
389
- n = n.filter((D, u) => u !== C), I();
390
- }), l.append(L, y), _.appendChild(l);
408
+ }), k.addEventListener("click", () => {
409
+ o = o.filter((U, I) => I !== C), A();
410
+ }), $.append(l, k), w.appendChild($);
391
411
  });
392
412
  }
393
- const A = () => {
394
- const i = g.value, C = n;
395
- return g.value = "", n = [], I(), {
396
- content: i,
413
+ const D = () => {
414
+ const s = u.value, C = o;
415
+ return u.value = "", o = [], A(), {
416
+ content: s,
397
417
  files: C
398
418
  };
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);
419
+ }, B = () => {
420
+ const { content: s, files: C } = D();
421
+ (s.trim() || C.length > 0) && i.onSend(s.trim(), C.length > 0 ? C : void 0);
402
422
  };
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";
423
+ return g.addEventListener("submit", (s) => {
424
+ s.preventDefault(), B();
425
+ }), u.addEventListener("keydown", (s) => {
426
+ s.key === "Enter" && !s.shiftKey && (s.preventDefault(), B());
427
+ }), v && T.appendChild(v), T.append(u, x), f && g.appendChild(f), g.append(w, T), {
428
+ inputRow: g,
429
+ getValueAndClear: D,
430
+ setDisabled: (s) => {
431
+ u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
412
432
  },
413
- focus: () => g.focus()
433
+ focus: () => u.focus()
414
434
  };
415
435
  }
416
436
  export {
417
- ue as mountChatWidget
437
+ _e as mountChatWidget
418
438
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useago/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "JavaScript SDK for AGO Chat integration",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1 +0,0 @@
1
- const I=require("./AgoClient-B6PsfMeg.cjs");function P(u,r){const m=r?r.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let c=u;if(r&&m)try{const a=m.getItem(r.key);a!=null&&(c=JSON.parse(a))}catch{}const o=new Set,h=()=>o.forEach(a=>a(c));function y(){if(r&&m)try{m.setItem(r.key,JSON.stringify(c))}catch{}}return{get:()=>c,set:a=>{c=a,y(),h()},subscribe:a=>(o.add(a),()=>{o.delete(a)})}}var O=/^[a-zA-Z0-9_-]{1,40}$/;function j(u){const{name:r,description:m,schema:c}=u;if(!O.test(r))throw new Error(`Invalid form collector name "${r}": must match ${O} (it becomes the update_/submit_ function names).`);const o=typeof u.submit=="string"?u.submit?{via:"client",url:u.submit}:!1:u.submit??!1,h=c.properties??{},y=c.required??[],a=e=>e==null||e==="",b=e=>y.filter(t=>a(e[t])),v=e=>{const t={};for(const[n,s]of Object.entries(e)){const i=h[n];if(i)if(s==null)t[n]=s;else if(i.type==="number"||i.type==="integer"){const g=typeof s=="number"?s:Number(s);t[n]=Number.isNaN(g)?s:g}else i.type==="boolean"?t[n]=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:!!s:t[n]=s}return t},f=u.initialValues??{},N=b(f),l=P({values:f,missing:N,complete:N.length===0,submitted:!1}),$=e=>{const t=l.get(),n={...t.values,...e},s=b(n),i={...t,values:n,missing:s,complete:s.length===0};return l.set(i),i};let d=null;const S=async()=>{const e=l.get();if(!e.complete)return{ok:!1,missing:e.missing};if(!o)return{ok:!1,error:"No submit target configured for this form collector."};const t=e.values;try{let n;if(o.via==="client")if("handler"in o)n=await o.handler(t);else{const s=await fetch(o.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!s.ok)return{ok:!1,error:`Submit failed: HTTP ${s.status}`};n=await s.json().catch(()=>{})}else{if(!d)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};n=await d.submitFormCollector(o.destination,t)}return l.set({...l.get(),submitted:!0}),{ok:!0,result:n}}catch(n){const s=n instanceof Error?n.message:"Submit failed";return I.logger.error(`FormCollector "${r}" submit failed:`,n),{ok:!1,error:s}}},_={name:`update_${r}`,description:`Fill or update fields of the "${r}" form. ${m} Pass any subset of fields; call it repeatedly to fill the form as the user provides information. Returns the current values and which required fields are still missing.`,parameters:{...c,required:[]},handler:e=>{const t=$(v(e));return{ok:!0,values:t.values,missing:t.missing,complete:t.complete}}},p=[_];o&&p.push({name:`submit_${r}`,description:`Submit the completed "${r}" form. Only call this once every required field is collected and the user has confirmed. If fields are missing it returns them instead of submitting.`,parameters:{type:"object",properties:{}},handler:()=>S()});const E="client__",k=o?`submit_${r}`:null,T=e=>{const t=e.functionName??e.toolName;if(t)return t.startsWith(E)?t.slice(8):t},w=e=>{let t={...f},n=!1;for(const i of e){const g=T(i);g===_.name?i.arguments&&(t={...t,...v(i.arguments)}):k&&g===k&&i.status?.toLowerCase()==="done"&&(n=!0)}const s=b(t);l.set({values:t,missing:s,complete:s.length===0,submitted:n})},C=`form:${r}`,F=()=>{const e=l.get(),t=o?` When all required fields are present and the user confirms, call submit_${r}.`:"";return{name:`Form: ${r}`,description:`Conversational form the assistant is helping fill. ${m} Use update_${r} to record fields; ask the user only for what is still missing.${t}`,data:{values:e.values,missing:e.missing,complete:e.complete,submitted:e.submitted}}},q=e=>{w((e.messages??[]).flatMap(t=>t.toolCalls??[]))};return{name:r,store:l,functions:p,contextKey:C,contextProvider:F,install:e=>{d=e;for(const t of p)e.register(t);return e.addDynamicContext(C,F),e.on("conversation:loaded",q),()=>{for(const t of p)e.unregisterFunction(t.name);e.removeDynamicContext(C),e.off("conversation:loaded",q),d===e&&(d=null)}},hydrate:w,submit:S,getValues:()=>l.get().values,setValues:e=>{$(v(e))},reset:()=>{const e=b(f);l.set({values:f,missing:e,complete:e.length===0,submitted:!1})}}}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return P}});
@@ -1 +0,0 @@
1
- function w(u={}){const{overrides:g={}}=u,d={id:"mock-msg-1",conversationId:"mock-conv-1",content:"Mock response",role:"assistant",status:"DONE",createdAt:new Date},l={id:"mock-conv-1",title:"Mock Conversation",lastMessageDate:new Date},t=new Map,a=[],m={sendMessage:async()=>d,getConversations:async()=>[l],getConversation:async()=>l,getMessages:async()=>[d],submitToolCallForm:async()=>{},confirmToolCall:async()=>{},rejectToolCall:async()=>{},submitFeedback:async()=>{},registerFunction:()=>{},unregisterFunction:()=>!0,getRegisteredFunctions:()=>[],getContextSnapshot:()=>null,registerNavigationFunction:()=>{},on:(e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)},off:(e,o)=>{t.get(e)?.delete(o)},once:(e,o)=>{const n=(...r)=>{t.get(e)?.delete(n),o(...r)};t.has(e)||t.set(e,new Set),t.get(e).add(n)},waitFor:(e,o)=>new Promise((n,r)=>{let i;const c=f=>{i&&clearTimeout(i),t.get(e)?.delete(c),n(f)};t.has(e)||t.set(e,new Set),t.get(e).add(c),o?.timeout&&(i=setTimeout(()=>{t.get(e)?.delete(c),r(new Error(`waitFor("${e}") timed out after ${o.timeout}ms`))},o.timeout))}),updateConfig:()=>{},destroy:()=>{t.clear()},...g},s={};for(const[e,o]of Object.entries(m))s[e]=(...n)=>(a.push({method:e,args:n}),o(...n));return s.__calls=a,s.__callsFor=e=>a.filter(o=>o.method===e),s.__emitEvent=(e,o)=>{const n=t.get(e);n&&[...n].forEach(r=>r(o))},s}Object.defineProperty(exports,"createMockClient",{enumerable:!0,get:function(){return w}});