use ai_sdk_provider::Error as ProviderError;
pub type Result<T> = std::result::Result<T, Error>;
pub type Error = Box<dyn std::error::Error + Send + Sync>;
#[derive(thiserror::Error, Debug)]
pub enum GenerateError {
#[error("Missing model - must call .model() before execute()")]
MissingModel,
#[error("Missing prompt - must call .prompt() before execute()")]
MissingPrompt,
#[error("Provider error: {0}")]
ProviderError(#[from] ProviderError),
#[error("Tool execution error: {0}")]
ToolError(#[from] ToolError),
#[error("Maximum steps reached without completion")]
MaxStepsReached,
#[error("Invalid parameters: {0}")]
InvalidParameters(String),
#[error("Stream error: {0}")]
StreamError(String),
#[error("Model error: {0}")]
ModelError(String),
}
#[derive(thiserror::Error, Debug)]
pub enum EmbedError {
#[error("Missing model - must call .model() before execute()")]
MissingModel,
#[error("Missing value - must call .value() before execute()")]
MissingValue,
#[error("Empty response from embedding model")]
EmptyResponse,
#[error("Provider error: {0}")]
ProviderError(#[from] ProviderError),
}
#[derive(thiserror::Error, Debug)]
pub enum ToolError {
#[error("Tool execution failed: {0}")]
ExecutionError(String),
#[error("Tool not found: {0}")]
ToolNotFound(String),
#[error("Invalid tool input: {0}")]
InvalidInput(String),
#[error("Tool execution denied")]
ExecutionDenied,
}
impl ToolError {
pub fn execution(msg: impl Into<String>) -> Self {
ToolError::ExecutionError(msg.into())
}
pub fn not_found(name: impl Into<String>) -> Self {
ToolError::ToolNotFound(name.into())
}
pub fn invalid_input(msg: impl Into<String>) -> Self {
ToolError::InvalidInput(msg.into())
}
}
#[derive(Debug, thiserror::Error)]
pub enum GenerateObjectError {
#[error("Model is required")]
MissingModel,
#[error("Prompt is required")]
MissingPrompt,
#[error("Output strategy is required")]
MissingOutputStrategy,
#[error("Provider error: {0}")]
ProviderError(#[from] ProviderError),
#[error("Validation failed: {0}")]
ValidationFailed(String),
#[error("JSON parsing error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("No text content in model response")]
NoTextContent,
#[error("Model error: {0}")]
ModelError(Box<dyn std::error::Error + Send + Sync>),
}
#[derive(Debug, thiserror::Error)]
pub enum StreamObjectError {
#[error("Model is required")]
MissingModel,
#[error("Prompt is required")]
MissingPrompt,
#[error("Output strategy is required")]
MissingOutputStrategy,
#[error("Provider error: {0}")]
ProviderError(#[from] ProviderError),
#[error("Validation failed: {0}")]
ValidationFailed(String),
#[error("Stream error: {0}")]
StreamError(String),
#[error("Model error: {0}")]
ModelError(Box<dyn std::error::Error + Send + Sync>),
}
#[derive(Debug, thiserror::Error)]
pub enum RegistryError {
#[error("No such provider: {provider_id} (available providers: {available_providers:?})")]
NoSuchProvider {
provider_id: String,
model_type: String,
available_providers: Vec<String>,
},
#[error("No such model: {model_id} (type: {model_type})")]
NoSuchModel {
model_id: String,
model_type: String,
},
#[error("Invalid model ID: {message}")]
InvalidModelId {
model_id: String,
model_type: String,
message: String,
},
}