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