briefcase_core/lib.rs
1//! # Briefcase AI Core Library
2//!
3//! High-performance AI observability, replay, and decision tracking for Rust applications.
4//!
5//! ## Features
6//!
7//! - **AI Decision Tracking**: Capture inputs, outputs, and context for every AI decision
8//! - **Deterministic Replay**: Reproduce AI decisions exactly with full context preservation
9//! - **Comprehensive Observability**: Monitor model performance, drift, and behavior
10//! - **Enterprise Security**: Built-in data sanitization and privacy controls
11//! - **Flexible Storage**: SQLite, cloud storage, and custom backends
12//! - **Cost Management**: Track and optimize AI model usage costs
13//! - **Cross-Platform**: Works on Linux, macOS, Windows, and WebAssembly
14//!
15//! ## Quick Start
16//!
17//! ```rust
18//! use briefcase_core::*;
19//! use serde_json::json;
20//!
21//! # #[tokio::main]
22//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
23//! // Create a decision snapshot
24//! let decision = DecisionSnapshot::new("ai_function")
25//! .add_input(Input::new("user_query", json!("Hello world"), "string"))
26//! .add_output(Output::new("response", json!("Hello back!"), "string").with_confidence(0.95))
27//! .with_execution_time(120.5);
28//!
29//! // Save to storage (requires storage feature)
30//! #[cfg(feature = "sqlite-storage")]
31//! {
32//! let storage = storage::SqliteBackend::in_memory()?;
33//! let decision_id = storage.save_decision(decision).await?;
34//! println!("Saved decision: {}", decision_id);
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Feature Flags
41//!
42//! - `async` - Enable async/await support (enabled by default)
43//! - `sqlite-storage` - Enable SQLite storage backend (enabled by default)
44//! - `lakefs-storage` - Enable LakeFS storage backend (enabled by default)
45//! - `networking` - Enable HTTP client for remote storage (enabled by default)
46//! - `compression` - Enable data compression (enabled by default)
47//! - `parallel` - Enable parallel processing with Rayon
48//! - `sync-only` - Sync-only APIs for WebAssembly compatibility
49
50/// Cost calculation and management functionality
51pub mod cost;
52
53/// Drift detection and model performance monitoring
54pub mod drift;
55
56/// Core data models and structures
57pub mod models;
58
59/// Decision replay and validation
60pub mod replay;
61
62/// Data sanitization and privacy controls
63pub mod sanitization;
64
65// Storage module only available with storage features
66#[cfg(any(feature = "sqlite-storage", feature = "lakefs-storage"))]
67/// Storage backends for persisting decisions and snapshots
68pub mod storage;
69
70// Re-export all public types for convenience
71pub use cost::*;
72pub use drift::*;
73pub use models::*;
74pub use replay::*;
75pub use sanitization::*;
76
77use thiserror::Error;
78
79#[derive(Error, Debug)]
80pub enum BriefcaseError {
81 #[cfg(any(feature = "sqlite-storage", feature = "lakefs-storage"))]
82 #[error("Storage error: {0}")]
83 Storage(#[from] storage::StorageError),
84
85 #[error("Replay error: {0}")]
86 Replay(#[from] replay::ReplayError),
87
88 #[error("Cost calculation error: {0}")]
89 Cost(#[from] cost::CostError),
90
91 #[error("Sanitization error: {0}")]
92 Sanitization(#[from] sanitization::SanitizationError),
93
94 #[error("Serialization error: {0}")]
95 Serialization(#[from] serde_json::Error),
96
97 #[error("Invalid input: {0}")]
98 InvalidInput(String),
99}