Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions codex-rs/app-server-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,20 +617,22 @@ impl InProcessAppServerClient {
where
T: DeserializeOwned,
{
let method = request_method_name(&request);
let method = request.method_name();
let response =
self.request(request)
.await
.map_err(|source| TypedRequestError::Transport {
method: method.clone(),
method: method.to_string(),
source,
})?;
let result = response.map_err(|source| TypedRequestError::Server {
method: method.clone(),
method: method.to_string(),
source,
})?;
serde_json::from_value(result)
.map_err(|source| TypedRequestError::Deserialize { method, source })
serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {
method: method.to_string(),
source,
})
}

/// Sends a typed client notification.
Expand Down Expand Up @@ -790,20 +792,22 @@ impl InProcessAppServerRequestHandle {
where
T: DeserializeOwned,
{
let method = request_method_name(&request);
let method = request.method_name();
let response =
self.request(request)
.await
.map_err(|source| TypedRequestError::Transport {
method: method.clone(),
method: method.to_string(),
source,
})?;
let result = response.map_err(|source| TypedRequestError::Server {
method: method.clone(),
method: method.to_string(),
source,
})?;
serde_json::from_value(result)
.map_err(|source| TypedRequestError::Deserialize { method, source })
serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {
method: method.to_string(),
source,
})
}
}

Expand Down Expand Up @@ -904,20 +908,6 @@ impl AppServerClient {
}
}

/// Extracts the JSON-RPC method name for diagnostics without extending the
/// protocol crate with in-process-only helpers.
pub(crate) fn request_method_name(request: &ClientRequest) -> String {
serde_json::to_value(request)
.ok()
.and_then(|value| {
value
.get("method")
.and_then(serde_json::Value::as_str)
.map(ToOwned::to_owned)
})
.unwrap_or_else(|| "<unknown>".to_string())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
25 changes: 14 additions & 11 deletions codex-rs/app-server-client/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::AppServerEvent;
use crate::RequestResult;
use crate::SHUTDOWN_TIMEOUT;
use crate::TypedRequestError;
use crate::request_method_name;
use codex_app_server_protocol::ClientInfo;
use codex_app_server_protocol::ClientNotification;
use codex_app_server_protocol::ClientRequest;
Expand Down Expand Up @@ -498,20 +497,22 @@ impl RemoteAppServerClient {
where
T: DeserializeOwned,
{
let method = request_method_name(&request);
let method = request.method_name();
let response =
self.request(request)
.await
.map_err(|source| TypedRequestError::Transport {
method: method.clone(),
method: method.to_string(),
source,
})?;
let result = response.map_err(|source| TypedRequestError::Server {
method: method.clone(),
method: method.to_string(),
source,
})?;
serde_json::from_value(result)
.map_err(|source| TypedRequestError::Deserialize { method, source })
serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {
method: method.to_string(),
source,
})
}

pub async fn notify(&self, notification: ClientNotification) -> IoResult<()> {
Expand Down Expand Up @@ -658,20 +659,22 @@ impl RemoteAppServerRequestHandle {
where
T: DeserializeOwned,
{
let method = request_method_name(&request);
let method = request.method_name();
let response =
self.request(request)
.await
.map_err(|source| TypedRequestError::Transport {
method: method.clone(),
method: method.to_string(),
source,
})?;
let result = response.map_err(|source| TypedRequestError::Server {
method: method.clone(),
method: method.to_string(),
source,
})?;
serde_json::from_value(result)
.map_err(|source| TypedRequestError::Deserialize { method, source })
serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {
method: method.to_string(),
source,
})
}
}

Expand Down
7 changes: 0 additions & 7 deletions codex-rs/app-server-protocol/src/protocol/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ macro_rules! client_request_definitions {
}
}

pub fn method(&self) -> String {
self.method_name().to_string()
}

pub fn serialization_scope(&self) -> Option<ClientRequestSerializationScope> {
match self {
$(
Expand Down Expand Up @@ -2671,7 +2667,6 @@ mod tests {
params: None,
};
assert_eq!(request.id(), &RequestId::Integer(1));
assert_eq!(request.method(), "account/rateLimits/read");
assert_eq!(
json!({
"method": "account/rateLimits/read",
Expand All @@ -2689,7 +2684,6 @@ mod tests {
params: None,
};
assert_eq!(request.id(), &RequestId::Integer(1));
assert_eq!(request.method(), "account/usage/read");
assert_eq!(
json!({
"method": "account/usage/read",
Expand All @@ -2707,7 +2701,6 @@ mod tests {
params: None,
};
assert_eq!(request.id(), &RequestId::Integer(1));
assert_eq!(request.method(), "account/workspaceMessages/read");
assert_eq!(
json!({
"method": "account/workspaceMessages/read",
Expand Down
Loading