agent_client_protocol_schema/ext.rs
1//! Extension types and constants for protocol extensibility.
2use derive_more::From;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use serde_json::value::RawValue;
6use std::sync::Arc;
7
8/// Value attached to a given ACP type on the `_meta` field.
9///
10/// The _meta property is reserved by ACP to allow clients and agents to attach
11/// additional metadata to their interactions. Implementations MUST NOT make assumptions about
12/// values at these keys.
13///
14/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
15pub type Meta = serde_json::Map<String, serde_json::Value>;
16
17/// Allows for sending an arbitrary request that is not part of the ACP spec.
18/// Extension methods provide a way to add custom functionality while maintaining
19/// protocol compatibility.
20///
21/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
22#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
23#[serde(transparent)]
24#[non_exhaustive]
25pub struct ExtRequest {
26 #[serde(skip)] // this is used for routing, but when serializing we only want the params
27 pub method: Arc<str>,
28 #[schemars(with = "serde_json::Value")]
29 pub params: Arc<RawValue>,
30}
31
32impl ExtRequest {
33 pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
34 Self {
35 method: method.into(),
36 params,
37 }
38 }
39}
40
41/// Allows for sending an arbitrary response to an [`ExtRequest`] that is not part of the ACP spec.
42/// Extension methods provide a way to add custom functionality while maintaining
43/// protocol compatibility.
44///
45/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
46#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, From)]
47#[serde(transparent)]
48#[non_exhaustive]
49pub struct ExtResponse(#[schemars(with = "serde_json::Value")] pub Arc<RawValue>);
50
51impl ExtResponse {
52 #[must_use]
53 pub fn new(params: Arc<RawValue>) -> Self {
54 Self(params)
55 }
56}
57
58/// Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
59/// Extension notifications provide a way to send one-way messages for custom functionality
60/// while maintaining protocol compatibility.
61///
62/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
63#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
64#[serde(transparent)]
65#[non_exhaustive]
66pub struct ExtNotification {
67 #[serde(skip)] // this is used for routing, but when serializing we only want the params
68 pub method: Arc<str>,
69 #[schemars(with = "serde_json::Value")]
70 pub params: Arc<RawValue>,
71}
72
73impl ExtNotification {
74 pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
75 Self {
76 method: method.into(),
77 params,
78 }
79 }
80}