@mastra/schema-compat 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806184630 → 0.0.0-vnext-20251104230439

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +131 -1
  2. package/README.md +0 -4
  3. package/dist/chunk-5WM4A32G.cjs +83 -0
  4. package/dist/chunk-5WM4A32G.cjs.map +1 -0
  5. package/dist/chunk-U2HXWNAF.js +77 -0
  6. package/dist/chunk-U2HXWNAF.js.map +1 -0
  7. package/dist/index.cjs +4560 -271
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +5 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +4558 -272
  12. package/dist/index.js.map +1 -1
  13. package/dist/json-schema.d.ts +4 -0
  14. package/dist/json-schema.d.ts.map +1 -0
  15. package/dist/provider-compats/anthropic.d.ts +6 -4
  16. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  17. package/dist/provider-compats/deepseek.d.ts +6 -4
  18. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  19. package/dist/provider-compats/google.d.ts +6 -4
  20. package/dist/provider-compats/google.d.ts.map +1 -1
  21. package/dist/provider-compats/meta.d.ts +6 -4
  22. package/dist/provider-compats/meta.d.ts.map +1 -1
  23. package/dist/provider-compats/openai-reasoning.d.ts +6 -4
  24. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  25. package/dist/provider-compats/openai.d.ts +6 -4
  26. package/dist/provider-compats/openai.d.ts.map +1 -1
  27. package/dist/schema-compatibility-v3.d.ts +287 -0
  28. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  29. package/dist/schema-compatibility-v4.d.ts +278 -0
  30. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  31. package/dist/schema-compatibility.d.ts +81 -165
  32. package/dist/schema-compatibility.d.ts.map +1 -1
  33. package/dist/types.d.ts +7 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils-test-suite.d.ts +2 -0
  36. package/dist/utils-test-suite.d.ts.map +1 -0
  37. package/dist/utils.d.ts +18 -6
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/zod-to-json-test-suite.d.ts +6 -0
  40. package/dist/zod-to-json-test-suite.d.ts.map +1 -0
  41. package/dist/zod-to-json.cjs +12 -0
  42. package/dist/zod-to-json.cjs.map +1 -0
  43. package/dist/zod-to-json.d.ts +6 -0
  44. package/dist/zod-to-json.d.ts.map +1 -0
  45. package/dist/zod-to-json.js +3 -0
  46. package/dist/zod-to-json.js.map +1 -0
  47. package/dist/zodTypes.d.ts +21 -0
  48. package/dist/zodTypes.d.ts.map +1 -0
  49. package/package.json +33 -10
  50. package/.turbo/turbo-build.log +0 -4
  51. package/eslint.config.js +0 -6
  52. package/src/index.ts +0 -39
  53. package/src/provider-compats/anthropic.ts +0 -44
  54. package/src/provider-compats/deepseek.ts +0 -35
  55. package/src/provider-compats/google.ts +0 -63
  56. package/src/provider-compats/meta.ts +0 -36
  57. package/src/provider-compats/openai-reasoning.ts +0 -91
  58. package/src/provider-compats/openai.ts +0 -56
  59. package/src/provider-compats.test.ts +0 -312
  60. package/src/schema-compatibility.test.ts +0 -471
  61. package/src/schema-compatibility.ts +0 -588
  62. package/src/utils.test.ts +0 -434
  63. package/src/utils.ts +0 -205
  64. package/tsconfig.build.json +0 -9
  65. package/tsconfig.json +0 -5
  66. package/tsup.config.ts +0 -17
  67. package/vitest.config.ts +0 -7
@@ -0,0 +1,278 @@
1
+ import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault, ZodNull } from 'zod/v4';
2
+ import type { ZodAny, ZodType } from 'zod/v4';
3
+ import type { Targets } from 'zod-to-json-schema';
4
+ import type { JSONSchema7 } from './json-schema.js';
5
+ import type { SchemaCompatLayer as ParentSchemaCompatLayer } from './schema-compatibility.js';
6
+ import type { Schema, ModelInformation } from './types.js';
7
+ /**
8
+ * All supported string validation check types that can be processed or converted to descriptions.
9
+ * @constant
10
+ */
11
+ export declare const ALL_STRING_CHECKS: readonly ["regex", "emoji", "email", "url", "uuid", "cuid", "min_length", "max_length", "string_format"];
12
+ /**
13
+ * All supported number validation check types that can be processed or converted to descriptions.
14
+ * @constant
15
+ */
16
+ export declare const ALL_NUMBER_CHECKS: readonly ["greater_than", "less_than", "multiple_of"];
17
+ /**
18
+ * All supported array validation check types that can be processed or converted to descriptions.
19
+ * @constant
20
+ */
21
+ export declare const ALL_ARRAY_CHECKS: readonly ["min", "max", "length"];
22
+ /**
23
+ * Zod types that are not supported by most AI model providers and should be avoided.
24
+ * @constant
25
+ */
26
+ export declare const UNSUPPORTED_ZOD_TYPES: readonly ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
27
+ /**
28
+ * Zod types that are generally supported by AI model providers.
29
+ * @constant
30
+ */
31
+ export declare const SUPPORTED_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault"];
32
+ /**
33
+ * All Zod types (both supported and unsupported).
34
+ * @constant
35
+ */
36
+ export declare const ALL_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault", "ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
37
+ /**
38
+ * Type representing string validation checks.
39
+ */
40
+ export type StringCheckType = (typeof ALL_STRING_CHECKS)[number];
41
+ /**
42
+ * Type representing number validation checks.
43
+ */
44
+ export type NumberCheckType = (typeof ALL_NUMBER_CHECKS)[number];
45
+ /**
46
+ * Type representing array validation checks.
47
+ */
48
+ export type ArrayCheckType = (typeof ALL_ARRAY_CHECKS)[number];
49
+ /**
50
+ * Type representing unsupported Zod schema types.
51
+ */
52
+ export type UnsupportedZodType = (typeof UNSUPPORTED_ZOD_TYPES)[number];
53
+ /**
54
+ * Type representing supported Zod schema types.
55
+ */
56
+ export type SupportedZodType = (typeof SUPPORTED_ZOD_TYPES)[number];
57
+ /**
58
+ * Type representing all Zod schema types (supported and unsupported).
59
+ */
60
+ export type AllZodType = (typeof ALL_ZOD_TYPES)[number];
61
+ /**
62
+ * Utility type to extract the shape of a Zod object schema.
63
+ */
64
+ export type ZodShape<T extends z.ZodObject<any, any>> = T['shape'];
65
+ /**
66
+ * Utility type to extract the keys from a Zod object shape.
67
+ */
68
+ export type ShapeKey<T extends z.ZodObject<any, any>> = keyof ZodShape<T>;
69
+ /**
70
+ * Utility type to extract the value types from a Zod object shape.
71
+ */
72
+ export type ShapeValue<T extends z.ZodObject<any, any>> = ZodShape<T>[ShapeKey<T>];
73
+ type ConstraintHelperText = string[];
74
+ /**
75
+ * Abstract base class for creating schema compatibility layers for different AI model providers.
76
+ *
77
+ * This class provides a framework for transforming Zod schemas to work with specific AI model
78
+ * provider requirements and limitations. Each provider may have different support levels for
79
+ * JSON Schema features, validation constraints, and data types.
80
+ *
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { SchemaCompatLayer } from '@mastra/schema-compat';
85
+ * import type { LanguageModelV1 } from 'ai';
86
+ *
87
+ * class CustomProviderCompat extends SchemaCompatLayer {
88
+ * constructor(model: LanguageModelV1) {
89
+ * super(model);
90
+ * }
91
+ *
92
+ * shouldApply(): boolean {
93
+ * return this.getModel().provider === 'custom-provider';
94
+ * }
95
+ *
96
+ * getSchemaTarget() {
97
+ * return 'jsonSchema7';
98
+ * }
99
+ *
100
+ * processZodType<T extends z.AnyZodObject>(value: z.ZodAny): ShapeValue<T> {
101
+ * // Custom processing logic for this provider
102
+ * switch (value._def.typeName) {
103
+ * case 'ZodString':
104
+ * return this.defaultZodStringHandler(value, ['email', 'url']);
105
+ * default:
106
+ * return this.defaultUnsupportedZodTypeHandler(value);
107
+ * }
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ export declare class SchemaCompatLayer {
113
+ private model;
114
+ private parent;
115
+ /**
116
+ * Creates a new schema compatibility instance.
117
+ *
118
+ * @param model - The language model this compatibility layer applies to
119
+ */
120
+ constructor(model: ModelInformation, parent: ParentSchemaCompatLayer);
121
+ /**
122
+ * Gets the language model associated with this compatibility layer.
123
+ *
124
+ * @returns The language model instance
125
+ */
126
+ getModel(): ModelInformation;
127
+ getUnsupportedZodTypes(): readonly string[];
128
+ /**
129
+ * Type guard for optional Zod types
130
+ */
131
+ isOptional(v: ZodAny | ZodOptional<any>): v is ZodOptional<any>;
132
+ /**
133
+ * Type guard for object Zod types
134
+ */
135
+ isObj(v: ZodAny | ZodObject<any, any>): v is ZodObject<any, any>;
136
+ /**
137
+ * Type guard for null Zod types
138
+ */
139
+ isNull(v: ZodAny | ZodNull): v is ZodNull;
140
+ /**
141
+ * Type guard for array Zod types
142
+ */
143
+ isArr(v: ZodAny | ZodArray<any>): v is ZodArray<any>;
144
+ /**
145
+ * Type guard for union Zod types
146
+ */
147
+ isUnion(v: ZodAny | ZodUnion<[ZodAny, ...ZodAny[]]>): v is ZodUnion<[ZodAny, ...ZodAny[]]>;
148
+ /**
149
+ * Type guard for string Zod types
150
+ */
151
+ isString(v: ZodAny | ZodString): v is ZodString;
152
+ /**
153
+ * Type guard for number Zod types
154
+ */
155
+ isNumber(v: ZodAny | ZodNumber): v is ZodNumber;
156
+ /**
157
+ * Type guard for date Zod types
158
+ */
159
+ isDate(v: ZodAny | ZodDate): v is ZodDate;
160
+ /**
161
+ * Type guard for default Zod types
162
+ */
163
+ isDefault(v: ZodAny | ZodDefault<any>): v is ZodDefault<any>;
164
+ /**
165
+ * Determines whether this compatibility layer should be applied for the current model.
166
+ *
167
+ * @returns True if this compatibility layer should be used, false otherwise
168
+ * @abstract
169
+ */
170
+ shouldApply(): boolean;
171
+ /**
172
+ * Returns the JSON Schema target format for this provider.
173
+ *
174
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
175
+ * @abstract
176
+ */
177
+ getSchemaTarget(): Targets | undefined;
178
+ /**
179
+ * Processes a specific Zod type according to the provider's requirements.
180
+ *
181
+ * @param value - The Zod type to process
182
+ * @returns The processed Zod type
183
+ * @abstract
184
+ */
185
+ processZodType(value: ZodType): ZodType;
186
+ /**
187
+ * Default handler for Zod object types. Recursively processes all properties in the object.
188
+ *
189
+ * @param value - The Zod object to process
190
+ * @returns The processed Zod object
191
+ */
192
+ defaultZodObjectHandler(value: ZodObject<any, any>, options?: {
193
+ passthrough?: boolean;
194
+ }): ZodObject<any, any>;
195
+ /**
196
+ * Merges validation constraints into a parameter description.
197
+ *
198
+ * This helper method converts validation constraints that may not be supported
199
+ * by a provider into human-readable descriptions.
200
+ *
201
+ * @param description - The existing parameter description
202
+ * @param constraints - The validation constraints to merge
203
+ * @returns The updated description with constraints, or undefined if no constraints
204
+ */
205
+ mergeParameterDescription(description: string | undefined, constraints: ConstraintHelperText): string | undefined;
206
+ /**
207
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
208
+ *
209
+ * @param value - The Zod type to check
210
+ * @param throwOnTypes - Array of type names to throw errors for
211
+ * @returns The original value if not in the throw list
212
+ * @throws Error if the type is in the unsupported list
213
+ */
214
+ defaultUnsupportedZodTypeHandler<T extends z.ZodObject<any, any>>(value: z.ZodAny, throwOnTypes?: readonly UnsupportedZodType[]): ShapeValue<T>;
215
+ /**
216
+ * Default handler for Zod array types. Processes array constraints according to provider support.
217
+ *
218
+ * @param value - The Zod array to process
219
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
220
+ * @returns The processed Zod array
221
+ */
222
+ defaultZodArrayHandler(value: ZodArray<any>, handleChecks?: readonly ArrayCheckType[]): ZodArray<any>;
223
+ /**
224
+ * Default handler for Zod union types. Processes all union options.
225
+ *
226
+ * @param value - The Zod union to process
227
+ * @returns The processed Zod union
228
+ * @throws Error if union has fewer than 2 options
229
+ */
230
+ defaultZodUnionHandler(value: ZodUnion<[ZodAny, ...ZodAny[]]>): ZodAny;
231
+ /**
232
+ * Default handler for Zod string types. Processes string validation constraints.
233
+ *
234
+ * @param value - The Zod string to process
235
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
236
+ * @returns The processed Zod string
237
+ */
238
+ defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
239
+ /**
240
+ * Default handler for Zod number types. Processes number validation constraints.
241
+ *
242
+ * @param value - The Zod number to process
243
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
244
+ * @returns The processed Zod number
245
+ */
246
+ defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
247
+ /**
248
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
249
+ *
250
+ * @param value - The Zod date to process
251
+ * @returns A Zod string schema representing the date in ISO format
252
+ */
253
+ defaultZodDateHandler(value: ZodDate): ZodString;
254
+ /**
255
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
256
+ *
257
+ * @param value - The Zod optional to process
258
+ * @param handleTypes - Types that should be processed vs passed through
259
+ * @returns The processed Zod optional
260
+ */
261
+ defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly AllZodType[]): ZodType;
262
+ /**
263
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
264
+ *
265
+ * @param zodSchema - The Zod object schema to process
266
+ * @returns An AI SDK Schema with provider-specific compatibility applied
267
+ */
268
+ processToAISDKSchema(zodSchema: ZodType): Schema;
269
+ /**
270
+ * Processes a Zod object schema and converts it to a JSON Schema.
271
+ *
272
+ * @param zodSchema - The Zod object schema to process
273
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
274
+ */
275
+ processToJSONSchema(zodSchema: ZodType): JSONSchema7;
276
+ }
277
+ export {};
278
+ //# sourceMappingURL=schema-compatibility-v4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-compatibility-v4.d.ts","sourceRoot":"","sources":["../src/schema-compatibility-v4.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,CAAC,EACD,WAAW,EACX,SAAS,EACT,QAAQ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SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EACrE,KAAK,EAAE,CAAC,CAAC,MAAM,EACf,YAAY,GAAE,SAAS,kBAAkB,EAA0B,GAClE,UAAU,CAAC,CAAC,CAAC;IAOhB;;;;;;OAMG;IACI,sBAAsB,CAC3B,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,EACpB,YAAY,GAAE,SAAS,cAAc,EAAqB,GACzD,QAAQ,CAAC,GAAG,CAAC;IAiDhB;;;;;;OAMG;IACI,sBAAsB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,GAAG,MAAM;IAW7E;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IA2DZ;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IAkEZ;;;;;OAKG;IACI,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS;IAoCvD;;;;;;OAMG;IACI,yBAAyB,CAC9B,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EACvB,WAAW,GAAE,SAAS,UAAU,EAAwB,GACvD,OAAO;IAQV;;;;;OAKG;IACI,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM;IAMvD;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,WAAW;CAG5D"}
@@ -1,166 +1,73 @@
1
- import type { Schema, LanguageModelV1 } from 'ai';
2
- import type { JSONSchema7 } from 'json-schema';
3
- import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault, ZodNull } from 'zod';
4
- import type { ZodTypeAny } from 'zod';
1
+ import type { z as zV3 } from 'zod/v3';
2
+ import type { z as zV4, ZodType } from 'zod/v4';
5
3
  import type { Targets } from 'zod-to-json-schema';
