2 lines
46 KiB
JavaScript
2 lines
46 KiB
JavaScript
import{r as o,j as e,g as Nt,i as wt}from"./router-zNjPR4CY.js";import{D as Y,i as ee,j as te,k as se,l as St,a5 as ne,X as Le,Y as Be,I as We,S as kt,B as b,a3 as _t,ai as Ct,aj as Mt,E as Et,T as Pt,O as $t,P as qe}from"./index-CuOHsLf7.js";import{B as g}from"./badge-CDs67obV.js";import{T as Tt,S as Ke,a7 as Dt,v as F,D as Ot,N as It,R as Rt,x as Lt}from"./icons-DTcdLw9j.js";import{S as Bt,a as qt,b as At,c as Ft,d as de}from"./select-DGqIoF9r.js";import{C as Se}from"./checkbox-DWiVrbnx.js";import{r as Gt,R as Ut,B as Jt,a as zt,C as Ht,M as Vt,P as Wt,H as K,b as Q}from"./reactflow-Bd-f2Ch7.js";const ue=8;function Kt(t){switch(t){case"entity":return"实体删除";case"relation":return"关系删除";case"paragraph":return"段落删除";case"source":return"来源删除";case"mixed":return"混合删除";default:return t||"删除"}}function Ae(t,s){return`${t} ${s}`}function Qt({items:t}){return t.length<=0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"当前预览没有可展示的明细项。"}):e.jsx("div",{className:"space-y-2",children:t.slice(0,16).map(s=>e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{variant:"outline",children:s.item_type}),s.source?e.jsx(g,{variant:"secondary",children:s.source}):null]}),e.jsx("div",{className:"mt-2 text-sm font-medium break-words",children:s.label||s.item_key||s.item_hash}),s.preview?e.jsx("div",{className:"mt-1 text-xs text-muted-foreground break-words",children:s.preview}):null,e.jsx("code",{className:"mt-2 block break-all text-[11px] text-muted-foreground",children:s.item_hash||s.item_key})]},`${s.item_type}:${s.item_hash}:${s.item_key??""}`))})}function Zt({open:t,onOpenChange:s,title:n,description:a,preview:l,result:r,loadingPreview:m=!1,executing:p=!1,restoring:y=!1,error:h,onExecute:k,onRestore:N}){const[S,$]=o.useState(""),[E,D]=o.useState(1),T=l?.counts??r?.counts??{},G=Array.isArray(l?.sources)?l.sources:[],C=Array.isArray(l?.items)?l.items:[],M=o.useMemo(()=>{const j=S.trim().toLowerCase();return j?C.filter(_=>[_.item_type,_.item_hash,_.item_key,_.label,_.preview,_.source].map(L=>String(L??"").toLowerCase()).some(L=>L.includes(j))):C},[S,C]),v=Math.max(1,Math.ceil(M.length/ue)),he=o.useMemo(()=>{const j=(E-1)*ue;return M.slice(j,j+ue)},[M,E]),w=[{key:"entities",label:"实体",value:Number(T.entities??0)},{key:"relations",label:"关系",value:Number(T.relations??0)},{key:"paragraphs",label:"段落",value:Number(T.paragraphs??0)},{key:"sources",label:"来源",value:Number(T.sources??0)}].filter(j=>j.value>0);return o.useEffect(()=>{$(""),D(1)},[l?.mode,l?.item_count,t]),o.useEffect(()=>{D(1)},[S]),o.useEffect(()=>{E>v&&D(v)},[E,v]),e.jsx(Y,{open:t,onOpenChange:s,children:e.jsxs(ee,{className:"max-w-3xl max-h-[85vh] grid grid-rows-[auto_1fr_auto]",confirmOnEnter:!0,children:[e.jsxs(te,{children:[e.jsxs(se,{className:"flex items-center gap-2",children:[e.jsx(Tt,{className:"h-5 w-5 text-amber-500"}),n]}),a?e.jsx(St,{children:a}):null]}),e.jsxs(ne,{className:"space-y-4 overflow-y-auto",children:[m?e.jsx("div",{className:"rounded-lg border bg-muted/30 p-4 text-sm text-muted-foreground",children:"正在生成删除预览..."}):null,h?e.jsx(Le,{variant:"destructive",children:e.jsx(Be,{children:h})}):null,l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{children:Kt(l.mode)}),e.jsx(g,{variant:"secondary",children:Ae("预览项",Number(l.item_count??C.length))}),w.map(j=>e.jsx(g,{variant:"outline",children:Ae(j.label,j.value)},j.key))]}),G.length>0?e.jsxs("div",{className:"mt-3 text-sm text-muted-foreground break-words",children:["关联来源:",G.join("、")]}):null,l.matched_source_count?e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["命中来源 ",l.matched_source_count,l.requested_source_count?` / 请求来源 ${l.requested_source_count}`:""]}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:"本次将删除的对象摘要"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["命中 ",M.length," / ",C.length," 项"]})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:min-w-[300px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ke,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(We,{value:S,onChange:j=>$(j.target.value),placeholder:"搜索类型 / hash / item_key / source",className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:["第 ",E," / ",v," 页"]}),e.jsxs("span",{children:["每页 ",ue," 项"]})]})]})]}),e.jsx(kt,{className:"h-[320px] rounded-lg border bg-background/60",children:e.jsx("div",{className:"p-3",children:e.jsx(Qt,{items:he})})}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>D(j=>Math.max(1,j-1)),disabled:E<=1,children:"上一页"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"支持按对象类型、hash、item_key、source 和预览内容检索"}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>D(j=>Math.min(v,j+1)),disabled:E>=v,children:"下一页"})]})]})]}):null,r?.success?e.jsx(Le,{children:e.jsxs(Be,{className:"space-y-1",children:[e.jsxs("div",{children:["删除执行成功,操作 ID:",e.jsx("code",{children:r.operation_id})]}),e.jsxs("div",{children:["实际删除:实体 ",r.deleted_entity_count,",关系 ",r.deleted_relation_count,",段落 ",r.deleted_paragraph_count,",来源 ",r.deleted_source_count]})]})}):null]}),e.jsxs(_t,{children:[e.jsx(b,{variant:"outline",onClick:()=>s(!1),children:"关闭"}),r?.success&&N?e.jsxs(b,{variant:"outline",onClick:N,disabled:y,children:[e.jsx(Dt,{className:"mr-2 h-4 w-4"}),y?"恢复中...":"恢复本次删除"]}):null,r?.success?null:e.jsxs(b,{"data-dialog-action":"confirm",variant:"destructive",onClick:k,disabled:m||p||!l,children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),p?"执行中...":"确认删除"]})]})]})})}async function Xt(){if(Ct()){const t=await Mt();return Fe(t)}return Fe(void 0)}function Fe(t){const s=String(t??"").replace(/\/+$/,"");return s?s.endsWith("/api/webui/memory")?s:s.endsWith("/api/webui")?`${s}/memory`:`${s}/api/webui/memory`:"/api/webui/memory"}function Yt(t){return{...t,credentials:t?.credentials??"include"}}function es(t){const s=t.trimStart().toLowerCase();return s.startsWith("<!doctype")||s.startsWith("<html")}function Ge(t){if(typeof window>"u")return t;try{return new URL(t,window.location.href).toString()}catch{return t}}function ts(t){const s=[];if(typeof window<"u"){const n=window.location.hostname;(n==="localhost"||n==="127.0.0.1")&&s.push(`http://${n}:8001/api/webui/memory`)}return s.push("http://127.0.0.1:8001/api/webui/memory"),s.push("http://localhost:8001/api/webui/memory"),Array.from(new Set(s)).filter(n=>n!==t)}async function c(t,s){const n=await Xt(),a=[`${n}${t}`,...ts(n).map(r=>`${r}${t}`)],l=Yt(s);for(let r=0;r<a.length;r+=1){const m=a[r],p=await fetch(m,l),y=await p.text(),h=es(y),k=r<a.length-1;if(!((h||p.status===404)&&k)){if(!p.ok){let N=`${p.status}`;try{const S=JSON.parse(y);N=String(S?.detail??S?.error??N)}catch{h&&(N=`接口返回了前端页面,未命中后端 API 路由;当前请求:${Ge(m)}`)}throw new Error(N)}try{return JSON.parse(y)}catch{throw h?new Error(`接口返回了前端页面,未命中后端 API 路由;当前请求:${Ge(m)}`):new Error(y?"接口响应不是合法 JSON":"接口返回了空响应")}}}throw new Error("接口请求失败")}async function ss(t=120){return c(`/graph?limit=${t}`)}async function ns(t,s=50){const n=new URLSearchParams({query:t,limit:String(s)});return c(`/graph/search?${n.toString()}`)}async function Ue(t,s){const n=new URLSearchParams({node_id:t,relation_limit:String(20),paragraph_limit:String(20),evidence_node_limit:String(80)});return c(`/graph/node-detail?${n.toString()}`)}async function as(t,s,n){const a=new URLSearchParams({source:t,target:s,paragraph_limit:String(20),evidence_node_limit:String(80)});return c(`/graph/edge-detail?${a.toString()}`)}async function rs(t){return c("/delete/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function is(t){return c("/delete/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function os(t){return c("/delete/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Ms(t=20,s=""){const n=new URLSearchParams({limit:String(t)});return s.trim()&&n.set("mode",s),c(`/delete/operations?${n.toString()}`)}async function Es(t){return c(`/delete/operations/${encodeURIComponent(t)}`)}async function Ps(t){const s=new URLSearchParams({limit:String(t?.limit??50)});return t?.status?.trim()&&s.set("status",t.status.trim()),t?.rollbackStatus?.trim()&&s.set("rollback_status",t.rollbackStatus.trim()),t?.query?.trim()&&s.set("query",t.query.trim()),c(`/feedback-corrections?${s.toString()}`)}async function $s(t){return c(`/feedback-corrections/${t}`)}async function Ts(t,s){return c(`/feedback-corrections/${t}/rollback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})}async function Ds(){return c("/sources")}async function Os(t){const s=new URLSearchParams({query:t?.query??"",limit:String(t?.limit??20),source:t?.source??"",person_id:t?.personId??"",platform:t?.platform??"",user_id:t?.userId??""});return t?.timeStart!==void 0&&s.set("time_start",String(t.timeStart)),t?.timeEnd!==void 0&&s.set("time_end",String(t.timeEnd)),c(`/episodes?${s.toString()}`)}async function Is(t){return c(`/episodes/${encodeURIComponent(t)}`)}async function Rs(t){return c("/episodes/rebuild",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Ls(t=20){return c(`/episodes/status?limit=${t}`)}async function Bs(t){return c("/episodes/process-pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function qs(t=50){return c(`/profiles?limit=${t}`)}async function As(t){const s=new URLSearchParams({person_id:t.personId??"",person_keyword:t.personKeyword??"",platform:t.platform??"",user_id:t.userId??"",limit:String(t.limit??50)});return c(`/profiles/search?${s.toString()}`)}async function Fs(t){const s=new URLSearchParams({person_id:t.personId??"",person_keyword:t.personKeyword??"",platform:t.platform??"",user_id:t.userId??"",limit:String(t.limit??12),force_refresh:t.forceRefresh?"true":"false"});return c(`/profiles/query?${s.toString()}`)}async function Gs(t){return c("/profiles/override",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Us(t){return c(`/profiles/override/${encodeURIComponent(t)}`,{method:"DELETE"})}async function Js(t=50){return c(`/maintenance/recycle-bin?limit=${t}`)}function me(t,s){return c(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})}async function zs(t){return me("/maintenance/restore",{target:t})}async function Hs(t){return me("/maintenance/reinforce",{target:t})}async function Vs(t){return me("/maintenance/freeze",{target:t})}async function Ws(t,s){return me("/maintenance/protect",s===void 0?{target:t}:{target:t,hours:s})}async function Ks(){return c("/runtime/config")}async function Qs(){return c("/runtime/self-check/refresh",{method:"POST"})}async function Zs(){return c("/import/settings")}async function Xs(){return c("/import/path-aliases")}async function Ys(t){return c("/import/resolve-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function en(t=20){return c(`/import/tasks?limit=${t}`)}async function tn(t,s=!1){return c(`/import/tasks/${encodeURIComponent(t)}?include_chunks=${s?"true":"false"}`)}async function sn(t,s,n=0,a=50){return c(`/import/tasks/${encodeURIComponent(t)}/chunks/${encodeURIComponent(s)}?offset=${n}&limit=${a}`)}async function nn(t,s){const n=new FormData;return t.forEach(a=>{n.append("files",a)}),n.append("payload_json",JSON.stringify(s)),c("/import/upload",{method:"POST",body:n})}async function an(t){return c("/import/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function rn(t){return c("/import/raw-scan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function on(t){return c("/import/lpmm-openie",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function ln(t){return c("/import/lpmm-convert",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function cn(t){return c("/import/temporal-backfill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function dn(t){return c("/import/maibot-migration",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function un(t){return c(`/import/tasks/${encodeURIComponent(t)}/cancel`,{method:"POST"})}async function mn(t,s={}){return c(`/import/tasks/${encodeURIComponent(t)}/retry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})}async function hn(){return c("/retrieval_tuning/profile")}async function xn(t=20){return c(`/retrieval_tuning/tasks?limit=${t}`)}async function pn(t){return c("/retrieval_tuning/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function fn(t){return c(`/retrieval_tuning/tasks/${encodeURIComponent(t)}/apply-best`,{method:"POST"})}function Qe(t){if(!t)return"未知";const s=new Date(Number(t)*1e3);return Number.isNaN(s.getTime())?"未知":s.toLocaleString()}function Ze({items:t,onDeleteRelation:s}){return t.length<=0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无可展示的关系语义。"}):e.jsx("div",{className:"space-y-2",children:t.map(n=>e.jsxs("div",{className:"rounded-lg border bg-muted/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{variant:"outline",children:n.predicate||"未命名谓词"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["证据段落 ",n.paragraph_count]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["置信度 ",n.confidence.toFixed(3)]})]}),s?e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>s(n),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除关系"]}):null]}),e.jsx("p",{className:"mt-2 text-sm font-medium",children:n.text}),e.jsx("code",{className:"mt-2 block break-all text-xs text-muted-foreground",children:n.hash})]},n.hash))})}function Xe({items:t,onDeleteParagraph:s}){return t.length<=0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无可展示的来源段落。"}):e.jsx("div",{className:"space-y-3",children:t.map(n=>e.jsxs("div",{className:"rounded-lg border bg-muted/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{variant:"secondary",children:n.source||"未命名来源"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["实体 ",n.entity_count]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["关系 ",n.relation_count]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["更新时间 ",Qe(n.updated_at)]})]}),s?e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>s(n),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除段落"]}):null]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-sm break-words",children:n.preview||n.content}),n.entities.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:n.entities.slice(0,8).map(a=>e.jsx(g,{variant:"outline",className:"text-xs",children:a},`${n.hash}-${a}`))})]},n.hash))})}function ls({open:t,onOpenChange:s,selectedNodeData:n,nodeDetail:a,loading:l=!1,onOpenEvidence:r,onDeleteEntity:m,onDeleteRelation:p,onDeleteParagraph:y}){const h=a?.node??n,[k,N]=o.useState(!1);return o.useEffect(()=>{t||N(!1)},[t,h?.id]),e.jsx(Y,{open:t,onOpenChange:s,children:e.jsxs(ee,{className:"max-w-4xl max-h-[85vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsx(te,{children:e.jsx(se,{children:"实体详情"})}),e.jsx(ne,{className:"h-full overflow-y-auto",children:h?e.jsxs("div",{className:"space-y-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-xl border bg-muted/30 p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{children:h.type==="entity"?"实体":h.type}),"appearance_count"in(a?.node??{})&&e.jsxs(g,{variant:"outline",children:["出现次数 ",a?.node.appearance_count??0]})]}),e.jsx("h3",{className:"mt-2 text-lg font-semibold",children:h.content}),e.jsx("code",{className:"mt-2 block break-all text-xs text-muted-foreground",children:h.id})]}),e.jsxs("div",{className:"flex flex-col items-end gap-3",children:[e.jsx(b,{variant:"outline",onClick:r,disabled:!r,children:"切到证据视图"}),m?e.jsxs("div",{className:"flex flex-col items-end gap-2 rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Se,{checked:k,onCheckedChange:S=>N(!!S),"aria-label":"删除该实体相关证据段落"}),e.jsx("span",{children:"删除该实体相关证据段落"})]}),e.jsxs(b,{variant:"outline",onClick:()=>m({includeParagraphs:k}),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除实体"]})]}):null]})]}),l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在加载节点证据…"}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"相关关系"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a?.relations.length??0," 条"]})]}),e.jsx(Ze,{items:a?.relations??[],onDeleteRelation:p})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"支持段落"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a?.paragraphs.length??0," 个"]})]}),e.jsx(Xe,{items:a?.paragraphs??[],onDeleteParagraph:y})]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"尚未选中实体。"})})]})})}function cs({open:t,onOpenChange:s,selectedEdgeData:n,edgeDetail:a,loading:l=!1,onOpenEvidence:r,onDeleteEdgeGroup:m,onDeleteRelation:p,onDeleteParagraph:y}){const h=n?.source.content??a?.edge.source??"",k=n?.target.content??a?.edge.target??"",[N,S]=o.useState(!1);return o.useEffect(()=>{t||S(!1)},[t,a?.edge.source,a?.edge.target]),e.jsx(Y,{open:t,onOpenChange:s,children:e.jsxs(ee,{className:"max-w-4xl max-h-[85vh] overflow-hidden grid grid-rows-[auto_1fr_auto]",children:[e.jsx(te,{children:e.jsx(se,{children:"关系详情"})}),e.jsx(ne,{className:"overflow-y-auto",children:n||a?e.jsxs("div",{className:"space-y-6 pb-2",children:[e.jsx("div",{className:"rounded-xl border bg-muted/30 p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[(a?.edge.predicates??[]).map($=>e.jsx(g,{variant:"outline",children:$},$)),e.jsxs(g,{variant:"secondary",children:["关系 ",a?.edge.relation_count??n?.edge.relationCount??0]}),e.jsxs(g,{variant:"secondary",children:["证据 ",a?.edge.evidence_count??n?.edge.evidenceCount??0]})]}),e.jsxs("p",{className:"mt-3 text-base font-semibold break-words",children:[h," → ",k]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["聚合权重 ",(a?.edge.weight??n?.edge.weight??0).toFixed(4)]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-3",children:[e.jsx(b,{variant:"outline",onClick:r,disabled:!r,children:"切到证据视图"}),m?e.jsxs("div",{className:"flex flex-col items-end gap-2 rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Se,{checked:N,onCheckedChange:$=>S(!!$),"aria-label":"同时删除支撑段落"}),e.jsx("span",{children:"同时删除支撑段落"})]}),e.jsxs(b,{variant:"outline",onClick:()=>m({includeParagraphs:N}),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除此关系组"]})]}):null]})]})}),l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在加载边的证据…"}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"关系语义"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a?.relations.length??0," 条"]})]}),e.jsx(Ze,{items:a?.relations??[],onDeleteRelation:p})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"支持段落"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a?.paragraphs.length??0," 个"]})]}),e.jsx(Xe,{items:a?.paragraphs??[],onDeleteParagraph:y})]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"尚未选中关系。"})})]})})}function ds({open:t,onOpenChange:s,relation:n,metadata:a,onDeleteRelation:l}){const[r,m]=o.useState(!1);return o.useEffect(()=>{t||m(!1)},[t,n?.hash]),n?e.jsx(Y,{open:t,onOpenChange:s,children:e.jsxs(ee,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsx(te,{children:e.jsx(se,{children:"关系明细"})}),e.jsxs(ne,{className:"space-y-4 overflow-y-auto",children:[e.jsxs("div",{className:"rounded-xl border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{variant:"outline",children:n.predicate||a?.predicate||"未命名谓词"}),e.jsxs(g,{variant:"secondary",children:["证据段落 ",n.paragraph_count]}),e.jsxs(g,{variant:"secondary",children:["置信度 ",n.confidence.toFixed(3)]})]}),e.jsx("p",{className:"mt-3 text-base font-semibold break-words",children:n.text}),e.jsx("code",{className:"mt-3 block break-all text-xs text-muted-foreground",children:n.hash})]}),l?e.jsxs("div",{className:"rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Se,{checked:r,onCheckedChange:p=>m(!!p),"aria-label":"同时删除支撑该关系的段落"}),e.jsx("span",{children:"同时删除支撑该关系的段落"})]}),e.jsxs(b,{className:"mt-3",variant:"outline",onClick:()=>l(n,r),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除这条关系"]})]}):null]})]})}):null}function us({open:t,onOpenChange:s,paragraph:n,metadata:a,onDeleteParagraph:l}){return n?e.jsx(Y,{open:t,onOpenChange:s,children:e.jsxs(ee,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsx(te,{children:e.jsx(se,{children:"段落明细"})}),e.jsxs(ne,{className:"space-y-4 overflow-y-auto",children:[e.jsxs("div",{className:"rounded-xl border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{variant:"secondary",children:n.source||a?.source||"未命名来源"}),e.jsxs(g,{variant:"outline",children:["实体 ",n.entity_count]}),e.jsxs(g,{variant:"outline",children:["关系 ",n.relation_count]}),e.jsxs(g,{variant:"outline",children:["更新时间 ",Qe(n.updated_at??a?.updated_at)]})]}),e.jsx("p",{className:"mt-3 whitespace-pre-wrap text-sm break-words",children:n.content}),e.jsx("code",{className:"mt-3 block break-all text-xs text-muted-foreground",children:n.hash})]}),n.entities.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:n.entities.map(r=>e.jsx(g,{variant:"outline",children:r},`${n.hash}-${r}`))}):null,l?e.jsxs(b,{variant:"outline",onClick:()=>l(n),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"删除这段证据"]}):null]})]})}):null}var ms=Gt();const Je=Nt(ms),Ye=o.memo(({data:t})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(K,{type:"target",position:Q.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:t.content,children:t.label}),e.jsx(K,{type:"source",position:Q.Bottom})]}));Ye.displayName="EntityNode";const et=o.memo(({data:t})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(K,{type:"target",position:Q.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:t.content,children:t.label}),e.jsx(K,{type:"source",position:Q.Bottom})]}));et.displayName="ParagraphNode";const tt=o.memo(({data:t})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-amber-500 to-orange-600 border-2 border-orange-700 min-w-[140px]",children:[e.jsx(K,{type:"target",position:Q.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[180px]",title:t.content,children:t.label}),e.jsx(K,{type:"source",position:Q.Bottom})]}));tt.displayName="RelationNode";const hs={entity:Ye,relation:tt,paragraph:et};function xs(t,s){const n=new Je.graphlib.Graph;n.setDefaultEdgeLabel(()=>({})),n.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const a=[],l=[];return t.forEach(r=>{const m=r.type==="relation"?{width:180,height:60}:r.type==="paragraph"?{width:190,height:56}:{width:150,height:50};n.setNode(r.id,m)}),s.forEach(r=>{n.setEdge(r.source,r.target)}),Je.layout(n),t.forEach(r=>{const m=n.node(r.id);a.push({id:r.id,type:r.type,position:{x:m.x-75,y:m.y-25},data:{label:r.content.slice(0,20)+(r.content.length>20?"...":""),content:r.content,type:r.type}})}),s.forEach((r,m)=>{const p=r.kind&&r.kind!=="relation",y=r.kind==="mentions"?"#0f766e":r.kind==="supports"?"#b45309":r.kind==="subject"?"#4f46e5":r.kind==="object"?"#7c3aed":"#64748b",h={id:`edge-${m}`,source:r.source,target:r.target,animated:t.length<=200&&(p||r.weight>5),style:{strokeWidth:p?Math.min(Math.max(r.weight,1.5),4):Math.min(r.weight/2,5),opacity:p?.9:.6,stroke:y},labelStyle:{fill:"#334155",fontSize:11,fontWeight:600},labelBgPadding:[6,2],labelBgBorderRadius:6,labelBgStyle:{fill:"rgba(255,255,255,0.88)",fillOpacity:.95}};r.label&&(p||t.length<=120)?h.label=r.label:r.weight>10&&t.length<100&&(h.label=`${r.weight.toFixed(0)}`),l.push(h)}),{nodes:a,edges:l}}function ze({graphData:t,onNodeClick:s,onEdgeClick:n,loading:a=!1}){const{nodes:l,edges:r}=o.useMemo(()=>xs(t.nodes,t.edges),[t.edges,t.nodes]),m=l.length,p=o.useMemo(()=>t.nodes.some(h=>h.type!=="entity")?"evidence":"entity",[t.nodes]),y=o.useCallback(h=>h.type==="entity"?"#6366f1":h.type==="relation"?"#f59e0b":h.type==="paragraph"?"#10b981":"#6b7280",[]);return a?null:e.jsxs("div",{style:{touchAction:"none"},role:"img","aria-label":`知识图谱可视化,共 ${m} 个节点,${r.length} 条关系`,className:"w-full h-full",children:[e.jsx("span",{className:"sr-only",children:`知识图谱包含 ${m} 个节点和 ${r.length} 条关系。`}),e.jsxs(Ut,{nodes:l,edges:r,onNodeClick:s,onEdgeClick:n,nodeTypes:hs,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:m<=500,nodesDraggable:m<=1e3,attributionPosition:"bottom-left",panOnScroll:!0,panOnScrollMode:void 0,panOnDrag:!0,zoomOnPinch:!0,children:[e.jsx(Jt,{variant:zt.Dots,gap:12,size:1}),e.jsx(Ht,{}),m<=500&&e.jsx(Vt,{nodeColor:y,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(Wt,{position:"top-right",className:"bg-background/95 backdrop-blur-sm rounded-lg border p-3 shadow-lg",children:[e.jsx("div",{className:"text-sm font-semibold mb-2",children:p==="entity"?"实体关系图图例":"证据视图图例"}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700","aria-hidden":"true"}),e.jsx("span",{children:"实体节点"})]}),p==="evidence"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-amber-500 to-orange-600 border-2 border-orange-700","aria-hidden":"true"}),e.jsx("span",{children:"关系节点"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700","aria-hidden":"true"}),e.jsx("span",{children:"段落节点"})]}),e.jsx("div",{className:"text-muted-foreground",children:"紫色线表示关系到宾语,蓝色线表示关系到主语,绿色/橙色线表示段落证据。"})]}),p==="entity"&&e.jsx("div",{className:"text-muted-foreground",children:"线条表示实体间聚合关系,边标签优先显示主谓词,更多语义可点击查看详情。"}),m>200&&e.jsxs("div",{className:"mt-2 pt-2 border-t text-yellow-600 dark:text-yellow-500",children:[e.jsx("div",{className:"font-semibold",children:"性能模式"}),e.jsx("div",{children:"已禁用动画"}),m>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})]})}function ps(t){const s=(t.nodes??[]).map(a=>({id:a.id,type:"entity",content:String(a.name??a.id),metadata:a.attributes??{}})),n=(t.edges??[]).map(a=>({source:a.source,target:a.target,weight:Number(a.weight??1),kind:"relation",label:String(a.label??""),relationHashes:a.relation_hashes??[],predicates:a.predicates??[],relationCount:Number(a.relation_count??a.relation_hashes?.length??0),evidenceCount:Number(a.evidence_count??0)}));return{nodes:s,edges:n}}function He(t){return{nodes:(t?.nodes??[]).map(s=>({id:s.id,type:s.type,content:s.content,metadata:s.metadata??{}})),edges:(t?.edges??[]).map(s=>({source:s.source,target:s.target,weight:Number(s.weight??1),kind:s.kind,label:s.label})),focusEntities:t?.focus_entities??[]}}function Ve(t,s){const n=s.trim().toLowerCase();if(!n)return t;const a=new Set(t.nodes.filter(r=>r.content.toLowerCase().includes(n)||r.id.toLowerCase().includes(n)).map(r=>r.id)),l=t.edges.filter(r=>{const m=String(r.label??"").toLowerCase(),p=(r.predicates??[]).some(h=>h.toLowerCase().includes(n)),y=a.has(r.source)||a.has(r.target)||m.includes(n)||p;return y&&(a.add(r.source),a.add(r.target)),y});return{nodes:t.nodes.filter(r=>a.has(r.id)),edges:l,focusEntities:t.focusEntities}}function fs(t,s){const n=new Set,a=[];for(const l of[...t?.relations??[],...s?.relations??[]])n.has(l.hash)||(n.add(l.hash),a.push(l));return a}function gs(t,s){const n=new Set,a=[];for(const l of[...t?.paragraphs??[],...s?.paragraphs??[]])n.has(l.hash)||(n.add(l.hash),a.push(l));return a}function ys(t){const s=String(t?.hash??"").trim();if(!s)return null;const n=String(t?.subject??"").trim(),a=String(t?.predicate??"").trim(),l=String(t?.object??"").trim(),r=String(t?.text??`${n} ${a} ${l}`).trim();return{hash:s,subject:n,predicate:a,object:l,text:r,confidence:Number(t?.confidence??0),paragraph_count:Number(t?.paragraph_count??0),paragraph_hashes:Array.isArray(t?.paragraph_hashes)?t.paragraph_hashes.map(String):[],source_paragraph:""}}function js(t){const s=String(t?.hash??"").trim();if(!s)return null;const n=String(t?.preview??"").trim();return{hash:s,content:n,preview:n,source:String(t?.source??"").trim(),updated_at:typeof t?.updated_at=="number"?t.updated_at:null,entity_count:Number(t?.entity_count??0),relation_count:Number(t?.relation_count??0),entities:[],relations:[]}}function bs({embedded:t=!1,onOpenConsole:s}={}){const n=wt(),{toast:a}=Et(),[l,r]=o.useState(!1),[m,p]=o.useState("120"),[y,h]=o.useState(""),[k,N]=o.useState(""),[S,$]=o.useState(!1),[E,D]=o.useState([]),[T,G]=o.useState(!1),[C,M]=o.useState("entity"),[v,he]=o.useState({nodes:[],edges:[]}),[w,j]=o.useState({nodes:[],edges:[]}),[_,L]=o.useState({nodes:[],edges:[]}),[xe,st]=o.useState(null),[pe,B]=o.useState(null),[fe,q]=o.useState(null),[O,ae]=o.useState(null),[I,ge]=o.useState(null),[ke,U]=o.useState(null),[nt,re]=o.useState(null),[_e,J]=o.useState(null),[at,ie]=o.useState(null),[ye,z]=o.useState(!1),[H,Ce]=o.useState(null),[rt,Me]=o.useState(!1),[it,oe]=o.useState(null),[Z,je]=o.useState(null),[ot,Ee]=o.useState(!1),[lt,Pe]=o.useState(!1),[ct,be]=o.useState(null),$e=o.useMemo(()=>fs(O,I),[I,O]),Te=o.useMemo(()=>gs(O,I),[I,O]),De=o.useCallback(()=>{B(null),q(null),ae(null),ge(null),U(null),re(null),J(null),ie(null)},[]),A=o.useCallback(async i=>{try{r(!0);const d=await ss(Number(m)),u=ps(d),f=T&&k?Ve(u,k):u;st(d),he(u),j(f),L({nodes:[],edges:[]}),De(),i?.silent||a({title:"图谱已更新",description:`当前加载 ${u.nodes.length} 个节点、${u.edges.length} 条关系`})}catch(d){a({title:"加载失败",description:d instanceof Error?d.message:"未知错误",variant:"destructive"})}finally{r(!1)}},[k,m,De,T,a]);o.useEffect(()=>{A({silent:!0})},[A]);const Oe=o.useCallback(async()=>{const i=y.trim();if(!i){N(""),G(!1),D([]),j(v),a({title:"已重置筛选",description:`当前显示 ${v.nodes.length} 个节点、${v.edges.length} 条关系`});return}$(!0),N(i);try{const d=await ns(i,50);if(!d.success)throw new Error(d.error||"图谱检索失败");const u=Array.isArray(d.items)?d.items:[];D(u),G(!1),j(v),a({title:"全库检索完成",description:`命中 ${d.count??u.length} 条结果`})}catch{const u=Ve(v,i);D([]),G(!0),j(u),a({title:"后端检索失败,已回退本地筛选",description:`仅当前已加载范围(${u.nodes.length} 个节点、${u.edges.length} 条关系)`,variant:"destructive"})}finally{$(!1)}},[v,y,a]),V=o.useMemo(()=>({totalNodes:xe?.total_nodes??v.nodes.length,totalEdges:xe?.total_edges??v.edges.length,visibleNodes:w.nodes.length,visibleEdges:w.edges.length,evidenceNodes:_.nodes.length,evidenceEdges:_.edges.length}),[_.edges.length,_.nodes.length,v.edges.length,v.nodes.length,w.edges.length,w.nodes.length,xe]),R=o.useCallback(async i=>{Ce(i),be(null),je(null),oe(null),Me(!0);try{const d=await rs(i.request);be(d)}catch(d){oe(d instanceof Error?d.message:"删除预览失败")}finally{Me(!1)}},[]),ve=o.useCallback(i=>{i||(Ce(null),be(null),je(null),oe(null))},[]),dt=o.useCallback(async()=>{if(H)try{Ee(!0);const i=await is(H.request);je(i),a({title:i.success?"删除成功":"删除失败",description:i.success?`操作 ${i.operation_id} 已完成`:i.error||"未能执行删除",variant:i.success?"default":"destructive"}),i.success&&await A({silent:!0})}catch(i){oe(i instanceof Error?i.message:"删除失败"),a({title:"删除失败",description:i instanceof Error?i.message:"未知错误",variant:"destructive"})}finally{Ee(!1)}},[H,A,a]),ut=o.useCallback(async()=>{if(Z?.operation_id)try{Pe(!0),await os({operation_id:Z.operation_id,requested_by:"knowledge_graph"}),a({title:"恢复成功",description:`删除操作 ${Z.operation_id} 已恢复`}),ve(!1),await A({silent:!0})}catch(i){a({title:"恢复失败",description:i instanceof Error?i.message:"未知错误",variant:"destructive"})}finally{Pe(!1)}},[ve,Z?.operation_id,A,a]),le=o.useCallback(async(i,d)=>{const u=String(i||"").trim();if(!u)return;const f=w.nodes.find(x=>x.id===u);d?.locateInEvidence?B(null):B(f??{id:u,type:"entity",content:u,metadata:{}}),q(null),ge(null),U(null),re(null),J(null),ie(null);try{z(!0);const x=await Ue(u);ae(x),L(He(x.evidence_graph)),d?.locateInEvidence&&M("evidence")}catch(x){a({title:"加载节点详情失败",description:x instanceof Error?x.message:"未知错误",variant:"destructive"})}finally{z(!1)}},[w.nodes,a]),ce=o.useCallback(async(i,d,u)=>{const f=String(i||"").trim(),x=String(d||"").trim();if(!(!f||!x)){if(B(null),ae(null),U(null),re(null),J(null),ie(null),u?.locateInEvidence)q(null);else{const P=w.nodes.find(W=>W.id===f)??{id:f,type:"entity",content:f,metadata:{}},X=w.nodes.find(W=>W.id===x)??{id:x,type:"entity",content:x,metadata:{}},vt=w.edges.find(W=>W.source===f&&W.target===x)??{source:f,target:x,weight:1,kind:"relation",label:"",relationHashes:[],predicates:[],relationCount:0,evidenceCount:0};q({source:P,target:X,edge:vt})}try{z(!0);const P=await as(f,x);ge(P),L(He(P.evidence_graph)),u?.locateInEvidence&&M("evidence")}catch(P){a({title:"加载关系详情失败",description:P instanceof Error?P.message:"未知错误",variant:"destructive"})}finally{z(!1)}}},[w.edges,w.nodes,a]),mt=o.useCallback((i,d)=>{le(d.id)},[le]),ht=o.useCallback((i,d)=>{ce(d.source,d.target)},[ce]),xt=o.useCallback(i=>{if(i.type==="entity"){const f=String(i.entity_name??i.title??"").trim();if(!f)return;le(f,{locateInEvidence:!0});return}const d=String(i.subject??"").trim(),u=String(i.object??"").trim();if(!d||!u){a({title:"结果缺少定位信息",description:"该关系记录没有可用的 subject/object,无法定位。",variant:"destructive"});return}ce(d,u,{locateInEvidence:!0})},[ce,le,a]),pt=o.useCallback(async(i,d)=>{const u=_.nodes.find(f=>f.id===d.id);if(u){if(u.type==="entity"){const f=String(u.metadata?.entity_name??"").trim()||u.content;try{z(!0);const x=await Ue(f);B({id:x.node.id,type:"entity",content:x.node.content,metadata:{hash:x.node.hash}}),q(null),ae(x)}catch(x){a({title:"加载实体详情失败",description:x instanceof Error?x.message:"未知错误",variant:"destructive"})}finally{z(!1)}return}if(u.type==="relation"){const f=u.metadata??{},x=String(f.hash??"").trim(),P=$e.find(X=>X.hash===x)??ys(f);re(f),U(P),J(null);return}if(u.type==="paragraph"){const f=u.metadata??{},x=String(f.hash??"").trim(),P=Te.find(X=>X.hash===x)??js(f);ie(f),J(P),U(null)}}},[Te,$e,_.nodes,a]),ft=o.useCallback(()=>{M("evidence"),B(null)},[]),gt=o.useCallback(()=>{M("evidence"),q(null)},[]),yt=o.useCallback(({includeParagraphs:i})=>{const d=String(O?.node.hash??"").trim();if(!d){a({title:"缺少实体标识",description:"当前实体没有可用的 hash,无法执行删除。",variant:"destructive"});return}R({title:"删除实体",description:"将删除该实体,并自动包含与该实体关联的关系。可按需额外删除支撑段落。",request:{mode:"mixed",selector:{entity_hashes:[d],paragraph_hashes:i?(O?.paragraphs??[]).map(u=>u.hash):[]},reason:"knowledge_graph_delete_entity",requested_by:"knowledge_graph"}})},[O,R,a]),jt=o.useCallback(({includeParagraphs:i})=>{const d=I?.edge.relation_hashes??[];if(d.length<=0){a({title:"缺少关系标识",description:"当前关系组没有可用的 relation hash。",variant:"destructive"});return}R({title:"删除关系组",description:"将删除这条聚合边对应的全部关系。可按需额外删除支撑段落。",request:{mode:"mixed",selector:{relation_hashes:d,paragraph_hashes:i?(I?.paragraphs??[]).map(u=>u.hash):[]},reason:"knowledge_graph_delete_edge_group",requested_by:"knowledge_graph"}})},[I,R,a]),Ne=o.useCallback((i,d=!1)=>{R({title:"删除关系",description:d?"将删除这条关系及其支撑段落。":"将只删除这条关系,保留段落证据。",request:{mode:"mixed",selector:{relation_hashes:[i.hash],paragraph_hashes:d?i.paragraph_hashes:[]},reason:"knowledge_graph_delete_relation",requested_by:"knowledge_graph"}})},[R]),we=o.useCallback(i=>{R({title:"删除段落证据",description:"将删除这段证据,并自动删除失去全部证据的关系。",request:{mode:"mixed",selector:{paragraph_hashes:[i.hash]},reason:"knowledge_graph_delete_paragraph",requested_by:"knowledge_graph"}})},[R]),Ie=C==="entity"?w:_,bt=!!(pe||fe||O||I),Re=o.useCallback(()=>{if(s){s();return}n({to:"/resource/knowledge-base"})},[n,s]);return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:t?"flex-none border-b bg-card/60 px-4 py-4 backdrop-blur":"flex-none border-b bg-card/60 px-6 py-4 backdrop-blur",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[!t&&e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"长期记忆图谱"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"基于 A_Memorix 的实体关系图与证据视图"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(g,{variant:"outline",className:"gap-1",children:[e.jsx(Ot,{className:"h-3.5 w-3.5"}),"总节点 ",V.totalNodes]}),e.jsxs(g,{variant:"outline",className:"gap-1",children:[e.jsx(It,{className:"h-3.5 w-3.5"}),"总关系 ",V.totalEdges]}),e.jsx(g,{variant:"secondary",children:C==="entity"?`当前显示 ${V.visibleNodes} / ${V.visibleEdges}`:`证据视图 ${V.evidenceNodes} / ${V.evidenceEdges}`})]})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex flex-1 gap-2",children:[e.jsx(We,{value:y,onChange:i=>h(i.target.value),onKeyDown:i=>i.key==="Enter"&&void Oe(),placeholder:"搜索实体、关系、hash(后端全库)"}),e.jsxs(b,{onClick:()=>{Oe()},variant:"secondary",disabled:S,children:[e.jsx(Ke,{className:"mr-2 h-4 w-4"}),S?"检索中":"搜索"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(Bt,{value:m,onValueChange:p,children:[e.jsx(qt,{className:"w-[140px]",children:e.jsx(At,{placeholder:"节点上限"})}),e.jsxs(Ft,{children:[e.jsx(de,{value:"80",children:"80 节点"}),e.jsx(de,{value:"120",children:"120 节点"}),e.jsx(de,{value:"240",children:"240 节点"}),e.jsx(de,{value:"480",children:"480 节点"})]})]}),e.jsxs(b,{onClick:()=>{A()},disabled:l,children:[e.jsx(Rt,{className:`mr-2 h-4 w-4 ${l?"animate-spin":""}`}),"刷新图谱"]}),e.jsxs(b,{variant:"outline",onClick:Re,className:t?"hidden":void 0,children:[e.jsx(Lt,{className:"mr-2 h-4 w-4"}),"打开控制台"]})]})]}),e.jsx(Pt,{value:C,onValueChange:i=>M(i),children:e.jsxs($t,{className:"h-auto flex-wrap justify-start",children:[e.jsx(qe,{value:"entity",children:"实体关系图"}),e.jsx(qe,{value:"evidence",children:"证据视图"})]})}),k?e.jsxs("div",{className:"rounded-lg border bg-background/80 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:["搜索词:",k]}),e.jsx(g,{variant:T?"destructive":"secondary",children:T?"仅当前已加载范围":`全库命中 ${E.length} 条`})]}),T?e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"后端检索不可用,当前结果来自已加载图谱范围。请先刷新图谱或稍后重试。"}):E.length<=0?e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"未命中实体或关系。"}):e.jsx("div",{className:"mt-3 max-h-56 space-y-2 overflow-auto pr-1",children:E.map((i,d)=>e.jsxs("button",{type:"button",className:"w-full rounded-md border bg-card px-3 py-2 text-left transition hover:bg-accent/40",onClick:()=>xt(i),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"outline",children:i.type==="entity"?"实体":"关系"}),e.jsx("span",{className:"truncate text-sm font-medium",children:i.title||"(无标题结果)"})]}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["命中字段:",i.matched_field," = ",i.matched_value,i.type==="entity"?` · appearance=${i.appearance_count??0}`:` · confidence=${Number(i.confidence??0).toFixed(2)}`]})]},`${i.type}-${i.entity_hash??i.relation_hash??`${i.title}-${d}`}`))})]}):null]})]}),e.jsx("div",{className:"min-h-0 flex-1 bg-muted/20",children:C==="entity"&&w.nodes.length>0?e.jsx(ze,{graphData:w,loading:l,onNodeClick:mt,onEdgeClick:ht}):C==="evidence"&&Ie.nodes.length>0?e.jsx(ze,{graphData:Ie,loading:ye,onNodeClick:pt,onEdgeClick:()=>{}}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"max-w-xl rounded-xl border bg-background p-8 text-center shadow-sm",children:C==="entity"?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"还没有可展示的长期记忆图谱"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"先在长期记忆控制台里完成导入或记忆生成,再回来查看关系网络。"}),e.jsx(b,{className:"mt-4",onClick:Re,children:"前往长期记忆控制台"})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"证据视图还没有可展示的选择"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"先在实体关系图里点击某个实体或边,再切换到证据视图查看 paragraph → relation/entity 的牵引。"}),e.jsxs("div",{className:"mt-4 flex justify-center gap-2",children:[e.jsx(b,{variant:"outline",onClick:()=>M("entity"),children:"返回实体关系图"}),bt&&e.jsx(b,{onClick:()=>M("evidence"),children:"刷新证据视图"})]})]})})})}),e.jsx(ls,{open:!!pe,onOpenChange:i=>!i&&B(null),selectedNodeData:pe,nodeDetail:O,loading:ye,onOpenEvidence:ft,onDeleteEntity:yt,onDeleteRelation:i=>Ne(i),onDeleteParagraph:we}),e.jsx(cs,{open:!!fe,onOpenChange:i=>!i&&q(null),selectedEdgeData:fe,edgeDetail:I,loading:ye,onOpenEvidence:gt,onDeleteEdgeGroup:jt,onDeleteRelation:i=>Ne(i),onDeleteParagraph:we}),e.jsx(ds,{open:!!ke,onOpenChange:i=>!i&&U(null),relation:ke,metadata:nt,onDeleteRelation:(i,d)=>Ne(i,d)}),e.jsx(us,{open:!!_e,onOpenChange:i=>!i&&J(null),paragraph:_e,metadata:at,onDeleteParagraph:we}),e.jsx(Zt,{open:!!H,onOpenChange:ve,title:H?.title??"删除预览",description:H?.description,preview:ct,result:Z,loadingPreview:rt,executing:ot,restoring:lt,error:it,onExecute:dt,onRestore:ut})]})}const gn=Object.freeze(Object.defineProperty({__proto__:null,KnowledgeGraphPage:bs},Symbol.toStringTag,{value:"Module"}));export{nn as A,an as B,rn as C,on as D,ln as E,cn as F,dn as G,un as H,mn as I,Ys as J,Es as K,rs as L,is as M,os as N,$s as O,Ts as P,Qs as Q,pn as R,fn as S,bs as T,Zt as U,gn as V,Os as a,Is as b,Js as c,Hs as d,Ws as e,Vs as f,Ls as g,zs as h,qs as i,Gs as j,Us as k,Ks as l,Zs as m,Xs as n,en as o,Bs as p,Fs as q,Rs as r,As as s,hn as t,xn as u,Ds as v,Ms as w,Ps as x,sn as y,tn as z};
|