ai 7.0.19 → 7.0.20
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 +7 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +3 -12
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +2 -2
- package/package.json +1 -1
- package/src/agent/tool-loop-agent-settings.ts +7 -0
- package/src/generate-text/generate-text.ts +9 -1
- package/src/generate-text/stream-text.ts +9 -1
- package/src/util/write-to-server-response.ts +9 -0
package/dist/internal/index.js
CHANGED
|
@@ -702,7 +702,7 @@ For persistence, store `UIMessage[]` as your source of truth and call [`convertT
|
|
|
702
702
|
|
|
703
703
|
### Everything else
|
|
704
704
|
|
|
705
|
-
Other options carry over with the same names: `prepareStep`, `onStepEnd`, `onEnd`, `onError`, `toolChoice`, `activeTools`, `timeout`, `
|
|
705
|
+
Other options carry over with the same names: `prepareStep`, `onStepEnd`, `onEnd`, `onError`, `toolChoice`, `activeTools`, `timeout`, `repairToolCall`, `experimental_sandbox`, and the usual generation settings (`temperature`, `maxOutputTokens`, `topP`, …). `WorkflowAgent` additionally adds `prepareCall` (runs once before the loop) and the `experimental_onStart` / `experimental_onStepStart` / `onToolExecutionStart` / `onToolExecutionEnd` lifecycle callbacks documented above.
|
|
706
706
|
|
|
707
707
|
## Next Steps
|
|
708
708
|
|
|
@@ -1207,10 +1207,6 @@ return createUIMessageStreamResponse({
|
|
|
1207
1207
|
|
|
1208
1208
|
## Tool Call Repair
|
|
1209
1209
|
|
|
1210
|
-
<Note type="warning">
|
|
1211
|
-
The tool call repair feature is experimental and may change in the future.
|
|
1212
|
-
</Note>
|
|
1213
|
-
|
|
1214
1210
|
Language models sometimes fail to generate valid tool calls,
|
|
1215
1211
|
especially when the input schema is complex or the model is smaller.
|
|
1216
1212
|
|
|
@@ -1219,7 +1215,7 @@ in the next step to give it an opportunity to fix it.
|
|
|
1219
1215
|
However, you may want to control how invalid tool calls are repaired without requiring
|
|
1220
1216
|
additional steps that pollute the message history.
|
|
1221
1217
|
|
|
1222
|
-
You can use the `
|
|
1218
|
+
You can use the `repairToolCall` function to attempt to repair the tool call
|
|
1223
1219
|
with a custom function.
|
|
1224
1220
|
|
|
1225
1221
|
You can use different strategies to repair the tool call:
|
|
@@ -1239,12 +1235,7 @@ const result = await generateText({
|
|
|
1239
1235
|
tools,
|
|
1240
1236
|
prompt,
|
|
1241
1237
|
|
|
1242
|
-
|
|
1243
|
-
toolCall,
|
|
1244
|
-
tools,
|
|
1245
|
-
inputSchema,
|
|
1246
|
-
error,
|
|
1247
|
-
}) => {
|
|
1238
|
+
repairToolCall: async ({ toolCall, tools, inputSchema, error }) => {
|
|
1248
1239
|
if (NoSuchToolError.isInstance(error)) {
|
|
1249
1240
|
return null; // do not attempt to fix invalid tool names
|
|
1250
1241
|
}
|
|
@@ -1280,7 +1271,7 @@ const result = await generateText({
|
|
|
1280
1271
|
tools,
|
|
1281
1272
|
prompt,
|
|
1282
1273
|
|
|
1283
|
-
|
|
1274
|
+
repairToolCall: async ({
|
|
1284
1275
|
toolCall,
|
|
1285
1276
|
tools,
|
|
1286
1277
|
error,
|
|
@@ -811,7 +811,7 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
811
811
|
],
|
|
812
812
|
},
|
|
813
813
|
{
|
|
814
|
-
name: '
|
|
814
|
+
name: 'repairToolCall',
|
|
815
815
|
type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
|
|
816
816
|
isOptional: true,
|
|
817
817
|
description:
|
|
@@ -855,7 +855,7 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
855
855
|
],
|
|
856
856
|
},
|
|
857
857
|
{
|
|
858
|
-
name: '
|
|
858
|
+
name: 'repairToolCall',
|
|
859
859
|
type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
|
|
860
860
|
isOptional: true,
|
|
861
861
|
description:
|
|
@@ -133,7 +133,7 @@ To see `ToolLoopAgent` in action, check out [these examples](#examples).
|
|
|
133
133
|
'Settings for controlling what data is included in step results. requestBody, requestMessages, and responseBody apply to generate(); requestBody, requestMessages, and rawChunks apply to stream().',
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
|
-
name: '
|
|
136
|
+
name: 'repairToolCall',
|
|
137
137
|
type: 'ToolCallRepairFunction',
|
|
138
138
|
isOptional: true,
|
|
139
139
|
description:
|
|
@@ -116,7 +116,7 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
116
116
|
'Default structured output specification. Per-stream values override this default.',
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
|
-
name: '
|
|
119
|
+
name: 'repairToolCall',
|
|
120
120
|
type: 'ToolCallRepairFunction',
|
|
121
121
|
isOptional: true,
|
|
122
122
|
description:
|
|
@@ -528,7 +528,7 @@ const result = await agent.stream({
|
|
|
528
528
|
description: 'Include raw, unprocessed chunks from the provider in the stream. Default: false.',
|
|
529
529
|
},
|
|
530
530
|
{
|
|
531
|
-
name: '
|
|
531
|
+
name: 'repairToolCall',
|
|
532
532
|
type: 'ToolCallRepairFunction',
|
|
533
533
|
isOptional: true,
|
|
534
534
|
description: 'Callback to attempt automatic recovery when a tool call cannot be parsed.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -142,6 +142,13 @@ export type ToolLoopAgentSettings<
|
|
|
142
142
|
/**
|
|
143
143
|
* A function that attempts to repair a tool call that failed to parse.
|
|
144
144
|
*/
|
|
145
|
+
repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A function that attempts to repair a tool call that failed to parse.
|
|
149
|
+
*
|
|
150
|
+
* @deprecated Use `repairToolCall` instead.
|
|
151
|
+
*/
|
|
145
152
|
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
146
153
|
|
|
147
154
|
/**
|
|
@@ -248,7 +248,8 @@ export async function generateText<
|
|
|
248
248
|
activeTools,
|
|
249
249
|
toolOrder,
|
|
250
250
|
prepareStep,
|
|
251
|
-
experimental_repairToolCall
|
|
251
|
+
experimental_repairToolCall,
|
|
252
|
+
repairToolCall = experimental_repairToolCall,
|
|
252
253
|
experimental_refineToolInput: refineToolInput,
|
|
253
254
|
experimental_download: download,
|
|
254
255
|
runtimeContext = {} as RUNTIME_CONTEXT,
|
|
@@ -378,6 +379,13 @@ export async function generateText<
|
|
|
378
379
|
/**
|
|
379
380
|
* A function that attempts to repair a tool call that failed to parse.
|
|
380
381
|
*/
|
|
382
|
+
repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A function that attempts to repair a tool call that failed to parse.
|
|
386
|
+
*
|
|
387
|
+
* @deprecated Use `repairToolCall` instead.
|
|
388
|
+
*/
|
|
381
389
|
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
382
390
|
|
|
383
391
|
/**
|
|
@@ -356,7 +356,8 @@ export function streamText<
|
|
|
356
356
|
providerOptions,
|
|
357
357
|
activeTools,
|
|
358
358
|
toolOrder,
|
|
359
|
-
experimental_repairToolCall
|
|
359
|
+
experimental_repairToolCall,
|
|
360
|
+
repairToolCall = experimental_repairToolCall,
|
|
360
361
|
experimental_refineToolInput: refineToolInput,
|
|
361
362
|
experimental_transform: transform,
|
|
362
363
|
experimental_download: download,
|
|
@@ -494,6 +495,13 @@ export function streamText<
|
|
|
494
495
|
/**
|
|
495
496
|
* A function that attempts to repair a tool call that failed to parse.
|
|
496
497
|
*/
|
|
498
|
+
repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* A function that attempts to repair a tool call that failed to parse.
|
|
502
|
+
*
|
|
503
|
+
* @deprecated Use `repairToolCall` instead.
|
|
504
|
+
*/
|
|
497
505
|
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
498
506
|
|
|
499
507
|
/**
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { ServerResponse } from 'node:http';
|
|
2
2
|
|
|
3
|
+
type FlushableServerResponse = ServerResponse & {
|
|
4
|
+
flush?: () => void;
|
|
5
|
+
};
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Writes the content of a stream to a server response.
|
|
5
9
|
*/
|
|
@@ -32,6 +36,11 @@ export function writeToServerResponse({
|
|
|
32
36
|
|
|
33
37
|
// Respect backpressure: if write() returns false, wait for 'drain' event
|
|
34
38
|
const canContinue = response.write(value);
|
|
39
|
+
const flush = (response as FlushableServerResponse).flush;
|
|
40
|
+
if (typeof flush === 'function') {
|
|
41
|
+
flush.call(response);
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
if (!canContinue) {
|
|
36
45
|
await new Promise<void>(resolve => {
|
|
37
46
|
response.once('drain', resolve);
|