Skip to content

Commit 0739069

Browse files
committed
fix: Make examples compile again
1 parent 7f9669c commit 0739069

2 files changed

Lines changed: 51 additions & 84 deletions

File tree

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

Lines changed: 26 additions & 49 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 _};
17+
use agent_client_protocol::{self as acp, Client as _, SessionConfigOptionValue};
1818
use serde_json::json;
1919
use tokio::sync::{mpsc, oneshot};
2020
use tokio_util::compat::{TokioAsyncReadCompatExt as _, TokioAsyncWriteCompatExt as _};
@@ -42,17 +42,8 @@ impl acp::Agent for ExampleAgent {
4242
arguments: acp::InitializeRequest,
4343
) -> Result<acp::InitializeResponse, acp::Error> {
4444
log::info!("Received initialize request {arguments:?}");
45-
Ok(acp::InitializeResponse {
46-
protocol_version: acp::V1,
47-
agent_capabilities: acp::AgentCapabilities::default(),
48-
auth_methods: Vec::new(),
49-
agent_info: Some(acp::Implementation {
50-
name: "example-agent".to_string(),
51-
title: Some("Example Agent".to_string()),
52-
version: "0.1.0".to_string(),
53-
}),
54-
meta: None,
55-
})
45+
Ok(acp::InitializeResponse::new(acp::ProtocolVersion::V1)
46+
.agent_info(acp::Implementation::new("example-agent", "0.1.0").title("Example Agent")))
5647
}
5748

5849
async fn authenticate(
@@ -70,26 +61,15 @@ impl acp::Agent for ExampleAgent {
7061
log::info!("Received new session request {arguments:?}");
7162
let session_id = self.next_session_id.get();
7263
self.next_session_id.set(session_id + 1);
73-
Ok(acp::NewSessionResponse {
74-
session_id: acp::SessionId(session_id.to_string().into()),
75-
modes: None,
76-
#[cfg(feature = "unstable_session_model")]
77-
models: None,
78-
meta: None,
79-
})
64+
Ok(acp::NewSessionResponse::new(session_id.to_string()))
8065
}
8166

8267
async fn load_session(
8368
&self,
8469
arguments: acp::LoadSessionRequest,
8570
) -> Result<acp::LoadSessionResponse, acp::Error> {
8671
log::info!("Received load session request {arguments:?}");
87-
Ok(acp::LoadSessionResponse {
88-
modes: None,
89-
#[cfg(feature = "unstable_session_model")]
90-
models: None,
91-
meta: None,
92-
})
72+
Ok(acp::LoadSessionResponse::new())
9373
}
9474

9575
async fn prompt(
@@ -101,23 +81,16 @@ impl acp::Agent for ExampleAgent {
10181
let (tx, rx) = oneshot::channel();
10282
self.session_update_tx
10383
.send((
104-
acp::SessionNotification {
105-
session_id: arguments.session_id.clone(),
106-
update: acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk {
107-
content,
108-
meta: None,
109-
}),
110-
meta: None,
111-
},
84+
acp::SessionNotification::new(
85+
arguments.session_id.clone(),
86+
acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk::new(content)),
87+
),
11288
tx,
11389
))
11490
.map_err(|_| acp::Error::internal_error())?;
11591
rx.await.map_err(|_| acp::Error::internal_error())?;
11692
}
117-
Ok(acp::PromptResponse {
118-
stop_reason: acp::StopReason::EndTurn,
119-
meta: None,
120-
})
93+
Ok(acp::PromptResponse::new(acp::StopReason::EndTurn))
12194
}
12295

12396
async fn cancel(&self, args: acp::CancelNotification) -> Result<(), acp::Error> {
@@ -147,17 +120,19 @@ impl acp::Agent for ExampleAgent {
147120
args: acp::SetSessionConfigOptionRequest,
148121
) -> Result<acp::SetSessionConfigOptionResponse, acp::Error> {
149122
log::info!("Received set session config option request {args:?}");
150-
Ok(acp::SetSessionConfigOptionResponse::new(vec![
151-
acp::SessionConfigOption::select(
152-
args.config_id,
153-
"Example Option",
154-
args.value,
155-
vec![
156-
acp::SessionConfigSelectOption::new("option1", "Option 1"),
157-
acp::SessionConfigSelectOption::new("option2", "Option 2"),
158-
]),
159-
),
160-
]))
123+
let SessionConfigOptionValue::ValueId { value } = args.value else {
124+
return Err(acp::Error::invalid_params());
125+
};
126+
let option = acp::SessionConfigOption::select(
127+
args.config_id,
128+
"Example Option",
129+
value,
130+
vec![
131+
acp::SessionConfigSelectOption::new("option1", "Option 1"),
132+
acp::SessionConfigSelectOption::new("option2", "Option 2"),
133+
],
134+
);
135+
Ok(acp::SetSessionConfigOptionResponse::new(vec![option]))
161136
}
162137

