Skip to main content

firstpass_proxy/
lib.rs

1//! # firstpass-proxy
2//!
3//! An HTTP proxy that sits as a drop-in `base_url` in front of Anthropic/OpenAI-compatible
4//! providers. In **observe** mode it forwards each request unchanged and records a
5//! tamper-evident audit trace asynchronously (zero added latency). In **enforce** mode it runs
6//! the escalation engine — cheapest model first, gate the output, escalate one rung on failure,
7//! serve the first output that passes — with cross-provider failover (SPEC §7.1, §7.1a, §9.1).
8//!
9//! - [`config`] — [`ProxyConfig`], loaded from the environment.
10//! - [`store`] — the background SQLite trace writer.
11//! - [`calibrate`] — recalibrate the conformal serving threshold from deferred feedback.
12//! - [`upstream`] — BYOK passthrough to the upstream provider (observe mode).
13//! - [`provider`] — normalized multi-provider model access (Anthropic, OpenAI).
14//! - [`gate`] — runtime verification gates (Batch 3 inline set).
15//! - [`router`] — the enforce-mode escalation engine.
16//! - [`proxy`] — axum routing, observe passthrough, and enforce dispatch.
17//! - [`error`] — structured, no-leak error responses.
18//! - [`key_custody`] — per-tenant AES-256-GCM envelope key custody (ADR 0004 §D5, pre-review).
19//! - [`metrics`] — Prometheus recorder install + `GET /metrics`.
20//! - [`cli`] — `firstpass doctor` / `trace` logic (validate a setup, read the store).
21//! - [`mcp`] — minimal MCP stdio server so an agent can read its traces and submit feedback.
22//! - [`tenant_auth`] — experimental multi-tenant API-key auth (ADR 0004 §D1, default-off).
23//! - [`run`] — shared server bootstrap for the `firstpass` and `firstpass-proxy` binaries.
24#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
25
26pub mod bandit;
27pub mod calibrate;
28pub mod cli;
29pub mod config;
30pub mod consistency;
31pub mod error;
32pub mod gate;
33pub mod judge;
34pub mod key_custody;
35pub mod mcp;
36pub mod metrics;
37pub mod onboard;
38pub mod ope;
39pub mod provider;
40pub mod proxy;
41pub mod router;
42pub mod run;
43pub mod store;
44pub mod subprocess;
45pub mod tenant_auth;
46pub mod upstream;
47
48pub use config::ProxyConfig;
49pub use error::ProxyError;
50pub use proxy::{AppState, app};
51pub use store::{TraceSender, load_all_traces};
52pub use tenant_auth::{TenantId, TenantKeys};