@useago/sdk 1.4.0 → 1.4.2

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 (36) hide show
  1. package/dist/{AgoClient-BrhKkDWt.js → AgoClient-BdtuHX7k.js} +49 -25
  2. package/dist/{AgoClient-B2BU8tfB.cjs → AgoClient-CRAnT4qE.cjs} +4 -4
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +12 -0
  5. package/dist/angular.d.ts +12 -0
  6. package/dist/angular.js +4 -1
  7. package/dist/{createConversationSession-Cin8dVNq.cjs → createConversationSession-B8zfTL78.cjs} +1 -1
  8. package/dist/{createConversationSession-ByePKfus.js → createConversationSession-CWpf4u6I.js} +1 -1
  9. package/dist/{createFormCollector-BYKe5Uxm.js → createFormCollector-B4n0_diV.js} +1 -1
  10. package/dist/{createFormCollector-CpYX_5PT.cjs → createFormCollector-BB_l0Sia.cjs} +1 -1
  11. package/dist/{createMockClient-DwdxNwEn.js → createMockClient-d-arlmCq.js} +19 -17
  12. package/dist/createMockClient-ucPENDzz.cjs +1 -0
  13. package/dist/devtools.d.cts +10 -0
  14. package/dist/devtools.d.ts +10 -0
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +10 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.js +4 -4
  19. package/dist/react.cjs +3 -3
  20. package/dist/react.d.cts +10 -0
  21. package/dist/react.d.ts +10 -0
  22. package/dist/react.js +135 -128
  23. package/dist/testing.cjs +1 -1
  24. package/dist/testing.d.cts +10 -0
  25. package/dist/testing.d.ts +10 -0
  26. package/dist/testing.js +1 -1
  27. package/dist/vue.cjs +1 -1
  28. package/dist/vue.d.cts +10 -0
  29. package/dist/vue.d.ts +10 -0
  30. package/dist/vue.js +14 -14
  31. package/dist/widget.cjs +1 -1
  32. package/dist/widget.d.cts +10 -0
  33. package/dist/widget.d.ts +10 -0
  34. package/dist/widget.js +3 -3
  35. package/package.json +1 -1
  36. package/dist/createMockClient-zHQ0cjUH.cjs +0 -1
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as j, i as G, o as V, s as Y, t as X } from "./AgoClient-BrhKkDWt.js";
2
- import { i as Q, n as Ne, r as H, t as O } from "./createFormCollector-BYKe5Uxm.js";
3
- import { t as _e } from "./createMockClient-DwdxNwEn.js";
1
+ import { a as J, i as j, o as V, s as Y, t as X } from "./AgoClient-BdtuHX7k.js";
2
+ import { i as Q, n as Ne, r as H, t as O } from "./createFormCollector-B4n0_diV.js";
3
+ import { t as _e } from "./createMockClient-d-arlmCq.js";
4
4
  import Z, { createContext as ee, useCallback as R, useContext as $, useEffect as C, useId as te, useMemo as N, useRef as A, useState as I, useSyncExternalStore as ne } from "react";
5
5
  import { Fragment as B, jsx as s, jsxs as M } from "react/jsx-runtime";
6
6
  import re from "react-markdown";
