@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.
@@ -108,12 +108,12 @@ const gatewayRerankingWarningSchema = () =>
108
108
  z.object({
109
109
  type: z.literal('unsupported'),
110
110
  feature: z.string(),
111
- details: z.string().optional(),
111
+ details: z.optional(z.string()),
112
112
  }),
113
113
  z.object({
114
114
  type: z.literal('compatibility'),
115
115
  feature: z.string(),
116
- details: z.string().optional(),
116
+ details: z.optional(z.string()),
117
117
  }),
118
118
  z.object({
119
119
  type: z.literal('deprecated'),
@@ -135,10 +135,10 @@ const gatewayRerankingResponseSchema = lazySchema(() =>
135
135
  relevanceScore: z.number(),
136
136
  }),
137
137
  ),
138
- warnings: z.array(gatewayRerankingWarningSchema()).optional(),
139
- providerMetadata: z
140
- .record(z.string(), z.record(z.string(), z.unknown()))
141
- .optional(),
138
+ warnings: z.optional(z.array(gatewayRerankingWarningSchema())),
139
+ providerMetadata: z.optional(
140
+ z.record(z.string(), z.record(z.string(), z.unknown())),
141
+ ),
142
142
  }),
143
143
  ),
144
144
  );
@@ -420,19 +420,19 @@ function createGatewaySpeechStream({
420
420
  });
421
421
  }
422
422
 
423
- const providerMetadataEntrySchema = () => z.object({}).catchall(z.unknown());
423
+ const providerMetadataEntrySchema = () => z.catchall(z.object({}), z.unknown());
424
424
 
425
425
  const gatewaySpeechWarningSchema = () =>
