Skip to main content

car_integrations/
lib.rs

1//! Account-bound integrations for Common Agent Runtime: Calendar, Contacts,
2//! Mail, Messages.
3//!
4//! The logical capabilities are the same on every OS; the backends are
5//! not. v1 defines the release contract — stable return shapes that carry
6//! explicit `available` + `backend` fields so downstream apps can branch
7//! cleanly while backends light up incrementally.
8//!
9//! # Backends (target)
10//!
11//! | OS      | Calendar                  | Contacts                  | Mail                 | Messages                    |
12//! |---------|---------------------------|---------------------------|----------------------|-----------------------------|
13//! | macOS   | EventKit (EKEventStore)   | Contacts.framework         | Mail.app automation  | Messages.app automation     |
14//! | Windows | MS Graph + Outlook MAPI   | Windows.Contacts + Graph   | MS Graph + MAPI      | Not modeled                 |
15//! | Linux   | Evolution DS + CalDAV     | Evolution DS + CardDAV     | Evolution DS + IMAP  | Not modeled                 |
16//!
17//! Backends return Unavailable-with-reason so callers can distinguish missing
18//! OS configuration, denied TCC access, and unmodeled platforms.
19//!
20//! # Dependencies (and honest gaps)
21//!
22//! Full operation needs:
23//! - **car-secrets** — where credentials and tokens live
24//! - **car-accounts** — to know which account the call should be bound to
25//! - **car-permissions** — to preflight OS consent before the side effect
26//!
27//! The macOS backends compose these where the OS exposes a useful native
28//! surface; other platforms are still modeled but not fully implemented.
29
30use serde::{Deserialize, Serialize};
31use thiserror::Error;
32
33pub mod apple;
34pub mod calendar;
35pub mod contacts;
36pub mod mail;
37pub mod messages;
38
39/// Availability envelope — returned from every list-ish method so callers
40/// can branch on `available` instead of assuming a populated list.
41///
42/// **Flatten caution.** This struct is `#[serde(flatten)]`ed into every
43/// listing payload (see `CalendarListing`, `ContactListing`, etc.). Do not
44/// add fields with names that collide with payload fields. `#[non_exhaustive]`
45/// to keep future additions additive.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[non_exhaustive]
48pub struct Availability {
49    /// True if the backend returned real data.
50    pub available: bool,
51    /// Backend that was attempted (`"eventkit"`, `"msgraph"`, `"eds"`, ...).
52    pub backend: String,
53    /// When `available` is false, human-readable explanation.
54    pub reason: Option<String>,
55}
56
57impl Availability {
58    pub fn pending(backend: &'static str, reason: impl Into<String>) -> Self {
59        Self {
60            available: false,
61            backend: backend.to_string(),
62            reason: Some(reason.into()),
63        }
64    }
65
66    pub fn available(backend: &'static str) -> Self {
67        Self {
68            available: true,
69            backend: backend.to_string(),
70            reason: None,
71        }
72    }
73}
74
75#[derive(Debug, Error)]
76pub enum IntegrationError {
77    #[error("backend not available: {0}")]
78    Unavailable(String),
79    #[error("integration backend error: {0}")]
80    Backend(String),
81    #[error("not yet implemented: {0}")]
82    NotImplemented(&'static str),
83}