@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +131 -1
  2. package/README.md +0 -4
  3. package/dist/chunk-5WM4A32G.cjs +83 -0
  4. package/dist/chunk-5WM4A32G.cjs.map +1 -0
  5. package/dist/chunk-U2HXWNAF.js +77 -0
  6. package/dist/chunk-U2HXWNAF.js.map +1 -0
  7. package/dist/index.cjs +4560 -271
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +5 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +4558 -272
  12. package/dist/index.js.map +1 -1
  13. package/dist/json-schema.d.ts +4 -0
  14. package/dist/json-schema.d.ts.map +1 -0
  15. package/dist/provider-compats/anthropic.d.ts +6 -4
  16. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  17. package/dist/provider-compats/deepseek.d.ts +6 -4
  18. package/dist/provider-compats/deepseek.d.ts.map +1 -1
  19. package/dist/provider-compats/google.d.ts +6 -4
  20. package/dist/provider-compats/google.d.ts.map +1 -1
  21. package/dist/provider-compats/meta.d.ts +6 -4
  22. package/dist/provider-compats/meta.d.ts.map +1 -1
  23. package/dist/provider-compats/openai-reasoning.d.ts +6 -4
  24. package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
  25. package/dist/provider-compats/openai.d.ts +6 -4
  26. package/dist/provider-compats/openai.d.ts.map +1 -1
  27. package/dist/schema-compatibility-v3.d.ts +287 -0
  28. package/dist/schema-compatibility-v3.d.ts.map +1 -0
  29. package/dist/schema-compatibility-v4.d.ts +278 -0
  30. package/dist/schema-compatibility-v4.d.ts.map +1 -0
  31. package/dist/schema-compatibility.d.ts +81 -165
  32. package/dist/schema-compatibility.d.ts.map +1 -1
  33. package/dist/types.d.ts +7 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils-test-suite.d.ts +2 -0
  36. package/dist/utils-test-suite.d.ts.map +1 -0
  37. package/dist/utils.d.ts +18 -6
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/zod-to-json-test-suite.d.ts +6 -0
  40. package/dist/zod-to-json-test-suite.d.ts.map +1 -0
  41. package/dist/zod-to-json.cjs +12 -0
  42. package/dist/zod-to-json.cjs.map +1 -0
  43. package/dist/zod-to-json.d.ts +6 -0
  44. package/dist/zod-to-json.d.ts.map +1 -0
  45. package/dist/zod-to-json.js +3 -0
  46. package/dist/zod-to-json.js.map +1 -0
  47. package/dist/zodTypes.d.ts +21 -0
  48. package/dist/zodTypes.d.ts.map +1 -0
  49. package/package.json +33 -10
  50. package/.turbo/turbo-build.log +0 -4
  51. package/eslint.config.js +0 -6
  52. package/src/index.ts +0 -39
  53. package/src/provider-compats/anthropic.ts +0 -44
  54. package/src/provider-compats/deepseek.ts +0 -35
  55. package/src/provider-compats/google.ts +0 -63
  56. package/src/provider-compats/meta.ts +0 -36
  57. package/src/provider-compats/openai-reasoning.ts +0 -91
  58. package/src/provider-compats/openai.ts +0 -56
  59. package/src/provider-compats.test.ts +0 -312
  60. package/src/schema-compatibility.test.ts +0 -471
  61. package/src/schema-compatibility.ts +0 -588
  62. package/src/utils.test.ts +0 -434
  63. package/src/utils.ts +0 -205
  64. package/tsconfig.build.json +0 -9
  65. package/tsconfig.json +0 -5
  66. package/tsup.config.ts +0 -17
  67. package/vitest.config.ts +0 -7
