use thiserror::Error;
pub type Result<T> = std::result::Result<T, TinyAgentsError>;
#[derive(Debug, Error)]
pub enum TinyAgentsError {
#[error("graph start node is not configured")]
MissingStart,
#[error("node `{0}` does not exist")]
MissingNode(String),
#[error("edge points to missing node `{0}`")]
MissingEdgeTarget(String),
#[error("conditional route `{route}` from node `{node}` does not exist")]
MissingRoute { node: String, route: String },
#[error("graph exceeded the recursion limit of {0} steps")]
RecursionLimit(usize),
#[error("sub-agent recursion exceeded the maximum depth of {0}")]
SubAgentDepth(usize),
#[error("model error: {0}")]
Model(String),
#[error("tool error: {0}")]
Tool(String),
#[error("tool `{0}` is not registered")]
ToolNotFound(String),
#[error("model `{0}` is not registered")]
ModelNotFound(String),
#[error("validation error: {0}")]
Validation(String),
#[error("structured output error: {0}")]
StructuredOutput(String),
#[error("limit exceeded: {0}")]
LimitExceeded(String),
#[error("run timed out: {0}")]
Timeout(String),
#[error("run cancelled")]
Cancelled,
#[error("middleware error: {0}")]
Middleware(String),
#[error("steering error: {0}")]
Steering(String),
#[error("memory error: {0}")]
Memory(String),
#[error("embedding error: {0}")]
Embedding(String),
#[error("graph error: {0}")]
Graph(String),
#[error("graph interrupted at node `{node}`: {message}")]
Interrupted { node: String, message: String },
#[error("checkpoint error: {0}")]
Checkpoint(String),
#[error("cannot resume: {0}")]
Resume(String),
#[error("parse error at line {line}, column {column}: {message}")]
Parse {
message: String,
line: usize,
column: usize,
},
#[error("compile error: {0}")]
Compile(String),
#[error("capability error: {0}")]
Capability(String),
#[error("duplicate component: {0}")]
DuplicateComponent(String),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
}