@mastra/schema-compat 0.0.0-ai-v5-20250801192614 → 0.0.0-bundle-recursion-20251030002519

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +140 -2
  2. package/README.md +0 -4
  3. package/dist/chunk-5WM4A32G.cjs +83 -0
  4. package/dist/chunk-5WM4A32G.cjs.map +1 -0
  5. package/dist/chunk-U2HXWNAF.js +77 -0
  6. package/dist/chunk-U2HXWNAF.js.map +1 -0
  7. package/dist/index.cjs +860 -138
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +10 -8
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +859 -139
  12. package/dist/index.js.map +1 -1
  13. package/dist/provider-compats/anthropic.d.ts +7 -5
  14. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  15. package/dist/provider-compats/deepseek.d.ts +7 -5
  16. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  17. package/dist/provider-compats/google.d.ts +7 -5
  18. package/dist/provider-compats/google.d.ts.map +1 -1
  19. package/dist/provider-compats/meta.d.ts +7 -5
  20. package/dist/provider-compats/meta.d.ts.map +1 -1
  21. package/dist/provider-compats/openai-reasoning.d.ts +7 -5
  22. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  23. package/dist/provider-compats/openai.d.ts +7 -5
  24. package/dist/provider-compats/openai.d.ts.map +1 -1
  25. package/dist/schema-compatibility-v3.d.ts +288 -0
  26. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  27. package/dist/schema-compatibility-v4.d.ts +279 -0
  28. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  29. package/dist/schema-compatibility.d.ts +81 -165
  30. package/dist/schema-compatibility.d.ts.map +1 -1
  31. package/dist/types.d.ts +6 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/dist/utils-test-suite.d.ts +2 -0
  34. package/dist/utils-test-suite.d.ts.map +1 -0
  35. package/dist/utils.d.ts +17 -5
  36. package/dist/utils.d.ts.map +1 -1
  37. package/dist/zod-to-json-test-suite.d.ts +6 -0
  38. package/dist/zod-to-json-test-suite.d.ts.map +1 -0
  39. package/dist/zod-to-json.cjs +12 -0
  40. package/dist/zod-to-json.cjs.map +1 -0
  41. package/dist/zod-to-json.d.ts +6 -0
  42. package/dist/zod-to-json.d.ts.map +1 -0
  43. package/dist/zod-to-json.js +3 -0
  44. package/dist/zod-to-json.js.map +1 -0
  45. package/dist/zodTypes.d.ts +21 -0
  46. package/dist/zodTypes.d.ts.map +1 -0
  47. package/package.json +35 -10
  48. package/.turbo/turbo-build.log +0 -4
  49. package/eslint.config.js +0 -6
  50. package/src/index.ts +0 -39
  51. package/src/provider-compats/anthropic.ts +0 -43
  52. package/src/provider-compats/deepseek.ts +0 -35
  53. package/src/provider-compats/google.ts +0 -63
  54. package/src/provider-compats/meta.ts +0 -36
  55. package/src/provider-compats/openai-reasoning.ts +0 -88
  56. package/src/provider-compats/openai.ts +0 -56
  57. package/src/provider-compats.test.ts +0 -312
  58. package/src/schema-compatibility.test.ts +0 -479
  59. package/src/schema-compatibility.ts +0 -590
  60. package/src/utils.test.ts +0 -442
  61. package/src/utils.ts +0 -205
  62. package/tsconfig.build.json +0 -9
  63. package/tsconfig.json +0 -5
  64. package/tsup.config.ts +0 -22
  65. package/vitest.config.ts +0 -7
package/dist/index.js CHANGED
@@ -1,22 +1,18 @@
1
- import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, z, ZodNull, ZodDefault, ZodDate } from 'zod';
1
+ import { zodToJsonSchema } from './chunk-U2HXWNAF.js';
2
+ import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodDate, ZodDefault } from 'zod';
2
3
  import { jsonSchema } from 'ai';
3
4
  import { convertJsonSchemaToZod } from 'zod-from-json-schema';
4
- import { zodToJsonSchema } from 'zod-to-json-schema';
5
+ import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
6
+ import { ZodOptional as ZodOptional$1, ZodObject as ZodObject$1, ZodNull as ZodNull$1, ZodArray as ZodArray$1, ZodUnion as ZodUnion$1, ZodString as ZodString$1, ZodNumber as ZodNumber$1, ZodDate as ZodDate$1, ZodDefault as ZodDefault$1, z as z$1 } from 'zod/v4';
5
7
 
