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 session: Option<String>,
37 pub default_channel: Option<String>,
42 pub unread_direct_messages: i64,
44 pub open_claimed_tasks: i64,
46}
47
48#[derive(Debug, Serialize, JsonSchema)]
51pub struct AgentInfo {
52 pub name: String,
53 pub display_name: Option<String>,
54 #[serde(skip_serializing_if = "Option::is_none", default)]
66 pub session: Option<String>,
67 pub status: String,
70 pub repo: Option<String>,
71 pub branch: Option<String>,
72 pub activity: Option<String>,
74 pub last_seen: Option<String>,
75 pub online: bool,
77 #[serde(skip_serializing_if = "Vec::is_empty", default)]
82 pub sessions: Vec<AgentSession>,
83}
84
85#[derive(Debug, Serialize, JsonSchema)]
87pub struct AgentSession {
88 #[serde(skip_serializing_if = "Option::is_none", default)]
90 pub session: Option<String>,
91 pub status: String,
92 pub repo: Option<String>,
93 pub branch: Option<String>,
94 pub activity: Option<String>,
95 pub last_seen: Option<String>,
96 pub online: bool,
97}
98
99#[derive(Debug, Serialize, JsonSchema)]
100pub struct AgentList {
101 pub agents: Vec<AgentInfo>,
102 pub online_count: usize,
104}
105
106#[derive(Debug, Serialize, JsonSchema)]
109pub struct ChannelInfo {
110 pub name: String,
111 pub topic: Option<String>,
112 pub message_count: i64,
113 pub created_at: String,
114}
115
116#[derive(Debug, Serialize, JsonSchema)]
117pub struct ChannelList {
118 pub channels: Vec<ChannelInfo>,
119}
120
121#[derive(Debug, Serialize, JsonSchema)]
122pub struct MessageInfo {
123 pub id: i64,
124 pub from: String,
125 pub from_session: Option<String>,
129 pub announce: bool,
133 pub channel: Option<String>,
135 pub to: Option<String>,
137 pub to_session: Option<String>,
141 pub body: String,
142 pub reply_to: Option<i64>,
143 #[schemars(schema_with = "any_json_schema")]
144 pub metadata: serde_json::Value,
145 pub attachments: Vec<AttachmentMeta>,
147 pub created_at: String,
148}
149
150#[derive(Debug, Serialize, serde::Deserialize, JsonSchema)]
151pub struct AttachmentMeta {
152 pub id: i64,
154 pub filename: String,
155 pub content_type: String,
156 pub size_bytes: i64,
157}
158
159#[derive(Debug, Serialize, JsonSchema)]
160pub struct AttachmentContent {
161 pub id: i64,
162 pub filename: String,
163 pub content_type: String,
164 pub size_bytes: i64,
165 pub uploaded_by: String,
166 pub created_at: String,
167 pub data_base64: String,
169}
170
171#[derive(Debug, Serialize, JsonSchema)]
172pub struct PostMessageResult {
173 pub message: MessageInfo,
174 pub delivered_to: Vec<String>,
176}
177
178#[derive(Debug, Serialize, JsonSchema)]
179pub struct MessageList {
180 pub messages: Vec<MessageInfo>,
181 pub scope: String,
183 pub cursor: i64,
186 pub truncated: bool,
188}
189
190#[derive(Debug, Serialize, JsonSchema)]
193pub struct TaskInfo {
194 pub key: String,
195 pub title: String,
196 pub description: Option<String>,
197 pub status: String,
199 pub depends_on: Vec<String>,
201 pub blocked: bool,
204 pub claimed_by: Option<String>,
205 pub claimed_session: Option<String>,
209 pub claimed_at: Option<String>,
210 pub lease_expires_at: Option<String>,
213 pub lease_seconds_remaining: Option<i64>,
216 pub lease_expired: bool,
218 pub result: Option<String>,
219 #[schemars(schema_with = "any_json_schema")]
220 pub metadata: serde_json::Value,
221 pub attachments: Vec<AttachmentMeta>,
223 pub created_by: Option<String>,
224 pub created_at: String,
225 pub updated_at: String,
226}
227
228#[derive(Debug, Serialize, JsonSchema)]
229pub struct TaskList {
230 pub tasks: Vec<TaskInfo>,
231 pub open: i64,
232 pub claimed: i64,
233}
234
235#[derive(Debug, Serialize, JsonSchema)]
236pub struct ClaimResult {
237 pub claimed: bool,
238 pub task: Option<TaskInfo>,
239 pub reason: Option<String>,
241}
242
243#[derive(Debug, Serialize, JsonSchema)]
244pub struct TaskEventInfo {
245 pub event: String,
246 pub agent: Option<String>,
247 pub detail: Option<String>,
248 pub created_at: String,
249}
250
251#[derive(Debug, Serialize, JsonSchema)]
252pub struct TaskDetail {
253 pub task: TaskInfo,
254 pub history: Vec<TaskEventInfo>,
255}
256
257#[derive(Debug, Serialize, JsonSchema)]
260pub struct NoteInfo {
261 pub scope: String,
262 pub key: String,
263 pub value: String,
264 pub tags: Vec<String>,
265 pub updated_by: Option<String>,
266 pub updated_at: String,
267}
268
269#[derive(Debug, Serialize, JsonSchema)]
270pub struct NoteList {
271 pub notes: Vec<NoteInfo>,
272}
273
274#[derive(Debug, Serialize, JsonSchema)]
275pub struct NoteRef {
276 pub scope: String,
277 pub key: String,
278 pub found: bool,
279 pub note: Option<NoteInfo>,
280}
281
282#[derive(Debug, Serialize, JsonSchema)]
283pub struct Ack {
284 pub ok: bool,
285 pub detail: String,
286}
287
288#[derive(Debug, Serialize, JsonSchema)]
291pub struct LockInfo {
292 pub name: String,
293 pub holder: String,
294 pub holder_session: Option<String>,
298 pub purpose: Option<String>,
299 pub acquired_at: String,
300 pub expires_at: String,
302}
303
304#[derive(Debug, Serialize, JsonSchema)]
305pub struct LockList {
306 pub locks: Vec<LockInfo>,
307}
308
309#[derive(Debug, Serialize, JsonSchema)]
310pub struct LockResult {
311 pub acquired: bool,
312 pub lock: Option<LockInfo>,
313 pub reason: Option<String>,
315}
316
317#[derive(Debug, Serialize, JsonSchema)]
320pub struct WaitEvent {
321 pub kind: String,
323 pub summary: String,
325}
326
327#[derive(Debug, Serialize, JsonSchema)]
328pub struct WaitResult {
329 pub woke: bool,
331 pub timed_out: bool,
332 pub events: Vec<WaitEvent>,
333 pub unread_direct_messages: i64,
335 pub suggestion: String,
337}
338
339#[derive(Debug, Serialize, JsonSchema)]
340pub struct AskResult {
341 pub answered: bool,
343 pub to: String,
345 pub question_message_id: i64,
348 pub answer: Option<MessageInfo>,
351 pub suggestion: String,
353}
354
355#[derive(Debug, Serialize, JsonSchema)]
358pub struct DigestMessage {
359 pub from: String,
360 pub body: String,
361 pub at: String,
362}
363
364#[derive(Debug, Serialize, JsonSchema)]
365pub struct DigestChannel {
366 pub name: String,
367 pub message_count: i64,
368 pub last_messages: Vec<DigestMessage>,
369}
370
371#[derive(Debug, Serialize, JsonSchema)]
372pub struct DigestTask {
373 pub key: String,
374 pub title: String,
375 pub status: String,
376 pub claimed_by: Option<String>,
377 pub result: Option<String>,
378 pub updated_at: String,
379}
380
381#[derive(Debug, Serialize, JsonSchema)]
382pub struct DigestNote {
383 pub scope: String,
384 pub key: String,
385 pub updated_by: Option<String>,
386 pub updated_at: String,
387}
388
389#[derive(Debug, Serialize, JsonSchema)]
390pub struct DigestAgent {
391 pub name: String,
392 pub activity: Option<String>,
393 pub last_seen: Option<String>,
394 pub online: bool,
395}
396
397#[derive(Debug, Serialize, JsonSchema)]
398pub struct DigestResult {
399 pub hours: i64,
401 pub channels: Vec<DigestChannel>,
402 pub tasks_moved: Vec<DigestTask>,
404 pub open_tasks: i64,
405 pub claimed_tasks: i64,
406 pub notes_updated: Vec<DigestNote>,
407 pub agents_seen: Vec<DigestAgent>,
408 pub active_locks: Vec<LockInfo>,
409}