dsh-memory-eternal 0.4.5 → 0.4.6
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/README.md +8 -7
- package/index.js +40 -4
- package/lib/client.js +4 -4
- package/lib/vault.js +56 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -215,18 +215,19 @@ dsh-memory-eternal/
|
|
|
215
215
|
- **会话预算**(`sessionBudgetChars` + `/budget`)
|
|
216
216
|
|
|
217
217
|
**待办(核心功能优化)**:
|
|
218
|
-
- [x] ~~多 Vault / 多 Profile~~、~~注入体积可配置~~、~~每日回顾+用量~~、~~自动归档整理~~、~~召回用户反馈~~、~~会话级 token
|
|
219
|
-
- [
|
|
220
|
-
- [ ]
|
|
221
|
-
- [ ]
|
|
222
|
-
- [ ]
|
|
223
|
-
- [ ]
|
|
218
|
+
- [x] ~~多 Vault / 多 Profile~~、~~注入体积可配置~~、~~每日回顾+用量~~、~~自动归档整理~~、~~召回用户反馈~~、~~会话级 token 预算~~(v0.4.5)
|
|
219
|
+
- [x] ~~批量智能合并~~(相似度预分组一键合并)、~~跨库聚合图谱/检索~~(vault 级)、~~语义召回升级~~(本地 bigram 语义加分,`recallEmbedding` 预留 embedding)、~~每日回顾定时生成~~(00-System/daily-*,30min 轮询幂等)(v0.4.6)
|
|
220
|
+
- [ ] **上下文压缩接入 harness**:记忆侧 `/compress` 已就绪,待 harness 在会话内调「召回替代 + 压缩旧轮」(需 harness 配合)
|
|
221
|
+
- [ ] 多 Vault 的**跨库合并/去重**(跨 profile 识别重复卡)
|
|
222
|
+
- [ ] 语义召回**接入外部 embedding provider**(当前为本地零依赖加分)
|
|
223
|
+
- [ ] 每日回顾**主动推送通道**(当前生成文件 + 手动查看,推送需 harness/通知渠道)
|
|
224
224
|
|
|
225
225
|
---
|
|
226
226
|
|
|
227
227
|
## 📦 发布记录
|
|
228
228
|
|
|
229
|
-
- **v0.4.
|
|
229
|
+
- **v0.4.6**:记忆侧优化**收官**——**批量智能合并**(按相似度并查集聚类、一键合并多组)、**跨库聚合图谱/检索**(`?all=1`,多 Vault 合并展示)、**语义召回升级**(本地 Jaccard bigram 语义加分,`recallEmbedding` 预留 embedding)、**每日回顾定时生成**(`00-System/daily-YYYY-MM-DD.md`,30 分钟轮询幂等)、**今日简报**(`/todayBrief`,管理面板一键查看)。
|
|
230
|
+
- **v0.4.5**:记忆侧**核心功能优化**——**注入体积可配置**、**多 Vault/多 Profile**、**每日回顾+用量统计**、**自动归档整理建议**(非破坏预览)、**召回用户反馈**、**会话级 token 预算**、**上下文压缩接口**(`/compress`)。
|
|
230
231
|
- **v0.4.3**:记忆侧**省 token/提质量**——沉淀预筛(无可复用信号直接跳过、不触发 LLM);召回按 `minScore` 过滤弱命中、注入片段截断到 130 字。
|
|
231
232
|
- **v0.4.2**:修复 GitHub/npm 顶部演示 GIF 无法显示(压缩至 README 10MB 阈值以下,8MB)。
|
|
232
233
|
- **v0.4.1**:Marketplace 收录标准落地(`dsh.marketplace` 元数据 + 自动扫描规则说明)。
|
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import path from 'node:path'
|
|
|
19
19
|
import os from 'node:os'
|
|
20
20
|
import z from '@deepseek-ai/schemastery'
|
|
21
21
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
22
|
-
import { ensureVault, listCards, readCard, search, graph, overview, exportCards, deleteCard, writeCard, parseCard, stats, optimizeCandidates, readFeedback, addFeedback } from './lib/vault.js'
|
|
22
|
+
import { ensureVault, listCards, readCard, search, searchAll, graph, graphAll, overview, exportCards, deleteCard, writeCard, parseCard, stats, optimizeCandidates, readFeedback, addFeedback, dailyBrief, generateDailyBrief } from './lib/vault.js'
|
|
23
23
|
import { compressExcerpt } from './lib/capture.js'
|
|
24
24
|
import { summarizeTurn, extractLastTurn, sliceNewEvents, resolveRoute, captureCard, captureUpdate, pickNeighbors } from './lib/capture.js'
|
|
25
25
|
|
|
@@ -65,7 +65,22 @@ export function apply(ctx, config) {
|
|
|
65
65
|
return path.join(home, 'memory-vault')
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
//
|
|
68
|
+
// 所有 profile 目录(当前激活 + 其余命名的),供跨库聚合。
|
|
69
|
+
const vaultRoots = () => {
|
|
70
|
+
const cfg = settings.get() ?? {}
|
|
71
|
+
const active = vaultDir()
|
|
72
|
+
const roots = [{ name: '', root: active }]
|
|
73
|
+
const seen = new Set([active])
|
|
74
|
+
const profiles = Array.isArray(cfg.vaultProfiles) ? cfg.vaultProfiles : []
|
|
75
|
+
for (const p of profiles) {
|
|
76
|
+
if (!p || !p.path || !p.path.trim()) continue
|
|
77
|
+
const r = path.resolve(p.path.trim())
|
|
78
|
+
if (seen.has(r)) continue
|
|
79
|
+
seen.add(r)
|
|
80
|
+
roots.push({ name: p.name || r, root: r })
|
|
81
|
+
}
|
|
82
|
+
return roots
|
|
83
|
+
}
|
|
69
84
|
// agent/turn-stopping 是 serial 事件:不在监听器里 await LLM(会拖慢收尾),
|
|
70
85
|
// 同步抓取增量事件快照后,把真正的捕获调度到后台队列执行。
|
|
71
86
|
const pending = new Map() // sessionId -> merged events array
|
|
@@ -223,6 +238,17 @@ export function apply(ctx, config) {
|
|
|
223
238
|
}))
|
|
224
239
|
}
|
|
225
240
|
|
|
241
|
+
// 每日回顾:每 30 分钟检查一次,跨天就生成当日简报文件(幂等,凌晨/首日各一次)。
|
|
242
|
+
let lastBriefDate = ''
|
|
243
|
+
const briefTimer = setInterval(() => {
|
|
244
|
+
const d = new Date()
|
|
245
|
+
const date = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
246
|
+
if (lastBriefDate === date) return
|
|
247
|
+
lastBriefDate = date
|
|
248
|
+
generateDailyBrief(vaultDir()).catch(() => {})
|
|
249
|
+
}, 30 * 60 * 1000)
|
|
250
|
+
ctx.effect(() => () => clearInterval(briefTimer), 'memory-eternal: daily brief timer')
|
|
251
|
+
|
|
226
252
|
// -- 3. 知识库 JSON API(客户端设置页数据源) ----------------------------
|
|
227
253
|
const webServer = ctx.get('webServer')
|
|
228
254
|
if (webServer !== undefined) {
|
|
@@ -283,12 +309,22 @@ async function handleApi(req, res, vaultRoot) {
|
|
|
283
309
|
case '/search': {
|
|
284
310
|
const q = query.get('q') || ''
|
|
285
311
|
if (!q.trim()) return json(res, 200, { ok: true, hits: [] })
|
|
286
|
-
|
|
312
|
+
const all = query.get('all') === '1'
|
|
313
|
+
const semantic = query.get('semantic') === '1'
|
|
314
|
+
const hits = all ? await searchAll(vaultRoots(), q, { limit: 30, semantic }) : await search(vaultRoot, q, { limit: 30, semantic })
|
|
315
|
+
json(res, 200, { ok: true, hits })
|
|
287
316
|
return
|
|
288
317
|
}
|
|
289
318
|
case '/graph': {
|
|
290
319
|
await ensureVault(vaultRoot)
|
|
291
|
-
|
|
320
|
+
const all = query.get('all') === '1'
|
|
321
|
+
json(res, 200, { ok: true, ...(all ? await graphAll(vaultRoots()) : await graph(vaultRoot)) })
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
case '/todayBrief': {
|
|
325
|
+
await ensureVault(vaultRoot)
|
|
326
|
+
const s = await stats(vaultRoot)
|
|
327
|
+
json(res, 200, { ok: true, today: s.today, brief: dailyBrief(s.todayCards) })
|
|
292
328
|
return
|
|
293
329
|
}
|
|
294
330
|
case '/export': {
|
package/lib/client.js
CHANGED
|
@@ -3,7 +3,7 @@ window.__ModuleLoader__.load({
|
|
|
3
3
|
factory: (require) => {
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
|
-
var st=Object.create;var
|
|
6
|
+
var st=Object.create;var Pe=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var mt=(o,s)=>{for(var m in s)Pe(o,m,{get:s[m],enumerable:!0})},tt=(o,s,m,u)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of ct(s))!pt.call(o,n)&&n!==m&&Pe(o,n,{get:()=>s[n],enumerable:!(u=lt(s,n))||u.enumerable});return o};var ut=(o,s,m)=>(m=o!=null?st(dt(o)):{},tt(s||!o||!o.__esModule?Pe(m,"default",{value:o,enumerable:!0}):m,o)),gt=o=>tt(Pe({},"__esModule",{value:!0}),o);var Bt={};mt(Bt,{apply:()=>xt,inject:()=>ft});module.exports=gt(Bt);var c=ut(require("react"),1),e=require("react/jsx-runtime"),Be="memory-eternal",U="/memory-eternal/api",ft=["settingsScope","slots","locale","connection","remote"],bt={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",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",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",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}",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"},ht={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",exportGraph:"Export",openCard:"Open card",focusNeighbors:"Highlight links",copyName:"Copy name",noMatch:"No matching memory",clearFilter:"Clear 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",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}",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"},yt=["all","project","knowledge","content","prompt","business","tool","mistake"],We={project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},ve={project:"kindProject",knowledge:"kindKnowledge",content:"kindContent",prompt:"kindPrompt",business:"kindBusiness",tool:"kindTool",mistake:"kindMistake",other:"kindKnowledge"},we=`
|
|
7
7
|
.memory-eternal-root { font-family: inherit; color: var(--dsw-alias-label-primary, #1f2937); }
|
|
8
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
9
|
.mc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
|
|
@@ -105,12 +105,12 @@ var st=Object.create;var Oe=Object.defineProperty;var lt=Object.getOwnPropertyDe
|
|
|
105
105
|
.me-graph-ctxmenu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; border-radius: 7px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
106
106
|
.me-graph-ctxmenu button:hover { background: rgba(255,255,255,0.1); }
|
|
107
107
|
.me-graph-hint { font-size: 11px; opacity: 0.6; margin-left: auto; }
|
|
108
|
-
`;function xt(
|
|
108
|
+
`;function xt(o){o.effect(()=>o.locale.register(Be,{zh:bt,en:ht}),"memory-eternal: locale");let s=o.locale.bind(Be);o.effect(()=>o.slots.inject("settings.section",()=>o.slots.register({name:"settings.section",id:Be,order:25,label:()=>s("nav"),locale:Be,inject:()=>({})},()=>c.default.createElement(nt,{t:s,inModal:!1}))),"memory-eternal: settings section"),o.effect(()=>o.slots.inject("sidebar.footer.action",()=>o.slots.register({name:"sidebar.footer.action",id:`${Be}:footer`,order:100,label:()=>s("nav"),locale:Be,inject:()=>({})},m=>c.default.createElement(vt,{t:s,wide:!(m&&m.wide===!1)}))),"memory-eternal: sidebar footer action")}function vt({t:o,wide:s}){let[m,u]=(0,c.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${s?"":" rail"}`,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>u(!0),"aria-label":o("nav"),title:o("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(at,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:o("nav")})]}),m&&(0,e.jsx)(wt,{t:o,onClose:()=>u(!1)})]})}function at(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}function wt({t:o,onClose:s}){return(0,c.useEffect)(()=>{let m=u=>{u.key==="Escape"&&s()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[s]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:s,children:[(0,e.jsx)("style",{children:we}),(0,e.jsx)("div",{className:"me-modal",onClick:m=>m.stopPropagation(),children:(0,e.jsx)(nt,{t:o,inModal:!0,onClose:s})})]})}function nt({t:o,inModal:s,onClose:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)([]),[z,P]=(0,c.useState)(!0),[T,F]=(0,c.useState)(""),[_,me]=(0,c.useState)("all"),[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)("cards"),[J,ue]=(0,c.useState)("recent"),[ne,R]=(0,c.useState)(null),W=(0,c.useRef)(null),h=(0,c.useRef)(null),[j,L]=(0,c.useState)(!1),[$,ye]=(0,c.useState)(!1),[ee,S]=(0,c.useState)(null),[H,G]=(0,c.useState)(null),[Ce,re]=(0,c.useState)(!1),de=(0,c.useRef)(null),[fe,Ne]=(0,c.useState)(24),xe=(0,c.useRef)(null);(0,c.useEffect)(()=>{if(A!=="cards")return;let d=xe.current;if(!d)return;let x=new IntersectionObserver(f=>{f[0]&&f[0].isIntersecting&&Ne(t=>t+24)},{rootMargin:"400px"});return x.observe(d),()=>x.disconnect()},[A,g,_,V]);let Fe=(0,c.useCallback)(async(d=_,x=V)=>{try{P(!0),F("");let f=new URLSearchParams;d&&d!=="all"&&f.set("kind",d),x.trim()&&f.set("q",x.trim());let q=await(await fetch(`${U}/cards?${f.toString()}`)).json();q.ok&&(I(q.cards||[]),Ne(24))}catch(f){F(String(f&&f.message?f.message:f))}finally{P(!1)}},[_,V]),te=(0,c.useCallback)(async()=>{try{let[d,x]=await Promise.all([fetch(`${U}/overview`).then(f=>f.json()),fetch(`${U}/cards`).then(f=>f.json())]);d.ok&&n(d),x.ok&&(I(x.cards||[]),Ne(24))}catch(d){F(String(d&&d.message?d.message:d))}finally{P(!1)}},[]),be=async d=>{try{let f=await(await fetch(`${U}/delete?path=${encodeURIComponent(d)}`)).json();f.ok?(R({ok:!0,msg:o("deleted")}),await te()):R({ok:!1,msg:f.error||o("deleteFail")})}catch{R({ok:!1,msg:o("deleteFail")})}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2e3)};(0,c.useEffect)(()=>(te(),()=>{de.current&&clearTimeout(de.current)}),[te]);let O=d=>{ke(d),de.current&&clearTimeout(de.current),de.current=setTimeout(()=>Fe(_,d),280)},Me=d=>{me(d),Fe(d,V)},Z=async d=>{try{let f=await(await fetch(`${U}/card?path=${encodeURIComponent(d.path||d.id)}`)).json();f.ok&&S({path:f.path,title:d.title,text:f.text})}catch(x){F(String(x&&x.message?x.message:x))}},i=async(d,x)=>{L(!0);try{let f=await fetch(`${U}/export`);if(!f.ok)throw new Error("HTTP "+f.status);let t=await f.json();if(!t.ok)throw new Error(t.error||"export failed");let q,Se,Ie;d==="json"?(Se="memory-vault.json",Ie="application/json",q=JSON.stringify(t.cards.map(se=>({path:se.path,title:se.title,kind:se.kind,text:se.text})),null,2)):(Se="memory-vault.md",Ie="text/markdown;charset=utf-8",q=t.cards.map(se=>se.text.trim()).filter(Boolean).join(`
|
|
109
109
|
|
|
110
110
|
---
|
|
111
111
|
|
|
112
|
-
`));let Re=new Blob([L],{type:xe}),me=await rt(Re,t,m);if(!me.ok){F({ok:!1,msg:me.aborted?a("exportCancel"):a("exportFail")}),U(!1);return}F({ok:!0,msg:me.picked?a("exportedTo")+"\uFF1A"+me.name:a("exportedTo")+"\uFF1A"+a("defaultDownloads")+" \xB7 "+me.name})}catch(g){F({ok:!1,msg:a("exportFail")+" \xB7 "+(g.message||"")})}finally{U(!1)}A.current&&clearTimeout(A.current),A.current=setTimeout(()=>F(null),2600)},_=async o=>{let m=o.target.files&&o.target.files[0];if(o.target.value="",!!m){try{let g=await m.text(),L=await(await fetch(`${q}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:g})).json();L.ok?(await ae(),F({ok:!0,msg:a("importedVault")+"\uFF1A"+(L.imported||0)+(L.skipped?a("importedSkipped")+L.skipped:"")})):F({ok:!1,msg:L.error||a("importFail")})}catch{F({ok:!1,msg:a("importFail")})}A.current&&clearTimeout(A.current),A.current=setTimeout(()=>F(null),2400)}},i=(0,d.useMemo)(()=>{let o=u.slice();return D==="title"?o.sort((m,g)=>String(m.title||"").localeCompare(String(g.title||""))):D==="hot"?o.sort((m,g)=>(g.weight||g.links||0)-(m.weight||m.links||0)):o.sort((m,g)=>new Date(g.updated||0).getTime()-new Date(m.updated||0).getTime()),o},[u,D]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:we}),$&&(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 "+($.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:$.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:$.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:$.msg})]}),s&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(at,{})}),(0,e.jsx)("h2",{children:a("memoryTitle")}),(0,e.jsx)("span",{children:a("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:p,"aria-label":a("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:a("total"),value:b?b.total:"\u2014"}),(0,e.jsx)(Ae,{label:a("recent"),value:b?b.recent:"\u2014"}),(0,e.jsx)(Ae,{label:a("tags"),value:b?b.tags:"\u2014"}),(0,e.jsx)(Ae,{label:a("cardCount"),value:b?b.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:a("searchPlaceholder"),value:X,onChange:o=>be(o.target.value)}),(0,e.jsxs)("div",{className:"mc-tabs",children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${R==="cards"?" active":""}`,onClick:()=>x("cards"),children:a("cardsTab")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${R==="graph"?" active":""}`,onClick:()=>x("graph"),children:a("graphTab")})]}),(0,e.jsx)("input",{ref:ze,type:"file",accept:".json,application/json",style:{display:"none"},onChange:_}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ze.current&&ze.current.click(),children:a("importVault")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:a("location"),children:[(0,e.jsx)("input",{type:"checkbox",checked:ee,onChange:o=>Ye(o.target.checked)}),a("location")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:fe,onClick:()=>ye("md",ee),children:a(fe?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:fe,onClick:()=>ye("json",ee),children:a(fe?"exporting":"exportJson")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>V({tab:"stats"}),children:a("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>ae(),children:a("refresh")})]}),R==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[yt.map(o=>(0,e.jsx)("button",{type:"button",className:`mc-chip${G===o?" active":""}`,onClick:()=>he(o),children:a(o==="all"?"all":ve[o])},o)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:a("sortRecent")},{key:"title",label:a("sortTitle")},{key:"hot",label:a("sortHot")}].map(o=>(0,e.jsx)("button",{type:"button",className:`mc-chip${D===o.key?" active":""}`,onClick:()=>O(o.key),children:o.label},o.key))]}),M&&(0,e.jsxs)("div",{className:"mc-empty",children:[a("error"),"\uFF1A",M]}),R==="cards"?j&&!u.length?(0,e.jsx)("div",{className:"mc-empty",children:a("loading")}):u.length===0?(0,e.jsx)("div",{className:"mc-empty",children:a("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:i.slice(0,J).map(o=>(0,e.jsx)(kt,{card:o,t:a,query:X.trim(),onOpen:B,onDelete:Le},o.path))}),i.length>J&&(0,e.jsx)("div",{ref:pe,style:{height:1}})]}):(0,e.jsx)(Mt,{t:a,onOpen:B}),te&&(0,e.jsx)(Nt,{t:a,card:te,onClose:()=>oe(null),onDelete:o=>{oe(null),Le(o)}}),se&&(0,e.jsx)(Ct,{t:a,tab:se.tab,onTab:o=>V({tab:o}),onClose:()=>V(null),onReload:()=>ae()})]})]})}var Ae=({label:a,value:s})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:s}),(0,e.jsx)("span",{children:a})]}),kt=({card:a,t:s,onOpen:p,query:b,onDelete:r})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>p(a),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[a.kind]||We.other}}),b?ot(a.title,b):a.title,Tt(a.updated)&&(0,e.jsx)("span",{className:"mc-new",children:s("newBadge")})]}),(0,e.jsx)("p",{children:b?ot(a.summary||"",b):a.summary||""}),a.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:a.tags.slice(0,4).map(u=>(0,e.jsx)("span",{className:"mc-tag",children:u},u))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:s(ve[a.kind])}),(0,e.jsx)("span",{children:it(a.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:s("delete"),onClick:u=>{u.stopPropagation(),window.confirm(s("deleteConfirm"))&&r&&r(a.path)},children:"\u2715"})]})]});function Ct({t:a,tab:s,onTab:p,onClose:b,onReload:r}){let[u,S]=(0,d.useState)(null),[j,C]=(0,d.useState)(null),[M,H]=(0,d.useState)(null),G=(0,d.useCallback)(async()=>{try{let[x,D,O]=await Promise.all([fetch(`${q}/stats`).then($=>$.json()),fetch(`${q}/optimize`).then($=>$.json()),fetch(`${q}/budget`).then($=>$.json())]);x.ok&&S(x),D.ok&&C(D),O.ok&&H(O)}catch{}},[]);(0,d.useEffect)(()=>{G()},[G]);let ie=async(x,D)=>{if(window.confirm(a("mergeConfirm")))try{(await fetch(`${q}/merge?paths=${encodeURIComponent(x+","+D)}`).then($=>$.json())).ok&&(await G(),r&&r())}catch{}},X=async x=>{if(window.confirm(a("deleteConfirm")))try{(await fetch(`${q}/delete?path=${encodeURIComponent(x)}`).then(O=>O.json())).ok&&(await G(),r&&r())}catch{}},Ie=["project","knowledge","content","prompt","business","tool","mistake"],R=({title:x,kind:D,updated:O,path:$})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Se.colors[D]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:it(O)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>X($),children:[a("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:b,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:x=>x.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="stats"?" active":""}`,onClick:()=>p("stats"),children:a("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="optimize"?" active":""}`,onClick:()=>p("optimize"),children:a("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:b,children:a("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[s==="stats"&&(0,e.jsx)("div",{children:u&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.total}),(0,e.jsx)("span",{children:a("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.today}),(0,e.jsx)("span",{children:a("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.week}),(0,e.jsx)("span",{children:a("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.tags}),(0,e.jsx)("span",{children:a("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:a("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:Ie.map(x=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Se.colors[x]||"#666"}}),a(ve[x]),": ",u.byKind?.[x]||0]},x))})]}),M&&(M.budgetChars||M.recallLimit||M.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:a("budgetLabel")}),"\uFF1A",a("budgetChars")," ",(0,e.jsx)("b",{children:M.budgetChars||8e4})," \xB7 ",a("recallLimitLabel")," ",(0,e.jsx)("b",{children:M.recallLimit||5})," \xB7 ",a("embeddingLabel")," ",M.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[a("todayList"),"\uFF08",u.todayCards?.length||0,"\uFF09"]}),u.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:u.todayCards.map(x=>(0,e.jsx)(R,{title:x.title,kind:x.kind,updated:x.updated,path:x.path},x.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:a("noOptimize")})]})]})}),s==="optimize"&&(0,e.jsx)("div",{children:j&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:a("mergePairs")}),j.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:j.merge.map((x,D)=>(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:[x.a.title," \u21C4 ",x.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(x.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ie(x.a.path,x.b.path),children:a("mergeNow")})]},D))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:a("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[a("staleCards"),"\uFF08",j.stale?.length||0,"\uFF09"]}),j.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:j.stale.map(x=>(0,e.jsx)(R,{title:x.title,kind:"other",updated:x.updated,path:x.path},x.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:a("noOptimize")})]})})]})]})]})}function Nt({t:a,card:s,onClose:p,onDelete:b}){(0,d.useEffect)(()=>{let j=C=>{C.key==="Escape"&&p()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[p]);let[r,u]=(0,d.useState)(!1),S=(s.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:p,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",onClick:j=>j.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:s.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[S&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>u(j=>!j),children:a(r?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(a("deleteConfirm"))&&b&&b(s.path)},children:a("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:p,children:a("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:r?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Lt(s.text)}})]})]})}function Mt({t:a,onOpen:s}){let[p,b]=(0,d.useState)(null),[r,u]=(0,d.useState)(""),S=(0,d.useCallback)(async()=>{try{let M=await(await fetch(`${q}/graph`)).json();b(M.ok?M:null),u("")}catch(C){u(String(C&&C.message?C.message:C))}},[]);(0,d.useEffect)(()=>{let C=!0;return fetch(`${q}/graph`).then(M=>M.json()).then(M=>{C&&b(M.ok?M:null)}).catch(M=>{C&&u(String(M&&M.message?M.message:M))}),()=>{C=!1}},[]);let j=(0,d.useCallback)(async C=>{try{let H=await(await fetch(`${q}/delete?path=${encodeURIComponent(C)}`)).json();return H&&H.ok?(await S(),!0):!1}catch{return!1}},[S]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:we}),r&&(0,e.jsxs)("div",{className:"mc-empty",children:[a("error"),"\uFF1A",r]}),!p&&!r&&(0,e.jsx)("div",{className:"mc-empty",children:a("loading")}),p&&p.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:a("emptyGraph")}),p&&p.nodes.length>0&&(0,e.jsx)(It,{nodes:p.nodes,edges:p.edges,onOpen:s,onDelete:j,t:a,countLabel:`${p.nodes.length} ${a("nodes")} \xB7 ${St(p.edges)} ${a("edges")}`})]})}function St(a){let s=new Set;for(let p of a||[])s.add([p.source,p.target].sort().join("|"));return s.size}var Se={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function It({nodes:a,edges:s,onOpen:p,onDelete:b,t:r,countLabel:u}){let S=(0,d.useRef)(null),j=(0,d.useRef)(null),C=(0,d.useRef)(null),M=(0,d.useRef)(null),H=(0,d.useRef)(null),G=(0,d.useRef)(p);(0,d.useEffect)(()=>{G.current=p},[p]);let ie=(0,d.useRef)(b);(0,d.useEffect)(()=>{ie.current=b},[b]);let[X,Ie]=(0,d.useState)(""),[R,x]=(0,d.useState)(null),D=(0,d.useRef)("");(0,d.useEffect)(()=>{D.current=X.trim().toLowerCase()},[X]);let[O,$]=(0,d.useState)("all"),F=(0,d.useRef)("all"),[A,ze]=(0,d.useState)(!1),fe=(0,d.useRef)(!1),[U,ee]=(0,d.useState)(null);(0,d.useEffect)(()=>{F.current=O},[O]),(0,d.useEffect)(()=>{fe.current=A},[A]);let Ye=(()=>{let i=X.trim().toLowerCase();return!!i&&!a.some(o=>(o.title||o.name||"").toLowerCase().includes(i)||String(o.kind||"").toLowerCase().includes(i)||String(ve[o.kind]||"").toLowerCase().includes(i))})();(0,d.useEffect)(()=>{let i=C.current;i&&i.wake&&i.wake()},[X]),(0,d.useEffect)(()=>{let i=C.current;i&&i.render&&i.render()},[O,A]);let te=(0,d.useRef)(null),[oe,se]=(0,d.useState)([]),[V,le]=(0,d.useState)(null),[J,ce]=(0,d.useState)(!1),[pe,Te]=(0,d.useState)(null),[ae,Le]=(0,d.useState)(""),be=(0,d.useRef)(null),he=(0,d.useRef)(null),B=(i,o=!0)=>{be.current&&clearTimeout(be.current),Te({msg:i,ok:o}),be.current=setTimeout(()=>Te(null),1900)},ye=i=>{Le(i),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>Le(""),1600)};(0,d.useEffect)(()=>()=>{be.current&&clearTimeout(be.current),he.current&&clearTimeout(he.current)},[]);let _=(0,d.useMemo)(()=>a.reduce((i,o)=>(i[o.id]=o,i),{}),[a]);return(0,d.useEffect)(()=>{let i=S.current;if(!i||a.length===0)return;let o=i.getContext("2d");if(!o)return;let m=Math.max(1,window.devicePixelRatio||1),g=()=>document.documentElement.getAttribute("data-theme")==="dark",T={};s.forEach(n=>{T[n.source]=(T[n.source]||0)+1,T[n.target]=(T[n.target]||0)+1});let L=Math.max(1,...Object.values(T)),t={nodes:a.map(n=>({id:n.id,name:n.title||"",type:n.kind||"other",r:9+Math.min(10,(T[n.id]||0)/L*8),x:0,y:0,vx:0,vy:0})),edges:s.map(n=>({sourceNodeId:n.source,targetNodeId:n.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:m,ctx:o,multi:[],marquee:null};t.domain=a,t.domainById=a.reduce((n,f)=>(n[f.id]=f,n),{}),t.nodes.forEach((n,f)=>{let c=f/t.nodes.length*Math.PI*2-Math.PI/2;n.x=Math.cos(c)*60,n.y=Math.sin(c)*60});let xe=[...new Set(t.nodes.map(n=>n.type))];t.clustered=xe.length>1,t.typeCenters={},xe.forEach((n,f)=>{let c=f/xe.length*Math.PI*2-Math.PI/2;t.typeCenters[n]={x:Math.cos(c)*160,y:Math.sin(c)*160}}),C.current=t;let Re=()=>{let n=i.clientWidth,f=i.clientHeight;t.w=n,t.h=f,i.width=n*m,i.height=f*m,o.setTransform(m,0,0,m,0,0)};Re();let me=new ResizeObserver(Re);me.observe(i.parentElement);let ue=(n,f)=>n&&n.length>f?n.slice(0,f)+"\u2026":n,Ee=(n,f,c,h)=>{if(o.beginPath(),h==="rect")o.rect(n-c,f-c*.75,c*2,c*1.5);else if(h==="diamond")o.moveTo(n,f-c),o.lineTo(n+c,f),o.lineTo(n,f+c),o.lineTo(n-c,f),o.closePath();else if(h==="hexagon"){for(let y=0;y<6;y++){let k=Math.PI/3*y-Math.PI/2,I=n+c*Math.cos(k),l=f+c*Math.sin(k);y===0?o.moveTo(I,l):o.lineTo(I,l)}o.closePath()}else o.arc(n,f,c,0,Math.PI*2)},je=()=>{if(!t.nodes.length)return;let n=1/0,f=-1/0,c=1/0,h=-1/0;t.nodes.forEach(N=>{n=Math.min(n,N.x),f=Math.max(f,N.x),c=Math.min(c,N.y),h=Math.max(h,N.y)});let y=36,k=f-n+y*2,I=h-c+y*2,l=Math.min(t.w/k,t.h/I);t.zoom=Math.max(.45,Math.min(2.4,l*1.22)),t.panX=t.w/2-(n+f)/2*t.zoom,t.panY=t.h/2-(c+h)/2*t.zoom};M.current=je;let qe=()=>{o.clearRect(0,0,t.w,t.h),t.searchTerm=D.current,t.kindFilter=F.current,t.timeMode=fe.current;let n=t.kindFilter,f=l=>String(l||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");o.save(),o.strokeStyle=g()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",o.lineWidth=.5;for(let l=0;l<t.w;l+=24)o.beginPath(),o.moveTo(l,0),o.lineTo(l,t.h),o.stroke();for(let l=0;l<t.h;l+=24)o.beginPath(),o.moveTo(0,l),o.lineTo(t.w,l),o.stroke();o.restore(),o.save(),o.translate(t.panX,t.panY),o.scale(t.zoom,t.zoom);let c={};t.nodes.forEach(l=>c[l.id]=l);let h=t.nodes.length>40,y=h?1.5:.55,k=t.selectedId||t.hoverId;t.edges.forEach(l=>{let N=c[l.sourceNodeId],z=c[l.targetNodeId];if(!N||!z)return;if(n!=="all"){let K=t.domainById[l.sourceNodeId]&&t.domainById[l.sourceNodeId].kind,Qe=t.domainById[l.targetNodeId]&&t.domainById[l.targetNodeId].kind;if(K!==n&&Qe!==n)return}let v=z.x-N.x,w=z.y-N.y,E=Math.sqrt(v*v+w*w)||1,P=h?12:18,W=-w/E*P,Z=v/E*P,Y=(N.x+z.x)/2+W,re=(N.y+z.y)/2+Z,Q=Se.colors[t.domainById[N.id]&&t.domainById[N.id].kind||"other"],de=k&&(l.sourceNodeId===k||l.targetNodeId===k),ke=k?de?.6:.08:h?.14:.24,Be=parseInt(Q.slice(1,3),16),De=parseInt(Q.slice(3,5),16),Ze=parseInt(Q.slice(5,7),16);o.strokeStyle="rgba("+Be+","+De+","+Ze+","+ke+")",o.lineWidth=de?1.6+(l.weight||1):.8+(l.weight||1)*.5,o.beginPath(),o.moveTo(N.x,N.y),o.quadraticCurveTo(Y,re,z.x,z.y),o.stroke()});let I=[];if(t.nodes.forEach(l=>{let N=t.domainById[l.id]||{},z=N.kind||"other",v=t.timeMode?zt(N.updated):Se.colors[z],w=Se.shapes[z],E=t.selectedId===l.id,P=t.hoverId===l.id,W=t.searchTerm||"",Z=!W||(l.name||"").toLowerCase().includes(W)||String(ve[z]||"").toLowerCase().includes(W)||String(z).toLowerCase().includes(W),Y=n==="all"||z===n,re=k&&l.id!==k&&!t.edges.some(K=>K.sourceNodeId===k&&K.targetNodeId===l.id||K.targetNodeId===k&&K.sourceNodeId===l.id)||W&&!Z||!Y;o.save(),o.globalAlpha=re?.08:1,(E||P)&&(o.shadowColor=v,o.shadowBlur=E?20:14),Ee(l.x,l.y,l.r,w);let Q=parseInt(v.slice(1,3),16),de=parseInt(v.slice(3,5),16),ke=parseInt(v.slice(5,7),16),Be=o.createRadialGradient(l.x-l.r*.3,l.y-l.r*.3,0,l.x,l.y,l.r*1.2);Be.addColorStop(0,"rgba("+Math.min(255,Q+70)+","+Math.min(255,de+70)+","+Math.min(255,ke+70)+",0.95)"),Be.addColorStop(1,v),o.fillStyle=Be,o.fill(),o.restore(),E?(o.save(),Ee(l.x,l.y,l.r+3,w),o.strokeStyle=v,o.lineWidth=3,o.shadowColor=v,o.shadowBlur=12,o.stroke(),o.restore()):P?(o.save(),Ee(l.x,l.y,l.r+2,w),o.strokeStyle=v,o.lineWidth=2,o.stroke(),o.restore()):W&&Z?(o.save(),Ee(l.x,l.y,l.r+2,w),o.strokeStyle="#e11d48",o.lineWidth=2,o.stroke(),o.restore()):t.multi.indexOf(l.id)>=0&&(o.save(),Ee(l.x,l.y,l.r+2,w),o.strokeStyle="#60a5fa",o.lineWidth=2,o.shadowColor="#60a5fa",o.shadowBlur=8,o.stroke(),o.restore());let De=ue(l.name,16);if((E||P||t.zoom>y||!h&&t.zoom>.6)&&Y){let K=1/t.zoom;o.font="500 "+(12*K).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let ge=o.measureText(De).width+16*K,Pe=18*K,Ce=l.y+l.r+8*K,et=!0;for(let Ne of I)if(l.x-ge/2<Ne.x+Ne.w&&l.x+ge/2>Ne.x&&Ce<Ne.y+Ne.h&&Ce+Pe>Ne.y){et=!1;break}if(!et&&!E&&!P)return;I.push({x:l.x-ge/2,y:Ce,w:ge,h:Pe}),o.fillStyle=g()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",o.beginPath(),o.roundRect?o.roundRect(l.x-ge/2,Ce,ge,Pe,4*K):o.rect(l.x-ge/2,Ce,ge,Pe),o.fill(),o.strokeStyle=g()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",o.lineWidth=1*K,o.stroke(),o.fillStyle=g()?E||P?"#eee":"#bbb":E||P?"#111":"#444",o.textAlign="center",o.fillText(De,l.x,Ce+13*K)}}),o.restore(),t.marquee){let l=t.marquee,N=Math.min(l.sx,l.ex),z=Math.min(l.sy,l.ey),v=Math.abs(l.ex-l.sx),w=Math.abs(l.ey-l.sy);o.save(),o.setLineDash([4,4]),o.strokeStyle="rgba(96,165,250,0.9)",o.lineWidth=1,o.fillStyle="rgba(96,165,250,0.12)",o.fillRect(N,z,v,w),o.strokeRect(N,z,v,w),o.restore()}if(t.hoverId&&te.current){let l=t.domainById[t.hoverId],N=t.nodes.find(function(z){return z.id===t.hoverId});if(l&&N){let z=t.edges.filter(function(E){return E.sourceNodeId===l.id||E.targetNodeId===l.id}).length,v=N.x*t.zoom+t.panX,w=N.y*t.zoom+t.panY;te.current.style.display="block",te.current.style.left=v+14+"px",te.current.style.top=w-6+"px",te.current.innerHTML="<b>"+f(l.title||l.name||"")+'</b><br/><span style="opacity:.8">'+f(l.kind||"")+" \xB7 "+z+" \u8FDE\u63A5</span>"}}else te.current&&(te.current.style.display="none")},ne=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=ne,t.render=qe;let Ue=()=>{let n=t.nodes.length;t.tickCount++;let c=.9-Math.min(.4,t.tickCount/1500),h=n>1e3?3e3:n>100?2e3:n>50?1200:800,y=n>100?.002:.005,k=n>1e3?.012:n>100?.005:.01,I=n>1e3?6:n>200?12:24,l={};t.nodes.forEach(v=>l[v.id]=v);for(let v=0;v<n;v++){if(t.dragNode===t.nodes[v])continue;let w=t.nodes[v],E=0,P=0;for(let Y=0;Y<n;Y++){if(v===Y)continue;let re=w.x-t.nodes[Y].x,Q=w.y-t.nodes[Y].y,de=Math.sqrt(re*re+Q*Q)||1,ke=h/(de*de);E+=re/de*ke,P+=Q/de*ke}if(t.clustered&&t.typeCenters[w.type]){let Y=t.typeCenters[w.type];E+=(Y.x-w.x)*.006,P+=(Y.y-w.y)*.006}else E-=w.x*k,P-=w.y*k;let W=(w.vx+E)*c,Z=(w.vy+P)*c;W=Math.max(-I,Math.min(I,W)),Z=Math.max(-I,Math.min(I,Z)),w.vx=W,w.vy=Z}t.edges.forEach(v=>{let w=l[v.sourceNodeId],E=l[v.targetNodeId];if(!w||!E)return;let P=E.x-w.x,W=E.y-w.y,Z=Math.sqrt(P*P+W*W)||1,Y=(Z-100)*y,re=P/Z*Y,Q=W/Z*Y;t.dragNode!==w&&(w.vx+=re,w.vy+=Q),t.dragNode!==E&&(E.vx-=re,E.vy-=Q)});let N=0;t.nodes.forEach(v=>{t.dragNode!==v&&(v.x+=v.vx,v.y+=v.vy,N+=v.vx*v.vx+v.vy*v.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,je()),(n?Math.sqrt(N/n):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{Ue(),qe()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Fe=(n,f)=>{let c=i.getBoundingClientRect();return{x:(n-c.left-t.panX)/t.zoom,y:(f-c.top-t.panY)/t.zoom}},$e=(n,f,c)=>Math.max(f,Math.min(c,n)),Ke=n=>{t.mouseX=n.clientX,t.mouseY=n.clientY;let f=Fe(n.clientX,n.clientY),c=null;for(let h=t.nodes.length-1;h>=0;h--){let y=t.nodes[h];if(F.current!=="all"&&(t.domainById[y.id]&&t.domainById[y.id].kind)!==F.current)continue;let k=y.x-f.x,I=y.y-f.y;if(k*k+I*I<y.r*y.r+36){c=y.id;break}}c!==t.hoverId&&(t.hoverId=c,ne())},He=n=>{if(n.button!==0)return;let f=Fe(n.clientX,n.clientY),c=null;for(let h=t.nodes.length-1;h>=0;h--){let y=t.nodes[h];if(F.current!=="all"&&(t.domainById[y.id]&&t.domainById[y.id].kind)!==F.current)continue;let k=y.x-f.x,I=y.y-f.y;if(k*k+I*I<y.r*y.r+25){c=y;break}}if(n.shiftKey){t.marquee={sx:n.clientX,sy:n.clientY,ex:n.clientX,ey:n.clientY};return}t.dragStart={x:n.clientX,y:n.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=c||null,c&&(t.dragOffset={dx:c.x-f.x,dy:c.y-f.y})},Ge=n=>{if(t.marquee){t.marquee.ex=n.clientX,t.marquee.ey=n.clientY,ne();return}if(!t.dragStart)return;let f=n.clientX-t.dragStart.x,c=n.clientY-t.dragStart.y;if(Math.abs(f)+Math.abs(c)>3&&(t.dragging=!0),t.dragNode){let h=Fe(n.clientX,n.clientY);t.dragNode.x=h.x+t.dragOffset.dx,t.dragNode.y=h.y+t.dragOffset.dy,ne()}else t.dragging&&(t.panX=$e(t.dragStart.px+f,-1e5,1e5),t.panY=$e(t.dragStart.py+c,-1e5,1e5),ne())},Ve=n=>{if(t.marquee){let c=t.marquee;t.marquee=null;let h=i.getBoundingClientRect(),y=Math.min(c.sx,c.ex)-h.left,k=Math.max(c.sx,c.ex)-h.left,I=Math.min(c.sy,c.ey)-h.top,l=Math.max(c.sy,c.ey)-h.top,N=t.nodes.filter(z=>{let v=z.x*t.zoom+t.panX,w=z.y*t.zoom+t.panY;return v>=y&&v<=k&&w>=I&&w<=l}).map(z=>z.id);t.multi=N,se(N),ne();return}if(t.dragStart&&!t.dragging){let c=Fe(n.clientX,n.clientY),h=null;for(let y=t.nodes.length-1;y>=0;y--){let k=t.nodes[y];if(F.current!=="all"&&(t.domainById[k.id]&&t.domainById[k.id].kind)!==F.current)continue;let I=k.x-c.x,l=k.y-c.y;if(I*I+l*l<k.r*k.r+20){h=k;break}}h?(t.selectedId=h.id,x(h.id),ne()):(t.selectedId=null,t.hoverId=null,n.shiftKey||(t.multi=[],se([])),x(null),ne())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=n=>{n.preventDefault();let f=Fe(n.clientX,n.clientY),c=null;for(let h=t.nodes.length-1;h>=0;h--){let y=t.nodes[h];if(F.current!=="all"&&(t.domainById[y.id]&&t.domainById[y.id].kind)!==F.current)continue;let k=y.x-f.x,I=y.y-f.y;if(k*k+I*I<y.r*y.r+25){c=y;break}}if(c){let h=t.domainById[c.id];h&&ee({x:n.clientX,y:n.clientY,id:c.id,path:h.id,title:h.title})}else ee(null)},Je=n=>{n.preventDefault();let f=i.getBoundingClientRect(),c=(n.clientX-f.left-t.panX)/t.zoom,h=(n.clientY-f.top-t.panY)/t.zoom,y=Math.max(.3,Math.min(3,t.zoom*(n.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+c*(t.zoom-y),-1e5,1e5),t.panY=$e(t.panY+h*(t.zoom-y),-1e5,1e5),t.zoom=y,ne()};i.addEventListener("mousemove",Ke),i.addEventListener("mousedown",He),window.addEventListener("mousemove",Ge),window.addEventListener("mouseup",Ve),i.addEventListener("wheel",Je,{passive:!1}),i.addEventListener("contextmenu",_e),H.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],se([]),je(),ne()};for(let n=0;n<200;n++)Ue();return je(),ne(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),me.disconnect(),i.removeEventListener("mousemove",Ke),i.removeEventListener("mousedown",He),window.removeEventListener("mousemove",Ge),window.removeEventListener("mouseup",Ve),i.removeEventListener("wheel",Je),i.removeEventListener("contextmenu",_e)}},[a,s]),(0,e.jsxs)("div",{className:"me-graph",ref:j,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[a.length," ",r("nodes")," \xB7 ",s.length," ",r("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:r("search"),value:X,onChange:i=>Ie(i.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${A?" me-on":""}`,onClick:()=>ze(i=>!i),children:r("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=S.current;if(i)try{i.toBlob(o=>{o&&le({url:URL.createObjectURL(o),blob:o})},"image/png")}catch{}},children:r("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>M.current&&M.current(),children:r("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{x(null),$("all"),H.current&&H.current()},children:r("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:S,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:te,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[A?[{c:"#10b981",l:r("timeNew")},{c:"#f59e0b",l:r("timeRecent")},{c:"#f97316",l:r("timeMonth")},{c:"#94a3b8",l:r("timeOld")}].map(i=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:i.c}}),i.l]},i.c)):Object.keys(We).map(i=>(0,e.jsxs)("button",{type:"button",className:`lg${O===i?" active":""}`,onClick:()=>$(o=>o===i?"all":i),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Se.colors[i]||We[i]}}),r(ve[i])]},i)),!A&&O!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>$("all"),children:[r("clearFilter")," \u2715"]})]}),Ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:r("noMatch")}),U&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>ee(null)}),U&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:U.x,top:U.y,zIndex:31},onMouseDown:i=>i.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{G.current({path:U.path,title:U.title}),ee(null)},children:r("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{U.id&&(C.current.selectedId=U.id,x(U.id)),ee(null);let i=C.current;i&&i.wake&&i.wake()},children:r("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(U.title||"")}catch{}ee(null),B(r("copied"))},children:r("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let i=U.path;ee(null),window.confirm(r("deleteConfirm"))&&(async()=>{try{(ie.current?await ie.current(i):!1)?B(r("deleted")):B(r("deleteFail"),!1)}catch{B(r("deleteFail"),!1)}})()},children:r("delete")})]}),oe.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:[oe.length," ",r("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let o=oe.map(L=>_[L]).filter(Boolean).map(L=>L.title||L.name).join(`
|
|
113
|
-
`),
|
|
112
|
+
`));let Ye=new Blob([q],{type:Ie}),ie=await rt(Ye,Se,x);if(!ie.ok){R({ok:!1,msg:ie.aborted?o("exportCancel"):o("exportFail")}),L(!1);return}R({ok:!0,msg:ie.picked?o("exportedTo")+"\uFF1A"+ie.name:o("exportedTo")+"\uFF1A"+o("defaultDownloads")+" \xB7 "+ie.name})}catch(f){R({ok:!1,msg:o("exportFail")+" \xB7 "+(f.message||"")})}finally{L(!1)}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2600)},a=async d=>{let x=d.target.files&&d.target.files[0];if(d.target.value="",!!x){try{let f=await x.text(),q=await(await fetch(`${U}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:f})).json();q.ok?(await te(),R({ok:!0,msg:o("importedVault")+"\uFF1A"+(q.imported||0)+(q.skipped?o("importedSkipped")+q.skipped:"")})):R({ok:!1,msg:q.error||o("importFail")})}catch{R({ok:!1,msg:o("importFail")})}W.current&&clearTimeout(W.current),W.current=setTimeout(()=>R(null),2400)}},N=(0,c.useMemo)(()=>{let d=g.slice();return J==="title"?d.sort((x,f)=>String(x.title||"").localeCompare(String(f.title||""))):J==="hot"?d.sort((x,f)=>(f.weight||f.links||0)-(x.weight||x.links||0)):d.sort((x,f)=>new Date(f.updated||0).getTime()-new Date(x.updated||0).getTime()),d},[g,J]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:we}),ne&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(ne.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:ne.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:ne.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:ne.msg})]}),s&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(at,{})}),(0,e.jsx)("h2",{children:o("memoryTitle")}),(0,e.jsx)("span",{children:o("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:m,"aria-label":o("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:o("total"),value:u?u.total:"\u2014"}),(0,e.jsx)(Ae,{label:o("recent"),value:u?u.recent:"\u2014"}),(0,e.jsx)(Ae,{label:o("tags"),value:u?u.tags:"\u2014"}),(0,e.jsx)(Ae,{label:o("cardCount"),value:u?u.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:o("searchPlaceholder"),value:V,onChange:d=>O(d.target.value)}),(0,e.jsxs)("div",{className:"mc-tabs",children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="cards"?" active":""}`,onClick:()=>ce("cards"),children:o("cardsTab")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${A==="graph"?" active":""}`,onClick:()=>ce("graph"),children:o("graphTab")})]}),(0,e.jsx)("input",{ref:h,type:"file",accept:".json,application/json",style:{display:"none"},onChange:a}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>h.current&&h.current.click(),children:o("importVault")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("location"),children:[(0,e.jsx)("input",{type:"checkbox",checked:$,onChange:d=>ye(d.target.checked)}),o("location")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("md",$),children:o(j?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:j,onClick:()=>i("json",$),children:o(j?"exporting":"exportJson")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:Ce,onChange:d=>re(d.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>G({tab:"stats"}),children:o("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>te(),children:o("refresh")})]}),A==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[yt.map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${_===d?" active":""}`,onClick:()=>Me(d),children:o(d==="all"?"all":ve[d])},d)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:o("sortRecent")},{key:"title",label:o("sortTitle")},{key:"hot",label:o("sortHot")}].map(d=>(0,e.jsx)("button",{type:"button",className:`mc-chip${J===d.key?" active":""}`,onClick:()=>ue(d.key),children:d.label},d.key))]}),T&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",T]}),A==="cards"?z&&!g.length?(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}):g.length===0?(0,e.jsx)("div",{className:"mc-empty",children:o("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:N.slice(0,fe).map(d=>(0,e.jsx)(kt,{card:d,t:o,query:V.trim(),onOpen:Z,onDelete:be},d.path))}),N.length>fe&&(0,e.jsx)("div",{ref:xe,style:{height:1}})]}):(0,e.jsx)(Mt,{t:o,onOpen:Z,all:Ce}),ee&&(0,e.jsx)(Nt,{t:o,card:ee,onClose:()=>S(null),onDelete:d=>{S(null),be(d)}}),H&&(0,e.jsx)(Ct,{t:o,tab:H.tab,onTab:d=>G({tab:d}),onClose:()=>G(null),onReload:()=>te()})]})]})}var Ae=({label:o,value:s})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:s}),(0,e.jsx)("span",{children:o})]}),kt=({card:o,t:s,onOpen:m,query:u,onDelete:n})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>m(o),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[o.kind]||We.other}}),u?ot(o.title,u):o.title,Tt(o.updated)&&(0,e.jsx)("span",{className:"mc-new",children:s("newBadge")})]}),(0,e.jsx)("p",{children:u?ot(o.summary||"",u):o.summary||""}),o.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:o.tags.slice(0,4).map(g=>(0,e.jsx)("span",{className:"mc-tag",children:g},g))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:s(ve[o.kind])}),(0,e.jsx)("span",{children:it(o.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:s("delete"),onClick:g=>{g.stopPropagation(),window.confirm(s("deleteConfirm"))&&n&&n(o.path)},children:"\u2715"})]})]});function Ct({t:o,tab:s,onTab:m,onClose:u,onReload:n}){let[g,I]=(0,c.useState)(null),[z,P]=(0,c.useState)(null),[T,F]=(0,c.useState)(null),[_,me]=(0,c.useState)(""),[V,ke]=(0,c.useState)(""),A=(0,c.useCallback)(async()=>{try{let h=await fetch(`${U}/todayBrief`).then(j=>j.json());me(h.ok&&h.brief||"")}catch{}},[]),ce=(0,c.useCallback)(async()=>{if(!(!z||!z.merge||!z.merge.length)&&window.confirm(o("mergeAllConfirm"))){ke("merge");try{let h={},j=S=>h[S]===void 0?S:h[S]=j(h[S]),L=(S,H)=>{h[j(S)]=j(H)},$=new Set;for(let S of z.merge)$.add(S.a.path),$.add(S.b.path),L(S.a.path,S.b.path);let ye={};for(let S of $){let H=j(S);(ye[H]=ye[H]||[]).push(S)}let ee=0;for(let S of Object.values(ye)){if(S.length<2)continue;(await fetch(`${U}/merge?paths=${encodeURIComponent(S.join(","))}`).then(G=>G.json())).ok&&ee++}await J(),n&&n()}catch{}ke("")}},[z,J,n,o]),J=(0,c.useCallback)(async()=>{try{let[h,j,L]=await Promise.all([fetch(`${U}/stats`).then($=>$.json()),fetch(`${U}/optimize`).then($=>$.json()),fetch(`${U}/budget`).then($=>$.json())]);h.ok&&I(h),j.ok&&P(j),L.ok&&F(L)}catch{}},[]);(0,c.useEffect)(()=>{J()},[J]);let ue=async(h,j)=>{if(window.confirm(o("mergeConfirm")))try{(await fetch(`${U}/merge?paths=${encodeURIComponent(h+","+j)}`).then($=>$.json())).ok&&(await J(),n&&n())}catch{}},ne=async h=>{if(window.confirm(o("deleteConfirm")))try{(await fetch(`${U}/delete?path=${encodeURIComponent(h)}`).then(L=>L.json())).ok&&(await J(),n&&n())}catch{}},R=["project","knowledge","content","prompt","business","tool","mistake"],W=({title:h,kind:j,updated:L,path:$})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[j]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:it(L)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ne($),children:[o("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:u,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:h=>h.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="stats"?" active":""}`,onClick:()=>m("stats"),children:o("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${s==="optimize"?" active":""}`,onClick:()=>m("optimize"),children:o("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:u,children:o("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[s==="stats"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:o("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:A,children:o("todayBrief")}),_&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:_})]}),g&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.total}),(0,e.jsx)("span",{children:o("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.today}),(0,e.jsx)("span",{children:o("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.week}),(0,e.jsx)("span",{children:o("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:g.tags}),(0,e.jsx)("span",{children:o("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:R.map(h=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[h]||"#666"}}),o(ve[h]),": ",g.byKind?.[h]||0]},h))})]}),T&&(T.budgetChars||T.recallLimit||T.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:o("budgetLabel")}),"\uFF1A",o("budgetChars")," ",(0,e.jsx)("b",{children:T.budgetChars||8e4})," \xB7 ",o("recallLimitLabel")," ",(0,e.jsx)("b",{children:T.recallLimit||5})," \xB7 ",o("embeddingLabel")," ",T.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("todayList"),"\uFF08",g.todayCards?.length||0,"\uFF09"]}),g.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:g.todayCards.map(h=>(0,e.jsx)(W,{title:h.title,kind:h.kind,updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})]})]}),s==="optimize"&&(0,e.jsx)("div",{children:z&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:z.merge?.length?o("mergePairs"):o("noOptimize")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),z.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:ce,children:o(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("mergePairs")}),z.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:z.merge.map((h,j)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[h.a.title," \u21C4 ",h.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(h.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>ue(h.a.path,h.b.path),children:o("mergeNow")})]},j))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:o("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("staleCards"),"\uFF08",z.stale?.length||0,"\uFF09"]}),z.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:z.stale.map(h=>(0,e.jsx)(W,{title:h.title,kind:"other",updated:h.updated,path:h.path},h.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})})]})]})]})}function Nt({t:o,card:s,onClose:m,onDelete:u}){(0,c.useEffect)(()=>{let z=P=>{P.key==="Escape"&&m()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[m]);let[n,g]=(0,c.useState)(!1),I=(s.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:m,children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",onClick:z=>z.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:s.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[I&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>g(z=>!z),children:o(n?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(o("deleteConfirm"))&&u&&u(s.path)},children:o("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:m,children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:n?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Lt(s.text)}})]})]})}function Mt({t:o,onOpen:s,all:m}){let[u,n]=(0,c.useState)(null),[g,I]=(0,c.useState)(""),z=(0,c.useCallback)(async()=>{try{let F=await(await fetch(`${U}/graph${m?"?all=1":""}`)).json();n(F.ok?F:null),I("")}catch(T){I(String(T&&T.message?T.message:T))}},[m]);(0,c.useEffect)(()=>{let T=!0;return fetch(`${U}/graph${m?"?all=1":""}`).then(F=>F.json()).then(F=>{T&&n(F.ok?F:null)}).catch(F=>{T&&I(String(F&&F.message?F.message:F))}),()=>{T=!1}},[m]);let P=(0,c.useCallback)(async T=>{try{let _=await(await fetch(`${U}/delete?path=${encodeURIComponent(T)}`)).json();return _&&_.ok?(await z(),!0):!1}catch{return!1}},[z]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:we}),g&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",g]}),!u&&!g&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),u&&u.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:o("emptyGraph")}),u&&u.nodes.length>0&&(0,e.jsx)(It,{nodes:u.nodes,edges:u.edges,onOpen:s,onDelete:P,t:o,countLabel:`${u.nodes.length} ${o("nodes")} \xB7 ${St(u.edges)} ${o("edges")}`})]})}function St(o){let s=new Set;for(let m of o||[])s.add([m.source,m.target].sort().join("|"));return s.size}var Ee={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function It({nodes:o,edges:s,onOpen:m,onDelete:u,t:n,countLabel:g}){let I=(0,c.useRef)(null),z=(0,c.useRef)(null),P=(0,c.useRef)(null),T=(0,c.useRef)(null),F=(0,c.useRef)(null),_=(0,c.useRef)(m);(0,c.useEffect)(()=>{_.current=m},[m]);let me=(0,c.useRef)(u);(0,c.useEffect)(()=>{me.current=u},[u]);let[V,ke]=(0,c.useState)(""),[A,ce]=(0,c.useState)(null),J=(0,c.useRef)("");(0,c.useEffect)(()=>{J.current=V.trim().toLowerCase()},[V]);let[ue,ne]=(0,c.useState)("all"),R=(0,c.useRef)("all"),[W,h]=(0,c.useState)(!1),j=(0,c.useRef)(!1),[L,$]=(0,c.useState)(null);(0,c.useEffect)(()=>{R.current=ue},[ue]),(0,c.useEffect)(()=>{j.current=W},[W]);let ye=(()=>{let i=V.trim().toLowerCase();return!!i&&!o.some(a=>(a.title||a.name||"").toLowerCase().includes(i)||String(a.kind||"").toLowerCase().includes(i)||String(ve[a.kind]||"").toLowerCase().includes(i))})();(0,c.useEffect)(()=>{let i=P.current;i&&i.wake&&i.wake()},[V]),(0,c.useEffect)(()=>{let i=P.current;i&&i.render&&i.render()},[ue,W]);let ee=(0,c.useRef)(null),[S,H]=(0,c.useState)([]),[G,Ce]=(0,c.useState)(null),[re,de]=(0,c.useState)(!1),[fe,Ne]=(0,c.useState)(null),[xe,Fe]=(0,c.useState)(""),te=(0,c.useRef)(null),be=(0,c.useRef)(null),O=(i,a=!0)=>{te.current&&clearTimeout(te.current),Ne({msg:i,ok:a}),te.current=setTimeout(()=>Ne(null),1900)},Me=i=>{Fe(i),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>Fe(""),1600)};(0,c.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),be.current&&clearTimeout(be.current)},[]);let Z=(0,c.useMemo)(()=>o.reduce((i,a)=>(i[a.id]=a,i),{}),[o]);return(0,c.useEffect)(()=>{let i=I.current;if(!i||o.length===0)return;let a=i.getContext("2d");if(!a)return;let N=Math.max(1,window.devicePixelRatio||1),d=()=>document.documentElement.getAttribute("data-theme")==="dark",x={};s.forEach(r=>{x[r.source]=(x[r.source]||0)+1,x[r.target]=(x[r.target]||0)+1});let f=Math.max(1,...Object.values(x)),t={nodes:o.map(r=>({id:r.id,name:r.title||"",type:r.kind||"other",r:9+Math.min(10,(x[r.id]||0)/f*8),x:0,y:0,vx:0,vy:0})),edges:s.map(r=>({sourceNodeId:r.source,targetNodeId:r.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:N,ctx:a,multi:[],marquee:null};t.domain=o,t.domainById=o.reduce((r,b)=>(r[b.id]=b,r),{}),t.nodes.forEach((r,b)=>{let p=b/t.nodes.length*Math.PI*2-Math.PI/2;r.x=Math.cos(p)*60,r.y=Math.sin(p)*60});let q=[...new Set(t.nodes.map(r=>r.type))];t.clustered=q.length>1,t.typeCenters={},q.forEach((r,b)=>{let p=b/q.length*Math.PI*2-Math.PI/2;t.typeCenters[r]={x:Math.cos(p)*160,y:Math.sin(p)*160}}),P.current=t;let Se=()=>{let r=i.clientWidth,b=i.clientHeight;t.w=r,t.h=b,i.width=r*N,i.height=b*N,a.setTransform(N,0,0,N,0,0)};Se();let Ie=new ResizeObserver(Se);Ie.observe(i.parentElement);let Ye=(r,b)=>r&&r.length>b?r.slice(0,b)+"\u2026":r,ie=(r,b,p,y)=>{if(a.beginPath(),y==="rect")a.rect(r-p,b-p*.75,p*2,p*1.5);else if(y==="diamond")a.moveTo(r,b-p),a.lineTo(r+p,b),a.lineTo(r,b+p),a.lineTo(r-p,b),a.closePath();else if(y==="hexagon"){for(let v=0;v<6;v++){let C=Math.PI/3*v-Math.PI/2,B=r+p*Math.cos(C),l=b+p*Math.sin(C);v===0?a.moveTo(B,l):a.lineTo(B,l)}a.closePath()}else a.arc(r,b,p,0,Math.PI*2)},se=()=>{if(!t.nodes.length)return;let r=1/0,b=-1/0,p=1/0,y=-1/0;t.nodes.forEach(M=>{r=Math.min(r,M.x),b=Math.max(b,M.x),p=Math.min(p,M.y),y=Math.max(y,M.y)});let v=36,C=b-r+v*2,B=y-p+v*2,l=Math.min(t.w/C,t.h/B);t.zoom=Math.max(.45,Math.min(2.4,l*1.22)),t.panX=t.w/2-(r+b)/2*t.zoom,t.panY=t.h/2-(p+y)/2*t.zoom};T.current=se;let Ue=()=>{a.clearRect(0,0,t.w,t.h),t.searchTerm=J.current,t.kindFilter=R.current,t.timeMode=j.current;let r=t.kindFilter,b=l=>String(l||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");a.save(),a.strokeStyle=d()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",a.lineWidth=.5;for(let l=0;l<t.w;l+=24)a.beginPath(),a.moveTo(l,0),a.lineTo(l,t.h),a.stroke();for(let l=0;l<t.h;l+=24)a.beginPath(),a.moveTo(0,l),a.lineTo(t.w,l),a.stroke();a.restore(),a.save(),a.translate(t.panX,t.panY),a.scale(t.zoom,t.zoom);let p={};t.nodes.forEach(l=>p[l.id]=l);let y=t.nodes.length>40,v=y?1.5:.55,C=t.selectedId||t.hoverId;t.edges.forEach(l=>{let M=p[l.sourceNodeId],E=p[l.targetNodeId];if(!M||!E)return;if(r!=="all"){let Q=t.domainById[l.sourceNodeId]&&t.domainById[l.sourceNodeId].kind,Qe=t.domainById[l.targetNodeId]&&t.domainById[l.targetNodeId].kind;if(Q!==r&&Qe!==r)return}let w=E.x-M.x,k=E.y-M.y,D=Math.sqrt(w*w+k*k)||1,Y=y?12:18,X=-k/D*Y,oe=w/D*Y,K=(M.x+E.x)/2+X,pe=(M.y+E.y)/2+oe,ae=Ee.colors[t.domainById[M.id]&&t.domainById[M.id].kind||"other"],ge=C&&(l.sourceNodeId===C||l.targetNodeId===C),ze=C?ge?.6:.08:y?.14:.24,je=parseInt(ae.slice(1,3),16),De=parseInt(ae.slice(3,5),16),Ze=parseInt(ae.slice(5,7),16);a.strokeStyle="rgba("+je+","+De+","+Ze+","+ze+")",a.lineWidth=ge?1.6+(l.weight||1):.8+(l.weight||1)*.5,a.beginPath(),a.moveTo(M.x,M.y),a.quadraticCurveTo(K,pe,E.x,E.y),a.stroke()});let B=[];if(t.nodes.forEach(l=>{let M=t.domainById[l.id]||{},E=M.kind||"other",w=t.timeMode?zt(M.updated):Ee.colors[E],k=Ee.shapes[E],D=t.selectedId===l.id,Y=t.hoverId===l.id,X=t.searchTerm||"",oe=!X||(l.name||"").toLowerCase().includes(X)||String(ve[E]||"").toLowerCase().includes(X)||String(E).toLowerCase().includes(X),K=r==="all"||E===r,pe=C&&l.id!==C&&!t.edges.some(Q=>Q.sourceNodeId===C&&Q.targetNodeId===l.id||Q.targetNodeId===C&&Q.sourceNodeId===l.id)||X&&!oe||!K;a.save(),a.globalAlpha=pe?.08:1,(D||Y)&&(a.shadowColor=w,a.shadowBlur=D?20:14),ie(l.x,l.y,l.r,k);let ae=parseInt(w.slice(1,3),16),ge=parseInt(w.slice(3,5),16),ze=parseInt(w.slice(5,7),16),je=a.createRadialGradient(l.x-l.r*.3,l.y-l.r*.3,0,l.x,l.y,l.r*1.2);je.addColorStop(0,"rgba("+Math.min(255,ae+70)+","+Math.min(255,ge+70)+","+Math.min(255,ze+70)+",0.95)"),je.addColorStop(1,w),a.fillStyle=je,a.fill(),a.restore(),D?(a.save(),ie(l.x,l.y,l.r+3,k),a.strokeStyle=w,a.lineWidth=3,a.shadowColor=w,a.shadowBlur=12,a.stroke(),a.restore()):Y?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle=w,a.lineWidth=2,a.stroke(),a.restore()):X&&oe?(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#e11d48",a.lineWidth=2,a.stroke(),a.restore()):t.multi.indexOf(l.id)>=0&&(a.save(),ie(l.x,l.y,l.r+2,k),a.strokeStyle="#60a5fa",a.lineWidth=2,a.shadowColor="#60a5fa",a.shadowBlur=8,a.stroke(),a.restore());let De=Ye(l.name,16);if((D||Y||t.zoom>v||!y&&t.zoom>.6)&&K){let Q=1/t.zoom;a.font="500 "+(12*Q).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let he=a.measureText(De).width+16*Q,Oe=18*Q,Te=l.y+l.r+8*Q,et=!0;for(let Le of B)if(l.x-he/2<Le.x+Le.w&&l.x+he/2>Le.x&&Te<Le.y+Le.h&&Te+Oe>Le.y){et=!1;break}if(!et&&!D&&!Y)return;B.push({x:l.x-he/2,y:Te,w:he,h:Oe}),a.fillStyle=d()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",a.beginPath(),a.roundRect?a.roundRect(l.x-he/2,Te,he,Oe,4*Q):a.rect(l.x-he/2,Te,he,Oe),a.fill(),a.strokeStyle=d()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",a.lineWidth=1*Q,a.stroke(),a.fillStyle=d()?D||Y?"#eee":"#bbb":D||Y?"#111":"#444",a.textAlign="center",a.fillText(De,l.x,Te+13*Q)}}),a.restore(),t.marquee){let l=t.marquee,M=Math.min(l.sx,l.ex),E=Math.min(l.sy,l.ey),w=Math.abs(l.ex-l.sx),k=Math.abs(l.ey-l.sy);a.save(),a.setLineDash([4,4]),a.strokeStyle="rgba(96,165,250,0.9)",a.lineWidth=1,a.fillStyle="rgba(96,165,250,0.12)",a.fillRect(M,E,w,k),a.strokeRect(M,E,w,k),a.restore()}if(t.hoverId&&ee.current){let l=t.domainById[t.hoverId],M=t.nodes.find(function(E){return E.id===t.hoverId});if(l&&M){let E=t.edges.filter(function(D){return D.sourceNodeId===l.id||D.targetNodeId===l.id}).length,w=M.x*t.zoom+t.panX,k=M.y*t.zoom+t.panY;ee.current.style.display="block",ee.current.style.left=w+14+"px",ee.current.style.top=k-6+"px",ee.current.innerHTML="<b>"+b(l.title||l.name||"")+'</b><br/><span style="opacity:.8">'+b(l.kind||"")+" \xB7 "+E+" \u8FDE\u63A5</span>"}}else ee.current&&(ee.current.style.display="none")},le=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=le,t.render=Ue;let qe=()=>{let r=t.nodes.length;t.tickCount++;let p=.9-Math.min(.4,t.tickCount/1500),y=r>1e3?3e3:r>100?2e3:r>50?1200:800,v=r>100?.002:.005,C=r>1e3?.012:r>100?.005:.01,B=r>1e3?6:r>200?12:24,l={};t.nodes.forEach(w=>l[w.id]=w);for(let w=0;w<r;w++){if(t.dragNode===t.nodes[w])continue;let k=t.nodes[w],D=0,Y=0;for(let K=0;K<r;K++){if(w===K)continue;let pe=k.x-t.nodes[K].x,ae=k.y-t.nodes[K].y,ge=Math.sqrt(pe*pe+ae*ae)||1,ze=y/(ge*ge);D+=pe/ge*ze,Y+=ae/ge*ze}if(t.clustered&&t.typeCenters[k.type]){let K=t.typeCenters[k.type];D+=(K.x-k.x)*.006,Y+=(K.y-k.y)*.006}else D-=k.x*C,Y-=k.y*C;let X=(k.vx+D)*p,oe=(k.vy+Y)*p;X=Math.max(-B,Math.min(B,X)),oe=Math.max(-B,Math.min(B,oe)),k.vx=X,k.vy=oe}t.edges.forEach(w=>{let k=l[w.sourceNodeId],D=l[w.targetNodeId];if(!k||!D)return;let Y=D.x-k.x,X=D.y-k.y,oe=Math.sqrt(Y*Y+X*X)||1,K=(oe-100)*v,pe=Y/oe*K,ae=X/oe*K;t.dragNode!==k&&(k.vx+=pe,k.vy+=ae),t.dragNode!==D&&(D.vx-=pe,D.vy-=ae)});let M=0;t.nodes.forEach(w=>{t.dragNode!==w&&(w.x+=w.vx,w.y+=w.vy,M+=w.vx*w.vx+w.vy*w.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,se()),(r?Math.sqrt(M/r):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{qe(),Ue()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Re=(r,b)=>{let p=i.getBoundingClientRect();return{x:(r-p.left-t.panX)/t.zoom,y:(b-p.top-t.panY)/t.zoom}},$e=(r,b,p)=>Math.max(b,Math.min(p,r)),Ke=r=>{t.mouseX=r.clientX,t.mouseY=r.clientY;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+36){p=v.id;break}}p!==t.hoverId&&(t.hoverId=p,le())},Ve=r=>{if(r.button!==0)return;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(r.shiftKey){t.marquee={sx:r.clientX,sy:r.clientY,ex:r.clientX,ey:r.clientY};return}t.dragStart={x:r.clientX,y:r.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=p||null,p&&(t.dragOffset={dx:p.x-b.x,dy:p.y-b.y})},He=r=>{if(t.marquee){t.marquee.ex=r.clientX,t.marquee.ey=r.clientY,le();return}if(!t.dragStart)return;let b=r.clientX-t.dragStart.x,p=r.clientY-t.dragStart.y;if(Math.abs(b)+Math.abs(p)>3&&(t.dragging=!0),t.dragNode){let y=Re(r.clientX,r.clientY);t.dragNode.x=y.x+t.dragOffset.dx,t.dragNode.y=y.y+t.dragOffset.dy,le()}else t.dragging&&(t.panX=$e(t.dragStart.px+b,-1e5,1e5),t.panY=$e(t.dragStart.py+p,-1e5,1e5),le())},Ge=r=>{if(t.marquee){let p=t.marquee;t.marquee=null;let y=i.getBoundingClientRect(),v=Math.min(p.sx,p.ex)-y.left,C=Math.max(p.sx,p.ex)-y.left,B=Math.min(p.sy,p.ey)-y.top,l=Math.max(p.sy,p.ey)-y.top,M=t.nodes.filter(E=>{let w=E.x*t.zoom+t.panX,k=E.y*t.zoom+t.panY;return w>=v&&w<=C&&k>=B&&k<=l}).map(E=>E.id);t.multi=M,H(M),le();return}if(t.dragStart&&!t.dragging){let p=Re(r.clientX,r.clientY),y=null;for(let v=t.nodes.length-1;v>=0;v--){let C=t.nodes[v];if(R.current!=="all"&&(t.domainById[C.id]&&t.domainById[C.id].kind)!==R.current)continue;let B=C.x-p.x,l=C.y-p.y;if(B*B+l*l<C.r*C.r+20){y=C;break}}y?(t.selectedId=y.id,ce(y.id),le()):(t.selectedId=null,t.hoverId=null,r.shiftKey||(t.multi=[],H([])),ce(null),le())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=r=>{r.preventDefault();let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let v=t.nodes[y];if(R.current!=="all"&&(t.domainById[v.id]&&t.domainById[v.id].kind)!==R.current)continue;let C=v.x-b.x,B=v.y-b.y;if(C*C+B*B<v.r*v.r+25){p=v;break}}if(p){let y=t.domainById[p.id];y&&$({x:r.clientX,y:r.clientY,id:p.id,path:y.id,title:y.title})}else $(null)},Je=r=>{r.preventDefault();let b=i.getBoundingClientRect(),p=(r.clientX-b.left-t.panX)/t.zoom,y=(r.clientY-b.top-t.panY)/t.zoom,v=Math.max(.3,Math.min(3,t.zoom*(r.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+p*(t.zoom-v),-1e5,1e5),t.panY=$e(t.panY+y*(t.zoom-v),-1e5,1e5),t.zoom=v,le()};i.addEventListener("mousemove",Ke),i.addEventListener("mousedown",Ve),window.addEventListener("mousemove",He),window.addEventListener("mouseup",Ge),i.addEventListener("wheel",Je,{passive:!1}),i.addEventListener("contextmenu",_e),F.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],H([]),se(),le()};for(let r=0;r<200;r++)qe();return se(),le(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),Ie.disconnect(),i.removeEventListener("mousemove",Ke),i.removeEventListener("mousedown",Ve),window.removeEventListener("mousemove",He),window.removeEventListener("mouseup",Ge),i.removeEventListener("wheel",Je),i.removeEventListener("contextmenu",_e)}},[o,s]),(0,e.jsxs)("div",{className:"me-graph",ref:z,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[o.length," ",n("nodes")," \xB7 ",s.length," ",n("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:n("search"),value:V,onChange:i=>ke(i.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${W?" me-on":""}`,onClick:()=>h(i=>!i),children:n("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=I.current;if(i)try{i.toBlob(a=>{a&&Ce({url:URL.createObjectURL(a),blob:a})},"image/png")}catch{}},children:n("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>T.current&&T.current(),children:n("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{ce(null),ne("all"),F.current&&F.current()},children:n("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:I,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:ee,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[W?[{c:"#10b981",l:n("timeNew")},{c:"#f59e0b",l:n("timeRecent")},{c:"#f97316",l:n("timeMonth")},{c:"#94a3b8",l:n("timeOld")}].map(i=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:i.c}}),i.l]},i.c)):Object.keys(We).map(i=>(0,e.jsxs)("button",{type:"button",className:`lg${ue===i?" active":""}`,onClick:()=>ne(a=>a===i?"all":i),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Ee.colors[i]||We[i]}}),n(ve[i])]},i)),!W&&ue!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>ne("all"),children:[n("clearFilter")," \u2715"]})]}),ye&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:n("noMatch")}),L&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>$(null)}),L&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:L.x,top:L.y,zIndex:31},onMouseDown:i=>i.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{_.current({path:L.path,title:L.title}),$(null)},children:n("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{L.id&&(P.current.selectedId=L.id,ce(L.id)),$(null);let i=P.current;i&&i.wake&&i.wake()},children:n("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(L.title||"")}catch{}$(null),O(n("copied"))},children:n("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let i=L.path;$(null),window.confirm(n("deleteConfirm"))&&(async()=>{try{(me.current?await me.current(i):!1)?O(n("deleted")):O(n("deleteFail"),!1)}catch{O(n("deleteFail"),!1)}})()},children:n("delete")})]}),S.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[S.length," ",n("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let a=S.map(f=>Z[f]).filter(Boolean).map(f=>f.title||f.name).join(`
|
|
113
|
+
`),N=new Blob([a],{type:"text/plain;charset=utf-8"}),d=URL.createObjectURL(N),x=document.createElement("a");x.href=d,x.download="memory-selected.txt",document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(d),1e3),O(S.length+n("exportedSel"))},children:n("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(S.length<2){O(n("mergeNeed"),!1);return}let i=S.map(N=>Z[N]?Z[N].id:N);if(!window.confirm(n("mergeConfirm")))return;H([]);let a=P.current;a&&(a.multi=[]),fetch(`${U}/merge?paths=${encodeURIComponent(i.join(","))}`).then(N=>N.json()).then(N=>{N&&N.ok?O(n("merged")):O(n("mergeFail"),!1)}).catch(()=>O(n("mergeFail"),!1))},children:n("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(n("deleteConfirm")))return;let i=S.map(N=>Z[N]?Z[N].id:N);H([]);let a=P.current;a&&(a.multi=[]),(async()=>{let N=0;for(let d of i)try{(me.current?await me.current(d):!1)&&N++}catch{}O(N+n("deletedSelected"),N>0)})()},children:n("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=P.current;i&&(i.multi=[]),H([]);let a=P.current;a&&a.render&&a.render()},children:n("clearSelection")})]}),A&&(0,e.jsxs)("div",{className:"me-graph-sidebar",style:{position:"absolute",right:10,top:10,zIndex:3,maxWidth:240,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:12,fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:Z[A]?Z[A].title||Z[A].name:A}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:Z[A]?n(ve[Z[A].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:n("graphHint")}),(s.filter(i=>i.source===A||i.target===A)||[]).slice(0,8).map((i,a)=>{let N=i.source===A?i.target:i.source,d=Z[N];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:x=>{x.preventDefault();let f=P.current;f&&(f.selectedId=N,f.hoverId=N,f.wake&&f.wake()),ce(N)},children:d?(d.title||d.name).slice(0,28):N},a)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:n("graphTip")}),fe&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(fe.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:fe.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:fe.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:fe.msg})]}),G&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{G.url&&URL.revokeObjectURL(G.url),Ce(null),de(!1)},children:[(0,e.jsx)("style",{children:we}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:re?"100vw":900,width:re?"100vw":"92vw",maxHeight:re?"100vh":"90vh",height:re?"100vh":void 0,borderRadius:re?0:14},onClick:i=>i.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:n("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:G.url,download:"memory-graph.png",onClick:()=>{Me("download"),O(n("downloaded")+" \xB7 "+n("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:n(xe==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Me("save");let i=G.blob;i&&typeof window.showSaveFilePicker=="function"?rt(i,"memory-graph.png",!0).then(a=>{a.ok?O(n("exportedTo")+"\uFF1A"+a.name):a.aborted?O(n("exportCancel")):O(n("exportFail"),!1)}):O(n("saveAsUnsupported"),!1)},children:n(xe==="save"?"done":"saveAs")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Me("full"),de(i=>!i),O(n("fullscreen"))},children:n(xe==="full"?"done":re?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let i=G.blob;i&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":i})]).then(()=>{Me("copy"),O(n("copied"))}).catch(()=>{O(n("copyFail"),!1)}):O(n("copyFail"),!1)},children:n(xe==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{G.url&&URL.revokeObjectURL(G.url),Ce(null),de(!1)},children:n("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:re?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:G.url,alt:n("exportGraph"),style:{maxWidth:"100%",maxHeight:re?"calc(100vh - 64px)":"70vh",borderRadius:re?0:8,cursor:"zoom-in"},onClick:()=>de(i=>!i)})})]})]})]})}function zt(o){let s=new Date(o||0).getTime();if(!s)return"#94a3b8";let m=(Date.now()-s)/864e5;return m<3?"#10b981":m<14?"#f59e0b":m<30?"#f97316":"#94a3b8"}function Tt(o){let s=new Date(o||0).getTime();return!!s&&(Date.now()-s)/864e5<3}async function rt(o,s,m){if(m&&typeof window.showSaveFilePicker=="function")try{let g=await window.showSaveFilePicker({suggestedName:s}),I=await g.createWritable();return await I.write(o),await I.close(),{ok:!0,picked:!0,name:g.name}}catch(g){return g&&g.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(g.message||g)}}let u=URL.createObjectURL(o),n=document.createElement("a");return n.href=u,n.download=s,document.body.appendChild(n),n.click(),document.body.removeChild(n),setTimeout(()=>URL.revokeObjectURL(u),1e3),{ok:!0,picked:!1,name:s}}function ot(o,s){if(!s||!o)return o;let m=o.toLowerCase(),u=s.toLowerCase(),n=[],g=0;for(;g<o.length;){let I=m.indexOf(u,g);if(I<0){n.push(o.slice(g));break}I>g&&n.push(o.slice(g,I)),n.push((0,e.jsx)("mark",{className:"mc-hl",children:o.slice(I,I+u.length)},I)),g=I+u.length}return n}function Lt(o){if(!o)return"";let s=String(o).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),m=[];return s=s.replace(/```([\w-]*)\n([\s\S]*?)```/g,function(u,n,g){return m.push("<pre><code>"+g+"</code></pre>"),"\0"+(m.length-1)+"\0"}),s=s.replace(/^(#{1,3})\s+(.+)$/gm,function(u,n,g){return"<h"+n.length+">"+g+"</h"+n.length+">"}),s=s.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),s=s.replace(/`([^`\n]+)`/g,"<code>$1</code>"),s=s.replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>"),s=s.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(u,n,g){return/^(https?:|\/)/.test(g)?'<a href="'+g+'" target="_blank" rel="noopener noreferrer">'+n+"</a>":n}),s=s.replace(/^(-)\s+(.+)$/gm,"\u2022 $2"),s=s.replace(/^\s*(>)\s*(.+)$/gm,"<blockquote>$2</blockquote>"),s=s.replace(/\n/g,"<br/>"),s=s.replace(/\u0000(\d+)\u0000/g,function(u,n){return m[n]}),s}function it(o){if(!o)return"";let s=new Date(o);if(Number.isNaN(s.getTime()))return"";let m=new Date,u=s.toDateString()===m.toDateString(),n=I=>String(I).padStart(2,"0"),g=`${n(s.getHours())}:${n(s.getMinutes())}`;return u?g:`${s.getMonth()+1}-${s.getDate()} ${g}`}
|
|
114
114
|
|
|
115
115
|
return module.exports;
|
|
116
116
|
},
|
package/lib/vault.js
CHANGED
|
@@ -270,8 +270,8 @@ export async function appendUpdate(root, rel, updateText, { threshold = 0.62 } =
|
|
|
270
270
|
return { ok: true, path: rel, kind: meta.kind || 'knowledge', updated: now }
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
/** 检索:整词/中文 bigram 命中 path + 正文。返回卡片摘要(带命中度)。minScore
|
|
274
|
-
export async function search(root, query, { limit = 30, minScore = 0 } = {}) {
|
|
273
|
+
/** 检索:整词/中文 bigram 命中 path + 正文。返回卡片摘要(带命中度)。minScore 过滤弱命中;semantic=true 加本地语义分。 */
|
|
274
|
+
export async function search(root, query, { limit = 30, minScore = 0, semantic = false } = {}) {
|
|
275
275
|
const q = String(query || '').trim()
|
|
276
276
|
if (!q) return []
|
|
277
277
|
const cards = await listCards(root)
|
|
@@ -290,6 +290,8 @@ export async function search(root, query, { limit = 30, minScore = 0 } = {}) {
|
|
|
290
290
|
for (const term of wanted) {
|
|
291
291
|
if (haystack.includes(term.toLowerCase())) score += 1
|
|
292
292
|
}
|
|
293
|
+
// 本地语义加分:Jaccard bigram 相似度(无 embedding 依赖),覆盖「同义改写/片段命中」
|
|
294
|
+
if (semantic) score += Math.round(textSimilarity(q, `${card.title} ${card.summary}`) * 6)
|
|
293
295
|
if (score > 0 && score >= minScore) {
|
|
294
296
|
out.push({ ...card, score })
|
|
295
297
|
}
|
|
@@ -298,6 +300,30 @@ export async function search(root, query, { limit = 30, minScore = 0 } = {}) {
|
|
|
298
300
|
return out.slice(0, limit)
|
|
299
301
|
}
|
|
300
302
|
|
|
303
|
+
/** 当日简报:按 mtime 列出今天新增/更新的卡(供每日回顾)。 */
|
|
304
|
+
export function dailyBrief(cardsToday) {
|
|
305
|
+
if (!cardsToday || cardsToday.length === 0) return '今天还没有新的记忆沉淀。'
|
|
306
|
+
return cardsToday.map((c) => `- ${c.kind}|${c.title}`).join('\n')
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 生成今日简报文件到 00-System/daily-YYYY-MM-DD.md,幂等(已存在则跳过)。 */
|
|
310
|
+
export async function generateDailyBrief(root) {
|
|
311
|
+
const d = new Date()
|
|
312
|
+
const date = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
313
|
+
const dir = path.join(root, '00-System')
|
|
314
|
+
const file = path.join(dir, `daily-${date}.md`)
|
|
315
|
+
try {
|
|
316
|
+
if (await exists(file)) return { ok: true, existed: true, file }
|
|
317
|
+
const s = await stats(root)
|
|
318
|
+
const content = `---\nkind: prompt\ntitle: 每日回顾 ${date}\ntags: [每日回顾, 统计]\ncreated: ${new Date().toISOString()}\nupdated: ${new Date().toISOString()}\nsource: daily-brief\n---\n# 每日回顾 ${date}\n\n今日新增 ${s.today} · 近 7 天 ${s.week} · 总 ${s.total}\n\n## 今日沉淀\n${dailyBrief(s.todayCards)}\n`
|
|
319
|
+
await fs.mkdir(dir, { recursive: true })
|
|
320
|
+
await fs.writeFile(file, content, 'utf8')
|
|
321
|
+
return { ok: true, existed: false, file }
|
|
322
|
+
} catch (e) {
|
|
323
|
+
return { ok: false, error: String(e.message || e) }
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
301
327
|
/** 导出全部卡片原始 Markdown。 */
|
|
302
328
|
export async function exportCards(root) {
|
|
303
329
|
const cards = await listCards(root)
|
|
@@ -407,6 +433,33 @@ export async function stats(root) {
|
|
|
407
433
|
}
|
|
408
434
|
}
|
|
409
435
|
|
|
436
|
+
/** 跨库聚合图谱:roots = [{name, root}],每个 vault 的子图合并(node id 前缀 profile 名避免冲突)。 */
|
|
437
|
+
export async function graphAll(roots) {
|
|
438
|
+
const nodes = []; const edges = []; const idSet = new Set()
|
|
439
|
+
for (const r of roots) {
|
|
440
|
+
let g
|
|
441
|
+
try { g = await graph(r.root) } catch { continue }
|
|
442
|
+
const pref = r.name ? `${r.name}::` : ''
|
|
443
|
+
const map = new Map()
|
|
444
|
+
for (const n of g.nodes) { const id = pref + n.id; if (!idSet.has(id)) { idSet.add(id); map.set(n.id, id); nodes.push({ ...n, id }) } else map.set(n.id, id) }
|
|
445
|
+
for (const e of g.edges) { const s = map.get(e.source) || (pref + e.source), t = map.get(e.target) || (pref + e.target); if (s && t) edges.push({ source: s, target: t, type: e.type }) }
|
|
446
|
+
}
|
|
447
|
+
return { nodes, edges }
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** 跨库聚合检索:多个 vault 的结果合并(path 前缀 profile 名)。 */
|
|
451
|
+
export async function searchAll(roots, query, opts = {}) {
|
|
452
|
+
const out = []
|
|
453
|
+
for (const r of roots) {
|
|
454
|
+
let hits
|
|
455
|
+
try { hits = await search(r.root, query, opts) } catch { continue }
|
|
456
|
+
const pref = r.name ? `${r.name}::` : ''
|
|
457
|
+
for (const h of hits) out.push({ ...h, path: pref + h.path, score: (h.score || 0) + (r.name ? 0 : 0), profile: r.name || '' })
|
|
458
|
+
}
|
|
459
|
+
out.sort((a, b) => b.score - a.score || b.mtime - a.mtime)
|
|
460
|
+
return out.slice(0, opts.limit || 30)
|
|
461
|
+
}
|
|
462
|
+
|
|
410
463
|
/** 整理建议(非破坏性预览):高相似卡对 + 陈旧卡(>90 天未更新且无连线)。 */
|
|
411
464
|
export async function optimizeCandidates(root) {
|
|
412
465
|
const cards = await listCards(root)
|
|
@@ -439,8 +492,7 @@ export async function addFeedback(root, rec) {
|
|
|
439
492
|
}
|
|
440
493
|
|
|
441
494
|
/** 统计:按 kind 计数 + 最近 7 天更新数 + 总标签数。 */
|
|
442
|
-
export async function overview(root) {
|
|
443
|
-
const cards = await listCards(root)
|
|
495
|
+
export async function overview(root) { const cards = await listCards(root)
|
|
444
496
|
const byKind = {}
|
|
445
497
|
for (const c of cards) byKind[c.kind] = (byKind[c.kind] || 0) + 1
|
|
446
498
|
const week = Date.now() - 7 * 86400000
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memory-eternal",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|