@mastra/schema-compat 0.0.0-ai-v5-20250729181825 → 0.0.0-feat-support-ai-sdk-5-again-20250813225910

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 (41) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +34 -1
  3. package/dist/index.cjs +4 -5
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +9 -31
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +4 -5
  8. package/dist/index.js.map +1 -0
  9. package/dist/provider-compats/anthropic.d.ts +11 -0
  10. package/dist/provider-compats/anthropic.d.ts.map +1 -0
  11. package/dist/provider-compats/deepseek.d.ts +11 -0
  12. package/dist/provider-compats/deepseek.d.ts.map +1 -0
  13. package/dist/provider-compats/google.d.ts +11 -0
  14. package/dist/provider-compats/google.d.ts.map +1 -0
  15. package/dist/provider-compats/meta.d.ts +11 -0
  16. package/dist/provider-compats/meta.d.ts.map +1 -0
  17. package/dist/provider-compats/openai-reasoning.d.ts +12 -0
  18. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
  19. package/dist/provider-compats/openai.d.ts +11 -0
  20. package/dist/provider-compats/openai.d.ts.map +1 -0
  21. package/dist/schema-compatibility.d.ts +282 -0
  22. package/dist/schema-compatibility.d.ts.map +1 -0
  23. package/dist/utils.d.ts +84 -0
  24. package/dist/utils.d.ts.map +1 -0
  25. package/package.json +8 -7
  26. package/src/provider-compats/anthropic.ts +2 -2
  27. package/src/provider-compats/deepseek.ts +2 -2
  28. package/src/provider-compats/google.ts +2 -3
  29. package/src/provider-compats/meta.ts +2 -2
  30. package/src/provider-compats/openai-reasoning.ts +7 -4
  31. package/src/provider-compats/openai.ts +2 -2
  32. package/src/provider-compats.test.ts +96 -25
  33. package/src/schema-compatibility.test.ts +18 -6
  34. package/src/schema-compatibility.ts +10 -8
  35. package/src/utils.test.ts +27 -6
  36. package/tsconfig.build.json +9 -0
  37. package/tsconfig.json +1 -1
  38. package/tsup.config.ts +17 -0
  39. package/dist/_tsup-dts-rollup.d.cts +0 -509
  40. package/dist/_tsup-dts-rollup.d.ts +0 -509
  41. package/dist/index.d.cts +0 -31
