Skip to main content

pawan/tools/
ares_bridge.rs

1//! Bridge ares tools into pawan's ToolRegistry
2//!
3//! Feature-gated behind `ares` feature flag.
4
5use super::Tool;
6use crate::{PawanError, Result};
7use async_trait::async_trait;
8use serde_json::Value;
9use std::sync::Arc;
10
11/// Wraps an ares Tool as a pawan Tool
12pub struct AresTool {
13    inner: Arc<dyn ares::tools::registry::Tool>,
14}
15
16impl AresTool {
17    pub fn new(tool: Arc<dyn ares::tools::registry::Tool>) -> Self {
18        Self { inner: tool }
19    }
20}
21
22#[async_trait]
23impl Tool for AresTool {
24    fn name(&self) -> &str {
25        self.inner.name()
26    }
27
28    fn description(&self) -> &str {
29        self.inner.description()
30    }
31
32    fn mutating(&self) -> bool {
33        true // Ares tools can potentially mutate state
34    }
35
36    fn parameters_schema(&self) -> Value {
37        self.inner.parameters_schema()
38    }
39
40    async fn execute(&self, args: Value) -> Result<Value> {
41        self.inner
42            .execute(args)
43            .await
44            .map_err(|e| PawanError::Tool(format!("Ares tool error: {}", e)))
45    }
46}
47
48/// Register all tools from an ares ToolRegistry into a pawan ToolRegistry
49pub fn bridge_ares_tools(
50    ares_registry: &ares::tools::registry::ToolRegistry,
51    pawan_registry: &mut super::ToolRegistry,
52) -> usize {
53    let ares_defs = ares_registry.get_tool_definitions();
54    let mut count = 0;
55
56    for def in &ares_defs {
57        if let Some(tool) = ares_registry.get(&def.name) {
58            pawan_registry.register(Arc::new(AresTool::new(Arc::clone(tool))));
59            count += 1;
60        }
61    }
62
63    count
64}