llm_kernel/lib.rs
1#![deny(missing_docs)]
2//! # llm-kernel
3//!
4//! Foundation library for Rust AI-native applications.
5//!
6//! Provides a composable, feature-gated set of modules for building
7//! LLM-powered tools, agents, and servers:
8//!
9//! | Feature | Module | Description |
10//! |---------------|-------------|-----------------------------------------------------|
11//! | `provider` | [`provider`] | Provider catalog, model descriptors, pricing — **default** |
12//! | `client-async`| [`llm`] | Async LLM client (OpenAI, Anthropic) with SSE streaming |
13//! | `discovery` | [`discovery`] | Dynamic model discovery (models.dev, Ollama, OpenAI-compat) |
14//! | `secrets` | [`secrets`] | SecretVault — dotenv-style credential management |
15//! | `store` | [`store`] | SQLite init helpers (WAL, PRAGMA, schema versioning) |
16//! | `config` | [`config`] | TOML config loader with auto-create from template |
17//! | `graph` | [`graph`] | Knowledge graph — SQLite, FTS5, smart recall, BFS traversal |
18//! | `mcp` | [`mcp`] | MCP server framework — JSON-RPC 2.0, stdio transport |
19//! | `tokens` | [`tokens`] | Token estimation with Unicode-script heuristics |
20//! | `install` | [`install`] | AI tool installation wizard (Claude, Cursor, Copilot, etc.) |
21//! | `search` | [`search`] | Hybrid search with Reciprocal Rank Fusion |
22//! | `embedding` | [`embedding`] | Embedding provider trait + cosine similarity |
23//! | `telemetry` | [`telemetry`] | Telemetry framework — enum-gated events, no PII |
24//! | `safety` | [`safety`] | Secret masking, error classification, output sanitization |
25//! | `dlp` | [`dlp`] | Data-loss prevention — content scan, provider data policy |
26//!
27//! ## Quick start
28//!
29//! The [`prelude`] module re-exports the most commonly used types:
30//!
31//! ```no_run
32//! use llm_kernel::prelude::*;
33//! ```
34
35// `embedding-fastembed` (static ONNX Runtime archive) and
36// `embedding-fastembed-dynamic-linking` (runtime `libonnxruntime.{so,dll,dylib}`
37// load) are mutually exclusive. Enabling both unifies `ort-download-binaries-*`
38// and `ort-load-dynamic` on the shared `fastembed`/`ort-sys` crate, which makes
39// ort-sys skip the static-archive download and silently expect a runtime dylib
40// llm-kernel never ships — the original #50/#55 failure mode. Force a hard
41// build error so the conflict can never be silent. See `Cargo.toml` feature
42// docs and #55.
43#[cfg(all(
44 feature = "embedding-fastembed",
45 feature = "embedding-fastembed-dynamic-linking"
46))]
47compile_error!(
48 "embedding-fastembed and embedding-fastembed-dynamic-linking are mutually exclusive \
49 (static vs dynamic ONNX Runtime linking). Enabling both triggers Cargo feature \
50 unification that silently disables the static link path (#50/#55). Enable exactly one."
51);
52
53// Every reqwest-backed feature needs a TLS crypto provider. reqwest 0.13's
54// `rustls` feature pins aws-lc-rs (needs cmake/nasm to cross-compile); the
55// `rustls-ring` feature swaps in the ring provider (#93) — no cmake/nasm,
56// a plain C compiler suffices (ring still builds some C/assembly). Without
57// one of them the build succeeds but reqwest panics at runtime when the
58// first client is built — force a hard build error instead.
59#[cfg(all(
60 any(
61 feature = "client-async",
62 feature = "discovery-async",
63 feature = "elastic"
64 ),
65 not(any(feature = "rustls-aws-lc-rs", feature = "rustls-ring"))
66))]
67compile_error!(
68 "client-async / discovery-async / elastic require a TLS provider feature: \
69 enable `rustls-aws-lc-rs` (default; aws-lc-rs needs a C toolchain) or \
70 `rustls-ring` (no cmake/nasm — a plain C compiler suffices). \
71 With default-features = false you must add one of them explicitly."
72);
73
74// Enabling both unifies reqwest to `rustls` + `rustls-no-provider`, where the
75// aws-lc-rs feature silently wins and `rustls-ring` is ignored. Reject it.
76#[cfg(all(feature = "rustls-ring", feature = "rustls-aws-lc-rs"))]
77compile_error!("rustls-ring and rustls-aws-lc-rs are mutually exclusive; enable exactly one.");
78
79/// TLS provider bootstrap (`rustls-ring`). Internal.
80pub(crate) mod tls;
81
82/// Error types and result alias for llm-kernel.
83pub mod error;
84
85#[cfg(feature = "provider")]
86pub mod provider;
87
88#[cfg(feature = "discovery")]
89pub mod discovery;
90
91#[cfg(feature = "secrets")]
92pub mod secrets;
93
94#[cfg(feature = "client-async")]
95pub mod llm;
96
97#[cfg(feature = "store")]
98pub mod store;
99
100#[cfg(feature = "config")]
101pub mod config;
102
103#[cfg(feature = "graph")]
104pub mod graph;
105
106#[cfg(feature = "mcp")]
107pub mod mcp;
108
109#[cfg(feature = "tokens")]
110pub mod tokens;
111
112#[cfg(feature = "install")]
113pub mod install;
114
115#[cfg(feature = "search")]
116pub mod search;
117
118#[cfg(any(feature = "embedding", feature = "embedding-openai"))]
119pub mod embedding;
120
121#[cfg(feature = "telemetry")]
122pub mod telemetry;
123
124#[cfg(feature = "safety")]
125pub mod safety;
126
127#[cfg(feature = "dlp")]
128pub mod dlp;
129
130pub mod prelude;
131
132/// Returns the crate name (`"llm-kernel"`).
133pub fn name() -> &'static str {
134 "llm-kernel"
135}
136
137/// Returns the crate version (from `Cargo.toml`).
138pub fn version() -> &'static str {
139 env!("CARGO_PKG_VERSION")
140}