@mastra/schema-compat 0.0.0-ai-v5-20250625173645

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.
@@ -0,0 +1,23 @@
1
+
2
+ > @mastra/schema-compat@0.10.2 build /home/runner/work/mastra/mastra/packages/schema-compat
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.0
8
+ TSC Build start
9
+ TSC ⚡️ Build success in 2200ms
10
+ DTS Build start
11
+ CLI Target: es2022
12
+ Analysis will use the bundled TypeScript version 5.8.3
13
+ Writing package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.ts
14
+ Analysis will use the bundled TypeScript version 5.8.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 1893ms
17
+ CLI Cleaning output folder
18
+ ESM Build start
19
+ CJS Build start
20
+ ESM dist/index.js 21.19 KB
21
+ ESM ⚡️ Build success in 149ms
22
+ CJS dist/index.cjs 21.82 KB
23
+ CJS ⚡️ Build success in 149ms
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @mastra/schema-compat
2
+
3
+ ## 0.0.0-ai-v5-20250625173645
4
+
5
+ ### Minor Changes
6
+
7
+ - 66858d4: AI SDK v5 beta
8
+
9
+ ## 0.10.2
10
+
11
+ ### Patch Changes
12
+
13
+ - f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
14
+ - f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra
15
+
16
+ ## 0.10.2-alpha.3
17
+
18
+ ### Patch Changes
19
+
20
+ - f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
21
+
22
+ ## 0.10.2-alpha.2
23
+
24
+ ### Patch Changes
25
+
26
+ - f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra
package/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
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
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
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.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # @mastra/schema-compat
2
+
3
+ Schema compatibility layer for Mastra.ai that provides compatibility fixes for different AI model providers when using Zod schemas with tools.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @mastra/schema-compat
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Usage
14
+
15
+ The package provides a base `SchemaCompatLayer` class that you can extend to create custom compatibility layers for different AI model providers:
16
+
17
+ ```typescript
18
+ import { SchemaCompatLayer } from '@mastra/schema-compat';
19
+ import type { LanguageModelV1 } from 'ai';
20
+
21
+ class MyCustomCompat extends SchemaCompatLayer {
22
+ constructor(model: LanguageModelV1) {
23
+ super(model);
24
+ }
25
+
26
+ shouldApply(): boolean {
27
+ return this.getModel().provider === 'my-provider';
28
+ }
29
+
30
+ getSchemaTarget() {
31
+ return 'jsonSchema7';
32
+ }
33
+
34
+ processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
35
+ // Your custom processing logic here
36
+ return value;
37
+ }
38
+ }
39
+ ```
40
+
41
+ ### Schema Processing
42
+
43
+ The package includes pre-built compatibility layers for popular AI providers:
44
+
45
+ Use the `applyCompatLayer` function to automatically apply the right compatibility layer:
46
+
47
+ ```typescript
48
+ import { applyCompatLayer, OpenAISchemaCompatLayer, AnthropicSchemaCompatLayer } from '@mastra/schema-compat';
49
+ import { yourCustomCompatibilityLayer } from './customCompatibilityLayer';
50
+ import { z } from 'zod';
51
+
52
+ const schema = z.object({
53
+ name: z.string().email(),
54
+ preferences: z.array(z.string()).min(1),
55
+ });
56
+
57
+ const compatLayers = [
58
+ new OpenAISchemaCompatLayer(model),
59
+ new AnthropicSchemaCompatLayer(model),
60
+ new yourCustomCompatibilityLayer(model),
61
+ ];
62
+
63
+ // Automatically applies the first matching compatibility
64
+ const result = applyCompatLayer({
65
+ schema,
66
+ compatLayers,
67
+ mode: 'aiSdkSchema', // or 'jsonSchema'
68
+ });
69
+ ```
70
+
71
+ ### Schema Building Utilities
72
+
73
+ The package also provides utility functions for schema conversion:
74
+
75
+ ```typescript
76
+ import { convertZodSchemaToAISDKSchema, convertSchemaToZod } from '@mastra/schema-compat';
77
+ import { z } from 'zod';
78
+ import { jsonSchema } from 'ai';
79
+
80
+ const zodSchema = z.object({
81
+ name: z.string(),
82
+ age: z.number(),
83
+ });
84
+
85
+ // Convert Zod to AI SDK Schema
86
+ const aiSchema = convertZodSchemaToAISDKSchema(zodSchema);
87
+
88
+ // Convert AI SDK Schema back to Zod
89
+ const aiSdkSchema = jsonSchema({
90
+ type: 'object',
91
+ properties: {
92
+ name: { type: 'string' },
93
+ },
94
+ });
95
+ const backToZod = convertSchemaToZod(aiSdkSchema);
96
+ ```
97
+
98
+ ## API Reference
99
+
100
+ ### Classes
101
+
102
+ - `SchemaCompatLayer` - Base abstract class for creating compatibility layers
103
+ - `AnthropicSchemaCompatLayer` - Compatibility for Anthropic Claude models
104
+ - `OpenAISchemaCompatLayer` - Compatibility for OpenAI models (without structured outputs)
105
+ - `OpenAIReasoningSchemaCompatLayer` - Compatibility for OpenAI reasoning models (o1 series)
106
+ - `GoogleSchemaCompatLayer` - Compatibility for Google Gemini models
107
+ - `DeepSeekSchemaCompatLayer` - Compatibility for DeepSeek models
108
+ - `MetaSchemaCompatLayer` - Compatibility for Meta Llama models
109
+
110
+ ### Functions
111
+
112
+ - `applyCompatLayer(options)` - Process schema with automatic compatibility detection
113
+ - `convertZodSchemaToAISDKSchema(zodSchema, target?)` - Convert Zod schema to AI SDK Schema
114
+ - `convertSchemaToZod(schema)` - Convert AI SDK Schema to Zod schema
115
+
116
+ ### Types and Constants
117
+
118
+ - `StringCheckType`, `NumberCheckType`, `ArrayCheckType` - Check types for validation
119
+ - `UnsupportedZodType`, `SupportedZodType`, `AllZodType` - Zod type classifications
120
+ - `ZodShape`, `ShapeKey`, `ShapeValue` - Utility types for Zod schemas
121
+ - `ALL_STRING_CHECKS`, `ALL_NUMBER_CHECKS`, `ALL_ARRAY_CHECKS` - Validation constraint arrays
122
+ - `SUPPORTED_ZOD_TYPES`, `UNSUPPORTED_ZOD_TYPES` - Type classification arrays
123
+
124
+ ## Provider-Specific Behavior
125
+
126
+ Different AI providers have varying levels of support for JSON Schema features. This package handles these differences automatically:
127
+
128
+ - **OpenAI**: Removes certain string validations for models without structured outputs
129
+ - **Anthropic**: Handles complex nested schemas with proper constraint descriptions
130
+ - **Google**: Uses OpenAPI 3.0 schema format for better compatibility
131
+ - **DeepSeek**: Converts advanced string patterns to descriptions
132
+ - **Meta**: Optimizes array and union type handling
133
+
134
+ ## Testing
135
+
136
+ The package includes comprehensive tests covering all functionality:
137
+
138
+ ```bash
139
+ # Run tests
140
+ pnpm test
141
+
142
+ # Run tests in watch mode
143
+ pnpm test --watch
144
+ ```
145
+
146
+ ## License
147
+
148
+ Elastic-2.0