@mastra/schema-compat 0.0.0-ai-v5-20250801192614 → 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938

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 +146 -2
  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 +4563 -280
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +12 -8
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +4561 -281
  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 +7 -5
  16. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  17. package/dist/provider-compats/deepseek.d.ts +7 -5
  18. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  19. package/dist/provider-compats/google.d.ts +7 -5
  20. package/dist/provider-compats/google.d.ts.map +1 -1
  21. package/dist/provider-compats/meta.d.ts +7 -5
  22. package/dist/provider-compats/meta.d.ts.map +1 -1
  23. package/dist/provider-compats/openai-reasoning.d.ts +7 -5
  24. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  25. package/dist/provider-compats/openai.d.ts +7 -5
  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 -166
  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 +19 -7
  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 +37 -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 -43
  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 -88
  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 -479
  61. package/src/schema-compatibility.ts +0 -590
  62. package/src/utils.test.ts +0 -442
  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 -22
  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,167 +1,73 @@
1
- import type { Schema, LanguageModel } 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
- export type SchemaCompatModel = Exclude<LanguageModel, string>;
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", "max"];
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 ["min", "max", "multipleOf"];
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
- export declare const isOptional: (v: ZodTypeAny) => v is ZodOptional<any>;
23
- export declare const isObj: (v: ZodTypeAny) => v is ZodObject<any, any, any>;
24
- export declare const isNull: (v: ZodTypeAny) => v is ZodNull;
25
- export declare const isArr: (v: ZodTypeAny) => v is ZodArray<any, any>;
26
- export declare const isUnion: (v: ZodTypeAny) => v is ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>;
27
- export declare const isString: (v: ZodTypeAny) => v is ZodString;
28
- export declare const isNumber: (v: ZodTypeAny) => v is ZodNumber;
29
- export declare const isDate: (v: ZodTypeAny) => v is ZodDate;
30
- export declare const isDefault: (v: ZodTypeAny) => v is ZodDefault<any>;
31
- /**
32
- * Zod types that are not supported by most AI model providers and should be avoided.
33
- * @constant
34
- */
35
- export declare const UNSUPPORTED_ZOD_TYPES: readonly ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
36
- /**
37
- * Zod types that are generally supported by AI model providers.
38
- * @constant
39
- */
40
- export declare const SUPPORTED_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault"];
41
- /**
42
- * All Zod types (both supported and unsupported).
43
- * @constant
44
- */
45
- export declare const ALL_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault", "ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
46
- /**
47
- * Type representing string validation checks.
48
- */
49
- export type StringCheckType = (typeof ALL_STRING_CHECKS)[number];
50
- /**
51
- * Type representing number validation checks.
52
- */
53
- export type NumberCheckType = (typeof ALL_NUMBER_CHECKS)[number];
54
- /**
55
- * Type representing array validation checks.
56
- */
57
- export type ArrayCheckType = (typeof ALL_ARRAY_CHECKS)[number];
58
- /**
59
- * Type representing unsupported Zod schema types.
60
- */
61
- export type UnsupportedZodType = (typeof UNSUPPORTED_ZOD_TYPES)[number];
62
- /**
63
- * Type representing supported Zod schema types.
64
- */
65
- export type SupportedZodType = (typeof SUPPORTED_ZOD_TYPES)[number];
66
- /**
67
- * Type representing all Zod schema types (supported and unsupported).
68
- */
69
- export type AllZodType = (typeof ALL_ZOD_TYPES)[number];
70
- /**
71
- * Utility type to extract the shape of a Zod object schema.
72
- */
73
- export type ZodShape<T extends z.AnyZodObject> = T['shape'];
74
- /**
75
- * Utility type to extract the keys from a Zod object shape.
76
- */
77
- export type ShapeKey<T extends z.AnyZodObject> = keyof ZodShape<T>;
78
- /**
79
- * Utility type to extract the value types from a Zod object shape.
80
- */
81
- export type ShapeValue<T extends z.AnyZodObject> = ZodShape<T>[ShapeKey<T>];
82
- type StringConstraints = {
83
- minLength?: number;
84
- maxLength?: number;
85
- email?: boolean;
86
- url?: boolean;
87
- uuid?: boolean;
88
- cuid?: boolean;
89
- emoji?: boolean;
90
- regex?: {
91
- pattern: string;
92
- flags?: string;
93
- };
94
- };
95
- type NumberConstraints = {
96
- gt?: number;
97
- gte?: number;
98
- lt?: number;
99
- lte?: number;
100
- multipleOf?: number;
101
- };
102
- type ArrayConstraints = {
103
- minLength?: number;
104
- maxLength?: number;
105
- exactLength?: number;
106
- };
107
- type DateConstraints = {
108
- minDate?: string;
109
- maxDate?: string;
110
- dateFormat?: string;
111
- };
112
- /**
113
- * Abstract base class for creating schema compatibility layers for different AI model providers.
114
- *
115
- * This class provides a framework for transforming Zod schemas to work with specific AI model
116
- * provider requirements and limitations. Each provider may have different support levels for
117
- * JSON Schema features, validation constraints, and data types.
118
- *
119
- * @abstract
120
- *
121
- * @example
122
- * ```typescript
123
- * import { SchemaCompatLayer } from '@mastra/schema-compat';
124
- * import type { LanguageModelV1 } from 'ai';
125
- *
126
- * class CustomProviderCompat extends SchemaCompatLayer {
127
- * constructor(model: LanguageModelV1) {
128
- * super(model);
129
- * }
130
- *
131
- * shouldApply(): boolean {
132
- * return this.getModel().provider === 'custom-provider';
133
- * }
134
- *
135
- * getSchemaTarget() {
136
- * return 'jsonSchema7';
137
- * }
138
- *
139
- * processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
140
- * // Custom processing logic for this provider
141
- * switch (value._def.typeName) {
142
- * case 'ZodString':
143
- * return this.defaultZodStringHandler(value, ['email', 'url']);
144
- * default:
145
- * return this.defaultUnsupportedZodTypeHandler(value);
146
- * }
147
- * }
148
- * }
149
- * ```
150
- */
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[];
151
9
  export declare abstract class SchemaCompatLayer {
152
10
  private model;
11
+ private v3Layer;
12
+ private v4Layer;
153
13
  /**
154
14
  * Creates a new schema compatibility instance.
155
15
  *
156
16
  * @param model - The language model this compatibility layer applies to
157
17
  */
158
- constructor(model: SchemaCompatModel);
18
+ constructor(model: ModelInformation);
159
19
  /**
160
20
  * Gets the language model associated with this compatibility layer.
161
21
  *
162
22
  * @returns The language model instance
163
23
  */
164
- getModel(): SchemaCompatModel;
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>;
165
71
  /**
166
72
  * Determines whether this compatibility layer should be applied for the current model.
167
73
  *
@@ -183,16 +89,21 @@ export declare abstract class SchemaCompatLayer {
183
89
  * @returns The processed Zod type
184
90
  * @abstract
185
91
  */
186
- 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;
187
95
  /**
188
96
  * Default handler for Zod object types. Recursively processes all properties in the object.
189
97
  *
190
98
  * @param value - The Zod object to process
191
99
  * @returns The processed Zod object
192
100
  */
193
- 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?: {
194
105
  passthrough?: boolean;
195
- }): ZodObject<any, any, any>;
106
+ }): zV3.ZodObject<any, any>;
196
107
  /**
197
108
  * Merges validation constraints into a parameter description.
198
109
  *
@@ -203,9 +114,7 @@ export declare abstract class SchemaCompatLayer {
203
114
  * @param constraints - The validation constraints to merge
204
115
  * @returns The updated description with constraints, or undefined if no constraints
205
116
  */
