agents 0.11.8 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +37 -1
  2. package/dist/{index-DSwOzhhd.d.ts → agent-tool-types-tBGRsPm0.d.ts} +584 -99
  3. package/dist/agent-tool-types.d.ts +34 -0
  4. package/dist/agent-tool-types.js +1 -0
  5. package/dist/agent-tools-BAdX1vdI.js +425 -0
  6. package/dist/agent-tools-BAdX1vdI.js.map +1 -0
  7. package/dist/agent-tools-CIO14miM.d.ts +14 -0
  8. package/dist/agent-tools.d.ts +68 -0
  9. package/dist/agent-tools.js +51 -0
  10. package/dist/agent-tools.js.map +1 -0
  11. package/dist/browser/ai.d.ts +1 -1
  12. package/dist/browser/ai.js +2 -2
  13. package/dist/browser/index.d.ts +1 -1
  14. package/dist/browser/index.js +1 -1
  15. package/dist/browser/tanstack-ai.d.ts +1 -1
  16. package/dist/browser/tanstack-ai.js +1 -1
  17. package/dist/chat/index.d.ts +27 -1
  18. package/dist/chat/index.js +3 -263
  19. package/dist/chat/index.js.map +1 -1
  20. package/dist/client.d.ts +2 -2
  21. package/dist/{compaction-helpers-C_cN3z55.js → compaction-helpers-CSaqCmdE.js} +1 -1
  22. package/dist/{compaction-helpers-C_cN3z55.js.map → compaction-helpers-CSaqCmdE.js.map} +1 -1
  23. package/dist/{compaction-helpers-YzCLvunJ.d.ts → compaction-helpers-D92Ipstp.d.ts} +1 -1
  24. package/dist/experimental/memory/session/index.d.ts +1 -1
  25. package/dist/experimental/memory/session/index.js +1 -1
  26. package/dist/experimental/memory/utils/index.d.ts +1 -1
  27. package/dist/experimental/memory/utils/index.js +1 -1
  28. package/dist/index.d.ts +74 -42
  29. package/dist/index.js +1393 -296
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/client.d.ts +1 -1
  32. package/dist/mcp/index.d.ts +1 -1
  33. package/dist/react.d.ts +16 -2
  34. package/dist/react.js +42 -1
  35. package/dist/react.js.map +1 -1
  36. package/dist/{serializable-Bg8ARWlN.d.ts → serializable-Brg7fRds.d.ts} +1 -1
  37. package/dist/serializable.d.ts +1 -1
  38. package/dist/{shared-mfBbxjS1.js → shared-C6l4ZKRN.js} +1 -1
  39. package/dist/{shared-mfBbxjS1.js.map → shared-C6l4ZKRN.js.map} +1 -1
  40. package/dist/{shared-BUHZFGTk.d.ts → shared-Ch9slKdI.d.ts} +1 -1
  41. package/dist/sub-routing.d.ts +6 -6
  42. package/dist/workflows.d.ts +1 -1
  43. package/package.json +9 -4
@@ -1,4 +1,4 @@
1
- import { t as BrowserToolsOptions } from "../shared-BUHZFGTk.js";
1
+ import { t as BrowserToolsOptions } from "../shared-Ch9slKdI.js";
2
2
  import { ToolSet } from "ai";
3
3
 
4
4
  //#region src/browser/ai.d.ts
@@ -1,6 +1,6 @@
1
- import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-mfBbxjS1.js";
2
- import { z } from "zod";
1
+ import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-C6l4ZKRN.js";
3
2
  import { tool } from "ai";
3
+ import { z } from "zod";
4
4
  //#region src/browser/ai.ts
