@ai-sdk/gateway 4.0.0-beta.13 → 4.0.0-beta.15
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 +13 -0
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/gateway-embedding-model.ts +8 -8
- package/src/gateway-fetch-metadata.ts +1 -1
- package/src/gateway-image-model.ts +10 -10
- package/src/gateway-language-model-settings.ts +4 -0
- package/src/gateway-language-model.ts +19 -19
- package/src/gateway-model-entry.ts +2 -2
- package/src/gateway-provider.ts +17 -17
- package/src/gateway-video-model.ts +15 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ImageModelV4,
|
|
3
|
+
ImageModelV4File,
|
|
4
|
+
ImageModelV4ProviderMetadata,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
@@ -17,8 +17,8 @@ import type { GatewayConfig } from './gateway-config';
|
|
|
17
17
|
import { asGatewayError } from './errors';
|
|
18
18
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
19
19
|
|
|
20
|
-
export class GatewayImageModel implements
|
|
21
|
-
readonly specificationVersion = '
|
|
20
|
+
export class GatewayImageModel implements ImageModelV4 {
|
|
21
|
+
readonly specificationVersion = 'v4' as const;
|
|
22
22
|
// Set a very large number to prevent client-side splitting of requests
|
|
23
23
|
readonly maxImagesPerCall = Number.MAX_SAFE_INTEGER;
|
|
24
24
|
|
|
@@ -45,8 +45,8 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
45
45
|
providerOptions,
|
|
46
46
|
headers,
|
|
47
47
|
abortSignal,
|
|
48
|
-
}: Parameters<
|
|
49
|
-
Awaited<ReturnType<
|
|
48
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
49
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
50
50
|
> {
|
|
51
51
|
const resolvedHeaders = await resolve(this.config.headers());
|
|
52
52
|
try {
|
|
@@ -89,7 +89,7 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
89
89
|
images: responseBody.images, // Always base64 strings from server
|
|
90
90
|
warnings: responseBody.warnings ?? [],
|
|
91
91
|
providerMetadata:
|
|
92
|
-
responseBody.providerMetadata as
|
|
92
|
+
responseBody.providerMetadata as ImageModelV4ProviderMetadata,
|
|
93
93
|
response: {
|
|
94
94
|
timestamp: new Date(),
|
|
95
95
|
modelId: this.modelId,
|
|
@@ -114,13 +114,13 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
114
114
|
|
|
115
115
|
private getModelConfigHeaders() {
|
|
116
116
|
return {
|
|
117
|
-
'ai-image-model-specification-version': '
|
|
117
|
+
'ai-image-model-specification-version': '4',
|
|
118
118
|
'ai-model-id': this.modelId,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
function maybeEncodeImageFile(file:
|
|
123
|
+
function maybeEncodeImageFile(file: ImageModelV4File) {
|
|
124
124
|
if (file.type === 'file' && file.data instanceof Uint8Array) {
|
|
125
125
|
return {
|
|
126
126
|
...file,
|
|
@@ -78,6 +78,8 @@ export type GatewayModelId =
|
|
|
78
78
|
| 'minimax/minimax-m2.1-lightning'
|
|
79
79
|
| 'minimax/minimax-m2.5'
|
|
80
80
|
| 'minimax/minimax-m2.5-highspeed'
|
|
81
|
+
| 'minimax/minimax-m2.7'
|
|
82
|
+
| 'minimax/minimax-m2.7-highspeed'
|
|
81
83
|
| 'mistral/codestral'
|
|
82
84
|
| 'mistral/devstral-2'
|
|
83
85
|
| 'mistral/devstral-small'
|
|
@@ -132,6 +134,8 @@ export type GatewayModelId =
|
|
|
132
134
|
| 'openai/gpt-5.3-chat'
|
|
133
135
|
| 'openai/gpt-5.3-codex'
|
|
134
136
|
| 'openai/gpt-5.4'
|
|
137
|
+
| 'openai/gpt-5.4-mini'
|
|
138
|
+
| 'openai/gpt-5.4-nano'
|
|
135
139
|
| 'openai/gpt-5.4-pro'
|
|
136
140
|
| 'openai/gpt-oss-120b'
|
|
137
141
|
| 'openai/gpt-oss-20b'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
|
+
LanguageModelV4CallOptions,
|
|
4
|
+
SharedV4Warning,
|
|
5
|
+
LanguageModelV4FilePart,
|
|
6
|
+
LanguageModelV4StreamPart,
|
|
7
|
+
LanguageModelV4GenerateResult,
|
|
8
|
+
LanguageModelV4StreamResult,
|
|
9
9
|
} from '@ai-sdk/provider';
|
|
10
10
|
import {
|
|
11
11
|
combineHeaders,
|
|
@@ -28,8 +28,8 @@ type GatewayChatConfig = GatewayConfig & {
|
|
|
28
28
|
o11yHeaders: Resolvable<Record<string, string>>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export class GatewayLanguageModel implements
|
|
32
|
-
readonly specificationVersion = '
|
|
31
|
+
export class GatewayLanguageModel implements LanguageModelV4 {
|
|
32
|
+
readonly specificationVersion = 'v4';
|
|
33
33
|
readonly supportedUrls = { '*/*': [/.*/] };
|
|
34
34
|
|
|
35
35
|
constructor(
|
|
@@ -41,7 +41,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
41
41
|
return this.config.provider;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
private async getArgs(options:
|
|
44
|
+
private async getArgs(options: LanguageModelV4CallOptions) {
|
|
45
45
|
const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
|
|
46
46
|
|
|
47
47
|
return {
|
|
@@ -51,8 +51,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async doGenerate(
|
|
54
|
-
options:
|
|
55
|
-
): Promise<
|
|
54
|
+
options: LanguageModelV4CallOptions,
|
|
55
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
56
56
|
const { args, warnings } = await this.getArgs(options);
|
|
57
57
|
const { abortSignal } = options;
|
|
58
58
|
|
|
@@ -93,8 +93,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
async doStream(
|
|
96
|
-
options:
|
|
97
|
-
): Promise<
|
|
96
|
+
options: LanguageModelV4CallOptions,
|
|
97
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
98
98
|
const { args, warnings } = await this.getArgs(options);
|
|
99
99
|
const { abortSignal } = options;
|
|
100
100
|
|
|
@@ -122,8 +122,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
122
122
|
return {
|
|
123
123
|
stream: response.pipeThrough(
|
|
124
124
|
new TransformStream<
|
|
125
|
-
ParseResult<
|
|
126
|
-
|
|
125
|
+
ParseResult<LanguageModelV4StreamPart>,
|
|
126
|
+
LanguageModelV4StreamPart
|
|
127
127
|
>({
|
|
128
128
|
start(controller) {
|
|
129
129
|
if (warnings.length > 0) {
|
|
@@ -177,11 +177,11 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
177
177
|
* @param options - The options to encode.
|
|
178
178
|
* @returns The options with the file parts encoded.
|
|
179
179
|
*/
|
|
180
|
-
private maybeEncodeFileParts(options:
|
|
180
|
+
private maybeEncodeFileParts(options: LanguageModelV4CallOptions) {
|
|
181
181
|
for (const message of options.prompt) {
|
|
182
182
|
for (const part of message.content) {
|
|
183
183
|
if (this.isFilePart(part)) {
|
|
184
|
-
const filePart = part as
|
|
184
|
+
const filePart = part as LanguageModelV4FilePart;
|
|
185
185
|
// If the file part is a URL it will get cleanly converted to a string.
|
|
186
186
|
// If it's a binary file attachment we convert it to a data url.
|
|
187
187
|
// In either case, server-side we should only ever see URLs as strings.
|
|
@@ -204,7 +204,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
204
204
|
|
|
205
205
|
private getModelConfigHeaders(modelId: string, streaming: boolean) {
|
|
206
206
|
return {
|
|
207
|
-
'ai-language-model-specification-version': '
|
|
207
|
+
'ai-language-model-specification-version': '4',
|
|
208
208
|
'ai-language-model-id': modelId,
|
|
209
209
|
'ai-language-model-streaming': String(streaming),
|
|
210
210
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export interface GatewayLanguageModelEntry {
|
|
4
4
|
/**
|
|
@@ -53,6 +53,6 @@ export interface GatewayLanguageModelEntry {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export type GatewayLanguageModelSpecification = Pick<
|
|
56
|
-
|
|
56
|
+
LanguageModelV4,
|
|
57
57
|
'specificationVersion' | 'provider' | 'modelId'
|
|
58
58
|
>;
|
package/src/gateway-provider.ts
CHANGED
|
@@ -24,27 +24,27 @@ import { gatewayTools } from './gateway-tools';
|
|
|
24
24
|
import { getVercelOidcToken, getVercelRequestId } from './vercel-environment';
|
|
25
25
|
import type { GatewayModelId } from './gateway-language-model-settings';
|
|
26
26
|
import type {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
LanguageModelV4,
|
|
28
|
+
EmbeddingModelV4,
|
|
29
|
+
ImageModelV4,
|
|
30
|
+
Experimental_VideoModelV4,
|
|
31
|
+
ProviderV4,
|
|
32
32
|
} from '@ai-sdk/provider';
|
|
33
33
|
import { withUserAgentSuffix } from '@ai-sdk/provider-utils';
|
|
34
34
|
import { VERSION } from './version';
|
|
35
35
|
|
|
36
|
-
export interface GatewayProvider extends
|
|
37
|
-
(modelId: GatewayModelId):
|
|
36
|
+
export interface GatewayProvider extends ProviderV4 {
|
|
37
|
+
(modelId: GatewayModelId): LanguageModelV4;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Creates a model for text generation.
|
|
41
41
|
*/
|
|
42
|
-
chat(modelId: GatewayModelId):
|
|
42
|
+
chat(modelId: GatewayModelId): LanguageModelV4;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Creates a model for text generation.
|
|
46
46
|
*/
|
|
47
|
-
languageModel(modelId: GatewayModelId):
|
|
47
|
+
languageModel(modelId: GatewayModelId): LanguageModelV4;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Returns available providers and models for use with the remote provider.
|
|
@@ -59,37 +59,37 @@ export interface GatewayProvider extends ProviderV3 {
|
|
|
59
59
|
/**
|
|
60
60
|
* Creates a model for generating text embeddings.
|
|
61
61
|
*/
|
|
62
|
-
embedding(modelId: GatewayEmbeddingModelId):
|
|
62
|
+
embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Creates a model for generating text embeddings.
|
|
66
66
|
*/
|
|
67
|
-
embeddingModel(modelId: GatewayEmbeddingModelId):
|
|
67
|
+
embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* @deprecated Use `embeddingModel` instead.
|
|
71
71
|
*/
|
|
72
|
-
textEmbeddingModel(modelId: GatewayEmbeddingModelId):
|
|
72
|
+
textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Creates a model for generating images.
|
|
76
76
|
*/
|
|
77
|
-
image(modelId: GatewayImageModelId):
|
|
77
|
+
image(modelId: GatewayImageModelId): ImageModelV4;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* Creates a model for generating images.
|
|
81
81
|
*/
|
|
82
|
-
imageModel(modelId: GatewayImageModelId):
|
|
82
|
+
imageModel(modelId: GatewayImageModelId): ImageModelV4;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Creates a model for generating videos.
|
|
86
86
|
*/
|
|
87
|
-
video(modelId: GatewayVideoModelId):
|
|
87
|
+
video(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Creates a model for generating videos.
|
|
91
91
|
*/
|
|
92
|
-
videoModel(modelId: GatewayVideoModelId):
|
|
92
|
+
videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Gateway-specific tools executed server-side.
|
|
@@ -263,7 +263,7 @@ export function createGatewayProvider(
|
|
|
263
263
|
return createLanguageModel(modelId);
|
|
264
264
|
};
|
|
265
265
|
|
|
266
|
-
provider.specificationVersion = '
|
|
266
|
+
provider.specificationVersion = 'v4' as const;
|
|
267
267
|
provider.getAvailableModels = getAvailableModels;
|
|
268
268
|
provider.getCredits = getCredits;
|
|
269
269
|
provider.imageModel = (modelId: GatewayImageModelId) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Experimental_VideoModelV4,
|
|
3
|
+
Experimental_VideoModelV4CallOptions,
|
|
4
|
+
Experimental_VideoModelV4File,
|
|
5
|
+
Experimental_VideoModelV4VideoData,
|
|
6
|
+
SharedV4ProviderMetadata,
|
|
7
|
+
SharedV4Warning,
|
|
8
8
|
} from '@ai-sdk/provider';
|
|
9
9
|
import { APICallError } from '@ai-sdk/provider';
|
|
10
10
|
import {
|
|
@@ -21,8 +21,8 @@ import type { GatewayConfig } from './gateway-config';
|
|
|
21
21
|
import { asGatewayError } from './errors';
|
|
22
22
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
23
23
|
|
|
24
|
-
export class GatewayVideoModel implements
|
|
25
|
-
readonly specificationVersion = '
|
|
24
|
+
export class GatewayVideoModel implements Experimental_VideoModelV4 {
|
|
25
|
+
readonly specificationVersion = 'v4' as const;
|
|
26
26
|
// Set a very large number to prevent client-side splitting of requests
|
|
27
27
|
readonly maxVideosPerCall = Number.MAX_SAFE_INTEGER;
|
|
28
28
|
|
|
@@ -50,10 +50,10 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
50
50
|
providerOptions,
|
|
51
51
|
headers,
|
|
52
52
|
abortSignal,
|
|
53
|
-
}:
|
|
54
|
-
videos: Array<
|
|
55
|
-
warnings: Array<
|
|
56
|
-
providerMetadata?:
|
|
53
|
+
}: Experimental_VideoModelV4CallOptions): Promise<{
|
|
54
|
+
videos: Array<Experimental_VideoModelV4VideoData>;
|
|
55
|
+
warnings: Array<SharedV4Warning>;
|
|
56
|
+
providerMetadata?: SharedV4ProviderMetadata;
|
|
57
57
|
response: {
|
|
58
58
|
timestamp: Date;
|
|
59
59
|
modelId: string;
|
|
@@ -170,7 +170,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
170
170
|
videos: responseBody.videos,
|
|
171
171
|
warnings: responseBody.warnings ?? [],
|
|
172
172
|
providerMetadata:
|
|
173
|
-
responseBody.providerMetadata as
|
|
173
|
+
responseBody.providerMetadata as SharedV4ProviderMetadata,
|
|
174
174
|
response: {
|
|
175
175
|
timestamp: new Date(),
|
|
176
176
|
modelId: this.modelId,
|
|
@@ -188,13 +188,13 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
188
188
|
|
|
189
189
|
private getModelConfigHeaders() {
|
|
190
190
|
return {
|
|
191
|
-
'ai-video-model-specification-version': '
|
|
191
|
+
'ai-video-model-specification-version': '4',
|
|
192
192
|
'ai-model-id': this.modelId,
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
function maybeEncodeVideoFile(file:
|
|
197
|
+
function maybeEncodeVideoFile(file: Experimental_VideoModelV4File) {
|
|
198
198
|
if (file.type === 'file' && file.data instanceof Uint8Array) {
|
|
199
199
|
return {
|
|
200
200
|
...file,
|