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