ai 7.0.127 → 7.0.128
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 +18 -0
- package/dist/index.d.ts +213 -153
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +239 -178
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +278 -68
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +340 -61
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +80 -12
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +49 -49
- package/docs/03-ai-sdk-core/35-image-generation.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +12 -12
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +2 -122
- package/src/global.ts +1 -1
- package/src/index.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/resolve-model.ts +45 -14
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/transcribe.ts +1 -1
- package/src/ui/chat.ts +9 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
|
@@ -368,11 +368,24 @@ Returns a Promise that resolves to an `MCPClient` with the following properties
|
|
|
368
368
|
'Tool definitions, typically returned by `listTools`.',
|
|
369
369
|
},
|
|
370
370
|
{
|
|
371
|
-
name: '
|
|
372
|
-
type: 'TOOL_SCHEMAS',
|
|
371
|
+
name: 'options',
|
|
372
|
+
type: '{ schemas?: TOOL_SCHEMAS }',
|
|
373
373
|
isOptional: true,
|
|
374
|
-
description:
|
|
375
|
-
|
|
374
|
+
description: 'Options for converting the tool definitions.',
|
|
375
|
+
properties: [
|
|
376
|
+
{
|
|
377
|
+
type: 'options',
|
|
378
|
+
parameters: [
|
|
379
|
+
{
|
|
380
|
+
name: 'schemas',
|
|
381
|
+
type: 'TOOL_SCHEMAS',
|
|
382
|
+
isOptional: true,
|
|
383
|
+
description:
|
|
384
|
+
'Optional schema definitions for compile-time type checking and typed outputs.',
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
},
|
|
388
|
+
],
|
|
376
389
|
},
|
|
377
390
|
],
|
|
378
391
|
},
|
|
@@ -641,6 +654,47 @@ The client throws `MCPClientError` for:
|
|
|
641
654
|
- Missing server capabilities
|
|
642
655
|
- Connection failures
|
|
643
656
|
|
|
657
|
+
Import `MCPClientError` from `@ai-sdk/mcp` and use its `isInstance` method to
|
|
658
|
+
safely narrow unknown errors:
|
|
659
|
+
|
|
660
|
+
```typescript
|
|
661
|
+
import { createMCPClient, MCPClientError } from '@ai-sdk/mcp';
|
|
662
|
+
|
|
663
|
+
try {
|
|
664
|
+
await createMCPClient({
|
|
665
|
+
transport: {
|
|
666
|
+
type: 'http',
|
|
667
|
+
url: 'https://your-server.com/mcp',
|
|
668
|
+
},
|
|
669
|
+
});
|
|
670
|
+
} catch (error) {
|
|
671
|
+
if (MCPClientError.isInstance(error)) {
|
|
672
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
673
|
+
// Authentication or authorization must be fixed before retrying.
|
|
674
|
+
throw error;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// Inspect error.code and error.statusCode according to your application's policy.
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
throw error;
|
|
681
|
+
}
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
The error exposes the optional `code`, `statusCode`, `url`, and `responseBody`
|
|
685
|
+
properties. `code` is the JSON-RPC application error code. `statusCode`, `url`,
|
|
686
|
+
and `responseBody` contain HTTP transport context when it is available. They
|
|
687
|
+
are `undefined` for failures without an HTTP response, such as network errors,
|
|
688
|
+
timeouts, aborted requests, and stdio transport failures.
|
|
689
|
+
|
|
690
|
+
`MCPClientError` also represents configuration and protocol errors, so its
|
|
691
|
+
type or a missing `statusCode` alone does not indicate a retryable failure.
|
|
692
|
+
OAuth failures can instead throw the separately exported `UnauthorizedError`
|
|
693
|
+
or `MCPClientOAuthError`.
|
|
694
|
+
|
|
695
|
+
Avoid logging `url` or `responseBody` without redacting sensitive endpoint,
|
|
696
|
+
query parameter, or server response data.
|
|
697
|
+
|
|
644
698
|
For tool execution, errors are propagated as `CallToolError` errors.
|
|
645
699
|
|
|
646
700
|
For unknown errors, the client exposes an `onUncaughtError` callback that can be used to manually log or handle errors that are not covered by known error types.
|
|
@@ -299,20 +299,20 @@ The `createProviderRegistry` function returns a `Provider` instance. It has the
|
|
|
299
299
|
]}
|
|
300
300
|
/>
|
|
301
301
|
|
|
302
|
-
## Experimental
|
|
302
|
+
## Experimental decision models
|
|
303
303
|
|
|
304
|
-
The inferred return type also exposes `
|
|
305
|
-
returning `
|
|
306
|
-
`
|
|
304
|
+
The inferred return type also exposes `decisionModel('providerId:modelId')`,
|
|
305
|
+
returning `Experimental_DecisionModelV4`. The provider must expose an
|
|
306
|
+
`decisionModel` factory. Custom separators and model ID
|
|
307
307
|
inference work as they do for video models. Language and image middleware do not
|
|
308
|
-
wrap
|
|
309
|
-
use the inferred return type or `
|
|
310
|
-
retain experimental
|
|
308
|
+
wrap decision models. `ProviderRegistryProvider` remains a stable interface;
|
|
309
|
+
use the inferred return type or `Experimental_DecisionProviderRegistry` to
|
|
310
|
+
retain experimental decision access.
|
|
311
311
|
|
|
312
|
-
Unavailable
|
|
313
|
-
`modelType: '
|
|
312
|
+
Unavailable decision capabilities or models throw `NoSuchModelError` with
|
|
313
|
+
`modelType: 'decisionModel'`; unknown registry providers throw
|
|
314
314
|
`NoSuchProviderError`. These capabilities are structural extensions and are not
|
|
315
|
-
added to the stable `ProviderV4` contract. Direct
|
|
315
|
+
added to the stable `ProviderV4` contract. Direct decision string IDs default
|
|
316
316
|
to Gateway when no default provider is configured.
|
|
317
|
-
See [
|
|
317
|
+
See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
|
|
318
318
|
for runnable usage patterns.
|
|
@@ -202,20 +202,20 @@ The `customProvider` function returns a `Provider` instance. It has the followin
|
|
|
202
202
|
]}
|
|
203
203
|
/>
|
|
204
204
|
|
|
205
|
-
## Experimental
|
|
205
|
+
## Experimental decision models
|
|
206
206
|
|
|
207
|
-
Pass `
|
|
208
|
-
aliases for
|
|
209
|
-
`
|
|
207
|
+
Pass `decisionModels: Record<string, Experimental_DecisionModel>` to define
|
|
208
|
+
aliases for decision model instances or string IDs. The returned provider adds
|
|
209
|
+
`decisionModel(alias): Experimental_DecisionModelV4`. String aliases resolve
|
|
210
210
|
through Gateway by default, or an explicitly configured default provider with
|
|
211
|
-
|
|
211
|
+
a `decisionModel` method. Unknown aliases use the fallback provider's decision
|
|
212
212
|
factory when available; model failures and unsupported questions do not trigger
|
|
213
213
|
substitution.
|
|
214
214
|
|
|
215
|
-
Unavailable
|
|
216
|
-
`modelType: '
|
|
215
|
+
Unavailable decision capabilities or models throw `NoSuchModelError` with
|
|
216
|
+
`modelType: 'decisionModel'`; unknown registry providers throw
|
|
217
217
|
`NoSuchProviderError`. These capabilities are structural extensions and are not
|
|
218
|
-
added to the stable `ProviderV4` contract. Direct
|
|
218
|
+
added to the stable `ProviderV4` contract. Direct decision string IDs default
|
|
219
219
|
to Gateway when no default provider is configured.
|
|
220
|
-
See [
|
|
220
|
+
See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
|
|
221
221
|
for runnable usage patterns.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: extractReasoningMiddleware
|
|
3
|
-
description: Middleware that extracts
|
|
3
|
+
description: Middleware that extracts reasoning sections from generated text using configurable delimiters
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# `extractReasoningMiddleware()`
|
|
7
7
|
|
|
8
|
-
`extractReasoningMiddleware` is a middleware function that extracts
|
|
8
|
+
`extractReasoningMiddleware` is a middleware function that extracts delimited reasoning sections from generated text and exposes them separately from the main text content. This is particularly useful when you want to separate an AI model's reasoning process from its final output.
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
11
|
import { extractReasoningMiddleware } from 'ai';
|
|
@@ -16,6 +16,22 @@ const middleware = extractReasoningMiddleware({
|
|
|
16
16
|
});
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
For models that emit non-XML delimiters, pass literal `opening` and `closing`
|
|
20
|
+
strings. For example, Gemma 4's raw thought-channel output uses a newline in its
|
|
21
|
+
opening delimiter:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const middleware = extractReasoningMiddleware({
|
|
25
|
+
tagName: { opening: '<|channel>thought\n', closing: '<channel|>' },
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Custom delimiters must be non-empty. They are matched literally, including
|
|
30
|
+
characters such as `|`, and can span multiple streaming chunks. Empty reasoning
|
|
31
|
+
blocks are removed from the answer text as well. Use this middleware when the
|
|
32
|
+
server returns these markers in text; providers that already return reasoning
|
|
33
|
+
separately do not need it.
|
|
34
|
+
|
|
19
35
|
## Import
|
|
20
36
|
|
|
21
37
|
<Snippet
|
|
@@ -31,10 +47,10 @@ const middleware = extractReasoningMiddleware({
|
|
|
31
47
|
content={[
|
|
32
48
|
{
|
|
33
49
|
name: 'tagName',
|
|
34
|
-
type: 'string',
|
|
50
|
+
type: 'string | { opening: string; closing: string }',
|
|
35
51
|
isOptional: false,
|
|
36
52
|
description:
|
|
37
|
-
'
|
|
53
|
+
'An XML tag name without angle brackets (e.g. "think" for <think> / </think>), or an object containing non-empty literal opening and closing delimiters.',
|
|
38
54
|
},
|
|
39
55
|
{
|
|
40
56
|
name: 'separator',
|
|
@@ -48,7 +64,7 @@ const middleware = extractReasoningMiddleware({
|
|
|
48
64
|
type: 'boolean',
|
|
49
65
|
isOptional: true,
|
|
50
66
|
description:
|
|
51
|
-
'Starts with reasoning tokens. Set to true when the response always starts with reasoning and the
|
|
67
|
+
'Starts with reasoning tokens. Set to true when the response always starts with reasoning and the opening delimiter is omitted. Defaults to false.',
|
|
52
68
|
},
|
|
53
69
|
]}
|
|
54
70
|
/>
|
|
@@ -58,9 +74,9 @@ const middleware = extractReasoningMiddleware({
|
|
|
58
74
|
Returns a middleware object that:
|
|
59
75
|
|
|
60
76
|
- Processes both streaming and non-streaming responses
|
|
61
|
-
- Extracts content between specified
|
|
62
|
-
- Removes the
|
|
63
|
-
-
|
|
77
|
+
- Extracts content between the specified delimiters as reasoning
|
|
78
|
+
- Removes the delimiters and reasoning from the main text
|
|
79
|
+
- Emits reasoning content parts separately from text content parts
|
|
64
80
|
- Maintains proper separation between text sections using the specified separator
|
|
65
81
|
|
|
66
82
|
### Type Parameters
|
|
@@ -60,7 +60,7 @@ export async function POST(req: Request) {
|
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
name: 'toolCalls',
|
|
63
|
-
type: `'all' | 'before-last-message' |
|
|
63
|
+
type: `'all' | 'before-last-message' | \`before-last-\${number}-messages\` | 'none' | Array<{ type: 'all' | 'before-last-message' | \`before-last-\${number}-messages\`; tools?: string[] }>`,
|
|
64
64
|
description:
|
|
65
65
|
'How to prune tool call/results/approval content. Can specify a strategy string or an array for per-tool fine control. Default: [] (empty array, equivalent to "none").',
|
|
66
66
|
},
|
|
@@ -99,7 +99,7 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
99
99
|
type: 'StopCondition | StopCondition[]',
|
|
100
100
|
isOptional: true,
|
|
101
101
|
description:
|
|
102
|
-
'Default stop condition for the agent loop. When omitted,
|
|
102
|
+
'Default stop condition for the agent loop. When omitted, generate defaults to 20 steps, while stream has no maximum step count. Use `isStepCount()` to bound execution. Per-call values override this default.',
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
name: 'activeTools',
|
|
@@ -478,6 +478,43 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
478
478
|
|
|
479
479
|
## Methods
|
|
480
480
|
|
|
481
|
+
### `generate()`
|
|
482
|
+
|
|
483
|
+
Runs the durable agent loop using the model's non-streaming `doGenerate()` method. Model calls and tool execution use the same orchestration as `stream()`.
|
|
484
|
+
|
|
485
|
+
```ts
|
|
486
|
+
const result = await agent.generate({ prompt: 'Summarize the findings.' });
|
|
487
|
+
console.log(result.text);
|
|
488
|
+
console.log(result.usage);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Accepts `WorkflowAgentGenerateOptions`, sharing prompt/messages, instructions, generation settings, tools and runtime context, preparation, stopping, output, and lifecycle options with `stream()`. It does not accept `writable`, `includeRawChunks`, `experimental_transform`, `sendFinish`, or `preventClose`. Without a configured stop condition, generation stops after at most 20 steps. `stream()` retains its existing unbounded default.
|
|
492
|
+
|
|
493
|
+
The `include` option accepts `requestBody`, `responseBody`, and `requestMessages` booleans, all defaulting to `false`. Enable them only when the additional request/response data is needed. Response IDs, timestamps, model IDs, headers, and provider metadata are retained when supplied by the model.
|
|
494
|
+
|
|
495
|
+
#### Returns
|
|
496
|
+
|
|
497
|
+
Returns `Promise<WorkflowAgentGenerateResult>` with the core [`GenerateTextResult`](/docs/reference/ai-sdk-core/generate-text#returns) semantics:
|
|
498
|
+
|
|
499
|
+
- `text`, `finishReason`, `rawFinishReason`, and `finalStep` describe the final step.
|
|
500
|
+
- `content`, `files`, `sources`, `warnings`, tool calls, and tool results cover all steps.
|
|
501
|
+
- `usage` and `totalUsage` sum all steps while retaining token details and unknown counts.
|
|
502
|
+
- `responseMessages` includes generated messages, even when `prepareStep` replaces the input history.
|
|
503
|
+
- `output` defaults to text, or follows the constructor/per-call output specification. Reading it throws `NoOutputGeneratedError` when output is unavailable, such as a final `tool-calls` response.
|
|
504
|
+
|
|
505
|
+
Inside a workflow, `timeout` bounds model calls, including retries and dispatch after suspension. It does not cancel a hook that a tool is waiting on. Use the Workflow runtime’s `run.cancel()` to stop a suspended run. See [deadlines, cancellation, and replay](/docs/agents/workflow-agent#deadlines-cancellation-and-replay).
|
|
506
|
+
|
|
507
|
+
Generation failures reject. The end callback runs before complete-output parsing; a parsing failure can therefore reject after `onEnd` has run. Existing Workflow callback shapes and preparation precedence apply; they are not all identical to core's callback APIs.
|
|
508
|
+
|
|
509
|
+
<Note>
|
|
510
|
+
Use the result API inside workflow code and return selected serializable
|
|
511
|
+
fields (for example, `text` and `usage`) through `run.returnValue`. Returning
|
|
512
|
+
the whole result class is not supported. Performance data currently measures
|
|
513
|
+
the model response; complete tool/step timing is not yet reported.
|
|
514
|
+
</Note>
|
|
515
|
+
|
|
516
|
+
Approval requests appear in `content` and `responseMessages` without requiring a writable. To continue, append `responseMessages` to the original history and add a tool message containing the user's `tool-approval-response`. Preserve the request signature and tool-call input; use the same `experimental_toolApprovalSecret` environment-variable reference on continuation. Local approvals are validated before execution, and provider-executed approval responses are forwarded to the provider. See [approval round trips](/docs/agents/workflow-agent#approval-round-trips-without-streaming).
|
|
517
|
+
|
|
481
518
|
### `stream()`
|
|
482
519
|
|
|
483
520
|
Runs the agent loop, streaming responses and executing tool calls as needed. Returns a promise resolving to a `WorkflowAgentStreamResult`.
|
|
@@ -549,7 +586,7 @@ const result = await agent.stream({
|
|
|
549
586
|
name: 'timeout',
|
|
550
587
|
type: 'number',
|
|
551
588
|
isOptional: true,
|
|
552
|
-
description: '
|
|
589
|
+
description: 'Model-call deadline in milliseconds. Inside a workflow, the absolute deadline is checked at dispatch and retry and remains in effect across suspension. It does not cancel a tool waiting on a Workflow hook; use run.cancel() to stop the suspended run.',
|
|
553
590
|
},
|
|
554
591
|
{
|
|
555
592
|
name: 'sendFinish',
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI_DecisionUnsupportedQuestionTypeError
|
|
3
|
+
description: Identify a decision question type that a model does not support.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AI_DecisionUnsupportedQuestionTypeError
|
|
7
|
+
|
|
8
|
+
This experimental error identifies a question whose type is unsupported by a
|
|
9
|
+
decision model. It is exported from `ai` and `@ai-sdk/provider` as
|
|
10
|
+
`Experimental_DecisionUnsupportedQuestionTypeError`.
|
|
11
|
+
|
|
12
|
+
## Properties
|
|
13
|
+
|
|
14
|
+
- `questionId`: The ID of the unsupported question.
|
|
15
|
+
- `questionType`: The requested question type.
|
|
16
|
+
- `provider`: The provider of the decision model.
|
|
17
|
+
- `modelId`: The decision model ID.
|
|
18
|
+
- `message`: A description of the unsupported question and model. Providers can
|
|
19
|
+
supply a custom message.
|
|
20
|
+
|
|
21
|
+
## Checking for this Error
|
|
22
|
+
|
|
23
|
+
Use the marker-based `isInstance` check, which works across package copies:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Experimental_DecisionUnsupportedQuestionTypeError as DecisionUnsupportedQuestionTypeError } from 'ai';
|
|
27
|
+
|
|
28
|
+
if (DecisionUnsupportedQuestionTypeError.isInstance(error)) {
|
|
29
|
+
console.log(error.questionId, error.questionType, error.modelId);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
@@ -25,6 +25,6 @@ if (NoSuchModelError.isInstance(error)) {
|
|
|
25
25
|
}
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Experimental
|
|
29
|
-
includes unavailable
|
|
30
|
-
provider IDs. See [
|
|
28
|
+
Experimental decision resolution uses `modelType: 'decisionModel'`. This
|
|
29
|
+
includes unavailable decision capabilities and unknown decision model or
|
|
30
|
+
provider IDs. See [Decisions](/docs/ai-sdk-core/decisions#default-provider-strings).
|
|
@@ -27,6 +27,6 @@ if (NoSuchProviderError.isInstance(error)) {
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Experimental
|
|
31
|
-
includes unavailable
|
|
32
|
-
provider IDs. See [
|
|
30
|
+
Experimental decision resolution uses `modelType: 'decisionModel'`. This
|
|
31
|
+
includes unavailable decision capabilities and unknown decision model or
|
|
32
|
+
provider IDs. See [Decisions](/docs/ai-sdk-core/decisions#default-provider-strings).
|
|
@@ -1385,7 +1385,7 @@ if (isToolUIPart(part)) {
|
|
|
1385
1385
|
|
|
1386
1386
|
The deprecated tool result content part of `{ type: 'media' }` has been removed in AI SDK 7.
|
|
1387
1387
|
|
|
1388
|
-
Use `{ type: 'file
|
|
1388
|
+
Use `{ type: 'file', mediaType, data: { type: 'data', data } }` for inline tool-result file content, including images, as described below. The legacy `file-data` variant still works through runtime auto-migration, but is deprecated.
|
|
1389
1389
|
|
|
1390
1390
|
#### Tool Result Content: Migrate Away From `image-*` and `file-*` variants to `file`
|
|
1391
1391
|
|
|
@@ -944,7 +944,7 @@ import { useAssistant } from '@ai-sdk/react';
|
|
|
944
944
|
code manually.
|
|
945
945
|
</Note>
|
|
946
946
|
|
|
947
|
-
The `threadId` and `messageId`
|
|
947
|
+
The `threadId` and `messageId` properties have been removed from the argument passed to the `AssistantResponse` callback. The initial response options passed to `AssistantResponse` still require both IDs.
|
|
948
948
|
Please use the `threadId` and `messageId` variables from the outer scope instead.
|
|
949
949
|
|
|
950
950
|
```ts filename="AI SDK 3.4"
|
|
@@ -57,14 +57,14 @@ const { messages, sendMessage, addToolOutput } = useChat({
|
|
|
57
57
|
try {
|
|
58
58
|
const result = await getLocationData();
|
|
59
59
|
|
|
60
|
-
// Important: Don't await inside onToolCall to avoid deadlocks
|
|
60
|
+
// Important: Don't await addToolOutput inside onToolCall to avoid deadlocks
|
|
61
61
|
addToolOutput({
|
|
62
62
|
tool: 'getLocation',
|
|
63
63
|
toolCallId: toolCall.toolCallId,
|
|
64
64
|
output: result,
|
|
65
65
|
});
|
|
66
66
|
} catch (err) {
|
|
67
|
-
// Important: Don't await inside onToolCall to avoid deadlocks
|
|
67
|
+
// Important: Don't await addToolOutput inside onToolCall to avoid deadlocks
|
|
68
68
|
addToolOutput({
|
|
69
69
|
tool: 'getLocation',
|
|
70
70
|
toolCallId: toolCall.toolCallId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.128",
|
|
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.104",
|
|
46
|
+
"@ai-sdk/provider": "4.0.22",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.54"
|
|
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.106",
|
|
51
|
+
"@ai-sdk/deepseek": "3.0.59",
|
|
52
|
+
"@ai-sdk/google": "4.0.88",
|
|
53
|
+
"@ai-sdk/groq": "4.0.55",
|
|
54
|
+
"@ai-sdk/huggingface": "2.0.63",
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.63",
|
|
56
|
+
"@ai-sdk/openai": "4.0.84",
|
|
57
57
|
"@ai-sdk/test-server": "2.0.3",
|
|
58
|
-
"@ai-sdk/xai": "5.0.
|
|
58
|
+
"@ai-sdk/xai": "5.0.15",
|
|
59
59
|
"@edge-runtime/vm": "^5.0.0",
|
|
60
60
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
61
61
|
"@smithy/util-utf8": "^4.3.3",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Experimental_DecisionModelV4CallOptions as DecisionModelV4CallOptions,
|
|
3
|
+
Experimental_DecisionModelV4Result as DecisionModelV4Result,
|
|
4
|
+
} from '@ai-sdk/provider';
|
|
5
|
+
import type { Context, ProviderOptions } from '@ai-sdk/provider-utils';
|
|
6
|
+
import type { DecisionQuestion, DecisionResult } from './decision-result';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Event passed to the `onStart` callback for decision operations.
|
|
10
|
+
*
|
|
11
|
+
* Called when the operation begins, before the decision model is called.
|
|
12
|
+
*/
|
|
13
|
+
export type DecideStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
14
|
+
/** User-defined runtime context. */
|
|
15
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
16
|
+
|
|
17
|
+
/** Unique identifier for this decision call, used to correlate events. */
|
|
18
|
+
readonly callId: string;
|
|
19
|
+
|
|
20
|
+
/** Identifies the operation type (`ai.decide`). */
|
|
21
|
+
readonly operationId: 'ai.decide';
|
|
22
|
+
|
|
23
|
+
/** The provider identifier. */
|
|
24
|
+
readonly provider: string;
|
|
25
|
+
|
|
26
|
+
/** The decision model identifier. */
|
|
27
|
+
readonly modelId: string;
|
|
28
|
+
|
|
29
|
+
/** The shared state used to make decisions. */
|
|
30
|
+
readonly state: DecisionModelV4CallOptions['state'];
|
|
31
|
+
|
|
32
|
+
/** The questions to decide against the shared state. */
|
|
33
|
+
readonly questions: Readonly<Record<string, DecisionQuestion>>;
|
|
34
|
+
|
|
35
|
+
/** Maximum number of retries for the decision model call. */
|
|
36
|
+
readonly maxRetries: number;
|
|
37
|
+
|
|
38
|
+
/** Additional HTTP headers sent with the request. */
|
|
39
|
+
readonly headers: Record<string, string> | undefined;
|
|
40
|
+
|
|
41
|
+
/** Additional provider-specific options. */
|
|
42
|
+
readonly providerOptions: ProviderOptions;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Event passed to the `onEnd` callback for decision operations.
|
|
47
|
+
*
|
|
48
|
+
* Called when the operation completes successfully.
|
|
49
|
+
*/
|
|
50
|
+
export type DecideEndEvent<RUNTIME_CONTEXT extends Context = Context> =
|
|
51
|
+
DecideStartEvent<RUNTIME_CONTEXT> & {
|
|
52
|
+
/** Exactly one typed answer per question ID. */
|
|
53
|
+
readonly answers: DecisionResult<
|
|
54
|
+
Record<string, DecisionQuestion>
|
|
55
|
+
>['answers'];
|
|
56
|
+
|
|
57
|
+
/** Token usage for the decision operation. */
|
|
58
|
+
readonly usage: DecisionResult<Record<string, DecisionQuestion>>['usage'];
|
|
59
|
+
|
|
60
|
+
/** Warnings from the decision model. */
|
|
61
|
+
readonly warnings: DecisionResult<
|
|
62
|
+
Record<string, DecisionQuestion>
|
|
63
|
+
>['warnings'];
|
|
64
|
+
|
|
65
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
66
|
+
readonly rounding: DecisionResult<
|
|
67
|
+
Record<string, DecisionQuestion>
|
|
68
|
+
>['rounding'];
|
|
69
|
+
|
|
70
|
+
/** Optional provider-specific metadata. */
|
|
71
|
+
readonly providerMetadata: DecisionResult<
|
|
72
|
+
Record<string, DecisionQuestion>
|
|
73
|
+
>['providerMetadata'];
|
|
74
|
+
|
|
75
|
+
/** Response metadata, including the resolved model ID and timestamp. */
|
|
76
|
+
readonly response: DecisionResult<
|
|
77
|
+
Record<string, DecisionQuestion>
|
|
78
|
+
>['response'];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Event fired when the decision model call begins.
|
|
83
|
+
*
|
|
84
|
+
* The logical model call includes any provider retries.
|
|
85
|
+
*/
|
|
86
|
+
export type DecisionModelCallStartEvent = {
|
|
87
|
+
/** Unique identifier for the outer decision call. */
|
|
88
|
+
readonly callId: string;
|
|
89
|
+
|
|
90
|
+
/** Identifies the inner operation (`ai.decide.doDecide`). */
|
|
91
|
+
readonly operationId: 'ai.decide.doDecide';
|
|
92
|
+
|
|
93
|
+
/** The provider identifier. */
|
|
94
|
+
readonly provider: string;
|
|
95
|
+
|
|
96
|
+
/** The decision model identifier. */
|
|
97
|
+
readonly modelId: string;
|
|
98
|
+
|
|
99
|
+
/** The shared state used to make decisions. */
|
|
100
|
+
readonly state: DecisionModelV4CallOptions['state'];
|
|
101
|
+
|
|
102
|
+
/** The questions to decide against the shared state. */
|
|
103
|
+
readonly questions: Readonly<Record<string, DecisionQuestion>>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Event fired after the decision model response has been validated.
|
|
108
|
+
*
|
|
109
|
+
* Contains the result of the logical model call, including any retries.
|
|
110
|
+
*/
|
|
111
|
+
export type DecisionModelCallEndEvent = DecisionModelCallStartEvent & {
|
|
112
|
+
/** Exactly one answer per question ID. */
|
|
113
|
+
readonly answers: DecisionModelV4Result['answers'];
|
|
114
|
+
|
|
115
|
+
/** Token usage reported by the decision model. */
|
|
116
|
+
readonly usage?: DecisionModelV4Result['usage'];
|
|
117
|
+
|
|
118
|
+
/** Warnings from the decision model. */
|
|
119
|
+
readonly warnings: DecisionModelV4Result['warnings'];
|
|
120
|
+
|
|
121
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
122
|
+
readonly rounding?: DecisionModelV4Result['rounding'];
|
|
123
|
+
|
|
124
|
+
/** Optional provider-specific metadata. */
|
|
125
|
+
readonly providerMetadata?: DecisionModelV4Result['providerMetadata'];
|
|
126
|
+
|
|
127
|
+
/** Optional raw response metadata from the provider. */
|
|
128
|
+
readonly response?: DecisionModelV4Result['response'];
|
|
129
|
+
};
|