fix: preserve openai properties maps

This commit is contained in:
Eva
2026-04-10 21:14:12 +07:00
committed by Peter Steinberger
parent 626eaf8496
commit 4a20e9f257
2 changed files with 40 additions and 1 deletions

View File

@@ -72,6 +72,35 @@ describe("buildProviderToolCompatFamilyHooks", () => {
).toEqual([]);
});
it("preserves explicit empty properties maps when normalizing strict openai schemas", () => {
const hooks = buildProviderToolCompatFamilyHooks("openai");
const parameters = {
type: "object",
properties: {},
};
const tools = [{ name: "ping", description: "", parameters }] as never;
const normalized = hooks.normalizeToolSchemas({
provider: "openai",
modelId: "gpt-5.4",
modelApi: "openai-responses",
model: {
provider: "openai",
api: "openai-responses",
baseUrl: "https://api.openai.com/v1",
id: "gpt-5.4",
} as never,
tools,
});
expect(normalized[0]?.parameters).toEqual({
type: "object",
properties: {},
required: [],
additionalProperties: false,
});
});
it("does not tighten permissive object schemas just to satisfy strict mode", () => {
const hooks = buildProviderToolCompatFamilyHooks("openai");
const permissiveParameters = {

View File

@@ -229,7 +229,17 @@ function normalizeOpenAIStrictCompatSchemaRecursive(schema: unknown): unknown {
let changed = false;
const normalized: Record<string, unknown> = {};
for (const [key, value] of Object.entries(record)) {
const next = normalizeOpenAIStrictCompatSchemaRecursive(value);
const next =
key === "properties" && value && typeof value === "object" && !Array.isArray(value)
? Object.fromEntries(
Object.entries(value as Record<string, unknown>).map(
([propertyName, propertyValue]) => [
propertyName,
normalizeOpenAIStrictCompatSchemaRecursive(propertyValue),
],
),
)
: normalizeOpenAIStrictCompatSchemaRecursive(value);
normalized[key] = next;
changed ||= next !== value;
}