@mastra/schema-compat 0.0.0-fix-fetching-workflow-snapshots-20250625000954 → 0.0.0-fix-zod-to-json-schema-ref-strategy-20250910193441
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/CHANGELOG.md +139 -1
- package/LICENSE.md +11 -42
- package/README.md +0 -4
- package/dist/chunk-7YUR5KZ5.cjs +34 -0
- package/dist/chunk-7YUR5KZ5.cjs.map +1 -0
- package/dist/chunk-GWTUXMDD.js +28 -0
- package/dist/chunk-GWTUXMDD.js.map +1 -0
- package/dist/index.cjs +847 -85
- 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 +846 -86
- 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 +37 -13
- package/.turbo/turbo-build.log +0 -23
- package/dist/_tsup-dts-rollup.d.cts +0 -504
- package/dist/_tsup-dts-rollup.d.ts +0 -504
- package/dist/index.d.cts +0 -31
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -39
- package/src/provider-compats/anthropic.ts +0 -44
- package/src/provider-compats/deepseek.ts +0 -35
- package/src/provider-compats/google.ts +0 -55
- package/src/provider-compats/meta.ts +0 -36
- package/src/provider-compats/openai-reasoning.ts +0 -87
- package/src/provider-compats/openai.ts +0 -56
- package/src/provider-compats.test.ts +0 -312
- package/src/schema-compatibility.test.ts +0 -471
- package/src/schema-compatibility.ts +0 -587
- package/src/utils.test.ts +0 -434
- package/src/utils.ts +0 -205
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -7
package/dist/index.cjs
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk7YUR5KZ5_cjs = require('./chunk-7YUR5KZ5.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 = chunk7YUR5KZ5_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 chunk7YUR5KZ5_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",
|
|
@@ -77,8 +77,6 @@ var isArr = (v) => v instanceof zod.ZodArray;
|
|
|
77
77
|
var isUnion = (v) => v instanceof zod.ZodUnion;
|
|
78
78
|
var isString = (v) => v instanceof zod.ZodString;
|
|
79
79
|
var isNumber = (v) => v instanceof zod.ZodNumber;
|
|
80
|
-
var isDate = (v) => v instanceof zod.ZodDate;
|
|
81
|
-
var isDefault = (v) => v instanceof zod.ZodDefault;
|
|
82
80
|
var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
83
81
|
var SUPPORTED_ZOD_TYPES = [
|
|
84
82
|
"ZodObject",
|
|
@@ -93,13 +91,15 @@ var SUPPORTED_ZOD_TYPES = [
|
|
|
93
91
|
var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
|
|
94
92
|
var SchemaCompatLayer = class {
|
|
95
93
|
model;
|
|
94
|
+
parent;
|
|
96
95
|
/**
|
|
97
96
|
* Creates a new schema compatibility instance.
|
|
98
97
|
*
|
|
99
98
|
* @param model - The language model this compatibility layer applies to
|
|
100
99
|
*/
|
|
101
|
-
constructor(model) {
|
|
100
|
+
constructor(model, parent) {
|
|
102
101
|
this.model = model;
|
|
102
|
+
this.parent = parent;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Gets the language model associated with this compatibility layer.
|
|
@@ -109,6 +109,91 @@ var SchemaCompatLayer = class {
|
|
|
109
109
|
getModel() {
|
|
110
110
|
return this.model;
|
|
111
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
|
+
}
|
|
112
197
|
/**
|
|
113
198
|
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
114
199
|
*
|
|
@@ -161,8 +246,8 @@ var SchemaCompatLayer = class {
|
|
|
161
246
|
* @throws Error if the type is in the unsupported list
|
|
162
247
|
*/
|
|
163
248
|
defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES) {
|
|
164
|
-
if (throwOnTypes.includes(value._def
|
|
165
|
-
throw new Error(`${this.model.modelId} does not support zod type: ${value._def
|
|
249
|
+
if (throwOnTypes.includes(value._def?.typeName)) {
|
|
250
|
+
throw new Error(`${this.model.modelId} does not support zod type: ${value._def?.typeName}`);
|
|
166
251
|
}
|
|
167
252
|
return value;
|
|
168
253
|
}
|
|
@@ -414,9 +499,680 @@ var SchemaCompatLayer = class {
|
|
|
414
499
|
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
415
500
|
}
|
|
416
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
|
+
}
|
|
417
1173
|
|
|
418
1174
|
// src/provider-compats/anthropic.ts
|
|
419
|
-
var AnthropicSchemaCompatLayer = class extends
|
|
1175
|
+
var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
420
1176
|
constructor(model) {
|
|
421
1177
|
super(model);
|
|
422
1178
|
}
|
|
@@ -427,29 +1183,38 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
427
1183
|
return this.getModel().modelId.includes("claude");
|
|
428
1184
|
}
|
|
429
1185
|
processZodType(value) {
|
|
430
|
-
if (
|
|
431
|
-
const handleTypes = [
|
|
1186
|
+
if (isOptional2(zod.z)(value)) {
|
|
1187
|
+
const handleTypes = [
|
|
1188
|
+
"ZodObject",
|
|
1189
|
+
"ZodArray",
|
|
1190
|
+
"ZodUnion",
|
|
1191
|
+
"ZodNever",
|
|
1192
|
+
"ZodUndefined",
|
|
1193
|
+
"ZodTuple"
|
|
1194
|
+
];
|
|
432
1195
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
433
1196
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
434
|
-
} else if (
|
|
1197
|
+
} else if (isObj2(zod.z)(value)) {
|
|
435
1198
|
return this.defaultZodObjectHandler(value);
|
|
436
|
-
} else if (
|
|
1199
|
+
} else if (isArr2(zod.z)(value)) {
|
|
437
1200
|
return this.defaultZodArrayHandler(value, []);
|
|
438
|
-
} else if (
|
|
1201
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
439
1202
|
return this.defaultZodUnionHandler(value);
|
|
440
|
-
} else if (
|
|
1203
|
+
} else if (isString2(zod.z)(value)) {
|
|
441
1204
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
442
1205
|
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
443
1206
|
} else {
|
|
444
1207
|
return value;
|
|
445
1208
|
}
|
|
446
1209
|
}
|
|
447
|
-
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1210
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1211
|
+
"ZodNever",
|
|
1212
|
+
"ZodTuple",
|
|
1213
|
+
"ZodUndefined"
|
|
1214
|
+
]);
|
|
448
1215
|
}
|
|
449
1216
|
};
|
|
450
|
-
|
|
451
|
-
// src/provider-compats/deepseek.ts
|
|
452
|
-
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1217
|
+
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
453
1218
|
constructor(model) {
|
|
454
1219
|
super(model);
|
|
455
1220
|
}
|
|
@@ -460,23 +1225,21 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
460
1225
|
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
461
1226
|
}
|
|
462
1227
|
processZodType(value) {
|
|
463
|
-
if (
|
|
1228
|
+
if (isOptional2(zod.z)(value)) {
|
|
464
1229
|
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
465
|
-
} else if (
|
|
1230
|
+
} else if (isObj2(zod.z)(value)) {
|
|
466
1231
|
return this.defaultZodObjectHandler(value);
|
|
467
|
-
} else if (
|
|
1232
|
+
} else if (isArr2(zod.z)(value)) {
|
|
468
1233
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
469
|
-
} else if (
|
|
1234
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
470
1235
|
return this.defaultZodUnionHandler(value);
|
|
471
|
-
} else if (
|
|
1236
|
+
} else if (isString2(zod.z)(value)) {
|
|
472
1237
|
return this.defaultZodStringHandler(value);
|
|
473
1238
|
}
|
|
474
1239
|
return value;
|
|
475
1240
|
}
|
|
476
1241
|
};
|
|
477
|
-
|
|
478
|
-
// src/provider-compats/google.ts
|
|
479
|
-
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1242
|
+
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
480
1243
|
constructor(model) {
|
|
481
1244
|
super(model);
|
|
482
1245
|
}
|
|
@@ -487,32 +1250,25 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
487
1250
|
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
488
1251
|
}
|
|
489
1252
|
processZodType(value) {
|
|
490
|
-
if (
|
|
491
|
-
return this.defaultZodOptionalHandler(value, [
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
"ZodString",
|
|
496
|
-
"ZodNumber",
|
|
497
|
-
...UNSUPPORTED_ZOD_TYPES
|
|
498
|
-
]);
|
|
499
|
-
} 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)) {
|
|
500
1258
|
return this.defaultZodObjectHandler(value);
|
|
501
|
-
} else if (
|
|
1259
|
+
} else if (isArr2(zod.z)(value)) {
|
|
502
1260
|
return this.defaultZodArrayHandler(value, []);
|
|
503
|
-
} else if (
|
|
1261
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
504
1262
|
return this.defaultZodUnionHandler(value);
|
|
505
|
-
} else if (
|
|
1263
|
+
} else if (isString2(zod.z)(value)) {
|
|
506
1264
|
return this.defaultZodStringHandler(value);
|
|
507
|
-
} else if (
|
|
1265
|
+
} else if (isNumber2(zod.z)(value)) {
|
|
508
1266
|
return this.defaultZodNumberHandler(value);
|
|
509
1267
|
}
|
|
510
1268
|
return this.defaultUnsupportedZodTypeHandler(value);
|
|
511
1269
|
}
|
|
512
1270
|
};
|
|
513
|
-
|
|
514
|
-
// src/provider-compats/meta.ts
|
|
515
|
-
var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1271
|
+
var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
516
1272
|
constructor(model) {
|
|
517
1273
|
super(model);
|
|
518
1274
|
}
|
|
@@ -523,25 +1279,23 @@ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
523
1279
|
return this.getModel().modelId.includes("meta");
|
|
524
1280
|
}
|
|
525
1281
|
processZodType(value) {
|
|
526
|
-
if (
|
|
1282
|
+
if (isOptional2(zod.z)(value)) {
|
|
527
1283
|
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
528
|
-
} else if (
|
|
1284
|
+
} else if (isObj2(zod.z)(value)) {
|
|
529
1285
|
return this.defaultZodObjectHandler(value);
|
|
530
|
-
} else if (
|
|
1286
|
+
} else if (isArr2(zod.z)(value)) {
|
|
531
1287
|
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
532
|
-
} else if (
|
|
1288
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
533
1289
|
return this.defaultZodUnionHandler(value);
|
|
534
|
-
} else if (
|
|
1290
|
+
} else if (isNumber2(zod.z)(value)) {
|
|
535
1291
|
return this.defaultZodNumberHandler(value);
|
|
536
|
-
} else if (
|
|
1292
|
+
} else if (isString2(zod.z)(value)) {
|
|
537
1293
|
return this.defaultZodStringHandler(value);
|
|
538
1294
|
}
|
|
539
1295
|
return value;
|
|
540
1296
|
}
|
|
541
1297
|
};
|
|
542
|
-
|
|
543
|
-
// src/provider-compats/openai.ts
|
|
544
|
-
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
1298
|
+
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
545
1299
|
constructor(model) {
|
|
546
1300
|
super(model);
|
|
547
1301
|
}
|
|
@@ -555,7 +1309,7 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
555
1309
|
return false;
|
|
556
1310
|
}
|
|
557
1311
|
processZodType(value) {
|
|
558
|
-
if (
|
|
1312
|
+
if (isOptional2(zod.z)(value)) {
|
|
559
1313
|
return this.defaultZodOptionalHandler(value, [
|
|
560
1314
|
"ZodObject",
|
|
561
1315
|
"ZodArray",
|
|
@@ -565,24 +1319,28 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
565
1319
|
"ZodUndefined",
|
|
566
1320
|
"ZodTuple"
|
|
567
1321
|
]);
|
|
568
|
-
} else if (
|
|
1322
|
+
} else if (isObj2(zod.z)(value)) {
|
|
569
1323
|
return this.defaultZodObjectHandler(value);
|
|
570
|
-
} else if (
|
|
1324
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
571
1325
|
return this.defaultZodUnionHandler(value);
|
|
572
|
-
} else if (
|
|
1326
|
+
} else if (isArr2(zod.z)(value)) {
|
|
573
1327
|
return this.defaultZodArrayHandler(value);
|
|
574
|
-
} else if (
|
|
1328
|
+
} else if (isString2(zod.z)(value)) {
|
|
575
1329
|
const model = this.getModel();
|
|
576
1330
|
const checks = ["emoji"];
|
|
577
1331
|
if (model.modelId.includes("gpt-4o-mini")) {
|
|
578
|
-
|
|
1332
|
+
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
579
1333
|
}
|
|
580
1334
|
return this.defaultZodStringHandler(value, checks);
|
|
581
1335
|
}
|
|
582
|
-
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1336
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1337
|
+
"ZodNever",
|
|
1338
|
+
"ZodUndefined",
|
|
1339
|
+
"ZodTuple"
|
|
1340
|
+
]);
|
|
583
1341
|
}
|
|
584
1342
|
};
|
|
585
|
-
var OpenAIReasoningSchemaCompatLayer = class extends
|
|
1343
|
+
var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
586
1344
|
constructor(model) {
|
|
587
1345
|
super(model);
|
|
588
1346
|
}
|
|
@@ -590,7 +1348,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
590
1348
|
return `openApi3`;
|
|
591
1349
|
}
|
|
592
1350
|
isReasoningModel() {
|
|
593
|
-
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`);
|
|
594
1352
|
}
|
|
595
1353
|
shouldApply() {
|
|
596
1354
|
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
@@ -599,16 +1357,16 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
599
1357
|
return false;
|
|
600
1358
|
}
|
|
601
1359
|
processZodType(value) {
|
|
602
|
-
if (
|
|
1360
|
+
if (isOptional2(zod.z)(value)) {
|
|
603
1361
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
604
1362
|
return innerZodType.nullable();
|
|
605
|
-
} else if (
|
|
1363
|
+
} else if (isObj2(zod.z)(value)) {
|
|
606
1364
|
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
607
|
-
} else if (
|
|
1365
|
+
} else if (isArr2(zod.z)(value)) {
|
|
608
1366
|
return this.defaultZodArrayHandler(value);
|
|
609
|
-
} else if (
|
|
1367
|
+
} else if (isUnion2(zod.z)(value)) {
|
|
610
1368
|
return this.defaultZodUnionHandler(value);
|
|
611
|
-
} else if (isDefault(value)) {
|
|
1369
|
+
} else if (isDefault(zod.z)(value)) {
|
|
612
1370
|
const defaultDef = value._def;
|
|
613
1371
|
const innerType = defaultDef.innerType;
|
|
614
1372
|
const defaultValue = defaultDef.defaultValue();
|
|
@@ -622,13 +1380,13 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
622
1380
|
result = result.describe(description);
|
|
623
1381
|
}
|
|
624
1382
|
return result;
|
|
625
|
-
} else if (
|
|
1383
|
+
} else if (isNumber2(zod.z)(value)) {
|
|
626
1384
|
return this.defaultZodNumberHandler(value);
|
|
627
|
-
} else if (
|
|
1385
|
+
} else if (isString2(zod.z)(value)) {
|
|
628
1386
|
return this.defaultZodStringHandler(value);
|
|
629
|
-
} else if (isDate(value)) {
|
|
1387
|
+
} else if (isDate(zod.z)(value)) {
|
|
630
1388
|
return this.defaultZodDateHandler(value);
|
|
631
|
-
} else if (value.
|
|
1389
|
+
} else if (value.constructor.name === "ZodAny") {
|
|
632
1390
|
return zod.z.string().describe(
|
|
633
1391
|
(value.description ?? "") + `
|
|
634
1392
|
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
@@ -649,7 +1407,9 @@ exports.MetaSchemaCompatLayer = MetaSchemaCompatLayer;
|
|
|
649
1407
|
exports.OpenAIReasoningSchemaCompatLayer = OpenAIReasoningSchemaCompatLayer;
|
|
650
1408
|
exports.OpenAISchemaCompatLayer = OpenAISchemaCompatLayer;
|
|
651
1409
|
exports.SUPPORTED_ZOD_TYPES = SUPPORTED_ZOD_TYPES;
|
|
652
|
-
exports.SchemaCompatLayer =
|
|
1410
|
+
exports.SchemaCompatLayer = SchemaCompatLayer3;
|
|
1411
|
+
exports.SchemaCompatLayerV3 = SchemaCompatLayer;
|
|
1412
|
+
exports.SchemaCompatLayerV4 = SchemaCompatLayer2;
|
|
653
1413
|
exports.UNSUPPORTED_ZOD_TYPES = UNSUPPORTED_ZOD_TYPES;
|
|
654
1414
|
exports.applyCompatLayer = applyCompatLayer;
|
|
655
1415
|
exports.convertSchemaToZod = convertSchemaToZod;
|
|
@@ -660,3 +1420,5 @@ exports.isObj = isObj;
|
|
|
660
1420
|
exports.isOptional = isOptional;
|
|
661
1421
|
exports.isString = isString;
|
|
662
1422
|
exports.isUnion = isUnion;
|
|
1423
|
+
//# sourceMappingURL=index.cjs.map
|
|
1424
|
+
//# sourceMappingURL=index.cjs.map
|