fix(antigravity): inject required placeholder when properties exist without required

This commit is contained in:
Supra4E8C
2025-12-29 23:55:59 +08:00
parent 3099114cbb
commit 06ddf575d9

View File

@@ -344,7 +344,7 @@ func cleanupRequiredFields(jsonStr string) string {
} }
// addEmptySchemaPlaceholder adds a placeholder "reason" property to empty object schemas. // addEmptySchemaPlaceholder adds a placeholder "reason" property to empty object schemas.
// Claude VALIDATED mode requires at least one property in tool schemas. // Claude VALIDATED mode requires at least one required property in tool schemas.
func addEmptySchemaPlaceholder(jsonStr string) string { func addEmptySchemaPlaceholder(jsonStr string) string {
// Find all "type" fields // Find all "type" fields
paths := findPaths(jsonStr, "type") paths := findPaths(jsonStr, "type")
@@ -364,6 +364,9 @@ func addEmptySchemaPlaceholder(jsonStr string) string {
// Check if properties exists and is empty or missing // Check if properties exists and is empty or missing
propsPath := joinPath(parentPath, "properties") propsPath := joinPath(parentPath, "properties")
propsVal := gjson.Get(jsonStr, propsPath) propsVal := gjson.Get(jsonStr, propsPath)
reqPath := joinPath(parentPath, "required")
reqVal := gjson.Get(jsonStr, reqPath)
hasRequiredProperties := reqVal.IsArray() && len(reqVal.Array()) > 0
needsPlaceholder := false needsPlaceholder := false
if !propsVal.Exists() { if !propsVal.Exists() {
@@ -381,8 +384,17 @@ func addEmptySchemaPlaceholder(jsonStr string) string {
jsonStr, _ = sjson.Set(jsonStr, reasonPath+".description", "Brief explanation of why you are calling this tool") jsonStr, _ = sjson.Set(jsonStr, reasonPath+".description", "Brief explanation of why you are calling this tool")
// Add to required array // Add to required array
reqPath := joinPath(parentPath, "required")
jsonStr, _ = sjson.Set(jsonStr, reqPath, []string{"reason"}) jsonStr, _ = sjson.Set(jsonStr, reqPath, []string{"reason"})
continue
}
// If schema has properties but none are required, add a minimal placeholder.
if propsVal.IsObject() && !hasRequiredProperties {
placeholderPath := joinPath(propsPath, "_")
if !gjson.Get(jsonStr, placeholderPath).Exists() {
jsonStr, _ = sjson.Set(jsonStr, placeholderPath+".type", "boolean")
}
jsonStr, _ = sjson.Set(jsonStr, reqPath, []string{"_"})
} }
} }