mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 16:04:01 +00:00
feat: revise free model routing fallback
This commit is contained in:
1 parent
6101055ad8
commit
cc71ba8aff
5 files changed
+160
-99
No files matched your search
+4
-4
@@ -47,15 +47,15 @@
|
||||
</section>
|
||||
<section id="page-playground" class="page hidden"><div class="play-grid"><form id="play-form" class="section"><div class="section-head"><div><h2>三协议请求台</h2><div class="section-caption">服务端强制非流式,并经由真实 Gateway 路由。</div></div></div><div class="form-grid"><div class="field"><label>入口协议</label><select id="play-protocol"><option value="chat">Chat Completions</option><option value="responses">Responses</option><option value="anthropic">Anthropic Messages</option></select></div><div class="field"><label>模型</label><select id="play-model"></select></div></div><div class="field"><label>请求 JSON</label><textarea id="play-request" class="json-editor" spellcheck="false"></textarea></div><div class="actions"><button id="play-reset" type="button" class="ghost">重置模板</button><button id="play-run" class="primary">发送诊断请求</button></div></form><div class="section"><div class="section-head"><div><h2>诊断结果</h2><div class="section-caption" id="play-state">尚未发送请求。</div></div></div><div id="play-facts" class="fact-grid"></div><div class="code-card"><div class="code-head"><span>Raw protocol response</span><button id="play-copy" type="button" class="copy">复制</button></div><pre id="play-output">{}</pre></div></div></div></section>
|
||||
<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 价格缓存状态。</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="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>
|
||||
</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>API Listen</label><input id="c-listen"></div><div class="field"><label>优先 Tier</label><select id="c-prefer"><option value="go">Go</option><option value="zen">Zen</option></select></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>
|
||||
<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>
|
||||
<div class="section"><div class="section-head"><div><h2>密钥与匿名通道</h2><div class="section-caption">敏感值默认仅显示掩码;移除后保存才会生效。</div></div><button id="reveal" type="button" class="ghost">二次验证查看</button></div><div class="form-grid"><div class="field full"><label class="check-label"><input id="c-anonymous" type="checkbox">启用 Zen 匿名通道</label></div><div class="field full"><label>Server Keys</label><div id="server_keys-chips" class="chips"></div><textarea id="server_keys-new" placeholder="每行新增一个 key"></textarea></div><div class="field"><label>Zen Keys</label><div id="zen_keys-chips" class="chips"></div><textarea id="zen_keys-new" placeholder="每行新增一个 key"></textarea></div><div class="field"><label>Go Keys</label><div id="go_keys-chips" class="chips"></div><textarea id="go_keys-new" placeholder="每行新增一个 key"></textarea></div></div></div>
|
||||
<div class="section"><div class="section-head"><div><h2>Proxy 节点</h2><div class="section-caption">支持 direct、HTTP(S) 与 SOCKS URL。</div></div></div><div id="proxies-chips" class="chips"></div><div class="form-grid"><div class="field"><label>新增 Proxy(每行一个)</label><textarea id="proxies-new" placeholder="direct http://user:pass@host:port"></textarea></div><div class="field"><label>Proxy File</label><input id="c-proxyfile" placeholder="proxies.txt"></div></div></div>
|
||||
<div class="section"><div class="section-head"><div><h2>上游与协议路由</h2><div class="section-caption">显式 protocol 映射优先于模型名称推断。</div></div></div><div class="form-grid"><div class="field"><label>Zen URL</label><input id="c-up-zen"></div><div class="field"><label>Go URL</label><input id="c-up-go"></div><div class="field"><label>最大尝试次数</label><input id="c-attempts" type="number"></div><div class="field"><label>请求超时(秒)</label><input id="c-timeout" type="number"></div><div class="field"><label>模型刷新(秒)</label><input id="c-refresh" type="number"></div><div class="field"><label>模型协议覆盖(JSON)</label><textarea id="c-protocols" spellcheck="false">{}</textarea></div></div></div>
|
||||
<div class="section"><div class="section-head"><div><h2>上游与协议路由</h2><div class="section-caption">anonymous 会耗尽可用 Proxy;显式 protocol 映射优先于模型名称推断。</div></div></div><div class="form-grid"><div class="field"><label>Zen URL</label><input id="c-up-zen"></div><div class="field"><label>Go URL</label><input id="c-up-go"></div><div class="field"><label>每个 Key Tier 最大尝试次数</label><input id="c-attempts" type="number"></div><div class="field"><label>请求超时(秒)</label><input id="c-timeout" type="number"></div><div class="field"><label>模型刷新(秒)</label><input id="c-refresh" type="number"></div><div class="field"><label>模型协议覆盖(JSON)</label><textarea id="c-protocols" spellcheck="false">{}</textarea></div></div></div>
|
||||
<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>Max Idle Conns</label><input id="c-idle" type="number"></div><div class="field"><label>Max Idle / Host</label><input id="c-idle-host" type="number"></div><div class="field"><label>Max Conns / Host</label><input id="c-max-host" type="number"></div><div class="field"><label>Idle Timeout(秒)</label><input id="c-idle-timeout" type="number"></div><div class="field"><label>Connect Timeout(秒)</label><input id="c-connect" type="number"></div><div class="field"><label>Failure Cooldown(秒)</label><input id="c-cooldown" type="number"></div><div class="field"><label>日志级别</label><select id="c-level"><option>debug</option><option>info</option><option>warn</option><option>error</option></select></div><div class="field"><label>日志 Ring Size</label><input id="c-ring" type="number"></div></div><div class="actions"><button id="reload-config" type="button" class="ghost">从磁盘重载</button><button class="primary">验证、保存并应用</button></div></div>
|
||||
</form></section>
|
||||
<section id="page-logs" class="page hidden"><div class="filters"><select id="log-level"><option value="">全部级别</option><option>debug</option><option>info</option><option>warn</option><option>error</option></select><input id="log-component" placeholder="模块"><input id="log-search" placeholder="搜索事件、Request ID、模型"><button id="log-pause" class="ghost">暂停</button></div><div id="log-list" class="logs"></div></section>
|
||||
@@ -102,7 +102,7 @@
|
||||
$('#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 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;appendCell(row,item.model);appendCell(row,`${item.native_protocol} · ${item.protocol_source}`);appendCell(row,item.route_error||`${item.tier||'—'} / ${item.anonymous?'anonymous':'key'}`,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,'没有匹配模型')}
|
||||
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(_){} }
|
||||
$('#refresh-now').onclick=async()=>{await Promise.all([refreshMonitor(),loadConfig(),loadDebugModels()]);toast('状态已刷新')};
|
||||
|
||||
Reference in new issue
Block a user