@ai-sdk/gateway 3.0.130 → 3.0.132
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 +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +104 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/errors/create-gateway-error.ts +8 -0
- package/src/errors/gateway-forbidden-error.ts +34 -0
- package/src/errors/index.ts +1 -0
- package/src/gateway-embedding-model.ts +19 -1
- package/src/gateway-language-model-settings.ts +1 -1
- package/src/gateway-reranking-model.ts +19 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from './gateway-model-not-found-error';
|
|
10
10
|
import { GatewayInternalServerError } from './gateway-internal-server-error';
|
|
11
11
|
import { GatewayFailedDependencyError } from './gateway-failed-dependency-error';
|
|
12
|
+
import { GatewayForbiddenError } from './gateway-forbidden-error';
|
|
12
13
|
import { GatewayResponseError } from './gateway-response-error';
|
|
13
14
|
import {
|
|
14
15
|
lazySchema,
|
|
@@ -111,6 +112,13 @@ export async function createGatewayErrorFromResponse({
|
|
|
111
112
|
cause,
|
|
112
113
|
generationId,
|
|
113
114
|
});
|
|
115
|
+
case 'forbidden':
|
|
116
|
+
return new GatewayForbiddenError({
|
|
117
|
+
message,
|
|
118
|
+
statusCode,
|
|
119
|
+
cause,
|
|
120
|
+
generationId,
|
|
121
|
+
});
|
|
114
122
|
default:
|
|
115
123
|
return new GatewayInternalServerError({
|
|
116
124
|
message,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GatewayError } from './gateway-error';
|
|
2
|
+
|
|
3
|
+
const name = 'GatewayForbiddenError';
|
|
4
|
+
const marker = `vercel.ai.gateway.error.${name}`;
|
|
5
|
+
const symbol = Symbol.for(marker);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Forbidden - the request was rejected by policy (e.g. a routing rule),
|
|
9
|
+
* not an authentication failure.
|
|
10
|
+
*/
|
|
11
|
+
export class GatewayForbiddenError extends GatewayError {
|
|
12
|
+
private readonly [symbol] = true; // used in isInstance
|
|
13
|
+
|
|
14
|
+
readonly name = name;
|
|
15
|
+
readonly type = 'forbidden';
|
|
16
|
+
|
|
17
|
+
constructor({
|
|
18
|
+
message = 'Forbidden',
|
|
19
|
+
statusCode = 403,
|
|
20
|
+
cause,
|
|
21
|
+
generationId,
|
|
22
|
+
}: {
|
|
23
|
+
message?: string;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
generationId?: string;
|
|
27
|
+
} = {}) {
|
|
28
|
+
super({ message, statusCode, cause, generationId });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static isInstance(error: unknown): error is GatewayForbiddenError {
|
|
32
|
+
return GatewayError.hasMarker(error) && symbol in error;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/errors/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { extractApiCallResponse } from './extract-api-call-response';
|
|
|
7
7
|
export { GatewayError } from './gateway-error';
|
|
8
8
|
export { GatewayAuthenticationError } from './gateway-authentication-error';
|
|
9
9
|
export { GatewayFailedDependencyError } from './gateway-failed-dependency-error';
|
|
10
|
+
export { GatewayForbiddenError } from './gateway-forbidden-error';
|
|
10
11
|
export { GatewayInternalServerError } from './gateway-internal-server-error';
|
|
11
12
|
export { GatewayInvalidRequestError } from './gateway-invalid-request-error';
|
|
12
13
|
export {
|
|
@@ -77,7 +77,7 @@ export class GatewayEmbeddingModel implements EmbeddingModelV3 {
|
|
|
77
77
|
providerMetadata:
|
|
78
78
|
responseBody.providerMetadata as unknown as SharedV3ProviderMetadata,
|
|
79
79
|
response: { headers: responseHeaders, body: rawValue },
|
|
80
|
-
warnings: [],
|
|
80
|
+
warnings: responseBody.warnings ?? [],
|
|
81
81
|
};
|
|
82
82
|
} catch (error) {
|
|
83
83
|
throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
|
|
@@ -96,11 +96,29 @@ export class GatewayEmbeddingModel implements EmbeddingModelV3 {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
const gatewayEmbeddingWarningSchema = z.discriminatedUnion('type', [
|
|
100
|
+
z.object({
|
|
101
|
+
type: z.literal('unsupported'),
|
|
102
|
+
feature: z.string(),
|
|
103
|
+
details: z.string().optional(),
|
|
104
|
+
}),
|
|
105
|
+
z.object({
|
|
106
|
+
type: z.literal('compatibility'),
|
|
107
|
+
feature: z.string(),
|
|
108
|
+
details: z.string().optional(),
|
|
109
|
+
}),
|
|
110
|
+
z.object({
|
|
111
|
+
type: z.literal('other'),
|
|
112
|
+
message: z.string(),
|
|
113
|
+
}),
|
|
114
|
+
]);
|
|
115
|
+
|
|
99
116
|
const gatewayEmbeddingResponseSchema = lazySchema(() =>
|
|
100
117
|
zodSchema(
|
|
101
118
|
z.object({
|
|
102
119
|
embeddings: z.array(z.array(z.number())),
|
|
103
120
|
usage: z.object({ tokens: z.number() }).nullish(),
|
|
121
|
+
warnings: z.array(gatewayEmbeddingWarningSchema).optional(),
|
|
104
122
|
providerMetadata: z
|
|
105
123
|
.record(z.string(), z.record(z.string(), z.unknown()))
|
|
106
124
|
.optional(),
|
|
@@ -29,7 +29,6 @@ export type GatewayModelId =
|
|
|
29
29
|
| 'amazon/nova-pro'
|
|
30
30
|
| 'anthropic/claude-3-haiku'
|
|
31
31
|
| 'anthropic/claude-3.5-haiku'
|
|
32
|
-
| 'anthropic/claude-fable-5'
|
|
33
32
|
| 'anthropic/claude-haiku-4.5'
|
|
34
33
|
| 'anthropic/claude-opus-4'
|
|
35
34
|
| 'anthropic/claude-opus-4.1'
|
|
@@ -114,6 +113,7 @@ export type GatewayModelId =
|
|
|
114
113
|
| 'moonshotai/kimi-k2.5'
|
|
115
114
|
| 'moonshotai/kimi-k2.6'
|
|
116
115
|
| 'moonshotai/kimi-k2.7-code'
|
|
116
|
+
| 'moonshotai/kimi-k2.7-code-highspeed'
|
|
117
117
|
| 'morph/morph-v3-fast'
|
|
118
118
|
| 'morph/morph-v3-large'
|
|
119
119
|
| 'nvidia/nemotron-3-nano-30b-a3b'
|
|
@@ -78,7 +78,7 @@ export class GatewayRerankingModel implements RerankingModelV3 {
|
|
|
78
78
|
providerMetadata:
|
|
79
79
|
responseBody.providerMetadata as unknown as SharedV3ProviderMetadata,
|
|
80
80
|
response: { headers: responseHeaders, body: rawValue },
|
|
81
|
-
warnings: [],
|
|
81
|
+
warnings: responseBody.warnings ?? [],
|
|
82
82
|
};
|
|
83
83
|
} catch (error) {
|
|
84
84
|
throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
|
|
@@ -97,6 +97,23 @@ export class GatewayRerankingModel implements RerankingModelV3 {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
const gatewayRerankingWarningSchema = z.discriminatedUnion('type', [
|
|
101
|
+
z.object({
|
|
102
|
+
type: z.literal('unsupported'),
|
|
103
|
+
feature: z.string(),
|
|
104
|
+
details: z.string().optional(),
|
|
105
|
+
}),
|
|
106
|
+
z.object({
|
|
107
|
+
type: z.literal('compatibility'),
|
|
108
|
+
feature: z.string(),
|
|
109
|
+
details: z.string().optional(),
|
|
110
|
+
}),
|
|
111
|
+
z.object({
|
|
112
|
+
type: z.literal('other'),
|
|
113
|
+
message: z.string(),
|
|
114
|
+
}),
|
|
115
|
+
]);
|
|
116
|
+
|
|
100
117
|
const gatewayRerankingResponseSchema = lazySchema(() =>
|
|
101
118
|
zodSchema(
|
|
102
119
|
z.object({
|
|
@@ -106,6 +123,7 @@ const gatewayRerankingResponseSchema = lazySchema(() =>
|
|
|
106
123
|
relevanceScore: z.number(),
|
|
107
124
|
}),
|
|
108
125
|
),
|
|
126
|
+
warnings: z.array(gatewayRerankingWarningSchema).optional(),
|
|
109
127
|
providerMetadata: z
|
|
110
128
|
.record(z.string(), z.record(z.string(), z.unknown()))
|
|
111
129
|
.optional(),
|