Skip to main content

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 briefcase_core::storage::StorageBackend;
20//! use serde_json::json;
21//!
22//! # #[tokio::main]
23//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//! // Create a decision snapshot
25//! let decision = DecisionSnapshot::new("ai_function")
26//!     .add_input(Input::new("user_query", json!("Hello world"), "string"))
27//!     .add_output(Output::new("response", json!("Hello back!"), "string").with_confidence(0.95))
28//!     .with_execution_time(120.5);
29//!
30//! // Save to storage (requires storage feature)
31//! #[cfg(feature = "sqlite-storage")]
32//! {
33//!     let storage = storage::SqliteBackend::in_memory()?;
34//!     let decision_id = storage.save_decision(&decision).await?;
35//!     println!("Saved decision: {}", decision_id);
36//! }
37//! # Ok(())
38//! # }
39//! ```
40//!
41//! ## Feature Flags
42//!
43//! - `async` - Enable async/await support (enabled by default)
44//! - `sqlite-storage` - Enable SQLite storage backend (enabled by default)
45//! - `lakefs-storage` - Enable LakeFS storage backend (enabled by default)
46//! - `networking` - Enable HTTP client for remote storage (enabled by default)
47//! - `compression` - Enable data compression (enabled by default)
48//! - `parallel` - Enable parallel processing with Rayon
49//! - `sync-only` - Sync-only APIs for WebAssembly compatibility
50
51/// Cost calculation and management functionality
52pub mod cost;
53
54/// Drift detection and model performance monitoring
55pub mod drift;
56
57/// Core data models and structures
58pub mod models;
59
60/// Decision replay and validation
61pub mod replay;
62
63/// Data sanitization and privacy controls
64pub mod sanitization;
65
66// Storage module only available with storage features
67#[cfg(any(feature = "sqlite-storage", feature = "lakefs-storage"))]
68/// Storage backends for persisting decisions and snapshots
69pub mod storage;
70
71// Re-export all public types for convenience
72pub use cost::*;
73pub use drift::*;
74pub use models::*;
75pub use replay::*;
76pub use sanitization::*;
77
78use thiserror::Error;
79
80#[derive(Error, Debug)]
81pub enum BriefcaseError {
82    #[cfg(any(feature = "sqlite-storage", feature = "lakefs-storage"))]
83    #[error("Storage error: {0}")]
84    Storage(#[from] storage::StorageError),
85
86    #[error("Replay error: {0}")]
87    Replay(#[from] replay::ReplayError),
88
89    #[error("Cost calculation error: {0}")]
90    Cost(#[from] cost::CostError),
91
92    #[error("Sanitization error: {0}")]
93    Sanitization(#[from] sanitization::SanitizationError),
94
95    #[error("Serialization error: {0}")]
96    Serialization(#[from] serde_json::Error),
97
98    #[error("Invalid input: {0}")]
99    InvalidInput(String),
100}