refactor(model-permissions): 简化 allowed_models 为纯列表格式

移除按 API 格式区分的字典模式(Dict[str, List[str]]),统一使用简单列表格式。

- 删除 normalize_allowed_models 的 api_format 参数
- 删除 check_model_allowed 的 api_format 参数
- 简化 merge_allowed_models 为直接列表交集
- 移除前端的字典模式兼容代码和警告 UI
- 删除 is_format_mode、convert_to_format_mode 等辅助函数
This commit is contained in:
fawney19
2026-01-14 17:57:21 +08:00
parent 133f3108f0
commit b272109055
9 changed files with 62 additions and 345 deletions

View File

@@ -223,12 +223,10 @@ class AdminUpdateEndpointKeyAdapter(AdminApiAdapter):
update_data["learned_rpm_limit"] = None
logger.info("Key %s 切换为自适应 RPM 模式", self.key_id)
# 统一处理 allowed_models空列表/空字典 -> None表示不限制
# 统一处理 allowed_models空列表 -> None表示不限制
if "allowed_models" in update_data:
am = update_data["allowed_models"]
if am is not None and (
(isinstance(am, list) and len(am) == 0) or (isinstance(am, dict) and len(am) == 0)
):
if isinstance(am, list) and len(am) == 0:
update_data["allowed_models"] = None
# 统一处理 locked_models空列表 -> None

View File

@@ -310,19 +310,12 @@ class AdminGetModelRoutingPreviewAdapter(AdminApiAdapter):
next_probe_at = fmt_next_probe
# 解析 allowed_models
# 语义说明:
# - None: 不限制(允许所有模型)
# - {}: 空字典 = 不限制normalize_allowed_models 返回 None
# - []: 空列表 = 拒绝所有模型
# - {"CLAUDE": []}: 指定格式空列表 = 该格式拒绝所有
raw_allowed_models = key.allowed_models
if raw_allowed_models is None:
allowed_models_list = None
elif isinstance(raw_allowed_models, dict) and not raw_allowed_models:
# 空 dict {} 在语义上等价于不限制
allowed_models_list = None
else:
allowed_models_list = parse_allowed_models_to_list(raw_allowed_models)
allowed_models_list = (
parse_allowed_models_to_list(raw_allowed_models)
if raw_allowed_models
else None
)
key_infos.append(
RoutingKeyInfo(