Skip to main content

systemprompt_models/events/payloads/
a2a.rs

1//! A2A event payload shapes.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8use systemprompt_identifiers::{ArtifactId, ContextId, MessageId, TaskId};
9
10use crate::a2a::{Artifact, TaskState};
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct TaskSubmittedPayload {
15    pub task_id: TaskId,
16    pub context_id: ContextId,
17    pub agent_name: String,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    // JSON: A2A `Message` input as sent by the client.
20    pub input: Option<Value>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct TaskStatusUpdatePayload {
26    pub task_id: TaskId,
27    pub context_id: ContextId,
28    pub state: TaskState,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub message: Option<String>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub struct ArtifactCreatedPayload {
36    pub task_id: TaskId,
37    pub context_id: ContextId,
38    pub artifact: Artifact,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase")]
43pub struct ArtifactUpdatedPayload {
44    pub task_id: TaskId,
45    pub context_id: ContextId,
46    pub artifact_id: ArtifactId,
47    pub append: bool,
48    pub last_chunk: bool,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    // JSON: A2A `Part` content as emitted by the agent.
51    pub content: Option<Value>,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct AgentMessagePayload {
57    pub task_id: TaskId,
58    pub context_id: ContextId,
59    pub message_id: MessageId,
60    pub content: String,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(rename_all = "camelCase")]
65pub struct InputRequiredPayload {
66    pub task_id: TaskId,
67    pub context_id: ContextId,
68    pub prompt: String,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(rename_all = "camelCase")]
73pub struct AuthRequiredPayload {
74    pub task_id: TaskId,
75    pub context_id: ContextId,
76    pub auth_url: String,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct JsonRpcResponsePayload {
82    // JSON: A2A JSON-RPC 2.0 envelope (`id` may be a string or a number).
83    pub id: Value,
84    // JSON: A2A JSON-RPC 2.0 envelope (`id` may be a string or a number).
85    pub result: Value,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(rename_all = "camelCase")]
90pub struct JsonRpcErrorPayload {
91    // JSON: A2A JSON-RPC 2.0 envelope (`id` may be a string or a number).
92    pub id: Value,
93    pub code: i32,
94    pub message: String,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    // JSON: A2A `DataPart.data` is spec-defined as a free-form object.
97    pub data: Option<Value>,
98}