agent_client_protocol/
agent.rs1use std::{rc::Rc, sync::Arc};
2
3use agent_client_protocol_schema::{
4 AuthenticateRequest, AuthenticateResponse, CancelNotification, Error, ExtNotification,
5 ExtRequest, ExtResponse, InitializeRequest, InitializeResponse, LoadSessionRequest,
6 LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse,
7 Result, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, SetSessionModeRequest,
8 SetSessionModeResponse,
9};
10#[cfg(feature = "unstable_session_fork")]
11use agent_client_protocol_schema::{ForkSessionRequest, ForkSessionResponse};
12#[cfg(feature = "unstable_session_list")]
13use agent_client_protocol_schema::{ListSessionsRequest, ListSessionsResponse};
14#[cfg(feature = "unstable_session_resume")]
15use agent_client_protocol_schema::{ResumeSessionRequest, ResumeSessionResponse};
16#[cfg(feature = "unstable_session_model")]
17use agent_client_protocol_schema::{SetSessionModelRequest, SetSessionModelResponse};
18use serde_json::value::RawValue;
19
20#[async_trait::async_trait(?Send)]
25pub trait Agent {
26 async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse>;
37
38 async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse>;
48
49 async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse>;
62
63 async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse>;
75
76 async fn cancel(&self, args: CancelNotification) -> Result<()>;
88
89 async fn load_session(&self, _args: LoadSessionRequest) -> Result<LoadSessionResponse> {
100 Err(Error::method_not_found())
101 }
102
103 async fn set_session_mode(
117 &self,
118 _args: SetSessionModeRequest,
119 ) -> Result<SetSessionModeResponse> {
120 Err(Error::method_not_found())
121 }
122
123 #[cfg(feature = "unstable_session_model")]
129 async fn set_session_model(
130 &self,
131 _args: SetSessionModelRequest,
132 ) -> Result<SetSessionModelResponse> {
133 Err(Error::method_not_found())
134 }
135
136 async fn set_session_config_option(
144 &self,
145 _args: SetSessionConfigOptionRequest,
146 ) -> Result<SetSessionConfigOptionResponse> {
147 Err(Error::method_not_found())
148 }
149
150 #[cfg(feature = "unstable_session_list")]
158 async fn list_sessions(&self, _args: ListSessionsRequest) -> Result<ListSessionsResponse> {
159 Err(Error::method_not_found())
160 }
161
162 #[cfg(feature = "unstable_session_fork")]
170 async fn fork_session(&self, _args: ForkSessionRequest) -> Result<ForkSessionResponse> {
171 Err(Error::method_not_found())
172 }
173
174 #[cfg(feature = "unstable_session_resume")]
185 async fn resume_session(&self, _args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
186 Err(Error::method_not_found())
187 }
188
189 async fn ext_method(&self, _args: ExtRequest) -> Result<ExtResponse> {
196 Ok(ExtResponse::new(RawValue::NULL.to_owned().into()))
197 }
198
199 async fn ext_notification(&self, _args: ExtNotification) -> Result<()> {
206 Ok(())
207 }
208}
209
210#[async_trait::async_trait(?Send)]
211impl<T: Agent> Agent for Rc<T> {
212 async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse> {
213 self.as_ref().initialize(args).await
214 }
215 async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse> {
216 self.as_ref().authenticate(args).await
217 }
218 async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse> {
219 self.as_ref().new_session(args).await
220 }
221 async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse> {
222 self.as_ref().load_session(args).await
223 }
224 async fn set_session_mode(
225 &self,
226 args: SetSessionModeRequest,
227 ) -> Result<SetSessionModeResponse> {
228 self.as_ref().set_session_mode(args).await
229 }
230 async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse> {
231 self.as_ref().prompt(args).await
232 }
233 async fn cancel(&self, args: CancelNotification) -> Result<()> {
234 self.as_ref().cancel(args).await
235 }
236 #[cfg(feature = "unstable_session_model")]
237 async fn set_session_model(
238 &self,
239 args: SetSessionModelRequest,
240 ) -> Result<SetSessionModelResponse> {
241 self.as_ref().set_session_model(args).await
242 }
243 async fn set_session_config_option(
244 &self,
245 args: SetSessionConfigOptionRequest,
246 ) -> Result<SetSessionConfigOptionResponse> {
247 self.as_ref().set_session_config_option(args).await
248 }
249 #[cfg(feature = "unstable_session_list")]
250 async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
251 self.as_ref().list_sessions(args).await
252 }
253 #[cfg(feature = "unstable_session_fork")]
254 async fn fork_session(&self, args: ForkSessionRequest) -> Result<ForkSessionResponse> {
255 self.as_ref().fork_session(args).await
256 }
257 #[cfg(feature = "unstable_session_resume")]
258 async fn resume_session(&self, args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
259 self.as_ref().resume_session(args).await
260 }
261 async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
262 self.as_ref().ext_method(args).await
263 }
264 async fn ext_notification(&self, args: ExtNotification) -> Result<()> {
265 self.as_ref().ext_notification(args).await
266 }
267}
268
269#[async_trait::async_trait(?Send)]
270impl<T: Agent> Agent for Arc<T> {
271 async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse> {
272 self.as_ref().initialize(args).await
273 }
274 async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse> {
275 self.as_ref().authenticate(args).await
276 }
277 async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse> {
278 self.as_ref().new_session(args).await
279 }
280 async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse> {
281 self.as_ref().load_session(args).await
282 }
283 async fn set_session_mode(
284 &self,
285 args: SetSessionModeRequest,
286 ) -> Result<SetSessionModeResponse> {
287 self.as_ref().set_session_mode(args).await
288 }
289 async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse> {
290 self.as_ref().prompt(args).await
291 }
292 async fn cancel(&self, args: CancelNotification) -> Result<()> {
293 self.as_ref().cancel(args).await
294 }
295 #[cfg(feature = "unstable_session_model")]
296 async fn set_session_model(
297 &self,
298 args: SetSessionModelRequest,
299 ) -> Result<SetSessionModelResponse> {
300 self.as_ref().set_session_model(args).await
301 }
302 async fn set_session_config_option(
303 &self,
304 args: SetSessionConfigOptionRequest,
305 ) -> Result<SetSessionConfigOptionResponse> {
306 self.as_ref().set_session_config_option(args).await
307 }
308 #[cfg(feature = "unstable_session_list")]
309 async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
310 self.as_ref().list_sessions(args).await
311 }
312 #[cfg(feature = "unstable_session_fork")]
313 async fn fork_session(&self, args: ForkSessionRequest) -> Result<ForkSessionResponse> {
314 self.as_ref().fork_session(args).await
315 }
316 #[cfg(feature = "unstable_session_resume")]
317 async fn resume_session(&self, args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
318 self.as_ref().resume_session(args).await
319 }
320 async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
321 self.as_ref().ext_method(args).await
322 }
323 async fn ext_notification(&self, args: ExtNotification) -> Result<()> {
324 self.as_ref().ext_notification(args).await
325 }
326}