@mastra/schema-compat 0.10.6 → 0.10.7-alpha.0
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 +1 -1
- package/CHANGELOG.md +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/anthropic.d.ts +2 -2
- package/dist/provider-compats/anthropic.d.ts.map +1 -1
- package/dist/provider-compats/deepseek.d.ts +2 -2
- package/dist/provider-compats/deepseek.d.ts.map +1 -1
- package/dist/provider-compats/google.d.ts +2 -2
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/meta.d.ts +2 -2
- package/dist/provider-compats/meta.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts +2 -2
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts +2 -2
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +8 -3
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/provider-compats/anthropic.ts +2 -3
- package/src/provider-compats/deepseek.ts +2 -2
- package/src/provider-compats/google.ts +2 -2
- package/src/provider-compats/meta.ts +2 -2
- package/src/provider-compats/openai-reasoning.ts +7 -3
- package/src/provider-compats/openai.ts +2 -3
- package/src/provider-compats.test.ts +120 -25
- package/src/schema-compatibility.test.ts +22 -6
- package/src/schema-compatibility.ts +10 -4
- package/src/utils.test.ts +32 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Schema
|
|
1
|
+
import type { Schema } from 'ai';
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
3
|
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault, ZodNull } from 'zod';
|
|
4
4
|
import type { ZodTypeAny } from 'zod';
|
|
@@ -142,6 +142,12 @@ type DateConstraints = {
|
|
|
142
142
|
dateFormat?: string;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
export type ModelInformation = {
|
|
146
|
+
modelId: string;
|
|
147
|
+
provider: string;
|
|
148
|
+
supportsStructuredOutputs: boolean;
|
|
149
|
+
};
|
|
150
|
+
|
|
145
151
|
/**
|
|
146
152
|
* Abstract base class for creating schema compatibility layers for different AI model providers.
|
|
147
153
|
*
|
|
@@ -182,14 +188,14 @@ type DateConstraints = {
|
|
|
182
188
|
* ```
|
|
183
189
|
*/
|
|
184
190
|
export abstract class SchemaCompatLayer {
|
|
185
|
-
private model:
|
|
191
|
+
private model: ModelInformation;
|
|
186
192
|
|
|
187
193
|
/**
|
|
188
194
|
* Creates a new schema compatibility instance.
|
|
189
195
|
*
|
|
190
196
|
* @param model - The language model this compatibility layer applies to
|
|
191
197
|
*/
|
|
192
|
-
constructor(model:
|
|
198
|
+
constructor(model: ModelInformation) {
|
|
193
199
|
this.model = model;
|
|
194
200
|
}
|
|
195
201
|
|
|
@@ -198,7 +204,7 @@ export abstract class SchemaCompatLayer {
|
|
|
198
204
|
*
|
|
199
205
|
* @returns The language model instance
|
|
200
206
|
*/
|
|
201
|
-
getModel():
|
|
207
|
+
getModel(): ModelInformation {
|
|
202
208
|
return this.model;
|
|
203
209
|
}
|
|
204
210
|
|
package/src/utils.test.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsonSchema } from 'ai';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Schema } from 'ai';
|
|
3
3
|
import { MockLanguageModelV1 } from 'ai/test';
|
|
4
4
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import type { ModelInformation } from './schema-compatibility';
|
|
6
7
|
import { SchemaCompatLayer } from './schema-compatibility';
|
|
7
8
|
import { convertZodSchemaToAISDKSchema, convertSchemaToZod, applyCompatLayer } from './utils';
|
|
8
9
|
|
|
@@ -13,7 +14,7 @@ const mockModel = new MockLanguageModelV1({
|
|
|
13
14
|
|
|
14
15
|
class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
15
16
|
constructor(
|
|
16
|
-
model:
|
|
17
|
+
model: ModelInformation,
|
|
17
18
|
private shouldApplyValue: boolean = true,
|
|
18
19
|
) {
|
|
19
20
|
super(model);
|
|
@@ -191,7 +192,11 @@ describe('Builder Functions', () => {
|
|
|
191
192
|
let mockCompatibility: MockSchemaCompatibility;
|
|
192
193
|
|
|
193
194
|
beforeEach(() => {
|
|
194
|
-
mockCompatibility = new MockSchemaCompatibility(
|
|
195
|
+
mockCompatibility = new MockSchemaCompatibility({
|
|
196
|
+
modelId: mockModel.modelId,
|
|
197
|
+
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
198
|
+
provider: mockModel.provider,
|
|
199
|
+
});
|
|
195
200
|
});
|
|
196
201
|
|
|
197
202
|
it('should process Zod object schema with compatibility', () => {
|
|
@@ -257,7 +262,14 @@ describe('Builder Functions', () => {
|
|
|
257
262
|
});
|
|
258
263
|
|
|
259
264
|
it('should return fallback when no compatibility applies', () => {
|
|
260
|
-
const nonApplyingCompatibility = new MockSchemaCompatibility(
|
|
265
|
+
const nonApplyingCompatibility = new MockSchemaCompatibility(
|
|
266
|
+
{
|
|
267
|
+
modelId: mockModel.modelId,
|
|
268
|
+
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
269
|
+
provider: mockModel.provider,
|
|
270
|
+
},
|
|
271
|
+
false,
|
|
272
|
+
);
|
|
261
273
|
const zodSchema = z.object({
|
|
262
274
|
name: z.string(),
|
|
263
275
|
});
|
|
@@ -303,8 +315,22 @@ describe('Builder Functions', () => {
|
|
|
303
315
|
});
|
|
304
316
|
|
|
305
317
|
it('should handle complex schema with multiple compatLayers', () => {
|
|
306
|
-
const compat1 = new MockSchemaCompatibility(
|
|
307
|
-
|
|
318
|
+
const compat1 = new MockSchemaCompatibility(
|
|
319
|
+
{
|
|
320
|
+
modelId: mockModel.modelId,
|
|
321
|
+
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? true,
|
|
322
|
+
provider: mockModel.provider,
|
|
323
|
+
},
|
|
324
|
+
false,
|
|
325
|
+
);
|
|
326
|
+
const compat2 = new MockSchemaCompatibility(
|
|
327
|
+
{
|
|
328
|
+
modelId: mockModel.modelId,
|
|
329
|
+
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
330
|
+
provider: mockModel.provider,
|
|
331
|
+
},
|
|
332
|
+
true,
|
|
333
|
+
);
|
|
308
334
|
|
|
309
335
|
vi.spyOn(compat1, 'processZodType');
|
|
310
336
|
vi.spyOn(compat2, 'processZodType');
|