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