ai 7.0.52 → 7.0.55

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.
@@ -95,6 +95,7 @@ The open-source community has created the following providers:
95
95
  - [Zhipu (Z.AI) Provider](/providers/community-providers/zhipu) (`zhipu-ai-provider`)
96
96
  - [OLLM Provider](/providers/community-providers/ollm) (`@ofoundation/ollm`)
97
97
  - [ZeroEntropy Provider](/providers/community-providers/zeroentropy) (`zeroentropy-ai-provider`)
98
+ - [Crusoe Provider](/providers/community-providers/crusoe) (`crusoe-ai-provider`)
98
99
  - [Neon AI Gateway Provider](/providers/community-providers/neon-ai-gateway) (`@neon/ai-sdk-provider`)
99
100
 
100
101
  ## Self-Hosted Models
@@ -327,5 +327,6 @@ try {
327
327
  | [xAI](/providers/ai-sdk-providers/xai#transcription-models) | `default` |
328
328
  | [Cartesia](/providers/ai-sdk-providers/cartesia#transcription-models) | `ink-whisper` |
329
329
  | [Cartesia](/providers/ai-sdk-providers/cartesia#streaming-transcription-models) | `ink-2` |
330
+ | [Fish Audio](/providers/ai-sdk-providers/fish-audio#transcription-models) | `transcribe-1` |
330
331
 
331
332
  Above are a small subset of the transcription models supported by the AI SDK providers. For more, see the respective provider documentation.
@@ -173,5 +173,8 @@ try {
173
173
  | [Cartesia](/providers/ai-sdk-providers/cartesia#speech-models) | `sonic-3` |
174
174
  | [Cartesia](/providers/ai-sdk-providers/cartesia#speech-models) | `sonic-2` |
175
175
  | [Cartesia](/providers/ai-sdk-providers/cartesia#speech-models) | `sonic-turbo` |
176
+ | [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s1` |
177
+ | [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s2-pro` |
178
+ | [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s2.1-pro` |
176
179
 
177
180
  Above are a small subset of the speech models supported by the AI SDK providers. For more, see the respective provider documentation.
@@ -57,6 +57,7 @@ The AI SDK comes with several built-in middlewares that you can use to configure
57
57
  - `extractReasoningMiddleware`: Extracts reasoning information from the generated text and exposes it as a `reasoning` property on the result.
58
58
  - `extractJsonMiddleware`: Extracts JSON from text content by stripping markdown code fences. Useful when using `Output.object()` with models that wrap JSON responses in code blocks.
59
59
  - `simulateStreamingMiddleware`: Simulates streaming behavior with responses from non-streaming language models.
60
+ - `defaultInstructionsMiddleware`: Applies default instructions when a call does not provide its own instructions.
60
61
  - `defaultSettingsMiddleware`: Applies default settings to a language model.
61
62
  - `addToolInputExamplesMiddleware`: Adds tool input examples to tool descriptions for providers that don't natively support the `inputExamples` property.
62
63
 
@@ -159,6 +160,33 @@ const model = wrapLanguageModel({
159
160
  });
160
161
  ```
161
162
 
163
+ ### Default Instructions
164
+
165
+ The `defaultInstructionsMiddleware` function applies instructions to calls that
166
+ do not already contain a system message. Instructions provided directly on a
167
+ call take precedence over the defaults.
168
+
169
+ ```ts
170
+ import { wrapLanguageModel, defaultInstructionsMiddleware } from 'ai';
171
+
172
+ const model = wrapLanguageModel({
173
+ model: yourModel,
174
+ middleware: defaultInstructionsMiddleware({
175
+ instructions: 'You are a concise technical assistant.',
176
+ }),
177
+ });
178
+ ```
179
+
180
+ The `instructions` option also accepts a `SystemModelMessage` or an array of
181
+ `SystemModelMessage` objects when you need provider options on an instruction.
182
+
183
+ <Note>
184
+ The middleware treats any system message in the normalized prompt as
185
+ call-level instructions and does not add the defaults. Only enable
186
+ `allowSystemInMessages` for trusted message histories, because a system
187
+ message in that history can override these defaults.
188
+ </Note>
189
+
162
190
  ### Add Tool Input Examples
163
191
 
164
192
  The `addToolInputExamplesMiddleware` function adds tool input examples to tool descriptions.
@@ -448,7 +448,8 @@ For `generateText` and `streamText`, the integration records 3 types of spans:
448
448
  - `gen_ai.provider.name`: the provider
449
449
  - `gen_ai.request.model`: the requested model ID
450
450
  - `gen_ai.request.temperature`, `gen_ai.request.max_tokens`, `gen_ai.request.top_p`, `gen_ai.request.top_k`, `gen_ai.request.frequency_penalty`, `gen_ai.request.presence_penalty`, `gen_ai.request.stop_sequences`: request parameters
451
- - `gen_ai.input.messages`: the prompt messages in [GenAI SemConv message format](#genai-message-format) (when `recordInputs` is enabled)
451
+ - `gen_ai.system_instructions`: instructions supplied separately from the chat history, formatted as a JSON array of parts (when `recordInputs` is enabled)
452
+ - `gen_ai.input.messages`: the prompt messages in [GenAI SemConv message format](#genai-message-format), including system messages that are part of the chat history in their original order (when `recordInputs` is enabled)
452
453
  - `gen_ai.tool.definitions`: the tool definitions as stringified JSON (when `recordInputs` is enabled)
453
454
 
454
455
  Attributes set on finish:
@@ -537,7 +538,7 @@ Messages are JSON arrays of objects with a `role` and a `parts` array. Each part
537
538
 
538
539
  Output messages also include a `finish_reason` field (e.g. `"stop"`, `"tool_call"`, `"length"`, `"content_filter"`).
539
540
 
540
- System instructions are recorded separately in `gen_ai.system_instructions` as a JSON array of `{ type: "text", content: "..." }` parts.
541
+ Instructions supplied through `instructions` (or the deprecated `system` option) are recorded separately in `gen_ai.system_instructions` as a JSON array of `{ type: "text", content: "..." }` parts. System messages supplied as chat history with `allowSystemInMessages` remain in `gen_ai.input.messages` in their original positions.
541
542
 
542
543
  ##### GenAI tool call spans
543
544
 
@@ -0,0 +1,106 @@
1
+ ---
2
+ title: defaultInstructionsMiddleware
3
+ description: Middleware that applies default instructions to language model calls
4
+ ---
5
+
6
+ # `defaultInstructionsMiddleware()`
7
+
8
+ `defaultInstructionsMiddleware` applies default instructions to language model
9
+ calls that do not already contain a system message. This is useful for
10
+ configuring reusable model behavior while allowing call-level `instructions` to
11
+ take precedence.
12
+
13
+ ## Import
14
+
15
+ <Snippet
16
+ text={`import { defaultInstructionsMiddleware } from "ai"`}
17
+ prompt={false}
18
+ />
19
+
20
+ ## API Signature
21
+
22
+ ```ts
23
+ function defaultInstructionsMiddleware(options: {
24
+ instructions: Instructions;
25
+ }): LanguageModelMiddleware;
26
+ ```
27
+
28
+ ### Parameters
29
+
30
+ <PropertiesTable
31
+ content={[
32
+ {
33
+ name: 'instructions',
34
+ type: 'string | SystemModelMessage | Array<SystemModelMessage>',
35
+ isOptional: false,
36
+ description:
37
+ 'Default instructions to prepend when a call does not already contain a system message.',
38
+ },
39
+ ]}
40
+ />
41
+
42
+ ### Returns
43
+
44
+ Returns a
45
+ [LanguageModelMiddleware](/docs/ai-sdk-core/middleware) that:
46
+
47
+ - Prepends the configured instructions to calls without a system message.
48
+ - Preserves instruction-level `providerOptions`.
49
+ - Leaves calls containing any system message unchanged, so call-level
50
+ instructions take precedence.
51
+ - Applies to both non-streaming and streaming language model calls.
52
+
53
+ ## Usage Example
54
+
55
+ ```ts
56
+ import {
57
+ defaultInstructionsMiddleware,
58
+ generateText,
59
+ wrapLanguageModel,
60
+ } from 'ai';
61
+
62
+ const model = wrapLanguageModel({
63
+ model: __MODEL__,
64
+ middleware: defaultInstructionsMiddleware({
65
+ instructions: 'You are a concise technical assistant.',
66
+ }),
67
+ });
68
+
69
+ const defaultResult = await generateText({
70
+ model,
71
+ prompt: 'Explain HTTP caching.',
72
+ });
73
+
74
+ const overriddenResult = await generateText({
75
+ model,
76
+ instructions: 'Explain concepts for a complete beginner.',
77
+ prompt: 'Explain HTTP caching.',
78
+ });
79
+ ```
80
+
81
+ You can attach provider options to default instructions by using a
82
+ `SystemModelMessage`:
83
+
84
+ ```ts
85
+ const model = wrapLanguageModel({
86
+ model: __MODEL__,
87
+ middleware: defaultInstructionsMiddleware({
88
+ instructions: {
89
+ role: 'system',
90
+ content: 'You are a concise technical assistant.',
91
+ providerOptions: {
92
+ anthropic: {
93
+ cacheControl: { type: 'ephemeral' },
94
+ },
95
+ },
96
+ },
97
+ }),
98
+ });
99
+ ```
100
+
101
+ <Note>
102
+ This middleware provides defaults, not enforced instructions. Any system
103
+ message in the normalized prompt suppresses the defaults. Only use
104
+ `allowSystemInMessages` with trusted message histories, because an untrusted
105
+ system message could override the configured defaults.
106
+ </Note>
@@ -7,6 +7,9 @@ description: Middleware that applies default settings for language models
7
7
 
8
8
  `defaultSettingsMiddleware` is a middleware function that applies default settings to language model calls. This is useful when you want to establish consistent default parameters across multiple model invocations.
9
9
 
10
+ To apply default system instructions, use
11
+ [`defaultInstructionsMiddleware`](/docs/reference/ai-sdk-core/default-instructions-middleware).
12
+
10
13
  ```ts
11
14
  import { defaultSettingsMiddleware } from 'ai';
12
15
 
@@ -201,6 +201,11 @@ It also contains the following helper functions:
201
201
  description: 'Applies default settings to a language model.',
202
202
  href: '/docs/reference/ai-sdk-core/default-settings-middleware',
203
203
  },
204
+ {
205
+ title: 'defaultInstructionsMiddleware()',
206
+ description: 'Applies default instructions to a language model.',
207
+ href: '/docs/reference/ai-sdk-core/default-instructions-middleware',
208
+ },
204
209
  {
205
210
  title: 'smoothStream()',
206
211
  description: 'Smooths text and reasoning streaming output.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.52",
3
+ "version": "7.0.55",
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,9 +42,9 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.41",
46
- "@ai-sdk/provider": "4.0.5",
47
- "@ai-sdk/provider-utils": "5.0.21"
45
+ "@ai-sdk/gateway": "4.0.43",
46
+ "@ai-sdk/provider": "4.0.6",
47
+ "@ai-sdk/provider-utils": "5.0.23"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@edge-runtime/vm": "^5.0.0",
@@ -326,6 +326,7 @@ export type ToolLoopAgentSettings<
326
326
  | 'frequencyPenalty'
327
327
  | 'stopSequences'
328
328
  | 'seed'
329
+ | 'reasoning'
329
330
  | 'headers'
330
331
  | 'instructions'
331
332
  | 'allowSystemInMessages'
@@ -361,6 +362,7 @@ export type ToolLoopAgentSettings<
361
362
  | 'frequencyPenalty'
362
363
  | 'stopSequences'
363
364
  | 'seed'
365
+ | 'reasoning'
364
366
  | 'headers'
365
367
  | 'instructions'
366
368
  | 'allowSystemInMessages'
@@ -0,0 +1,134 @@
1
+ import type {
2
+ Experimental_BatchV4Error as BatchV4Error,
3
+ Experimental_BatchV4StartResult as BatchV4StartResult,
4
+ Experimental_BatchV4Status as BatchV4Status,
5
+ Experimental_BatchLanguageModelV4 as BatchLanguageModelV4,
6
+ } from '@ai-sdk/provider';
7
+ import type { ProviderOptions } from '@ai-sdk/provider-utils';
8
+ import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
9
+ import type { Prompt } from '../prompt/prompt';
10
+ import type {
11
+ FinishReason,
12
+ GlobalProviderModelId,
13
+ } from '../types/language-model';
14
+ import type { ProviderMetadata } from '../types/provider-metadata';
15
+ import type { LanguageModelUsage } from '../types/usage';
16
+
17
+ /**
18
+ * Language model input that can be used for durable batch processing.
19
+ *
20
+ * String model IDs are resolved through the global provider and checked for
21
+ * batch support at runtime.
22
+ */
23
+ export type BatchLanguageModel = GlobalProviderModelId | BatchLanguageModelV4;
24
+
25
+ /**
26
+ * The persisted reference for a text batch.
27
+ */
28
+ export type TextBatchReference = {
29
+ readonly version: 1;
30
+ readonly type: 'text';
31
+ readonly id: string;
32
+ readonly provider: string;
33
+ readonly modelId: string;
34
+ };
35
+
36
+ /**
37
+ * Persisted reference for any supported batch type.
38
+ *
39
+ * Additional modality-specific references can be added to this union.
40
+ */
41
+ export type BatchReference = TextBatchReference;
42
+
43
+ /**
44
+ * Serializable error information for a batch or batch item.
45
+ */
46
+ export type BatchError = BatchV4Error;
47
+
48
+ /**
49
+ * The latest normalized lifecycle status for a batch.
50
+ */
51
+ export type BatchStatus = BatchV4Status;
52
+
53
+ /**
54
+ * A text batch and its latest normalized lifecycle status.
55
+ */
56
+ export type TextBatch = TextBatchReference & BatchStatus;
57
+
58
+ /**
59
+ * One text generation request within a batch.
60
+ */
61
+ export type TextBatchRequest = Prompt &
62
+ LanguageModelCallOptions & {
63
+ id: string;
64
+ providerOptions?: ProviderOptions;
65
+ };
66
+
67
+ type BatchRequestOptions = {
68
+ abortSignal?: AbortSignal;
69
+ headers?: Record<string, string | undefined>;
70
+ timeout?: number | { totalMs?: number };
71
+ };
72
+
73
+ /**
74
+ * Options for starting a text batch.
75
+ */
76
+ export type StartTextBatchOptions = {
77
+ model: BatchLanguageModel;
78
+ requests: ReadonlyArray<TextBatchRequest>;
79
+ providerOptions?: ProviderOptions;
80
+ } & BatchRequestOptions;
81
+
82
+ /**
83
+ * The acknowledged text batch and warnings produced while starting it.
84
+ */
85
+ export type StartTextBatchResult = TextBatch & {
86
+ readonly warnings: BatchV4StartResult['warnings'];
87
+ };
88
+
89
+ /**
90
+ * Options shared by batch status and result retrieval operations.
91
+ */
92
+ export type BatchOperationOptions = {
93
+ model: BatchLanguageModel;
94
+ batch: BatchReference;
95
+ providerOptions?: ProviderOptions;
96
+ maxRetries?: number;
97
+ } & BatchRequestOptions;
98
+
99
+ /**
100
+ * A normalized result for a successful text batch item.
101
+ */
102
+ export type TextBatchGenerationResult = {
103
+ readonly text: string;
104
+ readonly finishReason: FinishReason;
105
+ readonly rawFinishReason?: string;
106
+ readonly usage: LanguageModelUsage;
107
+ readonly response?: {
108
+ readonly id?: string;
109
+ readonly timestamp?: string;
110
+ readonly modelId?: string;
111
+ };
112
+ readonly providerMetadata?: ProviderMetadata;
113
+ };
114
+
115
+ /**
116
+ * A complete terminal result for one request in a text batch.
117
+ */
118
+ export type TextBatchItemResult =
119
+ | (TextBatchGenerationResult & {
120
+ readonly id: string;
121
+ readonly status: 'succeeded';
122
+ })
123
+ | {
124
+ readonly id: string;
125
+ readonly status: 'failed';
126
+ readonly error: BatchError;
127
+ readonly providerMetadata?: ProviderMetadata;
128
+ }
129
+ | {
130
+ readonly id: string;
131
+ readonly status: 'cancelled' | 'expired';
132
+ readonly error?: BatchError;
133
+ readonly providerMetadata?: ProviderMetadata;
134
+ };