Skip to content

Commit 097f6c8

Browse files
committed
style(acp-nats): apply rustfmt formatting
Run cargo fmt to fix formatting in client/mod.rs (match arm indentation for long type annotation) and client/terminal_output.rs (closure formatting and line length).
1 parent b2a84fa commit 097f6c8

3 files changed

Lines changed: 183 additions & 145 deletions

File tree

rsworkspace/crates/acp-nats/src/client/mod.rs

Lines changed: 124 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::nats::{
1818
ClientMethod, FlushClient, PublishClient, RequestClient, SubscribeClient, client,
1919
headers_with_trace_context, parse_client_subject,
2020
};
21-
use agent_client_protocol::{Client, ErrorCode};
21+
use agent_client_protocol::{Client, ErrorCode, Response};
2222
use async_nats::Message;
2323
use bytes::Bytes;
2424
use futures::StreamExt;
@@ -33,24 +33,19 @@ fn jsonrpc_error_response(
3333
code: ErrorCode,
3434
message: &str,
3535
) -> Bytes {
36-
let id_value = serde_json::to_value(&request_id).unwrap_or(serde_json::Value::Null);
37-
let response = serde_json::json!({
38-
"jsonrpc": "2.0",
39-
"id": id_value,
40-
"error": {
41-
"code": i32::from(code),
42-
"message": message
43-
}
44-
});
45-
serde_json::to_vec(&response).unwrap_or_else(|e| {
46-
format!(
47-
"{{\"jsonrpc\":\"2.0\",\"id\":null,\"error\":{{\"code\":{},\"message\":\"failed to serialize error response: {}\"}}}}",
48-
i32::from(code),
49-
e
50-
)
51-
.into_bytes()
52-
})
53-
.into()
36+
let response = Response::<()>::Error {
37+
id: request_id,
38+
error: agent_client_protocol::Error::new(i32::from(code), message),
39+
};
40+
serde_json::to_vec(&response)
41+
.unwrap_or_else(|_| {
42+
format!(
43+
"{{\"jsonrpc\":\"2.0\",\"id\":null,\"error\":{{\"code\":{},\"message\":\"failed to serialize error response\"}}}}",
44+
i32::from(code),
45+
)
46+
.into_bytes()
47+
})
48+
.into()
5449
}
5550
async fn publish_backpressure_error_reply<N: PublishClient + FlushClient, S: JsonSerialize>(
5651
nats: &N,
@@ -211,119 +206,117 @@ async fn dispatch_client_method<
211206

212207
Span::current().record("session_id", parsed.session_id.as_str());
213208

214-
let response_bytes: Option<Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>> = match parsed.method {
215-
ClientMethod::FsReadTextFile => {
216-
fs_read_text_file::handle(
217-
&payload,
218-
ctx.client,
219-
reply.as_deref(),
220-
ctx.nats,
221-
parsed.session_id.as_str(),
222-
ctx.serializer,
223-
)
224-
.await;
225-
None
226-
}
227-
ClientMethod::FsWriteTextFile => {
228-
fs_write_text_file::handle(
229-
&payload,
230-
ctx.client,
231-
reply.as_deref(),
232-
ctx.nats,
233-
parsed.session_id.as_str(),
234-
ctx.serializer,
235-
)
236-
.await;
237-
None
238-
}
239-
ClientMethod::SessionRequestPermission => {
240-
request_permission::handle(
241-
&payload,
242-
ctx.client,
243-
reply.as_deref(),
244-
ctx.nats,
245-
parsed.session_id.as_str(),
246-
ctx.serializer,
247-
)
248-
.await;
249-
None
250-
}
251-
ClientMethod::SessionUpdate => {
252-
if reply.is_some() {
253-
warn!(
254-
session_id = %parsed.session_id,
255-
method = ?parsed.method,
256-
"Unexpected reply subject on notification request"
257-
);
209+
let response_bytes: Option<Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>> =
210+
match parsed.method {
211+
ClientMethod::FsReadTextFile => {
212+
fs_read_text_file::handle(
213+
&payload,
214+
ctx.client,
215+
reply.as_deref(),
216+
ctx.nats,
217+
parsed.session_id.as_str(),
218+
ctx.serializer,
219+
)
220+
.await;
221+
None
258222
}
259-
session_update::handle(&payload, ctx.client).await;
260-
None
261-
}
262-
ClientMethod::ExtSessionPromptResponse => {
263-
ext_session_prompt_response::handle(
264-
parsed.session_id.as_str(),
265-
&payload,
266-
reply.as_deref(),
267-
ctx.bridge,
268-
)
269-
.await;
270-
None
271-
}
272-
ClientMethod::TerminalCreate => {
273-
terminal_create::handle(
274-
&payload,
275-
ctx.client,
276-
reply.as_deref(),
277-
ctx.nats,
278-
parsed.session_id.as_str(),
279-
ctx.serializer,
280-
)
281-
.await;
282-
None
283-
}
284-
ClientMethod::TerminalKill => {
285-
terminal_kill::handle(
286-
&payload,
287-
ctx.client,
288-
reply.as_deref(),
289-
ctx.nats,
290-
parsed.session_id.as_str(),
291-
ctx.serializer,
292-
)
293-
.await;
294-
None
295-
}
296-
ClientMethod::TerminalOutput => {
297-
Some(
298-
terminal_output::handle(&payload, ctx.client, parsed.session_id.as_str()).await,
299-
)
300-
}
301-
ClientMethod::TerminalRelease => {
302-
terminal_release::handle(
303-
&payload,
304-
ctx.client,
305-
reply.as_deref(),
306-
ctx.nats,
307-
parsed.session_id.as_str(),
308-
ctx.serializer,
309-
)
310-
.await;
311-
None
312-
}
313-
ClientMethod::TerminalWaitForExit => {
314-
terminal_wait_for_exit::handle(
315-
&payload,
316-
ctx.client,
317-
reply.as_deref(),
318-
ctx.nats,
319-
parsed.session_id.as_str(),
320-
ctx.bridge.config.operation_timeout(),
321-
ctx.serializer,
322-
)
323-
.await;
324-
None
325-
}
326-
};
223+
ClientMethod::FsWriteTextFile => {
224+
fs_write_text_file::handle(
225+
&payload,
226+
ctx.client,
227+
reply.as_deref(),
228+
ctx.nats,
229+
parsed.session_id.as_str(),
230+
ctx.serializer,
231+
)
232+
.await;
233+
None
234+
}
235+
ClientMethod::SessionRequestPermission => {
236+
request_permission::handle(
237+
&payload,
238+
ctx.client,
239+
reply.as_deref(),
240+
ctx.nats,
241+
parsed.session_id.as_str(),
242+
ctx.serializer,
243+
)
244+
.await;
245+
None
246+
}
247+
ClientMethod::SessionUpdate => {
248+
session_update::handle(&payload, ctx.client, reply.is_some()).await;
249+
None
250+
}
251+
ClientMethod::ExtSessionPromptResponse => {
252+
ext_session_prompt_response::handle(
253+
parsed.session_id.as_str(),
254+
&payload,
255+
reply.as_deref(),
256+
ctx.bridge,
257+
)
258+
.await;
259+
None
260+
}
261+
ClientMethod::TerminalCreate => {
262+
terminal_create::handle(
263+
&payload,
264+
ctx.client,
265+
reply.as_deref(),
266+
ctx.nats,
267+
parsed.session_id.as_str(),
268+
ctx.serializer,
269+
)
270+
.await;
271+
None
272+
}
273+
ClientMethod::TerminalKill => {
274+
terminal_kill::handle(
275+
&payload,
276+
ctx.client,
277+
reply.as_deref(),
278+
ctx.nats,
279+
parsed.session_id.as_str(),
280+
ctx.serializer,
281+
)
282+
.await;
283+
None
284+
}
285+
ClientMethod::TerminalOutput => {
286+
terminal_output::handle(
287+
&payload,
288+
ctx.client,
289+
parsed.session_id.as_str(),
290+
reply.is_some(),
291+
)
292+
.await
293+
}
294+
ClientMethod::TerminalRelease => {
295+
terminal_release::handle(
296+
&payload,
297+
ctx.client,
298+
reply.as_deref(),
299+
ctx.nats,
300+
parsed.session_id.as_str(),
301+
ctx.serializer,
302+
)
303+
.await;
304+
None
305+
}
306+
ClientMethod::TerminalWaitForExit => {
307+
terminal_wait_for_exit::handle(
308+
&payload,
309+
ctx.client,
310+
reply.as_deref(),
311+
ctx.nats,
312+
parsed.session_id.as_str(),
313+
ctx.bridge.config.operation_timeout(),
314+
ctx.serializer,
315+
)
316+
.await;
317+
None
318+
}
319+
};
327320

328321
if let (Some(reply_to), Some(result)) = (reply, response_bytes) {
329322
match result {

rsworkspace/crates/acp-nats/src/client/session_update.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use agent_client_protocol::{Client, SessionNotification};
22
use tracing::{instrument, warn};
33

44
#[instrument(name = "acp.client.session.update", skip(payload, client))]
5-
pub async fn handle<C: Client>(payload: &[u8], client: &C) {
5+
pub async fn handle<C: Client>(payload: &[u8], client: &C, has_reply: bool) {
6+
if has_reply {
7+
warn!("Unexpected reply subject on notification request");
8+
}
69
match serde_json::from_slice::<SessionNotification>(payload) {
710
Ok(notification) => {
811
if let Err(e) = client.session_notification(notification).await {
@@ -82,15 +85,15 @@ mod tests {
8285
);
8386
let payload = serde_json::to_vec(&notification).unwrap();
8487

85-
super::handle(&payload, &client).await;
88+
super::handle(&payload, &client, false).await;
8689

8790
assert_eq!(client.notification_count(), 1);
8891
}
8992

9093
#[tokio::test]
9194
async fn invalid_payload_does_not_panic() {
9295
let client = MockClient::new();
93-
super::handle(b"not json", &client).await;
96+
super::handle(b"not json", &client, false).await;
9497
assert_eq!(client.notification_count(), 0);
9598
}
9699

@@ -103,6 +106,6 @@ mod tests {
103106
);
104107
let payload = serde_json::to_vec(&notification).unwrap();
105108

106-
super::handle(&payload, &client).await;
109+
super::handle(&payload, &client, false).await;
107110
}
108111
}

0 commit comments

Comments
 (0)