refactor: 移除独立 hub/proxy/executor/gateway crate,统一为 gateway tunnel 架构

- 删除 aether-hub、aether-proxy 独立项目及其 Dockerfile/配置
- 删除 crates/aether-executor 和 crates/aether-gateway 全部模块
- 新增 apps/ 目录作为应用入口
- 将 hub 概念重构为 gateway tunnel transport
- 将 executor 重构为 execution runtime
- 新增 tunnel.rs 合约定义和 testkit tunnel/execution_runtime 模块
- 更新 Python 服务层和测试适配新架构命名
This commit is contained in:
fawney19
2026-04-03 14:59:58 +08:00
parent ddf18fed9a
commit 8f26e1a31f
983 changed files with 103098 additions and 105837 deletions

View File

@@ -0,0 +1,111 @@
use super::*;
pub(super) fn request_wants_stream(
request_context: &GatewayPublicRequestContext,
body: &axum::body::Bytes,
) -> bool {
if request_context
.request_path
.contains(":streamGenerateContent")
{
return true;
}
if !request_context
.request_content_type
.as_deref()
.map(|value| value.to_ascii_lowercase().contains("application/json"))
.unwrap_or(false)
|| body.is_empty()
{
return false;
}
serde_json::from_slice::<serde_json::Value>(body)
.ok()
.and_then(|value| value.get("stream").and_then(|stream| stream.as_bool()))
.unwrap_or(false)
}
pub(super) fn finalize_gateway_response(
state: &AppState,
mut response: Response<Body>,
trace_id: &str,
remote_addr: &std::net::SocketAddr,
method: &http::Method,
path_and_query: &str,
control_decision: Option<&GatewayControlDecision>,
execution_path: &'static str,
started_at: &Instant,
request_permit: Option<AdmissionPermit>,
) -> Response<Body> {
response.headers_mut().insert(
HeaderName::from_static(EXECUTION_PATH_HEADER),
HeaderValue::from_static(execution_path),
);
let elapsed_ms = started_at.elapsed().as_millis() as u64;
let python_dependency_reason = response
.headers()
.get(PYTHON_DEPENDENCY_REASON_HEADER)
.and_then(|value| value.to_str().ok())
.unwrap_or("none");
let local_execution_runtime_miss_reason = response
.headers()
.get(LOCAL_EXECUTION_RUNTIME_MISS_REASON_HEADER)
.or_else(|| {
response
.headers()
.get(LOCAL_LEGACY_EXECUTION_RUNTIME_MISS_REASON_HEADER)
})
.and_then(|value| value.to_str().ok())
.unwrap_or("none");
info!(
trace_id = %trace_id,
remote_addr = %remote_addr,
method = %method,
path = %path_and_query,
route_class = control_decision
.and_then(|decision| decision.route_class.as_deref())
.unwrap_or("passthrough"),
execution_path,
python_dependency_reason,
local_execution_runtime_miss_reason,
status = response.status().as_u16(),
elapsed_ms,
"gateway completed request"
);
record_shadow_result_non_blocking(
state.clone(),
trace_id,
method,
path_and_query,
control_decision,
execution_path,
&response,
);
maybe_hold_axum_response_permit(response, request_permit)
}
pub(super) fn finalize_gateway_response_with_context(
state: &AppState,
response: Response<Body>,
remote_addr: &std::net::SocketAddr,
request_context: &GatewayPublicRequestContext,
execution_path: &'static str,
started_at: &Instant,
request_permit: Option<AdmissionPermit>,
) -> Response<Body> {
finalize_gateway_response(
state,
response,
&request_context.trace_id,
remote_addr,
&request_context.request_method,
&request_context.request_path_and_query(),
request_context.control_decision.as_ref(),
execution_path,
started_at,
request_permit,
)
}

View File

@@ -0,0 +1,209 @@
use super::*;
pub(super) async fn maybe_build_local_internal_proxy_response(
state: &AppState,
request_context: &GatewayPublicRequestContext,
remote_addr: &std::net::SocketAddr,
request_body: Option<&axum::body::Bytes>,
legacy_internal_gateway_allowed: bool,
) -> Result<Option<Response<Body>>, GatewayError> {
let response = maybe_build_local_internal_proxy_response_impl(
state,
request_context,
remote_addr,
request_body,
legacy_internal_gateway_allowed,
)
.await?;
if request_context
.control_decision
.as_ref()
.and_then(|decision| decision.route_family.as_deref())
== Some("gateway_legacy")
{
return Ok(response.map(attach_legacy_internal_gateway_deprecation_headers));
}
Ok(response)
}
pub(super) async fn maybe_build_local_admin_proxy_response(
state: &AppState,
request_context: &GatewayPublicRequestContext,
request_body: Option<&axum::body::Bytes>,
) -> Result<Option<Response<Body>>, GatewayError> {
let Some(decision) = request_context.control_decision.as_ref() else {
return Ok(None);
};
if decision.route_class.as_deref() != Some("admin_proxy") {
return Ok(None);
}
if decision.admin_principal.is_none() {
return Ok(None);
}
if let Some(response) =
super::admin_provider_oauth_dispatch::maybe_build_local_admin_provider_oauth_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) = super::public_support::maybe_build_local_admin_announcements_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) = super::admin_core::maybe_build_local_admin_core_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) =
super::admin_global_models::maybe_build_local_admin_global_models_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) =
super::admin_provider_models::maybe_build_local_admin_provider_models_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) = super::admin_providers::maybe_build_local_admin_providers_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_provider_ops_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_adaptive_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_provider_strategy_response(state, request_context, request_body)
.await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_pool_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_billing_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_payments_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_provider_query_response(state, request_context, request_body)
.await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_security_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) = maybe_build_local_admin_stats_response(state, request_context).await? {
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_monitoring_response(state, request_context).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_usage_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_video_tasks_response(state, request_context).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_proxy_nodes_response(state, request_context).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_wallets_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_api_keys_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_ldap_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_gemini_files_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) =
maybe_build_local_admin_users_response(state, request_context, request_body).await?
{
return Ok(Some(response));
}
if let Some(response) = super::admin_endpoints::maybe_build_local_admin_endpoints_response(
state,
request_context,
request_body,
)
.await?
{
return Ok(Some(response));
}
Ok(None)
}