protocol_droid/adapters/secondary/acp/reply.rs
1//! `AcpReply` — the raw JSON-RPC 2.0 reply shape.
2//!
3//! # Why the peer carries a raw reply, not a typed one
4//!
5//! The peer is the transport layer. It does not
6//! know that the wire's `result` field for an
7//! `initialize` call is a typed
8//! [`InitializeResponse`](crate::domain::acp::initialize::InitializeResponse);
9//! the consumer is the one that deserialises the
10//! raw `serde_json::Value` into the concrete type
11//! the method returns. This is the same shape the
12//! protocol-neutral core's
13//! [`Envelope`](crate::domain::jsonrpc::envelope::Envelope)
14//! has: the wire is bytes, the consumer is the
15//! decoder.
16//!
17//! The peer's job is to *return* the value the
18//! agent sent. The consumer decodes.
19
20use serde::Deserialize;
21
22/// A JSON-RPC 2.0 reply: the agent's answer to a
23/// request.
24///
25/// The wire form has either a `result` (success)
26/// or an `error` (failure), never both, never
27/// neither. The typed form is the same: a
28/// `Result<AcpReply, AcpPeerError>` from the
29/// peer's `send_request` already encodes the
30/// success/failure split. The peer's
31/// [`JsonRpc`](super::error::AcpPeerError::JsonRpc)
32/// variant is the failure case, so the
33/// `AcpReply` value the consumer receives is
34/// always the success case.
35#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
36#[serde(deny_unknown_fields)]
37pub struct AcpReply {
38 /// The reply's JSON-RPC 2.0 protocol field.
39 /// Always `"2.0"`. Carried through the
40 /// decoder as a sanity check on the agent's
41 /// framing; the peer does not act on it.
42 pub jsonrpc: String,
43 /// The id the request carried. The peer
44 /// uses the id to correlate; the consumer
45 /// does not need to look at it.
46 pub id: serde_json::Value,
47 /// The success result. The shape depends
48 /// on the method; the peer does not
49 /// decode it.
50 pub result: serde_json::Value,
51}