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