agents 0.12.2 → 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.
Files changed (83) hide show
  1. package/dist/{agent-tool-types-DSteYkkS.d.ts → agent-tool-types-CM_50fcV.d.ts} +104 -87
  2. package/dist/agent-tool-types.d.ts +1 -1
  3. package/dist/agent-tools-BAdX1vdI.js.map +1 -1
  4. package/dist/{agent-tools-eGTCdVZX.d.ts → agent-tools-BylX6WXG.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +1 -1
  6. package/dist/agent-tools.js.map +1 -1
  7. package/dist/browser/ai.d.ts +2 -2
  8. package/dist/browser/ai.js +1 -1
  9. package/dist/browser/ai.js.map +1 -1
  10. package/dist/browser/index.d.ts +41 -10
  11. package/dist/browser/index.js +1 -1
  12. package/dist/browser/tanstack-ai.d.ts +2 -2
  13. package/dist/browser/tanstack-ai.js +1 -1
  14. package/dist/browser/tanstack-ai.js.map +1 -1
  15. package/dist/chat/index.d.ts +297 -148
  16. package/dist/chat/index.js +43 -14
  17. package/dist/chat/index.js.map +1 -1
  18. package/dist/{classPrivateFieldGet2-Bqby-AHD.js → classPrivateFieldGet2-CS51BNGR.js} +5 -5
  19. package/dist/cli/index.d.ts +1 -1
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/client-D1kFXo80.js.map +1 -1
  22. package/dist/client.d.ts +11 -10
  23. package/dist/client.js.map +1 -1
  24. package/dist/codemode/ai.d.ts +1 -1
  25. package/dist/{compaction-helpers-CSaqCmdE.js → compaction-helpers-DvcZnvQ1.js} +1 -1
  26. package/dist/{compaction-helpers-CSaqCmdE.js.map → compaction-helpers-DvcZnvQ1.js.map} +1 -1
  27. package/dist/{compaction-helpers-D92Ipstp.d.ts → compaction-helpers-bYvP1o2S.d.ts} +10 -3
  28. package/dist/{do-oauth-client-provider-C38aWbFV.d.ts → do-oauth-client-provider-4OKQU9rT.d.ts} +1 -1
  29. package/dist/{email-X72-zjuq.d.ts → email-J0GGS3sa.d.ts} +1 -1
  30. package/dist/email.d.ts +2 -2
  31. package/dist/email.js.map +1 -1
  32. package/dist/experimental/memory/session/index.d.ts +126 -26
  33. package/dist/experimental/memory/session/index.js +13 -3
  34. package/dist/experimental/memory/session/index.js.map +1 -1
  35. package/dist/experimental/memory/utils/index.d.ts +41 -5
  36. package/dist/experimental/memory/utils/index.js +15 -5
  37. package/dist/experimental/memory/utils/index.js.map +1 -1
  38. package/dist/experimental/webmcp.d.ts +9 -3
  39. package/dist/experimental/webmcp.js.map +1 -1
  40. package/dist/{index-Biv6K70p.d.ts → index-DKey3P4s.d.ts} +26 -2
  41. package/dist/index.d.ts +48 -44
  42. package/dist/index.js +122 -85
  43. package/dist/index.js.map +1 -1
  44. package/dist/{internal_context-BvuGZieY.d.ts → internal_context-BZrMS0B5.d.ts} +1 -1
  45. package/dist/internal_context.d.ts +1 -1
  46. package/dist/mcp/client.d.ts +26 -2
  47. package/dist/mcp/do-oauth-client-provider.d.ts +10 -2
  48. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  49. package/dist/mcp/index.d.ts +54 -2
  50. package/dist/mcp/index.js +43 -19
  51. package/dist/mcp/index.js.map +1 -1
  52. package/dist/mcp/x402.d.ts +74 -17
  53. package/dist/mcp/x402.js.map +1 -1
  54. package/dist/observability/index.d.ts +16 -2
  55. package/dist/observability/index.js +1 -1
  56. package/dist/observability/index.js.map +1 -1
  57. package/dist/react.d.ts +9 -7
  58. package/dist/react.js +18 -2
  59. package/dist/react.js.map +1 -1
  60. package/dist/{retries-fLD8cGNf.d.ts → retries-BVdRl5ZE.d.ts} +1 -1
  61. package/dist/retries.d.ts +1 -1
  62. package/dist/retries.js.map +1 -1
  63. package/dist/schedule.js.map +1 -1
  64. package/dist/serializable.d.ts +141 -7
  65. package/dist/{shared-Ch9slKdI.d.ts → shared-Cvj92byG.d.ts} +1 -1
  66. package/dist/{shared-C6l4ZKRN.js → shared-DzJYHisH.js} +3 -3
  67. package/dist/{shared-C6l4ZKRN.js.map → shared-DzJYHisH.js.map} +1 -1
  68. package/dist/sub-routing.d.ts +6 -6
  69. package/dist/sub-routing.js.map +1 -1
  70. package/dist/tool-output-truncation-CH-khbZ3.js +98 -0
  71. package/dist/tool-output-truncation-CH-khbZ3.js.map +1 -0
  72. package/dist/{types-DAHCZC_W.d.ts → types-_JjKmv-l.d.ts} +1 -1
  73. package/dist/types.d.ts +1 -1
  74. package/dist/types.js.map +1 -1
  75. package/dist/utils.js.map +1 -1
  76. package/dist/vite.js.map +1 -1
  77. package/dist/{workflow-types-DHs0L0KP.d.ts → workflow-types-Dkzg4hAx.d.ts} +1 -1
  78. package/dist/workflow-types.d.ts +1 -1
  79. package/dist/workflow-types.js.map +1 -1
  80. package/dist/workflows.d.ts +2 -2
  81. package/dist/workflows.js.map +1 -1
  82. package/package.json +9 -9
  83. package/dist/serializable-Brg7fRds.d.ts +0 -131
@@ -1,4 +1,4 @@
1
- import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-C6l4ZKRN.js";
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;AAkCnD,QAAO,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;AAC1C,MAAI,OAAO,QACT,OAAM,IAAI,MAAM,OAAO,KAAK;AAE9B,SAAO,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;AAC3C,MAAI,OAAO,QACT,OAAM,IAAI,MAAM,OAAO,KAAK;AAE9B,SAAO,EAAE,MAAM,OAAO,MAAM;GAGP,CAAC"}
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"}
@@ -1,5 +1,13 @@
1
- import { a as AgentToolEventState, i as AgentToolEventMessage, l as AgentToolRunState, r as AgentToolEvent } from "../agent-tool-types-DSteYkkS.js";
2
- import { n as createAgentToolEventState, t as applyAgentToolEvent } from "../agent-tools-eGTCdVZX.js";
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; /** When true, the output is preliminary (may be updated by a later chunk) */
33
- preliminary?: boolean; /** Approval ID for tools with needsApproval */
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<string, unknown>; /** Whether the tool was executed by the provider (e.g. Gemini code execution) */
36
- providerExecuted?: boolean; /** Payload for data-* parts (developer-defined typed JSON) */
37
- data?: unknown; /** When true, data parts are ephemeral and not persisted to message.parts */
38
- transient?: boolean; /** Message ID assigned by the server at stream start */
39
- messageId?: string; /** Per-message metadata attached by start/finish/message-metadata chunks */
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(parts: MessagePart[], chunk: StreamChunkData): boolean;
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(parts: MessagePart[], chunk: StreamChunkData): boolean;
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 (replace with summary)
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
- type: "start";
120
- messageId?: string;
121
- metadata?: Record<string, unknown>;
122
- } | {
123
- type: "finish";
124
- finishReason?: string;
125
- metadata?: Record<string, unknown>;
126
- } | {
127
- type: "message-metadata";
128
- metadata: Record<string, unknown>;
129
- } | {
130
- type: "tool-approval-request";
131
- toolCallId: string;
132
- } | {
133
- type: "cross-message-tool-update";
134
- updateType: "output-available" | "output-error";
135
- toolCallId: string;
136
- output?: unknown;
137
- errorText?: string;
138
- preliminary?: boolean;
139
- } | {
140
- type: "error";
141
- error: string;
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
- status: "completed";
178
- value: T;
179
- } | {
180
- status: "stale";
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>(requestId: string, fn: () => Promise<T>, options?: EnqueueOptions): Promise<TurnResult<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; /** Human-readable description of what the tool does */
225
- description?: Tool["description"]; /** JSON Schema defining the tool's input parameters */
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(clientTools?: ClientToolSchema[]): ToolSet;
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; /** The request ID associated with this turn. */
246
- requestId: string; /** Whether this turn was a continuation of a previous assistant turn. */
247
- continuation: boolean; /** How the turn ended. */
248
- status: "completed" | "error" | "aborted"; /** Error message when `status` is `"error"`. */
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; /** Whether the turn ran, was skipped, or was aborted. */
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; /** Request ID from the interrupted stream. */
297
- requestId: string; /** Partial text extracted from stored chunks. */
298
- partialText: string; /** Partial message parts reconstructed from chunks. */
299
- partialParts: MessagePart[]; /** Checkpoint data from `this.stash()` during the interrupted stream. */
300
- recoveryData: unknown | null; /** Current persisted messages. */
301
- messages: UIMessage[]; /** Custom body from the last chat request. */
302
- lastBody?: Record<string, unknown>; /** Client tool schemas from the last chat request. */
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; /** Schedule a continuation via `continueLastTurn()`. Default: true. */
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 = "queue" | "latest" | "merge" | "drop" | {
339
- strategy: "debounce";
340
- debounceMs?: number;
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 = "queue" | "latest" | "merge" | "drop" | {
345
- strategy: "debounce";
346
- debounceMs: number;
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
- status: "idle";
392
- } | {
393
- status: "observing";
394
- streamId: string;
395
- accumulator: StreamAccumulator;
396
- };
397
- type BroadcastStreamEvent = {
398
- type: "response";
399
- streamId: string; /** Fallback message ID for a new accumulator (ignored if one exists for this stream). */
400
- messageId: string;
401
- chunkData?: unknown;
402
- done?: boolean;
403
- error?: boolean;
404
- replay?: boolean;
405
- replayComplete?: boolean;
406
- continuation?: boolean; /** Required when continuation=true so the accumulator can pick up existing parts. */
407
- currentMessages?: UIMessage[];
408
- } | {
409
- type: "resume-fallback";
410
- streamId: string;
411
- messageId: string;
412
- } | {
413
- type: "clear";
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(state: BroadcastStreamState, event: BroadcastStreamEvent): TransitionResult;
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>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
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(connection: Connection, requestId: string): boolean;
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(notify: (conn: ContinuationConnection) => void): void;
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(parts: Array<Record<string, unknown>>, update: ToolPartUpdate): {
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(toolCallId: string, output: unknown, overrideState?: "output-error", errorText?: string): ToolPartUpdate;
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(toolCallId: string, approved: boolean): ToolPartUpdate;
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
- type: "chat-request";
756
- id: string;
757
- init: {
758
- method?: string;
759
- body?: string;
760
- [key: string]: unknown;
761
- };
762
- } | {
763
- type: "clear";
764
- } | {
765
- type: "cancel";
766
- id: string;
767
- } | {
768
- type: "tool-result";
769
- toolCallId: string;
770
- toolName: string;
771
- output: unknown;
772
- state?: string;
773
- errorText?: string;
774
- autoContinue?: boolean;
775
- clientTools?: Array<{
776
- name: string;
777
- description?: string;
778
- parameters?: unknown;
779
- }>;
780
- } | {
781
- type: "tool-approval";
782
- toolCallId: string;
783
- approved: boolean;
784
- autoContinue?: boolean;
785
- } | {
786
- type: "stream-resume-request";
787
- } | {
788
- type: "stream-resume-ack";
789
- id: string;
790
- } | {
791
- type: "messages";
792
- messages: unknown[];
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(incoming: UIMessage[], serverMessages: readonly UIMessage[], sanitizeForContentKey?: (message: UIMessage) => UIMessage): UIMessage[];
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(message: UIMessage, serverMessages: readonly UIMessage[]): UIMessage;
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(message: UIMessage, sanitize?: (message: UIMessage) => UIMessage): string | undefined;
931
+ declare function assistantContentKey(
932
+ message: UIMessage,
933
+ sanitize?: (message: UIMessage) => UIMessage
934
+ ): string | undefined;
841
935
  //#endregion
842
- export { AbortRegistry, type AgentToolEvent, type AgentToolEventMessage, type AgentToolEventState, type AgentToolRunState, type BroadcastStreamEvent, type BroadcastStreamState, type TransitionResult as BroadcastTransitionResult, CHAT_MESSAGE_TYPES, type ChatProtocolEvent, type ChatRecoveryContext, type ChatRecoveryOptions, type ChatResponseResult, type ChunkAction, type ChunkResult, type ClientToolSchema, type ContinuationConnection, type ContinuationDeferred, type ContinuationPending, ContinuationState, type EnqueueOptions, type MessageConcurrency, type MessagePart, type MessageParts, type NormalizedMessageConcurrency, ROW_MAX_BYTES, ResumableStream, type SaveMessagesOptions, type SaveMessagesResult, type SqlTaggedTemplate, StreamAccumulator, type StreamAccumulatorOptions, type StreamChunkData, SubmitConcurrencyController, type SubmitConcurrencyDecision, type ToolPartUpdate, TurnQueue, type TurnResult, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createAgentToolEventState, createToolsFromClientSchemas, enforceRowSizeLimit, isReplayChunk, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate };
843
- //# sourceMappingURL=index.d.ts.map
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