426
426
  z.discriminatedUnion('type', [
427
427
  z.object({
428
428
  type: z.literal('unsupported'),
429
429
  feature: z.string(),
430
- details: z.string().optional(),
430
+ details: z.optional(z.string()),
431
431
  }),
432
432
  z.object({
433
433
  type: z.literal('compatibility'),
434
434
  feature: z.string(),
435
- details: z.string().optional(),
435
+ details: z.optional(z.string()),
436
436
  }),
437
437
  z.object({
438
438
  type: z.literal('deprecated'),
@@ -449,11 +449,11 @@ const gatewaySpeechResponseSchema = lazySchema(() =>
449
449
  zodSchema(
450
450
  z.object({
451
451
  audio: z.string(),
452
- warnings: z.array(gatewaySpeechWarningSchema()).optional(),
453
- usage: z.record(z.string(), z.json()).optional(),
454
- providerMetadata: z
455
- .record(z.string(), providerMetadataEntrySchema())
456
- .optional(),
452
+ warnings: z.optional(z.array(gatewaySpeechWarningSchema())),
453
+ usage: z.optional(z.record(z.string(), z.json())),
454
+ providerMetadata: z.optional(
455
+ z.record(z.string(), providerMetadataEntrySchema()),
456
+ ),
457
457
  }),
458
458
  ),
459
459
  );
@@ -132,25 +132,25 @@ const gatewaySpendReportResponseSchema = lazySchema(() =>
132
132
  zodSchema(
133
133
  z.object({
134
134
  results: z.array(
135
- z
136
- .object({
137
- day: z.string().optional(),
138
- hour: z.string().optional(),
139
- user: z.string().optional(),
140
- model: z.string().optional(),
141
- tag: z.string().optional(),
142
- provider: z.string().optional(),
143
- credential_type: z.enum(['byok', 'system']).optional(),
135
+ z.pipe(
136
+ z.object({
137
+ day: z.optional(z.string()),
138
+ hour: z.optional(z.string()),
139
+ user: z.optional(z.string()),
140
+ model: z.optional(z.string()),
141
+ tag: z.optional(z.string()),
142
+ provider: z.optional(z.string()),
143
+ credential_type: z.optional(z.enum(['byok', 'system'])),
144
144
  total_cost: z.number(),
145
- market_cost: z.number().optional(),
146
- input_tokens: z.number().optional(),
147
- output_tokens: z.number().optional(),
148
- cached_input_tokens: z.number().optional(),
149
- cache_creation_input_tokens: z.number().optional(),
150
- reasoning_tokens: z.number().optional(),
151
- request_count: z.number().optional(),
152
- })
153
- .transform(
145
+ market_cost: z.optional(z.number()),
146
+ input_tokens: z.optional(z.number()),
147
+ output_tokens: z.optional(z.number()),
148
+ cached_input_tokens: z.optional(z.number()),
149
+ cache_creation_input_tokens: z.optional(z.number()),
150
+ reasoning_tokens: z.optional(z.number()),
151
+ request_count: z.optional(z.number()),
152
+ }),
153
+ z.transform(
154
154
  ({
155
155
  credential_type,
156
156
  total_cost,
@@ -189,6 +189,7 @@ const gatewaySpendReportResponseSchema = lazySchema(() =>
189
189
  : {}),
190
190
  }),
191
191
  ),
192
+ ),
192
193
  ),
193
194
  }),
194
195
  ),
@@ -469,19 +469,19 @@ function createGatewayTranscriptionStream({
469
469
  });
470
470
  }
471
471
 
472
- const providerMetadataEntrySchema = () => z.object({}).catchall(z.unknown());
472
+ const providerMetadataEntrySchema = () => z.catchall(z.object({}), z.unknown());
473
473
 
474
474
  const gatewayTranscriptionWarningSchema = () =>
475
475
  z.discriminatedUnion('type', [
476
476
  z.object({
477
477
  type: z.literal('unsupported'),
478
478
  feature: z.string(),
479
- details: z.string().optional(),
479
+ details: z.optional(z.string()),
480
480
  }),
481
481
  z.object({
482
482
  type: z.literal('compatibility'),
483
483
  feature: z.string(),
484
- details: z.string().optional(),
484
+ details: z.optional(z.string()),
485
485
  }),
486
486
  z.object({
487
487
  type: z.literal('deprecated'),
@@ -498,31 +498,31 @@ const gatewayTranscriptionResponseSchema = lazySchema(() =>
498
498
  zodSchema(
499
499
  z.object({
500
500
  text: z.string(),
501
- segments: z
502
- .array(
501
+ segments: z.optional(
502
+ z.array(
503
503
  z.object({
504
504
  text: z.string(),
505
505
  startSecond: z.number(),
506
506
  endSecond: z.number(),
507
507
  }),
508
- )
509
- .optional(),
510
- words: z
511
- .array(
508
+ ),
509
+ ),
510
+ words: z.nullish(
511
+ z.array(
512
512
  z.object({
513
513
  text: z.string(),
514
514
  startSecond: z.number(),
515
515
  endSecond: z.number(),
516
516
  }),
517
- )
518
- .nullish(),
519
- language: z.string().nullish(),
520
- durationInSeconds: z.number().nullish(),
521
- warnings: z.array(gatewayTranscriptionWarningSchema()).optional(),
522
- usage: z.record(z.string(), z.json()).optional(),
523
- providerMetadata: z
524
- .record(z.string(), providerMetadataEntrySchema())
525
- .optional(),
517
+ ),
518
+ ),
519
+ language: z.nullish(z.string()),
520
+ durationInSeconds: z.nullish(z.number()),
521
+ warnings: z.optional(z.array(gatewayTranscriptionWarningSchema())),
522
+ usage: z.optional(z.record(z.string(), z.json())),
523
+ providerMetadata: z.optional(
524
+ z.record(z.string(), providerMetadataEntrySchema()),
525
+ ),
526
526
  }),
527
527
  ),
528
528
  );
@@ -403,11 +403,12 @@ function maybeEncodeVideoFile(file: VideoModelV4File) {
403
403
  }
404
404
 
405
405
  const providerMetadataEntrySchema = () =>
406
- z
407
- .object({
408
- videos: z.array(z.unknown()).optional(),
409
- })
410
- .catchall(z.unknown());
406
+ z.catchall(
407
+ z.object({
408
+ videos: z.optional(z.array(z.unknown())),
409
+ }),
410
+ z.unknown(),
411
+ );
411
412
 
412
413
  const gatewayVideoDataSchema = () =>
413
414
  z.union([
@@ -432,12 +433,12 @@ const gatewayVideoWarningSchema = () =>
432
433
  z.object({
433
434
  type: z.literal('unsupported'),
434
435
  feature: z.string(),
435
- details: z.string().optional(),
436
+ details: z.optional(z.string()),
436
437
  }),
437
438
  z.object({
438
439
  type: z.literal('compatibility'),
439
440
  feature: z.string(),
440
- details: z.string().optional(),
441
+ details: z.optional(z.string()),
441
442
  }),
442
443
  z.object({
443
444
  type: z.literal('deprecated'),
@@ -456,17 +457,17 @@ const gatewayVideoEventSchema = lazySchema(() =>
456
457
  z.object({
457
458
  type: z.literal('result'),
458
459
  videos: z.array(gatewayVideoDataSchema()),
459
- warnings: z.array(gatewayVideoWarningSchema()).optional(),
460
- providerMetadata: z
461
- .record(z.string(), providerMetadataEntrySchema())
462
- .optional(),
460
+ warnings: z.optional(z.array(gatewayVideoWarningSchema())),
461
+ providerMetadata: z.optional(
462
+ z.record(z.string(), providerMetadataEntrySchema()),
463
+ ),
463
464
  }),
464
465
  z.object({
465
466
  type: z.literal('error'),
466
467
  message: z.string(),
467
468
  errorType: z.string(),
468
469
  statusCode: z.number(),
469
- param: z.unknown().nullable(),
470
+ param: z.nullable(z.unknown()),
470
471
  }),
471
472
  ]),
472
473
  ),
@@ -476,10 +477,10 @@ const gatewayVideoStartResponseSchema = lazySchema(() =>
476
477
  zodSchema(
477
478
  z.object({
478
479
  operation: z.unknown(),
479
- warnings: z.array(gatewayVideoWarningSchema()).nullish(),
480
- providerMetadata: z
481
- .record(z.string(), providerMetadataEntrySchema())
482
- .nullish(),
480
+ warnings: z.nullish(z.array(gatewayVideoWarningSchema())),
481
+ providerMetadata: z.nullish(
482
+ z.record(z.string(), providerMetadataEntrySchema()),
483
+ ),
483
484
  }),
484
485
  ),
485
486
  );
@@ -489,31 +490,31 @@ const gatewayVideoStatusResponseSchema = lazySchema(() =>
489
490
  z.discriminatedUnion('status', [
490
491
  z.object({
491
492
  status: z.literal('pending'),
492
- warnings: z.array(gatewayVideoWarningSchema()).nullish(),
493
- providerMetadata: z
494
- .record(z.string(), providerMetadataEntrySchema())
495
- .nullish(),
493
+ warnings: z.nullish(z.array(gatewayVideoWarningSchema())),
494
+ providerMetadata: z.nullish(
495
+ z.record(z.string(), providerMetadataEntrySchema()),
496
+ ),
496
497
  }),
497
498
  z.object({
498
499
  status: z.literal('completed'),
499
500
  videos: z.array(gatewayVideoDataSchema()),
500
- warnings: z.array(gatewayVideoWarningSchema()).nullish(),
501
- providerMetadata: z
502
- .record(z.string(), providerMetadataEntrySchema())
503
- .nullish(),
501
+ warnings: z.nullish(z.array(gatewayVideoWarningSchema())),
502
+ providerMetadata: z.nullish(
503
+ z.record(z.string(), providerMetadataEntrySchema()),
504
+ ),
504
505
  }),
505
506
  z.object({
506
507
  status: z.literal('error'),
507
508
  error: z.string(),
508
- providerMetadata: z
509
- .record(z.string(), providerMetadataEntrySchema())
510
- .nullish(),
509
+ providerMetadata: z.nullish(
510
+ z.record(z.string(), providerMetadataEntrySchema()),
511
+ ),
511
512
  }),
512
513
  z.object({
513
514
  status: z.literal('cancelled'),
514
- providerMetadata: z
515
- .record(z.string(), providerMetadataEntrySchema())
516
- .nullish(),
515
+ providerMetadata: z.nullish(
516
+ z.record(z.string(), providerMetadataEntrySchema()),
517
+ ),
517
518
  }),
518
519
  ]),
519
520
  ),
@@ -81,34 +81,27 @@ const jsonObjectSchema = () => z.record(z.string(), z.unknown());
81
81
  const browserbaseFetchInputSchema = lazySchema(() =>
82
82
  zodSchema(
83
83
  z.object({
84
- url: z.string().url().describe('URL of the page to fetch.'),
85
- allow_redirects: z
86
- .boolean()
87
- .optional()
88
- .describe('Whether to follow HTTP redirects (default: false).'),
89
- allow_insecure_ssl: z
90
- .boolean()
91
- .optional()
92
- .describe(
93
- 'Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts.',
94
- ),
95
- proxies: z
96
- .boolean()
97
- .optional()
98
- .describe(
99
- 'Whether to route the request through Browserbase proxies (default: false).',
100
- ),
101
- format: z
102
- .enum(['raw', 'json', 'markdown'])
103
- .optional()
104
- .describe(
105
- 'Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema.',
106
- ),
107
- schema: jsonObjectSchema()
108
- .optional()
109
- .describe(
110
- 'JSON Schema for structured extraction. Only use with format set to json.',
111
- ),
84
+ url: z.describe(z.url(), 'URL of the page to fetch.'),
85
+ allow_redirects: z.describe(
86
+ z.optional(z.boolean()),
87
+ 'Whether to follow HTTP redirects (default: false).',
88
+ ),
89
+ allow_insecure_ssl: z.describe(
90
+ z.optional(z.boolean()),
91
+ 'Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts.',
92
+ ),
93
+ proxies: z.describe(
94
+ z.optional(z.boolean()),
95
+ 'Whether to route the request through Browserbase proxies (default: false).',
96
+ ),
97
+ format: z.describe(
98
+ z.optional(z.enum(['raw', 'json', 'markdown'])),
99
+ 'Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema.',
100
+ ),
101
+ schema: z.describe(
102
+ z.optional(jsonObjectSchema()),
103
+ 'JSON Schema for structured extraction. Only use with format set to json.',
104
+ ),
112
105
  }),
113
106
  ),
114
107
  );
@@ -134,7 +127,7 @@ const browserbaseFetchOutputSchema = lazySchema(() =>
134
127
  'timeout',
135
128
  'unknown',
136
129
  ]),
137
- statusCode: z.number().optional(),
130
+ statusCode: z.optional(z.number()),
138
131
  message: z.string(),
139
132
  }),
140
133
  ]),
@@ -70,18 +70,16 @@ export type BrowserbaseSearchOutput =
70
70
  const browserbaseSearchInputSchema = lazySchema(() =>
71
71
  zodSchema(
72
72
  z.object({
73
- query: z
74
- .string()
75
- .min(1)
76
- .max(200)
77
- .describe('Web search query. Must be between 1 and 200 characters.'),
78
- num_results: z
79
- .number()
80
- .int()
81
- .min(1)
82
- .max(25)
83
- .optional()
84
- .describe('Maximum number of results to return (1-25, default: 10).'),
73
+ query: z.describe(
74
+ z.string().check(z.minLength(1)).check(z.maxLength(200)),
75
+ 'Web search query. Must be between 1 and 200 characters.',
76
+ ),
77
+ num_results: z.describe(
78
+ z.optional(
79
+ z.number().check(z.int()).check(z.minimum(1)).check(z.maximum(25)),
80
+ ),
81
+ 'Maximum number of results to return (1-25, default: 10).',
82
+ ),
85
83
  }),
86
84
  ),
87
85
  );
@@ -97,10 +95,10 @@ const browserbaseSearchOutputSchema = lazySchema(() =>
97
95
  id: z.string(),
98
96
  title: z.string(),
99
97
  url: z.string(),
100
- author: z.string().optional(),
101
- favicon: z.string().optional(),
102
- image: z.string().optional(),
103
- publishedDate: z.string().optional(),
98
+ author: z.optional(z.string()),
99
+ favicon: z.optional(z.string()),
100
+ image: z.optional(z.string()),
101
+ publishedDate: z.optional(z.string()),
104
102
  }),
105
103
  ),
106
104
  }),
@@ -114,7 +112,7 @@ const browserbaseSearchOutputSchema = lazySchema(() =>
114
112
  'timeout',
115
113
  'unknown',
116
114
  ]),
117
- statusCode: z.number().optional(),
115
+ statusCode: z.optional(z.number()),
118
116
  message: z.string(),
119
117
  }),
