@useago/sdk 1.5.5 → 1.7.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 (42) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/README.md +59 -0
  3. package/dist/AgoClient-BHegN73y.cjs +9 -0
  4. package/dist/{AgoClient-BI5esqbd.js → AgoClient-PWPaekcg.js} +657 -387
  5. package/dist/angular.cjs +1 -1
  6. package/dist/angular.d.cts +230 -5
  7. package/dist/angular.d.ts +230 -5
  8. package/dist/angular.js +10 -1
  9. package/dist/{createConversationSession-0zVkMdYj.cjs → createConversationSession-BbUUukV0.cjs} +1 -1
  10. package/dist/{createConversationSession-BlYTpxwz.js → createConversationSession-BkruoOVm.js} +1 -1
  11. package/dist/{createFormCollector-DiCe_8ik.cjs → createFormCollector-C1ixsjV0.cjs} +1 -1
  12. package/dist/{createFormCollector-Bgs94NyR.js → createFormCollector-CvVFNkp6.js} +1 -1
  13. package/dist/{createMockClient-DcuNlufr.js → createMockClient-BDLW6tVc.js} +5 -2
  14. package/dist/createMockClient-BSNuN3ys.cjs +1 -0
  15. package/dist/devtools.d.cts +220 -5
  16. package/dist/devtools.d.ts +220 -5
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +238 -6
  19. package/dist/index.d.ts +238 -6
  20. package/dist/index.js +111 -109
  21. package/dist/react.cjs +40 -3
  22. package/dist/react.d.cts +419 -7
  23. package/dist/react.d.ts +419 -7
  24. package/dist/react.js +1195 -743
  25. package/dist/sheetController-CBUVOroo.js +205 -0
  26. package/dist/sheetController-DY-sC13T.cjs +1 -0
  27. package/dist/testing.cjs +1 -1
  28. package/dist/testing.d.cts +220 -5
  29. package/dist/testing.d.ts +220 -5
  30. package/dist/testing.js +1 -1
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.d.cts +235 -5
  33. package/dist/vue.d.ts +235 -5
  34. package/dist/vue.js +121 -100
  35. package/dist/widget.cjs +4 -4
  36. package/dist/widget.d.cts +328 -5
  37. package/dist/widget.d.ts +328 -5
  38. package/dist/widget.js +721 -629
  39. package/llms-full.txt +202 -14
  40. package/package.json +1 -1
  41. package/dist/AgoClient-CQh8YovA.cjs +0 -8
  42. package/dist/createMockClient-Dw-cyISN.cjs +0 -1
