@mastra/schema-compat 0.0.0-ai-v5-20250813235735 → 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 +107 -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 +859 -134
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +3 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +858 -135
  12. package/dist/index.js.map +1 -1
  13. package/dist/provider-compats/anthropic.d.ts +5 -3
  14. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  15. package/dist/provider-compats/deepseek.d.ts +5 -3
  16. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  17. package/dist/provider-compats/google.d.ts +5 -3
  18. package/dist/provider-compats/google.d.ts.map +1 -1
  19. package/dist/provider-compats/meta.d.ts +5 -3
  20. package/dist/provider-compats/meta.d.ts.map +1 -1
  21. package/dist/provider-compats/openai-reasoning.d.ts +5 -3
  22. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  23. package/dist/provider-compats/openai.d.ts +5 -3
  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 +79 -164
  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 +16 -4
  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 +34 -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 -62
  54. package/src/provider-compats/meta.ts +0 -36
  55. package/src/provider-compats/openai-reasoning.ts +0 -91
  56. package/src/provider-compats/openai.ts +0 -56
  57. package/src/provider-compats.test.ts +0 -383
  58. package/src/schema-compatibility.test.ts +0 -491
  59. package/src/schema-compatibility.ts +0 -592
  60. package/src/utils.test.ts +0 -463
  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 -17
  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,35 +320,20 @@ var SchemaCompatLayer = class {
236
320
  if (handleChecks.includes(check.kind)) {
237
321
  switch (check.kind) {
238
322
  case "regex": {
239
- constraints.regex = `A string that must match the regex pattern: ${check.regex.source}, with flags: ${check.regex.flags}`;
240
- break;
241
- }
242
- case "emoji": {
243
- constraints.emoji = true;
244
- break;
245
- }
246
- case "email": {
247
- constraints.email = true;
248
- break;
249
- }
250
- case "url": {
251
- constraints.url = true;
252
- break;
253
- }
254
- case "uuid": {
255
- constraints.uuid = true;
323
+ constraints.push(`input must match this regex ${check.regex.source}`);
256
324
  break;
257
325
  }
326
+ case "emoji":
327
+ case "email":
328
+ case "url":
329
+ case "uuid":
258
330
  case "cuid": {
259
- constraints.cuid = true;
260
- break;
261
- }
262
- case "min": {
263
- constraints.minLength = check.value;
331
+ constraints.push(`a valid ${check.kind}`);
264
332
  break;
265
333
  }
334
+ case "min":
266
335
  case "max": {
267
- constraints.maxLength = check.value;
336
+ constraints.push(`${check.kind}imum length ${check.value}`);
268
337
  break;
269
338
  }
270
339
  }
@@ -291,7 +360,7 @@ var SchemaCompatLayer = class {
291
360
  * @returns The processed Zod number
292
361
  */
293
362
  defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
294
- const constraints = {};
363
+ const constraints = [];
295
364
  const checks = value._def.checks || [];
296
365
  const newChecks = [];
297
366
  for (const check of checks) {
@@ -300,20 +369,20 @@ var SchemaCompatLayer = class {
300
369
  switch (check.kind) {
301
370
  case "min":
302
371
  if (check.inclusive) {
303
- constraints.gte = check.value;
372
+ constraints.push(`greater than or equal to ${check.value}`);
304
373
  } else {
305
- constraints.gt = check.value;
374
+ constraints.push(`greater than ${check.value}`);
306
375
  }
307
376
  break;
308
377
  case "max":
309
378
  if (check.inclusive) {
310
- constraints.lte = check.value;
379
+ constraints.push(`lower than or equal to ${check.value}`);
311
380
  } else {
312
- constraints.lt = check.value;
381
+ constraints.push(`lower than ${check.value}`);
313
382
  }
314
383
  break;
315
384
  case "multipleOf": {
316
- constraints.multipleOf = check.value;
385
+ constraints.push(`multiple of ${check.value}`);
317
386
  break;
318
387
  }
319
388
  }
@@ -348,7 +417,7 @@ var SchemaCompatLayer = class {
348
417
  * @returns A Zod string schema representing the date in ISO format
349
418
  */
350
419
  defaultZodDateHandler(value) {
351
- const constraints = {};
420
+ const constraints = [];
352
421
  const checks = value._def.checks || [];
353
422
  for (const check of checks) {
354
423
  if ("kind" in check) {
@@ -356,19 +425,19 @@ var SchemaCompatLayer = class {
356
425
  case "min":
357
426
  const minDate = new Date(check.value);
358
427
  if (!isNaN(minDate.getTime())) {
359
- constraints.minDate = minDate.toISOString();
428
+ constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
360
429
  }
361
430
  break;
362
431
  case "max":
363
432
  const maxDate = new Date(check.value);
364
433
  if (!isNaN(maxDate.getTime())) {
365
- constraints.maxDate = maxDate.toISOString();
434
+ constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
366
435
  }
367
436
  break;
368
437
  }
369
438
  }
370
439
  }
371
- constraints.dateFormat = "date-time";
440
+ constraints.push(`Date format is date-time`);
372
441
  let result = z.string().describe("date-time");
373
442
  const description = this.mergeParameterDescription(value.description, constraints);
374
443
  if (description) {
@@ -410,9 +479,667 @@ var SchemaCompatLayer = class {
410
479
  return this.processToAISDKSchema(zodSchema).jsonSchema;
411
480
  }
412
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
+ }
413
1140
 
414
1141
  // src/provider-compats/anthropic.ts
415
- var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
1142
+ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
416
1143
  constructor(model) {
417
1144
  super(model);
418
1145
  }
@@ -423,29 +1150,38 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
423
1150
  return this.getModel().modelId.includes("claude");
424
1151
  }
425
1152
  processZodType(value) {
426
- if (isOptional(value)) {
427
- 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
+ ];
428
1162
  if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
429
1163
  return this.defaultZodOptionalHandler(value, handleTypes);
430
- } else if (isObj(value)) {
1164
+ } else if (isObj2(z)(value)) {
431
1165
  return this.defaultZodObjectHandler(value);
432
- } else if (isArr(value)) {
1166
+ } else if (isArr2(z)(value)) {
433
1167
  return this.defaultZodArrayHandler(value, []);
434
- } else if (isUnion(value)) {
1168
+ } else if (isUnion2(z)(value)) {
435
1169
  return this.defaultZodUnionHandler(value);
436
- } else if (isString(value)) {
1170
+ } else if (isString2(z)(value)) {
437
1171
  if (this.getModel().modelId.includes("claude-3.5-haiku")) {
438
1172
  return this.defaultZodStringHandler(value, ["max", "min"]);
439
1173
  } else {
440
1174
  return value;
441
1175
  }
442
1176
  }
443
- return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
1177
+ return this.defaultUnsupportedZodTypeHandler(value, [
1178
+ "ZodNever",
1179
+ "ZodTuple",
1180
+ "ZodUndefined"
1181
+ ]);
444
1182
  }
445
1183
  };
446
-
447
- // src/provider-compats/deepseek.ts
448
- var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
1184
+ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
449
1185
  constructor(model) {
450
1186
  super(model);
451
1187
  }
@@ -456,21 +1192,21 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
456
1192
  return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
457
1193
  }
458
1194
  processZodType(value) {
459
- if (isOptional(value)) {
1195
+ if (isOptional2(z)(value)) {
460
1196
  return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
461
- } else if (isObj(value)) {
1197
+ } else if (isObj2(z)(value)) {
462
1198
  return this.defaultZodObjectHandler(value);
463
- } else if (isArr(value)) {
1199
+ } else if (isArr2(z)(value)) {
464
1200
  return this.defaultZodArrayHandler(value, ["min", "max"]);
465
- } else if (isUnion(value)) {
1201
+ } else if (isUnion2(z)(value)) {
466
1202
  return this.defaultZodUnionHandler(value);
467
- } else if (isString(value)) {
1203
+ } else if (isString2(z)(value)) {
468
1204
  return this.defaultZodStringHandler(value);
469
1205
  }
470
1206
  return value;
471
1207
  }
472
1208
  };
473
- var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
1209
+ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
474
1210
  constructor(model) {
475
1211
  super(model);
476
1212
  }
@@ -481,34 +1217,25 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
481
1217
  return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
482
1218
  }
483
1219
  processZodType(value) {
484
- if (isOptional(value)) {
485
- return this.defaultZodOptionalHandler(value, [
486
- "ZodObject",
487
- "ZodArray",
488
- "ZodUnion",
489
- "ZodString",
490
- "ZodNumber",
491
- ...UNSUPPORTED_ZOD_TYPES
492
- ]);
493
- } else if (isNull(value)) {
494
- return z.any().refine((v) => v === null, { message: "must be null" }).describe(value._def.description || "must be null");
495
- } 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)) {
496
1225
  return this.defaultZodObjectHandler(value);
497
- } else if (isArr(value)) {
1226
+ } else if (isArr2(z)(value)) {
498
1227
  return this.defaultZodArrayHandler(value, []);
499
- } else if (isUnion(value)) {
1228
+ } else if (isUnion2(z)(value)) {
500
1229
  return this.defaultZodUnionHandler(value);
501
- } else if (isString(value)) {
1230
+ } else if (isString2(z)(value)) {
502
1231
  return this.defaultZodStringHandler(value);
503
- } else if (isNumber(value)) {
1232
+ } else if (isNumber2(z)(value)) {
504
1233
  return this.defaultZodNumberHandler(value);
505
1234
  }
506
1235
  return this.defaultUnsupportedZodTypeHandler(value);
507
1236
  }
