@mastra/schema-compat 0.0.0-fix-message-list-args-missing-20250807205055 → 0.0.0-fix-zod-to-json-schema-ref-strategy-20250910193441

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 (63) hide show
  1. package/CHANGELOG.md +89 -1
  2. package/README.md +0 -4
  3. package/dist/chunk-7YUR5KZ5.cjs +34 -0
  4. package/dist/chunk-7YUR5KZ5.cjs.map +1 -0
  5. package/dist/chunk-GWTUXMDD.js +28 -0
  6. package/dist/chunk-GWTUXMDD.js.map +1 -0
  7. package/dist/index.cjs +842 -83
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +10 -8
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +841 -84
  12. package/dist/index.js.map +1 -1
  13. package/dist/provider-compats/anthropic.d.ts +6 -4
  14. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  15. package/dist/provider-compats/deepseek.d.ts +6 -4
  16. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  17. package/dist/provider-compats/google.d.ts +6 -4
  18. package/dist/provider-compats/google.d.ts.map +1 -1
  19. package/dist/provider-compats/meta.d.ts +6 -4
  20. package/dist/provider-compats/meta.d.ts.map +1 -1
  21. package/dist/provider-compats/openai-reasoning.d.ts +6 -4
  22. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  23. package/dist/provider-compats/openai.d.ts +6 -4
  24. package/dist/provider-compats/openai.d.ts.map +1 -1
  25. package/dist/schema-compatibility-v3.d.ts +319 -0
  26. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  27. package/dist/schema-compatibility-v4.d.ts +310 -0
  28. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  29. package/dist/schema-compatibility.d.ts +76 -133
  30. package/dist/schema-compatibility.d.ts.map +1 -1
  31. package/dist/types.d.ts +6 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/dist/utils-test-suite.d.ts +2 -0
  34. package/dist/utils-test-suite.d.ts.map +1 -0
  35. package/dist/utils.d.ts +17 -5
  36. package/dist/utils.d.ts.map +1 -1
  37. package/dist/zod-to-json.cjs +12 -0
  38. package/dist/zod-to-json.cjs.map +1 -0
  39. package/dist/zod-to-json.d.ts +6 -0
  40. package/dist/zod-to-json.d.ts.map +1 -0
  41. package/dist/zod-to-json.js +3 -0
  42. package/dist/zod-to-json.js.map +1 -0
  43. package/dist/zodTypes.d.ts +21 -0
  44. package/dist/zodTypes.d.ts.map +1 -0
  45. package/package.json +31 -8
  46. package/.turbo/turbo-build.log +0 -4
  47. package/eslint.config.js +0 -6
  48. package/src/index.ts +0 -39
  49. package/src/provider-compats/anthropic.ts +0 -43
  50. package/src/provider-compats/deepseek.ts +0 -35
  51. package/src/provider-compats/google.ts +0 -63
  52. package/src/provider-compats/meta.ts +0 -36
  53. package/src/provider-compats/openai-reasoning.ts +0 -91
  54. package/src/provider-compats/openai.ts +0 -55
  55. package/src/provider-compats.test.ts +0 -407
  56. package/src/schema-compatibility.test.ts +0 -487
  57. package/src/schema-compatibility.ts +0 -594
  58. package/src/utils.test.ts +0 -460
  59. package/src/utils.ts +0 -205
  60. package/tsconfig.build.json +0 -9
  61. package/tsconfig.json +0 -5
  62. package/tsup.config.ts +0 -17
  63. package/vitest.config.ts +0 -7
