@mastra/schema-compat 0.10.2-alpha.2 → 0.10.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/_tsup-dts-rollup.d.cts +55 -26
- package/dist/_tsup-dts-rollup.d.ts +55 -26
- package/dist/index.cjs +178 -240
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +174 -242
- package/package.json +4 -4
- package/src/index.ts +7 -0
- package/src/provider-compats/anthropic.ts +27 -32
- package/src/provider-compats/deepseek.ts +15 -21
- package/src/provider-compats/google.ts +34 -33
- package/src/provider-compats/meta.ts +17 -24
- package/src/provider-compats/openai-reasoning.ts +51 -50
- package/src/provider-compats/openai.ts +28 -33
- package/src/schema-compatibility.test.ts +161 -40
- package/src/schema-compatibility.ts +83 -91
- package/src/utils.test.ts +129 -23
- package/src/utils.ts +8 -21
package/dist/index.cjs
CHANGED
|
@@ -45,18 +45,9 @@ function applyCompatLayer({
|
|
|
45
45
|
}) {
|
|
46
46
|
let zodSchema;
|
|
47
47
|
if (!isZodType(schema)) {
|
|
48
|
-
|
|
49
|
-
if (convertedSchema instanceof zod.z.ZodObject) {
|
|
50
|
-
zodSchema = convertedSchema;
|
|
51
|
-
} else {
|
|
52
|
-
zodSchema = zod.z.object({ value: convertedSchema });
|
|
53
|
-
}
|
|
48
|
+
zodSchema = convertSchemaToZod(schema);
|
|
54
49
|
} else {
|
|
55
|
-
|
|
56
|
-
zodSchema = schema;
|
|
57
|
-
} else {
|
|
58
|
-
zodSchema = zod.z.object({ value: schema });
|
|
59
|
-
}
|
|
50
|
+
zodSchema = schema;
|
|
60
51
|
}
|
|
61
52
|
for (const compat of compatLayers) {
|
|
62
53
|
if (compat.shouldApply()) {
|
|
@@ -80,6 +71,14 @@ var ALL_NUMBER_CHECKS = [
|
|
|
80
71
|
"multipleOf"
|
|
81
72
|
];
|
|
82
73
|
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
74
|
+
var isOptional = (v) => v instanceof zod.ZodOptional;
|
|
75
|
+
var isObj = (v) => v instanceof zod.ZodObject;
|
|
76
|
+
var isArr = (v) => v instanceof zod.ZodArray;
|
|
77
|
+
var isUnion = (v) => v instanceof zod.ZodUnion;
|
|
78
|
+
var isString = (v) => v instanceof zod.ZodString;
|
|
79
|
+
var isNumber = (v) => v instanceof zod.ZodNumber;
|
|
80
|
+
var isDate = (v) => v instanceof zod.ZodDate;
|
|
81
|
+
var isDefault = (v) => v instanceof zod.ZodDefault;
|
|
83
82
|
var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
84
83
|
var SUPPORTED_ZOD_TYPES = [
|
|
85
84
|
"ZodObject",
|
|
@@ -110,25 +109,6 @@ var SchemaCompatLayer = class {
|
|
|
110
109
|
getModel() {
|
|
111
110
|
return this.model;
|
|
112
111
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Applies compatibility transformations to a Zod object schema.
|
|
115
|
-
*
|
|
116
|
-
* @param zodSchema - The Zod object schema to transform
|
|
117
|
-
* @returns Object containing the transformed schema
|
|
118
|
-
* @private
|
|
119
|
-
*/
|
|
120
|
-
applyZodSchemaCompatibility(zodSchema) {
|
|
121
|
-
const newSchema = zod.z.object(
|
|
122
|
-
Object.entries(zodSchema.shape || {}).reduce(
|
|
123
|
-
(acc, [key, value]) => ({
|
|
124
|
-
...acc,
|
|
125
|
-
[key]: this.processZodType(value)
|
|
126
|
-
}),
|
|
127
|
-
{}
|
|
128
|
-
)
|
|
129
|
-
);
|
|
130
|
-
return { schema: newSchema };
|
|
131
|
-
}
|
|
132
112
|
/**
|
|
133
113
|
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
134
114
|
*
|
|
@@ -136,17 +116,17 @@ var SchemaCompatLayer = class {
|
|
|
136
116
|
* @returns The processed Zod object
|
|
137
117
|
*/
|
|
138
118
|
defaultZodObjectHandler(value) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const processedValue = this.processZodType(typedPropValue);
|
|
144
|
-
acc[key] = processedValue;
|
|
145
|
-
return acc;
|
|
146
|
-
},
|
|
147
|
-
{}
|
|
148
|
-
);
|
|
119
|
+
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
120
|
+
acc[key] = this.processZodType(propValue);
|
|
121
|
+
return acc;
|
|
122
|
+
}, {});
|
|
149
123
|
let result = zod.z.object(processedShape);
|
|
124
|
+
if (value._def.unknownKeys === "strict") {
|
|
125
|
+
result = result.strict();
|
|
126
|
+
}
|
|
127
|
+
if (value._def.catchall && !(value._def.catchall instanceof zod.z.ZodNever)) {
|
|
128
|
+
result = result.catchall(value._def.catchall);
|
|
129
|
+
}
|
|
150
130
|
if (value.description) {
|
|
151
131
|
result = result.describe(value.description);
|
|
152
132
|
}
|
|
@@ -191,28 +171,30 @@ var SchemaCompatLayer = class {
|
|
|
191
171
|
* @returns The processed Zod array
|
|
192
172
|
*/
|
|
193
173
|
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const constraints = {};
|
|
197
|
-
if (zodArray.minLength?.value !== void 0 && handleChecks.includes("min")) {
|
|
198
|
-
constraints.minLength = zodArray.minLength.value;
|
|
199
|
-
}
|
|
200
|
-
if (zodArray.maxLength?.value !== void 0 && handleChecks.includes("max")) {
|
|
201
|
-
constraints.maxLength = zodArray.maxLength.value;
|
|
202
|
-
}
|
|
203
|
-
if (zodArray.exactLength?.value !== void 0 && handleChecks.includes("length")) {
|
|
204
|
-
constraints.exactLength = zodArray.exactLength.value;
|
|
205
|
-
}
|
|
206
|
-
const processedType = arrayType._def.typeName === "ZodObject" ? this.processZodType(arrayType) : arrayType;
|
|
174
|
+
const zodArrayDef = value._def;
|
|
175
|
+
const processedType = this.processZodType(zodArrayDef.type);
|
|
207
176
|
let result = zod.z.array(processedType);
|
|
208
|
-
|
|
209
|
-
|
|
177
|
+
const constraints = {};
|
|
178
|
+
if (zodArrayDef.minLength?.value !== void 0) {
|
|
179
|
+
if (handleChecks.includes("min")) {
|
|
180
|
+
constraints.minLength = zodArrayDef.minLength.value;
|
|
181
|
+
} else {
|
|
182
|
+
result = result.min(zodArrayDef.minLength.value);
|
|
183
|
+
}
|
|
210
184
|
}
|
|
211
|
-
if (
|
|
212
|
-
|
|
185
|
+
if (zodArrayDef.maxLength?.value !== void 0) {
|
|
186
|
+
if (handleChecks.includes("max")) {
|
|
187
|
+
constraints.maxLength = zodArrayDef.maxLength.value;
|
|
188
|
+
} else {
|
|
189
|
+
result = result.max(zodArrayDef.maxLength.value);
|
|
190
|
+
}
|
|
213
191
|
}
|
|
214
|
-
if (
|
|
215
|
-
|
|
192
|
+
if (zodArrayDef.exactLength?.value !== void 0) {
|
|
193
|
+
if (handleChecks.includes("length")) {
|
|
194
|
+
constraints.exactLength = zodArrayDef.exactLength.value;
|
|
195
|
+
} else {
|
|
196
|
+
result = result.length(zodArrayDef.exactLength.value);
|
|
197
|
+
}
|
|
216
198
|
}
|
|
217
199
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
218
200
|
if (description) {
|
|
@@ -228,8 +210,7 @@ var SchemaCompatLayer = class {
|
|
|
228
210
|
* @throws Error if union has fewer than 2 options
|
|
229
211
|
*/
|
|
230
212
|
defaultZodUnionHandler(value) {
|
|
231
|
-
const
|
|
232
|
-
const processedOptions = zodUnion._def.options.map((option) => this.processZodType(option));
|
|
213
|
+
const processedOptions = value._def.options.map((option) => this.processZodType(option));
|
|
233
214
|
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
234
215
|
let result = zod.z.union(processedOptions);
|
|
235
216
|
if (value.description) {
|
|
@@ -245,9 +226,8 @@ var SchemaCompatLayer = class {
|
|
|
245
226
|
* @returns The processed Zod string
|
|
246
227
|
*/
|
|
247
228
|
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
248
|
-
const zodString = value;
|
|
249
229
|
const constraints = {};
|
|
250
|
-
const checks =
|
|
230
|
+
const checks = value._def.checks || [];
|
|
251
231
|
const newChecks = [];
|
|
252
232
|
for (const check of checks) {
|
|
253
233
|
if ("kind" in check) {
|
|
@@ -312,9 +292,8 @@ var SchemaCompatLayer = class {
|
|
|
312
292
|
* @returns The processed Zod number
|
|
313
293
|
*/
|
|
314
294
|
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
315
|
-
const zodNumber = value;
|
|
316
295
|
const constraints = {};
|
|
317
|
-
const checks =
|
|
296
|
+
const checks = value._def.checks || [];
|
|
318
297
|
const newChecks = [];
|
|
319
298
|
for (const check of checks) {
|
|
320
299
|
if ("kind" in check) {
|
|
@@ -370,9 +349,8 @@ var SchemaCompatLayer = class {
|
|
|
370
349
|
* @returns A Zod string schema representing the date in ISO format
|
|
371
350
|
*/
|
|
372
351
|
defaultZodDateHandler(value) {
|
|
373
|
-
const zodDate = value;
|
|
374
352
|
const constraints = {};
|
|
375
|
-
const checks =
|
|
353
|
+
const checks = value._def.checks || [];
|
|
376
354
|
for (const check of checks) {
|
|
377
355
|
if ("kind" in check) {
|
|
378
356
|
switch (check.kind) {
|
|
@@ -420,8 +398,8 @@ var SchemaCompatLayer = class {
|
|
|
420
398
|
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
421
399
|
*/
|
|
422
400
|
processToAISDKSchema(zodSchema) {
|
|
423
|
-
const
|
|
424
|
-
return convertZodSchemaToAISDKSchema(
|
|
401
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
402
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
425
403
|
}
|
|
426
404
|
/**
|
|
427
405
|
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
@@ -446,36 +424,28 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
446
424
|
return this.getModel().modelId.includes("claude");
|
|
447
425
|
}
|
|
448
426
|
processZodType(value) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return this.
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// added to the tool description
|
|
466
|
-
case "ZodString": {
|
|
467
|
-
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
468
|
-
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
469
|
-
} else {
|
|
470
|
-
return value;
|
|
471
|
-
}
|
|
427
|
+
if (isOptional(value)) {
|
|
428
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
429
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
430
|
+
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
431
|
+
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
432
|
+
} else if (isObj(value)) {
|
|
433
|
+
return this.defaultZodObjectHandler(value);
|
|
434
|
+
} else if (isArr(value)) {
|
|
435
|
+
return this.defaultZodArrayHandler(value, []);
|
|
436
|
+
} else if (isUnion(value)) {
|
|
437
|
+
return this.defaultZodUnionHandler(value);
|
|
438
|
+
} else if (isString(value)) {
|
|
439
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
440
|
+
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
441
|
+
} else {
|
|
442
|
+
return value;
|
|
472
443
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
444
|
+
}
|
|
445
|
+
if (this.getModel().modelId.includes("claude-3.7")) {
|
|
446
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
447
|
+
} else {
|
|
448
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
479
449
|
}
|
|
480
450
|
}
|
|
481
451
|
};
|
|
@@ -492,24 +462,18 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
492
462
|
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
493
463
|
}
|
|
494
464
|
processZodType(value) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
return this.defaultZodUnionHandler(value);
|
|
506
|
-
}
|
|
507
|
-
case "ZodString": {
|
|
508
|
-
return this.defaultZodStringHandler(value);
|
|
509
|
-
}
|
|
510
|
-
default:
|
|
511
|
-
return value;
|
|
465
|
+
if (isOptional(value)) {
|
|
466
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
467
|
+
} else if (isObj(value)) {
|
|
468
|
+
return this.defaultZodObjectHandler(value);
|
|
469
|
+
} else if (isArr(value)) {
|
|
470
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
471
|
+
} else if (isUnion(value)) {
|
|
472
|
+
return this.defaultZodUnionHandler(value);
|
|
473
|
+
} else if (isString(value)) {
|
|
474
|
+
return this.defaultZodStringHandler(value);
|
|
512
475
|
}
|
|
476
|
+
return value;
|
|
513
477
|
}
|
|
514
478
|
};
|
|
515
479
|
|
|
@@ -525,36 +489,27 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
525
489
|
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
526
490
|
}
|
|
527
491
|
processZodType(value) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
case "ZodString": {
|
|
550
|
-
return this.defaultZodStringHandler(value);
|
|
551
|
-
}
|
|
552
|
-
case "ZodNumber": {
|
|
553
|
-
return this.defaultZodNumberHandler(value);
|
|
554
|
-
}
|
|
555
|
-
default:
|
|
556
|
-
return this.defaultUnsupportedZodTypeHandler(value);
|
|
557
|
-
}
|
|
492
|
+
if (isOptional(value)) {
|
|
493
|
+
return this.defaultZodOptionalHandler(value, [
|
|
494
|
+
"ZodObject",
|
|
495
|
+
"ZodArray",
|
|
496
|
+
"ZodUnion",
|
|
497
|
+
"ZodString",
|
|
498
|
+
"ZodNumber",
|
|
499
|
+
...UNSUPPORTED_ZOD_TYPES
|
|
500
|
+
]);
|
|
501
|
+
} else if (isObj(value)) {
|
|
502
|
+
return this.defaultZodObjectHandler(value);
|
|
503
|
+
} else if (isArr(value)) {
|
|
504
|
+
return this.defaultZodArrayHandler(value, []);
|
|
505
|
+
} else if (isUnion(value)) {
|
|
506
|
+
return this.defaultZodUnionHandler(value);
|
|
507
|
+
} else if (isString(value)) {
|
|
508
|
+
return this.defaultZodStringHandler(value);
|
|
509
|
+
} else if (isNumber(value)) {
|
|
510
|
+
return this.defaultZodNumberHandler(value);
|
|
511
|
+
}
|
|
512
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
558
513
|
}
|
|
559
514
|
};
|
|
560
515
|
|
|
@@ -570,27 +525,20 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
570
525
|
return this.getModel().modelId.includes("meta");
|
|
571
526
|
}
|
|
572
527
|
processZodType(value) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
case "ZodNumber": {
|
|
586
|
-
return this.defaultZodNumberHandler(value);
|
|
587
|
-
}
|
|
588
|
-
case "ZodString": {
|
|
589
|
-
return this.defaultZodStringHandler(value);
|
|
590
|
-
}
|
|
591
|
-
default:
|
|
592
|
-
return value;
|
|
528
|
+
if (isOptional(value)) {
|
|
529
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
530
|
+
} else if (isObj(value)) {
|
|
531
|
+
return this.defaultZodObjectHandler(value);
|
|
532
|
+
} else if (isArr(value)) {
|
|
533
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
534
|
+
} else if (isUnion(value)) {
|
|
535
|
+
return this.defaultZodUnionHandler(value);
|
|
536
|
+
} else if (isNumber(value)) {
|
|
537
|
+
return this.defaultZodNumberHandler(value);
|
|
538
|
+
} else if (isString(value)) {
|
|
539
|
+
return this.defaultZodStringHandler(value);
|
|
593
540
|
}
|
|
541
|
+
return value;
|
|
594
542
|
}
|
|
595
543
|
};
|
|
596
544
|
|
|
@@ -609,37 +557,31 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
609
557
|
return false;
|
|
610
558
|
}
|
|
611
559
|
processZodType(value) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
return this.defaultZodStringHandler(value, checks);
|
|
639
|
-
}
|
|
640
|
-
default:
|
|
641
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
|
|
642
|
-
}
|
|
560
|
+
if (isOptional(value)) {
|
|
561
|
+
return this.defaultZodOptionalHandler(value, [
|
|
562
|
+
"ZodObject",
|
|
563
|
+
"ZodArray",
|
|
564
|
+
"ZodUnion",
|
|
565
|
+
"ZodString",
|
|
566
|
+
"ZodNever",
|
|
567
|
+
"ZodUndefined",
|
|
568
|
+
"ZodTuple"
|
|
569
|
+
]);
|
|
570
|
+
} else if (isObj(value)) {
|
|
571
|
+
return this.defaultZodObjectHandler(value);
|
|
572
|
+
} else if (isUnion(value)) {
|
|
573
|
+
return this.defaultZodUnionHandler(value);
|
|
574
|
+
} else if (isArr(value)) {
|
|
575
|
+
return this.defaultZodArrayHandler(value);
|
|
576
|
+
} else if (isString(value)) {
|
|
577
|
+
const model = this.getModel();
|
|
578
|
+
const checks = ["emoji"];
|
|
579
|
+
if (model.modelId.includes("gpt-4o-mini")) {
|
|
580
|
+
checks.push("regex");
|
|
581
|
+
}
|
|
582
|
+
return this.defaultZodStringHandler(value, checks);
|
|
583
|
+
}
|
|
584
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
|
|
643
585
|
}
|
|
644
586
|
};
|
|
645
587
|
var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
@@ -659,52 +601,42 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
659
601
|
return false;
|
|
660
602
|
}
|
|
661
603
|
processZodType(value) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
return this.defaultZodStringHandler(value);
|
|
695
|
-
}
|
|
696
|
-
case "ZodDate": {
|
|
697
|
-
return this.defaultZodDateHandler(value);
|
|
698
|
-
}
|
|
699
|
-
case "ZodAny": {
|
|
700
|
-
return zod.z.string().describe(
|
|
701
|
-
(value.description ?? "") + `
|
|
604
|
+
if (isOptional(value)) {
|
|
605
|
+
const innerZodType = this.processZodType(value._def.innerType);
|
|
606
|
+
return innerZodType.nullable();
|
|
607
|
+
} else if (isObj(value)) {
|
|
608
|
+
return this.defaultZodObjectHandler(value);
|
|
609
|
+
} else if (isArr(value)) {
|
|
610
|
+
return this.defaultZodArrayHandler(value);
|
|
611
|
+
} else if (isUnion(value)) {
|
|
612
|
+
return this.defaultZodUnionHandler(value);
|
|
613
|
+
} else if (isDefault(value)) {
|
|
614
|
+
const defaultDef = value._def;
|
|
615
|
+
const innerType = defaultDef.innerType;
|
|
616
|
+
const defaultValue = defaultDef.defaultValue();
|
|
617
|
+
const constraints = {};
|
|
618
|
+
if (defaultValue !== void 0) {
|
|
619
|
+
constraints.defaultValue = defaultValue;
|
|
620
|
+
}
|
|
621
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
622
|
+
let result = this.processZodType(innerType);
|
|
623
|
+
if (description) {
|
|
624
|
+
result = result.describe(description);
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
} else if (isNumber(value)) {
|
|
628
|
+
return this.defaultZodNumberHandler(value);
|
|
629
|
+
} else if (isString(value)) {
|
|
630
|
+
return this.defaultZodStringHandler(value);
|
|
631
|
+
} else if (isDate(value)) {
|
|
632
|
+
return this.defaultZodDateHandler(value);
|
|
633
|
+
} else if (value._def.typeName === "ZodAny") {
|
|
634
|
+
return zod.z.string().describe(
|
|
635
|
+
(value.description ?? "") + `
|
|
702
636
|
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
default:
|
|
706
|
-
return this.defaultUnsupportedZodTypeHandler(value);
|
|
637
|
+
);
|
|
707
638
|
}
|
|
639
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
708
640
|
}
|
|
709
641
|
};
|
|
710
642
|
|
|
@@ -724,3 +656,9 @@ exports.UNSUPPORTED_ZOD_TYPES = UNSUPPORTED_ZOD_TYPES;
|
|
|
724
656
|
exports.applyCompatLayer = applyCompatLayer;
|
|
725
657
|
exports.convertSchemaToZod = convertSchemaToZod;
|
|
726
658
|
exports.convertZodSchemaToAISDKSchema = convertZodSchemaToAISDKSchema;
|
|
659
|
+
exports.isArr = isArr;
|
|
660
|
+
exports.isNumber = isNumber;
|
|
661
|
+
exports.isObj = isObj;
|
|
662
|
+
exports.isOptional = isOptional;
|
|
663
|
+
exports.isString = isString;
|
|
664
|
+
exports.isUnion = isUnion;
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,12 @@ export { AllZodType } from './_tsup-dts-rollup.cjs';
|
|
|
14
14
|
export { ZodShape } from './_tsup-dts-rollup.cjs';
|
|
15
15
|
export { ShapeKey } from './_tsup-dts-rollup.cjs';
|
|
16
16
|
export { ShapeValue } from './_tsup-dts-rollup.cjs';
|
|
17
|
+
export { isOptional } from './_tsup-dts-rollup.cjs';
|
|
18
|
+
export { isObj } from './_tsup-dts-rollup.cjs';
|
|
19
|
+
export { isArr } from './_tsup-dts-rollup.cjs';
|
|
20
|
+
export { isUnion } from './_tsup-dts-rollup.cjs';
|
|
21
|
+
export { isString } from './_tsup-dts-rollup.cjs';
|
|
22
|
+
export { isNumber } from './_tsup-dts-rollup.cjs';
|
|
17
23
|
export { convertZodSchemaToAISDKSchema } from './_tsup-dts-rollup.cjs';
|
|
18
24
|
export { applyCompatLayer } from './_tsup-dts-rollup.cjs';
|
|
19
25
|
export { convertSchemaToZod } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export { AllZodType } from './_tsup-dts-rollup.js';
|
|
|
14
14
|
export { ZodShape } from './_tsup-dts-rollup.js';
|
|
15
15
|
export { ShapeKey } from './_tsup-dts-rollup.js';
|
|
16
16
|
export { ShapeValue } from './_tsup-dts-rollup.js';
|
|
17
|
+
export { isOptional } from './_tsup-dts-rollup.js';
|
|
18
|
+
export { isObj } from './_tsup-dts-rollup.js';
|
|
19
|
+
export { isArr } from './_tsup-dts-rollup.js';
|
|
20
|
+
export { isUnion } from './_tsup-dts-rollup.js';
|
|
21
|
+
export { isString } from './_tsup-dts-rollup.js';
|
|
22
|
+
export { isNumber } from './_tsup-dts-rollup.js';
|
|
17
23
|
export { convertZodSchemaToAISDKSchema } from './_tsup-dts-rollup.js';
|
|
18
24
|
export { applyCompatLayer } from './_tsup-dts-rollup.js';
|
|
19
25
|
export { convertSchemaToZod } from './_tsup-dts-rollup.js';
|