@alfe.ai/openclaw-memory-cloud 0.0.1
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/.turbo/turbo-build.log +4 -0
- package/dist/auto-capture.d.ts +34 -0
- package/dist/auto-capture.d.ts.map +1 -0
- package/dist/auto-capture.js +87 -0
- package/dist/auto-capture.js.map +1 -0
- package/dist/auto-recall.d.ts +23 -0
- package/dist/auto-recall.d.ts.map +1 -0
- package/dist/auto-recall.js +63 -0
- package/dist/auto-recall.js.map +1 -0
- package/dist/formatter.d.ts +7 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +27 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-client.d.ts +50 -0
- package/dist/memory-client.d.ts.map +1 -0
- package/dist/memory-client.js +108 -0
- package/dist/memory-client.js.map +1 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/openclaw.plugin.json +50 -0
- package/package.json +14 -0
- package/src/auto-capture.ts +96 -0
- package/src/auto-recall.ts +67 -0
- package/src/formatter.ts +30 -0
- package/src/index.ts +286 -0
- package/src/memory-client.ts +132 -0
- package/src/types.ts +47 -0
- package/sst-env.d.ts +10 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MemoryClient } from "./memory-client.js";
|
|
2
|
+
import type { MemoryCloudConfig, SessionMetadata } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Auto-capture manages the idle debounce timer and flushes
|
|
5
|
+
* accumulated messages to the memory service.
|
|
6
|
+
*
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. on_message_received: track message, reset timer
|
|
9
|
+
* 2. Timer fires (60s idle): flush batch to /memory/ingest
|
|
10
|
+
* 3. agent_end: final flush of remaining messages
|
|
11
|
+
*/
|
|
12
|
+
export declare class AutoCapture {
|
|
13
|
+
private readonly client;
|
|
14
|
+
private readonly config;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private static readonly MAX_QUEUE_SIZE;
|
|
17
|
+
private pendingMessages;
|
|
18
|
+
private messageIndex;
|
|
19
|
+
private idleTimer;
|
|
20
|
+
private sessionKey;
|
|
21
|
+
private metadata;
|
|
22
|
+
constructor(client: MemoryClient, config: MemoryCloudConfig, logger: {
|
|
23
|
+
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
24
|
+
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
25
|
+
});
|
|
26
|
+
setSession(sessionKey: string, metadata?: SessionMetadata): void;
|
|
27
|
+
trackMessage(role: string, content: string): void;
|
|
28
|
+
flush(): Promise<void>;
|
|
29
|
+
onAgentEnd(): Promise<void>;
|
|
30
|
+
destroy(): void;
|
|
31
|
+
private resetIdleTimer;
|
|
32
|
+
private clearIdleTimer;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=auto-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-capture.d.ts","sourceRoot":"","sources":["../src/auto-capture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpF;;;;;;;;GAQG;AACH,qBAAa,WAAW;IASpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAO;IAC7C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,QAAQ,CAAuB;gBAGpB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;KAAE;IAGtJ,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI;IAKhE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAsB3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBtB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,OAAO,IAAI,IAAI;IAIf,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-capture manages the idle debounce timer and flushes
|
|
3
|
+
* accumulated messages to the memory service.
|
|
4
|
+
*
|
|
5
|
+
* Flow:
|
|
6
|
+
* 1. on_message_received: track message, reset timer
|
|
7
|
+
* 2. Timer fires (60s idle): flush batch to /memory/ingest
|
|
8
|
+
* 3. agent_end: final flush of remaining messages
|
|
9
|
+
*/
|
|
10
|
+
export class AutoCapture {
|
|
11
|
+
client;
|
|
12
|
+
config;
|
|
13
|
+
logger;
|
|
14
|
+
static MAX_QUEUE_SIZE = 500;
|
|
15
|
+
pendingMessages = [];
|
|
16
|
+
messageIndex = 0;
|
|
17
|
+
idleTimer = null;
|
|
18
|
+
sessionKey = null;
|
|
19
|
+
metadata = {};
|
|
20
|
+
constructor(client, config, logger) {
|
|
21
|
+
this.client = client;
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
}
|
|
25
|
+
setSession(sessionKey, metadata) {
|
|
26
|
+
this.sessionKey = sessionKey;
|
|
27
|
+
if (metadata)
|
|
28
|
+
this.metadata = metadata;
|
|
29
|
+
}
|
|
30
|
+
trackMessage(role, content) {
|
|
31
|
+
if (!this.config.autoCapture)
|
|
32
|
+
return;
|
|
33
|
+
if (content.length > this.config.captureMaxChars) {
|
|
34
|
+
content = content.slice(0, this.config.captureMaxChars);
|
|
35
|
+
}
|
|
36
|
+
// Enforce max queue size — drop oldest if exceeded
|
|
37
|
+
if (this.pendingMessages.length >= AutoCapture.MAX_QUEUE_SIZE) {
|
|
38
|
+
this.logger.warn("Memory queue full — dropping oldest message", { queueSize: this.pendingMessages.length });
|
|
39
|
+
this.pendingMessages.shift();
|
|
40
|
+
}
|
|
41
|
+
this.pendingMessages.push({
|
|
42
|
+
role,
|
|
43
|
+
content,
|
|
44
|
+
index: this.messageIndex++,
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
});
|
|
47
|
+
this.resetIdleTimer();
|
|
48
|
+
}
|
|
49
|
+
async flush() {
|
|
50
|
+
if (this.pendingMessages.length === 0 || !this.sessionKey)
|
|
51
|
+
return;
|
|
52
|
+
const batch = [...this.pendingMessages];
|
|
53
|
+
this.pendingMessages = [];
|
|
54
|
+
this.logger.debug("Flushing memory batch", {
|
|
55
|
+
sessionKey: this.sessionKey,
|
|
56
|
+
messageCount: batch.length,
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
await this.client.ingest(this.sessionKey, batch, this.metadata);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
this.logger.warn("Failed to flush memories", { error: String(err) });
|
|
63
|
+
// Re-add failed messages for next flush attempt
|
|
64
|
+
this.pendingMessages.unshift(...batch);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async onAgentEnd() {
|
|
68
|
+
this.clearIdleTimer();
|
|
69
|
+
await this.flush();
|
|
70
|
+
}
|
|
71
|
+
destroy() {
|
|
72
|
+
this.clearIdleTimer();
|
|
73
|
+
}
|
|
74
|
+
resetIdleTimer() {
|
|
75
|
+
this.clearIdleTimer();
|
|
76
|
+
this.idleTimer = setTimeout(() => {
|
|
77
|
+
void this.flush();
|
|
78
|
+
}, this.config.idleFlushSeconds * 1000);
|
|
79
|
+
}
|
|
80
|
+
clearIdleTimer() {
|
|
81
|
+
if (this.idleTimer) {
|
|
82
|
+
clearTimeout(this.idleTimer);
|
|
83
|
+
this.idleTimer = null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=auto-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-capture.js","sourceRoot":"","sources":["../src/auto-capture.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IASH;IACA;IACA;IAVX,MAAM,CAAU,cAAc,GAAG,GAAG,CAAC;IACrC,eAAe,GAAoB,EAAE,CAAC;IACtC,YAAY,GAAG,CAAC,CAAC;IACjB,SAAS,GAAyC,IAAI,CAAC;IACvD,UAAU,GAAkB,IAAI,CAAC;IACjC,QAAQ,GAAoB,EAAE,CAAC;IAEvC,YACmB,MAAoB,EACpB,MAAyB,EACzB,MAAmI;QAFnI,WAAM,GAAN,MAAM,CAAc;QACpB,WAAM,GAAN,MAAM,CAAmB;QACzB,WAAM,GAAN,MAAM,CAA6H;IACnJ,CAAC;IAEJ,UAAU,CAAC,UAAkB,EAAE,QAA0B;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACzC,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,OAAe;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW;YAAE,OAAO;QACrC,I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AAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACrE,gDAAgD;YAChD,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAEO,cAAc;QACpB,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC/B,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MemoryClient } from "./memory-client.js";
|
|
2
|
+
import type { MemoryCloudConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Auto-recall loads tiered memory context at session start
|
|
5
|
+
* and formats it for injection into the agent's prompt.
|
|
6
|
+
*
|
|
7
|
+
* Called from the before_agent_start hook.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AutoRecall {
|
|
10
|
+
private readonly client;
|
|
11
|
+
private readonly config;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(client: MemoryClient, config: MemoryCloudConfig, logger: {
|
|
14
|
+
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
15
|
+
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Load memory context and return formatted XML for prompt injection.
|
|
19
|
+
* Returns prependContext string for the before_agent_start hook result.
|
|
20
|
+
*/
|
|
21
|
+
loadForPrompt(userMessage: string): Promise<string | undefined>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=auto-recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-recall.d.ts","sourceRoot":"","sources":["../src/auto-recall.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;KAAE;IAGtJ;;;OAGG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CA8BtE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-recall loads tiered memory context at session start
|
|
3
|
+
* and formats it for injection into the agent's prompt.
|
|
4
|
+
*
|
|
5
|
+
* Called from the before_agent_start hook.
|
|
6
|
+
*/
|
|
7
|
+
export class AutoRecall {
|
|
8
|
+
client;
|
|
9
|
+
config;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(client, config, logger) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Load memory context and return formatted XML for prompt injection.
|
|
18
|
+
* Returns prependContext string for the before_agent_start hook result.
|
|
19
|
+
*/
|
|
20
|
+
async loadForPrompt(userMessage) {
|
|
21
|
+
if (!this.config.autoRecall)
|
|
22
|
+
return undefined;
|
|
23
|
+
try {
|
|
24
|
+
// Detect topic from user message (first significant word)
|
|
25
|
+
const topicHint = extractTopicHint(userMessage);
|
|
26
|
+
// Load L1 (facts) + L2 (topic context) in one call
|
|
27
|
+
const tier = topicHint ? 2 : 1;
|
|
28
|
+
const context = await this.client.loadContext(tier, topicHint);
|
|
29
|
+
if (!context.formatted || context.formatted.length === 0) {
|
|
30
|
+
this.logger.debug("No relevant memories found for prompt");
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
this.logger.debug("Loaded memory context for prompt", {
|
|
34
|
+
tier,
|
|
35
|
+
topicHint,
|
|
36
|
+
factCount: context.facts.length,
|
|
37
|
+
memoryCount: context.memories.length,
|
|
38
|
+
tokenEstimate: context.tokenEstimate,
|
|
39
|
+
});
|
|
40
|
+
return context.formatted;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
this.logger.warn("Failed to load memory context", { error: String(err) });
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Simple topic hint extraction from user message.
|
|
50
|
+
* Returns the first capitalized word or proper noun as a potential topic.
|
|
51
|
+
*/
|
|
52
|
+
function extractTopicHint(message) {
|
|
53
|
+
// Look for proper nouns (capitalized words not at sentence start)
|
|
54
|
+
const words = message.split(/\s+/);
|
|
55
|
+
for (let i = 1; i < words.length; i++) {
|
|
56
|
+
const word = words[i];
|
|
57
|
+
if (word && word.length > 2 && /^[A-Z]/.test(word) && !/^(The|And|But|For|With|This|That|What|How|Why|When|Where)$/.test(word)) {
|
|
58
|
+
return word.toLowerCase();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=auto-recall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-recall.js","sourceRoot":"","sources":["../src/auto-recall.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IAEF;IACA;IACA;IAHnB,YACmB,MAAoB,EACpB,MAAyB,EACzB,MAAmI;QAFnI,WAAM,GAAN,MAAM,CAAc;QACpB,WAAM,GAAN,MAAM,CAAmB;QACzB,WAAM,GAAN,MAAM,CAA6H;IACnJ,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO,SAAS,CAAC;QAE9C,IAAI,CAAC;YACH,0DAA0D;YAC1D,MAAM,SAAS,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAEhD,mDAAmD;YACnD,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE/D,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBAC3D,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE;gBACpD,IAAI;gBACJ,SAAS;gBACT,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;gBAC/B,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBACpC,aAAa,EAAE,OAAO,CAAC,aAAa;aACrC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC,SAAS,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1E,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,kEAAkE;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,4DAA4D,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/H,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MemorySearchResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Format memory search results into an XML block for agent context injection.
|
|
4
|
+
* KG facts appear first (precise), then vector results (supporting context).
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatSearchResults(results: MemorySearchResult): string;
|
|
7
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAuBvE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format memory search results into an XML block for agent context injection.
|
|
3
|
+
* KG facts appear first (precise), then vector results (supporting context).
|
|
4
|
+
*/
|
|
5
|
+
export function formatSearchResults(results) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (results.facts.length > 0) {
|
|
8
|
+
parts.push("Known facts:");
|
|
9
|
+
for (const fact of results.facts) {
|
|
10
|
+
const since = typeof fact.since === "string" ? fact.since.slice(0, 10) : "unknown";
|
|
11
|
+
parts.push(`- ${fact.subject} ${fact.predicate} ${fact.object} (since ${since}, confidence: ${String(fact.confidence)})`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (results.memories.length > 0) {
|
|
15
|
+
if (parts.length > 0)
|
|
16
|
+
parts.push("");
|
|
17
|
+
parts.push("Related conversations:");
|
|
18
|
+
for (const mem of results.memories) {
|
|
19
|
+
const truncated = mem.text.length > 200 ? `${mem.text.slice(0, 200)}...` : mem.text;
|
|
20
|
+
parts.push(`- [${mem.topic}/${mem.subtopic}] ${truncated}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (parts.length === 0)
|
|
24
|
+
return "";
|
|
25
|
+
return `<relevant-memories>\n${parts.join("\n")}\n</relevant-memories>`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA2B;I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OAAO,EAAE,CAAC;IAElC,OAAO,wBAAwB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC;AAC1E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory-cloud — OpenClaw memory extension
|
|
3
|
+
*
|
|
4
|
+
* Replaces the builtin LanceDB memory extension with cloud-backed storage:
|
|
5
|
+
* - Turbopuffer for vector storage (via services/memory Lambda proxy)
|
|
6
|
+
* - DynamoDB for knowledge graph
|
|
7
|
+
* - Haiku for classification + entity extraction
|
|
8
|
+
*
|
|
9
|
+
* Registers:
|
|
10
|
+
* - Memory tools: memory_recall, memory_store, memory_forget, memory_navigate, memory_graph, memory_stats
|
|
11
|
+
* - Lifecycle hooks: before_agent_start (auto-recall), agent_end (auto-capture), message_received (idle debounce)
|
|
12
|
+
* - Memory runtime: replaces builtin SQLite backend with cloud backend
|
|
13
|
+
*/
|
|
14
|
+
interface PluginApi {
|
|
15
|
+
pluginConfig?: Record<string, unknown>;
|
|
16
|
+
config: Record<string, unknown>;
|
|
17
|
+
logger: {
|
|
18
|
+
info: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
19
|
+
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
20
|
+
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
21
|
+
error: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
22
|
+
};
|
|
23
|
+
registerTool: (factory: (ctx: ToolContext) => Tool, opts?: {
|
|
24
|
+
names?: string[];
|
|
25
|
+
}) => void;
|
|
26
|
+
registerHook: (events: string | string[], handler: (...args: unknown[]) => unknown, opts?: {
|
|
27
|
+
name?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
}) => void;
|
|
30
|
+
on: (hookName: string, handler: (...args: unknown[]) => unknown, opts?: {
|
|
31
|
+
priority?: number;
|
|
32
|
+
}) => void;
|
|
33
|
+
registerMemoryPromptSection: (builder: (params: {
|
|
34
|
+
availableTools: Set<string>;
|
|
35
|
+
}) => string[]) => void;
|
|
36
|
+
registerMemoryRuntime: (runtime: unknown) => void;
|
|
37
|
+
}
|
|
38
|
+
interface ToolContext {
|
|
39
|
+
agentId?: string;
|
|
40
|
+
sessionKey?: string;
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
messageChannel?: string;
|
|
43
|
+
}
|
|
44
|
+
interface Tool {
|
|
45
|
+
name: string;
|
|
46
|
+
label: string;
|
|
47
|
+
description: string;
|
|
48
|
+
parameters: Record<string, unknown>;
|
|
49
|
+
execute: (toolCallId: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
50
|
+
}
|
|
51
|
+
declare const _default: {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
version: string;
|
|
56
|
+
kind: "memory";
|
|
57
|
+
register(api: PluginApi): void;
|
|
58
|
+
};
|
|
59
|
+
export default _default;
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,UAAU,SAAS;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE;QACN,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QAC3D,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;QAC5D,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,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;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACpF;;;;;;;kBA2Be,SAAS,GAAG,IAAI;;AAPhC,wBAuNE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory-cloud — OpenClaw memory extension
|
|
3
|
+
*
|
|
4
|
+
* Replaces the builtin LanceDB memory extension with cloud-backed storage:
|
|
5
|
+
* - Turbopuffer for vector storage (via services/memory Lambda proxy)
|
|
6
|
+
* - DynamoDB for knowledge graph
|
|
7
|
+
* - Haiku for classification + entity extraction
|
|
8
|
+
*
|
|
9
|
+
* Registers:
|
|
10
|
+
* - Memory tools: memory_recall, memory_store, memory_forget, memory_navigate, memory_graph, memory_stats
|
|
11
|
+
* - Lifecycle hooks: before_agent_start (auto-recall), agent_end (auto-capture), message_received (idle debounce)
|
|
12
|
+
* - Memory runtime: replaces builtin SQLite backend with cloud backend
|
|
13
|
+
*/
|
|
14
|
+
import { MemoryClient } from "./memory-client.js";
|
|
15
|
+
import { AutoCapture } from "./auto-capture.js";
|
|
16
|
+
import { AutoRecall } from "./auto-recall.js";
|
|
17
|
+
import { formatSearchResults } from "./formatter.js";
|
|
18
|
+
const DEFAULT_CONFIG = {
|
|
19
|
+
autoCapture: true,
|
|
20
|
+
autoRecall: true,
|
|
21
|
+
captureMaxChars: 500,
|
|
22
|
+
idleFlushSeconds: 60,
|
|
23
|
+
};
|
|
24
|
+
function resolveConfig(pluginConfig) {
|
|
25
|
+
return {
|
|
26
|
+
autoCapture: typeof pluginConfig?.autoCapture === "boolean" ? pluginConfig.autoCapture : DEFAULT_CONFIG.autoCapture,
|
|
27
|
+
autoRecall: typeof pluginConfig?.autoRecall === "boolean" ? pluginConfig.autoRecall : DEFAULT_CONFIG.autoRecall,
|
|
28
|
+
captureMaxChars: typeof pluginConfig?.captureMaxChars === "number" ? pluginConfig.captureMaxChars : DEFAULT_CONFIG.captureMaxChars,
|
|
29
|
+
idleFlushSeconds: typeof pluginConfig?.idleFlushSeconds === "number" ? pluginConfig.idleFlushSeconds : DEFAULT_CONFIG.idleFlushSeconds,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export default {
|
|
33
|
+
id: "memory-cloud",
|
|
34
|
+
name: "Cloud Memory",
|
|
35
|
+
description: "Persistent agent memory backed by Turbopuffer + DynamoDB knowledge graph",
|
|
36
|
+
version: "0.1.0",
|
|
37
|
+
kind: "memory",
|
|
38
|
+
register(api) {
|
|
39
|
+
const config = resolveConfig(api.pluginConfig);
|
|
40
|
+
const logger = api.logger;
|
|
41
|
+
// Memory service URL from integration DESIRED_STATE config
|
|
42
|
+
const cfgUrl = api.pluginConfig?.memoryServiceUrl;
|
|
43
|
+
const cfgKey = api.pluginConfig?.agentApiKey;
|
|
44
|
+
const cfgAgent = api.pluginConfig?.agentId;
|
|
45
|
+
const memoryServiceUrl = typeof cfgUrl === "string" ? cfgUrl : "";
|
|
46
|
+
const agentApiKey = typeof cfgKey === "string" ? cfgKey : "";
|
|
47
|
+
const agentId = typeof cfgAgent === "string" ? cfgAgent : "";
|
|
48
|
+
if (!memoryServiceUrl) {
|
|
49
|
+
throw new Error("memory-cloud: memoryServiceUrl not configured — cannot register memory extension");
|
|
50
|
+
}
|
|
51
|
+
const client = new MemoryClient(memoryServiceUrl, agentApiKey, agentId);
|
|
52
|
+
const autoCapture = new AutoCapture(client, config, logger);
|
|
53
|
+
const autoRecall = new AutoRecall(client, config, logger);
|
|
54
|
+
// ─── Memory prompt section ──────────────────────────────────
|
|
55
|
+
api.registerMemoryPromptSection(({ availableTools }) => {
|
|
56
|
+
const lines = ["## Memory"];
|
|
57
|
+
if (availableTools.has("memory_recall")) {
|
|
58
|
+
lines.push("Use memory_recall to search your conversation history and knowledge graph.");
|
|
59
|
+
lines.push("Results include structured facts (from knowledge graph) and relevant conversation excerpts.");
|
|
60
|
+
}
|
|
61
|
+
if (availableTools.has("memory_store")) {
|
|
62
|
+
lines.push("Use memory_store to explicitly save important information for future reference.");
|
|
63
|
+
}
|
|
64
|
+
if (availableTools.has("memory_graph")) {
|
|
65
|
+
lines.push("Use memory_graph to look up what you know about a specific entity.");
|
|
66
|
+
}
|
|
67
|
+
return lines;
|
|
68
|
+
});
|
|
69
|
+
// ─── Tools ──────────────────────────────────────────────────
|
|
70
|
+
api.registerTool(() => ({
|
|
71
|
+
name: "memory_recall",
|
|
72
|
+
label: "Memory Recall",
|
|
73
|
+
description: "Search conversation memory and knowledge graph. Returns structured facts and relevant conversation excerpts.",
|
|
74
|
+
parameters: {
|
|
75
|
+
type: "object",
|
|
76
|
+
properties: {
|
|
77
|
+
query: { type: "string", description: "What to search for" },
|
|
78
|
+
limit: { type: "number", description: "Maximum results (default 10)" },
|
|
79
|
+
topic: { type: "string", description: "Filter by topic" },
|
|
80
|
+
tag: { type: "string", description: "Filter by tag (fact/decision/preference/event/discovery)" },
|
|
81
|
+
},
|
|
82
|
+
required: ["query"],
|
|
83
|
+
},
|
|
84
|
+
execute: async (_toolCallId, params) => {
|
|
85
|
+
const results = await client.search(params.query, {
|
|
86
|
+
limit: params.limit,
|
|
87
|
+
topic: params.topic,
|
|
88
|
+
tag: params.tag,
|
|
89
|
+
});
|
|
90
|
+
return formatSearchResults(results);
|
|
91
|
+
},
|
|
92
|
+
}), { names: ["memory_recall", "memory_search"] });
|
|
93
|
+
api.registerTool(() => ({
|
|
94
|
+
name: "memory_store",
|
|
95
|
+
label: "Memory Store",
|
|
96
|
+
description: "Explicitly save a piece of information to long-term memory.",
|
|
97
|
+
parameters: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
text: { type: "string", description: "The information to remember" },
|
|
101
|
+
topic: { type: "string", description: "Topic category (e.g., person name, project)" },
|
|
102
|
+
tag: { type: "string", description: "Memory type: fact, decision, preference, event, discovery" },
|
|
103
|
+
importance: { type: "number", description: "Importance 0-1 (default 0.7)" },
|
|
104
|
+
},
|
|
105
|
+
required: ["text"],
|
|
106
|
+
},
|
|
107
|
+
execute: async (_toolCallId, params) => {
|
|
108
|
+
const result = await client.store(params.text, {
|
|
109
|
+
topic: params.topic,
|
|
110
|
+
tag: params.tag,
|
|
111
|
+
importance: params.importance,
|
|
112
|
+
});
|
|
113
|
+
return `Stored memory: ${result.memoryId}`;
|
|
114
|
+
},
|
|
115
|
+
}), { names: ["memory_store"] });
|
|
116
|
+
api.registerTool(() => ({
|
|
117
|
+
name: "memory_forget",
|
|
118
|
+
label: "Memory Forget",
|
|
119
|
+
description: "Search for and delete memories matching a query.",
|
|
120
|
+
parameters: {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
query: { type: "string", description: "Search for memories to delete" },
|
|
124
|
+
},
|
|
125
|
+
required: ["query"],
|
|
126
|
+
},
|
|
127
|
+
execute: async (_toolCallId, params) => {
|
|
128
|
+
const results = await client.search(params.query, { limit: 5 });
|
|
129
|
+
if (results.memories.length === 0)
|
|
130
|
+
return "No matching memories found.";
|
|
131
|
+
const deleted = [];
|
|
132
|
+
for (const mem of results.memories) {
|
|
133
|
+
try {
|
|
134
|
+
await client.deleteMemory(mem.id);
|
|
135
|
+
deleted.push(mem.id);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
logger.warn("Failed to delete memory", { memoryId: mem.id });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return `Deleted ${String(deleted.length)} of ${String(results.memories.length)} matching memories.`;
|
|
142
|
+
},
|
|
143
|
+
}), { names: ["memory_forget"] });
|
|
144
|
+
api.registerTool(() => ({
|
|
145
|
+
name: "memory_graph",
|
|
146
|
+
label: "Knowledge Graph",
|
|
147
|
+
description: "Look up what you know about a specific entity from the knowledge graph.",
|
|
148
|
+
parameters: {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
entity: { type: "string", description: "The entity to look up (person, concept, system)" },
|
|
152
|
+
},
|
|
153
|
+
required: ["entity"],
|
|
154
|
+
},
|
|
155
|
+
execute: async (_toolCallId, params) => {
|
|
156
|
+
const result = await client.lookupEntity(params.entity);
|
|
157
|
+
if (result.triples.length === 0)
|
|
158
|
+
return `No knowledge found about "${params.entity}".`;
|
|
159
|
+
const facts = result.triples.map((t) => `- ${result.subject} ${t.predicate} ${t.object} (since ${t.validFrom.slice(0, 10)})`);
|
|
160
|
+
return `Known facts about ${result.subject}:\n${facts.join("\n")}`;
|
|
161
|
+
},
|
|
162
|
+
}), { names: ["memory_graph"] });
|
|
163
|
+
api.registerTool(() => ({
|
|
164
|
+
name: "memory_stats",
|
|
165
|
+
label: "Memory Stats",
|
|
166
|
+
description: "Get memory storage statistics.",
|
|
167
|
+
parameters: { type: "object", properties: {} },
|
|
168
|
+
execute: async () => {
|
|
169
|
+
const s = await client.stats();
|
|
170
|
+
return `Memories: ${String(s.vectorCount)}, Knowledge facts: ${String(s.tripleCount)}, Storage: ${String(Math.round(s.storageEstimateBytes / 1024))} KB`;
|
|
171
|
+
},
|
|
172
|
+
}), { names: ["memory_stats"] });
|
|
173
|
+
api.registerTool(() => ({
|
|
174
|
+
name: "memory_navigate",
|
|
175
|
+
label: "Memory Navigate",
|
|
176
|
+
description: "Browse your memory palace structure — list topics, subtopics, and memory counts.",
|
|
177
|
+
parameters: { type: "object", properties: {} },
|
|
178
|
+
execute: async () => {
|
|
179
|
+
const nav = await client.navigate();
|
|
180
|
+
const topics = nav?.topics ?? [];
|
|
181
|
+
if (topics.length === 0)
|
|
182
|
+
return "No memories stored yet.";
|
|
183
|
+
const lines = topics.map((t) => `- ${t.name} (${String(t.tripleCount)} facts, subtopics: ${t.subtopics.join(", ") || "none"})`);
|
|
184
|
+
return `Memory topics:\n${lines.join("\n")}`;
|
|
185
|
+
},
|
|
186
|
+
}), { names: ["memory_navigate"] });
|
|
187
|
+
// ─── Lifecycle hooks ────────────────────────────────────────
|
|
188
|
+
// Auto-recall: inject relevant memories at session start
|
|
189
|
+
api.on("before_agent_start", async (event, ctx) => {
|
|
190
|
+
const startEvent = event;
|
|
191
|
+
const agentCtx = ctx;
|
|
192
|
+
const prompt = typeof startEvent.prompt === "string" ? startEvent.prompt : "";
|
|
193
|
+
const sessionKey = typeof agentCtx.sessionKey === "string" ? agentCtx.sessionKey : undefined;
|
|
194
|
+
const channelId = typeof agentCtx.channelId === "string" ? agentCtx.channelId : undefined;
|
|
195
|
+
if (sessionKey) {
|
|
196
|
+
autoCapture.setSession(sessionKey, { channelId });
|
|
197
|
+
}
|
|
198
|
+
const contextXml = await autoRecall.loadForPrompt(prompt);
|
|
199
|
+
if (contextXml) {
|
|
200
|
+
return { prependContext: contextXml };
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}, { priority: 10 });
|
|
204
|
+
// Track incoming messages for idle debounce
|
|
205
|
+
api.on("message_received", (event) => {
|
|
206
|
+
const msgEvent = event;
|
|
207
|
+
const content = typeof msgEvent.content === "string" ? msgEvent.content : "";
|
|
208
|
+
autoCapture.trackMessage("user", content);
|
|
209
|
+
});
|
|
210
|
+
// Track outgoing messages
|
|
211
|
+
api.on("message_sending", (event) => {
|
|
212
|
+
const msgEvent = event;
|
|
213
|
+
const content = typeof msgEvent.content === "string" ? msgEvent.content : "";
|
|
214
|
+
autoCapture.trackMessage("assistant", content);
|
|
215
|
+
});
|
|
216
|
+
// Final flush on session end
|
|
217
|
+
api.on("agent_end", async (event) => {
|
|
218
|
+
const endEvent = event;
|
|
219
|
+
if (endEvent.success !== false) {
|
|
220
|
+
await autoCapture.onAgentEnd();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
logger.info("memory-cloud extension registered", { autoCapture: config.autoCapture, autoRecall: config.autoRecall });
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
//# sour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AC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7E,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,6BAA6B;QAC7B,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE;YAC3C,MAAM,QAAQ,GAAG,KAAgC,CAAC;YAClD,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;gBAC/B,MAAM,WAAW,CAAC,UAAU,EAAE,CAAC;YACjC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACvH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MemorySearchResult, MemoryContext, MemoryMessage, SessionMetadata } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP client for services/memory.
|
|
4
|
+
* All memory operations go through the Lambda service — no direct Turbopuffer/DynamoDB access.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryClient {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly agentApiKey;
|
|
9
|
+
private readonly agentId;
|
|
10
|
+
constructor(baseUrl: string, agentApiKey: string, agentId: string);
|
|
11
|
+
search(query: string, opts?: {
|
|
12
|
+
limit?: number;
|
|
13
|
+
topic?: string;
|
|
14
|
+
subtopic?: string;
|
|
15
|
+
tag?: string;
|
|
16
|
+
includeKnowledge?: boolean;
|
|
17
|
+
}): Promise<MemorySearchResult>;
|
|
18
|
+
store(text: string, opts?: {
|
|
19
|
+
topic?: string;
|
|
20
|
+
subtopic?: string;
|
|
21
|
+
tag?: string;
|
|
22
|
+
importance?: number;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
memoryId: string;
|
|
25
|
+
}>;
|
|
26
|
+
ingest(sessionKey: string, messages: MemoryMessage[], metadata?: SessionMetadata): Promise<void>;
|
|
27
|
+
loadContext(tier: number, topicHint?: string): Promise<MemoryContext>;
|
|
28
|
+
lookupEntity(subject: string): Promise<{
|
|
29
|
+
subject: string;
|
|
30
|
+
triples: {
|
|
31
|
+
tripleId: string;
|
|
32
|
+
predicate: string;
|
|
33
|
+
object: string;
|
|
34
|
+
validFrom: string;
|
|
35
|
+
validTo?: string;
|
|
36
|
+
confidence: number;
|
|
37
|
+
}[];
|
|
38
|
+
}>;
|
|
39
|
+
navigate(): Promise<unknown>;
|
|
40
|
+
deleteMemory(memoryId: string): Promise<void>;
|
|
41
|
+
stats(): Promise<{
|
|
42
|
+
vectorCount: number;
|
|
43
|
+
tripleCount: number;
|
|
44
|
+
storageEstimateBytes: number;
|
|
45
|
+
}>;
|
|
46
|
+
private post;
|
|
47
|
+
private get;
|
|
48
|
+
private del;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=memory-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-client.d.ts","sourceRoot":"","sources":["../src/memory-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpG;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM;IAK5B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QACjC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,E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