@ai-sdk/gateway 4.0.141 → 4.0.143
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 +17 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +453 -424
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/errors/create-gateway-error.ts +4 -4
- package/src/gateway-batch.ts +29 -27
- package/src/gateway-decision-model-settings.ts +3 -0
- package/src/gateway-decision-model.ts +21 -21
- package/src/gateway-embedding-model.ts +7 -7
- package/src/gateway-fetch-metadata.ts +33 -29
- package/src/gateway-generation-info.ts +13 -11
- package/src/gateway-image-model.ts +17 -16
- package/src/gateway-language-model-settings.ts +3 -1
- package/src/gateway-provider-options.ts +72 -50
- package/src/gateway-provider.ts +1 -1
- package/src/gateway-reranking-model.ts +6 -6
- package/src/gateway-speech-model.ts +8 -8
- package/src/gateway-spend-report.ts +19 -18
- package/src/gateway-transcription-model.ts +18 -18
- package/src/gateway-video-model.ts +31 -30
- package/src/tool/browserbase-fetch.ts +22 -29
- package/src/tool/browserbase-search.ts +15 -17
- package/src/tool/deepseek-fetch.ts +10 -10
- package/src/tool/deepseek-search.ts +36 -37
- package/src/tool/exa-search.ts +132 -125
- package/src/tool/gateway-tool-error.ts +8 -7
- package/src/tool/parallel-search.ts +93 -104
- package/src/tool/perplexity-search.ts +62 -85
- package/src/tool/tako-search.ts +277 -275
- package/src/zod.ts +47 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.143",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ai-sdk/provider": "4.0.37",
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.79",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"tsdown": "^0.23.0",
|
|
43
43
|
"tsx": "4.23.12",
|
|
44
44
|
"typescript": "6.0.3",
|
|
45
|
-
"zod": "
|
|
45
|
+
"zod": "4.6.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -153,11 +153,11 @@ const gatewayErrorResponseSchema = lazySchema(() =>
|
|
|
153
153
|
z.object({
|
|
154
154
|
error: z.object({
|
|
155
155
|
message: z.string(),
|
|
156
|
-
type: z.
|
|
157
|
-
param: z.
|
|
158
|
-
code: z.union([z.string(), z.number()])
|
|
156
|
+
type: z.nullish(z.string()),
|
|
157
|
+
param: z.nullish(z.unknown()),
|
|
158
|
+
code: z.nullish(z.union([z.string(), z.number()])),
|
|
159
159
|
}),
|
|
160
|
-
generationId: z.
|
|
160
|
+
generationId: z.nullish(z.string()),
|
|
161
161
|
}),
|
|
162
162
|
),
|
|
163
163
|
);
|
package/src/gateway-batch.ts
CHANGED
|
@@ -489,30 +489,31 @@ async function* convertGatewayBatchResultLines(
|
|
|
489
489
|
|
|
490
490
|
const gatewayBatchItemResultLineSchema = lazySchema(() =>
|
|
491
491
|
zodSchema(
|
|
492
|
-
z
|
|
493
|
-
.object({
|
|
492
|
+
z.catchall(
|
|
493
|
+
z.object({
|
|
494
494
|
type: z.literal('text'),
|
|
495
495
|
id: z.string(),
|
|
496
496
|
status: z.enum(['cancelled', 'expired', 'failed', 'succeeded']),
|
|
497
|
-
})
|
|
498
|
-
|
|
497
|
+
}),
|
|
498
|
+
z.unknown(),
|
|
499
|
+
),
|
|
499
500
|
),
|
|
500
501
|
);
|
|
501
502
|
|
|
502
503
|
const gatewayBatchErrorSchema = () =>
|
|
503
504
|
z.object({
|
|
504
505
|
message: z.string(),
|
|
505
|
-
type: z.
|
|
506
|
-
code: z.
|
|
507
|
-
statusCode: z.
|
|
506
|
+
type: z.nullish(z.string()),
|
|
507
|
+
code: z.nullish(z.string()),
|
|
508
|
+
statusCode: z.nullish(z.number()),
|
|
508
509
|
});
|
|
509
510
|
|
|
510
511
|
const gatewayBatchRequestCountsSchema = () =>
|
|
511
512
|
z.object({
|
|
512
|
-
total: z.
|
|
513
|
-
pending: z.
|
|
514
|
-
completed: z.
|
|
515
|
-
failed: z.
|
|
513
|
+
total: z.nullish(z.number()),
|
|
514
|
+
pending: z.nullish(z.number()),
|
|
515
|
+
completed: z.nullish(z.number()),
|
|
516
|
+
failed: z.nullish(z.number()),
|
|
516
517
|
});
|
|
517
518
|
|
|
518
519
|
const gatewayBatchProviderMetadataSchema = () =>
|
|
@@ -521,28 +522,29 @@ const gatewayBatchProviderMetadataSchema = () =>
|
|
|
521
522
|
const gatewayBatchStatusFieldsSchema = () =>
|
|
522
523
|
z.object({
|
|
523
524
|
status: z.enum(['completed', 'failed', 'pending']),
|
|
524
|
-
rawStatus: z.
|
|
525
|
-
requestCounts:
|
|
526
|
-
error:
|
|
527
|
-
createdAt: z.
|
|
528
|
-
expiresAt: z.
|
|
529
|
-
providerMetadata:
|
|
525
|
+
rawStatus: z.nullish(z.string()),
|
|
526
|
+
requestCounts: z.nullish(gatewayBatchRequestCountsSchema()),
|
|
527
|
+
error: z.nullish(gatewayBatchErrorSchema()),
|
|
528
|
+
createdAt: z.nullish(z.string()),
|
|
529
|
+
expiresAt: z.nullish(z.string()),
|
|
530
|
+
providerMetadata: z.nullish(gatewayBatchProviderMetadataSchema()),
|
|
530
531
|
});
|
|
531
532
|
|
|
532
533
|
const gatewayBatchStartResponseSchema = lazySchema(() =>
|
|
533
534
|
zodSchema(
|
|
534
|
-
gatewayBatchStatusFieldsSchema()
|
|
535
|
+
z.extend(gatewayBatchStatusFieldsSchema(), {
|
|
535
536
|
batchId: z.string(),
|
|
536
|
-
warnings: z
|
|
537
|
-
.array(
|
|
538
|
-
z
|
|
539
|
-
.object({
|
|
540
|
-
requestId: z.
|
|
537
|
+
warnings: z.nullish(
|
|
538
|
+
z.array(
|
|
539
|
+
z.catchall(
|
|
540
|
+
z.object({
|
|
541
|
+
requestId: z.nullish(z.string()),
|
|
541
542
|
warning: z.unknown(),
|
|
542
|
-
})
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
543
|
+
}),
|
|
544
|
+
z.unknown(),
|
|
545
|
+
),
|
|
546
|
+
),
|
|
547
|
+
),
|
|
546
548
|
}),
|
|
547
549
|
),
|
|
548
550
|
);
|
|
@@ -6,6 +6,9 @@ export type GatewayDecisionModelId =
|
|
|
6
6
|
| 'liquid/d1'
|
|
7
7
|
| 'liquid/d1-ultra'
|
|
8
8
|
| 'microsoft/microsoft-decision-1'
|
|
9
|
+
| 'nace-ai/drex-max-finance'
|
|
10
|
+
| 'nace-ai/drex-max-v1.1'
|
|
11
|
+
| 'nace-ai/drex-v2.0'
|
|
9
12
|
| 'openai/gpt-6-luna-decisions'
|
|
10
13
|
| 'parallel/parallel-decisions-fast'
|
|
11
14
|
| 'perplexity/pplx-decider-flash-v1.2'
|
|
@@ -140,12 +140,12 @@ const gatewayDecisionAnswerSchema = () =>
|
|
|
140
140
|
z.object({
|
|
141
141
|
type: z.literal('choice'),
|
|
142
142
|
choice: z.string(),
|
|
143
|
-
probabilities: z.record(z.string(), z.number())
|
|
143
|
+
probabilities: z.optional(z.record(z.string(), z.number())),
|
|
144
144
|
}),
|
|
145
145
|
z.object({
|
|
146
146
|
type: z.literal('score'),
|
|
147
147
|
score: z.number(),
|
|
148
|
-
probabilities: z.record(z.string(), z.number())
|
|
148
|
+
probabilities: z.optional(z.record(z.string(), z.number())),
|
|
149
149
|
}),
|
|
150
150
|
z.object({
|
|
151
151
|
type: z.literal('boolean'),
|
|
@@ -161,12 +161,12 @@ const gatewayDecisionWarningSchema = () =>
|
|
|
161
161
|
z.object({
|
|
162
162
|
type: z.literal('unsupported'),
|
|
163
163
|
feature: z.string(),
|
|
164
|
-
details: z.
|
|
164
|
+
details: z.optional(z.string()),
|
|
165
165
|
}),
|
|
166
166
|
z.object({
|
|
167
167
|
type: z.literal('compatibility'),
|
|
168
168
|
feature: z.string(),
|
|
169
|
-
details: z.
|
|
169
|
+
details: z.optional(z.string()),
|
|
170
170
|
}),
|
|
171
171
|
z.object({
|
|
172
172
|
type: z.literal('deprecated'),
|
|
@@ -183,23 +183,23 @@ const gatewayDecisionResponseSchema = lazySchema(() =>
|
|
|
183
183
|
zodSchema(
|
|
184
184
|
z.object({
|
|
185
185
|
answers: z.record(z.string(), gatewayDecisionAnswerSchema()),
|
|
186
|
-
model: z.
|
|
187
|
-
rounding: z
|
|
188
|
-
.object({
|
|
189
|
-
probabilityDecimals: z.
|
|
190
|
-
scoreDecimals: z.
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
usage: z
|
|
194
|
-
.object({
|
|
195
|
-
inputTokens: z.
|
|
196
|
-
outputTokens: z.
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
warnings: z.array(gatewayDecisionWarningSchema())
|
|
200
|
-
providerMetadata: z
|
|
201
|
-
.record(z.string(), z.record(z.string(), z.unknown()))
|
|
202
|
-
|
|
186
|
+
model: z.optional(z.string()),
|
|
187
|
+
rounding: z.optional(
|
|
188
|
+
z.object({
|
|
189
|
+
probabilityDecimals: z.optional(z.number()),
|
|
190
|
+
scoreDecimals: z.optional(z.number()),
|
|
191
|
+
}),
|
|
192
|
+
),
|
|
193
|
+
usage: z.optional(
|
|
194
|
+
z.object({
|
|
195
|
+
inputTokens: z.optional(z.number()),
|
|
196
|
+
outputTokens: z.optional(z.number()),
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
warnings: z.optional(z.array(gatewayDecisionWarningSchema())),
|
|
200
|
+
providerMetadata: z.optional(
|
|
201
|
+
z.record(z.string(), z.record(z.string(), z.unknown())),
|
|
202
|
+
),
|
|
203
203
|
}),
|
|
204
204
|
),
|
|
205
205
|
);
|
|
@@ -128,12 +128,12 @@ const gatewayEmbeddingWarningSchema = () =>
|
|
|
128
128
|
z.object({
|
|
129
129
|
type: z.literal('unsupported'),
|
|
130
130
|
feature: z.string(),
|
|
131
|
-
details: z.
|
|
131
|
+
details: z.optional(z.string()),
|
|
132
132
|
}),
|
|
133
133
|
z.object({
|
|
134
134
|
type: z.literal('compatibility'),
|
|
135
135
|
feature: z.string(),
|
|
136
|
-
details: z.
|
|
136
|
+
details: z.optional(z.string()),
|
|
137
137
|
}),
|
|
138
138
|
z.object({
|
|
139
139
|
type: z.literal('deprecated'),
|
|
@@ -150,11 +150,11 @@ const gatewayEmbeddingResponseSchema = lazySchema(() =>
|
|
|
150
150
|
zodSchema(
|
|
151
151
|
z.object({
|
|
152
152
|
embeddings: z.array(z.array(z.number())),
|
|
153
|
-
usage: z.object({ tokens: z.number() })
|
|
154
|
-
warnings: z.array(gatewayEmbeddingWarningSchema())
|
|
155
|
-
providerMetadata: z
|
|
156
|
-
.record(z.string(), z.record(z.string(), z.unknown()))
|
|
157
|
-
|
|
153
|
+
usage: z.nullish(z.object({ tokens: z.number() })),
|
|
154
|
+
warnings: z.optional(z.array(gatewayEmbeddingWarningSchema())),
|
|
155
|
+
providerMetadata: z.optional(
|
|
156
|
+
z.record(z.string(), z.record(z.string(), z.unknown())),
|
|
157
|
+
),
|
|
158
158
|
}),
|
|
159
159
|
),
|
|
160
160
|
);
|
|
@@ -112,61 +112,65 @@ function getTeamIdOrSlug(
|
|
|
112
112
|
const gatewayAvailableModelsResponseSchema = lazySchema(() =>
|
|
113
113
|
zodSchema(
|
|
114
114
|
z.object({
|
|
115
|
-
models: z
|
|
116
|
-
.array(
|
|
115
|
+
models: z.pipe(
|
|
116
|
+
z.array(
|
|
117
117
|
z.object({
|
|
118
118
|
id: z.string(),
|
|
119
119
|
name: z.string(),
|
|
120
|
-
description: z.
|
|
121
|
-
pricing: z
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.transform(
|
|
129
|
-
({ input, output, input_cache_read, input_cache_write }) => ({
|
|
130
|
-
input,
|
|
131
|
-
output,
|
|
132
|
-
...(input_cache_read
|
|
133
|
-
? { cachedInputTokens: input_cache_read }
|
|
134
|
-
: {}),
|
|
135
|
-
...(input_cache_write
|
|
136
|
-
? { cacheCreationInputTokens: input_cache_write }
|
|
137
|
-
: {}),
|
|
120
|
+
description: z.nullish(z.string()),
|
|
121
|
+
pricing: z.nullish(
|
|
122
|
+
z.pipe(
|
|
123
|
+
z.object({
|
|
124
|
+
input: z.string(),
|
|
125
|
+
output: z.string(),
|
|
126
|
+
input_cache_read: z.nullish(z.string()),
|
|
127
|
+
input_cache_write: z.nullish(z.string()),
|
|
138
128
|
}),
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
z.transform(
|
|
130
|
+
({ input, output, input_cache_read, input_cache_write }) => ({
|
|
131
|
+
input,
|
|
132
|
+
output,
|
|
133
|
+
...(input_cache_read
|
|
134
|
+
? { cachedInputTokens: input_cache_read }
|
|
135
|
+
: {}),
|
|
136
|
+
...(input_cache_write
|
|
137
|
+
? { cacheCreationInputTokens: input_cache_write }
|
|
138
|
+
: {}),
|
|
139
|
+
}),
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
),
|
|
141
143
|
specification: z.object({
|
|
142
144
|
specificationVersion: z.literal('v4'),
|
|
143
145
|
provider: z.string(),
|
|
144
146
|
modelId: z.string(),
|
|
145
147
|
}),
|
|
146
|
-
modelType: z.
|
|
148
|
+
modelType: z.nullish(z.string()),
|
|
147
149
|
}),
|
|
148
|
-
)
|
|
149
|
-
.transform(models =>
|
|
150
|
+
),
|
|
151
|
+
z.transform(models =>
|
|
150
152
|
models.filter(
|
|
151
153
|
(m): m is typeof m & { modelType?: KnownModelType | null } =>
|
|
152
154
|
m.modelType == null ||
|
|
153
155
|
KNOWN_MODEL_TYPES.includes(m.modelType as KnownModelType),
|
|
154
156
|
),
|
|
155
157
|
),
|
|
158
|
+
),
|
|
156
159
|
}),
|
|
157
160
|
),
|
|
158
161
|
);
|
|
159
162
|
|
|
160
163
|
const gatewayCreditsResponseSchema = lazySchema(() =>
|
|
161
164
|
zodSchema(
|
|
162
|
-
z
|
|
163
|
-
.object({
|
|
165
|
+
z.pipe(
|
|
166
|
+
z.object({
|
|
164
167
|
balance: z.string(),
|
|
165
168
|
total_used: z.string(),
|
|
166
|
-
})
|
|
167
|
-
.transform(({ balance, total_used }) => ({
|
|
169
|
+
}),
|
|
170
|
+
z.transform(({ balance, total_used }) => ({
|
|
168
171
|
balance,
|
|
169
172
|
totalUsed: total_used,
|
|
170
173
|
})),
|
|
174
|
+
),
|
|
171
175
|
),
|
|
172
176
|
);
|
|
@@ -95,15 +95,15 @@ export class GatewayGenerationInfoFetcher {
|
|
|
95
95
|
|
|
96
96
|
const gatewayGenerationInfoResponseSchema = lazySchema(() =>
|
|
97
97
|
zodSchema(
|
|
98
|
-
z
|
|
99
|
-
.object({
|
|
100
|
-
data: z
|
|
101
|
-
.object({
|
|
98
|
+
z.pipe(
|
|
99
|
+
z.object({
|
|
100
|
+
data: z.pipe(
|
|
101
|
+
z.object({
|
|
102
102
|
id: z.string(),
|
|
103
103
|
total_cost: z.number(),
|
|
104
|
-
market_cost: z.
|
|
105
|
-
surcharge_cost: z.
|
|
106
|
-
gateway_cost: z.
|
|
104
|
+
market_cost: z.nullish(z.number()),
|
|
105
|
+
surcharge_cost: z.nullish(z.number()),
|
|
106
|
+
gateway_cost: z.nullish(z.number()),
|
|
107
107
|
upstream_inference_cost: z.number(),
|
|
108
108
|
usage: z.number(),
|
|
109
109
|
created_at: z.string(),
|
|
@@ -120,8 +120,8 @@ const gatewayGenerationInfoResponseSchema = lazySchema(() =>
|
|
|
120
120
|
native_tokens_cached: z.number(),
|
|
121
121
|
native_tokens_cache_creation: z.number(),
|
|
122
122
|
billable_web_search_calls: z.number(),
|
|
123
|
-
})
|
|
124
|
-
.transform(
|
|
123
|
+
}),
|
|
124
|
+
z.transform(
|
|
125
125
|
({
|
|
126
126
|
total_cost,
|
|
127
127
|
market_cost,
|
|
@@ -162,7 +162,9 @@ const gatewayGenerationInfoResponseSchema = lazySchema(() =>
|
|
|
162
162
|
billableWebSearchCalls: billable_web_search_calls,
|
|
163
163
|
}),
|
|
164
164
|
),
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
),
|
|
166
|
+
}),
|
|
167
|
+
z.transform(({ data }) => data),
|
|
168
|
+
),
|
|
167
169
|
),
|
|
168
170
|
);
|
|
@@ -199,23 +199,24 @@ function toImageModelImages(
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
const providerMetadataEntrySchema = () =>
|
|
202
|
-
z
|
|
203
|
-
.object({
|
|
204
|
-
images: z.array(z.unknown())
|
|
205
|
-
})
|
|
206
|
-
|
|
202
|
+
z.catchall(
|
|
203
|
+
z.object({
|
|
204
|
+
images: z.optional(z.array(z.unknown())),
|
|
205
|
+
}),
|
|
206
|
+
z.unknown(),
|
|
207
|
+
);
|
|
207
208
|
|
|
208
209
|
const gatewayImageWarningSchema = () =>
|
|
209
210
|
z.discriminatedUnion('type', [
|
|
210
211
|
z.object({
|
|
211
212
|
type: z.literal('unsupported'),
|
|
212
213
|
feature: z.string(),
|
|
213
|
-
details: z.
|
|
214
|
+
details: z.optional(z.string()),
|
|
214
215
|
}),
|
|
215
216
|
z.object({
|
|
216
217
|
type: z.literal('compatibility'),
|
|
217
218
|
feature: z.string(),
|
|
218
|
-
details: z.
|
|
219
|
+
details: z.optional(z.string()),
|
|
219
220
|
}),
|
|
220
221
|
z.object({
|
|
221
222
|
type: z.literal('deprecated'),
|
|
@@ -230,9 +231,9 @@ const gatewayImageWarningSchema = () =>
|
|
|
230
231
|
|
|
231
232
|
const gatewayImageUsageSchema = () =>
|
|
232
233
|
z.object({
|
|
233
|
-
inputTokens: z.
|
|
234
|
-
outputTokens: z.
|
|
235
|
-
totalTokens: z.
|
|
234
|
+
inputTokens: z.nullish(z.number()),
|
|
235
|
+
outputTokens: z.nullish(z.number()),
|
|
236
|
+
totalTokens: z.nullish(z.number()),
|
|
236
237
|
});
|
|
237
238
|
|
|
238
239
|
const gatewayImageResponseSchema = lazySchema(() =>
|
|
@@ -242,12 +243,12 @@ const gatewayImageResponseSchema = lazySchema(() =>
|
|
|
242
243
|
// response is read (`experimental_binaryFields`), see
|
|
243
244
|
// `toImageModelImages`.
|
|
244
245
|
images: z.array(z.union([z.string(), z.instanceof(Uint8Array)])),
|
|
245
|
-
isRetryable: z.
|
|
246
|
-
warnings: z.array(gatewayImageWarningSchema())
|
|
247
|
-
providerMetadata: z
|
|
248
|
-
.record(z.string(), providerMetadataEntrySchema())
|
|
249
|
-
|
|
250
|
-
usage:
|
|
246
|
+
isRetryable: z.optional(z.boolean()),
|
|
247
|
+
warnings: z.optional(z.array(gatewayImageWarningSchema())),
|
|
248
|
+
providerMetadata: z.optional(
|
|
249
|
+
z.record(z.string(), providerMetadataEntrySchema()),
|
|
250
|
+
),
|
|
251
|
+
usage: z.optional(gatewayImageUsageSchema()),
|
|
251
252
|
}),
|
|
252
253
|
),
|
|
253
254
|
);
|
|
@@ -31,9 +31,10 @@ export type GatewayModelId =
|
|
|
31
31
|
| 'anthropic/claude-fable-5'
|
|
32
32
|
| 'anthropic/claude-fable-5-batch'
|
|
33
33
|
| 'anthropic/claude-fable-5.1'
|
|
34
|
-
| 'anthropic/claude-fable-5.2'
|
|
35
34
|
| 'anthropic/claude-fable-5.1-batch'
|
|
35
|
+
| 'anthropic/claude-fable-5.2'
|
|
36
36
|
| 'anthropic/claude-fable-5.2-batch'
|
|
37
|
+
| 'anthropic/claude-fable-5.2-fast'
|
|
37
38
|
| 'anthropic/claude-haiku-4.5'
|
|
38
39
|
| 'anthropic/claude-haiku-4.5-batch'
|
|
39
40
|
| 'anthropic/claude-haiku-5.5'
|
|
@@ -106,6 +107,7 @@ export type GatewayModelId =
|
|
|
106
107
|
| 'google/gemini-3.7-flash'
|
|
107
108
|
| 'google/gemini-3.8-flash'
|
|
108
109
|
| 'google/gemini-4-argon'
|
|
110
|
+
| 'google/gemini-4-carbon'
|
|
109
111
|
| 'google/gemini-nano-banana-2.1'
|
|
110
112
|
| 'google/gemini-omni-1.2-flash'
|
|
111
113
|
| 'google/gemini-omni-flash-preview'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
-
import type { ZodType } from 'zod/v4';
|
|
2
|
+
import type { ZodMiniType as ZodType } from 'zod/v4/mini';
|
|
3
3
|
import { z } from './zod';
|
|
4
4
|
|
|
5
5
|
// https://vercel.com/docs/ai-gateway/provider-options
|
|
@@ -9,11 +9,12 @@ export const DECISION_FALLBACK_MAX_QUESTION_LENGTH = 256;
|
|
|
9
9
|
|
|
10
10
|
export const gatewayDecisionProviderOptionsSchema = lazySchema(() =>
|
|
11
11
|
zodSchema(
|
|
12
|
-
z
|
|
13
|
-
.object({
|
|
14
|
-
models:
|
|
15
|
-
})
|
|
16
|
-
|
|
12
|
+
z.catchall(
|
|
13
|
+
z.object({
|
|
14
|
+
models: z.optional(gatewayModelFallbacksSchema()),
|
|
15
|
+
}),
|
|
16
|
+
z.unknown(),
|
|
17
|
+
),
|
|
17
18
|
),
|
|
18
19
|
);
|
|
19
20
|
|
|
@@ -171,29 +172,37 @@ type GatewayModelFallbackList<QUESTION_ID extends string> =
|
|
|
171
172
|
| string[]
|
|
172
173
|
| [ConditionalGatewayModelFallback<QUESTION_ID>, ...string[]];
|
|
173
174
|
|
|
174
|
-
const probabilitySchema = () =>
|
|
175
|
+
const probabilitySchema = () =>
|
|
176
|
+
z.number().check(z.minimum(0)).check(z.maximum(1));
|
|
175
177
|
const questionSchema = () =>
|
|
176
|
-
z
|
|
178
|
+
z
|
|
179
|
+
.string()
|
|
180
|
+
.check(z.minLength(1))
|
|
181
|
+
.check(z.maxLength(DECISION_FALLBACK_MAX_QUESTION_LENGTH));
|
|
177
182
|
const directConditionSchema = () =>
|
|
178
183
|
z.union([
|
|
179
|
-
z
|
|
180
|
-
.object({
|
|
181
|
-
question:
|
|
184
|
+
z.catchall(
|
|
185
|
+
z.object({
|
|
186
|
+
question: z.optional(questionSchema()),
|
|
182
187
|
confidenceBelow: probabilitySchema(),
|
|
183
|
-
})
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
}),
|
|
189
|
+
z.never(),
|
|
190
|
+
),
|
|
191
|
+
z.catchall(
|
|
192
|
+
z.object({
|
|
193
|
+
question: z.optional(questionSchema()),
|
|
188
194
|
probabilityBetween: z
|
|
189
195
|
.array(probabilitySchema())
|
|
190
|
-
.length(2)
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
.check(z.length(2))
|
|
197
|
+
.check(
|
|
198
|
+
z.refine(([minimum, maximum]) => minimum <= maximum, {
|
|
199
|
+
message:
|
|
200
|
+
'probabilityBetween minimum must be less than or equal to maximum',
|
|
201
|
+
}),
|
|
202
|
+
),
|
|
203
|
+
}),
|
|
204
|
+
z.never(),
|
|
205
|
+
),
|
|
197
206
|
]) as ZodType<DecisionFallbackCondition>;
|
|
198
207
|
|
|
199
208
|
const groupBeyondMaxDepthSchema = () =>
|
|
@@ -203,36 +212,44 @@ const groupBeyondMaxDepthSchema = () =>
|
|
|
203
212
|
z.object({ all: z.unknown() }),
|
|
204
213
|
z.object({ atLeast: z.unknown() }),
|
|
205
214
|
])
|
|
206
|
-
.
|
|
207
|
-
context.
|
|
215
|
+
.check(context => {
|
|
216
|
+
context.issues.push({
|
|
217
|
+
input: context.value,
|
|
218
|
+
continue: true,
|
|
208
219
|
code: 'custom',
|
|
209
220
|
message: `conditions can be nested at most ${DECISION_FALLBACK_MAX_CONDITION_DEPTH} levels deep`,
|
|
210
221
|
});
|
|
211
222
|
});
|
|
212
223
|
|
|
213
224
|
const conditionalModelFallbackSchema = () =>
|
|
214
|
-
z
|
|
215
|
-
.object({
|
|
216
|
-
model: z.string().
|
|
225
|
+
z.catchall(
|
|
226
|
+
z.object({
|
|
227
|
+
model: z.string().check(z.minLength(1)),
|
|
217
228
|
when: conditionSchema(1),
|
|
218
|
-
})
|
|
219
|
-
.
|
|
229
|
+
}),
|
|
230
|
+
z.never(),
|
|
231
|
+
);
|
|
220
232
|
|
|
221
233
|
const gatewayModelFallbacksSchema = () =>
|
|
222
234
|
z
|
|
223
235
|
.array(z.union([z.string(), conditionalModelFallbackSchema()]))
|
|
224
|
-
.
|
|
236
|
+
.check(context => {
|
|
237
|
+
const entries = context.value;
|
|
225
238
|
const conditionalIndexes = entries.flatMap((entry, index) =>
|
|
226
239
|
typeof entry === 'string' ? [] : [index],
|
|
227
240
|
);
|
|
228
241
|
if (conditionalIndexes.length > 1) {
|
|
229
|
-
context.
|
|
242
|
+
context.issues.push({
|
|
243
|
+
input: context.value,
|
|
244
|
+
continue: true,
|
|
230
245
|
code: 'custom',
|
|
231
246
|
message: 'models supports at most one conditional decision fallback',
|
|
232
247
|
});
|
|
233
248
|
}
|
|
234
249
|
if (conditionalIndexes[0] !== undefined && conditionalIndexes[0] !== 0) {
|
|
235
|
-
context.
|
|
250
|
+
context.issues.push({
|
|
251
|
+
input: context.value,
|
|
252
|
+
continue: true,
|
|
236
253
|
code: 'custom',
|
|
237
254
|
message:
|
|
238
255
|
'a conditional decision fallback must be the first models entry',
|
|
@@ -252,26 +269,31 @@ function conditionSchema(depth: number): ZodType<DecisionFallbackCondition> {
|
|
|
252
269
|
const childConditionSchema = conditionSchema(depth + 1);
|
|
253
270
|
const conditionListSchema = z
|
|
254
271
|
.array(childConditionSchema)
|
|
255
|
-
.
|
|
256
|
-
.
|
|
272
|
+
.check(z.minLength(1))
|
|
273
|
+
.check(z.maxLength(DECISION_FALLBACK_MAX_CONDITIONS_PER_LIST));
|
|
257
274
|
|
|
258
275
|
return z.union([
|
|
259
276
|
directConditionSchema(),
|
|
260
|
-
z.object({ any: conditionListSchema }).
|
|
261
|
-
z.object({ all: conditionListSchema }).
|
|
262
|
-
z
|
|
263
|
-
.object({
|
|
277
|
+
z.catchall(z.object({ any: conditionListSchema }), z.never()),
|
|
278
|
+
z.catchall(z.object({ all: conditionListSchema }), z.never()),
|
|
279
|
+
z.catchall(
|
|
280
|
+
z.object({
|
|
264
281
|
atLeast: z
|
|
265
|
-
.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
282
|
+
.catchall(
|
|
283
|
+
z.object({
|
|
284
|
+
count: z.number().check(z.int()).check(z.minimum(1)),
|
|
285
|
+
conditions: conditionListSchema,
|
|
286
|
+
}),
|
|
287
|
+
z.never(),
|
|
288
|
+
)
|
|
289
|
+
.check(
|
|
290
|
+
z.refine(({ count, conditions }) => count <= conditions.length, {
|
|
291
|
+
message: 'atLeast count cannot exceed the number of conditions',
|
|
292
|
+
path: ['count'],
|
|
293
|
+
}),
|
|
294
|
+
),
|
|
295
|
+
}),
|
|
296
|
+
z.never(),
|
|
297
|
+
),
|
|
276
298
|
]) as ZodType<DecisionFallbackCondition>;
|
|
277
299
|
}
|