@ai-sdk/gateway 4.0.120 → 4.0.121

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.
@@ -4,6 +4,8 @@ import type {
4
4
  SpeechModelV4,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
+ lazySchema,
8
+ zodSchema,
7
9
  combineHeaders,
8
10
  createJsonErrorResponseHandler,
9
11
  createJsonResponseHandler,
@@ -114,35 +116,40 @@ export class GatewaySpeechModel implements SpeechModelV4 {
114
116
  }
115
117
  }
116
118
 
117
- const providerMetadataEntrySchema = z.object({}).catchall(z.unknown());
119
+ const providerMetadataEntrySchema = () => z.object({}).catchall(z.unknown());
118
120
 
119
- const gatewaySpeechWarningSchema = z.discriminatedUnion('type', [
120
- z.object({
121
- type: z.literal('unsupported'),
122
- feature: z.string(),
123
- details: z.string().optional(),
124
- }),
125
- z.object({
126
- type: z.literal('compatibility'),
127
- feature: z.string(),
128
- details: z.string().optional(),
129
- }),
130
- z.object({
131
- type: z.literal('deprecated'),
132
- setting: z.string(),
133
- message: z.string(),
134
- }),
135
- z.object({
136
- type: z.literal('other'),
137
- message: z.string(),
138
- }),
139
- ]);
121
+ const gatewaySpeechWarningSchema = () =>
122
+ z.discriminatedUnion('type', [
123
+ z.object({
124
+ type: z.literal('unsupported'),
125
+ feature: z.string(),
126
+ details: z.string().optional(),
127
+ }),
128
+ z.object({
129
+ type: z.literal('compatibility'),
130
+ feature: z.string(),
131
+ details: z.string().optional(),
132
+ }),
133
+ z.object({
134
+ type: z.literal('deprecated'),
135
+ setting: z.string(),
136
+ message: z.string(),
137
+ }),
138
+ z.object({
139
+ type: z.literal('other'),
140
+ message: z.string(),
141
+ }),
142
+ ]);
140
143
 
141
- const gatewaySpeechResponseSchema = z.object({
142
- audio: z.string(),
143
- warnings: z.array(gatewaySpeechWarningSchema).optional(),
144
- usage: z.record(z.string(), z.json()).optional(),
145
- providerMetadata: z
146
- .record(z.string(), providerMetadataEntrySchema)
147
- .optional(),
148
- });
144
+ const gatewaySpeechResponseSchema = lazySchema(() =>
145
+ zodSchema(
146
+ z.object({
147
+ audio: z.string(),
148
+ warnings: z.array(gatewaySpeechWarningSchema()).optional(),
149
+ usage: z.record(z.string(), z.json()).optional(),
150
+ providerMetadata: z
151
+ .record(z.string(), providerMetadataEntrySchema())
152
+ .optional(),
153
+ }),
154
+ ),
155
+ );
@@ -8,6 +8,8 @@ import {
8
8
  type TranscriptionModelV4,
9
9
  } from '@ai-sdk/provider';
10
10
  import {
11
+ lazySchema,
12
+ zodSchema,
11
13
  combineHeaders,
12
14
  convertBase64ToUint8Array,
13
15
  convertUint8ArrayToBase64,
@@ -443,49 +445,54 @@ function createGatewayTranscriptionStream({
443
445
  });
444
446
  }
445
447
 
446
- const providerMetadataEntrySchema = z.object({}).catchall(z.unknown());
447
-
448
- const gatewayTranscriptionWarningSchema = z.discriminatedUnion('type', [
449
- z.object({
450
- type: z.literal('unsupported'),
451
- feature: z.string(),
452
- details: z.string().optional(),
453
- }),
454
- z.object({
455
- type: z.literal('compatibility'),
456
- feature: z.string(),
457
- details: z.string().optional(),
458
- }),
459
- z.object({
460
- type: z.literal('deprecated'),
461
- setting: z.string(),
462
- message: z.string(),
463
- }),
464
- z.object({
465
- type: z.literal('other'),
466
- message: z.string(),
467
- }),
468
- ]);
469
-
470
- const gatewayTranscriptionResponseSchema = z.object({
471
- text: z.string(),
472
- segments: z
473
- .array(
474
- z.object({
475
- text: z.string(),
476
- startSecond: z.number(),
477
- endSecond: z.number(),
478
- }),
479
- )
480
- .optional(),
481
- language: z.string().nullish(),
482
- durationInSeconds: z.number().nullish(),
483
- warnings: z.array(gatewayTranscriptionWarningSchema).optional(),
484
- usage: z.record(z.string(), z.json()).optional(),
485
- providerMetadata: z
486
- .record(z.string(), providerMetadataEntrySchema)
487
- .optional(),
488
- });
448
+ const providerMetadataEntrySchema = () => z.object({}).catchall(z.unknown());
449
+
450
+ const gatewayTranscriptionWarningSchema = () =>
451
+ z.discriminatedUnion('type', [
452
+ z.object({
453
+ type: z.literal('unsupported'),
454
+ feature: z.string(),
455
+ details: z.string().optional(),
456
+ }),
457
+ z.object({
458
+ type: z.literal('compatibility'),
459
+ feature: z.string(),
460
+ details: z.string().optional(),
461
+ }),
462
+ z.object({
463
+ type: z.literal('deprecated'),
464
+ setting: z.string(),
465
+ message: z.string(),
466
+ }),
467
+ z.object({
468
+ type: z.literal('other'),
469
+ message: z.string(),
470
+ }),
471
+ ]);
472
+
473
+ const gatewayTranscriptionResponseSchema = lazySchema(() =>
474
+ zodSchema(
475
+ z.object({
476
+ text: z.string(),
477
+ segments: z
478
+ .array(
479
+ z.object({
480
+ text: z.string(),
481
+ startSecond: z.number(),
482
+ endSecond: z.number(),
483
+ }),
484
+ )
485
+ .optional(),
486
+ language: z.string().nullish(),
487
+ durationInSeconds: z.number().nullish(),
488
+ warnings: z.array(gatewayTranscriptionWarningSchema()).optional(),
489
+ usage: z.record(z.string(), z.json()).optional(),
490
+ providerMetadata: z
491
+ .record(z.string(), providerMetadataEntrySchema())
492
+ .optional(),
493
+ }),
494
+ ),
495
+ );
489
496
 
