@useago/sdk 1.0.10 → 1.1.0

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