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//! - `recording` - Baseline decision capture pipeline (enabled by default)
44//! - `async` - Enable async/await runtime support (enabled by default)
45//! - `storage` - Enable persistent storage APIs (enabled by default)
46//! - `sqlite-storage` - SQLite storage backend (implied by `storage`)
47//! - `vcs-storage` - Version-control storage abstractions
48//! - `replay` - Deterministic replay engine
49//! - `drift` - Drift monitoring utilities
50//! - `sanitize` - Built-in PII sanitization
51//! - `otel` - OpenTelemetry instrumentation helpers
52//! - `tokens` - Token counting utilities
53//! - `networking` - HTTP client support for remote services
54//! - `compression` - Compression helpers for storage backends
55
56/// Cost calculation and management functionality
57pub mod cost;
58
59/// Drift detection and model performance monitoring
60#[cfg(feature = "drift")]
61pub mod drift;
62
63/// Core data models and structures
64pub mod models;
65
66/// Token counting and estimation
67#[cfg(feature = "tokens")]
68pub mod tokens;
69
70/// Telemetry helpers for reporting usage
71#[cfg(feature = "otel")]
72pub mod telemetry;
73
74/// The default base URL for the Briefcase AI API.
75pub const DEFAULT_API_URL: &str = "http://localhost:8080";
76
77/// Decision replay and validation
78#[cfg(feature = "replay")]
79pub mod replay;
80
81/// Data sanitization and privacy controls
82#[cfg(feature = "sanitize")]
83pub mod sanitization;
84
85// Storage module only available with storage features
86#[cfg(any(feature = "sqlite-storage", feature = "vcs-storage"))]
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::*;
102#[cfg(feature = "drift")]
103pub use drift::*;
104pub use models::*;
105#[cfg(feature = "replay")]
106pub use replay::*;
107#[cfg(feature = "sanitize")]
108pub use sanitization::*;
109#[cfg(feature = "tokens")]
110pub use tokens::*;
111
112use thiserror::Error;
113
114#[derive(Error, Debug)]
115pub enum BriefcaseError {
116 #[cfg(any(feature = "sqlite-storage", feature = "vcs-storage"))]
117 #[error("Storage error: {0}")]
118 Storage(#[from] storage::StorageError),
119
120 #[cfg(feature = "replay")]
121 #[error("Replay error: {0}")]
122 Replay(#[from] replay::ReplayError),
123
124 #[cfg(feature = "drift")]
125 #[error("Cost calculation error: {0}")]
126 Cost(#[from] cost::CostError),
127
128 #[cfg(feature = "sanitize")]
129 #[error("Sanitization error: {0}")]
130 Sanitization(#[from] sanitization::SanitizationError),
131
132 #[error("Serialization error: {0}")]
133 Serialization(#[from] serde_json::Error),
134
135 #[error("Invalid input: {0}")]
136 InvalidInput(String),
137
138 #[cfg(feature = "networking")]
139 #[error("Client error: {0}")]
140 Client(#[from] client::ClientError),
141}