dsh-memu-memory 1.3.1 → 1.3.3
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/AGENTS.md +6 -3
- package/CHANGELOG.md +57 -0
- package/README.md +8 -7
- package/README.zh.md +8 -5
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/stats.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +11 -0
- package/docs/contributing.md +6 -4
- package/docs/env-and-commands.md +12 -1
- package/docs/memory-semantics.md +8 -2
- package/docs/troubleshooting.md +24 -6
- package/lib/auto-link/apply.js +249 -0
- package/lib/auto-link/candidates.js +155 -0
- package/lib/auto-link/decide.js +304 -0
- package/lib/auto-link/normalize.js +99 -0
- package/lib/auto-link/policy.js +42 -0
- package/lib/auto-link/suppression.js +101 -0
- package/lib/auto-link/terminology.js +265 -0
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +1509 -72
- package/lib/graph.js +269 -18
- package/lib/memory.js +11 -0
- package/lib/memu.js +7 -6
- package/lib/private-links.js +105 -137
- package/lib/private.js +138 -38
- package/lib/rpc.js +73 -8
- package/lib/state.js +7 -2
- package/lib/tools.js +4 -2
- package/lib/webui/graph-LICENSE.txt +1 -62
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +921 -126
- package/lib/webui/standalone.js +3 -3
- package/package.json +1 -2
- package/scripts/build-graph.mjs +35 -7
- package/scripts/check-all.mjs +2 -0
- package/scripts/check-graph-browser.mjs +106 -23
- package/scripts/make-readme-shots.mjs +59 -0
- package/scripts/rebuild-auto-links.mjs +252 -0
- package/tests/audit-regression.test.mjs +11 -8
- package/tests/auto-link-candidates.test.mjs +161 -0
- package/tests/auto-link-decide.test.mjs +512 -0
- package/tests/auto-link-migration.test.mjs +133 -0
- package/tests/browser.test.mjs +27 -0
- package/tests/client-render.test.mjs +178 -6
- package/tests/consolidation-fork.test.mjs +148 -0
- package/tests/cycle.test.mjs +1 -1
- package/tests/graph-view.test.mjs +221 -22
- package/tests/graph.test.mjs +5 -0
- package/tests/help-page.test.mjs +3 -3
- package/tests/memu-resident-route.test.mjs +130 -0
- package/tests/private-links.test.mjs +81 -45
- package/tests/stubs/child-process-spy.mjs +14 -0
- package/tests/tools.test.mjs +24 -18
package/lib/client.js
CHANGED
|
@@ -8,7 +8,7 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
const exports = module.exports
|
|
9
9
|
|
|
10
10
|
const NS = 'dsh-memu-memory'
|
|
11
|
-
const SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'logs', 'lexicon', 'help']
|
|
11
|
+
const SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help']
|
|
12
12
|
const EMPTY_SESSIONS = Object.freeze({ byId: Object.freeze({}), ids: Object.freeze([]) })
|
|
13
13
|
const TAB_ID = `${NS}:memory`
|
|
14
14
|
const TAB_KIND = 'dsh-memu-memory'
|
|
@@ -117,6 +117,86 @@ window.__ModuleLoader__.load({
|
|
|
117
117
|
reviewConditions: '说明不同适用条件(至少 8 字)',
|
|
118
118
|
pageMemories: 'MemU 记忆',
|
|
119
119
|
descMemories: '跨库记忆、来源与状态',
|
|
120
|
+
pageGraph: '关系图谱',
|
|
121
|
+
descGraph: '力导向节点图:拖动即固定、弹簧链跟随',
|
|
122
|
+
graphCenter: '向心力',
|
|
123
|
+
graphPinned: '已固定',
|
|
124
|
+
graphUnpinAll: '解除全部固定',
|
|
125
|
+
graphRelayout: '重新布局',
|
|
126
|
+
graphPinHint: '左键拖动节点 · 右键锁定 / 解除 · Shift 拖整簇',
|
|
127
|
+
graphScopeHint: '拖动只影响所连的簇,其他簇保持不动',
|
|
128
|
+
gsManage: '管理',
|
|
129
|
+
gsSearch: '搜索节点 / 证据…',
|
|
130
|
+
gsRules: '规则筛选',
|
|
131
|
+
gsExport: '导出 PNG',
|
|
132
|
+
gsLegend: '图例',
|
|
133
|
+
gsForce: '力导向参数',
|
|
134
|
+
gsReset: '恢复默认',
|
|
135
|
+
gsCollapse: '折叠 / 展开检视面板',
|
|
136
|
+
gsGrid: '显示网格',
|
|
137
|
+
gsMinimap: '显示缩略图',
|
|
138
|
+
gsHelp: '快捷键',
|
|
139
|
+
gsFocusNode: '聚焦选中节点',
|
|
140
|
+
gsInspector: '检视面板',
|
|
141
|
+
gsInspectorHint: '面板独立滚动 · 不把整页撑成长列表',
|
|
142
|
+
gsNodes: '节点',
|
|
143
|
+
gsEdges: '边',
|
|
144
|
+
gsVisible: '可见',
|
|
145
|
+
gsAutoEdges: '自动边',
|
|
146
|
+
gsPending: '待确认',
|
|
147
|
+
gsRender: '渲染',
|
|
148
|
+
gsEmpty: '当前筛选下没有可显示的边',
|
|
149
|
+
gsAllLibraries: '全部记忆库',
|
|
150
|
+
gsGlobalEmpty: '全部记忆库还没有关联;先在 MemU 记忆里建立关系',
|
|
151
|
+
gsLocate: '图中定位',
|
|
152
|
+
gsNoSelection: '未选中节点',
|
|
153
|
+
gsLocalData: '插件数据',
|
|
154
|
+
gsThemeHint: '跟随宿主主题',
|
|
155
|
+
gsTitle: '标题',
|
|
156
|
+
gsKind: '类型',
|
|
157
|
+
gsStatus: '状态',
|
|
158
|
+
gsLayer: '层级',
|
|
159
|
+
gsConfirmed: '已确认',
|
|
160
|
+
gsNoRules: '当前没有带规则(evidence.rule)的边',
|
|
161
|
+
gsRuleAuto: '旧版自动',
|
|
162
|
+
gsRuleMention: '提及',
|
|
163
|
+
gsRuleConflict: '冲突',
|
|
164
|
+
gsRuleSupersede: '取代',
|
|
165
|
+
gsRuleFactKey: '同键',
|
|
166
|
+
gsRuleWorkerQuote: '引文',
|
|
167
|
+
gsAddNode: '新增节点',
|
|
168
|
+
gsEditNode: '编辑节点',
|
|
169
|
+
gsNodeMemory: '记忆',
|
|
170
|
+
gsNodeEntity: '实体',
|
|
171
|
+
gsRemoveNode: '删除节点',
|
|
172
|
+
gsRemoveNodeHint: '永久删除选中节点:记忆先归档再删除,实体连同其关联边一起删除',
|
|
173
|
+
gsNodeCreated: '已创建「{name}」',
|
|
174
|
+
gsNodeDeleted: '节点已删除',
|
|
175
|
+
gsAddLibrary: '目标记忆库',
|
|
176
|
+
gsDegree: '关联',
|
|
177
|
+
gsStrength: '强度',
|
|
178
|
+
gsAction: '操作',
|
|
179
|
+
gsAllKinds: '全部类型',
|
|
180
|
+
gsAllStatus: '全部状态',
|
|
181
|
+
gsSort: '排序方式',
|
|
182
|
+
gsNoMatch: '没有匹配的节点',
|
|
183
|
+
gsShortcuts: '+/− 缩放 · F 适应 · / 搜索 · 左键拖动 · 右键锁定/解除 · Shift 整簇 · 双击聚焦',
|
|
184
|
+
gsLegendMemory: '长期记忆',
|
|
185
|
+
gsLegendMust: '永久记忆',
|
|
186
|
+
gsLegendEntity: '已确认实体',
|
|
187
|
+
gsLegendPending: '待确认实体',
|
|
188
|
+
gsLegendGlobal: '全局记忆',
|
|
189
|
+
gsLegendMissing: '已删除',
|
|
190
|
+
gsLegendAuto: '自动边 · 实线',
|
|
191
|
+
gsLegendManual: '手动边 · 虚线',
|
|
192
|
+
gsHideNav: '收起左侧导航',
|
|
193
|
+
gsShowNav: '显示左侧导航',
|
|
194
|
+
gsBranch: '连接分支',
|
|
195
|
+
gsBranchHint: '查看所选节点的邻域、边类型与图中定位',
|
|
196
|
+
gsResize: '拖动调整面板宽度',
|
|
197
|
+
gsTier1: '一级邻域',
|
|
198
|
+
gsTier2: '二级邻域',
|
|
199
|
+
gsViewBranch: '查看分支',
|
|
120
200
|
pageLogs: '日志',
|
|
121
201
|
descLogs: '召回、写入、整理与向量的活动记录,可筛选、复制、下载',
|
|
122
202
|
logSearch: '搜索 id / 标题 / 错误',
|
|
@@ -190,6 +270,8 @@ window.__ModuleLoader__.load({
|
|
|
190
270
|
mergeReasonContainment: '名称包含',
|
|
191
271
|
mergeReasonDistance: '写法相近',
|
|
192
272
|
openMemu: '打开 MemU WebUI',
|
|
273
|
+
openGraphStudio: '打开关系图谱',
|
|
274
|
+
openGraphStudioHint: '在 WebUI 中打开完整关系图谱(浏览器拦下新标签页时在应用内打开)',
|
|
193
275
|
saved: '已保存',
|
|
194
276
|
copied: '已复制',
|
|
195
277
|
copyFailed: '复制失败,请手动选择文本',
|
|
@@ -253,6 +335,15 @@ window.__ModuleLoader__.load({
|
|
|
253
335
|
entityKind: '实体类型',
|
|
254
336
|
graphEmpty: '还没有关联',
|
|
255
337
|
graphAutoLink: '自动',
|
|
338
|
+
edgeFilterAll: '全部来源',
|
|
339
|
+
edgeFilterAuto: '仅自动',
|
|
340
|
+
edgeFilterManual: '仅手动',
|
|
341
|
+
purgeAutoLinks: '删除全部自动边',
|
|
342
|
+
purgeAutoConfirm: '确认删除自动边',
|
|
343
|
+
purgeAutoDone: '已删除 {n} 条自动边',
|
|
344
|
+
clearSuppression: '解除删除标记',
|
|
345
|
+
clearSuppressionConfirm: '确认解除删除标记',
|
|
346
|
+
clearSuppressionDone: '已解除 {n} 条删除标记',
|
|
256
347
|
deletedNode: '[已删除]',
|
|
257
348
|
graphLimited: '仅显示最多 200 个节点',
|
|
258
349
|
graphFit: '适应全图',
|
|
@@ -588,6 +679,9 @@ window.__ModuleLoader__.load({
|
|
|
588
679
|
memoryContent: '记忆内容',
|
|
589
680
|
add: '写入',
|
|
590
681
|
browserIndexOnly: '显示本地索引,正文以此为准。',
|
|
682
|
+
browseSearch: '搜索本库',
|
|
683
|
+
browseSearchPlaceholder: '按标题、正文、ID 或标签过滤当前记忆库…',
|
|
684
|
+
browseSearchClear: '清空',
|
|
591
685
|
// Enum display labels. Stored values stay English; only these flip with locale.
|
|
592
686
|
layerLongTerm: '长期记忆',
|
|
593
687
|
layerAnchor: '锚点记忆',
|
|
@@ -687,6 +781,11 @@ window.__ModuleLoader__.load({
|
|
|
687
781
|
privateCount: '私有记忆',
|
|
688
782
|
pinned: '永久记忆',
|
|
689
783
|
bound: '绑定对话',
|
|
784
|
+
consolidateNow: '手动整理',
|
|
785
|
+
consolidateHint: '为本库绑定的对话发起整理(与侧边栏同一通道,每次最多 5 个,正在整理的会跳过)。整理会产生模型调用成本。',
|
|
786
|
+
consolidateNone: '该库没有可整理的绑定对话',
|
|
787
|
+
consolidateDone: '已发起整理 {started} 个对话(正在整理 {running},失败 {failed}){rest}',
|
|
788
|
+
consolidateRest: ',还有 {n} 个可再点一次',
|
|
690
789
|
globalMemory: '全局记忆',
|
|
691
790
|
prompts: '提示词',
|
|
692
791
|
promptCustom: '自定义',
|
|
@@ -820,6 +919,29 @@ window.__ModuleLoader__.load({
|
|
|
820
919
|
orphanEntities: '未关联实体 ({n})',
|
|
821
920
|
orphanPruneHint: '这些实体没有被任何记忆或关系引用,插件下次启动时会自动清理。',
|
|
822
921
|
entityEmpty: '这个词库还没有实体。',
|
|
922
|
+
// —— 自动关联:待确认实体(DESIGN §9.2/§10)——
|
|
923
|
+
anchorReviewTitle: '待确认实体',
|
|
924
|
+
anchorReviewHint: '统计只用来排候选,不会自动写边。只有你确认过的名字,才会把已有记忆里的提及连到它。',
|
|
925
|
+
anchorTier1: '有证据的候选',
|
|
926
|
+
anchorTier2: '仅统计特征(需复核)',
|
|
927
|
+
anchorConfirm: '确认',
|
|
928
|
+
anchorConfirmSelected: '确认选中({n})',
|
|
929
|
+
anchorPendingEntity: '待确认',
|
|
930
|
+
anchorExistingEntity: '已有实体',
|
|
931
|
+
anchorArchivedEntity: '已归档',
|
|
932
|
+
anchorNoCandidates: '没有新的候选。',
|
|
933
|
+
anchorCreateHint: '确认后会建成实体,并立即给已有记忆补挂提及边。',
|
|
934
|
+
anchorKindHint: '类型随确认一起定下,之后不能修改。',
|
|
935
|
+
anchorConfirmedDone: '已确认 {n} 个实体,提及边已补挂。',
|
|
936
|
+
anchorSignalQuote: '引号',
|
|
937
|
+
anchorSignalIntro: '引导语',
|
|
938
|
+
anchorSignalMixed: '标识符',
|
|
939
|
+
anchorStats: 'df {df} · 凝聚 {cohesion} · 边界 {freedom}',
|
|
940
|
+
autoLinkMode: '自动关联',
|
|
941
|
+
autoLinkSuggest: '只出候选(推荐)',
|
|
942
|
+
autoLinkDeterministic: '确定性写边',
|
|
943
|
+
autoLinkOff: '关闭',
|
|
944
|
+
autoLinkHint: '“只出候选”不会写任何边;“确定性写边”只写两类边:已确认实体的提及,以及 conflicts_with / supersedes / 同 fact_key 的字段证据。词面相似度与向量永远不建边。',
|
|
823
945
|
firstRunTitle: '先建一个记忆库',
|
|
824
946
|
firstRunDesc: '还没有任何记忆库。新建一个私有库后,会话里的记忆才有地方落。',
|
|
825
947
|
firstRunGoLibraries: '去新建库',
|
|
@@ -934,6 +1056,86 @@ window.__ModuleLoader__.load({
|
|
|
934
1056
|
reviewConditions: 'Explain distinct conditions (at least 8 characters)',
|
|
935
1057
|
pageMemories: 'MemU Memory',
|
|
936
1058
|
descMemories: 'Memories, provenance and status across libraries',
|
|
1059
|
+
pageGraph: 'Relationship graph',
|
|
1060
|
+
descGraph: 'Force graph: drag to pin, spring-chain follow',
|
|
1061
|
+
graphCenter: 'Center force',
|
|
1062
|
+
graphPinned: 'Pinned',
|
|
1063
|
+
graphUnpinAll: 'Unpin all',
|
|
1064
|
+
graphRelayout: 'Re-layout',
|
|
1065
|
+
graphPinHint: 'Left-drag a node · right-click locks / unlocks · Shift drags the cluster',
|
|
1066
|
+
graphScopeHint: 'Dragging only moves the connected cluster',
|
|
1067
|
+
gsManage: 'Manage',
|
|
1068
|
+
gsSearch: 'Search nodes / evidence…',
|
|
1069
|
+
gsRules: 'Rule filter',
|
|
1070
|
+
gsExport: 'Export PNG',
|
|
1071
|
+
gsLegend: 'Legend',
|
|
1072
|
+
gsForce: 'Force parameters',
|
|
1073
|
+
gsReset: 'Reset',
|
|
1074
|
+
gsCollapse: 'Toggle inspector',
|
|
1075
|
+
gsGrid: 'Show grid',
|
|
1076
|
+
gsMinimap: 'Show minimap',
|
|
1077
|
+
gsHelp: 'Shortcuts',
|
|
1078
|
+
gsFocusNode: 'Focus selected',
|
|
1079
|
+
gsInspector: 'Inspector',
|
|
1080
|
+
gsInspectorHint: 'Scrolls on its own · the page never becomes one long list',
|
|
1081
|
+
gsNodes: 'Nodes',
|
|
1082
|
+
gsEdges: 'Edges',
|
|
1083
|
+
gsVisible: 'Visible',
|
|
1084
|
+
gsAutoEdges: 'Auto edges',
|
|
1085
|
+
gsPending: 'Pending',
|
|
1086
|
+
gsRender: 'Render',
|
|
1087
|
+
gsEmpty: 'No edges match the current filter',
|
|
1088
|
+
gsAllLibraries: 'All libraries',
|
|
1089
|
+
gsGlobalEmpty: 'No links across all libraries yet; create relations in MemU memory first',
|
|
1090
|
+
gsLocate: 'Locate',
|
|
1091
|
+
gsNoSelection: 'No node selected',
|
|
1092
|
+
gsLocalData: 'Plugin data',
|
|
1093
|
+
gsThemeHint: 'Follows host theme',
|
|
1094
|
+
gsTitle: 'Title',
|
|
1095
|
+
gsKind: 'Kind',
|
|
1096
|
+
gsStatus: 'Status',
|
|
1097
|
+
gsLayer: 'Layer',
|
|
1098
|
+
gsConfirmed: 'Confirmed',
|
|
1099
|
+
gsNoRules: 'No edges carry evidence.rule yet',
|
|
1100
|
+
gsRuleAuto: 'Legacy auto',
|
|
1101
|
+
gsRuleMention: 'Mention',
|
|
1102
|
+
gsRuleConflict: 'Conflict',
|
|
1103
|
+
gsRuleSupersede: 'Superseded',
|
|
1104
|
+
gsRuleFactKey: 'Fact key',
|
|
1105
|
+
gsRuleWorkerQuote: 'Worker quote',
|
|
1106
|
+
gsAddNode: 'Add node',
|
|
1107
|
+
gsEditNode: 'Edit node',
|
|
1108
|
+
gsNodeMemory: 'Memory',
|
|
1109
|
+
gsNodeEntity: 'Entity',
|
|
1110
|
+
gsRemoveNode: 'Delete node',
|
|
1111
|
+
gsRemoveNodeHint: 'Permanently delete the selected node: memories are archived then deleted, entities are removed with their links',
|
|
1112
|
+
gsNodeCreated: 'Created "{name}"',
|
|
1113
|
+
gsNodeDeleted: 'Node deleted',
|
|
1114
|
+
gsAddLibrary: 'Target library',
|
|
1115
|
+
gsDegree: 'Links',
|
|
1116
|
+
gsStrength: 'Strength',
|
|
1117
|
+
gsAction: 'Action',
|
|
1118
|
+
gsAllKinds: 'All kinds',
|
|
1119
|
+
gsAllStatus: 'All statuses',
|
|
1120
|
+
gsSort: 'Sort by',
|
|
1121
|
+
gsNoMatch: 'No matching nodes',
|
|
1122
|
+
gsShortcuts: '+/- zoom · F fit · / search · left-drag moves · right-click locks/unlocks · Shift cluster · double-click focus',
|
|
1123
|
+
gsLegendMemory: 'Long-term memory',
|
|
1124
|
+
gsLegendMust: 'Must remember',
|
|
1125
|
+
gsLegendEntity: 'Confirmed entity',
|
|
1126
|
+
gsLegendPending: 'Provisional entity',
|
|
1127
|
+
gsLegendGlobal: 'Global memory',
|
|
1128
|
+
gsLegendMissing: 'Deleted',
|
|
1129
|
+
gsLegendAuto: 'Auto edge · solid',
|
|
1130
|
+
gsLegendManual: 'Manual edge · dashed',
|
|
1131
|
+
gsHideNav: 'Hide left nav',
|
|
1132
|
+
gsShowNav: 'Show left nav',
|
|
1133
|
+
gsBranch: 'Connected branch',
|
|
1134
|
+
gsBranchHint: 'Inspect neighbourhood, edge kinds and locate on canvas',
|
|
1135
|
+
gsResize: 'Drag to resize the panel',
|
|
1136
|
+
gsTier1: 'Direct neighbours',
|
|
1137
|
+
gsTier2: 'Second-degree neighbours',
|
|
1138
|
+
gsViewBranch: 'View branch',
|
|
937
1139
|
pageLogs: 'Logs',
|
|
938
1140
|
descLogs: 'Recall, writes, consolidation and vector activity; filter, copy or download',
|
|
939
1141
|
logSearch: 'Search id / title / error',
|
|
@@ -1007,6 +1209,8 @@ window.__ModuleLoader__.load({
|
|
|
1007
1209
|
mergeReasonContainment: 'Name contained',
|
|
1008
1210
|
mergeReasonDistance: 'Similar spelling',
|
|
1009
1211
|
openMemu: 'Open MemU WebUI',
|
|
1212
|
+
openGraphStudio: 'Open relationship graph',
|
|
1213
|
+
openGraphStudioHint: 'Open the full relationship graph in the WebUI (opens in-app when the browser blocks a new tab)',
|
|
1010
1214
|
saved: 'Saved',
|
|
1011
1215
|
copied: 'Copied',
|
|
1012
1216
|
copyFailed: 'Copy failed; select the text manually',
|
|
@@ -1070,6 +1274,15 @@ window.__ModuleLoader__.load({
|
|
|
1070
1274
|
entityKind: 'Entity kind',
|
|
1071
1275
|
graphEmpty: 'No connections yet',
|
|
1072
1276
|
graphAutoLink: 'Auto',
|
|
1277
|
+
edgeFilterAll: 'All sources',
|
|
1278
|
+
edgeFilterAuto: 'Auto only',
|
|
1279
|
+
edgeFilterManual: 'Manual only',
|
|
1280
|
+
purgeAutoLinks: 'Remove all auto edges',
|
|
1281
|
+
purgeAutoConfirm: 'Confirm removing auto edges',
|
|
1282
|
+
purgeAutoDone: 'Removed {n} auto edge(s)',
|
|
1283
|
+
clearSuppression: 'Clear deletion markers',
|
|
1284
|
+
clearSuppressionConfirm: 'Confirm clearing deletion markers',
|
|
1285
|
+
clearSuppressionDone: 'Cleared {n} deletion marker(s)',
|
|
1073
1286
|
deletedNode: '[deleted]',
|
|
1074
1287
|
graphLimited: 'Showing at most 200 nodes',
|
|
1075
1288
|
graphFit: 'Fit graph',
|
|
@@ -1405,6 +1618,9 @@ window.__ModuleLoader__.load({
|
|
|
1405
1618
|
memoryContent: 'Memory content',
|
|
1406
1619
|
add: 'Write',
|
|
1407
1620
|
browserIndexOnly: 'Showing the local index, the authoritative copy.',
|
|
1621
|
+
browseSearch: 'Search this library',
|
|
1622
|
+
browseSearchPlaceholder: 'Filter the current library by title, body, id or tags…',
|
|
1623
|
+
browseSearchClear: 'Clear',
|
|
1408
1624
|
layerLongTerm: 'Long-term',
|
|
1409
1625
|
layerAnchor: 'Anchor',
|
|
1410
1626
|
layerMustRemember: 'Permanent',
|
|
@@ -1503,6 +1719,11 @@ window.__ModuleLoader__.load({
|
|
|
1503
1719
|
privateCount: 'Private',
|
|
1504
1720
|
pinned: 'Permanent',
|
|
1505
1721
|
bound: 'Sessions',
|
|
1722
|
+
consolidateNow: 'Consolidate now',
|
|
1723
|
+
consolidateHint: 'Start consolidation for conversations bound to this library (same channel as the sidebar; up to 5 per click, ones already running are skipped). Consolidation costs model calls.',
|
|
1724
|
+
consolidateNone: 'No bound conversations to consolidate in this library',
|
|
1725
|
+
consolidateDone: 'Started {started} conversations ({running} already running, {failed} failed){rest}',
|
|
1726
|
+
consolidateRest: ' — {n} more, click again',
|
|
1506
1727
|
globalMemory: 'Global memory',
|
|
1507
1728
|
prompts: 'Prompts',
|
|
1508
1729
|
promptCustom: 'Custom',
|
|
@@ -1636,6 +1857,29 @@ window.__ModuleLoader__.load({
|
|
|
1636
1857
|
orphanEntities: 'Unlinked entities ({n})',
|
|
1637
1858
|
orphanPruneHint: 'No memory or relationship references these entities; the plugin cleans them up automatically at the next startup.',
|
|
1638
1859
|
entityEmpty: 'No entities in this library yet.',
|
|
1860
|
+
// —— Auto-link: entities awaiting confirmation (DESIGN §9.2/§10) ——
|
|
1861
|
+
anchorReviewTitle: 'Entities to confirm',
|
|
1862
|
+
anchorReviewHint: 'Statistics only rank the queue and never write edges. Only a name you confirm gets its existing memories connected.',
|
|
1863
|
+
anchorTier1: 'Evidenced candidates',
|
|
1864
|
+
anchorTier2: 'Statistical only (needs review)',
|
|
1865
|
+
anchorConfirm: 'Confirm',
|
|
1866
|
+
anchorConfirmSelected: 'Confirm selected ({n})',
|
|
1867
|
+
anchorPendingEntity: 'Pending',
|
|
1868
|
+
anchorExistingEntity: 'Existing entity',
|
|
1869
|
+
anchorArchivedEntity: 'Archived',
|
|
1870
|
+
anchorNoCandidates: 'No new candidates.',
|
|
1871
|
+
anchorCreateHint: 'Confirming creates the entity and immediately attaches mention edges to existing memories.',
|
|
1872
|
+
anchorKindHint: 'The kind is fixed at confirmation time and cannot be changed later.',
|
|
1873
|
+
anchorConfirmedDone: 'Confirmed {n} entit(ies); mention edges are attached.',
|
|
1874
|
+
anchorSignalQuote: 'Quoted',
|
|
1875
|
+
anchorSignalIntro: 'Name intro',
|
|
1876
|
+
anchorSignalMixed: 'Identifier',
|
|
1877
|
+
anchorStats: 'df {df} · cohesion {cohesion} · boundary {freedom}',
|
|
1878
|
+
autoLinkMode: 'Auto-linking',
|
|
1879
|
+
autoLinkSuggest: 'Candidates only (recommended)',
|
|
1880
|
+
autoLinkDeterministic: 'Deterministic edges',
|
|
1881
|
+
autoLinkOff: 'Off',
|
|
1882
|
+
autoLinkHint: '"Candidates only" writes no edges. "Deterministic edges" writes exactly two kinds: mentions of confirmed entities, and field evidence from conflicts_with / supersedes / the same fact_key. Lexical similarity and vectors never create an edge.',
|
|
1639
1883
|
firstRunTitle: 'Create a memory library first',
|
|
1640
1884
|
firstRunDesc: 'There are no libraries yet. Memories from your conversations need one to land in.',
|
|
1641
1885
|
firstRunGoLibraries: 'Create a library',
|
|
@@ -1872,6 +2116,251 @@ window.__ModuleLoader__.load({
|
|
|
1872
2116
|
.dshm-graph-unlink.is-armed{width:auto;padding:0 8px;font-size:11.5px;color:var(--dsw-alias-state-error-primary,#b43e45);background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#b43e45) 12%,transparent)}
|
|
1873
2117
|
@media (max-width:1100px){.dshm-graph-stage{grid-template-columns:minmax(0,1fr)}}
|
|
1874
2118
|
.dshm-graph-missing{opacity:.5}
|
|
2119
|
+
/* Graph Studio 工作台:按 graph-studio/index.html 的界面逐块复刻,尺寸按 WebUI 收敛,
|
|
2120
|
+
颜色全部走 --dsw-alias-* token,自动跟随宿主明暗。画布本身仍由 graph-view.js 绘制。 */
|
|
2121
|
+
.dshm-gs{--gs-panel:var(--dsw-alias-bg-layer-1,#fff);--gs-panel-2:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));--gs-border:var(--dsw-alias-border-l1,rgba(127,127,127,.20));--gs-border-soft:var(--dsw-alias-border-l2,rgba(127,127,127,.10));--gs-text:var(--dsw-alias-label-primary,#1a1e2b);--gs-dim:var(--dsw-alias-label-secondary,rgba(127,127,127,.9));--gs-faint:var(--dsw-alias-label-secondary,rgba(127,127,127,.65));--gs-accent:var(--dsw-alias-brand-primary,#3b5bdb);--gs-on-accent:var(--dsw-alias-brand-text,#fff);--gs-accent-soft:color-mix(in srgb,var(--gs-accent) 12%,transparent);--gs-radius:12px;--gs-radius-sm:8px;--gs-shadow:0 12px 32px rgba(20,30,60,.16);--gs-shadow-sm:0 3px 12px rgba(20,30,60,.12);
|
|
2122
|
+
display:grid;grid-template-columns:46px minmax(0,1fr) 344px;grid-template-rows:50px minmax(0,1fr) 28px;
|
|
2123
|
+
height:clamp(520px,calc(100vh - 210px),860px);min-height:420px;position:relative;overflow:hidden;
|
|
2124
|
+
border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--dsw-alias-bg-base,transparent);
|
|
2125
|
+
color:var(--gs-text);font-size:12px;line-height:1.5}
|
|
2126
|
+
.dshm-gs *{box-sizing:border-box;min-width:0}
|
|
2127
|
+
.dshm-gs button,.dshm-gs input,.dshm-gs select{font:inherit;color:inherit}
|
|
2128
|
+
.dshm-gs button{cursor:pointer}
|
|
2129
|
+
.dshm-gs.is-collapsed{grid-template-columns:46px minmax(0,1fr) 0}
|
|
2130
|
+
.dshm-gs.is-collapsed .dshm-gs-inspector{display:none}
|
|
2131
|
+
.dshm-gs.is-manage{grid-template-columns:0 minmax(0,1fr) 0}
|
|
2132
|
+
.dshm-gs.is-manage .dshm-gs-rail,.dshm-gs.is-manage .dshm-gs-stage,.dshm-gs.is-manage .dshm-gs-inspector,.dshm-gs.is-manage .dshm-gs-popwrap,.dshm-gs.is-manage .dshm-gs-themechip,.dshm-gs.is-manage .dshm-gs-icon{display:none!important}
|
|
2133
|
+
.dshm-gs.is-manage .dshm-gs-manager{display:flex}
|
|
2134
|
+
.dshm-gs-c-memory{background:#618fcd}.dshm-gs-c-must{background:#d97768}.dshm-gs-c-short{background:#8a93a6}
|
|
2135
|
+
.dshm-gs-c-entity{background:#36a582}.dshm-gs-c-provisional{background:#b9963f}.dshm-gs-c-global{background:#8b7bd8}.dshm-gs-c-missing{background:#92959c}
|
|
2136
|
+
/* topbar */
|
|
2137
|
+
.dshm-gs-topbar{grid-column:1/-1;grid-row:1;display:flex;align-items:center;gap:9px;padding:0 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel);z-index:20;min-width:0}
|
|
2138
|
+
.dshm-gs-brand{display:flex;align-items:center;gap:9px;flex-shrink:0}
|
|
2139
|
+
.dshm-gs-mark{width:28px;height:28px;border-radius:8px;display:grid;place-items:center;background:linear-gradient(140deg,var(--gs-accent),color-mix(in srgb,var(--gs-accent) 55%,#8b7bd8));color:var(--gs-on-accent);font-weight:750;font-size:14px;box-shadow:var(--gs-shadow-sm)}
|
|
2140
|
+
.dshm-gs-brand-txt strong{display:block;font-size:12.5px;font-weight:680;line-height:1.15;white-space:nowrap}
|
|
2141
|
+
.dshm-gs-brand-txt small{display:block;color:var(--gs-faint);font-size:9.5px;letter-spacing:.1em;text-transform:uppercase}
|
|
2142
|
+
.dshm-gs-divider{width:1px;height:20px;background:var(--gs-border);flex-shrink:0}
|
|
2143
|
+
.dshm-gs-seg{display:inline-flex;padding:2px;gap:2px;border:1px solid var(--gs-border);border-radius:999px;background:var(--gs-panel-2);flex-shrink:0}
|
|
2144
|
+
.dshm-gs-seg button{border:0;background:transparent;color:var(--gs-dim);font-size:11px;padding:3px 10px;border-radius:999px;white-space:nowrap;transition:.18s}
|
|
2145
|
+
.dshm-gs-seg button[aria-pressed=true]{background:var(--gs-accent);color:var(--gs-on-accent);font-weight:600}
|
|
2146
|
+
.dshm-gs-field{height:29px;padding:0 9px;border:1px solid var(--gs-border);background:var(--gs-panel-2);border-radius:var(--gs-radius-sm);outline:none;font-size:11.5px;max-width:100%}
|
|
2147
|
+
.dshm-gs-field:focus{border-color:var(--gs-accent);box-shadow:0 0 0 3px var(--gs-accent-soft)}
|
|
2148
|
+
.dshm-gs-search{position:relative;flex:1 1 160px;max-width:260px;min-width:90px}
|
|
2149
|
+
/* standalone.css 会给外壳输入框统一 padding/height;工作台的紧凑控件必须用更高
|
|
2150
|
+
特异性拉回自己的尺寸,否则搜索图标会压住文字、顶栏控件高度也不齐。 */
|
|
2151
|
+
.dshm-gs-search .dshm-gs-field{width:100%;padding-left:28px!important}
|
|
2152
|
+
.dshm-gs-search-icon{position:absolute;left:9px;top:0;bottom:0;display:flex;align-items:center;font-size:14px;line-height:1;color:var(--gs-faint);pointer-events:none}
|
|
2153
|
+
html[data-standalone] .dshm-root .dshm-gs .dshm-gs-topbar input.dshm-gs-field,
|
|
2154
|
+
html[data-standalone] .dshm-root .dshm-gs .dshm-gs-topbar select.dshm-gs-field,
|
|
2155
|
+
html[data-standalone] .dshm-root .dshm-gs .dshm-gs-mgr-head select.dshm-gs-field{height:29px!important;padding:0 9px!important;border-radius:var(--gs-radius-sm)!important;font-size:11.5px!important;background:var(--gs-panel-2)!important;border-color:var(--gs-border)!important}
|
|
2156
|
+
html[data-standalone] .dshm-root .dshm-gs .dshm-gs-search input.dshm-gs-field{padding:0 9px 0 28px!important}
|
|
2157
|
+
html[data-standalone] .dshm-root .dshm-gs .dshm-gs-forcepop input[type=range]{height:auto!important;padding:0!important;border:0!important;background:transparent!important}
|
|
2158
|
+
.dshm-gs-spacer{flex:1 1 auto}
|
|
2159
|
+
.dshm-gs-btn{height:29px;padding:0 11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius-sm);background:var(--gs-panel-2);font-size:11.5px;white-space:nowrap;display:inline-flex;align-items:center;gap:6px;transition:.18s}
|
|
2160
|
+
.dshm-gs-btn:hover{border-color:var(--gs-accent);color:var(--gs-accent)}
|
|
2161
|
+
.dshm-gs-btn.primary{background:var(--gs-accent);border-color:transparent;color:var(--gs-on-accent);font-weight:600}
|
|
2162
|
+
.dshm-gs-btn.icon{width:29px;padding:0;justify-content:center;font-size:14px}
|
|
2163
|
+
.dshm-gs-btn:disabled{opacity:.45;cursor:not-allowed}
|
|
2164
|
+
.dshm-gs-count{font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
|
|
2165
|
+
.dshm-gs-popwrap,.dshm-gs-legendwrap{position:relative;flex-shrink:0}
|
|
2166
|
+
.dshm-gs-pop,.dshm-gs-legendpop{position:absolute;top:38px;right:0;width:230px;padding:11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--gs-panel);box-shadow:var(--gs-shadow);z-index:60}
|
|
2167
|
+
.dshm-gs-pop h4,.dshm-gs-legendpop h4{margin:0 0 8px;font-size:10.5px;letter-spacing:.07em;text-transform:uppercase;color:var(--gs-faint);font-weight:650}
|
|
2168
|
+
.dshm-gs-pop label{display:flex;align-items:center;gap:8px;padding:4px 2px;font-size:11.5px;color:var(--gs-dim);cursor:pointer}
|
|
2169
|
+
.dshm-gs-pop input{accent-color:var(--gs-accent)}
|
|
2170
|
+
.dshm-gs-themechip{display:inline-flex;align-items:center;gap:6px;height:27px;padding:0 10px;border:1px solid var(--gs-border);border-radius:999px;background:var(--gs-panel-2);font-size:11px;color:var(--gs-dim);white-space:nowrap}
|
|
2171
|
+
.dshm-gs-dot{width:8px;height:8px;border-radius:50%;background:var(--gs-accent)}
|
|
2172
|
+
/* rail */
|
|
2173
|
+
.dshm-gs-rail{grid-column:1;grid-row:2;display:flex;flex-direction:column;align-items:center;gap:6px;padding:10px 0;border-right:1px solid var(--gs-border);background:var(--gs-panel-2);z-index:10}
|
|
2174
|
+
.dshm-gs-rail button{width:30px;height:30px;border:1px solid transparent;border-radius:var(--gs-radius-sm);background:transparent;color:var(--gs-dim);display:grid;place-items:center;font-size:14px;transition:.18s}
|
|
2175
|
+
.dshm-gs-rail button:hover{background:var(--gs-accent-soft);color:var(--gs-accent);border-color:var(--gs-border)}
|
|
2176
|
+
.dshm-gs-rail button[aria-pressed=true]{background:var(--gs-accent-soft);color:var(--gs-accent);border-color:var(--gs-accent)}
|
|
2177
|
+
.dshm-gs-rail-sep{width:20px;height:1px;background:var(--gs-border);margin:2px 0}
|
|
2178
|
+
.dshm-gs-rail-grow{flex:1}
|
|
2179
|
+
/* stage */
|
|
2180
|
+
.dshm-gs-stage{grid-column:2;grid-row:2;position:relative;min-width:0;min-height:0;overflow:hidden;background:var(--gs-panel)}
|
|
2181
|
+
.dshm-gs-stage .dshm-graph-viewport{position:absolute;inset:0;border:0;border-radius:0;background:transparent}
|
|
2182
|
+
.dshm-gs-stage .dshm-graph-canvas{width:100%;height:100%;max-height:none;min-height:0}
|
|
2183
|
+
.dshm-gs-canvas-tools{position:absolute;left:12px;bottom:12px;display:flex;align-items:flex-end;gap:8px;z-index:8}
|
|
2184
|
+
.dshm-gs-zoombar{display:flex;align-items:center;gap:2px;padding:3px;border:1px solid var(--gs-border);background:var(--gs-panel);border-radius:10px;box-shadow:var(--gs-shadow-sm);opacity:.72}
|
|
2185
|
+
.dshm-gs-canvas-tools:hover .dshm-gs-zoombar,.dshm-gs-zoombar:focus-within{opacity:1}
|
|
2186
|
+
.dshm-gs-zoombar button{width:24px;height:24px;border:0;background:transparent;color:var(--gs-dim);border-radius:7px;font-size:13px;display:grid;place-items:center}
|
|
2187
|
+
.dshm-gs-zoombar button:hover{background:var(--gs-accent-soft);color:var(--gs-accent)}
|
|
2188
|
+
.dshm-gs-zoomval{min-width:40px;text-align:center;font-size:10.5px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
|
|
2189
|
+
.dshm-gs-legendbtn{border:1px solid var(--gs-border);background:var(--gs-panel);color:var(--gs-dim);font-size:11px;padding:5px 9px;border-radius:9px;box-shadow:var(--gs-shadow-sm);opacity:.72}
|
|
2190
|
+
.dshm-gs-legendbtn:hover,.dshm-gs-canvas-tools:hover .dshm-gs-legendbtn{opacity:1;color:var(--gs-accent)}
|
|
2191
|
+
.dshm-gs-legendpop{bottom:calc(100% + 8px);left:0;top:auto;right:auto;width:210px;padding:10px 12px}
|
|
2192
|
+
.dshm-gs-legend-row{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--gs-dim);padding:2px 0}
|
|
2193
|
+
.dshm-gs-swatch{width:9px;height:9px;border-radius:50%;flex-shrink:0;display:inline-block}
|
|
2194
|
+
.dshm-gs-line{width:16px;height:0;border-top:2px solid var(--gs-accent);flex-shrink:0}
|
|
2195
|
+
.dshm-gs-line.dashed{border-top-style:dashed;border-color:var(--gs-faint)}
|
|
2196
|
+
.dshm-gs-minimap{position:absolute;right:12px;bottom:12px;padding:7px;border:1px solid var(--gs-border);background:var(--gs-panel);border-radius:var(--gs-radius);box-shadow:var(--gs-shadow-sm);z-index:6}
|
|
2197
|
+
.dshm-gs-minimap h4{margin:0 0 5px;font-size:9.5px;letter-spacing:.08em;text-transform:uppercase;color:var(--gs-faint)}
|
|
2198
|
+
.dshm-gs-minimap canvas{display:block;width:158px;height:104px;border-radius:6px}
|
|
2199
|
+
.dshm-gs-rail-slot{position:relative;display:flex;flex:none}
|
|
2200
|
+
.dshm-gs-forcepop{position:absolute;left:calc(100% + 8px);top:-6px;width:226px;padding:11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--gs-panel);box-shadow:var(--gs-shadow);z-index:40}
|
|
2201
|
+
.dshm-gs-forcepop h4{margin:0 0 6px;font-size:11px;font-weight:650}
|
|
2202
|
+
.dshm-gs-forcepop label{display:grid;grid-template-columns:56px 1fr 36px;align-items:center;gap:7px;padding:5px 0;font-size:11px;color:var(--gs-dim)}
|
|
2203
|
+
.dshm-gs-forcepop input[type=range]{width:100%;accent-color:var(--gs-accent);margin:0}
|
|
2204
|
+
.dshm-gs-forcepop output{font-size:10px;text-align:right;color:var(--gs-dim);font-variant-numeric:tabular-nums}
|
|
2205
|
+
.dshm-gs-forcepop-toggles{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:6px;padding-top:8px;border-top:1px solid var(--gs-border-soft)}
|
|
2206
|
+
.dshm-gs-mini{height:26px;padding:0 10px;font-size:11.5px;border-radius:7px;border:1px solid var(--gs-border);background:var(--gs-panel);white-space:nowrap;margin-top:8px}
|
|
2207
|
+
.dshm-gs-mini:hover{border-color:var(--gs-accent);color:var(--gs-accent)}
|
|
2208
|
+
.dshm-gs-forcepop .dshm-gs-mini{margin-top:9px}
|
|
2209
|
+
.dshm-gs-toast{position:absolute;left:50%;bottom:22px;transform:translate(-50%,10px);z-index:40;padding:8px 14px;border-radius:999px;background:var(--gs-text);color:var(--gs-panel);font-size:11.5px;box-shadow:var(--gs-shadow);opacity:0;transition:.25s;pointer-events:none;max-width:80%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2210
|
+
.dshm-gs-toast.show{opacity:1;transform:translate(-50%,0)}
|
|
2211
|
+
.dshm-gs-empty{position:absolute;inset:0;display:grid;place-items:center;color:var(--gs-dim);font-size:12px;pointer-events:none}
|
|
2212
|
+
/* inspector */
|
|
2213
|
+
.dshm-gs-inspector{grid-column:3;grid-row:2;display:flex;flex-direction:column;min-height:0;border-left:1px solid var(--gs-border);background:var(--gs-panel);z-index:10}
|
|
2214
|
+
.dshm-gs-ins-head{flex-shrink:0;padding:12px 14px 9px;border-bottom:1px solid var(--gs-border-soft)}
|
|
2215
|
+
.dshm-gs-ins-title{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
2216
|
+
.dshm-gs-ins-title h2{margin:0;font-size:12.5px;font-weight:680}
|
|
2217
|
+
.dshm-gs-ins-head p{margin:3px 0 0;font-size:10.5px;color:var(--gs-dim)}
|
|
2218
|
+
.dshm-gs-ins-body{flex:1;min-height:0;overflow-y:auto;padding:12px 14px 20px;display:flex;flex-direction:column;gap:12px}
|
|
2219
|
+
.dshm-gs-sec{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius);padding:11px;background:var(--gs-panel-2)}
|
|
2220
|
+
.dshm-gs-sec-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:9px}
|
|
2221
|
+
.dshm-gs-sec-head h3{margin:0;font-size:10.5px;letter-spacing:.06em;text-transform:uppercase;color:var(--gs-faint);font-weight:680}
|
|
2222
|
+
.dshm-gs-hero{display:flex;gap:10px;align-items:flex-start}
|
|
2223
|
+
.dshm-gs-glyph{width:34px;height:34px;border-radius:10px;display:grid;place-items:center;color:#fff;font-size:15px;flex-shrink:0;font-weight:700}
|
|
2224
|
+
.dshm-gs-hero-t h3{margin:1px 0 5px;font-size:13px;font-weight:670;line-height:1.35;overflow-wrap:anywhere}
|
|
2225
|
+
.dshm-gs-tags{display:flex;flex-wrap:wrap;gap:5px}
|
|
2226
|
+
.dshm-gs-tag{display:inline-flex;align-items:center;font-size:10px;padding:2px 8px;border-radius:999px;background:var(--gs-accent-soft);color:var(--gs-accent);white-space:nowrap;font-weight:600}
|
|
2227
|
+
.dshm-gs-tag.neutral{background:var(--gs-panel);border:1px solid var(--gs-border);color:var(--gs-dim);font-weight:500}
|
|
2228
|
+
.dshm-gs-tag.auto{background:var(--gs-accent-soft);color:var(--gs-accent)}
|
|
2229
|
+
.dshm-gs-tag.manual{background:transparent;border:1px dashed var(--gs-border);color:var(--gs-dim)}
|
|
2230
|
+
.dshm-gs-tag.warn{background:color-mix(in srgb,#b9963f 16%,transparent);color:#b9963f}
|
|
2231
|
+
.dshm-gs-kv{display:grid;grid-template-columns:auto 1fr;gap:5px 12px;margin:11px 0 0;font-size:11px}
|
|
2232
|
+
.dshm-gs-kv dt{color:var(--gs-dim)}
|
|
2233
|
+
.dshm-gs-kv dd{margin:0;text-align:right;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
|
|
2234
|
+
.dshm-gs-edge-list{display:flex;flex-direction:column;gap:7px}
|
|
2235
|
+
.dshm-gs-edge{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius-sm);padding:8px 9px;background:var(--gs-panel);cursor:pointer;transition:.18s}
|
|
2236
|
+
.dshm-gs-edge:hover{border-color:var(--gs-accent);transform:translateY(-1px)}
|
|
2237
|
+
.dshm-gs-edge-top{display:flex;align-items:center;justify-content:space-between;gap:6px}
|
|
2238
|
+
.dshm-gs-edge-arrow{font-size:11.5px;font-weight:600;overflow-wrap:anywhere;line-height:1.45}
|
|
2239
|
+
.dshm-gs-conf{font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
|
|
2240
|
+
.dshm-gs-why{margin:5px 0 0;font-size:10.5px;color:var(--gs-dim);line-height:1.5}
|
|
2241
|
+
.dshm-gs-meta{display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;align-items:center}
|
|
2242
|
+
.dshm-gs-stats{display:grid;grid-template-columns:repeat(2,1fr);gap:8px}
|
|
2243
|
+
.dshm-gs-stat{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius-sm);padding:9px 10px;background:var(--gs-panel)}
|
|
2244
|
+
.dshm-gs-stat b{display:block;font-size:17px;font-weight:680;line-height:1.2;font-variant-numeric:tabular-nums}
|
|
2245
|
+
.dshm-gs-stat span{font-size:10.5px;color:var(--gs-dim)}
|
|
2246
|
+
.dshm-gs-hintbox{font-size:11px;color:var(--gs-dim);line-height:1.65;padding:10px;border:1px dashed var(--gs-border);border-radius:var(--gs-radius-sm);background:var(--gs-panel-2)}
|
|
2247
|
+
.dshm-gs-fold>summary{cursor:pointer;font-size:11px;color:var(--gs-dim);list-style:none}
|
|
2248
|
+
.dshm-gs-fold>summary::-webkit-details-marker{display:none}
|
|
2249
|
+
.dshm-gs-fold>summary::before{content:'▸';font-size:10px;margin-right:6px}
|
|
2250
|
+
.dshm-gs-fold[open]>summary::before{content:'▾'}
|
|
2251
|
+
/* manager */
|
|
2252
|
+
.dshm-gs-manager{grid-column:2/-1;grid-row:2;display:none;flex-direction:column;min-width:0;min-height:0;background:var(--gs-panel);z-index:12}
|
|
2253
|
+
.dshm-gs-mgr-head{flex-shrink:0;display:flex;align-items:center;gap:8px;padding:9px 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel-2);flex-wrap:wrap}
|
|
2254
|
+
.dshm-gs-mgr-add{display:grid;grid-template-columns:170px auto minmax(220px,1fr) 150px max-content;gap:8px;padding:10px 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel-2);align-items:center}
|
|
2255
|
+
.dshm-gs-mgr-add .dshm-gs-field,.dshm-gs-mgr-add .dshm-gs-btn{height:32px;min-width:0}
|
|
2256
|
+
.dshm-gs-mgr-add .dshm-gs-seg{height:32px;align-items:center}
|
|
2257
|
+
.dshm-gs-mgr-add .dshm-gs-seg button{height:26px}
|
|
2258
|
+
.dshm-gs-mgr-add textarea.dshm-gs-field{grid-column:3 / 5;height:66px;padding:7px 9px;line-height:1.45;font-family:inherit;resize:vertical}
|
|
2259
|
+
.dshm-gs-add-actions{display:flex;gap:8px;align-items:center;justify-content:flex-end}
|
|
2260
|
+
.dshm-gs-mgr-add .dshm-gs-seg button:disabled{opacity:1;cursor:default}
|
|
2261
|
+
.dshm-gs-mgr-add .dshm-gs-field:disabled{opacity:.75;cursor:default}
|
|
2262
|
+
.dshm-gs-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
2263
|
+
.dshm-gs-btn.is-danger{color:var(--dsw-alias-state-error-primary,#c0392b);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c0392b) 55%,transparent)}
|
|
2264
|
+
.dshm-gs-mgr-scroll{flex:1;min-height:0;overflow:auto}
|
|
2265
|
+
.dshm-gs-mgr-thead,.dshm-gs-mgr-row{display:grid;grid-template-columns:26px 92px minmax(140px,1fr) 88px 88px 92px 58px 70px 156px;align-items:center;gap:8px;padding:0 14px;min-width:900px}
|
|
2266
|
+
.dshm-gs-mgr-ops{display:flex;gap:4px;flex-wrap:nowrap}
|
|
2267
|
+
.dshm-gs-mgr-thead{position:sticky;top:0;z-index:2;height:36px;background:var(--gs-panel-2);border-bottom:1px solid var(--gs-border);font-size:11px;letter-spacing:.05em;text-transform:uppercase;color:var(--gs-faint);font-weight:650}
|
|
2268
|
+
/* 表头必须与数据行同一种列内对齐,否则看起来整列错位 */
|
|
2269
|
+
.dshm-gs-mgr-thead>span{text-align:left}
|
|
2270
|
+
.dshm-gs-mgr-thead>span.num{text-align:right}
|
|
2271
|
+
.dshm-gs-mgr-row>span{text-align:left}
|
|
2272
|
+
.dshm-gs-mgr-row{height:42px;border-bottom:1px solid var(--gs-border-soft);font-size:12.5px;cursor:pointer}
|
|
2273
|
+
.dshm-gs-mgr-row:hover{background:var(--gs-accent-soft)}
|
|
2274
|
+
.dshm-gs-mgr-row.sel{background:var(--gs-accent-soft);box-shadow:inset 2px 0 0 var(--gs-accent)}
|
|
2275
|
+
.dshm-gs-mgr-id{font-family:ui-monospace,monospace;font-size:11px;color:var(--gs-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2276
|
+
.dshm-gs-mgr-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2277
|
+
.dshm-gs-mgr-row .num{text-align:right;font-variant-numeric:tabular-nums;color:var(--gs-dim)}
|
|
2278
|
+
.dshm-gs-mgr-row .dshm-gs-mini{margin:0}
|
|
2279
|
+
.dshm-gs-mgr-empty{padding:28px 16px;text-align:center;color:var(--gs-dim)}
|
|
2280
|
+
.dshm-gs-mgr-foot{flex-shrink:0;display:flex;align-items:center;gap:8px;padding:8px 12px;border-top:1px solid var(--gs-border);background:var(--gs-panel-2);font-size:11px;color:var(--gs-dim)}
|
|
2281
|
+
/* status */
|
|
2282
|
+
.dshm-gs-status{grid-column:1/-1;grid-row:3;display:flex;align-items:center;gap:12px;padding:0 12px;border-top:1px solid var(--gs-border);background:var(--gs-panel);font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden}
|
|
2283
|
+
.dshm-gs-status b{color:var(--gs-text);font-weight:650}
|
|
2284
|
+
.dshm-gs-status-sep{width:1px;height:11px;background:var(--gs-border)}
|
|
2285
|
+
.dshm-gs-status-right{margin-left:auto;overflow:hidden;text-overflow:ellipsis}
|
|
2286
|
+
.dshm-gs-live{display:inline-flex;align-items:center;gap:5px}
|
|
2287
|
+
.dshm-gs-live i{width:6px;height:6px;border-radius:50%;background:#36a582;box-shadow:0 0 0 3px color-mix(in srgb,#36a582 20%,transparent)}
|
|
2288
|
+
@media (max-width:1100px){
|
|
2289
|
+
.dshm-gs{grid-template-columns:46px minmax(0,1fr) 0}
|
|
2290
|
+
.dshm-gs-inspector{position:absolute;top:50px;right:0;bottom:28px;width:340px;box-shadow:var(--gs-shadow);z-index:25}
|
|
2291
|
+
.dshm-gs.is-collapsed .dshm-gs-inspector{display:none}
|
|
2292
|
+
.dshm-gs-search{max-width:160px}
|
|
2293
|
+
.dshm-gs-brand-txt small,.dshm-gs-themechip{display:none}
|
|
2294
|
+
}
|
|
2295
|
+
@media (max-width:760px){
|
|
2296
|
+
.dshm-gs,.dshm-gs.is-collapsed,.dshm-gs.is-manage{grid-template-columns:minmax(0,1fr);grid-template-rows:50px 38px minmax(0,1fr) 28px}
|
|
2297
|
+
.dshm-gs-topbar{grid-column:1;grid-row:1}
|
|
2298
|
+
.dshm-gs-rail{grid-column:1;grid-row:2;flex-direction:row;justify-content:flex-start;padding:4px 8px;gap:4px;overflow-x:auto;border-right:0;border-bottom:1px solid var(--gs-border)}
|
|
2299
|
+
.dshm-gs-rail-sep{width:1px;height:20px;margin:0 2px}
|
|
2300
|
+
.dshm-gs-rail-grow{display:none}
|
|
2301
|
+
.dshm-gs-stage,.dshm-gs-manager{grid-column:1;grid-row:3}
|
|
2302
|
+
.dshm-gs-status{grid-column:1;grid-row:4}
|
|
2303
|
+
.dshm-gs-inspector{top:88px;width:min(300px,92vw)}
|
|
2304
|
+
.dshm-gs-search,.dshm-gs-divider,.dshm-gs-popwrap{display:none}
|
|
2305
|
+
.dshm-gs-mgr-thead,.dshm-gs-mgr-row{grid-template-columns:20px 58px minmax(90px,1fr) 70px 64px 130px;min-width:500px}
|
|
2306
|
+
.dshm-gs-mgr-thead span:nth-child(6),.dshm-gs-mgr-row>span:nth-child(6),.dshm-gs-mgr-thead span:nth-child(7),.dshm-gs-mgr-row>span:nth-child(7),.dshm-gs-mgr-thead span:nth-child(8),.dshm-gs-mgr-row>span:nth-child(8){display:none}
|
|
2307
|
+
}
|
|
2308
|
+
/* 管理视图的可调「连接分支」侧栏 */
|
|
2309
|
+
.dshm-gs-mgr-body{flex:1;min-height:0;display:flex;position:relative}
|
|
2310
|
+
.dshm-gs-mgr-body .dshm-gs-mgr-scroll{flex:1;min-width:0}
|
|
2311
|
+
.dshm-gs-br-resizer{width:5px;flex:0 0 5px;cursor:col-resize;background:var(--gs-border);border:0;padding:0}
|
|
2312
|
+
.dshm-gs-br-resizer:hover{background:var(--gs-accent)}
|
|
2313
|
+
.dshm-gs-branch{width:var(--gs-br-w,360px);flex:0 0 var(--gs-br-w,360px);background:var(--gs-panel);overflow:hidden;display:flex;flex-direction:column;border-left:1px solid var(--gs-border)}
|
|
2314
|
+
.dshm-gs-br-head{flex-shrink:0;padding:11px 13px 9px;border-bottom:1px solid var(--gs-border-soft)}
|
|
2315
|
+
.dshm-gs-br-head h3{margin:0 0 2px;font-size:12px;font-weight:680}
|
|
2316
|
+
.dshm-gs-br-head p{margin:0;font-size:10.5px;color:var(--gs-faint);line-height:1.5}
|
|
2317
|
+
.dshm-gs-br-body{flex:1;min-height:0;overflow-y:auto}
|
|
2318
|
+
.dshm-gs-br-hero{display:flex;gap:9px;align-items:flex-start;padding:11px 13px;border-bottom:1px solid var(--gs-border-soft)}
|
|
2319
|
+
.dshm-gs-br-hero .dshm-gs-glyph{width:28px;height:28px;font-size:13px;flex-shrink:0}
|
|
2320
|
+
.dshm-gs-br-hero .dshm-gs-hero-t{min-width:0;flex:1}
|
|
2321
|
+
.dshm-gs-br-hero .dshm-gs-hero-t b{display:block;font-size:12px;line-height:1.4;overflow-wrap:anywhere}
|
|
2322
|
+
.dshm-gs-br-hero .dshm-gs-hero-t span{display:block;margin-top:3px;font-size:10px;color:var(--gs-dim)}
|
|
2323
|
+
.dshm-gs-br-sec{padding:9px 13px}
|
|
2324
|
+
.dshm-gs-br-sec h4{margin:0 0 7px;font-size:10px;letter-spacing:.06em;text-transform:uppercase;color:var(--gs-faint)}
|
|
2325
|
+
.dshm-gs-br-item{display:flex;align-items:flex-start;gap:8px;padding:6px 0;border-bottom:1px solid var(--gs-border-soft)}
|
|
2326
|
+
.dshm-gs-br-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;margin-top:4px}
|
|
2327
|
+
.dshm-gs-br-col{min-width:0;flex:1}
|
|
2328
|
+
.dshm-gs-br-nm{font-size:11.5px;line-height:1.45;overflow-wrap:anywhere;cursor:pointer}
|
|
2329
|
+
.dshm-gs-br-nm:hover{color:var(--gs-accent);text-decoration:underline}
|
|
2330
|
+
.dshm-gs-br-meta{font-size:10px;color:var(--gs-faint);line-height:1.45;overflow-wrap:anywhere}
|
|
2331
|
+
.dshm-gs-br-item .dshm-gs-mini{flex-shrink:0;margin-top:0}
|
|
2332
|
+
.dshm-gs-br-empty{padding:26px 16px;text-align:center;color:var(--gs-dim);font-size:11.5px}
|
|
2333
|
+
@media (max-width:760px){.dshm-gs-branch,.dshm-gs-br-resizer{display:none}}
|
|
2334
|
+
/* 关系图谱是沉浸式页面:解除 980px/1180px 宽度锁,可一键收起 WebUI 左导航腾满宽度 */
|
|
2335
|
+
.dshm-root.is-graph-wide{padding:0}
|
|
2336
|
+
.dshm-root.is-graph-wide .dshm-head{display:none}
|
|
2337
|
+
.dshm-root.is-graph-wide .dshm-page{gap:0;min-height:0}
|
|
2338
|
+
.dshm-root.is-graph-wide .dshm-gs{border:1px solid var(--gs-border);border-radius:var(--gs-radius);height:calc(100dvh - 96px);min-height:560px;box-shadow:var(--gs-shadow-sm)}
|
|
2339
|
+
/* 贴在左导航右边缘的收起小块;收起后导航缩成 20px 窄条,把手本身始终可见 */
|
|
2340
|
+
.dshm-root.is-graph-wide .dshm-nav-handle{position:absolute;right:0;top:50%;transform:translateY(-50%);width:20px;height:56px;display:grid;place-items:center;border:1px solid var(--gs-border);border-right:0;border-radius:8px 0 0 8px;background:var(--gs-panel);color:var(--gs-dim);font-size:15px;z-index:30;box-shadow:var(--gs-shadow-sm)}
|
|
2341
|
+
.dshm-root.is-graph-wide .dshm-nav-handle:hover{color:var(--gs-accent);border-color:var(--gs-accent)}
|
|
2342
|
+
/* 收起/展开要有过渡;窄条状态下隐藏外壳的“记忆工作室”竖排小字 */
|
|
2343
|
+
.dshm-root.is-graph-wide .dshm-nav{transition:width .22s ease,min-width .22s ease,padding .22s ease}
|
|
2344
|
+
.dshm-root.is-graph-wide .dshm-shell{transition:grid-template-columns .22s ease}
|
|
2345
|
+
html[data-standalone] .stage{transition:padding-left .22s ease,padding-right .22s ease}
|
|
2346
|
+
/* 关系图谱独占一屏:内容区只留 8px 呼吸,隐藏外壳 footer,工作台整体上移并加高 */
|
|
2347
|
+
html[data-standalone]:has(.dshm-root.is-graph-wide) .stage{padding-top:8px;padding-bottom:8px}
|
|
2348
|
+
html[data-standalone]:has(.dshm-root.is-graph-wide) .foot{display:none}
|
|
2349
|
+
.dshm-root.is-graph-navless .dshm-nav::before{display:none}
|
|
2350
|
+
/* 宿主内嵌:左导航是 grid 的一列,收起后只剩窄条 */
|
|
2351
|
+
.dshm-root.is-graph-wide .dshm-shell{display:grid;max-width:none;gap:0;grid-template-columns:158px minmax(0,1fr);align-items:stretch;width:100%}
|
|
2352
|
+
.dshm-root.is-graph-navless .dshm-shell{grid-template-columns:20px minmax(0,1fr)}
|
|
2353
|
+
.dshm-root.is-graph-navless .dshm-nav{display:flex;width:20px;min-width:20px;padding:0;overflow:visible}
|
|
2354
|
+
.dshm-root.is-graph-navless .dshm-nav>*:not(.dshm-nav-handle){display:none}
|
|
2355
|
+
.dshm-root.is-graph-navless .dshm-nav-handle{border-right:1px solid var(--gs-border);border-radius:0}
|
|
2356
|
+
/* 独立 WebUI:外壳本来是 block + 固定左栏,只需解除内容列上限 */
|
|
2357
|
+
html[data-standalone] .dshm-root.is-graph-wide .dshm-shell{display:block;max-width:none}
|
|
2358
|
+
html[data-standalone] .dshm-root.is-graph-wide .dshm-page{max-width:none;margin:0}
|
|
2359
|
+
html[data-standalone] .dshm-root.is-graph-navless .dshm-nav{width:20px;min-width:20px;padding:0;overflow:visible}
|
|
2360
|
+
html[data-standalone]:has(.dshm-root.is-graph-navless) .stage{padding-left:28px;padding-right:16px}
|
|
2361
|
+
.dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-shell{display:flex;flex-direction:column;height:100%;min-height:0;max-width:none}
|
|
2362
|
+
.dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-page{flex:1;min-height:0;overflow:hidden}
|
|
2363
|
+
.dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-gs{height:100%;min-height:0}
|
|
1875
2364
|
/* The sidebar's context-scope form: a collapsed card instead of four bare
|
|
1876
2365
|
inputs and a browser-default button. */
|
|
1877
2366
|
.dshm-scope{width:100%;margin:0 0 10px;border:1px solid var(--dsw-alias-border-l1,#ddd);border-radius:12px;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.05));overflow:hidden;flex-shrink:0}
|
|
@@ -2624,17 +3113,23 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2624
3113
|
return graphModulePromise
|
|
2625
3114
|
}
|
|
2626
3115
|
|
|
2627
|
-
|
|
3116
|
+
// chrome=false 时外壳(rail / 参数弹层 / 状态栏)由 Graph Studio 工作台自己画,
|
|
3117
|
+
// 画布与引擎保持同一份实现:拖动、pin、弹簧链、簇作用域都不变。
|
|
3118
|
+
function GraphCanvas({ graph, focus, onFocus, t, chrome = true, options: controlledOptions = null,
|
|
3119
|
+
apiRef = null, onZoom = null, paintRef = null }) {
|
|
2628
3120
|
const ref = React.useRef(null)
|
|
2629
3121
|
const tooltipRef = React.useRef(null)
|
|
2630
3122
|
const viewRef = React.useRef(null)
|
|
2631
3123
|
const latest = React.useRef({ graph, focus, onFocus, t })
|
|
2632
3124
|
latest.current = { graph, focus, onFocus, t }
|
|
3125
|
+
const zoomNotify = React.useRef(onZoom)
|
|
3126
|
+
zoomNotify.current = onZoom
|
|
2633
3127
|
const [zoom, setZoom] = React.useState(1)
|
|
2634
3128
|
const [settingsOpen, setSettingsOpen] = React.useState(false)
|
|
2635
|
-
const [options, setOptions] = React.useState({ repulsion: 120, distance: 100, labels: true, motion: true })
|
|
2636
|
-
const
|
|
2637
|
-
optionsRef
|
|
3129
|
+
const [options, setOptions] = React.useState({ repulsion: 120, distance: 100, center: 0, labels: true, motion: true })
|
|
3130
|
+
const effectiveOptions = controlledOptions || options
|
|
3131
|
+
const optionsRef = React.useRef(effectiveOptions)
|
|
3132
|
+
optionsRef.current = effectiveOptions
|
|
2638
3133
|
const [loadError, setLoadError] = React.useState(false)
|
|
2639
3134
|
const [attempt, setAttempt] = React.useState(0)
|
|
2640
3135
|
React.useEffect(() => {
|
|
@@ -2646,41 +3141,64 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2646
3141
|
if (disposed) return
|
|
2647
3142
|
const view = module.createGraphView(canvas, {
|
|
2648
3143
|
onFocus: id => latest.current.onFocus(id),
|
|
2649
|
-
onZoom: setZoom,
|
|
3144
|
+
onZoom: value => { setZoom(value); zoomNotify.current?.(value) },
|
|
3145
|
+
// 主画布每重绘一次计一格:缩略图只在计数变化时才拷贝,空闲期零开销。
|
|
3146
|
+
onPaint: () => { if (paintRef) paintRef.current = (paintRef.current || 0) + 1 },
|
|
2650
3147
|
tooltip: tooltipRef.current,
|
|
2651
3148
|
reducedMotion: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
|
|
2652
3149
|
emptyLabel: latest.current.t('graphEmpty'),
|
|
2653
3150
|
})
|
|
2654
3151
|
viewRef.current = view
|
|
3152
|
+
// 只读句柄:浏览器验收与状态栏需要问「现在有几个节点被右键锁定」。
|
|
3153
|
+
canvas.__dshmGraphView = view
|
|
2655
3154
|
view.configure(optionsRef.current)
|
|
2656
3155
|
view.update(latest.current.graph, latest.current.focus)
|
|
2657
3156
|
}).catch(() => { if (!disposed) setLoadError(true) })
|
|
2658
3157
|
return () => {
|
|
2659
3158
|
disposed = true
|
|
2660
3159
|
viewRef.current?.dispose(); viewRef.current = null
|
|
3160
|
+
try { delete canvas.__dshmGraphView } catch {}
|
|
2661
3161
|
}
|
|
2662
3162
|
}, [attempt])
|
|
2663
3163
|
React.useEffect(() => { viewRef.current?.update(graph, focus) }, [graph, focus])
|
|
2664
|
-
React.useEffect(() => { viewRef.current?.configure(
|
|
3164
|
+
React.useEffect(() => { viewRef.current?.configure(effectiveOptions) }, [effectiveOptions])
|
|
3165
|
+
React.useEffect(() => {
|
|
3166
|
+
if (!apiRef) return undefined
|
|
3167
|
+
apiRef.current = {
|
|
3168
|
+
zoom: factor => viewRef.current?.zoom(factor),
|
|
3169
|
+
fit: () => viewRef.current?.fit(),
|
|
3170
|
+
unpinAll: () => viewRef.current?.unpinAll?.(),
|
|
3171
|
+
relayout: () => viewRef.current?.relayout?.(),
|
|
3172
|
+
exportPng: () => ref.current?.toDataURL?.('image/png') || '',
|
|
3173
|
+
}
|
|
3174
|
+
return () => { apiRef.current = null }
|
|
3175
|
+
}, [apiRef])
|
|
2665
3176
|
const icon = (label, text, action, extra = {}) => h('button', {
|
|
2666
3177
|
type: 'button', className: 'dshm-graph-icon', title: t(label), 'aria-label': t(label), onClick: action, ...extra,
|
|
2667
3178
|
}, text)
|
|
2668
3179
|
return h('div', { className: 'dshm-graph-viewport' },
|
|
2669
|
-
h('div', { className: 'dshm-graph-toolbar' },
|
|
3180
|
+
chrome ? h('div', { className: 'dshm-graph-toolbar' },
|
|
2670
3181
|
icon('graphZoomOut', '-', () => viewRef.current?.zoom(.8)),
|
|
2671
3182
|
h('output', { className: 'dshm-graph-scale', 'aria-label': t('graphView') }, Math.round(zoom * 100) + '%'),
|
|
2672
3183
|
icon('graphZoomIn', '+', () => viewRef.current?.zoom(1.25)),
|
|
2673
3184
|
icon('graphFit', '⛶', () => viewRef.current?.fit()),
|
|
2674
|
-
icon('
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
3185
|
+
icon('graphUnpinAll', '⊙', () => viewRef.current?.unpinAll?.()),
|
|
3186
|
+
icon('graphRelayout', '↻', () => viewRef.current?.relayout?.()),
|
|
3187
|
+
icon('graphOptions', h(GlyphSliders), () => setSettingsOpen(value => !value), { 'aria-expanded': settingsOpen })) : null,
|
|
3188
|
+
chrome && settingsOpen ? h('div', { className: 'dshm-graph-options' },
|
|
3189
|
+
[['repulsion', 'graphRepulsion', 30, 350, 5], ['distance', 'graphDistance', 40, 220, 5],
|
|
3190
|
+
['center', 'graphCenter', 0, 3, .05]].map(([key, label, min, max, step]) =>
|
|
3191
|
+
h('label', { key }, t(label), h('input', { type: 'range', min, max, step, value: options[key],
|
|
3192
|
+
'aria-label': t(label), title: t(label),
|
|
2678
3193
|
onChange: event => setOptions(value => ({ ...value, [key]: Number(event.target.value) })) }))),
|
|
2679
3194
|
[['labels', 'graphLabels'], ['motion', 'graphMotion']].map(([key, label]) =>
|
|
2680
3195
|
h('div', { key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10 } },
|
|
2681
3196
|
h('span', null, t(label)),
|
|
2682
3197
|
h(Toggle, { checked: options[key] === true, label: t(label),
|
|
2683
|
-
onChange: value => setOptions(current => ({ ...current, [key]: value })) })))
|
|
3198
|
+
onChange: value => setOptions(current => ({ ...current, [key]: value })) }))),
|
|
3199
|
+
h('div', { className: 'dshm-graph-actions' },
|
|
3200
|
+
h(Button, { title: t('graphUnpinAll'), onClick: () => viewRef.current?.unpinAll?.() }, t('graphUnpinAll')),
|
|
3201
|
+
h(Button, { title: t('graphRelayout'), onClick: () => viewRef.current?.relayout?.() }, t('graphRelayout')))) : null,
|
|
2684
3202
|
h('canvas', { ref, className: 'dshm-graph-canvas', role: 'img', tabIndex: 0, 'aria-label': t('graphView') }),
|
|
2685
3203
|
h('div', { ref: tooltipRef, className: 'dshm-graph-tooltip', hidden: true, 'aria-hidden': true }),
|
|
2686
3204
|
loadError ? h('div', { className: 'dshm-graph-error', role: 'alert' },
|
|
@@ -2738,6 +3256,698 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2738
3256
|
// 关系图的库选择器里,全局记忆不是一个私有库;用一个不可能与库 id 冲突的
|
|
2739
3257
|
// 占位值走同一套选择控件,避免再加一排 scope 按钮。
|
|
2740
3258
|
const GLOBAL_GRAPH_ID = '__global__'
|
|
3259
|
+
// Graph Studio 工作台:界面按 graph-studio/index.html 逐块复刻(顶栏 / 竖排工具 /
|
|
3260
|
+
// 画布浮动控件 / 检视面板 / 管理表格 / 状态栏),尺寸按 WebUI 收敛、颜色走 DSH
|
|
3261
|
+
// token 跟随宿主明暗。数据仍走插件 getGraph/listEntities,画布仍是 GraphCanvas +
|
|
3262
|
+
// 自研引擎,所以节点连接、拖动即固定、弹簧链、簇作用域这些手感一个都没改。
|
|
3263
|
+
const GS_NODE_COLORS = Object.freeze({
|
|
3264
|
+
memory: '#618fcd', must: '#d97768', short: '#8a93a6', entity: '#36a582',
|
|
3265
|
+
provisional: '#b9963f', global: '#8b7bd8', missing: '#92959c',
|
|
3266
|
+
})
|
|
3267
|
+
const gsKind = node => node.missing ? 'missing'
|
|
3268
|
+
: node.kind === 'global' ? 'global'
|
|
3269
|
+
: node.kind !== 'memory' ? (node.status === 'provisional' ? 'provisional' : 'entity') : 'memory'
|
|
3270
|
+
const gsColor = node => GS_NODE_COLORS[gsKind(node)]
|
|
3271
|
+
|
|
3272
|
+
function GraphStudioMinimap({ active, t, paintRef = null }) {
|
|
3273
|
+
const ref = React.useRef(null)
|
|
3274
|
+
React.useEffect(() => {
|
|
3275
|
+
if (!active || typeof document === 'undefined') return undefined
|
|
3276
|
+
let last = -1
|
|
3277
|
+
const paint = () => {
|
|
3278
|
+
const target = ref.current
|
|
3279
|
+
if (!target?.getContext) return
|
|
3280
|
+
// 主画布这一帧没重绘就不拷贝:空闲期缩略图不再每秒拷三次大画布纹理。
|
|
3281
|
+
if (paintRef) {
|
|
3282
|
+
const tick = paintRef.current || 0
|
|
3283
|
+
if (tick === last) return
|
|
3284
|
+
last = tick
|
|
3285
|
+
}
|
|
3286
|
+
const source = document.querySelector('.dshm-gs-stage canvas.dshm-graph-canvas')
|
|
3287
|
+
const context = target.getContext('2d')
|
|
3288
|
+
if (!source || !context) return
|
|
3289
|
+
context.clearRect(0, 0, target.width, target.height)
|
|
3290
|
+
try { context.drawImage(source, 0, 0, target.width, target.height) } catch {}
|
|
3291
|
+
}
|
|
3292
|
+
paint()
|
|
3293
|
+
const timer = setInterval(paint, 600)
|
|
3294
|
+
return () => clearInterval(timer)
|
|
3295
|
+
}, [active])
|
|
3296
|
+
return h('div', { className: 'dshm-gs-minimap' },
|
|
3297
|
+
h('h4', null, t('gsMinimap')),
|
|
3298
|
+
h('canvas', { ref, width: 158, height: 104, 'aria-label': t('gsMinimap') }))
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
// 规则筛选读显示层 rule。老版本插件的自动边没有 evidence.rule(handoff: 旧
|
|
3302
|
+
// suppression 键就是 'auto'),这里按 source==='auto' 兜底成 'auto' 桶——
|
|
3303
|
+
// 这样新客户端配旧后端/旧数据也不会出现「一条规则都没有」;新写入带真实规则。
|
|
3304
|
+
const GS_RULE_LABEL_KEYS = Object.freeze({
|
|
3305
|
+
'entity-mention': 'gsRuleMention', conflict: 'gsRuleConflict', supersede: 'gsRuleSupersede',
|
|
3306
|
+
'fact-key': 'gsRuleFactKey', 'worker-quote': 'gsRuleWorkerQuote', auto: 'gsRuleAuto',
|
|
3307
|
+
})
|
|
3308
|
+
const graphRuleOf = edge => edge.rule || (edge.source === 'auto' ? 'auto' : null)
|
|
3309
|
+
const graphRuleText = (rule, t) => GS_RULE_LABEL_KEYS[rule] ? t(GS_RULE_LABEL_KEYS[rule]) : String(rule)
|
|
3310
|
+
|
|
3311
|
+
function GraphStudioPanel({ call, libraries, revision, stamp, t, navHidden = false, onToggleNav = null }) {
|
|
3312
|
+
const [graphLib, setGraphLib] = React.useState('')
|
|
3313
|
+
// 默认落在有数据的私有库:全局图常常是空的,一进页面就空白会让人以为图坏了。
|
|
3314
|
+
const firstPrivate = libraries[0]?.id || ''
|
|
3315
|
+
const graphLibrary = graphLib === GLOBAL_GRAPH_ID ? GLOBAL_GRAPH_ID
|
|
3316
|
+
: (graphLib && libraries.some(lib => lib.id === graphLib) ? graphLib : (firstPrivate || GLOBAL_GRAPH_ID))
|
|
3317
|
+
const showGlobal = graphLibrary === GLOBAL_GRAPH_ID
|
|
3318
|
+
const [graph, setGraph] = React.useState({ nodes: [], edges: [] })
|
|
3319
|
+
const [entities, setEntities] = React.useState([])
|
|
3320
|
+
const [focus, setFocus] = React.useState('')
|
|
3321
|
+
const [error, setError] = React.useState('')
|
|
3322
|
+
const [view, setView] = React.useState('graph')
|
|
3323
|
+
const [query, setQuery] = React.useState('')
|
|
3324
|
+
const [source, setSource] = React.useState('all')
|
|
3325
|
+
const [rulesOff, setRulesOff] = React.useState(() => new Set())
|
|
3326
|
+
const [ruleOpen, setRuleOpen] = React.useState(false)
|
|
3327
|
+
const [legendOpen, setLegendOpen] = React.useState(false)
|
|
3328
|
+
const [forceOpen, setForceOpen] = React.useState(false)
|
|
3329
|
+
const [minimap, setMinimap] = React.useState(false)
|
|
3330
|
+
const [grid, setGrid] = React.useState(true)
|
|
3331
|
+
const [labels, setLabels] = React.useState(true)
|
|
3332
|
+
const [motion, setMotion] = React.useState(true)
|
|
3333
|
+
const [forces, setForces] = React.useState({ repulsion: 120, distance: 100, center: 0 })
|
|
3334
|
+
// 窄屏下检视面板是覆盖层,会挡住画布;默认收起,画布优先。
|
|
3335
|
+
const [inspectorOpen, setInspectorOpen] = React.useState(() =>
|
|
3336
|
+
typeof window === 'undefined' || typeof window.matchMedia !== 'function'
|
|
3337
|
+
? true : !window.matchMedia('(max-width: 1100px)').matches)
|
|
3338
|
+
const [zoom, setZoom] = React.useState(1)
|
|
3339
|
+
const [toast, setToast] = React.useState('')
|
|
3340
|
+
const [mgrKind, setMgrKind] = React.useState('')
|
|
3341
|
+
const [mgrStatus, setMgrStatus] = React.useState('')
|
|
3342
|
+
const [mgrSort, setMgrSort] = React.useState('degree')
|
|
3343
|
+
const [mgrSelected, setMgrSelected] = React.useState('')
|
|
3344
|
+
const [branchWidth, setBranchWidth] = React.useState(360)
|
|
3345
|
+
// 管理视图的增删节点:新增走 addMemory / createEntity,删除两段确认。
|
|
3346
|
+
const [mgrBusy, setMgrBusy] = React.useState(false)
|
|
3347
|
+
const [mgrArmed, setMgrArmed] = React.useState('')
|
|
3348
|
+
const [mgrDeleteRefused, setMgrDeleteRefused] = React.useState('')
|
|
3349
|
+
const [reloadKey, setReloadKey] = React.useState(0)
|
|
3350
|
+
const [addOpen, setAddOpen] = React.useState(false)
|
|
3351
|
+
const [addLib, setAddLib] = React.useState('')
|
|
3352
|
+
const [draft, setDraft] = React.useState({ type: 'memory', title: '', content: '', layer: 'long_term', name: '', kind: 'person' })
|
|
3353
|
+
// 编辑已有节点:记忆读 getMemory 取完整正文,实体读 listEntities 取别名;
|
|
3354
|
+
// 两者都与新增表单互斥,共用同一套网格样式。
|
|
3355
|
+
const [editBusy, setEditBusy] = React.useState(false)
|
|
3356
|
+
const [editOpen, setEditOpen] = React.useState(false)
|
|
3357
|
+
const [editDraft, setEditDraft] = React.useState(null)
|
|
3358
|
+
// 「全部记忆库」合并的是各私有库,新增必须选目标库;没有私有库时落到全局索引,只读。
|
|
3359
|
+
const mergedScope = showGlobal && libraries.length > 0
|
|
3360
|
+
const writable = !showGlobal || mergedScope
|
|
3361
|
+
const addTargetLib = mergedScope ? (addLib || libraries[0]?.id || '') : (showGlobal ? '' : graphLibrary)
|
|
3362
|
+
const apiRef = React.useRef(null)
|
|
3363
|
+
const searchRef = React.useRef(null)
|
|
3364
|
+
// 主画布重绘计数:缩略图只在计数变化时才拷贝纹理。
|
|
3365
|
+
const paintRef = React.useRef(0)
|
|
3366
|
+
const beat = `${revision ?? ''}:${stamp ?? ''}`
|
|
3367
|
+
const notify = message => setToast(message)
|
|
3368
|
+
|
|
3369
|
+
// 一切轮询仍走 SettingsPage 的心跳:revision/stamp 变动才重新取数。
|
|
3370
|
+
React.useEffect(() => {
|
|
3371
|
+
let alive = true
|
|
3372
|
+
const load = async () => {
|
|
3373
|
+
try {
|
|
3374
|
+
if (showGlobal && libraries.length) {
|
|
3375
|
+
// 「全部记忆库」= 合并每个私有库的图,和 MemU 记忆页的「全部记忆库」口径一致。
|
|
3376
|
+
const results = await Promise.all(libraries.map(lib =>
|
|
3377
|
+
call('getGraph', { libraryId: lib.id, focusId: null, depth: 2, limit: 200 }).catch(() => null)))
|
|
3378
|
+
const nodes = new Map(), edges = new Map()
|
|
3379
|
+
for (let i = 0; i < results.length; i++) {
|
|
3380
|
+
const value = results[i], lib = libraries[i]
|
|
3381
|
+
// 合并视图下节点要记住来源库:管理视图的删除必须有 libraryId。
|
|
3382
|
+
for (const node of value?.nodes || []) if (!nodes.has(node.id)) nodes.set(node.id, { ...node, libraryId: lib.id })
|
|
3383
|
+
for (const edge of value?.edges || []) edges.set(`${edge.from}|${edge.to}|${edge.kind || ''}`, edge)
|
|
3384
|
+
}
|
|
3385
|
+
if (!alive) return
|
|
3386
|
+
setGraph({ nodes: [...nodes.values()], edges: [...edges.values()] })
|
|
3387
|
+
} else {
|
|
3388
|
+
const payload = showGlobal
|
|
3389
|
+
? { scope: 'global', focusId: focus || null, depth: 2, limit: 200 }
|
|
3390
|
+
: { libraryId: graphLibrary, focusId: focus || null, depth: 2, limit: 200 }
|
|
3391
|
+
const value = await call('getGraph', payload)
|
|
3392
|
+
if (!alive) return
|
|
3393
|
+
setGraph(value && Array.isArray(value.nodes)
|
|
3394
|
+
? { nodes: value.nodes, edges: value.edges || [] } : { nodes: [], edges: [] })
|
|
3395
|
+
}
|
|
3396
|
+
setError('')
|
|
3397
|
+
} catch (failure) { if (alive) setError(String(failure?.message || failure)) }
|
|
3398
|
+
}
|
|
3399
|
+
void load()
|
|
3400
|
+
return () => { alive = false }
|
|
3401
|
+
}, [call, graphLibrary, showGlobal, focus, beat, reloadKey, libraries.length, libraries.map(lib => lib.id).join(',')])
|
|
3402
|
+
React.useEffect(() => {
|
|
3403
|
+
if (showGlobal) { setEntities([]); return undefined }
|
|
3404
|
+
let alive = true
|
|
3405
|
+
void call('listEntities', { libraryId: graphLibrary })
|
|
3406
|
+
.then(value => { if (alive) setEntities(value?.items || []) })
|
|
3407
|
+
.catch(() => { if (alive) setEntities([]) })
|
|
3408
|
+
return () => { alive = false }
|
|
3409
|
+
}, [call, graphLibrary, showGlobal, beat, reloadKey])
|
|
3410
|
+
React.useEffect(() => {
|
|
3411
|
+
if (!toast) return undefined
|
|
3412
|
+
const timer = setTimeout(() => setToast(''), 2200)
|
|
3413
|
+
return () => clearTimeout(timer)
|
|
3414
|
+
}, [toast])
|
|
3415
|
+
// 破坏性操作 = 二次点击,2.5s 未确认自动复原(§7.3)。
|
|
3416
|
+
React.useEffect(() => {
|
|
3417
|
+
if (!mgrArmed) return undefined
|
|
3418
|
+
const timer = setTimeout(() => { setMgrArmed(''); setMgrDeleteRefused('') }, 2500)
|
|
3419
|
+
return () => clearTimeout(timer)
|
|
3420
|
+
}, [mgrArmed])
|
|
3421
|
+
React.useEffect(() => {
|
|
3422
|
+
if (typeof document === 'undefined' || !document.addEventListener) return undefined
|
|
3423
|
+
const onKey = event => {
|
|
3424
|
+
const tag = event.target?.tagName
|
|
3425
|
+
if (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA') return
|
|
3426
|
+
if (event.key === '/') { event.preventDefault(); searchRef.current?.focus?.() }
|
|
3427
|
+
else if (event.key === 'f' || event.key === 'F') apiRef.current?.fit?.()
|
|
3428
|
+
}
|
|
3429
|
+
document.addEventListener('keydown', onKey)
|
|
3430
|
+
return () => document.removeEventListener('keydown', onKey)
|
|
3431
|
+
}, [])
|
|
3432
|
+
|
|
3433
|
+
const nodes = graph.nodes || [], edges = graph.edges || []
|
|
3434
|
+
const nodeIds = React.useMemo(() => new Set(nodes.map(node => node.id)), [graph])
|
|
3435
|
+
const degree = React.useMemo(() => {
|
|
3436
|
+
const map = new Map()
|
|
3437
|
+
for (const edge of edges) {
|
|
3438
|
+
map.set(edge.from, (map.get(edge.from) || 0) + 1)
|
|
3439
|
+
map.set(edge.to, (map.get(edge.to) || 0) + 1)
|
|
3440
|
+
}
|
|
3441
|
+
return map
|
|
3442
|
+
}, [graph])
|
|
3443
|
+
const rules = React.useMemo(() => [...new Set(edges.map(graphRuleOf).filter(Boolean))].sort(), [graph])
|
|
3444
|
+
const q = query.trim().toLowerCase()
|
|
3445
|
+
const visibleEdges = React.useMemo(() => {
|
|
3446
|
+
const matched = new Set(q ? nodes.filter(node => String(node.title || node.id).toLowerCase().includes(q))
|
|
3447
|
+
.map(node => node.id) : [])
|
|
3448
|
+
return edges.filter(edge => {
|
|
3449
|
+
if (edge.from === edge.to || !nodeIds.has(edge.from) || !nodeIds.has(edge.to)) return false
|
|
3450
|
+
if (source === 'auto' && edge.source !== 'auto') return false
|
|
3451
|
+
if (source === 'manual' && edge.source === 'auto') return false
|
|
3452
|
+
const rule = graphRuleOf(edge)
|
|
3453
|
+
if (rule && rulesOff.has(rule)) return false
|
|
3454
|
+
if (q && !matched.has(edge.from) && !matched.has(edge.to)) return false
|
|
3455
|
+
return true
|
|
3456
|
+
})
|
|
3457
|
+
}, [graph, q, source, rulesOff, nodeIds])
|
|
3458
|
+
const canvasGraph = React.useMemo(() => ({ nodes, edges: visibleEdges }), [graph, visibleEdges])
|
|
3459
|
+
// 搜索词透传给画布:匹配节点会被高亮,边筛选仍在工作台侧完成。
|
|
3460
|
+
const canvasOptions = React.useMemo(() => ({ ...forces, labels, motion, grid, query: q }),
|
|
3461
|
+
[forces, labels, motion, grid, q])
|
|
3462
|
+
const titles = React.useMemo(() => new Map(nodes.map(node => [node.id, node.title || node.id])), [graph])
|
|
3463
|
+
const panelFiles = React.useMemo(() => nodes.map(node => ({ id: node.id, title: node.title || node.id })), [graph])
|
|
3464
|
+
const selected = nodes.find(node => node.id === focus) || null
|
|
3465
|
+
const focusEdges = edges.filter(edge => edge.from === focus || edge.to === focus)
|
|
3466
|
+
const autoCount = edges.filter(edge => edge.source === 'auto').length
|
|
3467
|
+
const pendingCount = nodes.filter(node => node.status === 'provisional').length
|
|
3468
|
+
const manageRows = React.useMemo(() => nodes.filter(node => {
|
|
3469
|
+
if (q && !String(node.title || node.id).toLowerCase().includes(q)) return false
|
|
3470
|
+
if (mgrKind && node.kind !== mgrKind) return false
|
|
3471
|
+
if (mgrStatus && (node.status || 'confirmed') !== mgrStatus) return false
|
|
3472
|
+
return true
|
|
3473
|
+
}).sort((a, b) => mgrSort === 'degree' ? (degree.get(b.id) || 0) - (degree.get(a.id) || 0)
|
|
3474
|
+
: mgrSort === 'strength' ? (Number(b.strength) || 0) - (Number(a.strength) || 0)
|
|
3475
|
+
: String(mgrSort === 'id' ? a.id : a.title || a.id).localeCompare(String(mgrSort === 'id' ? b.id : b.title || b.id))),
|
|
3476
|
+
[graph, q, mgrKind, mgrStatus, mgrSort, degree])
|
|
3477
|
+
|
|
3478
|
+
const railBtn = (label, text, action, pressed) => h('button', {
|
|
3479
|
+
type: 'button', title: t(label), 'aria-label': t(label),
|
|
3480
|
+
'aria-pressed': pressed === undefined ? undefined : String(pressed), onClick: action,
|
|
3481
|
+
}, text)
|
|
3482
|
+
const segBtn = (label, value, current, action) => h('button', {
|
|
3483
|
+
type: 'button', 'aria-pressed': String(current === value), onClick: () => action(value),
|
|
3484
|
+
}, t(label))
|
|
3485
|
+
const toggleRule = rule => setRulesOff(current => {
|
|
3486
|
+
const next = new Set(current)
|
|
3487
|
+
if (next.has(rule)) next.delete(rule); else next.add(rule)
|
|
3488
|
+
return next
|
|
3489
|
+
})
|
|
3490
|
+
const exportPng = () => {
|
|
3491
|
+
const url = apiRef.current?.exportPng?.()
|
|
3492
|
+
if (!url || typeof document === 'undefined') return
|
|
3493
|
+
const link = document.createElement('a')
|
|
3494
|
+
link.href = url; link.download = 'relationship-graph.png'
|
|
3495
|
+
document.body?.appendChild?.(link); link.click?.(); link.remove?.()
|
|
3496
|
+
notify(t('gsExport'))
|
|
3497
|
+
}
|
|
3498
|
+
const fit = () => apiRef.current?.fit?.()
|
|
3499
|
+
const zoomBy = factor => apiRef.current?.zoom?.(factor)
|
|
3500
|
+
// 增删节点:记忆走 addMemory(事实级去重会返回 deduped),实体走 createEntity
|
|
3501
|
+
// (RPC 层强制 confirmed 并补提及边)。写入后立即重取图,不等心跳。
|
|
3502
|
+
const removeKey = mgrSelected ? 'remove:' + mgrSelected : ''
|
|
3503
|
+
const canAdd = writable && Boolean(addTargetLib) && !mgrBusy
|
|
3504
|
+
&& (draft.type === 'memory' ? Boolean(draft.content.trim()) : Boolean(draft.name.trim()))
|
|
3505
|
+
const canSave = Boolean(editDraft) && !editBusy
|
|
3506
|
+
&& (editDraft.kind === 'memory' ? Boolean(editDraft.content.trim()) : Boolean(editDraft.name.trim()))
|
|
3507
|
+
// updateMemory 只支持 short_term→long_term 升级与 must_remember 降级;
|
|
3508
|
+
// 提升到 must_remember 必须走带 pin 理由的写入口,这里不提供。
|
|
3509
|
+
const editLayers = !editDraft || editDraft.kind !== 'memory' ? []
|
|
3510
|
+
: editDraft.layer === 'must_remember' ? ['must_remember', 'long_term']
|
|
3511
|
+
: editDraft.layer === 'short_term' ? ['short_term', 'long_term'] : ['long_term']
|
|
3512
|
+
const addNode = async () => {
|
|
3513
|
+
if (!canAdd) return
|
|
3514
|
+
setMgrBusy(true)
|
|
3515
|
+
try {
|
|
3516
|
+
if (draft.type === 'entity') {
|
|
3517
|
+
const name = draft.name.trim()
|
|
3518
|
+
const entity = await call('createEntity', { libraryId: addTargetLib, name, kind: draft.kind })
|
|
3519
|
+
notifyMemoryWrite('relation', addTargetLib)
|
|
3520
|
+
setMgrSelected(entity?.id || '')
|
|
3521
|
+
setDraft(value => ({ ...value, name: '' }))
|
|
3522
|
+
notify(t('gsNodeCreated').replace('{name}', name))
|
|
3523
|
+
} else {
|
|
3524
|
+
const payload = { libraryId: addTargetLib, content: draft.content.trim(), title: draft.title.trim() || undefined, layer: draft.layer }
|
|
3525
|
+
if (draft.layer === 'must_remember') { payload.pinReason = 'user_explicit_note'; payload.pinSource = 'user_explicit' }
|
|
3526
|
+
const created = await call('addMemory', payload)
|
|
3527
|
+
if (created?.deduped === true) {
|
|
3528
|
+
notify(t('dedupedNotice').replace('{id}', created.existingId || '?'))
|
|
3529
|
+
return
|
|
3530
|
+
}
|
|
3531
|
+
notifyMemoryWrite('memory', addTargetLib)
|
|
3532
|
+
setMgrSelected(created?.id || '')
|
|
3533
|
+
setDraft(value => ({ ...value, title: '', content: '' }))
|
|
3534
|
+
notify(t('memorySaved'))
|
|
3535
|
+
}
|
|
3536
|
+
setReloadKey(value => value + 1)
|
|
3537
|
+
} catch (failure) { notify(String(failure?.message || failure)) } finally { setMgrBusy(false) }
|
|
3538
|
+
}
|
|
3539
|
+
const removeSelected = async () => {
|
|
3540
|
+
const node = mgrSelected ? nodes.find(item => item.id === mgrSelected) : null
|
|
3541
|
+
const libraryId = node?.libraryId || (showGlobal ? '' : graphLibrary)
|
|
3542
|
+
if (!node || !libraryId || !writable || mgrBusy) return
|
|
3543
|
+
if (mgrArmed !== removeKey) { setMgrArmed(removeKey); return }
|
|
3544
|
+
setMgrBusy(true)
|
|
3545
|
+
try {
|
|
3546
|
+
if (node.kind === 'memory') {
|
|
3547
|
+
// 永久删除只接受已归档条目:先归档再删;两段确认已由按钮承担。
|
|
3548
|
+
await call('archiveMemory', { libraryId, id: node.id })
|
|
3549
|
+
await call('deleteMemory', { libraryId, id: node.id, confirmed: true })
|
|
3550
|
+
notifyMemoryWrite('memory', libraryId)
|
|
3551
|
+
notify(t('memoryDeleted'))
|
|
3552
|
+
} else {
|
|
3553
|
+
await call('deleteEntity', { libraryId, entityId: node.id, force: mgrDeleteRefused === node.id })
|
|
3554
|
+
notifyMemoryWrite('relation', libraryId)
|
|
3555
|
+
notify(t('gsNodeDeleted'))
|
|
3556
|
+
}
|
|
3557
|
+
setMgrArmed(''); setMgrDeleteRefused(''); setMgrSelected('')
|
|
3558
|
+
setEditOpen(false); setEditDraft(null)
|
|
3559
|
+
if (focus === node.id) setFocus('')
|
|
3560
|
+
setReloadKey(value => value + 1)
|
|
3561
|
+
} catch (failure) {
|
|
3562
|
+
const message = String(failure?.message || failure)
|
|
3563
|
+
// 实体仍被引用:保留 armed,再点一次升级为 force(连同引用一起删)。
|
|
3564
|
+
if (/referenced|引用/.test(message)) setMgrDeleteRefused(node.id)
|
|
3565
|
+
notify(message)
|
|
3566
|
+
} finally { setMgrBusy(false) }
|
|
3567
|
+
}
|
|
3568
|
+
// 编辑已有节点:先读完整数据再开表单,避免拿节点摘要当正文保存。
|
|
3569
|
+
const editNode = async () => {
|
|
3570
|
+
const node = mgrSelected ? nodes.find(item => item.id === mgrSelected) : null
|
|
3571
|
+
const libraryId = node?.libraryId || (showGlobal ? '' : graphLibrary)
|
|
3572
|
+
if (!node || !libraryId || !writable || editBusy) return
|
|
3573
|
+
setEditBusy(true)
|
|
3574
|
+
try {
|
|
3575
|
+
if (node.kind === 'memory') {
|
|
3576
|
+
const loaded = await call('getMemory', { libraryId, id: node.id })
|
|
3577
|
+
const entry = loaded?.entry || {}
|
|
3578
|
+
setEditDraft({ id: node.id, kind: 'memory', libraryId,
|
|
3579
|
+
title: entry.title || '', content: entry.content || '', layer: entry.layer || 'long_term' })
|
|
3580
|
+
} else {
|
|
3581
|
+
const list = await call('listEntities', { libraryId })
|
|
3582
|
+
const found = (list?.items || []).find(item => item.id === node.id) || {}
|
|
3583
|
+
setEditDraft({ id: node.id, kind: 'entity', libraryId,
|
|
3584
|
+
name: found.name || node.title || '', aliases: (found.aliases || []).join(', ') })
|
|
3585
|
+
}
|
|
3586
|
+
setAddOpen(false)
|
|
3587
|
+
setEditOpen(true)
|
|
3588
|
+
} catch (failure) { notify(String(failure?.message || failure)) } finally { setEditBusy(false) }
|
|
3589
|
+
}
|
|
3590
|
+
const saveEdit = async () => {
|
|
3591
|
+
if (!canSave) return
|
|
3592
|
+
setEditBusy(true)
|
|
3593
|
+
try {
|
|
3594
|
+
if (editDraft.kind === 'memory') {
|
|
3595
|
+
const patch = { content: editDraft.content.trim(), layer: editDraft.layer }
|
|
3596
|
+
const title = editDraft.title.trim()
|
|
3597
|
+
if (title) patch.title = title
|
|
3598
|
+
await call('updateMemory', { libraryId: editDraft.libraryId, id: editDraft.id, patch })
|
|
3599
|
+
notifyMemoryWrite('memory', editDraft.libraryId)
|
|
3600
|
+
} else {
|
|
3601
|
+
// renameEntity 的 aliases 是整体替换:必须带上当前列表,否则会被清空。
|
|
3602
|
+
const aliases = String(editDraft.aliases || '').split(',').map(value => value.trim()).filter(Boolean)
|
|
3603
|
+
await call('renameEntity', { libraryId: editDraft.libraryId, entityId: editDraft.id,
|
|
3604
|
+
name: editDraft.name.trim(), aliases })
|
|
3605
|
+
notifyMemoryWrite('relation', editDraft.libraryId)
|
|
3606
|
+
}
|
|
3607
|
+
notify(t('saved'))
|
|
3608
|
+
setEditOpen(false); setEditDraft(null)
|
|
3609
|
+
setReloadKey(value => value + 1)
|
|
3610
|
+
} catch (failure) { notify(String(failure?.message || failure)) } finally { setEditBusy(false) }
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
const topbar = h('header', { className: 'dshm-gs-topbar' },
|
|
3614
|
+
h('div', { className: 'dshm-gs-brand' },
|
|
3615
|
+
h('div', { className: 'dshm-gs-mark', 'aria-hidden': 'true' }, 'M'),
|
|
3616
|
+
h('div', { className: 'dshm-gs-brand-txt' },
|
|
3617
|
+
h('strong', null, t('pageGraph')), h('small', null, 'GRAPH STUDIO'))),
|
|
3618
|
+
h('div', { className: 'dshm-gs-divider' }),
|
|
3619
|
+
h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('pageGraph') },
|
|
3620
|
+
segBtn('graphView', 'graph', view, setView), segBtn('gsManage', 'manage', view, setView)),
|
|
3621
|
+
h('select', {
|
|
3622
|
+
className: 'dshm-gs-field', value: graphLibrary,
|
|
3623
|
+
title: showGlobal ? t('gsAllLibraries') : (libraries.find(lib => lib.id === graphLibrary)?.scopeKey || t('currentLibrary')),
|
|
3624
|
+
'aria-label': t('currentLibrary'), onChange: event => setGraphLib(event.target.value),
|
|
3625
|
+
},
|
|
3626
|
+
h('option', { value: GLOBAL_GRAPH_ID }, t('gsAllLibraries')),
|
|
3627
|
+
libraries.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries)))),
|
|
3628
|
+
h('label', { className: 'dshm-gs-search' },
|
|
3629
|
+
h('span', { className: 'dshm-gs-search-icon', 'aria-hidden': 'true' }, '⌕'),
|
|
3630
|
+
h('input', { ref: searchRef, className: 'dshm-gs-field', type: 'search', value: query,
|
|
3631
|
+
placeholder: t('gsSearch'), 'aria-label': t('gsSearch'),
|
|
3632
|
+
onChange: event => setQuery(event.target.value) })),
|
|
3633
|
+
h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsRules') },
|
|
3634
|
+
segBtn('edgeFilterAll', 'all', source, setSource),
|
|
3635
|
+
segBtn('edgeFilterAuto', 'auto', source, setSource),
|
|
3636
|
+
segBtn('edgeFilterManual', 'manual', source, setSource)),
|
|
3637
|
+
h('div', { className: 'dshm-gs-popwrap' },
|
|
3638
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsRules'), 'aria-label': t('gsRules'),
|
|
3639
|
+
'aria-expanded': String(ruleOpen), onClick: () => setRuleOpen(value => !value) },
|
|
3640
|
+
t('gsRules'), h('span', { className: 'dshm-gs-count' }, `${rules.length - rulesOff.size}/${rules.length}`)),
|
|
3641
|
+
ruleOpen ? h('div', { className: 'dshm-gs-pop is-open' }, h('h4', null, t('gsRules')),
|
|
3642
|
+
rules.length ? rules.map(rule => h('label', { key: rule },
|
|
3643
|
+
h('input', { type: 'checkbox', checked: !rulesOff.has(rule), onChange: () => toggleRule(rule) }), graphRuleText(rule, t)))
|
|
3644
|
+
: h('p', { className: 'dshm-gs-pop-empty' }, t('gsNoRules'))) : null),
|
|
3645
|
+
h('div', { className: 'dshm-gs-spacer' }),
|
|
3646
|
+
h('span', { className: 'dshm-gs-themechip', 'aria-pressed': 'true' },
|
|
3647
|
+
h('i', { className: 'dshm-gs-dot' }), t('gsLocalData')),
|
|
3648
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsExport'), onClick: exportPng }, t('gsExport')),
|
|
3649
|
+
h('button', { type: 'button', className: 'dshm-gs-btn dshm-gs-icon', title: t('gsCollapse'),
|
|
3650
|
+
'aria-label': t('gsCollapse'), onClick: () => setInspectorOpen(value => !value) }, '⇥'))
|
|
3651
|
+
|
|
3652
|
+
// 力参数弹层贴在 rail 的「图谱设置」按钮正右边,而不是画布右下角。
|
|
3653
|
+
const forcePop = h('div', { className: 'dshm-gs-forcepop is-open' },
|
|
3654
|
+
h('h4', null, t('gsForce')),
|
|
3655
|
+
[['repulsion', 'graphRepulsion', 30, 350, 5], ['distance', 'graphDistance', 40, 220, 5],
|
|
3656
|
+
['center', 'graphCenter', 0, 3, .05]].map(([key, label, min, max, step]) =>
|
|
3657
|
+
h('label', { key }, t(label),
|
|
3658
|
+
h('input', { type: 'range', min, max, step, value: forces[key], title: t(label), 'aria-label': t(label),
|
|
3659
|
+
onChange: event => setForces(value => ({ ...value, [key]: Number(event.target.value) })) }),
|
|
3660
|
+
h('output', null, Number(forces[key]).toFixed(2)))),
|
|
3661
|
+
h('div', { className: 'dshm-gs-forcepop-toggles' },
|
|
3662
|
+
h(Toggle, { checked: labels, label: t('graphLabels'), onChange: setLabels }),
|
|
3663
|
+
h(Toggle, { checked: motion, label: t('graphMotion'), onChange: setMotion })),
|
|
3664
|
+
h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsReset'),
|
|
3665
|
+
onClick: () => { setForces({ repulsion: 120, distance: 100, center: 0 }); notify(t('gsReset')) } }, t('gsReset')))
|
|
3666
|
+
|
|
3667
|
+
const rail = h('nav', { className: 'dshm-gs-rail', 'aria-label': t('graphView') },
|
|
3668
|
+
railBtn('graphZoomIn', '+', () => zoomBy(1.25)),
|
|
3669
|
+
railBtn('graphZoomOut', '−', () => zoomBy(.8)),
|
|
3670
|
+
railBtn('graphFit', '⛶', fit),
|
|
3671
|
+
h('div', { className: 'dshm-gs-rail-sep' }),
|
|
3672
|
+
railBtn('graphLabels', 'Aa', () => setLabels(value => !value), labels),
|
|
3673
|
+
railBtn('gsGrid', '#', () => setGrid(value => !value), grid),
|
|
3674
|
+
railBtn('gsMinimap', '▭', () => setMinimap(value => !value), minimap),
|
|
3675
|
+
railBtn('graphRelayout', '↻', () => { apiRef.current?.relayout?.(); notify(t('graphRelayout')) }),
|
|
3676
|
+
h('div', { className: 'dshm-gs-rail-slot' },
|
|
3677
|
+
railBtn('graphOptions', '⚙', () => setForceOpen(value => !value), forceOpen),
|
|
3678
|
+
forceOpen ? forcePop : null),
|
|
3679
|
+
railBtn('graphUnpinAll', '⊘', () => { apiRef.current?.unpinAll?.(); notify(t('graphUnpinAll')) }),
|
|
3680
|
+
h('div', { className: 'dshm-gs-rail-sep' }),
|
|
3681
|
+
railBtn('gsFocusNode', '◎', () => { if (focus) notify(t('gsFocusNode')); else fit() }),
|
|
3682
|
+
h('div', { className: 'dshm-gs-rail-grow' }),
|
|
3683
|
+
railBtn('gsHelp', '?', () => notify(t('gsShortcuts'))))
|
|
3684
|
+
|
|
3685
|
+
const legendItems = [
|
|
3686
|
+
['memory', t('gsLegendMemory')], ['must', t('gsLegendMust')],
|
|
3687
|
+
['entity', t('gsLegendEntity')], ['provisional', t('gsLegendPending')],
|
|
3688
|
+
['global', t('gsLegendGlobal')], ['missing', t('gsLegendMissing')],
|
|
3689
|
+
]
|
|
3690
|
+
const canvasTools = h('div', { className: 'dshm-gs-canvas-tools' },
|
|
3691
|
+
h('div', { className: 'dshm-gs-zoombar' },
|
|
3692
|
+
h('button', { type: 'button', title: t('graphZoomOut'), 'aria-label': t('graphZoomOut'), onClick: () => zoomBy(.8) }, '−'),
|
|
3693
|
+
h('output', { className: 'dshm-gs-zoomval' }, `${Math.round(zoom * 100)}%`),
|
|
3694
|
+
h('button', { type: 'button', title: t('graphZoomIn'), 'aria-label': t('graphZoomIn'), onClick: () => zoomBy(1.25) }, '+'),
|
|
3695
|
+
h('button', { type: 'button', title: t('graphFit'), 'aria-label': t('graphFit'), onClick: fit }, '⛶')),
|
|
3696
|
+
h('div', { className: 'dshm-gs-legendwrap' },
|
|
3697
|
+
h('button', { type: 'button', className: 'dshm-gs-legendbtn', title: t('gsLegend'),
|
|
3698
|
+
'aria-expanded': String(legendOpen), onClick: () => setLegendOpen(value => !value) }, t('gsLegend')),
|
|
3699
|
+
legendOpen ? h('div', { className: 'dshm-gs-legendpop is-open' },
|
|
3700
|
+
h('h4', null, t('gsNodes')),
|
|
3701
|
+
legendItems.map(([kind, label]) => h('div', { key: kind, className: 'dshm-gs-legend-row' },
|
|
3702
|
+
h('i', { className: `dshm-gs-swatch dshm-gs-c-${kind}` }), label)),
|
|
3703
|
+
h('h4', null, t('gsEdges')),
|
|
3704
|
+
h('div', { className: 'dshm-gs-legend-row' }, h('i', { className: 'dshm-gs-line' }), t('gsLegendAuto')),
|
|
3705
|
+
h('div', { className: 'dshm-gs-legend-row' }, h('i', { className: 'dshm-gs-line dashed' }), t('gsLegendManual'))) : null))
|
|
3706
|
+
|
|
3707
|
+
const stage = h('main', { className: 'dshm-gs-stage' },
|
|
3708
|
+
h(GraphCanvas, { graph: canvasGraph, focus, onFocus: setFocus, t, chrome: false,
|
|
3709
|
+
options: canvasOptions, apiRef, onZoom: setZoom, paintRef }),
|
|
3710
|
+
canvasTools,
|
|
3711
|
+
minimap ? h(GraphStudioMinimap, { active: true, t, paintRef }) : null,
|
|
3712
|
+
h('div', { className: `dshm-gs-toast${toast ? ' show' : ''}`, role: 'status' }, toast),
|
|
3713
|
+
error ? h('div', { className: 'dshm-gs-toast show', role: 'alert' }, error) : null,
|
|
3714
|
+
!visibleEdges.length && nodes.length
|
|
3715
|
+
? h('div', { className: 'dshm-gs-empty' }, showGlobal ? t('gsGlobalEmpty') : t('gsEmpty')) : null)
|
|
3716
|
+
|
|
3717
|
+
const inspectorBody = selected
|
|
3718
|
+
? h(React.Fragment, null,
|
|
3719
|
+
h('div', { className: 'dshm-gs-sec' },
|
|
3720
|
+
h('div', { className: 'dshm-gs-hero' },
|
|
3721
|
+
h('div', { className: `dshm-gs-glyph dshm-gs-c-${gsKind(selected)}`, 'aria-hidden': 'true' },
|
|
3722
|
+
selected.kind === 'memory' ? '●' : '◆'),
|
|
3723
|
+
h('div', { className: 'dshm-gs-hero-t' },
|
|
3724
|
+
h('h3', null, String(selected.title || selected.id)),
|
|
3725
|
+
h('div', { className: 'dshm-gs-tags' },
|
|
3726
|
+
h('span', { className: 'dshm-gs-tag' }, String(selected.kind || 'memory')),
|
|
3727
|
+
selected.layer ? h('span', { className: 'dshm-gs-tag neutral' }, String(selected.layer)) : null,
|
|
3728
|
+
selected.status === 'provisional' ? h('span', { className: 'dshm-gs-tag warn' }, t('gsPending')) : null))),
|
|
3729
|
+
h('dl', { className: 'dshm-gs-kv' },
|
|
3730
|
+
h('dt', null, 'ID'), h('dd', null, String(selected.id)),
|
|
3731
|
+
h('dt', null, t('gsDegree')), h('dd', null, String(degree.get(selected.id) || 0)),
|
|
3732
|
+
h('dt', null, t('gsStrength')), h('dd', null, Number(selected.strength || 0).toFixed(2)))),
|
|
3733
|
+
h('div', { className: 'dshm-gs-sec' },
|
|
3734
|
+
h('div', { className: 'dshm-gs-sec-head' }, h('h3', null, t('relations')),
|
|
3735
|
+
h('span', { className: 'dshm-gs-count' }, String(focusEdges.length))),
|
|
3736
|
+
h('div', { className: 'dshm-gs-edge-list' }, focusEdges.slice(0, 20).map(edge => {
|
|
3737
|
+
const other = edge.from === focus ? edge.to : edge.from
|
|
3738
|
+
return h('div', { key: `${edge.from}:${edge.to}:${edge.kind || ''}`, className: 'dshm-gs-edge',
|
|
3739
|
+
onClick: () => setFocus(other) },
|
|
3740
|
+
h('div', { className: 'dshm-gs-edge-top' },
|
|
3741
|
+
h('span', { className: 'dshm-gs-edge-arrow' },
|
|
3742
|
+
`${titles.get(edge.from) || edge.from} → ${titles.get(edge.to) || edge.to}`),
|
|
3743
|
+
h('span', { className: 'dshm-gs-conf' }, Number(edge.confidence || 0).toFixed(2))),
|
|
3744
|
+
edge.note ? h('p', { className: 'dshm-gs-why' }, String(edge.note)) : null,
|
|
3745
|
+
h('div', { className: 'dshm-gs-meta' },
|
|
3746
|
+
h('span', { className: `dshm-gs-tag ${edge.source === 'auto' ? 'auto' : 'manual'}` },
|
|
3747
|
+
edge.source === 'auto' ? t('graphAutoLink') : t('edgeFilterManual')),
|
|
3748
|
+
edge.rule ? h('span', { className: 'dshm-gs-tag neutral' }, graphRuleText(edge.rule, t)) : null))
|
|
3749
|
+
}))),
|
|
3750
|
+
showGlobal ? null : h('details', { className: 'dshm-gs-fold' },
|
|
3751
|
+
h('summary', null, t('relations')),
|
|
3752
|
+
h(RelationshipPanel, { call, libraryId: graphLibrary, entities, files: panelFiles, t })))
|
|
3753
|
+
: h(React.Fragment, null,
|
|
3754
|
+
h('div', { className: 'dshm-gs-stats' },
|
|
3755
|
+
[[t('gsNodes'), nodes.length], [t('gsEdges'), edges.length],
|
|
3756
|
+
[t('gsVisible'), visibleEdges.length], [t('gsAutoEdges'), autoCount],
|
|
3757
|
+
[t('gsPending'), pendingCount]].map(([label, value]) =>
|
|
3758
|
+
h('div', { key: label, className: 'dshm-gs-stat' }, h('b', null, String(value)), h('span', null, label)))),
|
|
3759
|
+
h('div', { className: 'dshm-gs-hintbox' }, t('gsShortcuts')),
|
|
3760
|
+
h('div', { className: 'dshm-gs-hintbox' }, t('graphPinHint'), ' · ', t('graphScopeHint')))
|
|
3761
|
+
const inspector = h('aside', { className: 'dshm-gs-inspector' },
|
|
3762
|
+
h('div', { className: 'dshm-gs-ins-head' },
|
|
3763
|
+
h('div', { className: 'dshm-gs-ins-title' },
|
|
3764
|
+
h('h2', null, t('gsInspector')),
|
|
3765
|
+
h('span', { className: 'dshm-gs-count' }, selected ? String(selected.title || selected.id) : t('gsNoSelection'))),
|
|
3766
|
+
h('p', null, t('gsInspectorHint'))),
|
|
3767
|
+
h('div', { className: 'dshm-gs-ins-body' }, inspectorBody))
|
|
3768
|
+
|
|
3769
|
+
// 管理视图的「连接分支」侧栏:可拖动分隔条调宽度,复刻 HTML 的 br-resizer。
|
|
3770
|
+
const startBranchResize = event => {
|
|
3771
|
+
event.preventDefault?.()
|
|
3772
|
+
const startX = event.clientX || 0, startWidth = branchWidth
|
|
3773
|
+
const onMove = moveEvent => setBranchWidth(Math.max(240, Math.min(620, startWidth + startX - (moveEvent.clientX || 0))))
|
|
3774
|
+
const onUp = () => {
|
|
3775
|
+
window.removeEventListener?.('pointermove', onMove)
|
|
3776
|
+
window.removeEventListener?.('pointerup', onUp)
|
|
3777
|
+
}
|
|
3778
|
+
window.addEventListener?.('pointermove', onMove)
|
|
3779
|
+
window.addEventListener?.('pointerup', onUp)
|
|
3780
|
+
}
|
|
3781
|
+
const branchId = mgrSelected || focus
|
|
3782
|
+
const branchNode = nodes.find(node => node.id === branchId) || null
|
|
3783
|
+
const tier1 = branchId ? edges.filter(edge => edge.from === branchId || edge.to === branchId)
|
|
3784
|
+
.map(edge => ({ id: edge.from === branchId ? edge.to : edge.from, edge })) : []
|
|
3785
|
+
const tier1Ids = new Set(tier1.map(item => item.id))
|
|
3786
|
+
const tier2 = branchId ? edges.filter(edge => tier1Ids.has(edge.from) || tier1Ids.has(edge.to))
|
|
3787
|
+
.map(edge => ({ id: tier1Ids.has(edge.from) ? edge.to : edge.from, edge }))
|
|
3788
|
+
.filter(item => item.id !== branchId && !tier1Ids.has(item.id)) : []
|
|
3789
|
+
const branchRow = item => {
|
|
3790
|
+
const other = nodes.find(node => node.id === item.id) || { kind: 'memory' }
|
|
3791
|
+
return h('div', { key: `${item.id}:${item.edge.from}:${item.edge.to}`, className: 'dshm-gs-br-item' },
|
|
3792
|
+
h('i', { className: `dshm-gs-br-dot dshm-gs-c-${gsKind(other)}` }),
|
|
3793
|
+
h('div', { className: 'dshm-gs-br-col' },
|
|
3794
|
+
h('div', { className: 'dshm-gs-br-nm', onClick: () => { setFocus(item.id); setView('graph') } },
|
|
3795
|
+
titles.get(item.id) || item.id),
|
|
3796
|
+
h('div', { className: 'dshm-gs-br-meta' },
|
|
3797
|
+
`${item.edge.kind || 'link'} · ${item.edge.source === 'auto' ? t('graphAutoLink') : t('edgeFilterManual')}`)),
|
|
3798
|
+
h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsLocate'),
|
|
3799
|
+
onClick: () => { setFocus(item.id); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')))
|
|
3800
|
+
}
|
|
3801
|
+
const branchPanel = h('aside', { className: 'dshm-gs-branch' },
|
|
3802
|
+
h('div', { className: 'dshm-gs-br-head' },
|
|
3803
|
+
h('h3', null, t('gsBranch')), h('p', null, t('gsBranchHint'))),
|
|
3804
|
+
h('div', { className: 'dshm-gs-br-body' },
|
|
3805
|
+
branchNode ? h(React.Fragment, null,
|
|
3806
|
+
h('div', { className: 'dshm-gs-br-hero' },
|
|
3807
|
+
h('div', { className: `dshm-gs-glyph dshm-gs-c-${gsKind(branchNode)}` }, '◆'),
|
|
3808
|
+
h('div', { className: 'dshm-gs-hero-t' },
|
|
3809
|
+
h('b', null, String(branchNode.title || branchNode.id)),
|
|
3810
|
+
h('span', null, `${t('gsDegree')} ${degree.get(branchId) || 0}`))),
|
|
3811
|
+
h('div', { className: 'dshm-gs-br-sec' },
|
|
3812
|
+
h('h4', null, `${t('gsTier1')} (${tier1.length})`),
|
|
3813
|
+
tier1.slice(0, 30).map(branchRow)),
|
|
3814
|
+
tier2.length ? h('details', { className: 'dshm-gs-fold' },
|
|
3815
|
+
h('summary', null, `${t('gsTier2')} (${tier2.length})`),
|
|
3816
|
+
tier2.slice(0, 30).map(branchRow)) : null)
|
|
3817
|
+
: h('div', { className: 'dshm-gs-br-empty' }, t('gsNoSelection'))))
|
|
3818
|
+
|
|
3819
|
+
const manager = h('section', { className: 'dshm-gs-manager' },
|
|
3820
|
+
h('div', { className: 'dshm-gs-mgr-head' },
|
|
3821
|
+
h('span', { className: 'dshm-gs-count' }, `${manageRows.length} · ${t('gsNodes')}`),
|
|
3822
|
+
h('select', { className: 'dshm-gs-field', value: mgrKind, 'aria-label': t('gsAllKinds'),
|
|
3823
|
+
onChange: event => setMgrKind(event.target.value) },
|
|
3824
|
+
h('option', { value: '' }, t('gsAllKinds')),
|
|
3825
|
+
['memory', 'person', 'place', 'thing', 'global'].map(kind =>
|
|
3826
|
+
h('option', { key: kind, value: kind }, kind))),
|
|
3827
|
+
h('select', { className: 'dshm-gs-field', value: mgrStatus, 'aria-label': t('gsAllStatus'),
|
|
3828
|
+
onChange: event => setMgrStatus(event.target.value) },
|
|
3829
|
+
h('option', { value: '' }, t('gsAllStatus')),
|
|
3830
|
+
[['confirmed', 'entityConfirmed'], ['provisional', 'gsPending']].map(([value, label]) =>
|
|
3831
|
+
h('option', { key: value, value }, t(label)))),
|
|
3832
|
+
h('select', { className: 'dshm-gs-field', value: mgrSort, 'aria-label': t('gsSort'),
|
|
3833
|
+
onChange: event => setMgrSort(event.target.value) },
|
|
3834
|
+
[['degree', 'gsDegree'], ['strength', 'gsStrength'], ['title', 'gsTitle'], ['id', 'gsNodes']].map(([value, label]) =>
|
|
3835
|
+
h('option', { key: value, value }, t(label)))),
|
|
3836
|
+
writable ? h('button', { type: 'button', className: `dshm-gs-btn${mgrArmed === removeKey ? ' is-danger' : ''}`,
|
|
3837
|
+
title: t('gsRemoveNodeHint'), 'aria-label': t('gsRemoveNode'), disabled: !mgrSelected || mgrBusy,
|
|
3838
|
+
onClick: () => { void removeSelected() } },
|
|
3839
|
+
mgrArmed === removeKey ? (mgrDeleteRefused === mgrSelected ? t('relationConfirm') + '!' : t('confirmDelete')) : t('gsRemoveNode')) : null,
|
|
3840
|
+
writable ? h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsEditNode'),
|
|
3841
|
+
'aria-label': t('gsEditNode'), disabled: !mgrSelected || mgrBusy || editBusy,
|
|
3842
|
+
onClick: () => { void editNode() } }, t('gsEditNode')) : null,
|
|
3843
|
+
writable ? h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsAddNode'),
|
|
3844
|
+
'aria-expanded': String(addOpen), onClick: () => { setEditOpen(false); setEditDraft(null); setAddOpen(value => !value) } }, t('gsAddNode')) : null,
|
|
3845
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsExport'), onClick: exportPng }, t('gsExport'))),
|
|
3846
|
+
addOpen && writable ? h('div', { className: 'dshm-gs-mgr-add' },
|
|
3847
|
+
h('select', { className: 'dshm-gs-field', value: addTargetLib, title: t('gsAddLibrary'), 'aria-label': t('gsAddLibrary'),
|
|
3848
|
+
onChange: event => setAddLib(event.target.value) },
|
|
3849
|
+
(mergedScope ? libraries : libraries.filter(lib => lib.id === addTargetLib))
|
|
3850
|
+
.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries)))),
|
|
3851
|
+
h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsAddNode') },
|
|
3852
|
+
h('button', { type: 'button', 'aria-pressed': String(draft.type === 'memory'),
|
|
3853
|
+
onClick: () => setDraft(value => ({ ...value, type: 'memory' })) }, t('gsNodeMemory')),
|
|
3854
|
+
h('button', { type: 'button', 'aria-pressed': String(draft.type === 'entity'),
|
|
3855
|
+
onClick: () => setDraft(value => ({ ...value, type: 'entity' })) }, t('gsNodeEntity'))),
|
|
3856
|
+
draft.type === 'memory'
|
|
3857
|
+
? h('input', { className: 'dshm-gs-field', value: draft.title, placeholder: t('memoryTitle'), 'aria-label': t('memoryTitle'),
|
|
3858
|
+
onChange: event => setDraft(value => ({ ...value, title: event.target.value })) })
|
|
3859
|
+
: h('input', { className: 'dshm-gs-field', value: draft.name, placeholder: t('entityName'), 'aria-label': t('entityName'),
|
|
3860
|
+
onChange: event => setDraft(value => ({ ...value, name: event.target.value })) }),
|
|
3861
|
+
draft.type === 'memory'
|
|
3862
|
+
? h('select', { className: 'dshm-gs-field', value: draft.layer, 'aria-label': t('gsLayer'),
|
|
3863
|
+
onChange: event => setDraft(value => ({ ...value, layer: event.target.value })) },
|
|
3864
|
+
['long_term', 'short_term', 'must_remember'].map(layer => h('option', { key: layer, value: layer }, enumText(t, LAYER_LABELS, layer))))
|
|
3865
|
+
: h('select', { className: 'dshm-gs-field', value: draft.kind, 'aria-label': t('gsKind'),
|
|
3866
|
+
onChange: event => setDraft(value => ({ ...value, kind: event.target.value })) },
|
|
3867
|
+
['person', 'place', 'thing', 'org'].map(kind => h('option', { key: kind, value: kind }, kind))),
|
|
3868
|
+
h('div', { className: 'dshm-gs-add-actions' },
|
|
3869
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !canAdd, onClick: () => { void addNode() } }, t('add')),
|
|
3870
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', onClick: () => setAddOpen(false) }, t('cancelDelete'))),
|
|
3871
|
+
draft.type === 'memory'
|
|
3872
|
+
? h('textarea', { className: 'dshm-gs-field', value: draft.content, placeholder: t('memoryContent'), 'aria-label': t('memoryContent'),
|
|
3873
|
+
onChange: event => setDraft(value => ({ ...value, content: event.target.value })) })
|
|
3874
|
+
: null) : null,
|
|
3875
|
+
editOpen && editDraft ? h('div', { className: 'dshm-gs-mgr-add' },
|
|
3876
|
+
h('select', { className: 'dshm-gs-field', value: editDraft.libraryId, disabled: true, title: t('gsAddLibrary'), 'aria-label': t('gsAddLibrary') },
|
|
3877
|
+
h('option', { value: editDraft.libraryId },
|
|
3878
|
+
libraryOptionLabel(libraries.find(lib => lib.id === editDraft.libraryId) || { id: editDraft.libraryId }, libraries))),
|
|
3879
|
+
h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsEditNode') },
|
|
3880
|
+
h('button', { type: 'button', 'aria-pressed': 'true', disabled: true },
|
|
3881
|
+
editDraft.kind === 'memory' ? t('gsNodeMemory') : t('gsNodeEntity'))),
|
|
3882
|
+
editDraft.kind === 'memory'
|
|
3883
|
+
? h('input', { className: 'dshm-gs-field', value: editDraft.title, placeholder: t('memoryTitle'), 'aria-label': t('memoryTitle'),
|
|
3884
|
+
onChange: event => setEditDraft(value => ({ ...value, title: event.target.value })) })
|
|
3885
|
+
: h('input', { className: 'dshm-gs-field', value: editDraft.name, placeholder: t('entityName'), 'aria-label': t('entityName'),
|
|
3886
|
+
onChange: event => setEditDraft(value => ({ ...value, name: event.target.value })) }),
|
|
3887
|
+
editDraft.kind === 'memory'
|
|
3888
|
+
? h('select', { className: 'dshm-gs-field', value: editDraft.layer, 'aria-label': t('gsLayer'),
|
|
3889
|
+
onChange: event => setEditDraft(value => ({ ...value, layer: event.target.value })) },
|
|
3890
|
+
editLayers.map(layer => h('option', { key: layer, value: layer }, enumText(t, LAYER_LABELS, layer))))
|
|
3891
|
+
: h('input', { className: 'dshm-gs-field', value: editDraft.aliases, placeholder: t('entityAliases'), 'aria-label': t('entityAliases'),
|
|
3892
|
+
onChange: event => setEditDraft(value => ({ ...value, aliases: event.target.value })) }),
|
|
3893
|
+
h('div', { className: 'dshm-gs-add-actions' },
|
|
3894
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !canSave, onClick: () => { void saveEdit() } }, t('save')),
|
|
3895
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', onClick: () => { setEditOpen(false); setEditDraft(null) } }, t('cancelDelete'))),
|
|
3896
|
+
editDraft.kind === 'memory'
|
|
3897
|
+
? h('textarea', { className: 'dshm-gs-field', value: editDraft.content, placeholder: t('memoryContent'), 'aria-label': t('memoryContent'),
|
|
3898
|
+
onChange: event => setEditDraft(value => ({ ...value, content: event.target.value })) })
|
|
3899
|
+
: null) : null,
|
|
3900
|
+
h('div', { className: 'dshm-gs-mgr-body', style: { '--gs-br-w': `${branchWidth}px` } },
|
|
3901
|
+
h('div', { className: 'dshm-gs-mgr-scroll' },
|
|
3902
|
+
h('div', { className: 'dshm-gs-mgr-thead' },
|
|
3903
|
+
h('span', null, ''), h('span', null, 'ID'), h('span', null, t('gsTitle')),
|
|
3904
|
+
h('span', null, t('gsKind')), h('span', null, t('gsStatus')), h('span', null, t('gsLayer')),
|
|
3905
|
+
h('span', { className: 'num' }, t('gsDegree')), h('span', { className: 'num' }, t('gsStrength')),
|
|
3906
|
+
h('span', null, t('gsAction'))),
|
|
3907
|
+
manageRows.length ? manageRows.slice(0, 300).map(node => h('div', {
|
|
3908
|
+
key: node.id, className: `dshm-gs-mgr-row${mgrSelected === node.id ? ' sel' : ''}`,
|
|
3909
|
+
onClick: () => { setMgrSelected(node.id); setEditOpen(false); setEditDraft(null) },
|
|
3910
|
+
},
|
|
3911
|
+
h('span', { className: 'dshm-gs-mgr-dot' }, h('i', { className: `dshm-gs-swatch dshm-gs-c-${gsKind(node)}` })),
|
|
3912
|
+
h('span', { className: 'dshm-gs-mgr-id' }, String(node.id).slice(0, 8)),
|
|
3913
|
+
h('span', { className: 'dshm-gs-mgr-title' }, String(node.title || node.id)),
|
|
3914
|
+
h('span', null, String(node.kind || 'memory')),
|
|
3915
|
+
// 记忆条目写入即生效,没有「待确认」概念;只有实体才会是 provisional。
|
|
3916
|
+
h('span', null, node.status === 'provisional' ? t('gsPending')
|
|
3917
|
+
: node.kind === 'memory' || node.status === 'confirmed' ? t('gsConfirmed') : '—'),
|
|
3918
|
+
h('span', null, node.layer ? enumText(t, LAYER_LABELS, node.layer) : '—'),
|
|
3919
|
+
h('span', { className: 'num' }, String(degree.get(node.id) || 0)),
|
|
3920
|
+
h('span', { className: 'num' }, Number(node.strength || 0).toFixed(2)),
|
|
3921
|
+
h('span', { className: 'dshm-gs-mgr-ops' },
|
|
3922
|
+
h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsViewBranch'),
|
|
3923
|
+
onClick: event => { event.stopPropagation(); setMgrSelected(node.id); setView('manage') } }, t('gsViewBranch')),
|
|
3924
|
+
h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsLocate'),
|
|
3925
|
+
onClick: event => { event.stopPropagation(); setFocus(node.id); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')))))
|
|
3926
|
+
: h('div', { className: 'dshm-gs-mgr-empty' }, t('gsNoMatch'))),
|
|
3927
|
+
h('button', { type: 'button', className: 'dshm-gs-br-resizer', title: t('gsResize'),
|
|
3928
|
+
'aria-label': t('gsResize'), onPointerDown: startBranchResize }),
|
|
3929
|
+
branchPanel),
|
|
3930
|
+
h('div', { className: 'dshm-gs-mgr-foot' },
|
|
3931
|
+
h('span', null, mgrSelected || '—'),
|
|
3932
|
+
h('div', { className: 'dshm-gs-spacer' }),
|
|
3933
|
+
h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !mgrSelected,
|
|
3934
|
+
onClick: () => { setFocus(mgrSelected); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')),
|
|
3935
|
+
h('button', { type: 'button', className: 'dshm-gs-btn primary', onClick: () => setView('graph') }, t('graphView'))))
|
|
3936
|
+
|
|
3937
|
+
const status = h('footer', { className: 'dshm-gs-status' },
|
|
3938
|
+
h('span', { className: 'dshm-gs-live' }, h('i'), t('gsLocalData')),
|
|
3939
|
+
h('span', { className: 'dshm-gs-status-sep' }),
|
|
3940
|
+
h('span', null, t('gsNodes'), ' ', h('b', null, String(nodes.length))),
|
|
3941
|
+
h('span', null, t('gsEdges'), ' ', h('b', null, String(edges.length))),
|
|
3942
|
+
h('span', null, t('gsVisible'), ' ', h('b', null, String(visibleEdges.length))),
|
|
3943
|
+
h('span', null, t('gsAutoEdges'), ' ', h('b', null, String(autoCount))),
|
|
3944
|
+
h('span', null, t('gsPending'), ' ', h('b', null, String(pendingCount))),
|
|
3945
|
+
h('span', { className: 'dshm-gs-status-right' }, t('gsRender'), ' ', h('b', null, '—'),
|
|
3946
|
+
' · ', t('graphPinHint')))
|
|
3947
|
+
|
|
3948
|
+
return h('div', { className: `dshm-gs${inspectorOpen ? '' : ' is-collapsed'}${view === 'manage' ? ' is-manage' : ''}${minimap ? ' show-minimap' : ''}` },
|
|
3949
|
+
topbar, rail, stage, inspector, manager, status)
|
|
3950
|
+
}
|
|
2741
3951
|
function GraphPanel({ call, libraryId, files, t, global = false }) {
|
|
2742
3952
|
const [graph, setGraph] = React.useState({ nodes: [], edges: [] })
|
|
2743
3953
|
const [entities, setEntities] = React.useState([])
|
|
@@ -2754,6 +3964,15 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2754
3964
|
// 图谱其余部分,所以单独 catch 成空列表。
|
|
2755
3965
|
const [merges, setMerges] = React.useState([])
|
|
2756
3966
|
const [mergeNotice, setMergeNotice] = React.useState('')
|
|
3967
|
+
// 待确认实体(DESIGN §9.2):候选只排队列;确认动作才会补挂提及边。
|
|
3968
|
+
const [anchor, setAnchor] = React.useState(null)
|
|
3969
|
+
const [anchorKinds, setAnchorKinds] = React.useState({})
|
|
3970
|
+
const [anchorPicked, setAnchorPicked] = React.useState(() => new Set())
|
|
3971
|
+
const [anchorBusy, setAnchorBusy] = React.useState(false)
|
|
3972
|
+
// 边来源筛选 + “删除全部自动边”的二次确认(§10)。
|
|
3973
|
+
const [edgeFilter, setEdgeFilter] = React.useState('all')
|
|
3974
|
+
const [purgeArmed, setPurgeArmed] = React.useState(false)
|
|
3975
|
+
const [clearArmed, setClearArmed] = React.useState(false)
|
|
2757
3976
|
const [error, setError] = React.useState('')
|
|
2758
3977
|
const requestId = React.useRef(0)
|
|
2759
3978
|
const mounted = React.useRef(true)
|
|
@@ -2776,13 +3995,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2776
3995
|
}
|
|
2777
3996
|
return
|
|
2778
3997
|
}
|
|
2779
|
-
const [next, list, suggested] = await Promise.all([
|
|
3998
|
+
const [next, list, suggested, queue] = await Promise.all([
|
|
2780
3999
|
call('getGraph', { libraryId, focusId: focus || null, depth: 2, limit: 200 }),
|
|
2781
4000
|
call('listEntities', { libraryId }),
|
|
2782
4001
|
call('suggestEntityMerges', { libraryId }).catch(() => null),
|
|
4002
|
+
call('getAnchorCandidates', { libraryId }).catch(() => null),
|
|
2783
4003
|
])
|
|
2784
4004
|
if (mounted.current && id === requestId.current) {
|
|
2785
|
-
setGraph(next); setEntities(list.items || []); setMerges(suggested?.items || []); setError('')
|
|
4005
|
+
setGraph(next); setEntities(list.items || []); setMerges(suggested?.items || []); setAnchor(queue || null); setError('')
|
|
2786
4006
|
}
|
|
2787
4007
|
}, [call, libraryId, focus, global])
|
|
2788
4008
|
React.useEffect(() => {
|
|
@@ -2790,6 +4010,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2790
4010
|
if (libraryId || global) refresh().catch(error => { if (active) setError(String(error.message || error)) })
|
|
2791
4011
|
return () => { active = false; requestId.current++ }
|
|
2792
4012
|
}, [refresh, files, global])
|
|
4013
|
+
// Switching libraries must not keep a selection that belongs to another one.
|
|
4014
|
+
React.useEffect(() => { setAnchorPicked(new Set()) }, [libraryId])
|
|
2793
4015
|
React.useEffect(() => {
|
|
2794
4016
|
if (!armed) return undefined
|
|
2795
4017
|
const timer = setTimeout(() => setArmed(''), 2500)
|
|
@@ -2806,6 +4028,16 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2806
4028
|
const timer = setTimeout(() => setMergeNotice(''), 9000)
|
|
2807
4029
|
return () => clearTimeout(timer)
|
|
2808
4030
|
}, [mergeNotice])
|
|
4031
|
+
React.useEffect(() => {
|
|
4032
|
+
if (!purgeArmed) return undefined
|
|
4033
|
+
const timer = setTimeout(() => setPurgeArmed(false), 2500)
|
|
4034
|
+
return () => clearTimeout(timer)
|
|
4035
|
+
}, [purgeArmed])
|
|
4036
|
+
React.useEffect(() => {
|
|
4037
|
+
if (!clearArmed) return undefined
|
|
4038
|
+
const timer = setTimeout(() => setClearArmed(false), 2500)
|
|
4039
|
+
return () => clearTimeout(timer)
|
|
4040
|
+
}, [clearArmed])
|
|
2809
4041
|
const act = async (method, payload) => {
|
|
2810
4042
|
try {
|
|
2811
4043
|
await call(method, { libraryId, ...payload })
|
|
@@ -2835,8 +4067,74 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2835
4067
|
if (mounted.current) await refresh()
|
|
2836
4068
|
} catch (failure) { if (mounted.current) setError(String(failure.message || failure)) }
|
|
2837
4069
|
}
|
|
4070
|
+
// Confirm is the only action that changes an entity's status. It also runs
|
|
4071
|
+
// the incremental mention pass on the server, so the graph below updates
|
|
4072
|
+
// with the new edges in the same round trip.
|
|
4073
|
+
const confirmEntityIds = async (ids) => {
|
|
4074
|
+
const wanted = (Array.isArray(ids) ? ids : []).filter(Boolean)
|
|
4075
|
+
if (!wanted.length || anchorBusy) return
|
|
4076
|
+
setAnchorBusy(true)
|
|
4077
|
+
try {
|
|
4078
|
+
const result = await call('confirmEntities', { libraryId, entityIds: wanted })
|
|
4079
|
+
notifyMemoryWrite('relation', libraryId)
|
|
4080
|
+
setAnchorPicked(new Set())
|
|
4081
|
+
if (mounted.current) {
|
|
4082
|
+
await refresh()
|
|
4083
|
+
if (result?.confirmed?.length) setMergeNotice(t('anchorConfirmedDone').replace('{n}', String(result.confirmed.length)))
|
|
4084
|
+
}
|
|
4085
|
+
} catch (failure) {
|
|
4086
|
+
if (mounted.current) setError(String(failure?.message || failure))
|
|
4087
|
+
} finally {
|
|
4088
|
+
if (mounted.current) setAnchorBusy(false)
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
const confirmCandidate = async (row) => {
|
|
4092
|
+
if (!row || anchorBusy) return
|
|
4093
|
+
if (row.entityId) { if (row.entityStatus === 'provisional') await confirmEntityIds([row.entityId]); return }
|
|
4094
|
+
setAnchorBusy(true)
|
|
4095
|
+
try {
|
|
4096
|
+
await call('createEntity', { libraryId, name: row.term, kind: anchorKinds[row.term] || 'person' })
|
|
4097
|
+
notifyMemoryWrite('relation', libraryId)
|
|
4098
|
+
if (mounted.current) { await refresh(); setMergeNotice(t('anchorConfirmedDone').replace('{n}', '1')) }
|
|
4099
|
+
} catch (failure) {
|
|
4100
|
+
if (mounted.current) setError(String(failure?.message || failure))
|
|
4101
|
+
} finally {
|
|
4102
|
+
if (mounted.current) setAnchorBusy(false)
|
|
4103
|
+
}
|
|
4104
|
+
}
|
|
4105
|
+
const purgeAuto = async () => {
|
|
4106
|
+
if (!purgeArmed) { setPurgeArmed(true); return }
|
|
4107
|
+
setPurgeArmed(false)
|
|
4108
|
+
try {
|
|
4109
|
+
const result = await call('purgeAutoLinks', { libraryId })
|
|
4110
|
+
notifyMemoryWrite('relation', libraryId)
|
|
4111
|
+
if (mounted.current) {
|
|
4112
|
+
await refresh()
|
|
4113
|
+
setMergeNotice(t('purgeAutoDone').replace('{n}', String(result?.removed ?? 0)))
|
|
4114
|
+
}
|
|
4115
|
+
} catch (failure) {
|
|
4116
|
+
if (mounted.current) setError(String(failure?.message || failure))
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
const clearSuppressionNow = async () => {
|
|
4120
|
+
if (!clearArmed) { setClearArmed(true); return }
|
|
4121
|
+
setClearArmed(false)
|
|
4122
|
+
try {
|
|
4123
|
+
const result = await call('clearLinkSuppression', { libraryId })
|
|
4124
|
+
notifyMemoryWrite('relation', libraryId)
|
|
4125
|
+
if (mounted.current) {
|
|
4126
|
+
await refresh()
|
|
4127
|
+
setMergeNotice(t('clearSuppressionDone').replace('{n}', String(result?.cleared ?? 0)))
|
|
4128
|
+
}
|
|
4129
|
+
} catch (failure) {
|
|
4130
|
+
if (mounted.current) setError(String(failure?.message || failure))
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
2838
4133
|
const titles = new Map(graph.nodes.map(node => [node.id, node.missing ? t('deletedNode') : node.title]))
|
|
2839
|
-
const
|
|
4134
|
+
const focusEdges = graph.edges.filter(edge => !focus || edge.from === focus || edge.to === focus).sort((a, b) => b.confidence - a.confidence)
|
|
4135
|
+
const edges = focusEdges.filter(edge => edgeFilter === 'all'
|
|
4136
|
+
|| (edgeFilter === 'auto' ? edge.source === 'auto' : edge.source !== 'auto'))
|
|
4137
|
+
const canvasGraph = { ...graph, edges }
|
|
2840
4138
|
if (global) {
|
|
2841
4139
|
return h('div', null,
|
|
2842
4140
|
error ? h('div', { className: 'dshm-toast', role: 'status' }, error) : null,
|
|
@@ -2846,7 +4144,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2846
4144
|
files.map(file => h('option', { key: file.id, value: file.id }, file.title || file.id)))),
|
|
2847
4145
|
graph.truncated ? h('p', null, t('graphLimited')) : null,
|
|
2848
4146
|
h('div', { className: 'dshm-graph-stage' },
|
|
2849
|
-
h(GraphCanvas, { key: 'global', graph, focus, onFocus: setFocus, t }),
|
|
4147
|
+
h(GraphCanvas, { key: 'global', graph: canvasGraph, focus, onFocus: setFocus, t }),
|
|
2850
4148
|
h('div', { className: 'dshm-graph-list' }, edges.length ? edges.map(edge => h('div', { key: edge.from + edge.to + edge.kind, className: 'dshm-graph-edge' },
|
|
2851
4149
|
h('div', null,
|
|
2852
4150
|
h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.from) }, titles.get(edge.from) || edge.from),
|
|
@@ -2894,19 +4192,39 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2894
4192
|
h('select', { value: focus, title: t('focusMemory'), onChange: event => setFocus(event.target.value) },
|
|
2895
4193
|
h('option', { value: '' }, t('focusMemory')),
|
|
2896
4194
|
[...files, ...entities.map(entity => ({ id: entity.id, title: entity.name }))].map(file =>
|
|
2897
|
-
h('option', { key: file.id, value: file.id }, file.title || file.id)))
|
|
4195
|
+
h('option', { key: file.id, value: file.id }, file.title || file.id))),
|
|
4196
|
+
h('select', { value: edgeFilter, title: t('edgeFilterAll'), onChange: event => setEdgeFilter(event.target.value) },
|
|
4197
|
+
h('option', { value: 'all' }, t('edgeFilterAll')),
|
|
4198
|
+
h('option', { value: 'auto' }, t('edgeFilterAuto')),
|
|
4199
|
+
h('option', { value: 'manual' }, t('edgeFilterManual'))),
|
|
4200
|
+
h(Button, {
|
|
4201
|
+
disabled: anchorBusy || !graph.edges.some(edge => edge.source === 'auto'),
|
|
4202
|
+
style: purgeArmed ? { ...S.btn, color: V.danger, borderColor: V.danger } : S.ghost,
|
|
4203
|
+
onClick: () => void purgeAuto(),
|
|
4204
|
+
}, purgeArmed ? t('purgeAutoConfirm') : t('purgeAutoLinks')),
|
|
4205
|
+
h(Button, {
|
|
4206
|
+
disabled: anchorBusy,
|
|
4207
|
+
style: clearArmed ? { ...S.btn, color: V.danger, borderColor: V.danger } : S.ghost,
|
|
4208
|
+
onClick: () => void clearSuppressionNow(),
|
|
4209
|
+
}, clearArmed ? t('clearSuppressionConfirm') : t('clearSuppression'))),
|
|
2898
4210
|
graph.truncated ? h('p', null, t('graphLimited')) : null,
|
|
2899
4211
|
// The canvas and the adjacency list are one view: the picture shows the
|
|
2900
4212
|
// shape, the list keeps the reasons readable and clickable. Neither is an
|
|
2901
4213
|
// alternate mode, so there is no toggle to forget.
|
|
2902
4214
|
h('div', { className: 'dshm-graph-stage' },
|
|
2903
|
-
h(GraphCanvas, { key: libraryId, graph, focus, onFocus: setFocus, t }),
|
|
4215
|
+
h(GraphCanvas, { key: libraryId, graph: canvasGraph, focus, onFocus: setFocus, t }),
|
|
2904
4216
|
h('div', { className: 'dshm-graph-list' }, edges.length ? edges.map(edge => h('div', { key: edge.from + edge.to + edge.kind, className: 'dshm-graph-edge' },
|
|
2905
4217
|
h('div', null, h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.from) }, titles.get(edge.from) || edge.from),
|
|
2906
4218
|
' → ', h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.to) }, titles.get(edge.to) || edge.to),
|
|
2907
4219
|
// 私有自动关联(§5.7):source:'auto' 的边来自算法/实体枢纽,不是用户手连。
|
|
2908
4220
|
// 只多一个可点读的小 Tag;kind/confidence/note 与移除按钮保持原样。
|
|
2909
4221
|
edge.source === 'auto' ? h('span', { style: { margin: '0 5px', verticalAlign: 'middle' } }, h(Tag, { tone: 'info' }, t('graphAutoLink'))) : null,
|
|
4222
|
+
// §10:自动边要能说清“为什么”——规则 + 命中的表面/字段。
|
|
4223
|
+
// 老自动边没有 evidence.rule,用 edge.rule 的 'auto' 兜底标签。
|
|
4224
|
+
edge.rule ? h('span', { style: { margin: '0 5px', verticalAlign: 'middle' } }, h(Tag, null, graphRuleText(edge.rule, t))) : null,
|
|
4225
|
+
edge.evidence?.surface ? h('span', { style: { ...S.muted, fontSize: 11, marginRight: 5 } },
|
|
4226
|
+
`「${edge.evidence.surface}」${edge.evidence.field || ''}${Number.isInteger(edge.evidence.offset) ? ' @' + edge.evidence.offset : ''}`) : null,
|
|
4227
|
+
edge.evidence?.field && !edge.evidence?.surface ? h('span', { style: { ...S.muted, fontSize: 11, marginRight: 5 } }, edge.evidence.field) : null,
|
|
2910
4228
|
h('small', null, edge.kind + ' · ' + Math.round(edge.confidence * 100) + '% · ' + edge.note)),
|
|
2911
4229
|
h('button', {
|
|
2912
4230
|
type: 'button',
|
|
@@ -2947,6 +4265,77 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2947
4265
|
onClick: () => { if (armed !== key) { setArmed(key); return } void doMerge(item) },
|
|
2948
4266
|
}, armed === key ? t('entityMergeConfirm') : t('entityMergeAction')))
|
|
2949
4267
|
})) : null,
|
|
4268
|
+
// 待确认实体(DESIGN §9.2):候选只排队列、不改状态;确认后才补挂提及边。
|
|
4269
|
+
(() => {
|
|
4270
|
+
const provisional = entities.filter(entity => entity.status === 'provisional')
|
|
4271
|
+
const tiers = anchor?.tiers || { tier1: [], tier2: [] }
|
|
4272
|
+
const visible = (list) => (Array.isArray(list) ? list : []).filter(row => row.entityStatus !== 'confirmed')
|
|
4273
|
+
const tier1 = visible(tiers.tier1)
|
|
4274
|
+
const tier2 = visible(tiers.tier2)
|
|
4275
|
+
if (!provisional.length && !tier1.length && !tier2.length) {
|
|
4276
|
+
return h('div', { style: { margin: '10px 0' } },
|
|
4277
|
+
h('div', { style: { fontSize: 12, fontWeight: 600 } }, t('anchorReviewTitle')),
|
|
4278
|
+
h('div', { style: { ...S.muted, margin: '4px 0 0' } }, t('anchorNoCandidates')))
|
|
4279
|
+
}
|
|
4280
|
+
const kindOptions = ['person', 'place', 'thing', 'org']
|
|
4281
|
+
const candidateRow = (row) => {
|
|
4282
|
+
const archived = row.entityStatus === 'archived'
|
|
4283
|
+
return h('div', { key: 'cand:' + row.term, className: 'dshm-graph-tools', style: { alignItems: 'center', flexWrap: 'wrap' } },
|
|
4284
|
+
h('span', { style: { minWidth: 0, overflowWrap: 'anywhere', fontWeight: 600 } }, row.term),
|
|
4285
|
+
row.quoted ? h(Tag, { tone: 'info' }, t('anchorSignalQuote')) : null,
|
|
4286
|
+
row.intro ? h(Tag, { tone: 'info' }, t('anchorSignalIntro')) : null,
|
|
4287
|
+
row.mixed ? h(Tag, { tone: 'info' }, t('anchorSignalMixed')) : null,
|
|
4288
|
+
archived ? h(Tag, { tone: 'warn' }, t('anchorArchivedEntity')) : null,
|
|
4289
|
+
row.entityId && !archived ? h(Tag, null, t('anchorExistingEntity')) : null,
|
|
4290
|
+
h('span', { style: { ...S.muted, fontSize: 11, whiteSpace: 'nowrap' } },
|
|
4291
|
+
t('anchorStats').replace('{df}', String(row.df)).replace('{cohesion}', String(row.cohesion)).replace('{freedom}', String(row.freedom))),
|
|
4292
|
+
archived ? null : (row.entityId
|
|
4293
|
+
? (row.entityStatus === 'provisional'
|
|
4294
|
+
? h(Button, { disabled: anchorBusy, onClick: () => void confirmEntityIds([row.entityId]) }, t('anchorConfirm'))
|
|
4295
|
+
: null)
|
|
4296
|
+
: h(React.Fragment, null,
|
|
4297
|
+
h('select', {
|
|
4298
|
+
value: anchorKinds[row.term] || 'person', title: t('entityKind'),
|
|
4299
|
+
onChange: event => setAnchorKinds(prev => ({ ...prev, [row.term]: event.target.value })),
|
|
4300
|
+
style: { ...S.input, width: 'auto' },
|
|
4301
|
+
}, kindOptions.map(kind => h('option', { key: kind, value: kind }, kind))),
|
|
4302
|
+
h(Button, { disabled: anchorBusy, onClick: () => void confirmCandidate(row) }, t('anchorConfirm')))))
|
|
4303
|
+
}
|
|
4304
|
+
return h('div', { style: { margin: '10px 0' } },
|
|
4305
|
+
h('div', { style: { fontSize: 12, fontWeight: 600 } }, t('anchorReviewTitle') + (provisional.length ? ` (${provisional.length})` : '')),
|
|
4306
|
+
h('div', { style: { ...S.muted, margin: '4px 0 6px', lineHeight: 1.5 } }, t('anchorReviewHint')),
|
|
4307
|
+
provisional.length
|
|
4308
|
+
? h('div', null,
|
|
4309
|
+
provisional.map(entity => {
|
|
4310
|
+
const picked = anchorPicked.has(entity.id)
|
|
4311
|
+
return h('label', { key: 'pending:' + entity.id, className: 'dshm-graph-tools', style: { alignItems: 'center', cursor: 'pointer' } },
|
|
4312
|
+
h('input', {
|
|
4313
|
+
type: 'checkbox', checked: picked,
|
|
4314
|
+
// .dshm-graph-tools input stretches text fields; a checkbox must not.
|
|
4315
|
+
style: { flex: 'none', width: 16, height: 16, margin: 0, padding: 0 },
|
|
4316
|
+
onChange: () => setAnchorPicked(prev => {
|
|
4317
|
+
const next = new Set(prev)
|
|
4318
|
+
if (picked) next.delete(entity.id); else next.add(entity.id)
|
|
4319
|
+
return next
|
|
4320
|
+
}),
|
|
4321
|
+
}),
|
|
4322
|
+
h('span', { style: { minWidth: 0, overflowWrap: 'anywhere' } }, entity.name),
|
|
4323
|
+
h(Tag, null, entity.kind || 'person'),
|
|
4324
|
+
h(Tag, { tone: 'info' }, t('anchorPendingEntity')))
|
|
4325
|
+
}),
|
|
4326
|
+
h(Button, {
|
|
4327
|
+
disabled: anchorBusy || anchorPicked.size === 0,
|
|
4328
|
+
onClick: () => void confirmEntityIds([...anchorPicked]),
|
|
4329
|
+
}, t('anchorConfirmSelected').replace('{n}', String(anchorPicked.size))))
|
|
4330
|
+
: null,
|
|
4331
|
+
tier1.length ? h('div', { style: { marginTop: 8 } },
|
|
4332
|
+
h('div', { style: { ...S.muted, fontSize: 11 } }, t('anchorTier1')),
|
|
4333
|
+
tier1.map(candidateRow)) : null,
|
|
4334
|
+
tier2.length ? h('details', { style: { marginTop: 6 } },
|
|
4335
|
+
h('summary', { style: { cursor: 'pointer', fontSize: 12, color: V.textDim } }, t('anchorTier2') + ` (${tier2.length})`),
|
|
4336
|
+
tier2.map(candidateRow)) : null,
|
|
4337
|
+
h('div', { style: { ...S.muted, marginTop: 6, lineHeight: 1.5, fontSize: 11 } }, t('anchorCreateHint') + ' ' + t('anchorKindHint')))
|
|
4338
|
+
})(),
|
|
2950
4339
|
entities.length === 0 ? h(Empty, null, t('entityEmpty')) : null,
|
|
2951
4340
|
// 孤立分组(§6.4 包 D):listEntities 给出 linked 派生标记。被引用的实体照常
|
|
2952
4341
|
// 渲染;孤立实体(linked=false,没有任何记忆 link/关系快照指着)收进折叠区,
|
|
@@ -2996,8 +4385,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2996
4385
|
const [data, setData] = React.useState({ items: [], total: 0, errors: [] })
|
|
2997
4386
|
const [libraryId, setLibraryId] = React.useState(initialLibraryId || '')
|
|
2998
4387
|
const [multiBlocked, setMultiBlocked] = React.useState(false)
|
|
2999
|
-
const [view, setView] = React.useState('memories')
|
|
3000
|
-
const [graphLib, setGraphLib] = React.useState('')
|
|
3001
4388
|
const [pool, setPool] = React.useState('active')
|
|
3002
4389
|
const [layer, setLayer] = React.useState('all')
|
|
3003
4390
|
const [query, setQuery] = React.useState('')
|
|
@@ -3073,13 +4460,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3073
4460
|
void load()
|
|
3074
4461
|
return () => { alive = false }
|
|
3075
4462
|
}, [call, libraryId, revision, stamp, version, firstLibraryId])
|
|
3076
|
-
React.useEffect(() => {
|
|
3077
|
-
if (graphLib && libraries.some((lib) => lib.id === graphLib)) return
|
|
3078
|
-
const selected = libraryId && libraries.some((lib) => lib.id === libraryId) ? libraryId : ''
|
|
3079
|
-
const first = selected || libraries[0]?.id || ''
|
|
3080
|
-
if (first) setGraphLib(first)
|
|
3081
|
-
else if (graphLib) setGraphLib('')
|
|
3082
|
-
}, [graphLib, libraryId, libraries])
|
|
3083
4463
|
React.useEffect(() => {
|
|
3084
4464
|
if (!detail) return undefined
|
|
3085
4465
|
const onKey = (event) => { if (event.key === 'Escape') setDetail(null) }
|
|
@@ -3372,35 +4752,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3372
4752
|
h(Button, { style: S.ghost, onClick: () => setDetail(null) }, t('close')))))
|
|
3373
4753
|
: null
|
|
3374
4754
|
|
|
3375
|
-
const validLib = (id) => id && libraries.some((lib) => lib.id === id) ? id : ''
|
|
3376
|
-
// No private library is still a meaningful graph state: global edges do not
|
|
3377
|
-
// belong to any library, so the selector defaults to them instead of an
|
|
3378
|
-
// empty "no libraries" card.
|
|
3379
|
-
const graphLibrary = graphLib === GLOBAL_GRAPH_ID || libraries.length === 0
|
|
3380
|
-
? GLOBAL_GRAPH_ID
|
|
3381
|
-
: (validLib(graphLib) || validLib(libraryId) || libraries[0].id)
|
|
3382
|
-
const showGlobalGraph = graphLibrary === GLOBAL_GRAPH_ID
|
|
3383
|
-
const graphFiles = React.useMemo(() => items
|
|
3384
|
-
.filter(item => showGlobalGraph ? item.libraryId === null : item.libraryId === graphLibrary)
|
|
3385
|
-
.map(item => ({ id: item.id, title: item.title })), [items, graphLibrary, showGlobalGraph])
|
|
3386
|
-
const graphView = h('div', { className: 'dshm-card dshm-wall-graph' },
|
|
3387
|
-
h(React.Fragment, null,
|
|
3388
|
-
h('div', { className: 'dshm-graph-tools' },
|
|
3389
|
-
h('select', {
|
|
3390
|
-
value: graphLibrary,
|
|
3391
|
-
title: showGlobalGraph ? t('graphGlobalScope') : (libraries.find((lib) => lib.id === graphLibrary)?.scopeKey || t('currentLibrary')),
|
|
3392
|
-
// One selection drives both views, otherwise the graph's focus list can
|
|
3393
|
-
// be empty when the wall is filtered to a different library.
|
|
3394
|
-
onChange: (event) => {
|
|
3395
|
-
const value = event.target.value
|
|
3396
|
-
setGraphLib(value)
|
|
3397
|
-
if (value !== GLOBAL_GRAPH_ID) setLibraryId(value)
|
|
3398
|
-
},
|
|
3399
|
-
},
|
|
3400
|
-
h('option', { key: GLOBAL_GRAPH_ID, value: GLOBAL_GRAPH_ID }, t('graphGlobalScope')),
|
|
3401
|
-
libraries.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries))))),
|
|
3402
|
-
h(GraphPanel, { key: graphLibrary, call, libraryId: showGlobalGraph ? null : graphLibrary, files: graphFiles, t, global: showGlobalGraph })))
|
|
3403
|
-
|
|
3404
4755
|
// Category filters used to reuse the compact nav pills (2px gap, 30px high) and
|
|
3405
4756
|
// stacked directly on top of each other. Give every group its own segmented
|
|
3406
4757
|
// control, a label and breathing room so the state/layer filters are distinct.
|
|
@@ -3484,12 +4835,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3484
4835
|
})() : null
|
|
3485
4836
|
|
|
3486
4837
|
return h('div', { className: 'dshm-wall' },
|
|
3487
|
-
wallTabGroup([['memories', t('viewMemories')], ['relations', t('viewRelations')]], view, setView, { className: 'dshm-wall-views' }),
|
|
3488
4838
|
error || data.errors?.length ? h('p', { className: 'dshm-error', role: 'alert' }, error || t('wallReadError')) : null,
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
: h(React.Fragment, null,
|
|
3492
|
-
// 组分类:私有 / 全局(默认私有、私有靠前)。计数按各自的块算,切换即重置多选。
|
|
4839
|
+
h(React.Fragment, null,
|
|
4840
|
+
// 组分类:私有 / 全局(默认私有、私有靠前)。计数按各自的块算,切换即重置多选。
|
|
3493
4841
|
// The library selector belongs to the scope row, not the search row: it
|
|
3494
4842
|
// narrows the same private block the two tabs switch between.
|
|
3495
4843
|
wallTabGroup(scopeItems, scope, (value) => { setScope(value); exitMulti() }, { label: t('wallFilterScope'), marginTop: 10, extra: librarySelect }),
|
|
@@ -3985,11 +5333,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3985
5333
|
prompts: 7,
|
|
3986
5334
|
stats: 8,
|
|
3987
5335
|
memories: 9,
|
|
3988
|
-
//
|
|
3989
|
-
//
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
5336
|
+
// graph:10 插在 memories 之后;后续页顺延,三处清单(SETTINGS_PAGES /
|
|
5337
|
+
// PAGE_NAMES / PAGE)必须同序,否则导航会整片错位。
|
|
5338
|
+
graph: 10,
|
|
5339
|
+
logs: 11,
|
|
5340
|
+
lexicon: 12,
|
|
5341
|
+
help: 13,
|
|
3993
5342
|
}
|
|
3994
5343
|
const call = useRpc(ctx)
|
|
3995
5344
|
const sessionId = useCurrentSession(ctx)
|
|
@@ -4014,6 +5363,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4014
5363
|
const progressSpeedRef = React.useRef(new Map())
|
|
4015
5364
|
// 全局记忆页"查看此记忆"的接力棒:带着 id 切到 MemU 记忆页,墙直接开对应抽屉。
|
|
4016
5365
|
const [wallFocus, setWallFocus] = React.useState(null)
|
|
5366
|
+
// 关系图谱是沉浸式页面:默认解除 980px 宽度锁,用户还能收起左导航腾满宽度。
|
|
5367
|
+
const [graphNavHidden, setGraphNavHidden] = React.useState(false)
|
|
4017
5368
|
// Success messages need their own slot: reusing `error` would paint a good
|
|
4018
5369
|
// outcome in red and make the next real failure easy to miss.
|
|
4019
5370
|
const [notice, setNotice] = React.useState('')
|
|
@@ -4084,6 +5435,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4084
5435
|
// stayed in the same list with a different tag, so the mess you were trying to
|
|
4085
5436
|
// tidy up never actually left. Two lists, and only the archived one offers delete.
|
|
4086
5437
|
const [browseView, setBrowseView] = React.useState('active')
|
|
5438
|
+
// 当前库内的即时过滤:列表本来就已取回(browseLibrary),不再加一次 RPC。
|
|
5439
|
+
const [browseQuery, setBrowseQuery] = React.useState('')
|
|
4087
5440
|
// Permanent deletion is two clicks, and only for the row that was armed.
|
|
4088
5441
|
const [deleteArmed, setDeleteArmed] = React.useState('')
|
|
4089
5442
|
React.useEffect(() => {
|
|
@@ -4697,6 +6050,38 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4697
6050
|
setPage(PAGE.browser)
|
|
4698
6051
|
void openBrowser(libraryId)
|
|
4699
6052
|
}
|
|
6053
|
+
// 手动整理复用侧边栏同一条通道:generatePrivate(会话维度、force 语义一致),
|
|
6054
|
+
// 不新增端点。一次点击最多发起 5 个对话——整理是真金白银的模型调用,
|
|
6055
|
+
// 不能一键把整库几十个会话全点着;剩下的再按一次即可。
|
|
6056
|
+
// 计数全部取每个调用的返回值(ok / running / error),不估算。
|
|
6057
|
+
const consolidateLibrary = async (libraryId) => {
|
|
6058
|
+
if (!libraryId || !confirmAction('consolidate:' + libraryId)) return
|
|
6059
|
+
setBusy(true)
|
|
6060
|
+
try {
|
|
6061
|
+
const res = await call('listSessions', { limit: 200 })
|
|
6062
|
+
const targets = (res?.sessions || []).filter(row => row.libraryId === libraryId)
|
|
6063
|
+
if (!targets.length) { setError(t('consolidateNone')); return }
|
|
6064
|
+
let started = 0, running = 0, failed = 0
|
|
6065
|
+
for (const row of targets.slice(0, 5)) {
|
|
6066
|
+
try {
|
|
6067
|
+
const one = await call('generatePrivate', { sessionId: row.id })
|
|
6068
|
+
if (one?.ok === true) started++
|
|
6069
|
+
else if (one?.running) running++
|
|
6070
|
+
else failed++
|
|
6071
|
+
} catch { failed++ }
|
|
6072
|
+
}
|
|
6073
|
+
const rest = Math.max(0, targets.length - 5)
|
|
6074
|
+
setNotice(t('consolidateDone')
|
|
6075
|
+
.replace('{started}', String(started))
|
|
6076
|
+
.replace('{running}', String(running))
|
|
6077
|
+
.replace('{failed}', String(failed))
|
|
6078
|
+
.replace('{rest}', rest > 0 ? t('consolidateRest').replace('{n}', String(rest)) : ''))
|
|
6079
|
+
} catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
|
|
6080
|
+
}
|
|
6081
|
+
const consolidateButton = (libraryId, style = S.ghost) => h(Button, {
|
|
6082
|
+
style, disabled: busy || !libraryId, title: t('consolidateHint'),
|
|
6083
|
+
onClick: () => { void consolidateLibrary(libraryId) },
|
|
6084
|
+
}, actionLabel('consolidate:' + libraryId, t('consolidateNow')))
|
|
4700
6085
|
const addMemory = async () => {
|
|
4701
6086
|
if (!browseLibId || !newMem.content.trim()) return
|
|
4702
6087
|
setBrowseBusy(true)
|
|
@@ -5668,6 +7053,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5668
7053
|
h(Field, { label: t('sleepAfterIdleMinutes') }, h('input', { type: 'number', min: 1, style: S.input, value: settings.sleepAfterIdleMinutes ?? 2, onChange: (e) => setSetting('sleepAfterIdleMinutes', Number(e.target.value)) })),
|
|
5669
7054
|
h(Field, { label: t('autoCurateEveryHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.autoCurateEveryHours ?? 0, onChange: (e) => setSetting('autoCurateEveryHours', Number(e.target.value)) })),
|
|
5670
7055
|
h(Field, { label: t('autoCurateSessionLimit') }, h('input', { type: 'number', min: 1, max: 10, style: S.input, value: settings.autoCurateSessionLimit ?? 8, onChange: (e) => setSetting('autoCurateSessionLimit', Number(e.target.value)) })),
|
|
7056
|
+
h(Field, { label: t('autoLinkMode') },
|
|
7057
|
+
h('select', { style: S.input, value: settings.autoLinkMode || 'suggest', onChange: (e) => setSetting('autoLinkMode', e.target.value) },
|
|
7058
|
+
h('option', { value: 'suggest' }, t('autoLinkSuggest')),
|
|
7059
|
+
h('option', { value: 'deterministic' }, t('autoLinkDeterministic')),
|
|
7060
|
+
h('option', { value: 'off' }, t('autoLinkOff')))),
|
|
7061
|
+
h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('autoLinkHint')),
|
|
5671
7062
|
h(Field, { label: t('consolidationModelMode') },
|
|
5672
7063
|
h('select', { style: S.input, value: consolidationMode, onChange: (e) => setSetting('consolidationModelMode', e.target.value) },
|
|
5673
7064
|
h('option', { value: 'inherit' }, t('consolidationModeInherit')),
|
|
@@ -5713,6 +7104,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5713
7104
|
h('strong', null, lib.name || lib.id),
|
|
5714
7105
|
h('div', { style: S.muted }, lib.id)),
|
|
5715
7106
|
h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
|
|
7107
|
+
consolidateButton(lib.id),
|
|
5716
7108
|
h(Button, { onClick: () => openBrowserFromLibrary(lib.id) }, t('browse')),
|
|
5717
7109
|
h(Button, { onClick: () => archiveLibrary(lib.id), disabled: busy }, t('archive')))),
|
|
5718
7110
|
h('div', { style: S.muted }, `${t('scope')}: ${lib.scopeKey || '—'}`),
|
|
@@ -6082,7 +7474,11 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6082
7474
|
|
|
6083
7475
|
const browsePool = file => file.status === 'pending_review' ? 'review' : file.status === 'archived' ? 'archived'
|
|
6084
7476
|
: ['suppressed', 'expired', 'superseded'].includes(file.status) || file.expiresAt && Date.parse(file.expiresAt) <= Date.now() ? 'inactive' : 'active'
|
|
6085
|
-
const
|
|
7477
|
+
const browseQueryText = browseQuery.trim().toLowerCase()
|
|
7478
|
+
const browseMatched = file => !browseQueryText
|
|
7479
|
+
|| [file.title, file.content, file.id, ...(Array.isArray(file.tags) ? file.tags : [])]
|
|
7480
|
+
.some(value => String(value || '').toLowerCase().includes(browseQueryText))
|
|
7481
|
+
const archShown = browseFiles.filter(file => browsePool(file) === browseView && browseMatched(file))
|
|
6086
7482
|
// An archived row is a body you are deciding about, not a draft you are editing:
|
|
6087
7483
|
// no title/content/tag fields, just enough to recognise it plus the two exits.
|
|
6088
7484
|
const renderArchivedMemory = (f) => h('div', { key: f.id, style: S.item },
|
|
@@ -6137,6 +7533,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6137
7533
|
title: t('browser'),
|
|
6138
7534
|
desc: t('descBrowser'),
|
|
6139
7535
|
right: h('div', { style: { display: 'flex', gap: 8, flexShrink: 0 } },
|
|
7536
|
+
consolidateButton(browseLibId),
|
|
6140
7537
|
h(Button, { onClick: () => importLibraryNow(), disabled: !browseLibId || browseBusy, style: S.ghost, title: t('importHint') }, t('importJson')),
|
|
6141
7538
|
h(Button, { onClick: () => exportLibraryNow(), disabled: !browseLibId, style: S.ghost }, t('export')),
|
|
6142
7539
|
h(Button, { onClick: () => exportLibraryNow({ includeAttachments: true }), disabled: !browseLibId, title: t('exportZip') }, t('exportZip')),
|
|
@@ -6147,15 +7544,29 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6147
7544
|
h('select', {
|
|
6148
7545
|
style: { ...S.input, flex: 1 }, value: browseLibId,
|
|
6149
7546
|
title: (state.libraries || []).find((lib) => lib.id === browseLibId)?.scopeKey || t('currentLibrary'),
|
|
6150
|
-
onChange: (e) => setBrowseLibId(e.target.value),
|
|
7547
|
+
onChange: (e) => { setBrowseLibId(e.target.value); setBrowseQuery('') },
|
|
6151
7548
|
}, (state.libraries || []).map((l) => h('option', { key: l.id, value: l.id }, libraryOptionLabel(l, state.libraries || []))))),
|
|
7549
|
+
browseView === 'relations' ? null : h('div', { style: S.row },
|
|
7550
|
+
h('span', { style: S.label }, t('browseSearch')),
|
|
7551
|
+
h('input', {
|
|
7552
|
+
style: { ...S.input, flex: 1 }, type: 'search', value: browseQuery,
|
|
7553
|
+
placeholder: t('browseSearchPlaceholder'), 'aria-label': t('browseSearch'),
|
|
7554
|
+
onChange: (e) => setBrowseQuery(e.target.value),
|
|
7555
|
+
}),
|
|
7556
|
+
browseQuery
|
|
7557
|
+
? h('span', { style: S.muted, role: 'status' },
|
|
7558
|
+
`${archShown.length} / ${browseFiles.filter(file => browsePool(file) === browseView).length}`)
|
|
7559
|
+
: null,
|
|
7560
|
+
browseQuery
|
|
7561
|
+
? h(Button, { style: S.ghost, onClick: () => setBrowseQuery(''), title: t('browseSearchClear') }, t('browseSearchClear'))
|
|
7562
|
+
: null),
|
|
6152
7563
|
browseSource === 'index'
|
|
6153
7564
|
? h('div', { style: { ...S.muted, marginTop: 6 } }, t('browserIndexOnly'))
|
|
6154
7565
|
: null,
|
|
6155
7566
|
h('div', { className: 'dshm-nav-list is-row', role: 'tablist', style: { marginTop: 10 } },
|
|
6156
7567
|
[['active', t('browseActiveTab')], ['archived', t('browseArchivedTab')], ['review', t('poolReview')], ['inactive', t('poolInactive')], ['relations', t('relations')]].map((pair) => {
|
|
6157
7568
|
const value = pair[0]
|
|
6158
|
-
const count = browseFiles.filter(file => browsePool(file) === value).length
|
|
7569
|
+
const count = browseFiles.filter(file => browsePool(file) === value && browseMatched(file)).length
|
|
6159
7570
|
return h('button', {
|
|
6160
7571
|
key: value,
|
|
6161
7572
|
type: 'button',
|
|
@@ -6406,6 +7817,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6406
7817
|
{ label: t('pageStats'), overline: 'STATS', desc: t('descStats'), icon: GlyphChart },
|
|
6407
7818
|
]
|
|
6408
7819
|
pageDefs.push({ label: t('pageMemories'), overline: 'MEMU', desc: t('descMemories'), icon: GlyphLayers })
|
|
7820
|
+
// 关系图谱是独立页,放在「MemU 记忆」下面一页;复用现有 glyph,不新增资产。
|
|
7821
|
+
pageDefs.push({ label: t('pageGraph'), overline: 'GRAPH', desc: t('descGraph'), icon: GlyphChart })
|
|
6409
7822
|
pageDefs.push({ label: t('pageLogs'), overline: 'ACTIVITY', desc: t('descLogs'), icon: GlyphText })
|
|
6410
7823
|
pageDefs.push({ label: t('pageLexicon'), overline: 'LEXICON', desc: t('descLexicon'), icon: GlyphStack })
|
|
6411
7824
|
pageDefs.push({ label: t('pageHelp'), overline: 'GUIDE', desc: t('descHelp'), icon: GlyphQuestion })
|
|
@@ -6428,6 +7841,19 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6428
7841
|
if (item.libraryId) { setBrowseLibId(item.libraryId); setPage(PAGE.browser); void openBrowser(item.libraryId) }
|
|
6429
7842
|
else setPage(PAGE.global)
|
|
6430
7843
|
} }))
|
|
7844
|
+
// 关系图谱独立成页:库/全局选择器由 GraphStudioPanel 自持,刷新随 SettingsPage
|
|
7845
|
+
// 已有的心跳(revision/stamp)走 beat,页内不再开第二套轮询。
|
|
7846
|
+
// §7.1「两个壳一份实现」:完整工作室只在独立 WebUI 里渲染。宿主设置页/侧栏
|
|
7847
|
+
// 里这一页只给一个按钮,点了直接打开 WebUI 的关系图谱页,不再嵌第二份画布。
|
|
7848
|
+
const graphBlock = standalone
|
|
7849
|
+
? h(GraphStudioPanel, {
|
|
7850
|
+
call, libraries: state.libraries || [], revision: state.revision, stamp: state.stamp, t,
|
|
7851
|
+
navHidden: graphNavHidden, onToggleNav: () => setGraphNavHidden(value => !value),
|
|
7852
|
+
})
|
|
7853
|
+
: h(Section, { title: t('pageGraph'), desc: t('descGraph'), icon: GlyphChart },
|
|
7854
|
+
h('div', { style: S.row },
|
|
7855
|
+
h(Button, { primary: true, title: t('openGraphStudioHint'),
|
|
7856
|
+
onClick: () => openWebUiPage('graph') }, t('openGraphStudio'))))
|
|
6431
7857
|
// 词典页:sourceMemoryId →「来源记忆 ↗」复用全局记忆页的 wallFocus 接力棒,
|
|
6432
7858
|
// 跳到 MemU 记忆页并直接打开对应条目的抽屉。
|
|
6433
7859
|
const lexiconBlock = h(LexiconPanel, {
|
|
@@ -6640,19 +8066,30 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6640
8066
|
row.detail
|
|
6641
8067
|
? h('pre', { style: { ...S.muted, margin: '6px 0 0', fontSize: 11, whiteSpace: 'pre-wrap', wordBreak: 'break-all' } }, JSON.stringify(row.detail).slice(0, 600))
|
|
6642
8068
|
: null)))))
|
|
6643
|
-
const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, logsBlock, lexiconBlock, helpBlock]
|
|
8069
|
+
const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, graphBlock, logsBlock, lexiconBlock, helpBlock]
|
|
6644
8070
|
|
|
6645
8071
|
// Settings uses a left nav with a sliding indicator (the sidebar keeps its
|
|
6646
8072
|
// top segments). The indicator is one absolutely-positioned element moved by
|
|
6647
8073
|
// a transform, so the active item animates without per-item flicker.
|
|
6648
8074
|
const active = pageDefs[page] || pageDefs[0]
|
|
8075
|
+
// 沉浸式只给独立 WebUI 的完整工作室用。宿主设置页里这一页现在只是一个按钮,
|
|
8076
|
+
// 不能再套 is-graph-wide:那会把本来横排的导航强制成 158px 竖排。
|
|
8077
|
+
const graphWide = standalone && page === PAGE.graph
|
|
6649
8078
|
return h('div', {
|
|
6650
|
-
className:
|
|
8079
|
+
className: `dshm-root${graphWide ? ' is-graph-wide' : ''}${graphWide && graphNavHidden ? ' is-graph-navless' : ''}`,
|
|
6651
8080
|
'data-dshm-surface': embedded ? 'sidebar' : 'dialog',
|
|
6652
8081
|
style: { '--dshm-nav-h': `${NAV_ITEM_H}px`, '--dshm-nav-gap': `${NAV_GAP}px` },
|
|
6653
8082
|
},
|
|
6654
8083
|
h('div', { className: 'dshm-shell' },
|
|
6655
8084
|
h('nav', { className: 'dshm-nav', role: 'tablist', 'aria-orientation': 'vertical' },
|
|
8085
|
+
// 贴在左导航右边缘的收起小块:收起后本身仍留一条窄边,可随时展开。
|
|
8086
|
+
graphWide ? h('button', {
|
|
8087
|
+
type: 'button', className: 'dshm-nav-handle',
|
|
8088
|
+
title: graphNavHidden ? t('gsShowNav') : t('gsHideNav'),
|
|
8089
|
+
'aria-label': graphNavHidden ? t('gsShowNav') : t('gsHideNav'),
|
|
8090
|
+
'aria-expanded': String(!graphNavHidden),
|
|
8091
|
+
onClick: () => setGraphNavHidden(value => !value),
|
|
8092
|
+
}, graphNavHidden ? '›' : '‹') : null,
|
|
6656
8093
|
h('div', { className: 'dshm-brand' },
|
|
6657
8094
|
h('div', { className: 'dshm-brand-tile' }, h('img', { src: '/dsh-memu-memory/ui-assets/icon.png', alt: '', width: 32, height: 32 })),
|
|
6658
8095
|
h('div', { style: { minWidth: 0 } },
|