agents 0.12.3 → 0.12.4
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/dist/{agent-tool-types-DSteYkkS.d.ts → agent-tool-types-CM_50fcV.d.ts} +104 -87
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/agent-tools-BAdX1vdI.js.map +1 -1
- package/dist/{agent-tools-eGTCdVZX.d.ts → agent-tools-BylX6WXG.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.d.ts +2 -2
- package/dist/browser/ai.js +1 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +41 -10
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.d.ts +2 -2
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +297 -148
- package/dist/chat/index.js +43 -14
- package/dist/chat/index.js.map +1 -1
- package/dist/{classPrivateFieldGet2-Bqby-AHD.js → classPrivateFieldGet2-CS51BNGR.js} +5 -5
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/client-D1kFXo80.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.d.ts +1 -1
- package/dist/{compaction-helpers-CSaqCmdE.js → compaction-helpers-DvcZnvQ1.js} +1 -1
- package/dist/{compaction-helpers-CSaqCmdE.js.map → compaction-helpers-DvcZnvQ1.js.map} +1 -1
- package/dist/{compaction-helpers-CzCq1-fF.d.ts → compaction-helpers-bYvP1o2S.d.ts} +10 -3
- package/dist/{do-oauth-client-provider-C38aWbFV.d.ts → do-oauth-client-provider-4OKQU9rT.d.ts} +1 -1
- package/dist/{email-X72-zjuq.d.ts → email-J0GGS3sa.d.ts} +1 -1
- package/dist/email.d.ts +2 -2
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +126 -26
- package/dist/experimental/memory/session/index.js +13 -3
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +41 -5
- package/dist/experimental/memory/utils/index.js +15 -5
- package/dist/experimental/memory/utils/index.js.map +1 -1
- package/dist/experimental/webmcp.d.ts +9 -3
- package/dist/experimental/webmcp.js.map +1 -1
- package/dist/{index-Biv6K70p.d.ts → index-DKey3P4s.d.ts} +26 -2
- package/dist/index.d.ts +48 -44
- package/dist/index.js +122 -85
- package/dist/index.js.map +1 -1
- package/dist/{internal_context-BvuGZieY.d.ts → internal_context-BZrMS0B5.d.ts} +1 -1
- package/dist/internal_context.d.ts +1 -1
- package/dist/mcp/client.d.ts +26 -2
- package/dist/mcp/do-oauth-client-provider.d.ts +10 -2
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +54 -2
- package/dist/mcp/index.js +43 -19
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +74 -17
- package/dist/mcp/x402.js.map +1 -1
- package/dist/observability/index.d.ts +16 -2
- package/dist/observability/index.js +1 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.js.map +1 -1
- package/dist/{retries-fLD8cGNf.d.ts → retries-BVdRl5ZE.d.ts} +1 -1
- package/dist/retries.d.ts +1 -1
- package/dist/retries.js.map +1 -1
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{shared-Ch9slKdI.d.ts → shared-Cvj92byG.d.ts} +1 -1
- package/dist/{shared-C6l4ZKRN.js → shared-DzJYHisH.js} +3 -3
- package/dist/{shared-C6l4ZKRN.js.map → shared-DzJYHisH.js.map} +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/sub-routing.js.map +1 -1
- package/dist/tool-output-truncation-CH-khbZ3.js +98 -0
- package/dist/tool-output-truncation-CH-khbZ3.js.map +1 -0
- package/dist/{types-DAHCZC_W.d.ts → types-_JjKmv-l.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/{workflow-types-DHs0L0KP.d.ts → workflow-types-Dkzg4hAx.d.ts} +1 -1
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +2 -2
- package/dist/workflows.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-
|
|
1
|
+
import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-DzJYHisH.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { toolDefinition } from "@tanstack/ai";
|
|
4
4
|
//#region src/browser/tanstack-ai.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../src/browser/tanstack-ai.ts"],"sourcesContent":["import { toolDefinition } from \"@tanstack/ai\";\nimport type { ServerTool } from \"@tanstack/ai\";\nimport { z } from \"zod\";\nimport {\n createBrowserToolHandlers,\n SEARCH_DESCRIPTION,\n EXECUTE_DESCRIPTION,\n type BrowserToolsOptions\n} from \"./shared\";\n\nexport type { BrowserToolsOptions } from \"./shared\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array of `ServerTool`s: `browser_search` (query the CDP spec)\n * and `browser_execute` (run CDP commands against a live browser).\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * const browserTools = createBrowserTools({\n * browser: env.BROWSER,\n * loader: env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n */\nexport function createBrowserTools(options: BrowserToolsOptions): ServerTool[] {\n const handlers = createBrowserToolHandlers(options);\n\n const search = toolDefinition({\n name: \"browser_search\" as const,\n description: SEARCH_DESCRIPTION,\n inputSchema: z.object({\n code: z.string().meta({\n description: \"JavaScript async arrow function that queries the CDP spec\"\n })\n })\n }).server(async ({ code }) => {\n const result = await handlers.search(code);\n if (result.isError) {\n throw new Error(result.text);\n }\n return { text: result.text };\n });\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description: EXECUTE_DESCRIPTION,\n inputSchema: z.object({\n code: z.string().meta({\n description: \"JavaScript async arrow function that uses the cdp helper\"\n })\n })\n }).server(async ({ code }) => {\n const result = await handlers.execute(code);\n if (result.isError) {\n throw new Error(result.text);\n }\n return { text: result.text };\n });\n\n return [search, execute];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,mBAAmB,SAA4C;CAC7E,MAAM,WAAW,0BAA0B,QAAQ;
|
|
1
|
+
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../src/browser/tanstack-ai.ts"],"sourcesContent":["import { toolDefinition } from \"@tanstack/ai\";\nimport type { ServerTool } from \"@tanstack/ai\";\nimport { z } from \"zod\";\nimport {\n createBrowserToolHandlers,\n SEARCH_DESCRIPTION,\n EXECUTE_DESCRIPTION,\n type BrowserToolsOptions\n} from \"./shared\";\n\nexport type { BrowserToolsOptions } from \"./shared\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array of `ServerTool`s: `browser_search` (query the CDP spec)\n * and `browser_execute` (run CDP commands against a live browser).\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * const browserTools = createBrowserTools({\n * browser: env.BROWSER,\n * loader: env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n */\nexport function createBrowserTools(options: BrowserToolsOptions): ServerTool[] {\n const handlers = createBrowserToolHandlers(options);\n\n const search = toolDefinition({\n name: \"browser_search\" as const,\n description: SEARCH_DESCRIPTION,\n inputSchema: z.object({\n code: z.string().meta({\n description: \"JavaScript async arrow function that queries the CDP spec\"\n })\n })\n }).server(async ({ code }) => {\n const result = await handlers.search(code);\n if (result.isError) {\n throw new Error(result.text);\n }\n return { text: result.text };\n });\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description: EXECUTE_DESCRIPTION,\n inputSchema: z.object({\n code: z.string().meta({\n description: \"JavaScript async arrow function that uses the cdp helper\"\n })\n })\n }).server(async ({ code }) => {\n const result = await handlers.execute(code);\n if (result.isError) {\n throw new Error(result.text);\n }\n return { text: result.text };\n });\n\n return [search, execute];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,mBAAmB,SAA4C;CAC7E,MAAM,WAAW,0BAA0B,QAAQ;CAkCnD,OAAO,CAhCQ,eAAe;EAC5B,MAAM;EACN,aAAa;EACb,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,QAAQ,CAAC,KAAK,EACpB,aAAa,6DACd,CAAC,EACH,CAAC;EACH,CAAC,CAAC,OAAO,OAAO,EAAE,WAAW;EAC5B,MAAM,SAAS,MAAM,SAAS,OAAO,KAAK;EAC1C,IAAI,OAAO,SACT,MAAM,IAAI,MAAM,OAAO,KAAK;EAE9B,OAAO,EAAE,MAAM,OAAO,MAAM;GAmBhB,EAhBE,eAAe;EAC7B,MAAM;EACN,aAAa;EACb,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,QAAQ,CAAC,KAAK,EACpB,aAAa,4DACd,CAAC,EACH,CAAC;EACH,CAAC,CAAC,OAAO,OAAO,EAAE,WAAW;EAC5B,MAAM,SAAS,MAAM,SAAS,QAAQ,KAAK;EAC3C,IAAI,OAAO,SACT,MAAM,IAAI,MAAM,OAAO,KAAK;EAE9B,OAAO,EAAE,MAAM,OAAO,MAAM;GAGP,CAAC"}
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
a as AgentToolEventState,
|
|
3
|
+
i as AgentToolEventMessage,
|
|
4
|
+
l as AgentToolRunState,
|
|
5
|
+
r as AgentToolEvent
|
|
6
|
+
} from "../agent-tool-types-CM_50fcV.js";
|
|
7
|
+
import {
|
|
8
|
+
n as createAgentToolEventState,
|
|
9
|
+
t as applyAgentToolEvent
|
|
10
|
+
} from "../agent-tools-BylX6WXG.js";
|
|
3
11
|
import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
|
|
4
12
|
import { Connection } from "agents";
|
|
5
13
|
|
|
@@ -29,14 +37,17 @@ type StreamChunkData = {
|
|
|
29
37
|
inputTextDelta?: string;
|
|
30
38
|
output?: unknown;
|
|
31
39
|
state?: string;
|
|
32
|
-
errorText?: string
|
|
33
|
-
preliminary?: boolean
|
|
40
|
+
errorText?: string /** When true, the output is preliminary (may be updated by a later chunk) */;
|
|
41
|
+
preliminary?: boolean /** Approval ID for tools with needsApproval */;
|
|
34
42
|
approvalId?: string;
|
|
35
|
-
providerMetadata?: Record<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
providerMetadata?: Record<
|
|
44
|
+
string,
|
|
45
|
+
unknown
|
|
46
|
+
> /** Whether the tool was executed by the provider (e.g. Gemini code execution) */;
|
|
47
|
+
providerExecuted?: boolean /** Payload for data-* parts (developer-defined typed JSON) */;
|
|
48
|
+
data?: unknown /** When true, data parts are ephemeral and not persisted to message.parts */;
|
|
49
|
+
transient?: boolean /** Message ID assigned by the server at stream start */;
|
|
50
|
+
messageId?: string /** Per-message metadata attached by start/finish/message-metadata chunks */;
|
|
40
51
|
messageMetadata?: unknown;
|
|
41
52
|
[key: string]: unknown;
|
|
42
53
|
};
|
|
@@ -59,7 +70,10 @@ type StreamChunkData = {
|
|
|
59
70
|
* @param chunk - The parsed stream chunk data
|
|
60
71
|
* @returns true if handled, false if the chunk type is not recognized
|
|
61
72
|
*/
|
|
62
|
-
declare function applyChunkToParts(
|
|
73
|
+
declare function applyChunkToParts(
|
|
74
|
+
parts: MessagePart[],
|
|
75
|
+
chunk: StreamChunkData
|
|
76
|
+
): boolean;
|
|
63
77
|
/**
|
|
64
78
|
* Returns true if `chunk` would be a no-op replay against the already-known
|
|
65
79
|
* `parts` — i.e. some upstream is re-emitting events for a tool call that
|
|
@@ -83,7 +97,10 @@ declare function applyChunkToParts(parts: MessagePart[], chunk: StreamChunkData)
|
|
|
83
97
|
* longer `input-streaming` (i.e. has already advanced to `input-available`
|
|
84
98
|
* or any terminal state).
|
|
85
99
|
*/
|
|
86
|
-
declare function isReplayChunk(
|
|
100
|
+
declare function isReplayChunk(
|
|
101
|
+
parts: MessagePart[],
|
|
102
|
+
chunk: StreamChunkData
|
|
103
|
+
): boolean;
|
|
87
104
|
//#endregion
|
|
88
105
|
//#region src/chat/sanitize.d.ts
|
|
89
106
|
/** Maximum serialized message size before compaction (bytes). 1.8MB with headroom below SQLite's 2MB limit. */
|
|
@@ -103,7 +120,7 @@ declare function sanitizeMessage(message: UIMessage): UIMessage;
|
|
|
103
120
|
* when a serialized message exceeds the safety threshold (1.8MB).
|
|
104
121
|
*
|
|
105
122
|
* Compaction strategy:
|
|
106
|
-
* 1. Compact tool outputs over 1KB
|
|
123
|
+
* 1. Compact tool outputs over 1KB while preserving structured output shape
|
|
107
124
|
* 2. If still too big, truncate text parts from oldest to newest
|
|
108
125
|
*/
|
|
109
126
|
declare function enforceRowSizeLimit(message: UIMessage): UIMessage;
|
|
@@ -115,31 +132,37 @@ interface StreamAccumulatorOptions {
|
|
|
115
132
|
existingParts?: UIMessage["parts"];
|
|
116
133
|
existingMetadata?: Record<string, unknown>;
|
|
117
134
|
}
|
|
118
|
-
type ChunkAction =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
type ChunkAction =
|
|
136
|
+
| {
|
|
137
|
+
type: "start";
|
|
138
|
+
messageId?: string;
|
|
139
|
+
metadata?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
| {
|
|
142
|
+
type: "finish";
|
|
143
|
+
finishReason?: string;
|
|
144
|
+
metadata?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
| {
|
|
147
|
+
type: "message-metadata";
|
|
148
|
+
metadata: Record<string, unknown>;
|
|
149
|
+
}
|
|
150
|
+
| {
|
|
151
|
+
type: "tool-approval-request";
|
|
152
|
+
toolCallId: string;
|
|
153
|
+
}
|
|
154
|
+
| {
|
|
155
|
+
type: "cross-message-tool-update";
|
|
156
|
+
updateType: "output-available" | "output-error";
|
|
157
|
+
toolCallId: string;
|
|
158
|
+
output?: unknown;
|
|
159
|
+
errorText?: string;
|
|
160
|
+
preliminary?: boolean;
|
|
161
|
+
}
|
|
162
|
+
| {
|
|
163
|
+
type: "error";
|
|
164
|
+
error: string;
|
|
165
|
+
};
|
|
143
166
|
interface ChunkResult {
|
|
144
167
|
handled: boolean;
|
|
145
168
|
action?: ChunkAction;
|
|
@@ -173,12 +196,14 @@ declare class StreamAccumulator {
|
|
|
173
196
|
* @cloudflare/think (simple serial queue) to prevent overlapping
|
|
174
197
|
* chat turns.
|
|
175
198
|
*/
|
|
176
|
-
type TurnResult<T> =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
199
|
+
type TurnResult<T> =
|
|
200
|
+
| {
|
|
201
|
+
status: "completed";
|
|
202
|
+
value: T;
|
|
203
|
+
}
|
|
204
|
+
| {
|
|
205
|
+
status: "stale";
|
|
206
|
+
};
|
|
182
207
|
interface EnqueueOptions {
|
|
183
208
|
/**
|
|
184
209
|
* Generation to bind this turn to. Defaults to the current generation
|
|
@@ -196,7 +221,11 @@ declare class TurnQueue {
|
|
|
196
221
|
get generation(): number;
|
|
197
222
|
get activeRequestId(): string | null;
|
|
198
223
|
get isActive(): boolean;
|
|
199
|
-
enqueue<T>(
|
|
224
|
+
enqueue<T>(
|
|
225
|
+
requestId: string,
|
|
226
|
+
fn: () => Promise<T>,
|
|
227
|
+
options?: EnqueueOptions
|
|
228
|
+
): Promise<TurnResult<T>>;
|
|
200
229
|
/**
|
|
201
230
|
* Advance the generation counter. All turns enqueued under older
|
|
202
231
|
* generations will be skipped when they reach the front of the queue.
|
|
@@ -221,8 +250,8 @@ declare class TurnQueue {
|
|
|
221
250
|
* because Zod schemas cannot be serialized over the wire.
|
|
222
251
|
*/
|
|
223
252
|
type ClientToolSchema = {
|
|
224
|
-
/** Unique name for the tool */name: string
|
|
225
|
-
description?: Tool["description"]
|
|
253
|
+
/** Unique name for the tool */ name: string /** Human-readable description of what the tool does */;
|
|
254
|
+
description?: Tool["description"] /** JSON Schema defining the tool's input parameters */;
|
|
226
255
|
parameters?: JSONSchema7;
|
|
227
256
|
};
|
|
228
257
|
/**
|
|
@@ -234,7 +263,9 @@ type ClientToolSchema = {
|
|
|
234
263
|
* @param clientTools - Array of tool schemas from the client
|
|
235
264
|
* @returns Record of AI SDK tools that can be spread into your tools object
|
|
236
265
|
*/
|
|
237
|
-
declare function createToolsFromClientSchemas(
|
|
266
|
+
declare function createToolsFromClientSchemas(
|
|
267
|
+
clientTools?: ClientToolSchema[]
|
|
268
|
+
): ToolSet;
|
|
238
269
|
//#endregion
|
|
239
270
|
//#region src/chat/lifecycle.d.ts
|
|
240
271
|
/**
|
|
@@ -242,10 +273,13 @@ declare function createToolsFromClientSchemas(clientTools?: ClientToolSchema[]):
|
|
|
242
273
|
* turn completes.
|
|
243
274
|
*/
|
|
244
275
|
type ChatResponseResult = {
|
|
245
|
-
/** The finalized assistant message from this turn. */message: UIMessage
|
|
246
|
-
requestId: string
|
|
247
|
-
continuation: boolean
|
|
248
|
-
status:
|
|
276
|
+
/** The finalized assistant message from this turn. */ message: UIMessage /** The request ID associated with this turn. */;
|
|
277
|
+
requestId: string /** Whether this turn was a continuation of a previous assistant turn. */;
|
|
278
|
+
continuation: boolean /** How the turn ended. */;
|
|
279
|
+
status:
|
|
280
|
+
| "completed"
|
|
281
|
+
| "error"
|
|
282
|
+
| "aborted" /** Error message when `status` is `"error"`. */;
|
|
249
283
|
error?: string;
|
|
250
284
|
};
|
|
251
285
|
/**
|
|
@@ -285,7 +319,7 @@ type SaveMessagesOptions = {
|
|
|
285
319
|
* Partial chunks streamed before the abort are still persisted.
|
|
286
320
|
*/
|
|
287
321
|
type SaveMessagesResult = {
|
|
288
|
-
/** Server-generated request ID for the chat turn. */requestId: string
|
|
322
|
+
/** Server-generated request ID for the chat turn. */ requestId: string /** Whether the turn ran, was skipped, or was aborted. */;
|
|
289
323
|
status: "completed" | "skipped" | "aborted";
|
|
290
324
|
};
|
|
291
325
|
/**
|
|
@@ -293,13 +327,16 @@ type SaveMessagesResult = {
|
|
|
293
327
|
* stream is detected after DO restart.
|
|
294
328
|
*/
|
|
295
329
|
type ChatRecoveryContext = {
|
|
296
|
-
/** Stream ID from the interrupted stream. */streamId: string
|
|
297
|
-
requestId: string
|
|
298
|
-
partialText: string
|
|
299
|
-
partialParts: MessagePart[]
|
|
300
|
-
recoveryData: unknown | null
|
|
301
|
-
messages: UIMessage[]
|
|
302
|
-
lastBody?: Record<
|
|
330
|
+
/** Stream ID from the interrupted stream. */ streamId: string /** Request ID from the interrupted stream. */;
|
|
331
|
+
requestId: string /** Partial text extracted from stored chunks. */;
|
|
332
|
+
partialText: string /** Partial message parts reconstructed from chunks. */;
|
|
333
|
+
partialParts: MessagePart[] /** Checkpoint data from `this.stash()` during the interrupted stream. */;
|
|
334
|
+
recoveryData: unknown | null /** Current persisted messages. */;
|
|
335
|
+
messages: UIMessage[] /** Custom body from the last chat request. */;
|
|
336
|
+
lastBody?: Record<
|
|
337
|
+
string,
|
|
338
|
+
unknown
|
|
339
|
+
> /** Client tool schemas from the last chat request. */;
|
|
303
340
|
lastClientTools?: ClientToolSchema[];
|
|
304
341
|
/**
|
|
305
342
|
* Epoch milliseconds when the underlying fiber was started. Compare
|
|
@@ -312,7 +349,7 @@ type ChatRecoveryContext = {
|
|
|
312
349
|
* Options returned from `onChatRecovery` to control recovery behavior.
|
|
313
350
|
*/
|
|
314
351
|
type ChatRecoveryOptions = {
|
|
315
|
-
/** Save the partial response from stored chunks. Default: true. */persist?: boolean
|
|
352
|
+
/** Save the partial response from stored chunks. Default: true. */ persist?: boolean /** Schedule a continuation via `continueLastTurn()`. Default: true. */;
|
|
316
353
|
continue?: boolean;
|
|
317
354
|
};
|
|
318
355
|
/**
|
|
@@ -335,16 +372,26 @@ type ChatRecoveryOptions = {
|
|
|
335
372
|
* continuations, approvals, clears, programmatic `saveMessages`, and
|
|
336
373
|
* `continueLastTurn` keep their existing serialized behavior.
|
|
337
374
|
*/
|
|
338
|
-
type MessageConcurrency =
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
375
|
+
type MessageConcurrency =
|
|
376
|
+
| "queue"
|
|
377
|
+
| "latest"
|
|
378
|
+
| "merge"
|
|
379
|
+
| "drop"
|
|
380
|
+
| {
|
|
381
|
+
strategy: "debounce";
|
|
382
|
+
debounceMs?: number;
|
|
383
|
+
};
|
|
342
384
|
//#endregion
|
|
343
385
|
//#region src/chat/submit-concurrency.d.ts
|
|
344
|
-
type NormalizedMessageConcurrency =
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
386
|
+
type NormalizedMessageConcurrency =
|
|
387
|
+
| "queue"
|
|
388
|
+
| "latest"
|
|
389
|
+
| "merge"
|
|
390
|
+
| "drop"
|
|
391
|
+
| {
|
|
392
|
+
strategy: "debounce";
|
|
393
|
+
debounceMs: number;
|
|
394
|
+
};
|
|
348
395
|
type SubmitConcurrencyDecision = {
|
|
349
396
|
action: "execute" | "drop";
|
|
350
397
|
strategy: NormalizedMessageConcurrency | null;
|
|
@@ -359,9 +406,7 @@ declare class SubmitConcurrencyController {
|
|
|
359
406
|
private _resetEpoch;
|
|
360
407
|
private _activeDebounceTimers;
|
|
361
408
|
private _activeDebounceResolves;
|
|
362
|
-
constructor(options: {
|
|
363
|
-
defaultDebounceMs: number;
|
|
364
|
-
});
|
|
409
|
+
constructor(options: { defaultDebounceMs: number });
|
|
365
410
|
get pendingEnqueueCount(): number;
|
|
366
411
|
get overlappingSubmitCount(): number;
|
|
367
412
|
decide(options: {
|
|
@@ -387,37 +432,45 @@ declare class SubmitConcurrencyController {
|
|
|
387
432
|
}
|
|
388
433
|
//#endregion
|
|
389
434
|
//#region src/chat/broadcast-state.d.ts
|
|
390
|
-
type BroadcastStreamState =
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
435
|
+
type BroadcastStreamState =
|
|
436
|
+
| {
|
|
437
|
+
status: "idle";
|
|
438
|
+
}
|
|
439
|
+
| {
|
|
440
|
+
status: "observing";
|
|
441
|
+
streamId: string;
|
|
442
|
+
accumulator: StreamAccumulator;
|
|
443
|
+
};
|
|
444
|
+
type BroadcastStreamEvent =
|
|
445
|
+
| {
|
|
446
|
+
type: "response";
|
|
447
|
+
streamId: string /** Fallback message ID for a new accumulator (ignored if one exists for this stream). */;
|
|
448
|
+
messageId: string;
|
|
449
|
+
chunkData?: unknown;
|
|
450
|
+
done?: boolean;
|
|
451
|
+
error?: boolean;
|
|
452
|
+
replay?: boolean;
|
|
453
|
+
replayComplete?: boolean;
|
|
454
|
+
continuation?: boolean /** Required when continuation=true so the accumulator can pick up existing parts. */;
|
|
455
|
+
currentMessages?: UIMessage[];
|
|
456
|
+
}
|
|
457
|
+
| {
|
|
458
|
+
type: "resume-fallback";
|
|
459
|
+
streamId: string;
|
|
460
|
+
messageId: string;
|
|
461
|
+
}
|
|
462
|
+
| {
|
|
463
|
+
type: "clear";
|
|
464
|
+
};
|
|
415
465
|
interface TransitionResult {
|
|
416
466
|
state: BroadcastStreamState;
|
|
417
467
|
messagesUpdate?: (prev: UIMessage[]) => UIMessage[];
|
|
418
468
|
isStreaming: boolean;
|
|
419
469
|
}
|
|
420
|
-
declare function transition(
|
|
470
|
+
declare function transition(
|
|
471
|
+
state: BroadcastStreamState,
|
|
472
|
+
event: BroadcastStreamEvent
|
|
473
|
+
): TransitionResult;
|
|
421
474
|
//#endregion
|
|
422
475
|
//#region src/chat/resumable-stream.d.ts
|
|
423
476
|
/**
|
|
@@ -426,7 +479,10 @@ declare function transition(state: BroadcastStreamState, event: BroadcastStreamE
|
|
|
426
479
|
* depending on the full Agent class.
|
|
427
480
|
*/
|
|
428
481
|
type SqlTaggedTemplate = {
|
|
429
|
-
<T = Record<string, unknown>>(
|
|
482
|
+
<T = Record<string, unknown>>(
|
|
483
|
+
strings: TemplateStringsArray,
|
|
484
|
+
...values: (string | number | boolean | null)[]
|
|
485
|
+
): T[];
|
|
430
486
|
};
|
|
431
487
|
declare class ResumableStream {
|
|
432
488
|
private sql;
|
|
@@ -497,13 +553,20 @@ declare class ResumableStream {
|
|
|
497
553
|
* reconstruct and persist the partial message from the stored chunks.
|
|
498
554
|
* - **Completed during replay** (defensive): sends chunks + `done`.
|
|
499
555
|
*
|
|
556
|
+
* All sends use {@link sendIfOpen}, so a WebSocket closing mid-replay
|
|
557
|
+
* does not throw. If the connection drops while iterating chunks the
|
|
558
|
+
* stream is left active so the next reconnect can retry.
|
|
559
|
+
*
|
|
500
560
|
* @param connection - The WebSocket connection
|
|
501
561
|
* @param requestId - The original request ID
|
|
502
562
|
* @returns The stream ID if the stream was orphaned and finalized, null otherwise.
|
|
503
563
|
* When non-null the caller should reconstruct the message from chunks.
|
|
504
564
|
*/
|
|
505
565
|
replayChunks(connection: Connection, requestId: string): string | null;
|
|
506
|
-
replayCompletedChunksByRequestId(
|
|
566
|
+
replayCompletedChunksByRequestId(
|
|
567
|
+
connection: Connection,
|
|
568
|
+
requestId: string
|
|
569
|
+
): boolean;
|
|
507
570
|
/**
|
|
508
571
|
* Restore active stream state if the agent was restarted during streaming.
|
|
509
572
|
* All streams are restored regardless of age — stale cleanup happens
|
|
@@ -611,7 +674,9 @@ declare class ContinuationState {
|
|
|
611
674
|
* Flush awaiting connections by notifying each one via the provided
|
|
612
675
|
* callback (typically sends STREAM_RESUMING), then clear.
|
|
613
676
|
*/
|
|
614
|
-
flushAwaitingConnections(
|
|
677
|
+
flushAwaitingConnections(
|
|
678
|
+
notify: (conn: ContinuationConnection) => void
|
|
679
|
+
): void;
|
|
615
680
|
/**
|
|
616
681
|
* Transition pending → active. Called when the continuation stream
|
|
617
682
|
* actually starts. Moves request/connection IDs to active slots,
|
|
@@ -719,7 +784,10 @@ type ToolPartUpdate = {
|
|
|
719
784
|
*
|
|
720
785
|
* Returns `null` if no matching part was found.
|
|
721
786
|
*/
|
|
722
|
-
declare function applyToolUpdate(
|
|
787
|
+
declare function applyToolUpdate(
|
|
788
|
+
parts: Array<Record<string, unknown>>,
|
|
789
|
+
update: ToolPartUpdate
|
|
790
|
+
): {
|
|
723
791
|
parts: Array<Record<string, unknown>>;
|
|
724
792
|
index: number;
|
|
725
793
|
} | null;
|
|
@@ -729,14 +797,22 @@ declare function applyToolUpdate(parts: Array<Record<string, unknown>>, update:
|
|
|
729
797
|
* Matches parts in `input-available`, `approval-requested`, or `approval-responded` state.
|
|
730
798
|
* Sets state to `output-available` (with output) or `output-error` (with errorText).
|
|
731
799
|
*/
|
|
732
|
-
declare function toolResultUpdate(
|
|
800
|
+
declare function toolResultUpdate(
|
|
801
|
+
toolCallId: string,
|
|
802
|
+
output: unknown,
|
|
803
|
+
overrideState?: "output-error",
|
|
804
|
+
errorText?: string
|
|
805
|
+
): ToolPartUpdate;
|
|
733
806
|
/**
|
|
734
807
|
* Build an update descriptor for applying a tool approval.
|
|
735
808
|
*
|
|
736
809
|
* Matches parts in `input-available` or `approval-requested` state.
|
|
737
810
|
* Sets state to `approval-responded` (if approved) or `output-denied` (if denied).
|
|
738
811
|
*/
|
|
739
|
-
declare function toolApprovalUpdate(
|
|
812
|
+
declare function toolApprovalUpdate(
|
|
813
|
+
toolCallId: string,
|
|
814
|
+
approved: boolean
|
|
815
|
+
): ToolPartUpdate;
|
|
740
816
|
//#endregion
|
|
741
817
|
//#region src/chat/parse-protocol.d.ts
|
|
742
818
|
/**
|
|
@@ -751,46 +827,54 @@ declare function toolApprovalUpdate(toolCallId: string, approved: boolean): Tool
|
|
|
751
827
|
* Each agent handles the events it cares about and ignores the rest.
|
|
752
828
|
* Returns `null` for non-JSON messages or unrecognized types.
|
|
753
829
|
*/
|
|
754
|
-
type ChatProtocolEvent =
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
830
|
+
type ChatProtocolEvent =
|
|
831
|
+
| {
|
|
832
|
+
type: "chat-request";
|
|
833
|
+
id: string;
|
|
834
|
+
init: {
|
|
835
|
+
method?: string;
|
|
836
|
+
body?: string;
|
|
837
|
+
[key: string]: unknown;
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
| {
|
|
841
|
+
type: "clear";
|
|
842
|
+
}
|
|
843
|
+
| {
|
|
844
|
+
type: "cancel";
|
|
845
|
+
id: string;
|
|
846
|
+
}
|
|
847
|
+
| {
|
|
848
|
+
type: "tool-result";
|
|
849
|
+
toolCallId: string;
|
|
850
|
+
toolName: string;
|
|
851
|
+
output: unknown;
|
|
852
|
+
state?: string;
|
|
853
|
+
errorText?: string;
|
|
854
|
+
autoContinue?: boolean;
|
|
855
|
+
clientTools?: Array<{
|
|
856
|
+
name: string;
|
|
857
|
+
description?: string;
|
|
858
|
+
parameters?: unknown;
|
|
859
|
+
}>;
|
|
860
|
+
}
|
|
861
|
+
| {
|
|
862
|
+
type: "tool-approval";
|
|
863
|
+
toolCallId: string;
|
|
864
|
+
approved: boolean;
|
|
865
|
+
autoContinue?: boolean;
|
|
866
|
+
}
|
|
867
|
+
| {
|
|
868
|
+
type: "stream-resume-request";
|
|
869
|
+
}
|
|
870
|
+
| {
|
|
871
|
+
type: "stream-resume-ack";
|
|
872
|
+
id: string;
|
|
873
|
+
}
|
|
874
|
+
| {
|
|
875
|
+
type: "messages";
|
|
876
|
+
messages: unknown[];
|
|
877
|
+
};
|
|
794
878
|
/**
|
|
795
879
|
* Parse a raw WebSocket message string into a typed protocol event.
|
|
796
880
|
*
|
|
@@ -826,18 +910,83 @@ declare function parseProtocolMessage(raw: string): ChatProtocolEvent | null;
|
|
|
826
910
|
* its content key (typically strips ephemeral provider metadata)
|
|
827
911
|
* @returns Reconciled messages ready for persistence
|
|
828
912
|
*/
|
|
829
|
-
declare function reconcileMessages(
|
|
913
|
+
declare function reconcileMessages(
|
|
914
|
+
incoming: UIMessage[],
|
|
915
|
+
serverMessages: readonly UIMessage[],
|
|
916
|
+
sanitizeForContentKey?: (message: UIMessage) => UIMessage
|
|
917
|
+
): UIMessage[];
|
|
830
918
|
/**
|
|
831
919
|
* For a single message, resolve its ID by matching toolCallId against server state.
|
|
832
920
|
* Prevents duplicate DB rows when client IDs differ from server IDs.
|
|
833
921
|
* Tool call IDs are unique per conversation, so matching is safe regardless of state.
|
|
834
922
|
*/
|
|
835
|
-
declare function resolveToolMergeId(
|
|
923
|
+
declare function resolveToolMergeId(
|
|
924
|
+
message: UIMessage,
|
|
925
|
+
serverMessages: readonly UIMessage[]
|
|
926
|
+
): UIMessage;
|
|
836
927
|
/**
|
|
837
928
|
* Content key for assistant messages used for dedup of identical short replies.
|
|
838
929
|
* Returns JSON of sanitized parts, or undefined for non-assistant messages.
|
|
839
930
|
*/
|
|
840
|
-
declare function assistantContentKey(
|
|
931
|
+
declare function assistantContentKey(
|
|
932
|
+
message: UIMessage,
|
|
933
|
+
sanitize?: (message: UIMessage) => UIMessage
|
|
934
|
+
): string | undefined;
|
|
841
935
|
//#endregion
|
|
842
|
-
export {
|
|
843
|
-
|
|
936
|
+
export {
|
|
937
|
+
AbortRegistry,
|
|
938
|
+
type AgentToolEvent,
|
|
939
|
+
type AgentToolEventMessage,
|
|
940
|
+
type AgentToolEventState,
|
|
941
|
+
type AgentToolRunState,
|
|
942
|
+
type BroadcastStreamEvent,
|
|
943
|
+
type BroadcastStreamState,
|
|
944
|
+
type TransitionResult as BroadcastTransitionResult,
|
|
945
|
+
CHAT_MESSAGE_TYPES,
|
|
946
|
+
type ChatProtocolEvent,
|
|
947
|
+
type ChatRecoveryContext,
|
|
948
|
+
type ChatRecoveryOptions,
|
|
949
|
+
type ChatResponseResult,
|
|
950
|
+
type ChunkAction,
|
|
951
|
+
type ChunkResult,
|
|
952
|
+
type ClientToolSchema,
|
|
953
|
+
type ContinuationConnection,
|
|
954
|
+
type ContinuationDeferred,
|
|
955
|
+
type ContinuationPending,
|
|
956
|
+
ContinuationState,
|
|
957
|
+
type EnqueueOptions,
|
|
958
|
+
type MessageConcurrency,
|
|
959
|
+
type MessagePart,
|
|
960
|
+
type MessageParts,
|
|
961
|
+
type NormalizedMessageConcurrency,
|
|
962
|
+
ROW_MAX_BYTES,
|
|
963
|
+
ResumableStream,
|
|
964
|
+
type SaveMessagesOptions,
|
|
965
|
+
type SaveMessagesResult,
|
|
966
|
+
type SqlTaggedTemplate,
|
|
967
|
+
StreamAccumulator,
|
|
968
|
+
type StreamAccumulatorOptions,
|
|
969
|
+
type StreamChunkData,
|
|
970
|
+
SubmitConcurrencyController,
|
|
971
|
+
type SubmitConcurrencyDecision,
|
|
972
|
+
type ToolPartUpdate,
|
|
973
|
+
TurnQueue,
|
|
974
|
+
type TurnResult,
|
|
975
|
+
applyAgentToolEvent,
|
|
976
|
+
applyChunkToParts,
|
|
977
|
+
applyToolUpdate,
|
|
978
|
+
assistantContentKey,
|
|
979
|
+
transition as broadcastTransition,
|
|
980
|
+
byteLength,
|
|
981
|
+
createAgentToolEventState,
|
|
982
|
+
createToolsFromClientSchemas,
|
|
983
|
+
enforceRowSizeLimit,
|
|
984
|
+
isReplayChunk,
|
|
985
|
+
parseProtocolMessage,
|
|
986
|
+
reconcileMessages,
|
|
987
|
+
resolveToolMergeId,
|
|
988
|
+
sanitizeMessage,
|
|
989
|
+
toolApprovalUpdate,
|
|
990
|
+
toolResultUpdate
|
|
991
|
+
};
|
|
992
|
+
//# sourceMappingURL=index.d.ts.map
|