mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
829f5b6b59
## Why The app-server and exec-server expose separate JSON-RPC APIs, but exec-server currently sources its serialized protocol and envelope types through app-server-oriented code. Giving each API an explicit owner makes the crate boundary legible without introducing shared generic envelopes. ## What changed - Added `codex-exec-server-protocol` to own exec DTOs, process IDs, and JSON-RPC envelopes. - Updated exec-server clients, transports, handlers, and tests to use the new crate. - Exposed app-server's existing JSON-RPC types through a public `rpc` module while retaining root re-exports. - Preserved existing wire shapes, including exec `PathUri` behavior. ## Stack This is PR 1 of 6. Next: [PR #29721](https://github.com/openai/codex/pull/29721), which moves auth mode below the app wire boundary. ## Validation - Exec-server protocol and server coverage passed in the focused protocol test runs. - App-server protocol schema fixtures passed.
89 lines
2.6 KiB
Rust
89 lines
2.6 KiB
Rust
//! We do not do true JSON-RPC 2.0, as we neither send nor expect the
|
|
//! "jsonrpc": "2.0" field.
|
|
|
|
use codex_protocol::protocol::W3cTraceContext;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use std::fmt;
|
|
use ts_rs::TS;
|
|
|
|
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;
|
|
|
|
/// Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
|
|
#[serde(untagged)]
|
|
pub enum JSONRPCMessage {
|
|
Request(JSONRPCRequest),
|
|
Notification(JSONRPCNotification),
|
|
Response(JSONRPCResponse),
|
|
Error(JSONRPCError),
|
|
}
|
|
|
|
/// A request that expects a response.
|
|
#[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>,
|
|
/// Optional W3C Trace Context for distributed tracing.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
#[ts(optional)]
|
|
pub trace: Option<W3cTraceContext>,
|
|
}
|
|
|
|
/// A notification which does not expect a response.
|
|
#[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>,
|
|
}
|
|
|
|
/// A successful (non-error) response to a request.
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
|
|
pub struct JSONRPCResponse {
|
|
pub id: RequestId,
|
|
pub result: Result,
|
|
}
|
|
|
|
/// A response to a request that indicates an error occurred.
|
|
#[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,
|
|
}
|