refactor: 大规模模块拆分与代码精简,新增 ai-pipeline/data-contracts 独立 crate

- 新增 aether-ai-pipeline 和 aether-data-contracts crate,将 pipeline 逻辑与数据契约从 gateway 中解耦
- 重构 admin handlers:拆分单体模块为 auth/billing/endpoint/features/model/observability/provider/system 等独立子模块
- 合并 chat/cli 重复代码路径:精简 conversion、finalize、planner 中的 sync/chat/cli 分支
- 重构 scheduler/executor/data 层,引入 facade 模式降低模块间耦合
- 移除冗余的 intent 模块,将 plan_fallback/policy/stream_path/sync_path 迁移至 executor
- 前端适配:调整 admin API 调用和 provider 模型测试对话框
This commit is contained in:
fawney19
2026-04-07 02:50:19 +08:00
parent 763ff03a7b
commit 5d96d6673b
732 changed files with 28593 additions and 20666 deletions

View File

@@ -0,0 +1 @@
pub mod surfaces;

View File

@@ -0,0 +1,188 @@
pub const ANTIGRAVITY_PROVIDER_TYPE: &str = "antigravity";
pub const KIRO_PROVIDER_TYPE: &str = "kiro";
pub const KIRO_ENVELOPE_NAME: &str = "kiro:generateAssistantResponse";
pub const ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME: &str = "antigravity:v1internal";
pub const GEMINI_CLI_V1INTERNAL_ENVELOPE_NAME: &str = "gemini_cli:v1internal";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProviderAdaptationSurface {
AntigravityGeminiChat,
AntigravityGeminiCli,
GeminiCliV1Internal,
KiroClaudeCli,
}
#[derive(Debug, Clone, Copy)]
pub struct ProviderAdaptationDescriptor {
pub surface: ProviderAdaptationSurface,
pub provider_type: Option<&'static str>,
pub envelope_name: &'static str,
pub anchor_api_format: &'static str,
pub supports_request_bridge: bool,
pub supports_sync_finalize_bridge: bool,
pub supports_stream_bridge: bool,
pub requires_eventstream_accept: bool,
pub unwraps_response_envelope: bool,
}
const PROVIDER_ADAPTATION_SURFACES: &[ProviderAdaptationDescriptor] = &[
ProviderAdaptationDescriptor {
surface: ProviderAdaptationSurface::AntigravityGeminiChat,
provider_type: Some(ANTIGRAVITY_PROVIDER_TYPE),
envelope_name: ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME,
anchor_api_format: "gemini:chat",
supports_request_bridge: true,
supports_sync_finalize_bridge: true,
supports_stream_bridge: true,
requires_eventstream_accept: false,
unwraps_response_envelope: true,
},
ProviderAdaptationDescriptor {
surface: ProviderAdaptationSurface::AntigravityGeminiCli,
provider_type: Some(ANTIGRAVITY_PROVIDER_TYPE),
envelope_name: ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME,
anchor_api_format: "gemini:cli",
supports_request_bridge: true,
supports_sync_finalize_bridge: true,
supports_stream_bridge: true,
requires_eventstream_accept: false,
unwraps_response_envelope: true,
},
ProviderAdaptationDescriptor {
surface: ProviderAdaptationSurface::GeminiCliV1Internal,
provider_type: None,
envelope_name: GEMINI_CLI_V1INTERNAL_ENVELOPE_NAME,
anchor_api_format: "gemini:cli",
supports_request_bridge: false,
supports_sync_finalize_bridge: true,
supports_stream_bridge: true,
requires_eventstream_accept: false,
unwraps_response_envelope: true,
},
ProviderAdaptationDescriptor {
surface: ProviderAdaptationSurface::KiroClaudeCli,
provider_type: Some(KIRO_PROVIDER_TYPE),
envelope_name: KIRO_ENVELOPE_NAME,
anchor_api_format: "claude:cli",
supports_request_bridge: true,
supports_sync_finalize_bridge: true,
supports_stream_bridge: true,
requires_eventstream_accept: true,
unwraps_response_envelope: false,
},
];
pub fn provider_adaptation_descriptor_for_envelope(
envelope_name: &str,
provider_api_format: &str,
) -> Option<&'static ProviderAdaptationDescriptor> {
let envelope_name = envelope_name.trim();
let provider_api_format = provider_api_format.trim().to_ascii_lowercase();
PROVIDER_ADAPTATION_SURFACES.iter().find(|descriptor| {
descriptor.envelope_name.eq_ignore_ascii_case(envelope_name)
&& descriptor
.anchor_api_format
.eq_ignore_ascii_case(provider_api_format.as_str())
})
}
pub fn provider_adaptation_descriptor_for_provider_type(
provider_type: &str,
provider_api_format: &str,
) -> Option<&'static ProviderAdaptationDescriptor> {
let provider_type = provider_type.trim();
let provider_api_format = provider_api_format.trim().to_ascii_lowercase();
PROVIDER_ADAPTATION_SURFACES.iter().find(|descriptor| {
descriptor
.provider_type
.is_some_and(|value| value.eq_ignore_ascii_case(provider_type))
&& descriptor
.anchor_api_format
.eq_ignore_ascii_case(provider_api_format.as_str())
})
}
pub fn provider_adaptation_anchor_api_format(
envelope_name: &str,
provider_api_format: &str,
) -> Option<&'static str> {
provider_adaptation_descriptor_for_envelope(envelope_name, provider_api_format)
.map(|descriptor| descriptor.anchor_api_format)
}
pub fn provider_adaptation_allows_sync_finalize_envelope(
envelope_name: &str,
provider_api_format: &str,
) -> bool {
provider_adaptation_descriptor_for_envelope(envelope_name, provider_api_format)
.is_some_and(|descriptor| descriptor.supports_sync_finalize_bridge)
}
pub fn provider_adaptation_requires_eventstream_accept(
envelope_name: Option<&str>,
provider_api_format: &str,
) -> bool {
envelope_name
.and_then(|value| provider_adaptation_descriptor_for_envelope(value, provider_api_format))
.is_some_and(|descriptor| descriptor.requires_eventstream_accept)
}
pub fn provider_adaptation_should_unwrap_stream_envelope(
envelope_name: &str,
provider_api_format: &str,
) -> bool {
provider_adaptation_descriptor_for_envelope(envelope_name, provider_api_format)
.is_some_and(|descriptor| descriptor.unwraps_response_envelope)
}
#[cfg(test)]
mod tests {
use super::{
provider_adaptation_allows_sync_finalize_envelope, provider_adaptation_anchor_api_format,
provider_adaptation_requires_eventstream_accept,
provider_adaptation_should_unwrap_stream_envelope, ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME,
GEMINI_CLI_V1INTERNAL_ENVELOPE_NAME, KIRO_ENVELOPE_NAME,
};
#[test]
fn resolves_private_surface_anchor_contracts() {
assert_eq!(
provider_adaptation_anchor_api_format(
ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME,
"gemini:cli"
),
Some("gemini:cli")
);
assert_eq!(
provider_adaptation_anchor_api_format(
GEMINI_CLI_V1INTERNAL_ENVELOPE_NAME,
"gemini:cli"
),
Some("gemini:cli")
);
assert_eq!(
provider_adaptation_anchor_api_format(KIRO_ENVELOPE_NAME, "claude:cli"),
Some("claude:cli")
);
}
#[test]
fn exposes_private_surface_capabilities() {
assert!(provider_adaptation_allows_sync_finalize_envelope(
ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME,
"gemini:chat"
));
assert!(provider_adaptation_should_unwrap_stream_envelope(
GEMINI_CLI_V1INTERNAL_ENVELOPE_NAME,
"gemini:cli"
));
assert!(provider_adaptation_requires_eventstream_accept(
Some(KIRO_ENVELOPE_NAME),
"claude:cli"
));
assert!(!provider_adaptation_requires_eventstream_accept(
Some(ANTIGRAVITY_V1INTERNAL_ENVELOPE_NAME),
"gemini:cli"
));
}
}