ai 7.0.0-beta.21 → 7.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/index.js +41 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -37
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +6 -0
- package/docs/03-ai-sdk-core/35-image-generation.mdx +1 -1
- package/docs/03-ai-sdk-core/40-middleware.mdx +13 -13
- package/docs/03-ai-sdk-core/55-testing.mdx +10 -10
- package/docs/03-ai-sdk-core/65-event-listeners.mdx +1 -1
- package/docs/06-advanced/04-caching.mdx +10 -10
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +1 -1
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +29 -0
- package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +1 -1
- package/package.json +2 -2
- package/src/generate-text/create-stream-text-part-transform.ts +64 -12
- package/src/generate-text/run-tools-transformation.ts +34 -53
- package/src/telemetry/open-telemetry-integration.ts +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -153,7 +153,7 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
|
153
153
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
154
154
|
|
|
155
155
|
// src/version.ts
|
|
156
|
-
var VERSION = true ? "7.0.0-beta.
|
|
156
|
+
var VERSION = true ? "7.0.0-beta.22" : "0.0.0-test";
|
|
157
157
|
|
|
158
158
|
// src/util/download/download.ts
|
|
159
159
|
var download = async ({
|
package/dist/internal/index.mjs
CHANGED
|
@@ -133,7 +133,7 @@ import {
|
|
|
133
133
|
} from "@ai-sdk/provider-utils";
|
|
134
134
|
|
|
135
135
|
// src/version.ts
|
|
136
|
-
var VERSION = true ? "7.0.0-beta.
|
|
136
|
+
var VERSION = true ? "7.0.0-beta.22" : "0.0.0-test";
|
|
137
137
|
|
|
138
138
|
// src/util/download/download.ts
|
|
139
139
|
var download = async ({
|
|
@@ -42,6 +42,9 @@ const mcpClient = await createMCPClient({
|
|
|
42
42
|
|
|
43
43
|
// optional: provide an OAuth client provider for automatic authorization
|
|
44
44
|
authProvider: myOAuthClientProvider,
|
|
45
|
+
|
|
46
|
+
// optional: allow redirect responses (default is 'error' to prevent SSRF)
|
|
47
|
+
redirect: 'follow',
|
|
45
48
|
},
|
|
46
49
|
});
|
|
47
50
|
```
|
|
@@ -77,6 +80,9 @@ const mcpClient = await createMCPClient({
|
|
|
77
80
|
|
|
78
81
|
// optional: provide an OAuth client provider for automatic authorization
|
|
79
82
|
authProvider: myOAuthClientProvider,
|
|
83
|
+
|
|
84
|
+
// optional: allow redirect responses (default is 'error' to prevent SSRF)
|
|
85
|
+
redirect: 'follow',
|
|
80
86
|
},
|
|
81
87
|
});
|
|
82
88
|
```
|
|
@@ -230,7 +230,7 @@ try {
|
|
|
230
230
|
## Image Middleware
|
|
231
231
|
|
|
232
232
|
You can enhance image models, e.g. to set default values or implement logging, using
|
|
233
|
-
`wrapImageModel` and `
|
|
233
|
+
`wrapImageModel` and `ImageModelV4Middleware`.
|
|
234
234
|
|
|
235
235
|
Here is an example that sets a default size when none is provided:
|
|
236
236
|
|
|
@@ -297,11 +297,11 @@ This example shows how to log the parameters and generated text of a language mo
|
|
|
297
297
|
|
|
298
298
|
```ts
|
|
299
299
|
import type {
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
LanguageModelV4Middleware,
|
|
301
|
+
LanguageModelV4StreamPart,
|
|
302
302
|
} from '@ai-sdk/provider';
|
|
303
303
|
|
|
304
|
-
export const yourLogMiddleware:
|
|
304
|
+
export const yourLogMiddleware: LanguageModelV4Middleware = {
|
|
305
305
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
306
306
|
console.log('doGenerate called');
|
|
307
307
|
console.log(`params: ${JSON.stringify(params, null, 2)}`);
|
|
@@ -324,8 +324,8 @@ export const yourLogMiddleware: LanguageModelV3Middleware = {
|
|
|
324
324
|
const textBlocks = new Map<string, string>();
|
|
325
325
|
|
|
326
326
|
const transformStream = new TransformStream<
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
LanguageModelV4StreamPart,
|
|
328
|
+
LanguageModelV4StreamPart
|
|
329
329
|
>({
|
|
330
330
|
transform(chunk, controller) {
|
|
331
331
|
switch (chunk.type) {
|
|
@@ -370,11 +370,11 @@ export const yourLogMiddleware: LanguageModelV3Middleware = {
|
|
|
370
370
|
This example shows how to build a simple cache for the generated text of a language model call.
|
|
371
371
|
|
|
372
372
|
```ts
|
|
373
|
-
import type {
|
|
373
|
+
import type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
374
374
|
|
|
375
375
|
const cache = new Map<string, any>();
|
|
376
376
|
|
|
377
|
-
export const yourCacheMiddleware:
|
|
377
|
+
export const yourCacheMiddleware: LanguageModelV4Middleware = {
|
|
378
378
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
379
379
|
const cacheKey = JSON.stringify(params);
|
|
380
380
|
|
|
@@ -404,9 +404,9 @@ This example shows how to use RAG as middleware.
|
|
|
404
404
|
</Note>
|
|
405
405
|
|
|
406
406
|
```ts
|
|
407
|
-
import type {
|
|
407
|
+
import type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
408
408
|
|
|
409
|
-
export const yourRagMiddleware:
|
|
409
|
+
export const yourRagMiddleware: LanguageModelV4Middleware = {
|
|
410
410
|
transformParams: async ({ params }) => {
|
|
411
411
|
const lastUserMessageText = getLastUserMessageText({
|
|
412
412
|
prompt: params.prompt,
|
|
@@ -433,9 +433,9 @@ Guard rails are a way to ensure that the generated text of a language model call
|
|
|
433
433
|
is safe and appropriate. This example shows how to use guardrails as middleware.
|
|
434
434
|
|
|
435
435
|
```ts
|
|
436
|
-
import type {
|
|
436
|
+
import type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
437
437
|
|
|
438
|
-
export const yourGuardrailMiddleware:
|
|
438
|
+
export const yourGuardrailMiddleware: LanguageModelV4Middleware = {
|
|
439
439
|
wrapGenerate: async ({ doGenerate }) => {
|
|
440
440
|
const { text, ...rest } = await doGenerate();
|
|
441
441
|
|
|
@@ -458,9 +458,9 @@ To send and access custom metadata in Middleware, you can use `providerOptions`.
|
|
|
458
458
|
```ts
|
|
459
459
|
import { generateText, wrapLanguageModel } from 'ai';
|
|
460
460
|
__PROVIDER_IMPORT__;
|
|
461
|
-
import type {
|
|
461
|
+
import type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
462
462
|
|
|
463
|
-
export const yourLogMiddleware:
|
|
463
|
+
export const yourLogMiddleware: LanguageModelV4Middleware = {
|
|
464
464
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
465
465
|
console.log('METADATA', params?.providerMetadata?.yourLogMiddleware);
|
|
466
466
|
const result = await doGenerate();
|
|
@@ -11,8 +11,8 @@ and calling them is slow and expensive.
|
|
|
11
11
|
To enable you to unit test your code that uses the AI SDK, the AI SDK Core
|
|
12
12
|
includes mock providers and test helpers. You can import the following helpers from `ai/test`:
|
|
13
13
|
|
|
14
|
-
- `
|
|
15
|
-
- `
|
|
14
|
+
- `MockEmbeddingModelV4`: A mock embedding model using the [embedding model v4 specification](https://github.com/vercel/ai/blob/main/packages/provider/src/embedding-model/v4/embedding-model-v4.ts).
|
|
15
|
+
- `MockLanguageModelV4`: A mock language model using the [language model v4 specification](https://github.com/vercel/ai/blob/main/packages/provider/src/language-model/v4/language-model-v4.ts).
|
|
16
16
|
- `mockId`: Provides an incrementing integer ID.
|
|
17
17
|
- `mockValues`: Iterates over an array of values with each call. Returns the last value when the array is exhausted.
|
|
18
18
|
|
|
@@ -30,10 +30,10 @@ You can use the test helpers with the AI Core functions in your unit tests:
|
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { generateText } from 'ai';
|
|
33
|
-
import {
|
|
33
|
+
import { MockLanguageModelV4 } from 'ai/test';
|
|
34
34
|
|
|
35
35
|
const result = await generateText({
|
|
36
|
-
model: new
|
|
36
|
+
model: new MockLanguageModelV4({
|
|
37
37
|
doGenerate: async () => ({
|
|
38
38
|
content: [{ type: 'text', text: `Hello, world!` }],
|
|
39
39
|
finishReason: { unified: 'stop', raw: undefined },
|
|
@@ -61,10 +61,10 @@ const result = await generateText({
|
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
import { streamText, simulateReadableStream } from 'ai';
|
|
64
|
-
import {
|
|
64
|
+
import { MockLanguageModelV4 } from 'ai/test';
|
|
65
65
|
|
|
66
66
|
const result = streamText({
|
|
67
|
-
model: new
|
|
67
|
+
model: new MockLanguageModelV4({
|
|
68
68
|
doStream: async () => ({
|
|
69
69
|
stream: simulateReadableStream({
|
|
70
70
|
chunks: [
|
|
@@ -103,11 +103,11 @@ const result = streamText({
|
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
105
|
import { generateText, Output } from 'ai';
|
|
106
|
-
import {
|
|
106
|
+
import { MockLanguageModelV4 } from 'ai/test';
|
|
107
107
|
import { z } from 'zod';
|
|
108
108
|
|
|
109
109
|
const result = await generateText({
|
|
110
|
-
model: new
|
|
110
|
+
model: new MockLanguageModelV4({
|
|
111
111
|
doGenerate: async () => ({
|
|
112
112
|
content: [{ type: 'text', text: `{"content":"Hello, world!"}` }],
|
|
113
113
|
finishReason: { unified: 'stop', raw: undefined },
|
|
@@ -136,11 +136,11 @@ const result = await generateText({
|
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
138
|
import { streamText, Output, simulateReadableStream } from 'ai';
|
|
139
|
-
import {
|
|
139
|
+
import { MockLanguageModelV4 } from 'ai/test';
|
|
140
140
|
import { z } from 'zod';
|
|
141
141
|
|
|
142
142
|
const result = streamText({
|
|
143
|
-
model: new
|
|
143
|
+
model: new MockLanguageModelV4({
|
|
144
144
|
doStream: async () => ({
|
|
145
145
|
stream: simulateReadableStream({
|
|
146
146
|
chunks: [
|
|
@@ -265,7 +265,7 @@ const result = await generateText({
|
|
|
265
265
|
},
|
|
266
266
|
{
|
|
267
267
|
name: 'toolChoice',
|
|
268
|
-
type: '
|
|
268
|
+
type: 'LanguageModelV4ToolChoice | undefined',
|
|
269
269
|
description: 'The tool choice configuration for this step.',
|
|
270
270
|
},
|
|
271
271
|
{
|
|
@@ -18,9 +18,9 @@ Let's see how you can use language model middleware to cache responses.
|
|
|
18
18
|
```ts filename="ai/middleware.ts"
|
|
19
19
|
import { Redis } from '@upstash/redis';
|
|
20
20
|
import {
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
type
|
|
21
|
+
type LanguageModelV4,
|
|
22
|
+
type LanguageModelV4Middleware,
|
|
23
|
+
type LanguageModelV4StreamPart,
|
|
24
24
|
simulateReadableStream,
|
|
25
25
|
} from 'ai';
|
|
26
26
|
|
|
@@ -29,12 +29,12 @@ const redis = new Redis({
|
|
|
29
29
|
token: process.env.KV_TOKEN,
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
export const cacheMiddleware:
|
|
32
|
+
export const cacheMiddleware: LanguageModelV4Middleware = {
|
|
33
33
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
34
34
|
const cacheKey = JSON.stringify(params);
|
|
35
35
|
|
|
36
36
|
const cached = (await redis.get(cacheKey)) as Awaited<
|
|
37
|
-
ReturnType<
|
|
37
|
+
ReturnType<LanguageModelV4['doGenerate']>
|
|
38
38
|
> | null;
|
|
39
39
|
|
|
40
40
|
if (cached !== null) {
|
|
@@ -64,7 +64,7 @@ export const cacheMiddleware: LanguageModelV3Middleware = {
|
|
|
64
64
|
// If cached, return a simulated ReadableStream that yields the cached result
|
|
65
65
|
if (cached !== null) {
|
|
66
66
|
// Format the timestamps in the cached response
|
|
67
|
-
const formattedChunks = (cached as
|
|
67
|
+
const formattedChunks = (cached as LanguageModelV4StreamPart[]).map(p => {
|
|
68
68
|
if (p.type === 'response-metadata' && p.timestamp) {
|
|
69
69
|
return { ...p, timestamp: new Date(p.timestamp) };
|
|
70
70
|
} else return p;
|
|
@@ -81,11 +81,11 @@ export const cacheMiddleware: LanguageModelV3Middleware = {
|
|
|
81
81
|
// If not cached, proceed with streaming
|
|
82
82
|
const { stream, ...rest } = await doStream();
|
|
83
83
|
|
|
84
|
-
const fullResponse:
|
|
84
|
+
const fullResponse: LanguageModelV4StreamPart[] = [];
|
|
85
85
|
|
|
86
86
|
const transformStream = new TransformStream<
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
LanguageModelV4StreamPart,
|
|
88
|
+
LanguageModelV4StreamPart
|
|
89
89
|
>({
|
|
90
90
|
transform(chunk, controller) {
|
|
91
91
|
fullResponse.push(chunk);
|
|
@@ -110,7 +110,7 @@ export const cacheMiddleware: LanguageModelV3Middleware = {
|
|
|
110
110
|
responses but you can use any KV storage provider you would like.
|
|
111
111
|
</Note>
|
|
112
112
|
|
|
113
|
-
`
|
|
113
|
+
`LanguageModelV4Middleware` has two methods: `wrapGenerate` and `wrapStream`. `wrapGenerate` is called when using [`generateText`](/docs/reference/ai-sdk-core/generate-text), while `wrapStream` is called when using [`streamText`](/docs/reference/ai-sdk-core/stream-text).
|
|
114
114
|
|
|
115
115
|
For `wrapGenerate`, you can cache the response directly. Instead, for `wrapStream`, you cache an array of the stream parts, which can then be used with [`simulateReadableStream`](/docs/ai-sdk-core/testing#simulate-data-stream-protocol-responses) function to create a simulated `ReadableStream` that returns the cached response. In this way, the cached response is returned chunk-by-chunk as if it were being generated by the model. You can control the initial delay and delay between chunks by adjusting the `initialDelayInMs` and `chunkDelayInMs` parameters of `simulateReadableStream`.
|
|
116
116
|
|
|
@@ -694,7 +694,7 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
694
694
|
},
|
|
695
695
|
{
|
|
696
696
|
name: 'experimental_repairToolCall',
|
|
697
|
-
type: '(options: ToolCallRepairOptions) => Promise<
|
|
697
|
+
type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
|
|
698
698
|
isOptional: true,
|
|
699
699
|
description:
|
|
700
700
|
'A function that attempts to repair a tool call that failed to parse. Return either a repaired tool call or null if the tool call cannot be repaired.',
|
|
@@ -714,7 +714,7 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
714
714
|
},
|
|
715
715
|
{
|
|
716
716
|
name: 'toolCall',
|
|
717
|
-
type: '
|
|
717
|
+
type: 'LanguageModelV4ToolCall',
|
|
718
718
|
description: 'The tool call that failed to parse.',
|
|
719
719
|
},
|
|
720
720
|
{
|
|
@@ -1072,7 +1072,7 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
1072
1072
|
},
|
|
1073
1073
|
{
|
|
1074
1074
|
name: 'toolChoice',
|
|
1075
|
-
type: '
|
|
1075
|
+
type: 'LanguageModelV4ToolChoice | undefined',
|
|
1076
1076
|
description: 'The tool choice configuration for this step.',
|
|
1077
1077
|
},
|
|
1078
1078
|
{
|
|
@@ -731,7 +731,7 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
731
731
|
},
|
|
732
732
|
{
|
|
733
733
|
name: 'experimental_repairToolCall',
|
|
734
|
-
type: '(options: ToolCallRepairOptions) => Promise<
|
|
734
|
+
type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
|
|
735
735
|
isOptional: true,
|
|
736
736
|
description:
|
|
737
737
|
'A function that attempts to repair a tool call that failed to parse. Return either a repaired tool call or null if the tool call cannot be repaired.',
|
|
@@ -751,7 +751,7 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
751
751
|
},
|
|
752
752
|
{
|
|
753
753
|
name: 'toolCall',
|
|
754
|
-
type: '
|
|
754
|
+
type: 'LanguageModelV4ToolCall',
|
|
755
755
|
description: 'The tool call that failed to parse.',
|
|
756
756
|
},
|
|
757
757
|
{
|
|
@@ -1954,7 +1954,7 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
1954
1954
|
},
|
|
1955
1955
|
{
|
|
1956
1956
|
name: 'toolChoice',
|
|
1957
|
-
type: '
|
|
1957
|
+
type: 'LanguageModelV4ToolChoice | undefined',
|
|
1958
1958
|
description: 'The tool choice configuration for this step.',
|
|
1959
1959
|
},
|
|
1960
1960
|
{
|
|
@@ -292,7 +292,7 @@ To see `ToolLoopAgent` in action, check out [these examples](#examples).
|
|
|
292
292
|
},
|
|
293
293
|
{
|
|
294
294
|
name: 'toolChoice',
|
|
295
|
-
type: '
|
|
295
|
+
type: 'LanguageModelV4ToolChoice | undefined',
|
|
296
296
|
description: 'The tool choice configuration for this step.',
|
|
297
297
|
},
|
|
298
298
|
{
|
|
@@ -108,6 +108,13 @@ It currently does not support accepting notifications from an MCP server, and cu
|
|
|
108
108
|
description:
|
|
109
109
|
'Optional OAuth provider for authorization to access protected remote MCP servers.',
|
|
110
110
|
},
|
|
111
|
+
{
|
|
112
|
+
name: 'redirect',
|
|
113
|
+
type: "'follow' | 'error'",
|
|
114
|
+
isOptional: true,
|
|
115
|
+
description:
|
|
116
|
+
"Controls how HTTP redirects are handled for transport requests. Set to 'follow' to allow redirect responses. Defaults to 'error' to reject any redirect response, preventing servers from redirecting requests to unintended hosts.",
|
|
117
|
+
},
|
|
111
118
|
],
|
|
112
119
|
},
|
|
113
120
|
],
|
|
@@ -187,7 +187,7 @@ export interface ToolResultPart {
|
|
|
187
187
|
/**
|
|
188
188
|
* Result of the tool call. This is a JSON-serializable object.
|
|
189
189
|
*/
|
|
190
|
-
output:
|
|
190
|
+
output: LanguageModelV4ToolResultOutput;
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
Additional provider-specific metadata. They are passed through
|
|
@@ -198,7 +198,7 @@ export interface ToolResultPart {
|
|
|
198
198
|
}
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
### `
|
|
201
|
+
### `LanguageModelV4ToolResultOutput`
|
|
202
202
|
|
|
203
203
|
```ts
|
|
204
204
|
/**
|
|
@@ -30,12 +30,12 @@ const wrappedLanguageModel = wrapLanguageModel({
|
|
|
30
30
|
content={[
|
|
31
31
|
{
|
|
32
32
|
name: 'model',
|
|
33
|
-
type: '
|
|
34
|
-
description: 'The original
|
|
33
|
+
type: 'LanguageModelV4',
|
|
34
|
+
description: 'The original LanguageModelV4 instance to be wrapped.',
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
name: 'middleware',
|
|
38
|
-
type: '
|
|
38
|
+
type: 'LanguageModelV4Middleware | LanguageModelV4Middleware[]',
|
|
39
39
|
description:
|
|
40
40
|
'The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.',
|
|
41
41
|
},
|
|
@@ -56,4 +56,4 @@ const wrappedLanguageModel = wrapLanguageModel({
|
|
|
56
56
|
|
|
57
57
|
### Returns
|
|
58
58
|
|
|
59
|
-
A new `
|
|
59
|
+
A new `LanguageModelV4` instance with middleware applied.
|
|
@@ -35,12 +35,12 @@ const { image } = await generateImage({
|
|
|
35
35
|
content={[
|
|
36
36
|
{
|
|
37
37
|
name: 'model',
|
|
38
|
-
type: '
|
|
39
|
-
description: 'The original
|
|
38
|
+
type: 'ImageModelV4',
|
|
39
|
+
description: 'The original ImageModelV4 instance to be wrapped.',
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
name: 'middleware',
|
|
43
|
-
type: '
|
|
43
|
+
type: 'ImageModelV4Middleware | ImageModelV4Middleware[]',
|
|
44
44
|
description:
|
|
45
45
|
'The middleware to be applied to the image model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.',
|
|
46
46
|
},
|
|
@@ -61,4 +61,4 @@ const { image } = await generateImage({
|
|
|
61
61
|
|
|
62
62
|
### Returns
|
|
63
63
|
|
|
64
|
-
A new `
|
|
64
|
+
A new `ImageModelV4` instance with middleware applied.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: LanguageModelV4Middleware
|
|
3
3
|
description: Middleware for enhancing language model behavior (API Reference)
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# `
|
|
6
|
+
# `LanguageModelV4Middleware`
|
|
7
7
|
|
|
8
8
|
<Note type="warning">
|
|
9
9
|
Language model middleware is an experimental feature.
|
|
@@ -18,7 +18,7 @@ See [Language Model Middleware](/docs/ai-sdk-core/middleware) for more informati
|
|
|
18
18
|
## Import
|
|
19
19
|
|
|
20
20
|
<Snippet
|
|
21
|
-
text={`import {
|
|
21
|
+
text={`import { LanguageModelV4Middleware } from "ai"`}
|
|
22
22
|
prompt={false}
|
|
23
23
|
/>
|
|
24
24
|
|
|
@@ -33,40 +33,40 @@ See [Language Model Middleware](/docs/ai-sdk-core/middleware) for more informati
|
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
name: 'transformParams',
|
|
36
|
-
type: '({ type: "generate" | "stream", params:
|
|
36
|
+
type: '({ type: "generate" | "stream", params: LanguageModelV4CallOptions, model: LanguageModelV4 }) => PromiseLike<LanguageModelV4CallOptions>',
|
|
37
37
|
isOptional: true,
|
|
38
38
|
description:
|
|
39
39
|
'Transforms the parameters before they are passed to the language model.',
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
name: 'wrapGenerate',
|
|
43
|
-
type: '({ doGenerate: () => PromiseLike<
|
|
43
|
+
type: '({ doGenerate: () => PromiseLike<LanguageModelV4GenerateResult>, doStream: () => PromiseLike<LanguageModelV4StreamResult>, params: LanguageModelV4CallOptions, model: LanguageModelV4 }) => PromiseLike<LanguageModelV4GenerateResult>',
|
|
44
44
|
isOptional: true,
|
|
45
45
|
description:
|
|
46
46
|
'Wraps the generate operation of the language model. Receives both doGenerate and doStream functions.',
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
name: 'wrapStream',
|
|
50
|
-
type: '({ doGenerate: () => PromiseLike<
|
|
50
|
+
type: '({ doGenerate: () => PromiseLike<LanguageModelV4GenerateResult>, doStream: () => PromiseLike<LanguageModelV4StreamResult>, params: LanguageModelV4CallOptions, model: LanguageModelV4 }) => PromiseLike<LanguageModelV4StreamResult>',
|
|
51
51
|
isOptional: true,
|
|
52
52
|
description:
|
|
53
53
|
'Wraps the stream operation of the language model. Receives both doGenerate and doStream functions.',
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
name: 'overrideProvider',
|
|
57
|
-
type: '(options: { model:
|
|
57
|
+
type: '(options: { model: LanguageModelV4 }) => string',
|
|
58
58
|
isOptional: true,
|
|
59
59
|
description: 'Override the provider ID of the model.',
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
name: 'overrideModelId',
|
|
63
|
-
type: '(options: { model:
|
|
63
|
+
type: '(options: { model: LanguageModelV4 }) => string',
|
|
64
64
|
isOptional: true,
|
|
65
65
|
description: 'Override the model ID of the model.',
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
name: 'overrideSupportedUrls',
|
|
69
|
-
type: '(options: { model:
|
|
69
|
+
type: '(options: { model: LanguageModelV4 }) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>',
|
|
70
70
|
isOptional: true,
|
|
71
71
|
description: 'Override the supported URLs for the model.',
|
|
72
72
|
},
|
|
@@ -32,7 +32,7 @@ const middleware = defaultSettingsMiddleware({
|
|
|
32
32
|
|
|
33
33
|
The middleware accepts a configuration object with the following properties:
|
|
34
34
|
|
|
35
|
-
- `settings`: An object containing default parameter values to apply to language model calls. These can include any valid `
|
|
35
|
+
- `settings`: An object containing default parameter values to apply to language model calls. These can include any valid `LanguageModelV4CallOptions` properties and optional provider metadata.
|
|
36
36
|
|
|
37
37
|
### Returns
|
|
38
38
|
|
|
@@ -64,3 +64,32 @@ const result = await generateText({
|
|
|
64
64
|
This applies to all AI SDK functions that accept `experimental_telemetry`, including `streamText`, `generateObject`, `streamObject`, `embed`, and `embedMany`.
|
|
65
65
|
|
|
66
66
|
If you were not passing a custom `tracer` (relying on the default global tracer), no changes are needed — the `OpenTelemetryIntegration` is registered globally by default and uses `trace.getTracer('ai')` when no custom tracer is provided.
|
|
67
|
+
|
|
68
|
+
## MCP Package
|
|
69
|
+
|
|
70
|
+
### MCP Transport: `redirect` Default Changed from `'follow'` to `'error'`
|
|
71
|
+
|
|
72
|
+
The `redirect` option on `MCPTransportConfig` (used by both HTTP and SSE transports) now defaults to `'error'` instead of `'follow'`. This means HTTP redirects are rejected by default to prevent server-side request forgery (SSRF) attacks where an MCP server could redirect requests to unintended hosts.
|
|
73
|
+
|
|
74
|
+
If your MCP server relies on HTTP redirects, explicitly set `redirect: 'follow'` in your transport configuration:
|
|
75
|
+
|
|
76
|
+
```tsx filename="AI SDK 6"
|
|
77
|
+
const mcpClient = await createMCPClient({
|
|
78
|
+
transport: {
|
|
79
|
+
type: 'http',
|
|
80
|
+
url: 'https://your-server.com/mcp',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```tsx filename="AI SDK 7"
|
|
86
|
+
const mcpClient = await createMCPClient({
|
|
87
|
+
transport: {
|
|
88
|
+
type: 'http',
|
|
89
|
+
url: 'https://your-server.com/mcp',
|
|
90
|
+
redirect: 'follow',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If the MCP server you use does not issue redirects, no changes are needed — the new default is more secure.
|
|
@@ -9,7 +9,7 @@ description: Troubleshooting errors related to incompatible models.
|
|
|
9
9
|
|
|
10
10
|
I have updated the AI SDK and now I get the following error: `Type 'SomeModel' is not assignable to type 'LanguageModelV1'.`
|
|
11
11
|
|
|
12
|
-
<Note>Similar errors can occur with `
|
|
12
|
+
<Note>Similar errors can occur with `EmbeddingModelV4` as well.</Note>
|
|
13
13
|
|
|
14
14
|
## Background
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.22",
|
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/api": "1.9.0",
|
|
48
|
-
"@ai-sdk/gateway": "4.0.0-beta.
|
|
48
|
+
"@ai-sdk/gateway": "4.0.0-beta.14",
|
|
49
49
|
"@ai-sdk/provider": "4.0.0-beta.2",
|
|
50
50
|
"@ai-sdk/provider-utils": "5.0.0-beta.3"
|
|
51
51
|
},
|