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