vtcode_core/tools/registry/
registration_facade.rs1use anyhow::Result;
4
5use super::{ToolRegistration, ToolRegistry};
6
7impl ToolRegistry {
8 pub async fn register_tool(&self, registration: ToolRegistration) -> Result<()> {
16 let registration = if let Some(mode) = self.current_cgp_mode() {
17 if registration.is_cgp_wrapped() {
18 registration
19 } else if let Some(handler) = self.cgp_handler_for_registration(®istration, mode) {
20 registration.with_handler(handler).with_cgp_wrapped(true)
21 } else {
22 registration
23 }
24 } else {
25 registration
26 };
27 self.inventory.register_tool(registration)?;
28 if let Ok(mut cache) = self.cached_available_tools.write() {
30 *cache = None;
31 }
32 self.rebuild_tool_assembly().await;
33 self.tool_catalog_state
34 .note_explicit_refresh("tool_registration");
35 self.sync_policy_catalog().await;
36 Ok(())
37 }
38
39 pub async fn unregister_tool(&self, name: &str) -> Result<bool> {
41 let removed = self.inventory.remove_tool(name)?.is_some();
42 if removed {
43 if let Ok(mut cache) = self.cached_available_tools.write() {
44 *cache = None;
45 }
46 self.rebuild_tool_assembly().await;
47 self.tool_catalog_state
48 .note_explicit_refresh("tool_unregistration");
49 self.sync_policy_catalog().await;
50 }
51 Ok(removed)
52 }
53}