memory-eternal 0.10.13 → 0.10.15
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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/README.en.md +6 -4
- package/README.md +6 -4
- package/index.js +4 -2
- package/lib/client.js +2 -2
- package/lib/stall.js +11 -3
- package/package.json +1 -1
- package/web/app.js +2 -2
package/lib/client.js
CHANGED
|
@@ -298,11 +298,11 @@ Option A, because:
|
|
|
298
298
|
height: calc(100vh - var(--dsh-windows-titlebar-height, 0px));
|
|
299
299
|
max-height: calc(100vh - var(--dsh-windows-titlebar-height, 0px));
|
|
300
300
|
}
|
|
301
|
-
`;function Sa(t){t.effect(()=>t.locale.register(lt,{zh:Xt,en:Jt}),"memory-eternal: locale");let o=t.locale.bind(lt);t.effect(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:lt,order:25,label:()=>o("nav"),locale:lt,inject:()=>({})},()=>n.default.createElement(Na,{t:o}))),"memory-eternal: settings section"),t.effect(()=>t.slots.inject("sidebar.footer.action",()=>t.slots.register({name:"sidebar.footer.action",id:`${lt}:footer`,order:100,label:()=>o("nav"),locale:lt,inject:()=>({})},r=>n.default.createElement(Ma,{t:o,locale:t.locale,wide:!(r&&r.wide===!1)}))),"memory-eternal: sidebar footer action")}function Ca(){let[t,o]=(0,n.useState)(_+"/ui/app");return(0,n.useEffect)(()=>{let r=!0,m=()=>fetch("/memory-eternal/api/web-info").then(d=>d.json()).then(d=>{r&&d&&d.ok&&d.alive!==!1&&d.url&&o(d.url.endsWith("/")?d.url:d.url+"/")}).catch(()=>{});return fetch(_+"/ui/app",{method:"HEAD"}).then(d=>{if(r&&!d.ok)return m()}).catch(()=>r?m():void 0),()=>{r=!1}},[]),t}function Na({t}){return(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsx)(ta,{t,onReload:()=>{},version:0})]})}function Ma({t,locale:o,wide:r}){let[m,d]=(0,n.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${r?"":" rail"}`,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>d(!0),"aria-label":t("nav"),title:t("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(Qt,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:t("nav")})]}),m&&(0,e.jsx)(Da,{t,locale:o,onClose:()=>d(!1)})]})}function Da({t,locale:o,onClose:r,tab:m}){let[d,i]=(0,n.useState)(!1),w=(0,n.useRef)(null),C=Ca(),x=(0,n.useCallback)(I=>o&&typeof o.subscribe=="function"?o.subscribe(I):()=>{},[o]),A=(0,n.useCallback)(()=>o&&typeof o.getSnapshot=="function"?o.getSnapshot():null,[o]),k=(0,n.useSyncExternalStore)(x,A),h=k&&(k.active==="zh"||k.active==="en")?k.active:null,u=(0,n.useRef)(null);u.current===null&&h&&(u.current=h);let D=(0,n.useMemo)(()=>{let I=u.current?`lang=${u.current}`:"";if(m==="config")return`${_}/ui/config?tab=config${I?`&${I}`:""}`;let v=C.replace(/\/$/,""),T=v.endsWith("/ui/app")?"?":"/?";return m?`${v}${T}tab=${m}${I?`&${I}`:""}`:I?`${v}${T}${I}`:C},[C,m]);return(0,n.useEffect)(()=>{let I=w.current&&w.current.contentWindow;I&&h&&I.postMessage({source:"memory-eternal",type:"locale",lang:h},"*")},[h]),(0,n.useEffect)(()=>{let I=v=>{v.key==="Escape"&&r()};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[r]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:r,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsx)("div",{className:"me-modal"+(d?" me-modal-full":""),onClick:I=>I.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:()=>i(I=>!I),"aria-label":t(d?"exitFullscreen":"enterFullscreen"),title:t(d?"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:d?"\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:w,src:D,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 Qt(){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.
|
|
301
|
+
`;function Sa(t){t.effect(()=>t.locale.register(lt,{zh:Xt,en:Jt}),"memory-eternal: locale");let o=t.locale.bind(lt);t.effect(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:lt,order:25,label:()=>o("nav"),locale:lt,inject:()=>({})},()=>n.default.createElement(Na,{t:o}))),"memory-eternal: settings section"),t.effect(()=>t.slots.inject("sidebar.footer.action",()=>t.slots.register({name:"sidebar.footer.action",id:`${lt}:footer`,order:100,label:()=>o("nav"),locale:lt,inject:()=>({})},r=>n.default.createElement(Ma,{t:o,locale:t.locale,wide:!(r&&r.wide===!1)}))),"memory-eternal: sidebar footer action")}function Ca(){let[t,o]=(0,n.useState)(_+"/ui/app");return(0,n.useEffect)(()=>{let r=!0,m=()=>fetch("/memory-eternal/api/web-info").then(d=>d.json()).then(d=>{r&&d&&d.ok&&d.alive!==!1&&d.url&&o(d.url.endsWith("/")?d.url:d.url+"/")}).catch(()=>{});return fetch(_+"/ui/app",{method:"HEAD"}).then(d=>{if(r&&!d.ok)return m()}).catch(()=>r?m():void 0),()=>{r=!1}},[]),t}function Na({t}){return(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsx)(ta,{t,onReload:()=>{},version:0})]})}function Ma({t,locale:o,wide:r}){let[m,d]=(0,n.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${r?"":" rail"}`,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>d(!0),"aria-label":t("nav"),title:t("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(Qt,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:t("nav")})]}),m&&(0,e.jsx)(Da,{t,locale:o,onClose:()=>d(!1)})]})}function Da({t,locale:o,onClose:r,tab:m}){let[d,i]=(0,n.useState)(!1),w=(0,n.useRef)(null),C=Ca(),x=(0,n.useCallback)(I=>o&&typeof o.subscribe=="function"?o.subscribe(I):()=>{},[o]),A=(0,n.useCallback)(()=>o&&typeof o.getSnapshot=="function"?o.getSnapshot():null,[o]),k=(0,n.useSyncExternalStore)(x,A),h=k&&(k.active==="zh"||k.active==="en")?k.active:null,u=(0,n.useRef)(null);u.current===null&&h&&(u.current=h);let D=(0,n.useMemo)(()=>{let I=u.current?`lang=${u.current}`:"";if(m==="config")return`${_}/ui/config?tab=config${I?`&${I}`:""}`;let v=C.replace(/\/$/,""),T=v.endsWith("/ui/app")?"?":"/?";return m?`${v}${T}tab=${m}${I?`&${I}`:""}`:I?`${v}${T}${I}`:C},[C,m]);return(0,n.useEffect)(()=>{let I=w.current&&w.current.contentWindow;I&&h&&I.postMessage({source:"memory-eternal",type:"locale",lang:h},"*")},[h]),(0,n.useEffect)(()=>{let I=v=>{v.key==="Escape"&&r()};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[r]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:r,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsx)("div",{className:"me-modal"+(d?" me-modal-full":""),onClick:I=>I.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:()=>i(I=>!I),"aria-label":t(d?"exitFullscreen":"enterFullscreen"),title:t(d?"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:d?"\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:w,src:D,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 Qt(){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.15";function za({t,inModal:o,onClose:r,onFull:m,full:d}){let[i,w]=(0,n.useState)(null),[C,x]=(0,n.useState)([]),[A,k]=(0,n.useState)(!0),[h,u]=(0,n.useState)(null),[D,I]=(0,n.useState)(""),[v,T]=(0,n.useState)("all"),[N,j]=(0,n.useState)(""),[Q,xe]=(0,n.useState)("all"),[q,Re]=(0,n.useState)("all"),[U,me]=(0,n.useState)(()=>{try{let b=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),P={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(b&&P[b])return P[b]}catch{}return"cards"}),[le,F]=(0,n.useState)(()=>new Set([U])),y=(0,n.useCallback)(b=>{F(P=>P.has(b)?P:new Set(P).add(b)),me(b)},[]),[H,M]=(0,n.useState)("recent"),[ne,K]=(0,n.useState)(null),X=(0,n.useRef)(null),re=(0,n.useRef)(null),[f,W]=(0,n.useState)(!1),[de,Y]=(0,n.useState)(null),[ie,we]=(0,n.useState)(!1),[Ae,Me]=(0,n.useState)(!1),[ve,Ce]=(0,n.useState)(!0),[et,Ze]=(0,n.useState)(null),[Ve,nt]=(0,n.useState)(0),tt=(0,n.useCallback)(()=>nt(b=>b+1),[]),Te=i?.quarantine?.pending??0,Be=i?.quarantine?.deleted??0,pe=(0,n.useRef)(null),[Ye,Ne]=(0,n.useState)(0),[c,s]=(0,n.useState)(!1),E=(0,n.useRef)(null),se=(0,n.useRef)(null),$=(0,n.useCallback)(async(b=v,P=N,Z=q,ke={})=>{let G=ke.append===!0;try{G?s(!0):(k(!0),I(""));let he=new URLSearchParams;b&&b!=="all"&&he.set("kind",b),P.trim()&&he.set("q",P.trim()),he.set("status",Z||"all"),he.set("limit",String(va)),he.set("offset",String(ke.offset||0)),H==="title"&&he.set("sort","title");let Ie=await(await fetch(`${_}/cards?${he.toString()}`)).json();if(Ie.ok){let Ue=Ie.cards||[];x(He=>G?[...He,...Ue.filter(Ke=>!He.some(vt=>vt.path===Ke.path))]:Ue),Ne(Number(Ie.total)||Ue.length)}}catch(he){I(String(he&&he.message?he.message:he))}finally{G?s(!1):k(!1)}},[v,N,q,H]),ge=(0,n.useCallback)(async()=>{try{let[b,P]=await Promise.all([fetch(`${_}/overview`).then(Z=>Z.json()),fetch(`${_}/capture-log`).then(Z=>Z.json()).catch(()=>null)]);b.ok&&w(b),u(P&&P.ok&&P.available&&P.health||null)}catch(b){I(String(b&&b.message?b.message:b))}finally{k(!1)}},[]),a=async b=>{try{let Z=await(await fetch(`${_}/delete?path=${encodeURIComponent(b)}`)).json();Z.ok?(K({ok:!0,msg:t("deleted")}),await ge(),tt()):K({ok:!1,msg:Z.error||t("deleteFail")})}catch{K({ok:!1,msg:t("deleteFail")})}X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2e3)};(0,n.useEffect)(()=>(ge(),()=>{pe.current&&clearTimeout(pe.current)}),[ge]);let l=b=>{j(b),pe.current&&clearTimeout(pe.current),pe.current=setTimeout(()=>$(v,b,q),280)},L=b=>{T(b),$(b,N,q)};(0,n.useEffect)(()=>{U==="cards"&&$(v,N,q)},[q,U,Ve,H]),(0,n.useEffect)(()=>{if(U!=="cards"||A||c||C.length>=Ye)return;let b=E.current,P=se.current;if(!b)return;let Z=new IntersectionObserver(ke=>{ke[0]&&ke[0].isIntersecting&&$(v,N,q,{append:!0,offset:C.length})},{root:P||null,rootMargin:"400px"});return Z.observe(b),()=>Z.disconnect()},[U,C,Ye,A,c,v,N,q,$]);let B=async b=>{try{let P=b.status;if(!P&&b.path)try{let ze=((await fetch(`${_}/cards?status=all&q=${encodeURIComponent(b.title||"")}&limit=50`).then(Ie=>Ie.json())).cards||[]).find(Ie=>Ie.path===b.path);ze&&(P=ze.status)}catch{}let Z=P&&P!=="approved"?`&status=${encodeURIComponent(P)}`:"",ke=await fetch(`${_}/card?path=${encodeURIComponent(b.path||b.id)}${Z}`),G=await ke.json();G.ok?Y({path:G.path,title:b.title,text:G.text}):I(G.error||`HTTP ${ke.status}`)}catch(P){I(String(P&&P.message?P.message:P))}},J=async(b,P)=>{W(!0);try{let Z=await fetch(`${_}/export`);if(!Z.ok)throw new Error("HTTP "+Z.status);let ke=await Z.json();if(!ke.ok)throw new Error(ke.error||"export failed");let G,he,ze;if(b==="json"){he="memory-vault.json",ze="application/json";let He=ke.cards.map(Ke=>({path:Ke.path,title:Ke.title,kind:Ke.kind,status:Ke.status,store:Ke.store,text:Ke.text}));G=JSON.stringify({format:ke.format||"memory-eternal-vault",formatVersion:ke.formatVersion||1,exportedAt:ke.exportedAt||new Date().toISOString(),count:He.length,cards:He},null,2)}else he="memory-vault.md",ze="text/markdown;charset=utf-8",G=ke.cards.map(He=>He.text.trim()).filter(Boolean).join(`
|
|
302
302
|
|
|
303
303
|
---
|
|
304
304
|
|
|
305
|
-
`);let Ie=new Blob([G],{type:ze}),Ue=await Wa(Ie,he,!1);if(!Ue.ok){K({ok:!1,msg:t("exportFail")}),W(!1);return}K({ok:!0,msg:t("exportedTo")+"\uFF1A"+t("defaultDownloads")+" \xB7 "+Ue.name})}catch(Z){K({ok:!1,msg:t("exportFail")+" \xB7 "+(Z.message||"")})}finally{W(!1)}X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2600)},be=async b=>{let P=b.target.files&&b.target.files[0];if(b.target.value="",!!P){try{let Z=await P.text(),G=await(await fetch(`${_}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:Z})).json();if(G.ok){await ge();let he=G.imported||0,ze=t("importedVault")+"\uFF1A"+he;G.total&&(ze+=t("importedTotal")+G.total+t("importedTotalTail")),G.quarantined&&(ze+=t("importedQuarantine")+G.quarantined+t("importedQuarantineTail")),G.skipped&&(ze+=t("importedSkipped")+G.skipped+t("importedSkippedTail")),G.warning&&(ze+=" \xB7 "+G.warning),K({ok:he>0||!G.total,msg:ze})}else K({ok:!1,msg:G.error||t("importFail")})}catch{K({ok:!1,msg:t("importFail")})}X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2400)}},V=(0,n.useMemo)(()=>{let b=C.slice();return Q!=="all"&&(b=b.filter(P=>ut(P.submittedBy)===Q)),q!=="all"&&(b=b.filter(P=>(P.status||"approved")===q)),H==="title"?b.sort((P,Z)=>String(P.title||"").localeCompare(String(Z.title||""))):H==="hot"?b.sort((P,Z)=>(Z.weight||Z.links||0)-(P.weight||P.links||0)):b.sort((P,Z)=>new Date(Z.updated||0).getTime()-new Date(P.updated||0).getTime()),b},[C,H,Q,q]),oe=(0,n.useMemo)(()=>[...new Set(C.map(b=>ut(b.submittedBy)))],[C]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:Fe}),ne&&(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 "+(ne.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:ne.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:ne.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:ne.msg})]}),o&&(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)(Qt,{})}),(0,e.jsx)("h2",{children:t("memoryTitle")}),(0,e.jsx)("span",{children:t("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),m&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:m,"aria-label":t(d?"exitFull":"fullscreen"),children:d?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:r,"aria-label":t("close"),children:"\u2715"})]}),h&&h.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:[h.reason,(0,e.jsx)("div",{style:{opacity:.68,fontSize:11.5,marginTop:2},children:t("captureAlertHint")})]}),(0,e.jsx)("span",{style:{opacity:.7},children:h.since?pt(new Date(h.since).toISOString()):""})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:`mc-rail${ve?" open":""}`,children:[(0,e.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>Ce(b=>!b),"aria-label":t(ve?"collapse":"expand"),title:t(ve?"collapse":"expand"),children:ve?"\xAB":"\xBB"}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="cards"?" active":""}`,onClick:()=>y("cards"),title:t("cardsTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F9E0}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("cardsTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="graph"?" active":""}`,onClick:()=>y("graph"),title:t("graphTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F52E}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("graphTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="stats"?" active":""}`,onClick:()=>y("stats"),title:t("tabUsage"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C8}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabUsage")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="audit"?" active":""}`,onClick:()=>y("audit"),title:t("tabAudit"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F50D}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabAudit")}),Te>0&&(0,e.jsx)("span",{className:"mc-dot",children:Te>99?"99+":Te})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="optimize"?" active":""}`,onClick:()=>y("optimize"),title:t("tabRecycle"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u267B\uFE0F"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabRecycle")}),Be>0&&(0,e.jsx)("span",{className:"mc-dot",style:{background:"#6b7280"},children:Be>99?"99+":Be})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="config"?" active":""}`,onClick:()=>y("config"),title:t("tabConfig"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabConfig")})]}),(0,e.jsxs)("button",{type:"button",className:"mc-railbtn",onClick:()=>Me(!0),title:t("fbNav"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F41E}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("fbNav")})]})]}),(0,e.jsxs)("div",{className:"mc-main",ref:se,children:[U==="cards"&&(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(dt,{label:t("total"),value:i?i.total:"\u2014"}),(0,e.jsx)(dt,{label:t("recent"),value:i?i.recent:"\u2014"}),(0,e.jsx)(dt,{label:t("tags"),value:i?i.tags:"\u2014"}),(0,e.jsx)(dt,{label:t("pending"),value:i?.quarantine?.pending??i?.status?.pending??0}),(0,e.jsx)(dt,{label:t("rejected"),value:i?.quarantine?.rejected??i?.status?.rejected??0}),(0,e.jsx)(dt,{label:t("cardCount"),value:i?i.byKind?.knowledge??0:"\u2014"})]}),U==="cards"&&(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:t("searchPlaceholder"),value:N,onChange:b=>l(b.target.value)}),(0,e.jsx)("input",{ref:re,type:"file",accept:".json,application/json",style:{display:"none"},onChange:be}),(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:()=>Ze({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",t("newCard")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:f,onClick:()=>J("md"),children:t(f?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:f,onClick:()=>J("json"),children:t(f?"exporting":"exportJson")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ge(),children:t("refresh")})]}),U==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[Rt.map(b=>(0,e.jsx)("button",{type:"button",className:`mc-chip${v===b?" active":""}`,onClick:()=>L(b),children:t(b==="all"?"all":$e[b])},b)),(0,e.jsxs)("select",{value:Q,onChange:b=>xe(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")]}),Zt(oe).map(b=>(0,e.jsx)("option",{value:b,children:b},b))]}),(0,e.jsxs)("select",{value:q,onChange:b=>Re(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${H===b.key?" active":""}`,onClick:()=>M(b.key),children:b.label},b.key))]}),D&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",D]}),(0,e.jsx)("div",{style:{display:U==="cards"?"contents":"none"},children:A?(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}):D?(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",D," ",(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ge(),children:t("retry")})]}):C.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:V.map(b=>(0,e.jsx)(La,{card:b,t,query:N.trim(),onOpen:B,onDelete:a},b.path))}),C.length<Ye&&(0,e.jsx)("div",{ref:E,style:{height:1}}),c&&(0,e.jsxs)("div",{className:"mc-empty",style:{padding:"10px 0"},children:[t("loading"),"\uFF08",C.length," / ",Ye,"\uFF09"]})]})}),(0,e.jsx)("div",{style:{display:U==="graph"?"flex":"none",flex:1,minHeight:0},children:le.has("graph")&&(0,e.jsx)(Ea,{t,onOpen:B,all:ie,onAllChange:we,onMutate:tt,active:U==="graph",visible:U==="graph"})}),(0,e.jsx)("div",{style:{display:U==="config"?"contents":"none"},children:le.has("config")&&(0,e.jsx)(ta,{t,onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="stats"?"contents":"none"},children:le.has("stats")&&(0,e.jsx)(Ra,{t,tab:"stats",onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="audit"?"contents":"none"},children:le.has("audit")&&(0,e.jsx)(Ta,{t,onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="optimize"?"contents":"none"},children:le.has("optimize")&&(0,e.jsx)(Ia,{t,onReload:()=>ge(),version:Ve})}),Ae&&(0,e.jsx)(Ba,{t,onClose:()=>Me(!1)}),de&&(0,e.jsx)(Pa,{t,card:de,query:N.trim(),onClose:()=>Y(null),onDelete:b=>{Y(null),a(b)},onFeedback:b=>{let P=de.path;fetch(`${_}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:N.trim(),path:P,useful:b})}).then(()=>K({ok:!0,msg:t(b?"fbUseful":"fbIrr")})).catch(()=>{}),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2e3)}}),(0,e.jsx)(Aa,{t,newCard:et,setNewCard:Ze,onCreated:()=>{ge(),tt(),K({ok:!0,msg:t("created")}),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2e3)}})]})]})]})}var ea=({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,dt=({label:t,value:o})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:o}),(0,e.jsx)("span",{children:t})]});function ta({t,onReload:o,version:r,compact:m}){let[d,i]=(0,n.useState)(null),[w,C]=(0,n.useState)(0),[x,A]=(0,n.useState)(null),[k,h]=(0,n.useState)(null),[u,D]=(0,n.useState)(!1),[I,v]=(0,n.useState)(!1),T=(0,n.useRef)(!1),N=(0,n.useRef)(null),j=(0,n.useRef)({}),[Q,xe]=(0,n.useState)(null),[q,Re]=(0,n.useState)(null),[U,me]=(0,n.useState)(""),[le,F]=(0,n.useState)(""),[y,H]=(0,n.useState)(""),[M,ne]=(0,n.useState)(null),K=(0,n.useCallback)(async l=>{F("version");try{let L=await fetch(_+"/version-check"+(l?"?force=1":"")).then(B=>B.json());L&&L.ok?(ne(L),l&&Y(L.updateAvailable?t("vcLatest")+" v"+L.latest:t("vcUpToDate"))):l&&Y(t("vcCheckFail"),!1)}catch{l&&Y(t("vcCheckFail"),!1)}finally{F("")}},[t]);(0,n.useEffect)(()=>{K(!1)},[r,K]);let[X,re]=(0,n.useState)(""),[f,W]=(0,n.useState)(null),de=(0,n.useRef)(null),Y=(l,L=!0)=>{de.current&&clearTimeout(de.current),W({msg:l,ok:L}),de.current=setTimeout(()=>W(null),1900)},ie=async()=>{if(!le){F("restart");try{let l=await fetch(_+"/restart-self",{method:"POST"});if(l.status===404||l.status===405){Y(Me("vcRestartNoRoute",{cmd:M&&M.restartCommand||"dsh-memory restart --port 7999"}),!1);return}let L=await l.json().catch(()=>null);if(!L){Y(t("vcRestartFail")+"\uFF08HTTP "+l.status+"\uFF09",!1);return}if(!L.ok){Y(L.error||t("vcRestartFail"),!1);return}if(L.alreadyCurrent){Y(L.note||t("vcRestartCurrent"));return}Y(L.note||t("vcRestartSent")),L.alreadyRunning||setTimeout(()=>{K(!0)},6e3)}catch(l){Y(t("vcRestartFail")+"\uFF1A"+String(l&&l.message||l),!1)}finally{F("")}}},we=M&&M.resident?String(M.resident.served||""):"",Ae=!!(M&&M.onDisk&&we&&we!==M.onDisk),Me=(l,L)=>Object.keys(L).reduce((B,J)=>B.split("{"+J+"}").join(L[J]),t(l)),ve=(0,n.useCallback)(async()=>{try{let[l,L,B]=await Promise.all([fetch(`${_}/config`).then(J=>J.json()).catch(()=>null),fetch(`${_}/setup-status`).then(J=>J.json()).catch(()=>null),fetch(`${_}/budget`).then(J=>J.json()).catch(()=>null)]);if(l&&l.ok){i(l),C(l.revision??0),A(l.schema??null);let J=qt(l.config??{},j.current);j.current=J.overlay,h({...J.values}),xe(l.dsh??null),D(l.writable===!1),v(l.viaPending===!0),me(""),T.current=!1}else B&&B.ok?(h({...B}),D(!0),me(t("configNeedsDsh"))):me(t("adminLoadFail"));L&&L.ok&&Re(L),H("")}catch{me(t("adminLoadFail"))}},[t]);(0,n.useEffect)(()=>{ve()},[r,ve]);let Ce=(l,L)=>{T.current=!0,h(B=>({...B??{},[l]:L}))};(0,n.useEffect)(()=>{N.current=ve},[ve]),(0,n.useEffect)(()=>{if(typeof EventSource>"u")return;let l=null;try{l=new EventSource(_+"/events")}catch{return}let L=()=>{!T.current&&typeof N.current=="function"&&N.current()};try{l.addEventListener("config",L)}catch{}return()=>{try{l.close()}catch{}}},[]);let et=new Set(["dedupThreshold","captureMinChars","captureCooldownMs","maxCardsPerDay","captureMaxTokens","recallMinScore","recallLimit","recallSummaryLen","recycleRetentionDays","webPort","webCheckIntervalMs","webMaxRestart","sessionBudgetChars"]),Ze=l=>({init:t("modeInit"),interval:t("modeInterval"),manual:t("modeManual")})[l]||l,Ve=async()=>{if(!k)return;if(u){Y(t("editInSetting"),!1);return}let l={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]},L=[];for(let[B,[J,be]]of Object.entries(l)){if(!(B in k))continue;let V=k[B],oe=typeof V=="number"?V:Number(V);(V===""||V===null||V===void 0||!Number.isFinite(oe)||oe<J||oe>be)&&L.push(t("invalidField",{field:B,min:J,max:be,value:String(V===""?"\u7A7A":V)}))}if(L.length){let B=t("saveInvalid")+"\uFF1A"+L.join("\uFF1B");me(B),Y(B,!1);return}F("save");try{let B={...k};for(let oe of Object.keys(k))oe in B&&typeof B[oe]=="string"&&B[oe].trim()!==""&&et.has(oe)&&(B[oe]=Number(B[oe]));Array.isArray(B.vaultProfiles)&&(B.vaultProfiles=B.vaultProfiles.filter(oe=>oe&&(String(oe.name||"").trim()||String(oe.path||"").trim())));let J=await fetch(`${_}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:B,expectedRevision:w})}),be=await J.text(),V=null;try{V=be?JSON.parse(be):null}catch{V=null}if(V||(V={error:"HTTP "+J.status+(be?"\uFF1A"+be.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")}),V&&V.ok){let oe=typeof V.pendingOutcome=="string"?V.pendingOutcome:"",b,P=!0;if(oe==="applied")b=t("savedApplied")+(Array.isArray(V.applied)&&V.applied.length?" \xB7 "+V.applied.join("\u3001"):"");else if(oe==="queued")P=!1,b=t("saveQueued");else if(oe==="failed")P=!1,b=t("saveFail")+" \xB7 "+(V.hostGuard?t("saveHostGuard"):t("saveFailHint"));else if(oe==="applied-direct")b=t("savedOk")+" \xB7 "+t("savedDirect");else{let Z=Array.isArray(V.pending)&&V.pending.length?" \xB7 "+t("savePending"):V.note?" \xB7 "+t("restartHint"):"";b=(V.retried?"\u267B ":"")+t("savedOk")+Z}j.current={...j.current,...B},P?H(b):me(b),Y(b,P),await ve()}else{let oe=J.status===409?t("conflictRefresh"):V?.error||t("saveFail");me(oe),Y(oe,!1)}}catch{me(t("saveFail")),Y(t("saveFail"),!1)}finally{F("")}},nt=()=>{j.current={},h({...d?.config??{}}),H("")},tt={env:"vaultSrcEnv",profile:"vaultSrcProfile",workspace:"vaultSrcWorkspace",vaultDir:"vaultSrcVaultDir",default:"vaultSrcDefault"},Te=l=>Array.isArray(l?.vaultProfiles)?l.vaultProfiles:[],Be=(l,L,B)=>h(J=>{let be=Te(J).map(oe=>({...oe||{}})),V={...be[l]||{}};return L==="match"?String(B).trim()?V.match={...V.match||{},workspace:B}:delete V.match:V[L]=B,be[l]=V,{...J??{},vaultProfiles:be}}),pe=()=>h(l=>({...l??{},vaultProfiles:[...Te(l),{name:"",path:""}]})),Ye=l=>h(L=>({...L??{},vaultProfiles:Te(L).filter((B,J)=>J!==l)})),Ne={fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},c={padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:12,minWidth:0},s={A:{label:t("planA"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:2e3,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}},E=async l=>{let L=s[l];L&&h(B=>({...B??{},...L}))},se=async(l,L)=>{F(l+L);try{let J=await(await fetch(`${_}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:l,action:L})})).json();J&&J.ok?Y(Me(L==="install"?"mcpInstalled":"mcpUninstalled",{agent:l})):Y(Me("mcpActionFail",{agent:l,error:J?.error||""}),!1);try{let be=await fetch(`${_}/setup-status`).then(V=>V.json());be&&be.ok&&Re(be)}catch{}}catch{Y(t("mergeFail"),!1)}finally{F("")}},$=({k:l,label:L,type:B="text",step:J,min:be,max:V})=>(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:L||l}),(0,e.jsx)("input",{type:B,step:J,min:be,max:V,value:k?k[l]??"":"",onChange:oe=>{let b=oe.target.value;Ce(l,B==="number"?b===""?"":Number(b):b)},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}})]}),ge=new Set(["autoRestartOnDrift"]),a=({k:l,label:L})=>{let B=k?k[l]:void 0,J=B===void 0?ge.has(l):!!B;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:J,onChange:be=>Ce(l,be.target.checked),style:{marginTop:2,flex:"0 0 auto"}}),(0,e.jsx)("span",{style:{whiteSpace:"normal",overflowWrap:"anywhere"},children:L||l})]})};return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:m?"0 0 auto":1,minHeight:0,maxHeight:m?"52vh":void 0},children:[(0,e.jsx)("style",{children:Fe}),f&&(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 "+(f.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:f.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:f.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:f.msg})]}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[U&&(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 ",U]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:ve,children:["\u21BB ",t("retry")]})]}),I&&(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")]}),u&&(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")]}),y&&(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 ",y]}),d&&(d.version||d.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")}),d.version&&(0,e.jsxs)("code",{style:Ne,children:[t("vcLoaded")," v",d.version]}),M&&M.resident&&M.resident.served&&M.resident.served!==d.version&&(0,e.jsxs)("code",{style:Ne,children:[t("vcResident")," v",M.resident.served]}),bt&&(0,e.jsxs)("code",{style:Ne,children:[t("vcPage")," v",bt]}),M&&M.onDisk&&(0,e.jsxs)("code",{style:Ne,children:[t("vcOnDisk")," v",M.onDisk]}),M&&M.latest&&(0,e.jsxs)("code",{style:Ne,children:[t("vcLatest")," v",M.latest]}),d.dsh?.vaultDir&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",d.dsh.vaultDir]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:le==="version",onClick:()=>K(!0),children:le==="version"?t("checking"):"\u{1F504} "+t("vcCheck")})]}),M&&M.stale&&(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 ",Me("vcStale",{disk:M.onDisk,loaded:M.loaded})]}),Ae?(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:!!le,onClick:ie,children:le==="restart"?"\u23F3 "+t("vcRestarting"):"\u{1F504} "+t("vcRestart")}),M.restartCommand&&(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:M.restartCommand})]}):(0,e.jsxs)("div",{style:{marginTop:6,lineHeight:1.7},children:["\u2139\uFE0F ",t("vcHostStale"),M.restartCommand&&(0,e.jsxs)(e.Fragment,{children:[" ",(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:M.restartCommand})]})]})]}),bt&&M&&M.onDisk&&bt!==M.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:M.onDisk})}),M&&M.updateAvailable&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,opacity:.88},children:["\u2B06 ",t("vcOutdated")," \u2192 ",(0,e.jsx)("code",{children:M.updateCommand})]}),M&&M.checkError&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b91c1c"},children:[t("vcCheckFail"),"\uFF1A",M.checkError]})]}),q&&q.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:q.agents.map(l=>(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:l.isDsh?t("dshHostLabel"):l.name}),l.isDsh&&l.version&&(0,e.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",l.version]}),!l.installed&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",t("notInstalled"),")"]}),l.installed&&l.mcpConfigured===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",t("noMcpEntry"),")"]}),l.mcpConfigured===!0&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",t("healthy")]}),l.mcpConfigured===!0&&l.mcpMatchesCurrentNode===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",t("nodePathNote"),")"]}),l.isDsh&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",t("recallTool"),": ",l.recallTool?t("enabled"):t("disabled"),")"]})]}),l.hook&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",l.hook]}),!l.isDsh&&l.installed&&l.mcpConfigured===!1&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!le,onClick:()=>se(l.name,"install"),children:t("installMcp")}),!l.isDsh&&l.installed&&l.mcpConfigured===!0&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!le,onClick:()=>{window.confirm(t("uninstallConfirm"))&&se(l.name,"uninstall")},children:t("uninstallMcp")})]},l.name))}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:t("mcpSetupHint")}),X&&(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:X})})]}),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(l=>(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>E(l),disabled:!!le,children:[l==="A"?"\u{1F7E2} ":l==="B"?"\u{1F4B0} ":"\u2B50 ",s[l].label]},l))})]}),(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)(a,{k:"autoCapture",label:t("autoCapture")}),(0,e.jsx)(a,{k:"autoRecall",label:t("autoRecall")}),(0,e.jsx)($,{k:"captureMinChars",label:t("captureMinChars"),type:"number"}),(0,e.jsx)($,{k:"maxCardsPerDay",label:t("maxCardsPerDay"),type:"number"}),(0,e.jsx)($,{k:"dedupThreshold",label:t("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,e.jsx)($,{k:"recallLimit",label:t("recallLimit"),type:"number"}),(0,e.jsx)($,{k:"recallSummaryLen",label:t("recallSummaryLen"),type:"number"}),(0,e.jsx)(a,{k:"recallIncludeBody",label:t("recallBody")}),(0,e.jsx)($,{k:"secretHint",label:t("secretHint")}),(0,e.jsx)($,{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:Q?.vaultDir||"\u2014"}),Q?.vaultName?`\uFF08${Q.vaultName}\uFF09`:""," \xB7 ",t("vaultSource"),"\uFF1A",t(tt[Q?.vaultSource]||"vaultSrcDefault"),Q?.workspace?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),t("vaultWorkspace"),"\uFF1A",(0,e.jsx)("code",{children:Q.workspace})]}):null]}),Te(k).map((l,L)=>(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.6fr 1.5fr auto",gap:6,marginBottom:6},children:[(0,e.jsx)("input",{value:l.name||"",placeholder:t("vaultNamePh"),onChange:B=>Be(L,"name",B.target.value),style:c,disabled:u}),(0,e.jsx)("input",{value:l.path||"",placeholder:t("vaultPathPh"),onChange:B=>Be(L,"path",B.target.value),style:c,disabled:u}),(0,e.jsx)("input",{value:l.match&&l.match.workspace||"",placeholder:t("vaultMatchPh"),onChange:B=>Be(L,"match",B.target.value),style:c,disabled:u}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>Ye(L),disabled:u,title:t("delete"),children:"\u2715"})]},L)),(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:pe,disabled:u,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:l=>Ce("activeVault",l.target.value),disabled:u,style:c,children:[(0,e.jsx)("option",{value:"",children:t("vaultActiveNone")}),Te(k).filter(l=>l&&l.name).map(l=>(0,e.jsx)("option",{value:l.name,children:l.name},l.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)(a,{k:"enabled",label:t("enabledLabel")}),(0,e.jsx)($,{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)(a,{k:"distillEnabled",label:t("distillEnabled")}),(0,e.jsx)(a,{k:"dedupByLLM",label:t("dedupByLLM")}),(0,e.jsx)($,{k:"captureMaxTokens",label:t("captureMaxTokens"),type:"number"}),(0,e.jsx)($,{k:"recallMinScore",label:t("recallMinScore"),type:"number"}),(0,e.jsx)($,{k:"captureCooldownMs",label:t("captureCooldownMs"),type:"number"}),(0,e.jsx)($,{k:"captureProvider",label:t("captureProvider")}),(0,e.jsx)($,{k:"captureModel",label:t("captureModel")}),(0,e.jsx)($,{k:"sessionBudgetChars",label:t("sessionBudgetChars"),type:"number"})]})]}),(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:l=>Ce("auditMode",l.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)(Yt,{label:t("auditExemptAgents"),value:k.auditExemptAgents||[],options:[{value:"__all__",label:t("allExempt")},...(q?.agents||[]).filter(l=>!l.isDsh).map(l=>({value:l.name,label:l.name}))],onChange:l=>Ce("auditExemptAgents",l)}),(0,e.jsx)(Yt,{label:t("auditExemptKinds"),value:k.auditExemptKinds||[],options:[{value:"__all__",label:t("allExempt")},...Rt.filter(l=>l!=="all").map(l=>({value:l,label:t($e[l])}))],onChange:l=>Ce("auditExemptKinds",l)}),(0,e.jsx)($,{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)(a,{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:l=>Ce("autoWebMode",l.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)($,{k:"webPort",label:t("webPort"),type:"number"}),(0,e.jsx)($,{k:"webCheckIntervalMs",label:t("webCheckIntervalMs"),type:"number"}),(0,e.jsx)($,{k:"webMaxRestart",label:t("webMaxRestart"),type:"number"}),(0,e.jsx)(a,{k:"watchdogAutoSpawn",label:t("watchdogAutoSpawn")}),(0,e.jsx)(a,{k:"autoRestartOnDrift",label:t("autoRestartOnDrift")}),(0,e.jsx)(a,{k:"autoMcpSetup",label:t("autoMcpSetup")})]})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",alignItems:"center",marginBottom:10,flexWrap:"wrap"},children:[le==="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,opacity:.75},children:["\u23F3 ",t("saving")]}),y&&le!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#10b981"},children:["\u2705 ",y]}),U&&le!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#b91c1c"},children:["\u26A0 ",U]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:nt,disabled:!!le,children:t("reset")}),(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:u?()=>Y(t("readonlyTitle")+"\uFF1A"+t("readonlyBody"),!1):Ve,disabled:le==="save",title:t(u?"readonlyBody":"saveConfig"),children:le==="save"?"\u23F3 "+t("saving"):u?"\u{1F512} "+t("readonlyBtn"):"\u{1F4BE} "+t("saveConfig")})]})]}):(0,e.jsx)("div",{style:{fontSize:12,opacity:.6},children:t("loading")})]})]})}function Ta({t,onReload:o,version:r}){let[m,d]=(0,n.useState)([]),[i,w]=(0,n.useState)([]),[C,x]=(0,n.useState)("all"),[A,k]=(0,n.useState)("all"),[h,u]=(0,n.useState)(""),[D,I]=(0,n.useState)(new Set),[v,T]=(0,n.useState)(""),[N,j]=(0,n.useState)(null),[Q,xe]=(0,n.useState)("pending"),q=(f,W=!0)=>{j({msg:f,ok:W}),setTimeout(()=>j(null),3e3)},Re=[...new Set([...m,...i].map(f=>f.submittedBy).filter(Boolean))],U=(0,n.useCallback)(async()=>{try{let f=await fetch(`${_}/audit/list`).then(W=>W.json());f.ok&&(d(f.pending||[]),w(f.rejected||[]),I(new Set),H(new Set),ne({}))}catch{}},[]);(0,n.useEffect)(()=>{U()},[r,U]);let me=(Q==="pending"?m:i).filter(f=>{if(C!=="all"&&f.kind!==C||A!=="all"&&ut(f.submittedBy)!==A)return!1;if(h){let W=(f.created||"").slice(0,10);if(W&&W!==h)return!1}return!0}),le=f=>I(W=>{let de=new Set(W);return de.has(f)?de.delete(f):de.add(f),de}),F=async(f,W)=>{let de=W||[...D];if(!de.length){q(t("noSelection"),!1);return}T("apply");let Y=t(f==="approved"?"toastApproved":f==="rejected"?"toastRejected":"toastCardDeleted");try{let ie=0;for(let we of de){let Ae=f==="approved"?"audit/approve":f==="rejected"?"audit/reject":"delete";try{(await fetch(_+"/"+Ae+"?path="+encodeURIComponent(we)+(f==="delete"?"&permanent=0":""))).ok||ie++}catch{ie++}}await U(),o&&o(),ie?q(t("toastFailed")+"\uFF08"+ie+"/"+de.length+"\uFF09",!1):q(Y+" "+de.length+" \u5F20")}catch(ie){q(t("toastFailed")+": "+String(ie&&ie.message||ie),!1)}finally{T("")}},[y,H]=(0,n.useState)(new Set),[M,ne]=(0,n.useState)({}),K=f=>M[f]||{},X=async f=>{let W=f.path,de=!y.has(W);if(H(Y=>{let ie=new Set(Y);return de?ie.add(W):ie.delete(W),ie}),!(!de||M[W])){ne(Y=>({...Y,[W]:{loading:!0}}));try{let Y=f.status||(Q==="pending"?"pending":"rejected"),ie=await fetch(`${_}/card?path=${encodeURIComponent(W)}&status=${Y}`).then(we=>we.json());ie&&ie.ok?ne(we=>({...we,[W]:{text:ie.text||""}})):ne(we=>({...we,[W]:{error:ie&&ie.error||"HTTP"}}))}catch(Y){ne(ie=>({...ie,[W]:{error:String(Y&&Y.message||Y)}}))}}},re=[...D];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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(ea,{toast:N}),(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:C,onChange:f=>x(f.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")}),Rt.filter(f=>f!=="all").map(f=>(0,e.jsx)("option",{value:f,children:t($e[f])},f))]}),(0,e.jsxs)("select",{value:A,onChange:f=>k(f.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")}),Zt(Re).map(f=>(0,e.jsx)("option",{value:f,children:f},f))]}),(0,e.jsx)("input",{type:"date",value:h,onChange:f=>u(f.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${Q==="pending"?" me-on":""}`,onClick:()=>xe("pending"),children:[t("pending"),"\uFF08",m.length,"\uFF09"]}),(0,e.jsxs)("button",{type:"button",className:`mc-btn${Q==="rejected"?" me-on":""}`,onClick:()=>xe("rejected"),children:[t("rejected"),"\uFF08",i.length,"\uFF09"]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("label",{style:{fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:me.length>0&&re.length===me.length,onChange:f=>{f.target.checked?I(new Set(me.map(W=>W.path))):I(new Set)}})," ",t("selectAll")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!re.length||!!v,onClick:()=>F("approved"),children:["\u2713 ",t(Q==="rejected"?"restore":"approve")]}),Q==="pending"?(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!re.length||!!v,onClick:()=>F("rejected"),children:["\u2715 ",t("reject")]}):(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!re.length||!!v,onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&F("delete")},children:["\u{1F5D1} ",t("restoreDelete")]})]}),me.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:me.map(f=>{let W=K(f.path),de=y.has(f.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:D.has(f.path),onChange:()=>le(f.path)}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"0 6px"},title:t(de?"collapse":"expand"),"aria-expanded":de,onClick:()=>X(f),children:de?"\u25BE":"\u25B8"}),(0,e.jsx)("span",{className:"mc-kind",style:{background:_e[f.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},title:t(de?"collapse":"expand"),onClick:()=>X(f),children:f.title}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:ut(f.submittedBy)}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:f.created?f.created.slice(0,16).replace("T"," "):"-"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:f.kind}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,color:f.severity==="high"?"#f87171":"#9ca3af"},children:f.severity}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f.reason||"-"}),Q==="pending"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>F("approved",[f.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>F("rejected",[f.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:()=>F("approved",[f.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"))&&F("delete",[f.path])},children:"\u{1F5D1}"})]})]}),de&&(0,e.jsxs)("div",{style:{padding:"2px 10px 12px 34px"},children:[W.loading&&(0,e.jsxs)("div",{style:{fontSize:12,opacity:.6},children:["\u23F3 ",t("loading")]}),W.error&&(0,e.jsxs)("div",{style:{fontSize:12,color:"#f87171"},children:["\u26A0 ",t("auditBodyFail"),"\uFF1A",W.error]}),W.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:_e[f.kind]||"#6B7280",borderColor:(_e[f.kind]||"#6B7280")+"59",background:(_e[f.kind]||"#6B7280")+"1a"},children:[ht[f.kind]||"\u{1F4CE}"," ",t($e[f.kind]||"kindKnowledge")]}),(Array.isArray(f.tags)?f.tags:[]).slice(0,8).map(Y=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",Y]},Y)),!!f.reason&&(0,e.jsxs)("span",{className:"md-chip md-chip-st-warn",children:["\u2691 ",f.reason]})]}),(0,e.jsx)("div",{className:"md-doc",style:{maxHeight:340,overflow:"auto"},dangerouslySetInnerHTML:{__html:Tt(Ct(W.text).body)}}),Q==="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:!!v,onClick:()=>F("approved",[f.path]),children:["\u2713 ",t("approve")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!v,onClick:()=>F("rejected",[f.path]),children:["\u2715 ",t("reject")]})]})]})]})]},f.path)})}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:t("noAuditItems")})]})]})}function Ia({t,onReload:o,version:r}){let[m,d]=(0,n.useState)([]),[i,w]=(0,n.useState)(""),[C,x]=(0,n.useState)(null),A=(u,D=!0)=>{x({msg:u,ok:D}),setTimeout(()=>x(null),3200)},k=(0,n.useCallback)(async()=>{try{let u=await fetch(`${_}/recycle/list`).then(D=>D.json());u.ok&&d(u.items||[])}catch{}},[]);(0,n.useEffect)(()=>{k()},[r,k]);let h=async(u,D)=>{let I=(m.find(v=>v.path===D)||{}).title||D;w(u+D);try{let T=await fetch(_+(u==="restore"?"/recycle/restore":"/recycle/purge")+"?path="+encodeURIComponent(D)),N=await T.json().catch(()=>null);await k(),o&&o(),T.ok&&(!N||N.ok!==!1)?A(t(u==="restore"?"toastRestored":"toastPurged")+"\uFF1A"+I):A(t("toastFailed")+"\uFF1A"+(N&&N.error||"HTTP "+T.status),!1)}catch(v){A(t("toastFailed")+"\uFF1A"+String(v&&v.message||v),!1)}finally{w("")}};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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(ea,{toast:C}),(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:!!i||m.length===0,title:m.length?"":t("emptyRecycle"),onClick:async()=>{w("purgeAll");try{let u=await fetch(_+"/recycle/purge-expired?days=0"),D=await u.json().catch(()=>null);await k(),A(u.ok?t("toastPurgedExpired")+(D&&D.purged!=null?"\uFF08"+D.purged+"\uFF09":""):t("toastFailed"),u.ok)}catch(u){A(t("toastFailed")+"\uFF1A"+String(u&&u.message||u),!1)}finally{w("")}},children:t("emptyRecycle")})]}),m.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:m.map(u=>(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:_e[u.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.title}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[t("deletedAt")," ",(u.deletedAt||"").slice(0,10)]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!i,onClick:()=>h("restore",u.path),children:t("restore")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!i,onClick:()=>{window.confirm(t("purgeConfirm"))&&h("purge",u.path)},children:t("purge")})]},u.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:o,onOpen:r,query:m,onDelete:d})=>(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:_e[t.kind]||_e.other}}),(0,e.jsx)("span",{style:{marginRight:4},children:ht[t.kind]||"\u{1F4CE}"}),m?Gt(t.title,m):t.title,Oa(t.updated)&&(0,e.jsx)("span",{className:"mc-new",children:o("newBadge")}),t.status==="pending"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",o("statusPending")]}),t.status==="rejected"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#ef4444"},children:["\u274C ",o("statusRejected")]}),(!t.status||t.status==="approved")&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#10b981"},children:["\u2705 ",o("statusApproved")]})]}),(0,e.jsx)("p",{children:m?Gt(t.summary||"",m):t.summary||""}),t.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:t.tags.slice(0,4).map(i=>(0,e.jsxs)("span",{className:"mc-tag",children:["\u{1F3F7} ",i]},i))}),(0,e.jsxs)("footer",{children:[(0,e.jsxs)("span",{children:[ht[t.kind]||"\u{1F4CE}"," ",o($e[t.kind])]}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",ut(t.submittedBy)]}),(0,e.jsxs)("span",{children:["\u{1F4C5} ",pt(t.updated)]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:o("delete"),onClick:i=>{i.stopPropagation(),window.confirm(o("deleteConfirm"))&&d&&d(t.path)},children:"\u{1F5D1}"})]})]});function Ra({t,tab:o,onReload:r,version:m}){let[d,i]=(0,n.useState)(null),[w,C]=(0,n.useState)(""),[x,A]=(0,n.useState)(null),[k,h]=(0,n.useState)(null),[u,D]=(0,n.useState)(null),[I,v]=(0,n.useState)([]),[T,N]=(0,n.useState)(""),[j,Q]=(0,n.useState)(!1),xe=(0,n.useCallback)(async()=>{if(!(!x||!x.merge||!x.merge.length)&&window.confirm(t("mergeAllConfirm"))){N("merge");try{let y={},H=re=>y[re]===void 0?re:y[re]=H(y[re]),M=(re,f)=>{y[H(re)]=H(f)},ne=new Set;for(let re of x.merge)ne.add(re.a.path),ne.add(re.b.path),M(re.a.path,re.b.path);let K={};for(let re of ne){let f=H(re);(K[f]=K[f]||[]).push(re)}let X=0;for(let re of Object.values(K)){if(re.length<2)continue;(await fetch(`${_}/merge?paths=${encodeURIComponent(re.join(","))}`).then(W=>W.json())).ok&&X++}await q(),r&&r()}catch{}N("")}},[x,q,r,t]);async function q(){try{let y=await Promise.all([fetch(`${_}/stats`),fetch(`${_}/budget`),fetch(`${_}/capture-log`),fetch(`${_}/cards?status=all&limit=30&agent=${yt}`)]),[H,M,ne,K]=await Promise.all(y.map(X=>X.json()));H&&H.ok&&i(H),M&&M.ok&&h(M),ne&&ne.ok&&D(ne),K&&K.ok&&v(K.cards||[]),C(!H||!H.ok?t("adminLoadFail"):"")}catch{C(t("adminLoadFail"))}}let Re=(0,n.useCallback)(async()=>{N("scan");try{let y=await fetch(`${_}/optimize`).then(H=>H.json());y.ok&&A(y)}catch{C(t("adminLoadFail"))}finally{N("")}},[t]);(0,n.useEffect)(()=>{q()},[m]);let U=async(y,H)=>{if(window.confirm(t("mergeConfirm")))try{(await fetch(`${_}/merge?paths=${encodeURIComponent(y+","+H)}`).then(ne=>ne.json())).ok&&(await q(),r&&r())}catch{}},me=async y=>{if(window.confirm(t("deleteConfirm")))try{(await fetch(`${_}/delete?path=${encodeURIComponent(y)}`).then(M=>M.json())).ok&&(await q(),r&&r())}catch{}},le=["project","knowledge","content","prompt","business","tool","mistake"],F=({title:y,kind:H,updated:M,path:ne})=>(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:ct.colors[H]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:pt(M)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>me(ne),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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto"},children:[w&&(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 ",w]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:q,children:["\u21BB ",t("retry")]})]}),o==="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{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:()=>q(),children:["\u21BB ",t("refresh")]})]}),u?u.available===!1?(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:t("captureLogUnavailable")}):(u.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:(u.entries||[]).map((y,H)=>{let M=ka[y.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:pt(y.time?new Date(y.time).toISOString():"")}),(0,e.jsxs)("td",{style:{padding:"4px 6px",whiteSpace:"nowrap",color:M[1],fontWeight:600},children:[M[0]," ",y.action]}),(0,e.jsx)("td",{style:{padding:"4px 6px"},children:y.reason||""}),(0,e.jsx)("td",{style:{padding:"4px 6px",opacity:.55,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:y.preview||"",children:y.preview||""})]},H)})})})}):(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",I.length,"\uFF09"]}),I.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:I.map(y=>(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:_e[y.kind]||_e.other}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.title}),y.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:pt(y.updated)})]},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noCards")})]}),d&&(0,e.jsxs)(e.Fragment,{children:[d.trend&&d.trend.length>0&&(()=>{let y=d.trend,H=Math.max(...y.map(X=>X.count),1),M=260,ne=50,K=M/y.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:M,height:ne,style:{display:"block",width:"100%",height:50},children:y.map((X,re)=>{let f=Math.round(X.count/H*(ne-4));return(0,e.jsx)("rect",{x:re*K+1,y:ne-f,width:Math.max(K-2,2),height:f,rx:1.5,fill:X.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:X.count>0?.85:.35},X.date)})})]})})(),(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.total}),(0,e.jsx)("span",{children:t("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.today}),(0,e.jsx)("span",{children:t("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.week}),(0,e.jsx)("span",{children:t("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.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:le.map(y=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:ct.colors[y]||"#666"}}),t($e[y]),": ",d.byKind?.[y]||0]},y))})]}),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",d.todayCards?.length||0,"\uFF09"]}),d.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:d.todayCards.map(y=>(0,e.jsx)(F,{title:y.title,kind:y.kind,updated:y.updated,path:y.path},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})]})]}),o==="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:!!T,onClick:Re,children:T==="scan"?t("exporting"):"\u{1F50D} "+t("scanAndOrganize")}),x&&x.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!T,onClick:async()=>{if(window.confirm(t("oneClickOptimizeConfirm"))){N("oneclick");try{let y=JSON.stringify({cleanupStale:j}),M=await(await fetch(`${_}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:y})).json();M&&M.ok?(notify(`${t("oneClickOptimizeDone")}\uFF1A${M.plan.merged} ${t("optimizedMerged")}${j?` \xB7 ${M.plan.staleDeleted} ${t("optimizedStaleDeleted")}`:""}`),await q(),r&&r(),A(null)):notify(t("mergeFail"),!1)}catch{notify(t("mergeFail"),!1)}finally{N("")}}},children:T==="oneclick"?t("exporting"):"\u26A1 "+t("oneClickOptimize")}),x&&x.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:j,onChange:y=>Q(y.target.checked)}),t("oneClickAlsoStale")]})]}),!x&&(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:t("scanHint")}),x&&(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}}),x.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!T,onClick:xe,children:t(T==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("mergePairs")}),x.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:x.merge.map((y,H)=>(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:[y.a.title," \u21C4 ",y.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(y.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>U(y.a.path,y.b.path),children:t("mergeNow")})]},H))}):(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",x.stale?.length||0,"\uFF09"]}),x.stale?.length>0&&(0,e.jsx)("div",{style:{marginBottom:6},children:(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!T,onClick:async()=>{if(!window.confirm(t("deleteConfirm")))return;N("clean");let y=0;for(let H of x.stale)try{await fetch(`${_}/delete?path=${encodeURIComponent(H.path)}`),y++}catch{}N(""),notify(`${y} ${t("deletedStale")}`),await q(),r&&r()},children:t("cleanStale")})}),x.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:x.stale.map(y=>(0,e.jsx)(F,{title:y.title,kind:"other",updated:y.updated,path:y.path},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})})]})]})]})}var Lt=[{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 Aa({t,newCard:o,setNewCard:r,onCreated:m}){if(!o)return null;let d=Lt.find(h=>h.key===o.template),i=o.body||(d?t(d.bodyKey):""),w=o.kind||(d?d.kind:"knowledge"),C=o.tags||(d?t(d.tagKey):""),x=o._creating,A=h=>{let u=Lt.find(D=>D.key===h);r(D=>({...D,template:h,kind:u?u.kind:D.kind,body:u?t(u.bodyKey):D.body,tags:u?t(u.tagKey):D.tags}))},k=async()=>{if(!(!o.title&&!i)){r(h=>({...h,_creating:!0}));try{(await fetch(`${_}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:o.title||t("untitled"),kind:w,tags:C.split(",").map(u=>u.trim()).filter(Boolean),body:i,source:"manual"})}).then(u=>u.json())).ok?(r(null),m&&m()):r(u=>({...u,_creating:!1}))}catch{r(u=>({...u,_creating:!1}))}}};return(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>r(null),children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:h=>h.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:[Lt.map(h=>(0,e.jsx)("button",{type:"button",className:`mc-btn${o.template===h.key?" me-on":""}`,onClick:()=>A(h.key),children:t(h.label)},h.key)),(0,e.jsx)("button",{type:"button",className:`mc-btn${o.template===""?" me-on":""}`,onClick:()=>r(h=>({...h,template:"",body:"",tags:"",kind:"knowledge"})),children:t("tplBlank")})]}),(0,e.jsx)("select",{className:"mc-btn",value:w,onChange:h=>r(u=>({...u,kind:h.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(h=>(0,e.jsx)("option",{value:h,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:h},h))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("cardTitle"),value:o.title||"",onChange:h=>r(u=>({...u,title:h.target.value}))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("tagsHint"),value:C,onChange:h=>r(u=>({...u,tags:h.target.value}))}),(0,e.jsx)("textarea",{className:"mc-btn",placeholder:t("cardBody"),value:i,onChange:h=>r(u=>({...u,body:h.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:x,onClick:k,children:t(x?"exporting":"createCard")})})]})]})]})}async function Vt(t){let o=String(t||"");if(!o)return!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(o),!0}catch{}try{let r=document.createElement("textarea");r.value=o,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();let m=!!(document.execCommand&&document.execCommand("copy"));return document.body.removeChild(r),m}catch{return!1}}function Ba({t,onClose:o}){let[r,m]=(0,n.useState)(""),[d,i]=(0,n.useState)(""),[w,C]=(0,n.useState)(""),[x,A]=(0,n.useState)(!0),[k,h]=(0,n.useState)(!1),[u,D]=(0,n.useState)(""),[I,v]=(0,n.useState)(""),T=(0,n.useRef)(null),N=(0,n.useRef)(null),j=()=>{let F=T.current;if(F)try{F.focus(),F.select()}catch{}},Q=F=>{D(F),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>D(""),2400)};(0,n.useEffect)(()=>{let F=!0;return fetch(_+"/diagnostics").then(y=>y.json()).then(y=>{F&&(y&&y.ok?(i(String(y.diagnostics||"")),C(String(y.version||""))):h(!0))}).catch(()=>{F&&h(!0)}).finally(()=>{F&&A(!1)}),()=>{F=!1}},[]),(0,n.useEffect)(()=>{let F=y=>{y.key==="Escape"&&o()};return window.addEventListener("keydown",F),()=>{window.removeEventListener("keydown",F),N.current&&clearTimeout(N.current)}},[o]);let xe=(()=>{try{return String(navigator.language||"").toLowerCase().startsWith("en")?"en":"zh"}catch{return"zh"}})(),q=()=>{let F=r.trim().split(`
|
|
305
|
+
`);let Ie=new Blob([G],{type:ze}),Ue=await Wa(Ie,he,!1);if(!Ue.ok){K({ok:!1,msg:t("exportFail")}),W(!1);return}K({ok:!0,msg:t("exportedTo")+"\uFF1A"+t("defaultDownloads")+" \xB7 "+Ue.name})}catch(Z){K({ok:!1,msg:t("exportFail")+" \xB7 "+(Z.message||"")})}finally{W(!1)}X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2600)},be=async b=>{let P=b.target.files&&b.target.files[0];if(b.target.value="",!!P){try{let Z=await P.text(),G=await(await fetch(`${_}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:Z})).json();if(G.ok){await ge();let he=G.imported||0,ze=t("importedVault")+"\uFF1A"+he;G.total&&(ze+=t("importedTotal")+G.total+t("importedTotalTail")),G.quarantined&&(ze+=t("importedQuarantine")+G.quarantined+t("importedQuarantineTail")),G.skipped&&(ze+=t("importedSkipped")+G.skipped+t("importedSkippedTail")),G.warning&&(ze+=" \xB7 "+G.warning),K({ok:he>0||!G.total,msg:ze})}else K({ok:!1,msg:G.error||t("importFail")})}catch{K({ok:!1,msg:t("importFail")})}X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2400)}},V=(0,n.useMemo)(()=>{let b=C.slice();return Q!=="all"&&(b=b.filter(P=>ut(P.submittedBy)===Q)),q!=="all"&&(b=b.filter(P=>(P.status||"approved")===q)),H==="title"?b.sort((P,Z)=>String(P.title||"").localeCompare(String(Z.title||""))):H==="hot"?b.sort((P,Z)=>(Z.weight||Z.links||0)-(P.weight||P.links||0)):b.sort((P,Z)=>new Date(Z.updated||0).getTime()-new Date(P.updated||0).getTime()),b},[C,H,Q,q]),oe=(0,n.useMemo)(()=>[...new Set(C.map(b=>ut(b.submittedBy)))],[C]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:Fe}),ne&&(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 "+(ne.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:ne.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:ne.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:ne.msg})]}),o&&(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)(Qt,{})}),(0,e.jsx)("h2",{children:t("memoryTitle")}),(0,e.jsx)("span",{children:t("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),m&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:m,"aria-label":t(d?"exitFull":"fullscreen"),children:d?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:r,"aria-label":t("close"),children:"\u2715"})]}),h&&h.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:[h.reason,(0,e.jsx)("div",{style:{opacity:.68,fontSize:11.5,marginTop:2},children:t("captureAlertHint")})]}),(0,e.jsx)("span",{style:{opacity:.7},children:h.since?pt(new Date(h.since).toISOString()):""})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:`mc-rail${ve?" open":""}`,children:[(0,e.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>Ce(b=>!b),"aria-label":t(ve?"collapse":"expand"),title:t(ve?"collapse":"expand"),children:ve?"\xAB":"\xBB"}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="cards"?" active":""}`,onClick:()=>y("cards"),title:t("cardsTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F9E0}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("cardsTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="graph"?" active":""}`,onClick:()=>y("graph"),title:t("graphTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F52E}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("graphTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="stats"?" active":""}`,onClick:()=>y("stats"),title:t("tabUsage"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C8}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabUsage")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="audit"?" active":""}`,onClick:()=>y("audit"),title:t("tabAudit"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F50D}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabAudit")}),Te>0&&(0,e.jsx)("span",{className:"mc-dot",children:Te>99?"99+":Te})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="optimize"?" active":""}`,onClick:()=>y("optimize"),title:t("tabRecycle"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u267B\uFE0F"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabRecycle")}),Be>0&&(0,e.jsx)("span",{className:"mc-dot",style:{background:"#6b7280"},children:Be>99?"99+":Be})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${U==="config"?" active":""}`,onClick:()=>y("config"),title:t("tabConfig"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabConfig")})]}),(0,e.jsxs)("button",{type:"button",className:"mc-railbtn",onClick:()=>Me(!0),title:t("fbNav"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F41E}"}),ve&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("fbNav")})]})]}),(0,e.jsxs)("div",{className:"mc-main",ref:se,children:[U==="cards"&&(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(dt,{label:t("total"),value:i?i.total:"\u2014"}),(0,e.jsx)(dt,{label:t("recent"),value:i?i.recent:"\u2014"}),(0,e.jsx)(dt,{label:t("tags"),value:i?i.tags:"\u2014"}),(0,e.jsx)(dt,{label:t("pending"),value:i?.quarantine?.pending??i?.status?.pending??0}),(0,e.jsx)(dt,{label:t("rejected"),value:i?.quarantine?.rejected??i?.status?.rejected??0}),(0,e.jsx)(dt,{label:t("cardCount"),value:i?i.byKind?.knowledge??0:"\u2014"})]}),U==="cards"&&(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:t("searchPlaceholder"),value:N,onChange:b=>l(b.target.value)}),(0,e.jsx)("input",{ref:re,type:"file",accept:".json,application/json",style:{display:"none"},onChange:be}),(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:()=>Ze({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",t("newCard")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:f,onClick:()=>J("md"),children:t(f?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:f,onClick:()=>J("json"),children:t(f?"exporting":"exportJson")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ge(),children:t("refresh")})]}),U==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[Rt.map(b=>(0,e.jsx)("button",{type:"button",className:`mc-chip${v===b?" active":""}`,onClick:()=>L(b),children:t(b==="all"?"all":$e[b])},b)),(0,e.jsxs)("select",{value:Q,onChange:b=>xe(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")]}),Zt(oe).map(b=>(0,e.jsx)("option",{value:b,children:b},b))]}),(0,e.jsxs)("select",{value:q,onChange:b=>Re(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${H===b.key?" active":""}`,onClick:()=>M(b.key),children:b.label},b.key))]}),D&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",D]}),(0,e.jsx)("div",{style:{display:U==="cards"?"contents":"none"},children:A?(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}):D?(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",D," ",(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ge(),children:t("retry")})]}):C.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:V.map(b=>(0,e.jsx)(La,{card:b,t,query:N.trim(),onOpen:B,onDelete:a},b.path))}),C.length<Ye&&(0,e.jsx)("div",{ref:E,style:{height:1}}),c&&(0,e.jsxs)("div",{className:"mc-empty",style:{padding:"10px 0"},children:[t("loading"),"\uFF08",C.length," / ",Ye,"\uFF09"]})]})}),(0,e.jsx)("div",{style:{display:U==="graph"?"flex":"none",flex:1,minHeight:0},children:le.has("graph")&&(0,e.jsx)(Ea,{t,onOpen:B,all:ie,onAllChange:we,onMutate:tt,active:U==="graph",visible:U==="graph"})}),(0,e.jsx)("div",{style:{display:U==="config"?"contents":"none"},children:le.has("config")&&(0,e.jsx)(ta,{t,onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="stats"?"contents":"none"},children:le.has("stats")&&(0,e.jsx)(Ra,{t,tab:"stats",onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="audit"?"contents":"none"},children:le.has("audit")&&(0,e.jsx)(Ta,{t,onReload:()=>ge(),version:Ve})}),(0,e.jsx)("div",{style:{display:U==="optimize"?"contents":"none"},children:le.has("optimize")&&(0,e.jsx)(Ia,{t,onReload:()=>ge(),version:Ve})}),Ae&&(0,e.jsx)(Ba,{t,onClose:()=>Me(!1)}),de&&(0,e.jsx)(Pa,{t,card:de,query:N.trim(),onClose:()=>Y(null),onDelete:b=>{Y(null),a(b)},onFeedback:b=>{let P=de.path;fetch(`${_}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:N.trim(),path:P,useful:b})}).then(()=>K({ok:!0,msg:t(b?"fbUseful":"fbIrr")})).catch(()=>{}),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2e3)}}),(0,e.jsx)(Aa,{t,newCard:et,setNewCard:Ze,onCreated:()=>{ge(),tt(),K({ok:!0,msg:t("created")}),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>K(null),2e3)}})]})]})]})}var ea=({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,dt=({label:t,value:o})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:o}),(0,e.jsx)("span",{children:t})]});function ta({t,onReload:o,version:r,compact:m}){let[d,i]=(0,n.useState)(null),[w,C]=(0,n.useState)(0),[x,A]=(0,n.useState)(null),[k,h]=(0,n.useState)(null),[u,D]=(0,n.useState)(!1),[I,v]=(0,n.useState)(!1),T=(0,n.useRef)(!1),N=(0,n.useRef)(null),j=(0,n.useRef)({}),[Q,xe]=(0,n.useState)(null),[q,Re]=(0,n.useState)(null),[U,me]=(0,n.useState)(""),[le,F]=(0,n.useState)(""),[y,H]=(0,n.useState)(""),[M,ne]=(0,n.useState)(null),K=(0,n.useCallback)(async l=>{F("version");try{let L=await fetch(_+"/version-check"+(l?"?force=1":"")).then(B=>B.json());L&&L.ok?(ne(L),l&&Y(L.updateAvailable?t("vcLatest")+" v"+L.latest:t("vcUpToDate"))):l&&Y(t("vcCheckFail"),!1)}catch{l&&Y(t("vcCheckFail"),!1)}finally{F("")}},[t]);(0,n.useEffect)(()=>{K(!1)},[r,K]);let[X,re]=(0,n.useState)(""),[f,W]=(0,n.useState)(null),de=(0,n.useRef)(null),Y=(l,L=!0)=>{de.current&&clearTimeout(de.current),W({msg:l,ok:L}),de.current=setTimeout(()=>W(null),1900)},ie=async()=>{if(!le){F("restart");try{let l=await fetch(_+"/restart-self",{method:"POST"});if(l.status===404||l.status===405){Y(Me("vcRestartNoRoute",{cmd:M&&M.restartCommand||"dsh-memory restart --port 7999"}),!1);return}let L=await l.json().catch(()=>null);if(!L){Y(t("vcRestartFail")+"\uFF08HTTP "+l.status+"\uFF09",!1);return}if(!L.ok){Y(L.error||t("vcRestartFail"),!1);return}if(L.alreadyCurrent){Y(L.note||t("vcRestartCurrent"));return}Y(L.note||t("vcRestartSent")),L.alreadyRunning||setTimeout(()=>{K(!0)},6e3)}catch(l){Y(t("vcRestartFail")+"\uFF1A"+String(l&&l.message||l),!1)}finally{F("")}}},we=M&&M.resident?String(M.resident.served||""):"",Ae=!!(M&&M.onDisk&&we&&we!==M.onDisk),Me=(l,L)=>Object.keys(L).reduce((B,J)=>B.split("{"+J+"}").join(L[J]),t(l)),ve=(0,n.useCallback)(async()=>{try{let[l,L,B]=await Promise.all([fetch(`${_}/config`).then(J=>J.json()).catch(()=>null),fetch(`${_}/setup-status`).then(J=>J.json()).catch(()=>null),fetch(`${_}/budget`).then(J=>J.json()).catch(()=>null)]);if(l&&l.ok){i(l),C(l.revision??0),A(l.schema??null);let J=qt(l.config??{},j.current);j.current=J.overlay,h({...J.values}),xe(l.dsh??null),D(l.writable===!1),v(l.viaPending===!0),me(""),T.current=!1}else B&&B.ok?(h({...B}),D(!0),me(t("configNeedsDsh"))):me(t("adminLoadFail"));L&&L.ok&&Re(L),H("")}catch{me(t("adminLoadFail"))}},[t]);(0,n.useEffect)(()=>{ve()},[r,ve]);let Ce=(l,L)=>{T.current=!0,h(B=>({...B??{},[l]:L}))};(0,n.useEffect)(()=>{N.current=ve},[ve]),(0,n.useEffect)(()=>{if(typeof EventSource>"u")return;let l=null;try{l=new EventSource(_+"/events")}catch{return}let L=()=>{!T.current&&typeof N.current=="function"&&N.current()};try{l.addEventListener("config",L)}catch{}return()=>{try{l.close()}catch{}}},[]);let et=new Set(["dedupThreshold","captureMinChars","captureCooldownMs","maxCardsPerDay","captureMaxTokens","recallMinScore","recallLimit","recallSummaryLen","recycleRetentionDays","webPort","webCheckIntervalMs","webMaxRestart","sessionBudgetChars"]),Ze=l=>({init:t("modeInit"),interval:t("modeInterval"),manual:t("modeManual")})[l]||l,Ve=async()=>{if(!k)return;if(u){Y(t("editInSetting"),!1);return}let l={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]},L=[];for(let[B,[J,be]]of Object.entries(l)){if(!(B in k))continue;let V=k[B],oe=typeof V=="number"?V:Number(V);(V===""||V===null||V===void 0||!Number.isFinite(oe)||oe<J||oe>be)&&L.push(t("invalidField",{field:B,min:J,max:be,value:String(V===""?"\u7A7A":V)}))}if(L.length){let B=t("saveInvalid")+"\uFF1A"+L.join("\uFF1B");me(B),Y(B,!1);return}F("save");try{let B={...k};for(let oe of Object.keys(k))oe in B&&typeof B[oe]=="string"&&B[oe].trim()!==""&&et.has(oe)&&(B[oe]=Number(B[oe]));Array.isArray(B.vaultProfiles)&&(B.vaultProfiles=B.vaultProfiles.filter(oe=>oe&&(String(oe.name||"").trim()||String(oe.path||"").trim())));let J=await fetch(`${_}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:B,expectedRevision:w})}),be=await J.text(),V=null;try{V=be?JSON.parse(be):null}catch{V=null}if(V||(V={error:"HTTP "+J.status+(be?"\uFF1A"+be.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")}),V&&V.ok){let oe=typeof V.pendingOutcome=="string"?V.pendingOutcome:"",b,P=!0;if(oe==="applied")b=t("savedApplied")+(Array.isArray(V.applied)&&V.applied.length?" \xB7 "+V.applied.join("\u3001"):"");else if(oe==="queued")P=!1,b=t("saveQueued");else if(oe==="failed")P=!1,b=t("saveFail")+" \xB7 "+(V.hostGuard?t("saveHostGuard"):t("saveFailHint"));else if(oe==="applied-direct")b=t("savedOk")+" \xB7 "+t("savedDirect");else{let Z=Array.isArray(V.pending)&&V.pending.length?" \xB7 "+t("savePending"):V.note?" \xB7 "+t("restartHint"):"";b=(V.retried?"\u267B ":"")+t("savedOk")+Z}j.current={...j.current,...B},P?H(b):me(b),Y(b,P),await ve()}else{let oe=J.status===409?t("conflictRefresh"):V?.error||t("saveFail");me(oe),Y(oe,!1)}}catch{me(t("saveFail")),Y(t("saveFail"),!1)}finally{F("")}},nt=()=>{j.current={},h({...d?.config??{}}),H("")},tt={env:"vaultSrcEnv",profile:"vaultSrcProfile",workspace:"vaultSrcWorkspace",vaultDir:"vaultSrcVaultDir",default:"vaultSrcDefault"},Te=l=>Array.isArray(l?.vaultProfiles)?l.vaultProfiles:[],Be=(l,L,B)=>h(J=>{let be=Te(J).map(oe=>({...oe||{}})),V={...be[l]||{}};return L==="match"?String(B).trim()?V.match={...V.match||{},workspace:B}:delete V.match:V[L]=B,be[l]=V,{...J??{},vaultProfiles:be}}),pe=()=>h(l=>({...l??{},vaultProfiles:[...Te(l),{name:"",path:""}]})),Ye=l=>h(L=>({...L??{},vaultProfiles:Te(L).filter((B,J)=>J!==l)})),Ne={fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},c={padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:12,minWidth:0},s={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}},E=async l=>{let L=s[l];L&&h(B=>({...B??{},...L}))},se=async(l,L)=>{F(l+L);try{let J=await(await fetch(`${_}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:l,action:L})})).json();J&&J.ok?Y(Me(L==="install"?"mcpInstalled":"mcpUninstalled",{agent:l})):Y(Me("mcpActionFail",{agent:l,error:J?.error||""}),!1);try{let be=await fetch(`${_}/setup-status`).then(V=>V.json());be&&be.ok&&Re(be)}catch{}}catch{Y(t("mergeFail"),!1)}finally{F("")}},$=({k:l,label:L,type:B="text",step:J,min:be,max:V})=>(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:L||l}),(0,e.jsx)("input",{type:B,step:J,min:be,max:V,value:k?k[l]??"":"",onChange:oe=>{let b=oe.target.value;Ce(l,B==="number"?b===""?"":Number(b):b)},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}})]}),ge=new Set(["autoRestartOnDrift"]),a=({k:l,label:L})=>{let B=k?k[l]:void 0,J=B===void 0?ge.has(l):!!B;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:J,onChange:be=>Ce(l,be.target.checked),style:{marginTop:2,flex:"0 0 auto"}}),(0,e.jsx)("span",{style:{whiteSpace:"normal",overflowWrap:"anywhere"},children:L||l})]})};return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:m?"0 0 auto":1,minHeight:0,maxHeight:m?"52vh":void 0},children:[(0,e.jsx)("style",{children:Fe}),f&&(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 "+(f.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:f.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:f.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:f.msg})]}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[U&&(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 ",U]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:ve,children:["\u21BB ",t("retry")]})]}),I&&(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")]}),u&&(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")]}),y&&(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 ",y]}),d&&(d.version||d.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")}),d.version&&(0,e.jsxs)("code",{style:Ne,children:[t("vcLoaded")," v",d.version]}),M&&M.resident&&M.resident.served&&M.resident.served!==d.version&&(0,e.jsxs)("code",{style:Ne,children:[t("vcResident")," v",M.resident.served]}),bt&&(0,e.jsxs)("code",{style:Ne,children:[t("vcPage")," v",bt]}),M&&M.onDisk&&(0,e.jsxs)("code",{style:Ne,children:[t("vcOnDisk")," v",M.onDisk]}),M&&M.latest&&(0,e.jsxs)("code",{style:Ne,children:[t("vcLatest")," v",M.latest]}),d.dsh?.vaultDir&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",d.dsh.vaultDir]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:le==="version",onClick:()=>K(!0),children:le==="version"?t("checking"):"\u{1F504} "+t("vcCheck")})]}),M&&M.stale&&(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 ",Me("vcStale",{disk:M.onDisk,loaded:M.loaded})]}),Ae?(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:!!le,onClick:ie,children:le==="restart"?"\u23F3 "+t("vcRestarting"):"\u{1F504} "+t("vcRestart")}),M.restartCommand&&(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:M.restartCommand})]}):(0,e.jsxs)("div",{style:{marginTop:6,lineHeight:1.7},children:["\u2139\uFE0F ",t("vcHostStale"),M.restartCommand&&(0,e.jsxs)(e.Fragment,{children:[" ",(0,e.jsx)("code",{style:{fontSize:11,opacity:.75},children:M.restartCommand})]})]})]}),bt&&M&&M.onDisk&&bt!==M.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:M.onDisk})}),M&&M.updateAvailable&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,opacity:.88},children:["\u2B06 ",t("vcOutdated")," \u2192 ",(0,e.jsx)("code",{children:M.updateCommand})]}),M&&M.checkError&&(0,e.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b91c1c"},children:[t("vcCheckFail"),"\uFF1A",M.checkError]})]}),q&&q.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:q.agents.map(l=>(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:l.isDsh?t("dshHostLabel"):l.name}),l.isDsh&&l.version&&(0,e.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",l.version]}),!l.installed&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",t("notInstalled"),")"]}),l.installed&&l.mcpConfigured===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",t("noMcpEntry"),")"]}),l.mcpConfigured===!0&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",t("healthy")]}),l.mcpConfigured===!0&&l.mcpMatchesCurrentNode===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",t("nodePathNote"),")"]}),l.isDsh&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",t("recallTool"),": ",l.recallTool?t("enabled"):t("disabled"),")"]})]}),l.hook&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",l.hook]}),!l.isDsh&&l.installed&&l.mcpConfigured===!1&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!le,onClick:()=>se(l.name,"install"),children:t("installMcp")}),!l.isDsh&&l.installed&&l.mcpConfigured===!0&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!le,onClick:()=>{window.confirm(t("uninstallConfirm"))&&se(l.name,"uninstall")},children:t("uninstallMcp")})]},l.name))}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:t("mcpSetupHint")}),X&&(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:X})})]}),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(l=>(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>E(l),disabled:!!le,children:[l==="A"?"\u{1F7E2} ":l==="B"?"\u{1F4B0} ":"\u2B50 ",s[l].label]},l))})]}),(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)(a,{k:"autoCapture",label:t("autoCapture")}),(0,e.jsx)(a,{k:"autoRecall",label:t("autoRecall")}),(0,e.jsx)($,{k:"captureMinChars",label:t("captureMinChars"),type:"number"}),(0,e.jsx)($,{k:"maxCardsPerDay",label:t("maxCardsPerDay"),type:"number"}),(0,e.jsx)($,{k:"dedupThreshold",label:t("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,e.jsx)($,{k:"recallLimit",label:t("recallLimit"),type:"number"}),(0,e.jsx)($,{k:"recallSummaryLen",label:t("recallSummaryLen"),type:"number"}),(0,e.jsx)(a,{k:"recallIncludeBody",label:t("recallBody")}),(0,e.jsx)($,{k:"secretHint",label:t("secretHint")}),(0,e.jsx)($,{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:Q?.vaultDir||"\u2014"}),Q?.vaultName?`\uFF08${Q.vaultName}\uFF09`:""," \xB7 ",t("vaultSource"),"\uFF1A",t(tt[Q?.vaultSource]||"vaultSrcDefault"),Q?.workspace?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),t("vaultWorkspace"),"\uFF1A",(0,e.jsx)("code",{children:Q.workspace})]}):null]}),Te(k).map((l,L)=>(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.6fr 1.5fr auto",gap:6,marginBottom:6},children:[(0,e.jsx)("input",{value:l.name||"",placeholder:t("vaultNamePh"),onChange:B=>Be(L,"name",B.target.value),style:c,disabled:u}),(0,e.jsx)("input",{value:l.path||"",placeholder:t("vaultPathPh"),onChange:B=>Be(L,"path",B.target.value),style:c,disabled:u}),(0,e.jsx)("input",{value:l.match&&l.match.workspace||"",placeholder:t("vaultMatchPh"),onChange:B=>Be(L,"match",B.target.value),style:c,disabled:u}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>Ye(L),disabled:u,title:t("delete"),children:"\u2715"})]},L)),(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:pe,disabled:u,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:l=>Ce("activeVault",l.target.value),disabled:u,style:c,children:[(0,e.jsx)("option",{value:"",children:t("vaultActiveNone")}),Te(k).filter(l=>l&&l.name).map(l=>(0,e.jsx)("option",{value:l.name,children:l.name},l.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)(a,{k:"enabled",label:t("enabledLabel")}),(0,e.jsx)($,{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)(a,{k:"distillEnabled",label:t("distillEnabled")}),(0,e.jsx)(a,{k:"dedupByLLM",label:t("dedupByLLM")}),(0,e.jsx)($,{k:"captureMaxTokens",label:t("captureMaxTokens"),type:"number"}),(0,e.jsx)($,{k:"recallMinScore",label:t("recallMinScore"),type:"number"}),(0,e.jsx)($,{k:"captureCooldownMs",label:t("captureCooldownMs"),type:"number"}),(0,e.jsx)($,{k:"captureProvider",label:t("captureProvider")}),(0,e.jsx)($,{k:"captureModel",label:t("captureModel")}),(0,e.jsx)($,{k:"sessionBudgetChars",label:t("sessionBudgetChars"),type:"number"})]})]}),(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:l=>Ce("auditMode",l.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)(Yt,{label:t("auditExemptAgents"),value:k.auditExemptAgents||[],options:[{value:"__all__",label:t("allExempt")},...(q?.agents||[]).filter(l=>!l.isDsh).map(l=>({value:l.name,label:l.name}))],onChange:l=>Ce("auditExemptAgents",l)}),(0,e.jsx)(Yt,{label:t("auditExemptKinds"),value:k.auditExemptKinds||[],options:[{value:"__all__",label:t("allExempt")},...Rt.filter(l=>l!=="all").map(l=>({value:l,label:t($e[l])}))],onChange:l=>Ce("auditExemptKinds",l)}),(0,e.jsx)($,{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)(a,{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:l=>Ce("autoWebMode",l.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)($,{k:"webPort",label:t("webPort"),type:"number"}),(0,e.jsx)($,{k:"webCheckIntervalMs",label:t("webCheckIntervalMs"),type:"number"}),(0,e.jsx)($,{k:"webMaxRestart",label:t("webMaxRestart"),type:"number"}),(0,e.jsx)(a,{k:"watchdogAutoSpawn",label:t("watchdogAutoSpawn")}),(0,e.jsx)(a,{k:"autoRestartOnDrift",label:t("autoRestartOnDrift")}),(0,e.jsx)(a,{k:"autoMcpSetup",label:t("autoMcpSetup")})]})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",alignItems:"center",marginBottom:10,flexWrap:"wrap"},children:[le==="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,opacity:.75},children:["\u23F3 ",t("saving")]}),y&&le!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#10b981"},children:["\u2705 ",y]}),U&&le!=="save"&&(0,e.jsxs)("span",{style:{fontSize:11.5,color:"#b91c1c"},children:["\u26A0 ",U]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:nt,disabled:!!le,children:t("reset")}),(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:u?()=>Y(t("readonlyTitle")+"\uFF1A"+t("readonlyBody"),!1):Ve,disabled:le==="save",title:t(u?"readonlyBody":"saveConfig"),children:le==="save"?"\u23F3 "+t("saving"):u?"\u{1F512} "+t("readonlyBtn"):"\u{1F4BE} "+t("saveConfig")})]})]}):(0,e.jsx)("div",{style:{fontSize:12,opacity:.6},children:t("loading")})]})]})}function Ta({t,onReload:o,version:r}){let[m,d]=(0,n.useState)([]),[i,w]=(0,n.useState)([]),[C,x]=(0,n.useState)("all"),[A,k]=(0,n.useState)("all"),[h,u]=(0,n.useState)(""),[D,I]=(0,n.useState)(new Set),[v,T]=(0,n.useState)(""),[N,j]=(0,n.useState)(null),[Q,xe]=(0,n.useState)("pending"),q=(f,W=!0)=>{j({msg:f,ok:W}),setTimeout(()=>j(null),3e3)},Re=[...new Set([...m,...i].map(f=>f.submittedBy).filter(Boolean))],U=(0,n.useCallback)(async()=>{try{let f=await fetch(`${_}/audit/list`).then(W=>W.json());f.ok&&(d(f.pending||[]),w(f.rejected||[]),I(new Set),H(new Set),ne({}))}catch{}},[]);(0,n.useEffect)(()=>{U()},[r,U]);let me=(Q==="pending"?m:i).filter(f=>{if(C!=="all"&&f.kind!==C||A!=="all"&&ut(f.submittedBy)!==A)return!1;if(h){let W=(f.created||"").slice(0,10);if(W&&W!==h)return!1}return!0}),le=f=>I(W=>{let de=new Set(W);return de.has(f)?de.delete(f):de.add(f),de}),F=async(f,W)=>{let de=W||[...D];if(!de.length){q(t("noSelection"),!1);return}T("apply");let Y=t(f==="approved"?"toastApproved":f==="rejected"?"toastRejected":"toastCardDeleted");try{let ie=0;for(let we of de){let Ae=f==="approved"?"audit/approve":f==="rejected"?"audit/reject":"delete";try{(await fetch(_+"/"+Ae+"?path="+encodeURIComponent(we)+(f==="delete"?"&permanent=0":""))).ok||ie++}catch{ie++}}await U(),o&&o(),ie?q(t("toastFailed")+"\uFF08"+ie+"/"+de.length+"\uFF09",!1):q(Y+" "+de.length+" \u5F20")}catch(ie){q(t("toastFailed")+": "+String(ie&&ie.message||ie),!1)}finally{T("")}},[y,H]=(0,n.useState)(new Set),[M,ne]=(0,n.useState)({}),K=f=>M[f]||{},X=async f=>{let W=f.path,de=!y.has(W);if(H(Y=>{let ie=new Set(Y);return de?ie.add(W):ie.delete(W),ie}),!(!de||M[W])){ne(Y=>({...Y,[W]:{loading:!0}}));try{let Y=f.status||(Q==="pending"?"pending":"rejected"),ie=await fetch(`${_}/card?path=${encodeURIComponent(W)}&status=${Y}`).then(we=>we.json());ie&&ie.ok?ne(we=>({...we,[W]:{text:ie.text||""}})):ne(we=>({...we,[W]:{error:ie&&ie.error||"HTTP"}}))}catch(Y){ne(ie=>({...ie,[W]:{error:String(Y&&Y.message||Y)}}))}}},re=[...D];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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(ea,{toast:N}),(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:C,onChange:f=>x(f.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")}),Rt.filter(f=>f!=="all").map(f=>(0,e.jsx)("option",{value:f,children:t($e[f])},f))]}),(0,e.jsxs)("select",{value:A,onChange:f=>k(f.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")}),Zt(Re).map(f=>(0,e.jsx)("option",{value:f,children:f},f))]}),(0,e.jsx)("input",{type:"date",value:h,onChange:f=>u(f.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${Q==="pending"?" me-on":""}`,onClick:()=>xe("pending"),children:[t("pending"),"\uFF08",m.length,"\uFF09"]}),(0,e.jsxs)("button",{type:"button",className:`mc-btn${Q==="rejected"?" me-on":""}`,onClick:()=>xe("rejected"),children:[t("rejected"),"\uFF08",i.length,"\uFF09"]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("label",{style:{fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:me.length>0&&re.length===me.length,onChange:f=>{f.target.checked?I(new Set(me.map(W=>W.path))):I(new Set)}})," ",t("selectAll")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!re.length||!!v,onClick:()=>F("approved"),children:["\u2713 ",t(Q==="rejected"?"restore":"approve")]}),Q==="pending"?(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!re.length||!!v,onClick:()=>F("rejected"),children:["\u2715 ",t("reject")]}):(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!re.length||!!v,onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&F("delete")},children:["\u{1F5D1} ",t("restoreDelete")]})]}),me.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:me.map(f=>{let W=K(f.path),de=y.has(f.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:D.has(f.path),onChange:()=>le(f.path)}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"0 6px"},title:t(de?"collapse":"expand"),"aria-expanded":de,onClick:()=>X(f),children:de?"\u25BE":"\u25B8"}),(0,e.jsx)("span",{className:"mc-kind",style:{background:_e[f.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},title:t(de?"collapse":"expand"),onClick:()=>X(f),children:f.title}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:ut(f.submittedBy)}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:f.created?f.created.slice(0,16).replace("T"," "):"-"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:f.kind}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,color:f.severity==="high"?"#f87171":"#9ca3af"},children:f.severity}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f.reason||"-"}),Q==="pending"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>F("approved",[f.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>F("rejected",[f.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:()=>F("approved",[f.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"))&&F("delete",[f.path])},children:"\u{1F5D1}"})]})]}),de&&(0,e.jsxs)("div",{style:{padding:"2px 10px 12px 34px"},children:[W.loading&&(0,e.jsxs)("div",{style:{fontSize:12,opacity:.6},children:["\u23F3 ",t("loading")]}),W.error&&(0,e.jsxs)("div",{style:{fontSize:12,color:"#f87171"},children:["\u26A0 ",t("auditBodyFail"),"\uFF1A",W.error]}),W.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:_e[f.kind]||"#6B7280",borderColor:(_e[f.kind]||"#6B7280")+"59",background:(_e[f.kind]||"#6B7280")+"1a"},children:[ht[f.kind]||"\u{1F4CE}"," ",t($e[f.kind]||"kindKnowledge")]}),(Array.isArray(f.tags)?f.tags:[]).slice(0,8).map(Y=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",Y]},Y)),!!f.reason&&(0,e.jsxs)("span",{className:"md-chip md-chip-st-warn",children:["\u2691 ",f.reason]})]}),(0,e.jsx)("div",{className:"md-doc",style:{maxHeight:340,overflow:"auto"},dangerouslySetInnerHTML:{__html:Tt(Ct(W.text).body)}}),Q==="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:!!v,onClick:()=>F("approved",[f.path]),children:["\u2713 ",t("approve")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!v,onClick:()=>F("rejected",[f.path]),children:["\u2715 ",t("reject")]})]})]})]})]},f.path)})}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:t("noAuditItems")})]})]})}function Ia({t,onReload:o,version:r}){let[m,d]=(0,n.useState)([]),[i,w]=(0,n.useState)(""),[C,x]=(0,n.useState)(null),A=(u,D=!0)=>{x({msg:u,ok:D}),setTimeout(()=>x(null),3200)},k=(0,n.useCallback)(async()=>{try{let u=await fetch(`${_}/recycle/list`).then(D=>D.json());u.ok&&d(u.items||[])}catch{}},[]);(0,n.useEffect)(()=>{k()},[r,k]);let h=async(u,D)=>{let I=(m.find(v=>v.path===D)||{}).title||D;w(u+D);try{let T=await fetch(_+(u==="restore"?"/recycle/restore":"/recycle/purge")+"?path="+encodeURIComponent(D)),N=await T.json().catch(()=>null);await k(),o&&o(),T.ok&&(!N||N.ok!==!1)?A(t(u==="restore"?"toastRestored":"toastPurged")+"\uFF1A"+I):A(t("toastFailed")+"\uFF1A"+(N&&N.error||"HTTP "+T.status),!1)}catch(v){A(t("toastFailed")+"\uFF1A"+String(v&&v.message||v),!1)}finally{w("")}};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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsx)(ea,{toast:C}),(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:!!i||m.length===0,title:m.length?"":t("emptyRecycle"),onClick:async()=>{w("purgeAll");try{let u=await fetch(_+"/recycle/purge-expired?days=0"),D=await u.json().catch(()=>null);await k(),A(u.ok?t("toastPurgedExpired")+(D&&D.purged!=null?"\uFF08"+D.purged+"\uFF09":""):t("toastFailed"),u.ok)}catch(u){A(t("toastFailed")+"\uFF1A"+String(u&&u.message||u),!1)}finally{w("")}},children:t("emptyRecycle")})]}),m.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:m.map(u=>(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:_e[u.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.title}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[t("deletedAt")," ",(u.deletedAt||"").slice(0,10)]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!i,onClick:()=>h("restore",u.path),children:t("restore")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!i,onClick:()=>{window.confirm(t("purgeConfirm"))&&h("purge",u.path)},children:t("purge")})]},u.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:o,onOpen:r,query:m,onDelete:d})=>(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:_e[t.kind]||_e.other}}),(0,e.jsx)("span",{style:{marginRight:4},children:ht[t.kind]||"\u{1F4CE}"}),m?Gt(t.title,m):t.title,Oa(t.updated)&&(0,e.jsx)("span",{className:"mc-new",children:o("newBadge")}),t.status==="pending"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",o("statusPending")]}),t.status==="rejected"&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#ef4444"},children:["\u274C ",o("statusRejected")]}),(!t.status||t.status==="approved")&&(0,e.jsxs)("span",{className:"mc-status",style:{background:"#10b981"},children:["\u2705 ",o("statusApproved")]})]}),(0,e.jsx)("p",{children:m?Gt(t.summary||"",m):t.summary||""}),t.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:t.tags.slice(0,4).map(i=>(0,e.jsxs)("span",{className:"mc-tag",children:["\u{1F3F7} ",i]},i))}),(0,e.jsxs)("footer",{children:[(0,e.jsxs)("span",{children:[ht[t.kind]||"\u{1F4CE}"," ",o($e[t.kind])]}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",ut(t.submittedBy)]}),(0,e.jsxs)("span",{children:["\u{1F4C5} ",pt(t.updated)]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:o("delete"),onClick:i=>{i.stopPropagation(),window.confirm(o("deleteConfirm"))&&d&&d(t.path)},children:"\u{1F5D1}"})]})]});function Ra({t,tab:o,onReload:r,version:m}){let[d,i]=(0,n.useState)(null),[w,C]=(0,n.useState)(""),[x,A]=(0,n.useState)(null),[k,h]=(0,n.useState)(null),[u,D]=(0,n.useState)(null),[I,v]=(0,n.useState)([]),[T,N]=(0,n.useState)(""),[j,Q]=(0,n.useState)(!1),xe=(0,n.useCallback)(async()=>{if(!(!x||!x.merge||!x.merge.length)&&window.confirm(t("mergeAllConfirm"))){N("merge");try{let y={},H=re=>y[re]===void 0?re:y[re]=H(y[re]),M=(re,f)=>{y[H(re)]=H(f)},ne=new Set;for(let re of x.merge)ne.add(re.a.path),ne.add(re.b.path),M(re.a.path,re.b.path);let K={};for(let re of ne){let f=H(re);(K[f]=K[f]||[]).push(re)}let X=0;for(let re of Object.values(K)){if(re.length<2)continue;(await fetch(`${_}/merge?paths=${encodeURIComponent(re.join(","))}`).then(W=>W.json())).ok&&X++}await q(),r&&r()}catch{}N("")}},[x,q,r,t]);async function q(){try{let y=await Promise.all([fetch(`${_}/stats`),fetch(`${_}/budget`),fetch(`${_}/capture-log`),fetch(`${_}/cards?status=all&limit=30&agent=${yt}`)]),[H,M,ne,K]=await Promise.all(y.map(X=>X.json()));H&&H.ok&&i(H),M&&M.ok&&h(M),ne&&ne.ok&&D(ne),K&&K.ok&&v(K.cards||[]),C(!H||!H.ok?t("adminLoadFail"):"")}catch{C(t("adminLoadFail"))}}let Re=(0,n.useCallback)(async()=>{N("scan");try{let y=await fetch(`${_}/optimize`).then(H=>H.json());y.ok&&A(y)}catch{C(t("adminLoadFail"))}finally{N("")}},[t]);(0,n.useEffect)(()=>{q()},[m]);let U=async(y,H)=>{if(window.confirm(t("mergeConfirm")))try{(await fetch(`${_}/merge?paths=${encodeURIComponent(y+","+H)}`).then(ne=>ne.json())).ok&&(await q(),r&&r())}catch{}},me=async y=>{if(window.confirm(t("deleteConfirm")))try{(await fetch(`${_}/delete?path=${encodeURIComponent(y)}`).then(M=>M.json())).ok&&(await q(),r&&r())}catch{}},le=["project","knowledge","content","prompt","business","tool","mistake"],F=({title:y,kind:H,updated:M,path:ne})=>(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:ct.colors[H]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:pt(M)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>me(ne),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:Fe}),(0,e.jsxs)("div",{style:{overflow:"auto"},children:[w&&(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 ",w]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:q,children:["\u21BB ",t("retry")]})]}),o==="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{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:()=>q(),children:["\u21BB ",t("refresh")]})]}),u?u.available===!1?(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:t("captureLogUnavailable")}):(u.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:(u.entries||[]).map((y,H)=>{let M=ka[y.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:pt(y.time?new Date(y.time).toISOString():"")}),(0,e.jsxs)("td",{style:{padding:"4px 6px",whiteSpace:"nowrap",color:M[1],fontWeight:600},children:[M[0]," ",y.action]}),(0,e.jsx)("td",{style:{padding:"4px 6px"},children:y.reason||""}),(0,e.jsx)("td",{style:{padding:"4px 6px",opacity:.55,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:y.preview||"",children:y.preview||""})]},H)})})})}):(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",I.length,"\uFF09"]}),I.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:I.map(y=>(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:_e[y.kind]||_e.other}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.title}),y.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:pt(y.updated)})]},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noCards")})]}),d&&(0,e.jsxs)(e.Fragment,{children:[d.trend&&d.trend.length>0&&(()=>{let y=d.trend,H=Math.max(...y.map(X=>X.count),1),M=260,ne=50,K=M/y.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:M,height:ne,style:{display:"block",width:"100%",height:50},children:y.map((X,re)=>{let f=Math.round(X.count/H*(ne-4));return(0,e.jsx)("rect",{x:re*K+1,y:ne-f,width:Math.max(K-2,2),height:f,rx:1.5,fill:X.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:X.count>0?.85:.35},X.date)})})]})})(),(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.total}),(0,e.jsx)("span",{children:t("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.today}),(0,e.jsx)("span",{children:t("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.week}),(0,e.jsx)("span",{children:t("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:d.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:le.map(y=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:ct.colors[y]||"#666"}}),t($e[y]),": ",d.byKind?.[y]||0]},y))})]}),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",d.todayCards?.length||0,"\uFF09"]}),d.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:d.todayCards.map(y=>(0,e.jsx)(F,{title:y.title,kind:y.kind,updated:y.updated,path:y.path},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})]})]}),o==="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:!!T,onClick:Re,children:T==="scan"?t("exporting"):"\u{1F50D} "+t("scanAndOrganize")}),x&&x.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!T,onClick:async()=>{if(window.confirm(t("oneClickOptimizeConfirm"))){N("oneclick");try{let y=JSON.stringify({cleanupStale:j}),M=await(await fetch(`${_}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:y})).json();M&&M.ok?(notify(`${t("oneClickOptimizeDone")}\uFF1A${M.plan.merged} ${t("optimizedMerged")}${j?` \xB7 ${M.plan.staleDeleted} ${t("optimizedStaleDeleted")}`:""}`),await q(),r&&r(),A(null)):notify(t("mergeFail"),!1)}catch{notify(t("mergeFail"),!1)}finally{N("")}}},children:T==="oneclick"?t("exporting"):"\u26A1 "+t("oneClickOptimize")}),x&&x.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:j,onChange:y=>Q(y.target.checked)}),t("oneClickAlsoStale")]})]}),!x&&(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:t("scanHint")}),x&&(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}}),x.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!T,onClick:xe,children:t(T==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("mergePairs")}),x.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:x.merge.map((y,H)=>(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:[y.a.title," \u21C4 ",y.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(y.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>U(y.a.path,y.b.path),children:t("mergeNow")})]},H))}):(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",x.stale?.length||0,"\uFF09"]}),x.stale?.length>0&&(0,e.jsx)("div",{style:{marginBottom:6},children:(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!T,onClick:async()=>{if(!window.confirm(t("deleteConfirm")))return;N("clean");let y=0;for(let H of x.stale)try{await fetch(`${_}/delete?path=${encodeURIComponent(H.path)}`),y++}catch{}N(""),notify(`${y} ${t("deletedStale")}`),await q(),r&&r()},children:t("cleanStale")})}),x.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:x.stale.map(y=>(0,e.jsx)(F,{title:y.title,kind:"other",updated:y.updated,path:y.path},y.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})})]})]})]})}var Lt=[{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 Aa({t,newCard:o,setNewCard:r,onCreated:m}){if(!o)return null;let d=Lt.find(h=>h.key===o.template),i=o.body||(d?t(d.bodyKey):""),w=o.kind||(d?d.kind:"knowledge"),C=o.tags||(d?t(d.tagKey):""),x=o._creating,A=h=>{let u=Lt.find(D=>D.key===h);r(D=>({...D,template:h,kind:u?u.kind:D.kind,body:u?t(u.bodyKey):D.body,tags:u?t(u.tagKey):D.tags}))},k=async()=>{if(!(!o.title&&!i)){r(h=>({...h,_creating:!0}));try{(await fetch(`${_}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:o.title||t("untitled"),kind:w,tags:C.split(",").map(u=>u.trim()).filter(Boolean),body:i,source:"manual"})}).then(u=>u.json())).ok?(r(null),m&&m()):r(u=>({...u,_creating:!1}))}catch{r(u=>({...u,_creating:!1}))}}};return(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>r(null),children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:h=>h.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:[Lt.map(h=>(0,e.jsx)("button",{type:"button",className:`mc-btn${o.template===h.key?" me-on":""}`,onClick:()=>A(h.key),children:t(h.label)},h.key)),(0,e.jsx)("button",{type:"button",className:`mc-btn${o.template===""?" me-on":""}`,onClick:()=>r(h=>({...h,template:"",body:"",tags:"",kind:"knowledge"})),children:t("tplBlank")})]}),(0,e.jsx)("select",{className:"mc-btn",value:w,onChange:h=>r(u=>({...u,kind:h.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(h=>(0,e.jsx)("option",{value:h,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:h},h))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("cardTitle"),value:o.title||"",onChange:h=>r(u=>({...u,title:h.target.value}))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("tagsHint"),value:C,onChange:h=>r(u=>({...u,tags:h.target.value}))}),(0,e.jsx)("textarea",{className:"mc-btn",placeholder:t("cardBody"),value:i,onChange:h=>r(u=>({...u,body:h.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:x,onClick:k,children:t(x?"exporting":"createCard")})})]})]})]})}async function Vt(t){let o=String(t||"");if(!o)return!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(o),!0}catch{}try{let r=document.createElement("textarea");r.value=o,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();let m=!!(document.execCommand&&document.execCommand("copy"));return document.body.removeChild(r),m}catch{return!1}}function Ba({t,onClose:o}){let[r,m]=(0,n.useState)(""),[d,i]=(0,n.useState)(""),[w,C]=(0,n.useState)(""),[x,A]=(0,n.useState)(!0),[k,h]=(0,n.useState)(!1),[u,D]=(0,n.useState)(""),[I,v]=(0,n.useState)(""),T=(0,n.useRef)(null),N=(0,n.useRef)(null),j=()=>{let F=T.current;if(F)try{F.focus(),F.select()}catch{}},Q=F=>{D(F),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>D(""),2400)};(0,n.useEffect)(()=>{let F=!0;return fetch(_+"/diagnostics").then(y=>y.json()).then(y=>{F&&(y&&y.ok?(i(String(y.diagnostics||"")),C(String(y.version||""))):h(!0))}).catch(()=>{F&&h(!0)}).finally(()=>{F&&A(!1)}),()=>{F=!1}},[]),(0,n.useEffect)(()=>{let F=y=>{y.key==="Escape"&&o()};return window.addEventListener("keydown",F),()=>{window.removeEventListener("keydown",F),N.current&&clearTimeout(N.current)}},[o]);let xe=(()=>{try{return String(navigator.language||"").toLowerCase().startsWith("en")?"en":"zh"}catch{return"zh"}})(),q=()=>{let F=r.trim().split(`
|
|
306
306
|
`)[0]||"",y=Ot({title:"[Bug] "+(F.slice(0,60)||"memory-eternal \u95EE\u9898"),body:Wt({description:r,diagnostics:d,version:w})});try{window.open(y,"_blank","noopener")}catch{Q(t("fbCopyFail"))}},Re=async()=>{await Vt(d)?(v(""),Q(t("fbCopiedDiag"))):(v(d),Q(t("fbCopyManual")))},U=async()=>{let F=$t({lang:xe,description:r,diagnostics:d});await Vt(F)?(v(""),Q(t("fbCopiedPrompt"))):(v(F),Q(t("fbCopyManual")))},me={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},le={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:o,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720},onClick:F=>F.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:o,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:F=>m(F.target.value),placeholder:t("fbDesc"),rows:5,style:me}),(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:Re,disabled:!d,children:t("fbCopyDiag")})]}),(0,e.jsx)("pre",{style:le,children:x?t("fbLoading"):k?t("fbDiagFail"):d})]}),(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()){Q(t("fbNeedDesc"));return}q()},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:U,children:["\u{1F916} ",t("fbCopyPrompt")]})]}),u&&(0,e.jsx)("div",{style:{fontSize:12,color:"var(--dsw-alias-brand-primary, #3b82f6)"},children:u}),I&&(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:j,children:t("fbSelectAll")})]}),(0,e.jsx)("textarea",{ref:T,readOnly:!0,value:I,rows:7,style:me})]})]})]})]})}function Pa({t,card:o,query:r,onClose:m,onDelete:d,onFeedback:i}){(0,n.useEffect)(()=>{let T=N=>{N.key==="Escape"&&m()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[m]);let{meta:w,body:C}=(0,n.useMemo)(()=>Ct(o.text||""),[o.text]),x=T=>{let N=w.find(([j])=>String(j).toLowerCase()===T);return N?N[1]:""},A=jt(x("tags")),k=x("kind")||"knowledge",h=(x("status")||"approved").toLowerCase(),u=_e[k]||"#6B7280",D=(C||"").length>460,[I,v]=(0,n.useState)(!0);return(0,e.jsxs)("div",{className:"me-overlay",onClick:m,children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("div",{className:"me-dialog",onClick:T=>T.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("h3",{children:[(0,e.jsx)("span",{style:{marginRight:6},children:ht[k]||"\u{1F4CE}"}),o.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:()=>i&&i(!0),children:["\u{1F44D} ",t("fbUseful")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>i&&i(!1),children:["\u{1F44E} ",t("fbNotUseful")]})]}),D&&(0,e.jsx)("button",{type:"button",className:"mc-btn","aria-expanded":I,onClick:()=>v(T=>!T),children:t(I?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(t("deleteConfirm"))&&d&&d(o.path)},children:t("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:m,children:t("close")})]})]}),(0,e.jsxs)("div",{className:"md-meta",children:[(0,e.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:u,borderColor:u+"59",background:u+"1a"},children:[ht[k]||"\u{1F4CE}"," ",t($e[k]||"kindKnowledge")]}),(0,e.jsxs)("span",{className:"md-chip "+(h==="approved"?"md-chip-st-ok":h==="pending"?"md-chip-st-warn":"md-chip-st-bad"),children:[h==="approved"?"\u2705":h==="pending"?"\u23F3":"\u26D4"," ",t(h==="approved"?"statusApproved":h==="pending"?"statusPending":"statusRejected")]}),A.slice(0,8).map(T=>(0,e.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",T]},T)),!!x("updated")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F552} ",t("updated")," ",pt(x("updated"))]}),!!x("source")&&(0,e.jsxs)("span",{className:"md-chip md-date",children:["\u{1F4E5} ",x("source")]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:I?{}:{maxHeight:300,overflow:"hidden"},onClick:I?void 0:T=>{T.stopPropagation(),v(!0)},children:(0,e.jsx)("div",{className:"md-doc",dangerouslySetInnerHTML:{__html:Tt(C)}})}),!I&&(0,e.jsxs)("div",{className:"md-collapsed-hint",onClick:T=>{T.stopPropagation(),v(!0)},children:[t("expand")," \u2304"]})]})]})}function Ea({t,onOpen:o,all:r,onAllChange:m,onMutate:d,active:i,visible:w}){let[C,x]=(0,n.useState)(null),[A,k]=(0,n.useState)(""),h=(0,n.useRef)(!1),u=(0,n.useRef)(0),D=(0,n.useRef)(t);D.current=t;let I=(0,n.useCallback)(async()=>{try{h.current=!1;let j=await(await fetch(`${_}/graph${r?"?all=1":""}`)).json();j.ok?(x(j),k(""),h.current=!0):(x(null),k(j.error||t("error")))}catch(N){k(String(N&&N.message?N.message:N))}},[r,t]);(0,n.useEffect)(()=>{if(!i||h.current)return;let N=!0;return fetch(`${_}/graph${r?"?all=1":""}`).then(j=>j.json()).then(j=>{N&&(j.ok?(x(j),k(""),h.current=!0):(x(null),k(j.error||t("error"))))}).catch(j=>{N&&k(String(j&&j.message?j.message:j))}),()=>{N=!1}},[r,t,i]),(0,n.useEffect)(()=>{w&&C&&u.current++},[w,C]);let v=(0,n.useCallback)(async N=>{try{let Q=await(await fetch(`${_}/delete?path=${encodeURIComponent(N)}`)).json();return Q&&Q.ok?(await I(),d&&d(),!0):!1}catch{return!1}},[I]),T=(0,n.useCallback)(async N=>{if(!N||N.length<2)return!1;try{let j=await fetch(`${_}/merge?paths=${encodeURIComponent(N.join(","))}`).then(Q=>Q.json());return j&&j.ok?(await I(),d&&d(),!0):!1}catch{return!1}},[I,d]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:Fe}),A&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",A]}),!C&&!A&&(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}),C&&C.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:t("emptyGraph")}),C&&C.nodes.length>0&&(0,e.jsx)(Ha,{nodes:C.nodes,edges:C.edges,onOpen:o,onDelete:v,onMerge:T,t,all:r,onAllChange:m,countLabel:`${C.nodes.length} ${t("nodes")} \xB7 ${Fa(C.edges)} ${t("edges")}`,fitTrigger:u.current})]})}function Fa(t){let o=new Set;for(let r of t||[])o.add([r.source,r.target].sort().join("|"));return o.size}var ct={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 Ha({nodes:t,edges:o,onOpen:r,onDelete:m,onMerge:d,t:i,countLabel:w,all:C,onAllChange:x,fitTrigger:A}){let k=(0,n.useRef)(null),h=(0,n.useRef)(null),u=(0,n.useRef)(null),D=(0,n.useRef)(null),I=(0,n.useRef)(null),v=(0,n.useRef)(r);(0,n.useEffect)(()=>{v.current=r},[r]);let T=(0,n.useRef)(m);(0,n.useEffect)(()=>{T.current=m},[m]);let N=(0,n.useRef)(d);(0,n.useEffect)(()=>{N.current=d},[d]);let[j,Q]=(0,n.useState)(""),[xe,q]=(0,n.useState)(null),Re=(0,n.useRef)("");(0,n.useEffect)(()=>{Re.current=j.trim().toLowerCase()},[j]),(0,n.useEffect)(()=>{let c=u.current;if(!c)return;let s=j.trim().toLowerCase();if(!s)return;let E=c.nodes.find(se=>(se.name||"").toLowerCase().includes(s));E&&(u.current.selectedId=E.id,q(E.id),c.panX=c.w/2-E.x*c.zoom,c.panY=c.h/2-E.y*c.zoom,c.render&&c.render())},[j]);let[U,me]=(0,n.useState)("all"),[le,F]=(0,n.useState)(!1),y=(0,n.useRef)("all"),[H,M]=(0,n.useState)(""),ne=(0,n.useRef)(""),[K,X]=(0,n.useState)(!1),re=(0,n.useRef)(!1),[f,W]=(0,n.useState)(null);(0,n.useEffect)(()=>{y.current=U},[U]),(0,n.useEffect)(()=>{ne.current=H},[H]),(0,n.useEffect)(()=>{re.current=K},[K]);let de=(0,n.useMemo)(()=>{let c=new Map;for(let s of t)for(let E of s.tags||[]){let se=String(E).trim();se&&c.set(se,(c.get(se)||0)+1)}return[...c.entries()].sort((s,E)=>E[1]-s[1]).slice(0,24).map(([s,E])=>({tag:s,n:E}))},[t]),Y=(()=>{let c=j.trim().toLowerCase();return!!c&&!t.some(s=>(s.title||s.name||"").toLowerCase().includes(c)||String(s.kind||"").toLowerCase().includes(c)||String($e[s.kind]||"").toLowerCase().includes(c))})();(0,n.useEffect)(()=>{let c=u.current;c&&c.wake&&c.wake()},[j]),(0,n.useEffect)(()=>{let c=u.current;c&&c.render&&c.render()},[U,H,K]);let ie=(0,n.useRef)(null),[we,Ae]=(0,n.useState)([]),[Me,ve]=(0,n.useState)(null),[Ce,et]=(0,n.useState)(!1),[Ze,Ve]=(0,n.useState)(null),[nt,tt]=(0,n.useState)(""),Te=(0,n.useRef)(null),Be=(0,n.useRef)(null),pe=(c,s=!0)=>{Te.current&&clearTimeout(Te.current),Ve({msg:c,ok:s}),Te.current=setTimeout(()=>Ve(null),1900)},Ye=c=>{tt(c),Be.current&&clearTimeout(Be.current),Be.current=setTimeout(()=>tt(""),1600)};(0,n.useEffect)(()=>()=>{Te.current&&clearTimeout(Te.current),Be.current&&clearTimeout(Be.current)},[]);let Ne=(0,n.useMemo)(()=>t.reduce((c,s)=>(c[s.id]=s,c),{}),[t]);return(0,n.useEffect)(()=>{let c=k.current;if(!c||t.length===0)return;let s=c.getContext("2d");if(!s)return;let E=Math.max(1,window.devicePixelRatio||1),se=()=>document.documentElement.getAttribute("data-theme")==="dark",$={};o.forEach(p=>{$[p.source]=($[p.source]||0)+1,$[p.target]=($[p.target]||0)+1});let ge=Math.max(1,...Object.values($)),a={nodes:t.map(p=>({id:p.id,name:p.title||"",type:p.kind||"other",r:9+Math.min(10,($[p.id]||0)/ge*8),x:0,y:0,vx:0,vy:0})),edges:o.map(p=>({sourceNodeId:p.source,targetNodeId:p.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:E,ctx:s,multi:[],marquee:null};a.domain=t,a.domainById=t.reduce((p,z)=>(p[z.id]=z,p),{}),a.nodes.forEach((p,z)=>{let S=z/a.nodes.length*Math.PI*2-Math.PI/2;p.x=Math.cos(S)*60,p.y=Math.sin(S)*60});let l=[...new Set(a.nodes.map(p=>p.type))];a.clustered=l.length>1,a.typeCenters={},l.forEach((p,z)=>{let S=z/l.length*Math.PI*2-Math.PI/2;a.typeCenters[p]={x:Math.cos(S)*160,y:Math.sin(S)*160}}),u.current=a;let L=0,B=0,J=()=>{let p=c.clientWidth,z=c.clientHeight;a.w=p,a.h=z,c.width=p*E,c.height=z*E,s.setTransform(E,0,0,E,0,0),(L===0||B===0)&&p>0&&z>0&&a.tickCount>0&&requestAnimationFrame(()=>Z()),L=p,B=z};J();let be=new ResizeObserver(J);be.observe(c.parentElement);let V=(p,z)=>p&&p.length>z?p.slice(0,z)+"\u2026":p,oe=(p,z,S,R)=>{if(s.beginPath(),R==="rect")s.rect(p-S,z-S*.75,S*2,S*1.5);else if(R==="diamond")s.moveTo(p,z-S),s.lineTo(p+S,z),s.lineTo(p,z+S),s.lineTo(p-S,z),s.closePath();else if(R==="hexagon"){for(let O=0;O<6;O++){let ce=Math.PI/3*O-Math.PI/2,ee=p+S*Math.cos(ce),De=z+S*Math.sin(ce);O===0?s.moveTo(ee,De):s.lineTo(ee,De)}s.closePath()}else s.arc(p,z,S,0,Math.PI*2)},b=new Map,P=(p,z)=>{let S=p+"|"+Math.round(z),R=b.get(S);if(!R){let O=parseInt(p.slice(1,3),16),ce=parseInt(p.slice(3,5),16),ee=parseInt(p.slice(5,7),16);R=s.createRadialGradient(-z*.3,-z*.3,0,0,0,z*1.2),R.addColorStop(0,"rgba("+Math.min(255,O+70)+","+Math.min(255,ce+70)+","+Math.min(255,ee+70)+",0.95)"),R.addColorStop(1,p),b.set(S,R)}return R},Z=()=>{if(!a.nodes.length)return;let p=1/0,z=-1/0,S=1/0,R=-1/0;a.nodes.forEach(je=>{p=Math.min(p,je.x),z=Math.max(z,je.x),S=Math.min(S,je.y),R=Math.max(R,je.y)});let O=20,ce=z-p+O*2,ee=R-S+O*2,De=Math.min(a.w/ce,a.h/ee);a.zoom=Math.max(.35,Math.min(1.8,De)),a.panX=a.w/2-(p+z)/2*a.zoom,a.panY=a.h/2-(S+R)/2*a.zoom};D.current=Z;let ke=()=>{s.clearRect(0,0,a.w,a.h),a.searchTerm=Re.current,a.kindFilter=y.current,a.timeMode=re.current,a.tagFilter=ne.current;let p=a.tagFilter,z=a.kindFilter,S=g=>String(g||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");s.save(),s.strokeStyle=se()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",s.lineWidth=.5;for(let g=0;g<a.w;g+=24)s.beginPath(),s.moveTo(g,0),s.lineTo(g,a.h),s.stroke();for(let g=0;g<a.h;g+=24)s.beginPath(),s.moveTo(0,g),s.lineTo(a.w,g),s.stroke();s.restore(),s.save(),s.translate(a.panX,a.panY),s.scale(a.zoom,a.zoom);let R={};a.nodes.forEach(g=>R[g.id]=g);let O=a.nodes.length>40,ce=O?1.5:.55,ee=a.selectedId||a.hoverId,De=_t({panX:a.panX,panY:a.panY,zoom:a.zoom,w:a.w,h:a.h,margin:80}),je=(()=>{let g=(a.searchTerm||"").toLowerCase();if(!g)return null;let te=[];for(let ae of a.nodes){let Se=(a.domainById[ae.id]||{}).kind||"other";if(((ae.name||"").toLowerCase().includes(g)||String($e[Se]||"").toLowerCase().includes(g)||String(Se).toLowerCase().includes(g))&&te.push(ae.id),te.length>200)break}return te})(),ot=Kt(a.nodes,{limit:Ut(a.nodes.length),focusId:ee,hoverId:a.hoverId,searchHits:je,degree:$}),ue=new Map,ye=(g,te)=>{let ae=g+"|"+te,fe=ue.get(ae);return fe===void 0&&(s.font=g,fe=s.measureText(te).width,ue.set(ae,fe)),fe},Pe=a.nodes.length<=250,Oe=new Map;a.edges.forEach(g=>{let te=R[g.sourceNodeId],ae=R[g.targetNodeId];if(!te||!ae||!Nt(te.x,te.y,10,De)&&!Nt(ae.x,ae.y,10,De))return;if(z!=="all"){let rt=a.domainById[g.sourceNodeId]&&a.domainById[g.sourceNodeId].kind,Je=a.domainById[g.targetNodeId]&&a.domainById[g.targetNodeId].kind;if(rt!==z&&Je!==z)return}if(p){let rt=a.domainById[g.sourceNodeId]&&(a.domainById[g.sourceNodeId].tags||[]).includes(p),Je=a.domainById[g.targetNodeId]&&(a.domainById[g.targetNodeId].tags||[]).includes(p);if(!rt&&!Je)return}let fe=ae.x-te.x,Se=ae.y-te.y,Le=Math.sqrt(fe*fe+Se*Se)||1,Qe=O?12:18,at=-Se/Le*Qe,xt=fe/Le*Qe,wt=(te.x+ae.x)/2+at,kt=(te.y+ae.y)/2+xt,mt=ct.colors[a.domainById[te.id]&&a.domainById[te.id].kind||"other"],gt=ee&&(g.sourceNodeId===ee||g.targetNodeId===ee),Mt=ee?gt?.6:.08:O?.14:.24,Xe=parseInt(mt.slice(1,3),16),ft=parseInt(mt.slice(3,5),16),Dt=parseInt(mt.slice(5,7),16),qe=gt?1.6+(g.weight||1):.8+(g.weight||1)*.5,it=Xe+","+ft+","+Dt+","+Mt+","+qe,We=Oe.get(it);We||(We={path:new Path2D,stroke:"rgba("+Xe+","+ft+","+Dt+","+Mt+")",width:qe},Oe.set(it,We)),We.path.moveTo(te.x,te.y),We.path.quadraticCurveTo(wt,kt,ae.x,ae.y)}),Oe.forEach(g=>{s.strokeStyle=g.stroke,s.lineWidth=g.width,s.stroke(g.path)});let Ee=null;ee&&(Ee=new Set,a.edges.forEach(g=>{g.sourceNodeId===ee?Ee.add(g.targetNodeId):g.targetNodeId===ee&&Ee.add(g.sourceNodeId)}));let Ge=[];if(a.nodes.forEach(g=>{if(!Nt(g.x,g.y,g.r+2,De))return;let te=a.domainById[g.id]||{},ae=te.kind||"other",fe=a.timeMode?ja(te.updated):ct.colors[ae],Se=ct.shapes[ae],Le=a.selectedId===g.id,Qe=a.hoverId===g.id,at=a.searchTerm||"",xt=!at||(g.name||"").toLowerCase().includes(at)||String($e[ae]||"").toLowerCase().includes(at)||String(ae).toLowerCase().includes(at),wt=z==="all"||ae===z,kt=!p||(te.tags||[]).includes(p),mt=ee&&g.id!==ee&&!(Ee&&Ee.has(g.id))||at&&!xt||!wt||!kt;s.save(),s.globalAlpha=mt?.08:1,(Le||Qe)&&Pe&&(s.shadowColor=fe,s.shadowBlur=Le?20:14),s.translate(g.x,g.y),oe(0,0,g.r,Se),s.fillStyle=P(fe,g.r),s.fill(),s.restore(),Le?(s.save(),oe(g.x,g.y,g.r+3,Se),s.strokeStyle=fe,s.lineWidth=3,s.shadowColor=fe,s.shadowBlur=12,s.stroke(),s.restore()):Qe?(s.save(),oe(g.x,g.y,g.r+2,Se),s.strokeStyle=fe,s.lineWidth=2,s.stroke(),s.restore()):at&&xt?(s.save(),oe(g.x,g.y,g.r+2,Se),s.strokeStyle="#e11d48",s.lineWidth=2,s.stroke(),s.restore()):a.multi.indexOf(g.id)>=0&&(s.save(),oe(g.x,g.y,g.r+2,Se),s.strokeStyle="#60a5fa",s.lineWidth=2,s.shadowColor="#60a5fa",s.shadowBlur=8,s.stroke(),s.restore());let gt=V(g.name,16);if((Le||Qe||ot.has(g.id)&&a.zoom>ce||!O&&a.zoom>.6)&&wt&&kt){let Xe=1/a.zoom,ft="500 "+(12*Xe).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";s.font=ft;let qe=ye(ft,gt)+16*Xe,it=18*Xe,We=g.y+g.r+8*Xe,rt=!0;for(let Je of Ge)if(g.x-qe/2<Je.x+Je.w&&g.x+qe/2>Je.x&&We<Je.y+Je.h&&We+it>Je.y){rt=!1;break}if(!rt&&!Le&&!Qe)return;Ge.push({x:g.x-qe/2,y:We,w:qe,h:it}),s.fillStyle=se()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",s.beginPath(),s.roundRect?s.roundRect(g.x-qe/2,We,qe,it,4*Xe):s.rect(g.x-qe/2,We,qe,it),s.fill(),s.strokeStyle=se()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",s.lineWidth=1*Xe,s.stroke(),s.fillStyle=se()?Le||Qe?"#eee":"#bbb":Le||Qe?"#111":"#444",s.textAlign="center",s.fillText(gt,g.x,We+13*Xe)}}),s.restore(),a.marquee){let g=a.marquee,te=Math.min(g.sx,g.ex),ae=Math.min(g.sy,g.ey),fe=Math.abs(g.ex-g.sx),Se=Math.abs(g.ey-g.sy);s.save(),s.setLineDash([4,4]),s.strokeStyle="rgba(96,165,250,0.9)",s.lineWidth=1,s.fillStyle="rgba(96,165,250,0.12)",s.fillRect(te,ae,fe,Se),s.strokeRect(te,ae,fe,Se),s.restore()}if(a.hoverId&&ie.current){let g=a.domainById[a.hoverId],te=a.nodes.find(function(ae){return ae.id===a.hoverId});if(g&&te){let ae=a.edges.filter(function(Le){return Le.sourceNodeId===g.id||Le.targetNodeId===g.id}).length,fe=te.x*a.zoom+a.panX,Se=te.y*a.zoom+a.panY;ie.current.style.display="block",ie.current.style.left=fe+14+"px",ie.current.style.top=Se-6+"px",ie.current.innerHTML="<b>"+S(g.title||g.name||"")+'</b><br/><span style="opacity:.8">'+S(g.kind||"")+" \xB7 "+tRef.current("connCount").replace("{n}",ae)+"</span>"}}else ie.current&&(ie.current.style.display="none")},G=()=>{a.running=!0,a.raf||(a.raf=requestAnimationFrame(ze))};a.wake=G,a.render=ke;let he=()=>{let p=a.nodes.length;a.tickCount++;let S=.9-Math.min(.4,a.tickCount/1500),R=p>1e3?3e3:p>100?2e3:p>50?1200:800,O=p>100?.002:.005,ce=p>1e3?.012:p>100?.005:.01,ee=p>1e3?6:p>200?12:24,De={};a.nodes.forEach(ue=>De[ue.id]=ue);for(let ue=0;ue<p;ue++){if(a.dragNode===a.nodes[ue])continue;let ye=a.nodes[ue],Pe=0,Oe=0;for(let g=0;g<p;g++){if(ue===g)continue;let te=ye.x-a.nodes[g].x,ae=ye.y-a.nodes[g].y,fe=Math.sqrt(te*te+ae*ae)||1,Se=R/(fe*fe);Pe+=te/fe*Se,Oe+=ae/fe*Se}if(a.clustered&&a.typeCenters[ye.type]){let g=a.typeCenters[ye.type];Pe+=(g.x-ye.x)*.006,Oe+=(g.y-ye.y)*.006}else Pe-=ye.x*ce,Oe-=ye.y*ce;let Ee=(ye.vx+Pe)*S,Ge=(ye.vy+Oe)*S;Ee=Math.max(-ee,Math.min(ee,Ee)),Ge=Math.max(-ee,Math.min(ee,Ge)),ye.vx=Ee,ye.vy=Ge}a.edges.forEach(ue=>{let ye=De[ue.sourceNodeId],Pe=De[ue.targetNodeId];if(!ye||!Pe)return;let Oe=Pe.x-ye.x,Ee=Pe.y-ye.y,Ge=Math.sqrt(Oe*Oe+Ee*Ee)||1,g=(Ge-100)*O,te=Oe/Ge*g,ae=Ee/Ge*g;a.dragNode!==ye&&(ye.vx+=te,ye.vy+=ae),a.dragNode!==Pe&&(Pe.vx-=te,Pe.vy-=ae)});let je=0;a.nodes.forEach(ue=>{a.dragNode!==ue&&(ue.x+=ue.vx,ue.y+=ue.vy,je+=ue.vx*ue.vx+ue.vy*ue.vy)}),a.autoFitPending&&a.tickCount>45&&(a.autoFitPending=!1,Z()),(p?Math.sqrt(je/p):0)<.05&&a.tickCount>60&&!a.dragNode?a.quietTicks=(a.quietTicks|0)+1:a.quietTicks=0},ze=()=>{if(a.running){try{he(),ke()}catch{}if(a.quietTicks>30){a.raf=0;return}a.raf=requestAnimationFrame(ze)}},Ie=(p,z)=>{let S=c.getBoundingClientRect();return{x:(p-S.left-a.panX)/a.zoom,y:(z-S.top-a.panY)/a.zoom}},Ue=p=>{let z=a.domainById[p];return!(!z||y.current!=="all"&&z.kind!==y.current||ne.current&&!(z.tags||[]).includes(ne.current))},He=(p,z,S)=>Math.max(z,Math.min(S,p)),Ke=p=>{a.mouseX=p.clientX,a.mouseY=p.clientY;let z=Ie(p.clientX,p.clientY),S=null;for(let R=a.nodes.length-1;R>=0;R--){let O=a.nodes[R];if(!Ue(O.id))continue;let ce=O.x-z.x,ee=O.y-z.y;if(ce*ce+ee*ee<O.r*O.r+36){S=O.id;break}}S!==a.hoverId&&(a.hoverId=S,G())},vt=p=>{if(p.button!==0)return;let z=Ie(p.clientX,p.clientY),S=null;for(let R=a.nodes.length-1;R>=0;R--){let O=a.nodes[R];if(!Ue(O.id))continue;let ce=O.x-z.x,ee=O.y-z.y;if(ce*ce+ee*ee<O.r*O.r+25){S=O;break}}if(p.shiftKey){if(S){a.shiftClick=S.id;return}a.marquee={sx:p.clientX,sy:p.clientY,ex:p.clientX,ey:p.clientY};return}a.dragStart={x:p.clientX,y:p.clientY,px:a.panX,py:a.panY},a.dragging=!1,a.dragNode=S||null,S&&(a.dragOffset={dx:S.x-z.x,dy:S.y-z.y})},At=p=>{if(a.marquee){a.marquee.ex=p.clientX,a.marquee.ey=p.clientY,G();return}if(!a.dragStart)return;let z=p.clientX-a.dragStart.x,S=p.clientY-a.dragStart.y;if(Math.abs(z)+Math.abs(S)>3&&(a.dragging=!0),a.dragNode){let R=Ie(p.clientX,p.clientY);a.dragNode.x=R.x+a.dragOffset.dx,a.dragNode.y=R.y+a.dragOffset.dy,G()}else a.dragging&&(a.panX=He(a.dragStart.px+z,-1e5,1e5),a.panY=He(a.dragStart.py+S,-1e5,1e5),G())},Bt=p=>{if(a.marquee){let S=a.marquee;a.marquee=null;let R=c.getBoundingClientRect(),O=Math.min(S.sx,S.ex)-R.left,ce=Math.max(S.sx,S.ex)-R.left,ee=Math.min(S.sy,S.ey)-R.top,De=Math.max(S.sy,S.ey)-R.top,je=a.nodes.filter(ot=>{let ue=ot.x*a.zoom+a.panX,ye=ot.y*a.zoom+a.panY;return ue>=O&&ue<=ce&&ye>=ee&&ye<=De}).map(ot=>ot.id);a.multi=je,Ae(je),G();return}let z=a.dragStart&&!a.dragging;if(a.shiftClick){let S=a.shiftClick;a.shiftClick=null;let R=Array.isArray(a.multi)?a.multi.slice():[];R.includes(S)||R.push(S),a.multi=R,Ae(R),G();return}if(z){let S=Ie(p.clientX,p.clientY),R=null;for(let O=a.nodes.length-1;O>=0;O--){let ce=a.nodes[O];if(!Ue(ce.id))continue;let ee=ce.x-S.x,De=ce.y-S.y;if(ee*ee+De*De<ce.r*ce.r+20){R=ce;break}}R?(a.selectedId=R.id,q(R.id),G()):(a.selectedId=null,a.hoverId=null,p.shiftKey||(a.multi=[],Ae([])),q(null),G())}a.dragStart=null,a.dragging=!1,a.dragNode=null},Pt=p=>{p.preventDefault();let z=Ie(p.clientX,p.clientY),S=null;for(let R=a.nodes.length-1;R>=0;R--){let O=a.nodes[R];if(!Ue(O.id))continue;let ce=O.x-z.x,ee=O.y-z.y;if(ce*ce+ee*ee<O.r*O.r+25){S=O;break}}if(S){let R=a.domainById[S.id];R&&W({x:p.clientX,y:p.clientY,id:S.id,path:R.id,title:R.title})}else W(null)},Et=p=>{p.preventDefault();let z=c.getBoundingClientRect(),S=(p.clientX-z.left-a.panX)/a.zoom,R=(p.clientY-z.top-a.panY)/a.zoom,O=Math.max(.3,Math.min(3,a.zoom*(p.deltaY<0?1.1:1/1.1)));a.panX=He(a.panX+S*(a.zoom-O),-1e5,1e5),a.panY=He(a.panY+R*(a.zoom-O),-1e5,1e5),a.zoom=O,G()};c.addEventListener("mousemove",Ke),c.addEventListener("mousedown",vt),window.addEventListener("mousemove",At),window.addEventListener("mouseup",Bt),c.addEventListener("wheel",Et,{passive:!1}),c.addEventListener("contextmenu",Pt),I.current=()=>{a.selectedId=null,a.hoverId=null,a.multi=[],Ae([]),Z(),G()};for(let p=0;p<200;p++)he();Z(),G();let Ft=()=>F(!1);return window.addEventListener("mousedown",Ft),()=>{a.running=!1,a.raf&&cancelAnimationFrame(a.raf),be.disconnect(),c.removeEventListener("mousemove",Ke),c.removeEventListener("mousedown",vt),window.removeEventListener("mousemove",At),window.removeEventListener("mouseup",Bt),c.removeEventListener("wheel",Et),c.removeEventListener("contextmenu",Pt),window.removeEventListener("mousedown",Ft)}},[t,o]),(0,n.useEffect)(()=>{A!==void 0&&D.current&&requestAnimationFrame(()=>D.current())},[A]),(0,e.jsxs)("div",{className:"me-graph",ref:h,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[t.length," ",i("nodes")," \xB7 ",o.length," ",i("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",placeholder:i("search"),value:j,onChange:c=>Q(c.target.value)}),(0,e.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>F(c=>!c),"aria-expanded":le,title:i("filterLabel"),style:{borderRadius:8},children:["\u{1F50D} ",i("filterLabel")," ",U!=="all"||K||H?"\u25CF":"\u25BE"]}),le&&(0,e.jsx)("div",{className:"me-graph-legend-pop",onMouseDown:c=>c.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${U==="all"&&!K?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>{me("all"),X(!1)},children:i("all")}),Object.keys(_e).map(c=>(0,e.jsxs)("button",{type:"button",className:`lg${U===c?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>me(s=>s===c?"all":c),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:ct.colors[c]||_e[c]}}),i($e[c])]},c)),(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${K?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>X(c=>!c),children:["\u23F1 ",i("timeDim")]}),de.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:de.map(c=>(0,e.jsxs)("button",{type:"button",className:`lg${H===c.tag?" active":""}`,style:{color:"#ddd",padding:"2px 7px",fontSize:11},onClick:()=>M(s=>s===c.tag?"":c.tag),title:c.tag,children:["#",c.tag," ",(0,e.jsx)("span",{style:{opacity:.55},children:c.n})]},c.tag))})]}),(U!=="all"||K||H)&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",style:{justifyContent:"flex-start",color:"#f87171"},onClick:()=>{me("all"),X(!1),M("")},children:[i("clearFilter")," \u2715"]})]})})]}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:i("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:!!C,onChange:c=>x&&x(c.target.checked)}),i("crossVault")]}),(0,e.jsx)("button",{type:"button",className:`mc-btn${K?" me-on":""}`,onClick:()=>X(c=>!c),children:i("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let c=k.current;if(c)try{c.toBlob(s=>{s&&ve({url:URL.createObjectURL(s),blob:s})},"image/png")}catch{}},children:i("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>D.current&&D.current(),children:i("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{q(null),me("all"),I.current&&I.current()},children:i("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:ie,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)"}}),Y&&(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:i("noMatch")}),f&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>W(null)}),f&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:f.x,top:f.y,zIndex:31},onMouseDown:c=>c.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{v.current({path:f.path,title:f.title}),W(null)},children:i("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{f.id&&(u.current.selectedId=f.id,q(f.id)),W(null);let c=u.current;c&&c.wake&&c.wake()},children:i("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(f.title||"")}catch{}W(null),pe(i("copied"))},children:i("copyName")}),(0,e.jsx)("button",{type:"button",onClick:()=>{let c=u.current,s=c&&Array.isArray(c.multi)?c.multi.slice():[],E=f.id;if(E&&!s.includes(E)&&s.push(E),W(null),s.length<2){pe(i("mergeNeed"),!1);return}if(!window.confirm(i("mergeConfirm")))return;let se=N.current&&N.current(s);se&&se.then?se.then($=>$?pe(i("merged")):pe(i("mergeFail"),!1)).catch(()=>pe(i("mergeFail"),!1)):se&&pe(i("merged"))},children:i("merge")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let c=f.path;W(null),window.confirm(i("deleteConfirm"))&&(async()=>{try{(T.current?await T.current(c):!1)?pe(i("deleted")):pe(i("deleteFail"),!1)}catch{pe(i("deleteFail"),!1)}})()},children:i("delete")})]}),we.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:[we.length," ",i("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let s=we.map(ge=>Ne[ge]).filter(Boolean).map(ge=>ge.title||ge.name).join(`
|
|
307
307
|
`),E=new Blob([s],{type:"text/plain;charset=utf-8"}),se=URL.createObjectURL(E),$=document.createElement("a");$.href=se,$.download="memory-selected.txt",document.body.appendChild($),$.click(),document.body.removeChild($),setTimeout(()=>URL.revokeObjectURL(se),1e3),pe(we.length+i("exportedSel"))},children:i("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(we.length<2){pe(i("mergeNeed"),!1);return}let c=we.map(E=>Ne[E]?Ne[E].id:E);if(!window.confirm(i("mergeConfirm")))return;Ae([]);let s=u.current;s&&(s.multi=[]),fetch(`${_}/merge?paths=${encodeURIComponent(c.join(","))}`).then(E=>E.json()).then(E=>{E&&E.ok?pe(i("merged")):pe(i("mergeFail"),!1)}).catch(()=>pe(i("mergeFail"),!1))},children:i("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(i("deleteConfirm")))return;let c=we.map(E=>Ne[E]?Ne[E].id:E);Ae([]);let s=u.current;s&&(s.multi=[]),(async()=>{let E=0;for(let se of c)try{(T.current?await T.current(se):!1)&&E++}catch{}pe(E+i("deletedSelected"),E>0)})()},children:i("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let c=u.current;c&&(c.multi=[]),Ae([]);let s=u.current;s&&s.render&&s.render()},children:i("clearSelection")})]}),xe&&(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:Ne[xe]?Ne[xe].title||Ne[xe].name:xe}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:Ne[xe]?i($e[Ne[xe].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:i("graphHint")}),(o.filter(c=>c.source===xe||c.target===xe)||[]).slice(0,8).map((c,s)=>{let E=c.source===xe?c.target:c.source,se=Ne[E];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:$=>{$.preventDefault();let ge=u.current;ge&&(ge.selectedId=E,ge.hoverId=E,ge.wake&&ge.wake()),q(E)},children:se?(se.title||se.name).slice(0,28):E},s)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:i("graphTip")}),Ze&&(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 "+(Ze.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:Ze.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:Ze.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:Ze.msg})]}),Me&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{Me.url&&URL.revokeObjectURL(Me.url),ve(null),et(!1)},children:[(0,e.jsx)("style",{children:Fe}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:Ce?"100vw":900,width:Ce?"100vw":"92vw",maxHeight:Ce?"100%":"90vh",height:Ce?"100%":void 0,borderRadius:Ce?0:14},onClick:c=>c.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:i("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:Me.url,download:"memory-graph.png",onClick:()=>{Ye("download"),pe(i("downloaded")+" \xB7 "+i("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:i(nt==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Ye("full"),et(c=>!c),pe(i("fullscreen"))},children:i(nt==="full"?"done":Ce?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let c=Me.blob;c&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":c})]).then(()=>{Ye("copy"),pe(i("copied"))}).catch(()=>{pe(i("copyFail"),!1)}):pe(i("copyFail"),!1)},children:i(nt==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Me.url&&URL.revokeObjectURL(Me.url),ve(null),et(!1)},children:i("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:Ce?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:Me.url,alt:i("exportGraph"),style:{maxWidth:"100%",maxHeight:Ce?"calc(100% - 64px)":"70vh",borderRadius:Ce?0:8,cursor:"zoom-in"},onClick:()=>et(c=>!c)})})]})]})]})}function ja(t){let o=new Date(t||0).getTime();if(!o)return"#94a3b8";let r=(Date.now()-o)/864e5;return r<3?"#10b981":r<14?"#f59e0b":r<30?"#f97316":"#94a3b8"}function Yt({label:t,value:o=[],options:r,onChange:m,placeholder:d,z:i=20}){let[w,C]=(0,n.useState)(!1),x=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!w)return;let v=T=>{x.current&&!x.current.contains(T.target)&&C(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[w]);let A=Array.isArray(o)?o:[],k=A.includes("__all__"),h=k?r.find(v=>v.value==="__all__")?.label||"":A.length?A.map(v=>r.find(T=>T.value===v)?.label||v).join("\u3001"):"",u=(v,T)=>{if(v.value==="__all__"){m(T?["__all__"]:[]);return}let N=new Set(A);N.has("__all__")&&N.delete("__all__"),T?N.add(v.value):N.delete(v.value),m([...N])},D=r.find(v=>v.value==="__all__"),I=r.filter(v=>v.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:x,style:{position:"relative",minWidth:0},children:[(0,e.jsxs)("button",{type:"button",onClick:()=>C(v=>!v),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:h||d||"\u2014"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.7},children:"\u25BE"})]}),w&&(0,e.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,right:0,zIndex:i,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:[D&&(0,e.jsxs)("label",{onClick:v=>v.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:v=>u(D,v.target.checked)}),(0,e.jsx)("span",{children:D.label})]}),I.map(v=>(0,e.jsxs)("label",{onClick:T=>T.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer"},children:[(0,e.jsx)("input",{type:"checkbox",checked:A.includes(v.value),onChange:T=>u(v,T.target.checked)}),(0,e.jsx)("span",{children:v.label})]},v.value))]})]})]})}function Oa(t){let o=new Date(t||0).getTime();return!!o&&(Date.now()-o)/864e5<3}async function Wa(t,o,r){if(r&&typeof window.showSaveFilePicker=="function")try{let i=await window.showSaveFilePicker({suggestedName:o}),w=await i.createWritable();return await w.write(t),await w.close(),{ok:!0,picked:!0,name:i.name}}catch(i){return i&&i.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(i.message||i)}}let m=URL.createObjectURL(t),d=document.createElement("a");return d.href=m,d.download=o,document.body.appendChild(d),d.click(),document.body.removeChild(d),setTimeout(()=>URL.revokeObjectURL(m),1e3),{ok:!0,picked:!1,name:o}}function Gt(t,o){if(!o||!t)return t;let r=t.toLowerCase(),m=o.toLowerCase(),d=[],i=0;for(;i<t.length;){let w=r.indexOf(m,i);if(w<0){d.push(t.slice(i));break}w>i&&d.push(t.slice(i,w)),d.push((0,e.jsx)("mark",{className:"mc-hl",children:t.slice(w,w+m.length)},w)),i=w+m.length}return d}function pt(t){if(!t)return"";let o=new Date(t);if(Number.isNaN(o.getTime()))return"";let r=new Date,m=o.toDateString()===r.toDateString(),d=w=>String(w).padStart(2,"0"),i=`${d(o.getHours())}:${d(o.getMinutes())}`;return m?i:`${o.getMonth()+1}-${o.getDate()} ${i}`}
|
|
308
308
|
|