agent_client_protocol/
content.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
5#[serde(tag = "type", rename_all = "snake_case")]
6pub enum ContentBlock {
7    Text(TextContent),
8    Image(ImageContent),
9    Audio(AudioContent),
10    ResourceLink(ResourceLink),
11    Resource(EmbeddedResource),
12}
13
14/// Text provided to or from an LLM.
15#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
16pub struct TextContent {
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub annotations: Option<Annotations>,
19    pub text: String,
20}
21
22impl<T: Into<String>> From<T> for ContentBlock {
23    fn from(value: T) -> Self {
24        Self::Text(TextContent {
25            annotations: None,
26            text: value.into(),
27        })
28    }
29}
30
31/// An image provided to or from an LLM.
32#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
33pub struct ImageContent {
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub annotations: Option<Annotations>,
36    pub data: String,
37    #[serde(rename = "mimeType")]
38    pub mime_type: String,
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub uri: Option<String>,
41}
42
43/// Audio provided to or from an LLM.
44#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
45pub struct AudioContent {
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub annotations: Option<Annotations>,
48    pub data: String,
49    #[serde(rename = "mimeType")]
50    pub mime_type: String,
51}
52
53/// The contents of a resource, embedded into a prompt or tool call result.
54///
55/// It is up to the client how best to render embedded resources for the benefit
56/// of the LLM and/or the user.
57#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
58pub struct EmbeddedResource {
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub annotations: Option<Annotations>,
61    pub resource: EmbeddedResourceResource,
62}
63
64#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
65#[serde(untagged)]
66pub enum EmbeddedResourceResource {
67    TextResourceContents(TextResourceContents),
68    BlobResourceContents(BlobResourceContents),
69}
70
71#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
72pub struct TextResourceContents {
73    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
74    pub mime_type: Option<String>,
75    pub text: String,
76    pub uri: String,
77}
78
79#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
80pub struct BlobResourceContents {
81    pub blob: String,
82    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
83    pub mime_type: Option<String>,
84    pub uri: String,
85}
86
87/// A resource that the server is capable of reading, included in a prompt or tool call result.
88///
89/// Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
90#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
91pub struct ResourceLink {
92    #[serde(default, skip_serializing_if = "Option::is_none")]
93    pub annotations: Option<Annotations>,
94    #[serde(default, skip_serializing_if = "Option::is_none")]
95    pub description: Option<String>,
96    #[serde(rename = "mimeType", default, skip_serializing_if = "Option::is_none")]
97    pub mime_type: Option<String>,
98    pub name: String,
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub size: Option<i64>,
101    #[serde(default, skip_serializing_if = "Option::is_none")]
102    pub title: Option<String>,
103    pub uri: String,
104}
105
106/// Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
107#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
108pub struct Annotations {
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    pub audience: Option<Vec<Role>>,
111    #[serde(
112        rename = "lastModified",
113        default,
114        skip_serializing_if = "Option::is_none"
115    )]
116    pub last_modified: Option<String>,
117    #[serde(default, skip_serializing_if = "Option::is_none")]
118    pub priority: Option<f64>,
119}
120
121/// The sender or recipient of messages and data in a conversation.
122#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
123pub enum Role {
124    #[serde(rename = "assistant")]
125    Assistant,
126    #[serde(rename = "user")]
127    User,
128}