dsh-memory-eternal 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +3 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -105,12 +105,12 @@ var st=Object.create;var Pe=Object.defineProperty;var lt=Object.getOwnPropertyDe
|
|
|
105
105
|
.me-graph-ctxmenu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; border-radius: 7px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
106
106
|
.me-graph-ctxmenu button:hover { background: rgba(255,255,255,0.1); }
|
|
107
107
|
.me-graph-hint { font-size: 11px; opacity: 0.6; margin-left: auto; }
|
|
108
|
-
`;function xt(o){o.effect(()=>o.locale.register(Be,{zh:bt,en:ht}),"memory-eternal: locale");let s=o.locale.bind(Be);o.effect(()=>o.slots.inject("settings.section",()=>o.slots.register({name:"settings.section",id:Be,order:25,label:()=>s("nav"),locale:Be,inject:()=>({})},()=>c.default.createElement(nt,{t:s,inModal:!1}))),"memory-eternal: settings section"),o.effect(()=>o.slots.inject("sidebar.footer.action",()=>o.slots.register({name:"sidebar.footer.action",id:`${Be}:footer`,order:100,label:()=>s("nav"),locale:Be,inject:()=>({})},m=>c.default.createElement(vt,{t:s,wide:!(m&&m.wide===!1)}))),"memory-eternal: sidebar footer action")}function vt({t:o,wide:s}){let[m,u]=(0,c.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${s?"":" rail"}`,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>u(!0),"aria-label":o("nav"),title:o("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(at,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:o("nav")})]}),m&&(0,e.jsx)(wt,{t:o,onClose:()=>u(!1)})]})}function at(){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)"})]})}function wt({t:o,onClose:s}){return(0,c.useEffect)(()=>{let m=u=>{u.key==="Escape"&&s()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[s]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:s,children:[(0,e.jsx)("style",{children:we}),(0,e.jsx)("div",{className:"me-modal",onClick:m=>m.stopPropagation(),children:(0,e.jsx)(nt,{t:o,inModal:!0,onClose:s})})]})}function nt({t:o,inModal:s,onClose:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)([]),[z,P]=(0,c.useState)(!0),[T,F]=(0,c.useState)(""),[_,me]=(0,c.useState)("all"),[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)("cards"),[
|
|
108
|
+
`;function xt(o){o.effect(()=>o.locale.register(Be,{zh:bt,en:ht}),"memory-eternal: locale");let s=o.locale.bind(Be);o.effect(()=>o.slots.inject("settings.section",()=>o.slots.register({name:"settings.section",id:Be,order:25,label:()=>s("nav"),locale:Be,inject:()=>({})},()=>c.default.createElement(nt,{t:s,inModal:!1}))),"memory-eternal: settings section"),o.effect(()=>o.slots.inject("sidebar.footer.action",()=>o.slots.register({name:"sidebar.footer.action",id:`${Be}:footer`,order:100,label:()=>s("nav"),locale:Be,inject:()=>({})},m=>c.default.createElement(vt,{t:s,wide:!(m&&m.wide===!1)}))),"memory-eternal: sidebar footer action")}function vt({t:o,wide:s}){let[m,u]=(0,c.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${s?"":" rail"}`,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>u(!0),"aria-label":o("nav"),title:o("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(at,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:o("nav")})]}),m&&(0,e.jsx)(wt,{t:o,onClose:()=>u(!1)})]})}function at(){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)"})]})}function wt({t:o,onClose:s}){return(0,c.useEffect)(()=>{let m=u=>{u.key==="Escape"&&s()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[s]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:s,children:[(0,e.jsx)("style",{children:we}),(0,e.jsx)("div",{className:"me-modal",onClick:m=>m.stopPropagation(),children:(0,e.jsx)(nt,{t:o,inModal:!0,onClose:s})})]})}function nt({t:o,inModal:s,onClose:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)([]),[z,P]=(0,c.useState)(!0),[T,F]=(0,c.useState)(""),[_,me]=(0,c.useState)("all"),[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)("cards"),[Q,ue]=(0,c.useState)("recent"),[ne,R]=(0,c.useState)(null),W=(0,c.useRef)(null),h=(0,c.useRef)(null),[j,L]=(0,c.useState)(!1),[$,ye]=(0,c.useState)(!1),[ee,S]=(0,c.useState)(null),[H,G]=(0,c.useState)(null),[Ce,re]=(0,c.useState)(!1),de=(0,c.useRef)(null),[fe,Ne]=(0,c.useState)(24),xe=(0,c.useRef)(null);(0,c.useEffect)(()=>{if(A!=="cards")return;let d=xe.current;if(!d)return;let x=new IntersectionObserver(f=>{f[0]&&f[0].isIntersecting&&Ne(t=>t+24)},{rootMargin:"400px"});return x.observe(d),()=>x.disconnect()},[A,g,_,V]);let Fe=(0,c.useCallback)(async(d=_,x=V)=>{try{P(!0),F("");let f=new URLSearchParams;d&&d!=="all"&&f.set("kind",d),x.trim()&&f.set("q",x.trim());let q=await(await fetch(`${U}/cards?${f.toString()}`)).json();q.ok&&(I(q.cards||[]),Ne(24))}catch(f){F(String(f&&f.message?f.message:f))}finally{P(!1)}},[_,V]),te=(0,c.useCallback)(async()=>{try{let[d,x]=await Promise.all([fetch(`${U}/overview`).then(f=>f.json()),fetch(`${U}/cards`).then(f=>f.json())]);d.ok&&n(d),x.ok&&(I(x.cards||[]),Ne(24))}catch(d){F(String(d&&d.message?d.message:d))}finally{P(!1)}},[]),be=async d=>{try{let f=await(await fetch(`${U}/delete?path=${encodeURIComponent(d)}`)).json();f.ok?(R({ok:!0,msg:o("deleted")}),await te()):R({ok:!1,msg:f.error||o("deleteFail")})}catch{R({ok:!1,msg:o("deleteFail")})}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2e3)};(0,c.useEffect)(()=>(te(),()=>{de.current&&clearTimeout(de.current)}),[te]);let O=d=>{ke(d),de.current&&clearTimeout(de.current),de.current=setTimeout(()=>Fe(_,d),280)},Me=d=>{me(d),Fe(d,V)},J=async d=>{try{let f=await(await fetch(`${U}/card?path=${encodeURIComponent(d.path||d.id)}`)).json();f.ok&&S({path:f.path,title:d.title,text:f.text})}catch(x){F(String(x&&x.message?x.message:x))}},i=async(d,x)=>{L(!0);try{let f=await fetch(`${U}/export`);if(!f.ok)throw new Error("HTTP "+f.status);let t=await f.json();if(!t.ok)throw new Error(t.error||"export failed");let q,Se,Ie;d==="json"?(Se="memory-vault.json",Ie="application/json",q=JSON.stringify(t.cards.map(se=>({path:se.path,title:se.title,kind:se.kind,text:se.text})),null,2)):(Se="memory-vault.md",Ie="text/markdown;charset=utf-8",q=t.cards.map(se=>se.text.trim()).filter(Boolean).join(`
|
|
109
109
|
|
|
110
110
|
---
|
|
111
111
|
|
|
112
|
-
`));let Ye=new Blob([q],{type:Ie}),ie=await rt(Ye,Se,x);if(!ie.ok){R({ok:!1,msg:ie.aborted?o("exportCancel"):o("exportFail")}),L(!1);return}R({ok:!0,msg:ie.picked?o("exportedTo")+"\uFF1A"+ie.name:o("exportedTo")+"\uFF1A"+o("defaultDownloads")+" \xB7 "+ie.name})}catch(f){R({ok:!1,msg:o("exportFail")+" \xB7 "+(f.message||"")})}finally{L(!1)}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2600)},a=async d=>{let x=d.target.files&&d.target.files[0];if(d.target.value="",!!x){try{let f=await x.text(),q=await(await fetch(`${U}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:f})).json();q.ok?(await te(),R({ok:!0,msg:o("importedVault")+"\uFF1A"+(q.imported||0)+(q.skipped?o("importedSkipped")+q.skipped:"")})):R({ok:!1,msg:q.error||o("importFail")})}catch{R({ok:!1,msg:o("importFail")})}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2400)}},N=(0,c.useMemo)(()=>{let d=g.slice();return J==="title"?d.sort((x,f)=>String(x.title||"").localeCompare(String(f.title||""))):J==="hot"?d.sort((x,f)=>(f.weight||f.links||0)-(x.weight||x.links||0)):d.sort((x,f)=>new Date(f.updated||0).getTime()-new Date(x.updated||0).getTime()),d},[g,J]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:we}),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})]}),s&&(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)(at,{})}),(0,e.jsx)("h2",{children:o("memoryTitle")}),(0,e.jsx)("span",{children:o("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:m,"aria-label":o("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:o("total"),value:u?u.total:"\u2014"}),(0,e.jsx)(Ae,{label:o("recent"),value:u?u.recent:"\u2014"}),(0,e.jsx)(Ae,{label:o("tags"),value:u?u.tags:"\u2014"}),(0,e.jsx)(Ae,{label:o("cardCount"),value:u?u.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:o("searchPlaceholder"),value:V,onChange:d=>O(d.target.value)}),(0,e.jsxs)("div",{className:"mc-tabs",children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="cards"?" active":""}`,onClick:()=>ce("cards"),children:o("cardsTab")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="graph"?" active":""}`,onClick:()=>ce("graph"),children:o("graphTab")})]}),(0,e.jsx)("input",{ref:h,type:"file",accept:".json,application/json",style:{display:"none"},onChange:a}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>h.current&&h.current.click(),children:o("importVault")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("location"),children:[(0,e.jsx)("input",{type:"checkbox",checked:$,onChange:d=>ye(d.target.checked)}),o("location")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("md",$),children:o(j?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("json",$),children:o(j?"exporting":"exportJson")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:Ce,onChange:d=>re(d.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>G({tab:"stats"}),children:o("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>te(),children:o("refresh")})]}),A==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[yt.map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${_===d?" active":""}`,onClick:()=>Me(d),children:o(d==="all"?"all":ve[d])},d)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:o("sortRecent")},{key:"title",label:o("sortTitle")},{key:"hot",label:o("sortHot")}].map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${J===d.key?" active":""}`,onClick:()=>ue(d.key),children:d.label},d.key))]}),T&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",T]}),A==="cards"?z&&!g.length?(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}):g.length===0?(0,e.jsx)("div",{className:"mc-empty",children:o("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:N.slice(0,fe).map(d=>(0,e.jsx)(kt,{card:d,t:o,query:V.trim(),onOpen:Z,onDelete:be},d.path))}),N.length>fe&&(0,e.jsx)("div",{ref:xe,style:{height:1}})]}):(0,e.jsx)(Mt,{t:o,onOpen:Z,all:Ce}),ee&&(0,e.jsx)(Nt,{t:o,card:ee,onClose:()=>S(null),onDelete:d=>{S(null),be(d)}}),H&&(0,e.jsx)(Ct,{t:o,tab:H.tab,onTab:d=>G({tab:d}),onClose:()=>G(null),onReload:()=>te()})]})]})}var Ae=({label:o,value:s})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:s}),(0,e.jsx)("span",{children:o})]}),kt=({card:o,t:s,onOpen:m,query:u,onDelete:n})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>m(o),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[o.kind]||We.other}}),u?ot(o.title,u):o.title,Tt(o.updated)&&(0,e.jsx)("span",{className:"mc-new",children:s("newBadge")})]}),(0,e.jsx)("p",{children:u?ot(o.summary||"",u):o.summary||""}),o.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:o.tags.slice(0,4).map(g=>(0,e.jsx)("span",{className:"mc-tag",children:g},g))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:s(ve[o.kind])}),(0,e.jsx)("span",{children:it(o.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:s("delete"),onClick:g=>{g.stopPropagation(),window.confirm(s("deleteConfirm"))&&n&&n(o.path)},children:"\u2715"})]})]});function Ct({t:o,tab:s,onTab:m,onClose:u,onReload:n}){let[g,I]=(0,c.useState)(null),[z,P]=(0,c.useState)(null),[T,F]=(0,c.useState)(null),[_,me]=(0,c.useState)(""),[V,ke]=(0,c.useState)(""),A=(0,c.useCallback)(async()=>{try{let h=await fetch(`${U}/todayBrief`).then(j=>j.json());me(h.ok&&h.brief||"")}catch{}},[]),ce=(0,c.useCallback)(async()=>{if(!(!z||!z.merge||!z.merge.length)&&window.confirm(o("mergeAllConfirm"))){ke("merge");try{let h={},j=S=>h[S]===void 0?S:h[S]=j(h[S]),L=(S,H)=>{h[j(S)]=j(H)},$=new Set;for(let S of z.merge)$.add(S.a.path),$.add(S.b.path),L(S.a.path,S.b.path);let ye={};for(let S of $){let H=j(S);(ye[H]=ye[H]||[]).push(S)}let ee=0;for(let S of Object.values(ye)){if(S.length<2)continue;(await fetch(`${U}/merge?paths=${encodeURIComponent(S.join(","))}`).then(G=>G.json())).ok&&ee++}await J(),n&&n()}catch{}ke("")}},[z,J,n,o]),J=(0,c.useCallback)(async()=>{try{let[h,j,L]=await Promise.all([fetch(`${U}/stats`).then($=>$.json()),fetch(`${U}/optimize`).then($=>$.json()),fetch(`${U}/budget`).then($=>$.json())]);h.ok&&I(h),j.ok&&P(j),L.ok&&F(L)}catch{}},[]);(0,c.useEffect)(()=>{J()},[J]);let ue=async(h,j)=>{if(window.confirm(o("mergeConfirm")))try{(await fetch(`${U}/merge?paths=${encodeURIComponent(h+","+j)}`).then($=>$.json())).ok&&(await J(),n&&n())}catch{}},ne=async h=>{if(window.confirm(o("deleteConfirm")))try{(await fetch(`${U}/delete?path=${encodeURIComponent(h)}`).then(L=>L.json())).ok&&(await J(),n&&n())}catch{}},R=["project","knowledge","content","prompt","business","tool","mistake"],W=({title:h,kind:j,updated:L,path:$})=>(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:Ee.colors[j]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:it(L)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ne($),children:[o("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:u,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:h=>h.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="stats"?" active":""}`,onClick:()=>m("stats"),children:o("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="optimize"?" active":""}`,onClick:()=>m("optimize"),children:o("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:u,children:o("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[s==="stats"&&(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:o("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:A,children:o("todayBrief")}),_&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:_})]}),g&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.total}),(0,e.jsx)("span",{children:o("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.today}),(0,e.jsx)("span",{children:o("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.week}),(0,e.jsx)("span",{children:o("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.tags}),(0,e.jsx)("span",{children:o("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:R.map(h=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[h]||"#666"}}),o(ve[h]),": ",g.byKind?.[h]||0]},h))})]}),T&&(T.budgetChars||T.recallLimit||T.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:o("budgetLabel")}),"\uFF1A",o("budgetChars")," ",(0,e.jsx)("b",{children:T.budgetChars||8e4})," \xB7 ",o("recallLimitLabel")," ",(0,e.jsx)("b",{children:T.recallLimit||5})," \xB7 ",o("embeddingLabel")," ",T.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("todayList"),"\uFF08",g.todayCards?.length||0,"\uFF09"]}),g.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:g.todayCards.map(h=>(0,e.jsx)(W,{title:h.title,kind:h.kind,updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})]})]}),s==="optimize"&&(0,e.jsx)("div",{children:z&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:z.merge?.length?o("mergePairs"):o("noOptimize")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),z.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:ce,children:o(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("mergePairs")}),z.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:z.merge.map((h,j)=>(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:[h.a.title," \u21C4 ",h.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(h.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ue(h.a.path,h.b.path),children:o("mergeNow")})]},j))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:o("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("staleCards"),"\uFF08",z.stale?.length||0,"\uFF09"]}),z.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:z.stale.map(h=>(0,e.jsx)(W,{title:h.title,kind:"other",updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})})]})]})]})}function Nt({t:o,card:s,onClose:m,onDelete:u}){(0,c.useEffect)(()=>{let z=P=>{P.key==="Escape"&&m()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[m]);let[n,g]=(0,c.useState)(!1),I=(s.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:m,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",onClick:z=>z.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:s.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[I&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>g(z=>!z),children:o(n?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(o("deleteConfirm"))&&u&&u(s.path)},children:o("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:m,children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:n?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Lt(s.text)}})]})]})}function Mt({t:o,onOpen:s,all:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)(""),z=(0,c.useCallback)(async()=>{try{let F=await(await fetch(`${U}/graph${m?"?all=1":""}`)).json();n(F.ok?F:null),I("")}catch(T){I(String(T&&T.message?T.message:T))}},[m]);(0,c.useEffect)(()=>{let T=!0;return fetch(`${U}/graph${m?"?all=1":""}`).then(F=>F.json()).then(F=>{T&&n(F.ok?F:null)}).catch(F=>{T&&I(String(F&&F.message?F.message:F))}),()=>{T=!1}},[m]);let P=(0,c.useCallback)(async T=>{try{let _=await(await fetch(`${U}/delete?path=${encodeURIComponent(T)}`)).json();return _&&_.ok?(await z(),!0):!1}catch{return!1}},[z]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:we}),g&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",g]}),!u&&!g&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),u&&u.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:o("emptyGraph")}),u&&u.nodes.length>0&&(0,e.jsx)(It,{nodes:u.nodes,edges:u.edges,onOpen:s,onDelete:P,t:o,countLabel:`${u.nodes.length} ${o("nodes")} \xB7 ${St(u.edges)} ${o("edges")}`})]})}function St(o){let s=new Set;for(let m of o||[])s.add([m.source,m.target].sort().join("|"));return s.size}var Ee={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 It({nodes:o,edges:s,onOpen:m,onDelete:u,t:n,countLabel:g}){let I=(0,c.useRef)(null),z=(0,c.useRef)(null),P=(0,c.useRef)(null),T=(0,c.useRef)(null),F=(0,c.useRef)(null),_=(0,c.useRef)(m);(0,c.useEffect)(()=>{_.current=m},[m]);let me=(0,c.useRef)(u);(0,c.useEffect)(()=>{me.current=u},[u]);let[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)(null),J=(0,c.useRef)("");(0,c.useEffect)(()=>{J.current=V.trim().toLowerCase()},[V]);let[ue,ne]=(0,c.useState)("all"),R=(0,c.useRef)("all"),[W,h]=(0,c.useState)(!1),j=(0,c.useRef)(!1),[L,$]=(0,c.useState)(null);(0,c.useEffect)(()=>{R.current=ue},[ue]),(0,c.useEffect)(()=>{j.current=W},[W]);let ye=(()=>{let i=V.trim().toLowerCase();return!!i&&!o.some(a=>(a.title||a.name||"").toLowerCase().includes(i)||String(a.kind||"").toLowerCase().includes(i)||String(ve[a.kind]||"").toLowerCase().includes(i))})();(0,c.useEffect)(()=>{let i=P.current;i&&i.wake&&i.wake()},[V]),(0,c.useEffect)(()=>{let i=P.current;i&&i.render&&i.render()},[ue,W]);let ee=(0,c.useRef)(null),[S,H]=(0,c.useState)([]),[G,Ce]=(0,c.useState)(null),[re,de]=(0,c.useState)(!1),[fe,Ne]=(0,c.useState)(null),[xe,Fe]=(0,c.useState)(""),te=(0,c.useRef)(null),be=(0,c.useRef)(null),O=(i,a=!0)=>{te.current&&clearTimeout(te.current),Ne({msg:i,ok:a}),te.current=setTimeout(()=>Ne(null),1900)},Me=i=>{Fe(i),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>Fe(""),1600)};(0,c.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),be.current&&clearTimeout(be.current)},[]);let Z=(0,c.useMemo)(()=>o.reduce((i,a)=>(i[a.id]=a,i),{}),[o]);return(0,c.useEffect)(()=>{let i=I.current;if(!i||o.length===0)return;let a=i.getContext("2d");if(!a)return;let N=Math.max(1,window.devicePixelRatio||1),d=()=>document.documentElement.getAttribute("data-theme")==="dark",x={};s.forEach(r=>{x[r.source]=(x[r.source]||0)+1,x[r.target]=(x[r.target]||0)+1});let f=Math.max(1,...Object.values(x)),t={nodes:o.map(r=>({id:r.id,name:r.title||"",type:r.kind||"other",r:9+Math.min(10,(x[r.id]||0)/f*8),x:0,y:0,vx:0,vy:0})),edges:s.map(r=>({sourceNodeId:r.source,targetNodeId:r.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:N,ctx:a,multi:[],marquee:null};t.domain=o,t.domainById=o.reduce((r,b)=>(r[b.id]=b,r),{}),t.nodes.forEach((r,b)=>{let p=b/t.nodes.length*Math.PI*2-Math.PI/2;r.x=Math.cos(p)*60,r.y=Math.sin(p)*60});let q=[...new Set(t.nodes.map(r=>r.type))];t.clustered=q.length>1,t.typeCenters={},q.forEach((r,b)=>{let p=b/q.length*Math.PI*2-Math.PI/2;t.typeCenters[r]={x:Math.cos(p)*160,y:Math.sin(p)*160}}),P.current=t;let Se=()=>{let r=i.clientWidth,b=i.clientHeight;t.w=r,t.h=b,i.width=r*N,i.height=b*N,a.setTransform(N,0,0,N,0,0)};Se();let Ie=new ResizeObserver(Se);Ie.observe(i.parentElement);let Ye=(r,b)=>r&&r.length>b?r.slice(0,b)+"\u2026":r,ie=(r,b,p,y)=>{if(a.beginPath(),y==="rect")a.rect(r-p,b-p*.75,p*2,p*1.5);else if(y==="diamond")a.moveTo(r,b-p),a.lineTo(r+p,b),a.lineTo(r,b+p),a.lineTo(r-p,b),a.closePath();else if(y==="hexagon"){for(let v=0;v<6;v++){let C=Math.PI/3*v-Math.PI/2,B=r+p*Math.cos(C),l=b+p*Math.sin(C);v===0?a.moveTo(B,l):a.lineTo(B,l)}a.closePath()}else a.arc(r,b,p,0,Math.PI*2)},se=()=>{if(!t.nodes.length)return;let r=1/0,b=-1/0,p=1/0,y=-1/0;t.nodes.forEach(M=>{r=Math.min(r,M.x),b=Math.max(b,M.x),p=Math.min(p,M.y),y=Math.max(y,M.y)});let v=36,C=b-r+v*2,B=y-p+v*2,l=Math.min(t.w/C,t.h/B);t.zoom=Math.max(.45,Math.min(2.4,l*1.22)),t.panX=t.w/2-(r+b)/2*t.zoom,t.panY=t.h/2-(p+y)/2*t.zoom};T.current=se;let Ue=()=>{a.clearRect(0,0,t.w,t.h),t.searchTerm=J.current,t.kindFilter=R.current,t.timeMode=j.current;let r=t.kindFilter,b=l=>String(l||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");a.save(),a.strokeStyle=d()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",a.lineWidth=.5;for(let l=0;l<t.w;l+=24)a.beginPath(),a.moveTo(l,0),a.lineTo(l,t.h),a.stroke();for(let l=0;l<t.h;l+=24)a.beginPath(),a.moveTo(0,l),a.lineTo(t.w,l),a.stroke();a.restore(),a.save(),a.translate(t.panX,t.panY),a.scale(t.zoom,t.zoom);let p={};t.nodes.forEach(l=>p[l.id]=l);let y=t.nodes.length>40,v=y?1.5:.55,C=t.selectedId||t.hoverId;t.edges.forEach(l=>{let M=p[l.sourceNodeId],E=p[l.targetNodeId];if(!M||!E)return;if(r!=="all"){let Q=t.domainById[l.sourceNodeId]&&t.domainById[l.sourceNodeId].kind,Qe=t.domainById[l.targetNodeId]&&t.domainById[l.targetNodeId].kind;if(Q!==r&&Qe!==r)return}let w=E.x-M.x,k=E.y-M.y,D=Math.sqrt(w*w+k*k)||1,Y=y?12:18,X=-k/D*Y,oe=w/D*Y,K=(M.x+E.x)/2+X,pe=(M.y+E.y)/2+oe,ae=Ee.colors[t.domainById[M.id]&&t.domainById[M.id].kind||"other"],ge=C&&(l.sourceNodeId===C||l.targetNodeId===C),ze=C?ge?.6:.08:y?.14:.24,je=parseInt(ae.slice(1,3),16),De=parseInt(ae.slice(3,5),16),Ze=parseInt(ae.slice(5,7),16);a.strokeStyle="rgba("+je+","+De+","+Ze+","+ze+")",a.lineWidth=ge?1.6+(l.weight||1):.8+(l.weight||1)*.5,a.beginPath(),a.moveTo(M.x,M.y),a.quadraticCurveTo(K,pe,E.x,E.y),a.stroke()});let B=[];if(t.nodes.forEach(l=>{let M=t.domainById[l.id]||{},E=M.kind||"other",w=t.timeMode?zt(M.updated):Ee.colors[E],k=Ee.shapes[E],D=t.selectedId===l.id,Y=t.hoverId===l.id,X=t.searchTerm||"",oe=!X||(l.name||"").toLowerCase().includes(X)||String(ve[E]||"").toLowerCase().includes(X)||String(E).toLowerCase().includes(X),K=r==="all"||E===r,pe=C&&l.id!==C&&!t.edges.some(Q=>Q.sourceNodeId===C&&Q.targetNodeId===l.id||Q.targetNodeId===C&&Q.sourceNodeId===l.id)||X&&!oe||!K;a.save(),a.globalAlpha=pe?.08:1,(D||Y)&&(a.shadowColor=w,a.shadowBlur=D?20:14),ie(l.x,l.y,l.r,k);let ae=parseInt(w.slice(1,3),16),ge=parseInt(w.slice(3,5),16),ze=parseInt(w.slice(5,7),16),je=a.createRadialGradient(l.x-l.r*.3,l.y-l.r*.3,0,l.x,l.y,l.r*1.2);je.addColorStop(0,"rgba("+Math.min(255,ae+70)+","+Math.min(255,ge+70)+","+Math.min(255,ze+70)+",0.95)"),je.addColorStop(1,w),a.fillStyle=je,a.fill(),a.restore(),D?(a.save(),ie(l.x,l.y,l.r+3,k),a.strokeStyle=w,a.lineWidth=3,a.shadowColor=w,a.shadowBlur=12,a.stroke(),a.restore()):Y?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle=w,a.lineWidth=2,a.stroke(),a.restore()):X&&oe?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#e11d48",a.lineWidth=2,a.stroke(),a.restore()):t.multi.indexOf(l.id)>=0&&(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#60a5fa",a.lineWidth=2,a.shadowColor="#60a5fa",a.shadowBlur=8,a.stroke(),a.restore());let De=Ye(l.name,16);if((D||Y||t.zoom>v||!y&&t.zoom>.6)&&K){let Q=1/t.zoom;a.font="500 "+(12*Q).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let he=a.measureText(De).width+16*Q,Oe=18*Q,Te=l.y+l.r+8*Q,et=!0;for(let Le of B)if(l.x-he/2<Le.x+Le.w&&l.x+he/2>Le.x&&Te<Le.y+Le.h&&Te+Oe>Le.y){et=!1;break}if(!et&&!D&&!Y)return;B.push({x:l.x-he/2,y:Te,w:he,h:Oe}),a.fillStyle=d()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",a.beginPath(),a.roundRect?a.roundRect(l.x-he/2,Te,he,Oe,4*Q):a.rect(l.x-he/2,Te,he,Oe),a.fill(),a.strokeStyle=d()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",a.lineWidth=1*Q,a.stroke(),a.fillStyle=d()?D||Y?"#eee":"#bbb":D||Y?"#111":"#444",a.textAlign="center",a.fillText(De,l.x,Te+13*Q)}}),a.restore(),t.marquee){let l=t.marquee,M=Math.min(l.sx,l.ex),E=Math.min(l.sy,l.ey),w=Math.abs(l.ex-l.sx),k=Math.abs(l.ey-l.sy);a.save(),a.setLineDash([4,4]),a.strokeStyle="rgba(96,165,250,0.9)",a.lineWidth=1,a.fillStyle="rgba(96,165,250,0.12)",a.fillRect(M,E,w,k),a.strokeRect(M,E,w,k),a.restore()}if(t.hoverId&&ee.current){let l=t.domainById[t.hoverId],M=t.nodes.find(function(E){return E.id===t.hoverId});if(l&&M){let E=t.edges.filter(function(D){return D.sourceNodeId===l.id||D.targetNodeId===l.id}).length,w=M.x*t.zoom+t.panX,k=M.y*t.zoom+t.panY;ee.current.style.display="block",ee.current.style.left=w+14+"px",ee.current.style.top=k-6+"px",ee.current.innerHTML="<b>"+b(l.title||l.name||"")+'</b><br/><span style="opacity:.8">'+b(l.kind||"")+" \xB7 "+E+" \u8FDE\u63A5</span>"}}else ee.current&&(ee.current.style.display="none")},le=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=le,t.render=Ue;let qe=()=>{let r=t.nodes.length;t.tickCount++;let p=.9-Math.min(.4,t.tickCount/1500),y=r>1e3?3e3:r>100?2e3:r>50?1200:800,v=r>100?.002:.005,C=r>1e3?.012:r>100?.005:.01,B=r>1e3?6:r>200?12:24,l={};t.nodes.forEach(w=>l[w.id]=w);for(let w=0;w<r;w++){if(t.dragNode===t.nodes[w])continue;let k=t.nodes[w],D=0,Y=0;for(let K=0;K<r;K++){if(w===K)continue;let pe=k.x-t.nodes[K].x,ae=k.y-t.nodes[K].y,ge=Math.sqrt(pe*pe+ae*ae)||1,ze=y/(ge*ge);D+=pe/ge*ze,Y+=ae/ge*ze}if(t.clustered&&t.typeCenters[k.type]){let K=t.typeCenters[k.type];D+=(K.x-k.x)*.006,Y+=(K.y-k.y)*.006}else D-=k.x*C,Y-=k.y*C;let X=(k.vx+D)*p,oe=(k.vy+Y)*p;X=Math.max(-B,Math.min(B,X)),oe=Math.max(-B,Math.min(B,oe)),k.vx=X,k.vy=oe}t.edges.forEach(w=>{let k=l[w.sourceNodeId],D=l[w.targetNodeId];if(!k||!D)return;let Y=D.x-k.x,X=D.y-k.y,oe=Math.sqrt(Y*Y+X*X)||1,K=(oe-100)*v,pe=Y/oe*K,ae=X/oe*K;t.dragNode!==k&&(k.vx+=pe,k.vy+=ae),t.dragNode!==D&&(D.vx-=pe,D.vy-=ae)});let M=0;t.nodes.forEach(w=>{t.dragNode!==w&&(w.x+=w.vx,w.y+=w.vy,M+=w.vx*w.vx+w.vy*w.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,se()),(r?Math.sqrt(M/r):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{qe(),Ue()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Re=(r,b)=>{let p=i.getBoundingClientRect();return{x:(r-p.left-t.panX)/t.zoom,y:(b-p.top-t.panY)/t.zoom}},$e=(r,b,p)=>Math.max(b,Math.min(p,r)),Ke=r=>{t.mouseX=r.clientX,t.mouseY=r.clientY;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+36){p=v.id;break}}p!==t.hoverId&&(t.hoverId=p,le())},Ve=r=>{if(r.button!==0)return;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(r.shiftKey){t.marquee={sx:r.clientX,sy:r.clientY,ex:r.clientX,ey:r.clientY};return}t.dragStart={x:r.clientX,y:r.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=p||null,p&&(t.dragOffset={dx:p.x-b.x,dy:p.y-b.y})},He=r=>{if(t.marquee){t.marquee.ex=r.clientX,t.marquee.ey=r.clientY,le();return}if(!t.dragStart)return;let b=r.clientX-t.dragStart.x,p=r.clientY-t.dragStart.y;if(Math.abs(b)+Math.abs(p)>3&&(t.dragging=!0),t.dragNode){let y=Re(r.clientX,r.clientY);t.dragNode.x=y.x+t.dragOffset.dx,t.dragNode.y=y.y+t.dragOffset.dy,le()}else t.dragging&&(t.panX=$e(t.dragStart.px+b,-1e5,1e5),t.panY=$e(t.dragStart.py+p,-1e5,1e5),le())},Ge=r=>{if(t.marquee){let p=t.marquee;t.marquee=null;let y=i.getBoundingClientRect(),v=Math.min(p.sx,p.ex)-y.left,C=Math.max(p.sx,p.ex)-y.left,B=Math.min(p.sy,p.ey)-y.top,l=Math.max(p.sy,p.ey)-y.top,M=t.nodes.filter(E=>{let w=E.x*t.zoom+t.panX,k=E.y*t.zoom+t.panY;return w>=v&&w<=C&&k>=B&&k<=l}).map(E=>E.id);t.multi=M,H(M),le();return}if(t.dragStart&&!t.dragging){let p=Re(r.clientX,r.clientY),y=null;for(let v=t.nodes.length-1;v>=0;v--){let C=t.nodes[v];if(R.current!=="all"&&(t.domainById[C.id]&&t.domainById[C.id].kind)!==R.current)continue;let B=C.x-p.x,l=C.y-p.y;if(B*B+l*l<C.r*C.r+20){y=C;break}}y?(t.selectedId=y.id,ce(y.id),le()):(t.selectedId=null,t.hoverId=null,r.shiftKey||(t.multi=[],H([])),ce(null),le())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=r=>{r.preventDefault();let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(p){let y=t.domainById[p.id];y&&$({x:r.clientX,y:r.clientY,id:p.id,path:y.id,title:y.title})}else $(null)},Je=r=>{r.preventDefault();let b=i.getBoundingClientRect(),p=(r.clientX-b.left-t.panX)/t.zoom,y=(r.clientY-b.top-t.panY)/t.zoom,v=Math.max(.3,Math.min(3,t.zoom*(r.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+p*(t.zoom-v),-1e5,1e5),t.panY=$e(t.panY+y*(t.zoom-v),-1e5,1e5),t.zoom=v,le()};i.addEventListener("mousemove",Ke),i.addEventListener("mousedown",Ve),window.addEventListener("mousemove",He),window.addEventListener("mouseup",Ge),i.addEventListener("wheel",Je,{passive:!1}),i.addEventListener("contextmenu",_e),F.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],H([]),se(),le()};for(let r=0;r<200;r++)qe();return se(),le(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),Ie.disconnect(),i.removeEventListener("mousemove",Ke),i.removeEventListener("mousedown",Ve),window.removeEventListener("mousemove",He),window.removeEventListener("mouseup",Ge),i.removeEventListener("wheel",Je),i.removeEventListener("contextmenu",_e)}},[o,s]),(0,e.jsxs)("div",{className:"me-graph",ref:z,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[o.length," ",n("nodes")," \xB7 ",s.length," ",n("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:n("search"),value:V,onChange:i=>ke(i.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${W?" me-on":""}`,onClick:()=>h(i=>!i),children:n("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=I.current;if(i)try{i.toBlob(a=>{a&&Ce({url:URL.createObjectURL(a),blob:a})},"image/png")}catch{}},children:n("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>T.current&&T.current(),children:n("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{ce(null),ne("all"),F.current&&F.current()},children:n("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:I,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:ee,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[W?[{c:"#10b981",l:n("timeNew")},{c:"#f59e0b",l:n("timeRecent")},{c:"#f97316",l:n("timeMonth")},{c:"#94a3b8",l:n("timeOld")}].map(i=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:i.c}}),i.l]},i.c)):Object.keys(We).map(i=>(0,e.jsxs)("button",{type:"button",className:`lg${ue===i?" active":""}`,onClick:()=>ne(a=>a===i?"all":i),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[i]||We[i]}}),n(ve[i])]},i)),!W&&ue!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>ne("all"),children:[n("clearFilter")," \u2715"]})]}),ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:n("noMatch")}),L&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>$(null)}),L&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:L.x,top:L.y,zIndex:31},onMouseDown:i=>i.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{_.current({path:L.path,title:L.title}),$(null)},children:n("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{L.id&&(P.current.selectedId=L.id,ce(L.id)),$(null);let i=P.current;i&&i.wake&&i.wake()},children:n("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(L.title||"")}catch{}$(null),O(n("copied"))},children:n("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let i=L.path;$(null),window.confirm(n("deleteConfirm"))&&(async()=>{try{(me.current?await me.current(i):!1)?O(n("deleted")):O(n("deleteFail"),!1)}catch{O(n("deleteFail"),!1)}})()},children:n("delete")})]}),S.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:[S.length," ",n("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let a=S.map(f=>Z[f]).filter(Boolean).map(f=>f.title||f.name).join(`
|
|
113
|
-
`),N=new Blob([a],{type:"text/plain;charset=utf-8"}),d=URL.createObjectURL(N),x=document.createElement("a");x.href=d,x.download="memory-selected.txt",document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(d),1e3),O(S.length+n("exportedSel"))},children:n("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(S.length<2){O(n("mergeNeed"),!1);return}let i=S.map(N=>
|
|
112
|
+
`));let Ye=new Blob([q],{type:Ie}),ie=await rt(Ye,Se,x);if(!ie.ok){R({ok:!1,msg:ie.aborted?o("exportCancel"):o("exportFail")}),L(!1);return}R({ok:!0,msg:ie.picked?o("exportedTo")+"\uFF1A"+ie.name:o("exportedTo")+"\uFF1A"+o("defaultDownloads")+" \xB7 "+ie.name})}catch(f){R({ok:!1,msg:o("exportFail")+" \xB7 "+(f.message||"")})}finally{L(!1)}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2600)},a=async d=>{let x=d.target.files&&d.target.files[0];if(d.target.value="",!!x){try{let f=await x.text(),q=await(await fetch(`${U}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:f})).json();q.ok?(await te(),R({ok:!0,msg:o("importedVault")+"\uFF1A"+(q.imported||0)+(q.skipped?o("importedSkipped")+q.skipped:"")})):R({ok:!1,msg:q.error||o("importFail")})}catch{R({ok:!1,msg:o("importFail")})}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2400)}},N=(0,c.useMemo)(()=>{let d=g.slice();return Q==="title"?d.sort((x,f)=>String(x.title||"").localeCompare(String(f.title||""))):Q==="hot"?d.sort((x,f)=>(f.weight||f.links||0)-(x.weight||x.links||0)):d.sort((x,f)=>new Date(f.updated||0).getTime()-new Date(x.updated||0).getTime()),d},[g,Q]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:we}),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})]}),s&&(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)(at,{})}),(0,e.jsx)("h2",{children:o("memoryTitle")}),(0,e.jsx)("span",{children:o("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:m,"aria-label":o("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:o("total"),value:u?u.total:"\u2014"}),(0,e.jsx)(Ae,{label:o("recent"),value:u?u.recent:"\u2014"}),(0,e.jsx)(Ae,{label:o("tags"),value:u?u.tags:"\u2014"}),(0,e.jsx)(Ae,{label:o("cardCount"),value:u?u.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:o("searchPlaceholder"),value:V,onChange:d=>O(d.target.value)}),(0,e.jsxs)("div",{className:"mc-tabs",children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="cards"?" active":""}`,onClick:()=>ce("cards"),children:o("cardsTab")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="graph"?" active":""}`,onClick:()=>ce("graph"),children:o("graphTab")})]}),(0,e.jsx)("input",{ref:h,type:"file",accept:".json,application/json",style:{display:"none"},onChange:a}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>h.current&&h.current.click(),children:o("importVault")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("location"),children:[(0,e.jsx)("input",{type:"checkbox",checked:$,onChange:d=>ye(d.target.checked)}),o("location")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("md",$),children:o(j?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("json",$),children:o(j?"exporting":"exportJson")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:Ce,onChange:d=>re(d.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>G({tab:"stats"}),children:o("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>te(),children:o("refresh")})]}),A==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[yt.map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${_===d?" active":""}`,onClick:()=>Me(d),children:o(d==="all"?"all":ve[d])},d)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:o("sortRecent")},{key:"title",label:o("sortTitle")},{key:"hot",label:o("sortHot")}].map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${Q===d.key?" active":""}`,onClick:()=>ue(d.key),children:d.label},d.key))]}),T&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",T]}),A==="cards"?z&&!g.length?(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}):g.length===0?(0,e.jsx)("div",{className:"mc-empty",children:o("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:N.slice(0,fe).map(d=>(0,e.jsx)(kt,{card:d,t:o,query:V.trim(),onOpen:J,onDelete:be},d.path))}),N.length>fe&&(0,e.jsx)("div",{ref:xe,style:{height:1}})]}):(0,e.jsx)(Mt,{t:o,onOpen:J,all:Ce}),ee&&(0,e.jsx)(Nt,{t:o,card:ee,onClose:()=>S(null),onDelete:d=>{S(null),be(d)}}),H&&(0,e.jsx)(Ct,{t:o,tab:H.tab,onTab:d=>G({tab:d}),onClose:()=>G(null),onReload:()=>te()})]})]})}var Ae=({label:o,value:s})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:s}),(0,e.jsx)("span",{children:o})]}),kt=({card:o,t:s,onOpen:m,query:u,onDelete:n})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>m(o),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[o.kind]||We.other}}),u?ot(o.title,u):o.title,Tt(o.updated)&&(0,e.jsx)("span",{className:"mc-new",children:s("newBadge")})]}),(0,e.jsx)("p",{children:u?ot(o.summary||"",u):o.summary||""}),o.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:o.tags.slice(0,4).map(g=>(0,e.jsx)("span",{className:"mc-tag",children:g},g))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:s(ve[o.kind])}),(0,e.jsx)("span",{children:it(o.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:s("delete"),onClick:g=>{g.stopPropagation(),window.confirm(s("deleteConfirm"))&&n&&n(o.path)},children:"\u2715"})]})]});function Ct({t:o,tab:s,onTab:m,onClose:u,onReload:n}){let[g,I]=(0,c.useState)(null),[z,P]=(0,c.useState)(null),[T,F]=(0,c.useState)(null),[_,me]=(0,c.useState)(""),[V,ke]=(0,c.useState)(""),A=(0,c.useCallback)(async()=>{try{let h=await fetch(`${U}/todayBrief`).then(j=>j.json());me(h.ok&&h.brief||"")}catch{}},[]),ce=(0,c.useCallback)(async()=>{if(!(!z||!z.merge||!z.merge.length)&&window.confirm(o("mergeAllConfirm"))){ke("merge");try{let h={},j=S=>h[S]===void 0?S:h[S]=j(h[S]),L=(S,H)=>{h[j(S)]=j(H)},$=new Set;for(let S of z.merge)$.add(S.a.path),$.add(S.b.path),L(S.a.path,S.b.path);let ye={};for(let S of $){let H=j(S);(ye[H]=ye[H]||[]).push(S)}let ee=0;for(let S of Object.values(ye)){if(S.length<2)continue;(await fetch(`${U}/merge?paths=${encodeURIComponent(S.join(","))}`).then(G=>G.json())).ok&&ee++}await Q(),n&&n()}catch{}ke("")}},[z,Q,n,o]);async function Q(){try{let[h,j,L]=await Promise.all([fetch(`${U}/stats`).then($=>$.json()),fetch(`${U}/optimize`).then($=>$.json()),fetch(`${U}/budget`).then($=>$.json())]);h.ok&&I(h),j.ok&&P(j),L.ok&&F(L)}catch{}}(0,c.useEffect)(()=>{Q()},[]);let ue=async(h,j)=>{if(window.confirm(o("mergeConfirm")))try{(await fetch(`${U}/merge?paths=${encodeURIComponent(h+","+j)}`).then($=>$.json())).ok&&(await Q(),n&&n())}catch{}},ne=async h=>{if(window.confirm(o("deleteConfirm")))try{(await fetch(`${U}/delete?path=${encodeURIComponent(h)}`).then(L=>L.json())).ok&&(await Q(),n&&n())}catch{}},R=["project","knowledge","content","prompt","business","tool","mistake"],W=({title:h,kind:j,updated:L,path:$})=>(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:Ee.colors[j]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:it(L)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ne($),children:[o("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:u,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:h=>h.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="stats"?" active":""}`,onClick:()=>m("stats"),children:o("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="optimize"?" active":""}`,onClick:()=>m("optimize"),children:o("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:u,children:o("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[s==="stats"&&(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:o("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:A,children:o("todayBrief")}),_&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:_})]}),g&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.total}),(0,e.jsx)("span",{children:o("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.today}),(0,e.jsx)("span",{children:o("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.week}),(0,e.jsx)("span",{children:o("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.tags}),(0,e.jsx)("span",{children:o("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:R.map(h=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[h]||"#666"}}),o(ve[h]),": ",g.byKind?.[h]||0]},h))})]}),T&&(T.budgetChars||T.recallLimit||T.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:o("budgetLabel")}),"\uFF1A",o("budgetChars")," ",(0,e.jsx)("b",{children:T.budgetChars||8e4})," \xB7 ",o("recallLimitLabel")," ",(0,e.jsx)("b",{children:T.recallLimit||5})," \xB7 ",o("embeddingLabel")," ",T.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("todayList"),"\uFF08",g.todayCards?.length||0,"\uFF09"]}),g.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:g.todayCards.map(h=>(0,e.jsx)(W,{title:h.title,kind:h.kind,updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})]})]}),s==="optimize"&&(0,e.jsx)("div",{children:z&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:z.merge?.length?o("mergePairs"):o("noOptimize")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),z.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:ce,children:o(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("mergePairs")}),z.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:z.merge.map((h,j)=>(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:[h.a.title," \u21C4 ",h.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(h.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ue(h.a.path,h.b.path),children:o("mergeNow")})]},j))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:o("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("staleCards"),"\uFF08",z.stale?.length||0,"\uFF09"]}),z.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:z.stale.map(h=>(0,e.jsx)(W,{title:h.title,kind:"other",updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})})]})]})]})}function Nt({t:o,card:s,onClose:m,onDelete:u}){(0,c.useEffect)(()=>{let z=P=>{P.key==="Escape"&&m()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[m]);let[n,g]=(0,c.useState)(!1),I=(s.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:m,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",onClick:z=>z.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:s.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[I&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>g(z=>!z),children:o(n?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(o("deleteConfirm"))&&u&&u(s.path)},children:o("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:m,children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:n?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Lt(s.text)}})]})]})}function Mt({t:o,onOpen:s,all:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)(""),z=(0,c.useCallback)(async()=>{try{let F=await(await fetch(`${U}/graph${m?"?all=1":""}`)).json();n(F.ok?F:null),I("")}catch(T){I(String(T&&T.message?T.message:T))}},[m]);(0,c.useEffect)(()=>{let T=!0;return fetch(`${U}/graph${m?"?all=1":""}`).then(F=>F.json()).then(F=>{T&&n(F.ok?F:null)}).catch(F=>{T&&I(String(F&&F.message?F.message:F))}),()=>{T=!1}},[m]);let P=(0,c.useCallback)(async T=>{try{let _=await(await fetch(`${U}/delete?path=${encodeURIComponent(T)}`)).json();return _&&_.ok?(await z(),!0):!1}catch{return!1}},[z]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:we}),g&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",g]}),!u&&!g&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),u&&u.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:o("emptyGraph")}),u&&u.nodes.length>0&&(0,e.jsx)(It,{nodes:u.nodes,edges:u.edges,onOpen:s,onDelete:P,t:o,countLabel:`${u.nodes.length} ${o("nodes")} \xB7 ${St(u.edges)} ${o("edges")}`})]})}function St(o){let s=new Set;for(let m of o||[])s.add([m.source,m.target].sort().join("|"));return s.size}var Ee={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 It({nodes:o,edges:s,onOpen:m,onDelete:u,t:n,countLabel:g}){let I=(0,c.useRef)(null),z=(0,c.useRef)(null),P=(0,c.useRef)(null),T=(0,c.useRef)(null),F=(0,c.useRef)(null),_=(0,c.useRef)(m);(0,c.useEffect)(()=>{_.current=m},[m]);let me=(0,c.useRef)(u);(0,c.useEffect)(()=>{me.current=u},[u]);let[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)(null),Q=(0,c.useRef)("");(0,c.useEffect)(()=>{Q.current=V.trim().toLowerCase()},[V]);let[ue,ne]=(0,c.useState)("all"),R=(0,c.useRef)("all"),[W,h]=(0,c.useState)(!1),j=(0,c.useRef)(!1),[L,$]=(0,c.useState)(null);(0,c.useEffect)(()=>{R.current=ue},[ue]),(0,c.useEffect)(()=>{j.current=W},[W]);let ye=(()=>{let i=V.trim().toLowerCase();return!!i&&!o.some(a=>(a.title||a.name||"").toLowerCase().includes(i)||String(a.kind||"").toLowerCase().includes(i)||String(ve[a.kind]||"").toLowerCase().includes(i))})();(0,c.useEffect)(()=>{let i=P.current;i&&i.wake&&i.wake()},[V]),(0,c.useEffect)(()=>{let i=P.current;i&&i.render&&i.render()},[ue,W]);let ee=(0,c.useRef)(null),[S,H]=(0,c.useState)([]),[G,Ce]=(0,c.useState)(null),[re,de]=(0,c.useState)(!1),[fe,Ne]=(0,c.useState)(null),[xe,Fe]=(0,c.useState)(""),te=(0,c.useRef)(null),be=(0,c.useRef)(null),O=(i,a=!0)=>{te.current&&clearTimeout(te.current),Ne({msg:i,ok:a}),te.current=setTimeout(()=>Ne(null),1900)},Me=i=>{Fe(i),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>Fe(""),1600)};(0,c.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),be.current&&clearTimeout(be.current)},[]);let J=(0,c.useMemo)(()=>o.reduce((i,a)=>(i[a.id]=a,i),{}),[o]);return(0,c.useEffect)(()=>{let i=I.current;if(!i||o.length===0)return;let a=i.getContext("2d");if(!a)return;let N=Math.max(1,window.devicePixelRatio||1),d=()=>document.documentElement.getAttribute("data-theme")==="dark",x={};s.forEach(r=>{x[r.source]=(x[r.source]||0)+1,x[r.target]=(x[r.target]||0)+1});let f=Math.max(1,...Object.values(x)),t={nodes:o.map(r=>({id:r.id,name:r.title||"",type:r.kind||"other",r:9+Math.min(10,(x[r.id]||0)/f*8),x:0,y:0,vx:0,vy:0})),edges:s.map(r=>({sourceNodeId:r.source,targetNodeId:r.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:N,ctx:a,multi:[],marquee:null};t.domain=o,t.domainById=o.reduce((r,b)=>(r[b.id]=b,r),{}),t.nodes.forEach((r,b)=>{let p=b/t.nodes.length*Math.PI*2-Math.PI/2;r.x=Math.cos(p)*60,r.y=Math.sin(p)*60});let q=[...new Set(t.nodes.map(r=>r.type))];t.clustered=q.length>1,t.typeCenters={},q.forEach((r,b)=>{let p=b/q.length*Math.PI*2-Math.PI/2;t.typeCenters[r]={x:Math.cos(p)*160,y:Math.sin(p)*160}}),P.current=t;let Se=()=>{let r=i.clientWidth,b=i.clientHeight;t.w=r,t.h=b,i.width=r*N,i.height=b*N,a.setTransform(N,0,0,N,0,0)};Se();let Ie=new ResizeObserver(Se);Ie.observe(i.parentElement);let Ye=(r,b)=>r&&r.length>b?r.slice(0,b)+"\u2026":r,ie=(r,b,p,y)=>{if(a.beginPath(),y==="rect")a.rect(r-p,b-p*.75,p*2,p*1.5);else if(y==="diamond")a.moveTo(r,b-p),a.lineTo(r+p,b),a.lineTo(r,b+p),a.lineTo(r-p,b),a.closePath();else if(y==="hexagon"){for(let v=0;v<6;v++){let C=Math.PI/3*v-Math.PI/2,B=r+p*Math.cos(C),l=b+p*Math.sin(C);v===0?a.moveTo(B,l):a.lineTo(B,l)}a.closePath()}else a.arc(r,b,p,0,Math.PI*2)},se=()=>{if(!t.nodes.length)return;let r=1/0,b=-1/0,p=1/0,y=-1/0;t.nodes.forEach(M=>{r=Math.min(r,M.x),b=Math.max(b,M.x),p=Math.min(p,M.y),y=Math.max(y,M.y)});let v=36,C=b-r+v*2,B=y-p+v*2,l=Math.min(t.w/C,t.h/B);t.zoom=Math.max(.45,Math.min(2.4,l*1.22)),t.panX=t.w/2-(r+b)/2*t.zoom,t.panY=t.h/2-(p+y)/2*t.zoom};T.current=se;let Ue=()=>{a.clearRect(0,0,t.w,t.h),t.searchTerm=Q.current,t.kindFilter=R.current,t.timeMode=j.current;let r=t.kindFilter,b=l=>String(l||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");a.save(),a.strokeStyle=d()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",a.lineWidth=.5;for(let l=0;l<t.w;l+=24)a.beginPath(),a.moveTo(l,0),a.lineTo(l,t.h),a.stroke();for(let l=0;l<t.h;l+=24)a.beginPath(),a.moveTo(0,l),a.lineTo(t.w,l),a.stroke();a.restore(),a.save(),a.translate(t.panX,t.panY),a.scale(t.zoom,t.zoom);let p={};t.nodes.forEach(l=>p[l.id]=l);let y=t.nodes.length>40,v=y?1.5:.55,C=t.selectedId||t.hoverId;t.edges.forEach(l=>{let M=p[l.sourceNodeId],E=p[l.targetNodeId];if(!M||!E)return;if(r!=="all"){let Z=t.domainById[l.sourceNodeId]&&t.domainById[l.sourceNodeId].kind,Qe=t.domainById[l.targetNodeId]&&t.domainById[l.targetNodeId].kind;if(Z!==r&&Qe!==r)return}let w=E.x-M.x,k=E.y-M.y,D=Math.sqrt(w*w+k*k)||1,Y=y?12:18,X=-k/D*Y,oe=w/D*Y,K=(M.x+E.x)/2+X,pe=(M.y+E.y)/2+oe,ae=Ee.colors[t.domainById[M.id]&&t.domainById[M.id].kind||"other"],ge=C&&(l.sourceNodeId===C||l.targetNodeId===C),ze=C?ge?.6:.08:y?.14:.24,je=parseInt(ae.slice(1,3),16),De=parseInt(ae.slice(3,5),16),Ze=parseInt(ae.slice(5,7),16);a.strokeStyle="rgba("+je+","+De+","+Ze+","+ze+")",a.lineWidth=ge?1.6+(l.weight||1):.8+(l.weight||1)*.5,a.beginPath(),a.moveTo(M.x,M.y),a.quadraticCurveTo(K,pe,E.x,E.y),a.stroke()});let B=[];if(t.nodes.forEach(l=>{let M=t.domainById[l.id]||{},E=M.kind||"other",w=t.timeMode?zt(M.updated):Ee.colors[E],k=Ee.shapes[E],D=t.selectedId===l.id,Y=t.hoverId===l.id,X=t.searchTerm||"",oe=!X||(l.name||"").toLowerCase().includes(X)||String(ve[E]||"").toLowerCase().includes(X)||String(E).toLowerCase().includes(X),K=r==="all"||E===r,pe=C&&l.id!==C&&!t.edges.some(Z=>Z.sourceNodeId===C&&Z.targetNodeId===l.id||Z.targetNodeId===C&&Z.sourceNodeId===l.id)||X&&!oe||!K;a.save(),a.globalAlpha=pe?.08:1,(D||Y)&&(a.shadowColor=w,a.shadowBlur=D?20:14),ie(l.x,l.y,l.r,k);let ae=parseInt(w.slice(1,3),16),ge=parseInt(w.slice(3,5),16),ze=parseInt(w.slice(5,7),16),je=a.createRadialGradient(l.x-l.r*.3,l.y-l.r*.3,0,l.x,l.y,l.r*1.2);je.addColorStop(0,"rgba("+Math.min(255,ae+70)+","+Math.min(255,ge+70)+","+Math.min(255,ze+70)+",0.95)"),je.addColorStop(1,w),a.fillStyle=je,a.fill(),a.restore(),D?(a.save(),ie(l.x,l.y,l.r+3,k),a.strokeStyle=w,a.lineWidth=3,a.shadowColor=w,a.shadowBlur=12,a.stroke(),a.restore()):Y?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle=w,a.lineWidth=2,a.stroke(),a.restore()):X&&oe?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#e11d48",a.lineWidth=2,a.stroke(),a.restore()):t.multi.indexOf(l.id)>=0&&(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#60a5fa",a.lineWidth=2,a.shadowColor="#60a5fa",a.shadowBlur=8,a.stroke(),a.restore());let De=Ye(l.name,16);if((D||Y||t.zoom>v||!y&&t.zoom>.6)&&K){let Z=1/t.zoom;a.font="500 "+(12*Z).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let he=a.measureText(De).width+16*Z,Oe=18*Z,Te=l.y+l.r+8*Z,et=!0;for(let Le of B)if(l.x-he/2<Le.x+Le.w&&l.x+he/2>Le.x&&Te<Le.y+Le.h&&Te+Oe>Le.y){et=!1;break}if(!et&&!D&&!Y)return;B.push({x:l.x-he/2,y:Te,w:he,h:Oe}),a.fillStyle=d()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",a.beginPath(),a.roundRect?a.roundRect(l.x-he/2,Te,he,Oe,4*Z):a.rect(l.x-he/2,Te,he,Oe),a.fill(),a.strokeStyle=d()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",a.lineWidth=1*Z,a.stroke(),a.fillStyle=d()?D||Y?"#eee":"#bbb":D||Y?"#111":"#444",a.textAlign="center",a.fillText(De,l.x,Te+13*Z)}}),a.restore(),t.marquee){let l=t.marquee,M=Math.min(l.sx,l.ex),E=Math.min(l.sy,l.ey),w=Math.abs(l.ex-l.sx),k=Math.abs(l.ey-l.sy);a.save(),a.setLineDash([4,4]),a.strokeStyle="rgba(96,165,250,0.9)",a.lineWidth=1,a.fillStyle="rgba(96,165,250,0.12)",a.fillRect(M,E,w,k),a.strokeRect(M,E,w,k),a.restore()}if(t.hoverId&&ee.current){let l=t.domainById[t.hoverId],M=t.nodes.find(function(E){return E.id===t.hoverId});if(l&&M){let E=t.edges.filter(function(D){return D.sourceNodeId===l.id||D.targetNodeId===l.id}).length,w=M.x*t.zoom+t.panX,k=M.y*t.zoom+t.panY;ee.current.style.display="block",ee.current.style.left=w+14+"px",ee.current.style.top=k-6+"px",ee.current.innerHTML="<b>"+b(l.title||l.name||"")+'</b><br/><span style="opacity:.8">'+b(l.kind||"")+" \xB7 "+E+" \u8FDE\u63A5</span>"}}else ee.current&&(ee.current.style.display="none")},le=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=le,t.render=Ue;let qe=()=>{let r=t.nodes.length;t.tickCount++;let p=.9-Math.min(.4,t.tickCount/1500),y=r>1e3?3e3:r>100?2e3:r>50?1200:800,v=r>100?.002:.005,C=r>1e3?.012:r>100?.005:.01,B=r>1e3?6:r>200?12:24,l={};t.nodes.forEach(w=>l[w.id]=w);for(let w=0;w<r;w++){if(t.dragNode===t.nodes[w])continue;let k=t.nodes[w],D=0,Y=0;for(let K=0;K<r;K++){if(w===K)continue;let pe=k.x-t.nodes[K].x,ae=k.y-t.nodes[K].y,ge=Math.sqrt(pe*pe+ae*ae)||1,ze=y/(ge*ge);D+=pe/ge*ze,Y+=ae/ge*ze}if(t.clustered&&t.typeCenters[k.type]){let K=t.typeCenters[k.type];D+=(K.x-k.x)*.006,Y+=(K.y-k.y)*.006}else D-=k.x*C,Y-=k.y*C;let X=(k.vx+D)*p,oe=(k.vy+Y)*p;X=Math.max(-B,Math.min(B,X)),oe=Math.max(-B,Math.min(B,oe)),k.vx=X,k.vy=oe}t.edges.forEach(w=>{let k=l[w.sourceNodeId],D=l[w.targetNodeId];if(!k||!D)return;let Y=D.x-k.x,X=D.y-k.y,oe=Math.sqrt(Y*Y+X*X)||1,K=(oe-100)*v,pe=Y/oe*K,ae=X/oe*K;t.dragNode!==k&&(k.vx+=pe,k.vy+=ae),t.dragNode!==D&&(D.vx-=pe,D.vy-=ae)});let M=0;t.nodes.forEach(w=>{t.dragNode!==w&&(w.x+=w.vx,w.y+=w.vy,M+=w.vx*w.vx+w.vy*w.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,se()),(r?Math.sqrt(M/r):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{qe(),Ue()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Re=(r,b)=>{let p=i.getBoundingClientRect();return{x:(r-p.left-t.panX)/t.zoom,y:(b-p.top-t.panY)/t.zoom}},$e=(r,b,p)=>Math.max(b,Math.min(p,r)),Ke=r=>{t.mouseX=r.clientX,t.mouseY=r.clientY;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+36){p=v.id;break}}p!==t.hoverId&&(t.hoverId=p,le())},Ve=r=>{if(r.button!==0)return;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(r.shiftKey){t.marquee={sx:r.clientX,sy:r.clientY,ex:r.clientX,ey:r.clientY};return}t.dragStart={x:r.clientX,y:r.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=p||null,p&&(t.dragOffset={dx:p.x-b.x,dy:p.y-b.y})},He=r=>{if(t.marquee){t.marquee.ex=r.clientX,t.marquee.ey=r.clientY,le();return}if(!t.dragStart)return;let b=r.clientX-t.dragStart.x,p=r.clientY-t.dragStart.y;if(Math.abs(b)+Math.abs(p)>3&&(t.dragging=!0),t.dragNode){let y=Re(r.clientX,r.clientY);t.dragNode.x=y.x+t.dragOffset.dx,t.dragNode.y=y.y+t.dragOffset.dy,le()}else t.dragging&&(t.panX=$e(t.dragStart.px+b,-1e5,1e5),t.panY=$e(t.dragStart.py+p,-1e5,1e5),le())},Ge=r=>{if(t.marquee){let p=t.marquee;t.marquee=null;let y=i.getBoundingClientRect(),v=Math.min(p.sx,p.ex)-y.left,C=Math.max(p.sx,p.ex)-y.left,B=Math.min(p.sy,p.ey)-y.top,l=Math.max(p.sy,p.ey)-y.top,M=t.nodes.filter(E=>{let w=E.x*t.zoom+t.panX,k=E.y*t.zoom+t.panY;return w>=v&&w<=C&&k>=B&&k<=l}).map(E=>E.id);t.multi=M,H(M),le();return}if(t.dragStart&&!t.dragging){let p=Re(r.clientX,r.clientY),y=null;for(let v=t.nodes.length-1;v>=0;v--){let C=t.nodes[v];if(R.current!=="all"&&(t.domainById[C.id]&&t.domainById[C.id].kind)!==R.current)continue;let B=C.x-p.x,l=C.y-p.y;if(B*B+l*l<C.r*C.r+20){y=C;break}}y?(t.selectedId=y.id,ce(y.id),le()):(t.selectedId=null,t.hoverId=null,r.shiftKey||(t.multi=[],H([])),ce(null),le())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=r=>{r.preventDefault();let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(p){let y=t.domainById[p.id];y&&$({x:r.clientX,y:r.clientY,id:p.id,path:y.id,title:y.title})}else $(null)},Je=r=>{r.preventDefault();let b=i.getBoundingClientRect(),p=(r.clientX-b.left-t.panX)/t.zoom,y=(r.clientY-b.top-t.panY)/t.zoom,v=Math.max(.3,Math.min(3,t.zoom*(r.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+p*(t.zoom-v),-1e5,1e5),t.panY=$e(t.panY+y*(t.zoom-v),-1e5,1e5),t.zoom=v,le()};i.addEventListener("mousemove",Ke),i.addEventListener("mousedown",Ve),window.addEventListener("mousemove",He),window.addEventListener("mouseup",Ge),i.addEventListener("wheel",Je,{passive:!1}),i.addEventListener("contextmenu",_e),F.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],H([]),se(),le()};for(let r=0;r<200;r++)qe();return se(),le(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),Ie.disconnect(),i.removeEventListener("mousemove",Ke),i.removeEventListener("mousedown",Ve),window.removeEventListener("mousemove",He),window.removeEventListener("mouseup",Ge),i.removeEventListener("wheel",Je),i.removeEventListener("contextmenu",_e)}},[o,s]),(0,e.jsxs)("div",{className:"me-graph",ref:z,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[o.length," ",n("nodes")," \xB7 ",s.length," ",n("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:n("search"),value:V,onChange:i=>ke(i.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${W?" me-on":""}`,onClick:()=>h(i=>!i),children:n("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=I.current;if(i)try{i.toBlob(a=>{a&&Ce({url:URL.createObjectURL(a),blob:a})},"image/png")}catch{}},children:n("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>T.current&&T.current(),children:n("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{ce(null),ne("all"),F.current&&F.current()},children:n("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:I,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:ee,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[W?[{c:"#10b981",l:n("timeNew")},{c:"#f59e0b",l:n("timeRecent")},{c:"#f97316",l:n("timeMonth")},{c:"#94a3b8",l:n("timeOld")}].map(i=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:i.c}}),i.l]},i.c)):Object.keys(We).map(i=>(0,e.jsxs)("button",{type:"button",className:`lg${ue===i?" active":""}`,onClick:()=>ne(a=>a===i?"all":i),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[i]||We[i]}}),n(ve[i])]},i)),!W&&ue!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>ne("all"),children:[n("clearFilter")," \u2715"]})]}),ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:n("noMatch")}),L&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>$(null)}),L&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:L.x,top:L.y,zIndex:31},onMouseDown:i=>i.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{_.current({path:L.path,title:L.title}),$(null)},children:n("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{L.id&&(P.current.selectedId=L.id,ce(L.id)),$(null);let i=P.current;i&&i.wake&&i.wake()},children:n("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(L.title||"")}catch{}$(null),O(n("copied"))},children:n("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let i=L.path;$(null),window.confirm(n("deleteConfirm"))&&(async()=>{try{(me.current?await me.current(i):!1)?O(n("deleted")):O(n("deleteFail"),!1)}catch{O(n("deleteFail"),!1)}})()},children:n("delete")})]}),S.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:[S.length," ",n("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let a=S.map(f=>J[f]).filter(Boolean).map(f=>f.title||f.name).join(`
|
|
113
|
+
`),N=new Blob([a],{type:"text/plain;charset=utf-8"}),d=URL.createObjectURL(N),x=document.createElement("a");x.href=d,x.download="memory-selected.txt",document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(d),1e3),O(S.length+n("exportedSel"))},children:n("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(S.length<2){O(n("mergeNeed"),!1);return}let i=S.map(N=>J[N]?J[N].id:N);if(!window.confirm(n("mergeConfirm")))return;H([]);let a=P.current;a&&(a.multi=[]),fetch(`${U}/merge?paths=${encodeURIComponent(i.join(","))}`).then(N=>N.json()).then(N=>{N&&N.ok?O(n("merged")):O(n("mergeFail"),!1)}).catch(()=>O(n("mergeFail"),!1))},children:n("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(n("deleteConfirm")))return;let i=S.map(N=>J[N]?J[N].id:N);H([]);let a=P.current;a&&(a.multi=[]),(async()=>{let N=0;for(let d of i)try{(me.current?await me.current(d):!1)&&N++}catch{}O(N+n("deletedSelected"),N>0)})()},children:n("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=P.current;i&&(i.multi=[]),H([]);let a=P.current;a&&a.render&&a.render()},children:n("clearSelection")})]}),A&&(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:J[A]?J[A].title||J[A].name:A}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:J[A]?n(ve[J[A].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:n("graphHint")}),(s.filter(i=>i.source===A||i.target===A)||[]).slice(0,8).map((i,a)=>{let N=i.source===A?i.target:i.source,d=J[N];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:x=>{x.preventDefault();let f=P.current;f&&(f.selectedId=N,f.hoverId=N,f.wake&&f.wake()),ce(N)},children:d?(d.title||d.name).slice(0,28):N},a)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:n("graphTip")}),fe&&(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 "+(fe.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:fe.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:fe.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:fe.msg})]}),G&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{G.url&&URL.revokeObjectURL(G.url),Ce(null),de(!1)},children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:re?"100vw":900,width:re?"100vw":"92vw",maxHeight:re?"100vh":"90vh",height:re?"100vh":void 0,borderRadius:re?0:14},onClick:i=>i.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:n("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:G.url,download:"memory-graph.png",onClick:()=>{Me("download"),O(n("downloaded")+" \xB7 "+n("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:n(xe==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Me("save");let i=G.blob;i&&typeof window.showSaveFilePicker=="function"?rt(i,"memory-graph.png",!0).then(a=>{a.ok?O(n("exportedTo")+"\uFF1A"+a.name):a.aborted?O(n("exportCancel")):O(n("exportFail"),!1)}):O(n("saveAsUnsupported"),!1)},children:n(xe==="save"?"done":"saveAs")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Me("full"),de(i=>!i),O(n("fullscreen"))},children:n(xe==="full"?"done":re?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=G.blob;i&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":i})]).then(()=>{Me("copy"),O(n("copied"))}).catch(()=>{O(n("copyFail"),!1)}):O(n("copyFail"),!1)},children:n(xe==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{G.url&&URL.revokeObjectURL(G.url),Ce(null),de(!1)},children:n("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:re?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:G.url,alt:n("exportGraph"),style:{maxWidth:"100%",maxHeight:re?"calc(100vh - 64px)":"70vh",borderRadius:re?0:8,cursor:"zoom-in"},onClick:()=>de(i=>!i)})})]})]})]})}function zt(o){let s=new Date(o||0).getTime();if(!s)return"#94a3b8";let m=(Date.now()-s)/864e5;return m<3?"#10b981":m<14?"#f59e0b":m<30?"#f97316":"#94a3b8"}function Tt(o){let s=new Date(o||0).getTime();return!!s&&(Date.now()-s)/864e5<3}async function rt(o,s,m){if(m&&typeof window.showSaveFilePicker=="function")try{let g=await window.showSaveFilePicker({suggestedName:s}),I=await g.createWritable();return await I.write(o),await I.close(),{ok:!0,picked:!0,name:g.name}}catch(g){return g&&g.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(g.message||g)}}let u=URL.createObjectURL(o),n=document.createElement("a");return n.href=u,n.download=s,document.body.appendChild(n),n.click(),document.body.removeChild(n),setTimeout(()=>URL.revokeObjectURL(u),1e3),{ok:!0,picked:!1,name:s}}function ot(o,s){if(!s||!o)return o;let m=o.toLowerCase(),u=s.toLowerCase(),n=[],g=0;for(;g<o.length;){let I=m.indexOf(u,g);if(I<0){n.push(o.slice(g));break}I>g&&n.push(o.slice(g,I)),n.push((0,e.jsx)("mark",{className:"mc-hl",children:o.slice(I,I+u.length)},I)),g=I+u.length}return n}function Lt(o){if(!o)return"";let s=String(o).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),m=[];return s=s.replace(/```([\w-]*)\n([\s\S]*?)```/g,function(u,n,g){return m.push("<pre><code>"+g+"</code></pre>"),"\0"+(m.length-1)+"\0"}),s=s.replace(/^(#{1,3})\s+(.+)$/gm,function(u,n,g){return"<h"+n.length+">"+g+"</h"+n.length+">"}),s=s.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),s=s.replace(/`([^`\n]+)`/g,"<code>$1</code>"),s=s.replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>"),s=s.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(u,n,g){return/^(https?:|\/)/.test(g)?'<a href="'+g+'" target="_blank" rel="noopener noreferrer">'+n+"</a>":n}),s=s.replace(/^(-)\s+(.+)$/gm,"\u2022 $2"),s=s.replace(/^\s*(>)\s*(.+)$/gm,"<blockquote>$2</blockquote>"),s=s.replace(/\n/g,"<br/>"),s=s.replace(/\u0000(\d+)\u0000/g,function(u,n){return m[n]}),s}function it(o){if(!o)return"";let s=new Date(o);if(Number.isNaN(s.getTime()))return"";let m=new Date,u=s.toDateString()===m.toDateString(),n=I=>String(I).padStart(2,"0"),g=`${n(s.getHours())}:${n(s.getMinutes())}`;return u?g:`${s.getMonth()+1}-${s.getDate()} ${g}`}
|
|
114
114
|
|
|
115
115
|
return module.exports;
|
|
116
116
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memory-eternal",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|