@mastra/schema-compat 0.10.5 → 0.10.6-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +47 -0
  3. package/README.md +0 -4
  4. package/dist/chunk-FTKGHMGD.js +27 -0
  5. package/dist/chunk-FTKGHMGD.js.map +1 -0
  6. package/dist/chunk-LNR4XKDU.cjs +33 -0
  7. package/dist/chunk-LNR4XKDU.cjs.map +1 -0
  8. package/dist/index.cjs +845 -84
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +11 -31
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +844 -85
  13. package/dist/index.js.map +1 -0
  14. package/dist/provider-compats/anthropic.d.ts +13 -0
  15. package/dist/provider-compats/anthropic.d.ts.map +1 -0
  16. package/dist/provider-compats/deepseek.d.ts +13 -0
  17. package/dist/provider-compats/deepseek.d.ts.map +1 -0
  18. package/dist/provider-compats/google.d.ts +13 -0
  19. package/dist/provider-compats/google.d.ts.map +1 -0
  20. package/dist/provider-compats/meta.d.ts +13 -0
  21. package/dist/provider-compats/meta.d.ts.map +1 -0
  22. package/dist/provider-compats/openai-reasoning.d.ts +14 -0
  23. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
  24. package/dist/provider-compats/openai.d.ts +13 -0
  25. package/dist/provider-compats/openai.d.ts.map +1 -0
  26. package/dist/schema-compatibility-v3.d.ts +319 -0
  27. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  28. package/dist/schema-compatibility-v4.d.ts +310 -0
  29. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  30. package/dist/schema-compatibility.d.ts +228 -0
  31. package/dist/schema-compatibility.d.ts.map +1 -0
  32. package/dist/types.d.ts +6 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/dist/utils-test-suite.d.ts +2 -0
  35. package/dist/utils-test-suite.d.ts.map +1 -0
  36. package/dist/utils.d.ts +96 -0
  37. package/dist/utils.d.ts.map +1 -0
  38. package/dist/zod-to-json.cjs +12 -0
  39. package/dist/zod-to-json.cjs.map +1 -0
  40. package/dist/zod-to-json.d.ts +6 -0
  41. package/dist/zod-to-json.d.ts.map +1 -0
  42. package/dist/zod-to-json.js +3 -0
  43. package/dist/zod-to-json.js.map +1 -0
  44. package/dist/zodTypes.d.ts +21 -0
  45. package/dist/zodTypes.d.ts.map +1 -0
  46. package/package.json +19 -8
  47. package/src/index.ts +4 -3
  48. package/src/provider-compats/anthropic.ts +30 -13
  49. package/src/provider-compats/deepseek.ts +15 -10
  50. package/src/provider-compats/google.ts +19 -33
  51. package/src/provider-compats/meta.ts +16 -11
  52. package/src/provider-compats/openai-reasoning.ts +24 -26
  53. package/src/provider-compats/openai.ts +23 -14
  54. package/src/provider-compats.test.ts +120 -25
  55. package/src/schema-compatibility-v3.ts +664 -0
  56. package/src/schema-compatibility-v4.test.ts +476 -0
  57. package/src/schema-compatibility-v4.ts +706 -0
  58. package/src/schema-compatibility.test.ts +9 -9
  59. package/src/schema-compatibility.ts +266 -383
  60. package/src/types.ts +5 -0
  61. package/src/utils-test-suite.ts +467 -0
  62. package/src/utils-v3.test.ts +9 -0
  63. package/src/utils-v4.test.ts +9 -0
  64. package/src/utils.ts +30 -24
  65. package/src/zod-to-json.ts +27 -0
  66. package/src/zodTypes.ts +56 -0
  67. package/tsconfig.build.json +9 -0
  68. package/tsconfig.json +1 -1
  69. package/tsup.config.ts +22 -0
  70. package/dist/_tsup-dts-rollup.d.cts +0 -507
  71. package/dist/_tsup-dts-rollup.d.ts +0 -507
  72. package/dist/index.d.cts +0 -31
  73. package/src/utils.test.ts +0 -434