@@ -0,0 +1,282 @@
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';
5
+ 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?: string;
91
+ };
92
+ type NumberConstraints = {
93
+ gt?: number;
94
+ gte?: number;
95
+ lt?: number;
96
+ lte?: number;
97
+ multipleOf?: number;
98
+ };
99
+ type ArrayConstraints = {
100
+ minLength?: number;
101
+ maxLength?: number;
102
+ exactLength?: number;
103
+ };
104
+ type DateConstraints = {
105
+ minDate?: string;
106
+ maxDate?: string;
107
+ dateFormat?: string;
108
+ };
109
+ export type ModelInformation = {
110
+ modelId: string;
111
+ provider: string;
112
+ };
113
+ /**
114
+ * Abstract base class for creating schema compatibility layers for different AI model providers.
115
+ *
116
+ * This class provides a framework for transforming Zod schemas to work with specific AI model
117
+ * provider requirements and limitations. Each provider may have different support levels for
118
+ * JSON Schema features, validation constraints, and data types.
119
+ *
120
+ * @abstract
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { SchemaCompatLayer } from '@mastra/schema-compat';
125
+ * import type { LanguageModelV1 } from 'ai';
126
+ *
127
+ * class CustomProviderCompat extends SchemaCompatLayer {
128
+ * constructor(model: LanguageModelV1) {
129
+ * super(model);
130
+ * }
131
+ *
132
+ * shouldApply(): boolean {
133
+ * return this.getModel().provider === 'custom-provider';
134
+ * }
135
+ *
136
+ * getSchemaTarget() {
137
+ * return 'jsonSchema7';
138
+ * }
139
+ *
140
+ * processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
141
+ * // Custom processing logic for this provider
142
+ * switch (value._def.typeName) {
143
+ * case 'ZodString':
144
+ * return this.defaultZodStringHandler(value, ['email', 'url']);
145
+ * default:
146
+ * return this.defaultUnsupportedZodTypeHandler(value);
147
+ * }
148
+ * }
149
+ * }
150
+ * ```
151
+ */
152
+ export declare abstract class SchemaCompatLayer {
153
+ private model;
154
+ /**
155
+ * Creates a new schema compatibility instance.
156
+ *
157
+ * @param model - The language model this compatibility layer applies to
158
+ */
159
+ constructor(model: ModelInformation);
160
+ /**
161
+ * Gets the language model associated with this compatibility layer.
162
+ *
163
+ * @returns The language model instance
164
+ */
165
+ getModel(): ModelInformation;
166
+ /**
167
+ * Determines whether this compatibility layer should be applied for the current model.
168
+ *
169
+ * @returns True if this compatibility layer should be used, false otherwise
170
+ * @abstract
171
+ */
172
+ abstract shouldApply(): boolean;
173
+ /**
174
+ * Returns the JSON Schema target format for this provider.
175
+ *
176
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
177
+ * @abstract
178
+ */
179
+ abstract getSchemaTarget(): Targets | undefined;
180
+ /**
181
+ * Processes a specific Zod type according to the provider's requirements.
182
+ *
183
+ * @param value - The Zod type to process
184
+ * @returns The processed Zod type
185
+ * @abstract
186
+ */
187
+ abstract processZodType(value: ZodTypeAny): ZodTypeAny;
188
+ /**
189
+ * Default handler for Zod object types. Recursively processes all properties in the object.
190
+ *
191
+ * @param value - The Zod object to process
192
+ * @returns The processed Zod object
193
+ */
194
+ defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
195
+ passthrough?: boolean;
196
+ }): ZodObject<any, any, any>;
197
+ /**
198
+ * Merges validation constraints into a parameter description.
199
+ *
200
+ * This helper method converts validation constraints that may not be supported
201
+ * by a provider into human-readable descriptions.
202
+ *
203
+ * @param description - The existing parameter description
204
+ * @param constraints - The validation constraints to merge
205
+ * @returns The updated description with constraints, or undefined if no constraints
206
+ */
207
+ mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
208
+ defaultValue?: unknown;
209
+ }): string | undefined;
210
+ /**
211
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
212
+ *
213
+ * @param value - The Zod type to check
214
+ * @param throwOnTypes - Array of type names to throw errors for
215
+ * @returns The original value if not in the throw list
216
+ * @throws Error if the type is in the unsupported list
217
+ */
218
+ defaultUnsupportedZodTypeHandler<T extends z.AnyZodObject>(value: z.ZodTypeAny, throwOnTypes?: readonly UnsupportedZodType[]): ShapeValue<T>;
219
+ /**
220
+ * Default handler for Zod array types. Processes array constraints according to provider support.
221
+ *
222
+ * @param value - The Zod array to process
223
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
224
+ * @returns The processed Zod array
225
+ */
226
+ defaultZodArrayHandler(value: ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): ZodArray<any, any>;
227
+ /**
228
+ * Default handler for Zod union types. Processes all union options.
229
+ *
230
+ * @param value - The Zod union to process
231
+ * @returns The processed Zod union
232
+ * @throws Error if union has fewer than 2 options
233
+ */
234
+ defaultZodUnionHandler(value: ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>): ZodTypeAny;
235
+ /**
236
+ * Default handler for Zod string types. Processes string validation constraints.
237
+ *
238
+ * @param value - The Zod string to process
239
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
240
+ * @returns The processed Zod string
241
+ */
242
+ defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
243
+ /**
244
+ * Default handler for Zod number types. Processes number validation constraints.
245
+ *
246
+ * @param value - The Zod number to process
247
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
248
+ * @returns The processed Zod number
249
+ */
250
+ defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
251
+ /**
252
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
253
+ *
254
+ * @param value - The Zod date to process
255
+ * @returns A Zod string schema representing the date in ISO format
256
+ */
257
+ defaultZodDateHandler(value: ZodDate): ZodString;
258
+ /**
259
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
260
+ *
261
+ * @param value - The Zod optional to process
262
+ * @param handleTypes - Types that should be processed vs passed through
263
+ * @returns The processed Zod optional
264
+ */
265
+ defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly AllZodType[]): ZodTypeAny;
266
+ /**
267
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
268
+ *
269
+ * @param zodSchema - The Zod object schema to process
270
+ * @returns An AI SDK Schema with provider-specific compatibility applied
271
+ */
272
+ processToAISDKSchema(zodSchema: z.ZodSchema): Schema;
273
+ /**
274
+ * Processes a Zod object schema and converts it to a JSON Schema.
275
+ *
276
+ * @param zodSchema - The Zod object schema to process
277
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
278
+ */
279
+ processToJSONSchema(zodSchema: z.ZodSchema): JSONSchema7;
280
+ }
281
+ export {};
282
+ //# 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,aAAa,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACxH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2EAA4E,CAAC;AAE3G;;;GAGG;AACH,eAAO,MAAM,iBAAiB,uCAIpB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,gBAAgB,mCAAoC,CAAC;AAElE,eAAO,MAAM,UAAU,GAAI,GAAG,UAAU,KAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAA6B,CAAC;AAC7F,eAAO,MAA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EACnB,YAAY,GAAE,SAAS,kBAAkB,EAA0B,GAClE,UAAU,CAAC,CAAC,CAAC;IAOhB;;;;;;OAMG;IACI,sBAAsB,CAC3B,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EACzB,YAAY,GAAE,SAAS,cAAc,EAAqB,GACzD,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAuCrB;;;;;;OAMG;IACI,sBAAsB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,GAAG,UAAU;IAUzF;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IA0DZ;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IAqDZ;;;;;OAKG;IACI,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS;IAkCvD;;;;;;OAMG;IACI,yBAAyB,CAC9B,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EACvB,WAAW,GAAE,SAAS,UAAU,EAAwB,GACvD,UAAU;IAQb;;;;;OAKG;IACI,oBAAoB,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,MAAM;IAM3D;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,WAAW;CAGhE"}
@@ -0,0 +1,84 @@
1
+ import type { Schema } from 'ai';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ import type { z, ZodSchema } from 'zod';
4
+ import type { Targets } from 'zod-to-json-schema';
5
+ import type { SchemaCompatLayer } from './schema-compatibility.js';
6
+ /**
7
+ * Converts a Zod schema to an AI SDK Schema with validation support.
8
+ *
9
+ * This function mirrors the behavior of Vercel's AI SDK zod-schema utility but allows
10
+ * customization of the JSON Schema target format.
11
+ *
12
+ * @param zodSchema - The Zod schema to convert
13
+ * @param target - The JSON Schema target format (defaults to 'jsonSchema7')
14
+ * @returns An AI SDK Schema object with built-in validation
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { z } from 'zod';
19
+ * import { convertZodSchemaToAISDKSchema } from '@mastra/schema-compat';
20
+ *
21
+ * const userSchema = z.object({
22
+ * name: z.string(),
23
+ * age: z.number().min(0)
24
+ * });
25
+ *
26
+ * const aiSchema = convertZodSchemaToAISDKSchema(userSchema);
27
+ * ```
28
+ */
29
+ export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, target?: Targets): Schema<any>;
30
+ /**
31
+ * Converts an AI SDK Schema or Zod schema to a Zod schema.
32
+ *
33
+ * If the input is already a Zod schema, it returns it unchanged.
34
+ * If the input is an AI SDK Schema, it extracts the JSON schema and converts it to Zod.
35
+ *
36
+ * @param schema - The schema to convert (AI SDK Schema or Zod schema)
37
+ * @returns A Zod schema equivalent of the input
38
+ * @throws Error if the conversion fails
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { jsonSchema } from 'ai';
43
+ * import { convertSchemaToZod } from '@mastra/schema-compat';
44
+ *
45
+ * const aiSchema = jsonSchema({
46
+ * type: 'object',
47
+ * properties: {
48
+ * name: { type: 'string' }
49
+ * }
50
+ * });
51
+ *
52
+ * const zodSchema = convertSchemaToZod(aiSchema);
53
+ * ```
54
+ */
55
+ export declare function convertSchemaToZod(schema: Schema | z.ZodSchema): z.ZodType;
56
+ /**
57
+ * Processes a schema using provider compatibility layers and converts it to an AI SDK Schema.
58
+ *
59
+ * @param options - Configuration object for schema processing
60
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
61
+ * @param options.compatLayers - Array of compatibility layers to try
62
+ * @param options.mode - Must be 'aiSdkSchema'
63
+ * @returns Processed schema as an AI SDK Schema
64
+ */
65
+ export declare function applyCompatLayer(options: {
66
+ schema: Schema | z.ZodSchema;
67
+ compatLayers: SchemaCompatLayer[];
68
+ mode: 'aiSdkSchema';
69
+ }): Schema;
70
+ /**
71
+ * Processes a schema using provider compatibility layers and converts it to a JSON Schema.
72
+ *
73
+ * @param options - Configuration object for schema processing
74
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
75
+ * @param options.compatLayers - Array of compatibility layers to try
76
+ * @param options.mode - Must be 'jsonSchema'
77
+ * @returns Processed schema as a JSONSchema7
78
+ */
79
+ export declare function applyCompatLayer(options: {
80
+ schema: Schema | z.ZodSchema;
81
+ compatLayers: SchemaCompatLayer[];
82
+ mode: 'jsonSchema';
83
+ }): JSONSchema7;
84
+ //# 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;AAC/C,OAAO,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAGxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,OAAuB,eAalG;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAa1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC7B,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,CAAC,CAAC,SAAS,CAAC;IAC7B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,IAAI,EAAE,YAAY,CAAC;CACpB,GAAG,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/schema-compat",
3
- "version": "0.0.0-ai-v5-20250729181825",
3
+ "version": "0.0.0-feat-support-ai-sdk-5-again-20250813225910",
4
4
  "description": "Tool schema compatibility layer for Mastra.ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
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
  },
