use std::path::Path;
use tokio::sync::broadcast;
use crate::core::error::AgentError;
use crate::pipe::PipeSession;
use crate::transport::SpawnOptions;
use crate::core::types::{AgentEvent, CliTool};
pub struct TransportSession {
pub session_id: String,
pub tool: CliTool,
inner: PipeSession,
}
impl TransportSession {
pub async fn spawn(
tool: CliTool,
working_dir: &Path,
prompt: &str,
options: SpawnOptions,
) -> Result<Self, AgentError> {
use crate::core::types::SessionConfig;
let config = SessionConfig {
tool,
working_dir: working_dir.to_path_buf(),
env_vars: options.env_vars.clone(),
name: None,
};
let pipe_opts = crate::pipe::process::PipeProcessOptions {
extra_args: options.extra_args.clone(),
claude: crate::pipe::process::ClaudeOptions {
resume_session_id: options.resume_session_id.clone(),
model: options.model.clone(),
append_system_prompt: options.append_system_prompt.clone(),
},
};
let inner = PipeSession::spawn(config, prompt, pipe_opts).await?;
let session_id = inner.session_id().to_string();
Ok(Self {
session_id,
tool,
inner,
})
}
pub fn subscribe(&self) -> broadcast::Receiver<AgentEvent> {
self.inner.subscribe()
}
pub fn session_id(&self) -> &str {
&self.session_id
}
pub async fn send_prompt(&self, prompt: &str) -> Result<(), AgentError> {
self.inner.send_prompt(prompt).await
}
pub async fn kill(&self) -> Result<(), AgentError> {
self.inner.kill().await
}
}