cortico-world-memory 0.1.4 → 0.1.6
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/package.json +1 -1
- package/src/world.ts +23 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Cortico World 扩展:五层记忆(事实库/知识库/反思/人格/档案)+ 三级记忆底座 + Hybrid Recall 向量混合检索(移植自 E:/qq_bot 的记忆系统与 memory_server 向量 sidecar,qq_bot 源码零改动)。",
|
|
6
6
|
"license": "MIT",
|
package/src/world.ts
CHANGED
|
@@ -34,23 +34,35 @@ function isInboundUser(e: EventEnvelope): boolean {
|
|
|
34
34
|
/**
|
|
35
35
|
* 自动捕获的记忆域(scope):优先按「发送者 QQ 号」,做到私聊↔群聊按人统一——
|
|
36
36
|
* 同一个人无论是在私聊还是群聊发言,记忆都沉淀到同一个 `qq:<号>` 域,无缝衔接。
|
|
37
|
-
*
|
|
37
|
+
* 仅在事件确实来自 QQ 世界(e.source==='qqbot',qq-better 注入 meta.user=QQ号)时才用 qq: 前缀,
|
|
38
|
+
* 避免把其它世界的数字 user 误标成 qq:;QQ 没启动则无 qq 事件,自然退化为其它域(世界无关)。
|
|
39
|
+
* 非 QQ 来源退化为「来源:user」(若有 meta.user)→ 会话地址(senderKey)→ 来源(source)→ main。
|
|
38
40
|
*/
|
|
39
41
|
function scopeOfEvent(e: EventEnvelope): string {
|
|
40
42
|
const meta = (e.meta ?? {}) as Record<string, any>;
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
const src = typeof e.source === 'string' ? e.source : '';
|
|
44
|
+
const isQQ = src === 'qqbot';
|
|
45
|
+
|
|
46
|
+
// 1. QQ 来源:用发送者 QQ 号做按人统一域(私聊↔群聊无缝衔接)
|
|
47
|
+
if (isQQ) {
|
|
48
|
+
const u = meta.user;
|
|
49
|
+
if (typeof u === 'number' && Number.isFinite(u)) return `qq:${u}`;
|
|
50
|
+
if (typeof u === 'string' && /^\d{4,}$/.test(u.trim())) return `qq:${u.trim()}`;
|
|
51
|
+
const s = meta.sender;
|
|
52
|
+
if (typeof s === 'string') {
|
|
53
|
+
const m = s.match(/QQ[::]\s*(\d{4,})/);
|
|
54
|
+
if (m) return `qq:${m[1]}`;
|
|
55
|
+
}
|
|
50
56
|
}
|
|
57
|
+
|
|
58
|
+
// 2. 其它世界:若提供了 meta.user,按「来源:user」隔离(不同世界用户号避免撞车)
|
|
59
|
+
const u = meta.user;
|
|
60
|
+
if (typeof u === 'number' && Number.isFinite(u)) return `${src || 'user'}:${u}`;
|
|
61
|
+
if (typeof u === 'string' && u.trim()) return `${src || 'user'}:${u.trim()}`;
|
|
62
|
+
|
|
51
63
|
// 3. 退化:会话地址 → 来源 → main
|
|
52
64
|
if (typeof e.senderKey === 'string' && e.senderKey.trim()) return e.senderKey.trim();
|
|
53
|
-
if (
|
|
65
|
+
if (src) return src;
|
|
54
66
|
return 'main';
|
|
55
67
|
}
|
|
56
68
|
|