@psiclawops/hypermem 0.1.0 → 0.5.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.
- package/ARCHITECTURE.md +4 -3
- package/README.md +457 -174
- package/package.json +15 -5
- package/dist/background-indexer.d.ts +0 -117
- package/dist/background-indexer.d.ts.map +0 -1
- package/dist/background-indexer.js +0 -732
- package/dist/compaction-fence.d.ts +0 -89
- package/dist/compaction-fence.d.ts.map +0 -1
- package/dist/compaction-fence.js +0 -153
- package/dist/compositor.d.ts +0 -139
- package/dist/compositor.d.ts.map +0 -1
- package/dist/compositor.js +0 -1109
- package/dist/cross-agent.d.ts +0 -57
- package/dist/cross-agent.d.ts.map +0 -1
- package/dist/cross-agent.js +0 -254
- package/dist/db.d.ts +0 -131
- package/dist/db.d.ts.map +0 -1
- package/dist/db.js +0 -398
- package/dist/desired-state-store.d.ts +0 -100
- package/dist/desired-state-store.d.ts.map +0 -1
- package/dist/desired-state-store.js +0 -212
- package/dist/doc-chunk-store.d.ts +0 -115
- package/dist/doc-chunk-store.d.ts.map +0 -1
- package/dist/doc-chunk-store.js +0 -278
- package/dist/doc-chunker.d.ts +0 -99
- package/dist/doc-chunker.d.ts.map +0 -1
- package/dist/doc-chunker.js +0 -324
- package/dist/episode-store.d.ts +0 -48
- package/dist/episode-store.d.ts.map +0 -1
- package/dist/episode-store.js +0 -135
- package/dist/fact-store.d.ts +0 -57
- package/dist/fact-store.d.ts.map +0 -1
- package/dist/fact-store.js +0 -175
- package/dist/fleet-store.d.ts +0 -144
- package/dist/fleet-store.d.ts.map +0 -1
- package/dist/fleet-store.js +0 -276
- package/dist/hybrid-retrieval.d.ts +0 -60
- package/dist/hybrid-retrieval.d.ts.map +0 -1
- package/dist/hybrid-retrieval.js +0 -340
- package/dist/index.d.ts +0 -611
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1042
- package/dist/knowledge-graph.d.ts +0 -110
- package/dist/knowledge-graph.d.ts.map +0 -1
- package/dist/knowledge-graph.js +0 -305
- package/dist/knowledge-store.d.ts +0 -72
- package/dist/knowledge-store.d.ts.map +0 -1
- package/dist/knowledge-store.js +0 -241
- package/dist/library-schema.d.ts +0 -22
- package/dist/library-schema.d.ts.map +0 -1
- package/dist/library-schema.js +0 -717
- package/dist/message-store.d.ts +0 -76
- package/dist/message-store.d.ts.map +0 -1
- package/dist/message-store.js +0 -273
- package/dist/preference-store.d.ts +0 -54
- package/dist/preference-store.d.ts.map +0 -1
- package/dist/preference-store.js +0 -109
- package/dist/preservation-gate.d.ts +0 -82
- package/dist/preservation-gate.d.ts.map +0 -1
- package/dist/preservation-gate.js +0 -150
- package/dist/provider-translator.d.ts +0 -40
- package/dist/provider-translator.d.ts.map +0 -1
- package/dist/provider-translator.js +0 -349
- package/dist/rate-limiter.d.ts +0 -76
- package/dist/rate-limiter.d.ts.map +0 -1
- package/dist/rate-limiter.js +0 -179
- package/dist/redis.d.ts +0 -188
- package/dist/redis.d.ts.map +0 -1
- package/dist/redis.js +0 -534
- package/dist/schema.d.ts +0 -15
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -203
- package/dist/secret-scanner.d.ts +0 -51
- package/dist/secret-scanner.d.ts.map +0 -1
- package/dist/secret-scanner.js +0 -248
- package/dist/seed.d.ts +0 -108
- package/dist/seed.d.ts.map +0 -1
- package/dist/seed.js +0 -177
- package/dist/system-store.d.ts +0 -73
- package/dist/system-store.d.ts.map +0 -1
- package/dist/system-store.js +0 -182
- package/dist/topic-store.d.ts +0 -45
- package/dist/topic-store.d.ts.map +0 -1
- package/dist/topic-store.js +0 -136
- package/dist/types.d.ts +0 -329
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -9
- package/dist/vector-store.d.ts +0 -132
- package/dist/vector-store.d.ts.map +0 -1
- package/dist/vector-store.js +0 -498
- package/dist/work-store.d.ts +0 -112
- package/dist/work-store.d.ts.map +0 -1
- package/dist/work-store.js +0 -273
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HyperMem Compaction Fence
|
|
3
|
-
*
|
|
4
|
-
* Protects the recent conversation tail from being compacted.
|
|
5
|
-
*
|
|
6
|
-
* The fence is a per-conversation high-water mark (message ID) that divides
|
|
7
|
-
* the message timeline into two zones:
|
|
8
|
-
*
|
|
9
|
-
* - ABOVE the fence: messages the LLM can currently see (recent tail).
|
|
10
|
-
* These are off-limits to compaction.
|
|
11
|
-
* - BELOW the fence: older messages eligible for compaction/summarization.
|
|
12
|
-
*
|
|
13
|
-
* The compositor updates the fence every compose cycle by recording the
|
|
14
|
-
* oldest message ID that was included in the composed context. This means
|
|
15
|
-
* the fence automatically advances as conversations grow.
|
|
16
|
-
*
|
|
17
|
-
* Safety defaults:
|
|
18
|
-
* - No fence row = no compaction allowed (explicit opt-in)
|
|
19
|
-
* - Fence never moves backward (monotone progress)
|
|
20
|
-
* - Fence update is idempotent (same value = no-op)
|
|
21
|
-
*
|
|
22
|
-
* Inspired by the continuity model in openclaw-memory-libravdb, which
|
|
23
|
-
* formally proves that compaction must never touch the recent tail.
|
|
24
|
-
*/
|
|
25
|
-
import type { DatabaseSync } from 'node:sqlite';
|
|
26
|
-
export interface CompactionFence {
|
|
27
|
-
conversationId: number;
|
|
28
|
-
/** Message ID of the oldest message currently visible to the LLM */
|
|
29
|
-
fenceMessageId: number;
|
|
30
|
-
/** Timestamp of the last fence update */
|
|
31
|
-
updatedAt: string;
|
|
32
|
-
}
|
|
33
|
-
export interface CompactionEligibility {
|
|
34
|
-
conversationId: number;
|
|
35
|
-
/** Total messages below the fence (eligible for compaction) */
|
|
36
|
-
eligibleCount: number;
|
|
37
|
-
/** Message ID of the oldest eligible message */
|
|
38
|
-
oldestEligibleId: number | null;
|
|
39
|
-
/** Message ID of the newest eligible message (just below fence) */
|
|
40
|
-
newestEligibleId: number | null;
|
|
41
|
-
/** The fence itself */
|
|
42
|
-
fence: CompactionFence | null;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Add the compaction_fences table to an existing messages.db.
|
|
46
|
-
* Idempotent — safe to call on every startup.
|
|
47
|
-
*/
|
|
48
|
-
export declare function ensureCompactionFenceSchema(db: DatabaseSync): void;
|
|
49
|
-
/**
|
|
50
|
-
* Update the compaction fence for a conversation.
|
|
51
|
-
*
|
|
52
|
-
* Called by the compositor after assembling context, passing the ID of
|
|
53
|
-
* the oldest message that was included in the composed history.
|
|
54
|
-
*
|
|
55
|
-
* The fence only moves forward (monotone progress). If the new fence
|
|
56
|
-
* is lower than the existing one, the update is silently ignored.
|
|
57
|
-
* This prevents a short compose window from accidentally exposing
|
|
58
|
-
* already-compacted messages.
|
|
59
|
-
*/
|
|
60
|
-
export declare function updateCompactionFence(db: DatabaseSync, conversationId: number, oldestVisibleMessageId: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Get the current compaction fence for a conversation.
|
|
63
|
-
* Returns null if no fence has been set (meaning: no compaction allowed).
|
|
64
|
-
*/
|
|
65
|
-
export declare function getCompactionFence(db: DatabaseSync, conversationId: number): CompactionFence | null;
|
|
66
|
-
/**
|
|
67
|
-
* Query compaction eligibility for a conversation.
|
|
68
|
-
*
|
|
69
|
-
* Returns the count and range of messages that are below the fence
|
|
70
|
-
* and therefore eligible for compaction. If no fence exists, returns
|
|
71
|
-
* zero eligible (safe default: no fence = no compaction).
|
|
72
|
-
*
|
|
73
|
-
* Excludes messages that are already covered by a summary
|
|
74
|
-
* (via the summary_messages junction table).
|
|
75
|
-
*/
|
|
76
|
-
export declare function getCompactionEligibility(db: DatabaseSync, conversationId: number): CompactionEligibility;
|
|
77
|
-
/**
|
|
78
|
-
* Get messages eligible for compaction (below the fence, not yet summarized).
|
|
79
|
-
*
|
|
80
|
-
* Returns messages in chronological order, ready for clustering.
|
|
81
|
-
* Respects the fence boundary and excludes already-summarized messages.
|
|
82
|
-
*/
|
|
83
|
-
export declare function getCompactableMessages(db: DatabaseSync, conversationId: number, limit?: number): Array<{
|
|
84
|
-
id: number;
|
|
85
|
-
role: string;
|
|
86
|
-
textContent: string;
|
|
87
|
-
createdAt: string;
|
|
88
|
-
}>;
|
|
89
|
-
//# sourceMappingURL=compaction-fence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-fence.d.ts","sourceRoot":"","sources":["../src/compaction-fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,oEAAoE;IACpE,cAAc,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,uBAAuB;IACvB,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;CAC/B;AAID;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAQlE;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,YAAY,EAChB,cAAc,EAAE,MAAM,EACtB,sBAAsB,EAAE,MAAM,GAC7B,IAAI,CAqBN;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,YAAY,EAChB,cAAc,EAAE,MAAM,GACrB,eAAe,GAAG,IAAI,CAYxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,YAAY,EAChB,cAAc,EAAE,MAAM,GACrB,qBAAqB,CAwCvB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,YAAY,EAChB,cAAc,EAAE,MAAM,EACtB,KAAK,GAAE,MAAY,GAClB,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CA8B7E"}
|
package/dist/compaction-fence.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HyperMem Compaction Fence
|
|
3
|
-
*
|
|
4
|
-
* Protects the recent conversation tail from being compacted.
|
|
5
|
-
*
|
|
6
|
-
* The fence is a per-conversation high-water mark (message ID) that divides
|
|
7
|
-
* the message timeline into two zones:
|
|
8
|
-
*
|
|
9
|
-
* - ABOVE the fence: messages the LLM can currently see (recent tail).
|
|
10
|
-
* These are off-limits to compaction.
|
|
11
|
-
* - BELOW the fence: older messages eligible for compaction/summarization.
|
|
12
|
-
*
|
|
13
|
-
* The compositor updates the fence every compose cycle by recording the
|
|
14
|
-
* oldest message ID that was included in the composed context. This means
|
|
15
|
-
* the fence automatically advances as conversations grow.
|
|
16
|
-
*
|
|
17
|
-
* Safety defaults:
|
|
18
|
-
* - No fence row = no compaction allowed (explicit opt-in)
|
|
19
|
-
* - Fence never moves backward (monotone progress)
|
|
20
|
-
* - Fence update is idempotent (same value = no-op)
|
|
21
|
-
*
|
|
22
|
-
* Inspired by the continuity model in openclaw-memory-libravdb, which
|
|
23
|
-
* formally proves that compaction must never touch the recent tail.
|
|
24
|
-
*/
|
|
25
|
-
// ─── Schema ─────────────────────────────────────────────────────
|
|
26
|
-
/**
|
|
27
|
-
* Add the compaction_fences table to an existing messages.db.
|
|
28
|
-
* Idempotent — safe to call on every startup.
|
|
29
|
-
*/
|
|
30
|
-
export function ensureCompactionFenceSchema(db) {
|
|
31
|
-
db.exec(`
|
|
32
|
-
CREATE TABLE IF NOT EXISTS compaction_fences (
|
|
33
|
-
conversation_id INTEGER PRIMARY KEY REFERENCES conversations(id),
|
|
34
|
-
fence_message_id INTEGER NOT NULL,
|
|
35
|
-
updated_at TEXT NOT NULL
|
|
36
|
-
)
|
|
37
|
-
`);
|
|
38
|
-
}
|
|
39
|
-
// ─── Fence Operations ───────────────────────────────────────────
|
|
40
|
-
/**
|
|
41
|
-
* Update the compaction fence for a conversation.
|
|
42
|
-
*
|
|
43
|
-
* Called by the compositor after assembling context, passing the ID of
|
|
44
|
-
* the oldest message that was included in the composed history.
|
|
45
|
-
*
|
|
46
|
-
* The fence only moves forward (monotone progress). If the new fence
|
|
47
|
-
* is lower than the existing one, the update is silently ignored.
|
|
48
|
-
* This prevents a short compose window from accidentally exposing
|
|
49
|
-
* already-compacted messages.
|
|
50
|
-
*/
|
|
51
|
-
export function updateCompactionFence(db, conversationId, oldestVisibleMessageId) {
|
|
52
|
-
const now = new Date().toISOString();
|
|
53
|
-
const existing = db.prepare('SELECT fence_message_id FROM compaction_fences WHERE conversation_id = ?').get(conversationId);
|
|
54
|
-
if (!existing) {
|
|
55
|
-
// First fence for this conversation
|
|
56
|
-
db.prepare('INSERT INTO compaction_fences (conversation_id, fence_message_id, updated_at) VALUES (?, ?, ?)').run(conversationId, oldestVisibleMessageId, now);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
// Monotone progress: fence only moves forward
|
|
60
|
-
if (oldestVisibleMessageId > existing.fence_message_id) {
|
|
61
|
-
db.prepare('UPDATE compaction_fences SET fence_message_id = ?, updated_at = ? WHERE conversation_id = ?').run(oldestVisibleMessageId, now, conversationId);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get the current compaction fence for a conversation.
|
|
66
|
-
* Returns null if no fence has been set (meaning: no compaction allowed).
|
|
67
|
-
*/
|
|
68
|
-
export function getCompactionFence(db, conversationId) {
|
|
69
|
-
const row = db.prepare('SELECT conversation_id, fence_message_id, updated_at FROM compaction_fences WHERE conversation_id = ?').get(conversationId);
|
|
70
|
-
if (!row)
|
|
71
|
-
return null;
|
|
72
|
-
return {
|
|
73
|
-
conversationId: row.conversation_id,
|
|
74
|
-
fenceMessageId: row.fence_message_id,
|
|
75
|
-
updatedAt: row.updated_at,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Query compaction eligibility for a conversation.
|
|
80
|
-
*
|
|
81
|
-
* Returns the count and range of messages that are below the fence
|
|
82
|
-
* and therefore eligible for compaction. If no fence exists, returns
|
|
83
|
-
* zero eligible (safe default: no fence = no compaction).
|
|
84
|
-
*
|
|
85
|
-
* Excludes messages that are already covered by a summary
|
|
86
|
-
* (via the summary_messages junction table).
|
|
87
|
-
*/
|
|
88
|
-
export function getCompactionEligibility(db, conversationId) {
|
|
89
|
-
const fence = getCompactionFence(db, conversationId);
|
|
90
|
-
if (!fence) {
|
|
91
|
-
return {
|
|
92
|
-
conversationId,
|
|
93
|
-
eligibleCount: 0,
|
|
94
|
-
oldestEligibleId: null,
|
|
95
|
-
newestEligibleId: null,
|
|
96
|
-
fence: null,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// Messages below the fence that haven't been summarized yet
|
|
100
|
-
const stats = db.prepare(`
|
|
101
|
-
SELECT
|
|
102
|
-
COUNT(*) AS cnt,
|
|
103
|
-
MIN(m.id) AS oldest_id,
|
|
104
|
-
MAX(m.id) AS newest_id
|
|
105
|
-
FROM messages m
|
|
106
|
-
WHERE m.conversation_id = ?
|
|
107
|
-
AND m.id < ?
|
|
108
|
-
AND m.id NOT IN (
|
|
109
|
-
SELECT sm.message_id FROM summary_messages sm
|
|
110
|
-
JOIN summaries s ON sm.summary_id = s.id
|
|
111
|
-
WHERE s.conversation_id = ?
|
|
112
|
-
)
|
|
113
|
-
`).get(conversationId, fence.fenceMessageId, conversationId);
|
|
114
|
-
return {
|
|
115
|
-
conversationId,
|
|
116
|
-
eligibleCount: stats.cnt,
|
|
117
|
-
oldestEligibleId: stats.oldest_id,
|
|
118
|
-
newestEligibleId: stats.newest_id,
|
|
119
|
-
fence,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get messages eligible for compaction (below the fence, not yet summarized).
|
|
124
|
-
*
|
|
125
|
-
* Returns messages in chronological order, ready for clustering.
|
|
126
|
-
* Respects the fence boundary and excludes already-summarized messages.
|
|
127
|
-
*/
|
|
128
|
-
export function getCompactableMessages(db, conversationId, limit = 100) {
|
|
129
|
-
const fence = getCompactionFence(db, conversationId);
|
|
130
|
-
if (!fence)
|
|
131
|
-
return [];
|
|
132
|
-
const rows = db.prepare(`
|
|
133
|
-
SELECT m.id, m.role, m.text_content, m.created_at
|
|
134
|
-
FROM messages m
|
|
135
|
-
WHERE m.conversation_id = ?
|
|
136
|
-
AND m.id < ?
|
|
137
|
-
AND m.text_content IS NOT NULL
|
|
138
|
-
AND m.id NOT IN (
|
|
139
|
-
SELECT sm.message_id FROM summary_messages sm
|
|
140
|
-
JOIN summaries s ON sm.summary_id = s.id
|
|
141
|
-
WHERE s.conversation_id = ?
|
|
142
|
-
)
|
|
143
|
-
ORDER BY m.id ASC
|
|
144
|
-
LIMIT ?
|
|
145
|
-
`).all(conversationId, fence.fenceMessageId, conversationId, limit);
|
|
146
|
-
return rows.map(r => ({
|
|
147
|
-
id: r.id,
|
|
148
|
-
role: r.role,
|
|
149
|
-
textContent: r.text_content,
|
|
150
|
-
createdAt: r.created_at,
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=compaction-fence.js.map
|
package/dist/compositor.d.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HyperMem Compositor
|
|
3
|
-
*
|
|
4
|
-
* Assembles context for LLM calls by orchestrating all four memory layers:
|
|
5
|
-
* L1 Redis — hot session working memory (system, identity, recent msgs)
|
|
6
|
-
* L2 Messages — conversation history from messages.db
|
|
7
|
-
* L3 Vectors — semantic search across all indexed content
|
|
8
|
-
* L4 Library — structured knowledge (facts, preferences, knowledge, episodes)
|
|
9
|
-
*
|
|
10
|
-
* Token-budgeted: never exceeds the budget, prioritizes by configured order.
|
|
11
|
-
* Provider-neutral internally, translates at the output boundary.
|
|
12
|
-
*/
|
|
13
|
-
import type { DatabaseSync } from 'node:sqlite';
|
|
14
|
-
import type { ComposeRequest, ComposeResult, CompositorConfig } from './types.js';
|
|
15
|
-
import { RedisLayer } from './redis.js';
|
|
16
|
-
import { VectorStore } from './vector-store.js';
|
|
17
|
-
/**
|
|
18
|
-
* A trigger definition maps a collection to the conversation signals that
|
|
19
|
-
* indicate it should be queried. When any keyword matches the user's latest
|
|
20
|
-
* message, the compositor fetches relevant chunks from that collection.
|
|
21
|
-
*
|
|
22
|
-
* Centralizing trigger logic here (not in workspace stubs) means:
|
|
23
|
-
* - One update propagates to all agents
|
|
24
|
-
* - Stubs become documentation, not code
|
|
25
|
-
* - Trigger logic can be tested independently
|
|
26
|
-
*/
|
|
27
|
-
export interface CollectionTrigger {
|
|
28
|
-
/** Collection path: governance/policy, identity/job, etc. */
|
|
29
|
-
collection: string;
|
|
30
|
-
/** Keywords that trigger this collection (case-insensitive) */
|
|
31
|
-
keywords: string[];
|
|
32
|
-
/** Max tokens to inject from this collection */
|
|
33
|
-
maxTokens?: number;
|
|
34
|
-
/** Max chunks to retrieve */
|
|
35
|
-
maxChunks?: number;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Default trigger registry for standard ACA collections.
|
|
39
|
-
* Covers the core ACA offload use case from Anvil's spec.
|
|
40
|
-
*/
|
|
41
|
-
export declare const DEFAULT_TRIGGERS: CollectionTrigger[];
|
|
42
|
-
export interface CompositorDeps {
|
|
43
|
-
redis: RedisLayer;
|
|
44
|
-
vectorStore?: VectorStore | null;
|
|
45
|
-
libraryDb?: DatabaseSync | null;
|
|
46
|
-
/** Custom trigger registry; defaults to DEFAULT_TRIGGERS if not provided */
|
|
47
|
-
triggerRegistry?: CollectionTrigger[];
|
|
48
|
-
}
|
|
49
|
-
export declare class Compositor {
|
|
50
|
-
private readonly config;
|
|
51
|
-
private readonly redis;
|
|
52
|
-
private vectorStore;
|
|
53
|
-
private readonly libraryDb;
|
|
54
|
-
private readonly triggerRegistry;
|
|
55
|
-
constructor(deps: CompositorDeps | RedisLayer, config?: Partial<CompositorConfig>);
|
|
56
|
-
/**
|
|
57
|
-
* Set or replace the vector store after construction.
|
|
58
|
-
* Called by HyperMem.create() once sqlite-vec is confirmed available.
|
|
59
|
-
*/
|
|
60
|
-
setVectorStore(vs: VectorStore): void;
|
|
61
|
-
/**
|
|
62
|
-
* Compose a complete message array for sending to an LLM.
|
|
63
|
-
*
|
|
64
|
-
* Orchestrates all four memory layers:
|
|
65
|
-
* 1. System prompt + identity (never truncated)
|
|
66
|
-
* 2. Conversation history (L1 Redis → L2 messages.db)
|
|
67
|
-
* 3. Active facts from library (L4)
|
|
68
|
-
* 4. Knowledge entries relevant to conversation (L4)
|
|
69
|
-
* 5. User preferences (L4)
|
|
70
|
-
* 6. Semantic recall via vector search (L3)
|
|
71
|
-
* 7. Cross-session context (L2)
|
|
72
|
-
*
|
|
73
|
-
* Each slot respects the remaining token budget.
|
|
74
|
-
*/
|
|
75
|
-
compose(request: ComposeRequest, db: DatabaseSync, libraryDb?: DatabaseSync): Promise<ComposeResult>;
|
|
76
|
-
/**
|
|
77
|
-
* Warm a session from SQLite into Redis.
|
|
78
|
-
* Called on session start or Redis cache miss.
|
|
79
|
-
*/
|
|
80
|
-
warmSession(agentId: string, sessionKey: string, db: DatabaseSync, opts?: {
|
|
81
|
-
systemPrompt?: string;
|
|
82
|
-
identity?: string;
|
|
83
|
-
libraryDb?: DatabaseSync;
|
|
84
|
-
}): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Get slot content: try Redis first, fall back to SQLite.
|
|
87
|
-
*/
|
|
88
|
-
private getSlotContent;
|
|
89
|
-
/**
|
|
90
|
-
* Get conversation history: try Redis first, fall back to SQLite.
|
|
91
|
-
*/
|
|
92
|
-
private getHistory;
|
|
93
|
-
/**
|
|
94
|
-
* Build facts content from library DB.
|
|
95
|
-
*/
|
|
96
|
-
private buildFactsFromDb;
|
|
97
|
-
/**
|
|
98
|
-
* Build knowledge content from library DB.
|
|
99
|
-
* Prioritizes high-confidence, non-superseded entries.
|
|
100
|
-
*/
|
|
101
|
-
private buildKnowledgeFromDb;
|
|
102
|
-
/**
|
|
103
|
-
* Build preferences content from library DB.
|
|
104
|
-
* Shows user/operator preferences relevant to this agent.
|
|
105
|
-
*/
|
|
106
|
-
private buildPreferencesFromDb;
|
|
107
|
-
/**
|
|
108
|
-
* Build semantic recall content using hybrid FTS5+KNN retrieval.
|
|
109
|
-
*
|
|
110
|
-
* Uses Reciprocal Rank Fusion to merge keyword and vector results.
|
|
111
|
-
* Gracefully degrades: FTS5-only when no vector store, KNN-only
|
|
112
|
-
* when FTS query is empty (all stop words), both when available.
|
|
113
|
-
*/
|
|
114
|
-
private buildSemanticRecall;
|
|
115
|
-
/**
|
|
116
|
-
* Format a hybrid search result for injection into context.
|
|
117
|
-
* Shows retrieval source(s) and relevance score.
|
|
118
|
-
*/
|
|
119
|
-
private formatHybridResult;
|
|
120
|
-
/**
|
|
121
|
-
* Format a vector-only search result (legacy fallback).
|
|
122
|
-
*/
|
|
123
|
-
private formatVectorResult;
|
|
124
|
-
/**
|
|
125
|
-
* Build cross-session context by finding recent activity
|
|
126
|
-
* in other sessions for this agent.
|
|
127
|
-
*/
|
|
128
|
-
private buildCrossSessionContext;
|
|
129
|
-
/**
|
|
130
|
-
* Extract the last user message text from the composed messages.
|
|
131
|
-
*/
|
|
132
|
-
private getLastUserMessage;
|
|
133
|
-
/**
|
|
134
|
-
* Truncate text to approximately fit within a token budget.
|
|
135
|
-
* Truncates at line boundaries when possible.
|
|
136
|
-
*/
|
|
137
|
-
private truncateToTokens;
|
|
138
|
-
}
|
|
139
|
-
//# sourceMappingURL=compositor.d.ts.map
|
package/dist/compositor.d.ts.map
DELETED
|
@@ -1 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