ai 7.0.127 → 7.0.129
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 +53 -0
- package/dist/index.d.ts +230 -155
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -209
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +288 -70
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +407 -76
- 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-foundations/06-provider-options.mdx +11 -10
- 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/02-building-agents.mdx +16 -11
- package/docs/03-agents/07-workflow-agent.mdx +83 -15
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
- package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
- package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
- package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -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/04-ai-sdk-ui/21-error-handling.mdx +28 -3
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- 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 +15 -15
- 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-object/generate-object.ts +10 -0
- package/src/generate-object/stream-object.ts +10 -0
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-speech/index.ts +13 -1
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +5 -123
- package/src/generate-text/tool-approval-signature.ts +7 -4
- package/src/global.ts +3 -2
- package/src/index.ts +1 -1
- package/src/logger/deprecations.ts +72 -0
- package/src/logger/log-warnings.ts +25 -3
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/model/resolve-model.ts +45 -14
- package/src/prompt/convert-to-language-model-prompt.ts +7 -1
- package/src/realtime/encode-realtime-frame.ts +7 -2
- 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/index.ts +13 -1
- package/src/transcribe/transcribe.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/language-model.ts +9 -1
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +25 -9
- package/src/ui/convert-to-model-messages.ts +40 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/process-text-stream.ts +5 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/src/ui/text-stream-chat-transport.ts +3 -1
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +10 -2
- 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
|
@@ -114,7 +114,7 @@ const result = await generateText({
|
|
|
114
114
|
});
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
Not registering integrations with `registerTelemetry()` prevents delivery to globally registered integrations, but does not disable per-call integrations or Node.js tracing-channel subscribers. To disable telemetry events for a call, including tracing-channel events, pass `telemetry: { isEnabled: false }`. Apply this setting to every call if you want to opt out throughout your application.
|
|
118
118
|
|
|
119
119
|
## Telemetry Metadata
|
|
120
120
|
|
|
@@ -157,7 +157,7 @@ const result = await generateText({
|
|
|
157
157
|
});
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
In this example, telemetry integrations receive `runtimeContext` as `{ requestId: 'req_abc' }`. Properties set to `false` or omitted are excluded. If `telemetry.includeRuntimeContext` is omitted, no runtime context properties are included. `telemetry.includeRuntimeContext` is supported by `generateText`, `streamText`, `ToolLoopAgent`, `embed`, `embedMany`, `rerank`, and `
|
|
160
|
+
In this example, telemetry integrations receive `runtimeContext` as `{ requestId: 'req_abc' }`. Properties set to `false` or omitted are excluded. If `telemetry.includeRuntimeContext` is omitted, no runtime context properties are included. `telemetry.includeRuntimeContext` is supported by `generateText`, `streamText`, `ToolLoopAgent`, `embed`, `embedMany`, `rerank`, and `experimental_decide`.
|
|
161
161
|
|
|
162
162
|
<Note>
|
|
163
163
|
`telemetry.includeRuntimeContext` only filters telemetry integrations,
|
|
@@ -354,6 +354,10 @@ class MyIntegration implements Telemetry {
|
|
|
354
354
|
async onAbort(event) {
|
|
355
355
|
console.log('Stream aborted after', event.steps.length, 'finished steps');
|
|
356
356
|
}
|
|
357
|
+
|
|
358
|
+
async onError(event) {
|
|
359
|
+
console.error('Generation failed:', event.callId, event.error);
|
|
360
|
+
}
|
|
357
361
|
}
|
|
358
362
|
|
|
359
363
|
export function myIntegration(): Telemetry {
|
|
@@ -415,27 +419,26 @@ export function myIntegration(): Telemetry {
|
|
|
415
419
|
description: 'Called when an individual reranking model call completes.',
|
|
416
420
|
},
|
|
417
421
|
{
|
|
418
|
-
name: '
|
|
419
|
-
type: '(event:
|
|
420
|
-
description: 'Called when an experimental
|
|
422
|
+
name: 'experimental_onDecideStart',
|
|
423
|
+
type: '(event: Experimental_DecideStartEvent) => void | PromiseLike<void>',
|
|
424
|
+
description: 'Called when an experimental decision operation begins.',
|
|
421
425
|
},
|
|
422
426
|
{
|
|
423
|
-
name: '
|
|
424
|
-
type: '(event:
|
|
427
|
+
name: 'experimental_onDecisionModelCallStart',
|
|
428
|
+
type: '(event: Experimental_DecisionModelCallStartEvent) => void | PromiseLike<void>',
|
|
425
429
|
description:
|
|
426
|
-
'Called when the logical
|
|
430
|
+
'Called when the logical decision model call begins. The call includes any provider retries.',
|
|
427
431
|
},
|
|
428
432
|
{
|
|
429
|
-
name: '
|
|
430
|
-
type: '(event:
|
|
433
|
+
name: 'experimental_onDecisionModelCallEnd',
|
|
434
|
+
type: '(event: Experimental_DecisionModelCallEndEvent) => void | PromiseLike<void>',
|
|
431
435
|
description:
|
|
432
|
-
'Called when the logical
|
|
436
|
+
'Called when the logical decision model call, including any retries, completes.',
|
|
433
437
|
},
|
|
434
438
|
{
|
|
435
|
-
name: '
|
|
436
|
-
type: '(event:
|
|
437
|
-
description:
|
|
438
|
-
'Called when an experimental evaluation operation completes.',
|
|
439
|
+
name: 'experimental_onDecideEnd',
|
|
440
|
+
type: '(event: Experimental_DecideEndEvent) => void | PromiseLike<void>',
|
|
441
|
+
description: 'Called when an experimental decision operation completes.',
|
|
439
442
|
},
|
|
440
443
|
{
|
|
441
444
|
name: 'onEnd',
|
|
@@ -449,10 +452,16 @@ export function myIntegration(): Telemetry {
|
|
|
449
452
|
description:
|
|
450
453
|
'Called when a streaming text generation operation is aborted before it completes.',
|
|
451
454
|
},
|
|
455
|
+
{
|
|
456
|
+
name: 'onError',
|
|
457
|
+
type: '(event: { callId: string; error: unknown }) => void | PromiseLike<void>',
|
|
458
|
+
description:
|
|
459
|
+
'Called when an unrecoverable error occurs. The event identifies the operation and contains the thrown value.',
|
|
460
|
+
},
|
|
452
461
|
]}
|
|
453
462
|
/>
|
|
454
463
|
|
|
455
|
-
Experimental
|
|
464
|
+
Experimental decision events use the four `experimental_*` callbacks above.
|
|
456
465
|
They are not included in the stable `onStart` and `onEnd` event unions.
|
|
457
466
|
|
|
458
467
|
The event types for each method are the same as the corresponding [lifecycle callbacks](/docs/ai-sdk-core/lifecycle-callbacks). See the lifecycle callbacks documentation for the full property reference of each event.
|
|
@@ -598,30 +607,30 @@ corresponding input/output recording controls. Raw audio is not captured, so
|
|
|
598
607
|
transcription input and speech output do not populate message attributes with
|
|
599
608
|
audio content or placeholder audio parts.
|
|
600
609
|
|
|
601
|
-
####
|
|
610
|
+
#### experimental_decide
|
|
602
611
|
|
|
603
|
-
For `
|
|
604
|
-
kind:
|
|
605
|
-
**`
|
|
612
|
+
For `experimental_decide`, the integration records two spans with `CLIENT`
|
|
613
|
+
kind: a **`decide {modelId}`** root span for the whole operation and one
|
|
614
|
+
**`decide {modelId}`** child span for decision model work, including
|
|
606
615
|
retries. Both include the provider and requested model with
|
|
607
|
-
`gen_ai.operation.name: "
|
|
608
|
-
usage is recorded on the child span. When
|
|
616
|
+
`gen_ai.operation.name: "decide"`. Token
|
|
617
|
+
usage is recorded on the child span. When decision attributes are enabled,
|
|
609
618
|
answers are recorded on both spans so the operation span contains its output.
|
|
610
619
|
|
|
611
|
-
`
|
|
620
|
+
`decide` is an AI SDK-defined custom operation name, not a well-known
|
|
612
621
|
OpenTelemetry GenAI operation. OpenTelemetry permits custom operation names
|
|
613
622
|
when no well-known value describes the operation.
|
|
614
623
|
|
|
615
624
|
OpenTelemetry's `gen_ai.evaluation.result` event describes the result of
|
|
616
625
|
evaluating a GenAI output for quality or other characteristics. In contrast,
|
|
617
|
-
`
|
|
626
|
+
`experimental_decide` can use arbitrary JSON state for classification,
|
|
618
627
|
routing, scoring, and similar tasks. The integration therefore does not emit a
|
|
619
628
|
`gen_ai.evaluation.result` event.
|
|
620
629
|
|
|
621
|
-
|
|
622
|
-
semantic-convention attributes. Enable the `
|
|
630
|
+
Decision state, questions, and answers also do not have applicable GenAI
|
|
631
|
+
semantic-convention attributes. Enable the `experimental_decision`
|
|
623
632
|
supplemental option to record them under AI SDK-specific
|
|
624
|
-
`ai.
|
|
633
|
+
`ai.decision.*` attributes.
|
|
625
634
|
|
|
626
635
|
#### GenAI span details
|
|
627
636
|
|
|
@@ -678,10 +687,10 @@ registerTelemetry(
|
|
|
678
687
|
|
|
679
688
|
The callback runs when each span is created and receives:
|
|
680
689
|
|
|
681
|
-
- `spanType`: the type of span being created (`operation`, `step`, `languageModel`, `tool`, `embedding`, `reranking`, or `
|
|
690
|
+
- `spanType`: the type of span being created (`operation`, `step`, `languageModel`, `tool`, `embedding`, `reranking`, or `experimental_decision`).
|
|
682
691
|
- `operationId`: the AI SDK operation ID for the current call, such as `ai.generateText` or `ai.streamText`.
|
|
683
692
|
- `callId`: the unique ID for the current AI SDK call.
|
|
684
|
-
- `runtimeContext`: the telemetry-filtered runtime context for text generation, embedding, reranking, and
|
|
693
|
+
- `runtimeContext`: the telemetry-filtered runtime context for text generation, embedding, reranking, and decision spans. Text generation spans also reflect updates from `prepareStep`.
|
|
685
694
|
|
|
686
695
|
Custom attributes are merged with AI SDK attributes on the span. AI SDK-owned
|
|
687
696
|
attributes take precedence when a custom attribute uses the same key.
|
|
@@ -741,7 +750,7 @@ registerTelemetry(
|
|
|
741
750
|
providerMetadata: true,
|
|
742
751
|
embedding: true,
|
|
743
752
|
reranking: true,
|
|
744
|
-
|
|
753
|
+
experimental_decision: true,
|
|
745
754
|
runtimeContext: true,
|
|
746
755
|
headers: true,
|
|
747
756
|
toolChoice: true,
|
|
@@ -756,7 +765,7 @@ The available options are:
|
|
|
756
765
|
- `providerMetadata`: `ai.response.providerMetadata` on operation, step, and model-call spans.
|
|
757
766
|
- `embedding`: embedding inputs and outputs.
|
|
758
767
|
- `reranking`: rerank input documents and ranking output.
|
|
759
|
-
- `
|
|
768
|
+
- `experimental_decision`: experimental decision state, questions, and answers.
|
|
760
769
|
- `runtimeContext`: `ai.settings.context.*`.
|
|
761
770
|
- `headers`: `ai.request.headers.*`.
|
|
762
771
|
- `toolChoice`: `ai.prompt.toolChoice`.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Lifecycle Callbacks
|
|
3
|
-
description: Observe AI SDK lifecycle events in generateText, streamText, embed, embedMany, rerank, and
|
|
3
|
+
description: Observe AI SDK lifecycle events in generateText, streamText, embed, embedMany, rerank, and experimental_decide calls
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Lifecycle Callbacks
|
|
7
7
|
|
|
8
8
|
Event callbacks let you run your own code at important points in an AI SDK call.
|
|
9
|
-
You can attach them directly to `generateText`, `streamText`, `embed`, `embedMany`, `rerank`, and `
|
|
9
|
+
You can attach them directly to `generateText`, `streamText`, `embed`, `embedMany`, `rerank`, and `experimental_decide` calls to observe what happened, record usage, debug multi-step generations, and monitor tool execution.
|
|
10
10
|
|
|
11
11
|
They are especially useful when you want application-specific logic close to the call site:
|
|
12
12
|
|
|
@@ -452,21 +452,20 @@ const result = await generateText({
|
|
|
452
452
|
]}
|
|
453
453
|
/>
|
|
454
454
|
|
|
455
|
-
### `
|
|
455
|
+
### `experimental_decide`
|
|
456
456
|
|
|
457
457
|
<PropertiesTable
|
|
458
458
|
content={[
|
|
459
459
|
{
|
|
460
460
|
name: 'onStart',
|
|
461
|
-
type: '(event:
|
|
461
|
+
type: '(event: Experimental_DecideStartEvent) => void | Promise<void>',
|
|
462
462
|
description:
|
|
463
|
-
'Called when the
|
|
463
|
+
'Called when the decision operation begins, before the decision model is called.',
|
|
464
464
|
},
|
|
465
465
|
{
|
|
466
466
|
name: 'onEnd',
|
|
467
|
-
type: '(event:
|
|
468
|
-
description:
|
|
469
|
-
'Called when the evaluation operation completes successfully.',
|
|
467
|
+
type: '(event: Experimental_DecideEndEvent) => void | Promise<void>',
|
|
468
|
+
description: 'Called when the decision operation completes successfully.',
|
|
470
469
|
},
|
|
471
470
|
]}
|
|
472
471
|
/>
|
|
@@ -1174,10 +1173,10 @@ For `embed`, `value` is a single string. For `embedMany`, `value` is an array of
|
|
|
1174
1173
|
]}
|
|
1175
1174
|
/>
|
|
1176
1175
|
|
|
1177
|
-
###
|
|
1176
|
+
### Decision Events
|
|
1178
1177
|
|
|
1179
|
-
|
|
1180
|
-
`
|
|
1178
|
+
Decision callbacks are experimental. Their exported types are
|
|
1179
|
+
`Experimental_DecideStartEvent` and `Experimental_DecideEndEvent`.
|
|
1181
1180
|
|
|
1182
1181
|
#### onStart
|
|
1183
1182
|
|
|
@@ -1186,12 +1185,12 @@ Evaluation callbacks are experimental. Their exported types are
|
|
|
1186
1185
|
{
|
|
1187
1186
|
name: 'callId',
|
|
1188
1187
|
type: 'string',
|
|
1189
|
-
description: 'Unique identifier for this
|
|
1188
|
+
description: 'Unique identifier for this decision call.',
|
|
1190
1189
|
},
|
|
1191
1190
|
{
|
|
1192
1191
|
name: 'operationId',
|
|
1193
|
-
type: "'ai.
|
|
1194
|
-
description: '
|
|
1192
|
+
type: "'ai.decide'",
|
|
1193
|
+
description: 'Decision operation identifier.',
|
|
1195
1194
|
},
|
|
1196
1195
|
{
|
|
1197
1196
|
name: 'runtimeContext',
|
|
@@ -1201,22 +1200,22 @@ Evaluation callbacks are experimental. Their exported types are
|
|
|
1201
1200
|
{
|
|
1202
1201
|
name: 'provider',
|
|
1203
1202
|
type: 'string',
|
|
1204
|
-
description: 'Provider identifier for the
|
|
1203
|
+
description: 'Provider identifier for the decision model.',
|
|
1205
1204
|
},
|
|
1206
1205
|
{
|
|
1207
1206
|
name: 'modelId',
|
|
1208
1207
|
type: 'string',
|
|
1209
|
-
description: '
|
|
1208
|
+
description: 'Decision model identifier.',
|
|
1210
1209
|
},
|
|
1211
1210
|
{
|
|
1212
1211
|
name: 'state',
|
|
1213
1212
|
type: 'string | object | array',
|
|
1214
|
-
description: 'Shared state
|
|
1213
|
+
description: 'Shared state used to make decisions.',
|
|
1215
1214
|
},
|
|
1216
1215
|
{
|
|
1217
1216
|
name: 'questions',
|
|
1218
|
-
type: 'Readonly<Record<string,
|
|
1219
|
-
description: 'Questions
|
|
1217
|
+
type: 'Readonly<Record<string, Experimental_DecisionQuestion>>',
|
|
1218
|
+
description: 'Questions to decide against the shared state.',
|
|
1220
1219
|
},
|
|
1221
1220
|
{
|
|
1222
1221
|
name: 'maxRetries',
|
|
@@ -1244,18 +1243,18 @@ Includes every `onStart` field plus:
|
|
|
1244
1243
|
content={[
|
|
1245
1244
|
{
|
|
1246
1245
|
name: 'answers',
|
|
1247
|
-
type: 'Record<string,
|
|
1246
|
+
type: 'Record<string, Experimental_DecisionAnswer>',
|
|
1248
1247
|
description: 'Exactly one typed answer per question ID.',
|
|
1249
1248
|
},
|
|
1250
1249
|
{
|
|
1251
1250
|
name: 'usage',
|
|
1252
1251
|
type: '{ inputTokens: number | undefined; outputTokens: number | undefined; totalTokens: number | undefined }',
|
|
1253
|
-
description: 'Token usage for the
|
|
1252
|
+
description: 'Token usage for the decision operation.',
|
|
1254
1253
|
},
|
|
1255
1254
|
{
|
|
1256
1255
|
name: 'warnings',
|
|
1257
1256
|
type: 'Array<Warning>',
|
|
1258
|
-
description: 'Warnings from the
|
|
1257
|
+
description: 'Warnings from the decision model.',
|
|
1259
1258
|
},
|
|
1260
1259
|
{
|
|
1261
1260
|
name: 'rounding',
|
|
@@ -6,8 +6,8 @@ description: Use @ai-sdk/tui with HarnessAgent.
|
|
|
6
6
|
# Harnesses with Terminal UI
|
|
7
7
|
|
|
8
8
|
`@ai-sdk/tui` can render harness streams, tool calls, reasoning sections, and
|
|
9
|
-
approval prompts in a terminal. Because `HarnessAgent` requires a session
|
|
10
|
-
|
|
9
|
+
approval prompts in a terminal. Because `HarnessAgent` requires a session for
|
|
10
|
+
`generate` and `stream` calls, wrap it with a small `AgentTUIAgent` adapter that injects one
|
|
11
11
|
session for the lifetime of the terminal UI.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
@@ -12,15 +12,17 @@ These warnings help you fix problems before they cause errors.
|
|
|
12
12
|
|
|
13
13
|
### When Warnings Appear
|
|
14
14
|
|
|
15
|
-
Warnings
|
|
15
|
+
Warnings use Node.js `process.emitWarning` when available and `console.warn` in
|
|
16
|
+
browser/edge runtimes. They appear when:
|
|
16
17
|
|
|
17
18
|
- **Unsupported features**: You use a feature or setting that is not supported by the AI model (e.g., certain options or parameters).
|
|
18
19
|
- **Compatibility warnings**: A feature is used in a compatibility mode, which might work differently or less optimally than intended.
|
|
20
|
+
- **Deprecations**: You use a deprecated API, option, or message format.
|
|
19
21
|
- **Other warnings**: The AI model reports another type of issue, such as general problems or advisory messages.
|
|
20
22
|
|
|
21
23
|
### Warning Messages
|
|
22
24
|
|
|
23
|
-
All warnings
|
|
25
|
+
All warnings include "AI SDK Warning" so you can easily find them. For example:
|
|
24
26
|
|
|
25
27
|
```
|
|
26
28
|
AI SDK Warning: The feature "temperature" is not supported by this model
|
|
@@ -41,7 +43,8 @@ globalThis.AI_SDK_LOG_WARNINGS = false;
|
|
|
41
43
|
#### Custom Warning Handler
|
|
42
44
|
|
|
43
45
|
You can also provide your own function to handle warnings.
|
|
44
|
-
It receives
|
|
46
|
+
It receives a list of warnings and optional provider and model ids. Custom
|
|
47
|
+
handlers receive every warning, including repeated deprecations.
|
|
45
48
|
|
|
46
49
|
```ts
|
|
47
50
|
globalThis.AI_SDK_LOG_WARNINGS = ({ warnings, provider, model }) => {
|
|
@@ -49,6 +52,28 @@ globalThis.AI_SDK_LOG_WARNINGS = ({ warnings, provider, model }) => {
|
|
|
49
52
|
};
|
|
50
53
|
```
|
|
51
54
|
|
|
55
|
+
### Deprecation Warnings
|
|
56
|
+
|
|
57
|
+
The default logger emits each deprecation code once per loaded SDK instance.
|
|
58
|
+
In Node.js, these warnings have the type `DeprecationWarning` and a stable
|
|
59
|
+
`AISDK_DEP_*` code, available as `warning.code` on `process.on('warning', handler)`.
|
|
60
|
+
Browser/edge console messages include the code in brackets.
|
|
61
|
+
|
|
62
|
+
| Code | Deprecated usage / replacement |
|
|
63
|
+
| ---------------------------------------- | -------------------------------------------------------------------------- |
|
|
64
|
+
| `AISDK_DEP_GENERATE_OBJECT` | Use `generateText` with `output` instead of `generateObject`. |
|
|
65
|
+
| `AISDK_DEP_STREAM_OBJECT` | Use `streamText` with `output` instead of `streamObject`. |
|
|
66
|
+
| `AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH` | Use `generateSpeech` instead of `experimental_generateSpeech`. |
|
|
67
|
+
| `AISDK_DEP_EXPERIMENTAL_TRANSCRIBE` | Use `transcribe` instead of `experimental_transcribe`. |
|
|
68
|
+
| `AISDK_DEP_TOOL_RESULT_*` | Use `file` with tagged `data` instead of legacy tool-result content types. |
|
|
69
|
+
| `AISDK_DEP_UI_MESSAGE_RAW_INPUT` | Use `input` instead of `rawInput` in UI tool parts. |
|
|
70
|
+
| `AISDK_DEP_IMAGE_CONTENT_PART` | Use `file` with an image `mediaType` instead of `image` message parts. |
|
|
71
|
+
|
|
72
|
+
Run Node.js with `--throw-deprecation` to fail on deprecated usage,
|
|
73
|
+
`--no-deprecation` to suppress deprecations, or `--trace-deprecation` for stack
|
|
74
|
+
traces. These flags affect all `DeprecationWarning`s, rather than individual
|
|
75
|
+
codes, and apply only to the default Node.js logger.
|
|
76
|
+
|
|
52
77
|
## Error Handling
|
|
53
78
|
|
|
54
79
|
### Error Helper Object
|
|
@@ -84,7 +84,7 @@ Tool: bookFlight("BA123", "12th December", ["John Doe", "Jane Doe"])
|
|
|
84
84
|
Model: Your flight has been booked!
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
After `lookupFlight` returns, the passenger details needed by the `bookFlight` tool are not yet available in the application context. The model asks the user for those details; once the user supplies the names, the model can call `bookFlight`.
|
|
88
88
|
|
|
89
89
|
Looking up passenger information could've been another tool that the model could've called before calling the `bookFlight` tool assuming that the user is logged into the application. This way, the model does not have to ask the user for the passenger details and can proceed with the booking.
|
|
90
90
|
|
|
@@ -455,10 +455,10 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
455
455
|
},
|
|
456
456
|
{
|
|
457
457
|
name: 'reasoning',
|
|
458
|
-
type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
|
|
458
|
+
type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'",
|
|
459
459
|
isOptional: true,
|
|
460
460
|
description:
|
|
461
|
-
"Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning.
|
|
461
|
+
"Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning. Provider-specific settings take precedence over corresponding mapped fields. Partial configurations may still use portable reasoning to fill missing fields; summary and display settings can be combined with it. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
|
|
462
462
|
},
|
|
463
463
|
{
|
|
464
464
|
name: 'maxRetries',
|
|
@@ -456,10 +456,10 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
456
456
|
},
|
|
457
457
|
{
|
|
458
458
|
name: 'reasoning',
|
|
459
|
-
type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
|
|
459
|
+
type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'",
|
|
460
460
|
isOptional: true,
|
|
461
461
|
description:
|
|
462
|
-
"Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning.
|
|
462
|
+
"Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning. Provider-specific settings take precedence over corresponding mapped fields. Partial configurations may still use portable reasoning to fill missing fields; summary and display settings can be combined with it. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
|
|
463
463
|
},
|
|
464
464
|
{
|
|
465
465
|
name: 'maxRetries',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: experimental_decide
|
|
3
|
+
description: Decide answers to typed questions against shared state with a decision model.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `experimental_decide()`
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { experimental_decide } from 'ai';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Decides answers to a nonempty map of `choice`, `score`, and `boolean` questions against one
|
|
13
|
+
state. See [Decisions](/docs/ai-sdk-core/decisions) for examples and semantics.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| ----------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `model` | `Experimental_DecisionModel` | Required experimental v4 model instance or a string ID resolved by Gateway or an explicitly configured decision-capable default provider. |
|
|
20
|
+
| `state` | `string \| object \| array` | Required JSON-compatible shared state. |
|
|
21
|
+
| `questions` | `Record<string, Experimental_DecisionQuestion>` | Required nonempty question map. |
|
|
22
|
+
| `maxRetries` | `number` | Nonnegative integer; defaults to 2. |
|
|
23
|
+
| `abortSignal` | `AbortSignal` | Cancels the decisions request. |
|
|
24
|
+
| `headers` | `Record<string, string>` | Additional HTTP headers. |
|
|
25
|
+
| `providerOptions` | `ProviderOptions` | Provider-specific options. |
|
|
26
|
+
| `telemetry` | `TelemetryOptions` | Telemetry configuration, including per-call integrations, input/output recording, and a function ID. |
|
|
27
|
+
| `runtimeContext` | `Record<string, unknown>` | Context available to lifecycle callbacks and selectively included in telemetry with `telemetry.includeRuntimeContext`. |
|
|
28
|
+
| `onStart` | `(event: Experimental_DecideStartEvent) => void` | Called when the decision operation begins. |
|
|
29
|
+
| `onEnd` | `(event: Experimental_DecideEndEvent) => void` | Called when the decision operation completes successfully. |
|
|
30
|
+
|
|
31
|
+
See [Lifecycle Callbacks](/docs/ai-sdk-core/lifecycle-callbacks#experimental_decide)
|
|
32
|
+
for the complete `onStart` and `onEnd` event fields.
|
|
33
|
+
|
|
34
|
+
## Result
|
|
35
|
+
|
|
36
|
+
Returns `Promise<Experimental_DecisionResult<QUESTIONS>>`:
|
|
37
|
+
|
|
38
|
+
- `answers`: One typed answer per question ID, with literal Choice option inference.
|
|
39
|
+
- `usage`: `inputTokens`, `outputTokens`, and `totalTokens`, each possibly undefined.
|
|
40
|
+
- `warnings`: Provider warnings, also passed to the SDK warning logger.
|
|
41
|
+
- `rounding`: Optional provider-declared decimal precision for probabilities and scores.
|
|
42
|
+
- `providerMetadata`: Optional provider-specific metadata.
|
|
43
|
+
- `response`: Timestamp, model ID, and optional response ID, headers, and body.
|
|
44
|
+
|
|
45
|
+
## Provider specification
|
|
46
|
+
|
|
47
|
+
`Experimental_DecisionModelV4` is exported from `@ai-sdk/provider` and declares
|
|
48
|
+
`specificationVersion: 'v4'`, `provider`, `modelId`, `supportedQuestionTypes`, and
|
|
49
|
+
`doDecide(options)`. Decision models are isolated from stable `ProviderV4`.
|
|
50
|
+
|
|
51
|
+
The public core types are `Experimental_DecisionModel`,
|
|
52
|
+
`Experimental_DecisionQuestion`, `Experimental_DecisionAnswer`, and
|
|
53
|
+
`Experimental_DecisionResult`. All decision-specific classes use the
|
|
54
|
+
`Decision` prefix, with `Experimental_` aliases at package boundaries.
|
|
55
|
+
|
|
56
|
+
## Errors
|
|
57
|
+
|
|
58
|
+
Unsupported types throw `Experimental_DecisionUnsupportedQuestionTypeError`
|
|
59
|
+
before provider I/O. Invalid inputs throw `InvalidArgumentError`; malformed
|
|
60
|
+
answers throw `InvalidResponseDataError`. Invalid answers are not retried.
|
|
61
|
+
Neither partial results nor missing probability synthesis are supported.
|
|
62
|
+
|
|
63
|
+
## Model resolution
|
|
64
|
+
|
|
65
|
+
Use `registry.decisionModel('provider:model')` or
|
|
66
|
+
`customProvider({ decisionModels: { alias: model } }).decisionModel('alias')`
|
|
67
|
+
to resolve models. Strings passed directly to `experimental_decide` use
|
|
68
|
+
`globalThis.AI_SDK_DEFAULT_PROVIDER.decisionModel(id)` when a default provider is
|
|
69
|
+
configured, or Gateway when no default provider is configured.
|
|
70
|
+
|
|
71
|
+
Resolution errors use the existing `NoSuchModelError` and `NoSuchProviderError`
|
|
72
|
+
classes with `modelType: 'decisionModel'`. Model instances and resolved models
|
|
73
|
+
must implement v4; other versions throw `UnsupportedModelVersionError`.
|
|
74
|
+
See [model resolution examples](/docs/ai-sdk-core/decisions#model-aliases-and-registries).
|
|
@@ -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.
|