pub struct AcpAgentPeer { /* private fields */ }Expand description
The agent-side transport for ACP.
Constructed via AcpAgentPeer::from_stdio.
The peer owns two tasks (the reader and
the writer); dropping the peer stops the
tasks. The agent process’s own lifecycle
is independent — the agent process is
not owned by this peer.
Implementations§
Source§impl AcpAgentPeer
impl AcpAgentPeer
Sourcepub fn from_stdio<R, W>(stdin: R, stdout: W) -> Self
pub fn from_stdio<R, W>(stdin: R, stdout: W) -> Self
Construct an agent peer from a stdin
reader and a stdout writer. The
generic parameters let the test suite
pass tokio::io::DuplexStream halves
instead of a real ChildStdin /
ChildStdout.
The peer spawns a reader task and a
writer task; the application
communicates with the peer through
the mpsc channels the reader and
writer tasks own. The half moves
happen at construction time; the
returned peer is Send + 'static.
Sourcepub async fn recv_request(&mut self) -> Option<AgentRequest>
pub async fn recv_request(&mut self) -> Option<AgentRequest>
Await the next AgentRequest the
client sent.
Returns None when the reader task
is gone (the client closed its end
of the wire, or the pipe broke).
The application is expected to
shut down its handler loop on
None.
Sourcepub async fn send_reply(
&self,
id: Value,
result: Value,
) -> Result<(), AcpPeerError>
pub async fn send_reply( &self, id: Value, result: Value, ) -> Result<(), AcpPeerError>
Send a success reply for a previously received request.
The wire form is
{ "jsonrpc": "2.0", "id": <id>, "result": <result> }. The id is
the value the request carried; the
peer passes it through unchanged.
Sourcepub async fn send_error(
&self,
id: Value,
code: i64,
message: impl Into<String>,
) -> Result<(), AcpPeerError>
pub async fn send_error( &self, id: Value, code: i64, message: impl Into<String>, ) -> Result<(), AcpPeerError>
Send a JSON-RPC 2.0 error reply for a
previously received request. The
code and message are the
JSON-RPC error code and human-readable
message; the wire form is
{ "jsonrpc": "2.0", "id": <id>, "error": { "code": <code>, "message": <message> } }.
Sourcepub async fn send_notification<Params>(
&self,
method: &str,
params: Params,
) -> Result<(), AcpPeerError>where
Params: Serialize,
pub async fn send_notification<Params>(
&self,
method: &str,
params: Params,
) -> Result<(), AcpPeerError>where
Params: Serialize,
Send a notification to the client.
The wire form is { "jsonrpc": "2.0", "method": ..., "params": ... } with
no id field. The schema’s
session/update is the canonical
example.