@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.
@@ -1,4 +1,4 @@
1
- import type { Schema, LanguageModelV1 } from 'ai';
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: LanguageModelV1;
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: LanguageModelV1) {
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(): LanguageModelV1 {
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 { LanguageModelV1, Schema } from 'ai';
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: LanguageModelV1,
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(mockModel);
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(mockModel, false);
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(mockModel, false);
307
- const compat2 = new MockSchemaCompatibility(mockModel, true);
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');