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/index.js
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-memory-core — 六层记忆底座的 host 半边。
|
|
3
|
+
*
|
|
4
|
+
* 一期原则(见《一期执行清单》):
|
|
5
|
+
* - 默认只常驻 mem_admin_catalog;其余工具按需注入,用完卸载。
|
|
6
|
+
* - 库打不开时不自吹:注册一个 degraded 目录,把真实错误说出来。
|
|
7
|
+
* - 不碰任何外部记忆文件(MEMORY.md / mnemon)—— 只读引用在 W4 的导入器里做。
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import os from 'node:os'
|
|
11
|
+
import fs from 'node:fs'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
import MemoryStore from './memory/store.js'
|
|
14
|
+
import { buildRegistry } from './memory/tools.js'
|
|
15
|
+
import { Injector } from './memory/inject.js'
|
|
16
|
+
import { attachLifecycle, lifecycleSummary } from './memory/lifecycle.js'
|
|
17
|
+
import { decorateRows, explainRecord } from './memory/explain.js'
|
|
18
|
+
import { readDetail } from './memory/detail.js'
|
|
19
|
+
import { createQqBridge } from './memory/qq.js'
|
|
20
|
+
import { createApiHandler, ensureApiToken, createApiServer } from './memory/api.js'
|
|
21
|
+
import { createQqOfficialBridge } from './memory/qq-official.js'
|
|
22
|
+
import { ingestQqSessions, affectReport } from './memory/affect-events.js'
|
|
23
|
+
import { timeline } from './memory/timeline.js'
|
|
24
|
+
import { ledgerSync, ledgerVerify, healthLine } from './memory/ledger.js'
|
|
25
|
+
import { saveAffectReport } from './memory/affect-report.js'
|
|
26
|
+
import { notifyAffectSpike } from './memory/affect-alert.js'
|
|
27
|
+
import { sendReport } from './memory/notify.js'
|
|
28
|
+
import { listParts } from './parts/index.js'
|
|
29
|
+
import { searchLibrary, catalogMeta } from './parts/library.js'
|
|
30
|
+
import { installPart, uninstallPart, listInstalled, resetActive } from './parts/installer.js'
|
|
31
|
+
import { startJob, getJob, cancelJob } from './parts/jobs.js'
|
|
32
|
+
|
|
33
|
+
export const name = 'memory-core'
|
|
34
|
+
|
|
35
|
+
// 注意:不能把 connection 写成必需依赖 —— 这个宿主里拿不到该服务,
|
|
36
|
+
// 插件会一直 pending,连工具都不注册(2026-10-31 实测)。
|
|
37
|
+
// 改为启动时延迟重试 + 诊断日志。
|
|
38
|
+
export const inject = ['tools', 'systemPrompt']
|
|
39
|
+
|
|
40
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
41
|
+
|
|
42
|
+
// 诊断日志:插件加载/注册的每一步都落盘,出问题不靠猜。
|
|
43
|
+
const DIAG_FILE = path.join(HERE, '..', 'docs', '_rpc-diag.log')
|
|
44
|
+
function diag(message) {
|
|
45
|
+
try {
|
|
46
|
+
fs.appendFileSync(DIAG_FILE, `${new Date().toISOString()} ${message}\n`, 'utf8')
|
|
47
|
+
} catch {
|
|
48
|
+
/* 诊断写失败不影响主流程 */
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 工具宿主:负责动态注入与卸载,保证不会重复注册。 */
|
|
53
|
+
class ToolHost {
|
|
54
|
+
constructor(ctx) {
|
|
55
|
+
this.ctx = ctx
|
|
56
|
+
this.disposers = new Map()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
open(names) {
|
|
60
|
+
for (const toolName of names) {
|
|
61
|
+
if (this.disposers.has(toolName)) continue
|
|
62
|
+
const definition = this.definitions?.get(toolName)
|
|
63
|
+
if (!definition) continue
|
|
64
|
+
const dispose = this.ctx.tools.register(definition)
|
|
65
|
+
this.disposers.set(toolName, dispose)
|
|
66
|
+
}
|
|
67
|
+
return this.injected()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
injected() {
|
|
71
|
+
return [...this.disposers.keys()]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
closeAll() {
|
|
75
|
+
for (const dispose of this.disposers.values()) {
|
|
76
|
+
try {
|
|
77
|
+
dispose()
|
|
78
|
+
} catch {
|
|
79
|
+
/* 卸载失败不阻断 */
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.disposers.clear()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function resolveQqOfficialConfig(cfg, dataDir) {
|
|
87
|
+
const base = { enabled: false, sandbox: false, prefix: '/', allowedOpenids: [], ...(cfg ?? {}) }
|
|
88
|
+
if (!base.appSecret || !base.appId) {
|
|
89
|
+
try {
|
|
90
|
+
const file = path.join(dataDir, 'meta', 'qq-bot.json')
|
|
91
|
+
const json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''))
|
|
92
|
+
if (!base.appId && json.appId) base.appId = String(json.appId)
|
|
93
|
+
if (!base.appSecret && json.appSecret) base.appSecret = String(json.appSecret)
|
|
94
|
+
if (json.sandbox !== undefined && cfg?.sandbox === undefined) base.sandbox = Boolean(json.sandbox)
|
|
95
|
+
if (!Array.isArray(base.allowedOpenids) || base.allowedOpenids.length === 0) {
|
|
96
|
+
if (Array.isArray(json.allowedOpenids)) base.allowedOpenids = json.allowedOpenids
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
/* 没有文件就保持原样 */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return base
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resolveDataDir(config) {
|
|
106
|
+
if (config && typeof config.dataDir === 'string' && config.dataDir.trim()) return path.resolve(config.dataDir)
|
|
107
|
+
if (process.env.DSH_MEMORY_DATA_DIR) return path.resolve(process.env.DSH_MEMORY_DATA_DIR)
|
|
108
|
+
// 没有配置时的自愈默认:仓库旁的 dsh-memory-data 存在就用它(当前布局),否则退回用户目录
|
|
109
|
+
const besideRepo = path.resolve(HERE, '..', '..', 'dsh-memory-data')
|
|
110
|
+
try {
|
|
111
|
+
if (fs.existsSync(besideRepo)) return besideRepo
|
|
112
|
+
} catch {
|
|
113
|
+
/* 忽略 */
|
|
114
|
+
}
|
|
115
|
+
return path.join(os.homedir(), '.dsh', 'memory-core-data')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function resolveAuthority(config) {
|
|
119
|
+
const fromConfig = config && typeof config.authority === 'string' ? config.authority : null
|
|
120
|
+
const fromEnv = process.env.DSH_MEMORY_AUTHORITY ?? null
|
|
121
|
+
return fromConfig || fromEnv || 'shadow'
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function degradedCatalog(error, dataDir) {
|
|
125
|
+
return {
|
|
126
|
+
name: 'mem_admin_catalog',
|
|
127
|
+
description: '六层记忆底座的能力目录(当前降级:库打不开)',
|
|
128
|
+
parameters: { type: 'object', additionalProperties: false, properties: {} },
|
|
129
|
+
output: {
|
|
130
|
+
schema: {
|
|
131
|
+
type: 'object',
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
properties: { text: { type: 'string' }, degraded: { type: 'boolean' }, reason: { type: 'string' } },
|
|
134
|
+
required: ['text'],
|
|
135
|
+
},
|
|
136
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
137
|
+
},
|
|
138
|
+
isConcurrencySafe: () => true,
|
|
139
|
+
execute: async () => ({
|
|
140
|
+
text: [
|
|
141
|
+
'memory-core 处于降级状态:记忆库打不开,所有记忆工具不可用。',
|
|
142
|
+
`原因:${error?.message ?? String(error)}`,
|
|
143
|
+
`数据目录:${dataDir}`,
|
|
144
|
+
'处理:检查该目录是否可写、是否被另一个进程占用(WAL 锁),然后重启 DSH。',
|
|
145
|
+
].join('\n'),
|
|
146
|
+
degraded: true,
|
|
147
|
+
reason: error?.message ?? String(error),
|
|
148
|
+
}),
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @param {any} ctx @param {{dataDir?:string, authority?:string}} [config] */
|
|
153
|
+
export function apply(ctx, config = {}) {
|
|
154
|
+
const dataDir = resolveDataDir(config)
|
|
155
|
+
const authority = resolveAuthority(config)
|
|
156
|
+
const logger = ctx.logger
|
|
157
|
+
diag('apply start: dataDir=' + dataDir)
|
|
158
|
+
|
|
159
|
+
let store = null
|
|
160
|
+
let openError = null
|
|
161
|
+
try {
|
|
162
|
+
store = new MemoryStore({ dataDir, authority }).open()
|
|
163
|
+
diag('store open ok: schema=' + store.getMeta('schema_version'))
|
|
164
|
+
} catch (error) {
|
|
165
|
+
openError = error
|
|
166
|
+
diag('store open FAILED: ' + (error?.message ?? String(error)))
|
|
167
|
+
logger?.warn?.(`memory-core: 记忆库打开失败(进入降级):${error?.message ?? error}`)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 每轮注入器:默认 3 条 / 500 字 / 同源最多 1 条(P1 组合检查)
|
|
171
|
+
const injector = store
|
|
172
|
+
? new Injector({
|
|
173
|
+
store,
|
|
174
|
+
affect: config.affect?.hint === false ? null : { hours: Number(config.affect?.hours ?? 3), threshold: Number(config.affect?.threshold ?? 2) },
|
|
175
|
+
})
|
|
176
|
+
: null
|
|
177
|
+
diag('injector ' + (injector ? 'ok' : 'skipped'))
|
|
178
|
+
|
|
179
|
+
// QQ 机器人桥(OneBot v11 WebSocket 客户端):只有显式开 enabled 才连
|
|
180
|
+
const qq = store ? createQqBridge({ store, config: config.qq ?? {}, log: (m) => diag(m) }) : null
|
|
181
|
+
if (qq && qq.enabled) {
|
|
182
|
+
try {
|
|
183
|
+
ctx.effect(() => {
|
|
184
|
+
qq.start()
|
|
185
|
+
diag('qq: 桥已启动 wsUrl=' + String(config.qq?.wsUrl ?? ''))
|
|
186
|
+
return () => {
|
|
187
|
+
qq.stop()
|
|
188
|
+
diag('qq: 桥已停止')
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
} catch (error) {
|
|
192
|
+
diag('qq: 启动失败 ' + (error?.message ?? String(error)))
|
|
193
|
+
}
|
|
194
|
+
} else if (qq) {
|
|
195
|
+
diag('qq: 未启用(config.qq.enabled=true 才连)')
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// QQ 官方机器人(QQ Bot v2):AppSecret 从配置或 meta/qq-bot.json 读
|
|
199
|
+
let qqOfficial = null
|
|
200
|
+
const qqOfficialConfig = resolveQqOfficialConfig(config.qqOfficial, dataDir)
|
|
201
|
+
if (store && qqOfficialConfig.enabled) {
|
|
202
|
+
qqOfficial = createQqOfficialBridge({ store, config: qqOfficialConfig, log: (m) => diag(m) })
|
|
203
|
+
if (qqOfficial.enabled) {
|
|
204
|
+
try {
|
|
205
|
+
ctx.effect(() => {
|
|
206
|
+
qqOfficial.start()
|
|
207
|
+
diag('qq-official: 已启动 appId=' + String(qqOfficialConfig.appId))
|
|
208
|
+
return () => {
|
|
209
|
+
qqOfficial.stop()
|
|
210
|
+
diag('qq-official: 已停止')
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
} catch (error) {
|
|
214
|
+
diag('qq-official: 启动失败 ' + (error?.message ?? String(error)))
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
diag('qq-official: 缺少 appSecret,未启动(填 meta/qq-bot.json)')
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 情绪事件采集:每 10 分钟扫一次 QQ 会话(config.affect.enabled=false 可关)
|
|
222
|
+
if (store && config.affect?.enabled !== false) {
|
|
223
|
+
const runIngest = () => {
|
|
224
|
+
try {
|
|
225
|
+
const r = ingestQqSessions({ store, sessionsRoot: config.affect?.sessionsRoot, limit: config.affect?.limit ?? 10 })
|
|
226
|
+
if (r.added > 0) diag('affect: 采集新增 ' + r.added + ' 条(扫描 ' + r.scanned + ')')
|
|
227
|
+
} catch (error) {
|
|
228
|
+
diag('affect: 采集失败 ' + (error?.message ?? String(error)))
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
runIngest()
|
|
232
|
+
const affectTimer = setInterval(runIngest, Number(config.affect?.pollMs ?? 600000))
|
|
233
|
+
affectTimer.unref?.()
|
|
234
|
+
ctx.effect(() => () => clearInterval(affectTimer))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 二期:日报/周报落盘(每 6 小时;周一 9 点补周报)
|
|
238
|
+
if (store && config.affect?.enabled !== false) {
|
|
239
|
+
const runReport = () => {
|
|
240
|
+
try {
|
|
241
|
+
saveAffectReport({ store, dataDir, range: 'day' })
|
|
242
|
+
const now = new Date()
|
|
243
|
+
if (now.getDay() === 1 && now.getHours() === 9) saveAffectReport({ store, dataDir, range: 'week' })
|
|
244
|
+
try {
|
|
245
|
+
ledgerSync({ store })
|
|
246
|
+
const line = healthLine({ store })
|
|
247
|
+
const dir = path.join(dataDir, 'reports')
|
|
248
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
249
|
+
fs.appendFileSync(path.join(dir, 'health.log'), line + '\n', 'utf8')
|
|
250
|
+
} catch (error) {
|
|
251
|
+
diag('health: 写入失败 ' + (error?.message ?? String(error)))
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
diag('affect: 报告写入失败 ' + (error?.message ?? String(error)))
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
runReport()
|
|
258
|
+
const reportTimer = setInterval(runReport, 6 * 3600 * 1000)
|
|
259
|
+
reportTimer.unref?.()
|
|
260
|
+
ctx.effect(() => () => clearInterval(reportTimer))
|
|
261
|
+
|
|
262
|
+
// 三期:情绪尖峰主动通知(默认走现有邮件/飞书通道,6 小时冷却)
|
|
263
|
+
if (config.affect?.notify !== false) {
|
|
264
|
+
const runAlert = () => {
|
|
265
|
+
notifyAffectSpike({
|
|
266
|
+
store,
|
|
267
|
+
notify: (msg) => sendReport(msg),
|
|
268
|
+
options: { hours: Number(config.affect?.hours ?? 3), threshold: Number(config.affect?.threshold ?? 2) },
|
|
269
|
+
})
|
|
270
|
+
.then((r) => {
|
|
271
|
+
if (r.sent) diag('affect: 已发送情绪提醒')
|
|
272
|
+
})
|
|
273
|
+
.catch(() => {})
|
|
274
|
+
}
|
|
275
|
+
runAlert()
|
|
276
|
+
const alertTimer = setInterval(runAlert, 30 * 60 * 1000)
|
|
277
|
+
alertTimer.unref?.()
|
|
278
|
+
ctx.effect(() => () => clearInterval(alertTimer))
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// 对外 HTTP API(token 鉴权):config.api.enabled 才开,默认只读
|
|
283
|
+
let apiHandler = null
|
|
284
|
+
if (store && config.api?.enabled) {
|
|
285
|
+
try {
|
|
286
|
+
const apiToken = ensureApiToken({ dataDir, configured: config.api?.token })
|
|
287
|
+
apiHandler = createApiHandler({ store, token: apiToken, allowWrite: config.api?.allowWrite === true })
|
|
288
|
+
diag('api: 已启用(写入=' + (config.api?.allowWrite === true ? '开' : '关') + ')')
|
|
289
|
+
} catch (error) {
|
|
290
|
+
diag('api: 启用失败 ' + (error?.message ?? String(error)))
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 固定端口监听(可选):config.api.port;不配就只走 DSH webServer 的随机端口
|
|
295
|
+
if (apiHandler && Number(config.api?.port) > 0) {
|
|
296
|
+
try {
|
|
297
|
+
const apiServer = createApiServer({ handler: apiHandler })
|
|
298
|
+
apiServer.listen(Number(config.api.port), '127.0.0.1')
|
|
299
|
+
ctx.effect(() => () => {
|
|
300
|
+
try {
|
|
301
|
+
apiServer.close()
|
|
302
|
+
} catch {
|
|
303
|
+
/* 忽略 */
|
|
304
|
+
}
|
|
305
|
+
})
|
|
306
|
+
diag('api: 固定端口监听 127.0.0.1:' + config.api.port)
|
|
307
|
+
} catch (error) {
|
|
308
|
+
diag('api: 固定端口启动失败 ' + (error?.message ?? String(error)))
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 注意:服务注册被刻意放到工具注册之后(见文件末尾)。
|
|
313
|
+
// 服务化是增值功能,不能因为它失败导致工具不可用。
|
|
314
|
+
|
|
315
|
+
const host = new ToolHost(ctx)
|
|
316
|
+
const registry = store ? buildRegistry(store, host) : null
|
|
317
|
+
host.definitions = registry
|
|
318
|
+
? new Map([...registry.entries()].map(([toolName, item]) => [toolName, item.definition]))
|
|
319
|
+
: new Map()
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
ctx.effect(() => {
|
|
323
|
+
const disposers = []
|
|
324
|
+
|
|
325
|
+
// 常驻:目录 + 注入 + 单次调用(三者都刻意保持极短)
|
|
326
|
+
const resident = store
|
|
327
|
+
? ['mem_admin_catalog', 'mem_admin_open', 'mem_admin_call']
|
|
328
|
+
: []
|
|
329
|
+
for (const toolName of resident) {
|
|
330
|
+
try {
|
|
331
|
+
disposers.push(ctx.tools.register(registry.get(toolName).definition))
|
|
332
|
+
} catch (error) {
|
|
333
|
+
diag('register failed ' + toolName + ': ' + (error?.message ?? String(error)))
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!store) {
|
|
337
|
+
try {
|
|
338
|
+
disposers.push(ctx.tools.register(degradedCatalog(openError, dataDir)))
|
|
339
|
+
} catch (error) {
|
|
340
|
+
diag('degraded catalog failed: ' + (error?.message ?? String(error)))
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return () => {
|
|
345
|
+
host.closeAll()
|
|
346
|
+
for (const dispose of disposers) {
|
|
347
|
+
try {
|
|
348
|
+
dispose()
|
|
349
|
+
} catch {
|
|
350
|
+
/* 忽略 */
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
store?.close()
|
|
355
|
+
} catch {
|
|
356
|
+
/* 忽略 */
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}, 'memory-core.tools')
|
|
360
|
+
diag('tools registered')
|
|
361
|
+
} catch (error) {
|
|
362
|
+
diag('tools effect FAILED: ' + (error?.message ?? String(error)))
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// P6 服务化已拆到独立插件行 lib/service-plugin.js:
|
|
366
|
+
// 主插件不再调用 ctx.provide —— 那一步一旦抛错会把整个插件带崩。
|
|
367
|
+
|
|
368
|
+
if (store) {
|
|
369
|
+
try {
|
|
370
|
+
ctx.systemPrompt?.section?.({
|
|
371
|
+
name: 'memory-core',
|
|
372
|
+
order: 58,
|
|
373
|
+
text: [
|
|
374
|
+
'# 六层记忆底座(memory-core)',
|
|
375
|
+
'- 默认只常驻 mem_admin_catalog;要用检索/写入,先 mem_admin_open 注入 mem_search / mem_write / mem_read。',
|
|
376
|
+
'- 检索无命中就是空,不要编造"没有找到相关记忆"这类话术;写入前不要替用户润色事实。',
|
|
377
|
+
'- S 级(凭证类)记录默认不进检索结果,需要时显式 include_sensitive=true 并说明理由。',
|
|
378
|
+
].join('\n'),
|
|
379
|
+
})
|
|
380
|
+
} catch {
|
|
381
|
+
/* systemPrompt 可选,缺失不影响工具 */
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// P1:动态记忆快照。每次组装系统提示词时调用,取指针、按预算截断、无内容即空。
|
|
385
|
+
// 用 context 而不是 section:它是"模型可见的数据快照",不是指令。
|
|
386
|
+
if (injector) {
|
|
387
|
+
try {
|
|
388
|
+
ctx.effect(() => {
|
|
389
|
+
const dispose = ctx.systemPrompt?.context?.({
|
|
390
|
+
name: 'memory-core',
|
|
391
|
+
order: 60,
|
|
392
|
+
text: () => injector.text(),
|
|
393
|
+
})
|
|
394
|
+
return () => {
|
|
395
|
+
try {
|
|
396
|
+
dispose?.()
|
|
397
|
+
} catch {
|
|
398
|
+
/* 忽略 */
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}, 'memory-core.context')
|
|
402
|
+
} catch {
|
|
403
|
+
/* systemPrompt.context 不可用时静默降级:只保留工具 */
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// P7:每轮记忆生命周期 —— 自动召回(agent/pre-step)+ 候选沉淀(turn/end → pending)。
|
|
408
|
+
// 这一层让记忆不再依赖"模型想得起来调 mem_search"。
|
|
409
|
+
if (store) {
|
|
410
|
+
try {
|
|
411
|
+
ctx.effect(() => {
|
|
412
|
+
const dispose = attachLifecycle(ctx, {
|
|
413
|
+
store,
|
|
414
|
+
config: config.lifecycle ?? {},
|
|
415
|
+
diag,
|
|
416
|
+
})
|
|
417
|
+
return () => {
|
|
418
|
+
try {
|
|
419
|
+
dispose?.()
|
|
420
|
+
} catch {
|
|
421
|
+
/* 忽略 */
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}, 'memory-core.lifecycle')
|
|
425
|
+
} catch (error) {
|
|
426
|
+
diag('lifecycle: attach failed: ' + (error?.message ?? String(error)))
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// P4:设置页「记忆底座」的 RPC 通道。UI 只读 + 审核,不直接读库。
|
|
431
|
+
// 宿主里 connection 服务可能在 apply 时还没就绪;这里延迟重试,
|
|
432
|
+
// 并把探测结果写进 docs/_rpc-diag.log,避免靠猜。
|
|
433
|
+
ctx.effect(() => {
|
|
434
|
+
const diagFile = path.join(HERE, '..', 'docs', '_rpc-diag.log')
|
|
435
|
+
const diag = (msg) => {
|
|
436
|
+
try {
|
|
437
|
+
fs.appendFileSync(diagFile, `${new Date().toISOString()} ${msg}\n`, 'utf8')
|
|
438
|
+
} catch {
|
|
439
|
+
/* 诊断写失败不影响主流程 */
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
diag('apply: connection=' + Boolean(ctx.get?.('connection')) + ' webServer=' + Boolean(ctx.get?.('webServer')))
|
|
444
|
+
} catch (e) {
|
|
445
|
+
diag('probe failed: ' + (e?.message ?? String(e)))
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const parseHits = (raw) => {
|
|
449
|
+
try {
|
|
450
|
+
const v = JSON.parse(raw || '[]')
|
|
451
|
+
return Array.isArray(v) ? v : []
|
|
452
|
+
} catch {
|
|
453
|
+
return []
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const recentTraces = (limit) => {
|
|
457
|
+
if (!store) return []
|
|
458
|
+
const n = Math.min(Math.max(Number(limit) || 20, 1), 200)
|
|
459
|
+
return store.db
|
|
460
|
+
.prepare('SELECT trace_id, at, op, query_preview, hits FROM traces ORDER BY at DESC LIMIT ?')
|
|
461
|
+
.all(n)
|
|
462
|
+
.map((t) => ({ ...t, hits: parseHits(t.hits) }))
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const handler = async (endpoint, payload) => {
|
|
466
|
+
const args = payload || {}
|
|
467
|
+
try {
|
|
468
|
+
if (!store) {
|
|
469
|
+
return { ok: false, error: { code: 'memory/degraded', message: openError?.message ?? '记忆库不可用' } }
|
|
470
|
+
}
|
|
471
|
+
if (endpoint === 'status') {
|
|
472
|
+
const s = store.stats()
|
|
473
|
+
return { ok: true, value: { ...s, lifecycle: lifecycleSummary(), qq: qq ? qq.status() : null, qqOfficial: qqOfficial ? qqOfficial.status() : null, recent: recentTraces(5) } }
|
|
474
|
+
}
|
|
475
|
+
if (endpoint === 'search') {
|
|
476
|
+
return { ok: true, value: decorateRows(store.search({ query: String(args.query ?? ''), topK: args.topK })) }
|
|
477
|
+
}
|
|
478
|
+
if (endpoint === 'read') {
|
|
479
|
+
return {
|
|
480
|
+
ok: true,
|
|
481
|
+
value: readDetail({
|
|
482
|
+
store,
|
|
483
|
+
recordId: String(args.record_id ?? ''),
|
|
484
|
+
includeSensitive: Boolean(args.includeSensitive),
|
|
485
|
+
}),
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (endpoint === 'pending') return { ok: true, value: decorateRows(store.pendingReview(args.limit)) }
|
|
489
|
+
if (endpoint === 'handoffs') return { ok: true, value: store.handoffList() }
|
|
490
|
+
if (endpoint === 'handoff') return { ok: true, value: store.handoffRead(String(args.scene ?? '')) }
|
|
491
|
+
if (endpoint === 'check') return { ok: true, value: store.checkBudgets(args.scene ?? null) }
|
|
492
|
+
if (endpoint === 'tasks') {
|
|
493
|
+
return { ok: true, value: store.taskList({ scene: args.scene ?? null, scope: args.scope ?? 'all' }) }
|
|
494
|
+
}
|
|
495
|
+
if (endpoint === 'task') return { ok: true, value: store.taskGet(String(args.task_id ?? '')) }
|
|
496
|
+
if (endpoint === 'review') {
|
|
497
|
+
return { ok: true, value: store.review(String(args.record_id ?? ''), String(args.decision ?? ''), args.note ?? null) }
|
|
498
|
+
}
|
|
499
|
+
if (endpoint === 'traces') return { ok: true, value: recentTraces(args.limit) }
|
|
500
|
+
if (endpoint === 'parts') return { ok: true, value: listParts() }
|
|
501
|
+
if (endpoint === 'graph/view') {
|
|
502
|
+
const id = String(args.record_id ?? '')
|
|
503
|
+
if (!id) return { ok: false, error: { message: 'record_id 必填' } }
|
|
504
|
+
if (store.db.prepare('SELECT COUNT(*) AS n FROM edges').get().n === 0) store.buildEdges()
|
|
505
|
+
return { ok: true, value: store.graphNeighbors(id, { hops: args.hops ?? 1, edgeTypes: args.edge_types ?? null }) }
|
|
506
|
+
}
|
|
507
|
+
if (endpoint === 'records') {
|
|
508
|
+
const layer = String(args.layer ?? '')
|
|
509
|
+
const limit = Math.min(Math.max(Number(args.limit ?? 200), 1), 500)
|
|
510
|
+
const rows = layer
|
|
511
|
+
? store.db.prepare("SELECT record_id, layer, sad_level, summary, created_at FROM records WHERE status = 'active' AND layer = ? ORDER BY created_at DESC LIMIT ?").all(layer, limit)
|
|
512
|
+
: store.db.prepare("SELECT record_id, layer, sad_level, summary, created_at FROM records WHERE status = 'active' ORDER BY created_at DESC LIMIT ?").all(limit)
|
|
513
|
+
return { ok: true, value: decorateRows(rows) }
|
|
514
|
+
}
|
|
515
|
+
if (endpoint === 'graph.all') {
|
|
516
|
+
if (store.db.prepare('SELECT COUNT(*) AS n FROM edges').get().n === 0) store.buildEdges()
|
|
517
|
+
const nodes = store.db.prepare("SELECT record_id, layer, sad_level, summary, created_at FROM records WHERE status = 'active' LIMIT 300").all()
|
|
518
|
+
const edges = store.db.prepare('SELECT from_id, to_id, kind FROM edges LIMIT 3000').all()
|
|
519
|
+
return { ok: true, value: { nodes: decorateRows(nodes), edges } }
|
|
520
|
+
}
|
|
521
|
+
if (endpoint === 'timeline') {
|
|
522
|
+
const data = timeline({ store, days: args.days ?? 7 })
|
|
523
|
+
const groups = (data?.groups ?? []).map((g) => ({ ...g, memories: decorateRows(g.memories) }))
|
|
524
|
+
return { ok: true, value: { ...data, groups } }
|
|
525
|
+
}
|
|
526
|
+
if (endpoint === 'affect/report') return { ok: true, value: affectReport({ store, range: args.range ?? 'day' }) }
|
|
527
|
+
if (endpoint === 'affect/ingest') return { ok: true, value: ingestQqSessions({ store, limit: args.limit ?? 20 }) }
|
|
528
|
+
if (endpoint === 'parts/meta') return { ok: true, value: catalogMeta() }
|
|
529
|
+
if (endpoint === 'parts/library') return { ok: true, value: searchLibrary(args) }
|
|
530
|
+
if (endpoint === 'parts/installed') {
|
|
531
|
+
const dshHome = process.env.DSH_HOME ?? path.join(os.homedir(), '.dsh')
|
|
532
|
+
const profile = String(config.profile ?? process.env.DSH_PROFILE ?? 'desktop')
|
|
533
|
+
return { ok: true, value: listInstalled({ dshHome, profile }) }
|
|
534
|
+
}
|
|
535
|
+
if (endpoint === 'parts/install') {
|
|
536
|
+
if (config.parts?.allowInstall === false) return { ok: false, error: { code: 'memory/forbidden', message: '安装已禁用(config.parts.allowInstall=false)' } }
|
|
537
|
+
const dshHome = process.env.DSH_HOME ?? path.join(os.homedir(), '.dsh')
|
|
538
|
+
const profile = String(config.profile ?? process.env.DSH_PROFILE ?? 'desktop')
|
|
539
|
+
const job = startJob(async (progress, setAbort) => {
|
|
540
|
+
try { return await installPart({ item: args.item, profile, dshHome, onProgress: progress, registerAbort: setAbort }) }
|
|
541
|
+
finally { resetActive() }
|
|
542
|
+
})
|
|
543
|
+
return { ok: true, value: { jobId: job.id } }
|
|
544
|
+
}
|
|
545
|
+
if (endpoint === 'parts/uninstall') {
|
|
546
|
+
if (config.parts?.allowInstall === false) return { ok: false, error: { code: 'memory/forbidden', message: '卸载已禁用(config.parts.allowInstall=false)' } }
|
|
547
|
+
const dshHome = process.env.DSH_HOME ?? path.join(os.homedir(), '.dsh')
|
|
548
|
+
const profile = String(config.profile ?? process.env.DSH_PROFILE ?? 'desktop')
|
|
549
|
+
const job = startJob(async (progress, setAbort) => {
|
|
550
|
+
try { return await uninstallPart({ name: args.name, profile, dshHome, onProgress: progress, registerAbort: setAbort }) }
|
|
551
|
+
finally { resetActive() }
|
|
552
|
+
})
|
|
553
|
+
return { ok: true, value: { jobId: job.id } }
|
|
554
|
+
}
|
|
555
|
+
if (endpoint === 'parts/job') return { ok: true, value: getJob(args.jobId) }
|
|
556
|
+
if (endpoint === 'parts/job/cancel') return { ok: true, value: cancelJob(args.jobId) }
|
|
557
|
+
if (endpoint === 'observe') {
|
|
558
|
+
// 观测层:近 24h 的注入/召回活动 + 库健康,供面板和 dsh-context 对照
|
|
559
|
+
const since = new Date(Date.now() - 24 * 3600 * 1000).toISOString()
|
|
560
|
+
const injectRows = store.db
|
|
561
|
+
.prepare("SELECT injected FROM traces WHERE op = 'inject' AND at >= ?")
|
|
562
|
+
.all(since)
|
|
563
|
+
let pointers = 0
|
|
564
|
+
for (const r of injectRows) {
|
|
565
|
+
try {
|
|
566
|
+
const a = JSON.parse(r.injected || '[]')
|
|
567
|
+
if (Array.isArray(a)) pointers += a.length
|
|
568
|
+
} catch {
|
|
569
|
+
/* 忽略坏行 */
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const searchRows = store.db
|
|
573
|
+
.prepare("SELECT hits FROM traces WHERE op = 'search' AND at >= ?")
|
|
574
|
+
.all(since)
|
|
575
|
+
let hits = 0
|
|
576
|
+
for (const r of searchRows) {
|
|
577
|
+
try {
|
|
578
|
+
if (JSON.parse(r.hits || '[]').length > 0) hits += 1
|
|
579
|
+
} catch {
|
|
580
|
+
/* 忽略坏行 */
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
// 近 14 天情绪趋势:每天写入量 + 负面/正面条数(缺的日期补 0)
|
|
584
|
+
const trendDays = 14
|
|
585
|
+
const trendSince = new Date(Date.now() - (trendDays - 1) * 24 * 3600 * 1000).toISOString().slice(0, 10)
|
|
586
|
+
const rawTrend = store.db
|
|
587
|
+
.prepare(
|
|
588
|
+
`SELECT substr(created_at, 1, 10) AS day, COUNT(*) AS n,
|
|
589
|
+
SUM(CASE WHEN affect_label IN ('negative', 'urgent') THEN 1 ELSE 0 END) AS bad,
|
|
590
|
+
SUM(CASE WHEN affect_label = 'positive' THEN 1 ELSE 0 END) AS good
|
|
591
|
+
FROM records
|
|
592
|
+
WHERE status = 'active' AND substr(created_at, 1, 10) >= ?
|
|
593
|
+
GROUP BY day`,
|
|
594
|
+
)
|
|
595
|
+
.all(trendSince)
|
|
596
|
+
const byDay = new Map(rawTrend.map((r) => [r.day, r]))
|
|
597
|
+
const trend = []
|
|
598
|
+
for (let i = trendDays - 1; i >= 0; i -= 1) {
|
|
599
|
+
const day = new Date(Date.now() - i * 24 * 3600 * 1000).toISOString().slice(0, 10)
|
|
600
|
+
const row = byDay.get(day)
|
|
601
|
+
trend.push({ day, n: row?.n ?? 0, bad: row?.bad ?? 0, good: row?.good ?? 0 })
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
ok: true,
|
|
605
|
+
value: {
|
|
606
|
+
windowHours: 24,
|
|
607
|
+
injectCount: injectRows.length,
|
|
608
|
+
avgPointers: injectRows.length ? Math.round((pointers / injectRows.length) * 10) / 10 : 0,
|
|
609
|
+
searchCount: searchRows.length,
|
|
610
|
+
hitCount: hits,
|
|
611
|
+
affect: Object.fromEntries(
|
|
612
|
+
store.db
|
|
613
|
+
.prepare(
|
|
614
|
+
"SELECT COALESCE(affect_label, 'neutral') AS label, COUNT(*) AS n FROM records WHERE status = 'active' GROUP BY label",
|
|
615
|
+
)
|
|
616
|
+
.all()
|
|
617
|
+
.map((r) => [r.label, r.n]),
|
|
618
|
+
),
|
|
619
|
+
trend,
|
|
620
|
+
stats: store.stats(),
|
|
621
|
+
},
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return { ok: false, error: { code: 'memory/unknown-endpoint', message: 'unknown endpoint: ' + String(endpoint) } }
|
|
625
|
+
} catch (error) {
|
|
626
|
+
return { ok: false, error: { code: 'memory/error', message: error?.message ?? String(error) } }
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
let dispose = null
|
|
631
|
+
let timer = null
|
|
632
|
+
let tries = 0
|
|
633
|
+
|
|
634
|
+
// 退路:桌面宿主没有 connection 服务(它属于 dsh web),
|
|
635
|
+
// 但 webServer.register 一定在。这里手工实现同一条 RPC 信封协议。
|
|
636
|
+
const registerRaw = () => {
|
|
637
|
+
const webServer = ctx.get?.('webServer')
|
|
638
|
+
if (!webServer || typeof webServer.register !== 'function') {
|
|
639
|
+
diag('webServer 也不可用')
|
|
640
|
+
return false
|
|
641
|
+
}
|
|
642
|
+
const wantPath = '/memory-core'
|
|
643
|
+
try {
|
|
644
|
+
dispose = webServer.register({
|
|
645
|
+
kind: 'prefix',
|
|
646
|
+
path: wantPath,
|
|
647
|
+
handler: async (req, res) => {
|
|
648
|
+
try {
|
|
649
|
+
const pathname = new URL(req.url, 'http://127.0.0.1').pathname
|
|
650
|
+
const endpoint = pathname.slice(wantPath.length + 1)
|
|
651
|
+
if (req.method !== 'POST' || !endpoint) {
|
|
652
|
+
res.statusCode = 404
|
|
653
|
+
res.end('not found')
|
|
654
|
+
return
|
|
655
|
+
}
|
|
656
|
+
// 原始路由不走 connection 的 Host/Origin 围栏,这里补一个最小同源校验
|
|
657
|
+
const origin = req.headers.origin
|
|
658
|
+
if (origin) {
|
|
659
|
+
try {
|
|
660
|
+
if (new URL(origin).host !== req.headers.host) {
|
|
661
|
+
res.statusCode = 403
|
|
662
|
+
res.end('forbidden')
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
} catch {
|
|
666
|
+
res.statusCode = 403
|
|
667
|
+
res.end('forbidden')
|
|
668
|
+
return
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
let body = ''
|
|
672
|
+
for await (const chunk of req) body += chunk
|
|
673
|
+
// 对外 HTTP API(token 鉴权),不走 RPC 信封
|
|
674
|
+
if (apiHandler && endpoint.startsWith('api/')) {
|
|
675
|
+
let parsed = {}
|
|
676
|
+
try {
|
|
677
|
+
parsed = body ? JSON.parse(body) : {}
|
|
678
|
+
} catch {
|
|
679
|
+
parsed = {}
|
|
680
|
+
}
|
|
681
|
+
const apiResult = await apiHandler({
|
|
682
|
+
path: endpoint.slice(4),
|
|
683
|
+
method: req.method ?? 'POST',
|
|
684
|
+
headers: req.headers ?? {},
|
|
685
|
+
body: parsed,
|
|
686
|
+
})
|
|
687
|
+
res.statusCode = apiResult.status
|
|
688
|
+
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
689
|
+
res.end(JSON.stringify(apiResult.json))
|
|
690
|
+
return
|
|
691
|
+
}
|
|
692
|
+
const msg = JSON.parse(body || '{}')
|
|
693
|
+
const result = await handler(endpoint, msg.payload || {})
|
|
694
|
+
res.setHeader('content-type', 'application/json')
|
|
695
|
+
res.end(JSON.stringify({ type: 'server-response', rpcId: msg.rpcId ?? 'unknown', result }))
|
|
696
|
+
} catch (error) {
|
|
697
|
+
res.statusCode = 400
|
|
698
|
+
res.end(String(error?.message ?? error))
|
|
699
|
+
}
|
|
700
|
+
},
|
|
701
|
+
})
|
|
702
|
+
diag('registered raw prefix route via webServer: ' + wantPath)
|
|
703
|
+
return true
|
|
704
|
+
} catch (error) {
|
|
705
|
+
diag('raw register failed: ' + (error?.message ?? String(error)))
|
|
706
|
+
return false
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const attempt = () => {
|
|
711
|
+
if (dispose) return
|
|
712
|
+
tries += 1
|
|
713
|
+
const connection = ctx.get?.('connection')
|
|
714
|
+
if (connection && connection.rpc && typeof connection.rpc.handle === 'function') {
|
|
715
|
+
try {
|
|
716
|
+
dispose = connection.rpc.handle('/memory-core', handler)
|
|
717
|
+
diag('registered via connection(第 ' + tries + ' 次尝试)')
|
|
718
|
+
return
|
|
719
|
+
} catch (error) {
|
|
720
|
+
diag('connection register failed: ' + (error?.message ?? String(error)))
|
|
721
|
+
}
|
|
722
|
+
} else if (tries === 1) {
|
|
723
|
+
diag('connection 不可用,改走 webServer 原始路由')
|
|
724
|
+
}
|
|
725
|
+
if (tries <= 3 && registerRaw()) return
|
|
726
|
+
if (tries < 30) timer = setTimeout(attempt, 1000)
|
|
727
|
+
else diag('give up: connection 与 webServer 都不可用')
|
|
728
|
+
}
|
|
729
|
+
attempt()
|
|
730
|
+
|
|
731
|
+
return () => {
|
|
732
|
+
if (timer) clearTimeout(timer)
|
|
733
|
+
try {
|
|
734
|
+
dispose?.()
|
|
735
|
+
} catch {
|
|
736
|
+
/* 忽略 */
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}, 'memory-core.rpc')
|
|
740
|
+
}
|
|
741
|
+
}
|