1use serde::{Deserialize, Serialize};
8
9use crate::JsonObject;
10use crate::event::BaseEvent;
11use crate::ids::{MessageId, SubagentRunId};
12use crate::patch::PatchOperation;
13
14#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
18#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
19pub struct ActivitySnapshotEvent {
20 #[serde(flatten)]
22 pub base: BaseEvent,
23 pub message_id: MessageId,
25 pub activity_type: String,
27 #[cfg_attr(
29 feature = "schemars",
30 schemars(with = "std::collections::BTreeMap<String, serde_json::Value>")
31 )]
32 #[cfg_attr(feature = "utoipa", schema(value_type = Object))]
33 pub content: JsonObject,
34 #[serde(default = "default_replace")]
37 pub replace: bool,
38 #[serde(
41 default,
42 deserialize_with = "crate::serde_util::reject_null",
43 skip_serializing_if = "Option::is_none"
44 )]
45 pub subagent_run_id: Option<SubagentRunId>,
46}
47
48const fn default_replace() -> bool {
51 true
52}
53
54impl Default for ActivitySnapshotEvent {
55 fn default() -> Self {
56 Self {
57 base: BaseEvent::default(),
58 message_id: MessageId::default(),
59 activity_type: String::new(),
60 content: JsonObject::new(),
61 replace: default_replace(),
62 subagent_run_id: None,
63 }
64 }
65}
66
67impl ActivitySnapshotEvent {
68 pub fn new(
70 message_id: impl Into<MessageId>,
71 activity_type: impl Into<String>,
72 content: JsonObject,
73 ) -> Self {
74 Self {
75 base: BaseEvent::default(),
76 message_id: message_id.into(),
77 activity_type: activity_type.into(),
78 content,
79 replace: true,
80 subagent_run_id: None,
81 }
82 }
83}
84
85#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
87#[serde(rename_all = "camelCase")]
88#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
89#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
90pub struct ActivityDeltaEvent {
91 #[serde(flatten)]
93 pub base: BaseEvent,
94 pub message_id: MessageId,
96 pub activity_type: String,
98 pub patch: Vec<PatchOperation>,
100 #[serde(
103 default,
104 deserialize_with = "crate::serde_util::reject_null",
105 skip_serializing_if = "Option::is_none"
106 )]
107 pub subagent_run_id: Option<SubagentRunId>,
108}
109
110impl ActivityDeltaEvent {
111 pub fn new(
113 message_id: impl Into<MessageId>,
114 activity_type: impl Into<String>,
115 patch: impl Into<Vec<PatchOperation>>,
116 ) -> Self {
117 Self {
118 base: BaseEvent::default(),
119 message_id: message_id.into(),
120 activity_type: activity_type.into(),
121 patch: patch.into(),
122 subagent_run_id: None,
123 }
124 }
125}