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