@mastra/schema-compat 0.0.0-vector-query-tool-provider-options-20250828222356 → 0.0.0-vnext-20251104230439

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 (68) hide show
  1. package/CHANGELOG.md +70 -1
  2. package/dist/chunk-5WM4A32G.cjs +83 -0
  3. package/dist/chunk-5WM4A32G.cjs.map +1 -0
  4. package/dist/chunk-U2HXWNAF.js +77 -0
  5. package/dist/chunk-U2HXWNAF.js.map +1 -0
  6. package/dist/index.cjs +3652 -122
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +12 -10
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +3652 -123
  11. package/dist/index.js.map +1 -1
  12. package/dist/json-schema.d.ts +4 -0
  13. package/dist/json-schema.d.ts.map +1 -0
  14. package/dist/provider-compats/anthropic.d.ts +2 -2
  15. package/dist/provider-compats/deepseek.d.ts +2 -2
  16. package/dist/provider-compats/google.d.ts +2 -2
  17. package/dist/provider-compats/meta.d.ts +2 -2
  18. package/dist/provider-compats/openai-reasoning.d.ts +2 -2
  19. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  20. package/dist/provider-compats/openai.d.ts +2 -2
  21. package/dist/schema-compatibility-v3.d.ts +5 -37
  22. package/dist/schema-compatibility-v3.d.ts.map +1 -1
  23. package/dist/schema-compatibility-v4.d.ts +5 -37
  24. package/dist/schema-compatibility-v4.d.ts.map +1 -1
  25. package/dist/schema-compatibility.d.ts +6 -38
  26. package/dist/schema-compatibility.d.ts.map +1 -1
  27. package/dist/types.d.ts +1 -0
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/utils-test-suite.d.ts.map +1 -1
  30. package/dist/utils.d.ts +3 -3
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/zod-to-json-test-suite.d.ts +6 -0
  33. package/dist/zod-to-json-test-suite.d.ts.map +1 -0
  34. package/dist/zod-to-json.cjs +2 -2
  35. package/dist/zod-to-json.d.ts +1 -1
  36. package/dist/zod-to-json.d.ts.map +1 -1
  37. package/dist/zod-to-json.js +1 -1
  38. package/package.json +20 -7
  39. package/.turbo/turbo-build.log +0 -4
  40. package/dist/chunk-MKYBUMTK.js +0 -27
  41. package/dist/chunk-MKYBUMTK.js.map +0 -1
  42. package/dist/chunk-V7Y3FXBJ.cjs +0 -33
  43. package/dist/chunk-V7Y3FXBJ.cjs.map +0 -1
  44. package/eslint.config.js +0 -6
  45. package/src/index.ts +0 -40
  46. package/src/provider-compats/anthropic.ts +0 -61
  47. package/src/provider-compats/deepseek.ts +0 -40
  48. package/src/provider-compats/google.ts +0 -49
  49. package/src/provider-compats/meta.ts +0 -41
  50. package/src/provider-compats/openai-reasoning.ts +0 -85
  51. package/src/provider-compats/openai.ts +0 -65
  52. package/src/provider-compats.test.ts +0 -407
  53. package/src/schema-compatibility-v3.ts +0 -664
  54. package/src/schema-compatibility-v4.test.ts +0 -476
  55. package/src/schema-compatibility-v4.ts +0 -706
  56. package/src/schema-compatibility.test.ts +0 -471
  57. package/src/schema-compatibility.ts +0 -471
  58. package/src/types.ts +0 -5
  59. package/src/utils-test-suite.ts +0 -467
  60. package/src/utils-v3.test.ts +0 -9
  61. package/src/utils-v4.test.ts +0 -9
  62. package/src/utils.ts +0 -211
  63. package/src/zod-to-json.ts +0 -28
  64. package/src/zodTypes.ts +0 -56
  65. package/tsconfig.build.json +0 -9
  66. package/tsconfig.json +0 -5
  67. package/tsup.config.ts +0 -22
  68. package/vitest.config.ts +0 -7
