use adk_core::{AdkError, ErrorCategory, ErrorComponent};
use thiserror::Error;
pub type Result<T, E = ComputerUseError> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum ComputerUseError {
#[error("computer-use MCP call failed: {0}")]
Mcp(String),
#[error("failed to decode computer-use payload: {0}")]
Decode(String),
#[error("computer-use identity mismatch: {0}")]
IdentityMismatch(String),
#[error("invalid computer-use request: {0}")]
InvalidRequest(String),
#[error("{operation} is not implemented by this runtime adapter")]
Unsupported {
operation: &'static str,
},
#[error("computer-use runtime error: {0}")]
Runtime(String),
}
impl From<serde_json::Error> for ComputerUseError {
fn from(error: serde_json::Error) -> Self {
ComputerUseError::Decode(error.to_string())
}
}
impl From<ComputerUseError> for AdkError {
fn from(error: ComputerUseError) -> Self {
let (component, category, code) = match &error {
ComputerUseError::Mcp(_) => {
(ErrorComponent::Tool, ErrorCategory::Unavailable, "tool.computer_use.mcp")
}
ComputerUseError::Decode(_) => {
(ErrorComponent::Tool, ErrorCategory::InvalidInput, "tool.computer_use.decode")
}
ComputerUseError::IdentityMismatch(_) => {
(ErrorComponent::Auth, ErrorCategory::Forbidden, "auth.computer_use.identity")
}
ComputerUseError::InvalidRequest(_) => (
ErrorComponent::Tool,
ErrorCategory::InvalidInput,
"tool.computer_use.invalid_request",
),
ComputerUseError::Unsupported { .. } => {
(ErrorComponent::Tool, ErrorCategory::Unsupported, "tool.computer_use.unsupported")
}
ComputerUseError::Runtime(_) => {
(ErrorComponent::Tool, ErrorCategory::Internal, "tool.computer_use.runtime")
}
};
AdkError::new(component, category, code, error.to_string())
}
}