@useago/sdk 1.5.6 → 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 +223 -0
  2. package/README.md +59 -0
  3. package/dist/AgoClient-BHegN73y.cjs +9 -0
  4. package/dist/{AgoClient-B_R_qi2s.js → AgoClient-PWPaekcg.js} +656 -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-Dqh7NXK4.cjs → createConversationSession-BbUUukV0.cjs} +1 -1
  10. package/dist/{createConversationSession-CdtI4vrf.js → createConversationSession-BkruoOVm.js} +1 -1
  11. package/dist/{createFormCollector-BjO3oB63.cjs → createFormCollector-C1ixsjV0.cjs} +1 -1
  12. package/dist/{createFormCollector-YwaZ78wU.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-DLB9icvv.cjs +0 -8
  42. package/dist/createMockClient-Dw-cyISN.cjs +0 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./AgoClient-DLB9icvv.cjs"),C=require("./autoContinue-CP9pJR-V.cjs"),p=require("./createConversationSession-Dqh7NXK4.cjs"),f=require("./createFormCollector-BjO3oB63.cjs"),E=require("./createMockClient-Dw-cyISN.cjs");require("./testing.cjs");const g=require("./functions-CPs7omgM.cjs");function S(e){return e}function w(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function y(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function v(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function F(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function b(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function M(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function T(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function q(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*I(e,o,l){const a=[];let n=null,i=!1;const c=s=>{a.push(s),n?.()},m=s=>c({type:"start",data:s}),r=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),i=!0,n?.()},d=s=>{c({type:"error",data:s}),i=!0,n?.()},A=s=>c({type:"toolCall",data:s});e.on("message:start",m),e.on("message:chunk",r),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",A),e.sendMessage(o,l).catch(()=>{i=!0,n?.()});try{for(;!i||a.length>0;)a.length>0?yield a.shift():(await new Promise(s=>{n=s}),n=null)}finally{e.off("message:start",m),e.off("message:chunk",r),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",A)}}function h(e){let o,l,a,n,i,c;if(typeof window<"u"&&window.AGO){const r=window.AGO;o=r.basepath,l=r.widgetId,a=r.agent||r.defaultAgent,n=r.permission,i=r.email,c=r.jwt}if(typeof document<"u"){const r=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||r("ago-base-url"),l=l||r("ago-widget-id"),a=a||r("ago-agent")||r("ago-agent-id"),n=n||r("ago-permission"),i=i||r("ago-user-email")}if(typeof document<"u"){const r=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of r)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,n=n||u.getAttribute("data-ago-permission")||void 0,i=i||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,n=e?.permission||n,i=e?.userEmail||i,c=e?.userJwt||c;const m=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:n,userEmail:i,userJwt:c,debug:m}:null}function _(e){const o=h(e);if(!o)throw new t.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new t.AgoClient(o)}function k(e,o){return{...e,handler:o}}exports.ActivityLedger=t.ActivityLedger;exports.AgoApiError=t.AgoApiError;exports.AgoClient=t.AgoClient;exports.AgoError=t.AgoError;exports.AgoFunctionError=t.AgoFunctionError;exports.AgoNetworkError=t.AgoNetworkError;exports.AgoStreamError=t.AgoStreamError;exports.ClientContextRegistry=t.ClientContextRegistry;exports.DEFAULT_MAX_ACTIVITY_ENTRIES=t.DEFAULT_MAX_ACTIVITY_ENTRIES;exports.EventEmitter=t.EventEmitter;exports.FunctionRegistry=t.FunctionRegistry;exports.SSEHandler=t.SSEHandler;exports.SignalCollector=t.SignalCollector;exports.attachAutoContinueAfterNavigation=C.attachAutoContinueAfterNavigation;exports.autoDetectConfig=h;exports.canInlineImage=t.canInlineImage;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=_;exports.createAgoProactive=t.createAgoProactive;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=I;exports.createMockClient=E.createMockClient;exports.createStore=t.createStore;exports.defineFunction=S;exports.deriveFormStatus=f.deriveFormStatus;exports.formatFileSize=t.formatFileSize;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=t.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=t.logger;exports.matchesRoutePattern=t.matchesRoutePattern;exports.matchesWhen=t.matchesWhen;exports.onFormError=T;exports.onFormSubmitted=M;exports.onFunctionInvoke=q;exports.onMessage=w;exports.onMessageChunk=y;exports.onMessageError=F;exports.onMessageStart=v;exports.onToolCall=b;exports.openUrl=g.openUrl;exports.partialDeepMatch=t.partialDeepMatch;exports.safeAttachmentUrl=t.safeAttachmentUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=t.validateConfig;exports.withHandler=k;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./AgoClient-BHegN73y.cjs"),p=require("./autoContinue-CP9pJR-V.cjs"),E=require("./createConversationSession-BbUUukV0.cjs"),f=require("./createFormCollector-C1ixsjV0.cjs"),S=require("./createMockClient-BSNuN3ys.cjs");require("./testing.cjs");const g=require("./functions-CPs7omgM.cjs");function w(e){return e}function y(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function v(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function F(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function M(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function T(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function q(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function I(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*_(e,o,l){const i=[];let n=null,a=!1;const c=s=>{i.push(s),n?.()},m=s=>c({type:"start",data:s}),r=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),a=!0,n?.()},d=s=>{c({type:"error",data:s}),a=!0,n?.()},A=s=>c({type:"toolCall",data:s}),h=()=>{a=!0,n?.()};e.on("message:start",m),e.on("message:chunk",r),e.on("message:complete",u),e.on("message:error",d),e.on("message:stopped",h),e.on("toolCall:received",A),e.sendMessage(o,l).catch(()=>{a=!0,n?.()});try{for(;!a||i.length>0;)i.length>0?yield i.shift():(await new Promise(s=>{n=s}),n=null)}finally{e.off("message:start",m),e.off("message:chunk",r),e.off("message:complete",u),e.off("message:error",d),e.off("message:stopped",h),e.off("toolCall:received",A)}}function C(e){let o,l,i,n,a,c;if(typeof window<"u"&&window.AGO){const r=window.AGO;o=r.basepath,l=r.widgetId,i=r.agent||r.defaultAgent,n=r.permission,a=r.email,c=r.jwt}if(typeof document<"u"){const r=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||r("ago-base-url"),l=l||r("ago-widget-id"),i=i||r("ago-agent")||r("ago-agent-id"),n=n||r("ago-permission"),a=a||r("ago-user-email")}if(typeof document<"u"){const r=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of r)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,i=i||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,n=n||u.getAttribute("data-ago-permission")||void 0,a=a||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,i=e?.agent||e?.defaultAgentId||i,n=e?.permission||n,a=e?.userEmail||a,c=e?.userJwt||c;const m=e?.debug;return o?{baseUrl:o,widgetId:l,agent:i,permission:n,userEmail:a,userJwt:c,debug:m}:null}function k(e){const o=C(e);if(!o)throw new t.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new t.AgoClient(o)}function U(e,o){return{...e,handler:o}}exports.ActivityLedger=t.ActivityLedger;exports.AgoApiError=t.AgoApiError;exports.AgoClient=t.AgoClient;exports.AgoError=t.AgoError;exports.AgoFunctionError=t.AgoFunctionError;exports.AgoNetworkError=t.AgoNetworkError;exports.AgoStreamError=t.AgoStreamError;exports.ClientContextRegistry=t.ClientContextRegistry;exports.DEFAULT_MAX_ACTIVITY_ENTRIES=t.DEFAULT_MAX_ACTIVITY_ENTRIES;exports.EventEmitter=t.EventEmitter;exports.FunctionRegistry=t.FunctionRegistry;exports.SSEHandler=t.SSEHandler;exports.SignalCollector=t.SignalCollector;exports.attachAutoContinueAfterNavigation=p.attachAutoContinueAfterNavigation;exports.autoDetectConfig=C;exports.canInlineImage=t.canInlineImage;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=k;exports.createAgoProactive=t.createAgoProactive;exports.createConversationSession=E.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=_;exports.createMockClient=S.createMockClient;exports.createStore=t.createStore;exports.defineFunction=w;exports.deriveFormStatus=f.deriveFormStatus;exports.formatFileSize=t.formatFileSize;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=t.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=t.logger;exports.matchesRoutePattern=t.matchesRoutePattern;exports.matchesWhen=t.matchesWhen;exports.onFormError=q;exports.onFormSubmitted=T;exports.onFunctionInvoke=I;exports.onMessage=y;exports.onMessageChunk=v;exports.onMessageError=b;exports.onMessageStart=F;exports.onToolCall=M;exports.openUrl=g.openUrl;exports.partialDeepMatch=t.partialDeepMatch;exports.safeAttachmentUrl=t.safeAttachmentUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=t.validateConfig;exports.withHandler=U;
package/dist/index.d.cts CHANGED
@@ -96,6 +96,10 @@ export declare class AgoClient {
96
96
  private config;
97
97
  /** Conversations already warned about an empty reply (one warning each). */
98
98
  private warnedEmptyConversations;
99
+ /** Whether the placeholder-mode page-data warning has already been logged. */
100
+ private warnedPageDataPlaceholder;
101
+ /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
102
+ private pageDataCompanions;
99
103
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
100
104
  private pendingResumes;
101
105
  /**
@@ -106,6 +110,20 @@ export declare class AgoClient {
106
110
  private pendingApprovals;
107
111
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
108
112
  private resumeGate;
113
+ /** The turn currently streaming, or `null` when the client is idle. */
114
+ private activeTurn;
115
+ /**
116
+ * A turn that closed as `WAITING_CLIENT` and has not resumed yet. There is no
117
+ * open stream in that window, but the turn is still live for the user, so it
118
+ * stays stoppable (see {@link stop}).
119
+ */
120
+ private pausedTurn;
121
+ /**
122
+ * Turns stopped while they were paused on client functions. A resume may
123
+ * already be queued (or waiting on the resume gate) at that point; this drops
124
+ * it, so a stopped turn is never restarted.
125
+ */
126
+ private stoppedTurnIds;
109
127
  /**
110
128
  * Proactive-mode controller, set when the client was created with
111
129
  * `proactive` options or when `createAgoProactive(client, opts)` was called.
@@ -117,7 +135,53 @@ export declare class AgoClient {
117
135
  * Send a message and receive a streaming response
118
136
  */
119
137
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
138
+ /**
139
+ * Fire the streaming request, returning `null` when the user stopped before
140
+ * the response came back. Any other failure ends the turn and propagates, so
141
+ * a real error still reaches the caller.
142
+ */
143
+ private sendRequest;
120
144
  private processSSEResponse;
145
+ /**
146
+ * Stop the turn that is generating right now: closes the stream so the UI
147
+ * stops immediately, and tells the backend to stop generating.
148
+ *
149
+ * Both halves matter. Closing the stream alone does NOT stop the agent — it
150
+ * keeps running and the full answer reappears the next time the conversation
151
+ * is loaded. The backend unwinds at its next safe point (any tool already
152
+ * running finishes, no further tool or reasoning round starts), keeps the text
153
+ * produced so far and finalizes the message as `CANCELED`.
154
+ *
155
+ * The in-flight `sendMessage` / `continueMessage` promise resolves normally
156
+ * with that partial message (it does not reject), `message:complete` fires
157
+ * with status `CANCELED`, then `message:stopped`.
158
+ *
159
+ * ```ts
160
+ * // "Stop" button
161
+ * stopButton.onclick = () => void client.stop();
162
+ * ```
163
+ *
164
+ * Returns the backend's verdict, or `null` when nothing was generating or the
165
+ * stop landed before the message had an id (the stream is still closed).
166
+ */
167
+ stop(): Promise<StopMessageResult | null>;
168
+ /**
169
+ * Ask the backend to stop a specific in-flight turn, without touching any
170
+ * local stream. Idempotent — stopping a finished turn answers
171
+ * `{ status: "not_running" }` rather than failing. Most apps want
172
+ * {@link stop} instead; use this to stop a turn started elsewhere (e.g. one
173
+ * still running after a page reload, found via `getConversation`).
174
+ */
175
+ stopMessage(messageId: string): Promise<StopMessageResult>;
176
+ /** Whether a turn is generating right now (i.e. {@link stop} has something to stop). */
177
+ isGenerating(): boolean;
178
+ /** Open a new turn, replacing any bookkeeping left by the previous one. */
179
+ private beginTurn;
180
+ private endTurn;
181
+ /** POST the stop for a turn, once, never letting the failure escape. */
182
+ private postStopForTurn;
183
+ /** The message a caller gets back when the stop beat the response. */
184
+ private buildStoppedMessage;
121
185
  private resolveClientFunctionsMode;
122
186
  /**
123
187
  * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
@@ -345,13 +409,38 @@ export declare class AgoClient {
345
409
  * },
346
410
  * ]);
347
411
  * ```
412
+ *
413
+ * Pass `opts.data` and the agent also gets back **what the page now shows**,
414
+ * as the result of its own call, instead of having to wait for the next
415
+ * message's context. That also registers a read-only `readPageData`
416
+ * companion. See {@link AgoPageDataSource}.
348
417
  */
349
418
  registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
350
419
  /**
351
- * Unregister a page state function and its dynamic context provider.
352
- * Mirror of unregistering `navigateToPage`.
420
+ * Unregister a page state function, its `readPageData` companion, and its
421
+ * dynamic context provider. Mirror of unregistering `navigateToPage`.
353
422
  */
354
423
  unregisterPageStateFunction(functionName?: string): void;
424
+ /**
425
+ * Size ceiling for a page snapshot, before the envelope is accounted for.
426
+ * Read at call time, not at registration, so `updateConfig` moves it.
427
+ */
428
+ private pageDataBudget;
429
+ /** Bytes the non-`data` part of the result costs, `data` included as `null`. */
430
+ private envelopeBytes;
431
+ /**
432
+ * Wait for the page to stop reloading, then read the snapshot. `get` and
433
+ * `isLoading` are re-read from `source` on every tick so a re-render that
434
+ * swaps the closures (without re-registering) is picked up mid-wait.
435
+ */
436
+ private readPageData;
437
+ /**
438
+ * The snapshot only reaches the agent inside the same turn in pause mode,
439
+ * where the SDK submits the tool result and resumes. In placeholder mode the
440
+ * turn is already over, so a `data` source looks broken from the outside:
441
+ * say so once rather than let the integrator hunt for an SDK bug.
442
+ */
443
+ private warnIfPlaceholderMode;
355
444
  /**
356
445
  * Register or update a piece of client-side context.
357
446
  * This context is sent with every message so the AI understands the user's situation.
@@ -519,6 +608,18 @@ export declare interface AgoClientEvents {
519
608
  conversationId: string;
520
609
  messageId: string;
521
610
  };
611
+ /**
612
+ * The user stopped the turn (`client.stop()`): the stream was closed and the
613
+ * backend was told to stop generating. Always fires, so this is the event to
614
+ * finalize a UI on. When there was an answer to keep, a `message:complete`
615
+ * carrying it with status `CANCELED` fires first; there is none when the stop
616
+ * landed before the backend named the message (`messageId` is then an empty
617
+ * string) or when the stopped turn was paused on client functions.
618
+ */
619
+ "message:stopped": {
620
+ conversationId: string;
621
+ messageId: string;
622
+ };
522
623
  "message:error": {
523
624
  error: string;
524
625
  /** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
@@ -744,6 +845,80 @@ export declare class AgoNetworkError extends AgoError {
744
845
  constructor(message: string, originalError?: Error | undefined);
745
846
  }
746
847
 
848
+ /**
849
+ * What the page currently displays, returned to the agent as the *result* of
850
+ * `setPageState` instead of only as context on the next message.
851
+ *
852
+ * Declare it when the agent should be able to act on what its own change
853
+ * produced ("search for dupont" → it can say who was found).
854
+ *
855
+ * A control change usually kicks off work (a refetch, a recomputation). The SDK
856
+ * has to wait for that work before reading, and there are two ways to tell it
857
+ * when the work is done. **Prefer the first.**
858
+ *
859
+ * **1. Return a promise from `get()`** — you own the await, so the SDK is
860
+ * exact: it resolves when your work resolves, with no polling and no timing
861
+ * assumption. With TanStack Query, `ensureQueryData` gives you that promise and
862
+ * shares the single in-flight request with the UI:
863
+ *
864
+ * ```ts
865
+ * useAgoPageState(controls, {
866
+ * data: {
867
+ * description: "The users matching the current filters.",
868
+ * get: () => queryClient.ensureQueryData({
869
+ * queryKey: ["users", filters],
870
+ * queryFn: fetchUsers,
871
+ * }),
872
+ * },
873
+ * });
874
+ * ```
875
+ *
876
+ * **2. Declare `isLoading`** — for data you cannot get a promise for. The SDK
877
+ * polls it instead, which is a heuristic: the flag has to be up within ~100 ms
878
+ * of the change or the SDK concludes the page settled and reads the previous
879
+ * rows. Fine for a query library that flips `isFetching` on render, wrong for a
880
+ * debounced fetch.
881
+ *
882
+ * ```ts
883
+ * const { data: users, isFetching } = useQuery({ queryKey: ["users", filters], queryFn: fetchUsers });
884
+ *
885
+ * useAgoPageState(controls, {
886
+ * data: {
887
+ * description: "The users matching the current filters.",
888
+ * get: () => users ?? [],
889
+ * // isFetching, NOT isLoading: a background refetch must count as loading,
890
+ * // otherwise the agent reads the rows from the previous search.
891
+ * isLoading: () => isFetching,
892
+ * },
893
+ * });
894
+ * ```
895
+ */
896
+ export declare interface AgoPageDataSource<T = unknown> {
897
+ /** What this data is, for the LLM: "The users matching the current filters." */
898
+ description: string;
899
+ /**
900
+ * The snapshot handed back to the agent.
901
+ *
902
+ * Return a promise and the SDK awaits it: that promise resolving *is* the
903
+ * signal that the work the change triggered has finished, so nothing is
904
+ * guessed. It is bounded by `settleTimeoutMs`.
905
+ */
906
+ get: () => T | Promise<T>;
907
+ /**
908
+ * True while the page is (re)loading this data. Only needed when `get()`
909
+ * cannot return a promise. The SDK polls it every 50 ms and treats two
910
+ * consecutive `false` readings as settled, so a flag raised more than ~100 ms
911
+ * after the change is missed and the agent reads stale rows.
912
+ */
913
+ isLoading?: () => boolean;
914
+ /**
915
+ * Size ceiling for the returned snapshot, in bytes. Defaults to the client's
916
+ * `maxFunctionResultBytes`. Over the ceiling the snapshot keeps the first
917
+ * whole items that fit; `success` and `applied` are never dropped.
918
+ */
919
+ maxResultBytes?: number;
920
+ }
921
+
747
922
  /**
748
923
  * Options for {@link AgoClient.registerPageStateFunction}.
749
924
  */
@@ -755,6 +930,23 @@ export declare interface AgoPageStateOptions {
755
930
  * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
756
931
  */
757
932
  requiresApproval?: boolean;
933
+ /**
934
+ * Declare what the page displays so `setPageState` returns it. Omit it and
935
+ * the result stays exactly `{ success, applied }`.
936
+ *
937
+ * Also registers a read-only companion function (`readPageData`, derived from
938
+ * `functionName`) that returns the same snapshot without touching the page.
939
+ *
940
+ * The snapshot travels only when the agent calls one of those functions: it
941
+ * is deliberately kept out of the `page-state:` dynamic context, which would
942
+ * put it in every message.
943
+ */
944
+ data?: AgoPageDataSource;
945
+ /**
946
+ * How long to wait for the page to finish reloading before reading the
947
+ * snapshot. Defaults to 10 000 ms; on timeout whatever is there is returned.
948
+ */
949
+ settleTimeoutMs?: number;
758
950
  }
759
951
 
760
952
  /**
@@ -1558,6 +1750,12 @@ export declare class FunctionRegistry {
1558
1750
  constructor(options?: FunctionRegistryOptions);
1559
1751
  /** Update the client-level result-size ceiling at runtime. */
1560
1752
  setDefaultMaxResultBytes(bytes: number): void;
1753
+ /**
1754
+ * The client-level result-size ceiling in force right now. Callers that size
1755
+ * a payload before returning it must budget against this exact number, or
1756
+ * their careful truncation gets replaced by {@link guardResultSize}'s preview.
1757
+ */
1758
+ getDefaultMaxResultBytes(): number;
1561
1759
  /**
1562
1760
  * Register a function that AGO can call.
1563
1761
  * Accepts either a single definition object or (name, handler, schema) args.
@@ -1665,13 +1863,21 @@ declare class HttpClient {
1665
1863
  keepalive?: boolean;
1666
1864
  }): Promise<T>;
1667
1865
  /**
1668
- * Make a POST request and return the raw Response (for streaming)
1866
+ * Make a POST request and return the raw Response (for streaming).
1867
+ *
1868
+ * `signal` lets the caller close the stream mid-flight (see
1869
+ * `AgoClient.stop`); an abort is rethrown as-is rather than wrapped in an
1870
+ * `AgoNetworkError`, so a deliberate stop is not mistaken for a network drop.
1669
1871
  */
1670
- postStream(path: string, body?: unknown): Promise<Response>;
1872
+ postStream(path: string, body?: unknown, options?: {
1873
+ signal?: AbortSignal;
1874
+ }): Promise<Response>;
1671
1875
  /**
1672
1876
  * Make a POST request with FormData (for file uploads)
1673
1877
  */
1674
- postFormData(path: string, formData: FormData): Promise<Response>;
1878
+ postFormData(path: string, formData: FormData, options?: {
1879
+ signal?: AbortSignal;
1880
+ }): Promise<Response>;
1675
1881
  private request;
1676
1882
  private handleErrorResponse;
1677
1883
  }
@@ -2377,6 +2583,7 @@ export declare interface SSEChunkData {
2377
2583
  */
2378
2584
  export declare class SSEHandler {
2379
2585
  private callbacks;
2586
+ private options;
2380
2587
  private buffer;
2381
2588
  private message;
2382
2589
  private toolCalls;
@@ -2386,7 +2593,7 @@ export declare class SSEHandler {
2386
2593
  private answerCompleteEmitted;
2387
2594
  private waitingClientEmitted;
2388
2595
  private firedClientFunctions;
2389
- constructor(callbacks: SSEHandlerCallbacks);
2596
+ constructor(callbacks: SSEHandlerCallbacks, options?: SSEHandlerOptions);
2390
2597
  /**
2391
2598
  * Process a streaming response
2392
2599
  */
@@ -2450,6 +2657,31 @@ declare interface SSEHandlerCallbacks {
2450
2657
  onError?: (error: Error) => void;
2451
2658
  }
2452
2659
 
2660
+ declare interface SSEHandlerOptions {
2661
+ /**
2662
+ * Signal of the fetch feeding this stream. When it fires the read rejects,
2663
+ * and that is a deliberate stop rather than a failure: the handler keeps the
2664
+ * text produced so far, ends the message as `CANCELED`, and does NOT call
2665
+ * `onError`.
2666
+ */
2667
+ signal?: AbortSignal;
2668
+ }
2669
+
2670
+ /**
2671
+ * Response of `POST /messages/{id}/stop` (see `AgoClient.stopMessage`).
2672
+ *
2673
+ * - `"stopping"` — the request was accepted; the turn unwinds at its next safe
2674
+ * point and finalizes as `CANCELED`, keeping the text produced so far.
2675
+ * - `"not_running"` — the turn had already finished. Harmless.
2676
+ * - `"not_supported"` — a background agent run, which cannot be stopped once
2677
+ * started.
2678
+ */
2679
+ export declare interface StopMessageResult {
2680
+ status: "stopping" | "not_running" | "not_supported";
2681
+ /** The message's status when the stop was requested. */
2682
+ messageStatus?: MessageStatus;
2683
+ }
2684
+
2453
2685
  /** The slice of the Web Storage API that {@link createStore} relies on. */
2454
2686
  export declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
2455
2687