package/dist/vue.d.ts CHANGED
@@ -65,6 +65,10 @@ declare class AgoClient {
65
65
  private config;
66
66
  /** Conversations already warned about an empty reply (one warning each). */
67
67
  private warnedEmptyConversations;
68
+ /** Whether the placeholder-mode page-data warning has already been logged. */
69
+ private warnedPageDataPlaceholder;
70
+ /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
71
+ private pageDataCompanions;
68
72
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
69
73
  private pendingResumes;
70
74
  /**
@@ -75,6 +79,20 @@ declare class AgoClient {
75
79
  private pendingApprovals;
76
80
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
77
81
  private resumeGate;
82
+ /** The turn currently streaming, or `null` when the client is idle. */
83
+ private activeTurn;
84
+ /**
85
+ * A turn that closed as `WAITING_CLIENT` and has not resumed yet. There is no
86
+ * open stream in that window, but the turn is still live for the user, so it
87
+ * stays stoppable (see {@link stop}).
88
+ */
89
+ private pausedTurn;
90
+ /**
91
+ * Turns stopped while they were paused on client functions. A resume may
92
+ * already be queued (or waiting on the resume gate) at that point; this drops
93
+ * it, so a stopped turn is never restarted.
94
+ */
95
+ private stoppedTurnIds;
78
96
  /**
79
97
  * Proactive-mode controller, set when the client was created with
80
98
  * `proactive` options or when `createAgoProactive(client, opts)` was called.
@@ -86,7 +104,53 @@ declare class AgoClient {
86
104
  * Send a message and receive a streaming response
87
105
  */
88
106
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
107
+ /**
108
+ * Fire the streaming request, returning `null` when the user stopped before
109
+ * the response came back. Any other failure ends the turn and propagates, so
110
+ * a real error still reaches the caller.
111
+ */
112
+ private sendRequest;
89
113
  private processSSEResponse;
114
+ /**
115
+ * Stop the turn that is generating right now: closes the stream so the UI
116
+ * stops immediately, and tells the backend to stop generating.
117
+ *
118
+ * Both halves matter. Closing the stream alone does NOT stop the agent — it
119
+ * keeps running and the full answer reappears the next time the conversation
120
+ * is loaded. The backend unwinds at its next safe point (any tool already
121
+ * running finishes, no further tool or reasoning round starts), keeps the text
122
+ * produced so far and finalizes the message as `CANCELED`.
123
+ *
124
+ * The in-flight `sendMessage` / `continueMessage` promise resolves normally
125
+ * with that partial message (it does not reject), `message:complete` fires
126
+ * with status `CANCELED`, then `message:stopped`.
127
+ *
128
+ * ```ts
129
+ * // "Stop" button
130
+ * stopButton.onclick = () => void client.stop();
131
+ * ```
132
+ *
133
+ * Returns the backend's verdict, or `null` when nothing was generating or the
134
+ * stop landed before the message had an id (the stream is still closed).
135
+ */
136
+ stop(): Promise<StopMessageResult | null>;
137
+ /**
138
+ * Ask the backend to stop a specific in-flight turn, without touching any
139
+ * local stream. Idempotent — stopping a finished turn answers
140
+ * `{ status: "not_running" }` rather than failing. Most apps want
141
+ * {@link stop} instead; use this to stop a turn started elsewhere (e.g. one
142
+ * still running after a page reload, found via `getConversation`).
143
+ */
144
+ stopMessage(messageId: string): Promise<StopMessageResult>;
145
+ /** Whether a turn is generating right now (i.e. {@link stop} has something to stop). */
146
+ isGenerating(): boolean;
147
+ /** Open a new turn, replacing any bookkeeping left by the previous one. */
148
+ private beginTurn;
149
+ private endTurn;
150
+ /** POST the stop for a turn, once, never letting the failure escape. */
151
+ private postStopForTurn;
152
+ /** The message a caller gets back when the stop beat the response. */
153
+ private buildStoppedMessage;
90
154
  private resolveClientFunctionsMode;
91
155
  /**
92
156
  * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
@@ -314,13 +378,38 @@ declare class AgoClient {
314
378
  * },
315
379
  * ]);
316
380
  * ```
381
+ *
382
+ * Pass `opts.data` and the agent also gets back **what the page now shows**,
383
+ * as the result of its own call, instead of having to wait for the next
384
+ * message's context. That also registers a read-only `readPageData`
385
+ * companion. See {@link AgoPageDataSource}.
317
386
  */
318
387
  registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
319
388
  /**
320
- * Unregister a page state function and its dynamic context provider.
321
- * Mirror of unregistering `navigateToPage`.
389
+ * Unregister a page state function, its `readPageData` companion, and its
390
+ * dynamic context provider. Mirror of unregistering `navigateToPage`.
322
391
  */
323
392
  unregisterPageStateFunction(functionName?: string): void;
393
+ /**
394
+ * Size ceiling for a page snapshot, before the envelope is accounted for.
395
+ * Read at call time, not at registration, so `updateConfig` moves it.
396
+ */
397
+ private pageDataBudget;
398
+ /** Bytes the non-`data` part of the result costs, `data` included as `null`. */
399
+ private envelopeBytes;
400
+ /**
401
+ * Wait for the page to stop reloading, then read the snapshot. `get` and
402
+ * `isLoading` are re-read from `source` on every tick so a re-render that
403
+ * swaps the closures (without re-registering) is picked up mid-wait.
404
+ */
405
+ private readPageData;
406
+ /**
407
+ * The snapshot only reaches the agent inside the same turn in pause mode,
408
+ * where the SDK submits the tool result and resumes. In placeholder mode the
409
+ * turn is already over, so a `data` source looks broken from the outside:
410
+ * say so once rather than let the integrator hunt for an SDK bug.
411
+ */
412
+ private warnIfPlaceholderMode;
324
413
  /**
325
414
  * Register or update a piece of client-side context.
326
415
  * This context is sent with every message so the AI understands the user's situation.
@@ -488,6 +577,18 @@ declare interface AgoClientEvents {
488
577
  conversationId: string;
489
578
  messageId: string;
490
579
  };
580
+ /**
581
+ * The user stopped the turn (`client.stop()`): the stream was closed and the
582
+ * backend was told to stop generating. Always fires, so this is the event to
583
+ * finalize a UI on. When there was an answer to keep, a `message:complete`
584
+ * carrying it with status `CANCELED` fires first; there is none when the stop
585
+ * landed before the backend named the message (`messageId` is then an empty
586
+ * string) or when the stopped turn was paused on client functions.
587
+ */
588
+ "message:stopped": {
589
+ conversationId: string;
590
+ messageId: string;
591
+ };
491
592
  "message:error": {
492
593
  error: string;
493
594
  /** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
@@ -681,6 +782,80 @@ export declare interface AgoMessage {
681
782
  createdAt: Date;
682
783
  }
683
784
 
785
+ /**
786
+ * What the page currently displays, returned to the agent as the *result* of
787
+ * `setPageState` instead of only as context on the next message.
788
+ *
789
+ * Declare it when the agent should be able to act on what its own change
790
+ * produced ("search for dupont" → it can say who was found).
791
+ *
792
+ * A control change usually kicks off work (a refetch, a recomputation). The SDK
793
+ * has to wait for that work before reading, and there are two ways to tell it
794
+ * when the work is done. **Prefer the first.**
795
+ *
796
+ * **1. Return a promise from `get()`** — you own the await, so the SDK is
797
+ * exact: it resolves when your work resolves, with no polling and no timing
798
+ * assumption. With TanStack Query, `ensureQueryData` gives you that promise and
799
+ * shares the single in-flight request with the UI:
800
+ *
801
+ * ```ts
802
+ * useAgoPageState(controls, {
803
+ * data: {
804
+ * description: "The users matching the current filters.",
805
+ * get: () => queryClient.ensureQueryData({
806
+ * queryKey: ["users", filters],
807
+ * queryFn: fetchUsers,
808
+ * }),
809
+ * },
810
+ * });
811
+ * ```
812
+ *
813
+ * **2. Declare `isLoading`** — for data you cannot get a promise for. The SDK
814
+ * polls it instead, which is a heuristic: the flag has to be up within ~100 ms
815
+ * of the change or the SDK concludes the page settled and reads the previous
816
+ * rows. Fine for a query library that flips `isFetching` on render, wrong for a
817
+ * debounced fetch.
818
+ *
819
+ * ```ts
820
+ * const { data: users, isFetching } = useQuery({ queryKey: ["users", filters], queryFn: fetchUsers });
821
+ *
822
+ * useAgoPageState(controls, {
823
+ * data: {
824
+ * description: "The users matching the current filters.",
825
+ * get: () => users ?? [],
826
+ * // isFetching, NOT isLoading: a background refetch must count as loading,
827
+ * // otherwise the agent reads the rows from the previous search.
828
+ * isLoading: () => isFetching,
829
+ * },
830
+ * });
831
+ * ```
832
+ */
833
+ export declare interface AgoPageDataSource<T = unknown> {
834
+ /** What this data is, for the LLM: "The users matching the current filters." */
835
+ description: string;
836
+ /**
837
+ * The snapshot handed back to the agent.
838
+ *
839
+ * Return a promise and the SDK awaits it: that promise resolving *is* the
840
+ * signal that the work the change triggered has finished, so nothing is
841
+ * guessed. It is bounded by `settleTimeoutMs`.
842
+ */
843
+ get: () => T | Promise<T>;
844
+ /**
845
+ * True while the page is (re)loading this data. Only needed when `get()`
846
+ * cannot return a promise. The SDK polls it every 50 ms and treats two
847
+ * consecutive `false` readings as settled, so a flag raised more than ~100 ms
848
+ * after the change is missed and the agent reads stale rows.
849
+ */
850
+ isLoading?: () => boolean;
851
+ /**
852
+ * Size ceiling for the returned snapshot, in bytes. Defaults to the client's
853
+ * `maxFunctionResultBytes`. Over the ceiling the snapshot keeps the first
854
+ * whole items that fit; `success` and `applied` are never dropped.
855
+ */
856
+ maxResultBytes?: number;
857
+ }
858
+
684
859
  /**
685
860
  * Options for {@link AgoClient.registerPageStateFunction}.
686
861
  */
@@ -692,6 +867,23 @@ export declare interface AgoPageStateOptions {
692
867
  * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
693
868
  */
694
869
  requiresApproval?: boolean;
870
+ /**
871
+ * Declare what the page displays so `setPageState` returns it. Omit it and
872
+ * the result stays exactly `{ success, applied }`.
873
+ *
874
+ * Also registers a read-only companion function (`readPageData`, derived from
875
+ * `functionName`) that returns the same snapshot without touching the page.
876
+ *
877
+ * The snapshot travels only when the agent calls one of those functions: it
878
+ * is deliberately kept out of the `page-state:` dynamic context, which would
879
+ * put it in every message.
880
+ */
881
+ data?: AgoPageDataSource;
882
+ /**
883
+ * How long to wait for the page to finish reloading before reading the
884
+ * snapshot. Defaults to 10 000 ms; on timeout whatever is there is returned.
885
+ */
886
+ settleTimeoutMs?: number;
695
887
  }
696
888
 
697
889
  /**
@@ -1020,13 +1212,21 @@ declare class HttpClient {
1020
1212
  keepalive?: boolean;
1021
1213
  }): Promise<T>;
1022
1214
  /**
1023
- * Make a POST request and return the raw Response (for streaming)
1215
+ * Make a POST request and return the raw Response (for streaming).
1216
+ *
1217
+ * `signal` lets the caller close the stream mid-flight (see
1218
+ * `AgoClient.stop`); an abort is rethrown as-is rather than wrapped in an
1219
+ * `AgoNetworkError`, so a deliberate stop is not mistaken for a network drop.
1024
1220
  */
1025
- postStream(path: string, body?: unknown): Promise<Response>;
1221
+ postStream(path: string, body?: unknown, options?: {
1222
+ signal?: AbortSignal;
1223
+ }): Promise<Response>;
1026
1224
  /**
1027
1225
  * Make a POST request with FormData (for file uploads)
1028
1226
  */
1029
- postFormData(path: string, formData: FormData): Promise<Response>;
1227
+ postFormData(path: string, formData: FormData, options?: {
1228
+ signal?: AbortSignal;
1229
+ }): Promise<Response>;
1030
1230
  private request;
1031
1231
  private handleErrorResponse;
1032
1232
  }
@@ -1358,6 +1558,21 @@ declare interface SSEChunkData {
1358
1558
  waiting_tool_call_ids?: string[];
1359
1559
  }
1360
1560
 
1561
+ /**
1562
+ * Response of `POST /messages/{id}/stop` (see `AgoClient.stopMessage`).
1563
+ *
1564
+ * - `"stopping"` — the request was accepted; the turn unwinds at its next safe
1565
+ * point and finalizes as `CANCELED`, keeping the text produced so far.
1566
+ * - `"not_running"` — the turn had already finished. Harmless.
1567
+ * - `"not_supported"` — a background agent run, which cannot be stopped once
1568
+ * started.
1569
+ */
1570
+ declare interface StopMessageResult {
1571
+ status: "stopping" | "not_running" | "not_supported";
1572
+ /** The message's status when the stop was requested. */
1573
+ messageStatus?: MessageStatus;
1574
+ }
1575
+
1361
1576
  /** The slice of the Web Storage API that {@link createStore} relies on. */
1362
1577
  declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1363
1578
 
@@ -1519,6 +1734,19 @@ export declare function useAgoNavigation(navigate: (path: string) => void, route
1519
1734
  * },
1520
1735
  * ]);
