diff --git a/rust/crates/plugin-llm/src/llm_audit.rs b/rust/crates/plugin-llm/src/llm_audit.rs index 2579c1e..61fb8be 100644 --- a/rust/crates/plugin-llm/src/llm_audit.rs +++ b/rust/crates/plugin-llm/src/llm_audit.rs @@ -536,7 +536,11 @@ pub fn user_recent(username: &str, days: u32) -> Value { hour_24[h as usize] += 1; } } - // 7d by_slot + // 7d by_slot:last_status 必须用「最大 ts 的那次调用」 + // —— list_days() 是倒序(今天 → 昨天),如果无脑 entry.last_status = status + // 覆盖,昨天最后几行的 status 会**覆盖**今天的最新值 + // (昨天 9-14 末尾 wugui minimax 全是 429,今天 9-15 末尾是 200, + // 无脑覆盖 → 显示 429 而非 200,1.0.34 现场踩坑)。 if ts >= cutoff_7d { let entry = by_slot_7d.entry(slot.to_owned()).or_default(); entry.calls += 1; @@ -545,7 +549,11 @@ pub fn user_recent(username: &str, days: u32) -> Value { if ts >= cutoff_24h { entry.calls_24h += 1; } - entry.last_status = status; + // 按 ts 取 max:ts 更大才覆盖(**7d 窗口内最大 ts** 那次的 status) + if ts > entry.max_ts { + entry.max_ts = ts; + entry.last_status = status; + } } } } @@ -618,6 +626,8 @@ struct SlotStat7d { calls_24h: u64, tin: u64, tout: u64, + /// 当前已记下的最大 ts —— last_status 仅在 ts 更大时覆盖(1.0.34 现场) + max_ts: i64, last_status: u64, } diff --git a/www/assets/admin.css b/www/assets/admin.css index ffb1a48..58ec710 100644 --- a/www/assets/admin.css +++ b/www/assets/admin.css @@ -205,18 +205,16 @@ button.host-copy:hover{text-decoration:underline solid} .spark-svg .s-zero{fill:#e6eaf0} /* ============================================================================ - me.html 「我能调的 LLM 上游」:协议分组 + 复制即用 curl + me.html 「我能调的 LLM 上游」:按协议分组 + 「OpenAI / Anthropic」复制 URL 按钮 + (1.0.34b:去掉之前的 curl 示例,只复制纯 URL——WorkBuddy / Claude Code + 客户端拿到后**不要尾巴**) ========================================================================== */ .upstream-card{border:1px solid var(--border);border-radius:8px;background:var(--panel); padding:12px 14px;margin-bottom:12px} .upstream-head{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin-bottom:8px} -.upstream-curl-row{display:flex;align-items:flex-start;gap:8px;margin-top:8px} -.upstream-curl-row + .upstream-curl-row{border-top:1px dashed var(--border);padding-top:8px} -.upstream-proto-tag{flex-shrink:0;padding:2px 8px;border-radius:4px;font-size:11px; - font-weight:600;line-height:1.4;white-space:nowrap} -.upstream-proto-tag.openai{background:#dbeafe;color:#1e40af} -.upstream-proto-tag.anthropic{background:#fde68a;color:#92400e} -.upstream-curl{flex:1;min-width:0;margin:0;padding:10px 12px;background:var(--bg); - border:1px solid var(--border);border-radius:6px;font-size:11.5px;line-height:1.55; - white-space:pre-wrap;word-break:break-all;color:#334155;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace} -.copy-btn{flex-shrink:0} +.upstream-url-row{display:flex;align-items:center;gap:8px;margin-top:6px} +.upstream-url-row + .upstream-url-row{border-top:1px dashed var(--border);padding-top:6px;margin-top:6px} +.upstream-url{flex:1;min-width:0;padding:6px 10px;background:var(--bg); + border:1px solid var(--border);border-radius:6px;font-size:12px;color:#334155; + font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;word-break:break-all} +.copy-url-btn{flex-shrink:0;min-width:88px} diff --git a/www/assets/me.js b/www/assets/me.js index 084a89a..d960e56 100644 --- a/www/assets/me.js +++ b/www/assets/me.js @@ -101,11 +101,15 @@ /** * 同一个 upstream 通常**两个 base_url 都存在**: - * - `base_url`:OpenAI 协议路径(如 `https://host/minimax/v1`) - * - `anthropic_base_url`:Anthropic 协议路径(如 `https://host/minimax/anthropic`) + * - `base_url`:OpenAI 协议路径(如 `https://lm.mayishangshu.cn:88/deepseek/v1`) + * - `anthropic_base_url`:Anthropic 协议路径(如 `https://lm.mayishangshu.cn:88/deepseek/anthropic`) * - * 用户视角两种客户端(OpenAI SDK / Anthropic SDK)都能用—— - * 每种协议各自渲染一份**复制即用** curl。 + * **1.0.34b**:只展示**纯 URL**(不加任何尾巴),点击按钮直接复制。 + * 不展示 curl —— WorkBuddy / Claude Code 客户端拿到 URL 后**自行拼路径**, + * 中间再加 `/chat/completions` 这种尾巴会 404。 + * + * 注意 base_url 末尾已经带 `/v1` 或 `/anthropic` —— 客户端 SDK 看到 + * `https://host/slot/v1` 就知道 base path。 */ function renderUpstreams(upstreams) { var el = $("dUpstream"); @@ -114,44 +118,23 @@ return; } - function curlOpenAI(baseUrl, model) { - // base_url 已带 `/v1`,再加 `/chat/completions` - return 'curl -sk -H "Authorization: Bearer " \\\n' + - ' -H "Content-Type: application/json" \\\n' + - ' ' + esc(baseUrl) + '/chat/completions \\\n' + - ' -d \'{"model":"' + esc(model) + '","messages":[{"role":"user","content":"hi"}]}\''; - } - function curlAnthropic(baseUrl, model) { - // anthropic_base_url 是 path 前缀(如 `/minimax/anthropic`),加 `/v1/messages` - // 实际看网关 nginx 配置:`/anthropic/v1/messages` 等价于上游的 anthropic 协议端点 - return 'curl -sk -H "x-api-key: " \\\n' + - ' -H "anthropic-version: 2023-06-01" \\\n' + - ' -H "Content-Type: application/json" \\\n' + - ' ' + esc(baseUrl) + '/v1/messages \\\n' + - ' -d \'{"model":"' + esc(model) + '","max_tokens":1024,"messages":[{"role":"user","content":"hi"}]}\''; + function renderBtn(proto, url) { + return ''; } - function renderCard(proto, baseUrl, model) { - var curl = proto === "openai" - ? curlOpenAI(baseUrl, model) - : curlAnthropic(baseUrl, model); - return '
' + - '' + - (proto === "openai" ? "OpenAI" : "Anthropic") + '' + - '
' +
-          esc(curl) +
-        '
' + - '' + + function renderUrlRow(proto, url) { + return '
' + + renderBtn(proto, url) + + '' + esc(url) + '' + '
'; } el.innerHTML = upstreams.map(function (u) { - var model = (u.models && u.models[0]) || ""; - var hasOpenAI = !!u.base_url; - var hasAnthropic = !!u.anthropic_base_url; var protocols = []; - if (hasOpenAI) protocols.push(["openai", u.base_url]); - if (hasAnthropic) protocols.push(["anthropic", u.anthropic_base_url]); + if (u.base_url) protocols.push(["openai", u.base_url]); + if (u.anthropic_base_url) protocols.push(["anthropic", u.anthropic_base_url]); return '
' + '
' + '' + esc(u.slot || "") + '' + @@ -159,17 +142,15 @@ esc((u.models || []).join("、") || "—") + '' + (u.note ? '— ' + esc(u.note) + '' : '') + '
' + - protocols.map(function (p) { return renderCard(p[0], p[1], model); }).join("") + + protocols.map(function (p) { return renderUrlRow(p[0], p[1]); }).join("") + '
'; }).join(""); - // 复制按钮 - Array.prototype.forEach.call(el.querySelectorAll(".copy-btn"), function (btn) { + // 复制按钮:原样复制 URL,不加尾巴 + Array.prototype.forEach.call(el.querySelectorAll(".copy-url-btn"), function (btn) { btn.addEventListener("click", function (e) { e.preventDefault(); - var pre = btn.previousElementSibling; - var curl = pre.getAttribute("data-curl"); - IP.copyText(curl, "curl"); + IP.copyText(btn.getAttribute("data-url"), "URL"); }); }); } diff --git a/www/me.html b/www/me.html index 9d2eecb..12dace6 100644 --- a/www/me.html +++ b/www/me.html @@ -81,7 +81,7 @@

我能调的 LLM 上游

- 按白名单过滤后的可用 slot;base_url 是调用方视角的完整 URL,客户端可直接配。 + 按白名单过滤后的可用 slot;点 OpenAI / Anthropic 按钮复制纯 URL(不带尾巴——直接贴到 Claude Code / WorkBuddy 客户端)。