memory-eternal 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,186 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "memory-eternal",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ var It=Object.create;var at=Object.defineProperty;var Lt=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var Bt=Object.getPrototypeOf,Dt=Object.prototype.hasOwnProperty;var Rt=(t,l)=>{for(var d in l)at(t,d,{get:l[d],enumerable:!0})},ht=(t,l,d,x)=>{if(l&&typeof l=="object"||typeof l=="function")for(let g of Tt(l))!Dt.call(t,g)&&g!==d&&at(t,g,{get:()=>l[g],enumerable:!(x=Lt(l,g))||x.enumerable});return t};var At=(t,l,d)=>(d=t!=null?It(Bt(t)):{},ht(l||!t||!t.__esModule?at(d,"default",{value:t,enumerable:!0}):d,t)),jt=t=>ht(at({},"__esModule",{value:!0}),t);var aa={};Rt(aa,{EN:()=>Ct,MemoryLibrary:()=>_t,ZH:()=>kt,apply:()=>Et,inject:()=>Ft});module.exports=jt(aa);var i=At(require("react"),1),e=require("react/jsx-runtime"),We="memory-eternal",j="/memory-eternal/api",Ft=["settingsScope","slots","locale","connection","remote"],kt={nav:"\u8BB0\u5FC6",loading:"\u52A0\u8F7D\u4E2D\u2026",refresh:"\u5237\u65B0",overview:"\u8BB0\u5FC6\u5E93\u6982\u89C8",total:"\u77E5\u8BC6\u5361",recent:"\u8FD1 7 \u5929\u65B0\u589E",tags:"\u6807\u7B7E",searchPlaceholder:"\u641C\u7D22\u8BB0\u5FC6\uFF08\u652F\u6301\u4E2D\u6587\u7247\u6BB5\uFF09\u2026",search:"\u641C\u7D22",all:"\u5168\u90E8",kindProject:"\u9879\u76EE",kindKnowledge:"\u77E5\u8BC6",kindContent:"\u5185\u5BB9",kindPrompt:"\u63D0\u793A\u8BCD",kindBusiness:"\u4E1A\u52A1",kindTool:"\u5DE5\u5177",kindMistake:"\u6559\u8BAD",cardsTab:"\u77E5\u8BC6\u5361",graphTab:"\u77E5\u8BC6\u56FE\u8C31",graph:"\u77E5\u8BC6\u56FE\u8C31",graphHint:"\u8282\u70B9=\u77E5\u8BC6\u5361\uFF1B\u8FDE\u7EBF=[[\u94FE\u63A5]] \u6216\u5171\u4EAB\u6807\u7B7E\u3002\u70B9\u51FB\u8282\u70B9\u9605\u8BFB\u5361\u7247\u3002",graphTip:"\u5DE6\u952E\u51F8\u663E \xB7 Shift+\u62D6\u62FD\u6846\u9009 \xB7 \u53F3\u952E\u83DC\u5355 \xB7 \u6EDA\u8F6E\u7F29\u653E \xB7 \u62D6\u62FD\u5E73\u79FB",rebuild:"\u91CD\u5EFA",reset:"\u91CD\u7F6E",expandAll:"\u5168\u90E8\u5C55\u5F00",capped:"\u5DF2\u5C55\u793A\u6700\u6838\u5FC3\u7684",clearFocus:"\u53D6\u6D88\u9AD8\u4EAE",empty:"\u8BB0\u5FC6\u5E93\u8FD8\u662F\u7A7A\u7684\u3002\u591A\u804A\u51E0\u8F6E\u540E\uFF0C\u503C\u5F97\u4FDD\u5B58\u7684\u5185\u5BB9\u4F1A\u81EA\u52A8\u6C89\u6DC0\u6210\u77E5\u8BC6\u5361\u3002",emptyGraph:"\u56FE\u8C31\u6682\u65E0\u6570\u636E\u3002",open:"\u9605\u8BFB",updated:"\u66F4\u65B0\u4E8E",created:"\u521B\u5EFA\u4E8E",source:"\u6765\u6E90",close:"\u5173\u95ED",vaultDir:"\u8BB0\u5FC6\u5E93\u76EE\u5F55",capture:"\u81EA\u52A8\u6C89\u6DC0",recall:"\u81EA\u52A8\u53EC\u56DE",enabled:"\u5DF2\u542F\u7528",disabled:"\u5DF2\u7981\u7528",error:"\u52A0\u8F7D\u5931\u8D25",back:"\u8FD4\u56DE\u5217\u8868",cardCount:"\u5F20\u5361",nodes:"\u8282\u70B9",edges:"\u8FDE\u7EBF",memoryTitle:"\u8BB0\u5FC6\u5E93",memoryHint:"\u4F60\u7684\u672C\u5730\u7B2C\u4E8C\u5927\u8111",zoomIn:"\u653E\u5927",zoomOut:"\u7F29\u5C0F",fit:"\u9002\u5E94",enterFullscreen:"\u5168\u5C4F",exitFullscreen:"\u9000\u51FA\u5168\u5C4F",exportGraph:"\u5BFC\u51FA",openCard:"\u6253\u5F00\u5361\u7247",focusNeighbors:"\u51F8\u663E\u5173\u8054",copyName:"\u590D\u5236\u540D\u79F0",noMatch:"\u6CA1\u6709\u5339\u914D\u7684\u8BB0\u5FC6",clearFilter:"\u6E05\u9664\u8FC7\u6EE4",filterLabel:"\u7B5B\u9009",sortRecent:"\u6700\u8FD1",sortTitle:"\u6807\u9898",sortHot:"\u70ED\u70B9",exportSel:"\u5BFC\u51FA\u9009\u4E2D",clearSelection:"\u6E05\u7A7A\u9009\u62E9",download:"\u4E0B\u8F7D",openNewTab:"\u65B0\u6807\u7B7E\u6253\u5F00",copyImage:"\u590D\u5236\u56FE\u7247",done:"\u5B8C\u6210",downloaded:"\u5DF2\u5F00\u59CB\u4E0B\u8F7D",openedTab:"\u5DF2\u5728\u65B0\u6807\u7B7E\u6253\u5F00",copied:"\u5DF2\u590D\u5236",exportedSel:"\u4E2A\u8282\u70B9\u5DF2\u5BFC\u51FA",fullscreen:"\u5168\u5C4F",exitFull:"\u9000\u51FA\u5168\u5C4F",copyFail:"\u590D\u5236\u5931\u8D25",timeDim:"\u65F6\u95F4\u7EF4",timeNew:"3 \u5929\u5185",timeRecent:"2 \u5468\u5185",timeMonth:"1 \u6708\u5185",timeOld:"\u66F4\u65E9",newBadge:"\u65B0",expand:"\u5C55\u5F00\u5168\u90E8",collapse:"\u6536\u8D77",exportVault:"\u5BFC\u51FAMD",exportJson:"\u5BFC\u51FAJSON",exporting:"\u5BFC\u51FA\u4E2D\u2026",exportedVault:"\u8BB0\u5FC6\u5E93\u5DF2\u5BFC\u51FA",exportFail:"\u5BFC\u51FA\u5931\u8D25",importVault:"\u5BFC\u5165",importedVault:"\u5BFC\u5165\u5B8C\u6210",importedSkipped:"\uFF08\u8DF3\u8FC7\u91CD\u590D ",importFail:"\u5BFC\u5165\u5931\u8D25",location:"\u81EA\u9009\u4F4D\u7F6E",saveAs:"\u53E6\u5B58\u4E3A",saveAsUnsupported:"\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u9009\u62E9\u4FDD\u5B58\u4F4D\u7F6E",exportedTo:"\u5DF2\u5BFC\u51FA\u5230",defaultDownloads:"\u9ED8\u8BA4\u4E0B\u8F7D\u6587\u4EF6\u5939",exportCancel:"\u5DF2\u53D6\u6D88\u5BFC\u51FA",manage:"\u7BA1\u7406",tabUsage:"\u7528\u91CF/\u4ECA\u65E5",tabOptimize:"\u6574\u7406\u5EFA\u8BAE",adminLoadFail:"\u6570\u636E\u52A0\u8F7D\u5931\u8D25\uFF1A\u8BF7\u5F7B\u5E95\u91CD\u542F dsh-desktop\uFF08host \u9700\u52A0\u8F7D\u65B0\u7248 /memory-eternal \u8DEF\u7531\uFF09",retry:"\u91CD\u8BD5",mergeSimilar:"\u4E00\u952E\u5408\u5E76\u76F8\u4F3C",trendLabel:"\u8FD1 30 \u5929\u8D8B\u52BF",cleanStale:"\u{1F5D1}\uFE0F \u4E00\u952E\u6E05\u7406\u9648\u65E7",deletedStale:"\u4E2A\u9648\u65E7\u5361\u5DF2\u6E05\u7406",newCard:"\u65B0\u5EFA",tplDecision:"\u{1F4DD} \u6280\u672F\u51B3\u7B56",tplBug:"\u{1F41B} \u8E29\u5751",tplMeeting:"\u{1F4CB} \u4F1A\u8BAE\u7EAA\u8981",tplWeekly:"\u{1F4CA} \u5468\u62A5",createCard:"\u521B\u5EFA",cardTitle:"\u6807\u9898",cardBody:"\u6B63\u6587",fbUseful:"\u6709\u7528",fbIrr:"\u65E0\u5173",todayAdd:"\u4ECA\u65E5\u65B0\u589E",weekAdd:"\u8FD1 7 \u5929",byKind:"\u5206\u7C7B\u7EDF\u8BA1",todayList:"\u4ECA\u65E5\u6C89\u6DC0",budgetLabel:"\u4F1A\u8BDD\u9884\u7B97",budgetChars:"\u9884\u7B97\u5B57\u7B26",recallLimitLabel:"\u53EC\u56DE\u6761\u6570",embeddingLabel:"\u8BED\u4E49\u53EC\u56DE",mergePairs:"\u76F8\u4F3C\u5361\u5BF9\uFF08\u53EF\u5408\u5E76\uFF09",staleCards:"\u9648\u65E7\u5361\uFF08>90 \u5929\u672A\u66F4\u65B0\uFF09",noOptimize:"\u6682\u65E0\u53EF\u6574\u7406\u9879\uFF0C\u5F88\u5065\u5EB7 \u{1F389}",oneClickOptimize:"\u4E00\u952E\u4F18\u5316",oneClickOptimizeConfirm:"\u786E\u8BA4\u4E00\u952E\u4F18\u5316\uFF1F\u5C06\u5408\u5E76\u6240\u6709\u76F8\u4F3C\u5361\u5BF9\uFF08\u9ED8\u8BA4\u4E0D\u6E05\u7406\u9648\u65E7\u5361\uFF09\u3002",oneClickAlsoStale:"\u540C\u65F6\u6E05\u7406\u9648\u65E7\u5361",oneClickOptimizeDone:"\u4E00\u952E\u4F18\u5316\u5B8C\u6210",optimizedMerged:"\u5BF9\u5DF2\u5408\u5E76",optimizedStaleDeleted:"\u5F20\u9648\u65E7\u5361\u5DF2\u6E05\u7406",mcpSetupStatus:"Agent MCP \u6302\u8F7D\u72B6\u6001",rerunSetup:"\u8865\u5168 MCP",notInstalled:"\u672A\u5B89\u88C5",noMcpEntry:"\u914D\u7F6E\u7F3A\u5931",nodePathMismatch:"node \u8DEF\u5F84\u4E0D\u4E00\u81F4\uFF0C\u5EFA\u8BAE\u91CD\u8DD1 setup",nodePathNote:"node \u73AF\u5883\u4E0D\u540C\uFF08\u53EF\u7528\uFF09",healthy:"\u914D\u7F6E\u6B63\u5E38",mcpSetupHint:"\u300C\u81EA\u52A8\u6302\u8F7D MCP\u300D= \u8BA9 Claude Code / Codex / Cursor \u8FD9\u4E9B\u5DE5\u5177\u80FD\u8C03\u7528\u8BB0\u5FC6\u5E93\u3002\u5F00\u542F\u540E\u81EA\u52A8\u628A\u5B83\u4EEC\u914D\u7F6E\u597D\uFF1B\u5173\u6389\u5C31\u4E0D\u52A8\u4F60\u7535\u8111\u4E0A\u4EFB\u4F55\u914D\u7F6E\u6587\u4EF6\uFF0C\u9700\u8981\u65F6\u624B\u52A8\u8DD1 dsh-memory setup\u3002",mcpManageHint:"\u6BCF\u4E2A agent \u7528\u4E0B\u65B9\u6309\u94AE\u5355\u72EC\u5B89\u88C5/\u5378\u8F7D MCP",tabConfig:"\u8BB0\u5FC6\u914D\u7F6E",tabAudit:"\u5BA1\u6838\u4E2D\u5FC3",statusApproved:"\u5DF2\u5BA1\u6838",statusPending:"\u5F85\u5BA1\u6838",statusRejected:"\u5DF2\u9A73\u56DE",allStatus:"\u5168\u90E8\u72B6\u6001",tabRecycle:"\u56DE\u6536\u4E2D\u5FC3",pending:"\u5F85\u5BA1\u6838",rejected:"\u5DF2\u9A73\u56DE",selectAll:"\u5168\u9009",approve:"\u6279\u51C6",reject:"\u9A73\u56DE",allAgents:"\u5168\u90E8\u667A\u80FD\u4F53",noAuditItems:"\u6682\u65E0\u5BA1\u6838\u9879\u76EE",deletedAt:"\u5220\u9664\u4E8E",restore:"\u6062\u590D",restoreDelete:"\u5220\u9664\u8FDB\u56DE\u6536\u7AD9",purge:"\u6C38\u4E45\u5220\u9664",emptyRecycle:"\u56DE\u6536\u7AD9\u4E3A\u7A7A",recycleHint:"\u5220\u9664\u7684\u5361\u7247\u5148\u8FDB\u56DE\u6536\u7AD9\uFF0C30 \u5929\u5185\u53EF\u6062\u590D\uFF0C\u8D85\u671F\u81EA\u52A8\u6C38\u4E45\u5220\u9664",purgeConfirm:"\u786E\u5B9A\u6C38\u4E45\u5220\u9664\uFF1F\u4E0D\u53EF\u6062\u590D\u3002",recycleDeleteConfirm:"\u786E\u5B9A\u5220\u9664\u8FDB\u56DE\u6536\u7AD9\uFF1F30 \u5929\u5185\u53EF\u6062\u590D\u3002",modeInit:"\u542F\u52A8\u65F6\u62C9\u4E00\u6B21",modeInterval:"\u5468\u671F\u4FDD\u6D3B",modeManual:"\u4EC5\u624B\u52A8",serviceConfig:"\u670D\u52A1\u81EA\u7BA1\u7406\u914D\u7F6E",auditConfig:"\u81EA\u52A8\u5BA1\u6838\u914D\u7F6E",auditHint:"\u547D\u4E2D\u514D\u5BA1\u7684\u65B0\u5361\u76F4\u63A5\u5165\u5E93\uFF0C\u5176\u4F59\u8FDB\u5F85\u5BA1\u6838",auditMode:"\u5BA1\u6838\u6A21\u5F0F",auditAll:"\u5168\u90E8\u8981\u5BA1\u6838",auditNone:"\u5168\u90E8\u514D\u5BA1",auditExemptAgents:"\u514D\u5BA1\u667A\u80FD\u4F53",auditExemptKinds:"\u514D\u5BA1\u7C7B\u578B",allExempt:"\u5168\u90E8\u514D\u5BA1",recycleDays:"\u56DE\u6536\u4FDD\u7559\u5929\u6570",editInSetting:"\u7F16\u8F91\u8BF7\u5230 DSH \u8BBE\u7F6E \u2192 \u8BB0\u5FC6",setupRunInTerminal:"\u8BF7\u590D\u5236\u4EE5\u4E0B\u547D\u4EE4\u5230\u7EC8\u7AEF\u6267\u884C\uFF1A",dshMemoryConfig:"DSH \u8BB0\u5FC6\u914D\u7F6E",autoCapture:"\u81EA\u52A8\u6C89\u6DC0",autoRecall:"\u81EA\u52A8\u53EC\u56DE",captureMinChars:"\u6355\u83B7\u6700\u5C0F\u957F\u5EA6",maxCardsPerDay:"\u65E5\u914D\u989D",dedupThreshold:"\u53BB\u91CD\u9608\u503C",recallLimit:"\u53EC\u56DE\u6761\u6570",recallSummaryLen:"\u53EC\u56DE\u6458\u8981\u957F\u5EA6",recallBody:"\u53EC\u56DE\u542B\u6B63\u6587",autoWeb:"Web server",autoWebMode:"\u4FDD\u6D3B\u6A21\u5F0F",webPort:"Web \u7AEF\u53E3",webCheckIntervalMs:"\u63A2\u6D3B\u95F4\u9694(ms)",webMaxRestart:"\u6700\u5927\u91CD\u542F\u6B21\u6570",watchdogAutoSpawn:"\u770B\u95E8\u72D7\u8FDB\u7A0B",autoMcpSetup:"\u81EA\u52A8\u6302\u8F7D MCP",saveConfig:"\u4FDD\u5B58\u914D\u7F6E",saveFail:"\u4FDD\u5B58\u5931\u8D25",savedOk:"\u5DF2\u4FDD\u5B58",recallTool:"recall \u5DE5\u5177",costControl:"\u6210\u672C\u63A7\u5236",costHint:"\u7701 token\u3001\u63A7 LLM \u6D88\u8017",distillEnabled:"\u84B8\u998F\u77E5\u8BC6\u5361(\u5F00=LLM \u538B\u7F29, \u5173=\u539F\u6587\u5361\u96F6 LLM)",dedupByLLM:"\u8BED\u4E49\u53BB\u91CD\u5582 LLM(\u5173=\u7EAF\u8BCD\u6CD5\u66F4\u7701)",captureMaxTokens:"\u84B8\u998F\u8F93\u51FA\u4E0A\u9650(token)",recallMinScore:"\u53EC\u56DE\u76F8\u5173\u6027\u9608\u503C(\u8D8A\u9AD8\u8D8A\u7701)",configNeedsDsh:"\u914D\u7F6E\u7F16\u8F91\u9700\u5728 DSH \u5185\u6253\u5F00\uFF08\u672C\u9875\u53EF\u80FD\u53EA\u8BFB\u6216\u6709\u90E8\u5206\u7F3A\u5931\uFF09",installMcp:"\u5B89\u88C5 MCP",uninstallMcp:"\u5378\u8F7D MCP",uninstallConfirm:"\u786E\u8BA4\u5378\u8F7D\u8BE5\u667A\u80FD\u4F53\u7684 MCP\uFF1FClaude Code/Codex \u5C06\u65E0\u6CD5\u518D\u8C03\u7528\u8BB0\u5FC6\u5E93\u3002",presetConfig:"\u4E00\u952E\u63A8\u8350\u914D\u7F6E",presetHint:"\u70B9\u51FB\u586B\u5145\u5BF9\u5E94\u65B9\u6848\uFF0C\u70B9\u4FDD\u5B58\u751F\u6548",planA:"A \u8F7B\u91CF\u7701\u5FC3",planB:"B \u6781\u81F4\u7701\u94B1",planC:"C \u9AD8\u8D28\u91CF",pluginInfo:"\u63D2\u4EF6\u4FE1\u606F",organizeTitle:"\u6574\u7406\u5EFA\u8BAE",scanAndOrganize:"\u4E00\u952E\u641C\u7D22\u548C\u6574\u7406",scanHint:"\u70B9\u300C\u{1F50D} \u4E00\u952E\u641C\u7D22\u548C\u6574\u7406\u300D\u626B\u63CF\u76F8\u4F3C\u5361/\u9648\u65E7\u5361\uFF0C\u518D\u7528\u300C\u26A1 \u4E00\u952E\u4F18\u5316\u300D\u6267\u884C\u3002",mergeNow:"\u5408\u5E76",delete:"\u5220\u9664",todayBriefLabel:"\u6BCF\u65E5\u56DE\u987E",todayBrief:"\u67E5\u770B\u4ECA\u65E5\u7B80\u62A5",batchMerge:"\u4E00\u952E\u667A\u80FD\u5408\u5E76",mergeAllConfirm:"\u5C06\u6309\u76F8\u4F3C\u5EA6\u5206\u7EC4\u7684\u5361\u7247\u5404\u5408\u5E76\u4E3A\u4E00\u5F20\uFF08\u4FDD\u7559\u5404\u81EA kind\uFF09\uFF0C\u539F\u5361\u5220\u9664\uFF1F",crossVault:"\u8DE8\u5E93\u805A\u5408",deleteConfirm:"\u786E\u5B9A\u5220\u9664\u8BE5\u8BB0\u5FC6\u5361\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002",deleted:"\u5DF2\u5220\u9664",deleteFail:"\u5220\u9664\u5931\u8D25",deleteSelected:"\u5220\u9664\u9009\u4E2D",deletedSelected:"\u5F20\u5361\u5DF2\u5220\u9664",merge:"\u5408\u5E76",mergeNeed:"\u81F3\u5C11\u9009 2 \u5F20\u5361",mergeConfirm:"\u5C06\u6240\u9009\u5361\u7247\u5408\u5E76\u4E3A\u4E00\u5F20\u5E76\u5220\u9664\u539F\u5361\uFF1F",merged:"\u5DF2\u5408\u5E76",mergeFail:"\u5408\u5E76\u5931\u8D25"},Ct={nav:"Memory",loading:"Loading\u2026",refresh:"Refresh",overview:"Memory Overview",total:"Cards",recent:"Added (7d)",tags:"Tags",searchPlaceholder:"Search memory\u2026",search:"Search",all:"All",kindProject:"Projects",kindKnowledge:"Knowledge",kindContent:"Content",kindPrompt:"Prompts",kindBusiness:"Business",kindTool:"Tools",kindMistake:"Mistakes",cardsTab:"Cards",graphTab:"Graph",graph:"Knowledge Graph",graphHint:"Nodes = cards; edges = [[links]] or shared tags. Click a node to read.",graphTip:"Left-click highlights \xB7 Shift+drag box-select \xB7 right-click menu \xB7 scroll zoom \xB7 drag to pan",rebuild:"Rebuild",reset:"Reset",expandAll:"Expand all",capped:"Showing the",clearFocus:"Clear highlight",empty:"Memory is empty. After a few conversations, valuable content is auto-captured.",emptyGraph:"No graph data yet.",open:"Read",updated:"Updated",created:"Created",source:"Source",close:"Close",vaultDir:"Vault directory",capture:"Auto capture",recall:"Auto recall",enabled:"on",disabled:"off",error:"Load failed",back:"Back to list",cardCount:"cards",nodes:"nodes",edges:"edges",memoryTitle:"Memory Library",memoryHint:"Your local second brain",zoomIn:"Zoom in",zoomOut:"Zoom out",fit:"Fit",enterFullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",exportGraph:"Export",openCard:"Open card",focusNeighbors:"Highlight links",copyName:"Copy name",noMatch:"No matching memory",clearFilter:"Clear filter",filterLabel:"Filter",sortRecent:"Recent",sortTitle:"Title",sortHot:"Hot",exportSel:"Export selected",clearSelection:"Clear selection",download:"Download",openNewTab:"Open in new tab",copyImage:"Copy image",done:"Done",downloaded:"Download started",openedTab:"Opened in new tab",copied:"Copied",exportedSel:" nodes exported",fullscreen:"Fullscreen",exitFull:"Exit fullscreen",copyFail:"Copy failed",timeDim:"Time",timeNew:"\u22643 days",timeRecent:"\u22642 weeks",timeMonth:"\u22641 month",timeOld:"Older",newBadge:"NEW",expand:"Expand",collapse:"Collapse",exportVault:"Export MD",exportJson:"Export JSON",exporting:"Exporting\u2026",exportedVault:"Vault exported",exportFail:"Export failed",importVault:"Import",importedVault:"Import complete",importedSkipped:" (skipped dup ",importFail:"Import failed",location:"Choose location",saveAs:"Save as",saveAsUnsupported:"Choose-save-location not supported here",exportedTo:"Exported to",defaultDownloads:"default Downloads folder",exportCancel:"Export cancelled",manage:"Manage",tabUsage:"Usage / Today",tabOptimize:"Optimize",adminLoadFail:"Load failed: fully restart dsh-desktop so the host picks up the new /memory-eternal routes",retry:"Retry",mergeSimilar:"Merge similar",trendLabel:"Last 30 days trend",cleanStale:"\u{1F5D1}\uFE0F Clean stale",deletedStale:" stale cards cleaned",newCard:"New",tplDecision:"\u{1F4DD} Decision",tplBug:"\u{1F41B} Bug",tplMeeting:"\u{1F4CB} Meeting",tplWeekly:"\u{1F4CA} Weekly",createCard:"Create",cardTitle:"Title",cardBody:"Body",fbUseful:"Useful",fbIrr:"Irrelevant",todayAdd:"Added today",weekAdd:"Last 7d",byKind:"By kind",todayList:"Captured today",budgetLabel:"Session budget",budgetChars:"Budget chars",recallLimitLabel:"Recall limit",embeddingLabel:"Semantic recall",mergePairs:"Similar pairs (mergeable)",staleCards:"Stale (>90d)",noOptimize:"Nothing to organize, healthy \u{1F389}",oneClickOptimize:"One-click optimize",oneClickOptimizeConfirm:"Confirm one-click optimize? This will merge all similar pairs (stale cards are NOT deleted by default).",oneClickAlsoStale:"Also clean stale cards",oneClickOptimizeDone:"One-click optimize done",optimizedMerged:"pairs merged",optimizedStaleDeleted:"stale cards cleaned",mcpSetupStatus:"Agent MCP mount status",rerunSetup:"Re-run setup",notInstalled:"not installed",noMcpEntry:"no MCP entry",nodePathMismatch:"node path mismatch, consider re-running setup",nodePathNote:"different node env (usable)",healthy:"healthy",mcpSetupHint:'"Auto-mount MCP" = lets Claude Code / Codex / Cursor use the memory vault. On = auto-configures them; Off = never touches your machine config, run dsh-memory setup manually when needed.',mcpManageHint:"Use each agent row to install/uninstall MCP individually",tabConfig:"Memory Config",tabAudit:"Audit Center",statusApproved:"Approved",statusPending:"Pending",statusRejected:"Rejected",allStatus:"All statuses",tabRecycle:"Recycle Bin",pending:"Pending",rejected:"Rejected",selectAll:"Select all",approve:"Approve",reject:"Reject",allAgents:"All agents",noAuditItems:"No items to review",deletedAt:"deleted",restore:"Restore",restoreDelete:"Delete to recycle",purge:"Purge",emptyRecycle:"Recycle bin is empty",recycleHint:"Deleted cards go to the recycle bin \u2014 recover within 30 days, else auto-purged",purgeConfirm:"Permanently delete? This cannot be undone.",recycleDeleteConfirm:"Delete to recycle? Recoverable within 30 days.",modeInit:"Init once",modeInterval:"Interval keep-alive",modeManual:"Manual only",serviceConfig:"Service self-hosting config",auditConfig:"Auto-audit config",auditHint:"Cards matching an exemption go straight in; others await audit",auditMode:"Audit mode",auditAll:"Audit all",auditNone:"Skip all",auditExemptAgents:"Exempt agents",auditExemptKinds:"Exempt kinds",allExempt:"Exempt all",recycleDays:"Recycle retention days",editInSetting:"Edit in DSH Settings \u2192 Memory",setupRunInTerminal:"Copy this command to your terminal:",dshMemoryConfig:"DSH Memory Config",autoCapture:"Auto capture",autoRecall:"Auto recall",captureMinChars:"Min capture chars",maxCardsPerDay:"Daily quota",dedupThreshold:"Dedup threshold",recallLimit:"Recall limit",recallSummaryLen:"Recall summary len",recallBody:"Recall with body",autoWeb:"Web server",autoWebMode:"Keep-alive mode",webPort:"Web port",webCheckIntervalMs:"Probe interval (ms)",webMaxRestart:"Max restart",watchdogAutoSpawn:"Watchdog process",autoMcpSetup:"Auto-mount MCP",saveConfig:"Save config",saveFail:"Save failed",savedOk:"Saved",recallTool:"recall tool",costControl:"Cost control",costHint:"save tokens, control LLM usage",distillEnabled:"Distill cards (on=LLM compress, off=raw cards zero LLM)",dedupByLLM:"Dedup feeds LLM (off=pure lexical, cheaper)",captureMaxTokens:"Distill output cap (tokens)",recallMinScore:"Recall min score (higher = cheaper)",configNeedsDsh:"Edit config inside DSH (this page may be read-only or partially missing)",installMcp:"Install MCP",uninstallMcp:"Uninstall MCP",uninstallConfirm:"Confirm uninstall MCP for this agent? Claude Code/Codex will lose access to the memory vault.",presetConfig:"One-click preset config",presetHint:"Click to fill a plan, then hit Save",planA:"A Light",planB:"B Budget",planC:"C Premium",pluginInfo:"Plugin info",organizeTitle:"Organize",scanAndOrganize:"Scan & organize",scanHint:'Click "\u{1F50D} Scan & organize" to find similar/stale cards, then "\u26A1 One-click optimize" to run.',mergeNow:"Merge",delete:"Delete",todayBriefLabel:"Daily review",todayBrief:"Today brief",batchMerge:"Smart batch merge",mergeAllConfirm:"Merge similar-grouped cards into one each (keep kind), delete originals?",crossVault:"All vaults",deleteConfirm:"Delete this memory card? This cannot be undone.",deleted:"Deleted",deleteFail:"Delete failed",deleteSelected:"Delete selected",deletedSelected:" cards deleted",merge:"Merge",mergeNeed:"Select at least 2 cards",mergeConfirm:"Merge the selected cards into one and delete the originals?",merged:"Merged",mergeFail:"Merge failed"},rt=["all","project","knowledge","content","prompt","business","tool","mistake"],Ue={project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},De={project:"kindProject",knowledge:"kindKnowledge",content:"kindContent",prompt:"kindPrompt",business:"kindBusiness",tool:"kindTool",mistake:"kindMistake",other:"kindKnowledge"},nt="deepseek-harness",Ye=t=>{let l=String(t||""),d=l.toLowerCase();return!l||l==="agent"||l==="unknown"||l.startsWith("session:")||d.startsWith("claude-code")?d.startsWith("claude-code")?"claude":nt:d==="deepseek harness"?nt:l.split(":")[0]||nt},$t=[nt,"claude","codex","cursor","codex-desktop"],St=(t=[])=>[...new Set([...$t,...(t||[]).map(Ye)])],Ce=`
7
+ .memory-eternal-root { font-family: inherit; color: var(--dsw-alias-label-primary, #1f2937); }
8
+ .mc-card { background: var(--dsw-alias-bg-layer-1, #fff); border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); border-radius: 12px; padding: 14px 16px; }
9
+ .mc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
10
+ .mc-stat { text-align: center; }
11
+ .mc-stat b { display: block; font-size: 22px; line-height: 1.2; }
12
+ .mc-stat span { font-size: 12px; opacity: 0.65; }
13
+ .mc-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
14
+ .mc-toolbar input[type=text] { flex: 1; min-width: 180px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: var(--dsw-alias-bg-base, #f9fafb); color: inherit; font-size: 13px; }
15
+ .mc-btn { border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: transparent; color: inherit; border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer; }
16
+ .mc-btn.me-on { background: var(--dsw-alias-accent, #2563eb) !important; color: #fff !important; border-color: transparent !important; }
17
+ .mc-new { display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; line-height: 16px; font-weight: 600; color: #fff; background: linear-gradient(135deg, #f97316, #ef4444); vertical-align: middle; }
18
+ .mc-hl { background: rgba(245,158,11,0.35); color: inherit; border-radius: 2px; padding: 0 1px; }
19
+ .mc-btn:hover { opacity: 0.85; }
20
+ .mc-tabs { display: inline-flex; gap: 4px; padding: 3px; background: var(--dsw-alias-bg-base, #f3f4f6); border-radius: 999px; }
21
+ .mc-tab { border: 0; background: transparent; color: inherit; border-radius: 999px; padding: 5px 14px; font-size: 12px; cursor: pointer; opacity: 0.7; }
22
+ .mc-viewbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
23
+ .mc-rail { width: 54px; flex: none; display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding-right: 12px; border-right: 1px solid var(--dsw-alias-border-l1, #e5e7eb); transition: width 0.18s ease; }
24
+ .mc-rail.open { width: 150px; }
25
+ .mc-rail-collapse { align-self: flex-start; border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: var(--dsw-alias-bg-base, #f3f4f6); color: var(--dsw-alias-label-secondary, #6b7280); border-radius: 8px; width: 26px; height: 26px; line-height: 1; cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; transition: all 0.15s ease; }
26
+ .mc-rail-collapse:hover { color: var(--dsw-alias-label-primary, #111); border-color: var(--dsw-alias-brand-primary, #3b82f6); }
27
+ .mc-railbtn { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); background: var(--dsw-alias-bg-base, #f3f4f6); color: var(--dsw-alias-label-secondary, #6b7280); cursor: pointer; display: flex; align-items: center; gap: 9px; padding: 0 10px; font-size: 13px; font-weight: 650; transition: all 0.16s ease; }
28
+ .mc-railbtn .mc-rail-ico { font-size: 18px; flex: none; }
29
+ .mc-railbtn .mc-rail-label { white-space: nowrap; overflow: hidden; }
30
+ .mc-rail:not(.open) .mc-railbtn { justify-content: center; padding: 0; }
31
+ .mc-rail:not(.open) .mc-railbtn .mc-rail-label, .mc-rail:not(.open) .mc-rail-collapse { position: relative; }
32
+ .mc-railbtn:hover { border-color: var(--dsw-alias-brand-primary, #3b82f6); color: var(--dsw-alias-label-primary, #111); background: var(--dsw-alias-bg-layer-1, #fff); }
33
+ .mc-railbtn.active { background: #3b82f6; border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(59,130,246,0.35); }
34
+ .mc-main { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
35
+ .mc-tab.active { background: var(--dsw-alias-bg-layer-1, #fff); opacity: 1; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
36
+ .mc-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
37
+ .mc-chip { border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: transparent; color: inherit; border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer; opacity: 0.7; }
38
+ .mc-chip.active { opacity: 1; font-weight: 600; border-color: currentColor; }
39
+ .mc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
40
+ .mc-cardrow { cursor: pointer; transition: border-color 0.15s, transform 0.15s; display: flex; flex-direction: column; gap: 6px; min-height: 110px; }
41
+ .mc-cardrow:hover { border-color: var(--dsw-alias-brand-primary, #6366f1); transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0,0,0,0.08); }
42
+ .mc-cardrow h4 { margin: 0; font-size: 14px; line-height: 1.35; }
43
+ .mc-cardrow p { margin: 0; font-size: 12px; opacity: 0.7; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
44
+ .mc-cardrow footer { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 11px; opacity: 0.55; }
45
+ .mc-card-del { border: none; background: transparent; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 5px; border-radius: 5px; opacity: 0.45; }
46
+ .mc-cardrow:hover .mc-card-del { opacity: 0.9; }
47
+ .mc-card-del:hover { color: #ef4444; background: rgba(239,68,68,0.12); }
48
+ /* \u77E5\u8BC6\u5E93\u6EDA\u52A8\u6761\uFF1A\u6E05\u6670\u53EF\u89C1 */
49
+ .memory-eternal-root * { scrollbar-width: thin; scrollbar-color: var(--dsw-alias-label-secondary, #94a3b8) transparent; }
50
+ .memory-eternal-root ::-webkit-scrollbar { width: 10px; height: 10px; }
51
+ .memory-eternal-root ::-webkit-scrollbar-thumb { background: var(--dsw-alias-label-secondary, #94a3b8); border-radius: 6px; }
52
+ .memory-eternal-root ::-webkit-scrollbar-thumb:hover { background: var(--dsw-alias-label-primary, #64748b); }
53
+ .memory-eternal-root ::-webkit-scrollbar-track { background: rgba(127,127,127,0.08); }
54
+ .mc-tags { display: flex; gap: 4px; flex-wrap: wrap; }
55
+ .mc-tag { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: var(--dsw-alias-border-l2, #d1d5db); opacity: 1; color: var(--dsw-alias-label-primary, #1f2937); }
56
+ .mc-status { display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px; font-size: 10px; line-height: 16px; font-weight: 600; color: #fff; vertical-align: middle; }
57
+ .mc-kind { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
58
+ .mc-empty { text-align: center; padding: 40px 10px; opacity: 0.6; font-size: 13px; }
59
+ .mc-flag { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l2, #d1d5db); margin-left: 6px; }
60
+
61
+ /* ---- sidebar footer button ---- */
62
+ /* \u8BA9\u300C\u8BB0\u5FC6\u300D\u6309\u94AE\u72EC\u5360\u4E00\u884C\uFF1A\u8BA9\u5BB9\u5668\u53EF\u6362\u884C\uFF0C\u672C\u6309\u94AE flex-basis:100% \u5360\u6EE1\u6574\u884C\u3002
63
+ \u540C\u65F6\u547D\u4E2D\u300CfooterActions \u76F4\u63A5\u5305\u542B\u300D\u4E0E\u300C\u4E2D\u95F4\u9694\u4E00\u5C42 wrapper\u300D\u4E24\u79CD\u60C5\u51B5\uFF08:has \u5728 WebView2/Chromium \u5747\u652F\u6301\uFF09\u3002 */
64
+ [class*="footerActions"]:has(.me-footer), :has(> .me-footer) { flex-wrap: wrap; width: 100%; }
65
+ .me-footer { width: 100%; flex: 1 1 100%; }
66
+ .me-footer-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.14)); background: var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.04)); color: var(--dsw-alias-label-secondary, #6b7280); font: inherit; font-size: 13.5px; line-height: 18px; border-radius: 8px; cursor: pointer; text-align: left; }
67
+ .me-footer-btn:hover { background: var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.06)); color: var(--dsw-alias-label-primary, #111); }
68
+ .me-footer-btn:active { transform: translateY(0.5px); }
69
+ .me-footer-ico { display: inline-flex; flex: none; width: 18px; height: 18px; align-items: center; justify-content: center; }
70
+ .me-footer-ico svg { width: 18px; height: 18px; }
71
+ .me-footer-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
72
+ .me-footer.rail .me-footer-btn { justify-content: center; padding: 7px 0; }
73
+ .me-footer.rail .me-footer-label { display: none; }
74
+
75
+ /* ---- full library modal ---- */
76
+ .me-overlay-top { position: fixed; inset: 0; z-index: 1001; background: rgba(0,0,0,0.72); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 28px; }
77
+ .me-modal { width: min(1380px, 98vw); height: min(98vh, 1080px); display: flex; flex-direction: column; background: var(--dsw-alias-bg-layer-1, #1e232c); color: var(--dsw-alias-label-primary, #e5e7eb); border: 1px solid var(--dsw-alias-border-l1, #2c333c); border-radius: 18px; box-shadow: 0 34px 90px rgba(0,0,0,0.6); overflow: hidden; animation: me-pop 0.22s cubic-bezier(0.2,0.8,0.2,1); }
78
+ @keyframes me-pop { from { opacity: 0; transform: translateY(12px) scale(0.985); } }
79
+ .me-modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--dsw-alias-border-l1, #e5e7eb); }
80
+ .me-modal-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
81
+ .me-modal-title h2 { margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; }
82
+ .me-modal-title span { font-size: 12px; opacity: 0.55; white-space: nowrap; }
83
+ .me-modal-title .me-wicon { width: 26px; height: 26px; flex: none; }
84
+ .me-modal-title .me-wicon svg { display: block; width: 100%; height: 100%; }
85
+ .me-modal-head .spacer { flex: 1; }
86
+ .me-modal-close { border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: transparent; color: inherit; border-radius: 8px; width: 30px; height: 30px; line-height: 1; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
87
+ .me-modal-close:hover { background: var(--dsw-alias-bg-layer-1, #f3f4f6); }
88
+ .me-modal-body { flex: 1; padding: 18px 20px; overflow: hidden; display: flex; }
89
+ .me-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.66); z-index: 1002; display: flex; align-items: center; justify-content: center; padding: 24px; }
90
+ .me-dialog { background: var(--dsw-alias-bg-layer-1, #1e232c); color: var(--dsw-alias-label-primary, #e5e7eb); border-radius: 14px; max-width: 760px; width: 100%; max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,0.5); border: 1px solid var(--dsw-alias-border-l1, #2c333c); }
91
+ .me-dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--dsw-alias-border-l1, #e5e7eb); }
92
+ .me-dialog-head h3 { margin: 0; font-size: 15px; }
93
+ .me-dialog-body { padding: 14px 18px; overflow: auto; font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
94
+ .me-dialog-body h3 { font-size: 15px; margin: 10px 0 6px; color: var(--dsw-alias-label-primary, #111); }
95
+ .me-dialog-body h4 { font-size: 13px; margin: 8px 0 4px; color: var(--dsw-alias-label-primary, #111); }
96
+ .me-dialog-body b, .me-dialog-body strong { font-weight: 700; }
97
+ .me-dialog-body code { background: var(--dsw-alias-bg-layer-1, rgba(127,127,127,0.14)); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, monospace; }
98
+ .me-dialog-body pre { background: var(--dsw-alias-bg-layer-1, rgba(127,127,127,0.1)); border-radius: 8px; padding: 10px; overflow: auto; margin: 8px 0; }
99
+ .me-dialog-body pre code { background: none; padding: 0; }
100
+ .me-dialog-body ul, .me-dialog-body ol { margin: 6px 0; padding-left: 20px; }
101
+ .me-dialog-body a { color: var(--dsw-alias-accent, #2563eb); }
102
+ .me-dialog-body blockquote { border-left: 3px solid var(--dsw-alias-border-l2, #d1d5db); margin: 6px 0; padding: 2px 12px; opacity: 0.85; }
103
+
104
+ /* ---- enhanced graph ---- */
105
+ .me-graph { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
106
+ .me-graph-toolbar { display: flex; align-items: center; gap: 8px; }
107
+ .me-graph-toolbar input[type=text] { flex: 1; min-width: 180px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: var(--dsw-alias-bg-base, #f9fafb); color: inherit; font-size: 13px; }
108
+ .me-graph-count { font-size: 12px; opacity: 0.7; }
109
+ .me-graph-canvas { position: relative; flex: 1; min-height: 300px; border-radius: 14px; overflow: hidden; background: radial-gradient(120% 120% at 50% 40%, var(--dsw-alias-bg-layer-2, #f8fafc) 0%, var(--dsw-alias-bg-base, #eef2f7) 100%); border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); cursor: grab; touch-action: none; user-select: none; }
110
+ .me-graph-canvas.dragging { cursor: grabbing; }
111
+ .me-graph-tip { font-size: 11px; opacity: 0.6; }
112
+ .me-graph-canvas svg { width: 100%; height: 100%; display: block; }
113
+ .me-graph-edge { fill: none; stroke-width: 1; }
114
+ .me-graph-node { cursor: pointer; }
115
+ .me-nodelabel { font-size: 11px; fill: var(--dsw-alias-label-primary, #334); pointer-events: none; transition: opacity .12s; }
116
+ .me-nodelabel.core { font-weight: 650; }
117
+ .me-graph-legend { display: flex; gap: 12px; flex-wrap: wrap; padding: 2px 2px 0; font-size: 11px; opacity: 0.85; }
118
+ .me-graph-legend .lg { display: inline-flex; align-items: center; gap: 5px; border: none; background: transparent; color: inherit; font: inherit; font-size: 11px; padding: 3px 6px; border-radius: 7px; cursor: pointer; }
119
+ .me-graph-legend .lg:hover { background: var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.08)); }
120
+ .me-graph-legend .lg.active { background: var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.14)); box-shadow: 0 0 0 1px var(--dsw-alias-border-l1, #d1d5db); }
121
+ .me-graph-legend .lg.lg-clear { opacity: 0.85; }
122
+ /* \u56FE\u8C31\u7B5B\u9009\u4E0B\u62C9\uFF1A\u9009\u9879\u6DF1\u8272\u5E95\u6D45\u5B57\uFF0C\u907F\u514D\u767D\u5361\u7247\u523A\u773C */
123
+ .me-graph-legend-pop { color: #e5e7eb; }
124
+ .me-graph-legend-pop .lg { width: 100%; background: rgba(255,255,255,0.06); color: #e5e7eb; padding: 7px 9px; margin-bottom: 2px; border-radius: 7px; }
125
+ .me-graph-legend-pop .lg:hover { background: rgba(255,255,255,0.14); }
126
+ .me-graph-legend-pop .lg.active { background: rgba(59,130,246,0.32); color: #fff; box-shadow: 0 0 0 1px rgba(59,130,246,0.5); }
127
+ .me-graph-legend-pop .lg.lg-clear { color: #f87171; }
128
+ .me-graph-ctxmenu { min-width: 156px; padding: 6px; background: rgba(28,28,32,0.95); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: #eee; border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; box-shadow: 0 12px 34px rgba(0,0,0,.3); font-size: 12px; }
129
+ .me-graph-ctxmenu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; border-radius: 7px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
130
+ .me-graph-ctxmenu button:hover { background: rgba(255,255,255,0.1); }
131
+ .me-graph-hint { font-size: 11px; opacity: 0.6; margin-left: auto; }
132
+ `;function Et(t){t.effect(()=>t.locale.register(We,{zh:kt,en:Ct}),"memory-eternal: locale");let l=t.locale.bind(We);t.effect(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:We,order:25,label:()=>l("nav"),locale:We,inject:()=>({})},()=>i.default.createElement(Ot,{t:l}))),"memory-eternal: settings section"),t.effect(()=>t.slots.inject("sidebar.footer.action",()=>t.slots.register({name:"sidebar.footer.action",id:`${We}:footer`,order:100,label:()=>l("nav"),locale:We,inject:()=>({})},d=>i.default.createElement(Wt,{t:l,wide:!(d&&d.wide===!1)}))),"memory-eternal: sidebar footer action")}function Pt(){let[t,l]=(0,i.useState)("http://127.0.0.1:7999/");return(0,i.useEffect)(()=>{fetch("/memory-eternal/api/web-info").then(d=>d.json()).then(d=>{d&&d.ok&&d.url&&l(d.url.endsWith("/")?d.url:d.url+"/")}).catch(()=>{})},[]),t}function Ot({t}){return(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsx)(Nt,{t,onReload:()=>{},version:0})]})}function Wt({t,wide:l}){let[d,x]=(0,i.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${l?"":" rail"}`,children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>x(!0),"aria-label":t("nav"),title:t("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(Mt,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:t("nav")})]}),d&&(0,e.jsx)(Ht,{t,onClose:()=>x(!1)})]})}function Ht({t,onClose:l,tab:d}){let[x,g]=(0,i.useState)(!1),o=Pt(),B=d==="config"?`${j}/ui/config?tab=config`:d?`${o.replace(/\/$/,"")}/?tab=${d}`:o;return(0,i.useEffect)(()=>{let D=M=>{M.key==="Escape"&&l()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[l]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:l,children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsx)("div",{className:"me-modal",onClick:D=>D.stopPropagation(),style:x?{position:"fixed",inset:0,width:"100vw",height:"100vh",maxWidth:"100vw",maxHeight:"100vh",borderRadius:0}:{},children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[(0,e.jsxs)("div",{style:{position:"absolute",top:8,right:8,zIndex:10,display:"flex",gap:4,padding:"4px 6px",background:"var(--dsw-alias-bg-overlay, rgba(17,24,39,0.45))",borderRadius:8,backdropFilter:"blur(4px)"},children:[(0,e.jsx)("button",{type:"button",onClick:()=>g(D=>!D),"aria-label":t(x?"exitFullscreen":"enterFullscreen"),title:t(x?"exitFullscreen":"enterFullscreen"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:14,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:x?"\u2921":"\u2922"}),(0,e.jsx)("button",{type:"button",onClick:l,"aria-label":t("close"),title:t("close"),style:{width:26,height:26,borderRadius:6,border:"1px solid rgba(255,255,255,0.18)",background:"rgba(255,255,255,0.08)",color:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),(0,e.jsx)("iframe",{src:B,title:"memory-eternal",style:{width:"100%",flex:1,border:0,borderRadius:"inherit",background:"var(--dsw-alias-bg-base, #fff)"}})]})})]})}function Mt(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}function _t({t,inModal:l,onClose:d,onFull:x,full:g}){let[o,B]=(0,i.useState)(null),[D,M]=(0,i.useState)([]),[z,R]=(0,i.useState)(!0),[y,h]=(0,i.useState)(""),[C,J]=(0,i.useState)("all"),[k,Y]=(0,i.useState)(""),[_,Se]=(0,i.useState)("all"),[E,U]=(0,i.useState)("all"),[F,re]=(0,i.useState)(()=>{try{let c=new URLSearchParams(typeof location<"u"?location.search:"").get("tab"),I={cards:"cards",graph:"graph",usage:"stats",stats:"stats",audit:"audit",recycle:"optimize",optimize:"optimize",config:"config"};if(c&&I[c])return I[c]}catch{}return"cards"}),[te,he]=(0,i.useState)("recent"),[b,u]=(0,i.useState)(null),w=(0,i.useRef)(null),O=(0,i.useRef)(null),[W,Q]=(0,i.useState)(!1),[ee,K]=(0,i.useState)(null),[Z,xe]=(0,i.useState)(!1),[pe,Ke]=(0,i.useState)(!0),[we,ne]=(0,i.useState)(null),[oe,m]=(0,i.useState)(0),$=(0,i.useCallback)(()=>m(c=>c+1),[]),H=(0,i.useRef)(null),[se,be]=(0,i.useState)(100),Ie=(0,i.useRef)(null),Le=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(F!=="cards")return;let c=Ie.current,I=Le.current;if(!c)return;let a=new IntersectionObserver(ae=>{ae[0]&&ae[0].isIntersecting&&be(ye=>ye+24)},{root:I||null,rootMargin:"400px"});return a.observe(c),()=>a.disconnect()},[F,D,C,k]);let Ee=(0,i.useCallback)(async(c=C,I=k,a=E)=>{try{R(!0),h("");let ae=new URLSearchParams;c&&c!=="all"&&ae.set("kind",c),I.trim()&&ae.set("q",I.trim()),ae.set("status",a||"all"),ae.set("limit","500");let Te=await(await fetch(`${j}/cards?${ae.toString()}`)).json();Te.ok&&(M(Te.cards||[]),be(100))}catch(ae){h(String(ae&&ae.message?ae.message:ae))}finally{R(!1)}},[C,k,E]),de=(0,i.useCallback)(async()=>{try{let[c,I]=await Promise.all([fetch(`${j}/overview`).then(a=>a.json()),fetch(`${j}/cards?status=all&limit=500`).then(a=>a.json())]);c.ok&&B(c),I.ok&&(M(I.cards||[]),be(100))}catch(c){h(String(c&&c.message?c.message:c))}finally{R(!1)}},[]),Re=async c=>{try{let a=await(await fetch(`${j}/delete?path=${encodeURIComponent(c)}`)).json();a.ok?(u({ok:!0,msg:t("deleted")}),await de()):u({ok:!1,msg:a.error||t("deleteFail")})}catch{u({ok:!1,msg:t("deleteFail")})}w.current&&clearTimeout(w.current),w.current=setTimeout(()=>u(null),2e3)};(0,i.useEffect)(()=>(de(),()=>{H.current&&clearTimeout(H.current)}),[de]);let ie=c=>{Y(c),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>Ee(C,c,E),280)},qe=c=>{J(c),Ee(c,k,E)};(0,i.useEffect)(()=>{Ee(C,k,E)},[E]);let ve=async c=>{try{let a=await(await fetch(`${j}/card?path=${encodeURIComponent(c.path||c.id)}`)).json();a.ok&&K({path:a.path,title:c.title,text:a.text})}catch(I){h(String(I&&I.message?I.message:I))}},r=async(c,I)=>{Q(!0);try{let a=await fetch(`${j}/export`);if(!a.ok)throw new Error("HTTP "+a.status);let ae=await a.json();if(!ae.ok)throw new Error(ae.error||"export failed");let ye,Te,Xe;c==="json"?(Te="memory-vault.json",Xe="application/json",ye=JSON.stringify(ae.cards.map(Be=>({path:Be.path,title:Be.title,kind:Be.kind,text:Be.text})),null,2)):(Te="memory-vault.md",Xe="text/markdown;charset=utf-8",ye=ae.cards.map(Be=>Be.text.trim()).filter(Boolean).join(`
133
+
134
+ ---
135
+
136
+ `));let je=new Blob([ye],{type:Xe}),Fe=await ea(je,Te,!1);if(!Fe.ok){u({ok:!1,msg:t("exportFail")}),Q(!1);return}u({ok:!0,msg:t("exportedTo")+"\uFF1A"+t("defaultDownloads")+" \xB7 "+Fe.name})}catch(a){u({ok:!1,msg:t("exportFail")+" \xB7 "+(a.message||"")})}finally{Q(!1)}w.current&&clearTimeout(w.current),w.current=setTimeout(()=>u(null),2600)},n=async c=>{let I=c.target.files&&c.target.files[0];if(c.target.value="",!!I){try{let a=await I.text(),ye=await(await fetch(`${j}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:a})).json();ye.ok?(await de(),u({ok:!0,msg:t("importedVault")+"\uFF1A"+(ye.imported||0)+(ye.skipped?t("importedSkipped")+ye.skipped:"")})):u({ok:!1,msg:ye.error||t("importFail")})}catch{u({ok:!1,msg:t("importFail")})}w.current&&clearTimeout(w.current),w.current=setTimeout(()=>u(null),2400)}},N=(0,i.useMemo)(()=>{let c=D.slice();return _!=="all"&&(c=c.filter(I=>Ye(I.submittedBy)===_)),E!=="all"&&(c=c.filter(I=>(I.status||"approved")===E)),te==="title"?c.sort((I,a)=>String(I.title||"").localeCompare(String(a.title||""))):te==="hot"?c.sort((I,a)=>(a.weight||a.links||0)-(I.weight||I.links||0)):c.sort((I,a)=>new Date(a.updated||0).getTime()-new Date(I.updated||0).getTime()),c},[D,te,_,E]),X=(0,i.useMemo)(()=>[...new Set(D.map(c=>Ye(c.submittedBy)))],[D]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:Ce}),b&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(b.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:b.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:b.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:b.msg})]}),l&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(Mt,{})}),(0,e.jsx)("h2",{children:t("memoryTitle")}),(0,e.jsx)("span",{children:t("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),x&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:x,"aria-label":t(g?"exitFull":"fullscreen"),children:g?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:d,"aria-label":t("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:`mc-rail${pe?" open":""}`,children:[(0,e.jsx)("button",{type:"button",className:"mc-rail-collapse",onClick:()=>Ke(c=>!c),"aria-label":t(pe?"collapse":"expand"),title:t(pe?"collapse":"expand"),children:pe?"\xAB":"\xBB"}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="cards"?" active":""}`,onClick:()=>re("cards"),title:t("cardsTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4C7}"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("cardsTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="graph"?" active":""}`,onClick:()=>re("graph"),title:t("graphTab"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F578}"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("graphTab")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="stats"?" active":""}`,onClick:()=>re("stats"),title:t("tabUsage"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F4CA}"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabUsage")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="audit"?" active":""}`,onClick:()=>re("audit"),title:t("tabAudit"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F6E1}\uFE0F"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabAudit")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="optimize"?" active":""}`,onClick:()=>re("optimize"),title:t("tabRecycle"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u{1F5D1}\uFE0F"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabRecycle")})]}),(0,e.jsxs)("button",{type:"button",className:`mc-railbtn${F==="config"?" active":""}`,onClick:()=>re("config"),title:t("tabConfig"),children:[(0,e.jsx)("span",{className:"mc-rail-ico",children:"\u2699\uFE0F"}),pe&&(0,e.jsx)("span",{className:"mc-rail-label",children:t("tabConfig")})]})]}),(0,e.jsxs)("div",{className:"mc-main",ref:Le,children:[F==="cards"&&(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(He,{label:t("total"),value:o?o.total:"\u2014"}),(0,e.jsx)(He,{label:t("recent"),value:o?o.recent:"\u2014"}),(0,e.jsx)(He,{label:t("tags"),value:o?o.tags:"\u2014"}),(0,e.jsx)(He,{label:t("pending"),value:o?.status?.pending??0}),(0,e.jsx)(He,{label:t("rejected"),value:o?.status?.rejected??0}),(0,e.jsx)(He,{label:t("cardCount"),value:o?o.byKind?.knowledge??0:"\u2014"})]}),F==="cards"&&(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:t("searchPlaceholder"),value:k,onChange:c=>ie(c.target.value)}),(0,e.jsx)("input",{ref:O,type:"file",accept:".json,application/json",style:{display:"none"},onChange:n}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>O.current&&O.current.click(),children:t("importVault")}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",onClick:()=>ne({kind:"knowledge",title:"",body:"",tags:"",template:""}),children:["+ ",t("newCard")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:W,onClick:()=>r("md"),children:t(W?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:W,onClick:()=>r("json"),children:t(W?"exporting":"exportJson")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>de(),children:t("refresh")})]}),F==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[rt.map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${C===c?" active":""}`,onClick:()=>qe(c),children:t(c==="all"?"all":De[c])},c)),(0,e.jsxs)("select",{value:_,onChange:c=>Se(c.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsxs)("option",{value:"all",children:["\u{1F916} ",t("allAgents")]}),St(X).map(c=>(0,e.jsx)("option",{value:c,children:c},c))]}),(0,e.jsxs)("select",{value:E,onChange:c=>U(c.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("allStatus")}),(0,e.jsx)("option",{value:"approved",children:t("statusApproved")}),(0,e.jsx)("option",{value:"pending",children:t("statusPending")}),(0,e.jsx)("option",{value:"rejected",children:t("statusRejected")})]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:t("sortRecent")},{key:"title",label:t("sortTitle")},{key:"hot",label:t("sortHot")}].map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${te===c.key?" active":""}`,onClick:()=>he(c.key),children:c.label},c.key))]}),y&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",y]}),F==="cards"?z&&!D.length?(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}):D.length===0?(0,e.jsx)("div",{className:"mc-empty",children:t("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:N.slice(0,se).map(c=>(0,e.jsx)(Kt,{card:c,t,query:k.trim(),onOpen:ve,onDelete:Re},c.path))}),N.length>se&&(0,e.jsx)("div",{ref:Ie,style:{height:1}})]}):F==="graph"?(0,e.jsx)(Vt,{t,onOpen:ve,all:Z,onAllChange:xe,onMutate:$}):F==="config"?(0,e.jsx)(Nt,{t,onReload:()=>de(),version:oe}):F==="stats"?(0,e.jsx)(xt,{t,tab:"stats",onReload:()=>de(),version:oe}):F==="audit"?(0,e.jsx)(Ut,{t,onReload:()=>de(),version:oe}):F==="optimize"?(0,e.jsx)(Yt,{t,onReload:()=>de(),version:oe}):(0,e.jsx)(xt,{t,tab:"stats",onReload:()=>de(),version:oe}),ee&&(0,e.jsx)(Xt,{t,card:ee,query:k.trim(),onClose:()=>K(null),onDelete:c=>{K(null),Re(c)},onFeedback:c=>{let I=ee.path;fetch(`${j}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:k.trim(),path:I,useful:c})}).then(()=>u({ok:!0,msg:t(c?"fbUseful":"fbIrr")})).catch(()=>{}),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>u(null),2e3)}}),(0,e.jsx)(qt,{t,newCard:we,setNewCard:ne,onCreated:()=>{de(),$(),u({ok:!0,msg:t("created")}),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>u(null),2e3)}})]})]})]})}var He=({label:t,value:l})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:l}),(0,e.jsx)("span",{children:t})]});function Nt({t,onReload:l,version:d,compact:x}){let[g,o]=(0,i.useState)(null),[B,D]=(0,i.useState)(0),[M,z]=(0,i.useState)(null),[R,y]=(0,i.useState)(null),[h,C]=(0,i.useState)(!1),[J,k]=(0,i.useState)(null),[Y,_]=(0,i.useState)(null),[Se,E]=(0,i.useState)(""),[U,F]=(0,i.useState)(""),[re,te]=(0,i.useState)(""),[he,b]=(0,i.useState)(""),[u,w]=(0,i.useState)(null),O=(0,i.useRef)(null),W=(m,$=!0)=>{O.current&&clearTimeout(O.current),w({msg:m,ok:$}),O.current=setTimeout(()=>w(null),1900)},Q=(0,i.useCallback)(async()=>{try{let[m,$,H]=await Promise.all([fetch(`${j}/config`).then(se=>se.json()).catch(()=>null),fetch(`${j}/setup-status`).then(se=>se.json()).catch(()=>null),fetch(`${j}/budget`).then(se=>se.json()).catch(()=>null)]);m&&m.ok?(o(m),D(m.revision??0),z(m.schema??null),y({...m.config??{}}),k(m.dsh??null),C(m.writable===!1),E("")):H&&H.ok?(y({...H}),C(!0),E(t("configNeedsDsh"))):E(t("adminLoadFail")),$&&$.ok&&_($),te("")}catch{E(t("adminLoadFail"))}},[t]);(0,i.useEffect)(()=>{Q()},[d,Q]);let ee=(m,$)=>y(H=>({...H??{},[m]:$})),K=m=>({init:t("modeInit"),interval:t("modeInterval"),manual:t("modeManual")})[m]||m,Z=async()=>{if(R){if(h){W(t("editInSetting"),!1);return}F("save");try{let $=await(await fetch(`${j}/config`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patch:R,expectedRevision:B})})).json();if($&&$.ok){let H=$.note||t("savedOk");te(t("savedOk")+($.note?` \xB7 ${$.note}`:"")),W(H),await Q()}else E($?.error||t("saveFail")),W($?.error||t("saveFail"),!1)}catch{E(t("saveFail")),W(t("saveFail"),!1)}finally{F("")}}},xe=()=>{y({...g?.config??{}}),te("")},pe={A:{label:t("planA"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:900,recallMinScore:2,recallLimit:5,recallSummaryLen:130,recallIncludeBody:!1,captureCooldownMs:3e5},B:{label:t("planB"),autoWebMode:"init",watchdogAutoSpawn:!1,distillEnabled:!1,dedupByLLM:!1,captureMaxTokens:500,recallMinScore:3,recallLimit:3,recallSummaryLen:80,recallIncludeBody:!1,captureMinChars:300,maxCardsPerDay:40,captureCooldownMs:3e5},C:{label:t("planC"),autoWebMode:"interval",watchdogAutoSpawn:!0,distillEnabled:!0,dedupByLLM:!0,captureMaxTokens:1200,recallMinScore:1,recallLimit:8,recallSummaryLen:200,recallIncludeBody:!0,captureCooldownMs:12e4}},Ke=async m=>{let $=pe[m];$&&y(H=>({...H??{},...$}))},we=async(m,$)=>{F(m+$);try{let se=await(await fetch(`${j}/mcp/action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:m,action:$})})).json();se&&se.ok?W($==="install"?`\u2705 ${m} MCP \u5DF2\u5B89\u88C5`:`\u2705 ${m} MCP \u5DF2\u5378\u8F7D`):W(`\u274C ${m} MCP \u64CD\u4F5C\u5931\u8D25\uFF1A${se?.error||""}`,!1);try{let be=await fetch(`${j}/setup-status`).then(Ie=>Ie.json());be&&be.ok&&_(be)}catch{}}catch{W(t("mergeFail"),!1)}finally{F("")}},ne=({k:m,label:$,type:H="text",step:se,min:be,max:Ie})=>(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:$||m}),(0,e.jsx)("input",{type:H,step:se,min:be,max:Ie,value:R?R[m]??"":"",onChange:Le=>ee(m,H==="number"?Number(Le.target.value):Le.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}})]}),oe=({k:m,label:$})=>(0,e.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:!!(R&&R[m]),onChange:H=>ee(m,H.target.checked)}),(0,e.jsx)("span",{children:$||m})]});return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:x?"0 0 auto":1,minHeight:0,maxHeight:x?"52vh":void 0},children:[(0,e.jsx)("style",{children:Ce}),u&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(u.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:u.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:u.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:u.msg})]}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[Se&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,e.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",Se]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:Q,children:["\u21BB ",t("retry")]})]}),h&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #f59e0b",background:"rgba(245,158,11,0.08)",padding:"10px 14px",marginBottom:10,fontSize:12,color:"#b45309"},children:["\u2139\uFE0F ",t("configNeedsDsh")," \u2014\u2014 ",t("editInSetting")]}),re&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #10b981",background:"rgba(16,185,129,0.08)",padding:"10px 14px",marginBottom:10,fontSize:12,color:"#059669"},children:["\u2713 ",re]}),g&&(g.version||g.dsh?.vaultDir)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px",display:"flex",gap:14,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F4E6} ",t("pluginInfo")]}),(0,e.jsx)("span",{style:{fontSize:12,opacity:.7},children:g.dsh?.label||t("nav")}),g.version&&(0,e.jsxs)("code",{style:{fontSize:11,padding:"2px 8px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:6},children:["v",g.version]}),g.dsh?.vaultDir&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.6},children:["\u{1F4C1} ",g.dsh.vaultDir]})]}),Y&&Y.agents&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F50C} ",t("mcpSetupStatus")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("mcpManageHint")})]}),(0,e.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:Y.agents.map(m=>(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1},children:[(0,e.jsx)("b",{children:m.isDsh?m.label||"DeepSeek Harness":m.name}),m.isDsh&&m.version&&(0,e.jsxs)("span",{style:{marginLeft:6,fontSize:11,opacity:.5},children:["v",m.version]}),!m.installed&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6},children:["(",t("notInstalled"),")"]}),m.installed&&m.mcpConfigured===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#f59e0b"},children:["(",t("noMcpEntry"),")"]}),m.mcpConfigured===!0&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#10b981"},children:["\u2713 ",t("healthy")]}),m.mcpConfigured===!0&&m.mcpMatchesCurrentNode===!1&&(0,e.jsxs)("span",{style:{marginLeft:6,color:"#9ca3af",fontSize:10},children:["(",t("nodePathNote"),")"]}),m.isDsh&&(0,e.jsxs)("span",{style:{marginLeft:6,opacity:.6,fontSize:11},children:["(",t("recallTool"),": ",m.recallTool?t("enabled"):t("disabled"),")"]})]}),m.hook&&(0,e.jsxs)("span",{style:{fontSize:11,opacity:.7},children:["hook: ",m.hook]}),!m.isDsh&&m.installed&&m.mcpConfigured===!1&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!U,onClick:()=>we(m.name,"install"),children:t("installMcp")}),!m.isDsh&&m.installed&&m.mcpConfigured===!0&&(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!U,onClick:()=>{window.confirm(t("uninstallConfirm"))&&we(m.name,"uninstall")},children:t("uninstallMcp")})]},m.name))}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.55,marginTop:6},children:t("mcpSetupHint")}),he&&(0,e.jsx)("div",{style:{fontSize:11,marginTop:6},children:(0,e.jsx)("code",{style:{padding:"2px 6px",background:"var(--dsw-alias-bg-layer-2, #f3f4f6)",borderRadius:4},children:he})})]}),R?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #3b82f6"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8,flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F3AF} ",t("presetConfig")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("presetHint")})]}),(0,e.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["A","B","C"].map(m=>(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>Ke(m),disabled:!!U,children:[m==="A"?"\u{1F7E2} ":m==="B"?"\u{1F4B0} ":"\u2B50 ",pe[m].label]},m))})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F9E0} ",t("dshMemoryConfig")]})}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:8},children:[(0,e.jsx)(oe,{k:"autoCapture",label:t("autoCapture")}),(0,e.jsx)(oe,{k:"autoRecall",label:t("autoRecall")}),(0,e.jsx)(ne,{k:"captureMinChars",label:t("captureMinChars"),type:"number"}),(0,e.jsx)(ne,{k:"maxCardsPerDay",label:t("maxCardsPerDay"),type:"number"}),(0,e.jsx)(ne,{k:"dedupThreshold",label:t("dedupThreshold"),type:"number",step:"0.01",min:"0",max:"1"}),(0,e.jsx)(ne,{k:"recallLimit",label:t("recallLimit"),type:"number"}),(0,e.jsx)(ne,{k:"recallSummaryLen",label:t("recallSummaryLen"),type:"number"}),(0,e.jsx)(oe,{k:"recallIncludeBody",label:t("recallBody")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #f59e0b"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:4},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F4B0} ",t("costControl")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("costHint")})]}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:8,marginTop:6},children:[(0,e.jsx)(oe,{k:"distillEnabled",label:t("distillEnabled")}),(0,e.jsx)(oe,{k:"dedupByLLM",label:t("dedupByLLM")}),(0,e.jsx)(ne,{k:"captureMaxTokens",label:t("captureMaxTokens"),type:"number"}),(0,e.jsx)(ne,{k:"recallMinScore",label:t("recallMinScore"),type:"number"})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px",borderLeft:"3px solid #8b5cf6"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",t("auditConfig")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("auditHint")})]}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:8},children:[(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("auditMode")}),(0,e.jsxs)("select",{value:R.auditMode??"all",onChange:m=>ee("auditMode",m.target.value),style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"all",children:t("auditAll")}),(0,e.jsx)("option",{value:"none",children:t("auditNone")})]})]}),(0,e.jsx)(vt,{label:t("auditExemptAgents"),value:R.auditExemptAgents||[],options:[{value:"__all__",label:t("allExempt")},...(Y?.agents||[]).filter(m=>!m.isDsh).map(m=>({value:m.name,label:m.name}))],onChange:m=>ee("auditExemptAgents",m)}),(0,e.jsx)(vt,{label:t("auditExemptKinds"),value:R.auditExemptKinds||[],options:[{value:"__all__",label:t("allExempt")},...rt.filter(m=>m!=="all").map(m=>({value:m,label:t(De[m])}))],onChange:m=>ee("auditExemptKinds",m)}),(0,e.jsx)(ne,{k:"recycleRetentionDays",label:t("recycleDays"),type:"number"})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"12px 14px"},children:[(0,e.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E0} ",t("serviceConfig")]})}),(0,e.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:8},children:[(0,e.jsx)(oe,{k:"autoWeb",label:t("autoWeb")}),(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t("autoWebMode")}),(0,e.jsxs)("select",{value:R.autoWebMode??"init",onChange:m=>ee("autoWebMode",m.target.value),style:{padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12},children:[(0,e.jsx)("option",{value:"init",children:t("modeInit")}),(0,e.jsx)("option",{value:"interval",children:t("modeInterval")}),(0,e.jsx)("option",{value:"manual",children:t("modeManual")})]})]}),(0,e.jsx)(ne,{k:"webPort",label:t("webPort"),type:"number"}),(0,e.jsx)(ne,{k:"webCheckIntervalMs",label:t("webCheckIntervalMs"),type:"number"}),(0,e.jsx)(ne,{k:"webMaxRestart",label:t("webMaxRestart"),type:"number"}),(0,e.jsx)(oe,{k:"watchdogAutoSpawn",label:t("watchdogAutoSpawn")}),(0,e.jsx)(oe,{k:"autoMcpSetup",label:t("autoMcpSetup")})]})]}),(0,e.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginBottom:10},children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:xe,disabled:!!U,children:t("reset")}),(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",onClick:Z,disabled:!!U||U==="save"||h,children:U==="save"?t("exporting"):"\u{1F4BE} "+t("saveConfig")})]})]}):(0,e.jsx)("div",{style:{fontSize:12,opacity:.6},children:t("loading")})]})]})}function Ut({t,onReload:l,version:d}){let[x,g]=(0,i.useState)([]),[o,B]=(0,i.useState)([]),[D,M]=(0,i.useState)("all"),[z,R]=(0,i.useState)("all"),[y,h]=(0,i.useState)(""),[C,J]=(0,i.useState)(new Set),[k,Y]=(0,i.useState)(""),[_,Se]=(0,i.useState)("pending"),E=[...new Set([...x,...o].map(b=>b.submittedBy).filter(Boolean))],U=(0,i.useCallback)(async()=>{try{let b=await fetch(`${j}/audit/list`).then(u=>u.json());b.ok&&(g(b.pending||[]),B(b.rejected||[]),J(new Set))}catch{}},[]);(0,i.useEffect)(()=>{U()},[d,U]);let F=(_==="pending"?x:o).filter(b=>{if(D!=="all"&&b.kind!==D||z!=="all"&&Ye(b.submittedBy)!==z)return!1;if(y){let u=(b.created||"").slice(0,10);if(u&&u!==y)return!1}return!0}),re=b=>J(u=>{let w=new Set(u);return w.has(b)?w.delete(b):w.add(b),w}),te=async(b,u)=>{Y("apply");try{for(let w of u||[...C])await fetch(`${j}/${b==="approved"?"audit/approve":b==="rejected"?"audit/reject":"delete"}?path=${encodeURIComponent(w)}${b==="delete"?"&permanent=0":""}`);await U(),l&&l()}catch{}finally{Y("")}},he=[...C];return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F6E1}\uFE0F ",t("tabAudit")]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("select",{value:D,onChange:b=>M(b.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("all")}),rt.filter(b=>b!=="all").map(b=>(0,e.jsx)("option",{value:b,children:t(De[b])},b))]}),(0,e.jsxs)("select",{value:z,onChange:b=>R(b.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"},children:[(0,e.jsx)("option",{value:"all",children:t("allAgents")}),St(E).map(b=>(0,e.jsx)("option",{value:b,children:b},b))]}),(0,e.jsx)("input",{type:"date",value:y,onChange:b=>h(b.target.value),style:{fontSize:12,padding:"4px 8px",borderRadius:8,background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",border:"1px solid var(--dsw-alias-border-l2, #d1d5db)"}})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("button",{type:"button",className:`mc-btn${_==="pending"?" me-on":""}`,onClick:()=>Se("pending"),children:[t("pending"),"\uFF08",x.length,"\uFF09"]}),(0,e.jsxs)("button",{type:"button",className:`mc-btn${_==="rejected"?" me-on":""}`,onClick:()=>Se("rejected"),children:[t("rejected"),"\uFF08",o.length,"\uFF09"]}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsxs)("label",{style:{fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:F.length>0&&he.length===F.length,onChange:b=>{b.target.checked?J(new Set(F.map(u=>u.path))):J(new Set)}})," ",t("selectAll")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn me-on",disabled:!he.length||!!k,onClick:()=>te("approved"),children:["\u2713 ",t(_==="rejected"?"restore":"approve")]}),_==="pending"?(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!he.length||!!k,onClick:()=>te("rejected"),children:["\u2715 ",t("reject")]}):(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!he.length||!!k,onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&te("delete")},children:["\u{1F5D1} ",t("restoreDelete")||"\u5220\u9664\u8FDB\u56DE\u6536\u7AD9"]})]}),F.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:F.map(b=>(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsx)("input",{type:"checkbox",checked:C.has(b.path),onChange:()=>re(b.path)}),(0,e.jsx)("span",{className:"mc-kind",style:{background:Ue[b.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.title}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:Ye(b.submittedBy)}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:b.created?b.created.slice(0,16).replace("T"," "):"-"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6},children:b.kind}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,color:b.severity==="high"?"#f87171":"#9ca3af"},children:b.severity}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.6,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.reason||"-"}),_==="pending"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>te("approved",[b.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},onClick:()=>te("rejected",[b.path]),children:"\u2715"})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},title:t("restore"),onClick:()=>te("approved",[b.path]),children:"\u2713"}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},title:t("restoreDelete")||"\u5220\u9664\u8FDB\u56DE\u6536\u7AD9",onClick:()=>{window.confirm(t("recycleDeleteConfirm"))&&te("delete",[b.path])},children:"\u{1F5D1}"})]})]},b.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:t("noAuditItems")})]})]})}function Yt({t,onReload:l,version:d}){let[x,g]=(0,i.useState)([]),[o,B]=(0,i.useState)(""),D=(0,i.useCallback)(async()=>{try{let z=await fetch(`${j}/recycle/list`).then(R=>R.json());z.ok&&g(z.items||[])}catch{}},[]);(0,i.useEffect)(()=>{D()},[d,D]);let M=async(z,R)=>{B(z+R);try{z==="restore"?await fetch(`${j}/recycle/restore?path=${encodeURIComponent(R)}`):z==="purge"&&await fetch(`${j}/recycle/purge?path=${encodeURIComponent(R)}`),await D(),l&&l()}catch{}finally{B("")}};return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{style:{overflow:"auto",padding:4},children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsxs)("b",{style:{fontSize:12},children:["\u{1F5D1}\uFE0F ",t("tabRecycle")]}),(0,e.jsx)("span",{style:{fontSize:11,opacity:.6},children:t("recycleHint")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!o,onClick:async()=>{B("purgeAll");try{await fetch(`${j}/recycle/purge-expired?days=0`),await D()}catch{}finally{B("")}},children:t("emptyRecycle")})]}),x.length?(0,e.jsx)("div",{className:"mc-card",style:{display:"flex",flexDirection:"column"},children:x.map(z=>(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ue[z.kind]||"#999"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.title}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:[t("deletedAt")," ",(z.deletedAt||"").slice(0,10)]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},disabled:!!o,onClick:()=>M("restore",z.path),children:t("restore")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px",color:"#f87171"},disabled:!!o,onClick:()=>{window.confirm(t("purgeConfirm"))&&M("purge",z.path)},children:t("purge")})]},z.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,padding:20,textAlign:"center"},children:t("emptyRecycle")})]})]})}var Kt=({card:t,t:l,onOpen:d,query:x,onDelete:g})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>d(t),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ue[t.kind]||Ue.other}}),x?wt(t.title,x):t.title,Qt(t.updated)&&(0,e.jsx)("span",{className:"mc-new",children:l("newBadge")}),t.status==="pending"&&(0,e.jsx)("span",{className:"mc-status",style:{background:"#f59e0b"},children:l("statusPending")}),t.status==="rejected"&&(0,e.jsx)("span",{className:"mc-status",style:{background:"#ef4444"},children:l("statusRejected")}),(!t.status||t.status==="approved")&&(0,e.jsx)("span",{className:"mc-status",style:{background:"#10b981"},children:l("statusApproved")})]}),(0,e.jsx)("p",{children:x?wt(t.summary||"",x):t.summary||""}),t.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:t.tags.slice(0,4).map(o=>(0,e.jsx)("span",{className:"mc-tag",children:o},o))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:l(De[t.kind])}),(0,e.jsxs)("span",{style:{fontSize:10,opacity:.6},children:["\u{1F916} ",Ye(t.submittedBy)]}),(0,e.jsx)("span",{children:zt(t.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:l("delete"),onClick:o=>{o.stopPropagation(),window.confirm(l("deleteConfirm"))&&g&&g(t.path)},children:"\u2715"})]})]});function xt({t,tab:l,onReload:d,version:x}){let[g,o]=(0,i.useState)(null),[B,D]=(0,i.useState)(""),[M,z]=(0,i.useState)(null),[R,y]=(0,i.useState)(null),[h,C]=(0,i.useState)(""),[J,k]=(0,i.useState)(""),[Y,_]=(0,i.useState)(!1),Se=(0,i.useCallback)(async()=>{if(h){C("");return}try{let u=await fetch(`${j}/todayBrief`).then(w=>w.json());C(u.ok&&u.brief||"")}catch{}},[h]),E=(0,i.useCallback)(async()=>{if(!(!M||!M.merge||!M.merge.length)&&window.confirm(t("mergeAllConfirm"))){k("merge");try{let u={},w=K=>u[K]===void 0?K:u[K]=w(u[K]),O=(K,Z)=>{u[w(K)]=w(Z)},W=new Set;for(let K of M.merge)W.add(K.a.path),W.add(K.b.path),O(K.a.path,K.b.path);let Q={};for(let K of W){let Z=w(K);(Q[Z]=Q[Z]||[]).push(K)}let ee=0;for(let K of Object.values(Q)){if(K.length<2)continue;(await fetch(`${j}/merge?paths=${encodeURIComponent(K.join(","))}`).then(xe=>xe.json())).ok&&ee++}await U(),d&&d()}catch{}k("")}},[M,U,d,t]);async function U(){try{let u=await Promise.all([fetch(`${j}/stats`),fetch(`${j}/budget`)]),[w,O]=await Promise.all(u.map(W=>W.json()));w.ok&&o(w),O.ok&&y(O),D(w.ok?"":t("adminLoadFail"))}catch{D(t("adminLoadFail"))}}let F=(0,i.useCallback)(async()=>{k("scan");try{let u=await fetch(`${j}/optimize`).then(w=>w.json());u.ok&&z(u)}catch{D(t("adminLoadFail"))}finally{k("")}},[t]);(0,i.useEffect)(()=>{U()},[x]);let re=async(u,w)=>{if(window.confirm(t("mergeConfirm")))try{(await fetch(`${j}/merge?paths=${encodeURIComponent(u+","+w)}`).then(W=>W.json())).ok&&(await U(),d&&d())}catch{}},te=async u=>{if(window.confirm(t("deleteConfirm")))try{(await fetch(`${j}/delete?path=${encodeURIComponent(u)}`).then(O=>O.json())).ok&&(await U(),d&&d())}catch{}},he=["project","knowledge","content","prompt","business","tool","mistake"],b=({title:u,kind:w,updated:O,path:W})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:_e.colors[w]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:zt(O)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>te(W),children:[t("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"mc-admin",style:{display:"flex",flexDirection:"column",overflow:"auto",flex:1,minHeight:0},children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{style:{overflow:"auto"},children:[B&&(0,e.jsxs)("div",{className:"mc-card",style:{borderLeft:"4px solid #ef4444",background:"rgba(239,68,68,0.08)",padding:"12px 14px",marginBottom:10},children:[(0,e.jsxs)("div",{style:{fontSize:13,color:"#b91c1c",fontWeight:600,marginBottom:6},children:["\u26A0 ",B]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:U,children:["\u21BB ",t("retry")]})]}),l==="stats"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:Se,children:h?`\u{1F4D5} ${t("collapse")}`:`\u{1F4D6} ${t("todayBrief")}`}),h&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:h})]}),g&&(0,e.jsxs)(e.Fragment,{children:[g.trend&&g.trend.length>0&&(()=>{let u=g.trend,w=Math.max(...u.map(ee=>ee.count),1),O=260,W=50,Q=O/u.length;return(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,padding:"10px 14px"},children:[(0,e.jsxs)("div",{style:{fontSize:11,opacity:.6,marginBottom:4},children:["\u{1F4C8} ",t("trendLabel")]}),(0,e.jsx)("svg",{width:O,height:W,style:{display:"block",width:"100%",height:50},children:u.map((ee,K)=>{let Z=Math.round(ee.count/w*(W-4));return(0,e.jsx)("rect",{x:K*Q+1,y:W-Z,width:Math.max(Q-2,2),height:Z,rx:1.5,fill:ee.count>0?"var(--dsw-alias-accent, #3b82f6)":"var(--dsw-alias-border-l1, #e5e7eb)",opacity:ee.count>0?.85:.35},ee.date)})})]})})(),(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.total}),(0,e.jsx)("span",{children:t("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.today}),(0,e.jsx)("span",{children:t("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.week}),(0,e.jsx)("span",{children:t("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.tags}),(0,e.jsx)("span",{children:t("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:he.map(u=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:_e.colors[u]||"#666"}}),t(De[u]),": ",g.byKind?.[u]||0]},u))})]}),R&&(R.budgetChars||R.recallLimit||R.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:t("budgetLabel")}),"\uFF1A",t("budgetChars")," ",(0,e.jsx)("b",{children:R.budgetChars||8e4})," \xB7 ",t("recallLimitLabel")," ",(0,e.jsx)("b",{children:R.recallLimit||5})," \xB7 ",t("embeddingLabel")," ",R.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[t("todayList"),"\uFF08",g.todayCards?.length||0,"\uFF09"]}),g.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:g.todayCards.map(u=>(0,e.jsx)(b,{title:u.title,kind:u.kind,updated:u.updated,path:u.path},u.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})]})]}),l==="optimize"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("organizeTitle")}),(0,e.jsx)("div",{style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:!!J,onClick:F,children:J==="scan"?t("exporting"):"\u{1F50D} "+t("scanAndOrganize")}),M&&M.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!J,onClick:async()=>{if(window.confirm(t("oneClickOptimizeConfirm"))){k("oneclick");try{let u=JSON.stringify({cleanupStale:Y}),O=await(await fetch(`${j}/optimize-execute`,{method:"POST",headers:{"Content-Type":"application/json"},body:u})).json();O&&O.ok?(notify(`${t("oneClickOptimizeDone")}\uFF1A${O.plan.merged} ${t("optimizedMerged")}${Y?` \xB7 ${O.plan.staleDeleted} ${t("optimizedStaleDeleted")}`:""}`),await U(),d&&d(),z(null)):notify(t("mergeFail"),!1)}catch{notify(t("mergeFail"),!1)}finally{k("")}}},children:J==="oneclick"?t("exporting"):"\u26A1 "+t("oneClickOptimize")}),M&&M.merge?.length>0&&(0,e.jsxs)("label",{style:{fontSize:11,opacity:.7,display:"flex",alignItems:"center",gap:4},children:[(0,e.jsx)("input",{type:"checkbox",checked:Y,onChange:u=>_(u.target.checked)}),t("oneClickAlsoStale")]})]}),!M&&(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:10},children:t("scanHint")}),M&&(0,e.jsx)(e.Fragment,{children:(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",flexDirection:"column",gap:8},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:t("mergePairs")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),M.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!J,onClick:E,children:t(J==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:t("mergePairs")}),M.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:M.merge.map((u,w)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[u.a.title," \u21C4 ",u.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(u.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>re(u.a.path,u.b.path),children:t("mergeNow")})]},w))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:t("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[t("staleCards"),"\uFF08",M.stale?.length||0,"\uFF09"]}),M.stale?.length>0&&(0,e.jsx)("div",{style:{marginBottom:6},children:(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},disabled:!!J,onClick:async()=>{if(!window.confirm(t("deleteConfirm")))return;k("clean");let u=0;for(let w of M.stale)try{await fetch(`${j}/delete?path=${encodeURIComponent(w.path)}`),u++}catch{}k(""),notify(`${u} ${t("deletedStale")}`),await U(),d&&d()},children:t("cleanStale")})}),M.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:M.stale.map(u=>(0,e.jsx)(b,{title:u.title,kind:"other",updated:u.updated,path:u.path},u.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:t("noOptimize")})]})})]})]})]})}var lt=[{key:"decision",label:"tplDecision",kind:"knowledge",tags:["\u51B3\u7B56","\u65B9\u6848"],body:`# \u6280\u672F\u51B3\u7B56\uFF1A[\u6807\u9898]
137
+
138
+ ## \u80CC\u666F
139
+ - \u95EE\u9898\u63CF\u8FF0
140
+
141
+ ## \u5019\u9009\u65B9\u6848
142
+ | \u65B9\u6848 | \u4F18\u70B9 | \u7F3A\u70B9 |
143
+ | --- | --- | --- |
144
+ | A | | |
145
+ | B | | |
146
+
147
+ ## \u51B3\u7B56
148
+ \u9009\u62E9\u65B9\u6848 A\uFF0C\u539F\u56E0\uFF1A
149
+
150
+ ## \u98CE\u9669\u4E0E\u540E\u7EED
151
+ `},{key:"bug",label:"tplBug",kind:"mistake",tags:["\u8E29\u5751","\u6559\u8BAD"],body:`# \u8E29\u5751\u8BB0\u5F55\uFF1A[\u6807\u9898]
152
+
153
+ ## \u73B0\u8C61
154
+ - \u53D1\u751F\u4E86\u4EC0\u4E48
155
+
156
+ ## \u6839\u56E0
157
+
158
+ ## \u89E3\u51B3\u65B9\u6848
159
+
160
+ ## \u6559\u8BAD
161
+ - \u5982\u4F55\u907F\u514D\u4E0B\u6B21`},{key:"meeting",label:"tplMeeting",kind:"content",tags:["\u4F1A\u8BAE","\u7EAA\u8981"],body:`# \u4F1A\u8BAE\u7EAA\u8981\uFF1A[\u6807\u9898]
162
+
163
+ **\u65E5\u671F**\uFF1A
164
+ **\u53C2\u4F1A\u4EBA**\uFF1A
165
+
166
+ ## \u8BAE\u9898
167
+ 1.
168
+
169
+ ## \u7ED3\u8BBA
170
+
171
+ ## \u5F85\u529E
172
+ - [ ] `},{key:"weekly",label:"tplWeekly",kind:"content",tags:["\u5468\u62A5"],body:`# \u5468\u62A5 [YYYY-MM-DD]
173
+
174
+ ## \u672C\u5468\u5B8C\u6210
175
+ -
176
+
177
+ ## \u4E0B\u5468\u8BA1\u5212
178
+ -
179
+
180
+ ## \u98CE\u9669/\u963B\u585E
181
+ - `}];function qt({t,newCard:l,setNewCard:d,onCreated:x}){if(!l)return null;let g=lt.find(y=>y.key===l.template),o=l.body||(g?g.body:""),B=l.kind||(g?g.kind:"knowledge"),D=l.tags||(g?g.tags.join(", "):""),M=l._creating,z=y=>{let h=lt.find(C=>C.key===y);d(C=>({...C,template:y,kind:h?h.kind:C.kind,body:h?h.body:C.body,tags:h?h.tags.join(", "):C.tags}))},R=async()=>{if(!(!l.title&&!o)){d(y=>({...y,_creating:!0}));try{(await fetch(`${j}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:l.title||"\u65E0\u6807\u9898",kind:B,tags:D.split(",").map(h=>h.trim()).filter(Boolean),body:o,source:"manual"})}).then(h=>h.json())).ok?(d(null),x&&x()):d(h=>({...h,_creating:!1}))}catch{d(h=>({...h,_creating:!1}))}}};return(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>d(null),children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:600,width:"92vw",maxHeight:"85vh"},onClick:y=>y.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:t("newCard")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>d(null),children:t("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{display:"flex",flexDirection:"column",gap:10,overflow:"auto"},children:[(0,e.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[lt.map(y=>(0,e.jsx)("button",{type:"button",className:`mc-btn${l.template===y.key?" me-on":""}`,onClick:()=>z(y.key),children:t(y.label)},y.key)),(0,e.jsx)("button",{type:"button",className:`mc-btn${l.template===""?" me-on":""}`,onClick:()=>d(y=>({...y,template:"",body:"",tags:"",kind:"knowledge"})),children:"\u{1F4C4} \u7A7A\u767D"})]}),(0,e.jsx)("select",{className:"mc-btn",value:B,onChange:y=>d(h=>({...h,kind:y.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(y=>(0,e.jsx)("option",{value:y,style:{background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)"},children:y},y))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("cardTitle"),value:l.title||"",onChange:y=>d(h=>({...h,title:y.target.value}))}),(0,e.jsx)("input",{type:"text",className:"mc-btn",placeholder:t("tags")+" (\u9017\u53F7\u5206\u9694)",value:D,onChange:y=>d(h=>({...h,tags:y.target.value}))}),(0,e.jsx)("textarea",{className:"mc-btn",placeholder:t("cardBody"),value:o,onChange:y=>d(h=>({...h,body:y.target.value})),style:{minHeight:180,resize:"vertical",fontFamily:"inherit"}}),(0,e.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:M,onClick:R,children:t(M?"exporting":"createCard")})})]})]})]})}function Xt({t,card:l,query:d,onClose:x,onDelete:g,onFeedback:o}){(0,i.useEffect)(()=>{let z=R=>{R.key==="Escape"&&x()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[x]);let[B,D]=(0,i.useState)(!1),M=(l.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:x,children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{className:"me-dialog",onClick:z=>z.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:l.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[d&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>o&&o(!0),children:["\u{1F44D} ",t("fbUseful")]}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>o&&o(!1),children:["\u{1F44E} ",t("fbIrr")]})]}),M&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>D(z=>!z),children:t(B?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(t("deleteConfirm"))&&g&&g(l.path)},children:t("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:x,children:t("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:B?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:ta(l.text)}})]})]})}function Vt({t,onOpen:l,all:d,onAllChange:x,onMutate:g}){let[o,B]=(0,i.useState)(null),[D,M]=(0,i.useState)(""),z=(0,i.useCallback)(async()=>{try{let C=await(await fetch(`${j}/graph${d?"?all=1":""}`)).json();C.ok?(B(C),M("")):(B(null),M(C.error||t("error")))}catch(h){M(String(h&&h.message?h.message:h))}},[d,t]);(0,i.useEffect)(()=>{let h=!0;return fetch(`${j}/graph${d?"?all=1":""}`).then(C=>C.json()).then(C=>{h&&(C.ok?(B(C),M("")):(B(null),M(C.error||t("error"))))}).catch(C=>{h&&M(String(C&&C.message?C.message:C))}),()=>{h=!1}},[d,t]);let R=(0,i.useCallback)(async h=>{try{let J=await(await fetch(`${j}/delete?path=${encodeURIComponent(h)}`)).json();return J&&J.ok?(await z(),g&&g(),!0):!1}catch{return!1}},[z]),y=(0,i.useCallback)(async h=>{if(!h||h.length<2)return!1;try{let C=await fetch(`${j}/merge?paths=${encodeURIComponent(h.join(","))}`).then(J=>J.json());return C&&C.ok?(await z(),g&&g(),!0):!1}catch{return!1}},[z,g]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:Ce}),D&&(0,e.jsxs)("div",{className:"mc-empty",children:[t("error"),"\uFF1A",D]}),!o&&!D&&(0,e.jsx)("div",{className:"mc-empty",children:t("loading")}),o&&o.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:t("emptyGraph")}),o&&o.nodes.length>0&&(0,e.jsx)(Jt,{nodes:o.nodes,edges:o.edges,onOpen:l,onDelete:R,onMerge:y,t,all:d,onAllChange:x,countLabel:`${o.nodes.length} ${t("nodes")} \xB7 ${Gt(o.edges)} ${t("edges")}`})]})}function Gt(t){let l=new Set;for(let d of t||[])l.add([d.source,d.target].sort().join("|"));return l.size}var _e={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 Jt({nodes:t,edges:l,onOpen:d,onDelete:x,onMerge:g,t:o,countLabel:B,all:D,onAllChange:M}){let z=(0,i.useRef)(null),R=(0,i.useRef)(null),y=(0,i.useRef)(null),h=(0,i.useRef)(null),C=(0,i.useRef)(null),J=(0,i.useRef)(d);(0,i.useEffect)(()=>{J.current=d},[d]);let k=(0,i.useRef)(x);(0,i.useEffect)(()=>{k.current=x},[x]);let Y=(0,i.useRef)(g);(0,i.useEffect)(()=>{Y.current=g},[g]);let[_,Se]=(0,i.useState)(""),[E,U]=(0,i.useState)(null),F=(0,i.useRef)("");(0,i.useEffect)(()=>{F.current=_.trim().toLowerCase()},[_]),(0,i.useEffect)(()=>{let r=y.current;if(!r)return;let n=_.trim().toLowerCase();if(!n)return;let N=r.nodes.find(X=>(X.name||"").toLowerCase().includes(n));N&&(y.current.selectedId=N.id,U(N.id),r.panX=r.w/2-N.x*r.zoom,r.panY=r.h/2-N.y*r.zoom,r.render&&r.render())},[_]);let[re,te]=(0,i.useState)("all"),[he,b]=(0,i.useState)(!1),u=(0,i.useRef)("all"),[w,O]=(0,i.useState)(""),W=(0,i.useRef)(""),[Q,ee]=(0,i.useState)(!1),K=(0,i.useRef)(!1),[Z,xe]=(0,i.useState)(null);(0,i.useEffect)(()=>{u.current=re},[re]),(0,i.useEffect)(()=>{W.current=w},[w]),(0,i.useEffect)(()=>{K.current=Q},[Q]);let pe=(0,i.useMemo)(()=>{let r=new Map;for(let n of t)for(let N of n.tags||[]){let X=String(N).trim();X&&r.set(X,(r.get(X)||0)+1)}return[...r.entries()].sort((n,N)=>N[1]-n[1]).slice(0,24).map(([n,N])=>({tag:n,n:N}))},[t]),Ke=(()=>{let r=_.trim().toLowerCase();return!!r&&!t.some(n=>(n.title||n.name||"").toLowerCase().includes(r)||String(n.kind||"").toLowerCase().includes(r)||String(De[n.kind]||"").toLowerCase().includes(r))})();(0,i.useEffect)(()=>{let r=y.current;r&&r.wake&&r.wake()},[_]),(0,i.useEffect)(()=>{let r=y.current;r&&r.render&&r.render()},[re,w,Q]);let we=(0,i.useRef)(null),[ne,oe]=(0,i.useState)([]),[m,$]=(0,i.useState)(null),[H,se]=(0,i.useState)(!1),[be,Ie]=(0,i.useState)(null),[Le,Ee]=(0,i.useState)(""),de=(0,i.useRef)(null),Re=(0,i.useRef)(null),ie=(r,n=!0)=>{de.current&&clearTimeout(de.current),Ie({msg:r,ok:n}),de.current=setTimeout(()=>Ie(null),1900)},qe=r=>{Ee(r),Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>Ee(""),1600)};(0,i.useEffect)(()=>()=>{de.current&&clearTimeout(de.current),Re.current&&clearTimeout(Re.current)},[]);let ve=(0,i.useMemo)(()=>t.reduce((r,n)=>(r[n.id]=n,r),{}),[t]);return(0,i.useEffect)(()=>{let r=z.current;if(!r||t.length===0)return;let n=r.getContext("2d");if(!n)return;let N=Math.max(1,window.devicePixelRatio||1),X=()=>document.documentElement.getAttribute("data-theme")==="dark",c={};l.forEach(s=>{c[s.source]=(c[s.source]||0)+1,c[s.target]=(c[s.target]||0)+1});let I=Math.max(1,...Object.values(c)),a={nodes:t.map(s=>({id:s.id,name:s.title||"",type:s.kind||"other",r:9+Math.min(10,(c[s.id]||0)/I*8),x:0,y:0,vx:0,vy:0})),edges:l.map(s=>({sourceNodeId:s.source,targetNodeId:s.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:N,ctx:n,multi:[],marquee:null};a.domain=t,a.domainById=t.reduce((s,v)=>(s[v.id]=v,s),{}),a.nodes.forEach((s,v)=>{let f=v/a.nodes.length*Math.PI*2-Math.PI/2;s.x=Math.cos(f)*60,s.y=Math.sin(f)*60});let ae=[...new Set(a.nodes.map(s=>s.type))];a.clustered=ae.length>1,a.typeCenters={},ae.forEach((s,v)=>{let f=v/ae.length*Math.PI*2-Math.PI/2;a.typeCenters[s]={x:Math.cos(f)*160,y:Math.sin(f)*160}}),y.current=a;let ye=()=>{let s=r.clientWidth,v=r.clientHeight;a.w=s,a.h=v,r.width=s*N,r.height=v*N,n.setTransform(N,0,0,N,0,0)};ye();let Te=new ResizeObserver(ye);Te.observe(r.parentElement);let Xe=(s,v)=>s&&s.length>v?s.slice(0,v)+"\u2026":s,je=(s,v,f,S)=>{if(n.beginPath(),S==="rect")n.rect(s-f,v-f*.75,f*2,f*1.5);else if(S==="diamond")n.moveTo(s,v-f),n.lineTo(s+f,v),n.lineTo(s,v+f),n.lineTo(s-f,v),n.closePath();else if(S==="hexagon"){for(let L=0;L<6;L++){let q=Math.PI/3*L-Math.PI/2,P=s+f*Math.cos(q),me=v+f*Math.sin(q);L===0?n.moveTo(P,me):n.lineTo(P,me)}n.closePath()}else n.arc(s,v,f,0,Math.PI*2)},Fe=()=>{if(!a.nodes.length)return;let s=1/0,v=-1/0,f=1/0,S=-1/0;a.nodes.forEach(p=>{s=Math.min(s,p.x),v=Math.max(v,p.x),f=Math.min(f,p.y),S=Math.max(S,p.y)});let L=20,q=v-s+L*2,P=S-f+L*2,me=Math.min(a.w/q,a.h/P);a.zoom=Math.max(.35,Math.min(1.8,me)),a.panX=a.w/2-(s+v)/2*a.zoom,a.panY=a.h/2-(f+S)/2*a.zoom};h.current=Fe;let Be=()=>{n.clearRect(0,0,a.w,a.h),a.searchTerm=F.current,a.kindFilter=u.current,a.timeMode=K.current,a.tagFilter=W.current;let s=a.tagFilter,v=a.kindFilter,f=p=>String(p||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");n.save(),n.strokeStyle=X()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",n.lineWidth=.5;for(let p=0;p<a.w;p+=24)n.beginPath(),n.moveTo(p,0),n.lineTo(p,a.h),n.stroke();for(let p=0;p<a.h;p+=24)n.beginPath(),n.moveTo(0,p),n.lineTo(a.w,p),n.stroke();n.restore(),n.save(),n.translate(a.panX,a.panY),n.scale(a.zoom,a.zoom);let S={};a.nodes.forEach(p=>S[p.id]=p);let L=a.nodes.length>40,q=L?1.5:.55,P=a.selectedId||a.hoverId;a.edges.forEach(p=>{let V=S[p.sourceNodeId],T=S[p.targetNodeId];if(!V||!T)return;if(v!=="all"){let et=a.domainById[p.sourceNodeId]&&a.domainById[p.sourceNodeId].kind,fe=a.domainById[p.targetNodeId]&&a.domainById[p.targetNodeId].kind;if(et!==v&&fe!==v)return}if(s){let et=a.domainById[p.sourceNodeId]&&(a.domainById[p.sourceNodeId].tags||[]).includes(s),fe=a.domainById[p.targetNodeId]&&(a.domainById[p.targetNodeId].tags||[]).includes(s);if(!et&&!fe)return}let A=T.x-V.x,G=T.y-V.y,le=Math.sqrt(A*A+G*G)||1,ce=L?12:18,ue=-G/le*ce,ge=A/le*ce,Me=(V.x+T.x)/2+ue,Ne=(V.y+T.y)/2+ge,ze=_e.colors[a.domainById[V.id]&&a.domainById[V.id].kind||"other"],$e=P&&(p.sourceNodeId===P||p.targetNodeId===P),ot=P?$e?.6:.08:L?.14:.24,it=parseInt(ze.slice(1,3),16),Ge=parseInt(ze.slice(3,5),16),Qe=parseInt(ze.slice(5,7),16);n.strokeStyle="rgba("+it+","+Ge+","+Qe+","+ot+")",n.lineWidth=$e?1.6+(p.weight||1):.8+(p.weight||1)*.5,n.beginPath(),n.moveTo(V.x,V.y),n.quadraticCurveTo(Me,Ne,T.x,T.y),n.stroke()});let me=[];if(a.nodes.forEach(p=>{let V=a.domainById[p.id]||{},T=V.kind||"other",A=a.timeMode?Zt(V.updated):_e.colors[T],G=_e.shapes[T],le=a.selectedId===p.id,ce=a.hoverId===p.id,ue=a.searchTerm||"",ge=!ue||(p.name||"").toLowerCase().includes(ue)||String(De[T]||"").toLowerCase().includes(ue)||String(T).toLowerCase().includes(ue),Me=v==="all"||T===v,Ne=!s||(V.tags||[]).includes(s),ze=P&&p.id!==P&&!a.edges.some(fe=>fe.sourceNodeId===P&&fe.targetNodeId===p.id||fe.targetNodeId===P&&fe.sourceNodeId===p.id)||ue&&!ge||!Me||!Ne;n.save(),n.globalAlpha=ze?.08:1,(le||ce)&&(n.shadowColor=A,n.shadowBlur=le?20:14),je(p.x,p.y,p.r,G);let $e=parseInt(A.slice(1,3),16),ot=parseInt(A.slice(3,5),16),it=parseInt(A.slice(5,7),16),Ge=n.createRadialGradient(p.x-p.r*.3,p.y-p.r*.3,0,p.x,p.y,p.r*1.2);Ge.addColorStop(0,"rgba("+Math.min(255,$e+70)+","+Math.min(255,ot+70)+","+Math.min(255,it+70)+",0.95)"),Ge.addColorStop(1,A),n.fillStyle=Ge,n.fill(),n.restore(),le?(n.save(),je(p.x,p.y,p.r+3,G),n.strokeStyle=A,n.lineWidth=3,n.shadowColor=A,n.shadowBlur=12,n.stroke(),n.restore()):ce?(n.save(),je(p.x,p.y,p.r+2,G),n.strokeStyle=A,n.lineWidth=2,n.stroke(),n.restore()):ue&&ge?(n.save(),je(p.x,p.y,p.r+2,G),n.strokeStyle="#e11d48",n.lineWidth=2,n.stroke(),n.restore()):a.multi.indexOf(p.id)>=0&&(n.save(),je(p.x,p.y,p.r+2,G),n.strokeStyle="#60a5fa",n.lineWidth=2,n.shadowColor="#60a5fa",n.shadowBlur=8,n.stroke(),n.restore());let Qe=Xe(p.name,16);if((le||ce||a.zoom>q||!L&&a.zoom>.6)&&Me&&Ne){let fe=1/a.zoom;n.font="500 "+(12*fe).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let Ae=n.measureText(Qe).width+16*fe,tt=18*fe,Pe=p.y+p.r+8*fe,yt=!0;for(let Oe of me)if(p.x-Ae/2<Oe.x+Oe.w&&p.x+Ae/2>Oe.x&&Pe<Oe.y+Oe.h&&Pe+tt>Oe.y){yt=!1;break}if(!yt&&!le&&!ce)return;me.push({x:p.x-Ae/2,y:Pe,w:Ae,h:tt}),n.fillStyle=X()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",n.beginPath(),n.roundRect?n.roundRect(p.x-Ae/2,Pe,Ae,tt,4*fe):n.rect(p.x-Ae/2,Pe,Ae,tt),n.fill(),n.strokeStyle=X()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",n.lineWidth=1*fe,n.stroke(),n.fillStyle=X()?le||ce?"#eee":"#bbb":le||ce?"#111":"#444",n.textAlign="center",n.fillText(Qe,p.x,Pe+13*fe)}}),n.restore(),a.marquee){let p=a.marquee,V=Math.min(p.sx,p.ex),T=Math.min(p.sy,p.ey),A=Math.abs(p.ex-p.sx),G=Math.abs(p.ey-p.sy);n.save(),n.setLineDash([4,4]),n.strokeStyle="rgba(96,165,250,0.9)",n.lineWidth=1,n.fillStyle="rgba(96,165,250,0.12)",n.fillRect(V,T,A,G),n.strokeRect(V,T,A,G),n.restore()}if(a.hoverId&&we.current){let p=a.domainById[a.hoverId],V=a.nodes.find(function(T){return T.id===a.hoverId});if(p&&V){let T=a.edges.filter(function(le){return le.sourceNodeId===p.id||le.targetNodeId===p.id}).length,A=V.x*a.zoom+a.panX,G=V.y*a.zoom+a.panY;we.current.style.display="block",we.current.style.left=A+14+"px",we.current.style.top=G-6+"px",we.current.innerHTML="<b>"+f(p.title||p.name||"")+'</b><br/><span style="opacity:.8">'+f(p.kind||"")+" \xB7 "+T+" \u8FDE\u63A5</span>"}}else we.current&&(we.current.style.display="none")},ke=()=>{a.running=!0,a.raf||(a.raf=requestAnimationFrame(dt))};a.wake=ke,a.render=Be;let st=()=>{let s=a.nodes.length;a.tickCount++;let f=.9-Math.min(.4,a.tickCount/1500),S=s>1e3?3e3:s>100?2e3:s>50?1200:800,L=s>100?.002:.005,q=s>1e3?.012:s>100?.005:.01,P=s>1e3?6:s>200?12:24,me={};a.nodes.forEach(T=>me[T.id]=T);for(let T=0;T<s;T++){if(a.dragNode===a.nodes[T])continue;let A=a.nodes[T],G=0,le=0;for(let ge=0;ge<s;ge++){if(T===ge)continue;let Me=A.x-a.nodes[ge].x,Ne=A.y-a.nodes[ge].y,ze=Math.sqrt(Me*Me+Ne*Ne)||1,$e=S/(ze*ze);G+=Me/ze*$e,le+=Ne/ze*$e}if(a.clustered&&a.typeCenters[A.type]){let ge=a.typeCenters[A.type];G+=(ge.x-A.x)*.006,le+=(ge.y-A.y)*.006}else G-=A.x*q,le-=A.y*q;let ce=(A.vx+G)*f,ue=(A.vy+le)*f;ce=Math.max(-P,Math.min(P,ce)),ue=Math.max(-P,Math.min(P,ue)),A.vx=ce,A.vy=ue}a.edges.forEach(T=>{let A=me[T.sourceNodeId],G=me[T.targetNodeId];if(!A||!G)return;let le=G.x-A.x,ce=G.y-A.y,ue=Math.sqrt(le*le+ce*ce)||1,ge=(ue-100)*L,Me=le/ue*ge,Ne=ce/ue*ge;a.dragNode!==A&&(A.vx+=Me,A.vy+=Ne),a.dragNode!==G&&(G.vx-=Me,G.vy-=Ne)});let p=0;a.nodes.forEach(T=>{a.dragNode!==T&&(T.x+=T.vx,T.y+=T.vy,p+=T.vx*T.vx+T.vy*T.vy)}),a.autoFitPending&&a.tickCount>45&&(a.autoFitPending=!1,Fe()),(s?Math.sqrt(p/s):0)<.05&&a.tickCount>60&&!a.dragNode?a.quietTicks=(a.quietTicks|0)+1:a.quietTicks=0},dt=()=>{if(a.running){try{st(),Be()}catch{}if(a.quietTicks>30){a.raf=0;return}a.raf=requestAnimationFrame(dt)}},Ve=(s,v)=>{let f=r.getBoundingClientRect();return{x:(s-f.left-a.panX)/a.zoom,y:(v-f.top-a.panY)/a.zoom}},Je=s=>{let v=a.domainById[s];return!(!v||u.current!=="all"&&v.kind!==u.current||W.current&&!(v.tags||[]).includes(W.current))},Ze=(s,v,f)=>Math.max(v,Math.min(f,s)),ct=s=>{a.mouseX=s.clientX,a.mouseY=s.clientY;let v=Ve(s.clientX,s.clientY),f=null;for(let S=a.nodes.length-1;S>=0;S--){let L=a.nodes[S];if(!Je(L.id))continue;let q=L.x-v.x,P=L.y-v.y;if(q*q+P*P<L.r*L.r+36){f=L.id;break}}f!==a.hoverId&&(a.hoverId=f,ke())},pt=s=>{if(s.button!==0)return;let v=Ve(s.clientX,s.clientY),f=null;for(let S=a.nodes.length-1;S>=0;S--){let L=a.nodes[S];if(!Je(L.id))continue;let q=L.x-v.x,P=L.y-v.y;if(q*q+P*P<L.r*L.r+25){f=L;break}}if(s.shiftKey){if(f){a.shiftClick=f.id;return}a.marquee={sx:s.clientX,sy:s.clientY,ex:s.clientX,ey:s.clientY};return}a.dragStart={x:s.clientX,y:s.clientY,px:a.panX,py:a.panY},a.dragging=!1,a.dragNode=f||null,f&&(a.dragOffset={dx:f.x-v.x,dy:f.y-v.y})},mt=s=>{if(a.marquee){a.marquee.ex=s.clientX,a.marquee.ey=s.clientY,ke();return}if(!a.dragStart)return;let v=s.clientX-a.dragStart.x,f=s.clientY-a.dragStart.y;if(Math.abs(v)+Math.abs(f)>3&&(a.dragging=!0),a.dragNode){let S=Ve(s.clientX,s.clientY);a.dragNode.x=S.x+a.dragOffset.dx,a.dragNode.y=S.y+a.dragOffset.dy,ke()}else a.dragging&&(a.panX=Ze(a.dragStart.px+v,-1e5,1e5),a.panY=Ze(a.dragStart.py+f,-1e5,1e5),ke())},ut=s=>{if(a.marquee){let f=a.marquee;a.marquee=null;let S=r.getBoundingClientRect(),L=Math.min(f.sx,f.ex)-S.left,q=Math.max(f.sx,f.ex)-S.left,P=Math.min(f.sy,f.ey)-S.top,me=Math.max(f.sy,f.ey)-S.top,p=a.nodes.filter(V=>{let T=V.x*a.zoom+a.panX,A=V.y*a.zoom+a.panY;return T>=L&&T<=q&&A>=P&&A<=me}).map(V=>V.id);a.multi=p,oe(p),ke();return}let v=a.dragStart&&!a.dragging;if(a.shiftClick){let f=a.shiftClick;a.shiftClick=null;let S=Array.isArray(a.multi)?a.multi.slice():[];S.includes(f)||S.push(f),a.multi=S,oe(S),ke();return}if(v){let f=Ve(s.clientX,s.clientY),S=null;for(let L=a.nodes.length-1;L>=0;L--){let q=a.nodes[L];if(!Je(q.id))continue;let P=q.x-f.x,me=q.y-f.y;if(P*P+me*me<q.r*q.r+20){S=q;break}}S?(a.selectedId=S.id,U(S.id),ke()):(a.selectedId=null,a.hoverId=null,s.shiftKey||(a.multi=[],oe([])),U(null),ke())}a.dragStart=null,a.dragging=!1,a.dragNode=null},gt=s=>{s.preventDefault();let v=Ve(s.clientX,s.clientY),f=null;for(let S=a.nodes.length-1;S>=0;S--){let L=a.nodes[S];if(!Je(L.id))continue;let q=L.x-v.x,P=L.y-v.y;if(q*q+P*P<L.r*L.r+25){f=L;break}}if(f){let S=a.domainById[f.id];S&&xe({x:s.clientX,y:s.clientY,id:f.id,path:S.id,title:S.title})}else xe(null)},ft=s=>{s.preventDefault();let v=r.getBoundingClientRect(),f=(s.clientX-v.left-a.panX)/a.zoom,S=(s.clientY-v.top-a.panY)/a.zoom,L=Math.max(.3,Math.min(3,a.zoom*(s.deltaY<0?1.1:1/1.1)));a.panX=Ze(a.panX+f*(a.zoom-L),-1e5,1e5),a.panY=Ze(a.panY+S*(a.zoom-L),-1e5,1e5),a.zoom=L,ke()};r.addEventListener("mousemove",ct),r.addEventListener("mousedown",pt),window.addEventListener("mousemove",mt),window.addEventListener("mouseup",ut),r.addEventListener("wheel",ft,{passive:!1}),r.addEventListener("contextmenu",gt),C.current=()=>{a.selectedId=null,a.hoverId=null,a.multi=[],oe([]),Fe(),ke()};for(let s=0;s<200;s++)st();Fe(),ke();let bt=()=>b(!1);return window.addEventListener("mousedown",bt),()=>{a.running=!1,a.raf&&cancelAnimationFrame(a.raf),Te.disconnect(),r.removeEventListener("mousemove",ct),r.removeEventListener("mousedown",pt),window.removeEventListener("mousemove",mt),window.removeEventListener("mouseup",ut),r.removeEventListener("wheel",ft),r.removeEventListener("contextmenu",gt),window.removeEventListener("mousedown",bt)}},[t,l]),(0,e.jsxs)("div",{className:"me-graph",ref:R,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[t.length," ",o("nodes")," \xB7 ",l.length," ",o("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",placeholder:o("search"),value:_,onChange:r=>Se(r.target.value)}),(0,e.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,e.jsxs)("button",{type:"button",className:"mc-btn",onClick:()=>b(r=>!r),"aria-expanded":he,title:"\u7B5B\u9009",style:{borderRadius:8},children:["\u{1F50D} ",o("filterLabel")," ",re!=="all"||Q||w?"\u25CF":"\u25BE"]}),he&&(0,e.jsx)("div",{className:"me-graph-legend-pop",onMouseDown:r=>r.stopPropagation(),style:{position:"absolute",top:"calc(100% + 6px)",left:0,zIndex:50,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,padding:8,minWidth:240,boxShadow:"0 12px 34px rgba(0,0,0,.35)"},children:(0,e.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,e.jsx)("button",{type:"button",className:`lg${re==="all"&&!Q?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>{te("all"),ee(!1)},children:o("all")}),Object.keys(Ue).map(r=>(0,e.jsxs)("button",{type:"button",className:`lg${re===r?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>te(n=>n===r?"all":r),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:_e.colors[r]||Ue[r]}}),o(De[r])]},r)),(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsxs)("button",{type:"button",className:`lg${Q?" active":""}`,style:{justifyContent:"flex-start"},onClick:()=>ee(r=>!r),children:["\u23F1 ",o("timeDim")]}),pe.length>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{height:1,background:"rgba(255,255,255,0.1)",margin:"4px 0"}}),(0,e.jsx)("div",{style:{maxHeight:130,overflow:"auto",display:"flex",flexWrap:"wrap",gap:4},children:pe.map(r=>(0,e.jsxs)("button",{type:"button",className:`lg${w===r.tag?" active":""}`,style:{color:"#ddd",padding:"2px 7px",fontSize:11},onClick:()=>O(n=>n===r.tag?"":r.tag),title:r.tag,children:["#",r.tag," ",(0,e.jsx)("span",{style:{opacity:.55},children:r.n})]},r.tag))})]}),(re!=="all"||Q||w)&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",style:{justifyContent:"flex-start",color:"#f87171"},onClick:()=>{te("all"),ee(!1),O("")},children:[o("clearFilter")," \u2715"]})]})})]}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:!!D,onChange:r=>M&&M(r.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:`mc-btn${Q?" me-on":""}`,onClick:()=>ee(r=>!r),children:o("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let r=z.current;if(r)try{r.toBlob(n=>{n&&$({url:URL.createObjectURL(n),blob:n})},"image/png")}catch{}},children:o("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>h.current&&h.current(),children:o("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{U(null),te("all"),C.current&&C.current()},children:o("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:z,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:we,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)"}}),Ke&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:o("noMatch")}),Z&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>xe(null)}),Z&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:Z.x,top:Z.y,zIndex:31},onMouseDown:r=>r.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{J.current({path:Z.path,title:Z.title}),xe(null)},children:o("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{Z.id&&(y.current.selectedId=Z.id,U(Z.id)),xe(null);let r=y.current;r&&r.wake&&r.wake()},children:o("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(Z.title||"")}catch{}xe(null),ie(o("copied"))},children:o("copyName")}),(0,e.jsx)("button",{type:"button",onClick:()=>{let r=y.current,n=r&&Array.isArray(r.multi)?r.multi.slice():[],N=Z.id;if(N&&!n.includes(N)&&n.push(N),xe(null),n.length<2){ie(o("mergeNeed"),!1);return}if(!window.confirm(o("mergeConfirm")))return;let X=Y.current&&Y.current(n);X&&X.then?X.then(c=>c?ie(o("merged")):ie(o("mergeFail"),!1)).catch(()=>ie(o("mergeFail"),!1)):X&&ie(o("merged"))},children:o("merge")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let r=Z.path;xe(null),window.confirm(o("deleteConfirm"))&&(async()=>{try{(k.current?await k.current(r):!1)?ie(o("deleted")):ie(o("deleteFail"),!1)}catch{ie(o("deleteFail"),!1)}})()},children:o("delete")})]}),ne.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[ne.length," ",o("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let n=ne.map(I=>ve[I]).filter(Boolean).map(I=>I.title||I.name).join(`
182
+ `),N=new Blob([n],{type:"text/plain;charset=utf-8"}),X=URL.createObjectURL(N),c=document.createElement("a");c.href=X,c.download="memory-selected.txt",document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(X),1e3),ie(ne.length+o("exportedSel"))},children:o("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(ne.length<2){ie(o("mergeNeed"),!1);return}let r=ne.map(N=>ve[N]?ve[N].id:N);if(!window.confirm(o("mergeConfirm")))return;oe([]);let n=y.current;n&&(n.multi=[]),fetch(`${j}/merge?paths=${encodeURIComponent(r.join(","))}`).then(N=>N.json()).then(N=>{N&&N.ok?ie(o("merged")):ie(o("mergeFail"),!1)}).catch(()=>ie(o("mergeFail"),!1))},children:o("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(o("deleteConfirm")))return;let r=ne.map(N=>ve[N]?ve[N].id:N);oe([]);let n=y.current;n&&(n.multi=[]),(async()=>{let N=0;for(let X of r)try{(k.current?await k.current(X):!1)&&N++}catch{}ie(N+o("deletedSelected"),N>0)})()},children:o("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let r=y.current;r&&(r.multi=[]),oe([]);let n=y.current;n&&n.render&&n.render()},children:o("clearSelection")})]}),E&&(0,e.jsxs)("div",{className:"me-graph-sidebar",style:{position:"absolute",right:10,top:10,zIndex:3,maxWidth:240,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:12,fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:ve[E]?ve[E].title||ve[E].name:E}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:ve[E]?o(De[ve[E].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:o("graphHint")}),(l.filter(r=>r.source===E||r.target===E)||[]).slice(0,8).map((r,n)=>{let N=r.source===E?r.target:r.source,X=ve[N];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:c=>{c.preventDefault();let I=y.current;I&&(I.selectedId=N,I.hoverId=N,I.wake&&I.wake()),U(N)},children:X?(X.title||X.name).slice(0,28):N},n)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:o("graphTip")}),be&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(be.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:be.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:be.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:be.msg})]}),m&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{m.url&&URL.revokeObjectURL(m.url),$(null),se(!1)},children:[(0,e.jsx)("style",{children:Ce}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:H?"100vw":900,width:H?"100vw":"92vw",maxHeight:H?"100vh":"90vh",height:H?"100vh":void 0,borderRadius:H?0:14},onClick:r=>r.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:o("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:m.url,download:"memory-graph.png",onClick:()=>{qe("download"),ie(o("downloaded")+" \xB7 "+o("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:o(Le==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{qe("full"),se(r=>!r),ie(o("fullscreen"))},children:o(Le==="full"?"done":H?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let r=m.blob;r&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":r})]).then(()=>{qe("copy"),ie(o("copied"))}).catch(()=>{ie(o("copyFail"),!1)}):ie(o("copyFail"),!1)},children:o(Le==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{m.url&&URL.revokeObjectURL(m.url),$(null),se(!1)},children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:H?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:m.url,alt:o("exportGraph"),style:{maxWidth:"100%",maxHeight:H?"calc(100vh - 64px)":"70vh",borderRadius:H?0:8,cursor:"zoom-in"},onClick:()=>se(r=>!r)})})]})]})]})}function Zt(t){let l=new Date(t||0).getTime();if(!l)return"#94a3b8";let d=(Date.now()-l)/864e5;return d<3?"#10b981":d<14?"#f59e0b":d<30?"#f97316":"#94a3b8"}function vt({label:t,value:l=[],options:d,onChange:x,placeholder:g,z:o=20}){let[B,D]=(0,i.useState)(!1),M=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!B)return;let k=Y=>{M.current&&!M.current.contains(Y.target)&&D(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[B]);let z=Array.isArray(l)?l:[],R=z.includes("__all__"),y=R?d.find(k=>k.value==="__all__")?.label||"":z.length?z.map(k=>d.find(Y=>Y.value===k)?.label||k).join("\u3001"):"",h=(k,Y)=>{if(k.value==="__all__"){x(Y?["__all__"]:[]);return}let _=new Set(z);_.has("__all__")&&_.delete("__all__"),Y?_.add(k.value):_.delete(k.value),x([..._])},C=d.find(k=>k.value==="__all__"),J=d.filter(k=>k.value!=="__all__");return(0,e.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:3,fontSize:12},children:[(0,e.jsx)("span",{style:{opacity:.6},children:t}),(0,e.jsxs)("div",{ref:M,style:{position:"relative"},children:[(0,e.jsxs)("button",{type:"button",onClick:()=>D(k=>!k),style:{width:"100%",textAlign:"left",padding:"6px 8px",borderRadius:8,border:"1px solid var(--dsw-alias-border-l2, #d1d5db)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"inherit",fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[(0,e.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y||g||"\u2014"}),(0,e.jsx)("span",{style:{fontSize:10,opacity:.7},children:"\u25BE"})]}),B&&(0,e.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,right:0,zIndex:o,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:[C&&(0,e.jsxs)("label",{onClick:k=>k.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("input",{type:"checkbox",checked:R,onChange:k=>h(C,k.target.checked)}),(0,e.jsx)("span",{children:C.label})]}),J.map(k=>(0,e.jsxs)("label",{onClick:Y=>Y.stopPropagation(),style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",cursor:"pointer"},children:[(0,e.jsx)("input",{type:"checkbox",checked:z.includes(k.value),onChange:Y=>h(k,Y.target.checked)}),(0,e.jsx)("span",{children:k.label})]},k.value))]})]})]})}function Qt(t){let l=new Date(t||0).getTime();return!!l&&(Date.now()-l)/864e5<3}async function ea(t,l,d){if(d&&typeof window.showSaveFilePicker=="function")try{let o=await window.showSaveFilePicker({suggestedName:l}),B=await o.createWritable();return await B.write(t),await B.close(),{ok:!0,picked:!0,name:o.name}}catch(o){return o&&o.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(o.message||o)}}let x=URL.createObjectURL(t),g=document.createElement("a");return g.href=x,g.download=l,document.body.appendChild(g),g.click(),document.body.removeChild(g),setTimeout(()=>URL.revokeObjectURL(x),1e3),{ok:!0,picked:!1,name:l}}function wt(t,l){if(!l||!t)return t;let d=t.toLowerCase(),x=l.toLowerCase(),g=[],o=0;for(;o<t.length;){let B=d.indexOf(x,o);if(B<0){g.push(t.slice(o));break}B>o&&g.push(t.slice(o,B)),g.push((0,e.jsx)("mark",{className:"mc-hl",children:t.slice(B,B+x.length)},B)),o=B+x.length}return g}function ta(t){if(!t)return"";let l=String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),d=[];return l=l.replace(/```([\w-]*)\n([\s\S]*?)```/g,function(x,g,o){return d.push("<pre><code>"+o+"</code></pre>"),"\0"+(d.length-1)+"\0"}),l=l.replace(/^(#{1,3})\s+(.+)$/gm,function(x,g,o){return"<h"+g.length+">"+o+"</h"+g.length+">"}),l=l.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),l=l.replace(/`([^`\n]+)`/g,"<code>$1</code>"),l=l.replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>"),l=l.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(x,g,o){return/^(https?:|\/)/.test(o)?'<a href="'+o+'" target="_blank" rel="noopener noreferrer">'+g+"</a>":g}),l=l.replace(/^(-)\s+(.+)$/gm,"\u2022 $2"),l=l.replace(/^\s*(&gt;)\s*(.+)$/gm,"<blockquote>$2</blockquote>"),l=l.replace(/\n/g,"<br/>"),l=l.replace(/\u0000(\d+)\u0000/g,function(x,g){return d[g]}),l}function zt(t){if(!t)return"";let l=new Date(t);if(Number.isNaN(l.getTime()))return"";let d=new Date,x=l.toDateString()===d.toDateString(),g=B=>String(B).padStart(2,"0"),o=`${g(l.getHours())}:${g(l.getMinutes())}`;return x?o:`${l.getMonth()+1}-${l.getDate()} ${o}`}
183
+
184
+ return module.exports;
185
+ },
186
+ });
@@ -0,0 +1,84 @@
1
+ // 记忆核心 · OpenAI 兼容 LLM 适配器(独立进程用)。
2
+ //
3
+ // 在没有 DSH llm 服务的环境(MCP server / CLI / web / hooks)里,为
4
+ // lib/capture.js 的 summarizeTurn 提供同形状的 llm 对象:
5
+ // - listProviders() / listModels() → 供 resolveRoute 解析路由
6
+ // - stream(options) → async iterable,yield 纯文本 chunk(由 capture.js
7
+ // fallback BlockAssembler 拼装)
8
+ //
9
+ // 配置(环境变量,或显式传参覆盖):
10
+ // MEMORY_LLM_BASE_URL OpenAI 兼容端点,如 https://api.deepseek.com、
11
+ // http://127.0.0.1:11434/v1(Ollama)等
12
+ // MEMORY_LLM_KEY API key(本地端点可留空)
13
+ // MEMORY_LLM_MODEL 模型名,如 deepseek-chat
14
+ // 未配置时 createLlmFromEnv() 返回 null:调用方应降级(recall 不受影响,
15
+ // capture 退化为存原文卡)。
16
+
17
+ function flatContent(content) {
18
+ if (typeof content === 'string') return content
19
+ if (Array.isArray(content)) {
20
+ return content
21
+ .map((c) => (typeof c === 'string' ? c : c?.text ?? ''))
22
+ .filter(Boolean)
23
+ .join('\n')
24
+ }
25
+ return String(content ?? '')
26
+ }
27
+
28
+ export function createOpenAiLlm({ baseUrl, apiKey = '', model, purpose = 'memory-capture' } = {}) {
29
+ if (!baseUrl || !model) return null
30
+ const endpoint = baseUrl.replace(/\/+$/, '') + '/chat/completions'
31
+
32
+ return {
33
+ purpose,
34
+
35
+ listProviders() {
36
+ return [{ id: 'openai-compat' }]
37
+ },
38
+
39
+ async listModels() {
40
+ return [{ id: model }]
41
+ },
42
+
43
+ /**
44
+ * 非流式调用,整体作为单个 chunk yield(capture 的蒸馏一次性输出 JSON,
45
+ * 无需逐 token 流式)。signal 超时/中断会向上抛出。
46
+ */
47
+ async *stream(options = {}) {
48
+ const messages = []
49
+ if (options.system) messages.push({ role: 'system', content: options.system })
50
+ for (const m of options.messages ?? []) {
51
+ messages.push({ role: m?.role ?? 'user', content: flatContent(m?.content) })
52
+ }
53
+ const body = {
54
+ model: options.model || model,
55
+ messages,
56
+ max_tokens: options.maxTokens ?? 900,
57
+ stream: false,
58
+ }
59
+ const headers = { 'Content-Type': 'application/json' }
60
+ if (apiKey) headers.Authorization = `Bearer ${apiKey}`
61
+ const res = await fetch(endpoint, {
62
+ method: 'POST',
63
+ headers,
64
+ body: JSON.stringify(body),
65
+ signal: options.signal ?? undefined,
66
+ })
67
+ if (!res.ok) {
68
+ const detail = await res.text().catch(() => '')
69
+ throw new Error(`[memory-eternal] LLM ${res.status}: ${detail.slice(0, 300)}`)
70
+ }
71
+ const data = await res.json()
72
+ const text = data?.choices?.[0]?.message?.content ?? ''
73
+ if (text) yield text
74
+ },
75
+ }
76
+ }
77
+
78
+ export function createLlmFromEnv(env = process.env) {
79
+ const baseUrl = env.MEMORY_LLM_BASE_URL || env.OPENAI_BASE_URL || ''
80
+ const apiKey = env.MEMORY_LLM_KEY || env.OPENAI_API_KEY || ''
81
+ const model = env.MEMORY_LLM_MODEL || ''
82
+ if (!baseUrl || !model) return null
83
+ return createOpenAiLlm({ baseUrl, apiKey, model })
84
+ }