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