@modusensus/dsh-mneme 0.7.5 → 0.7.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/.github/workflows/publish.yml +38 -0
- package/CHANGELOG.md +2 -0
- package/README.md +11 -7
- package/dsh-mneme/CHANGELOG.md +15 -0
- package/dsh-mneme/README.md +9 -8
- package/dsh-mneme/lib/service.js +38 -0
- package/dsh-mneme/lib/store.js +22 -0
- package/dsh-mneme/lib/tools.js +24 -18
- package/dsh-mneme/package-lock.json +2 -2
- package/dsh-mneme/package.json +1 -1
- package/dsh-mneme/scripts/sync-lib.js +3 -3
- package/dsh-mneme/src/client.js +2050 -0
- package/dsh-mneme/src/service.js +38 -0
- package/dsh-mneme/src/store.js +22 -0
- package/dsh-mneme/src/tools.js +24 -18
- package/dsh-mneme/test/client.test.js +10 -5
- package/dsh-mneme/test/tools.test.js +133 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2050 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@modusensus/dsh-mneme",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let { useState, useEffect, useCallback, useRef } = react;
|
|
10
|
+
const IconArchiveOutline20 = primitives.IconArchiveOutline20;
|
|
11
|
+
|
|
12
|
+
// Portal target for the hero fallback surface. The host whitelists
|
|
13
|
+
// react-dom for its own bundles (dsh-client-ui-trajectory requires it);
|
|
14
|
+
// when the runtime rejects it for plugins the overlay renders in place —
|
|
15
|
+
// position:fixed keeps it viewport-sized either way.
|
|
16
|
+
let reactDom = null;
|
|
17
|
+
try { reactDom = require("react-dom"); } catch { reactDom = null; }
|
|
18
|
+
|
|
19
|
+
// Node-graph pictogram (three nodes joined by edges). The primitives kit
|
|
20
|
+
// ships no network/graph icon, and its share-style glyph reads as
|
|
21
|
+
// "share" — exactly the confusion this custom 16px replacement avoids.
|
|
22
|
+
const GraphNodesIcon = ({ size = 16, className }) => h("svg", {
|
|
23
|
+
width: size,
|
|
24
|
+
height: size,
|
|
25
|
+
className,
|
|
26
|
+
viewBox: "0 0 16 16",
|
|
27
|
+
fill: "none",
|
|
28
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
29
|
+
},
|
|
30
|
+
h("path", {
|
|
31
|
+
d: "M8 5.2 4.6 10.4M8 5.2l3.4 5.2M5.2 12h5.6",
|
|
32
|
+
stroke: "currentColor",
|
|
33
|
+
strokeWidth: "1.2",
|
|
34
|
+
strokeLinecap: "round",
|
|
35
|
+
strokeLinejoin: "round"
|
|
36
|
+
}),
|
|
37
|
+
h("circle", { cx: 8, cy: 3.4, r: 1.8, fill: "currentColor" }),
|
|
38
|
+
h("circle", { cx: 3.6, cy: 12, r: 1.8, fill: "currentColor" }),
|
|
39
|
+
h("circle", { cx: 12.4, cy: 12, r: 1.8, fill: "currentColor" })
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Unified API fetcher: attaches the optional apiToken (set in the settings
|
|
43
|
+
// view, persisted in localStorage) as a Bearer header. When no token has
|
|
44
|
+
// been configured the header is omitted and the API stays open (default).
|
|
45
|
+
const API_TOKEN_KEY = "dsh-mneme-api-token";
|
|
46
|
+
function apiFetch(path, opts = {}) {
|
|
47
|
+
const token = (typeof window !== "undefined" && window.localStorage)
|
|
48
|
+
? window.localStorage.getItem(API_TOKEN_KEY) || ""
|
|
49
|
+
: "";
|
|
50
|
+
const headers = { ...(opts.headers || {}) };
|
|
51
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
52
|
+
return fetch(path, { ...opts, headers });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const inject = ["slots", "locale"];
|
|
56
|
+
|
|
57
|
+
const NS = "memory";
|
|
58
|
+
|
|
59
|
+
const dictionaries = {
|
|
60
|
+
zh: {
|
|
61
|
+
"memory.panel.empty": "暂无记忆条目",
|
|
62
|
+
"memory.panel.open": "记忆",
|
|
63
|
+
"memory.tab.all": "全部",
|
|
64
|
+
"memory.tab.preference": "偏好",
|
|
65
|
+
"memory.tab.project": "项目",
|
|
66
|
+
"memory.tab.decision": "决策",
|
|
67
|
+
"memory.tab.history": "历史",
|
|
68
|
+
"memory.tab.user": "用户",
|
|
69
|
+
"memory.tab.fact": "事实",
|
|
70
|
+
"memory.settings.title": "记忆库设置",
|
|
71
|
+
"memory.settings.profile": "用户画像",
|
|
72
|
+
"memory.settings.profileHint": "描述你自己(角色、背景、偏好),Agent 会在每轮遵循",
|
|
73
|
+
"memory.settings.profileSave": "保存画像",
|
|
74
|
+
"memory.settings.profileSaved": "画像已保存",
|
|
75
|
+
"memory.settings.rules": "规则",
|
|
76
|
+
"memory.settings.rulesHint": "Agent 必须遵守的行为规则,每轮注入",
|
|
77
|
+
"memory.settings.autoTagTitle": "自动打标签",
|
|
78
|
+
"memory.settings.autoTagHint": "开启后,新记忆由轻量模型自动打标签,目录页按标签自动分类(opt-in,默认关)",
|
|
79
|
+
"memory.settings.autoTagEnabled": "自动打标签",
|
|
80
|
+
"memory.settings.autoTagSave": "保存",
|
|
81
|
+
"memory.settings.autoTagSaved": "已保存",
|
|
82
|
+
"memory.settings.sidebarTriggerTitle": "侧边栏入口按钮",
|
|
83
|
+
"memory.settings.sidebarTriggerHint": "关闭后隐藏侧边栏底部(左下角)的记忆入口按钮。与其他插件 UI 冲突时建议关闭;记忆库仍可通过顶部「记忆库」标签访问",
|
|
84
|
+
"memory.settings.sidebarTriggerEnabled": "显示左下角入口按钮",
|
|
85
|
+
"memory.settings.sidebarTriggerSave": "保存",
|
|
86
|
+
"memory.settings.sidebarTriggerSaved": "已保存",
|
|
87
|
+
"memory.settings.ruleAdd": "添加规则",
|
|
88
|
+
"memory.settings.rulePlaceholder": "例如:回答时总是先给结论",
|
|
89
|
+
"memory.settings.commands": "自定义指令",
|
|
90
|
+
"memory.settings.commandsHint": "注册斜杠命令(/名称),触发时把指令内容交给 Agent",
|
|
91
|
+
"memory.settings.cmdName": "命令名",
|
|
92
|
+
"memory.settings.cmdDesc": "描述",
|
|
93
|
+
"memory.settings.cmdInstruction": "指令内容",
|
|
94
|
+
"memory.settings.cmdAdd": "添加命令",
|
|
95
|
+
"memory.settings.cmdDelete": "删除",
|
|
96
|
+
"memory.settings.empty": "暂无内容",
|
|
97
|
+
"memory.panel.semantic": "语义",
|
|
98
|
+
"memory.sidebar.aria": "打开记忆库",
|
|
99
|
+
"memory.view.label": "记忆库",
|
|
100
|
+
"memory.overlay.close": "关闭",
|
|
101
|
+
"memory.explorer.tabMemory": "记忆",
|
|
102
|
+
"memory.explorer.tabGraph": "图谱",
|
|
103
|
+
"memory.explorer.tabDirectory": "目录",
|
|
104
|
+
"memory.explorer.tabSettings": "设置",
|
|
105
|
+
"memory.explorer.tabOverview": "总览",
|
|
106
|
+
"memory.explorer.search": "搜索标题或内容…",
|
|
107
|
+
"memory.explorer.searchTitle": "语义检索",
|
|
108
|
+
"memory.explorer.types": "分类",
|
|
109
|
+
"memory.explorer.timeline": "时间树",
|
|
110
|
+
"memory.explorer.detail": "详情",
|
|
111
|
+
"memory.explorer.emptyDetail": "在时间树中选择一条记忆查看全文",
|
|
112
|
+
"memory.explorer.copy": "复制全文",
|
|
113
|
+
"memory.explorer.copied": "已复制",
|
|
114
|
+
"memory.explorer.refresh": "刷新",
|
|
115
|
+
"memory.explorer.count": "共 {n} 条",
|
|
116
|
+
"memory.explorer.empty": "暂无记忆条目",
|
|
117
|
+
"memory.explorer.source": "来源",
|
|
118
|
+
"memory.explorer.created": "创建",
|
|
119
|
+
"memory.explorer.updated": "更新",
|
|
120
|
+
"memory.explorer.tags": "标签",
|
|
121
|
+
"memory.explorer.tagAdd": "添加标签",
|
|
122
|
+
"memory.explorer.tagRemove": "移除标签",
|
|
123
|
+
"memory.explorer.tagPlaceholder": "输入标签,回车添加",
|
|
124
|
+
"memory.explorer.tagsEmpty": "暂无标签",
|
|
125
|
+
"memory.explorer.importance": "重要性",
|
|
126
|
+
"memory.explorer.topK": "返回数量",
|
|
127
|
+
"memory.explorer.topKOption": "返回 {n} 条",
|
|
128
|
+
"memory.overview.empty": "还没有记忆。开始对话后 Agent 会自动沉淀记忆,这里会展示分层总览",
|
|
129
|
+
"memory.overview.profileEmpty": "暂无用户画像记忆,可在对话中让 AI 记录",
|
|
130
|
+
"memory.overview.distribution": "类型分布",
|
|
131
|
+
"memory.overview.layers": "记忆分层",
|
|
132
|
+
"memory.overview.trend": "近 7 天趋势",
|
|
133
|
+
"memory.overview.none": "暂无",
|
|
134
|
+
"memory.overview.badgeInject": "常注入",
|
|
135
|
+
"memory.overview.badgeImportance": "按重要性",
|
|
136
|
+
"memory.directory.untagged": "无标签",
|
|
137
|
+
"memory.directory.loading": "加载中…",
|
|
138
|
+
"memory.directory.empty": "暂无记忆条目",
|
|
139
|
+
"directory.editToggle": "编辑模式(显示删除)",
|
|
140
|
+
"directory.deleteConfirm": "确定删除这条记忆吗?",
|
|
141
|
+
"directory.deleteConfirmShort": "确认?",
|
|
142
|
+
"directory.deleteError": "删除失败",
|
|
143
|
+
"memory.card.open": "在主区记忆库中查看全文",
|
|
144
|
+
"memory.time.now": "刚刚",
|
|
145
|
+
"memory.time.seconds": "{n}秒前",
|
|
146
|
+
"memory.time.minutes": "{n}分钟前",
|
|
147
|
+
"memory.time.hours": "{n}小时前",
|
|
148
|
+
"memory.time.days": "{n}天前",
|
|
149
|
+
"memory.graph.title": "记忆图谱",
|
|
150
|
+
"memory.graph.aria": "记忆图谱",
|
|
151
|
+
"memory.graph.placeholder": "输入实体名,查看关联网络…",
|
|
152
|
+
"memory.graph.depth": "跳数",
|
|
153
|
+
"memory.graph.empty": "图谱待积累:随对话记忆的沉淀,实体与关系会自动进入图谱",
|
|
154
|
+
"memory.graph.notFound": "未找到该实体",
|
|
155
|
+
"memory.graph.attrs": "属性",
|
|
156
|
+
"memory.graph.related": "关联记忆",
|
|
157
|
+
"memory.graph.relation": "关系",
|
|
158
|
+
"memory.graph.sourceMemory": "查看来源记忆",
|
|
159
|
+
"memory.graph.hint": "点击节点展开 · 拖拽调整布局",
|
|
160
|
+
"memory.graph.viewInGraph": "在图谱中查看",
|
|
161
|
+
"memory.graph.loading": "加载中…",
|
|
162
|
+
"memory.graph.distance": "距中心 {n} 跳",
|
|
163
|
+
"memory.settings.vectorTitle": "向量搜索",
|
|
164
|
+
"memory.settings.vectorHint": "接入 OpenAI 兼容的 embeddings API 做语义搜索,可匹配字面不同但语义相近的记忆",
|
|
165
|
+
"memory.settings.vectorEnabled": "启用向量搜索",
|
|
166
|
+
"memory.settings.vectorBaseUrl": "API 地址 (Base URL)",
|
|
167
|
+
"memory.settings.vectorApiKey": "API Key",
|
|
168
|
+
"memory.settings.vectorModel": "模型名",
|
|
169
|
+
"memory.settings.vectorSave": "保存配置",
|
|
170
|
+
"memory.settings.vectorSaved": "配置已保存",
|
|
171
|
+
"memory.settings.vectorReindex": "重建索引",
|
|
172
|
+
"memory.settings.vectorReindexing": "索引中…",
|
|
173
|
+
"memory.settings.vectorReindexDone": "已索引 {n} 条",
|
|
174
|
+
"memory.settings.apiTokenTitle": "API Token(可选)",
|
|
175
|
+
"memory.settings.apiTokenHint": "设置后,写操作与密钥接口(画像/规则/命令/向量配置)需携带 Authorization: Bearer <token>;面板只读操作不受影响。清空并保存可关闭鉴权。",
|
|
176
|
+
"memory.settings.apiTokenPlaceholder": "留空 = 不鉴权(默认)",
|
|
177
|
+
"memory.settings.apiTokenSave": "保存 Token",
|
|
178
|
+
"memory.settings.apiTokenSaved": "Token 已保存",
|
|
179
|
+
"memory.wikilink.backlinks": "链接到此记忆",
|
|
180
|
+
"memory.wikilink.forward": "此记忆链接到",
|
|
181
|
+
"memory.wikilink.empty": "暂无关联记忆",
|
|
182
|
+
"memory.wikilink.loading": "加载中…",
|
|
183
|
+
"memory.wikilink.unresolved": "目标记忆不存在"
|
|
184
|
+
},
|
|
185
|
+
en: {
|
|
186
|
+
"memory.panel.empty": "No memories yet",
|
|
187
|
+
"memory.panel.open": "Memory",
|
|
188
|
+
"memory.tab.all": "All",
|
|
189
|
+
"memory.tab.preference": "Preferences",
|
|
190
|
+
"memory.tab.project": "Projects",
|
|
191
|
+
"memory.tab.decision": "Decisions",
|
|
192
|
+
"memory.tab.history": "History",
|
|
193
|
+
"memory.tab.user": "User",
|
|
194
|
+
"memory.tab.fact": "Facts",
|
|
195
|
+
"memory.settings.title": "Memory Settings",
|
|
196
|
+
"memory.settings.profile": "User Profile",
|
|
197
|
+
"memory.settings.profileHint": "Describe yourself — the agent follows this every turn",
|
|
198
|
+
"memory.settings.profileSave": "Save Profile",
|
|
199
|
+
"memory.settings.profileSaved": "Profile saved",
|
|
200
|
+
"memory.settings.rules": "Rules",
|
|
201
|
+
"memory.settings.rulesHint": "Behavior rules the agent must follow every turn",
|
|
202
|
+
"memory.settings.autoTagTitle": "Auto-Tag",
|
|
203
|
+
"memory.settings.autoTagHint": "When on, new memories are auto-tagged by a light model and the directory auto-grouped by tag (opt-in, off by default)",
|
|
204
|
+
"memory.settings.autoTagEnabled": "Auto-tagging",
|
|
205
|
+
"memory.settings.autoTagSave": "Save",
|
|
206
|
+
"memory.settings.autoTagSaved": "Saved",
|
|
207
|
+
"memory.settings.sidebarTriggerTitle": "Sidebar trigger",
|
|
208
|
+
"memory.settings.sidebarTriggerHint": "Hide the memory entrance button at the sidebar footer (bottom-left) when it clashes with other plugins. The library stays reachable via the 记忆库 conversation tab",
|
|
209
|
+
"memory.settings.sidebarTriggerEnabled": "Show the bottom-left trigger",
|
|
210
|
+
"memory.settings.sidebarTriggerSave": "Save",
|
|
211
|
+
"memory.settings.sidebarTriggerSaved": "Saved",
|
|
212
|
+
"memory.settings.ruleAdd": "Add Rule",
|
|
213
|
+
"memory.settings.rulePlaceholder": "e.g. Always lead with a conclusion",
|
|
214
|
+
"memory.settings.commands": "Custom Commands",
|
|
215
|
+
"memory.settings.commandsHint": "Register slash commands (/name) whose instruction is handed to the agent",
|
|
216
|
+
"memory.settings.cmdName": "Name",
|
|
217
|
+
"memory.settings.cmdDesc": "Description",
|
|
218
|
+
"memory.settings.cmdInstruction": "Instruction",
|
|
219
|
+
"memory.settings.cmdAdd": "Add Command",
|
|
220
|
+
"memory.settings.cmdDelete": "Delete",
|
|
221
|
+
"memory.settings.empty": "Nothing yet",
|
|
222
|
+
"memory.panel.semantic": "Semantic",
|
|
223
|
+
"memory.sidebar.aria": "Open memory panel",
|
|
224
|
+
"memory.view.label": "Memory",
|
|
225
|
+
"memory.overlay.close": "Close",
|
|
226
|
+
"memory.explorer.tabMemory": "Memories",
|
|
227
|
+
"memory.explorer.tabGraph": "Graph",
|
|
228
|
+
"memory.explorer.tabDirectory": "Directory",
|
|
229
|
+
"memory.explorer.tabSettings": "Settings",
|
|
230
|
+
"memory.explorer.tabOverview": "Overview",
|
|
231
|
+
"memory.explorer.search": "Search title or content…",
|
|
232
|
+
"memory.explorer.searchTitle": "Semantic Search",
|
|
233
|
+
"memory.explorer.types": "Types",
|
|
234
|
+
"memory.explorer.timeline": "Timeline",
|
|
235
|
+
"memory.explorer.detail": "Details",
|
|
236
|
+
"memory.explorer.emptyDetail": "Select a memory in the timeline to read it",
|
|
237
|
+
"memory.explorer.copy": "Copy content",
|
|
238
|
+
"memory.explorer.copied": "Copied",
|
|
239
|
+
"memory.explorer.refresh": "Refresh",
|
|
240
|
+
"memory.explorer.count": "{n} items",
|
|
241
|
+
"memory.explorer.empty": "No memories yet",
|
|
242
|
+
"memory.explorer.source": "Source",
|
|
243
|
+
"memory.explorer.created": "Created",
|
|
244
|
+
"memory.explorer.updated": "Updated",
|
|
245
|
+
"memory.explorer.tags": "Tags",
|
|
246
|
+
"memory.explorer.tagAdd": "Add tag",
|
|
247
|
+
"memory.explorer.tagRemove": "Remove tag",
|
|
248
|
+
"memory.explorer.tagPlaceholder": "Type a tag, press Enter",
|
|
249
|
+
"memory.explorer.tagsEmpty": "No tags",
|
|
250
|
+
"memory.explorer.importance": "Importance",
|
|
251
|
+
"memory.explorer.topK": "Results limit",
|
|
252
|
+
"memory.explorer.topKOption": "Return {n}",
|
|
253
|
+
"memory.overview.empty": "No memories yet. Once you chat, the agent starts saving memories and the layered overview appears here",
|
|
254
|
+
"memory.overview.profileEmpty": "No user-profile memories yet — ask the agent to remember things about you in chat",
|
|
255
|
+
"memory.overview.distribution": "By Type",
|
|
256
|
+
"memory.overview.layers": "Memory Layers",
|
|
257
|
+
"memory.overview.trend": "Last 7 days",
|
|
258
|
+
"memory.overview.none": "None",
|
|
259
|
+
"memory.overview.badgeInject": "Auto-inject",
|
|
260
|
+
"memory.overview.badgeImportance": "By importance",
|
|
261
|
+
"memory.directory.untagged": "Untagged",
|
|
262
|
+
"memory.directory.loading": "Loading…",
|
|
263
|
+
"memory.directory.empty": "No memories yet",
|
|
264
|
+
"directory.editToggle": "Edit mode",
|
|
265
|
+
"directory.deleteConfirm": "Delete this memory?",
|
|
266
|
+
"directory.deleteConfirmShort": "Confirm?",
|
|
267
|
+
"directory.deleteError": "Delete failed",
|
|
268
|
+
"memory.card.open": "Open full text in the Memory tab",
|
|
269
|
+
"memory.time.now": "just now",
|
|
270
|
+
"memory.time.seconds": "{n}s ago",
|
|
271
|
+
"memory.time.minutes": "{n}m ago",
|
|
272
|
+
"memory.time.hours": "{n}h ago",
|
|
273
|
+
"memory.time.days": "{n}d ago",
|
|
274
|
+
"memory.graph.title": "Memory Graph",
|
|
275
|
+
"memory.graph.aria": "Memory graph",
|
|
276
|
+
"memory.graph.placeholder": "Type an entity name to see its network…",
|
|
277
|
+
"memory.graph.depth": "hops",
|
|
278
|
+
"memory.graph.empty": "The graph is waiting for data: entities and relations accumulate as memories are extracted",
|
|
279
|
+
"memory.graph.notFound": "Entity not found",
|
|
280
|
+
"memory.graph.attrs": "Attributes",
|
|
281
|
+
"memory.graph.related": "Related memories",
|
|
282
|
+
"memory.graph.relation": "Relation",
|
|
283
|
+
"memory.graph.sourceMemory": "View source memory",
|
|
284
|
+
"memory.graph.hint": "Click a node to expand · drag to rearrange",
|
|
285
|
+
"memory.graph.viewInGraph": "View in graph",
|
|
286
|
+
"memory.graph.loading": "Loading…",
|
|
287
|
+
"memory.graph.distance": "{n} hop(s) from root",
|
|
288
|
+
"memory.settings.vectorTitle": "Vector Search",
|
|
289
|
+
"memory.settings.vectorHint": "Connect an OpenAI-compatible embeddings API for semantic search by meaning, not just keywords",
|
|
290
|
+
"memory.settings.vectorEnabled": "Enable vector search",
|
|
291
|
+
"memory.settings.vectorBaseUrl": "Base URL",
|
|
292
|
+
"memory.settings.vectorApiKey": "API Key",
|
|
293
|
+
"memory.settings.vectorModel": "Model",
|
|
294
|
+
"memory.settings.vectorSave": "Save Config",
|
|
295
|
+
"memory.settings.vectorSaved": "Config saved",
|
|
296
|
+
"memory.settings.vectorReindex": "Reindex",
|
|
297
|
+
"memory.settings.vectorReindexing": "Indexing…",
|
|
298
|
+
"memory.settings.vectorReindexDone": "Indexed {n} items",
|
|
299
|
+
"memory.settings.apiTokenTitle": "API Token (optional)",
|
|
300
|
+
"memory.settings.apiTokenHint": "When set, write operations and secret endpoints (profile/rules/commands/vector config) require Authorization: Bearer <token>. Read-only panel calls stay open. Save empty to disable.",
|
|
301
|
+
"memory.settings.apiTokenPlaceholder": "Empty = no auth (default)",
|
|
302
|
+
"memory.settings.apiTokenSave": "Save Token",
|
|
303
|
+
"memory.settings.apiTokenSaved": "Token saved",
|
|
304
|
+
"memory.wikilink.backlinks": "Links to this memory",
|
|
305
|
+
"memory.wikilink.forward": "This memory links to",
|
|
306
|
+
"memory.wikilink.empty": "No linked memories",
|
|
307
|
+
"memory.wikilink.loading": "Loading…",
|
|
308
|
+
"memory.wikilink.unresolved": "Target memory not found"
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
function typeLabel(t, type) {
|
|
313
|
+
const key = `memory.tab.${type}`;
|
|
314
|
+
const label = t(key);
|
|
315
|
+
return label && label !== key ? label : String(type);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function formatDate(value) {
|
|
319
|
+
if (!value) return "—";
|
|
320
|
+
const date = new Date(value);
|
|
321
|
+
return Number.isNaN(date.getTime()) ? "—" : date.toLocaleString();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Relative time ("2分钟前") keeps cards scannable; anything older than a
|
|
325
|
+
// week falls back to the absolute date. The card meta shows the relative
|
|
326
|
+
// form and carries the full timestamp in a title tooltip.
|
|
327
|
+
function formatRelativeTime(value, t) {
|
|
328
|
+
if (!value) return "—";
|
|
329
|
+
const ms = new Date(value).getTime();
|
|
330
|
+
if (Number.isNaN(ms)) return "—";
|
|
331
|
+
const diff = Date.now() - ms;
|
|
332
|
+
if (diff < 60_000) return t("memory.time.now");
|
|
333
|
+
const minutes = Math.floor(diff / 60_000);
|
|
334
|
+
if (minutes < 60) return t("memory.time.minutes").replace("{n}", String(minutes));
|
|
335
|
+
const hours = Math.floor(minutes / 60);
|
|
336
|
+
if (hours < 24) return t("memory.time.hours").replace("{n}", String(hours));
|
|
337
|
+
const days = Math.floor(hours / 24);
|
|
338
|
+
if (days < 7) return t("memory.time.days").replace("{n}", String(days));
|
|
339
|
+
return new Date(ms).toLocaleDateString();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Memory-library stylesheet, injected once per page following the host's
|
|
343
|
+
// data-plugin-css convention. Every value resolves to the host's design
|
|
344
|
+
// tokens: background layers, label/border/interactive aliases and the
|
|
345
|
+
// --dsw-font-* scale, so the page reads as a first-party view beside
|
|
346
|
+
// Chat / Trajectory (flat layer-1 canvas, hairline column separators,
|
|
347
|
+
// text-turns-brand-blue active states — no boxed panels).
|
|
348
|
+
const CSS_TAG = "@modusensus/dsh-mneme/drawer.css";
|
|
349
|
+
const css = [
|
|
350
|
+
// --- sidebar foot trigger (wide row / collapsed rail icon) ---
|
|
351
|
+
".mneme-trigger{box-sizing:border-box;cursor:pointer;width:calc(100% + 4px);height:42px;color:var(--dsw-alias-label-primary);background:0 0;border:none;border-radius:12px;flex:none;align-items:center;gap:8px;margin:4px -2px;padding:0 10px 0 8px;font-family:inherit;font-size:14px;line-height:22px;display:flex;overflow:hidden}",
|
|
352
|
+
".mneme-trigger:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
353
|
+
".mneme-trigger.mneme-rail{border-radius:50%;justify-content:center;gap:0;width:36px;height:36px;margin:8px 0 10px;padding:0}",
|
|
354
|
+
".mneme-trigger-label{white-space:nowrap;overflow:hidden}",
|
|
355
|
+
// --- shared controls ---
|
|
356
|
+
".mneme-search{box-sizing:border-box;height:30px;padding:0 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base,transparent);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px;outline:none;transition:border-color .12s,box-shadow .12s}",
|
|
357
|
+
".mneme-search:focus{border-color:var(--dsw-alias-state-business-primary);box-shadow:0 0 0 3px color-mix(in srgb,var(--dsw-alias-state-business-primary) 15%,transparent)}",
|
|
358
|
+
".mneme-search::placeholder{color:var(--dsw-alias-label-tertiary)}",
|
|
359
|
+
".mneme-chip{height:26px;padding:0 10px;border-radius:8px;border:1px solid transparent;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:12px;line-height:16px;display:inline-flex;align-items:center}",
|
|
360
|
+
".mneme-chip:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
361
|
+
".mneme-chip.mneme-active{color:var(--dsw-alias-state-business-primary);background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 10%,transparent)}",
|
|
362
|
+
".mneme-select{box-sizing:border-box;height:30px;padding:0 8px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base,transparent);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px;outline:none}",
|
|
363
|
+
".mneme-footbtn{border:none;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:12px;line-height:16px;padding:3px 8px;border-radius:6px}",
|
|
364
|
+
".mneme-footbtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}",
|
|
365
|
+
".mneme-hint{color:var(--dsw-alias-label-tertiary);padding:24px 0;text-align:center;font-size:13px}",
|
|
366
|
+
".mneme-entitychip{flex:none;height:26px;padding:0 10px;border-radius:8px;border:none;background:none;color:var(--dsw-alias-state-business-primary);cursor:pointer;font-family:inherit;font-size:12px;line-height:16px;display:inline-flex;align-items:center}",
|
|
367
|
+
".mneme-entitychip:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 10%,transparent)}",
|
|
368
|
+
// --- tag chips in the detail meta (v0.6.2) ---
|
|
369
|
+
".mneme-tagrow{display:flex;flex-wrap:wrap;gap:6px;align-items:center}",
|
|
370
|
+
".mneme-tagchip{display:inline-flex;align-items:center;gap:4px;max-width:100%;height:22px;padding:0 4px 0 8px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base,transparent);color:var(--dsw-alias-state-business-primary);cursor:pointer;font-family:inherit;font-size:12px;line-height:16px}",
|
|
371
|
+
".mneme-tagchip:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 10%,transparent)}",
|
|
372
|
+
".mneme-tagremove{flex:none;display:inline-flex;align-items:center;justify-content:center;width:14px;height:14px;border:none;border-radius:4px;background:none;color:var(--dsw-alias-label-tertiary);cursor:pointer;font-family:inherit;font-size:12px;line-height:1;padding:0}",
|
|
373
|
+
".mneme-tagremove:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}",
|
|
374
|
+
".mneme-tagadd{border:none;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:12px;line-height:16px;padding:2px 8px;border-radius:6px;flex:none}",
|
|
375
|
+
".mneme-tagadd:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}",
|
|
376
|
+
".mneme-taginput{box-sizing:border-box;height:22px;padding:0 8px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base,transparent);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;outline:none;width:150px}",
|
|
377
|
+
".mneme-taginput:focus{border-color:var(--dsw-alias-state-business-primary)}",
|
|
378
|
+
".mneme-tagempty{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:16px}",
|
|
379
|
+
// --- main-area memory library page ---
|
|
380
|
+
".mneme-x{flex:1;min-height:0;height:100%;width:100%;box-sizing:border-box;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}",
|
|
381
|
+
".mneme-xbar{flex:none;display:flex;align-items:center;gap:6px;border-bottom:1px solid var(--dsw-alias-border-l2);padding:0 16px}",
|
|
382
|
+
".mneme-filterbar{flex:none;display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 16px;border-bottom:1px solid var(--dsw-alias-border-l2)}",
|
|
383
|
+
".mneme-vtabs{display:flex;align-items:stretch;height:38px}",
|
|
384
|
+
".mneme-vtab{position:relative;border:0;background:none;cursor:pointer;padding:0 10px;color:var(--dsw-alias-label-tertiary);font-family:inherit;font-size:13px;font-weight:500;line-height:16px;display:inline-flex;align-items:center;gap:6px}",
|
|
385
|
+
".mneme-vtab:hover{color:var(--dsw-alias-label-primary)}",
|
|
386
|
+
".mneme-vtab.mneme-active{color:var(--dsw-alias-state-business-primary)}",
|
|
387
|
+
".mneme-vtab.mneme-active::after{content:\"\";position:absolute;left:8px;right:8px;bottom:-1px;height:2px;border-radius:2px;background:var(--dsw-alias-state-business-primary)}",
|
|
388
|
+
".mneme-xtools{margin-left:auto;display:flex;align-items:center;gap:8px;padding:0 0 0 12px}",
|
|
389
|
+
".mneme-xcount{flex:none;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);white-space:nowrap}",
|
|
390
|
+
// --- memory explorer cards (column layout) ---
|
|
391
|
+
".mneme-xrow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
392
|
+
".mneme-xsearch{width:100%}",
|
|
393
|
+
".mneme-xselect{flex:1;min-width:0}",
|
|
394
|
+
".mneme-xcolhead{flex:none;font-size:12px;font-weight:500;color:var(--dsw-alias-label-tertiary);padding:2px 8px 8px}",
|
|
395
|
+
".mneme-xtype{display:flex;justify-content:space-between;align-items:center;gap:8px;width:100%;padding:5px 8px;border:none;border-radius:8px;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:13px;line-height:18px;text-align:left}",
|
|
396
|
+
".mneme-xtype:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
397
|
+
".mneme-xtype.mneme-active{background:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary);font-weight:500}",
|
|
398
|
+
".mneme-xcount2{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}",
|
|
399
|
+
".mneme-xmonth{display:flex;align-items:center;gap:4px;width:100%;padding:6px 8px 4px;border:none;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);cursor:pointer;font-family:inherit;font-size:13px;font-weight:500;line-height:18px;text-align:left}",
|
|
400
|
+
".mneme-xmonth:first-child{margin-top:0}",
|
|
401
|
+
".mneme-xmonth:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
402
|
+
".mneme-xcaret{flex:none;font-size:10px;color:var(--dsw-alias-label-tertiary);width:10px}",
|
|
403
|
+
".mneme-xday{display:flex;align-items:center;gap:4px;margin:6px 0 2px 22px;padding:2px 6px;border:none;border-radius:6px;background:none;font-family:inherit;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);cursor:pointer;text-align:left}",
|
|
404
|
+
".mneme-xday:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}",
|
|
405
|
+
".mneme-xitem{display:flex;gap:8px;align-items:baseline;width:calc(100% - 22px);margin-left:22px;padding:4px 8px;border:none;border-radius:8px;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:13px;line-height:18px;text-align:left}",
|
|
406
|
+
".mneme-xitem:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
407
|
+
".mneme-xitem.mneme-active{background:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary)}",
|
|
408
|
+
".mneme-xtime{flex:none;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
409
|
+
".mneme-xname{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
410
|
+
".mneme-xempty{padding:32px 16px;text-align:center;color:var(--dsw-alias-label-tertiary);font-size:13px}",
|
|
411
|
+
// --- memory explorer root ---
|
|
412
|
+
".mneme-xmain{display:flex;flex-direction:column}",
|
|
413
|
+
".mneme-xfilter-bar{flex:none;height:48px;display:flex;align-items:center;gap:8px;padding:0 12px;border-bottom:1px solid var(--dsw-alias-border-l2,#ddd)}",
|
|
414
|
+
".mneme-xcards{flex:1;display:flex;flex-direction:row;gap:12px;padding:12px;overflow:hidden}",
|
|
415
|
+
".mneme-card{background:var(--dsw-alias-bg-base,#fafafa);border-radius:8px;box-shadow:0 1px 3px rgba(0,0,0,.06);padding:12px;display:flex;flex-direction:column;overflow:auto}",
|
|
416
|
+
".mneme-card--search{width:236px;flex:none}",
|
|
417
|
+
".mneme-card--tree{width:260px;flex:none}",
|
|
418
|
+
".mneme-card--detail{flex:1;min-width:0}",
|
|
419
|
+
".mneme-xdinner{max-width:720px}",
|
|
420
|
+
".mneme-xdtitle{font-size:16px;font-weight:600;line-height:24px;color:var(--dsw-alias-label-primary);margin-bottom:10px;word-break:break-word}",
|
|
421
|
+
".mneme-xdmeta{display:flex;flex-wrap:wrap;gap:4px 14px;margin-bottom:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}",
|
|
422
|
+
".mneme-xdcontent{margin-top:14px;font-size:14px;line-height:1.75;color:var(--dsw-alias-label-primary);white-space:pre-wrap;word-break:break-word}",
|
|
423
|
+
".mneme-xdactions{display:flex;gap:8px;margin-top:18px}",
|
|
424
|
+
// --- wiki-link backlinks panel (detail pane footer) ---
|
|
425
|
+
".mneme-backlinks{margin-top:18px;padding-top:14px;border-top:1px solid var(--dsw-alias-border-l1);display:flex;flex-direction:column;gap:12px}",
|
|
426
|
+
".mneme-bl-block{display:flex;flex-direction:column;gap:4px}",
|
|
427
|
+
".mneme-bl-head{font-size:12px;font-weight:500;color:var(--dsw-alias-label-tertiary)}",
|
|
428
|
+
".mneme-bl-list{display:flex;flex-wrap:wrap;gap:6px}",
|
|
429
|
+
".mneme-bl-link{display:inline-flex;align-items:center;gap:6px;max-width:100%;border:none;background:none;color:var(--dsw-alias-state-business-primary);cursor:pointer;font-family:inherit;font-size:13px;line-height:18px;padding:2px 8px;border-radius:6px;text-align:left}",
|
|
430
|
+
".mneme-bl-link:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 10%,transparent)}",
|
|
431
|
+
".mneme-bl-link.mneme-bl-link--dim{color:var(--dsw-alias-label-tertiary);cursor:default}",
|
|
432
|
+
".mneme-bl-link.mneme-bl-link--dim:hover{background:none}",
|
|
433
|
+
".mneme-bl-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
434
|
+
".mneme-bl-meta{flex:none;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
435
|
+
".mneme-bl-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}",
|
|
436
|
+
// --- inline [[wiki-link]] links inside the detail content ---
|
|
437
|
+
".mneme-wikilink{display:inline;padding:0 2px;border:none;background:none;color:var(--dsw-alias-state-business-primary);cursor:pointer;font-family:inherit;font-size:inherit;line-height:inherit;text-decoration:underline;text-underline-offset:2px;border-radius:3px}",
|
|
438
|
+
".mneme-wikilink:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 8%,transparent)}",
|
|
439
|
+
// --- graph sub-view (fills the content area under the tabs) ---
|
|
440
|
+
".mneme-graph{flex:1;min-height:0;width:100%;display:flex;flex-direction:column;padding:12px 16px 16px;box-sizing:border-box}",
|
|
441
|
+
".mneme-graphbar{display:flex;gap:8px;align-items:center;flex:none;margin-bottom:10px}",
|
|
442
|
+
".mneme-graphsvg{flex:1;min-height:180px;width:100%;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-button-elevated-fill);cursor:grab;touch-action:none}",
|
|
443
|
+
".mneme-gnode{cursor:pointer}",
|
|
444
|
+
".mneme-gnode circle{stroke:var(--dsw-alias-bg-layer-2);stroke-width:2;transition:stroke-width .12s}",
|
|
445
|
+
".mneme-gnode:hover circle{stroke-width:4}",
|
|
446
|
+
".mneme-gnode.mneme-groot circle{stroke:var(--dsw-alias-state-business-primary);stroke-width:3}",
|
|
447
|
+
".mneme-glabel{fill:var(--dsw-alias-label-secondary);font-size:11px;text-anchor:middle;pointer-events:none;user-select:none}",
|
|
448
|
+
".mneme-gedge{stroke:var(--dsw-alias-label-dimmed);stroke-width:1.5;cursor:pointer}",
|
|
449
|
+
".mneme-gedge:hover{stroke:var(--dsw-alias-state-business-primary)}",
|
|
450
|
+
".mneme-gedge-dashed{stroke-dasharray:5 4;opacity:.7}",
|
|
451
|
+
".mneme-graphhint{flex:none;color:var(--dsw-alias-label-tertiary);font-size:13px;text-align:center;padding:6px 0 2px}",
|
|
452
|
+
".mneme-graphside{flex:none;max-height:220px;overflow-y:auto;border-top:1px solid var(--dsw-alias-border-l1);margin-top:10px;padding-top:10px}",
|
|
453
|
+
".mneme-gs-title{font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary);margin-bottom:4px;display:flex;justify-content:space-between;align-items:baseline;gap:8px}",
|
|
454
|
+
".mneme-gs-meta{font-size:13px;color:var(--dsw-alias-label-tertiary);margin-bottom:6px}",
|
|
455
|
+
".mneme-gs-attr{display:flex;gap:6px;font-size:13px;padding:2px 0}",
|
|
456
|
+
".mneme-gs-attrkey{flex:none;color:var(--dsw-alias-label-tertiary);font-size:13px}",
|
|
457
|
+
".mneme-gs-attrval{color:var(--dsw-alias-label-secondary);word-break:break-word;font-size:13px}",
|
|
458
|
+
".mneme-gs-link{display:block;width:100%;text-align:left;border:none;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:13px;padding:3px 6px;border-radius:6px;word-break:break-word}",
|
|
459
|
+
".mneme-gs-link:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}",
|
|
460
|
+
// --- directory sub-view (v0.6.3): tag folders + memory entries ---
|
|
461
|
+
".mneme-directory{flex:1;min-height:0;overflow-y:auto;padding:8px 10px 28px}",
|
|
462
|
+
".mneme-edit-toggle{margin:6px 10px;display:flex;align-items:center;gap:6px;font-size:12px;cursor:pointer;user-select:none}",
|
|
463
|
+
".mneme-dir-item{position:relative;display:flex;align-items:center;gap:6px;padding:2px 6px;border-radius:4px}",
|
|
464
|
+
".mneme-dir-item:hover{background:rgba(127,127,127,.18)}",
|
|
465
|
+
".mneme-tree-line{width:14px;height:1px;border-top:1px dashed rgba(127,127,127,.5);flex:none}",
|
|
466
|
+
".mneme-dir-item .mneme-dir-del{opacity:0;transition:opacity .12s}",
|
|
467
|
+
".mneme-dir-item:hover .mneme-dir-del{opacity:1}",
|
|
468
|
+
".mneme-dir-del{margin-left:auto;background:none;border:none;color:#e5484d;cursor:pointer;font-size:13px;line-height:1;padding:2px 4px}",
|
|
469
|
+
".mneme-dir-del:hover{filter:brightness(1.25)}",
|
|
470
|
+
".mneme-edit-on .mneme-dir-del{opacity:1}",
|
|
471
|
+
".mneme-dir-del-confirm{font-weight:700;background:rgba(229,72,77,.12);border-radius:4px}",
|
|
472
|
+
".mneme-dir-item.mneme-dir-error{background:rgba(229,72,77,.14)}",
|
|
473
|
+
".mneme-dir-del-err{flex:none;font-size:12px;line-height:16px;color:#e5484d}",
|
|
474
|
+
".mneme-dir-ititle{background:none;border:none;padding:0;font:inherit;color:inherit;cursor:pointer;flex:1;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
475
|
+
".mneme-dir-folder{margin-bottom:4px}",
|
|
476
|
+
".mneme-dir-folderhead{display:flex;align-items:center;gap:6px;width:100%;padding:6px 8px;border:none;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);cursor:pointer;font-family:inherit;font-size:13px;font-weight:500;line-height:18px;text-align:left}",
|
|
477
|
+
".mneme-dir-folderhead:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
478
|
+
".mneme-dir-caret{flex:none;width:10px;text-align:center;color:var(--dsw-alias-label-tertiary);font-size:12px}",
|
|
479
|
+
".mneme-dir-fname{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
480
|
+
".mneme-dir-fcount{flex:none;margin-left:auto;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
481
|
+
".mneme-dir-fbody{margin:2px 0 4px 22px;padding-left:8px;border-left:1px solid var(--dsw-alias-border-l2)}",
|
|
482
|
+
".mneme-dir-item{display:flex;gap:8px;align-items:baseline;width:100%;padding:4px 8px;border:none;border-radius:8px;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;font-family:inherit;font-size:13px;line-height:18px;text-align:left}",
|
|
483
|
+
".mneme-dir-item:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
484
|
+
".mneme-dir-item.mneme-active{background:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary)}",
|
|
485
|
+
".mneme-dir-ititle{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
486
|
+
".mneme-dir-itime{flex:none;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
487
|
+
".mneme-dir-empty{color:var(--dsw-alias-label-tertiary);padding:24px 0;text-align:center;font-size:13px}",
|
|
488
|
+
// --- settings sub-view ---
|
|
489
|
+
".mneme-xsettings{flex:1;min-height:0;overflow-y:auto;padding:24px 24px 48px}",
|
|
490
|
+
".mneme-xsettings-inner{max-width:640px}",
|
|
491
|
+
// --- overview sub-view (layered stats dashboard, .mneme-ov-* only) ---
|
|
492
|
+
".mneme-ov-wrap{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:12px;padding:12px 16px 28px}",
|
|
493
|
+
".mneme-ov-profile{gap:8px}",
|
|
494
|
+
".mneme-ov-prow{display:flex;flex-direction:column;gap:2px;padding:4px 0;border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
495
|
+
".mneme-ov-prow:first-of-type{border-top:none}",
|
|
496
|
+
".mneme-ov-ptitle{font-size:13px;font-weight:600;line-height:18px;color:var(--dsw-alias-label-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
497
|
+
".mneme-ov-ppreview{font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
498
|
+
".mneme-ov-dist{display:flex;flex-direction:column;gap:6px}",
|
|
499
|
+
".mneme-ov-distrow{display:flex;align-items:center;gap:8px}",
|
|
500
|
+
".mneme-ov-distlabel{flex:none;width:76px;font-size:12px;line-height:16px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
501
|
+
".mneme-ov-distcount{flex:none;width:34px;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;text-align:right}",
|
|
502
|
+
".mneme-ov-disttrack{flex:1;min-width:0;height:8px;border-radius:4px;background:var(--dsw-alias-border-l2)}",
|
|
503
|
+
".mneme-ov-distbar{height:100%;min-width:2px;border-radius:4px;background:var(--dsw-alias-state-business-primary)}",
|
|
504
|
+
".mneme-ov-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:10px}",
|
|
505
|
+
".mneme-ov-tile{box-sizing:border-box;text-align:left;border:none;cursor:pointer;font-family:inherit;gap:6px;overflow:hidden}",
|
|
506
|
+
".mneme-ov-tile:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
507
|
+
".mneme-ov-tilehead{display:flex;align-items:center;gap:6px}",
|
|
508
|
+
".mneme-ov-tiletitle{min-width:0;font-size:13px;font-weight:600;line-height:18px;color:var(--dsw-alias-label-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
509
|
+
".mneme-ov-tilecount{flex:none;margin-left:auto;font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
510
|
+
".mneme-ov-badge{flex:none;font-size:11px;line-height:16px;padding:0 6px;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 12%,transparent);color:var(--dsw-alias-state-business-primary)}",
|
|
511
|
+
".mneme-ov-badge--dim{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary)}",
|
|
512
|
+
".mneme-ov-tilelatest{font-size:12px;line-height:17px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
513
|
+
".mneme-ov-trend{display:flex;align-items:flex-end;gap:8px;padding:8px 4px 0}",
|
|
514
|
+
".mneme-ov-trendcol{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center;gap:4px}",
|
|
515
|
+
".mneme-ov-trendbar{width:min(100%,30px);border-radius:4px 4px 0 0;background:var(--dsw-alias-state-business-primary)}",
|
|
516
|
+
".mneme-ov-trenddate{font-size:10px;line-height:12px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;white-space:nowrap}",
|
|
517
|
+
// --- hero fallback: full-viewport memory library when no tab ring exists ---
|
|
518
|
+
// The host hides the whole conversation tab ring while a session is
|
|
519
|
+
// blank (hero screen), so the sidebar entry cannot activate the tab
|
|
520
|
+
// there. This surface reuses the exact MemoryExplorer UI at full size —
|
|
521
|
+
// not a side drawer — so the library stays reachable from any state.
|
|
522
|
+
".mneme-overlay{position:fixed;inset:0;z-index:1000;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1);animation:mneme-fadein .12s ease-out}",
|
|
523
|
+
// issue #41: overlay 顶栏右侧原本与宿主窗口标题栏的控制按钮(最小化/最大化/关闭)
|
|
524
|
+
// 落在同一区域——宿主控制按钮浮在 web 内容最上层,抢占了 overlay"关闭"按钮的
|
|
525
|
+
// 点击热区,导致记忆窗口无法关闭。改为左对齐(标题 + 关闭按钮并排),关闭按钮
|
|
526
|
+
// 离开右上角宿主控制按钮区,任何窗口尺寸/宿主下都可见可点。
|
|
527
|
+
".mneme-overlaybar{flex:none;display:flex;align-items:center;justify-content:flex-start;gap:12px;height:44px;padding:0 12px 0 16px;border-bottom:1px solid var(--dsw-alias-border-l2)}",
|
|
528
|
+
".mneme-overlaytitle{font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary)}",
|
|
529
|
+
".mneme-overlaybody{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}",
|
|
530
|
+
"@keyframes mneme-fadein{from{opacity:0}to{opacity:1}}"
|
|
531
|
+
].join("\n");
|
|
532
|
+
if (typeof document !== "undefined" && document.querySelector(`style[data-plugin-css="${CSS_TAG}"]`) === null) {
|
|
533
|
+
const tag = document.createElement("style");
|
|
534
|
+
tag.dataset.plugin = "@modusensus/dsh-mneme";
|
|
535
|
+
tag.dataset.pluginCss = CSS_TAG;
|
|
536
|
+
tag.textContent = css;
|
|
537
|
+
document.head.appendChild(tag);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const h = react.createElement;
|
|
541
|
+
|
|
542
|
+
// --- graph view constants ---
|
|
543
|
+
// Entity type → node fill. The host has no palette token for categorical
|
|
544
|
+
// data, so these are fixed hues tuned for both light and dark themes
|
|
545
|
+
// (medium saturation, similar luminance).
|
|
546
|
+
const TYPE_COLORS = {
|
|
547
|
+
person: "#3b82f6",
|
|
548
|
+
project: "#22c55e",
|
|
549
|
+
concept: "#a855f7",
|
|
550
|
+
technology: "#f59e0b",
|
|
551
|
+
organization: "#06b6d4"
|
|
552
|
+
};
|
|
553
|
+
function typeColor(type) {
|
|
554
|
+
return TYPE_COLORS[type] || "#94a3b8";
|
|
555
|
+
}
|
|
556
|
+
function nodeRadius(n) {
|
|
557
|
+
// mention_count → area-ish growth, clamped so hubs stay legible.
|
|
558
|
+
const base = 7 + Math.min(20, Math.max(1, n.mention_count ?? 1)) * 0.55;
|
|
559
|
+
// v0.7.0 heat: hot entities render slightly larger; cold → base.
|
|
560
|
+
if (n.heat == null) return base;
|
|
561
|
+
return base + (Math.max(0, Math.min(1, n.heat)) - 0.5) * 4;
|
|
562
|
+
}
|
|
563
|
+
function nodeOpacity(n) {
|
|
564
|
+
// v0.7.0 heat: hot entities are bright (opacity 1), cold fade to 0.4.
|
|
565
|
+
if (n.heat == null) return 1;
|
|
566
|
+
return 0.4 + 0.6 * Math.max(0, Math.min(1, n.heat));
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Deterministic golden-angle spiral: no two nodes start overlapping, and
|
|
570
|
+
// re-running the layout for the same data is stable (no random seeding).
|
|
571
|
+
function initialPositions(nodes, width, height) {
|
|
572
|
+
const cx = width / 2;
|
|
573
|
+
const cy = height / 2;
|
|
574
|
+
return nodes.map((n, i) => {
|
|
575
|
+
const r = i === 0 ? 0 : 34 + 13 * Math.sqrt(i);
|
|
576
|
+
const a = i * 2.39996;
|
|
577
|
+
return { ...n, x: cx + r * Math.cos(a), y: cy + r * Math.sin(a), vx: 0, vy: 0, pinned: false };
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// --- wiki-link (v0.6.1) -------------------------------------------------
|
|
582
|
+
// Splits detail content into literal text and clickable [[target]] /
|
|
583
|
+
// [[display|target]] links. Mirrors src/parser/wiki-link.js: single pipe
|
|
584
|
+
// only, empty / multi-pipe / unclosed markers stay literal text.
|
|
585
|
+
function wikilinkSegments(text, onClick) {
|
|
586
|
+
if (typeof text !== "string" || text.length === 0) return text;
|
|
587
|
+
const out = [];
|
|
588
|
+
let last = 0;
|
|
589
|
+
let key = 0;
|
|
590
|
+
const re = /\[\[([^\[\]]*)\]\]/g;
|
|
591
|
+
let m;
|
|
592
|
+
while ((m = re.exec(text)) !== null) {
|
|
593
|
+
const parts = m[1].split("|");
|
|
594
|
+
if (parts.length > 2) continue; // 多管道 → 非法,保留字面文本
|
|
595
|
+
const target = (parts.length === 2 ? parts[1] : parts[0]).trim();
|
|
596
|
+
if (!target) continue; // 空目标 → 非法
|
|
597
|
+
if (m.index > last) out.push(text.slice(last, m.index));
|
|
598
|
+
out.push(h("button", {
|
|
599
|
+
key: `w${key++}`,
|
|
600
|
+
type: "button",
|
|
601
|
+
className: "mneme-wikilink",
|
|
602
|
+
title: target,
|
|
603
|
+
onClick: () => onClick(target)
|
|
604
|
+
}, parts[0].trim() || target));
|
|
605
|
+
last = m.index + m[0].length;
|
|
606
|
+
}
|
|
607
|
+
if (last < text.length) out.push(text.slice(last));
|
|
608
|
+
return out.length ? out : text;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Backlinks panel: the two wiki-link relation blocks under the detail pane.
|
|
612
|
+
// Backlinks = memories whose content links to this one; forward = memories
|
|
613
|
+
// this one links to (unresolved targets surface as dim, non-clickable).
|
|
614
|
+
// Mounted per-selection (the surrounding Fragment keys on selected.id), so
|
|
615
|
+
// state resets and the fetches re-run on every switch.
|
|
616
|
+
function BacklinksPanel({ memory, t, onJump }) {
|
|
617
|
+
const [back, setBack] = useState(null); // null = loading
|
|
618
|
+
const [forward, setForward] = useState(null);
|
|
619
|
+
|
|
620
|
+
useEffect(() => {
|
|
621
|
+
let cancelled = false;
|
|
622
|
+
if (!memory || !memory.id) return;
|
|
623
|
+
apiFetch(`/api/dsh-mneme/wikilinks/backlinks?id=${encodeURIComponent(memory.id)}`)
|
|
624
|
+
.then((r) => (r.ok ? r.json() : { backlinks: [] }))
|
|
625
|
+
.then((j) => { if (!cancelled) setBack(Array.isArray(j.backlinks) ? j.backlinks : []); })
|
|
626
|
+
.catch(() => { if (!cancelled) setBack([]); });
|
|
627
|
+
apiFetch(`/api/dsh-mneme/wikilinks/forward?id=${encodeURIComponent(memory.id)}`)
|
|
628
|
+
.then((r) => (r.ok ? r.json() : { links: [] }))
|
|
629
|
+
.then((j) => { if (!cancelled) setForward(Array.isArray(j.links) ? j.links : []); })
|
|
630
|
+
.catch(() => { if (!cancelled) setForward([]); });
|
|
631
|
+
return () => { cancelled = true; };
|
|
632
|
+
}, [memory && memory.id]);
|
|
633
|
+
|
|
634
|
+
if (!memory || !memory.id) return null;
|
|
635
|
+
|
|
636
|
+
const loading = back === null || forward === null;
|
|
637
|
+
const row = (link, i) => {
|
|
638
|
+
const canJump = !!link.id;
|
|
639
|
+
return h("button", {
|
|
640
|
+
key: link.id ?? `unresolved-${i}`,
|
|
641
|
+
type: "button",
|
|
642
|
+
className: canJump ? "mneme-bl-link" : "mneme-bl-link mneme-bl-link--dim",
|
|
643
|
+
title: canJump ? t("memory.card.open") : t("memory.wikilink.unresolved"),
|
|
644
|
+
disabled: !canJump,
|
|
645
|
+
onClick: () => onJump && onJump({ id: link.id })
|
|
646
|
+
},
|
|
647
|
+
h("span", { className: "mneme-bl-title" }, link.title || "—"),
|
|
648
|
+
link.type && h("span", { className: "mneme-bl-meta" }, typeLabel(t, link.type))
|
|
649
|
+
);
|
|
650
|
+
};
|
|
651
|
+
const section = (label, items) =>
|
|
652
|
+
h("div", { className: "mneme-bl-block" },
|
|
653
|
+
h("div", { className: "mneme-bl-head" }, label),
|
|
654
|
+
loading
|
|
655
|
+
? h("div", { className: "mneme-bl-empty" }, t("memory.wikilink.loading"))
|
|
656
|
+
: items.length === 0
|
|
657
|
+
? h("div", { className: "mneme-bl-empty" }, t("memory.wikilink.empty"))
|
|
658
|
+
: h("div", { className: "mneme-bl-list" }, items.map(row))
|
|
659
|
+
);
|
|
660
|
+
|
|
661
|
+
return h("div", { className: "mneme-backlinks" },
|
|
662
|
+
section(t("memory.wikilink.backlinks"), back || []),
|
|
663
|
+
section(t("memory.wikilink.forward"), forward || [])
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// --- Graph view: ego-graph of one entity, zero-dependency SVG force layout ---
|
|
668
|
+
// The DSH client module table only whitelists platform modules, so a graph
|
|
669
|
+
// library like vis-network cannot be required from a plugin. A hand-rolled
|
|
670
|
+
// spring simulation (repulsion + edge springs + center gravity, damped) is
|
|
671
|
+
// plenty for the ≤40 nodes the ego API returns.
|
|
672
|
+
function GraphPanel({ t, focusEntity, onJumpMemory }) {
|
|
673
|
+
const [entityName, setEntityName] = useState(focusEntity || "");
|
|
674
|
+
const [inputValue, setInputValue] = useState(focusEntity || "");
|
|
675
|
+
const [depth, setDepth] = useState(1);
|
|
676
|
+
const [data, setData] = useState(null);
|
|
677
|
+
const [status, setStatus] = useState("idle"); // idle | loading | ready | notfound | error
|
|
678
|
+
const [selected, setSelected] = useState(null); // { kind: "node"|"edge", node?|edge? }
|
|
679
|
+
const [attrs, setAttrs] = useState([]);
|
|
680
|
+
const [related, setRelated] = useState([]);
|
|
681
|
+
const svgRef = useRef(null);
|
|
682
|
+
const posRef = useRef([]); // live simulation positions, not React state
|
|
683
|
+
const dragRef = useRef(null); // { id, moved }
|
|
684
|
+
const [frame, setFrame] = useState(0); // re-render tick driven by the simulation
|
|
685
|
+
|
|
686
|
+
useEffect(() => {
|
|
687
|
+
if (focusEntity && focusEntity !== entityName) {
|
|
688
|
+
setEntityName(focusEntity);
|
|
689
|
+
setInputValue(focusEntity);
|
|
690
|
+
}
|
|
691
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
692
|
+
}, [focusEntity]);
|
|
693
|
+
|
|
694
|
+
const load = useCallback(async (name, d) => {
|
|
695
|
+
if (!name) { setData(null); setStatus("idle"); return; }
|
|
696
|
+
setStatus("loading");
|
|
697
|
+
setSelected(null);
|
|
698
|
+
try {
|
|
699
|
+
const res = await apiFetch(`/api/dsh-mneme/semantic/graph/ego?entity=${encodeURIComponent(name)}&depth=${d}`);
|
|
700
|
+
if (res.status === 404) { setData(null); setStatus("notfound"); return; }
|
|
701
|
+
if (!res.ok) { setData(null); setStatus("error"); return; }
|
|
702
|
+
const json = await res.json();
|
|
703
|
+
setData(json);
|
|
704
|
+
setStatus("ready");
|
|
705
|
+
} catch {
|
|
706
|
+
setData(null);
|
|
707
|
+
setStatus("error");
|
|
708
|
+
}
|
|
709
|
+
}, []);
|
|
710
|
+
|
|
711
|
+
useEffect(() => { load(entityName, depth); }, [load, entityName, depth]);
|
|
712
|
+
|
|
713
|
+
// Detail pane: node → current attrs + entity: search for related memories.
|
|
714
|
+
useEffect(() => {
|
|
715
|
+
setAttrs([]);
|
|
716
|
+
setRelated([]);
|
|
717
|
+
if (!selected || selected.kind !== "node") return;
|
|
718
|
+
const name = selected.node.name;
|
|
719
|
+
let cancelled = false;
|
|
720
|
+
apiFetch(`/api/dsh-mneme/semantic/graph/entity-attrs?entity=${encodeURIComponent(name)}`)
|
|
721
|
+
.then((r) => (r.ok ? r.json() : { attrs: [] }))
|
|
722
|
+
.then((j) => { if (!cancelled) setAttrs(Array.isArray(j.attrs) ? j.attrs : []); })
|
|
723
|
+
.catch(() => {});
|
|
724
|
+
apiFetch(`/api/dsh-mneme/search?q=${encodeURIComponent("entity:" + name)}&limit=10`)
|
|
725
|
+
.then((r) => (r.ok ? r.json() : { items: [] }))
|
|
726
|
+
.then((j) => { if (!cancelled) setRelated(Array.isArray(j.items) ? j.items : []); })
|
|
727
|
+
.catch(() => {});
|
|
728
|
+
return () => { cancelled = true; };
|
|
729
|
+
}, [selected]);
|
|
730
|
+
|
|
731
|
+
// Simulation: run in rAF against posRef, tick React only every few frames.
|
|
732
|
+
// Re-seeds when data changes; dragging writes straight into posRef.
|
|
733
|
+
useEffect(() => {
|
|
734
|
+
if (!data || data.nodes.length === 0) return;
|
|
735
|
+
const width = Math.max(280, svgRef.current?.clientWidth || 380);
|
|
736
|
+
const height = 300;
|
|
737
|
+
posRef.current = initialPositions(data.nodes, width, height);
|
|
738
|
+
const byId = new Map(posRef.current.map((n) => [n.id, n]));
|
|
739
|
+
const edges = data.edges;
|
|
740
|
+
let raf = 0;
|
|
741
|
+
let n = 0;
|
|
742
|
+
const tick = () => {
|
|
743
|
+
const nodes = posRef.current;
|
|
744
|
+
// pairwise repulsion, capped so far nodes don't explode
|
|
745
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
746
|
+
for (let j = i + 1; j < nodes.length; j++) {
|
|
747
|
+
const a = nodes[i], b = nodes[j];
|
|
748
|
+
let dx = b.x - a.x, dy = b.y - a.y;
|
|
749
|
+
let d2 = dx * dx + dy * dy;
|
|
750
|
+
if (d2 < 1) { dx = (Math.random() - 0.5) || 1; dy = (Math.random() - 0.5) || 1; d2 = dx * dx + dy * dy; }
|
|
751
|
+
const d = Math.sqrt(d2);
|
|
752
|
+
const f = Math.min(2200 / d2, 6);
|
|
753
|
+
const fx = (dx / d) * f, fy = (dy / d) * f;
|
|
754
|
+
a.vx -= fx; a.vy -= fy; b.vx += fx; b.vy += fy;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
// edge springs pull toward the target length
|
|
758
|
+
for (const e of edges) {
|
|
759
|
+
const a = byId.get(e.from), b = byId.get(e.to);
|
|
760
|
+
if (!a || !b) continue;
|
|
761
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
762
|
+
const d = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
763
|
+
const f = (d - 90) * 0.02;
|
|
764
|
+
const fx = (dx / d) * f, fy = (dy / d) * f;
|
|
765
|
+
a.vx += fx; a.vy += fy; b.vx -= fx; b.vy -= fy;
|
|
766
|
+
}
|
|
767
|
+
let energy = 0;
|
|
768
|
+
for (const node of nodes) {
|
|
769
|
+
// gentle gravity toward center keeps the cloud from drifting off-canvas
|
|
770
|
+
node.vx += (width / 2 - node.x) * 0.002;
|
|
771
|
+
node.vy += (height / 2 - node.y) * 0.002;
|
|
772
|
+
if (node.pinned || node === dragRef.current?.node) { node.vx = 0; node.vy = 0; continue; }
|
|
773
|
+
node.vx *= 0.85; node.vy *= 0.85;
|
|
774
|
+
node.x = Math.max(nodeRadius(node) + 4, Math.min(width - nodeRadius(node) - 4, node.x + node.vx));
|
|
775
|
+
node.y = Math.max(nodeRadius(node) + 14, Math.min(height - nodeRadius(node) - 14, node.y + node.vy));
|
|
776
|
+
energy += Math.abs(node.vx) + Math.abs(node.vy);
|
|
777
|
+
}
|
|
778
|
+
n++;
|
|
779
|
+
if (n % 3 === 0) setFrame((f) => f + 1);
|
|
780
|
+
if (n < 300 && energy > 0.4) raf = requestAnimationFrame(tick);
|
|
781
|
+
};
|
|
782
|
+
raf = requestAnimationFrame(tick);
|
|
783
|
+
return () => cancelAnimationFrame(raf);
|
|
784
|
+
}, [data]);
|
|
785
|
+
|
|
786
|
+
// drag handling on the svg surface
|
|
787
|
+
const onNodeMouseDown = (e, node) => {
|
|
788
|
+
e.preventDefault();
|
|
789
|
+
dragRef.current = { node, moved: false };
|
|
790
|
+
const startX = e.clientX, startY = e.clientY;
|
|
791
|
+
const origX = node.x, origY = node.y;
|
|
792
|
+
const svg = svgRef.current;
|
|
793
|
+
const rect = svg.getBoundingClientRect();
|
|
794
|
+
const scale = 380 / Math.max(1, rect.width); // viewBox width / css width
|
|
795
|
+
const onMove = (ev) => {
|
|
796
|
+
dragRef.current.moved = true;
|
|
797
|
+
node.x = origX + (ev.clientX - startX) * scale;
|
|
798
|
+
node.y = origY + (ev.clientY - startY) * scale;
|
|
799
|
+
setFrame((f) => f + 1);
|
|
800
|
+
};
|
|
801
|
+
const onUp = () => {
|
|
802
|
+
window.removeEventListener("mousemove", onMove);
|
|
803
|
+
window.removeEventListener("mouseup", onUp);
|
|
804
|
+
setTimeout(() => { dragRef.current = null; }, 0);
|
|
805
|
+
};
|
|
806
|
+
window.addEventListener("mousemove", onMove);
|
|
807
|
+
window.addEventListener("mouseup", onUp);
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
const onNodeClick = (node) => {
|
|
811
|
+
if (dragRef.current?.moved) return; // it was a drag, not a click
|
|
812
|
+
setSelected({ kind: "node", node });
|
|
813
|
+
};
|
|
814
|
+
const onEdgeClick = (edge) => setSelected({ kind: "edge", edge });
|
|
815
|
+
|
|
816
|
+
const nodes = posRef.current;
|
|
817
|
+
const nodeById = new Map(nodes.map((n) => [n.id, n]));
|
|
818
|
+
const VIEW_W = 380, VIEW_H = 300;
|
|
819
|
+
|
|
820
|
+
const side = selected?.kind === "node"
|
|
821
|
+
? h("div", { className: "mneme-graphside" },
|
|
822
|
+
h("div", { className: "mneme-gs-title" },
|
|
823
|
+
h("span", null, selected.node.name),
|
|
824
|
+
h("span", { className: "mneme-gs-meta" },
|
|
825
|
+
`${typeLabel(t, selected.node.type || "concept")} · ★${selected.node.mention_count ?? 1}`)
|
|
826
|
+
),
|
|
827
|
+
attrs.length > 0 && h("div", null,
|
|
828
|
+
h("div", { className: "mneme-gs-meta" }, t("memory.graph.attrs")),
|
|
829
|
+
attrs.map((a, i) => h("div", { key: i, className: "mneme-gs-attr" },
|
|
830
|
+
h("span", { className: "mneme-gs-attrkey" }, `${a.key}:`),
|
|
831
|
+
h("span", { className: "mneme-gs-attrval" }, a.value)
|
|
832
|
+
))
|
|
833
|
+
),
|
|
834
|
+
related.length > 0 && h("div", { style: { marginTop: 8 } },
|
|
835
|
+
h("div", { className: "mneme-gs-meta" }, t("memory.graph.related")),
|
|
836
|
+
related.map((m) => h("button", {
|
|
837
|
+
key: m.id,
|
|
838
|
+
type: "button",
|
|
839
|
+
className: "mneme-gs-link",
|
|
840
|
+
title: t("memory.card.open"),
|
|
841
|
+
onClick: () => onJumpMemory && onJumpMemory(m)
|
|
842
|
+
}, m.title || m.content?.slice(0, 60)))
|
|
843
|
+
)
|
|
844
|
+
)
|
|
845
|
+
: selected?.kind === "edge"
|
|
846
|
+
? h("div", { className: "mneme-graphside" },
|
|
847
|
+
h("div", { className: "mneme-gs-title" },
|
|
848
|
+
h("span", null,
|
|
849
|
+
`${nodeById.get(selected.edge.from)?.name ?? "?"} → ${selected.edge.relation_type} → ${nodeById.get(selected.edge.to)?.name ?? "?"}`)
|
|
850
|
+
),
|
|
851
|
+
h("div", { className: "mneme-gs-meta" },
|
|
852
|
+
`${t("memory.graph.relation")} · ${formatRelativeTime(selected.edge.created_at, t)}`),
|
|
853
|
+
selected.edge.memory_id && h("button", {
|
|
854
|
+
className: "mneme-footbtn",
|
|
855
|
+
onClick: () => onJumpMemory && onJumpMemory({ id: selected.edge.memory_id })
|
|
856
|
+
}, t("memory.graph.sourceMemory"))
|
|
857
|
+
)
|
|
858
|
+
: null;
|
|
859
|
+
|
|
860
|
+
return h("div", { className: "mneme-graph" },
|
|
861
|
+
h("div", { className: "mneme-graphbar" },
|
|
862
|
+
h("input", {
|
|
863
|
+
className: "mneme-search",
|
|
864
|
+
style: { flex: 1, minWidth: 0, maxWidth: 280 },
|
|
865
|
+
placeholder: t("memory.graph.placeholder"),
|
|
866
|
+
value: inputValue,
|
|
867
|
+
onChange: (e) => setInputValue(e.target.value),
|
|
868
|
+
onKeyDown: (e) => { if (e.key === "Enter") setEntityName(inputValue.trim()); }
|
|
869
|
+
}),
|
|
870
|
+
h("button", {
|
|
871
|
+
className: depth === 2 ? "mneme-chip mneme-active" : "mneme-chip",
|
|
872
|
+
title: t("memory.graph.depth"),
|
|
873
|
+
onClick: () => setDepth(depth === 1 ? 2 : 1)
|
|
874
|
+
}, `${depth} ${t("memory.graph.depth")}`)
|
|
875
|
+
),
|
|
876
|
+
status === "idle" && h("div", { className: "mneme-hint" }, t("memory.graph.empty")),
|
|
877
|
+
status === "loading" && h("div", { className: "mneme-hint" }, t("memory.graph.loading")),
|
|
878
|
+
status === "notfound" && h("div", { className: "mneme-hint" }, t("memory.graph.notFound")),
|
|
879
|
+
status === "error" && h("div", { className: "mneme-hint" }, t("memory.panel.empty")),
|
|
880
|
+
status === "ready" && (data.nodes.length <= 1
|
|
881
|
+
? h("div", { className: "mneme-hint" }, t("memory.graph.empty"))
|
|
882
|
+
: h(react.Fragment, null,
|
|
883
|
+
h("svg", {
|
|
884
|
+
ref: svgRef,
|
|
885
|
+
className: "mneme-graphsvg",
|
|
886
|
+
viewBox: `0 0 ${VIEW_W} ${VIEW_H}`
|
|
887
|
+
},
|
|
888
|
+
data.edges.map((e) => {
|
|
889
|
+
const a = nodeById.get(e.from), b = nodeById.get(e.to);
|
|
890
|
+
if (!a || !b) return null;
|
|
891
|
+
return h("line", {
|
|
892
|
+
key: e.id,
|
|
893
|
+
x1: a.x, y1: a.y, x2: b.x, y2: b.y,
|
|
894
|
+
className: e.memory_id ? "mneme-gedge" : "mneme-gedge mneme-gedge-dashed",
|
|
895
|
+
onClick: () => onEdgeClick(e)
|
|
896
|
+
});
|
|
897
|
+
}),
|
|
898
|
+
nodes.map((n) => h("g", {
|
|
899
|
+
key: n.id,
|
|
900
|
+
className: n.id === data.root.id ? "mneme-gnode mneme-groot" : "mneme-gnode",
|
|
901
|
+
transform: `translate(${n.x},${n.y})`,
|
|
902
|
+
onMouseDown: (e) => onNodeMouseDown(e, n),
|
|
903
|
+
onClick: () => onNodeClick(n),
|
|
904
|
+
"data-node": n.name
|
|
905
|
+
},
|
|
906
|
+
h("circle", { r: nodeRadius(n), fill: typeColor(n.type), fillOpacity: nodeOpacity(n) }),
|
|
907
|
+
h("text", { className: "mneme-glabel", y: nodeRadius(n) + 13 }, n.name)
|
|
908
|
+
))
|
|
909
|
+
),
|
|
910
|
+
h("div", { className: "mneme-graphhint" }, t("memory.graph.hint"))
|
|
911
|
+
)),
|
|
912
|
+
side
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// --- Settings view: user profile, rules, custom commands, vector, token ---
|
|
917
|
+
const styles = {
|
|
918
|
+
footerButton: { padding: "4px 10px", borderRadius: 8, border: "1px solid var(--dsw-alias-border-l2, #ddd)", background: "none", cursor: "pointer", fontSize: 12, margin: "2px 8px", color: "var(--dsw-alias-label-secondary, #666)", fontFamily: "inherit" }
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
function SettingsContent({ t }) {
|
|
922
|
+
const [profile, setProfile] = react.useState("");
|
|
923
|
+
const [rules, setRules] = react.useState([]);
|
|
924
|
+
const [commands, setCommands] = react.useState([]);
|
|
925
|
+
const [newRule, setNewRule] = react.useState("");
|
|
926
|
+
const [newCmd, setNewCmd] = react.useState({ name: "", description: "", instruction: "" });
|
|
927
|
+
const [saved, setSaved] = react.useState(false);
|
|
928
|
+
const [cmdError, setCmdError] = react.useState("");
|
|
929
|
+
const [vector, setVector] = react.useState({ enabled: false, baseUrl: "", apiKey: "", model: "" });
|
|
930
|
+
const [vectorSaved, setVectorSaved] = react.useState(false);
|
|
931
|
+
const [reindexing, setReindexing] = react.useState(false);
|
|
932
|
+
const [reindexMsg, setReindexMsg] = react.useState("");
|
|
933
|
+
const [apiToken, setApiToken] = react.useState(() =>
|
|
934
|
+
(typeof window !== "undefined" && window.localStorage) ? window.localStorage.getItem("dsh-mneme-api-token") || "" : ""
|
|
935
|
+
);
|
|
936
|
+
const [apiTokenSaved, setApiTokenSaved] = react.useState(false);
|
|
937
|
+
const [autoTag, setAutoTag] = react.useState(false);
|
|
938
|
+
const [autoTagSaved, setAutoTagSaved] = react.useState(false);
|
|
939
|
+
const [showSidebarTrigger, setShowSidebarTrigger] = react.useState(true);
|
|
940
|
+
const [sidebarTriggerSaved, setSidebarTriggerSaved] = react.useState(false);
|
|
941
|
+
|
|
942
|
+
const load = react.useCallback(async () => {
|
|
943
|
+
try {
|
|
944
|
+
const [p, r, c, v] = await Promise.all([
|
|
945
|
+
apiFetch("/api/dsh-mneme/profile").then((res) => res.json()),
|
|
946
|
+
apiFetch("/api/dsh-mneme/rules").then((res) => res.json()),
|
|
947
|
+
apiFetch("/api/dsh-mneme/commands").then((res) => res.json()),
|
|
948
|
+
apiFetch("/api/dsh-mneme/vector-config").then((res) => res.json())
|
|
949
|
+
]);
|
|
950
|
+
setProfile(p.profile || "");
|
|
951
|
+
setRules(Array.isArray(r.rules) ? r.rules : []);
|
|
952
|
+
setCommands(Array.isArray(c.commands) ? c.commands : []);
|
|
953
|
+
setVector(v.config || { enabled: false, baseUrl: "", apiKey: "", model: "" });
|
|
954
|
+
// autoTag loads independently so a config failure can't cascade-block the rest.
|
|
955
|
+
try {
|
|
956
|
+
const g = await apiFetch("/api/dsh-mneme/config").then((res) => res.json());
|
|
957
|
+
setAutoTag(g.config?.autoTagEnabled === true);
|
|
958
|
+
// issue #38: sidebar trigger defaults to visible (true).
|
|
959
|
+
setShowSidebarTrigger(g.config?.showSidebarTrigger !== false);
|
|
960
|
+
} catch { /* keep defaults */ }
|
|
961
|
+
} catch { /* ignore */ }
|
|
962
|
+
}, []);
|
|
963
|
+
|
|
964
|
+
react.useEffect(() => { load(); }, [load]);
|
|
965
|
+
|
|
966
|
+
async function saveProfile() {
|
|
967
|
+
try {
|
|
968
|
+
await apiFetch("/api/dsh-mneme/profile", {
|
|
969
|
+
method: "PUT",
|
|
970
|
+
headers: { "Content-Type": "application/json" },
|
|
971
|
+
body: JSON.stringify({ profile })
|
|
972
|
+
});
|
|
973
|
+
setSaved(true);
|
|
974
|
+
setTimeout(() => setSaved(false), 1500);
|
|
975
|
+
} catch { /* ignore */ }
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
async function putRules(next) {
|
|
979
|
+
await apiFetch("/api/dsh-mneme/rules", {
|
|
980
|
+
method: "PUT",
|
|
981
|
+
headers: { "Content-Type": "application/json" },
|
|
982
|
+
body: JSON.stringify({ rules: next })
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
async function addRule() {
|
|
987
|
+
const text = newRule.trim();
|
|
988
|
+
if (!text) return;
|
|
989
|
+
const next = [...rules, text];
|
|
990
|
+
await putRules(next);
|
|
991
|
+
setRules(next);
|
|
992
|
+
setNewRule("");
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
async function removeRule(index) {
|
|
996
|
+
const next = rules.filter((_, i) => i !== index);
|
|
997
|
+
await putRules(next);
|
|
998
|
+
setRules(next);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
async function addCommand() {
|
|
1002
|
+
const name = newCmd.name.trim();
|
|
1003
|
+
const instruction = newCmd.instruction.trim();
|
|
1004
|
+
if (!name || !instruction) return;
|
|
1005
|
+
try {
|
|
1006
|
+
const res = await apiFetch("/api/dsh-mneme/commands", {
|
|
1007
|
+
method: "POST",
|
|
1008
|
+
headers: { "Content-Type": "application/json" },
|
|
1009
|
+
body: JSON.stringify({ name, description: newCmd.description, instruction })
|
|
1010
|
+
});
|
|
1011
|
+
const data = await res.json();
|
|
1012
|
+
if (!res.ok) { setCmdError(data.error || "failed"); return; }
|
|
1013
|
+
setCmdError("");
|
|
1014
|
+
setCommands([...commands, data.command]);
|
|
1015
|
+
setNewCmd({ name: "", description: "", instruction: "" });
|
|
1016
|
+
} catch { setCmdError("failed"); }
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
async function removeCommand(id) {
|
|
1020
|
+
await apiFetch(`/api/dsh-mneme/commands?id=${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
1021
|
+
setCommands(commands.filter((c) => c.id !== id));
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
async function saveVector() {
|
|
1025
|
+
try {
|
|
1026
|
+
await apiFetch("/api/dsh-mneme/vector-config", {
|
|
1027
|
+
method: "PUT",
|
|
1028
|
+
headers: { "Content-Type": "application/json" },
|
|
1029
|
+
body: JSON.stringify(vector)
|
|
1030
|
+
});
|
|
1031
|
+
setVectorSaved(true);
|
|
1032
|
+
setTimeout(() => setVectorSaved(false), 1500);
|
|
1033
|
+
} catch { /* ignore */ }
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
async function reindex() {
|
|
1037
|
+
setReindexing(true);
|
|
1038
|
+
setReindexMsg("");
|
|
1039
|
+
try {
|
|
1040
|
+
const res = await apiFetch("/api/dsh-mneme/vector-reindex");
|
|
1041
|
+
const data = await res.json();
|
|
1042
|
+
const n = data.indexed ?? 0;
|
|
1043
|
+
setReindexMsg(t("memory.settings.vectorReindexDone").replace("{n}", String(n)));
|
|
1044
|
+
} catch { setReindexMsg(""); }
|
|
1045
|
+
setReindexing(false);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
function saveToken() {
|
|
1049
|
+
try {
|
|
1050
|
+
if (apiToken.trim()) window.localStorage.setItem("dsh-mneme-api-token", apiToken.trim());
|
|
1051
|
+
else window.localStorage.removeItem("dsh-mneme-api-token");
|
|
1052
|
+
setApiTokenSaved(true);
|
|
1053
|
+
setTimeout(() => setApiTokenSaved(false), 1500);
|
|
1054
|
+
} catch { /* ignore */ }
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
async function saveAutoTag() {
|
|
1058
|
+
try {
|
|
1059
|
+
await apiFetch("/api/dsh-mneme/config", {
|
|
1060
|
+
method: "PUT",
|
|
1061
|
+
headers: { "Content-Type": "application/json" },
|
|
1062
|
+
body: JSON.stringify({ autoTagEnabled: autoTag })
|
|
1063
|
+
});
|
|
1064
|
+
setAutoTagSaved(true);
|
|
1065
|
+
setTimeout(() => setAutoTagSaved(false), 1500);
|
|
1066
|
+
} catch { /* ignore */ }
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
async function saveSidebarTrigger() {
|
|
1070
|
+
try {
|
|
1071
|
+
await apiFetch("/api/dsh-mneme/config", {
|
|
1072
|
+
method: "PUT",
|
|
1073
|
+
headers: { "Content-Type": "application/json" },
|
|
1074
|
+
body: JSON.stringify({ showSidebarTrigger })
|
|
1075
|
+
});
|
|
1076
|
+
setSidebarTriggerSaved(true);
|
|
1077
|
+
setTimeout(() => setSidebarTriggerSaved(false), 1500);
|
|
1078
|
+
} catch { /* ignore */ }
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const inputStyle = { boxSizing: "border-box", width: "100%", height: 34, padding: "0 12px", borderRadius: 10, border: "1px solid var(--dsw-alias-border-l2, #ddd)", background: "var(--dsw-alias-bg-base, transparent)", color: "var(--dsw-alias-label-primary)", fontFamily: "inherit", fontSize: 13, outline: "none", marginBottom: 8 };
|
|
1082
|
+
const labelStyle = { fontSize: 12, fontWeight: 600, margin: "12px 0 4px", color: "var(--dsw-alias-label-primary)" };
|
|
1083
|
+
const hintStyle = { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #999)", marginBottom: 8 };
|
|
1084
|
+
const rowStyle = { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8, padding: "6px 0", borderBottom: "1px solid var(--dsw-alias-border-l1, #eee)" };
|
|
1085
|
+
|
|
1086
|
+
return h("div", { style: { paddingBottom: 8 } },
|
|
1087
|
+
// api token (optional)
|
|
1088
|
+
h("div", { style: { ...labelStyle, marginTop: 20 } }, t("memory.settings.apiTokenTitle")),
|
|
1089
|
+
h("div", { style: hintStyle }, t("memory.settings.apiTokenHint")),
|
|
1090
|
+
h("div", { style: { display: "flex", gap: 6 } },
|
|
1091
|
+
h("input", { style: { ...inputStyle, flex: 1, marginBottom: 0 }, type: "password", value: apiToken, placeholder: t("memory.settings.apiTokenPlaceholder"), onChange: (e) => setApiToken(e.target.value) }),
|
|
1092
|
+
h("button", { style: styles.footerButton, onClick: saveToken }, t("memory.settings.apiTokenSave"))
|
|
1093
|
+
),
|
|
1094
|
+
apiTokenSaved && h("div", { style: { fontSize: 12, color: "var(--dsw-alias-state-success, #2a7)" } }, t("memory.settings.apiTokenSaved")),
|
|
1095
|
+
// profile
|
|
1096
|
+
h("div", { style: labelStyle }, t("memory.settings.profile")),
|
|
1097
|
+
h("div", { style: hintStyle }, t("memory.settings.profileHint")),
|
|
1098
|
+
h("textarea", {
|
|
1099
|
+
style: { ...inputStyle, minHeight: 72, resize: "vertical", fontFamily: "inherit", padding: "8px 12px", height: "auto" },
|
|
1100
|
+
value: profile,
|
|
1101
|
+
placeholder: t("memory.settings.profile"),
|
|
1102
|
+
onChange: (e) => setProfile(e.target.value)
|
|
1103
|
+
}),
|
|
1104
|
+
h("div", null,
|
|
1105
|
+
h("button", { style: styles.footerButton, onClick: saveProfile }, t("memory.settings.profileSave")),
|
|
1106
|
+
saved && h("span", { style: { fontSize: 12, color: "var(--dsw-alias-state-success, #2a7)" } }, t("memory.settings.profileSaved"))
|
|
1107
|
+
),
|
|
1108
|
+
// rules
|
|
1109
|
+
h("div", { style: labelStyle }, t("memory.settings.rules")),
|
|
1110
|
+
h("div", { style: hintStyle }, t("memory.settings.rulesHint")),
|
|
1111
|
+
rules.length === 0 && h("div", { style: { fontSize: 12, color: "var(--dsw-alias-label-tertiary, #999)", padding: "8px 0" } }, t("memory.settings.empty")),
|
|
1112
|
+
rules.map((rule, i) =>
|
|
1113
|
+
h("div", { key: i, style: rowStyle },
|
|
1114
|
+
h("span", { style: { fontSize: 13, flex: 1 } }, rule),
|
|
1115
|
+
h("button", { style: { ...styles.footerButton, color: "var(--dsw-alias-state-error, #c33)" }, onClick: () => removeRule(i) }, "×")
|
|
1116
|
+
)
|
|
1117
|
+
),
|
|
1118
|
+
h("div", { style: { display: "flex", gap: 6 } },
|
|
1119
|
+
h("input", {
|
|
1120
|
+
style: { ...inputStyle, flex: 1, marginBottom: 0 },
|
|
1121
|
+
value: newRule,
|
|
1122
|
+
placeholder: t("memory.settings.rulePlaceholder"),
|
|
1123
|
+
onChange: (e) => setNewRule(e.target.value)
|
|
1124
|
+
}),
|
|
1125
|
+
h("button", { style: styles.footerButton, onClick: addRule }, t("memory.settings.ruleAdd"))
|
|
1126
|
+
),
|
|
1127
|
+
// custom commands
|
|
1128
|
+
h("div", { style: labelStyle }, t("memory.settings.commands")),
|
|
1129
|
+
h("div", { style: hintStyle }, t("memory.settings.commandsHint")),
|
|
1130
|
+
commands.length === 0 && h("div", { style: { fontSize: 12, color: "var(--dsw-alias-label-tertiary, #999)", padding: "8px 0" } }, t("memory.settings.empty")),
|
|
1131
|
+
commands.map((cmd) =>
|
|
1132
|
+
h("div", { key: cmd.id, style: rowStyle },
|
|
1133
|
+
h("div", { style: { flex: 1 } },
|
|
1134
|
+
h("div", { style: { fontSize: 13, fontWeight: 600 } }, `/${cmd.name}`),
|
|
1135
|
+
h("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #999)" } }, cmd.description || cmd.instruction)
|
|
1136
|
+
),
|
|
1137
|
+
h("button", { style: { ...styles.footerButton, color: "var(--dsw-alias-state-error, #c33)" }, onClick: () => removeCommand(cmd.id) }, t("memory.settings.cmdDelete"))
|
|
1138
|
+
)
|
|
1139
|
+
),
|
|
1140
|
+
h("div", { style: { display: "grid", gap: 6, marginTop: 6 } },
|
|
1141
|
+
h("input", { style: { ...inputStyle, marginBottom: 0 }, value: newCmd.name, placeholder: t("memory.settings.cmdName"), onChange: (e) => setNewCmd({ ...newCmd, name: e.target.value }) }),
|
|
1142
|
+
h("input", { style: { ...inputStyle, marginBottom: 0 }, value: newCmd.description, placeholder: t("memory.settings.cmdDesc"), onChange: (e) => setNewCmd({ ...newCmd, description: e.target.value }) }),
|
|
1143
|
+
h("textarea", { style: { ...inputStyle, marginBottom: 0, minHeight: 48, resize: "vertical", fontFamily: "inherit", padding: "8px 12px", height: "auto" }, value: newCmd.instruction, placeholder: t("memory.settings.cmdInstruction"), onChange: (e) => setNewCmd({ ...newCmd, instruction: e.target.value }) }),
|
|
1144
|
+
h("button", { style: styles.footerButton, onClick: addCommand }, t("memory.settings.cmdAdd")),
|
|
1145
|
+
cmdError && h("div", { style: { fontSize: 12, color: "var(--dsw-alias-state-error, #c33)" } }, cmdError)
|
|
1146
|
+
),
|
|
1147
|
+
// auto-tag switch
|
|
1148
|
+
h("div", { style: { ...labelStyle, marginTop: 20 } }, t("memory.settings.autoTagTitle")),
|
|
1149
|
+
h("div", { style: hintStyle }, t("memory.settings.autoTagHint")),
|
|
1150
|
+
h("label", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 8, fontSize: 13 } },
|
|
1151
|
+
h("input", { type: "checkbox", checked: autoTag, onChange: (e) => setAutoTag(e.target.checked) }),
|
|
1152
|
+
h("span", null, t("memory.settings.autoTagEnabled"))
|
|
1153
|
+
),
|
|
1154
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 6 } },
|
|
1155
|
+
h("button", { style: styles.footerButton, onClick: saveAutoTag }, t("memory.settings.autoTagSave")),
|
|
1156
|
+
autoTagSaved && h("span", { style: { fontSize: 12, color: "var(--dsw-alias-state-success, #2a7)" } }, t("memory.settings.autoTagSaved"))
|
|
1157
|
+
),
|
|
1158
|
+
// sidebar trigger switch (issue #38)
|
|
1159
|
+
h("div", { style: { ...labelStyle, marginTop: 20 } }, t("memory.settings.sidebarTriggerTitle")),
|
|
1160
|
+
h("div", { style: hintStyle }, t("memory.settings.sidebarTriggerHint")),
|
|
1161
|
+
h("label", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 8, fontSize: 13 } },
|
|
1162
|
+
h("input", { type: "checkbox", checked: showSidebarTrigger, onChange: (e) => setShowSidebarTrigger(e.target.checked) }),
|
|
1163
|
+
h("span", null, t("memory.settings.sidebarTriggerEnabled"))
|
|
1164
|
+
),
|
|
1165
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 6 } },
|
|
1166
|
+
h("button", { style: styles.footerButton, onClick: saveSidebarTrigger }, t("memory.settings.sidebarTriggerSave")),
|
|
1167
|
+
sidebarTriggerSaved && h("span", { style: { fontSize: 12, color: "var(--dsw-alias-state-success, #2a7)" } }, t("memory.settings.sidebarTriggerSaved"))
|
|
1168
|
+
),
|
|
1169
|
+
// vector search
|
|
1170
|
+
h("div", { style: { ...labelStyle, marginTop: 20 } }, t("memory.settings.vectorTitle")),
|
|
1171
|
+
h("div", { style: hintStyle }, t("memory.settings.vectorHint")),
|
|
1172
|
+
h("label", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 8, fontSize: 13 } },
|
|
1173
|
+
h("input", { type: "checkbox", checked: !!vector.enabled, onChange: (e) => setVector({ ...vector, enabled: e.target.checked }) }),
|
|
1174
|
+
h("span", null, t("memory.settings.vectorEnabled"))
|
|
1175
|
+
),
|
|
1176
|
+
h("input", { style: inputStyle, value: vector.baseUrl, placeholder: t("memory.settings.vectorBaseUrl"), onChange: (e) => setVector({ ...vector, baseUrl: e.target.value }) }),
|
|
1177
|
+
h("input", { style: inputStyle, type: "password", value: vector.apiKey, placeholder: t("memory.settings.vectorApiKey"), onChange: (e) => setVector({ ...vector, apiKey: e.target.value }) }),
|
|
1178
|
+
h("input", { style: inputStyle, value: vector.model, placeholder: t("memory.settings.vectorModel"), onChange: (e) => setVector({ ...vector, model: e.target.value }) }),
|
|
1179
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 6, flexWrap: "wrap" } },
|
|
1180
|
+
h("button", { style: styles.footerButton, onClick: saveVector }, t("memory.settings.vectorSave")),
|
|
1181
|
+
vectorSaved && h("span", { style: { fontSize: 12, color: "var(--dsw-alias-state-success, #2a7)" } }, t("memory.settings.vectorSaved")),
|
|
1182
|
+
h("button", { style: styles.footerButton, onClick: reindex, disabled: reindexing }, reindexing ? t("memory.settings.vectorReindexing") : t("memory.settings.vectorReindex")),
|
|
1183
|
+
reindexMsg && h("span", { style: { fontSize: 12, color: "var(--dsw-alias-label-secondary, #666)" } }, reindexMsg)
|
|
1184
|
+
)
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// --- Main-area memory library: the single home for every memory feature ---
|
|
1189
|
+
// Registered under conversation.view beside Chat / Trajectory. The old
|
|
1190
|
+
// right-hand drawer is gone: the sidebar foot entry activates this tab
|
|
1191
|
+
// directly. The framework keeps the active-view setter private to the
|
|
1192
|
+
// conversation package, and the DOM tab click is the one stable
|
|
1193
|
+
// activation path available to plugins.
|
|
1194
|
+
//
|
|
1195
|
+
// One host constraint remains: the conversation header (and with it the
|
|
1196
|
+
// whole tab ring) is hidden while a session is blank — the new-chat hero
|
|
1197
|
+
// screen. There the tab simply does not exist, so activateExplorerTab
|
|
1198
|
+
// resolves false and the sidebar entry falls back to the full-viewport
|
|
1199
|
+
// overlay surface below.
|
|
1200
|
+
function findExplorerTab(label) {
|
|
1201
|
+
const tabs = document.querySelectorAll('[role="tab"]');
|
|
1202
|
+
for (const tab of tabs) {
|
|
1203
|
+
if ((tab.textContent || "").trim() === label) return tab;
|
|
1204
|
+
}
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// Click the memory library tab and wait (bounded, rAF-polled) until the
|
|
1209
|
+
// host actually marks it selected — a silent React re-render gap must not
|
|
1210
|
+
// be mistaken for success, or the fallback would never kick in.
|
|
1211
|
+
function activateExplorerTab(label) {
|
|
1212
|
+
return new Promise((resolve) => {
|
|
1213
|
+
const tab = findExplorerTab(label);
|
|
1214
|
+
if (!tab) { resolve(false); return; }
|
|
1215
|
+
tab.click();
|
|
1216
|
+
const deadline = Date.now() + 400;
|
|
1217
|
+
(function check() {
|
|
1218
|
+
if (tab.getAttribute("aria-selected") === "true") { resolve(true); return; }
|
|
1219
|
+
if (Date.now() >= deadline) { resolve(false); return; }
|
|
1220
|
+
requestAnimationFrame(check);
|
|
1221
|
+
})();
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// --- Hero fallback overlay state (module-level pub/sub) ---
|
|
1226
|
+
const overlayListeners = new Set();
|
|
1227
|
+
let overlayOpenState = false;
|
|
1228
|
+
function setOverlayOpen(v) {
|
|
1229
|
+
if (v === overlayOpenState) return;
|
|
1230
|
+
overlayOpenState = v;
|
|
1231
|
+
for (const fn of overlayListeners) fn();
|
|
1232
|
+
}
|
|
1233
|
+
function useOverlayOpen() {
|
|
1234
|
+
const [open, setOpen] = useState(overlayOpenState);
|
|
1235
|
+
useEffect(() => {
|
|
1236
|
+
const fn = () => setOpen(overlayOpenState);
|
|
1237
|
+
overlayListeners.add(fn);
|
|
1238
|
+
return () => { overlayListeners.delete(fn); };
|
|
1239
|
+
}, []);
|
|
1240
|
+
return [open, setOverlayOpen];
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// Full-viewport memory library for states without a tab ring (new-chat
|
|
1244
|
+
// hero). Same MemoryExplorer component as the tab view — identical
|
|
1245
|
+
// three-column layout, graph and settings — plus a slim top bar with a
|
|
1246
|
+
// close affordance. Esc closes. Portalled to <body> so sidebar stacking
|
|
1247
|
+
// contexts cannot clip it.
|
|
1248
|
+
function MemoryOverlay({ t }) {
|
|
1249
|
+
const [open, setOpen] = useOverlayOpen();
|
|
1250
|
+
useEffect(() => {
|
|
1251
|
+
if (!open) return undefined;
|
|
1252
|
+
const onKey = (e) => { if (e.key === "Escape") setOpen(false); };
|
|
1253
|
+
window.addEventListener("keydown", onKey);
|
|
1254
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
1255
|
+
}, [open]);
|
|
1256
|
+
if (!open) return null;
|
|
1257
|
+
const tree = h("div", { className: "mneme-overlay", role: "region", "aria-label": t("memory.view.label") },
|
|
1258
|
+
h("div", { className: "mneme-overlaybar" },
|
|
1259
|
+
h("span", { className: "mneme-overlaytitle" }, t("memory.view.label")),
|
|
1260
|
+
h("button", {
|
|
1261
|
+
type: "button",
|
|
1262
|
+
className: "mneme-footbtn",
|
|
1263
|
+
onClick: () => setOpen(false)
|
|
1264
|
+
}, t("memory.overlay.close"))
|
|
1265
|
+
),
|
|
1266
|
+
h("div", { className: "mneme-overlaybody" }, h(MemoryExplorer, { t }))
|
|
1267
|
+
);
|
|
1268
|
+
if (reactDom && typeof document !== "undefined") return reactDom.createPortal(tree, document.body);
|
|
1269
|
+
return tree;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
// --- directory sub-view (v0.6.3) ---
|
|
1273
|
+
// A tag folder tree over the live memory set. One-level folders keyed by
|
|
1274
|
+
// tag (handled on the server, getDirectory), each with a 二级 memory
|
|
1275
|
+
// entry list (title + updated time); memories without a live tag land in
|
|
1276
|
+
// the "untagged" folder. Collapse state lives in MemoryExplorer (lifted via
|
|
1277
|
+
// `collapsed`), so switching tabs does not drop it. Clicking an entry jumps
|
|
1278
|
+
// back into the browser with that memory selected (onJump = jumpToMemory).
|
|
1279
|
+
function DirectoryPanel({ t, onJump, collapsed, setCollapsed }) {
|
|
1280
|
+
const [dir, setDir] = useState(null); // { groups: [...], untagged: [...] }
|
|
1281
|
+
const [status, setStatus] = useState("loading"); // loading | ready | error
|
|
1282
|
+
const [editMode, setEditMode] = useState(false); // manual tag/delete UI gate
|
|
1283
|
+
const [confirmingId, setConfirmingId] = useState(null); // row waiting for the 2nd confirm click
|
|
1284
|
+
const [delErrorId, setDelErrorId] = useState(null); // row whose delete just failed
|
|
1285
|
+
const confirmTimer = useRef(null);
|
|
1286
|
+
|
|
1287
|
+
useEffect(() => {
|
|
1288
|
+
let cancelled = false;
|
|
1289
|
+
setStatus("loading");
|
|
1290
|
+
apiFetch("/api/dsh-mneme/directory")
|
|
1291
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
1292
|
+
.then((d) => {
|
|
1293
|
+
if (cancelled) return;
|
|
1294
|
+
if (!d) { setDir(null); setStatus("error"); return; }
|
|
1295
|
+
setDir({ groups: Array.isArray(d.groups) ? d.groups : [], untagged: Array.isArray(d.untagged) ? d.untagged : [] });
|
|
1296
|
+
setStatus("ready");
|
|
1297
|
+
})
|
|
1298
|
+
.catch(() => { if (!cancelled) { setDir(null); setStatus("error"); } });
|
|
1299
|
+
apiFetch("/api/dsh-mneme/config")
|
|
1300
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
1301
|
+
.then((d) => { if (!cancelled && d?.config && typeof d.config.manualTagEnabled === "boolean") setEditMode(d.config.manualTagEnabled); })
|
|
1302
|
+
.catch(() => {});
|
|
1303
|
+
return () => { cancelled = true; };
|
|
1304
|
+
}, []);
|
|
1305
|
+
|
|
1306
|
+
const toggle = (key) => setCollapsed((c) => ({ ...c, [key]: !c[key] }));
|
|
1307
|
+
|
|
1308
|
+
const toggleEdit = () => {
|
|
1309
|
+
const next = !editMode;
|
|
1310
|
+
apiFetch("/api/dsh-mneme/config", {
|
|
1311
|
+
method: "PUT",
|
|
1312
|
+
headers: { "Content-Type": "application/json" },
|
|
1313
|
+
body: JSON.stringify({ manualTagEnabled: next })
|
|
1314
|
+
}).then((res) => { if (res.ok) setEditMode(next); }).catch(() => {});
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
const resetConfirm = () => {
|
|
1318
|
+
clearTimeout(confirmTimer.current);
|
|
1319
|
+
setConfirmingId(null);
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
const handleDelete = (memId, e) => {
|
|
1323
|
+
e?.stopPropagation?.();
|
|
1324
|
+
// 第一击进入「确认?」态,第二击才真正发 DELETE;宿主 web 环境里
|
|
1325
|
+
// window.confirm 不可靠(可能被拦截或直接返回 false),点击会无反应,
|
|
1326
|
+
// 所以改为面板内联两步确认,不依赖任何原生对话框。
|
|
1327
|
+
if (confirmingId !== memId) {
|
|
1328
|
+
setConfirmingId(memId);
|
|
1329
|
+
clearTimeout(confirmTimer.current);
|
|
1330
|
+
confirmTimer.current = setTimeout(() => setConfirmingId((cur) => (cur === memId ? null : cur)), 3000);
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
clearTimeout(confirmTimer.current);
|
|
1334
|
+
setConfirmingId(null);
|
|
1335
|
+
apiFetch("/api/dsh-mneme/memories", {
|
|
1336
|
+
method: "DELETE",
|
|
1337
|
+
headers: { "Content-Type": "application/json" },
|
|
1338
|
+
body: JSON.stringify({ id: memId })
|
|
1339
|
+
})
|
|
1340
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
1341
|
+
.then((d) => {
|
|
1342
|
+
if (!d || d.deleted !== true) {
|
|
1343
|
+
// 服务端未确认删除也给出可见提示,不静默吞掉
|
|
1344
|
+
setDelErrorId(memId);
|
|
1345
|
+
setTimeout(() => setDelErrorId((cur) => (cur === memId ? null : cur)), 3500);
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
setDir((prev) => ({
|
|
1349
|
+
groups: prev.groups.map((g) => ({ ...g, memories: g.memories.filter((m) => m.id !== memId) })),
|
|
1350
|
+
untagged: prev.untagged.filter((m) => m.id !== memId)
|
|
1351
|
+
}));
|
|
1352
|
+
})
|
|
1353
|
+
.catch(() => {
|
|
1354
|
+
// 网络失败同样给出可见提示
|
|
1355
|
+
setDelErrorId(memId);
|
|
1356
|
+
setTimeout(() => setDelErrorId((cur) => (cur === memId ? null : cur)), 3500);
|
|
1357
|
+
});
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
const renderFolder = (name, memories, extraKey, emptyLabel) => {
|
|
1361
|
+
const folderKey = extraKey || name;
|
|
1362
|
+
const open = !collapsed[folderKey];
|
|
1363
|
+
const rows = memories.map((m) => {
|
|
1364
|
+
const confirming = confirmingId === m.id;
|
|
1365
|
+
const err = delErrorId === m.id;
|
|
1366
|
+
return h("div", {
|
|
1367
|
+
key: m.id,
|
|
1368
|
+
className: err ? "mneme-dir-item mneme-dir-error" : "mneme-dir-item",
|
|
1369
|
+
// 点击行内其它地方取消「确认?」态
|
|
1370
|
+
onClick: resetConfirm
|
|
1371
|
+
},
|
|
1372
|
+
h("span", { className: "mneme-tree-line" }),
|
|
1373
|
+
h("button", { type: "button", className: "mneme-dir-ititle", onClick: () => onJump(m) }, m.title || m.content?.slice(0, 40)),
|
|
1374
|
+
h("span", { className: "mneme-dir-itime" }, formatDate(m.updated_at || m.created_at)),
|
|
1375
|
+
editMode && h("button", {
|
|
1376
|
+
type: "button",
|
|
1377
|
+
className: confirming ? "mneme-dir-del mneme-dir-del-confirm" : "mneme-dir-del",
|
|
1378
|
+
"aria-label": "delete",
|
|
1379
|
+
onClick: (e) => handleDelete(m.id, e)
|
|
1380
|
+
}, confirming ? t("directory.deleteConfirmShort") : "✕"),
|
|
1381
|
+
err && h("span", { className: "mneme-dir-del-err" }, t("directory.deleteError"))
|
|
1382
|
+
);
|
|
1383
|
+
});
|
|
1384
|
+
return h("div", {
|
|
1385
|
+
key: folderKey,
|
|
1386
|
+
className: "mneme-dir-folder",
|
|
1387
|
+
"data-expanded": String(open)
|
|
1388
|
+
},
|
|
1389
|
+
h("button", {
|
|
1390
|
+
type: "button",
|
|
1391
|
+
className: "mneme-dir-folderhead",
|
|
1392
|
+
"aria-expanded": String(open),
|
|
1393
|
+
onClick: () => toggle(folderKey)
|
|
1394
|
+
},
|
|
1395
|
+
h("span", { className: "mneme-dir-caret" }, open ? "▾" : "▸"),
|
|
1396
|
+
h("span", { className: "mneme-dir-fname" }, `📁 ${name}`),
|
|
1397
|
+
h("span", { className: "mneme-dir-fcount" }, String(memories.length))
|
|
1398
|
+
),
|
|
1399
|
+
open && h("div", { className: "mneme-dir-fbody" },
|
|
1400
|
+
rows.length > 0 ? rows : h("div", { className: "mneme-dir-empty" }, emptyLabel || t("memory.directory.empty"))
|
|
1401
|
+
)
|
|
1402
|
+
);
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
if (status === "loading") {
|
|
1406
|
+
return h("div", { className: "mneme-directory" }, h("div", { className: "mneme-dir-empty" }, t("memory.directory.loading")));
|
|
1407
|
+
}
|
|
1408
|
+
const hasAny = dir && (dir.groups.length > 0 || dir.untagged.length > 0);
|
|
1409
|
+
if (status === "error" || !hasAny) {
|
|
1410
|
+
return h("div", { className: "mneme-directory" }, h("div", { className: "mneme-dir-empty" }, t("memory.directory.empty")));
|
|
1411
|
+
}
|
|
1412
|
+
return h("div", { className: editMode ? "mneme-directory mneme-edit-on" : "mneme-directory" },
|
|
1413
|
+
h("label", { className: "mneme-edit-toggle" },
|
|
1414
|
+
h("input", { type: "checkbox", checked: editMode, onChange: toggleEdit }),
|
|
1415
|
+
t("directory.editToggle")
|
|
1416
|
+
),
|
|
1417
|
+
dir.groups.map((g) => renderFolder(g.tag, g.memories)),
|
|
1418
|
+
dir.untagged.length > 0 && renderFolder(t("memory.directory.untagged"), dir.untagged, "mneme-untagged")
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// --- Overview sub-view (layered stats dashboard) ---
|
|
1423
|
+
// Card grid of every memory type (fixed display order, strays appended
|
|
1424
|
+
// alphabetically), plus a user-profile card, a CSS-only type distribution
|
|
1425
|
+
// bar chart and a 7-day creation trend. Data comes from /stats; each tile
|
|
1426
|
+
// probes /list?type=X&limit=1 for a representative latest title (the list
|
|
1427
|
+
// API sorts importance-first, so limit=1 is the type's most prominent row).
|
|
1428
|
+
const OVERVIEW_TYPE_ORDER = ["preference", "project", "decision", "history", "user", "fact", "summary", "pattern"];
|
|
1429
|
+
// Injection-priority tiers from service.js (summary > preference/user >
|
|
1430
|
+
// importance): these layers ride into nearly every prompt.
|
|
1431
|
+
const OVERVIEW_INJECT_TYPES = ["summary", "user", "preference"];
|
|
1432
|
+
|
|
1433
|
+
function OverviewPanel({ t, onPickType }) {
|
|
1434
|
+
const [stats, setStats] = useState(null); // null = loading
|
|
1435
|
+
const [profile, setProfile] = useState(null); // user-type memories (list card)
|
|
1436
|
+
const [latest, setLatest] = useState({}); // type -> representative memory | null
|
|
1437
|
+
|
|
1438
|
+
useEffect(() => {
|
|
1439
|
+
let cancelled = false;
|
|
1440
|
+
apiFetch("/api/dsh-mneme/stats?days=7")
|
|
1441
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
1442
|
+
.then((d) => { if (!cancelled) setStats(d && d.byType ? d : { byType: {}, total: 0, recent: [] }); })
|
|
1443
|
+
.catch(() => { if (!cancelled) setStats({ byType: {}, total: 0, recent: [] }); });
|
|
1444
|
+
apiFetch("/api/dsh-mneme/list?type=user&limit=20")
|
|
1445
|
+
.then((r) => (r.ok ? r.json() : { items: [] }))
|
|
1446
|
+
.then((d) => { if (!cancelled) setProfile(Array.isArray(d.items) ? d.items : []); })
|
|
1447
|
+
.catch(() => { if (!cancelled) setProfile([]); });
|
|
1448
|
+
return () => { cancelled = true; };
|
|
1449
|
+
}, []);
|
|
1450
|
+
|
|
1451
|
+
const byType = stats ? stats.byType : {};
|
|
1452
|
+
const gridTypes = stats
|
|
1453
|
+
? OVERVIEW_TYPE_ORDER.filter((k) => byType[k]).concat(
|
|
1454
|
+
Object.keys(byType).filter((k) => !OVERVIEW_TYPE_ORDER.includes(k)).sort())
|
|
1455
|
+
: [];
|
|
1456
|
+
|
|
1457
|
+
// Representative-latest probe, one small request per visible layer.
|
|
1458
|
+
// Derived purely from stats, so [stats] is the full dependency set.
|
|
1459
|
+
useEffect(() => {
|
|
1460
|
+
if (!stats || gridTypes.length === 0) return;
|
|
1461
|
+
let cancelled = false;
|
|
1462
|
+
Promise.all(gridTypes.map((k) =>
|
|
1463
|
+
apiFetch(`/api/dsh-mneme/list?type=${encodeURIComponent(k)}&limit=1`)
|
|
1464
|
+
.then((r) => (r.ok ? r.json() : { items: [] }))
|
|
1465
|
+
.then((d) => [k, (Array.isArray(d.items) && d.items[0]) || null])
|
|
1466
|
+
.catch(() => [k, null])
|
|
1467
|
+
)).then((pairs) => { if (!cancelled) setLatest(Object.fromEntries(pairs)); });
|
|
1468
|
+
return () => { cancelled = true; };
|
|
1469
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1470
|
+
}, [stats]);
|
|
1471
|
+
|
|
1472
|
+
if (!stats) return h("div", { className: "mneme-ov-wrap" }, h("div", { className: "mneme-hint" }, t("memory.directory.loading")));
|
|
1473
|
+
if (stats.total === 0) return h("div", { className: "mneme-ov-wrap" }, h("div", { className: "mneme-hint" }, t("memory.overview.empty")));
|
|
1474
|
+
|
|
1475
|
+
const distRow = (key) => {
|
|
1476
|
+
const count = byType[key] || 0;
|
|
1477
|
+
const pct = stats.total > 0 ? Math.round((count / stats.total) * 100) : 0;
|
|
1478
|
+
return h("div", { key, className: "mneme-ov-distrow" },
|
|
1479
|
+
h("span", { className: "mneme-ov-distlabel" }, typeLabel(t, key)),
|
|
1480
|
+
h("span", { className: "mneme-ov-distcount" }, String(count)),
|
|
1481
|
+
h("div", { className: "mneme-ov-disttrack" },
|
|
1482
|
+
h("div", { className: "mneme-ov-distbar", style: { width: `${pct}%` } }))
|
|
1483
|
+
);
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
const tile = (key) => {
|
|
1487
|
+
const inject = OVERVIEW_INJECT_TYPES.includes(key);
|
|
1488
|
+
const last = latest[key];
|
|
1489
|
+
return h("button", {
|
|
1490
|
+
key,
|
|
1491
|
+
type: "button",
|
|
1492
|
+
className: "mneme-card mneme-ov-tile",
|
|
1493
|
+
title: t("memory.card.open"),
|
|
1494
|
+
onClick: () => onPickType && onPickType(key)
|
|
1495
|
+
},
|
|
1496
|
+
h("div", { className: "mneme-ov-tilehead" },
|
|
1497
|
+
h("span", { className: "mneme-ov-tiletitle" }, typeLabel(t, key)),
|
|
1498
|
+
h("span", { className: inject ? "mneme-ov-badge" : "mneme-ov-badge mneme-ov-badge--dim" },
|
|
1499
|
+
inject ? t("memory.overview.badgeInject") : t("memory.overview.badgeImportance")),
|
|
1500
|
+
h("span", { className: "mneme-ov-tilecount" }, String(byType[key] || 0))
|
|
1501
|
+
),
|
|
1502
|
+
h("div", { className: "mneme-ov-tilelatest" },
|
|
1503
|
+
(last && (last.title || (last.content || "").slice(0, 40))) || t("memory.overview.none"))
|
|
1504
|
+
);
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// Trend bars scale to the busiest day; heights are fixed px so they do
|
|
1508
|
+
// not depend on percentage resolution inside the flex columns.
|
|
1509
|
+
const recent = Array.isArray(stats.recent) ? stats.recent : [];
|
|
1510
|
+
const maxTrend = Math.max(1, ...recent.map((d) => d.count || 0));
|
|
1511
|
+
const trendCol = (d) => {
|
|
1512
|
+
const count = d.count || 0;
|
|
1513
|
+
const px = count > 0 ? 6 + Math.round((count / maxTrend) * 90) : 0;
|
|
1514
|
+
return h("div", {
|
|
1515
|
+
key: d.date,
|
|
1516
|
+
className: "mneme-ov-trendcol",
|
|
1517
|
+
title: `${d.date} · ${t("memory.explorer.count").replace("{n}", String(count))}`
|
|
1518
|
+
},
|
|
1519
|
+
h("div", { className: "mneme-ov-trendbar", style: { height: `${px}px` } }),
|
|
1520
|
+
h("div", { className: "mneme-ov-trenddate" }, (d.date || "").slice(5)) // MM-DD
|
|
1521
|
+
);
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
return h("div", { className: "mneme-ov-wrap" },
|
|
1525
|
+
h("div", { className: "mneme-card mneme-ov-profile", role: "region", "aria-label": t("memory.settings.profile") },
|
|
1526
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.settings.profile")),
|
|
1527
|
+
profile === null
|
|
1528
|
+
? h("div", { className: "mneme-ov-ppreview" }, t("memory.directory.loading"))
|
|
1529
|
+
: profile.length === 0
|
|
1530
|
+
? h("div", { className: "mneme-ov-ppreview" }, t("memory.overview.profileEmpty"))
|
|
1531
|
+
: profile.map((m) => h("div", { key: m.id, className: "mneme-ov-prow" },
|
|
1532
|
+
h("span", { className: "mneme-ov-ptitle" }, m.title || "—"),
|
|
1533
|
+
h("span", { className: "mneme-ov-ppreview" }, (m.content_preview || m.content || "").slice(0, 100))
|
|
1534
|
+
))
|
|
1535
|
+
),
|
|
1536
|
+
h("div", { className: "mneme-card", role: "region", "aria-label": t("memory.overview.distribution") },
|
|
1537
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.overview.distribution")),
|
|
1538
|
+
h("div", { className: "mneme-ov-dist" }, gridTypes.map(distRow))
|
|
1539
|
+
),
|
|
1540
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.overview.layers")),
|
|
1541
|
+
h("div", { className: "mneme-ov-grid" }, gridTypes.map(tile)),
|
|
1542
|
+
h("div", { className: "mneme-card", role: "region", "aria-label": t("memory.overview.trend") },
|
|
1543
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.overview.trend")),
|
|
1544
|
+
recent.length === 0
|
|
1545
|
+
? h("div", { className: "mneme-ov-tilelatest" }, t("memory.overview.none"))
|
|
1546
|
+
: h("div", { className: "mneme-ov-trend" }, recent.map(trendCol))
|
|
1547
|
+
)
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
const EXPLORER_TYPES = ["preference", "project", "decision", "summary", "history", "user", "fact"];
|
|
1552
|
+
|
|
1553
|
+
function MemoryExplorer({ t }) {
|
|
1554
|
+
const [view, setView] = useState("memory"); // memory | overview | directory | graph | settings
|
|
1555
|
+
const [items, setItems] = useState([]);
|
|
1556
|
+
const [loading, setLoading] = useState(true);
|
|
1557
|
+
const [type, setType] = useState("all");
|
|
1558
|
+
const [query, setQuery] = useState("");
|
|
1559
|
+
const [semantic, setSemantic] = useState(false);
|
|
1560
|
+
const [vecEnabled, setVecEnabled] = useState(false);
|
|
1561
|
+
const [searchTopK, setSearchTopK] = useState(20);
|
|
1562
|
+
const [remoteItems, setRemoteItems] = useState(null);
|
|
1563
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
1564
|
+
const [collapsed, setCollapsed] = useState({});
|
|
1565
|
+
// v0.6.3 directory sub-view: its own folder-collapse state, kept in
|
|
1566
|
+
// MemoryExplorer so switching tabs does not lose it and jumpToMemory's
|
|
1567
|
+
// time-tree reset (setCollapsed({})) cannot clobber it.
|
|
1568
|
+
const [dirCollapsed, setDirCollapsed] = useState({});
|
|
1569
|
+
const [copied, setCopied] = useState(false);
|
|
1570
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
1571
|
+
const [graphFocus, setGraphFocus] = useState("");
|
|
1572
|
+
// v0.6.2 tag editing state for the detail pane. The authoritative tag set
|
|
1573
|
+
// lives server-side (entity_attrs), so it is fetched per selected memory
|
|
1574
|
+
// and refreshed after every write instead of trusting the list snapshot.
|
|
1575
|
+
const [tagTags, setTagTags] = useState([]);
|
|
1576
|
+
const [tagManual, setTagManual] = useState(true);
|
|
1577
|
+
const [tagInput, setTagInput] = useState("");
|
|
1578
|
+
const [tagAdding, setTagAdding] = useState(false);
|
|
1579
|
+
const itemRefs = useRef(new Map());
|
|
1580
|
+
|
|
1581
|
+
useEffect(() => {
|
|
1582
|
+
apiFetch("/api/dsh-mneme/vector-config")
|
|
1583
|
+
.then((res) => res.json())
|
|
1584
|
+
.then((d) => setVecEnabled(!!d.config?.enabled))
|
|
1585
|
+
.catch(() => {});
|
|
1586
|
+
}, []);
|
|
1587
|
+
|
|
1588
|
+
useEffect(() => {
|
|
1589
|
+
let cancelled = false;
|
|
1590
|
+
setLoading(true);
|
|
1591
|
+
apiFetch("/api/dsh-mneme/list?limit=500")
|
|
1592
|
+
.then((res) => (res.ok ? res.json() : { items: [] }))
|
|
1593
|
+
.then((d) => { if (!cancelled) { setItems(d.items || []); setLoading(false); } })
|
|
1594
|
+
.catch(() => { if (!cancelled) { setItems([]); setLoading(false); } });
|
|
1595
|
+
return () => { cancelled = true; };
|
|
1596
|
+
}, [reloadKey]);
|
|
1597
|
+
|
|
1598
|
+
// Semantic search: server-side ranking replaces the client filter
|
|
1599
|
+
// while enabled and a query is present (debounced). tag: queries always
|
|
1600
|
+
// go server-side (searchMemories resolves them without vector support),
|
|
1601
|
+
// so they bypass the semantic toggle and use the same search endpoint.
|
|
1602
|
+
useEffect(() => {
|
|
1603
|
+
const q = query.trim();
|
|
1604
|
+
if ((!semantic && !q.startsWith("tag:")) || !q || q.startsWith("entity:")) { setRemoteItems(null); return; }
|
|
1605
|
+
let cancelled = false;
|
|
1606
|
+
const timer = setTimeout(() => {
|
|
1607
|
+
apiFetch(`/api/dsh-mneme/search?q=${encodeURIComponent(q)}&mode=vector&topK=${searchTopK}`)
|
|
1608
|
+
.then((res) => (res.ok ? res.json() : { items: [] }))
|
|
1609
|
+
.then((d) => { if (!cancelled) setRemoteItems(d.items || []); })
|
|
1610
|
+
.catch(() => { if (!cancelled) setRemoteItems([]); });
|
|
1611
|
+
}, 250);
|
|
1612
|
+
return () => { cancelled = true; clearTimeout(timer); };
|
|
1613
|
+
}, [semantic, query, searchTopK]);
|
|
1614
|
+
|
|
1615
|
+
useEffect(() => {
|
|
1616
|
+
if (!selectedId) return;
|
|
1617
|
+
itemRefs.current.get(selectedId)?.scrollIntoView({ block: "nearest" });
|
|
1618
|
+
}, [selectedId]);
|
|
1619
|
+
|
|
1620
|
+
// Load the authoritative tag set for the selected memory (entity_attrs-
|
|
1621
|
+
// backed) plus the manualTagEnabled gate that hides editing when off.
|
|
1622
|
+
const loadTags = (id) => {
|
|
1623
|
+
if (!id) { setTagTags([]); setTagManual(true); setTagInput(""); return; }
|
|
1624
|
+
apiFetch(`/api/dsh-mneme/memory/tags?id=${encodeURIComponent(id)}`)
|
|
1625
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
1626
|
+
.then((j) => { if (j) { setTagTags(Array.isArray(j.tags) ? j.tags : []); setTagManual(j.manualTagEnabled !== false); } })
|
|
1627
|
+
.catch(() => {});
|
|
1628
|
+
};
|
|
1629
|
+
useEffect(() => {
|
|
1630
|
+
let cancelled = false;
|
|
1631
|
+
if (selectedId) {
|
|
1632
|
+
apiFetch(`/api/dsh-mneme/memory/tags?id=${encodeURIComponent(selectedId)}`)
|
|
1633
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
1634
|
+
.then((j) => { if (!cancelled && j) { setTagTags(Array.isArray(j.tags) ? j.tags : []); setTagManual(j.manualTagEnabled !== false); } })
|
|
1635
|
+
.catch(() => {});
|
|
1636
|
+
} else {
|
|
1637
|
+
setTagTags([]);
|
|
1638
|
+
setTagManual(true);
|
|
1639
|
+
}
|
|
1640
|
+
setTagAdding(false);
|
|
1641
|
+
return () => { cancelled = true; };
|
|
1642
|
+
}, [selectedId]);
|
|
1643
|
+
|
|
1644
|
+
const q = query.trim().toLowerCase();
|
|
1645
|
+
// "entity:" is the graph entry grammar: typing it means the user wants
|
|
1646
|
+
// the entity's neighborhood, not a memory list. Offer the jump instead
|
|
1647
|
+
// of auto-switching so the list stays predictable.
|
|
1648
|
+
const entityQuery = query.trim().startsWith("entity:")
|
|
1649
|
+
? query.trim().slice(7).trim()
|
|
1650
|
+
: "";
|
|
1651
|
+
const visible = remoteItems
|
|
1652
|
+
? remoteItems
|
|
1653
|
+
: items.filter((m) => {
|
|
1654
|
+
if (type !== "all" && m.type !== type) return false;
|
|
1655
|
+
if (!q) return true;
|
|
1656
|
+
return (m.title || "").toLowerCase().includes(q) || (m.content || "").toLowerCase().includes(q);
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
const counts = {};
|
|
1660
|
+
for (const m of items) counts[m.type] = (counts[m.type] || 0) + 1;
|
|
1661
|
+
const knownTypes = EXPLORER_TYPES.filter((k) => counts[k]);
|
|
1662
|
+
const extraTypes = Object.keys(counts)
|
|
1663
|
+
.filter((k) => !EXPLORER_TYPES.includes(k))
|
|
1664
|
+
.sort((a, b) => counts[b] - counts[a]);
|
|
1665
|
+
|
|
1666
|
+
// Time tree: sort newest first, then group month → day in one pass so
|
|
1667
|
+
// the grouping follows the sort order instead of re-sorting buckets.
|
|
1668
|
+
const sorted = [...visible].sort((a, b) =>
|
|
1669
|
+
new Date(b.updated_at || b.created_at || 0) - new Date(a.updated_at || a.created_at || 0));
|
|
1670
|
+
const months = [];
|
|
1671
|
+
let curMonth = null, curDay = null;
|
|
1672
|
+
for (const m of sorted) {
|
|
1673
|
+
const d = new Date(m.updated_at || m.created_at || 0);
|
|
1674
|
+
const valid = !Number.isNaN(d.getTime());
|
|
1675
|
+
const mk = valid ? `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}` : "unknown";
|
|
1676
|
+
if (!curMonth || curMonth.key !== mk) {
|
|
1677
|
+
curMonth = {
|
|
1678
|
+
key: mk,
|
|
1679
|
+
label: valid ? d.toLocaleDateString(undefined, { year: "numeric", month: "long" }) : "—",
|
|
1680
|
+
days: []
|
|
1681
|
+
};
|
|
1682
|
+
months.push(curMonth);
|
|
1683
|
+
curDay = null;
|
|
1684
|
+
}
|
|
1685
|
+
const dk = valid ? `${mk}-${String(d.getDate())}` : "unknown";
|
|
1686
|
+
if (!curDay || curDay.key !== dk) {
|
|
1687
|
+
curDay = { key: dk, label: valid ? d.toLocaleDateString(undefined, { day: "numeric" }) : "—", items: [] };
|
|
1688
|
+
curMonth.days.push(curDay);
|
|
1689
|
+
}
|
|
1690
|
+
curDay.items.push(m);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
const selected = items.find((m) => m.id === selectedId) || null;
|
|
1694
|
+
|
|
1695
|
+
const copyContent = () => {
|
|
1696
|
+
if (!selected) return;
|
|
1697
|
+
navigator.clipboard?.writeText(selected.content || "").then(
|
|
1698
|
+
() => { setCopied(true); setTimeout(() => setCopied(false), 1500); },
|
|
1699
|
+
() => {}
|
|
1700
|
+
);
|
|
1701
|
+
};
|
|
1702
|
+
|
|
1703
|
+
// v0.6.2 tag editing: a chip click jumps to a tag:xxx search (reusing
|
|
1704
|
+
// the query-driven search flow), the + entry and per-chip × post the new
|
|
1705
|
+
// tag set through the tags endpoint then re-fetch. A 409 from the server
|
|
1706
|
+
// means manualTagEnabled turned off — flip the gate so editing hides.
|
|
1707
|
+
const submitTag = () => {
|
|
1708
|
+
const tag = tagInput.trim();
|
|
1709
|
+
if (!tag || !selectedId) return;
|
|
1710
|
+
apiFetch("/api/dsh-mneme/memory/tags", {
|
|
1711
|
+
method: "POST",
|
|
1712
|
+
headers: { "Content-Type": "application/json" },
|
|
1713
|
+
body: JSON.stringify({ id: selectedId, tags: [...tagTags, tag] })
|
|
1714
|
+
}).then((res) => {
|
|
1715
|
+
if (res.status === 409) { setTagManual(false); setTagAdding(false); setTagInput(""); return; }
|
|
1716
|
+
return res.json();
|
|
1717
|
+
}).then((j) => {
|
|
1718
|
+
if (j?.ok) { setTagAdding(false); setTagInput(""); loadTags(selectedId); }
|
|
1719
|
+
}).catch(() => {});
|
|
1720
|
+
};
|
|
1721
|
+
const removeTag = (tag) => {
|
|
1722
|
+
if (!selectedId) return;
|
|
1723
|
+
apiFetch("/api/dsh-mneme/memory/tags", {
|
|
1724
|
+
method: "POST",
|
|
1725
|
+
headers: { "Content-Type": "application/json" },
|
|
1726
|
+
body: JSON.stringify({ id: selectedId, tags: tagTags.filter((x) => x !== tag) })
|
|
1727
|
+
}).then((res) => {
|
|
1728
|
+
if (res.status === 409) { setTagManual(false); return; }
|
|
1729
|
+
return res.json();
|
|
1730
|
+
}).then((j) => {
|
|
1731
|
+
if (j?.ok) loadTags(selectedId);
|
|
1732
|
+
}).catch(() => {});
|
|
1733
|
+
};
|
|
1734
|
+
const onTagClick = (tag) => {
|
|
1735
|
+
setType("all");
|
|
1736
|
+
setQuery(`tag:${tag}`);
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
// Graph → memory jump: land on the browser tab with filters reset so
|
|
1740
|
+
// the target row is visible, selected and scrolled into view.
|
|
1741
|
+
const jumpToMemory = (target) => {
|
|
1742
|
+
if (!target?.id) return;
|
|
1743
|
+
setView("memory");
|
|
1744
|
+
setType("all");
|
|
1745
|
+
setQuery("");
|
|
1746
|
+
setCollapsed({});
|
|
1747
|
+
setSelectedId(target.id);
|
|
1748
|
+
};
|
|
1749
|
+
|
|
1750
|
+
// [[wiki-link]] click in the detail content: resolve the title to a
|
|
1751
|
+
// memory (case-insensitive exact match) then jump to it. Unresolvable
|
|
1752
|
+
// titles silently no-op — the link stays as display text.
|
|
1753
|
+
const onWikilinkClick = (target) => {
|
|
1754
|
+
if (!target) return;
|
|
1755
|
+
apiFetch(`/api/dsh-mneme/wikilinks/resolve?title=${encodeURIComponent(target)}`)
|
|
1756
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
1757
|
+
.then((j) => { if (j?.memory?.id) jumpToMemory(j.memory); })
|
|
1758
|
+
.catch(() => {});
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
const openGraphFor = (name) => {
|
|
1762
|
+
setGraphFocus(name || "");
|
|
1763
|
+
setView("graph");
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1766
|
+
// Overview tile click: dive into the memory view filtered to that layer.
|
|
1767
|
+
const pickLayerType = (key) => {
|
|
1768
|
+
setType(key);
|
|
1769
|
+
setView("memory");
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
const subviews = [
|
|
1773
|
+
{ key: "memory", label: t("memory.explorer.tabMemory") },
|
|
1774
|
+
{ key: "overview", label: t("memory.explorer.tabOverview") },
|
|
1775
|
+
{ key: "directory", label: t("memory.explorer.tabDirectory") },
|
|
1776
|
+
{ key: "graph", label: t("memory.explorer.tabGraph") },
|
|
1777
|
+
{ key: "settings", label: t("memory.explorer.tabSettings") }
|
|
1778
|
+
];
|
|
1779
|
+
|
|
1780
|
+
return h("div", { className: "mneme-x" },
|
|
1781
|
+
h("div", { className: "mneme-xbar" },
|
|
1782
|
+
h("nav", { className: "mneme-vtabs", "aria-label": t("memory.view.label") },
|
|
1783
|
+
subviews.map((s) =>
|
|
1784
|
+
h("button", {
|
|
1785
|
+
key: s.key,
|
|
1786
|
+
type: "button",
|
|
1787
|
+
className: view === s.key ? "mneme-vtab mneme-active" : "mneme-vtab",
|
|
1788
|
+
"aria-pressed": String(view === s.key),
|
|
1789
|
+
onClick: () => setView(s.key)
|
|
1790
|
+
},
|
|
1791
|
+
s.key === "graph"
|
|
1792
|
+
? h(react.Fragment, null, h(GraphNodesIcon, { size: 16 }), s.label)
|
|
1793
|
+
: s.label
|
|
1794
|
+
))
|
|
1795
|
+
),
|
|
1796
|
+
),
|
|
1797
|
+
view === "memory" && h("div", { className: "mneme-xmain" },
|
|
1798
|
+
// 1. 中间分类栏
|
|
1799
|
+
h("div", { className: "mneme-xfilter-bar" },
|
|
1800
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.explorer.types")),
|
|
1801
|
+
h("button", {
|
|
1802
|
+
className: type === "all" ? "mneme-xtype mneme-active" : "mneme-xtype",
|
|
1803
|
+
"aria-pressed": type === "all",
|
|
1804
|
+
onClick: () => setType("all")
|
|
1805
|
+
}, h("span", null, t("memory.tab.all")), h("span", { className: "mneme-xcount2" }, String(items.length))),
|
|
1806
|
+
knownTypes.concat(extraTypes).map((key) =>
|
|
1807
|
+
h("button", {
|
|
1808
|
+
key,
|
|
1809
|
+
className: type === key ? "mneme-xtype mneme-active" : "mneme-xtype",
|
|
1810
|
+
"aria-pressed": type === key,
|
|
1811
|
+
onClick: () => setType(key)
|
|
1812
|
+
},
|
|
1813
|
+
h("span", null, typeLabel(t, key)),
|
|
1814
|
+
h("span", { className: "mneme-xcount2" }, String(counts[key]))
|
|
1815
|
+
))
|
|
1816
|
+
),
|
|
1817
|
+
// 2. 底部三卡片
|
|
1818
|
+
h("div", { className: "mneme-xcards" },
|
|
1819
|
+
// 左卡:搜索
|
|
1820
|
+
h("div", { className: "mneme-card mneme-card--search", role: "region", "aria-label": t("memory.explorer.searchTitle") },
|
|
1821
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.explorer.searchTitle")),
|
|
1822
|
+
h("input", {
|
|
1823
|
+
className: "mneme-search mneme-xsearch",
|
|
1824
|
+
"aria-label": t("memory.explorer.search"),
|
|
1825
|
+
placeholder: t("memory.explorer.search"),
|
|
1826
|
+
value: query,
|
|
1827
|
+
onChange: (e) => setQuery(e.target.value)
|
|
1828
|
+
}),
|
|
1829
|
+
entityQuery && h("button", {
|
|
1830
|
+
className: "mneme-entitychip",
|
|
1831
|
+
style: { textAlign: "left", justifyContent: "flex-start" },
|
|
1832
|
+
onClick: () => openGraphFor(entityQuery)
|
|
1833
|
+
}, `${t("memory.graph.viewInGraph")} “${entityQuery}”`),
|
|
1834
|
+
h("div", { className: "mneme-xrow" },
|
|
1835
|
+
vecEnabled && h("button", {
|
|
1836
|
+
className: semantic ? "mneme-chip mneme-active" : "mneme-chip",
|
|
1837
|
+
title: t("memory.settings.vectorTitle"),
|
|
1838
|
+
onClick: () => setSemantic(!semantic)
|
|
1839
|
+
}, t("memory.panel.semantic")),
|
|
1840
|
+
h("select", {
|
|
1841
|
+
className: "mneme-select mneme-xselect",
|
|
1842
|
+
value: searchTopK,
|
|
1843
|
+
onChange: (e) => setSearchTopK(Number(e.target.value)),
|
|
1844
|
+
title: t("memory.explorer.topK")
|
|
1845
|
+
}, [5, 10, 20, 50].map((n) => h("option", { key: n, value: n }, t("memory.explorer.topKOption").replace("{n}", String(n)))))
|
|
1846
|
+
),
|
|
1847
|
+
h("div", { className: "mneme-xrow" },
|
|
1848
|
+
h("span", { className: "mneme-xcount" }, t("memory.explorer.count").replace("{n}", String(visible.length))),
|
|
1849
|
+
h("button", { className: "mneme-footbtn", onClick: () => setReloadKey((k) => k + 1) }, t("memory.explorer.refresh"))
|
|
1850
|
+
)
|
|
1851
|
+
),
|
|
1852
|
+
// 中卡:时间树
|
|
1853
|
+
h("div", { className: "mneme-card mneme-card--tree", role: "region", "aria-label": t("memory.explorer.timeline") },
|
|
1854
|
+
h("div", { className: "mneme-xcolhead" }, t("memory.explorer.timeline")),
|
|
1855
|
+
loading
|
|
1856
|
+
? h("div", { className: "mneme-xempty" }, "…")
|
|
1857
|
+
: months.length === 0
|
|
1858
|
+
? h("div", { className: "mneme-xempty" }, t("memory.explorer.empty"))
|
|
1859
|
+
: months.map((month) =>
|
|
1860
|
+
h("div", { key: month.key },
|
|
1861
|
+
h("button", {
|
|
1862
|
+
className: "mneme-xmonth",
|
|
1863
|
+
"aria-expanded": String(!collapsed[month.key]),
|
|
1864
|
+
onClick: () => setCollapsed((c) => ({ ...c, [month.key]: !c[month.key] }))
|
|
1865
|
+
},
|
|
1866
|
+
h("span", { className: "mneme-xcaret" }, collapsed[month.key] ? "▸" : "▾"),
|
|
1867
|
+
month.label
|
|
1868
|
+
),
|
|
1869
|
+
!collapsed[month.key] && month.days.map((day) =>
|
|
1870
|
+
h("div", { key: day.key },
|
|
1871
|
+
h("button", {
|
|
1872
|
+
className: "mneme-xday",
|
|
1873
|
+
"aria-expanded": String(!collapsed[day.key]),
|
|
1874
|
+
onClick: () => setCollapsed((c) => ({ ...c, [day.key]: !c[day.key] }))
|
|
1875
|
+
},
|
|
1876
|
+
h("span", { className: "mneme-xcaret" }, collapsed[day.key] ? "▸" : "▾"),
|
|
1877
|
+
day.label
|
|
1878
|
+
),
|
|
1879
|
+
!collapsed[day.key] && day.items.map((m) => {
|
|
1880
|
+
const d = new Date(m.updated_at || m.created_at || 0);
|
|
1881
|
+
const time = Number.isNaN(d.getTime())
|
|
1882
|
+
? ""
|
|
1883
|
+
: d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" });
|
|
1884
|
+
return h("button", {
|
|
1885
|
+
key: m.id,
|
|
1886
|
+
ref: (el) => { if (el) itemRefs.current.set(m.id, el); else itemRefs.current.delete(m.id); },
|
|
1887
|
+
className: m.id === selectedId ? "mneme-xitem mneme-active" : "mneme-xitem",
|
|
1888
|
+
onClick: () => setSelectedId(m.id)
|
|
1889
|
+
},
|
|
1890
|
+
h("span", { className: "mneme-xtime" }, time),
|
|
1891
|
+
h("span", { className: "mneme-xname" }, m.title || m.content?.slice(0, 40))
|
|
1892
|
+
);
|
|
1893
|
+
})
|
|
1894
|
+
)
|
|
1895
|
+
)
|
|
1896
|
+
)
|
|
1897
|
+
)),
|
|
1898
|
+
// 右卡:详情
|
|
1899
|
+
h("div", { className: "mneme-card mneme-card--detail", role: "region", "aria-label": t("memory.explorer.detail") },
|
|
1900
|
+
selected
|
|
1901
|
+
? h(react.Fragment, { key: selected.id },
|
|
1902
|
+
h("div", { className: "mneme-xdinner" },
|
|
1903
|
+
h("div", { className: "mneme-xdtitle" }, selected.title),
|
|
1904
|
+
h("div", { className: "mneme-xdmeta" },
|
|
1905
|
+
h("span", null, `${typeLabel(t, selected.type)} · ${t("memory.explorer.importance")} ★${selected.importance}`),
|
|
1906
|
+
selected.source && h("span", null, `${t("memory.explorer.source")}: ${selected.source}`),
|
|
1907
|
+
h("span", { title: formatDate(selected.created_at) }, `${t("memory.explorer.created")}: ${formatDate(selected.created_at)}`),
|
|
1908
|
+
h("span", { title: formatDate(selected.updated_at) }, `${t("memory.explorer.updated")}: ${formatDate(selected.updated_at)}`)
|
|
1909
|
+
),
|
|
1910
|
+
h("div", { className: "mneme-xdmeta" },
|
|
1911
|
+
h("span", null, t("memory.explorer.tags")),
|
|
1912
|
+
h("div", { className: "mneme-tagrow" },
|
|
1913
|
+
tagTags.length > 0
|
|
1914
|
+
? tagTags.map((tag) =>
|
|
1915
|
+
h("span", {
|
|
1916
|
+
key: tag,
|
|
1917
|
+
className: "mneme-tagchip",
|
|
1918
|
+
title: `tag:${tag}`,
|
|
1919
|
+
onClick: () => onTagClick(tag)
|
|
1920
|
+
},
|
|
1921
|
+
tag,
|
|
1922
|
+
tagManual && h("button", {
|
|
1923
|
+
type: "button",
|
|
1924
|
+
className: "mneme-tagremove",
|
|
1925
|
+
"aria-label": `${t("memory.explorer.tagRemove")}: ${tag}`,
|
|
1926
|
+
onClick: (e) => { e.stopPropagation(); removeTag(tag); }
|
|
1927
|
+
}, "×")
|
|
1928
|
+
)
|
|
1929
|
+
)
|
|
1930
|
+
: h("span", { className: "mneme-tagempty" }, t("memory.explorer.tagsEmpty")),
|
|
1931
|
+
tagManual && (tagAdding
|
|
1932
|
+
? h("input", {
|
|
1933
|
+
key: selectedId,
|
|
1934
|
+
className: "mneme-taginput",
|
|
1935
|
+
autoFocus: true,
|
|
1936
|
+
value: tagInput,
|
|
1937
|
+
placeholder: t("memory.explorer.tagPlaceholder"),
|
|
1938
|
+
onChange: (e) => setTagInput(e.target.value),
|
|
1939
|
+
onKeyDown: (e) => { if (e.key === "Enter") submitTag(); },
|
|
1940
|
+
onBlur: () => { setTagAdding(false); setTagInput(""); }
|
|
1941
|
+
})
|
|
1942
|
+
: h("button", {
|
|
1943
|
+
type: "button",
|
|
1944
|
+
className: "mneme-tagadd",
|
|
1945
|
+
onClick: () => setTagAdding(true)
|
|
1946
|
+
}, `+ ${t("memory.explorer.tagAdd")}`))
|
|
1947
|
+
)
|
|
1948
|
+
),
|
|
1949
|
+
h("div", { className: "mneme-xdcontent" },
|
|
1950
|
+
selected.content ? wikilinkSegments(selected.content, onWikilinkClick) : selected.content
|
|
1951
|
+
),
|
|
1952
|
+
h("div", { className: "mneme-xdactions" },
|
|
1953
|
+
h("button", { className: "mneme-footbtn", onClick: copyContent },
|
|
1954
|
+
copied ? t("memory.explorer.copied") : t("memory.explorer.copy"))
|
|
1955
|
+
),
|
|
1956
|
+
h(BacklinksPanel, { memory: selected, t, onJump: jumpToMemory })
|
|
1957
|
+
)
|
|
1958
|
+
)
|
|
1959
|
+
: h("div", { className: "mneme-xempty" }, t("memory.explorer.emptyDetail"))
|
|
1960
|
+
)
|
|
1961
|
+
)
|
|
1962
|
+
),
|
|
1963
|
+
view === "overview" && h(OverviewPanel, { t, onPickType: pickLayerType }),
|
|
1964
|
+
view === "directory" && h(DirectoryPanel, { t, onJump: jumpToMemory, collapsed: dirCollapsed, setCollapsed: setDirCollapsed }),
|
|
1965
|
+
view === "graph" && h(GraphPanel, { t, focusEntity: graphFocus, onJumpMemory: jumpToMemory }),
|
|
1966
|
+
view === "settings" && h("div", { className: "mneme-xsettings" },
|
|
1967
|
+
h("div", { className: "mneme-xsettings-inner" }, h(SettingsContent, { t }))
|
|
1968
|
+
)
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
// --- Sidebar foot entry: the wide row / rail icon that activates the
|
|
1973
|
+
// main-area memory library tab. When the tab ring is absent (new-chat
|
|
1974
|
+
// hero screen hides the conversation header entirely) the same click
|
|
1975
|
+
// opens the full-viewport overlay instead — the library stays reachable
|
|
1976
|
+
// from every conversation state.
|
|
1977
|
+
function SidebarTrigger({ wide, t }) {
|
|
1978
|
+
// issue #38: the entrance button is now optional (settings-over-config
|
|
1979
|
+
// toggle, persisted via /api/dsh-mneme/config). While the value loads we
|
|
1980
|
+
// render the button (default = visible) so it never flashes out; if the
|
|
1981
|
+
// user disabled it, it drops away after the config resolves. The library
|
|
1982
|
+
// itself is unaffected — the 记忆库 conversation tab stays.
|
|
1983
|
+
const [visible, setVisible] = useState(true);
|
|
1984
|
+
useEffect(() => {
|
|
1985
|
+
let cancelled = false;
|
|
1986
|
+
apiFetch("/api/dsh-mneme/config")
|
|
1987
|
+
.then((res) => res.json())
|
|
1988
|
+
.then((d) => { if (!cancelled) setVisible(d.config?.showSidebarTrigger !== false); })
|
|
1989
|
+
.catch(() => { if (!cancelled) setVisible(true); });
|
|
1990
|
+
return () => { cancelled = true; };
|
|
1991
|
+
}, []);
|
|
1992
|
+
const [, setOpen] = useOverlayOpen();
|
|
1993
|
+
if (!visible) return null;
|
|
1994
|
+
return h("button", {
|
|
1995
|
+
type: "button",
|
|
1996
|
+
className: wide ? "mneme-trigger" : "mneme-trigger mneme-rail",
|
|
1997
|
+
"aria-label": t("memory.sidebar.aria"),
|
|
1998
|
+
title: t("memory.sidebar.aria"),
|
|
1999
|
+
onClick: () => {
|
|
2000
|
+
activateExplorerTab(t("memory.view.label")).then((ok) => { if (!ok) setOpen(true); });
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
h(IconArchiveOutline20, { size: wide ? 16 : 18 }),
|
|
2004
|
+
wide && h("span", { className: "mneme-trigger-label" }, t("memory.panel.open"))
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
function apply(ctx) {
|
|
2009
|
+
ctx.effect(() => ctx.locale.register(NS, dictionaries), "dsh-mneme: dictionaries");
|
|
2010
|
+
|
|
2011
|
+
// Register the memory entry beside Settings at the sidebar foot. The
|
|
2012
|
+
// entry renders a wide row (icon + label) when the sidebar is expanded
|
|
2013
|
+
// and a rail icon when collapsed; clicking activates the memory
|
|
2014
|
+
// library conversation view.
|
|
2015
|
+
ctx.slots.inject("sidebar.footer.action", () => {
|
|
2016
|
+
const t = ctx.locale.bind(NS);
|
|
2017
|
+
return ctx.slots.register({
|
|
2018
|
+
name: "sidebar.footer.action",
|
|
2019
|
+
id: "dsh-mneme",
|
|
2020
|
+
order: 0,
|
|
2021
|
+
label: () => t("memory.panel.open")
|
|
2022
|
+
}, (props) => h(react.Fragment, null,
|
|
2023
|
+
h(SidebarTrigger, { ...props, t }),
|
|
2024
|
+
// The overlay mounts from the always-rendered sidebar slot so it
|
|
2025
|
+
// survives conversation switches; the portal moves it to <body>.
|
|
2026
|
+
h(MemoryOverlay, { t })
|
|
2027
|
+
));
|
|
2028
|
+
});
|
|
2029
|
+
|
|
2030
|
+
// Register the memory library as a conversation view tab, beside
|
|
2031
|
+
// Chat / Trajectory. The view ignores its session props: the library
|
|
2032
|
+
// reads the memory store over HTTP. It hosts every memory feature —
|
|
2033
|
+
// browse, graph and settings — in the main content area.
|
|
2034
|
+
ctx.slots.inject("conversation.view", () => {
|
|
2035
|
+
const t = ctx.locale.bind(NS);
|
|
2036
|
+
return ctx.slots.register({
|
|
2037
|
+
name: "conversation.view",
|
|
2038
|
+
id: "dsh-mneme-memory",
|
|
2039
|
+
order: 30,
|
|
2040
|
+
locale: NS,
|
|
2041
|
+
label: () => t("memory.view.label")
|
|
2042
|
+
}, () => h(MemoryExplorer, { t }));
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
exports.apply = apply;
|
|
2047
|
+
exports.inject = inject;
|
|
2048
|
+
return module.exports;
|
|
2049
|
+
}
|
|
2050
|
+
});
|