@mastra/schema-compat 0.10.7 → 0.11.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 +1 -1
- package/CHANGELOG.md +40 -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 +846 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +845 -85
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/anthropic.d.ts +6 -4
- package/dist/provider-compats/anthropic.d.ts.map +1 -1
- package/dist/provider-compats/deepseek.d.ts +6 -4
- package/dist/provider-compats/deepseek.d.ts.map +1 -1
- package/dist/provider-compats/google.d.ts +6 -4
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/meta.d.ts +6 -4
- package/dist/provider-compats/meta.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts +6 -4
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts +6 -4
- package/dist/provider-compats/openai.d.ts.map +1 -1
- 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 +80 -134
- package/dist/schema-compatibility.d.ts.map +1 -1
- 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 +17 -5
- package/dist/utils.d.ts.map +1 -1
- 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 +16 -6
- package/src/index.ts +4 -3
- package/src/provider-compats/anthropic.ts +29 -11
- package/src/provider-compats/deepseek.ts +14 -9
- package/src/provider-compats/google.ts +18 -32
- package/src/provider-compats/meta.ts +15 -10
- package/src/provider-compats/openai-reasoning.ts +18 -24
- package/src/provider-compats/openai.ts +22 -12
- 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 +12 -28
- package/src/schema-compatibility.ts +263 -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/tsup.config.ts +8 -3
- package/src/utils.test.ts +0 -460
|
@@ -1,83 +1,10 @@
|
|
|
1
1
|
import type { Schema } from 'ai';
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
-
import { z
|
|
4
|
-
import type {
|
|
3
|
+
import type { z as zV3 } from 'zod/v3';
|
|
4
|
+
import type { z as zV4, ZodType } from 'zod/v4';
|
|
5
5
|
import type { Targets } from 'zod-to-json-schema';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @constant
|
|
9
|
-
*/
|
|
10
|
-
export declare const ALL_STRING_CHECKS: readonly ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
|
|
11
|
-
/**
|
|
12
|
-
* All supported number validation check types that can be processed or converted to descriptions.
|
|
13
|
-
* @constant
|
|
14
|
-
*/
|
|
15
|
-
export declare const ALL_NUMBER_CHECKS: readonly ["min", "max", "multipleOf"];
|
|
16
|
-
/**
|
|
17
|
-
* All supported array validation check types that can be processed or converted to descriptions.
|
|
18
|
-
* @constant
|
|
19
|
-
*/
|
|
20
|
-
export declare const ALL_ARRAY_CHECKS: readonly ["min", "max", "length"];
|
|
21
|
-
export declare const isOptional: (v: ZodTypeAny) => v is ZodOptional<any>;
|
|
22
|
-
export declare const isObj: (v: ZodTypeAny) => v is ZodObject<any, any, any>;
|
|
23
|
-
export declare const isNull: (v: ZodTypeAny) => v is ZodNull;
|
|
24
|
-
export declare const isArr: (v: ZodTypeAny) => v is ZodArray<any, any>;
|
|
25
|
-
export declare const isUnion: (v: ZodTypeAny) => v is ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>;
|
|
26
|
-
export declare const isString: (v: ZodTypeAny) => v is ZodString;
|
|
27
|
-
export declare const isNumber: (v: ZodTypeAny) => v is ZodNumber;
|
|
28
|
-
export declare const isDate: (v: ZodTypeAny) => v is ZodDate;
|
|
29
|
-
export declare const isDefault: (v: ZodTypeAny) => v is ZodDefault<any>;
|
|
30
|
-
/**
|
|
31
|
-
* Zod types that are not supported by most AI model providers and should be avoided.
|
|
32
|
-
* @constant
|
|
33
|
-
*/
|
|
34
|
-
export declare const UNSUPPORTED_ZOD_TYPES: readonly ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
35
|
-
/**
|
|
36
|
-
* Zod types that are generally supported by AI model providers.
|
|
37
|
-
* @constant
|
|
38
|
-
*/
|
|
39
|
-
export declare const SUPPORTED_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault"];
|
|
40
|
-
/**
|
|
41
|
-
* All Zod types (both supported and unsupported).
|
|
42
|
-
* @constant
|
|
43
|
-
*/
|
|
44
|
-
export declare const ALL_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault", "ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
45
|
-
/**
|
|
46
|
-
* Type representing string validation checks.
|
|
47
|
-
*/
|
|
48
|
-
export type StringCheckType = (typeof ALL_STRING_CHECKS)[number];
|
|
49
|
-
/**
|
|
50
|
-
* Type representing number validation checks.
|
|
51
|
-
*/
|
|
52
|
-
export type NumberCheckType = (typeof ALL_NUMBER_CHECKS)[number];
|
|
53
|
-
/**
|
|
54
|
-
* Type representing array validation checks.
|
|
55
|
-
*/
|
|
56
|
-
export type ArrayCheckType = (typeof ALL_ARRAY_CHECKS)[number];
|
|
57
|
-
/**
|
|
58
|
-
* Type representing unsupported Zod schema types.
|
|
59
|
-
*/
|
|
60
|
-
export type UnsupportedZodType = (typeof UNSUPPORTED_ZOD_TYPES)[number];
|
|
61
|
-
/**
|
|
62
|
-
* Type representing supported Zod schema types.
|
|
63
|
-
*/
|
|
64
|
-
export type SupportedZodType = (typeof SUPPORTED_ZOD_TYPES)[number];
|
|
65
|
-
/**
|
|
66
|
-
* Type representing all Zod schema types (supported and unsupported).
|
|
67
|
-
*/
|
|
68
|
-
export type AllZodType = (typeof ALL_ZOD_TYPES)[number];
|
|
69
|
-
/**
|
|
70
|
-
* Utility type to extract the shape of a Zod object schema.
|
|
71
|
-
*/
|
|
72
|
-
export type ZodShape<T extends z.AnyZodObject> = T['shape'];
|
|
73
|
-
/**
|
|
74
|
-
* Utility type to extract the keys from a Zod object shape.
|
|
75
|
-
*/
|
|
76
|
-
export type ShapeKey<T extends z.AnyZodObject> = keyof ZodShape<T>;
|
|
77
|
-
/**
|
|
78
|
-
* Utility type to extract the value types from a Zod object shape.
|
|
79
|
-
*/
|
|
80
|
-
export type ShapeValue<T extends z.AnyZodObject> = ZodShape<T>[ShapeKey<T>];
|
|
6
|
+
import type { UnsupportedZodType as UnsupportedZodTypeV3, ShapeValue as ShapeValueV3, StringCheckType, NumberCheckType, ArrayCheckType, AllZodType as AllZodTypeV3 } from './schema-compatibility-v3';
|
|
7
|
+
import type { UnsupportedZodType as UnsupportedZodTypeV4, ShapeValue as ShapeValueV4, AllZodType as AllZodTypeV4 } from './schema-compatibility-v4';
|
|
81
8
|
type StringConstraints = {
|
|
82
9
|
minLength?: number;
|
|
83
10
|
maxLength?: number;
|
|
@@ -86,7 +13,10 @@ type StringConstraints = {
|
|
|
86
13
|
uuid?: boolean;
|
|
87
14
|
cuid?: boolean;
|
|
88
15
|
emoji?: boolean;
|
|
89
|
-
regex?:
|
|
16
|
+
regex?: {
|
|
17
|
+
pattern: string;
|
|
18
|
+
flags?: string;
|
|
19
|
+
};
|
|
90
20
|
};
|
|
91
21
|
type NumberConstraints = {
|
|
92
22
|
gt?: number;
|
|
@@ -105,52 +35,11 @@ type DateConstraints = {
|
|
|
105
35
|
maxDate?: string;
|
|
106
36
|
dateFormat?: string;
|
|
107
37
|
};
|
|
108
|
-
|
|
109
|
-
modelId: string;
|
|
110
|
-
provider: string;
|
|
111
|
-
supportsStructuredOutputs: boolean;
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Abstract base class for creating schema compatibility layers for different AI model providers.
|
|
115
|
-
*
|
|
116
|
-
* This class provides a framework for transforming Zod schemas to work with specific AI model
|
|
117
|
-
* provider requirements and limitations. Each provider may have different support levels for
|
|
118
|
-
* JSON Schema features, validation constraints, and data types.
|
|
119
|
-
*
|
|
120
|
-
* @abstract
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* import { SchemaCompatLayer } from '@mastra/schema-compat';
|
|
125
|
-
* import type { LanguageModelV1 } from 'ai';
|
|
126
|
-
*
|
|
127
|
-
* class CustomProviderCompat extends SchemaCompatLayer {
|
|
128
|
-
* constructor(model: LanguageModelV1) {
|
|
129
|
-
* super(model);
|
|
130
|
-
* }
|
|
131
|
-
*
|
|
132
|
-
* shouldApply(): boolean {
|
|
133
|
-
* return this.getModel().provider === 'custom-provider';
|
|
134
|
-
* }
|
|
135
|
-
*
|
|
136
|
-
* getSchemaTarget() {
|
|
137
|
-
* return 'jsonSchema7';
|
|
138
|
-
* }
|
|
139
|
-
*
|
|
140
|
-
* processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
|
|
141
|
-
* // Custom processing logic for this provider
|
|
142
|
-
* switch (value._def.typeName) {
|
|
143
|
-
* case 'ZodString':
|
|
144
|
-
* return this.defaultZodStringHandler(value, ['email', 'url']);
|
|
145
|
-
* default:
|
|
146
|
-
* return this.defaultUnsupportedZodTypeHandler(value);
|
|
147
|
-
* }
|
|
148
|
-
* }
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
38
|
+
import type { ModelInformation } from './types';
|
|
152
39
|
export declare abstract class SchemaCompatLayer {
|
|
153
40
|
private model;
|
|
41
|
+
private v3Layer;
|
|
42
|
+
private v4Layer;
|
|
154
43
|
/**
|
|
155
44
|
* Creates a new schema compatibility instance.
|
|
156
45
|
*
|
|
@@ -163,6 +52,52 @@ export declare abstract class SchemaCompatLayer {
|
|
|
163
52
|
* @returns The language model instance
|
|
164
53
|
*/
|
|
165
54
|
getModel(): ModelInformation;
|
|
55
|
+
getUnsupportedZodTypes(v: ZodType): readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* Type guard for optional Zod types
|
|
58
|
+
*/
|
|
59
|
+
isOptional(v: zV4.ZodType): v is zV4.ZodOptional<any>;
|
|
60
|
+
isOptional(v: zV3.ZodType): v is zV3.ZodOptional<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Type guard for object Zod types
|
|
63
|
+
*/
|
|
64
|
+
isObj(v: zV4.ZodType): v is zV4.ZodObject<any, any>;
|
|
65
|
+
isObj(v: zV3.ZodType): v is zV3.ZodObject<any, any, any, any, any>;
|
|
66
|
+
/**
|
|
67
|
+
* Type guard for null Zod types
|
|
68
|
+
*/
|
|
69
|
+
isNull(v: zV4.ZodType): v is zV4.ZodNull;
|
|
70
|
+
isNull(v: zV3.ZodType): v is zV3.ZodNull;
|
|
71
|
+
/**
|
|
72
|
+
* Type guard for array Zod types
|
|
73
|
+
*/
|
|
74
|
+
isArr(v: zV4.ZodType): v is zV4.ZodArray<any>;
|
|
75
|
+
isArr(v: zV3.ZodType): v is zV3.ZodArray<any, any>;
|
|
76
|
+
/**
|
|
77
|
+
* Type guard for union Zod types
|
|
78
|
+
*/
|
|
79
|
+
isUnion(v: zV4.ZodType): v is zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>;
|
|
80
|
+
isUnion(v: zV3.ZodType): v is zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>;
|
|
81
|
+
/**
|
|
82
|
+
* Type guard for string Zod types
|
|
83
|
+
*/
|
|
84
|
+
isString(v: zV4.ZodType): v is zV4.ZodString;
|
|
85
|
+
isString(v: zV3.ZodType): v is zV3.ZodString;
|
|
86
|
+
/**
|
|
87
|
+
* Type guard for number Zod types
|
|
88
|
+
*/
|
|
89
|
+
isNumber(v: zV4.ZodType): v is zV4.ZodNumber;
|
|
90
|
+
isNumber(v: zV3.ZodType): v is zV3.ZodNumber;
|
|
91
|
+
/**
|
|
92
|
+
* Type guard for date Zod types
|
|
93
|
+
*/
|
|
94
|
+
isDate(v: zV4.ZodType): v is zV4.ZodDate;
|
|
95
|
+
isDate(v: zV3.ZodType): v is zV3.ZodDate;
|
|
96
|
+
/**
|
|
97
|
+
* Type guard for default Zod types
|
|
98
|
+
*/
|
|
99
|
+
isDefault(v: zV4.ZodType): v is zV4.ZodDefault<any>;
|
|
100
|
+
isDefault(v: zV3.ZodType): v is zV3.ZodDefault<any>;
|
|
166
101
|
/**
|
|
167
102
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
168
103
|
*
|
|
@@ -184,16 +119,21 @@ export declare abstract class SchemaCompatLayer {
|
|
|
184
119
|
* @returns The processed Zod type
|
|
185
120
|
* @abstract
|
|
186
121
|
*/
|
|
187
|
-
abstract processZodType(value:
|
|
122
|
+
abstract processZodType(value: zV4.ZodType): zV4.ZodType;
|
|
123
|
+
abstract processZodType(value: zV3.ZodType): zV3.ZodType;
|
|
124
|
+
abstract processZodType(value: zV4.ZodType | zV3.ZodType): zV4.ZodType | zV3.ZodType;
|
|
188
125
|
/**
|
|
189
126
|
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
190
127
|
*
|
|
191
128
|
* @param value - The Zod object to process
|
|
192
129
|
* @returns The processed Zod object
|
|
193
130
|
*/
|
|
194
|
-
defaultZodObjectHandler(value: ZodObject<any, any
|
|
131
|
+
defaultZodObjectHandler(value: zV4.ZodObject<any, any>, options?: {
|
|
132
|
+
passthrough?: boolean;
|
|
133
|
+
}): zV4.ZodObject<any, any>;
|
|
134
|
+
defaultZodObjectHandler(value: zV3.ZodObject<any, any>, options?: {
|
|
195
135
|
passthrough?: boolean;
|
|
196
|
-
}): ZodObject<any, any
|
|
136
|
+
}): zV3.ZodObject<any, any>;
|
|
197
137
|
/**
|
|
198
138
|
* Merges validation constraints into a parameter description.
|
|
199
139
|
*
|
|
@@ -215,7 +155,7 @@ export declare abstract class SchemaCompatLayer {
|
|
|
215
155
|
* @returns The original value if not in the throw list
|
|
216
156
|
* @throws Error if the type is in the unsupported list
|
|
217
157
|
*/
|
|
218
|
-
defaultUnsupportedZodTypeHandler<T extends
|
|
158
|
+
defaultUnsupportedZodTypeHandler<T extends zV4.ZodObject | zV3.AnyZodObject>(value: T, throwOnTypes?: T extends zV4.ZodObject ? UnsupportedZodTypeV4[] : T extends zV3.AnyZodObject ? UnsupportedZodTypeV3[] : never): T extends zV4.ZodObject ? ShapeValueV4<T> : T extends zV3.AnyZodObject ? ShapeValueV3<T> : never;
|
|
219
159
|
/**
|
|
220
160
|
* Default handler for Zod array types. Processes array constraints according to provider support.
|
|
221
161
|
*
|
|
@@ -223,7 +163,8 @@ export declare abstract class SchemaCompatLayer {
|
|
|
223
163
|
* @param handleChecks - Array constraints to convert to descriptions vs keep as validation
|
|
224
164
|
* @returns The processed Zod array
|
|
225
165
|
*/
|
|
226
|
-
defaultZodArrayHandler(value: ZodArray<any
|
|
166
|
+
defaultZodArrayHandler(value: zV4.ZodArray<any>, handleChecks?: readonly ArrayCheckType[]): zV4.ZodArray<any>;
|
|
167
|
+
defaultZodArrayHandler(value: zV3.ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): zV3.ZodArray<any, any>;
|
|
227
168
|
/**
|
|
228
169
|
* Default handler for Zod union types. Processes all union options.
|
|
229
170
|
*
|
|
@@ -231,7 +172,8 @@ export declare abstract class SchemaCompatLayer {
|
|
|
231
172
|
* @returns The processed Zod union
|
|
232
173
|
* @throws Error if union has fewer than 2 options
|
|
233
174
|
*/
|
|
234
|
-
defaultZodUnionHandler(value: ZodUnion<[
|
|
175
|
+
defaultZodUnionHandler(value: zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>): zV4.ZodType;
|
|
176
|
+
defaultZodUnionHandler(value: zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>): zV3.ZodType;
|
|
235
177
|
/**
|
|
236
178
|
* Default handler for Zod string types. Processes string validation constraints.
|
|
237
179
|
*
|
|
@@ -239,7 +181,8 @@ export declare abstract class SchemaCompatLayer {
|
|
|
239
181
|
* @param handleChecks - String constraints to convert to descriptions vs keep as validation
|
|
240
182
|
* @returns The processed Zod string
|
|
241
183
|
*/
|
|
242
|
-
defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
|
|
184
|
+
defaultZodStringHandler(value: zV4.ZodString, handleChecks?: readonly StringCheckType[]): zV4.ZodString;
|
|
185
|
+
defaultZodStringHandler(value: zV3.ZodString, handleChecks?: readonly StringCheckType[]): zV3.ZodString;
|
|
243
186
|
/**
|
|
244
187
|
* Default handler for Zod number types. Processes number validation constraints.
|
|
245
188
|
*
|
|
@@ -247,14 +190,16 @@ export declare abstract class SchemaCompatLayer {
|
|
|
247
190
|
* @param handleChecks - Number constraints to convert to descriptions vs keep as validation
|
|
248
191
|
* @returns The processed Zod number
|
|
249
192
|
*/
|
|
250
|
-
defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
|
|
193
|
+
defaultZodNumberHandler(value: zV4.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV4.ZodNumber;
|
|
194
|
+
defaultZodNumberHandler(value: zV3.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV3.ZodNumber;
|
|
251
195
|
/**
|
|
252
196
|
* Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
|
|
253
197
|
*
|
|
254
198
|
* @param value - The Zod date to process
|
|
255
199
|
* @returns A Zod string schema representing the date in ISO format
|
|
256
200
|
*/
|
|
257
|
-
defaultZodDateHandler(value: ZodDate): ZodString;
|
|
201
|
+
defaultZodDateHandler(value: zV4.ZodDate): zV4.ZodString;
|
|
202
|
+
defaultZodDateHandler(value: zV3.ZodDate): zV3.ZodString;
|
|
258
203
|
/**
|
|
259
204
|
* Default handler for Zod optional types. Processes the inner type and maintains optionality.
|
|
260
205
|
*
|
|
@@ -262,21 +207,22 @@ export declare abstract class SchemaCompatLayer {
|
|
|
262
207
|
* @param handleTypes - Types that should be processed vs passed through
|
|
263
208
|
* @returns The processed Zod optional
|
|
264
209
|
*/
|
|
265
|
-
defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly
|
|
210
|
+
defaultZodOptionalHandler(value: zV4.ZodOptional<any>, handleTypes?: readonly AllZodTypeV4[]): zV4.ZodType;
|
|
211
|
+
defaultZodOptionalHandler(value: zV3.ZodOptional<any>, handleTypes?: readonly AllZodTypeV3[]): zV3.ZodType;
|
|
266
212
|
/**
|
|
267
213
|
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
268
214
|
*
|
|
269
215
|
* @param zodSchema - The Zod object schema to process
|
|
270
216
|
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
271
217
|
*/
|
|
272
|
-
processToAISDKSchema(zodSchema:
|
|
218
|
+
processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema;
|
|
273
219
|
/**
|
|
274
220
|
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
275
221
|
*
|
|
276
222
|
* @param zodSchema - The Zod object schema to process
|
|
277
223
|
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
278
224
|
*/
|
|
279
|
-
processToJSONSchema(zodSchema:
|
|
225
|
+
processToJSONSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): JSONSchema7;
|
|
280
226
|
}
|
|
281
227
|
export {};
|
|
282
228
|
//# sourceMappingURL=schema-compatibility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-compatibility.d.ts","sourceRoot":"","sources":["../src/schema-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"schema-compatibility.d.ts","sourceRoot":"","sources":["../src/schema-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AASlD,OAAO,KAAK,EACV,kBAAkB,IAAI,oBAAoB,EAC1C,UAAU,IAAI,YAAY,EAC1B,eAAe,EACf,eAAe,EACf,cAAc,EACd,UAAU,IAAI,YAAY,EAC3B,MAAM,2BAA2B,CAAC;AAMnC,OAAO,KAAK,EACV,kBAAkB,IAAI,oBAAoB,EAC1C,UAAU,IAAI,YAAY,EAC1B,UAAU,IAA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E,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,OAAO;IAC1G,yBAAyB,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,OAAO;IAYjH;;;;;OAKG;IACI,oBAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,OAAO,GAAG,MAAM;IAM3E;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,OAAO,GAAG,WAAW;CAGhF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB,EAAE,OAAO,CAAC;CACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-test-suite.d.ts","sourceRoot":"","sources":["../src/utils-test-suite.ts"],"names":[],"mappings":"AAgDA,wBAAgB,YAAY,SAka3B"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Schema } from 'ai';
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ZodSchema as ZodSchemaV3, ZodType as ZodTypeV3 } from 'zod/v3';
|
|
4
|
+
import type { ZodType as ZodSchemaV4, ZodType as ZodTypeV4 } from 'zod/v4';
|
|
4
5
|
import type { Targets } from 'zod-to-json-schema';
|
|
5
|
-
import type { SchemaCompatLayer } from './schema-compatibility
|
|
6
|
+
import type { SchemaCompatLayer } from './schema-compatibility';
|
|
7
|
+
type ZodSchema = ZodSchemaV3 | ZodSchemaV4;
|
|
8
|
+
type ZodType = ZodTypeV3 | ZodTypeV4;
|
|
6
9
|
/**
|
|
7
10
|
* Converts a Zod schema to an AI SDK Schema with validation support.
|
|
8
11
|
*
|
|
@@ -27,6 +30,14 @@ import type { SchemaCompatLayer } from './schema-compatibility.js';
|
|
|
27
30
|
* ```
|
|
28
31
|
*/
|
|
29
32
|
export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, target?: Targets): Schema<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is a Zod type by examining its properties and methods.
|
|
35
|
+
*
|
|
36
|
+
* @param value - The value to check
|
|
37
|
+
* @returns True if the value is a Zod type, false otherwise
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function isZodType(value: unknown): value is ZodType;
|
|
30
41
|
/**
|
|
31
42
|
* Converts an AI SDK Schema or Zod schema to a Zod schema.
|
|
32
43
|
*
|
|
@@ -52,7 +63,7 @@ export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, targ
|
|
|
52
63
|
* const zodSchema = convertSchemaToZod(aiSchema);
|
|
53
64
|
* ```
|
|
54
65
|
*/
|
|
55
|
-
export declare function convertSchemaToZod(schema: Schema |
|
|
66
|
+
export declare function convertSchemaToZod(schema: Schema | ZodSchema): ZodType;
|
|
56
67
|
/**
|
|
57
68
|
* Processes a schema using provider compatibility layers and converts it to an AI SDK Schema.
|
|
58
69
|
*
|
|
@@ -63,7 +74,7 @@ export declare function convertSchemaToZod(schema: Schema | z.ZodSchema): z.ZodT
|
|
|
63
74
|
* @returns Processed schema as an AI SDK Schema
|
|
64
75
|
*/
|
|
65
76
|
export declare function applyCompatLayer(options: {
|
|
66
|
-
schema: Schema |
|
|
77
|
+
schema: Schema | ZodSchema;
|
|
67
78
|
compatLayers: SchemaCompatLayer[];
|
|
68
79
|
mode: 'aiSdkSchema';
|
|
69
80
|
}): Schema;
|
|
@@ -77,8 +88,9 @@ export declare function applyCompatLayer(options: {
|
|
|
77
88
|
* @returns Processed schema as a JSONSchema7
|
|
78
89
|
*/
|
|
79
90
|
export declare function applyCompatLayer(options: {
|
|
80
|
-
schema: Schema |
|
|
91
|
+
schema: Schema | ZodSchema;
|
|
81
92
|
compatLayers: SchemaCompatLayer[];
|
|
82
93
|
mode: 'jsonSchema';
|
|
83
94
|
}): JSONSchema7;
|
|
95
|
+
export {};
|
|
84
96
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,IAAI,WAAW,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAI3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,KAAK,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAC3C,KAAK,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,OAAuB,eASlG;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAW1D;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAkBtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,IAAI,EAAE,aAAa,CAAC;CACrB,GAAG,MAAM,CAAC;AAEX;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,IAAI,EAAE,YAAY,CAAC;CACpB,GAAG,WAAW,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLNR4XKDU_cjs = require('./chunk-LNR4XKDU.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "zodToJsonSchema", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkLNR4XKDU_cjs.zodToJsonSchema; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=zod-to-json.cjs.map
|
|
12
|
+
//# sourceMappingURL=zod-to-json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"zod-to-json.cjs"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { ZodSchema as ZodSchemaV3 } from 'zod/v3';
|
|
3
|
+
import type { ZodType as ZodSchemaV4 } from 'zod/v4';
|
|
4
|
+
import type { Targets } from 'zod-to-json-schema';
|
|
5
|
+
export declare function zodToJsonSchema(zodSchema: ZodSchemaV3 | ZodSchemaV4, target?: Targets): JSONSchema7;
|
|
6
|
+
//# sourceMappingURL=zod-to-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-json.d.ts","sourceRoot":"","sources":["../src/zod-to-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,MAAM,GAAE,OAAuB,eAmBpG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"zod-to-json.js"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { z as zV3 } from 'zod/v3';
|
|
2
|
+
import type { z as zV4 } from 'zod/v4';
|
|
3
|
+
export declare function isOptional<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodOptional<any>;
|
|
4
|
+
export declare function isOptional<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodOptional<any>;
|
|
5
|
+
export declare function isObj<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodObject<any>;
|
|
6
|
+
export declare function isObj<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodObject;
|
|
7
|
+
export declare function isNull<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodNull;
|
|
8
|
+
export declare function isNull<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodNull;
|
|
9
|
+
export declare function isArr<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodArray<any>;
|
|
10
|
+
export declare function isArr<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodArray;
|
|
11
|
+
export declare function isUnion<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodUnion<any>;
|
|
12
|
+
export declare function isUnion<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodUnion;
|
|
13
|
+
export declare function isString<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodString;
|
|
14
|
+
export declare function isString<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodString;
|
|
15
|
+
export declare function isNumber<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodNumber;
|
|
16
|
+
export declare function isNumber<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodNumber;
|
|
17
|
+
export declare function isDate<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodDate;
|
|
18
|
+
export declare function isDate<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodDate;
|
|
19
|
+
export declare function isDefault<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodDefault<any>;
|
|
20
|
+
export declare function isDefault<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodDefault;
|
|
21
|
+
//# sourceMappingURL=zodTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodTypes.d.ts","sourceRoot":"","sources":["../src/zodTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAC9F,wBAAgB,UAAU,CAAC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C,SAAS,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/schema-compat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Tool schema compatibility layer for Mastra.ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,6 +16,16 @@
|
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"./zod-to-json": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/zod-to-json.d.ts",
|
|
22
|
+
"default": "./dist/zod-to-json.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/zod-to-json.d.ts",
|
|
26
|
+
"default": "./dist/zod-to-json.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
19
29
|
"./package.json": "./package.json"
|
|
20
30
|
},
|
|
21
31
|
"keywords": [
|
|
@@ -29,12 +39,13 @@
|
|
|
29
39
|
"license": "Apache-2.0",
|
|
30
40
|
"dependencies": {
|
|
31
41
|
"json-schema": "^0.4.0",
|
|
32
|
-
"zod-from-json-schema": "^0.0
|
|
42
|
+
"zod-from-json-schema": "^0.5.0",
|
|
43
|
+
"zod-from-json-schema-v3": "npm:zod-from-json-schema@^0.0.5",
|
|
33
44
|
"zod-to-json-schema": "^3.24.5"
|
|
34
45
|
},
|
|
35
46
|
"peerDependencies": {
|
|
36
|
-
"ai": "^4.0.0",
|
|
37
|
-
"zod": "^3.0.0"
|
|
47
|
+
"ai": "^4.0.0 || ^5.0.0",
|
|
48
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
38
49
|
},
|
|
39
50
|
"devDependencies": {
|
|
40
51
|
"@types/json-schema": "^7.0.15",
|
|
@@ -45,8 +56,7 @@
|
|
|
45
56
|
"typescript": "^5.8.3",
|
|
46
57
|
"vitest": "^3.2.4",
|
|
47
58
|
"zod": "^3.25.67",
|
|
48
|
-
"@internal/lint": "0.0.
|
|
49
|
-
"@internal/types-builder": "0.0.4"
|
|
59
|
+
"@internal/lint": "0.0.34"
|
|
50
60
|
},
|
|
51
61
|
"scripts": {
|
|
52
62
|
"build": "tsup --silent --config tsup.config.ts",
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Schema compatibility base class and related types
|
|
2
2
|
export {
|
|
3
|
-
SchemaCompatLayer,
|
|
4
|
-
// Constants
|
|
3
|
+
SchemaCompatLayer as SchemaCompatLayerV3,
|
|
5
4
|
ALL_STRING_CHECKS,
|
|
6
5
|
ALL_NUMBER_CHECKS,
|
|
7
6
|
ALL_ARRAY_CHECKS,
|
|
@@ -25,7 +24,9 @@ export {
|
|
|
25
24
|
isUnion,
|
|
26
25
|
isString,
|
|
27
26
|
isNumber,
|
|
28
|
-
} from './schema-compatibility';
|
|
27
|
+
} from './schema-compatibility-v3';
|
|
28
|
+
export { SchemaCompatLayer as SchemaCompatLayerV4 } from './schema-compatibility-v4';
|
|
29
|
+
export { SchemaCompatLayer } from './schema-compatibility';
|
|
29
30
|
|
|
30
31
|
// Utility functions
|
|
31
32
|
export { convertZodSchemaToAISDKSchema, applyCompatLayer, convertSchemaToZod } from './utils';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ZodType as ZodTypeV3, ZodObject as ZodObjectV3 } from 'zod/v3';
|
|
3
|
+
import type { ZodType as ZodTypeV4, ZodObject as ZodObjectV4 } from 'zod/v4';
|
|
2
4
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
|
-
import { SchemaCompatLayer
|
|
4
|
-
import type { AllZodType
|
|
5
|
+
import { SchemaCompatLayer } from '../schema-compatibility';
|
|
6
|
+
import type { AllZodType as AllZodTypeV3 } from '../schema-compatibility-v3';
|
|
7
|
+
import type { AllZodType as AllZodTypeV4 } from '../schema-compatibility-v4';
|
|
8
|
+
import type { ModelInformation } from '../types';
|
|
9
|
+
import { isOptional, isObj, isArr, isUnion, isString } from '../zodTypes';
|
|
5
10
|
|
|
6
11
|
export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
12
|
constructor(model: ModelInformation) {
|
|
@@ -16,18 +21,27 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
16
21
|
return this.getModel().modelId.includes('claude');
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
processZodType(value:
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
processZodType(value: ZodTypeV3): ZodTypeV3;
|
|
25
|
+
processZodType(value: ZodTypeV4): ZodTypeV4;
|
|
26
|
+
processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
|
|
27
|
+
if (isOptional(z)(value)) {
|
|
28
|
+
const handleTypes: AllZodTypeV3[] | AllZodTypeV4 = [
|
|
29
|
+
'ZodObject',
|
|
30
|
+
'ZodArray',
|
|
31
|
+
'ZodUnion',
|
|
32
|
+
'ZodNever',
|
|
33
|
+
'ZodUndefined',
|
|
34
|
+
'ZodTuple',
|
|
35
|
+
];
|
|
22
36
|
if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
|
|
23
37
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
24
|
-
} else if (isObj(value)) {
|
|
38
|
+
} else if (isObj(z)(value)) {
|
|
25
39
|
return this.defaultZodObjectHandler(value);
|
|
26
|
-
} else if (isArr(value)) {
|
|
40
|
+
} else if (isArr(z)(value)) {
|
|
27
41
|
return this.defaultZodArrayHandler(value, []);
|
|
28
|
-
} else if (isUnion(value)) {
|
|
42
|
+
} else if (isUnion(z)(value)) {
|
|
29
43
|
return this.defaultZodUnionHandler(value);
|
|
30
|
-
} else if (isString(value)) {
|
|
44
|
+
} else if (isString(z)(value)) {
|
|
31
45
|
// the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
|
|
32
46
|
// added to the tool description
|
|
33
47
|
|
|
@@ -38,6 +52,10 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
38
52
|
}
|
|
39
53
|
}
|
|
40
54
|
|
|
41
|
-
return this.defaultUnsupportedZodTypeHandler(value
|
|
55
|
+
return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>, [
|
|
56
|
+
'ZodNever',
|
|
57
|
+
'ZodTuple',
|
|
58
|
+
'ZodUndefined',
|
|
59
|
+
]);
|
|
42
60
|
}
|
|
43
61
|
}
|