6
- // src/schema-compatibility.ts
7
8
  function convertZodSchemaToAISDKSchema(zodSchema, target = "jsonSchema7") {
8
- return jsonSchema(
9
- zodToJsonSchema(zodSchema, {
10
- $refStrategy: "none",
11
- target
12
- }),
13
- {
14
- validate: (value) => {
15
- const result = zodSchema.safeParse(value);
16
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
17
- }
9
+ const jsonSchemaToUse = zodToJsonSchema(zodSchema, target);
10
+ return jsonSchema(jsonSchemaToUse, {
11
+ validate: (value) => {
12
+ const result = zodSchema.safeParse(value);
13
+ return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
18
14
  }
19
- );
15
+ });
20
16
  }
21
17
  function isZodType(value) {
22
18
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
@@ -27,7 +23,11 @@ function convertSchemaToZod(schema) {
27
23
  } else {
28
24
  const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
29
25
  try {
30
- return convertJsonSchemaToZod(jsonSchemaToConvert);
26
+ if ("toJSONSchema" in z) {
27
+ return convertJsonSchemaToZod(jsonSchemaToConvert);
28
+ } else {
29
+ return convertJsonSchemaToZod$1(jsonSchemaToConvert);
30
+ }
31
31
  } catch (e) {
32
32
  const errorMessage = `[Schema Builder] Failed to convert schema parameters to Zod. Original schema: ${JSON.stringify(jsonSchemaToConvert)}`;
33
33
  console.error(errorMessage, e);
@@ -53,13 +53,13 @@ function applyCompatLayer({
53
53
  }
54
54
  }
55
55
  if (mode === "jsonSchema") {
56
- return zodToJsonSchema(zodSchema, { $refStrategy: "none", target: "jsonSchema7" });
56
+ return zodToJsonSchema(zodSchema, "jsonSchema7");
57
57
  } else {
58
58
  return convertZodSchemaToAISDKSchema(zodSchema);
59
59
  }
60
60
  }
61
61
 
62
- // src/schema-compatibility.ts
62
+ // src/schema-compatibility-v3.ts
63
63
  var ALL_STRING_CHECKS = ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
64
64
  var ALL_NUMBER_CHECKS = [
65
65
  "min",
@@ -71,13 +71,10 @@ var ALL_NUMBER_CHECKS = [
71
71
  var ALL_ARRAY_CHECKS = ["min", "max", "length"];
72
72
  var isOptional = (v) => v instanceof ZodOptional;
73
73
  var isObj = (v) => v instanceof ZodObject;
74
- var isNull = (v) => v instanceof ZodNull;
75
74
  var isArr = (v) => v instanceof ZodArray;
76
75
  var isUnion = (v) => v instanceof ZodUnion;
77
76
  var isString = (v) => v instanceof ZodString;
78
77
  var isNumber = (v) => v instanceof ZodNumber;
79
- var isDate = (v) => v instanceof ZodDate;
80
- var isDefault = (v) => v instanceof ZodDefault;
81
78
  var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
82
79
  var SUPPORTED_ZOD_TYPES = [
83
80
  "ZodObject",
@@ -92,13 +89,15 @@ var SUPPORTED_ZOD_TYPES = [
92
89
  var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
93
90
  var SchemaCompatLayer = class {
94
91
  model;
92
+ parent;
95
93
  /**
96
94
  * Creates a new schema compatibility instance.
97
95
  *
98
96
  * @param model - The language model this compatibility layer applies to
99
97
  */
100
- constructor(model) {
98
+ constructor(model, parent) {
101
99
  this.model = model;
100
+ this.parent = parent;
102
101
  }
103
102
  /**
104
103
  * Gets the language model associated with this compatibility layer.
@@ -108,6 +107,91 @@ var SchemaCompatLayer = class {
108
107
  getModel() {
109
108
  return this.model;
110
109
  }
110
+ getUnsupportedZodTypes() {
111
+ return UNSUPPORTED_ZOD_TYPES;
112
+ }
113
+ /**
114
+ * Type guard for optional Zod types
115
+ */
116
+ isOptional(v) {
117
+ return v instanceof ZodOptional;
118
+ }
119
+ /**
120
+ * Type guard for object Zod types
121
+ */
122
+ isObj(v) {
123
+ return v instanceof ZodObject;
124
+ }
125
+ /**
126
+ * Type guard for null Zod types
127
+ */
128
+ isNull(v) {
129
+ return v instanceof ZodNull;
130
+ }
131
+ /**
132
+ * Type guard for array Zod types
133
+ */
134
+ isArr(v) {
135
+ return v instanceof ZodArray;
136
+ }
137
+ /**
138
+ * Type guard for union Zod types
139
+ */
140
+ isUnion(v) {
141
+ return v instanceof ZodUnion;
142
+ }
143
+ /**
144
+ * Type guard for string Zod types
145
+ */
146
+ isString(v) {
147
+ return v instanceof ZodString;
148
+ }
149
+ /**
150
+ * Type guard for number Zod types
151
+ */
152
+ isNumber(v) {
153
+ return v instanceof ZodNumber;
154
+ }
155
+ /**
156
+ * Type guard for date Zod types
157
+ */
158
+ isDate(v) {
159
+ return v instanceof ZodDate;
160
+ }
161
+ /**
162
+ * Type guard for default Zod types
163
+ */
164
+ isDefault(v) {
165
+ return v instanceof ZodDefault;
166
+ }
167
+ /**
168
+ * Determines whether this compatibility layer should be applied for the current model.
169
+ *
170
+ * @returns True if this compatibility layer should be used, false otherwise
171
+ * @abstract
172
+ */
173
+ shouldApply() {
174
+ return this.parent.shouldApply();
175
+ }
176
+ /**
177
+ * Returns the JSON Schema target format for this provider.
178
+ *
179
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
180
+ * @abstract
181
+ */
182
+ getSchemaTarget() {
183
+ return this.parent.getSchemaTarget();
184
+ }
185
+ /**
186
+ * Processes a specific Zod type according to the provider's requirements.
187
+ *
188
+ * @param value - The Zod type to process
189
+ * @returns The processed Zod type
190
+ * @abstract
191
+ */
192
+ processZodType(value) {
193
+ return this.parent.processZodType(value);
194
+ }
111
195
  /**
112
196
  * Default handler for Zod object types. Recursively processes all properties in the object.
113
197
  *
@@ -145,8 +229,8 @@ var SchemaCompatLayer = class {
145
229
  * @returns The updated description with constraints, or undefined if no constraints
146
230
  */
147
231
  mergeParameterDescription(description, constraints) {
148
- if (Object.keys(constraints).length > 0) {
149
- return (description ? description + "\n" : "") + JSON.stringify(constraints);
232
+ if (constraints.length > 0) {
233
+ return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
150
234
  } else {
151
235
  return description;
152
236
  }
@@ -176,24 +260,24 @@ var SchemaCompatLayer = class {
176
260
  const zodArrayDef = value._def;
177
261
  const processedType = this.processZodType(zodArrayDef.type);
178
262
  let result = z.array(processedType);
179
- const constraints = {};
263
+ const constraints = [];
180
264
  if (zodArrayDef.minLength?.value !== void 0) {
181
265
  if (handleChecks.includes("min")) {
182
- constraints.minLength = zodArrayDef.minLength.value;
266
+ constraints.push(`minimum length ${zodArrayDef.minLength.value}`);
183
267
  } else {
184
268
  result = result.min(zodArrayDef.minLength.value);
185
269
  }
186
270
  }
187
271
  if (zodArrayDef.maxLength?.value !== void 0) {
188
272
  if (handleChecks.includes("max")) {
189
- constraints.maxLength = zodArrayDef.maxLength.value;
273
+ constraints.push(`maximum length ${zodArrayDef.maxLength.value}`);
190
274
  } else {
191
275
  result = result.max(zodArrayDef.maxLength.value);
192
276
  }
193
277
  }
194
278
  if (zodArrayDef.exactLength?.value !== void 0) {
195
279
  if (handleChecks.includes("length")) {
196
- constraints.exactLength = zodArrayDef.exactLength.value;
280
+ constraints.push(`exact length ${zodArrayDef.exactLength.value}`);
197
281
  } else {
198
282
  result = result.length(zodArrayDef.exactLength.value);
199
283
  }
@@ -228,7 +312,7 @@ var SchemaCompatLayer = class {
228
312
  * @returns The processed Zod string
229
313
  */
230
314
  defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
231
- const constraints = {};
315
+ const constraints = [];
232
316
  const checks = value._def.checks || [];
233
317
  const newChecks = [];
234
318
  for (const check of checks) {
@@ -236,38 +320,20 @@ var SchemaCompatLayer = class {
236
320
  if (handleChecks.includes(check.kind)) {
237
321
  switch (check.kind) {
238
322
  case "regex": {
239
- constraints.regex = {
240
- pattern: check.regex.source,
241
- flags: check.regex.flags
242
- };
243
- break;
244
- }
245
- case "emoji": {
246
- constraints.emoji = true;
247
- break;
248
- }
249
- case "email": {
250
- constraints.email = true;
251
- break;
252
- }
253
- case "url": {
254
- constraints.url = true;
255
- break;
256
- }
257
- case "uuid": {
258
- constraints.uuid = true;
323
+ constraints.push(`input must match this regex ${check.regex.source}`);
259
324
  break;
260
325
  }
326
+ case "emoji":
327
+ case "email":
328
+ case "url":
329
+ case "uuid":
261
330
  case "cuid": {
262
- constraints.cuid = true;
263
- break;
264
- }
265
- case "min": {
266
- constraints.minLength = check.value;
331
+ constraints.push(`a valid ${check.kind}`);
267
332
  break;
268
333
  }
334
+ case "min":
269
335
  case "max": {
270
- constraints.maxLength = check.value;
336
+ constraints.push(`${check.kind}imum length ${check.value}`);
271
337
  break;
272
338
  }
273
339
  }
@@ -294,7 +360,7 @@ var SchemaCompatLayer = class {
294
360
  * @returns The processed Zod number
295
361
  */
296
362
  defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
297
- const constraints = {};
363
+ const constraints = [];
298
364
  const checks = value._def.checks || [];
299
365
  const newChecks = [];
300
366
  for (const check of checks) {
@@ -303,20 +369,20 @@ var SchemaCompatLayer = class {
303
369
  switch (check.kind) {
304
370
  case "min":
305
371
  if (check.inclusive) {
306
- constraints.gte = check.value;
372
+ constraints.push(`greater than or equal to ${check.value}`);
307
373
  } else {
308
- constraints.gt = check.value;
374
+ constraints.push(`greater than ${check.value}`);
309
375
  }
310
376
  break;
311
377
  case "max":
312
378
  if (check.inclusive) {
313
- constraints.lte = check.value;
379
+ constraints.push(`lower than or equal to ${check.value}`);
314
380
  } else {
315
- constraints.lt = check.value;
381
+ constraints.push(`lower than ${check.value}`);
316
382
  }
317
383
  break;
318
384
  case "multipleOf": {
319
- constraints.multipleOf = check.value;
385
+ constraints.push(`multiple of ${check.value}`);
320
386
  break;
321
387
  }
322
388
  }
@@ -351,7 +417,7 @@ var SchemaCompatLayer = class {
351
417
  * @returns A Zod string schema representing the date in ISO format
352
418
  */
353
419
  defaultZodDateHandler(value) {
354
- const constraints = {};
420
+ const constraints = [];
355
421
  const checks = value._def.checks || [];
356
422
  for (const check of checks) {
357
423
  if ("kind" in check) {
@@ -359,19 +425,19 @@ var SchemaCompatLayer = class {
359
425
  case "min":
360
426
  const minDate = new Date(check.value);
361
427
  if (!isNaN(minDate.getTime())) {
362
- constraints.minDate = minDate.toISOString();
428
+ constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
363
429
  }
364
430
  break;
365
431
  case "max":
366
432
  const maxDate = new Date(check.value);
367
433
  if (!isNaN(maxDate.getTime())) {
368
- constraints.maxDate = maxDate.toISOString();
434
+ constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
369
435
  }
370
436
  break;
371
437
  }
372
438
  }
373
439
  }
374
- constraints.dateFormat = "date-time";
440
+ constraints.push(`Date format is date-time`);
375
441
  let result = z.string().describe("date-time");
376
442
  const description = this.mergeParameterDescription(value.description, constraints);
377
443
  if (description) {
@@ -413,9 +479,667 @@ var SchemaCompatLayer = class {
413
479
  return this.processToAISDKSchema(zodSchema).jsonSchema;
414
480
  }
415
481
  };
482
+ var ALL_STRING_CHECKS2 = [
483
+ "regex",
484
+ "emoji",
485
+ "email",
486
+ "url",
487
+ "uuid",
488
+ "cuid",
489
+ "min_length",
490
+ "max_length",
491
+ "string_format"
492
+ ];
493
+ var ALL_NUMBER_CHECKS2 = ["greater_than", "less_than", "multiple_of"];
494
+ var ALL_ARRAY_CHECKS2 = ["min", "max", "length"];
495
+ var UNSUPPORTED_ZOD_TYPES2 = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
496
+ var SUPPORTED_ZOD_TYPES2 = [
497
+ "ZodObject",
498
+ "ZodArray",
499
+ "ZodUnion",
500
+ "ZodString",
501
+ "ZodNumber",
502
+ "ZodDate",
503
+ "ZodAny",
504
+ "ZodDefault"
505
+ ];
506
+ var SchemaCompatLayer2 = class {
507
+ model;
508
+ parent;
509
+ /**
510
+ * Creates a new schema compatibility instance.
511
+ *
512
+ * @param model - The language model this compatibility layer applies to
513
+ */
514
+ constructor(model, parent) {
515
+ this.model = model;
516
+ this.parent = parent;
517
+ }
518
+ /**
519
+ * Gets the language model associated with this compatibility layer.
520
+ *
521
+ * @returns The language model instance
522
+ */
523
+ getModel() {
524
+ return this.model;
525
+ }
526
+ getUnsupportedZodTypes() {
527
+ return UNSUPPORTED_ZOD_TYPES2;
528
+ }
529
+ /**
530
+ * Type guard for optional Zod types
531
+ */
532
+ isOptional(v) {
533
+ return v instanceof ZodOptional$1;
534
+ }
535
+ /**
536
+ * Type guard for object Zod types
537
+ */
538
+ isObj(v) {
539
+ return v instanceof ZodObject$1;
540
+ }
541
+ /**
542
+ * Type guard for null Zod types
543
+ */
544
+ isNull(v) {
545
+ return v instanceof ZodNull$1;
546
+ }
547
+ /**
548
+ * Type guard for array Zod types
549
+ */
550
+ isArr(v) {
551
+ return v instanceof ZodArray$1;
552
+ }
553
+ /**
554
+ * Type guard for union Zod types
555
+ */
556
+ isUnion(v) {
557
+ return v instanceof ZodUnion$1;
558
+ }
559
+ /**
560
+ * Type guard for string Zod types
561
+ */
562
+ isString(v) {
563
+ return v instanceof ZodString$1;
564
+ }
565
+ /**
566
+ * Type guard for number Zod types
567
+ */
568
+ isNumber(v) {
569
+ return v instanceof ZodNumber$1;
570
+ }
571
+ /**
572
+ * Type guard for date Zod types
573
+ */
574
+ isDate(v) {
575
+ return v instanceof ZodDate$1;
576
+ }
577
+ /**
578
+ * Type guard for default Zod types
579
+ */
580
+ isDefault(v) {
581
+ return v instanceof ZodDefault$1;
582
+ }
583
+ /**
584
+ * Determines whether this compatibility layer should be applied for the current model.
585
+ *
586
+ * @returns True if this compatibility layer should be used, false otherwise
587
+ * @abstract
588
+ */
589
+ shouldApply() {
590
+ return this.parent.shouldApply();
591
+ }
592
+ /**
593
+ * Returns the JSON Schema target format for this provider.
594
+ *
595
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
596
+ * @abstract
597
+ */
598
+ getSchemaTarget() {
599
+ return this.parent.getSchemaTarget();
600
+ }
601
+ /**
602
+ * Processes a specific Zod type according to the provider's requirements.
603
+ *
604
+ * @param value - The Zod type to process
605
+ * @returns The processed Zod type
606
+ * @abstract
607
+ */
608
+ processZodType(value) {
609
+ return this.parent.processZodType(value);
610
+ }
611
+ /**
612
+ * Default handler for Zod object types. Recursively processes all properties in the object.
613
+ *
614
+ * @param value - The Zod object to process
615
+ * @returns The processed Zod object
616
+ */
617
+ defaultZodObjectHandler(value, options = { passthrough: true }) {
618
+ const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
619
+ acc[key] = this.processZodType(propValue);
620
+ return acc;
621
+ }, {});
622
+ let result = z$1.object(processedShape);
623
+ if (value._zod.def.catchall instanceof z$1.ZodNever) {
624
+ result = z$1.strictObject(processedShape);
625
+ }
626
+ if (value._zod.def.catchall && !(value._zod.def.catchall instanceof z$1.ZodNever)) {
627
+ result = result.catchall(value._zod.def.catchall);
628
+ }
629
+ if (value.description) {
630
+ result = result.describe(value.description);
631
+ }
632
+ if (options.passthrough && value._zod.def.catchall instanceof z$1.ZodUnknown) {
633
+ result = z$1.looseObject(processedShape);
634
+ }
635
+ return result;
636
+ }
637
+ /**
638
+ * Merges validation constraints into a parameter description.
639
+ *
640
+ * This helper method converts validation constraints that may not be supported
641
+ * by a provider into human-readable descriptions.
642
+ *
643
+ * @param description - The existing parameter description
644
+ * @param constraints - The validation constraints to merge
645
+ * @returns The updated description with constraints, or undefined if no constraints
646
+ */
647
+ mergeParameterDescription(description, constraints) {
648
+ if (constraints.length > 0) {
649
+ return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
650
+ } else {
651
+ return description;
652
+ }
653
+ }
654
+ /**
655
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
656
+ *
657
+ * @param value - The Zod type to check
658
+ * @param throwOnTypes - Array of type names to throw errors for
659
+ * @returns The original value if not in the throw list
660
+ * @throws Error if the type is in the unsupported list
661
+ */
662
+ defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES2) {
663
+ if (throwOnTypes.includes(value.constructor.name)) {
664
+ throw new Error(`${this.model.modelId} does not support zod type: ${value.constructor.name}`);
665
+ }
666
+ return value;
667
+ }
668
+ /**
669
+ * Default handler for Zod array types. Processes array constraints according to provider support.
670
+ *
671
+ * @param value - The Zod array to process
672
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
673
+ * @returns The processed Zod array
674
+ */
675
+ defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS2) {
676
+ const zodArrayDef = value._zod.def;
677
+ const processedType = this.processZodType(zodArrayDef.element);
678
+ let result = z$1.array(processedType);
679
+ const constraints = [];
680
+ if (zodArrayDef.checks) {
681
+ for (const check of zodArrayDef.checks) {
682
+ if (check._zod.def.check === "min_length") {
683
+ if (handleChecks.includes("min")) {
684
+ constraints.push(`minimum length ${check._zod.def.minimum}`);
685
+ } else {
686
+ result = result.min(check._zod.def.minimum);
687
+ }
688
+ }
689
+ if (check._zod.def.check === "max_length") {
690
+ if (handleChecks.includes("max")) {
691
+ constraints.push(`maximum length ${check._zod.def.maximum}`);
692
+ } else {
693
+ result = result.max(check._zod.def.maximum);
694
+ }
695
+ }
696
+ if (check._zod.def.check === "length_equals") {
697
+ if (handleChecks.includes("length")) {
698
+ constraints.push(`exact length ${check._zod.def.length}`);
699
+ } else {
700
+ result = result.length(check._zod.def.length);
701
+ }
702
+ }
703
+ }
704
+ }
705
+ const metaDescription = value.meta()?.description;
706
+ const legacyDescription = value.description;
707
+ const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
708
+ if (description) {
709
+ result = result.describe(description);
710
+ }
711
+ return result;
712
+ }
713
+ /**
714
+ * Default handler for Zod union types. Processes all union options.
715
+ *
716
+ * @param value - The Zod union to process
717
+ * @returns The processed Zod union
718
+ * @throws Error if union has fewer than 2 options
719
+ */
720
+ defaultZodUnionHandler(value) {
721
+ const processedOptions = value._zod.def.options.map((option) => this.processZodType(option));
722
+ if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
723
+ let result = z$1.union(processedOptions);
724
+ if (value.description) {
725
+ result = result.describe(value.description);
726
+ }
727
+ return result;
728
+ }
729
+ /**
730
+ * Default handler for Zod string types. Processes string validation constraints.
731
+ *
732
+ * @param value - The Zod string to process
733
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
734
+ * @returns The processed Zod string
735
+ */
736
+ defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS2) {
737
+ const constraints = [];
738
+ const checks = value._zod.def.checks || [];
739
+ const newChecks = [];
740
+ if (checks) {
741
+ for (const check of checks) {
742
+ if (handleChecks.includes(check._zod.def.check)) {
743
+ switch (check._zod.def.check) {
744
+ case "min_length":
745
+ constraints.push(`minimum length ${check._zod.def.minimum}`);
746
+ break;
747
+ case "max_length":
748
+ constraints.push(`maximum length ${check._zod.def.maximum}`);
749
+ break;
750
+ case "string_format":
751
+ {
752
+ switch (check._zod.def.format) {
753
+ case "email":
754
+ case "url":
755
+ case "emoji":
756
+ case "uuid":
757
+ case "cuid":
758
+ constraints.push(`a valid ${check._zod.def.format}`);
759
+ break;
760
+ case "regex":
761
+ constraints.push(`input must match this regex ${check._zod.def.pattern}`);
762
+ break;
763
+ }
764
+ }
765
+ break;
766
+ }
767
+ } else {
768
+ newChecks.push(check);
769
+ }
770
+ }
771
+ }
772
+ let result = z$1.string();
773
+ for (const check of newChecks) {
774
+ result = result.check(check);
775
+ }
776
+ const metaDescription = value.meta()?.description;
777
+ const legacyDescription = value.description;
778
+ const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
779
+ if (description) {
780
+ result = result.describe(description);
781
+ }
782
+ return result;
783
+ }
784
+ /**
785
+ * Default handler for Zod number types. Processes number validation constraints.
786
+ *
787
+ * @param value - The Zod number to process
788
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
789
+ * @returns The processed Zod number
790
+ */
791
+ defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS2) {
792
+ const constraints = [];
793
+ const checks = value._zod.def.checks || [];
794
+ const newChecks = [];
795
+ if (checks) {
796
+ for (const check of checks) {
797
+ if (handleChecks.includes(check._zod.def.check)) {
798
+ switch (check._zod.def.check) {
799
+ case "greater_than":
800
+ if (check._zod.def.inclusive) {
801
+ constraints.push(`greater than or equal to ${check._zod.def.value}`);
802
+ } else {
803
+ constraints.push(`greater than ${check._zod.def.value}`);
804
+ }
805
+ break;
806
+ case "less_than":
807
+ if (check._zod.def.inclusive) {
808
+ constraints.push(`lower than or equal to ${check._zod.def.value}`);
809
+ } else {
810
+ constraints.push(`lower than ${check._zod.def.value}`);
811
+ }
812
+ break;
813
+ case "multiple_of": {
814
+ constraints.push(`multiple of ${check._zod.def.value}`);
815
+ break;
816
+ }
817
+ }
818
+ } else {
819
+ newChecks.push(check);
820
+ }
821
+ }
822
+ }
823
+ let result = z$1.number();
824
+ for (const check of newChecks) {
825
+ switch (check._zod.def.check) {
826
+ case "number_format": {
827
+ switch (check._zod.def.format) {
828
+ case "safeint":
829
+ result = result.int();
830
+ break;
831
+ }
832
+ break;
833
+ }
834
+ default:
835
+ result = result.check(check);
836
+ }
837
+ }
838
+ const description = this.mergeParameterDescription(value.description, constraints);
839
+ if (description) {
840
+ result = result.describe(description);
841
+ }
842
+ return result;
843
+ }
844
+ /**
845
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
846
+ *
847
+ * @param value - The Zod date to process
848
+ * @returns A Zod string schema representing the date in ISO format
849
+ */
850
+ defaultZodDateHandler(value) {
851
+ const constraints = [];
852
+ const checks = value._zod.def.checks || [];
853
+ if (checks) {
854
+ for (const check of checks) {
855
+ switch (check._zod.def.check) {
856
+ case "less_than":
857
+ const minDate = new Date(check._zod.def.value);
858
+ if (!isNaN(minDate.getTime())) {
859
+ constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
860
+ }
861
+ break;
862
+ case "greater_than":
863
+ const maxDate = new Date(check._zod.def.value);
864
+ if (!isNaN(maxDate.getTime())) {
865
+ constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
866
+ }
867
+ break;
868
+ }
869
+ }
870
+ }
871
+ constraints.push(`Date format is date-time`);
872
+ let result = z$1.string().describe("date-time");
873
+ const description = this.mergeParameterDescription(value.description, constraints);
874
+ if (description) {
875
+ result = result.describe(description);
876
+ }
877
+ return result;
878
+ }
879
+ /**
880
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
881
+ *
882
+ * @param value - The Zod optional to process
883
+ * @param handleTypes - Types that should be processed vs passed through
884
+ * @returns The processed Zod optional
885
+ */
886
+ defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES2) {
887
+ if (handleTypes.includes(value.constructor.name)) {
888
+ return this.processZodType(value._zod.def.innerType).optional();
889
+ } else {
890
+ return value;
891
+ }
892
+ }
893
+ /**
894
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
895
+ *
896
+ * @param zodSchema - The Zod object schema to process
897
+ * @returns An AI SDK Schema with provider-specific compatibility applied
898
+ */
899
+ processToAISDKSchema(zodSchema) {
900
+ const processedSchema = this.processZodType(zodSchema);
901
+ return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
902
+ }
903
+ /**
904
+ * Processes a Zod object schema and converts it to a JSON Schema.
905
+ *
906
+ * @param zodSchema - The Zod object schema to process
907
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
908
+ */
909
+ processToJSONSchema(zodSchema) {
910
+ return this.processToAISDKSchema(zodSchema).jsonSchema;
911
+ }
912
+ };
913
+
914
+ // src/schema-compatibility.ts
915
+ var SchemaCompatLayer3 = class {
916
+ model;
917
+ v3Layer;
918
+ v4Layer;
919
+ /**
920
+ * Creates a new schema compatibility instance.
921
+ *
922
+ * @param model - The language model this compatibility layer applies to
923
+ */
924
+ constructor(model) {
925
+ this.model = model;
926
+ this.v3Layer = new SchemaCompatLayer(model, this);
927
+ this.v4Layer = new SchemaCompatLayer2(model, this);
928
+ }
929
+ /**
930
+ * Gets the language model associated with this compatibility layer.
931
+ *
932
+ * @returns The language model instance
933
+ */
934
+ getModel() {
935
+ return this.model;
936
+ }
937
+ getUnsupportedZodTypes(v) {
938
+ if ("_zod" in v) {
939
+ return this.v4Layer.getUnsupportedZodTypes();
940
+ } else {
941
+ return this.v3Layer.getUnsupportedZodTypes();
942
+ }
943
+ }
944
+ isOptional(v) {
945
+ if ("_zod" in v) {
946
+ return this.v4Layer.isOptional(v);
947
+ } else {
948
+ return this.v3Layer.isOptional(v);
949
+ }
950
+ }
951
+ isObj(v) {
952
+ if ("_zod" in v) {
953
+ return this.v4Layer.isObj(v);
954
+ } else {
955
+ return this.v3Layer.isObj(v);
956
+ }
957
+ }
958
+ isNull(v) {
959
+ if ("_zod" in v) {
960
+ return this.v4Layer.isNull(v);
961
+ } else {
962
+ return this.v3Layer.isNull(v);
963
+ }
964
+ }
965
+ isArr(v) {
966
+ if ("_zod" in v) {
967
+ return this.v4Layer.isArr(v);
968
+ } else {
969
+ return this.v3Layer.isArr(v);
970
+ }
971
+ }
972
+ isUnion(v) {
973
+ if ("_zod" in v) {
974
+ return this.v4Layer.isUnion(v);
975
+ } else {
976
+ return this.v3Layer.isUnion(v);
977
+ }
978
+ }
979
+ isString(v) {
980
+ if ("_zod" in v) {
981
+ return this.v4Layer.isString(v);
982
+ } else {
983
+ return this.v3Layer.isString(v);
984
+ }
985
+ }
986
+ isNumber(v) {
987
+ if ("_zod" in v) {
988
+ return this.v4Layer.isNumber(v);
989
+ } else {
990
+ return this.v3Layer.isNumber(v);
991
+ }
992
+ }
993
+ isDate(v) {
994
+ if ("_zod" in v) {
995
+ return this.v4Layer.isDate(v);
996
+ } else {
997
+ return this.v3Layer.isDate(v);
998
+ }
999
+ }
1000
+ isDefault(v) {
1001
+ if ("_zod" in v) {
1002
+ return this.v4Layer.isDefault(v);
1003
+ } else {
1004
+ return this.v3Layer.isDefault(v);
1005
+ }
1006
+ }
1007
+ defaultZodObjectHandler(value, options = { passthrough: true }) {
1008
+ if ("_zod" in value) {
1009
+ return this.v4Layer.defaultZodObjectHandler(value, options);
1010
+ } else {
1011
+ return this.v3Layer.defaultZodObjectHandler(value, options);
1012
+ }
1013
+ }
1014
+ /**
1015
+ * Merges validation constraints into a parameter description.
1016
+ *
1017
+ * This helper method converts validation constraints that may not be supported
1018
+ * by a provider into human-readable descriptions.
1019
+ *
1020
+ * @param description - The existing parameter description
1021
+ * @param constraints - The validation constraints to merge
1022
+ * @returns The updated description with constraints, or undefined if no constraints
1023
+ */
1024
+ mergeParameterDescription(description, constraints) {
1025
+ return this.v3Layer.mergeParameterDescription(description, constraints);
1026
+ }
1027
+ /**
1028
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
1029
+ *
1030
+ * @param value - The Zod type to check
1031
+ * @param throwOnTypes - Array of type names to throw errors for
1032
+ * @returns The original value if not in the throw list
1033
+ * @throws Error if the type is in the unsupported list
1034
+ */
1035
+ defaultUnsupportedZodTypeHandler(value, throwOnTypes) {
1036
+ if ("_zod" in value) {
1037
+ return this.v4Layer.defaultUnsupportedZodTypeHandler(
1038
+ // @ts-expect-error - fix later
1039
+ value,
1040
+ throwOnTypes ?? UNSUPPORTED_ZOD_TYPES2
1041
+ );
1042
+ } else {
1043
+ return this.v3Layer.defaultUnsupportedZodTypeHandler(
1044
+ value,
1045
+ throwOnTypes ?? UNSUPPORTED_ZOD_TYPES
1046
+ );
1047
+ }
1048
+ }
1049
+ defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
1050
+ if ("_zod" in value) {
1051
+ return this.v4Layer.defaultZodArrayHandler(value, handleChecks);
1052
+ } else {
1053
+ return this.v3Layer.defaultZodArrayHandler(value, handleChecks);
1054
+ }
1055
+ }
1056
+ defaultZodUnionHandler(value) {
1057
+ if ("_zod" in value) {
1058
+ return this.v4Layer.defaultZodUnionHandler(value);
1059
+ } else {
1060
+ return this.v3Layer.defaultZodUnionHandler(value);
1061
+ }
1062
+ }
1063
+ defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
1064
+ if ("_zod" in value) {
1065
+ return this.v4Layer.defaultZodStringHandler(value);
1066
+ } else {
1067
+ return this.v3Layer.defaultZodStringHandler(value, handleChecks);
1068
+ }
1069
+ }
1070
+ defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
1071
+ if ("_zod" in value) {
1072
+ return this.v4Layer.defaultZodNumberHandler(value);
1073
+ } else {
1074
+ return this.v3Layer.defaultZodNumberHandler(value, handleChecks);
1075
+ }
1076
+ }
1077
+ defaultZodDateHandler(value) {
1078
+ if ("_zod" in value) {
1079
+ return this.v4Layer.defaultZodDateHandler(value);
1080
+ } else {
1081
+ return this.v3Layer.defaultZodDateHandler(value);
1082
+ }
1083
+ }
1084
+ defaultZodOptionalHandler(value, handleTypes) {
1085
+ if ("_zod" in value) {
1086
+ return this.v4Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES2);
1087
+ } else {
1088
+ return this.v3Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES);
1089
+ }
1090
+ }
1091
+ /**
1092
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
1093
+ *
1094
+ * @param zodSchema - The Zod object schema to process
1095
+ * @returns An AI SDK Schema with provider-specific compatibility applied
1096
+ */
1097
+ processToAISDKSchema(zodSchema) {
1098
+ const processedSchema = this.processZodType(zodSchema);
1099
+ return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
1100
+ }
1101
+ /**
1102
+ * Processes a Zod object schema and converts it to a JSON Schema.
1103
+ *
1104
+ * @param zodSchema - The Zod object schema to process
1105
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
1106
+ */
1107
+ processToJSONSchema(zodSchema) {
1108
+ return this.processToAISDKSchema(zodSchema).jsonSchema;
1109
+ }
1110
+ };
1111
+
1112
+ // src/zodTypes.ts
1113
+ function isOptional2(z10) {
1114
+ return (v) => v instanceof z10["ZodOptional"];
1115
+ }
1116
+ function isObj2(z10) {
1117
+ return (v) => v instanceof z10["ZodObject"];
1118
+ }
1119
+ function isNull(z10) {
1120
+ return (v) => v instanceof z10["ZodNull"];
1121
+ }
1122
+ function isArr2(z10) {
1123
+ return (v) => v instanceof z10["ZodArray"];
1124
+ }
1125
+ function isUnion2(z10) {
1126
+ return (v) => v instanceof z10["ZodUnion"];
1127
+ }
1128
+ function isString2(z10) {
1129
+ return (v) => v instanceof z10["ZodString"];
1130
+ }
1131
+ function isNumber2(z10) {
1132
+ return (v) => v instanceof z10["ZodNumber"];
1133
+ }
1134
+ function isDate(z10) {
1135
+ return (v) => v instanceof z10["ZodDate"];
1136
+ }
1137
+ function isDefault(z10) {
1138
+ return (v) => v instanceof z10["ZodDefault"];
1139
+ }
416
1140
 
417
1141
  // src/provider-compats/anthropic.ts
418
- var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
1142
+ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
419
1143
  constructor(model) {
420
1144
  super(model);
421
1145
  }
@@ -426,29 +1150,38 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
426
1150
  return this.getModel().modelId.includes("claude");
427
1151
  }
428
1152
  processZodType(value) {
429
- if (isOptional(value)) {
430
- const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
1153
+ if (isOptional2(z)(value)) {
1154
+ const handleTypes = [
1155
+ "ZodObject",
1156
+ "ZodArray",
1157
+ "ZodUnion",
1158
+ "ZodNever",
1159
+ "ZodUndefined",
1160
+ "ZodTuple"
1161
+ ];
431
1162
  if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
432
1163
  return this.defaultZodOptionalHandler(value, handleTypes);
433
- } else if (isObj(value)) {
1164
+ } else if (isObj2(z)(value)) {
434
1165
  return this.defaultZodObjectHandler(value);
435
- } else if (isArr(value)) {
1166
+ } else if (isArr2(z)(value)) {
436
1167
  return this.defaultZodArrayHandler(value, []);
437
- } else if (isUnion(value)) {
1168
+ } else if (isUnion2(z)(value)) {
438
1169
  return this.defaultZodUnionHandler(value);
439
- } else if (isString(value)) {
1170
+ } else if (isString2(z)(value)) {
440
1171
  if (this.getModel().modelId.includes("claude-3.5-haiku")) {
441
1172
  return this.defaultZodStringHandler(value, ["max", "min"]);
442
1173
  } else {
443
1174
  return value;
444
1175
  }
445
1176
  }
446
- return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
1177
+ return this.defaultUnsupportedZodTypeHandler(value, [
1178
+ "ZodNever",
1179
+ "ZodTuple",
1180
+ "ZodUndefined"
1181
+ ]);
447
1182
  }
448
1183
  };
449
-
450
- // src/provider-compats/deepseek.ts
451
- var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
1184
+ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
452
1185
  constructor(model) {
453
1186
  super(model);
454
1187
  }
@@ -459,21 +1192,21 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
459
1192
  return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
460
1193
  }
461
1194
  processZodType(value) {
462
- if (isOptional(value)) {
1195
+ if (isOptional2(z)(value)) {
463
1196
  return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
464
- } else if (isObj(value)) {
1197
+ } else if (isObj2(z)(value)) {
465
1198
  return this.defaultZodObjectHandler(value);
466
- } else if (isArr(value)) {
1199
+ } else if (isArr2(z)(value)) {
467
1200
  return this.defaultZodArrayHandler(value, ["min", "max"]);
468
- } else if (isUnion(value)) {
1201
+ } else if (isUnion2(z)(value)) {
469
1202
  return this.defaultZodUnionHandler(value);
470
- } else if (isString(value)) {
1203
+ } else if (isString2(z)(value)) {
471
1204
  return this.defaultZodStringHandler(value);
472
1205
  }
473
1206
  return value;
474
1207
  }
475
1208
  };
476
- var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
1209
+ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
477
1210
  constructor(model) {
478
1211
  super(model);
479
1212
  }
@@ -484,34 +1217,25 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
484
1217
  return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
485
1218
  }
486
1219
  processZodType(value) {
487
- if (isOptional(value)) {
488
- return this.defaultZodOptionalHandler(value, [
489
- "ZodObject",
490
- "ZodArray",
491
- "ZodUnion",
492
- "ZodString",
493
- "ZodNumber",
494
- ...UNSUPPORTED_ZOD_TYPES
495
- ]);
496
- } else if (isNull(value)) {
497
- return z.any().refine((v) => v === null, { message: "must be null" }).describe(value._def.description || "must be null");
498
- } else if (isObj(value)) {
1220
+ if (isOptional2(z)(value)) {
1221
+ return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
1222
+ } else if (isNull(z)(value)) {
1223
+ return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
1224
+ } else if (isObj2(z)(value)) {
499
1225
  return this.defaultZodObjectHandler(value);
500
- } else if (isArr(value)) {
1226
+ } else if (isArr2(z)(value)) {
501
1227
  return this.defaultZodArrayHandler(value, []);
502
- } else if (isUnion(value)) {
1228
+ } else if (isUnion2(z)(value)) {
503
1229
  return this.defaultZodUnionHandler(value);
504
- } else if (isString(value)) {
1230
+ } else if (isString2(z)(value)) {
505
1231
  return this.defaultZodStringHandler(value);
506
- } else if (isNumber(value)) {
1232
+ } else if (isNumber2(z)(value)) {
507
1233
  return this.defaultZodNumberHandler(value);
508
1234
  }
509
1235
  return this.defaultUnsupportedZodTypeHandler(value);
510
1236
  }
511
1237
  };
512
-
513
- // src/provider-compats/meta.ts
514
- var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
1238
+ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
515
1239
  constructor(model) {
516
1240
  super(model);
517
1241
  }
@@ -522,25 +1246,23 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
522
1246
  return this.getModel().modelId.includes("meta");
523
1247
  }
524
1248
  processZodType(value) {
525
- if (isOptional(value)) {
1249
+ if (isOptional2(z)(value)) {
526
1250
  return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
527
- } else if (isObj(value)) {
1251
+ } else if (isObj2(z)(value)) {
528
1252
  return this.defaultZodObjectHandler(value);
529
- } else if (isArr(value)) {
1253
+ } else if (isArr2(z)(value)) {
530
1254
  return this.defaultZodArrayHandler(value, ["min", "max"]);
531
- } else if (isUnion(value)) {
1255
+ } else if (isUnion2(z)(value)) {
532
1256
  return this.defaultZodUnionHandler(value);
533
- } else if (isNumber(value)) {
1257
+ } else if (isNumber2(z)(value)) {
534
1258
  return this.defaultZodNumberHandler(value);
535
- } else if (isString(value)) {
1259
+ } else if (isString2(z)(value)) {
536
1260
  return this.defaultZodStringHandler(value);
537
1261
  }
538
1262
  return value;
539
1263
  }
540
1264
  };
541
-
542
- // src/provider-compats/openai.ts
543
- var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
1265
+ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
544
1266
  constructor(model) {
545
1267
  super(model);
546
1268
  }
@@ -548,16 +1270,13 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
548
1270
  return `jsonSchema7`;
549
1271
  }
550
1272
  shouldApply() {
551
- if (
552
- // !this.getModel().supportsStructuredOutputs && // <- TODO: this no longer exists, do we need it?
553
- this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`)
554
- ) {
1273
+ if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
555
1274
  return true;
556
1275
  }
557
1276
  return false;
558
1277
  }
559
1278
  processZodType(value) {
560
- if (isOptional(value)) {
1279
+ if (isOptional2(z)(value)) {
561
1280
  return this.defaultZodOptionalHandler(value, [
562
1281
  "ZodObject",
563
1282
  "ZodArray",
@@ -567,24 +1286,28 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
567
1286
  "ZodUndefined",
568
1287
  "ZodTuple"
569
1288
  ]);
570
- } else if (isObj(value)) {
1289
+ } else if (isObj2(z)(value)) {
571
1290
  return this.defaultZodObjectHandler(value);
572
- } else if (isUnion(value)) {
1291
+ } else if (isUnion2(z)(value)) {
573
1292
  return this.defaultZodUnionHandler(value);
574
- } else if (isArr(value)) {
1293
+ } else if (isArr2(z)(value)) {
575
1294
  return this.defaultZodArrayHandler(value);
576
- } else if (isString(value)) {
1295
+ } else if (isString2(z)(value)) {
577
1296
  const model = this.getModel();
578
1297
  const checks = ["emoji"];
579
1298
  if (model.modelId.includes("gpt-4o-mini")) {
580
- checks.push("regex");
1299
+ return this.defaultZodStringHandler(value, ["emoji", "regex"]);
581
1300
  }
582
1301
  return this.defaultZodStringHandler(value, checks);
583
1302
  }
584
- return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
1303
+ return this.defaultUnsupportedZodTypeHandler(value, [
1304
+ "ZodNever",
1305
+ "ZodUndefined",
1306
+ "ZodTuple"
1307
+ ]);
585
1308
  }
586
1309
  };
587
- var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
1310
+ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
588
1311
  constructor(model) {
589
1312
  super(model);
590
1313
  }
@@ -592,34 +1315,31 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
592
1315
  return `openApi3`;
593
1316
  }
594
1317
  isReasoningModel() {
595
- return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
1318
+ return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
596
1319
  }
597
1320
  shouldApply() {
598
- if (
599
- // (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && // <- supportsStructuredOutputs no longer exists
600
- this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
601
- ) {
1321
+ if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
602
1322
  return true;
603
1323
  }
604
1324
  return false;
605
1325
  }
606
1326
  processZodType(value) {
607
- if (isOptional(value)) {
1327
+ if (isOptional2(z)(value)) {
608
1328
  const innerZodType = this.processZodType(value._def.innerType);
609
1329
  return innerZodType.nullable();
610
- } else if (isObj(value)) {
1330
+ } else if (isObj2(z)(value)) {
611
1331
  return this.defaultZodObjectHandler(value, { passthrough: false });
612
- } else if (isArr(value)) {
1332
+ } else if (isArr2(z)(value)) {
613
1333
  return this.defaultZodArrayHandler(value);
614
- } else if (isUnion(value)) {
1334
+ } else if (isUnion2(z)(value)) {
615
1335
  return this.defaultZodUnionHandler(value);
616
- } else if (isDefault(value)) {
1336
+ } else if (isDefault(z)(value)) {
617
1337
  const defaultDef = value._def;
618
1338
  const innerType = defaultDef.innerType;
619
- const defaultValue = defaultDef.defaultValue();
620
- const constraints = {};
1339
+ const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
1340
+ const constraints = [];
621
1341
  if (defaultValue !== void 0) {
622
- constraints.defaultValue = defaultValue;
1342
+ constraints.push(`the default value is ${defaultValue}`);
623
1343
  }
624
1344
  const description = this.mergeParameterDescription(value.description, constraints);
625
1345
  let result = this.processZodType(innerType);
@@ -627,13 +1347,13 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
627
1347
  result = result.describe(description);
628
1348
  }
629
1349
  return result;
630
- } else if (isNumber(value)) {
1350
+ } else if (isNumber2(z)(value)) {
631
1351
  return this.defaultZodNumberHandler(value);
632
- } else if (isString(value)) {
1352
+ } else if (isString2(z)(value)) {
633
1353
  return this.defaultZodStringHandler(value);
634
- } else if (isDate(value)) {
1354
+ } else if (isDate(z)(value)) {
635
1355
  return this.defaultZodDateHandler(value);
636
- } else if (value._def.typeName === "ZodAny") {
1356
+ } else if (value.constructor.name === "ZodAny") {
637
1357
  return z.string().describe(
638
1358
  (value.description ?? "") + `
639
1359
  Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
@@ -643,6 +1363,6 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
643
1363
  }
644
1364
  };
645
1365
 
646
- export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, convertSchemaToZod, convertZodSchemaToAISDKSchema, isArr, isNumber, isObj, isOptional, isString, isUnion };
1366
+ export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer3 as SchemaCompatLayer, SchemaCompatLayer as SchemaCompatLayerV3, SchemaCompatLayer2 as SchemaCompatLayerV4, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, convertSchemaToZod, convertZodSchemaToAISDKSchema, isArr, isNumber, isObj, isOptional, isString, isUnion };
647
1367
  //# sourceMappingURL=index.js.map
648
1368
  //# sourceMappingURL=index.js.map