@@ -1,471 +0,0 @@
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 {
7
- SchemaCompatLayer as SchemaCompatLayerV3,
8
- ALL_STRING_CHECKS,
9
- ALL_NUMBER_CHECKS,
10
- ALL_ARRAY_CHECKS,
11
- UNSUPPORTED_ZOD_TYPES as UNSUPPORTED_ZOD_TYPES_V3,
12
- SUPPORTED_ZOD_TYPES as SUPPORTED_ZOD_TYPES_V3,
13
- } from './schema-compatibility-v3';
14
- import type {
15
- UnsupportedZodType as UnsupportedZodTypeV3,
16
- ShapeValue as ShapeValueV3,
17
- StringCheckType,
18
- NumberCheckType,
19
- ArrayCheckType,
20
- AllZodType as AllZodTypeV3,
21
- } from './schema-compatibility-v3';
22
- import {
23
- SchemaCompatLayer as SchemaCompatLayerV4,
24
- UNSUPPORTED_ZOD_TYPES as UNSUPPORTED_ZOD_TYPES_V4,
25
- SUPPORTED_ZOD_TYPES as SUPPORTED_ZOD_TYPES_V4,
26
- } from './schema-compatibility-v4';
27
- import type {
28
- UnsupportedZodType as UnsupportedZodTypeV4,
29
- ShapeValue as ShapeValueV4,
30
- AllZodType as AllZodTypeV4,
31
- } from './schema-compatibility-v4';
32
-
33
- // Define constraint types locally since they're not exported from v3/v4 files
34
- type StringConstraints = {
35
- minLength?: number;
36
- maxLength?: number;
37
- email?: boolean;
38
- url?: boolean;
39
- uuid?: boolean;
40
- cuid?: boolean;
41
- emoji?: boolean;
42
- regex?: { pattern: string; flags?: string };
43
- };
44
-
45
- type NumberConstraints = {
46
- gt?: number;
47
- gte?: number;
48
- lt?: number;
49
- lte?: number;
50
- multipleOf?: number;
51
- };
52
-
53
- type ArrayConstraints = {
54
- minLength?: number;
55
- maxLength?: number;
56
- exactLength?: number;
57
- };
58
-
59
- type DateConstraints = {
60
- minDate?: string;
61
- maxDate?: string;
62
- dateFormat?: string;
63
- };
64
- import type { ModelInformation } from './types';
65
- import { convertZodSchemaToAISDKSchema } from './utils';
66
-
67
- export abstract class SchemaCompatLayer {
68
- private model: ModelInformation;
69
- private v3Layer: SchemaCompatLayerV3;
70
- private v4Layer: SchemaCompatLayerV4;
71
-
72
- /**
73
- * Creates a new schema compatibility instance.
74
- *
75
- * @param model - The language model this compatibility layer applies to
76
- */
77
- constructor(model: ModelInformation) {
78
- this.model = model;
79
- this.v3Layer = new SchemaCompatLayerV3(model, this);
80
- this.v4Layer = new SchemaCompatLayerV4(model, this);
81
- }
82
-
83
- /**
84
- * Gets the language model associated with this compatibility layer.
85
- *
86
- * @returns The language model instance
87
- */
88
- getModel(): ModelInformation {
89
- return this.model;
90
- }
91
-
92
- getUnsupportedZodTypes(v: ZodType): readonly string[] {
93
- if ('_zod' in v) {
94
- return this.v4Layer.getUnsupportedZodTypes();
95
- } else {
96
- return this.v3Layer.getUnsupportedZodTypes();
97
- }
98
- }
99
-
100
- /**
101
- * Type guard for optional Zod types
102
- */
103
- isOptional(v: zV4.ZodType): v is zV4.ZodOptional<any>;
104
- isOptional(v: zV3.ZodType): v is zV3.ZodOptional<any>;
105
- isOptional(v: zV3.ZodType | zV4.ZodType) {
106
- if ('_zod' in v) {
107
- // @ts-expect-error - fix later
108
- return this.v4Layer.isOptional(v);
109
- } else {
110
- return this.v3Layer.isOptional(v);
111
- }
112
- }
113
-
114
- /**
115
- * Type guard for object Zod types
116
- */
117
- isObj(v: zV4.ZodType): v is zV4.ZodObject<any, any>;
118
- isObj(v: zV3.ZodType): v is zV3.ZodObject<any, any, any, any, any>;
119
- isObj(v: zV3.ZodType | zV4.ZodType) {
120
- if ('_zod' in v) {
121
- // @ts-expect-error - fix later
122
- return this.v4Layer.isObj(v);
123
- } else {
124
- return this.v3Layer.isObj(v);
125
- }
126
- }
127
-
128
- /**
129
- * Type guard for null Zod types
130
- */
131
- isNull(v: zV4.ZodType): v is zV4.ZodNull;
132
- isNull(v: zV3.ZodType): v is zV3.ZodNull;
133
- isNull(v: zV3.ZodType | zV4.ZodType) {
134
- if ('_zod' in v) {
135
- // @ts-expect-error - fix later
136
- return this.v4Layer.isNull(v);
137
- } else {
138
- return this.v3Layer.isNull(v);
139
- }
140
- }
141
-
142
- /**
143
- * Type guard for array Zod types
144
- */
145
- isArr(v: zV4.ZodType): v is zV4.ZodArray<any>;
146
- isArr(v: zV3.ZodType): v is zV3.ZodArray<any, any>;
147
- isArr(v: zV3.ZodType | zV4.ZodType) {
148
- if ('_zod' in v) {
149
- // @ts-expect-error - fix later
150
- return this.v4Layer.isArr(v);
151
- } else {
152
- return this.v3Layer.isArr(v);
153
- }
154
- }
155
-
156
- /**
157
- * Type guard for union Zod types
158
- */
159
- isUnion(v: zV4.ZodType): v is zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>;
160
- isUnion(v: zV3.ZodType): v is zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>;
161
- isUnion(v: zV3.ZodType | zV4.ZodType) {
162
- if ('_zod' in v) {
163
- // @ts-expect-error - fix later
164
- return this.v4Layer.isUnion(v);
165
- } else {
166
- return this.v3Layer.isUnion(v);
167
- }
168
- }
169
-
170
- /**
171
- * Type guard for string Zod types
172
- */
173
- isString(v: zV4.ZodType): v is zV4.ZodString;
174
- isString(v: zV3.ZodType): v is zV3.ZodString;
175
- isString(v: zV3.ZodType | zV4.ZodType) {
176
- if ('_zod' in v) {
177
- // @ts-expect-error - fix later
178
- return this.v4Layer.isString(v);
179
- } else {
180
- return this.v3Layer.isString(v);
181
- }
182
- }
183
-
184
- /**
185
- * Type guard for number Zod types
186
- */
187
- isNumber(v: zV4.ZodType): v is zV4.ZodNumber;
188
- isNumber(v: zV3.ZodType): v is zV3.ZodNumber;
189
- isNumber(v: zV3.ZodType | zV4.ZodType) {
190
- if ('_zod' in v) {
191
- // @ts-expect-error - fix later
192
- return this.v4Layer.isNumber(v);
193
- } else {
194
- return this.v3Layer.isNumber(v);
195
- }
196
- }
197
-
198
- /**
199
- * Type guard for date Zod types
200
- */
201
- isDate(v: zV4.ZodType): v is zV4.ZodDate;
202
- isDate(v: zV3.ZodType): v is zV3.ZodDate;
203
- isDate(v: zV3.ZodType | zV4.ZodType) {
204
- if ('_zod' in v) {
205
- // @ts-expect-error - fix later
206
- return this.v4Layer.isDate(v);
207
- } else {
208
- return this.v3Layer.isDate(v);
209
- }
210
- }
211
-
212
- /**
213
- * Type guard for default Zod types
214
- */
215
- isDefault(v: zV4.ZodType): v is zV4.ZodDefault<any>;
216
- isDefault(v: zV3.ZodType): v is zV3.ZodDefault<any>;
217
- isDefault(v: zV3.ZodType | zV4.ZodType) {
218
- if ('_zod' in v) {
219
- // @ts-expect-error - fix later
220
- return this.v4Layer.isDefault(v);
221
- } else {
222
- return this.v3Layer.isDefault(v);
223
- }
224
- }
225
-
226
- /**
227
- * Determines whether this compatibility layer should be applied for the current model.
228
- *
229
- * @returns True if this compatibility layer should be used, false otherwise
230
- * @abstract
231
- */
232
- abstract shouldApply(): boolean;
233
-
234
- /**
235
- * Returns the JSON Schema target format for this provider.
236
- *
237
- * @returns The schema target format, or undefined to use the default 'jsonSchema7'
238
- * @abstract
239
- */
240
- abstract getSchemaTarget(): Targets | undefined;
241
-
242
- /**
243
- * Processes a specific Zod type according to the provider's requirements.
244
- *
245
- * @param value - The Zod type to process
246
- * @returns The processed Zod type
247
- * @abstract
248
- */
249
- abstract processZodType(value: zV4.ZodType): zV4.ZodType;
250
- abstract processZodType(value: zV3.ZodType): zV3.ZodType;
251
- abstract processZodType(value: zV4.ZodType | zV3.ZodType): zV4.ZodType | zV3.ZodType;
252
-
253
- /**
254
- * Default handler for Zod object types. Recursively processes all properties in the object.
255
- *
256
- * @param value - The Zod object to process
257
- * @returns The processed Zod object
258
- */
259
- public defaultZodObjectHandler(
260
- value: zV4.ZodObject<any, any>,
261
- options?: { passthrough?: boolean },
262
- ): zV4.ZodObject<any, any>;
263
- public defaultZodObjectHandler(
264
- value: zV3.ZodObject<any, any>,
265
- options?: { passthrough?: boolean },
266
- ): zV3.ZodObject<any, any>;
267
- public defaultZodObjectHandler(
268
- value: zV3.ZodObject<any, any, any, any, any> | zV4.ZodObject<any, any>,
269
- options: { passthrough?: boolean } = { passthrough: true },
270
- ): zV3.ZodObject<any, any, any, any, any> | zV4.ZodObject<any, any> {
271
- if ('_zod' in value) {
272
- return this.v4Layer.defaultZodObjectHandler(value, options);
273
- } else {
274
- return this.v3Layer.defaultZodObjectHandler(value, options);
275
- }
276
- }
277
-
278
- /**
279
- * Merges validation constraints into a parameter description.
280
- *
281
- * This helper method converts validation constraints that may not be supported
282
- * by a provider into human-readable descriptions.
283
- *
284
- * @param description - The existing parameter description
285
- * @param constraints - The validation constraints to merge
286
- * @returns The updated description with constraints, or undefined if no constraints
287
- */
288
- public mergeParameterDescription(
289
- description: string | undefined,
290
- constraints:
291
- | NumberConstraints
292
- | StringConstraints
293
- | ArrayConstraints
294
- | DateConstraints
295
- | { defaultValue?: unknown },
296
- ): string | undefined {
297
- // This method doesn't depend on Zod version, so we can use either layer
298
- return this.v3Layer.mergeParameterDescription(description, constraints);
299
- }
300
-
301
- /**
302
- * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
303
- *
304
- * @param value - The Zod type to check
305
- * @param throwOnTypes - Array of type names to throw errors for
306
- * @returns The original value if not in the throw list
307
- * @throws Error if the type is in the unsupported list
308
- */
309
- public defaultUnsupportedZodTypeHandler<T extends zV4.ZodObject | zV3.AnyZodObject>(
310
- value: T,
311
- throwOnTypes?: T extends zV4.ZodObject
312
- ? UnsupportedZodTypeV4[]
313
- : T extends zV3.AnyZodObject
314
- ? UnsupportedZodTypeV3[]
315
- : never,
316
- ): T extends zV4.ZodObject ? ShapeValueV4<T> : T extends zV3.AnyZodObject ? ShapeValueV3<T> : never {
317
- if ('_zod' in value) {
318
- return this.v4Layer.defaultUnsupportedZodTypeHandler(
319
- // @ts-expect-error - fix later
320
- value,
321
- (throwOnTypes ?? UNSUPPORTED_ZOD_TYPES_V4) as typeof UNSUPPORTED_ZOD_TYPES_V4,
322
- );
323
- } else {
324
- return this.v3Layer.defaultUnsupportedZodTypeHandler(
325
- value,
326
- (throwOnTypes ?? UNSUPPORTED_ZOD_TYPES_V3) as typeof UNSUPPORTED_ZOD_TYPES_V3,
327
- );
328
- }
329
- }
330
-
331
- /**
332
- * Default handler for Zod array types. Processes array constraints according to provider support.
333
- *
334
- * @param value - The Zod array to process
335
- * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
336
- * @returns The processed Zod array
337
- */
338
- public defaultZodArrayHandler(value: zV4.ZodArray<any>, handleChecks?: readonly ArrayCheckType[]): zV4.ZodArray<any>;
339
- public defaultZodArrayHandler(
340
- value: zV3.ZodArray<any, any>,
341
- handleChecks?: readonly ArrayCheckType[],
342
- ): zV3.ZodArray<any, any>;
343
- public defaultZodArrayHandler(
344
- value: zV4.ZodArray<any> | zV3.ZodArray<any, any>,
345
- handleChecks: readonly ArrayCheckType[] = ALL_ARRAY_CHECKS,
346
- ): zV4.ZodArray<any> | zV3.ZodArray<any, any> {
347
- if ('_zod' in value) {
348
- return this.v4Layer.defaultZodArrayHandler(value, handleChecks);
349
- } else {
350
- return this.v3Layer.defaultZodArrayHandler(value, handleChecks);
351
- }
352
- }
353
-
354
- /**
355
- * Default handler for Zod union types. Processes all union options.
356
- *
357
- * @param value - The Zod union to process
358
- * @returns The processed Zod union
359
- * @throws Error if union has fewer than 2 options
360
- */
361
- public defaultZodUnionHandler(value: zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]>): zV4.ZodType;
362
- public defaultZodUnionHandler(value: zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>): zV3.ZodType;
363
- public defaultZodUnionHandler(
364
- value: zV4.ZodUnion<[zV4.ZodType, ...zV4.ZodType[]]> | zV3.ZodUnion<[zV3.ZodType, ...zV3.ZodType[]]>,
365
- ): zV4.ZodType | zV3.ZodType {
366
- if ('_zod' in value) {
367
- // @ts-expect-error - fix later
368
- return this.v4Layer.defaultZodUnionHandler(value);
369
- } else {
370
- return this.v3Layer.defaultZodUnionHandler(value);
371
- }
372
- }
373
-
374
- /**
375
- * Default handler for Zod string types. Processes string validation constraints.
376
- *
377
- * @param value - The Zod string to process
378
- * @param handleChecks - String constraints to convert to descriptions vs keep as validation
379
- * @returns The processed Zod string
380
- */
381
- public defaultZodStringHandler(value: zV4.ZodString, handleChecks?: readonly StringCheckType[]): zV4.ZodString;
382
- public defaultZodStringHandler(value: zV3.ZodString, handleChecks?: readonly StringCheckType[]): zV3.ZodString;
383
- public defaultZodStringHandler(
384
- value: zV4.ZodString | zV3.ZodString,
385
- handleChecks: readonly StringCheckType[] = ALL_STRING_CHECKS,
386
- ): zV4.ZodString | zV3.ZodString {
387
- if ('_zod' in value) {
388
- return this.v4Layer.defaultZodStringHandler(value);
389
- } else {
390
- return this.v3Layer.defaultZodStringHandler(value, handleChecks);
391
- }
392
- }
393
-
394
- /**
395
- * Default handler for Zod number types. Processes number validation constraints.
396
- *
397
- * @param value - The Zod number to process
398
- * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
399
- * @returns The processed Zod number
400
- */
401
- public defaultZodNumberHandler(value: zV4.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV4.ZodNumber;
402
- public defaultZodNumberHandler(value: zV3.ZodNumber, handleChecks?: readonly NumberCheckType[]): zV3.ZodNumber;
403
- public defaultZodNumberHandler(
404
- value: zV4.ZodNumber | zV3.ZodNumber,
405
- handleChecks: readonly NumberCheckType[] = ALL_NUMBER_CHECKS,
406
- ): zV4.ZodNumber | zV3.ZodNumber {
407
- if ('_zod' in value) {
408
- return this.v4Layer.defaultZodNumberHandler(value);
409
- } else {
410
- return this.v3Layer.defaultZodNumberHandler(value, handleChecks);
411
- }
412
- }
413
-
414
- /**
415
- * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
416
- *
417
- * @param value - The Zod date to process
418
- * @returns A Zod string schema representing the date in ISO format
419
- */
420
- public defaultZodDateHandler(value: zV4.ZodDate): zV4.ZodString;
421
- public defaultZodDateHandler(value: zV3.ZodDate): zV3.ZodString;
422
- public defaultZodDateHandler(value: zV4.ZodDate | zV3.ZodDate): zV4.ZodString | zV3.ZodString {
423
- if ('_zod' in value) {
424
- return this.v4Layer.defaultZodDateHandler(value);
425
- } else {
426
- return this.v3Layer.defaultZodDateHandler(value);
427
- }
428
- }
429
-
430
- /**
431
- * Default handler for Zod optional types. Processes the inner type and maintains optionality.
432
- *
433
- * @param value - The Zod optional to process
434
- * @param handleTypes - Types that should be processed vs passed through
435
- * @returns The processed Zod optional
436
- */
437
- public defaultZodOptionalHandler(value: zV4.ZodOptional<any>, handleTypes?: readonly AllZodTypeV4[]): zV4.ZodType;
438
- public defaultZodOptionalHandler(value: zV3.ZodOptional<any>, handleTypes?: readonly AllZodTypeV3[]): zV3.ZodType;
439
- public defaultZodOptionalHandler(
440
- value: zV4.ZodOptional<any> | zV3.ZodOptional<any>,
441
- handleTypes?: readonly AllZodTypeV3[] | readonly AllZodTypeV4[],
442
- ): zV4.ZodType | zV3.ZodType {
443
- if ('_zod' in value) {
444
- return this.v4Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES_V4);
445
- } else {
446
- return this.v3Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES_V3);
447
- }
448
- }
449
-
450
- /**
451
- * Processes a Zod object schema and converts it to an AI SDK Schema.
452
- *
453
- * @param zodSchema - The Zod object schema to process
454
- * @returns An AI SDK Schema with provider-specific compatibility applied
455
- */
456
- public processToAISDKSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): Schema {
457
- const processedSchema = this.processZodType(zodSchema);
458
-
459
- return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
460
- }
461
-
462
- /**
463
- * Processes a Zod object schema and converts it to a JSON Schema.
464
- *
465
- * @param zodSchema - The Zod object schema to process
466
- * @returns A JSONSchema7 object with provider-specific compatibility applied
467
- */
468
- public processToJSONSchema(zodSchema: zV3.ZodSchema | zV4.ZodType): JSONSchema7 {
469
- return this.processToAISDKSchema(zodSchema).jsonSchema;
470
- }
471
- }
package/src/types.ts DELETED
@@ -1,5 +0,0 @@
1
- export type ModelInformation = {
2
- modelId: string;
3
- provider: string;
4
- supportsStructuredOutputs: boolean;
5
- };