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