pub struct Client { /* private fields */ }Expand description
A connection to a remote session, reconnecting automatically if it drops.
A clone is a view: it shares the connection and request queue but may
address a different session (Client::with_session).
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(path: &Path) -> Result<Client>
pub async fn connect(path: &Path) -> Result<Client>
Connect to a server listening at path.
The first connect is eager — Err if nothing is listening — but after
that the client reconnects on its own if the connection drops.
Sourcepub fn lazy(path: &Path) -> Client
pub fn lazy(path: &Path) -> Client
Connect lazily: never fails. The supervisor keeps trying path in the
background, so a peer that is not up yet (or restarts) is reached once it
appears — the right mode for an A2A peer (--peer/[peers]), where two
sessions may each be waiting for the other.
Sourcepub fn with_session(&self, session: SessionId) -> Client
pub fn with_session(&self, session: SessionId) -> Client
A per-session view over the same connection: a cheap clone sharing the
Inner and request queue but addressed to session. Its
Client::subscribe hears only session’s events; replies are matched
by reply_to and are independent of the view.
To hear a session’s stream, session must be the id the server actually
serves (the id it stamps outbound frames with — learn it from
Request::ListSessions). A view narrowed to any other id hears
nothing; over a single-session server, where the served id is not
otherwise known, only the connection-wide view (connect/lazy) is safe.
Sourcepub fn send(&self, request: Request) -> Result<(), Closed>
pub fn send(&self, request: Request) -> Result<(), Closed>
Fire-and-forget: queue a request. Streaming events (and the eventual
reply) arrive on the subscription from Client::subscribe. Fails only
once every clone has dropped and the supervisor has ended.
Sourcepub fn send_from(&self, from: SessionId, request: Request) -> Result<(), Closed>
pub fn send_from(&self, from: SessionId, request: Request) -> Result<(), Closed>
Fire-and-forget, attributing the request to a remote from address
(A2A). The server feeds from into the target’s before_inbound and its
sender tag, exactly as an in-process send_from does.
Sourcepub async fn ask_within(
&self,
request: Request,
dur: Duration,
) -> Result<AgentEvent, AskError>
pub async fn ask_within( &self, request: Request, dur: Duration, ) -> Result<AgentEvent, AskError>
Like Client::ask, but bounded by dur — the remote twin of
crate::Backend::ask_within. Only the caller’s wait is bounded (the
supervisor’s reply path is unchanged). On timeout the pending slot is
removed (see PendingGuard), so a late reply finds no waiter.
Sourcepub fn subscribe(&self) -> Receiver<AgentEvent>
pub fn subscribe(&self) -> Receiver<AgentEvent>
Stream the events this view hears: its own session’s, or — for the
connection-wide view (connect/lazy) — every session’s. Each subscriber
gets its own receiver, which survives a reconnect (only events during the
gap are lost).
The view must address the served id to hear its stream (see
Client::with_session).
Sourcepub fn subscribe_roster(&self) -> Receiver<Vec<SessionInfo>>
pub fn subscribe_roster(&self) -> Receiver<Vec<SessionInfo>>
A live view of the connection-wide roster of served sessions,
seeded with the current value. The server pushes an unsolicited
AgentEvent::Sessions frame when the roster grows (a session
registered at runtime); this receiver yields the new list. It is
connection-wide, not per-session: every view over this connection
shares it, so an unnarrowed and a with_session view see the same ids.
Sourcepub async fn flush(&self, timeout: Duration)
pub async fn flush(&self, timeout: Duration)
Best-effort barrier: resolves once every frame queued before this call
has been written to the socket — the queue is FIFO and the supervisor
writes in order — or after timeout if the peer is unreachable or
reconnecting, so a one-shot exit flushes its fire-and-forget deliveries
without hanging. flush_all flushes every connection at once.