<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>BoltFusionAI知识库</title>
<style>:root{font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#17243b;background:#f4f7fb}*{box-sizing:border-box}body{margin:0}header{background:#fff;border-bottom:1px solid #e1e7f0;padding:24px max(5vw,20px)}h1{margin:0;font-size:25px}small,.muted{color:#63728c}main{max-width:1420px;margin:28px auto;padding:0 24px}.grid{display:grid;grid-template-columns:360px 1fr;gap:24px}.card{background:white;border:1px solid #e1e7f0;border-radius:14px;padding:24px;margin-bottom:22px}h2{font-size:18px;margin:0 0 18px}label{display:block;font-weight:550;margin:16px 0 6px}input,select,textarea{width:100%;border:1px solid #c9d4e3;border-radius:8px;padding:10px;font:inherit}textarea{min-height:96px;resize:vertical}button{border:0;border-radius:8px;padding:10px 16px;font:inherit;cursor:pointer;color:white;background:#315dec;margin-top:16px}button.secondary{background:#edf2ff;color:#3151a4}button:disabled{opacity:.5;cursor:default}.pill{display:inline-block;background:#edf4ff;color:#3159aa;border-radius:16px;padding:3px 10px;font-size:13px}.entry{border:1px solid #e1e7f0;border-radius:10px;padding:16px;margin:12px 0}.entry h3{margin:0 0 6px;font-size:17px}.error{color:#b52e3e;white-space:pre-wrap}.row{display:flex;align-items:center;justify-content:space-between;gap:12px}pre{font:13px/1.7 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;max-height:520px;overflow:auto}.banner{padding:13px 18px;background:#eef4ff;border-radius:10px;margin:18px 0}.hidden{display:none}@media(max-width:850px){.grid{grid-template-columns:1fr}}a{color:#315dec}</style>
<header><h1>BoltFusionAI知识库</h1><div class="muted">先登录 Spec，再注册、选择和查询知识库</div></header><main><div id="status" class="banner" role="status">正在检查登录状态…</div><div class="grid"><aside><section class="card"><h2>登录并注册知识库</h2><p class="muted">先在 Spec 登录账号，从知识库“外部接入”复制 MCP 地址。接下来通过浏览器登录授权，只读访问该知识库。</p><a href="https://spec.boltfusion.cn/" target="_blank" rel="noreferrer">打开 Spec 登录</a><form id="connect"><label for="name">本地显示名称</label><input id="name" required maxlength="120" placeholder="例如：ecology9知识库"><label for="platform">平台归属</label><select id="platform"><option value="general">通用知识库</option><option value="e9">泛微 ecology9</option><option value="e10">泛微 ecology10</option><option value="shared">E9/E10 共用构建库（审核目录限定）</option></select><label for="role">知识用途</label><select id="role"><option value="general">通用库</option><option value="platform_spec">平台原始知识库</option><option value="implementation_agent">实施智能体知识库</option><option value="agent_builder">智能体构建知识库</option></select><label for="endpoint">MCP 接入地址</label><input id="endpoint" required type="url" placeholder="https://spec.example/mcp/projects/…/libraries/…"><button id="login" type="submit">登录 Spec 并注册</button></form><p class="muted">账号密码由 Spec 登录页处理，本地页面不收集密码。令牌存入系统钥匙串；支持自动续期。会话目标至少 7 天，实际授权以服务端为准。</p><div id="connectError" class="error" role="alert"></div></section></aside><article><section class="card"><div class="row"><h2>已注册知识库</h2><button class="secondary" id="refresh">刷新状态</button></div><div id="libraries">登录授权后显示知识库。</div></section><section class="card"><h2>查询与连接验证</h2><label for="scope">任务平台</label><select id="scope"><option value="e9">ecology9</option><option value="e10">ecology10</option><option value="general">通用：手选通用库</option></select><label for="purpose">任务用途</label><select id="purpose"><option value="knowledge">K1 手选知识库（无默认库）</option><option value="implementation">业务与运维：平台库＋实施智能体库</option><option value="builder">智能体构建：基础库＋构建库＋实施库</option></select><label for="library">K1 必须手选；业务按双库、构建按三库绑定查询</label><select id="library"></select><label for="query">查询问题</label><textarea id="query" placeholder="输入问题；结果会保留来源和引用，不上传至经验服务。"></textarea><div class="row"><select aria-label="推理模式" id="mode" style="width:auto"><option value="QUICK">QUICK 快速检索</option><option value="SMART">SMART 智能推理（最长约15分钟）</option></select><button id="search">查询知识库</button></div><div id="queryState" role="status"></div><pre id="result"></pre></section></article></div></main>
<script>
let state={libraries:[],bindings:{}},poll;
const $=s=>document.querySelector(s);
const errors={local_session_required:'本地会话失效，请刷新页面。',spec_login_required:'请先登录 Spec。',oauth_refresh_requires_login:'自动续期未完成，请重新登录授权。',knowledge_platform_mismatch:'知识库平台不匹配，E9 与 E10 不能互相代用。',platform_knowledge_binding_required:'请先绑定该平台的知识库。',knowledge_not_published:'构建知识库尚未发布，不能用于业务构建。',unreviewed_shared_library:'共用知识库必须有已审核的精确身份映射。',knowledge_not_verified:'知识库连接尚未验证，请检查权限和外部接入状态。',permission_denied:'当前 Spec 账号没有访问权限。',oauth_permission_denied:'授权已拒绝，未完成注册。',remote_unavailable:'Spec 暂时不可用，请稍后重试。'};
async function api(path,value){const r=await fetch(path,value===undefined?{cache:'no-store'}:{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(value)});const data=await r.json();if(!r.ok)throw Error(errors[data.error]||data.error||'请求失败');return data;}
function esc(v){const d=document.createElement('div');d.textContent=String(v);return d.innerHTML;}
function selection(){const platform=$('#scope').value;const list=state.libraries.filter(p=>p.platform===platform||(p.applicablePlatforms||[]).includes(platform));$('#library').innerHTML=list.length?'<option value="">请手动选择本次知识库</option>'+list.map(p=>`<option value="${esc(p.id)}">${esc(p.name)}${p.ready?'':'（未验证）'}</option>`).join(''):'<option value="">尚未绑定此平台的知识库</option>';$('#search').disabled=!state.authenticated||($('#purpose').value==='knowledge'&&!$('#library').value);}
async function refresh(){try{state=await api('/api/status');$('#status').textContent=state.authenticated?'已通过 Spec 登录授权 · E9/E10 分别绑定 · 后台自动续期':'尚未登录授权：请先登录 Spec 并完成知识库授权';$('#libraries').innerHTML=state.libraries.length?state.libraries.map(p=>`<div class="entry"><div class="row"><h3>${esc(p.name)}</h3><span class="pill">${esc(p.platform)} · ${esc(p.role)}</span></div><small>${p.authenticated?'已登录':'需要重新登录'} · ${p.ready?'连接已验证':'连接未验证'}</small><div><button class="secondary" data-bind="${esc(p.id)}" ${!p.ready||!p.authenticated||$('#purpose').value==='knowledge'||p.platform==='general'||!(p.applicablePlatforms||[p.platform]).includes($('#scope').value)||p.platform==='shared'&&$('#purpose').value!=='builder'?'disabled':''}>${state.bindings[$('#scope').value]?.[$('#purpose').value]?.[p.role]===p.id?'已绑定当前用途':'绑定到当前业务/构建用途'}</button> <button class="secondary" data-logout="${esc(p.id)}">退出并撤销此库授权</button></div></div>`).join(''):'登录授权后注册的知识库将在这里显示。';selection();}catch(e){$('#status').textContent=e.message;}}
$('#connect').onsubmit=async e=>{e.preventDefault();$('#connectError').textContent='';$('#login').disabled=true;try{const r=await api('/api/login',{name:$('#name').value,platform:$('#platform').value,role:$('#role').value,endpoint:$('#endpoint').value});location.assign(r.authorizationUrl);}catch(e){$('#connectError').textContent=e.message;$('#login').disabled=false;}};
$('#libraries').onclick=async e=>{const logout=e.target.closest('[data-logout]');if(logout){logout.disabled=true;try{const r=await api('/api/logout',{libraryRef:logout.dataset.logout});await refresh();$('#status').textContent=r.remoteRevocation==='pending'?'本机已退出；Spec撤销尚未确认，请重试退出以完成远端撤销。':'本机已退出，Spec已确认撤销此库授权。';}catch(e){$('#status').textContent=e.message;logout.disabled=false;}return;}const b=e.target.closest('[data-bind]');if(!b)return;try{const p=state.libraries.find(x=>x.id===b.dataset.bind);await api('/api/select',{platform:$('#scope').value,role:p.role,purpose:$('#purpose').value,libraryRef:p.id});await refresh();}catch(e){$('#status').textContent=e.message;}};
$('#refresh').onclick=refresh;$('#scope').onchange=refresh;$('#library').onchange=()=>{$('#search').disabled=!$('#library').value;};$('#purpose').onchange=refresh;
$('#search').onclick=async()=>{clearTimeout(poll);$('#search').disabled=true;$('#result').textContent='';try{const r=await api('/api/query',{libraryRef:$('#library').value,platform:$('#scope').value,query:$('#query').value,purpose:$('#purpose').value,reasoningMode:$('#mode').value,limit:5});$('#queryState').textContent='查询进行中…';const check=async()=>{try{const j=await api('/api/query-status?id='+encodeURIComponent(r.jobId));if(j.state==='running'){poll=setTimeout(check,1500);return;}$('#queryState').textContent=j.state==='completed'?'查询已完成':'查询失败：'+(errors[j.error]||j.error);if(j.result)$('#result').textContent=JSON.stringify(j.result,null,2);selection();}catch(e){$('#queryState').textContent=e.message;selection();}};await check();}catch(e){$('#queryState').textContent=e.message;selection();}};
refresh();
</script></html>
