Skip to content

Commit edeb309

Browse files
authored
feat(rust): Expose v1 schema types only under v1 module (#1457)
* fix: Cleanup rust crate exports and trait derives * feat: Expose v1 schema types only under v1 module Prepares the way for multiple versions exported from the same crate. Accepting the breaking change pre-1.0
1 parent fcc8732 commit edeb309

14 files changed

Lines changed: 86 additions & 69 deletions

File tree

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@
1919
//!
2020
//! ## What's in this crate
2121
//!
22-
//! - Wire-format types for every ACP method: request, response, and
23-
//! notification structs grouped by which side handles them.
24-
//! - JSON-RPC envelope and routing types: [`JsonRpcMessage`],
25-
//! [`rpc::JsonRpcBatch`], [`Request`], [`Response`], [`Notification`],
26-
//! [`RequestId`], [`Error`].
27-
//! - Aggregated routing enums: [`AgentRequest`], [`AgentResponse`],
28-
//! [`AgentNotification`], and the matching client-side trio used by SDK
22+
//! - Versioned wire-format types for every ACP method: request, response, and
23+
//! notification structs grouped by which side handles them, currently under
24+
//! the [`v1`] module.
25+
//! - JSON-RPC envelope and routing types: [`v1::JsonRpcMessage`],
26+
//! [`rpc::JsonRpcBatch`], [`v1::Request`], [`v1::Response`],
27+
//! [`v1::Notification`], [`v1::RequestId`], [`v1::Error`].
28+
//! - Aggregated routing enums: [`v1::AgentRequest`], [`v1::AgentResponse`],
29+
//! [`v1::AgentNotification`], and the matching client-side trio used by SDK
2930
//! crates to dispatch incoming JSON-RPC messages.
3031
//!
3132
//! ## Versioning
3233
//!
33-
//! The default surface re-exports the v1 (current stable) protocol types
34-
//! directly at the crate root, so most consumers can write
35-
//! `agent_client_protocol_schema::SessionId` (and so on) without thinking
36-
//! about versions.
34+
//! Stable protocol types are exposed through explicit version modules. For
35+
//! example, use `agent_client_protocol_schema::v1::SessionId` for ACP protocol
36+
//! version 1 types.
3737
//!
3838
//! For the complete protocol specification and documentation, visit
3939
//! <https://agentclientprotocol.com>.
4040
4141
pub mod rpc;
4242
mod serde_util;
43-
mod v1;
43+
pub mod v1;
4444
#[cfg(feature = "unstable_protocol_v2")]
4545
pub mod v2;
4646
mod version;
4747

48-
pub use serde_util::*;
49-
pub use v1::*;
48+
pub(crate) use serde_util::SkipListener;
49+
pub use serde_util::{IntoMaybeUndefined, IntoOption, MaybeUndefined};
5050
pub use version::*;
5151

5252
#[cfg(test)]

agent-client-protocol-schema/src/rpc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum RequestId {
5050
}
5151

5252
/// A JSON-RPC request object.
53-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
53+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
5454
#[allow(
5555
clippy::exhaustive_structs,
5656
reason = "This comes from the JSON-RPC specification itself"
@@ -67,7 +67,7 @@ pub struct Request<Params> {
6767
}
6868

6969
/// A JSON-RPC response object.
70-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
70+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
7171
#[allow(
7272
clippy::exhaustive_enums,
7373
reason = "This comes from the JSON-RPC specification itself"
@@ -109,7 +109,7 @@ impl<R, E> Response<R, E> {
109109
}
110110

111111
/// A JSON-RPC notification object.
112-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
112+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
113113
#[allow(
114114
clippy::exhaustive_structs,
115115
reason = "This comes from the JSON-RPC specification itself"
@@ -123,7 +123,7 @@ pub struct Notification<Params> {
123123
pub params: Option<Params>,
124124
}
125125

126-
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
126+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
127127
#[schemars(inline)]
128128
enum JsonRpcVersion {
129129
#[serde(rename = "2.0")]
@@ -134,7 +134,7 @@ enum JsonRpcVersion {
134134
/// [required by JSON-RPC 2.0 Specification][1].
135135
///
136136
/// [1]: https://www.jsonrpc.org/specification#compatibility
137-
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
137+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
138138
#[schemars(inline)]
139139
pub struct JsonRpcMessage<M> {
140140
jsonrpc: JsonRpcVersion,
@@ -174,7 +174,7 @@ pub struct EmptyJsonRpcBatch;
174174
impl std::error::Error for EmptyJsonRpcBatch {}
175175

176176
/// A non-empty JSON-RPC 2.0 batch message.
177-
#[derive(Debug, Serialize, JsonSchema)]
177+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
178178
#[schemars(inline)]
179179
#[serde(transparent)]
180180
#[allow(
@@ -238,7 +238,7 @@ where
238238
mod tests {
239239
use super::*;
240240

241-
use crate::{
241+
use crate::v1::{
242242
AgentNotification, CancelNotification, ClientNotification, ContentBlock, ContentChunk,
243243
SessionId, SessionNotification, SessionUpdate, TextContent,
244244
};

agent-client-protocol-schema/src/serde_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use serde_with::{DeserializeAs, de::DeserializeAsWrap};
3939
#[cfg(feature = "tracing")]
4040
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
4141
#[non_exhaustive]
42-
pub struct SkipListener;
42+
pub(crate) struct SkipListener;
4343

4444
#[cfg(feature = "tracing")]
4545
impl serde_with::InspectError for SkipListener {
@@ -55,7 +55,7 @@ impl serde_with::InspectError for SkipListener {
5555
/// disabled. Resolves to `()`, which `serde_with` already ships with a no-op
5656
/// `InspectError` implementation.
5757
#[cfg(not(feature = "tracing"))]
58-
pub type SkipListener = ();
58+
pub(crate) type SkipListener = ();
5959

6060
#[cfg(test)]
6161
mod skip_listener_tests {

agent-client-protocol-schema/src/v1/agent.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use schemars::JsonSchema;
1313
use serde::{Deserialize, Serialize};
1414
use serde_with::{DefaultOnError, VecSkipError, serde_as, skip_serializing_none};
1515

16-
use crate::{
17-
ClientCapabilities, ContentBlock, ExtNotification, ExtRequest, ExtResponse, IntoOption, Meta,
18-
ProtocolVersion, SessionId, SkipListener,
16+
use crate::{IntoOption, ProtocolVersion, SkipListener};
17+
18+
use super::{
19+
ClientCapabilities, ContentBlock, ExtNotification, ExtRequest, ExtResponse, Meta, SessionId,
1920
};
2021

2122
#[cfg(feature = "unstable_mcp_over_acp")]
@@ -24,15 +25,15 @@ use super::mcp::{
2425
};
2526

2627
#[cfg(feature = "unstable_nes")]
27-
use crate::{
28+
use super::{
2829
AcceptNesNotification, CloseNesRequest, CloseNesResponse, DidChangeDocumentNotification,
2930
DidCloseDocumentNotification, DidFocusDocumentNotification, DidOpenDocumentNotification,
3031
DidSaveDocumentNotification, NesCapabilities, PositionEncodingKind, RejectNesNotification,
3132
StartNesRequest, StartNesResponse, SuggestNesRequest, SuggestNesResponse,
3233
};
3334

3435
#[cfg(feature = "unstable_nes")]
35-
use crate::{
36+
use super::{
3637
DOCUMENT_DID_CHANGE_METHOD_NAME, DOCUMENT_DID_CLOSE_METHOD_NAME,
3738
DOCUMENT_DID_FOCUS_METHOD_NAME, DOCUMENT_DID_OPEN_METHOD_NAME, DOCUMENT_DID_SAVE_METHOD_NAME,
3839
NES_ACCEPT_METHOD_NAME, NES_CLOSE_METHOD_NAME, NES_REJECT_METHOD_NAME, NES_START_METHOD_NAME,

agent-client-protocol-schema/src/v1/client.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ use serde::{Deserialize, Serialize};
1111
use serde_with::{DefaultOnError, VecSkipError, serde_as, skip_serializing_none};
1212

1313
#[cfg(feature = "unstable_elicitation")]
14-
use crate::{
14+
use super::{
1515
CompleteElicitationNotification, CreateElicitationRequest, CreateElicitationResponse,
1616
ElicitationCapabilities,
1717
};
18-
use crate::{
19-
ContentBlock, EnvVariable, ExtNotification, ExtRequest, ExtResponse, IntoMaybeUndefined,
20-
IntoOption, MaybeUndefined, Meta, Plan, SessionConfigOption, SessionId, SessionModeId,
21-
SkipListener, ToolCall, ToolCallUpdate,
18+
use crate::{IntoMaybeUndefined, IntoOption, MaybeUndefined, SkipListener};
19+
20+
use super::{
21+
ContentBlock, EnvVariable, ExtNotification, ExtRequest, ExtResponse, Meta, Plan,
22+
SessionConfigOption, SessionId, SessionModeId, ToolCall, ToolCallUpdate,
2223
};
2324
#[cfg(feature = "unstable_plan_operations")]
24-
use crate::{PlanCapabilities, PlanRemoved, PlanUpdate};
25+
use super::{PlanCapabilities, PlanRemoved, PlanUpdate};
2526

2627
#[cfg(feature = "unstable_mcp_over_acp")]
2728
use super::mcp::{
@@ -31,7 +32,7 @@ use super::mcp::{
3132
};
3233

3334
#[cfg(feature = "unstable_nes")]
34-
use crate::{ClientNesCapabilities, PositionEncodingKind};
35+
use super::{ClientNesCapabilities, PositionEncodingKind};
3536

3637
// Session updates
3738

@@ -2281,7 +2282,7 @@ mod tests {
22812282

22822283
assert_eq!(
22832284
serde_json::to_value(SessionUpdate::AgentMessageChunk(ContentChunk::new(
2284-
ContentBlock::Text(crate::TextContent::new("Hello"))
2285+
ContentBlock::Text(crate::v1::TextContent::new("Hello"))
22852286
)))
22862287
.unwrap(),
22872288
json!({
@@ -2295,7 +2296,7 @@ mod tests {
22952296

22962297
assert_eq!(
22972298
serde_json::to_value(SessionUpdate::AgentMessageChunk(
2298-
ContentChunk::new(ContentBlock::Text(crate::TextContent::new("Hello")))
2299+
ContentChunk::new(ContentBlock::Text(crate::v1::TextContent::new("Hello")))
22992300
.message_id("msg_agent_c42b9")
23002301
))
23012302
.unwrap(),
@@ -2388,15 +2389,16 @@ mod tests {
23882389
fn test_plan_operations_serialization() {
23892390
use serde_json::json;
23902391

2391-
let plan_update =
2392-
SessionUpdate::PlanUpdate(PlanUpdate::new(crate::PlanUpdateContent::items(
2393-
"plan-1",
2394-
vec![crate::PlanEntry::new(
2395-
"Step 1",
2396-
crate::PlanEntryPriority::High,
2397-
crate::PlanEntryStatus::Pending,
2398-
)],
2399-
)));
2392+
use crate::v1::{PlanEntry, PlanEntryPriority, PlanEntryStatus, PlanUpdateContent};
2393+
2394+
let plan_update = SessionUpdate::PlanUpdate(PlanUpdate::new(PlanUpdateContent::items(
2395+
"plan-1",
2396+
vec![PlanEntry::new(
2397+
"Step 1",
2398+
PlanEntryPriority::High,
2399+
PlanEntryStatus::Pending,
2400+
)],
2401+
)));
24002402

24012403
assert_eq!(
24022404
serde_json::to_value(plan_update).unwrap(),

agent-client-protocol-schema/src/v1/content.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use schemars::JsonSchema;
1313
use serde::{Deserialize, Serialize};
1414
use serde_with::{DefaultOnError, VecSkipError, serde_as, skip_serializing_none};
1515

16-
use crate::{IntoOption, Meta, SkipListener};
16+
use crate::{IntoOption, SkipListener};
17+
18+
use super::Meta;
1719

1820
/// Content blocks represent displayable information in the Agent Client Protocol.
1921
///

agent-client-protocol-schema/src/v1/elicitation.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use schemars::JsonSchema;
1212
use serde::{Deserialize, Serialize};
1313
use serde_with::{DefaultOnError, serde_as, skip_serializing_none};
1414

15-
use crate::{
16-
ELICITATION_COMPLETE_NOTIFICATION, ELICITATION_CREATE_METHOD_NAME, IntoOption, Meta, RequestId,
17-
SessionId, ToolCallId,
15+
use crate::IntoOption;
16+
17+
use super::{
18+
ELICITATION_COMPLETE_NOTIFICATION, ELICITATION_CREATE_METHOD_NAME, Meta, RequestId, SessionId,
19+
ToolCallId,
1820
};
1921

2022
/// **UNSTABLE**
@@ -1729,7 +1731,7 @@ mod tests {
17291731
/// concrete `CreateElicitationResponse` type.
17301732
#[test]
17311733
fn client_response_serialization_accept() {
1732-
use crate::ClientResponse;
1734+
use crate::v1::ClientResponse;
17331735

17341736
let resp = ClientResponse::CreateElicitationResponse(CreateElicitationResponse::new(
17351737
ElicitationAction::Accept(ElicitationAcceptAction::new().content(BTreeMap::from([(
@@ -1748,7 +1750,7 @@ mod tests {
17481750

17491751
#[test]
17501752
fn client_response_serialization_decline() {
1751-
use crate::ClientResponse;
1753+
use crate::v1::ClientResponse;
17521754

17531755
let resp = ClientResponse::CreateElicitationResponse(CreateElicitationResponse::new(
17541756
ElicitationAction::Decline,
@@ -1762,7 +1764,7 @@ mod tests {
17621764

17631765
#[test]
17641766
fn client_response_serialization_cancel() {
1765-
use crate::ClientResponse;
1767+
use crate::v1::ClientResponse;
17661768

17671769
let resp = ClientResponse::CreateElicitationResponse(CreateElicitationResponse::new(
17681770
ElicitationAction::Cancel,

agent-client-protocol-schema/src/v1/mcp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use serde::{Deserialize, Serialize};
88
use serde_json::value::RawValue;
99
use serde_with::skip_serializing_none;
1010

11-
use crate::{IntoOption, McpServerAcpId, Meta};
11+
use crate::IntoOption;
12+
13+
use super::{McpServerAcpId, Meta};
1214

1315
/// **UNSTABLE**
1416
///

agent-client-protocol-schema/src/v1/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod plan;
1616
mod protocol_level;
1717
mod tool_call;
1818

19-
pub use crate::rpc::{JsonRpcMessage, Notification, Request, RequestId};
19+
pub use crate::rpc::{JsonRpcBatch, JsonRpcMessage, Notification, Request, RequestId};
2020
pub use agent::*;
2121
pub use client::*;
2222
pub use content::*;

agent-client-protocol-schema/src/v1/nes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use schemars::JsonSchema;
88
use serde::{Deserialize, Serialize};
99
use serde_with::{DefaultOnError, VecSkipError, serde_as, skip_serializing_none};
1010

11-
use crate::{IntoOption, Meta, SessionId, SkipListener};
11+
use crate::{IntoOption, SkipListener};
12+
13+
use super::{Meta, SessionId};
1214

1315
// Method name constants
1416

0 commit comments

Comments
 (0)