@@ -0,0 +1,228 @@
1
+ import type { Schema } from 'ai';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ import type { z as zV3 } from 'zod/v3';
4
+ import type { z as zV4, ZodType } from 'zod/v4';
5
+ import type { Targets } from 'zod-to-json-schema';
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';
8
+ type StringConstraints = {
9
+ minLength?: number;
10
+ maxLength?: number;
11
+ email?: boolean;
12
+ url?: boolean;
13
+ uuid?: boolean;
14
+ cuid?: boolean;
15
+ emoji?: boolean;
16
+ regex?: {
17
+ pattern: string;
18
+ flags?: string;
19
+ };
20
+ };
21
+ type NumberConstraints = {
22
+ gt?: number;
23
+ gte?: number;
24
+ lt?: number;
25
+ lte?: number;
26
+ multipleOf?: number;
27
+ };
28
+ type ArrayConstraints = {
29
+ minLength?: number;
30
+ maxLength?: number;
31
+ exactLength?: number;
32
+ };
33
+ type DateConstraints = {
34
+ minDate?: string;
35
+ maxDate?: string;
36
+ dateFormat?: string;
37
+ };
38
+ import type { ModelInformation } from './types';
39
+ export declare abstract class SchemaCompatLayer {
40
+ private model;
41
+ private v3Layer;
42
+ private v4Layer;
43
+ /**
44
+ * Creates a new schema compatibility instance.
45
+ *
46
+ * @param model - The language model this compatibility layer applies to
47
+ */
48
+ constructor(model: ModelInformation);
49
+ /**
50
+ * Gets the language model associated with this compatibility layer.
51
+ *
52
+ * @returns The language model instance
53
+ */
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>;
101
+ /**
102
+ * Determines whether this compatibility layer should be applied for the current model.
103
+ *
104
+ * @returns True if this compatibility layer should be used, false otherwise
105
+ * @abstract
106
+ */
107
+ abstract shouldApply(): boolean;
108
+ /**
109
+ * Returns the JSON Schema target format for this provider.
110
+ *
111
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
112
+ * @abstract
113
+ */
114
+ abstract getSchemaTarget(): Targets | undefined;
115
+ /**
116
+ * Processes a specific Zod type according to the provider's requirements.
117
+ *
118
+ * @param value - The Zod type to process
119
+ * @returns The processed Zod type
120
+ * @abstract
121
+ */
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;
125
+ /**
126
+ * Default handler for Zod object types. Recursively processes all properties in the object.
127
+ *
128
+ * @param value - The Zod object to process
129
+ * @returns The processed Zod object
130
+ */
131
+ defaultZodObjectHandler(value: zV4.ZodObject<any, any>, options?: {
132
+ passthrough?: boolean;
133
+ }): zV4.ZodObject<any, any>;
134
+ defaultZodObjectHandler(value: zV3.ZodObject<any, any>, options?: {
135
+ passthrough?: boolean;
136
+ }): zV3.ZodObject<any, any>;
137
+ /**
138
+ * Merges validation constraints into a parameter description.
139
+ *
140
+ * This helper method converts validation constraints that may not be supported
141
+ * by a provider into human-readable descriptions.
142
+ *
143
+ * @param description - The existing parameter description
144
+ * @param constraints - The validation constraints to merge
145
+ * @returns The updated description with constraints, or undefined if no constraints
146
+ */
147
+ mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
148
+ defaultValue?: unknown;
149
+ }): string | undefined;
150
+ /**
151
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
152
+ *
153
+ * @param value - The Zod type to check
154
+ * @param throwOnTypes - Array of type names to throw errors for
155
+ * @returns The original value if not in the throw list
156
+ * @throws Error if the type is in the unsupported list
157
+ */
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;
159
+ /**
160
+ * Default handler for Zod array types. Processes array constraints according to provider support.
161
+ *
162
+ * @param value - The Zod array to process
163
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
164
+ * @returns The processed Zod array
165
+ */
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>;
168
+ /**
169
+ * Default handler for Zod union types. Processes all union options.
170
+ *
171
+ * @param value - The Zod union to process
172
+ * @returns The processed Zod union
173
+ * @throws Error if union has fewer than 2 options
174
+ */
175
+ defaultZodUnionHandler(value: zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>): zV4.ZodType;
176
+ defaultZodUnionHandler(value: zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>): zV3.ZodType;
177
+ /**
178
+ * Default handler for Zod string types. Processes string validation constraints.
179
+ *
180
+ * @param value - The Zod string to process
181
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
182
+ * @returns The processed Zod string
183
+ */
184
+ defaultZodStringHandler(value: zV4.ZodString, handleChecks?: readonly StringCheckType[]): zV4.ZodString;
185
+ defaultZodStringHandler(value: zV3.ZodString, handleChecks?: readonly StringCheckType[]): zV3.ZodString;
186
+ /**
187
+ * Default handler for Zod number types. Processes number validation constraints.
188
+ *
189
+ * @param value - The Zod number to process
190
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
191
+ * @returns The processed Zod number
192
+ */
193
+ defaultZodNumberHandler(value: zV4.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV4.ZodNumber;
194
+ defaultZodNumberHandler(value: zV3.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV3.ZodNumber;
195
+ /**
196
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
197
+ *
198
+ * @param value - The Zod date to process
199
+ * @returns A Zod string schema representing the date in ISO format
200
+ */
201
+ defaultZodDateHandler(value: zV4.ZodDate): zV4.ZodString;
202
+ defaultZodDateHandler(value: zV3.ZodDate): zV3.ZodString;
203
+ /**
204
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
205
+ *
206
+ * @param value - The Zod optional to process
207
+ * @param handleTypes - Types that should be processed vs passed through
208
+ * @returns The processed Zod optional
209
+ */
210
+ defaultZodOptionalHandler(value: zV4.ZodOptional<any>, handleTypes?: readonly AllZodTypeV4[]): zV4.ZodType;
211
+ defaultZodOptionalHandler(value: zV3.ZodOptional<any>, handleTypes?: readonly AllZodTypeV3[]): zV3.ZodType;
212
+ /**
213
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
214
+ *
215
+ * @param zodSchema - The Zod object schema to process
216
+ * @returns An AI SDK Schema with provider-specific compatibility applied
217
+ */
218
+ processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema;
219
+ /**
220
+ * Processes a Zod object schema and converts it to a JSON Schema.
221
+ *
222
+ * @param zodSchema - The Zod object schema to process
223
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
224
+ */
225
+ processToJSONSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): JSONSchema7;
226
+ }
227
+ export {};
228
+ //# sourceMappingURL=schema-compatibility.d.ts.map
@@ -0,0 +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,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,IA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SAAS;IAS/D;;;;;;OAMG;IACI,yBAAyB,CAAC,KAAK,EAAE,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"}
@@ -0,0 +1,6 @@
1
+ export type ModelInformation = {
2
+ modelId: string;
3
+ provider: string;
4
+ supportsStructuredOutputs: boolean;
5
+ };
6
+ //# sourceMappingURL=types.d.ts.map
@@ -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,2 @@
1
+ export declare function runTestSuite(): void;
2
+ //# sourceMappingURL=utils-test-suite.d.ts.map
@@ -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"}
@@ -0,0 +1,96 @@
1
+ import type { Schema } from 'ai';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ import type { ZodSchema as ZodSchemaV3, ZodType as ZodTypeV3 } from 'zod/v3';
4
+ import type { ZodType as ZodSchemaV4, ZodType as ZodTypeV4 } from 'zod/v4';
5
+ import type { Targets } from 'zod-to-json-schema';
6
+ import type { SchemaCompatLayer } from './schema-compatibility';
7
+ type ZodSchema = ZodSchemaV3 | ZodSchemaV4;
8
+ type ZodType = ZodTypeV3 | ZodTypeV4;
9
+ /**
10
+ * Converts a Zod schema to an AI SDK Schema with validation support.
11
+ *
12
+ * This function mirrors the behavior of Vercel's AI SDK zod-schema utility but allows
13
+ * customization of the JSON Schema target format.
14
+ *
15
+ * @param zodSchema - The Zod schema to convert
16
+ * @param target - The JSON Schema target format (defaults to 'jsonSchema7')
17
+ * @returns An AI SDK Schema object with built-in validation
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { z } from 'zod';
22
+ * import { convertZodSchemaToAISDKSchema } from '@mastra/schema-compat';
23
+ *
24
+ * const userSchema = z.object({
25
+ * name: z.string(),
26
+ * age: z.number().min(0)
27
+ * });
28
+ *
29
+ * const aiSchema = convertZodSchemaToAISDKSchema(userSchema);
30
+ * ```
31
+ */
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;
41
+ /**
42
+ * Converts an AI SDK Schema or Zod schema to a Zod schema.
43
+ *
44
+ * If the input is already a Zod schema, it returns it unchanged.
45
+ * If the input is an AI SDK Schema, it extracts the JSON schema and converts it to Zod.
46
+ *
47
+ * @param schema - The schema to convert (AI SDK Schema or Zod schema)
48
+ * @returns A Zod schema equivalent of the input
49
+ * @throws Error if the conversion fails
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { jsonSchema } from 'ai';
54
+ * import { convertSchemaToZod } from '@mastra/schema-compat';
55
+ *
56
+ * const aiSchema = jsonSchema({
57
+ * type: 'object',
58
+ * properties: {
59
+ * name: { type: 'string' }
60
+ * }
61
+ * });
62
+ *
63
+ * const zodSchema = convertSchemaToZod(aiSchema);
64
+ * ```
65
+ */
66
+ export declare function convertSchemaToZod(schema: Schema | ZodSchema): ZodType;
67
+ /**
68
+ * Processes a schema using provider compatibility layers and converts it to an AI SDK Schema.
69
+ *
70
+ * @param options - Configuration object for schema processing
71
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
72
+ * @param options.compatLayers - Array of compatibility layers to try
73
+ * @param options.mode - Must be 'aiSdkSchema'
74
+ * @returns Processed schema as an AI SDK Schema
75
+ */
76
+ export declare function applyCompatLayer(options: {
77
+ schema: Schema | ZodSchema;
78
+ compatLayers: SchemaCompatLayer[];
79
+ mode: 'aiSdkSchema';
80
+ }): Schema;
81
+ /**
82
+ * Processes a schema using provider compatibility layers and converts it to a JSON Schema.
83
+ *
84
+ * @param options - Configuration object for schema processing
85
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
86
+ * @param options.compatLayers - Array of compatibility layers to try
87
+ * @param options.mode - Must be 'jsonSchema'
88
+ * @returns Processed schema as a JSONSchema7
89
+ */
90
+ export declare function applyCompatLayer(options: {
91
+ schema: Schema | ZodSchema;
92
+ compatLayers: SchemaCompatLayer[];
93
+ mode: 'jsonSchema';
94
+ }): JSONSchema7;
95
+ export {};
96
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +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;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,3 @@
1
+ export { zodToJsonSchema } from './chunk-FTKGHMGD.js';
2
+ //# sourceMappingURL=zod-to-json.js.map
3
+ //# sourceMappingURL=zod-to-json.js.map
@@ -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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C,GAAG,CAAC,CAAC;AAC5F,wBAAgB,SAAS,CAAC,CAAC,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.10.5",
3
+ "version": "0.10.6-alpha.1",
4
4
  "description": "Tool schema compatibility layer for Mastra.ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,10 +12,20 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cts",
