1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use sha2::{Digest, Sha256};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum TrustLevel {
9 UserAuthored,
10 UntrustedExternal,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct AccountSummary {
17 pub id: String,
18 pub name: String,
19 pub folder_count: usize,
20 pub note_count: usize,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct FolderSummary {
25 pub id: String,
26 pub name: String,
27 pub path: String,
28 pub account: String,
29 pub note_count: usize,
30 #[serde(default)]
31 pub subfolder_count: usize,
32 pub allowed_by_policy: bool,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct NotesOverview {
37 pub schema_version: String,
38 pub profile: String,
39 pub total_accounts: usize,
40 pub total_folders: usize,
41 pub total_notes: usize,
42 pub hidden_by_policy_folders: usize,
43 pub accounts: Vec<AccountSummary>,
44 pub folders: Vec<FolderSummary>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct NoteSummary {
49 pub id: String,
50 pub title: String,
51 pub account: String,
52 pub folder: String,
53 #[serde(default)]
54 pub folder_path: String,
55 pub created_at: Option<String>,
56 pub modified_at: Option<String>,
57 pub password_protected: bool,
58 pub attachment_count: usize,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct FidelityInfo {
63 pub has_attachments: bool,
64 pub has_tables: bool,
65 pub has_checklists: bool,
66 pub has_internal_links: bool,
67 pub has_images: bool,
68 pub safe_mutations: Vec<String>,
69 pub blocked_mutations: Vec<String>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct NoteDetail {
74 pub schema_version: String,
75 pub id: String,
76 pub title: String,
77 pub account: String,
78 pub folder: String,
79 pub folder_path: String,
80 pub created_at: Option<String>,
81 pub modified_at: Option<String>,
82 pub revision: String,
83 pub trust_level: TrustLevel,
84 pub password_protected: bool,
85 pub attachment_count: usize,
86 pub fidelity: FidelityInfo,
87 pub redactions: BTreeMap<String, usize>,
88 pub truncated: bool,
89 pub body_text: String,
90 #[serde(skip_serializing_if = "Option::is_none")]
91 pub body_html: Option<String>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct DuplicateTitleGroup {
96 pub normalized_title: String,
97 pub count: usize,
98 pub notes: Vec<NoteSummary>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct NotesAuditReport {
103 pub schema_version: String,
104 pub profile: String,
105 pub total_folders_scanned: usize,
106 pub total_notes_scanned: usize,
107 pub empty_folders: Vec<FolderSummary>,
108 pub single_note_folders: Vec<FolderSummary>,
109 pub duplicate_folder_names: BTreeMap<String, Vec<String>>,
110 pub duplicate_titles: Vec<DuplicateTitleGroup>,
111 pub oldest_unmodified_notes: Vec<NoteSummary>,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct MailAccountSummary {
118 pub id: String,
119 pub name: String,
120 pub email_addresses: Vec<String>,
121 pub mailbox_count: usize,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct MailboxSummary {
126 pub name: String,
127 pub account: String,
128 pub unread_count: usize,
129 pub message_count: usize,
130 pub allowed_by_policy: bool,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct MailSignature {
135 pub name: String,
136 pub content_preview: String,
137 pub char_count: usize,
138}
139
140#[derive(Debug, Clone, Serialize, Deserialize)]
141pub struct MailOverview {
142 pub schema_version: String,
143 pub profile: String,
144 pub total_accounts: usize,
145 pub total_mailboxes: usize,
146 pub total_unread: usize,
147 pub accounts: Vec<MailAccountSummary>,
148 pub mailboxes: Vec<MailboxSummary>,
149 pub signatures: Vec<MailSignature>,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct MailMessageSummary {
154 pub id: String,
156 pub local_id: String,
157 pub rfc_message_id: Option<String>,
158 pub account: String,
159 pub mailbox: String,
160 pub subject: String,
161 pub sender: String,
162 pub date_received: Option<String>,
163 pub read: bool,
164 pub flagged: bool,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct MailMessageDetail {
169 pub schema_version: String,
170 pub id: String,
171 pub local_id: String,
172 pub rfc_message_id: Option<String>,
173 pub account: String,
174 pub mailbox: String,
175 pub subject: String,
176 pub sender: String,
177 pub to: Vec<String>,
178 pub cc: Vec<String>,
179 pub date_received: Option<String>,
180 pub read: bool,
181 pub flagged: bool,
182 pub revision: String,
183 pub trust_level: TrustLevel,
184 pub content_warning: String,
185 pub redactions: BTreeMap<String, usize>,
186 pub truncated: bool,
187 pub body_text: String,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct CalendarEvent {
194 pub calendar: String,
195 pub title: String,
196 pub start_at: Option<String>,
197 pub end_at: Option<String>,
198 pub all_day: bool,
199 #[serde(skip_serializing_if = "Option::is_none")]
200 pub location: Option<String>,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize)]
204pub struct ReminderItem {
205 pub list: String,
206 pub title: String,
207 pub due_at: Option<String>,
208 pub overdue: bool,
209 pub priority: u8,
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
215pub struct ShortcutSummary {
216 pub name: String,
217 pub allowed_by_policy: bool,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct ShortcutsListResult {
222 pub schema_version: String,
223 pub profile: String,
224 pub total: usize,
225 pub allowed_count: usize,
226 pub shortcuts: Vec<ShortcutSummary>,
227}
228
229#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct ContactSummary {
233 pub id: String,
234 pub name: String,
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub organization: Option<String>,
237 pub emails: Vec<String>,
238 pub phones: Vec<String>,
239}
240
241#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct ContactsListResult {
243 pub schema_version: String,
244 pub total_matched: usize,
245 pub returned: usize,
246 pub contacts: Vec<ContactSummary>,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize)]
250pub struct ContactsAuditReport {
251 pub schema_version: String,
252 pub total_contacts: usize,
253 pub duplicate_names: BTreeMap<String, usize>,
254 pub duplicate_emails: BTreeMap<String, Vec<String>>,
255 pub empty_contacts: Vec<ContactSummary>,
256}
257
258#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct SafariTab {
262 pub window_index: usize,
263 pub tab_index: usize,
264 pub title: String,
265 pub url: String,
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
269pub struct SafariTabsResult {
270 pub schema_version: String,
271 pub total_tabs: usize,
272 pub tabs: Vec<SafariTab>,
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize)]
278pub struct DailyBrief {
279 pub schema_version: String,
280 pub profile: String,
281 pub generated_at_unix: u64,
282 pub upcoming_events: Vec<CalendarEvent>,
283 pub open_reminders: Vec<ReminderItem>,
284 pub unread_mail_count: usize,
285 pub unread_mails: Vec<MailMessageSummary>,
286 pub recent_notes: Vec<NoteSummary>,
287 pub warnings: Vec<String>,
288}
289
290#[derive(Debug, Clone, Serialize, Deserialize)]
291pub struct PersonContext {
292 pub schema_version: String,
293 pub profile: String,
294 pub query: String,
295 pub generated_at_unix: u64,
296 pub contacts: Vec<ContactSummary>,
297 pub recent_mails: Vec<MailMessageSummary>,
298 pub matching_notes: Vec<NoteSummary>,
299 pub upcoming_events: Vec<CalendarEvent>,
300 pub open_reminders: Vec<ReminderItem>,
301 pub warnings: Vec<String>,
302}
303
304#[derive(Debug, Clone, Serialize, Deserialize)]
305pub struct MeetingPrepContext {
306 pub schema_version: String,
307 pub profile: String,
308 pub query: String,
309 pub generated_at_unix: u64,
310 pub target_event: Option<CalendarEvent>,
311 pub related_contacts: Vec<ContactSummary>,
312 pub related_mails: Vec<MailMessageSummary>,
313 pub related_notes: Vec<NoteSummary>,
314 pub warnings: Vec<String>,
315}
316
317#[derive(Debug, Clone, Serialize, Deserialize)]
318pub struct WeeklyReviewContext {
319 pub schema_version: String,
320 pub profile: String,
321 pub generated_at_unix: u64,
322 pub recent_notes: Vec<NoteSummary>,
323 pub unread_mails: Vec<MailMessageSummary>,
324 pub overdue_reminders: Vec<ReminderItem>,
325 pub upcoming_events: Vec<CalendarEvent>,
326 pub open_safari_tabs: Vec<SafariTab>,
327 pub warnings: Vec<String>,
328}
329
330pub fn compute_revision_hash(input: &str) -> String {
331 let mut hasher = Sha256::new();
332 hasher.update(input.as_bytes());
333 let digest = hasher.finalize();
334 let hex: String = digest.iter().map(|b| format!("{b:02x}")).collect();
335 format!("sha256:{}", &hex[..16])
336}
337
338pub fn compute_sha256_hex(input: &str) -> String {
339 let mut hasher = Sha256::new();
340 hasher.update(input.as_bytes());
341 let digest = hasher.finalize();
342 digest.iter().map(|b| format!("{b:02x}")).collect()
343}