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