Skip to content

Commit 0f65a51

Browse files
authored
Implement Agent and Client for Rc and Arc (#110)
Signed-off-by: Ben Brandt <benjamin.j.brandt@gmail.com>
1 parent 94015cb commit 0f65a51

2 files changed

Lines changed: 206 additions & 0 deletions

File tree

rust/agent.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module defines the Agent trait and all associated types for implementing
44
//! an AI coding agent that follows the Agent Client Protocol (ACP).
55
6+
use std::rc::Rc;
67
use std::{path::PathBuf, sync::Arc};
78

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

147+
#[async_trait::async_trait(?Send)]
148+
impl<T: Agent> Agent for Rc<T> {
149+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
150+
self.initialize(args).await
151+
}
152+
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
153+
self.authenticate(args).await
154+
}
155+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
156+
self.new_session(args).await
157+
}
158+
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
159+
self.load_session(args).await
160+
}
161+
async fn set_session_mode(
162+
&self,
163+
args: SetSessionModeRequest,
164+
) -> Result<SetSessionModeResponse, Error> {
165+
self.set_session_mode(args).await
166+
}
167+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
168+
self.prompt(args).await
169+
}
170+
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
171+
self.cancel(args).await
172+
}
173+
#[cfg(feature = "unstable")]
174+
async fn set_session_model(
175+
&self,
176+
args: SetSessionModelRequest,
177+
) -> Result<SetSessionModelResponse, Error> {
178+
self.set_session_model(args).await
179+
}
180+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
181+
self.ext_method(args).await
182+
}
183+
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
184+
self.ext_notification(args).await
185+
}
186+
}
187+
188+
#[async_trait::async_trait(?Send)]
189+
impl<T: Agent> Agent for Arc<T> {
190+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
191+
self.initialize(args).await
192+
}
193+
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
194+
self.authenticate(args).await
195+
}
196+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
197+
self.new_session(args).await
198+
}
199+
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
200+
self.load_session(args).await
201+
}
202+
async fn set_session_mode(
203+
&self,
204+
args: SetSessionModeRequest,
205+
) -> Result<SetSessionModeResponse, Error> {
206+
self.set_session_mode(args).await
207+
}
208+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
209+
self.prompt(args).await
210+
}
211+
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
212+
self.cancel(args).await
213+
}
214+
#[cfg(feature = "unstable")]
215+
async fn set_session_model(
216+
&self,
217+
args: SetSessionModelRequest,
218+
) -> Result<SetSessionModelResponse, Error> {
219+
self.set_session_model(args).await
220+
}
221+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
222+
self.ext_method(args).await
223+
}
224+
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
225+
self.ext_notification(args).await
226+
}
227+
}
228+
146229
// Initialize
147230

148231
/// Request parameters for the initialize method.

rust/client.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module defines the Client trait and all associated types for implementing
44
//! a client that interacts with AI coding agents via the Agent Client Protocol (ACP).
55
6+
use std::rc::Rc;
67
use std::{fmt, path::PathBuf, sync::Arc};
78

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

166+
#[async_trait::async_trait(?Send)]
167+
impl<T: Client> Client for Rc<T> {
168+
async fn request_permission(
169+
&self,
170+
args: RequestPermissionRequest,
171+
) -> Result<RequestPermissionResponse, Error> {
172+
self.request_permission(args).await
173+
}
174+
async fn write_text_file(
175+
&self,
176+
args: WriteTextFileRequest,
177+
) -> Result<WriteTextFileResponse, Error> {
178+
self.write_text_file(args).await
179+
}
180+
async fn read_text_file(
181+
&self,
182+
args: ReadTextFileRequest,
183+
) -> Result<ReadTextFileResponse, Error> {
184+
self.read_text_file(args).await
185+
}
186+
async fn session_notification(&self, args: SessionNotification) -> Result<(), Error> {
187+
self.session_notification(args).await
188+
}
189+
async fn create_terminal(
190+
&self,
191+
args: CreateTerminalRequest,
192+
) -> Result<CreateTerminalResponse, Error> {
193+
self.create_terminal(args).await
194+
}
195+
async fn terminal_output(
196+
&self,
197+
args: TerminalOutputRequest,
198+
) -> Result<TerminalOutputResponse, Error> {
199+
self.terminal_output(args).await
200+
}
201+
async fn release_terminal(
202+
&self,
203+
args: ReleaseTerminalRequest,
204+
) -> Result<ReleaseTerminalResponse, Error> {
205+
self.release_terminal(args).await
206+
}
207+
async fn wait_for_terminal_exit(
208+
&self,
209+
args: WaitForTerminalExitRequest,
210+
) -> Result<WaitForTerminalExitResponse, Error> {
211+
self.wait_for_terminal_exit(args).await
212+
}
213+
async fn kill_terminal_command(
214+
&self,
215+
args: KillTerminalCommandRequest,
216+
) -> Result<KillTerminalCommandResponse, Error> {
217+
self.kill_terminal_command(args).await
218+
}
219+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
220+
self.ext_method(args).await
221+
}
222+
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
223+
self.ext_notification(args).await
224+
}
225+
}
226+
227+
#[async_trait::async_trait(?Send)]
228+
impl<T: Client> Client for Arc<T> {
229+
async fn request_permission(
230+
&self,
231+
args: RequestPermissionRequest,
232+
) -> Result<RequestPermissionResponse, Error> {
233+
self.request_permission(args).await
234+
}
235+
async fn write_text_file(
236+
&self,
237+
args: WriteTextFileRequest,
238+
) -> Result<WriteTextFileResponse, Error> {
239+
self.write_text_file(args).await
240+
}
241+
async fn read_text_file(
242+
&self,
243+
args: ReadTextFileRequest,
244+
) -> Result<ReadTextFileResponse, Error> {
245+
self.read_text_file(args).await
246+
}
247+
async fn session_notification(&self, args: SessionNotification) -> Result<(), Error> {
248+
self.session_notification(args).await
249+
}
250+
async fn create_terminal(
251+
&self,
252+
args: CreateTerminalRequest,
253+
) -> Result<CreateTerminalResponse, Error> {
254+
self.create_terminal(args).await
255+
}
256+
async fn terminal_output(
257+
&self,
258+
args: TerminalOutputRequest,
259+
) -> Result<TerminalOutputResponse, Error> {
260+
self.terminal_output(args).await
261+
}
262+
async fn release_terminal(
263+
&self,
264+
args: ReleaseTerminalRequest,
265+
) -> Result<ReleaseTerminalResponse, Error> {
266+
self.release_terminal(args).await
267+
}
268+
async fn wait_for_terminal_exit(
269+
&self,
270+
args: WaitForTerminalExitRequest,
271+
) -> Result<WaitForTerminalExitResponse, Error> {
272+
self.wait_for_terminal_exit(args).await
273+
}
274+
async fn kill_terminal_command(
275+
&self,
276+
args: KillTerminalCommandRequest,
277+
) -> Result<KillTerminalCommandResponse, Error> {
278+
self.kill_terminal_command(args).await
279+
}
280+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
281+
self.ext_method(args).await
282+
}
283+
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
284+
self.ext_notification(args).await
285+
}
286+
}
287+
165288
// Session updates
166289

167290
/// Notification containing a session update from the agent.

0 commit comments

Comments
 (0)