5
5
  /**
6
6
  * Create AI SDK tools for browser automation via CDP code mode.
@@ -1,4 +1,4 @@
1
- import { a as createBrowserToolHandlers, i as ToolResult, n as EXECUTE_DESCRIPTION, r as SEARCH_DESCRIPTION, t as BrowserToolsOptions } from "../shared-BUHZFGTk.js";
1
+ import { a as createBrowserToolHandlers, i as ToolResult, n as EXECUTE_DESCRIPTION, r as SEARCH_DESCRIPTION, t as BrowserToolsOptions } from "../shared-Ch9slKdI.js";
2
2
 
3
3
  //#region src/browser/cdp-session.d.ts
4
4
  interface DebugEntry {
@@ -1,2 +1,2 @@
1
- import { a as connectBrowser, i as CdpSession, n as SEARCH_DESCRIPTION, o as connectUrl, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-mfBbxjS1.js";
1
+ import { a as connectBrowser, i as CdpSession, n as SEARCH_DESCRIPTION, o as connectUrl, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-C6l4ZKRN.js";
2
2
  export { CdpSession, EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, connectBrowser, connectUrl, createBrowserToolHandlers };
@@ -1,4 +1,4 @@
1
- import { t as BrowserToolsOptions } from "../shared-BUHZFGTk.js";
1
+ import { t as BrowserToolsOptions } from "../shared-Ch9slKdI.js";
2
2
  import { ServerTool } from "@tanstack/ai";
3
3
 
4
4
  //#region src/browser/tanstack-ai.d.ts
@@ -1,4 +1,4 @@
1
- import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-mfBbxjS1.js";
1
+ import { n as SEARCH_DESCRIPTION, r as createBrowserToolHandlers, t as EXECUTE_DESCRIPTION } from "../shared-C6l4ZKRN.js";
2
2
  import { z } from "zod";
3
3
  import { toolDefinition } from "@tanstack/ai";
4
4
  //#region src/browser/tanstack-ai.ts
@@ -1,3 +1,5 @@
1
+ import { a as AgentToolEventState, i as AgentToolEventMessage, l as AgentToolRunState, r as AgentToolEvent } from "../agent-tool-types-tBGRsPm0.js";
2
+ import { n as createAgentToolEventState, t as applyAgentToolEvent } from "../agent-tools-CIO14miM.js";
1
3
  import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
2
4
  import { Connection } from "agents";
3
5
 
@@ -58,6 +60,30 @@ type StreamChunkData = {
58
60
  * @returns true if handled, false if the chunk type is not recognized
59
61
  */
60
62
  declare function applyChunkToParts(parts: MessagePart[], chunk: StreamChunkData): boolean;
63
+ /**
64
+ * Returns true if `chunk` would be a no-op replay against the already-known
65
+ * `parts` — i.e. some upstream is re-emitting events for a tool call that
66
+ * the message has already advanced past.
67
+ *
68
+ * Used by stream broadcasters to suppress re-broadcasting these chunks to
69
+ * connected clients. AI SDK v6's `updateToolPart` mutates an existing tool
70
+ * part in place when a chunk arrives with a matching `toolCallId`, so a
71
+ * replayed `tool-input-start` would clobber an `output-available` part back
72
+ * to `input-streaming` on the client (issue #1404).
73
+ *
74
+ * Only returns true when re-broadcasting would *visibly regress* state on
75
+ * a v6 client. Safe-by-construction chunk types (e.g. `tool-output-available`
76
+ * carrying the same output the part already has) return false.
77
+ *
78
+ * Conditions:
79
+ * - `tool-input-start` for a `toolCallId` that already exists in `parts`.
80
+ * - `tool-input-delta` for a `toolCallId` whose existing part is no longer
81
+ * `input-streaming`.
82
+ * - `tool-input-available` for a `toolCallId` whose existing part is no
83
+ * longer `input-streaming` (i.e. has already advanced to `input-available`
84
+ * or any terminal state).
85
+ */
86
+ declare function isReplayChunk(parts: MessagePart[], chunk: StreamChunkData): boolean;
61
87
  //#endregion
62
88
  //#region src/chat/sanitize.d.ts
63
89
  /** Maximum serialized message size before compaction (bytes). 1.8MB with headroom below SQLite's 2MB limit. */
