protocol_droid/domain/jsonrpc/mod.rs
1//! The protocol-neutral JSON-RPC layer.
2//!
3//! # What belongs here
4//!
5//! JSON-RPC 2.0 has no knowledge of MCP, and neither does anything in this
6//! module. The envelope, the id, the error codes, and the decode step are the
7//! same for an MCP session, an A2A session, and an ACP session — which is the
8//! property that lets a later task add a protocol as a feature-gated module
9//! rather than a fork of the transport layer.
10//!
11//! The converse boundary is enforced by the module layout rather than by
12//! discipline: the method table that says `tools/call` exists lives in
13//! [`crate::application::jsonrpc`] as a trait, and its MCP implementation lives
14//! under `adapters`. Nothing here names a method.
15//!
16//! # The two views of a message
17//!
18//! | | Owned | Borrowed |
19//! | --- | --- | --- |
20//! | module | [`crate::domain::ir`] | this one |
21//! | holds | [`crate::domain::ir::IrMessage`] | [`Frame`] |
22//! | costs | an allocation per string id | none |
23//! | used when | a message has to be stored, logged, or replayed | a message is being routed |
24//!
25//! They are not two versions of the same thing and neither replaces the other.
26//! The borrowed view is what the hot path uses, because routing a frame should
27//! not allocate; the owned view is what the session engine and the transports
28//! use, because those keep messages past the life of the read buffer.
29
30pub mod envelope;
31pub mod reply;
32
33pub use envelope::{
34 DecodeError, Envelope, Frame, MessageKind, Method, Outcome, WireError, WireId, WireIdError,
35 decode,
36};
37
38/// Re-exported so this module is the front door for the JSON-RPC concept.
39///
40/// [`crate::domain::RequestId`] and [`crate::domain::ir::IrErrorCode`] predate
41/// this module and are used by the IR, so they are not moved here — a caller
42/// that thinks of "JSON-RPC" should find the id and the codes through the
43/// module that owns the concept, and a caller that is holding an `IrRequest`
44/// should not have to learn a second path to the same type.
45pub use crate::domain::RequestId;
46pub use crate::domain::ir::IrErrorCode;