@mastra/schema-compat 0.0.0-fix-fetching-workflow-snapshots-20250625000954 → 0.0.0-fix-message-list-args-missing-20250807205055

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 (42) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +51 -1
  3. package/LICENSE.md +11 -42
  4. package/dist/index.cjs +8 -5
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.ts +9 -31
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +9 -6
  9. package/dist/index.js.map +1 -0
  10. package/dist/provider-compats/anthropic.d.ts +11 -0
  11. package/dist/provider-compats/anthropic.d.ts.map +1 -0
  12. package/dist/provider-compats/deepseek.d.ts +11 -0
  13. package/dist/provider-compats/deepseek.d.ts.map +1 -0
  14. package/dist/provider-compats/google.d.ts +11 -0
  15. package/dist/provider-compats/google.d.ts.map +1 -0
  16. package/dist/provider-compats/meta.d.ts +11 -0
  17. package/dist/provider-compats/meta.d.ts.map +1 -0
  18. package/dist/provider-compats/openai-reasoning.d.ts +12 -0
  19. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
  20. package/dist/provider-compats/openai.d.ts +11 -0
  21. package/dist/provider-compats/openai.d.ts.map +1 -0
  22. package/dist/schema-compatibility.d.ts +285 -0
  23. package/dist/schema-compatibility.d.ts.map +1 -0
  24. package/dist/utils.d.ts +84 -0
  25. package/dist/utils.d.ts.map +1 -0
  26. package/package.json +9 -8
  27. package/src/provider-compats/anthropic.ts +2 -3
  28. package/src/provider-compats/deepseek.ts +2 -2
  29. package/src/provider-compats/google.ts +10 -2
  30. package/src/provider-compats/meta.ts +2 -2
  31. package/src/provider-compats/openai-reasoning.ts +7 -3
  32. package/src/provider-compats/openai.ts +2 -3
  33. package/src/provider-compats.test.ts +120 -25
  34. package/src/schema-compatibility.test.ts +22 -6
  35. package/src/schema-compatibility.ts +14 -7
  36. package/src/utils.test.ts +32 -6
  37. package/tsconfig.build.json +9 -0
  38. package/tsconfig.json +1 -1
  39. package/tsup.config.ts +17 -0
  40. package/dist/_tsup-dts-rollup.d.cts +0 -504
  41. package/dist/_tsup-dts-rollup.d.ts +0 -504
  42. package/dist/index.d.cts +0 -31