@@ -33,23 +33,24 @@
33
33
  "zod-to-json-schema": "^3.24.5"
34
34
  },
35
35
  "peerDependencies": {
36
- "ai": "5.0.0-beta.14",
36
+ "ai": "^5.0.0",
37
37
  "zod": "^3.0.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/json-schema": "^7.0.15",
41
- "ai": "5.0.0-beta.14",
41
+ "ai": "latest",
42
42
  "@types/node": "^20.19.0",
43
43
  "eslint": "^9.30.1",
44
44
  "tsup": "^8.5.0",
45
45
  "typescript": "^5.8.3",
46
46
  "vitest": "^3.2.4",
47
47
  "zod": "^3.25.67",
48
- "@internal/lint": "0.0.0-ai-v5-20250729181825"
48
+ "@internal/types-builder": "0.0.0-feat-support-ai-sdk-5-again-20250813225910",
49
+ "@internal/lint": "0.0.0-feat-support-ai-sdk-5-again-20250813225910"
49
50
  },
50
51
  "scripts": {
51
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
52
- "build:watch": "pnpm build --watch",
52
+ "build": "tsup --silent --config tsup.config.ts",
53
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
53
54
  "test": "vitest run",
54
55
  "lint": "eslint ."
55
56
  }
@@ -1,10 +1,10 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import type { Targets } from 'zod-to-json-schema';
3
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { AllZodType, SchemaCompatModel } from '../schema-compatibility';
4
+ import type { AllZodType, ModelInformation } from '../schema-compatibility';
5
5
 
