@xdarkicex/openclaw-memory-libravdb 1.4.8 → 1.4.10
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/dist/context-engine.d.ts +42 -5
- package/dist/context-engine.js +106 -9
- package/dist/generated/libravdb/ipc/v1/rpc_pb.d.ts +1803 -0
- package/dist/generated/libravdb/ipc/v1/rpc_pb.d.ts.map +1 -0
- package/dist/generated/libravdb/ipc/v1/rpc_pb.js +2800 -0
- package/dist/generated/libravdb/ipc/v1/rpc_pb.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/plugin-runtime.d.ts +1 -0
- package/dist/plugin-runtime.js +4 -1
- package/dist/rpc-protobuf-codecs.d.ts +1 -1
- package/dist/rpc-protobuf-codecs.js +9 -2
- package/dist/rpc.d.ts +1 -0
- package/dist/rpc.js +89 -10
- package/dist/sidecar.d.ts +2 -1
- package/dist/sidecar.js +20 -4
- package/dist/types.d.ts +2 -0
- package/docs/install.md +10 -1
- package/docs/installation.md +14 -1
- package/openclaw.plugin.json +158 -47
- package/package.json +5 -6
package/dist/context-engine.d.ts
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import type { PluginRuntime } from "./plugin-runtime.js";
|
|
2
2
|
import type { LoggerLike, PluginConfig, RecallCache, SearchResult } from "./types.js";
|
|
3
|
-
import { AssembleContextInternalResponse } from "
|
|
3
|
+
import { AssembleContextInternalResponse } from "./generated/libravdb/ipc/v1/rpc_pb.js";
|
|
4
|
+
type KernelCompatibleMessage = {
|
|
5
|
+
role: string;
|
|
6
|
+
content: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
};
|
|
9
|
+
type OpenClawCompatibleMessage = {
|
|
10
|
+
role: string;
|
|
11
|
+
content: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
};
|
|
14
|
+
type OpenClawCompatibleAssembleResult = {
|
|
15
|
+
messages: OpenClawCompatibleMessage[];
|
|
16
|
+
estimatedTokens: number;
|
|
17
|
+
systemPromptAddition: string;
|
|
18
|
+
debug?: AssembleContextInternalResponse["debug"];
|
|
19
|
+
};
|
|
20
|
+
export declare function normalizeKernelMessage(message: {
|
|
21
|
+
role: string;
|
|
22
|
+
content: unknown;
|
|
23
|
+
id?: string;
|
|
24
|
+
}): KernelCompatibleMessage;
|
|
25
|
+
export declare function normalizeKernelMessages(messages: Array<{
|
|
26
|
+
role: string;
|
|
27
|
+
content: unknown;
|
|
28
|
+
id?: string;
|
|
29
|
+
}>): KernelCompatibleMessage[];
|
|
30
|
+
export declare function normalizeAssembleResult(result: {
|
|
31
|
+
messages?: Array<{
|
|
32
|
+
role: string;
|
|
33
|
+
content?: unknown;
|
|
34
|
+
id?: string;
|
|
35
|
+
}>;
|
|
36
|
+
estimatedTokens?: number;
|
|
37
|
+
systemPromptAddition?: string;
|
|
38
|
+
debug?: AssembleContextInternalResponse["debug"];
|
|
39
|
+
}): OpenClawCompatibleAssembleResult;
|
|
4
40
|
export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: PluginConfig, recallCache: RecallCache<SearchResult>, logger?: LoggerLike): {
|
|
5
41
|
info: {
|
|
6
42
|
id: string;
|
|
@@ -19,7 +55,7 @@ export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: P
|
|
|
19
55
|
userId?: string;
|
|
20
56
|
message: {
|
|
21
57
|
role: string;
|
|
22
|
-
content:
|
|
58
|
+
content: unknown;
|
|
23
59
|
id?: string;
|
|
24
60
|
};
|
|
25
61
|
isHeartbeat?: boolean;
|
|
@@ -30,12 +66,12 @@ export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: P
|
|
|
30
66
|
userId?: string;
|
|
31
67
|
messages: Array<{
|
|
32
68
|
role: string;
|
|
33
|
-
content:
|
|
69
|
+
content: unknown;
|
|
34
70
|
id?: string;
|
|
35
71
|
}>;
|
|
36
72
|
tokenBudget: number;
|
|
37
73
|
prompt?: string;
|
|
38
|
-
}): Promise<
|
|
74
|
+
}): Promise<OpenClawCompatibleAssembleResult>;
|
|
39
75
|
compact(args: {
|
|
40
76
|
sessionId: string;
|
|
41
77
|
force?: boolean;
|
|
@@ -47,10 +83,11 @@ export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: P
|
|
|
47
83
|
userId?: string;
|
|
48
84
|
messages: Array<{
|
|
49
85
|
role: string;
|
|
50
|
-
content:
|
|
86
|
+
content: unknown;
|
|
51
87
|
id?: string;
|
|
52
88
|
}>;
|
|
53
89
|
prePromptMessageCount?: number;
|
|
54
90
|
isHeartbeat?: boolean;
|
|
55
91
|
}): Promise<any>;
|
|
56
92
|
};
|
|
93
|
+
export {};
|
package/dist/context-engine.js
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
+
function describeUnexpectedContent(value) {
|
|
2
|
+
try {
|
|
3
|
+
const serialized = JSON.stringify(value);
|
|
4
|
+
return serialized === undefined ? String(value) : serialized;
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return String(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function stringifyKernelBlock(block) {
|
|
11
|
+
if (!block || typeof block !== "object") {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
const record = block;
|
|
15
|
+
switch (record.type) {
|
|
16
|
+
case "text":
|
|
17
|
+
return typeof record.text === "string" ? record.text : "";
|
|
18
|
+
case "thinking":
|
|
19
|
+
return typeof record.thinking === "string" ? record.thinking : "";
|
|
20
|
+
case "toolCall": {
|
|
21
|
+
const name = typeof record.name === "string" ? record.name : "tool";
|
|
22
|
+
const args = record.arguments;
|
|
23
|
+
let renderedArgs = "";
|
|
24
|
+
if (typeof args === "string") {
|
|
25
|
+
renderedArgs = args;
|
|
26
|
+
}
|
|
27
|
+
else if (args !== undefined) {
|
|
28
|
+
try {
|
|
29
|
+
renderedArgs = JSON.stringify(args);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
renderedArgs = String(args);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return renderedArgs ? `[tool:${name}] ${renderedArgs}` : `[tool:${name}]`;
|
|
36
|
+
}
|
|
37
|
+
case "image":
|
|
38
|
+
return "[image omitted]";
|
|
39
|
+
default:
|
|
40
|
+
console.warn("[libravdb] unsupported kernel content block", {
|
|
41
|
+
type: record.type,
|
|
42
|
+
block: describeUnexpectedContent(record),
|
|
43
|
+
});
|
|
44
|
+
return typeof record.text === "string" ? record.text : "";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function normalizeKernelContent(content) {
|
|
48
|
+
if (typeof content === "string") {
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(content)) {
|
|
52
|
+
console.warn("[libravdb] unexpected kernel content shape", {
|
|
53
|
+
kind: typeof content,
|
|
54
|
+
value: describeUnexpectedContent(content),
|
|
55
|
+
});
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
return content.map(stringifyKernelBlock).filter((part) => part.length > 0).join("\n");
|
|
59
|
+
}
|
|
60
|
+
export function normalizeKernelMessage(message) {
|
|
61
|
+
return {
|
|
62
|
+
role: message.role,
|
|
63
|
+
content: normalizeKernelContent(message.content),
|
|
64
|
+
...(typeof message.id === "string" ? { id: message.id } : {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function normalizeKernelMessages(messages) {
|
|
68
|
+
return messages.map((message) => normalizeKernelMessage(message));
|
|
69
|
+
}
|
|
70
|
+
export function normalizeAssembleResult(result) {
|
|
71
|
+
const messages = Array.isArray(result.messages)
|
|
72
|
+
? result.messages.map((message) => ({
|
|
73
|
+
// OpenClaw replay only expects conversational turns here, so assemble output
|
|
74
|
+
// is collapsed to user/assistant even though normalizeKernelMessage preserves
|
|
75
|
+
// richer inbound roles. If kernel.assembleContext starts emitting other roles,
|
|
76
|
+
// this coercion point is where that contract needs to be revisited.
|
|
77
|
+
role: message.role === "user" ? "user" : "assistant",
|
|
78
|
+
content: normalizeKernelContent(message.content),
|
|
79
|
+
...(typeof message.id === "string" ? { id: message.id } : {}),
|
|
80
|
+
}))
|
|
81
|
+
: [];
|
|
82
|
+
return {
|
|
83
|
+
messages,
|
|
84
|
+
estimatedTokens: typeof result.estimatedTokens === "number" ? result.estimatedTokens : 0,
|
|
85
|
+
systemPromptAddition: typeof result.systemPromptAddition === "string" ? result.systemPromptAddition : "",
|
|
86
|
+
...(result.debug != null ? { debug: result.debug } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
1
89
|
export function buildContextEngineFactory(runtime, cfg, recallCache, logger = console) {
|
|
2
90
|
return {
|
|
3
91
|
info: { id: "libravdb-memory", name: "LibraVDB Memory", ownsCompaction: true },
|
|
@@ -24,39 +112,44 @@ export function buildContextEngineFactory(runtime, cfg, recallCache, logger = co
|
|
|
24
112
|
return await rpc.call("bootstrap_session_kernel", args);
|
|
25
113
|
},
|
|
26
114
|
async ingest(args) {
|
|
115
|
+
const message = normalizeKernelMessage(args.message);
|
|
27
116
|
const kernel = runtime.getKernel();
|
|
28
117
|
if (kernel) {
|
|
29
118
|
return await kernel.ingestMessage({
|
|
30
119
|
sessionId: args.sessionId,
|
|
31
120
|
sessionKey: args.sessionKey,
|
|
32
121
|
userId: args.userId,
|
|
33
|
-
message
|
|
122
|
+
message,
|
|
34
123
|
isHeartbeat: args.isHeartbeat,
|
|
35
124
|
});
|
|
36
125
|
}
|
|
37
126
|
const rpc = await runtime.getRpc();
|
|
38
|
-
return await rpc.call("ingest_message_kernel",
|
|
127
|
+
return await rpc.call("ingest_message_kernel", {
|
|
128
|
+
...args,
|
|
129
|
+
message,
|
|
130
|
+
});
|
|
39
131
|
},
|
|
40
132
|
async assemble(args) {
|
|
133
|
+
const messages = normalizeKernelMessages(args.messages);
|
|
41
134
|
const kernel = runtime.getKernel();
|
|
42
135
|
if (kernel) {
|
|
43
|
-
return await kernel.assembleContext({
|
|
136
|
+
return normalizeAssembleResult(await kernel.assembleContext({
|
|
44
137
|
sessionId: args.sessionId,
|
|
45
138
|
sessionKey: args.sessionKey,
|
|
46
139
|
userId: args.userId,
|
|
47
140
|
queryText: args.prompt ?? "",
|
|
48
|
-
visibleMessages:
|
|
141
|
+
visibleMessages: messages,
|
|
49
142
|
tokenBudget: args.tokenBudget,
|
|
50
143
|
config: {},
|
|
51
144
|
emitDebug: true
|
|
52
|
-
});
|
|
145
|
+
}));
|
|
53
146
|
}
|
|
54
147
|
const rpc = await runtime.getRpc();
|
|
55
148
|
const resp = await rpc.call("assemble_context_internal", {
|
|
56
149
|
sessionId: args.sessionId,
|
|
57
150
|
sessionKey: args.sessionKey,
|
|
58
151
|
userId: args.userId,
|
|
59
|
-
messages
|
|
152
|
+
messages,
|
|
60
153
|
tokenBudget: args.tokenBudget,
|
|
61
154
|
prompt: args.prompt,
|
|
62
155
|
emitDebug: true,
|
|
@@ -92,7 +185,7 @@ export function buildContextEngineFactory(runtime, cfg, recallCache, logger = co
|
|
|
92
185
|
ingestionGateThreshold: cfg.ingestionGateThreshold,
|
|
93
186
|
},
|
|
94
187
|
});
|
|
95
|
-
return resp;
|
|
188
|
+
return normalizeAssembleResult(resp);
|
|
96
189
|
},
|
|
97
190
|
async compact(args) {
|
|
98
191
|
const kernel = runtime.getKernel();
|
|
@@ -107,19 +200,23 @@ export function buildContextEngineFactory(runtime, cfg, recallCache, logger = co
|
|
|
107
200
|
return await rpc.call("compact_session", args);
|
|
108
201
|
},
|
|
109
202
|
async afterTurn(args) {
|
|
203
|
+
const messages = normalizeKernelMessages(args.messages);
|
|
110
204
|
const kernel = runtime.getKernel();
|
|
111
205
|
if (kernel) {
|
|
112
206
|
return await kernel.afterTurn({
|
|
113
207
|
sessionId: args.sessionId,
|
|
114
208
|
sessionKey: args.sessionKey,
|
|
115
209
|
userId: args.userId,
|
|
116
|
-
messages
|
|
210
|
+
messages,
|
|
117
211
|
prePromptMessageCount: args.prePromptMessageCount,
|
|
118
212
|
isHeartbeat: args.isHeartbeat,
|
|
119
213
|
});
|
|
120
214
|
}
|
|
121
215
|
const rpc = await runtime.getRpc();
|
|
122
|
-
return await rpc.call("after_turn_kernel",
|
|
216
|
+
return await rpc.call("after_turn_kernel", {
|
|
217
|
+
...args,
|
|
218
|
+
messages,
|
|
219
|
+
});
|
|
123
220
|
}
|
|
124
221
|
};
|
|
125
222
|
}
|