@mastra/schema-compat 0.10.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,709 @@
1
+ import { z } from 'zod';
2
+ import { jsonSchema } from 'ai';
3
+ import { convertJsonSchemaToZod } from 'zod-from-json-schema';
4
+ import { zodToJsonSchema } from 'zod-to-json-schema';
5
+
6
+ // src/schema-compatibility.ts
7
+ 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
+ }
18
+ }
19
+ );
20
+ }
21
+ function isZodType(value) {
22
+ return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
23
+ }
24
+ function convertSchemaToZod(schema) {
25
+ if (isZodType(schema)) {
26
+ return schema;
27
+ } else {
28
+ const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
29
+ try {
30
+ return convertJsonSchemaToZod(jsonSchemaToConvert);
31
+ } catch (e) {
32
+ const errorMessage = `[Schema Builder] Failed to convert schema parameters to Zod. Original schema: ${JSON.stringify(jsonSchemaToConvert)}`;
33
+ console.error(errorMessage, e);
34
+ throw new Error(errorMessage + (e instanceof Error ? `
35
+ ${e.stack}` : "\nUnknown error object"));
36
+ }
37
+ }
38
+ }
39
+ function applyCompatLayer({
40
+ schema,
41
+ compatLayers,
42
+ mode
43
+ }) {
44
+ let zodSchema;
45
+ if (!isZodType(schema)) {
46
+ const convertedSchema = convertSchemaToZod(schema);
47
+ if (convertedSchema instanceof z.ZodObject) {
48
+ zodSchema = convertedSchema;
49
+ } else {
50
+ zodSchema = z.object({ value: convertedSchema });
51
+ }
52
+ } else {
53
+ if (schema instanceof z.ZodObject) {
54
+ zodSchema = schema;
55
+ } else {
56
+ zodSchema = z.object({ value: schema });
57
+ }
58
+ }
59
+ for (const compat of compatLayers) {
60
+ if (compat.shouldApply()) {
61
+ return mode === "jsonSchema" ? compat.processToJSONSchema(zodSchema) : compat.processToAISDKSchema(zodSchema);
62
+ }
63
+ }
64
+ if (mode === "jsonSchema") {
65
+ return zodToJsonSchema(zodSchema, { $refStrategy: "none", target: "jsonSchema7" });
66
+ } else {
67
+ return convertZodSchemaToAISDKSchema(zodSchema);
68
+ }
69
+ }
70
+
71
+ // src/schema-compatibility.ts
72
+ var ALL_STRING_CHECKS = ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
73
+ var ALL_NUMBER_CHECKS = [
74
+ "min",
75
+ // gte internally
76
+ "max",
77
+ // lte internally
78
+ "multipleOf"
79
+ ];
80
+ var ALL_ARRAY_CHECKS = ["min", "max", "length"];
81
+ var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
82
+ var SUPPORTED_ZOD_TYPES = [
83
+ "ZodObject",
84
+ "ZodArray",
85
+ "ZodUnion",
86
+ "ZodString",
87
+ "ZodNumber",
88
+ "ZodDate",
89
+ "ZodAny",
90
+ "ZodDefault"
91
+ ];
92
+ var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
93
+ var SchemaCompatLayer = class {
94
+ model;
95
+ /**
96
+ * Creates a new schema compatibility instance.
97
+ *
98
+ * @param model - The language model this compatibility layer applies to
99
+ */
100
+ constructor(model) {
101
+ this.model = model;
102
+ }
103
+ /**
104
+ * Gets the language model associated with this compatibility layer.
105
+ *
106
+ * @returns The language model instance
107
+ */
108
+ getModel() {
109
+ return this.model;
110
+ }
111
+ /**
112
+ * Applies compatibility transformations to a Zod object schema.
113
+ *
114
+ * @param zodSchema - The Zod object schema to transform
115
+ * @returns Object containing the transformed schema
116
+ * @private
117
+ */
118
+ applyZodSchemaCompatibility(zodSchema) {
119
+ const newSchema = z.object(
120
+ Object.entries(zodSchema.shape || {}).reduce(
121
+ (acc, [key, value]) => ({
122
+ ...acc,
123
+ [key]: this.processZodType(value)
124
+ }),
125
+ {}
126
+ )
127
+ );
128
+ return { schema: newSchema };
129
+ }
130
+ /**
131
+ * Default handler for Zod object types. Recursively processes all properties in the object.
132
+ *
133
+ * @param value - The Zod object to process
134
+ * @returns The processed Zod object
135
+ */
136
+ defaultZodObjectHandler(value) {
137
+ const zodObject = value;
138
+ const processedShape = Object.entries(zodObject.shape || {}).reduce(
139
+ (acc, [key, propValue]) => {
140
+ const typedPropValue = propValue;
141
+ const processedValue = this.processZodType(typedPropValue);
142
+ acc[key] = processedValue;
143
+ return acc;
144
+ },
145
+ {}
146
+ );
147
+ let result = z.object(processedShape);
148
+ if (value.description) {
149
+ result = result.describe(value.description);
150
+ }
151
+ return result;
152
+ }
153
+ /**
154
+ * Merges validation constraints into a parameter description.
155
+ *
156
+ * This helper method converts validation constraints that may not be supported
157
+ * by a provider into human-readable descriptions.
158
+ *
159
+ * @param description - The existing parameter description
160
+ * @param constraints - The validation constraints to merge
161
+ * @returns The updated description with constraints, or undefined if no constraints
162
+ */
163
+ mergeParameterDescription(description, constraints) {
164
+ if (Object.keys(constraints).length > 0) {
165
+ return (description ? description + "\n" : "") + JSON.stringify(constraints);
166
+ } else {
167
+ return description;
168
+ }
169
+ }
170
+ /**
171
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
172
+ *
173
+ * @param value - The Zod type to check
174
+ * @param throwOnTypes - Array of type names to throw errors for
175
+ * @returns The original value if not in the throw list
176
+ * @throws Error if the type is in the unsupported list
177
+ */
178
+ defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES) {
179
+ if (throwOnTypes.includes(value._def.typeName)) {
180
+ throw new Error(`${this.model.modelId} does not support zod type: ${value._def.typeName}`);
181
+ }
182
+ return value;
183
+ }
184
+ /**
185
+ * Default handler for Zod array types. Processes array constraints according to provider support.
186
+ *
187
+ * @param value - The Zod array to process
188
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
189
+ * @returns The processed Zod array
190
+ */
191
+ defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
192
+ const zodArray = value._def;
193
+ const arrayType = zodArray.type;
194
+ const constraints = {};
195
+ if (zodArray.minLength?.value !== void 0 && handleChecks.includes("min")) {
196
+ constraints.minLength = zodArray.minLength.value;
197
+ }
198
+ if (zodArray.maxLength?.value !== void 0 && handleChecks.includes("max")) {
199
+ constraints.maxLength = zodArray.maxLength.value;
200
+ }
201
+ if (zodArray.exactLength?.value !== void 0 && handleChecks.includes("length")) {
202
+ constraints.exactLength = zodArray.exactLength.value;
203
+ }
204
+ const processedType = arrayType._def.typeName === "ZodObject" ? this.processZodType(arrayType) : arrayType;
205
+ let result = z.array(processedType);
206
+ if (zodArray.minLength?.value !== void 0 && !handleChecks.includes("min")) {
207
+ result = result.min(zodArray.minLength.value);
208
+ }
209
+ if (zodArray.maxLength?.value !== void 0 && !handleChecks.includes("max")) {
210
+ result = result.max(zodArray.maxLength.value);
211
+ }
212
+ if (zodArray.exactLength?.value !== void 0 && !handleChecks.includes("length")) {
213
+ result = result.length(zodArray.exactLength.value);
214
+ }
215
+ const description = this.mergeParameterDescription(value.description, constraints);
216
+ if (description) {
217
+ result = result.describe(description);
218
+ }
219
+ return result;
220
+ }
221
+ /**
222
+ * Default handler for Zod union types. Processes all union options.
223
+ *
224
+ * @param value - The Zod union to process
225
+ * @returns The processed Zod union
226
+ * @throws Error if union has fewer than 2 options
227
+ */
228
+ defaultZodUnionHandler(value) {
229
+ const zodUnion = value;
230
+ const processedOptions = zodUnion._def.options.map((option) => this.processZodType(option));
231
+ if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
232
+ let result = z.union(processedOptions);
233
+ if (value.description) {
234
+ result = result.describe(value.description);
235
+ }
236
+ return result;
237
+ }
238
+ /**
239
+ * Default handler for Zod string types. Processes string validation constraints.
240
+ *
241
+ * @param value - The Zod string to process
242
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
243
+ * @returns The processed Zod string
244
+ */
245
+ defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
246
+ const zodString = value;
247
+ const constraints = {};
248
+ const checks = zodString._def.checks || [];
249
+ const newChecks = [];
250
+ for (const check of checks) {
251
+ if ("kind" in check) {
252
+ if (handleChecks.includes(check.kind)) {
253
+ switch (check.kind) {
254
+ case "regex": {
255
+ constraints.regex = {
256
+ pattern: check.regex.source,
257
+ flags: check.regex.flags
258
+ };
259
+ break;
260
+ }
261
+ case "emoji": {
262
+ constraints.emoji = true;
263
+ break;
264
+ }
265
+ case "email": {
266
+ constraints.email = true;
267
+ break;
268
+ }
269
+ case "url": {
270
+ constraints.url = true;
271
+ break;
272
+ }
273
+ case "uuid": {
274
+ constraints.uuid = true;
275
+ break;
276
+ }
277
+ case "cuid": {
278
+ constraints.cuid = true;
279
+ break;
280
+ }
281
+ case "min": {
282
+ constraints.minLength = check.value;
283
+ break;
284
+ }
285
+ case "max": {
286
+ constraints.maxLength = check.value;
287
+ break;
288
+ }
289
+ }
290
+ } else {
291
+ newChecks.push(check);
292
+ }
293
+ }
294
+ }
295
+ let result = z.string();
296
+ for (const check of newChecks) {
297
+ result = result._addCheck(check);
298
+ }
299
+ const description = this.mergeParameterDescription(value.description, constraints);
300
+ if (description) {
301
+ result = result.describe(description);
302
+ }
303
+ return result;
304
+ }
305
+ /**
306
+ * Default handler for Zod number types. Processes number validation constraints.
307
+ *
308
+ * @param value - The Zod number to process
309
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
310
+ * @returns The processed Zod number
311
+ */
312
+ defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
313
+ const zodNumber = value;
314
+ const constraints = {};
315
+ const checks = zodNumber._def.checks || [];
316
+ const newChecks = [];
317
+ for (const check of checks) {
318
+ if ("kind" in check) {
319
+ if (handleChecks.includes(check.kind)) {
320
+ switch (check.kind) {
321
+ case "min":
322
+ if (check.inclusive) {
323
+ constraints.gte = check.value;
324
+ } else {
325
+ constraints.gt = check.value;
326
+ }
327
+ break;
328
+ case "max":
329
+ if (check.inclusive) {
330
+ constraints.lte = check.value;
331
+ } else {
332
+ constraints.lt = check.value;
333
+ }
334
+ break;
335
+ case "multipleOf": {
336
+ constraints.multipleOf = check.value;
337
+ break;
338
+ }
339
+ }
340
+ } else {
341
+ newChecks.push(check);
342
+ }
343
+ }
344
+ }
345
+ let result = z.number();
346
+ for (const check of newChecks) {
347
+ switch (check.kind) {
348
+ case "int":
349
+ result = result.int();
350
+ break;
351
+ case "finite":
352
+ result = result.finite();
353
+ break;
354
+ default:
355
+ result = result._addCheck(check);
356
+ }
357
+ }
358
+ const description = this.mergeParameterDescription(value.description, constraints);
359
+ if (description) {
360
+ result = result.describe(description);
361
+ }
362
+ return result;
363
+ }
364
+ /**
365
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
366
+ *
367
+ * @param value - The Zod date to process
368
+ * @returns A Zod string schema representing the date in ISO format
369
+ */
370
+ defaultZodDateHandler(value) {
371
+ const zodDate = value;
372
+ const constraints = {};
373
+ const checks = zodDate._def.checks || [];
374
+ for (const check of checks) {
375
+ if ("kind" in check) {
376
+ switch (check.kind) {
377
+ case "min":
378
+ const minDate = new Date(check.value);
379
+ if (!isNaN(minDate.getTime())) {
380
+ constraints.minDate = minDate.toISOString();
381
+ }
382
+ break;
383
+ case "max":
384
+ const maxDate = new Date(check.value);
385
+ if (!isNaN(maxDate.getTime())) {
386
+ constraints.maxDate = maxDate.toISOString();
387
+ }
388
+ break;
389
+ }
390
+ }
391
+ }
392
+ constraints.dateFormat = "date-time";
393
+ let result = z.string().describe("date-time");
394
+ const description = this.mergeParameterDescription(value.description, constraints);
395
+ if (description) {
396
+ result = result.describe(description);
397
+ }
398
+ return result;
399
+ }
400
+ /**
401
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
402
+ *
403
+ * @param value - The Zod optional to process
404
+ * @param handleTypes - Types that should be processed vs passed through
405
+ * @returns The processed Zod optional
406
+ */
407
+ defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
408
+ if (handleTypes.includes(value._def.innerType._def.typeName)) {
409
+ return this.processZodType(value._def.innerType).optional();
410
+ } else {
411
+ return value;
412
+ }
413
+ }
414
+ /**
415
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
416
+ *
417
+ * @param zodSchema - The Zod object schema to process
418
+ * @returns An AI SDK Schema with provider-specific compatibility applied
419
+ */
420
+ processToAISDKSchema(zodSchema) {
421
+ const { schema } = this.applyZodSchemaCompatibility(zodSchema);
422
+ return convertZodSchemaToAISDKSchema(schema, this.getSchemaTarget());
423
+ }
424
+ /**
425
+ * Processes a Zod object schema and converts it to a JSON Schema.
426
+ *
427
+ * @param zodSchema - The Zod object schema to process
428
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
429
+ */
430
+ processToJSONSchema(zodSchema) {
431
+ return this.processToAISDKSchema(zodSchema).jsonSchema;
432
+ }
433
+ };
434
+
435
+ // src/provider-compats/anthropic.ts
436
+ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
437
+ constructor(model) {
438
+ super(model);
439
+ }
440
+ getSchemaTarget() {
441
+ return "jsonSchema7";
442
+ }
443
+ shouldApply() {
444
+ return this.getModel().modelId.includes("claude");
445
+ }
446
+ processZodType(value) {
447
+ switch (value._def.typeName) {
448
+ case "ZodOptional":
449
+ const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
450
+ if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
451
+ if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
452
+ return this.defaultZodOptionalHandler(value, handleTypes);
453
+ case "ZodObject": {
454
+ return this.defaultZodObjectHandler(value);
455
+ }
456
+ case "ZodArray": {
457
+ return this.defaultZodArrayHandler(value, []);
458
+ }
459
+ case "ZodUnion": {
460
+ return this.defaultZodUnionHandler(value);
461
+ }
462
+ // the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
463
+ // added to the tool description
464
+ case "ZodString": {
465
+ if (this.getModel().modelId.includes("claude-3.5-haiku")) {
466
+ return this.defaultZodStringHandler(value, ["max", "min"]);
467
+ } else {
468
+ return value;
469
+ }
470
+ }
471
+ default:
472
+ if (this.getModel().modelId.includes("claude-3.7")) {
473
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
474
+ } else {
475
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
476
+ }
477
+ }
478
+ }
479
+ };
480
+
481
+ // src/provider-compats/deepseek.ts
482
+ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
483
+ constructor(model) {
484
+ super(model);
485
+ }
486
+ getSchemaTarget() {
487
+ return "jsonSchema7";
488
+ }
489
+ shouldApply() {
490
+ return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
491
+ }
492
+ processZodType(value) {
493
+ switch (value._def.typeName) {
494
+ case "ZodOptional":
495
+ return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
496
+ case "ZodObject": {
497
+ return this.defaultZodObjectHandler(value);
498
+ }
499
+ case "ZodArray": {
500
+ return this.defaultZodArrayHandler(value, ["min", "max"]);
501
+ }
502
+ case "ZodUnion": {
503
+ return this.defaultZodUnionHandler(value);
504
+ }
505
+ case "ZodString": {
506
+ return this.defaultZodStringHandler(value);
507
+ }
508
+ default:
509
+ return value;
510
+ }
511
+ }
512
+ };
513
+
514
+ // src/provider-compats/google.ts
515
+ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
516
+ constructor(model) {
517
+ super(model);
518
+ }
519
+ getSchemaTarget() {
520
+ return "jsonSchema7";
521
+ }
522
+ shouldApply() {
523
+ return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
524
+ }
525
+ processZodType(value) {
526
+ switch (value._def.typeName) {
527
+ case "ZodOptional":
528
+ return this.defaultZodOptionalHandler(value, [
529
+ "ZodObject",
530
+ "ZodArray",
531
+ "ZodUnion",
532
+ "ZodString",
533
+ "ZodNumber",
534
+ ...UNSUPPORTED_ZOD_TYPES
535
+ ]);
536
+ case "ZodObject": {
537
+ return this.defaultZodObjectHandler(value);
538
+ }
539
+ case "ZodArray": {
540
+ return this.defaultZodArrayHandler(value, []);
541
+ }
542
+ case "ZodUnion": {
543
+ return this.defaultZodUnionHandler(value);
544
+ }
545
+ // Google models support these properties but the model doesn't respect them, but it respects them when they're
546
+ // added to the tool description
547
+ case "ZodString": {
548
+ return this.defaultZodStringHandler(value);
549
+ }
550
+ case "ZodNumber": {
551
+ return this.defaultZodNumberHandler(value);
552
+ }
553
+ default:
554
+ return this.defaultUnsupportedZodTypeHandler(value);
555
+ }
556
+ }
557
+ };
558
+
559
+ // src/provider-compats/meta.ts
560
+ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
561
+ constructor(model) {
562
+ super(model);
563
+ }
564
+ getSchemaTarget() {
565
+ return "jsonSchema7";
566
+ }
567
+ shouldApply() {
568
+ return this.getModel().modelId.includes("meta");
569
+ }
570
+ processZodType(value) {
571
+ switch (value._def.typeName) {
572
+ case "ZodOptional":
573
+ return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
574
+ case "ZodObject": {
575
+ return this.defaultZodObjectHandler(value);
576
+ }
577
+ case "ZodArray": {
578
+ return this.defaultZodArrayHandler(value, ["min", "max"]);
579
+ }
580
+ case "ZodUnion": {
581
+ return this.defaultZodUnionHandler(value);
582
+ }
583
+ case "ZodNumber": {
584
+ return this.defaultZodNumberHandler(value);
585
+ }
586
+ case "ZodString": {
587
+ return this.defaultZodStringHandler(value);
588
+ }
589
+ default:
590
+ return value;
591
+ }
592
+ }
593
+ };
594
+
595
+ // src/provider-compats/openai.ts
596
+ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
597
+ constructor(model) {
598
+ super(model);
599
+ }
600
+ getSchemaTarget() {
601
+ return `jsonSchema7`;
602
+ }
603
+ shouldApply() {
604
+ if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
605
+ return true;
606
+ }
607
+ return false;
608
+ }
609
+ processZodType(value) {
610
+ switch (value._def.typeName) {
611
+ case "ZodOptional":
612
+ return this.defaultZodOptionalHandler(value, [
613
+ "ZodObject",
614
+ "ZodArray",
615
+ "ZodUnion",
616
+ "ZodString",
617
+ "ZodNever",
618
+ "ZodUndefined",
619
+ "ZodTuple"
620
+ ]);
621
+ case "ZodObject": {
622
+ return this.defaultZodObjectHandler(value);
623
+ }
624
+ case "ZodUnion": {
625
+ return this.defaultZodUnionHandler(value);
626
+ }
627
+ case "ZodArray": {
628
+ return this.defaultZodArrayHandler(value);
629
+ }
630
+ case "ZodString": {
631
+ const model = this.getModel();
632
+ const checks = ["emoji"];
633
+ if (model.modelId.includes("gpt-4o-mini")) {
634
+ checks.push("regex");
635
+ }
636
+ return this.defaultZodStringHandler(value, checks);
637
+ }
638
+ default:
639
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
640
+ }
641
+ }
642
+ };
643
+ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
644
+ constructor(model) {
645
+ super(model);
646
+ }
647
+ getSchemaTarget() {
648
+ return `openApi3`;
649
+ }
650
+ isReasoningModel() {
651
+ return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
652
+ }
653
+ shouldApply() {
654
+ if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
655
+ return true;
656
+ }
657
+ return false;
658
+ }
659
+ processZodType(value) {
660
+ switch (value._def.typeName) {
661
+ case "ZodOptional":
662
+ const innerZodType = this.processZodType(value._def.innerType);
663
+ return innerZodType.nullable();
664
+ case "ZodObject": {
665
+ return this.defaultZodObjectHandler(value);
666
+ }
667
+ case "ZodArray": {
668
+ return this.defaultZodArrayHandler(value);
669
+ }
670
+ case "ZodUnion": {
671
+ return this.defaultZodUnionHandler(value);
672
+ }
673
+ case "ZodDefault": {
674
+ const defaultDef = value._def;
675
+ const innerType = defaultDef.innerType;
676
+ const defaultValue = defaultDef.defaultValue();
677
+ const constraints = {};
678
+ if (defaultValue !== void 0) {
679
+ constraints.defaultValue = defaultValue;
680
+ }
681
+ const description = this.mergeParameterDescription(value.description, constraints);
682
+ let result = this.processZodType(innerType);
683
+ if (description) {
684
+ result = result.describe(description);
685
+ }
686
+ return result;
687
+ }
688
+ case "ZodNumber": {
689
+ return this.defaultZodNumberHandler(value);
690
+ }
691
+ case "ZodString": {
692
+ return this.defaultZodStringHandler(value);
693
+ }
694
+ case "ZodDate": {
695
+ return this.defaultZodDateHandler(value);
696
+ }
697
+ case "ZodAny": {
698
+ return z.string().describe(
699
+ (value.description ?? "") + `
700
+ Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
701
+ );
702
+ }
703
+ default:
704
+ return this.defaultUnsupportedZodTypeHandler(value);
705
+ }
706
+ }
707
+ };
708
+
709
+ 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 };
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@internal/lint/eslint';
2
+
3
+ const config = await createConfig();
4
+
5
+ /** @type {import("eslint").Linter.Config[]} */
6
+ export default [...config];