1use schemars::JsonSchema;
8use serde::Serialize;
9
10pub fn ts(dt: chrono::DateTime<chrono::Utc>) -> String {
11 dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
12}
13
14pub fn ts_opt(dt: Option<chrono::DateTime<chrono::Utc>>) -> Option<String> {
15 dt.map(ts)
16}
17
18#[derive(Debug, Serialize, JsonSchema)]
19pub struct WhoAmI {
20 pub agent: String,
22 pub agent_id: String,
23 pub team: String,
24 pub team_id: String,
25 pub unread_direct_messages: i64,
27 pub open_claimed_tasks: i64,
29}
30
31#[derive(Debug, Serialize, JsonSchema)]
34pub struct AgentInfo {
35 pub name: String,
36 pub display_name: Option<String>,
37 pub status: String,
40 pub repo: Option<String>,
41 pub branch: Option<String>,
42 pub activity: Option<String>,
44 pub last_seen: Option<String>,
45 pub online: bool,
46}
47
48#[derive(Debug, Serialize, JsonSchema)]
49pub struct AgentList {
50 pub agents: Vec<AgentInfo>,
51 pub online_count: usize,
52}
53
54#[derive(Debug, Serialize, JsonSchema)]
57pub struct ChannelInfo {
58 pub name: String,
59 pub topic: Option<String>,
60 pub message_count: i64,
61 pub created_at: String,
62}
63
64#[derive(Debug, Serialize, JsonSchema)]
65pub struct ChannelList {
66 pub channels: Vec<ChannelInfo>,
67}
68
69#[derive(Debug, Serialize, JsonSchema)]
70pub struct MessageInfo {
71 pub id: i64,
72 pub from: String,
73 pub channel: Option<String>,
75 pub to: Option<String>,
77 pub body: String,
78 pub reply_to: Option<i64>,
79 pub metadata: serde_json::Value,
80 pub created_at: String,
81}
82
83#[derive(Debug, Serialize, JsonSchema)]
84pub struct PostMessageResult {
85 pub message: MessageInfo,
86 pub delivered_to: Vec<String>,
88}
89
90#[derive(Debug, Serialize, JsonSchema)]
91pub struct MessageList {
92 pub messages: Vec<MessageInfo>,
93 pub scope: String,
95 pub cursor: i64,
98 pub truncated: bool,
100}
101
102#[derive(Debug, Serialize, JsonSchema)]
105pub struct TaskInfo {
106 pub key: String,
107 pub title: String,
108 pub description: Option<String>,
109 pub status: String,
111 pub depends_on: Vec<String>,
113 pub blocked: bool,
116 pub claimed_by: Option<String>,
117 pub claimed_at: Option<String>,
118 pub lease_expires_at: Option<String>,
121 pub lease_expired: bool,
123 pub result: Option<String>,
124 pub metadata: serde_json::Value,
125 pub created_by: Option<String>,
126 pub created_at: String,
127 pub updated_at: String,
128}
129
130#[derive(Debug, Serialize, JsonSchema)]
131pub struct TaskList {
132 pub tasks: Vec<TaskInfo>,
133 pub open: i64,
134 pub claimed: i64,
135}
136
137#[derive(Debug, Serialize, JsonSchema)]
138pub struct ClaimResult {
139 pub claimed: bool,
140 pub task: Option<TaskInfo>,
141 pub reason: Option<String>,
143}
144
145#[derive(Debug, Serialize, JsonSchema)]
146pub struct TaskEventInfo {
147 pub event: String,
148 pub agent: Option<String>,
149 pub detail: Option<String>,
150 pub created_at: String,
151}
152
153#[derive(Debug, Serialize, JsonSchema)]
154pub struct TaskDetail {
155 pub task: TaskInfo,
156 pub history: Vec<TaskEventInfo>,
157}
158
159#[derive(Debug, Serialize, JsonSchema)]
162pub struct NoteInfo {
163 pub scope: String,
164 pub key: String,
165 pub value: String,
166 pub tags: Vec<String>,
167 pub updated_by: Option<String>,
168 pub updated_at: String,
169}
170
171#[derive(Debug, Serialize, JsonSchema)]
172pub struct NoteList {
173 pub notes: Vec<NoteInfo>,
174}
175
176#[derive(Debug, Serialize, JsonSchema)]
177pub struct NoteRef {
178 pub scope: String,
179 pub key: String,
180 pub found: bool,
181 pub note: Option<NoteInfo>,
182}
183
184#[derive(Debug, Serialize, JsonSchema)]
185pub struct Ack {
186 pub ok: bool,
187 pub detail: String,
188}
189
190#[derive(Debug, Serialize, JsonSchema)]
193pub struct LockInfo {
194 pub name: String,
195 pub holder: String,
196 pub purpose: Option<String>,
197 pub acquired_at: String,
198 pub expires_at: String,
200}
201
202#[derive(Debug, Serialize, JsonSchema)]
203pub struct LockList {
204 pub locks: Vec<LockInfo>,
205}
206
207#[derive(Debug, Serialize, JsonSchema)]
208pub struct LockResult {
209 pub acquired: bool,
210 pub lock: Option<LockInfo>,
211 pub reason: Option<String>,
213}
214
215#[derive(Debug, Serialize, JsonSchema)]
218pub struct WaitEvent {
219 pub kind: String,
221 pub summary: String,
223}
224
225#[derive(Debug, Serialize, JsonSchema)]
226pub struct WaitResult {
227 pub woke: bool,
229 pub timed_out: bool,
230 pub events: Vec<WaitEvent>,
231 pub unread_direct_messages: i64,
233 pub suggestion: String,
235}
236
237#[derive(Debug, Serialize, JsonSchema)]
238pub struct AskResult {
239 pub answered: bool,
241 pub to: String,
243 pub question_message_id: i64,
246 pub answer: Option<MessageInfo>,
249 pub suggestion: String,
251}
252
253#[derive(Debug, Serialize, JsonSchema)]
256pub struct DigestMessage {
257 pub from: String,
258 pub body: String,
259 pub at: String,
260}
261
262#[derive(Debug, Serialize, JsonSchema)]
263pub struct DigestChannel {
264 pub name: String,
265 pub message_count: i64,
266 pub last_messages: Vec<DigestMessage>,
267}
268
269#[derive(Debug, Serialize, JsonSchema)]
270pub struct DigestTask {
271 pub key: String,
272 pub title: String,
273 pub status: String,
274 pub claimed_by: Option<String>,
275 pub result: Option<String>,
276 pub updated_at: String,
277}
278
279#[derive(Debug, Serialize, JsonSchema)]
280pub struct DigestNote {
281 pub scope: String,
282 pub key: String,
283 pub updated_by: Option<String>,
284 pub updated_at: String,
285}
286
287#[derive(Debug, Serialize, JsonSchema)]
288pub struct DigestAgent {
289 pub name: String,
290 pub activity: Option<String>,
291 pub last_seen: Option<String>,
292 pub online: bool,
293}
294
295#[derive(Debug, Serialize, JsonSchema)]
296pub struct DigestResult {
297 pub hours: i64,
299 pub channels: Vec<DigestChannel>,
300 pub tasks_moved: Vec<DigestTask>,
302 pub open_tasks: i64,
303 pub claimed_tasks: i64,
304 pub notes_updated: Vec<DigestNote>,
305 pub agents_seen: Vec<DigestAgent>,
306 pub active_locks: Vec<LockInfo>,
307}