diff --git a/src/core/processor/tool_selector.rs b/src/core/processor/tool_selector.rs index 1fc8e3eb..f0014470 100644 --- a/src/core/processor/tool_selector.rs +++ b/src/core/processor/tool_selector.rs @@ -1,5 +1,7 @@ use crate::core::admin_config::{self, ProcessorConfig, ToolConfig}; +use crate::core::processor::processor_config_v3; use anyhow::{Context, Result}; +use std::collections::HashMap; use std::path::PathBuf; use tracing::info; @@ -15,6 +17,19 @@ impl ToolSelector { } pub async fn select_tool(&self, executor: &super::PythonExecutor) -> Result> { + match self.select_tool_v3().await { + Ok(Some(tool)) => { + info!("[{}] Selected tool via V3: {}", self.processor_name, tool.name); + return Ok(Some(tool)); + } + Ok(None) => { + info!("[{}] No tool found via V3, falling back to V2", self.processor_name); + } + Err(e) => { + info!("[{}] V3 config failed: {}, falling back to V2", self.processor_name, e); + } + } + let config = admin_config::get_processor_config(&self.processor_name) .await .context("Failed to get processor config")?; @@ -62,6 +77,63 @@ impl ToolSelector { info!("[{}] No available tool found", self.processor_name); Ok(None) } + + pub async fn select_tool_v3(&self) -> Result> { + let manager = processor_config_v3::get_config_manager().await?; + + let implementations = manager.get_implementations_by_priority(&self.processor_name); + + if implementations.is_empty() { + return Ok(None); + } + + let variables = self.build_variables(); + + for impl_ in implementations { + if !impl_.enabled { + continue; + } + + match manager.resolve_command(&self.processor_name, &impl_.tool, &variables) { + Ok(Some((executable, args))) => { + info!( + "[ToolSelector V3] Selected: {} (priority {}, timeout {}s)", + impl_.tool, impl_.priority, impl_.timeout + ); + + return Ok(Some(SelectedTool { + name: impl_.tool.clone(), + path: executable, + args, + parameters: impl_.parameters.clone(), + timeout: impl_.timeout, + })); + } + Ok(None) => { + info!("[ToolSelector V3] Tool {} not available, trying next", impl_.tool); + continue; + } + Err(e) => { + info!("[ToolSelector V3] Failed to resolve {}: {}", impl_.tool, e); + continue; + } + } + } + + Ok(None) + } + + fn build_variables(&self) -> HashMap { + let mut vars = HashMap::new(); + + if let Ok(output_dir) = std::env::var("MOMENTRY_OUTPUT_DIR") { + vars.insert("output_dir".to_string(), output_dir); + } else { + vars.insert("output_dir".to_string(), "/Users/accusys/momentry/output".to_string()); + } + + vars + } fn find_tool(&self, tool_name: &str, executor: &super::PythonExecutor) -> Option { match (self.processor_name.as_str(), tool_name) { @@ -197,5 +269,19 @@ impl ToolSelector { pub struct SelectedTool { pub name: String, pub path: PathBuf, + pub args: Vec, pub parameters: serde_json::Map, + pub timeout: u64, +} + +impl Default for SelectedTool { + fn default() -> Self { + Self { + name: String::new(), + path: PathBuf::new(), + args: Vec::new(), + parameters: serde_json::Map::new(), + timeout: 3600, + } + } } \ No newline at end of file