1mod context_server_registry;
2mod copy_path_tool;
3mod create_directory_tool;
4mod delete_path_tool;
5mod diagnostics_tool;
6mod edit_file_tool;
7mod fetch_tool;
8mod find_path_tool;
9mod grep_tool;
10mod list_directory_tool;
11mod move_path_tool;
12mod now_tool;
13mod open_tool;
14mod read_file_tool;
15mod restore_file_from_disk_tool;
16mod save_file_tool;
17mod streaming_edit_file_tool;
18mod subagent_tool;
19mod terminal_tool;
20mod web_search_tool;
21
22use crate::AgentTool;
23use language_model::{LanguageModelRequestTool, LanguageModelToolSchemaFormat};
24
25pub use context_server_registry::*;
26pub use copy_path_tool::*;
27pub use create_directory_tool::*;
28pub use delete_path_tool::*;
29pub use diagnostics_tool::*;
30pub use edit_file_tool::*;
31pub use fetch_tool::*;
32pub use find_path_tool::*;
33pub use grep_tool::*;
34pub use list_directory_tool::*;
35pub use move_path_tool::*;
36pub use now_tool::*;
37pub use open_tool::*;
38pub use read_file_tool::*;
39pub use restore_file_from_disk_tool::*;
40pub use save_file_tool::*;
41pub use streaming_edit_file_tool::*;
42pub use subagent_tool::*;
43pub use terminal_tool::*;
44pub use web_search_tool::*;
45
46macro_rules! tools {
47 ($($tool:ty),* $(,)?) => {
48 /// Every built-in tool name, determined at compile time.
49 pub const ALL_TOOL_NAMES: &[&str] = &[
50 $(<$tool>::NAME,)*
51 ];
52
53 const _: () = {
54 const fn str_eq(a: &str, b: &str) -> bool {
55 let a = a.as_bytes();
56 let b = b.as_bytes();
57 if a.len() != b.len() {
58 return false;
59 }
60 let mut i = 0;
61 while i < a.len() {
62 if a[i] != b[i] {
63 return false;
64 }
65 i += 1;
66 }
67 true
68 }
69
70 const NAMES: &[&str] = ALL_TOOL_NAMES;
71 let mut i = 0;
72 while i < NAMES.len() {
73 let mut j = i + 1;
74 while j < NAMES.len() {
75 if str_eq(NAMES[i], NAMES[j]) {
76 panic!("Duplicate tool name in tools! macro");
77 }
78 j += 1;
79 }
80 i += 1;
81 }
82 };
83
84 /// Returns whether the tool with the given name supports the given provider.
85 pub fn tool_supports_provider(name: &str, provider: &language_model::LanguageModelProviderId) -> bool {
86 $(
87 if name == <$tool>::NAME {
88 return <$tool>::supports_provider(provider);
89 }
90 )*
91 false
92 }
93
94 /// A list of all built-in tools
95 pub fn built_in_tools() -> impl Iterator<Item = LanguageModelRequestTool> {
96 fn language_model_tool<T: AgentTool>() -> LanguageModelRequestTool {
97 LanguageModelRequestTool {
98 name: T::NAME.to_string(),
99 description: T::description().to_string(),
100 input_schema: T::input_schema(LanguageModelToolSchemaFormat::JsonSchema).to_value(),
101 }
102 }
103 [
104 $(
105 language_model_tool::<$tool>(),
106 )*
107 ]
108 .into_iter()
109 }
110 };
111}
112
113tools! {
114 CopyPathTool,
115 CreateDirectoryTool,
116 DeletePathTool,
117 DiagnosticsTool,
118 EditFileTool,
119 FetchTool,
120 FindPathTool,
121 GrepTool,
122 ListDirectoryTool,
123 MovePathTool,
124 NowTool,
125 OpenTool,
126 ReadFileTool,
127 RestoreFileFromDiskTool,
128 SaveFileTool,
129 SubagentTool,
130 TerminalTool,
131 WebSearchTool,
132}