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,5 @@
use super::*;
use crate::gateway::{AppState, LocalProviderDeleteTaskState};
use serde_json::json;
pub(crate) fn admin_provider_id_for_keys(request_path: &str) -> Option<String> {
request_path

View File

@@ -1,4 +1,10 @@
use super::*;
use crate::gateway::handlers::{json_string_list, unix_secs_to_rfc3339};
use crate::gateway::AppState;
#[cfg(test)]
use aether_crypto::DEVELOPMENT_ENCRYPTION_KEY;
use aether_crypto::{decrypt_python_fernet_ciphertext, encrypt_python_fernet_plaintext};
use aether_data::repository::provider_catalog::StoredProviderCatalogKey;
use serde_json::json;
pub(crate) fn decrypt_catalog_secret_with_fallbacks(
encryption_key: Option<&str>,

View File

@@ -1,11 +1,73 @@
pub(crate) use super::*;
mod admin_paths;
mod catalog;
mod payloads;
mod request_utils;
pub(crate) use self::admin_paths::*;
pub(crate) use self::catalog::*;
pub(crate) use self::payloads::*;
pub(crate) use self::request_utils::*;
pub(crate) use self::admin_paths::{
admin_clear_oauth_invalid_key_id, admin_export_key_id, admin_gemini_file_mapping_id_from_path,
admin_global_model_assign_to_providers_id, admin_global_model_id_from_path,
admin_global_model_providers_id, admin_global_model_routing_id,
admin_management_token_id_from_path, admin_management_token_status_id_from_path,
admin_oauth_provider_type_from_path, admin_oauth_test_provider_type_from_path,
admin_provider_assign_global_models_path, admin_provider_available_source_models_path,
admin_provider_clear_pool_cooldown_parts, admin_provider_delete_task_parts,
admin_provider_id_for_health_monitor, admin_provider_id_for_keys,
admin_provider_id_for_manage_path, admin_provider_id_for_mapping_preview,
admin_provider_id_for_models_list, admin_provider_id_for_pool_status,
admin_provider_id_for_provider_ops_balance, admin_provider_id_for_provider_ops_checkin,
admin_provider_id_for_provider_ops_config, admin_provider_id_for_provider_ops_connect,
admin_provider_id_for_provider_ops_disconnect, admin_provider_id_for_provider_ops_status,
admin_provider_id_for_provider_ops_verify, admin_provider_id_for_provider_strategy_billing,
admin_provider_id_for_provider_strategy_quota, admin_provider_id_for_provider_strategy_stats,
admin_provider_id_for_refresh_quota, admin_provider_id_for_suffix,
admin_provider_id_for_summary, admin_provider_import_models_path,
admin_provider_model_route_parts, admin_provider_models_batch_path,
admin_provider_oauth_batch_import_provider_id, admin_provider_oauth_batch_import_task_path,
admin_provider_oauth_batch_import_task_provider_id, admin_provider_oauth_complete_key_id,
admin_provider_oauth_complete_provider_id, admin_provider_oauth_device_authorize_provider_id,
admin_provider_oauth_device_poll_provider_id, admin_provider_oauth_import_provider_id,
admin_provider_oauth_refresh_key_id, admin_provider_oauth_start_key_id,
admin_provider_oauth_start_provider_id, admin_provider_ops_action_route_parts,
admin_provider_ops_architecture_id_from_path, admin_provider_pool_key_route_parts,
admin_provider_reset_pool_cost_parts, admin_reveal_key_id, admin_system_config_key_from_path,
admin_system_email_template_preview_type_from_path,
admin_system_email_template_reset_type_from_path, admin_system_email_template_type_from_path,
admin_update_key_id, build_admin_provider_delete_task_payload,
is_admin_gemini_files_capable_keys_root, is_admin_gemini_files_mappings_root,
is_admin_gemini_files_stats_root, is_admin_gemini_files_upload_root,
is_admin_global_models_root, is_admin_management_tokens_root,
is_admin_provider_ops_architectures_root, is_admin_provider_ops_batch_balance_root,
is_admin_provider_strategy_strategies_root, is_admin_providers_root,
is_admin_system_configs_root, is_admin_system_email_templates_root,
put_admin_provider_delete_task,
};
pub(crate) use self::catalog::{
build_admin_provider_key_response, decrypt_catalog_secret_with_fallbacks,
default_provider_key_status_snapshot, effective_catalog_encryption_key,
encrypt_catalog_secret_with_fallbacks, masked_catalog_api_key, parse_catalog_auth_config_json,
provider_key_health_summary, provider_key_status_snapshot_payload,
};
pub(crate) use self::payloads::{
default_admin_endpoint_max_retries, AdminBatchAssignGlobalModelsRequest,
AdminBatchAssignToProvidersRequest, AdminBatchDeleteIdsRequest, AdminGlobalModelCreateRequest,
AdminGlobalModelUpdateRequest, AdminImportProviderModelsRequest,
AdminOAuthProviderUpsertRequest, AdminProviderCreateRequest,
AdminProviderEndpointCreateRequest, AdminProviderEndpointUpdateRequest,
AdminProviderKeyBatchDeleteRequest, AdminProviderKeyCreateRequest,
AdminProviderKeyUpdateRequest, AdminProviderModelCreateRequest,
AdminProviderModelUpdateRequest, AdminProviderQuotaRefreshRequest, AdminProviderUpdateRequest,
InternalGatewayAuthContextRequest, InternalGatewayExecuteRequest,
InternalGatewayResolveRequest, InternalTunnelHeartbeatRequest, InternalTunnelNodeStatusRequest,
ANTIGRAVITY_FETCH_AVAILABLE_MODELS_PATH, CODEX_WHAM_USAGE_URL, KIRO_USAGE_LIMITS_PATH,
KIRO_USAGE_SDK_VERSION, OAUTH_ACCOUNT_BLOCK_PREFIX, OAUTH_EXPIRED_PREFIX,
OAUTH_REFRESH_FAILED_PREFIX, OAUTH_REQUEST_FAILED_PREFIX,
};
pub(crate) use self::request_utils::{
admin_proxy_local_requires_buffered_body, internal_proxy_local_requires_buffered_body,
json_string_list, local_proxy_route_requires_buffered_body,
mark_external_models_official_providers, public_support_local_requires_buffered_body,
query_param_bool, query_param_optional_bool, query_param_value,
request_enables_control_execute, rust_auth_terminates_provider_credentials,
sanitize_upstream_path_and_query, should_strip_forwarded_provider_credential_header,
should_strip_forwarded_trusted_admin_header, strip_query_param, unix_secs_to_rfc3339,
};

View File

@@ -1,4 +1,5 @@
use super::*;
use serde::Deserialize;
use std::collections::BTreeMap;
#[derive(Debug, Deserialize)]
pub(crate) struct AdminProviderKeyCreateRequest {
@@ -152,7 +153,7 @@ pub(crate) struct InternalTunnelNodeStatusRequest {
}
#[derive(Debug, Deserialize)]
pub(crate) struct LegacyGatewayResolveRequest {
pub(crate) struct InternalGatewayResolveRequest {
#[serde(default)]
pub(crate) trace_id: Option<String>,
pub(crate) method: String,
@@ -164,7 +165,7 @@ pub(crate) struct LegacyGatewayResolveRequest {
}
#[derive(Debug, Deserialize)]
pub(crate) struct LegacyGatewayAuthContextRequest {
pub(crate) struct InternalGatewayAuthContextRequest {
#[serde(default)]
pub(crate) trace_id: Option<String>,
#[serde(default)]
@@ -175,7 +176,7 @@ pub(crate) struct LegacyGatewayAuthContextRequest {
}
#[derive(Debug, Deserialize)]
pub(crate) struct LegacyGatewayExecuteRequest {
pub(crate) struct InternalGatewayExecuteRequest {
#[serde(default)]
pub(crate) trace_id: Option<String>,
pub(crate) method: String,

View File

@@ -1,4 +1,13 @@
use super::*;
use crate::gateway::constants::{
CONTROL_EXECUTE_FALLBACK_HEADER, TRUSTED_ADMIN_MANAGEMENT_TOKEN_ID_HEADER,
TRUSTED_ADMIN_SESSION_ID_HEADER, TRUSTED_ADMIN_USER_ID_HEADER, TRUSTED_ADMIN_USER_ROLE_HEADER,
};
use crate::gateway::handlers::OFFICIAL_EXTERNAL_MODEL_PROVIDERS;
use crate::gateway::headers::header_value_str;
use crate::gateway::{GatewayControlDecision, GatewayPublicRequestContext};
use axum::http::{self, HeaderName};
use chrono::{SecondsFormat, Utc};
use url::form_urlencoded;
pub(crate) fn rust_auth_terminates_provider_credentials(
decision: Option<&GatewayControlDecision>,
@@ -154,18 +163,11 @@ pub(crate) fn query_param_value(query: Option<&str>, key: &str) -> Option<String
}
pub(crate) fn request_enables_control_execute(headers: &http::HeaderMap) -> bool {
[
CONTROL_EXECUTE_FALLBACK_HEADER,
LEGACY_INTERNAL_GATEWAY_HEADER,
]
.into_iter()
.any(|header| {
header_value_str(headers, header).is_some_and(|value| {
matches!(
value.to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
header_value_str(headers, CONTROL_EXECUTE_FALLBACK_HEADER).is_some_and(|value| {
matches!(
value.to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
}
@@ -349,7 +351,7 @@ pub(crate) fn internal_proxy_local_requires_buffered_body(
Some(crate::gateway::TUNNEL_ROUTE_FAMILY),
Some("heartbeat" | "node_status")
) | (
Some("gateway_legacy"),
Some("internal_gateway"),
Some(
"resolve"
| "auth_context"
@@ -386,7 +388,7 @@ pub(crate) fn public_support_local_requires_buffered_body(
decision.route_kind.as_deref(),
),
(
Some("auth_legacy"),
Some("auth"),
http::Method::POST,
Some(
"login"
@@ -396,7 +398,7 @@ pub(crate) fn public_support_local_requires_buffered_body(
| "verification_status"
),
) | (
Some("users_me_legacy"),
Some("users_me"),
http::Method::PUT,
Some(
"update_detail"
@@ -408,19 +410,19 @@ pub(crate) fn public_support_local_requires_buffered_body(
| "api_key_capabilities_update",
),
) | (
Some("users_me_legacy"),
Some("users_me"),
http::Method::PATCH,
Some("password" | "session_update" | "api_key_patch"),
) | (
Some("users_me_legacy"),
Some("users_me"),
http::Method::POST,
Some("api_keys_create" | "management_tokens_create"),
) | (
Some("wallet_legacy"),
Some("wallet"),
http::Method::POST,
Some("create_refund" | "create_recharge_order"),
) | (
Some("payment_callback_legacy"),
Some("payment_callback"),
http::Method::POST,
Some("callback"),
)