508
1237
  };
509
-
510
- // src/provider-compats/meta.ts
511
- var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
1238
+ var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
512
1239
  constructor(model) {
513
1240
  super(model);
514
1241
  }
@@ -519,25 +1246,23 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
519
1246
  return this.getModel().modelId.includes("meta");
520
1247
  }
521
1248
  processZodType(value) {
522
- if (isOptional(value)) {
1249
+ if (isOptional2(z)(value)) {
523
1250
  return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
524
- } else if (isObj(value)) {
1251
+ } else if (isObj2(z)(value)) {
525
1252
  return this.defaultZodObjectHandler(value);
526
- } else if (isArr(value)) {
1253
+ } else if (isArr2(z)(value)) {
527
1254
  return this.defaultZodArrayHandler(value, ["min", "max"]);
528
- } else if (isUnion(value)) {
1255
+ } else if (isUnion2(z)(value)) {
529
1256
  return this.defaultZodUnionHandler(value);
530
- } else if (isNumber(value)) {
1257
+ } else if (isNumber2(z)(value)) {
531
1258
  return this.defaultZodNumberHandler(value);
532
- } else if (isString(value)) {
1259
+ } else if (isString2(z)(value)) {
533
1260
  return this.defaultZodStringHandler(value);
534
1261
  }
535
1262
  return value;
536
1263
  }
537
1264
  };
