@mastra/schema-compat 0.11.2-alpha.1 → 0.11.2-alpha.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mastra/schema-compat
2
2
 
3
+ ## 0.11.2-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
8
+
3
9
  ## 0.11.2-alpha.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@mastra/schema-compat",
3
- "version": "0.11.2-alpha.1",
3
+ "version": "0.11.2-alpha.2",
4
4
  "description": "Tool schema compatibility layer for Mastra.ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md"
11
+ ],
8
12
  "exports": {
9
13
  ".": {
10
14
  "import": {
@@ -58,6 +62,15 @@
58
62
  "zod": "^3.25.76",
59
63
  "@internal/lint": "0.0.34"
60
64
  },
65
+ "homepage": "https://mastra.ai",
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/mastra-ai/mastra.git",
69
+ "directory": "packages/schema-compat"
70
+ },
71
+ "bugs": {
72
+ "url": "https://github.com/mastra-ai/mastra/issues"
73
+ },
61
74
  "scripts": {
62
75
  "build": "tsup --silent --config tsup.config.ts",
63
76
  "build:watch": "tsup --watch --silent --config tsup.config.ts",
@@ -1,4 +0,0 @@
1
-
2
- > @mastra/schema-compat@0.11.2-alpha.1 build /home/runner/work/mastra/mastra/packages/schema-compat
3
- > tsup --silent --config tsup.config.ts
4
-
package/eslint.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [...config];
package/src/index.ts DELETED
@@ -1,40 +0,0 @@
1
- // Schema compatibility base class and related types
2
- export {
3
- SchemaCompatLayer as SchemaCompatLayerV3,
4
- ALL_STRING_CHECKS,
5
- ALL_NUMBER_CHECKS,
6
- ALL_ARRAY_CHECKS,
7
- UNSUPPORTED_ZOD_TYPES,
8
- SUPPORTED_ZOD_TYPES,
9
- ALL_ZOD_TYPES,
10
- // Types
11
- type StringCheckType,
12
- type NumberCheckType,
13
- type ArrayCheckType,
14
- type UnsupportedZodType,
15
- type SupportedZodType,
16
- type AllZodType,
17
- type ZodShape,
18
- type ShapeKey,
19
- type ShapeValue,
20
- // Re-usable type predicates
21
- isOptional,
22
- isObj,
23
- isArr,
24
- isUnion,
25
- isString,
26
- isNumber,
27
- } from './schema-compatibility-v3';
28
- export { SchemaCompatLayer as SchemaCompatLayerV4 } from './schema-compatibility-v4';
29
- export { SchemaCompatLayer } from './schema-compatibility';
30
-
31
- // Utility functions
32
- export { convertZodSchemaToAISDKSchema, applyCompatLayer, convertSchemaToZod } from './utils';
33
-
34
- // Provider compatibility implementations
35
- export { AnthropicSchemaCompatLayer } from './provider-compats/anthropic';
36
- export { DeepSeekSchemaCompatLayer } from './provider-compats/deepseek';
37
- export { GoogleSchemaCompatLayer } from './provider-compats/google';
38
- export { MetaSchemaCompatLayer } from './provider-compats/meta';
39
- export { OpenAISchemaCompatLayer } from './provider-compats/openai';
40
- export { OpenAIReasoningSchemaCompatLayer } from './provider-compats/openai-reasoning';
@@ -1,61 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3, ZodObject as ZodObjectV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4, ZodObject as ZodObjectV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { AllZodType as AllZodTypeV3 } from '../schema-compatibility-v3';
7
- import type { AllZodType as AllZodTypeV4 } from '../schema-compatibility-v4';
8
- import type { ModelInformation } from '../types';
9
- import { isOptional, isObj, isArr, isUnion, isString } from '../zodTypes';
10
-
11
- export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
12
- constructor(model: ModelInformation) {
13
- super(model);
14
- }
15
-
16
- getSchemaTarget(): Targets | undefined {
17
- return 'jsonSchema7';
18
- }
19
-
20
- shouldApply(): boolean {
21
- return this.getModel().modelId.includes('claude');
22
- }
23
-
24
- processZodType(value: ZodTypeV3): ZodTypeV3;
25
- processZodType(value: ZodTypeV4): ZodTypeV4;
26
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
27
- if (isOptional(z)(value)) {
28
- const handleTypes: AllZodTypeV3[] | AllZodTypeV4 = [
29
- 'ZodObject',
30
- 'ZodArray',
31
- 'ZodUnion',
32
- 'ZodNever',
33
- 'ZodUndefined',
34
- 'ZodTuple',
35
- ];
36
- if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
37
- return this.defaultZodOptionalHandler(value, handleTypes);
38
- } else if (isObj(z)(value)) {
39
- return this.defaultZodObjectHandler(value);
40
- } else if (isArr(z)(value)) {
41
- return this.defaultZodArrayHandler(value, []);
42
- } else if (isUnion(z)(value)) {
43
- return this.defaultZodUnionHandler(value);
44
- } else if (isString(z)(value)) {
45
- // the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
46
- // added to the tool description
47
-
48
- if (this.getModel().modelId.includes('claude-3.5-haiku')) {
49
- return this.defaultZodStringHandler(value, ['max', 'min']);
50
- } else {
51
- return value;
52
- }
53
- }
54
-
55
- return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>, [
56
- 'ZodNever',
57
- 'ZodTuple',
58
- 'ZodUndefined',
59
- ]);
60
- }
61
- }
@@ -1,40 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { ModelInformation } from '../types';
7
- import { isOptional, isObj, isArr, isUnion, isString } from '../zodTypes';
8
-
9
- export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
10
- constructor(model: ModelInformation) {
11
- super(model);
12
- }
13
-
14
- getSchemaTarget(): Targets | undefined {
15
- return 'jsonSchema7';
16
- }
17
-
18
- shouldApply(): boolean {
19
- // Deepseek R1 performs perfectly without this compat layer
20
- return this.getModel().modelId.includes('deepseek') && !this.getModel().modelId.includes('r1');
21
- }
22
-
23
- processZodType(value: ZodTypeV3): ZodTypeV3;
24
- processZodType(value: ZodTypeV4): ZodTypeV4;
25
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
26
- if (isOptional(z)(value)) {
27
- return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
28
- } else if (isObj(z)(value)) {
29
- return this.defaultZodObjectHandler(value);
30
- } else if (isArr(z)(value)) {
31
- return this.defaultZodArrayHandler(value, ['min', 'max']);
32
- } else if (isUnion(z)(value)) {
33
- return this.defaultZodUnionHandler(value);
34
- } else if (isString(z)(value)) {
35
- return this.defaultZodStringHandler(value);
36
- }
37
-
38
- return value;
39
- }
40
- }
@@ -1,49 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3, ZodObject as ZodObjectV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4, ZodObject as ZodObjectV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { ModelInformation } from '../types';
7
- import { isOptional, isNull, isObj, isArr, isUnion, isString, isNumber } from '../zodTypes';
8
-
9
- export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
10
- constructor(model: ModelInformation) {
11
- super(model);
12
- }
13
-
14
- getSchemaTarget(): Targets | undefined {
15
- return 'jsonSchema7';
16
- }
17
-
18
- shouldApply(): boolean {
19
- return this.getModel().provider.includes('google') || this.getModel().modelId.includes('google');
20
- }
21
- processZodType(value: ZodTypeV3): ZodTypeV3;
22
- processZodType(value: ZodTypeV4): ZodTypeV4;
23
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
24
- if (isOptional(z)(value)) {
25
- return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
26
- } else if (isNull(z)(value)) {
27
- // Google models don't support null, so we need to convert it to any and then refine it to null
28
- return z
29
- .any()
30
- .refine(v => v === null, { message: 'must be null' })
31
- .describe(value.description || 'must be null');
32
- } else if (isObj(z)(value)) {
33
- return this.defaultZodObjectHandler(value);
34
- } else if (isArr(z)(value)) {
35
- return this.defaultZodArrayHandler(value, []);
36
- } else if (isUnion(z)(value)) {
37
- return this.defaultZodUnionHandler(value);
38
- } else if (isString(z)(value)) {
39
- // Google models support these properties but the model doesn't respect them, but it respects them when they're
40
- // added to the tool description
41
- return this.defaultZodStringHandler(value);
42
- } else if (isNumber(z)(value)) {
43
- // Google models support these properties but the model doesn't respect them, but it respects them when they're
44
- // added to the tool description
45
- return this.defaultZodNumberHandler(value);
46
- }
47
- return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>);
48
- }
49
- }
@@ -1,41 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { ModelInformation } from '../types';
7
- import { isOptional, isObj, isArr, isUnion, isNumber, isString } from '../zodTypes';
8
-
9
- export class MetaSchemaCompatLayer extends SchemaCompatLayer {
10
- constructor(model: ModelInformation) {
11
- super(model);
12
- }
13
-
14
- getSchemaTarget(): Targets | undefined {
15
- return 'jsonSchema7';
16
- }
17
-
18
- shouldApply(): boolean {
19
- return this.getModel().modelId.includes('meta');
20
- }
21
-
22
- processZodType(value: ZodTypeV3): ZodTypeV3;
23
- processZodType(value: ZodTypeV4): ZodTypeV4;
24
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
25
- if (isOptional(z)(value)) {
26
- return this.defaultZodOptionalHandler(value, ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodString', 'ZodNumber']);
27
- } else if (isObj(z)(value)) {
28
- return this.defaultZodObjectHandler(value);
29
- } else if (isArr(z)(value)) {
30
- return this.defaultZodArrayHandler(value, ['min', 'max']);
31
- } else if (isUnion(z)(value)) {
32
- return this.defaultZodUnionHandler(value);
33
- } else if (isNumber(z)(value)) {
34
- return this.defaultZodNumberHandler(value);
35
- } else if (isString(z)(value)) {
36
- return this.defaultZodStringHandler(value);
37
- }
38
-
39
- return value;
40
- }
41
- }
@@ -1,85 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3, ZodObject as ZodObjectV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4, ZodObject as ZodObjectV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { ModelInformation } from '../types';
7
- import { isOptional, isObj, isArr, isUnion, isDefault, isNumber, isString, isDate } from '../zodTypes';
8
-
9
- export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
10
- constructor(model: ModelInformation) {
11
- super(model);
12
- }
13
-
14
- getSchemaTarget(): Targets | undefined {
15
- return `openApi3`;
16
- }
17
-
18
- isReasoningModel(): boolean {
19
- // there isn't a good way to automatically detect reasoning models besides doing this.
20
- // in the future when o5 is released this compat wont apply and we'll want to come back and update this class + our tests
21
- return (
22
- this.getModel().modelId.includes(`o3`) ||
23
- this.getModel().modelId.includes(`o4`) ||
24
- this.getModel().modelId.includes(`o1`)
25
- );
26
- }
27
-
28
- shouldApply(): boolean {
29
- if (
30
- (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) &&
31
- (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
32
- ) {
33
- return true;
34
- }
35
-
36
- return false;
37
- }
38
-
39
- processZodType(value: ZodTypeV3): ZodTypeV3;
40
- processZodType(value: ZodTypeV4): ZodTypeV4;
41
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
42
- if (isOptional(z)(value)) {
43
- const innerZodType = this.processZodType(value._def.innerType);
44
- return innerZodType.nullable();
45
- } else if (isObj(z)(value)) {
46
- return this.defaultZodObjectHandler(value, { passthrough: false });
47
- } else if (isArr(z)(value)) {
48
- return this.defaultZodArrayHandler(value);
49
- } else if (isUnion(z)(value)) {
50
- return this.defaultZodUnionHandler(value);
51
- } else if (isDefault(z)(value)) {
52
- const defaultDef = value._def;
53
- const innerType = defaultDef.innerType;
54
- const defaultValue = defaultDef.defaultValue();
55
- const constraints: { defaultValue?: unknown } = {};
56
- if (defaultValue !== undefined) {
57
- constraints.defaultValue = defaultValue;
58
- }
59
-
60
- const description = this.mergeParameterDescription(value.description, constraints);
61
- let result = this.processZodType(innerType);
62
- if (description) {
63
- result = result.describe(description);
64
- }
65
- return result;
66
- } else if (isNumber(z)(value)) {
67
- return this.defaultZodNumberHandler(value);
68
- } else if (isString(z)(value)) {
69
- return this.defaultZodStringHandler(value);
70
- } else if (isDate(z)(value)) {
71
- return this.defaultZodDateHandler(value);
72
- } else if (value.constructor.name === 'ZodAny') {
73
- // 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
74
- // in the schema. Usually when it's "any" it could be a json object or a union of specific types.
75
- return z
76
- .string()
77
- .describe(
78
- (value.description ?? '') +
79
- `\nArgument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`,
80
- );
81
- }
82
-
83
- return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>);
84
- }
85
- }
@@ -1,65 +0,0 @@
1
- import { z } from 'zod';
2
- import type { ZodType as ZodTypeV3, ZodObject as ZodObjectV3 } from 'zod/v3';
3
- import type { ZodType as ZodTypeV4, ZodObject as ZodObjectV4 } from 'zod/v4';
4
- import type { Targets } from 'zod-to-json-schema';
5
- import { SchemaCompatLayer } from '../schema-compatibility';
6
- import type { ModelInformation } from '../types';
7
- import { isOptional, isObj, isUnion, isArr, isString } from '../zodTypes';
8
-
9
- export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
10
- constructor(model: ModelInformation) {
11
- super(model);
12
- }
13
-
14
- getSchemaTarget(): Targets | undefined {
15
- return `jsonSchema7`;
16
- }
17
-
18
- shouldApply(): boolean {
19
- if (
20
- !this.getModel().supportsStructuredOutputs &&
21
- (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
22
- ) {
23
- return true;
24
- }
25
-
26
- return false;
27
- }
28
-
29
- processZodType(value: ZodTypeV3): ZodTypeV3;
30
- processZodType(value: ZodTypeV4): ZodTypeV4;
31
- processZodType(value: ZodTypeV3 | ZodTypeV4): ZodTypeV3 | ZodTypeV4 {
32
- if (isOptional(z)(value)) {
33
- return this.defaultZodOptionalHandler(value, [
34
- 'ZodObject',
35
- 'ZodArray',
36
- 'ZodUnion',
37
- 'ZodString',
38
- 'ZodNever',
39
- 'ZodUndefined',
40
- 'ZodTuple',
41
- ]);
42
- } else if (isObj(z)(value)) {
43
- return this.defaultZodObjectHandler(value);
44
- } else if (isUnion(z)(value)) {
45
- return this.defaultZodUnionHandler(value);
46
- } else if (isArr(z)(value)) {
47
- return this.defaultZodArrayHandler(value);
48
- } else if (isString(z)(value)) {
49
- const model = this.getModel();
50
- const checks = ['emoji'] as const;
51
-
52
- if (model.modelId.includes('gpt-4o-mini')) {
53
- return this.defaultZodStringHandler(value, ['emoji', 'regex']);
54
- }
55
-
56
- return this.defaultZodStringHandler(value, checks);
57
- }
58
-
59
- return this.defaultUnsupportedZodTypeHandler(value as ZodObjectV4<any> | ZodObjectV3<any>, [
60
- 'ZodNever',
61
- 'ZodUndefined',
62
- 'ZodTuple',
63
- ]);
64
- }
65
- }