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