@useago/sdk 1.4.2 → 1.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 (38) hide show
  1. package/README.md +4 -1
  2. package/dist/AgoClient-CMDVqNaH.cjs +8 -0
  3. package/dist/{AgoClient-BdtuHX7k.js → AgoClient-S8oeNnAE.js} +273 -157
  4. package/dist/angular.cjs +1 -1
  5. package/dist/angular.d.cts +121 -4
  6. package/dist/angular.d.ts +121 -4
  7. package/dist/angular.js +1 -1
  8. package/dist/{createConversationSession-B8zfTL78.cjs → createConversationSession-CmBq7uGi.cjs} +1 -1
  9. package/dist/{createConversationSession-CWpf4u6I.js → createConversationSession-DoUHdVNR.js} +1 -1
  10. package/dist/{createFormCollector-BB_l0Sia.cjs → createFormCollector-Bz_0IJ0Q.cjs} +1 -1
  11. package/dist/{createFormCollector-B4n0_diV.js → createFormCollector-vy-QvFja.js} +1 -1
  12. package/dist/createMockClient-BSr-UV8R.cjs +1 -0
  13. package/dist/{createMockClient-d-arlmCq.js → createMockClient-bAZ9KBHC.js} +18 -15
  14. package/dist/devtools.d.cts +120 -3
  15. package/dist/devtools.d.ts +120 -3
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.cts +132 -3
  18. package/dist/index.d.ts +132 -3
  19. package/dist/index.js +4 -4
  20. package/dist/react.cjs +3 -3
  21. package/dist/react.d.cts +134 -9
  22. package/dist/react.d.ts +134 -9
  23. package/dist/react.js +440 -429
  24. package/dist/testing.cjs +1 -1
  25. package/dist/testing.d.cts +120 -3
  26. package/dist/testing.d.ts +120 -3
  27. package/dist/testing.js +1 -1
  28. package/dist/vue.cjs +1 -1
  29. package/dist/vue.d.cts +127 -4
  30. package/dist/vue.d.ts +127 -4
  31. package/dist/vue.js +1 -1
  32. package/dist/widget.cjs +3 -3
  33. package/dist/widget.d.cts +120 -3
  34. package/dist/widget.d.ts +120 -3
  35. package/dist/widget.js +120 -120
  36. package/package.json +1 -1
  37. package/dist/AgoClient-CRAnT4qE.cjs +0 -8
  38. package/dist/createMockClient-ucPENDzz.cjs +0 -1
package/dist/react.js CHANGED
@@ -1,20 +1,20 @@
1
- import { a as J, i as j, o as V, s as Y, t as X } from "./AgoClient-BdtuHX7k.js";
2
- import { i as Q, n as Ne, r as H, t as O } from "./createFormCollector-B4n0_diV.js";
3
- import { t as _e } from "./createMockClient-d-arlmCq.js";
4
- import Z, { createContext as ee, useCallback as R, useContext as $, useEffect as C, useId as te, useMemo as N, useRef as A, useState as I, useSyncExternalStore as ne } from "react";
5
- import { Fragment as B, jsx as s, jsxs as M } from "react/jsx-runtime";
1
+ import { a as J, i as j, o as V, s as Y, t as X } from "./AgoClient-S8oeNnAE.js";
2
+ import { i as Q, n as Pe, r as O, t as $ } from "./createFormCollector-vy-QvFja.js";
3
+ import { t as _e } from "./createMockClient-bAZ9KBHC.js";
4
+ import Z, { createContext as ee, useCallback as R, useContext as G, useEffect as k, useId as te, useMemo as F, useRef as A, useState as M, useSyncExternalStore as ne } from "react";
5
+ import { Fragment as B, jsx as i, jsxs as N } from "react/jsx-runtime";
6
6
  import re from "react-markdown";
7
7
  import oe from "remark-gfm";