6
6
  export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: SchemaCompatModel) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10
 
@@ -1,10 +1,10 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import type { Targets } from 'zod-to-json-schema';
3
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { SchemaCompatModel } from '../schema-compatibility';
4
+ import type { ModelInformation } from '../schema-compatibility';
5
5
 
6
6
  export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: SchemaCompatModel) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10
 
@@ -1,6 +1,7 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import { z } from 'zod';
3
3
  import type { Targets } from 'zod-to-json-schema';
4
+ import type { ModelInformation } from '../schema-compatibility';
4
5
  import {
5
6
  SchemaCompatLayer,
6
7
  UNSUPPORTED_ZOD_TYPES,
@@ -12,10 +13,8 @@ import {
12
13
  isString,
13
14
  isUnion,
14
15
  } from '../schema-compatibility';
15
- import type { SchemaCompatModel } from '../schema-compatibility';
16
-
17
16
  export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
18
- constructor(model: SchemaCompatModel) {
17
+ constructor(model: ModelInformation) {
19
18
  super(model);
20
19
  }
21
20
 
@@ -1,10 +1,10 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import type { Targets } from 'zod-to-json-schema';
3
3
  import { SchemaCompatLayer, isArr, isNumber, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { SchemaCompatModel } from '../schema-compatibility';
4
+ import type { ModelInformation } from '../schema-compatibility';
5
5
 
6
6
  export class MetaSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: SchemaCompatModel) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10
 
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { ZodTypeAny } from 'zod';
3
3
  import type { Targets } from 'zod-to-json-schema';
4
+ import type { ModelInformation } from '../schema-compatibility';
4
5
  import {
5
6
  SchemaCompatLayer,
6
7
  isArr,
@@ -12,10 +13,8 @@ import {
12
13
  isString,
13
14
  isUnion,
14
15
  } from '../schema-compatibility';
15
- import type { SchemaCompatModel } from '../schema-compatibility';
16
-
17
16
  export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
18
- constructor(model: SchemaCompatModel) {
17
+ constructor(model: ModelInformation) {
19
18
  super(model);
20
19
  }
21
20
 
@@ -26,7 +25,11 @@ export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
26
25
  isReasoningModel(): boolean {
27
26
  // there isn't a good way to automatically detect reasoning models besides doing this.
28
27
  // in the future when o5 is released this compat wont apply and we'll want to come back and update this class + our tests
29
- return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
28
+ return (
29
+ this.getModel().modelId.includes(`o3`) ||
30
+ this.getModel().modelId.includes(`o4`) ||
31
+ this.getModel().modelId.includes(`o1`)
32
+ );
30
33
  }
31
34
 
32
35
  shouldApply(): boolean {
@@ -1,10 +1,10 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import type { Targets } from 'zod-to-json-schema';
3
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { SchemaCompatModel, StringCheckType } from '../schema-compatibility';
4
+ import type { ModelInformation, StringCheckType } from '../schema-compatibility';
5
5
 
6
6
  export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: SchemaCompatModel) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10