Skip to content

Commit 04597c9

Browse files
authored
Fix the rpc_test and example use following the new schema api (#88)
* Fix the rpc_test and example use following the new schema api * fix format stuff * fix use as_value_id() API * Fix format stuff again * fix advertise auth.logout capability in TestAgent * fix format
1 parent 46e4720 commit 04597c9

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use std::cell::Cell;
1616

17-
use agent_client_protocol::{self as acp, Client as _, SessionConfigOptionValue};
17+
use agent_client_protocol::{self as acp, Client as _};
1818
use serde_json::json;
1919
use tokio::sync::{mpsc, oneshot};
2020
use tokio_util::compat::{TokioAsyncReadCompatExt as _, TokioAsyncWriteCompatExt as _};
@@ -120,9 +120,11 @@ impl acp::Agent for ExampleAgent {
120120
args: acp::SetSessionConfigOptionRequest,
121121
) -> Result<acp::SetSessionConfigOptionResponse, acp::Error> {
122122
log::info!("Received set session config option request {args:?}");
123-
let SessionConfigOptionValue::ValueId { value } = args.value else {
124-
return Err(acp::Error::invalid_params());
125-
};
123+
let value = args
124+
.value
125+
.as_value_id()
126+
.ok_or(acp::Error::invalid_params())?
127+
.clone();
126128
let option = acp::SessionConfigOption::select(
127129
args.config_id,
128130
"Example Option",

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ impl TestAgent {
156156
#[async_trait::async_trait(?Send)]
157157
impl Agent for TestAgent {
158158
async fn initialize(&self, arguments: InitializeRequest) -> Result<InitializeResponse> {
159+
let mut capabilities = AgentCapabilities::new();
160+
#[cfg(feature = "unstable_logout")]
161+
{
162+
capabilities.auth.logout =
163+
Some(agent_client_protocol_schema::LogoutCapabilities::default());
164+
}
159165
Ok(InitializeResponse::new(arguments.protocol_version)
160-
.agent_capabilities(
161-
AgentCapabilities::new().auth(
162-
agent_client_protocol_schema::AgentAuthCapabilities::new()
163-
.logout(agent_client_protocol_schema::LogoutCapabilities::new()),
164-
),
165-
)
166+
.agent_capabilities(capabilities)
166167
.agent_info(Implementation::new("test-agent", "0.0.0").title("Test Agent")))
167168
}
168169

@@ -271,9 +272,11 @@ impl Agent for TestAgent {
271272
&self,
272273
args: agent_client_protocol_schema::SetSessionConfigOptionRequest,
273274
) -> Result<agent_client_protocol_schema::SetSessionConfigOptionResponse> {
274-
let SessionConfigOptionValue::ValueId { value } = args.value else {
275-
return Err(Error::invalid_params());
276-
};
275+
let value = args
276+
.value
277+
.as_value_id()
278+
.ok_or(agent_client_protocol_schema::Error::invalid_params())?
279+
.clone();
277280
let option = agent_client_protocol_schema::SessionConfigOption::select(
278281
args.config_id,
279282
"Test Option",

0 commit comments

Comments
 (0)