memory-eternal 0.10.41 → 0.10.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -198,6 +198,14 @@ Option A, because:
198
198
  .me-dialog { background: var(--dsw-alias-bg-layer-1, #1e232c); color: var(--dsw-alias-label-primary, #e5e7eb); border-radius: 14px; max-width: 760px; width: 100%; max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,0.5); border: 1px solid var(--dsw-alias-border-l1, #2c333c); }
199
199
  .me-dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--dsw-alias-border-l1, #e5e7eb); }
200
200
  .me-dialog-head h3 { margin: 0; font-size: 15px; }
201
+ /* \u6807\u9898\u8FC7\u957F\u65F6\u4E0D\u8BB8\u6324\u538B\u6309\u94AE\uFF08\u7528\u6237\u53CD\u9988\uFF0C\u89C1\u56FE 1/\u56FE 2\uFF09\uFF1A
202
+ \u2460 h3 \u5FC5\u987B\u80FD\u6536\u7F29\uFF08min-width:0\uFF09\u5E76\u5355\u884C\u7701\u7565\uFF0C\u5426\u5219\u957F\u6807\u9898\u4F1A\u628A\u6309\u94AE\u9876\u51FA\u53EF\u89C6\u533A\uFF1B
203
+ \u2461 \u6309\u94AE\u7EC4 flex:0 0 auto + nowrap \u2014\u2014 \u5426\u5219\u4F1A\u88AB\u538B\u6210\u7AD6\u6392\uFF08\u300C\u6536/\u8D77\u300D\u300C\u5173/\u95ED\u300D\uFF09\uFF1B
204
+ \u2462 \u5934\u90E8\u5141\u8BB8\u6362\u884C\uFF1A\u6781\u7A84\u65F6\u6309\u94AE\u6574\u4F53\u6389\u5230\u7B2C\u4E8C\u884C\uFF0C\u4ECD\u7136\u4E00\u4E2A\u4E2A\u53EF\u70B9\uFF0C\u800C\u4E0D\u662F\u88AB\u538B\u6241\u3002 */
205
+ .me-dialog-head { flex-wrap: wrap; gap: 8px 12px; }
206
+ .me-dialog-head h3 { min-width: 0; flex: 1 1 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
207
+ .me-dialog-head .me-head-actions { display: flex; flex-wrap: nowrap; gap: 8px; flex: 0 0 auto; margin-left: auto; align-items: center; }
208
+ .me-dialog-head .me-head-actions .mc-btn { flex: 0 0 auto; white-space: nowrap; }
201
209
  .me-dialog-body { padding: 14px 18px; overflow: auto; font-size: 13.5px; line-height: 1.78; white-space: normal; word-break: break-word; position: relative; }
202
210
  .me-dialog-body h3 { font-size: 15px; margin: 10px 0 6px; color: var(--dsw-alias-label-primary, #111); }
203
211
  .me-dialog-body h4 { font-size: 13px; margin: 8px 0 4px; color: var(--dsw-alias-label-primary, #111); }
@@ -329,13 +337,13 @@ Option A, because:
329
337
  height: calc(100vh - var(--dsh-frame-overlay-top, 68px));
330
338
  max-height: calc(100vh - var(--dsh-frame-overlay-top, 68px));
331
339
  }
332
- `;function Ma(t){t.effect(()=>t.locale.register(dt,{zh:Qt,en:ea}),"memory-eternal: locale");let i=t.locale.bind(dt);t.effect(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:dt,order:25,label:()=>i("nav"),locale:dt,inject:()=>({})},()=>o.default.createElement(Ra,{t:i}))),"memory-eternal: settings section"),t.effect(()=>t.slots.inject("sidebar.footer.action",()=>t.slots.register({name:"sidebar.footer.action",id:`${dt}:footer`,order:100,label:()=>i("nav"),locale:dt,inject:()=>({})},r=>o.default.createElement(Da,{t:i,locale:t.locale,wide:!(r&&r.wide===!1)}))),"memory-eternal: sidebar footer action")}function Ta(){let[t,i]=(0,o.useState)(E+"/ui/app");return(0,o.useEffect)(()=>{let r=!0,g=()=>fetch("/memory-eternal/api/web-info").then(c=>c.json()).then(c=>{r&&c&&c.ok&&c.alive!==!1&&c.url&&i(c.url.endsWith("/")?c.url:c.url+"/")}).catch(()=>{});return fetch(E+"/ui/app",{method:"HEAD"}).then(c=>{if(r&&!c.ok)return g()}).catch(()=>r?g():void 0),()=>{r=!1}},[]),t}function Ra({t}){return(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsx)(oa,{t,onReload:()=>{},version:0})]})}function Da({t,locale:i,wide:r}){let[g,c]=(0,o.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${r?"":" rail"}`,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>c(!0),"aria-label":t("nav"),title:t("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(aa,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:t("nav")})]}),g&&(0,e.jsx)(za,{t,locale:i,onClose:()=>c(!1)})]})}function za({t,locale:i,onClose:r,tab:g}){let[c,l]=(0,o.useState)(!1),C=(0,o.useRef)(null),R=Ta(),S=(0,o.useCallback)(T=>i&&typeof i.subscribe=="function"?i.subscribe(T):()=>{},[i]),O=(0,o.useCallback)(()=>i&&typeof i.getSnapshot=="function"?i.getSnapshot():null,[i]),k=(0,o.useSyncExternalStore)(S,O),x=k&&(k.active==="zh"||k.active==="en")?k.active:null,m=(0,o.useRef)(null);m.current===null&&x&&(m.current=x);let z=(0,o.useMemo)(()=>{let T=m.current?`lang=${m.current}`:"";if(g==="config")return`${E}/ui/config?tab=config${T?`&${T}`:""}`;let w=R.replace(/\/$/,""),j=w.endsWith("/ui/app")?"?":"/?";return g?`${w}${j}tab=${g}${T?`&${T}`:""}`:T?`${w}${j}${T}`:R},[R,g]);return(0,o.useEffect)(()=>{let T=C.current&&C.current.contentWindow;T&&x&&T.postMessage({source:"memory-eternal",type:"locale",lang:x},"*")},[x]),(0,o.useEffect)(()=>{let T=w=>{w.key==="Escape"&&r()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[r]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:r,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsx)("div",{className:"me-modal"+(c?" me-modal-full":""),onClick:T=>T.stopPropagation(),children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[(0,e.jsxs)("div",{style:{position:"absolute",top:8,right:8,zIndex:10,display:"flex",gap:4,padding:"4px 6px",background:"var(--dsw-alias-bg-overlay, rgba(17,24,39,0.45))",borderRadius:8,backdropFilter:"blur(4px)"},children:[(0,e.jsx)("button",{type:"button",onClick:()=>l(T=>!T),"aria-label":t(c?"exitFullscreen":"enterFullscreen"),title:t(c?"exitFullscreen":"enterFullscreen"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:c?"\u2921":"\u2922"}),(0,e.jsx)("button",{type:"button",onClick:r,"aria-label":t("close"),title:t("close"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),(0,e.jsx)("iframe",{ref:C,src:z,title:"memory-eternal",allow:"clipboard-write; clipboard-read",style:{width:"100%",flex:1,border:0,borderRadius:"inherit",background:"var(--dsw-alias-bg-base, #fff)"}})]})})]})}function aa(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}var bt="0.10.41";function Ia({t,inModal:i,onClose:r,onFull:g,full:c}){let[l,C]=(0,o.useState)(null),[R,S]=(0,o.useState)([]),[O,k]=(0,o.useState)(!0),[x,m]=(0,o.useState)(null),[z,T]=(0,o.useState)(""),[w,j]=(0,o.useState)("all"),[L,K]=(0,o.useState)(""),[te,V]=(0,o.useState)("all"),[F,Ie]=(0,o.useState)("all"),[G,ge]=(0,o.useState)(()=>{try{let b=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),n={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(b&&n[b])return n[b]}catch{}return"cards"}),[X,$]=(0,o.useState)(()=>new Set([G])),le=(0,o.useCallback)(b=>{$(n=>n.has(b)?n:new Set(n).add(b)),ge(b)},[]),[he,Ae]=(0,o.useState)("recent"),[xe,y]=(0,o.useState)(null),ue=(0,o.useRef)(null),Re=(0,o.useRef)(null),[h,U]=(0,o.useState)(!1),[re,ye]=(0,o.useState)(null),[ee,J]=(0,o.useState)(!1),[Be,Ce]=(0,o.useState)(!1),[Te,Ne]=(0,o.useState)(!0),[s,N]=(0,o.useState)(null),[I,Z]=(0,o.useState)(0),ke=(0,o.useCallback)(()=>Z(b=>b+1),[]),de=l?.quarantine?.pending??0,ae=l?.quarantine?.deleted??0,Y=(0,o.useRef)(null),[We,je]=(0,o.useState)(0),[p,d]=(0,o.useState)(!1),_=(0,o.useRef)(null),se=(0,o.useRef)(null),ce=(0,o.useCallback)(async(b=w,n=L,v=F,D={})=>{let P=D.append===!0;try{P?d(!0):(k(!0),T(""));let W=new URLSearchParams;b&&b!=="all"&&W.set("kind",b),n.trim()&&W.set("q",n.trim()),W.set("status",v||"all"),W.set("limit",String(wa)),W.set("offset",String(D.offset||0)),he==="title"&&W.set("sort","title");let Q=await(await fetch(`${E}/cards?${W.toString()}`)).json();if(Q.ok){let Se=Q.cards||[];S(De=>P?[...De,...Se.filter(Le=>!De.some(lt=>lt.path===Le.path))]:Se),je(Number(Q.total)||Se.length)}}catch(W){T(String(W&&W.message?W.message:W))}finally{P?d(!1):k(!1)}},[w,L,F,he]),fe=(0,o.useCallback)(async()=>{try{let[b,n]=await Promise.all([fetch(`${E}/overview`).then(v=>v.json()),fetch(`${E}/capture-log`).then(v=>v.json()).catch(()=>null)]);b.ok&&C(b),m(n&&n.ok&&n.available&&n.health||null)}catch(b){T(String(b&&b.message?b.message:b))}finally{k(!1)}},[]),a=async b=>{try{let v=await(await fetch(`${E}/delete?path=${encodeURIComponent(b)}`)).json();v.ok?(y({ok:!0,msg:t("deleted")}),await fe(),ke()):y({ok:!1,msg:v.error||t("deleteFail")})}catch{y({ok:!1,msg:t("deleteFail")})}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2e3)};(0,o.useEffect)(()=>(fe(),()=>{Y.current&&clearTimeout(Y.current)}),[fe]);let Pe=b=>{K(b),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>ce(w,b,F),280)},Je=b=>{j(b),ce(b,L,F)};(0,o.useEffect)(()=>{G==="cards"&&ce(w,L,F)},[F,G,I,he]),(0,o.useEffect)(()=>{if(G!=="cards"||O||p||R.length>=We)return;let b=_.current,n=se.current;if(!b)return;let v=new IntersectionObserver(D=>{D[0]&&D[0].isIntersecting&&ce(w,L,F,{append:!0,offset:R.length})},{root:n||null,rootMargin:"400px"});return v.observe(b),()=>v.disconnect()},[G,R,We,O,p,w,L,F,ce]);let tt=async b=>{try{let n=b.status;if(!n&&b.path)try{let B=((await fetch(`${E}/cards?status=all&q=${encodeURIComponent(b.title||"")}&limit=50`).then(Q=>Q.json())).cards||[]).find(Q=>Q.path===b.path);B&&(n=B.status)}catch{}let v=n&&n!=="approved"?`&status=${encodeURIComponent(n)}`:"",D=await fetch(`${E}/card?path=${encodeURIComponent(b.path||b.id)}${v}`),P=await D.json();P.ok?ye({path:P.path,title:b.title,text:P.text}):T(P.error||`HTTP ${D.status}`)}catch(n){T(String(n&&n.message?n.message:n))}},nt=async(b,n)=>{U(!0);try{let v=await fetch(`${E}/export`);if(!v.ok)throw new Error("HTTP "+v.status);let D=await v.json();if(!D.ok)throw new Error(D.error||"export failed");let P,W,B;if(b==="json"){W="memory-vault.json",B="application/json";let De=D.cards.map(Le=>({path:Le.path,title:Le.title,kind:Le.kind,status:Le.status,store:Le.store,text:Le.text}));P=JSON.stringify({format:D.format||"memory-eternal-vault",formatVersion:D.formatVersion||1,exportedAt:D.exportedAt||new Date().toISOString(),count:De.length,cards:De},null,2)}else W="memory-vault.md",B="text/markdown;charset=utf-8",P=D.cards.map(De=>De.text.trim()).filter(Boolean).join(`
340
+ `;function Ma(t){t.effect(()=>t.locale.register(dt,{zh:Qt,en:ea}),"memory-eternal: locale");let i=t.locale.bind(dt);t.effect(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:dt,order:25,label:()=>i("nav"),locale:dt,inject:()=>({})},()=>o.default.createElement(Ra,{t:i}))),"memory-eternal: settings section"),t.effect(()=>t.slots.inject("sidebar.footer.action",()=>t.slots.register({name:"sidebar.footer.action",id:`${dt}:footer`,order:100,label:()=>i("nav"),locale:dt,inject:()=>({})},r=>o.default.createElement(Da,{t:i,locale:t.locale,wide:!(r&&r.wide===!1)}))),"memory-eternal: sidebar footer action")}function Ta(){let[t,i]=(0,o.useState)(E+"/ui/app");return(0,o.useEffect)(()=>{let r=!0,g=()=>fetch("/memory-eternal/api/web-info").then(c=>c.json()).then(c=>{r&&c&&c.ok&&c.alive!==!1&&c.url&&i(c.url.endsWith("/")?c.url:c.url+"/")}).catch(()=>{});return fetch(E+"/ui/app",{method:"HEAD"}).then(c=>{if(r&&!c.ok)return g()}).catch(()=>r?g():void 0),()=>{r=!1}},[]),t}function Ra({t}){return(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsx)(oa,{t,onReload:()=>{},version:0})]})}function Da({t,locale:i,wide:r}){let[g,c]=(0,o.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${r?"":" rail"}`,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>c(!0),"aria-label":t("nav"),title:t("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(aa,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:t("nav")})]}),g&&(0,e.jsx)(za,{t,locale:i,onClose:()=>c(!1)})]})}function za({t,locale:i,onClose:r,tab:g}){let[c,l]=(0,o.useState)(!1),C=(0,o.useRef)(null),R=Ta(),S=(0,o.useCallback)(T=>i&&typeof i.subscribe=="function"?i.subscribe(T):()=>{},[i]),O=(0,o.useCallback)(()=>i&&typeof i.getSnapshot=="function"?i.getSnapshot():null,[i]),k=(0,o.useSyncExternalStore)(S,O),x=k&&(k.active==="zh"||k.active==="en")?k.active:null,m=(0,o.useRef)(null);m.current===null&&x&&(m.current=x);let z=(0,o.useMemo)(()=>{let T=m.current?`lang=${m.current}`:"";if(g==="config")return`${E}/ui/config?tab=config${T?`&${T}`:""}`;let w=R.replace(/\/$/,""),j=w.endsWith("/ui/app")?"?":"/?";return g?`${w}${j}tab=${g}${T?`&${T}`:""}`:T?`${w}${j}${T}`:R},[R,g]);return(0,o.useEffect)(()=>{let T=C.current&&C.current.contentWindow;T&&x&&T.postMessage({source:"memory-eternal",type:"locale",lang:x},"*")},[x]),(0,o.useEffect)(()=>{let T=w=>{w.key==="Escape"&&r()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[r]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:r,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsx)("div",{className:"me-modal"+(c?" me-modal-full":""),onClick:T=>T.stopPropagation(),children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[(0,e.jsxs)("div",{style:{position:"absolute",top:8,right:8,zIndex:10,display:"flex",gap:4,padding:"4px 6px",background:"var(--dsw-alias-bg-overlay, rgba(17,24,39,0.45))",borderRadius:8,backdropFilter:"blur(4px)"},children:[(0,e.jsx)("button",{type:"button",onClick:()=>l(T=>!T),"aria-label":t(c?"exitFullscreen":"enterFullscreen"),title:t(c?"exitFullscreen":"enterFullscreen"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:c?"\u2921":"\u2922"}),(0,e.jsx)("button",{type:"button",onClick:r,"aria-label":t("close"),title:t("close"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),(0,e.jsx)("iframe",{ref:C,src:z,title:"memory-eternal",allow:"clipboard-write; clipboard-read",style:{width:"100%",flex:1,border:0,borderRadius:"inherit",background:"var(--dsw-alias-bg-base, #fff)"}})]})})]})}function aa(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}var bt="0.10.42";function Ia({t,inModal:i,onClose:r,onFull:g,full:c}){let[l,C]=(0,o.useState)(null),[R,S]=(0,o.useState)([]),[O,k]=(0,o.useState)(!0),[x,m]=(0,o.useState)(null),[z,T]=(0,o.useState)(""),[w,j]=(0,o.useState)("all"),[L,K]=(0,o.useState)(""),[te,V]=(0,o.useState)("all"),[F,Ie]=(0,o.useState)("all"),[G,ge]=(0,o.useState)(()=>{try{let b=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),n={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(b&&n[b])return n[b]}catch{}return"cards"}),[X,$]=(0,o.useState)(()=>new Set([G])),le=(0,o.useCallback)(b=>{$(n=>n.has(b)?n:new Set(n).add(b)),ge(b)},[]),[he,Ae]=(0,o.useState)("recent"),[xe,y]=(0,o.useState)(null),ue=(0,o.useRef)(null),Re=(0,o.useRef)(null),[h,U]=(0,o.useState)(!1),[re,ye]=(0,o.useState)(null),[ee,J]=(0,o.useState)(!1),[Be,Ce]=(0,o.useState)(!1),[Te,Ne]=(0,o.useState)(!0),[s,N]=(0,o.useState)(null),[I,Z]=(0,o.useState)(0),ke=(0,o.useCallback)(()=>Z(b=>b+1),[]),de=l?.quarantine?.pending??0,ae=l?.quarantine?.deleted??0,Y=(0,o.useRef)(null),[We,je]=(0,o.useState)(0),[p,d]=(0,o.useState)(!1),_=(0,o.useRef)(null),se=(0,o.useRef)(null),ce=(0,o.useCallback)(async(b=w,n=L,v=F,D={})=>{let P=D.append===!0;try{P?d(!0):(k(!0),T(""));let W=new URLSearchParams;b&&b!=="all"&&W.set("kind",b),n.trim()&&W.set("q",n.trim()),W.set("status",v||"all"),W.set("limit",String(wa)),W.set("offset",String(D.offset||0)),he==="title"&&W.set("sort","title");let Q=await(await fetch(`${E}/cards?${W.toString()}`)).json();if(Q.ok){let Se=Q.cards||[];S(De=>P?[...De,...Se.filter(Le=>!De.some(lt=>lt.path===Le.path))]:Se),je(Number(Q.total)||Se.length)}}catch(W){T(String(W&&W.message?W.message:W))}finally{P?d(!1):k(!1)}},[w,L,F,he]),fe=(0,o.useCallback)(async()=>{try{let[b,n]=await Promise.all([fetch(`${E}/overview`).then(v=>v.json()),fetch(`${E}/capture-log`).then(v=>v.json()).catch(()=>null)]);b.ok&&C(b),m(n&&n.ok&&n.available&&n.health||null)}catch(b){T(String(b&&b.message?b.message:b))}finally{k(!1)}},[]),a=async b=>{try{let v=await(await fetch(`${E}/delete?path=${encodeURIComponent(b)}`)).json();v.ok?(y({ok:!0,msg:t("deleted")}),await fe(),ke()):y({ok:!1,msg:v.error||t("deleteFail")})}catch{y({ok:!1,msg:t("deleteFail")})}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2e3)};(0,o.useEffect)(()=>(fe(),()=>{Y.current&&clearTimeout(Y.current)}),[fe]);let Pe=b=>{K(b),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>ce(w,b,F),280)},Je=b=>{j(b),ce(b,L,F)};(0,o.useEffect)(()=>{G==="cards"&&ce(w,L,F)},[F,G,I,he]),(0,o.useEffect)(()=>{if(G!=="cards"||O||p||R.length>=We)return;let b=_.current,n=se.current;if(!b)return;let v=new IntersectionObserver(D=>{D[0]&&D[0].isIntersecting&&ce(w,L,F,{append:!0,offset:R.length})},{root:n||null,rootMargin:"400px"});return v.observe(b),()=>v.disconnect()},[G,R,We,O,p,w,L,F,ce]);let tt=async b=>{try{let n=b.status;if(!n&&b.path)try{let B=((await fetch(`${E}/cards?status=all&q=${encodeURIComponent(b.title||"")}&limit=50`).then(Q=>Q.json())).cards||[]).find(Q=>Q.path===b.path);B&&(n=B.status)}catch{}let v=n&&n!=="approved"?`&status=${encodeURIComponent(n)}`:"",D=await fetch(`${E}/card?path=${encodeURIComponent(b.path||b.id)}${v}`),P=await D.json();P.ok?ye({path:P.path,title:b.title,text:P.text}):T(P.error||`HTTP ${D.status}`)}catch(n){T(String(n&&n.message?n.message:n))}},nt=async(b,n)=>{U(!0);try{let v=await fetch(`${E}/export`);if(!v.ok)throw new Error("HTTP "+v.status);let D=await v.json();if(!D.ok)throw new Error(D.error||"export failed");let P,W,B;if(b==="json"){W="memory-vault.json",B="application/json";let De=D.cards.map(Le=>({path:Le.path,title:Le.title,kind:Le.kind,status:Le.status,store:Le.store,text:Le.text}));P=JSON.stringify({format:D.format||"memory-eternal-vault",formatVersion:D.formatVersion||1,exportedAt:D.exportedAt||new Date().toISOString(),count:De.length,cards:De},null,2)}else W="memory-vault.md",B="text/markdown;charset=utf-8",P=D.cards.map(De=>De.text.trim()).filter(Boolean).join(`
333
341
 
334
342
  ---
335
343
 
336
344
  `);let Q=new Blob([P],{type:B}),Se=await Ua(Q,W,!1);if(!Se.ok){y({ok:!1,msg:t("exportFail")}),U(!1);return}y({ok:!0,msg:t("exportedTo")+"\uFF1A"+t("defaultDownloads")+" \xB7 "+Se.name})}catch(v){y({ok:!1,msg:t("exportFail")+" \xB7 "+(v.message||"")})}finally{U(!1)}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2600)},ot=async b=>{let n=b.target.files&&b.target.files[0];if(b.target.value="",!!n){try{let v=await n.text(),P=await(await fetch(`${E}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:v})).json();if(P.ok){await fe();let W=P.imported||0,B=t("importedVault")+"\uFF1A"+W;P.total&&(B+=t("importedTotal")+P.total+t("importedTotalTail")),P.quarantined&&(B+=t("importedQuarantine")+P.quarantined+t("importedQuarantineTail")),P.skipped&&(B+=t("importedSkipped")+P.skipped+t("importedSkippedTail")),P.warning&&(B+=" \xB7 "+P.warning),y({ok:W>0||!P.total,msg:B})}else y({ok:!1,msg:P.error||t("importFail")})}catch{y({ok:!1,msg:t("importFail")})}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2400)}},we=(0,o.useMemo)(()=>{let b=R.slice();return te!=="all"&&(b=b.filter(n=>mt(n.submittedBy)===te)),F!=="all"&&(b=b.filter(n=>(n.status||"approved")===F)),he==="title"?b.sort((n,v)=>String(n.title||"").localeCompare(String(v.title||""))):he==="hot"?b.sort((n,v)=>(v.weight||v.links||0)-(n.weight||n.links||0)):b.sort((n,v)=>new Date(v.updated||0).getTime()-new Date(n.updated||0).getTime()),b},[R,he,te,F]),Ze=(0,o.useMemo)(()=>[...new Set(R.map(b=>mt(b.submittedBy)))],[R]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:Ee}),xe&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(xe.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:xe.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:xe.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:xe.msg})]}),i&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(aa,{})}),(0,e.jsx)("h2",{children:t("memoryTitle")}),(0,e.jsx)("span",{children:t("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),g&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:g,"aria-label":t(c?"exitFull":"fullscreen"),children:c?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:r,"aria-label":t("close"),children:"\u2715"})]}),x&&x.ok===!1&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,margin:"0 0 8px",padding:"9px 14px",borderRadius:10,background:"rgba(239,68,68,0.10)",border:"1px solid rgba(239,68,68,0.45)",borderLeft:"4px solid #ef4444",color:"var(--dsw-alias-label-primary, #e5e7eb)",fontSize:12.5,lineHeight:1.6},children:[(0,e.jsxs)("span",{style:{fontWeight:800},children:["\u26A0 ",t("captureAlert")]}),(0,e.jsxs)("span",{style:{flex:1},children:[x.reason,(0,e.jsx)("div",{style:{opacity:.68,fontSize:11.5,marginTop:2},children:t("captureAlertHint")})]}),(0,e.jsx)("span",{style:{opacity:.7},children:x.since?ut(new Date(x.since).toISOString()):""})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:`mc-rail${Te?" open":""}`,children:[(0,e.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>Ne(b=>!b),"aria-label":t(Te?"collapse":"expand"),title:t(Te?"collapse":"expand"),children:Te?"\xAB":"\xBB"}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="cards"?" active":""}`,onClick:()=>le("cards"),title:t("cardsTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F9E0}"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("cardsTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="graph"?" active":""}`,onClick:()=>le("graph"),title:t("graphTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F52E}"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("graphTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="stats"?" active":""}`,onClick:()=>le("stats"),title:t("tabUsage"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C8}"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabUsage")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="audit"?" active":""}`,onClick:()=>le("audit"),title:t("tabAudit"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F50D}"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabAudit")}),de>0&&(0,e.jsx)("span",{className:"mc-dot",children:de>99?"99+":de})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="optimize"?" active":""}`,onClick:()=>le("optimize"),title:t("tabRecycle"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u267B\uFE0F"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabRecycle")}),ae>0&&(0,e.jsx)("span",{className:"mc-dot",style:{background:"#6b7280"},children:ae>99?"99+":ae})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${G==="config"?" active":""}`,onClick:()=>le("config"),title:t("tabConfig"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabConfig")})]}),(0,e.jsxs)("button",{type:"button",className:"mc-railbtn",onClick:()=>Ce(!0),title:t("fbNav"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F41E}"}),Te&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("fbNav")})]})]}),(0,e.jsxs)("div",{className:"mc-main",ref:se,children:[l&&l.db&&l.db.writable===!1?(0,e.jsxs)("div",{style:{margin:"8px 10px 0",padding:"8px 12px",borderRadius:8,fontSize:12,lineHeight:1.7,background:"rgba(239,68,68,0.10)",border:"1px solid rgba(239,68,68,0.35)",color:"#b91c1c"},children:["\u26A0\uFE0F ",t("dbReadonlyTitle"),"\uFF1A",l.db.error||"\u2014"," \u2014\u2014 ",t("dbReadonlyBody"),(0,e.jsx)("div",{style:{opacity:.85,marginTop:2},children:t("dbReadonlyFix")})]}):null,G==="cards"&&(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(ct,{label:t("total"),value:l?l.total:"\u2014"}),(0,e.jsx)(ct,{label:t("recent"),value:l?l.recent:"\u2014"}),(0,e.jsx)(ct,{label:t("tags"),value:l?l.tags:"\u2014"}),(0,e.jsx)(ct,{label:t("pending"),value:l?.quarantine?.pending??l?.status?.pending??0}),(0,e.jsx)(ct,{label:t("rejected"),value:l?.quarantine?.rejected??l?.status?.rejected??0}),(0,e.jsx)(ct,{label:t("cardCount"),value:l?l.byKind?.knowledge??0:"\u2014"})]}),G==="cards"&&(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:t("searchPlaceholder"),value:L,onChange:b=>Pe(b.target.value)}),(0,e.jsx)("input",{ref:Re,type:"file",accept:".json,application/json",style:{display:"none"},onChange:ot}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>Re.current&&Re.current.click(),children:t("importVault")}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",onClick:()=>N({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",t("newCard")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:h,onClick:()=>nt("md"),children:t(h?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:h,onClick:()=>nt("json"),children:t(h?"exporting":"exportJson")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>fe(),children:t("refresh")})]}),G==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[At.map(b=>(0,e.jsx)("button",{type:"button",className:`mc-chip${w===b?" active":""}`,onClick:()=>Je(b),children:t(b==="all"?"all":Ke[b])},b)),(0,e.jsxs)("select",{value:te,onChange:b=>V(b.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsxs)("option",{value:"all",children:["\u{1F916} ",t("allAgents")]}),ta(Ze).map(b=>(0,e.jsx)("option",{value:b,children:b},b))]}),(0,e.jsxs)("select",{value:F,onChange:b=>Ie(b.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("allStatus")}),(0,e.jsx)("option",{value:"approved",children:t("statusApproved")}),(0,e.jsx)("option",{value:"pending",children:t("statusPending")}),(0,e.jsx)("option",{value:"rejected",children:t("statusRejected")})]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:t("sortRecent")},{key:"title",label:t("sortTitle")},{key:"hot",label:t("sortHot")}].map(b=>(0,e.jsx)("button",{type:"button",className:`mc-chip${he===b.key?" active":""}`,onClick:()=>Ae(b.key),children:b.label},b.key))]}),z&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",z]}),(0,e.jsx)("div",{style:{display:G==="cards"?"contents":"none"},children:O?(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}):z?(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",z," ",(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>fe(),children:t("retry")})]}):R.length===0?(0,e.jsx)("div",{className:"mc-empty",children:t("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:we.map(b=>(0,e.jsx)(La,{card:b,t,query:L.trim(),onOpen:tt,onDelete:a},b.path))}),R.length<We&&(0,e.jsx)("div",{ref:_,style:{height:1}}),p&&(0,e.jsxs)("div",{className:"mc-empty",style:{padding:"10px 0"},children:[t("loading"),"\uFF08",R.length," / ",We,"\uFF09"]})]})}),(0,e.jsx)("div",{style:{display:G==="graph"?"flex":"none",flex:1,minHeight:0},children:X.has("graph")&&(0,e.jsx)(Oa,{t,onOpen:tt,all:ee,onAllChange:J,onMutate:ke,active:G==="graph",visible:G==="graph"})}),(0,e.jsx)("div",{style:{display:G==="config"?"contents":"none"},children:X.has("config")&&(0,e.jsx)(oa,{t,onReload:()=>fe(),version:I})}),(0,e.jsx)("div",{style:{display:G==="stats"?"contents":"none"},children:X.has("stats")&&(0,e.jsx)(ja,{t,tab:"stats",onReload:()=>fe(),version:I})}),(0,e.jsx)("div",{style:{display:G==="audit"?"contents":"none"},children:X.has("audit")&&(0,e.jsx)(Aa,{t,onReload:()=>fe(),version:I})}),(0,e.jsx)("div",{style:{display:G==="optimize"?"contents":"none"},children:X.has("optimize")&&(0,e.jsx)(Ba,{t,onReload:()=>fe(),version:I})}),Be&&(0,e.jsx)(Pa,{t,onClose:()=>Ce(!1)}),re&&(0,e.jsx)(Ha,{t,card:re,query:L.trim(),onClose:()=>ye(null),onDelete:b=>{ye(null),a(b)},onFeedback:b=>{let n=re.path;fetch(`${E}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:L.trim(),path:n,useful:b})}).then(()=>y({ok:!0,msg:t(b?"fbUseful":"fbIrr")})).catch(()=>{}),ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2e3)}}),(0,e.jsx)(Fa,{t,newCard:s,setNewCard:N,onCreated:()=>{fe(),ke(),y({ok:!0,msg:t("created")}),ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>y(null),2e3)}})]})]})]})}var na=({toast:t})=>t?(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"8px 12px",fontSize:12,borderLeft:"4px solid "+(t.ok?"#10b981":"#ef4444"),background:t.ok?"rgba(16,185,129,0.08)":"rgba(239,68,68,0.08)"},children:[t.ok?"\u2705":"\u26A0"," ",t.msg]}):null,ct=({label:t,value:i})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:i}),(0,e.jsx)("span",{children:t})]});function oa({t,onReload:i,version:r,compact:g}){let[c,l]=(0,o.useState)(null),[C,R]=(0,o.useState)(0),[S,O]=(0,o.useState)(null),[k,x]=(0,o.useState)(null),[m,z]=(0,o.useState)(!1),[T,w]=(0,o.useState)(!1),j=(0,o.useRef)(!1),L=(0,o.useRef)(null),K=(0,o.useRef)({}),[te,V]=(0,o.useState)(null),[F,Ie]=(0,o.useState)(null),[G,ge]=(0,o.useState)(""),[X,$]=(0,o.useState)(""),[le,he]=(0,o.useState)(""),[Ae,xe]=(0,o.useState)(null),[y,ue]=(0,o.useState)(null),Re=(0,o.useCallback)(async n=>{$("version");try{let v=await fetch(E+"/version-check"+(n?"?force=1":"")).then(D=>D.json());v&&v.ok?(ue(v),n&&J(v.updateAvailable?t("vcLatest")+" v"+v.latest:t("vcUpToDate"))):n&&J(t("vcCheckFail"),!1)}catch{n&&J(t("vcCheckFail"),!1)}finally{$("")}},[t]);(0,o.useEffect)(()=>{Re(!1)},[r,Re]);let[h,U]=(0,o.useState)(""),[re,ye]=(0,o.useState)(null),ee=(0,o.useRef)(null),J=(n,v=!0)=>{ee.current&&clearTimeout(ee.current),ye({msg:n,ok:v}),ee.current=setTimeout(()=>ye(null),1900)},Be=async()=>{if(!X){$("restart");try{let n=await fetch(E+"/restart-self",{method:"POST"});if(n.status===404||n.status===405){J(de("vcRestartNoRoute",{cmd:y&&y.restartCommand||"dsh-memory restart --port 7999"}),!1);return}let v=await n.json().catch(()=>null);if(!v){J(t("vcRestartFail")+"\uFF08HTTP "+n.status+"\uFF09",!1);return}if(!v.ok){J(v.error||t("vcRestartFail"),!1);return}if(v.alreadyCurrent){J(v.note||t("vcRestartCurrent"));return}J(v.note||t("vcRestartSent")),v.alreadyRunning||setTimeout(()=>{Re(!0)},6e3)}catch(n){J(t("vcRestartFail")+"\uFF1A"+String(n&&n.message||n),!1)}finally{$("")}}},Ce=y&&y.resident?String(y.resident.served||""):"",Te=!!(y&&y.onDisk&&Ce&&Ce!==y.onDisk),Ne=!!(y&&y.resident&&y.resident.managed===!1&&y.resident.managedKnown===!1),s=y&&y.resident&&y.resident.replaceBlocked&&y.resident.replaceBlocked.fresh||null,N=!!(y&&y.resident&&y.resident.managedBy==="host"),I=!!(y&&y.resident&&y.resident.managed===!1&&!Ne&&!N),Z=!!(y&&y.resident&&!Ce),ke=Te||Z||I||Ne,de=(n,v)=>Object.keys(v).reduce((D,P)=>D.split("{"+P+"}").join(v[P]),t(n)),ae=(0,o.useCallback)(async()=>{try{let[n,v,D,P]=await Promise.all([fetch(`${E}/config`).then(W=>W.json()).catch(()=>null),fetch(`${E}/setup-status`).then(W=>W.json()).catch(()=>null),fetch(`${E}/budget`).then(W=>W.json()).catch(()=>null),fetch(`${E}/llm-routes`).then(W=>W.json()).catch(()=>null)]);if(P&&P.ok&&xe(P),n&&n.ok){l(n),R(n.revision??0),O(n.schema??null);let W=Yt(n.config??{},K.current);K.current=W.overlay,x({...W.values}),V(n.dsh??null),z(n.writable===!1),w(n.viaPending===!0),ge(""),j.current=!1}else D&&D.ok?(x({...D}),z(!0),ge(t("configNeedsDsh"))):ge(t("adminLoadFail"));v&&v.ok&&Ie(v),he("")}catch{ge(t("adminLoadFail"))}},[t]);(0,o.useEffect)(()=>{ae()},[r,ae]);let Y=(n,v)=>{j.current=!0,x(D=>({...D??{},[n]:v}))};(0,o.useEffect)(()=>{L.current=ae},[ae]),(0,o.useEffect)(()=>{if(typeof EventSource>"u")return;let n=null;try{n=new EventSource(E+"/events")}catch{return}let v=()=>{!j.current&&typeof L.current=="function"&&L.current()};try{n.addEventListener("config",v)}catch{}return()=>{try{n.close()}catch{}}},[]);let We=new Set(["dedupThreshold","captureMinChars","captureCooldownMs","maxCardsPerDay","captureMaxTokens","recallMinScore","recallLimit","recallSummaryLen","recycleRetentionDays","webPort","webCheckIntervalMs","webMaxRestart","sessionBudgetChars"]),je=n=>({init:t("modeInit"),interval:t("modeInterval"),manual:t("modeManual")})[n]||n,p=async()=>{if(!k)return;if(m){J(t("editInSetting"),!1);return}let n={dedupThreshold:[0,1],captureMinChars:[0,1e6],captureCooldownMs:[0,1e9],maxCardsPerDay:[0,1e6],captureMaxTokens:[100,4e3],recallMinScore:[0,50],recallLimit:[1,20],recallSummaryLen:[40,400],recycleRetentionDays:[1,3650],webPort:[1,65535],webCheckIntervalMs:[1e3,6e5],webMaxRestart:[1,1e3],sessionBudgetChars:[0,1e9]},v=[];for(let[D,[P,W]]of Object.entries(n)){if(!(D in k))continue;let B=k[D],Q=typeof B=="number"?B:Number(B);(B===""||B===null||B===void 0||!Number.isFinite(Q)||Q<P||Q>W)&&v.push(t("invalidField",{field:D,min:P,max:W,value:String(B===""?"\u7A7A":B)}))}if(v.length){let D=t("saveInvalid")+"\uFF1A"+v.join("\uFF1B");ge(D),J(D,!1);return}$("save");try{let D={...k};for(let Q of Object.keys(k))Q in D&&typeof D[Q]=="string"&&D[Q].trim()!==""&&We.has(Q)&&(D[Q]=Number(D[Q]));Array.isArray(D.vaultProfiles)&&(D.vaultProfiles=D.vaultProfiles.filter(Q=>Q&&(String(Q.name||"").trim()||String(Q.path||"").trim())));let P=await fetch(`${E}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:D,expectedRevision:C})}),W=await P.text(),B=null;try{B=W?JSON.parse(W):null}catch{B=null}if(B||(B={error:"HTTP "+P.status+(W?"\uFF1A"+W.slice(0,200):"\uFF08\u5BBF\u4E3B\u672A\u8FD4\u56DE\u539F\u56E0\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u6570\u5B57\u5B57\u6BB5\u4E3A\u7A7A\u6216\u8D85\u51FA\u8303\u56F4\uFF09")}),B&&B.ok){let Q=typeof B.pendingOutcome=="string"?B.pendingOutcome:"",Se,De=!0;if(Q==="applied")Se=t("savedApplied")+(Array.isArray(B.applied)&&B.applied.length?" \xB7 "+B.applied.join("\u3001"):"");else if(Q==="queued")De=!1,Se=t("saveQueued");else if(Q==="failed")De=!1,Se=t("saveFail")+" \xB7 "+(B.hostGuard?t("saveHostGuard"):t("saveFailHint"));else if(Q==="applied-direct")Se=t("savedOk")+" \xB7 "+t("savedDirect");else{let Le=Array.isArray(B.pending)&&B.pending.length?" \xB7 "+t("savePending"):B.note?" \xB7 "+t("restartHint"):"";Se=(B.retried?"\u267B ":"")+t("savedOk")+Le}K.current={...K.current,...D},De?he(Se):ge(Se),J(Se,De),await ae()}else{let Q=P.status===409?t("conflictRefresh"):B?.error||t("saveFail");ge(Q),J(Q,!1)}}catch{ge(t("saveFail")),J(t("saveFail"),!1)}finally{$("")}},d=()=>{K.current={},x({...c?.config??{}}),he("")},_={env:"vaultSrcEnv",profile:"vaultSrcProfile",workspace:"vaultSrcWorkspace",vaultDir:"vaultSrcVaultDir",default:"vaultSrcDefault"},se=n=>Array.isArray(n?.vaultProfiles)?n.vaultProfiles:[],ce=(n,v,D)=>x(P=>{let W=se(P).map(Q=>({...Q||{}})),B={...W[n]||{}};return v==="match"?String(D).trim()?B.match={...B.match||{},workspace:D}:delete B.match:B[v]=D,W[n]=B,{...P??{},vaultProfiles:W}}),fe=()=>x(n=>({...n??{},vaultProfiles:[...se(n),{name:"",path:""}]})),a=n=>x(v=>({...v??{},vaultProfiles:se(v).filter((D,P)=>P!==n)})),Pe={fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},Je={padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:12,minWidth:0},tt={A:{label:t("planA"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:4e3,recallMinScore:2,recallLimit:5,recallSummaryLen:130,recallIncludeBody:!1,captureCooldownMs:3e5},B:{label:t("planB"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!1,dedupByLLM:!1,captureMaxTokens:500,recallMinScore:3,recallLimit:3,recallSummaryLen:80,recallIncludeBody:!1,captureMinChars:300,maxCardsPerDay:40,captureCooldownMs:3e5},C:{label:t("planC"),autoWebMode:"interval",watchdogAutoSpawn:!0,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:1200,recallMinScore:1,recallLimit:8,recallSummaryLen:200,recallIncludeBody:!0,captureCooldownMs:12e4}},nt=async n=>{let v=tt[n];v&&x(D=>({...D??{},...v}))},ot=async(n,v)=>{$(n+v);try{let P=await(await fetch(`${E}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:n,action:v})})).json();P&&P.ok?J(de(v==="install"?"mcpInstalled":"mcpUninstalled",{agent:n})):J(de("mcpActionFail",{agent:n,error:P?.error||""}),!1);try{let W=await fetch(`${E}/setup-status`).then(B=>B.json());W&&W.ok&&Ie(W)}catch{}}catch{J(t("mergeFail"),!1)}finally{$("")}},we=({k:n,label:v,type:D="text",step:P,min:W,max:B})=>(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,e.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:v||n}),(0,e.jsx)("input",{type:D,step:P,min:W,max:B,value:k?k[n]??"":"",onChange:Q=>{let Se=Q.target.value;Y(n,D==="number"?Se===""?"":Number(Se):Se)},style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12}})]}),Ze=new Set(["autoRestartOnDrift"]),b=({k:n,label:v})=>{let D=k?k[n]:void 0,P=D===void 0?Ze.has(n):!!D;return(0,e.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:12,minWidth:0,lineHeight:1.5},children:[(0,e.jsx)("input",{type:"checkbox",checked:P,onChange:W=>Y(n,W.target.checked),style:{marginTop:2,flex:"0 0 auto"}}),(0,e.jsx)("span",{style:{whiteSpace:"normal",overflowWrap:"anywhere"},children:v||n})]})};return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:g?"0 0 auto":1,minHeight:0,maxHeight:g?"52vh":void 0},children:[(0,e.jsx)("style",{children:Ee}),re&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(re.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:re.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:re.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:re.msg})]}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[G&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,e.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",G]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:ae,children:["\u21BB ",t("retry")]})]}),T&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #3b82f6",background:"rgba(59,130,246,0.08)",padding:"10px 14px",marginBottom:10,fontSize:12,color:"#1d4ed8",lineHeight:1.7},children:["\u2139 ",t("pendingSyncNote")]}),m&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #f59e0b",background:"rgba(245,158,11,0.08)",padding:"10px 14px",marginBottom:10,fontSize:12,color:"#b45309"},children:["\u2139\uFE0F ",t("configNeedsDsh")," \u2014\u2014 ",t("editInSetting")]}),le&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #10b981",background:"rgba(16,185,129,0.08)",padding:"10px 14px",marginBottom:10,fontSize:12,color:"#059669"},children:["\u2713 ",le]}),c&&(c.version||c.dsh?.vaultDir)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F4E6} ",t("pluginInfo")]}),(0,e.jsx)("span",{style:{fontSize:12,opacity:.7},children:t("dshHostLabel")}),c.version&&(0,e.jsxs)("code",{style:Pe,children:[t("vcLoaded")," v",c.version]}),y&&y.resident&&y.resident.served&&y.resident.served!==c.version&&(0,e.jsxs)("code",{style:Pe,children:[t("vcResident")," v",y.resident.served]}),y&&y.resident&&!y.resident.served&&(0,e.jsxs)("code",{style:{...Pe,color:"#b45309",fontWeight:600},children:[t("vcResident")," ",t("vcResidentDownShort")]}),y&&y.resident&&y.resident.served&&y.resident.managed===!1&&(0,e.jsxs)("code",{style:{...Pe,color:"#b45309",fontWeight:600},children:[t("vcResident")," v",y.resident.served," \xB7 ",t(s?"vcResidentReplaceBlockedShort":N?"vcResidentHostManagedShort":Ne?"vcResidentLockUnknownShort":"vcResidentUnmanagedShort")]}),bt&&(0,e.jsxs)("code",{style:Pe,children:[t("vcPage")," v",bt]}),y&&y.onDisk&&(0,e.jsxs)("code",{style:Pe,children:[t("vcOnDisk")," v",y.onDisk]}),y&&y.latest&&(0,e.jsxs)("code",{style:Pe,children:[t("vcLatest")," v",y.latest]}),c.dsh?.vaultDir&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",c.dsh.vaultDir]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:X==="version",onClick:()=>Re(!0),children:X==="version"?t("checking"):"\u{1F504} "+t("vcCheck")})]}),y&&(y.stale||Z||I||Ne||s)&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b45309",background:"rgba(245,158,11,0.12)",border:"1px solid rgba(245,158,11,0.35)",borderRadius:8,padding:"6px 10px"},children:[(0,e.jsxs)("div",{children:["\u26A0\uFE0F ",y.stale?de("vcStale",{disk:y.onDisk,loaded:y.loaded}):Z?de("vcResidentDown",{port:y.resident&&y.resident.port||"",cmd:y.restartCommand||"dsh-memory restart --port 7999"}):s?de("vcResidentReplaceBlocked",{served:Ce,err:s.error||"",path:s.lockPath||"",cmd:y.restartCommand||"dsh-memory restart --port "+(y.resident&&y.resident.port||7999)}):Ne?de("vcResidentLockUnknown",{served:Ce,path:y.resident&&y.resident.lock&&y.resident.lock.path||"",err:y.resident&&y.resident.lock&&y.resident.lock.error||""}):de("vcResidentUnmanaged",{served:Ce,cmd:y.restartCommand||"dsh-memory restart --port 7999"})]}),ke?(0,e.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",marginTop:6,flexWrap:"wrap"},children:[(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!X,onClick:Be,children:X==="restart"?"\u23F3 "+t("vcRestarting"):"\u{1F504} "+t("vcRestart")}),y.restartCommand&&(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:y.restartCommand})]}):(0,e.jsxs)("div",{style:{marginTop:6,lineHeight:1.7},children:["\u2139\uFE0F ",t("vcHostStale"),y.restartCommand&&(0,e.jsxs)(e.Fragment,{children:[" ",(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:y.restartCommand})]})]})]}),bt&&y&&y.onDisk&&bt!==y.onDisk&&(0,e.jsx)("div",{style:{marginTop:8,fontSize:11.5,color:"#b45309",background:"rgba(245,158,11,0.12)",border:"1px solid rgba(245,158,11,0.35)",borderRadius:8,padding:"6px 10px",lineHeight:1.7},children:t("vcPageStale",{page:bt,disk:y.onDisk})}),y&&y.updateAvailable&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,opacity:.88},children:["\u2B06 ",t("vcOutdated")," \u2192 ",(0,e.jsx)("code",{children:y.updateCommand})]}),y&&y.checkError&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b91c1c"},children:[t("vcCheckFail"),"\uFF1A",y.checkError]})]}),F&&F.agents&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F50C} ",t("mcpSetupStatus")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("mcpManageHint")})]}),(0,e.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:F.agents.map(n=>(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1},children:[(0,e.jsx)("b",{children:n.isDsh?t("dshHostLabel"):n.name}),n.isDsh&&n.version&&(0,e.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",n.version]}),!n.installed&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",t("notInstalled"),")"]}),n.installed&&n.mcpConfigured===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",t("noMcpEntry"),")"]}),n.mcpConfigured===!0&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",t("healthy")]}),n.mcpConfigured===!0&&n.mcpMatchesCurrentNode===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",t("nodePathNote"),")"]}),n.isDsh&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",t("recallTool"),": ",n.recallTool?t("enabled"):t("disabled"),")"]})]}),n.hook&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",n.hook]}),!n.isDsh&&n.installed&&n.mcpConfigured===!1&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!X,onClick:()=>ot(n.name,"install"),children:t("installMcp")}),!n.isDsh&&n.installed&&n.mcpConfigured===!0&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!X,onClick:()=>{window.confirm(t("uninstallConfirm"))&&ot(n.name,"uninstall")},children:t("uninstallMcp")})]},n.name))}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:t("mcpSetupHint")}),h&&(0,e.jsx)("div",{style:{fontSize:11,marginTop:6},children:(0,e.jsx)("code",{style:{padding:"2px 6px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:4},children:h})})]}),k?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #3b82f6"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8,flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F3AF} ",t("presetConfig")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("presetHint")})]}),(0,e.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["A","B","C"].map(n=>(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>nt(n),disabled:!!X,children:[n==="A"?"\u{1F7E2} ":n==="B"?"\u{1F4B0} ":"\u2B50 ",tt[n].label]},n))})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F9E0} ",t("dshMemoryConfig")]})}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,e.jsx)(b,{k:"autoCapture",label:t("autoCapture")}),(0,e.jsx)(b,{k:"autoRecall",label:t("autoRecall")}),(0,e.jsx)(we,{k:"captureMinChars",label:t("captureMinChars"),type:"number"}),(0,e.jsx)(we,{k:"maxCardsPerDay",label:t("maxCardsPerDay"),type:"number"}),(0,e.jsx)(we,{k:"dedupThreshold",label:t("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,e.jsx)(we,{k:"recallLimit",label:t("recallLimit"),type:"number"}),(0,e.jsx)(we,{k:"recallSummaryLen",label:t("recallSummaryLen"),type:"number"}),(0,e.jsx)(b,{k:"recallIncludeBody",label:t("recallBody")}),(0,e.jsx)(we,{k:"secretHint",label:t("secretHint")}),(0,e.jsx)(we,{k:"recallEmbedding",label:t("recallEmbedding")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #06b6d4"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:6},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F5C2}\uFE0F ",t("vaultMulti")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("vaultMultiHint")})]}),(0,e.jsxs)("div",{style:{fontSize:11.5,opacity:.85,marginBottom:8,lineHeight:1.7},children:[t("vaultNow"),"\uFF1A",(0,e.jsx)("code",{children:te?.vaultDir||"\u2014"}),te?.vaultName?`\uFF08${te.vaultName}\uFF09`:""," \xB7 ",t("vaultSource"),"\uFF1A",t(_[te?.vaultSource]||"vaultSrcDefault"),te?.workspace?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),t("vaultWorkspace"),"\uFF1A",(0,e.jsx)("code",{children:te.workspace})]}):null]}),se(k).map((n,v)=>(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.6fr 1.5fr auto",gap:6,marginBottom:6},children:[(0,e.jsx)("input",{value:n.name||"",placeholder:t("vaultNamePh"),onChange:D=>ce(v,"name",D.target.value),style:Je,disabled:m}),(0,e.jsx)("input",{value:n.path||"",placeholder:t("vaultPathPh"),onChange:D=>ce(v,"path",D.target.value),style:Je,disabled:m}),(0,e.jsx)("input",{value:n.match&&n.match.workspace||"",placeholder:t("vaultMatchPh"),onChange:D=>ce(v,"match",D.target.value),style:Je,disabled:m}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>a(v),disabled:m,title:t("delete"),children:"\u2715"})]},v)),(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginTop:4},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:fe,disabled:m,children:["\uFF0B ",t("vaultAdd")]}),(0,e.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("vaultActive")}),(0,e.jsxs)("select",{value:k.activeVault||"",onChange:n=>Y("activeVault",n.target.value),disabled:m,style:Je,children:[(0,e.jsx)("option",{value:"",children:t("vaultActiveNone")}),se(k).filter(n=>n&&n.name).map(n=>(0,e.jsx)("option",{value:n.name,children:n.name},n.name))]})]})]})]}),(0,e.jsx)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,e.jsx)(b,{k:"enabled",label:t("enabledLabel")}),(0,e.jsx)(we,{k:"vaultDir",label:t("vaultDirLabel")})]})}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #f59e0b"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F4B0} ",t("costControl")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("costHint")})]}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8,marginTop:6},children:[(0,e.jsx)(b,{k:"distillEnabled",label:t("distillEnabled")}),(0,e.jsx)(b,{k:"dedupByLLM",label:t("dedupByLLM")}),(0,e.jsx)(we,{k:"captureMaxTokens",label:t("captureMaxTokens"),type:"number"}),(0,e.jsx)(we,{k:"recallMinScore",label:t("recallMinScore"),type:"number"}),(0,e.jsx)(we,{k:"captureCooldownMs",label:t("captureCooldownMs"),type:"number"}),Ae&&Ae.providers&&Ae.providers.length?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("captureProvider")}),(0,e.jsxs)("select",{value:k.captureProvider||"",onChange:n=>{Y("captureProvider",n.target.value),Y("captureModel","")},style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"",children:t("routeAuto")}),Ae.providers.map(n=>(0,e.jsx)("option",{value:n.id,children:n.label},n.id))]})]}),(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("captureModel")}),(0,e.jsxs)("select",{value:k.captureModel||"",onChange:n=>Y("captureModel",n.target.value),style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"",children:t("routeAuto")}),((Ae.providers.find(n=>n.id===k.captureProvider)||{}).models||[]).map(n=>(0,e.jsx)("option",{value:n.id,children:n.label||n.id},n.id))]})]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(we,{k:"captureProvider",label:t("captureProvider")}),(0,e.jsx)(we,{k:"captureModel",label:t("captureModel")})]}),(0,e.jsx)(b,{k:"captureFollowSession",label:t("captureFollowSession")}),(0,e.jsx)(b,{k:"captureFirstOnly",label:t("captureFirstOnly")}),(0,e.jsx)(we,{k:"sessionBudgetChars",label:t("sessionBudgetChars"),type:"number"}),(0,e.jsx)("div",{style:{display:"flex",alignItems:"flex-end"},children:(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!X,onClick:async()=>{$("llmtest");try{let n=await fetch(E+"/llm-test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k.captureProvider||"",model:k.captureModel||"",firstOnly:k.captureFirstOnly===!0})}).then(v=>v.json());n&&n.ok?J(t("llmTestOk")+"\uFF1A"+n.route.provider+(n.route.model?"/"+n.route.model:"")+" \xB7 "+n.ms+"ms \xB7 "+t("llmCandidates")+" "+n.candidates):J(t("llmTestFail")+"\uFF1A"+(n&&(n.failure?n.failure.code+" "+n.failure.message:n.error)||"?"),!1)}catch(n){J(t("llmTestFail")+"\uFF1A"+String(n&&n.message||n),!1)}finally{$("")}},children:X==="llmtest"?t("exporting"):"\u{1F50C} "+t("llmTest")})})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #8b5cf6"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",t("auditConfig")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("auditHint")})]}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,e.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:t("auditMode")}),(0,e.jsxs)("select",{value:k.auditMode??"all",onChange:n=>Y("auditMode",n.target.value),style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"all",children:t("auditAll")}),(0,e.jsx)("option",{value:"none",children:t("auditNone")})]})]}),(0,e.jsx)(Jt,{label:t("auditExemptAgents"),value:k.auditExemptAgents||[],options:[{value:"__all__",label:t("allExempt")},...(F?.agents||[]).filter(n=>!n.isDsh).map(n=>({value:n.name,label:n.name}))],onChange:n=>Y("auditExemptAgents",n)}),(0,e.jsx)(Jt,{label:t("auditExemptKinds"),value:k.auditExemptKinds||[],options:[{value:"__all__",label:t("allExempt")},...At.filter(n=>n!=="all").map(n=>({value:n,label:t(Ke[n])}))],onChange:n=>Y("auditExemptKinds",n)}),(0,e.jsx)(we,{k:"recycleRetentionDays",label:t("recycleDays"),type:"number"})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E0} ",t("serviceConfig")]})}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,e.jsx)(b,{k:"autoWeb",label:t("autoWeb")}),(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("autoWebMode")}),(0,e.jsxs)("select",{value:k.autoWebMode??"init",onChange:n=>Y("autoWebMode",n.target.value),style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"init",children:t("modeInit")}),(0,e.jsx)("option",{value:"interval",children:t("modeInterval")}),(0,e.jsx)("option",{value:"manual",children:t("modeManual")})]})]}),(0,e.jsx)(we,{k:"webPort",label:t("webPort"),type:"number"}),(0,e.jsx)(we,{k:"webCheckIntervalMs",label:t("webCheckIntervalMs"),type:"number"}),(0,e.jsx)(we,{k:"webMaxRestart",label:t("webMaxRestart"),type:"number"}),(0,e.jsx)(b,{k:"watchdogAutoSpawn",label:t("watchdogAutoSpawn")}),(0,e.jsx)(b,{k:"autoRestartOnDrift",label:t("autoRestartOnDrift")}),(0,e.jsx)(b,{k:"autoMcpSetup",label:t("autoMcpSetup")})]})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",alignItems:"center",marginBottom:10,flexWrap:"wrap"},children:[X==="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,opacity:.75},children:["\u23F3 ",t("saving")]}),le&&X!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#10b981"},children:["\u2705 ",le]}),G&&X!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#b91c1c"},children:["\u26A0 ",G]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:d,disabled:!!X,children:t("reset")}),(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:m?()=>J(t("readonlyTitle")+"\uFF1A"+t("readonlyBody"),!1):p,disabled:X==="save",title:t(m?"readonlyBody":"saveConfig"),children:X==="save"?"\u23F3 "+t("saving"):m?"\u{1F512} "+t("readonlyBtn"):"\u{1F4BE} "+t("saveConfig")})]})]}):(0,e.jsx)("div",{style:{fontSize:12,opacity:.6},children:t("loading")})]})]})}function Aa({t,onReload:i,version:r}){let[g,c]=(0,o.useState)([]),[l,C]=(0,o.useState)([]),[R,S]=(0,o.useState)("all"),[O,k]=(0,o.useState)("all"),[x,m]=(0,o.useState)(""),[z,T]=(0,o.useState)(new Set),[w,j]=(0,o.useState)(""),[L,K]=(0,o.useState)(null),[te,V]=(0,o.useState)("pending"),F=(h,U=!0)=>{K({msg:h,ok:U}),setTimeout(()=>K(null),3e3)},Ie=[...new Set([...g,...l].map(h=>h.submittedBy).filter(Boolean))],G=(0,o.useCallback)(async()=>{try{let h=await fetch(`${E}/audit/list`).then(U=>U.json());h.ok&&(c(h.pending||[]),C(h.rejected||[]),T(new Set),he(new Set),xe({}))}catch{}},[]);(0,o.useEffect)(()=>{G()},[r,G]);let ge=(te==="pending"?g:l).filter(h=>{if(R!=="all"&&h.kind!==R||O!=="all"&&mt(h.submittedBy)!==O)return!1;if(x){let U=(h.created||"").slice(0,10);if(U&&U!==x)return!1}return!0}),X=h=>T(U=>{let re=new Set(U);return re.has(h)?re.delete(h):re.add(h),re}),$=async(h,U)=>{let re=U||[...z];if(!re.length){F(t("noSelection"),!1);return}j("apply");let ye=t(h==="approved"?"toastApproved":h==="rejected"?"toastRejected":"toastCardDeleted");try{let ee=0;for(let J of re){let Be=h==="approved"?"audit/approve":h==="rejected"?"audit/reject":"delete";try{(await fetch(E+"/"+Be+"?path="+encodeURIComponent(J)+(h==="delete"?"&permanent=0":""))).ok||ee++}catch{ee++}}await G(),i&&i(),ee?F(t("toastFailed")+"\uFF08"+ee+"/"+re.length+"\uFF09",!1):F(ye+" "+re.length+" \u5F20")}catch(ee){F(t("toastFailed")+": "+String(ee&&ee.message||ee),!1)}finally{j("")}},[le,he]=(0,o.useState)(new Set),[Ae,xe]=(0,o.useState)({}),y=h=>Ae[h]||{},ue=async h=>{let U=h.path,re=!le.has(U);if(he(ye=>{let ee=new Set(ye);return re?ee.add(U):ee.delete(U),ee}),!(!re||Ae[U])){xe(ye=>({...ye,[U]:{loading:!0}}));try{let ye=h.status||(te==="pending"?"pending":"rejected"),ee=await fetch(`${E}/card?path=${encodeURIComponent(U)}&status=${ye}`).then(J=>J.json());ee&&ee.ok?xe(J=>({...J,[U]:{text:ee.text||""}})):xe(J=>({...J,[U]:{error:ee&&ee.error||"HTTP"}}))}catch(ye){xe(ee=>({...ee,[U]:{error:String(ye&&ye.message||ye)}}))}}},Re=[...z];return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(na,{toast:L}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",t("tabAudit")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("select",{value:R,onChange:h=>S(h.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("all")}),At.filter(h=>h!=="all").map(h=>(0,e.jsx)("option",{value:h,children:t(Ke[h])},h))]}),(0,e.jsxs)("select",{value:O,onChange:h=>k(h.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("allAgents")}),ta(Ie).map(h=>(0,e.jsx)("option",{value:h,children:h},h))]}),(0,e.jsx)("input",{type:"date",value:x,onChange:h=>m(h.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"}})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("button",{type:"button",className:`mc-btn${te==="pending"?" me-on":""}`,onClick:()=>V("pending"),children:[t("pending"),"\uFF08",g.length,"\uFF09"]}),(0,e.jsxs)("button",{type:"button",className:`mc-btn${te==="rejected"?" me-on":""}`,onClick:()=>V("rejected"),children:[t("rejected"),"\uFF08",l.length,"\uFF09"]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("label",{style:{fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:ge.length>0&&Re.length===ge.length,onChange:h=>{h.target.checked?T(new Set(ge.map(U=>U.path))):T(new Set)}})," ",t("selectAll")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!Re.length||!!w,onClick:()=>$("approved"),children:["\u2713 ",t(te==="rejected"?"restore":"approve")]}),te==="pending"?(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!Re.length||!!w,onClick:()=>$("rejected"),children:["\u2715 ",t("reject")]}):(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!Re.length||!!w,onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&$("delete")},children:["\u{1F5D1} ",t("restoreDelete")]})]}),ge.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:ge.map(h=>{let U=y(h.path),re=le.has(h.path);return(0,e.jsxs)("div",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:z.has(h.path),onChange:()=>X(h.path)}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"0 6px"},title:t(re?"collapse":"expand"),"aria-expanded":re,onClick:()=>ue(h),children:re?"\u25BE":"\u25B8"}),(0,e.jsx)("span",{className:"mc-kind",style:{background:qe[h.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},title:t(re?"collapse":"expand"),onClick:()=>ue(h),children:h.title}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:mt(h.submittedBy)}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:h.created?h.created.slice(0,16).replace("T"," "):"-"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:h.kind}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,color:h.severity==="high"?"#f87171":"#9ca3af"},children:h.severity}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.reason||"-"}),te==="pending"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>$("approved",[h.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>$("rejected",[h.path]),children:"\u2715"})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},title:t("restore"),onClick:()=>$("approved",[h.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},title:t("restoreDelete"),onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&$("delete",[h.path])},children:"\u{1F5D1}"})]})]}),re&&(0,e.jsxs)("div",{style:{padding:"2px 10px 12px 34px"},children:[U.loading&&(0,e.jsxs)("div",{style:{fontSize:12,opacity:.6},children:["\u23F3 ",t("loading")]}),U.error&&(0,e.jsxs)("div",{style:{fontSize:12,color:"#f87171"},children:["\u26A0 ",t("auditBodyFail"),"\uFF1A",U.error]}),U.text!=null&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"md-meta",style:{marginBottom:6},children:[(0,e.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:qe[h.kind]||"#6B7280",borderColor:(qe[h.kind]||"#6B7280")+"59",background:(qe[h.kind]||"#6B7280")+"1a"},children:[vt[h.kind]||"\u{1F4CE}"," ",t(Ke[h.kind]||"kindKnowledge")]}),(Array.isArray(h.tags)?h.tags:[]).slice(0,8).map(ye=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",ye]},ye)),!!h.reason&&(0,e.jsxs)("span",{className:"md-chip md-chip-st-warn",children:["\u2691 ",h.reason]})]}),(0,e.jsx)("div",{className:"md-doc",style:{maxHeight:340,overflow:"auto"},dangerouslySetInnerHTML:{__html:Dt(Ct(U.text).body)}}),te==="pending"&&(0,e.jsxs)("div",{style:{display:"flex",gap:8,marginTop:8},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!!w,onClick:()=>$("approved",[h.path]),children:["\u2713 ",t("approve")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!w,onClick:()=>$("rejected",[h.path]),children:["\u2715 ",t("reject")]})]})]})]})]},h.path)})}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:t("noAuditItems")})]})]})}function Ba({t,onReload:i,version:r}){let[g,c]=(0,o.useState)([]),[l,C]=(0,o.useState)(""),[R,S]=(0,o.useState)(null),O=(m,z=!0)=>{S({msg:m,ok:z}),setTimeout(()=>S(null),3200)},k=(0,o.useCallback)(async()=>{try{let m=await fetch(`${E}/recycle/list`).then(z=>z.json());m.ok&&c(m.items||[])}catch{}},[]);(0,o.useEffect)(()=>{k()},[r,k]);let x=async(m,z)=>{let T=(g.find(w=>w.path===z)||{}).title||z;C(m+z);try{let j=await fetch(E+(m==="restore"?"/recycle/restore":"/recycle/purge")+"?path="+encodeURIComponent(z)),L=await j.json().catch(()=>null);await k(),i&&i(),j.ok&&(!L||L.ok!==!1)?O(t(m==="restore"?"toastRestored":"toastPurged")+"\uFF1A"+T):O(t("toastFailed")+"\uFF1A"+(L&&L.error||"HTTP "+j.status),!1)}catch(w){O(t("toastFailed")+"\uFF1A"+String(w&&w.message||w),!1)}finally{C("")}};return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(na,{toast:R}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F5D1}\uFE0F ",t("tabRecycle")]}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("recycleHint")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!l||g.length===0,title:g.length?"":t("emptyRecycle"),onClick:async()=>{C("purgeAll");try{let m=await fetch(E+"/recycle/purge-expired?days=0"),z=await m.json().catch(()=>null);await k(),O(m.ok?t("toastPurgedExpired")+(z&&z.purged!=null?"\uFF08"+z.purged+"\uFF09":""):t("toastFailed"),m.ok)}catch(m){O(t("toastFailed")+"\uFF1A"+String(m&&m.message||m),!1)}finally{C("")}},children:t("emptyRecycle")})]}),g.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:g.map(m=>(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:qe[m.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.title}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[t("deletedAt")," ",(m.deletedAt||"").slice(0,10)]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!l,onClick:()=>x("restore",m.path),children:t("restore")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!l,onClick:()=>{window.confirm(t("purgeConfirm"))&&x("purge",m.path)},children:t("purge")})]},m.path))}):(0,e.jsxs)("div",{className:"mc-card",style:{padding:18,fontSize:12.5,opacity:.78,textAlign:"center",lineHeight:1.9},children:["\u{1F5D1}\uFE0F ",t("emptyRecycle"),(0,e.jsx)("br",{}),(0,e.jsx)("span",{style:{fontSize:11.5},children:t("recycleEmptyHint").split("{days}").join("30")})]})]})]})}var La=({card:t,t:i,onOpen:r,query:g,onDelete:c})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>r(t),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:qe[t.kind]||qe.other}}),(0,e.jsx)("span",{style:{marginRight:4},children:vt[t.kind]||"\u{1F4CE}"}),g?Zt(t.title,g):t.title,_a(t.updated)&&(0,e.jsx)("span",{className:"mc-new",children:i("newBadge")}),t.status==="pending"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",i("statusPending")]}),t.status==="rejected"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#ef4444"},children:["\u274C ",i("statusRejected")]}),(!t.status||t.status==="approved")&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#10b981"},children:["\u2705 ",i("statusApproved")]})]}),(0,e.jsx)("p",{children:g?Zt(t.summary||"",g):t.summary||""}),Gt(t).length>0&&(0,e.jsx)("div",{className:"mc-tags",children:Gt(t).slice(0,4).map(l=>(0,e.jsxs)("span",{className:"mc-tag",children:["\u{1F3F7} ",l]},l))}),(0,e.jsxs)("footer",{children:[(0,e.jsxs)("span",{children:[vt[t.kind]||"\u{1F4CE}"," ",i(Ke[t.kind])]}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",mt(t.submittedBy)]}),(0,e.jsxs)("span",{children:["\u{1F4C5} ",ut(t.updated)]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:i("delete"),onClick:l=>{l.stopPropagation(),window.confirm(i("deleteConfirm"))&&c&&c(t.path)},children:"\u{1F5D1}"})]})]});function ja({t,tab:i,onReload:r,version:g}){let[c,l]=(0,o.useState)(null),[C,R]=(0,o.useState)(""),[S,O]=(0,o.useState)(null),[k,x]=(0,o.useState)(null),[m,z]=(0,o.useState)(null),[T,w]=(0,o.useState)(null),j=(0,o.useCallback)(async()=>{F("align");try{let s=await fetch(E+"/align").then(N=>N.json());s&&s.findings?w(s):notify(t("alignFail"),!1)}catch{notify(t("alignFail"),!1)}finally{F("")}},[t]),L=async()=>{if(window.confirm(t("alignFixConfirm"))){F("alignfix");try{let s=await fetch(E+"/setup-run",{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"}).then(N=>N.json());s&&s.ok?(notify(t("alignFixed")),await j()):notify(t("alignFail"),!1)}catch{notify(t("alignFail"),!1)}finally{F("")}}},[K,te]=(0,o.useState)([]),[V,F]=(0,o.useState)(""),[Ie,G]=(0,o.useState)(!1),ge=(0,o.useCallback)(async()=>{if(!(!S||!S.merge||!S.merge.length)&&window.confirm(t("mergeAllConfirm"))){F("merge");try{let s={},N=ae=>s[ae]===void 0?ae:s[ae]=N(s[ae]),I=(ae,Y)=>{s[N(ae)]=N(Y)},Z=new Set;for(let ae of S.merge)Z.add(ae.a.path),Z.add(ae.b.path),I(ae.a.path,ae.b.path);let ke={};for(let ae of Z){let Y=N(ae);(ke[Y]=ke[Y]||[]).push(ae)}let de=0;for(let ae of Object.values(ke)){if(ae.length<2)continue;(await fetch(`${E}/merge?paths=${encodeURIComponent(ae.join(","))}`).then(We=>We.json())).ok&&de++}await X(),r&&r()}catch{}F("")}},[S,X,r,t]);async function X(){try{let s=await Promise.all([fetch(`${E}/stats`),fetch(`${E}/budget`),fetch(`${E}/capture-log`),fetch(`${E}/cards?status=all&limit=30&agent=${ht}`)]),[N,I,Z,ke]=await Promise.all(s.map(de=>de.json()));N&&N.ok&&l(N),I&&I.ok&&x(I),Z&&Z.ok&&z(Z),ke&&ke.ok&&te(ke.cards||[]),R(!N||!N.ok?t("adminLoadFail"):"")}catch{R(t("adminLoadFail"))}}let $=(0,o.useCallback)(async()=>{F("scan");try{let s=await fetch(`${E}/optimize`).then(N=>N.json());s.ok&&O(s)}catch{R(t("adminLoadFail"))}finally{F("")}},[t]),[le,he]=(0,o.useState)(null),Ae=(0,o.useCallback)(async()=>{F("refine");try{let s=await fetch(`${E}/refine-scan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({limit:8})}).then(N=>N.json());s&&s.ok?he(s):notify(s&&s.error||t("refineFail"),!1)}catch{notify(t("refineFail"),!1)}finally{F("")}},[t]),xe=async(s,N)=>{if(!(N==="merge"&&!window.confirm(t("mergeConfirm")))){F("refineapply");try{let I=await fetch(`${E}/refine-apply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({a:s.a.path,b:s.b.path,action:N,relation:s.relation})}).then(Z=>Z.json());I&&I.ok?(notify(t("refineApplied")),he(Z=>Z&&{...Z,findings:(Z.findings||[]).filter(ke=>!(ke.a.path===s.a.path&&ke.b.path===s.b.path))}),await X(),r&&r()):notify(I&&I.error||t("refineFail"),!1)}catch{notify(t("refineFail"),!1)}finally{F("")}}},[y,ue]=(0,o.useState)(null),Re=(0,o.useCallback)(async()=>{F("junk");try{let s=await fetch(`${E}/refine-junk`).then(N=>N.json());s&&s.ok?ue(s.items||[]):notify(t("junkFail"),!1)}catch{notify(t("junkFail"),!1)}finally{F("")}},[t]),h=async s=>{if(s.length&&window.confirm(t("junkRecycleAllConfirm"))){F("junkpurge");try{let N=await fetch(`${E}/refine-junk-purge`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:s})}).then(I=>I.json());N&&N.removed?(notify(t("junkDone")+"\uFF1A"+N.removed.length+(N.failed?.length?"\uFF08\u5931\u8D25 "+N.failed.length+"\uFF09":"")),ue(I=>I&&I.filter(Z=>!N.removed.includes(Z.path))),await X(),r&&r()):notify(t("junkFail"),!1)}catch{notify(t("junkFail"),!1)}finally{F("")}}},[U,re]=(0,o.useState)(null),ye=(0,o.useCallback)(async()=>{F("goals");try{let s=await fetch(E+"/refine-goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({limit:30})}).then(N=>N.json());s&&s.ok?re(s):notify(s&&s.error||t("goalFail"),!1)}catch{notify(t("goalFail"),!1)}finally{F("")}},[t]),ee=async s=>{F("goalskeep");try{let N=await fetch(E+"/refine-goals-keep",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:s.members.map(I=>I.path)})}).then(I=>I.json());N&&N.ok?(notify(t("goalDone")),re(I=>I&&{...I,clusters:(I.clusters||[]).filter(Z=>Z.goal!==s.goal)})):notify(t("goalFail"),!1)}catch{notify(t("goalFail"),!1)}finally{F("")}},J=async s=>{if(window.confirm(t("mergeConfirm"))){F("goalsmerge");try{let N=await fetch(E+"/merge?paths="+encodeURIComponent(s.members.map(I=>I.path).join(","))).then(I=>I.json());N&&N.ok?(notify(t("goalMerged")),re(I=>I&&{...I,clusters:(I.clusters||[]).filter(Z=>Z.goal!==s.goal)}),await X(),r&&r()):notify(t("mergeFail"),!1)}catch{notify(t("mergeFail"),!1)}finally{F("")}}};(0,o.useEffect)(()=>{X()},[g]);let Be=async(s,N)=>{if(window.confirm(t("mergeConfirm")))try{(await fetch(`${E}/merge?paths=${encodeURIComponent(s+","+N)}`).then(Z=>Z.json())).ok&&(await X(),r&&r())}catch{}},Ce=async s=>{if(window.confirm(t("deleteConfirm")))try{(await fetch(`${E}/delete?path=${encodeURIComponent(s)}`).then(I=>I.json())).ok&&(await X(),r&&r())}catch{}},Te=["project","knowledge","content","prompt","business","tool","mistake"],Ne=({title:s,kind:N,updated:I,path:Z})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:pt.colors[N]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:ut(I)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>Ce(Z),children:[t("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{style:{overflow:"auto"},children:[C&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,e.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",C]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:X,children:["\u21BB ",t("retry")]})]}),i==="stats"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F527} ",t("alignTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:j,children:t(V==="align"?"exporting":"alignRun")}),T&&T.counts&&T.counts.fix>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:L,children:t(V==="alignfix"?"exporting":"alignFix")}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("alignHint")})]}),T&&T.findings?(0,e.jsxs)("div",{style:{marginTop:6},children:[(0,e.jsxs)("div",{style:{fontSize:12,opacity:.75,marginBottom:4},children:[t("alignDisk")," v",T.onDisk||"?",T.residentServed?" \xB7 "+t("alignResident")+" v"+T.residentServed:"",T.hostVersion?" \xB7 "+t("alignHost")+" v"+T.hostVersion:""]}),(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:T.findings.map((s,N)=>(0,e.jsxs)("li",{style:{padding:"4px 2px",borderTop:N?"1px solid rgba(127,127,127,0.12)":"none",fontSize:12},children:[(0,e.jsx)("span",{style:{fontWeight:700,color:s.level==="fix"?"#ef4444":s.level==="warn"?"#f59e0b":"#10b981"},children:s.level==="fix"?"\u2717":s.level==="warn"?"\u26A0":"\u2713"})," ",(0,e.jsx)("span",{children:s.title}),s.detail?(0,e.jsx)("div",{style:{opacity:.75,marginLeft:14},children:s.detail}):null,s.command?(0,e.jsxs)("div",{style:{marginLeft:14,opacity:.9},children:["\u2192 ",(0,e.jsx)("code",{children:s.command})]}):null]},N))})]}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginTop:4},children:t("alignIdle")})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1FAB5} ",t("captureLog")]}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("captureLogHint")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>X(),children:["\u21BB ",t("refresh")]})]}),m?m.available===!1?(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:t("captureLogUnavailable")}):(m.entries||[]).length===0?(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:t("captureLogEmpty")}):(0,e.jsx)("div",{style:{maxHeight:260,overflow:"auto",marginTop:8},children:(0,e.jsx)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:(0,e.jsx)("tbody",{children:(m.entries||[]).map((s,N)=>{let I=Na[s.action]||["\u2022","inherit"];return(0,e.jsxs)("tr",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("td",{style:{padding:"4px 6px",opacity:.55,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:ut(s.time?new Date(s.time).toISOString():"")}),(0,e.jsxs)("td",{style:{padding:"4px 6px",whiteSpace:"nowrap",color:I[1],fontWeight:600},children:[I[0]," ",s.action]}),(0,e.jsx)("td",{style:{padding:"4px 6px"},children:s.reason||""}),(0,e.jsx)("td",{style:{padding:"4px 6px",opacity:.55,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s.preview||"",children:s.preview||""})]},N)})})})}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:t("loading")})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:["\u{1F916} ",t("captureAgentCards"),"\uFF08",K.length,"\uFF09"]}),K.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:K.map(s=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:qe[s.kind]||qe.other}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.title}),s.status==="pending"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",t("statusPending")]}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:ut(s.updated)})]},s.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noCards")})]}),c&&(0,e.jsxs)(e.Fragment,{children:[c.trend&&c.trend.length>0&&(()=>{let s=c.trend,N=Math.max(...s.map(de=>de.count),1),I=260,Z=50,ke=I/s.length;return(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,e.jsxs)("div",{style:{fontSize:11,opacity:.6,marginBottom:4},children:["\u{1F4C8} ",t("trendLabel")]}),(0,e.jsx)("svg",{width:I,height:Z,style:{display:"block",width:"100%",height:50},children:s.map((de,ae)=>{let Y=Math.round(de.count/N*(Z-4));return(0,e.jsx)("rect",{x:ae*ke+1,y:Z-Y,width:Math.max(ke-2,2),height:Y,rx:1.5,fill:de.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:de.count>0?.85:.35},de.date)})})]})})(),(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:c.total}),(0,e.jsx)("span",{children:t("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:c.today}),(0,e.jsx)("span",{children:t("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:c.week}),(0,e.jsx)("span",{children:t("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:c.tags}),(0,e.jsx)("span",{children:t("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:Te.map(s=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:pt.colors[s]||"#666"}}),t(Ke[s]),": ",c.byKind?.[s]||0]},s))})]}),k&&(k.budgetChars||k.recallLimit||k.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:t("budgetLabel")}),"\uFF1A",t("budgetChars")," ",(0,e.jsx)("b",{children:k.budgetChars||8e4})," \xB7 ",t("recallLimitLabel")," ",(0,e.jsx)("b",{children:k.recallLimit||5})," \xB7 ",t("embeddingLabel")," ",k.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[t("todayList"),"\uFF08",c.todayCards?.length||0,"\uFF09"]}),c.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:c.todayCards.map(s=>(0,e.jsx)(Ne,{title:s.title,kind:s.kind,updated:s.updated,path:s.path},s.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})]})]}),i==="optimize"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("organizeTitle")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:$,children:V==="scan"?t("exporting"):"\u{1F50D} "+t("scanAndOrganize")}),S&&S.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:async()=>{if(window.confirm(t("oneClickOptimizeConfirm"))){F("oneclick");try{let s=JSON.stringify({cleanupStale:Ie}),I=await(await fetch(`${E}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:s})).json();I&&I.ok?(notify(`${t("oneClickOptimizeDone")}\uFF1A${I.plan.merged} ${t("optimizedMerged")}${Ie?` \xB7 ${I.plan.staleDeleted} ${t("optimizedStaleDeleted")}`:""}`),await X(),r&&r(),O(null)):notify(t("mergeFail"),!1)}catch{notify(t("mergeFail"),!1)}finally{F("")}}},children:V==="oneclick"?t("exporting"):"\u26A1 "+t("oneClickOptimize")}),S&&S.merge?.length>0&&(0,e.jsxs)("label",{style:{fontSize:11,opacity:.7,display:"flex",alignItems:"center",gap:4},children:[(0,e.jsx)("input",{type:"checkbox",checked:Ie,onChange:s=>G(s.target.checked)}),t("oneClickAlsoStale")]})]}),!S&&(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:t("scanHint")}),S&&(0,e.jsx)(e.Fragment,{children:(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",flexDirection:"column",gap:8},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("mergePairs")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),S.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:ge,children:t(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("mergePairs")}),S.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:S.merge.map((s,N)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s.a.title," \u21C4 ",s.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(s.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>Be(s.a.path,s.b.path),children:t("mergeNow")})]},N))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:t("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[t("staleCards"),"\uFF08",S.stale?.length||0,"\uFF09"]}),S.stale?.length>0&&(0,e.jsx)("div",{style:{marginBottom:6},children:(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!V,onClick:async()=>{if(!window.confirm(t("deleteConfirm")))return;F("clean");let s=0;for(let N of S.stale)try{await fetch(`${E}/delete?path=${encodeURIComponent(N.path)}`),s++}catch{}F(""),notify(`${s} ${t("deletedStale")}`),await X(),r&&r()},children:t("cleanStale")})}),S.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:S.stale.map(s=>(0,e.jsx)(Ne,{title:s.title,kind:"other",updated:s.updated,path:s.path},s.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginBottom:6},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F9ED} ",t("refineTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:Ae,children:t(V==="refine"?"exporting":"refineScan")}),(0,e.jsx)("span",{style:{opacity:.6,fontSize:11},children:t("refineHint")})]}),le?.findings?.length?le.findings.map((s,N)=>(0,e.jsxs)("div",{style:{borderTop:N?"1px solid rgba(127,127,127,0.14)":"none",padding:"7px 2px"},children:[(0,e.jsxs)("div",{style:{fontSize:12,marginBottom:3},children:[(0,e.jsx)("span",{style:{fontWeight:700,color:s.relation==="conflict"?"#ef4444":s.relation==="duplicate"?"#f59e0b":"#10b981"},children:t("refineRel_"+s.relation)}),(0,e.jsxs)("span",{style:{opacity:.55},children:[" \xB7 sim ",s.sim," \xB7 ",s.useModel||""]}),s.conflict?(0,e.jsx)("span",{style:{marginLeft:6},children:s.conflict}):null]}),(0,e.jsxs)("div",{style:{fontSize:12,opacity:.85,marginBottom:5},children:["A\uFF1A",s.a.title,(0,e.jsx)("br",{}),"B\uFF1A",s.b.title]}),(0,e.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>xe(s,"keepA"),children:t("refineKeepA")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>xe(s,"keepB"),children:t("refineKeepB")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>xe(s,"keepBoth"),children:t("refineKeepBoth")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>xe(s,"merge"),children:t("refineMerge")})]})]},N)):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t(le?"refineNone":"refineIdle")})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginBottom:6},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F9F9} ",t("junkTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:Re,children:t(V==="junk"?"exporting":"junkScan")}),y?.length?(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:()=>h(y.map(s=>s.path)),children:t(V==="junkpurge"?"exporting":"junkRecycleAll")}):null,(0,e.jsx)("span",{style:{opacity:.6,fontSize:11},children:t("junkHint")})]}),y?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:y.map((s,N)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 2px",borderTop:N?"1px solid rgba(127,127,127,0.14)":"none",fontSize:12},children:[(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s.reasons.join("\uFF1B"),children:s.title||s.path}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:s.reasons[0]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>h([s.path]),children:t("junkRecycle")})]},N))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t(y?"junkNone":"junkIdle")})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginBottom:6},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F3AF} ",t("goalTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!V,onClick:ye,children:t(V==="goals"?"exporting":"goalScan")}),U?(0,e.jsxs)("span",{style:{opacity:.6,fontSize:11},children:[t("goalStats"),"\uFF1A",U.cached," / ",U.calls]}):null,(0,e.jsx)("span",{style:{opacity:.6,fontSize:11},children:t("goalHint")})]}),U?.clusters?.length?U.clusters.map((s,N)=>(0,e.jsxs)("div",{style:{borderTop:N?"1px solid rgba(127,127,127,0.14)":"none",padding:"7px 2px"},children:[(0,e.jsxs)("div",{style:{fontSize:12,marginBottom:4},children:[(0,e.jsx)("b",{children:s.goal})," ",(0,e.jsxs)("span",{style:{opacity:.55},children:["\xB7 ",s.members.length," ",t("goalCards")]})]}),(0,e.jsx)("ul",{style:{margin:"0 0 5px",padding:"0 0 0 16px",fontSize:12,opacity:.85},children:s.members.map((I,Z)=>(0,e.jsx)("li",{children:I.title},Z))}),(0,e.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>ee(s),children:t("goalKeep")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!V,onClick:()=>J(s),children:t("goalMerge")})]})]},N)):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t(U?"goalNone":"goalIdle")})]})]})]})]})}var It=[{key:"decision",label:"tplDecision",kind:"knowledge",tagKey:"tplDecisionTags",bodyKey:"tplDecisionBody"},{key:"bug",label:"tplBug",kind:"mistake",tagKey:"tplBugTags",bodyKey:"tplBugBody"},{key:"meeting",label:"tplMeeting",kind:"content",tagKey:"tplMeetingTags",bodyKey:"tplMeetingBody"},{key:"weekly",label:"tplWeekly",kind:"content",tagKey:"tplWeeklyTags",bodyKey:"tplWeeklyBody"}];function Fa({t,newCard:i,setNewCard:r,onCreated:g}){if(!i)return null;let c=It.find(x=>x.key===i.template),l=i.body||(c?t(c.bodyKey):""),C=i.kind||(c?c.kind:"knowledge"),R=i.tags||(c?t(c.tagKey):""),S=i._creating,O=x=>{let m=It.find(z=>z.key===x);r(z=>({...z,template:x,kind:m?m.kind:z.kind,body:m?t(m.bodyKey):z.body,tags:m?t(m.tagKey):z.tags}))},k=async()=>{if(!(!i.title&&!l)){r(x=>({...x,_creating:!0}));try{(await fetch(`${E}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:i.title||t("untitled"),kind:C,tags:R.split(",").map(m=>m.trim()).filter(Boolean),body:l,source:"manual"})}).then(m=>m.json())).ok?(r(null),g&&g()):r(m=>({...m,_creating:!1}))}catch{r(m=>({...m,_creating:!1}))}}};return(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>r(null),children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:x=>x.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:t("newCard")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>r(null),children:t("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10,overflow:"auto"},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[It.map(x=>(0,e.jsx)("button",{type:"button",className:`mc-btn${i.template===x.key?" me-on":""}`,onClick:()=>O(x.key),children:t(x.label)},x.key)),(0,e.jsx)("button",{type:"button",className:`mc-btn${i.template===""?" me-on":""}`,onClick:()=>r(x=>({...x,template:"",body:"",tags:"",kind:"knowledge"})),children:t("tplBlank")})]}),(0,e.jsx)("select",{className:"mc-btn",value:C,onChange:x=>r(m=>({...m,kind:x.target.value})),style:{maxWidth:180,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:["project","knowledge","content","prompt","business","tool","mistake"].map(x=>(0,e.jsx)("option",{value:x,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:x},x))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("cardTitle"),value:i.title||"",onChange:x=>r(m=>({...m,title:x.target.value}))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("tagsHint"),value:R,onChange:x=>r(m=>({...m,tags:x.target.value}))}),(0,e.jsx)("textarea",{className:"mc-btn",placeholder:t("cardBody"),value:l,onChange:x=>r(m=>({...m,body:x.target.value})),style:{minHeight:180,resize:"vertical",fontFamily:"inherit"}}),(0,e.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:S,onClick:k,children:t(S?"exporting":"createCard")})})]})]})]})}async function Xt(t){let i=String(t||"");if(!i)return!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(i),!0}catch{}try{let r=document.createElement("textarea");r.value=i,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();let g=!!(document.execCommand&&document.execCommand("copy"));return document.body.removeChild(r),g}catch{return!1}}function Pa({t,onClose:i}){let[r,g]=(0,o.useState)(""),[c,l]=(0,o.useState)(""),[C,R]=(0,o.useState)(""),[S,O]=(0,o.useState)(!0),[k,x]=(0,o.useState)(!1),[m,z]=(0,o.useState)(""),[T,w]=(0,o.useState)(""),j=(0,o.useRef)(null),L=(0,o.useRef)(null),K=()=>{let $=j.current;if($)try{$.focus(),$.select()}catch{}},te=$=>{z($),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>z(""),2400)};(0,o.useEffect)(()=>{let $=!0;return fetch(E+"/diagnostics").then(le=>le.json()).then(le=>{$&&(le&&le.ok?(l(String(le.diagnostics||"")),R(String(le.version||""))):x(!0))}).catch(()=>{$&&x(!0)}).finally(()=>{$&&O(!1)}),()=>{$=!1}},[]),(0,o.useEffect)(()=>{let $=le=>{le.key==="Escape"&&i()};return window.addEventListener("keydown",$),()=>{window.removeEventListener("keydown",$),L.current&&clearTimeout(L.current)}},[i]);let V=(()=>{try{return String(navigator.language||"").toLowerCase().startsWith("en")?"en":"zh"}catch{return"zh"}})(),F=()=>{let $=r.trim().split(`
337
- `)[0]||"",le=$t({title:"[Bug] "+($.slice(0,60)||"memory-eternal \u95EE\u9898"),body:_t({description:r,diagnostics:c,version:C})});try{window.open(le,"_blank","noopener")}catch{te(t("fbCopyFail"))}},Ie=async()=>{await Xt(c)?(w(""),te(t("fbCopiedDiag"))):(w(c),te(t("fbCopyManual")))},G=async()=>{let $=Ut({lang:V,description:r,diagnostics:c});await Xt($)?(w(""),te(t("fbCopiedPrompt"))):(w($),te(t("fbCopyManual")))},ge={width:"100%",resize:"vertical",padding:"8px 10px",borderRadius:10,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:13},X={margin:0,maxHeight:170,overflow:"auto",fontSize:11.5,lineHeight:1.55,padding:"8px 10px",borderRadius:10,background:"var(--dsw-alias-bg-layer-1, rgba(127,127,127,0.08))",whiteSpace:"pre-wrap"};return(0,e.jsxs)("div",{className:"me-overlay",onClick:i,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720},onClick:$=>$.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("h3",{children:["\u{1F41E} ",t("fbTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:i,children:t("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10},children:[(0,e.jsx)("div",{style:{fontSize:12,opacity:.72,lineHeight:1.6},children:t("fbWhy")}),(0,e.jsx)("textarea",{value:r,onChange:$=>g($.target.value),placeholder:t("fbDesc"),rows:5,style:ge}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("fbDiag")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:Ie,disabled:!c,children:t("fbCopyDiag")})]}),(0,e.jsx)("pre",{style:X,children:S?t("fbLoading"):k?t("fbDiagFail"):c})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>{if(!r.trim()){te(t("fbNeedDesc"));return}F()},style:{borderColor:"var(--dsw-alias-brand-primary, #3b82f6)",color:"var(--dsw-alias-brand-primary, #3b82f6)",fontWeight:600},children:["\u{1F680} ",t("fbOpenIssue")]}),(0,e.jsx)("span",{style:{opacity:.5,fontSize:12},children:t("fbOr")}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:G,children:["\u{1F916} ",t("fbCopyPrompt")]})]}),m&&(0,e.jsx)("div",{style:{fontSize:12,color:"var(--dsw-alias-brand-primary, #3b82f6)"},children:m}),T&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,e.jsxs)("b",{style:{fontSize:12,color:"#b45309"},children:["\u26A0 ",t("fbCopyFail")]}),(0,e.jsx)("span",{style:{fontSize:11.5,opacity:.75},children:t("fbCopyManual")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:K,children:t("fbSelectAll")})]}),(0,e.jsx)("textarea",{ref:j,readOnly:!0,value:T,rows:7,style:ge})]})]})]})]})}function Ha({t,card:i,query:r,onClose:g,onDelete:c,onFeedback:l}){(0,o.useEffect)(()=>{let j=L=>{L.key==="Escape"&&g()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[g]);let{meta:C,body:R}=(0,o.useMemo)(()=>Ct(i.text||""),[i.text]),S=j=>{let L=C.find(([K])=>String(K).toLowerCase()===j);return L?L[1]:""},O=Wt(S("tags")),k=S("kind")||"knowledge",x=(S("status")||"approved").toLowerCase(),m=qe[k]||"#6B7280",z=(R||"").length>460,[T,w]=(0,o.useState)(!0);return(0,e.jsxs)("div",{className:"me-overlay",onClick:g,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",onClick:j=>j.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("h3",{children:[(0,e.jsx)("span",{style:{marginRight:6},children:vt[k]||"\u{1F4CE}"}),i.title]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[r&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!0),children:["\u{1F44D} ",t("fbUseful")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!1),children:["\u{1F44E} ",t("fbNotUseful")]})]}),z&&(0,e.jsx)("button",{type:"button",className:"mc-btn","aria-expanded":T,onClick:()=>w(j=>!j),children:t(T?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(t("deleteConfirm"))&&c&&c(i.path)},children:t("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:g,children:t("close")})]})]}),(0,e.jsxs)("div",{className:"md-meta",children:[(0,e.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:m,borderColor:m+"59",background:m+"1a"},children:[vt[k]||"\u{1F4CE}"," ",t(Ke[k]||"kindKnowledge")]}),(0,e.jsxs)("span",{className:"md-chip "+(x==="approved"?"md-chip-st-ok":x==="pending"?"md-chip-st-warn":"md-chip-st-bad"),children:[x==="approved"?"\u2705":x==="pending"?"\u23F3":"\u26D4"," ",t(x==="approved"?"statusApproved":x==="pending"?"statusPending":"statusRejected")]}),(Array.isArray(O)?O:[]).slice(0,8).map(j=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",j]},j)),!!S("updated")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F552} ",t("updated")," ",ut(S("updated"))]}),!!S("source")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F4E5} ",S("source")]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:T?{}:{maxHeight:300,overflow:"hidden"},onClick:T?void 0:j=>{j.stopPropagation(),w(!0)},children:(0,e.jsx)("div",{className:"md-doc",dangerouslySetInnerHTML:{__html:Dt(R)}})}),!T&&(0,e.jsxs)("div",{className:"md-collapsed-hint",onClick:j=>{j.stopPropagation(),w(!0)},children:[t("expand")," \u2304"]})]})]})}function Oa({t,onOpen:i,all:r,onAllChange:g,onMutate:c,active:l,visible:C}){let[R,S]=(0,o.useState)(null),[O,k]=(0,o.useState)(""),x=(0,o.useRef)(!1),m=(0,o.useRef)(0),z=(0,o.useRef)(t);z.current=t;let T=(0,o.useCallback)(async()=>{try{x.current=!1;let K=await(await fetch(`${E}/graph${r?"?all=1":""}`)).json();K.ok?(S(K),k(""),x.current=!0):(S(null),k(K.error||t("error")))}catch(L){k(String(L&&L.message?L.message:L))}},[r,t]);(0,o.useEffect)(()=>{if(!l||x.current)return;let L=!0;return fetch(`${E}/graph${r?"?all=1":""}`).then(K=>K.json()).then(K=>{L&&(K.ok?(S(K),k(""),x.current=!0):(S(null),k(K.error||t("error"))))}).catch(K=>{L&&k(String(K&&K.message?K.message:K))}),()=>{L=!1}},[r,t,l]),(0,o.useEffect)(()=>{C&&R&&m.current++},[C,R]);let w=(0,o.useCallback)(async L=>{try{let te=await(await fetch(`${E}/delete?path=${encodeURIComponent(L)}`)).json();return te&&te.ok?(await T(),c&&c(),!0):!1}catch{return!1}},[T]),j=(0,o.useCallback)(async L=>{if(!L||L.length<2)return!1;try{let K=await fetch(`${E}/merge?paths=${encodeURIComponent(L.join(","))}`).then(te=>te.json());return K&&K.ok?(await T(),c&&c(),!0):!1}catch{return!1}},[T,c]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:Ee}),O&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",O]}),!R&&!O&&(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}),R&&R.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:t("emptyGraph")}),R&&R.nodes.length>0&&(0,e.jsx)(Wa,{nodes:R.nodes,edges:R.edges,onOpen:i,onDelete:w,onMerge:j,t,all:r,onAllChange:g,countLabel:`${R.nodes.length} ${t("nodes")} \xB7 ${Ea(R.edges)} ${t("edges")}`,fitTrigger:m.current})]})}function Ea(t){let i=new Set;for(let r of t||[])i.add([r.source,r.target].sort().join("|"));return i.size}var pt={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function Wa({nodes:t,edges:i,onOpen:r,onDelete:g,onMerge:c,t:l,countLabel:C,all:R,onAllChange:S,fitTrigger:O}){let k=(0,o.useRef)(null),x=(0,o.useRef)(null),m=(0,o.useRef)(null),z=(0,o.useRef)(null),T=(0,o.useRef)(null),w=(0,o.useRef)(r);(0,o.useEffect)(()=>{w.current=r},[r]);let j=(0,o.useRef)(g);(0,o.useEffect)(()=>{j.current=g},[g]);let L=(0,o.useRef)(c);(0,o.useEffect)(()=>{L.current=c},[c]);let[K,te]=(0,o.useState)(""),[V,F]=(0,o.useState)(null),Ie=(0,o.useRef)("");(0,o.useEffect)(()=>{Ie.current=K.trim().toLowerCase()},[K]),(0,o.useEffect)(()=>{let p=m.current;if(!p)return;let d=K.trim().toLowerCase();if(!d)return;let _=p.nodes.find(se=>(se.name||"").toLowerCase().includes(d));_&&(m.current.selectedId=_.id,F(_.id),p.panX=p.w/2-_.x*p.zoom,p.panY=p.h/2-_.y*p.zoom,p.render&&p.render())},[K]);let[G,ge]=(0,o.useState)("all"),[X,$]=(0,o.useState)(!1),le=(0,o.useRef)("all"),[he,Ae]=(0,o.useState)(""),xe=(0,o.useRef)(""),[y,ue]=(0,o.useState)(!1),Re=(0,o.useRef)(!1),[h,U]=(0,o.useState)(null);(0,o.useEffect)(()=>{le.current=G},[G]),(0,o.useEffect)(()=>{xe.current=he},[he]),(0,o.useEffect)(()=>{Re.current=y},[y]);let re=(0,o.useMemo)(()=>{let p=new Map;for(let d of t)for(let _ of d.tags||[]){let se=String(_).trim();se&&p.set(se,(p.get(se)||0)+1)}return[...p.entries()].sort((d,_)=>_[1]-d[1]).slice(0,24).map(([d,_])=>({tag:d,n:_}))},[t]),ye=(()=>{let p=K.trim().toLowerCase();return!!p&&!t.some(d=>(d.title||d.name||"").toLowerCase().includes(p)||String(d.kind||"").toLowerCase().includes(p)||String(Ke[d.kind]||"").toLowerCase().includes(p))})();(0,o.useEffect)(()=>{let p=m.current;p&&p.wake&&p.wake()},[K]),(0,o.useEffect)(()=>{let p=m.current;p&&p.render&&p.render()},[G,he,y]);let ee=(0,o.useRef)(null),[J,Be]=(0,o.useState)([]),[Ce,Te]=(0,o.useState)(null),[Ne,s]=(0,o.useState)(!1),[N,I]=(0,o.useState)(null),[Z,ke]=(0,o.useState)(""),de=(0,o.useRef)(null),ae=(0,o.useRef)(null),Y=(p,d=!0)=>{de.current&&clearTimeout(de.current),I({msg:p,ok:d}),de.current=setTimeout(()=>I(null),1900)},We=p=>{ke(p),ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>ke(""),1600)};(0,o.useEffect)(()=>()=>{de.current&&clearTimeout(de.current),ae.current&&clearTimeout(ae.current)},[]);let je=(0,o.useMemo)(()=>t.reduce((p,d)=>(p[d.id]=d,p),{}),[t]);return(0,o.useEffect)(()=>{let p=k.current;if(!p||t.length===0)return;let d=p.getContext("2d");if(!d)return;let _=Math.max(1,window.devicePixelRatio||1),se=()=>document.documentElement.getAttribute("data-theme")==="dark",ce={};i.forEach(u=>{ce[u.source]=(ce[u.source]||0)+1,ce[u.target]=(ce[u.target]||0)+1});let fe=Math.max(1,...Object.values(ce)),a={nodes:t.map(u=>({id:u.id,name:u.title||"",type:u.kind||"other",r:9+Math.min(10,(ce[u.id]||0)/fe*8),x:0,y:0,vx:0,vy:0})),edges:i.map(u=>({sourceNodeId:u.source,targetNodeId:u.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:_,ctx:d,multi:[],marquee:null};a.domain=t,a.domainById=t.reduce((u,A)=>(u[A.id]=A,u),{}),a.nodes.forEach((u,A)=>{let M=A/a.nodes.length*Math.PI*2-Math.PI/2;u.x=Math.cos(M)*60,u.y=Math.sin(M)*60});let Pe=[...new Set(a.nodes.map(u=>u.type))];a.clustered=Pe.length>1,a.typeCenters={},Pe.forEach((u,A)=>{let M=A/Pe.length*Math.PI*2-Math.PI/2;a.typeCenters[u]={x:Math.cos(M)*160,y:Math.sin(M)*160}}),m.current=a;let Je=0,tt=0,nt=()=>{let u=p.clientWidth,A=p.clientHeight;a.w=u,a.h=A,p.width=u*_,p.height=A*_,d.setTransform(_,0,0,_,0,0),(Je===0||tt===0)&&u>0&&A>0&&a.tickCount>0&&requestAnimationFrame(()=>P()),Je=u,tt=A};nt();let ot=new ResizeObserver(nt);ot.observe(p.parentElement);let we=(u,A)=>u&&u.length>A?u.slice(0,A)+"\u2026":u,Ze=(u,A,M,H)=>{if(d.beginPath(),H==="rect")d.rect(u-M,A-M*.75,M*2,M*1.5);else if(H==="diamond")d.moveTo(u,A-M),d.lineTo(u+M,A),d.lineTo(u,A+M),d.lineTo(u-M,A),d.closePath();else if(H==="hexagon"){for(let q=0;q<6;q++){let pe=Math.PI/3*q-Math.PI/2,ne=u+M*Math.cos(pe),ze=A+M*Math.sin(pe);q===0?d.moveTo(ne,ze):d.lineTo(ne,ze)}d.closePath()}else d.arc(u,A,M,0,Math.PI*2)},b=new Map,n=(u,A)=>{let M=u+"|"+Math.round(A),H=b.get(M);if(!H){let q=parseInt(u.slice(1,3),16),pe=parseInt(u.slice(3,5),16),ne=parseInt(u.slice(5,7),16);H=d.createRadialGradient(-A*.3,-A*.3,0,0,0,A*1.2),H.addColorStop(0,"rgba("+Math.min(255,q+70)+","+Math.min(255,pe+70)+","+Math.min(255,ne+70)+",0.95)"),H.addColorStop(1,u),b.set(M,H)}return H},v=1.1,D=2,P=()=>{if(!a.nodes.length)return;let u=1/0,A=-1/0,M=1/0,H=-1/0;a.nodes.forEach($e=>{u=Math.min(u,$e.x),A=Math.max(A,$e.x),M=Math.min(M,$e.y),H=Math.max(H,$e.y)});let q=20,pe=A-u+q*2,ne=H-M+q*2,ze=Math.min(a.w/pe,a.h/ne),Qe=Math.pow(1/v,D);a.zoom=Math.max(.35,Math.min(1.8,ze*Qe)),a.panX=a.w/2-(u+A)/2*a.zoom,a.panY=a.h/2-(M+H)/2*a.zoom};z.current=P;let W=()=>{d.clearRect(0,0,a.w,a.h),a.searchTerm=Ie.current,a.kindFilter=le.current,a.timeMode=Re.current,a.tagFilter=xe.current;let u=a.tagFilter,A=a.kindFilter,M=f=>String(f||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");d.save(),d.strokeStyle=se()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",d.lineWidth=.5;for(let f=0;f<a.w;f+=24)d.beginPath(),d.moveTo(f,0),d.lineTo(f,a.h),d.stroke();for(let f=0;f<a.h;f+=24)d.beginPath(),d.moveTo(0,f),d.lineTo(a.w,f),d.stroke();d.restore(),d.save(),d.translate(a.panX,a.panY),d.scale(a.zoom,a.zoom);let H={};a.nodes.forEach(f=>H[f.id]=f);let q=a.nodes.length>40,pe=q?1.5:.55,ne=a.selectedId||a.hoverId,ze=Kt({panX:a.panX,panY:a.panY,zoom:a.zoom,w:a.w,h:a.h,margin:80}),Qe=(()=>{let f=(a.searchTerm||"").toLowerCase();if(!f)return null;let oe=[];for(let ie of a.nodes){let Me=(a.domainById[ie.id]||{}).kind||"other";if(((ie.name||"").toLowerCase().includes(f)||String(Ke[Me]||"").toLowerCase().includes(f)||String(Me).toLowerCase().includes(f))&&oe.push(ie.id),oe.length>200)break}return oe})(),$e=Vt(a.nodes,{limit:qt(a.nodes.length),focusId:ne,hoverId:a.hoverId,searchHits:Qe,degree:ce}),me=new Map,ve=(f,oe)=>{let ie=f+"|"+oe,be=me.get(ie);return be===void 0&&(d.font=f,be=d.measureText(oe).width,me.set(ie,be)),be},He=a.nodes.length<=250,_e=new Map;a.edges.forEach(f=>{let oe=H[f.sourceNodeId],ie=H[f.targetNodeId];if(!oe||!ie||!Nt(oe.x,oe.y,10,ze)&&!Nt(ie.x,ie.y,10,ze))return;if(A!=="all"){let rt=a.domainById[f.sourceNodeId]&&a.domainById[f.sourceNodeId].kind,Xe=a.domainById[f.targetNodeId]&&a.domainById[f.targetNodeId].kind;if(rt!==A&&Xe!==A)return}if(u){let rt=a.domainById[f.sourceNodeId]&&(a.domainById[f.sourceNodeId].tags||[]).includes(u),Xe=a.domainById[f.targetNodeId]&&(a.domainById[f.targetNodeId].tags||[]).includes(u);if(!rt&&!Xe)return}let be=ie.x-oe.x,Me=ie.y-oe.y,Fe=Math.sqrt(be*be+Me*Me)||1,et=q?12:18,at=-Me/Fe*et,xt=be/Fe*et,kt=(oe.x+ie.x)/2+at,wt=(oe.y+ie.y)/2+xt,gt=pt.colors[a.domainById[oe.id]&&a.domainById[oe.id].kind||"other"],ft=ne&&(f.sourceNodeId===ne||f.targetNodeId===ne),Mt=ne?ft?.6:.08:q?.14:.24,Ge=parseInt(gt.slice(1,3),16),yt=parseInt(gt.slice(3,5),16),Tt=parseInt(gt.slice(5,7),16),Ve=ft?1.6+(f.weight||1):.8+(f.weight||1)*.5,it=Ge+","+yt+","+Tt+","+Mt+","+Ve,Ue=_e.get(it);Ue||(Ue={path:new Path2D,stroke:"rgba("+Ge+","+yt+","+Tt+","+Mt+")",width:Ve},_e.set(it,Ue)),Ue.path.moveTo(oe.x,oe.y),Ue.path.quadraticCurveTo(kt,wt,ie.x,ie.y)}),_e.forEach(f=>{d.strokeStyle=f.stroke,d.lineWidth=f.width,d.stroke(f.path)});let Oe=null;ne&&(Oe=new Set,a.edges.forEach(f=>{f.sourceNodeId===ne?Oe.add(f.targetNodeId):f.targetNodeId===ne&&Oe.add(f.sourceNodeId)}));let Ye=[];if(a.nodes.forEach(f=>{if(!Nt(f.x,f.y,f.r+2,ze))return;let oe=a.domainById[f.id]||{},ie=oe.kind||"other",be=a.timeMode?$a(oe.updated):pt.colors[ie],Me=pt.shapes[ie],Fe=a.selectedId===f.id,et=a.hoverId===f.id,at=a.searchTerm||"",xt=!at||(f.name||"").toLowerCase().includes(at)||String(Ke[ie]||"").toLowerCase().includes(at)||String(ie).toLowerCase().includes(at),kt=A==="all"||ie===A,wt=!u||(oe.tags||[]).includes(u),gt=ne&&f.id!==ne&&!(Oe&&Oe.has(f.id))||at&&!xt||!kt||!wt;d.save(),d.globalAlpha=gt?.08:1,(Fe||et)&&He&&(d.shadowColor=be,d.shadowBlur=Fe?20:14),d.translate(f.x,f.y),Ze(0,0,f.r,Me),d.fillStyle=n(be,f.r),d.fill(),d.restore(),Fe?(d.save(),Ze(f.x,f.y,f.r+3,Me),d.strokeStyle=be,d.lineWidth=3,d.shadowColor=be,d.shadowBlur=12,d.stroke(),d.restore()):et?(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle=be,d.lineWidth=2,d.stroke(),d.restore()):at&&xt?(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle="#e11d48",d.lineWidth=2,d.stroke(),d.restore()):a.multi.indexOf(f.id)>=0&&(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle="#60a5fa",d.lineWidth=2,d.shadowColor="#60a5fa",d.shadowBlur=8,d.stroke(),d.restore());let ft=we(f.name,16);if((Fe||et||$e.has(f.id)&&a.zoom>pe||!q&&a.zoom>.6)&&kt&&wt){let Ge=1/a.zoom,yt="500 "+(12*Ge).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";d.font=yt;let Ve=ve(yt,ft)+16*Ge,it=18*Ge,Ue=f.y+f.r+8*Ge,rt=!0;for(let Xe of Ye)if(f.x-Ve/2<Xe.x+Xe.w&&f.x+Ve/2>Xe.x&&Ue<Xe.y+Xe.h&&Ue+it>Xe.y){rt=!1;break}if(!rt&&!Fe&&!et)return;Ye.push({x:f.x-Ve/2,y:Ue,w:Ve,h:it}),d.fillStyle=se()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",d.beginPath(),d.roundRect?d.roundRect(f.x-Ve/2,Ue,Ve,it,4*Ge):d.rect(f.x-Ve/2,Ue,Ve,it),d.fill(),d.strokeStyle=se()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",d.lineWidth=1*Ge,d.stroke(),d.fillStyle=se()?Fe||et?"#eee":"#bbb":Fe||et?"#111":"#444",d.textAlign="center",d.fillText(ft,f.x,Ue+13*Ge)}}),d.restore(),a.marquee){let f=a.marquee,oe=Math.min(f.sx,f.ex),ie=Math.min(f.sy,f.ey),be=Math.abs(f.ex-f.sx),Me=Math.abs(f.ey-f.sy);d.save(),d.setLineDash([4,4]),d.strokeStyle="rgba(96,165,250,0.9)",d.lineWidth=1,d.fillStyle="rgba(96,165,250,0.12)",d.fillRect(oe,ie,be,Me),d.strokeRect(oe,ie,be,Me),d.restore()}if(a.hoverId&&ee.current){let f=a.domainById[a.hoverId],oe=a.nodes.find(function(ie){return ie.id===a.hoverId});if(f&&oe){let ie=a.edges.filter(function(Fe){return Fe.sourceNodeId===f.id||Fe.targetNodeId===f.id}).length,be=oe.x*a.zoom+a.panX,Me=oe.y*a.zoom+a.panY;ee.current.style.display="block",ee.current.style.left=be+14+"px",ee.current.style.top=Me-6+"px",ee.current.innerHTML="<b>"+M(f.title||f.name||"")+'</b><br/><span style="opacity:.8">'+M(f.kind||"")+" \xB7 "+tRef.current("connCount").replace("{n}",ie)+"</span>"}}else ee.current&&(ee.current.style.display="none")},B=()=>{a.running=!0,a.raf||(a.raf=requestAnimationFrame(Se))};a.wake=B,a.render=W;let Q=()=>{let u=a.nodes.length;a.tickCount++;let M=.9-Math.min(.4,a.tickCount/1500),H=u>1e3?3e3:u>100?2e3:u>50?1200:800,q=u>100?.002:.005,pe=u>1e3?.012:u>100?.005:.01,ne=u>1e3?6:u>200?12:24,ze={};a.nodes.forEach(me=>ze[me.id]=me);for(let me=0;me<u;me++){if(a.dragNode===a.nodes[me])continue;let ve=a.nodes[me],He=0,_e=0;for(let f=0;f<u;f++){if(me===f)continue;let oe=ve.x-a.nodes[f].x,ie=ve.y-a.nodes[f].y,be=Math.sqrt(oe*oe+ie*ie)||1,Me=H/(be*be);He+=oe/be*Me,_e+=ie/be*Me}if(a.clustered&&a.typeCenters[ve.type]){let f=a.typeCenters[ve.type];He+=(f.x-ve.x)*.006,_e+=(f.y-ve.y)*.006}else He-=ve.x*pe,_e-=ve.y*pe;let Oe=(ve.vx+He)*M,Ye=(ve.vy+_e)*M;Oe=Math.max(-ne,Math.min(ne,Oe)),Ye=Math.max(-ne,Math.min(ne,Ye)),ve.vx=Oe,ve.vy=Ye}a.edges.forEach(me=>{let ve=ze[me.sourceNodeId],He=ze[me.targetNodeId];if(!ve||!He)return;let _e=He.x-ve.x,Oe=He.y-ve.y,Ye=Math.sqrt(_e*_e+Oe*Oe)||1,f=(Ye-100)*q,oe=_e/Ye*f,ie=Oe/Ye*f;a.dragNode!==ve&&(ve.vx+=oe,ve.vy+=ie),a.dragNode!==He&&(He.vx-=oe,He.vy-=ie)});let Qe=0;a.nodes.forEach(me=>{a.dragNode!==me&&(me.x+=me.vx,me.y+=me.vy,Qe+=me.vx*me.vx+me.vy*me.vy)}),a.autoFitPending&&a.tickCount>45&&(a.autoFitPending=!1,P()),(u?Math.sqrt(Qe/u):0)<.05&&a.tickCount>60&&!a.dragNode?a.quietTicks=(a.quietTicks|0)+1:a.quietTicks=0},Se=()=>{if(a.running){try{Q(),W()}catch{}if(a.quietTicks>30){a.raf=0;return}a.raf=requestAnimationFrame(Se)}},De=(u,A)=>{let M=p.getBoundingClientRect();return{x:(u-M.left-a.panX)/a.zoom,y:(A-M.top-a.panY)/a.zoom}},Le=u=>{let A=a.domainById[u];return!(!A||le.current!=="all"&&A.kind!==le.current||xe.current&&!(A.tags||[]).includes(xe.current))},lt=(u,A,M)=>Math.max(A,Math.min(M,u)),Bt=u=>{a.mouseX=u.clientX,a.mouseY=u.clientY;let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+36){M=q.id;break}}M!==a.hoverId&&(a.hoverId=M,B())},Lt=u=>{if(u.button!==0)return;let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+25){M=q;break}}if(u.shiftKey){if(M){a.shiftClick=M.id;return}a.marquee={sx:u.clientX,sy:u.clientY,ex:u.clientX,ey:u.clientY};return}a.dragStart={x:u.clientX,y:u.clientY,px:a.panX,py:a.panY},a.dragging=!1,a.dragNode=M||null,M&&(a.dragOffset={dx:M.x-A.x,dy:M.y-A.y})},jt=u=>{if(a.marquee){a.marquee.ex=u.clientX,a.marquee.ey=u.clientY,B();return}if(!a.dragStart)return;let A=u.clientX-a.dragStart.x,M=u.clientY-a.dragStart.y;if(Math.abs(A)+Math.abs(M)>3&&(a.dragging=!0),a.dragNode){let H=De(u.clientX,u.clientY);a.dragNode.x=H.x+a.dragOffset.dx,a.dragNode.y=H.y+a.dragOffset.dy,B()}else a.dragging&&(a.panX=lt(a.dragStart.px+A,-1e5,1e5),a.panY=lt(a.dragStart.py+M,-1e5,1e5),B())},Ft=u=>{if(a.marquee){let M=a.marquee;a.marquee=null;let H=p.getBoundingClientRect(),q=Math.min(M.sx,M.ex)-H.left,pe=Math.max(M.sx,M.ex)-H.left,ne=Math.min(M.sy,M.ey)-H.top,ze=Math.max(M.sy,M.ey)-H.top,Qe=a.nodes.filter($e=>{let me=$e.x*a.zoom+a.panX,ve=$e.y*a.zoom+a.panY;return me>=q&&me<=pe&&ve>=ne&&ve<=ze}).map($e=>$e.id);a.multi=Qe,Be(Qe),B();return}let A=a.dragStart&&!a.dragging;if(a.shiftClick){let M=a.shiftClick;a.shiftClick=null;let H=Array.isArray(a.multi)?a.multi.slice():[];H.includes(M)||H.push(M),a.multi=H,Be(H),B();return}if(A){let M=De(u.clientX,u.clientY),H=null;for(let q=a.nodes.length-1;q>=0;q--){let pe=a.nodes[q];if(!Le(pe.id))continue;let ne=pe.x-M.x,ze=pe.y-M.y;if(ne*ne+ze*ze<pe.r*pe.r+20){H=pe;break}}H?(a.selectedId=H.id,F(H.id),B()):(a.selectedId=null,a.hoverId=null,u.shiftKey||(a.multi=[],Be([])),F(null),B())}a.dragStart=null,a.dragging=!1,a.dragNode=null},Pt=u=>{u.preventDefault();let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+25){M=q;break}}if(M){let H=a.domainById[M.id];H&&U({x:u.clientX,y:u.clientY,id:M.id,path:H.id,title:H.title})}else U(null)},Ht=u=>{u.preventDefault();let A=p.getBoundingClientRect(),M=(u.clientX-A.left-a.panX)/a.zoom,H=(u.clientY-A.top-a.panY)/a.zoom,q=Math.max(.3,Math.min(3,a.zoom*(u.deltaY<0?v:1/v)));a.panX=lt(a.panX+M*(a.zoom-q),-1e5,1e5),a.panY=lt(a.panY+H*(a.zoom-q),-1e5,1e5),a.zoom=q,B()};p.addEventListener("mousemove",Bt),p.addEventListener("mousedown",Lt),window.addEventListener("mousemove",jt),window.addEventListener("mouseup",Ft),p.addEventListener("wheel",Ht,{passive:!1}),p.addEventListener("contextmenu",Pt),T.current=()=>{a.selectedId=null,a.hoverId=null,a.multi=[],Be([]),P(),B()};for(let u=0;u<200;u++)Q();P(),B();let Ot=()=>$(!1);return window.addEventListener("mousedown",Ot),()=>{a.running=!1,a.raf&&cancelAnimationFrame(a.raf),ot.disconnect(),p.removeEventListener("mousemove",Bt),p.removeEventListener("mousedown",Lt),window.removeEventListener("mousemove",jt),window.removeEventListener("mouseup",Ft),p.removeEventListener("wheel",Ht),p.removeEventListener("contextmenu",Pt),window.removeEventListener("mousedown",Ot)}},[t,i]),(0,o.useEffect)(()=>{O!==void 0&&z.current&&requestAnimationFrame(()=>z.current())},[O]),(0,e.jsxs)("div",{className:"me-graph",ref:x,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[t.length," ",l("nodes")," \xB7 ",i.length," ",l("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",placeholder:l("search"),value:K,onChange:p=>te(p.target.value)}),(0,e.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>$(p=>!p),"aria-expanded":X,title:l("filterLabel"),style:{borderRadius:8},children:["\u{1F50D} ",l("filterLabel")," ",G!=="all"||y||he?"\u25CF":"\u25BE"]}),X&&(0,e.jsx)("div",{className:"me-graph-legend-pop",onMouseDown:p=>p.stopPropagation(),style:{position:"absolute",top:"calc(100% + 6px)",left:0,zIndex:50,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,padding:8,minWidth:240,boxShadow:"0 12px 34px rgba(0,0,0,.35)"},children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,e.jsx)("button",{type:"button",className:`lg${G==="all"&&!y?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>{ge("all"),ue(!1)},children:l("all")}),Object.keys(qe).map(p=>(0,e.jsxs)("button",{type:"button",className:`lg${G===p?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>ge(d=>d===p?"all":p),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:pt.colors[p]||qe[p]}}),l(Ke[p])]},p)),(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsxs)("button",{type:"button",className:`lg${y?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>ue(p=>!p),children:["\u23F1 ",l("timeDim")]}),re.length>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsx)("div",{style:{maxHeight:130,overflow:"auto",display:"flex",flexWrap:"wrap",gap:4},children:re.map(p=>(0,e.jsxs)("button",{type:"button",className:`lg${he===p.tag?" active":""}`,style:{color:"#ddd",padding:"2px 7px",fontSize:11},onClick:()=>Ae(d=>d===p.tag?"":p.tag),title:p.tag,children:["#",p.tag," ",(0,e.jsx)("span",{style:{opacity:.55},children:p.n})]},p.tag))})]}),(G!=="all"||y||he)&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",style:{justifyContent:"flex-start",color:"#f87171"},onClick:()=>{ge("all"),ue(!1),Ae("")},children:[l("clearFilter")," \u2715"]})]})})]}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:l("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:!!R,onChange:p=>S&&S(p.target.checked)}),l("crossVault")]}),(0,e.jsx)("button",{type:"button",className:`mc-btn${y?" me-on":""}`,onClick:()=>ue(p=>!p),children:l("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=k.current;if(p)try{p.toBlob(d=>{d&&Te({url:URL.createObjectURL(d),blob:d})},"image/png")}catch{}},children:l("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>z.current&&z.current(),children:l("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{F(null),ge("all"),T.current&&T.current()},children:l("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:k,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:ee,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:l("noMatch")}),h&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>U(null)}),h&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:h.x,top:h.y,zIndex:31},onMouseDown:p=>p.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{w.current({path:h.path,title:h.title}),U(null)},children:l("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{h.id&&(m.current.selectedId=h.id,F(h.id)),U(null);let p=m.current;p&&p.wake&&p.wake()},children:l("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(h.title||"")}catch{}U(null),Y(l("copied"))},children:l("copyName")}),(0,e.jsx)("button",{type:"button",onClick:()=>{let p=m.current,d=p&&Array.isArray(p.multi)?p.multi.slice():[],_=h.id;if(_&&!d.includes(_)&&d.push(_),U(null),d.length<2){Y(l("mergeNeed"),!1);return}if(!window.confirm(l("mergeConfirm")))return;let se=L.current&&L.current(d);se&&se.then?se.then(ce=>ce?Y(l("merged")):Y(l("mergeFail"),!1)).catch(()=>Y(l("mergeFail"),!1)):se&&Y(l("merged"))},children:l("merge")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let p=h.path;U(null),window.confirm(l("deleteConfirm"))&&(async()=>{try{(j.current?await j.current(p):!1)?Y(l("deleted")):Y(l("deleteFail"),!1)}catch{Y(l("deleteFail"),!1)}})()},children:l("delete")})]}),J.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[J.length," ",l("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let d=J.map(fe=>je[fe]).filter(Boolean).map(fe=>fe.title||fe.name).join(`
338
- `),_=new Blob([d],{type:"text/plain;charset=utf-8"}),se=URL.createObjectURL(_),ce=document.createElement("a");ce.href=se,ce.download="memory-selected.txt",document.body.appendChild(ce),ce.click(),document.body.removeChild(ce),setTimeout(()=>URL.revokeObjectURL(se),1e3),Y(J.length+l("exportedSel"))},children:l("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(J.length<2){Y(l("mergeNeed"),!1);return}let p=J.map(_=>je[_]?je[_].id:_);if(!window.confirm(l("mergeConfirm")))return;Be([]);let d=m.current;d&&(d.multi=[]),fetch(`${E}/merge?paths=${encodeURIComponent(p.join(","))}`).then(_=>_.json()).then(_=>{_&&_.ok?Y(l("merged")):Y(l("mergeFail"),!1)}).catch(()=>Y(l("mergeFail"),!1))},children:l("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(l("deleteConfirm")))return;let p=J.map(_=>je[_]?je[_].id:_);Be([]);let d=m.current;d&&(d.multi=[]),(async()=>{let _=0;for(let se of p)try{(j.current?await j.current(se):!1)&&_++}catch{}Y(_+l("deletedSelected"),_>0)})()},children:l("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=m.current;p&&(p.multi=[]),Be([]);let d=m.current;d&&d.render&&d.render()},children:l("clearSelection")})]}),V&&(0,e.jsxs)("div",{className:"me-graph-sidebar",style:{position:"absolute",right:10,top:10,zIndex:3,maxWidth:240,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:12,fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:je[V]?je[V].title||je[V].name:V}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:je[V]?l(Ke[je[V].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:l("graphHint")}),(i.filter(p=>p.source===V||p.target===V)||[]).slice(0,8).map((p,d)=>{let _=p.source===V?p.target:p.source,se=je[_];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:ce=>{ce.preventDefault();let fe=m.current;fe&&(fe.selectedId=_,fe.hoverId=_,fe.wake&&fe.wake()),F(_)},children:se?(se.title||se.name).slice(0,28):_},d)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:l("graphTip")}),N&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(N.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:N.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:N.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:N.msg})]}),Ce&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{Ce.url&&URL.revokeObjectURL(Ce.url),Te(null),s(!1)},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:Ne?"100vw":900,width:Ne?"100vw":"92vw",maxHeight:Ne?"100%":"90vh",height:Ne?"100%":void 0,borderRadius:Ne?0:14},onClick:p=>p.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:l("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:Ce.url,download:"memory-graph.png",onClick:()=>{We("download"),Y(l("downloaded")+" \xB7 "+l("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:l(Z==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{We("full"),s(p=>!p),Y(l("fullscreen"))},children:l(Z==="full"?"done":Ne?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=Ce.blob;p&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":p})]).then(()=>{We("copy"),Y(l("copied"))}).catch(()=>{Y(l("copyFail"),!1)}):Y(l("copyFail"),!1)},children:l(Z==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Ce.url&&URL.revokeObjectURL(Ce.url),Te(null),s(!1)},children:l("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:Ne?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:Ce.url,alt:l("exportGraph"),style:{maxWidth:"100%",maxHeight:Ne?"calc(100% - 64px)":"70vh",borderRadius:Ne?0:8,cursor:"zoom-in"},onClick:()=>s(p=>!p)})})]})]})]})}function $a(t){let i=new Date(t||0).getTime();if(!i)return"#94a3b8";let r=(Date.now()-i)/864e5;return r<3?"#10b981":r<14?"#f59e0b":r<30?"#f97316":"#94a3b8"}function Jt({label:t,value:i=[],options:r,onChange:g,placeholder:c,z:l=20}){let[C,R]=(0,o.useState)(!1),S=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!C)return;let w=j=>{S.current&&!S.current.contains(j.target)&&R(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[C]);let O=Array.isArray(i)?i:[],k=O.includes("__all__"),x=k?r.find(w=>w.value==="__all__")?.label||"":O.length?O.map(w=>r.find(j=>j.value===w)?.label||w).join("\u3001"):"",m=(w,j)=>{if(w.value==="__all__"){g(j?["__all__"]:[]);return}let L=new Set(O);L.has("__all__")&&L.delete("__all__"),j?L.add(w.value):L.delete(w.value),g([...L])},z=r.find(w=>w.value==="__all__"),T=r.filter(w=>w.value!=="__all__");return(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,e.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:t}),(0,e.jsxs)("div",{ref:S,style:{position:"relative",minWidth:0},children:[(0,e.jsxs)("button",{type:"button",onClick:()=>R(w=>!w),style:{width:"100%",textAlign:"left",padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[(0,e.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x||c||"\u2014"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.7},children:"\u25BE"})]}),C&&(0,e.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,right:0,zIndex:l,marginTop:2,borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",boxShadow:"0 6px 20px rgba(0,0,0,0.14)",maxHeight:180,overflow:"auto"},children:[z&&(0,e.jsxs)("label",{onClick:w=>w.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("input",{type:"checkbox",checked:k,onChange:w=>m(z,w.target.checked)}),(0,e.jsx)("span",{children:z.label})]}),T.map(w=>(0,e.jsxs)("label",{onClick:j=>j.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer"},children:[(0,e.jsx)("input",{type:"checkbox",checked:O.includes(w.value),onChange:j=>m(w,j.target.checked)}),(0,e.jsx)("span",{children:w.label})]},w.value))]})]})]})}function _a(t){let i=new Date(t||0).getTime();return!!i&&(Date.now()-i)/864e5<3}async function Ua(t,i,r){if(r&&typeof window.showSaveFilePicker=="function")try{let l=await window.showSaveFilePicker({suggestedName:i}),C=await l.createWritable();return await C.write(t),await C.close(),{ok:!0,picked:!0,name:l.name}}catch(l){return l&&l.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(l.message||l)}}let g=URL.createObjectURL(t),c=document.createElement("a");return c.href=g,c.download=i,document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(g),1e3),{ok:!0,picked:!1,name:i}}function Zt(t,i){if(!i||!t)return t;let r=t.toLowerCase(),g=i.toLowerCase(),c=[],l=0;for(;l<t.length;){let C=r.indexOf(g,l);if(C<0){c.push(t.slice(l));break}C>l&&c.push(t.slice(l,C)),c.push((0,e.jsx)("mark",{className:"mc-hl",children:t.slice(C,C+g.length)},C)),l=C+g.length}return c}function ut(t){if(!t)return"";let i=new Date(t);if(Number.isNaN(i.getTime()))return"";let r=new Date,g=i.toDateString()===r.toDateString(),c=C=>String(C).padStart(2,"0"),l=`${c(i.getHours())}:${c(i.getMinutes())}`;return g?l:`${i.getMonth()+1}-${i.getDate()} ${l}`}
345
+ `)[0]||"",le=$t({title:"[Bug] "+($.slice(0,60)||"memory-eternal \u95EE\u9898"),body:_t({description:r,diagnostics:c,version:C})});try{window.open(le,"_blank","noopener")}catch{te(t("fbCopyFail"))}},Ie=async()=>{await Xt(c)?(w(""),te(t("fbCopiedDiag"))):(w(c),te(t("fbCopyManual")))},G=async()=>{let $=Ut({lang:V,description:r,diagnostics:c});await Xt($)?(w(""),te(t("fbCopiedPrompt"))):(w($),te(t("fbCopyManual")))},ge={width:"100%",resize:"vertical",padding:"8px 10px",borderRadius:10,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:13},X={margin:0,maxHeight:170,overflow:"auto",fontSize:11.5,lineHeight:1.55,padding:"8px 10px",borderRadius:10,background:"var(--dsw-alias-bg-layer-1, rgba(127,127,127,0.08))",whiteSpace:"pre-wrap"};return(0,e.jsxs)("div",{className:"me-overlay",onClick:i,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720},onClick:$=>$.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("h3",{children:["\u{1F41E} ",t("fbTitle")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:i,children:t("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10},children:[(0,e.jsx)("div",{style:{fontSize:12,opacity:.72,lineHeight:1.6},children:t("fbWhy")}),(0,e.jsx)("textarea",{value:r,onChange:$=>g($.target.value),placeholder:t("fbDesc"),rows:5,style:ge}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("fbDiag")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:Ie,disabled:!c,children:t("fbCopyDiag")})]}),(0,e.jsx)("pre",{style:X,children:S?t("fbLoading"):k?t("fbDiagFail"):c})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>{if(!r.trim()){te(t("fbNeedDesc"));return}F()},style:{borderColor:"var(--dsw-alias-brand-primary, #3b82f6)",color:"var(--dsw-alias-brand-primary, #3b82f6)",fontWeight:600},children:["\u{1F680} ",t("fbOpenIssue")]}),(0,e.jsx)("span",{style:{opacity:.5,fontSize:12},children:t("fbOr")}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:G,children:["\u{1F916} ",t("fbCopyPrompt")]})]}),m&&(0,e.jsx)("div",{style:{fontSize:12,color:"var(--dsw-alias-brand-primary, #3b82f6)"},children:m}),T&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,e.jsxs)("b",{style:{fontSize:12,color:"#b45309"},children:["\u26A0 ",t("fbCopyFail")]}),(0,e.jsx)("span",{style:{fontSize:11.5,opacity:.75},children:t("fbCopyManual")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:K,children:t("fbSelectAll")})]}),(0,e.jsx)("textarea",{ref:j,readOnly:!0,value:T,rows:7,style:ge})]})]})]})]})}function Ha({t,card:i,query:r,onClose:g,onDelete:c,onFeedback:l}){(0,o.useEffect)(()=>{let j=L=>{L.key==="Escape"&&g()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[g]);let{meta:C,body:R}=(0,o.useMemo)(()=>Ct(i.text||""),[i.text]),S=j=>{let L=C.find(([K])=>String(K).toLowerCase()===j);return L?L[1]:""},O=Wt(S("tags")),k=S("kind")||"knowledge",x=(S("status")||"approved").toLowerCase(),m=qe[k]||"#6B7280",z=(R||"").length>460,[T,w]=(0,o.useState)(!0);return(0,e.jsxs)("div",{className:"me-overlay",onClick:g,children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",onClick:j=>j.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("h3",{title:i.title,children:[(0,e.jsx)("span",{style:{marginRight:6,flex:"none"},children:vt[k]||"\u{1F4CE}"}),i.title]}),(0,e.jsxs)("div",{className:"me-head-actions",children:[r&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!0),children:["\u{1F44D} ",t("fbUseful")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!1),children:["\u{1F44E} ",t("fbNotUseful")]})]}),z&&(0,e.jsx)("button",{type:"button",className:"mc-btn","aria-expanded":T,onClick:()=>w(j=>!j),children:t(T?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(t("deleteConfirm"))&&c&&c(i.path)},children:t("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:g,children:t("close")})]})]}),(0,e.jsxs)("div",{className:"md-meta",children:[(0,e.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:m,borderColor:m+"59",background:m+"1a"},children:[vt[k]||"\u{1F4CE}"," ",t(Ke[k]||"kindKnowledge")]}),(0,e.jsxs)("span",{className:"md-chip "+(x==="approved"?"md-chip-st-ok":x==="pending"?"md-chip-st-warn":"md-chip-st-bad"),children:[x==="approved"?"\u2705":x==="pending"?"\u23F3":"\u26D4"," ",t(x==="approved"?"statusApproved":x==="pending"?"statusPending":"statusRejected")]}),(Array.isArray(O)?O:[]).slice(0,8).map(j=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",j]},j)),!!S("updated")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F552} ",t("updated")," ",ut(S("updated"))]}),!!S("source")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F4E5} ",S("source")]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:T?{}:{maxHeight:300,overflow:"hidden"},onClick:T?void 0:j=>{j.stopPropagation(),w(!0)},children:(0,e.jsx)("div",{className:"md-doc",dangerouslySetInnerHTML:{__html:Dt(R)}})}),!T&&(0,e.jsxs)("div",{className:"md-collapsed-hint",onClick:j=>{j.stopPropagation(),w(!0)},children:[t("expand")," \u2304"]})]})]})}function Oa({t,onOpen:i,all:r,onAllChange:g,onMutate:c,active:l,visible:C}){let[R,S]=(0,o.useState)(null),[O,k]=(0,o.useState)(""),x=(0,o.useRef)(!1),m=(0,o.useRef)(0),z=(0,o.useRef)(t);z.current=t;let T=(0,o.useCallback)(async()=>{try{x.current=!1;let K=await(await fetch(`${E}/graph${r?"?all=1":""}`)).json();K.ok?(S(K),k(""),x.current=!0):(S(null),k(K.error||t("error")))}catch(L){k(String(L&&L.message?L.message:L))}},[r,t]);(0,o.useEffect)(()=>{if(!l||x.current)return;let L=!0;return fetch(`${E}/graph${r?"?all=1":""}`).then(K=>K.json()).then(K=>{L&&(K.ok?(S(K),k(""),x.current=!0):(S(null),k(K.error||t("error"))))}).catch(K=>{L&&k(String(K&&K.message?K.message:K))}),()=>{L=!1}},[r,t,l]),(0,o.useEffect)(()=>{C&&R&&m.current++},[C,R]);let w=(0,o.useCallback)(async L=>{try{let te=await(await fetch(`${E}/delete?path=${encodeURIComponent(L)}`)).json();return te&&te.ok?(await T(),c&&c(),!0):!1}catch{return!1}},[T]),j=(0,o.useCallback)(async L=>{if(!L||L.length<2)return!1;try{let K=await fetch(`${E}/merge?paths=${encodeURIComponent(L.join(","))}`).then(te=>te.json());return K&&K.ok?(await T(),c&&c(),!0):!1}catch{return!1}},[T,c]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:Ee}),O&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",O]}),!R&&!O&&(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}),R&&R.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:t("emptyGraph")}),R&&R.nodes.length>0&&(0,e.jsx)(Wa,{nodes:R.nodes,edges:R.edges,onOpen:i,onDelete:w,onMerge:j,t,all:r,onAllChange:g,countLabel:`${R.nodes.length} ${t("nodes")} \xB7 ${Ea(R.edges)} ${t("edges")}`,fitTrigger:m.current})]})}function Ea(t){let i=new Set;for(let r of t||[])i.add([r.source,r.target].sort().join("|"));return i.size}var pt={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function Wa({nodes:t,edges:i,onOpen:r,onDelete:g,onMerge:c,t:l,countLabel:C,all:R,onAllChange:S,fitTrigger:O}){let k=(0,o.useRef)(null),x=(0,o.useRef)(null),m=(0,o.useRef)(null),z=(0,o.useRef)(null),T=(0,o.useRef)(null),w=(0,o.useRef)(r);(0,o.useEffect)(()=>{w.current=r},[r]);let j=(0,o.useRef)(g);(0,o.useEffect)(()=>{j.current=g},[g]);let L=(0,o.useRef)(c);(0,o.useEffect)(()=>{L.current=c},[c]);let[K,te]=(0,o.useState)(""),[V,F]=(0,o.useState)(null),Ie=(0,o.useRef)("");(0,o.useEffect)(()=>{Ie.current=K.trim().toLowerCase()},[K]),(0,o.useEffect)(()=>{let p=m.current;if(!p)return;let d=K.trim().toLowerCase();if(!d)return;let _=p.nodes.find(se=>(se.name||"").toLowerCase().includes(d));_&&(m.current.selectedId=_.id,F(_.id),p.panX=p.w/2-_.x*p.zoom,p.panY=p.h/2-_.y*p.zoom,p.render&&p.render())},[K]);let[G,ge]=(0,o.useState)("all"),[X,$]=(0,o.useState)(!1),le=(0,o.useRef)("all"),[he,Ae]=(0,o.useState)(""),xe=(0,o.useRef)(""),[y,ue]=(0,o.useState)(!1),Re=(0,o.useRef)(!1),[h,U]=(0,o.useState)(null);(0,o.useEffect)(()=>{le.current=G},[G]),(0,o.useEffect)(()=>{xe.current=he},[he]),(0,o.useEffect)(()=>{Re.current=y},[y]);let re=(0,o.useMemo)(()=>{let p=new Map;for(let d of t)for(let _ of d.tags||[]){let se=String(_).trim();se&&p.set(se,(p.get(se)||0)+1)}return[...p.entries()].sort((d,_)=>_[1]-d[1]).slice(0,24).map(([d,_])=>({tag:d,n:_}))},[t]),ye=(()=>{let p=K.trim().toLowerCase();return!!p&&!t.some(d=>(d.title||d.name||"").toLowerCase().includes(p)||String(d.kind||"").toLowerCase().includes(p)||String(Ke[d.kind]||"").toLowerCase().includes(p))})();(0,o.useEffect)(()=>{let p=m.current;p&&p.wake&&p.wake()},[K]),(0,o.useEffect)(()=>{let p=m.current;p&&p.render&&p.render()},[G,he,y]);let ee=(0,o.useRef)(null),[J,Be]=(0,o.useState)([]),[Ce,Te]=(0,o.useState)(null),[Ne,s]=(0,o.useState)(!1),[N,I]=(0,o.useState)(null),[Z,ke]=(0,o.useState)(""),de=(0,o.useRef)(null),ae=(0,o.useRef)(null),Y=(p,d=!0)=>{de.current&&clearTimeout(de.current),I({msg:p,ok:d}),de.current=setTimeout(()=>I(null),1900)},We=p=>{ke(p),ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>ke(""),1600)};(0,o.useEffect)(()=>()=>{de.current&&clearTimeout(de.current),ae.current&&clearTimeout(ae.current)},[]);let je=(0,o.useMemo)(()=>t.reduce((p,d)=>(p[d.id]=d,p),{}),[t]);return(0,o.useEffect)(()=>{let p=k.current;if(!p||t.length===0)return;let d=p.getContext("2d");if(!d)return;let _=Math.max(1,window.devicePixelRatio||1),se=()=>document.documentElement.getAttribute("data-theme")==="dark",ce={};i.forEach(u=>{ce[u.source]=(ce[u.source]||0)+1,ce[u.target]=(ce[u.target]||0)+1});let fe=Math.max(1,...Object.values(ce)),a={nodes:t.map(u=>({id:u.id,name:u.title||"",type:u.kind||"other",r:9+Math.min(10,(ce[u.id]||0)/fe*8),x:0,y:0,vx:0,vy:0})),edges:i.map(u=>({sourceNodeId:u.source,targetNodeId:u.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:_,ctx:d,multi:[],marquee:null};a.domain=t,a.domainById=t.reduce((u,A)=>(u[A.id]=A,u),{}),a.nodes.forEach((u,A)=>{let M=A/a.nodes.length*Math.PI*2-Math.PI/2;u.x=Math.cos(M)*60,u.y=Math.sin(M)*60});let Pe=[...new Set(a.nodes.map(u=>u.type))];a.clustered=Pe.length>1,a.typeCenters={},Pe.forEach((u,A)=>{let M=A/Pe.length*Math.PI*2-Math.PI/2;a.typeCenters[u]={x:Math.cos(M)*160,y:Math.sin(M)*160}}),m.current=a;let Je=0,tt=0,nt=()=>{let u=p.clientWidth,A=p.clientHeight;a.w=u,a.h=A,p.width=u*_,p.height=A*_,d.setTransform(_,0,0,_,0,0),(Je===0||tt===0)&&u>0&&A>0&&a.tickCount>0&&requestAnimationFrame(()=>P()),Je=u,tt=A};nt();let ot=new ResizeObserver(nt);ot.observe(p.parentElement);let we=(u,A)=>u&&u.length>A?u.slice(0,A)+"\u2026":u,Ze=(u,A,M,H)=>{if(d.beginPath(),H==="rect")d.rect(u-M,A-M*.75,M*2,M*1.5);else if(H==="diamond")d.moveTo(u,A-M),d.lineTo(u+M,A),d.lineTo(u,A+M),d.lineTo(u-M,A),d.closePath();else if(H==="hexagon"){for(let q=0;q<6;q++){let pe=Math.PI/3*q-Math.PI/2,ne=u+M*Math.cos(pe),ze=A+M*Math.sin(pe);q===0?d.moveTo(ne,ze):d.lineTo(ne,ze)}d.closePath()}else d.arc(u,A,M,0,Math.PI*2)},b=new Map,n=(u,A)=>{let M=u+"|"+Math.round(A),H=b.get(M);if(!H){let q=parseInt(u.slice(1,3),16),pe=parseInt(u.slice(3,5),16),ne=parseInt(u.slice(5,7),16);H=d.createRadialGradient(-A*.3,-A*.3,0,0,0,A*1.2),H.addColorStop(0,"rgba("+Math.min(255,q+70)+","+Math.min(255,pe+70)+","+Math.min(255,ne+70)+",0.95)"),H.addColorStop(1,u),b.set(M,H)}return H},v=1.1,D=2,P=()=>{if(!a.nodes.length)return;let u=1/0,A=-1/0,M=1/0,H=-1/0;a.nodes.forEach($e=>{u=Math.min(u,$e.x),A=Math.max(A,$e.x),M=Math.min(M,$e.y),H=Math.max(H,$e.y)});let q=20,pe=A-u+q*2,ne=H-M+q*2,ze=Math.min(a.w/pe,a.h/ne),Qe=Math.pow(1/v,D);a.zoom=Math.max(.35,Math.min(1.8,ze*Qe)),a.panX=a.w/2-(u+A)/2*a.zoom,a.panY=a.h/2-(M+H)/2*a.zoom};z.current=P;let W=()=>{d.clearRect(0,0,a.w,a.h),a.searchTerm=Ie.current,a.kindFilter=le.current,a.timeMode=Re.current,a.tagFilter=xe.current;let u=a.tagFilter,A=a.kindFilter,M=f=>String(f||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");d.save(),d.strokeStyle=se()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",d.lineWidth=.5;for(let f=0;f<a.w;f+=24)d.beginPath(),d.moveTo(f,0),d.lineTo(f,a.h),d.stroke();for(let f=0;f<a.h;f+=24)d.beginPath(),d.moveTo(0,f),d.lineTo(a.w,f),d.stroke();d.restore(),d.save(),d.translate(a.panX,a.panY),d.scale(a.zoom,a.zoom);let H={};a.nodes.forEach(f=>H[f.id]=f);let q=a.nodes.length>40,pe=q?1.5:.55,ne=a.selectedId||a.hoverId,ze=Kt({panX:a.panX,panY:a.panY,zoom:a.zoom,w:a.w,h:a.h,margin:80}),Qe=(()=>{let f=(a.searchTerm||"").toLowerCase();if(!f)return null;let oe=[];for(let ie of a.nodes){let Me=(a.domainById[ie.id]||{}).kind||"other";if(((ie.name||"").toLowerCase().includes(f)||String(Ke[Me]||"").toLowerCase().includes(f)||String(Me).toLowerCase().includes(f))&&oe.push(ie.id),oe.length>200)break}return oe})(),$e=Vt(a.nodes,{limit:qt(a.nodes.length),focusId:ne,hoverId:a.hoverId,searchHits:Qe,degree:ce}),me=new Map,ve=(f,oe)=>{let ie=f+"|"+oe,be=me.get(ie);return be===void 0&&(d.font=f,be=d.measureText(oe).width,me.set(ie,be)),be},He=a.nodes.length<=250,_e=new Map;a.edges.forEach(f=>{let oe=H[f.sourceNodeId],ie=H[f.targetNodeId];if(!oe||!ie||!Nt(oe.x,oe.y,10,ze)&&!Nt(ie.x,ie.y,10,ze))return;if(A!=="all"){let rt=a.domainById[f.sourceNodeId]&&a.domainById[f.sourceNodeId].kind,Xe=a.domainById[f.targetNodeId]&&a.domainById[f.targetNodeId].kind;if(rt!==A&&Xe!==A)return}if(u){let rt=a.domainById[f.sourceNodeId]&&(a.domainById[f.sourceNodeId].tags||[]).includes(u),Xe=a.domainById[f.targetNodeId]&&(a.domainById[f.targetNodeId].tags||[]).includes(u);if(!rt&&!Xe)return}let be=ie.x-oe.x,Me=ie.y-oe.y,Fe=Math.sqrt(be*be+Me*Me)||1,et=q?12:18,at=-Me/Fe*et,xt=be/Fe*et,kt=(oe.x+ie.x)/2+at,wt=(oe.y+ie.y)/2+xt,gt=pt.colors[a.domainById[oe.id]&&a.domainById[oe.id].kind||"other"],ft=ne&&(f.sourceNodeId===ne||f.targetNodeId===ne),Mt=ne?ft?.6:.08:q?.14:.24,Ge=parseInt(gt.slice(1,3),16),yt=parseInt(gt.slice(3,5),16),Tt=parseInt(gt.slice(5,7),16),Ve=ft?1.6+(f.weight||1):.8+(f.weight||1)*.5,it=Ge+","+yt+","+Tt+","+Mt+","+Ve,Ue=_e.get(it);Ue||(Ue={path:new Path2D,stroke:"rgba("+Ge+","+yt+","+Tt+","+Mt+")",width:Ve},_e.set(it,Ue)),Ue.path.moveTo(oe.x,oe.y),Ue.path.quadraticCurveTo(kt,wt,ie.x,ie.y)}),_e.forEach(f=>{d.strokeStyle=f.stroke,d.lineWidth=f.width,d.stroke(f.path)});let Oe=null;ne&&(Oe=new Set,a.edges.forEach(f=>{f.sourceNodeId===ne?Oe.add(f.targetNodeId):f.targetNodeId===ne&&Oe.add(f.sourceNodeId)}));let Ye=[];if(a.nodes.forEach(f=>{if(!Nt(f.x,f.y,f.r+2,ze))return;let oe=a.domainById[f.id]||{},ie=oe.kind||"other",be=a.timeMode?$a(oe.updated):pt.colors[ie],Me=pt.shapes[ie],Fe=a.selectedId===f.id,et=a.hoverId===f.id,at=a.searchTerm||"",xt=!at||(f.name||"").toLowerCase().includes(at)||String(Ke[ie]||"").toLowerCase().includes(at)||String(ie).toLowerCase().includes(at),kt=A==="all"||ie===A,wt=!u||(oe.tags||[]).includes(u),gt=ne&&f.id!==ne&&!(Oe&&Oe.has(f.id))||at&&!xt||!kt||!wt;d.save(),d.globalAlpha=gt?.08:1,(Fe||et)&&He&&(d.shadowColor=be,d.shadowBlur=Fe?20:14),d.translate(f.x,f.y),Ze(0,0,f.r,Me),d.fillStyle=n(be,f.r),d.fill(),d.restore(),Fe?(d.save(),Ze(f.x,f.y,f.r+3,Me),d.strokeStyle=be,d.lineWidth=3,d.shadowColor=be,d.shadowBlur=12,d.stroke(),d.restore()):et?(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle=be,d.lineWidth=2,d.stroke(),d.restore()):at&&xt?(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle="#e11d48",d.lineWidth=2,d.stroke(),d.restore()):a.multi.indexOf(f.id)>=0&&(d.save(),Ze(f.x,f.y,f.r+2,Me),d.strokeStyle="#60a5fa",d.lineWidth=2,d.shadowColor="#60a5fa",d.shadowBlur=8,d.stroke(),d.restore());let ft=we(f.name,16);if((Fe||et||$e.has(f.id)&&a.zoom>pe||!q&&a.zoom>.6)&&kt&&wt){let Ge=1/a.zoom,yt="500 "+(12*Ge).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";d.font=yt;let Ve=ve(yt,ft)+16*Ge,it=18*Ge,Ue=f.y+f.r+8*Ge,rt=!0;for(let Xe of Ye)if(f.x-Ve/2<Xe.x+Xe.w&&f.x+Ve/2>Xe.x&&Ue<Xe.y+Xe.h&&Ue+it>Xe.y){rt=!1;break}if(!rt&&!Fe&&!et)return;Ye.push({x:f.x-Ve/2,y:Ue,w:Ve,h:it}),d.fillStyle=se()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",d.beginPath(),d.roundRect?d.roundRect(f.x-Ve/2,Ue,Ve,it,4*Ge):d.rect(f.x-Ve/2,Ue,Ve,it),d.fill(),d.strokeStyle=se()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",d.lineWidth=1*Ge,d.stroke(),d.fillStyle=se()?Fe||et?"#eee":"#bbb":Fe||et?"#111":"#444",d.textAlign="center",d.fillText(ft,f.x,Ue+13*Ge)}}),d.restore(),a.marquee){let f=a.marquee,oe=Math.min(f.sx,f.ex),ie=Math.min(f.sy,f.ey),be=Math.abs(f.ex-f.sx),Me=Math.abs(f.ey-f.sy);d.save(),d.setLineDash([4,4]),d.strokeStyle="rgba(96,165,250,0.9)",d.lineWidth=1,d.fillStyle="rgba(96,165,250,0.12)",d.fillRect(oe,ie,be,Me),d.strokeRect(oe,ie,be,Me),d.restore()}if(a.hoverId&&ee.current){let f=a.domainById[a.hoverId],oe=a.nodes.find(function(ie){return ie.id===a.hoverId});if(f&&oe){let ie=a.edges.filter(function(Fe){return Fe.sourceNodeId===f.id||Fe.targetNodeId===f.id}).length,be=oe.x*a.zoom+a.panX,Me=oe.y*a.zoom+a.panY;ee.current.style.display="block",ee.current.style.left=be+14+"px",ee.current.style.top=Me-6+"px",ee.current.innerHTML="<b>"+M(f.title||f.name||"")+'</b><br/><span style="opacity:.8">'+M(f.kind||"")+" \xB7 "+tRef.current("connCount").replace("{n}",ie)+"</span>"}}else ee.current&&(ee.current.style.display="none")},B=()=>{a.running=!0,a.raf||(a.raf=requestAnimationFrame(Se))};a.wake=B,a.render=W;let Q=()=>{let u=a.nodes.length;a.tickCount++;let M=.9-Math.min(.4,a.tickCount/1500),H=u>1e3?3e3:u>100?2e3:u>50?1200:800,q=u>100?.002:.005,pe=u>1e3?.012:u>100?.005:.01,ne=u>1e3?6:u>200?12:24,ze={};a.nodes.forEach(me=>ze[me.id]=me);for(let me=0;me<u;me++){if(a.dragNode===a.nodes[me])continue;let ve=a.nodes[me],He=0,_e=0;for(let f=0;f<u;f++){if(me===f)continue;let oe=ve.x-a.nodes[f].x,ie=ve.y-a.nodes[f].y,be=Math.sqrt(oe*oe+ie*ie)||1,Me=H/(be*be);He+=oe/be*Me,_e+=ie/be*Me}if(a.clustered&&a.typeCenters[ve.type]){let f=a.typeCenters[ve.type];He+=(f.x-ve.x)*.006,_e+=(f.y-ve.y)*.006}else He-=ve.x*pe,_e-=ve.y*pe;let Oe=(ve.vx+He)*M,Ye=(ve.vy+_e)*M;Oe=Math.max(-ne,Math.min(ne,Oe)),Ye=Math.max(-ne,Math.min(ne,Ye)),ve.vx=Oe,ve.vy=Ye}a.edges.forEach(me=>{let ve=ze[me.sourceNodeId],He=ze[me.targetNodeId];if(!ve||!He)return;let _e=He.x-ve.x,Oe=He.y-ve.y,Ye=Math.sqrt(_e*_e+Oe*Oe)||1,f=(Ye-100)*q,oe=_e/Ye*f,ie=Oe/Ye*f;a.dragNode!==ve&&(ve.vx+=oe,ve.vy+=ie),a.dragNode!==He&&(He.vx-=oe,He.vy-=ie)});let Qe=0;a.nodes.forEach(me=>{a.dragNode!==me&&(me.x+=me.vx,me.y+=me.vy,Qe+=me.vx*me.vx+me.vy*me.vy)}),a.autoFitPending&&a.tickCount>45&&(a.autoFitPending=!1,P()),(u?Math.sqrt(Qe/u):0)<.05&&a.tickCount>60&&!a.dragNode?a.quietTicks=(a.quietTicks|0)+1:a.quietTicks=0},Se=()=>{if(a.running){try{Q(),W()}catch{}if(a.quietTicks>30){a.raf=0;return}a.raf=requestAnimationFrame(Se)}},De=(u,A)=>{let M=p.getBoundingClientRect();return{x:(u-M.left-a.panX)/a.zoom,y:(A-M.top-a.panY)/a.zoom}},Le=u=>{let A=a.domainById[u];return!(!A||le.current!=="all"&&A.kind!==le.current||xe.current&&!(A.tags||[]).includes(xe.current))},lt=(u,A,M)=>Math.max(A,Math.min(M,u)),Bt=u=>{a.mouseX=u.clientX,a.mouseY=u.clientY;let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+36){M=q.id;break}}M!==a.hoverId&&(a.hoverId=M,B())},Lt=u=>{if(u.button!==0)return;let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+25){M=q;break}}if(u.shiftKey){if(M){a.shiftClick=M.id;return}a.marquee={sx:u.clientX,sy:u.clientY,ex:u.clientX,ey:u.clientY};return}a.dragStart={x:u.clientX,y:u.clientY,px:a.panX,py:a.panY},a.dragging=!1,a.dragNode=M||null,M&&(a.dragOffset={dx:M.x-A.x,dy:M.y-A.y})},jt=u=>{if(a.marquee){a.marquee.ex=u.clientX,a.marquee.ey=u.clientY,B();return}if(!a.dragStart)return;let A=u.clientX-a.dragStart.x,M=u.clientY-a.dragStart.y;if(Math.abs(A)+Math.abs(M)>3&&(a.dragging=!0),a.dragNode){let H=De(u.clientX,u.clientY);a.dragNode.x=H.x+a.dragOffset.dx,a.dragNode.y=H.y+a.dragOffset.dy,B()}else a.dragging&&(a.panX=lt(a.dragStart.px+A,-1e5,1e5),a.panY=lt(a.dragStart.py+M,-1e5,1e5),B())},Ft=u=>{if(a.marquee){let M=a.marquee;a.marquee=null;let H=p.getBoundingClientRect(),q=Math.min(M.sx,M.ex)-H.left,pe=Math.max(M.sx,M.ex)-H.left,ne=Math.min(M.sy,M.ey)-H.top,ze=Math.max(M.sy,M.ey)-H.top,Qe=a.nodes.filter($e=>{let me=$e.x*a.zoom+a.panX,ve=$e.y*a.zoom+a.panY;return me>=q&&me<=pe&&ve>=ne&&ve<=ze}).map($e=>$e.id);a.multi=Qe,Be(Qe),B();return}let A=a.dragStart&&!a.dragging;if(a.shiftClick){let M=a.shiftClick;a.shiftClick=null;let H=Array.isArray(a.multi)?a.multi.slice():[];H.includes(M)||H.push(M),a.multi=H,Be(H),B();return}if(A){let M=De(u.clientX,u.clientY),H=null;for(let q=a.nodes.length-1;q>=0;q--){let pe=a.nodes[q];if(!Le(pe.id))continue;let ne=pe.x-M.x,ze=pe.y-M.y;if(ne*ne+ze*ze<pe.r*pe.r+20){H=pe;break}}H?(a.selectedId=H.id,F(H.id),B()):(a.selectedId=null,a.hoverId=null,u.shiftKey||(a.multi=[],Be([])),F(null),B())}a.dragStart=null,a.dragging=!1,a.dragNode=null},Pt=u=>{u.preventDefault();let A=De(u.clientX,u.clientY),M=null;for(let H=a.nodes.length-1;H>=0;H--){let q=a.nodes[H];if(!Le(q.id))continue;let pe=q.x-A.x,ne=q.y-A.y;if(pe*pe+ne*ne<q.r*q.r+25){M=q;break}}if(M){let H=a.domainById[M.id];H&&U({x:u.clientX,y:u.clientY,id:M.id,path:H.id,title:H.title})}else U(null)},Ht=u=>{u.preventDefault();let A=p.getBoundingClientRect(),M=(u.clientX-A.left-a.panX)/a.zoom,H=(u.clientY-A.top-a.panY)/a.zoom,q=Math.max(.3,Math.min(3,a.zoom*(u.deltaY<0?v:1/v)));a.panX=lt(a.panX+M*(a.zoom-q),-1e5,1e5),a.panY=lt(a.panY+H*(a.zoom-q),-1e5,1e5),a.zoom=q,B()};p.addEventListener("mousemove",Bt),p.addEventListener("mousedown",Lt),window.addEventListener("mousemove",jt),window.addEventListener("mouseup",Ft),p.addEventListener("wheel",Ht,{passive:!1}),p.addEventListener("contextmenu",Pt),T.current=()=>{a.selectedId=null,a.hoverId=null,a.multi=[],Be([]),P(),B()};for(let u=0;u<200;u++)Q();P(),B();let Ot=()=>$(!1);return window.addEventListener("mousedown",Ot),()=>{a.running=!1,a.raf&&cancelAnimationFrame(a.raf),ot.disconnect(),p.removeEventListener("mousemove",Bt),p.removeEventListener("mousedown",Lt),window.removeEventListener("mousemove",jt),window.removeEventListener("mouseup",Ft),p.removeEventListener("wheel",Ht),p.removeEventListener("contextmenu",Pt),window.removeEventListener("mousedown",Ot)}},[t,i]),(0,o.useEffect)(()=>{O!==void 0&&z.current&&requestAnimationFrame(()=>z.current())},[O]),(0,e.jsxs)("div",{className:"me-graph",ref:x,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[t.length," ",l("nodes")," \xB7 ",i.length," ",l("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",placeholder:l("search"),value:K,onChange:p=>te(p.target.value)}),(0,e.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>$(p=>!p),"aria-expanded":X,title:l("filterLabel"),style:{borderRadius:8},children:["\u{1F50D} ",l("filterLabel")," ",G!=="all"||y||he?"\u25CF":"\u25BE"]}),X&&(0,e.jsx)("div",{className:"me-graph-legend-pop",onMouseDown:p=>p.stopPropagation(),style:{position:"absolute",top:"calc(100% + 6px)",left:0,zIndex:50,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,padding:8,minWidth:240,boxShadow:"0 12px 34px rgba(0,0,0,.35)"},children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,e.jsx)("button",{type:"button",className:`lg${G==="all"&&!y?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>{ge("all"),ue(!1)},children:l("all")}),Object.keys(qe).map(p=>(0,e.jsxs)("button",{type:"button",className:`lg${G===p?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>ge(d=>d===p?"all":p),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:pt.colors[p]||qe[p]}}),l(Ke[p])]},p)),(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsxs)("button",{type:"button",className:`lg${y?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>ue(p=>!p),children:["\u23F1 ",l("timeDim")]}),re.length>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsx)("div",{style:{maxHeight:130,overflow:"auto",display:"flex",flexWrap:"wrap",gap:4},children:re.map(p=>(0,e.jsxs)("button",{type:"button",className:`lg${he===p.tag?" active":""}`,style:{color:"#ddd",padding:"2px 7px",fontSize:11},onClick:()=>Ae(d=>d===p.tag?"":p.tag),title:p.tag,children:["#",p.tag," ",(0,e.jsx)("span",{style:{opacity:.55},children:p.n})]},p.tag))})]}),(G!=="all"||y||he)&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",style:{justifyContent:"flex-start",color:"#f87171"},onClick:()=>{ge("all"),ue(!1),Ae("")},children:[l("clearFilter")," \u2715"]})]})})]}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:l("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:!!R,onChange:p=>S&&S(p.target.checked)}),l("crossVault")]}),(0,e.jsx)("button",{type:"button",className:`mc-btn${y?" me-on":""}`,onClick:()=>ue(p=>!p),children:l("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=k.current;if(p)try{p.toBlob(d=>{d&&Te({url:URL.createObjectURL(d),blob:d})},"image/png")}catch{}},children:l("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>z.current&&z.current(),children:l("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{F(null),ge("all"),T.current&&T.current()},children:l("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:k,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:ee,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:l("noMatch")}),h&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>U(null)}),h&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:h.x,top:h.y,zIndex:31},onMouseDown:p=>p.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{w.current({path:h.path,title:h.title}),U(null)},children:l("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{h.id&&(m.current.selectedId=h.id,F(h.id)),U(null);let p=m.current;p&&p.wake&&p.wake()},children:l("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(h.title||"")}catch{}U(null),Y(l("copied"))},children:l("copyName")}),(0,e.jsx)("button",{type:"button",onClick:()=>{let p=m.current,d=p&&Array.isArray(p.multi)?p.multi.slice():[],_=h.id;if(_&&!d.includes(_)&&d.push(_),U(null),d.length<2){Y(l("mergeNeed"),!1);return}if(!window.confirm(l("mergeConfirm")))return;let se=L.current&&L.current(d);se&&se.then?se.then(ce=>ce?Y(l("merged")):Y(l("mergeFail"),!1)).catch(()=>Y(l("mergeFail"),!1)):se&&Y(l("merged"))},children:l("merge")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let p=h.path;U(null),window.confirm(l("deleteConfirm"))&&(async()=>{try{(j.current?await j.current(p):!1)?Y(l("deleted")):Y(l("deleteFail"),!1)}catch{Y(l("deleteFail"),!1)}})()},children:l("delete")})]}),J.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[J.length," ",l("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let d=J.map(fe=>je[fe]).filter(Boolean).map(fe=>fe.title||fe.name).join(`
346
+ `),_=new Blob([d],{type:"text/plain;charset=utf-8"}),se=URL.createObjectURL(_),ce=document.createElement("a");ce.href=se,ce.download="memory-selected.txt",document.body.appendChild(ce),ce.click(),document.body.removeChild(ce),setTimeout(()=>URL.revokeObjectURL(se),1e3),Y(J.length+l("exportedSel"))},children:l("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(J.length<2){Y(l("mergeNeed"),!1);return}let p=J.map(_=>je[_]?je[_].id:_);if(!window.confirm(l("mergeConfirm")))return;Be([]);let d=m.current;d&&(d.multi=[]),fetch(`${E}/merge?paths=${encodeURIComponent(p.join(","))}`).then(_=>_.json()).then(_=>{_&&_.ok?Y(l("merged")):Y(l("mergeFail"),!1)}).catch(()=>Y(l("mergeFail"),!1))},children:l("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(l("deleteConfirm")))return;let p=J.map(_=>je[_]?je[_].id:_);Be([]);let d=m.current;d&&(d.multi=[]),(async()=>{let _=0;for(let se of p)try{(j.current?await j.current(se):!1)&&_++}catch{}Y(_+l("deletedSelected"),_>0)})()},children:l("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=m.current;p&&(p.multi=[]),Be([]);let d=m.current;d&&d.render&&d.render()},children:l("clearSelection")})]}),V&&(0,e.jsxs)("div",{className:"me-graph-sidebar",style:{position:"absolute",right:10,top:10,zIndex:3,maxWidth:240,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:12,fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:je[V]?je[V].title||je[V].name:V}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:je[V]?l(Ke[je[V].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:l("graphHint")}),(i.filter(p=>p.source===V||p.target===V)||[]).slice(0,8).map((p,d)=>{let _=p.source===V?p.target:p.source,se=je[_];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:ce=>{ce.preventDefault();let fe=m.current;fe&&(fe.selectedId=_,fe.hoverId=_,fe.wake&&fe.wake()),F(_)},children:se?(se.title||se.name).slice(0,28):_},d)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:l("graphTip")}),N&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(N.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:N.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:N.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:N.msg})]}),Ce&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{Ce.url&&URL.revokeObjectURL(Ce.url),Te(null),s(!1)},children:[(0,e.jsx)("style",{children:Ee}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:Ne?"100vw":900,width:Ne?"100vw":"92vw",maxHeight:Ne?"100%":"90vh",height:Ne?"100%":void 0,borderRadius:Ne?0:14},onClick:p=>p.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:l("exportGraph")}),(0,e.jsxs)("div",{className:"me-head-actions",children:[(0,e.jsx)("a",{className:"mc-btn",href:Ce.url,download:"memory-graph.png",onClick:()=>{We("download"),Y(l("downloaded")+" \xB7 "+l("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:l(Z==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{We("full"),s(p=>!p),Y(l("fullscreen"))},children:l(Z==="full"?"done":Ne?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let p=Ce.blob;p&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":p})]).then(()=>{We("copy"),Y(l("copied"))}).catch(()=>{Y(l("copyFail"),!1)}):Y(l("copyFail"),!1)},children:l(Z==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Ce.url&&URL.revokeObjectURL(Ce.url),Te(null),s(!1)},children:l("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:Ne?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:Ce.url,alt:l("exportGraph"),style:{maxWidth:"100%",maxHeight:Ne?"calc(100% - 64px)":"70vh",borderRadius:Ne?0:8,cursor:"zoom-in"},onClick:()=>s(p=>!p)})})]})]})]})}function $a(t){let i=new Date(t||0).getTime();if(!i)return"#94a3b8";let r=(Date.now()-i)/864e5;return r<3?"#10b981":r<14?"#f59e0b":r<30?"#f97316":"#94a3b8"}function Jt({label:t,value:i=[],options:r,onChange:g,placeholder:c,z:l=20}){let[C,R]=(0,o.useState)(!1),S=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!C)return;let w=j=>{S.current&&!S.current.contains(j.target)&&R(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[C]);let O=Array.isArray(i)?i:[],k=O.includes("__all__"),x=k?r.find(w=>w.value==="__all__")?.label||"":O.length?O.map(w=>r.find(j=>j.value===w)?.label||w).join("\u3001"):"",m=(w,j)=>{if(w.value==="__all__"){g(j?["__all__"]:[]);return}let L=new Set(O);L.has("__all__")&&L.delete("__all__"),j?L.add(w.value):L.delete(w.value),g([...L])},z=r.find(w=>w.value==="__all__"),T=r.filter(w=>w.value!=="__all__");return(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,e.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:t}),(0,e.jsxs)("div",{ref:S,style:{position:"relative",minWidth:0},children:[(0,e.jsxs)("button",{type:"button",onClick:()=>R(w=>!w),style:{width:"100%",textAlign:"left",padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[(0,e.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x||c||"\u2014"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.7},children:"\u25BE"})]}),C&&(0,e.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,right:0,zIndex:l,marginTop:2,borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",boxShadow:"0 6px 20px rgba(0,0,0,0.14)",maxHeight:180,overflow:"auto"},children:[z&&(0,e.jsxs)("label",{onClick:w=>w.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("input",{type:"checkbox",checked:k,onChange:w=>m(z,w.target.checked)}),(0,e.jsx)("span",{children:z.label})]}),T.map(w=>(0,e.jsxs)("label",{onClick:j=>j.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer"},children:[(0,e.jsx)("input",{type:"checkbox",checked:O.includes(w.value),onChange:j=>m(w,j.target.checked)}),(0,e.jsx)("span",{children:w.label})]},w.value))]})]})]})}function _a(t){let i=new Date(t||0).getTime();return!!i&&(Date.now()-i)/864e5<3}async function Ua(t,i,r){if(r&&typeof window.showSaveFilePicker=="function")try{let l=await window.showSaveFilePicker({suggestedName:i}),C=await l.createWritable();return await C.write(t),await C.close(),{ok:!0,picked:!0,name:l.name}}catch(l){return l&&l.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(l.message||l)}}let g=URL.createObjectURL(t),c=document.createElement("a");return c.href=g,c.download=i,document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(g),1e3),{ok:!0,picked:!1,name:i}}function Zt(t,i){if(!i||!t)return t;let r=t.toLowerCase(),g=i.toLowerCase(),c=[],l=0;for(;l<t.length;){let C=r.indexOf(g,l);if(C<0){c.push(t.slice(l));break}C>l&&c.push(t.slice(l,C)),c.push((0,e.jsx)("mark",{className:"mc-hl",children:t.slice(C,C+g.length)},C)),l=C+g.length}return c}function ut(t){if(!t)return"";let i=new Date(t);if(Number.isNaN(i.getTime()))return"";let r=new Date,g=i.toDateString()===r.toDateString(),c=C=>String(C).padStart(2,"0"),l=`${c(i.getHours())}:${c(i.getMinutes())}`;return g?l:`${i.getMonth()+1}-${i.getDate()} ${l}`}
339
347
 
340
348
  return module.exports;
341
349
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-eternal",
3
- "version": "0.10.41",
3
+ "version": "0.10.42",
4
4
  "description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -64,7 +64,7 @@
64
64
  "prepublishOnly": "node build.mjs",
65
65
  "release": "node scripts/release.mjs",
66
66
  "release:dry": "node scripts/release.mjs --dry-run",
67
- "test": "node build.mjs && node tests/vault.test.mjs && node tests/capture.test.mjs && node tests/capture-route.test.mjs && node tests/stall.test.mjs && node tests/vault-path.test.mjs && node tests/vault-resolve.test.mjs && node tests/minhash.test.mjs && node tests/settings-save.test.mjs && node tests/config-coverage.test.mjs && node tests/config-sync.test.mjs && node tests/config-merge.test.mjs && node tests/sse.test.mjs && node tests/api.test.mjs && node tests/import-roundtrip.test.mjs && node tests/graph-perf.test.mjs && node tests/settings-compat.test.mjs && node tests/node-bin.test.mjs && node tests/watchdog-lock.test.mjs && node tests/markdown.test.mjs && node tests/feedback.test.mjs && node tests/graph-lod.test.mjs && node tests/ssr.test.mjs && node tests/web-assets.test.mjs && node tests/manifests.test.mjs && node tests/two-store.test.mjs && node tests/noise-gate.test.mjs && node tests/e2e-recall.test.mjs && node tests/issue-fixes.test.mjs && node tests/issue-fixes-2.test.mjs && node tests/issue-fixes-3.test.mjs && node tests/watchdog-orphans.test.mjs && node tests/watchdog-restart.test.mjs && node tests/readme-i18n.test.mjs && node tests/issue-fixes-4.test.mjs && node tests/host-drain.test.mjs && node tests/e2e-host-drain.mjs && node tests/issue-fixes-5.test.mjs && node tests/issue-fixes-6.test.mjs && node tests/capture-json-repair.test.mjs && node tests/csrf-origin.test.mjs && node tests/watchdog-orphan-web.test.mjs && node tests/config-validate.test.mjs && node tests/issue-fixes-8.test.mjs && node tests/issue-fixes-9.test.mjs && node tests/release-verify.test.mjs && node tests/refine.test.mjs && node tests/db-restore.test.mjs && node tests/align.test.mjs && node tests/tags-normalize.test.mjs && node tests/resident-state.test.mjs && node tests/llm-route.test.mjs && node tests/host-managed.test.mjs && node tests/replace-claim.test.mjs && node tests/version-check-self.test.mjs && node tests/setup-codex.test.mjs && node tests/listener-netstat.test.mjs && node tests/issue-46-overlay.test.mjs && node tests/graph-initial-zoom.test.mjs"
67
+ "test": "node build.mjs && node tests/vault.test.mjs && node tests/capture.test.mjs && node tests/capture-route.test.mjs && node tests/stall.test.mjs && node tests/vault-path.test.mjs && node tests/vault-resolve.test.mjs && node tests/minhash.test.mjs && node tests/settings-save.test.mjs && node tests/config-coverage.test.mjs && node tests/config-sync.test.mjs && node tests/config-merge.test.mjs && node tests/sse.test.mjs && node tests/api.test.mjs && node tests/import-roundtrip.test.mjs && node tests/graph-perf.test.mjs && node tests/settings-compat.test.mjs && node tests/node-bin.test.mjs && node tests/watchdog-lock.test.mjs && node tests/markdown.test.mjs && node tests/feedback.test.mjs && node tests/graph-lod.test.mjs && node tests/ssr.test.mjs && node tests/web-assets.test.mjs && node tests/manifests.test.mjs && node tests/two-store.test.mjs && node tests/noise-gate.test.mjs && node tests/e2e-recall.test.mjs && node tests/issue-fixes.test.mjs && node tests/issue-fixes-2.test.mjs && node tests/issue-fixes-3.test.mjs && node tests/watchdog-orphans.test.mjs && node tests/watchdog-restart.test.mjs && node tests/readme-i18n.test.mjs && node tests/issue-fixes-4.test.mjs && node tests/host-drain.test.mjs && node tests/e2e-host-drain.mjs && node tests/issue-fixes-5.test.mjs && node tests/issue-fixes-6.test.mjs && node tests/capture-json-repair.test.mjs && node tests/csrf-origin.test.mjs && node tests/watchdog-orphan-web.test.mjs && node tests/config-validate.test.mjs && node tests/issue-fixes-8.test.mjs && node tests/issue-fixes-9.test.mjs && node tests/release-verify.test.mjs && node tests/refine.test.mjs && node tests/db-restore.test.mjs && node tests/align.test.mjs && node tests/tags-normalize.test.mjs && node tests/resident-state.test.mjs && node tests/llm-route.test.mjs && node tests/host-managed.test.mjs && node tests/replace-claim.test.mjs && node tests/version-check-self.test.mjs && node tests/setup-codex.test.mjs && node tests/listener-netstat.test.mjs && node tests/issue-46-overlay.test.mjs && node tests/graph-initial-zoom.test.mjs && node tests/card-head-actions.test.mjs"
68
68
  },
69
69
  "dependencies": {
70
70
  "@deepseek-ai/schemastery": "^3.18.1"