Skip to main content

agent_client_protocol_schema/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! [![Agent Client Protocol](https://zed.dev/img/acp/banner-dark.webp)](https://agentclientprotocol.com/)
4//!
5//! # Agent Client Protocol Schema
6//!
7//! Strongly-typed Rust definitions of the Agent Client Protocol (ACP) wire
8//! format. ACP is a JSON-RPC based protocol that standardizes communication
9//! between code editors (IDEs, text-editors, etc.) and coding agents
10//! (programs that use generative AI to autonomously modify code).
11//!
12//! This crate is **only** the schema: the request, response, and
13//! notification types, plus serde plumbing and JSON Schema generation. For
14//! the runtime pieces (transport, connection setup, the `Agent` / `Client`
15//! traits, etc.) use the higher-level [`agent-client-protocol`] crate, which
16//! builds on top of these types.
17//!
18//! [`agent-client-protocol`]: https://crates.io/crates/agent-client-protocol
19//!
20//! ## What's in this crate
21//!
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
30//!   crates to dispatch incoming JSON-RPC messages.
31//!
32//! ## Versioning
33//!
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.
37//!
38//! For the complete protocol specification and documentation, visit
39//! <https://agentclientprotocol.com>.
40
41pub mod rpc;
42mod serde_util;
43pub mod v1;
44#[cfg(feature = "unstable_protocol_v2")]
45pub mod v2;
46mod version;
47
48pub(crate) use serde_util::SkipListener;
49pub use serde_util::{IntoMaybeUndefined, IntoOption, MaybeUndefined};
50pub use version::*;
51
52#[cfg(test)]
53mod serde_json_feature_tests {
54    use serde_json::Value;
55
56    #[test]
57    fn serde_json_values_preserve_object_key_order() {
58        let Value::Object(object) =
59            serde_json::from_str::<Value>(r#"{"z":1,"a":2,"m":3}"#).unwrap()
60        else {
61            panic!("expected JSON object");
62        };
63
64        let keys = object.keys().map(String::as_str).collect::<Vec<_>>();
65        assert_eq!(keys, ["z", "a", "m"]);
66    }
67}