use crate::agent::AgentError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum OrchestratorError {
#[error("A redesign has been triggered. Restarting execution.")]
RedesignAndRestart,
#[error("Agent error: {0}")]
AgentError(#[from] AgentError),
#[error("No agent found with name: {0}")]
AgentNotFound(String),
#[error("Strategy generation failed: {0}")]
StrategyGenerationFailed(String),
#[error("Template rendering error: {0}")]
TemplateRenderError(String),
#[error("Execution failed: {0}")]
ExecutionFailed(String),
#[error("Redesign determination failed: {0}")]
RedesignFailed(String),
#[error("JSON error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("Orchestrator error: {0}")]
Other(String),
#[error("Step {step_index} exceeded maximum remediation attempts ({max_remediations})")]
MaxStepRemediationsExceeded {
step_index: usize,
max_remediations: usize,
},
#[error("Total number of redesigns exceeded the maximum limit ({0})")]
MaxTotalRedesignsExceeded(usize),
#[error("Total number of loop iterations exceeded the maximum limit ({0})")]
MaxLoopIterationsExceeded(usize),
#[error("The internal agent failed to recover even after a fallback attempt: {0}")]
InternalAgentUnrecoverable(String),
#[error("Step '{step_id}' timed out after {timeout:?}")]
StepTimeout {
step_id: String,
timeout: std::time::Duration,
},
#[error("Step '{step_id}' was cancelled")]
Cancelled { step_id: String },
}
impl OrchestratorError {
pub fn no_strategy() -> Self {
Self::Other("No strategy available".to_string())
}
pub fn invalid_blueprint(reason: impl Into<String>) -> Self {
Self::Other(format!("Invalid blueprint: {}", reason.into()))
}
}