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
4 changes: 4 additions & 0 deletions src/agent-client-protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

### Fixed

- Preserve stable v1 `NewSessionResponse::config_options` on `ActiveSession`,
expose them through `ActiveSession::config_options`, and include them in
reconstructed and proxied session responses.
([#301](https://github.com/agentclientprotocol/rust-sdk/issues/301))
- *(unstable-v2)* Require native v2 client and agent connections to complete
their single initialization handshake before sending or accepting other
protocol traffic. Reject initialization in the wrong direction and reject
Expand Down
14 changes: 12 additions & 2 deletions src/agent-client-protocol/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
role::{HasPeer, acp::ProxySessionMessages},
schema::v1::{
ContentBlock, ContentChunk, NewSessionRequest, NewSessionResponse, PromptRequest,
PromptResponse, SessionId, SessionModeState, SessionNotification, SessionUpdate,
StopReason,
PromptResponse, SessionConfigOption, SessionId, SessionModeState, SessionNotification,
SessionUpdate, StopReason,
},
util::{MatchDispatch, MatchDispatchFrom, run_until},
};
Expand Down Expand Up @@ -93,6 +93,7 @@ where
let NewSessionResponse {
session_id,
modes,
config_options,
meta,
..
} = response;
Expand All @@ -104,6 +105,7 @@ where
Ok(ActiveSession {
session_id,
modes,
config_options,
meta,
update_rx,
update_tx,
Expand Down Expand Up @@ -526,6 +528,7 @@ where
update_rx: mpsc::UnboundedReceiver<SessionMessage>,
update_tx: mpsc::UnboundedSender<SessionMessage>,
modes: Option<SessionModeState>,
config_options: Option<Vec<SessionConfigOption>>,
meta: Option<serde_json::Map<String, serde_json::Value>>,
connection: ConnectionTo<Link>,

Expand Down Expand Up @@ -573,6 +576,11 @@ where
self.modes.as_ref()
}

/// Access the initial session configuration options returned by the agent.
pub fn config_options(&self) -> Option<&[SessionConfigOption]> {
self.config_options.as_deref()
}

/// Access meta data from session response.
pub fn meta(&self) -> Option<&serde_json::Map<String, serde_json::Value>> {
self.meta.as_ref()
Expand All @@ -585,6 +593,7 @@ where
pub fn response(&self) -> NewSessionResponse {
NewSessionResponse::new(self.session_id.clone())
.modes(self.modes.clone())
.config_options(self.config_options.clone())
.meta(self.meta.clone())
}

Expand Down Expand Up @@ -697,6 +706,7 @@ where
mcp_handler_registrations,
// These fields are not needed for proxying
modes: _,
config_options: _,
meta: _,
_runner,
} = self;
Expand Down
51 changes: 50 additions & 1 deletion src/agent-client-protocol/tests/session_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use agent_client_protocol::{
SessionMessage, TransportBatch, TransportFrame,
schema::v1::{
ContentBlock, ContentChunk, NewSessionRequest, NewSessionResponse, PromptRequest,
PromptResponse, SessionId, SessionNotification, SessionUpdate, StopReason, TextContent,
PromptResponse, SessionConfigOption, SessionConfigOptionCategory,
SessionConfigSelectOption, SessionId, SessionNotification, SessionUpdate, StopReason,
TextContent,
},
};
use futures::{StreamExt as _, channel::oneshot};
Expand Down Expand Up @@ -169,6 +171,53 @@ mod callback_future_lifetimes {
}
}

#[tokio::test(flavor = "current_thread")]
async fn active_session_preserves_config_options_from_new_session_response() {
let config_options = vec![
SessionConfigOption::select(
"model",
"Model",
"sonnet",
vec![
SessionConfigSelectOption::new("sonnet", "Sonnet"),
SessionConfigSelectOption::new("opus", "Opus"),
],
)
.category(SessionConfigOptionCategory::Model),
];
let expected_response =
NewSessionResponse::new("config-options-session").config_options(config_options.clone());
let agent_response = expected_response.clone();

let agent = Agent.builder().on_receive_request(
async move |_request: NewSessionRequest,
responder: Responder<NewSessionResponse>,
_connection: ConnectionTo<Client>| {
responder.respond(agent_response.clone())
},
agent_client_protocol::on_receive_request!(),
);

let client = Client
.builder()
.connect_with(agent, async move |connection| {
let session = connection
.build_session_cwd()?
.block_task()
.start_session()
.await?;

assert_eq!(session.config_options(), Some(config_options.as_slice()));
assert_eq!(session.response(), expected_response);
Ok(())
});

tokio::time::timeout(TIMEOUT, client)
.await
.expect("session setup timed out")
.expect("session connection failed");
}

#[tokio::test(flavor = "current_thread")]
async fn on_session_start_callback_can_consume_later_session_messages() {
let session_id = SessionId::new("ordered-session");
Expand Down