@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/angular.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./AgoClient-CQh8YovA.cjs"),c=require("./autoContinue-CP9pJR-V.cjs");var n=class{constructor(t){this.client=new o.AgoClient(t),this.messages$=this.fromEvent("message:complete"),this.chunks$=this.fromEvent("message:chunk"),this.errors$=this.fromEvent("message:error"),this.messageStart$=this.fromEvent("message:start")}fromEvent(t){const e=this.client;return{subscribe(i){const r=s=>{i.next?.(s)};return e.on(t,r),{unsubscribe:()=>e.off(t,r)}}}}sendMessage(t,e){return this.client.sendMessage(t,e)}getConversations(){return this.client.getConversations().then(t=>t.data)}getConversation(t){return this.client.getConversation(t)}getMessages(t){return this.client.getMessages(t)}submitToolCallForm(t,e){return this.client.submitToolCallForm(t,e)}confirmToolCall(t){return this.client.confirmToolCall(t)}rejectToolCall(t){return this.client.rejectToolCall(t)}submitFeedback(t,e){return this.client.submitFeedback(t,e)}registerFunction(t,e,i){typeof t=="object"?this.client.registerFunction(t):this.client.registerFunction(t,e,i)}unregisterFunction(t){return this.client.unregisterFunction(t)}registerNavigationFunction(t,e){this.client.registerNavigationFunction(t,e)}unregisterNavigationFunction(){this.client.unregisterNavigationFunction()}enableAutoContinueAfterNavigation(t){return c.attachAutoContinueAfterNavigation(this.client,t)}registerPageStateFunction(t,e){this.client.registerPageStateFunction(t,e)}unregisterPageStateFunction(t){this.client.unregisterPageStateFunction(t)}on(t,e){this.client.on(t,e)}off(t,e){this.client.off(t,e)}updateConfig(t){this.client.updateConfig(t)}getClient(){return this.client}destroy(){this.client.destroy()}};function u(t){return{provide:n,useValue:new n(t)}}exports.AgoService=n;exports.provideAgo=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./AgoClient-BHegN73y.cjs"),c=require("./autoContinue-CP9pJR-V.cjs");var n=class{constructor(t){this.client=new o.AgoClient(t),this.messages$=this.fromEvent("message:complete"),this.chunks$=this.fromEvent("message:chunk"),this.errors$=this.fromEvent("message:error"),this.messageStart$=this.fromEvent("message:start")}fromEvent(t){const e=this.client;return{subscribe(i){const s=r=>{i.next?.(r)};return e.on(t,s),{unsubscribe:()=>e.off(t,s)}}}}sendMessage(t,e){return this.client.sendMessage(t,e)}stop(){return this.client.stop()}stopMessage(t){return this.client.stopMessage(t)}isGenerating(){return this.client.isGenerating()}getConversations(){return this.client.getConversations().then(t=>t.data)}getConversation(t){return this.client.getConversation(t)}getMessages(t){return this.client.getMessages(t)}submitToolCallForm(t,e){return this.client.submitToolCallForm(t,e)}confirmToolCall(t){return this.client.confirmToolCall(t)}rejectToolCall(t){return this.client.rejectToolCall(t)}submitFeedback(t,e){return this.client.submitFeedback(t,e)}registerFunction(t,e,i){typeof t=="object"?this.client.registerFunction(t):this.client.registerFunction(t,e,i)}unregisterFunction(t){return this.client.unregisterFunction(t)}registerNavigationFunction(t,e){this.client.registerNavigationFunction(t,e)}unregisterNavigationFunction(){this.client.unregisterNavigationFunction()}enableAutoContinueAfterNavigation(t){return c.attachAutoContinueAfterNavigation(this.client,t)}registerPageStateFunction(t,e){this.client.registerPageStateFunction(t,e)}unregisterPageStateFunction(t){this.client.unregisterPageStateFunction(t)}on(t,e){this.client.on(t,e)}off(t,e){this.client.off(t,e)}updateConfig(t){this.client.updateConfig(t)}getClient(){return this.client}destroy(){this.client.destroy()}};function u(t){return{provide:n,useValue:new n(t)}}exports.AgoService=n;exports.provideAgo=u;
@@ -74,6 +74,10 @@ declare class AgoClient {
74
74
  private config;
75
75
  /** Conversations already warned about an empty reply (one warning each). */
76
76
  private warnedEmptyConversations;
77
+ /** Whether the placeholder-mode page-data warning has already been logged. */
78
+ private warnedPageDataPlaceholder;
79
+ /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
80
+ private pageDataCompanions;
77
81
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
78
82
  private pendingResumes;
79
83
  /**
@@ -84,6 +88,20 @@ declare class AgoClient {
84
88
  private pendingApprovals;
85
89
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
86
90
  private resumeGate;
91
+ /** The turn currently streaming, or `null` when the client is idle. */
92
+ private activeTurn;
93
+ /**
94
+ * A turn that closed as `WAITING_CLIENT` and has not resumed yet. There is no
95
+ * open stream in that window, but the turn is still live for the user, so it
96
+ * stays stoppable (see {@link stop}).
97
+ */
98
+ private pausedTurn;
99
+ /**
100
+ * Turns stopped while they were paused on client functions. A resume may
101
+ * already be queued (or waiting on the resume gate) at that point; this drops
102
+ * it, so a stopped turn is never restarted.
103
+ */
104
+ private stoppedTurnIds;
87
105
  /**
88
106
  * Proactive-mode controller, set when the client was created with
89
107
  * `proactive` options or when `createAgoProactive(client, opts)` was called.
@@ -95,7 +113,53 @@ declare class AgoClient {
95
113
  * Send a message and receive a streaming response
96
114
  */
97
115
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
116
+ /**
117
+ * Fire the streaming request, returning `null` when the user stopped before
118
+ * the response came back. Any other failure ends the turn and propagates, so
119
+ * a real error still reaches the caller.
120
+ */
121
+ private sendRequest;
98
122
  private processSSEResponse;
123
+ /**
124
+ * Stop the turn that is generating right now: closes the stream so the UI
125
+ * stops immediately, and tells the backend to stop generating.
126
+ *
127
+ * Both halves matter. Closing the stream alone does NOT stop the agent — it
128
+ * keeps running and the full answer reappears the next time the conversation
129
+ * is loaded. The backend unwinds at its next safe point (any tool already
130
+ * running finishes, no further tool or reasoning round starts), keeps the text
131
+ * produced so far and finalizes the message as `CANCELED`.
132
+ *
133
+ * The in-flight `sendMessage` / `continueMessage` promise resolves normally
134
+ * with that partial message (it does not reject), `message:complete` fires
135
+ * with status `CANCELED`, then `message:stopped`.
136
+ *
137
+ * ```ts
138
+ * // "Stop" button
139
+ * stopButton.onclick = () => void client.stop();
140
+ * ```
141
+ *
142
+ * Returns the backend's verdict, or `null` when nothing was generating or the
143
+ * stop landed before the message had an id (the stream is still closed).
144
+ */
145
+ stop(): Promise<StopMessageResult | null>;
146
+ /**
147
+ * Ask the backend to stop a specific in-flight turn, without touching any
148
+ * local stream. Idempotent — stopping a finished turn answers
149
+ * `{ status: "not_running" }` rather than failing. Most apps want
150
+ * {@link stop} instead; use this to stop a turn started elsewhere (e.g. one
151
+ * still running after a page reload, found via `getConversation`).
152
+ */
153
+ stopMessage(messageId: string): Promise<StopMessageResult>;
154
+ /** Whether a turn is generating right now (i.e. {@link stop} has something to stop). */
155
+ isGenerating(): boolean;
156
+ /** Open a new turn, replacing any bookkeeping left by the previous one. */
157
+ private beginTurn;
158
+ private endTurn;
159
+ /** POST the stop for a turn, once, never letting the failure escape. */
160
+ private postStopForTurn;
161
+ /** The message a caller gets back when the stop beat the response. */
162
+ private buildStoppedMessage;
99
163
  private resolveClientFunctionsMode;
100
164
  /**
101
165
  * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
@@ -323,13 +387,38 @@ declare class AgoClient {
323
387
  * },
324
388
  * ]);
325
389
  * ```
390
+ *
391
+ * Pass `opts.data` and the agent also gets back **what the page now shows**,
392
+ * as the result of its own call, instead of having to wait for the next
393
+ * message's context. That also registers a read-only `readPageData`
394
+ * companion. See {@link AgoPageDataSource}.
326
395
  */
327
396
  registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
328
397
  /**
329
- * Unregister a page state function and its dynamic context provider.
330
- * Mirror of unregistering `navigateToPage`.
398
+ * Unregister a page state function, its `readPageData` companion, and its
399
+ * dynamic context provider. Mirror of unregistering `navigateToPage`.
331
400
  */
332
401
  unregisterPageStateFunction(functionName?: string): void;
402
+ /**
403
+ * Size ceiling for a page snapshot, before the envelope is accounted for.
404
+ * Read at call time, not at registration, so `updateConfig` moves it.
405
+ */
406
+ private pageDataBudget;
407
+ /** Bytes the non-`data` part of the result costs, `data` included as `null`. */
408
+ private envelopeBytes;
409
+ /**
410
+ * Wait for the page to stop reloading, then read the snapshot. `get` and
411
+ * `isLoading` are re-read from `source` on every tick so a re-render that
412
+ * swaps the closures (without re-registering) is picked up mid-wait.
413
+ */
414
+ private readPageData;
415
+ /**
416
+ * The snapshot only reaches the agent inside the same turn in pause mode,
417
+ * where the SDK submits the tool result and resumes. In placeholder mode the
418
+ * turn is already over, so a `data` source looks broken from the outside:
419
+ * say so once rather than let the integrator hunt for an SDK bug.
420
+ */
421
+ private warnIfPlaceholderMode;
333
422
  /**
334
423
  * Register or update a piece of client-side context.
335
424
  * This context is sent with every message so the AI understands the user's situation.
@@ -497,6 +586,18 @@ export declare interface AgoClientEvents {
497
586
  conversationId: string;
498
587
  messageId: string;
499
588
  };
589
+ /**
590
+ * The user stopped the turn (`client.stop()`): the stream was closed and the
591
+ * backend was told to stop generating. Always fires, so this is the event to
592
+ * finalize a UI on. When there was an answer to keep, a `message:complete`
593
+ * carrying it with status `CANCELED` fires first; there is none when the stop
594
+ * landed before the backend named the message (`messageId` is then an empty
595
+ * string) or when the stopped turn was paused on client functions.
596
+ */
597
+ "message:stopped": {
598
+ conversationId: string;
599
+ messageId: string;
600
+ };
500
601
  "message:error": {
501
602
  error: string;
502
603
  /** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
@@ -690,6 +791,80 @@ export declare interface AgoMessage {
690
791
  createdAt: Date;
691
792
  }
692
793
 
794
+ /**
795
+ * What the page currently displays, returned to the agent as the *result* of
796
+ * `setPageState` instead of only as context on the next message.
797
+ *
798
+ * Declare it when the agent should be able to act on what its own change
799
+ * produced ("search for dupont" → it can say who was found).
800
+ *
801
+ * A control change usually kicks off work (a refetch, a recomputation). The SDK
802
+ * has to wait for that work before reading, and there are two ways to tell it
803
+ * when the work is done. **Prefer the first.**
804
+ *
805
+ * **1. Return a promise from `get()`** — you own the await, so the SDK is
806
+ * exact: it resolves when your work resolves, with no polling and no timing
807
+ * assumption. With TanStack Query, `ensureQueryData` gives you that promise and
808
+ * shares the single in-flight request with the UI:
809
+ *
810
+ * ```ts
811
+ * useAgoPageState(controls, {
812
+ * data: {
813
+ * description: "The users matching the current filters.",
814
+ * get: () => queryClient.ensureQueryData({
815
+ * queryKey: ["users", filters],
816
+ * queryFn: fetchUsers,
817
+ * }),
818
+ * },
819
+ * });
820
+ * ```
821
+ *
822
+ * **2. Declare `isLoading`** — for data you cannot get a promise for. The SDK
823
+ * polls it instead, which is a heuristic: the flag has to be up within ~100 ms
824
+ * of the change or the SDK concludes the page settled and reads the previous
825
+ * rows. Fine for a query library that flips `isFetching` on render, wrong for a
826
+ * debounced fetch.
827
+ *
828
+ * ```ts
829
+ * const { data: users, isFetching } = useQuery({ queryKey: ["users", filters], queryFn: fetchUsers });
830
+ *
831
+ * useAgoPageState(controls, {
832
+ * data: {
833
+ * description: "The users matching the current filters.",
834
+ * get: () => users ?? [],
835
+ * // isFetching, NOT isLoading: a background refetch must count as loading,
836
+ * // otherwise the agent reads the rows from the previous search.
837
+ * isLoading: () => isFetching,
838
+ * },
839
+ * });
840
+ * ```
841
+ */
842
+ export declare interface AgoPageDataSource<T = unknown> {
843
+ /** What this data is, for the LLM: "The users matching the current filters." */
844
+ description: string;
845
+ /**
846
+ * The snapshot handed back to the agent.
847
+ *
848
+ * Return a promise and the SDK awaits it: that promise resolving *is* the
849
+ * signal that the work the change triggered has finished, so nothing is
850
+ * guessed. It is bounded by `settleTimeoutMs`.
851
+ */
852
+ get: () => T | Promise<T>;
853
+ /**
854
+ * True while the page is (re)loading this data. Only needed when `get()`
855
+ * cannot return a promise. The SDK polls it every 50 ms and treats two
856
+ * consecutive `false` readings as settled, so a flag raised more than ~100 ms
857
+ * after the change is missed and the agent reads stale rows.
858
+ */
859
+ isLoading?: () => boolean;
860
+ /**
861
+ * Size ceiling for the returned snapshot, in bytes. Defaults to the client's
862
+ * `maxFunctionResultBytes`. Over the ceiling the snapshot keeps the first
863
+ * whole items that fit; `success` and `applied` are never dropped.
864
+ */
865
+ maxResultBytes?: number;
866
+ }
867
+
693
868
  /**
694
869
  * Options for {@link AgoClient.registerPageStateFunction}.
695
870
  */
@@ -701,6 +876,23 @@ export declare interface AgoPageStateOptions {
701
876
  * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
702
877
  */
703
878
  requiresApproval?: boolean;
879
+ /**
880
+ * Declare what the page displays so `setPageState` returns it. Omit it and
881
+ * the result stays exactly `{ success, applied }`.
882
+ *
883
+ * Also registers a read-only companion function (`readPageData`, derived from
884
+ * `functionName`) that returns the same snapshot without touching the page.
885
+ *
886
+ * The snapshot travels only when the agent calls one of those functions: it
887
+ * is deliberately kept out of the `page-state:` dynamic context, which would
888
+ * put it in every message.
889
+ */
890
+ data?: AgoPageDataSource;
891
+ /**
892
+ * How long to wait for the page to finish reloading before reading the
893
+ * snapshot. Defaults to 10 000 ms; on timeout whatever is there is returned.
894
+ */
895
+ settleTimeoutMs?: number;
704
896
  }
705
897
 
706
898
  export declare type AgoProvideOptions = AgoConfig;
@@ -755,6 +947,16 @@ export declare class AgoService {
755
947
  private fromEvent;
756
948
  /** Send a message and get a streaming response */
757
949
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
950
+ /**
951
+ * Stop the turn that is generating: closes the stream and tells the backend to
952
+ * stop generating. The partial answer is kept and the message ends as
953
+ * `CANCELED`. No-op when nothing is generating.
954
+ */
955
+ stop(): Promise<StopMessageResult | null>;
956
+ /** Ask the backend to stop a specific in-flight turn (e.g. one found after a reload). */
957
+ stopMessage(messageId: string): Promise<StopMessageResult>;
958
+ /** Whether a turn is generating right now. */
959
+ isGenerating(): boolean;
758
960
  /** Get the most recent conversations (first page). */
759
961
  getConversations(): Promise<Conversation[]>;
760
962
  /** Get a specific conversation with messages */
@@ -1120,13 +1322,21 @@ declare class HttpClient {
1120
1322
  keepalive?: boolean;
1121
1323
  }): Promise<T>;
1122
1324
  /**
1123
- * Make a POST request and return the raw Response (for streaming)
1325
+ * Make a POST request and return the raw Response (for streaming).
1326
+ *
1327
+ * `signal` lets the caller close the stream mid-flight (see
1328
+ * `AgoClient.stop`); an abort is rethrown as-is rather than wrapped in an
1329
+ * `AgoNetworkError`, so a deliberate stop is not mistaken for a network drop.
1124
1330
  */
1125
- postStream(path: string, body?: unknown): Promise<Response>;
1331
+ postStream(path: string, body?: unknown, options?: {
1332
+ signal?: AbortSignal;
1333
+ }): Promise<Response>;
1126
1334
  /**
1127
1335
  * Make a POST request with FormData (for file uploads)
1128
1336
  */
1129
- postFormData(path: string, formData: FormData): Promise<Response>;
1337
+ postFormData(path: string, formData: FormData, options?: {
1338
+ signal?: AbortSignal;
1339
+ }): Promise<Response>;
1130
1340
  private request;
1131
1341
  private handleErrorResponse;
1132
1342
  }
@@ -1483,6 +1693,21 @@ declare interface SSEChunkData {
1483
1693
  waiting_tool_call_ids?: string[];
1484
1694
  }
1485
1695
 
1696
+ /**
1697
+ * Response of `POST /messages/{id}/stop` (see `AgoClient.stopMessage`).
1698
+ *
1699
+ * - `"stopping"` — the request was accepted; the turn unwinds at its next safe
1700
+ * point and finalizes as `CANCELED`, keeping the text produced so far.
1701
+ * - `"not_running"` — the turn had already finished. Harmless.
1702
+ * - `"not_supported"` — a background agent run, which cannot be stopped once
1703
+ * started.
1704
+ */
1705
+ declare interface StopMessageResult {
1706
+ status: "stopping" | "not_running" | "not_supported";
1707
+ /** The message's status when the stop was requested. */
1708
+ messageStatus?: MessageStatus;
1709
+ }
1710
+
1486
1711
  /** The slice of the Web Storage API that {@link createStore} relies on. */
1487
1712
  declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1488
1713
 
package/dist/angular.d.ts CHANGED
@@ -74,6 +74,10 @@ declare class AgoClient {
74
74
  private config;
75
75
  /** Conversations already warned about an empty reply (one warning each). */
76
76
  private warnedEmptyConversations;
77
+ /** Whether the placeholder-mode page-data warning has already been logged. */
78
+ private warnedPageDataPlaceholder;
79
+ /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
80
+ private pageDataCompanions;
77
81
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
78
82
  private pendingResumes;
79
83
  /**
@@ -84,6 +88,20 @@ declare class AgoClient {
84
88
  private pendingApprovals;
85
89
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
86
90
  private resumeGate;
91
+ /** The turn currently streaming, or `null` when the client is idle. */
92
+ private activeTurn;
93
+ /**
94
+ * A turn that closed as `WAITING_CLIENT` and has not resumed yet. There is no
95
+ * open stream in that window, but the turn is still live for the user, so it
96
+ * stays stoppable (see {@link stop}).
97
+ */
98
+ private pausedTurn;
99
+ /**
100
+ * Turns stopped while they were paused on client functions. A resume may
101
+ * already be queued (or waiting on the resume gate) at that point; this drops
102
+ * it, so a stopped turn is never restarted.
103
+ */
104
+ private stoppedTurnIds;
87
105
  /**
88
106
  * Proactive-mode controller, set when the client was created with
89
107
  * `proactive` options or when `createAgoProactive(client, opts)` was called.
@@ -95,7 +113,53 @@ declare class AgoClient {
95
113
  * Send a message and receive a streaming response
96
114
  */
97
115
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
116
+ /**
117
+ * Fire the streaming request, returning `null` when the user stopped before
118
+ * the response came back. Any other failure ends the turn and propagates, so
119
+ * a real error still reaches the caller.
120
+ */
121
+ private sendRequest;
98
122
  private processSSEResponse;
123
+ /**
124
+ * Stop the turn that is generating right now: closes the stream so the UI
125
+ * stops immediately, and tells the backend to stop generating.
126
+ *
127
+ * Both halves matter. Closing the stream alone does NOT stop the agent — it
128
+ * keeps running and the full answer reappears the next time the conversation
129
+ * is loaded. The backend unwinds at its next safe point (any tool already
130
+ * running finishes, no further tool or reasoning round starts), keeps the text
131
+ * produced so far and finalizes the message as `CANCELED`.
132
+ *
133
+ * The in-flight `sendMessage` / `continueMessage` promise resolves normally
134
+ * with that partial message (it does not reject), `message:complete` fires
135
+ * with status `CANCELED`, then `message:stopped`.
136
+ *
137
+ * ```ts
138
+ * // "Stop" button
139
+ * stopButton.onclick = () => void client.stop();
140
+ * ```
141
+ *
142
+ * Returns the backend's verdict, or `null` when nothing was generating or the
143
+ * stop landed before the message had an id (the stream is still closed).
144
+ */
145
+ stop(): Promise<StopMessageResult | null>;
146
+ /**
147
+ * Ask the backend to stop a specific in-flight turn, without touching any
148
+ * local stream. Idempotent — stopping a finished turn answers
149
+ * `{ status: "not_running" }` rather than failing. Most apps want
150
+ * {@link stop} instead; use this to stop a turn started elsewhere (e.g. one
151
+ * still running after a page reload, found via `getConversation`).
152
+ */
153
+ stopMessage(messageId: string): Promise<StopMessageResult>;
154
+ /** Whether a turn is generating right now (i.e. {@link stop} has something to stop). */
155
+ isGenerating(): boolean;
156
+ /** Open a new turn, replacing any bookkeeping left by the previous one. */
157
+ private beginTurn;
158
+ private endTurn;
159
+ /** POST the stop for a turn, once, never letting the failure escape. */
160
+ private postStopForTurn;
161
+ /** The message a caller gets back when the stop beat the response. */
162
+ private buildStoppedMessage;
99
163
  private resolveClientFunctionsMode;
100
164
  /**
101
165
  * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
@@ -323,13 +387,38 @@ declare class AgoClient {
323
387
  * },
324
388
  * ]);
325
389
  * ```
390
+ *
391
+ * Pass `opts.data` and the agent also gets back **what the page now shows**,
392
+ * as the result of its own call, instead of having to wait for the next
393
+ * message's context. That also registers a read-only `readPageData`
394
+ * companion. See {@link AgoPageDataSource}.
326
395
  */
327
396
  registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
328
397
  /**
329
- * Unregister a page state function and its dynamic context provider.
330
- * Mirror of unregistering `navigateToPage`.
398
+ * Unregister a page state function, its `readPageData` companion, and its
399
+ * dynamic context provider. Mirror of unregistering `navigateToPage`.
331
400
  */
332
401
  unregisterPageStateFunction(functionName?: string): void;
402
+ /**
403
+ * Size ceiling for a page snapshot, before the envelope is accounted for.
404
+ * Read at call time, not at registration, so `updateConfig` moves it.
405
+ */
406
+ private pageDataBudget;
407
+ /** Bytes the non-`data` part of the result costs, `data` included as `null`. */
408
+ private envelopeBytes;
409
+ /**
410
+ * Wait for the page to stop reloading, then read the snapshot. `get` and
411
+ * `isLoading` are re-read from `source` on every tick so a re-render that
412
+ * swaps the closures (without re-registering) is picked up mid-wait.
413
+ */
414
+ private readPageData;
415
+ /**
416
+ * The snapshot only reaches the agent inside the same turn in pause mode,
417
+ * where the SDK submits the tool result and resumes. In placeholder mode the
418
+ * turn is already over, so a `data` source looks broken from the outside:
419
+ * say so once rather than let the integrator hunt for an SDK bug.
420
+ */
421
+ private warnIfPlaceholderMode;
333
422
  /**
334
423
  * Register or update a piece of client-side context.
335
424
  * This context is sent with every message so the AI understands the user's situation.
@@ -497,6 +586,18 @@ export declare interface AgoClientEvents {
497
586
  conversationId: string;
498
587
  messageId: string;
499
588
  };
589
+ /**
590
+ * The user stopped the turn (`client.stop()`): the stream was closed and the
591
+ * backend was told to stop generating. Always fires, so this is the event to
592
+ * finalize a UI on. When there was an answer to keep, a `message:complete`
593
+ * carrying it with status `CANCELED` fires first; there is none when the stop
594
+ * landed before the backend named the message (`messageId` is then an empty
595
+ * string) or when the stopped turn was paused on client functions.
596
+ */
597
+ "message:stopped": {
598
+ conversationId: string;
599
+ messageId: string;
600
+ };
500
601
  "message:error": {
501
602
  error: string;
502
603
  /** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
@@ -690,6 +791,80 @@ export declare interface AgoMessage {
690
791
  createdAt: Date;
691
792
  }
692
793
 
794
+ /**
795
+ * What the page currently displays, returned to the agent as the *result* of
796
+ * `setPageState` instead of only as context on the next message.
797
+ *
798
+ * Declare it when the agent should be able to act on what its own change
799
+ * produced ("search for dupont" → it can say who was found).
800
+ *
801
+ * A control change usually kicks off work (a refetch, a recomputation). The SDK
802
+ * has to wait for that work before reading, and there are two ways to tell it
803
+ * when the work is done. **Prefer the first.**
804
+ *
805
+ * **1. Return a promise from `get()`** — you own the await, so the SDK is
806
+ * exact: it resolves when your work resolves, with no polling and no timing
807
+ * assumption. With TanStack Query, `ensureQueryData` gives you that promise and
808
+ * shares the single in-flight request with the UI:
809
+ *
810
+ * ```ts
811
+ * useAgoPageState(controls, {
812
+ * data: {
813
+ * description: "The users matching the current filters.",
814
+ * get: () => queryClient.ensureQueryData({
815
+ * queryKey: ["users", filters],
816
+ * queryFn: fetchUsers,
817
+ * }),
818
+ * },
819
+ * });
820
+ * ```
821
+ *
822
+ * **2. Declare `isLoading`** — for data you cannot get a promise for. The SDK
823
+ * polls it instead, which is a heuristic: the flag has to be up within ~100 ms
824
+ * of the change or the SDK concludes the page settled and reads the previous
825
+ * rows. Fine for a query library that flips `isFetching` on render, wrong for a
826
+ * debounced fetch.
827
+ *
828
+ * ```ts
829
+ * const { data: users, isFetching } = useQuery({ queryKey: ["users", filters], queryFn: fetchUsers });
830
+ *
831
+ * useAgoPageState(controls, {
832
+ * data: {
833
+ * description: "The users matching the current filters.",
834
+ * get: () => users ?? [],
835
+ * // isFetching, NOT isLoading: a background refetch must count as loading,
836
+ * // otherwise the agent reads the rows from the previous search.
837
+ * isLoading: () => isFetching,
838
+ * },
839
+ * });
840
+ * ```
841
+ */
842
+ export declare interface AgoPageDataSource<T = unknown> {
843
+ /** What this data is, for the LLM: "The users matching the current filters." */
844
+ description: string;
845
+ /**
846
+ * The snapshot handed back to the agent.
847
+ *
848
+ * Return a promise and the SDK awaits it: that promise resolving *is* the
849
+ * signal that the work the change triggered has finished, so nothing is
850
+ * guessed. It is bounded by `settleTimeoutMs`.
851
+ */
852
+ get: () => T | Promise<T>;
853
+ /**
854
+ * True while the page is (re)loading this data. Only needed when `get()`
855
+ * cannot return a promise. The SDK polls it every 50 ms and treats two
856
+ * consecutive `false` readings as settled, so a flag raised more than ~100 ms
857
+ * after the change is missed and the agent reads stale rows.
858
+ */
859
+ isLoading?: () => boolean;
860
+ /**
861
+ * Size ceiling for the returned snapshot, in bytes. Defaults to the client's
862
+ * `maxFunctionResultBytes`. Over the ceiling the snapshot keeps the first
863
+ * whole items that fit; `success` and `applied` are never dropped.
864
+ */
865
+ maxResultBytes?: number;
866
+ }
867
+
693
868
  /**
694
869
  * Options for {@link AgoClient.registerPageStateFunction}.
695
870
  */
@@ -701,6 +876,23 @@ export declare interface AgoPageStateOptions {
701
876
  * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
702
877
  */
703
878
  requiresApproval?: boolean;
879
+ /**
880
+ * Declare what the page displays so `setPageState` returns it. Omit it and
881
+ * the result stays exactly `{ success, applied }`.
882
+ *
883
+ * Also registers a read-only companion function (`readPageData`, derived from
884
+ * `functionName`) that returns the same snapshot without touching the page.
885
+ *
886
+ * The snapshot travels only when the agent calls one of those functions: it
887
+ * is deliberately kept out of the `page-state:` dynamic context, which would
888
+ * put it in every message.
889
+ */
890
+ data?: AgoPageDataSource;
891
+ /**
892
+ * How long to wait for the page to finish reloading before reading the
893
+ * snapshot. Defaults to 10 000 ms; on timeout whatever is there is returned.
894
+ */
895
+ settleTimeoutMs?: number;
704
896
  }
705
897
 
706
898
  export declare type AgoProvideOptions = AgoConfig;
@@ -755,6 +947,16 @@ export declare class AgoService {
755
947
  private fromEvent;
756
948
  /** Send a message and get a streaming response */
757
949
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
950
+ /**
951
+ * Stop the turn that is generating: closes the stream and tells the backend to
952
+ * stop generating. The partial answer is kept and the message ends as
953
+ * `CANCELED`. No-op when nothing is generating.
954
+ */
955
+ stop(): Promise<StopMessageResult | null>;
956
+ /** Ask the backend to stop a specific in-flight turn (e.g. one found after a reload). */
957
+ stopMessage(messageId: string): Promise<StopMessageResult>;
958
+ /** Whether a turn is generating right now. */
959
+ isGenerating(): boolean;
758
960
  /** Get the most recent conversations (first page). */
759
961
  getConversations(): Promise<Conversation[]>;
760
962
  /** Get a specific conversation with messages */
@@ -1120,13 +1322,21 @@ declare class HttpClient {
1120
1322
  keepalive?: boolean;
1121
1323
  }): Promise<T>;
1122
1324
  /**
1123
- * Make a POST request and return the raw Response (for streaming)
1325
+ * Make a POST request and return the raw Response (for streaming).
1326
+ *
1327
+ * `signal` lets the caller close the stream mid-flight (see
1328
+ * `AgoClient.stop`); an abort is rethrown as-is rather than wrapped in an
1329
+ * `AgoNetworkError`, so a deliberate stop is not mistaken for a network drop.
1124
1330
  */
1125
- postStream(path: string, body?: unknown): Promise<Response>;
1331
+ postStream(path: string, body?: unknown, options?: {
1332
+ signal?: AbortSignal;
1333
+ }): Promise<Response>;
1126
1334
  /**
1127
1335
  * Make a POST request with FormData (for file uploads)
1128
1336
  */
1129
- postFormData(path: string, formData: FormData): Promise<Response>;
1337
+ postFormData(path: string, formData: FormData, options?: {
1338
+ signal?: AbortSignal;
1339
+ }): Promise<Response>;
1130
1340
  private request;
1131
1341
  private handleErrorResponse;
1132
1342
  }
@@ -1483,6 +1693,21 @@ declare interface SSEChunkData {
1483
1693
  waiting_tool_call_ids?: string[];
1484
1694
  }
1485
1695
 
1696
+ /**
1697
+ * Response of `POST /messages/{id}/stop` (see `AgoClient.stopMessage`).
1698
+ *
1699
+ * - `"stopping"` — the request was accepted; the turn unwinds at its next safe
1700
+ * point and finalizes as `CANCELED`, keeping the text produced so far.
1701
+ * - `"not_running"` — the turn had already finished. Harmless.
1702
+ * - `"not_supported"` — a background agent run, which cannot be stopped once
1703
+ * started.
1704
+ */
1705
+ declare interface StopMessageResult {
1706
+ status: "stopping" | "not_running" | "not_supported";
1707
+ /** The message's status when the stop was requested. */
1708
+ messageStatus?: MessageStatus;
1709
+ }
1710
+
1486
1711
  /** The slice of the Web Storage API that {@link createStore} relies on. */
1487
1712
  declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1488
1713
 
package/dist/angular.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as o } from "./AgoClient-BI5esqbd.js";
1
+ import { t as o } from "./AgoClient-PWPaekcg.js";
2
2
  import { t as c } from "./autoContinue-CC8K9mBU.js";
3
3
  var s = class {
4
4
  constructor(t) {
@@ -16,6 +16,15 @@ var s = class {
16
16
  sendMessage(t, e) {
17
17
  return this.client.sendMessage(t, e);
18
18
  }
19
+ stop() {
20
+ return this.client.stop();
21
+ }
22
+ stopMessage(t) {
23
+ return this.client.stopMessage(t);
24
+ }
25
+ isGenerating() {
26
+ return this.client.isGenerating();
27
+ }
19
28
  getConversations() {
20
29
  return this.client.getConversations().then((t) => t.data);
21
30
  }
@@ -1 +1 @@
1
- const d=require("./AgoClient-CQh8YovA.cjs");var f="ago_widget_id",g="ago_last_thread",y=7200*1e3;function v(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.floor(Math.random()*16);return(e==="x"?r:r&3|8).toString(16)})}function _(e={}){const r=e.key??f,i=e.threadKey??g,u=e.ttlMs??y,l=e.storage??(typeof localStorage<"u"?localStorage:void 0);let n=e.widgetId??"";if(!n&&l)try{n=l.getItem(r)??""}catch{}if(n||(n=v()),l)try{l.setItem(r,n)}catch{}const o=d.createStore({value:null,lastMessageAt:null},{key:i,storage:l}),s=o.get();s.value!==null&&c(s.lastMessageAt)&&o.set({value:null,lastMessageAt:null});function c(t){return t===null?!0:Number.isFinite(u)?Date.now()-t>u:!1}return{widgetId:n,key:r,getLastActiveThread(){const{value:t,lastMessageAt:a}=o.get();return t===null||c(a)?null:t},setActiveThread(t,a){const x=a==null?null:a instanceof Date?a.getTime():a;o.set({value:t,lastMessageAt:x})},clear(){o.set({value:null,lastMessageAt:null})}}}Object.defineProperty(exports,"createConversationSession",{enumerable:!0,get:function(){return _}});
1
+ const d=require("./AgoClient-BHegN73y.cjs");var f="ago_widget_id",g="ago_last_thread",y=7200*1e3;function v(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.floor(Math.random()*16);return(e==="x"?r:r&3|8).toString(16)})}function _(e={}){const r=e.key??f,i=e.threadKey??g,u=e.ttlMs??y,l=e.storage??(typeof localStorage<"u"?localStorage:void 0);let n=e.widgetId??"";if(!n&&l)try{n=l.getItem(r)??""}catch{}if(n||(n=v()),l)try{l.setItem(r,n)}catch{}const o=d.createStore({value:null,lastMessageAt:null},{key:i,storage:l}),s=o.get();s.value!==null&&c(s.lastMessageAt)&&o.set({value:null,lastMessageAt:null});function c(t){return t===null?!0:Number.isFinite(u)?Date.now()-t>u:!1}return{widgetId:n,key:r,getLastActiveThread(){const{value:t,lastMessageAt:a}=o.get();return t===null||c(a)?null:t},setActiveThread(t,a){const x=a==null?null:a instanceof Date?a.getTime():a;o.set({value:t,lastMessageAt:x})},clear(){o.set({value:null,lastMessageAt:null})}}}Object.defineProperty(exports,"createConversationSession",{enumerable:!0,get:function(){return _}});
@@ -1,4 +1,4 @@
1
- import { h as d } from "./AgoClient-BI5esqbd.js";
1
+ import { h as d } from "./AgoClient-PWPaekcg.js";
2
2
  var f = "ago_widget_id", g = "ago_last_thread", y = 7200 * 1e3;
3
3
  function v() {
4
4
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {