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