pub trait Component: Send + 'static {
// Required method
fn serve(
self,
channels: Channels,
) -> impl Future<Output = Result<(), Error>> + Send;
}Expand description
Re-export component types from sacp A component that can participate in the Agent-Client Protocol.
This trait represents anything that can communicate via JSON-RPC messages over channels -
agents, proxies, in-process connections, or any ACP-speaking component. Components receive
Channels for bidirectional message passing and serve on those channels until completion.
§Component Types
The trait is implemented by several built-in types representing different communication patterns:
ByteStreams: A component communicating over byte streams (stdin/stdout, sockets, etc.)Channels: A component communicating via in-process message channels (for testing or direct connections)AcpAgent: An external agent running in a separate process with stdio communication- Custom components: Proxies, transformers, or any ACP-aware service
§Implementation
Implement this trait using async fn syntax. Most components set up a JrHandlerChain
to handle incoming messages:
use sacp::Component;
use sacp::Channels;
struct MyProxy {
config: ProxyConfig,
}
impl Component for MyProxy {
async fn serve(self, channels: Channels) -> Result<(), sacp::Error> {
sacp::JrHandlerChain::new()
.name("my-proxy")
.on_receive_request(async |req: MyRequest, cx| {
// Transform and forward request
cx.respond(MyResponse { status: "ok".into() })
})
.serve(channels)
.await
}
}§Heterogeneous Collections
For storing different component types in the same collection, use DynComponent:
let components: Vec<DynComponent> = vec![
DynComponent::new(proxy1),
DynComponent::new(proxy2),
DynComponent::new(agent),
];Required Methods§
Sourcefn serve(
self,
channels: Channels,
) -> impl Future<Output = Result<(), Error>> + Send
fn serve( self, channels: Channels, ) -> impl Future<Output = Result<(), Error>> + Send
Serve this component on the given channels.
The component should set up its handler chain and serve on the provided channels, which connect it to its conductor.
§Arguments
channels- Bidirectional message channels for communicating with the conductor
§Returns
A future that resolves when the component stops serving, either successfully
or with an error. The future must be Send.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.