@mastra/schema-compat 0.10.5 → 0.10.6-alpha.1
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 +2 -21
- package/CHANGELOG.md +47 -0
- package/README.md +0 -4
- package/dist/chunk-FTKGHMGD.js +27 -0
- package/dist/chunk-FTKGHMGD.js.map +1 -0
- package/dist/chunk-LNR4XKDU.cjs +33 -0
- package/dist/chunk-LNR4XKDU.cjs.map +1 -0
- package/dist/index.cjs +845 -84
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -31
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +844 -85
- package/dist/index.js.map +1 -0
- package/dist/provider-compats/anthropic.d.ts +13 -0
- package/dist/provider-compats/anthropic.d.ts.map +1 -0
- package/dist/provider-compats/deepseek.d.ts +13 -0
- package/dist/provider-compats/deepseek.d.ts.map +1 -0
- package/dist/provider-compats/google.d.ts +13 -0
- package/dist/provider-compats/google.d.ts.map +1 -0
- package/dist/provider-compats/meta.d.ts +13 -0
- package/dist/provider-compats/meta.d.ts.map +1 -0
- package/dist/provider-compats/openai-reasoning.d.ts +14 -0
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
- package/dist/provider-compats/openai.d.ts +13 -0
- package/dist/provider-compats/openai.d.ts.map +1 -0
- package/dist/schema-compatibility-v3.d.ts +319 -0
- package/dist/schema-compatibility-v3.d.ts.map +1 -0
- package/dist/schema-compatibility-v4.d.ts +310 -0
- package/dist/schema-compatibility-v4.d.ts.map +1 -0
- package/dist/schema-compatibility.d.ts +228 -0
- package/dist/schema-compatibility.d.ts.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils-test-suite.d.ts +2 -0
- package/dist/utils-test-suite.d.ts.map +1 -0
- package/dist/utils.d.ts +96 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/zod-to-json.cjs +12 -0
- package/dist/zod-to-json.cjs.map +1 -0
- package/dist/zod-to-json.d.ts +6 -0
- package/dist/zod-to-json.d.ts.map +1 -0
- package/dist/zod-to-json.js +3 -0
- package/dist/zod-to-json.js.map +1 -0
- package/dist/zodTypes.d.ts +21 -0
- package/dist/zodTypes.d.ts.map +1 -0
- package/package.json +19 -8
- package/src/index.ts +4 -3
- package/src/provider-compats/anthropic.ts +30 -13
- package/src/provider-compats/deepseek.ts +15 -10
- package/src/provider-compats/google.ts +19 -33
- package/src/provider-compats/meta.ts +16 -11
- package/src/provider-compats/openai-reasoning.ts +24 -26
- package/src/provider-compats/openai.ts +23 -14
- package/src/provider-compats.test.ts +120 -25
- package/src/schema-compatibility-v3.ts +664 -0
- package/src/schema-compatibility-v4.test.ts +476 -0
- package/src/schema-compatibility-v4.ts +706 -0
- package/src/schema-compatibility.test.ts +9 -9
- package/src/schema-compatibility.ts +266 -383
- package/src/types.ts +5 -0
- package/src/utils-test-suite.ts +467 -0
- package/src/utils-v3.test.ts +9 -0
- package/src/utils-v4.test.ts +9 -0
- package/src/utils.ts +30 -24
- package/src/zod-to-json.ts +27 -0
- package/src/zodTypes.ts +56 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -507
- package/dist/_tsup-dts-rollup.d.ts +0 -507
- package/dist/index.d.cts +0 -31
- package/src/utils.test.ts +0 -434
package/dist/index.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { zodToJsonSchema } from './chunk-FTKGHMGD.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 {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
*
|
|
@@ -413,9 +497,680 @@ var SchemaCompatLayer = class {
|
|
|
413
497
|
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
414
498
|
}
|
|
415
499
|
};
|
|
500
|
+
var ALL_STRING_CHECKS2 = [
|
|
501
|
+
"regex",
|
|
502
|
+
"emoji",
|
|
503
|
+
"email",
|
|
504
|
+
"url",
|
|
505
|
+
"uuid",
|
|
506
|
+
"cuid",
|
|
507
|
+
"min_length",
|
|
508
|
+
"max_length",
|
|
509
|
+
"string_format"
|
|
510
|
+
];
|
|
511
|
+
var ALL_NUMBER_CHECKS2 = ["greater_than", "less_than", "multiple_of"];
|
|
512
|
+
var ALL_ARRAY_CHECKS2 = ["min", "max", "length"];
|
|
513
|
+
var UNSUPPORTED_ZOD_TYPES2 = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
514
|
+
var SUPPORTED_ZOD_TYPES2 = [
|
|
515
|
+
"ZodObject",
|
|
516
|
+
"ZodArray",
|
|
517
|
+
"ZodUnion",
|
|
518
|
+
"ZodString",
|
|
519
|
+
"ZodNumber",
|
|
520
|
+
"ZodDate",
|
|
521
|
+
"ZodAny",
|
|
522
|
+
"ZodDefault"
|
|
523
|
+
];
|
|
524
|
+
var SchemaCompatLayer2 = class {
|
|
525
|
+
model;
|
|
526
|
+
parent;
|
|
527
|
+
/**
|
|
528
|
+
* Creates a new schema compatibility instance.
|
|
529
|
+
*
|
|
530
|
+
* @param model - The language model this compatibility layer applies to
|
|
531
|
+
*/
|
|
532
|
+
constructor(model, parent) {
|
|
533
|
+
this.model = model;
|
|
534
|
+
this.parent = parent;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Gets the language model associated with this compatibility layer.
|
|
538
|
+
*
|
|
539
|
+
* @returns The language model instance
|
|
540
|
+
*/
|
|
541
|
+
getModel() {
|
|
542
|
+
return this.model;
|
|
543
|
+
}
|
|
544
|
+
getUnsupportedZodTypes() {
|
|
545
|
+
return UNSUPPORTED_ZOD_TYPES2;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Type guard for optional Zod types
|
|
549
|
+
*/
|
|
550
|
+
isOptional(v) {
|
|
551
|
+
return v instanceof ZodOptional$1;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Type guard for object Zod types
|
|
555
|
+
*/
|
|
556
|
+
isObj(v) {
|
|
557
|
+
return v instanceof ZodObject$1;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Type guard for null Zod types
|
|
561
|
+
*/
|
|
562
|
+
isNull(v) {
|
|
563
|
+
return v instanceof ZodNull$1;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Type guard for array Zod types
|
|
567
|
+
*/
|
|
568
|
+
isArr(v) {
|
|
569
|
+
return v instanceof ZodArray$1;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Type guard for union Zod types
|
|
573
|
+
*/
|
|
574
|
+
isUnion(v) {
|
|
575
|
+
return v instanceof ZodUnion$1;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Type guard for string Zod types
|
|
579
|
+
*/
|
|
580
|
+
isString(v) {
|
|
581
|
+
return v instanceof ZodString$1;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Type guard for number Zod types
|
|
585
|
+
*/
|
|
586
|
+
isNumber(v) {
|
|
587
|
+
return v instanceof ZodNumber$1;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Type guard for date Zod types
|
|
591
|
+
*/
|
|
592
|
+
isDate(v) {
|
|
593
|
+
return v instanceof ZodDate$1;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Type guard for default Zod types
|
|
597
|
+
*/
|
|
598
|
+
isDefault(v) {
|
|
599
|
+
return v instanceof ZodDefault$1;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Determines whether this compatibility layer should be applied for the current model.
|
|
603
|
+
*
|
|
604
|
+
* @returns True if this compatibility layer should be used, false otherwise
|
|
605
|
+
* @abstract
|
|
606
|
+
*/
|
|
607
|
+
shouldApply() {
|
|
608
|
+
return this.parent.shouldApply();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Returns the JSON Schema target format for this provider.
|
|
612
|
+
*
|
|
613
|
+
* @returns The schema target format, or undefined to use the default 'jsonSchema7'
|
|
614
|
+
* @abstract
|
|
615
|
+
*/
|
|
616
|
+
getSchemaTarget() {
|
|
617
|
+
return this.parent.getSchemaTarget();
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Processes a specific Zod type according to the provider's requirements.
|
|
621
|
+
*
|
|
622
|
+
* @param value - The Zod type to process
|
|
623
|
+
* @returns The processed Zod type
|
|
624
|
+
* @abstract
|
|
625
|
+
*/
|
|
626
|
+
processZodType(value) {
|
|
627
|
+
return this.parent.processZodType(value);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
631
|
+
*
|
|
632
|
+
* @param value - The Zod object to process
|
|
633
|
+
* @returns The processed Zod object
|
|
634
|
+
*/
|
|
635
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
636
|
+
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
637
|
+
acc[key] = this.processZodType(propValue);
|
|
638
|
+
return acc;
|
|
639
|
+
}, {});
|
|
640
|
+
let result = z$1.object(processedShape);
|
|
641
|
+
if (value._zod.def.catchall instanceof z$1.ZodNever) {
|
|
642
|
+
result = z$1.strictObject(processedShape);
|
|
643
|
+
}
|
|
644
|
+
if (value._zod.def.catchall && !(value._zod.def.catchall instanceof z$1.ZodNever)) {
|
|
645
|
+
result = result.catchall(value._zod.def.catchall);
|
|
646
|
+
}
|
|
647
|
+
if (value.description) {
|
|
648
|
+
result = result.describe(value.description);
|
|
649
|
+
}
|
|
650
|
+
if (options.passthrough && value._zod.def.catchall instanceof z$1.ZodUnknown) {
|
|
651
|
+
result = z$1.looseObject(processedShape);
|
|
652
|
+
}
|
|
653
|
+
return result;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Merges validation constraints into a parameter description.
|
|
657
|
+
*
|
|
658
|
+
* This helper method converts validation constraints that may not be supported
|
|
659
|
+
* by a provider into human-readable descriptions.
|
|
660
|
+
*
|
|
661
|
+
* @param description - The existing parameter description
|
|
662
|
+
* @param constraints - The validation constraints to merge
|
|
663
|
+
* @returns The updated description with constraints, or undefined if no constraints
|
|
664
|
+
*/
|
|
665
|
+
mergeParameterDescription(description, constraints) {
|
|
666
|
+
if (Object.keys(constraints).length > 0) {
|
|
667
|
+
return (description ? description + "\n" : "") + JSON.stringify(constraints);
|
|
668
|
+
} else {
|
|
669
|
+
return description;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
674
|
+
*
|
|
675
|
+
* @param value - The Zod type to check
|
|
676
|
+
* @param throwOnTypes - Array of type names to throw errors for
|
|
677
|
+
* @returns The original value if not in the throw list
|
|
678
|
+
* @throws Error if the type is in the unsupported list
|
|
679
|
+
*/
|
|
680
|
+
defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES2) {
|
|
681
|
+
if (throwOnTypes.includes(value.constructor.name)) {
|
|
682
|
+
throw new Error(`${this.model.modelId} does not support zod type: ${value.constructor.name}`);
|
|
683
|
+
}
|
|
684
|
+
return value;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Default handler for Zod array types. Processes array constraints according to provider support.
|
|
688
|
+
*
|
|
689
|
+
* @param value - The Zod array to process
|
|
690
|
+
* @param handleChecks - Array constraints to convert to descriptions vs keep as validation
|
|
691
|
+
* @returns The processed Zod array
|
|
692
|
+
*/
|
|
693
|
+
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS2) {
|
|
694
|
+
const zodArrayDef = value._zod.def;
|
|
695
|
+
const processedType = this.processZodType(zodArrayDef.element);
|
|
696
|
+
let result = z$1.array(processedType);
|
|
697
|
+
const constraints = {};
|
|
698
|
+
if (zodArrayDef.checks) {
|
|
699
|
+
for (const check of zodArrayDef.checks) {
|
|
700
|
+
if (check._zod.def.check === "min_length") {
|
|
701
|
+
if (handleChecks.includes("min")) {
|
|
702
|
+
constraints.minLength = check._zod.def.minimum;
|
|
703
|
+
} else {
|
|
704
|
+
result = result.min(check._zod.def.minimum);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (check._zod.def.check === "max_length") {
|
|
708
|
+
if (handleChecks.includes("max")) {
|
|
709
|
+
constraints.maxLength = check._zod.def.maximum;
|
|
710
|
+
} else {
|
|
711
|
+
result = result.max(check._zod.def.maximum);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (check._zod.def.check === "length_equals") {
|
|
715
|
+
if (handleChecks.includes("length")) {
|
|
716
|
+
constraints.exactLength = check._zod.def.length;
|
|
717
|
+
} else {
|
|
718
|
+
result = result.length(check._zod.def.length);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const metaDescription = value.meta()?.description;
|
|
724
|
+
const legacyDescription = value.description;
|
|
725
|
+
const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
|
|
726
|
+
if (description) {
|
|
727
|
+
result = result.describe(description);
|
|
728
|
+
}
|
|
729
|
+
return result;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Default handler for Zod union types. Processes all union options.
|
|
733
|
+
*
|
|
734
|
+
* @param value - The Zod union to process
|
|
735
|
+
* @returns The processed Zod union
|
|
736
|
+
* @throws Error if union has fewer than 2 options
|
|
737
|
+
*/
|
|
738
|
+
defaultZodUnionHandler(value) {
|
|
739
|
+
const processedOptions = value._zod.def.options.map((option) => this.processZodType(option));
|
|
740
|
+
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
741
|
+
let result = z$1.union(processedOptions);
|
|
742
|
+
if (value.description) {
|
|
743
|
+
result = result.describe(value.description);
|
|
744
|
+
}
|
|
745
|
+
return result;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Default handler for Zod string types. Processes string validation constraints.
|
|
749
|
+
*
|
|
750
|
+
* @param value - The Zod string to process
|
|
751
|
+
* @param handleChecks - String constraints to convert to descriptions vs keep as validation
|
|
752
|
+
* @returns The processed Zod string
|
|
753
|
+
*/
|
|
754
|
+
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS2) {
|
|
755
|
+
const constraints = {};
|
|
756
|
+
const checks = value._zod.def.checks || [];
|
|
757
|
+
const newChecks = [];
|
|
758
|
+
if (checks) {
|
|
759
|
+
for (const check of checks) {
|
|
760
|
+
if (handleChecks.includes(check._zod.def.check)) {
|
|
761
|
+
switch (check._zod.def.check) {
|
|
762
|
+
case "min_length":
|
|
763
|
+
constraints.minLength = check._zod.def.minimum;
|
|
764
|
+
break;
|
|
765
|
+
case "max_length":
|
|
766
|
+
constraints.maxLength = check._zod.def.maximum;
|
|
767
|
+
break;
|
|
768
|
+
case "string_format":
|
|
769
|
+
{
|
|
770
|
+
switch (check._zod.def.format) {
|
|
771
|
+
case "email":
|
|
772
|
+
constraints.email = true;
|
|
773
|
+
break;
|
|
774
|
+
case "url":
|
|
775
|
+
constraints.url = true;
|
|
776
|
+
break;
|
|
777
|
+
case "emoji":
|
|
778
|
+
constraints.emoji = true;
|
|
779
|
+
break;
|
|
780
|
+
case "uuid":
|
|
781
|
+
constraints.uuid = true;
|
|
782
|
+
break;
|
|
783
|
+
case "cuid":
|
|
784
|
+
constraints.cuid = true;
|
|
785
|
+
break;
|
|
786
|
+
case "regex":
|
|
787
|
+
constraints.regex = {
|
|
788
|
+
// @ts-expect-error - fix later
|
|
789
|
+
pattern: check._zod.def.pattern,
|
|
790
|
+
// @ts-expect-error - fix later
|
|
791
|
+
flags: check._zod.def.flags
|
|
792
|
+
};
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
} else {
|
|
799
|
+
newChecks.push(check);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
let result = z$1.string();
|
|
804
|
+
for (const check of newChecks) {
|
|
805
|
+
result = result.check(check);
|
|
806
|
+
}
|
|
807
|
+
const metaDescription = value.meta()?.description;
|
|
808
|
+
const legacyDescription = value.description;
|
|
809
|
+
const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
|
|
810
|
+
if (description) {
|
|
811
|
+
result = result.describe(description);
|
|
812
|
+
}
|
|
813
|
+
return result;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Default handler for Zod number types. Processes number validation constraints.
|
|
817
|
+
*
|
|
818
|
+
* @param value - The Zod number to process
|
|
819
|
+
* @param handleChecks - Number constraints to convert to descriptions vs keep as validation
|
|
820
|
+
* @returns The processed Zod number
|
|
821
|
+
*/
|
|
822
|
+
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS2) {
|
|
823
|
+
const constraints = {};
|
|
824
|
+
const checks = value._zod.def.checks || [];
|
|
825
|
+
const newChecks = [];
|
|
826
|
+
if (checks) {
|
|
827
|
+
for (const check of checks) {
|
|
828
|
+
if (handleChecks.includes(check._zod.def.check)) {
|
|
829
|
+
switch (check._zod.def.check) {
|
|
830
|
+
case "greater_than":
|
|
831
|
+
if (check._zod.def.inclusive) {
|
|
832
|
+
constraints.gte = check._zod.def.value;
|
|
833
|
+
} else {
|
|
834
|
+
constraints.gt = check._zod.def.value;
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
case "less_than":
|
|
838
|
+
if (check._zod.def.inclusive) {
|
|
839
|
+
constraints.lte = check._zod.def.value;
|
|
840
|
+
} else {
|
|
841
|
+
constraints.lt = check._zod.def.value;
|
|
842
|
+
}
|
|
843
|
+
break;
|
|
844
|
+
case "multiple_of": {
|
|
845
|
+
constraints.multipleOf = check._zod.def.value;
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
newChecks.push(check);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
let result = z$1.number();
|
|
855
|
+
for (const check of newChecks) {
|
|
856
|
+
switch (check._zod.def.check) {
|
|
857
|
+
case "number_format": {
|
|
858
|
+
switch (check._zod.def.format) {
|
|
859
|
+
case "safeint":
|
|
860
|
+
result = result.int();
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
default:
|
|
866
|
+
result = result.check(check);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
870
|
+
if (description) {
|
|
871
|
+
result = result.describe(description);
|
|
872
|
+
}
|
|
873
|
+
return result;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
|
|
877
|
+
*
|
|
878
|
+
* @param value - The Zod date to process
|
|
879
|
+
* @returns A Zod string schema representing the date in ISO format
|
|
880
|
+
*/
|
|
881
|
+
defaultZodDateHandler(value) {
|
|
882
|
+
const constraints = {};
|
|
883
|
+
const checks = value._zod.def.checks || [];
|
|
884
|
+
if (checks) {
|
|
885
|
+
for (const check of checks) {
|
|
886
|
+
switch (check._zod.def.check) {
|
|
887
|
+
case "less_than":
|
|
888
|
+
const minDate = new Date(check._zod.def.value);
|
|
889
|
+
if (!isNaN(minDate.getTime())) {
|
|
890
|
+
constraints.minDate = minDate.toISOString();
|
|
891
|
+
}
|
|
892
|
+
break;
|
|
893
|
+
case "greater_than":
|
|
894
|
+
const maxDate = new Date(check._zod.def.value);
|
|
895
|
+
if (!isNaN(maxDate.getTime())) {
|
|
896
|
+
constraints.maxDate = maxDate.toISOString();
|
|
897
|
+
}
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
constraints.dateFormat = "date-time";
|
|
903
|
+
let result = z$1.string().describe("date-time");
|
|
904
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
905
|
+
if (description) {
|
|
906
|
+
result = result.describe(description);
|
|
907
|
+
}
|
|
908
|
+
return result;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Default handler for Zod optional types. Processes the inner type and maintains optionality.
|
|
912
|
+
*
|
|
913
|
+
* @param value - The Zod optional to process
|
|
914
|
+
* @param handleTypes - Types that should be processed vs passed through
|
|
915
|
+
* @returns The processed Zod optional
|
|
916
|
+
*/
|
|
917
|
+
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES2) {
|
|
918
|
+
if (handleTypes.includes(value.constructor.name)) {
|
|
919
|
+
return this.processZodType(value._zod.def.innerType).optional();
|
|
920
|
+
} else {
|
|
921
|
+
return value;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
926
|
+
*
|
|
927
|
+
* @param zodSchema - The Zod object schema to process
|
|
928
|
+
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
929
|
+
*/
|
|
930
|
+
processToAISDKSchema(zodSchema) {
|
|
931
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
932
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
936
|
+
*
|
|
937
|
+
* @param zodSchema - The Zod object schema to process
|
|
938
|
+
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
939
|
+
*/
|
|
940
|
+
processToJSONSchema(zodSchema) {
|
|
941
|
+
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// src/schema-compatibility.ts
|
|
946
|
+
var SchemaCompatLayer3 = class {
|
|
947
|
+
model;
|
|
948
|
+
v3Layer;
|
|
949
|
+
v4Layer;
|
|
950
|
+
/**
|
|
951
|
+
* Creates a new schema compatibility instance.
|
|
952
|
+
*
|
|
953
|
+
* @param model - The language model this compatibility layer applies to
|
|
954
|
+
*/
|
|
955
|
+
constructor(model) {
|
|
956
|
+
this.model = model;
|
|
957
|
+
this.v3Layer = new SchemaCompatLayer(model, this);
|
|
958
|
+
this.v4Layer = new SchemaCompatLayer2(model, this);
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Gets the language model associated with this compatibility layer.
|
|
962
|
+
*
|
|
963
|
+
* @returns The language model instance
|
|
964
|
+
*/
|
|
965
|
+
getModel() {
|
|
966
|
+
return this.model;
|
|
967
|
+
}
|
|
968
|
+
getUnsupportedZodTypes(v) {
|
|
969
|
+
if ("_zod" in v) {
|
|
970
|
+
return this.v4Layer.getUnsupportedZodTypes();
|
|
971
|
+
} else {
|
|
972
|
+
return this.v3Layer.getUnsupportedZodTypes();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
isOptional(v) {
|
|
976
|
+
if ("_zod" in v) {
|
|
977
|
+
return this.v4Layer.isOptional(v);
|
|
978
|
+
} else {
|
|
979
|
+
return this.v3Layer.isOptional(v);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
isObj(v) {
|
|
983
|
+
if ("_zod" in v) {
|
|
984
|
+
return this.v4Layer.isObj(v);
|
|
985
|
+
} else {
|
|
986
|
+
return this.v3Layer.isObj(v);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
isNull(v) {
|
|
990
|
+
if ("_zod" in v) {
|
|
991
|
+
return this.v4Layer.isNull(v);
|
|
992
|
+
} else {
|
|
993
|
+
return this.v3Layer.isNull(v);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
isArr(v) {
|
|
997
|
+
if ("_zod" in v) {
|
|
998
|
+
return this.v4Layer.isArr(v);
|
|
999
|
+
} else {
|
|
1000
|
+
return this.v3Layer.isArr(v);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
isUnion(v) {
|
|
1004
|
+
if ("_zod" in v) {
|
|
1005
|
+
return this.v4Layer.isUnion(v);
|
|
1006
|
+
} else {
|
|
1007
|
+
return this.v3Layer.isUnion(v);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
isString(v) {
|
|
1011
|
+
if ("_zod" in v) {
|
|
1012
|
+
return this.v4Layer.isString(v);
|
|
1013
|
+
} else {
|
|
1014
|
+
return this.v3Layer.isString(v);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
isNumber(v) {
|
|
1018
|
+
if ("_zod" in v) {
|
|
1019
|
+
return this.v4Layer.isNumber(v);
|
|
1020
|
+
} else {
|
|
1021
|
+
return this.v3Layer.isNumber(v);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
isDate(v) {
|
|
1025
|
+
if ("_zod" in v) {
|
|
1026
|
+
return this.v4Layer.isDate(v);
|
|
1027
|
+
} else {
|
|
1028
|
+
return this.v3Layer.isDate(v);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
isDefault(v) {
|
|
1032
|
+
if ("_zod" in v) {
|
|
1033
|
+
return this.v4Layer.isDefault(v);
|
|
1034
|
+
} else {
|
|
1035
|
+
return this.v3Layer.isDefault(v);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
1039
|
+
if ("_zod" in value) {
|
|
1040
|
+
return this.v4Layer.defaultZodObjectHandler(value, options);
|
|
1041
|
+
} else {
|
|
1042
|
+
return this.v3Layer.defaultZodObjectHandler(value, options);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Merges validation constraints into a parameter description.
|
|
1047
|
+
*
|
|
1048
|
+
* This helper method converts validation constraints that may not be supported
|
|
1049
|
+
* by a provider into human-readable descriptions.
|
|
1050
|
+
*
|
|
1051
|
+
* @param description - The existing parameter description
|
|
1052
|
+
* @param constraints - The validation constraints to merge
|
|
1053
|
+
* @returns The updated description with constraints, or undefined if no constraints
|
|
1054
|
+
*/
|
|
1055
|
+
mergeParameterDescription(description, constraints) {
|
|
1056
|
+
return this.v3Layer.mergeParameterDescription(description, constraints);
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
1060
|
+
*
|
|
1061
|
+
* @param value - The Zod type to check
|
|
1062
|
+
* @param throwOnTypes - Array of type names to throw errors for
|
|
1063
|
+
* @returns The original value if not in the throw list
|
|
1064
|
+
* @throws Error if the type is in the unsupported list
|
|
1065
|
+
*/
|
|
1066
|
+
defaultUnsupportedZodTypeHandler(value, throwOnTypes) {
|
|
1067
|
+
if ("_zod" in value) {
|
|
1068
|
+
return this.v4Layer.defaultUnsupportedZodTypeHandler(
|
|
1069
|
+
// @ts-expect-error - fix later
|
|
1070
|
+
value,
|
|
1071
|
+
throwOnTypes ?? UNSUPPORTED_ZOD_TYPES2
|
|
1072
|
+
);
|
|
1073
|
+
} else {
|
|
1074
|
+
return this.v3Layer.defaultUnsupportedZodTypeHandler(
|
|
1075
|
+
value,
|
|
1076
|
+
throwOnTypes ?? UNSUPPORTED_ZOD_TYPES
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
1081
|
+
if ("_zod" in value) {
|
|
1082
|
+
return this.v4Layer.defaultZodArrayHandler(value, handleChecks);
|
|
1083
|
+
} else {
|
|
1084
|
+
return this.v3Layer.defaultZodArrayHandler(value, handleChecks);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
defaultZodUnionHandler(value) {
|
|
1088
|
+
if ("_zod" in value) {
|
|
1089
|
+
return this.v4Layer.defaultZodUnionHandler(value);
|
|
1090
|
+
} else {
|
|
1091
|
+
return this.v3Layer.defaultZodUnionHandler(value);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
1095
|
+
if ("_zod" in value) {
|
|
1096
|
+
return this.v4Layer.defaultZodStringHandler(value);
|
|
1097
|
+
} else {
|
|
1098
|
+
return this.v3Layer.defaultZodStringHandler(value, handleChecks);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
1102
|
+
if ("_zod" in value) {
|
|
1103
|
+
return this.v4Layer.defaultZodNumberHandler(value);
|
|
1104
|
+
} else {
|
|
1105
|
+
return this.v3Layer.defaultZodNumberHandler(value, handleChecks);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
defaultZodDateHandler(value) {
|
|
1109
|
+
if ("_zod" in value) {
|
|
1110
|
+
return this.v4Layer.defaultZodDateHandler(value);
|
|
1111
|
+
} else {
|
|
1112
|
+
return this.v3Layer.defaultZodDateHandler(value);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
defaultZodOptionalHandler(value, handleTypes) {
|
|
1116
|
+
if ("_zod" in value) {
|
|
1117
|
+
return this.v4Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES2);
|
|
1118
|
+
} else {
|
|
1119
|
+
return this.v3Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
1124
|
+
*
|
|
1125
|
+
* @param zodSchema - The Zod object schema to process
|
|
1126
|
+
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
1127
|
+
*/
|
|
1128
|
+
processToAISDKSchema(zodSchema) {
|
|
1129
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
1130
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
1134
|
+
*
|
|
1135
|
+
* @param zodSchema - The Zod object schema to process
|
|
1136
|
+
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
1137
|
+
*/
|
|
1138
|
+
processToJSONSchema(zodSchema) {
|
|
1139
|
+
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
// src/zodTypes.ts
|
|
1144
|
+
function isOptional2(z10) {
|
|
1145
|
+
return (v) => v instanceof z10["ZodOptional"];
|
|
1146
|
+
}
|
|
1147
|
+
function isObj2(z10) {
|
|
1148
|
+
return (v) => v instanceof z10["ZodObject"];
|
|
1149
|
+
}
|
|
1150
|
+
function isNull(z10) {
|
|
1151
|
+
return (v) => v instanceof z10["ZodNull"];
|
|
1152
|
+
}
|
|
1153
|
+
function isArr2(z10) {
|
|
1154
|
+
return (v) => v instanceof z10["ZodArray"];
|
|
1155
|
+
}
|
|
1156
|
+
function isUnion2(z10) {
|
|
1157
|
+
return (v) => v instanceof z10["ZodUnion"];
|
|
1158
|
+
}
|
|
1159
|
+
function isString2(z10) {
|
|
1160
|
+
return (v) => v instanceof z10["ZodString"];
|
|
1161
|
+
}
|
|
1162
|
+
function isNumber2(z10) {
|
|
1163
|
+
return (v) => v instanceof z10["ZodNumber"];
|
|
1164
|
+
}
|
|
1165
|
+
function isDate(z10) {
|
|
1166
|
+
return (v) => v instanceof z10["ZodDate"];
|
|
1167
|
+
}
|
|
1168
|
+
function isDefault(z10) {
|
|
1169
|
+
return (v) => v instanceof z10["ZodDefault"];
|
|
1170
|
+
}
|
|
416
1171
|
|
|
417
1172
|
// src/provider-compats/anthropic.ts
|
|
418
|
-
var AnthropicSchemaCompatLayer = class extends
|
|
1173
|
+
var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
419
1174
|
constructor(model) {
|
|
420
1175
|
super(model);
|
|
421
1176
|
}
|
|
@@ -426,29 +1181,38 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
426
1181
|
return this.getModel().modelId.includes("claude");
|
|
427
1182
|
}
|
|
428
1183
|
processZodType(value) {
|
|
429
|
-
if (
|
|
430
|
-
const handleTypes = [
|
|
1184
|
+
if (isOptional2(z)(value)) {
|
|
1185
|
+
const handleTypes = [
|
|
1186
|
+
"ZodObject",
|
|
1187
|
+
"ZodArray",
|
|
1188
|
+
"ZodUnion",
|
|
1189
|
+
"ZodNever",
|
|
1190
|
+
"ZodUndefined",
|
|
1191
|
+
"ZodTuple"
|
|
1192
|
+
];
|
|
431
1193
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
432
1194
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
433
|
-
} else if (
|
|
1195
|
+
} else if (isObj2(z)(value)) {
|
|
434
1196
|
return this.defaultZodObjectHandler(value);
|
|
435
|
-
} else if (
|
|
1197
|
+
} else if (isArr2(z)(value)) {
|
|
436
1198
|
return this.defaultZodArrayHandler(value, []);
|
|
437
|
-
} else if (
|
|
1199
|
+
} else if (isUnion2(z)(value)) {
|
|
438
1200
|
return this.defaultZodUnionHandler(value);
|
|
439
|
-
} else if (
|
|
1201
|
+
} else if (isString2(z)(value)) {
|
|
440
1202
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
441
1203
|
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
442
1204
|
} else {
|
|
443
1205
|
return value;
|
|
444
1206
|
}
|
|
445
1207
|
}
|
|
446
|
-
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1208
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1209
|
+
"ZodNever",
|
|
1210
|
+
"ZodTuple",
|
|
1211
|
+
"ZodUndefined"
|
|
1212
|
+
]);
|
|
447
1213
|
}
|
|
448
1214
|
};
|
|
449
|
-
|
|
450
|
-
// src/provider-compats/deepseek.ts
|
|
451
|
-
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1215
|
+
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
452
1216
|
constructor(model) {
|
|
453
1217
|
super(model);
|
|
454
1218
|
}
|
|
@@ -459,21 +1223,21 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
459
1223
|
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
460
1224
|
}
|
|
461
1225
|
processZodType(value) {
|
|
462
|
-
if (
|
|
1226
|
+
if (isOptional2(z)(value)) {
|
|
463
1227
|
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
464
|
-
} else if (
|
|
1228
|
+
} else if (isObj2(z)(value)) {
|
|
465
1229
|
return this.defaultZodObjectHandler(value);
|
|
466
|
-
} else if (
|
|
1230
|
+
} else if (isArr2(z)(value)) {
|
|
467
1231
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
468
|
-
} else if (
|
|
1232
|
+
} else if (isUnion2(z)(value)) {
|
|
469
1233
|
return this.defaultZodUnionHandler(value);
|
|
470
|
-
} else if (
|
|
1234
|
+
} else if (isString2(z)(value)) {
|
|
471
1235
|
return this.defaultZodStringHandler(value);
|
|
472
1236
|
}
|
|
473
1237
|
return value;
|
|
474
1238
|
}
|
|
475
1239
|
};
|
|
476
|
-
var GoogleSchemaCompatLayer = class extends
|
|
1240
|
+
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
477
1241
|
constructor(model) {
|
|
478
1242
|
super(model);
|
|
479
1243
|
}
|
|
@@ -484,34 +1248,25 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
484
1248
|
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
485
1249
|
}
|
|
486
1250
|
processZodType(value) {
|
|
487
|
-
if (
|
|
488
|
-
return this.defaultZodOptionalHandler(value, [
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
"ZodString",
|
|
493
|
-
"ZodNumber",
|
|
494
|
-
...UNSUPPORTED_ZOD_TYPES
|
|
495
|
-
]);
|
|
496
|
-
} else if (isNull(value)) {
|
|
497
|
-
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value._def.description || "must be null");
|
|
498
|
-
} else if (isObj(value)) {
|
|
1251
|
+
if (isOptional2(z)(value)) {
|
|
1252
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
1253
|
+
} else if (isNull(z)(value)) {
|
|
1254
|
+
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
1255
|
+
} else if (isObj2(z)(value)) {
|
|
499
1256
|
return this.defaultZodObjectHandler(value);
|
|
500
|
-
} else if (
|
|
1257
|
+
} else if (isArr2(z)(value)) {
|
|
501
1258
|
return this.defaultZodArrayHandler(value, []);
|
|
502
|
-
} else if (
|
|
1259
|
+
} else if (isUnion2(z)(value)) {
|
|
503
1260
|
return this.defaultZodUnionHandler(value);
|
|
504
|
-
} else if (
|
|
1261
|
+
} else if (isString2(z)(value)) {
|
|
505
1262
|
return this.defaultZodStringHandler(value);
|
|
506
|
-
} else if (
|
|
1263
|
+
} else if (isNumber2(z)(value)) {
|
|
507
1264
|
return this.defaultZodNumberHandler(value);
|
|
508
1265
|
}
|
|
509
1266
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
510
1267
|
}
|
|
511
1268
|
};
|
|
512
|
-
|
|
513
|
-
// src/provider-compats/meta.ts
|
|
514
|
-
var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1269
|
+
var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
515
1270
|
constructor(model) {
|
|
516
1271
|
super(model);
|
|
517
1272
|
}
|
|
@@ -522,25 +1277,23 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
522
1277
|
return this.getModel().modelId.includes("meta");
|
|
523
1278
|
}
|
|
524
1279
|
processZodType(value) {
|
|
525
|
-
if (
|
|
1280
|
+
if (isOptional2(z)(value)) {
|
|
526
1281
|
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
527
|
-
} else if (
|
|
1282
|
+
} else if (isObj2(z)(value)) {
|
|
528
1283
|
return this.defaultZodObjectHandler(value);
|
|
529
|
-
} else if (
|
|
1284
|
+
} else if (isArr2(z)(value)) {
|
|
530
1285
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
531
|
-
} else if (
|
|
1286
|
+
} else if (isUnion2(z)(value)) {
|
|
532
1287
|
return this.defaultZodUnionHandler(value);
|
|
533
|
-
} else if (
|
|
1288
|
+
} else if (isNumber2(z)(value)) {
|
|
534
1289
|
return this.defaultZodNumberHandler(value);
|
|
535
|
-
} else if (
|
|
1290
|
+
} else if (isString2(z)(value)) {
|
|
536
1291
|
return this.defaultZodStringHandler(value);
|
|
537
1292
|
}
|
|
538
1293
|
return value;
|
|
539
1294
|
}
|
|
540
1295
|
};
|
|
541
|
-
|
|
542
|
-
// src/provider-compats/openai.ts
|
|
543
|
-
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1296
|
+
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
544
1297
|
constructor(model) {
|
|
545
1298
|
super(model);
|
|
546
1299
|
}
|
|
@@ -554,7 +1307,7 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
554
1307
|
return false;
|
|
555
1308
|
}
|
|
556
1309
|
processZodType(value) {
|
|
557
|
-
if (
|
|
1310
|
+
if (isOptional2(z)(value)) {
|
|
558
1311
|
return this.defaultZodOptionalHandler(value, [
|
|
559
1312
|
"ZodObject",
|
|
560
1313
|
"ZodArray",
|
|
@@ -564,24 +1317,28 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
564
1317
|
"ZodUndefined",
|
|
565
1318
|
"ZodTuple"
|
|
566
1319
|
]);
|
|
567
|
-
} else if (
|
|
1320
|
+
} else if (isObj2(z)(value)) {
|
|
568
1321
|
return this.defaultZodObjectHandler(value);
|
|
569
|
-
} else if (
|
|
1322
|
+
} else if (isUnion2(z)(value)) {
|
|
570
1323
|
return this.defaultZodUnionHandler(value);
|
|
571
|
-
} else if (
|
|
1324
|
+
} else if (isArr2(z)(value)) {
|
|
572
1325
|
return this.defaultZodArrayHandler(value);
|
|
573
|
-
} else if (
|
|
1326
|
+
} else if (isString2(z)(value)) {
|
|
574
1327
|
const model = this.getModel();
|
|
575
1328
|
const checks = ["emoji"];
|
|
576
1329
|
if (model.modelId.includes("gpt-4o-mini")) {
|
|
577
|
-
|
|
1330
|
+
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
578
1331
|
}
|
|
579
1332
|
return this.defaultZodStringHandler(value, checks);
|
|
580
1333
|
}
|
|
581
|
-
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1334
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1335
|
+
"ZodNever",
|
|
1336
|
+
"ZodUndefined",
|
|
1337
|
+
"ZodTuple"
|
|
1338
|
+
]);
|
|
582
1339
|
}
|
|
583
1340
|
};
|
|
584
|
-
var OpenAIReasoningSchemaCompatLayer = class extends
|
|
1341
|
+
var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
585
1342
|
constructor(model) {
|
|
586
1343
|
super(model);
|
|
587
1344
|
}
|
|
@@ -589,7 +1346,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
589
1346
|
return `openApi3`;
|
|
590
1347
|
}
|
|
591
1348
|
isReasoningModel() {
|
|
592
|
-
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
|
|
1349
|
+
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
|
|
593
1350
|
}
|
|
594
1351
|
shouldApply() {
|
|
595
1352
|
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
@@ -598,16 +1355,16 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
598
1355
|
return false;
|
|
599
1356
|
}
|
|
600
1357
|
processZodType(value) {
|
|
601
|
-
if (
|
|
1358
|
+
if (isOptional2(z)(value)) {
|
|
602
1359
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
603
1360
|
return innerZodType.nullable();
|
|
604
|
-
} else if (
|
|
1361
|
+
} else if (isObj2(z)(value)) {
|
|
605
1362
|
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
606
|
-
} else if (
|
|
1363
|
+
} else if (isArr2(z)(value)) {
|
|
607
1364
|
return this.defaultZodArrayHandler(value);
|
|
608
|
-
} else if (
|
|
1365
|
+
} else if (isUnion2(z)(value)) {
|
|
609
1366
|
return this.defaultZodUnionHandler(value);
|
|
610
|
-
} else if (isDefault(value)) {
|
|
1367
|
+
} else if (isDefault(z)(value)) {
|
|
611
1368
|
const defaultDef = value._def;
|
|
612
1369
|
const innerType = defaultDef.innerType;
|
|
613
1370
|
const defaultValue = defaultDef.defaultValue();
|
|
@@ -621,13 +1378,13 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
621
1378
|
result = result.describe(description);
|
|
622
1379
|
}
|
|
623
1380
|
return result;
|
|
624
|
-
} else if (
|
|
1381
|
+
} else if (isNumber2(z)(value)) {
|
|
625
1382
|
return this.defaultZodNumberHandler(value);
|
|
626
|
-
} else if (
|
|
1383
|
+
} else if (isString2(z)(value)) {
|
|
627
1384
|
return this.defaultZodStringHandler(value);
|
|
628
|
-
} else if (isDate(value)) {
|
|
1385
|
+
} else if (isDate(z)(value)) {
|
|
629
1386
|
return this.defaultZodDateHandler(value);
|
|
630
|
-
} else if (value.
|
|
1387
|
+
} else if (value.constructor.name === "ZodAny") {
|
|
631
1388
|
return z.string().describe(
|
|
632
1389
|
(value.description ?? "") + `
|
|
633
1390
|
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
@@ -637,4 +1394,6 @@ Argument was an "any" type, but you (the LLM) do not support "any", so it was ca
|
|
|
637
1394
|
}
|
|
638
1395
|
};
|
|
639
1396
|
|
|
640
|
-
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 };
|
|
1397
|
+
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 };
|
|
1398
|
+
//# sourceMappingURL=index.js.map
|
|
1399
|
+
//# sourceMappingURL=index.js.map
|