490
497
  /**
491
498
  * `asGatewayError` is async while the WebSocket event handlers are
@@ -13,6 +13,8 @@ import {
13
13
  type SharedV4Warning,
14
14
  } from '@ai-sdk/provider';
15
15
  import {
16
+ lazySchema,
17
+ zodSchema,
16
18
  combineHeaders,
17
19
  convertUint8ArrayToBase64,
18
20
  createJsonErrorResponseHandler,
@@ -400,98 +402,115 @@ function maybeEncodeVideoFile(file: VideoModelV4File) {
400
402
  return file;
401
403
  }
402
404
 
403
- const providerMetadataEntrySchema = z
404
- .object({
405
- videos: z.array(z.unknown()).optional(),
406
- })
407
- .catchall(z.unknown());
408
-
409
- const gatewayVideoDataSchema = z.union([
410
- z.object({
411
- type: z.literal('url'),
412
- url: z.string(),
413
- mediaType: z.string(),
414
- }),
415
- z.object({
416
- type: z.literal('base64'),
417
- data: z.string(),
418
- mediaType: z.string(),
419
- }),
420
- ]);
421
-
422
- const gatewayVideoWarningSchema = z.discriminatedUnion('type', [
423
- z.object({
424
- type: z.literal('unsupported'),
425
- feature: z.string(),
426
- details: z.string().optional(),
427
- }),
428
- z.object({
429
- type: z.literal('compatibility'),
430
- feature: z.string(),
431
- details: z.string().optional(),
432
- }),
433
- z.object({
434
- type: z.literal('deprecated'),
435
- setting: z.string(),
436
- message: z.string(),
437
- }),
438
- z.object({
439
- type: z.literal('other'),
440
- message: z.string(),
441
- }),
442
- ]);
443
-
444
- const gatewayVideoEventSchema = z.discriminatedUnion('type', [
445
- z.object({
446
- type: z.literal('result'),
447
- videos: z.array(gatewayVideoDataSchema),
448
- warnings: z.array(gatewayVideoWarningSchema).optional(),
449
- providerMetadata: z
450
- .record(z.string(), providerMetadataEntrySchema)
451
- .optional(),
452
- }),
453
- z.object({
454
- type: z.literal('error'),
455
- message: z.string(),
456
- errorType: z.string(),
457
- statusCode: z.number(),
458
- param: z.unknown().nullable(),
459
- }),
460
- ]);
461
-
462
- const gatewayVideoStartResponseSchema = z.object({
463
- operation: z.unknown(),
464
- warnings: z.array(gatewayVideoWarningSchema).nullish(),
465
- providerMetadata: z.record(z.string(), providerMetadataEntrySchema).nullish(),
466
- });
467
-
468
- const gatewayVideoStatusResponseSchema = z.discriminatedUnion('status', [
469
- z.object({
470
- status: z.literal('pending'),
471
- warnings: z.array(gatewayVideoWarningSchema).nullish(),
472
- providerMetadata: z
473
- .record(z.string(), providerMetadataEntrySchema)
474
- .nullish(),
475
- }),
476
- z.object({
477
- status: z.literal('completed'),
478
- videos: z.array(gatewayVideoDataSchema),
479
- warnings: z.array(gatewayVideoWarningSchema).nullish(),
480
- providerMetadata: z
481
- .record(z.string(), providerMetadataEntrySchema)
482
- .nullish(),
483
- }),
484
- z.object({
485
- status: z.literal('error'),
486
- error: z.string(),
487
- providerMetadata: z
488
- .record(z.string(), providerMetadataEntrySchema)
489
- .nullish(),
490
- }),
491
- z.object({
492
- status: z.literal('cancelled'),
493
- providerMetadata: z
494
- .record(z.string(), providerMetadataEntrySchema)
495
- .nullish(),
496
- }),
497
- ]);
405
+ const providerMetadataEntrySchema = () =>
406
+ z
407
+ .object({
408
+ videos: z.array(z.unknown()).optional(),
409
+ })
410
+ .catchall(z.unknown());
411
+
412
+ const gatewayVideoDataSchema = () =>
413
+ z.union([
414
+ z.object({
415
+ type: z.literal('url'),
416
+ url: z.string(),
417
+ mediaType: z.string(),
418
+ }),
419
+ z.object({
420
+ type: z.literal('base64'),
421
+ data: z.string(),
422
+ mediaType: z.string(),
423
+ }),
424
+ ]);
425
+
426
+ const gatewayVideoWarningSchema = () =>
427
+ z.discriminatedUnion('type', [
428
+ z.object({
429
+ type: z.literal('unsupported'),
430
+ feature: z.string(),
431
+ details: z.string().optional(),
432
+ }),
433
+ z.object({
434
+ type: z.literal('compatibility'),
435
+ feature: z.string(),
436
+ details: z.string().optional(),
437
+ }),
438
+ z.object({
439
+ type: z.literal('deprecated'),
440
+ setting: z.string(),
441
+ message: z.string(),
442
+ }),
443
+ z.object({
444
+ type: z.literal('other'),
445
+ message: z.string(),
446
+ }),
447
+ ]);
448
+
449
+ const gatewayVideoEventSchema = lazySchema(() =>
450
+ zodSchema(
451
+ z.discriminatedUnion('type', [
452
+ z.object({
453
+ type: z.literal('result'),
454
+ videos: z.array(gatewayVideoDataSchema()),
455
+ warnings: z.array(gatewayVideoWarningSchema()).optional(),
456
+ providerMetadata: z
457
+ .record(z.string(), providerMetadataEntrySchema())
458
+ .optional(),
459
+ }),
460
+ z.object({
461
+ type: z.literal('error'),
462
+ message: z.string(),
463
+ errorType: z.string(),
464
+ statusCode: z.number(),
465
+ param: z.unknown().nullable(),
466
+ }),
467
+ ]),
468
+ ),
469
+ );
470
+
471
+ const gatewayVideoStartResponseSchema = lazySchema(() =>
472
+ zodSchema(
473
+ z.object({
474
+ operation: z.unknown(),
475
+ warnings: z.array(gatewayVideoWarningSchema()).nullish(),
476
+ providerMetadata: z
477
+ .record(z.string(), providerMetadataEntrySchema())
478
+ .nullish(),
479
+ }),
480
+ ),
481
+ );
482
+
483
+ const gatewayVideoStatusResponseSchema = lazySchema(() =>
484
+ zodSchema(
485
+ z.discriminatedUnion('status', [
486
+ z.object({
487
+ status: z.literal('pending'),
488
+ warnings: z.array(gatewayVideoWarningSchema()).nullish(),
489
+ providerMetadata: z
490
+ .record(z.string(), providerMetadataEntrySchema())
491
+ .nullish(),
492
+ }),
493
+ z.object({
494
+ status: z.literal('completed'),
495
+ videos: z.array(gatewayVideoDataSchema()),
496
+ warnings: z.array(gatewayVideoWarningSchema()).nullish(),
497
+ providerMetadata: z
498
+ .record(z.string(), providerMetadataEntrySchema())
499
+ .nullish(),
500
+ }),
501
+ z.object({
502
+ status: z.literal('error'),
503
+ error: z.string(),
504
+ providerMetadata: z
505
+ .record(z.string(), providerMetadataEntrySchema())
506
+ .nullish(),
507
+ }),
508
+ z.object({
509
+ status: z.literal('cancelled'),
510
+ providerMetadata: z
511
+ .record(z.string(), providerMetadataEntrySchema())
512
+ .nullish(),
513
+ }),
514
+ ]),
515
+ ),
516
+ );
@@ -76,7 +76,7 @@ export type BrowserbaseFetchOutput =
76
76
  | BrowserbaseFetchError
77
77
  | BrowserbaseFetchResponse;
78
78
 
79
- const jsonObjectSchema = z.record(z.string(), z.unknown());
79
+ const jsonObjectSchema = () => z.record(z.string(), z.unknown());
80
80
 
81
81
  const browserbaseFetchInputSchema = lazySchema(() =>
82
82
  zodSchema(
@@ -104,7 +104,7 @@ const browserbaseFetchInputSchema = lazySchema(() =>
104
104
  .describe(
105
105
  'Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema.',
106
106
  ),
107
- schema: jsonObjectSchema
107
+ schema: jsonObjectSchema()
108
108
  .optional()
109
109
  .describe(
110
110
  'JSON Schema for structured extraction. Only use with format set to json.',
@@ -118,7 +118,7 @@ const browserbaseFetchOutputSchema = lazySchema(() =>
118
118
  z.union([
119
119
  z.object({
120
120
  id: z.string(),
121
- content: z.union([z.string(), jsonObjectSchema]),
121
+ content: z.union([z.string(), jsonObjectSchema()]),
122
122
  contentType: z.string(),
123
123
  encoding: z.string(),
124
124
  headers: z.record(z.string(), z.string()),