120
118
  ]),
@@ -29,11 +29,10 @@ export type DeepSeekFetchOutput = DeepSeekFetchResponse | GatewayToolError;
29
29
  const deepseekFetchInputSchema = lazySchema(() =>
30
30
  zodSchema(
31
31
  z.object({
32
- url: z
33
- .string()
34
- .describe(
35
- 'URL to fetch, at most 8192 characters; HTTP(S) only, without a username or password.',
36
- ),
32
+ url: z.describe(
33
+ z.string(),
34
+ 'URL to fetch, at most 8192 characters; HTTP(S) only, without a username or password.',
35
+ ),
37
36
  }),
38
37
  ),
39
38
  );
@@ -41,12 +40,13 @@ const deepseekFetchInputSchema = lazySchema(() =>
41
40
  const deepseekFetchOutputSchema = lazySchema(() =>
42
41
  zodSchema(
43
42
  z.union([
44
- z
45
- .object({
46
- title: z.string().nullish(),
43
+ z.catchall(
44
+ z.object({
45
+ title: z.nullish(z.string()),
47
46
  content: z.string(),
48
- })
49
- .passthrough(),
47
+ }),
48
+ z.unknown(),
49
+ ),
50
50
  gatewayToolErrorSchema(),
51
51
  ]),
52
52
  ),
@@ -51,25 +51,22 @@ export type DeepSeekSearchOutput = DeepSeekSearchResponse | GatewayToolError;
51
51
  const deepseekSearchInputSchema = lazySchema(() =>
52
52
  zodSchema(
53
53
  z.object({
54
- query: z
55
- .string()
56
- .describe(
57
- 'Web search query, 1 to 128 Unicode characters. Supports site:, -site:, lang:, after:, before:, and quoted phrases.',
58
- ),
59
- count: z
60
- .number()
61
- .int()
62
- .optional()
63
- .describe('Number of results, 1 to 50 (default: 10).'),
64
- need_content: z
65
- .boolean()
66
- .optional()
67
- .describe('Include available page content (default: false).'),
68
- ori_question: z
69
- .string()
70
- .nullable()
71
- .optional()
72
- .describe('Original user question, 1 to 128 Unicode characters.'),
54
+ query: z.describe(
55
+ z.string(),
56
+ 'Web search query, 1 to 128 Unicode characters. Supports site:, -site:, lang:, after:, before:, and quoted phrases.',
57
+ ),
58
+ count: z.describe(
59
+ z.optional(z.number().check(z.int())),
60
+ 'Number of results, 1 to 50 (default: 10).',
61
+ ),
62
+ need_content: z.describe(
63
+ z.optional(z.boolean()),
64
+ 'Include available page content (default: false).',
65
+ ),
66
+ ori_question: z.describe(
67
+ z.optional(z.nullable(z.string())),
68
+ 'Original user question, 1 to 128 Unicode characters.',
69
+ ),
73
70
  }),
74
71
  ),
75
72
  );
@@ -77,26 +74,28 @@ const deepseekSearchInputSchema = lazySchema(() =>
77
74
  const deepseekSearchOutputSchema = lazySchema(() =>
78
75
  zodSchema(
79
76
  z.union([
80
- z
81
- .object({
77
+ z.catchall(
78
+ z.object({
82
79
  results: z.array(
83
- z
84
- .object({
85
- authority: z.number().nullish(),
86
- content: z.string().nullish(),
87
- date: z.string().nullish(),
88
- rerank_score: z.number().nullish(),
89
- site_icon: z.string().nullish(),
90
- site_name: z.string().nullish(),
91
- snippet: z.string().nullish(),
92
- summary: z.string().nullish(),
93
- title: z.string().nullish(),
94
- url: z.string().nullish(),
95
- })
96
- .passthrough(),
80
+ z.catchall(
81
+ z.object({
82
+ authority: z.nullish(z.number()),
83
+ content: z.nullish(z.string()),
84
+ date: z.nullish(z.string()),
85
+ rerank_score: z.nullish(z.number()),
86
+ site_icon: z.nullish(z.string()),
87
+ site_name: z.nullish(z.string()),
88
+ snippet: z.nullish(z.string()),
89
+ summary: z.nullish(z.string()),
90
+ title: z.nullish(z.string()),
91
+ url: z.nullish(z.string()),
92
+ }),
93
+ z.unknown(),
94
+ ),
97
95
  ),
98
- })
99
- .passthrough(),
96
+ }),
97
+ z.unknown(),
98
+ ),
100
99
  gatewayToolErrorSchema(),
101
100
  ]),
102
101
  ),