@@ -48,11 +48,11 @@ var z = ee(null), He = ({ children: e, client: t, tools: r, helpers: n, pageCont
48
48
  }, [l, r]), C(() => {
49
49
  if (!n) return;
50
50
  const g = [];
51
- return import("./functions-CApuQZ2b.js").then((d) => d.n).then((d) => {
52
- for (const [y, p] of Object.entries(n)) {
53
- const x = d[y];
51
+ return import("./functions-CApuQZ2b.js").then((u) => u.n).then((u) => {
52
+ for (const [b, p] of Object.entries(n)) {
53
+ const x = u[b];
54
54
  if (!x) {
55
- console.warn(`[AGO] Unknown helper: "${y}"`);
55
+ console.warn(`[AGO] Unknown helper: "${b}"`);
56
56
  continue;
57
57
  }
58
58
  const h = p === !0 ? x : {
@@ -62,7 +62,7 @@ var z = ee(null), He = ({ children: e, client: t, tools: r, helpers: n, pageCont
62
62
  l.register(h), g.push(h.name);
63
63
  }
64
64
  }), () => {
65
- for (const d of g) l.unregisterFunction(d);
65
+ for (const u of g) l.unregisterFunction(u);
66
66
  };
67
67
  }, [l, n]), C(() => {
68
68
  o === "auto" && l.enableAutoPageContext();
@@ -82,7 +82,7 @@ function D() {
82
82
  function U({ client: e, conversationId: t } = {}) {
83
83
  const r = D(), n = e || r;
84
84
  if (!n) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
85
- const [o, i] = I([]), [c, l] = I(t), [g, d] = I(!1), [y, p] = I(null);
85
+ const [o, i] = I([]), [c, l] = I(t), [g, u] = I(!1), [b, p] = I(null);
86
86
  C(() => {
87
87
  t && t !== c && (l(t), x(t));
88
88
  }, [t]);
@@ -95,61 +95,68 @@ function U({ client: e, conversationId: t } = {}) {
95
95
  };
96
96
  return C(() => {
97
97
  const h = (f) => {
98
- c || l(f.conversationId);
98
+ c || l(f.conversationId), u(!0), i((d) => d.some((y) => y.role === "assistant" && y.status === "IN_PROGRESS") ? d : [...d, {
99
+ id: f.messageId,
100
+ conversationId: f.conversationId,
101
+ content: "",
102
+ role: "assistant",
103
+ status: "IN_PROGRESS",
104
+ createdAt: /* @__PURE__ */ new Date()
105
+ }]);
99
106
  }, m = (f) => {
100
- i((u) => {
101
- const w = u[u.length - 1];
102
- return w && w.id === f.messageId ? [...u.slice(0, -1), {
103
- ...w,
104
- content: w.content + f.content
105
- }] : u;
107
+ i((d) => {
108
+ const y = d[d.length - 1];
109
+ return y && y.id === f.messageId ? [...d.slice(0, -1), {
110
+ ...y,
111
+ content: y.content + f.content
112
+ }] : d;
106
113
  });
107
- }, v = (f) => {
108
- i((u) => {
109
- let w = -1;
110
- for (let k = u.length - 1; k >= 0; k--) if (u[k].role === "assistant" && u[k].status === "IN_PROGRESS") {
111
- w = k;
114
+ }, w = (f) => {
115
+ i((d) => {
116
+ let y = -1;
117
+ for (let k = d.length - 1; k >= 0; k--) if (d[k].role === "assistant" && d[k].status === "IN_PROGRESS") {
118
+ y = k;
112
119
  break;
113
120
  }
114
- return w < 0 ? u : [
115
- ...u.slice(0, w),
121
+ return y < 0 ? d : [
122
+ ...d.slice(0, y),
116
123
  {
117
- ...u[w],
124
+ ...d[y],
118
125
  ...f
119
126
  },
120
- ...u.slice(w + 1)
127
+ ...d.slice(y + 1)
121
128
  ];
122
129
  });
123
- }, b = (f) => {
124
- i((u) => {
125
- const w = u.findIndex((k) => k.id === f.id);
126
- return w >= 0 ? [
127
- ...u.slice(0, w),
130
+ }, v = (f) => {
131
+ i((d) => {
132
+ const y = d.findIndex((k) => k.id === f.id);
133
+ return y >= 0 ? [
134
+ ...d.slice(0, y),
128
135
  f,
129
- ...u.slice(w + 1)
130
- ] : [...u, f];
131
- }), d(!1);
136
+ ...d.slice(y + 1)
137
+ ] : [...d, f];
138
+ }), u(!1);
132
139
  }, a = (f) => {
133
- p(new Error(f.error)), d(!1);
140
+ p(new Error(f.error)), u(!1);
134
141
  };
135
- return n.on("message:start", h), n.on("message:chunk", m), n.on("message:answer-complete", v), n.on("message:complete", b), n.on("message:error", a), () => {
136
- n.off("message:start", h), n.off("message:chunk", m), n.off("message:answer-complete", v), n.off("message:complete", b), n.off("message:error", a);
142
+ return n.on("message:start", h), n.on("message:chunk", m), n.on("message:answer-complete", w), n.on("message:complete", v), n.on("message:error", a), () => {
143
+ n.off("message:start", h), n.off("message:chunk", m), n.off("message:answer-complete", w), n.off("message:complete", v), n.off("message:error", a);
137
144
  };
138
145
  }, [n, c]), {
139
146
  messages: o,
140
147
  isLoading: g,
141
- error: y,
148
+ error: b,
142
149
  sendMessage: R(async (h, m) => {
143
- d(!0), p(null);
144
- const v = {
150
+ u(!0), p(null);
151
+ const w = {
145
152
  id: `temp-${Date.now()}`,
146
153
  conversationId: c || "",
147
154
  content: h,
148
155
  role: "user",
149
156
  status: "DONE",
150
- attachments: m && m.length > 0 ? G(m) : void 0,
157
+ attachments: m && m.length > 0 ? j(m) : void 0,
151
158
  createdAt: /* @__PURE__ */ new Date()
152
- }, b = {
159
+ }, v = {
153
160
  id: `temp-assistant-${Date.now()}`,
154
161
  conversationId: c || "",
155
162
  content: "",
@@ -159,8 +166,8 @@ function U({ client: e, conversationId: t } = {}) {
159
166
  };
160
167
  i((a) => [
161
168
  ...a,
162
- v,
163
- b
169
+ w,
170
+ v
164
171
  ]);
165
172
  try {
166
173
  const a = await n.sendMessage(h, {
@@ -168,19 +175,19 @@ function U({ client: e, conversationId: t } = {}) {
168
175
  files: m
169
176
  });
170
177
  return a.conversationId && !c && l(a.conversationId), i((f) => {
171
- const u = f.filter((k) => !k.id.startsWith("temp-")), w = {
172
- ...v,
173
- id: v.id.replace("temp-", "user-"),
178
+ const d = f.filter((k) => !k.id.startsWith("temp-")), y = {
179
+ ...w,
180
+ id: w.id.replace("temp-", "user-"),
174
181
  conversationId: a.conversationId
175
182
  };
176
- return u.some((k) => k.id === a.id) ? [...u, w].sort((k, _) => new Date(k.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
177
- ...u,
178
- w,
183
+ return d.some((k) => k.id === a.id) ? [...d, y].sort((k, _) => new Date(k.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
184
+ ...d,
185
+ y,
179
186
  a
180
187
  ];
181
188
  }), a;
182
189
  } catch (a) {
183
- return p(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), d(!1), i((f) => f.filter((u) => !u.id.startsWith("temp-"))), null;
190
+ return p(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), u(!1), i((f) => f.filter((d) => !d.id.startsWith("temp-"))), null;
184
191
  }
185
192
  }, [n, c]),
186
193
  clearMessages: R(() => {
@@ -190,8 +197,8 @@ function U({ client: e, conversationId: t } = {}) {
190
197
  };
191
198
  }
192
199
  var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: o = "" }) => {
193
- const [i, c] = I(""), [l, g] = I([]), d = A(null), y = A(null), p = R(() => {
194
- const a = y.current;
200
+ const [i, c] = I(""), [l, g] = I([]), u = A(null), b = A(null), p = R(() => {
201
+ const a = b.current;
195
202
  if (!a) return;
196
203
  const f = 110;
197
204
  a.style.height = "auto", a.style.height = `${Math.min(a.scrollHeight + 2, f)}px`, a.style.overflowY = a.scrollHeight + 2 > f ? "auto" : "hidden";
@@ -206,10 +213,10 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
206
213
  a.key === "Enter" && !a.shiftKey && (a.preventDefault(), x(a));
207
214
  }, [x]), m = R((a) => {
208
215
  const f = Array.from(a.target.files || []);
209
- g((u) => [...u, ...f]);
210
- }, []), v = R((a) => {
211
- g((f) => f.filter((u, w) => w !== a));
212
- }, []), b = i.trim() || l.length > 0;
216
+ g((d) => [...d, ...f]);
217
+ }, []), w = R((a) => {
218
+ g((f) => f.filter((d, y) => y !== a));
219
+ }, []), v = i.trim() || l.length > 0;
213
220
  return /* @__PURE__ */ M("form", {
214
221
  onSubmit: x,
215
222
  className: `ago-chat-input ${o}`,
@@ -249,7 +256,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
249
256
  children: a.name
250
257
  }), /* @__PURE__ */ s("button", {
251
258
  type: "button",
252
- onClick: () => v(f),
259
+ onClick: () => w(f),
253
260
  "aria-label": `Remove ${a.name}`,
254
261
  style: {
255
262
  border: "none",
@@ -272,7 +279,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
272
279
  children: [
273
280
  n && /* @__PURE__ */ M(B, { children: [/* @__PURE__ */ s("button", {
274
281
  type: "button",
275
- onClick: () => d.current?.click(),
282
+ onClick: () => u.current?.click(),
276
283
  disabled: t,
277
284
  "aria-label": "Attach file",
278
285
  style: {
@@ -287,14 +294,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
287
294
  },
288
295
  children: "+"
289
296
  }), /* @__PURE__ */ s("input", {
290
- ref: d,
297
+ ref: u,
291
298
  type: "file",
292
299
  multiple: !0,
293
300
  onChange: m,
294
301
  style: { display: "none" }
295
302
  })] }),
296
303
  /* @__PURE__ */ s("textarea", {
297
- ref: y,
304
+ ref: b,
298
305
  value: i,
299
306
  onChange: (a) => {
300
307
  c(a.target.value), p();
@@ -330,14 +337,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
330
337
  }),
331
338
  /* @__PURE__ */ s("button", {
332
339
  type: "submit",
333
- disabled: t || !b,
340
+ disabled: t || !v,
334
341
  style: {
335
342
  padding: "10px 18px",
336
343
  border: "none",
337
344
  borderRadius: "20px",
338
- backgroundColor: t || !b ? "#b5bfc8" : "#03182f",
345
+ backgroundColor: t || !v ? "#b5bfc8" : "#03182f",
339
346
  color: "#fff",
340
- cursor: t || !b ? "not-allowed" : "pointer",
347
+ cursor: t || !v ? "not-allowed" : "pointer",
341
348
  fontWeight: 500,
342
349
  fontSize: "16px",
343
350
  transition: "background-color 0.15s"
@@ -510,7 +517,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
510
517
  children: e
511
518
  }), Ce = ({ attachment: e, isUser: t }) => {
512
519
  const r = Y(e.url);
513
- if (j(e)) return /* @__PURE__ */ s("a", {
520
+ if (J(e)) return /* @__PURE__ */ s("a", {
514
521
  href: r,
515
522
  target: "_blank",
516
523
  rel: "noopener noreferrer",
@@ -766,34 +773,34 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
766
773
  cursor: o ? "pointer" : "default",
767
774
  transition: "border-color 0.15s"
768
775
  },
769
- onMouseEnter: (d) => {
770
- d.currentTarget.style.borderColor = "#1b5fc4";
776
+ onMouseEnter: (u) => {
777
+ u.currentTarget.style.borderColor = "#1b5fc4";
771
778
  },
772
- onMouseLeave: (d) => {
773
- d.currentTarget.style.borderColor = "#dee3e8";
779
+ onMouseLeave: (u) => {
780
+ u.currentTarget.style.borderColor = "#dee3e8";
774
781
  },
775
782
  children: l
776
783
  }, g))
777
784
  })
778
785
  ]
779
786
  });
780
- }, Oe = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: i = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: d, onFollowUpClick: y, className: p = "", onMessageSent: x, onMessageReceived: h }) => {
781
- const m = A(null), v = D(), b = e ?? v, { messages: a, isLoading: f, error: u, sendMessage: w } = U({
787
+ }, Oe = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: i = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: u, onFollowUpClick: b, className: p = "", onMessageSent: x, onMessageReceived: h }) => {
788
+ const m = A(null), w = D(), v = e ?? w, { messages: a, isLoading: f, error: d, sendMessage: y } = U({
782
789
  client: e,
783
790
  conversationId: t
784
791
  });
785
792
  C(() => {
786
- if (!b || !d || d.length === 0) return;
793
+ if (!v || !u || u.length === 0) return;
787
794
  let S = !1;
788
- const E = [];
789
- return Promise.all(d.map((P) => P.schema != null ? Promise.resolve(O(P)) : H(b, P))).then((P) => {
795
+ const P = [];
796
+ return Promise.all(u.map((E) => E.schema != null ? Promise.resolve(O(E)) : H(v, E))).then((E) => {
790
797
  if (!S)
791
- for (const J of P) E.push(J.install(b));
798
+ for (const G of E) P.push(G.install(v));
792
799
  }).catch(() => {
793
800
  }), () => {
794
- S = !0, E.forEach((P) => P());
801
+ S = !0, P.forEach((E) => E());
795
802
  };
796
- }, [b, d ? JSON.stringify(d.map((S) => [
803
+ }, [v, u ? JSON.stringify(u.map((S) => [
797
804
  S.name,
798
805
  S.schema ?? null,
799
806
  S.submit ?? !1,
@@ -807,9 +814,9 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
807
814
  content: S.content
808
815
  });
809
816
  }, [a, h]);
810
- const k = async (S, E) => {
811
- x?.(S), await w(S, E);
812
- }, _ = a[a.length - 1], K = f && _?.role === "assistant" && _.status === "IN_PROGRESS", q = y === !1 ? void 0 : y ?? ((S) => k(S));
817
+ const k = async (S, P) => {
818
+ x?.(S), await y(S, P);
819
+ }, _ = a[a.length - 1], K = f && _?.role === "assistant" && _.status === "IN_PROGRESS", q = b === !1 ? void 0 : b ?? ((S) => k(S));
813
820
  return /* @__PURE__ */ M("div", {
814
821
  className: `ago-chat-widget ${p}`,
815
822
  style: {
@@ -874,13 +881,13 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
874
881
  lineHeight: "1.5"
875
882
  },
876
883
  children: n
877
- }) : a.map((S, E) => /* @__PURE__ */ s(Me, {
884
+ }) : a.map((S, P) => /* @__PURE__ */ s(Me, {
878
885
  message: S,
879
886
  showAgentName: g,
880
- isLast: E === a.length - 1,
887
+ isLast: P === a.length - 1,
881
888
  onFollowUpClick: q
882
889
  }, S.id)),
883
- u && /* @__PURE__ */ s("div", {
890
+ d && /* @__PURE__ */ s("div", {
884
891
  role: "alert",
885
892
  style: {
886
893
  padding: "10px 14px",
@@ -891,7 +898,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
891
898
  fontSize: "13px",
892
899
  border: "1px solid #fecaca"
893
900
  },
894
- children: u.message
901
+ children: d.message
895
902
  }),
896
903
  /* @__PURE__ */ s("div", { ref: m })
897
904
  ]
@@ -908,23 +915,23 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
908
915
  function Re({ client: e, autoLoad: t = !0 } = {}) {
909
916
  const r = D(), n = e || r;
910
917
  if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
911
- const [o, i] = I([]), [c, l] = I(null), [g, d] = I(!1), [y, p] = I(null), x = R(async () => {
912
- d(!0), p(null);
918
+ const [o, i] = I([]), [c, l] = I(null), [g, u] = I(!1), [b, p] = I(null), x = R(async () => {
919
+ u(!0), p(null);
913
920
  try {
914
921
  i(await n.getConversations());
915
- } catch (v) {
916
- p(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversations"));
922
+ } catch (w) {
923
+ p(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversations"));
917
924
  } finally {
918
- d(!1);
925
+ u(!1);
919
926
  }
920
- }, [n]), h = R(async (v) => {
921
- d(!0), p(null);
927
+ }, [n]), h = R(async (w) => {
928
+ u(!0), p(null);
922
929
  try {
923
- l(await n.getConversation(v));
924
- } catch (b) {
925
- p(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load conversation"));
930
+ l(await n.getConversation(w));
931
+ } catch (v) {
932
+ p(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversation"));
926
933
  } finally {
927
- d(!1);
934
+ u(!1);
928
935
  }
929
936
  }, [n]), m = R(() => {
930
937
  l(null);
@@ -935,7 +942,7 @@ function Re({ client: e, autoLoad: t = !0 } = {}) {
935
942
  conversations: o,
936
943
  currentConversation: c,
937
944
  isLoading: g,
938
- error: y,
945
+ error: b,
939
946
  selectConversation: h,
940
947
  startNewConversation: m,
941
948
  refreshConversations: x
@@ -972,7 +979,7 @@ function Be(e, t) {
972
979
  ...t
973
980
  } : e, l = A(c);
974
981
  l.current = c, C(() => {
975
- const g = (d) => l.current(d);
982
+ const g = (u) => l.current(u);
976
983
  return r.registerFunction(n, g, {
977
984
  description: o,
978
985
  parameters: i
@@ -989,7 +996,7 @@ function Be(e, t) {
989
996
  function Ue(e, t) {
990
997
  const r = T(), n = A(e);
991
998
  n.current = e, C(() => (r.registerNavigationFunction((o) => n.current(o), t), () => {
992
- r.unregisterFunction("navigateToPage");
999
+ r.unregisterNavigationFunction();
993
1000
  }), [r, t]);
994
1001
  }
995
1002
  function Ke(e, t) {
@@ -1033,12 +1040,12 @@ function qe(e) {
1033
1040
  }, o = () => t.getRegisteredFunctions().some((p) => p.name === r.current.pageStateFunctionName), i = (p) => new Promise((x) => {
1034
1041
  let h = !1;
1035
1042
  const m = (f) => {
1036
- h || (h = !0, clearTimeout(a), t.off("context:changed", b), x(f));
1037
- }, v = () => setTimeout(() => m(p === n.runId && o()), r.current.settleMs), b = () => {
1043
+ h || (h = !0, clearTimeout(a), t.off("context:changed", v), x(f));
1044
+ }, w = () => setTimeout(() => m(p === n.runId && o()), r.current.settleMs), v = () => {
1038
1045
  if (p !== n.runId) return m(!1);
1039
- o() && (t.off("context:changed", b), v());
1046
+ o() && (t.off("context:changed", v), w());
1040
1047
  }, a = setTimeout(() => m(!1), r.current.readinessTimeoutMs);
1041
- o() ? v() : t.on("context:changed", b);
1048
+ o() ? w() : t.on("context:changed", v);
1042
1049
  }), c = async (p) => {
1043
1050
  const x = ++n.runId;
1044
1051
  if (!(!await i(x) || x !== n.runId)) {
@@ -1056,19 +1063,19 @@ function qe(e) {
1056
1063
  r.current.navigationFunctions.includes(p.functionName) && (n.navigated = !0);
1057
1064
  }, g = () => {
1058
1065
  n.ourSendPending || (n.depth = 0, n.runId += 1);
1059
- }, d = (p) => {
1066
+ }, u = (p) => {
1060
1067
  n.ourSendPending = !1;
1061
1068
  const x = n.navigated;
1062
1069
  n.navigated = !1, r.current.enabled && x && (n.depth >= r.current.maxDepth || c(p.conversationId));
1063
- }, y = () => {
1070
+ }, b = () => {
1064
1071
  n.ourSendPending = !1;
1065
1072
  };
1066
- return t.on("function:invoke", l), t.on("message:start", g), t.on("message:complete", d), t.on("message:error", y), () => {
1067
- n.runId += 1, t.off("function:invoke", l), t.off("message:start", g), t.off("message:complete", d), t.off("message:error", y);
1073
+ return t.on("function:invoke", l), t.on("message:start", g), t.on("message:complete", u), t.on("message:error", b), () => {
1074
+ n.runId += 1, t.off("function:invoke", l), t.off("message:start", g), t.off("message:complete", u), t.off("message:error", b);
1068
1075
  };
1069
1076
  }, [t]);
1070
1077
  }
1071
- function Je(e, t) {
1078
+ function Ge(e, t) {
1072
1079
  const r = T(), n = te(), o = t ?? n, i = A(e);
1073
1080
  i.current = e;
1074
1081
  const c = typeof e == "function";
@@ -1089,14 +1096,14 @@ function Je(e, t) {
1089
1096
  c ? "" : JSON.stringify(e)
1090
1097
  ]);
1091
1098
  }
1092
- function Pe(e) {
1099
+ function Ee(e) {
1093
1100
  return ne(e.subscribe, e.get, e.get);
1094
1101
  }
1095
1102
  var W = {
1096
1103
  missing: [],
1097
1104
  complete: !1
1098
1105
  };
1099
- function je(e) {
1106
+ function Je(e) {
1100
1107
  const t = T(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), o = e.submit, i = o ? typeof o == "string" ? `client:${o}` : o.via === "backend" ? "backend" : "handler" in o ? "client:handler" : `client:${o.url}` : "none", c = JSON.stringify(e.initialValues ?? null), l = N(() => r ? O(e) : null, [
1101
1108
  r,
1102
1109
  e.name,
@@ -1104,7 +1111,7 @@ function je(e) {
1104
1111
  i,
1105
1112
  c,
1106
1113
  e.autoSubmit
1107
- ]), [g, d] = I({
1114
+ ]), [g, u] = I({
1108
1115
  collector: null,
1109
1116
  loading: !r,
1110
1117
  error: null
@@ -1112,21 +1119,21 @@ function je(e) {
1112
1119
  C(() => {
1113
1120
  if (r) return;
1114
1121
  let f = !1;
1115
- return d({
1122
+ return u({
1116
1123
  collector: null,
1117
1124
  loading: !0,
1118
1125
  error: null
1119
- }), H(t, e).then((u) => {
1120
- f || d({
1121
- collector: u,
1126
+ }), H(t, e).then((d) => {
1127
+ f || u({
1128
+ collector: d,
1122
1129
  loading: !1,
1123
1130
  error: null
1124
1131
  });
1125
- }).catch((u) => {
1126
- f || d({
1132
+ }).catch((d) => {
1133
+ f || u({
1127
1134
  collector: null,
1128
1135
  loading: !1,
1129
- error: u instanceof Error ? u : new Error(String(u))
1136
+ error: d instanceof Error ? d : new Error(String(d))
1130
1137
  });
1131
1138
  }), () => {
1132
1139
  f = !0;
@@ -1139,18 +1146,18 @@ function je(e) {
1139
1146
  c,
1140
1147
  e.autoSubmit
1141
1148
  ]);
1142
- const y = r ? l : g.collector, p = r ? !1 : g.loading, x = r ? null : g.error;
1149
+ const b = r ? l : g.collector, p = r ? !1 : g.loading, x = r ? null : g.error;
1143
1150
  C(() => {
1144
- if (y)
1145
- return y.install(t);
1146
- }, [t, y]);
1151
+ if (b)
1152
+ return b.install(t);
1153
+ }, [t, b]);
1147
1154
  const h = N(() => Q({
1148
1155
  values: e.initialValues ?? {},
1149
1156
  submitted: !1
1150
- }), [c]), m = Pe(y?.store ?? h), v = N(() => y?.getStatus() ?? W, [m, y]), b = N(() => ({
1157
+ }), [c]), m = Ee(b?.store ?? h), w = N(() => b?.getStatus() ?? W, [m, b]), v = N(() => ({
1151
1158
  ...m,
1152
- ...v
1153
- }), [m, v]), a = N(() => ({
1159
+ ...w
1160
+ }), [m, w]), a = N(() => ({
1154
1161
  name: e.name,
1155
1162
  store: h,
1156
1163
  functions: [],
@@ -1175,8 +1182,8 @@ function je(e) {
1175
1182
  getStatus: () => W
1176
1183
  }), [e.name, h]);
1177
1184
  return {
1178
- ...y ?? a,
1179
- state: b,
1185
+ ...b ?? a,
1186
+ state: v,
1180
1187
  loading: p,
1181
1188
  error: x
1182
1189
  };
@@ -1194,14 +1201,14 @@ export {
1194
1201
  ae as useAgo,
1195
1202
  qe as useAgoAutoContinueAfterNavigation,
1196
1203
  T as useAgoClient,
1197
- Je as useAgoContext,
1204
+ Ge as useAgoContext,
1198
1205
  Be as useAgoFunction,
1199
1206
  Ue as useAgoNavigation,
1200
1207
  Ke as useAgoPageState,
1201
- Pe as useAgoStore,
1208
+ Ee as useAgoStore,
1202
1209
  $e as useChat,
1203
1210
  Re as useConversation,
1204
- je as useFormCollector,
1211
+ Je as useFormCollector,
1205
1212
  U as useMessages,
1206
1213
  D as useOptionalAgoClient
1207
1214
  };
package/dist/testing.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createMockClient-zHQ0cjUH.cjs");exports.createMockClient=e.createMockClient;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createMockClient-ucPENDzz.cjs");exports.createMockClient=e.createMockClient;
@@ -146,6 +146,12 @@ declare class AgoClient {
146
146
  getRegisteredFunctions(): ClientFunctionSchema[];
147
147
  /**
148
148
  * Register a navigation function that lets AGO navigate users to different pages.
149
+ *
150
+ * Also registers a dynamic context entry (`current-page`) that reports the page
151
+ * the user is currently on, by route name, on every message. This is what lets
152
+ * the agent know *where* it is after it navigates (e.g. so auto-continuation
153
+ * can apply page state on the destination), not just how to navigate away.
154
+ *
149
155
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
150
156
  * @param routes - Map of route names to paths, with descriptions for the LLM
151
157
  */
@@ -154,6 +160,10 @@ declare class AgoClient {
154
160
  path: string;
155
161
  description: string;
156
162
  }>): void;
163
+ /**
164
+ * Unregister the navigation function and its `current-page` context provider.
165
+ */
166
+ unregisterNavigationFunction(): void;
157
167
  /**
158
168
  * Register a "page state" function that lets AGO change the current page's
159
169
  * state (filters, sort, view mode, selection…) and reads the current state
package/dist/testing.d.ts CHANGED
@@ -146,6 +146,12 @@ declare class AgoClient {
146
146
  getRegisteredFunctions(): ClientFunctionSchema[];
147
147
  /**
148
148
  * Register a navigation function that lets AGO navigate users to different pages.
149
+ *
150
+ * Also registers a dynamic context entry (`current-page`) that reports the page
151
+ * the user is currently on, by route name, on every message. This is what lets
152
+ * the agent know *where* it is after it navigates (e.g. so auto-continuation
153
+ * can apply page state on the destination), not just how to navigate away.
154
+ *
149
155
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
150
156
  * @param routes - Map of route names to paths, with descriptions for the LLM
151
157
  */
@@ -154,6 +160,10 @@ declare class AgoClient {
154
160
  path: string;
155
161
  description: string;
156
162
  }>): void;
163
+ /**
164
+ * Unregister the navigation function and its `current-page` context provider.
165
+ */
166
+ unregisterNavigationFunction(): void;
157
167
  /**
158
168
  * Register a "page state" function that lets AGO change the current page's
159
169
  * state (filters, sort, view mode, selection…) and reads the current state
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./createMockClient-DwdxNwEn.js";
1
+ import { t as e } from "./createMockClient-d-arlmCq.js";
2
2
  export {
3
3
  e as createMockClient
4
4
  };
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient-B2BU8tfB.cjs");let o=require("vue");var I=Symbol("ago-client"),N={install(t,n){const e=new p.AgoClient(n);t.provide(I,e)}};function d(t){if(t)return new p.AgoClient(t);const n=(0,o.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(t={}){const n=t.client??d(),e=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),i=(0,o.ref)(!1),r=(0,o.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.value=!1};(0,o.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,o.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function g(a,u){i.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},S={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,S);try{const l=await n.sendMessage(a,{conversationId:s.value,files:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),i.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:i,error:r,conversationId:s,sendMessage:g,clearMessages:h}}function M(t={}){const n=t.client??d(),e=t.autoLoad??!0,s=(0,o.ref)([]),i=(0,o.ref)(null),r=(0,o.ref)(!1),c=(0,o.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(g){c.value=g instanceof Error?g:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(g){r.value=!0,c.value=null;try{i.value=await n.getConversation(g)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){i.value=null}return(0,o.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function L(t={}){const n=E({client:t.client,conversationId:t.conversationId}),e=M({client:t.client,autoLoad:t.autoLoad}),s=(0,o.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function y(t,n){const e=d();(0,o.onMounted)(()=>{e.registerFunction(t,n.handler,{description:n.description,parameters:n.parameters})}),(0,o.onUnmounted)(()=>{e.unregisterFunction(t)})}function F(t,n){const e=d();(0,o.onMounted)(()=>{e.registerNavigationFunction(t,n)}),(0,o.onUnmounted)(()=>{e.unregisterFunction("navigateToPage")})}function P(t,n){const e=d(),s=n?.functionName??"setPageState";(0,o.onMounted)(()=>{e.registerPageStateFunction(t,{functionName:s})}),(0,o.onUnmounted)(()=>{e.unregisterPageStateFunction(s)})}function _(t,n){const e=d();(0,o.onMounted)(()=>{e.on(t,n)}),(0,o.onUnmounted)(()=>{e.off(t,n)})}function D(t){const n=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=N;exports.useAgo=d;exports.useAgoEvents=_;exports.useAgoFunction=y;exports.useAgoNavigation=F;exports.useAgoPageState=P;exports.useAgoStore=D;exports.useChat=L;exports.useConversation=M;exports.useMessages=E;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient-CRAnT4qE.cjs");let o=require("vue");var I=Symbol("ago-client"),S={install(t,n){const e=new p.AgoClient(n);t.provide(I,e)}};function d(t){if(t)return new p.AgoClient(t);const n=(0,o.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(t={}){const n=t.client??d(),e=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),i=(0,o.ref)(!1),r=(0,o.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.value=!1};(0,o.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,o.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function g(a,u){i.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},N={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,N);try{const l=await n.sendMessage(a,{conversationId:s.value,files:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),i.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:i,error:r,conversationId:s,sendMessage:g,clearMessages:h}}function M(t={}){const n=t.client??d(),e=t.autoLoad??!0,s=(0,o.ref)([]),i=(0,o.ref)(null),r=(0,o.ref)(!1),c=(0,o.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(g){c.value=g instanceof Error?g:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(g){r.value=!0,c.value=null;try{i.value=await n.getConversation(g)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){i.value=null}return(0,o.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function L(t={}){const n=E({client:t.client,conversationId:t.conversationId}),e=M({client:t.client,autoLoad:t.autoLoad}),s=(0,o.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function y(t,n){const e=d();(0,o.onMounted)(()=>{e.registerFunction(t,n.handler,{description:n.description,parameters:n.parameters})}),(0,o.onUnmounted)(()=>{e.unregisterFunction(t)})}function F(t,n){const e=d();(0,o.onMounted)(()=>{e.registerNavigationFunction(t,n)}),(0,o.onUnmounted)(()=>{e.unregisterNavigationFunction()})}function P(t,n){const e=d(),s=n?.functionName??"setPageState";(0,o.onMounted)(()=>{e.registerPageStateFunction(t,{functionName:s})}),(0,o.onUnmounted)(()=>{e.unregisterPageStateFunction(s)})}function _(t,n){const e=d();(0,o.onMounted)(()=>{e.on(t,n)}),(0,o.onUnmounted)(()=>{e.off(t,n)})}function D(t){const n=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=S;exports.useAgo=d;exports.useAgoEvents=_;exports.useAgoFunction=y;exports.useAgoNavigation=F;exports.useAgoPageState=P;exports.useAgoStore=D;exports.useChat=L;exports.useConversation=M;exports.useMessages=E;