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