assistant_tools: Fix code_action and rename schemas for Gemini (#28634)

Closes #28475

Updates `rename` and `code_action` `input_schema` methods to use
`json_schema_for<T>()` which transforms standard JSONSchema into the
subset required by Gemini.
Also makes `input_schema` implementations consistent.
Tested tools against Gemini 2.5 Pro Preview, Zed Claude 3.7 Sonnet
Thinking, o3-mini

Release Notes:

- Agent Beta: Fixed error 400 `INVALID_ARGUMENT` when using Gemini with
`code_actions` or `rename` tools enabled.
This commit is contained in:
duvetfall 2025-04-14 19:01:47 +04:00 committed by GitHub
parent b45230784d
commit fddaa31655
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
use std::{ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
use ui::IconName; use ui::IconName;
use crate::schema::json_schema_for;
#[derive(Debug, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct CodeActionToolInput { pub struct CodeActionToolInput {
/// The relative path to the file containing the text range. /// The relative path to the file containing the text range.
@ -97,10 +99,9 @@ impl Tool for CodeActionTool {
fn input_schema( fn input_schema(
&self, &self,
_format: language_model::LanguageModelToolSchemaFormat, format: language_model::LanguageModelToolSchemaFormat,
) -> serde_json::Value { ) -> serde_json::Value {
let schema = schemars::schema_for!(CodeActionToolInput); json_schema_for::<CodeActionToolInput>(format)
serde_json::to_value(&schema).unwrap()
} }
fn ui_text(&self, input: &serde_json::Value) -> String { fn ui_text(&self, input: &serde_json::Value) -> String {

View file

@ -9,6 +9,8 @@ use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
use ui::IconName; use ui::IconName;
use crate::schema::json_schema_for;
#[derive(Debug, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct RenameToolInput { pub struct RenameToolInput {
/// The relative path to the file containing the symbol to rename. /// The relative path to the file containing the symbol to rename.
@ -68,10 +70,9 @@ impl Tool for RenameTool {
fn input_schema( fn input_schema(
&self, &self,
_format: language_model::LanguageModelToolSchemaFormat, format: language_model::LanguageModelToolSchemaFormat,
) -> serde_json::Value { ) -> serde_json::Value {
let schema = schemars::schema_for!(RenameToolInput); json_schema_for::<RenameToolInput>(format)
serde_json::to_value(&schema).unwrap()
} }
fn ui_text(&self, input: &serde_json::Value) -> String { fn ui_text(&self, input: &serde_json::Value) -> String {