Skip to main content

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    #[must_use]
34    pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
35        Self {
36            method: method.into(),
37            params,
38        }
39    }
40}
41
42/// Allows for sending an arbitrary response to an [`ExtRequest`] that is not part of the ACP spec.
43/// Extension methods provide a way to add custom functionality while maintaining
44/// protocol compatibility.
45///
46/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
47#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, From)]
48#[serde(transparent)]
49#[non_exhaustive]
50pub struct ExtResponse(#[schemars(with = "serde_json::Value")] pub Arc<RawValue>);
51
52impl ExtResponse {
53    #[must_use]
54    pub fn new(params: Arc<RawValue>) -> Self {
55        Self(params)
56    }
57}
58
59/// Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
60/// Extension notifications provide a way to send one-way messages for custom functionality
61/// while maintaining protocol compatibility.
62///
63/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
64#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
65#[serde(transparent)]
66#[non_exhaustive]
67pub struct ExtNotification {
68    #[serde(skip)] // this is used for routing, but when serializing we only want the params
69    pub method: Arc<str>,
70    #[schemars(with = "serde_json::Value")]
71    pub params: Arc<RawValue>,
72}
73
74impl ExtNotification {
75    #[must_use]
76    pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
77        Self {
78            method: method.into(),
79            params,
80        }
81    }
82}