pub type AcpResult<T> = Result<T, AcpError>;
#[derive(Debug, thiserror::Error)]
pub enum AcpError {
#[error("Agent not found: {0}")]
AgentNotFound(String),
#[error("Network error: {0}")]
NetworkError(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Invalid request: {0}")]
InvalidRequest(String),
#[error("Remote error from {agent_id}: {message}{code}", code = if let Some(code) = code { format!(" (code: {})", code) } else { String::new() })]
RemoteError {
agent_id: String,
message: String,
code: Option<i32>,
},
#[error("Timeout: {0}")]
Timeout(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Internal error: {0}")]
Internal(String),
}
impl From<reqwest::Error> for AcpError {
fn from(err: reqwest::Error) -> Self {
AcpError::NetworkError(err.to_string())
}
}
impl From<serde_json::Error> for AcpError {
fn from(err: serde_json::Error) -> Self {
AcpError::SerializationError(err.to_string())
}
}
impl From<anyhow::Error> for AcpError {
fn from(err: anyhow::Error) -> Self {
AcpError::Internal(err.to_string())
}
}