dsh-sixlayer-memory 0.0.0-stage → 2.0.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/CHANGELOG.md +123 -0
- package/README.md +292 -3
- package/catalog/.index.json +111704 -0
- package/catalog/parts.json +8808 -0
- package/cordis.patch.yml +8 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +51 -0
- package/docs//347/224/237/345/221/275/345/221/250/346/234/237-/350/207/252/345/212/250/345/217/254/345/233/236/344/270/216/345/200/231/351/200/211.md +103 -0
- package/icon.svg +8 -0
- package/lib/client.js +1209 -0
- package/lib/index.js +741 -0
- package/lib/memory/affect-alert.js +60 -0
- package/lib/memory/affect-events.js +201 -0
- package/lib/memory/affect-report.js +61 -0
- package/lib/memory/api.js +194 -0
- package/lib/memory/crypto.js +68 -0
- package/lib/memory/detail.js +43 -0
- package/lib/memory/embed.js +394 -0
- package/lib/memory/emotion.js +99 -0
- package/lib/memory/explain.js +207 -0
- package/lib/memory/importer.js +215 -0
- package/lib/memory/inject.js +193 -0
- package/lib/memory/ledger.js +101 -0
- package/lib/memory/lifecycle.js +491 -0
- package/lib/memory/notify.js +164 -0
- package/lib/memory/policy.js +182 -0
- package/lib/memory/qq-official.js +196 -0
- package/lib/memory/qq.js +326 -0
- package/lib/memory/recorder.js +241 -0
- package/lib/memory/redact.js +120 -0
- package/lib/memory/scanners.js +142 -0
- package/lib/memory/schema.js +205 -0
- package/lib/memory/service-plugin.js +69 -0
- package/lib/memory/service.js +123 -0
- package/lib/memory/shadow.js +133 -0
- package/lib/memory/store.js +1138 -0
- package/lib/memory/timeline.js +74 -0
- package/lib/memory/tokenize.js +66 -0
- package/lib/memory/tools.js +1371 -0
- package/lib/memory/util.js +129 -0
- package/lib/parts/index.js +154 -0
- package/lib/parts/installer.js +294 -0
- package/lib/parts/jobs.js +91 -0
- package/lib/parts/library.js +91 -0
- package/lib/probe-plugin.js +38 -0
- package/lib/voice/board-asr.js +31 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +114 -3
- package/tools/backfill-affect.mjs +82 -0
- package/tools/eval.mjs +88 -0
- package/tools/p1.mjs +108 -0
- package/tools/p10.mjs +36 -0
- package/tools/p11.mjs +51 -0
- package/tools/p12.mjs +53 -0
- package/tools/p13.mjs +65 -0
- package/tools/p14.mjs +66 -0
- package/tools/p15.mjs +43 -0
- package/tools/p16.mjs +42 -0
- package/tools/p17.mjs +29 -0
- package/tools/p18.mjs +48 -0
- package/tools/p19.mjs +50 -0
- package/tools/p2.mjs +59 -0
- package/tools/p20.mjs +54 -0
- package/tools/p21.mjs +42 -0
- package/tools/p22.mjs +32 -0
- package/tools/p23.mjs +43 -0
- package/tools/p24.mjs +40 -0
- package/tools/p25.mjs +151 -0
- package/tools/p26.mjs +113 -0
- package/tools/p27.mjs +89 -0
- package/tools/p28.mjs +60 -0
- package/tools/p3.mjs +54 -0
- package/tools/p4.mjs +73 -0
- package/tools/p5.mjs +117 -0
- package/tools/p6.mjs +122 -0
- package/tools/p8.mjs +50 -0
- package/tools/p9.mjs +35 -0
- package/tools/phase2.mjs +159 -0
- package/tools/preflight.mjs +320 -0
- package/tools/push-via-api.mjs +187 -0
- package/tools/quarterly.mjs +129 -0
- package/tools/refresh-catalog.mjs +60 -0
- package/tools/register-bundle.mjs +38 -0
- package/tools/review.mjs +156 -0
- package/tools/selfcheck.mjs +80 -0
- package/tools/smoke.mjs +112 -0
- package/tools/testset-v1.json +70 -0
- package/tools/validate-tools.mjs +150 -0
- package/tools/verify-all.mjs +39 -0
- package/tools/write-chain.mjs +139 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1209 @@
|
|
|
1
|
+
// dsh-memory-core · Client bundle(P4)
|
|
2
|
+
// 设置页「记忆底座」:总览 / 检索 / 待审 / 审计。
|
|
3
|
+
// 数据只走 RPC(/memory-core),UI 不直接读库;写操作只有审核。
|
|
4
|
+
window.__ModuleLoader__.load({
|
|
5
|
+
id: 'dsh-sixlayer-memory',
|
|
6
|
+
factory: function (require) {
|
|
7
|
+
var module = { exports: {} }
|
|
8
|
+
var exports = module.exports
|
|
9
|
+
var React = require('react')
|
|
10
|
+
|
|
11
|
+
var name = 'dsh-sixlayer-memory'
|
|
12
|
+
var inject = ['slots', 'connection']
|
|
13
|
+
|
|
14
|
+
var CSS = [
|
|
15
|
+
'.mc-root{display:flex;flex-direction:column;gap:14px;padding:4px 0 28px;font-size:13px;line-height:1.6}',
|
|
16
|
+
'.mc-tabs{display:flex;gap:6px;border-bottom:1px solid var(--dsh-border,rgba(127,127,127,.25));padding-bottom:8px}',
|
|
17
|
+
'.mc-tab{border:1px solid transparent;border-radius:999px;padding:5px 14px;background:transparent;color:inherit;cursor:pointer;font-size:13px}',
|
|
18
|
+
'.mc-tab:hover{background:rgba(127,127,127,.1)}',
|
|
19
|
+
'.mc-tab-on{border-color:var(--dsh-border,rgba(127,127,127,.35));background:rgba(127,127,127,.14);font-weight:600}',
|
|
20
|
+
'.mc-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:8px}',
|
|
21
|
+
'.mc-card{border:1px solid var(--dsh-border,rgba(127,127,127,.22));border-radius:10px;padding:10px 12px}',
|
|
22
|
+
'.mc-k{opacity:.6;font-size:12px}',
|
|
23
|
+
'.mc-v{font-size:19px;font-weight:650;line-height:1.3}',
|
|
24
|
+
'.mc-ok{color:var(--dsh-success,#37a86b)}.mc-warn{color:var(--dsh-warning,#c98a24)}.mc-err{color:var(--dsh-danger,#c0392b)}',
|
|
25
|
+
'.mc-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}',
|
|
26
|
+
'.mc-input{flex:1;min-width:180px;border:1px solid var(--dsh-border,rgba(127,127,127,.35));border-radius:8px;padding:7px 10px;background:transparent;color:inherit;font:inherit}',
|
|
27
|
+
'.mc-btn{border:1px solid var(--dsh-border,rgba(127,127,127,.35));border-radius:999px;padding:5px 14px;background:transparent;color:inherit;cursor:pointer}',
|
|
28
|
+
'.mc-btn:hover{background:rgba(127,127,127,.12)}',
|
|
29
|
+
'.mc-btn[disabled]{opacity:.45;cursor:default}',
|
|
30
|
+
'.mc-list{border:1px solid var(--dsh-border,rgba(127,127,127,.22));border-radius:10px;overflow:hidden}',
|
|
31
|
+
'.mc-item{padding:9px 12px;border-bottom:1px solid rgba(127,127,127,.14);cursor:pointer}',
|
|
32
|
+
'.mc-item:last-child{border-bottom:none}',
|
|
33
|
+
'.mc-item:hover{background:rgba(127,127,127,.09)}',
|
|
34
|
+
'.mc-meta{opacity:.65;font-size:12px}',
|
|
35
|
+
'.mc-bar{height:8px;border-radius:4px;background:rgba(127,127,127,.2);overflow:hidden;margin-top:4px}',
|
|
36
|
+
'.mc-bar>i{display:block;height:100%;background:var(--dsh-accent,#4b7bec)}',
|
|
37
|
+
'.mc-pre{margin:0;max-height:280px;overflow:auto;white-space:pre-wrap;word-break:break-word;border:1px solid var(--dsh-border,rgba(127,127,127,.22));border-radius:10px;padding:10px;font-size:12px}',
|
|
38
|
+
'.mc-empty{opacity:.6;padding:18px 4px}',
|
|
39
|
+
'.mc-banner{border-radius:10px;padding:8px 12px;border:1px solid var(--dsh-danger,#c0392b)}',
|
|
40
|
+
'.mc-tag{font-size:11px;border:1px solid var(--dsh-border,rgba(127,127,127,.3));border-radius:6px;padding:1px 6px;margin-left:6px}',
|
|
41
|
+
].join('\n')
|
|
42
|
+
|
|
43
|
+
function h(tag, props) {
|
|
44
|
+
var children = [].slice.call(arguments, 2)
|
|
45
|
+
return React.createElement.apply(React, [tag, props].concat(children))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 一条记录 → 给人看的三段:标题 / 一句人话 / 小标签(类别 + 时间)。
|
|
50
|
+
* 宿主返回的 display 是"人话"来源;没有就退回摘要,保证旧数据也能显示。
|
|
51
|
+
*/
|
|
52
|
+
function dispOf(row) {
|
|
53
|
+
var d = (row && row.display) || {}
|
|
54
|
+
return {
|
|
55
|
+
title: d.title || (row && (row.summary || row.snippet)) || (row && row.record_id) || '(空)',
|
|
56
|
+
plain: d.plain || '',
|
|
57
|
+
meta: [d.kind, d.when].filter(Boolean).join(' · '),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 待审原因 → 人话。 */
|
|
62
|
+
function reasonOf(code) {
|
|
63
|
+
var map = {
|
|
64
|
+
'unverified-source': '来源没验证过(不是你自己敲的字)',
|
|
65
|
+
'contradiction-suspect': '这条和已有记忆可能冲突',
|
|
66
|
+
'quarantined': '内容里有可疑指令,先隔离',
|
|
67
|
+
}
|
|
68
|
+
return map[String(code || '')] || '需要你看一眼'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 详情卡:一条记忆的全部信息(人话在上,原始正文与记录号在下)。 */
|
|
72
|
+
function DetailCard(props) {
|
|
73
|
+
var d = props.detail
|
|
74
|
+
if (!d) return null
|
|
75
|
+
var dp = dispOf(d)
|
|
76
|
+
var facts = [
|
|
77
|
+
['记的是', dp.meta || '—'],
|
|
78
|
+
['层级', d.layer || '—'],
|
|
79
|
+
['分级', d.sad_level || '—'],
|
|
80
|
+
['信任', d.trust_level || '—'],
|
|
81
|
+
['来源', d.source_channel || '—'],
|
|
82
|
+
['重要度', d.alpha == null || d.alpha === null ? '未评分' : Number(d.alpha).toFixed(2)],
|
|
83
|
+
]
|
|
84
|
+
return h('div', { className: 'mc-card', style: { marginTop: '10px' } },
|
|
85
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between', alignItems: 'flex-start' } },
|
|
86
|
+
h('div', { style: { fontWeight: 600, fontSize: '15px' } }, dp.title),
|
|
87
|
+
props.onClose ? h('button', { className: 'mc-btn', onClick: props.onClose }, '关闭') : null),
|
|
88
|
+
dp.plain ? h('div', { className: 'mc-meta', style: { marginTop: '2px' } }, dp.plain) : null,
|
|
89
|
+
h('div', { className: 'mc-grid', style: { marginTop: '8px' } }, facts.map(function (kv) {
|
|
90
|
+
return h('div', { key: kv[0] },
|
|
91
|
+
h('div', { className: 'mc-k' }, kv[0]),
|
|
92
|
+
h('div', null, String(kv[1])))
|
|
93
|
+
})),
|
|
94
|
+
(d.tags && d.tags.length) ? h('div', { className: 'mc-row', style: { marginTop: '8px' } }, d.tags.map(function (t) {
|
|
95
|
+
return h('span', { key: t, className: 'mc-tag' }, t)
|
|
96
|
+
})) : null,
|
|
97
|
+
d.denied
|
|
98
|
+
? h('div', { className: 'mc-banner', style: { marginTop: '8px' } }, d.reason || '这条需要授权才能看正文')
|
|
99
|
+
: h('pre', { className: 'mc-pre', style: { marginTop: '8px', whiteSpace: 'pre-wrap' } }, d.content || d.summary || ''),
|
|
100
|
+
h('div', { className: 'mc-meta', style: { marginTop: '6px', opacity: '.55', fontSize: '11px' } }, '记录号 ' + (d.record_id || '—')),
|
|
101
|
+
(d.neighbors && d.neighbors.length) ? h('div', { style: { marginTop: '10px' } },
|
|
102
|
+
h('div', { className: 'mc-k' }, '相关记忆(' + d.neighbors.length + ')'),
|
|
103
|
+
d.neighbors.map(function (n) {
|
|
104
|
+
return h('div', {
|
|
105
|
+
key: n.record_id, className: 'mc-meta', style: { cursor: 'pointer', marginTop: '3px' },
|
|
106
|
+
onClick: function () { if (props.onOpen) props.onOpen(n.record_id) },
|
|
107
|
+
}, '· ' + n.title + (n.reasons && n.reasons.length ? '(' + n.reasons.join('、') + ')' : ''))
|
|
108
|
+
})) : null)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 列表一行:标题 + 人话 + 小标签,不露 record_id。 */
|
|
112
|
+
function MemRow(props) {
|
|
113
|
+
var d = dispOf(props.row)
|
|
114
|
+
return h('div', { className: 'mc-item', onClick: props.onClick, style: props.style },
|
|
115
|
+
h('div', { style: { fontWeight: 600 } }, d.title),
|
|
116
|
+
d.plain ? h('div', { className: 'mc-meta', style: { marginTop: '2px' } }, d.plain) : null,
|
|
117
|
+
d.meta ? h('div', { className: 'mc-meta', style: { marginTop: '2px', opacity: '.55', fontSize: '11px' } }, d.meta) : null,
|
|
118
|
+
props.children || null)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function useRpc(rpc) {
|
|
122
|
+
return React.useCallback(
|
|
123
|
+
function (endpoint, payload) {
|
|
124
|
+
return rpc.call('/memory-core', endpoint, payload || {}).then(function (res) {
|
|
125
|
+
if (!res || res.ok === false) {
|
|
126
|
+
var msg = res && res.error && res.error.message ? res.error.message : 'RPC 调用失败'
|
|
127
|
+
throw new Error(msg)
|
|
128
|
+
}
|
|
129
|
+
return res.value
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
[rpc],
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function Kpi(props) {
|
|
137
|
+
return h('div', { className: 'mc-card', title: props.title || '' },
|
|
138
|
+
h('div', { className: 'mc-k' }, props.label),
|
|
139
|
+
h('div', { className: 'mc-v ' + (props.tone || '') }, String(props.value)))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function Overview(props) {
|
|
143
|
+
var jump = props.onJump || function () {}
|
|
144
|
+
var s = props.status
|
|
145
|
+
if (!s) return h('div', { className: 'mc-empty' }, '加载中…')
|
|
146
|
+
var layers = s.byLayer || []
|
|
147
|
+
var max = layers.reduce(function (m, x) { return Math.max(m, x.n) }, 1)
|
|
148
|
+
return h('div', { className: 'mc-root' },
|
|
149
|
+
h('div', { className: 'mc-grid' },
|
|
150
|
+
h(Kpi, { label: '记录', value: s.records }),
|
|
151
|
+
h(Kpi, { label: '待审', value: s.pending, tone: s.pending > 20 ? 'mc-warn' : '' }),
|
|
152
|
+
h(Kpi, { label: 'S 级', value: s.sLevel }),
|
|
153
|
+
h(Kpi, { label: 'FTS 行', value: s.fts }),
|
|
154
|
+
h(Kpi, { label: '审计', value: s.audit && s.audit.ok ? '一致' : '异常', tone: s.audit && s.audit.ok ? 'mc-ok' : 'mc-err' }),
|
|
155
|
+
h(Kpi, { label: '权威源', value: s.authority })),
|
|
156
|
+
h('div', { className: 'mc-card' },
|
|
157
|
+
h('div', { className: 'mc-k', style: { marginBottom: '6px' } }, '分层分布'),
|
|
158
|
+
layers.length === 0 ? h('div', { className: 'mc-empty' }, '还没有记忆。第一次写入后这里会出现。') :
|
|
159
|
+
layers.map(function (x) {
|
|
160
|
+
return h('div', { key: x.layer, style: { marginBottom: '6px' } },
|
|
161
|
+
h('div', { className: 'mc-row' },
|
|
162
|
+
h('span', null, x.layer),
|
|
163
|
+
h('span', { className: 'mc-meta' }, String(x.n))),
|
|
164
|
+
h('div', { className: 'mc-bar' }, h('i', { style: { width: Math.round((x.n / max) * 100) + '%' } })))
|
|
165
|
+
})),
|
|
166
|
+
h('div', { className: 'mc-card' },
|
|
167
|
+
h('div', { className: 'mc-k', style: { marginBottom: '6px' } }, '最近操作'),
|
|
168
|
+
(s.recent || []).length === 0 ? h('div', { className: 'mc-empty' }, '(暂无记录)') :
|
|
169
|
+
h('div', { className: 'mc-list' }, (s.recent || []).map(function (t, i) {
|
|
170
|
+
return h('div', { key: (t.trace_id || i), className: 'mc-item', style: { cursor: 'default' } },
|
|
171
|
+
h('div', { className: 'mc-row' },
|
|
172
|
+
h('span', { className: 'mc-tag' }, t.op),
|
|
173
|
+
h('span', { className: 'mc-meta' }, String(t.at || '').replace('T', ' ').slice(0, 19)),
|
|
174
|
+
h('span', { className: 'mc-meta' }, t.query_preview || (t.hits ? (t.hits.length + ' 命中') : ''))))
|
|
175
|
+
})))),
|
|
176
|
+
h('div', { className: 'mc-card' },
|
|
177
|
+
h('div', { className: 'mc-k', style: { marginBottom: '6px' } }, '更新说明'),
|
|
178
|
+
h('div', { className: 'mc-meta' }, 'v1.5.2 · 所有分类都有「安装」;没有安装链接时给明确提示'),
|
|
179
|
+
h('div', { className: 'mc-meta' }, 'v1.5.1 · GitHub 无根清单时按仓库地址搜 npm 包;新增「复制安装链接」;修 onProgress 崩溃'),
|
|
180
|
+
h('div', { className: 'mc-meta' }, 'v1.5.0 · 图查询:edges 表 + BFS 邻域/扩散'),
|
|
181
|
+
h('div', { className: 'mc-meta' }, 'v1.4.0 · 情绪日报/周报落盘、尖峰注入提示、主动提醒'),
|
|
182
|
+
h('div', { className: 'mc-meta' }, 'v1.3.0 · 情绪事件表、QQ 采集、观测页情绪卡片')),
|
|
183
|
+
h('div', { className: 'mc-card' },
|
|
184
|
+
h('div', { className: 'mc-k', style: { marginBottom: '6px' } }, '页签功能(点一下跳过去)'),
|
|
185
|
+
[['search', '检索', '全文搜记忆,点开看正文'],
|
|
186
|
+
['review', '待审', '未验证来源的写入,审核后才进正式库'],
|
|
187
|
+
['handoff', '交接', '场景交接:上次做到哪、下一步是什么'],
|
|
188
|
+
['tasks', '派单', '多 agent 任务台账(派给谁、进度、回执)'],
|
|
189
|
+
['observe', '观测', '体量/分层/情绪分布/今日情绪事件'],
|
|
190
|
+
['timeline', '时间轴', '按日期看情绪变化与当天记忆'],
|
|
191
|
+
['parts', '零件', '插件/技能/MCP 零件库:搜索、安装、卸载'],
|
|
192
|
+
['security', '安全', '已装插件的静态安全扫描'],
|
|
193
|
+
['audit', '审计', '记录仪链校验与注入回放']].map(function (x) {
|
|
194
|
+
return h('div', {
|
|
195
|
+
key: x[0], className: 'mc-meta', style: { cursor: 'pointer', padding: '1px 0' },
|
|
196
|
+
onClick: function () { jump(x[0]) },
|
|
197
|
+
}, '→ ' + x[1] + ' · ' + x[2])
|
|
198
|
+
})),
|
|
199
|
+
h('div', { className: 'mc-card' },
|
|
200
|
+
h('div', { className: 'mc-k', style: { marginBottom: '6px' } }, '记忆导图'),
|
|
201
|
+
['L1 闪存(会话内)', 'L2 情景(项目事实 / 决策)', 'L3 长期(指针 / 结论)', 'L4 知识', 'L5 沉淀', 'L6 归档(降层留痕)'].map(function (line, i) {
|
|
202
|
+
return h('div', {
|
|
203
|
+
key: i, className: 'mc-meta',
|
|
204
|
+
style: { cursor: 'pointer', fontFamily: 'ui-monospace, monospace', paddingLeft: (i * 14) + 'px' },
|
|
205
|
+
onClick: function () { jump('search') },
|
|
206
|
+
}, (i === 0 ? '' : '└─ ') + line)
|
|
207
|
+
}),
|
|
208
|
+
h('div', { className: 'mc-meta', style: { marginTop: '4px' } }, '点任一层跳到检索;层级之间靠标签/同批次连边,命令 mem_graph_view 看邻域。'))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function TimelineView(props) {
|
|
212
|
+
var [data, setData] = React.useState(null)
|
|
213
|
+
var [days, setDays] = React.useState(7)
|
|
214
|
+
var [neighbor, setNeighbor] = React.useState(null)
|
|
215
|
+
function showNeighbors(id) {
|
|
216
|
+
props.call('graph/view', { record_id: id, hops: 1 })
|
|
217
|
+
.then(function (v) { setNeighbor({ id: id, data: v }) })
|
|
218
|
+
.catch(function (e) { props.onError(e.message) })
|
|
219
|
+
}
|
|
220
|
+
var LABEL = { neutral: '中性', positive: '正面', negative: '负面', urgent: '紧急' }
|
|
221
|
+
React.useEffect(function () {
|
|
222
|
+
props.call('timeline', { days: days })
|
|
223
|
+
.then(function (v) { setData(v) })
|
|
224
|
+
.catch(function (e) { props.onError(e.message) })
|
|
225
|
+
}, [days])
|
|
226
|
+
return h('div', { className: 'mc-root' },
|
|
227
|
+
h('div', { className: 'mc-row', style: { gap: '6px' } },
|
|
228
|
+
h('span', { className: 'mc-k' }, '时间轴'),
|
|
229
|
+
[7, 14, 30].map(function (d) {
|
|
230
|
+
return h('button', { key: d, className: 'mc-tab' + (days === d ? ' mc-tab-on' : ''), onClick: function () { setDays(d) } }, '近 ' + d + ' 天')
|
|
231
|
+
})),
|
|
232
|
+
data && data.groups.length ? h('div', { className: 'mc-card' },
|
|
233
|
+
h('div', { className: 'mc-k', style: { marginBottom: '4px' } }, '负面趋势(按天)'),
|
|
234
|
+
h('div', { style: { display: 'flex', alignItems: 'flex-end', gap: '3px', height: '36px' } },
|
|
235
|
+
data.groups.slice().reverse().map(function (g) {
|
|
236
|
+
var total = g.affect.length || 1
|
|
237
|
+
var ratio = (g.counts.negative + g.counts.urgent) / total
|
|
238
|
+
return h('div', {
|
|
239
|
+
key: g.date, title: g.date + ' 负面 ' + Math.round(ratio * 100) + '%',
|
|
240
|
+
style: {
|
|
241
|
+
width: '16px', height: Math.max(4, Math.round(ratio * 34)) + 'px',
|
|
242
|
+
background: ratio >= 0.5 ? 'var(--dsh-error, #e5484d)' : 'var(--dsh-accent, #4d8bf5)',
|
|
243
|
+
borderRadius: '2px', opacity: 0.9,
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
}))) : null,
|
|
247
|
+
!data ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
248
|
+
data.groups.length === 0 ? h('div', { className: 'mc-empty' }, '这段时间还没有记录。') :
|
|
249
|
+
data.groups.map(function (g) {
|
|
250
|
+
return h('div', { key: g.date, className: 'mc-card' },
|
|
251
|
+
h('div', { className: 'mc-k', style: { marginBottom: '4px' } }, g.date + ' · 情绪 ' + g.affect.length + ' 条 · 记忆 ' + g.memories.length + ' 条'),
|
|
252
|
+
g.affect.length ? h('div', { className: 'mc-meta' }, '情绪') : null,
|
|
253
|
+
g.affect.map(function (a, i) {
|
|
254
|
+
return h('div', { key: 'a' + i, className: 'mc-row' },
|
|
255
|
+
h('span', { className: 'mc-tag' }, a.time + ' ' + (a.labelCn || LABEL[a.label] || a.label)),
|
|
256
|
+
h('span', { className: 'mc-meta' }, a.excerpt))
|
|
257
|
+
}),
|
|
258
|
+
g.memories.length ? h('div', { className: 'mc-meta', style: { marginTop: '4px' } }, '记忆') : null,
|
|
259
|
+
g.memories.map(function (m, i) {
|
|
260
|
+
return h('div', {
|
|
261
|
+
key: 'm' + i, className: 'mc-row', style: { cursor: 'pointer' },
|
|
262
|
+
title: '点一下看这条记忆和谁相连',
|
|
263
|
+
onClick: function () { showNeighbors(m.record_id) },
|
|
264
|
+
},
|
|
265
|
+
h('span', { className: 'mc-meta' }, m.display && m.display.kind ? m.display.kind : m.layer),
|
|
266
|
+
h('span', null, m.display && m.display.title ? m.display.title : m.summary))
|
|
267
|
+
}))
|
|
268
|
+
}),
|
|
269
|
+
neighbor ? h('div', { className: 'mc-card' },
|
|
270
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between' } },
|
|
271
|
+
h('div', { className: 'mc-k' }, neighbor.id + ' 的邻居'),
|
|
272
|
+
h('button', { className: 'mc-btn', onClick: function () { setNeighbor(null) } }, '关闭')),
|
|
273
|
+
(neighbor.data.nodes || []).filter(function (n) { return n.depth > 0 }).slice(0, 12).map(function (n) {
|
|
274
|
+
var nd = n.display || {}
|
|
275
|
+
return h('div', { key: n.record_id, className: 'mc-meta' }, (n.depth > 1 ? '隔 ' + n.depth + ' 层 · ' : '') + (nd.title || n.summary || n.record_id))
|
|
276
|
+
}),
|
|
277
|
+
(neighbor.data.nodes || []).filter(function (n) { return n.depth > 0 }).length === 0
|
|
278
|
+
? h('div', { className: 'mc-empty' }, '这条记忆暂时没有连边(需要共享标签或同批写入)')
|
|
279
|
+
: null) : null)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function SearchView(props) {
|
|
283
|
+
var [q, setQ] = React.useState('')
|
|
284
|
+
var [rows, setRows] = React.useState(null)
|
|
285
|
+
var [detail, setDetail] = React.useState(null)
|
|
286
|
+
var [busy, setBusy] = React.useState(false)
|
|
287
|
+
function run() {
|
|
288
|
+
if (!q.trim()) return
|
|
289
|
+
setBusy(true)
|
|
290
|
+
props.call('search', { query: q, topK: 10 })
|
|
291
|
+
.then(function (v) { setRows(v || []) })
|
|
292
|
+
.catch(function (e) { props.onError(e.message) })
|
|
293
|
+
.finally(function () { setBusy(false) })
|
|
294
|
+
}
|
|
295
|
+
function open(id) {
|
|
296
|
+
props.call('read', { record_id: id })
|
|
297
|
+
.then(function (v) { setDetail(v) })
|
|
298
|
+
.catch(function (e) { props.onError(e.message) })
|
|
299
|
+
}
|
|
300
|
+
return h('div', { className: 'mc-root' },
|
|
301
|
+
h('div', { className: 'mc-row' },
|
|
302
|
+
h('input', {
|
|
303
|
+
className: 'mc-input', value: q, placeholder: '搜记忆…',
|
|
304
|
+
onChange: function (e) { setQ(e.target.value) },
|
|
305
|
+
onKeyDown: function (e) { if (e.key === 'Enter') run() },
|
|
306
|
+
}),
|
|
307
|
+
h('button', { className: 'mc-btn', onClick: run, disabled: busy }, busy ? '搜索中…' : '搜索')),
|
|
308
|
+
rows === null ? null : (rows.length === 0
|
|
309
|
+
? h('div', { className: 'mc-empty' }, '没有匹配的记录。')
|
|
310
|
+
: h('div', { className: 'mc-list' }, rows.map(function (r) {
|
|
311
|
+
return h(MemRow, { key: r.record_id, row: r, onClick: function () { open(r.record_id) } },
|
|
312
|
+
r.caveat ? h('div', { className: 'mc-meta mc-warn' }, r.caveat) : null)
|
|
313
|
+
}))),
|
|
314
|
+
detail ? h('div', null,
|
|
315
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between' } },
|
|
316
|
+
h('div', { className: 'mc-k' }, dispOf(detail).title),
|
|
317
|
+
h('button', { className: 'mc-btn', onClick: function () { setDetail(null) } }, '关闭')),
|
|
318
|
+
dispOf(detail).plain ? h('div', { className: 'mc-meta', style: { margin: '2px 0 6px' } }, dispOf(detail).plain) : null,
|
|
319
|
+
detail.denied
|
|
320
|
+
? h('div', { className: 'mc-banner' }, detail.reason || 'S 级记录需要显式授权')
|
|
321
|
+
: h('pre', { className: 'mc-pre' }, detail.content || detail.summary || ''))
|
|
322
|
+
: null)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function ReviewView(props) {
|
|
326
|
+
var [rows, setRows] = React.useState(null)
|
|
327
|
+
var [busy, setBusy] = React.useState(false)
|
|
328
|
+
function load() {
|
|
329
|
+
props.call('pending', { limit: 50 })
|
|
330
|
+
.then(function (v) { setRows(v || []) })
|
|
331
|
+
.catch(function (e) { props.onError(e.message) })
|
|
332
|
+
}
|
|
333
|
+
React.useEffect(function () { load() }, [])
|
|
334
|
+
function decide(id, decision) {
|
|
335
|
+
setBusy(true)
|
|
336
|
+
props.call('review', { record_id: id, decision: decision })
|
|
337
|
+
.then(function () { load() })
|
|
338
|
+
.catch(function (e) { props.onError(e.message) })
|
|
339
|
+
.finally(function () { setBusy(false) })
|
|
340
|
+
}
|
|
341
|
+
return h('div', { className: 'mc-root' },
|
|
342
|
+
h('div', { className: 'mc-k' }, '待审与隔离区的出口。批准后信任升为 trusted。'),
|
|
343
|
+
rows === null ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
344
|
+
rows.length === 0 ? h('div', { className: 'mc-empty' }, '没有待审记录。') :
|
|
345
|
+
h('div', { className: 'mc-list' }, rows.map(function (r) {
|
|
346
|
+
return h(MemRow, { key: r.record_id, row: r, style: { cursor: 'default' } },
|
|
347
|
+
h('div', { className: 'mc-meta', style: { marginTop: '3px' } }, '为什么还在这:' + reasonOf(r.reason)),
|
|
348
|
+
h('div', { className: 'mc-row', style: { marginTop: '6px' } },
|
|
349
|
+
h('button', { className: 'mc-btn', disabled: busy, onClick: function () { decide(r.record_id, 'approve') } }, '批准'),
|
|
350
|
+
h('button', { className: 'mc-btn', disabled: busy, onClick: function () { decide(r.record_id, 'release') } }, '放行'),
|
|
351
|
+
h('button', { className: 'mc-btn', disabled: busy, onClick: function () { decide(r.record_id, 'reject') } }, '拒绝')))
|
|
352
|
+
})))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function AuditView(props) {
|
|
356
|
+
var [rows, setRows] = React.useState(null)
|
|
357
|
+
React.useEffect(function () {
|
|
358
|
+
props.call('traces', { limit: 30 })
|
|
359
|
+
.then(function (v) { setRows(v || []) })
|
|
360
|
+
.catch(function (e) { props.onError(e.message) })
|
|
361
|
+
}, [])
|
|
362
|
+
return h('div', { className: 'mc-root' },
|
|
363
|
+
h('div', { className: 'mc-k' }, '记录仪索引(正文 JSONL 才是真源;此页用于快速回放)。'),
|
|
364
|
+
rows === null ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
365
|
+
rows.length === 0 ? h('div', { className: 'mc-empty' }, '(暂无记录)') :
|
|
366
|
+
h('div', { className: 'mc-list' }, rows.map(function (t, i) {
|
|
367
|
+
return h('div', { key: t.trace_id || i, className: 'mc-item', style: { cursor: 'default' } },
|
|
368
|
+
h('div', { className: 'mc-row' },
|
|
369
|
+
h('span', { className: 'mc-tag' }, t.op),
|
|
370
|
+
h('span', { className: 'mc-meta' }, String(t.at || '').replace('T', ' ').slice(0, 19)),
|
|
371
|
+
h('span', { className: 'mc-meta' }, t.query_preview || '')),
|
|
372
|
+
h('div', { className: 'mc-meta' }, (t.trace_id || '') + (t.hits && t.hits.length ? ' · ' + t.hits.length + ' 命中' : '')))
|
|
373
|
+
})))
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
var SECTION_LABELS = {
|
|
377
|
+
last: '1) 上次交接',
|
|
378
|
+
projects: '2) 当前项目',
|
|
379
|
+
changes: '3) 私有记忆变更',
|
|
380
|
+
next: '4) 下一步',
|
|
381
|
+
blockers: '5) 卡点',
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function HandoffView(props) {
|
|
385
|
+
var [rows, setRows] = React.useState(null)
|
|
386
|
+
var [detail, setDetail] = React.useState(null)
|
|
387
|
+
var [check, setCheck] = React.useState(null)
|
|
388
|
+
function load() {
|
|
389
|
+
props.call('handoffs')
|
|
390
|
+
.then(function (v) { setRows(v || []) })
|
|
391
|
+
.catch(function (e) { props.onError(e.message) })
|
|
392
|
+
}
|
|
393
|
+
React.useEffect(function () { load() }, [])
|
|
394
|
+
function open(scene) {
|
|
395
|
+
props.call('handoff', { scene: scene })
|
|
396
|
+
.then(function (v) { setDetail(v); setCheck(null) })
|
|
397
|
+
.catch(function (e) { props.onError(e.message) })
|
|
398
|
+
}
|
|
399
|
+
function runCheck(scene) {
|
|
400
|
+
props.call('check', scene ? { scene: scene } : {})
|
|
401
|
+
.then(function (v) { setCheck(v) })
|
|
402
|
+
.catch(function (e) { props.onError(e.message) })
|
|
403
|
+
}
|
|
404
|
+
return h('div', { className: 'mc-root' },
|
|
405
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between' } },
|
|
406
|
+
h('div', { className: 'mc-k' }, '每个场景一份「§〇 交接」:覆盖写、≤4 KB、五小节。换会话前必须先写。'),
|
|
407
|
+
h('button', { className: 'mc-btn', onClick: function () { runCheck(detail ? detail.scene : null) } }, '体检')),
|
|
408
|
+
check && check.items ? h('div', { className: 'mc-card' },
|
|
409
|
+
check.items.map(function (i) {
|
|
410
|
+
return h('div', { key: i.name, className: 'mc-meta ' + (i.ok ? 'mc-ok' : 'mc-err') },
|
|
411
|
+
(i.ok ? '✓ ' : '✗ ') + i.name + ': ' + i.value + '/' + i.limit)
|
|
412
|
+
})) : null,
|
|
413
|
+
rows === null ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
414
|
+
rows.length === 0 ? h('div', { className: 'mc-empty' }, '还没有交接。用 mem_handoff 写第一份。') :
|
|
415
|
+
h('div', { className: 'mc-list' }, rows.map(function (r) {
|
|
416
|
+
return h('div', { key: r.scene, className: 'mc-item', onClick: function () { open(r.scene) } },
|
|
417
|
+
h('div', null, r.title || r.scene),
|
|
418
|
+
h('div', { className: 'mc-meta' }, r.scene + ' · ' + r.bytes + '/4096 字节 · ' + String(r.updated_at || '').replace('T', ' ').slice(0, 19)))
|
|
419
|
+
})),
|
|
420
|
+
detail ? h('div', null,
|
|
421
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between' } },
|
|
422
|
+
h('div', { className: 'mc-k' }, detail.scene + ' · 更新于 ' + String(detail.updated_at || '').slice(0, 19)),
|
|
423
|
+
h('button', { className: 'mc-btn', onClick: function () { setDetail(null) } }, '关闭')),
|
|
424
|
+
Object.keys(SECTION_LABELS).filter(function (k) { return detail.sections && detail.sections[k] }).map(function (k) {
|
|
425
|
+
return h('div', { key: k, className: 'mc-card' },
|
|
426
|
+
h('div', { className: 'mc-k' }, SECTION_LABELS[k]),
|
|
427
|
+
h('div', { style: { whiteSpace: 'pre-wrap', marginTop: '4px' } }, detail.sections[k]))
|
|
428
|
+
})) : null)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function TaskView(props) {
|
|
432
|
+
var [rows, setRows] = React.useState(null)
|
|
433
|
+
var [detail, setDetail] = React.useState(null)
|
|
434
|
+
function load() {
|
|
435
|
+
props.call('tasks', { scope: 'all' })
|
|
436
|
+
.then(function (v) { setRows(v || []) })
|
|
437
|
+
.catch(function (e) { props.onError(e.message) })
|
|
438
|
+
}
|
|
439
|
+
React.useEffect(function () { load() }, [])
|
|
440
|
+
function open(id) {
|
|
441
|
+
props.call('task', { task_id: id })
|
|
442
|
+
.then(function (v) { setDetail(v) })
|
|
443
|
+
.catch(function (e) { props.onError(e.message) })
|
|
444
|
+
}
|
|
445
|
+
var tone = function (t) {
|
|
446
|
+
if (t.overdue || t.effective_status === 'overdue') return 'mc-err'
|
|
447
|
+
if (t.status === 'done' || t.status === 'closed') return 'mc-ok'
|
|
448
|
+
return 'mc-warn'
|
|
449
|
+
}
|
|
450
|
+
return h('div', { className: 'mc-root' },
|
|
451
|
+
h('div', { className: 'mc-k' }, '派单台账:sent → delivered → acked → done。超时未回执会标红。'),
|
|
452
|
+
rows === null ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
453
|
+
rows.length === 0 ? h('div', { className: 'mc-empty' }, '台账是空的。') :
|
|
454
|
+
h('div', { className: 'mc-list' }, rows.map(function (t) {
|
|
455
|
+
return h('div', { key: t.task_id, className: 'mc-item', onClick: function () { open(t.task_id) } },
|
|
456
|
+
h('div', null, (t.kind === 'dispatch' ? '派单 ' : '公告 ') + t.title),
|
|
457
|
+
h('div', { className: 'mc-meta' },
|
|
458
|
+
t.from_scene + ' → ' + t.to_scene + ' · ',
|
|
459
|
+
h('span', { className: tone(t) }, t.overdue ? '超时未回执' : t.effective_status),
|
|
460
|
+
' · ' + String(t.created_at || '').slice(0, 10)))
|
|
461
|
+
})),
|
|
462
|
+
detail ? h('div', { className: 'mc-card' },
|
|
463
|
+
h('div', { className: 'mc-row', style: { justifyContent: 'space-between' } },
|
|
464
|
+
h('div', { className: 'mc-k' }, detail.task_id + ' · ' + detail.status),
|
|
465
|
+
h('button', { className: 'mc-btn', onClick: function () { setDetail(null) } }, '关闭')),
|
|
466
|
+
h('div', { style: { marginTop: '6px' } }, detail.title),
|
|
467
|
+
detail.phenomenon ? h('div', { className: 'mc-meta', style: { marginTop: '6px' } }, '现象:' + detail.phenomenon) : null,
|
|
468
|
+
detail.how_to ? h('div', { className: 'mc-meta' }, '照哪做:' + detail.how_to) : null,
|
|
469
|
+
detail.how_verify ? h('div', { className: 'mc-meta' }, '怎么验:' + detail.how_verify) : null,
|
|
470
|
+
detail.ack ? h('div', { style: { marginTop: '8px' } },
|
|
471
|
+
h('div', { className: 'mc-k' }, '回执'),
|
|
472
|
+
h('div', { className: 'mc-meta' }, '结论:' + detail.ack.conclusion),
|
|
473
|
+
h('div', { className: 'mc-meta' }, '证据:' + detail.ack.evidence)) : null) : null)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function ObserveView(props) {
|
|
477
|
+
var [data, setData] = React.useState(null)
|
|
478
|
+
var [affect, setAffect] = React.useState(null)
|
|
479
|
+
var [affectMsg, setAffectMsg] = React.useState('')
|
|
480
|
+
function loadAffect() {
|
|
481
|
+
props.call('affect/report', { range: 'day' })
|
|
482
|
+
.then(function (v) { setAffect(v) })
|
|
483
|
+
.catch(function () {})
|
|
484
|
+
}
|
|
485
|
+
React.useEffect(function () {
|
|
486
|
+
props.call('observe')
|
|
487
|
+
.then(function (v) { setData(v) })
|
|
488
|
+
.catch(function (e) { props.onError(e.message) })
|
|
489
|
+
loadAffect()
|
|
490
|
+
}, [])
|
|
491
|
+
if (!data) return h('div', { className: 'mc-empty' }, '加载中…')
|
|
492
|
+
var s = data.stats || {}
|
|
493
|
+
var a = data.affect || {}
|
|
494
|
+
return h('div', { className: 'mc-root' },
|
|
495
|
+
h('div', { className: 'mc-k' }, '近 24 小时记忆活动。上下文构成请打开 dsh-context 的「Context」标签对照。'),
|
|
496
|
+
h('div', { className: 'mc-grid' },
|
|
497
|
+
h(Kpi, { label: '注入次数', value: data.injectCount }),
|
|
498
|
+
h(Kpi, { label: '平均指针', value: data.avgPointers }),
|
|
499
|
+
h(Kpi, { label: '检索次数', value: data.searchCount }),
|
|
500
|
+
h(Kpi, { label: '有结果', value: data.hitCount }),
|
|
501
|
+
h(Kpi, { label: '待审', value: s.pending, tone: s.pending > 20 ? 'mc-warn' : '' }),
|
|
502
|
+
h(Kpi, { label: '审计', value: s.audit && s.audit.ok ? '一致' : '异常', tone: s.audit && s.audit.ok ? 'mc-ok' : 'mc-err' })),
|
|
503
|
+
h('div', { className: 'mc-card' },
|
|
504
|
+
h('div', { className: 'mc-k' }, '情绪分布(全部活跃记忆)'),
|
|
505
|
+
h('div', { className: 'mc-meta', style: { marginTop: '6px' } },
|
|
506
|
+
'中性 ' + (a.neutral || 0) + ' · 正面 ' + (a.positive || 0) + ' · 负面 ' + (a.negative || 0) + ' · 紧急 ' + (a.urgent || 0)),
|
|
507
|
+
h('div', { className: 'mc-meta' }, '情绪标签在写入时由规则算出(效价/唤醒度),不调模型;重要性=基线+情绪强度+层级。')),
|
|
508
|
+
h('div', { className: 'mc-card' },
|
|
509
|
+
h('div', { className: 'mc-k' }, '近 14 天情绪趋势'),
|
|
510
|
+
h('div', { style: { marginTop: '8px', display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
511
|
+
(data.trend || []).map(function (d) {
|
|
512
|
+
var total = d.n || 0
|
|
513
|
+
var badPct = total ? Math.round((d.bad / total) * 100) : 0
|
|
514
|
+
var goodPct = total ? Math.round((d.good / total) * 100) : 0
|
|
515
|
+
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' } },
|
|
516
|
+
h('span', { style: { width: '44px', color: '#888' } }, d.day.slice(5)),
|
|
517
|
+
h('div', { style: { flex: 1, height: '8px', background: '#eee', borderRadius: '4px', display: 'flex', overflow: 'hidden' } },
|
|
518
|
+
h('div', { style: { width: badPct + '%', background: '#e5484d' } }),
|
|
519
|
+
h('div', { style: { width: goodPct + '%', background: '#30a46c' } })),
|
|
520
|
+
h('span', { style: { width: '92px', textAlign: 'right', color: '#666' } }, total ? (total + ' 条 · 负 ' + d.bad + ' · 正 ' + d.good) : '—'))
|
|
521
|
+
}))),
|
|
522
|
+
h('div', { className: 'mc-card' },
|
|
523
|
+
h('div', { className: 'mc-k' }, '今日情绪事件(QQ 采集)'),
|
|
524
|
+
h('div', { className: 'mc-meta', style: { marginTop: '4px' } },
|
|
525
|
+
affect
|
|
526
|
+
? ('事件 ' + affect.total + ' 条 · 负面占比 ' + Math.round(affect.negativeRatio * 100) + '% · 中性 ' + (affect.byLabel.neutral || 0) + ' · 正面 ' + (affect.byLabel.positive || 0) + ' · 负面 ' + (affect.byLabel.negative || 0) + ' · 紧急 ' + (affect.byLabel.urgent || 0))
|
|
527
|
+
: '加载中…'),
|
|
528
|
+
affect && affect.topTriggers && affect.topTriggers.length
|
|
529
|
+
? h('div', { className: 'mc-meta' }, '高频触发:' + affect.topTriggers.map(function (x) { return x.word + '×' + x.n }).join('、'))
|
|
530
|
+
: null,
|
|
531
|
+
h('div', { style: { marginTop: '6px' } },
|
|
532
|
+
h('button', {
|
|
533
|
+
className: 'mc-tab',
|
|
534
|
+
onClick: function () {
|
|
535
|
+
props.call('affect/ingest', { limit: 20 })
|
|
536
|
+
.then(function (v) { setAffectMsg('采集完成:新增 ' + v.added + ' 条(扫描 ' + v.scanned + ')'); loadAffect() })
|
|
537
|
+
.catch(function (e) { setAffectMsg('采集失败:' + e.message) })
|
|
538
|
+
},
|
|
539
|
+
}, '立即采集'),
|
|
540
|
+
affectMsg ? h('span', { className: 'mc-meta', style: { marginLeft: '8px' } }, affectMsg) : null)),
|
|
541
|
+
h('div', { className: 'mc-card' },
|
|
542
|
+
h('div', { className: 'mc-k' }, '怎么读这组数'),
|
|
543
|
+
h('div', { className: 'mc-meta', style: { marginTop: '6px' } }, '注入次数 = 系统提示词里带出记忆快照的次数;平均指针 = 每次带出几条。'),
|
|
544
|
+
h('div', { className: 'mc-meta' }, '检索次数 / 有结果 = 模型主动 mem_search 的次数与命中率。'),
|
|
545
|
+
h('div', { className: 'mc-meta' }, '要和上下文占用一起看:dsh-context 的 Context 标签给出 token 构成,这里给出记忆侧的活跃度。')))
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function PartsView(props) {
|
|
549
|
+
var [installed, setInstalled] = React.useState(null)
|
|
550
|
+
var [plugins, setPlugins] = React.useState(null)
|
|
551
|
+
var [meta, setMeta] = React.useState(null)
|
|
552
|
+
var [query, setQuery] = React.useState('')
|
|
553
|
+
var [category, setCategory] = React.useState('')
|
|
554
|
+
var [lib, setLib] = React.useState(null)
|
|
555
|
+
var [msg, setMsg] = React.useState('')
|
|
556
|
+
var [busy, setBusy] = React.useState(false)
|
|
557
|
+
var [job, setJob] = React.useState(null)
|
|
558
|
+
var [copied, setCopied] = React.useState('')
|
|
559
|
+
|
|
560
|
+
function refresh() {
|
|
561
|
+
props.call('parts').then(setInstalled).catch(function () {})
|
|
562
|
+
props.call('parts/installed').then(setPlugins).catch(function () {})
|
|
563
|
+
props.call('parts/meta').then(setMeta).catch(function () {})
|
|
564
|
+
}
|
|
565
|
+
React.useEffect(refresh, [])
|
|
566
|
+
React.useEffect(function () {
|
|
567
|
+
props.call('parts/library', { query: query, category: category, limit: 40 })
|
|
568
|
+
.then(setLib)
|
|
569
|
+
.catch(function (e) { props.onError(e.message) })
|
|
570
|
+
}, [query, category])
|
|
571
|
+
|
|
572
|
+
function pollJob(jobId, key) {
|
|
573
|
+
var timer = window.setInterval(function () {
|
|
574
|
+
props.call('parts/job', { jobId: jobId }).then(function (v) {
|
|
575
|
+
if (!v) return
|
|
576
|
+
setJob({ id: jobId, key: key, percent: v.percent, message: v.message, state: v.state, error: v.error })
|
|
577
|
+
if (v.state === 'done' || v.state === 'error') {
|
|
578
|
+
window.clearInterval(timer)
|
|
579
|
+
setBusy(false)
|
|
580
|
+
if (v.state === 'done') {
|
|
581
|
+
var name = v.result && v.result.package ? v.result.package : key
|
|
582
|
+
setMsg('完成:' + name + '。请重启 DSH 生效。')
|
|
583
|
+
refresh()
|
|
584
|
+
} else {
|
|
585
|
+
setMsg('失败:' + (v.error || '未知错误'))
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}).catch(function () { window.clearInterval(timer); setBusy(false) })
|
|
589
|
+
}, 700)
|
|
590
|
+
}
|
|
591
|
+
function install(p) {
|
|
592
|
+
if (!p.repo && !p.install) {
|
|
593
|
+
setMsg((p.name || '') + ':没有安装链接,请按仓库说明手动安装')
|
|
594
|
+
return
|
|
595
|
+
}
|
|
596
|
+
if (!window.confirm('安装 ' + p.name + ' ?\n\n' + (p.install || p.repo || '') + '\n\n安装后需要重启 DSH。')) return
|
|
597
|
+
var key = p.id || p.name
|
|
598
|
+
setBusy(true); setMsg('')
|
|
599
|
+
setJob({ id: null, key: key, percent: 2, message: '启动安装…', state: 'running' })
|
|
600
|
+
props.call('parts/install', { item: p })
|
|
601
|
+
.then(function (v) { pollJob(v.jobId, key) })
|
|
602
|
+
.catch(function (e) { setBusy(false); setJob(null); setMsg('安装失败:' + e.message) })
|
|
603
|
+
}
|
|
604
|
+
function uninstall(name) {
|
|
605
|
+
if (!window.confirm('卸载 ' + name + ' ?卸载后需要重启。')) return
|
|
606
|
+
setBusy(true); setMsg('')
|
|
607
|
+
setJob({ id: null, key: name, percent: 2, message: '启动卸载…', state: 'running' })
|
|
608
|
+
props.call('parts/uninstall', { name: name })
|
|
609
|
+
.then(function (v) { pollJob(v.jobId, name) })
|
|
610
|
+
.catch(function (e) { setBusy(false); setJob(null); setMsg('卸载失败:' + e.message) })
|
|
611
|
+
}
|
|
612
|
+
function copyLink(p) {
|
|
613
|
+
var link = p.repo || p.install || ''
|
|
614
|
+
try {
|
|
615
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(link)
|
|
616
|
+
setCopied(p.id || p.name)
|
|
617
|
+
window.setTimeout(function () { setCopied('') }, 1500)
|
|
618
|
+
} catch (error) {
|
|
619
|
+
setMsg('复制失败:' + (error && error.message ? error.message : error))
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function progressBar(key) {
|
|
623
|
+
if (!job || job.key !== key) return null
|
|
624
|
+
var pct = Math.max(0, Math.min(100, job.percent || 0))
|
|
625
|
+
var color = job.state === 'error' ? '#e5484d' : job.state === 'cancelled' ? '#888' : '#30a46c'
|
|
626
|
+
return h('div', { style: { marginTop: '6px' } },
|
|
627
|
+
h('div', { style: { height: '6px', background: 'rgba(127,127,127,.18)', borderRadius: '3px', overflow: 'hidden' } },
|
|
628
|
+
h('div', { style: { width: pct + '%', height: '100%', background: color, transition: 'width .3s' } })),
|
|
629
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '3px' } },
|
|
630
|
+
h('span', { className: 'mc-meta' }, pct + '% · ' + (job.message || '')),
|
|
631
|
+
job.state === 'running' && job.id
|
|
632
|
+
? h('button', { className: 'mc-tab', onClick: function () { props.call('parts/job/cancel', { jobId: job.id }).catch(function () {}) } }, '取消')
|
|
633
|
+
: null))
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
var cats = meta && meta.categories ? Object.keys(meta.categories) : []
|
|
637
|
+
return h('div', { className: 'mc-root' },
|
|
638
|
+
msg ? h('div', { className: 'mc-banner' }, msg) : null,
|
|
639
|
+
h('div', { className: 'mc-k' }, '内置零件(随工作台加载)'),
|
|
640
|
+
h('div', { className: 'mc-card' }, (installed || []).map(function (p) {
|
|
641
|
+
return h('div', { key: p.name, className: 'mc-meta', style: { marginTop: '4px' } }, '• ' + p.name + ' v' + p.version + ':' + p.describe)
|
|
642
|
+
})),
|
|
643
|
+
h('div', { className: 'mc-k', style: { marginTop: '10px' } }, '已装插件'),
|
|
644
|
+
h('div', { className: 'mc-card' }, (plugins || []).length === 0 ? h('div', { className: 'mc-empty' }, '暂无') : (plugins || []).map(function (p) {
|
|
645
|
+
return h('div', { key: p.name, style: { marginTop: '6px' } },
|
|
646
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: '8px', alignItems: 'center' } },
|
|
647
|
+
h('span', { className: 'mc-meta' }, p.name + (p.version ? ' v' + p.version : '') + (p.bundle ? ' · 已登记' : '')),
|
|
648
|
+
p.removable ? h('button', { className: 'mc-tab', disabled: busy, onClick: function () { uninstall(p.name) } }, '卸载') : null),
|
|
649
|
+
progressBar(p.name))
|
|
650
|
+
})),
|
|
651
|
+
h('div', { className: 'mc-k', style: { marginTop: '10px' } }, '零件库' + (meta ? '(' + meta.count + '/' + meta.total + ' 条)' : '')),
|
|
652
|
+
h('div', { className: 'mc-meta' }, '装不上?去「设置 → 插件 → 市场」搜同名零件;或点「复制安装链接」在终端安装。'),
|
|
653
|
+
h('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '6px 0' } },
|
|
654
|
+
h('input', {
|
|
655
|
+
value: query,
|
|
656
|
+
placeholder: '搜索零件(名称 / 作者 / 说明)',
|
|
657
|
+
onChange: function (e) { setQuery(e.target.value) },
|
|
658
|
+
style: { flex: '1 1 220px', padding: '6px 10px', borderRadius: '8px', border: '1px solid #ccc', fontSize: '13px' },
|
|
659
|
+
}),
|
|
660
|
+
h('button', { className: 'mc-tab', onClick: function () { setCategory('') } }, '全部'),
|
|
661
|
+
cats.map(function (c) {
|
|
662
|
+
return h('button', { key: c, className: 'mc-tab' + (category === c ? ' mc-tab-on' : ''), onClick: function () { setCategory(category === c ? '' : c) } }, c + ' ' + meta.categories[c])
|
|
663
|
+
})),
|
|
664
|
+
lib && lib.items ? (lib.items.length === 0 ? h('div', { className: 'mc-empty' }, '没有匹配的零件。') : lib.items.map(function (p) {
|
|
665
|
+
return h('div', { key: p.id ?? p.name, className: 'mc-card', style: { marginTop: '6px' } },
|
|
666
|
+
h('div', { className: 'mc-k' }, p.name + ' ★' + p.stars + ' · ' + p.category + (p.audited ? ' · 已审' : '')),
|
|
667
|
+
h('div', { className: 'mc-meta', style: { marginTop: '4px' } }, p.summary || '(无说明)'),
|
|
668
|
+
h('div', { className: 'mc-meta' }, '作者:' + (p.author || '未知') + ' | ' + (p.repo || '')),
|
|
669
|
+
h('div', { style: { marginTop: '6px', display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
670
|
+
h('button', { className: 'mc-tab', disabled: busy, onClick: function () { install(p) } }, '安装'),
|
|
671
|
+
h('button', { className: 'mc-tab', onClick: function () { setMsg((p.name || '') + ':' + (p.install || '按仓库说明安装')) } }, '查看说明'),
|
|
672
|
+
h('button', { className: 'mc-tab', onClick: function () { copyLink(p) } }, copied === (p.id || p.name) ? '已复制' : '复制安装链接'),
|
|
673
|
+
progressBar(p.id || p.name)))
|
|
674
|
+
})) : h('div', { className: 'mc-empty' }, '加载中…'))
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function SecurityView(props) {
|
|
678
|
+
var [targets, setTargets] = React.useState([])
|
|
679
|
+
var [report, setReport] = React.useState(null)
|
|
680
|
+
var [busy, setBusy] = React.useState(false)
|
|
681
|
+
var [error, setError] = React.useState('')
|
|
682
|
+
|
|
683
|
+
function tsCall(endpoint, payload) {
|
|
684
|
+
return fetch('/threat-scan/' + endpoint, {
|
|
685
|
+
method: 'POST',
|
|
686
|
+
headers: { 'content-type': 'application/json' },
|
|
687
|
+
body: JSON.stringify(payload || {}),
|
|
688
|
+
}).then(function (r) {
|
|
689
|
+
if (r.status === 404) throw new Error('安全扫描插件未安装')
|
|
690
|
+
return r.json()
|
|
691
|
+
}).then(function (j) {
|
|
692
|
+
if (!j || j.ok !== true) throw new Error((j && j.error && j.error.message) || '请求失败')
|
|
693
|
+
return j.value
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
React.useEffect(function () {
|
|
697
|
+
tsCall('discover', {}).then(function (v) { setTargets((v && v.units) || []) }).catch(function (e) { setError(e.message) })
|
|
698
|
+
}, [])
|
|
699
|
+
function run(marketplace) {
|
|
700
|
+
setBusy(true); setError('')
|
|
701
|
+
var paths = (targets || []).map(function (t) { return t.path })
|
|
702
|
+
tsCall('scan', { paths: paths, deep: true, online: false, lookup: false, marketplace: marketplace === true })
|
|
703
|
+
.then(function (v) { setReport(v) })
|
|
704
|
+
.catch(function (e) { setError(e.message) })
|
|
705
|
+
.then(function () { setBusy(false) })
|
|
706
|
+
}
|
|
707
|
+
var su = report && report.summary ? report.summary : null
|
|
708
|
+
return h('div', { className: 'mc-root' },
|
|
709
|
+
h('div', { className: 'mc-k' }, '插件安全扫描(dsh-plugin-threat-scan):本地启发式静态分析,不联网、不执行被扫代码。'),
|
|
710
|
+
h('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap', margin: '8px 0' } },
|
|
711
|
+
h('button', { className: 'mc-tab', disabled: busy, onClick: function () { run(false) } }, '扫描已发现目标(' + (targets || []).length + ')'),
|
|
712
|
+
h('button', { className: 'mc-tab', disabled: busy, onClick: function () { run(true) } }, '扫描整个插件市场')),
|
|
713
|
+
error ? h('div', { className: 'mc-banner' }, error) : null,
|
|
714
|
+
su ? h('div', { className: 'mc-card' },
|
|
715
|
+
h('div', { className: 'mc-meta' }, '严重 ' + su.critical + ' · 高 ' + su.high + ' · 中 ' + su.medium + ' · 低 ' + su.low),
|
|
716
|
+
h('div', { className: 'mc-meta' }, '风险插件 ' + su.riskyUnits + ' · 含真实命中 ' + su.unitsWithRealHits + ' · URL ' + su.urlCount + ' · 情报命中 ' + su.feedHits)) : null,
|
|
717
|
+
report && Array.isArray(report.records) ? report.records.slice(0, 20).map(function (r, i) {
|
|
718
|
+
return h('div', { key: 'r' + i, className: 'mc-meta' }, '· [' + r.severity + '] ' + (r.rel || r.path) + ' — ' + (r.label || r.magic || ''))
|
|
719
|
+
}) : null)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function Panel(props) {
|
|
723
|
+
var rpc = props.connection && props.connection.rpc
|
|
724
|
+
var safeRpc = rpc || { call: function () { return Promise.reject(new Error('连接服务不可用')) } }
|
|
725
|
+
var call = useRpc(safeRpc)
|
|
726
|
+
var [tab, setTab] = React.useState('mem')
|
|
727
|
+
var [sub, setSub] = React.useState('overview')
|
|
728
|
+
var [status, setStatus] = React.useState(null)
|
|
729
|
+
var [error, setError] = React.useState('')
|
|
730
|
+
|
|
731
|
+
function loadStatus() {
|
|
732
|
+
call('status')
|
|
733
|
+
.then(function (v) { setStatus(v); setError('') })
|
|
734
|
+
.catch(function (e) { setError(e.message) })
|
|
735
|
+
}
|
|
736
|
+
React.useEffect(function () { loadStatus() }, [])
|
|
737
|
+
|
|
738
|
+
if (!rpc) return h('div', { className: 'mc-empty' }, '连接服务不可用:这个位置需要 connection 服务。')
|
|
739
|
+
|
|
740
|
+
var tabs = [
|
|
741
|
+
['mem', '记忆可视化'],
|
|
742
|
+
['more', '更多'],
|
|
743
|
+
]
|
|
744
|
+
var moreTabs = [
|
|
745
|
+
['overview', '总览'],
|
|
746
|
+
['search', '检索'],
|
|
747
|
+
['review', '待审'],
|
|
748
|
+
['handoff', '交接'],
|
|
749
|
+
['tasks', '派单'],
|
|
750
|
+
['observe', '观测'],
|
|
751
|
+
['timeline', '时间轴'],
|
|
752
|
+
['parts', '零件'],
|
|
753
|
+
['security', '安全'],
|
|
754
|
+
['audit', '审计'],
|
|
755
|
+
]
|
|
756
|
+
|
|
757
|
+
return h('div', { className: 'mc-root' },
|
|
758
|
+
error ? h('div', { className: 'mc-banner' }, error) : null,
|
|
759
|
+
status && status.audit && status.audit.ok === false
|
|
760
|
+
? h('div', { className: 'mc-banner' }, '审计链异常:' + (status.audit.brokenAt || '未知位置'))
|
|
761
|
+
: null,
|
|
762
|
+
h('div', { className: 'mc-tabs' }, tabs.map(function (t) {
|
|
763
|
+
return h('button', {
|
|
764
|
+
key: t[0],
|
|
765
|
+
className: 'mc-tab' + (tab === t[0] ? ' mc-tab-on' : ''),
|
|
766
|
+
onClick: function () { setTab(t[0]); if (t[0] === 'more' && sub === 'overview') loadStatus() },
|
|
767
|
+
}, t[1])
|
|
768
|
+
}), h('span', { key: 'v', className: 'mc-meta', style: { marginLeft: 'auto', alignSelf: 'center' } }, 'v1.9.3')),
|
|
769
|
+
tab === 'more' ? h('div', { className: 'mc-tabs' }, moreTabs.map(function (t) {
|
|
770
|
+
return h('button', {
|
|
771
|
+
key: t[0],
|
|
772
|
+
className: 'mc-tab' + (sub === t[0] ? ' mc-tab-on' : ''),
|
|
773
|
+
onClick: function () { setSub(t[0]); if (t[0] === 'overview') loadStatus() },
|
|
774
|
+
}, t[1])
|
|
775
|
+
})) : null,
|
|
776
|
+
tab === 'mem' ? h(MemoryVis, { call: call, onError: setError }) : null,
|
|
777
|
+
tab === 'more' && sub === 'overview' ? h(Overview, { status: status, onJump: function (id) { setTab('more'); setSub(id) } }) : null,
|
|
778
|
+
tab === 'more' && sub === 'search' ? h(SearchView, { call: call, onError: setError }) : null,
|
|
779
|
+
tab === 'more' && sub === 'review' ? h(ReviewView, { call: call, onError: setError }) : null,
|
|
780
|
+
tab === 'more' && sub === 'handoff' ? h(HandoffView, { call: call, onError: setError }) : null,
|
|
781
|
+
tab === 'more' && sub === 'tasks' ? h(TaskView, { call: call, onError: setError }) : null,
|
|
782
|
+
tab === 'more' && sub === 'observe' ? h(ObserveView, { call: call, onError: setError }) : null,
|
|
783
|
+
tab === 'more' && sub === 'timeline' ? h(TimelineView, { call: call, onError: setError }) : null,
|
|
784
|
+
tab === 'more' && sub === 'parts' ? h(PartsView, { call: call, onError: setError }) : null,
|
|
785
|
+
tab === 'more' && sub === 'security' ? h(SecurityView, { call: call, onError: setError }) : null,
|
|
786
|
+
tab === 'more' && sub === 'audit' ? h(AuditView, { call: call, onError: setError }) : null)
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function GraphCanvas(props) {
|
|
790
|
+
var wrapRef = React.useRef(null)
|
|
791
|
+
var cvRef = React.useRef(null)
|
|
792
|
+
var st = React.useRef({ nodes: [], edges: [], zoom: 1, panX: 0, panY: 0, drag: null, hover: null, down: null })
|
|
793
|
+
var [tip, setTip] = React.useState(null)
|
|
794
|
+
var [legend, setLegend] = React.useState([])
|
|
795
|
+
|
|
796
|
+
var COL = { L1: '#38bdf8', L2: '#a78bfa', L3: '#34d399', L4: '#fbbf24', L5: '#f472b6', L6: '#94a3b8' }
|
|
797
|
+
|
|
798
|
+
function resize() {
|
|
799
|
+
var cv = cvRef.current
|
|
800
|
+
if (!cv || !wrapRef.current) return
|
|
801
|
+
var r = wrapRef.current.getBoundingClientRect()
|
|
802
|
+
cv.width = Math.max(320, Math.floor(r.width))
|
|
803
|
+
cv.height = Math.max(320, Math.floor(r.height))
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function layout() {
|
|
807
|
+
var cv = cvRef.current
|
|
808
|
+
if (!cv) return
|
|
809
|
+
var W = cv.width, H = cv.height
|
|
810
|
+
var s = st.current
|
|
811
|
+
var n = s.nodes.length
|
|
812
|
+
if (!n) return
|
|
813
|
+
// 初始位置:按层级分圈,避免全挤在一起
|
|
814
|
+
for (var i = 0; i < n; i++) {
|
|
815
|
+
var node = s.nodes[i]
|
|
816
|
+
var ring = node.layer === 'L1' ? 0.55 : node.layer === 'L2' ? 0.78 : 1.0
|
|
817
|
+
var a = i * 2.399
|
|
818
|
+
node.x = W / 2 + Math.cos(a) * W * 0.32 * ring
|
|
819
|
+
node.y = H / 2 + Math.sin(a) * H * 0.32 * ring
|
|
820
|
+
node.vx = 0
|
|
821
|
+
node.vy = 0
|
|
822
|
+
}
|
|
823
|
+
// 力导向:斥力 + 弹簧 + 向心
|
|
824
|
+
for (var it = 0; it < 420; it++) {
|
|
825
|
+
for (var i2 = 0; i2 < n; i2++) {
|
|
826
|
+
var a2 = s.nodes[i2]
|
|
827
|
+
for (var j = i2 + 1; j < n; j++) {
|
|
828
|
+
var b2 = s.nodes[j]
|
|
829
|
+
var dx = a2.x - b2.x, dy = a2.y - b2.y
|
|
830
|
+
var d2 = dx * dx + dy * dy || 0.01
|
|
831
|
+
if (d2 < 60000) {
|
|
832
|
+
var f = 1200 / d2
|
|
833
|
+
a2.vx += dx * f; a2.vy += dy * f
|
|
834
|
+
b2.vx -= dx * f; b2.vy -= dy * f
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
a2.vx += (W / 2 - a2.x) * 0.006
|
|
838
|
+
a2.vy += (H / 2 - a2.y) * 0.006
|
|
839
|
+
}
|
|
840
|
+
for (var k = 0; k < s.edges.length; k++) {
|
|
841
|
+
var e = s.edges[k], na = s.nodes[e.a], nb = s.nodes[e.b]
|
|
842
|
+
var ddx = nb.x - na.x, ddy = nb.y - na.y
|
|
843
|
+
var d = Math.sqrt(ddx * ddx + ddy * ddy) || 1
|
|
844
|
+
var ff = (d - 70) * 0.02
|
|
845
|
+
na.vx += ddx / d * ff; na.vy += ddy / d * ff
|
|
846
|
+
nb.vx -= ddx / d * ff; nb.vy -= ddy / d * ff
|
|
847
|
+
}
|
|
848
|
+
for (var n2 = 0; n2 < n; n2++) {
|
|
849
|
+
var nn = s.nodes[n2]
|
|
850
|
+
nn.vx *= 0.82; nn.vy *= 0.82
|
|
851
|
+
nn.x += nn.vx * 0.35
|
|
852
|
+
nn.y += nn.vy * 0.35
|
|
853
|
+
if (!isFinite(nn.x) || !isFinite(nn.y)) { nn.x = W / 2; nn.y = H / 2 }
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
fit()
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// 视图自适应:让所有节点落在画面里
|
|
860
|
+
function fit() {
|
|
861
|
+
var cv = cvRef.current
|
|
862
|
+
if (!cv) return
|
|
863
|
+
var s = st.current
|
|
864
|
+
if (!s.nodes.length) return
|
|
865
|
+
var minX = 1e9, maxX = -1e9, minY = 1e9, maxY = -1e9
|
|
866
|
+
for (var i = 0; i < s.nodes.length; i++) {
|
|
867
|
+
var n = s.nodes[i]
|
|
868
|
+
if (n.x < minX) minX = n.x
|
|
869
|
+
if (n.x > maxX) maxX = n.x
|
|
870
|
+
if (n.y < minY) minY = n.y
|
|
871
|
+
if (n.y > maxY) maxY = n.y
|
|
872
|
+
}
|
|
873
|
+
var w = Math.max(1, maxX - minX), h = Math.max(1, maxY - minY)
|
|
874
|
+
var pad = 60
|
|
875
|
+
var z = Math.min((cv.width - pad * 2) / w, (cv.height - pad * 2) / h, 2.2)
|
|
876
|
+
z = Math.max(0.3, z)
|
|
877
|
+
s.zoom = z
|
|
878
|
+
s.panX = cv.width / 2 - (minX + maxX) / 2 * z
|
|
879
|
+
s.panY = cv.height / 2 - (minY + maxY) / 2 * z
|
|
880
|
+
draw()
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function draw() {
|
|
884
|
+
var cv = cvRef.current
|
|
885
|
+
if (!cv) return
|
|
886
|
+
var ctx = cv.getContext('2d')
|
|
887
|
+
var s = st.current
|
|
888
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
|
889
|
+
ctx.clearRect(0, 0, cv.width, cv.height)
|
|
890
|
+
// 背景点阵,让画面不那么空
|
|
891
|
+
ctx.fillStyle = 'rgba(103,232,249,.045)'
|
|
892
|
+
for (var gx = 20; gx < cv.width; gx += 36) {
|
|
893
|
+
for (var gy = 20; gy < cv.height; gy += 36) {
|
|
894
|
+
ctx.fillRect(gx, gy, 1.2, 1.2)
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
ctx.translate(s.panX, s.panY)
|
|
898
|
+
ctx.scale(s.zoom, s.zoom)
|
|
899
|
+
// 边
|
|
900
|
+
ctx.strokeStyle = 'rgba(103,232,249,.10)'
|
|
901
|
+
ctx.lineWidth = 0.7 / s.zoom
|
|
902
|
+
for (var i = 0; i < s.edges.length; i++) {
|
|
903
|
+
var e = s.edges[i], a = s.nodes[e.a], b = s.nodes[e.b]
|
|
904
|
+
var hot = s.hover && (a === s.hover || b === s.hover)
|
|
905
|
+
if (hot) { ctx.strokeStyle = 'rgba(103,232,249,.55)'; ctx.lineWidth = 1.4 / s.zoom }
|
|
906
|
+
else { ctx.strokeStyle = 'rgba(103,232,249,.10)'; ctx.lineWidth = 0.7 / s.zoom }
|
|
907
|
+
ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke()
|
|
908
|
+
}
|
|
909
|
+
// 节点
|
|
910
|
+
for (var k = 0; k < s.nodes.length; k++) {
|
|
911
|
+
var n = s.nodes[k]
|
|
912
|
+
var isHover = n === s.hover
|
|
913
|
+
var r = (n.layer === 'L2' ? 6.5 : 5) / Math.max(0.6, s.zoom * 0.75)
|
|
914
|
+
ctx.beginPath()
|
|
915
|
+
ctx.fillStyle = isHover ? '#ffffff' : (COL[n.layer] || '#94a3b8')
|
|
916
|
+
if (isHover) { ctx.shadowColor = '#67e8f9'; ctx.shadowBlur = 18 } else { ctx.shadowBlur = 0 }
|
|
917
|
+
ctx.arc(n.x, n.y, isHover ? r + 2 : r, 0, Math.PI * 2)
|
|
918
|
+
ctx.fill()
|
|
919
|
+
ctx.shadowBlur = 0
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function build() {
|
|
924
|
+
resize()
|
|
925
|
+
var cv = cvRef.current
|
|
926
|
+
if (!cv) return
|
|
927
|
+
var data = props.data || { nodes: [], edges: [] }
|
|
928
|
+
var nodes = (data.nodes || []).map(function (n) {
|
|
929
|
+
return { id: n.record_id, layer: n.layer, summary: n.summary, x: 0, y: 0, vx: 0, vy: 0, r: n.layer === 'L2' ? 6.5 : 5 }
|
|
930
|
+
})
|
|
931
|
+
var idx = new Map(nodes.map(function (n, i) { return [n.id, i] }))
|
|
932
|
+
var edges = (data.edges || []).filter(function (e) { return idx.has(e.from_id) && idx.has(e.to_id) }).map(function (e) { return { a: idx.get(e.from_id), b: idx.get(e.to_id) } })
|
|
933
|
+
st.current.nodes = nodes
|
|
934
|
+
st.current.edges = edges
|
|
935
|
+
var counts = {}
|
|
936
|
+
nodes.forEach(function (n) { counts[n.layer] = (counts[n.layer] || 0) + 1 })
|
|
937
|
+
setLegend(Object.keys(COL).filter(function (k) { return counts[k] }).map(function (k) { return { layer: k, n: counts[k], color: COL[k] } }))
|
|
938
|
+
layout()
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
React.useEffect(function () { build() }, [props.data])
|
|
942
|
+
React.useEffect(function () {
|
|
943
|
+
function onResize() { resize(); fit() }
|
|
944
|
+
window.addEventListener('resize', onResize)
|
|
945
|
+
return function () { window.removeEventListener('resize', onResize) }
|
|
946
|
+
}, [])
|
|
947
|
+
|
|
948
|
+
function pos(ev) { var r = cvRef.current.getBoundingClientRect(); return { x: ev.clientX - r.left, y: ev.clientY - r.top } }
|
|
949
|
+
function toWorld(p) { var s = st.current; return { x: (p.x - s.panX) / s.zoom, y: (p.y - s.panY) / s.zoom } }
|
|
950
|
+
|
|
951
|
+
function onDown(ev) {
|
|
952
|
+
var p = pos(ev), w = toWorld(p), s = st.current
|
|
953
|
+
var hit = null
|
|
954
|
+
for (var i = 0; i < s.nodes.length; i++) {
|
|
955
|
+
if (Math.sqrt(Math.pow(s.nodes[i].x - w.x, 2) + Math.pow(s.nodes[i].y - w.y, 2)) < 14 / s.zoom + s.nodes[i].r) { hit = s.nodes[i]; break }
|
|
956
|
+
}
|
|
957
|
+
// 记下来:点在谁身上、从哪儿开始 —— 松开时用来区分「点一下」和「拖一下」
|
|
958
|
+
s.down = { node: hit, x: p.x, y: p.y, moved: false }
|
|
959
|
+
if (hit) s.drag = { node: hit, dx: w.x - hit.x, dy: w.y - hit.y }
|
|
960
|
+
else s.drag = { pan: true, startX: p.x, startY: p.y, panX: s.panX, panY: s.panY }
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function onMove(ev) {
|
|
964
|
+
var s = st.current, p = pos(ev), w = toWorld(p)
|
|
965
|
+
if (s.down && Math.abs(p.x - s.down.x) + Math.abs(p.y - s.down.y) > 4) s.down.moved = true
|
|
966
|
+
if (s.drag) {
|
|
967
|
+
if (s.drag.node) { s.drag.node.x = w.x - s.drag.dx; s.drag.node.y = w.y - s.drag.dy; draw() }
|
|
968
|
+
else { s.panX = s.drag.panX + (p.x - s.drag.startX); s.panY = s.drag.panY + (p.y - s.drag.startY); draw() }
|
|
969
|
+
return
|
|
970
|
+
}
|
|
971
|
+
var hover = null
|
|
972
|
+
for (var i = 0; i < s.nodes.length; i++) {
|
|
973
|
+
if (Math.sqrt(Math.pow(s.nodes[i].x - w.x, 2) + Math.pow(s.nodes[i].y - w.y, 2)) < s.nodes[i].r + 8 / s.zoom) { hover = s.nodes[i]; break }
|
|
974
|
+
}
|
|
975
|
+
if (hover !== s.hover) {
|
|
976
|
+
s.hover = hover
|
|
977
|
+
draw()
|
|
978
|
+
if (cvRef.current) cvRef.current.style.cursor = hover ? 'pointer' : 'grab'
|
|
979
|
+
var hv = hover ? dispOf(hover) : null
|
|
980
|
+
setTip(hv ? { x: Math.min(p.x + 14, cvRef.current.width - 350), y: p.y + 10, title: hv.title, plain: hv.plain, meta: hv.meta } : null)
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// 松开:没拖动过就是「点一下」→ 打开这条记忆的全部细节;点空白处 → 收起详情
|
|
985
|
+
function onUp() {
|
|
986
|
+
var s = st.current
|
|
987
|
+
var down = s.down
|
|
988
|
+
s.drag = null
|
|
989
|
+
s.down = null
|
|
990
|
+
if (!down || down.moved) return
|
|
991
|
+
if (typeof props.onOpen === 'function') props.onOpen(down.node ? down.node.id : null)
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// 指针离开画布:只清状态,不当成点击
|
|
995
|
+
function onCancel() {
|
|
996
|
+
st.current.drag = null
|
|
997
|
+
st.current.down = null
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function onWheel(ev) {
|
|
1001
|
+
ev.preventDefault()
|
|
1002
|
+
var p = pos(ev), s = st.current
|
|
1003
|
+
var before = toWorld(p)
|
|
1004
|
+
s.zoom = Math.max(0.2, Math.min(4, s.zoom * (ev.deltaY < 0 ? 1.15 : 1 / 1.15)))
|
|
1005
|
+
var after = toWorld(p)
|
|
1006
|
+
s.panX += (after.x - before.x) * s.zoom
|
|
1007
|
+
s.panY += (after.y - before.y) * s.zoom
|
|
1008
|
+
draw()
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
return h('div', { ref: wrapRef, style: { position: 'relative', height: '520px', border: '1px solid var(--dsh-border, rgba(127,127,127,.22))', borderRadius: '10px', overflow: 'hidden', background: 'radial-gradient(900px 500px at 50% 0%, rgba(11,32,56,.9), rgba(3,6,13,.95))' } },
|
|
1012
|
+
h('canvas', {
|
|
1013
|
+
ref: cvRef,
|
|
1014
|
+
style: { display: 'block', width: '100%', height: '100%', cursor: 'grab' },
|
|
1015
|
+
onMouseDown: onDown, onMouseMove: onMove, onMouseUp: onUp, onMouseLeave: onCancel, onWheel: onWheel,
|
|
1016
|
+
}),
|
|
1017
|
+
h('div', { style: { position: 'absolute', right: '10px', top: '10px', display: 'flex', gap: '6px' } },
|
|
1018
|
+
h('button', { className: 'mc-tab', onClick: fit }, '适应'),
|
|
1019
|
+
h('button', { className: 'mc-tab', onClick: function () { layout(); fit() } }, '重排')),
|
|
1020
|
+
h('div', { style: { position: 'absolute', left: '10px', bottom: '10px', fontSize: '11px', color: '#cfe6ff', display: 'flex', gap: '10px', background: 'rgba(3,10,20,.75)', padding: '4px 8px', borderRadius: '8px' } },
|
|
1021
|
+
legend.map(function (x) {
|
|
1022
|
+
return h('span', { key: x.layer }, h('i', { style: { display: 'inline-block', width: '8px', height: '8px', borderRadius: '50%', background: x.color, marginRight: '4px' } }), x.layer + ' ' + x.n)
|
|
1023
|
+
})),
|
|
1024
|
+
h('div', { style: { position: 'absolute', right: '10px', bottom: '10px', fontSize: '11px', color: '#9fb6d8' } }, '点一下看详情 / 拖节点 / 滚轮缩放'),
|
|
1025
|
+
tip ? h('div', { style: { position: 'absolute', left: tip.x, top: tip.y, background: '#0a1626', color: '#e6f2ff', border: '1px solid rgba(103,232,249,.45)', borderRadius: '8px', padding: '7px 10px', fontSize: '12px', lineHeight: '1.55', maxWidth: '340px', pointerEvents: 'none', boxShadow: '0 6px 20px rgba(0,0,0,.55)', zIndex: 20 } },
|
|
1026
|
+
h('div', { style: { fontWeight: 600, fontSize: '13px' } }, tip.title),
|
|
1027
|
+
tip.plain ? h('div', { style: { marginTop: '3px', color: '#b7cde6' } }, tip.plain) : null,
|
|
1028
|
+
tip.meta ? h('div', { style: { marginTop: '4px', color: '#7f9cbd', fontSize: '11px' } }, tip.meta) : null) : null)
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
function MemoryVis(props) {
|
|
1032
|
+
var [view, setView] = React.useState('graph')
|
|
1033
|
+
var [stats, setStats] = React.useState(null)
|
|
1034
|
+
var [rows, setRows] = React.useState(null)
|
|
1035
|
+
var [q, setQ] = React.useState('')
|
|
1036
|
+
var [layer, setLayer] = React.useState('')
|
|
1037
|
+
var [detail, setDetail] = React.useState(null)
|
|
1038
|
+
var [graphData, setGraphData] = React.useState(null)
|
|
1039
|
+
var [tl, setTl] = React.useState(null)
|
|
1040
|
+
var detailRef = React.useRef(null)
|
|
1041
|
+
|
|
1042
|
+
// 点圆球打开详情后,把它滚进视野(画布占了 520px,详情在下面)
|
|
1043
|
+
React.useEffect(function () {
|
|
1044
|
+
if (!detail) return
|
|
1045
|
+
var el = detailRef.current
|
|
1046
|
+
if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
|
1047
|
+
}, [detail])
|
|
1048
|
+
|
|
1049
|
+
function loadStats() { props.call('status').then(function (v) { setStats(v) }).catch(function (e) { props.onError(e.message) }) }
|
|
1050
|
+
function loadRows() { props.call('records', { layer: layer || undefined, limit: 300 }).then(function (v) { setRows(v || []) }).catch(function (e) { props.onError(e.message) }) }
|
|
1051
|
+
function runSearch() {
|
|
1052
|
+
if (!q.trim()) { loadRows(); return }
|
|
1053
|
+
props.call('search', { query: q, topK: 30 }).then(function (v) {
|
|
1054
|
+
setRows((v || []).map(function (r) { return { record_id: r.record_id, layer: r.layer, summary: r.snippet, created_at: r.created_at } }))
|
|
1055
|
+
}).catch(function (e) { props.onError(e.message) })
|
|
1056
|
+
}
|
|
1057
|
+
function open(id) { props.call('read', { record_id: id }).then(function (v) { setDetail(v) }).catch(function (e) { props.onError(e.message) }) }
|
|
1058
|
+
|
|
1059
|
+
React.useEffect(function () { loadStats(); loadRows() }, [layer])
|
|
1060
|
+
React.useEffect(function () {
|
|
1061
|
+
if (view === 'graph' && !graphData) props.call('graph.all').then(function (v) { setGraphData(v) }).catch(function (e) { props.onError(e.message) })
|
|
1062
|
+
if (view === 'timeline' && !tl) props.call('timeline', { days: 14 }).then(function (v) { setTl(v) }).catch(function (e) { props.onError(e.message) })
|
|
1063
|
+
}, [view])
|
|
1064
|
+
|
|
1065
|
+
var layers = stats ? (stats.layers || []) : []
|
|
1066
|
+
return h('div', { className: 'mc-root' },
|
|
1067
|
+
h('div', { className: 'mc-row', style: { gap: '8px', flexWrap: 'wrap' } },
|
|
1068
|
+
h('input', { className: 'mc-input', value: q, placeholder: '搜记忆…', style: { flex: '1 1 220px' }, onChange: function (e) { setQ(e.target.value) }, onKeyDown: function (e) { if (e.key === 'Enter') runSearch() } }),
|
|
1069
|
+
h('button', { className: 'mc-btn', onClick: runSearch }, '搜索'),
|
|
1070
|
+
h('button', { className: 'mc-btn', onClick: function () { setQ(''); loadRows() } }, '全部'),
|
|
1071
|
+
h('button', { className: 'mc-tab' + (view === 'graph' ? ' mc-tab-on' : ''), onClick: function () { setView('graph') } }, '关系图'),
|
|
1072
|
+
h('button', { className: 'mc-tab' + (view === 'list' ? ' mc-tab-on' : ''), onClick: function () { setView('list') } }, '列表'),
|
|
1073
|
+
h('button', { className: 'mc-tab' + (view === 'timeline' ? ' mc-tab-on' : ''), onClick: function () { setView('timeline') } }, '时间轴')),
|
|
1074
|
+
stats ? h('div', { className: 'mc-meta', style: { marginTop: '6px' } },
|
|
1075
|
+
'记录 ' + stats.records + ' · ' + layers.map(function (x) { return x.layer + ':' + x.n }).join(' ') + ' · S 级 ' + stats.sLevel + ' · 关系图可拖拽/滚轮缩放') : null,
|
|
1076
|
+
view === 'graph' ? h(GraphCanvas, {
|
|
1077
|
+
data: graphData || { nodes: [], edges: [] },
|
|
1078
|
+
onOpen: function (id) { if (id) open(id); else setDetail(null) },
|
|
1079
|
+
}) : null,
|
|
1080
|
+
view === 'graph' && detail ? h('div', { ref: detailRef },
|
|
1081
|
+
h(DetailCard, { detail: detail, onClose: function () { setDetail(null) }, onOpen: open })) : null,
|
|
1082
|
+
view === 'timeline' ? h('div', null, tl ? tl.groups.map(function (g) {
|
|
1083
|
+
return h('div', { key: g.date, className: 'mc-card' },
|
|
1084
|
+
h('div', { className: 'mc-k' }, g.date + ' · 情绪 ' + g.affect.length + ' · 记忆 ' + g.memories.length),
|
|
1085
|
+
g.memories.map(function (m) {
|
|
1086
|
+
return h(MemRow, { key: m.record_id, row: m, onClick: function () { open(m.record_id) } })
|
|
1087
|
+
}))
|
|
1088
|
+
}) : h('div', { className: 'mc-empty' }, '加载中…')) : null,
|
|
1089
|
+
view === 'list' ? h('div', { style: { display: 'flex', gap: '10px', marginTop: '8px' } },
|
|
1090
|
+
h('div', { style: { flex: '1 1 46%', maxHeight: '480px', overflow: 'auto' } },
|
|
1091
|
+
rows === null ? h('div', { className: 'mc-empty' }, '加载中…') :
|
|
1092
|
+
rows.length === 0 ? h('div', { className: 'mc-empty' }, '没有记录') :
|
|
1093
|
+
rows.map(function (r) {
|
|
1094
|
+
return h(MemRow, { key: r.record_id, row: r, onClick: function () { open(r.record_id) } })
|
|
1095
|
+
})),
|
|
1096
|
+
h('div', { style: { flex: '1 1 54%' } },
|
|
1097
|
+
detail ? h(DetailCard, { detail: detail, onClose: function () { setDetail(null) }, onOpen: open }) : h('div', { className: 'mc-empty' }, '点左边一条看详情'))) : null)
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
var ErrorBoundary = (function () {
|
|
1101
|
+
if (typeof React.Component !== 'function') {
|
|
1102
|
+
return function (p) { return p && p.children ? p.children : null }
|
|
1103
|
+
}
|
|
1104
|
+
return class ErrorBoundary extends React.Component {
|
|
1105
|
+
constructor(props) { super(props); this.state = { err: null } }
|
|
1106
|
+
static getDerivedStateFromError(error) { return { err: error } }
|
|
1107
|
+
render() {
|
|
1108
|
+
if (this.state && this.state.err) {
|
|
1109
|
+
return h('div', { className: 'mc-banner' }, '面板渲染出错:' + (this.state.err.message || String(this.state.err)))
|
|
1110
|
+
}
|
|
1111
|
+
return this.props.children || null
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
})()
|
|
1115
|
+
|
|
1116
|
+
function apply(ctx) {
|
|
1117
|
+
var slots = ctx.slots
|
|
1118
|
+
if (!slots) {
|
|
1119
|
+
console.warn('[dsh-memory-core] slots 服务缺失,面板禁用')
|
|
1120
|
+
return
|
|
1121
|
+
}
|
|
1122
|
+
var tag = null
|
|
1123
|
+
if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css="dsh-sixlayer-memory"]') === null) {
|
|
1124
|
+
tag = document.createElement('style')
|
|
1125
|
+
tag.dataset.plugin = 'dsh-memory-core'
|
|
1126
|
+
tag.dataset.pluginCss = 'dsh-memory-core'
|
|
1127
|
+
tag.textContent = CSS
|
|
1128
|
+
document.head.appendChild(tag)
|
|
1129
|
+
}
|
|
1130
|
+
slots.inject('settings.section', function () {
|
|
1131
|
+
return slots.register(
|
|
1132
|
+
{ name: 'settings.section', id: 'memory-core', order: 27, label: function () { return '工作台' } },
|
|
1133
|
+
function () { return h(ErrorBoundary, null, h(Panel, { connection: ctx.connection })) },
|
|
1134
|
+
)
|
|
1135
|
+
})
|
|
1136
|
+
|
|
1137
|
+
try {
|
|
1138
|
+
slots.inject('conversation.view', function () {
|
|
1139
|
+
return slots.register(
|
|
1140
|
+
{ name: 'conversation.view', id: 'memory-core-view', order: 36, label: function () { return '记忆' } },
|
|
1141
|
+
function () { return h(ErrorBoundary, null, h(Panel, { connection: ctx.connection })) },
|
|
1142
|
+
)
|
|
1143
|
+
})
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
console.warn('[dsh-sixlayer-memory] conversation.view 注册失败:', error)
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
// B5:右侧栏「记忆」页签,和 dsh-context 的 Context 并排(不 fork 它)
|
|
1149
|
+
try {
|
|
1150
|
+
if (typeof ctx.inject === 'function') {
|
|
1151
|
+
ctx.inject(['sidebarRightTabs'], function (sub) {
|
|
1152
|
+
var tabs = sub.sidebarRightTabs
|
|
1153
|
+
if (!tabs || typeof tabs.register !== 'function') return
|
|
1154
|
+
var disposers = []
|
|
1155
|
+
try {
|
|
1156
|
+
disposers.push(tabs.register({
|
|
1157
|
+
id: 'memory-core',
|
|
1158
|
+
kind: 'memory-core',
|
|
1159
|
+
title: function () { return '记忆' },
|
|
1160
|
+
guide: [{
|
|
1161
|
+
order: 30,
|
|
1162
|
+
title: function () { return '记忆' },
|
|
1163
|
+
description: function () { return '记忆底座:总览 / 检索 / 待审 / 交接 / 派单 / 观测 / 审计' },
|
|
1164
|
+
}],
|
|
1165
|
+
}))
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
console.warn('[dsh-memory-core] sidebarRightTabs.register failed:', error)
|
|
1168
|
+
}
|
|
1169
|
+
try {
|
|
1170
|
+
disposers.push(sub.slots.inject('sidebar.right.pane.tab', function () {
|
|
1171
|
+
return sub.slots.register(
|
|
1172
|
+
{ name: 'sidebar.right.pane.tab', key: 'memory-core' },
|
|
1173
|
+
function (paneProps) {
|
|
1174
|
+
return h(Panel, { connection: (sub && sub.connection) || ctx.connection || (paneProps && paneProps.connection) })
|
|
1175
|
+
},
|
|
1176
|
+
)
|
|
1177
|
+
}))
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
console.warn('[dsh-memory-core] sidebar.right.pane.tab failed:', error)
|
|
1180
|
+
}
|
|
1181
|
+
try {
|
|
1182
|
+
disposers.push(sub.slots.inject('sidebar.right.pane.tab.title', function () {
|
|
1183
|
+
return sub.slots.register(
|
|
1184
|
+
{ name: 'sidebar.right.pane.tab.title', key: 'memory-core' },
|
|
1185
|
+
function () { return h('span', null, '记忆') },
|
|
1186
|
+
)
|
|
1187
|
+
}))
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
console.warn('[dsh-memory-core] sidebar.right.pane.tab.title failed:', error)
|
|
1190
|
+
}
|
|
1191
|
+
return function () {
|
|
1192
|
+
disposers.forEach(function (dispose) {
|
|
1193
|
+
try { if (typeof dispose === 'function') dispose() } catch { /* 忽略 */ }
|
|
1194
|
+
})
|
|
1195
|
+
}
|
|
1196
|
+
})
|
|
1197
|
+
}
|
|
1198
|
+
} catch (error) {
|
|
1199
|
+
console.warn('[dsh-memory-core] 侧栏页签不可用:', error)
|
|
1200
|
+
}
|
|
1201
|
+
ctx.effect(function () {
|
|
1202
|
+
return function () { if (tag !== null && tag.isConnected) tag.remove() }
|
|
1203
|
+
})
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
module.exports = { name: name, inject: inject, apply: apply }
|
|
1207
|
+
return module.exports
|
|
1208
|
+
},
|
|
1209
|
+
})
|