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/// Token counting and estimation
70pub mod tokens;
71
72/// The default base URL for the Briefcase AI API.
73pub const DEFAULT_API_URL: &str = "https://api.briefcasebrain.com";
74
75/// Decision replay and validation
76pub mod replay;
77
78/// Data sanitization and privacy controls
79pub mod sanitization;
80
81// Storage module only available with storage features
82#[cfg(any(
83    feature = "sqlite-storage",
84    feature = "lakefs-storage",
85    feature = "vcs-storage"
86))]
87/// Storage backends for persisting decisions and snapshots
88pub mod storage;
89
90// Control plane abstraction for auth/authz backends (remote, local, etc.)
91#[cfg(feature = "async")]
92/// Control plane trait and implementations for client lookup
93pub mod control;
94
95// Client authentication module (requires networking for server validation)
96#[cfg(feature = "networking")]
97/// Unified client for authenticated access to the Briefcase AI platform
98pub mod client;
99
100// Re-export all public types for convenience
101pub use cost::*;
102pub use drift::*;
103pub use models::*;
104pub use replay::*;
105pub use sanitization::*;
106pub use tokens::*;
107
108use thiserror::Error;
109
110#[derive(Error, Debug)]
111pub enum BriefcaseError {
112    #[cfg(any(
113        feature = "sqlite-storage",
114        feature = "lakefs-storage",
115        feature = "vcs-storage"
116    ))]
117    #[error("Storage error: {0}")]
118    Storage(#[from] storage::StorageError),
119
120    #[error("Replay error: {0}")]
121    Replay(#[from] replay::ReplayError),
122
123    #[error("Cost calculation error: {0}")]
124    Cost(#[from] cost::CostError),
125
126    #[error("Sanitization error: {0}")]
127    Sanitization(#[from] sanitization::SanitizationError),
128
129    #[error("Serialization error: {0}")]
130    Serialization(#[from] serde_json::Error),
131
132    #[error("Invalid input: {0}")]
133    InvalidInput(String),
134
135    #[cfg(feature = "networking")]
136    #[error("Client error: {0}")]
137    Client(#[from] client::ClientError),
138}