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