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