AgentSideConnection

Struct AgentSideConnection 

Source
pub struct AgentSideConnection { /* private fields */ }
Expand description

An agent-side connection to a client.

This struct provides the agent’s view of an ACP connection, allowing agents to communicate with clients. It implements the Client trait to provide methods for requesting permissions, accessing the file system, and sending session updates.

See protocol docs: Agent

Implementations§

Source§

impl AgentSideConnection

Source

pub fn new( agent: impl MessageHandler<AgentSide> + 'static, outgoing_bytes: impl Unpin + AsyncWrite, incoming_bytes: impl Unpin + AsyncRead, spawn: impl Fn(LocalBoxFuture<'static, ()>) + 'static, ) -> (Self, impl Future<Output = Result<()>>)

Creates a new agent-side connection to a client.

This establishes the communication channel from the agent’s perspective following the ACP specification.

§Arguments
  • agent - A handler that implements the Agent trait to process incoming client requests
  • outgoing_bytes - The stream for sending data to the client (typically stdout)
  • incoming_bytes - The stream for receiving data from the client (typically stdin)
  • spawn - A function to spawn async tasks (e.g., tokio::spawn)
§Returns

Returns a tuple containing:

  • The connection instance for making requests to the client
  • An I/O future that must be spawned to handle the underlying communication

See protocol docs: Communication Model

Source

pub fn subscribe(&self) -> StreamReceiver

Subscribe to receive stream updates from the client.

This allows the agent to receive real-time notifications about client activities and cancellation requests.

§Returns

A StreamReceiver that can be used to receive stream messages.

Trait Implementations§

Source§

impl Client for AgentSideConnection

Source§

async fn request_permission( &self, arguments: RequestPermissionRequest, ) -> Result<RequestPermissionResponse, Error>

Requests permission from the user for a tool call operation. Read more
Source§

async fn write_text_file( &self, arguments: WriteTextFileRequest, ) -> Result<WriteTextFileResponse, Error>

Writes content to a text file in the client’s file system. Read more
Source§

async fn read_text_file( &self, arguments: ReadTextFileRequest, ) -> Result<ReadTextFileResponse, Error>

Reads content from a text file in the client’s file system. Read more
Source§

async fn create_terminal( &self, arguments: CreateTerminalRequest, ) -> Result<CreateTerminalResponse, Error>

Executes a command in a new terminal Read more
Source§

async fn terminal_output( &self, arguments: TerminalOutputRequest, ) -> Result<TerminalOutputResponse, Error>

Gets the terminal output and exit status Read more
Source§

async fn release_terminal( &self, arguments: ReleaseTerminalRequest, ) -> Result<ReleaseTerminalResponse, Error>

Releases a terminal Read more
Source§

async fn wait_for_terminal_exit( &self, arguments: WaitForTerminalExitRequest, ) -> Result<WaitForTerminalExitResponse, Error>

Waits for the terminal command to exit and return its exit status Read more
Source§

async fn kill_terminal_command( &self, arguments: KillTerminalCommandRequest, ) -> Result<KillTerminalCommandResponse, Error>

Kills the terminal command without releasing the terminal Read more
Source§

async fn session_notification( &self, notification: SessionNotification, ) -> Result<(), Error>

Handles session update notifications from the agent. Read more
Source§

async fn ext_method( &self, method: Arc<str>, params: Arc<RawValue>, ) -> Result<Arc<RawValue>, Error>

Handles extension method requests from the agent. Read more
Source§

async fn ext_notification( &self, method: Arc<str>, params: Arc<RawValue>, ) -> Result<(), Error>

Handles extension notifications from the agent. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.