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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ agent-client-protocol-trace-viewer = { path = "src/agent-client-protocol-trace-v
yopo = { package = "agent-client-protocol-yopo", path = "src/yopo" }

# Protocol
agent-client-protocol-schema = { version = "=0.13.6", features = ["tracing"] }
agent-client-protocol-schema = { version = "=0.13.8", features = ["tracing"] }

# Core async runtime
tokio = { version = "1.52", features = ["full"] }
Expand Down
13 changes: 9 additions & 4 deletions src/agent-client-protocol-conductor/tests/trace_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl EventNormalizer {
fn normalize_json(&mut self, value: serde_json::Value) -> serde_json::Value {
match value {
serde_json::Value::Object(map) => {
let normalized: serde_json::Map<String, serde_json::Value> = map
let mut normalized: serde_json::Map<String, serde_json::Value> = map
.into_iter()
.map(|(k, v)| {
let v = if k == "sessionId" {
Expand All @@ -89,6 +89,14 @@ impl EventNormalizer {
(k, v)
})
.collect();
if matches!(
normalized.get("auth"),
Some(serde_json::Value::Object(auth))
if auth.len() == 1
&& auth.get("terminal") == Some(&serde_json::Value::Bool(false))
) {
normalized.remove("auth");
}
serde_json::Value::Object(normalized)
}
serde_json::Value::Array(arr) => {
Expand Down Expand Up @@ -197,9 +205,6 @@ async fn test_trace_snapshot() -> Result<(), agent_client_protocol::Error> {
"writeTextFile": Bool(false),
},
"terminal": Bool(false),
"auth": Object {
"terminal": Bool(false),
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/agent-client-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ unstable = [
"unstable_elicitation",
"unstable_end_turn_token_usage",
"unstable_mcp_over_acp",
"unstable_model_config_category",
"unstable_session_fork",
]
unstable_auth_methods = ["agent-client-protocol-schema/unstable_auth_methods"]
Expand All @@ -34,6 +35,7 @@ unstable_cancel_request = ["agent-client-protocol-schema/unstable_cancel_request
unstable_elicitation = ["agent-client-protocol-schema/unstable_elicitation"]
unstable_end_turn_token_usage = ["agent-client-protocol-schema/unstable_end_turn_token_usage"]
unstable_mcp_over_acp = ["agent-client-protocol-schema/unstable_mcp_over_acp"]
unstable_model_config_category = ["agent-client-protocol-schema/unstable_model_config_category"]
unstable_session_fork = ["agent-client-protocol-schema/unstable_session_fork"]
unstable_protocol_v2 = ["agent-client-protocol-schema/unstable_protocol_v2"]

Expand Down
78 changes: 44 additions & 34 deletions src/agent-client-protocol/src/jsonrpc/incoming_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,19 @@ pub(super) async fn incoming_protocol_actor<Counterpart: Role>(
&protocol_compat,
&request_cancellations,
) {
Ok(dispatch) => {
dispatch_dispatch(
counterpart.clone(),
connection,
dispatch,
&mut dynamic_handlers,
&mut handler,
&mut pending_messages,
&request_cancellations,
)
.await?;
Ok(dispatches) => {
for dispatch in dispatches {
dispatch_dispatch(
counterpart.clone(),
connection,
dispatch,
&mut dynamic_handlers,
&mut handler,
&mut pending_messages,
&request_cancellations,
)
.await?;
}
}
Err(error) => {
report_handler_error(
Expand All @@ -188,17 +190,19 @@ pub(super) async fn incoming_protocol_actor<Counterpart: Role>(
&protocol_compat,
&request_cancellations,
) {
Ok(dispatch) => {
dispatch_dispatch(
counterpart.clone(),
connection,
dispatch,
&mut dynamic_handlers,
&mut handler,
&mut pending_messages,
&request_cancellations,
)
.await?;
Ok(dispatches) => {
for dispatch in dispatches {
dispatch_dispatch(
counterpart.clone(),
connection,
dispatch,
&mut dynamic_handlers,
&mut handler,
&mut pending_messages,
&request_cancellations,
)
.await?;
}
}
Err(error) => {
report_handler_error(connection, None, request_method, error)?;
Expand Down Expand Up @@ -266,22 +270,28 @@ fn dispatch_from_message<Counterpart: Role>(
id: Option<agent_client_protocol_schema::RequestId>,
protocol_compat: &ProtocolCompat,
request_cancellations: &super::RequestCancellationRegistry,
) -> Result<Dispatch, crate::Error> {
) -> Result<Vec<Dispatch>, crate::Error> {
let message = UntypedMessage::new(&method, crate::jsonrpc::params_from_transport(params))
.expect("well-formed JSON");
let message = protocol_compat.incoming_message(message)?;

match id {
Some(id) => Ok(Dispatch::Request(
message,
Responder::new(
connection.message_tx.clone(),
method.to_string(),
id,
request_cancellations,
),
)),
None => Ok(Dispatch::Notification(message)),
Some(id) => {
let message = protocol_compat.incoming_message(message)?;
Ok(vec![Dispatch::Request(
message,
Responder::new(
connection.message_tx.clone(),
method.to_string(),
id,
request_cancellations,
),
)])
}
None => Ok(protocol_compat
.incoming_notification(message)?
.into_iter()
.map(Dispatch::Notification)
.collect()),
}
}

Expand Down
30 changes: 24 additions & 6 deletions src/agent-client-protocol/src/jsonrpc/outgoing_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,33 @@ pub(super) async fn outgoing_protocol_actor(
request
}
OutgoingMessage::Notification { untyped } => {
match protocol_compat
.outgoing_message(untyped)
.and_then(|untyped| untyped.into_raw_jsonrpc_message(None))
{
Ok(msg) => msg,
let messages = match protocol_compat.outgoing_notification(untyped) {
Ok(messages) => messages,
Err(error) => {
tracing::warn!(
?error,
"Dropping outgoing notification after conversion failed"
);
continue;
}
};

for untyped in messages {
let message = match untyped.into_raw_jsonrpc_message(None) {
Ok(message) => message,
Err(error) => {
tracing::warn!(
?error,
"Dropping outgoing notification after serialization failed"
);
continue;
}
};
transport_tx
.unbounded_send(Ok(message))
.map_err(crate::Error::into_internal_error)?;
}
continue;
}
OutgoingMessage::Response {
id,
Expand Down Expand Up @@ -146,6 +160,10 @@ mod tests {
crate::UntypedMessage::new("session/new", serde_json::json!({}))
}

fn malformed_v2_known_notification() -> Result<crate::UntypedMessage, crate::Error> {
crate::UntypedMessage::new("session/update", serde_json::json!({}))
}

#[tokio::test(flavor = "current_thread")]
async fn failed_request_conversion_completes_request_locally() -> Result<(), crate::Error> {
let (outgoing_tx, outgoing_rx) = mpsc::unbounded();
Expand Down Expand Up @@ -196,7 +214,7 @@ mod tests {

outgoing_tx
.unbounded_send(OutgoingMessage::Notification {
untyped: malformed_v2_known_method()?,
untyped: malformed_v2_known_notification()?,
})
.map_err(crate::Error::into_internal_error)?;
outgoing_tx
Expand Down
Loading