Skip to main content

AppState

Struct AppState 

Source
pub struct AppState {
    pub config: Arc<AtomicValue<Config>>,
    pub auth: Arc<AuthSystem>,
    pub storage: Arc<StorageLayer>,
    pub pricing: Arc<PricingService>,
    pub budget_limits: Arc<UnifiedBudgetLimits>,
    pub budget_manager: Arc<BudgetManager>,
    pub team_manager: Arc<TeamManager>,
    pub key_manager: RuntimeVirtualKeyManager,
    pub callbacks: RuntimeObservability,
    pub audit_logger: Arc<AuditLogger>,
    pub ip_access: Arc<IpAccessControl>,
    /* private fields */
}
Expand description

HTTP server state shared across handlers

This struct contains shared resources that need to be accessed across multiple request handlers. All fields are wrapped in Arc for efficient sharing across threads.

config uses AtomicValue so callers can explicitly swap the entire configuration at runtime while readers obtain lock-free Arc<Config> snapshots. This type does not start a file watcher by itself.

Router, guardrails, and response cache are published together through Self::apply_runtime. Self::pin_runtime holds one generation for a request lifecycle. Live accessors load from that same bundle so HTTP traffic never stays on construction-time Arcs after a successful apply.

Fields§

§config: Arc<AtomicValue<Config>>

Gateway configuration (atomically swappable by explicit callers)

§auth: Arc<AuthSystem>

Authentication system

§storage: Arc<StorageLayer>

Storage layer

§pricing: Arc<PricingService>

Unified pricing service

§budget_limits: Arc<UnifiedBudgetLimits>

Budget limits for provider and model cost tracking

§budget_manager: Arc<BudgetManager>

General budget manager for keyed budget scopes such as API key budgets

§team_manager: Arc<TeamManager>

Team manager for team lifecycle operations (shared, in-memory by default)

§key_manager: RuntimeVirtualKeyManager

API key manager for /v1/keys route handlers (shared across requests)

§callbacks: RuntimeObservability

Non-blocking external request lifecycle callback dispatcher

§audit_logger: Arc<AuditLogger>

Explicitly configured request audit logger.

§ip_access: Arc<IpAccessControl>

IP policy consumed by the outer HTTP middleware.

Implementations§

Source§

impl AppState

Source

pub fn config_sync_status(&self) -> ConfigSyncStatus

Current node’s revision and sanitized synchronization diagnostics.

Source§

impl AppState

Source

pub fn new_with_unified_router( config: Config, auth: AuthSystem, unified_router: UnifiedRouter, storage: StorageLayer, pricing: Arc<PricingService>, budget_limits: Arc<UnifiedBudgetLimits>, ) -> Self

Create a new AppState with unified router

Source

pub fn new_with_runtime( revision: RuntimeRevision, auth: AuthSystem, storage: StorageLayer, pricing: Arc<PricingService>, budget_limits: Arc<UnifiedBudgetLimits>, ) -> Self

Create AppState from a fully built runtime revision.

Source

pub fn with_callbacks(self, callbacks: RuntimeObservability) -> Self

Attach a configured callback dispatcher.

Source

pub fn with_audit_logger(self, audit_logger: Arc<AuditLogger>) -> Self

Attach the request audit logger built during startup.

Source

pub fn with_request_policies( self, guardrails: Arc<GuardrailEngine>, ip_access: Arc<IpAccessControl>, ) -> Self

Attach validated content and network policy engines.

Source

pub fn pin_runtime(&self) -> Arc<RuntimeRevision> ⓘ

Lock-free pin of the active runtime generation.

Clone the returned Arc (or clone this pin) to keep router, guardrails, cache, config, and generation stable for the rest of a request even if Self::apply_runtime publishes a newer revision.

Source

pub fn unified_router(&self) -> Arc<UnifiedRouter> ⓘ

Live router for the current generation.

Source

pub fn guardrails(&self) -> Arc<GuardrailEngine> ⓘ

Live guardrail engine for the current generation.

Source

pub fn response_cache(&self) -> Option<Arc<LLMCache>>

Live response cache for the current generation.

Source

pub async fn apply_runtime(&self, candidate: Config) -> Result<u64>

Validate and build a complete candidate revision, then publish it atomically.

Any build failure leaves the previous revision fully active. On success, router, provider health, guardrails, response cache, generation, and Self::config observe one consistent generation. Pricing is reused from Self::pricing rather than rebuilt.

Source

pub fn config(&self) -> Arc<Config> ⓘ

Load a snapshot of the current gateway configuration.

Returns an Arc<Config> that is valid for the lifetime of the caller — subsequent explicit swaps will not affect already-loaded snapshots.

Trait Implementations§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BudgetAwareRouting for T

Source§

fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>

Filter providers based on budget availability
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SharedResource for T
where T: Send + Sync + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more