pub struct BudgetEnforcer { /* private fields */ }Expand description
Enforces spending limits by checking the metering engine before each LLM call. Supports per-fighter and global limits.
Implementations§
Source§impl BudgetEnforcer
impl BudgetEnforcer
Sourcepub fn new(metering: Arc<MeteringEngine>) -> Self
pub fn new(metering: Arc<MeteringEngine>) -> Self
Create a new budget enforcer backed by the given metering engine.
Sourcepub fn set_fighter_limit(&self, fighter_id: FighterId, limit: BudgetLimit)
pub fn set_fighter_limit(&self, fighter_id: FighterId, limit: BudgetLimit)
Set a per-fighter budget limit.
Sourcepub fn remove_fighter_limit(&self, fighter_id: &FighterId)
pub fn remove_fighter_limit(&self, fighter_id: &FighterId)
Remove a per-fighter budget limit.
Sourcepub fn get_fighter_limit(&self, fighter_id: &FighterId) -> Option<BudgetLimit>
pub fn get_fighter_limit(&self, fighter_id: &FighterId) -> Option<BudgetLimit>
Get the per-fighter budget limit, if configured.
Sourcepub fn set_global_limit(&self, limit: BudgetLimit)
pub fn set_global_limit(&self, limit: BudgetLimit)
Set the global budget limit (applies to all fighters).
Uses std::sync::RwLock so this is safe from both sync and async contexts.
Sourcepub fn clear_global_limit(&self)
pub fn clear_global_limit(&self)
Remove the global budget limit.
Sourcepub fn get_global_limit(&self) -> Option<BudgetLimit>
pub fn get_global_limit(&self) -> Option<BudgetLimit>
Get the current global budget limit.
Sourcepub async fn check_budget(
&self,
fighter_id: &FighterId,
) -> PunchResult<BudgetVerdict>
pub async fn check_budget( &self, fighter_id: &FighterId, ) -> PunchResult<BudgetVerdict>
Check the budget for a specific fighter before an LLM call.
This checks both the per-fighter limit (if set) and the global limit (if set). The most restrictive verdict wins.
Sourcepub async fn get_fighter_status(
&self,
fighter_id: &FighterId,
) -> PunchResult<BudgetStatus>
pub async fn get_fighter_status( &self, fighter_id: &FighterId, ) -> PunchResult<BudgetStatus>
Get the current budget status for a fighter (for API responses).
Sourcepub async fn get_global_status(&self) -> PunchResult<BudgetStatus>
pub async fn get_global_status(&self) -> PunchResult<BudgetStatus>
Get the global budget status.
Auto Trait Implementations§
impl !Freeze for BudgetEnforcer
impl !RefUnwindSafe for BudgetEnforcer
impl Send for BudgetEnforcer
impl Sync for BudgetEnforcer
impl Unpin for BudgetEnforcer
impl UnsafeUnpin for BudgetEnforcer
impl !UnwindSafe for BudgetEnforcer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more