Skip to content

Commit 719a26c

Browse files
authored
Export and use acp::Result type (#3)
1 parent b366040 commit 719a26c

File tree

11 files changed

+156
-217
lines changed

11 files changed

+156
-217
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.4.8 (2025-10-16)
4+
5+
- Export `acp::Result<T, E = acp::Error>` for easier indication of ACP errors.
6+
37
## 0.4.7 (2025-10-13)
48

59
- Depend on `agent-client-protocol-schema` for schema types

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "agent-client-protocol"
33
authors = ["Zed <hi@zed.dev>"]
4-
version = "0.4.7"
4+
version = "0.4.8"
55
edition = "2024"
66
license = "Apache-2.0"
77
description = "A protocol for standardizing communication between code editors and AI coding agents"
@@ -17,14 +17,13 @@ include = ["/src/**/*.rs", "/README.md", "/LICENSE", "/Cargo.toml"]
1717
unstable = ["agent-client-protocol-schema/unstable"]
1818

1919
[dependencies]
20-
agent-client-protocol-schema = "0.4.9"
20+
agent-client-protocol-schema = "0.4.10"
2121
anyhow = "1"
2222
async-broadcast = "0.7"
2323
async-trait = "0.1"
2424
futures = { version = "0.3" }
2525
log = "0.4"
2626
parking_lot = "0.12"
27-
schemars = { version = "1" }
2827
serde = { version = "1", features = ["derive", "rc"] }
2928
serde_json = { version = "1", features = ["raw_value"] }
3029

examples/agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl acp::Agent for ExampleAgent {
154154
}
155155

156156
#[tokio::main(flavor = "current_thread")]
157-
async fn main() -> anyhow::Result<()> {
157+
async fn main() -> acp::Result<()> {
158158
env_logger::init();
159159

160160
let outgoing = tokio::io::stdout().compat_write();

examples/client.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! ```
1414
1515
use agent_client_protocol::{self as acp, Agent as _};
16-
use anyhow::bail;
1716
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
1817

1918
struct ExampleClient {}
@@ -23,21 +22,21 @@ impl acp::Client for ExampleClient {
2322
async fn request_permission(
2423
&self,
2524
_args: acp::RequestPermissionRequest,
26-
) -> anyhow::Result<acp::RequestPermissionResponse, acp::Error> {
25+
) -> acp::Result<acp::RequestPermissionResponse> {
2726
Err(acp::Error::method_not_found())
2827
}
2928

3029
async fn write_text_file(
3130
&self,
3231
_args: acp::WriteTextFileRequest,
33-
) -> anyhow::Result<acp::WriteTextFileResponse, acp::Error> {
32+
) -> acp::Result<acp::WriteTextFileResponse> {
3433
Err(acp::Error::method_not_found())
3534
}
3635

3736
async fn read_text_file(
3837
&self,
3938
_args: acp::ReadTextFileRequest,
40-
) -> anyhow::Result<acp::ReadTextFileResponse, acp::Error> {
39+
) -> acp::Result<acp::ReadTextFileResponse> {
4140
Err(acp::Error::method_not_found())
4241
}
4342

@@ -51,35 +50,35 @@ impl acp::Client for ExampleClient {
5150
async fn terminal_output(
5251
&self,
5352
_args: acp::TerminalOutputRequest,
54-
) -> anyhow::Result<acp::TerminalOutputResponse, acp::Error> {
53+
) -> acp::Result<acp::TerminalOutputResponse> {
5554
Err(acp::Error::method_not_found())
5655
}
5756

5857
async fn release_terminal(
5958
&self,
6059
_args: acp::ReleaseTerminalRequest,
61-
) -> anyhow::Result<acp::ReleaseTerminalResponse, acp::Error> {
60+
) -> acp::Result<acp::ReleaseTerminalResponse> {
6261
Err(acp::Error::method_not_found())
6362
}
6463

6564
async fn wait_for_terminal_exit(
6665
&self,
6766
_args: acp::WaitForTerminalExitRequest,
68-
) -> anyhow::Result<acp::WaitForTerminalExitResponse, acp::Error> {
67+
) -> acp::Result<acp::WaitForTerminalExitResponse> {
6968
Err(acp::Error::method_not_found())
7069
}
7170

7271
async fn kill_terminal_command(
7372
&self,
7473
_args: acp::KillTerminalCommandRequest,
75-
) -> anyhow::Result<acp::KillTerminalCommandResponse, acp::Error> {
74+
) -> acp::Result<acp::KillTerminalCommandResponse> {
7675
Err(acp::Error::method_not_found())
7776
}
7877

7978
async fn session_notification(
8079
&self,
8180
args: acp::SessionNotification,
82-
) -> anyhow::Result<(), acp::Error> {
81+
) -> acp::Result<(), acp::Error> {
8382
match args.update {
8483
acp::SessionUpdate::AgentMessageChunk { content } => {
8584
let text = match content {
@@ -102,11 +101,11 @@ impl acp::Client for ExampleClient {
102101
Ok(())
103102
}
104103

105-
async fn ext_method(&self, _args: acp::ExtRequest) -> Result<acp::ExtResponse, acp::Error> {
104+
async fn ext_method(&self, _args: acp::ExtRequest) -> acp::Result<acp::ExtResponse> {
106105
Err(acp::Error::method_not_found())
107106
}
108107

109-
async fn ext_notification(&self, _args: acp::ExtNotification) -> Result<(), acp::Error> {
108+
async fn ext_notification(&self, _args: acp::ExtNotification) -> acp::Result<()> {
110109
Err(acp::Error::method_not_found())
111110
}
112111
}
@@ -130,7 +129,7 @@ async fn main() -> anyhow::Result<()> {
130129
child,
131130
)
132131
}
133-
_ => bail!("Usage: client AGENT_PROGRAM AGENT_ARG..."),
132+
_ => anyhow::bail!("Usage: client AGENT_PROGRAM AGENT_ARG..."),
134133
};
135134

136135
// The ClientSideConnection will spawn futures onto our Tokio runtime.

src/agent.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use std::{rc::Rc, sync::Arc};
22

3-
use serde_json::value::RawValue;
4-
53
use agent_client_protocol_schema::{
64
AuthenticateRequest, AuthenticateResponse, CancelNotification, Error, ExtNotification,
75
ExtRequest, ExtResponse, InitializeRequest, InitializeResponse, LoadSessionRequest,
86
LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse,
9-
SetSessionModeRequest, SetSessionModeResponse,
7+
Result, SetSessionModeRequest, SetSessionModeResponse,
108
};
119
#[cfg(feature = "unstable")]
1210
use agent_client_protocol_schema::{SetSessionModelRequest, SetSessionModelResponse};
11+
use serde_json::value::RawValue;
1312

1413
/// Defines the interface that all ACP-compliant agents must implement.
1514
///
@@ -27,7 +26,7 @@ pub trait Agent {
2726
/// The agent should respond with its supported protocol version and capabilities.
2827
///
2928
/// See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
30-
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error>;
29+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse>;
3130

3231
/// Authenticates the client using the specified authentication method.
3332
///
@@ -38,7 +37,7 @@ pub trait Agent {
3837
/// `new_session` without receiving an `auth_required` error.
3938
///
4039
/// See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
41-
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error>;
40+
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse>;
4241

4342
/// Creates a new conversation session with the agent.
4443
///
@@ -52,7 +51,7 @@ pub trait Agent {
5251
/// May return an `auth_required` error if the agent requires authentication.
5352
///
5453
/// See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
55-
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error>;
54+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse>;
5655

5756
/// Processes a user prompt within a session.
5857
///
@@ -65,7 +64,7 @@ pub trait Agent {
6564
/// - Returns when the turn is complete with a stop reason
6665
///
6766
/// See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
68-
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error>;
67+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse>;
6968

7069
/// Cancels ongoing operations for a session.
7170
///
@@ -78,7 +77,7 @@ pub trait Agent {
7877
/// - Respond to the original `session/prompt` request with `StopReason::Cancelled`
7978
///
8079
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
81-
async fn cancel(&self, args: CancelNotification) -> Result<(), Error>;
80+
async fn cancel(&self, args: CancelNotification) -> Result<()>;
8281

8382
/// Loads an existing session to resume a previous conversation.
8483
///
@@ -90,7 +89,7 @@ pub trait Agent {
9089
/// - Stream the entire conversation history back to the client via notifications
9190
///
9291
/// See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
93-
async fn load_session(&self, _args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
92+
async fn load_session(&self, _args: LoadSessionRequest) -> Result<LoadSessionResponse> {
9493
Err(Error::method_not_found())
9594
}
9695

@@ -110,7 +109,7 @@ pub trait Agent {
110109
async fn set_session_mode(
111110
&self,
112111
_args: SetSessionModeRequest,
113-
) -> Result<SetSessionModeResponse, Error> {
112+
) -> Result<SetSessionModeResponse> {
114113
Err(Error::method_not_found())
115114
}
116115

@@ -123,7 +122,7 @@ pub trait Agent {
123122
async fn set_session_model(
124123
&self,
125124
_args: SetSessionModelRequest,
126-
) -> Result<SetSessionModelResponse, Error> {
125+
) -> Result<SetSessionModelResponse> {
127126
Err(Error::method_not_found())
128127
}
129128

@@ -133,7 +132,7 @@ pub trait Agent {
133132
/// protocol compatibility.
134133
///
135134
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
136-
async fn ext_method(&self, _args: ExtRequest) -> Result<ExtResponse, Error> {
135+
async fn ext_method(&self, _args: ExtRequest) -> Result<ExtResponse> {
137136
Ok(RawValue::NULL.to_owned().into())
138137
}
139138

@@ -143,89 +142,89 @@ pub trait Agent {
143142
/// while maintaining protocol compatibility.
144143
///
145144
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
146-
async fn ext_notification(&self, _args: ExtNotification) -> Result<(), Error> {
145+
async fn ext_notification(&self, _args: ExtNotification) -> Result<()> {
147146
Ok(())
148147
}
149148
}
150149

151150
#[async_trait::async_trait(?Send)]
152151
impl<T: Agent> Agent for Rc<T> {
153-
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
152+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse> {
154153
self.as_ref().initialize(args).await
155154
}
156-
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
155+
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse> {
157156
self.as_ref().authenticate(args).await
158157
}
159-
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
158+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse> {
160159
self.as_ref().new_session(args).await
161160
}
162-
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
161+
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse> {
163162
self.as_ref().load_session(args).await
164163
}
165164
async fn set_session_mode(
166165
&self,
167166
args: SetSessionModeRequest,
168-
) -> Result<SetSessionModeResponse, Error> {
167+
) -> Result<SetSessionModeResponse> {
169168
self.as_ref().set_session_mode(args).await
170169
}
171-
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
170+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse> {
172171
self.as_ref().prompt(args).await
173172
}
174-
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
173+
async fn cancel(&self, args: CancelNotification) -> Result<()> {
175174
self.as_ref().cancel(args).await
176175
}
177176
#[cfg(feature = "unstable")]
178177
async fn set_session_model(
179178
&self,
180179
args: SetSessionModelRequest,
181-
) -> Result<SetSessionModelResponse, Error> {
180+
) -> Result<SetSessionModelResponse> {
182181
self.as_ref().set_session_model(args).await
183182
}
184-
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
183+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
185184
self.as_ref().ext_method(args).await
186185
}
187-
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
186+
async fn ext_notification(&self, args: ExtNotification) -> Result<()> {
188187
self.as_ref().ext_notification(args).await
189188
}
190189
}
191190

192191
#[async_trait::async_trait(?Send)]
193192
impl<T: Agent> Agent for Arc<T> {
194-
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse, Error> {
193+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse> {
195194
self.as_ref().initialize(args).await
196195
}
197-
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse, Error> {
196+
async fn authenticate(&self, args: AuthenticateRequest) -> Result<AuthenticateResponse> {
198197
self.as_ref().authenticate(args).await
199198
}
200-
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
199+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse> {
201200
self.as_ref().new_session(args).await
202201
}
203-
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse, Error> {
202+
async fn load_session(&self, args: LoadSessionRequest) -> Result<LoadSessionResponse> {
204203
self.as_ref().load_session(args).await
205204
}
206205
async fn set_session_mode(
207206
&self,
208207
args: SetSessionModeRequest,
209-
) -> Result<SetSessionModeResponse, Error> {
208+
) -> Result<SetSessionModeResponse> {
210209
self.as_ref().set_session_mode(args).await
211210
}
212-
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse, Error> {
211+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse> {
213212
self.as_ref().prompt(args).await
214213
}
215-
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
214+
async fn cancel(&self, args: CancelNotification) -> Result<()> {
216215
self.as_ref().cancel(args).await
217216
}
218217
#[cfg(feature = "unstable")]
219218
async fn set_session_model(
220219
&self,
221220
args: SetSessionModelRequest,
222-
) -> Result<SetSessionModelResponse, Error> {
221+
) -> Result<SetSessionModelResponse> {
223222
self.as_ref().set_session_model(args).await
224223
}
225-
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, Error> {
224+
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
226225
self.as_ref().ext_method(args).await
227226
}
228-
async fn ext_notification(&self, args: ExtNotification) -> Result<(), Error> {
227+
async fn ext_notification(&self, args: ExtNotification) -> Result<()> {
229228
self.as_ref().ext_notification(args).await
230229
}
231230
}

0 commit comments

Comments
 (0)