agent_client_protocol_schema/
ext.rs

1//! Extension types and constants for protocol extensibility.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use serde_json::value::RawValue;
6use std::sync::Arc;
7
8#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
9#[serde(transparent)]
10#[schemars(with = "serde_json::Value")]
11#[non_exhaustive]
12pub struct ExtRequest {
13    #[serde(skip)] // this is used for routing, but when serializing we only want the params
14    pub method: Arc<str>,
15    pub params: Arc<RawValue>,
16}
17
18impl ExtRequest {
19    pub fn new(method: impl Into<Arc<str>>, params: impl Into<Arc<RawValue>>) -> Self {
20        Self {
21            method: method.into(),
22            params: params.into(),
23        }
24    }
25}
26
27pub type ExtResponse = Arc<RawValue>;
28
29#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
30#[serde(transparent)]
31#[schemars(with = "serde_json::Value")]
32#[non_exhaustive]
33pub struct ExtNotification {
34    #[serde(skip)] // this is used for routing, but when serializing we only want the params
35    pub method: Arc<str>,
36    pub params: Arc<RawValue>,
37}
38
39impl ExtNotification {
40    pub fn new(method: impl Into<Arc<str>>, params: impl Into<Arc<RawValue>>) -> Self {
41        Self {
42            method: method.into(),
43            params: params.into(),
44        }
45    }
46}