mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:51:23 +00:00
Revert "fix: flatten remaining anyOf/oneOf in Gemini schema cleaning"
This reverts commit 06b961b037.
This commit is contained in:
@@ -207,36 +207,6 @@ function simplifyUnionVariants(params: { obj: Record<string, unknown>; variants:
|
||||
return { variants: stripped ? nonNullVariants : variants };
|
||||
}
|
||||
|
||||
function flattenUnionFallback(
|
||||
obj: Record<string, unknown>,
|
||||
value: unknown,
|
||||
): Record<string, unknown> | undefined {
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
const variants = (value as Record<string, unknown>[]).filter((v) => v && typeof v === "object");
|
||||
const types = new Set(variants.map((v) => v.type).filter(Boolean));
|
||||
if (variants.length === 1) {
|
||||
const merged: Record<string, unknown> = { ...variants[0] };
|
||||
copySchemaMeta(obj, merged);
|
||||
return merged;
|
||||
}
|
||||
if (types.size === 1) {
|
||||
const merged: Record<string, unknown> = { type: Array.from(types)[0] };
|
||||
copySchemaMeta(obj, merged);
|
||||
return merged;
|
||||
}
|
||||
const first = variants[0];
|
||||
if (first?.type) {
|
||||
const merged: Record<string, unknown> = { type: first.type };
|
||||
copySchemaMeta(obj, merged);
|
||||
return merged;
|
||||
}
|
||||
const merged: Record<string, unknown> = {};
|
||||
copySchemaMeta(obj, merged);
|
||||
return merged;
|
||||
}
|
||||
|
||||
function cleanSchemaForGeminiWithDefs(
|
||||
schema: unknown,
|
||||
defs: SchemaDefs | undefined,
|
||||
@@ -369,20 +339,6 @@ function cleanSchemaForGeminiWithDefs(
|
||||
}
|
||||
}
|
||||
|
||||
// Cloud Code Assist API also rejects anyOf/oneOf in nested schemas.
|
||||
// If simplifyUnionVariants couldn't reduce the union above, flatten it
|
||||
// here as a fallback: pick the first variant's type or use a permissive
|
||||
// schema so the tool declaration is accepted.
|
||||
const flattenedAnyOf = flattenUnionFallback(cleaned, cleaned.anyOf);
|
||||
if (flattenedAnyOf) {
|
||||
return flattenedAnyOf;
|
||||
}
|
||||
|
||||
const flattenedOneOf = flattenUnionFallback(cleaned, cleaned.oneOf);
|
||||
if (flattenedOneOf) {
|
||||
return flattenedOneOf;
|
||||
}
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user