From 504f93999929eb37d1d461b9928d96b3761c286c Mon Sep 17 00:00:00 2001 From: Ben Brandt Date: Mon, 6 Apr 2026 21:17:41 +0200 Subject: [PATCH] fix: Re-export Result and update docs to use V1 Switch examples and documentation from `ProtocolVersion::LATEST` to `ProtocolVersion::V1`, and simplify public signatures to use the re-exported `Result` alias. --- src/agent-client-protocol-cookbook/src/lib.rs | 4 +-- src/agent-client-protocol-core/README.md | 2 +- .../examples/simple_agent.rs | 4 +-- .../examples/yolo_one_shot_client.rs | 2 +- .../src/component.rs | 34 +++++++++---------- .../src/concepts/connections.rs | 2 +- .../src/concepts/peers.rs | 2 +- src/agent-client-protocol-core/src/lib.rs | 6 ++-- src/yopo/src/lib.rs | 2 +- 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/agent-client-protocol-cookbook/src/lib.rs b/src/agent-client-protocol-cookbook/src/lib.rs index c2f6fa3..fc3be1f 100644 --- a/src/agent-client-protocol-cookbook/src/lib.rs +++ b/src/agent-client-protocol-cookbook/src/lib.rs @@ -71,7 +71,7 @@ pub mod one_shot_prompt { //! .name("my-client") //! .connect_with(transport, async |connection| { //! // Initialize the connection - //! connection.send_request(InitializeRequest::new(ProtocolVersion::LATEST)) + //! connection.send_request(InitializeRequest::new(ProtocolVersion::V1)) //! .block_task().await?; //! //! // Create a session, send prompt, read response @@ -135,7 +135,7 @@ pub mod connecting_as_client { //! .name("my-client") //! .connect_with(transport, async |connection| { //! // Initialize the connection - //! connection.send_request(InitializeRequest::new(ProtocolVersion::LATEST)) + //! connection.send_request(InitializeRequest::new(ProtocolVersion::V1)) //! .block_task().await?; //! //! // Create a session and send a prompt diff --git a/src/agent-client-protocol-core/README.md b/src/agent-client-protocol-core/README.md index 1e4c8d0..a33a37d 100644 --- a/src/agent-client-protocol-core/README.md +++ b/src/agent-client-protocol-core/README.md @@ -23,7 +23,7 @@ Client.builder() .name("my-client") .connect_with(transport, async |cx| { // Initialize the connection - cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST)) + cx.send_request(InitializeRequest::new(ProtocolVersion::V1)) .block_task() .await?; diff --git a/src/agent-client-protocol-core/examples/simple_agent.rs b/src/agent-client-protocol-core/examples/simple_agent.rs index e40ec9c..939f1da 100644 --- a/src/agent-client-protocol-core/examples/simple_agent.rs +++ b/src/agent-client-protocol-core/examples/simple_agent.rs @@ -1,11 +1,11 @@ use agent_client_protocol_core::schema::{ AgentCapabilities, InitializeRequest, InitializeResponse, }; -use agent_client_protocol_core::{Agent, Client, ConnectionTo, Dispatch}; +use agent_client_protocol_core::{Agent, Client, ConnectionTo, Dispatch, Result}; use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; #[tokio::main] -async fn main() -> Result<(), agent_client_protocol_core::Error> { +async fn main() -> Result<()> { Agent .builder() .name("my-agent") // for debugging diff --git a/src/agent-client-protocol-core/examples/yolo_one_shot_client.rs b/src/agent-client-protocol-core/examples/yolo_one_shot_client.rs index 85f3759..109da71 100644 --- a/src/agent-client-protocol-core/examples/yolo_one_shot_client.rs +++ b/src/agent-client-protocol-core/examples/yolo_one_shot_client.rs @@ -120,7 +120,7 @@ async fn main() -> Result<(), Box> { // Initialize the agent eprintln!("🤝 Initializing agent..."); let init_response = connection - .send_request(InitializeRequest::new(ProtocolVersion::LATEST)) + .send_request(InitializeRequest::new(ProtocolVersion::V1)) .block_task() .await?; diff --git a/src/agent-client-protocol-core/src/component.rs b/src/agent-client-protocol-core/src/component.rs index 9ee8a11..f86bc2e 100644 --- a/src/agent-client-protocol-core/src/component.rs +++ b/src/agent-client-protocol-core/src/component.rs @@ -11,8 +11,7 @@ //! To implement a component, implement the `connect_to` method: //! //! ```rust,ignore -//! use agent_client_protocol_core::ConnectTo; -//! use agent_client_protocol_core::Client; +//! use agent_client_protocol_core::{Agent, Client, Connect, Result}; //! //! struct MyAgent { //! // configuration fields @@ -20,8 +19,8 @@ //! //! // An agent connects to clients //! impl ConnectTo for MyAgent { -//! async fn connect_to(self, client: impl ConnectTo) -> Result<(), agent_client_protocol_core::Error> { -//! agent_client_protocol_core::Agent.builder() +//! async fn connect_to(self, client: impl ConnectTo) -> Result<()> { +//! Agent.builder() //! .name("my-agent") //! // configure handlers here //! .connect_to(client) @@ -33,7 +32,7 @@ use futures::future::BoxFuture; use std::{fmt::Debug, future::Future, marker::PhantomData}; -use crate::{Channel, role::Role}; +use crate::{Channel, Result, role::Role}; /// A component that can exchange JSON-RPC messages to an endpoint playing the role `R` /// (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}; /// # Implementation Example /// /// ```rust,ignore -/// use agent_client_protocol_core::{Serve, role::Client}; +/// use agent_client_protocol_core::{Agent, Result, Serve, role::Client}; /// /// struct MyAgent { /// config: AgentConfig, /// } /// /// impl Serve for MyAgent { -/// async fn serve(self, client: impl Serve) -> Result<(), agent_client_protocol_core::Error> { +/// async fn serve(self, client: impl Serve) -> Result<()> { /// // Set up connection that forwards to client -/// agent_client_protocol_core::Agent.builder() +/// Agent.builder() /// .name("my-agent") /// .on_receive_request(async |req: MyRequest, cx| { /// // Handle request @@ -124,7 +123,7 @@ pub trait ConnectTo: Send + 'static { fn connect_to( self, client: impl ConnectTo, - ) -> impl Future> + Send; + ) -> impl Future> + Send; /// Convert this component into a channel endpoint and server future. /// @@ -141,7 +140,7 @@ pub trait ConnectTo: Send + 'static { /// /// A tuple of `(Channel, BoxFuture)` where the channel is for the caller to use /// and the future must be spawned to run the server. - fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) + fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<()>>) where Self: Sized, { @@ -162,11 +161,10 @@ trait ErasedConnectTo: Send { fn connect_to_erased( self: Box, client: Box>, - ) -> BoxFuture<'static, Result<(), crate::Error>>; + ) -> BoxFuture<'static, Result<()>>; - fn into_channel_and_future_erased( - self: Box, - ) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>); + fn into_channel_and_future_erased(self: Box) + -> (Channel, BoxFuture<'static, Result<()>>); } /// Blanket implementation: any `Serve` can be type-erased. @@ -178,7 +176,7 @@ impl, R: Role> ErasedConnectTo for C { fn connect_to_erased( self: Box, client: Box>, - ) -> BoxFuture<'static, Result<(), crate::Error>> { + ) -> BoxFuture<'static, Result<()>> { Box::pin(async move { (*self) .connect_to(DynConnectTo { @@ -191,7 +189,7 @@ impl, R: Role> ErasedConnectTo for C { fn into_channel_and_future_erased( self: Box, - ) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) { + ) -> (Channel, BoxFuture<'static, Result<()>>) { (*self).into_channel_and_future() } } @@ -237,13 +235,13 @@ impl DynConnectTo { } impl ConnectTo for DynConnectTo { - async fn connect_to(self, client: impl ConnectTo) -> Result<(), crate::Error> { + async fn connect_to(self, client: impl ConnectTo) -> Result<()> { self.inner .connect_to_erased(Box::new(client) as Box>) .await } - fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) { + fn into_channel_and_future(self) -> (Channel, BoxFuture<'static, Result<()>>) { self.inner.into_channel_and_future_erased() } } diff --git a/src/agent-client-protocol-core/src/concepts/connections.rs b/src/agent-client-protocol-core/src/concepts/connections.rs index d93893c..a4c9006 100644 --- a/src/agent-client-protocol-core/src/concepts/connections.rs +++ b/src/agent-client-protocol-core/src/concepts/connections.rs @@ -46,7 +46,7 @@ //! # async fn example(transport: impl ConnectTo) -> Result<(), agent_client_protocol_core::Error> { //! # Client.builder().connect_with(transport, async |cx| { //! // Send a request and wait for the response -//! let response = cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST)) +//! let response = cx.send_request(InitializeRequest::new(ProtocolVersion::V1)) //! .block_task() //! .await?; //! diff --git a/src/agent-client-protocol-core/src/concepts/peers.rs b/src/agent-client-protocol-core/src/concepts/peers.rs index 5bdfa56..93d8204 100644 --- a/src/agent-client-protocol-core/src/concepts/peers.rs +++ b/src/agent-client-protocol-core/src/concepts/peers.rs @@ -21,7 +21,7 @@ //! # async fn example(transport: impl ConnectTo) -> Result<(), agent_client_protocol_core::Error> { //! # Client.builder().connect_with(transport, async |cx| { //! // As a client -//! cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST)); +//! cx.send_request(InitializeRequest::new(ProtocolVersion::V1)); //! # Ok(()) //! # }).await?; //! # Ok(()) diff --git a/src/agent-client-protocol-core/src/lib.rs b/src/agent-client-protocol-core/src/lib.rs index 4193d1e..9175751 100644 --- a/src/agent-client-protocol-core/src/lib.rs +++ b/src/agent-client-protocol-core/src/lib.rs @@ -24,12 +24,12 @@ //! use agent_client_protocol_core::Client; //! use agent_client_protocol_core::schema::{InitializeRequest, ProtocolVersion}; //! -//! # async fn run(transport: impl agent_client_protocol_core::ConnectTo) -> Result<(), agent_client_protocol_core::Error> { +//! # async fn run(transport: impl agent_client_protocol_core::ConnectTo) -> agent_client_protocol_core::Result<()> { //! Client.builder() //! .name("my-client") //! .connect_with(transport, async |cx| { //! // Step 1: Initialize the connection -//! cx.send_request(InitializeRequest::new(ProtocolVersion::LATEST)) +//! cx.send_request(InitializeRequest::new(ProtocolVersion::V1)) //! .block_task().await?; //! //! // Step 2: Create a session and send a prompt @@ -134,7 +134,7 @@ pub use schema::{ }; // Re-export commonly used infrastructure types for convenience -pub use schema::{Error, ErrorCode}; +pub use schema::{Error, ErrorCode, Result}; // Re-export derive macros for custom JSON-RPC types pub use agent_client_protocol_derive::{JsonRpcNotification, JsonRpcRequest, JsonRpcResponse}; diff --git a/src/yopo/src/lib.rs b/src/yopo/src/lib.rs index 46505cd..4bac474 100644 --- a/src/yopo/src/lib.rs +++ b/src/yopo/src/lib.rs @@ -102,7 +102,7 @@ pub async fn prompt_with_callback( .connect_with(component, |cx: agent_client_protocol_core::ConnectionTo| async move { // Initialize the agent let _init_response = cx - .send_request(InitializeRequest::new(ProtocolVersion::LATEST)) + .send_request(InitializeRequest::new(ProtocolVersion::V1)) .block_task() .await?;