refactor: 移除 Python upstream 依赖,清理全部 legacy/Python 兼容层

- 移除 upstream_base_url 参数及 AETHER_GATEWAY_UPSTREAM 环境变量,gateway 不再需要指向 Python 宿主
- 删除所有 LEGACY_*/PYTHON_* 常量、路由组、header 定义及 sunset/phaseout 机制
- 将 legacy_gateway_bridge 重命名为 internal_gateway,executor 相关命名统一为 execution_runtime
- dev.sh 新增 Postgres/Redis 预检查,移除 upstream 相关启动参数和提示
- 新增 ai_public 路由处理器
- 全量适配 handler、test、state、control 等模块的命名和接口变更
This commit is contained in:
fawney19
2026-04-04 01:40:24 +08:00
parent 1d9c77522a
commit cbc811f6ce
484 changed files with 11046 additions and 3925 deletions

View File

@@ -1,4 +1,10 @@
use super::*;
use chrono::{DateTime, Utc};
use crate::gateway::gateway_data::GatewayDataState;
use super::{
system_config_bool, system_config_u64, system_config_usize, DELETE_AUDIT_LOGS_BEFORE_SQL,
};
pub(crate) async fn cleanup_audit_logs_once(
data: &GatewayDataState,

View File

@@ -1,4 +1,9 @@
use super::*;
use chrono::{DateTime, Utc};
use serde_json::Value;
use crate::gateway::gateway_data::GatewayDataState;
use super::{UsageCleanupSettings, UsageCleanupWindow};
pub(super) async fn system_config_bool(
data: &GatewayDataState,

View File

@@ -1,4 +1,8 @@
use super::*;
use tracing::warn;
use crate::gateway::gateway_data::GatewayDataState;
use super::{system_config_bool, DB_MAINTENANCE_TABLES};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) struct DbMaintenanceRunSummary {

View File

@@ -1,4 +1,17 @@
use super::*;
use std::collections::HashSet;
use chrono::Utc;
use sqlx::Row;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
pending_cleanup_batch_size, pending_cleanup_timeout_minutes,
SELECT_COMPLETED_PENDING_REQUEST_IDS_SQL, SELECT_STALE_PENDING_USAGE_BATCH_SQL,
UPDATE_FAILED_PENDING_CANDIDATES_SQL, UPDATE_FAILED_STALE_USAGE_SQL,
UPDATE_FAILED_VOID_STALE_USAGE_SQL, UPDATE_RECOVERED_STALE_USAGE_SQL,
UPDATE_RECOVERED_STREAMING_CANDIDATES_SQL,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(crate) struct PendingCleanupSummary {

View File

@@ -1,4 +1,15 @@
use super::*;
use std::collections::HashMap;
use aether_data::repository::provider_catalog::{
StoredProviderCatalogEndpoint, StoredProviderCatalogProvider,
};
use futures_util::stream::{self, StreamExt};
use tracing::{debug, warn};
use crate::gateway::handlers::admin::admin_provider_ops_local_action_response;
use crate::gateway::{AppState, GatewayError};
use super::{system_config_bool, PROVIDER_CHECKIN_CONCURRENCY};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ProviderCheckinRunSummary {

View File

@@ -1,4 +1,8 @@
use super::*;
use tracing::info;
use crate::gateway::gateway_data::GatewayDataState;
use super::{now_unix_secs, system_config_bool, system_config_u64, system_config_usize};
pub(crate) async fn cleanup_request_candidates_once(
data: &GatewayDataState,

View File

@@ -1,4 +1,15 @@
use super::*;
use tracing::info;
use crate::gateway::gateway_data::GatewayDataState;
use crate::gateway::{AppState, GatewayError};
use super::{
cleanup_audit_logs_once, cleanup_expired_gemini_file_mappings_once,
cleanup_request_candidates_once, cleanup_stale_pending_requests_once,
perform_db_maintenance_once, perform_provider_checkin_once, perform_stats_aggregation_once,
perform_stats_hourly_aggregation_once, perform_usage_cleanup_once,
perform_wallet_daily_usage_aggregation_once, summarize_postgres_pool,
};
pub(super) async fn run_audit_cleanup_once(
data: &GatewayDataState,

View File

@@ -1,4 +1,17 @@
use super::*;
use std::time::Duration;
use chrono::{DateTime, Datelike, TimeZone, Timelike, Utc, Weekday};
use chrono_tz::Tz;
use tracing::warn;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
system_config_string, WalletDailyUsageAggregationTarget, DB_MAINTENANCE_HOUR,
DB_MAINTENANCE_MINUTE, DB_MAINTENANCE_WEEKDAY, DB_MAINTENANCE_WEEKLY_INTERVAL,
MAINTENANCE_DEFAULT_TIMEZONE, PROVIDER_CHECKIN_DEFAULT_TIME, STATS_DAILY_AGGREGATION_HOUR,
STATS_DAILY_AGGREGATION_MINUTE, STATS_HOURLY_AGGREGATION_MINUTE,
};
pub(super) async fn provider_checkin_schedule(
data: &GatewayDataState,

View File

@@ -1,4 +1,24 @@
use super::*;
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use sqlx::Row;
use uuid::Uuid;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
stats_aggregation_target_day, system_config_bool, PercentileSummary, StatsAggregationSummary,
DELETE_STATS_DAILY_ERRORS_FOR_DATE_SQL, INSERT_STATS_DAILY_ERROR_SQL, INSERT_STATS_SUMMARY_SQL,
SELECT_ACTIVE_USER_IDS_SQL, SELECT_EXISTING_STATS_SUMMARY_ID_SQL,
SELECT_STATS_DAILY_AGGREGATE_SQL, SELECT_STATS_DAILY_API_KEY_AGGREGATES_SQL,
SELECT_STATS_DAILY_ERROR_AGGREGATES_SQL, SELECT_STATS_DAILY_FALLBACK_COUNT_SQL,
SELECT_STATS_DAILY_FIRST_BYTE_PERCENTILES_SQL, SELECT_STATS_DAILY_MODEL_AGGREGATES_SQL,
SELECT_STATS_DAILY_PROVIDER_AGGREGATES_SQL, SELECT_STATS_DAILY_RESPONSE_TIME_PERCENTILES_SQL,
SELECT_STATS_SUMMARY_ENTITY_COUNTS_SQL, SELECT_STATS_SUMMARY_TOTALS_SQL,
SELECT_STATS_USER_DAILY_AGGREGATES_SQL, UPDATE_STATS_SUMMARY_SQL,
UPSERT_STATS_DAILY_API_KEY_SQL, UPSERT_STATS_DAILY_MODEL_SQL, UPSERT_STATS_DAILY_PROVIDER_SQL,
UPSERT_STATS_DAILY_SQL, UPSERT_STATS_USER_DAILY_SQL,
};
pub(super) async fn perform_stats_aggregation_once(
data: &GatewayDataState,

View File

@@ -1,4 +1,15 @@
use super::*;
use chrono::{DateTime, Utc};
use sqlx::Row;
use uuid::Uuid;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
stats_hourly_aggregation_target_hour, system_config_bool, SELECT_STATS_HOURLY_AGGREGATE_SQL,
SELECT_STATS_HOURLY_MODEL_AGGREGATES_SQL, SELECT_STATS_HOURLY_PROVIDER_AGGREGATES_SQL,
SELECT_STATS_HOURLY_USER_AGGREGATES_SQL, UPSERT_STATS_HOURLY_MODEL_SQL,
UPSERT_STATS_HOURLY_PROVIDER_SQL, UPSERT_STATS_HOURLY_SQL, UPSERT_STATS_HOURLY_USER_SQL,
};
#[derive(Debug, Clone, PartialEq)]
pub(super) struct StatsHourlyAggregationSummary {

View File

@@ -1,9 +1,25 @@
use std::collections::{HashSet, VecDeque};
use std::sync::{Arc, Mutex};
use chrono::{DateTime, Utc};
use chrono_tz::Tz;
use serde_json::json;
use super::*;
use super::{
cleanup_audit_logs_with, next_daily_run_after, next_db_maintenance_run_after,
next_stats_aggregation_run_after, next_stats_hourly_aggregation_run_after,
pending_cleanup_batch_size, pending_cleanup_timeout_minutes, plan_pending_cleanup_batch,
provider_checkin_schedule, run_db_maintenance_with, spawn_audit_cleanup_worker,
spawn_db_maintenance_worker, spawn_pending_cleanup_worker, spawn_pool_monitor_worker,
spawn_provider_checkin_worker, spawn_stats_aggregation_worker,
spawn_stats_hourly_aggregation_worker, spawn_usage_cleanup_worker,
spawn_wallet_daily_usage_aggregation_worker, stats_aggregation_target_day,
stats_hourly_aggregation_target_hour, summarize_postgres_pool, usage_cleanup_settings,
usage_cleanup_window, wallet_daily_usage_aggregation_target, AppState, DbMaintenanceRunSummary,
FailedPendingUsageRow, GatewayDataState, StalePendingUsageRow, UsageCleanupSettings,
USAGE_CLEANUP_HOUR, USAGE_CLEANUP_MINUTE, WALLET_DAILY_USAGE_AGGREGATION_HOUR,
WALLET_DAILY_USAGE_AGGREGATION_MINUTE,
};
#[tokio::test]
async fn spawn_audit_cleanup_worker_skips_when_postgres_unavailable() {
@@ -52,7 +68,7 @@ async fn spawn_wallet_daily_usage_aggregation_worker_skips_when_postgres_unavail
#[tokio::test]
async fn spawn_provider_checkin_worker_skips_when_provider_catalog_unavailable() {
let state = AppState::new("http://127.0.0.1:18084")
let state = AppState::new()
.expect("gateway state should build")
.with_data_state_for_tests(GatewayDataState::disabled());

View File

@@ -1,4 +1,23 @@
use super::*;
use std::io::Write;
use chrono::{DateTime, Utc};
use flate2::{write::GzEncoder, Compression};
use serde_json::Value;
use sqlx::Row;
use tracing::warn;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
system_config_bool, usage_cleanup_settings, usage_cleanup_window, ExpiredApiKeyRow,
UsageBodyCompressionRow, UsageCleanupSummary, CLEAR_USAGE_BODY_FIELDS_SQL,
CLEAR_USAGE_HEADER_FIELDS_SQL, DELETE_EXPIRED_API_KEY_SQL, DELETE_OLD_USAGE_RECORDS_SQL,
DISABLE_EXPIRED_API_KEY_SQL, EXPIRED_API_KEY_PRE_CLEAN_BATCH_SIZE,
NULLIFY_REQUEST_CANDIDATE_API_KEY_BATCH_SQL, NULLIFY_USAGE_API_KEY_BATCH_SQL,
SELECT_EXPIRED_ACTIVE_API_KEYS_SQL, SELECT_USAGE_BODY_COMPRESSION_BATCH_SQL,
SELECT_USAGE_HEADER_BATCH_SQL, SELECT_USAGE_STALE_BODY_BATCH_SQL,
UPDATE_USAGE_BODY_COMPRESSION_SQL,
};
pub(super) async fn perform_usage_cleanup_once(
data: &GatewayDataState,

View File

@@ -1,4 +1,14 @@
use super::*;
use chrono::{DateTime, Utc};
use sqlx::Row;
use uuid::Uuid;
use crate::gateway::gateway_data::GatewayDataState;
use super::{
maintenance_timezone, wallet_daily_usage_aggregation_target,
DELETE_STALE_WALLET_DAILY_USAGE_LEDGERS_SQL, SELECT_WALLET_DAILY_USAGE_AGGREGATION_ROWS_SQL,
UPSERT_WALLET_DAILY_USAGE_LEDGER_SQL,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct WalletDailyUsageAggregationSummary {

View File

@@ -1,4 +1,24 @@
use super::*;
use std::sync::Arc;
use chrono::Utc;
use tracing::warn;
use crate::gateway::gateway_data::GatewayDataState;
use crate::gateway::AppState;
use super::{
duration_until_next_daily_run, duration_until_next_db_maintenance_run,
duration_until_next_stats_aggregation_run, duration_until_next_stats_hourly_aggregation_run,
maintenance_timezone, parse_hhmm_time, provider_checkin_schedule, run_audit_cleanup_once,
run_db_maintenance_once, run_gemini_file_mapping_cleanup_once, run_pending_cleanup_once,
run_pool_monitor_once, run_provider_checkin_once, run_request_candidate_cleanup_once,
run_stats_aggregation_once, run_stats_hourly_aggregation_once, run_usage_cleanup_once,
run_wallet_daily_usage_aggregation_once, AUDIT_LOG_CLEANUP_INTERVAL,
GEMINI_FILE_MAPPING_CLEANUP_INTERVAL, PENDING_CLEANUP_INTERVAL, POOL_MONITOR_INTERVAL,
PROVIDER_CHECKIN_DEFAULT_TIME, REQUEST_CANDIDATE_CLEANUP_INTERVAL, USAGE_CLEANUP_HOUR,
USAGE_CLEANUP_MINUTE, WALLET_DAILY_USAGE_AGGREGATION_HOUR,
WALLET_DAILY_USAGE_AGGREGATION_MINUTE,
};
pub(crate) fn spawn_audit_cleanup_worker(
data: Arc<GatewayDataState>,