@@ -1,56 +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 { StringCheckType } from '../schema-compatibility';
6
-
7
- export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
8
- constructor(model: LanguageModelV1) {
9
- super(model);
10
- }
11
-
12
- getSchemaTarget(): Targets | undefined {
13
- return `jsonSchema7`;
14
- }
15
-
16
- shouldApply(): boolean {
17
- if (
18
- !this.getModel().supportsStructuredOutputs &&
19
- (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
20
- ) {
21
- return true;
22
- }
23
-
24
- return false;
25
- }
26
-
27
- processZodType(value: ZodTypeAny): ZodTypeAny {
28
- if (isOptional(value)) {
29
- return this.defaultZodOptionalHandler(value, [
30
- 'ZodObject',
31
- 'ZodArray',
32
- 'ZodUnion',
33
- 'ZodString',
34
- 'ZodNever',
35
- 'ZodUndefined',
36
- 'ZodTuple',
37
- ]);
38
- } else if (isObj(value)) {
39
- return this.defaultZodObjectHandler(value);
40
- } else if (isUnion(value)) {
41
- return this.defaultZodUnionHandler(value);
42
- } else if (isArr(value)) {
43
- return this.defaultZodArrayHandler(value);
44
- } else if (isString(value)) {
45
- const model = this.getModel();
46
- const checks: StringCheckType[] = ['emoji'];
47
-
48
- if (model.modelId.includes('gpt-4o-mini')) {
49
- checks.push('regex');
50
- }
51
- return this.defaultZodStringHandler(value, checks);
52
- }
53
-
54
- return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodUndefined', 'ZodTuple']);
55
- }
56
- }
@@ -1,312 +0,0 @@
1
- import { MockLanguageModelV1 } from 'ai/test';
2
- import { describe, it, expect } from 'vitest';
3
- import { z } from 'zod';
4
- import {
5
- AnthropicSchemaCompatLayer,
6
- OpenAISchemaCompatLayer,
7
- OpenAIReasoningSchemaCompatLayer,
8
- GoogleSchemaCompatLayer,
9
- DeepSeekSchemaCompatLayer,
10
- MetaSchemaCompatLayer,
11
- } from './index';
12
-
13
- describe('Provider Compatibility Classes', () => {
14
- const mockModels = {
15
- anthropic: new MockLanguageModelV1({
16
- modelId: 'claude-3-sonnet-20240229',
17
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
18
- }),
19
- openai: new MockLanguageModelV1({
20
- modelId: 'openai/gpt-4',
21
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
22
- }),
23
- openaiReasoning: new MockLanguageModelV1({
24
- modelId: 'openai/o3-mini',
25
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
26
- }),
27
- google: new MockLanguageModelV1({
28
- modelId: 'gemini-pro',
29
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
30
- }),
31
- deepseek: new MockLanguageModelV1({
32
- modelId: 'deepseek-chat',
33
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
34
- }),
35
- meta: new MockLanguageModelV1({
36
- modelId: 'llama-3.1-405b-instruct',
37
- doGenerate: async () => ({ response: { id: 'test' } }) as any,
38
- }),
39
- };
40
-
41
- describe('AnthropicSchemaCompatLayer', () => {
42
- it('should apply for Anthropic models', () => {
43
- const compat = new AnthropicSchemaCompatLayer(mockModels.anthropic);
44
- expect(compat.shouldApply()).toBe(true);
45
- });
46
-
47
- it('should not apply for non-Anthropic models', () => {
48
- const compat = new AnthropicSchemaCompatLayer(mockModels.openai);
49
- expect(compat.shouldApply()).toBe(false);
50
- });
51
-
52
- it('should return correct schema target', () => {
53
- const compat = new AnthropicSchemaCompatLayer(mockModels.anthropic);
54
- expect(compat.getSchemaTarget()).toBe('jsonSchema7');
55
- });
56
-
57
- it('should process schemas correctly', () => {
58
- const compat = new AnthropicSchemaCompatLayer(mockModels.anthropic);
59
- const schema = z.object({
60
- text: z.string().min(1).max(100),
61
- count: z.number().min(1),
62
- });
63
-
64
- const result = compat.processToAISDKSchema(schema);
65
-
66
- expect(result).toHaveProperty('jsonSchema');
67
- expect(result).toHaveProperty('validate');
68
-
69
- const validData = {
70
- text: 'Hello, world!',
71
- count: 10,
72
- };
73
-
74
- const validationResult = result.validate!(validData);
75
- expect(typeof validationResult).toBe('object');
76
- expect(validationResult).toHaveProperty('success');
77
- });
78
- });
79
-
80
- describe('OpenAISchemaCompatLayer', () => {
81
- it('should apply for OpenAI models without structured outputs support', () => {
82
- const compat = new OpenAISchemaCompatLayer(mockModels.openai);
83
- expect(compat.shouldApply()).toBe(true);
84
- });
85
-
86
- it('should return correct schema target', () => {
87
- const compat = new OpenAISchemaCompatLayer(mockModels.openai);
88
- expect(compat.getSchemaTarget()).toBe('jsonSchema7');
89
- });
90
-
91
- it('should process complex schemas', () => {
92
- const compat = new OpenAISchemaCompatLayer(mockModels.openai);
93
- const schema = z.object({
94
- user: z.object({
95
- name: z.string().email(),
96
- preferences: z.array(z.enum(['dark', 'light'])),
97
- }),
98
- settings: z.record(z.boolean()),
99
- });
100
-
101
- const result = compat.processToAISDKSchema(schema);
102
-
103
- const validData = {
104
- user: {
105
- name: 'John Doe',
106
- preferences: ['dark'],
107
- },
108
- settings: {
109
- public: true,
110
- featured: false,
111
- },
112
- };
113
-
114
- expect(result).toHaveProperty('jsonSchema');
115
- expect(result).toHaveProperty('validate');
116
-
117
- const validationResult = result.validate!(validData);
118
- expect(typeof validationResult).toBe('object');
119
- expect(validationResult).toHaveProperty('success');
120
- });
121
- });
122
-
123
- describe('OpenAIReasoningSchemaCompatLayer', () => {
124
- it('should have consistent behavior', () => {
125
- const compat = new OpenAIReasoningSchemaCompatLayer(mockModels.openaiReasoning);
126
- expect(compat.shouldApply()).toBe(true);
127
- });
128
-
129
- it('should return correct schema target', () => {
130
- const compat = new OpenAIReasoningSchemaCompatLayer(mockModels.openaiReasoning);
131
- expect(compat.getSchemaTarget()).toBe('openApi3');
132
- });
133
- });
134
-
135
- describe('GoogleSchemaCompatLayer', () => {
136
- it('should have consistent behavior', () => {
137
- const compat = new GoogleSchemaCompatLayer(mockModels.google);
138
- expect(typeof compat.shouldApply()).toBe('boolean');
139
- });
140
-
141
- it('should return correct schema target', () => {
142
- const compat = new GoogleSchemaCompatLayer(mockModels.google);
143
- expect(compat.getSchemaTarget()).toBe('jsonSchema7');
144
- });
145
-
146
- it('should handle date types correctly', () => {
147
- const compat = new GoogleSchemaCompatLayer(mockModels.google);
148
- const schema = z.object({
149
- startDate: z.date(),
150
- endDate: z.date().optional(),
151
- title: z.string(),
152
- });
153
-
154
- const result = compat.processToAISDKSchema(schema);
155
-
156
- expect(result).toHaveProperty('jsonSchema');
157
- expect(result).toHaveProperty('validate');
158
-
159
- const validData = {
160
- startDate: new Date(),
161
- title: 'Hello, world!',
162
- };
163
-
164
- const validationResult = result.validate!(validData);
165
- expect(typeof validationResult).toBe('object');
166
- expect(validationResult).toHaveProperty('success');
167
- });
168
- });
169
-
170
- describe('DeepSeekSchemaCompatLayer', () => {
171
- it('should apply for DeepSeek models', () => {
172
- const compat = new DeepSeekSchemaCompatLayer(mockModels.deepseek);
173
- expect(compat.shouldApply()).toBe(true);
174
- });
175
-
176
- it('should not apply for non-DeepSeek models', () => {
177
- const compat = new DeepSeekSchemaCompatLayer(mockModels.openai);
178
- expect(compat.shouldApply()).toBe(false);
179
- });
180
-
181
- it('should return correct schema target', () => {
182
- const compat = new DeepSeekSchemaCompatLayer(mockModels.deepseek);
183
- expect(compat.getSchemaTarget()).toBe('jsonSchema7');
184
- });
185
-
186
- it('should handle string constraints', () => {
187
- const compat = new DeepSeekSchemaCompatLayer(mockModels.deepseek);
188
- const schema = z.object({
189
- email: z.string().email(),
190
- url: z.string().url(),
191
- uuid: z.string().uuid(),
192
- text: z.string().min(10).max(1000),
193
- });
194
-
195
- const result = compat.processToAISDKSchema(schema);
196
-
197
- expect(result).toHaveProperty('jsonSchema');
198
- expect(result).toHaveProperty('validate');
199
-
200
- const validData = {
201
- email: 'john@example.com',
202
- url: 'https://example.com',
203
- uuid: '123e4567-e89b-12d3-a456-426614174000',
204
- text: 'Hello, world!',
205
- };
206
-
207
- const validationResult = result.validate!(validData);
208
- expect(typeof validationResult).toBe('object');
209
- expect(validationResult).toHaveProperty('success');
210
- });
211
- });
212
-
213
- describe('MetaSchemaCompatLayer', () => {
214
- it('should have consistent behavior', () => {
215
- const compat = new MetaSchemaCompatLayer(mockModels.meta);
216
- expect(typeof compat.shouldApply()).toBe('boolean');
217
- });
218
-
219
- it('should return correct schema target', () => {
220
- const compat = new MetaSchemaCompatLayer(mockModels.meta);
221
- expect(compat.getSchemaTarget()).toBe('jsonSchema7');
222
- });
223
-
224
- it('should handle array and union types', () => {
225
- const compat = new MetaSchemaCompatLayer(mockModels.meta);
226
- const schema = z.object({
227
- tags: z.array(z.string()).min(1).max(10),
228
- status: z.union([z.literal('active'), z.literal('inactive')]),
229
- priority: z.enum(['low', 'medium', 'high']),
230
- });
231
-
232
- const result = compat.processToAISDKSchema(schema);
233
-
234
- expect(result).toHaveProperty('jsonSchema');
235
- expect(result).toHaveProperty('validate');
236
-
237
- const validData = {
238
- tags: ['tag1'],
239
- status: 'active',
240
- priority: 'high',
241
- };
242
-
243
- const validationResult = result.validate!(validData);
244
- expect(typeof validationResult).toBe('object');
245
- expect(validationResult).toHaveProperty('success');
246
- });
247
- });
248
-
249
- describe('Integration tests', () => {
250
- it('should handle schema processing across providers', () => {
251
- const complexSchema = z.object({
252
- user: z.object({
253
- name: z.string().min(1).max(100),
254
- email: z.string().email(),
255
- age: z.number().min(0).max(120).optional(),
256
- }),
257
- preferences: z.object({
258
- theme: z.enum(['light', 'dark']),
259
- notifications: z.boolean(),
260
- language: z.string().regex(/^[a-z]{2}$/),
261
- }),
262
- tags: z.array(z.string()).min(1).max(5),
263
- metadata: z.record(z.union([z.string(), z.number(), z.boolean()])),
264
- createdAt: z.date(),
265
- settings: z
266
- .object({
267
- public: z.boolean(),
268
- featured: z.boolean().optional(),
269
- })
270
- .optional(),
271
- });
272
-
273
- const providers = [
274
- new AnthropicSchemaCompatLayer(mockModels.anthropic),
275
- new OpenAISchemaCompatLayer(mockModels.openai),
276
- new OpenAIReasoningSchemaCompatLayer(mockModels.openaiReasoning),
277
- new GoogleSchemaCompatLayer(mockModels.google),
278
- new DeepSeekSchemaCompatLayer(mockModels.deepseek),
279
- new MetaSchemaCompatLayer(mockModels.meta),
280
- ];
281
-
282
- providers.forEach(provider => {
283
- const result = provider.processToAISDKSchema(complexSchema);
284
-
285
- expect(result).toHaveProperty('jsonSchema');
286
- expect(result).toHaveProperty('validate');
287
- expect(typeof result.validate).toBe('function');
288
-
289
- const validData = {
290
- user: {
291
- name: 'John Doe',
292
- email: 'john@example.com',
293
- },
294
- preferences: {
295
- theme: 'dark' as const,
296
- notifications: true,
297
- language: 'en',
298
- },
299
- tags: ['tag1'],
300
- metadata: {
301
- key1: 'value1',
302
- },
303
- createdAt: new Date(),
304
- };
305
-
306
- const validationResult = result.validate!(validData);
307
- expect(typeof validationResult).toBe('object');
308
- expect(validationResult).toHaveProperty('success');
309
- });
310
- });
311
- });
312
- });