Skip to main content

ahp_types/
errors.rs

1// Generated from types/*.ts — do not edit.
2//
3// Regenerate with: npm run generate:rust
4
5#![allow(missing_docs)]
6
7#[allow(unused_imports)]
8use crate::common::{AnyValue, JsonObject, StringOrMarkdown, Uri};
9#[allow(unused_imports)]
10use serde::{Deserialize, Serialize};
11#[allow(unused_imports)]
12use serde_repr::{Deserialize_repr, Serialize_repr};
13
14use crate::commands::ResourceRequestParams;
15use crate::state::ProtectedResourceMetadata;
16
17// ─── Standard JSON-RPC Error Codes ─────────────────────────────────────────
18
19/// Standard JSON-RPC 2.0 error codes.
20pub mod json_rpc_error_codes {
21    /// Invalid JSON.
22    pub const PARSE_ERROR: i32 = -32700;
23    /// Not a valid JSON-RPC request.
24    pub const INVALID_REQUEST: i32 = -32600;
25    /// Unknown method name.
26    pub const METHOD_NOT_FOUND: i32 = -32601;
27    /// Invalid method parameters.
28    pub const INVALID_PARAMS: i32 = -32602;
29    /// Unspecified server error.
30    pub const INTERNAL_ERROR: i32 = -32603;
31}
32
33/// AHP application-specific error codes.
34pub mod ahp_error_codes {
35    /// The referenced session URI does not exist.
36    pub const SESSION_NOT_FOUND: i32 = -32001;
37    /// The requested agent provider is not registered.
38    pub const PROVIDER_NOT_FOUND: i32 = -32002;
39    /// A session with the given URI already exists.
40    pub const SESSION_ALREADY_EXISTS: i32 = -32003;
41    /// The operation requires no active turn, but one is in progress.
42    pub const TURN_IN_PROGRESS: i32 = -32004;
43    /// The server cannot speak any of the protocol versions offered by the
44    /// client in `InitializeParams.protocolVersions`.
45    pub const UNSUPPORTED_PROTOCOL_VERSION: i32 = -32005;
46    /// The requested content URI does not exist.
47    pub const CONTENT_NOT_FOUND: i32 = -32006;
48    /// Authentication required for a protected resource.
49    pub const AUTH_REQUIRED: i32 = -32007;
50    /// The requested file, folder, or URI does not exist.
51    pub const NOT_FOUND: i32 = -32008;
52    /// The client is not permitted to access the requested resource.
53    pub const PERMISSION_DENIED: i32 = -32009;
54    /// The target resource already exists and the operation does not allow overwriting.
55    pub const ALREADY_EXISTS: i32 = -32010;
56    /// An optimistic-concurrency precondition failed: a request's precondition token (e.g. `ResourceWriteParams.if_match`) no longer matches the resource's current state.
57    pub const CONFLICT: i32 = -32011;
58}
59
60/// Type alias: AHP application error code.
61pub type AhpErrorCode = i32;
62/// Type alias: JSON-RPC 2.0 error code.
63pub type JsonRpcErrorCode = i32;
64
65// ─── Error Detail Payloads ────────────────────────────────────────────────
66
67/// Details carried in the `data` field of an `AuthRequired` (-32007) error.
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub struct AuthRequiredErrorData {
71    /// Protected resources that require authentication.
72    pub resources: Vec<ProtectedResourceMetadata>,
73}
74
75/// Details carried in the `data` field of a `PermissionDenied` (-32009) error.
76#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct PermissionDeniedErrorData {
79    /// The resource access that, if granted via `resourceRequest`, would
80    /// unlock the operation. Omitted when no specific access grant would
81    /// resolve the denial.
82    #[serde(default, skip_serializing_if = "Option::is_none")]
83    pub request: Option<ResourceRequestParams>,
84}
85
86/// Details carried in the `data` field of an `UnsupportedProtocolVersion`
87/// (-32005) error.
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
89#[serde(rename_all = "camelCase")]
90pub struct UnsupportedProtocolVersionErrorData {
91    /// Protocol versions the server is willing to speak. Each entry is
92    /// either a SemVer `MAJOR.MINOR.PATCH` string (e.g. `"0.1.0"`) or a
93    /// SemVer range constraint (e.g. `">=0.1.0 <0.3.0"` or `"^0.2.0"`).
94    pub supported_versions: Vec<String>,
95}