use super::ToolRuntime;
use std::{
collections::HashSet,
path::PathBuf,
sync::{Arc, Mutex},
};
impl ToolRuntime {
pub fn new(cwd: impl Into<PathBuf>) -> anyhow::Result<Self> {
Self::new_with_settings(cwd, crate::config::ToolSettings::default())
}
pub fn new_with_settings(
cwd: impl Into<PathBuf>,
settings: crate::config::ToolSettings,
) -> anyhow::Result<Self> {
let disabled_tools = Arc::new(Mutex::new(Self::settings_disabled_tool_names(&settings)));
Self::new_with_settings_and_disabled_tools(cwd, settings, disabled_tools)
}
pub fn dispatch(&self, name: &str, arguments: serde_json::Value) -> crate::tools::ToolResult {
self.dispatch_with_context(
name,
arguments,
crate::output::ToolDispatchContext::new_with_hook_context_and_cancellation(
None,
None,
crate::output::HookContextMetadata::new(crate::output::InvocationMode::Print),
crate::cancellation::AgentCancellation::default(),
),
)
}
pub(super) fn settings_disabled_tool_names(
settings: &crate::config::ToolSettings,
) -> HashSet<String> {
settings
.disabled
.iter()
.map(|name| name.trim())
.filter(|name| !name.is_empty())
.map(ToString::to_string)
.collect()
}
}