Skip to main content

mailrs_intelligence/
lib.rs

1#![deny(missing_docs)]
2#![deny(rustdoc::broken_intra_doc_links)]
3
4//! Email intelligence primitives — LLM-powered analysis with a pluggable provider.
5//!
6//! `mailrs-intelligence` extracts the five analysis modules from the
7//! `mailrs` mail server:
8//!
9//! - [`analyze`] — full email analysis (category, summary, entities, intent)
10//! - [`spam`]    — spam classification with an optional cache
11//! - [`importance`] — heuristic importance scoring (no LLM)
12//! - [`structured`] — JSON-LD / Microdata extraction from HTML (no LLM)
13//! - [`provider`] — the [`LlmProvider`] trait + an OpenAI-compatible reference impl
14//!
15//! # Why a trait
16//!
17//! Mail servers tend to mix cheap small-core inference (for hot paths like
18//! per-message classification) with occasional big-core calls (for rare,
19//! high-value structured extraction). Letting analysis functions take
20//! `&dyn LlmProvider` keeps that choice **visible at the call site**: every
21//! consumer can grep their own code for "which provider do I pass into
22//! `analyze_email`?" without diving into config.
23//!
24//! # Quickstart
25//!
26//! ```no_run
27//! use mailrs_intelligence::{OpenAiCompatibleProvider, analyze::analyze_email};
28//!
29//! # async fn run() -> Option<()> {
30//! let provider = OpenAiCompatibleProvider::new(
31//!     "http://llm.example.com/complete".into(),
32//!     Some("sk-…".into()),
33//!     "qwen3.5-9b/v8".into(),
34//! );
35//!
36//! let analysis = analyze_email(
37//!     &provider,
38//!     "boss@example.com",
39//!     "Q3 review",
40//!     "Please send your Q3 self-review by Friday.",
41//! )
42//! .await?;
43//!
44//! println!("category={} requires_action={}", analysis.category, analysis.requires_action);
45//! # Some(())
46//! # }
47//! ```
48//!
49//! # Feature flags
50//!
51//! - `http` (default) — enables [`OpenAiCompatibleProvider`], the reqwest-backed
52//!   reference [`LlmProvider`].
53//! - `kevy-cache` (default) — enables [`spam::KevySpamCache`], a Kevy-backed
54//!   [`spam::SpamCache`] implementation. Disable if you cache yourself or run
55//!   without a cache.
56//!
57//! Disable both default features if you're plugging in your own backends.
58
59pub mod analyze;
60pub mod importance;
61/// Pluggable LLM provider trait (currently Claude / Ollama implementations).
62pub mod provider;
63pub mod spam;
64/// Schema.org JSON-LD extraction from HTML message bodies.
65pub mod structured;
66
67#[cfg(feature = "http")]
68mod openai_compatible;
69
70pub use provider::LlmProvider;
71
72#[cfg(feature = "http")]
73pub use openai_compatible::OpenAiCompatibleProvider;