feat(models): add external catalog proxy selection

This commit is contained in:
elky
2026-07-31 09:32:25 +08:00
parent 12057db476
commit beb003b7ad
34 changed files with 2286 additions and 176 deletions
@@ -1,3 +1,4 @@
use crate::handlers::admin::model::ADMIN_EXTERNAL_MODELS_PROXY_NODE_CONFIG_KEY;
use crate::handlers::admin::request::AdminAppState;
use crate::handlers::shared::unix_secs_to_rfc3339;
use crate::GatewayError;
@@ -17,6 +18,30 @@ use axum::body::Bytes;
use axum::http;
use serde_json::json;
const ADMIN_EXTERNAL_MODELS_CONFIG_ROUTE: &str = "/api/admin/models/external/config";
fn is_external_models_proxy_node_config_key(key: &str) -> bool {
key.trim()
.eq_ignore_ascii_case(ADMIN_EXTERNAL_MODELS_PROXY_NODE_CONFIG_KEY)
}
fn external_models_proxy_node_config_owner_error(
key: &str,
) -> Option<(http::StatusCode, serde_json::Value)> {
is_external_models_proxy_node_config_key(key).then(|| {
(
http::StatusCode::BAD_REQUEST,
json!({
"detail": format!(
"配置项 '{}' 由模型目录管理,请使用 {}",
ADMIN_EXTERNAL_MODELS_PROXY_NODE_CONFIG_KEY,
ADMIN_EXTERNAL_MODELS_CONFIG_ROUTE,
)
}),
)
})
}
fn normalize_admin_system_config_key(requested_key: &str) -> String {
normalize_admin_system_config_key_pure(requested_key)
}
@@ -51,7 +76,12 @@ fn legacy_admin_system_config_fallback_key(normalized_key: &str) -> Option<&'sta
pub(crate) fn build_admin_system_configs_payload(
entries: &[aether_data::repository::system::StoredSystemConfigEntry],
) -> serde_json::Value {
build_admin_system_configs_payload_pure(entries)
let visible_entries = entries
.iter()
.filter(|entry| !is_external_models_proxy_node_config_key(&entry.key))
.cloned()
.collect::<Vec<_>>();
build_admin_system_configs_payload_pure(&visible_entries)
}
pub(crate) async fn build_admin_system_config_detail_payload(
@@ -59,6 +89,9 @@ pub(crate) async fn build_admin_system_config_detail_payload(
requested_key: &str,
) -> Result<Result<serde_json::Value, (http::StatusCode, serde_json::Value)>, GatewayError> {
let requested_key = requested_key.trim();
if let Some(error) = external_models_proxy_node_config_owner_error(requested_key) {
return Ok(Err(error));
}
let normalized_key = normalize_admin_system_config_key(requested_key);
let mut value = state.read_system_config_json_value(&normalized_key).await?;
if value.is_none() {
@@ -78,6 +111,9 @@ pub(crate) async fn apply_admin_system_config_update(
requested_key: &str,
request_body: &Bytes,
) -> Result<Result<serde_json::Value, (http::StatusCode, serde_json::Value)>, GatewayError> {
if let Some(error) = external_models_proxy_node_config_owner_error(requested_key) {
return Ok(Err(error));
}
let update = match parse_admin_system_config_update(requested_key, request_body) {
Ok(update) => update,
Err(err) => return Ok(Err(err)),
@@ -123,6 +159,9 @@ pub(crate) async fn delete_admin_system_config(
state: &AdminAppState<'_>,
requested_key: &str,
) -> Result<Result<serde_json::Value, (http::StatusCode, serde_json::Value)>, GatewayError> {
if let Some(error) = external_models_proxy_node_config_owner_error(requested_key) {
return Ok(Err(error));
}
let delete_keys = admin_system_config_delete_keys(requested_key);
let mut deleted = false;
for key in &delete_keys {