mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-11 03:39:49 +08:00
* feat(pool): 号池支持跳过额度耗尽账号 - 新增 pool_advanced.skip_exhausted_accounts 开关及高级设置 UI, 默认关闭并兼容旧配置 - 为 Codex/Kiro 增加额度耗尽判定, 接入请求侧候选跳过并新增 account_quota_exhausted skip reason - 号池列表将额度耗尽账号标记为 blocked/额度耗尽, 并补充前后端相关测试 * fix(kiro): 对齐账号管理与 provider-query 的 Rust 行为 - 修复 Kiro 单条导入误走 import-refresh-token 的前端分流, 并为误用路径返回明确错误提示 - 为 Kiro 导入与本地请求链补齐 bearer 兼容, 同步放开账号启停等 Key 更新操作的 auth_type 校验 - 实现 Kiro provider-query 本地模型测试与 failover 执行链, 并修复结果弹窗在无 trace 时无法展示 attempts/响应体的问题 * fix(model): 删除全局模型时级联清理关联提供商模型 - 对齐 Python 版本删除逻辑, GlobalModel 删除前先在事务内清理关联的 Provider Model 记录 - 修复已绑定 Provider 的模型在 Rust SQL 仓库下会被外键约束拦住、无法正常删除的问题 - 增加管理端回归测试, 覆盖绑定 Provider Model 的 GlobalModel 删除场景 * fix(kiro,ci): 恢复 Kiro OAuth 持久化并修复 Rust CI * Fix oauth-managed provider key semantics --------- Co-authored-by: fawney19 <[email protected]>
127 lines
4.1 KiB
Rust
127 lines
4.1 KiB
Rust
use crate::handlers::admin::request::AdminAppState;
|
|
use crate::provider_key_auth::provider_key_is_oauth_managed;
|
|
use aether_admin::provider::pool as admin_provider_pool_pure;
|
|
use aether_data_contracts::repository::provider_catalog::StoredProviderCatalogKey;
|
|
|
|
pub(super) fn admin_pool_normalize_text(value: impl AsRef<str>) -> String {
|
|
admin_provider_pool_pure::admin_pool_normalize_text(value)
|
|
}
|
|
|
|
fn admin_pool_parse_auth_config_json(
|
|
state: &AdminAppState<'_>,
|
|
key: &StoredProviderCatalogKey,
|
|
) -> Option<serde_json::Map<String, serde_json::Value>> {
|
|
let ciphertext = key.encrypted_auth_config.as_deref()?.trim();
|
|
if ciphertext.is_empty() {
|
|
return None;
|
|
}
|
|
let plaintext = state.decrypt_catalog_secret_with_fallbacks(ciphertext)?;
|
|
serde_json::from_str::<serde_json::Value>(&plaintext)
|
|
.ok()?
|
|
.as_object()
|
|
.cloned()
|
|
}
|
|
|
|
fn admin_pool_derive_oauth_plan_type(
|
|
state: &AdminAppState<'_>,
|
|
key: &StoredProviderCatalogKey,
|
|
provider_type: &str,
|
|
) -> Option<String> {
|
|
let normalize = |value: &str| {
|
|
let mut text = value.trim().to_string();
|
|
if text.is_empty() {
|
|
return None;
|
|
}
|
|
let provider_type = provider_type.trim().to_ascii_lowercase();
|
|
if !provider_type.is_empty() && text.to_ascii_lowercase().starts_with(&provider_type) {
|
|
text = text[provider_type.len()..]
|
|
.trim_matches(|ch: char| [' ', ':', '-', '_'].contains(&ch))
|
|
.to_string();
|
|
}
|
|
if text.is_empty() {
|
|
None
|
|
} else {
|
|
Some(text.to_ascii_lowercase())
|
|
}
|
|
};
|
|
|
|
if !provider_key_is_oauth_managed(key, provider_type) {
|
|
return None;
|
|
}
|
|
|
|
if let Some(upstream_metadata) = key
|
|
.upstream_metadata
|
|
.as_ref()
|
|
.and_then(serde_json::Value::as_object)
|
|
{
|
|
let provider_bucket = upstream_metadata
|
|
.get(&provider_type.trim().to_ascii_lowercase())
|
|
.and_then(serde_json::Value::as_object);
|
|
for source in provider_bucket
|
|
.into_iter()
|
|
.chain(std::iter::once(upstream_metadata))
|
|
{
|
|
for plan_key in [
|
|
"plan_type",
|
|
"tier",
|
|
"subscription_title",
|
|
"subscription_plan",
|
|
] {
|
|
if let Some(value) = source.get(plan_key).and_then(serde_json::Value::as_str) {
|
|
if let Some(normalized) = normalize(value) {
|
|
return Some(normalized);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if let Some(auth_config) = admin_pool_parse_auth_config_json(state, key) {
|
|
for plan_key in ["plan_type", "tier", "plan", "subscription_plan"] {
|
|
if let Some(value) = auth_config
|
|
.get(plan_key)
|
|
.and_then(serde_json::Value::as_str)
|
|
{
|
|
if let Some(normalized) = normalize(value) {
|
|
return Some(normalized);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
pub(super) fn admin_pool_matches_quick_selector(
|
|
state: &AdminAppState<'_>,
|
|
key: &StoredProviderCatalogKey,
|
|
provider_type: &str,
|
|
selector: &str,
|
|
) -> bool {
|
|
let oauth_plan_type = admin_pool_derive_oauth_plan_type(state, key, provider_type);
|
|
admin_provider_pool_pure::admin_pool_matches_quick_selector(
|
|
key,
|
|
selector,
|
|
oauth_plan_type.as_deref(),
|
|
admin_provider_pool_pure::admin_pool_now_unix_secs(),
|
|
)
|
|
}
|
|
|
|
pub(super) fn admin_pool_matches_search(
|
|
state: &AdminAppState<'_>,
|
|
key: &StoredProviderCatalogKey,
|
|
provider_type: &str,
|
|
search: Option<&str>,
|
|
) -> bool {
|
|
let oauth_plan_type = admin_pool_derive_oauth_plan_type(state, key, provider_type);
|
|
admin_provider_pool_pure::admin_pool_matches_search(key, search, oauth_plan_type.as_deref())
|
|
}
|
|
|
|
pub(super) fn admin_pool_key_is_known_banned(key: &StoredProviderCatalogKey) -> bool {
|
|
admin_provider_pool_pure::admin_pool_key_is_known_banned(key)
|
|
}
|
|
|
|
pub(super) fn admin_pool_sort_keys(keys: &mut [StoredProviderCatalogKey]) {
|
|
admin_provider_pool_pure::admin_pool_sort_keys(keys);
|
|
}
|