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//! - `vcs-storage` - Enable VCS provider abstraction layer
51//! - `vcs-dvc` - DVC (Data Version Control) backend
52//! - `vcs-nessie` - Project Nessie backend
53//! - `vcs-pachyderm` - Pachyderm backend
54//! - `vcs-artivc` - ArtiVC backend
55//! - `vcs-ducklake` - DuckLake backend
56//! - `vcs-iceberg` - Apache Iceberg backend
57//! - `vcs-gitlfs` - Git + Git-LFS backend
58//! - `vcs-all` - Enable all VCS backends
59
60/// Cost calculation and management functionality
61pub mod cost;
62
63/// Drift detection and model performance monitoring
64pub mod drift;
65
66/// Core data models and structures
67pub mod models;
68
69/// Decision replay and validation
70pub mod replay;
71
72/// Data sanitization and privacy controls
73pub mod sanitization;
74
75// Storage module only available with storage features
76#[cfg(any(
77    feature = "sqlite-storage",
78    feature = "lakefs-storage",
79    feature = "vcs-storage"
80))]
81/// Storage backends for persisting decisions and snapshots
82pub mod storage;
83
84// Control plane abstraction for auth/authz backends (remote, local, etc.)
85#[cfg(feature = "async")]
86/// Control plane trait and implementations for client lookup
87pub mod control;
88
89// Client authentication module (requires networking for server validation)
90#[cfg(feature = "networking")]
91/// Unified client for authenticated access to the Briefcase AI platform
92pub mod client;
93
94// Re-export all public types for convenience
95pub use cost::*;
96pub use drift::*;
97pub use models::*;
98pub use replay::*;
99pub use sanitization::*;
100
101use thiserror::Error;
102
103#[derive(Error, Debug)]
104pub enum BriefcaseError {
105    #[cfg(any(
106        feature = "sqlite-storage",
107        feature = "lakefs-storage",
108        feature = "vcs-storage"
109    ))]
110    #[error("Storage error: {0}")]
111    Storage(#[from] storage::StorageError),
112
113    #[error("Replay error: {0}")]
114    Replay(#[from] replay::ReplayError),
115
116    #[error("Cost calculation error: {0}")]
117    Cost(#[from] cost::CostError),
118
119    #[error("Sanitization error: {0}")]
120    Sanitization(#[from] sanitization::SanitizationError),
121
122    #[error("Serialization error: {0}")]
123    Serialization(#[from] serde_json::Error),
124
125    #[error("Invalid input: {0}")]
126    InvalidInput(String),
127
128    #[cfg(feature = "networking")]
129    #[error("Client error: {0}")]
130    Client(#[from] client::ClientError),
131}