whale-memory-core 0.19.1 → 0.19.2

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/index.js CHANGED
@@ -19,3 +19,4 @@ export * as archive from './lib/archive.js'
19
19
  export * as timeSense from './lib/time-sense.js'
20
20
  export * as relativeWindow from './lib/relative-window.js'
21
21
  export * as personCard from './lib/person-card.js'
22
+ export * as scopeKey from './lib/scope-key.js'
@@ -0,0 +1,10 @@
1
+ /** 去掉人设后缀(#p_xxx),得到会话级键 */
2
+ export function baseChatKey(chatKey: string): string
3
+ /** 这个键是不是人设级 */
4
+ export function isPersonaScoped(chatKey: string): boolean
5
+ /** 一次查询应覆盖的键:人设级 = [人设键, 会话键];会话级 = [会话键](不反向并入,避免串台) */
6
+ export function scopeKeysFor(chatKey: string): string[]
7
+ /** 记录是否落在查询范围内 */
8
+ export function recordInScope(recordChatKey: string, queryChatKey: string): boolean
9
+ /** 一个键的所有写法(去重) */
10
+ export function variantsOf(chatKey: string): string[]
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 会话作用域键:同一个会话可能有两种写法——会话级 `group_123` 和人设级 `group_123#p_abcd`。
3
+ * 检索时如果只认精确键,人设级查询就看不到会话级的老记录。
4
+ *
5
+ * 规则(从 QQ Agent 插件的真实 bug 里提炼):
6
+ * - 人设级查询 = 人设级记录 + 同会话的会话级记录
7
+ * - 会话级查询 = 只认会话级记录(不反向并入人设记录,避免把某人的记忆串给所有人)
8
+ *
9
+ * 纯函数,宿主无关。
10
+ */
11
+
12
+ const PERSONA_SUFFIX = /#p_[A-Za-z0-9]+$/i;
13
+
14
+ /** 去掉人设后缀,得到会话级键。 */
15
+ export function baseChatKey(chatKey) {
16
+ return String(chatKey || '').trim().replace(PERSONA_SUFFIX, '');
17
+ }
18
+
19
+ /** 这个键是不是人设级。 */
20
+ export function isPersonaScoped(chatKey) {
21
+ return PERSONA_SUFFIX.test(String(chatKey || '').trim());
22
+ }
23
+
24
+ /**
25
+ * 一次查询应该覆盖哪些键。
26
+ * @param {string} chatKey 当前会话键
27
+ * @returns {string[]} 由具体到宽泛;会话级查询只有一个
28
+ */
29
+ export function scopeKeysFor(chatKey) {
30
+ const raw = String(chatKey || '').trim();
31
+ if (!raw) return [];
32
+ const base = baseChatKey(raw);
33
+ if (!base || base === raw) return [raw];
34
+ return [raw, base];
35
+ }
36
+
37
+ /**
38
+ * 一条记录的会话键是否落在本次查询范围内。
39
+ * @param {string} recordChatKey 记录自己的键
40
+ * @param {string} queryChatKey 查询用的键
41
+ */
42
+ export function recordInScope(recordChatKey, queryChatKey) {
43
+ const record = String(recordChatKey || '').trim();
44
+ const query = String(queryChatKey || '').trim();
45
+ if (!query) return true; // 不限定会话 = 全局
46
+ if (!record) return false;
47
+ return scopeKeysFor(query).includes(record);
48
+ }
49
+
50
+ /** 供测试与迁移用:把一个键的两种写法都列出来。 */
51
+ export function variantsOf(chatKey) {
52
+ const raw = String(chatKey || '').trim();
53
+ const base = baseChatKey(raw);
54
+ if (!base) return [];
55
+ return [...new Set([base, raw])];
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whale-memory-core",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "Self-layer autobiographical memory core: then / later, append-only. Vault, evidence and consolidation live in the QQ Agent plugin.",
5
5
  "type": "module",
6
6
  "main": "./index.js",