@@ -812,5 +838,5 @@ declare function resolveToolMergeId(message: UIMessage, serverMessages: readonly
812
838
  */
813
839
  declare function assistantContentKey(message: UIMessage, sanitize?: (message: UIMessage) => UIMessage): string | undefined;
814
840
  //#endregion
815
- export { AbortRegistry, 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, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createToolsFromClientSchemas, enforceRowSizeLimit, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate };
841
+ 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 };
816
842
  //# sourceMappingURL=index.d.ts.map
@@ -1,266 +1,6 @@
1
- import { nanoid } from "nanoid";
1
+ import { i as isReplayChunk, n as createAgentToolEventState, r as applyChunkToParts, t as applyAgentToolEvent } from "../agent-tools-BAdX1vdI.js";
2
2
  import { jsonSchema, tool } from "ai";
3
- //#region src/chat/message-builder.ts
4
- /**
5
- * Applies a stream chunk to a mutable parts array, building up the message
6
- * incrementally. Returns true if the chunk was handled, false if it was
7
- * an unrecognized type (caller may handle it with additional logic).
8
- *
9
- * Handles all common chunk types that both server and client need:
10
- * - text-start / text-delta / text-end
11
- * - reasoning-start / reasoning-delta / reasoning-end
12
- * - file
13
- * - source-url / source-document
14
- * - tool-input-start / tool-input-delta / tool-input-available / tool-input-error
15
- * - tool-output-available / tool-output-error
16
- * - step-start (aliased from start-step)
17
- * - data-* (developer-defined typed JSON blobs)
18
- *
19
- * @param parts - The mutable parts array to update
20
- * @param chunk - The parsed stream chunk data
21
- * @returns true if handled, false if the chunk type is not recognized
22
- */
23
- function applyChunkToParts(parts, chunk) {
24
- switch (chunk.type) {
25
- case "text-start":
26
- parts.push({
27
- type: "text",
28
- text: "",
29
- state: "streaming"
30
- });
31
- return true;
32
- case "text-delta": {
33
- const lastTextPart = findLastPartByType(parts, "text");
34
- if (lastTextPart && lastTextPart.type === "text") lastTextPart.text += chunk.delta ?? "";
35
- else parts.push({
36
- type: "text",
37
- text: chunk.delta ?? "",
38
- state: "streaming"
39
- });
40
- return true;
41
- }
42
- case "text-end": {
43
- const lastTextPart = findLastPartByType(parts, "text");
44
- if (lastTextPart && "state" in lastTextPart) lastTextPart.state = "done";
45
- return true;
46
- }
47
- case "reasoning-start":
48
- parts.push({
49
- type: "reasoning",
50
- text: "",
51
- state: "streaming"
52
- });
53
- return true;
54
- case "reasoning-delta": {
55
- const lastReasoningPart = findLastPartByType(parts, "reasoning");
56
- if (lastReasoningPart && lastReasoningPart.type === "reasoning") {
57
- lastReasoningPart.text += chunk.delta ?? "";
58
- mergeProviderMetadata(lastReasoningPart, chunk.providerMetadata);
59
- } else parts.push({
60
- type: "reasoning",
61
- text: chunk.delta ?? "",
62
- state: "streaming",
63
- ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
64
- });
65
- return true;
66
- }
67
- case "reasoning-end": {
68
- const lastReasoningPart = findLastPartByType(parts, "reasoning");
69
- if (lastReasoningPart && "state" in lastReasoningPart) {
70
- lastReasoningPart.state = "done";
71
- mergeProviderMetadata(lastReasoningPart, chunk.providerMetadata);
72
- }
73
- return true;
74
- }
75
- case "file":
76
- parts.push({
77
- type: "file",
78
- mediaType: chunk.mediaType,
79
- url: chunk.url
80
- });
81
- return true;
82
- case "source-url":
83
- parts.push({
84
- type: "source-url",
85
- sourceId: chunk.sourceId,
86
- url: chunk.url,
87
- title: chunk.title,
88
- providerMetadata: chunk.providerMetadata
89
- });
90
- return true;
91
- case "source-document":
92
- parts.push({
93
- type: "source-document",
94
- sourceId: chunk.sourceId,
95
- mediaType: chunk.mediaType,
96
- title: chunk.title,
97
- filename: chunk.filename,
98
- providerMetadata: chunk.providerMetadata
99
- });
100
- return true;
101
- case "tool-input-start":
102
- parts.push({
103
- type: `tool-${chunk.toolName}`,
104
- toolCallId: chunk.toolCallId,
105
- toolName: chunk.toolName,
106
- state: "input-streaming",
107
- input: void 0,
108
- ...chunk.providerExecuted != null ? { providerExecuted: chunk.providerExecuted } : {},
109
- ...chunk.providerMetadata != null ? { callProviderMetadata: chunk.providerMetadata } : {},
110
- ...chunk.title != null ? { title: chunk.title } : {}
111
- });
112
- return true;
113
- case "tool-input-delta": {
114
- const toolPart = findToolPartByCallId(parts, chunk.toolCallId);
115
- if (toolPart) toolPart.input = chunk.input;
116
- return true;
117
- }
118
- case "tool-input-available": {
119
- const existing = findToolPartByCallId(parts, chunk.toolCallId);
120
- if (existing) {
121
- const p = existing;
122
- p.state = "input-available";
123
- p.input = chunk.input;
124
- if (chunk.providerExecuted != null) p.providerExecuted = chunk.providerExecuted;
125
- if (chunk.providerMetadata != null) p.callProviderMetadata = chunk.providerMetadata;
126
- if (chunk.title != null) p.title = chunk.title;
127
- } else parts.push({
128
- type: `tool-${chunk.toolName}`,
129
- toolCallId: chunk.toolCallId,
130
- toolName: chunk.toolName,
131
- state: "input-available",
132
- input: chunk.input,
133
- ...chunk.providerExecuted != null ? { providerExecuted: chunk.providerExecuted } : {},
134
- ...chunk.providerMetadata != null ? { callProviderMetadata: chunk.providerMetadata } : {},
135
- ...chunk.title != null ? { title: chunk.title } : {}
136
- });
137
- return true;
138
- }
139
- case "tool-input-error": {
140
- const existing = findToolPartByCallId(parts, chunk.toolCallId);
141
- if (existing) {
142
- const p = existing;
143
- p.state = "output-error";
144
- p.errorText = chunk.errorText;
145
- p.input = chunk.input;
146
- if (chunk.providerExecuted != null) p.providerExecuted = chunk.providerExecuted;
147
- if (chunk.providerMetadata != null) p.callProviderMetadata = chunk.providerMetadata;
148
- } else parts.push({
149
- type: `tool-${chunk.toolName}`,
150
- toolCallId: chunk.toolCallId,
151
- toolName: chunk.toolName,
152
- state: "output-error",
153
- input: chunk.input,
154
- errorText: chunk.errorText,
155
- ...chunk.providerExecuted != null ? { providerExecuted: chunk.providerExecuted } : {},
156
- ...chunk.providerMetadata != null ? { callProviderMetadata: chunk.providerMetadata } : {}
157
- });
158
- return true;
159
- }
160
- case "tool-approval-request": {
161
- const toolPart = findToolPartByCallId(parts, chunk.toolCallId);
162
- if (toolPart) {
163
- const p = toolPart;
164
- p.state = "approval-requested";
165
- p.approval = { id: chunk.approvalId };
166
- }
167
- return true;
168
- }
169
- case "tool-output-denied": {
170
- const toolPart = findToolPartByCallId(parts, chunk.toolCallId);
171
- if (toolPart) {
172
- const p = toolPart;
173
- p.state = "output-denied";
174
- }
175
- return true;
176
- }
177
- case "tool-output-available": {
178
- const toolPart = findToolPartByCallId(parts, chunk.toolCallId);
179
- if (toolPart) {
180
- const p = toolPart;
181
- p.state = "output-available";
182
- p.output = chunk.output;
183
- if (chunk.preliminary !== void 0) p.preliminary = chunk.preliminary;
184
- }
185
- return true;
186
- }
187
- case "tool-output-error": {
188
- const toolPart = findToolPartByCallId(parts, chunk.toolCallId);
189
- if (toolPart) {
190
- const p = toolPart;
191
- p.state = "output-error";
192
- p.errorText = chunk.errorText;
193
- }
194
- return true;
195
- }
196
- case "step-start":
197
- case "start-step":
198
- parts.push({ type: "step-start" });
199
- return true;
200
- default:
201
- if (chunk.type.startsWith("data-")) {
202
- if (chunk.transient) return true;
203
- if (chunk.id != null) {
204
- const existing = findDataPartByTypeAndId(parts, chunk.type, chunk.id);
205
- if (existing) {
206
- existing.data = chunk.data;
207
- return true;
208
- }
209
- }
210
- parts.push({
211
- type: chunk.type,
212
- ...chunk.id != null && { id: chunk.id },
213
- data: chunk.data
214
- });
215
- return true;
216
- }
217
- return false;
218
- }
219
- }
220
- /**
221
- * Finds the last part in the array matching the given type.
222
- * Searches from the end for efficiency (the part we want is usually recent).
223
- */
224
- function findLastPartByType(parts, type) {
225
- for (let i = parts.length - 1; i >= 0; i--) if (parts[i].type === type) return parts[i];
226
- }
227
- /**
228
- * Finds a tool part by its toolCallId.
229
- * Searches from the end since the tool part is usually recent.
230
- */
231
- function findToolPartByCallId(parts, toolCallId) {
232
- if (!toolCallId) return void 0;
233
- for (let i = parts.length - 1; i >= 0; i--) {
234
- const p = parts[i];
235
- if ("toolCallId" in p && p.toolCallId === toolCallId) return p;
236
- }
237
- }
238
- /**
239
- * Shallow-merges providerMetadata from a chunk onto an existing part.
240
- * Preserves any metadata already on the part (e.g. from earlier deltas)
241
- * while adding new keys from the chunk. This is critical for providers
242
- * like Anthropic that emit the thinking block signature on reasoning-end.
243
- */
244
- function mergeProviderMetadata(part, metadata) {
245
- if (metadata == null) return;
246
- const p = part;
247
- p.providerMetadata = {
248
- ...p.providerMetadata,
249
- ...metadata
250
- };
251
- }
252
- /**
253
- * Finds a data part by its type and id for reconciliation.
254
- * Data parts use type+id as a composite key so when the same combination
255
- * is seen again, the existing part's data is updated in-place.
256
- */
257
- function findDataPartByTypeAndId(parts, type, id) {
258
- for (let i = parts.length - 1; i >= 0; i--) {
259
- const p = parts[i];
260
- if (p.type === type && "id" in p && p.id === id) return p;
261
- }
262
- }
263
- //#endregion
3
+ import { nanoid } from "nanoid";
264
4
  //#region src/chat/sanitize.ts
265
5
  const textEncoder$1 = new TextEncoder();
266
6
  /** Maximum serialized message size before compaction (bytes). 1.8MB with headroom below SQLite's 2MB limit. */
@@ -1578,6 +1318,6 @@ function findMessageByToolCallId(messages, toolCallId) {
1578
1318
  }
1579
1319
  }
1580
1320
  //#endregion
1581
- export { AbortRegistry, CHAT_MESSAGE_TYPES, ContinuationState, ROW_MAX_BYTES, ResumableStream, StreamAccumulator, SubmitConcurrencyController, TurnQueue, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createToolsFromClientSchemas, enforceRowSizeLimit, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate };
1321
+ export { AbortRegistry, CHAT_MESSAGE_TYPES, ContinuationState, ROW_MAX_BYTES, ResumableStream, StreamAccumulator, SubmitConcurrencyController, TurnQueue, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createAgentToolEventState, createToolsFromClientSchemas, enforceRowSizeLimit, isReplayChunk, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate };
1582
1322
 
1583
1323
  //# sourceMappingURL=index.js.map