Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix/gemini tool schema unsupported keys (#52670)
Om Chillureef4af8f92415
diff --git a/crates/language_model/src/tool_schema.rs b/crates/language_model/src/tool_schema.rsindex 6fbb3761b43..69afcd1f288 100644--- a/crates/language_model/src/tool_schema.rs+++ b/crates/language_model/src/tool_schema.rs@@ -105,9 +105,12 @@ fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {);}- const KEYS_TO_REMOVE: [(&str, fn(&Value) -> bool); 5] = [+ const KEYS_TO_REMOVE: [(&str, fn(&Value) -> bool); 6] = [("format", |value| value.is_string()),- ("additionalProperties", |value| value.is_boolean()),+ // Gemini doesn't support `additionalProperties` in any form (boolean or schema object)+ ("additionalProperties", |_| true),+ // Gemini doesn't support `propertyNames`+ ("propertyNames", |_| true),("exclusiveMinimum", |value| value.is_number()),("exclusiveMaximum", |value| value.is_number()),("optional", |value| value.is_boolean()),@@ -234,6 +237,28 @@ mod tests {"format": {},}));++ // additionalProperties as an object schema is also unsupported by Gemini+ let mut json = json!({+ "type": "object",+ "properties": {+ "name": { "type": "string" }+ },+ "additionalProperties": { "type": "string" },+ "propertyNames": { "pattern": "^[A-Za-z]+$" }+ });++ adapt_to_json_schema_subset(&mut json).unwrap();++ assert_eq!(+ json,+ json!({+ "type": "object",+ "properties": {+ "name": { "type": "string" }+ }+ })+ );}#[test]