import{a as m,j as e}from"./react-vendor-BVoutfaX.js";import{u as p}from"./index-DoKF8LKc.js";import"./xyflow-CYMCcsWN.js";import"./graph-layout-7tFr_anw.js";import"./elk-CXeXGyKz.js";import"./graphology-BgTy_cc3.js";function u(r){return Array.isArray(r)?r.join(" "):typeof r=="string"?r:""}function b(r){var n;return[r.name,r.summary,r.filePath,r.tags.join(" "),u((n=r.knowledgeMeta)==null?void 0:n.content)].join(`
`)}function f(r){const n=r.toLowerCase(),a=n.match(/[a-z0-9_\-\.]{2,}/g)??[],t=n.match(/[\u4e00-\u9fa5]/g)??[],c=[];for(let s=0;s<t.length-1;s+=1)c.push(`${t[s]}${t[s+1]}`);return Array.from(new Set([...a,...c,...t].filter(s=>s.trim().length>0)))}function h(r,n){const a=r.replace(/\s+/g," ").trim();if(!a)return"";const t=a.toLowerCase(),c=n.map(i=>t.indexOf(i.toLowerCase())).filter(i=>i>=0).sort((i,d)=>i-d)[0],s=Math.max(0,(c??0)-80),l=a.slice(s,s+220);return`${s>0?"…":""}${l}${s+220<a.length?"…":""}`}function g(r,n){const a=f(n);return a.length===0?[]:r.map(t=>{const c=b(t),s=c.toLowerCase();let l=0;for(const i of a){const d=i.toLowerCase();if(!d)continue;const x=s.split(d).length-1;x>0&&(l+=x*Math.min(d.length,8))}return s.includes(n.toLowerCase())&&(l+=40),t.name.toLowerCase().includes(n.toLowerCase())&&(l+=80),{node:t,score:l,snippet:h(c,a)}}).filter(t=>t.score>0&&t.snippet).sort((t,c)=>c.score-t.score).slice(0,8)}function j(r,n){if(!r.trim())return"请输入要检索或提问的内容。";if(n.length===0)return"知识库未检索到明确依据。建议换一个关键词，或确认相关文档是否已经加入 05_需求文档 / 07_技术文档 / 08_测试相关。";const a=n.slice(0,4);return[`结论：已基于本地知识库检索到 ${n.length} 条相关依据。以下是可追溯摘要：`,"",...a.map((t,c)=>`${c+1}. ${t.node.name}
   ${t.snippet}
   来源：${t.node.filePath??t.node.id}`),"","说明：当前为本地抽取式 RAG，不调用外部大模型；回答只基于知识库原文片段生成。"].join(`
`)}function L({onClose:r}){const n=p(o=>o.graph),a=p(o=>o.navigateToNodeInLayer),[t,c]=m.useState(""),[s,l]=m.useState(""),i=m.useMemo(()=>g((n==null?void 0:n.nodes)??[],s),[n,s]),d=m.useMemo(()=>j(s,i),[s,i]),x=()=>l(t.trim());return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/65 backdrop-blur-sm p-4 sm:p-6",onMouseDown:r,children:e.jsxs("div",{className:"w-[calc(100vw-32px)] max-w-[920px] h-[calc(100vh-64px)] max-h-[760px] rounded-lg border border-border-medium bg-surface shadow-2xl overflow-hidden flex flex-col",onMouseDown:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle bg-elevated/40",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-heading text-lg text-text-primary",children:"知识库 RAG 问答"}),e.jsx("p",{className:"text-xs text-text-muted mt-1",children:"本地检索 knowledge-graph.json 中的文档内容，返回可追溯来源。"})]}),e.jsx("button",{type:"button",onClick:r,className:"text-text-muted hover:text-accent transition-colors text-xl leading-none",children:"×"})]}),e.jsxs("div",{className:"p-5 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{value:t,onChange:o=>c(o.target.value),onKeyDown:o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&x()},placeholder:"例如：如愿系统的真实人额度规则是什么？客服工单怎么流转？",className:"flex-1 min-h-[76px] resize-none bg-elevated text-text-primary text-sm rounded-lg px-3 py-2 border border-border-subtle focus:outline-none focus:border-accent/50 placeholder-text-muted"}),e.jsx("button",{type:"button",onClick:x,className:"px-4 py-2 rounded-lg bg-accent/20 text-accent hover:text-accent-bright border border-accent/30 text-sm font-semibold transition-colors",children:"检索问答"})]}),e.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"快捷键：Ctrl + Enter 提交"})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-5 grid grid-cols-1 lg:grid-cols-[1fr_320px] gap-5",children:[e.jsxs("section",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[11px] font-semibold text-accent uppercase tracking-wider mb-2",children:"回答"}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm leading-relaxed text-text-secondary bg-elevated/50 border border-border-subtle rounded-lg p-4 font-sans",children:s?d:"输入问题后点击“检索问答”。"})]}),e.jsxs("section",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[11px] font-semibold text-accent uppercase tracking-wider mb-2",children:"命中文档"}),e.jsxs("div",{className:"space-y-2",children:[i.length===0&&s&&e.jsx("div",{className:"text-sm text-text-muted border border-border-subtle rounded-lg p-3",children:"暂无命中。"}),i.map(o=>e.jsxs("button",{type:"button",onClick:()=>a(o.node.id),className:"w-full text-left border border-border-subtle bg-elevated/40 hover:border-accent/40 rounded-lg p-3 transition-colors",children:[e.jsx("div",{className:"text-sm text-text-primary truncate",children:o.node.name}),e.jsx("div",{className:"text-[11px] text-text-muted mt-1 truncate",children:o.node.filePath??o.node.id}),e.jsx("div",{className:"text-xs text-text-secondary mt-2 line-clamp-3",children:o.snippet})]},o.node.id))]})]})]})]})})}export{L as default};
