Skip to main content

oharness_budget/
lib.rs

1//! Budget middleware and shipped [`BudgetHandle`] implementations (plan §10).
2//!
3//! The [`BudgetHandle`] trait itself lives in `oharness-core`; this crate
4//! provides the concrete implementations (`TokenBudget`, `StepBudget`,
5//! `CostBudget`, `TimeBudget`, `CompositeBudget`), a [`PricingTable`] for
6//! cost calculations, and [`BudgetMiddleware`] — an `Llm` wrapper that
7//! pre-checks, post-consumes on `complete()`, and observes `Chunk::Usage`
8//! events on `stream()`.
9//!
10//! `BudgetMiddleware` implements [`oharness_llm::Llm`] directly (the escape
11//! hatch per plan §5.6.2) rather than via a helper-trait wrapper, because it
12//! needs to thread the same budget counter through all three hook sites.
13//!
14//! Feature flags per plan §16.1: `token` and `step` are on by default;
15//! `cost` and `wall-clock` opt-in.
16//!
17//! [`BudgetHandle`]: oharness_core::BudgetHandle
18
19pub mod amount;
20pub mod composite;
21pub mod error;
22pub mod middleware;
23pub mod pricing;
24
25#[cfg(feature = "cost")]
26pub mod cost;
27#[cfg(feature = "step")]
28pub mod step;
29#[cfg(feature = "wall-clock")]
30pub mod time;
31#[cfg(feature = "token")]
32pub mod token;
33
34pub use amount::{amount_from_response, amount_from_usage, budget_request_from};
35pub use composite::CompositeBudget;
36pub use error::BudgetExceeded;
37pub use middleware::BudgetMiddleware;
38pub use pricing::{ModelPricing, PricingTable};
39
40#[cfg(feature = "cost")]
41pub use cost::CostBudget;
42#[cfg(feature = "step")]
43pub use step::StepBudget;
44#[cfg(feature = "wall-clock")]
45pub use time::TimeBudget;
46#[cfg(feature = "token")]
47pub use token::TokenBudget;