@useago/sdk 1.7.2 → 1.12.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/README.md +96 -1
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +402 -5
  5. package/dist/angular.d.ts +402 -5
  6. package/dist/angular.js +11 -7
  7. package/dist/{createConversationSession-DP90nY71.js → createConversationSession-B1Qn-y0I.js} +3 -3
  8. package/dist/createConversationSession-B3v_xOU7.cjs +1 -0
  9. package/dist/createFormCollector-FvwDOqnV.cjs +1 -0
  10. package/dist/{createFormCollector-BivHRIAe.js → createFormCollector-m79zk_NA.js} +1 -1
  11. package/dist/createMockClient-BEOXI8yW.cjs +1 -0
  12. package/dist/{createMockClient-BDLW6tVc.js → createMockClient-Beao82tu.js} +31 -18
  13. package/dist/devtools.cjs +61 -12
  14. package/dist/devtools.d.cts +403 -5
  15. package/dist/devtools.d.ts +403 -5
  16. package/dist/devtools.js +225 -73
  17. package/dist/errors-BLfjXnLB.js +32 -0
  18. package/dist/errors-o1IB5fEu.cjs +1 -0
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +489 -7
  21. package/dist/index.d.ts +489 -7
  22. package/dist/index.js +124 -118
  23. package/dist/react.cjs +4 -4
  24. package/dist/react.d.cts +510 -3
  25. package/dist/react.d.ts +510 -3
  26. package/dist/react.js +1036 -752
  27. package/dist/sheetController-BThJRtOu.cjs +1 -0
  28. package/dist/sheetController-aEKXIvjk.js +343 -0
  29. package/dist/testing.cjs +1 -1
  30. package/dist/testing.d.cts +393 -3
  31. package/dist/testing.d.ts +393 -3
  32. package/dist/testing.js +1 -1
  33. package/dist/types-Ct1hlKwg.js +2408 -0
  34. package/dist/types-mcW8vB1U.cjs +10 -0
  35. package/dist/vue.cjs +1 -1
  36. package/dist/vue.d.cts +615 -3
  37. package/dist/vue.d.ts +615 -3
  38. package/dist/vue.js +202 -154
  39. package/dist/widget.cjs +6 -4
  40. package/dist/widget.d.cts +733 -5
  41. package/dist/widget.d.ts +733 -5
  42. package/dist/widget.js +3996 -786
  43. package/llms-full.txt +264 -31
  44. package/package.json +1 -1
  45. package/dist/AgoClient-7yXQ6R3O.cjs +0 -9
  46. package/dist/AgoClient-DTkBRGFE.js +0 -1965
  47. package/dist/createConversationSession-Bv6a15E0.cjs +0 -1
  48. package/dist/createFormCollector-CwfiYn0V.cjs +0 -1
  49. package/dist/createMockClient-BSNuN3ys.cjs +0 -1
  50. package/dist/sheetController-CBUVOroo.js +0 -205
  51. package/dist/sheetController-DY-sC13T.cjs +0 -1
