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/// Allows for sending an arbitrary request that is not part of the ACP spec.
9/// Extension methods provide a way to add custom functionality while maintaining
10/// protocol compatibility.
11///
12/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
13#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
14#[serde(transparent)]
15#[non_exhaustive]
16pub struct ExtRequest {
17 #[serde(skip)] // this is used for routing, but when serializing we only want the params
18 pub method: Arc<str>,
19 #[schemars(with = "serde_json::Value")]
20 pub params: Arc<RawValue>,
21}
22
23impl ExtRequest {
24 pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
25 Self {
26 method: method.into(),
27 params,
28 }
29 }
30}
31
32/// Allows for sending an arbitrary response to an [`ExtRequest`] that is not part of the ACP spec.
33/// Extension methods provide a way to add custom functionality while maintaining
34/// protocol compatibility.
35///
36/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
37#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, From)]
38#[serde(transparent)]
39#[non_exhaustive]
40pub struct ExtResponse(#[schemars(with = "serde_json::Value")] pub Arc<RawValue>);
41
42impl ExtResponse {
43 #[must_use]
44 pub fn new(params: Arc<RawValue>) -> Self {
45 Self(params)
46 }
47}
48
49/// Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
50/// Extension notifications provide a way to send one-way messages for custom functionality
51/// while maintaining protocol compatibility.
52///
53/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
54#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
55#[serde(transparent)]
56#[non_exhaustive]
57pub struct ExtNotification {
58 #[serde(skip)] // this is used for routing, but when serializing we only want the params
59 pub method: Arc<str>,
60 #[schemars(with = "serde_json::Value")]
61 pub params: Arc<RawValue>,
62}
63
64impl ExtNotification {
65 pub fn new(method: impl Into<Arc<str>>, params: Arc<RawValue>) -> Self {
66 Self {
67 method: method.into(),
68 params,
69 }
70 }
71}