Skip to main content

a2a_protocol_types/generated/
message.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3// @generated by tools/a2a-codegen from proto/a2a_v1/a2a.proto,
4// sha256 e195bf96ab630c69797851970203e1b2b6b19528f2e9803b7d904b91a5104016.
5// Included by the `message` module. Do not edit: change the proto or
6// crates/a2a-protocol-types/codegen.toml and regenerate (ADR 0016).
7
8/// Defines the sender of a message in A2A protocol communication.
9///
10/// On the wire each role is its `ProtoJSON` name (`"ROLE_USER"`, spec §5.5); the
11/// v0.3 lowercase spellings are accepted on input.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
13#[non_exhaustive]
14pub enum MessageRole {
15    /// The role is unspecified.
16    #[serde(rename = "ROLE_UNSPECIFIED", alias = "unspecified")]
17    Unspecified = 0,
18    /// The message is from the client to the server.
19    #[serde(rename = "ROLE_USER", alias = "user")]
20    User = 1,
21    /// The message is from the server to the client.
22    #[serde(rename = "ROLE_AGENT", alias = "agent")]
23    Agent = 2,
24}
25
26/// `Part` represents a container for a section of communication content.
27/// Parts can be purely textual, some sort of file (image, video, etc) or
28/// a structured data blob (i.e. JSON).
29///
30/// On the wire the member that is set names the content, beside the other
31/// fields, and `Deserialize` is written by hand, beside this type, to read
32/// them in one pass:
33///
34/// ```json
35/// {"text": "hello"}
36/// {"raw": "base64data", "filename": "f.png", "mediaType": "image/png"}
37/// {"url": "https://example.com/f.pdf", "filename": "f.pdf", "mediaType": "application/pdf"}
38/// {"data": {"key": "value"}, "mediaType": "application/json"}
39/// ```
40#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
41#[serde(rename_all = "camelCase")]
42#[non_exhaustive]
43pub struct Part {
44    /// The content of this part (text, raw, url, or data).
45    #[serde(flatten)]
46    pub content: crate::message::PartContent,
47    /// Optional. metadata associated with this part.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub metadata: Option<serde_json::Value>,
50    /// An optional `filename` for the file (e.g., "document.pdf").
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub filename: Option<String>,
53    /// The `media_type` (MIME type) of the part content (e.g., "text/plain", "application/json", "image/png").
54    /// This field is available for all part types.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub media_type: Option<String>,
57}
58
59/// The content of a [`Part`], discriminated by JSON member name per v1.0 spec.
60///
61/// In JSON, the member name determines the variant:
62/// - `"text"` → text string content
63/// - `"raw"` → base64-encoded bytes
64/// - `"url"` → URL pointing to content
65/// - `"data"` → structured JSON data
66#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
67#[serde(rename_all = "camelCase")]
68#[non_exhaustive]
69pub enum PartContent {
70    /// The string content of the `text` part.
71    Text(String),
72    /// The `raw` byte content of a file. In JSON serialization, this is encoded as a base64 string.
73    Raw(String),
74    /// A `url` pointing to the file's content.
75    Url(String),
76    /// Arbitrary structured `data` as a JSON value (object, array, string, number, boolean, or null).
77    Data(serde_json::Value),
78}
79
80/// `Message` is one unit of communication between client and server.
81///
82/// It can be
83/// associated with a context and/or a task. For server messages, `context_id` must
84/// be provided, and `task_id` only if a task was created. For client messages, both
85/// fields are optional, with the caveat that if both are provided, they have to
86/// match (the `context_id` has to be the one that is set on the task). If only
87/// `task_id` is provided, the server will infer `context_id` from it.
88#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
89#[serde(rename_all = "camelCase")]
90#[non_exhaustive]
91pub struct Message {
92    /// The unique identifier (e.g. UUID) of the message. This is created by the message creator.
93    #[serde(rename = "messageId", alias = "message_id")]
94    pub id: crate::message::MessageId,
95    /// Optional. The context id of the message. If set, the message will be associated with the given context.
96    #[serde(alias = "context_id", skip_serializing_if = "Option::is_none")]
97    pub context_id: Option<crate::task::ContextId>,
98    /// Optional. The task id of the message. If set, the message will be associated with the given task.
99    #[serde(alias = "task_id", skip_serializing_if = "Option::is_none")]
100    pub task_id: Option<crate::task::TaskId>,
101    /// Identifies the sender of the message.
102    pub role: crate::message::MessageRole,
103    /// Parts is the container of the message content.
104    ///
105    /// **Spec requirement:** Must contain at least one element. The A2A
106    /// protocol does not define behavior for empty parts lists.
107    ///
108    /// Parsing treats absence as empty (`ProtoJSON` printers omit empty
109    /// repeated fields; the gRPC binding already decodes it that way) — the
110    /// server rejects empty parts with a structured invalid-params error
111    /// instead of a JSON type error, uniformly across bindings.
112    #[serde(default)]
113    pub parts: Vec<crate::message::Part>,
114    /// Optional. Any metadata to provide along with the message.
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub metadata: Option<serde_json::Value>,
117    /// The URIs of extensions that are present or contributed to this Message.
118    #[serde(skip_serializing_if = "Option::is_none")]
119    pub extensions: Option<Vec<String>>,
120    /// A list of task IDs that this message references for additional context.
121    #[serde(alias = "reference_task_ids", skip_serializing_if = "Option::is_none")]
122    pub reference_task_ids: Option<Vec<crate::task::TaskId>>,
123}