163138
async fn ext_method(&self, args: acp::ExtRequest) -> Result<acp::ExtResponse, acp::Error> {
@@ -166,7 +141,9 @@ impl acp::Agent for ExampleAgent {
166141
args.method,
167142
args.params
168143
);
169-
Ok(serde_json::value::to_raw_value(&json!({"example": "response"}))?.into())
144+
Ok(acp::ExtResponse::new(
145+
serde_json::value::to_raw_value(&json!({"example": "response"}))?.into(),
146+
))
170147
}
171148

172149
async fn ext_notification(&self, args: acp::ExtNotification) -> Result<(), acp::Error> {

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

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,29 @@ impl acp::Client for ExampleClient {
6868
Err(acp::Error::method_not_found())
6969
}
7070

71-
async fn kill_terminal_command(
71+
async fn kill_terminal(
7272
&self,
73-
_args: acp::KillTerminalCommandRequest,
74-
) -> acp::Result<acp::KillTerminalCommandResponse> {
73+
_args: acp::KillTerminalRequest,
74+
) -> acp::Result<acp::KillTerminalResponse> {
7575
Err(acp::Error::method_not_found())
7676
}
7777

7878
async fn session_notification(
7979
&self,
8080
args: acp::SessionNotification,
8181
) -> acp::Result<(), acp::Error> {
82-
match args.update {
83-
acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk { content, .. }) => {
84-
let text = match content {
85-
acp::ContentBlock::Text(text_content) => text_content.text,
86-
acp::ContentBlock::Image(_) => "<image>".into(),
87-
acp::ContentBlock::Audio(_) => "<audio>".into(),
88-
acp::ContentBlock::ResourceLink(resource_link) => resource_link.uri,
89-
acp::ContentBlock::Resource(_) => "<resource>".into(),
90-
};
91-
println!("| Agent: {text}");
92-
}
93-
_ => {} // Handle future variants gracefully
82+
if let acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk { content, .. }) =
83+
args.update
84+
{
85+
let text = match content {
86+
acp::ContentBlock::Text(text_content) => text_content.text,
87+
acp::ContentBlock::Image(_) => "<image>".into(),
88+
acp::ContentBlock::Audio(_) => "<audio>".into(),
89+
acp::ContentBlock::ResourceLink(resource_link) => resource_link.uri,
90+
acp::ContentBlock::Resource(_) => "<resource>".into(),
91+
_ => "Unknown chunk".into(),
92+
};
93+
println!("| Agent: {text}");
9494
}
9595
Ok(())
9696
}
@@ -142,34 +142,24 @@ async fn main() -> anyhow::Result<()> {
142142
tokio::task::spawn_local(handle_io);
143143

144144
// Connect to the agent and set up a session.
145-
conn.initialize(acp::InitializeRequest {
146-
protocol_version: acp::V1,
147-
client_capabilities: acp::ClientCapabilities::default(),
148-
client_info: Some(acp::Implementation {
149-
name: "example-client".to_string(),
150-
title: Some("Example Client".to_string()),
151-
version: "0.1.0".to_string(),
152-
}),
153-
meta: None,
154-
})
145+
conn.initialize(
146+
acp::InitializeRequest::new(acp::ProtocolVersion::V1).client_info(
147+
acp::Implementation::new("example-client", "0.1.0").title("Example Client"),
148+
),
149+
)
155150
.await?;
156151
let response = conn
157-
.new_session(acp::NewSessionRequest {
158-
mcp_servers: Vec::new(),
159-
cwd: std::env::current_dir()?,
160-
meta: None,
161-
})
152+
.new_session(acp::NewSessionRequest::new(std::env::current_dir()?))
162153
.await?;
163154

164155
// Send prompts to the agent until stdin is closed.
165156
let mut rl = rustyline::DefaultEditor::new()?;
166157
while let Ok(line) = rl.readline("> ") {
167158
let result = conn
168-
.prompt(acp::PromptRequest {
169-
session_id: response.session_id.clone(),
170-
prompt: vec![line.into()],
171-
meta: None,
172-
})
159+
.prompt(acp::PromptRequest::new(
160+
response.session_id.clone(),
161+
vec![line.into()],
162+
))
173163
.await;
174164
if let Err(e) = result {
175165
log::error!("{e}");

0 commit comments

Comments
 (0)