538
-
539
- // src/provider-compats/openai.ts
540
- var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
1265
+ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
541
1266
  constructor(model) {
542
1267
  super(model);
543
1268
  }
@@ -545,16 +1270,13 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
545
1270
  return `jsonSchema7`;
546
1271
  }
547
1272
  shouldApply() {
548
- if (
549
- // !this.getModel().supportsStructuredOutputs && // <- TODO: this no longer exists, do we need it?
550
- this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`)
551
- ) {
1273
+ if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
552
1274
  return true;
553
1275
  }
554
1276
  return false;
555
1277
  }
556
1278
  processZodType(value) {
557
- if (isOptional(value)) {
1279
+ if (isOptional2(z)(value)) {
558
1280
  return this.defaultZodOptionalHandler(value, [
559
1281
  "ZodObject",
560
1282
  "ZodArray",
@@ -564,24 +1286,28 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
564
1286
  "ZodUndefined",
565
1287
  "ZodTuple"
566
1288
  ]);
567
- } else if (isObj(value)) {
1289
+ } else if (isObj2(z)(value)) {
568
1290
  return this.defaultZodObjectHandler(value);
569
- } else if (isUnion(value)) {
1291
+ } else if (isUnion2(z)(value)) {
570
1292
  return this.defaultZodUnionHandler(value);
571
- } else if (isArr(value)) {
1293
+ } else if (isArr2(z)(value)) {
572
1294
  return this.defaultZodArrayHandler(value);
573
- } else if (isString(value)) {
1295
+ } else if (isString2(z)(value)) {
574
1296
  const model = this.getModel();
575
1297
  const checks = ["emoji"];
576
1298
  if (model.modelId.includes("gpt-4o-mini")) {
577
- checks.push("regex");
1299
+ return this.defaultZodStringHandler(value, ["emoji", "regex"]);
578
1300
  }
579
1301
  return this.defaultZodStringHandler(value, checks);
580
1302
  }
581
- return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
1303
+ return this.defaultUnsupportedZodTypeHandler(value, [
1304
+ "ZodNever",
1305
+ "ZodUndefined",
1306
+ "ZodTuple"
1307
+ ]);
582
1308
  }
583
1309
  };
584
- var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
1310
+ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
585
1311
  constructor(model) {
586
1312
  super(model);
587
1313
  }
@@ -592,31 +1318,28 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
592
1318
  return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
593
1319
  }
594
1320
  shouldApply() {
595
- if (
596
- // (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && // <- supportsStructuredOutputs no longer exists
597
- this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
598
- ) {
1321
+ if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
599
1322
  return true;
600
1323
  }
601
1324
  return false;
602
1325
  }
603
1326
  processZodType(value) {
604
- if (isOptional(value)) {
1327
+ if (isOptional2(z)(value)) {
605
1328
  const innerZodType = this.processZodType(value._def.innerType);
606
1329
  return innerZodType.nullable();
607
- } else if (isObj(value)) {
1330
+ } else if (isObj2(z)(value)) {
608
1331
  return this.defaultZodObjectHandler(value, { passthrough: false });
609
- } else if (isArr(value)) {
1332
+ } else if (isArr2(z)(value)) {
610
1333
  return this.defaultZodArrayHandler(value);
611
- } else if (isUnion(value)) {
1334
+ } else if (isUnion2(z)(value)) {
612
1335
  return this.defaultZodUnionHandler(value);
613
- } else if (isDefault(value)) {
1336
+ } else if (isDefault(z)(value)) {
614
1337
  const defaultDef = value._def;
615
1338
  const innerType = defaultDef.innerType;
616
- const defaultValue = defaultDef.defaultValue();
617
- const constraints = {};
1339
+ const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
1340
+ const constraints = [];
618
1341
  if (defaultValue !== void 0) {
619
- constraints.defaultValue = defaultValue;
1342
+ constraints.push(`the default value is ${defaultValue}`);
620
1343
  }
621
1344
  const description = this.mergeParameterDescription(value.description, constraints);
622
1345
  let result = this.processZodType(innerType);
@@ -624,13 +1347,13 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
624
1347
  result = result.describe(description);
625
1348
  }
626
1349
  return result;
627
- } else if (isNumber(value)) {
1350
+ } else if (isNumber2(z)(value)) {
628
1351
  return this.defaultZodNumberHandler(value);
629
- } else if (isString(value)) {
1352
+ } else if (isString2(z)(value)) {
630
1353
  return this.defaultZodStringHandler(value);
631
- } else if (isDate(value)) {
1354
+ } else if (isDate(z)(value)) {
632
1355
  return this.defaultZodDateHandler(value);
633
- } else if (value._def.typeName === "ZodAny") {
1356
+ } else if (value.constructor.name === "ZodAny") {
634
1357
  return z.string().describe(
635
1358
  (value.description ?? "") + `
636
1359
  Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
@@ -640,6 +1363,6 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
640
1363
  }
641
1364
  };
642
1365
 
643
- 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 };
644
1367
  //# sourceMappingURL=index.js.map
645
1368
  //# sourceMappingURL=index.js.map