assistant_tools.rs

  1mod batch_tool;
  2mod code_action_tool;
  3mod code_symbols_tool;
  4mod contents_tool;
  5mod copy_path_tool;
  6mod create_directory_tool;
  7mod create_file_tool;
  8mod delete_path_tool;
  9mod diagnostics_tool;
 10mod fetch_tool;
 11mod find_replace_file_tool;
 12mod list_directory_tool;
 13mod move_path_tool;
 14mod now_tool;
 15mod open_tool;
 16mod path_search_tool;
 17mod read_file_tool;
 18mod regex_search_tool;
 19mod rename_tool;
 20mod replace;
 21mod schema;
 22mod symbol_info_tool;
 23mod terminal_tool;
 24mod thinking_tool;
 25
 26use std::sync::Arc;
 27
 28use assistant_tool::ToolRegistry;
 29use copy_path_tool::CopyPathTool;
 30use gpui::App;
 31use http_client::HttpClientWithUrl;
 32use move_path_tool::MovePathTool;
 33
 34use crate::batch_tool::BatchTool;
 35use crate::code_action_tool::CodeActionTool;
 36use crate::code_symbols_tool::CodeSymbolsTool;
 37use crate::contents_tool::ContentsTool;
 38use crate::create_directory_tool::CreateDirectoryTool;
 39use crate::create_file_tool::CreateFileTool;
 40use crate::delete_path_tool::DeletePathTool;
 41use crate::diagnostics_tool::DiagnosticsTool;
 42use crate::fetch_tool::FetchTool;
 43use crate::find_replace_file_tool::FindReplaceFileTool;
 44use crate::list_directory_tool::ListDirectoryTool;
 45use crate::now_tool::NowTool;
 46use crate::open_tool::OpenTool;
 47use crate::path_search_tool::PathSearchTool;
 48use crate::read_file_tool::ReadFileTool;
 49use crate::regex_search_tool::RegexSearchTool;
 50use crate::rename_tool::RenameTool;
 51use crate::symbol_info_tool::SymbolInfoTool;
 52use crate::terminal_tool::TerminalTool;
 53use crate::thinking_tool::ThinkingTool;
 54
 55pub fn init(http_client: Arc<HttpClientWithUrl>, cx: &mut App) {
 56    assistant_tool::init(cx);
 57
 58    let registry = ToolRegistry::global(cx);
 59    registry.register_tool(TerminalTool);
 60    registry.register_tool(BatchTool);
 61    registry.register_tool(CreateDirectoryTool);
 62    registry.register_tool(CreateFileTool);
 63    registry.register_tool(CopyPathTool);
 64    registry.register_tool(DeletePathTool);
 65    registry.register_tool(FindReplaceFileTool);
 66    registry.register_tool(SymbolInfoTool);
 67    registry.register_tool(CodeActionTool);
 68    registry.register_tool(MovePathTool);
 69    registry.register_tool(DiagnosticsTool);
 70    registry.register_tool(ListDirectoryTool);
 71    registry.register_tool(NowTool);
 72    registry.register_tool(OpenTool);
 73    registry.register_tool(CodeSymbolsTool);
 74    registry.register_tool(ContentsTool);
 75    registry.register_tool(PathSearchTool);
 76    registry.register_tool(ReadFileTool);
 77    registry.register_tool(RegexSearchTool);
 78    registry.register_tool(RenameTool);
 79    registry.register_tool(ThinkingTool);
 80    registry.register_tool(FetchTool::new(http_client));
 81}
 82
 83#[cfg(test)]
 84mod tests {
 85    use http_client::FakeHttpClient;
 86
 87    use super::*;
 88
 89    #[gpui::test]
 90    fn test_builtin_tool_schema_compatibility(cx: &mut App) {
 91        crate::init(
 92            Arc::new(http_client::HttpClientWithUrl::new(
 93                FakeHttpClient::with_200_response(),
 94                "https://zed.dev",
 95                None,
 96            )),
 97            cx,
 98        );
 99
100        for tool in ToolRegistry::global(cx).tools() {
101            let actual_schema = tool
102                .input_schema(language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset)
103                .unwrap();
104            let mut expected_schema = actual_schema.clone();
105            assistant_tool::adapt_schema_to_format(
106                &mut expected_schema,
107                language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset,
108            )
109            .unwrap();
110
111            let error_message = format!(
112                "Tool schema for `{}` is not compatible with `language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset` (Gemini Models).\n\
113                Are you using `schema::json_schema_for<T>(format)` to generate the schema?",
114                tool.name(),
115            );
116
117            assert_eq!(actual_schema, expected_schema, "{}", error_message)
118        }
119    }
120}