feat: show upstream key suffix per request

This commit is contained in:
Jason Xu committed 2026-08-27 21:36:17 +08:00
1 parent 6a03be875d
commit 3be4b393c0
7 files changed
+170 -30

No files matched your search

+5 -4
View File
@@ -30,7 +30,7 @@
<div id="restart-notice" class="notice hidden"></div>
<section id="page-overview" class="page">
<div class="metric-grid"><div class="metric-card"><div class="label">Last hour requests</div><div id="m-total" class="metric">—</div><div class="metric-note">最近 60 分钟</div></div><div class="metric-card"><div class="label">Success rate</div><div id="m-rate" class="metric">—</div><div class="metric-note">HTTP 2xx–3xx</div></div><div class="metric-card"><div class="label">P95 latency</div><div id="m-p95" class="metric">—</div><div class="metric-note">端到端毫秒</div></div><div class="metric-card"><div class="label">Active / stream</div><div id="m-active" class="metric">—</div><div class="metric-note">当前并发</div></div></div>
<div class="split"><div class="section"><div class="section-head"><div><h2>Proxy 节点</h2><div class="section-caption">这里显示代理节点,不将其描述为出口 IP。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>节点</th><th>健康</th><th>绑定</th></tr></thead><tbody id="proxy-table"></tbody></table></div></div><div class="section"><div class="section-head"><div><h2>Key 池</h2><div class="section-caption">仅显示稳定指纹与冷却状态。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>指纹</th><th>Tier</th><th>状态</th></tr></thead><tbody id="key-table"></tbody></table></div></div></div>
<div class="split"><div class="section"><div class="section-head"><div><h2>Proxy 节点</h2><div class="section-caption">这里显示代理节点,不将其描述为出口 IP。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>节点</th><th>健康</th><th>绑定</th></tr></thead><tbody id="proxy-table"></tbody></table></div></div><div class="section"><div class="section-head"><div><h2>Key 池</h2><div class="section-caption">仅显示 Key 最后 5 位与冷却状态。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>Key 尾码</th><th>Tier</th><th>状态</th></tr></thead><tbody id="key-table"></tbody></table></div></div></div>
<div class="section"><div class="section-head"><div><h2>请求分布</h2><div class="section-caption">端点、模型、Tier 与状态码的最近一小时聚合。</div></div></div><div id="breakdowns" class="split"></div></div>
</section>
<section id="page-guide" class="page hidden"><div class="section-head"><div><h2>六步上线检查</h2><div class="section-caption">状态来自当前配置与实时资源,不写入浏览器存储。</div></div></div><div id="guide-steps" class="guide"></div></section>
@@ -49,7 +49,8 @@
<section id="page-diagnostics" class="page hidden">
<div class="split"><div class="section"><div class="section-head"><div><h2>模型 Metadata</h2><div class="section-caption">models.dev OpenCode 价格缓存状态;零成本或名称含 free 任一条件即可进入匿名通道。</div></div></div><div id="metadata-facts" class="fact-grid"></div></div><div class="section"><div class="section-head"><div><h2>最近 Playground</h2><div class="section-caption">只保留当前管理进程内的最后一次追踪。</div></div></div><div id="last-playground" class="fact-grid"></div></div></div>
<div class="section"><div class="section-head"><div><h2>模型路由表</h2><div class="section-caption">显式协议、匿名资格来源与成本判断。</div></div><input id="diagnostic-model-search" placeholder="筛选模型" style="max-width:260px"></div><div class="table-wrap"><table class="table"><thead><tr><th>模型</th><th>原生协议</th><th>路由</th><th>匿名资格</th><th>判断来源</th><th>成本 input / output</th></tr></thead><tbody id="diagnostic-models"></tbody></table></div></div>
<div class="section"><div class="section-head"><div><h2>上游尝试</h2><div class="section-caption">Key 指纹、匿名通道与脱敏代理节点;最多展示最近 100 条。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>时间</th><th>Request ID</th><th>模型</th><th>通道</th><th>Key</th><th>代理节点</th><th>状态</th><th>耗时</th></tr></thead><tbody id="upstream-attempts"></tbody></table></div></div>
<div class="section"><div class="section-head"><div><h2>请求路由</h2><div class="section-caption">每个请求最终实际使用的 Key 尾码或 anonymous;最多展示最近 100 条。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>时间</th><th>Request ID</th><th>模型</th><th>Tier</th><th>通道</th><th>Key 尾码</th><th>尝试</th><th>状态</th><th>耗时</th></tr></thead><tbody id="upstream-requests"></tbody></table></div></div>
<div class="section"><div class="section-head"><div><h2>上游尝试</h2><div class="section-caption">Key 尾码、匿名通道与脱敏代理节点;最多展示最近 100 条。</div></div></div><div class="table-wrap"><table class="table"><thead><tr><th>时间</th><th>Request ID</th><th>模型</th><th>通道</th><th>Key 尾码</th><th>代理节点</th><th>状态</th><th>耗时</th></tr></thead><tbody id="upstream-attempts"></tbody></table></div></div>
</section>
<section id="page-config" class="page hidden"><form id="config-form">
<div class="section"><div class="section-head"><div><h2>服务与管理端</h2><div class="section-caption">监听地址变更保存后需要重启。</div></div></div><div class="form-grid"><div class="field"><label>认证 Key 首选 Tier</label><select id="c-prefer"><option value="go">Go(失败回退 Zen)</option><option value="zen">Zen(失败回退 Go)</option></select></div><div class="field"><label>API Listen</label><input id="c-listen"></div><div class="field"><label>WebUI Listen</label><input id="c-web-listen"></div><div class="field"><label>Session TTL(分钟)</label><input id="c-session" type="number"></div><div class="field full"><label class="check-label"><input id="c-web-enabled" type="checkbox">启用 WebUI(修改需重启)</label></div></div></div>
@@ -98,10 +99,10 @@
function playgroundTemplate(){const protocol=$('#play-protocol').value,model=$('#play-model').value||'YOUR_MODEL';if(protocol==='responses')return{model,input:'用一句话说明这个模型的能力。'};if(protocol==='anthropic')return{model,max_tokens:512,messages:[{role:'user',content:'用一句话说明这个模型的能力。'}]};return{model,messages:[{role:'user',content:'用一句话说明这个模型的能力。'}]}}
function resetPlayTemplate(){$('#play-request').value=JSON.stringify(playgroundTemplate(),null,2)}
$('#play-protocol').addEventListener('change',resetPlayTemplate);$('#play-model').addEventListener('change',()=>{try{const request=JSON.parse($('#play-request').value);request.model=$('#play-model').value;$('#play-request').value=JSON.stringify(request,null,2)}catch(_){resetPlayTemplate()}});$('#play-reset').onclick=resetPlayTemplate;
function displayPlayground(result){lastPlayground=result;$('#play-state').textContent=result.ok?`请求成功 · HTTP ${result.http_status}`:`请求失败 · HTTP ${result.http_status}`;$('#play-state').className=`section-caption ${result.ok?'ok':'bad'}`;const route=result.route||{},eligibility=route.anonymous_eligibility||{};renderFacts('#play-facts',[['HTTP 状态',result.http_status,result.ok?'ok':'bad'],['耗时',`${result.duration_ms} ms`],['Request ID',result.request_id||'—'],['实际路由',route.tier?`${route.tier} / ${route.anonymous?'anonymous':'key'}`:'未路由'],['原生协议',route.native_protocol||'—'],['匿名判断',`${eligibility.allowed?'允许':'拒绝'} · ${eligibility.source||'—'}`,eligibility.allowed?'ok':'warn']]);$('#play-output').textContent=JSON.stringify(result.response,null,2);renderDiagnostics()}
function displayPlayground(result){lastPlayground=result;$('#play-state').textContent=result.ok?`请求成功 · HTTP ${result.http_status}`:`请求失败 · HTTP ${result.http_status}`;$('#play-state').className=`section-caption ${result.ok?'ok':'bad'}`;const route=result.route||{},eligibility=route.anonymous_eligibility||{},routeLabel=route.tier?`${route.tier} / ${route.anonymous?'anonymous':(route.key_id||'key')}`:'未路由';renderFacts('#play-facts',[['HTTP 状态',result.http_status,result.ok?'ok':'bad'],['耗时',`${result.duration_ms} ms`],['Request ID',result.request_id||'—'],['实际路由',routeLabel],['原生协议',route.native_protocol||'—'],['匿名判断',`${eligibility.allowed?'允许':'拒绝'} · ${eligibility.source||'—'}`,eligibility.allowed?'ok':'warn']]);$('#play-output').textContent=JSON.stringify(result.response,null,2);renderDiagnostics()}
$('#play-form').addEventListener('submit',async event=>{event.preventDefault();let request;try{request=JSON.parse($('#play-request').value)}catch(error){toast(`请求 JSON 无效:${error.message}`,true);return}$('#play-run').disabled=true;$('#play-state').textContent='Gateway 请求进行中…';try{const result=await api('/api/debug/inference',{method:'POST',body:JSON.stringify({protocol:$('#play-protocol').value,request})});displayPlayground(result)}catch(error){toast(error.message,true);$('#play-state').textContent='诊断入口请求失败'}finally{$('#play-run').disabled=false}});
$('#play-copy').onclick=async()=>{try{await navigator.clipboard.writeText($('#play-output').textContent);toast('原始响应已复制')}catch(_){toast('浏览器不允许剪贴板访问',true)}};
function renderDiagnostics(){if(!monitorData&&!debugData)return;const metadata=debugData?.metadata||monitorData?.resources?.metadata||{},last=lastPlayground||debugData?.last_inference;renderFacts('#metadata-facts',[['就绪',metadata.ready?'是':'否',metadata.ready?'ok':'warn'],['模型数',formatTokens(metadata.models)],['更新时间',metadata.updated_at?new Date(metadata.updated_at).toLocaleString():'尚未更新'],['是否过期',metadata.stale?'是':'否',metadata.stale?'warn':'ok'],['下次刷新',metadata.next_refresh?new Date(metadata.next_refresh).toLocaleString():'—'],['最近错误',metadata.last_error||'无',metadata.last_error?'bad':'ok']]);renderFacts('#last-playground',last?[['结果',last.ok?'成功':'失败',last.ok?'ok':'bad'],['HTTP',last.http_status],['耗时',`${last.duration_ms} ms`],['Request ID',last.request_id||'—'],['模型',last.route?.model||'—'],['路由',last.route?.tier?`${last.route.tier} / ${last.route.anonymous?'anonymous':'key'}`:'未路由']]:[['状态','尚无 Playground 追踪']]);renderDiagnosticModels();const attempts=$('#upstream-attempts');attempts.replaceChildren();(monitorData?.upstream?.recent||[]).slice(-100).reverse().forEach(attempt=>{const row=document.createElement('tr');appendCell(row,new Date(attempt.time).toLocaleTimeString());appendCell(row,attempt.request_id);appendCell(row,attempt.model);appendCell(row,`${attempt.tier} / ${attempt.channel}`);appendCell(row,attempt.key_id);appendCell(row,attempt.proxy_node);appendCell(row,attempt.status||attempt.outcome,attempt.success?'ok':'bad');appendCell(row,`${attempt.duration_ms} ms`);attempts.appendChild(row)});if(!attempts.children.length)emptyRow(attempts,8,'尚无上游尝试')}
function renderDiagnostics(){if(!monitorData&&!debugData)return;const metadata=debugData?.metadata||monitorData?.resources?.metadata||{},last=lastPlayground||debugData?.last_inference;renderFacts('#metadata-facts',[['就绪',metadata.ready?'是':'否',metadata.ready?'ok':'warn'],['模型数',formatTokens(metadata.models)],['更新时间',metadata.updated_at?new Date(metadata.updated_at).toLocaleString():'尚未更新'],['是否过期',metadata.stale?'是':'否',metadata.stale?'warn':'ok'],['下次刷新',metadata.next_refresh?new Date(metadata.next_refresh).toLocaleString():'—'],['最近错误',metadata.last_error||'无',metadata.last_error?'bad':'ok']]);renderFacts('#last-playground',last?[['结果',last.ok?'成功':'失败',last.ok?'ok':'bad'],['HTTP',last.http_status],['耗时',`${last.duration_ms} ms`],['Request ID',last.request_id||'—'],['模型',last.route?.model||'—'],['路由',last.route?.tier?`${last.route.tier} / ${last.route.anonymous?'anonymous':(last.route.key_id||'key')}`:'未路由']]:[['状态','尚无 Playground 追踪']]);renderDiagnosticModels();const requests=$('#upstream-requests');requests.replaceChildren();(monitorData?.upstream?.requests||[]).slice(-100).reverse().forEach(request=>{const row=document.createElement('tr');appendCell(row,new Date(request.time).toLocaleTimeString());appendCell(row,request.request_id);appendCell(row,request.model);appendCell(row,request.tier||'—');appendCell(row,request.channel);appendCell(row,request.key_id||'—');appendCell(row,request.attempts);appendCell(row,request.status||request.outcome,request.success?'ok':'bad');appendCell(row,`${request.duration_ms} ms`);requests.appendChild(row)});if(!requests.children.length)emptyRow(requests,9,'尚无请求路由');const attempts=$('#upstream-attempts');attempts.replaceChildren();(monitorData?.upstream?.recent||[]).slice(-100).reverse().forEach(attempt=>{const row=document.createElement('tr');appendCell(row,new Date(attempt.time).toLocaleTimeString());appendCell(row,attempt.request_id);appendCell(row,attempt.model);appendCell(row,`${attempt.tier} / ${attempt.channel}`);appendCell(row,attempt.key_id);appendCell(row,attempt.proxy_node);appendCell(row,attempt.status||attempt.outcome,attempt.success?'ok':'bad');appendCell(row,`${attempt.duration_ms} ms`);attempts.appendChild(row)});if(!attempts.children.length)emptyRow(attempts,8,'尚无上游尝试')}
function renderDiagnosticModels(){const host=$('#diagnostic-models');if(!host||!debugData)return;const query=$('#diagnostic-model-search').value.trim().toLowerCase();host.replaceChildren();(debugData.models||[]).filter(item=>!query||item.model.toLowerCase().includes(query)).forEach(item=>{const eligibility=item.anonymous_eligibility||{},row=document.createElement('tr'),input=eligibility.input_cost,output=eligibility.output_cost,plan=[...(item.anonymous?['anonymous']:[]),...(item.key_tiers||[])];appendCell(row,item.model);appendCell(row,`${item.native_protocol} · ${item.protocol_source}`);appendCell(row,item.route_error||(plan.length?plan.join(' → '):'—'),item.route_error?'bad':'');appendCell(row,eligibility.allowed?'允许':'拒绝',eligibility.allowed?'ok':'warn');appendCell(row,eligibility.source||'—');appendCell(row,`${input==null?'?':input} / ${output==null?'?':output}`,'cost');host.appendChild(row)});if(!host.children.length)emptyRow(host,6,'没有匹配模型')}
$('#diagnostic-model-search').addEventListener('input',renderDiagnosticModels);
async function refreshMonitor(){try{monitorData=await api('/api/monitor');const metrics=monitorData.metrics;$('#version').textContent=`version ${monitorData.version}`;$('#m-total').textContent=Number(metrics.last_hour.total||0).toLocaleString();$('#m-rate').textContent=`${((metrics.last_hour.success_rate||0)*100).toFixed(1)}%`;$('#m-p95').textContent=`${metrics.last_hour.p95_ms||0} ms`;$('#m-active').textContent=`${metrics.active_requests||0} / ${metrics.active_streams||0}`;renderResources(monitorData.resources);renderBreakdowns(metrics);renderGuide();renderUsage();renderDiagnostics()}catch(_){} }