Skip to content

Commit 986e0c6

Browse files
committed
refactor: rename handler chain terminology to connection builder
- Rename Conductor::into_handler_chain() to into_connection_builder() - Rename JrConnectionBuilder::with_handler_chain() to with_connection_builder() - Rename test file jsonrpc_handler_chain.rs to jsonrpc_connection_builder.rs - Update docs and comments throughout to use 'connection builder' and 'registered handlers' instead of 'handler chain'
1 parent c39988d commit 986e0c6

12 files changed

Lines changed: 37 additions & 37 deletions

File tree

md/trace-viewer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ sacp-conductor agent --trace ./trace.jsons "proxy1" "proxy2" "agent"
226226
```rust
227227
Conductor::new(name, components, mcp_bridge_mode)
228228
.trace_to("./trace.jsons")
229-
.into_handler_chain()
229+
.into_connection_builder()
230230
// ...
231231
```
232232

md/transport-architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ Responsibilities:
6565
#### Incoming Protocol Actor
6666
```
6767
Input: mpsc::UnboundedReceiver<jsonrpcmsg::Message>
68-
Output: Routes to reply_actor or handler chain
68+
Output: Routes to reply_actor or registered handlers
6969
```
7070

7171
Responsibilities:
7272
- Route responses to reply_actor (matches by ID)
73-
- Route requests/notifications to handler chain
73+
- Route requests/notifications to registered handlers
7474
- Convert `jsonrpcmsg::Request` to `UntypedMessage` for handlers
7575

7676
#### Reply Actor
@@ -149,7 +149,7 @@ Transport Incoming Actor
149149
|
150150
Incoming Protocol Actor
151151
| - Route responses → reply_actor
152-
| - Route requests → handler chain
152+
| - Route requests → registered handlers
153153
v
154154
Handler or Reply Actor
155155
```
@@ -269,7 +269,7 @@ Benefits:
269269
The refactored API separates handler setup from transport selection:
270270

271271
```rust
272-
// Build handler chain
272+
// Build connection with handlers
273273
let connection = JrConnection::new()
274274
.name("my-component")
275275
.on_receive_request(|req: InitializeRequest, cx| {

skills/sacp-v2-migration/skill.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: sacp-v2-migration
3-
description: Migrate Rust code from sacp v1.x to v2.0 role-based API. Use when upgrading sacp dependencies, fixing JrHandlerChain errors, or when code references MessageAndCx or old connection patterns.
3+
description: Migrate Rust code from sacp v1.x to v2.0 role-based API. Use when upgrading sacp dependencies, fixing JrConnectionBuilder errors, or when code references MessageAndCx or old connection patterns.
44
---
55

66
# SACP v2 Migration
@@ -9,7 +9,7 @@ description: Migrate Rust code from sacp v1.x to v2.0 role-based API. Use when u
99

1010
Apply these transformations when migrating from sacp v1.x to v2.0:
1111

12-
### 1. Replace JrHandlerChain with role builder
12+
### 1. Replace JrHandlerChain with role-based connection builder
1313

1414
```rust
1515
// Before

src/sacp-conductor/src/conductor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Conductor {
191191
self
192192
}
193193

194-
pub fn into_handler_chain(self) -> JrConnectionBuilder<ConductorMessageHandler> {
194+
pub fn into_connection_builder(self) -> JrConnectionBuilder<ConductorMessageHandler> {
195195
let (mut conductor_tx, mut conductor_rx) = mpsc::channel(128 /* chosen arbitrarily */);
196196

197197
let mut state = ConductorHandlerState {
@@ -228,13 +228,13 @@ impl Conductor {
228228
///
229229
/// This is equivalent to:
230230
/// ```ignore
231-
/// conductor.into_handler_chain()
231+
/// conductor.into_connection_builder()
232232
/// .connect_to(transport)
233233
/// .serve()
234234
/// .await
235235
/// ```
236236
pub async fn run(self, transport: impl Component + 'static) -> Result<(), sacp::Error> {
237-
self.into_handler_chain()
237+
self.into_connection_builder()
238238
.connect_to(transport)?
239239
.serve()
240240
.await

src/sacp-conductor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl ConductorArgs {
288288
}
289289

290290
conductor
291-
.into_handler_chain()
291+
.into_connection_builder()
292292
.connect_to(stdio)?
293293
.serve()
294294
.await

src/sacp-tee/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Component for Tee {
205205
}
206206
});
207207

208-
// Create the handler chain
208+
// Create the connection
209209
ProxyToConductor::builder()
210210
.name("sacp-tee")
211211
.with_handler(TeeHandler::new(log_tx))

src/sacp/src/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use crate::Channel;
6666
///
6767
/// impl Component for MyProxy {
6868
/// async fn serve(self, client: impl Component) -> Result<(), sacp::Error> {
69-
/// // Set up handler chain that forwards to client
69+
/// // Set up connection that forwards to client
7070
/// sacp::UntypedRole::builder()
7171
/// .name("my-proxy")
7272
/// .on_receive_request(async |req: MyRequest, cx| {
@@ -97,7 +97,7 @@ use crate::Channel;
9797
pub trait Component: Send + 'static {
9898
/// Serve this component by forwarding to a client component.
9999
///
100-
/// Most components implement this method to set up their handler chain and
100+
/// Most components implement this method to set up their connection and
101101
/// forward messages to the provided client.
102102
///
103103
/// # Arguments

src/sacp/src/jsonrpc.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub trait JrMessageHandler {
189189
cx: JrConnectionCx<Self::Role>,
190190
) -> Result<Handled<MessageCx>, crate::Error>;
191191

192-
/// Returns a debug description of the handler chain for diagnostics
192+
/// Returns a debug description of the registered handlers for diagnostics.
193193
fn describe_chain(&self) -> impl std::fmt::Debug;
194194
}
195195