15
+ "types": "./dist/index.d.ts",
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.5",
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.0.0 || ^4.0.0"
38
49
  },
39
50
  "devDependencies": {
40
51
  "@types/json-schema": "^7.0.15",
@@ -45,11 +56,11 @@
45
56
  "typescript": "^5.8.3",
46
57
  "vitest": "^3.2.4",
47
58
  "zod": "^3.25.67",
48
- "@internal/lint": "0.0.20"
59
+ "@internal/lint": "0.0.31"
49
60
  },
50
61
  "scripts": {
51
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
52
- "build:watch": "pnpm build --watch",
62
+ "build": "tsup --silent --config tsup.config.ts",
63
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
53
64
  "test": "vitest run",
54
65
  "lint": "eslint ."
55
66
  }
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,11 +1,15 @@
1
- import type { LanguageModelV1 } from 'ai';
2
- import type { ZodTypeAny } from 'zod';
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';
3
4
  import type { Targets } from 'zod-to-json-schema';
4
- import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
5
- import type { AllZodType } from '../schema-compatibility';
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';
6
10
 
7
11
  export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
8
- constructor(model: LanguageModelV1) {
12
+ constructor(model: ModelInformation) {
9
13
  super(model);
10
14
  }
11
15
 
@@ -17,18 +21,27 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
17
21
  return this.getModel().modelId.includes('claude');
18
22
  }
