pub struct Connection { /* private fields */ }Expand description
A handle to a live ACP connection driven by the agent-client-protocol crate.
Constructed with Connection::spawn, which owns the transport and runs the crate’s
JSON-RPC dispatch loop on a background task for the connection’s whole lifetime.
§Single-flight, single-session limitation
The driver’s command loop (spawned by Connection::spawn) awaits the reply to
initialize / new_session before pulling the next command off the channel. prompt
is the exception: the loop runs the prompt turn on a cx.spawned task (AU‑3) so a
concurrent Cancel (session/cancel) can actually interrupt it — a block_task().await
inline would pin the loop for the whole turn and starve the very cancel meant to stop it.
Notifications are connection-wide, not scoped to a session (see the module-level docs). A
future multi-session Connection needs to (a) filter delivered notifications by
SessionNotification::session_id and (b) generalise the per-command spawning so one
session’s in-flight request never blocks another session’s commands.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn spawn<R, W>(
reader: R,
writer: W,
) -> (Arc<Connection>, UnboundedReceiver<SessionNotification>, UnboundedReceiver<PermissionRequest>)
pub fn spawn<R, W>( reader: R, writer: W, ) -> (Arc<Connection>, UnboundedReceiver<SessionNotification>, UnboundedReceiver<PermissionRequest>)
Spawn a driver task that adapts reader/writer into an ACP transport and drives
the agent-client-protocol client connection over it.
Returns a Connection handle plus two receivers: one that yields every
session/update notification, and one (AU‑4) that yields every
agent→client session/request_permission request the supervisor must
answer.
Sourcepub async fn initialize(&self) -> Result<()>
pub async fn initialize(&self) -> Result<()>
Send the ACP initialize handshake.
Sourcepub async fn new_session(&self, cwd: &str) -> Result<SessionId>
pub async fn new_session(&self, cwd: &str) -> Result<SessionId>
Create a new session rooted at cwd.
Sourcepub async fn prompt(&self, session: &SessionId, text: &str) -> Result<()>
pub async fn prompt(&self, session: &SessionId, text: &str) -> Result<()>
Send a text prompt to session.
Sourcepub async fn cancel(&self, session: &SessionId) -> Result<()>
pub async fn cancel(&self, session: &SessionId) -> Result<()>
AU‑3: interrupt the active turn on session without ending it.
Forwards an ACP session/cancel notification; the agent stops its
current turn and reports a Cancelled stop reason on the update
stream. The session stays open and usable for the next prompt.
Ok(()) means the notification reached the transport, not that the
agent has finished cancelling.
Auto Trait Implementations§
impl Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
impl UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more