macro_rules! string_enum { ( $(#[$meta:meta])* pub enum $name:ident { $($variant:ident => $value:literal),+ $(,)? } ) => { $(#[$meta])* #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum $name { $($variant),+ } impl $name { pub const ALL: &'static [Self] = &[$(Self::$variant),+]; pub const VALUES: &'static [&'static str] = &[$($value),+]; pub const fn as_str(self) -> &'static str { match self { $(Self::$variant => $value),+ } } } }; } #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct HttpRoute(&'static str); impl HttpRoute { pub const fn unmatched() -> Self { Self("unmatched") } pub fn from_matched_path(path: &str) -> Self { crate::schema::HTTP_ROUTE_DOMAIN .iter() .copied() .find(|candidate| *candidate != "unmatched" && *candidate == path) .map_or_else(Self::unmatched, Self) } pub const fn as_str(self) -> &'static str { self.0 } } string_enum! { pub enum HttpMethod { Get => "GET", Post => "POST", Put => "PUT", Patch => "PATCH", Delete => "DELETE", Options => "OPTIONS", Head => "HEAD", Connect => "CONNECT", Trace => "TRACE", Other => "OTHER", } } impl HttpMethod { pub fn classify(method: &str) -> Self { match method { "GET" => Self::Get, "POST" => Self::Post, "PUT" => Self::Put, "PATCH" => Self::Patch, "DELETE" => Self::Delete, "OPTIONS" => Self::Options, "HEAD" => Self::Head, "CONNECT" => Self::Connect, "TRACE" => Self::Trace, _ => Self::Other, } } } impl McpOutcome { pub const fn from_http_status(status: u16) -> Self { match status { 200..=299 => Self::Success, 400..=499 => Self::ClientError, 500..=599 => Self::ServerError, _ => Self::Other, } } } string_enum! { pub enum HttpStatusClass { Informational => "1xx", Success => "2xx", Redirection => "3xx", ClientError => "4xx", ServerError => "5xx", Other => "other", } } impl HttpStatusClass { pub const fn from_status(status: u16) -> Self { match status { 100..=199 => Self::Informational, 200..=299 => Self::Success, 300..=399 => Self::Redirection, 400..=499 => Self::ClientError, 500..=599 => Self::ServerError, _ => Self::Other, } } } string_enum! { pub enum McpMethod { Initialize => "initialize", Initialized => "initialized", Ping => "ping", ToolsList => "tools_list", ToolsCall => "tools_call", Notification => "notification", Unsupported => "unsupported", Response => "response", Invalid => "invalid", } } string_enum! { pub enum McpResponseMode { Json => "json", Sse => "sse", Unknown => "unknown", } } string_enum! { pub enum McpOutcome { Success => "success", ClientError => "client_error", ServerError => "server_error", JsonRpcError => "jsonrpc_error", ToolError => "tool_error", Aborted => "aborted", Other => "other", } } string_enum! { pub enum InvocationSource { Internal => "internal", AdminTestRun => "admin_test_run", AgentToolCall => "agent_tool_call", } } string_enum! { pub enum ToolOutcome { Success => "success", Error => "error", Aborted => "aborted", } } string_enum! { pub enum ToolErrorKind { None => "none", Schema => "schema", Mapping => "mapping", RestAdapter => "rest_adapter", ProtocolAdapter => "protocol_adapter", UnsupportedProtocol => "unsupported_protocol", UnsupportedExecutionMode => "unsupported_execution_mode", ConcurrencyLimit => "concurrency_limit", InvalidPreparedRequest => "invalid_prepared_request", ConfirmationRequired => "confirmation_required", InvalidConfirmationToken => "invalid_confirmation_token", ConfirmationStore => "confirmation_store", IdempotencyStore => "idempotency_store", IdempotencyInProgress => "idempotency_in_progress", IdempotencyConflict => "idempotency_conflict", IdempotencyOutcomeUnknown => "idempotency_outcome_unknown", MissingAuthProfile => "missing_auth_profile", MissingSecret => "missing_secret", MissingSecretVersion => "missing_secret_version", InvalidAuthSecret => "invalid_auth_secret", SecretCrypto => "secret_crypto", Aborted => "aborted", } } string_enum! { pub enum UpstreamOperationKind { Rest => "rest", } } string_enum! { pub enum UpstreamOutcome { Success => "success", ClientError => "client_error", ServerError => "server_error", UnexpectedStatus => "unexpected_status", Timeout => "timeout", TransportError => "transport_error", ResponseTooLarge => "response_too_large", Rejected => "rejected", WindowExpired => "window_expired", InvalidResponse => "invalid_response", InvalidRequest => "invalid_request", Configuration => "configuration", Aborted => "aborted", } } string_enum! { pub enum LimitStage { Concurrency => "concurrency", RateLimit => "rate_limit", McpStream => "mcp_stream", Admission => "admission", } } string_enum! { pub enum RejectionReason { Limit => "limit", Capacity => "capacity", QueueFull => "queue_full", Deadline => "deadline", Unsupported => "unsupported", DependencyUnavailable => "dependency_unavailable", } } string_enum! { pub enum ScopeKind { Process => "process", Global => "global", Agent => "agent", Tool => "tool", } } string_enum! { pub enum AdmissionModeLabel { Synchronous => "synchronous", Background => "background", } } string_enum! { pub enum CacheOutcome { Hit => "hit", Miss => "miss", ReadError => "read_error", DecodeError => "decode_error", EvictError => "evict_error", Stored => "stored", WriteError => "write_error", } } string_enum! { pub enum IdempotencyOutcome { Execute => "execute", Replay => "replay", Completed => "completed", Conflict => "conflict", InProgress => "in_progress", OutcomeUnknown => "outcome_unknown", StoreUnavailable => "store_unavailable", Error => "error", } } string_enum! { pub enum ConfirmationOutcome { Approved => "approved", Required => "required", InvalidToken => "invalid_token", StoreUnavailable => "store_unavailable", Error => "error", } } string_enum! { pub enum DbPoolState { Idle => "idle", Used => "used", } } string_enum! { pub enum SignalType { Trace => "trace", InvocationHistory => "invocation_history", } } string_enum! { pub enum Exporter { Otlp => "otlp", Postgres => "postgres", } }