206
- mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
207
- defaultValue?: unknown;
208
- }): string | undefined;
117
+ mergeParameterDescription(description: string | undefined, constraints: ConstraintHelperText): string | undefined;
209
118
  /**
210
119
  * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
211
120
  *
@@ -214,7 +123,7 @@ export declare abstract class SchemaCompatLayer {
214
123
  * @returns The original value if not in the throw list
215
124
  * @throws Error if the type is in the unsupported list
216
125
  */
217
- 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;
218
127
  /**
219
128
  * Default handler for Zod array types. Processes array constraints according to provider support.
220
129
  *
@@ -222,7 +131,8 @@ export declare abstract class SchemaCompatLayer {
222
131
  * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
223
132
  * @returns The processed Zod array
224
133
  */
225
- 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>;
226
136
  /**
227
137
  * Default handler for Zod union types. Processes all union options.
228
138
  *
@@ -230,7 +140,8 @@ export declare abstract class SchemaCompatLayer {
230
140
  * @returns The processed Zod union
231
141
  * @throws Error if union has fewer than 2 options
232
142
  */
233
- 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;
234
145
  /**
235
146
  * Default handler for Zod string types. Processes string validation constraints.
236
147
  *
@@ -238,7 +149,8 @@ export declare abstract class SchemaCompatLayer {
238
149
  * @param handleChecks - String constraints to convert to descriptions vs keep as validation
239
150
  * @returns The processed Zod string
240
151
  */
241
- 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;
242
154
  /**
243
155
  * Default handler for Zod number types. Processes number validation constraints.
244
156
  *
@@ -246,14 +158,16 @@ export declare abstract class SchemaCompatLayer {
246
158
  * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
247
159
  * @returns The processed Zod number
248
160
  */
249
- 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;
250
163
  /**
251
164
  * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
252
165
  *
253
166
  * @param value - The Zod date to process
254
167
  * @returns A Zod string schema representing the date in ISO format
255
168
  */
256
- defaultZodDateHandler(value: ZodDate): ZodString;
169
+ defaultZodDateHandler(value: zV4.ZodDate): zV4.ZodString;
170
+ defaultZodDateHandler(value: zV3.ZodDate): zV3.ZodString;
257
171
  /**
258
172
  * Default handler for Zod optional types. Processes the inner type and maintains optionality.
259
173
  *
@@ -261,21 +175,22 @@ export declare abstract class SchemaCompatLayer {
261
175
  * @param handleTypes - Types that should be processed vs passed through
262
176
  * @returns The processed Zod optional
263
177
  */
264
- 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;
265
180
  /**
266
181
  * Processes a Zod object schema and converts it to an AI SDK Schema.
267
182
  *
268
183
  * @param zodSchema - The Zod object schema to process
269
184
  * @returns An AI SDK Schema with provider-specific compatibility applied
270
185
  */
271
- processToAISDKSchema(zodSchema: z.ZodSchema): Schema;
186
+ processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema;
272
187
  /**
273
188
  * Processes a Zod object schema and converts it to a JSON Schema.
274
189
  *
275
190
  * @param zodSchema - The Zod object schema to process
276
191
  * @returns A JSONSchema7 object with provider-specific compatibility applied
277
192
  */
278
- processToJSONSchema(zodSchema: z.ZodSchema): JSONSchema7;
193
+ processToJSONSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): JSONSchema7;
279
194
  }
280
195
  export {};
281
196
  //# sourceMappingURL=schema-compatibility.d.ts.map