6
- /**
7
- * All supported string validation check types that can be processed or converted to descriptions.
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>];
81
- type StringConstraints = {
82
- minLength?: number;
83
- maxLength?: number;
84
- email?: boolean;
85
- url?: boolean;
86
- uuid?: boolean;
87
- cuid?: boolean;
88
- emoji?: boolean;
89
- regex?: {
90
- pattern: string;
91
- flags?: string;
92
- };
93
- };
94
- type NumberConstraints = {
95
- gt?: number;
96
- gte?: number;
97
- lt?: number;
98
- lte?: number;
99
- multipleOf?: number;
100
- };
101
- type ArrayConstraints = {
102
- minLength?: number;
103
- maxLength?: number;
104
- exactLength?: number;
105
- };
106
- type DateConstraints = {
107
- minDate?: string;
108
- maxDate?: string;
109
- dateFormat?: string;
110
- };
111
- /**
112
- * Abstract base class for creating schema compatibility layers for different AI model providers.
113
- *
114
- * This class provides a framework for transforming Zod schemas to work with specific AI model
115
- * provider requirements and limitations. Each provider may have different support levels for
116
- * JSON Schema features, validation constraints, and data types.
117
- *
118
- * @abstract
119
- *
120
- * @example
121
- * ```typescript
122
- * import { SchemaCompatLayer } from '@mastra/schema-compat';
123
- * import type { LanguageModelV1 } from 'ai';
124
- *
125
- * class CustomProviderCompat extends SchemaCompatLayer {
126
- * constructor(model: LanguageModelV1) {
127
- * super(model);
128
- * }
129
- *
130
- * shouldApply(): boolean {
131
- * return this.getModel().provider === 'custom-provider';
132
- * }
133
- *
134
- * getSchemaTarget() {
135
- * return 'jsonSchema7';
136
- * }
137
- *
138
- * processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
139
- * // Custom processing logic for this provider
140
- * switch (value._def.typeName) {
141
- * case 'ZodString':
142
- * return this.defaultZodStringHandler(value, ['email', 'url']);
143
- * default:
144
- * return this.defaultUnsupportedZodTypeHandler(value);
145
- * }
146
- * }
147
- * }
148
- * ```
149
- */
4
+ import type { JSONSchema7 } from './json-schema.js';
5
+ import type { UnsupportedZodType as UnsupportedZodTypeV3, ShapeValue as ShapeValueV3, StringCheckType, NumberCheckType, ArrayCheckType, AllZodType as AllZodTypeV3 } from './schema-compatibility-v3.js';
6
+ import type { UnsupportedZodType as UnsupportedZodTypeV4, ShapeValue as ShapeValueV4, AllZodType as AllZodTypeV4 } from './schema-compatibility-v4.js';
7
+ import type { Schema, ModelInformation } from './types.js';
8
+ type ConstraintHelperText = string[];
150
9
  export declare abstract class SchemaCompatLayer {
151
10
  private model;
11
+ private v3Layer;
12
+ private v4Layer;
152
13
  /**
153
14
  * Creates a new schema compatibility instance.
154
15
  *
155
16
  * @param model - The language model this compatibility layer applies to
156
17
  */
157
- constructor(model: LanguageModelV1);
18
+ constructor(model: ModelInformation);
158
19
  /**
159
20
  * Gets the language model associated with this compatibility layer.
160
21
  *
161
22
  * @returns The language model instance
162
23
  */
163
- getModel(): LanguageModelV1;
24
+ getModel(): ModelInformation;
25
+ getUnsupportedZodTypes(v: ZodType): readonly string[];
26
+ /**
27
+ * Type guard for optional Zod types
28
+ */
29
+ isOptional(v: zV4.ZodType): v is zV4.ZodOptional<any>;
30
+ isOptional(v: zV3.ZodType): v is zV3.ZodOptional<any>;
31
+ /**
32
+ * Type guard for object Zod types
33
+ */
34
+ isObj(v: zV4.ZodType): v is zV4.ZodObject<any, any>;
35
+ isObj(v: zV3.ZodType): v is zV3.ZodObject<any, any, any, any, any>;
36
+ /**
37
+ * Type guard for null Zod types
38
+ */
39
+ isNull(v: zV4.ZodType): v is zV4.ZodNull;
40
+ isNull(v: zV3.ZodType): v is zV3.ZodNull;
41
+ /**
42
+ * Type guard for array Zod types
43
+ */
44
+ isArr(v: zV4.ZodType): v is zV4.ZodArray<any>;
45
+ isArr(v: zV3.ZodType): v is zV3.ZodArray<any, any>;
46
+ /**
47
+ * Type guard for union Zod types
48
+ */
49
+ isUnion(v: zV4.ZodType): v is zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>;
50
+ isUnion(v: zV3.ZodType): v is zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>;
51
+ /**
52
+ * Type guard for string Zod types
53
+ */
54
+ isString(v: zV4.ZodType): v is zV4.ZodString;
55
+ isString(v: zV3.ZodType): v is zV3.ZodString;
56
+ /**
57
+ * Type guard for number Zod types
58
+ */
59
+ isNumber(v: zV4.ZodType): v is zV4.ZodNumber;
60
+ isNumber(v: zV3.ZodType): v is zV3.ZodNumber;
61
+ /**
62
+ * Type guard for date Zod types
63
+ */
64
+ isDate(v: zV4.ZodType): v is zV4.ZodDate;
65
+ isDate(v: zV3.ZodType): v is zV3.ZodDate;
66
+ /**
67
+ * Type guard for default Zod types
68
+ */
69
+ isDefault(v: zV4.ZodType): v is zV4.ZodDefault<any>;
70
+ isDefault(v: zV3.ZodType): v is zV3.ZodDefault<any>;
164
71
  /**
165
72
  * Determines whether this compatibility layer should be applied for the current model.
166
73
  *
@@ -182,16 +89,21 @@ export declare abstract class SchemaCompatLayer {
182
89
  * @returns The processed Zod type
183
90
  * @abstract
184
91
  */
185
- abstract processZodType(value: ZodTypeAny): ZodTypeAny;
92
+ abstract processZodType(value: zV4.ZodType): zV4.ZodType;
93
+ abstract processZodType(value: zV3.ZodType): zV3.ZodType;
94
+ abstract processZodType(value: zV4.ZodType | zV3.ZodType): zV4.ZodType | zV3.ZodType;
186
95
  /**
187
96
  * Default handler for Zod object types. Recursively processes all properties in the object.
188
97
  *
189
98
  * @param value - The Zod object to process
190
99
  * @returns The processed Zod object
191
100
  */
192
- defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
101
+ defaultZodObjectHandler(value: zV4.ZodObject<any, any>, options?: {
102
+ passthrough?: boolean;
103
+ }): zV4.ZodObject<any, any>;
104
+ defaultZodObjectHandler(value: zV3.ZodObject<any, any>, options?: {
193
105
  passthrough?: boolean;
194
- }): ZodObject<any, any, any>;
106
+ }): zV3.ZodObject<any, any>;
195
107
  /**
196
108
  * Merges validation constraints into a parameter description.
197
109
  *
@@ -202,9 +114,7 @@ export declare abstract class SchemaCompatLayer {
202
114
  * @param constraints - The validation constraints to merge
203
115
  * @returns The updated description with constraints, or undefined if no constraints
204
116
  */
