mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 08:27:46 +08:00
fix(kiro,pool,model): 对齐 Kiro 管理链路并修复全局模型删除行为 (#305)
* 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]>
This commit is contained in:
@@ -3,6 +3,8 @@ use crate::handlers::admin::provider::shared::support::{
|
||||
};
|
||||
use crate::handlers::admin::request::AdminAppState;
|
||||
use crate::handlers::admin::shared::{provider_key_status_snapshot_payload, unix_secs_to_rfc3339};
|
||||
use crate::provider_key_auth::provider_key_auth_semantics;
|
||||
use aether_admin::provider::pool as admin_provider_pool_pure;
|
||||
use aether_data_contracts::repository::provider_catalog::StoredProviderCatalogKey;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -122,10 +124,11 @@ fn admin_pool_normalize_oauth_plan_type(value: &str, provider_type: &str) -> Opt
|
||||
}
|
||||
|
||||
fn admin_pool_derive_oauth_expires_at(
|
||||
provider_type: &str,
|
||||
key: &StoredProviderCatalogKey,
|
||||
auth_config: Option<&serde_json::Map<String, serde_json::Value>>,
|
||||
) -> Option<u64> {
|
||||
if !key.auth_type.trim().eq_ignore_ascii_case("oauth") {
|
||||
if !provider_key_auth_semantics(key, provider_type).oauth_managed() {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ fn admin_pool_derive_oauth_plan_type(
|
||||
provider_type: &str,
|
||||
auth_config: Option<&serde_json::Map<String, serde_json::Value>>,
|
||||
) -> Option<String> {
|
||||
if !key.auth_type.trim().eq_ignore_ascii_case("oauth") {
|
||||
if !provider_key_auth_semantics(key, provider_type).oauth_managed() {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -551,6 +554,7 @@ fn admin_pool_scheduling_payload(
|
||||
cooldown_ttl_seconds: Option<u64>,
|
||||
health_score: f64,
|
||||
circuit_breaker_open: bool,
|
||||
account_quota_exhausted: bool,
|
||||
) -> (String, String, String, Vec<serde_json::Value>) {
|
||||
if !key.is_active {
|
||||
return (
|
||||
@@ -567,6 +571,21 @@ fn admin_pool_scheduling_payload(
|
||||
})],
|
||||
);
|
||||
}
|
||||
if account_quota_exhausted {
|
||||
return (
|
||||
"blocked".to_string(),
|
||||
"account_quota_exhausted".to_string(),
|
||||
"额度耗尽".to_string(),
|
||||
vec![json!({
|
||||
"code": "account_quota_exhausted",
|
||||
"label": "额度耗尽",
|
||||
"blocking": true,
|
||||
"source": "quota",
|
||||
"ttl_seconds": serde_json::Value::Null,
|
||||
"detail": serde_json::Value::Null,
|
||||
})],
|
||||
);
|
||||
}
|
||||
if let Some(reason) = cooldown_reason {
|
||||
return (
|
||||
"degraded".to_string(),
|
||||
@@ -632,6 +651,9 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
.and_then(|_| runtime.cooldown_ttl_by_key.get(&key.id).copied());
|
||||
let health_score = admin_pool_health_score(key);
|
||||
let circuit_breaker_open = admin_pool_circuit_breaker_open(key);
|
||||
let auth_semantics = provider_key_auth_semantics(key, provider_type);
|
||||
let account_quota_exhausted = pool_config.is_some_and(|config| config.skip_exhausted_accounts)
|
||||
&& admin_provider_pool_pure::admin_pool_key_account_quota_exhausted(key, provider_type);
|
||||
let (scheduling_status, scheduling_reason, scheduling_label, scheduling_reasons) =
|
||||
admin_pool_scheduling_payload(
|
||||
key,
|
||||
@@ -639,9 +661,11 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
cooldown_ttl_seconds,
|
||||
health_score,
|
||||
circuit_breaker_open,
|
||||
account_quota_exhausted,
|
||||
);
|
||||
let auth_config = state.parse_catalog_auth_config_json(key);
|
||||
let oauth_expires_at = admin_pool_derive_oauth_expires_at(key, auth_config.as_ref());
|
||||
let oauth_expires_at =
|
||||
admin_pool_derive_oauth_expires_at(provider_type, key, auth_config.as_ref());
|
||||
let oauth_plan_type =
|
||||
admin_pool_derive_oauth_plan_type(key, provider_type, auth_config.as_ref());
|
||||
let status_snapshot = provider_key_status_snapshot_payload(key);
|
||||
@@ -656,15 +680,29 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
.and_then(serde_json::Value::as_object);
|
||||
let quota_updated_at =
|
||||
admin_pool_json_to_u64(quota_snapshot.and_then(|item| item.get("updated_at")));
|
||||
let oauth_invalid_at =
|
||||
let oauth_invalid_at = if auth_semantics.can_show_oauth_metadata() {
|
||||
admin_pool_json_to_u64(oauth_snapshot.and_then(|item| item.get("invalid_at")))
|
||||
.or(key.oauth_invalid_at_unix_secs);
|
||||
let oauth_account_id = admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_id");
|
||||
let oauth_account_name =
|
||||
admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_name");
|
||||
let oauth_account_user_id =
|
||||
admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_user_id");
|
||||
let oauth_organizations = admin_pool_oauth_organizations(auth_config.as_ref());
|
||||
.or(key.oauth_invalid_at_unix_secs)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let oauth_account_id = auth_semantics
|
||||
.can_show_oauth_metadata()
|
||||
.then(|| admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_id"))
|
||||
.flatten();
|
||||
let oauth_account_name = auth_semantics
|
||||
.can_show_oauth_metadata()
|
||||
.then(|| admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_name"))
|
||||
.flatten();
|
||||
let oauth_account_user_id = auth_semantics
|
||||
.can_show_oauth_metadata()
|
||||
.then(|| admin_pool_trimmed_string_from_map(auth_config.as_ref(), "account_user_id"))
|
||||
.flatten();
|
||||
let oauth_organizations = if auth_semantics.can_show_oauth_metadata() {
|
||||
admin_pool_oauth_organizations(auth_config.as_ref())
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let account_status_code = admin_pool_trimmed_string_from_map(account_snapshot, "code");
|
||||
let account_status_label =
|
||||
admin_pool_trimmed_string(account_snapshot.and_then(|item| item.get("label")));
|
||||
@@ -686,11 +724,38 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
payload.insert("key_name".to_string(), json!(key.name));
|
||||
payload.insert("is_active".to_string(), json!(key.is_active));
|
||||
payload.insert("auth_type".to_string(), json!(key.auth_type));
|
||||
payload.insert(
|
||||
"credential_kind".to_string(),
|
||||
json!(auth_semantics.credential_kind().as_str()),
|
||||
);
|
||||
payload.insert(
|
||||
"runtime_auth_kind".to_string(),
|
||||
json!(auth_semantics.runtime_auth_kind().as_str()),
|
||||
);
|
||||
payload.insert(
|
||||
"oauth_managed".to_string(),
|
||||
json!(auth_semantics.oauth_managed()),
|
||||
);
|
||||
payload.insert(
|
||||
"can_refresh_oauth".to_string(),
|
||||
json!(auth_semantics.can_refresh_oauth()),
|
||||
);
|
||||
payload.insert(
|
||||
"can_export_oauth".to_string(),
|
||||
json!(auth_semantics.can_export_oauth()),
|
||||
);
|
||||
payload.insert(
|
||||
"can_edit_oauth".to_string(),
|
||||
json!(auth_semantics.can_edit_oauth()),
|
||||
);
|
||||
payload.insert("oauth_expires_at".to_string(), json!(oauth_expires_at));
|
||||
payload.insert("oauth_invalid_at".to_string(), json!(oauth_invalid_at));
|
||||
payload.insert(
|
||||
"oauth_invalid_reason".to_string(),
|
||||
json!(key.oauth_invalid_reason),
|
||||
json!(auth_semantics
|
||||
.can_show_oauth_metadata()
|
||||
.then_some(key.oauth_invalid_reason.clone())
|
||||
.flatten()),
|
||||
);
|
||||
payload.insert("oauth_plan_type".to_string(), json!(oauth_plan_type));
|
||||
payload.insert("oauth_account_id".to_string(), json!(oauth_account_id));
|
||||
|
||||
Reference in New Issue
Block a user