Skip to main content

systemprompt_agent/models/a2a/protocol/
events.rs

1use crate::models::a2a::{Artifact, TaskStatus};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
5#[serde(rename_all = "camelCase")]
6pub struct TaskStatusUpdateEvent {
7    pub kind: String,
8    pub task_id: String,
9    pub context_id: String,
10    pub status: TaskStatus,
11    #[serde(rename = "final")]
12    pub is_final: bool,
13}
14
15impl TaskStatusUpdateEvent {
16    pub fn new(
17        task_id: impl Into<String>,
18        context_id: impl Into<String>,
19        status: TaskStatus,
20        is_final: bool,
21    ) -> Self {
22        Self {
23            kind: "status-update".to_string(),
24            task_id: task_id.into(),
25            context_id: context_id.into(),
26            status,
27            is_final,
28        }
29    }
30
31    pub fn to_jsonrpc_response(&self) -> serde_json::Value {
32        serde_json::json!({
33            "jsonrpc": "2.0",
34            "result": self
35        })
36    }
37}
38
39#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
40#[serde(rename_all = "camelCase")]
41pub struct TaskArtifactUpdateEvent {
42    pub kind: String,
43    pub task_id: String,
44    pub context_id: String,
45    pub artifact: Artifact,
46    #[serde(rename = "final")]
47    pub is_final: bool,
48}
49
50impl TaskArtifactUpdateEvent {
51    pub fn new(
52        task_id: impl Into<String>,
53        context_id: impl Into<String>,
54        artifact: Artifact,
55        is_final: bool,
56    ) -> Self {
57        Self {
58            kind: "artifact-update".to_string(),
59            task_id: task_id.into(),
60            context_id: context_id.into(),
61            artifact,
62            is_final,
63        }
64    }
65
66    pub fn to_jsonrpc_response(&self) -> serde_json::Value {
67        serde_json::json!({
68            "jsonrpc": "2.0",
69            "result": self
70        })
71    }
72}