@restregular/dsh-memory 0.7.2 → 0.7.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/README.md +4 -0
- package/lib/client.js +17 -2
- package/lib/panel.js +9 -1
- package/lib/provider/apply.js +10 -0
- package/lib/provider/index.js +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -320,6 +320,10 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
|
|
|
320
320
|
|
|
321
321
|
## 版本
|
|
322
322
|
|
|
323
|
+
- **0.7.3** —— 修复「编辑一条记忆后一直显示待嵌入」:
|
|
324
|
+
- 面板 `/update` 改内容时只删了内存里的向量、**没有把 `.vec` 标脏**,重启后旧向量仍在磁盘上,会被当成“已嵌入”继续用(而且内容已经变了)。现在旧向量在内存与磁盘上一并作废。
|
|
325
|
+
- 编辑后**立即重建这一条**的向量(不再等 60s 的定时回填);重建失败才留在队列里由重试兜底。
|
|
326
|
+
- 面板在有「待嵌入」时每 2s 自动刷新列表与统计(最多 30 次),徽标与计数会自己归零,不用切标签/重进面板。
|
|
323
327
|
- **0.7.2** —— Star / issue 那行改为居中展示。
|
|
324
328
|
- **0.7.1** —— 「服务」页底部加了 Star / issue 入口:「觉得好用?⭐ 去 GitHub 点个 Star · 💬 反馈建议 / 提 issue」,两段都是外链(仓库主页 / 新建 issue)。
|
|
325
329
|
- **0.7.0** —— 作用域语义:**`path` 指定工作区,`scope` 用作作用域显示名(别名)**。
|
package/lib/client.js
CHANGED
|
@@ -898,6 +898,9 @@ window.__ModuleLoader__.load({
|
|
|
898
898
|
)
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
+
/** 待嵌入自动刷新:最多 30 次 × 2s(后端挂着时不无限轮询)。 */
|
|
902
|
+
const PENDING_POLL_LIMIT = 30
|
|
903
|
+
|
|
901
904
|
function MemoryPanel() {
|
|
902
905
|
const [records, setRecords] = React.useState([])
|
|
903
906
|
const [scopes, setScopes] = React.useState([])
|
|
@@ -911,6 +914,7 @@ window.__ModuleLoader__.load({
|
|
|
911
914
|
const [loading, setLoading] = React.useState(true)
|
|
912
915
|
const [error, setError] = React.useState('')
|
|
913
916
|
const [tab, setTab] = React.useState('data')
|
|
917
|
+
const [pendingTick, setPendingTick] = React.useState(0)
|
|
914
918
|
const [creating, setCreating] = React.useState(false)
|
|
915
919
|
|
|
916
920
|
const load = async (query, scopeF) => {
|
|
@@ -1021,6 +1025,17 @@ window.__ModuleLoader__.load({
|
|
|
1021
1025
|
|
|
1022
1026
|
const total = scopes.reduce((n, s) => n + s.records, 0)
|
|
1023
1027
|
const pending = scopes.reduce((n, s) => n + s.pendingEmbeds, 0)
|
|
1028
|
+
// 有"待嵌入"时自动刷新:编辑后向量重建需要一两秒,列表与统计不能一直停在旧状态,
|
|
1029
|
+
// 等用户切标签/重进面板才知道好了。(有上限,后端挂着时不会无限轮询。)
|
|
1030
|
+
React.useEffect(() => {
|
|
1031
|
+
if (pending === 0 || pendingTick >= PENDING_POLL_LIMIT) return undefined
|
|
1032
|
+
if (!configured || !vectorEnabled) return undefined
|
|
1033
|
+
const timer = setTimeout(() => {
|
|
1034
|
+
setPendingTick((n) => n + 1)
|
|
1035
|
+
load()
|
|
1036
|
+
}, 2000)
|
|
1037
|
+
return () => clearTimeout(timer)
|
|
1038
|
+
}, [pendingTick, pending])
|
|
1024
1039
|
// 服务端 /status 给的 scope → label 映射(会话标题、project 的 cwd 只有服务端知道)
|
|
1025
1040
|
const labels = {}
|
|
1026
1041
|
for (const s of scopes) if (s && s.scope && typeof s.label === 'string') labels[s.scope] = s.label
|
|
@@ -1190,13 +1205,13 @@ window.__ModuleLoader__.load({
|
|
|
1190
1205
|
? h(CreateForm, {
|
|
1191
1206
|
scopes,
|
|
1192
1207
|
onCancel: () => setCreating(false),
|
|
1193
|
-
onCreated: () => { setCreating(false); load('', '') },
|
|
1208
|
+
onCreated: () => { setCreating(false); setPendingTick(0); load('', '') },
|
|
1194
1209
|
})
|
|
1195
1210
|
: null
|
|
1196
1211
|
const listBody = !loading && !error && records.length === 0
|
|
1197
1212
|
? h('div', { className: 'empty' }, filtering ? '没有匹配的记忆' : '还没有记忆')
|
|
1198
1213
|
: h('div', { className: 'list' },
|
|
1199
|
-
records.map((rec) => h(RecordCard, { key: rec.id, rec, vectorOn: configured && vectorEnabled, labels: labels, onSaved: () => load(), onDeleted: () => load() })))
|
|
1214
|
+
records.map((rec) => h(RecordCard, { key: rec.id, rec, vectorOn: configured && vectorEnabled, labels: labels, onSaved: () => { setPendingTick(0); load() }, onDeleted: () => { setPendingTick(0); load() } })))
|
|
1200
1215
|
|
|
1201
1216
|
// 服务页底部:一句号召 + 两个外链(Star / issue)。放在内容最后,不打扰上面的状态卡。
|
|
1202
1217
|
const footer = h('div', { className: 'footer' },
|
package/lib/panel.js
CHANGED
|
@@ -422,14 +422,18 @@ async function handle(ctx, routePath, req, res) {
|
|
|
422
422
|
}
|
|
423
423
|
if (!target) throw new ApiError(404, 'RECORD_NOT_FOUND', `no record ${id}`)
|
|
424
424
|
const { s, rec } = target
|
|
425
|
+
let reindex = false
|
|
425
426
|
if (body.content !== undefined) {
|
|
426
427
|
const content = String(body.content)
|
|
427
428
|
if (!content.trim()) throw new ApiError(400, 'CONTENT_EMPTY', 'content 不能为空')
|
|
428
429
|
if (content !== rec.content) {
|
|
429
430
|
rec.content = content
|
|
430
|
-
//
|
|
431
|
+
// 旧向量作废:内存 + 磁盘一起丢掉(vectorsDirty),再排队重建。
|
|
432
|
+
// 只删内存不标 dirty 的话,重启后 load 会看到旧向量、把它当成"已嵌入"。
|
|
431
433
|
s.vectors.delete(id)
|
|
434
|
+
s.vectorsDirty = true
|
|
432
435
|
s.embedPending.add(id)
|
|
436
|
+
reindex = true
|
|
433
437
|
}
|
|
434
438
|
}
|
|
435
439
|
if (body.kind !== undefined) rec.kind = String(body.kind)
|
|
@@ -439,6 +443,10 @@ async function handle(ctx, routePath, req, res) {
|
|
|
439
443
|
rec.updatedAt = Date.now()
|
|
440
444
|
s.dirty = true
|
|
441
445
|
store.scheduleFlush()
|
|
446
|
+
// 立即重建向量(不等 60s 的定时回填);失败就留在 pending 里由重试兜底。
|
|
447
|
+
if (reindex && typeof memory.reindexRecord === 'function') {
|
|
448
|
+
void memory.reindexRecord(rec.scope, id).catch(() => {})
|
|
449
|
+
}
|
|
442
450
|
writeJson(res, { ok: true, value: { record: wireRecord(rec, s) } })
|
|
443
451
|
return
|
|
444
452
|
}
|
package/lib/provider/apply.js
CHANGED
|
@@ -150,6 +150,16 @@ export class CordisMemoryService extends Service {
|
|
|
150
150
|
return this.impl.listSync(input)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
/** 面板编辑后立即重建这一条的向量。 */
|
|
154
|
+
reindexRecord(scope , id ) {
|
|
155
|
+
return this.impl.reindexRecord(scope, id)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 作用域别名(没有则 undefined)。 */
|
|
159
|
+
scopeName(scope ) {
|
|
160
|
+
return this.impl.scopeName(scope)
|
|
161
|
+
}
|
|
162
|
+
|
|
153
163
|
/** 注入设置(面板「设置」标签页读它)。 */
|
|
154
164
|
injectSettings() {
|
|
155
165
|
return this.impl.injectSettings()
|
package/lib/provider/index.js
CHANGED
|
@@ -1274,6 +1274,28 @@ export class LocalMemoryService {
|
|
|
1274
1274
|
return done
|
|
1275
1275
|
}
|
|
1276
1276
|
|
|
1277
|
+
/**
|
|
1278
|
+
* 编辑之后立即重建**这一条**的向量,不等 60s 的回填窗口。
|
|
1279
|
+
* 旧向量同时从内存与磁盘作废(vectorsDirty),失败则留在 pending 里由重试兜底 ——
|
|
1280
|
+
* 绝不能让"新内容 + 旧向量"在重启后被当成已嵌入。
|
|
1281
|
+
*/
|
|
1282
|
+
async reindexRecord(scope , id ) {
|
|
1283
|
+
if (!this.cfg.vector.enabled || !this.cfg.vector.configured) return false
|
|
1284
|
+
const s = this.store.peek(scope)
|
|
1285
|
+
const record = s?.records.get(id)
|
|
1286
|
+
if (!s || !record) return false
|
|
1287
|
+
s.vectors.delete(id)
|
|
1288
|
+
s.vectorsDirty = true
|
|
1289
|
+
s.embedPending.add(id)
|
|
1290
|
+
try {
|
|
1291
|
+
await this.embedRecord(record)
|
|
1292
|
+
} catch { /* 失败留给重试定时器 */ }
|
|
1293
|
+
if (!s.vectors.has(id)) return false
|
|
1294
|
+
s.embedPending.delete(id)
|
|
1295
|
+
this.store.scheduleFlush()
|
|
1296
|
+
return true
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1277
1299
|
/**
|
|
1278
1300
|
* First-fill: embed the ENTIRE backlog (unlike backfillEmbeddings' single
|
|
1279
1301
|
* batch per scope), in throttled batches so a big import does not hammer
|