1use schemars::JsonSchema;
8use serde::Serialize;
9
10pub fn any_json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
14 schemars::json_schema!({})
15}
16
17pub fn ts(dt: chrono::DateTime<chrono::Utc>) -> String {
18 dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
19}
20
21pub fn ts_opt(dt: Option<chrono::DateTime<chrono::Utc>>) -> Option<String> {
22 dt.map(ts)
23}
24
25#[derive(Debug, Serialize, JsonSchema)]
26pub struct WhoAmI {
27 pub agent: String,
29 pub agent_id: String,
30 pub team: String,
31 pub team_id: String,
32 pub unread_direct_messages: i64,
34 pub open_claimed_tasks: i64,
36}
37
38#[derive(Debug, Serialize, JsonSchema)]
41pub struct AgentInfo {
42 pub name: String,
43 pub display_name: Option<String>,
44 pub status: String,
47 pub repo: Option<String>,
48 pub branch: Option<String>,
49 pub activity: Option<String>,
51 pub last_seen: Option<String>,
52 pub online: bool,
53}
54
55#[derive(Debug, Serialize, JsonSchema)]
56pub struct AgentList {
57 pub agents: Vec<AgentInfo>,
58 pub online_count: usize,
59}
60
61#[derive(Debug, Serialize, JsonSchema)]
64pub struct ChannelInfo {
65 pub name: String,
66 pub topic: Option<String>,
67 pub message_count: i64,
68 pub created_at: String,
69}
70
71#[derive(Debug, Serialize, JsonSchema)]
72pub struct ChannelList {
73 pub channels: Vec<ChannelInfo>,
74}
75
76#[derive(Debug, Serialize, JsonSchema)]
77pub struct MessageInfo {
78 pub id: i64,
79 pub from: String,
80 pub channel: Option<String>,
82 pub to: Option<String>,
84 pub body: String,
85 pub reply_to: Option<i64>,
86 #[schemars(schema_with = "any_json_schema")]
87 pub metadata: serde_json::Value,
88 pub attachments: Vec<AttachmentMeta>,
90 pub created_at: String,
91}
92
93#[derive(Debug, Serialize, serde::Deserialize, JsonSchema)]
94pub struct AttachmentMeta {
95 pub id: i64,
97 pub filename: String,
98 pub content_type: String,
99 pub size_bytes: i64,
100}
101
102#[derive(Debug, Serialize, JsonSchema)]
103pub struct AttachmentContent {
104 pub id: i64,
105 pub filename: String,
106 pub content_type: String,
107 pub size_bytes: i64,
108 pub uploaded_by: String,
109 pub created_at: String,
110 pub data_base64: String,
112}
113
114#[derive(Debug, Serialize, JsonSchema)]
115pub struct PostMessageResult {
116 pub message: MessageInfo,
117 pub delivered_to: Vec<String>,
119}
120
121#[derive(Debug, Serialize, JsonSchema)]
122pub struct MessageList {
123 pub messages: Vec<MessageInfo>,
124 pub scope: String,
126 pub cursor: i64,
129 pub truncated: bool,
131}
132
133#[derive(Debug, Serialize, JsonSchema)]
136pub struct TaskInfo {
137 pub key: String,
138 pub title: String,
139 pub description: Option<String>,
140 pub status: String,
142 pub depends_on: Vec<String>,
144 pub blocked: bool,
147 pub claimed_by: Option<String>,
148 pub claimed_at: Option<String>,
149 pub lease_expires_at: Option<String>,
152 pub lease_expired: bool,
154 pub result: Option<String>,
155 #[schemars(schema_with = "any_json_schema")]
156 pub metadata: serde_json::Value,
157 pub attachments: Vec<AttachmentMeta>,
159 pub created_by: Option<String>,
160 pub created_at: String,
161 pub updated_at: String,
162}
163
164#[derive(Debug, Serialize, JsonSchema)]
165pub struct TaskList {
166 pub tasks: Vec<TaskInfo>,
167 pub open: i64,
168 pub claimed: i64,
169}
170
171#[derive(Debug, Serialize, JsonSchema)]
172pub struct ClaimResult {
173 pub claimed: bool,
174 pub task: Option<TaskInfo>,
175 pub reason: Option<String>,
177}
178
179#[derive(Debug, Serialize, JsonSchema)]
180pub struct TaskEventInfo {
181 pub event: String,
182 pub agent: Option<String>,
183 pub detail: Option<String>,
184 pub created_at: String,
185}
186
187#[derive(Debug, Serialize, JsonSchema)]
188pub struct TaskDetail {
189 pub task: TaskInfo,
190 pub history: Vec<TaskEventInfo>,
191}
192
193#[derive(Debug, Serialize, JsonSchema)]
196pub struct NoteInfo {
197 pub scope: String,
198 pub key: String,
199 pub value: String,
200 pub tags: Vec<String>,
201 pub updated_by: Option<String>,
202 pub updated_at: String,
203}
204
205#[derive(Debug, Serialize, JsonSchema)]
206pub struct NoteList {
207 pub notes: Vec<NoteInfo>,
208}
209
210#[derive(Debug, Serialize, JsonSchema)]
211pub struct NoteRef {
212 pub scope: String,
213 pub key: String,
214 pub found: bool,
215 pub note: Option<NoteInfo>,
216}
217
218#[derive(Debug, Serialize, JsonSchema)]
219pub struct Ack {
220 pub ok: bool,
221 pub detail: String,
222}
223
224#[derive(Debug, Serialize, JsonSchema)]
227pub struct LockInfo {
228 pub name: String,
229 pub holder: String,
230 pub purpose: Option<String>,
231 pub acquired_at: String,
232 pub expires_at: String,
234}
235
236#[derive(Debug, Serialize, JsonSchema)]
237pub struct LockList {
238 pub locks: Vec<LockInfo>,
239}
240
241#[derive(Debug, Serialize, JsonSchema)]
242pub struct LockResult {
243 pub acquired: bool,
244 pub lock: Option<LockInfo>,
245 pub reason: Option<String>,
247}
248
249#[derive(Debug, Serialize, JsonSchema)]
252pub struct WaitEvent {
253 pub kind: String,
255 pub summary: String,
257}
258
259#[derive(Debug, Serialize, JsonSchema)]
260pub struct WaitResult {
261 pub woke: bool,
263 pub timed_out: bool,
264 pub events: Vec<WaitEvent>,
265 pub unread_direct_messages: i64,
267 pub suggestion: String,
269}
270
271#[derive(Debug, Serialize, JsonSchema)]
272pub struct AskResult {
273 pub answered: bool,
275 pub to: String,
277 pub question_message_id: i64,
280 pub answer: Option<MessageInfo>,
283 pub suggestion: String,
285}
286
287#[derive(Debug, Serialize, JsonSchema)]
290pub struct DigestMessage {
291 pub from: String,
292 pub body: String,
293 pub at: String,
294}
295
296#[derive(Debug, Serialize, JsonSchema)]
297pub struct DigestChannel {
298 pub name: String,
299 pub message_count: i64,
300 pub last_messages: Vec<DigestMessage>,
301}
302
303#[derive(Debug, Serialize, JsonSchema)]
304pub struct DigestTask {
305 pub key: String,
306 pub title: String,
307 pub status: String,
308 pub claimed_by: Option<String>,
309 pub result: Option<String>,
310 pub updated_at: String,
311}
312
313#[derive(Debug, Serialize, JsonSchema)]
314pub struct DigestNote {
315 pub scope: String,
316 pub key: String,
317 pub updated_by: Option<String>,
318 pub updated_at: String,
319}
320
321#[derive(Debug, Serialize, JsonSchema)]
322pub struct DigestAgent {
323 pub name: String,
324 pub activity: Option<String>,
325 pub last_seen: Option<String>,
326 pub online: bool,
327}
328
329#[derive(Debug, Serialize, JsonSchema)]
330pub struct DigestResult {
331 pub hours: i64,
333 pub channels: Vec<DigestChannel>,
334 pub tasks_moved: Vec<DigestTask>,
336 pub open_tasks: i64,
337 pub claimed_tasks: i64,
338 pub notes_updated: Vec<DigestNote>,
339 pub agents_seen: Vec<DigestAgent>,
340 pub active_locks: Vec<LockInfo>,
341}