19
23
 
20
- processZodType(value: ZodTypeAny): ZodTypeAny {
21
- if (isOptional(value)) {
22
- const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined', 'ZodTuple'];
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
+ ];
23
36
  if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
24
37
  return this.defaultZodOptionalHandler(value, handleTypes);
25
- } else if (isObj(value)) {
38
+ } else if (isObj(z)(value)) {
26
39
  return this.defaultZodObjectHandler(value);
27
- } else if (isArr(value)) {
40
+ } else if (isArr(z)(value)) {
28
41
  return this.defaultZodArrayHandler(value, []);
29
- } else if (isUnion(value)) {
42
+ } else if (isUnion(z)(value)) {
30
43
  return this.defaultZodUnionHandler(value);
31
- } else if (isString(value)) {
44
+ } else if (isString(z)(value)) {
32
45
  // the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
33
46
  // added to the tool description
34
47
 
@@ -39,6 +52,10 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
39
52
  }
40
53
  }
41
54
 
42
- return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
55
+ return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>, [
56
+ 'ZodNever',
57
+ 'ZodTuple',
58
+ 'ZodUndefined',
59
+ ]);
43
60
  }
44
61
  }
@@ -1,10 +1,13 @@
1
- import type { LanguageModelV1 } from 'ai';
2
- import type { ZodTypeAny } from 'zod';
1
+ import { z } from 'zod';
2
+ import type { ZodType as ZodTypeV3 } from 'zod/v3';
3
+ import type { ZodType as ZodTypeV4 } from 'zod/v4';
3
4
  import type { Targets } from 'zod-to-json-schema';