@@ -0,0 +1,11 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ import type { Targets } from 'zod-to-json-schema';
3
+ import type { ModelInformation } from '../schema-compatibility.js';
4
+ import { SchemaCompatLayer } from '../schema-compatibility.js';
5
+ export declare class GoogleSchemaCompatLayer extends SchemaCompatLayer {
6
+ constructor(model: ModelInformation);
7
+ getSchemaTarget(): Targets | undefined;
8
+ shouldApply(): boolean;
9
+ processZodType(value: ZodTypeAny): ZodTypeAny;
10
+ }
11
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/provider-compats/google.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,iBAAiB,EASlB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,uBAAwB,SAAQ,iBAAiB;gBAChD,KAAK,EAAE,gBAAgB;IAInC,eAAe,IAAI,OAAO,GAAG,SAAS;IAItC,WAAW,IAAI,OAAO;IAItB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CAiC9C"}
@@ -0,0 +1,11 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ import type { Targets } from 'zod-to-json-schema';
3
+ import { SchemaCompatLayer } from '../schema-compatibility.js';
4
+ import type { ModelInformation } from '../schema-compatibility.js';
5
+ export declare class MetaSchemaCompatLayer extends SchemaCompatLayer {
6
+ constructor(model: ModelInformation);
7
+ getSchemaTarget(): Targets | undefined;
8
+ shouldApply(): boolean;
9
+ processZodType(value: ZodTypeAny): ZodTypeAny;
10
+ }
11
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/provider-compats/meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAyD,MAAM,yBAAyB,CAAC;AACnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,qBAAa,qBAAsB,SAAQ,iBAAiB;gBAC9C,KAAK,EAAE,gBAAgB;IAInC,eAAe,IAAI,OAAO,GAAG,SAAS;IAItC,WAAW,IAAI,OAAO;IAItB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CAiB9C"}
@@ -0,0 +1,12 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ import type { Targets } from 'zod-to-json-schema';
3
+ import type { ModelInformation } from '../schema-compatibility.js';
4
+ import { SchemaCompatLayer } from '../schema-compatibility.js';
5
+ export declare class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
6
+ constructor(model: ModelInformation);
7
+ getSchemaTarget(): Targets | undefined;
8
+ isReasoningModel(): boolean;
9
+ shouldApply(): boolean;
10
+ processZodType(value: ZodTypeAny): ZodTypeAny;
11
+ }
12
+ //# sourceMappingURL=openai-reasoning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-reasoning.d.ts","sourceRoot":"","sources":["../../src/provider-compats/openai-reasoning.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,iBAAiB,EASlB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,gCAAiC,SAAQ,iBAAiB;gBACzD,KAAK,EAAE,gBAAgB;IAInC,eAAe,IAAI,OAAO,GAAG,SAAS;IAItC,gBAAgB,IAAI,OAAO;IAU3B,WAAW,IAAI,OAAO;IAWtB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CA4C9C"}
@@ -0,0 +1,11 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ import type { Targets } from 'zod-to-json-schema';
3
+ import { SchemaCompatLayer } from '../schema-compatibility.js';
4
+ import type { ModelInformation } from '../schema-compatibility.js';
5
+ export declare class OpenAISchemaCompatLayer extends SchemaCompatLayer {
6
+ constructor(model: ModelInformation);
7
+ getSchemaTarget(): Targets | undefined;
8
+ shouldApply(): boolean;
9
+ processZodType(value: ZodTypeAny): ZodTypeAny;
10
+ }
11
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/provider-compats/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAA+C,MAAM,yBAAyB,CAAC;AACzG,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,yBAAyB,CAAC;AAEjF,qBAAa,uBAAwB,SAAQ,iBAAiB;gBAChD,KAAK,EAAE,gBAAgB;IAInC,eAAe,IAAI,OAAO,GAAG,SAAS;IAItC,WAAW,IAAI,OAAO;IAWtB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CA6B9C"}
@@ -0,0 +1,285 @@
1
+ import type { Schema } 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
+ /**
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
+ export type ModelInformation = {
112
+ modelId: string;
113
+ provider: string;
114
+ supportsStructuredOutputs: boolean;
115
+ };
116
+ /**
117
+ * Abstract base class for creating schema compatibility layers for different AI model providers.
118
+ *
119
+ * This class provides a framework for transforming Zod schemas to work with specific AI model
120
+ * provider requirements and limitations. Each provider may have different support levels for
121
+ * JSON Schema features, validation constraints, and data types.
122
+ *
123
+ * @abstract
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * import { SchemaCompatLayer } from '@mastra/schema-compat';
128
+ * import type { LanguageModelV1 } from 'ai';
129
+ *
130
+ * class CustomProviderCompat extends SchemaCompatLayer {
131
+ * constructor(model: LanguageModelV1) {
132
+ * super(model);
133
+ * }
134
+ *
135
+ * shouldApply(): boolean {
136
+ * return this.getModel().provider === 'custom-provider';
137
+ * }
138
+ *
139
+ * getSchemaTarget() {
140
+ * return 'jsonSchema7';
141
+ * }
142
+ *
143
+ * processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
144
+ * // Custom processing logic for this provider
145
+ * switch (value._def.typeName) {
146
+ * case 'ZodString':
147
+ * return this.defaultZodStringHandler(value, ['email', 'url']);
148
+ * default:
149
+ * return this.defaultUnsupportedZodTypeHandler(value);
150
+ * }
151
+ * }
152
+ * }
153
+ * ```
154
+ */
155
+ export declare abstract class SchemaCompatLayer {
156
+ private model;
157
+ /**
158
+ * Creates a new schema compatibility instance.
159
+ *
160
+ * @param model - The language model this compatibility layer applies to
161
+ */
162
+ constructor(model: ModelInformation);
163
+ /**
164
+ * Gets the language model associated with this compatibility layer.
165
+ *
166
+ * @returns The language model instance
167
+ */
168
+ getModel(): ModelInformation;
169
+ /**
170
+ * Determines whether this compatibility layer should be applied for the current model.
171
+ *
172
+ * @returns True if this compatibility layer should be used, false otherwise
173
+ * @abstract
174
+ */
175
+ abstract shouldApply(): boolean;
176
+ /**
177
+ * Returns the JSON Schema target format for this provider.
178
+ *
179
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
180
+ * @abstract
181
+ */
182
+ abstract getSchemaTarget(): Targets | undefined;
183
+ /**
184
+ * Processes a specific Zod type according to the provider's requirements.
185
+ *
186
+ * @param value - The Zod type to process
187
+ * @returns The processed Zod type
188
+ * @abstract
189
+ */
190
+ abstract processZodType(value: ZodTypeAny): ZodTypeAny;
191
+ /**
192
+ * Default handler for Zod object types. Recursively processes all properties in the object.
193
+ *
194
+ * @param value - The Zod object to process
195
+ * @returns The processed Zod object
196
+ */
197
+ defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
198
+ passthrough?: boolean;
199
+ }): ZodObject<any, any, any>;
200
+ /**
201
+ * Merges validation constraints into a parameter description.
202
+ *
203
+ * This helper method converts validation constraints that may not be supported
204
+ * by a provider into human-readable descriptions.
205
+ *
206
+ * @param description - The existing parameter description
207
+ * @param constraints - The validation constraints to merge
208
+ * @returns The updated description with constraints, or undefined if no constraints
209
+ */
210
+ mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
211
+ defaultValue?: unknown;
212
+ }): string | undefined;
213
+ /**
214
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
215
+ *
216
+ * @param value - The Zod type to check
217
+ * @param throwOnTypes - Array of type names to throw errors for
218
+ * @returns The original value if not in the throw list
219
+ * @throws Error if the type is in the unsupported list
220
+ */
221
+ defaultUnsupportedZodTypeHandler<T extends z.AnyZodObject>(value: z.ZodTypeAny, throwOnTypes?: readonly UnsupportedZodType[]): ShapeValue<T>;
222
+ /**
223
+ * Default handler for Zod array types. Processes array constraints according to provider support.
224
+ *
225
+ * @param value - The Zod array to process
226
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
227
+ * @returns The processed Zod array
228
+ */
229
+ defaultZodArrayHandler(value: ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): ZodArray<any, any>;
230
+ /**
231
+ * Default handler for Zod union types. Processes all union options.
232
+ *
233
+ * @param value - The Zod union to process
234
+ * @returns The processed Zod union
235
+ * @throws Error if union has fewer than 2 options
236
+ */
237
+ defaultZodUnionHandler(value: ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>): ZodTypeAny;
238
+ /**
239
+ * Default handler for Zod string types. Processes string validation constraints.
240
+ *
241
+ * @param value - The Zod string to process
242
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
243
+ * @returns The processed Zod string
244
+ */
245
+ defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
246
+ /**
247
+ * Default handler for Zod number types. Processes number validation constraints.
248
+ *
249
+ * @param value - The Zod number to process
250
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
251
+ * @returns The processed Zod number
252
+ */
253
+ defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
254
+ /**
255
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
256
+ *
257
+ * @param value - The Zod date to process
258
+ * @returns A Zod string schema representing the date in ISO format
259
+ */
260
+ defaultZodDateHandler(value: ZodDate): ZodString;
261
+ /**
262
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
263
+ *
264
+ * @param value - The Zod optional to process
265
+ * @param handleTypes - Types that should be processed vs passed through
266
+ * @returns The processed Zod optional
267
+ */
268
+ defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly AllZodType[]): ZodTypeAny;
269
+ /**
270
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
271
+ *
272
+ * @param zodSchema - The Zod object schema to process
273
+ * @returns An AI SDK Schema with provider-specific compatibility applied
274
+ */
275
+ processToAISDKSchema(zodSchema: z.ZodSchema): Schema;
276
+ /**
277
+ * Processes a Zod object schema and converts it to a JSON Schema.
278
+ *
279
+ * @param zodSchema - The Zod object schema to process
280
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
281
+ */
282
+ processToJSONSchema(zodSchema: z.ZodSchema): JSONSchema7;
283
+ }
284
+ export {};
285
+ //# 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,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;;;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,MAAM,KAAK,GAAI,GAAG,UAAU,KAAG,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAA2B,CAAC;AAC9F,eAAO,MAAM,MAAM,GAAI,GAAG,UAAU,KAAG,CAAC,IAAI,OAA+B,CAAC;AAC5E,eAAO,MAAM,KAAK,GAAI,GAAG,UAAU,KAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAA0B,CAAC;AACvF,eAAO,MAAM,OAAO,GAAI,GAAG,UAAU,KAAG,CAAC,I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AC;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;IA6DZ;;;;;;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-fix-fetching-workflow-snapshots-20250625000954",
3
+ "version": "0.0.0-fix-message-list-args-missing-20250807205055",
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
  },
