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