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/lib/stall.js CHANGED
@@ -17,13 +17,21 @@
17
17
  * @param {number} [input.now] 当前时间
18
18
  * @param {number} [input.windowMs] 观察窗口,默认 20 分钟
19
19
  * @param {number} [input.minStarted] 窗口内至少开始几个轮次才判停滞,默认 3
20
- * @returns {{alert:boolean, started:number, stopped:number, windowMs:number}}
20
+ * @param {number} [input.everStopped] 本次运行**至今**收到的收尾事件数(缺省 = stoppedAt.length)
21
+ * @returns {{alert:boolean, started:number, stopped:number, windowMs:number, reason:string}}
21
22
  */
22
- export function evaluateStall({ claimedAt = [], stoppedAt = [], now = Date.now(), windowMs = 20 * 60 * 1000, minStarted = 3 } = {}) {
23
+ export function evaluateStall({ claimedAt = [], stoppedAt = [], now = Date.now(), windowMs = 20 * 60 * 1000, minStarted = 3, everStopped } = {}) {
23
24
  const from = now - windowMs
24
25
  const started = claimedAt.filter((t) => t >= from).length
25
26
  const stopped = stoppedAt.filter((t) => t >= from).length
26
- return { alert: started >= minStarted && stopped === 0, started, stopped, windowMs }
27
+ // 2026-10-09:再加一条硬前提 —— 「事件被改名/移除」是**进程生命周期**属性,不是窗口属性。
28
+ // 只要本次运行里见过哪怕一次收尾,事件通路就是通的;窗口内 0 收尾只说明「当前这一轮还没结束」
29
+ // (实测:一轮几十分钟的对话里 agent/inbox/claimed 会多次触发,而 turn-stopping 要等回合真的
30
+ // 结束才来 —— 20 分钟窗口必然 3 次 claim / 0 收尾,于是长回合被误报成「收尾事件疑似失效」,
31
+ // 并且把「自动沉淀异常」这个红警报推给了用户)。真的被改名时,本次运行会是 0 收尾。
32
+ const ever = Number.isFinite(everStopped) ? Number(everStopped) : stoppedAt.length
33
+ if (ever > 0) return { alert: false, started, stopped, windowMs, reason: 'wiring-proven' }
34
+ return { alert: started >= minStarted && stopped === 0, started, stopped, windowMs, reason: 'no-stop-ever' }
27
35
  }
28
36
 
29
37
  /** 时间戳数组的裁剪上限:只保留窗口相关的近邻,避免长跑无界增长。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-eternal",
3
- "version": "0.10.13",
3
+ "version": "0.10.15",
4
4
  "description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
5
5
  "license": "MIT",
6
6
  "repository": {
package/web/app.js CHANGED
@@ -300,11 +300,11 @@ Option A, because:
300
300
  height: calc(100vh - var(--dsh-windows-titlebar-height, 0px));
301
301
  max-height: calc(100vh - var(--dsh-windows-titlebar-height, 0px));
302
302
  }
303
- `;function Vg(){return(0,i.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,i.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,i.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,i.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,i.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,i.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,i.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,i.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}var Ko="0.10.13";function ef({t:e,inModal:t,onClose:n,onFull:r,full:o}){let[l,a]=(0,v.useState)(null),[s,u]=(0,v.useState)([]),[f,y]=(0,v.useState)(!0),[h,m]=(0,v.useState)(null),[k,M]=(0,v.useState)(""),[w,I]=(0,v.useState)("all"),[d,c]=(0,v.useState)(""),[g,N]=(0,v.useState)("all"),[P,j]=(0,v.useState)("all"),[D,O]=(0,v.useState)(()=>{try{let L=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),V={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(L&&V[L])return V[L]}catch{}return"cards"}),[Y,_]=(0,v.useState)(()=>new Set([D])),T=(0,v.useCallback)(L=>{_(V=>V.has(L)?V:new Set(V).add(L)),O(L)},[]),[K,A]=(0,v.useState)("recent"),[ce,Z]=(0,v.useState)(null),re=(0,v.useRef)(null),me=(0,v.useRef)(null),[z,G]=(0,v.useState)(!1),[he,te]=(0,v.useState)(null),[pe,Fe]=(0,v.useState)(!1),[ht,Qe]=(0,v.useState)(!1),[_e,He]=(0,v.useState)(!0),[bn,un]=(0,v.useState)(null),[Gt,Kn]=(0,v.useState)(0),Sn=(0,v.useCallback)(()=>Kn(L=>L+1),[]),ot=l?.quarantine?.pending??0,yt=l?.quarantine?.deleted??0,xe=(0,v.useRef)(null),[qt,We]=(0,v.useState)(0),[S,x]=(0,v.useState)(!1),Q=(0,v.useRef)(null),ge=(0,v.useRef)(null),q=(0,v.useCallback)(async(L=w,V=d,le=P,Ae={})=>{let ne=Ae.append===!0;try{ne?x(!0):(y(!0),M(""));let Le=new URLSearchParams;L&&L!=="all"&&Le.set("kind",L),V.trim()&&Le.set("q",V.trim()),Le.set("status",le||"all"),Le.set("limit",String(Wg)),Le.set("offset",String(Ae.offset||0)),K==="title"&&Le.set("sort","title");let lt=await(await fetch(`${J}/cards?${Le.toString()}`)).json();if(lt.ok){let jt=lt.cards||[];u(Et=>ne?[...Et,...jt.filter(Bt=>!Et.some(Xo=>Xo.path===Bt.path))]:jt),We(Number(lt.total)||jt.length)}}catch(Le){M(String(Le&&Le.message?Le.message:Le))}finally{ne?x(!1):y(!1)}},[w,d,P,K]),ke=(0,v.useCallback)(async()=>{try{let[L,V]=await Promise.all([fetch(`${J}/overview`).then(le=>le.json()),fetch(`${J}/capture-log`).then(le=>le.json()).catch(()=>null)]);L.ok&&a(L),m(V&&V.ok&&V.available&&V.health||null)}catch(L){M(String(L&&L.message?L.message:L))}finally{y(!1)}},[]),p=async L=>{try{let le=await(await fetch(`${J}/delete?path=${encodeURIComponent(L)}`)).json();le.ok?(Z({ok:!0,msg:e("deleted")}),await ke(),Sn()):Z({ok:!1,msg:le.error||e("deleteFail")})}catch{Z({ok:!1,msg:e("deleteFail")})}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)};(0,v.useEffect)(()=>(ke(),()=>{xe.current&&clearTimeout(xe.current)}),[ke]);let b=L=>{c(L),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>q(w,L,P),280)},W=L=>{I(L),q(L,d,P)};(0,v.useEffect)(()=>{D==="cards"&&q(w,d,P)},[P,D,Gt,K]),(0,v.useEffect)(()=>{if(D!=="cards"||f||S||s.length>=qt)return;let L=Q.current,V=ge.current;if(!L)return;let le=new IntersectionObserver(Ae=>{Ae[0]&&Ae[0].isIntersecting&&q(w,d,P,{append:!0,offset:s.length})},{root:V||null,rootMargin:"400px"});return le.observe(L),()=>le.disconnect()},[D,s,qt,f,S,w,d,P,q]);let U=async L=>{try{let V=L.status;if(!V&&L.path)try{let Ze=((await fetch(`${J}/cards?status=all&q=${encodeURIComponent(L.title||"")}&limit=50`).then(lt=>lt.json())).cards||[]).find(lt=>lt.path===L.path);Ze&&(V=Ze.status)}catch{}let le=V&&V!=="approved"?`&status=${encodeURIComponent(V)}`:"",Ae=await fetch(`${J}/card?path=${encodeURIComponent(L.path||L.id)}${le}`),ne=await Ae.json();ne.ok?te({path:ne.path,title:L.title,text:ne.text}):M(ne.error||`HTTP ${Ae.status}`)}catch(V){M(String(V&&V.message?V.message:V))}},oe=async(L,V)=>{G(!0);try{let le=await fetch(`${J}/export`);if(!le.ok)throw new Error("HTTP "+le.status);let Ae=await le.json();if(!Ae.ok)throw new Error(Ae.error||"export failed");let ne,Le,Ze;if(L==="json"){Le="memory-vault.json",Ze="application/json";let Et=Ae.cards.map(Bt=>({path:Bt.path,title:Bt.title,kind:Bt.kind,status:Bt.status,store:Bt.store,text:Bt.text}));ne=JSON.stringify({format:Ae.format||"memory-eternal-vault",formatVersion:Ae.formatVersion||1,exportedAt:Ae.exportedAt||new Date().toISOString(),count:Et.length,cards:Et},null,2)}else Le="memory-vault.md",Ze="text/markdown;charset=utf-8",ne=Ae.cards.map(Et=>Et.text.trim()).filter(Boolean).join(`
303
+ `;function Vg(){return(0,i.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,i.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,i.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,i.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,i.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,i.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,i.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,i.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}var Ko="0.10.15";function ef({t:e,inModal:t,onClose:n,onFull:r,full:o}){let[l,a]=(0,v.useState)(null),[s,u]=(0,v.useState)([]),[f,y]=(0,v.useState)(!0),[h,m]=(0,v.useState)(null),[k,M]=(0,v.useState)(""),[w,I]=(0,v.useState)("all"),[d,c]=(0,v.useState)(""),[g,N]=(0,v.useState)("all"),[P,j]=(0,v.useState)("all"),[D,O]=(0,v.useState)(()=>{try{let L=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),V={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(L&&V[L])return V[L]}catch{}return"cards"}),[Y,_]=(0,v.useState)(()=>new Set([D])),T=(0,v.useCallback)(L=>{_(V=>V.has(L)?V:new Set(V).add(L)),O(L)},[]),[K,A]=(0,v.useState)("recent"),[ce,Z]=(0,v.useState)(null),re=(0,v.useRef)(null),me=(0,v.useRef)(null),[z,G]=(0,v.useState)(!1),[he,te]=(0,v.useState)(null),[pe,Fe]=(0,v.useState)(!1),[ht,Qe]=(0,v.useState)(!1),[_e,He]=(0,v.useState)(!0),[bn,un]=(0,v.useState)(null),[Gt,Kn]=(0,v.useState)(0),Sn=(0,v.useCallback)(()=>Kn(L=>L+1),[]),ot=l?.quarantine?.pending??0,yt=l?.quarantine?.deleted??0,xe=(0,v.useRef)(null),[qt,We]=(0,v.useState)(0),[S,x]=(0,v.useState)(!1),Q=(0,v.useRef)(null),ge=(0,v.useRef)(null),q=(0,v.useCallback)(async(L=w,V=d,le=P,Ae={})=>{let ne=Ae.append===!0;try{ne?x(!0):(y(!0),M(""));let Le=new URLSearchParams;L&&L!=="all"&&Le.set("kind",L),V.trim()&&Le.set("q",V.trim()),Le.set("status",le||"all"),Le.set("limit",String(Wg)),Le.set("offset",String(Ae.offset||0)),K==="title"&&Le.set("sort","title");let lt=await(await fetch(`${J}/cards?${Le.toString()}`)).json();if(lt.ok){let jt=lt.cards||[];u(Et=>ne?[...Et,...jt.filter(Bt=>!Et.some(Xo=>Xo.path===Bt.path))]:jt),We(Number(lt.total)||jt.length)}}catch(Le){M(String(Le&&Le.message?Le.message:Le))}finally{ne?x(!1):y(!1)}},[w,d,P,K]),ke=(0,v.useCallback)(async()=>{try{let[L,V]=await Promise.all([fetch(`${J}/overview`).then(le=>le.json()),fetch(`${J}/capture-log`).then(le=>le.json()).catch(()=>null)]);L.ok&&a(L),m(V&&V.ok&&V.available&&V.health||null)}catch(L){M(String(L&&L.message?L.message:L))}finally{y(!1)}},[]),p=async L=>{try{let le=await(await fetch(`${J}/delete?path=${encodeURIComponent(L)}`)).json();le.ok?(Z({ok:!0,msg:e("deleted")}),await ke(),Sn()):Z({ok:!1,msg:le.error||e("deleteFail")})}catch{Z({ok:!1,msg:e("deleteFail")})}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)};(0,v.useEffect)(()=>(ke(),()=>{xe.current&&clearTimeout(xe.current)}),[ke]);let b=L=>{c(L),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>q(w,L,P),280)},W=L=>{I(L),q(L,d,P)};(0,v.useEffect)(()=>{D==="cards"&&q(w,d,P)},[P,D,Gt,K]),(0,v.useEffect)(()=>{if(D!=="cards"||f||S||s.length>=qt)return;let L=Q.current,V=ge.current;if(!L)return;let le=new IntersectionObserver(Ae=>{Ae[0]&&Ae[0].isIntersecting&&q(w,d,P,{append:!0,offset:s.length})},{root:V||null,rootMargin:"400px"});return le.observe(L),()=>le.disconnect()},[D,s,qt,f,S,w,d,P,q]);let U=async L=>{try{let V=L.status;if(!V&&L.path)try{let Ze=((await fetch(`${J}/cards?status=all&q=${encodeURIComponent(L.title||"")}&limit=50`).then(lt=>lt.json())).cards||[]).find(lt=>lt.path===L.path);Ze&&(V=Ze.status)}catch{}let le=V&&V!=="approved"?`&status=${encodeURIComponent(V)}`:"",Ae=await fetch(`${J}/card?path=${encodeURIComponent(L.path||L.id)}${le}`),ne=await Ae.json();ne.ok?te({path:ne.path,title:L.title,text:ne.text}):M(ne.error||`HTTP ${Ae.status}`)}catch(V){M(String(V&&V.message?V.message:V))}},oe=async(L,V)=>{G(!0);try{let le=await fetch(`${J}/export`);if(!le.ok)throw new Error("HTTP "+le.status);let Ae=await le.json();if(!Ae.ok)throw new Error(Ae.error||"export failed");let ne,Le,Ze;if(L==="json"){Le="memory-vault.json",Ze="application/json";let Et=Ae.cards.map(Bt=>({path:Bt.path,title:Bt.title,kind:Bt.kind,status:Bt.status,store:Bt.store,text:Bt.text}));ne=JSON.stringify({format:Ae.format||"memory-eternal-vault",formatVersion:Ae.formatVersion||1,exportedAt:Ae.exportedAt||new Date().toISOString(),count:Et.length,cards:Et},null,2)}else Le="memory-vault.md",Ze="text/markdown;charset=utf-8",ne=Ae.cards.map(Et=>Et.text.trim()).filter(Boolean).join(`
304
304
 
305
305
  ---
306
306
 
307
- `);let lt=new Blob([ne],{type:Ze}),jt=await lh(lt,Le,!1);if(!jt.ok){Z({ok:!1,msg:e("exportFail")}),G(!1);return}Z({ok:!0,msg:e("exportedTo")+"\uFF1A"+e("defaultDownloads")+" \xB7 "+jt.name})}catch(le){Z({ok:!1,msg:e("exportFail")+" \xB7 "+(le.message||"")})}finally{G(!1)}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2600)},ze=async L=>{let V=L.target.files&&L.target.files[0];if(L.target.value="",!!V){try{let le=await V.text(),ne=await(await fetch(`${J}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:le})).json();if(ne.ok){await ke();let Le=ne.imported||0,Ze=e("importedVault")+"\uFF1A"+Le;ne.total&&(Ze+=e("importedTotal")+ne.total+e("importedTotalTail")),ne.quarantined&&(Ze+=e("importedQuarantine")+ne.quarantined+e("importedQuarantineTail")),ne.skipped&&(Ze+=e("importedSkipped")+ne.skipped+e("importedSkippedTail")),ne.warning&&(Ze+=" \xB7 "+ne.warning),Z({ok:Le>0||!ne.total,msg:Ze})}else Z({ok:!1,msg:ne.error||e("importFail")})}catch{Z({ok:!1,msg:e("importFail")})}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2400)}},ee=(0,v.useMemo)(()=>{let L=s.slice();return g!=="all"&&(L=L.filter(V=>Kr(V.submittedBy)===g)),P!=="all"&&(L=L.filter(V=>(V.status||"approved")===P)),K==="title"?L.sort((V,le)=>String(V.title||"").localeCompare(String(le.title||""))):K==="hot"?L.sort((V,le)=>(le.weight||le.links||0)-(V.weight||V.links||0)):L.sort((V,le)=>new Date(le.updated||0).getTime()-new Date(V.updated||0).getTime()),L},[s,K,g,P]),de=(0,v.useMemo)(()=>[...new Set(s.map(L=>Kr(L.submittedBy)))],[s]);return(0,i.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,i.jsx)("style",{children:sn}),ce&&(0,i.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 "+(ce.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,i.jsx)("span",{style:{color:ce.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:ce.ok?"\u2713":"\u2715"}),(0,i.jsx)("span",{children:ce.msg})]}),t&&(0,i.jsxs)("div",{className:"me-modal-head",children:[(0,i.jsxs)("div",{className:"me-modal-title",children:[(0,i.jsx)("span",{className:"me-wicon",children:(0,i.jsx)(Vg,{})}),(0,i.jsx)("h2",{children:e("memoryTitle")}),(0,i.jsx)("span",{children:e("memoryHint")})]}),(0,i.jsx)("div",{className:"spacer"}),r&&(0,i.jsx)("button",{type:"button",className:"me-modal-close",onClick:r,"aria-label":e(o?"exitFull":"fullscreen"),children:o?"\u2750":"\u26F6"}),(0,i.jsx)("button",{type:"button",className:"me-modal-close",onClick:n,"aria-label":e("close"),children:"\u2715"})]}),h&&h.ok===!1&&(0,i.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,i.jsxs)("span",{style:{fontWeight:800},children:["\u26A0 ",e("captureAlert")]}),(0,i.jsxs)("span",{style:{flex:1},children:[h.reason,(0,i.jsx)("div",{style:{opacity:.68,fontSize:11.5,marginTop:2},children:e("captureAlertHint")})]}),(0,i.jsx)("span",{style:{opacity:.7},children:h.since?Vr(new Date(h.since).toISOString()):""})]}),(0,i.jsxs)("div",{className:"me-modal-body",children:[(0,i.jsxs)("div",{className:`mc-rail${_e?" open":""}`,children:[(0,i.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>He(L=>!L),"aria-label":e(_e?"collapse":"expand"),title:e(_e?"collapse":"expand"),children:_e?"\xAB":"\xBB"}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="cards"?" active":""}`,onClick:()=>T("cards"),title:e("cardsTab"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F9E0}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("cardsTab")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="graph"?" active":""}`,onClick:()=>T("graph"),title:e("graphTab"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F52E}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("graphTab")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="stats"?" active":""}`,onClick:()=>T("stats"),title:e("tabUsage"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C8}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabUsage")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="audit"?" active":""}`,onClick:()=>T("audit"),title:e("tabAudit"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F50D}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabAudit")}),ot>0&&(0,i.jsx)("span",{className:"mc-dot",children:ot>99?"99+":ot})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="optimize"?" active":""}`,onClick:()=>T("optimize"),title:e("tabRecycle"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u267B\uFE0F"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabRecycle")}),yt>0&&(0,i.jsx)("span",{className:"mc-dot",style:{background:"#6b7280"},children:yt>99?"99+":yt})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="config"?" active":""}`,onClick:()=>T("config"),title:e("tabConfig"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabConfig")})]}),(0,i.jsxs)("button",{type:"button",className:"mc-railbtn",onClick:()=>Qe(!0),title:e("fbNav"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F41E}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("fbNav")})]})]}),(0,i.jsxs)("div",{className:"mc-main",ref:ge,children:[D==="cards"&&(0,i.jsxs)("div",{className:"mc-stats",children:[(0,i.jsx)($r,{label:e("total"),value:l?l.total:"\u2014"}),(0,i.jsx)($r,{label:e("recent"),value:l?l.recent:"\u2014"}),(0,i.jsx)($r,{label:e("tags"),value:l?l.tags:"\u2014"}),(0,i.jsx)($r,{label:e("pending"),value:l?.quarantine?.pending??l?.status?.pending??0}),(0,i.jsx)($r,{label:e("rejected"),value:l?.quarantine?.rejected??l?.status?.rejected??0}),(0,i.jsx)($r,{label:e("cardCount"),value:l?l.byKind?.knowledge??0:"\u2014"})]}),D==="cards"&&(0,i.jsxs)("div",{className:"mc-toolbar",children:[(0,i.jsx)("input",{type:"text",placeholder:e("searchPlaceholder"),value:d,onChange:L=>b(L.target.value)}),(0,i.jsx)("input",{ref:me,type:"file",accept:".json,application/json",style:{display:"none"},onChange:ze}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>me.current&&me.current.click(),children:e("importVault")}),(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",onClick:()=>un({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",e("newCard")]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:z,onClick:()=>oe("md"),children:e(z?"exporting":"exportVault")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:z,onClick:()=>oe("json"),children:e(z?"exporting":"exportJson")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ke(),children:e("refresh")})]}),D==="cards"&&(0,i.jsxs)("div",{className:"mc-chips",children:[Gs.map(L=>(0,i.jsx)("button",{type:"button",className:`mc-chip${w===L?" active":""}`,onClick:()=>W(L),children:e(L==="all"?"all":Ft[L])},L)),(0,i.jsxs)("select",{value:g,onChange:L=>N(L.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,i.jsxs)("option",{value:"all",children:["\u{1F916} ",e("allAgents")]}),Jp(de).map(L=>(0,i.jsx)("option",{value:L,children:L},L))]}),(0,i.jsxs)("select",{value:P,onChange:L=>j(L.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,i.jsx)("option",{value:"all",children:e("allStatus")}),(0,i.jsx)("option",{value:"approved",children:e("statusApproved")}),(0,i.jsx)("option",{value:"pending",children:e("statusPending")}),(0,i.jsx)("option",{value:"rejected",children:e("statusRejected")})]}),(0,i.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:e("sortRecent")},{key:"title",label:e("sortTitle")},{key:"hot",label:e("sortHot")}].map(L=>(0,i.jsx)("button",{type:"button",className:`mc-chip${K===L.key?" active":""}`,onClick:()=>A(L.key),children:L.label},L.key))]}),k&&(0,i.jsxs)("div",{className:"mc-empty",children:[e("error"),"\uFF1A",k]}),(0,i.jsx)("div",{style:{display:D==="cards"?"contents":"none"},children:f?(0,i.jsx)("div",{className:"mc-empty",children:e("loading")}):k?(0,i.jsxs)("div",{className:"mc-empty",children:[e("error"),"\uFF1A",k," ",(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ke(),children:e("retry")})]}):s.length===0?(0,i.jsx)("div",{className:"mc-empty",children:e("empty")}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"mc-grid",children:ee.map(L=>(0,i.jsx)(Xg,{card:L,t:e,query:d.trim(),onOpen:U,onDelete:p},L.path))}),s.length<qt&&(0,i.jsx)("div",{ref:Q,style:{height:1}}),S&&(0,i.jsxs)("div",{className:"mc-empty",style:{padding:"10px 0"},children:[e("loading"),"\uFF08",s.length," / ",qt,"\uFF09"]})]})}),(0,i.jsx)("div",{style:{display:D==="graph"?"flex":"none",flex:1,minHeight:0},children:Y.has("graph")&&(0,i.jsx)(eh,{t:e,onOpen:U,all:pe,onAllChange:Fe,onMutate:Sn,active:D==="graph",visible:D==="graph"})}),(0,i.jsx)("div",{style:{display:D==="config"?"contents":"none"},children:Y.has("config")&&(0,i.jsx)(Kg,{t:e,onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="stats"?"contents":"none"},children:Y.has("stats")&&(0,i.jsx)(Gg,{t:e,tab:"stats",onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="audit"?"contents":"none"},children:Y.has("audit")&&(0,i.jsx)(Qg,{t:e,onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="optimize"?"contents":"none"},children:Y.has("optimize")&&(0,i.jsx)(Yg,{t:e,onReload:()=>ke(),version:Gt})}),ht&&(0,i.jsx)(Zg,{t:e,onClose:()=>Qe(!1)}),he&&(0,i.jsx)(Jg,{t:e,card:he,query:d.trim(),onClose:()=>te(null),onDelete:L=>{te(null),p(L)},onFeedback:L=>{let V=he.path;fetch(`${J}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:d.trim(),path:V,useful:L})}).then(()=>Z({ok:!0,msg:e(L?"fbUseful":"fbIrr")})).catch(()=>{}),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)}}),(0,i.jsx)(qg,{t:e,newCard:bn,setNewCard:un,onCreated:()=>{ke(),Sn(),Z({ok:!0,msg:e("created")}),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)}})]})]})]})}var tf=({toast:e})=>e?(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"8px 12px",fontSize:12,borderLeft:"4px solid "+(e.ok?"#10b981":"#ef4444"),background:e.ok?"rgba(16,185,129,0.08)":"rgba(239,68,68,0.08)"},children:[e.ok?"\u2705":"\u26A0"," ",e.msg]}):null,$r=({label:e,value:t})=>(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:t}),(0,i.jsx)("span",{children:e})]});function Kg({t:e,onReload:t,version:n,compact:r}){let[o,l]=(0,v.useState)(null),[a,s]=(0,v.useState)(0),[u,f]=(0,v.useState)(null),[y,h]=(0,v.useState)(null),[m,k]=(0,v.useState)(!1),[M,w]=(0,v.useState)(!1),I=(0,v.useRef)(!1),d=(0,v.useRef)(null),c=(0,v.useRef)({}),[g,N]=(0,v.useState)(null),[P,j]=(0,v.useState)(null),[D,O]=(0,v.useState)(""),[Y,_]=(0,v.useState)(""),[T,K]=(0,v.useState)(""),[A,ce]=(0,v.useState)(null),Z=(0,v.useCallback)(async b=>{_("version");try{let W=await fetch(J+"/version-check"+(b?"?force=1":"")).then(U=>U.json());W&&W.ok?(ce(W),b&&te(W.updateAvailable?e("vcLatest")+" v"+W.latest:e("vcUpToDate"))):b&&te(e("vcCheckFail"),!1)}catch{b&&te(e("vcCheckFail"),!1)}finally{_("")}},[e]);(0,v.useEffect)(()=>{Z(!1)},[n,Z]);let[re,me]=(0,v.useState)(""),[z,G]=(0,v.useState)(null),he=(0,v.useRef)(null),te=(b,W=!0)=>{he.current&&clearTimeout(he.current),G({msg:b,ok:W}),he.current=setTimeout(()=>G(null),1900)},pe=async()=>{if(!Y){_("restart");try{let b=await fetch(J+"/restart-self",{method:"POST"});if(b.status===404||b.status===405){te(Qe("vcRestartNoRoute",{cmd:A&&A.restartCommand||"dsh-memory restart --port 7999"}),!1);return}let W=await b.json().catch(()=>null);if(!W){te(e("vcRestartFail")+"\uFF08HTTP "+b.status+"\uFF09",!1);return}if(!W.ok){te(W.error||e("vcRestartFail"),!1);return}if(W.alreadyCurrent){te(W.note||e("vcRestartCurrent"));return}te(W.note||e("vcRestartSent")),W.alreadyRunning||setTimeout(()=>{Z(!0)},6e3)}catch(b){te(e("vcRestartFail")+"\uFF1A"+String(b&&b.message||b),!1)}finally{_("")}}},Fe=A&&A.resident?String(A.resident.served||""):"",ht=!!(A&&A.onDisk&&Fe&&Fe!==A.onDisk),Qe=(b,W)=>Object.keys(W).reduce((U,oe)=>U.split("{"+oe+"}").join(W[oe]),e(b)),_e=(0,v.useCallback)(async()=>{try{let[b,W,U]=await Promise.all([fetch(`${J}/config`).then(oe=>oe.json()).catch(()=>null),fetch(`${J}/setup-status`).then(oe=>oe.json()).catch(()=>null),fetch(`${J}/budget`).then(oe=>oe.json()).catch(()=>null)]);if(b&&b.ok){l(b),s(b.revision??0),f(b.schema??null);let oe=Vp(b.config??{},c.current);c.current=oe.overlay,h({...oe.values}),N(b.dsh??null),k(b.writable===!1),w(b.viaPending===!0),O(""),I.current=!1}else U&&U.ok?(h({...U}),k(!0),O(e("configNeedsDsh"))):O(e("adminLoadFail"));W&&W.ok&&j(W),K("")}catch{O(e("adminLoadFail"))}},[e]);(0,v.useEffect)(()=>{_e()},[n,_e]);let He=(b,W)=>{I.current=!0,h(U=>({...U??{},[b]:W}))};(0,v.useEffect)(()=>{d.current=_e},[_e]),(0,v.useEffect)(()=>{if(typeof EventSource>"u")return;let b=null;try{b=new EventSource(J+"/events")}catch{return}let W=()=>{!I.current&&typeof d.current=="function"&&d.current()};try{b.addEventListener("config",W)}catch{}return()=>{try{b.close()}catch{}}},[]);let bn=new Set(["dedupThreshold","captureMinChars","captureCooldownMs","maxCardsPerDay","captureMaxTokens","recallMinScore","recallLimit","recallSummaryLen","recycleRetentionDays","webPort","webCheckIntervalMs","webMaxRestart","sessionBudgetChars"]),un=b=>({init:e("modeInit"),interval:e("modeInterval"),manual:e("modeManual")})[b]||b,Gt=async()=>{if(!y)return;if(m){te(e("editInSetting"),!1);return}let b={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]},W=[];for(let[U,[oe,ze]]of Object.entries(b)){if(!(U in y))continue;let ee=y[U],de=typeof ee=="number"?ee:Number(ee);(ee===""||ee===null||ee===void 0||!Number.isFinite(de)||de<oe||de>ze)&&W.push(e("invalidField",{field:U,min:oe,max:ze,value:String(ee===""?"\u7A7A":ee)}))}if(W.length){let U=e("saveInvalid")+"\uFF1A"+W.join("\uFF1B");O(U),te(U,!1);return}_("save");try{let U={...y};for(let de of Object.keys(y))de in U&&typeof U[de]=="string"&&U[de].trim()!==""&&bn.has(de)&&(U[de]=Number(U[de]));Array.isArray(U.vaultProfiles)&&(U.vaultProfiles=U.vaultProfiles.filter(de=>de&&(String(de.name||"").trim()||String(de.path||"").trim())));let oe=await fetch(`${J}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:U,expectedRevision:a})}),ze=await oe.text(),ee=null;try{ee=ze?JSON.parse(ze):null}catch{ee=null}if(ee||(ee={error:"HTTP "+oe.status+(ze?"\uFF1A"+ze.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")}),ee&&ee.ok){let de=typeof ee.pendingOutcome=="string"?ee.pendingOutcome:"",L,V=!0;if(de==="applied")L=e("savedApplied")+(Array.isArray(ee.applied)&&ee.applied.length?" \xB7 "+ee.applied.join("\u3001"):"");else if(de==="queued")V=!1,L=e("saveQueued");else if(de==="failed")V=!1,L=e("saveFail")+" \xB7 "+(ee.hostGuard?e("saveHostGuard"):e("saveFailHint"));else if(de==="applied-direct")L=e("savedOk")+" \xB7 "+e("savedDirect");else{let le=Array.isArray(ee.pending)&&ee.pending.length?" \xB7 "+e("savePending"):ee.note?" \xB7 "+e("restartHint"):"";L=(ee.retried?"\u267B ":"")+e("savedOk")+le}c.current={...c.current,...U},V?K(L):O(L),te(L,V),await _e()}else{let de=oe.status===409?e("conflictRefresh"):ee?.error||e("saveFail");O(de),te(de,!1)}}catch{O(e("saveFail")),te(e("saveFail"),!1)}finally{_("")}},Kn=()=>{c.current={},h({...o?.config??{}}),K("")},Sn={env:"vaultSrcEnv",profile:"vaultSrcProfile",workspace:"vaultSrcWorkspace",vaultDir:"vaultSrcVaultDir",default:"vaultSrcDefault"},ot=b=>Array.isArray(b?.vaultProfiles)?b.vaultProfiles:[],yt=(b,W,U)=>h(oe=>{let ze=ot(oe).map(de=>({...de||{}})),ee={...ze[b]||{}};return W==="match"?String(U).trim()?ee.match={...ee.match||{},workspace:U}:delete ee.match:ee[W]=U,ze[b]=ee,{...oe??{},vaultProfiles:ze}}),xe=()=>h(b=>({...b??{},vaultProfiles:[...ot(b),{name:"",path:""}]})),qt=b=>h(W=>({...W??{},vaultProfiles:ot(W).filter((U,oe)=>oe!==b)})),We={fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},S={padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:12,minWidth:0},x={A:{label:e("planA"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:2e3,recallMinScore:2,recallLimit:5,recallSummaryLen:130,recallIncludeBody:!1,captureCooldownMs:3e5},B:{label:e("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:e("planC"),autoWebMode:"interval",watchdogAutoSpawn:!0,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:1200,recallMinScore:1,recallLimit:8,recallSummaryLen:200,recallIncludeBody:!0,captureCooldownMs:12e4}},Q=async b=>{let W=x[b];W&&h(U=>({...U??{},...W}))},ge=async(b,W)=>{_(b+W);try{let oe=await(await fetch(`${J}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:b,action:W})})).json();oe&&oe.ok?te(Qe(W==="install"?"mcpInstalled":"mcpUninstalled",{agent:b})):te(Qe("mcpActionFail",{agent:b,error:oe?.error||""}),!1);try{let ze=await fetch(`${J}/setup-status`).then(ee=>ee.json());ze&&ze.ok&&j(ze)}catch{}}catch{te(e("mergeFail"),!1)}finally{_("")}},q=({k:b,label:W,type:U="text",step:oe,min:ze,max:ee})=>(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,i.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:W||b}),(0,i.jsx)("input",{type:U,step:oe,min:ze,max:ee,value:y?y[b]??"":"",onChange:de=>{let L=de.target.value;He(b,U==="number"?L===""?"":Number(L):L)},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}})]}),ke=new Set(["autoRestartOnDrift"]),p=({k:b,label:W})=>{let U=y?y[b]:void 0,oe=U===void 0?ke.has(b):!!U;return(0,i.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:12,minWidth:0,lineHeight:1.5},children:[(0,i.jsx)("input",{type:"checkbox",checked:oe,onChange:ze=>He(b,ze.target.checked),style:{marginTop:2,flex:"0 0 auto"}}),(0,i.jsx)("span",{style:{whiteSpace:"normal",overflowWrap:"anywhere"},children:W||b})]})};return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:r?"0 0 auto":1,minHeight:0,maxHeight:r?"52vh":void 0},children:[(0,i.jsx)("style",{children:sn}),z&&(0,i.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 "+(z.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,i.jsx)("span",{style:{color:z.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:z.ok?"\u2713":"\u2715"}),(0,i.jsx)("span",{style:{wordBreak:"break-all"},children:z.msg})]}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[D&&(0,i.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",D]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:_e,children:["\u21BB ",e("retry")]})]}),M&&(0,i.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 ",e("pendingSyncNote")]}),m&&(0,i.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 ",e("configNeedsDsh")," \u2014\u2014 ",e("editInSetting")]}),T&&(0,i.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 ",T]}),o&&(o.version||o.dsh?.vaultDir)&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F4E6} ",e("pluginInfo")]}),(0,i.jsx)("span",{style:{fontSize:12,opacity:.7},children:e("dshHostLabel")}),o.version&&(0,i.jsxs)("code",{style:We,children:[e("vcLoaded")," v",o.version]}),A&&A.resident&&A.resident.served&&A.resident.served!==o.version&&(0,i.jsxs)("code",{style:We,children:[e("vcResident")," v",A.resident.served]}),Ko&&(0,i.jsxs)("code",{style:We,children:[e("vcPage")," v",Ko]}),A&&A.onDisk&&(0,i.jsxs)("code",{style:We,children:[e("vcOnDisk")," v",A.onDisk]}),A&&A.latest&&(0,i.jsxs)("code",{style:We,children:[e("vcLatest")," v",A.latest]}),o.dsh?.vaultDir&&(0,i.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",o.dsh.vaultDir]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:Y==="version",onClick:()=>Z(!0),children:Y==="version"?e("checking"):"\u{1F504} "+e("vcCheck")})]}),A&&A.stale&&(0,i.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,i.jsxs)("div",{children:["\u26A0\uFE0F ",Qe("vcStale",{disk:A.onDisk,loaded:A.loaded})]}),ht?(0,i.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",marginTop:6,flexWrap:"wrap"},children:[(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!Y,onClick:pe,children:Y==="restart"?"\u23F3 "+e("vcRestarting"):"\u{1F504} "+e("vcRestart")}),A.restartCommand&&(0,i.jsx)("code",{style:{fontSize:11,opacity:.75},children:A.restartCommand})]}):(0,i.jsxs)("div",{style:{marginTop:6,lineHeight:1.7},children:["\u2139\uFE0F ",e("vcHostStale"),A.restartCommand&&(0,i.jsxs)(i.Fragment,{children:[" ",(0,i.jsx)("code",{style:{fontSize:11,opacity:.75},children:A.restartCommand})]})]})]}),Ko&&A&&A.onDisk&&Ko!==A.onDisk&&(0,i.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:e("vcPageStale",{page:Ko,disk:A.onDisk})}),A&&A.updateAvailable&&(0,i.jsxs)("div",{style:{marginTop:8,fontSize:11.5,opacity:.88},children:["\u2B06 ",e("vcOutdated")," \u2192 ",(0,i.jsx)("code",{children:A.updateCommand})]}),A&&A.checkError&&(0,i.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b91c1c"},children:[e("vcCheckFail"),"\uFF1A",A.checkError]})]}),P&&P.agents&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F50C} ",e("mcpSetupStatus")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("mcpManageHint")})]}),(0,i.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:P.agents.map(b=>(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[(0,i.jsxs)("span",{style:{flex:1},children:[(0,i.jsx)("b",{children:b.isDsh?e("dshHostLabel"):b.name}),b.isDsh&&b.version&&(0,i.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",b.version]}),!b.installed&&(0,i.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",e("notInstalled"),")"]}),b.installed&&b.mcpConfigured===!1&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",e("noMcpEntry"),")"]}),b.mcpConfigured===!0&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",e("healthy")]}),b.mcpConfigured===!0&&b.mcpMatchesCurrentNode===!1&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",e("nodePathNote"),")"]}),b.isDsh&&(0,i.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",e("recallTool"),": ",b.recallTool?e("enabled"):e("disabled"),")"]})]}),b.hook&&(0,i.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",b.hook]}),!b.isDsh&&b.installed&&b.mcpConfigured===!1&&(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!Y,onClick:()=>ge(b.name,"install"),children:e("installMcp")}),!b.isDsh&&b.installed&&b.mcpConfigured===!0&&(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!Y,onClick:()=>{window.confirm(e("uninstallConfirm"))&&ge(b.name,"uninstall")},children:e("uninstallMcp")})]},b.name))}),(0,i.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:e("mcpSetupHint")}),re&&(0,i.jsx)("div",{style:{fontSize:11,marginTop:6},children:(0,i.jsx)("code",{style:{padding:"2px 6px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:4},children:re})})]}),y?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #3b82f6"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8,flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F3AF} ",e("presetConfig")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("presetHint")})]}),(0,i.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["A","B","C"].map(b=>(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>Q(b),disabled:!!Y,children:[b==="A"?"\u{1F7E2} ":b==="B"?"\u{1F4B0} ":"\u2B50 ",x[b].label]},b))})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F9E0} ",e("dshMemoryConfig")]})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"autoCapture",label:e("autoCapture")}),(0,i.jsx)(p,{k:"autoRecall",label:e("autoRecall")}),(0,i.jsx)(q,{k:"captureMinChars",label:e("captureMinChars"),type:"number"}),(0,i.jsx)(q,{k:"maxCardsPerDay",label:e("maxCardsPerDay"),type:"number"}),(0,i.jsx)(q,{k:"dedupThreshold",label:e("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,i.jsx)(q,{k:"recallLimit",label:e("recallLimit"),type:"number"}),(0,i.jsx)(q,{k:"recallSummaryLen",label:e("recallSummaryLen"),type:"number"}),(0,i.jsx)(p,{k:"recallIncludeBody",label:e("recallBody")}),(0,i.jsx)(q,{k:"secretHint",label:e("secretHint")}),(0,i.jsx)(q,{k:"recallEmbedding",label:e("recallEmbedding")})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #06b6d4"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:6},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F5C2}\uFE0F ",e("vaultMulti")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("vaultMultiHint")})]}),(0,i.jsxs)("div",{style:{fontSize:11.5,opacity:.85,marginBottom:8,lineHeight:1.7},children:[e("vaultNow"),"\uFF1A",(0,i.jsx)("code",{children:g?.vaultDir||"\u2014"}),g?.vaultName?`\uFF08${g.vaultName}\uFF09`:""," \xB7 ",e("vaultSource"),"\uFF1A",e(Sn[g?.vaultSource]||"vaultSrcDefault"),g?.workspace?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("br",{}),e("vaultWorkspace"),"\uFF1A",(0,i.jsx)("code",{children:g.workspace})]}):null]}),ot(y).map((b,W)=>(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.6fr 1.5fr auto",gap:6,marginBottom:6},children:[(0,i.jsx)("input",{value:b.name||"",placeholder:e("vaultNamePh"),onChange:U=>yt(W,"name",U.target.value),style:S,disabled:m}),(0,i.jsx)("input",{value:b.path||"",placeholder:e("vaultPathPh"),onChange:U=>yt(W,"path",U.target.value),style:S,disabled:m}),(0,i.jsx)("input",{value:b.match&&b.match.workspace||"",placeholder:e("vaultMatchPh"),onChange:U=>yt(W,"match",U.target.value),style:S,disabled:m}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>qt(W),disabled:m,title:e("delete"),children:"\u2715"})]},W)),(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginTop:4},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:xe,disabled:m,children:["\uFF0B ",e("vaultAdd")]}),(0,i.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12},children:[(0,i.jsx)("span",{style:{opacity:.6},children:e("vaultActive")}),(0,i.jsxs)("select",{value:y.activeVault||"",onChange:b=>He("activeVault",b.target.value),disabled:m,style:S,children:[(0,i.jsx)("option",{value:"",children:e("vaultActiveNone")}),ot(y).filter(b=>b&&b.name).map(b=>(0,i.jsx)("option",{value:b.name,children:b.name},b.name))]})]})]})]}),(0,i.jsx)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"enabled",label:e("enabledLabel")}),(0,i.jsx)(q,{k:"vaultDir",label:e("vaultDirLabel")})]})}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #f59e0b"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F4B0} ",e("costControl")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("costHint")})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8,marginTop:6},children:[(0,i.jsx)(p,{k:"distillEnabled",label:e("distillEnabled")}),(0,i.jsx)(p,{k:"dedupByLLM",label:e("dedupByLLM")}),(0,i.jsx)(q,{k:"captureMaxTokens",label:e("captureMaxTokens"),type:"number"}),(0,i.jsx)(q,{k:"recallMinScore",label:e("recallMinScore"),type:"number"}),(0,i.jsx)(q,{k:"captureCooldownMs",label:e("captureCooldownMs"),type:"number"}),(0,i.jsx)(q,{k:"captureProvider",label:e("captureProvider")}),(0,i.jsx)(q,{k:"captureModel",label:e("captureModel")}),(0,i.jsx)(q,{k:"sessionBudgetChars",label:e("sessionBudgetChars"),type:"number"})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #8b5cf6"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",e("auditConfig")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("auditHint")})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,i.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:e("auditMode")}),(0,i.jsxs)("select",{value:y.auditMode??"all",onChange:b=>He("auditMode",b.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,i.jsx)("option",{value:"all",children:e("auditAll")}),(0,i.jsx)("option",{value:"none",children:e("auditNone")})]})]}),(0,i.jsx)(Gp,{label:e("auditExemptAgents"),value:y.auditExemptAgents||[],options:[{value:"__all__",label:e("allExempt")},...(P?.agents||[]).filter(b=>!b.isDsh).map(b=>({value:b.name,label:b.name}))],onChange:b=>He("auditExemptAgents",b)}),(0,i.jsx)(Gp,{label:e("auditExemptKinds"),value:y.auditExemptKinds||[],options:[{value:"__all__",label:e("allExempt")},...Gs.filter(b=>b!=="all").map(b=>({value:b,label:e(Ft[b])}))],onChange:b=>He("auditExemptKinds",b)}),(0,i.jsx)(q,{k:"recycleRetentionDays",label:e("recycleDays"),type:"number"})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E0} ",e("serviceConfig")]})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"autoWeb",label:e("autoWeb")}),(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,i.jsx)("span",{style:{opacity:.6},children:e("autoWebMode")}),(0,i.jsxs)("select",{value:y.autoWebMode??"init",onChange:b=>He("autoWebMode",b.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,i.jsx)("option",{value:"init",children:e("modeInit")}),(0,i.jsx)("option",{value:"interval",children:e("modeInterval")}),(0,i.jsx)("option",{value:"manual",children:e("modeManual")})]})]}),(0,i.jsx)(q,{k:"webPort",label:e("webPort"),type:"number"}),(0,i.jsx)(q,{k:"webCheckIntervalMs",label:e("webCheckIntervalMs"),type:"number"}),(0,i.jsx)(q,{k:"webMaxRestart",label:e("webMaxRestart"),type:"number"}),(0,i.jsx)(p,{k:"watchdogAutoSpawn",label:e("watchdogAutoSpawn")}),(0,i.jsx)(p,{k:"autoRestartOnDrift",label:e("autoRestartOnDrift")}),(0,i.jsx)(p,{k:"autoMcpSetup",label:e("autoMcpSetup")})]})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",alignItems:"center",marginBottom:10,flexWrap:"wrap"},children:[Y==="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,opacity:.75},children:["\u23F3 ",e("saving")]}),T&&Y!=="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,color:"#10b981"},children:["\u2705 ",T]}),D&&Y!=="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,color:"#b91c1c"},children:["\u26A0 ",D]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:Kn,disabled:!!Y,children:e("reset")}),(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:m?()=>te(e("readonlyTitle")+"\uFF1A"+e("readonlyBody"),!1):Gt,disabled:Y==="save",title:e(m?"readonlyBody":"saveConfig"),children:Y==="save"?"\u23F3 "+e("saving"):m?"\u{1F512} "+e("readonlyBtn"):"\u{1F4BE} "+e("saveConfig")})]})]}):(0,i.jsx)("div",{style:{fontSize:12,opacity:.6},children:e("loading")})]})]})}function Qg({t:e,onReload:t,version:n}){let[r,o]=(0,v.useState)([]),[l,a]=(0,v.useState)([]),[s,u]=(0,v.useState)("all"),[f,y]=(0,v.useState)("all"),[h,m]=(0,v.useState)(""),[k,M]=(0,v.useState)(new Set),[w,I]=(0,v.useState)(""),[d,c]=(0,v.useState)(null),[g,N]=(0,v.useState)("pending"),P=(z,G=!0)=>{c({msg:z,ok:G}),setTimeout(()=>c(null),3e3)},j=[...new Set([...r,...l].map(z=>z.submittedBy).filter(Boolean))],D=(0,v.useCallback)(async()=>{try{let z=await fetch(`${J}/audit/list`).then(G=>G.json());z.ok&&(o(z.pending||[]),a(z.rejected||[]),M(new Set),K(new Set),ce({}))}catch{}},[]);(0,v.useEffect)(()=>{D()},[n,D]);let O=(g==="pending"?r:l).filter(z=>{if(s!=="all"&&z.kind!==s||f!=="all"&&Kr(z.submittedBy)!==f)return!1;if(h){let G=(z.created||"").slice(0,10);if(G&&G!==h)return!1}return!0}),Y=z=>M(G=>{let he=new Set(G);return he.has(z)?he.delete(z):he.add(z),he}),_=async(z,G)=>{let he=G||[...k];if(!he.length){P(e("noSelection"),!1);return}I("apply");let te=e(z==="approved"?"toastApproved":z==="rejected"?"toastRejected":"toastCardDeleted");try{let pe=0;for(let Fe of he){let ht=z==="approved"?"audit/approve":z==="rejected"?"audit/reject":"delete";try{(await fetch(J+"/"+ht+"?path="+encodeURIComponent(Fe)+(z==="delete"?"&permanent=0":""))).ok||pe++}catch{pe++}}await D(),t&&t(),pe?P(e("toastFailed")+"\uFF08"+pe+"/"+he.length+"\uFF09",!1):P(te+" "+he.length+" \u5F20")}catch(pe){P(e("toastFailed")+": "+String(pe&&pe.message||pe),!1)}finally{I("")}},[T,K]=(0,v.useState)(new Set),[A,ce]=(0,v.useState)({}),Z=z=>A[z]||{},re=async z=>{let G=z.path,he=!T.has(G);if(K(te=>{let pe=new Set(te);return he?pe.add(G):pe.delete(G),pe}),!(!he||A[G])){ce(te=>({...te,[G]:{loading:!0}}));try{let te=z.status||(g==="pending"?"pending":"rejected"),pe=await fetch(`${J}/card?path=${encodeURIComponent(G)}&status=${te}`).then(Fe=>Fe.json());pe&&pe.ok?ce(Fe=>({...Fe,[G]:{text:pe.text||""}})):ce(Fe=>({...Fe,[G]:{error:pe&&pe.error||"HTTP"}}))}catch(te){ce(pe=>({...pe,[G]:{error:String(te&&te.message||te)}}))}}},me=[...k];return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,i.jsx)(tf,{toast:d}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",e("tabAudit")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("select",{value:s,onChange:z=>u(z.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,i.jsx)("option",{value:"all",children:e("all")}),Gs.filter(z=>z!=="all").map(z=>(0,i.jsx)("option",{value:z,children:e(Ft[z])},z))]}),(0,i.jsxs)("select",{value:f,onChange:z=>y(z.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,i.jsx)("option",{value:"all",children:e("allAgents")}),Jp(j).map(z=>(0,i.jsx)("option",{value:z,children:z},z))]}),(0,i.jsx)("input",{type:"date",value:h,onChange:z=>m(z.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,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("button",{type:"button",className:`mc-btn${g==="pending"?" me-on":""}`,onClick:()=>N("pending"),children:[e("pending"),"\uFF08",r.length,"\uFF09"]}),(0,i.jsxs)("button",{type:"button",className:`mc-btn${g==="rejected"?" me-on":""}`,onClick:()=>N("rejected"),children:[e("rejected"),"\uFF08",l.length,"\uFF09"]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("label",{style:{fontSize:12},children:[(0,i.jsx)("input",{type:"checkbox",checked:O.length>0&&me.length===O.length,onChange:z=>{z.target.checked?M(new Set(O.map(G=>G.path))):M(new Set)}})," ",e("selectAll")]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!me.length||!!w,onClick:()=>_("approved"),children:["\u2713 ",e(g==="rejected"?"restore":"approve")]}),g==="pending"?(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!me.length||!!w,onClick:()=>_("rejected"),children:["\u2715 ",e("reject")]}):(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!me.length||!!w,onClick:()=>{window.confirm(e("recycleDeleteConfirm"))&&_("delete")},children:["\u{1F5D1} ",e("restoreDelete")]})]}),O.length?(0,i.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:O.map(z=>{let G=Z(z.path),he=T.has(z.path);return(0,i.jsxs)("div",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",fontSize:12},children:[(0,i.jsx)("input",{type:"checkbox",checked:k.has(z.path),onChange:()=>Y(z.path)}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"0 6px"},title:e(he?"collapse":"expand"),"aria-expanded":he,onClick:()=>re(z),children:he?"\u25BE":"\u25B8"}),(0,i.jsx)("span",{className:"mc-kind",style:{background:At[z.kind]||"#999"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},title:e(he?"collapse":"expand"),onClick:()=>re(z),children:z.title}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:Kr(z.submittedBy)}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:z.created?z.created.slice(0,16).replace("T"," "):"-"}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:z.kind}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6,color:z.severity==="high"?"#f87171":"#9ca3af"},children:z.severity}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.reason||"-"}),g==="pending"?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>_("approved",[z.path]),children:"\u2713"}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>_("rejected",[z.path]),children:"\u2715"})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},title:e("restore"),onClick:()=>_("approved",[z.path]),children:"\u2713"}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},title:e("restoreDelete"),onClick:()=>{window.confirm(e("recycleDeleteConfirm"))&&_("delete",[z.path])},children:"\u{1F5D1}"})]})]}),he&&(0,i.jsxs)("div",{style:{padding:"2px 10px 12px 34px"},children:[G.loading&&(0,i.jsxs)("div",{style:{fontSize:12,opacity:.6},children:["\u23F3 ",e("loading")]}),G.error&&(0,i.jsxs)("div",{style:{fontSize:12,color:"#f87171"},children:["\u26A0 ",e("auditBodyFail"),"\uFF1A",G.error]}),G.text!=null&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"md-meta",style:{marginBottom:6},children:[(0,i.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:At[z.kind]||"#6B7280",borderColor:(At[z.kind]||"#6B7280")+"59",background:(At[z.kind]||"#6B7280")+"1a"},children:[Yo[z.kind]||"\u{1F4CE}"," ",e(Ft[z.kind]||"kindKnowledge")]}),(Array.isArray(z.tags)?z.tags:[]).slice(0,8).map(te=>(0,i.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",te]},te)),!!z.reason&&(0,i.jsxs)("span",{className:"md-chip md-chip-st-warn",children:["\u2691 ",z.reason]})]}),(0,i.jsx)("div",{className:"md-doc",style:{maxHeight:340,overflow:"auto"},dangerouslySetInnerHTML:{__html:Ks(ki(G.text).body)}}),g==="pending"&&(0,i.jsxs)("div",{style:{display:"flex",gap:8,marginTop:8},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!!w,onClick:()=>_("approved",[z.path]),children:["\u2713 ",e("approve")]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!w,onClick:()=>_("rejected",[z.path]),children:["\u2715 ",e("reject")]})]})]})]})]},z.path)})}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:e("noAuditItems")})]})]})}function Yg({t:e,onReload:t,version:n}){let[r,o]=(0,v.useState)([]),[l,a]=(0,v.useState)(""),[s,u]=(0,v.useState)(null),f=(m,k=!0)=>{u({msg:m,ok:k}),setTimeout(()=>u(null),3200)},y=(0,v.useCallback)(async()=>{try{let m=await fetch(`${J}/recycle/list`).then(k=>k.json());m.ok&&o(m.items||[])}catch{}},[]);(0,v.useEffect)(()=>{y()},[n,y]);let h=async(m,k)=>{let M=(r.find(w=>w.path===k)||{}).title||k;a(m+k);try{let I=await fetch(J+(m==="restore"?"/recycle/restore":"/recycle/purge")+"?path="+encodeURIComponent(k)),d=await I.json().catch(()=>null);await y(),t&&t(),I.ok&&(!d||d.ok!==!1)?f(e(m==="restore"?"toastRestored":"toastPurged")+"\uFF1A"+M):f(e("toastFailed")+"\uFF1A"+(d&&d.error||"HTTP "+I.status),!1)}catch(w){f(e("toastFailed")+"\uFF1A"+String(w&&w.message||w),!1)}finally{a("")}};return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,i.jsx)(tf,{toast:s}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F5D1}\uFE0F ",e("tabRecycle")]}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("recycleHint")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:!!l||r.length===0,title:r.length?"":e("emptyRecycle"),onClick:async()=>{a("purgeAll");try{let m=await fetch(J+"/recycle/purge-expired?days=0"),k=await m.json().catch(()=>null);await y(),f(m.ok?e("toastPurgedExpired")+(k&&k.purged!=null?"\uFF08"+k.purged+"\uFF09":""):e("toastFailed"),m.ok)}catch(m){f(e("toastFailed")+"\uFF1A"+String(m&&m.message||m),!1)}finally{a("")}},children:e("emptyRecycle")})]}),r.length?(0,i.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:r.map(m=>(0,i.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,i.jsx)("span",{className:"mc-kind",style:{background:At[m.kind]||"#999"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.title}),(0,i.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[e("deletedAt")," ",(m.deletedAt||"").slice(0,10)]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!l,onClick:()=>h("restore",m.path),children:e("restore")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!l,onClick:()=>{window.confirm(e("purgeConfirm"))&&h("purge",m.path)},children:e("purge")})]},m.path))}):(0,i.jsxs)("div",{className:"mc-card",style:{padding:18,fontSize:12.5,opacity:.78,textAlign:"center",lineHeight:1.9},children:["\u{1F5D1}\uFE0F ",e("emptyRecycle"),(0,i.jsx)("br",{}),(0,i.jsx)("span",{style:{fontSize:11.5},children:e("recycleEmptyHint").split("{days}").join("30")})]})]})]})}var Xg=({card:e,t,onOpen:n,query:r,onDelete:o})=>(0,i.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>n(e),children:[(0,i.jsxs)("h4",{children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:At[e.kind]||At.other}}),(0,i.jsx)("span",{style:{marginRight:4},children:Yo[e.kind]||"\u{1F4CE}"}),r?qp(e.title,r):e.title,oh(e.updated)&&(0,i.jsx)("span",{className:"mc-new",children:t("newBadge")}),e.status==="pending"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",t("statusPending")]}),e.status==="rejected"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#ef4444"},children:["\u274C ",t("statusRejected")]}),(!e.status||e.status==="approved")&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#10b981"},children:["\u2705 ",t("statusApproved")]})]}),(0,i.jsx)("p",{children:r?qp(e.summary||"",r):e.summary||""}),e.tags.length>0&&(0,i.jsx)("div",{className:"mc-tags",children:e.tags.slice(0,4).map(l=>(0,i.jsxs)("span",{className:"mc-tag",children:["\u{1F3F7} ",l]},l))}),(0,i.jsxs)("footer",{children:[(0,i.jsxs)("span",{children:[Yo[e.kind]||"\u{1F4CE}"," ",t(Ft[e.kind])]}),(0,i.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",Kr(e.submittedBy)]}),(0,i.jsxs)("span",{children:["\u{1F4C5} ",Vr(e.updated)]}),(0,i.jsx)("span",{className:"spacer",style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-card-del",title:t("delete"),onClick:l=>{l.stopPropagation(),window.confirm(t("deleteConfirm"))&&o&&o(e.path)},children:"\u{1F5D1}"})]})]});function Gg({t:e,tab:t,onReload:n,version:r}){let[o,l]=(0,v.useState)(null),[a,s]=(0,v.useState)(""),[u,f]=(0,v.useState)(null),[y,h]=(0,v.useState)(null),[m,k]=(0,v.useState)(null),[M,w]=(0,v.useState)([]),[I,d]=(0,v.useState)(""),[c,g]=(0,v.useState)(!1),N=(0,v.useCallback)(async()=>{if(!(!u||!u.merge||!u.merge.length)&&window.confirm(e("mergeAllConfirm"))){d("merge");try{let T={},K=me=>T[me]===void 0?me:T[me]=K(T[me]),A=(me,z)=>{T[K(me)]=K(z)},ce=new Set;for(let me of u.merge)ce.add(me.a.path),ce.add(me.b.path),A(me.a.path,me.b.path);let Z={};for(let me of ce){let z=K(me);(Z[z]=Z[z]||[]).push(me)}let re=0;for(let me of Object.values(Z)){if(me.length<2)continue;(await fetch(`${J}/merge?paths=${encodeURIComponent(me.join(","))}`).then(G=>G.json())).ok&&re++}await P(),n&&n()}catch{}d("")}},[u,P,n,e]);async function P(){try{let T=await Promise.all([fetch(`${J}/stats`),fetch(`${J}/budget`),fetch(`${J}/capture-log`),fetch(`${J}/cards?status=all&limit=30&agent=${Qo}`)]),[K,A,ce,Z]=await Promise.all(T.map(re=>re.json()));K&&K.ok&&l(K),A&&A.ok&&h(A),ce&&ce.ok&&k(ce),Z&&Z.ok&&w(Z.cards||[]),s(!K||!K.ok?e("adminLoadFail"):"")}catch{s(e("adminLoadFail"))}}let j=(0,v.useCallback)(async()=>{d("scan");try{let T=await fetch(`${J}/optimize`).then(K=>K.json());T.ok&&f(T)}catch{s(e("adminLoadFail"))}finally{d("")}},[e]);(0,v.useEffect)(()=>{P()},[r]);let D=async(T,K)=>{if(window.confirm(e("mergeConfirm")))try{(await fetch(`${J}/merge?paths=${encodeURIComponent(T+","+K)}`).then(ce=>ce.json())).ok&&(await P(),n&&n())}catch{}},O=async T=>{if(window.confirm(e("deleteConfirm")))try{(await fetch(`${J}/delete?path=${encodeURIComponent(T)}`).then(A=>A.json())).ok&&(await P(),n&&n())}catch{}},Y=["project","knowledge","content","prompt","business","tool","mistake"],_=({title:T,kind:K,updated:A,path:ce})=>(0,i.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:Ur.colors[K]||"#666"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T}),(0,i.jsx)("span",{style:{opacity:.55,fontSize:11},children:Vr(A)}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>O(ce),children:[e("delete")," \u2715"]})]});return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto"},children:[a&&(0,i.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",a]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:P,children:["\u21BB ",e("retry")]})]}),t==="stats"&&(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1FAB5} ",e("captureLog")]}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("captureLogHint")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>P(),children:["\u21BB ",e("refresh")]})]}),m?m.available===!1?(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("captureLogUnavailable")}):(m.entries||[]).length===0?(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("captureLogEmpty")}):(0,i.jsx)("div",{style:{maxHeight:260,overflow:"auto",marginTop:8},children:(0,i.jsx)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:(0,i.jsx)("tbody",{children:(m.entries||[]).map((T,K)=>{let A=Ug[T.action]||["\u2022","inherit"];return(0,i.jsxs)("tr",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsx)("td",{style:{padding:"4px 6px",opacity:.55,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:Vr(T.time?new Date(T.time).toISOString():"")}),(0,i.jsxs)("td",{style:{padding:"4px 6px",whiteSpace:"nowrap",color:A[1],fontWeight:600},children:[A[0]," ",T.action]}),(0,i.jsx)("td",{style:{padding:"4px 6px"},children:T.reason||""}),(0,i.jsx)("td",{style:{padding:"4px 6px",opacity:.55,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:T.preview||"",children:T.preview||""})]},K)})})})}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("loading")})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:["\u{1F916} ",e("captureAgentCards"),"\uFF08",M.length,"\uFF09"]}),M.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:M.map(T=>(0,i.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,i.jsx)("span",{className:"mc-kind",style:{background:At[T.kind]||At.other}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.title}),T.status==="pending"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",e("statusPending")]}),(0,i.jsx)("span",{style:{opacity:.55,fontSize:11},children:Vr(T.updated)})]},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noCards")})]}),o&&(0,i.jsxs)(i.Fragment,{children:[o.trend&&o.trend.length>0&&(()=>{let T=o.trend,K=Math.max(...T.map(re=>re.count),1),A=260,ce=50,Z=A/T.length;return(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,i.jsxs)("div",{style:{fontSize:11,opacity:.6,marginBottom:4},children:["\u{1F4C8} ",e("trendLabel")]}),(0,i.jsx)("svg",{width:A,height:ce,style:{display:"block",width:"100%",height:50},children:T.map((re,me)=>{let z=Math.round(re.count/K*(ce-4));return(0,i.jsx)("rect",{x:me*Z+1,y:ce-z,width:Math.max(Z-2,2),height:z,rx:1.5,fill:re.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:re.count>0?.85:.35},re.date)})})]})})(),(0,i.jsxs)("div",{className:"mc-stats",children:[(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.total}),(0,i.jsx)("span",{children:e("total")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.today}),(0,i.jsx)("span",{children:e("todayAdd")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.week}),(0,i.jsx)("span",{children:e("weekAdd")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.tags}),(0,i.jsx)("span",{children:e("tags")})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:e("byKind")}),(0,i.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:Y.map(T=>(0,i.jsxs)("span",{style:{fontSize:12},children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:Ur.colors[T]||"#666"}}),e(Ft[T]),": ",o.byKind?.[T]||0]},T))})]}),y&&(y.budgetChars||y.recallLimit||y.embedding)&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,i.jsx)("b",{children:e("budgetLabel")}),"\uFF1A",e("budgetChars")," ",(0,i.jsx)("b",{children:y.budgetChars||8e4})," \xB7 ",e("recallLimitLabel")," ",(0,i.jsx)("b",{children:y.recallLimit||5})," \xB7 ",e("embeddingLabel")," ",y.embedding?"ON":"OFF"]}),(0,i.jsxs)("div",{className:"mc-card",children:[(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[e("todayList"),"\uFF08",o.todayCards?.length||0,"\uFF09"]}),o.todayCards?.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:o.todayCards.map(T=>(0,i.jsx)(_,{title:T.title,kind:T.kind,updated:T.updated,path:T.path},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noOptimize")})]})]})]}),t==="optimize"&&(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsx)("b",{style:{fontSize:12},children:e("organizeTitle")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:!!I,onClick:j,children:I==="scan"?e("exporting"):"\u{1F50D} "+e("scanAndOrganize")}),u&&u.merge?.length>0&&(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!I,onClick:async()=>{if(window.confirm(e("oneClickOptimizeConfirm"))){d("oneclick");try{let T=JSON.stringify({cleanupStale:c}),A=await(await fetch(`${J}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:T})).json();A&&A.ok?(notify(`${e("oneClickOptimizeDone")}\uFF1A${A.plan.merged} ${e("optimizedMerged")}${c?` \xB7 ${A.plan.staleDeleted} ${e("optimizedStaleDeleted")}`:""}`),await P(),n&&n(),f(null)):notify(e("mergeFail"),!1)}catch{notify(e("mergeFail"),!1)}finally{d("")}}},children:I==="oneclick"?e("exporting"):"\u26A1 "+e("oneClickOptimize")}),u&&u.merge?.length>0&&(0,i.jsxs)("label",{style:{fontSize:11,opacity:.7,display:"flex",alignItems:"center",gap:4},children:[(0,i.jsx)("input",{type:"checkbox",checked:c,onChange:T=>g(T.target.checked)}),e("oneClickAlsoStale")]})]}),!u&&(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:e("scanHint")}),u&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",flexDirection:"column",gap:8},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[(0,i.jsx)("b",{style:{fontSize:12},children:e("mergePairs")}),(0,i.jsx)("div",{className:"spacer",style:{flex:1}}),u.merge?.length>0&&(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!I,onClick:N,children:e(I==="merge"?"exporting":"batchMerge")})]}),(0,i.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:e("mergePairs")}),u.merge?.length?(0,i.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:u.merge.map((T,K)=>(0,i.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,i.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[T.a.title," \u21C4 ",T.b.title]}),(0,i.jsxs)("span",{style:{opacity:.6},children:[Math.round(T.sim*100),"%"]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>D(T.a.path,T.b.path),children:e("mergeNow")})]},K))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:e("noOptimize")}),(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[e("staleCards"),"\uFF08",u.stale?.length||0,"\uFF09"]}),u.stale?.length>0&&(0,i.jsx)("div",{style:{marginBottom:6},children:(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!I,onClick:async()=>{if(!window.confirm(e("deleteConfirm")))return;d("clean");let T=0;for(let K of u.stale)try{await fetch(`${J}/delete?path=${encodeURIComponent(K.path)}`),T++}catch{}d(""),notify(`${T} ${e("deletedStale")}`),await P(),n&&n()},children:e("cleanStale")})}),u.stale?.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:u.stale.map(T=>(0,i.jsx)(_,{title:T.title,kind:"other",updated:T.updated,path:T.path},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noOptimize")})]})})]})]})]})}var Ys=[{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 qg({t:e,newCard:t,setNewCard:n,onCreated:r}){if(!t)return null;let o=Ys.find(h=>h.key===t.template),l=t.body||(o?e(o.bodyKey):""),a=t.kind||(o?o.kind:"knowledge"),s=t.tags||(o?e(o.tagKey):""),u=t._creating,f=h=>{let m=Ys.find(k=>k.key===h);n(k=>({...k,template:h,kind:m?m.kind:k.kind,body:m?e(m.bodyKey):k.body,tags:m?e(m.tagKey):k.tags}))},y=async()=>{if(!(!t.title&&!l)){n(h=>({...h,_creating:!0}));try{(await fetch(`${J}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:t.title||e("untitled"),kind:a,tags:s.split(",").map(m=>m.trim()).filter(Boolean),body:l,source:"manual"})}).then(m=>m.json())).ok?(n(null),r&&r()):n(m=>({...m,_creating:!1}))}catch{n(m=>({...m,_creating:!1}))}}};return(0,i.jsxs)("div",{className:"me-overlay",onClick:()=>n(null),children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:h=>h.stopPropagation(),children:[(0,i.jsxs)("div",{className:"me-dialog-head",children:[(0,i.jsx)("h3",{children:e("newCard")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>n(null),children:e("close")})]}),(0,i.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10,overflow:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[Ys.map(h=>(0,i.jsx)("button",{type:"button",className:`mc-btn${t.template===h.key?" me-on":""}`,onClick:()=>f(h.key),children:e(h.label)},h.key)),(0,i.jsx)("button",{type:"button",className:`mc-btn${t.template===""?" me-on":""}`,onClick:()=>n(h=>({...h,template:"",body:"",tags:"",kind:"knowledge"})),children:e("tplBlank")})]}),(0,i.jsx)("select",{className:"mc-btn",value:a,onChange:h=>n(m=>({...m,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,i.jsx)("option",{value:h,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:h},h))}),(0,i.jsx)("input",{type:"text",className:"mc-btn",placeholder:e("cardTitle"),value:t.title||"",onChange:h=>n(m=>({...m,title:h.target.value}))}),(0,i.jsx)("input",{type:"text",className:"mc-btn",placeholder:e("tagsHint"),value:s,onChange:h=>n(m=>({...m,tags:h.target.value}))}),(0,i.jsx)("textarea",{className:"mc-btn",placeholder:e("cardBody"),value:l,onChange:h=>n(m=>({...m,body:h.target.value})),style:{minHeight:180,resize:"vertical",fontFamily:"inherit"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:u,onClick:y,children:e(u?"exporting":"createCard")})})]})]})]})}async function Xp(e){let t=String(e||"");if(!t)return!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{let n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.style.position="fixed",n.style.left="-9999px",n.style.top="0",document.body.appendChild(n),n.focus(),n.select();let r=!!(document.execCommand&&document.execCommand("copy"));return document.body.removeChild(n),r}catch{return!1}}function Zg({t:e,onClose:t}){let[n,r]=(0,v.useState)(""),[o,l]=(0,v.useState)(""),[a,s]=(0,v.useState)(""),[u,f]=(0,v.useState)(!0),[y,h]=(0,v.useState)(!1),[m,k]=(0,v.useState)(""),[M,w]=(0,v.useState)(""),I=(0,v.useRef)(null),d=(0,v.useRef)(null),c=()=>{let _=I.current;if(_)try{_.focus(),_.select()}catch{}},g=_=>{k(_),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>k(""),2400)};(0,v.useEffect)(()=>{let _=!0;return fetch(J+"/diagnostics").then(T=>T.json()).then(T=>{_&&(T&&T.ok?(l(String(T.diagnostics||"")),s(String(T.version||""))):h(!0))}).catch(()=>{_&&h(!0)}).finally(()=>{_&&f(!1)}),()=>{_=!1}},[]),(0,v.useEffect)(()=>{let _=T=>{T.key==="Escape"&&t()};return window.addEventListener("keydown",_),()=>{window.removeEventListener("keydown",_),d.current&&clearTimeout(d.current)}},[t]);let N=(()=>{try{return String(navigator.language||"").toLowerCase().startsWith("en")?"en":"zh"}catch{return"zh"}})(),P=()=>{let _=n.trim().split(`
307
+ `);let lt=new Blob([ne],{type:Ze}),jt=await lh(lt,Le,!1);if(!jt.ok){Z({ok:!1,msg:e("exportFail")}),G(!1);return}Z({ok:!0,msg:e("exportedTo")+"\uFF1A"+e("defaultDownloads")+" \xB7 "+jt.name})}catch(le){Z({ok:!1,msg:e("exportFail")+" \xB7 "+(le.message||"")})}finally{G(!1)}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2600)},ze=async L=>{let V=L.target.files&&L.target.files[0];if(L.target.value="",!!V){try{let le=await V.text(),ne=await(await fetch(`${J}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:le})).json();if(ne.ok){await ke();let Le=ne.imported||0,Ze=e("importedVault")+"\uFF1A"+Le;ne.total&&(Ze+=e("importedTotal")+ne.total+e("importedTotalTail")),ne.quarantined&&(Ze+=e("importedQuarantine")+ne.quarantined+e("importedQuarantineTail")),ne.skipped&&(Ze+=e("importedSkipped")+ne.skipped+e("importedSkippedTail")),ne.warning&&(Ze+=" \xB7 "+ne.warning),Z({ok:Le>0||!ne.total,msg:Ze})}else Z({ok:!1,msg:ne.error||e("importFail")})}catch{Z({ok:!1,msg:e("importFail")})}re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2400)}},ee=(0,v.useMemo)(()=>{let L=s.slice();return g!=="all"&&(L=L.filter(V=>Kr(V.submittedBy)===g)),P!=="all"&&(L=L.filter(V=>(V.status||"approved")===P)),K==="title"?L.sort((V,le)=>String(V.title||"").localeCompare(String(le.title||""))):K==="hot"?L.sort((V,le)=>(le.weight||le.links||0)-(V.weight||V.links||0)):L.sort((V,le)=>new Date(le.updated||0).getTime()-new Date(V.updated||0).getTime()),L},[s,K,g,P]),de=(0,v.useMemo)(()=>[...new Set(s.map(L=>Kr(L.submittedBy)))],[s]);return(0,i.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,i.jsx)("style",{children:sn}),ce&&(0,i.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 "+(ce.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,i.jsx)("span",{style:{color:ce.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:ce.ok?"\u2713":"\u2715"}),(0,i.jsx)("span",{children:ce.msg})]}),t&&(0,i.jsxs)("div",{className:"me-modal-head",children:[(0,i.jsxs)("div",{className:"me-modal-title",children:[(0,i.jsx)("span",{className:"me-wicon",children:(0,i.jsx)(Vg,{})}),(0,i.jsx)("h2",{children:e("memoryTitle")}),(0,i.jsx)("span",{children:e("memoryHint")})]}),(0,i.jsx)("div",{className:"spacer"}),r&&(0,i.jsx)("button",{type:"button",className:"me-modal-close",onClick:r,"aria-label":e(o?"exitFull":"fullscreen"),children:o?"\u2750":"\u26F6"}),(0,i.jsx)("button",{type:"button",className:"me-modal-close",onClick:n,"aria-label":e("close"),children:"\u2715"})]}),h&&h.ok===!1&&(0,i.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,i.jsxs)("span",{style:{fontWeight:800},children:["\u26A0 ",e("captureAlert")]}),(0,i.jsxs)("span",{style:{flex:1},children:[h.reason,(0,i.jsx)("div",{style:{opacity:.68,fontSize:11.5,marginTop:2},children:e("captureAlertHint")})]}),(0,i.jsx)("span",{style:{opacity:.7},children:h.since?Vr(new Date(h.since).toISOString()):""})]}),(0,i.jsxs)("div",{className:"me-modal-body",children:[(0,i.jsxs)("div",{className:`mc-rail${_e?" open":""}`,children:[(0,i.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>He(L=>!L),"aria-label":e(_e?"collapse":"expand"),title:e(_e?"collapse":"expand"),children:_e?"\xAB":"\xBB"}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="cards"?" active":""}`,onClick:()=>T("cards"),title:e("cardsTab"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F9E0}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("cardsTab")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="graph"?" active":""}`,onClick:()=>T("graph"),title:e("graphTab"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F52E}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("graphTab")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="stats"?" active":""}`,onClick:()=>T("stats"),title:e("tabUsage"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C8}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabUsage")})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="audit"?" active":""}`,onClick:()=>T("audit"),title:e("tabAudit"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F50D}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabAudit")}),ot>0&&(0,i.jsx)("span",{className:"mc-dot",children:ot>99?"99+":ot})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="optimize"?" active":""}`,onClick:()=>T("optimize"),title:e("tabRecycle"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u267B\uFE0F"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabRecycle")}),yt>0&&(0,i.jsx)("span",{className:"mc-dot",style:{background:"#6b7280"},children:yt>99?"99+":yt})]}),(0,i.jsxs)("button",{type:"button",className:`mc-railbtn${D==="config"?" active":""}`,onClick:()=>T("config"),title:e("tabConfig"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("tabConfig")})]}),(0,i.jsxs)("button",{type:"button",className:"mc-railbtn",onClick:()=>Qe(!0),title:e("fbNav"),children:[(0,i.jsx)("span",{className:"mc-rail-ico",children:"\u{1F41E}"}),_e&&(0,i.jsx)("span",{className:"mc-rail-label",children:e("fbNav")})]})]}),(0,i.jsxs)("div",{className:"mc-main",ref:ge,children:[D==="cards"&&(0,i.jsxs)("div",{className:"mc-stats",children:[(0,i.jsx)($r,{label:e("total"),value:l?l.total:"\u2014"}),(0,i.jsx)($r,{label:e("recent"),value:l?l.recent:"\u2014"}),(0,i.jsx)($r,{label:e("tags"),value:l?l.tags:"\u2014"}),(0,i.jsx)($r,{label:e("pending"),value:l?.quarantine?.pending??l?.status?.pending??0}),(0,i.jsx)($r,{label:e("rejected"),value:l?.quarantine?.rejected??l?.status?.rejected??0}),(0,i.jsx)($r,{label:e("cardCount"),value:l?l.byKind?.knowledge??0:"\u2014"})]}),D==="cards"&&(0,i.jsxs)("div",{className:"mc-toolbar",children:[(0,i.jsx)("input",{type:"text",placeholder:e("searchPlaceholder"),value:d,onChange:L=>b(L.target.value)}),(0,i.jsx)("input",{ref:me,type:"file",accept:".json,application/json",style:{display:"none"},onChange:ze}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>me.current&&me.current.click(),children:e("importVault")}),(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",onClick:()=>un({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",e("newCard")]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:z,onClick:()=>oe("md"),children:e(z?"exporting":"exportVault")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:z,onClick:()=>oe("json"),children:e(z?"exporting":"exportJson")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ke(),children:e("refresh")})]}),D==="cards"&&(0,i.jsxs)("div",{className:"mc-chips",children:[Gs.map(L=>(0,i.jsx)("button",{type:"button",className:`mc-chip${w===L?" active":""}`,onClick:()=>W(L),children:e(L==="all"?"all":Ft[L])},L)),(0,i.jsxs)("select",{value:g,onChange:L=>N(L.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,i.jsxs)("option",{value:"all",children:["\u{1F916} ",e("allAgents")]}),Jp(de).map(L=>(0,i.jsx)("option",{value:L,children:L},L))]}),(0,i.jsxs)("select",{value:P,onChange:L=>j(L.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,i.jsx)("option",{value:"all",children:e("allStatus")}),(0,i.jsx)("option",{value:"approved",children:e("statusApproved")}),(0,i.jsx)("option",{value:"pending",children:e("statusPending")}),(0,i.jsx)("option",{value:"rejected",children:e("statusRejected")})]}),(0,i.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:e("sortRecent")},{key:"title",label:e("sortTitle")},{key:"hot",label:e("sortHot")}].map(L=>(0,i.jsx)("button",{type:"button",className:`mc-chip${K===L.key?" active":""}`,onClick:()=>A(L.key),children:L.label},L.key))]}),k&&(0,i.jsxs)("div",{className:"mc-empty",children:[e("error"),"\uFF1A",k]}),(0,i.jsx)("div",{style:{display:D==="cards"?"contents":"none"},children:f?(0,i.jsx)("div",{className:"mc-empty",children:e("loading")}):k?(0,i.jsxs)("div",{className:"mc-empty",children:[e("error"),"\uFF1A",k," ",(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ke(),children:e("retry")})]}):s.length===0?(0,i.jsx)("div",{className:"mc-empty",children:e("empty")}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"mc-grid",children:ee.map(L=>(0,i.jsx)(Xg,{card:L,t:e,query:d.trim(),onOpen:U,onDelete:p},L.path))}),s.length<qt&&(0,i.jsx)("div",{ref:Q,style:{height:1}}),S&&(0,i.jsxs)("div",{className:"mc-empty",style:{padding:"10px 0"},children:[e("loading"),"\uFF08",s.length," / ",qt,"\uFF09"]})]})}),(0,i.jsx)("div",{style:{display:D==="graph"?"flex":"none",flex:1,minHeight:0},children:Y.has("graph")&&(0,i.jsx)(eh,{t:e,onOpen:U,all:pe,onAllChange:Fe,onMutate:Sn,active:D==="graph",visible:D==="graph"})}),(0,i.jsx)("div",{style:{display:D==="config"?"contents":"none"},children:Y.has("config")&&(0,i.jsx)(Kg,{t:e,onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="stats"?"contents":"none"},children:Y.has("stats")&&(0,i.jsx)(Gg,{t:e,tab:"stats",onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="audit"?"contents":"none"},children:Y.has("audit")&&(0,i.jsx)(Qg,{t:e,onReload:()=>ke(),version:Gt})}),(0,i.jsx)("div",{style:{display:D==="optimize"?"contents":"none"},children:Y.has("optimize")&&(0,i.jsx)(Yg,{t:e,onReload:()=>ke(),version:Gt})}),ht&&(0,i.jsx)(Zg,{t:e,onClose:()=>Qe(!1)}),he&&(0,i.jsx)(Jg,{t:e,card:he,query:d.trim(),onClose:()=>te(null),onDelete:L=>{te(null),p(L)},onFeedback:L=>{let V=he.path;fetch(`${J}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:d.trim(),path:V,useful:L})}).then(()=>Z({ok:!0,msg:e(L?"fbUseful":"fbIrr")})).catch(()=>{}),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)}}),(0,i.jsx)(qg,{t:e,newCard:bn,setNewCard:un,onCreated:()=>{ke(),Sn(),Z({ok:!0,msg:e("created")}),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>Z(null),2e3)}})]})]})]})}var tf=({toast:e})=>e?(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"8px 12px",fontSize:12,borderLeft:"4px solid "+(e.ok?"#10b981":"#ef4444"),background:e.ok?"rgba(16,185,129,0.08)":"rgba(239,68,68,0.08)"},children:[e.ok?"\u2705":"\u26A0"," ",e.msg]}):null,$r=({label:e,value:t})=>(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:t}),(0,i.jsx)("span",{children:e})]});function Kg({t:e,onReload:t,version:n,compact:r}){let[o,l]=(0,v.useState)(null),[a,s]=(0,v.useState)(0),[u,f]=(0,v.useState)(null),[y,h]=(0,v.useState)(null),[m,k]=(0,v.useState)(!1),[M,w]=(0,v.useState)(!1),I=(0,v.useRef)(!1),d=(0,v.useRef)(null),c=(0,v.useRef)({}),[g,N]=(0,v.useState)(null),[P,j]=(0,v.useState)(null),[D,O]=(0,v.useState)(""),[Y,_]=(0,v.useState)(""),[T,K]=(0,v.useState)(""),[A,ce]=(0,v.useState)(null),Z=(0,v.useCallback)(async b=>{_("version");try{let W=await fetch(J+"/version-check"+(b?"?force=1":"")).then(U=>U.json());W&&W.ok?(ce(W),b&&te(W.updateAvailable?e("vcLatest")+" v"+W.latest:e("vcUpToDate"))):b&&te(e("vcCheckFail"),!1)}catch{b&&te(e("vcCheckFail"),!1)}finally{_("")}},[e]);(0,v.useEffect)(()=>{Z(!1)},[n,Z]);let[re,me]=(0,v.useState)(""),[z,G]=(0,v.useState)(null),he=(0,v.useRef)(null),te=(b,W=!0)=>{he.current&&clearTimeout(he.current),G({msg:b,ok:W}),he.current=setTimeout(()=>G(null),1900)},pe=async()=>{if(!Y){_("restart");try{let b=await fetch(J+"/restart-self",{method:"POST"});if(b.status===404||b.status===405){te(Qe("vcRestartNoRoute",{cmd:A&&A.restartCommand||"dsh-memory restart --port 7999"}),!1);return}let W=await b.json().catch(()=>null);if(!W){te(e("vcRestartFail")+"\uFF08HTTP "+b.status+"\uFF09",!1);return}if(!W.ok){te(W.error||e("vcRestartFail"),!1);return}if(W.alreadyCurrent){te(W.note||e("vcRestartCurrent"));return}te(W.note||e("vcRestartSent")),W.alreadyRunning||setTimeout(()=>{Z(!0)},6e3)}catch(b){te(e("vcRestartFail")+"\uFF1A"+String(b&&b.message||b),!1)}finally{_("")}}},Fe=A&&A.resident?String(A.resident.served||""):"",ht=!!(A&&A.onDisk&&Fe&&Fe!==A.onDisk),Qe=(b,W)=>Object.keys(W).reduce((U,oe)=>U.split("{"+oe+"}").join(W[oe]),e(b)),_e=(0,v.useCallback)(async()=>{try{let[b,W,U]=await Promise.all([fetch(`${J}/config`).then(oe=>oe.json()).catch(()=>null),fetch(`${J}/setup-status`).then(oe=>oe.json()).catch(()=>null),fetch(`${J}/budget`).then(oe=>oe.json()).catch(()=>null)]);if(b&&b.ok){l(b),s(b.revision??0),f(b.schema??null);let oe=Vp(b.config??{},c.current);c.current=oe.overlay,h({...oe.values}),N(b.dsh??null),k(b.writable===!1),w(b.viaPending===!0),O(""),I.current=!1}else U&&U.ok?(h({...U}),k(!0),O(e("configNeedsDsh"))):O(e("adminLoadFail"));W&&W.ok&&j(W),K("")}catch{O(e("adminLoadFail"))}},[e]);(0,v.useEffect)(()=>{_e()},[n,_e]);let He=(b,W)=>{I.current=!0,h(U=>({...U??{},[b]:W}))};(0,v.useEffect)(()=>{d.current=_e},[_e]),(0,v.useEffect)(()=>{if(typeof EventSource>"u")return;let b=null;try{b=new EventSource(J+"/events")}catch{return}let W=()=>{!I.current&&typeof d.current=="function"&&d.current()};try{b.addEventListener("config",W)}catch{}return()=>{try{b.close()}catch{}}},[]);let bn=new Set(["dedupThreshold","captureMinChars","captureCooldownMs","maxCardsPerDay","captureMaxTokens","recallMinScore","recallLimit","recallSummaryLen","recycleRetentionDays","webPort","webCheckIntervalMs","webMaxRestart","sessionBudgetChars"]),un=b=>({init:e("modeInit"),interval:e("modeInterval"),manual:e("modeManual")})[b]||b,Gt=async()=>{if(!y)return;if(m){te(e("editInSetting"),!1);return}let b={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]},W=[];for(let[U,[oe,ze]]of Object.entries(b)){if(!(U in y))continue;let ee=y[U],de=typeof ee=="number"?ee:Number(ee);(ee===""||ee===null||ee===void 0||!Number.isFinite(de)||de<oe||de>ze)&&W.push(e("invalidField",{field:U,min:oe,max:ze,value:String(ee===""?"\u7A7A":ee)}))}if(W.length){let U=e("saveInvalid")+"\uFF1A"+W.join("\uFF1B");O(U),te(U,!1);return}_("save");try{let U={...y};for(let de of Object.keys(y))de in U&&typeof U[de]=="string"&&U[de].trim()!==""&&bn.has(de)&&(U[de]=Number(U[de]));Array.isArray(U.vaultProfiles)&&(U.vaultProfiles=U.vaultProfiles.filter(de=>de&&(String(de.name||"").trim()||String(de.path||"").trim())));let oe=await fetch(`${J}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:U,expectedRevision:a})}),ze=await oe.text(),ee=null;try{ee=ze?JSON.parse(ze):null}catch{ee=null}if(ee||(ee={error:"HTTP "+oe.status+(ze?"\uFF1A"+ze.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")}),ee&&ee.ok){let de=typeof ee.pendingOutcome=="string"?ee.pendingOutcome:"",L,V=!0;if(de==="applied")L=e("savedApplied")+(Array.isArray(ee.applied)&&ee.applied.length?" \xB7 "+ee.applied.join("\u3001"):"");else if(de==="queued")V=!1,L=e("saveQueued");else if(de==="failed")V=!1,L=e("saveFail")+" \xB7 "+(ee.hostGuard?e("saveHostGuard"):e("saveFailHint"));else if(de==="applied-direct")L=e("savedOk")+" \xB7 "+e("savedDirect");else{let le=Array.isArray(ee.pending)&&ee.pending.length?" \xB7 "+e("savePending"):ee.note?" \xB7 "+e("restartHint"):"";L=(ee.retried?"\u267B ":"")+e("savedOk")+le}c.current={...c.current,...U},V?K(L):O(L),te(L,V),await _e()}else{let de=oe.status===409?e("conflictRefresh"):ee?.error||e("saveFail");O(de),te(de,!1)}}catch{O(e("saveFail")),te(e("saveFail"),!1)}finally{_("")}},Kn=()=>{c.current={},h({...o?.config??{}}),K("")},Sn={env:"vaultSrcEnv",profile:"vaultSrcProfile",workspace:"vaultSrcWorkspace",vaultDir:"vaultSrcVaultDir",default:"vaultSrcDefault"},ot=b=>Array.isArray(b?.vaultProfiles)?b.vaultProfiles:[],yt=(b,W,U)=>h(oe=>{let ze=ot(oe).map(de=>({...de||{}})),ee={...ze[b]||{}};return W==="match"?String(U).trim()?ee.match={...ee.match||{},workspace:U}:delete ee.match:ee[W]=U,ze[b]=ee,{...oe??{},vaultProfiles:ze}}),xe=()=>h(b=>({...b??{},vaultProfiles:[...ot(b),{name:"",path:""}]})),qt=b=>h(W=>({...W??{},vaultProfiles:ot(W).filter((U,oe)=>oe!==b)})),We={fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},S={padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"transparent",color:"inherit",font:"inherit",fontSize:12,minWidth:0},x={A:{label:e("planA"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:4e3,recallMinScore:2,recallLimit:5,recallSummaryLen:130,recallIncludeBody:!1,captureCooldownMs:3e5},B:{label:e("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:e("planC"),autoWebMode:"interval",watchdogAutoSpawn:!0,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:1200,recallMinScore:1,recallLimit:8,recallSummaryLen:200,recallIncludeBody:!0,captureCooldownMs:12e4}},Q=async b=>{let W=x[b];W&&h(U=>({...U??{},...W}))},ge=async(b,W)=>{_(b+W);try{let oe=await(await fetch(`${J}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:b,action:W})})).json();oe&&oe.ok?te(Qe(W==="install"?"mcpInstalled":"mcpUninstalled",{agent:b})):te(Qe("mcpActionFail",{agent:b,error:oe?.error||""}),!1);try{let ze=await fetch(`${J}/setup-status`).then(ee=>ee.json());ze&&ze.ok&&j(ze)}catch{}}catch{te(e("mergeFail"),!1)}finally{_("")}},q=({k:b,label:W,type:U="text",step:oe,min:ze,max:ee})=>(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,i.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:W||b}),(0,i.jsx)("input",{type:U,step:oe,min:ze,max:ee,value:y?y[b]??"":"",onChange:de=>{let L=de.target.value;He(b,U==="number"?L===""?"":Number(L):L)},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}})]}),ke=new Set(["autoRestartOnDrift"]),p=({k:b,label:W})=>{let U=y?y[b]:void 0,oe=U===void 0?ke.has(b):!!U;return(0,i.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:12,minWidth:0,lineHeight:1.5},children:[(0,i.jsx)("input",{type:"checkbox",checked:oe,onChange:ze=>He(b,ze.target.checked),style:{marginTop:2,flex:"0 0 auto"}}),(0,i.jsx)("span",{style:{whiteSpace:"normal",overflowWrap:"anywhere"},children:W||b})]})};return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:r?"0 0 auto":1,minHeight:0,maxHeight:r?"52vh":void 0},children:[(0,i.jsx)("style",{children:sn}),z&&(0,i.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 "+(z.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,i.jsx)("span",{style:{color:z.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:z.ok?"\u2713":"\u2715"}),(0,i.jsx)("span",{style:{wordBreak:"break-all"},children:z.msg})]}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[D&&(0,i.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",D]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:_e,children:["\u21BB ",e("retry")]})]}),M&&(0,i.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 ",e("pendingSyncNote")]}),m&&(0,i.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 ",e("configNeedsDsh")," \u2014\u2014 ",e("editInSetting")]}),T&&(0,i.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 ",T]}),o&&(o.version||o.dsh?.vaultDir)&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F4E6} ",e("pluginInfo")]}),(0,i.jsx)("span",{style:{fontSize:12,opacity:.7},children:e("dshHostLabel")}),o.version&&(0,i.jsxs)("code",{style:We,children:[e("vcLoaded")," v",o.version]}),A&&A.resident&&A.resident.served&&A.resident.served!==o.version&&(0,i.jsxs)("code",{style:We,children:[e("vcResident")," v",A.resident.served]}),Ko&&(0,i.jsxs)("code",{style:We,children:[e("vcPage")," v",Ko]}),A&&A.onDisk&&(0,i.jsxs)("code",{style:We,children:[e("vcOnDisk")," v",A.onDisk]}),A&&A.latest&&(0,i.jsxs)("code",{style:We,children:[e("vcLatest")," v",A.latest]}),o.dsh?.vaultDir&&(0,i.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",o.dsh.vaultDir]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:Y==="version",onClick:()=>Z(!0),children:Y==="version"?e("checking"):"\u{1F504} "+e("vcCheck")})]}),A&&A.stale&&(0,i.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,i.jsxs)("div",{children:["\u26A0\uFE0F ",Qe("vcStale",{disk:A.onDisk,loaded:A.loaded})]}),ht?(0,i.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",marginTop:6,flexWrap:"wrap"},children:[(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!Y,onClick:pe,children:Y==="restart"?"\u23F3 "+e("vcRestarting"):"\u{1F504} "+e("vcRestart")}),A.restartCommand&&(0,i.jsx)("code",{style:{fontSize:11,opacity:.75},children:A.restartCommand})]}):(0,i.jsxs)("div",{style:{marginTop:6,lineHeight:1.7},children:["\u2139\uFE0F ",e("vcHostStale"),A.restartCommand&&(0,i.jsxs)(i.Fragment,{children:[" ",(0,i.jsx)("code",{style:{fontSize:11,opacity:.75},children:A.restartCommand})]})]})]}),Ko&&A&&A.onDisk&&Ko!==A.onDisk&&(0,i.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:e("vcPageStale",{page:Ko,disk:A.onDisk})}),A&&A.updateAvailable&&(0,i.jsxs)("div",{style:{marginTop:8,fontSize:11.5,opacity:.88},children:["\u2B06 ",e("vcOutdated")," \u2192 ",(0,i.jsx)("code",{children:A.updateCommand})]}),A&&A.checkError&&(0,i.jsxs)("div",{style:{marginTop:8,fontSize:11.5,color:"#b91c1c"},children:[e("vcCheckFail"),"\uFF1A",A.checkError]})]}),P&&P.agents&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F50C} ",e("mcpSetupStatus")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("mcpManageHint")})]}),(0,i.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:P.agents.map(b=>(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[(0,i.jsxs)("span",{style:{flex:1},children:[(0,i.jsx)("b",{children:b.isDsh?e("dshHostLabel"):b.name}),b.isDsh&&b.version&&(0,i.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",b.version]}),!b.installed&&(0,i.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",e("notInstalled"),")"]}),b.installed&&b.mcpConfigured===!1&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",e("noMcpEntry"),")"]}),b.mcpConfigured===!0&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",e("healthy")]}),b.mcpConfigured===!0&&b.mcpMatchesCurrentNode===!1&&(0,i.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",e("nodePathNote"),")"]}),b.isDsh&&(0,i.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",e("recallTool"),": ",b.recallTool?e("enabled"):e("disabled"),")"]})]}),b.hook&&(0,i.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",b.hook]}),!b.isDsh&&b.installed&&b.mcpConfigured===!1&&(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!Y,onClick:()=>ge(b.name,"install"),children:e("installMcp")}),!b.isDsh&&b.installed&&b.mcpConfigured===!0&&(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!Y,onClick:()=>{window.confirm(e("uninstallConfirm"))&&ge(b.name,"uninstall")},children:e("uninstallMcp")})]},b.name))}),(0,i.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:e("mcpSetupHint")}),re&&(0,i.jsx)("div",{style:{fontSize:11,marginTop:6},children:(0,i.jsx)("code",{style:{padding:"2px 6px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:4},children:re})})]}),y?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #3b82f6"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8,flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F3AF} ",e("presetConfig")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("presetHint")})]}),(0,i.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["A","B","C"].map(b=>(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>Q(b),disabled:!!Y,children:[b==="A"?"\u{1F7E2} ":b==="B"?"\u{1F4B0} ":"\u2B50 ",x[b].label]},b))})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F9E0} ",e("dshMemoryConfig")]})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"autoCapture",label:e("autoCapture")}),(0,i.jsx)(p,{k:"autoRecall",label:e("autoRecall")}),(0,i.jsx)(q,{k:"captureMinChars",label:e("captureMinChars"),type:"number"}),(0,i.jsx)(q,{k:"maxCardsPerDay",label:e("maxCardsPerDay"),type:"number"}),(0,i.jsx)(q,{k:"dedupThreshold",label:e("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,i.jsx)(q,{k:"recallLimit",label:e("recallLimit"),type:"number"}),(0,i.jsx)(q,{k:"recallSummaryLen",label:e("recallSummaryLen"),type:"number"}),(0,i.jsx)(p,{k:"recallIncludeBody",label:e("recallBody")}),(0,i.jsx)(q,{k:"secretHint",label:e("secretHint")}),(0,i.jsx)(q,{k:"recallEmbedding",label:e("recallEmbedding")})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #06b6d4"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:6},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F5C2}\uFE0F ",e("vaultMulti")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("vaultMultiHint")})]}),(0,i.jsxs)("div",{style:{fontSize:11.5,opacity:.85,marginBottom:8,lineHeight:1.7},children:[e("vaultNow"),"\uFF1A",(0,i.jsx)("code",{children:g?.vaultDir||"\u2014"}),g?.vaultName?`\uFF08${g.vaultName}\uFF09`:""," \xB7 ",e("vaultSource"),"\uFF1A",e(Sn[g?.vaultSource]||"vaultSrcDefault"),g?.workspace?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("br",{}),e("vaultWorkspace"),"\uFF1A",(0,i.jsx)("code",{children:g.workspace})]}):null]}),ot(y).map((b,W)=>(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1.6fr 1.5fr auto",gap:6,marginBottom:6},children:[(0,i.jsx)("input",{value:b.name||"",placeholder:e("vaultNamePh"),onChange:U=>yt(W,"name",U.target.value),style:S,disabled:m}),(0,i.jsx)("input",{value:b.path||"",placeholder:e("vaultPathPh"),onChange:U=>yt(W,"path",U.target.value),style:S,disabled:m}),(0,i.jsx)("input",{value:b.match&&b.match.workspace||"",placeholder:e("vaultMatchPh"),onChange:U=>yt(W,"match",U.target.value),style:S,disabled:m}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>qt(W),disabled:m,title:e("delete"),children:"\u2715"})]},W)),(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",marginTop:4},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:xe,disabled:m,children:["\uFF0B ",e("vaultAdd")]}),(0,i.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12},children:[(0,i.jsx)("span",{style:{opacity:.6},children:e("vaultActive")}),(0,i.jsxs)("select",{value:y.activeVault||"",onChange:b=>He("activeVault",b.target.value),disabled:m,style:S,children:[(0,i.jsx)("option",{value:"",children:e("vaultActiveNone")}),ot(y).filter(b=>b&&b.name).map(b=>(0,i.jsx)("option",{value:b.name,children:b.name},b.name))]})]})]})]}),(0,i.jsx)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"enabled",label:e("enabledLabel")}),(0,i.jsx)(q,{k:"vaultDir",label:e("vaultDirLabel")})]})}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #f59e0b"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F4B0} ",e("costControl")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("costHint")})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8,marginTop:6},children:[(0,i.jsx)(p,{k:"distillEnabled",label:e("distillEnabled")}),(0,i.jsx)(p,{k:"dedupByLLM",label:e("dedupByLLM")}),(0,i.jsx)(q,{k:"captureMaxTokens",label:e("captureMaxTokens"),type:"number"}),(0,i.jsx)(q,{k:"recallMinScore",label:e("recallMinScore"),type:"number"}),(0,i.jsx)(q,{k:"captureCooldownMs",label:e("captureCooldownMs"),type:"number"}),(0,i.jsx)(q,{k:"captureProvider",label:e("captureProvider")}),(0,i.jsx)(q,{k:"captureModel",label:e("captureModel")}),(0,i.jsx)(q,{k:"sessionBudgetChars",label:e("sessionBudgetChars"),type:"number"})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #8b5cf6"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",e("auditConfig")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("auditHint")})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:8},children:[(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,i.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:e("auditMode")}),(0,i.jsxs)("select",{value:y.auditMode??"all",onChange:b=>He("auditMode",b.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,i.jsx)("option",{value:"all",children:e("auditAll")}),(0,i.jsx)("option",{value:"none",children:e("auditNone")})]})]}),(0,i.jsx)(Gp,{label:e("auditExemptAgents"),value:y.auditExemptAgents||[],options:[{value:"__all__",label:e("allExempt")},...(P?.agents||[]).filter(b=>!b.isDsh).map(b=>({value:b.name,label:b.name}))],onChange:b=>He("auditExemptAgents",b)}),(0,i.jsx)(Gp,{label:e("auditExemptKinds"),value:y.auditExemptKinds||[],options:[{value:"__all__",label:e("allExempt")},...Gs.filter(b=>b!=="all").map(b=>({value:b,label:e(Ft[b])}))],onChange:b=>He("auditExemptKinds",b)}),(0,i.jsx)(q,{k:"recycleRetentionDays",label:e("recycleDays"),type:"number"})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E0} ",e("serviceConfig")]})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:8},children:[(0,i.jsx)(p,{k:"autoWeb",label:e("autoWeb")}),(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,i.jsx)("span",{style:{opacity:.6},children:e("autoWebMode")}),(0,i.jsxs)("select",{value:y.autoWebMode??"init",onChange:b=>He("autoWebMode",b.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,i.jsx)("option",{value:"init",children:e("modeInit")}),(0,i.jsx)("option",{value:"interval",children:e("modeInterval")}),(0,i.jsx)("option",{value:"manual",children:e("modeManual")})]})]}),(0,i.jsx)(q,{k:"webPort",label:e("webPort"),type:"number"}),(0,i.jsx)(q,{k:"webCheckIntervalMs",label:e("webCheckIntervalMs"),type:"number"}),(0,i.jsx)(q,{k:"webMaxRestart",label:e("webMaxRestart"),type:"number"}),(0,i.jsx)(p,{k:"watchdogAutoSpawn",label:e("watchdogAutoSpawn")}),(0,i.jsx)(p,{k:"autoRestartOnDrift",label:e("autoRestartOnDrift")}),(0,i.jsx)(p,{k:"autoMcpSetup",label:e("autoMcpSetup")})]})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",alignItems:"center",marginBottom:10,flexWrap:"wrap"},children:[Y==="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,opacity:.75},children:["\u23F3 ",e("saving")]}),T&&Y!=="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,color:"#10b981"},children:["\u2705 ",T]}),D&&Y!=="save"&&(0,i.jsxs)("span",{style:{fontSize:11.5,color:"#b91c1c"},children:["\u26A0 ",D]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:Kn,disabled:!!Y,children:e("reset")}),(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:m?()=>te(e("readonlyTitle")+"\uFF1A"+e("readonlyBody"),!1):Gt,disabled:Y==="save",title:e(m?"readonlyBody":"saveConfig"),children:Y==="save"?"\u23F3 "+e("saving"):m?"\u{1F512} "+e("readonlyBtn"):"\u{1F4BE} "+e("saveConfig")})]})]}):(0,i.jsx)("div",{style:{fontSize:12,opacity:.6},children:e("loading")})]})]})}function Qg({t:e,onReload:t,version:n}){let[r,o]=(0,v.useState)([]),[l,a]=(0,v.useState)([]),[s,u]=(0,v.useState)("all"),[f,y]=(0,v.useState)("all"),[h,m]=(0,v.useState)(""),[k,M]=(0,v.useState)(new Set),[w,I]=(0,v.useState)(""),[d,c]=(0,v.useState)(null),[g,N]=(0,v.useState)("pending"),P=(z,G=!0)=>{c({msg:z,ok:G}),setTimeout(()=>c(null),3e3)},j=[...new Set([...r,...l].map(z=>z.submittedBy).filter(Boolean))],D=(0,v.useCallback)(async()=>{try{let z=await fetch(`${J}/audit/list`).then(G=>G.json());z.ok&&(o(z.pending||[]),a(z.rejected||[]),M(new Set),K(new Set),ce({}))}catch{}},[]);(0,v.useEffect)(()=>{D()},[n,D]);let O=(g==="pending"?r:l).filter(z=>{if(s!=="all"&&z.kind!==s||f!=="all"&&Kr(z.submittedBy)!==f)return!1;if(h){let G=(z.created||"").slice(0,10);if(G&&G!==h)return!1}return!0}),Y=z=>M(G=>{let he=new Set(G);return he.has(z)?he.delete(z):he.add(z),he}),_=async(z,G)=>{let he=G||[...k];if(!he.length){P(e("noSelection"),!1);return}I("apply");let te=e(z==="approved"?"toastApproved":z==="rejected"?"toastRejected":"toastCardDeleted");try{let pe=0;for(let Fe of he){let ht=z==="approved"?"audit/approve":z==="rejected"?"audit/reject":"delete";try{(await fetch(J+"/"+ht+"?path="+encodeURIComponent(Fe)+(z==="delete"?"&permanent=0":""))).ok||pe++}catch{pe++}}await D(),t&&t(),pe?P(e("toastFailed")+"\uFF08"+pe+"/"+he.length+"\uFF09",!1):P(te+" "+he.length+" \u5F20")}catch(pe){P(e("toastFailed")+": "+String(pe&&pe.message||pe),!1)}finally{I("")}},[T,K]=(0,v.useState)(new Set),[A,ce]=(0,v.useState)({}),Z=z=>A[z]||{},re=async z=>{let G=z.path,he=!T.has(G);if(K(te=>{let pe=new Set(te);return he?pe.add(G):pe.delete(G),pe}),!(!he||A[G])){ce(te=>({...te,[G]:{loading:!0}}));try{let te=z.status||(g==="pending"?"pending":"rejected"),pe=await fetch(`${J}/card?path=${encodeURIComponent(G)}&status=${te}`).then(Fe=>Fe.json());pe&&pe.ok?ce(Fe=>({...Fe,[G]:{text:pe.text||""}})):ce(Fe=>({...Fe,[G]:{error:pe&&pe.error||"HTTP"}}))}catch(te){ce(pe=>({...pe,[G]:{error:String(te&&te.message||te)}}))}}},me=[...k];return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,i.jsx)(tf,{toast:d}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",e("tabAudit")]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("select",{value:s,onChange:z=>u(z.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,i.jsx)("option",{value:"all",children:e("all")}),Gs.filter(z=>z!=="all").map(z=>(0,i.jsx)("option",{value:z,children:e(Ft[z])},z))]}),(0,i.jsxs)("select",{value:f,onChange:z=>y(z.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,i.jsx)("option",{value:"all",children:e("allAgents")}),Jp(j).map(z=>(0,i.jsx)("option",{value:z,children:z},z))]}),(0,i.jsx)("input",{type:"date",value:h,onChange:z=>m(z.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,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("button",{type:"button",className:`mc-btn${g==="pending"?" me-on":""}`,onClick:()=>N("pending"),children:[e("pending"),"\uFF08",r.length,"\uFF09"]}),(0,i.jsxs)("button",{type:"button",className:`mc-btn${g==="rejected"?" me-on":""}`,onClick:()=>N("rejected"),children:[e("rejected"),"\uFF08",l.length,"\uFF09"]}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("label",{style:{fontSize:12},children:[(0,i.jsx)("input",{type:"checkbox",checked:O.length>0&&me.length===O.length,onChange:z=>{z.target.checked?M(new Set(O.map(G=>G.path))):M(new Set)}})," ",e("selectAll")]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!me.length||!!w,onClick:()=>_("approved"),children:["\u2713 ",e(g==="rejected"?"restore":"approve")]}),g==="pending"?(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!me.length||!!w,onClick:()=>_("rejected"),children:["\u2715 ",e("reject")]}):(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!me.length||!!w,onClick:()=>{window.confirm(e("recycleDeleteConfirm"))&&_("delete")},children:["\u{1F5D1} ",e("restoreDelete")]})]}),O.length?(0,i.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:O.map(z=>{let G=Z(z.path),he=T.has(z.path);return(0,i.jsxs)("div",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",fontSize:12},children:[(0,i.jsx)("input",{type:"checkbox",checked:k.has(z.path),onChange:()=>Y(z.path)}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"0 6px"},title:e(he?"collapse":"expand"),"aria-expanded":he,onClick:()=>re(z),children:he?"\u25BE":"\u25B8"}),(0,i.jsx)("span",{className:"mc-kind",style:{background:At[z.kind]||"#999"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},title:e(he?"collapse":"expand"),onClick:()=>re(z),children:z.title}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:Kr(z.submittedBy)}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:z.created?z.created.slice(0,16).replace("T"," "):"-"}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6},children:z.kind}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6,color:z.severity==="high"?"#f87171":"#9ca3af"},children:z.severity}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.reason||"-"}),g==="pending"?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>_("approved",[z.path]),children:"\u2713"}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>_("rejected",[z.path]),children:"\u2715"})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},title:e("restore"),onClick:()=>_("approved",[z.path]),children:"\u2713"}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},title:e("restoreDelete"),onClick:()=>{window.confirm(e("recycleDeleteConfirm"))&&_("delete",[z.path])},children:"\u{1F5D1}"})]})]}),he&&(0,i.jsxs)("div",{style:{padding:"2px 10px 12px 34px"},children:[G.loading&&(0,i.jsxs)("div",{style:{fontSize:12,opacity:.6},children:["\u23F3 ",e("loading")]}),G.error&&(0,i.jsxs)("div",{style:{fontSize:12,color:"#f87171"},children:["\u26A0 ",e("auditBodyFail"),"\uFF1A",G.error]}),G.text!=null&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"md-meta",style:{marginBottom:6},children:[(0,i.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:At[z.kind]||"#6B7280",borderColor:(At[z.kind]||"#6B7280")+"59",background:(At[z.kind]||"#6B7280")+"1a"},children:[Yo[z.kind]||"\u{1F4CE}"," ",e(Ft[z.kind]||"kindKnowledge")]}),(Array.isArray(z.tags)?z.tags:[]).slice(0,8).map(te=>(0,i.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",te]},te)),!!z.reason&&(0,i.jsxs)("span",{className:"md-chip md-chip-st-warn",children:["\u2691 ",z.reason]})]}),(0,i.jsx)("div",{className:"md-doc",style:{maxHeight:340,overflow:"auto"},dangerouslySetInnerHTML:{__html:Ks(ki(G.text).body)}}),g==="pending"&&(0,i.jsxs)("div",{style:{display:"flex",gap:8,marginTop:8},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!!w,onClick:()=>_("approved",[z.path]),children:["\u2713 ",e("approve")]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!w,onClick:()=>_("rejected",[z.path]),children:["\u2715 ",e("reject")]})]})]})]})]},z.path)})}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:e("noAuditItems")})]})]})}function Yg({t:e,onReload:t,version:n}){let[r,o]=(0,v.useState)([]),[l,a]=(0,v.useState)(""),[s,u]=(0,v.useState)(null),f=(m,k=!0)=>{u({msg:m,ok:k}),setTimeout(()=>u(null),3200)},y=(0,v.useCallback)(async()=>{try{let m=await fetch(`${J}/recycle/list`).then(k=>k.json());m.ok&&o(m.items||[])}catch{}},[]);(0,v.useEffect)(()=>{y()},[n,y]);let h=async(m,k)=>{let M=(r.find(w=>w.path===k)||{}).title||k;a(m+k);try{let I=await fetch(J+(m==="restore"?"/recycle/restore":"/recycle/purge")+"?path="+encodeURIComponent(k)),d=await I.json().catch(()=>null);await y(),t&&t(),I.ok&&(!d||d.ok!==!1)?f(e(m==="restore"?"toastRestored":"toastPurged")+"\uFF1A"+M):f(e("toastFailed")+"\uFF1A"+(d&&d.error||"HTTP "+I.status),!1)}catch(w){f(e("toastFailed")+"\uFF1A"+String(w&&w.message||w),!1)}finally{a("")}};return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,i.jsx)(tf,{toast:s}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1F5D1}\uFE0F ",e("tabRecycle")]}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("recycleHint")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:!!l||r.length===0,title:r.length?"":e("emptyRecycle"),onClick:async()=>{a("purgeAll");try{let m=await fetch(J+"/recycle/purge-expired?days=0"),k=await m.json().catch(()=>null);await y(),f(m.ok?e("toastPurgedExpired")+(k&&k.purged!=null?"\uFF08"+k.purged+"\uFF09":""):e("toastFailed"),m.ok)}catch(m){f(e("toastFailed")+"\uFF1A"+String(m&&m.message||m),!1)}finally{a("")}},children:e("emptyRecycle")})]}),r.length?(0,i.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:r.map(m=>(0,i.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,i.jsx)("span",{className:"mc-kind",style:{background:At[m.kind]||"#999"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.title}),(0,i.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[e("deletedAt")," ",(m.deletedAt||"").slice(0,10)]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!l,onClick:()=>h("restore",m.path),children:e("restore")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!l,onClick:()=>{window.confirm(e("purgeConfirm"))&&h("purge",m.path)},children:e("purge")})]},m.path))}):(0,i.jsxs)("div",{className:"mc-card",style:{padding:18,fontSize:12.5,opacity:.78,textAlign:"center",lineHeight:1.9},children:["\u{1F5D1}\uFE0F ",e("emptyRecycle"),(0,i.jsx)("br",{}),(0,i.jsx)("span",{style:{fontSize:11.5},children:e("recycleEmptyHint").split("{days}").join("30")})]})]})]})}var Xg=({card:e,t,onOpen:n,query:r,onDelete:o})=>(0,i.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>n(e),children:[(0,i.jsxs)("h4",{children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:At[e.kind]||At.other}}),(0,i.jsx)("span",{style:{marginRight:4},children:Yo[e.kind]||"\u{1F4CE}"}),r?qp(e.title,r):e.title,oh(e.updated)&&(0,i.jsx)("span",{className:"mc-new",children:t("newBadge")}),e.status==="pending"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",t("statusPending")]}),e.status==="rejected"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#ef4444"},children:["\u274C ",t("statusRejected")]}),(!e.status||e.status==="approved")&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#10b981"},children:["\u2705 ",t("statusApproved")]})]}),(0,i.jsx)("p",{children:r?qp(e.summary||"",r):e.summary||""}),e.tags.length>0&&(0,i.jsx)("div",{className:"mc-tags",children:e.tags.slice(0,4).map(l=>(0,i.jsxs)("span",{className:"mc-tag",children:["\u{1F3F7} ",l]},l))}),(0,i.jsxs)("footer",{children:[(0,i.jsxs)("span",{children:[Yo[e.kind]||"\u{1F4CE}"," ",t(Ft[e.kind])]}),(0,i.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",Kr(e.submittedBy)]}),(0,i.jsxs)("span",{children:["\u{1F4C5} ",Vr(e.updated)]}),(0,i.jsx)("span",{className:"spacer",style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-card-del",title:t("delete"),onClick:l=>{l.stopPropagation(),window.confirm(t("deleteConfirm"))&&o&&o(e.path)},children:"\u{1F5D1}"})]})]});function Gg({t:e,tab:t,onReload:n,version:r}){let[o,l]=(0,v.useState)(null),[a,s]=(0,v.useState)(""),[u,f]=(0,v.useState)(null),[y,h]=(0,v.useState)(null),[m,k]=(0,v.useState)(null),[M,w]=(0,v.useState)([]),[I,d]=(0,v.useState)(""),[c,g]=(0,v.useState)(!1),N=(0,v.useCallback)(async()=>{if(!(!u||!u.merge||!u.merge.length)&&window.confirm(e("mergeAllConfirm"))){d("merge");try{let T={},K=me=>T[me]===void 0?me:T[me]=K(T[me]),A=(me,z)=>{T[K(me)]=K(z)},ce=new Set;for(let me of u.merge)ce.add(me.a.path),ce.add(me.b.path),A(me.a.path,me.b.path);let Z={};for(let me of ce){let z=K(me);(Z[z]=Z[z]||[]).push(me)}let re=0;for(let me of Object.values(Z)){if(me.length<2)continue;(await fetch(`${J}/merge?paths=${encodeURIComponent(me.join(","))}`).then(G=>G.json())).ok&&re++}await P(),n&&n()}catch{}d("")}},[u,P,n,e]);async function P(){try{let T=await Promise.all([fetch(`${J}/stats`),fetch(`${J}/budget`),fetch(`${J}/capture-log`),fetch(`${J}/cards?status=all&limit=30&agent=${Qo}`)]),[K,A,ce,Z]=await Promise.all(T.map(re=>re.json()));K&&K.ok&&l(K),A&&A.ok&&h(A),ce&&ce.ok&&k(ce),Z&&Z.ok&&w(Z.cards||[]),s(!K||!K.ok?e("adminLoadFail"):"")}catch{s(e("adminLoadFail"))}}let j=(0,v.useCallback)(async()=>{d("scan");try{let T=await fetch(`${J}/optimize`).then(K=>K.json());T.ok&&f(T)}catch{s(e("adminLoadFail"))}finally{d("")}},[e]);(0,v.useEffect)(()=>{P()},[r]);let D=async(T,K)=>{if(window.confirm(e("mergeConfirm")))try{(await fetch(`${J}/merge?paths=${encodeURIComponent(T+","+K)}`).then(ce=>ce.json())).ok&&(await P(),n&&n())}catch{}},O=async T=>{if(window.confirm(e("deleteConfirm")))try{(await fetch(`${J}/delete?path=${encodeURIComponent(T)}`).then(A=>A.json())).ok&&(await P(),n&&n())}catch{}},Y=["project","knowledge","content","prompt","business","tool","mistake"],_=({title:T,kind:K,updated:A,path:ce})=>(0,i.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:Ur.colors[K]||"#666"}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T}),(0,i.jsx)("span",{style:{opacity:.55,fontSize:11},children:Vr(A)}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>O(ce),children:[e("delete")," \u2715"]})]});return(0,i.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{style:{overflow:"auto"},children:[a&&(0,i.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",a]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:P,children:["\u21BB ",e("retry")]})]}),t==="stats"&&(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsxs)("b",{style:{fontSize:12},children:["\u{1FAB5} ",e("captureLog")]}),(0,i.jsx)("span",{style:{fontSize:11,opacity:.6},children:e("captureLogHint")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>P(),children:["\u21BB ",e("refresh")]})]}),m?m.available===!1?(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("captureLogUnavailable")}):(m.entries||[]).length===0?(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("captureLogEmpty")}):(0,i.jsx)("div",{style:{maxHeight:260,overflow:"auto",marginTop:8},children:(0,i.jsx)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:(0,i.jsx)("tbody",{children:(m.entries||[]).map((T,K)=>{let A=Ug[T.action]||["\u2022","inherit"];return(0,i.jsxs)("tr",{style:{borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsx)("td",{style:{padding:"4px 6px",opacity:.55,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:Vr(T.time?new Date(T.time).toISOString():"")}),(0,i.jsxs)("td",{style:{padding:"4px 6px",whiteSpace:"nowrap",color:A[1],fontWeight:600},children:[A[0]," ",T.action]}),(0,i.jsx)("td",{style:{padding:"4px 6px"},children:T.reason||""}),(0,i.jsx)("td",{style:{padding:"4px 6px",opacity:.55,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:T.preview||"",children:T.preview||""})]},K)})})})}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,padding:"8px 0"},children:e("loading")})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:["\u{1F916} ",e("captureAgentCards"),"\uFF08",M.length,"\uFF09"]}),M.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:M.map(T=>(0,i.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,i.jsx)("span",{className:"mc-kind",style:{background:At[T.kind]||At.other}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T.title}),T.status==="pending"&&(0,i.jsxs)("span",{className:"mc-status",style:{background:"#f59e0b"},children:["\u23F3 ",e("statusPending")]}),(0,i.jsx)("span",{style:{opacity:.55,fontSize:11},children:Vr(T.updated)})]},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noCards")})]}),o&&(0,i.jsxs)(i.Fragment,{children:[o.trend&&o.trend.length>0&&(()=>{let T=o.trend,K=Math.max(...T.map(re=>re.count),1),A=260,ce=50,Z=A/T.length;return(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,i.jsxs)("div",{style:{fontSize:11,opacity:.6,marginBottom:4},children:["\u{1F4C8} ",e("trendLabel")]}),(0,i.jsx)("svg",{width:A,height:ce,style:{display:"block",width:"100%",height:50},children:T.map((re,me)=>{let z=Math.round(re.count/K*(ce-4));return(0,i.jsx)("rect",{x:me*Z+1,y:ce-z,width:Math.max(Z-2,2),height:z,rx:1.5,fill:re.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:re.count>0?.85:.35},re.date)})})]})})(),(0,i.jsxs)("div",{className:"mc-stats",children:[(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.total}),(0,i.jsx)("span",{children:e("total")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.today}),(0,i.jsx)("span",{children:e("todayAdd")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.week}),(0,i.jsx)("span",{children:e("weekAdd")})]}),(0,i.jsxs)("div",{className:"mc-stat mc-card",children:[(0,i.jsx)("b",{children:o.tags}),(0,i.jsx)("span",{children:e("tags")})]})]}),(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,i.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:e("byKind")}),(0,i.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:Y.map(T=>(0,i.jsxs)("span",{style:{fontSize:12},children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:Ur.colors[T]||"#666"}}),e(Ft[T]),": ",o.byKind?.[T]||0]},T))})]}),y&&(y.budgetChars||y.recallLimit||y.embedding)&&(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,i.jsx)("b",{children:e("budgetLabel")}),"\uFF1A",e("budgetChars")," ",(0,i.jsx)("b",{children:y.budgetChars||8e4})," \xB7 ",e("recallLimitLabel")," ",(0,i.jsx)("b",{children:y.recallLimit||5})," \xB7 ",e("embeddingLabel")," ",y.embedding?"ON":"OFF"]}),(0,i.jsxs)("div",{className:"mc-card",children:[(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[e("todayList"),"\uFF08",o.todayCards?.length||0,"\uFF09"]}),o.todayCards?.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:o.todayCards.map(T=>(0,i.jsx)(_,{title:T.title,kind:T.kind,updated:T.updated,path:T.path},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noOptimize")})]})]})]}),t==="optimize"&&(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,i.jsx)("b",{style:{fontSize:12},children:e("organizeTitle")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",disabled:!!I,onClick:j,children:I==="scan"?e("exporting"):"\u{1F50D} "+e("scanAndOrganize")}),u&&u.merge?.length>0&&(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!I,onClick:async()=>{if(window.confirm(e("oneClickOptimizeConfirm"))){d("oneclick");try{let T=JSON.stringify({cleanupStale:c}),A=await(await fetch(`${J}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:T})).json();A&&A.ok?(notify(`${e("oneClickOptimizeDone")}\uFF1A${A.plan.merged} ${e("optimizedMerged")}${c?` \xB7 ${A.plan.staleDeleted} ${e("optimizedStaleDeleted")}`:""}`),await P(),n&&n(),f(null)):notify(e("mergeFail"),!1)}catch{notify(e("mergeFail"),!1)}finally{d("")}}},children:I==="oneclick"?e("exporting"):"\u26A1 "+e("oneClickOptimize")}),u&&u.merge?.length>0&&(0,i.jsxs)("label",{style:{fontSize:11,opacity:.7,display:"flex",alignItems:"center",gap:4},children:[(0,i.jsx)("input",{type:"checkbox",checked:c,onChange:T=>g(T.target.checked)}),e("oneClickAlsoStale")]})]}),!u&&(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:e("scanHint")}),u&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",flexDirection:"column",gap:8},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[(0,i.jsx)("b",{style:{fontSize:12},children:e("mergePairs")}),(0,i.jsx)("div",{className:"spacer",style:{flex:1}}),u.merge?.length>0&&(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!I,onClick:N,children:e(I==="merge"?"exporting":"batchMerge")})]}),(0,i.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:e("mergePairs")}),u.merge?.length?(0,i.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:u.merge.map((T,K)=>(0,i.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,i.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[T.a.title," \u21C4 ",T.b.title]}),(0,i.jsxs)("span",{style:{opacity:.6},children:[Math.round(T.sim*100),"%"]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>D(T.a.path,T.b.path),children:e("mergeNow")})]},K))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:e("noOptimize")}),(0,i.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[e("staleCards"),"\uFF08",u.stale?.length||0,"\uFF09"]}),u.stale?.length>0&&(0,i.jsx)("div",{style:{marginBottom:6},children:(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!I,onClick:async()=>{if(!window.confirm(e("deleteConfirm")))return;d("clean");let T=0;for(let K of u.stale)try{await fetch(`${J}/delete?path=${encodeURIComponent(K.path)}`),T++}catch{}d(""),notify(`${T} ${e("deletedStale")}`),await P(),n&&n()},children:e("cleanStale")})}),u.stale?.length?(0,i.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:u.stale.map(T=>(0,i.jsx)(_,{title:T.title,kind:"other",updated:T.updated,path:T.path},T.path))}):(0,i.jsx)("div",{style:{opacity:.6,fontSize:12},children:e("noOptimize")})]})})]})]})]})}var Ys=[{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 qg({t:e,newCard:t,setNewCard:n,onCreated:r}){if(!t)return null;let o=Ys.find(h=>h.key===t.template),l=t.body||(o?e(o.bodyKey):""),a=t.kind||(o?o.kind:"knowledge"),s=t.tags||(o?e(o.tagKey):""),u=t._creating,f=h=>{let m=Ys.find(k=>k.key===h);n(k=>({...k,template:h,kind:m?m.kind:k.kind,body:m?e(m.bodyKey):k.body,tags:m?e(m.tagKey):k.tags}))},y=async()=>{if(!(!t.title&&!l)){n(h=>({...h,_creating:!0}));try{(await fetch(`${J}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:t.title||e("untitled"),kind:a,tags:s.split(",").map(m=>m.trim()).filter(Boolean),body:l,source:"manual"})}).then(m=>m.json())).ok?(n(null),r&&r()):n(m=>({...m,_creating:!1}))}catch{n(m=>({...m,_creating:!1}))}}};return(0,i.jsxs)("div",{className:"me-overlay",onClick:()=>n(null),children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:h=>h.stopPropagation(),children:[(0,i.jsxs)("div",{className:"me-dialog-head",children:[(0,i.jsx)("h3",{children:e("newCard")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>n(null),children:e("close")})]}),(0,i.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10,overflow:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[Ys.map(h=>(0,i.jsx)("button",{type:"button",className:`mc-btn${t.template===h.key?" me-on":""}`,onClick:()=>f(h.key),children:e(h.label)},h.key)),(0,i.jsx)("button",{type:"button",className:`mc-btn${t.template===""?" me-on":""}`,onClick:()=>n(h=>({...h,template:"",body:"",tags:"",kind:"knowledge"})),children:e("tplBlank")})]}),(0,i.jsx)("select",{className:"mc-btn",value:a,onChange:h=>n(m=>({...m,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,i.jsx)("option",{value:h,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:h},h))}),(0,i.jsx)("input",{type:"text",className:"mc-btn",placeholder:e("cardTitle"),value:t.title||"",onChange:h=>n(m=>({...m,title:h.target.value}))}),(0,i.jsx)("input",{type:"text",className:"mc-btn",placeholder:e("tagsHint"),value:s,onChange:h=>n(m=>({...m,tags:h.target.value}))}),(0,i.jsx)("textarea",{className:"mc-btn",placeholder:e("cardBody"),value:l,onChange:h=>n(m=>({...m,body:h.target.value})),style:{minHeight:180,resize:"vertical",fontFamily:"inherit"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:(0,i.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:u,onClick:y,children:e(u?"exporting":"createCard")})})]})]})]})}async function Xp(e){let t=String(e||"");if(!t)return!1;try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{let n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.style.position="fixed",n.style.left="-9999px",n.style.top="0",document.body.appendChild(n),n.focus(),n.select();let r=!!(document.execCommand&&document.execCommand("copy"));return document.body.removeChild(n),r}catch{return!1}}function Zg({t:e,onClose:t}){let[n,r]=(0,v.useState)(""),[o,l]=(0,v.useState)(""),[a,s]=(0,v.useState)(""),[u,f]=(0,v.useState)(!0),[y,h]=(0,v.useState)(!1),[m,k]=(0,v.useState)(""),[M,w]=(0,v.useState)(""),I=(0,v.useRef)(null),d=(0,v.useRef)(null),c=()=>{let _=I.current;if(_)try{_.focus(),_.select()}catch{}},g=_=>{k(_),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>k(""),2400)};(0,v.useEffect)(()=>{let _=!0;return fetch(J+"/diagnostics").then(T=>T.json()).then(T=>{_&&(T&&T.ok?(l(String(T.diagnostics||"")),s(String(T.version||""))):h(!0))}).catch(()=>{_&&h(!0)}).finally(()=>{_&&f(!1)}),()=>{_=!1}},[]),(0,v.useEffect)(()=>{let _=T=>{T.key==="Escape"&&t()};return window.addEventListener("keydown",_),()=>{window.removeEventListener("keydown",_),d.current&&clearTimeout(d.current)}},[t]);let N=(()=>{try{return String(navigator.language||"").toLowerCase().startsWith("en")?"en":"zh"}catch{return"zh"}})(),P=()=>{let _=n.trim().split(`
308
308
  `)[0]||"",T=jp({title:"[Bug] "+(_.slice(0,60)||"memory-eternal \u95EE\u9898"),body:Bp({description:n,diagnostics:o,version:a})});try{window.open(T,"_blank","noopener")}catch{g(e("fbCopyFail"))}},j=async()=>{await Xp(o)?(w(""),g(e("fbCopiedDiag"))):(w(o),g(e("fbCopyManual")))},D=async()=>{let _=Hp({lang:N,description:n,diagnostics:o});await Xp(_)?(w(""),g(e("fbCopiedPrompt"))):(w(_),g(e("fbCopyManual")))},O={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},Y={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,i.jsxs)("div",{className:"me-overlay",onClick:t,children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{className:"me-dialog",style:{maxWidth:720},onClick:_=>_.stopPropagation(),children:[(0,i.jsxs)("div",{className:"me-dialog-head",children:[(0,i.jsxs)("h3",{children:["\u{1F41E} ",e("fbTitle")]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:t,children:e("close")})]}),(0,i.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10},children:[(0,i.jsx)("div",{style:{fontSize:12,opacity:.72,lineHeight:1.6},children:e("fbWhy")}),(0,i.jsx)("textarea",{value:n,onChange:_=>r(_.target.value),placeholder:e("fbDesc"),rows:5,style:O}),(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,i.jsx)("b",{style:{fontSize:12},children:e("fbDiag")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:j,disabled:!o,children:e("fbCopyDiag")})]}),(0,i.jsx)("pre",{style:Y,children:u?e("fbLoading"):y?e("fbDiagFail"):o})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end"},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>{if(!n.trim()){g(e("fbNeedDesc"));return}P()},style:{borderColor:"var(--dsw-alias-brand-primary, #3b82f6)",color:"var(--dsw-alias-brand-primary, #3b82f6)",fontWeight:600},children:["\u{1F680} ",e("fbOpenIssue")]}),(0,i.jsx)("span",{style:{opacity:.5,fontSize:12},children:e("fbOr")}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:D,children:["\u{1F916} ",e("fbCopyPrompt")]})]}),m&&(0,i.jsx)("div",{style:{fontSize:12,color:"var(--dsw-alias-brand-primary, #3b82f6)"},children:m}),M&&(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[(0,i.jsxs)("b",{style:{fontSize:12,color:"#b45309"},children:["\u26A0 ",e("fbCopyFail")]}),(0,i.jsx)("span",{style:{fontSize:11.5,opacity:.75},children:e("fbCopyManual")}),(0,i.jsx)("div",{style:{flex:1}}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:c,children:e("fbSelectAll")})]}),(0,i.jsx)("textarea",{ref:I,readOnly:!0,value:M,rows:7,style:O})]})]})]})]})}function Jg({t:e,card:t,query:n,onClose:r,onDelete:o,onFeedback:l}){(0,v.useEffect)(()=>{let I=d=>{d.key==="Escape"&&r()};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[r]);let{meta:a,body:s}=(0,v.useMemo)(()=>ki(t.text||""),[t.text]),u=I=>{let d=a.find(([c])=>String(c).toLowerCase()===I);return d?d[1]:""},f=Ap(u("tags")),y=u("kind")||"knowledge",h=(u("status")||"approved").toLowerCase(),m=At[y]||"#6B7280",k=(s||"").length>460,[M,w]=(0,v.useState)(!0);return(0,i.jsxs)("div",{className:"me-overlay",onClick:r,children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{className:"me-dialog",onClick:I=>I.stopPropagation(),children:[(0,i.jsxs)("div",{className:"me-dialog-head",children:[(0,i.jsxs)("h3",{children:[(0,i.jsx)("span",{style:{marginRight:6},children:Yo[y]||"\u{1F4CE}"}),t.title]}),(0,i.jsxs)("div",{style:{display:"flex",gap:8},children:[n&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!0),children:["\u{1F44D} ",e("fbUseful")]}),(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>l&&l(!1),children:["\u{1F44E} ",e("fbNotUseful")]})]}),k&&(0,i.jsx)("button",{type:"button",className:"mc-btn","aria-expanded":M,onClick:()=>w(I=>!I),children:e(M?"collapse":"expand")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(e("deleteConfirm"))&&o&&o(t.path)},children:e("delete")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:r,children:e("close")})]})]}),(0,i.jsxs)("div",{className:"md-meta",children:[(0,i.jsxs)("span",{className:"md-chip md-chip-kind",style:{color:m,borderColor:m+"59",background:m+"1a"},children:[Yo[y]||"\u{1F4CE}"," ",e(Ft[y]||"kindKnowledge")]}),(0,i.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"," ",e(h==="approved"?"statusApproved":h==="pending"?"statusPending":"statusRejected")]}),f.slice(0,8).map(I=>(0,i.jsxs)("span",{className:"md-chip md-chip-tag",children:["\u{1F3F7} ",I]},I)),!!u("updated")&&(0,i.jsxs)("span",{className:"md-chip md-date",children:["\u{1F552} ",e("updated")," ",Vr(u("updated"))]}),!!u("source")&&(0,i.jsxs)("span",{className:"md-chip md-date",children:["\u{1F4E5} ",u("source")]})]}),(0,i.jsx)("div",{className:"me-dialog-body",style:M?{}:{maxHeight:300,overflow:"hidden"},onClick:M?void 0:I=>{I.stopPropagation(),w(!0)},children:(0,i.jsx)("div",{className:"md-doc",dangerouslySetInnerHTML:{__html:Ks(s)}})}),!M&&(0,i.jsxs)("div",{className:"md-collapsed-hint",onClick:I=>{I.stopPropagation(),w(!0)},children:[e("expand")," \u2304"]})]})]})}function eh({t:e,onOpen:t,all:n,onAllChange:r,onMutate:o,active:l,visible:a}){let[s,u]=(0,v.useState)(null),[f,y]=(0,v.useState)(""),h=(0,v.useRef)(!1),m=(0,v.useRef)(0),k=(0,v.useRef)(e);k.current=e;let M=(0,v.useCallback)(async()=>{try{h.current=!1;let c=await(await fetch(`${J}/graph${n?"?all=1":""}`)).json();c.ok?(u(c),y(""),h.current=!0):(u(null),y(c.error||e("error")))}catch(d){y(String(d&&d.message?d.message:d))}},[n,e]);(0,v.useEffect)(()=>{if(!l||h.current)return;let d=!0;return fetch(`${J}/graph${n?"?all=1":""}`).then(c=>c.json()).then(c=>{d&&(c.ok?(u(c),y(""),h.current=!0):(u(null),y(c.error||e("error"))))}).catch(c=>{d&&y(String(c&&c.message?c.message:c))}),()=>{d=!1}},[n,e,l]),(0,v.useEffect)(()=>{a&&s&&m.current++},[a,s]);let w=(0,v.useCallback)(async d=>{try{let g=await(await fetch(`${J}/delete?path=${encodeURIComponent(d)}`)).json();return g&&g.ok?(await M(),o&&o(),!0):!1}catch{return!1}},[M]),I=(0,v.useCallback)(async d=>{if(!d||d.length<2)return!1;try{let c=await fetch(`${J}/merge?paths=${encodeURIComponent(d.join(","))}`).then(g=>g.json());return c&&c.ok?(await M(),o&&o(),!0):!1}catch{return!1}},[M,o]);return(0,i.jsxs)("div",{className:"me-graph",children:[(0,i.jsx)("style",{children:sn}),f&&(0,i.jsxs)("div",{className:"mc-empty",children:[e("error"),"\uFF1A",f]}),!s&&!f&&(0,i.jsx)("div",{className:"mc-empty",children:e("loading")}),s&&s.nodes.length===0&&(0,i.jsx)("div",{className:"mc-empty",children:e("emptyGraph")}),s&&s.nodes.length>0&&(0,i.jsx)(nh,{nodes:s.nodes,edges:s.edges,onOpen:t,onDelete:w,onMerge:I,t:e,all:n,onAllChange:r,countLabel:`${s.nodes.length} ${e("nodes")} \xB7 ${th(s.edges)} ${e("edges")}`,fitTrigger:m.current})]})}function th(e){let t=new Set;for(let n of e||[])t.add([n.source,n.target].sort().join("|"));return t.size}var Ur={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 nh({nodes:e,edges:t,onOpen:n,onDelete:r,onMerge:o,t:l,countLabel:a,all:s,onAllChange:u,fitTrigger:f}){let y=(0,v.useRef)(null),h=(0,v.useRef)(null),m=(0,v.useRef)(null),k=(0,v.useRef)(null),M=(0,v.useRef)(null),w=(0,v.useRef)(n);(0,v.useEffect)(()=>{w.current=n},[n]);let I=(0,v.useRef)(r);(0,v.useEffect)(()=>{I.current=r},[r]);let d=(0,v.useRef)(o);(0,v.useEffect)(()=>{d.current=o},[o]);let[c,g]=(0,v.useState)(""),[N,P]=(0,v.useState)(null),j=(0,v.useRef)("");(0,v.useEffect)(()=>{j.current=c.trim().toLowerCase()},[c]),(0,v.useEffect)(()=>{let S=m.current;if(!S)return;let x=c.trim().toLowerCase();if(!x)return;let Q=S.nodes.find(ge=>(ge.name||"").toLowerCase().includes(x));Q&&(m.current.selectedId=Q.id,P(Q.id),S.panX=S.w/2-Q.x*S.zoom,S.panY=S.h/2-Q.y*S.zoom,S.render&&S.render())},[c]);let[D,O]=(0,v.useState)("all"),[Y,_]=(0,v.useState)(!1),T=(0,v.useRef)("all"),[K,A]=(0,v.useState)(""),ce=(0,v.useRef)(""),[Z,re]=(0,v.useState)(!1),me=(0,v.useRef)(!1),[z,G]=(0,v.useState)(null);(0,v.useEffect)(()=>{T.current=D},[D]),(0,v.useEffect)(()=>{ce.current=K},[K]),(0,v.useEffect)(()=>{me.current=Z},[Z]);let he=(0,v.useMemo)(()=>{let S=new Map;for(let x of e)for(let Q of x.tags||[]){let ge=String(Q).trim();ge&&S.set(ge,(S.get(ge)||0)+1)}return[...S.entries()].sort((x,Q)=>Q[1]-x[1]).slice(0,24).map(([x,Q])=>({tag:x,n:Q}))},[e]),te=(()=>{let S=c.trim().toLowerCase();return!!S&&!e.some(x=>(x.title||x.name||"").toLowerCase().includes(S)||String(x.kind||"").toLowerCase().includes(S)||String(Ft[x.kind]||"").toLowerCase().includes(S))})();(0,v.useEffect)(()=>{let S=m.current;S&&S.wake&&S.wake()},[c]),(0,v.useEffect)(()=>{let S=m.current;S&&S.render&&S.render()},[D,K,Z]);let pe=(0,v.useRef)(null),[Fe,ht]=(0,v.useState)([]),[Qe,_e]=(0,v.useState)(null),[He,bn]=(0,v.useState)(!1),[un,Gt]=(0,v.useState)(null),[Kn,Sn]=(0,v.useState)(""),ot=(0,v.useRef)(null),yt=(0,v.useRef)(null),xe=(S,x=!0)=>{ot.current&&clearTimeout(ot.current),Gt({msg:S,ok:x}),ot.current=setTimeout(()=>Gt(null),1900)},qt=S=>{Sn(S),yt.current&&clearTimeout(yt.current),yt.current=setTimeout(()=>Sn(""),1600)};(0,v.useEffect)(()=>()=>{ot.current&&clearTimeout(ot.current),yt.current&&clearTimeout(yt.current)},[]);let We=(0,v.useMemo)(()=>e.reduce((S,x)=>(S[x.id]=x,S),{}),[e]);return(0,v.useEffect)(()=>{let S=y.current;if(!S||e.length===0)return;let x=S.getContext("2d");if(!x)return;let Q=Math.max(1,window.devicePixelRatio||1),ge=()=>document.documentElement.getAttribute("data-theme")==="dark",q={};t.forEach(C=>{q[C.source]=(q[C.source]||0)+1,q[C.target]=(q[C.target]||0)+1});let ke=Math.max(1,...Object.values(q)),p={nodes:e.map(C=>({id:C.id,name:C.title||"",type:C.kind||"other",r:9+Math.min(10,(q[C.id]||0)/ke*8),x:0,y:0,vx:0,vy:0})),edges:t.map(C=>({sourceNodeId:C.source,targetNodeId:C.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:Q,ctx:x,multi:[],marquee:null};p.domain=e,p.domainById=e.reduce((C,B)=>(C[B.id]=B,C),{}),p.nodes.forEach((C,B)=>{let F=B/p.nodes.length*Math.PI*2-Math.PI/2;C.x=Math.cos(F)*60,C.y=Math.sin(F)*60});let b=[...new Set(p.nodes.map(C=>C.type))];p.clustered=b.length>1,p.typeCenters={},b.forEach((C,B)=>{let F=B/b.length*Math.PI*2-Math.PI/2;p.typeCenters[C]={x:Math.cos(F)*160,y:Math.sin(F)*160}}),m.current=p;let W=0,U=0,oe=()=>{let C=S.clientWidth,B=S.clientHeight;p.w=C,p.h=B,S.width=C*Q,S.height=B*Q,x.setTransform(Q,0,0,Q,0,0),(W===0||U===0)&&C>0&&B>0&&p.tickCount>0&&requestAnimationFrame(()=>le()),W=C,U=B};oe();let ze=new ResizeObserver(oe);ze.observe(S.parentElement);let ee=(C,B)=>C&&C.length>B?C.slice(0,B)+"\u2026":C,de=(C,B,F,$)=>{if(x.beginPath(),$==="rect")x.rect(C-F,B-F*.75,F*2,F*1.5);else if($==="diamond")x.moveTo(C,B-F),x.lineTo(C+F,B),x.lineTo(C,B+F),x.lineTo(C-F,B),x.closePath();else if($==="hexagon"){for(let X=0;X<6;X++){let ye=Math.PI/3*X-Math.PI/2,ae=C+F*Math.cos(ye),Ye=B+F*Math.sin(ye);X===0?x.moveTo(ae,Ye):x.lineTo(ae,Ye)}x.closePath()}else x.arc(C,B,F,0,Math.PI*2)},L=new Map,V=(C,B)=>{let F=C+"|"+Math.round(B),$=L.get(F);if(!$){let X=parseInt(C.slice(1,3),16),ye=parseInt(C.slice(3,5),16),ae=parseInt(C.slice(5,7),16);$=x.createRadialGradient(-B*.3,-B*.3,0,0,0,B*1.2),$.addColorStop(0,"rgba("+Math.min(255,X+70)+","+Math.min(255,ye+70)+","+Math.min(255,ae+70)+",0.95)"),$.addColorStop(1,C),L.set(F,$)}return $},le=()=>{if(!p.nodes.length)return;let C=1/0,B=-1/0,F=1/0,$=-1/0;p.nodes.forEach(zt=>{C=Math.min(C,zt.x),B=Math.max(B,zt.x),F=Math.min(F,zt.y),$=Math.max($,zt.y)});let X=20,ye=B-C+X*2,ae=$-F+X*2,Ye=Math.min(p.w/ye,p.h/ae);p.zoom=Math.max(.35,Math.min(1.8,Ye)),p.panX=p.w/2-(C+B)/2*p.zoom,p.panY=p.h/2-(F+$)/2*p.zoom};k.current=le;let Ae=()=>{x.clearRect(0,0,p.w,p.h),p.searchTerm=j.current,p.kindFilter=T.current,p.timeMode=me.current,p.tagFilter=ce.current;let C=p.tagFilter,B=p.kindFilter,F=E=>String(E||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");x.save(),x.strokeStyle=ge()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",x.lineWidth=.5;for(let E=0;E<p.w;E+=24)x.beginPath(),x.moveTo(E,0),x.lineTo(E,p.h),x.stroke();for(let E=0;E<p.h;E+=24)x.beginPath(),x.moveTo(0,E),x.lineTo(p.w,E),x.stroke();x.restore(),x.save(),x.translate(p.panX,p.panY),x.scale(p.zoom,p.zoom);let $={};p.nodes.forEach(E=>$[E.id]=E);let X=p.nodes.length>40,ye=X?1.5:.55,ae=p.selectedId||p.hoverId,Ye=Wp({panX:p.panX,panY:p.panY,zoom:p.zoom,w:p.w,h:p.h,margin:80}),zt=(()=>{let E=(p.searchTerm||"").toLowerCase();if(!E)return null;let se=[];for(let ue of p.nodes){let je=(p.domainById[ue.id]||{}).kind||"other";if(((ue.name||"").toLowerCase().includes(E)||String(Ft[je]||"").toLowerCase().includes(E)||String(je).toLowerCase().includes(E))&&se.push(ue.id),se.length>200)break}return se})(),Qn=Up(p.nodes,{limit:$p(p.nodes.length),focusId:ae,hoverId:p.hoverId,searchHits:zt,degree:q}),we=new Map,Me=(E,se)=>{let ue=E+"|"+se,Ce=we.get(ue);return Ce===void 0&&(x.font=E,Ce=x.measureText(se).width,we.set(ue,Ce)),Ce},vt=p.nodes.length<=250,Mt=new Map;p.edges.forEach(E=>{let se=$[E.sourceNodeId],ue=$[E.targetNodeId];if(!se||!ue||!bi(se.x,se.y,10,Ye)&&!bi(ue.x,ue.y,10,Ye))return;if(B!=="all"){let dr=p.domainById[E.sourceNodeId]&&p.domainById[E.sourceNodeId].kind,en=p.domainById[E.targetNodeId]&&p.domainById[E.targetNodeId].kind;if(dr!==B&&en!==B)return}if(C){let dr=p.domainById[E.sourceNodeId]&&(p.domainById[E.sourceNodeId].tags||[]).includes(C),en=p.domainById[E.targetNodeId]&&(p.domainById[E.targetNodeId].tags||[]).includes(C);if(!dr&&!en)return}let Ce=ue.x-se.x,je=ue.y-se.y,ct=Math.sqrt(Ce*Ce+je*je)||1,cn=X?12:18,Cn=-je/ct*cn,Go=Ce/ct*cn,qo=(se.x+ue.x)/2+Cn,Zo=(se.y+ue.y)/2+Go,Yr=Ur.colors[p.domainById[se.id]&&p.domainById[se.id].kind||"other"],Xr=ae&&(E.sourceNodeId===ae||E.targetNodeId===ae),Ci=ae?Xr?.6:.08:X?.14:.24,Jt=parseInt(Yr.slice(1,3),16),Gr=parseInt(Yr.slice(3,5),16),Ni=parseInt(Yr.slice(5,7),16),Ht=Xr?1.6+(E.weight||1):.8+(E.weight||1)*.5,Yn=Jt+","+Gr+","+Ni+","+Ci+","+Ht,Tt=Mt.get(Yn);Tt||(Tt={path:new Path2D,stroke:"rgba("+Jt+","+Gr+","+Ni+","+Ci+")",width:Ht},Mt.set(Yn,Tt)),Tt.path.moveTo(se.x,se.y),Tt.path.quadraticCurveTo(qo,Zo,ue.x,ue.y)}),Mt.forEach(E=>{x.strokeStyle=E.stroke,x.lineWidth=E.width,x.stroke(E.path)});let xt=null;ae&&(xt=new Set,p.edges.forEach(E=>{E.sourceNodeId===ae?xt.add(E.targetNodeId):E.targetNodeId===ae&&xt.add(E.sourceNodeId)}));let Zt=[];if(p.nodes.forEach(E=>{if(!bi(E.x,E.y,E.r+2,Ye))return;let se=p.domainById[E.id]||{},ue=se.kind||"other",Ce=p.timeMode?rh(se.updated):Ur.colors[ue],je=Ur.shapes[ue],ct=p.selectedId===E.id,cn=p.hoverId===E.id,Cn=p.searchTerm||"",Go=!Cn||(E.name||"").toLowerCase().includes(Cn)||String(Ft[ue]||"").toLowerCase().includes(Cn)||String(ue).toLowerCase().includes(Cn),qo=B==="all"||ue===B,Zo=!C||(se.tags||[]).includes(C),Yr=ae&&E.id!==ae&&!(xt&&xt.has(E.id))||Cn&&!Go||!qo||!Zo;x.save(),x.globalAlpha=Yr?.08:1,(ct||cn)&&vt&&(x.shadowColor=Ce,x.shadowBlur=ct?20:14),x.translate(E.x,E.y),de(0,0,E.r,je),x.fillStyle=V(Ce,E.r),x.fill(),x.restore(),ct?(x.save(),de(E.x,E.y,E.r+3,je),x.strokeStyle=Ce,x.lineWidth=3,x.shadowColor=Ce,x.shadowBlur=12,x.stroke(),x.restore()):cn?(x.save(),de(E.x,E.y,E.r+2,je),x.strokeStyle=Ce,x.lineWidth=2,x.stroke(),x.restore()):Cn&&Go?(x.save(),de(E.x,E.y,E.r+2,je),x.strokeStyle="#e11d48",x.lineWidth=2,x.stroke(),x.restore()):p.multi.indexOf(E.id)>=0&&(x.save(),de(E.x,E.y,E.r+2,je),x.strokeStyle="#60a5fa",x.lineWidth=2,x.shadowColor="#60a5fa",x.shadowBlur=8,x.stroke(),x.restore());let Xr=ee(E.name,16);if((ct||cn||Qn.has(E.id)&&p.zoom>ye||!X&&p.zoom>.6)&&qo&&Zo){let Jt=1/p.zoom,Gr="500 "+(12*Jt).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";x.font=Gr;let Ht=Me(Gr,Xr)+16*Jt,Yn=18*Jt,Tt=E.y+E.r+8*Jt,dr=!0;for(let en of Zt)if(E.x-Ht/2<en.x+en.w&&E.x+Ht/2>en.x&&Tt<en.y+en.h&&Tt+Yn>en.y){dr=!1;break}if(!dr&&!ct&&!cn)return;Zt.push({x:E.x-Ht/2,y:Tt,w:Ht,h:Yn}),x.fillStyle=ge()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",x.beginPath(),x.roundRect?x.roundRect(E.x-Ht/2,Tt,Ht,Yn,4*Jt):x.rect(E.x-Ht/2,Tt,Ht,Yn),x.fill(),x.strokeStyle=ge()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",x.lineWidth=1*Jt,x.stroke(),x.fillStyle=ge()?ct||cn?"#eee":"#bbb":ct||cn?"#111":"#444",x.textAlign="center",x.fillText(Xr,E.x,Tt+13*Jt)}}),x.restore(),p.marquee){let E=p.marquee,se=Math.min(E.sx,E.ex),ue=Math.min(E.sy,E.ey),Ce=Math.abs(E.ex-E.sx),je=Math.abs(E.ey-E.sy);x.save(),x.setLineDash([4,4]),x.strokeStyle="rgba(96,165,250,0.9)",x.lineWidth=1,x.fillStyle="rgba(96,165,250,0.12)",x.fillRect(se,ue,Ce,je),x.strokeRect(se,ue,Ce,je),x.restore()}if(p.hoverId&&pe.current){let E=p.domainById[p.hoverId],se=p.nodes.find(function(ue){return ue.id===p.hoverId});if(E&&se){let ue=p.edges.filter(function(ct){return ct.sourceNodeId===E.id||ct.targetNodeId===E.id}).length,Ce=se.x*p.zoom+p.panX,je=se.y*p.zoom+p.panY;pe.current.style.display="block",pe.current.style.left=Ce+14+"px",pe.current.style.top=je-6+"px",pe.current.innerHTML="<b>"+F(E.title||E.name||"")+'</b><br/><span style="opacity:.8">'+F(E.kind||"")+" \xB7 "+tRef.current("connCount").replace("{n}",ue)+"</span>"}}else pe.current&&(pe.current.style.display="none")},ne=()=>{p.running=!0,p.raf||(p.raf=requestAnimationFrame(Ze))};p.wake=ne,p.render=Ae;let Le=()=>{let C=p.nodes.length;p.tickCount++;let F=.9-Math.min(.4,p.tickCount/1500),$=C>1e3?3e3:C>100?2e3:C>50?1200:800,X=C>100?.002:.005,ye=C>1e3?.012:C>100?.005:.01,ae=C>1e3?6:C>200?12:24,Ye={};p.nodes.forEach(we=>Ye[we.id]=we);for(let we=0;we<C;we++){if(p.dragNode===p.nodes[we])continue;let Me=p.nodes[we],vt=0,Mt=0;for(let E=0;E<C;E++){if(we===E)continue;let se=Me.x-p.nodes[E].x,ue=Me.y-p.nodes[E].y,Ce=Math.sqrt(se*se+ue*ue)||1,je=$/(Ce*Ce);vt+=se/Ce*je,Mt+=ue/Ce*je}if(p.clustered&&p.typeCenters[Me.type]){let E=p.typeCenters[Me.type];vt+=(E.x-Me.x)*.006,Mt+=(E.y-Me.y)*.006}else vt-=Me.x*ye,Mt-=Me.y*ye;let xt=(Me.vx+vt)*F,Zt=(Me.vy+Mt)*F;xt=Math.max(-ae,Math.min(ae,xt)),Zt=Math.max(-ae,Math.min(ae,Zt)),Me.vx=xt,Me.vy=Zt}p.edges.forEach(we=>{let Me=Ye[we.sourceNodeId],vt=Ye[we.targetNodeId];if(!Me||!vt)return;let Mt=vt.x-Me.x,xt=vt.y-Me.y,Zt=Math.sqrt(Mt*Mt+xt*xt)||1,E=(Zt-100)*X,se=Mt/Zt*E,ue=xt/Zt*E;p.dragNode!==Me&&(Me.vx+=se,Me.vy+=ue),p.dragNode!==vt&&(vt.vx-=se,vt.vy-=ue)});let zt=0;p.nodes.forEach(we=>{p.dragNode!==we&&(we.x+=we.vx,we.y+=we.vy,zt+=we.vx*we.vx+we.vy*we.vy)}),p.autoFitPending&&p.tickCount>45&&(p.autoFitPending=!1,le()),(C?Math.sqrt(zt/C):0)<.05&&p.tickCount>60&&!p.dragNode?p.quietTicks=(p.quietTicks|0)+1:p.quietTicks=0},Ze=()=>{if(p.running){try{Le(),Ae()}catch{}if(p.quietTicks>30){p.raf=0;return}p.raf=requestAnimationFrame(Ze)}},lt=(C,B)=>{let F=S.getBoundingClientRect();return{x:(C-F.left-p.panX)/p.zoom,y:(B-F.top-p.panY)/p.zoom}},jt=C=>{let B=p.domainById[C];return!(!B||T.current!=="all"&&B.kind!==T.current||ce.current&&!(B.tags||[]).includes(ce.current))},Et=(C,B,F)=>Math.max(B,Math.min(F,C)),Bt=C=>{p.mouseX=C.clientX,p.mouseY=C.clientY;let B=lt(C.clientX,C.clientY),F=null;for(let $=p.nodes.length-1;$>=0;$--){let X=p.nodes[$];if(!jt(X.id))continue;let ye=X.x-B.x,ae=X.y-B.y;if(ye*ye+ae*ae<X.r*X.r+36){F=X.id;break}}F!==p.hoverId&&(p.hoverId=F,ne())},Xo=C=>{if(C.button!==0)return;let B=lt(C.clientX,C.clientY),F=null;for(let $=p.nodes.length-1;$>=0;$--){let X=p.nodes[$];if(!jt(X.id))continue;let ye=X.x-B.x,ae=X.y-B.y;if(ye*ye+ae*ae<X.r*X.r+25){F=X;break}}if(C.shiftKey){if(F){p.shiftClick=F.id;return}p.marquee={sx:C.clientX,sy:C.clientY,ex:C.clientX,ey:C.clientY};return}p.dragStart={x:C.clientX,y:C.clientY,px:p.panX,py:p.panY},p.dragging=!1,p.dragNode=F||null,F&&(p.dragOffset={dx:F.x-B.x,dy:F.y-B.y})},Zs=C=>{if(p.marquee){p.marquee.ex=C.clientX,p.marquee.ey=C.clientY,ne();return}if(!p.dragStart)return;let B=C.clientX-p.dragStart.x,F=C.clientY-p.dragStart.y;if(Math.abs(B)+Math.abs(F)>3&&(p.dragging=!0),p.dragNode){let $=lt(C.clientX,C.clientY);p.dragNode.x=$.x+p.dragOffset.dx,p.dragNode.y=$.y+p.dragOffset.dy,ne()}else p.dragging&&(p.panX=Et(p.dragStart.px+B,-1e5,1e5),p.panY=Et(p.dragStart.py+F,-1e5,1e5),ne())},Js=C=>{if(p.marquee){let F=p.marquee;p.marquee=null;let $=S.getBoundingClientRect(),X=Math.min(F.sx,F.ex)-$.left,ye=Math.max(F.sx,F.ex)-$.left,ae=Math.min(F.sy,F.ey)-$.top,Ye=Math.max(F.sy,F.ey)-$.top,zt=p.nodes.filter(Qn=>{let we=Qn.x*p.zoom+p.panX,Me=Qn.y*p.zoom+p.panY;return we>=X&&we<=ye&&Me>=ae&&Me<=Ye}).map(Qn=>Qn.id);p.multi=zt,ht(zt),ne();return}let B=p.dragStart&&!p.dragging;if(p.shiftClick){let F=p.shiftClick;p.shiftClick=null;let $=Array.isArray(p.multi)?p.multi.slice():[];$.includes(F)||$.push(F),p.multi=$,ht($),ne();return}if(B){let F=lt(C.clientX,C.clientY),$=null;for(let X=p.nodes.length-1;X>=0;X--){let ye=p.nodes[X];if(!jt(ye.id))continue;let ae=ye.x-F.x,Ye=ye.y-F.y;if(ae*ae+Ye*Ye<ye.r*ye.r+20){$=ye;break}}$?(p.selectedId=$.id,P($.id),ne()):(p.selectedId=null,p.hoverId=null,C.shiftKey||(p.multi=[],ht([])),P(null),ne())}p.dragStart=null,p.dragging=!1,p.dragNode=null},eu=C=>{C.preventDefault();let B=lt(C.clientX,C.clientY),F=null;for(let $=p.nodes.length-1;$>=0;$--){let X=p.nodes[$];if(!jt(X.id))continue;let ye=X.x-B.x,ae=X.y-B.y;if(ye*ye+ae*ae<X.r*X.r+25){F=X;break}}if(F){let $=p.domainById[F.id];$&&G({x:C.clientX,y:C.clientY,id:F.id,path:$.id,title:$.title})}else G(null)},tu=C=>{C.preventDefault();let B=S.getBoundingClientRect(),F=(C.clientX-B.left-p.panX)/p.zoom,$=(C.clientY-B.top-p.panY)/p.zoom,X=Math.max(.3,Math.min(3,p.zoom*(C.deltaY<0?1.1:1/1.1)));p.panX=Et(p.panX+F*(p.zoom-X),-1e5,1e5),p.panY=Et(p.panY+$*(p.zoom-X),-1e5,1e5),p.zoom=X,ne()};S.addEventListener("mousemove",Bt),S.addEventListener("mousedown",Xo),window.addEventListener("mousemove",Zs),window.addEventListener("mouseup",Js),S.addEventListener("wheel",tu,{passive:!1}),S.addEventListener("contextmenu",eu),M.current=()=>{p.selectedId=null,p.hoverId=null,p.multi=[],ht([]),le(),ne()};for(let C=0;C<200;C++)Le();le(),ne();let nu=()=>_(!1);return window.addEventListener("mousedown",nu),()=>{p.running=!1,p.raf&&cancelAnimationFrame(p.raf),ze.disconnect(),S.removeEventListener("mousemove",Bt),S.removeEventListener("mousedown",Xo),window.removeEventListener("mousemove",Zs),window.removeEventListener("mouseup",Js),S.removeEventListener("wheel",tu),S.removeEventListener("contextmenu",eu),window.removeEventListener("mousedown",nu)}},[e,t]),(0,v.useEffect)(()=>{f!==void 0&&k.current&&requestAnimationFrame(()=>k.current())},[f]),(0,i.jsxs)("div",{className:"me-graph",ref:h,children:[(0,i.jsxs)("div",{className:"me-graph-toolbar",children:[(0,i.jsxs)("span",{className:"me-graph-count",children:[e.length," ",l("nodes")," \xB7 ",t.length," ",l("edges")]}),(0,i.jsx)("span",{className:"spacer",style:{flex:1}}),(0,i.jsx)("input",{type:"text",placeholder:l("search"),value:c,onChange:S=>g(S.target.value)}),(0,i.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,i.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>_(S=>!S),"aria-expanded":Y,title:l("filterLabel"),style:{borderRadius:8},children:["\u{1F50D} ",l("filterLabel")," ",D!=="all"||Z||K?"\u25CF":"\u25BE"]}),Y&&(0,i.jsx)("div",{className:"me-graph-legend-pop",onMouseDown:S=>S.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,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,i.jsx)("button",{type:"button",className:`lg${D==="all"&&!Z?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>{O("all"),re(!1)},children:l("all")}),Object.keys(At).map(S=>(0,i.jsxs)("button",{type:"button",className:`lg${D===S?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>O(x=>x===S?"all":S),children:[(0,i.jsx)("span",{className:"mc-kind",style:{background:Ur.colors[S]||At[S]}}),l(Ft[S])]},S)),(0,i.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,i.jsxs)("button",{type:"button",className:`lg${Z?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>re(S=>!S),children:["\u23F1 ",l("timeDim")]}),he.length>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,i.jsx)("div",{style:{maxHeight:130,overflow:"auto",display:"flex",flexWrap:"wrap",gap:4},children:he.map(S=>(0,i.jsxs)("button",{type:"button",className:`lg${K===S.tag?" active":""}`,style:{color:"#ddd",padding:"2px 7px",fontSize:11},onClick:()=>A(x=>x===S.tag?"":S.tag),title:S.tag,children:["#",S.tag," ",(0,i.jsx)("span",{style:{opacity:.55},children:S.n})]},S.tag))})]}),(D!=="all"||Z||K)&&(0,i.jsxs)("button",{type:"button",className:"lg lg-clear",style:{justifyContent:"flex-start",color:"#f87171"},onClick:()=>{O("all"),re(!1),A("")},children:[l("clearFilter")," \u2715"]})]})})]}),(0,i.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:l("crossVault"),children:[(0,i.jsx)("input",{type:"checkbox",checked:!!s,onChange:S=>u&&u(S.target.checked)}),l("crossVault")]}),(0,i.jsx)("button",{type:"button",className:`mc-btn${Z?" me-on":""}`,onClick:()=>re(S=>!S),children:l("timeDim")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let S=y.current;if(S)try{S.toBlob(x=>{x&&_e({url:URL.createObjectURL(x),blob:x})},"image/png")}catch{}},children:l("exportGraph")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>k.current&&k.current(),children:l("fit")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{P(null),O("all"),M.current&&M.current()},children:l("reset")})]}),(0,i.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,i.jsx)("canvas",{ref:y,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,i.jsx)("div",{className:"me-graph-tooltip",ref:pe,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)"}}),te&&(0,i.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:l("noMatch")}),z&&(0,i.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>G(null)}),z&&(0,i.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:z.x,top:z.y,zIndex:31},onMouseDown:S=>S.stopPropagation(),children:[(0,i.jsx)("button",{type:"button",onClick:()=>{w.current({path:z.path,title:z.title}),G(null)},children:l("openCard")}),(0,i.jsx)("button",{type:"button",onClick:()=>{z.id&&(m.current.selectedId=z.id,P(z.id)),G(null);let S=m.current;S&&S.wake&&S.wake()},children:l("focusNeighbors")}),(0,i.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(z.title||"")}catch{}G(null),xe(l("copied"))},children:l("copyName")}),(0,i.jsx)("button",{type:"button",onClick:()=>{let S=m.current,x=S&&Array.isArray(S.multi)?S.multi.slice():[],Q=z.id;if(Q&&!x.includes(Q)&&x.push(Q),G(null),x.length<2){xe(l("mergeNeed"),!1);return}if(!window.confirm(l("mergeConfirm")))return;let ge=d.current&&d.current(x);ge&&ge.then?ge.then(q=>q?xe(l("merged")):xe(l("mergeFail"),!1)).catch(()=>xe(l("mergeFail"),!1)):ge&&xe(l("merged"))},children:l("merge")}),(0,i.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let S=z.path;G(null),window.confirm(l("deleteConfirm"))&&(async()=>{try{(I.current?await I.current(S):!1)?xe(l("deleted")):xe(l("deleteFail"),!1)}catch{xe(l("deleteFail"),!1)}})()},children:l("delete")})]}),Fe.length>0&&(0,i.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,i.jsxs)("span",{style:{fontWeight:700},children:[Fe.length," ",l("nodes")]}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let x=Fe.map(ke=>We[ke]).filter(Boolean).map(ke=>ke.title||ke.name).join(`
309
309
  `),Q=new Blob([x],{type:"text/plain;charset=utf-8"}),ge=URL.createObjectURL(Q),q=document.createElement("a");q.href=ge,q.download="memory-selected.txt",document.body.appendChild(q),q.click(),document.body.removeChild(q),setTimeout(()=>URL.revokeObjectURL(ge),1e3),xe(Fe.length+l("exportedSel"))},children:l("exportSel")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(Fe.length<2){xe(l("mergeNeed"),!1);return}let S=Fe.map(Q=>We[Q]?We[Q].id:Q);if(!window.confirm(l("mergeConfirm")))return;ht([]);let x=m.current;x&&(x.multi=[]),fetch(`${J}/merge?paths=${encodeURIComponent(S.join(","))}`).then(Q=>Q.json()).then(Q=>{Q&&Q.ok?xe(l("merged")):xe(l("mergeFail"),!1)}).catch(()=>xe(l("mergeFail"),!1))},children:l("merge")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(l("deleteConfirm")))return;let S=Fe.map(Q=>We[Q]?We[Q].id:Q);ht([]);let x=m.current;x&&(x.multi=[]),(async()=>{let Q=0;for(let ge of S)try{(I.current?await I.current(ge):!1)&&Q++}catch{}xe(Q+l("deletedSelected"),Q>0)})()},children:l("deleteSelected")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let S=m.current;S&&(S.multi=[]),ht([]);let x=m.current;x&&x.render&&x.render()},children:l("clearSelection")})]}),N&&(0,i.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,i.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:We[N]?We[N].title||We[N].name:N}),(0,i.jsx)("div",{style:{opacity:.8,marginBottom:8},children:We[N]?l(Ft[We[N].kind]||"kindKnowledge"):"\u2014"}),(0,i.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:l("graphHint")}),(t.filter(S=>S.source===N||S.target===N)||[]).slice(0,8).map((S,x)=>{let Q=S.source===N?S.target:S.source,ge=We[Q];return(0,i.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:q=>{q.preventDefault();let ke=m.current;ke&&(ke.selectedId=Q,ke.hoverId=Q,ke.wake&&ke.wake()),P(Q)},children:ge?(ge.title||ge.name).slice(0,28):Q},x)})]})]}),(0,i.jsx)("div",{className:"me-graph-tip",children:l("graphTip")}),un&&(0,i.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 "+(un.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,i.jsx)("span",{style:{color:un.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:un.ok?"\u2713":"\u2715"}),(0,i.jsx)("span",{style:{wordBreak:"break-all"},children:un.msg})]}),Qe&&(0,i.jsxs)("div",{className:"me-overlay",onClick:()=>{Qe.url&&URL.revokeObjectURL(Qe.url),_e(null),bn(!1)},children:[(0,i.jsx)("style",{children:sn}),(0,i.jsxs)("div",{className:"me-dialog",style:{maxWidth:He?"100vw":900,width:He?"100vw":"92vw",maxHeight:He?"100%":"90vh",height:He?"100%":void 0,borderRadius:He?0:14},onClick:S=>S.stopPropagation(),children:[(0,i.jsxs)("div",{className:"me-dialog-head",children:[(0,i.jsx)("h3",{children:l("exportGraph")}),(0,i.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,i.jsx)("a",{className:"mc-btn",href:Qe.url,download:"memory-graph.png",onClick:()=>{qt("download"),xe(l("downloaded")+" \xB7 "+l("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:l(Kn==="download"?"done":"download")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{qt("full"),bn(S=>!S),xe(l("fullscreen"))},children:l(Kn==="full"?"done":He?"exitFull":"fullscreen")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let S=Qe.blob;S&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":S})]).then(()=>{qt("copy"),xe(l("copied"))}).catch(()=>{xe(l("copyFail"),!1)}):xe(l("copyFail"),!1)},children:l(Kn==="copy"?"done":"copyImage")}),(0,i.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Qe.url&&URL.revokeObjectURL(Qe.url),_e(null),bn(!1)},children:l("close")})]})]}),(0,i.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:He?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,i.jsx)("img",{src:Qe.url,alt:l("exportGraph"),style:{maxWidth:"100%",maxHeight:He?"calc(100% - 64px)":"70vh",borderRadius:He?0:8,cursor:"zoom-in"},onClick:()=>bn(S=>!S)})})]})]})]})}function rh(e){let t=new Date(e||0).getTime();if(!t)return"#94a3b8";let n=(Date.now()-t)/864e5;return n<3?"#10b981":n<14?"#f59e0b":n<30?"#f97316":"#94a3b8"}function Gp({label:e,value:t=[],options:n,onChange:r,placeholder:o,z:l=20}){let[a,s]=(0,v.useState)(!1),u=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(!a)return;let w=I=>{u.current&&!u.current.contains(I.target)&&s(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[a]);let f=Array.isArray(t)?t:[],y=f.includes("__all__"),h=y?n.find(w=>w.value==="__all__")?.label||"":f.length?f.map(w=>n.find(I=>I.value===w)?.label||w).join("\u3001"):"",m=(w,I)=>{if(w.value==="__all__"){r(I?["__all__"]:[]);return}let d=new Set(f);d.has("__all__")&&d.delete("__all__"),I?d.add(w.value):d.delete(w.value),r([...d])},k=n.find(w=>w.value==="__all__"),M=n.filter(w=>w.value!=="__all__");return(0,i.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:12,minWidth:0},children:[(0,i.jsx)("span",{style:{opacity:.6,whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.5},children:e}),(0,i.jsxs)("div",{ref:u,style:{position:"relative",minWidth:0},children:[(0,i.jsxs)("button",{type:"button",onClick:()=>s(w=>!w),style:{width:"100%",textAlign:"left",padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[(0,i.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h||o||"\u2014"}),(0,i.jsx)("span",{style:{fontSize:10,opacity:.7},children:"\u25BE"})]}),a&&(0,i.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,right:0,zIndex:l,marginTop:2,borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",boxShadow:"0 6px 20px rgba(0,0,0,0.14)",maxHeight:180,overflow:"auto"},children:[k&&(0,i.jsxs)("label",{onClick:w=>w.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,i.jsx)("input",{type:"checkbox",checked:y,onChange:w=>m(k,w.target.checked)}),(0,i.jsx)("span",{children:k.label})]}),M.map(w=>(0,i.jsxs)("label",{onClick:I=>I.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer"},children:[(0,i.jsx)("input",{type:"checkbox",checked:f.includes(w.value),onChange:I=>m(w,I.target.checked)}),(0,i.jsx)("span",{children:w.label})]},w.value))]})]})]})}function oh(e){let t=new Date(e||0).getTime();return!!t&&(Date.now()-t)/864e5<3}async function lh(e,t,n){if(n&&typeof window.showSaveFilePicker=="function")try{let l=await window.showSaveFilePicker({suggestedName:t}),a=await l.createWritable();return await a.write(e),await a.close(),{ok:!0,picked:!0,name:l.name}}catch(l){return l&&l.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(l.message||l)}}let r=URL.createObjectURL(e),o=document.createElement("a");return o.href=r,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>URL.revokeObjectURL(r),1e3),{ok:!0,picked:!1,name:t}}function qp(e,t){if(!t||!e)return e;let n=e.toLowerCase(),r=t.toLowerCase(),o=[],l=0;for(;l<e.length;){let a=n.indexOf(r,l);if(a<0){o.push(e.slice(l));break}a>l&&o.push(e.slice(l,a)),o.push((0,i.jsx)("mark",{className:"mc-hl",children:e.slice(a,a+r.length)},a)),l=a+r.length}return o}function Vr(e){if(!e)return"";let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let n=new Date,r=t.toDateString()===n.toDateString(),o=a=>String(a).padStart(2,"0"),l=`${o(t.getHours())}:${o(t.getMinutes())}`;return r?l:`${t.getMonth()+1}-${t.getDate()} ${l}`}var qs=Xn(Vo(),1);function ih(){try{let e=new URLSearchParams(window.location.search).get("lang");if(e==="zh"||e==="en")return e}catch{}return typeof navigator<"u"&&String(navigator.language||"").toLowerCase().startsWith("zh")?"zh":"en"}function ah(){let[e,t]=(0,Qr.useState)(ih);(0,Qr.useEffect)(()=>{let r=o=>{let l=o&&o.data;l&&l.source==="memory-eternal"&&l.type==="locale"&&(l.lang==="zh"||l.lang==="en")&&t(l.lang)};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[]);let n=(0,Qr.useMemo)(()=>r=>(e==="zh"?Xs:Zp)[r]??Xs[r]??r,[e]);return document.documentElement.lang=e==="zh"?"zh-CN":"en",(0,qs.jsx)(ef,{t:n,inModal:!1})}var sh=(0,nf.createRoot)(document.getElementById("root"));sh.render((0,qs.jsx)(ah,{}));})();
310
310
  /*! Bundled license information: