Skip to content

Commit ec9ceae

Browse files
authored
fix: Re-export Result and update docs to use V1 (#110)
Switch examples and documentation from `ProtocolVersion::LATEST` to `ProtocolVersion::V1`, and simplify public signatures to use the re-exported `Result` alias.
1 parent 4194d70 commit ec9ceae

File tree

9 files changed

+28
-30
lines changed

9 files changed

+28
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub mod one_shot_prompt {
7171
//! .name("my-client")
7272
//! .connect_with(transport, async |connection| {
7373
//! // Initialize the connection
74-
//! connection.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
74+
//! connection.send_request(InitializeRequest::new(ProtocolVersion::V1))
7575
//! .block_task().await?;
7676
//!
7777
//! // Create a session, send prompt, read response
@@ -135,7 +135,7 @@ pub mod connecting_as_client {
135135
//! .name("my-client")
136136
//! .connect_with(transport, async |connection| {
137137
//! // Initialize the connection
138-
//! connection.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
138+
//! connection.send_request(InitializeRequest::new(ProtocolVersion::V1))
139139
//! .block_task().await?;
140140
//!
141141
//! // Create a session and send a prompt

src/agent-client-protocol-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Client.builder()
2323
.name("my-client")
2424
.connect_with(transport, async |cx| {
2525
// Initialize the connection
26-
cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
26+
cx.send_request(InitializeRequest::new(ProtocolVersion::V1))
2727
.block_task()
2828
.await?;
2929

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use agent_client_protocol_core::schema::{
22
AgentCapabilities, InitializeRequest, InitializeResponse,
33
};
4-
use agent_client_protocol_core::{Agent, Client, ConnectionTo, Dispatch};
4+
use agent_client_protocol_core::{Agent, Client, ConnectionTo, Dispatch, Result};
55
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
66

77
#[tokio::main]
8-
async fn main() -> Result<(), agent_client_protocol_core::Error> {
8+
async fn main() -> Result<()> {
99
Agent
1010
.builder()
1111
.name("my-agent") // for debugging

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
120120
// Initialize the agent
121121
eprintln!("🤝 Initializing agent...");
122122
let init_response = connection
123-
.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
123+
.send_request(InitializeRequest::new(ProtocolVersion::V1))
124124
.block_task()
125125
.await?;
126126

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
//! To implement a component, implement the `connect_to` method:
1212
//!
1313
//! ```rust,ignore
14-
//! use agent_client_protocol_core::ConnectTo;
15-
//! use agent_client_protocol_core::Client;
14+
//! use agent_client_protocol_core::{Agent, Client, Connect, Result};
1615
//!
1716
//! struct MyAgent {
1817
//! // configuration fields
1918
//! }
2019
//!
2120
//! // An agent connects to clients
2221
//! impl ConnectTo<Client> for MyAgent {
23-
//! async fn connect_to(self, client: impl ConnectTo<Agent>) -> Result<(), agent_client_protocol_core::Error> {
24-
//! agent_client_protocol_core::Agent.builder()
22+
//! async fn connect_to(self, client: impl ConnectTo<Agent>) -> Result<()> {
23+
//! Agent.builder()
2524
//! .name("my-agent")
2625
//! // configure handlers here
2726
//! .connect_to(client)
@@ -33,7 +32,7 @@
3332
use futures::future::BoxFuture;
3433
use std::{fmt::Debug, future::Future, marker::PhantomData};
3534

36-
use crate::{Channel, role::Role};
35+
use crate::{Channel, Result, role::Role};
3736

3837
/// A component that can exchange JSON-RPC messages to an endpoint playing the role `R`
3938
/// (e.g., an ACP [`Agent`](`crate::role::acp::Agent`) or an MCP [`Server`](`crate::role::mcp::Server`)).
@@ -69,16 +68,16 @@ use crate::{Channel, role::Role};
6968
/// # Implementation Example
7069
///
7170
/// ```rust,ignore
72-
/// use agent_client_protocol_core::{Serve, role::Client};
71+
/// use agent_client_protocol_core::{Agent, Result, Serve, role::Client};
7372
///
7473
/// struct MyAgent {
7574
/// config: AgentConfig,
7675
/// }
7776
///
7877
/// impl Serve<Client> for MyAgent {
79-
/// async fn serve(self, client: impl Serve<Client::Counterpart>) -> Result<(), agent_client_protocol_core::Error> {
78+
/// async fn serve(self, client: impl Serve<Client::Counterpart>) -> Result<()> {
8079
/// // Set up connection that forwards to client
81-
/// agent_client_protocol_core::Agent.builder()
80+
/// Agent.builder()
8281
/// .name("my-agent")
8382
/// .on_receive_request(async |req: MyRequest, cx| {
8483
/// // Handle request
@@ -124,7 +123,7 @@ pub trait ConnectTo<R: Role>: Send + 'static {
124123
fn connect_to(
125124
self,
126125
client: impl ConnectTo<R::Counterpart>,
127-
) -> impl Future<Output = Result<(), crate::Error>> + Send;
126+
) -> impl Future<Output = Result<()>> + Send;
128127

129128
/// Convert this component into a channel endpoint and server future.
130129
///
@@ -141,7 +140,7 @@ pub trait ConnectTo<R: Role>: Send + 'static {
141140
///
142141
/// A tuple of `(Channel, BoxFuture)` where the channel is for the caller to use
143142
/// and the future must be spawned to run the server.
144-
fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>)
143+
fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<()>>)
145144
where
146145
Self: Sized,
147146
{
@@ -162,11 +161,10 @@ trait ErasedConnectTo<R: Role>: Send {
162161
fn connect_to_erased(
163162
self: Box<Self>,
164163
client: Box<dyn ErasedConnectTo<R::Counterpart>>,
165-
) -> BoxFuture<'static, Result<(), crate::Error>>;
164+
) -> BoxFuture<'static, Result<()>>;
166165

167-
fn into_channel_and_future_erased(
168-
self: Box<Self>,
169-
) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>);
166+
fn into_channel_and_future_erased(self: Box<Self>)
167+
-> (Channel, BoxFuture<'static, Result<()>>);
170168
}
171169

172170
/// Blanket implementation: any `Serve<R>` can be type-erased.
@@ -178,7 +176,7 @@ impl<C: ConnectTo<R>, R: Role> ErasedConnectTo<R> for C {
178176
fn connect_to_erased(
179177
self: Box<Self>,
180178
client: Box<dyn ErasedConnectTo<R::Counterpart>>,
181-
) -> BoxFuture<'static, Result<(), crate::Error>> {
179+
) -> BoxFuture<'static, Result<()>> {
182180
Box::pin(async move {
183181
(*self)
184182
.connect_to(DynConnectTo {
@@ -191,7 +189,7 @@ impl<C: ConnectTo<R>, R: Role> ErasedConnectTo<R> for C {
191189

192190
fn into_channel_and_future_erased(
193191
self: Box<Self>,
194-
) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) {
192+
) -> (Channel, BoxFuture<'static, Result<()>>) {
195193
(*self).into_channel_and_future()
196194
}
197195
}
@@ -237,13 +235,13 @@ impl<R: Role> DynConnectTo<R> {
237235
}
238236

239237
impl<R: Role> ConnectTo<R> for DynConnectTo<R> {
240-
async fn connect_to(self, client: impl ConnectTo<R::Counterpart>) -> Result<(), crate::Error> {
238+
async fn connect_to(self, client: impl ConnectTo<R::Counterpart>) -> Result<()> {
241239
self.inner
242240
.connect_to_erased(Box::new(client) as Box<dyn ErasedConnectTo<R::Counterpart>>)
243241
.await
244242
}
245243

246-
fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) {
244+
fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<()>>) {
247245
self.inner.into_channel_and_future_erased()
248246
}
249247
}

src/agent-client-protocol-core/src/concepts/connections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//! # async fn example(transport: impl ConnectTo<Client>) -> Result<(), agent_client_protocol_core::Error> {
4747
//! # Client.builder().connect_with(transport, async |cx| {
4848
//! // Send a request and wait for the response
49-
//! let response = cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
49+
//! let response = cx.send_request(InitializeRequest::new(ProtocolVersion::V1))
5050
//! .block_task()
5151
//! .await?;
5252
//!

src/agent-client-protocol-core/src/concepts/peers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! # async fn example(transport: impl ConnectTo<Client>) -> Result<(), agent_client_protocol_core::Error> {
2222
//! # Client.builder().connect_with(transport, async |cx| {
2323
//! // As a client
24-
//! cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST));
24+
//! cx.send_request(InitializeRequest::new(ProtocolVersion::V1));
2525
//! # Ok(())
2626
//! # }).await?;
2727
//! # Ok(())

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
//! use agent_client_protocol_core::Client;
2525
//! use agent_client_protocol_core::schema::{InitializeRequest, ProtocolVersion};
2626
//!
27-
//! # async fn run(transport: impl agent_client_protocol_core::ConnectTo<agent_client_protocol_core::Client>) -> Result<(), agent_client_protocol_core::Error> {
27+
//! # async fn run(transport: impl agent_client_protocol_core::ConnectTo<agent_client_protocol_core::Client>) -> agent_client_protocol_core::Result<()> {
2828
//! Client.builder()
2929
//! .name("my-client")
3030
//! .connect_with(transport, async |cx| {
3131
//! // Step 1: Initialize the connection
32-
//! cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
32+
//! cx.send_request(InitializeRequest::new(ProtocolVersion::V1))
3333
//! .block_task().await?;
3434
//!
3535
//! // Step 2: Create a session and send a prompt
@@ -134,7 +134,7 @@ pub use schema::{
134134
};
135135

136136
// Re-export commonly used infrastructure types for convenience
137-
pub use schema::{Error, ErrorCode};
137+
pub use schema::{Error, ErrorCode, Result};
138138

139139
// Re-export derive macros for custom JSON-RPC types
140140
pub use agent_client_protocol_derive::{JsonRpcNotification, JsonRpcRequest, JsonRpcResponse};

src/yopo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub async fn prompt_with_callback(
102102
.connect_with(component, |cx: agent_client_protocol_core::ConnectionTo<Agent>| async move {
103103
// Initialize the agent
104104
let _init_response = cx
105-
.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
105+
.send_request(InitializeRequest::new(ProtocolVersion::V1))
106106
.block_task()
107107
.await?;
108108

0 commit comments

Comments
 (0)