@restregular/dsh-memory 0.11.1 → 0.12.0

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.
@@ -499,7 +499,13 @@ export class LocalMemoryService {
499
499
  /** 注入设置(面板「设置」标签页可改;落盘在 <storeDir>/settings.json)。 */
500
500
  inject
501
501
  /** 注入半边的审计收集器(可选;没有注入半边时保持 null)。 */
502
- injectAuditSink = null
502
+ injectAuditSink
503
+
504
+
505
+
506
+
507
+
508
+ = null
503
509
 
504
510
  constructor(config = {}) {
505
511
  this.cfg = resolveConfig(config)
@@ -545,13 +551,65 @@ export class LocalMemoryService {
545
551
  }
546
552
 
547
553
  /** 注入半边注册审计收集器。重复注册时后一个覆盖前一个(激活重载)。 */
548
- attachInjectAudit(sink ) {
554
+ attachInjectAudit(sink
555
+
556
+
557
+
558
+
559
+
560
+ ) {
561
+ // 显式解绑:插件半边 dispose 时必须清掉,否则面板会继续读到已停止更新的旧 store。
562
+ if (sink === null) {
563
+ try { this.injectAuditSink?.dispose?.() } catch { /* 审计清理失败不影响 provider */ }
564
+ } else if (this.injectAuditSink !== null && this.injectAuditSink !== sink) {
565
+ // 多激活实例不应悄悄覆盖:保留诊断日志,查询边界仍以最后注册者为准。
566
+ console.warn('[dsh-memory-local] audit sink replaced by another activation')
567
+ }
549
568
  this.injectAuditSink = sink
550
569
  }
551
570
 
552
- /** 面板 /memory/api/audit 用:返回注入评估记录(最新在前);没有注入半边时为空。 */
571
+ /** 显式解绑:只有当前 sink 或未指定 sink 时才清理,避免旧实例卸载误清新实例。 */
572
+ detachInjectAudit(sink ) {
573
+ if (sink !== undefined && this.injectAuditSink !== null && sink !== this.injectAuditSink) return
574
+ try { this.injectAuditSink?.dispose?.() } catch { /* 审计清理失败不影响 provider */ }
575
+ this.injectAuditSink = null
576
+ }
577
+
578
+ /** 兼容旧调用:返回审计条目数组(最新在前);没有注入半边时为空。 */
553
579
  injectAudit(sessionId ) {
554
- try { return this.injectAuditSink?.list(sessionId) ?? [] } catch { return [] }
580
+ try { return this.injectAuditSink?.list?.(sessionId) ?? [] } catch { return [] }
581
+ }
582
+
583
+ /** v2 查询:优先用类型化 sink;旧 sink 只有 list 时降级包装成单页。 */
584
+ injectAuditPage(query ) {
585
+ try {
586
+ const sink = this.injectAuditSink
587
+ if (sink?.query !== undefined) return sink.query(query)
588
+ const q = (query && typeof query === 'object' ? query : {})
589
+ const entries = sink?.list?.(q.sessionId) ?? []
590
+ return {
591
+ entries,
592
+ total: Array.isArray(entries) ? entries.length : 0,
593
+ stats: this.injectAuditStats(),
594
+ }
595
+ } catch {
596
+ return { entries: [], total: 0, stats: this.injectAuditStats() }
597
+ }
598
+ }
599
+
600
+ /** 审计容量/丢弃/写入错误等健康状态。 */
601
+ injectAuditStats() {
602
+ try {
603
+ return this.injectAuditSink?.stats?.() ?? {
604
+ entries: 0, capacity: 0, perSessionCapacity: 0, dropped: 0,
605
+ writeErrors: 0, persistence: 'memory',
606
+ }
607
+ } catch {
608
+ return {
609
+ entries: 0, capacity: 0, perSessionCapacity: 0, dropped: 0,
610
+ writeErrors: 0, persistence: 'degraded',
611
+ }
612
+ }
555
613
  }
556
614
 
557
615
  /** 面板改设置:合并补丁 → 落盘 → 返回新值。写盘失败只告警,不影响运行中的设置。 */
@@ -1908,6 +1966,9 @@ export class LocalMemoryService {
1908
1966
 
1909
1967
  /** Force a synchronous flush (dispose/HMR path). */
1910
1968
  flushSync() {
1969
+ // 审计 sink 属于注入半边:provider 退出时解绑并释放,避免面板继续读旧 store。
1970
+ try { this.injectAuditSink?.dispose?.() } catch { /* 审计清理失败不影响 provider */ }
1971
+ this.injectAuditSink = null
1911
1972
  if (this.maintenanceTimer) {
1912
1973
  clearInterval(this.maintenanceTimer)
1913
1974
  this.maintenanceTimer = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",