Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/agent-client-protocol-cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/agent-client-protocol-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
4 changes: 2 additions & 2 deletions src/agent-client-protocol-core/examples/simple_agent.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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?;

Expand Down
34 changes: 16 additions & 18 deletions src/agent-client-protocol-core/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
//! 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
//! }
//!
//! // An agent connects to clients
//! impl ConnectTo<Client> for MyAgent {
//! async fn connect_to(self, client: impl ConnectTo<Agent>) -> Result<(), agent_client_protocol_core::Error> {
//! agent_client_protocol_core::Agent.builder()
//! async fn connect_to(self, client: impl ConnectTo<Agent>) -> Result<()> {
//! Agent.builder()
//! .name("my-agent")
//! // configure handlers here
//! .connect_to(client)
Expand All @@ -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`)).
Expand Down Expand Up @@ -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<Client> for MyAgent {
/// async fn serve(self, client: impl Serve<Client::Counterpart>) -> Result<(), agent_client_protocol_core::Error> {
/// async fn serve(self, client: impl Serve<Client::Counterpart>) -> 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
Expand Down Expand Up @@ -124,7 +123,7 @@ pub trait ConnectTo<R: Role>: Send + 'static {
fn connect_to(
self,
client: impl ConnectTo<R::Counterpart>,
) -> impl Future<Output = Result<(), crate::Error>> + Send;
) -> impl Future<Output = Result<()>> + Send;

/// Convert this component into a channel endpoint and server future.
///
Expand All @@ -141,7 +140,7 @@ pub trait ConnectTo<R: Role>: 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,
{
Expand All @@ -162,11 +161,10 @@ trait ErasedConnectTo<R: Role>: Send {
fn connect_to_erased(
self: Box<Self>,
client: Box<dyn ErasedConnectTo<R::Counterpart>>,
) -> BoxFuture<'static, Result<(), crate::Error>>;
) -> BoxFuture<'static, Result<()>>;

fn into_channel_and_future_erased(
self: Box<Self>,
) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>);
fn into_channel_and_future_erased(self: Box<Self>)
-> (Channel, BoxFuture<'static, Result<()>>);
}

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

fn into_channel_and_future_erased(
self: Box<Self>,
) -> (Channel, BoxFuture<'static, Result<(), crate::Error>>) {
) -> (Channel, BoxFuture<'static, Result<()>>) {
(*self).into_channel_and_future()
}
}
Expand Down Expand Up @@ -237,13 +235,13 @@ impl<R: Role> DynConnectTo<R> {
}

impl<R: Role> ConnectTo<R> for DynConnectTo<R> {
async fn connect_to(self, client: impl ConnectTo<R::Counterpart>) -> Result<(), crate::Error> {
async fn connect_to(self, client: impl ConnectTo<R::Counterpart>) -> Result<()> {
self.inner
.connect_to_erased(Box::new(client) as Box<dyn ErasedConnectTo<R::Counterpart>>)
.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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent-client-protocol-core/src/concepts/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! # async fn example(transport: impl ConnectTo<Client>) -> 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?;
//!
Expand Down
2 changes: 1 addition & 1 deletion src/agent-client-protocol-core/src/concepts/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! # async fn example(transport: impl ConnectTo<Client>) -> 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(())
Expand Down
6 changes: 3 additions & 3 deletions src/agent-client-protocol-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<agent_client_protocol_core::Client>) -> Result<(), agent_client_protocol_core::Error> {
//! # async fn run(transport: impl agent_client_protocol_core::ConnectTo<agent_client_protocol_core::Client>) -> 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
Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/yopo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn prompt_with_callback(
.connect_with(component, |cx: agent_client_protocol_core::ConnectionTo<Agent>| async move {
// Initialize the agent
let _init_response = cx
.send_request(InitializeRequest::new(ProtocolVersion::LATEST))
.send_request(InitializeRequest::new(ProtocolVersion::V1))
.block_task()
.await?;

Expand Down
Loading