const paths = {
overview:'M3 3h7v7H3zm11 0h7v7h-7zM3 14h7v7H3zm11 0h7v7h-7z',
accounts:'M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2m20 0v-2a4 4 0 0 0-3-3.87M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8m8-7.87a4 4 0 0 1 0 7.75',
models:'m12 2 9 5-9 5-9-5 9-5zm-9 10 9 5 9-5M3 17l9 5 9-5',
logs:'M5 3h14v18H5zM8 7h8M8 11h8M8 15h5',
play:'m8 4 13 8-13 8V4Z',code:'m8 6-6 6 6 6m8-12 6 6-6 6m-3-15-2 18',
refresh:'M20 7a9 9 0 0 0-15-3L2 7m0-5v5h5m-3 10a9 9 0 0 0 15 3l3-3m0 5v-5h-5',
plus:'M12 5v14M5 12h14',arrow:'M4 12h16m-6-6 6 6-6 6',
clock:'M12 8v5l3 2m7-3a10 10 0 1 1-20 0 10 10 0 0 1 20 0',
check:'m5 12 4 4L19 6',chart:'M4 3v17h17M8 15l4-5 4 2 5-7',
close:'m6 6 12 12M6 18 18 6',search:'M21 21l-5-5m2-6a8 8 0 1 1-16 0 8 8 0 0 1 16 0',
upload:'M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6',download:'M12 3v13m-5-5 5 5 5-5M4 17v4h16v-4',
lock:'M6 10h12v11H6zM8 10V6a4 4 0 0 1 8 0v4',
copy:'M9 9h12v12H9zM15 9V3H3v12h6',activity:'M2 12h5l3-8 4 16 3-8h5',
settings:'M3 7h18M7 3v8M3 17h18m-6-4v8',
};
const icon = name => ` `;
document.querySelectorAll('[data-icon]').forEach(el => el.innerHTML = icon(el.dataset.icon));
const $ = selector => document.querySelector(selector);
const esc = value => String(value ?? '').replace(/[&<>"']/g, char => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[char]));
const n = value => Number(value || 0).toLocaleString('zh-CN');
const duration = value => value == null ? '—' : value < 1000 ? `${Math.round(value)} ms` : `${(value / 1000).toFixed(2)} s`;
const percent = value => value == null ? '—' : `${value.toFixed(1)}%`;
const time = value => value ? new Date(value).toLocaleTimeString('zh-CN', {hour12:false}) : '尚未检测';
const date = value => value ? new Date(value).toLocaleString('zh-CN', {hour12:false}) : '—';
const ago = value => !value ? '尚未检测' : Date.now()-value < 60000 ? '刚刚' : Date.now()-value < 3600000 ? `${Math.floor((Date.now()-value)/60000)} 分钟前` : date(value);
const shortSid = value => value ? `${value.slice(0,10)}…${value.slice(-4)}` : '外部刷新';
const titles = {overview:'代理概览',accounts:'号池管理',models:'模型与性能',logs:'请求日志',playground:'请求测试',connect:'API 接入'};
const statuses = {ready:'可用',pending:'未检测',retry:'待重试',cooling:'冷却中',error:'异常',expired:'已过期',disabled:'已停用',success:'成功',cancelled:'已取消'};
const badge = (status, title='') => `${statuses[status] || esc(status)} `;
let state, page = location.hash.slice(1) || 'overview', busyCount = 0, loading = false;
let accountQuery = '', accountFilter = 'all', logQuery = '', logFilter = 'all', logPage = 0;
let deleteId, playController, playStarted;
const busyAccounts = new Set();
async function api(path, { method = 'GET', body } = {}) {
const response = await fetch(`/api${path}`, {method, headers:{'X-Logicc-Admin':'1',...(body !== undefined || method === 'POST' ? {'Content-Type':'application/json'} : {})},body:body !== undefined ? JSON.stringify(body) : method === 'POST' ? '{}' : undefined, signal:AbortSignal.timeout(35000)});
const result = await response.json();
if (!response.ok) throw new Error(result.error?.message || `HTTP ${response.status}`);
return result;
}
function toast(message, error = false) {
const element = document.createElement('div');
element.className = `toast${error?' error':''}`;
element.textContent = message;
$('#toasts').append(element);
while ($('#toasts').children.length > 3) $('#toasts').firstElementChild.remove();
setTimeout(() => element.remove(), 5000);
}
function errorAt(id, message) { const el = $(id); el.textContent = message; el.hidden = !message; }
async function reload(force = false) {
if (loading) return;
loading = true;
try {
state = await api('/state');
$('#connection-error').hidden = true;
$('#connection-state').innerHTML = ' 代理运行中';
$('#sidebar-status').textContent = '本地服务在线';
$('#sidebar-dot').classList.remove('offline');
$('#sidebar-address').textContent = new URL(state.service.baseUrl).host;
$('#nav-count').textContent = state.accounts.length;
$('#last-updated').textContent = `上次同步 ${time(Date.now())}`;
if (force || (!busyCount && !$('dialog[open]') && !$('details.menu[open]') && !['INPUT','TEXTAREA','SELECT'].includes(document.activeElement?.tagName))) render();
} catch (error) {
$('#connection-error').textContent = `连接失败:${error.message}。请确认代理仍在运行;5 秒后自动重试。`;
$('#connection-error').hidden = false;
$('#connection-state').innerHTML = ' 连接已断开';
$('#sidebar-status').textContent = '服务连接中断';
$('#sidebar-dot').classList.add('offline');
if (!state) $('#main').innerHTML = empty('无法连接代理','请检查启动服务的终端,或点击右上角刷新按钮重试。','activity');
} finally { loading = false; }
}
function heading(title, subtitle, actions = '', eyebrow = 'WORKSPACE / LOCAL') {
return `
${eyebrow}
${title} ${subtitle}
${actions}
`;
}
const addButton = `${icon('plus')}添加账户 `;
const importButton = `${icon('upload')}批量导入 `;
const empty = (title, description, symbol = 'accounts', action = '') => `${icon(symbol)}
${title} ${description}
${action}
`;
function metric(label,value,foot,symbol) { return `${label}${icon(symbol)}
${value}
`; }
function render() {
if (!state) return;
if (!titles[page]) page = 'overview';
$('#breadcrumb-page').textContent = titles[page];
document.title = `${titles[page]} · Logicc`;
document.querySelectorAll('[data-page]').forEach(link => { link.classList.toggle('active',link.dataset.page === page); if(link.dataset.page === page) link.setAttribute('aria-current','page'); else link.removeAttribute('aria-current'); });
if (page === 'playground' && $('#play-form')) return;
$('#main').innerHTML = ({overview:overviewPage,accounts:accountsPage,models:modelsPage,logs:logsPage,playground:playgroundPage,connect:connectPage})[page]();
}
function chart() {
const max = Math.max(2, ...state.trend.map(b => b.success+b.error));
const plot = {x:30,y:10,w:578,h:120};
const grid = [0,.5,1].map(f => `${Math.round(max*(1-f))} `).join('');
const bars = state.trend.map((bucket,i) => {
const x = plot.x+i*24.5;
const h = bucket.success/max*120, e=bucket.error/max*120;
return `${time(bucket.time)} · 成功 ${bucket.success} / 异常 ${bucket.error} `;
}).join('');
const labels = [0,4,8,12,16,20,23].map(i=>`${new Date(state.trend[i].time).getHours().toString().padStart(2,'0')}:00 `).join('');
return `${grid}${bars} ${labels} ${!state.stats.requests?'
等待第一条请求 接入客户端后,流量将在这里显示
':''}
`;
}
function overviewPage() {
const s=state.stats, total=state.accounts.length, available=s.available;
const trouble=state.accounts.filter(a=>['error','cooling','expired'].includes(a.status)).length;
const disabled=state.accounts.filter(a=>a.status==='disabled').length;
return heading('让每一次请求,都有迹可循。','账号、模型与流量,在一个地方掌握。',`${icon('code')}接入 API ${addButton}`,'LOGICC / PROXY OVERVIEW') +
`${metric('可调度账户',`${n(available)}/ ${n(total)} `,`${available?'调度池已就绪':'等待添加账户'} `,'accounts')}${metric('请求总量',n(s.requests),`过去 24 小时 · ${n(s.active)} 个处理中`,'chart')}${metric('请求成功率',percent(s.successRate),`${n(s.successes)} 次成功 · ${n(s.failures)} 次异常 / 取消`,'check')}${metric('平均首字延迟',s.avgTtft == null?'—':`${(s.avgTtft/1000).toFixed(2)}s `,'首次文本输出 · 含代理开销','clock')}
${total?Math.round(available/total*100):0}% 可调度
可调度${available.toString().padStart(2,'0')}
待处理${trouble.toString().padStart(2,'0')}
已停用${disabled.toString().padStart(2,'0')}
${accountTable(state.accounts.slice(0,4),true)}
${logTable(state.requests.slice(0,4))} `;
}
function accountTable(accounts,compact=false) {
if (!accounts.length) return empty(state.accounts.length?'没有匹配的账户':'添加你的第一个账户',state.accounts.length?'试试其他名称、Session ID 或状态。':'添加凭据后检测连接,即可通过 OpenAI 兼容接口发送请求。','accounts',state.accounts.length?'':addButton);
return `账户 状态 认证方式 请求 / 成功率 ${compact?'':'上次检测 '}操作 ${accounts.map((a,i)=>`${String(state.accounts.indexOf(a)+1).padStart(2,'0')} ${esc(a.name)} ${esc(shortSid(a.sessionId))}
${badge(a.status,a.lastError || '')}${a.inFlight?`${a.inFlight} 个处理中
`:''} ${a.hasClientCookie?'Client 自动刷新':'Session JWT'} ${!compact?`${a.hasToken&&a.tokenExpiresAt?`JWT ${a.tokenExpiresAt>Date.now()?'有效至 '+time(a.tokenExpiresAt):'待刷新'}`:'按需获取 JWT'}
`:''}${n(a.requests)} / ${percent(a.successRate)} ${compact?'':`${ago(a.lastCheckedAt)} ${a.lastError?`${esc(a.lastError)}
`:''} `}${busyAccounts.has(a.id)?'检测中…':'检测'}
`).join('')}
`;
}
function accountsPage() {
return heading('号池管理','管理账户凭据,让请求在可用账户间有序分配。',`${importButton}${addButton}`,'WORKSPACE / ACCOUNTS')+
`检测仅获取模型列表,不生成回答。停用账户保留配置;移除账户会删除本地凭据。
`;
}
function filteredAccounts() {
const query=accountQuery.toLowerCase();
return accountTable(state.accounts.filter(a=>(`${a.name} ${a.sessionId}`.toLowerCase().includes(query)) && (accountFilter==='all' || (accountFilter==='error'?['error','expired'].includes(a.status):a.status===accountFilter))));
}
function modelsPage() {
const maxLatency=Math.max(1,...state.modelStats.map(m=>m.avgTtft || 0));
return heading('模型与性能','查看上游可用模型,以及真实调用产生的性能数据。',`${icon('refresh')}同步模型 `,'WORKSPACE / MODELS')+
`模型目录 / ${state.models.length.toString().padStart(2,'0')} ${state.modelsUpdatedAt?'最近同步 '+date(state.modelsUpdatedAt):'连接账户后,从上游同步模型目录'}
性能 · 近 24 小时 ${!state.models.length?empty('模型目录尚未同步','先在号池中添加并检测账户,或点击「同步模型」。','models'):`模型 ID 提供方 调用次数 成功率 平均首字延迟 平均总耗时 ${state.models.map(m=>{const s=state.modelStats.find(s=>s.model===m.id);return `${esc(m.id)}
${m.name!==m.id?`${esc(m.name)}
`:''}${esc(m.provider)} ${s?n(s.requests):'0'} ${percent(s?.successRate)} ${duration(s?.avgTtft)} ${s?.avgTtft!=null?` `:''}
${duration(s?.avgLatency)} 测试${icon('arrow')} `;}).join('')}
`}能力说明 支持流式与非流式文本响应,内置搜索与图片工具可透传。自定义函数采用提示词约定,尚不支持标准 tool_calls;当前多轮消息会合并为单条提示词。
`;
}
const kindLabel = kind => ({chat:'聊天请求',models:'模型列表',check:'账户检测'}[kind] || kind);
function logTable(records) {
if (!records.length) return empty('暂无请求记录','账号检测、模型同步和客户端调用完成后,记录会显示在这里。','logs');
return `时间 账户 / 请求 模型 首字延迟 总耗时 结果 ${records.map(r=>`${time(r.startedAt)}
${new Date(r.startedAt).toLocaleDateString('zh-CN')}
${esc(r.accountName || '未分配账户')}
${kindLabel(r.kind)}${r.stream?' · 流式':''}
${esc(r.model || '—')} ${duration(r.ttftMs)} ${duration(r.durationMs)} ${badge(r.status,r.error || '')} 详情 `).join('')}
`;
}
function filteredLogs() {
const query=logQuery.toLowerCase();
return state.requests.filter(r=>(`${r.model || ''} ${r.accountName || ''} ${r.error || ''} ${kindLabel(r.kind)}`.toLowerCase().includes(query))&&(logFilter==='all'||r.status===logFilter));
}
function logsContent() {
const records=filteredLogs(), pages=Math.max(1,Math.ceil(records.length/15));
logPage=Math.min(logPage,pages-1);
return `${logTable(records.slice(logPage*15,logPage*15+15))}`;
}
function logsPage() {
return heading('请求日志','从一次请求,追溯账户、模型与响应状态。',`${icon('download')}导出当前结果 `,'WORKSPACE / REQUEST LOGS')+
`仅保存请求元数据,不记录提示词、回答或凭据。数据文件最多保留 2,000 条;指标按保留记录中的近 24 小时计算。
`;
}
function connectPage() {
const base=state.service.baseUrl;
const model=state.models[0]?.id || 'default';
const snippet=`curl ${base}/chat/completions \\\n -H 'Content-Type: application/json' \\\n -H 'Authorization: Bearer ${state.service.apiKeyRequired?'YOUR_API_KEY':'local'}' \\\n -d '${JSON.stringify({model,stream:true,messages:[{role:'user',content:'你好,请简单介绍自己。'}]})}'`;
return heading('连接你的客户端','通过 OpenAI 兼容协议,将客户端接入 Logicc 号池。','','DEVELOPER / API ACCESS')+
`OpenAI 兼容接口 在客户端的自定义服务中填写以下 Base URL。
${esc(base)}${icon('copy')}复制
API Key ${state.service.apiKeyRequired?'使用启动时配置的 LOGICC_API_KEY':'任意非空字符串,例如 local'}
模型列表 GET /v1/models
聊天补全 POST /v1/chat/completions
快速测试 cURL / Streaming 连接信息 服务范围 仅本机 · 127.0.0.1
上游服务 app.logicc.com
账户调度 低并发优先轮询
速率限制 429 后冷却 60 秒
凭据异常 401 / 403 后冷却 5 分钟
请求记录 最多 2,000 条
关于凭据刷新 __client Cookie + Session ID 可按需获取短期 JWT。客户端凭据失效时,在号池中更新后重新检测即可。 检测和实际请求会更新账户状态;控制台自动刷新只读取本地数据。
`;
}
function playgroundPage() {
return heading('发起一次真实请求','直接验证号池、模型与流式响应;测试会消耗上游额度。','','WORKSPACE / PLAYGROUND')+
`在左侧输入消息,查看实时响应。 连接本地 OpenAI 兼容接口
`;
}
function openAccount(id) {
const form=$('#account-form'); form.reset();
errorAt('#account-error','');
const account=id?state.accounts.find(a=>a.id===id):null;
form.elements.id.value=id || '';
form.elements.name.value=account?.name || '';
form.elements.sessionId.value=account?.sessionId || '';
form.elements.enabled.checked=account?account.enabled:true;
form.elements.clientCookie.placeholder=account?.hasClientCookie?'已保存 · 留空保留原凭据':'粘贴 clerk.logicc.com 的 __client 值';
form.querySelector('details').open=false;
$('#account-dialog-title').textContent=account?'编辑账户':'添加账户';
$('#account-dialog').showModal();
form.elements.name.focus();
}
async function checkAccount(id, refresh=false, silent=false) {
busyAccounts.add(id);busyCount++;
try {
const result=await api(`/accounts/${id}/${refresh?'refresh':'check'}`,{method:'POST'});
if(!silent)toast(`账户可用 · 已同步 ${result.models} 个模型`);
return true;
} catch(error) { if(!silent)toast(error.message,true); return false; }
finally { busyAccounts.delete(id);busyCount--; }
}
async function copy(text) { try { await navigator.clipboard.writeText(text);toast('已复制到剪贴板'); } catch {toast('复制失败,请手动选择文本复制',true);} }
$('#account-form').addEventListener('submit',async event=>{
event.preventDefault(); const form=event.currentTarget,button=form.querySelector('[type=submit]');button.disabled=true;errorAt('#account-error','');
const values=Object.fromEntries(new FormData(form)); const id=values.id;delete values.id;values.enabled=form.elements.enabled.checked;
if (!values.token.trim()) delete values.token;
if (!values.clientCookie.trim()) delete values.clientCookie;
try {await api(id?`/accounts/${id}`:'/accounts',{method:id?'PATCH':'POST',body:values});form.reset();$('#account-dialog').close();toast(id?'账户已更新':'账户已添加,可以检测连接');await reload(true);}
catch(error){errorAt('#account-error',error.message);}finally{button.disabled=false;}
});
$('#import-file').addEventListener('change',async event=>{
const file=event.target.files[0];if(!file)return;
if(file.size>1048576){errorAt('#import-error','文件不能超过 1 MB');return;}
$('#import-form').elements.accounts.value=await file.text();
});
$('#import-form').addEventListener('submit',async event=>{
event.preventDefault();const form=event.currentTarget,button=form.querySelector('[type=submit]');button.disabled=true;errorAt('#import-error','');
try {let body;try{body=JSON.parse(form.elements.accounts.value);}catch{throw new Error('JSON 格式不正确,请检查引号和逗号');}const result=await api('/accounts/import',{method:'POST',body});form.reset();$('#import-dialog').close();toast(`成功导入 ${result.accounts.length} 个账户`);await reload(true);}
catch(error){errorAt('#import-error',error.message);}finally{button.disabled=false;}
});
$('#confirm-form').addEventListener('submit',async event=>{
event.preventDefault();const button=event.currentTarget.querySelector('[type=submit]');button.disabled=true;errorAt('#confirm-error','');
try{await api(`/accounts/${deleteId}`,{method:'DELETE'});$('#confirm-dialog').close();toast('账户已移除');await reload(true);}catch(error){errorAt('#confirm-error',error.message);}finally{button.disabled=false;}
});
document.addEventListener('input',event=>{
if(event.target.id==='account-search'){accountQuery=event.target.value;$('#accounts-table').innerHTML=filteredAccounts();}
if(event.target.id==='log-search'){logQuery=event.target.value;logPage=0;$('#logs-content').innerHTML=logsContent();}
});
document.addEventListener('change',event=>{
if(event.target.id==='account-filter'){accountFilter=event.target.value;$('#accounts-table').innerHTML=filteredAccounts();}
if(event.target.id==='log-filter'){logFilter=event.target.value;logPage=0;$('#logs-content').innerHTML=logsContent();}
});
document.addEventListener('click',async event=>{
const close=event.target.closest('[data-close]');if(close){$(`#${close.dataset.close}`).close();return;}
const button=event.target.closest('[data-action]');if(!button || button.disabled)return;
const {action,id}=button.dataset;
button.closest('details')?.removeAttribute('open');
try {
if(action==='add')return openAccount();
if(action==='edit')return openAccount(id);
if(action==='import'){errorAt('#import-error','');$('#import-form').reset();return $('#import-dialog').showModal();}
if(action==='delete'){deleteId=id;errorAt('#confirm-error','');$('#confirm-message').textContent=`将移除「${state.accounts.find(a=>a.id===id).name}」及其本地凭据。已有请求记录会保留。`;return $('#confirm-dialog').showModal();}
if(action==='log-detail'){
const r=state.requests.find(r=>r.id===id);
$('#request-detail').innerHTML=`${[['请求 ID',r.id],['开始时间',date(r.startedAt)],['请求类型',kindLabel(r.kind)],['账户',r.accountName || '未分配'],['模型',r.model || '—'],['首字延迟',duration(r.ttftMs)],['总耗时',duration(r.durationMs)],['结果',statuses[r.status]],['Token 用量',r.usage?`${r.usage.prompt_tokens} 输入 / ${r.usage.completion_tokens} 输出`:'上游未提供'],...(r.error?[['错误',r.error]]:[])].map(([label,value])=>`
${label} ${esc(value)} `).join('')} `;return $('#detail-dialog').showModal();
}
if(action==='copy-url')return copy(state.service.baseUrl);
if(action==='copy-code')return copy($('#curl-snippet').textContent);
if(action==='prev-logs'||action==='next-logs'){logPage+=action==='next-logs'?1:-1;$('#logs-content').innerHTML=logsContent();return;}
if(action==='export-logs'){
const cell=value=>`"${String(value??'').replace(/^[=+@-]/,"'").replace(/"/g,'""')}"`;
const csv=[['时间','类型','账户','模型','结果','首字延迟(ms)','耗时(ms)','错误'],...filteredLogs().map(r=>[date(r.startedAt),kindLabel(r.kind),r.accountName,r.model,statuses[r.status],r.ttftMs,r.durationMs,r.error])].map(row=>row.map(cell).join(',')).join('\r\n');
const url=URL.createObjectURL(new Blob(['\ufeff'+csv],{type:'text/csv;charset=utf-8'}));const link=document.createElement('a');link.href=url;link.download=`logicc-requests-${new Date().toISOString().slice(0,10)}.csv`;link.click();setTimeout(()=>URL.revokeObjectURL(url),1000);return;
}
if(action==='try-model'){location.hash='playground';page='playground';render();$('#play-form').elements.model.value=button.dataset.model;return;}
if(action==='stop-play'){playController?.abort();return;}
button.disabled=true;busyCount++;
if(action==='check'||action==='refresh-token')await checkAccount(id,action==='refresh-token');
if(action==='toggle'){const a=state.accounts.find(a=>a.id===id);await api(`/accounts/${id}`,{method:'PATCH',body:{enabled:!a.enabled}});toast(a.enabled?'已暂停此账户调度':'账户已启用');}
if(action==='sync-models'){const result=await api('/models/refresh',{method:'POST'});toast(`已同步 ${result.models.length} 个模型`);}
if(action==='check-all'){
const accounts=state.accounts.filter(a=>a.enabled);let ok=0;
if(!accounts.length)toast('没有已启用的账户');
else{for(let i=0;i{
if(event.target.id!=='play-form')return;
event.preventDefault();if(playController)return;
const form=event.target,output=$('#play-output'),status=$('#play-status'),meta=$('#play-meta'),submit=$('#play-submit'),stop=$('#play-stop');
playController=new AbortController();playStarted=performance.now();let first=null;
submit.disabled=true;stop.hidden=false;output.textContent='';output.classList.remove('output-placeholder');status.textContent='请求中';meta.textContent='正在等待模型响应…';
const data=new FormData(form),body={model:data.get('model'),stream:true,messages:[{role:'user',content:data.get('prompt')}]};
if(data.get('tool'))body.tools=[{type:'function',function:{name:data.get('tool')}}];
try{
const response=await fetch('/v1/chat/completions',{method:'POST',headers:{'Content-Type':'application/json',Authorization:`Bearer ${data.get('apiKey')||'local'}`},body:JSON.stringify(body),signal:playController.signal});
if(!response.ok){const result=await response.json();throw new Error(result.error?.message||`HTTP ${response.status}`);}
const reader=response.body.getReader(),decoder=new TextDecoder();let buffer='';
for(;;){const {value,done}=await reader.read();if(done)break;buffer+=decoder.decode(value,{stream:true});let index;
while((index=buffer.indexOf('\n\n'))!==-1){const frame=buffer.slice(0,index);buffer=buffer.slice(index+2);for(const line of frame.split('\n')){if(!line.startsWith('data:'))continue;const text=line.slice(5).trim();if(!text||text==='[DONE]')continue;const chunk=JSON.parse(text);if(chunk.error)throw new Error(chunk.error.message);const delta=chunk.choices?.[0]?.delta?.content;if(delta){first??=performance.now()-playStarted;output.textContent+=delta;status.textContent='接收中';}}}
}
status.textContent='已完成';meta.textContent=`首段文本 ${duration(first)} · 总耗时 ${duration(performance.now()-playStarted)}`;
if(!output.textContent)output.textContent='请求已完成,但上游未返回文本。';
}catch(error){const cancelled=error.name==='AbortError';status.textContent=cancelled?'已停止':'请求失败';meta.textContent=cancelled?'请求已由你停止':error.message;if(!output.textContent)output.textContent=cancelled?'请求已停止。':error.message;}
finally{playController=null;submit.disabled=false;stop.hidden=true;await reload();}
});
window.addEventListener('hashchange',()=>{if(playController)playController.abort();page=location.hash.slice(1)||'overview';render();$('#main').focus({preventScroll:true});window.scrollTo(0,0);});
$('#refresh').addEventListener('click',()=>reload(true));
for(const dialog of document.querySelectorAll('dialog'))dialog.addEventListener('click',event=>{if(event.target===dialog){const box=dialog.getBoundingClientRect();if(event.clientXbox.right||event.clientYbox.bottom)dialog.close();}});
await reload(true);
setInterval(()=>{if(!document.hidden)reload();},5000);