| |
| |
|
|
| use crate::JsonSchema; |
| use crate::TS; |
| use codex_protocol::protocol::W3cTraceContext; |
| use serde::Deserialize; |
| use serde::Serialize; |
| use std::fmt; |
|
|
| pub const JSONRPC_VERSION: &str = "2.0"; |
|
|
| #[derive( |
| Debug, Clone, PartialEq, PartialOrd, Ord, Deserialize, Serialize, Hash, Eq, JsonSchema, TS, |
| )] |
| #[serde(untagged)] |
| pub enum RequestId { |
| String(String), |
| #[ts(type = "number")] |
| Integer(i64), |
| } |
|
|
| impl fmt::Display for RequestId { |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| match self { |
| Self::String(value) => f.write_str(value), |
| Self::Integer(value) => write!(f, "{value}"), |
| } |
| } |
| } |
|
|
| pub type Result = serde_json::Value; |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| #[serde(untagged)] |
| pub enum JSONRPCMessage { |
| Request(JSONRPCRequest), |
| Notification(JSONRPCNotification), |
| Response(JSONRPCResponse), |
| Error(JSONRPCError), |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| pub struct JSONRPCRequest { |
| pub id: RequestId, |
| pub method: String, |
| #[serde(default, skip_serializing_if = "Option::is_none")] |
| #[ts(optional)] |
| pub params: Option<serde_json::Value>, |
| |
| #[serde(default, skip_serializing_if = "Option::is_none")] |
| #[ts(optional)] |
| pub trace: Option<W3cTraceContext>, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| pub struct JSONRPCNotification { |
| pub method: String, |
| #[serde(default, skip_serializing_if = "Option::is_none")] |
| #[ts(optional)] |
| pub params: Option<serde_json::Value>, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| pub struct JSONRPCResponse { |
| pub id: RequestId, |
| pub result: Result, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| pub struct JSONRPCError { |
| pub error: JSONRPCErrorError, |
| pub id: RequestId, |
| } |
|
|
| #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] |
| pub struct JSONRPCErrorError { |
| pub code: i64, |
| #[serde(default, skip_serializing_if = "Option::is_none")] |
| #[ts(optional)] |
| pub data: Option<serde_json::Value>, |
| pub message: String, |
| } |
|
|