mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 07:04:29 +00:00
acp spec (#155)
This commit is contained in:
parent
70287ec471
commit
e72eb9f611
264 changed files with 18559 additions and 51021 deletions
|
|
@ -8,12 +8,15 @@ use utoipa::ToSchema;
|
|||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ErrorType {
|
||||
InvalidRequest,
|
||||
Conflict,
|
||||
UnsupportedAgent,
|
||||
AgentNotInstalled,
|
||||
InstallFailed,
|
||||
AgentProcessExited,
|
||||
TokenInvalid,
|
||||
PermissionDenied,
|
||||
NotAcceptable,
|
||||
UnsupportedMediaType,
|
||||
SessionNotFound,
|
||||
SessionAlreadyExists,
|
||||
ModeNotSupported,
|
||||
|
|
@ -25,12 +28,15 @@ impl ErrorType {
|
|||
pub fn as_urn(&self) -> &'static str {
|
||||
match self {
|
||||
Self::InvalidRequest => "urn:sandbox-agent:error:invalid_request",
|
||||
Self::Conflict => "urn:sandbox-agent:error:conflict",
|
||||
Self::UnsupportedAgent => "urn:sandbox-agent:error:unsupported_agent",
|
||||
Self::AgentNotInstalled => "urn:sandbox-agent:error:agent_not_installed",
|
||||
Self::InstallFailed => "urn:sandbox-agent:error:install_failed",
|
||||
Self::AgentProcessExited => "urn:sandbox-agent:error:agent_process_exited",
|
||||
Self::TokenInvalid => "urn:sandbox-agent:error:token_invalid",
|
||||
Self::PermissionDenied => "urn:sandbox-agent:error:permission_denied",
|
||||
Self::NotAcceptable => "urn:sandbox-agent:error:not_acceptable",
|
||||
Self::UnsupportedMediaType => "urn:sandbox-agent:error:unsupported_media_type",
|
||||
Self::SessionNotFound => "urn:sandbox-agent:error:session_not_found",
|
||||
Self::SessionAlreadyExists => "urn:sandbox-agent:error:session_already_exists",
|
||||
Self::ModeNotSupported => "urn:sandbox-agent:error:mode_not_supported",
|
||||
|
|
@ -42,12 +48,15 @@ impl ErrorType {
|
|||
pub fn title(&self) -> &'static str {
|
||||
match self {
|
||||
Self::InvalidRequest => "Invalid Request",
|
||||
Self::Conflict => "Conflict",
|
||||
Self::UnsupportedAgent => "Unsupported Agent",
|
||||
Self::AgentNotInstalled => "Agent Not Installed",
|
||||
Self::InstallFailed => "Install Failed",
|
||||
Self::AgentProcessExited => "Agent Process Exited",
|
||||
Self::TokenInvalid => "Token Invalid",
|
||||
Self::PermissionDenied => "Permission Denied",
|
||||
Self::NotAcceptable => "Not Acceptable",
|
||||
Self::UnsupportedMediaType => "Unsupported Media Type",
|
||||
Self::SessionNotFound => "Session Not Found",
|
||||
Self::SessionAlreadyExists => "Session Already Exists",
|
||||
Self::ModeNotSupported => "Mode Not Supported",
|
||||
|
|
@ -59,12 +68,15 @@ impl ErrorType {
|
|||
pub fn status_code(&self) -> u16 {
|
||||
match self {
|
||||
Self::InvalidRequest => 400,
|
||||
Self::Conflict => 409,
|
||||
Self::UnsupportedAgent => 400,
|
||||
Self::AgentNotInstalled => 404,
|
||||
Self::InstallFailed => 500,
|
||||
Self::AgentProcessExited => 500,
|
||||
Self::TokenInvalid => 401,
|
||||
Self::PermissionDenied => 403,
|
||||
Self::NotAcceptable => 406,
|
||||
Self::UnsupportedMediaType => 415,
|
||||
Self::SessionNotFound => 404,
|
||||
Self::SessionAlreadyExists => 409,
|
||||
Self::ModeNotSupported => 400,
|
||||
|
|
@ -118,6 +130,8 @@ pub struct AgentError {
|
|||
pub enum SandboxError {
|
||||
#[error("invalid request: {message}")]
|
||||
InvalidRequest { message: String },
|
||||
#[error("conflict: {message}")]
|
||||
Conflict { message: String },
|
||||
#[error("unsupported agent: {agent}")]
|
||||
UnsupportedAgent { agent: String },
|
||||
#[error("agent not installed: {agent}")]
|
||||
|
|
@ -137,6 +151,10 @@ pub enum SandboxError {
|
|||
TokenInvalid { message: Option<String> },
|
||||
#[error("permission denied")]
|
||||
PermissionDenied { message: Option<String> },
|
||||
#[error("not acceptable: {message}")]
|
||||
NotAcceptable { message: String },
|
||||
#[error("unsupported media type: {message}")]
|
||||
UnsupportedMediaType { message: String },
|
||||
#[error("session not found: {session_id}")]
|
||||
SessionNotFound { session_id: String },
|
||||
#[error("session already exists: {session_id}")]
|
||||
|
|
@ -153,12 +171,15 @@ impl SandboxError {
|
|||
pub fn error_type(&self) -> ErrorType {
|
||||
match self {
|
||||
Self::InvalidRequest { .. } => ErrorType::InvalidRequest,
|
||||
Self::Conflict { .. } => ErrorType::Conflict,
|
||||
Self::UnsupportedAgent { .. } => ErrorType::UnsupportedAgent,
|
||||
Self::AgentNotInstalled { .. } => ErrorType::AgentNotInstalled,
|
||||
Self::InstallFailed { .. } => ErrorType::InstallFailed,
|
||||
Self::AgentProcessExited { .. } => ErrorType::AgentProcessExited,
|
||||
Self::TokenInvalid { .. } => ErrorType::TokenInvalid,
|
||||
Self::PermissionDenied { .. } => ErrorType::PermissionDenied,
|
||||
Self::NotAcceptable { .. } => ErrorType::NotAcceptable,
|
||||
Self::UnsupportedMediaType { .. } => ErrorType::UnsupportedMediaType,
|
||||
Self::SessionNotFound { .. } => ErrorType::SessionNotFound,
|
||||
Self::SessionAlreadyExists { .. } => ErrorType::SessionAlreadyExists,
|
||||
Self::ModeNotSupported { .. } => ErrorType::ModeNotSupported,
|
||||
|
|
@ -170,6 +191,11 @@ impl SandboxError {
|
|||
pub fn to_agent_error(&self) -> AgentError {
|
||||
let (agent, session_id, details) = match self {
|
||||
Self::InvalidRequest { .. } => (None, None, None),
|
||||
Self::Conflict { message } => {
|
||||
let mut map = Map::new();
|
||||
map.insert("message".to_string(), Value::String(message.clone()));
|
||||
(None, None, Some(Value::Object(map)))
|
||||
}
|
||||
Self::UnsupportedAgent { agent } => (Some(agent.clone()), None, None),
|
||||
Self::AgentNotInstalled { agent } => (Some(agent.clone()), None, None),
|
||||
Self::InstallFailed { agent, stderr } => {
|
||||
|
|
@ -228,6 +254,16 @@ impl SandboxError {
|
|||
});
|
||||
(None, None, details)
|
||||
}
|
||||
Self::NotAcceptable { message } => {
|
||||
let mut map = Map::new();
|
||||
map.insert("message".to_string(), Value::String(message.clone()));
|
||||
(None, None, Some(Value::Object(map)))
|
||||
}
|
||||
Self::UnsupportedMediaType { message } => {
|
||||
let mut map = Map::new();
|
||||
map.insert("message".to_string(), Value::String(message.clone()));
|
||||
(None, None, Some(Value::Object(map)))
|
||||
}
|
||||
Self::SessionNotFound { session_id } => (None, Some(session_id.clone()), None),
|
||||
Self::SessionAlreadyExists { session_id } => (None, Some(session_id.clone()), None),
|
||||
Self::ModeNotSupported { agent, mode } => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue