@useago/sdk 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,19 +1,19 @@
1
- import { t as J } from "./AgoClient-QcTtrN7u.js";
2
- import { i as q, n as Me, r as z, t as H } from "./createFormCollector-CFt1_QSL.js";
3
- import { t as Ee } from "./createMockClient-DwdxNwEn.js";
4
- import G, { createContext as V, useCallback as E, useContext as O, useEffect as S, useId as j, useMemo as F, useRef as T, useState as M, useSyncExternalStore as X } from "react";
5
- import { Fragment as Y, jsx as s, jsxs as I } from "react/jsx-runtime";
1
+ import { t as q } from "./AgoClient-QcTtrN7u.js";
2
+ import { i as J, n as Me, r as z, t as W } from "./createFormCollector-CFt1_QSL.js";
3
+ import { t as Re } from "./createMockClient-DwdxNwEn.js";
4
+ import G, { createContext as V, useCallback as I, useContext as $, useEffect as k, useId as j, useMemo as T, useRef as A, useState as M, useSyncExternalStore as Y } from "react";
5
+ import { Fragment as X, jsx as a, jsxs as R } from "react/jsx-runtime";
6
6
  import Q from "react-markdown";
7
7
  import Z from "remark-gfm";
8
8
  function ee(e) {
9
- const [t, r] = M(!1), n = T(null), o = F(() => {
9
+ const [t, r] = M(!1), n = A(null), s = T(() => {
10
10
  if (n.current && (n.current.destroy(), n.current = null), !e) return null;
11
- const a = new J(e);
12
- return n.current = a, a;
11
+ const i = new q(e);
12
+ return n.current = i, i;
13
13
  }, [e?.baseUrl, e?.widgetId]);
14
- return S(() => (r(!0), () => {
14
+ return k(() => (r(!0), () => {
15
15
  n.current?.destroy(), n.current = null;
16
- }), [o]), S(() => {
16
+ }), [s]), k(() => {
17
17
  n.current && e && n.current.updateConfig({
18
18
  agent: e.agent,
19
19
  defaultAgentId: e.defaultAgentId,
@@ -32,180 +32,186 @@ function ee(e) {
32
32
  e?.debug,
33
33
  e?.warnOnEmptyReply
34
34
  ]), {
35
- client: o,
35
+ client: s,
36
36
  isReady: t
37
37
  };
38
38
  }
39
- var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageContext: o, ...a }) => {
40
- const { client: d } = ee(t ? null : a), i = t || d;
41
- return S(() => {
39
+ var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageContext: s, ...i }) => {
40
+ const { client: u } = ee(t ? null : i), l = t || u;
41
+ return k(() => {
42
42
  if (!(!r || r.length === 0)) {
43
- for (const f of r) i.register(f);
43
+ for (const f of r) l.register(f);
44
44
  return () => {
45
- for (const f of r) i.unregisterFunction(f.name);
45
+ for (const f of r) l.unregisterFunction(f.name);
46
46
  };
47
47
  }
48
- }, [i, r]), S(() => {
48
+ }, [l, r]), k(() => {
49
49
  if (!n) return;
50
50
  const f = [];
51
- return import("./functions-CApuQZ2b.js").then((c) => c.n).then((c) => {
52
- for (const [x, v] of Object.entries(n)) {
53
- const k = c[x];
54
- if (!k) {
55
- console.warn(`[AGO] Unknown helper: "${x}"`);
51
+ return import("./functions-CApuQZ2b.js").then((d) => d.n).then((d) => {
52
+ for (const [y, m] of Object.entries(n)) {
53
+ const C = d[y];
54
+ if (!C) {
55
+ console.warn(`[AGO] Unknown helper: "${y}"`);
56
56
  continue;
57
57
  }
58
- const m = v === !0 ? k : {
59
- ...k,
60
- handler: v
58
+ const g = m === !0 ? C : {
59
+ ...C,
60
+ handler: m
61
61
  };
62
- i.register(m), f.push(m.name);
62
+ l.register(g), f.push(g.name);
63
63
  }
64
64
  }), () => {
65
- for (const c of f) i.unregisterFunction(c);
65
+ for (const d of f) l.unregisterFunction(d);
66
66
  };
67
- }, [i, n]), S(() => {
68
- o === "auto" && i.enableAutoPageContext();
69
- }, [i, o]), /* @__PURE__ */ s(D.Provider, {
70
- value: i,
67
+ }, [l, n]), k(() => {
68
+ s === "auto" && l.enableAutoPageContext();
69
+ }, [l, s]), /* @__PURE__ */ a(D.Provider, {
70
+ value: l,
71
71
  children: e
72
72
  });
73
73
  };
74
74
  function P() {
75
- const e = O(D);
75
+ const e = $(D);
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
79
  function L() {
80
- return O(D);
80
+ return $(D);
81
81
  }
82
- function $({ client: e, conversationId: t } = {}) {
82
+ function O({ client: e, conversationId: t } = {}) {
83
83
  const r = L(), n = e || r;
84
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, a] = M([]), [d, i] = M(t), [f, c] = M(!1), [x, v] = M(null);
86
- S(() => {
87
- t && t !== d && (i(t), k(t));
85
+ const [s, i] = M([]), [u, l] = M(t), [f, d] = M(!1), [y, m] = M(null);
86
+ k(() => {
87
+ t && t !== u && (l(t), C(t));
88
88
  }, [t]);
89
- const k = async (m) => {
89
+ const C = async (g) => {
90
90
  try {
91
- a(await n.getMessages(m));
91
+ i(await n.getMessages(g));
92
92
  } catch (b) {
93
- v(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load messages"));
93
+ m(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load messages"));
94
94
  }
95
95
  };
96
- return S(() => {
97
- const m = (g) => {
98
- d || i(g.conversationId);
99
- }, b = (g) => {
100
- a((u) => {
101
- const w = u[u.length - 1];
102
- return w && w.id === g.messageId ? [...u.slice(0, -1), {
103
- ...w,
104
- content: w.content + g.content
105
- }] : u;
96
+ return k(() => {
97
+ const g = (p) => {
98
+ u || l(p.conversationId);
99
+ }, b = (p) => {
100
+ i((c) => {
101
+ const x = c[c.length - 1];
102
+ return x && x.id === p.messageId ? [...c.slice(0, -1), {
103
+ ...x,
104
+ content: x.content + p.content
105
+ }] : c;
106
106
  });
107
- }, l = (g) => {
108
- a((u) => {
109
- let w = -1;
110
- for (let C = u.length - 1; C >= 0; C--) if (u[C].role === "assistant" && u[C].status === "IN_PROGRESS") {
111
- w = C;
107
+ }, v = (p) => {
108
+ i((c) => {
109
+ let x = -1;
110
+ for (let S = c.length - 1; S >= 0; S--) if (c[S].role === "assistant" && c[S].status === "IN_PROGRESS") {
111
+ x = S;
112
112
  break;
113
113
  }
114
- return w < 0 ? u : [
115
- ...u.slice(0, w),
114
+ return x < 0 ? c : [
115
+ ...c.slice(0, x),
116
116
  {
117
- ...u[w],
118
- ...g
117
+ ...c[x],
118
+ ...p
119
119
  },
120
- ...u.slice(w + 1)
120
+ ...c.slice(x + 1)
121
121
  ];
122
122
  });
123
- }, h = (g) => {
124
- a((u) => {
125
- const w = u.findIndex((C) => C.id === g.id);
126
- return w >= 0 ? [
127
- ...u.slice(0, w),
128
- g,
129
- ...u.slice(w + 1)
130
- ] : [...u, g];
131
- }), c(!1);
132
- }, p = (g) => {
133
- v(new Error(g.error)), c(!1);
123
+ }, w = (p) => {
124
+ i((c) => {
125
+ const x = c.findIndex((S) => S.id === p.id);
126
+ return x >= 0 ? [
127
+ ...c.slice(0, x),
128
+ p,
129
+ ...c.slice(x + 1)
130
+ ] : [...c, p];
131
+ }), d(!1);
132
+ }, o = (p) => {
133
+ m(new Error(p.error)), d(!1);
134
134
  };
135
- return n.on("message:start", m), n.on("message:chunk", b), n.on("message:answer-complete", l), n.on("message:complete", h), n.on("message:error", p), () => {
136
- n.off("message:start", m), n.off("message:chunk", b), n.off("message:answer-complete", l), n.off("message:complete", h), n.off("message:error", p);
135
+ return n.on("message:start", g), n.on("message:chunk", b), n.on("message:answer-complete", v), n.on("message:complete", w), n.on("message:error", o), () => {
136
+ n.off("message:start", g), n.off("message:chunk", b), n.off("message:answer-complete", v), n.off("message:complete", w), n.off("message:error", o);
137
137
  };
138
- }, [n, d]), {
139
- messages: o,
138
+ }, [n, u]), {
139
+ messages: s,
140
140
  isLoading: f,
141
- error: x,
142
- sendMessage: E(async (m, b) => {
143
- c(!0), v(null);
144
- const l = {
141
+ error: y,
142
+ sendMessage: I(async (g, b) => {
143
+ d(!0), m(null);
144
+ const v = {
145
145
  id: `temp-${Date.now()}`,
146
- conversationId: d || "",
147
- content: m,
146
+ conversationId: u || "",
147
+ content: g,
148
148
  role: "user",
149
149
  status: "DONE",
150
150
  createdAt: /* @__PURE__ */ new Date()
151
- }, h = {
151
+ }, w = {
152
152
  id: `temp-assistant-${Date.now()}`,
153
- conversationId: d || "",
153
+ conversationId: u || "",
154
154
  content: "",
155
155
  role: "assistant",
156
156
  status: "IN_PROGRESS",
157
157
  createdAt: /* @__PURE__ */ new Date()
158
158
  };
159
- a((p) => [
160
- ...p,
161
- l,
162
- h
159
+ i((o) => [
160
+ ...o,
161
+ v,
162
+ w
163
163
  ]);
164
164
  try {
165
- const p = await n.sendMessage(m, {
166
- conversationId: d,
165
+ const o = await n.sendMessage(g, {
166
+ conversationId: u,
167
167
  files: b
168
168
  });
169
- return p.conversationId && !d && i(p.conversationId), a((g) => {
170
- const u = g.filter((C) => !C.id.startsWith("temp-")), w = {
171
- ...l,
172
- id: l.id.replace("temp-", "user-"),
173
- conversationId: p.conversationId
169
+ return o.conversationId && !u && l(o.conversationId), i((p) => {
170
+ const c = p.filter((S) => !S.id.startsWith("temp-")), x = {
171
+ ...v,
172
+ id: v.id.replace("temp-", "user-"),
173
+ conversationId: o.conversationId
174
174
  };
175
- return u.some((C) => C.id === p.id) ? [...u, w].sort((C, _) => new Date(C.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
176
- ...u,
177
- w,
178
- p
175
+ return c.some((S) => S.id === o.id) ? [...c, x].sort((S, _) => new Date(S.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
176
+ ...c,
177
+ x,
178
+ o
179
179
  ];
180
- }), p;
181
- } catch (p) {
182
- return v(p instanceof Error ? p : /* @__PURE__ */ new Error("Failed to send message")), c(!1), a((g) => g.filter((u) => !u.id.startsWith("temp-"))), null;
180
+ }), o;
181
+ } catch (o) {
182
+ return m(o instanceof Error ? o : /* @__PURE__ */ new Error("Failed to send message")), d(!1), i((p) => p.filter((c) => !c.id.startsWith("temp-"))), null;
183
183
  }
184
- }, [n, d]),
185
- clearMessages: E(() => {
186
- a([]), i(void 0), v(null);
184
+ }, [n, u]),
185
+ clearMessages: I(() => {
186
+ i([]), l(void 0), m(null);
187
187
  }, []),
188
- conversationId: d
188
+ conversationId: u
189
189
  };
190
190
  }
191
- var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: o = "" }) => {
192
- const [a, d] = M(""), [i, f] = M([]), c = T(null), x = E((l) => {
193
- l.preventDefault(), (a.trim() || i.length > 0) && (e(a.trim(), i.length > 0 ? i : void 0), d(""), f([]));
191
+ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: s = "" }) => {
192
+ const [i, u] = M(""), [l, f] = M([]), d = A(null), y = A(null), m = I(() => {
193
+ const o = y.current;
194
+ if (!o) return;
195
+ const p = 110;
196
+ o.style.height = "auto", o.style.height = `${Math.min(o.scrollHeight + 2, p)}px`, o.style.overflowY = o.scrollHeight + 2 > p ? "auto" : "hidden";
197
+ }, []), C = I((o) => {
198
+ o.preventDefault(), (i.trim() || l.length > 0) && (e(i.trim(), l.length > 0 ? l : void 0), u(""), f([]), requestAnimationFrame(m));
194
199
  }, [
195
- a,
196
200
  i,
197
- e
198
- ]), v = E((l) => {
199
- l.key === "Enter" && !l.shiftKey && (l.preventDefault(), x(l));
200
- }, [x]), k = E((l) => {
201
- const h = Array.from(l.target.files || []);
202
- f((p) => [...p, ...h]);
203
- }, []), m = E((l) => {
204
- f((h) => h.filter((p, g) => g !== l));
205
- }, []), b = a.trim() || i.length > 0;
206
- return /* @__PURE__ */ I("form", {
207
- onSubmit: x,
208
- className: `ago-chat-input ${o}`,
201
+ l,
202
+ e,
203
+ m
204
+ ]), g = I((o) => {
205
+ o.key === "Enter" && !o.shiftKey && (o.preventDefault(), C(o));
206
+ }, [C]), b = I((o) => {
207
+ const p = Array.from(o.target.files || []);
208
+ f((c) => [...c, ...p]);
209
+ }, []), v = I((o) => {
210
+ f((p) => p.filter((c, x) => x !== o));
211
+ }, []), w = i.trim() || l.length > 0;
212
+ return /* @__PURE__ */ R("form", {
213
+ onSubmit: C,
214
+ className: `ago-chat-input ${s}`,
209
215
  style: {
210
216
  display: "flex",
211
217
  flexDirection: "column",
@@ -214,14 +220,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
214
220
  borderTop: "1px solid #dee3e8",
215
221
  backgroundColor: "#fff"
216
222
  },
217
- children: [i.length > 0 && /* @__PURE__ */ s("div", {
223
+ children: [l.length > 0 && /* @__PURE__ */ a("div", {
218
224
  className: "ago-chat-input__files",
219
225
  style: {
220
226
  display: "flex",
221
227
  flexWrap: "wrap",
222
228
  gap: "6px"
223
229
  },
224
- children: i.map((l, h) => /* @__PURE__ */ I("div", {
230
+ children: l.map((o, p) => /* @__PURE__ */ R("div", {
225
231
  style: {
226
232
  display: "flex",
227
233
  alignItems: "center",
@@ -232,17 +238,18 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
232
238
  fontSize: "12px",
233
239
  color: "#30373e"
234
240
  },
235
- children: [/* @__PURE__ */ s("span", {
241
+ children: [/* @__PURE__ */ a("span", {
236
242
  style: {
237
243
  maxWidth: "120px",
238
244
  overflow: "hidden",
239
245
  textOverflow: "ellipsis",
240
246
  whiteSpace: "nowrap"
241
247
  },
242
- children: l.name
243
- }), /* @__PURE__ */ s("button", {
248
+ children: o.name
249
+ }), /* @__PURE__ */ a("button", {
244
250
  type: "button",
245
- onClick: () => m(h),
251
+ onClick: () => v(p),
252
+ "aria-label": `Remove ${o.name}`,
246
253
  style: {
247
254
  border: "none",
248
255
  background: "none",
@@ -254,18 +261,19 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
254
261
  },
255
262
  children: "×"
256
263
  })]
257
- }, h))
258
- }), /* @__PURE__ */ I("div", {
264
+ }, p))
265
+ }), /* @__PURE__ */ R("div", {
259
266
  style: {
260
267
  display: "flex",
261
268
  gap: "8px",
262
269
  alignItems: "flex-end"
263
270
  },
264
271
  children: [
265
- n && /* @__PURE__ */ I(Y, { children: [/* @__PURE__ */ s("button", {
272
+ n && /* @__PURE__ */ R(X, { children: [/* @__PURE__ */ a("button", {
266
273
  type: "button",
267
- onClick: () => c.current?.click(),
274
+ onClick: () => d.current?.click(),
268
275
  disabled: t,
276
+ "aria-label": "Attach file",
269
277
  style: {
270
278
  padding: "8px",
271
279
  border: "1px solid #dee3e8",
@@ -277,18 +285,22 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
277
285
  lineHeight: 1
278
286
  },
279
287
  children: "+"
280
- }), /* @__PURE__ */ s("input", {
281
- ref: c,
288
+ }), /* @__PURE__ */ a("input", {
289
+ ref: d,
282
290
  type: "file",
283
291
  multiple: !0,
284
- onChange: k,
292
+ onChange: b,
285
293
  style: { display: "none" }
286
294
  })] }),
287
- /* @__PURE__ */ s("textarea", {
288
- value: a,
289
- onChange: (l) => d(l.target.value),
290
- onKeyDown: v,
295
+ /* @__PURE__ */ a("textarea", {
296
+ ref: y,
297
+ value: i,
298
+ onChange: (o) => {
299
+ u(o.target.value), m();
300
+ },
301
+ onKeyDown: g,
291
302
  placeholder: r,
303
+ "aria-label": r,
292
304
  disabled: t,
293
305
  rows: 1,
294
306
  style: {
@@ -298,29 +310,33 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
298
310
  borderRadius: "20px",
299
311
  resize: "none",
300
312
  outline: "none",
313
+ boxSizing: "border-box",
314
+ maxHeight: "110px",
315
+ overflowY: "hidden",
301
316
  fontFamily: "inherit",
302
317
  fontSize: "16px",
318
+ lineHeight: 1.4,
303
319
  color: "#30373e",
304
320
  backgroundColor: "#f8f8f8",
305
321
  transition: "border-color 0.15s"
306
322
  },
307
- onFocus: (l) => {
308
- l.currentTarget.style.borderColor = "#1b5fc4";
323
+ onFocus: (o) => {
324
+ o.currentTarget.style.borderColor = "#1b5fc4";
309
325
  },
310
- onBlur: (l) => {
311
- l.currentTarget.style.borderColor = "#dee3e8";
326
+ onBlur: (o) => {
327
+ o.currentTarget.style.borderColor = "#dee3e8";
312
328
  }
313
329
  }),
314
- /* @__PURE__ */ s("button", {
330
+ /* @__PURE__ */ a("button", {
315
331
  type: "submit",
316
- disabled: t || !b,
332
+ disabled: t || !w,
317
333
  style: {
318
334
  padding: "10px 18px",
319
335
  border: "none",
320
336
  borderRadius: "20px",
321
- backgroundColor: t || !b ? "#b5bfc8" : "#03182f",
337
+ backgroundColor: t || !w ? "#b5bfc8" : "#03182f",
322
338
  color: "#fff",
323
- cursor: t || !b ? "not-allowed" : "pointer",
339
+ cursor: t || !w ? "not-allowed" : "pointer",
324
340
  fontWeight: 500,
325
341
  fontSize: "16px",
326
342
  transition: "background-color 0.15s"
@@ -330,7 +346,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
330
346
  ]
331
347
  })]
332
348
  });
333
- }, ne = ({ href: e, children: t, ...r }) => /* @__PURE__ */ s("a", {
349
+ }, ne = ({ href: e, children: t, ...r }) => /* @__PURE__ */ a("a", {
334
350
  href: e,
335
351
  target: "_blank",
336
352
  rel: "noopener noreferrer",
@@ -340,7 +356,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
340
356
  },
341
357
  ...r,
342
358
  children: t
343
- }), re = ({ children: e, ...t }) => /* @__PURE__ */ s("p", {
359
+ }), re = ({ children: e, ...t }) => /* @__PURE__ */ a("p", {
344
360
  style: {
345
361
  margin: "0 0 8px 0",
346
362
  lineHeight: "1.6"
@@ -348,17 +364,17 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
348
364
  ...t,
349
365
  children: e
350
366
  }), N = (e, t) => {
351
- const r = ({ children: n, ...o }) => G.createElement(`h${e}`, {
367
+ const r = ({ children: n, ...s }) => G.createElement(`h${e}`, {
352
368
  style: {
353
369
  margin: "16px 0 8px 0",
354
370
  fontSize: t,
355
371
  fontWeight: 600,
356
372
  lineHeight: "1.3"
357
373
  },
358
- ...o
374
+ ...s
359
375
  }, n);
360
376
  return r.displayName = `MarkdownHeading${e}`, r;
361
- }, oe = ({ children: e, ...t }) => /* @__PURE__ */ s("ul", {
377
+ }, oe = ({ children: e, ...t }) => /* @__PURE__ */ a("ul", {
362
378
  style: {
363
379
  margin: "0 0 8px 0",
364
380
  paddingLeft: "20px",
@@ -367,7 +383,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
367
383
  },
368
384
  ...t,
369
385
  children: e
370
- }), se = ({ children: e, ...t }) => /* @__PURE__ */ s("ol", {
386
+ }), se = ({ children: e, ...t }) => /* @__PURE__ */ a("ol", {
371
387
  style: {
372
388
  margin: "0 0 8px 0",
373
389
  paddingLeft: "20px",
@@ -376,7 +392,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
376
392
  },
377
393
  ...t,
378
394
  children: e
379
- }), ae = ({ children: e, ...t }) => /* @__PURE__ */ s("li", {
395
+ }), ae = ({ children: e, ...t }) => /* @__PURE__ */ a("li", {
380
396
  style: {
381
397
  display: "list-item",
382
398
  margin: "2px 0",
@@ -385,7 +401,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
385
401
  ...t,
386
402
  children: e
387
403
  }), ie = ({ className: e, children: t, ...r }) => e !== void 0 || String(t).includes(`
388
- `) ? /* @__PURE__ */ s("code", {
404
+ `) ? /* @__PURE__ */ a("code", {
389
405
  style: {
390
406
  display: "block",
391
407
  background: "#f5f5f5",
@@ -397,7 +413,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
397
413
  },
398
414
  ...r,
399
415
  children: t
400
- }) : /* @__PURE__ */ s("code", {
416
+ }) : /* @__PURE__ */ a("code", {
401
417
  style: {
402
418
  background: "#f0f2f5",
403
419
  padding: "2px 5px",
@@ -407,11 +423,11 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
407
423
  },
408
424
  ...r,
409
425
  children: t
410
- }), le = ({ children: e, ...t }) => /* @__PURE__ */ s("pre", {
426
+ }), le = ({ children: e, ...t }) => /* @__PURE__ */ a("pre", {
411
427
  style: { margin: "0 0 8px 0" },
412
428
  ...t,
413
429
  children: e
414
- }), ce = ({ children: e, ...t }) => /* @__PURE__ */ s("blockquote", {
430
+ }), ce = ({ children: e, ...t }) => /* @__PURE__ */ a("blockquote", {
415
431
  style: {
416
432
  borderLeft: "4px solid #dee3e8",
417
433
  paddingLeft: "12px",
@@ -421,12 +437,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
421
437
  },
422
438
  ...t,
423
439
  children: e
424
- }), de = ({ children: e, ...t }) => /* @__PURE__ */ s("div", {
440
+ }), de = ({ children: e, ...t }) => /* @__PURE__ */ a("div", {
425
441
  style: {
426
442
  overflowX: "auto",
427
443
  margin: "0 0 8px 0"
428
444
  },
429
- children: /* @__PURE__ */ s("table", {
445
+ children: /* @__PURE__ */ a("table", {
430
446
  style: {
431
447
  borderCollapse: "collapse",
432
448
  width: "100%",
@@ -435,7 +451,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
435
451
  ...t,
436
452
  children: e
437
453
  })
438
- }), ue = ({ children: e, ...t }) => /* @__PURE__ */ s("th", {
454
+ }), ue = ({ children: e, ...t }) => /* @__PURE__ */ a("th", {
439
455
  style: {
440
456
  border: "1px solid #dee3e8",
441
457
  padding: "6px 10px",
@@ -445,14 +461,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
445
461
  },
446
462
  ...t,
447
463
  children: e
448
- }), pe = ({ children: e, ...t }) => /* @__PURE__ */ s("td", {
464
+ }), pe = ({ children: e, ...t }) => /* @__PURE__ */ a("td", {
449
465
  style: {
450
466
  border: "1px solid #dee3e8",
451
467
  padding: "6px 10px"
452
468
  },
453
469
  ...t,
454
470
  children: e
455
- }), fe = ({ alt: e, ...t }) => /* @__PURE__ */ s("img", {
471
+ }), fe = ({ alt: e, ...t }) => /* @__PURE__ */ a("img", {
456
472
  alt: e ?? "",
457
473
  style: {
458
474
  maxWidth: "100%",
@@ -460,7 +476,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
460
476
  margin: "4px 0"
461
477
  },
462
478
  ...t
463
- }), ge = (e) => /* @__PURE__ */ s("hr", {
479
+ }), ge = (e) => /* @__PURE__ */ a("hr", {
464
480
  style: {
465
481
  border: "none",
466
482
  borderTop: "1px solid #dee3e8",
@@ -487,12 +503,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
487
503
  td: pe,
488
504
  img: fe,
489
505
  hr: ge
490
- }, xe = [Z], he = ({ content: e }) => /* @__PURE__ */ s(Q, {
506
+ }, xe = [Z], he = ({ content: e }) => /* @__PURE__ */ a(Q, {
491
507
  remarkPlugins: xe,
492
508
  components: me,
493
509
  children: e
494
510
  }), ye = ({ source: e, index: t }) => {
495
- const r = /* @__PURE__ */ I("div", {
511
+ const r = /* @__PURE__ */ R("div", {
496
512
  style: {
497
513
  display: "flex",
498
514
  alignItems: "center",
@@ -500,7 +516,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
500
516
  width: "100%",
501
517
  minWidth: 0
502
518
  },
503
- children: [/* @__PURE__ */ s("div", {
519
+ children: [/* @__PURE__ */ a("div", {
504
520
  style: {
505
521
  flexShrink: 0,
506
522
  width: "18px",
@@ -516,7 +532,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
516
532
  backgroundColor: "#f0f4ff"
517
533
  },
518
534
  children: t + 1
519
- }), /* @__PURE__ */ s("div", {
535
+ }), /* @__PURE__ */ a("div", {
520
536
  style: {
521
537
  fontSize: "12px",
522
538
  overflow: "hidden",
@@ -540,23 +556,23 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
540
556
  minWidth: 0,
541
557
  transition: "border-color 0.15s"
542
558
  };
543
- return e.url ? /* @__PURE__ */ s("a", {
559
+ return e.url ? /* @__PURE__ */ a("a", {
544
560
  href: e.url,
545
561
  target: "_blank",
546
562
  rel: "noopener noreferrer",
547
563
  style: n,
548
- onMouseEnter: (o) => {
549
- o.currentTarget.style.borderColor = "#1b5fc4";
564
+ onMouseEnter: (s) => {
565
+ s.currentTarget.style.borderColor = "#1b5fc4";
550
566
  },
551
- onMouseLeave: (o) => {
552
- o.currentTarget.style.borderColor = "#dee3e8";
567
+ onMouseLeave: (s) => {
568
+ s.currentTarget.style.borderColor = "#dee3e8";
553
569
  },
554
570
  children: r
555
- }) : /* @__PURE__ */ s("div", {
571
+ }) : /* @__PURE__ */ a("div", {
556
572
  style: n,
557
573
  children: r
558
574
  });
559
- }, be = () => /* @__PURE__ */ I("div", {
575
+ }, be = () => /* @__PURE__ */ R("div", {
560
576
  style: {
561
577
  display: "flex",
562
578
  gap: "4px",
@@ -566,31 +582,31 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
566
582
  0,
567
583
  1,
568
584
  2
569
- ].map((e) => /* @__PURE__ */ s("div", { style: {
585
+ ].map((e) => /* @__PURE__ */ a("div", { style: {
570
586
  width: "6px",
571
587
  height: "6px",
572
588
  borderRadius: "50%",
573
589
  backgroundColor: "#b5bfc8",
574
590
  animation: "ago-pulse 1.2s ease-in-out infinite",
575
591
  animationDelay: `${e * 0.2}s`
576
- } }, e)), /* @__PURE__ */ s("style", { children: `
592
+ } }, e)), /* @__PURE__ */ a("style", { children: `
577
593
  @keyframes ago-pulse {
578
594
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
579
595
  40% { opacity: 1; transform: scale(1); }
580
596
  }
581
597
  ` })]
582
- }), ve = ({ message: e, className: t = "", showAgentName: r = !1, isLast: n = !1, onFollowUpClick: o }) => {
583
- const a = e.role === "user", d = e.status === "IN_PROGRESS";
584
- return /* @__PURE__ */ I("div", {
598
+ }), ve = ({ message: e, className: t = "", showAgentName: r = !1, isLast: n = !1, onFollowUpClick: s }) => {
599
+ const i = e.role === "user", u = e.status === "IN_PROGRESS";
600
+ return /* @__PURE__ */ R("div", {
585
601
  className: `ago-message ago-message--${e.role} ${t}`,
586
602
  style: {
587
603
  display: "flex",
588
604
  flexDirection: "column",
589
- alignItems: a ? "flex-end" : "flex-start",
605
+ alignItems: i ? "flex-end" : "flex-start",
590
606
  marginBottom: "16px"
591
607
  },
592
608
  children: [
593
- !a && r && e.agent && /* @__PURE__ */ s("div", {
609
+ !i && r && e.agent && /* @__PURE__ */ a("div", {
594
610
  className: "ago-message__agent",
595
611
  style: {
596
612
  display: "flex",
@@ -604,7 +620,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
604
620
  },
605
621
  children: e.agent.displayName || e.agent.name
606
622
  }),
607
- !a && e.sources && e.sources.length > 0 && /* @__PURE__ */ s("div", {
623
+ !i && e.sources && e.sources.length > 0 && /* @__PURE__ */ a("div", {
608
624
  className: "ago-message__sources",
609
625
  style: {
610
626
  display: "grid",
@@ -614,26 +630,26 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
614
630
  width: "100%",
615
631
  maxWidth: "85%"
616
632
  },
617
- children: e.sources.map((i, f) => /* @__PURE__ */ s(ye, {
618
- source: i,
633
+ children: e.sources.map((l, f) => /* @__PURE__ */ a(ye, {
634
+ source: l,
619
635
  index: f
620
- }, i.id))
636
+ }, l.id))
621
637
  }),
622
- /* @__PURE__ */ s("div", {
638
+ /* @__PURE__ */ a("div", {
623
639
  className: "ago-message__content",
624
640
  style: {
625
- maxWidth: a ? "75%" : "100%",
626
- padding: a ? "10px 14px" : "2px 8px",
627
- borderRadius: a ? "16px" : "0",
628
- backgroundColor: a ? "#03182f" : "transparent",
629
- color: a ? "#fff" : "#30373e",
641
+ maxWidth: i ? "75%" : "100%",
642
+ padding: i ? "10px 14px" : "2px 8px",
643
+ borderRadius: i ? "16px" : "0",
644
+ backgroundColor: i ? "#03182f" : "transparent",
645
+ color: i ? "#fff" : "#30373e",
630
646
  wordBreak: "break-word",
631
647
  fontSize: "16px",
632
648
  lineHeight: "1.6"
633
649
  },
634
- children: e.content ? /* @__PURE__ */ s(he, { content: e.content }) : d && /* @__PURE__ */ s(be, {})
650
+ children: e.content ? /* @__PURE__ */ a(he, { content: e.content }) : u && /* @__PURE__ */ a(be, {})
635
651
  }),
636
- n && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ s("div", {
652
+ n && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ a("div", {
637
653
  className: "ago-message__followups",
638
654
  style: {
639
655
  display: "flex",
@@ -641,71 +657,72 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
641
657
  gap: "8px",
642
658
  marginTop: "10px"
643
659
  },
644
- children: e.followUpReplies.map((i, f) => /* @__PURE__ */ s("button", {
660
+ children: e.followUpReplies.map((l, f) => /* @__PURE__ */ a("button", {
645
661
  type: "button",
646
662
  className: "ago-message__followup-btn",
647
- disabled: !o,
648
- onClick: o ? () => o(i) : void 0,
663
+ disabled: !s,
664
+ onClick: s ? () => s(l) : void 0,
649
665
  style: {
666
+ minHeight: "36px",
650
667
  padding: "6px 14px",
651
668
  fontSize: "13px",
652
669
  borderRadius: "16px",
653
670
  border: "1px solid #dee3e8",
654
671
  backgroundColor: "#fff",
655
672
  color: "#30373e",
656
- cursor: o ? "pointer" : "default",
673
+ cursor: s ? "pointer" : "default",
657
674
  transition: "border-color 0.15s"
658
675
  },
659
- onMouseEnter: (c) => {
660
- c.currentTarget.style.borderColor = "#1b5fc4";
676
+ onMouseEnter: (d) => {
677
+ d.currentTarget.style.borderColor = "#1b5fc4";
661
678
  },
662
- onMouseLeave: (c) => {
663
- c.currentTarget.style.borderColor = "#dee3e8";
679
+ onMouseLeave: (d) => {
680
+ d.currentTarget.style.borderColor = "#dee3e8";
664
681
  },
665
- children: i
682
+ children: l
666
683
  }, f))
667
684
  })
668
685
  ]
669
686
  });
670
- }, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: a = !1, height: d = 500, logoUrl: i, showAgentName: f = !1, forms: c, onFollowUpClick: x, className: v = "", onMessageSent: k, onMessageReceived: m }) => {
671
- const b = T(null), l = L(), h = e ?? l, { messages: p, isLoading: g, error: u, sendMessage: w } = $({
687
+ }, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: s = "Type a message...", allowFiles: i = !1, height: u = 500, logoUrl: l, showAgentName: f = !1, forms: d, onFollowUpClick: y, className: m = "", onMessageSent: C, onMessageReceived: g }) => {
688
+ const b = A(null), v = L(), w = e ?? v, { messages: o, isLoading: p, error: c, sendMessage: x } = O({
672
689
  client: e,
673
690
  conversationId: t
674
691
  });
675
- S(() => {
676
- if (!h || !c || c.length === 0) return;
677
- let y = !1;
678
- const A = [];
679
- return Promise.all(c.map((R) => R.schema != null ? Promise.resolve(H(R)) : z(h, R))).then((R) => {
680
- if (!y)
681
- for (const U of R) A.push(U.install(h));
692
+ k(() => {
693
+ if (!w || !d || d.length === 0) return;
694
+ let h = !1;
695
+ const F = [];
696
+ return Promise.all(d.map((E) => E.schema != null ? Promise.resolve(W(E)) : z(w, E))).then((E) => {
697
+ if (!h)
698
+ for (const U of E) F.push(U.install(w));
682
699
  }).catch(() => {
683
700
  }), () => {
684
- y = !0, A.forEach((R) => R());
701
+ h = !0, F.forEach((E) => E());
685
702
  };
686
- }, [h, c ? JSON.stringify(c.map((y) => [
687
- y.name,
688
- y.schema ?? null,
689
- y.submit ?? !1,
690
- y.description ?? null
691
- ])) : ""]), S(() => {
703
+ }, [w, d ? JSON.stringify(d.map((h) => [
704
+ h.name,
705
+ h.schema ?? null,
706
+ h.submit ?? !1,
707
+ h.description ?? null
708
+ ])) : ""]), k(() => {
692
709
  b.current?.scrollIntoView({ behavior: "smooth" });
693
- }, [p]), S(() => {
694
- const y = p[p.length - 1];
695
- y && y.role === "assistant" && y.status === "DONE" && m && m({
696
- id: y.id,
697
- content: y.content
710
+ }, [o]), k(() => {
711
+ const h = o[o.length - 1];
712
+ h && h.role === "assistant" && h.status === "DONE" && g && g({
713
+ id: h.id,
714
+ content: h.content
698
715
  });
699
- }, [p, m]);
700
- const C = async (y, A) => {
701
- k?.(y), await w(y, A);
702
- }, _ = p[p.length - 1], B = g && _?.role === "assistant" && _.status === "IN_PROGRESS", K = x === !1 ? void 0 : x ?? ((y) => C(y));
703
- return /* @__PURE__ */ I("div", {
704
- className: `ago-chat-widget ${v}`,
716
+ }, [o, g]);
717
+ const S = async (h, F) => {
718
+ C?.(h), await x(h, F);
719
+ }, _ = o[o.length - 1], B = p && _?.role === "assistant" && _.status === "IN_PROGRESS", K = y === !1 ? void 0 : y ?? ((h) => S(h));
720
+ return /* @__PURE__ */ R("div", {
721
+ className: `ago-chat-widget ${m}`,
705
722
  style: {
706
723
  display: "flex",
707
724
  flexDirection: "column",
708
- height: typeof d == "number" ? `${d}px` : d,
725
+ height: typeof u == "number" ? `${u}px` : u,
709
726
  border: "1px solid #dee3e8",
710
727
  borderRadius: "16px",
711
728
  overflow: "hidden",
@@ -715,7 +732,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
715
732
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
716
733
  },
717
734
  children: [
718
- /* @__PURE__ */ I("div", {
735
+ /* @__PURE__ */ R("div", {
719
736
  className: "ago-chat-widget__header",
720
737
  style: {
721
738
  padding: "14px 16px",
@@ -726,14 +743,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
726
743
  alignItems: "center",
727
744
  gap: "10px"
728
745
  },
729
- children: [i && /* @__PURE__ */ s("img", {
730
- src: i,
746
+ children: [l && /* @__PURE__ */ a("img", {
747
+ src: l,
731
748
  alt: "Logo",
732
749
  style: {
733
750
  height: "24px",
734
751
  width: "auto"
735
752
  }
736
- }), /* @__PURE__ */ s("h3", {
753
+ }), /* @__PURE__ */ a("h3", {
737
754
  style: {
738
755
  margin: 0,
739
756
  fontSize: "15px",
@@ -742,8 +759,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
742
759
  children: r
743
760
  })]
744
761
  }),
745
- /* @__PURE__ */ I("div", {
762
+ /* @__PURE__ */ R("div", {
746
763
  className: "ago-chat-widget__messages",
764
+ role: "log",
765
+ "aria-live": "polite",
766
+ "aria-relevant": "additions text",
767
+ "aria-atomic": !1,
747
768
  style: {
748
769
  flex: 1,
749
770
  overflow: "auto",
@@ -751,7 +772,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
751
772
  backgroundColor: "#fbfbfb"
752
773
  },
753
774
  children: [
754
- p.length === 0 ? /* @__PURE__ */ s("div", {
775
+ o.length === 0 ? /* @__PURE__ */ a("div", {
755
776
  style: {
756
777
  textAlign: "center",
757
778
  color: "#6b6d6f",
@@ -760,13 +781,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
760
781
  lineHeight: "1.5"
761
782
  },
762
783
  children: n
763
- }) : p.map((y, A) => /* @__PURE__ */ s(ve, {
764
- message: y,
784
+ }) : o.map((h, F) => /* @__PURE__ */ a(ve, {
785
+ message: h,
765
786
  showAgentName: f,
766
- isLast: A === p.length - 1,
787
+ isLast: F === o.length - 1,
767
788
  onFollowUpClick: K
768
- }, y.id)),
769
- u && /* @__PURE__ */ s("div", {
789
+ }, h.id)),
790
+ c && /* @__PURE__ */ a("div", {
791
+ role: "alert",
770
792
  style: {
771
793
  padding: "10px 14px",
772
794
  backgroundColor: "#fef2f2",
@@ -776,16 +798,16 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
776
798
  fontSize: "13px",
777
799
  border: "1px solid #fecaca"
778
800
  },
779
- children: u.message
801
+ children: c.message
780
802
  }),
781
- /* @__PURE__ */ s("div", { ref: b })
803
+ /* @__PURE__ */ a("div", { ref: b })
782
804
  ]
783
805
  }),
784
- /* @__PURE__ */ s(te, {
785
- onSend: C,
806
+ /* @__PURE__ */ a(te, {
807
+ onSend: S,
786
808
  disabled: B,
787
- placeholder: o,
788
- allowFiles: a
809
+ placeholder: s,
810
+ allowFiles: i
789
811
  })
790
812
  ]
791
813
  });
@@ -793,175 +815,175 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
793
815
  function we({ client: e, autoLoad: t = !0 } = {}) {
794
816
  const r = L(), n = e || r;
795
817
  if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
796
- const [o, a] = M([]), [d, i] = M(null), [f, c] = M(!1), [x, v] = M(null), k = E(async () => {
797
- c(!0), v(null);
818
+ const [s, i] = M([]), [u, l] = M(null), [f, d] = M(!1), [y, m] = M(null), C = I(async () => {
819
+ d(!0), m(null);
798
820
  try {
799
- a(await n.getConversations());
800
- } catch (l) {
801
- v(l instanceof Error ? l : /* @__PURE__ */ new Error("Failed to load conversations"));
821
+ i(await n.getConversations());
822
+ } catch (v) {
823
+ m(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversations"));
802
824
  } finally {
803
- c(!1);
825
+ d(!1);
804
826
  }
805
- }, [n]), m = E(async (l) => {
806
- c(!0), v(null);
827
+ }, [n]), g = I(async (v) => {
828
+ d(!0), m(null);
807
829
  try {
808
- i(await n.getConversation(l));
809
- } catch (h) {
810
- v(h instanceof Error ? h : /* @__PURE__ */ new Error("Failed to load conversation"));
830
+ l(await n.getConversation(v));
831
+ } catch (w) {
832
+ m(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversation"));
811
833
  } finally {
812
- c(!1);
834
+ d(!1);
813
835
  }
814
- }, [n]), b = E(() => {
815
- i(null);
836
+ }, [n]), b = I(() => {
837
+ l(null);
816
838
  }, []);
817
- return S(() => {
818
- t && k();
819
- }, [t, k]), {
820
- conversations: o,
821
- currentConversation: d,
839
+ return k(() => {
840
+ t && C();
841
+ }, [t, C]), {
842
+ conversations: s,
843
+ currentConversation: u,
822
844
  isLoading: f,
823
- error: x,
824
- selectConversation: m,
845
+ error: y,
846
+ selectConversation: g,
825
847
  startNewConversation: b,
826
- refreshConversations: k
848
+ refreshConversations: C
827
849
  };
828
850
  }
829
851
  function Pe(e = {}) {
830
852
  const t = L(), r = e.client || t;
831
853
  if (!r) throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
832
- const n = $({
854
+ const n = O({
833
855
  client: r,
834
856
  conversationId: e.conversationId
835
- }), o = we({
857
+ }), s = we({
836
858
  client: r,
837
859
  autoLoad: e.autoLoad
838
860
  });
839
861
  return {
840
862
  messages: n.messages,
841
863
  isLoading: n.isLoading,
842
- error: n.error || o.error,
864
+ error: n.error || s.error,
843
865
  sendMessage: n.sendMessage,
844
866
  clearMessages: n.clearMessages,
845
867
  conversationId: n.conversationId,
846
- conversations: o.conversations,
847
- currentConversation: o.currentConversation,
848
- isConversationsLoading: o.isLoading,
849
- selectConversation: o.selectConversation,
850
- startNewConversation: o.startNewConversation,
851
- refreshConversations: o.refreshConversations
868
+ conversations: s.conversations,
869
+ currentConversation: s.currentConversation,
870
+ isConversationsLoading: s.isLoading,
871
+ selectConversation: s.selectConversation,
872
+ startNewConversation: s.startNewConversation,
873
+ refreshConversations: s.refreshConversations
852
874
  };
853
875
  }
854
876
  function Le(e, t) {
855
- const r = P(), { name: n, description: o, parameters: a, handler: d } = typeof e == "string" ? {
877
+ const r = P(), { name: n, description: s, parameters: i, handler: u } = typeof e == "string" ? {
856
878
  name: e,
857
879
  ...t
858
- } : e, i = T(d);
859
- i.current = d, S(() => {
860
- const f = (c) => i.current(c);
880
+ } : e, l = A(u);
881
+ l.current = u, k(() => {
882
+ const f = (d) => l.current(d);
861
883
  return r.registerFunction(n, f, {
862
- description: o,
863
- parameters: a
884
+ description: s,
885
+ parameters: i
864
886
  }), () => {
865
887
  r.unregisterFunction(n);
866
888
  };
867
889
  }, [
868
890
  r,
869
891
  n,
870
- o,
871
- a
892
+ s,
893
+ i
872
894
  ]);
873
895
  }
874
896
  function De(e, t) {
875
- const r = P(), n = T(e);
876
- n.current = e, S(() => (r.registerNavigationFunction((o) => n.current(o), t), () => {
897
+ const r = P(), n = A(e);
898
+ n.current = e, k(() => (r.registerNavigationFunction((s) => n.current(s), t), () => {
877
899
  r.unregisterFunction("navigateToPage");
878
900
  }), [r, t]);
879
901
  }
880
- function We(e, t) {
881
- const r = P(), n = j(), o = t ?? n, a = T(e);
882
- a.current = e;
883
- const d = typeof e == "function";
884
- S(() => {
885
- if (typeof a.current == "function") {
886
- const i = () => a.current();
887
- return r.addDynamicContext(o, i), () => {
888
- r.removeDynamicContext(o);
902
+ function He(e, t) {
903
+ const r = P(), n = j(), s = t ?? n, i = A(e);
904
+ i.current = e;
905
+ const u = typeof e == "function";
906
+ k(() => {
907
+ if (typeof i.current == "function") {
908
+ const l = () => i.current();
909
+ return r.addDynamicContext(s, l), () => {
910
+ r.removeDynamicContext(s);
889
911
  };
890
912
  }
891
- return r.setContext(o, a.current), () => {
892
- r.removeContext(o);
913
+ return r.setContext(s, i.current), () => {
914
+ r.removeContext(s);
893
915
  };
894
916
  }, [
895
917
  r,
896
- o,
897
- d,
898
- d ? "" : JSON.stringify(e)
918
+ s,
919
+ u,
920
+ u ? "" : JSON.stringify(e)
899
921
  ]);
900
922
  }
901
923
  function Ce(e) {
902
- return X(e.subscribe, e.get, e.get);
924
+ return Y(e.subscribe, e.get, e.get);
903
925
  }
904
- var W = {
926
+ var H = {
905
927
  missing: [],
906
928
  complete: !1
907
929
  };
908
930
  function ze(e) {
909
- const t = P(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), o = e.submit, a = o ? typeof o == "string" ? `client:${o}` : o.via === "backend" ? "backend" : "handler" in o ? "client:handler" : `client:${o.url}` : "none", d = JSON.stringify(e.initialValues ?? null), i = F(() => r ? H(e) : null, [
931
+ const t = P(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), s = e.submit, i = s ? typeof s == "string" ? `client:${s}` : s.via === "backend" ? "backend" : "handler" in s ? "client:handler" : `client:${s.url}` : "none", u = JSON.stringify(e.initialValues ?? null), l = T(() => r ? W(e) : null, [
910
932
  r,
911
933
  e.name,
912
934
  n,
913
- a,
914
- d,
935
+ i,
936
+ u,
915
937
  e.autoSubmit
916
- ]), [f, c] = M({
938
+ ]), [f, d] = M({
917
939
  collector: null,
918
940
  loading: !r,
919
941
  error: null
920
942
  });
921
- S(() => {
943
+ k(() => {
922
944
  if (r) return;
923
- let g = !1;
924
- return c({
945
+ let p = !1;
946
+ return d({
925
947
  collector: null,
926
948
  loading: !0,
927
949
  error: null
928
- }), z(t, e).then((u) => {
929
- g || c({
930
- collector: u,
950
+ }), z(t, e).then((c) => {
951
+ p || d({
952
+ collector: c,
931
953
  loading: !1,
932
954
  error: null
933
955
  });
934
- }).catch((u) => {
935
- g || c({
956
+ }).catch((c) => {
957
+ p || d({
936
958
  collector: null,
937
959
  loading: !1,
938
- error: u instanceof Error ? u : new Error(String(u))
960
+ error: c instanceof Error ? c : new Error(String(c))
939
961
  });
940
962
  }), () => {
941
- g = !0;
963
+ p = !0;
942
964
  };
943
965
  }, [
944
966
  t,
945
967
  r,
946
968
  e.name,
947
- a,
948
- d,
969
+ i,
970
+ u,
949
971
  e.autoSubmit
950
972
  ]);
951
- const x = r ? i : f.collector, v = r ? !1 : f.loading, k = r ? null : f.error;
952
- S(() => {
953
- if (x)
954
- return x.install(t);
955
- }, [t, x]);
956
- const m = F(() => q({
973
+ const y = r ? l : f.collector, m = r ? !1 : f.loading, C = r ? null : f.error;
974
+ k(() => {
975
+ if (y)
976
+ return y.install(t);
977
+ }, [t, y]);
978
+ const g = T(() => J({
957
979
  values: e.initialValues ?? {},
958
980
  submitted: !1
959
- }), [d]), b = Ce(x?.store ?? m), l = F(() => x?.getStatus() ?? W, [b, x]), h = F(() => ({
981
+ }), [u]), b = Ce(y?.store ?? g), v = T(() => y?.getStatus() ?? H, [b, y]), w = T(() => ({
960
982
  ...b,
961
- ...l
962
- }), [b, l]), p = F(() => ({
983
+ ...v
984
+ }), [b, v]), o = T(() => ({
963
985
  name: e.name,
964
- store: m,
986
+ store: g,
965
987
  functions: [],
966
988
  contextKey: `form:${e.name}`,
967
989
  contextProvider: () => ({
@@ -976,18 +998,18 @@ function ze(e) {
976
998
  ok: !1,
977
999
  error: "Form definition not loaded yet."
978
1000
  }),
979
- getValues: () => m.get().values,
1001
+ getValues: () => g.get().values,
980
1002
  setValues: () => {
981
1003
  },
982
1004
  reset: () => {
983
1005
  },
984
- getStatus: () => W
985
- }), [e.name, m]);
1006
+ getStatus: () => H
1007
+ }), [e.name, g]);
986
1008
  return {
987
- ...x ?? p,
988
- state: h,
989
- loading: v,
990
- error: k
1009
+ ...y ?? o,
1010
+ state: w,
1011
+ loading: m,
1012
+ error: C
991
1013
  };
992
1014
  }
993
1015
  export {
@@ -996,19 +1018,19 @@ export {
996
1018
  _e as ChatWidget,
997
1019
  he as Markdown,
998
1020
  ve as Message,
999
- H as createFormCollector,
1000
- Ee as createMockClient,
1021
+ W as createFormCollector,
1022
+ Re as createMockClient,
1001
1023
  Me as deriveFormStatus,
1002
1024
  z as loadFormCollector,
1003
1025
  ee as useAgo,
1004
1026
  P as useAgoClient,
1005
- We as useAgoContext,
1027
+ He as useAgoContext,
1006
1028
  Le as useAgoFunction,
1007
1029
  De as useAgoNavigation,
1008
1030
  Ce as useAgoStore,
1009
1031
  Pe as useChat,
1010
1032
  we as useConversation,
1011
1033
  ze as useFormCollector,
1012
- $ as useMessages,
1034
+ O as useMessages,
1013
1035
  L as useOptionalAgoClient
1014
1036
  };