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