@@ -26,7 +26,7 @@
26
26
  "zod"
27
27
  ],
28
28
  "author": "",
29
- "license": "Elastic-2.0",
29
+ "license": "Apache-2.0",
30
30
  "dependencies": {
31
31
  "json-schema": "^0.4.0",
32
32
  "zod-from-json-schema": "^0.0.5",
@@ -40,16 +40,17 @@
40
40
  "@types/json-schema": "^7.0.15",
41
41
  "@types/node": "^20.19.0",
42
42
  "ai": "4.3.16",
43
- "eslint": "^9.29.0",
43
+ "eslint": "^9.30.1",
44
44
  "tsup": "^8.5.0",
45
45
  "typescript": "^5.8.3",
46
- "vitest": "^3.2.3",
46
+ "vitest": "^3.2.4",
47
47
  "zod": "^3.25.67",
48
- "@internal/lint": "0.0.0-fix-fetching-workflow-snapshots-20250625000954"
48
+ "@internal/lint": "0.0.0-fix-message-list-args-missing-20250807205055",
49
+ "@internal/types-builder": "0.0.0-fix-message-list-args-missing-20250807205055"
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,11 +1,10 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import type { ZodTypeAny } from 'zod';
3
2
  import type { Targets } from 'zod-to-json-schema';
4
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
5
- import type { AllZodType } from '../schema-compatibility';
4
+ import type { AllZodType, ModelInformation } from '../schema-compatibility';
6
5
 
7
6
  export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
8
- constructor(model: LanguageModelV1) {
7
+ constructor(model: ModelInformation) {
9
8
  super(model);
10
9
  }
11
10
 
@@ -1,10 +1,10 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import type { ZodTypeAny } from 'zod';
3
2
  import type { Targets } from 'zod-to-json-schema';
4
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
+ import type { ModelInformation } from '../schema-compatibility';
5
5
 
6
6
  export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: LanguageModelV1) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10
 
@@ -1,10 +1,12 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import type { ZodTypeAny } from 'zod';
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,
7
8
  isArr,
9
+ isNull,
8
10
  isNumber,
9
11
  isObj,
10
12
  isOptional,
@@ -13,7 +15,7 @@ import {
13
15
  } from '../schema-compatibility';
14
16
 
15
17
  export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
16
- constructor(model: LanguageModelV1) {
18
+ constructor(model: ModelInformation) {
17
19
  super(model);
18
20
  }
19
21
 
@@ -35,6 +37,12 @@ export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
35
37
  'ZodNumber',
36
38
  ...UNSUPPORTED_ZOD_TYPES,
37
39
  ]);
