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;
38pub mod msgraph;
39
40/// Availability envelope — returned from every list-ish method so callers
41/// can branch on `available` instead of assuming a populated list.
42///
43/// **Flatten caution.** This struct is `#[serde(flatten)]`ed into every
44/// listing payload (see `CalendarListing`, `ContactListing`, etc.). Do not
45/// add fields with names that collide with payload fields. `#[non_exhaustive]`
46/// to keep future additions additive.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[non_exhaustive]
49pub struct Availability {
50    /// True if the backend returned real data.
51    pub available: bool,
52    /// Backend that was attempted (`"eventkit"`, `"msgraph"`, `"eds"`, ...).
53    pub backend: String,
54    /// When `available` is false, human-readable explanation.
55    pub reason: Option<String>,
56}
57
58impl Availability {
59    pub fn pending(backend: &'static str, reason: impl Into<String>) -> Self {
60        Self {
61            available: false,
62            backend: backend.to_string(),
63            reason: Some(reason.into()),
64        }
65    }
66
67    pub fn available(backend: &'static str) -> Self {
68        Self {
69            available: true,
70            backend: backend.to_string(),
71            reason: None,
72        }
73    }
74}
75
76#[derive(Debug, Error)]
77pub enum IntegrationError {
78    #[error("backend not available: {0}")]
79    Unavailable(String),
80    #[error("integration backend error: {0}")]
81    Backend(String),
82    #[error("not yet implemented: {0}")]
83    NotImplemented(&'static str),
84}