205
- mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
206
- defaultValue?: unknown;
207
- }): string | undefined;
117
+ mergeParameterDescription(description: string | undefined, constraints: ConstraintHelperText): string | undefined;
208
118
  /**
209
119
  * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
210
120
  *
@@ -213,7 +123,7 @@ export declare abstract class SchemaCompatLayer {
213
123
  * @returns The original value if not in the throw list
214
124
  * @throws Error if the type is in the unsupported list
215
125
  */
216
- defaultUnsupportedZodTypeHandler<T extends z.AnyZodObject>(value: z.ZodTypeAny, throwOnTypes?: readonly UnsupportedZodType[]): ShapeValue<T>;
126
+ 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;
217
127
  /**
218
128
  * Default handler for Zod array types. Processes array constraints according to provider support.
219
129
  *
@@ -221,7 +131,8 @@ export declare abstract class SchemaCompatLayer {
221
131
  * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
222
132
  * @returns The processed Zod array
223
133
  */
224
- defaultZodArrayHandler(value: ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): ZodArray<any, any>;
134
+ defaultZodArrayHandler(value: zV4.ZodArray<any>, handleChecks?: readonly ArrayCheckType[]): zV4.ZodArray<any>;
135
+ defaultZodArrayHandler(value: zV3.ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): zV3.ZodArray<any, any>;
225
136
  /**
226
137
  * Default handler for Zod union types. Processes all union options.
227
138
  *
@@ -229,7 +140,8 @@ export declare abstract class SchemaCompatLayer {
229
140
  * @returns The processed Zod union
230
141
  * @throws Error if union has fewer than 2 options
231
142
  */
