@mastra/schema-compat 0.0.0-ai-v5-20250626003446 → 0.0.0-ai-v5-20250710191716
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 +7 -7
- package/CHANGELOG.md +32 -1
- package/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +6 -1
- package/dist/_tsup-dts-rollup.d.ts +6 -1
- package/dist/index.cjs +10 -11
- package/dist/index.js +11 -12
- package/package.json +9 -9
- package/src/provider-compats/anthropic.ts +2 -7
- package/src/provider-compats/google.ts +8 -0
- package/src/provider-compats/openai-reasoning.ts +1 -1
- package/src/schema-compatibility.ts +11 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/schema-compat@0.10.
|
|
2
|
+
> @mastra/schema-compat@0.10.4 build /home/runner/work/mastra/mastra/packages/schema-compat
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 2248ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2018ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[32m21.
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m21.
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m21.30 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 137ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m21.92 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 137ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
-
## 0.0.0-ai-v5-
|
|
3
|
+
## 0.0.0-ai-v5-20250710191716
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 66858d4: AI SDK v5 beta
|
|
8
8
|
|
|
9
|
+
## 0.10.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0c85311: Fix Google models ZodNull tool schema handling
|
|
14
|
+
|
|
15
|
+
## 0.10.4-alpha.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 0c85311: Fix Google models ZodNull tool schema handling
|
|
20
|
+
|
|
21
|
+
## 0.10.3
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
26
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
27
|
+
|
|
28
|
+
## 0.10.3-alpha.1
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
33
|
+
|
|
34
|
+
## 0.10.3-alpha.0
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
39
|
+
|
|
9
40
|
## 0.10.2
|
|
10
41
|
|
|
11
42
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -6,6 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import { ZodArray } from 'zod';
|
|
7
7
|
import { ZodDate } from 'zod';
|
|
8
8
|
import { ZodDefault } from 'zod';
|
|
9
|
+
import { ZodNull } from 'zod';
|
|
9
10
|
import { ZodNumber } from 'zod';
|
|
10
11
|
import { ZodObject } from 'zod';
|
|
11
12
|
import { ZodOptional } from 'zod';
|
|
@@ -195,6 +196,8 @@ export declare const isDate: (v: ZodTypeAny) => v is ZodDate;
|
|
|
195
196
|
|
|
196
197
|
export declare const isDefault: (v: ZodTypeAny) => v is ZodDefault<any>;
|
|
197
198
|
|
|
199
|
+
export declare const isNull: (v: ZodTypeAny) => v is ZodNull;
|
|
200
|
+
|
|
198
201
|
declare const isNumber: (v: ZodTypeAny) => v is ZodNumber;
|
|
199
202
|
export { isNumber }
|
|
200
203
|
export { isNumber as isNumber_alias_1 }
|
|
@@ -339,7 +342,9 @@ declare abstract class SchemaCompatLayer {
|
|
|
339
342
|
* @param value - The Zod object to process
|
|
340
343
|
* @returns The processed Zod object
|
|
341
344
|
*/
|
|
342
|
-
defaultZodObjectHandler(value: ZodObject<any, any, any
|
|
345
|
+
defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
|
|
346
|
+
passthrough?: boolean;
|
|
347
|
+
}): ZodObject<any, any, any>;
|
|
343
348
|
/**
|
|
344
349
|
* Merges validation constraints into a parameter description.
|
|
345
350
|
*
|
|
@@ -6,6 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import { ZodArray } from 'zod';
|
|
7
7
|
import { ZodDate } from 'zod';
|
|
8
8
|
import { ZodDefault } from 'zod';
|
|
9
|
+
import { ZodNull } from 'zod';
|
|
9
10
|
import { ZodNumber } from 'zod';
|
|
10
11
|
import { ZodObject } from 'zod';
|
|
11
12
|
import { ZodOptional } from 'zod';
|
|
@@ -195,6 +196,8 @@ export declare const isDate: (v: ZodTypeAny) => v is ZodDate;
|
|
|
195
196
|
|
|
196
197
|
export declare const isDefault: (v: ZodTypeAny) => v is ZodDefault<any>;
|
|
197
198
|
|
|
199
|
+
export declare const isNull: (v: ZodTypeAny) => v is ZodNull;
|
|
200
|
+
|
|
198
201
|
declare const isNumber: (v: ZodTypeAny) => v is ZodNumber;
|
|
199
202
|
export { isNumber }
|
|
200
203
|
export { isNumber as isNumber_alias_1 }
|
|
@@ -339,7 +342,9 @@ declare abstract class SchemaCompatLayer {
|
|
|
339
342
|
* @param value - The Zod object to process
|
|
340
343
|
* @returns The processed Zod object
|
|
341
344
|
*/
|
|
342
|
-
defaultZodObjectHandler(value: ZodObject<any, any, any
|
|
345
|
+
defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
|
|
346
|
+
passthrough?: boolean;
|
|
347
|
+
}): ZodObject<any, any, any>;
|
|
343
348
|
/**
|
|
344
349
|
* Merges validation constraints into a parameter description.
|
|
345
350
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ var ALL_NUMBER_CHECKS = [
|
|
|
73
73
|
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
74
74
|
var isOptional = (v) => v instanceof zod.ZodOptional;
|
|
75
75
|
var isObj = (v) => v instanceof zod.ZodObject;
|
|
76
|
+
var isNull = (v) => v instanceof zod.ZodNull;
|
|
76
77
|
var isArr = (v) => v instanceof zod.ZodArray;
|
|
77
78
|
var isUnion = (v) => v instanceof zod.ZodUnion;
|
|
78
79
|
var isString = (v) => v instanceof zod.ZodString;
|
|
@@ -115,7 +116,7 @@ var SchemaCompatLayer = class {
|
|
|
115
116
|
* @param value - The Zod object to process
|
|
116
117
|
* @returns The processed Zod object
|
|
117
118
|
*/
|
|
118
|
-
defaultZodObjectHandler(value) {
|
|
119
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
119
120
|
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
120
121
|
acc[key] = this.processZodType(propValue);
|
|
121
122
|
return acc;
|
|
@@ -130,6 +131,9 @@ var SchemaCompatLayer = class {
|
|
|
130
131
|
if (value.description) {
|
|
131
132
|
result = result.describe(value.description);
|
|
132
133
|
}
|
|
134
|
+
if (options.passthrough && value._def.unknownKeys === "passthrough") {
|
|
135
|
+
result = result.passthrough();
|
|
136
|
+
}
|
|
133
137
|
return result;
|
|
134
138
|
}
|
|
135
139
|
/**
|
|
@@ -425,9 +429,8 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
425
429
|
}
|
|
426
430
|
processZodType(value) {
|
|
427
431
|
if (isOptional(value)) {
|
|
428
|
-
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
432
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
|
|
429
433
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
430
|
-
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
431
434
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
432
435
|
} else if (isObj(value)) {
|
|
433
436
|
return this.defaultZodObjectHandler(value);
|
|
@@ -442,11 +445,7 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
442
445
|
return value;
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
|
-
|
|
446
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
447
|
-
} else {
|
|
448
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
449
|
-
}
|
|
448
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
450
449
|
}
|
|
451
450
|
};
|
|
452
451
|
|
|
@@ -476,8 +475,6 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
476
475
|
return value;
|
|
477
476
|
}
|
|
478
477
|
};
|
|
479
|
-
|
|
480
|
-
// src/provider-compats/google.ts
|
|
481
478
|
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
482
479
|
constructor(model) {
|
|
483
480
|
super(model);
|
|
@@ -498,6 +495,8 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
498
495
|
"ZodNumber",
|
|
499
496
|
...UNSUPPORTED_ZOD_TYPES
|
|
500
497
|
]);
|
|
498
|
+
} else if (isNull(value)) {
|
|
499
|
+
return zod.z.any().refine((v) => v === null, { message: "must be null" }).describe(value._def.description || "must be null");
|
|
501
500
|
} else if (isObj(value)) {
|
|
502
501
|
return this.defaultZodObjectHandler(value);
|
|
503
502
|
} else if (isArr(value)) {
|
|
@@ -611,7 +610,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
611
610
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
612
611
|
return innerZodType.nullable();
|
|
613
612
|
} else if (isObj(value)) {
|
|
614
|
-
return this.defaultZodObjectHandler(value);
|
|
613
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
615
614
|
} else if (isArr(value)) {
|
|
616
615
|
return this.defaultZodArrayHandler(value);
|
|
617
616
|
} else if (isUnion(value)) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, z, ZodDefault, ZodDate } from 'zod';
|
|
1
|
+
import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, z, ZodNull, ZodDefault, ZodDate } from 'zod';
|
|
2
2
|
import { jsonSchema } from 'ai';
|
|
3
3
|
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
4
4
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
@@ -71,6 +71,7 @@ var ALL_NUMBER_CHECKS = [
|
|
|
71
71
|
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
72
72
|
var isOptional = (v) => v instanceof ZodOptional;
|
|
73
73
|
var isObj = (v) => v instanceof ZodObject;
|
|
74
|
+
var isNull = (v) => v instanceof ZodNull;
|
|
74
75
|
var isArr = (v) => v instanceof ZodArray;
|
|
75
76
|
var isUnion = (v) => v instanceof ZodUnion;
|
|
76
77
|
var isString = (v) => v instanceof ZodString;
|
|
@@ -113,7 +114,7 @@ var SchemaCompatLayer = class {
|
|
|
113
114
|
* @param value - The Zod object to process
|
|
114
115
|
* @returns The processed Zod object
|
|
115
116
|
*/
|
|
116
|
-
defaultZodObjectHandler(value) {
|
|
117
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
117
118
|
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
118
119
|
acc[key] = this.processZodType(propValue);
|
|
119
120
|
return acc;
|
|
@@ -128,6 +129,9 @@ var SchemaCompatLayer = class {
|
|
|
128
129
|
if (value.description) {
|
|
129
130
|
result = result.describe(value.description);
|
|
130
131
|
}
|
|
132
|
+
if (options.passthrough && value._def.unknownKeys === "passthrough") {
|
|
133
|
+
result = result.passthrough();
|
|
134
|
+
}
|
|
131
135
|
return result;
|
|
132
136
|
}
|
|
133
137
|
/**
|
|
@@ -423,9 +427,8 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
423
427
|
}
|
|
424
428
|
processZodType(value) {
|
|
425
429
|
if (isOptional(value)) {
|
|
426
|
-
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
430
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
|
|
427
431
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
428
|
-
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
429
432
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
430
433
|
} else if (isObj(value)) {
|
|
431
434
|
return this.defaultZodObjectHandler(value);
|
|
@@ -440,11 +443,7 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
440
443
|
return value;
|
|
441
444
|
}
|
|
442
445
|
}
|
|
443
|
-
|
|
444
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
445
|
-
} else {
|
|
446
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
447
|
-
}
|
|
446
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
448
447
|
}
|
|
449
448
|
};
|
|
450
449
|
|
|
@@ -474,8 +473,6 @@ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
474
473
|
return value;
|
|
475
474
|
}
|
|
476
475
|
};
|
|
477
|
-
|
|
478
|
-
// src/provider-compats/google.ts
|
|
479
476
|
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
480
477
|
constructor(model) {
|
|
481
478
|
super(model);
|
|
@@ -496,6 +493,8 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
496
493
|
"ZodNumber",
|
|
497
494
|
...UNSUPPORTED_ZOD_TYPES
|
|
498
495
|
]);
|
|
496
|
+
} else if (isNull(value)) {
|
|
497
|
+
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value._def.description || "must be null");
|
|
499
498
|
} else if (isObj(value)) {
|
|
500
499
|
return this.defaultZodObjectHandler(value);
|
|
501
500
|
} else if (isArr(value)) {
|
|
@@ -609,7 +608,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
609
608
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
610
609
|
return innerZodType.nullable();
|
|
611
610
|
} else if (isObj(value)) {
|
|
612
|
-
return this.defaultZodObjectHandler(value);
|
|
611
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
613
612
|
} else if (isArr(value)) {
|
|
614
613
|
return this.defaultZodArrayHandler(value);
|
|
615
614
|
} else if (isUnion(value)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/schema-compat",
|
|
3
|
-
"version": "0.0.0-ai-v5-
|
|
3
|
+
"version": "0.0.0-ai-v5-20250710191716",
|
|
4
4
|
"description": "Tool schema compatibility layer for Mastra.ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,26 +26,26 @@
|
|
|
26
26
|
"zod"
|
|
27
27
|
],
|
|
28
28
|
"author": "",
|
|
29
|
-
"license": "
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"json-schema": "^0.4.0",
|
|
32
32
|
"zod-from-json-schema": "^0.0.5",
|
|
33
33
|
"zod-to-json-schema": "^3.24.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"ai": "5.0.0-beta.
|
|
36
|
+
"ai": "5.0.0-beta.14",
|
|
37
37
|
"zod": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/json-schema": "^7.0.15",
|
|
41
|
-
"ai": "5.0.0-beta.
|
|
42
|
-
"eslint": "^9.28.0",
|
|
43
|
-
"tsup": "^8.5.0",
|
|
41
|
+
"ai": "5.0.0-beta.14",
|
|
44
42
|
"@types/node": "^20.19.0",
|
|
43
|
+
"eslint": "^9.29.0",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
45
|
"typescript": "^5.8.3",
|
|
46
|
-
"vitest": "^3.2.
|
|
47
|
-
"zod": "^3.25.
|
|
48
|
-
"@internal/lint": "0.0.0-ai-v5-
|
|
46
|
+
"vitest": "^3.2.4",
|
|
47
|
+
"zod": "^3.25.67",
|
|
48
|
+
"@internal/lint": "0.0.0-ai-v5-20250710191716"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
@@ -18,9 +18,8 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
18
18
|
|
|
19
19
|
processZodType(value: ZodTypeAny): ZodTypeAny {
|
|
20
20
|
if (isOptional(value)) {
|
|
21
|
-
const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined'];
|
|
21
|
+
const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined', 'ZodTuple'];
|
|
22
22
|
if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
|
|
23
|
-
if (this.getModel().modelId.includes('claude-3.7')) handleTypes.push('ZodTuple');
|
|
24
23
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
25
24
|
} else if (isObj(value)) {
|
|
26
25
|
return this.defaultZodObjectHandler(value);
|
|
@@ -39,10 +38,6 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
|
|
44
|
-
} else {
|
|
45
|
-
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodUndefined']);
|
|
46
|
-
}
|
|
41
|
+
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
|
|
47
42
|
}
|
|
48
43
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ZodTypeAny } from 'zod';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import {
|
|
4
5
|
SchemaCompatLayer,
|
|
5
6
|
UNSUPPORTED_ZOD_TYPES,
|
|
6
7
|
isArr,
|
|
8
|
+
isNull,
|
|
7
9
|
isNumber,
|
|
8
10
|
isObj,
|
|
9
11
|
isOptional,
|
|
@@ -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)) {
|
|
@@ -46,7 +46,7 @@ export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
46
46
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
47
47
|
return innerZodType.nullable();
|
|
48
48
|
} else if (isObj(value)) {
|
|
49
|
-
return this.defaultZodObjectHandler(value);
|
|
49
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
50
50
|
} else if (isArr(value)) {
|
|
51
51
|
return this.defaultZodArrayHandler(value);
|
|
52
52
|
} else if (isUnion(value)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Schema, LanguageModel } from 'ai';
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
-
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault } from 'zod';
|
|
3
|
+
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault, ZodNull } from 'zod';
|
|
4
4
|
import type { ZodTypeAny } from 'zod';
|
|
5
5
|
import type { Targets } from 'zod-to-json-schema';
|
|
6
6
|
import { convertZodSchemaToAISDKSchema } from './utils';
|
|
@@ -31,6 +31,7 @@ export const ALL_ARRAY_CHECKS = ['min', 'max', 'length'] as const;
|
|
|
31
31
|
|
|
32
32
|
export const isOptional = (v: ZodTypeAny): v is ZodOptional<any> => v instanceof ZodOptional;
|
|
33
33
|
export const isObj = (v: ZodTypeAny): v is ZodObject<any, any, any> => v instanceof ZodObject;
|
|
34
|
+
export const isNull = (v: ZodTypeAny): v is ZodNull => v instanceof ZodNull;
|
|
34
35
|
export const isArr = (v: ZodTypeAny): v is ZodArray<any, any> => v instanceof ZodArray;
|
|
35
36
|
export const isUnion = (v: ZodTypeAny): v is ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]> => v instanceof ZodUnion;
|
|
36
37
|
export const isString = (v: ZodTypeAny): v is ZodString => v instanceof ZodString;
|
|
@@ -234,7 +235,10 @@ export abstract class SchemaCompatLayer {
|
|
|
234
235
|
* @param value - The Zod object to process
|
|
235
236
|
* @returns The processed Zod object
|
|
236
237
|
*/
|
|
237
|
-
public defaultZodObjectHandler(
|
|
238
|
+
public defaultZodObjectHandler(
|
|
239
|
+
value: ZodObject<any, any, any>,
|
|
240
|
+
options: { passthrough?: boolean } = { passthrough: true },
|
|
241
|
+
): ZodObject<any, any, any> {
|
|
238
242
|
const processedShape = Object.entries(value.shape).reduce<Record<string, ZodTypeAny>>((acc, [key, propValue]) => {
|
|
239
243
|
acc[key] = this.processZodType(propValue as ZodTypeAny);
|
|
240
244
|
return acc;
|
|
@@ -252,6 +256,11 @@ export abstract class SchemaCompatLayer {
|
|
|
252
256
|
if (value.description) {
|
|
253
257
|
result = result.describe(value.description);
|
|
254
258
|
}
|
|
259
|
+
|
|
260
|
+
if (options.passthrough && value._def.unknownKeys === 'passthrough') {
|
|
261
|
+
result = result.passthrough();
|
|
262
|
+
}
|
|
263
|
+
|
|
255
264
|
return result;
|
|
256
265
|
}
|
|
257
266
|
|