whale-memory-core 0.8.0 → 0.8.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/demo.mjs +7 -2
- package/lib/evidence-policy.js +12 -3
- package/lib/self-experience.d.ts +11 -0
- package/package.json +46 -13
package/demo.mjs
CHANGED
|
@@ -26,8 +26,13 @@ const e = exp.addExperience(dir, {
|
|
|
26
26
|
console.log('\n[写] id=', e.id, '| 重要度=', e.weight)
|
|
27
27
|
|
|
28
28
|
// 2) 第二天她想起(相关话题触发);mark:true 表示这次取回也记一次“想起”
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// 查询要用能命中的短锚点;长问句会被“≥8 字要求 60% 命中”的门槛挡住(这是故意的)
|
|
30
|
+
const hits = exp.recall(dir, '烤肉', { limit: 1, mark: true })
|
|
31
|
+
if (!hits.length) {
|
|
32
|
+
console.log('\n[想起] 这次什么都没想起来(查询和记录没有足够重叠)')
|
|
33
|
+
} else {
|
|
34
|
+
console.log('\n[想起]\n' + exp.renderTwoPart(hits[0]))
|
|
35
|
+
}
|
|
31
36
|
|
|
32
37
|
// 3) 她改主意:只往 later 追加,不动"当时"
|
|
33
38
|
exp.reviseExperience(dir, { id: e.id, thought: '现在觉得那个人其实是在护着朋友', reason: '读到后面那段' })
|
package/lib/evidence-policy.js
CHANGED
|
@@ -52,11 +52,11 @@ export function currentFact(facts, { subject, slot = 'default', at = new Date().
|
|
|
52
52
|
return alive.length ? alive[alive.length - 1] : null
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// 主查询:有就给出值 +
|
|
55
|
+
// 主查询:有就给出值 + 证据链;没有就明说没有;同一时刻互相矛盾也明说说不清
|
|
56
56
|
export function query(facts, { subject, slot = 'default', at = new Date().toISOString() } = {}) {
|
|
57
57
|
const all = normalizeFacts(facts)
|
|
58
58
|
const atT = ts(at)
|
|
59
|
-
if (atT === null) return { status: 'unknown', reason: 'as-of 时间不合法' }
|
|
59
|
+
if (atT === null) return { status: 'unknown', reason: 'as-of 时间不合法', evidence: [] }
|
|
60
60
|
|
|
61
61
|
const pool = all.filter((f) => f.subject === subject && f.slot === slot && f.t <= atT)
|
|
62
62
|
if (!pool.length) {
|
|
@@ -70,7 +70,15 @@ export function query(facts, { subject, slot = 'default', at = new Date().toISOS
|
|
|
70
70
|
return { status: 'unknown', reason: '该时间点的记录都已被后续取代', evidence: pool }
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
// 同一时刻、值不同、又没有任何一条被明确取代:说不清,不按 id 顺序替她决定
|
|
74
|
+
const latestT = alive[alive.length - 1].t
|
|
75
|
+
const tied = alive.filter((f) => f.t === latestT)
|
|
76
|
+
const distinctValues = new Set(tied.map((f) => JSON.stringify(f.value)))
|
|
77
|
+
if (tied.length > 1 && distinctValues.size > 1) {
|
|
78
|
+
return { status: 'unknown', reason: '同一时间有多条互相矛盾的记录,说不清', evidence: tied }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const latest = tied[tied.length - 1]
|
|
74
82
|
const chain = []
|
|
75
83
|
let cur = latest
|
|
76
84
|
const seen = new Set()
|
|
@@ -80,6 +88,7 @@ export function query(facts, { subject, slot = 'default', at = new Date().toISOS
|
|
|
80
88
|
cur = cur.supersedes ? pool.find((f) => f.id === cur.supersedes) || null : null
|
|
81
89
|
}
|
|
82
90
|
chain.reverse()
|
|
91
|
+
for (const f of tied) if (!seen.has(f.id)) { chain.push(f); seen.add(f.id) }
|
|
83
92
|
|
|
84
93
|
return {
|
|
85
94
|
status: 'known',
|
package/lib/self-experience.d.ts
CHANGED
|
@@ -73,4 +73,15 @@ export function recall(dir: string, query: string, opts?: {
|
|
|
73
73
|
|
|
74
74
|
export function renderTwoPart(entry: Experience, opts?: { now?: Date; laterCount?: number }): string
|
|
75
75
|
|
|
76
|
+
export interface RecallContextItem {
|
|
77
|
+
id: string
|
|
78
|
+
day: string
|
|
79
|
+
text: string
|
|
80
|
+
thought: string
|
|
81
|
+
weight: Weight
|
|
82
|
+
raw: Experience
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function recallForContext(dir: string, query: string, opts?: { max?: number }): RecallContextItem[]
|
|
86
|
+
|
|
76
87
|
export const internals: { WEIGHTS: Set<Weight>; FILE: string }
|
package/package.json
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whale-memory-core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.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",
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"./self-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"./
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"./self-experience": {
|
|
14
|
+
"types": "./lib/self-experience.d.ts",
|
|
15
|
+
"default": "./lib/self-experience.js"
|
|
16
|
+
},
|
|
17
|
+
"./self-memory": {
|
|
18
|
+
"types": "./lib/self-memory.d.ts",
|
|
19
|
+
"default": "./lib/self-memory.js"
|
|
20
|
+
},
|
|
21
|
+
"./waking": {
|
|
22
|
+
"types": "./lib/waking.d.ts",
|
|
23
|
+
"default": "./lib/waking.js"
|
|
24
|
+
},
|
|
25
|
+
"./self-prompt": {
|
|
26
|
+
"types": "./lib/self-prompt.d.ts",
|
|
27
|
+
"default": "./lib/self-prompt.js"
|
|
28
|
+
},
|
|
29
|
+
"./self-settings": {
|
|
30
|
+
"types": "./lib/self-settings.d.ts",
|
|
31
|
+
"default": "./lib/self-settings.js"
|
|
32
|
+
},
|
|
33
|
+
"./recall-events": {
|
|
34
|
+
"types": "./lib/recall-events.d.ts",
|
|
35
|
+
"default": "./lib/recall-events.js"
|
|
36
|
+
},
|
|
37
|
+
"./later-events": {
|
|
38
|
+
"types": "./lib/later-events.d.ts",
|
|
39
|
+
"default": "./lib/later-events.js"
|
|
40
|
+
},
|
|
41
|
+
"./file-lock": {
|
|
42
|
+
"types": "./lib/file-lock.d.ts",
|
|
43
|
+
"default": "./lib/file-lock.js"
|
|
44
|
+
},
|
|
45
|
+
"./evidence-policy": {
|
|
46
|
+
"types": "./lib/evidence-policy.d.ts",
|
|
47
|
+
"default": "./lib/evidence-policy.js"
|
|
48
|
+
},
|
|
49
|
+
"./evidence-from-experience": {
|
|
50
|
+
"types": "./lib/evidence-from-experience.d.ts",
|
|
51
|
+
"default": "./lib/evidence-from-experience.js"
|
|
52
|
+
}
|
|
20
53
|
},
|
|
21
54
|
"files": [
|
|
22
55
|
"index.js",
|
|
@@ -45,4 +78,4 @@
|
|
|
45
78
|
"directory": "packages/core"
|
|
46
79
|
},
|
|
47
80
|
"sideEffects": false
|
|
48
|
-
}
|
|
81
|
+
}
|