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: RuntimeVirtualKeyManagerAPI key manager for /v1/keys route handlers (shared across requests)
callbacks: RuntimeObservabilityNon-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
impl AppState
Sourcepub fn config_sync_status(&self) -> ConfigSyncStatus
pub fn config_sync_status(&self) -> ConfigSyncStatus
Current node’s revision and sanitized synchronization diagnostics.
Source§impl AppState
impl AppState
Sourcepub fn new_with_unified_router(
config: Config,
auth: AuthSystem,
unified_router: UnifiedRouter,
storage: StorageLayer,
pricing: Arc<PricingService>,
budget_limits: Arc<UnifiedBudgetLimits>,
) -> Self
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
Sourcepub fn new_with_runtime(
revision: RuntimeRevision,
auth: AuthSystem,
storage: StorageLayer,
pricing: Arc<PricingService>,
budget_limits: Arc<UnifiedBudgetLimits>,
) -> Self
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.
Sourcepub fn with_callbacks(self, callbacks: RuntimeObservability) -> Self
pub fn with_callbacks(self, callbacks: RuntimeObservability) -> Self
Attach a configured callback dispatcher.
Sourcepub fn with_audit_logger(self, audit_logger: Arc<AuditLogger>) -> Self
pub fn with_audit_logger(self, audit_logger: Arc<AuditLogger>) -> Self
Attach the request audit logger built during startup.
Sourcepub fn with_request_policies(
self,
guardrails: Arc<GuardrailEngine>,
ip_access: Arc<IpAccessControl>,
) -> Self
pub fn with_request_policies( self, guardrails: Arc<GuardrailEngine>, ip_access: Arc<IpAccessControl>, ) -> Self
Attach validated content and network policy engines.
Sourcepub fn pin_runtime(&self) -> Arc<RuntimeRevision> ⓘ
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.
Sourcepub fn unified_router(&self) -> Arc<UnifiedRouter> ⓘ
pub fn unified_router(&self) -> Arc<UnifiedRouter> ⓘ
Live router for the current generation.
Sourcepub fn guardrails(&self) -> Arc<GuardrailEngine> ⓘ
pub fn guardrails(&self) -> Arc<GuardrailEngine> ⓘ
Live guardrail engine for the current generation.
Sourcepub fn response_cache(&self) -> Option<Arc<LLMCache>>
pub fn response_cache(&self) -> Option<Arc<LLMCache>>
Live response cache for the current generation.
Sourcepub async fn apply_runtime(&self, candidate: Config) -> Result<u64>
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
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> BudgetAwareRouting for T
impl<T> BudgetAwareRouting for T
Source§fn filter_by_budget(
&self,
providers: Vec<String>,
budget_router: &BudgetAwareRouter,
) -> Vec<String>
fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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