use lingshu_types::{AgentError, ToolError};
#[derive(Debug, thiserror::Error)]
pub enum SdkError {
#[error(transparent)]
Agent(#[from] AgentError),
#[error(transparent)]
Tool(#[from] ToolError),
#[error("SDK configuration error: {0}")]
Config(String),
#[error("Provider error for model '{model}': {message}")]
Provider { model: String, message: String },
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Agent not initialized: {0}")]
NotInitialized(String),
}
impl SdkError {
pub fn is_retryable(&self) -> bool {
match self {
Self::Agent(AgentError::RateLimited { .. }) => true,
Self::Agent(AgentError::Llm(msg)) => {
msg.contains("timeout") || msg.contains("connection")
}
_ => false,
}
}
pub fn category(&self) -> &'static str {
match self {
Self::Agent(_) => "agent",
Self::Tool(_) => "tool",
Self::Config(_) => "config",
Self::Provider { .. } => "provider",
Self::Serialization(_) => "serialization",
Self::NotInitialized(_) => "initialization",
}
}
}