@@ -1,43 +0,0 @@
1
- import type { ZodTypeAny } from 'zod';
2
- import type { Targets } from 'zod-to-json-schema';
3
- import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { AllZodType, ModelInformation } from '../schema-compatibility';
5
-
6
- export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: ModelInformation) {
8
- super(model);
9
- }
10
-
11
- getSchemaTarget(): Targets | undefined {
12
- return 'jsonSchema7';
13
- }
14
-
15
- shouldApply(): boolean {
16
- return this.getModel().modelId.includes('claude');
17
- }
18
-
19
- processZodType(value: ZodTypeAny): ZodTypeAny {
20
- if (isOptional(value)) {
21
- const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined', 'ZodTuple'];
22
- if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
23
- return this.defaultZodOptionalHandler(value, handleTypes);
24
- } else if (isObj(value)) {
25
- return this.defaultZodObjectHandler(value);
26
- } else if (isArr(value)) {
27
- return this.defaultZodArrayHandler(value, []);
28
- } else if (isUnion(value)) {
29
- return this.defaultZodUnionHandler(value);
30
- } else if (isString(value)) {
31
- // the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
32
- // added to the tool description
33
-
34
- if (this.getModel().modelId.includes('claude-3.5-haiku')) {
35
- return this.defaultZodStringHandler(value, ['max', 'min']);
36
- } else {
37
- return value;
38
- }
39
- }
40
-
41
- return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
42
- }
43
- }
@@ -1,35 +0,0 @@
1
- import type { ZodTypeAny } from 'zod';
2
- import type { Targets } from 'zod-to-json-schema';
3
- import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { ModelInformation } from '../schema-compatibility';
5
-
6
- export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: ModelInformation) {
8
- super(model);
9
- }
10
-
11
- getSchemaTarget(): Targets | undefined {
12
- return 'jsonSchema7';
13
- }
14
-
15
- shouldApply(): boolean {
16
- // Deepseek R1 performs perfectly without this compat layer
17
- return this.getModel().modelId.includes('deepseek') && !this.getModel().modelId.includes('r1');
18
- }
19
-
20
- processZodType(value: ZodTypeAny): ZodTypeAny {
21
- if (isOptional(value)) {
22
- return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
23
- } else if (isObj(value)) {
24
- return this.defaultZodObjectHandler(value);
25
- } else if (isArr(value)) {
26
- return this.defaultZodArrayHandler(value, ['min', 'max']);
27
- } else if (isUnion(value)) {
28
- return this.defaultZodUnionHandler(value);
29
- } else if (isString(value)) {
30
- return this.defaultZodStringHandler(value);
31
- }
32
-
33
- return value;
34
- }
35
- }
@@ -1,63 +0,0 @@
1
- import type { ZodTypeAny } from 'zod';
2
- import { z } from 'zod';
3
- import type { Targets } from 'zod-to-json-schema';
4
- import type { ModelInformation } from '../schema-compatibility';
5
- import {
6
- SchemaCompatLayer,
7
- UNSUPPORTED_ZOD_TYPES,
8
- isArr,
9
- isNull,
10
- isNumber,
11
- isObj,
12
- isOptional,
13
- isString,
14
- isUnion,
15
- } from '../schema-compatibility';
16
-
17
- export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
18
- constructor(model: ModelInformation) {
19
- super(model);
20
- }
21
-
22
- getSchemaTarget(): Targets | undefined {
23
- return 'jsonSchema7';
24
- }
25
-
26
- shouldApply(): boolean {
27
- return this.getModel().provider.includes('google') || this.getModel().modelId.includes('google');
28
- }
29
-
30
- processZodType(value: ZodTypeAny): ZodTypeAny {
31
- if (isOptional(value)) {
32
- return this.defaultZodOptionalHandler(value, [
33
- 'ZodObject',
34
- 'ZodArray',
35
- 'ZodUnion',
36
- 'ZodString',
37
- 'ZodNumber',
38
- ...UNSUPPORTED_ZOD_TYPES,
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');
46
- } else if (isObj(value)) {
47
- return this.defaultZodObjectHandler(value);
48
- } else if (isArr(value)) {
49
- return this.defaultZodArrayHandler(value, []);
50
- } else if (isUnion(value)) {
51
- return this.defaultZodUnionHandler(value);
52
- } else if (isString(value)) {
53
- // Google models support these properties but the model doesn't respect them, but it respects them when they're
54
- // added to the tool description
55
- return this.defaultZodStringHandler(value);
56
- } else if (isNumber(value)) {
57
- // Google models support these properties but the model doesn't respect them, but it respects them when they're
58
- // added to the tool description
59
- return this.defaultZodNumberHandler(value);
60
- }
61
- return this.defaultUnsupportedZodTypeHandler(value);
62
- }
63
- }
@@ -1,36 +0,0 @@
1
- import type { ZodTypeAny } from 'zod';
2
- import type { Targets } from 'zod-to-json-schema';
3
- import { SchemaCompatLayer, isArr, isNumber, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { ModelInformation } from '../schema-compatibility';
5
-
6
- export class MetaSchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: ModelInformation) {
8
- super(model);
9
- }
10
-
11
- getSchemaTarget(): Targets | undefined {
12
- return 'jsonSchema7';
13
- }
14
-
15
- shouldApply(): boolean {
16
- return this.getModel().modelId.includes('meta');
17
- }
18
-
19
- processZodType(value: ZodTypeAny): ZodTypeAny {
20
- if (isOptional(value)) {
21
- return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
22
- } else if (isObj(value)) {
23
- return this.defaultZodObjectHandler(value);
24
- } else if (isArr(value)) {
25
- return this.defaultZodArrayHandler(value, ['min', 'max']);
26
- } else if (isUnion(value)) {
27
- return this.defaultZodUnionHandler(value);
28
- } else if (isNumber(value)) {
29
- return this.defaultZodNumberHandler(value);
30
- } else if (isString(value)) {
31
- return this.defaultZodStringHandler(value);
32
- }
33
-
34
- return value;
35
- }
36
- }
@@ -1,91 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodTypeAny } from 'zod';
3
- import type { Targets } from 'zod-to-json-schema';
4
- import type { ModelInformation } from '../schema-compatibility';
5
- import {
6
- SchemaCompatLayer,
7
- isArr,
8
- isDate,
9
- isDefault,
10
- isNumber,
11
- isObj,
12
- isOptional,
13
- isString,
14
- isUnion,
15
- } from '../schema-compatibility';
16
-
17
- export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
18
- constructor(model: ModelInformation) {
19
- super(model);
20
- }
21
-
22
- getSchemaTarget(): Targets | undefined {
23
- return `openApi3`;
24
- }
25
-
26
- isReasoningModel(): boolean {
27
- // there isn't a good way to automatically detect reasoning models besides doing this.
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 (
30
- this.getModel().modelId.includes(`o3`) ||
31
- this.getModel().modelId.includes(`o4`) ||
32
- this.getModel().modelId.includes(`o1`)
33
- );
34
- }
35
-
36
- shouldApply(): boolean {
37
- if (
38
- (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) &&
39
- (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
40
- ) {
41
- return true;
42
- }
43
-
44
- return false;
45
- }
46
-
47
- processZodType(value: ZodTypeAny): ZodTypeAny {
48
- if (isOptional(value)) {
49
- const innerZodType = this.processZodType(value._def.innerType);
50
- return innerZodType.nullable();
51
- } else if (isObj(value)) {
52
- return this.defaultZodObjectHandler(value, { passthrough: false });
53
- } else if (isArr(value)) {
54
- return this.defaultZodArrayHandler(value);
55
- } else if (isUnion(value)) {
56
- return this.defaultZodUnionHandler(value);
57
- } else if (isDefault(value)) {
58
- const defaultDef = value._def;
59
- const innerType = defaultDef.innerType;
60
- const defaultValue = defaultDef.defaultValue();
61
- const constraints: { defaultValue?: unknown } = {};
62
- if (defaultValue !== undefined) {
63
- constraints.defaultValue = defaultValue;
64
- }
65
-
66
- const description = this.mergeParameterDescription(value.description, constraints);
67
- let result = this.processZodType(innerType);
68
- if (description) {
69
- result = result.describe(description);
70
- }
71
- return result;
72
- } else if (isNumber(value)) {
73
- return this.defaultZodNumberHandler(value);
74
- } else if (isString(value)) {
75
- return this.defaultZodStringHandler(value);
76
- } else if (isDate(value)) {
77
- return this.defaultZodDateHandler(value);
78
- } else if (value._def.typeName === 'ZodAny') {
79
- // It's bad practice in the tool to use any, it's not reasonable for models that don't support that OOTB, to cast every single possible type
80
- // in the schema. Usually when it's "any" it could be a json object or a union of specific types.
81
- return z
82
- .string()
83
- .describe(
84
- (value.description ?? '') +
85
- `\nArgument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`,
86
- );
87
- }
88
-
89
- return this.defaultUnsupportedZodTypeHandler(value);
90
- }
91
- }
@@ -1,55 +0,0 @@
1
- import type { ZodTypeAny } from 'zod';
2
- import type { Targets } from 'zod-to-json-schema';
3
- import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
4
- import type { ModelInformation, StringCheckType } from '../schema-compatibility';
5
-
6
- export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
7
- constructor(model: ModelInformation) {
8
- super(model);
9
- }
10
-
11
- getSchemaTarget(): Targets | undefined {
12
- return `jsonSchema7`;
13
- }
14
-
15
- shouldApply(): boolean {
16
- if (
17
- !this.getModel().supportsStructuredOutputs &&
18
- (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
19
- ) {
20
- return true;
21
- }
22
-
23
- return false;
24
- }
25
-
26
- processZodType(value: ZodTypeAny): ZodTypeAny {
27
- if (isOptional(value)) {
28
- return this.defaultZodOptionalHandler(value, [
29
- 'ZodObject',
30
- 'ZodArray',
31
- 'ZodUnion',
32
- 'ZodString',
33
- 'ZodNever',
34
- 'ZodUndefined',
35
- 'ZodTuple',
36
- ]);
37
- } else if (isObj(value)) {
38
- return this.defaultZodObjectHandler(value);
39
- } else if (isUnion(value)) {
40
- return this.defaultZodUnionHandler(value);
41
- } else if (isArr(value)) {
42
- return this.defaultZodArrayHandler(value);
43
- } else if (isString(value)) {
44
- const model = this.getModel();
45
- const checks: StringCheckType[] = ['emoji'];
46
-
47
- if (model.modelId.includes('gpt-4o-mini')) {
48
- checks.push('regex');
49
- }
50
- return this.defaultZodStringHandler(value, checks);
51
- }
52
-
53
- return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodUndefined', 'ZodTuple']);
54
- }
55
- }