rightkit_agent_engine_protocol/
message.rs1use crate::references::ReferenceMeta;
2use crate::refs::OutputRef;
3use crate::tool::ToolCall;
4use crate::trust::TrustEnvelope;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(tag = "$kind")]
13pub enum TranscriptMessage {
14 #[serde(rename = "system", rename_all = "camelCase")]
15 System {
16 id: String,
17 created_at: String,
18 content: String,
19 pinned: bool,
20 },
21
22 #[serde(rename = "user", rename_all = "camelCase")]
23 User {
24 id: String,
25 created_at: String,
26 content: String,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
28 trust: Option<TrustEnvelope>,
29 pinned: bool,
30 #[serde(default, skip_serializing_if = "Vec::is_empty")]
39 attachments: Vec<ReferenceMeta>,
40 },
41
42 #[serde(rename = "assistant", rename_all = "camelCase")]
43 Assistant {
44 id: String,
45 created_at: String,
46 content: String,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 reasoning_content: Option<String>,
49 #[serde(default, skip_serializing_if = "Vec::is_empty")]
50 tool_calls: Vec<ToolCall>,
51 pinned: bool,
52 },
53
54 #[serde(rename = "tool", rename_all = "camelCase")]
57 Tool {
58 id: String,
59 created_at: String,
60 tool_call_id: String,
61 summary: String,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 output: Option<OutputRef>,
64 #[serde(default, skip_serializing_if = "Option::is_none")]
65 trust: Option<TrustEnvelope>,
66 is_error: bool,
67 pinned: bool,
68 #[serde(default, skip_serializing_if = "Option::is_none")]
69 process_id: Option<String>,
70 },
71
72 #[serde(rename = "compact", rename_all = "camelCase")]
75 Compact {
76 id: String,
77 created_at: String,
78 summary: String,
79 dropped_count: i32,
80 pinned: bool,
81 },
82
83 #[serde(rename = "fold", rename_all = "camelCase")]
87 Fold {
88 id: String,
89 created_at: String,
90 subtask_id: String,
91 summary: String,
92 dropped_count: i32,
93 archive_ref: String,
95 pinned: bool,
96 },
97}
98
99impl TranscriptMessage {
100 pub fn set_id(&mut self, value: String) {
105 match self {
106 Self::System { id, .. }
107 | Self::User { id, .. }
108 | Self::Assistant { id, .. }
109 | Self::Tool { id, .. }
110 | Self::Compact { id, .. }
111 | Self::Fold { id, .. } => *id = value,
112 }
113 }
114
115 pub fn id(&self) -> &str {
117 match self {
118 Self::System { id, .. }
119 | Self::User { id, .. }
120 | Self::Assistant { id, .. }
121 | Self::Tool { id, .. }
122 | Self::Compact { id, .. }
123 | Self::Fold { id, .. } => id.as_str(),
124 }
125 }
126
127 pub fn created_at(&self) -> &str {
129 match self {
130 Self::System { created_at, .. }
131 | Self::User { created_at, .. }
132 | Self::Assistant { created_at, .. }
133 | Self::Tool { created_at, .. }
134 | Self::Compact { created_at, .. }
135 | Self::Fold { created_at, .. } => created_at.as_str(),
136 }
137 }
138
139 pub fn user(
144 id: impl Into<String>,
145 created_at: impl Into<String>,
146 content: impl Into<String>,
147 trust: Option<TrustEnvelope>,
148 pinned: bool,
149 ) -> Self {
150 Self::User {
151 id: id.into(),
152 created_at: created_at.into(),
153 content: content.into(),
154 trust,
155 pinned,
156 attachments: Vec::new(),
157 }
158 }
159
160 pub fn user_with_attachments(
165 id: impl Into<String>,
166 created_at: impl Into<String>,
167 content: impl Into<String>,
168 trust: Option<TrustEnvelope>,
169 pinned: bool,
170 attachments: Vec<ReferenceMeta>,
171 ) -> Self {
172 Self::User {
173 id: id.into(),
174 created_at: created_at.into(),
175 content: content.into(),
176 trust,
177 pinned,
178 attachments,
179 }
180 }
181
182 pub fn is_provider_visible(&self) -> bool {
183 match self {
184 Self::Tool { output, .. } => output
185 .as_ref()
186 .map(|output| output.kind != crate::refs::TOOL_OUTPUT_INTERNAL_KIND)
187 .unwrap_or(true),
188 _ => true,
189 }
190 }
191
192 pub fn user_attachments(&self) -> &[ReferenceMeta] {
196 match self {
197 Self::User { attachments, .. } => attachments.as_slice(),
198 _ => &[],
199 }
200 }
201
202 pub fn into_user_attachments(self) -> Vec<ReferenceMeta> {
206 match self {
207 Self::User { attachments, .. } => attachments,
208 _ => Vec::new(),
209 }
210 }
211}