@ai-sdk/gateway 4.0.0-beta.1 → 4.0.0-beta.108
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 +794 -4
- package/dist/index.d.ts +314 -42
- package/dist/index.js +1369 -397
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +447 -61
- package/package.json +15 -15
- package/src/errors/as-gateway-error.ts +2 -1
- package/src/errors/create-gateway-error.ts +17 -3
- package/src/errors/gateway-authentication-error.ts +8 -5
- package/src/errors/gateway-error.ts +8 -0
- package/src/errors/gateway-failed-dependency-error.ts +35 -0
- package/src/errors/gateway-forbidden-error.ts +34 -0
- package/src/errors/gateway-response-error.ts +1 -1
- package/src/errors/index.ts +2 -0
- package/src/errors/parse-auth-method.ts +1 -2
- package/src/gateway-config.ts +1 -1
- package/src/gateway-embedding-model-settings.ts +1 -0
- package/src/gateway-embedding-model.ts +62 -15
- package/src/gateway-fetch-metadata.ts +51 -38
- package/src/gateway-generation-info.ts +149 -0
- package/src/gateway-headers.ts +3 -0
- package/src/gateway-image-model-settings.ts +14 -1
- package/src/gateway-image-model.ts +46 -21
- package/src/gateway-language-model-settings.ts +52 -31
- package/src/gateway-language-model.ts +72 -42
- package/src/gateway-model-entry.ts +15 -3
- package/src/gateway-provider-options.ts +50 -78
- package/src/gateway-provider.ts +239 -35
- package/src/gateway-realtime-auth.ts +126 -0
- package/src/gateway-realtime-model-settings.ts +1 -0
- package/src/gateway-realtime-model.ts +107 -0
- package/src/gateway-reranking-model-settings.ts +7 -0
- package/src/gateway-reranking-model.ts +142 -0
- package/src/gateway-speech-model-settings.ts +1 -0
- package/src/gateway-speech-model.ts +145 -0
- package/src/gateway-spend-report.ts +193 -0
- package/src/gateway-transcription-model-settings.ts +1 -0
- package/src/gateway-transcription-model.ts +155 -0
- package/src/gateway-video-model-settings.ts +4 -0
- package/src/gateway-video-model.ts +29 -19
- package/src/index.ts +30 -5
- package/src/tool/parallel-search.ts +10 -11
- package/src/tool/perplexity-search.ts +10 -11
- package/dist/index.d.mts +0 -602
- package/dist/index.mjs +0 -1539
- package/dist/index.mjs.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
APICallError,
|
|
3
|
+
type Experimental_VideoModelV4,
|
|
4
|
+
type Experimental_VideoModelV4CallOptions,
|
|
5
|
+
type Experimental_VideoModelV4File,
|
|
6
|
+
type Experimental_VideoModelV4VideoData,
|
|
7
|
+
type SharedV4ProviderMetadata,
|
|
8
|
+
type SharedV4Warning,
|
|
8
9
|
} from '@ai-sdk/provider';
|
|
9
|
-
import { APICallError } from '@ai-sdk/provider';
|
|
10
10
|
import {
|
|
11
11
|
combineHeaders,
|
|
12
12
|
convertUint8ArrayToBase64,
|
|
@@ -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,17 +50,19 @@ 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;
|
|
60
60
|
headers: Record<string, string> | undefined;
|
|
61
61
|
};
|
|
62
62
|
}> {
|
|
63
|
-
const resolvedHeaders =
|
|
63
|
+
const resolvedHeaders = this.config.headers
|
|
64
|
+
? await resolve(this.config.headers)
|
|
65
|
+
: undefined;
|
|
64
66
|
try {
|
|
65
67
|
const { responseHeaders, value: responseBody } = await postJsonToApi({
|
|
66
68
|
url: this.getUrl(),
|
|
@@ -170,7 +172,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
170
172
|
videos: responseBody.videos,
|
|
171
173
|
warnings: responseBody.warnings ?? [],
|
|
172
174
|
providerMetadata:
|
|
173
|
-
responseBody.providerMetadata as
|
|
175
|
+
responseBody.providerMetadata as SharedV4ProviderMetadata,
|
|
174
176
|
response: {
|
|
175
177
|
timestamp: new Date(),
|
|
176
178
|
modelId: this.modelId,
|
|
@@ -178,7 +180,10 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
178
180
|
},
|
|
179
181
|
};
|
|
180
182
|
} catch (error) {
|
|
181
|
-
throw await asGatewayError(
|
|
183
|
+
throw await asGatewayError(
|
|
184
|
+
error,
|
|
185
|
+
await parseAuthMethod(resolvedHeaders ?? {}),
|
|
186
|
+
);
|
|
182
187
|
}
|
|
183
188
|
}
|
|
184
189
|
|
|
@@ -188,13 +193,13 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
|
|
|
188
193
|
|
|
189
194
|
private getModelConfigHeaders() {
|
|
190
195
|
return {
|
|
191
|
-
'ai-video-model-specification-version': '
|
|
196
|
+
'ai-video-model-specification-version': '4',
|
|
192
197
|
'ai-model-id': this.modelId,
|
|
193
198
|
};
|
|
194
199
|
}
|
|
195
200
|
}
|
|
196
201
|
|
|
197
|
-
function maybeEncodeVideoFile(file:
|
|
202
|
+
function maybeEncodeVideoFile(file: Experimental_VideoModelV4File) {
|
|
198
203
|
if (file.type === 'file' && file.data instanceof Uint8Array) {
|
|
199
204
|
return {
|
|
200
205
|
...file,
|
|
@@ -234,6 +239,11 @@ const gatewayVideoWarningSchema = z.discriminatedUnion('type', [
|
|
|
234
239
|
feature: z.string(),
|
|
235
240
|
details: z.string().optional(),
|
|
236
241
|
}),
|
|
242
|
+
z.object({
|
|
243
|
+
type: z.literal('deprecated'),
|
|
244
|
+
setting: z.string(),
|
|
245
|
+
message: z.string(),
|
|
246
|
+
}),
|
|
237
247
|
z.object({
|
|
238
248
|
type: z.literal('other'),
|
|
239
249
|
message: z.string(),
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
export type { GatewayModelId } from './gateway-language-model-settings';
|
|
2
|
+
export {
|
|
3
|
+
GATEWAY_AUTH_SUBPROTOCOL_PREFIX,
|
|
4
|
+
GATEWAY_REALTIME_SUBPROTOCOL,
|
|
5
|
+
GATEWAY_TEAM_SUBPROTOCOL_PREFIX,
|
|
6
|
+
getGatewayRealtimeAuthToken,
|
|
7
|
+
getGatewayRealtimeProtocols,
|
|
8
|
+
getGatewayRealtimeTeamIdOrSlug,
|
|
9
|
+
} from './gateway-realtime-auth';
|
|
10
|
+
export type { GatewayRealtimeModelId } from './gateway-realtime-model-settings';
|
|
11
|
+
export type { GatewayRerankingModelId } from './gateway-reranking-model-settings';
|
|
12
|
+
export type { GatewaySpeechModelId } from './gateway-speech-model-settings';
|
|
13
|
+
export type { GatewayTranscriptionModelId } from './gateway-transcription-model-settings';
|
|
2
14
|
export type { GatewayVideoModelId } from './gateway-video-model-settings';
|
|
3
15
|
export type {
|
|
4
16
|
GatewayLanguageModelEntry,
|
|
5
17
|
GatewayLanguageModelSpecification,
|
|
6
18
|
} from './gateway-model-entry';
|
|
7
19
|
export type { GatewayCreditsResponse } from './gateway-fetch-metadata';
|
|
20
|
+
export type {
|
|
21
|
+
GatewaySpendReportParams,
|
|
22
|
+
GatewaySpendReportRow,
|
|
23
|
+
GatewaySpendReportResponse,
|
|
24
|
+
} from './gateway-spend-report';
|
|
25
|
+
export type {
|
|
26
|
+
GatewayGenerationInfoParams,
|
|
27
|
+
GatewayGenerationInfo,
|
|
28
|
+
} from './gateway-generation-info';
|
|
8
29
|
export type { GatewayLanguageModelEntry as GatewayModelEntry } from './gateway-model-entry';
|
|
9
30
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
createGateway,
|
|
32
|
+
/** @deprecated Use `createGateway` instead. */
|
|
33
|
+
createGateway as createGatewayProvider,
|
|
12
34
|
gateway,
|
|
13
35
|
} from './gateway-provider';
|
|
14
36
|
export type {
|
|
@@ -16,13 +38,15 @@ export type {
|
|
|
16
38
|
GatewayProviderSettings,
|
|
17
39
|
} from './gateway-provider';
|
|
18
40
|
export type {
|
|
19
|
-
|
|
20
|
-
/** @deprecated Use `
|
|
21
|
-
|
|
41
|
+
GatewayProviderOptions,
|
|
42
|
+
/** @deprecated Use `GatewayProviderOptions` instead. */
|
|
43
|
+
GatewayProviderOptions as GatewayLanguageModelOptions,
|
|
22
44
|
} from './gateway-provider-options';
|
|
23
45
|
export {
|
|
24
46
|
GatewayError,
|
|
25
47
|
GatewayAuthenticationError,
|
|
48
|
+
GatewayFailedDependencyError,
|
|
49
|
+
GatewayForbiddenError,
|
|
26
50
|
GatewayInvalidRequestError,
|
|
27
51
|
GatewayRateLimitError,
|
|
28
52
|
GatewayModelNotFoundError,
|
|
@@ -30,3 +54,4 @@ export {
|
|
|
30
54
|
GatewayResponseError,
|
|
31
55
|
} from './errors';
|
|
32
56
|
export type { GatewayErrorResponse } from './errors';
|
|
57
|
+
export { VERSION } from './version';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -278,16 +278,15 @@ const parallelSearchOutputSchema = lazySchema(() =>
|
|
|
278
278
|
),
|
|
279
279
|
);
|
|
280
280
|
|
|
281
|
-
export const parallelSearchToolFactory =
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
});
|
|
281
|
+
export const parallelSearchToolFactory = createProviderExecutedToolFactory<
|
|
282
|
+
ParallelSearchInput,
|
|
283
|
+
ParallelSearchOutput,
|
|
284
|
+
ParallelSearchConfig
|
|
285
|
+
>({
|
|
286
|
+
id: 'gateway.parallel_search',
|
|
287
|
+
inputSchema: parallelSearchInputSchema,
|
|
288
|
+
outputSchema: parallelSearchOutputSchema,
|
|
289
|
+
});
|
|
291
290
|
|
|
292
291
|
export const parallelSearch = (
|
|
293
292
|
config: ParallelSearchConfig = {},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -277,16 +277,15 @@ const perplexitySearchOutputSchema = lazySchema(() =>
|
|
|
277
277
|
),
|
|
278
278
|
);
|
|
279
279
|
|
|
280
|
-
export const perplexitySearchToolFactory =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
});
|
|
280
|
+
export const perplexitySearchToolFactory = createProviderExecutedToolFactory<
|
|
281
|
+
PerplexitySearchInput,
|
|
282
|
+
PerplexitySearchOutput,
|
|
283
|
+
PerplexitySearchConfig
|
|
284
|
+
>({
|
|
285
|
+
id: 'gateway.perplexity_search',
|
|
286
|
+
inputSchema: perplexitySearchInputSchema,
|
|
287
|
+
outputSchema: perplexitySearchOutputSchema,
|
|
288
|
+
});
|
|
290
289
|
|
|
291
290
|
export const perplexitySearch = (
|
|
292
291
|
config: PerplexitySearchConfig = {},
|