2026-04-05 20:23:16 +08:00
|
|
|
use std::collections::HashMap;
|
2026-05-11 01:45:49 +08:00
|
|
|
use std::sync::atomic::AtomicU64;
|
2026-04-05 20:23:16 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::sync::Mutex as StdMutex;
|
2026-05-15 01:54:20 +08:00
|
|
|
use std::time::Duration;
|
2026-04-05 20:23:16 +08:00
|
|
|
|
2026-05-08 00:18:12 +08:00
|
|
|
use aether_runtime::ConcurrencyGate;
|
|
|
|
|
use aether_runtime_state::{RuntimeSemaphore, RuntimeState};
|
2026-04-05 20:23:16 +08:00
|
|
|
|
|
|
|
|
use super::super::async_task::{VideoTaskPollerConfig, VideoTaskService};
|
|
|
|
|
use super::super::cache::{
|
2026-04-15 03:03:20 +08:00
|
|
|
AuthApiKeyLastUsedCache, AuthContextCache, DashboardResponseCache, DirectPlanBypassCache,
|
2026-04-23 14:42:51 +08:00
|
|
|
SchedulerAffinityCache, SystemConfigCache,
|
2026-04-05 20:23:16 +08:00
|
|
|
};
|
|
|
|
|
use super::super::data::GatewayDataState;
|
2026-04-07 02:50:19 +08:00
|
|
|
use super::super::fallback_metrics;
|
2026-04-05 20:23:16 +08:00
|
|
|
use super::super::rate_limit::FrontdoorUserRpmLimiter;
|
|
|
|
|
use super::super::{provider_transport, usage};
|
|
|
|
|
use super::{
|
|
|
|
|
AdminBillingCollectorRecord, AdminBillingRuleRecord, AdminPaymentCallbackRecord,
|
|
|
|
|
AdminWalletPaymentOrderRecord, AdminWalletRefundRecord, AdminWalletTransactionRecord,
|
|
|
|
|
CachedProviderTransportSnapshot, FrontdoorCorsConfig, LocalExecutionRuntimeMissDiagnostic,
|
|
|
|
|
LocalProviderDeleteTaskState, ProviderTransportSnapshotCacheKey,
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-20 16:59:18 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
|
type TestExecutionRuntimeSyncOverrideFn = dyn Fn(
|
|
|
|
|
&aether_contracts::ExecutionPlan,
|
|
|
|
|
) -> Result<aether_contracts::ExecutionResult, crate::GatewayError>
|
|
|
|
|
+ Send
|
|
|
|
|
+ Sync;
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub(crate) struct TestExecutionRuntimeSyncOverride(
|
|
|
|
|
pub(crate) Arc<TestExecutionRuntimeSyncOverrideFn>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
impl std::fmt::Debug for TestExecutionRuntimeSyncOverride {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.write_str("TestExecutionRuntimeSyncOverride(..)")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 20:23:16 +08:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct AppState {
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) execution_runtime_override_base_url: Option<String>,
|
2026-04-20 16:59:18 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) execution_runtime_sync_override: Option<TestExecutionRuntimeSyncOverride>,
|
2026-04-05 20:23:16 +08:00
|
|
|
pub(crate) data: Arc<GatewayDataState>,
|
2026-05-08 00:18:12 +08:00
|
|
|
pub(crate) runtime_state: Arc<RuntimeState>,
|
2026-04-05 20:23:16 +08:00
|
|
|
pub(crate) usage_runtime: Arc<usage::UsageRuntime>,
|
|
|
|
|
pub(crate) video_tasks: Arc<VideoTaskService>,
|
|
|
|
|
pub(crate) video_task_poller: Option<VideoTaskPollerConfig>,
|
|
|
|
|
pub(crate) request_gate: Option<Arc<ConcurrencyGate>>,
|
2026-05-08 00:18:12 +08:00
|
|
|
pub(crate) distributed_request_gate: Option<Arc<RuntimeSemaphore>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
pub(crate) client: reqwest::Client,
|
|
|
|
|
pub(crate) auth_context_cache: Arc<AuthContextCache>,
|
|
|
|
|
pub(crate) auth_api_key_last_used_cache: Arc<AuthApiKeyLastUsedCache>,
|
|
|
|
|
pub(crate) oauth_refresh: Arc<provider_transport::LocalOAuthRefreshCoordinator>,
|
|
|
|
|
pub(crate) direct_plan_bypass_cache: Arc<DirectPlanBypassCache>,
|
|
|
|
|
pub(crate) scheduler_affinity_cache: Arc<SchedulerAffinityCache>,
|
2026-05-11 01:45:49 +08:00
|
|
|
pub(crate) scheduler_affinity_epoch: Arc<AtomicU64>,
|
2026-04-15 03:03:20 +08:00
|
|
|
pub(crate) dashboard_response_cache: Arc<DashboardResponseCache>,
|
2026-04-23 14:42:51 +08:00
|
|
|
pub(crate) system_config_cache: Arc<SystemConfigCache>,
|
2026-04-05 20:23:16 +08:00
|
|
|
pub(crate) fallback_metrics: Arc<fallback_metrics::GatewayFallbackMetrics>,
|
|
|
|
|
pub(crate) frontdoor_cors: Option<Arc<FrontdoorCorsConfig>>,
|
|
|
|
|
pub(crate) frontdoor_user_rpm: Arc<FrontdoorUserRpmLimiter>,
|
|
|
|
|
pub(crate) tunnel: crate::tunnel::EmbeddedTunnelState,
|
|
|
|
|
pub(crate) provider_transport_snapshot_cache:
|
|
|
|
|
Arc<StdMutex<HashMap<ProviderTransportSnapshotCacheKey, CachedProviderTransportSnapshot>>>,
|
|
|
|
|
pub(crate) provider_key_rpm_resets: Arc<StdMutex<HashMap<String, u64>>>,
|
|
|
|
|
pub(crate) local_execution_runtime_miss_diagnostics:
|
|
|
|
|
Arc<StdMutex<HashMap<String, LocalExecutionRuntimeMissDiagnostic>>>,
|
|
|
|
|
pub(crate) admin_monitoring_error_stats_reset_at: Arc<StdMutex<Option<u64>>>,
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) provider_delete_tasks: Arc<StdMutex<HashMap<String, LocalProviderDeleteTaskState>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-05-15 01:54:20 +08:00
|
|
|
pub(crate) turnstile_siteverify_url_override: Option<String>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) turnstile_siteverify_timeout_override: Option<Duration>,
|
|
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) provider_oauth_state_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) provider_oauth_device_session_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) provider_oauth_batch_task_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) auth_session_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, crate::data::state::StoredUserSessionRecord>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) auth_email_verification_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) auth_email_delivery_store: Option<Arc<StdMutex<Vec<serde_json::Value>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) auth_user_store: Option<
|
|
|
|
|
Arc<StdMutex<HashMap<String, aether_data::repository::users::StoredUserAuthRecord>>>,
|
|
|
|
|
>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) auth_user_model_capability_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, serde_json::Value>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) auth_wallet_store: Option<
|
|
|
|
|
Arc<StdMutex<HashMap<String, aether_data::repository::wallet::StoredWalletSnapshot>>>,
|
|
|
|
|
>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_wallet_payment_order_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminWalletPaymentOrderRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_payment_callback_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminPaymentCallbackRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_wallet_transaction_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminWalletTransactionRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_wallet_refund_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminWalletRefundRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_billing_rule_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminBillingRuleRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_billing_collector_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, AdminBillingCollectorRecord>>>>,
|
|
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) admin_security_blacklist_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_security_whitelist_store:
|
|
|
|
|
Option<Arc<StdMutex<std::collections::BTreeSet<String>>>>,
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) admin_monitoring_cache_affinity_store:
|
|
|
|
|
Option<Arc<StdMutex<HashMap<String, String>>>>,
|
|
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) admin_monitoring_redis_key_store: Option<Arc<StdMutex<HashMap<String, String>>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
#[cfg(test)]
|
2026-04-07 02:50:19 +08:00
|
|
|
pub(crate) provider_oauth_token_url_overrides: Arc<StdMutex<HashMap<String, String>>>,
|
2026-04-05 20:23:16 +08:00
|
|
|
}
|