1use std::path::PathBuf;
2use thiserror::Error;
3use uuid::Uuid;
4
5pub type TaskId = Uuid;
6pub type AgentId = Uuid;
7
8#[derive(Error, Debug)]
9pub enum SdkError {
10 #[error("IO error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("JSON serialization error: {0}")]
14 Serde(#[from] serde_json::Error),
15
16 #[error("HTTP error: {0}")]
17 Http(#[from] reqwest::Error),
18
19 #[error("LLM API error: {status} - {message}")]
20 LlmApi { status: u16, message: String },
21
22 #[error("LLM rate limited, retry after {retry_after_ms}ms")]
23 RateLimited { retry_after_ms: u64 },
24
25 #[error("LLM response parse error: {0}")]
26 LlmResponseParse(String),
27
28 #[error("Task {task_id} not found")]
29 TaskNotFound { task_id: TaskId },
30
31 #[error("Task {task_id} failed: {reason}")]
32 TaskFailed { task_id: TaskId, reason: String },
33
34 #[error("Agent {agent_id} crashed: {reason}")]
35 AgentCrashed { agent_id: AgentId, reason: String },
36
37 #[error("Dependency cycle detected involving tasks: {task_ids:?}")]
38 DependencyCycle { task_ids: Vec<TaskId> },
39
40 #[error("Lock acquisition failed for {path}")]
41 LockFailed { path: PathBuf },
42
43 #[error("Configuration error: {0}")]
44 Config(String),
45
46 #[error("Tool execution error in {tool_name}: {message}")]
47 ToolExecution { tool_name: String, message: String },
48
49 #[error("Agent loop exceeded maximum iterations ({max_iterations})")]
50 MaxIterationsExceeded { max_iterations: usize },
51
52 #[error("Context window overflow: {current_tokens} exceeds {max_tokens} limit")]
53 ContextOverflow { current_tokens: usize, max_tokens: usize },
54}
55
56pub type SdkResult<T> = Result<T, SdkError>;