mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Simplify goal file materialization
This commit is contained in:
@@ -38,7 +38,6 @@ use codex_app_server_protocol::ConfigWarningNotification;
|
||||
use codex_app_server_protocol::InitializeCapabilities;
|
||||
use codex_app_server_protocol::InitializeParams;
|
||||
use codex_app_server_protocol::JSONRPCErrorError;
|
||||
use codex_app_server_protocol::JSONRPCRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::Result as JsonRpcResult;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
@@ -848,16 +847,6 @@ impl AppServerClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn request_json_rpc(&self, request: JSONRPCRequest) -> IoResult<RequestResult> {
|
||||
match self {
|
||||
Self::InProcess(_) => Err(IoError::new(
|
||||
ErrorKind::InvalidInput,
|
||||
"raw JSON-RPC requests are only supported by the remote app-server client",
|
||||
)),
|
||||
Self::Remote(client) => client.request_json_rpc(request).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn request_typed<T>(&self, request: ClientRequest) -> Result<T, TypedRequestError>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
@@ -911,20 +900,6 @@ impl AppServerClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_codex_home(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::InProcess(_) => None,
|
||||
Self::Remote(client) => client.codex_home(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_platform_family(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::InProcess(_) => None,
|
||||
Self::Remote(client) => client.platform_family(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_handle(&self) -> AppServerRequestHandle {
|
||||
match self {
|
||||
Self::InProcess(client) => AppServerRequestHandle::InProcess(client.request_handle()),
|
||||
@@ -1131,8 +1106,6 @@ mod tests {
|
||||
result: serde_json::json!({
|
||||
"userAgent": "codex_cli_rs/9.8.7-test (Test OS; x86_64) rust",
|
||||
"codexHome": "/server/.codex",
|
||||
"platformFamily": "unix",
|
||||
"platformOs": "linux",
|
||||
}),
|
||||
}),
|
||||
)
|
||||
@@ -1470,7 +1443,6 @@ mod tests {
|
||||
|
||||
assert_eq!(client.server_version(), Some("9.8.7-test"));
|
||||
assert_eq!(client.codex_home(), Some("/server/.codex"));
|
||||
assert_eq!(client.platform_family(), Some("unix"));
|
||||
let response: GetAccountResponse = client
|
||||
.request_typed(ClientRequest::GetAccount {
|
||||
request_id: RequestId::Integer(1),
|
||||
|
||||
@@ -152,7 +152,6 @@ pub struct RemoteAppServerClient {
|
||||
pending_events: VecDeque<AppServerEvent>,
|
||||
server_version: Option<String>,
|
||||
codex_home: Option<String>,
|
||||
platform_family: Option<String>,
|
||||
worker_handle: tokio::task::JoinHandle<()>,
|
||||
}
|
||||
|
||||
@@ -160,7 +159,6 @@ pub struct RemoteAppServerClient {
|
||||
struct RemoteInitializeInfo {
|
||||
server_version: Option<String>,
|
||||
codex_home: Option<String>,
|
||||
platform_family: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -198,10 +196,6 @@ impl RemoteAppServerClient {
|
||||
self.codex_home.as_deref()
|
||||
}
|
||||
|
||||
pub fn platform_family(&self) -> Option<&str> {
|
||||
self.platform_family.as_deref()
|
||||
}
|
||||
|
||||
async fn connect_with_stream<S>(
|
||||
channel_capacity: usize,
|
||||
endpoint: String,
|
||||
@@ -235,17 +229,36 @@ impl RemoteAppServerClient {
|
||||
};
|
||||
match command {
|
||||
RemoteClientCommand::Request { request, response_tx } => {
|
||||
if !write_remote_request(
|
||||
let request_id = request.id.clone();
|
||||
if pending_requests.contains_key(&request_id) {
|
||||
let _ = response_tx.send(Err(IoError::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!("duplicate remote app-server request id `{request_id}`"),
|
||||
)));
|
||||
continue;
|
||||
}
|
||||
pending_requests.insert(request_id.clone(), response_tx);
|
||||
if let Err(err) = write_jsonrpc_message(
|
||||
&mut stream,
|
||||
JSONRPCMessage::Request(*request),
|
||||
&endpoint,
|
||||
&mut pending_requests,
|
||||
*request,
|
||||
response_tx,
|
||||
&event_tx,
|
||||
&mut worker_exit_error,
|
||||
)
|
||||
.await
|
||||
{
|
||||
let err_message = err.to_string();
|
||||
let message = format!(
|
||||
"remote app server at `{endpoint}` write failed: {err_message}"
|
||||
);
|
||||
if let Some(response_tx) = pending_requests.remove(&request_id) {
|
||||
let _ = response_tx.send(Err(err));
|
||||
}
|
||||
let _ = deliver_event(
|
||||
&event_tx,
|
||||
AppServerEvent::Disconnected {
|
||||
message: message.clone(),
|
||||
},
|
||||
);
|
||||
worker_exit_error = Some((ErrorKind::BrokenPipe, message));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -471,7 +484,6 @@ impl RemoteAppServerClient {
|
||||
pending_events: pending_events.into(),
|
||||
server_version: initialize_info.server_version,
|
||||
codex_home: initialize_info.codex_home,
|
||||
platform_family: initialize_info.platform_family,
|
||||
worker_handle,
|
||||
})
|
||||
}
|
||||
@@ -487,7 +499,7 @@ impl RemoteAppServerClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn request_json_rpc(&self, request: JSONRPCRequest) -> IoResult<RequestResult> {
|
||||
async fn request_json_rpc(&self, request: JSONRPCRequest) -> IoResult<RequestResult> {
|
||||
let (response_tx, response_rx) = oneshot::channel();
|
||||
self.command_tx
|
||||
.send(RemoteClientCommand::Request {
|
||||
@@ -619,7 +631,6 @@ impl RemoteAppServerClient {
|
||||
pending_events: _pending_events,
|
||||
server_version: _server_version,
|
||||
codex_home: _codex_home,
|
||||
platform_family: _platform_family,
|
||||
worker_handle,
|
||||
} = self;
|
||||
let mut worker_handle = worker_handle;
|
||||
@@ -648,7 +659,7 @@ impl RemoteAppServerRequestHandle {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn request_json_rpc(&self, request: JSONRPCRequest) -> IoResult<RequestResult> {
|
||||
pub async fn request_json_rpc(&self, request: JSONRPCRequest) -> IoResult<RequestResult> {
|
||||
let (response_tx, response_rx) = oneshot::channel();
|
||||
self.command_tx
|
||||
.send(RemoteClientCommand::Request {
|
||||
@@ -856,11 +867,6 @@ where
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.filter(|codex_home| !codex_home.is_empty())
|
||||
.map(str::to_string);
|
||||
initialize_info.platform_family = response
|
||||
.result
|
||||
.get("platformFamily")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::to_string);
|
||||
break Ok(());
|
||||
}
|
||||
JSONRPCMessage::Error(error) if error.id == initialize_request_id => {
|
||||
@@ -974,47 +980,6 @@ fn deliver_event(
|
||||
})
|
||||
}
|
||||
|
||||
async fn write_remote_request<S>(
|
||||
stream: &mut WebSocketStream<S>,
|
||||
endpoint: &str,
|
||||
pending_requests: &mut HashMap<RequestId, oneshot::Sender<IoResult<RequestResult>>>,
|
||||
request: JSONRPCRequest,
|
||||
response_tx: oneshot::Sender<IoResult<RequestResult>>,
|
||||
event_tx: &mpsc::UnboundedSender<AppServerEvent>,
|
||||
worker_exit_error: &mut Option<(ErrorKind, String)>,
|
||||
) -> bool
|
||||
where
|
||||
S: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
let request_id = request.id.clone();
|
||||
if pending_requests.contains_key(&request_id) {
|
||||
let _ = response_tx.send(Err(IoError::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!("duplicate remote app-server request id `{request_id}`"),
|
||||
)));
|
||||
return true;
|
||||
}
|
||||
pending_requests.insert(request_id.clone(), response_tx);
|
||||
if let Err(err) =
|
||||
write_jsonrpc_message(stream, JSONRPCMessage::Request(request), endpoint).await
|
||||
{
|
||||
let err_message = err.to_string();
|
||||
let message = format!("remote app server at `{endpoint}` write failed: {err_message}");
|
||||
if let Some(response_tx) = pending_requests.remove(&request_id) {
|
||||
let _ = response_tx.send(Err(err));
|
||||
}
|
||||
let _ = deliver_event(
|
||||
event_tx,
|
||||
AppServerEvent::Disconnected {
|
||||
message: message.clone(),
|
||||
},
|
||||
);
|
||||
*worker_exit_error = Some((ErrorKind::BrokenPipe, message));
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn jsonrpc_request_from_client_request(request: ClientRequest) -> JSONRPCRequest {
|
||||
let value = match serde_json::to_value(request) {
|
||||
Ok(value) => value,
|
||||
@@ -1085,7 +1050,6 @@ mod tests {
|
||||
pending_events: VecDeque::new(),
|
||||
server_version: None,
|
||||
codex_home: None,
|
||||
platform_family: None,
|
||||
worker_handle,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user