package/dist/react.js CHANGED
@@ -1,27 +1,29 @@
1
- import { a as Ee, b as Z, h as Me, i as Te, o as Fe, s as We, t as ze } from "./AgoClient-DTkBRGFE.js";
2
- import { t as Pe } from "./autoContinue-CC8K9mBU.js";
3
- import { n as Et, r as ue, t as pe } from "./createFormCollector-BivHRIAe.js";
4
- import { t as Tt } from "./createMockClient-BDLW6tVc.js";
5
- import { C as De, S as Le, n as He } from "./sheetController-CBUVOroo.js";
6
- import Be, { createContext as Oe, forwardRef as je, useCallback as R, useContext as fe, useEffect as N, useId as $e, useImperativeHandle as qe, useMemo as H, useRef as W, useState as z, useSyncExternalStore as ge } from "react";
7
- import { Fragment as me, jsx as a, jsxs as T } from "react/jsx-runtime";
8
- import Ke from "react-markdown";
9
- import Ue from "remark-gfm";
10
- function Ge(e) {
11
- const [o, t] = z(!1), r = W(null), n = H(() => {
12
- if (r.current && (r.current.destroy(), r.current = null), !e) return null;
13
- const s = new ze(e);
14
- return r.current = s, s;
1
+ import { a as Fe, c as We, g as ze, n as De, o as Pe, s as Le, t as He } from "./types-Ct1hlKwg.js";
2
+ import { n as X } from "./errors-BLfjXnLB.js";
3
+ import { t as Be } from "./autoContinue-CC8K9mBU.js";
4
+ import { n as Lt, r as ge, t as me } from "./createFormCollector-m79zk_NA.js";
5
+ import { t as Bt } from "./createMockClient-Beao82tu.js";
6
+ import { U as Oe, W as qe, n as je } from "./sheetController-aEKXIvjk.js";
7
+ import $e, { createContext as Ke, forwardRef as Ue, useCallback as _, useContext as he, useEffect as E, useId as Ge, useImperativeHandle as Je, useMemo as B, useRef as D, useState as T, useSyncExternalStore as xe } from "react";
8
+ import { Fragment as be, jsx as a, jsxs as M } from "react/jsx-runtime";
9
+ import Ve from "react-markdown";
10
+ import Ye from "remark-gfm";
11
+ function Xe(e) {
12
+ const [r, t] = T(!1), o = D(null), n = B(() => {
13
+ if (o.current && (o.current.destroy(), o.current = null), !e) return null;
14
+ const l = new De(e);
15
+ return o.current = l, l;
15
16
  }, [e?.baseUrl, e?.widgetId]);
16
- return N(() => (n && r.current === null && (r.current = n, n.reviveAfterDestroy()), t(!0), () => {
17
- r.current?.destroy(), r.current = null;
18
- }), [n]), N(() => {
19
- r.current && e && r.current.updateConfig({
17
+ return E(() => (n && o.current === null && (o.current = n, n.reviveAfterDestroy()), t(!0), () => {
18
+ o.current?.destroy(), o.current = null;
19
+ }), [n]), E(() => {
20
+ o.current && e && o.current.updateConfig({
20
21
  agent: e.agent,
21
22
  defaultAgentId: e.defaultAgentId,
22
23
  permission: e.permission,
23
24
  userEmail: e.userEmail,
24
25
  userJwt: e.userJwt,
26
+ metadata: e.metadata ?? null,
25
27
  debug: e.debug,
26
28
  warnOnEmptyReply: e.warnOnEmptyReply
27
29
  });
@@ -31,58 +33,59 @@ function Ge(e) {
31
33
  e?.permission,
32
34
  e?.userEmail,
33
35
  e?.userJwt,
36
+ e?.metadata,
34
37
  e?.debug,
35
38
  e?.warnOnEmptyReply
36
39
  ]), {
37
40
  client: n,
38
- isReady: o
41
+ isReady: r
39
42
  };
40
43
  }
41
- var Q = Oe(null), Lt = ({ children: e, client: o, tools: t, helpers: r, pageContext: n, ...s }) => {
42
- const { client: i } = Ge(o ? null : s), l = o || i;
43
- return N(() => {
44
+ var ee = Ke(null), Ut = ({ children: e, client: r, tools: t, helpers: o, pageContext: n, ...l }) => {
45
+ const { client: s } = Xe(r ? null : l), i = r || s;
46
+ return E(() => {
44
47
  if (!(!t || t.length === 0)) {
45
- for (const c of t) l.register(c);
48
+ for (const u of t) i.register(u);
46
49
  return () => {
47
- for (const c of t) l.unregisterFunction(c.name);
50
+ for (const u of t) i.unregisterFunction(u.name);
48
51
  };
49
52
  }
50
- }, [l, t]), N(() => {
51
- if (!r) return;
52
- const c = [];
53
- return import("./functions-tzyOZNp6.js").then((p) => p.n).then((p) => {
54
- for (const [f, k] of Object.entries(r)) {
55
- const _ = p[f];
56
- if (!_) {
57
- console.warn(`[AGO] Unknown helper: "${f}"`);
53
+ }, [i, t]), E(() => {
54
+ if (!o) return;
55
+ const u = [];
56
+ return import("./functions-tzyOZNp6.js").then((c) => c.n).then((c) => {
57
+ for (const [p, v] of Object.entries(o)) {
58
+ const S = c[p];
59
+ if (!S) {
60
+ console.warn(`[AGO] Unknown helper: "${p}"`);
58
61
  continue;
59
62
  }
60
- const C = k === !0 ? _ : {
61
- ..._,
62
- handler: k
63
+ const g = v === !0 ? S : {
64
+ ...S,
65
+ handler: v
63
66
  };
64
- l.register(C), c.push(C.name);
67
+ i.register(g), u.push(g.name);
65
68
  }
66
69
  }), () => {
67
- for (const p of c) l.unregisterFunction(p);
70
+ for (const c of u) i.unregisterFunction(c);
68
71
  };
69
- }, [l, r]), N(() => {
70
- n === "auto" && l.enableAutoPageContext();
71
- }, [l, n]), /* @__PURE__ */ a(Q.Provider, {
72
- value: l,
72
+ }, [i, o]), E(() => {
73
+ n === "auto" && i.enableAutoPageContext();
74
+ }, [i, n]), /* @__PURE__ */ a(ee.Provider, {
75
+ value: i,
73
76
  children: e
74
77
  });
75
78
  };
76
79
  function $() {
77
- const e = fe(Q);
80
+ const e = he(ee);
78
81
  if (!e) throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');
79
82
  return e;
80
83
  }
81
84
  function O() {
82
- return fe(Q);
85
+ return he(ee);
83
86
  }
84
- var Je = /* @__PURE__ */ new Set(["awaiting-approval"]);
85
- function he(e) {
87
+ var Ze = /* @__PURE__ */ new Set(["awaiting-approval"]);
88
+ function ye(e) {
86
89
  switch (e) {
87
90
  case "progress_indicator":
88
91
  return "progress";
@@ -96,22 +99,22 @@ function he(e) {
96
99
  return "status";
97
100
  }
98
101
  }
99
- function Ve(e) {
100
- return e.type === "client_function" ? e.functionName === "navigateToPage" ? "navigation" : "action" : he(e.type);
102
+ function Qe(e) {
103
+ return e.type === "client_function" ? e.functionName === "navigateToPage" ? "navigation" : "action" : ye(e.type);
101
104
  }
102
- function se(e, o) {
105
+ function le(e, r) {
103
106
  const t = (e ?? "").toLowerCase();
104
- return t.includes("reject") ? "rejected" : t.includes("error") || t.includes("fail") ? "error" : t.includes("done") || t.includes("complet") ? "done" : (t.includes("waiting") || t.includes("pending")) && (o === "confirmation" || o === "form") ? "awaiting-approval" : "running";
107
+ return t.includes("reject") ? "rejected" : t.includes("error") || t.includes("fail") ? "error" : t.includes("done") || t.includes("complet") ? "done" : (t.includes("waiting") || t.includes("pending")) && (r === "confirmation" || r === "form") ? "awaiting-approval" : "running";
105
108
  }
106
- function le(e) {
107
- return typeof e != "string" || !e ? "page" : e.replace(/[-_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\b\w/g, (o) => o.toUpperCase()).trim();
109
+ function ce(e) {
110
+ return typeof e != "string" || !e ? "page" : e.replace(/[-_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\b\w/g, (r) => r.toUpperCase()).trim();
108
111
  }
109
- function Ye(e) {
112
+ function et(e) {
110
113
  switch (e.kind) {
111
114
  case "navigation":
112
- return `Navigating to ${le(e.arguments?.page)}`;
115
+ return `Navigating to ${ce(e.arguments?.page)}`;
113
116
  case "action":
114
- return e.functionName === "setPageState" ? "Updating the page" : e.functionName === "openFilteredConversations" ? "Opening conversations" : e.toolDisplayName || e.message || le(e.functionName) || "Working";
117
+ return e.functionName === "setPageState" ? "Updating the page" : e.functionName === "openFilteredConversations" ? "Opening conversations" : e.toolDisplayName || e.message || ce(e.functionName) || "Working";
115
118
  case "progress":
116
119
  return e.message || "Working";
117
120
  case "reasoning":
@@ -124,281 +127,281 @@ function Ye(e) {
124
127
  return e.message || e.toolDisplayName || e.toolName || "Working";
125
128
  }
126
129
  }
127
- function Xe(e = {}) {
128
- const { includeReasoning: o = !1, labelFor: t } = e, r = O(), n = e.client || r;
129
- if (!n) throw new Z("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.", "provider_missing_client");
130
- const [s, i] = z([]), l = W(/* @__PURE__ */ new Set()), c = W(void 0), p = W(t);
131
- p.current = t;
132
- const f = R((u, A) => {
133
- i((b) => {
134
- const d = b.findIndex((m) => m.id === u), y = {
135
- ...d >= 0 ? b[d] : {
136
- id: u,
130
+ function tt(e = {}) {
131
+ const { includeReasoning: r = !1, labelFor: t } = e, o = O(), n = e.client || o;
132
+ if (!n) throw new X("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.", "provider_missing_client");
133
+ const [l, s] = T([]), i = D(/* @__PURE__ */ new Set()), u = D(void 0), c = D(t);
134
+ c.current = t;
135
+ const p = _((d, w) => {
136
+ s((x) => {
137
+ const f = x.findIndex((y) => y.id === d), h = {
138
+ ...f >= 0 ? x[f] : {
139
+ id: d,
137
140
  kind: "status",
138
141
  label: "",
139
142
  status: "running",
140
143
  requiresApproval: !1,
141
144
  createdAt: /* @__PURE__ */ new Date()
142
145
  },
143
- ...A
146
+ ...w
144
147
  };
145
- return y.label = p.current?.(y) ?? Ye(y), d >= 0 ? [
146
- ...b.slice(0, d),
147
- y,
148
- ...b.slice(d + 1)
149
- ] : [...b, y];
148
+ return h.label = c.current?.(h) ?? et(h), f >= 0 ? [
149
+ ...x.slice(0, f),
150
+ h,
151
+ ...x.slice(f + 1)
152
+ ] : [...x, h];
150
153
  });
151
154
  }, []);
152
- N(() => {
153
- const u = (x) => {
154
- c.current = x.messageId;
155
- }, A = (x) => {
156
- const M = he(x.type);
157
- M === "reasoning" && !o || f(x.id, {
158
- kind: M,
159
- status: se(x.status, M),
160
- messageId: c.current,
161
- toolName: x.toolName,
162
- toolDisplayName: x.toolDisplayName,
163
- message: x.message,
164
- data: x.data,
165
- formSchema: x.formSchema,
166
- requiresApproval: M === "confirmation" || M === "form"
155
+ E(() => {
156
+ const d = (k) => {
157
+ u.current = k.messageId;
158
+ }, w = (k) => {
159
+ const F = ye(k.type);
160
+ F === "reasoning" && !r || p(k.id, {
161
+ kind: F,
162
+ status: le(k.status, F),
163
+ messageId: u.current,
164
+ toolName: k.toolName,
165
+ toolDisplayName: k.toolDisplayName,
166
+ message: k.message,
167
+ data: k.data,
168
+ formSchema: k.formSchema,
169
+ requiresApproval: F === "confirmation" || F === "form"
167
170
  });
168
- }, b = (x) => {
169
- x.invocationId && f(x.invocationId, {
170
- kind: x.functionName === "navigateToPage" ? "navigation" : "action",
171
+ }, x = (k) => {
172
+ k.invocationId && p(k.invocationId, {
173
+ kind: k.functionName === "navigateToPage" ? "navigation" : "action",
171
174
  status: "running",
172
- messageId: c.current,
173
- functionName: x.functionName,
174
- arguments: x.arguments
175
+ messageId: u.current,
176
+ functionName: k.functionName,
177
+ arguments: k.arguments
175
178
  });
176
- }, d = (x) => {
177
- x.invocationId && f(x.invocationId, {
178
- kind: x.functionName === "navigateToPage" ? "navigation" : "action",
179
+ }, f = (k) => {
180
+ k.invocationId && p(k.invocationId, {
181
+ kind: k.functionName === "navigateToPage" ? "navigation" : "action",
179
182
  status: "awaiting-approval",
180
- messageId: c.current,
181
- functionName: x.functionName,
182
- arguments: x.arguments,
183
+ messageId: u.current,
184
+ functionName: k.functionName,
185
+ arguments: k.arguments,
183
186
  requiresApproval: !0
184
187
  });
185
- }, y = (x) => {
186
- if (!x.invocationId) return;
187
- const M = x.result, v = typeof x.result == "object" && M !== null && M.approved === !1 && M.reason === "user_rejected";
188
- f(x.invocationId, {
189
- status: x.error ? "error" : v ? "rejected" : "done",
188
+ }, h = (k) => {
189
+ if (!k.invocationId) return;
190
+ const F = k.result, C = typeof k.result == "object" && F !== null && F.approved === !1 && F.reason === "user_rejected";
191
+ p(k.invocationId, {
192
+ status: k.error ? "error" : C ? "rejected" : "done",
190
193
  requiresApproval: !1
191
194
  });
192
- }, m = (x) => {
193
- for (const M of x.messages ?? [])
194
- if (M.role === "assistant")
195
- for (const v of M.toolCalls ?? []) {
196
- const D = Ve(v);
197
- D === "reasoning" && !o || /waiting/i.test(v.status ?? "") || f(v.id, {
198
- kind: D,
199
- status: se(v.status, D),
200
- messageId: M.id,
201
- toolName: v.toolName,
202
- toolDisplayName: v.toolDisplayName,
203
- functionName: v.functionName,
204
- arguments: v.arguments,
205
- message: v.message,
206
- data: v.data,
207
- formSchema: v.formSchema,
208
- requiresApproval: D === "confirmation" || D === "form"
195
+ }, y = (k) => {
196
+ for (const F of k.messages ?? [])
197
+ if (F.role === "assistant")
198
+ for (const C of F.toolCalls ?? []) {
199
+ const I = Qe(C);
200
+ I === "reasoning" && !r || /waiting/i.test(C.status ?? "") || p(C.id, {
201
+ kind: I,
202
+ status: le(C.status, I),
203
+ messageId: F.id,
204
+ toolName: C.toolName,
205
+ toolDisplayName: C.toolDisplayName,
206
+ functionName: C.functionName,
207
+ arguments: C.arguments,
208
+ message: C.message,
209
+ data: C.data,
210
+ formSchema: C.formSchema,
211
+ requiresApproval: I === "confirmation" || I === "form"
209
212
  });
210
213
  }
211
- }, g = (x) => {
212
- i((M) => M.map((v) => v.status === "running" || v.status === "awaiting-approval" ? {
213
- ...v,
214
- status: x
215
- } : v));
216
- }, w = () => g("done"), S = () => g("error");
217
- return n.on("message:start", u), n.on("toolCall:received", A), n.on("function:invoke", b), n.on("function:awaiting-approval", d), n.on("function:result", y), n.on("conversation:loaded", m), n.on("message:complete", w), n.on("message:error", S), () => {
218
- n.off("message:start", u), n.off("toolCall:received", A), n.off("function:invoke", b), n.off("function:awaiting-approval", d), n.off("function:result", y), n.off("conversation:loaded", m), n.off("message:complete", w), n.off("message:error", S);
214
+ }, m = (k) => {
215
+ s((F) => F.map((C) => C.status === "running" || C.status === "awaiting-approval" ? {
216
+ ...C,
217
+ status: k
218
+ } : C));
219
+ }, A = () => m("done"), N = () => m("error");
220
+ return n.on("message:start", d), n.on("toolCall:received", w), n.on("function:invoke", x), n.on("function:awaiting-approval", f), n.on("function:result", h), n.on("conversation:loaded", y), n.on("message:complete", A), n.on("message:error", N), () => {
221
+ n.off("message:start", d), n.off("toolCall:received", w), n.off("function:invoke", x), n.off("function:awaiting-approval", f), n.off("function:result", h), n.off("conversation:loaded", y), n.off("message:complete", A), n.off("message:error", N);
219
222
  };
220
223
  }, [
221
224
  n,
222
- o,
223
- f
225
+ r,
226
+ p
224
227
  ]);
225
- const k = R(async (u) => {
226
- const A = s.find((b) => b.id === u);
227
- !A || A.status !== "awaiting-approval" || l.current.has(u) || A.kind !== "form" && (l.current.add(u), f(u, {
228
+ const v = _(async (d) => {
229
+ const w = l.find((x) => x.id === d);
230
+ !w || w.status !== "awaiting-approval" || i.current.has(d) || w.kind !== "form" && (i.current.add(d), p(d, {
228
231
  status: "running",
229
232
  requiresApproval: !1
230
- }), A.functionName ? await n.approveFunction(u) : await n.confirmToolCall(u));
233
+ }), w.functionName ? await n.approveFunction(d) : await n.confirmToolCall(d));
231
234
  }, [
232
235
  n,
233
- s,
234
- f
235
- ]), _ = R(async (u) => {
236
- const A = s.find((b) => b.id === u);
237
- !A || A.status !== "awaiting-approval" || l.current.has(u) || (l.current.add(u), f(u, {
236
+ l,
237
+ p
238
+ ]), S = _(async (d) => {
239
+ const w = l.find((x) => x.id === d);
240
+ !w || w.status !== "awaiting-approval" || i.current.has(d) || (i.current.add(d), p(d, {
238
241
  status: "rejected",
239
242
  requiresApproval: !1
240
- }), A.functionName ? await n.rejectFunction(u) : await n.rejectToolCall(u));
243
+ }), w.functionName ? await n.rejectFunction(d) : await n.rejectToolCall(d));
241
244
  }, [
242
245
  n,
243
- s,
244
- f
245
- ]), C = R(async (u, A) => {
246
- f(u, {
246
+ l,
247
+ p
248
+ ]), g = _(async (d, w) => {
249
+ p(d, {
247
250
  status: "running",
248
251
  requiresApproval: !1
249
- }), await n.submitToolCallForm(u, A), f(u, { status: "done" });
250
- }, [n, f]), I = R(() => {
251
- l.current.clear(), i([]);
252
+ }), await n.submitToolCallForm(d, w), p(d, { status: "done" });
253
+ }, [n, p]), R = _(() => {
254
+ i.current.clear(), s([]);
252
255
  }, []);
253
256
  return {
254
- items: s,
255
- latest: s.length > 0 ? s[s.length - 1] : void 0,
256
- isAwaitingApproval: s.some((u) => Je.has(u.status)),
257
- approve: k,
258
- reject: _,
259
- submitForm: C,
260
- clear: I
257
+ items: l,
258
+ latest: l.length > 0 ? l[l.length - 1] : void 0,
259
+ isAwaitingApproval: l.some((d) => Ze.has(d.status)),
260
+ approve: v,
261
+ reject: S,
262
+ submitForm: g,
263
+ clear: R
261
264
  };
262
265
  }
263
- function xe({ client: e, conversationId: o } = {}) {
264
- const t = O(), r = e || t;
265
- if (!r) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
266
- const [n, s] = z([]), [i, l] = z(o), [c, p] = z(!1), [f, k] = z(null);
267
- N(() => {
268
- o && o !== i && (l(o), _(o));
269
- }, [o]);
270
- const _ = async (C) => {
266
+ function ve({ client: e, conversationId: r } = {}) {
267
+ const t = O(), o = e || t;
268
+ if (!o) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
269
+ const [n, l] = T([]), [s, i] = T(r), [u, c] = T(!1), [p, v] = T(null);
270
+ E(() => {
271
+ r && r !== s && (i(r), S(r));
272
+ }, [r]);
273
+ const S = async (g) => {
271
274
  try {
272
- s((await r.getMessages(C)).filter((I) => !I.hidden));
273
- } catch (I) {
274
- k(I instanceof Error ? I : /* @__PURE__ */ new Error("Failed to load messages"));
275
+ l((await o.getMessages(g)).filter((R) => !R.hidden));
276
+ } catch (R) {
277
+ v(R instanceof Error ? R : /* @__PURE__ */ new Error("Failed to load messages"));
275
278
  }
276
279
  };
277
- return N(() => {
278
- const C = (m) => m === "IN_PROGRESS" || m === "WAITING_CLIENT", I = (m) => {
279
- i || l(m.conversationId), p(!0), s((g) => {
280
- const w = g.findIndex((S) => S.id === m.messageId);
281
- return w >= 0 ? g.map((S, x) => x === w ? {
282
- ...S,
280
+ return E(() => {
281
+ const g = (y) => y === "IN_PROGRESS" || y === "WAITING_CLIENT", R = (y) => {
282
+ s || i(y.conversationId), c(!0), l((m) => {
283
+ const A = m.findIndex((N) => N.id === y.messageId);
284
+ return A >= 0 ? m.map((N, k) => k === A ? {
285
+ ...N,
283
286
  status: "IN_PROGRESS"
284
- } : S) : g.some((S) => S.role === "assistant" && C(S.status)) ? g : [...g, {
285
- id: m.messageId,
286
- conversationId: m.conversationId,
287
+ } : N) : m.some((N) => N.role === "assistant" && g(N.status)) ? m : [...m, {
288
+ id: y.messageId,
289
+ conversationId: y.conversationId,
287
290
  content: "",
288
291
  role: "assistant",
289
292
  status: "IN_PROGRESS",
290
293
  createdAt: /* @__PURE__ */ new Date()
291
294
  }];
292
295
  });
293
- }, u = (m) => {
294
- s((g) => {
295
- const w = g.findIndex((S) => S.id === m.messageId);
296
- return w < 0 ? g : g.map((S, x) => x === w ? {
297
- ...S,
298
- content: S.content + m.content
299
- } : S);
296
+ }, d = (y) => {
297
+ l((m) => {
298
+ const A = m.findIndex((N) => N.id === y.messageId);
299
+ return A < 0 ? m : m.map((N, k) => k === A ? {
300
+ ...N,
301
+ content: N.content + y.content
302
+ } : N);
300
303
  });
301
- }, A = (m) => {
302
- s((g) => {
303
- let w = -1;
304
- for (let S = g.length - 1; S >= 0; S--) if (g[S].role === "assistant" && C(g[S].status)) {
305
- w = S;
304
+ }, w = (y) => {
305
+ l((m) => {
306
+ let A = -1;
307
+ for (let N = m.length - 1; N >= 0; N--) if (m[N].role === "assistant" && g(m[N].status)) {
308
+ A = N;
306
309
  break;
307
310
  }
308
- return w < 0 ? g : [
309
- ...g.slice(0, w),
311
+ return A < 0 ? m : [
312
+ ...m.slice(0, A),
310
313
  {
311
- ...g[w],
312
- ...m
314
+ ...m[A],
315
+ ...y
313
316
  },
314
- ...g.slice(w + 1)
317
+ ...m.slice(A + 1)
315
318
  ];
316
319
  });
317
- }, b = (m) => {
318
- s((g) => {
319
- const w = g.findIndex((S) => S.id === m.id);
320
- return w >= 0 ? [
321
- ...g.slice(0, w),
322
- m,
323
- ...g.slice(w + 1)
324
- ] : [...g, m];
325
- }), p(!1);
326
- }, d = (m) => {
327
- k(new Error(m.error)), p(!1);
328
- }, y = () => {
329
- s((m) => {
330
- let g = -1;
331
- for (let w = m.length - 1; w >= 0; w--) if (m[w].role === "assistant" && C(m[w].status)) {
332
- g = w;
320
+ }, x = (y) => {
321
+ l((m) => {
322
+ const A = m.findIndex((N) => N.id === y.id);
323
+ return A >= 0 ? [
324
+ ...m.slice(0, A),
325
+ y,
326
+ ...m.slice(A + 1)
327
+ ] : [...m, y];
328
+ }), c(!1);
329
+ }, f = (y) => {
330
+ v(new Error(y.error)), c(!1);
331
+ }, h = () => {
332
+ l((y) => {
333
+ let m = -1;
334
+ for (let A = y.length - 1; A >= 0; A--) if (y[A].role === "assistant" && g(y[A].status)) {
335
+ m = A;
333
336
  break;
334
337
  }
335
- return g < 0 ? m : m[g].content ? m.map((w, S) => S === g ? {
336
- ...w,
338
+ return m < 0 ? y : y[m].content ? y.map((A, N) => N === m ? {
339
+ ...A,
337
340
  status: "CANCELED"
338
- } : w) : m.filter((w, S) => S !== g);
339
- }), p(!1);
341
+ } : A) : y.filter((A, N) => N !== m);
342
+ }), c(!1);
340
343
  };
341
- return r.on("message:start", I), r.on("message:chunk", u), r.on("message:answer-complete", A), r.on("message:complete", b), r.on("message:error", d), r.on("message:stopped", y), () => {
342
- r.off("message:start", I), r.off("message:chunk", u), r.off("message:answer-complete", A), r.off("message:complete", b), r.off("message:error", d), r.off("message:stopped", y);
344
+ return o.on("message:start", R), o.on("message:chunk", d), o.on("message:answer-complete", w), o.on("message:complete", x), o.on("message:error", f), o.on("message:stopped", h), () => {
345
+ o.off("message:start", R), o.off("message:chunk", d), o.off("message:answer-complete", w), o.off("message:complete", x), o.off("message:error", f), o.off("message:stopped", h);
343
346
  };
344
- }, [r, i]), {
347
+ }, [o, s]), {
345
348
  messages: n,
346
- isLoading: c,
347
- error: f,
348
- sendMessage: R(async (C, I) => {
349
- p(!0), k(null);
350
- const u = {
349
+ isLoading: u,
350
+ error: p,
351
+ sendMessage: _(async (g, R) => {
352
+ c(!0), v(null);
353
+ const d = {
351
354
  id: `temp-${Date.now()}`,
352
- conversationId: i || "",
353
- content: C,
355
+ conversationId: s || "",
356
+ content: g,
354
357
  role: "user",
355
358
  status: "DONE",
356
- attachments: I && I.length > 0 ? Te(I) : void 0,
359
+ attachments: R && R.length > 0 ? Fe(R) : void 0,
357
360
  createdAt: /* @__PURE__ */ new Date()
358
- }, A = {
361
+ }, w = {
359
362
  id: `temp-assistant-${Date.now()}`,
360
- conversationId: i || "",
363
+ conversationId: s || "",
361
364
  content: "",
362
365
  role: "assistant",
363
366
  status: "IN_PROGRESS",
364
367
  createdAt: /* @__PURE__ */ new Date()
365
368
  };
366
- s((b) => [
367
- ...b,
368
- u,
369
- A
369
+ l((x) => [
370
+ ...x,
371
+ d,
372
+ w
370
373
  ]);
371
374
  try {
372
- const b = await r.sendMessage(C, {
373
- conversationId: i,
374
- files: I
375
+ const x = await o.sendMessage(g, {
376
+ conversationId: s,
377
+ files: R
375
378
  });
376
- return b.conversationId && !i && l(b.conversationId), s((d) => {
377
- const y = d.filter((g) => !g.id.startsWith("temp-")), m = {
378
- ...u,
379
- id: u.id.replace("temp-", "user-"),
380
- conversationId: b.conversationId
379
+ return x.conversationId && !s && i(x.conversationId), l((f) => {
380
+ const h = f.filter((m) => !m.id.startsWith("temp-")), y = {
381
+ ...d,
382
+ id: d.id.replace("temp-", "user-"),
383
+ conversationId: x.conversationId
381
384
  };
382
- return y.some((g) => g.id === b.id) ? [...y, m].sort((g, w) => new Date(g.createdAt).getTime() - new Date(w.createdAt).getTime()) : [
383
- ...y,
384
- m,
385
- b
385
+ return h.some((m) => m.id === x.id) ? [...h, y].sort((m, A) => new Date(m.createdAt).getTime() - new Date(A.createdAt).getTime()) : [
386
+ ...h,
387
+ y,
388
+ x
386
389
  ];
387
- }), b;
388
- } catch (b) {
389
- return k(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to send message")), p(!1), s((d) => d.filter((y) => !y.id.startsWith("temp-"))), null;
390
+ }), x;
391
+ } catch (x) {
392
+ return v(x instanceof Error ? x : /* @__PURE__ */ new Error("Failed to send message")), c(!1), l((f) => f.filter((h) => !h.id.startsWith("temp-"))), null;
390
393
  }
391
- }, [r, i]),
392
- stop: R(async () => {
393
- await r.stop();
394
- }, [r]),
395
- clearMessages: R(() => {
396
- s([]), l(void 0), k(null);
394
+ }, [o, s]),
395
+ stop: _(async () => {
396
+ await o.stop();
397
+ }, [o]),
398
+ clearMessages: _(() => {
399
+ l([]), i(void 0), v(null);
397
400
  }, []),
398
- conversationId: i
401
+ conversationId: s
399
402
  };
400
403
  }
401
- var ce = {
404
+ var de = {
402
405
  compact: !1,
403
406
  state: "peek",
404
407
  isModal: !1,
@@ -406,49 +409,49 @@ var ce = {
406
409
  style: {},
407
410
  attrs: {}
408
411
  }
409
- }, Ze = { tabindex: "tabIndex" };
410
- function Qe(e) {
411
- const o = {};
412
- for (const [t, r] of Object.entries(e)) o[Ze[t] ?? t] = r;
413
- return o;
412
+ }, nt = { tabindex: "tabIndex" };
413
+ function rt(e) {
414
+ const r = {};
415
+ for (const [t, o] of Object.entries(e)) r[nt[t] ?? t] = o;
416
+ return r;
414
417
  }
415
- function et(e) {
416
- const o = e !== !1, t = o ? e ?? {} : void 0, r = W(t?.onStateChange);
417
- r.current = t?.onStateChange;
418
- const n = H(() => {
419
- if (o)
420
- return He({
418
+ function ot(e) {
419
+ const r = e !== !1, t = r ? e ?? {} : void 0, o = D(t?.onStateChange);
420
+ o.current = t?.onStateChange;
421
+ const n = B(() => {
422
+ if (r)
423
+ return je({
421
424
  breakpoint: t?.breakpoint,
422
425
  initialState: t?.initialState,
423
426
  bottomOffset: t?.bottomOffset,
424
427
  peekHeight: t?.peekHeight,
425
- onStateChange: (i, l) => r.current?.(i, l)
428
+ onStateChange: (s, i) => o.current?.(s, i)
426
429
  });
427
430
  }, [
428
- o,
431
+ r,
429
432
  t?.breakpoint,
430
433
  t?.initialState,
431
434
  t?.bottomOffset,
432
435
  t?.peekHeight
433
- ]), s = ge(R((i) => n?.subscribe(i) ?? (() => {
434
- }), [n]), R(() => n?.getSnapshot() ?? ce, [n]), R(() => n?.getServerSnapshot() ?? ce, [n]));
436
+ ]), l = xe(_((s) => n?.subscribe(s) ?? (() => {
437
+ }), [n]), _(() => n?.getSnapshot() ?? de, [n]), _(() => n?.getServerSnapshot() ?? de, [n]));
435
438
  return {
436
- sheet: H(() => ({
437
- ...s,
439
+ sheet: B(() => ({
440
+ ...l,
438
441
  surface: {
439
- ...s.surface,
440
- attrs: Qe(s.surface.attrs)
442
+ ...l.surface,
443
+ attrs: rt(l.surface.attrs)
441
444
  }
442
- }), [s]),
443
- expand: R((i) => n?.expand(i), [n]),
444
- collapse: R((i) => n?.collapse(i), [n]),
445
- toggle: R((i) => n?.toggle(i), [n])
445
+ }), [l]),
446
+ expand: _((s) => n?.expand(s), [n]),
447
+ collapse: _((s) => n?.collapse(s), [n]),
448
+ toggle: _((s) => n?.toggle(s), [n])
446
449
  };
447
450
  }
448
- var tt = /(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;
449
- function ye(e) {
450
- const o = e.split(tt);
451
- return o.length === 1 ? e : o.map((t, r) => r % 2 === 0 || !t ? t : t.startsWith("`") ? /* @__PURE__ */ a("code", {
451
+ var at = /(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;
452
+ function we(e) {
453
+ const r = e.split(at);
454
+ return r.length === 1 ? e : r.map((t, o) => o % 2 === 0 || !t ? t : t.startsWith("`") ? /* @__PURE__ */ a("code", {
452
455
  style: {
453
456
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
454
457
  fontSize: "0.92em",
@@ -457,12 +460,12 @@ function ye(e) {
457
460
  backgroundColor: "rgba(0, 0, 0, 0.06)"
458
461
  },
459
462
  children: t.slice(1, -1)
460
- }, r) : t.startsWith("**") ? /* @__PURE__ */ a("strong", {
463
+ }, o) : t.startsWith("**") ? /* @__PURE__ */ a("strong", {
461
464
  style: { fontWeight: 600 },
462
465
  children: t.slice(2, -2)
463
- }, r) : /* @__PURE__ */ a("em", { children: t.slice(1, -1) }, r));
466
+ }, o) : /* @__PURE__ */ a("em", { children: t.slice(1, -1) }, o));
464
467
  }
465
- var nt = `
468
+ var it = `
466
469
  @keyframes ago-activity-enter {
467
470
  from { opacity: 0; transform: translateY(4px); }
468
471
  to { opacity: 1; transform: none; }
@@ -499,7 +502,7 @@ var nt = `
499
502
  color: var(--ago-activity-color, #5b5d5f);
500
503
  }
501
504
  }
502
- `, ot = ({ label: e }) => /* @__PURE__ */ T("div", {
505
+ `, st = ({ label: e }) => /* @__PURE__ */ M("div", {
503
506
  className: "ago-activity",
504
507
  role: "status",
505
508
  "aria-live": "polite",
@@ -520,36 +523,36 @@ var nt = `
520
523
  },
521
524
  children: [/* @__PURE__ */ a("span", {
522
525
  className: "ago-activity__label",
523
- children: ye(e)
524
- }, e), /* @__PURE__ */ a("style", { children: nt })]
525
- }), rt = ({ onSend: e, onStop: o, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: s = "" }) => {
526
- const [i, l] = z(""), [c, p] = z([]), f = W(null), k = W(null), _ = R(() => {
527
- const d = k.current;
528
- if (!d) return;
529
- const y = 110;
530
- d.style.height = "auto", d.style.height = `${Math.min(d.scrollHeight + 2, y)}px`, d.style.overflowY = d.scrollHeight + 2 > y ? "auto" : "hidden";
531
- }, []), C = R(async (d) => {
532
- if (d.preventDefault(), !i.trim() && c.length === 0) return;
533
- const y = i.trim(), m = c.length > 0 ? c : void 0;
534
- l(""), p([]), requestAnimationFrame(_), await e(y, m) === !1 && (l((g) => g.trim() ? g : y), m && p((g) => [...m, ...g]), requestAnimationFrame(_));
526
+ children: we(e)
527
+ }, e), /* @__PURE__ */ a("style", { children: it })]
528
+ }), lt = ({ onSend: e, onStop: r, disabled: t = !1, placeholder: o = "Type a message...", allowFiles: n = !1, className: l = "" }) => {
529
+ const [s, i] = T(""), [u, c] = T([]), p = D(null), v = D(null), S = _(() => {
530
+ const f = v.current;
531
+ if (!f) return;
532
+ const h = 110;
533
+ f.style.height = "auto", f.style.height = `${Math.min(f.scrollHeight + 2, h)}px`, f.style.overflowY = f.scrollHeight + 2 > h ? "auto" : "hidden";
534
+ }, []), g = _(async (f) => {
535
+ if (f.preventDefault(), !s.trim() && u.length === 0) return;
536
+ const h = s.trim(), y = u.length > 0 ? u : void 0;
537
+ i(""), c([]), requestAnimationFrame(S), await e(h, y) === !1 && (i((m) => m.trim() ? m : h), y && c((m) => [...y, ...m]), requestAnimationFrame(S));
535
538
  }, [
536
- i,
537
- c,
539
+ s,
540
+ u,
538
541
  e,
539
- _
540
- ]), I = R((d) => {
541
- d.key === "Enter" && !d.shiftKey && (d.preventDefault(), C(d));
542
- }, [C]), u = R((d) => {
543
- const y = Array.from(d.target.files || []);
544
- p((m) => [...m, ...y]);
545
- }, []), A = R((d) => {
546
- p((y) => y.filter((m, g) => g !== d));
547
- }, []), b = i.trim() || c.length > 0;
548
- return /* @__PURE__ */ T("form", {
549
- onSubmit: (d) => {
550
- C(d);
542
+ S
543
+ ]), R = _((f) => {
544
+ f.key === "Enter" && !f.shiftKey && (f.preventDefault(), g(f));
545
+ }, [g]), d = _((f) => {
546
+ const h = Array.from(f.target.files || []);
547
+ c((y) => [...y, ...h]);
548
+ }, []), w = _((f) => {
549
+ c((h) => h.filter((y, m) => m !== f));
550
+ }, []), x = s.trim() || u.length > 0;
551
+ return /* @__PURE__ */ M("form", {
552
+ onSubmit: (f) => {
553
+ g(f);
551
554
  },
552
- className: `ago-chat-input ${s}`,
555
+ className: `ago-chat-input ${l}`,
553
556
  style: {
554
557
  display: "flex",
555
558
  flexDirection: "column",
@@ -558,14 +561,14 @@ var nt = `
558
561
  borderTop: "1px solid #dee3e8",
559
562
  backgroundColor: "#fff"
560
563
  },
561
- children: [c.length > 0 && /* @__PURE__ */ a("div", {
564
+ children: [u.length > 0 && /* @__PURE__ */ a("div", {
562
565
  className: "ago-chat-input__files",
563
566
  style: {
564
567
  display: "flex",
565
568
  flexWrap: "wrap",
566
569
  gap: "6px"
567
570
  },
568
- children: c.map((d, y) => /* @__PURE__ */ T("div", {
571
+ children: u.map((f, h) => /* @__PURE__ */ M("div", {
569
572
  style: {
570
573
  display: "flex",
571
574
  alignItems: "center",
@@ -583,11 +586,11 @@ var nt = `
583
586
  textOverflow: "ellipsis",
584
587
  whiteSpace: "nowrap"
585
588
  },
586
- children: d.name
589
+ children: f.name
587
590
  }), /* @__PURE__ */ a("button", {
588
591
  type: "button",
589
- onClick: () => A(y),
590
- "aria-label": `Remove ${d.name}`,
592
+ onClick: () => w(h),
593
+ "aria-label": `Remove ${f.name}`,
591
594
  style: {
592
595
  flexShrink: 0,
593
596
  width: "44px",
@@ -606,17 +609,17 @@ var nt = `
606
609
  },
607
610
  children: "×"
608
611
  })]
609
- }, y))
610
- }), /* @__PURE__ */ T("div", {
612
+ }, h))
613
+ }), /* @__PURE__ */ M("div", {
611
614
  style: {
612
615
  display: "flex",
613
616
  gap: "8px",
614
617
  alignItems: "flex-end"
615
618
  },
616
619
  children: [
617
- n && /* @__PURE__ */ T(me, { children: [/* @__PURE__ */ a("button", {
620
+ n && /* @__PURE__ */ M(be, { children: [/* @__PURE__ */ a("button", {
618
621
  type: "button",
619
- onClick: () => f.current?.click(),
622
+ onClick: () => p.current?.click(),
620
623
  disabled: t,
621
624
  "aria-label": "Attach file",
622
625
  style: {
@@ -637,22 +640,22 @@ var nt = `
637
640
  },
638
641
  children: "+"
639
642
  }), /* @__PURE__ */ a("input", {
640
- ref: f,
643
+ ref: p,
641
644
  type: "file",
642
645
  multiple: !0,
643
- onChange: u,
646
+ onChange: d,
644
647
  style: { display: "none" }
645
648
  })] }),
646
649
  /* @__PURE__ */ a("textarea", {
647
- ref: k,
650
+ ref: v,
648
651
  className: "ago-chat-input__field",
649
- value: i,
650
- onChange: (d) => {
651
- l(d.target.value), _();
652
+ value: s,
653
+ onChange: (f) => {
654
+ i(f.target.value), S();
652
655
  },
653
- onKeyDown: I,
654
- placeholder: r,
655
- "aria-label": r,
656
+ onKeyDown: R,
657
+ placeholder: o,
658
+ "aria-label": o,
656
659
  disabled: t,
657
660
  rows: 1,
658
661
  style: {
@@ -672,16 +675,16 @@ var nt = `
672
675
  backgroundColor: "#f8f8f8",
673
676
  transition: "border-color 0.15s"
674
677
  },
675
- onFocus: (d) => {
676
- d.currentTarget.style.borderColor = "#1b5fc4";
678
+ onFocus: (f) => {
679
+ f.currentTarget.style.borderColor = "#1b5fc4";
677
680
  },
678
- onBlur: (d) => {
679
- d.currentTarget.style.borderColor = "#dee3e8";
681
+ onBlur: (f) => {
682
+ f.currentTarget.style.borderColor = "#dee3e8";
680
683
  }
681
684
  }),
682
- t && o ? /* @__PURE__ */ a("button", {
685
+ t && r ? /* @__PURE__ */ a("button", {
683
686
  type: "button",
684
- onClick: o,
687
+ onClick: r,
685
688
  "aria-label": "Stop generating",
686
689
  style: {
687
690
  minHeight: "44px",
@@ -698,15 +701,15 @@ var nt = `
698
701
  children: "Stop"
699
702
  }) : /* @__PURE__ */ a("button", {
700
703
  type: "submit",
701
- disabled: t || !b,
704
+ disabled: t || !x,
702
705
  style: {
703
706
  minHeight: "44px",
704
707
  padding: "10px 18px",
705
708
  border: "none",
706
709
  borderRadius: "20px",
707
- backgroundColor: t || !b ? "#b5bfc8" : "#03182f",
710
+ backgroundColor: t || !x ? "#b5bfc8" : "#03182f",
708
711
  color: "#fff",
709
- cursor: t || !b ? "not-allowed" : "pointer",
712
+ cursor: t || !x ? "not-allowed" : "pointer",
710
713
  fontWeight: 500,
711
714
  fontSize: "16px",
712
715
  transition: "background-color 0.15s"
@@ -716,7 +719,7 @@ var nt = `
716
719
  ]
717
720
  })]
718
721
  });
719
- }, at = ({ href: e, children: o, ...t }) => /* @__PURE__ */ a("a", {
722
+ }, ct = ({ href: e, children: r, ...t }) => /* @__PURE__ */ a("a", {
720
723
  href: e,
721
724
  target: "_blank",
722
725
  rel: "noopener noreferrer",
@@ -725,52 +728,52 @@ var nt = `
725
728
  textDecoration: "underline"
726
729
  },
727
730
  ...t,
728
- children: o
729
- }), it = ({ children: e, ...o }) => /* @__PURE__ */ a("p", {
731
+ children: r
732
+ }), dt = ({ children: e, ...r }) => /* @__PURE__ */ a("p", {
730
733
  style: {
731
734
  margin: "0 0 8px 0",
732
735
  lineHeight: "1.6"
733
736
  },
734
- ...o,
737
+ ...r,
735
738
  children: e
736
- }), j = (e, o) => {
737
- const t = ({ children: r, ...n }) => Be.createElement(`h${e}`, {
739
+ }), j = (e, r) => {
740
+ const t = ({ children: o, ...n }) => $e.createElement(`h${e}`, {
738
741
  style: {
739
742
  margin: "16px 0 8px 0",
740
- fontSize: o,
743
+ fontSize: r,
741
744
  fontWeight: 600,
742
745
  lineHeight: "1.3"
743
746
  },
744
747
  ...n
745
- }, r);
748
+ }, o);
746
749
  return t.displayName = `MarkdownHeading${e}`, t;
747
- }, st = ({ children: e, ...o }) => /* @__PURE__ */ a("ul", {
750
+ }, ut = ({ children: e, ...r }) => /* @__PURE__ */ a("ul", {
748
751
  style: {
749
752
  margin: "0 0 8px 0",
750
753
  paddingLeft: "20px",
751
754
  listStyleType: "disc",
752
755
  listStylePosition: "outside"
753
756
  },
754
- ...o,
757
+ ...r,
755
758
  children: e
756
- }), lt = ({ children: e, ...o }) => /* @__PURE__ */ a("ol", {
759
+ }), pt = ({ children: e, ...r }) => /* @__PURE__ */ a("ol", {
757
760
  style: {
758
761
  margin: "0 0 8px 0",
759
762
  paddingLeft: "20px",
760
763
  listStyleType: "decimal",
761
764
  listStylePosition: "outside"
762
765
  },
763
- ...o,
766
+ ...r,
764
767
  children: e
765
- }), ct = ({ children: e, ...o }) => /* @__PURE__ */ a("li", {
768
+ }), ft = ({ children: e, ...r }) => /* @__PURE__ */ a("li", {
766
769
  style: {
767
770
  display: "list-item",
768
771
  margin: "2px 0",
769
772
  lineHeight: "1.6"
770
773
  },
771
- ...o,
774
+ ...r,
772
775
  children: e
773
- }), dt = ({ className: e, children: o, ...t }) => e !== void 0 || String(o).includes(`
776
+ }), gt = ({ className: e, children: r, ...t }) => e !== void 0 || String(r).includes(`
774
777
  `) ? /* @__PURE__ */ a("code", {
775
778
  style: {
776
779
  display: "block",
@@ -782,7 +785,7 @@ var nt = `
782
785
  fontFamily: '"IBM Plex Mono", monospace'
783
786
  },
784
787
  ...t,
785
- children: o
788
+ children: r
786
789
  }) : /* @__PURE__ */ a("code", {
787
790
  style: {
788
791
  background: "#f0f2f5",
@@ -792,12 +795,12 @@ var nt = `
792
795
  fontFamily: '"IBM Plex Mono", monospace'
793
796
  },
794
797
  ...t,
795
- children: o
796
- }), ut = ({ children: e, ...o }) => /* @__PURE__ */ a("pre", {
798
+ children: r
799
+ }), mt = ({ children: e, ...r }) => /* @__PURE__ */ a("pre", {
797
800
  style: { margin: "0 0 8px 0" },
798
- ...o,
801
+ ...r,
799
802
  children: e
800
- }), pt = ({ children: e, ...o }) => /* @__PURE__ */ a("blockquote", {
803
+ }), ht = ({ children: e, ...r }) => /* @__PURE__ */ a("blockquote", {
801
804
  style: {
802
805
  borderLeft: "4px solid #dee3e8",
803
806
  paddingLeft: "12px",
@@ -805,9 +808,9 @@ var nt = `
805
808
  fontStyle: "italic",
806
809
  color: "#6b6d6f"
807
810
  },
808
- ...o,
811
+ ...r,
809
812
  children: e
810
- }), ft = ({ children: e, ...o }) => /* @__PURE__ */ a("div", {
813
+ }), xt = ({ children: e, ...r }) => /* @__PURE__ */ a("div", {
811
814
  style: {
812
815
  overflowX: "auto",
813
816
  margin: "0 0 8px 0"
@@ -818,10 +821,10 @@ var nt = `
818
821
  width: "100%",
819
822
  fontSize: "13px"
820
823
  },
821
- ...o,
824
+ ...r,
822
825
  children: e
823
826
  })
824
- }), gt = ({ children: e, ...o }) => /* @__PURE__ */ a("th", {
827
+ }), bt = ({ children: e, ...r }) => /* @__PURE__ */ a("th", {
825
828
  style: {
826
829
  border: "1px solid #dee3e8",
827
830
  padding: "6px 10px",
@@ -829,57 +832,57 @@ var nt = `
829
832
  backgroundColor: "#f5f7fa",
830
833
  fontWeight: 600
831
834
  },
832
- ...o,
835
+ ...r,
833
836
  children: e
834
- }), mt = ({ children: e, ...o }) => /* @__PURE__ */ a("td", {
837
+ }), yt = ({ children: e, ...r }) => /* @__PURE__ */ a("td", {
835
838
  style: {
836
839
  border: "1px solid #dee3e8",
837
840
  padding: "6px 10px"
838
841
  },
839
- ...o,
842
+ ...r,
840
843
  children: e
841
- }), ht = ({ alt: e, ...o }) => /* @__PURE__ */ a("img", {
844
+ }), vt = ({ alt: e, ...r }) => /* @__PURE__ */ a("img", {
842
845
  alt: e ?? "",
843
846
  style: {
844
847
  maxWidth: "100%",
845
848
  borderRadius: "8px",
846
849
  margin: "4px 0"
847
850
  },
848
- ...o
849
- }), xt = (e) => /* @__PURE__ */ a("hr", {
851
+ ...r
852
+ }), wt = (e) => /* @__PURE__ */ a("hr", {
850
853
  style: {
851
854
  border: "none",
852
855
  borderTop: "1px solid #dee3e8",
853
856
  margin: "12px 0"
854
857
  },
855
858
  ...e
856
- }), yt = {
857
- a: at,
858
- p: it,
859
+ }), kt = {
860
+ a: ct,
861
+ p: dt,
859
862
  h1: j(1, "20px"),
860
863
  h2: j(2, "18px"),
861
864
  h3: j(3, "16px"),
862
865
  h4: j(4, "15px"),
863
866
  h5: j(5, "14px"),
864
867
  h6: j(6, "13px"),
865
- ul: st,
866
- ol: lt,
867
- li: ct,
868
- code: dt,
869
- pre: ut,
870
- blockquote: pt,
871
- table: ft,
872
- th: gt,
873
- td: mt,
874
- img: ht,
875
- hr: xt
876
- }, vt = [Ue], bt = ({ content: e }) => /* @__PURE__ */ a(Ke, {
877
- remarkPlugins: vt,
878
- components: yt,
868
+ ul: ut,
869
+ ol: pt,
870
+ li: ft,
871
+ code: gt,
872
+ pre: mt,
873
+ blockquote: ht,
874
+ table: xt,
875
+ th: bt,
876
+ td: yt,
877
+ img: vt,
878
+ hr: wt
879
+ }, Ct = [Ye], St = ({ content: e }) => /* @__PURE__ */ a(Ve, {
880
+ remarkPlugins: Ct,
881
+ components: kt,
879
882
  children: e
880
- }), wt = ({ attachment: e, isUser: o }) => {
883
+ }), At = ({ attachment: e, isUser: r }) => {
881
884
  const t = We(e.url);
882
- if (Ee(e)) return /* @__PURE__ */ a("a", {
885
+ if (Pe(e)) return /* @__PURE__ */ a("a", {
883
886
  href: t,
884
887
  target: "_blank",
885
888
  rel: "noopener noreferrer",
@@ -901,7 +904,7 @@ var nt = `
901
904
  }
902
905
  })
903
906
  });
904
- const r = Fe(e.fileSize), n = /* @__PURE__ */ T(me, { children: [/* @__PURE__ */ a("span", {
907
+ const o = Le(e.fileSize), n = /* @__PURE__ */ M(be, { children: [/* @__PURE__ */ a("span", {
905
908
  style: {
906
909
  fontSize: "16px",
907
910
  lineHeight: 1,
@@ -909,7 +912,7 @@ var nt = `
909
912
  },
910
913
  "aria-hidden": !0,
911
914
  children: "📄"
912
- }), /* @__PURE__ */ T("span", {
915
+ }), /* @__PURE__ */ M("span", {
913
916
  style: {
914
917
  display: "flex",
915
918
  flexDirection: "column",
@@ -924,22 +927,22 @@ var nt = `
924
927
  },
925
928
  title: e.name,
926
929
  children: e.name
927
- }), r && /* @__PURE__ */ a("span", {
930
+ }), o && /* @__PURE__ */ a("span", {
928
931
  style: {
929
932
  fontSize: "11px",
930
933
  color: "#6b6d6f"
931
934
  },
932
- children: r
935
+ children: o
933
936
  })]
934
- })] }), s = {
937
+ })] }), l = {
935
938
  display: "inline-flex",
936
939
  alignItems: "center",
937
940
  gap: "8px",
938
941
  padding: "8px 12px",
939
942
  borderRadius: "10px",
940
943
  border: "1px solid #dee3e8",
941
- backgroundColor: o ? "rgba(255,255,255,0.12)" : "#fff",
942
- color: o ? "#fff" : "#30373e",
944
+ backgroundColor: r ? "rgba(255,255,255,0.12)" : "#fff",
945
+ color: r ? "#fff" : "#30373e",
943
946
  fontSize: "13px",
944
947
  textDecoration: "none",
945
948
  maxWidth: "220px"
@@ -948,14 +951,14 @@ var nt = `
948
951
  href: t,
949
952
  target: "_blank",
950
953
  rel: "noopener noreferrer",
951
- style: s,
954
+ style: l,
952
955
  children: n
953
956
  }) : /* @__PURE__ */ a("div", {
954
- style: s,
957
+ style: l,
955
958
  children: n
956
959
  });
957
- }, Ct = ({ source: e, index: o }) => {
958
- const t = /* @__PURE__ */ T("div", {
960
+ }, It = ({ source: e, index: r }) => {
961
+ const t = /* @__PURE__ */ M("div", {
959
962
  style: {
960
963
  display: "flex",
961
964
  alignItems: "center",
@@ -978,7 +981,7 @@ var nt = `
978
981
  justifyContent: "center",
979
982
  backgroundColor: "#f0f4ff"
980
983
  },
981
- children: o + 1
984
+ children: r + 1
982
985
  }), /* @__PURE__ */ a("div", {
983
986
  style: {
984
987
  fontSize: "12px",
@@ -990,7 +993,7 @@ var nt = `
990
993
  title: e.title,
991
994
  children: e.title
992
995
  })]
993
- }), r = {
996
+ }), o = {
994
997
  display: "flex",
995
998
  alignItems: "center",
996
999
  padding: "8px 10px",
@@ -1007,7 +1010,7 @@ var nt = `
1007
1010
  href: e.url,
1008
1011
  target: "_blank",
1009
1012
  rel: "noopener noreferrer",
1010
- style: r,
1013
+ style: o,
1011
1014
  onMouseEnter: (n) => {
1012
1015
  n.currentTarget.style.borderColor = "#1b5fc4";
1013
1016
  },
@@ -1016,10 +1019,10 @@ var nt = `
1016
1019
  },
1017
1020
  children: t
1018
1021
  }) : /* @__PURE__ */ a("div", {
1019
- style: r,
1022
+ style: o,
1020
1023
  children: t
1021
1024
  });
1022
- }, ve = () => /* @__PURE__ */ T("div", {
1025
+ }, ke = () => /* @__PURE__ */ M("div", {
1023
1026
  style: {
1024
1027
  display: "flex",
1025
1028
  gap: "4px",
@@ -1043,10 +1046,10 @@ var nt = `
1043
1046
  40% { opacity: 1; transform: scale(1); }
1044
1047
  }
1045
1048
  ` })]
1046
- }), kt = ({ message: e, className: o = "", showAgentName: t = !1, isLast: r = !1, onFollowUpClick: n, showStreamingDots: s = !0 }) => {
1047
- const i = e.role === "user", l = e.status === "IN_PROGRESS" || e.status === "WAITING_CLIENT";
1048
- return /* @__PURE__ */ T("div", {
1049
- className: `ago-message ago-message--${e.role} ${o}`,
1049
+ }), Nt = ({ message: e, className: r = "", showAgentName: t = !1, isLast: o = !1, onFollowUpClick: n, showStreamingDots: l = !0, feedback: s }) => {
1050
+ const i = e.role === "user", u = e.status === "IN_PROGRESS" || e.status === "WAITING_CLIENT";
1051
+ return /* @__PURE__ */ M("div", {
1052
+ className: `ago-message ago-message--${e.role} ${r}`,
1050
1053
  style: {
1051
1054
  display: "flex",
1052
1055
  flexDirection: "column",
@@ -1078,7 +1081,7 @@ var nt = `
1078
1081
  width: "100%",
1079
1082
  maxWidth: "85%"
1080
1083
  },
1081
- children: e.sources.map((c, p) => /* @__PURE__ */ a(Ct, {
1084
+ children: e.sources.map((c, p) => /* @__PURE__ */ a(It, {
1082
1085
  source: c,
1083
1086
  index: p
1084
1087
  }, c.id))
@@ -1093,12 +1096,12 @@ var nt = `
1093
1096
  justifyContent: i ? "flex-end" : "flex-start",
1094
1097
  maxWidth: "75%"
1095
1098
  },
1096
- children: e.attachments.map((c) => /* @__PURE__ */ a(wt, {
1099
+ children: e.attachments.map((c) => /* @__PURE__ */ a(At, {
1097
1100
  attachment: c,
1098
1101
  isUser: i
1099
1102
  }, c.id))
1100
1103
  }),
1101
- (e.content || l && s) && /* @__PURE__ */ a("div", {
1104
+ (e.content || u && l) && /* @__PURE__ */ a("div", {
1102
1105
  className: "ago-message__content",
1103
1106
  style: {
1104
1107
  maxWidth: i ? "75%" : "100%",
@@ -1110,9 +1113,10 @@ var nt = `
1110
1113
  fontSize: "16px",
1111
1114
  lineHeight: "1.6"
1112
1115
  },
1113
- children: e.content ? /* @__PURE__ */ a(bt, { content: e.content }) : l && s && /* @__PURE__ */ a(ve, {})
1116
+ children: e.content ? /* @__PURE__ */ a(St, { content: e.content }) : u && l && /* @__PURE__ */ a(ke, {})
1114
1117
  }),
1115
- r && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ a("div", {
1118
+ !i && s,
1119
+ o && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ a("div", {
1116
1120
  className: "ago-message__followups",
1117
1121
  style: {
1118
1122
  display: "flex",
@@ -1136,121 +1140,385 @@ var nt = `
1136
1140
  cursor: n ? "pointer" : "default",
1137
1141
  transition: "border-color 0.15s"
1138
1142
  },
1139
- onMouseEnter: (f) => {
1140
- f.currentTarget.style.borderColor = "#1b5fc4";
1143
+ onMouseEnter: (v) => {
1144
+ v.currentTarget.style.borderColor = "#1b5fc4";
1141
1145
  },
1142
- onMouseLeave: (f) => {
1143
- f.currentTarget.style.borderColor = "#dee3e8";
1146
+ onMouseLeave: (v) => {
1147
+ v.currentTarget.style.borderColor = "#dee3e8";
1144
1148
  },
1145
1149
  children: c
1146
1150
  }, p))
1147
1151
  })
1148
1152
  ]
1149
1153
  });
1150
- }, Ht = je(function({ client: o, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: s = "Type a message...", allowFiles: i = !1, allowStop: l = !0, height: c = 500, logoUrl: p, showAgentName: f = !1, forms: k, onFollowUpClick: _, className: C = "", onMessageSent: I, onMessageReceived: u, sheet: A = !1, thinkingLabel: b = "Thinking...", functionLabels: d, showReasoning: y = !0 }, m) {
1151
- const g = W(null), w = W(!0), [S, x] = z(!0), M = W(null), { sheet: v, expand: D, collapse: q, toggle: ee } = et(A), [be, Y] = z(!1), X = v.compact && v.state === "peek", we = O(), K = o ?? we, { messages: P, isLoading: Ce, error: te, sendMessage: ke, stop: Se } = xe({
1152
- client: o,
1154
+ };
1155
+ function Rt({ client: e } = {}) {
1156
+ const r = O(), t = e || r;
1157
+ if (!t) throw new X("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.", "missing_client");
1158
+ const [o, n] = T({}), [l, s] = T(!1), [i, u] = T(null), c = D(/* @__PURE__ */ new Map()), p = (S) => {
1159
+ const g = (c.current.get(S) ?? 0) + 1;
1160
+ return c.current.set(S, g), g;
1161
+ }, v = (S, g) => c.current.get(S) === g;
1162
+ return {
1163
+ ratings: o,
1164
+ submitFeedback: _(async (S, g, R) => {
1165
+ const d = p(S);
1166
+ s(!0), u(null);
1167
+ try {
1168
+ await t.submitFeedback(S, g, R), v(S, d) && n((w) => ({
1169
+ ...w,
1170
+ [S]: g
1171
+ }));
1172
+ } catch (w) {
1173
+ const x = w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to submit feedback");
1174
+ throw u(x), x;
1175
+ } finally {
1176
+ s(!1);
1177
+ }
1178
+ }, [t]),
1179
+ submitConversationFeedback: _(async (S, g, R) => {
1180
+ const d = p(S);
1181
+ s(!0), u(null);
1182
+ try {
1183
+ const w = await t.submitConversationFeedback(S, g, R);
1184
+ return v(S, d) && n((x) => ({
1185
+ ...x,
1186
+ [w]: g
1187
+ })), w;
1188
+ } catch (w) {
1189
+ const x = w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to submit feedback");
1190
+ throw u(x), x;
1191
+ } finally {
1192
+ s(!1);
1193
+ }
1194
+ }, [t]),
1195
+ isSubmitting: l,
1196
+ error: i
1197
+ };
1198
+ }
1199
+ var ue = {
1200
+ helpful: "Helpful",
1201
+ notHelpful: "Not helpful",
1202
+ whatWentWrong: "What went wrong?",
1203
+ reasons: {
1204
+ inaccurate: "Inaccurate",
1205
+ incomplete: "Incomplete",
1206
+ information_not_found: "Information not found",
1207
+ technical_issue: "Technical issue"
1208
+ },
1209
+ commentPlaceholder: "Anything else? (optional)",
1210
+ send: "Send",
1211
+ thanks: "Thanks, this was reported."
1212
+ }, _t = {
1213
+ display: "inline-flex",
1214
+ alignItems: "center",
1215
+ justifyContent: "center",
1216
+ width: "44px",
1217
+ height: "44px",
1218
+ margin: "-8px",
1219
+ padding: 0,
1220
+ border: "none",
1221
+ borderRadius: "8px",
1222
+ background: "transparent",
1223
+ cursor: "pointer",
1224
+ lineHeight: 1
1225
+ }, Et = ({ messageId: e, client: r, askWhy: t = !0, labels: o, onSubmit: n, onError: l, className: s = "" }) => {
1226
+ const i = {
1227
+ ...ue,
1228
+ ...o,
1229
+ reasons: {
1230
+ ...ue.reasons,
1231
+ ...o?.reasons
1232
+ }
1233
+ }, { ratings: u, submitFeedback: c } = Rt({ client: r }), p = u[e], [v, S] = T(!1), [g, R] = T([]), [d, w] = T(""), [x, f] = T(!1), [h, y] = T(!1), m = async (C, I) => {
1234
+ try {
1235
+ return await c(e, C, I), n?.({
1236
+ messageId: e,
1237
+ rating: C,
1238
+ reasons: I?.reasons ?? [],
1239
+ comment: I?.comment || void 0
1240
+ }), !0;
1241
+ } catch (L) {
1242
+ return l?.(L instanceof Error ? L : new Error(String(L))), !1;
1243
+ }
1244
+ }, A = (C) => {
1245
+ m(C), S(C === "negative" && t && !x);
1246
+ }, N = (C) => {
1247
+ R((I) => I.includes(C) ? I.filter((L) => L !== C) : [...I, C]);
1248
+ }, k = g.length > 0 || d.trim().length > 0, F = () => {
1249
+ !k || h || (y(!0), m(p ?? "negative", {
1250
+ reasons: g,
1251
+ comment: d.trim()
1252
+ }).then((C) => {
1253
+ y(!1), C && (f(!0), S(!1));
1254
+ }));
1255
+ };
1256
+ return /* @__PURE__ */ M("div", {
1257
+ className: `ago-feedback ${s}`,
1258
+ style: {
1259
+ marginTop: "6px",
1260
+ width: "100%",
1261
+ maxWidth: "85%"
1262
+ },
1263
+ children: [
1264
+ /* @__PURE__ */ M("div", {
1265
+ className: "ago-feedback__actions",
1266
+ style: {
1267
+ display: "flex",
1268
+ alignItems: "center",
1269
+ gap: "2px"
1270
+ },
1271
+ children: [/* @__PURE__ */ a(pe, {
1272
+ direction: "up",
1273
+ label: i.helpful,
1274
+ selected: p === "positive",
1275
+ onClick: () => A("positive")
1276
+ }), /* @__PURE__ */ a(pe, {
1277
+ direction: "down",
1278
+ label: i.notHelpful,
1279
+ selected: p === "negative",
1280
+ onClick: () => A("negative")
1281
+ })]
1282
+ }),
1283
+ x && /* @__PURE__ */ a("div", {
1284
+ className: "ago-feedback__thanks",
1285
+ role: "status",
1286
+ style: {
1287
+ marginTop: "6px",
1288
+ fontSize: "13px",
1289
+ color: "#6b6d6f"
1290
+ },
1291
+ children: i.thanks
1292
+ }),
1293
+ v && !x && /* @__PURE__ */ M("div", {
1294
+ className: "ago-feedback__panel",
1295
+ role: "group",
1296
+ "aria-label": i.whatWentWrong,
1297
+ style: {
1298
+ marginTop: "8px",
1299
+ padding: "12px",
1300
+ border: "1px solid #dee3e8",
1301
+ borderRadius: "16px",
1302
+ backgroundColor: "#fff"
1303
+ },
1304
+ children: [
1305
+ /* @__PURE__ */ a("div", {
1306
+ style: {
1307
+ fontSize: "13px",
1308
+ fontWeight: 500,
1309
+ color: "#30373e",
1310
+ marginBottom: "8px"
1311
+ },
1312
+ children: i.whatWentWrong
1313
+ }),
1314
+ /* @__PURE__ */ a("div", {
1315
+ className: "ago-feedback__reasons",
1316
+ style: {
1317
+ display: "flex",
1318
+ flexWrap: "wrap",
1319
+ gap: "6px",
1320
+ marginBottom: "8px"
1321
+ },
1322
+ children: He.map((C) => {
1323
+ const I = g.includes(C);
1324
+ return /* @__PURE__ */ a("button", {
1325
+ type: "button",
1326
+ className: "ago-feedback__reason",
1327
+ "aria-pressed": I,
1328
+ onClick: () => N(C),
1329
+ style: {
1330
+ minHeight: "44px",
1331
+ padding: "4px 12px",
1332
+ fontSize: "13px",
1333
+ fontFamily: "inherit",
1334
+ borderRadius: "999px",
1335
+ border: `1px solid ${I ? "#1b5fc4" : "#dee3e8"}`,
1336
+ backgroundColor: "transparent",
1337
+ color: I ? "#1b5fc4" : "#30373e",
1338
+ cursor: "pointer"
1339
+ },
1340
+ children: i.reasons[C]
1341
+ }, C);
1342
+ })
1343
+ }),
1344
+ /* @__PURE__ */ a("textarea", {
1345
+ className: "ago-feedback__comment",
1346
+ rows: 2,
1347
+ value: d,
1348
+ placeholder: i.commentPlaceholder,
1349
+ "aria-label": i.commentPlaceholder,
1350
+ onChange: (C) => w(C.target.value),
1351
+ style: {
1352
+ width: "100%",
1353
+ boxSizing: "border-box",
1354
+ padding: "8px 10px",
1355
+ fontSize: "14px",
1356
+ fontFamily: "inherit",
1357
+ color: "#30373e",
1358
+ border: "1px solid #dee3e8",
1359
+ borderRadius: "10px",
1360
+ backgroundColor: "transparent",
1361
+ resize: "vertical"
1362
+ }
1363
+ }),
1364
+ /* @__PURE__ */ a("button", {
1365
+ type: "button",
1366
+ className: "ago-feedback__send",
1367
+ onClick: F,
1368
+ disabled: !k || h,
1369
+ style: {
1370
+ marginTop: "8px",
1371
+ minHeight: "44px",
1372
+ padding: "6px 16px",
1373
+ fontSize: "14px",
1374
+ fontFamily: "inherit",
1375
+ borderRadius: "10px",
1376
+ border: "none",
1377
+ backgroundColor: k ? "#03182f" : "#b5bfc8",
1378
+ color: "#fff",
1379
+ opacity: h ? 0.6 : 1,
1380
+ cursor: k && !h ? "pointer" : "default"
1381
+ },
1382
+ children: i.send
1383
+ })
1384
+ ]
1385
+ })
1386
+ ]
1387
+ });
1388
+ }, pe = ({ direction: e, label: r, selected: t, onClick: o }) => /* @__PURE__ */ a("button", {
1389
+ type: "button",
1390
+ className: `ago-feedback__thumb ago-feedback__thumb--${e}`,
1391
+ "aria-label": r,
1392
+ "aria-pressed": t,
1393
+ title: r,
1394
+ onClick: o,
1395
+ style: {
1396
+ ..._t,
1397
+ color: t ? "#1b5fc4" : "#6b6d6f"
1398
+ },
1399
+ children: /* @__PURE__ */ M("svg", {
1400
+ width: "16",
1401
+ height: "16",
1402
+ viewBox: "0 0 24 24",
1403
+ fill: "none",
1404
+ "aria-hidden": "true",
1405
+ style: e === "down" ? { transform: "rotate(180deg)" } : void 0,
1406
+ children: [/* @__PURE__ */ a("path", {
1407
+ d: "M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",
1408
+ stroke: "currentColor",
1409
+ strokeWidth: "1.8",
1410
+ strokeLinejoin: "round"
1411
+ }), /* @__PURE__ */ a("path", {
1412
+ d: "M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",
1413
+ stroke: "currentColor",
1414
+ strokeWidth: "1.8",
1415
+ strokeLinejoin: "round"
1416
+ })]
1417
+ })
1418
+ }), Gt = Ue(function({ client: r, conversationId: t, title: o = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: l = "Type a message...", allowFiles: s = !1, allowStop: i = !0, height: u = 500, logoUrl: c, showAgentName: p = !1, forms: v, feedback: S = !1, onFollowUpClick: g, className: R = "", onMessageSent: d, onMessageReceived: w, sheet: x = !1, thinkingLabel: f = "Thinking...", functionLabels: h, showReasoning: y = !0 }, m) {
1419
+ const A = D(null), N = D(!0), [k, F] = T(!0), C = D(null), { sheet: I, expand: L, collapse: K, toggle: te } = ot(x), [Ce, Z] = T(!1), Q = I.compact && I.state === "peek", Se = O(), U = r ?? Se, { messages: P, isLoading: Ae, error: ne, sendMessage: Ie, stop: Ne } = ve({
1420
+ client: r,
1153
1421
  conversationId: t
1154
1422
  });
1155
- N(() => {
1156
- if (!K || !k || k.length === 0) return;
1157
- let h = !1;
1158
- const F = [];
1159
- return Promise.all(k.map((E) => E.schema != null ? Promise.resolve(pe(E)) : ue(K, E))).then((E) => {
1160
- if (!h)
1161
- for (const L of E) F.push(L.install(K));
1423
+ E(() => {
1424
+ if (!U || !v || v.length === 0) return;
1425
+ let b = !1;
1426
+ const z = [];
1427
+ return Promise.all(v.map((W) => W.schema != null ? Promise.resolve(me(W)) : ge(U, W))).then((W) => {
1428
+ if (!b)
1429
+ for (const H of W) z.push(H.install(U));
1162
1430
  }).catch(() => {
1163
1431
  }), () => {
1164
- h = !0, F.forEach((E) => E());
1432
+ b = !0, z.forEach((W) => W());
1165
1433
  };
1166
- }, [K, k ? JSON.stringify(k.map((h) => [
1167
- h.name,
1168
- h.schema ?? null,
1169
- h.submit ?? !1,
1170
- h.description ?? null
1171
- ])) : ""]), N(() => {
1172
- const h = g.current;
1173
- !h || !w.current || (h.scrollTop = h.scrollHeight);
1434
+ }, [U, v ? JSON.stringify(v.map((b) => [
1435
+ b.name,
1436
+ b.schema ?? null,
1437
+ b.submit ?? !1,
1438
+ b.description ?? null
1439
+ ])) : ""]), E(() => {
1440
+ const b = A.current;
1441
+ !b || !N.current || (b.scrollTop = b.scrollHeight);
1174
1442
  }, [P]);
1175
- const Ae = () => {
1176
- const h = g.current;
1177
- h && (w.current = !0, x(!0), h.scrollTop = h.scrollHeight);
1443
+ const Re = () => {
1444
+ const b = A.current;
1445
+ b && (N.current = !0, F(!0), b.scrollTop = b.scrollHeight);
1178
1446
  };
1179
- N(() => {
1180
- const h = P[P.length - 1];
1181
- h && h.role === "assistant" && h.status === "DONE" && u && u({
1182
- id: h.id,
1183
- content: h.content
1447
+ E(() => {
1448
+ const b = P[P.length - 1];
1449
+ b && b.role === "assistant" && b.status === "DONE" && w && w({
1450
+ id: b.id,
1451
+ content: b.content
1184
1452
  });
1185
- }, [P, u]), N(() => {
1186
- Y(!!X);
1187
- }, [P.length]), N(() => {
1188
- const h = M.current;
1189
- if (!v.compact || !h) return;
1190
- const F = document.documentElement;
1191
- if (v.state !== "peek") return;
1192
- const E = () => {
1193
- F.style.setProperty("--ago-sheet-height", `${Math.round(h.getBoundingClientRect().height)}px`);
1453
+ }, [P, w]), E(() => {
1454
+ Z(!!Q);
1455
+ }, [P.length]), E(() => {
1456
+ const b = C.current;
1457
+ if (!I.compact || !b) return;
1458
+ const z = document.documentElement;
1459
+ if (I.state !== "peek") return;
1460
+ const W = () => {
1461
+ z.style.setProperty("--ago-sheet-height", `${Math.round(b.getBoundingClientRect().height)}px`);
1194
1462
  };
1195
- E();
1196
- const L = typeof ResizeObserver == "function" ? new ResizeObserver(E) : null;
1197
- return L?.observe(h), () => L?.disconnect();
1198
- }, [v.compact, v.state]), N(() => {
1199
- v.compact || document.documentElement.style.removeProperty("--ago-sheet-height");
1200
- }, [v.compact]), N(() => () => {
1463
+ W();
1464
+ const H = typeof ResizeObserver == "function" ? new ResizeObserver(W) : null;
1465
+ return H?.observe(b), () => H?.disconnect();
1466
+ }, [I.compact, I.state]), E(() => {
1467
+ I.compact || document.documentElement.style.removeProperty("--ago-sheet-height");
1468
+ }, [I.compact]), E(() => () => {
1201
1469
  document.documentElement.style.removeProperty("--ago-sheet-height");
1202
- }, []), qe(m, () => ({
1203
- expand: D,
1204
- collapse: q,
1205
- toggle: ee,
1206
- state: v.state
1470
+ }, []), Je(m, () => ({
1471
+ expand: L,
1472
+ collapse: K,
1473
+ toggle: te,
1474
+ state: I.state
1207
1475
  }), [
1208
- D,
1209
- q,
1210
- ee,
1211
- v.state
1212
- ]), N(() => {
1213
- if (!v.isModal) return;
1214
- const h = /* @__PURE__ */ Symbol("ago-react-sheet");
1215
- Le(h);
1216
- const F = (E) => {
1217
- if (E.key === "Escape") {
1218
- q("user");
1476
+ L,
1477
+ K,
1478
+ te,
1479
+ I.state
1480
+ ]), E(() => {
1481
+ if (!I.isModal) return;
1482
+ const b = /* @__PURE__ */ Symbol("ago-react-sheet");
1483
+ Oe(b);
1484
+ const z = (W) => {
1485
+ if (W.key === "Escape") {
1486
+ K("user");
1219
1487
  return;
1220
1488
  }
1221
- if (E.key !== "Tab") return;
1222
- const L = M.current;
1223
- if (!L) return;
1224
- const J = Array.from(L.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((_e) => _e.getClientRects().length > 0);
1225
- if (J.length === 0) {
1226
- E.preventDefault();
1489
+ if (W.key !== "Tab") return;
1490
+ const H = C.current;
1491
+ if (!H) return;
1492
+ const V = Array.from(H.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((Me) => Me.getClientRects().length > 0);
1493
+ if (V.length === 0) {
1494
+ W.preventDefault();
1227
1495
  return;
1228
1496
  }
1229
- const ae = J[0], ie = J[J.length - 1], V = document.activeElement;
1230
- E.shiftKey && (V === ae || !L.contains(V)) ? (E.preventDefault(), ie.focus()) : !E.shiftKey && (V === ie || !L.contains(V)) && (E.preventDefault(), ae.focus());
1497
+ const ie = V[0], se = V[V.length - 1], Y = document.activeElement;
1498
+ W.shiftKey && (Y === ie || !H.contains(Y)) ? (W.preventDefault(), se.focus()) : !W.shiftKey && (Y === se || !H.contains(Y)) && (W.preventDefault(), ie.focus());
1231
1499
  };
1232
- return document.addEventListener("keydown", F), M.current?.focus({ preventScroll: !0 }), () => {
1233
- document.removeEventListener("keydown", F), De(h);
1500
+ return document.addEventListener("keydown", z), C.current?.focus({ preventScroll: !0 }), () => {
1501
+ document.removeEventListener("keydown", z), qe(b);
1234
1502
  };
1235
- }, [v.isModal, q]);
1236
- const ne = async (h, F) => (w.current = !0, x(!0), I?.(h), await ke(h, F) !== null), B = P[P.length - 1], G = Ce && B?.role === "assistant" && (B.status === "IN_PROGRESS" || B.status === "WAITING_CLIENT"), Ie = R((h) => {
1237
- const F = h.functionName;
1238
- if (!(!d || !F))
1239
- return typeof d == "function" ? d(F, h.arguments ?? {}) : d[F];
1240
- }, [d]), { items: Ne } = Xe({
1241
- client: K ?? void 0,
1242
- labelFor: Ie,
1503
+ }, [I.isModal, K]);
1504
+ const re = async (b, z) => (N.current = !0, F(!0), d?.(b), await Ie(b, z) !== null), q = P[P.length - 1], J = Ae && q?.role === "assistant" && (q.status === "IN_PROGRESS" || q.status === "WAITING_CLIENT"), _e = _((b) => {
1505
+ const z = b.functionName;
1506
+ if (!(!h || !z))
1507
+ return typeof h == "function" ? h(z, b.arguments ?? {}) : h[z];
1508
+ }, [h]), { items: Ee } = tt({
1509
+ client: U ?? void 0,
1510
+ labelFor: _e,
1243
1511
  includeReasoning: y
1244
- }), oe = Ne.filter((h) => B?.id !== void 0 && h.messageId === B.id), U = d === !1 ? void 0 : oe[oe.length - 1]?.label, re = !!(G && U), Re = _ === !1 ? void 0 : _ ?? ((h) => ne(h));
1245
- return /* @__PURE__ */ T("div", {
1246
- ref: M,
1247
- className: `ago-chat-widget ${C}`,
1248
- ...v.surface.attrs,
1249
- "data-ago-sheet-state": v.compact ? v.state : void 0,
1512
+ }), oe = Ee.filter((b) => q?.id !== void 0 && b.messageId === q.id), G = h === !1 ? void 0 : oe[oe.length - 1]?.label, ae = !!(J && G), Te = g === !1 ? void 0 : g ?? ((b) => re(b));
1513
+ return /* @__PURE__ */ M("div", {
1514
+ ref: C,
1515
+ className: `ago-chat-widget ${R}`,
1516
+ ...I.surface.attrs,
1517
+ "data-ago-sheet-state": I.compact ? I.state : void 0,
1250
1518
  style: {
1251
1519
  display: "flex",
1252
1520
  flexDirection: "column",
1253
- height: typeof c == "number" ? `${c}px` : c,
1521
+ height: typeof u == "number" ? `${u}px` : u,
1254
1522
  border: "1px solid #dee3e8",
1255
1523
  borderRadius: "16px",
1256
1524
  overflow: "hidden",
@@ -1258,10 +1526,10 @@ var nt = `
1258
1526
  fontFamily: '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
1259
1527
  textAlign: "left",
1260
1528
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px",
1261
- ...v.surface.style
1529
+ ...I.surface.style
1262
1530
  },
1263
1531
  children: [
1264
- !v.compact && /* @__PURE__ */ T("div", {
1532
+ !I.compact && /* @__PURE__ */ M("div", {
1265
1533
  className: "ago-chat-widget__header",
1266
1534
  style: {
1267
1535
  padding: "14px 16px",
@@ -1272,8 +1540,8 @@ var nt = `
1272
1540
  alignItems: "center",
1273
1541
  gap: "10px"
1274
1542
  },
1275
- children: [p && /* @__PURE__ */ a("img", {
1276
- src: p,
1543
+ children: [c && /* @__PURE__ */ a("img", {
1544
+ src: c,
1277
1545
  alt: "Logo",
1278
1546
  style: {
1279
1547
  height: "24px",
@@ -1285,16 +1553,16 @@ var nt = `
1285
1553
  fontSize: "15px",
1286
1554
  fontWeight: 600
1287
1555
  },
1288
- children: r
1556
+ children: o
1289
1557
  })]
1290
1558
  }),
1291
- X && /* @__PURE__ */ T("button", {
1559
+ Q && /* @__PURE__ */ M("button", {
1292
1560
  type: "button",
1293
1561
  className: "ago-chat-widget__peek",
1294
1562
  "aria-expanded": !1,
1295
1563
  "aria-label": "Open the conversation",
1296
1564
  onClick: () => {
1297
- Y(!1), D("user");
1565
+ Z(!1), L("user");
1298
1566
  },
1299
1567
  style: {
1300
1568
  display: "flex",
@@ -1311,7 +1579,7 @@ var nt = `
1311
1579
  font: "inherit",
1312
1580
  color: "inherit"
1313
1581
  },
1314
- children: [/* @__PURE__ */ T("span", {
1582
+ children: [/* @__PURE__ */ M("span", {
1315
1583
  style: {
1316
1584
  display: "flex",
1317
1585
  alignItems: "center",
@@ -1324,8 +1592,8 @@ var nt = `
1324
1592
  opacity: 0.7
1325
1593
  },
1326
1594
  children: [
1327
- r,
1328
- be && /* @__PURE__ */ a("span", {
1595
+ o,
1596
+ Ce && /* @__PURE__ */ a("span", {
1329
1597
  "aria-label": "New message",
1330
1598
  style: {
1331
1599
  width: "6px",
@@ -1343,13 +1611,13 @@ var nt = `
1343
1611
  children: "↑"
1344
1612
  })
1345
1613
  ]
1346
- }), G && !B?.content ? /* @__PURE__ */ T("span", {
1614
+ }), J && !q?.content ? /* @__PURE__ */ M("span", {
1347
1615
  style: {
1348
1616
  display: "flex",
1349
1617
  alignItems: "center",
1350
1618
  gap: "8px"
1351
1619
  },
1352
- children: [!U && /* @__PURE__ */ a(ve, {}), /* @__PURE__ */ a("span", {
1620
+ children: [!G && /* @__PURE__ */ a(ke, {}), /* @__PURE__ */ a("span", {
1353
1621
  style: {
1354
1622
  fontSize: "13px",
1355
1623
  opacity: 0.7,
@@ -1357,7 +1625,7 @@ var nt = `
1357
1625
  textOverflow: "ellipsis",
1358
1626
  whiteSpace: "nowrap"
1359
1627
  },
1360
- children: U ? ye(U) : b
1628
+ children: G ? we(G) : f
1361
1629
  })]
1362
1630
  }) : /* @__PURE__ */ a("span", {
1363
1631
  style: {
@@ -1370,10 +1638,10 @@ var nt = `
1370
1638
  color: "inherit",
1371
1639
  minHeight: "calc(2 * 1.5 * 13px)"
1372
1640
  },
1373
- children: B?.content || n
1641
+ children: q?.content || n
1374
1642
  })]
1375
1643
  }),
1376
- v.compact && v.state === "full" && /* @__PURE__ */ T("div", {
1644
+ I.compact && I.state === "full" && /* @__PURE__ */ M("div", {
1377
1645
  className: "ago-chat-widget__sheet-header",
1378
1646
  style: {
1379
1647
  display: "flex",
@@ -1395,11 +1663,11 @@ var nt = `
1395
1663
  whiteSpace: "nowrap",
1396
1664
  textOverflow: "ellipsis"
1397
1665
  },
1398
- children: r
1666
+ children: o
1399
1667
  }), /* @__PURE__ */ a("button", {
1400
1668
  type: "button",
1401
1669
  "aria-label": "Collapse the conversation",
1402
- onClick: () => q("user"),
1670
+ onClick: () => K("user"),
1403
1671
  style: {
1404
1672
  marginLeft: "auto",
1405
1673
  flexShrink: 0,
@@ -1427,25 +1695,25 @@ var nt = `
1427
1695
  })
1428
1696
  })]
1429
1697
  }),
1430
- /* @__PURE__ */ T("div", {
1698
+ /* @__PURE__ */ M("div", {
1431
1699
  style: {
1432
1700
  position: "relative",
1433
1701
  flex: 1,
1434
- display: X ? "none" : "flex",
1702
+ display: Q ? "none" : "flex",
1435
1703
  minHeight: 0
1436
1704
  },
1437
- children: [/* @__PURE__ */ T("div", {
1438
- ref: g,
1705
+ children: [/* @__PURE__ */ M("div", {
1706
+ ref: A,
1439
1707
  className: "ago-chat-widget__messages",
1440
- onScroll: (h) => {
1441
- const F = h.currentTarget, E = F.scrollHeight - F.scrollTop - F.clientHeight <= 48;
1442
- w.current = E, x(E);
1708
+ onScroll: (b) => {
1709
+ const z = b.currentTarget, W = z.scrollHeight - z.scrollTop - z.clientHeight <= 48;
1710
+ N.current = W, F(W);
1443
1711
  },
1444
1712
  role: "log",
1445
1713
  "aria-live": "polite",
1446
1714
  "aria-relevant": "additions text",
1447
1715
  "aria-atomic": !1,
1448
- "aria-busy": G,
1716
+ "aria-busy": J,
1449
1717
  style: {
1450
1718
  flex: 1,
1451
1719
  overflow: "auto",
@@ -1463,15 +1731,20 @@ var nt = `
1463
1731
  lineHeight: "1.5"
1464
1732
  },
1465
1733
  children: n
1466
- }) : P.map((h, F) => /* @__PURE__ */ a(kt, {
1467
- message: h,
1468
- showAgentName: f,
1469
- isLast: F === P.length - 1,
1470
- onFollowUpClick: Re,
1471
- showStreamingDots: !re
1472
- }, h.id)),
1473
- re && /* @__PURE__ */ a(ot, { label: U ?? "" }),
1474
- te && /* @__PURE__ */ a("div", {
1734
+ }) : P.map((b, z) => /* @__PURE__ */ a(Nt, {
1735
+ message: b,
1736
+ showAgentName: p,
1737
+ isLast: z === P.length - 1,
1738
+ onFollowUpClick: Te,
1739
+ showStreamingDots: !ae,
1740
+ feedback: S && b.role === "assistant" && b.status === "DONE" && b.content ? /* @__PURE__ */ a(Et, {
1741
+ messageId: b.id,
1742
+ client: r,
1743
+ ...S === !0 ? {} : S
1744
+ }) : void 0
1745
+ }, b.id)),
1746
+ ae && /* @__PURE__ */ a(st, { label: G ?? "" }),
1747
+ ne && /* @__PURE__ */ a("div", {
1475
1748
  role: "alert",
1476
1749
  style: {
1477
1750
  padding: "10px 14px",
@@ -1482,15 +1755,15 @@ var nt = `
1482
1755
  fontSize: "13px",
1483
1756
  border: "1px solid #fecaca"
1484
1757
  },
1485
- children: te.message
1758
+ children: ne.message
1486
1759
  }),
1487
1760
  /* @__PURE__ */ a("div", {})
1488
1761
  ]
1489
- }), !S && /* @__PURE__ */ a("button", {
1762
+ }), !k && /* @__PURE__ */ a("button", {
1490
1763
  type: "button",
1491
1764
  className: "ago-chat-widget__jump",
1492
1765
  "aria-label": "Jump to latest message",
1493
- onClick: Ae,
1766
+ onClick: Re,
1494
1767
  style: {
1495
1768
  position: "absolute",
1496
1769
  left: "50%",
@@ -1523,68 +1796,68 @@ var nt = `
1523
1796
  })
1524
1797
  })]
1525
1798
  }),
1526
- /* @__PURE__ */ a(rt, {
1527
- onSend: ne,
1528
- onStop: l ? () => {
1529
- Se();
1799
+ /* @__PURE__ */ a(lt, {
1800
+ onSend: re,
1801
+ onStop: i ? () => {
1802
+ Ne();
1530
1803
  } : void 0,
1531
- disabled: G,
1532
- placeholder: s,
1533
- allowFiles: i
1804
+ disabled: J,
1805
+ placeholder: l,
1806
+ allowFiles: s
1534
1807
  })
1535
1808
  ]
1536
1809
  });
1537
1810
  });
1538
- function St(e = {}) {
1539
- const o = O(), t = e.client ?? o;
1540
- if (!t) throw new Z("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.", "proactive_missing_client");
1541
- const [r, n] = z(null), s = W(r);
1542
- s.current = r;
1543
- const i = W(e.onExpand);
1544
- return i.current = e.onExpand, N(() => {
1545
- const l = (p) => {
1546
- n(p), t.proactive?.shown(p);
1547
- }, c = ({ nudge: p }) => {
1548
- n((f) => f?.id === p.id ? null : f);
1811
+ function Tt(e = {}) {
1812
+ const r = O(), t = e.client ?? r;
1813
+ if (!t) throw new X("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.", "proactive_missing_client");
1814
+ const [o, n] = T(null), l = D(o);
1815
+ l.current = o;
1816
+ const s = D(e.onExpand);
1817
+ return s.current = e.onExpand, E(() => {
1818
+ const i = (c) => {
1819
+ n(c), t.proactive?.shown(c);
1820
+ }, u = ({ nudge: c }) => {
1821
+ n((p) => p?.id === c.id ? null : p);
1549
1822
  };
1550
- return t.on("nudge:ready", l), t.on("nudge:accepted", c), t.on("nudge:dismissed", c), () => {
1551
- t.off("nudge:ready", l), t.off("nudge:accepted", c), t.off("nudge:dismissed", c);
1823
+ return t.on("nudge:ready", i), t.on("nudge:accepted", u), t.on("nudge:dismissed", u), () => {
1824
+ t.off("nudge:ready", i), t.off("nudge:accepted", u), t.off("nudge:dismissed", u);
1552
1825
  };
1553
1826
  }, [t]), {
1554
- nudge: r,
1555
- accept: R(async () => {
1556
- const l = s.current;
1557
- l && (n(null), await t.proactive?.accept(l), (l.source === "agent" || l.goal) && i.current?.(l));
1827
+ nudge: o,
1828
+ accept: _(async () => {
1829
+ const i = l.current;
1830
+ i && (n(null), await t.proactive?.accept(i), (i.source === "agent" || i.goal) && s.current?.(i));
1558
1831
  }, [t]),
1559
- dismiss: R(() => {
1560
- const l = s.current;
1561
- l && (n(null), t.proactive?.dismiss(l));
1832
+ dismiss: _(() => {
1833
+ const i = l.current;
1834
+ i && (n(null), t.proactive?.dismiss(i));
1562
1835
  }, [t])
1563
1836
  };
1564
1837
  }
1565
- var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right", openChatLabel: n = "Open chat", className: s = "" }) => {
1566
- const { nudge: i, accept: l, dismiss: c } = St({
1838
+ var Jt = ({ client: e, onExpand: r, autoHideMs: t, position: o = "bottom-right", openChatLabel: n = "Open chat", className: l = "" }) => {
1839
+ const { nudge: s, accept: i, dismiss: u } = Tt({
1567
1840
  client: e,
1568
- onExpand: o
1841
+ onExpand: r
1569
1842
  });
1570
- if (N(() => {
1571
- if (!i || !t) return;
1572
- const f = setTimeout(() => c(), t);
1573
- return () => clearTimeout(f);
1843
+ if (E(() => {
1844
+ if (!s || !t) return;
1845
+ const p = setTimeout(() => u(), t);
1846
+ return () => clearTimeout(p);
1574
1847
  }, [
1575
- i,
1848
+ s,
1576
1849
  t,
1577
- c
1578
- ]), !i) return null;
1579
- const p = i.source === "agent" || !!i.goal;
1580
- return /* @__PURE__ */ T("div", {
1581
- className: `ago-nudge ${s}`,
1850
+ u
1851
+ ]), !s) return null;
1852
+ const c = s.source === "agent" || !!s.goal;
1853
+ return /* @__PURE__ */ M("div", {
1854
+ className: `ago-nudge ${l}`,
1582
1855
  role: "status",
1583
1856
  "aria-live": "polite",
1584
1857
  style: {
1585
1858
  position: "fixed",
1586
1859
  bottom: "90px",
1587
- ...r === "bottom-left" ? { left: "20px" } : { right: "20px" },
1860
+ ...o === "bottom-left" ? { left: "20px" } : { right: "20px" },
1588
1861
  zIndex: 2147483e3,
1589
1862
  maxWidth: "320px",
1590
1863
  padding: "14px 16px",
@@ -1603,7 +1876,7 @@ var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right",
1603
1876
  type: "button",
1604
1877
  className: "ago-nudge__close",
1605
1878
  "aria-label": "Dismiss",
1606
- onClick: c,
1879
+ onClick: u,
1607
1880
  style: {
1608
1881
  position: "absolute",
1609
1882
  top: "6px",
@@ -1621,9 +1894,9 @@ var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right",
1621
1894
  /* @__PURE__ */ a("div", {
1622
1895
  className: "ago-nudge__message",
1623
1896
  style: { paddingRight: "16px" },
1624
- children: i.message
1897
+ children: s.message
1625
1898
  }),
1626
- (i.action || p) && /* @__PURE__ */ T("div", {
1899
+ (s.action || c) && /* @__PURE__ */ M("div", {
1627
1900
  className: "ago-nudge__actions",
1628
1901
  style: {
1629
1902
  display: "flex",
@@ -1631,11 +1904,11 @@ var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right",
1631
1904
  marginTop: "10px",
1632
1905
  flexWrap: "wrap"
1633
1906
  },
1634
- children: [i.action && /* @__PURE__ */ a("button", {
1907
+ children: [s.action && /* @__PURE__ */ a("button", {
1635
1908
  type: "button",
1636
1909
  className: "ago-nudge__action",
1637
1910
  onClick: () => {
1638
- l();
1911
+ i();
1639
1912
  },
1640
1913
  style: {
1641
1914
  border: "none",
@@ -1647,12 +1920,12 @@ var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right",
1647
1920
  fontWeight: 600,
1648
1921
  cursor: "pointer"
1649
1922
  },
1650
- children: i.action.label
1651
- }), p && /* @__PURE__ */ a("button", {
1923
+ children: s.action.label
1924
+ }), c && /* @__PURE__ */ a("button", {
1652
1925
  type: "button",
1653
1926
  className: "ago-nudge__expand",
1654
1927
  onClick: () => {
1655
- l();
1928
+ i();
1656
1929
  },
1657
1930
  style: {
1658
1931
  border: "1px solid #dee3e8",
@@ -1670,61 +1943,61 @@ var Bt = ({ client: e, onExpand: o, autoHideMs: t, position: r = "bottom-right",
1670
1943
  ]
1671
1944
  });
1672
1945
  };
1673
- function At({ client: e, autoLoad: o = !0 } = {}) {
1674
- const t = O(), r = e || t;
1675
- if (!r) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
1676
- const [n, s] = z([]), [i, l] = z(null), [c, p] = z(!1), [f, k] = z(null), _ = R(async () => {
1677
- p(!0), k(null);
1946
+ function Mt({ client: e, autoLoad: r = !0 } = {}) {
1947
+ const t = O(), o = e || t;
1948
+ if (!o) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
1949
+ const [n, l] = T([]), [s, i] = T(null), [u, c] = T(!1), [p, v] = T(null), S = _(async () => {
1950
+ c(!0), v(null);
1678
1951
  try {
1679
- const { data: u } = await r.getConversations();
1680
- s(u);
1681
- } catch (u) {
1682
- k(u instanceof Error ? u : /* @__PURE__ */ new Error("Failed to load conversations"));
1952
+ const { data: d } = await o.getConversations();
1953
+ l(d);
1954
+ } catch (d) {
1955
+ v(d instanceof Error ? d : /* @__PURE__ */ new Error("Failed to load conversations"));
1683
1956
  } finally {
1684
- p(!1);
1957
+ c(!1);
1685
1958
  }
1686
- }, [r]), C = R(async (u) => {
1687
- p(!0), k(null);
1959
+ }, [o]), g = _(async (d) => {
1960
+ c(!0), v(null);
1688
1961
  try {
1689
- l(await r.getConversation(u));
1690
- } catch (A) {
1691
- k(A instanceof Error ? A : /* @__PURE__ */ new Error("Failed to load conversation"));
1962
+ i(await o.getConversation(d));
1963
+ } catch (w) {
1964
+ v(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversation"));
1692
1965
  } finally {
1693
- p(!1);
1966
+ c(!1);
1694
1967
  }
1695
- }, [r]), I = R(() => {
1696
- l(null);
1968
+ }, [o]), R = _(() => {
1969
+ i(null);
1697
1970
  }, []);
1698
- return N(() => {
1699
- o && _();
1700
- }, [o, _]), {
1971
+ return E(() => {
1972
+ r && S();
1973
+ }, [r, S]), {
1701
1974
  conversations: n,
1702
- currentConversation: i,
1703
- isLoading: c,
1704
- error: f,
1705
- selectConversation: C,
1706
- startNewConversation: I,
1707
- refreshConversations: _
1975
+ currentConversation: s,
1976
+ isLoading: u,
1977
+ error: p,
1978
+ selectConversation: g,
1979
+ startNewConversation: R,
1980
+ refreshConversations: S
1708
1981
  };
1709
1982
  }
1710
- function Ot(e = {}) {
1711
- const o = O(), t = e.client || o;
1983
+ function Vt(e = {}) {
1984
+ const r = O(), t = e.client || r;
1712
1985
  if (!t) throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
1713
- const r = xe({
1986
+ const o = ve({
1714
1987
  client: t,
1715
1988
  conversationId: e.conversationId
1716
- }), n = At({
1989
+ }), n = Mt({
1717
1990
  client: t,
1718
1991
  autoLoad: e.autoLoad
1719
1992
  });
1720
1993
  return {
1721
- messages: r.messages,
1722
- isLoading: r.isLoading,
1723
- error: r.error || n.error,
1724
- sendMessage: r.sendMessage,
1725
- stop: r.stop,
1726
- clearMessages: r.clearMessages,
1727
- conversationId: r.conversationId,
1994
+ messages: o.messages,
1995
+ isLoading: o.isLoading,
1996
+ error: o.error || n.error,
1997
+ sendMessage: o.sendMessage,
1998
+ stop: o.stop,
1999
+ clearMessages: o.clearMessages,
2000
+ conversationId: o.conversationId,
1728
2001
  conversations: n.conversations,
1729
2002
  currentConversation: n.currentConversation,
1730
2003
  isConversationsLoading: n.isLoading,
@@ -1733,182 +2006,189 @@ function Ot(e = {}) {
1733
2006
  refreshConversations: n.refreshConversations
1734
2007
  };
1735
2008
  }
1736
- function jt(e, o) {
1737
- const t = $(), { name: r, description: n, parameters: s, handler: i, maxResultBytes: l, requiresApproval: c } = typeof e == "string" ? {
2009
+ function Yt(e, r) {
2010
+ const t = $(), { name: o, description: n, parameters: l, handler: s, maxResultBytes: i, requiresApproval: u } = typeof e == "string" ? {
1738
2011
  name: e,
1739
- ...o
1740
- } : e, p = W(i);
1741
- p.current = i, N(() => {
1742
- const f = (k) => p.current(k);
1743
- return t.registerFunction(r, f, {
2012
+ ...r
2013
+ } : e, c = D(s);
2014
+ c.current = s, E(() => {
2015
+ const p = (v) => c.current(v);
2016
+ return t.registerFunction(o, p, {
1744
2017
  description: n,
1745
- parameters: s,
1746
- maxResultBytes: l,
1747
- requiresApproval: c
2018
+ parameters: l,
2019
+ maxResultBytes: i,
2020
+ requiresApproval: u
1748
2021
  }), () => {
1749
- t.unregisterFunction(r);
2022
+ t.unregisterFunction(o);
1750
2023
  };
1751
2024
  }, [
1752
2025
  t,
1753
- r,
2026
+ o,
1754
2027
  n,
1755
- s,
1756
2028
  l,
1757
- c
2029
+ i,
2030
+ u
1758
2031
  ]);
1759
2032
  }
1760
- function $t(e, o) {
1761
- const t = $(), r = W(e);
1762
- r.current = e, N(() => (t.registerNavigationFunction((n) => r.current(n), o), () => {
2033
+ function Xt(e, r) {
2034
+ const t = $(), o = D(e);
2035
+ o.current = e, E(() => (t.registerNavigationFunction((n) => o.current(n), r), () => {
1763
2036
  t.unregisterNavigationFunction();
1764
- }), [t, o]);
2037
+ }), [t, r]);
1765
2038
  }
1766
- function qt(e, o) {
1767
- const t = $(), r = o?.functionName ?? "setPageState", n = o?.requiresApproval, s = o?.data !== void 0, i = o?.data?.description, l = o?.data?.maxResultBytes, c = o?.settleTimeoutMs, p = W(e);
1768
- p.current = e;
1769
- const f = W(o);
1770
- f.current = o, N(() => {
1771
- const k = p.current.map((C) => {
1772
- const I = () => p.current.find((u) => u.name === C.name) ?? C;
2039
+ function Zt(e, r) {
2040
+ const t = $(), o = r?.functionName ?? "setPageState", n = r?.requiresApproval, l = r?.data !== void 0, s = r?.data?.description, i = r?.data?.maxResultBytes, u = r?.settleTimeoutMs, c = D(e);
2041
+ c.current = e;
2042
+ const p = D(r);
2043
+ p.current = r, E(() => {
2044
+ const v = c.current.map((g) => {
2045
+ const R = () => c.current.find((d) => d.name === g.name) ?? g;
1773
2046
  return {
1774
- name: C.name,
1775
- description: C.description,
1776
- schema: C.schema,
1777
- get: C.get ? () => I().get?.() : void 0,
1778
- set: (u) => I().set(u)
2047
+ name: g.name,
2048
+ description: g.description,
2049
+ schema: g.schema,
2050
+ clearable: g.clearable,
2051
+ get: g.get ? () => R().get?.() : void 0,
2052
+ set: (d) => R().set(d)
1779
2053
  };
1780
- }), _ = s ? {
1781
- description: i ?? "What the page is currently showing.",
1782
- maxResultBytes: l,
1783
- get: () => f.current?.data?.get(),
1784
- isLoading: () => f.current?.data?.isLoading?.() ?? !1
2054
+ }), S = l ? {
2055
+ description: s ?? "What the page is currently showing.",
2056
+ maxResultBytes: i,
2057
+ get: () => p.current?.data?.get(),
2058
+ isLoading: () => p.current?.data?.isLoading?.() ?? !1
1785
2059
  } : void 0;
1786
- return t.registerPageStateFunction(k, {
1787
- functionName: r,
2060
+ return t.registerPageStateFunction(v, {
2061
+ functionName: o,
1788
2062
  requiresApproval: n,
1789
- data: _,
1790
- settleTimeoutMs: c
2063
+ data: S,
2064
+ settleTimeoutMs: u
1791
2065
  }), () => {
1792
- t.unregisterPageStateFunction(r);
2066
+ t.unregisterPageStateFunction(o);
1793
2067
  };
1794
2068
  }, [
1795
2069
  t,
1796
- r,
2070
+ o,
1797
2071
  n,
2072
+ l,
1798
2073
  s,
1799
2074
  i,
1800
- l,
1801
- c
2075
+ u,
2076
+ JSON.stringify(e.map((v) => ({
2077
+ name: v.name,
2078
+ description: v.description,
2079
+ schema: v.schema,
2080
+ clearable: v.clearable
2081
+ })))
1802
2082
  ]);
1803
2083
  }
1804
- function Kt(e) {
1805
- const o = $(), t = W(e);
1806
- t.current = e, N(() => Pe(o, () => t.current), [o]);
2084
+ function Qt(e) {
2085
+ const r = $(), t = D(e);
2086
+ t.current = e, E(() => Be(r, () => t.current), [r]);
1807
2087
  }
1808
- function Ut(e = {}) {
1809
- const o = O(), t = e.client || o;
1810
- if (!t) throw new Z("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.", "provider_missing_client");
1811
- const [r, n] = z(() => t.getRecentActivity());
1812
- N(() => {
2088
+ function en(e = {}) {
2089
+ const r = O(), t = e.client || r;
2090
+ if (!t) throw new X("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.", "provider_missing_client");
2091
+ const [o, n] = T(() => t.getRecentActivity());
2092
+ E(() => {
1813
2093
  n(t.getRecentActivity());
1814
- const l = () => n(t.getRecentActivity());
1815
- return t.on("activity:recorded", l), () => t.off("activity:recorded", l);
2094
+ const i = () => n(t.getRecentActivity());
2095
+ return t.on("activity:recorded", i), () => t.off("activity:recorded", i);
1816
2096
  }, [t]);
1817
- const s = R((l) => t.recordActivity(l), [t]), i = R(() => {
2097
+ const l = _((i) => t.recordActivity(i), [t]), s = _(() => {
1818
2098
  t.clearActivity(), n([]);
1819
2099
  }, [t]);
1820
2100
  return {
1821
- entries: r,
1822
- latest: r.length > 0 ? r[r.length - 1] : void 0,
1823
- record: s,
1824
- clear: i
2101
+ entries: o,
2102
+ latest: o.length > 0 ? o[o.length - 1] : void 0,
2103
+ record: l,
2104
+ clear: s
1825
2105
  };
1826
2106
  }
1827
- function Gt(e, o) {
1828
- const t = $(), r = $e(), n = o ?? r, s = W(e);
1829
- s.current = e;
1830
- const i = typeof e == "function";
1831
- N(() => {
1832
- if (typeof s.current == "function") {
1833
- const l = () => s.current();
1834
- return t.addDynamicContext(n, l), () => {
2107
+ function tn(e, r) {
2108
+ const t = $(), o = Ge(), n = r ?? o, l = D(e);
2109
+ l.current = e;
2110
+ const s = typeof e == "function";
2111
+ E(() => {
2112
+ if (typeof l.current == "function") {
2113
+ const i = () => l.current();
2114
+ return t.addDynamicContext(n, i), () => {
1835
2115
  t.removeDynamicContext(n);
1836
2116
  };
1837
2117
  }
1838
- return t.setContext(n, s.current), () => {
2118
+ return t.setContext(n, l.current), () => {
1839
2119
  t.removeContext(n);
1840
2120
  };
1841
2121
  }, [
1842
2122
  t,
1843
2123
  n,
1844
- i,
1845
- i ? "" : JSON.stringify(e)
2124
+ s,
2125
+ s ? "" : JSON.stringify(e)
1846
2126
  ]);
1847
2127
  }
1848
- function It(e) {
1849
- return ge(e.subscribe, e.get, e.get);
2128
+ function Ft(e) {
2129
+ return xe(e.subscribe, e.get, e.get);
1850
2130
  }
1851
- var de = {
2131
+ var fe = {
1852
2132
  missing: [],
1853
2133
  complete: !1
1854
2134
  };
1855
- function Jt(e) {
1856
- const o = $(), t = e.schema != null, r = JSON.stringify(e.schema ?? null), n = e.submit, s = n ? typeof n == "string" ? `client:${n}` : n.via === "backend" ? "backend" : "handler" in n ? "client:handler" : `client:${n.url}` : "none", i = JSON.stringify(e.initialValues ?? null), l = H(() => t ? pe(e) : null, [
2135
+ function nn(e) {
2136
+ const r = $(), t = e.schema != null, o = JSON.stringify(e.schema ?? null), n = e.submit, l = n ? typeof n == "string" ? `client:${n}` : n.via === "backend" ? "backend" : "handler" in n ? "client:handler" : `client:${n.url}` : "none", s = JSON.stringify(e.initialValues ?? null), i = B(() => t ? me(e) : null, [
1857
2137
  t,
1858
2138
  e.name,
1859
- r,
2139
+ o,
2140
+ l,
1860
2141
  s,
1861
- i,
1862
2142
  e.autoSubmit
1863
- ]), [c, p] = z({
2143
+ ]), [u, c] = T({
1864
2144
  collector: null,
1865
2145
  loading: !t,
1866
2146
  error: null
1867
2147
  });
1868
- N(() => {
2148
+ E(() => {
1869
2149
  if (t) return;
1870
- let d = !1;
1871
- return p({
2150
+ let f = !1;
2151
+ return c({
1872
2152
  collector: null,
1873
2153
  loading: !0,
1874
2154
  error: null
1875
- }), ue(o, e).then((y) => {
1876
- d || p({
1877
- collector: y,
2155
+ }), ge(r, e).then((h) => {
2156
+ f || c({
2157
+ collector: h,
1878
2158
  loading: !1,
1879
2159
  error: null
1880
2160
  });
1881
- }).catch((y) => {
1882
- d || p({
2161
+ }).catch((h) => {
2162
+ f || c({
1883
2163
  collector: null,
1884
2164
  loading: !1,
1885
- error: y instanceof Error ? y : new Error(String(y))
2165
+ error: h instanceof Error ? h : new Error(String(h))
1886
2166
  });
1887
2167
  }), () => {
1888
- d = !0;
2168
+ f = !0;
1889
2169
  };
1890
2170
  }, [
1891
- o,
2171
+ r,
1892
2172
  t,
1893
2173
  e.name,
2174
+ l,
1894
2175
  s,
1895
- i,
1896
2176
  e.autoSubmit
1897
2177
  ]);
1898
- const f = t ? l : c.collector, k = t ? !1 : c.loading, _ = t ? null : c.error;
1899
- N(() => {
1900
- if (f)
1901
- return f.install(o);
1902
- }, [o, f]);
1903
- const C = H(() => Me({
2178
+ const p = t ? i : u.collector, v = t ? !1 : u.loading, S = t ? null : u.error;
2179
+ E(() => {
2180
+ if (p)
2181
+ return p.install(r);
2182
+ }, [r, p]);
2183
+ const g = B(() => ze({
1904
2184
  values: e.initialValues ?? {},
1905
2185
  submitted: !1
1906
- }), [i]), I = It(f?.store ?? C), u = H(() => f?.getStatus() ?? de, [I, f]), A = H(() => ({
1907
- ...I,
1908
- ...u
1909
- }), [I, u]), b = H(() => ({
2186
+ }), [s]), R = Ft(p?.store ?? g), d = B(() => p?.getStatus() ?? fe, [R, p]), w = B(() => ({
2187
+ ...R,
2188
+ ...d
2189
+ }), [R, d]), x = B(() => ({
1910
2190
  name: e.name,
1911
- store: C,
2191
+ store: g,
1912
2192
  functions: [],
1913
2193
  contextKey: `form:${e.name}`,
1914
2194
  contextProvider: () => ({
@@ -1929,46 +2209,50 @@ function Jt(e) {
1929
2209
  ok: !1,
1930
2210
  error: "Form definition not loaded yet."
1931
2211
  }),
1932
- getValues: () => C.get().values,
2212
+ getValues: () => g.get().values,
1933
2213
  setValues: () => {
1934
2214
  },
1935
2215
  reset: () => {
1936
2216
  },
1937
- getStatus: () => de
1938
- }), [e.name, C]);
2217
+ getStatus: () => fe
2218
+ }), [e.name, g]);
1939
2219
  return {
1940
- ...f ?? b,
1941
- state: A,
1942
- loading: k,
1943
- error: _
2220
+ ...p ?? x,
2221
+ state: w,
2222
+ loading: v,
2223
+ error: S
1944
2224
  };
1945
2225
  }
1946
2226
  export {
1947
- Bt as AgoNudge,
1948
- Lt as AgoProvider,
1949
- rt as ChatInput,
1950
- Ht as ChatWidget,
1951
- bt as Markdown,
1952
- kt as Message,
1953
- pe as createFormCollector,
1954
- Tt as createMockClient,
1955
- Et as deriveFormStatus,
1956
- ue as loadFormCollector,
1957
- Ge as useAgo,
1958
- Xe as useAgoActivity,
1959
- Ut as useAgoActivityLog,
1960
- Kt as useAgoAutoContinueAfterNavigation,
2227
+ Jt as AgoNudge,
2228
+ Ut as AgoProvider,
2229
+ lt as ChatInput,
2230
+ Gt as ChatWidget,
2231
+ ue as DEFAULT_MESSAGE_FEEDBACK_LABELS,
2232
+ He as FEEDBACK_REASONS,
2233
+ St as Markdown,
2234
+ Nt as Message,
2235
+ Et as MessageFeedback,
2236
+ me as createFormCollector,
2237
+ Bt as createMockClient,
2238
+ Lt as deriveFormStatus,
2239
+ ge as loadFormCollector,
2240
+ Xe as useAgo,
2241
+ tt as useAgoActivity,
2242
+ en as useAgoActivityLog,
2243
+ Qt as useAgoAutoContinueAfterNavigation,
1961
2244
  $ as useAgoClient,
1962
- Gt as useAgoContext,
1963
- jt as useAgoFunction,
1964
- $t as useAgoNavigation,
1965
- qt as useAgoPageState,
1966
- It as useAgoStore,
1967
- Ot as useChat,
1968
- At as useConversation,
1969
- Jt as useFormCollector,
1970
- xe as useMessages,
2245
+ tn as useAgoContext,
2246
+ Yt as useAgoFunction,
2247
+ Xt as useAgoNavigation,
2248
+ Zt as useAgoPageState,
2249
+ Ft as useAgoStore,
2250
+ Vt as useChat,
2251
+ Mt as useConversation,
2252
+ Rt as useFeedback,
2253
+ nn as useFormCollector,
2254
+ ve as useMessages,
1971
2255
  O as useOptionalAgoClient,
1972
- St as useProactiveNudge,
1973
- et as useSheet
2256
+ Tt as useProactiveNudge,
2257
+ ot as useSheet
1974
2258
  };