@useago/sdk 1.5.6 → 1.7.1
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.
- package/CHANGELOG.md +233 -0
- package/README.md +59 -0
- package/dist/{AgoClient-B_R_qi2s.js → AgoClient-BJjLTOw4.js} +658 -388
- package/dist/AgoClient-B_u_d-XS.cjs +9 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +230 -5
- package/dist/angular.d.ts +230 -5
- package/dist/angular.js +10 -1
- package/dist/{createConversationSession-Dqh7NXK4.cjs → createConversationSession-BCdwAhLF.cjs} +1 -1
- package/dist/{createConversationSession-CdtI4vrf.js → createConversationSession-Bgvx753t.js} +1 -1
- package/dist/{createFormCollector-YwaZ78wU.js → createFormCollector-CM3qjGcM.js} +1 -1
- package/dist/{createFormCollector-BjO3oB63.cjs → createFormCollector-ssBP8u0p.cjs} +1 -1
- package/dist/{createMockClient-DcuNlufr.js → createMockClient-BDLW6tVc.js} +5 -2
- package/dist/createMockClient-BSNuN3ys.cjs +1 -0
- package/dist/devtools.d.cts +220 -5
- package/dist/devtools.d.ts +220 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +238 -6
- package/dist/index.d.ts +238 -6
- package/dist/index.js +111 -109
- package/dist/react.cjs +40 -3
- package/dist/react.d.cts +419 -7
- package/dist/react.d.ts +419 -7
- package/dist/react.js +1195 -743
- package/dist/sheetController-CBUVOroo.js +205 -0
- package/dist/sheetController-DY-sC13T.cjs +1 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +220 -5
- package/dist/testing.d.ts +220 -5
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +235 -5
- package/dist/vue.d.ts +235 -5
- package/dist/vue.js +121 -100
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +328 -5
- package/dist/widget.d.ts +328 -5
- package/dist/widget.js +721 -629
- package/llms-full.txt +202 -14
- package/package.json +1 -1
- package/dist/AgoClient-DLB9icvv.cjs +0 -8
- package/dist/createMockClient-Dw-cyISN.cjs +0 -1
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
|
|
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
|
|
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
|
|
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
|
|
package/dist/index.d.ts
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
|
|
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
|
|
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
|
|
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
|
|