1521
1736
  * ```
1737
+ *
1738
+ * Pass `opts.data` to also hand the agent what the page ends up displaying, as
1739
+ * the result of its own `setPageState` call:
1740
+ *
1741
+ * ```ts
1742
+ * useAgoPageState(controls, {
1743
+ * data: {
1744
+ * description: "The rows matching the current filters.",
1745
+ * get: () => rows.value,
1746
+ * isLoading: () => isFetching.value,
1747
+ * },
1748
+ * });
1749
+ * ```
1522
1750
  */
1523
1751
  export declare function useAgoPageState(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
1524
1752
 
@@ -1637,6 +1865,7 @@ export declare function useChat(options?: UseChatOptions): {
1637
1865
  isLoading: Ref<boolean, boolean>;
1638
1866
  error: ComputedRef<Error | null>;
1639
1867
  sendMessage: (content: string, files?: File[]) => Promise<AgoMessage | null>;
1868
+ stop: () => Promise<void>;
1640
1869
  clearMessages: () => void;
1641
1870
  conversationId: Ref<string | undefined, string | undefined>;
1642
1871
  conversations: Ref< {
@@ -2158,6 +2387,7 @@ export declare function useMessages(options?: UseMessagesOptions): {
2158
2387
  error: Ref<Error | null, Error | null>;
2159
2388
  conversationId: Ref<string | undefined, string | undefined>;
2160
2389
  sendMessage: (content: string, files?: File[]) => Promise<AgoMessage | null>;
2390
+ stop: () => Promise<void>;
2161
2391
  clearMessages: () => void;
2162
2392
  };
2163
2393
 
package/dist/vue.js CHANGED
@@ -1,45 +1,58 @@
1
- import { t as E } from "./AgoClient-BI5esqbd.js";
2
- import { computed as M, inject as F, onMounted as d, onScopeDispose as S, onUnmounted as m, ref as l, shallowRef as A } from "vue";
3
- var N = /* @__PURE__ */ Symbol("ago-client"), b = { install(t, e) {
4
- const n = new E(e);
5
- t.provide(N, n);
1
+ import { t as N } from "./AgoClient-PWPaekcg.js";
2
+ import { computed as R, inject as F, onMounted as f, onScopeDispose as P, onUnmounted as m, ref as v, shallowRef as y } from "vue";
3
+ var A = /* @__PURE__ */ Symbol("ago-client"), k = { install(t, e) {
4
+ const n = new N(e);
5
+ t.provide(A, n);
6
6
  } };
7
- function f(t) {
8
- if (t) return new E(t);
9
- const e = F(N);
7
+ function g(t) {
8
+ if (t) return new N(t);
9
+ const e = F(A);
10
10
  if (!e) throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");
11
11
  return e;
12
12
  }
13
- function R(t = {}) {
14
- const e = t.client ?? f(), n = l([]), s = l(t.conversationId), o = l(!1), r = l(null), c = (a) => {
15
- s.value || (s.value = a.conversationId);
16
- }, p = (a) => {
17
- const i = n.value.findIndex((v) => v.id === a.messageId);
18
- i >= 0 && (n.value[i] = {
19
- ...n.value[i],
20
- content: n.value[i].content + a.content
13
+ function x(t = {}) {
14
+ const e = t.client ?? g(), n = v([]), s = v(t.conversationId), a = v(!1), i = v(null), c = (o) => {
15
+ s.value || (s.value = o.conversationId);
16
+ }, p = (o) => {
17
+ const r = n.value.findIndex((u) => u.id === o.messageId);
18
+ r >= 0 && (n.value[r] = {
19
+ ...n.value[r],
20
+ content: n.value[r].content + o.content
21
21
  });
22
- }, h = (a) => {
23
- const i = n.value.findIndex((v) => v.id === a.id);
24
- i >= 0 ? n.value[i] = a : n.value.push(a), o.value = !1;
25
- }, C = (a) => {
26
- r.value = new Error(a.error), o.value = !1;
22
+ }, h = (o) => {
23
+ const r = n.value.findIndex((u) => u.id === o.id);
24
+ r >= 0 ? n.value[r] = o : n.value.push(o), a.value = !1;
25
+ }, C = (o) => {
26
+ i.value = new Error(o.error), a.value = !1;
27
+ }, d = () => {
28
+ let o = -1;
29
+ for (let r = n.value.length - 1; r >= 0; r--) {
30
+ const u = n.value[r];
31
+ if (u.role === "assistant" && (u.status === "IN_PROGRESS" || u.status === "WAITING_CLIENT")) {
32
+ o = r;
33
+ break;
34
+ }
35
+ }
36
+ o >= 0 && (n.value[o].content ? n.value[o] = {
37
+ ...n.value[o],
38
+ status: "CANCELED"
39
+ } : n.value.splice(o, 1)), a.value = !1;
27
40
  };
28
- d(() => {
29
- e.on("message:start", c), e.on("message:chunk", p), e.on("message:complete", h), e.on("message:error", C);
41
+ f(() => {
42
+ e.on("message:start", c), e.on("message:chunk", p), e.on("message:complete", h), e.on("message:error", C), e.on("message:stopped", d);
30
43
  }), m(() => {
31
- e.off("message:start", c), e.off("message:chunk", p), e.off("message:complete", h), e.off("message:error", C);
44
+ e.off("message:start", c), e.off("message:chunk", p), e.off("message:complete", h), e.off("message:error", C), e.off("message:stopped", d);
32
45
  });
33
- async function g(a, i) {
34
- o.value = !0, r.value = null;
35
- const v = {
46
+ async function I(o, r) {
47
+ a.value = !0, i.value = null;
48
+ const u = {
36
49
  id: `temp-${Date.now()}`,
37
50
  conversationId: s.value || "",
38
- content: a,
51
+ content: o,
39
52
  role: "user",
40
53
  status: "DONE",
41
54
  createdAt: /* @__PURE__ */ new Date()
42
- }, L = {
55
+ }, M = {
43
56
  id: `temp-assistant-${Date.now()}`,
44
57
  conversationId: s.value || "",
45
58
  content: "",
@@ -47,85 +60,90 @@ function R(t = {}) {
47
60
  status: "IN_PROGRESS",
48
61
  createdAt: /* @__PURE__ */ new Date()
49
62
  };
50
- n.value.push(v, L);
63
+ n.value.push(u, M);
51
64
  try {
52
- const u = await e.sendMessage(a, {
65
+ const l = await e.sendMessage(o, {
53
66
  conversationId: s.value,
54
- files: i
67
+ files: r
55
68
  });
56
- u.conversationId && !s.value && (s.value = u.conversationId), n.value = n.value.filter((y) => !y.id.startsWith("temp-"));
57
- const I = {
58
- ...v,
59
- id: v.id.replace("temp-", "user-"),
60
- conversationId: u.conversationId
69
+ l.conversationId && !s.value && (s.value = l.conversationId), n.value = n.value.filter((E) => !E.id.startsWith("temp-"));
70
+ const w = {
71
+ ...u,
72
+ id: u.id.replace("temp-", "user-"),
73
+ conversationId: l.conversationId
61
74
  };
62
- return n.value.some((y) => y.id === u.id) ? n.value.push(I) : n.value.push(I, u), u;
63
- } catch (u) {
64
- return r.value = u instanceof Error ? u : /* @__PURE__ */ new Error("Failed to send"), o.value = !1, n.value = n.value.filter((I) => !I.id.startsWith("temp-")), null;
75
+ return n.value.some((E) => E.id === l.id) ? n.value.push(w) : n.value.push(w, l), l;
76
+ } catch (l) {
77
+ return i.value = l instanceof Error ? l : /* @__PURE__ */ new Error("Failed to send"), a.value = !1, n.value = n.value.filter((w) => !w.id.startsWith("temp-")), null;
65
78
  }
66
79
  }
67
- function w() {
68
- n.value = [], s.value = void 0, r.value = null;
80
+ async function L() {
81
+ await e.stop();
82
+ }
83
+ function S() {
84
+ n.value = [], s.value = void 0, i.value = null;
69
85
  }
70
86
  return {
71
87
  messages: n,
72
- isLoading: o,
73
- error: r,
88
+ isLoading: a,
89
+ error: i,
74
90
  conversationId: s,
75
- sendMessage: g,
76
- clearMessages: w
91
+ sendMessage: I,
92
+ stop: L,
93
+ clearMessages: S
77
94
  };
78
95
  }
79
- function P(t = {}) {
80
- const e = t.client ?? f(), n = t.autoLoad ?? !0, s = l([]), o = l(null), r = l(!1), c = l(null);
96
+ function D(t = {}) {
97
+ const e = t.client ?? g(), n = t.autoLoad ?? !0, s = v([]), a = v(null), i = v(!1), c = v(null);
81
98
  async function p() {
82
- r.value = !0, c.value = null;
99
+ i.value = !0, c.value = null;
83
100
  try {
84
101
  s.value = (await e.getConversations()).data;
85
- } catch (g) {
86
- c.value = g instanceof Error ? g : /* @__PURE__ */ new Error("Failed to load conversations");
102
+ } catch (d) {
103
+ c.value = d instanceof Error ? d : /* @__PURE__ */ new Error("Failed to load conversations");
87
104
  } finally {
88
- r.value = !1;
105
+ i.value = !1;
89
106
  }
90
107
  }
91
- async function h(g) {
92
- r.value = !0, c.value = null;
108
+ async function h(d) {
109
+ i.value = !0, c.value = null;
93
110
  try {
94
- o.value = await e.getConversation(g);
95
- } catch (w) {
96
- c.value = w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversation");
111
+ a.value = await e.getConversation(d);
112
+ } catch (I) {
113
+ c.value = I instanceof Error ? I : /* @__PURE__ */ new Error("Failed to load conversation");
97
114
  } finally {
98
- r.value = !1;
115
+ i.value = !1;
99
116
  }
100
117
  }
101
118
  function C() {
102
- o.value = null;
119
+ a.value = null;
103
120
  }
104
- return d(() => {
121
+ return f(() => {
105
122
  n && p();
106
123
  }), {
107
124
  conversations: s,
108
- currentConversation: o,
109
- isLoading: r,
125
+ currentConversation: a,
126
+ isLoading: i,
110
127
  error: c,
111
128
  selectConversation: h,
112
129
  startNewConversation: C,
113
130
  refreshConversations: p
114
131
  };
115
132
  }
116
- function k(t = {}) {
117
- const e = R({
133
+ function G(t = {}) {
134
+ const e = x({
118
135
  client: t.client,
119
136
  conversationId: t.conversationId
120
- }), n = P({
137
+ }), n = D({
121
138
  client: t.client,
122
139
  autoLoad: t.autoLoad
123
- }), s = M(() => e.error.value || n.error.value);
140
+ }), s = R(() => e.error.value || n.error.value);
124
141
  return {
125
142
  messages: e.messages,
126
143
  isLoading: e.isLoading,
127
144
  error: s,
128
145
  sendMessage: e.sendMessage,
146
+ stop: e.stop,
129
147
  clearMessages: e.clearMessages,
130
148
  conversationId: e.conversationId,
131
149
  conversations: n.conversations,
@@ -137,8 +155,8 @@ function k(t = {}) {
137
155
  };
138
156
  }
139
157
  function O(t, e) {
140
- const n = f();
141
- d(() => {
158
+ const n = g();
159
+ f(() => {
142
160
  n.registerFunction(t, e.handler, {
143
161
  description: e.description,
144
162
  parameters: e.parameters,
@@ -148,69 +166,72 @@ function O(t, e) {
148
166
  n.unregisterFunction(t);
149
167
  });
150
168
  }
151
- function _(t, e) {
152
- const n = f();
153
- d(() => {
169
+ function T(t, e) {
170
+ const n = g();
171
+ f(() => {
154
172
  n.registerNavigationFunction(t, e);
155
173
  }), m(() => {
156
174
  n.unregisterNavigationFunction();
157
175
  });
158
176
  }
159
- function B(t, e) {
160
- const n = f(), s = e?.functionName ?? "setPageState";
161
- d(() => {
162
- n.registerPageStateFunction(t, { functionName: s });
177
+ function W(t, e) {
178
+ const n = g(), s = e?.functionName ?? "setPageState";
179
+ f(() => {
180
+ n.registerPageStateFunction(t, {
181
+ ...e,
182
+ functionName: s
183
+ });
163
184
  }), m(() => {
164
185
  n.unregisterPageStateFunction(s);
165
186
  });
166
187
  }
167
- function G(t, e) {
168
- const n = f();
169
- d(() => {
188
+ function B(t, e) {
189
+ const n = g();
190
+ f(() => {
170
191
  n.on(t, e);
171
192
  }), m(() => {
172
193
  n.off(t, e);
173
194
  });
174
195
  }
175
196
  function U(t) {
176
- const e = A(t.get());
177
- return S(t.subscribe((n) => {
197
+ const e = y(t.get());
198
+ return P(t.subscribe((n) => {
178
199
  e.value = n;
179
200
  })), e;
180
201
  }
181
- function W() {
182
- const t = f(), e = A(null), n = (o) => {
183
- e.value = o, t.proactive?.shown(o);
184
- }, s = ({ nudge: o }) => {
185
- e.value?.id === o.id && (e.value = null);
202
+ function $() {
203
+ const t = g(), e = y(null), n = (a) => {
204
+ e.value = a, t.proactive?.shown(a);
205
+ }, s = ({ nudge: a }) => {
206
+ e.value?.id === a.id && (e.value = null);
186
207
  };
187
- return d(() => {
208
+ return f(() => {
188
209
  t.on("nudge:ready", n), t.on("nudge:accepted", s), t.on("nudge:dismissed", s);
189
210
  }), m(() => {
190
211
  t.off("nudge:ready", n), t.off("nudge:accepted", s), t.off("nudge:dismissed", s);
191
212
  }), {
192
213
  nudge: e,
193
214
  accept: async () => {
194
- const o = e.value;
195
- o && (e.value = null, await t.proactive?.accept(o));
215
+ const a = e.value;
216
+ a && (e.value = null, await t.proactive?.accept(a));
196
217
  },
197
218
  dismiss: () => {
198
- const o = e.value;
199
- o && (e.value = null, t.proactive?.dismiss(o));
219
+ const a = e.value;
220
+ a && (e.value = null, t.proactive?.dismiss(a));
200
221
  }
201
222
  };
202
223
  }
203
224
  export {
204
- N as AGO_CLIENT_KEY,
205
- b as AgoPlugin,
206
- f as useAgo,
207
- G as useAgoEvents,
225
+ A as AGO_CLIENT_KEY,
226
+ k as AgoPlugin,
227
+ g as useAgo,
228
+ B as useAgoEvents,
208
229
  O as useAgoFunction,
209
- _ as useAgoNavigation,
210
- B as useAgoPageState,
230
+ T as useAgoNavigation,
231
+ W as useAgoPageState,
211
232
  U as useAgoStore,
212
- k as useChat,
213
- P as useConversation,
214
- R as useMessages,
215
- W as useProactiveNudge
233
+ G as useChat,
234
+ D as useConversation,
235
+ x as useMessages,
236
+ $ as useProactiveNudge
216
237
  };