Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions rust/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This module defines the Agent trait and all associated types for implementing
//! an AI coding agent that follows the Agent Client Protocol (ACP).

use std::rc::Rc;
use std::{path::PathBuf, sync::Arc};

use anyhow::Result;
Expand Down Expand Up @@ -143,6 +144,88 @@ pub trait Agent {
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error>;
}

#[async_trait::async_trait(?Send)]
impl<T: Agent> Agent for Rc<T> {
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
self.initialize(args).await
}
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
self.authenticate(args).await
}
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
self.new_session(args).await
}
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
self.load_session(args).await
}
async fn set_session_mode(
&self,
args: SetSessionModeRequest,
) -> Result<SetSessionModeResponse, Error> {
self.set_session_mode(args).await
}
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
self.prompt(args).await
}
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
self.cancel(args).await
}
#[cfg(feature = "unstable")]
async fn set_session_model(
&self,
args: SetSessionModelRequest,
) -> Result<SetSessionModelResponse, Error> {
self.set_session_model(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
self.ext_method(args).await
}
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
self.ext_notification(args).await
}
}

#[async_trait::async_trait(?Send)]
impl<T: Agent> Agent for Arc<T> {
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
self.initialize(args).await
}
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
self.authenticate(args).await
}
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
self.new_session(args).await
}
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
self.load_session(args).await
}
async fn set_session_mode(
&self,
args: SetSessionModeRequest,
) -> Result<SetSessionModeResponse, Error> {
self.set_session_mode(args).await
}
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
self.prompt(args).await
}
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
self.cancel(args).await
}
#[cfg(feature = "unstable")]
async fn set_session_model(
&self,
args: SetSessionModelRequest,
) -> Result<SetSessionModelResponse, Error> {
self.set_session_model(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
self.ext_method(args).await
}
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
self.ext_notification(args).await
}
}

// Initialize

/// Request parameters for the initialize method.
Expand Down
123 changes: 123 additions & 0 deletions rust/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This module defines the Client trait and all associated types for implementing
//! a client that interacts with AI coding agents via the Agent Client Protocol (ACP).

use std::rc::Rc;
use std::{fmt, path::PathBuf, sync::Arc};

use anyhow::Result;
Expand Down Expand Up @@ -162,6 +163,128 @@ pub trait Client {
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error>;
}

#[async_trait::async_trait(?Send)]
impl<T: Client> Client for Rc<T> {
async fn request_permission(
&self,
args: RequestPermissionRequest,
) -> Result<RequestPermissionResponse, Error> {
self.request_permission(args).await
}
async fn write_text_file(
&self,
args: WriteTextFileRequest,
) -> Result<WriteTextFileResponse, Error> {
self.write_text_file(args).await
}
async fn read_text_file(
&self,
args: ReadTextFileRequest,
) -> Result<ReadTextFileResponse, Error> {
self.read_text_file(args).await
}
async fn session_notification(&self, args: SessionNotification) -> Result<(), Error> {
self.session_notification(args).await
}
async fn create_terminal(
&self,
args: CreateTerminalRequest,
) -> Result<CreateTerminalResponse, Error> {
self.create_terminal(args).await
}
async fn terminal_output(
&self,
args: TerminalOutputRequest,
) -> Result<TerminalOutputResponse, Error> {
self.terminal_output(args).await
}
async fn release_terminal(
&self,
args: ReleaseTerminalRequest,
) -> Result<ReleaseTerminalResponse, Error> {
self.release_terminal(args).await
}
async fn wait_for_terminal_exit(
&self,
args: WaitForTerminalExitRequest,
) -> Result<WaitForTerminalExitResponse, Error> {
self.wait_for_terminal_exit(args).await
}
async fn kill_terminal_command(
&self,
args: KillTerminalCommandRequest,
) -> Result<KillTerminalCommandResponse, Error> {
self.kill_terminal_command(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
self.ext_method(args).await
}
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
self.ext_notification(args).await
}
}

#[async_trait::async_trait(?Send)]
impl<T: Client> Client for Arc<T> {
async fn request_permission(
&self,
args: RequestPermissionRequest,
) -> Result<RequestPermissionResponse, Error> {
self.request_permission(args).await
}
async fn write_text_file(
&self,
args: WriteTextFileRequest,
) -> Result<WriteTextFileResponse, Error> {
self.write_text_file(args).await
}
async fn read_text_file(
&self,
args: ReadTextFileRequest,
) -> Result<ReadTextFileResponse, Error> {
self.read_text_file(args).await
}
async fn session_notification(&self, args: SessionNotification) -> Result<(), Error> {
self.session_notification(args).await
}
async fn create_terminal(
&self,
args: CreateTerminalRequest,
) -> Result<CreateTerminalResponse, Error> {
self.create_terminal(args).await
}
async fn terminal_output(
&self,
args: TerminalOutputRequest,
) -> Result<TerminalOutputResponse, Error> {
self.terminal_output(args).await
}
async fn release_terminal(
&self,
args: ReleaseTerminalRequest,
) -> Result<ReleaseTerminalResponse, Error> {
self.release_terminal(args).await
}
async fn wait_for_terminal_exit(
&self,
args: WaitForTerminalExitRequest,
) -> Result<WaitForTerminalExitResponse, Error> {
self.wait_for_terminal_exit(args).await
}
async fn kill_terminal_command(
&self,
args: KillTerminalCommandRequest,
) -> Result<KillTerminalCommandResponse, Error> {
self.kill_terminal_command(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
self.ext_method(args).await
}
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
self.ext_notification(args).await
}
}

// Session updates

/// Notification containing a session update from the agent.
Expand Down