mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
fix: preserve openai properties maps
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user