@mastra/schema-compat 1.0.0-beta.6 → 1.0.0-beta.7
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/openai.d.ts +15 -0
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed OpenAI schema validation error when using passthrough schemas with tools like `vectorQueryTool`. ([#11846](https://github.com/mastra-ai/mastra/pull/11846))
|
|
8
|
+
|
|
9
|
+
**What was happening:** Tools using `.passthrough()` or `z.looseObject()` schemas (like the RAG `vectorQueryTool`) would fail with OpenAI models, returning the error: "Invalid schema for function: In context=('additionalProperties',), schema must have a 'type' key."
|
|
10
|
+
|
|
11
|
+
**What changed:** The OpenAI schema compatibility layer now converts passthrough schemas to strict object schemas, producing valid `additionalProperties: false` instead of the invalid empty object `{}` that Zod v4 generates.
|
|
12
|
+
|
|
13
|
+
Fixes #11823
|
|
14
|
+
|
|
3
15
|
## 1.0.0-beta.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -4907,6 +4907,50 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
4907
4907
|
"ZodTuple"
|
|
4908
4908
|
]);
|
|
4909
4909
|
}
|
|
4910
|
+
/**
|
|
4911
|
+
* Override to fix additionalProperties: {} which OpenAI doesn't support.
|
|
4912
|
+
* Converts empty object {} to true to preserve passthrough intent.
|
|
4913
|
+
*/
|
|
4914
|
+
processToJSONSchema(zodSchema2) {
|
|
4915
|
+
const jsonSchema2 = super.processToJSONSchema(zodSchema2);
|
|
4916
|
+
return this.fixAdditionalProperties(jsonSchema2);
|
|
4917
|
+
}
|
|
4918
|
+
/**
|
|
4919
|
+
* Recursively fixes additionalProperties: {} to additionalProperties: true.
|
|
4920
|
+
* OpenAI requires additionalProperties to be either:
|
|
4921
|
+
* - false (no additional properties allowed)
|
|
4922
|
+
* - true (any additional properties allowed)
|
|
4923
|
+
* - an object with a "type" key (typed additional properties)
|
|
4924
|
+
* An empty object {} is NOT valid.
|
|
4925
|
+
*/
|
|
4926
|
+
fixAdditionalProperties(schema) {
|
|
4927
|
+
if (typeof schema !== "object" || schema === null) {
|
|
4928
|
+
return schema;
|
|
4929
|
+
}
|
|
4930
|
+
const result = { ...schema };
|
|
4931
|
+
if (result.additionalProperties !== void 0 && typeof result.additionalProperties === "object" && result.additionalProperties !== null && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length === 0) {
|
|
4932
|
+
result.additionalProperties = true;
|
|
4933
|
+
}
|
|
4934
|
+
if (result.properties) {
|
|
4935
|
+
result.properties = Object.fromEntries(
|
|
4936
|
+
Object.entries(result.properties).map(([key, value]) => [
|
|
4937
|
+
key,
|
|
4938
|
+
this.fixAdditionalProperties(value)
|
|
4939
|
+
])
|
|
4940
|
+
);
|
|
4941
|
+
}
|
|
4942
|
+
if (result.items) {
|
|
4943
|
+
if (Array.isArray(result.items)) {
|
|
4944
|
+
result.items = result.items.map((item) => this.fixAdditionalProperties(item));
|
|
4945
|
+
} else {
|
|
4946
|
+
result.items = this.fixAdditionalProperties(result.items);
|
|
4947
|
+
}
|
|
4948
|
+
}
|
|
4949
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties) && Object.keys(result.additionalProperties).length > 0) {
|
|
4950
|
+
result.additionalProperties = this.fixAdditionalProperties(result.additionalProperties);
|
|
4951
|
+
}
|
|
4952
|
+
return result;
|
|
4953
|
+
}
|
|
4910
4954
|
};
|
|
4911
4955
|
var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
4912
4956
|
constructor(model) {
|