#[cfg(feature = "stream-json")]
pub mod stream_json;
#[cfg(feature = "pty")]
pub mod pty;
#[cfg(any(feature = "stream-json", feature = "pty"))]
mod common {
use crate::core::{AgentEvent, ClientFrame};
#[async_trait::async_trait]
pub trait Driver: Send {
async fn send(&mut self, frame: ClientFrame) -> Result<(), DriverError>;
async fn next_event(&mut self) -> Option<AgentEvent>;
async fn shutdown(&mut self) -> Result<(), DriverError>;
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DriverError {
#[error("agent binary not found on PATH: {0}")]
BinaryNotFound(String),
#[error("failed to spawn agent process: {0}")]
SpawnFailed(#[source] std::io::Error),
#[error("agent process exited unexpectedly")]
AgentExited,
#[error("io error while talking to agent: {0}")]
Io(#[from] std::io::Error),
#[error("failed to parse agent output: {0}")]
Parse(String),
#[error("agent reported error: {code} — {message}")]
AgentError { code: String, message: String },
}
#[cfg(feature = "stream-json")]
impl From<serde_json::Error> for DriverError {
fn from(e: serde_json::Error) -> Self {
DriverError::Parse(e.to_string())
}
}
}
#[cfg(any(feature = "stream-json", feature = "pty"))]
pub use common::{Driver, DriverError};