Skip to content

Commit c009c23

Browse files
authored
feat(unstable): Add initial support for listing sessions (#31)
* Update schema version * feat(unstable): Add initial support for listing sessions
1 parent ecbecff commit c009c23

File tree

7 files changed

+90
-15
lines changed

7 files changed

+90
-15
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tokio = { version = "1.48", features = ["full"] }
2727
tokio-util = { version = "0.7", features = ["compat"] }
2828

2929
# Protocol
30-
agent-client-protocol-schema = { version = "0.10.0" }
30+
agent-client-protocol-schema = { version = "=0.10.4" }
3131

3232
# Serialization
3333
serde = { version = "1.0", features = ["derive", "rc"] }

examples/agent.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl acp::Agent for ExampleAgent {
7373
Ok(acp::NewSessionResponse {
7474
session_id: acp::SessionId(session_id.to_string().into()),
7575
modes: None,
76-
#[cfg(feature = "unstable")]
76+
#[cfg(feature = "unstable_session_model")]
7777
models: None,
7878
meta: None,
7979
})
@@ -86,7 +86,7 @@ impl acp::Agent for ExampleAgent {
8686
log::info!("Received load session request {arguments:?}");
8787
Ok(acp::LoadSessionResponse {
8888
modes: None,
89-
#[cfg(feature = "unstable")]
89+
#[cfg(feature = "unstable_session_model")]
9090
models: None,
9191
meta: None,
9292
})
@@ -133,7 +133,7 @@ impl acp::Agent for ExampleAgent {
133133
Ok(acp::SetSessionModeResponse::default())
134134
}
135135

136-
#[cfg(feature = "unstable")]
136+
#[cfg(feature = "unstable_session_model")]
137137
async fn set_session_model(
138138
&self,
139139
args: acp::SetSessionModelRequest,
@@ -142,6 +142,15 @@ impl acp::Agent for ExampleAgent {
142142
Ok(acp::SetSessionModelResponse::default())
143143
}
144144

145+
#[cfg(feature = "unstable_session_list")]
146+
async fn list_sessions(
147+
&self,
148+
args: acp::ListSessionsRequest,
149+
) -> Result<acp::ListSessionsResponse, acp::Error> {
150+
log::info!("Received list sessions request {args:?}");
151+
Ok(acp::ListSessionsResponse::new(vec![]))
152+
}
153+
145154
async fn ext_method(&self, args: acp::ExtRequest) -> Result<acp::ExtResponse, acp::Error> {
146155
log::info!(
147156
"Received extension method call: method={}, params={:?}",

src/agent-client-protocol/Cargo.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ keywords = ["agent", "client", "protocol", "ai", "editor"]
1313
categories = ["development-tools", "api-bindings"]
1414

1515
[features]
16-
unstable = ["agent-client-protocol-schema/unstable"]
16+
unstable = [
17+
"unstable_cancel_request",
18+
"unstable_session_config_options",
19+
"unstable_session_fork",
20+
"unstable_session_info_update",
21+
"unstable_session_list",
22+
"unstable_session_model",
23+
"unstable_session_resume",
24+
]
25+
unstable_cancel_request = ["agent-client-protocol-schema/unstable_cancel_request"]
26+
unstable_session_config_options = ["agent-client-protocol-schema/unstable_session_config_options"]
27+
unstable_session_fork = ["agent-client-protocol-schema/unstable_session_fork"]
28+
unstable_session_info_update = ["agent-client-protocol-schema/unstable_session_info_update"]
29+
unstable_session_list = ["agent-client-protocol-schema/unstable_session_list"]
30+
unstable_session_model = ["agent-client-protocol-schema/unstable_session_model"]
31+
unstable_session_resume = ["agent-client-protocol-schema/unstable_session_resume"]
1732

1833
[dependencies]
1934
agent-client-protocol-schema.workspace = true

src/agent-client-protocol/src/agent.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use agent_client_protocol_schema::{
66
LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse,
77
Result, SetSessionModeRequest, SetSessionModeResponse,
88
};
9-
#[cfg(feature = "unstable")]
9+
#[cfg(feature = "unstable_session_list")]
10+
use agent_client_protocol_schema::{ListSessionsRequest, ListSessionsResponse};
11+
#[cfg(feature = "unstable_session_model")]
1012
use agent_client_protocol_schema::{SetSessionModelRequest, SetSessionModelResponse};
1113
use serde_json::value::RawValue;
1214

@@ -118,14 +120,26 @@ pub trait Agent {
118120
/// This capability is not part of the spec yet, and may be removed or changed at any point.
119121
///
120122
/// Select a model for a given session.
121-
#[cfg(feature = "unstable")]
123+
#[cfg(feature = "unstable_session_model")]
122124
async fn set_session_model(
123125
&self,
124126
_args: SetSessionModelRequest,
125127
) -> Result<SetSessionModelResponse> {
126128
Err(Error::method_not_found())
127129
}
128130

131+
/// **UNSTABLE**
132+
///
133+
/// This capability is not part of the spec yet, and may be removed or changed at any point.
134+
///
135+
/// Lists existing sessions known to the agent.
136+
///
137+
/// Only available if the Agent supports the `sessionCapabilities.list` capability.
138+
#[cfg(feature = "unstable_session_list")]
139+
async fn list_sessions(&self, _args: ListSessionsRequest) -> Result<ListSessionsResponse> {
140+
Err(Error::method_not_found())
141+
}
142+
129143
/// Handles extension method requests from the client.
130144
///
131145
/// Extension methods provide a way to add custom functionality while maintaining
@@ -173,13 +187,17 @@ impl<T: Agent> Agent for Rc<T> {
173187
async fn cancel(&self, args: CancelNotification) -> Result<()> {
174188
self.as_ref().cancel(args).await
175189
}
176-
#[cfg(feature = "unstable")]
190+
#[cfg(feature = "unstable_session_model")]
177191
async fn set_session_model(
178192
&self,
179193
args: SetSessionModelRequest,
180194
) -> Result<SetSessionModelResponse> {
181195
self.as_ref().set_session_model(args).await
182196
}
197+
#[cfg(feature = "unstable_session_list")]
198+
async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
199+
self.as_ref().list_sessions(args).await
200+
}
183201
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
184202
self.as_ref().ext_method(args).await
185203
}
@@ -214,13 +232,17 @@ impl<T: Agent> Agent for Arc<T> {
214232
async fn cancel(&self, args: CancelNotification) -> Result<()> {
215233
self.as_ref().cancel(args).await
216234
}
217-
#[cfg(feature = "unstable")]
235+
#[cfg(feature = "unstable_session_model")]
218236
async fn set_session_model(
219237
&self,
220238
args: SetSessionModelRequest,
221239
) -> Result<SetSessionModelResponse> {
222240
self.as_ref().set_session_model(args).await
223241
}
242+
#[cfg(feature = "unstable_session_list")]
243+
async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
244+
self.as_ref().list_sessions(args).await
245+
}
224246
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
225247
self.as_ref().ext_method(args).await
226248
}

src/agent-client-protocol/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl Agent for ClientSideConnection {
142142
)
143143
}
144144

145-
#[cfg(feature = "unstable")]
145+
#[cfg(feature = "unstable_session_model")]
146146
async fn set_session_model(
147147
&self,
148148
args: SetSessionModelRequest,
@@ -155,6 +155,16 @@ impl Agent for ClientSideConnection {
155155
.await
156156
}
157157

158+
#[cfg(feature = "unstable_session_list")]
159+
async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
160+
self.conn
161+
.request(
162+
AGENT_METHOD_NAMES.session_list,
163+
Some(ClientRequest::ListSessionsRequest(args)),
164+
)
165+
.await
166+
}
167+
158168
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
159169
self.conn
160170
.request(
@@ -514,10 +524,14 @@ impl Side for AgentSide {
514524
m if m == AGENT_METHOD_NAMES.session_set_mode => serde_json::from_str(params.get())
515525
.map(ClientRequest::SetSessionModeRequest)
516526
.map_err(Into::into),
517-
#[cfg(feature = "unstable")]
527+
#[cfg(feature = "unstable_session_model")]
518528
m if m == AGENT_METHOD_NAMES.session_set_model => serde_json::from_str(params.get())
519529
.map(ClientRequest::SetSessionModelRequest)
520530
.map_err(Into::into),
531+
#[cfg(feature = "unstable_session_list")]
532+
m if m == AGENT_METHOD_NAMES.session_list => serde_json::from_str(params.get())
533+
.map(ClientRequest::ListSessionsRequest)
534+
.map_err(Into::into),
521535
m if m == AGENT_METHOD_NAMES.session_prompt => serde_json::from_str(params.get())
522536
.map(ClientRequest::PromptRequest)
523537
.map_err(Into::into),
@@ -582,11 +596,16 @@ impl<T: Agent> MessageHandler<AgentSide> for T {
582596
let response = self.set_session_mode(args).await?;
583597
Ok(AgentResponse::SetSessionModeResponse(response))
584598
}
585-
#[cfg(feature = "unstable")]
599+
#[cfg(feature = "unstable_session_model")]
586600
ClientRequest::SetSessionModelRequest(args) => {
587601
let response = self.set_session_model(args).await?;
588602
Ok(AgentResponse::SetSessionModelResponse(response))
589603
}
604+
#[cfg(feature = "unstable_session_list")]
605+
ClientRequest::ListSessionsRequest(args) => {
606+
let response = self.list_sessions(args).await?;
607+
Ok(AgentResponse::ListSessionsResponse(response))
608+
}
590609
ClientRequest::ExtMethodRequest(args) => {
591610
let response = self.ext_method(args).await?;
592611
Ok(AgentResponse::ExtMethodResponse(response))

src/agent-client-protocol/src/rpc_tests.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl Agent for TestAgent {
196196
Ok(())
197197
}
198198

199-
#[cfg(feature = "unstable")]
199+
#[cfg(feature = "unstable_session_model")]
200200
async fn set_session_model(
201201
&self,
202202
args: agent_client_protocol_schema::SetSessionModelRequest,
@@ -205,6 +205,16 @@ impl Agent for TestAgent {
205205
Ok(agent_client_protocol_schema::SetSessionModelResponse::default())
206206
}
207207

208+
#[cfg(feature = "unstable_session_list")]
209+
async fn list_sessions(
210+
&self,
211+
_args: agent_client_protocol_schema::ListSessionsRequest,
212+
) -> Result<agent_client_protocol_schema::ListSessionsResponse> {
213+
Ok(agent_client_protocol_schema::ListSessionsResponse::new(
214+
vec![],
215+
))
216+
}
217+
208218
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
209219
dbg!();
210220
match dbg!(args.method.as_ref()) {

0 commit comments

Comments
 (0)