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)]
59 pub session: Option<String>,
60 pub status: String,
63 pub repo: Option<String>,
64 pub branch: Option<String>,
65 pub activity: Option<String>,
67 pub last_seen: Option<String>,
68 pub online: bool,
70 #[serde(skip_serializing_if = "Vec::is_empty", default)]
75 pub sessions: Vec<AgentSession>,
76}
77
78#[derive(Debug, Serialize, JsonSchema)]
80pub struct AgentSession {
81 #[serde(skip_serializing_if = "Option::is_none", default)]
83 pub session: Option<String>,
84 pub status: String,
85 pub repo: Option<String>,
86 pub branch: Option<String>,
87 pub activity: Option<String>,
88 pub last_seen: Option<String>,
89 pub online: bool,
90}
91
92#[derive(Debug, Serialize, JsonSchema)]
93pub struct AgentList {
94 pub agents: Vec<AgentInfo>,
95 pub online_count: usize,
97}
98
99#[derive(Debug, Serialize, JsonSchema)]
102pub struct ChannelInfo {
103 pub name: String,
104 pub topic: Option<String>,
105 pub message_count: i64,
106 pub created_at: String,
107}
108
109#[derive(Debug, Serialize, JsonSchema)]
110pub struct ChannelList {
111 pub channels: Vec<ChannelInfo>,
112}
113
114#[derive(Debug, Serialize, JsonSchema)]
115pub struct MessageInfo {
116 pub id: i64,
117 pub from: String,
118 pub from_session: Option<String>,
122 pub announce: bool,
126 pub channel: Option<String>,
128 pub to: Option<String>,
130 pub to_session: Option<String>,
134 pub body: String,
135 pub reply_to: Option<i64>,
136 #[schemars(schema_with = "any_json_schema")]
137 pub metadata: serde_json::Value,
138 pub attachments: Vec<AttachmentMeta>,
140 pub created_at: String,
141}
142
143#[derive(Debug, Serialize, serde::Deserialize, JsonSchema)]
144pub struct AttachmentMeta {
145 pub id: i64,
147 pub filename: String,
148 pub content_type: String,
149 pub size_bytes: i64,
150}
151
152#[derive(Debug, Serialize, JsonSchema)]
153pub struct AttachmentContent {
154 pub id: i64,
155 pub filename: String,
156 pub content_type: String,
157 pub size_bytes: i64,
158 pub uploaded_by: String,
159 pub created_at: String,
160 pub data_base64: String,
162}
163
164#[derive(Debug, Serialize, JsonSchema)]
165pub struct PostMessageResult {
166 pub message: MessageInfo,
167 pub delivered_to: Vec<String>,
169}
170
171#[derive(Debug, Serialize, JsonSchema)]
172pub struct MessageList {
173 pub messages: Vec<MessageInfo>,
174 pub scope: String,
176 pub cursor: i64,
179 pub truncated: bool,
181}
182
183#[derive(Debug, Serialize, JsonSchema)]
186pub struct TaskInfo {
187 pub key: String,
188 pub title: String,
189 pub description: Option<String>,
190 pub status: String,
192 pub depends_on: Vec<String>,
194 pub blocked: bool,
197 pub claimed_by: Option<String>,
198 pub claimed_session: Option<String>,
202 pub claimed_at: Option<String>,
203 pub lease_expires_at: Option<String>,
206 pub lease_seconds_remaining: Option<i64>,
209 pub lease_expired: bool,
211 pub result: Option<String>,
212 #[schemars(schema_with = "any_json_schema")]
213 pub metadata: serde_json::Value,
214 pub attachments: Vec<AttachmentMeta>,
216 pub created_by: Option<String>,
217 pub created_at: String,
218 pub updated_at: String,
219}
220
221#[derive(Debug, Serialize, JsonSchema)]
222pub struct TaskList {
223 pub tasks: Vec<TaskInfo>,
224 pub open: i64,
225 pub claimed: i64,
226}
227
228#[derive(Debug, Serialize, JsonSchema)]
229pub struct ClaimResult {
230 pub claimed: bool,
231 pub task: Option<TaskInfo>,
232 pub reason: Option<String>,
234}
235
236#[derive(Debug, Serialize, JsonSchema)]
237pub struct TaskEventInfo {
238 pub event: String,
239 pub agent: Option<String>,
240 pub detail: Option<String>,
241 pub created_at: String,
242}
243
244#[derive(Debug, Serialize, JsonSchema)]
245pub struct TaskDetail {
246 pub task: TaskInfo,
247 pub history: Vec<TaskEventInfo>,
248}
249
250#[derive(Debug, Serialize, JsonSchema)]
253pub struct NoteInfo {
254 pub scope: String,
255 pub key: String,
256 pub value: String,
257 pub tags: Vec<String>,
258 pub updated_by: Option<String>,
259 pub updated_at: String,
260}
261
262#[derive(Debug, Serialize, JsonSchema)]
263pub struct NoteList {
264 pub notes: Vec<NoteInfo>,
265}
266
267#[derive(Debug, Serialize, JsonSchema)]
268pub struct NoteRef {
269 pub scope: String,
270 pub key: String,
271 pub found: bool,
272 pub note: Option<NoteInfo>,
273}
274
275#[derive(Debug, Serialize, JsonSchema)]
276pub struct Ack {
277 pub ok: bool,
278 pub detail: String,
279}
280
281#[derive(Debug, Serialize, JsonSchema)]
284pub struct LockInfo {
285 pub name: String,
286 pub holder: String,
287 pub holder_session: Option<String>,
291 pub purpose: Option<String>,
292 pub acquired_at: String,
293 pub expires_at: String,
295}
296
297#[derive(Debug, Serialize, JsonSchema)]
298pub struct LockList {
299 pub locks: Vec<LockInfo>,
300}
301
302#[derive(Debug, Serialize, JsonSchema)]
303pub struct LockResult {
304 pub acquired: bool,
305 pub lock: Option<LockInfo>,
306 pub reason: Option<String>,
308}
309
310#[derive(Debug, Serialize, JsonSchema)]
313pub struct WaitEvent {
314 pub kind: String,
316 pub summary: String,
318}
319
320#[derive(Debug, Serialize, JsonSchema)]
321pub struct WaitResult {
322 pub woke: bool,
324 pub timed_out: bool,
325 pub events: Vec<WaitEvent>,
326 pub unread_direct_messages: i64,
328 pub suggestion: String,
330}
331
332#[derive(Debug, Serialize, JsonSchema)]
333pub struct AskResult {
334 pub answered: bool,
336 pub to: String,
338 pub question_message_id: i64,
341 pub answer: Option<MessageInfo>,
344 pub suggestion: String,
346}
347
348#[derive(Debug, Serialize, JsonSchema)]
351pub struct DigestMessage {
352 pub from: String,
353 pub body: String,
354 pub at: String,
355}
356
357#[derive(Debug, Serialize, JsonSchema)]
358pub struct DigestChannel {
359 pub name: String,
360 pub message_count: i64,
361 pub last_messages: Vec<DigestMessage>,
362}
363
364#[derive(Debug, Serialize, JsonSchema)]
365pub struct DigestTask {
366 pub key: String,
367 pub title: String,
368 pub status: String,
369 pub claimed_by: Option<String>,
370 pub result: Option<String>,
371 pub updated_at: String,
372}
373
374#[derive(Debug, Serialize, JsonSchema)]
375pub struct DigestNote {
376 pub scope: String,
377 pub key: String,
378 pub updated_by: Option<String>,
379 pub updated_at: String,
380}
381
382#[derive(Debug, Serialize, JsonSchema)]
383pub struct DigestAgent {
384 pub name: String,
385 pub activity: Option<String>,
386 pub last_seen: Option<String>,
387 pub online: bool,
388}
389
390#[derive(Debug, Serialize, JsonSchema)]
391pub struct DigestResult {
392 pub hours: i64,
394 pub channels: Vec<DigestChannel>,
395 pub tasks_moved: Vec<DigestTask>,
397 pub open_tasks: i64,
398 pub claimed_tasks: i64,
399 pub notes_updated: Vec<DigestNote>,
400 pub agents_seen: Vec<DigestAgent>,
401 pub active_locks: Vec<LockInfo>,
402}