@mastra/schema-compat 0.0.0-ai-v5-20250626003446 → 0.0.0-fix-fetch-workflow-runs-20250624231457
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 +7 -7
- package/CHANGELOG.md +16 -3
- package/dist/_tsup-dts-rollup.d.cts +12 -12
- package/dist/_tsup-dts-rollup.d.ts +12 -12
- package/dist/index.cjs +9 -17
- package/dist/index.js +9 -17
- package/package.json +7 -7
- package/src/provider-compats/anthropic.ts +5 -9
- 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 +4 -5
- package/src/provider-compats/openai.ts +5 -5
- package/src/provider-compats.test.ts +7 -7
- package/src/schema-compatibility.test.ts +5 -13
- package/src/schema-compatibility.ts +13 -7
- package/src/utils.test.ts +5 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/schema-compat@0.10.
|
|
2
|
+
> @mastra/schema-compat@0.10.3-alpha.1 build /home/runner/work/mastra/mastra/packages/schema-compat
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 1480ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/schema-compat/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 1431ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m21.59 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 138ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m20.96 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 138ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-fix-fetch-workflow-runs-20250624231457
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
8
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
9
|
+
|
|
10
|
+
## 0.10.3-alpha.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
15
|
+
|
|
16
|
+
## 0.10.3-alpha.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
6
19
|
|
|
7
|
-
-
|
|
20
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
8
21
|
|
|
9
22
|
## 0.10.2
|
|
10
23
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageModelV1 } from 'ai';
|
|
3
3
|
import type { Schema } from 'ai';
|
|
4
4
|
import type { Targets } from 'zod-to-json-schema';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -54,7 +54,7 @@ export { AllZodType }
|
|
|
54
54
|
export { AllZodType as AllZodType_alias_1 }
|
|
55
55
|
|
|
56
56
|
declare class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
57
|
-
constructor(model:
|
|
57
|
+
constructor(model: LanguageModelV1);
|
|
58
58
|
getSchemaTarget(): Targets | undefined;
|
|
59
59
|
shouldApply(): boolean;
|
|
60
60
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -170,7 +170,7 @@ declare type DateConstraints = {
|
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
declare class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
|
|
173
|
-
constructor(model:
|
|
173
|
+
constructor(model: LanguageModelV1);
|
|
174
174
|
getSchemaTarget(): Targets | undefined;
|
|
175
175
|
shouldApply(): boolean;
|
|
176
176
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -179,7 +179,7 @@ export { DeepSeekSchemaCompatLayer }
|
|
|
179
179
|
export { DeepSeekSchemaCompatLayer as DeepSeekSchemaCompatLayer_alias_1 }
|
|
180
180
|
|
|
181
181
|
declare class GoogleSchemaCompatLayer extends SchemaCompatLayer {
|
|
182
|
-
constructor(model:
|
|
182
|
+
constructor(model: LanguageModelV1);
|
|
183
183
|
getSchemaTarget(): Targets | undefined;
|
|
184
184
|
shouldApply(): boolean;
|
|
185
185
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -216,7 +216,7 @@ export { isUnion }
|
|
|
216
216
|
export { isUnion as isUnion_alias_1 }
|
|
217
217
|
|
|
218
218
|
declare class MetaSchemaCompatLayer extends SchemaCompatLayer {
|
|
219
|
-
constructor(model:
|
|
219
|
+
constructor(model: LanguageModelV1);
|
|
220
220
|
getSchemaTarget(): Targets | undefined;
|
|
221
221
|
shouldApply(): boolean;
|
|
222
222
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -240,7 +240,7 @@ declare type NumberConstraints = {
|
|
|
240
240
|
};
|
|
241
241
|
|
|
242
242
|
declare class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
243
|
-
constructor(model:
|
|
243
|
+
constructor(model: LanguageModelV1);
|
|
244
244
|
getSchemaTarget(): Targets | undefined;
|
|
245
245
|
isReasoningModel(): boolean;
|
|
246
246
|
shouldApply(): boolean;
|
|
@@ -250,7 +250,7 @@ export { OpenAIReasoningSchemaCompatLayer }
|
|
|
250
250
|
export { OpenAIReasoningSchemaCompatLayer as OpenAIReasoningSchemaCompatLayer_alias_1 }
|
|
251
251
|
|
|
252
252
|
declare class OpenAISchemaCompatLayer extends SchemaCompatLayer {
|
|
253
|
-
constructor(model:
|
|
253
|
+
constructor(model: LanguageModelV1);
|
|
254
254
|
getSchemaTarget(): Targets | undefined;
|
|
255
255
|
shouldApply(): boolean;
|
|
256
256
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -304,13 +304,13 @@ declare abstract class SchemaCompatLayer {
|
|
|
304
304
|
*
|
|
305
305
|
* @param model - The language model this compatibility layer applies to
|
|
306
306
|
*/
|
|
307
|
-
constructor(model:
|
|
307
|
+
constructor(model: LanguageModelV1);
|
|
308
308
|
/**
|
|
309
309
|
* Gets the language model associated with this compatibility layer.
|
|
310
310
|
*
|
|
311
311
|
* @returns The language model instance
|
|
312
312
|
*/
|
|
313
|
-
getModel():
|
|
313
|
+
getModel(): LanguageModelV1;
|
|
314
314
|
/**
|
|
315
315
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
316
316
|
*
|
|
@@ -339,7 +339,9 @@ declare abstract class SchemaCompatLayer {
|
|
|
339
339
|
* @param value - The Zod object to process
|
|
340
340
|
* @returns The processed Zod object
|
|
341
341
|
*/
|
|
342
|
-
defaultZodObjectHandler(value: ZodObject<any, any, any
|
|
342
|
+
defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
|
|
343
|
+
passthrough?: boolean;
|
|
344
|
+
}): ZodObject<any, any, any>;
|
|
343
345
|
/**
|
|
344
346
|
* Merges validation constraints into a parameter description.
|
|
345
347
|
*
|
|
@@ -427,8 +429,6 @@ declare abstract class SchemaCompatLayer {
|
|
|
427
429
|
export { SchemaCompatLayer }
|
|
428
430
|
export { SchemaCompatLayer as SchemaCompatLayer_alias_1 }
|
|
429
431
|
|
|
430
|
-
export declare type SchemaCompatModel = Exclude<LanguageModel, string>;
|
|
431
|
-
|
|
432
432
|
/**
|
|
433
433
|
* Utility type to extract the keys from a Zod object shape.
|
|
434
434
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageModelV1 } from 'ai';
|
|
3
3
|
import type { Schema } from 'ai';
|
|
4
4
|
import type { Targets } from 'zod-to-json-schema';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -54,7 +54,7 @@ export { AllZodType }
|
|
|
54
54
|
export { AllZodType as AllZodType_alias_1 }
|
|
55
55
|
|
|
56
56
|
declare class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
57
|
-
constructor(model:
|
|
57
|
+
constructor(model: LanguageModelV1);
|
|
58
58
|
getSchemaTarget(): Targets | undefined;
|
|
59
59
|
shouldApply(): boolean;
|
|
60
60
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -170,7 +170,7 @@ declare type DateConstraints = {
|
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
declare class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
|
|
173
|
-
constructor(model:
|
|
173
|
+
constructor(model: LanguageModelV1);
|
|
174
174
|
getSchemaTarget(): Targets | undefined;
|
|
175
175
|
shouldApply(): boolean;
|
|
176
176
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -179,7 +179,7 @@ export { DeepSeekSchemaCompatLayer }
|
|
|
179
179
|
export { DeepSeekSchemaCompatLayer as DeepSeekSchemaCompatLayer_alias_1 }
|
|
180
180
|
|
|
181
181
|
declare class GoogleSchemaCompatLayer extends SchemaCompatLayer {
|
|
182
|
-
constructor(model:
|
|
182
|
+
constructor(model: LanguageModelV1);
|
|
183
183
|
getSchemaTarget(): Targets | undefined;
|
|
184
184
|
shouldApply(): boolean;
|
|
185
185
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -216,7 +216,7 @@ export { isUnion }
|
|
|
216
216
|
export { isUnion as isUnion_alias_1 }
|
|
217
217
|
|
|
218
218
|
declare class MetaSchemaCompatLayer extends SchemaCompatLayer {
|
|
219
|
-
constructor(model:
|
|
219
|
+
constructor(model: LanguageModelV1);
|
|
220
220
|
getSchemaTarget(): Targets | undefined;
|
|
221
221
|
shouldApply(): boolean;
|
|
222
222
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -240,7 +240,7 @@ declare type NumberConstraints = {
|
|
|
240
240
|
};
|
|
241
241
|
|
|
242
242
|
declare class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
243
|
-
constructor(model:
|
|
243
|
+
constructor(model: LanguageModelV1);
|
|
244
244
|
getSchemaTarget(): Targets | undefined;
|
|
245
245
|
isReasoningModel(): boolean;
|
|
246
246
|
shouldApply(): boolean;
|
|
@@ -250,7 +250,7 @@ export { OpenAIReasoningSchemaCompatLayer }
|
|
|
250
250
|
export { OpenAIReasoningSchemaCompatLayer as OpenAIReasoningSchemaCompatLayer_alias_1 }
|
|
251
251
|
|
|
252
252
|
declare class OpenAISchemaCompatLayer extends SchemaCompatLayer {
|
|
253
|
-
constructor(model:
|
|
253
|
+
constructor(model: LanguageModelV1);
|
|
254
254
|
getSchemaTarget(): Targets | undefined;
|
|
255
255
|
shouldApply(): boolean;
|
|
256
256
|
processZodType(value: ZodTypeAny): ZodTypeAny;
|
|
@@ -304,13 +304,13 @@ declare abstract class SchemaCompatLayer {
|
|
|
304
304
|
*
|
|
305
305
|
* @param model - The language model this compatibility layer applies to
|
|
306
306
|
*/
|
|
307
|
-
constructor(model:
|
|
307
|
+
constructor(model: LanguageModelV1);
|
|
308
308
|
/**
|
|
309
309
|
* Gets the language model associated with this compatibility layer.
|
|
310
310
|
*
|
|
311
311
|
* @returns The language model instance
|
|
312
312
|
*/
|
|
313
|
-
getModel():
|
|
313
|
+
getModel(): LanguageModelV1;
|
|
314
314
|
/**
|
|
315
315
|
* Determines whether this compatibility layer should be applied for the current model.
|
|
316
316
|
*
|
|
@@ -339,7 +339,9 @@ declare abstract class SchemaCompatLayer {
|
|
|
339
339
|
* @param value - The Zod object to process
|
|
340
340
|
* @returns The processed Zod object
|
|
341
341
|
*/
|
|
342
|
-
defaultZodObjectHandler(value: ZodObject<any, any, any
|
|
342
|
+
defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
|
|
343
|
+
passthrough?: boolean;
|
|
344
|
+
}): ZodObject<any, any, any>;
|
|
343
345
|
/**
|
|
344
346
|
* Merges validation constraints into a parameter description.
|
|
345
347
|
*
|
|
@@ -427,8 +429,6 @@ declare abstract class SchemaCompatLayer {
|
|
|
427
429
|
export { SchemaCompatLayer }
|
|
428
430
|
export { SchemaCompatLayer as SchemaCompatLayer_alias_1 }
|
|
429
431
|
|
|
430
|
-
export declare type SchemaCompatModel = Exclude<LanguageModel, string>;
|
|
431
|
-
|
|
432
432
|
/**
|
|
433
433
|
* Utility type to extract the keys from a Zod object shape.
|
|
434
434
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -115,7 +115,7 @@ var SchemaCompatLayer = class {
|
|
|
115
115
|
* @param value - The Zod object to process
|
|
116
116
|
* @returns The processed Zod object
|
|
117
117
|
*/
|
|
118
|
-
defaultZodObjectHandler(value) {
|
|
118
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
119
119
|
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
120
120
|
acc[key] = this.processZodType(propValue);
|
|
121
121
|
return acc;
|
|
@@ -130,6 +130,9 @@ var SchemaCompatLayer = class {
|
|
|
130
130
|
if (value.description) {
|
|
131
131
|
result = result.describe(value.description);
|
|
132
132
|
}
|
|
133
|
+
if (options.passthrough && value._def.unknownKeys === "passthrough") {
|
|
134
|
+
result = result.passthrough();
|
|
135
|
+
}
|
|
133
136
|
return result;
|
|
134
137
|
}
|
|
135
138
|
/**
|
|
@@ -425,9 +428,8 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
425
428
|
}
|
|
426
429
|
processZodType(value) {
|
|
427
430
|
if (isOptional(value)) {
|
|
428
|
-
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
431
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
|
|
429
432
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
430
|
-
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
431
433
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
432
434
|
} else if (isObj(value)) {
|
|
433
435
|
return this.defaultZodObjectHandler(value);
|
|
@@ -442,11 +444,7 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
442
444
|
return value;
|
|
443
445
|
}
|
|
444
446
|
}
|
|
445
|
-
|
|
446
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
447
|
-
} else {
|
|
448
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
449
|
-
}
|
|
447
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
450
448
|
}
|
|
451
449
|
};
|
|
452
450
|
|
|
@@ -551,10 +549,7 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
551
549
|
return `jsonSchema7`;
|
|
552
550
|
}
|
|
553
551
|
shouldApply() {
|
|
554
|
-
if (
|
|
555
|
-
// !this.getModel().supportsStructuredOutputs && // <- TODO: this no longer exists, do we need it?
|
|
556
|
-
this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`)
|
|
557
|
-
) {
|
|
552
|
+
if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
558
553
|
return true;
|
|
559
554
|
}
|
|
560
555
|
return false;
|
|
@@ -598,10 +593,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
598
593
|
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
|
|
599
594
|
}
|
|
600
595
|
shouldApply() {
|
|
601
|
-
if (
|
|
602
|
-
// (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && // <- supportsStructuredOutputs no longer exists
|
|
603
|
-
this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
|
|
604
|
-
) {
|
|
596
|
+
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
605
597
|
return true;
|
|
606
598
|
}
|
|
607
599
|
return false;
|
|
@@ -611,7 +603,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
611
603
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
612
604
|
return innerZodType.nullable();
|
|
613
605
|
} else if (isObj(value)) {
|
|
614
|
-
return this.defaultZodObjectHandler(value);
|
|
606
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
615
607
|
} else if (isArr(value)) {
|
|
616
608
|
return this.defaultZodArrayHandler(value);
|
|
617
609
|
} else if (isUnion(value)) {
|
package/dist/index.js
CHANGED
|
@@ -113,7 +113,7 @@ var SchemaCompatLayer = class {
|
|
|
113
113
|
* @param value - The Zod object to process
|
|
114
114
|
* @returns The processed Zod object
|
|
115
115
|
*/
|
|
116
|
-
defaultZodObjectHandler(value) {
|
|
116
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
117
117
|
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
118
118
|
acc[key] = this.processZodType(propValue);
|
|
119
119
|
return acc;
|
|
@@ -128,6 +128,9 @@ var SchemaCompatLayer = class {
|
|
|
128
128
|
if (value.description) {
|
|
129
129
|
result = result.describe(value.description);
|
|
130
130
|
}
|
|
131
|
+
if (options.passthrough && value._def.unknownKeys === "passthrough") {
|
|
132
|
+
result = result.passthrough();
|
|
133
|
+
}
|
|
131
134
|
return result;
|
|
132
135
|
}
|
|
133
136
|
/**
|
|
@@ -423,9 +426,8 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
423
426
|
}
|
|
424
427
|
processZodType(value) {
|
|
425
428
|
if (isOptional(value)) {
|
|
426
|
-
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
429
|
+
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined", "ZodTuple"];
|
|
427
430
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
428
|
-
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
429
431
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
430
432
|
} else if (isObj(value)) {
|
|
431
433
|
return this.defaultZodObjectHandler(value);
|
|
@@ -440,11 +442,7 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
440
442
|
return value;
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
|
-
|
|
444
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
445
|
-
} else {
|
|
446
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
447
|
-
}
|
|
445
|
+
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
448
446
|
}
|
|
449
447
|
};
|
|
450
448
|
|
|
@@ -549,10 +547,7 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
549
547
|
return `jsonSchema7`;
|
|
550
548
|
}
|
|
551
549
|
shouldApply() {
|
|
552
|
-
if (
|
|
553
|
-
// !this.getModel().supportsStructuredOutputs && // <- TODO: this no longer exists, do we need it?
|
|
554
|
-
this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`)
|
|
555
|
-
) {
|
|
550
|
+
if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
556
551
|
return true;
|
|
557
552
|
}
|
|
558
553
|
return false;
|
|
@@ -596,10 +591,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
596
591
|
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
|
|
597
592
|
}
|
|
598
593
|
shouldApply() {
|
|
599
|
-
if (
|
|
600
|
-
// (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && // <- supportsStructuredOutputs no longer exists
|
|
601
|
-
this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
|
|
602
|
-
) {
|
|
594
|
+
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
603
595
|
return true;
|
|
604
596
|
}
|
|
605
597
|
return false;
|
|
@@ -609,7 +601,7 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
609
601
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
610
602
|
return innerZodType.nullable();
|
|
611
603
|
} else if (isObj(value)) {
|
|
612
|
-
return this.defaultZodObjectHandler(value);
|
|
604
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
613
605
|
} else if (isArr(value)) {
|
|
614
606
|
return this.defaultZodArrayHandler(value);
|
|
615
607
|
} else if (isUnion(value)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/schema-compat",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-fix-fetch-workflow-runs-20250624231457",
|
|
4
4
|
"description": "Tool schema compatibility layer for Mastra.ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
"zod-to-json-schema": "^3.24.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"ai": "
|
|
36
|
+
"ai": "^4.0.0",
|
|
37
37
|
"zod": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/json-schema": "^7.0.15",
|
|
41
|
-
"ai": "5.0.0-beta.1",
|
|
42
|
-
"eslint": "^9.28.0",
|
|
43
|
-
"tsup": "^8.5.0",
|
|
44
41
|
"@types/node": "^20.19.0",
|
|
42
|
+
"ai": "4.3.16",
|
|
43
|
+
"eslint": "^9.29.0",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
45
|
"typescript": "^5.8.3",
|
|
46
46
|
"vitest": "^3.2.3",
|
|
47
|
-
"zod": "^3.25.
|
|
48
|
-
"@internal/lint": "0.0.0-
|
|
47
|
+
"zod": "^3.25.67",
|
|
48
|
+
"@internal/lint": "0.0.0-fix-fetch-workflow-runs-20250624231457"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
4
|
-
import type { AllZodType
|
|
5
|
+
import type { AllZodType } from '../schema-compatibility';
|
|
5
6
|
|
|
6
7
|
export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model:
|
|
8
|
+
constructor(model: LanguageModelV1) {
|
|
8
9
|
super(model);
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -18,9 +19,8 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
18
19
|
|
|
19
20
|
processZodType(value: ZodTypeAny): ZodTypeAny {
|
|
20
21
|
if (isOptional(value)) {
|
|
21
|
-
const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined'];
|
|
22
|
+
const handleTypes: AllZodType[] = ['ZodObject', 'ZodArray', 'ZodUnion', 'ZodNever', 'ZodUndefined', 'ZodTuple'];
|
|
22
23
|
if (this.getModel().modelId.includes('claude-3.5-haiku')) handleTypes.push('ZodString');
|
|
23
|
-
if (this.getModel().modelId.includes('claude-3.7')) handleTypes.push('ZodTuple');
|
|
24
24
|
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
25
25
|
} else if (isObj(value)) {
|
|
26
26
|
return this.defaultZodObjectHandler(value);
|
|
@@ -39,10 +39,6 @@ export class AnthropicSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
|
|
44
|
-
} else {
|
|
45
|
-
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodUndefined']);
|
|
46
|
-
}
|
|
42
|
+
return this.defaultUnsupportedZodTypeHandler(value, ['ZodNever', 'ZodTuple', 'ZodUndefined']);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
4
|
-
import type { SchemaCompatModel } from '../schema-compatibility';
|
|
5
5
|
|
|
6
6
|
export class DeepSeekSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model:
|
|
7
|
+
constructor(model: LanguageModelV1) {
|
|
8
8
|
super(model);
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import {
|
|
@@ -10,10 +11,9 @@ import {
|
|
|
10
11
|
isString,
|
|
11
12
|
isUnion,
|
|
12
13
|
} from '../schema-compatibility';
|
|
13
|
-
import type { SchemaCompatModel } from '../schema-compatibility';
|
|
14
14
|
|
|
15
15
|
export class GoogleSchemaCompatLayer extends SchemaCompatLayer {
|
|
16
|
-
constructor(model:
|
|
16
|
+
constructor(model: LanguageModelV1) {
|
|
17
17
|
super(model);
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import { SchemaCompatLayer, isArr, isNumber, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
4
|
-
import type { SchemaCompatModel } from '../schema-compatibility';
|
|
5
5
|
|
|
6
6
|
export class MetaSchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model:
|
|
7
|
+
constructor(model: LanguageModelV1) {
|
|
8
8
|
super(model);
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import type { ZodTypeAny } from 'zod';
|
|
3
4
|
import type { Targets } from 'zod-to-json-schema';
|
|
@@ -12,10 +13,9 @@ import {
|
|
|
12
13
|
isString,
|
|
13
14
|
isUnion,
|
|
14
15
|
} from '../schema-compatibility';
|
|
15
|
-
import type { SchemaCompatModel } from '../schema-compatibility';
|
|
16
16
|
|
|
17
17
|
export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
18
|
-
constructor(model:
|
|
18
|
+
constructor(model: LanguageModelV1) {
|
|
19
19
|
super(model);
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -31,8 +31,7 @@ export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
31
31
|
|
|
32
32
|
shouldApply(): boolean {
|
|
33
33
|
if (
|
|
34
|
-
|
|
35
|
-
this.isReasoningModel() &&
|
|
34
|
+
(this.getModel().supportsStructuredOutputs || this.isReasoningModel()) &&
|
|
36
35
|
(this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
|
|
37
36
|
) {
|
|
38
37
|
return true;
|
|
@@ -46,7 +45,7 @@ export class OpenAIReasoningSchemaCompatLayer extends SchemaCompatLayer {
|
|
|
46
45
|
const innerZodType = this.processZodType(value._def.innerType);
|
|
47
46
|
return innerZodType.nullable();
|
|
48
47
|
} else if (isObj(value)) {
|
|
49
|
-
return this.defaultZodObjectHandler(value);
|
|
48
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
50
49
|
} else if (isArr(value)) {
|
|
51
50
|
return this.defaultZodArrayHandler(value);
|
|
52
51
|
} else if (isUnion(value)) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
1
2
|
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
import type { Targets } from 'zod-to-json-schema';
|
|
3
4
|
import { SchemaCompatLayer, isArr, isObj, isOptional, isString, isUnion } from '../schema-compatibility';
|
|
4
|
-
import type {
|
|
5
|
+
import type { StringCheckType } from '../schema-compatibility';
|
|
5
6
|
|
|
6
7
|
export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
|
|
7
|
-
constructor(model:
|
|
8
|
+
constructor(model: LanguageModelV1) {
|
|
8
9
|
super(model);
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -14,9 +15,8 @@ export class OpenAISchemaCompatLayer extends SchemaCompatLayer {
|
|
|
14
15
|
|
|
15
16
|
shouldApply(): boolean {
|
|
16
17
|
if (
|
|
17
|
-
|
|
18
|
-
this.getModel().provider.includes(`openai`) ||
|
|
19
|
-
this.getModel().modelId.includes(`openai`)
|
|
18
|
+
!this.getModel().supportsStructuredOutputs &&
|
|
19
|
+
(this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
|
|
20
20
|
) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MockLanguageModelV1 } from 'ai/test';
|
|
2
2
|
import { describe, it, expect } from 'vitest';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import {
|
|
@@ -12,27 +12,27 @@ import {
|
|
|
12
12
|
|
|
13
13
|
describe('Provider Compatibility Classes', () => {
|
|
14
14
|
const mockModels = {
|
|
15
|
-
anthropic: new
|
|
15
|
+
anthropic: new MockLanguageModelV1({
|
|
16
16
|
modelId: 'claude-3-sonnet-20240229',
|
|
17
17
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
18
18
|
}),
|
|
19
|
-
openai: new
|
|
19
|
+
openai: new MockLanguageModelV1({
|
|
20
20
|
modelId: 'openai/gpt-4',
|
|
21
21
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
22
22
|
}),
|
|
23
|
-
openaiReasoning: new
|
|
23
|
+
openaiReasoning: new MockLanguageModelV1({
|
|
24
24
|
modelId: 'openai/o3-mini',
|
|
25
25
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
26
26
|
}),
|
|
27
|
-
google: new
|
|
27
|
+
google: new MockLanguageModelV1({
|
|
28
28
|
modelId: 'gemini-pro',
|
|
29
29
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
30
30
|
}),
|
|
31
|
-
deepseek: new
|
|
31
|
+
deepseek: new MockLanguageModelV1({
|
|
32
32
|
modelId: 'deepseek-chat',
|
|
33
33
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
34
34
|
}),
|
|
35
|
-
meta: new
|
|
35
|
+
meta: new MockLanguageModelV1({
|
|
36
36
|
modelId: 'llama-3.1-405b-instruct',
|
|
37
37
|
doGenerate: async () => ({ response: { id: 'test' } }) as any,
|
|
38
38
|
}),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LanguageModelV1 } from 'ai';
|
|
2
|
+
import { MockLanguageModelV1 } from 'ai/test';
|
|
2
3
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
3
4
|
import { z } from 'zod';
|
|
4
|
-
import type { SchemaCompatModel } from './schema-compatibility';
|
|
5
5
|
import { isArr, isObj, isOptional, isString, isUnion, SchemaCompatLayer } from './schema-compatibility';
|
|
6
6
|
|
|
7
7
|
class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
8
|
-
constructor(model:
|
|
8
|
+
constructor(model: LanguageModelV1) {
|
|
9
9
|
super(model);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -36,8 +36,9 @@ class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const mockModel = new
|
|
39
|
+
const mockModel = new MockLanguageModelV1({
|
|
40
40
|
modelId: 'test-model',
|
|
41
|
+
defaultObjectGenerationMode: 'json',
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
describe('SchemaCompatLayer', () => {
|
|
@@ -382,11 +383,9 @@ describe('SchemaCompatLayer', () => {
|
|
|
382
383
|
expect(result.jsonSchema.type).toBe('array');
|
|
383
384
|
expect(result.jsonSchema.description).toContain('minLength');
|
|
384
385
|
// The validator itself should be gone
|
|
385
|
-
// TODO: success type is messed up in AI SDK V5 for us
|
|
386
386
|
expect(
|
|
387
387
|
result.validate?.([
|
|
388
388
|
/* empty array */
|
|
389
|
-
// @ts-expect-error
|
|
390
389
|
]).success,
|
|
391
390
|
).toBe(true);
|
|
392
391
|
|
|
@@ -407,7 +406,6 @@ describe('SchemaCompatLayer', () => {
|
|
|
407
406
|
expect(
|
|
408
407
|
preservingResult.validate?.([
|
|
409
408
|
/* empty array */
|
|
410
|
-
// @ts-expect-error
|
|
411
409
|
]).success,
|
|
412
410
|
).toBe(false); // validator preserved
|
|
413
411
|
});
|
|
@@ -439,9 +437,7 @@ describe('SchemaCompatLayer', () => {
|
|
|
439
437
|
.optional();
|
|
440
438
|
|
|
441
439
|
const result = compatibility.processToAISDKSchema(optionalSchema);
|
|
442
|
-
// @ts-expect-error
|
|
443
440
|
expect(result.validate!({ name: 'test' }).success).toBe(true);
|
|
444
|
-
// @ts-expect-error
|
|
445
441
|
expect(result.validate!(undefined).success).toBe(true);
|
|
446
442
|
|
|
447
443
|
const jsonSchema = result.jsonSchema;
|
|
@@ -452,9 +448,7 @@ describe('SchemaCompatLayer', () => {
|
|
|
452
448
|
it('should handle optional array schemas', () => {
|
|
453
449
|
const optionalSchema = z.array(z.string()).optional();
|
|
454
450
|
const result = compatibility.processToAISDKSchema(optionalSchema);
|
|
455
|
-
// @ts-expect-error
|
|
456
451
|
expect(result.validate!(['test']).success).toBe(true);
|
|
457
|
-
// @ts-expect-error
|
|
458
452
|
expect(result.validate!(undefined).success).toBe(true);
|
|
459
453
|
|
|
460
454
|
const jsonSchema = result.jsonSchema;
|
|
@@ -466,9 +460,7 @@ describe('SchemaCompatLayer', () => {
|
|
|
466
460
|
it('should handle optional scalar schemas', () => {
|
|
467
461
|
const optionalSchema = z.string().optional();
|
|
468
462
|
const result = compatibility.processToAISDKSchema(optionalSchema);
|
|
469
|
-
// @ts-expect-error
|
|
470
463
|
expect(result.validate!('test').success).toBe(true);
|
|
471
|
-
// @ts-expect-error
|
|
472
464
|
expect(result.validate!(undefined).success).toBe(true);
|
|
473
465
|
|
|
474
466
|
const jsonSchema = result.jsonSchema;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { Schema,
|
|
1
|
+
import type { Schema, LanguageModelV1 } from 'ai';
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
3
|
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault } from 'zod';
|
|
4
4
|
import type { ZodTypeAny } from 'zod';
|
|
5
5
|
import type { Targets } from 'zod-to-json-schema';
|
|
6
6
|
import { convertZodSchemaToAISDKSchema } from './utils';
|
|
7
7
|
|
|
8
|
-
export type SchemaCompatModel = Exclude<LanguageModel, string>;
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* All supported string validation check types that can be processed or converted to descriptions.
|
|
12
10
|
* @constant
|
|
@@ -183,14 +181,14 @@ type DateConstraints = {
|
|
|
183
181
|
* ```
|
|
184
182
|
*/
|
|
185
183
|
export abstract class SchemaCompatLayer {
|
|
186
|
-
private model:
|
|
184
|
+
private model: LanguageModelV1;
|
|
187
185
|
|
|
188
186
|
/**
|
|
189
187
|
* Creates a new schema compatibility instance.
|
|
190
188
|
*
|
|
191
189
|
* @param model - The language model this compatibility layer applies to
|
|
192
190
|
*/
|
|
193
|
-
constructor(model:
|
|
191
|
+
constructor(model: LanguageModelV1) {
|
|
194
192
|
this.model = model;
|
|
195
193
|
}
|
|
196
194
|
|
|
@@ -199,7 +197,7 @@ export abstract class SchemaCompatLayer {
|
|
|
199
197
|
*
|
|
200
198
|
* @returns The language model instance
|
|
201
199
|
*/
|
|
202
|
-
getModel():
|
|
200
|
+
getModel(): LanguageModelV1 {
|
|
203
201
|
return this.model;
|
|
204
202
|
}
|
|
205
203
|
|
|
@@ -234,7 +232,10 @@ export abstract class SchemaCompatLayer {
|
|
|
234
232
|
* @param value - The Zod object to process
|
|
235
233
|
* @returns The processed Zod object
|
|
236
234
|
*/
|
|
237
|
-
public defaultZodObjectHandler(
|
|
235
|
+
public defaultZodObjectHandler(
|
|
236
|
+
value: ZodObject<any, any, any>,
|
|
237
|
+
options: { passthrough?: boolean } = { passthrough: true },
|
|
238
|
+
): ZodObject<any, any, any> {
|
|
238
239
|
const processedShape = Object.entries(value.shape).reduce<Record<string, ZodTypeAny>>((acc, [key, propValue]) => {
|
|
239
240
|
acc[key] = this.processZodType(propValue as ZodTypeAny);
|
|
240
241
|
return acc;
|
|
@@ -252,6 +253,11 @@ export abstract class SchemaCompatLayer {
|
|
|
252
253
|
if (value.description) {
|
|
253
254
|
result = result.describe(value.description);
|
|
254
255
|
}
|
|
256
|
+
|
|
257
|
+
if (options.passthrough && value._def.unknownKeys === 'passthrough') {
|
|
258
|
+
result = result.passthrough();
|
|
259
|
+
}
|
|
260
|
+
|
|
255
261
|
return result;
|
|
256
262
|
}
|
|
257
263
|
|
package/src/utils.test.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { jsonSchema } from 'ai';
|
|
2
|
-
import type { Schema } from 'ai';
|
|
3
|
-
import {
|
|
2
|
+
import type { LanguageModelV1, Schema } from 'ai';
|
|
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 { SchemaCompatModel } from './schema-compatibility';
|
|
7
6
|
import { SchemaCompatLayer } from './schema-compatibility';
|
|
8
7
|
import { convertZodSchemaToAISDKSchema, convertSchemaToZod, applyCompatLayer } from './utils';
|
|
9
8
|
|
|
10
|
-
const mockModel = new
|
|
9
|
+
const mockModel = new MockLanguageModelV1({
|
|
11
10
|
modelId: 'test-model',
|
|
11
|
+
defaultObjectGenerationMode: 'json',
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
15
15
|
constructor(
|
|
16
|
-
model:
|
|
16
|
+
model: LanguageModelV1,
|
|
17
17
|
private shouldApplyValue: boolean = true,
|
|
18
18
|
) {
|
|
19
19
|
super(model);
|
|
@@ -66,20 +66,12 @@ describe('Builder Functions', () => {
|
|
|
66
66
|
expect(result.validate).toBeDefined();
|
|
67
67
|
|
|
68
68
|
const validResult = result.validate!({ email: 'test@example.com' });
|
|
69
|
-
// TODO: tool types are broken
|
|
70
|
-
// @ts-expect-error
|
|
71
69
|
expect(validResult.success).toBe(true);
|
|
72
|
-
// TODO: tool types are broken
|
|
73
|
-
// @ts-expect-error
|
|
74
70
|
if (validResult.success) {
|
|
75
|
-
// TODO: tool types are broken
|
|
76
|
-
// @ts-expect-error
|
|
77
71
|
expect(validResult.value).toEqual({ email: 'test@example.com' });
|
|
78
72
|
}
|
|
79
73
|
|
|
80
74
|
const invalidResult = result.validate!({ email: 'invalid-email' });
|
|
81
|
-
// TODO: tool types are broken
|
|
82
|
-
// @ts-expect-error
|
|
83
75
|
expect(invalidResult.success).toBe(false);
|
|
84
76
|
});
|
|
85
77
|
|