fix(me): by_slot last_status 用 max_ts 取最新一次的状态 (1.0.36)
`user_recent` 的 by_slot_7d 计算里 `entry.last_status = status` 无 条件覆盖,导致**昨天末尾的 status 覆盖今天最新**—— `list_days()` 是**倒序**(今天 → 昨天),如果昨天的最后几行是 失败状态(minimax 9-14 末尾 9 行全是 429),会覆盖今天的最新值。 现场:wugui minimax 最近 5 分钟全是 200,但 me.html 显示 429。 修:track `max_ts`,**仅在 ts > max_ts 才更新 last_status**—— 保证 last_status 反映 7d 窗口内**最大 ts 的那次调用**。 回归 238/0 全绿。
This commit is contained in:
1 parent
704a332f3f
commit
a47e08b5ac
4 files changed
+44
-55
No files matched your search
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
+9
-11
@@ -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}
|
||||
+22
-41
@@ -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 <YOUR_KEY>" \\\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: <YOUR_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 '<button class="btn-sm copy-url-btn" data-url="' + esc(url) + '" ' +
|
||||
'title="点击复制(不带尾巴,原样可粘到 WorkBuddy / Claude Code)">' +
|
||||
(proto === "openai" ? "OpenAI" : "Anthropic") + '</button>';
|
||||
}
|
||||
|
||||
function renderCard(proto, baseUrl, model) {
|
||||
var curl = proto === "openai"
|
||||
? curlOpenAI(baseUrl, model)
|
||||
: curlAnthropic(baseUrl, model);
|
||||
return '<div class="upstream-curl-row">' +
|
||||
'<span class="upstream-proto-tag ' + proto + '">' +
|
||||
(proto === "openai" ? "OpenAI" : "Anthropic") + '</span>' +
|
||||
'<pre class="upstream-curl" data-curl="' + esc(curl).replace(/"/g, """) + '">' +
|
||||
esc(curl) +
|
||||
'</pre>' +
|
||||
'<button class="btn-sm copy-btn">复制</button>' +
|
||||
function renderUrlRow(proto, url) {
|
||||
return '<div class="upstream-url-row">' +
|
||||
renderBtn(proto, url) +
|
||||
'<code class="upstream-url mono">' + esc(url) + '</code>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
el.innerHTML = upstreams.map(function (u) {
|
||||
var model = (u.models && u.models[0]) || "<model>";
|
||||
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 '<div class="upstream-card">' +
|
||||
'<div class="upstream-head">' +
|
||||
'<span class="mono"><b>' + esc(u.slot || "") + '</b></span>' +
|
||||
@@ -159,17 +142,15 @@
|
||||
esc((u.models || []).join("、") || "—") + '</span>' +
|
||||
(u.note ? '<span class="muted" style="margin-left:8px;font-size:12px">— ' + esc(u.note) + '</span>' : '') +
|
||||
'</div>' +
|
||||
protocols.map(function (p) { return renderCard(p[0], p[1], model); }).join("") +
|
||||
protocols.map(function (p) { return renderUrlRow(p[0], p[1]); }).join("") +
|
||||
'</div>';
|
||||
}).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");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@
|
||||
<div>
|
||||
<h2>我能调的 LLM 上游</h2>
|
||||
<div class="desc">
|
||||
按白名单过滤后的可用 slot;base_url 是<a href="https://doc.你的域名" target="_blank" rel="noopener">调用方视角</a>的完整 URL,客户端可直接配。
|
||||
按白名单过滤后的可用 slot;点 <b>OpenAI</b> / <b>Anthropic</b> 按钮复制纯 URL(<b>不带尾巴</b>——直接贴到 Claude Code / WorkBuddy 客户端)。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user