ai 7.0.172 → 7.0.174
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 +41 -0
- package/dist/index.d.ts +68 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +325 -100
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +109 -9
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +68 -18
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/02-foundations/03-prompts.mdx +1 -1
- package/docs/03-agents/04-loop-control.mdx +1 -1
- package/docs/03-agents/06-memory.mdx +28 -1
- package/docs/03-agents/06-tool-approvals.mdx +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +87 -34
- package/docs/03-ai-sdk-core/05-generating-text.mdx +7 -2
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +4 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +3 -0
- package/docs/03-ai-sdk-core/26-reasoning.mdx +3 -3
- package/docs/03-ai-sdk-core/32-decisions.mdx +4 -0
- package/docs/03-ai-sdk-core/33-extractions.mdx +59 -2
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +3 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +3 -0
- package/docs/03-ai-sdk-core/42-batch.mdx +54 -0
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -0
- package/docs/07-reference/01-ai-sdk-core/14-extract.mdx +13 -13
- package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/22-get-batch-results.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +6 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +3 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +14 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +13 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +62 -5
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -0
- package/package.json +12 -12
- package/src/agent/default-stop-condition.ts +28 -13
- package/src/batch/batch-types.ts +70 -18
- package/src/batch/batch.ts +93 -7
- package/src/extract/extract.ts +23 -4
- package/src/extract/extraction-provider.ts +5 -0
- package/src/extract/extraction-result.ts +1 -1
- package/src/generate-text/stream-text.ts +1 -1
- package/src/generate-text/validate-tool-approvals.ts +23 -19
- package/src/global.ts +1 -0
- package/src/model/resolve-model.ts +25 -0
- package/src/registry/custom-provider.ts +37 -0
- package/src/registry/index.ts +1 -0
- package/src/registry/no-such-provider-error.ts +1 -0
- package/src/registry/provider-registry.ts +59 -5
- package/src/telemetry/redact-telemetry-credentials.ts +22 -4
- package/src/types/citation.ts +41 -25
- package/src/ui/validate-ui-messages.ts +46 -91
- package/src/util/normalize-json-value.ts +182 -0
|
@@ -14,19 +14,19 @@ Extracts a nonempty map of typed fields from one state. See
|
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
16
16
|
|
|
17
|
-
| Parameter | Type | Description
|
|
18
|
-
| ----------------------- | ---------------------------------------------------------------------------------------------- |
|
|
19
|
-
| `model` | `Experimental_ExtractionModel` | Required experimental v4 extraction model instance.
|
|
20
|
-
| `state` | `Experimental_ExtractionState` | Required string, JSON object, or ordered array of text, file, and JSON parts.
|
|
21
|
-
| `fields` | `Record<string, Experimental_ExtractionField>` | Required nonempty field map.
|
|
22
|
-
| `referenceDate` | `string` | Optional `YYYY-MM-DD` date that anchors relative dates.
|
|
23
|
-
| `maxOutputTokens` | `number` | Optional maximum output tokens, an integer >= 1.
|
|
24
|
-
| `reasoning` | `'provider-default' \| 'none' \| 'minimal' \| 'low' \| 'medium' \| 'high' \| 'xhigh' \| 'max'` | Optional reasoning effort for supported models.
|
|
25
|
-
| `maxRetries` | `number` | Nonnegative integer; defaults to 2.
|
|
26
|
-
| `abortSignal` | `AbortSignal` | Cancels the extraction request.
|
|
27
|
-
| `experimental_download` | `Experimental_DownloadFunction` | Required for remote file URLs in state. Use `createDownload({ fetch })` with a DNS-protected transport for untrusted URLs.
|
|
28
|
-
| `headers` | `Record<string, string>` | Additional HTTP headers.
|
|
29
|
-
| `providerOptions` | `ProviderOptions` | Provider-specific options.
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| ----------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `model` | `Experimental_ExtractionModel` | Required experimental v4 extraction model instance, or a string ID resolved by a configured default provider with an `extractionModel` method. |
|
|
20
|
+
| `state` | `Experimental_ExtractionState` | Required string, JSON object, or ordered array of text, file, and JSON parts. |
|
|
21
|
+
| `fields` | `Record<string, Experimental_ExtractionField>` | Required nonempty field map. |
|
|
22
|
+
| `referenceDate` | `string` | Optional `YYYY-MM-DD` date that anchors relative dates. |
|
|
23
|
+
| `maxOutputTokens` | `number` | Optional maximum output tokens, an integer >= 1. |
|
|
24
|
+
| `reasoning` | `'provider-default' \| 'none' \| 'minimal' \| 'low' \| 'medium' \| 'high' \| 'xhigh' \| 'max'` | Optional reasoning effort for supported models. |
|
|
25
|
+
| `maxRetries` | `number` | Nonnegative integer; defaults to 2. |
|
|
26
|
+
| `abortSignal` | `AbortSignal` | Cancels the extraction request. |
|
|
27
|
+
| `experimental_download` | `Experimental_DownloadFunction` | Required for remote file URLs in state. Use `createDownload({ fetch })` with a DNS-protected transport for untrusted URLs. |
|
|
28
|
+
| `headers` | `Record<string, string>` | Additional HTTP headers. |
|
|
29
|
+
| `providerOptions` | `ProviderOptions` | Provider-specific options. |
|
|
30
30
|
|
|
31
31
|
Remote file URLs are rejected with `DownloadError` unless `experimental_download`
|
|
32
32
|
is supplied. The model's `fetch` option does not apply to these downloads. See
|
|
@@ -50,6 +50,13 @@ const batch = await startBatch({
|
|
|
50
50
|
description:
|
|
51
51
|
'The independent requests to process. Each request must have a unique, non-empty id, a supported type, and type-specific properties such as model and prompt or messages for text requests.',
|
|
52
52
|
},
|
|
53
|
+
{
|
|
54
|
+
name: 'output',
|
|
55
|
+
type: 'Output',
|
|
56
|
+
isOptional: true,
|
|
57
|
+
description:
|
|
58
|
+
'Specification for structured data in text responses, as in generateText. Its response format is sent with every text request; image requests ignore it. Pass the same value to getBatchResults to parse and validate results.',
|
|
59
|
+
},
|
|
53
60
|
{
|
|
54
61
|
name: 'providerOptions',
|
|
55
62
|
type: 'ProviderOptions',
|
|
@@ -59,6 +59,13 @@ for await (const item of getBatchResults({ provider: anthropic, batch })) {
|
|
|
59
59
|
description:
|
|
60
60
|
'The client-defined tools provided on requests in the batch. Used to validate and normalize returned tool calls; execute functions are never invoked.',
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
name: 'output',
|
|
64
|
+
type: 'Output',
|
|
65
|
+
isOptional: true,
|
|
66
|
+
description:
|
|
67
|
+
'The output specification that was provided on requests in the batch. When set, the text of each successful item is parsed and validated. Items have either an `output` or an `outputError`; a parsing failure does not fail the item.',
|
|
68
|
+
},
|
|
62
69
|
{
|
|
63
70
|
name: 'providerOptions',
|
|
64
71
|
type: 'ProviderOptions',
|
|
@@ -7,6 +7,12 @@ description: API Reference for validateUIMessages
|
|
|
7
7
|
|
|
8
8
|
`validateUIMessages` is an async function that validates UI messages against schemas for metadata, data parts, and tools. It ensures type safety and data integrity for your message arrays before processing or rendering.
|
|
9
9
|
|
|
10
|
+
Structural validation stops at the first invalid element in message and part arrays.
|
|
11
|
+
Part types and tool states select the applicable schema before its fields are validated.
|
|
12
|
+
The error retains the failing element's path without accumulating errors for every
|
|
13
|
+
malformed element. Valid message and part arrays have no SDK-imposed count limit;
|
|
14
|
+
apply request size and message history limits appropriate for your application.
|
|
15
|
+
|
|
10
16
|
## Basic Usage
|
|
11
17
|
|
|
12
18
|
Simple validation without custom schemas:
|
|
@@ -7,6 +7,9 @@ description: API Reference for safeValidateUIMessages
|
|
|
7
7
|
|
|
8
8
|
`safeValidateUIMessages` is an async function that validates UI messages like [`validateUIMessages`](/docs/reference/ai-sdk-core/validate-ui-messages), but instead of throwing it returns an object with a `success` key and either `data` or `error`.
|
|
9
9
|
|
|
10
|
+
Structural validation stops at the first invalid element in message and part
|
|
11
|
+
arrays, retaining its path in the returned error.
|
|
12
|
+
|
|
10
13
|
## Basic Usage
|
|
11
14
|
|
|
12
15
|
Simple validation without custom schemas:
|
|
@@ -316,3 +316,17 @@ added to the stable `ProviderV4` contract. Direct decision string IDs default
|
|
|
316
316
|
to Gateway when no default provider is configured.
|
|
317
317
|
See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
|
|
318
318
|
for runnable usage patterns.
|
|
319
|
+
|
|
320
|
+
## Experimental extraction models
|
|
321
|
+
|
|
322
|
+
The inferred return type also exposes `extractionModel('providerId:modelId')`,
|
|
323
|
+
returning `Experimental_ExtractionModelV4`. The provider must expose an
|
|
324
|
+
`extractionModel` factory. Custom separators and model ID inference work as they
|
|
325
|
+
do for decision models, and middleware does not wrap extraction models. Use the
|
|
326
|
+
inferred return type or `Experimental_ExtractionProviderRegistry`, which also
|
|
327
|
+
includes decision access, to retain experimental extraction access.
|
|
328
|
+
|
|
329
|
+
Unavailable extraction capabilities or models throw `NoSuchModelError` with
|
|
330
|
+
`modelType: 'extractionModel'`; unknown registry providers throw
|
|
331
|
+
`NoSuchProviderError`. See
|
|
332
|
+
[Extractions](/docs/ai-sdk-core/extractions#model-aliases-and-registries).
|
|
@@ -219,3 +219,16 @@ added to the stable `ProviderV4` contract. Direct decision string IDs default
|
|
|
219
219
|
to Gateway when no default provider is configured.
|
|
220
220
|
See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
|
|
221
221
|
for runnable usage patterns.
|
|
222
|
+
|
|
223
|
+
## Experimental extraction models
|
|
224
|
+
|
|
225
|
+
Pass `extractionModels: Record<string, Experimental_ExtractionModel>` to define
|
|
226
|
+
aliases for extraction model instances or string IDs. The returned provider adds
|
|
227
|
+
`extractionModel(alias): Experimental_ExtractionModelV4`. String aliases resolve
|
|
228
|
+
through an explicitly configured default provider with an `extractionModel`
|
|
229
|
+
method. Unknown aliases use the fallback provider's extraction factory when
|
|
230
|
+
available.
|
|
231
|
+
|
|
232
|
+
Unavailable extraction capabilities or models throw `NoSuchModelError` with
|
|
233
|
+
`modelType: 'extractionModel'`. See
|
|
234
|
+
[Extractions](/docs/ai-sdk-core/extractions#model-aliases-and-registries).
|
|
@@ -117,6 +117,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
117
117
|
description:
|
|
118
118
|
'Default set of active tools. Limits which tools the model can call without changing tool call and result types. Per-stream values override this default.',
|
|
119
119
|
},
|
|
120
|
+
{
|
|
121
|
+
name: 'toolOrder',
|
|
122
|
+
type: 'ToolOrder<TTools>',
|
|
123
|
+
isOptional: true,
|
|
124
|
+
description:
|
|
125
|
+
'Controls the order in which tools are sent to the provider. The list can be partial. Tools not listed in `toolOrder` are sent after the listed tools, sorted alphabetically. Tool names are restricted to the string keys of the tool set.',
|
|
126
|
+
},
|
|
120
127
|
{
|
|
121
128
|
name: 'output',
|
|
122
129
|
type: 'OutputSpecification',
|
|
@@ -131,6 +138,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
131
138
|
description:
|
|
132
139
|
"Default function to repair tool calls that fail to parse. Mark the function with 'use step' when used in a workflow. Per-stream values override this default.",
|
|
133
140
|
},
|
|
141
|
+
{
|
|
142
|
+
name: 'experimental_refineToolInput',
|
|
143
|
+
type: 'ToolInputRefinement<TTools>',
|
|
144
|
+
isOptional: true,
|
|
145
|
+
description:
|
|
146
|
+
'Optional mapping of tool names to functions that refine parsed tool inputs. Each function receives the typed input for its tool and must return the same input type shape. The refined input is used for tool execution, output parts, lifecycle callbacks, and telemetry in both `generate()` and `stream()`. Per-stream values override this default.',
|
|
147
|
+
},
|
|
134
148
|
{
|
|
135
149
|
name: 'experimental_download',
|
|
136
150
|
type: 'DownloadFunction',
|
|
@@ -145,6 +159,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
145
159
|
description:
|
|
146
160
|
'Default sandbox session passed to tool descriptions and execution as `experimental_sandbox`, and exposed to `prepareStep`. Per-stream values override this default.',
|
|
147
161
|
},
|
|
162
|
+
{
|
|
163
|
+
name: 'toolApproval',
|
|
164
|
+
type: 'ToolApprovalConfiguration<TTools, TRuntimeContext>',
|
|
165
|
+
isOptional: true,
|
|
166
|
+
description:
|
|
167
|
+
"Default approval configuration for tool calls. Pass a `GenericToolApprovalFunction` to handle all tool calls in one callback with `toolCall`, `tools`, `toolsContext`, `messages`, and `runtimeContext`, or pass a per-tool object where each key can be a status (`'not-applicable'`, `'approved'`, `'denied'`, or `'user-approval'`), an object form such as `{ type: 'denied', reason: 'blocked by policy' }`, or a `SingleToolApprovalFunction` that receives the tool input and options `toolCallId`, `messages`, `toolContext`, and `runtimeContext`. This setting takes precedence over a tool's `needsApproval` default. The functions in the configuration run in workflow context, outside of the durable model steps, and are never passed across a step boundary. Per-stream values override this default.",
|
|
168
|
+
},
|
|
148
169
|
{
|
|
149
170
|
name: 'experimental_toolApprovalSecret',
|
|
150
171
|
type: 'WorkflowToolApprovalSecret',
|
|
@@ -628,6 +649,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
|
|
|
628
649
|
isOptional: true,
|
|
629
650
|
description: 'Limits the subset of tools available for this call without changing tool call and result types.',
|
|
630
651
|
},
|
|
652
|
+
{
|
|
653
|
+
name: 'toolOrder',
|
|
654
|
+
type: 'ToolOrder<TTools>',
|
|
655
|
+
isOptional: true,
|
|
656
|
+
description:
|
|
657
|
+
'Controls the order in which tools are sent to the provider. The list can be partial. Tools not listed in `toolOrder` are sent after the listed tools, sorted alphabetically. Tool names are restricted to the string keys of the tool set.',
|
|
658
|
+
},
|
|
631
659
|
{
|
|
632
660
|
name: 'output',
|
|
633
661
|
type: 'OutputSpecification',
|
|
@@ -637,9 +665,9 @@ In addition to the options in the table, `stream()` accepts the generation setti
|
|
|
637
665
|
},
|
|
638
666
|
{
|
|
639
667
|
name: 'timeout',
|
|
640
|
-
type: '
|
|
668
|
+
type: 'WorkflowAgentTimeoutConfiguration',
|
|
641
669
|
isOptional: true,
|
|
642
|
-
description: '
|
|
670
|
+
description: 'Timeout for model calls. A number, or `totalMs` in the object form, is one deadline in milliseconds for the whole run. Inside a workflow, the absolute deadline is checked at dispatch and retry and remains in effect across suspension. `stepMs` limits each model call. `firstChunkMs` limits the wait for the first output of each model call, and `chunkMs` limits the wait between two outputs. A timeout does not cancel a tool waiting on a Workflow hook; use run.cancel() to stop the suspended run.',
|
|
643
671
|
},
|
|
644
672
|
{
|
|
645
673
|
name: 'sendFinish',
|
|
@@ -665,6 +693,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
|
|
|
665
693
|
isOptional: true,
|
|
666
694
|
description: "Callback to attempt automatic recovery when a tool call cannot be parsed. Mark the function with 'use step' when used in a workflow.",
|
|
667
695
|
},
|
|
696
|
+
{
|
|
697
|
+
name: 'experimental_refineToolInput',
|
|
698
|
+
type: 'ToolInputRefinement<TTools>',
|
|
699
|
+
isOptional: true,
|
|
700
|
+
description:
|
|
701
|
+
'Optional mapping of tool names to functions that refine parsed tool inputs. Each function receives the typed input for its tool and must return the same input type shape. The refined input is used for tool execution, output parts, lifecycle callbacks, and telemetry in both `generate()` and `stream()`. Overrides the constructor default.',
|
|
702
|
+
},
|
|
668
703
|
{
|
|
669
704
|
name: 'experimental_download',
|
|
670
705
|
type: 'DownloadFunction',
|
|
@@ -679,6 +714,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
|
|
|
679
714
|
description:
|
|
680
715
|
'Sandbox session passed to tool descriptions and execution as `experimental_sandbox`, and exposed to `prepareStep`. Overrides the constructor default.',
|
|
681
716
|
},
|
|
717
|
+
{
|
|
718
|
+
name: 'toolApproval',
|
|
719
|
+
type: 'ToolApprovalConfiguration<TTools, TRuntimeContext>',
|
|
720
|
+
isOptional: true,
|
|
721
|
+
description:
|
|
722
|
+
"Approval configuration for tool calls. Pass a `GenericToolApprovalFunction` to handle all tool calls in one callback with `toolCall`, `tools`, `toolsContext`, `messages`, and `runtimeContext`, or pass a per-tool object where each key can be a status (`'not-applicable'`, `'approved'`, `'denied'`, or `'user-approval'`), an object form such as `{ type: 'denied', reason: 'blocked by policy' }`, or a `SingleToolApprovalFunction` that receives the tool input and options `toolCallId`, `messages`, `toolContext`, and `runtimeContext`. This setting takes precedence over a tool's `needsApproval` default. The functions in the configuration run in workflow context, outside of the durable model steps, and are never passed across a step boundary. Overrides the constructor default.",
|
|
723
|
+
},
|
|
682
724
|
{
|
|
683
725
|
name: 'experimental_toolApprovalSecret',
|
|
684
726
|
type: 'WorkflowToolApprovalSecret',
|
|
@@ -912,6 +954,21 @@ type ActiveTools<TTools extends ToolSet> =
|
|
|
912
954
|
|
|
913
955
|
Limits a workflow agent call to the listed tool names. `undefined` means no tool restriction is applied.
|
|
914
956
|
|
|
957
|
+
### `WorkflowAgentTimeoutConfiguration`
|
|
958
|
+
|
|
959
|
+
```ts
|
|
960
|
+
type WorkflowAgentTimeoutConfiguration =
|
|
961
|
+
| number
|
|
962
|
+
| {
|
|
963
|
+
totalMs?: number;
|
|
964
|
+
stepMs?: number;
|
|
965
|
+
firstChunkMs?: number;
|
|
966
|
+
chunkMs?: number;
|
|
967
|
+
};
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
The `timeout` option of `generate()` and `stream()`. A number is the total deadline in milliseconds. `generate()` uses `totalMs` and `stepMs`. `stream()` uses all four values. See [Deadlines, cancellation, and replay](/docs/agents/workflow-agent#deadlines-cancellation-and-replay).
|
|
971
|
+
|
|
915
972
|
### `InferWorkflowAgentUIMessage`
|
|
916
973
|
|
|
917
974
|
Infers the UI message type for a `WorkflowAgent` instance. Optionally accepts a second type argument for custom message metadata.
|
|
@@ -1079,9 +1136,9 @@ console.log(result.output);
|
|
|
1079
1136
|
|
|
1080
1137
|
### Agent with Tool Approval
|
|
1081
1138
|
|
|
1082
|
-
|
|
1083
|
-
`
|
|
1084
|
-
`
|
|
1139
|
+
Tool approval is configured on the tool definition with `needsApproval` or on
|
|
1140
|
+
the agent with `toolApproval`. The `toolApproval` configuration takes precedence
|
|
1141
|
+
over `needsApproval`.
|
|
1085
1142
|
|
|
1086
1143
|
```ts
|
|
1087
1144
|
import { WorkflowAgent } from '@ai-sdk/workflow';
|
|
@@ -28,3 +28,6 @@ if (NoSuchModelError.isInstance(error)) {
|
|
|
28
28
|
Experimental decision resolution uses `modelType: 'decisionModel'`. This
|
|
29
29
|
includes unavailable decision capabilities and unknown decision model or
|
|
30
30
|
provider IDs. See [Decisions](/docs/ai-sdk-core/decisions#default-provider-strings).
|
|
31
|
+
|
|
32
|
+
Experimental extraction resolution uses `modelType: 'extractionModel'`. See
|
|
33
|
+
[Extractions](/docs/ai-sdk-core/extractions#model-aliases-and-registries).
|
|
@@ -30,3 +30,6 @@ if (NoSuchProviderError.isInstance(error)) {
|
|
|
30
30
|
Experimental decision resolution uses `modelType: 'decisionModel'`. This
|
|
31
31
|
includes unavailable decision capabilities and unknown decision model or
|
|
32
32
|
provider IDs. See [Decisions](/docs/ai-sdk-core/decisions#default-provider-strings).
|
|
33
|
+
|
|
34
|
+
Experimental extraction resolution uses `modelType: 'extractionModel'`. See
|
|
35
|
+
[Extractions](/docs/ai-sdk-core/extractions#model-aliases-and-registries).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.174",
|
|
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",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/gateway": "4.0.
|
|
46
|
-
"@ai-sdk/provider": "4.0.
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
45
|
+
"@ai-sdk/gateway": "4.0.147",
|
|
46
|
+
"@ai-sdk/provider": "4.0.39",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.82"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@ai-sdk/amazon-bedrock": "5.0.
|
|
51
|
-
"@ai-sdk/deepseek": "3.0.
|
|
52
|
-
"@ai-sdk/google": "4.0.
|
|
53
|
-
"@ai-sdk/groq": "4.0.
|
|
54
|
-
"@ai-sdk/huggingface": "2.0.
|
|
55
|
-
"@ai-sdk/moonshotai": "3.0.
|
|
56
|
-
"@ai-sdk/openai": "4.0.
|
|
50
|
+
"@ai-sdk/amazon-bedrock": "5.0.143",
|
|
51
|
+
"@ai-sdk/deepseek": "3.0.88",
|
|
52
|
+
"@ai-sdk/google": "4.0.122",
|
|
53
|
+
"@ai-sdk/groq": "4.0.85",
|
|
54
|
+
"@ai-sdk/huggingface": "2.0.94",
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.94",
|
|
56
|
+
"@ai-sdk/openai": "4.0.119",
|
|
57
57
|
"@ai-sdk/test-server": "2.0.4",
|
|
58
|
-
"@ai-sdk/xai": "5.0.
|
|
58
|
+
"@ai-sdk/xai": "5.0.47",
|
|
59
59
|
"@edge-runtime/vm": "^5.0.0",
|
|
60
60
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
61
61
|
"@smithy/util-utf8": "^4.3.3",
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import { logWarnings } from '../logger/log-warnings';
|
|
2
2
|
import type { StopCondition } from '../generate-text/stop-condition';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Logs the warning for the default stopWhen condition.
|
|
6
|
+
*/
|
|
7
|
+
export function logDefaultStopConditionWarning({
|
|
8
|
+
stepCount,
|
|
9
|
+
provider,
|
|
10
|
+
modelId,
|
|
11
|
+
}: {
|
|
12
|
+
stepCount: number;
|
|
13
|
+
provider: string;
|
|
14
|
+
modelId: string;
|
|
15
|
+
}): void {
|
|
16
|
+
logWarnings({
|
|
17
|
+
provider,
|
|
18
|
+
model: modelId,
|
|
19
|
+
warnings: [
|
|
20
|
+
{
|
|
21
|
+
type: 'other',
|
|
22
|
+
message:
|
|
23
|
+
`The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). ` +
|
|
24
|
+
'To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. ' +
|
|
25
|
+
'Learn more: https://ai-sdk.dev/docs/agents/loop-control',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
4
31
|
/**
|
|
5
32
|
* Stop conditions are only evaluated when the tool loop can otherwise continue,
|
|
6
33
|
* so logging here avoids warning when a call finishes naturally at the limit.
|
|
@@ -14,19 +41,7 @@ export function createDefaultStopCondition(
|
|
|
14
41
|
}
|
|
15
42
|
|
|
16
43
|
const { provider, modelId } = steps[steps.length - 1].model;
|
|
17
|
-
|
|
18
|
-
provider,
|
|
19
|
-
model: modelId,
|
|
20
|
-
warnings: [
|
|
21
|
-
{
|
|
22
|
-
type: 'other',
|
|
23
|
-
message:
|
|
24
|
-
`The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). ` +
|
|
25
|
-
'To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. ' +
|
|
26
|
-
'Learn more: https://ai-sdk.dev/docs/agents/loop-control',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
});
|
|
44
|
+
logDefaultStopConditionWarning({ stepCount, provider, modelId });
|
|
30
45
|
|
|
31
46
|
return true;
|
|
32
47
|
};
|
package/src/batch/batch-types.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
ToolSet,
|
|
14
14
|
} from '@ai-sdk/provider-utils';
|
|
15
15
|
import type { ContentPart } from '../generate-text/content-part';
|
|
16
|
+
import type { Output } from '../generate-text/output';
|
|
17
|
+
import type { InferCompleteOutput } from '../generate-text/output-utils';
|
|
16
18
|
import type { ToolOrder } from '../generate-text/tool-order';
|
|
17
19
|
import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
|
|
18
20
|
import type { Prompt } from '../prompt/prompt';
|
|
@@ -125,6 +127,16 @@ export type StartBatchOptions<
|
|
|
125
127
|
|
|
126
128
|
providerOptions?: ProviderOptions;
|
|
127
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Specification for structured data in the text responses. Its response
|
|
132
|
+
* format is sent with every text request in the batch; image requests
|
|
133
|
+
* ignore it.
|
|
134
|
+
*
|
|
135
|
+
* Pass the same specification to `getBatchResults` as `output` to parse and
|
|
136
|
+
* validate each result.
|
|
137
|
+
*/
|
|
138
|
+
output?: Output;
|
|
139
|
+
|
|
128
140
|
/**
|
|
129
141
|
* URL that the provider should notify when the batch reaches a terminal
|
|
130
142
|
* state. Providers that do not support completion webhooks return an
|
|
@@ -193,16 +205,26 @@ export type GetBatchStatusOptions = {
|
|
|
193
205
|
/**
|
|
194
206
|
* Options for retrieving batch results.
|
|
195
207
|
*/
|
|
196
|
-
export type GetBatchResultsOptions<
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
export type GetBatchResultsOptions<
|
|
209
|
+
TOOLS extends ToolSet = ToolSet,
|
|
210
|
+
OUTPUT extends Output | undefined = undefined,
|
|
211
|
+
> = GetBatchStatusOptions & {
|
|
212
|
+
/**
|
|
213
|
+
* Definitions for client tools that were provided to `startBatch` requests.
|
|
214
|
+
*
|
|
215
|
+
* The definitions are used only to validate and normalize returned tool
|
|
216
|
+
* calls. Their `execute` functions are never invoked.
|
|
217
|
+
*/
|
|
218
|
+
tools?: TOOLS;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The output specification that was provided to `startBatch` requests.
|
|
222
|
+
*
|
|
223
|
+
* When provided, the text of each successful item is parsed and validated
|
|
224
|
+
* with it. The item then has either `output` or `outputError`.
|
|
225
|
+
*/
|
|
226
|
+
output?: OUTPUT;
|
|
227
|
+
};
|
|
206
228
|
|
|
207
229
|
/**
|
|
208
230
|
* A normalized result for a successful text batch item.
|
|
@@ -222,16 +244,45 @@ export type TextBatchGenerationResult<TOOLS extends ToolSet = ToolSet> = {
|
|
|
222
244
|
readonly providerMetadata?: ProviderMetadata;
|
|
223
245
|
};
|
|
224
246
|
|
|
247
|
+
/**
|
|
248
|
+
* The parsed output of a successful text batch item, or the reason it could
|
|
249
|
+
* not be produced. Only present when `output` is passed to `getBatchResults`.
|
|
250
|
+
*
|
|
251
|
+
* A parsing failure does not fail the item: `text`, `usage` and the other
|
|
252
|
+
* generation results remain available.
|
|
253
|
+
*/
|
|
254
|
+
export type TextBatchOutputResult<OUTPUT extends Output | undefined> =
|
|
255
|
+
OUTPUT extends Output
|
|
256
|
+
?
|
|
257
|
+
| {
|
|
258
|
+
readonly output: InferCompleteOutput<OUTPUT>;
|
|
259
|
+
readonly outputError?: undefined;
|
|
260
|
+
}
|
|
261
|
+
| {
|
|
262
|
+
readonly output?: undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Why no output is available, e.g. the text was not valid JSON,
|
|
265
|
+
* did not match the schema, or the item did not finish with a
|
|
266
|
+
* complete response.
|
|
267
|
+
*/
|
|
268
|
+
readonly outputError: BatchError;
|
|
269
|
+
}
|
|
270
|
+
: unknown;
|
|
271
|
+
|
|
225
272
|
/**
|
|
226
273
|
* A complete terminal result for one request in a text batch.
|
|
227
274
|
*/
|
|
228
|
-
export type TextBatchItemResult<
|
|
275
|
+
export type TextBatchItemResult<
|
|
276
|
+
TOOLS extends ToolSet = ToolSet,
|
|
277
|
+
OUTPUT extends Output | undefined = undefined,
|
|
278
|
+
> = {
|
|
229
279
|
readonly type: 'text';
|
|
230
280
|
} & (
|
|
231
|
-
| (TextBatchGenerationResult<TOOLS> &
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
281
|
+
| (TextBatchGenerationResult<TOOLS> &
|
|
282
|
+
TextBatchOutputResult<OUTPUT> & {
|
|
283
|
+
readonly id: string;
|
|
284
|
+
readonly status: 'succeeded';
|
|
285
|
+
})
|
|
235
286
|
| {
|
|
236
287
|
readonly id: string;
|
|
237
288
|
readonly status: 'failed';
|
|
@@ -282,6 +333,7 @@ export type ImageBatchItemResult = { readonly type: 'image' } & (
|
|
|
282
333
|
/**
|
|
283
334
|
* A complete terminal result for one request in a batch.
|
|
284
335
|
*/
|
|
285
|
-
export type BatchItemResult<
|
|
286
|
-
|
|
287
|
-
|
|
|
336
|
+
export type BatchItemResult<
|
|
337
|
+
TOOLS extends ToolSet = ToolSet,
|
|
338
|
+
OUTPUT extends Output | undefined = undefined,
|
|
339
|
+
> = TextBatchItemResult<TOOLS, OUTPUT> | ImageBatchItemResult;
|