funera_builtin_tools/
lib.rs1pub mod edit;
25pub mod hashline;
26pub mod read;
27pub mod shell;
28pub mod write;
29
30pub use edit::EditTool;
31pub use read::ReadTool;
32pub use shell::ShellTool;
33pub use write::WriteTool;
34
35use std::sync::Arc;
36
37#[cfg(feature = "sandbox")]
38pub use funera_core::security::sandbox::SandboxPolicy;
39
40use funera_core::re_act::tool::ToolRegistry;
41
42pub fn register_all_tools(registry: &mut ToolRegistry) {
47 registry.add_tool(Arc::new(ReadTool));
48 registry.add_tool(Arc::new(WriteTool));
49 registry.add_tool(Arc::new(EditTool));
50 registry.add_tool(Arc::new(ShellTool::new()));
51}
52
53#[cfg(feature = "sandbox")]
64pub fn register_all_tools_with_sandbox(registry: &mut ToolRegistry, policy: SandboxPolicy) {
65 registry.add_tool(Arc::new(ReadTool));
66 registry.add_tool(Arc::new(WriteTool));
67 registry.add_tool(Arc::new(EditTool));
68 registry.add_tool(Arc::new(ShellTool::with_sandbox(policy)));
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn register_all_tools_adds_four_tools() {
77 let mut registry = ToolRegistry::new();
78 register_all_tools(&mut registry);
79 assert_eq!(registry.tool_count(), 4);
80 assert!(registry.tool_exists("read"));
81 assert!(registry.tool_exists("write"));
82 assert!(registry.tool_exists("edit"));
83 assert!(registry.tool_exists("shell"));
84 }
85
86 #[test]
87 fn each_tool_has_valid_schema() {
88 let mut registry = ToolRegistry::new();
89 register_all_tools(&mut registry);
90 let json = registry.available_tools_json();
91 let tools = json.as_array().unwrap();
92 assert_eq!(tools.len(), 4);
93 for tool in tools {
94 assert!(tool["function"]["name"].as_str().is_some());
95 assert!(tool["function"]["parameters"].is_object());
96 }
97 }
98
99 #[cfg(feature = "sandbox")]
100 #[test]
101 fn register_all_tools_with_sandbox_adds_four_tools() {
102 let mut registry = ToolRegistry::new();
103 register_all_tools_with_sandbox(&mut registry, SandboxPolicy::disabled());
104 assert_eq!(registry.tool_count(), 4);
105 assert!(registry.tool_exists("read"));
106 assert!(registry.tool_exists("write"));
107 assert!(registry.tool_exists("edit"));
108 assert!(registry.tool_exists("shell"));
109 }
110}