Skip to content

Commit d8df88c

Browse files
fix(acp): remove boxfnonce dependency in favor of Box<dyn FnOnce> (#137)
* refactor(acp): remove boxfnonce dependency in favor of Box<dyn FnOnce> Signed-off-by: Sachin Bhat <sachubhat17@gmail.com> * chore(deps): bump tokio, rmcp, clap, hyper, and other workspace dependencies Signed-off-by: Sachin Bhat <sachubhat17@gmail.com> * style(acp): remove redundant wildcard patterns flagged by clippy Signed-off-by: Sachin Bhat <sachubhat17@gmail.com> * Revert unnecessary changes --------- Signed-off-by: Sachin Bhat <sachubhat17@gmail.com> Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
1 parent 739c07b commit d8df88c

5 files changed

Lines changed: 28 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ tower-http = { version = "0.6", features = ["fs"] }
7272
async-broadcast = "0.7"
7373
async-stream = "0.3.6"
7474
async-trait = "0.1"
75-
boxfnonce = "0.1.1"
7675
chrono = "0.4"
7776
derive_more = { version = "2", features = ["from"] }
7877
futures = "0.3.32"

src/agent-client-protocol/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ unstable_session_usage = ["agent-client-protocol-schema/unstable_session_usage"]
4242
agent-client-protocol-schema.workspace = true
4343
agent-client-protocol-derive.workspace = true
4444
anyhow.workspace = true
45-
boxfnonce.workspace = true
4645
futures.workspace = true
4746
futures-concurrency.workspace = true
4847
rustc-hash.workspace = true

src/agent-client-protocol/src/jsonrpc.rs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::panic::Location;
1111
use std::pin::pin;
1212
use uuid::Uuid;
1313

14-
use boxfnonce::SendBoxFnOnce;
1514
use futures::channel::{mpsc, oneshot};
1615
use futures::future::{self, BoxFuture, Either};
1716
use futures::{AsyncRead, AsyncWrite, StreamExt};
@@ -1900,7 +1899,7 @@ pub struct Responder<T: JsonRpcResponse = serde_json::Value> {
19001899
///
19011900
/// For incoming requests: serializes to JSON and sends over the wire.
19021901
/// For incoming responses: sends to the waiting oneshot channel.
1903-
send_fn: SendBoxFnOnce<'static, (Result<T, crate::Error>,), Result<(), crate::Error>>,
1902+
send_fn: Box<dyn FnOnce(Result<T, crate::Error>) -> Result<(), crate::Error> + Send>,
19041903
}
19051904

19061905
impl<T: JsonRpcResponse> std::fmt::Debug for Responder<T> {
@@ -1922,17 +1921,15 @@ impl Responder<serde_json::Value> {
19221921
Self {
19231922
method,
19241923
id,
1925-
send_fn: SendBoxFnOnce::new(
1926-
move |response: Result<serde_json::Value, crate::Error>| {
1927-
send_raw_message(
1928-
&message_tx,
1929-
OutgoingMessage::Response {
1930-
id: id_clone,
1931-
response,
1932-
},
1933-
)
1934-
},
1935-
),
1924+
send_fn: Box::new(move |response: Result<serde_json::Value, crate::Error>| {
1925+
send_raw_message(
1926+
&message_tx,
1927+
OutgoingMessage::Response {
1928+
id: id_clone,
1929+
response,
1930+
},
1931+
)
1932+
}),
19361933
}
19371934
}
19381935

@@ -1988,9 +1985,9 @@ impl<T: JsonRpcResponse> Responder<T> {
19881985
Responder {
19891986
method: self.method,
19901987
id: self.id,
1991-
send_fn: SendBoxFnOnce::new(move |input: Result<U, crate::Error>| {
1988+
send_fn: Box::new(move |input: Result<U, crate::Error>| {
19921989
let t_value = wrap_fn(&method, input);
1993-
self.send_fn.call(t_value)
1990+
(self.send_fn)(t_value)
19941991
}),
19951992
}
19961993
}
@@ -2001,7 +1998,7 @@ impl<T: JsonRpcResponse> Responder<T> {
20011998
response: Result<T, crate::Error>,
20021999
) -> Result<(), crate::Error> {
20032000
tracing::debug!(id = ?self.id, "respond called");
2004-
self.send_fn.call(response)
2001+
(self.send_fn)(response)
20052002
}
20062003

20072004
/// Respond to the JSON-RPC request with a value.
@@ -2042,7 +2039,7 @@ pub struct ResponseRouter<T: JsonRpcResponse = serde_json::Value> {
20422039
role_id: RoleId,
20432040

20442041
/// Function to send the response to the waiting task.
2045-
send_fn: SendBoxFnOnce<'static, (Result<T, crate::Error>,), Result<(), crate::Error>>,
2042+
send_fn: Box<dyn FnOnce(Result<T, crate::Error>) -> Result<(), crate::Error> + Send>,
20462043
}
20472044

20482045
impl<T: JsonRpcResponse> std::fmt::Debug for ResponseRouter<T> {
@@ -2070,18 +2067,16 @@ impl ResponseRouter<serde_json::Value> {
20702067
method,
20712068
id,
20722069
role_id,
2073-
send_fn: SendBoxFnOnce::new(
2074-
move |response: Result<serde_json::Value, crate::Error>| {
2075-
sender
2076-
.send(ResponsePayload {
2077-
result: response,
2078-
ack_tx: None,
2079-
})
2080-
.map_err(|_| {
2081-
crate::util::internal_error("failed to send response, receiver dropped")
2082-
})
2083-
},
2084-
),
2070+
send_fn: Box::new(move |response: Result<serde_json::Value, crate::Error>| {
2071+
sender
2072+
.send(ResponsePayload {
2073+
result: response,
2074+
ack_tx: None,
2075+
})
2076+
.map_err(|_| {
2077+
crate::util::internal_error("failed to send response, receiver dropped")
2078+
})
2079+
}),
20852080
}
20862081
}
20872082

@@ -2137,9 +2132,9 @@ impl<T: JsonRpcResponse> ResponseRouter<T> {
21372132
method: self.method,
21382133
id: self.id,
21392134
role_id: self.role_id,
2140-
send_fn: SendBoxFnOnce::new(move |input: Result<U, crate::Error>| {
2135+
send_fn: Box::new(move |input: Result<U, crate::Error>| {
21412136
let t_value = wrap_fn(&method, input);
2142-
self.send_fn.call(t_value)
2137+
(self.send_fn)(t_value)
21432138
}),
21442139
}
21452140
}
@@ -2150,7 +2145,7 @@ impl<T: JsonRpcResponse> ResponseRouter<T> {
21502145
response: Result<T, crate::Error>,
21512146
) -> Result<(), crate::Error> {
21522147
tracing::debug!(id = ?self.id, "response routed to awaiter");
2153-
self.send_fn.call(response)
2148+
(self.send_fn)(response)
21542149
}
21552150

21562151
/// Complete the response by sending a value to the waiting task.

src/agent-client-protocol/src/session.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,7 @@ where
565565
PromptRequest::new(self.session_id.clone(), vec![prompt.to_string().into()]),
566566
)
567567
.on_receiving_result(async move |result| {
568-
let PromptResponse {
569-
stop_reason,
570-
meta: _,
571-
..
572-
} = result?;
568+
let PromptResponse { stop_reason, .. } = result?;
573569

574570
update_tx
575571
.unbounded_send(SessionMessage::StopReason(stop_reason))
@@ -602,7 +598,6 @@ where
602598
.if_notification(async |notif: SessionNotification| match notif.update {
603599
SessionUpdate::AgentMessageChunk(ContentChunk {
604600
content: ContentBlock::Text(text),
605-
meta: _,
606601
..
607602
}) => {
608603
output.push_str(&text.text);

0 commit comments

Comments
 (0)