4
- import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
5
+ import { SchemaCompatLayer } from '../schema-compatibility';
6
+ import type { ModelInformation } from '../types';
7
+ import { isOptional, isObj, isArr, isUnion, isString } from '../zodTypes';
5
8
 
6
9
  export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: LanguageModelV1) {
10
+ constructor(model: ModelInformation) {
8
11
  super(model);
9
12
  }
10
13
 
@@ -17,16 +20,18 @@ export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
17
20
  return this.getModel().modelId.includes('deepseek') && !this.getModel().modelId.includes('r1');
18
21
  }
19
22
 
20
- processZodType(value: ZodTypeAny): ZodTypeAny {
21
- if (isOptional(value)) {
23
+ processZodType(value: ZodTypeV3): ZodTypeV3;
24
+ processZodType(value: ZodTypeV4): ZodTypeV4;
25
+ processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
26
+ if (isOptional(z)(value)) {
22
27
  return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
23
- } else if (isObj(value)) {
28
+ } else if (isObj(z)(value)) {
24
29
  return this.defaultZodObjectHandler(value);
25
- } else if (isArr(value)) {
30
+ } else if (isArr(z)(value)) {
26
31
  return this.defaultZodArrayHandler(value, ['min', 'max']);
27
- } else if (isUnion(value)) {
32
+ } else if (isUnion(z)(value)) {
28
33
  return this.defaultZodUnionHandler(value);
29
- } else if (isString(value)) {
34
+ } else if (isString(z)(value)) {
30
35
  return this.defaultZodStringHandler(value);
31
36
  }
32
37