232
- defaultZodUnionHandler(value: ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>): ZodTypeAny;
143
+ defaultZodUnionHandler(value: zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>): zV4.ZodType;
144
+ defaultZodUnionHandler(value: zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>): zV3.ZodType;
233
145
  /**
234
146
  * Default handler for Zod string types. Processes string validation constraints.
235
147
  *
@@ -237,7 +149,8 @@ export declare abstract class SchemaCompatLayer {
237
149
  * @param handleChecks - String constraints to convert to descriptions vs keep as validation
238
150
  * @returns The processed Zod string
239
151
  */
240
- defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
152
+ defaultZodStringHandler(value: zV4.ZodString, handleChecks?: readonly StringCheckType[]): zV4.ZodString;
153
+ defaultZodStringHandler(value: zV3.ZodString, handleChecks?: readonly StringCheckType[]): zV3.ZodString;
241
154
  /**
242
155
  * Default handler for Zod number types. Processes number validation constraints.
243
156
  *
@@ -245,14 +158,16 @@ export declare abstract class SchemaCompatLayer {
245
158
  * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
246
159
  * @returns The processed Zod number
247
160
  */
248
- defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
161
+ defaultZodNumberHandler(value: zV4.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV4.ZodNumber;
162
+ defaultZodNumberHandler(value: zV3.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV3.ZodNumber;
249
163
  /**
250
164
  * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
251
165
  *
252
166
  * @param value - The Zod date to process
253
167
  * @returns A Zod string schema representing the date in ISO format
254
168
  */
255
- defaultZodDateHandler(value: ZodDate): ZodString;
169
+ defaultZodDateHandler(value: zV4.ZodDate): zV4.ZodString;
170
+ defaultZodDateHandler(value: zV3.ZodDate): zV3.ZodString;
256
171
  /**
257
172
  * Default handler for Zod optional types. Processes the inner type and maintains optionality.
258
173
  *
@@ -260,21 +175,22 @@ export declare abstract class SchemaCompatLayer {
260
175
  * @param handleTypes - Types that should be processed vs passed through
261
176
  * @returns The processed Zod optional
262
177
  */
263
- defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly AllZodType[]): ZodTypeAny;
178
+ defaultZodOptionalHandler(value: zV4.ZodOptional<any>, handleTypes?: readonly AllZodTypeV4[]): zV4.ZodType;
179
+ defaultZodOptionalHandler(value: zV3.ZodOptional<any>, handleTypes?: readonly AllZodTypeV3[]): zV3.ZodType;
264
180
  /**
265
181
  * Processes a Zod object schema and converts it to an AI SDK Schema.
266
182
  *
267
183
  * @param zodSchema - The Zod object schema to process
268
184
  * @returns An AI SDK Schema with provider-specific compatibility applied
269
185
  */
270
- processToAISDKSchema(zodSchema: z.ZodSchema): Schema;
186
+ processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema;
271
187
  /**
272
188
  * Processes a Zod object schema and converts it to a JSON Schema.
273
189
  *
274
190
  * @param zodSchema - The Zod object schema to process
275
191
  * @returns A JSONSchema7 object with provider-specific compatibility applied
276
192
  */
277
- processToJSONSchema(zodSchema: z.ZodSchema): JSONSchema7;
193
+ processToJSONSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): JSONSchema7;
278
194
  }
279
195
  export {};
280
196
  //# sourceMappingURL=schema-compatibility.d.ts.map