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