tools.rs

 1mod context_server_registry;
 2mod copy_path_tool;
 3mod create_directory_tool;
 4mod delete_path_tool;
 5mod diagnostics_tool;
 6mod edit_file_tool;
 7
 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;
16
17mod terminal_tool;
18mod thinking_tool;
19mod web_search_tool;
20
21use crate::AgentTool;
22use language_model::{LanguageModelRequestTool, LanguageModelToolSchemaFormat};
23
24pub use context_server_registry::*;
25pub use copy_path_tool::*;
26pub use create_directory_tool::*;
27pub use delete_path_tool::*;
28pub use diagnostics_tool::*;
29pub use edit_file_tool::*;
30
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::*;
39
40pub use terminal_tool::*;
41pub use thinking_tool::*;
42pub use web_search_tool::*;
43
44macro_rules! tools {
45    ($($tool:ty),* $(,)?) => {
46        /// A list of all built-in tool names
47        pub fn supported_built_in_tool_names(provider: Option<language_model::LanguageModelProviderId>) -> impl Iterator<Item = String> {
48            [
49                $(
50                    (if let Some(provider) = provider.as_ref() {
51                        <$tool>::supports_provider(provider)
52                    } else {
53                        true
54                    })
55                    .then(|| <$tool>::name().to_string()),
56                )*
57            ]
58            .into_iter()
59            .flatten()
60        }
61
62        /// A list of all built-in tools
63        pub fn built_in_tools() -> impl Iterator<Item = LanguageModelRequestTool> {
64            fn language_model_tool<T: AgentTool>() -> LanguageModelRequestTool {
65                LanguageModelRequestTool {
66                    name: T::name().to_string(),
67                    description: T::description().to_string(),
68                    input_schema: T::input_schema(LanguageModelToolSchemaFormat::JsonSchema).to_value(),
69                }
70            }
71            [
72                $(
73                    language_model_tool::<$tool>(),
74                )*
75            ]
76            .into_iter()
77        }
78    };
79}
80
81tools! {
82    CopyPathTool,
83    CreateDirectoryTool,
84    DeletePathTool,
85    DiagnosticsTool,
86    EditFileTool,
87    FetchTool,
88    FindPathTool,
89    GrepTool,
90    ListDirectoryTool,
91    MovePathTool,
92    NowTool,
93    OpenTool,
94    ReadFileTool,
95    TerminalTool,
96    ThinkingTool,
97    WebSearchTool,
98}