40
+ } else if (isNull(value)) {
41
+ // Google models don't support null, so we need to convert it to any and then refine it to null
42
+ return z
43
+ .any()
44
+ .refine(v => v === null, { message: 'must be null' })
45
+ .describe(value._def.description || 'must be null');
38
46
  } else if (isObj(value)) {
39
47
  return this.defaultZodObjectHandler(value);
40
48
  } else if (isArr(value)) {
@@ -1,10 +1,10 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import type { ZodTypeAny } from 'zod';
3
2
  import type { Targets } from 'zod-to-json-schema';
4
3
  import { SchemaCompatLayer, isArr, isNumber, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
+ import type { ModelInformation } from '../schema-compatibility';
5
5
 
6
6
  export class MetaSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: LanguageModelV1) {
7
+ constructor(model: ModelInformation) {
8
8
  super(model);
9
9
  }
10
10
 
@@ -1,7 +1,7 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import { z } from 'zod';
3
2
  import type { ZodTypeAny } from 'zod';
4
3
  import type { Targets } from 'zod-to-json-schema';
4
+ import type { ModelInformation } from '../schema-compatibility';
5
5
  import {
6
6
  SchemaCompatLayer,
7
7
  isArr,
@@ -15,7 +15,7 @@ import {
15
15
  } from '../schema-compatibility';
16
16
 
17
17
  export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
18
- constructor(model: LanguageModelV1) {
18
+ constructor(model: ModelInformation) {
19
19
  super(model);
20
20
  }
21
21
 
@@ -26,7 +26,11 @@ export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
26
26
  isReasoningModel(): boolean {
27
27
  // there isn't a good way to automatically detect reasoning models besides doing this.
28
28
  // 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`);
29
+ return (
30
+ this.getModel().modelId.includes(`o3`) ||
31
+ this.getModel().modelId.includes(`o4`) ||
32
+ this.getModel().modelId.includes(`o1`)
33
+ );
30
34
  }
31
35
 
32
36
  shouldApply(): boolean {
@@ -1,11 +1,10 @@
1
- import type { LanguageModelV1 } from 'ai';
2
1
  import type { ZodTypeAny } from 'zod';
3
2
  import type { Targets } from 'zod-to-json-schema';
4
3
  import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
5
- import type { StringCheckType } from '../schema-compatibility';
4
+ import type { ModelInformation, StringCheckType } from '../schema-compatibility';
6
5
 
7
6
  export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
8
- constructor(model: LanguageModelV1) {
7
+ constructor(model: ModelInformation) {
9
8
  super(model);
10
9
  }
11
10