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,6 @@
mod types;
pub use types::{
ProviderQuotaReadRepository, ProviderQuotaRepository, ProviderQuotaWriteRepository,
StoredProviderQuotaSnapshot,
};

View File

@@ -0,0 +1,71 @@
use async_trait::async_trait;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct StoredProviderQuotaSnapshot {
pub provider_id: String,
pub billing_type: String,
pub monthly_quota_usd: Option<f64>,
pub monthly_used_usd: f64,
pub quota_reset_day: Option<u64>,
pub quota_last_reset_at_unix_secs: Option<u64>,
pub quota_expires_at_unix_secs: Option<u64>,
pub is_active: bool,
}
impl StoredProviderQuotaSnapshot {
#[allow(clippy::too_many_arguments)]
pub fn new(
provider_id: String,
billing_type: String,
monthly_quota_usd: Option<f64>,
monthly_used_usd: f64,
quota_reset_day: Option<i32>,
quota_last_reset_at_unix_secs: Option<i64>,
quota_expires_at_unix_secs: Option<i64>,
is_active: bool,
) -> Result<Self, crate::DataLayerError> {
if provider_id.trim().is_empty() || billing_type.trim().is_empty() {
return Err(crate::DataLayerError::UnexpectedValue(
"provider quota identity is empty".to_string(),
));
}
if !monthly_used_usd.is_finite() || monthly_quota_usd.is_some_and(|v| !v.is_finite()) {
return Err(crate::DataLayerError::UnexpectedValue(
"provider quota value is not finite".to_string(),
));
}
Ok(Self {
provider_id,
billing_type,
monthly_quota_usd,
monthly_used_usd,
quota_reset_day: quota_reset_day.map(|value| value as u64),
quota_last_reset_at_unix_secs: quota_last_reset_at_unix_secs.map(|value| value as u64),
quota_expires_at_unix_secs: quota_expires_at_unix_secs.map(|value| value as u64),
is_active,
})
}
}
#[async_trait]
pub trait ProviderQuotaReadRepository: Send + Sync {
async fn find_by_provider_id(
&self,
provider_id: &str,
) -> Result<Option<StoredProviderQuotaSnapshot>, crate::DataLayerError>;
}
#[async_trait]
pub trait ProviderQuotaWriteRepository: Send + Sync {
async fn reset_due(&self, now_unix_secs: u64) -> Result<usize, crate::DataLayerError>;
}
pub trait ProviderQuotaRepository:
ProviderQuotaReadRepository + ProviderQuotaWriteRepository + Send + Sync
{
}
impl<T> ProviderQuotaRepository for T where
T: ProviderQuotaReadRepository + ProviderQuotaWriteRepository + Send + Sync
{
}