mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-10-03 23:54:06 +00:00
fix(gateway): AUTO 被密钥模型范围拦下时报错误导 + 编辑器给出提示
一个密钥的模型范围不含 AUTO 时,它用不了 AUTO —— 范围过滤发生在链之前。 但这两条路径都不说真话: 1. 请求侧:AUTO 走的是通用分支,返回 model_not_found "model \"AUTO\" is not configured",读起来像 AUTO 没配置。非 AUTO 模型早就有 model_not_allowed 的专门提示,AUTO 漏了。补上,并说明修法(把 AUTO 加进该密钥的 models, 或去掉范围限制)。 2. 编辑器侧:per-key AUTO 链编辑器可以正常配链、保存也成功,看起来一切正常, 但该密钥的每个请求都会 403。管理员无从得知。现在弹窗顶部在检测到冲突时 显示警告,并列出当前范围。 刻意不做的事:不自动把 AUTO 加进该密钥的模型范围。那等于悄悄授予运营 没要求的访问权,比一个显眼的警告更糟。 判据 1 条,除确认提示出现外还断言该函数体内没有 PUT/POST/fetch/api —— 它只报告,不得写回。变异(去掉 AUTO 判断)判红。 CDP 实测四种场景:范围含 AUTO → 无提示;范围不含 → 警告并列出范围; 空范围(不受限)→ 无提示;范围含 AUTO → 无提示。 Co-Authored-By: ModelRouter <noreply@modelrouter.dev>
This commit is contained in:
@ -517,7 +517,20 @@
|
||||
#toast{left:12px;right:12px;bottom:12px;text-align:center}
|
||||
th,td{padding:8px 10px}
|
||||
}
|
||||
</style>
|
||||
|
||||
/* Shown when a key's model scope blocks AUTO: the chain editor can look
|
||||
fine while every request 403s, so the conflict must be visible here. */
|
||||
.warn-box {
|
||||
margin: 0 0 10px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(224, 108, 51, 0.45);
|
||||
background: rgba(224, 108, 51, 0.1);
|
||||
color: #b45309;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="bgfx" aria-hidden="true">
|
||||
@ -835,6 +848,7 @@
|
||||
kAutoChainSeeded: "已复制全局 AUTO 链作为编辑起点,保存后该密钥将使用这条独立链",
|
||||
kAutoChainNewOwn: "该密钥当前跟随全局链,保存后改用这里配置的独立链",
|
||||
kAutoChainWillInherit: "保存后该密钥将恢复跟随全局 AUTO 链",
|
||||
kAutoChainScopeWarn: "警告:该密钥的模型范围不包含 AUTO,配了独立 AUTO 链也用不了。当前范围:",
|
||||
kAutoChainBad: "已保存,但槽位无法解析(模型与源的组合不存在),AUTO 请求会失败",
|
||||
kName: "名称",
|
||||
kRole: "角色",
|
||||
@ -1109,6 +1123,7 @@
|
||||
kAutoChainSeeded: "Copied the global AUTO chain as a starting point — saving gives this key its own chain",
|
||||
kAutoChainNewOwn: "This key currently follows the global chain; saving switches it to the chain configured here",
|
||||
kAutoChainWillInherit: "Saving makes this key follow the global AUTO chain again",
|
||||
kAutoChainScopeWarn: "Warning: this key\u2019s model scope does not include AUTO, so a per-key AUTO chain will still be rejected. Current scope: ",
|
||||
kAutoChainBad: "Saved, but the slot does not resolve (no source serves that model); AUTO requests will fail",
|
||||
kName: "Name",
|
||||
kRole: "Role",
|
||||
@ -4811,8 +4826,11 @@ function afterChainEdit() {
|
||||
async function loadKeys() {
|
||||
const el = $("#k-list");
|
||||
if (!el) return;
|
||||
const j = await api("/api/keys");
|
||||
const j = await api("/api/keys");
|
||||
const ks = j.keys || [];
|
||||
// Cached so the per-key AUTO editor can read a key's model scope
|
||||
// without a second request (keyAutoScopeWarning).
|
||||
window._keyRows = ks;
|
||||
el.innerHTML = ks.length
|
||||
? ks.map((k) => keyCanvasHtml(k)).join("")
|
||||
: `<div class="muted">${t("kEmpty")}</div>`;
|
||||
@ -5268,6 +5286,7 @@ function afterChainEdit() {
|
||||
wrap.innerHTML = `<div class="card" style="width:900px;max-width:100%">
|
||||
<h2>${esc(t("kAutoChainTitle"))} \u00b7 ${esc(name || key)}</h2>
|
||||
<div class="muted" style="margin-bottom:10px">${esc(t("kAutoChainHint"))}</div>
|
||||
<div id="ka-scope-warn"></div>
|
||||
<div id="ka-canvas-host"></div>
|
||||
<p><button class="ghost small" onclick="scrAddModal()">+ ${esc(t("sortAdd"))}</button>
|
||||
<button class="ghost small" onclick="keyAutoInherit()">${esc(t("kAutoChainInherit"))}</button>
|
||||
@ -5309,6 +5328,7 @@ try {
|
||||
renderSortEditor($("#ka-canvas-host"), { canvasId: "key-auto-canvas" });
|
||||
keyAutoState.seeded = seededFromGlobal;
|
||||
keyAutoInheritNotice();
|
||||
keyAutoScopeWarning(key);
|
||||
} catch (e) {
|
||||
toast(String(e));
|
||||
}
|
||||
@ -5364,6 +5384,31 @@ try {
|
||||
paintSort();
|
||||
keyAutoInheritNotice();
|
||||
}
|
||||
// keyAutoScopeWarning tells the admin when the key's model scope blocks
|
||||
// AUTO outright. Configuring a per-key AUTO chain for such a key looks
|
||||
// like it works, yet every request 403s — the scope filter runs before
|
||||
// the chain is consulted. We deliberately do NOT widen the scope
|
||||
// automatically: that would silently grant access nobody asked for.
|
||||
function keyAutoScopeWarning(key) {
|
||||
const host = $("#ka-scope-warn");
|
||||
if (!host) return;
|
||||
const rec = (window._keyRows || []).find((k) => k.key === key);
|
||||
const models = (rec && rec.models) || [];
|
||||
if (!models.length) {
|
||||
host.innerHTML = "";
|
||||
return;
|
||||
}
|
||||
const hasAuto = models.some(
|
||||
(m) => (m.model || "").toUpperCase() === "AUTO",
|
||||
);
|
||||
host.innerHTML = hasAuto
|
||||
? ""
|
||||
: '<div class="warn-box">' +
|
||||
esc(t("kAutoChainScopeWarn")) +
|
||||
" " +
|
||||
esc(models.map((m) => m.model).join(", ")) +
|
||||
"</div>";
|
||||
}
|
||||
function keyAutoClose() {
|
||||
const m = document.getElementById("key-auto-modal");
|
||||
if (m) m.remove();
|
||||
|
||||
Reference in New Issue
Block a user