@mastra/schema-compat 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806184630 → 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.
- package/CHANGELOG.md +131 -1
- package/README.md +0 -4
- package/dist/chunk-5WM4A32G.cjs +83 -0
- package/dist/chunk-5WM4A32G.cjs.map +1 -0
- package/dist/chunk-U2HXWNAF.js +77 -0
- package/dist/chunk-U2HXWNAF.js.map +1 -0
- package/dist/index.cjs +4560 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4558 -272
- package/dist/index.js.map +1 -1
- package/dist/json-schema.d.ts +4 -0
- package/dist/json-schema.d.ts.map +1 -0
- 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 +287 -0
- package/dist/schema-compatibility-v3.d.ts.map +1 -0
- package/dist/schema-compatibility-v4.d.ts +278 -0
- package/dist/schema-compatibility-v4.d.ts.map +1 -0
- package/dist/schema-compatibility.d.ts +81 -165
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/types.d.ts +7 -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 +18 -6
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json-test-suite.d.ts +6 -0
- package/dist/zod-to-json-test-suite.d.ts.map +1 -0
- 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 +33 -10
- package/.turbo/turbo-build.log +0 -4
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -39
- package/src/provider-compats/anthropic.ts +0 -44
- package/src/provider-compats/deepseek.ts +0 -35
- package/src/provider-compats/google.ts +0 -63
- package/src/provider-compats/meta.ts +0 -36
- package/src/provider-compats/openai-reasoning.ts +0 -91
- package/src/provider-compats/openai.ts +0 -56
- package/src/provider-compats.test.ts +0 -312
- package/src/schema-compatibility.test.ts +0 -471
- package/src/schema-compatibility.ts +0 -588
- package/src/utils.test.ts +0 -434
- package/src/utils.ts +0 -205
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-compatibility.d.ts","sourceRoot":"","sources":["../src/schema-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schema-compatibility.d.ts","sourceRoot":"","sources":["../src/schema-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;A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AE,OAAO,CAAC;CACpC,CAAC;AAEF,YAAY,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-test-suite.d.ts","sourceRoot":"","sources":["../src/utils-test-suite.ts"],"names":[],"mappings":"AA+CA,wBAAgB,YAAY,SAka3B"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { z, ZodSchema } from 'zod';
|
|
1
|
+
import type { ZodSchema as ZodSchemaV3, ZodType as ZodTypeV3 } from 'zod/v3';
|
|
2
|
+
import type { ZodType as ZodSchemaV4, ZodType as ZodTypeV4 } from 'zod/v4';
|
|
4
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
4
|
+
import type { JSONSchema7 } from './json-schema.js';
|
|
5
5
|
import type { SchemaCompatLayer } from './schema-compatibility.js';
|
|
6
|
+
import type { Schema } from './types.js';
|
|
7
|
+
type ZodSchema = ZodSchemaV3 | ZodSchemaV4;
|
|
8
|
+
type ZodType = ZodTypeV3 | ZodTypeV4;
|
|
6
9
|
/**
|
|
7
10
|
* Converts a Zod schema to an AI SDK Schema with validation support.
|
|
8
11
|
*
|
|
@@ -27,6 +30,14 @@ import type { SchemaCompatLayer } from './schema-compatibility.js';
|
|
|
27
30
|
* ```
|
|
28
31
|
*/
|
|
29
32
|
export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, target?: Targets): Schema<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is a Zod type by examining its properties and methods.
|
|
35
|
+
*
|
|
36
|
+
* @param value - The value to check
|
|
37
|
+
* @returns True if the value is a Zod type, false otherwise
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function isZodType(value: unknown): value is ZodType;
|
|
30
41
|
/**
|
|
31
42
|
* Converts an AI SDK Schema or Zod schema to a Zod schema.
|
|
32
43
|
*
|
|
@@ -52,7 +63,7 @@ export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, targ
|
|
|
52
63
|
* const zodSchema = convertSchemaToZod(aiSchema);
|
|
53
64
|
* ```
|
|
54
65
|
*/
|
|
55
|
-
export declare function convertSchemaToZod(schema: Schema |
|
|
66
|
+
export declare function convertSchemaToZod(schema: Schema | ZodSchema): ZodType;
|
|
56
67
|
/**
|
|
57
68
|
* Processes a schema using provider compatibility layers and converts it to an AI SDK Schema.
|
|
58
69
|
*
|
|
@@ -63,7 +74,7 @@ export declare function convertSchemaToZod(schema: Schema | z.ZodSchema): z.ZodT
|
|
|
63
74
|
* @returns Processed schema as an AI SDK Schema
|
|
64
75
|
*/
|
|
65
76
|
export declare function applyCompatLayer(options: {
|
|
66
|
-
schema: Schema |
|
|
77
|
+
schema: Schema | ZodSchema;
|
|
67
78
|
compatLayers: SchemaCompatLayer[];
|
|
68
79
|
mode: 'aiSdkSchema';
|
|
69
80
|
}): Schema;
|
|
@@ -77,8 +88,9 @@ export declare function applyCompatLayer(options: {
|
|
|
77
88
|
* @returns Processed schema as a JSONSchema7
|
|
78
89
|
*/
|
|
79
90
|
export declare function applyCompatLayer(options: {
|
|
80
|
-
schema: Schema |
|
|
91
|
+
schema: Schema | ZodSchema;
|
|
81
92
|
compatLayers: SchemaCompatLayer[];
|
|
82
93
|
mode: 'jsonSchema';
|
|
83
94
|
}): JSONSchema7;
|
|
95
|
+
export {};
|
|
84
96
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,IAAI,WAAW,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ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shared test suite for zodToJsonSchema that runs with both Zod v3 and v4.
|
|
3
|
+
* The importing test file should mock 'zod' to either v3 or v4 before calling this.
|
|
4
|
+
*/
|
|
5
|
+
export declare function runZodToJsonTestSuite(): void;
|
|
6
|
+
//# sourceMappingURL=zod-to-json-test-suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-json-test-suite.d.ts","sourceRoot":"","sources":["../src/zod-to-json-test-suite.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,qBAAqB,SA8jBpC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5WM4A32G_cjs = require('./chunk-5WM4A32G.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "zodToJsonSchema", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunk5WM4A32G_cjs.zodToJsonSchema; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=zod-to-json.cjs.map
|
|
12
|
+
//# sourceMappingURL=zod-to-json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"zod-to-json.cjs"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { ZodSchema as ZodSchemaV3 } from 'zod/v3';
|
|
3
|
+
import type { ZodType as ZodSchemaV4 } from 'zod/v4';
|
|
4
|
+
import type { Targets } from 'zod-to-json-schema';
|
|
5
|
+
export declare function zodToJsonSchema(zodSchema: ZodSchemaV3 | ZodSchemaV4, target?: Targets, strategy?: 'none' | 'seen' | 'root' | 'relative'): JSONSchema7;
|
|
6
|
+
//# sourceMappingURL=zod-to-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-json.d.ts","sourceRoot":"","sources":["../src/zod-to-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAmFlD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,WAAW,GAAG,WAAW,EACpC,MAAM,GAAE,OAAuB,EAC/B,QAAQ,GAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAuB,eA2B7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"zod-to-json.js"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { z as zV3 } from 'zod/v3';
|
|
2
|
+
import type { z as zV4 } from 'zod/v4';
|
|
3
|
+
export declare function isOptional<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodOptional<any>;
|
|
4
|
+
export declare function isOptional<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodOptional<any>;
|
|
5
|
+
export declare function isObj<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodObject<any>;
|
|
6
|
+
export declare function isObj<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodObject;
|
|
7
|
+
export declare function isNull<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodNull;
|
|
8
|
+
export declare function isNull<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodNull;
|
|
9
|
+
export declare function isArr<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodArray<any>;
|
|
10
|
+
export declare function isArr<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodArray;
|
|
11
|
+
export declare function isUnion<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodUnion<any>;
|
|
12
|
+
export declare function isUnion<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodUnion;
|
|
13
|
+
export declare function isString<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodString;
|
|
14
|
+
export declare function isString<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodString;
|
|
15
|
+
export declare function isNumber<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodNumber;
|
|
16
|
+
export declare function isNumber<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodNumber;
|
|
17
|
+
export declare function isDate<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodDate;
|
|
18
|
+
export declare function isDate<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodDate;
|
|
19
|
+
export declare function isDefault<Z extends typeof zV3>(z: Z): (v: any) => v is zV3.ZodDefault<any>;
|
|
20
|
+
export declare function isDefault<Z extends typeof zV4>(z: Z): (v: any) => v is zV4.ZodDefault;
|
|
21
|
+
//# sourceMappingURL=zodTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodTypes.d.ts","sourceRoot":"","sources":["../src/zodTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAC9F,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAK9F,wBAAgB,KAAK,CAAC,CA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|
{
|
|
2
2
|
"name": "@mastra/schema-compat",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-vnext-20251104230439",
|
|
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": {
|
|
@@ -16,6 +20,16 @@
|
|
|
16
20
|
"default": "./dist/index.cjs"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
23
|
+
"./zod-to-json": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/zod-to-json.d.ts",
|
|
26
|
+
"default": "./dist/zod-to-json.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/zod-to-json.d.ts",
|
|
30
|
+
"default": "./dist/zod-to-json.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
19
33
|
"./package.json": "./package.json"
|
|
20
34
|
},
|
|
21
35
|
"keywords": [
|
|
@@ -29,24 +43,33 @@
|
|
|
29
43
|
"license": "Apache-2.0",
|
|
30
44
|
"dependencies": {
|
|
31
45
|
"json-schema": "^0.4.0",
|
|
32
|
-
"zod-from-json-schema": "^0.0
|
|
33
|
-
"zod-
|
|
46
|
+
"zod-from-json-schema": "^0.5.0",
|
|
47
|
+
"zod-from-json-schema-v3": "npm:zod-from-json-schema@^0.0.5",
|
|
48
|
+
"zod-to-json-schema": "^3.24.6"
|
|
34
49
|
},
|
|
35
50
|
"peerDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"zod": "^3.0.0"
|
|
51
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
38
52
|
},
|
|
39
53
|
"devDependencies": {
|
|
40
54
|
"@types/json-schema": "^7.0.15",
|
|
41
55
|
"@types/node": "^20.19.0",
|
|
42
|
-
"
|
|
43
|
-
"eslint": "^9.30.1",
|
|
56
|
+
"eslint": "^9.37.0",
|
|
44
57
|
"tsup": "^8.5.0",
|
|
45
58
|
"typescript": "^5.8.3",
|
|
46
59
|
"vitest": "^3.2.4",
|
|
47
|
-
"zod": "^3.25.
|
|
48
|
-
"@internal/types-builder": "0.0.0-
|
|
49
|
-
"@internal/lint": "0.0.0-
|
|
60
|
+
"zod": "^3.25.76",
|
|
61
|
+
"@internal/types-builder": "0.0.0-vnext-20251104230439",
|
|
62
|
+
"@internal/lint": "0.0.0-vnext-20251104230439",
|
|
63
|
+
"@internal/ai-sdk-v4": "0.0.0-vnext-20251104230439"
|
|
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"
|
|
50
73
|
},
|
|
51
74
|
"scripts": {
|
|
52
75
|
"build": "tsup --silent --config tsup.config.ts",
|
package/.turbo/turbo-build.log
DELETED
package/eslint.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Schema compatibility base class and related types
|
|
2
|
-
export {
|
|
3
|
-
SchemaCompatLayer,
|
|
4
|
-
// Constants
|
|
5
|
-
ALL_STRING_CHECKS,
|
|
6
|
-
ALL_NUMBER_CHECKS,
|
|
7
|
-
ALL_ARRAY_CHECKS,
|
|
8
|
-
UNSUPPORTED_ZOD_TYPES,
|
|
9
|
-
SUPPORTED_ZOD_TYPES,
|
|
10
|
-
ALL_ZOD_TYPES,
|
|
11
|
-
// Types
|
|
12
|
-
type StringCheckType,
|
|
13
|
-
type NumberCheckType,
|
|
14
|
-
type ArrayCheckType,
|
|
15
|
-
type UnsupportedZodType,
|
|
16
|
-
type SupportedZodType,
|
|
17
|
-
type AllZodType,
|
|
18
|
-
type ZodShape,
|
|
19
|
-
type ShapeKey,
|
|
20
|
-
type ShapeValue,
|
|
21
|
-
// Re-usable type predicates
|
|
22
|
-
isOptional,
|
|
23
|
-
isObj,
|
|
24
|
-
isArr,
|
|
25
|
-
isUnion,
|
|
26
|
-
isString,
|
|
27
|
-
isNumber,
|
|
28
|
-
} from './schema-compatibility';
|
|
29
|
-
|
|
30
|
-
// Utility functions
|
|
31
|
-
export { convertZodSchemaToAISDKSchema, applyCompatLayer, convertSchemaToZod } from './utils';
|
|
32
|
-
|
|
33
|
-
// Provider compatibility implementations
|
|
34
|
-
export { AnthropicSchemaCompatLayer } from './provider-compats/anthropic';
|
|
35
|
-
export { DeepSeekSchemaCompatLayer } from './provider-compats/deepseek';
|
|
36
|
-
export { GoogleSchemaCompatLayer } from './provider-compats/google';
|
|
37
|
-
export { MetaSchemaCompatLayer } from './provider-compats/meta';
|
|
38
|
-
export { OpenAISchemaCompatLayer } from './provider-compats/openai';
|
|
39
|
-
export { OpenAIReasoningSchemaCompatLayer } from './provider-compats/openai-reasoning';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { LanguageModelV1 } from 'ai';
|
|
2
|
-
import type { ZodTypeAny } from 'zod';
|
|
3
|
-
import type { Targets } from 'zod-to-json-schema';
|
|
4
|
-
import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
5
|
-
import type { AllZodType } from '../schema-compatibility';
|
|
6
|
-
|
|
7
|
-
export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
8
|
-
constructor(model: LanguageModelV1) {
|
|
9
|
-
super(model);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
getSchemaTarget(): Targets | undefined {
|
|
13
|
-
return 'jsonSchema7';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
shouldApply(): boolean {
|
|
17
|
-
return this.getModel().modelId.includes('claude');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
processZodType(value: ZodTypeAny): ZodTypeAny {
|
|
21
|
-
if (isOptional(value)) {
|
|
22
|
-
const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined', 'ZodTuple'];
|
|
23
|
-
if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
|
|
24
|
-
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
25
|
-
} else if (isObj(value)) {
|
|
26
|
-
return this.defaultZodObjectHandler(value);
|
|
27
|
-
} else if (isArr(value)) {
|
|
28
|
-
return this.defaultZodArrayHandler(value, []);
|
|
29
|
-
} else if (isUnion(value)) {
|
|
30
|
-
return this.defaultZodUnionHandler(value);
|
|
31
|
-
} else if (isString(value)) {
|
|
32
|
-
// the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
|
|
33
|
-
// added to the tool description
|
|
34
|
-
|
|
35
|
-
if (this.getModel().modelId.includes('claude-3.5-haiku')) {
|
|
36
|
-
return this.defaultZodStringHandler(value, ['max', 'min']);
|
|
37
|
-
} else {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { LanguageModelV1 } from 'ai';
|
|
2
|
-
import type { ZodTypeAny } from 'zod';
|
|
3
|
-
import type { Targets } from 'zod-to-json-schema';
|
|
4
|
-
import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
5
|
-
|
|
6
|
-
export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model: LanguageModelV1) {
|
|
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 { LanguageModelV1 } from 'ai';
|
|
2
|
-
import type { ZodTypeAny } from 'zod';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import type { Targets } from 'zod-to-json-schema';
|
|
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: LanguageModelV1) {
|
|
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 { LanguageModelV1 } from 'ai';
|
|
2
|
-
import type { ZodTypeAny } from 'zod';
|
|
3
|
-
import type { Targets } from 'zod-to-json-schema';
|
|
4
|
-
import { SchemaCompatLayer, isArr, isNumber, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
5
|
-
|
|
6
|
-
export class MetaSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model: LanguageModelV1) {
|
|
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 type { LanguageModelV1 } from 'ai';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { ZodTypeAny } from 'zod';
|
|
4
|
-
import type { Targets } from 'zod-to-json-schema';
|
|
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: LanguageModelV1) {
|
|
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
|
-
}
|