@@ -213,7 +213,7 @@ pub trait JrMessageHandlerSend: Send {
213213
cx: JrConnectionCx<Self::Role>,
214214
) -> impl Future<Output = Result<Handled<MessageCx>, crate::Error>> + Send;
215215

216-
/// Describe this handler chain.
216+
/// Returns a debug description of the registered handlers for diagnostics.
217217
fn describe_chain(&self) -> impl std::fmt::Debug;
218218
}
219219

@@ -554,7 +554,7 @@ impl<Role: JrRole> JrConnectionBuilder<NullHandler<Role>> {
554554
}
555555

556556
impl<H: JrMessageHandler> JrConnectionBuilder<H> {
557-
/// Create a new handler chain with the given handler and roles.
557+
/// Create a new connection builder with the given handler.
558558
pub fn new_with(handler: H) -> Self {
559559
Self {
560560
name: Default::default(),
@@ -573,29 +573,29 @@ impl<H: JrMessageHandler> JrConnectionBuilder<H> {
573573
574574
/// Returns a reference to the remote role.
575575
576-
/// Add a new [`JrMessageHandler`] to the chain.
576+
/// Merge another [`JrConnectionBuilder`] into this one.
577577
///
578578
/// Prefer [`Self::on_receive_request`] or [`Self::on_receive_notification`].
579579
/// This is a low-level method that is not intended for general use.
580-
pub fn with_handler_chain<H1>(
580+
pub fn with_connection_builder<H1>(
581581
mut self,
582-
handler_chain: JrConnectionBuilder<H1>,
582+
other: JrConnectionBuilder<H1>,
583583
) -> JrConnectionBuilder<ChainedHandler<H, NamedHandler<H1>>>
584584
where
585585
H1: JrMessageHandler<Role = H::Role>,
586586
{
587587
self.pending_tasks.extend(
588-
handler_chain
588+
other
589589
.pending_tasks
590590
.into_iter()
591-
.map(|t| t.named(handler_chain.name.clone())),
591+
.map(|t| t.named(other.name.clone())),
592592
);
593593

594594
JrConnectionBuilder {
595595
name: self.name,
596596
handler: ChainedHandler::new(
597597
self.handler,
598-
NamedHandler::new(handler_chain.name, handler_chain.handler),
598+
NamedHandler::new(other.name, other.handler),
599599
),
600600
pending_tasks: self.pending_tasks,
601601
}
@@ -968,10 +968,10 @@ impl<H: JrMessageHandler> JrConnectionBuilder<H> {
968968
})
969969
}
970970

971-
/// Apply the handler chain to a single message.
971+
/// Apply the registered handlers to a single message.
972972
///
973-
/// This method processes one message through the entire handler chain, attempting to
974-
/// match it against each registered handler in order. This is useful when implementing
973+
/// This method processes one message through all registered handlers, attempting to
974+
/// match it against each handler in order. This is useful when implementing
975975
/// custom message handling logic or when you need fine-grained control over message
976976
/// processing.
977977
///
@@ -992,7 +992,7 @@ impl<H: JrMessageHandler> JrConnectionBuilder<H> {
992992
///
993993
/// # Example: Borrow Checker Challenges
994994
///
995-
/// When building a handler chain with `async {}` blocks (non-move), you might encounter
995+
/// When building a connection with `async {}` blocks (non-move), you might encounter
996996
/// borrow checker errors if multiple handlers need access to the same mutable state:
997997
///
998998
/// ```compile_fail
@@ -1333,7 +1333,7 @@ pub enum Handled<T> {
13331333
/// Trait for converting handler return values into [`Handled`].
13341334
///
13351335
/// This trait allows handlers to return either `()` (which becomes `Handled::Yes`)
1336-
/// or an explicit `Handled<T>` value for more control over handler chain propagation.
1336+
/// or an explicit `Handled<T>` value for more control over handler propagation.
13371337
pub trait IntoHandled<T> {
13381338
/// Convert this value into a `Handled<T>`.
13391339
fn into_handled(self) -> Handled<T>;
@@ -1718,7 +1718,7 @@ impl<Role: JrRole> JrConnectionCx<Role> {
17181718
///
17191719
/// Dynamic message handlers are called first for every incoming message.
17201720
///
1721-
/// If they decline to handle the message, then the message is passed to the regular handler chain.
1721+
/// If they decline to handle the message, then the message is passed to the regular registered handlers.
17221722
///
17231723
/// The handler will stay registered until the [`DynamicHandlerRegistration`] is dropped.
17241724
pub fn add_dynamic_handler(
@@ -2858,7 +2858,7 @@ where
28582858
/// tokio::io::stdin().compat(),
28592859
/// );
28602860
///
2861-
/// // Use as a component in a handler chain
2861+
/// // Use as a component in a connection
28622862
/// sacp::role::UntypedRole::builder()
28632863
/// .name("my-client")
28642864
/// .serve(component)

src/sacp/src/jsonrpc/incoming_actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::Handled;
2121
///
2222
/// This actor handles JSON-RPC protocol semantics:
2323
/// - Routes responses to reply_actor (for request/response correlation)
24-
/// - Routes requests/notifications to handler chain
24+
/// - Routes requests/notifications to registered handlers
2525
/// - Converts jsonrpcmsg::Request to UntypedMessage for handlers
2626
///
2727
/// This is the protocol layer - it has no knowledge of how messages arrived.

src/sacp/src/mcp_server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! let registry = McpServiceRegistry::new()
1818
//! .with_mcp_server("my-server", server)?;
1919
//!
20-
//! // Use the registry in your handler chain
20+
//! // Use the registry in your connection
2121
//! UntypedRole::builder()
2222
//! .with_handler(registry)
2323
//! .serve(connection)

0 commit comments

Comments
 (0)