use super::layer_trait::{Layer, LayerConfig, LayerResult};
use crate::mcp::agent::functions::run_acp_command;
use crate::session::Session;
use anyhow::Result;
use async_trait::async_trait;
pub struct LayerProcessor {
pub config: LayerConfig,
}
impl LayerProcessor {
pub fn new(config: LayerConfig) -> Self {
Self { config }
}
}
#[async_trait]
impl Layer for LayerProcessor {
fn name(&self) -> &str {
&self.config.name
}
fn config(&self) -> &LayerConfig {
&self.config
}
async fn process(
&self,
input: &str,
session: &Session,
_config: &crate::config::Config,
operation_cancelled: tokio::sync::watch::Receiver<bool>,
) -> Result<LayerResult> {
let task = self.prepare_input(input, session);
let session_workdir = crate::mcp::get_thread_working_directory();
let workdir = self.config.get_resolved_workdir(&session_workdir);
let start = std::time::Instant::now();
let output =
run_acp_command(&self.config.command, &task, &workdir, operation_cancelled).await?;
Ok(LayerResult {
outputs: vec![output],
total_time_ms: start.elapsed().as_millis() as u64,
})
}
}