8
8
  function ae(e) {
9
- const [t, r] = I(!1), n = A(null), o = N(() => {
10
- if (n.current && (n.current.destroy(), n.current = null), !e) return null;
11
- const i = new X(e);
12
- return n.current = i, i;
9
+ const [n, r] = M(!1), t = A(null), o = F(() => {
10
+ if (t.current && (t.current.destroy(), t.current = null), !e) return null;
11
+ const s = new X(e);
12
+ return t.current = s, s;
13
13
  }, [e?.baseUrl, e?.widgetId]);
14
- return C(() => (r(!0), () => {
15
- n.current?.destroy(), n.current = null;
16
- }), [o]), C(() => {
17
- n.current && e && n.current.updateConfig({
14
+ return k(() => (r(!0), () => {
15
+ t.current?.destroy(), t.current = null;
16
+ }), [o]), k(() => {
17
+ t.current && e && t.current.updateConfig({
18
18
  agent: e.agent,
19
19
  defaultAgentId: e.defaultAgentId,
20
20
  permission: e.permission,
@@ -33,130 +33,136 @@ function ae(e) {
33
33
  e?.warnOnEmptyReply
34
34
  ]), {
35
35
  client: o,
36
- isReady: t
36
+ isReady: n
37
37
  };
38
38
  }
39
- var z = ee(null), He = ({ children: e, client: t, tools: r, helpers: n, pageContext: o, ...i }) => {
40
- const { client: c } = ae(t ? null : i), l = t || c;
41
- return C(() => {
39
+ var L = ee(null), He = ({ children: e, client: n, tools: r, helpers: t, pageContext: o, ...s }) => {
40
+ const { client: c } = ae(n ? null : s), l = n || c;
41
+ return k(() => {
42
42
  if (!(!r || r.length === 0)) {
43
43
  for (const g of r) l.register(g);
44
44
  return () => {
45
45
  for (const g of r) l.unregisterFunction(g.name);
46
46
  };
47
47
  }
48
- }, [l, r]), C(() => {
49
- if (!n) return;
48
+ }, [l, r]), k(() => {
49
+ if (!t) return;
50
50
  const g = [];
51
- return import("./functions-CApuQZ2b.js").then((u) => u.n).then((u) => {
52
- for (const [b, p] of Object.entries(n)) {
53
- const x = u[b];
54
- if (!x) {
55
- console.warn(`[AGO] Unknown helper: "${b}"`);
51
+ return import("./functions-CApuQZ2b.js").then((d) => d.n).then((d) => {
52
+ for (const [v, y] of Object.entries(t)) {
53
+ const I = d[v];
54
+ if (!I) {
55
+ console.warn(`[AGO] Unknown helper: "${v}"`);
56
56
  continue;
57
57
  }
58
- const h = p === !0 ? x : {
59
- ...x,
60
- handler: p
58
+ const f = y === !0 ? I : {
59
+ ...I,
60
+ handler: y
61
61
  };
62
- l.register(h), g.push(h.name);
62
+ l.register(f), g.push(f.name);
63
63
  }
64
64
  }), () => {
65
- for (const u of g) l.unregisterFunction(u);
65
+ for (const d of g) l.unregisterFunction(d);
66
66
  };
67
- }, [l, n]), C(() => {
67
+ }, [l, t]), k(() => {
68
68
  o === "auto" && l.enableAutoPageContext();
69
- }, [l, o]), /* @__PURE__ */ s(z.Provider, {
69
+ }, [l, o]), /* @__PURE__ */ i(L.Provider, {
70
70
  value: l,
71
71
  children: e
72
72
  });
73
73
  };
74
- function T() {
75
- const e = $(z);
74
+ function _() {
75
+ const e = G(L);
76
76
  if (!e) throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');
77
77
  return e;
78
78
  }
79
- function D() {
80
- return $(z);
79
+ function W() {
80
+ return G(L);
81
81
  }
82
- function U({ client: e, conversationId: t } = {}) {
83
- const r = D(), n = e || r;
84
- if (!n) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
85
- const [o, i] = I([]), [c, l] = I(t), [g, u] = I(!1), [b, p] = I(null);
86
- C(() => {
87
- t && t !== c && (l(t), x(t));
88
- }, [t]);
89
- const x = async (h) => {
82
+ function U({ client: e, conversationId: n } = {}) {
83
+ const r = W(), t = e || r;
84
+ if (!t) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
85
+ const [o, s] = M([]), [c, l] = M(n), [g, d] = M(!1), [v, y] = M(null);
86
+ k(() => {
87
+ n && n !== c && (l(n), I(n));
88
+ }, [n]);
89
+ const I = async (f) => {
90
90
  try {
91
- i((await n.getMessages(h)).filter((m) => !m.hidden));
91
+ s((await t.getMessages(f)).filter((m) => !m.hidden));
92
92
  } catch (m) {
93
- p(m instanceof Error ? m : /* @__PURE__ */ new Error("Failed to load messages"));
93
+ y(m instanceof Error ? m : /* @__PURE__ */ new Error("Failed to load messages"));
94
94
  }
95
95
  };
96
- return C(() => {
97
- const h = (f) => {
98
- c || l(f.conversationId), u(!0), i((d) => d.some((y) => y.role === "assistant" && y.status === "IN_PROGRESS") ? d : [...d, {
99
- id: f.messageId,
100
- conversationId: f.conversationId,
101
- content: "",
102
- role: "assistant",
103
- status: "IN_PROGRESS",
104
- createdAt: /* @__PURE__ */ new Date()
105
- }]);
106
- }, m = (f) => {
107
- i((d) => {
108
- const y = d[d.length - 1];
109
- return y && y.id === f.messageId ? [...d.slice(0, -1), {
110
- ...y,
111
- content: y.content + f.content
112
- }] : d;
96
+ return k(() => {
97
+ const f = (u) => u === "IN_PROGRESS" || u === "WAITING_CLIENT", m = (u) => {
98
+ c || l(u.conversationId), d(!0), s((p) => {
99
+ const b = p.findIndex((h) => h.id === u.messageId);
100
+ return b >= 0 ? p.map((h, D) => D === b ? {
101
+ ...h,
102
+ status: "IN_PROGRESS"
103
+ } : h) : p.some((h) => h.role === "assistant" && f(h.status)) ? p : [...p, {
104
+ id: u.messageId,
105
+ conversationId: u.conversationId,
106
+ content: "",
107
+ role: "assistant",
108
+ status: "IN_PROGRESS",
109
+ createdAt: /* @__PURE__ */ new Date()
110
+ }];
113
111
  });
114
- }, w = (f) => {
115
- i((d) => {
116
- let y = -1;
117
- for (let k = d.length - 1; k >= 0; k--) if (d[k].role === "assistant" && d[k].status === "IN_PROGRESS") {
118
- y = k;
112
+ }, S = (u) => {
113
+ s((p) => {
114
+ const b = p.findIndex((h) => h.id === u.messageId);
115
+ return b < 0 ? p : p.map((h, D) => D === b ? {
116
+ ...h,
117
+ content: h.content + u.content
118
+ } : h);
119
+ });
120
+ }, w = (u) => {
121
+ s((p) => {
122
+ let b = -1;
123
+ for (let h = p.length - 1; h >= 0; h--) if (p[h].role === "assistant" && f(p[h].status)) {
124
+ b = h;
119
125
  break;
120
126
  }
121
- return y < 0 ? d : [
122
- ...d.slice(0, y),
127
+ return b < 0 ? p : [
128
+ ...p.slice(0, b),
123
129
  {
124
- ...d[y],
125
- ...f
130
+ ...p[b],
131
+ ...u
126
132
  },
127
- ...d.slice(y + 1)
133
+ ...p.slice(b + 1)
128
134
  ];
129
135
  });
130
- }, v = (f) => {
131
- i((d) => {
132
- const y = d.findIndex((k) => k.id === f.id);
133
- return y >= 0 ? [
134
- ...d.slice(0, y),
135
- f,
136
- ...d.slice(y + 1)
137
- ] : [...d, f];
138
- }), u(!1);
139
- }, a = (f) => {
140
- p(new Error(f.error)), u(!1);
136
+ }, a = (u) => {
137
+ s((p) => {
138
+ const b = p.findIndex((h) => h.id === u.id);
139
+ return b >= 0 ? [
140
+ ...p.slice(0, b),
141
+ u,
142
+ ...p.slice(b + 1)
143
+ ] : [...p, u];
144
+ }), d(!1);
145
+ }, x = (u) => {
146
+ y(new Error(u.error)), d(!1);
141
147
  };
142
- return n.on("message:start", h), n.on("message:chunk", m), n.on("message:answer-complete", w), n.on("message:complete", v), n.on("message:error", a), () => {
143
- n.off("message:start", h), n.off("message:chunk", m), n.off("message:answer-complete", w), n.off("message:complete", v), n.off("message:error", a);
148
+ return t.on("message:start", m), t.on("message:chunk", S), t.on("message:answer-complete", w), t.on("message:complete", a), t.on("message:error", x), () => {
149
+ t.off("message:start", m), t.off("message:chunk", S), t.off("message:answer-complete", w), t.off("message:complete", a), t.off("message:error", x);
144
150
  };
145
- }, [n, c]), {
151
+ }, [t, c]), {
146
152
  messages: o,
147
153
  isLoading: g,
148
- error: b,
149
- sendMessage: R(async (h, m) => {
150
- u(!0), p(null);
151
- const w = {
154
+ error: v,
155
+ sendMessage: R(async (f, m) => {
156
+ d(!0), y(null);
157
+ const S = {
152
158
  id: `temp-${Date.now()}`,
153
159
  conversationId: c || "",
154
- content: h,
160
+ content: f,
155
161
  role: "user",
156
162
  status: "DONE",
157
163
  attachments: m && m.length > 0 ? j(m) : void 0,
158
164
  createdAt: /* @__PURE__ */ new Date()
159
- }, v = {
165
+ }, w = {
160
166
  id: `temp-assistant-${Date.now()}`,
161
167
  conversationId: c || "",
162
168
  content: "",
@@ -164,61 +170,61 @@ function U({ client: e, conversationId: t } = {}) {
164
170
  status: "IN_PROGRESS",
165
171
  createdAt: /* @__PURE__ */ new Date()
166
172
  };
167
- i((a) => [
173
+ s((a) => [
168
174
  ...a,
169
- w,
170
- v
175
+ S,
176
+ w
171
177
  ]);
172
178
  try {
173
- const a = await n.sendMessage(h, {
179
+ const a = await t.sendMessage(f, {
174
180
  conversationId: c,
175
181
  files: m
176
182
  });
177
- return a.conversationId && !c && l(a.conversationId), i((f) => {
178
- const d = f.filter((k) => !k.id.startsWith("temp-")), y = {
179
- ...w,
180
- id: w.id.replace("temp-", "user-"),
183
+ return a.conversationId && !c && l(a.conversationId), s((x) => {
184
+ const u = x.filter((b) => !b.id.startsWith("temp-")), p = {
185
+ ...S,
186
+ id: S.id.replace("temp-", "user-"),
181
187
  conversationId: a.conversationId
182
188
  };
183
- return d.some((k) => k.id === a.id) ? [...d, y].sort((k, _) => new Date(k.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
184
- ...d,
185
- y,
189
+ return u.some((b) => b.id === a.id) ? [...u, p].sort((b, h) => new Date(b.createdAt).getTime() - new Date(h.createdAt).getTime()) : [
190
+ ...u,
191
+ p,
186
192
  a
187
193
  ];
188
194
  }), a;
189
195
  } catch (a) {
190
- return p(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), u(!1), i((f) => f.filter((d) => !d.id.startsWith("temp-"))), null;
196
+ return y(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), d(!1), s((x) => x.filter((u) => !u.id.startsWith("temp-"))), null;
191
197
  }
192
- }, [n, c]),
198
+ }, [t, c]),
193
199
  clearMessages: R(() => {
194
- i([]), l(void 0), p(null);
200
+ s([]), l(void 0), y(null);
195
201
  }, []),
196
202
  conversationId: c
197
203
  };
198
204
  }
199
- var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: o = "" }) => {
200
- const [i, c] = I(""), [l, g] = I([]), u = A(null), b = A(null), p = R(() => {
201
- const a = b.current;
205
+ var se = ({ onSend: e, disabled: n = !1, placeholder: r = "Type a message...", allowFiles: t = !1, className: o = "" }) => {
206
+ const [s, c] = M(""), [l, g] = M([]), d = A(null), v = A(null), y = R(() => {
207
+ const a = v.current;
202
208
  if (!a) return;
203
- const f = 110;
204
- a.style.height = "auto", a.style.height = `${Math.min(a.scrollHeight + 2, f)}px`, a.style.overflowY = a.scrollHeight + 2 > f ? "auto" : "hidden";
205
- }, []), x = R((a) => {
206
- a.preventDefault(), (i.trim() || l.length > 0) && (e(i.trim(), l.length > 0 ? l : void 0), c(""), g([]), requestAnimationFrame(p));
209
+ const x = 110;
210
+ a.style.height = "auto", a.style.height = `${Math.min(a.scrollHeight + 2, x)}px`, a.style.overflowY = a.scrollHeight + 2 > x ? "auto" : "hidden";
211
+ }, []), I = R((a) => {
212
+ a.preventDefault(), (s.trim() || l.length > 0) && (e(s.trim(), l.length > 0 ? l : void 0), c(""), g([]), requestAnimationFrame(y));
207
213
  }, [
208
- i,
214
+ s,
209
215
  l,
210
216
  e,
211
- p
212
- ]), h = R((a) => {
213
- a.key === "Enter" && !a.shiftKey && (a.preventDefault(), x(a));
214
- }, [x]), m = R((a) => {
215
- const f = Array.from(a.target.files || []);
216
- g((d) => [...d, ...f]);
217
- }, []), w = R((a) => {
218
- g((f) => f.filter((d, y) => y !== a));
219
- }, []), v = i.trim() || l.length > 0;
220
- return /* @__PURE__ */ M("form", {
221
- onSubmit: x,
217
+ y
218
+ ]), f = R((a) => {
219
+ a.key === "Enter" && !a.shiftKey && (a.preventDefault(), I(a));
220
+ }, [I]), m = R((a) => {
221
+ const x = Array.from(a.target.files || []);
222
+ g((u) => [...u, ...x]);
223
+ }, []), S = R((a) => {
224
+ g((x) => x.filter((u, p) => p !== a));
225
+ }, []), w = s.trim() || l.length > 0;
226
+ return /* @__PURE__ */ N("form", {
227
+ onSubmit: I,
222
228
  className: `ago-chat-input ${o}`,
223
229
  style: {
224
230
  display: "flex",
@@ -228,14 +234,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
228
234
  borderTop: "1px solid #dee3e8",
229
235
  backgroundColor: "#fff"
230
236
  },
231
- children: [l.length > 0 && /* @__PURE__ */ s("div", {
237
+ children: [l.length > 0 && /* @__PURE__ */ i("div", {
232
238
  className: "ago-chat-input__files",
233
239
  style: {
234
240
  display: "flex",
235
241
  flexWrap: "wrap",
236
242
  gap: "6px"
237
243
  },
238
- children: l.map((a, f) => /* @__PURE__ */ M("div", {
244
+ children: l.map((a, x) => /* @__PURE__ */ N("div", {
239
245
  style: {
240
246
  display: "flex",
241
247
  alignItems: "center",
@@ -246,7 +252,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
246
252
  fontSize: "12px",
247
253
  color: "#30373e"
248
254
  },
249
- children: [/* @__PURE__ */ s("span", {
255
+ children: [/* @__PURE__ */ i("span", {
250
256
  style: {
251
257
  maxWidth: "120px",
252
258
  overflow: "hidden",
@@ -254,9 +260,9 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
254
260
  whiteSpace: "nowrap"
255
261
  },
256
262
  children: a.name
257
- }), /* @__PURE__ */ s("button", {
263
+ }), /* @__PURE__ */ i("button", {
258
264
  type: "button",
259
- onClick: () => w(f),
265
+ onClick: () => S(x),
260
266
  "aria-label": `Remove ${a.name}`,
261
267
  style: {
262
268
  border: "none",
@@ -269,47 +275,47 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
269
275
  },
270
276
  children: "×"
271
277
  })]
272
- }, f))
273
- }), /* @__PURE__ */ M("div", {
278
+ }, x))
279
+ }), /* @__PURE__ */ N("div", {
274
280
  style: {
275
281
  display: "flex",
276
282
  gap: "8px",
277
283
  alignItems: "flex-end"
278
284
  },
279
285
  children: [
280
- n && /* @__PURE__ */ M(B, { children: [/* @__PURE__ */ s("button", {
286
+ t && /* @__PURE__ */ N(B, { children: [/* @__PURE__ */ i("button", {
281
287
  type: "button",
282
- onClick: () => u.current?.click(),
283
- disabled: t,
288
+ onClick: () => d.current?.click(),
289
+ disabled: n,
284
290
  "aria-label": "Attach file",
285
291
  style: {
286
292
  padding: "8px",
287
293
  border: "1px solid #dee3e8",
288
294
  borderRadius: "8px",
289
295
  backgroundColor: "#fff",
290
- cursor: t ? "not-allowed" : "pointer",
296
+ cursor: n ? "not-allowed" : "pointer",
291
297
  color: "#6b6d6f",
292
298
  fontSize: "16px",
293
299
  lineHeight: 1
294
300
  },
295
301
  children: "+"
296
- }), /* @__PURE__ */ s("input", {
297
- ref: u,
302
+ }), /* @__PURE__ */ i("input", {
303
+ ref: d,
298
304
  type: "file",
299
305
  multiple: !0,
300
306
  onChange: m,
301
307
  style: { display: "none" }
302
308
  })] }),
303
- /* @__PURE__ */ s("textarea", {
304
- ref: b,
305
- value: i,
309
+ /* @__PURE__ */ i("textarea", {
310
+ ref: v,
311
+ value: s,
306
312
  onChange: (a) => {
307
- c(a.target.value), p();
313
+ c(a.target.value), y();
308
314
  },
309
- onKeyDown: h,
315
+ onKeyDown: f,
310
316
  placeholder: r,
311
317
  "aria-label": r,
312
- disabled: t,
318
+ disabled: n,
313
319
  rows: 1,
314
320
  style: {
315
321
  flex: 1,
@@ -335,16 +341,16 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
335
341
  a.currentTarget.style.borderColor = "#dee3e8";
336
342
  }
337
343
  }),
338
- /* @__PURE__ */ s("button", {
344
+ /* @__PURE__ */ i("button", {
339
345
  type: "submit",
340
- disabled: t || !v,
346
+ disabled: n || !w,
341
347
  style: {
342
348
  padding: "10px 18px",
343
349
  border: "none",
344
350
  borderRadius: "20px",
345
- backgroundColor: t || !v ? "#b5bfc8" : "#03182f",
351
+ backgroundColor: n || !w ? "#b5bfc8" : "#03182f",
346
352
  color: "#fff",
347
- cursor: t || !v ? "not-allowed" : "pointer",
353
+ cursor: n || !w ? "not-allowed" : "pointer",
348
354
  fontWeight: 500,
349
355
  fontSize: "16px",
350
356
  transition: "background-color 0.15s"
@@ -354,7 +360,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
354
360
  ]
355
361
  })]
356
362
  });
357
- }, ie = ({ href: e, children: t, ...r }) => /* @__PURE__ */ s("a", {
363
+ }, ie = ({ href: e, children: n, ...r }) => /* @__PURE__ */ i("a", {
358
364
  href: e,
359
365
  target: "_blank",
360
366
  rel: "noopener noreferrer",
@@ -363,53 +369,53 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
363
369
  textDecoration: "underline"
364
370
  },
365
371
  ...r,
366
- children: t
367
- }), le = ({ children: e, ...t }) => /* @__PURE__ */ s("p", {
372
+ children: n
373
+ }), le = ({ children: e, ...n }) => /* @__PURE__ */ i("p", {
368
374
  style: {
369
375
  margin: "0 0 8px 0",
370
376
  lineHeight: "1.6"
371
377
  },
372
- ...t,
378
+ ...n,
373
379
  children: e
374
- }), F = (e, t) => {
375
- const r = ({ children: n, ...o }) => Z.createElement(`h${e}`, {
380
+ }), P = (e, n) => {
381
+ const r = ({ children: t, ...o }) => Z.createElement(`h${e}`, {
376
382
  style: {
377
383
  margin: "16px 0 8px 0",
378
- fontSize: t,
384
+ fontSize: n,
379
385
  fontWeight: 600,
380
386
  lineHeight: "1.3"
381
387
  },
382
388
  ...o
383
- }, n);
389
+ }, t);
384
390
  return r.displayName = `MarkdownHeading${e}`, r;
385
- }, ce = ({ children: e, ...t }) => /* @__PURE__ */ s("ul", {
391
+ }, ce = ({ children: e, ...n }) => /* @__PURE__ */ i("ul", {
386
392
  style: {
387
393
  margin: "0 0 8px 0",
388
394
  paddingLeft: "20px",
389
395
  listStyleType: "disc",
390
396
  listStylePosition: "outside"
391
397
  },
392
- ...t,
398
+ ...n,
393
399
  children: e
394
- }), de = ({ children: e, ...t }) => /* @__PURE__ */ s("ol", {
400
+ }), de = ({ children: e, ...n }) => /* @__PURE__ */ i("ol", {
395
401
  style: {
396
402
  margin: "0 0 8px 0",
397
403
  paddingLeft: "20px",
398
404
  listStyleType: "decimal",
399
405
  listStylePosition: "outside"
400
406
  },
401
- ...t,
407
+ ...n,
402
408
  children: e
403
- }), ue = ({ children: e, ...t }) => /* @__PURE__ */ s("li", {
409
+ }), ue = ({ children: e, ...n }) => /* @__PURE__ */ i("li", {
404
410
  style: {
405
411
  display: "list-item",
406
412
  margin: "2px 0",
407
413
  lineHeight: "1.6"
408
414
  },
409
- ...t,
415
+ ...n,
410
416
  children: e
411
- }), fe = ({ className: e, children: t, ...r }) => e !== void 0 || String(t).includes(`
412
- `) ? /* @__PURE__ */ s("code", {
417
+ }), fe = ({ className: e, children: n, ...r }) => e !== void 0 || String(n).includes(`
418
+ `) ? /* @__PURE__ */ i("code", {
413
419
  style: {
414
420
  display: "block",
415
421
  background: "#f5f5f5",
@@ -420,8 +426,8 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
420
426
  fontFamily: '"IBM Plex Mono", monospace'
421
427
  },
422
428
  ...r,
423
- children: t
424
- }) : /* @__PURE__ */ s("code", {
429
+ children: n
430
+ }) : /* @__PURE__ */ i("code", {
425
431
  style: {
426
432
  background: "#f0f2f5",
427
433
  padding: "2px 5px",
@@ -430,12 +436,12 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
430
436
  fontFamily: '"IBM Plex Mono", monospace'
431
437
  },
432
438
  ...r,
433
- children: t
434
- }), ge = ({ children: e, ...t }) => /* @__PURE__ */ s("pre", {
439
+ children: n
440
+ }), ge = ({ children: e, ...n }) => /* @__PURE__ */ i("pre", {
435
441
  style: { margin: "0 0 8px 0" },
436
- ...t,
442
+ ...n,
437
443
  children: e
438
- }), pe = ({ children: e, ...t }) => /* @__PURE__ */ s("blockquote", {
444
+ }), pe = ({ children: e, ...n }) => /* @__PURE__ */ i("blockquote", {
439
445
  style: {
440
446
  borderLeft: "4px solid #dee3e8",
441
447
  paddingLeft: "12px",
@@ -443,23 +449,23 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
443
449
  fontStyle: "italic",
444
450
  color: "#6b6d6f"
445
451
  },
446
- ...t,
452
+ ...n,
447
453
  children: e
448
- }), me = ({ children: e, ...t }) => /* @__PURE__ */ s("div", {
454
+ }), me = ({ children: e, ...n }) => /* @__PURE__ */ i("div", {
449
455
  style: {
450
456
  overflowX: "auto",
451
457
  margin: "0 0 8px 0"
452
458
  },
453
- children: /* @__PURE__ */ s("table", {
459
+ children: /* @__PURE__ */ i("table", {
454
460
  style: {
455
461
  borderCollapse: "collapse",
456
462
  width: "100%",
457
463
  fontSize: "13px"
458
464
  },
459
- ...t,
465
+ ...n,
460
466
  children: e
461
467
  })
462
- }), he = ({ children: e, ...t }) => /* @__PURE__ */ s("th", {
468
+ }), he = ({ children: e, ...n }) => /* @__PURE__ */ i("th", {
463
469
  style: {
464
470
  border: "1px solid #dee3e8",
465
471
  padding: "6px 10px",
@@ -467,24 +473,24 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
467
473
  backgroundColor: "#f5f7fa",
468
474
  fontWeight: 600
469
475
  },
470
- ...t,
476
+ ...n,
471
477
  children: e
472
- }), xe = ({ children: e, ...t }) => /* @__PURE__ */ s("td", {
478
+ }), xe = ({ children: e, ...n }) => /* @__PURE__ */ i("td", {
473
479
  style: {
474
480
  border: "1px solid #dee3e8",
475
481
  padding: "6px 10px"
476
482
  },
477
- ...t,
483
+ ...n,
478
484
  children: e
479
- }), ye = ({ alt: e, ...t }) => /* @__PURE__ */ s("img", {
485
+ }), ye = ({ alt: e, ...n }) => /* @__PURE__ */ i("img", {
480
486
  alt: e ?? "",
481
487
  style: {
482
488
  maxWidth: "100%",
483
489
  borderRadius: "8px",
484
490
  margin: "4px 0"
485
491
  },
486
- ...t
487
- }), be = (e) => /* @__PURE__ */ s("hr", {
492
+ ...n
493
+ }), be = (e) => /* @__PURE__ */ i("hr", {
488
494
  style: {
489
495
  border: "none",
490
496
  borderTop: "1px solid #dee3e8",
@@ -494,12 +500,12 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
494
500
  }), ve = {
495
501
  a: ie,
496
502
  p: le,
497
- h1: F(1, "20px"),
498
- h2: F(2, "18px"),
499
- h3: F(3, "16px"),
500
- h4: F(4, "15px"),
501
- h5: F(5, "14px"),
502
- h6: F(6, "13px"),
503
+ h1: P(1, "20px"),
504
+ h2: P(2, "18px"),
505
+ h3: P(3, "16px"),
506
+ h4: P(4, "15px"),
507
+ h5: P(5, "14px"),
508
+ h6: P(6, "13px"),
503
509
  ul: ce,
504
510
  ol: de,
505
511
  li: ue,
@@ -511,13 +517,13 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
511
517
  td: xe,
512
518
  img: ye,
513
519
  hr: be
514
- }, we = [oe], Se = ({ content: e }) => /* @__PURE__ */ s(re, {
520
+ }, we = [oe], Se = ({ content: e }) => /* @__PURE__ */ i(re, {
515
521
  remarkPlugins: we,
516
522
  components: ve,
517
523
  children: e
518
- }), Ce = ({ attachment: e, isUser: t }) => {
524
+ }), Ce = ({ attachment: e, isUser: n }) => {
519
525
  const r = Y(e.url);
520
- if (J(e)) return /* @__PURE__ */ s("a", {
526
+ if (J(e)) return /* @__PURE__ */ i("a", {
521
527
  href: r,
522
528
  target: "_blank",
523
529
  rel: "noopener noreferrer",
@@ -525,7 +531,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
525
531
  display: "inline-block",
526
532
  textDecoration: "none"
527
533
  },
528
- children: /* @__PURE__ */ s("img", {
534
+ children: /* @__PURE__ */ i("img", {
529
535
  src: r,
530
536
  alt: e.name,
531
537
  loading: "lazy",
@@ -539,7 +545,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
539
545
  }
540
546
  })
541
547
  });
542
- const n = V(e.fileSize), o = /* @__PURE__ */ M(B, { children: [/* @__PURE__ */ s("span", {
548
+ const t = V(e.fileSize), o = /* @__PURE__ */ N(B, { children: [/* @__PURE__ */ i("span", {
543
549
  style: {
544
550
  fontSize: "16px",
545
551
  lineHeight: 1,
@@ -547,13 +553,13 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
547
553
  },
548
554
  "aria-hidden": !0,
549
555
  children: "📄"
550
- }), /* @__PURE__ */ M("span", {
556
+ }), /* @__PURE__ */ N("span", {
551
557
  style: {
552
558
  display: "flex",
553
559
  flexDirection: "column",
554
560
  minWidth: 0
555
561
  },
556
- children: [/* @__PURE__ */ s("span", {
562
+ children: [/* @__PURE__ */ i("span", {
557
563
  style: {
558
564
  overflow: "hidden",
559
565
  textOverflow: "ellipsis",
@@ -562,38 +568,38 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
562
568
  },
563
569
  title: e.name,
564
570
  children: e.name
565
- }), n && /* @__PURE__ */ s("span", {
571
+ }), t && /* @__PURE__ */ i("span", {
566
572
  style: {
567
573
  fontSize: "11px",
568
574
  color: "#6b6d6f"
569
575
  },
570
- children: n
576
+ children: t
571
577
  })]
572
- })] }), i = {
578
+ })] }), s = {
573
579
  display: "inline-flex",
574
580
  alignItems: "center",
575
581
  gap: "8px",
576
582
  padding: "8px 12px",
577
583
  borderRadius: "10px",
578
584
  border: "1px solid #dee3e8",
579
- backgroundColor: t ? "rgba(255,255,255,0.12)" : "#fff",
580
- color: t ? "#fff" : "#30373e",
585
+ backgroundColor: n ? "rgba(255,255,255,0.12)" : "#fff",
586
+ color: n ? "#fff" : "#30373e",
581
587
  fontSize: "13px",
582
588
  textDecoration: "none",
583
589
  maxWidth: "220px"
584
590
  };
585
- return r ? /* @__PURE__ */ s("a", {
591
+ return r ? /* @__PURE__ */ i("a", {
586
592
  href: r,
587
593
  target: "_blank",
588
594
  rel: "noopener noreferrer",
589
- style: i,
595
+ style: s,
590
596
  children: o
591
- }) : /* @__PURE__ */ s("div", {
592
- style: i,
597
+ }) : /* @__PURE__ */ i("div", {
598
+ style: s,
593
599
  children: o
594
600
  });
595
- }, ke = ({ source: e, index: t }) => {
596
- const r = /* @__PURE__ */ M("div", {
601
+ }, Ie = ({ source: e, index: n }) => {
602
+ const r = /* @__PURE__ */ N("div", {
597
603
  style: {
598
604
  display: "flex",
599
605
  alignItems: "center",
@@ -601,7 +607,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
601
607
  width: "100%",
602
608
  minWidth: 0
603
609
  },
604
- children: [/* @__PURE__ */ s("div", {
610
+ children: [/* @__PURE__ */ i("div", {
605
611
  style: {
606
612
  flexShrink: 0,
607
613
  width: "18px",
@@ -616,8 +622,8 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
616
622
  justifyContent: "center",
617
623
  backgroundColor: "#f0f4ff"
618
624
  },
619
- children: t + 1
620
- }), /* @__PURE__ */ s("div", {
625
+ children: n + 1
626
+ }), /* @__PURE__ */ i("div", {
621
627
  style: {
622
628
  fontSize: "12px",
623
629
  overflow: "hidden",
@@ -628,7 +634,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
628
634
  title: e.title,
629
635
  children: e.title
630
636
  })]
631
- }), n = {
637
+ }), t = {
632
638
  display: "flex",
633
639
  alignItems: "center",
634
640
  padding: "8px 10px",
@@ -641,11 +647,11 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
641
647
  minWidth: 0,
642
648
  transition: "border-color 0.15s"
643
649
  };
644
- return e.url ? /* @__PURE__ */ s("a", {
650
+ return e.url ? /* @__PURE__ */ i("a", {
645
651
  href: e.url,
646
652
  target: "_blank",
647
653
  rel: "noopener noreferrer",
648
- style: n,
654
+ style: t,
649
655
  onMouseEnter: (o) => {
650
656
  o.currentTarget.style.borderColor = "#1b5fc4";
651
657
  },
@@ -653,11 +659,11 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
653
659
  o.currentTarget.style.borderColor = "#dee3e8";
654
660
  },
655
661
  children: r
656
- }) : /* @__PURE__ */ s("div", {
657
- style: n,
662
+ }) : /* @__PURE__ */ i("div", {
663
+ style: t,
658
664
  children: r
659
665
  });
660
- }, Ie = () => /* @__PURE__ */ M("div", {
666
+ }, ke = () => /* @__PURE__ */ N("div", {
661
667
  style: {
662
668
  display: "flex",
663
669
  gap: "4px",
@@ -667,31 +673,31 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
667
673
  0,
668
674
  1,
669
675
  2
670
- ].map((e) => /* @__PURE__ */ s("div", { style: {
676
+ ].map((e) => /* @__PURE__ */ i("div", { style: {
671
677
  width: "6px",
672
678
  height: "6px",
673
679
  borderRadius: "50%",
674
680
  backgroundColor: "#b5bfc8",
675
681
  animation: "ago-pulse 1.2s ease-in-out infinite",
676
682
  animationDelay: `${e * 0.2}s`
677
- } }, e)), /* @__PURE__ */ s("style", { children: `
683
+ } }, e)), /* @__PURE__ */ i("style", { children: `
678
684
  @keyframes ago-pulse {
679
685
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
680
686
  40% { opacity: 1; transform: scale(1); }
681
687
  }
682
688
  ` })]
683
- }), Me = ({ message: e, className: t = "", showAgentName: r = !1, isLast: n = !1, onFollowUpClick: o }) => {
684
- const i = e.role === "user", c = e.status === "IN_PROGRESS";
685
- return /* @__PURE__ */ M("div", {
686
- className: `ago-message ago-message--${e.role} ${t}`,
689
+ }), Me = ({ message: e, className: n = "", showAgentName: r = !1, isLast: t = !1, onFollowUpClick: o }) => {
690
+ const s = e.role === "user", c = e.status === "IN_PROGRESS" || e.status === "WAITING_CLIENT";
691
+ return /* @__PURE__ */ N("div", {
692
+ className: `ago-message ago-message--${e.role} ${n}`,
687
693
  style: {
688
694
  display: "flex",
689
695
  flexDirection: "column",
690
- alignItems: i ? "flex-end" : "flex-start",
696
+ alignItems: s ? "flex-end" : "flex-start",
691
697
  marginBottom: "16px"
692
698
  },
693
699
  children: [
694
- !i && r && e.agent && /* @__PURE__ */ s("div", {
700
+ !s && r && e.agent && /* @__PURE__ */ i("div", {
695
701
  className: "ago-message__agent",
696
702
  style: {
697
703
  display: "flex",
@@ -705,7 +711,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
705
711
  },
706
712
  children: e.agent.displayName || e.agent.name
707
713
  }),
708
- !i && e.sources && e.sources.length > 0 && /* @__PURE__ */ s("div", {
714
+ !s && e.sources && e.sources.length > 0 && /* @__PURE__ */ i("div", {
709
715
  className: "ago-message__sources",
710
716
  style: {
711
717
  display: "grid",
@@ -715,41 +721,41 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
715
721
  width: "100%",
716
722
  maxWidth: "85%"
717
723
  },
718
- children: e.sources.map((l, g) => /* @__PURE__ */ s(ke, {
724
+ children: e.sources.map((l, g) => /* @__PURE__ */ i(Ie, {
719
725
  source: l,
720
726
  index: g
721
727
  }, l.id))
722
728
  }),
723
- e.attachments && e.attachments.length > 0 && /* @__PURE__ */ s("div", {
729
+ e.attachments && e.attachments.length > 0 && /* @__PURE__ */ i("div", {
724
730
  className: "ago-message__attachments",
725
731
  style: {
726
732
  display: "flex",
727
733
  flexWrap: "wrap",
728
734
  gap: "6px",
729
735
  marginBottom: "6px",
730
- justifyContent: i ? "flex-end" : "flex-start",
736
+ justifyContent: s ? "flex-end" : "flex-start",
731
737
  maxWidth: "75%"
732
738
  },
733
- children: e.attachments.map((l) => /* @__PURE__ */ s(Ce, {
739
+ children: e.attachments.map((l) => /* @__PURE__ */ i(Ce, {
734
740
  attachment: l,
735
- isUser: i
741
+ isUser: s
736
742
  }, l.id))
737
743
  }),
738
- (e.content || c) && /* @__PURE__ */ s("div", {
744
+ (e.content || c) && /* @__PURE__ */ i("div", {
739
745
  className: "ago-message__content",
740
746
  style: {
741
- maxWidth: i ? "75%" : "100%",
742
- padding: i ? "10px 14px" : "2px 8px",
743
- borderRadius: i ? "16px" : "0",
744
- backgroundColor: i ? "#03182f" : "transparent",
745
- color: i ? "#fff" : "#30373e",
747
+ maxWidth: s ? "75%" : "100%",
748
+ padding: s ? "10px 14px" : "2px 8px",
749
+ borderRadius: s ? "16px" : "0",
750
+ backgroundColor: s ? "#03182f" : "transparent",
751
+ color: s ? "#fff" : "#30373e",
746
752
  wordBreak: "break-word",
747
753
  fontSize: "16px",
748
754
  lineHeight: "1.6"
749
755
  },
750
- children: e.content ? /* @__PURE__ */ s(Se, { content: e.content }) : c && /* @__PURE__ */ s(Ie, {})
756
+ children: e.content ? /* @__PURE__ */ i(Se, { content: e.content }) : c && /* @__PURE__ */ i(ke, {})
751
757
  }),
752
- n && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ s("div", {
758
+ t && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ i("div", {
753
759
  className: "ago-message__followups",
754
760
  style: {
755
761
  display: "flex",
@@ -757,7 +763,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
757
763
  gap: "8px",
758
764
  marginTop: "10px"
759
765
  },
760
- children: e.followUpReplies.map((l, g) => /* @__PURE__ */ s("button", {
766
+ children: e.followUpReplies.map((l, g) => /* @__PURE__ */ i("button", {
761
767
  type: "button",
762
768
  className: "ago-message__followup-btn",
763
769
  disabled: !o,
@@ -773,52 +779,52 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
773
779
  cursor: o ? "pointer" : "default",
774
780
  transition: "border-color 0.15s"
775
781
  },
776
- onMouseEnter: (u) => {
777
- u.currentTarget.style.borderColor = "#1b5fc4";
782
+ onMouseEnter: (d) => {
783
+ d.currentTarget.style.borderColor = "#1b5fc4";
778
784
  },
779
- onMouseLeave: (u) => {
780
- u.currentTarget.style.borderColor = "#dee3e8";
785
+ onMouseLeave: (d) => {
786
+ d.currentTarget.style.borderColor = "#dee3e8";
781
787
  },
782
788
  children: l
783
789
  }, g))
784
790
  })
785
791
  ]
786
792
  });
787
- }, Oe = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: i = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: u, onFollowUpClick: b, className: p = "", onMessageSent: x, onMessageReceived: h }) => {
788
- const m = A(null), w = D(), v = e ?? w, { messages: a, isLoading: f, error: d, sendMessage: y } = U({
793
+ }, Oe = ({ client: e, conversationId: n, title: r = "Chat", welcomeMessage: t = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: s = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: d, onFollowUpClick: v, className: y = "", onMessageSent: I, onMessageReceived: f }) => {
794
+ const m = A(null), S = W(), w = e ?? S, { messages: a, isLoading: x, error: u, sendMessage: p } = U({
789
795
  client: e,
790
- conversationId: t
796
+ conversationId: n
791
797
  });
792
- C(() => {
793
- if (!v || !u || u.length === 0) return;
794
- let S = !1;
795
- const P = [];
796
- return Promise.all(u.map((E) => E.schema != null ? Promise.resolve(O(E)) : H(v, E))).then((E) => {
797
- if (!S)
798
- for (const G of E) P.push(G.install(v));
798
+ k(() => {
799
+ if (!w || !d || d.length === 0) return;
800
+ let C = !1;
801
+ const T = [];
802
+ return Promise.all(d.map((E) => E.schema != null ? Promise.resolve($(E)) : O(w, E))).then((E) => {
803
+ if (!C)
804
+ for (const q of E) T.push(q.install(w));
799
805
  }).catch(() => {
800
806
  }), () => {
801
- S = !0, P.forEach((E) => E());
807
+ C = !0, T.forEach((E) => E());
802
808
  };
803
- }, [v, u ? JSON.stringify(u.map((S) => [
804
- S.name,
805
- S.schema ?? null,
806
- S.submit ?? !1,
807
- S.description ?? null
808
- ])) : ""]), C(() => {
809
+ }, [w, d ? JSON.stringify(d.map((C) => [
810
+ C.name,
811
+ C.schema ?? null,
812
+ C.submit ?? !1,
813
+ C.description ?? null
814
+ ])) : ""]), k(() => {
809
815
  m.current?.scrollIntoView({ behavior: "smooth" });
810
- }, [a]), C(() => {
811
- const S = a[a.length - 1];
812
- S && S.role === "assistant" && S.status === "DONE" && h && h({
813
- id: S.id,
814
- content: S.content
816
+ }, [a]), k(() => {
817
+ const C = a[a.length - 1];
818
+ C && C.role === "assistant" && C.status === "DONE" && f && f({
819
+ id: C.id,
820
+ content: C.content
815
821
  });
816
- }, [a, h]);
817
- const k = async (S, P) => {
818
- x?.(S), await y(S, P);
819
- }, _ = a[a.length - 1], K = f && _?.role === "assistant" && _.status === "IN_PROGRESS", q = b === !1 ? void 0 : b ?? ((S) => k(S));
820
- return /* @__PURE__ */ M("div", {
821
- className: `ago-chat-widget ${p}`,
822
+ }, [a, f]);
823
+ const b = async (C, T) => {
824
+ I?.(C), await p(C, T);
825
+ }, h = a[a.length - 1], D = x && h?.role === "assistant" && (h.status === "IN_PROGRESS" || h.status === "WAITING_CLIENT"), K = v === !1 ? void 0 : v ?? ((C) => b(C));
826
+ return /* @__PURE__ */ N("div", {
827
+ className: `ago-chat-widget ${y}`,
822
828
  style: {
823
829
  display: "flex",
824
830
  flexDirection: "column",
@@ -832,7 +838,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
832
838
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
833
839
  },
834
840
  children: [
835
- /* @__PURE__ */ M("div", {
841
+ /* @__PURE__ */ N("div", {
836
842
  className: "ago-chat-widget__header",
837
843
  style: {
838
844
  padding: "14px 16px",
@@ -843,14 +849,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
843
849
  alignItems: "center",
844
850
  gap: "10px"
845
851
  },
846
- children: [l && /* @__PURE__ */ s("img", {
852
+ children: [l && /* @__PURE__ */ i("img", {
847
853
  src: l,
848
854
  alt: "Logo",
849
855
  style: {
850
856
  height: "24px",
851
857
  width: "auto"
852
858
  }
853
- }), /* @__PURE__ */ s("h3", {
859
+ }), /* @__PURE__ */ i("h3", {
854
860
  style: {
855
861
  margin: 0,
856
862
  fontSize: "15px",
@@ -859,7 +865,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
859
865
  children: r
860
866
  })]
861
867
  }),
862
- /* @__PURE__ */ M("div", {
868
+ /* @__PURE__ */ N("div", {
863
869
  className: "ago-chat-widget__messages",
864
870
  role: "log",
865
871
  "aria-live": "polite",
@@ -872,7 +878,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
872
878
  backgroundColor: "#fbfbfb"
873
879
  },
874
880
  children: [
875
- a.length === 0 ? /* @__PURE__ */ s("div", {
881
+ a.length === 0 ? /* @__PURE__ */ i("div", {
876
882
  style: {
877
883
  textAlign: "center",
878
884
  color: "#6b6d6f",
@@ -880,14 +886,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
880
886
  fontSize: "16px",
881
887
  lineHeight: "1.5"
882
888
  },
883
- children: n
884
- }) : a.map((S, P) => /* @__PURE__ */ s(Me, {
885
- message: S,
889
+ children: t
890
+ }) : a.map((C, T) => /* @__PURE__ */ i(Me, {
891
+ message: C,
886
892
  showAgentName: g,
887
- isLast: P === a.length - 1,
888
- onFollowUpClick: q
889
- }, S.id)),
890
- d && /* @__PURE__ */ s("div", {
893
+ isLast: T === a.length - 1,
894
+ onFollowUpClick: K
895
+ }, C.id)),
896
+ u && /* @__PURE__ */ i("div", {
891
897
  role: "alert",
892
898
  style: {
893
899
  padding: "10px 14px",
@@ -898,73 +904,73 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
898
904
  fontSize: "13px",
899
905
  border: "1px solid #fecaca"
900
906
  },
901
- children: d.message
907
+ children: u.message
902
908
  }),
903
- /* @__PURE__ */ s("div", { ref: m })
909
+ /* @__PURE__ */ i("div", { ref: m })
904
910
  ]
905
911
  }),
906
- /* @__PURE__ */ s(se, {
907
- onSend: k,
908
- disabled: K,
912
+ /* @__PURE__ */ i(se, {
913
+ onSend: b,
914
+ disabled: D,
909
915
  placeholder: o,
910
- allowFiles: i
916
+ allowFiles: s
911
917
  })
912
918
  ]
913
919
  });
914
920
  };
915
- function Re({ client: e, autoLoad: t = !0 } = {}) {
916
- const r = D(), n = e || r;
917
- if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
918
- const [o, i] = I([]), [c, l] = I(null), [g, u] = I(!1), [b, p] = I(null), x = R(async () => {
919
- u(!0), p(null);
921
+ function Ne({ client: e, autoLoad: n = !0 } = {}) {
922
+ const r = W(), t = e || r;
923
+ if (!t) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
924
+ const [o, s] = M([]), [c, l] = M(null), [g, d] = M(!1), [v, y] = M(null), I = R(async () => {
925
+ d(!0), y(null);
920
926
  try {
921
- i(await n.getConversations());
922
- } catch (w) {
923
- p(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversations"));
927
+ s(await t.getConversations());
928
+ } catch (S) {
929
+ y(S instanceof Error ? S : /* @__PURE__ */ new Error("Failed to load conversations"));
924
930
  } finally {
925
- u(!1);
931
+ d(!1);
926
932
  }
927
- }, [n]), h = R(async (w) => {
928
- u(!0), p(null);
933
+ }, [t]), f = R(async (S) => {
934
+ d(!0), y(null);
929
935
  try {
930
- l(await n.getConversation(w));
931
- } catch (v) {
932
- p(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversation"));
936
+ l(await t.getConversation(S));
937
+ } catch (w) {
938
+ y(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversation"));
933
939
  } finally {
934
- u(!1);
940
+ d(!1);
935
941
  }
936
- }, [n]), m = R(() => {
942
+ }, [t]), m = R(() => {
937
943
  l(null);
938
944
  }, []);
939
- return C(() => {
940
- t && x();
941
- }, [t, x]), {
945
+ return k(() => {
946
+ n && I();
947
+ }, [n, I]), {
942
948
  conversations: o,
943
949
  currentConversation: c,
944
950
  isLoading: g,
945
- error: b,
946
- selectConversation: h,
951
+ error: v,
952
+ selectConversation: f,
947
953
  startNewConversation: m,
948
- refreshConversations: x
954
+ refreshConversations: I
949
955
  };
950
956
  }
951
957
  function $e(e = {}) {
952
- const t = D(), r = e.client || t;
958
+ const n = W(), r = e.client || n;
953
959
  if (!r) throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
954
- const n = U({
960
+ const t = U({
955
961
  client: r,
956
962
  conversationId: e.conversationId
957
- }), o = Re({
963
+ }), o = Ne({
958
964
  client: r,
959
965
  autoLoad: e.autoLoad
960
966
  });
961
967
  return {
962
- messages: n.messages,
963
- isLoading: n.isLoading,
964
- error: n.error || o.error,
965
- sendMessage: n.sendMessage,
966
- clearMessages: n.clearMessages,
967
- conversationId: n.conversationId,
968
+ messages: t.messages,
969
+ isLoading: t.isLoading,
970
+ error: t.error || o.error,
971
+ sendMessage: t.sendMessage,
972
+ clearMessages: t.clearMessages,
973
+ conversationId: t.conversationId,
968
974
  conversations: o.conversations,
969
975
  currentConversation: o.currentConversation,
970
976
  isConversationsLoading: o.isLoading,
@@ -973,36 +979,36 @@ function $e(e = {}) {
973
979
  refreshConversations: o.refreshConversations
974
980
  };
975
981
  }
976
- function Be(e, t) {
977
- const r = T(), { name: n, description: o, parameters: i, handler: c } = typeof e == "string" ? {
982
+ function Ge(e, n) {
983
+ const r = _(), { name: t, description: o, parameters: s, handler: c } = typeof e == "string" ? {
978
984
  name: e,
979
- ...t
985
+ ...n
980
986
  } : e, l = A(c);
981
- l.current = c, C(() => {
982
- const g = (u) => l.current(u);
983
- return r.registerFunction(n, g, {
987
+ l.current = c, k(() => {
988
+ const g = (d) => l.current(d);
989
+ return r.registerFunction(t, g, {
984
990
  description: o,
985
- parameters: i
991
+ parameters: s
986
992
  }), () => {
987
- r.unregisterFunction(n);
993
+ r.unregisterFunction(t);
988
994
  };
989
995
  }, [
990
996
  r,
991
- n,
997
+ t,
992
998
  o,
993
- i
999
+ s
994
1000
  ]);
995
1001
  }
996
- function Ue(e, t) {
997
- const r = T(), n = A(e);
998
- n.current = e, C(() => (r.registerNavigationFunction((o) => n.current(o), t), () => {
1002
+ function Be(e, n) {
1003
+ const r = _(), t = A(e);
1004
+ t.current = e, k(() => (r.registerNavigationFunction((o) => t.current(o), n), () => {
999
1005
  r.unregisterNavigationFunction();
1000
- }), [r, t]);
1006
+ }), [r, n]);
1001
1007
  }
1002
- function Ke(e, t) {
1003
- const r = T(), n = t?.functionName ?? "setPageState", o = A(e);
1004
- o.current = e, C(() => {
1005
- const i = o.current.map((c) => {
1008
+ function Ue(e, n) {
1009
+ const r = _(), t = n?.functionName ?? "setPageState", o = A(e);
1010
+ o.current = e, k(() => {
1011
+ const s = o.current.map((c) => {
1006
1012
  const l = () => o.current.find((g) => g.name === c.name) ?? c;
1007
1013
  return {
1008
1014
  name: c.name,
@@ -1012,81 +1018,86 @@ function Ke(e, t) {
1012
1018
  set: (g) => l().set(g)
1013
1019
  };
1014
1020
  });
1015
- return r.registerPageStateFunction(i, { functionName: n }), () => {
1016
- r.unregisterPageStateFunction(n);
1021
+ return r.registerPageStateFunction(s, { functionName: t }), () => {
1022
+ r.unregisterPageStateFunction(t);
1017
1023
  };
1018
- }, [r, n]);
1024
+ }, [r, t]);
1019
1025
  }
1020
- var Ae = "You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";
1021
- function L(e) {
1026
+ var Re = "You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";
1027
+ function z(e) {
1022
1028
  return {
1023
1029
  navigationFunctions: e?.navigationFunctions ?? ["navigateToPage"],
1024
1030
  pageStateFunctionName: e?.pageStateFunctionName ?? "setPageState",
1025
- continuationPrompt: e?.continuationPrompt ?? Ae,
1031
+ continuationPrompt: e?.continuationPrompt ?? Re,
1026
1032
  maxDepth: e?.maxDepth ?? 1,
1027
1033
  readinessTimeoutMs: e?.readinessTimeoutMs ?? 4e3,
1028
1034
  settleMs: e?.settleMs ?? 150,
1029
1035
  enabled: e?.enabled ?? !0
1030
1036
  };
1031
1037
  }
1032
- function qe(e) {
1033
- const t = T(), r = A(L(e));
1034
- r.current = L(e), C(() => {
1035
- const n = {
1038
+ function Ke(e) {
1039
+ const n = _(), r = A(z(e));
1040
+ r.current = z(e), k(() => {
1041
+ const t = {
1036
1042
  navigated: !1,
1043
+ pausedTurnNavigated: !1,
1037
1044
  depth: 0,
1038
1045
  runId: 0,
1039
1046
  ourSendPending: !1
1040
- }, o = () => t.getRegisteredFunctions().some((p) => p.name === r.current.pageStateFunctionName), i = (p) => new Promise((x) => {
1041
- let h = !1;
1042
- const m = (f) => {
1043
- h || (h = !0, clearTimeout(a), t.off("context:changed", v), x(f));
1044
- }, w = () => setTimeout(() => m(p === n.runId && o()), r.current.settleMs), v = () => {
1045
- if (p !== n.runId) return m(!1);
1046
- o() && (t.off("context:changed", v), w());
1047
- }, a = setTimeout(() => m(!1), r.current.readinessTimeoutMs);
1048
- o() ? w() : t.on("context:changed", v);
1049
- }), c = async (p) => {
1050
- const x = ++n.runId;
1051
- if (!(!await i(x) || x !== n.runId)) {
1052
- n.depth += 1, n.ourSendPending = !0;
1047
+ }, o = () => n.getRegisteredFunctions().some((f) => f.name === r.current.pageStateFunctionName), s = (f) => new Promise((m) => {
1048
+ let S = !1;
1049
+ const w = (p) => {
1050
+ S || (S = !0, clearTimeout(u), n.off("context:changed", x), m(p));
1051
+ }, a = () => setTimeout(() => w(f === t.runId && o()), r.current.settleMs), x = () => {
1052
+ if (f !== t.runId) return w(!1);
1053
+ o() && (n.off("context:changed", x), a());
1054
+ }, u = setTimeout(() => w(!1), r.current.readinessTimeoutMs);
1055
+ o() ? a() : n.on("context:changed", x);
1056
+ }), c = async (f) => {
1057
+ const m = ++t.runId;
1058
+ if (!(!await s(m) || m !== t.runId)) {
1059
+ t.depth += 1, t.ourSendPending = !0;
1053
1060
  try {
1054
- await t.sendMessage(r.current.continuationPrompt, {
1055
- conversationId: p,
1061
+ await n.sendMessage(r.current.continuationPrompt, {
1062
+ conversationId: f,
1056
1063
  hidden: !0
1057
1064
  });
1058
1065
  } catch {
1059
- n.ourSendPending = !1;
1066
+ t.ourSendPending = !1;
1060
1067
  }
1061
1068
  }
1062
- }, l = (p) => {
1063
- r.current.navigationFunctions.includes(p.functionName) && (n.navigated = !0);
1064
- }, g = () => {
1065
- n.ourSendPending || (n.depth = 0, n.runId += 1);
1066
- }, u = (p) => {
1067
- n.ourSendPending = !1;
1068
- const x = n.navigated;
1069
- n.navigated = !1, r.current.enabled && x && (n.depth >= r.current.maxDepth || c(p.conversationId));
1070
- }, b = () => {
1071
- n.ourSendPending = !1;
1069
+ }, l = (f) => {
1070
+ r.current.navigationFunctions.includes(f.functionName) && (t.navigated = !0);
1071
+ }, g = n.registerResumeGate(async () => {
1072
+ r.current.enabled && t.pausedTurnNavigated && (t.pausedTurnNavigated = !1, await s(++t.runId));
1073
+ }), d = () => {
1074
+ t.pausedTurnNavigated = t.navigated, t.navigated = !1;
1075
+ }, v = () => {
1076
+ t.ourSendPending || (t.depth = 0, t.runId += 1);
1077
+ }, y = (f) => {
1078
+ t.ourSendPending = !1;
1079
+ const m = t.navigated;
1080
+ t.navigated = !1, r.current.enabled && m && (t.depth >= r.current.maxDepth || c(f.conversationId));
1081
+ }, I = () => {
1082
+ t.ourSendPending = !1;
1072
1083
  };
1073
- return t.on("function:invoke", l), t.on("message:start", g), t.on("message:complete", u), t.on("message:error", b), () => {
1074
- n.runId += 1, t.off("function:invoke", l), t.off("message:start", g), t.off("message:complete", u), t.off("message:error", b);
1084
+ return n.on("function:invoke", l), n.on("message:start", v), n.on("message:waiting-client", d), n.on("message:complete", y), n.on("message:error", I), () => {
1085
+ t.runId += 1, g(), n.off("function:invoke", l), n.off("message:start", v), n.off("message:waiting-client", d), n.off("message:complete", y), n.off("message:error", I);
1075
1086
  };
1076
- }, [t]);
1087
+ }, [n]);
1077
1088
  }
1078
- function Ge(e, t) {
1079
- const r = T(), n = te(), o = t ?? n, i = A(e);
1080
- i.current = e;
1089
+ function qe(e, n) {
1090
+ const r = _(), t = te(), o = n ?? t, s = A(e);
1091
+ s.current = e;
1081
1092
  const c = typeof e == "function";
1082
- C(() => {
1083
- if (typeof i.current == "function") {
1084
- const l = () => i.current();
1093
+ k(() => {
1094
+ if (typeof s.current == "function") {
1095
+ const l = () => s.current();
1085
1096
  return r.addDynamicContext(o, l), () => {
1086
1097
  r.removeDynamicContext(o);
1087
1098
  };
1088
1099
  }
1089
- return r.setContext(o, i.current), () => {
1100
+ return r.setContext(o, s.current), () => {
1090
1101
  r.removeContext(o);
1091
1102
  };
1092
1103
  }, [
@@ -1096,70 +1107,70 @@ function Ge(e, t) {
1096
1107
  c ? "" : JSON.stringify(e)
1097
1108
  ]);
1098
1109
  }
1099
- function Ee(e) {
1110
+ function Ae(e) {
1100
1111
  return ne(e.subscribe, e.get, e.get);
1101
1112
  }
1102
- var W = {
1113
+ var H = {
1103
1114
  missing: [],
1104
1115
  complete: !1
1105
1116
  };
1106
1117
  function Je(e) {
1107
- const t = T(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), o = e.submit, i = o ? typeof o == "string" ? `client:${o}` : o.via === "backend" ? "backend" : "handler" in o ? "client:handler" : `client:${o.url}` : "none", c = JSON.stringify(e.initialValues ?? null), l = N(() => r ? O(e) : null, [
1118
+ const n = _(), r = e.schema != null, t = JSON.stringify(e.schema ?? null), o = e.submit, s = o ? typeof o == "string" ? `client:${o}` : o.via === "backend" ? "backend" : "handler" in o ? "client:handler" : `client:${o.url}` : "none", c = JSON.stringify(e.initialValues ?? null), l = F(() => r ? $(e) : null, [
1108
1119
  r,
1109
1120
  e.name,
1110
- n,
1111
- i,
1121
+ t,
1122
+ s,
1112
1123
  c,
1113
1124
  e.autoSubmit
1114
- ]), [g, u] = I({
1125
+ ]), [g, d] = M({
1115
1126
  collector: null,
1116
1127
  loading: !r,
1117
1128
  error: null
1118
1129
  });
1119
- C(() => {
1130
+ k(() => {
1120
1131
  if (r) return;
1121
- let f = !1;
1122
- return u({
1132
+ let x = !1;
1133
+ return d({
1123
1134
  collector: null,
1124
1135
  loading: !0,
1125
1136
  error: null
1126
- }), H(t, e).then((d) => {
1127
- f || u({
1128
- collector: d,
1137
+ }), O(n, e).then((u) => {
1138
+ x || d({
1139
+ collector: u,
1129
1140
  loading: !1,
1130
1141
  error: null
1131
1142
  });
1132
- }).catch((d) => {
1133
- f || u({
1143
+ }).catch((u) => {
1144
+ x || d({
1134
1145
  collector: null,
1135
1146
  loading: !1,
1136
- error: d instanceof Error ? d : new Error(String(d))
1147
+ error: u instanceof Error ? u : new Error(String(u))
1137
1148
  });
1138
1149
  }), () => {
1139
- f = !0;
1150
+ x = !0;
1140
1151
  };
1141
1152
  }, [
1142
- t,
1153
+ n,
1143
1154
  r,
1144
1155
  e.name,
1145
- i,
1156
+ s,
1146
1157
  c,
1147
1158
  e.autoSubmit
1148
1159
  ]);
1149
- const b = r ? l : g.collector, p = r ? !1 : g.loading, x = r ? null : g.error;
1150
- C(() => {
1151
- if (b)
1152
- return b.install(t);
1153
- }, [t, b]);
1154
- const h = N(() => Q({
1160
+ const v = r ? l : g.collector, y = r ? !1 : g.loading, I = r ? null : g.error;
1161
+ k(() => {
1162
+ if (v)
1163
+ return v.install(n);
1164
+ }, [n, v]);
1165
+ const f = F(() => Q({
1155
1166
  values: e.initialValues ?? {},
1156
1167
  submitted: !1
1157
- }), [c]), m = Ee(b?.store ?? h), w = N(() => b?.getStatus() ?? W, [m, b]), v = N(() => ({
1168
+ }), [c]), m = Ae(v?.store ?? f), S = F(() => v?.getStatus() ?? H, [m, v]), w = F(() => ({
1158
1169
  ...m,
1159
- ...w
1160
- }), [m, w]), a = N(() => ({
1170
+ ...S
1171
+ }), [m, S]), a = F(() => ({
1161
1172
  name: e.name,
1162
- store: h,
1173
+ store: f,
1163
1174
  functions: [],
1164
1175
  contextKey: `form:${e.name}`,
1165
1176
  contextProvider: () => ({
@@ -1174,18 +1185,18 @@ function Je(e) {
1174
1185
  ok: !1,
1175
1186
  error: "Form definition not loaded yet."
1176
1187
  }),
1177
- getValues: () => h.get().values,
1188
+ getValues: () => f.get().values,
1178
1189
  setValues: () => {
1179
1190
  },
1180
1191
  reset: () => {
1181
1192
  },
1182
- getStatus: () => W
1183
- }), [e.name, h]);
1193
+ getStatus: () => H
1194
+ }), [e.name, f]);
1184
1195
  return {
1185
- ...b ?? a,
1186
- state: v,
1187
- loading: p,
1188
- error: x
1196
+ ...v ?? a,
1197
+ state: w,
1198
+ loading: y,
1199
+ error: I
1189
1200
  };
1190
1201
  }
1191
1202
  export {
@@ -1194,21 +1205,21 @@ export {
1194
1205
  Oe as ChatWidget,
1195
1206
  Se as Markdown,
1196
1207
  Me as Message,
1197
- O as createFormCollector,
1208
+ $ as createFormCollector,
1198
1209
  _e as createMockClient,
1199
- Ne as deriveFormStatus,
1200
- H as loadFormCollector,
1210
+ Pe as deriveFormStatus,
1211
+ O as loadFormCollector,
1201
1212
  ae as useAgo,
1202
- qe as useAgoAutoContinueAfterNavigation,
1203
- T as useAgoClient,
1204
- Ge as useAgoContext,
1205
- Be as useAgoFunction,
1206
- Ue as useAgoNavigation,
1207
- Ke as useAgoPageState,
1208
- Ee as useAgoStore,
1213
+ Ke as useAgoAutoContinueAfterNavigation,
1214
+ _ as useAgoClient,
1215
+ qe as useAgoContext,
1216
+ Ge as useAgoFunction,
1217
+ Be as useAgoNavigation,
1218
+ Ue as useAgoPageState,
1219
+ Ae as useAgoStore,
1209
1220
  $e as useChat,
1210
- Re as useConversation,
1221
+ Ne as useConversation,
1211
1222
  Je as useFormCollector,
1212
1223
  U as useMessages,
1213
- D as useOptionalAgoClient
1224
+ W as useOptionalAgoClient
1214
1225
  };