@xdarkicex/openclaw-memory-libravdb 1.9.2 → 1.9.4
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.js +39 -6
- package/dist/index.js +60 -17
- package/dist/types.d.ts +2 -0
- package/dist/types.js +17 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/context-engine.js
CHANGED
|
@@ -812,7 +812,7 @@ function logPredictiveCompactionOutcome(params) {
|
|
|
812
812
|
params.logger.info?.(message);
|
|
813
813
|
return;
|
|
814
814
|
}
|
|
815
|
-
params.logger.
|
|
815
|
+
params.logger.info?.(message);
|
|
816
816
|
}
|
|
817
817
|
/**
|
|
818
818
|
* Truncates content to fit within token budget, preserving the tail.
|
|
@@ -869,7 +869,7 @@ function boundAfterTurnMessagesForIngest(messages, logger, sessionId) {
|
|
|
869
869
|
}
|
|
870
870
|
const bounded = trimMessagesToBudget(messages, AFTER_TURN_INGEST_MAX_TOKENS)
|
|
871
871
|
.map((message) => normalizeKernelMessage(message));
|
|
872
|
-
logger.
|
|
872
|
+
logger.info?.(`LibraVDB afterTurn trimmed oversized ingest payload sessionId=${sessionId} ` +
|
|
873
873
|
`estimatedTokens=${estimatedTokens} maxTokens=${AFTER_TURN_INGEST_MAX_TOKENS} ` +
|
|
874
874
|
`forwardedMessages=${bounded.length}`);
|
|
875
875
|
return bounded;
|
|
@@ -1367,7 +1367,7 @@ function ensureReplaySafeUserTurn(assembled, sourceMessages, logger, tokenBudget
|
|
|
1367
1367
|
const fallbackUser = findLastReplaySafeUserMessage(sourceMessages);
|
|
1368
1368
|
if (!fallbackUser)
|
|
1369
1369
|
return assembled;
|
|
1370
|
-
logger?.
|
|
1370
|
+
logger?.info?.("LibraVDB assemble produced no replay-safe user turn; reinjecting the latest user message for provider compatibility.");
|
|
1371
1371
|
const baseEstimatedTokens = Math.max(0, assembled.estimatedTokens, approximateMessagesTokens(assembled.messages));
|
|
1372
1372
|
if (typeof tokenBudget === "number" && Number.isFinite(tokenBudget) && tokenBudget > 0) {
|
|
1373
1373
|
const effectiveBudget = resolveEffectiveAssembleBudget(tokenBudget);
|
|
@@ -1426,6 +1426,26 @@ export function normalizeAssembleResult(result, sourceMessages) {
|
|
|
1426
1426
|
const systemPromptWasReduced = rawSystemPromptAddition.length > systemPromptAddition.length;
|
|
1427
1427
|
const messages = [];
|
|
1428
1428
|
const extractedMemoryItems = [];
|
|
1429
|
+
let lastProviderReplayKey;
|
|
1430
|
+
let lastSourceIndex;
|
|
1431
|
+
const pushProviderReplayMessage = (message, sourceIndex) => {
|
|
1432
|
+
const key = `${message.role}\0${message.content}`;
|
|
1433
|
+
if (key === lastProviderReplayKey) {
|
|
1434
|
+
if (lastSourceIndex !== undefined &&
|
|
1435
|
+
sourceIndex !== undefined &&
|
|
1436
|
+
lastSourceIndex >= 0 &&
|
|
1437
|
+
sourceIndex >= 0 &&
|
|
1438
|
+
lastSourceIndex !== sourceIndex) {
|
|
1439
|
+
// Fall through — push the message.
|
|
1440
|
+
}
|
|
1441
|
+
else {
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
messages.push(message);
|
|
1446
|
+
lastProviderReplayKey = key;
|
|
1447
|
+
lastSourceIndex = sourceIndex;
|
|
1448
|
+
};
|
|
1429
1449
|
const pushMemoryItem = (args) => {
|
|
1430
1450
|
if (args.content.trim().length === 0)
|
|
1431
1451
|
return;
|
|
@@ -1435,6 +1455,7 @@ export function normalizeAssembleResult(result, sourceMessages) {
|
|
|
1435
1455
|
if (Array.isArray(result.messages)) {
|
|
1436
1456
|
const lastUserIndex = sourceMessages ? findLastUserMessageIndex(sourceMessages) : -1;
|
|
1437
1457
|
let liveSourceCursor = sourceMessages ? lastUserIndex + 1 : undefined;
|
|
1458
|
+
let providerReplaySourceCursor = sourceMessages ? 0 : undefined;
|
|
1438
1459
|
for (const message of result.messages) {
|
|
1439
1460
|
const content = normalizeKernelContent(message.content);
|
|
1440
1461
|
const historicalToolSource = getHistoricalToolSource(message.role, message.content, content);
|
|
@@ -1447,6 +1468,10 @@ export function normalizeAssembleResult(result, sourceMessages) {
|
|
|
1447
1468
|
}
|
|
1448
1469
|
const liveToolProtocolSource = consumeLiveToolAtCursor(message, content, sourceMessages, liveSourceCursor, lastUserIndex >= 0 ? lastUserIndex : undefined);
|
|
1449
1470
|
if (liveToolProtocolSource) {
|
|
1471
|
+
// Live tool protocol messages are cursor-guarded by
|
|
1472
|
+
// consumeLiveToolAtCursor — consecutive toolResults with the
|
|
1473
|
+
// same content but different toolCallId linkage must not be
|
|
1474
|
+
// collapsed. Push directly, bypassing provider-replay dedup.
|
|
1450
1475
|
messages.push(preserveLiveToolProtocolMessage(liveToolProtocolSource.message));
|
|
1451
1476
|
liveSourceCursor = liveToolProtocolSource.index + 1;
|
|
1452
1477
|
}
|
|
@@ -1478,11 +1503,19 @@ export function normalizeAssembleResult(result, sourceMessages) {
|
|
|
1478
1503
|
}
|
|
1479
1504
|
continue;
|
|
1480
1505
|
}
|
|
1481
|
-
|
|
1506
|
+
const providerReplaySourceIndex = sourceMessages
|
|
1507
|
+
? findMatchingSourceMessageIndex(message, content, sourceMessages, providerReplaySourceCursor)
|
|
1508
|
+
: undefined;
|
|
1509
|
+
pushProviderReplayMessage({
|
|
1482
1510
|
role: message.role,
|
|
1483
1511
|
content: sanitizedContent,
|
|
1484
1512
|
...(typeof message.id === "string" ? { id: message.id } : {}),
|
|
1485
|
-
});
|
|
1513
|
+
}, providerReplaySourceIndex);
|
|
1514
|
+
if (providerReplaySourceCursor !== undefined &&
|
|
1515
|
+
providerReplaySourceIndex !== undefined &&
|
|
1516
|
+
providerReplaySourceIndex >= 0) {
|
|
1517
|
+
providerReplaySourceCursor = providerReplaySourceIndex + 1;
|
|
1518
|
+
}
|
|
1486
1519
|
}
|
|
1487
1520
|
else {
|
|
1488
1521
|
// Daemon memory items may not be in sourceMessages — only advance
|
|
@@ -2159,7 +2192,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2159
2192
|
reason: compactionResult.reason,
|
|
2160
2193
|
});
|
|
2161
2194
|
if (!compactionResult.ok) {
|
|
2162
|
-
logger.
|
|
2195
|
+
logger.info?.(`LibraVDB predictive compaction blocked assemble path at ${currentContextTokens} tokens ` +
|
|
2163
2196
|
`(threshold=${dynamicCompactThreshold}): ${compactionResult.reason ?? "compaction failed"}`);
|
|
2164
2197
|
return ensureReplaySafeUserTurn(sanitizeProviderReplayMessages(buildBudgetFallbackContext(args.messages, args.tokenBudget), args.messages), args.messages, logger, args.tokenBudget);
|
|
2165
2198
|
}
|
package/dist/index.js
CHANGED
|
@@ -36160,7 +36160,7 @@ function logPredictiveCompactionOutcome(params) {
|
|
|
36160
36160
|
params.logger.info?.(message);
|
|
36161
36161
|
return;
|
|
36162
36162
|
}
|
|
36163
|
-
params.logger.
|
|
36163
|
+
params.logger.info?.(message);
|
|
36164
36164
|
}
|
|
36165
36165
|
function truncateContentToTokenBudget(content, tokenBudget) {
|
|
36166
36166
|
if (tokenBudget <= 0) return "";
|
|
@@ -36204,7 +36204,7 @@ function boundAfterTurnMessagesForIngest(messages, logger, sessionId) {
|
|
|
36204
36204
|
return messages;
|
|
36205
36205
|
}
|
|
36206
36206
|
const bounded = trimMessagesToBudget(messages, AFTER_TURN_INGEST_MAX_TOKENS).map((message) => normalizeKernelMessage(message));
|
|
36207
|
-
logger.
|
|
36207
|
+
logger.info?.(
|
|
36208
36208
|
`LibraVDB afterTurn trimmed oversized ingest payload sessionId=${sessionId} estimatedTokens=${estimatedTokens} maxTokens=${AFTER_TURN_INGEST_MAX_TOKENS} forwardedMessages=${bounded.length}`
|
|
36209
36209
|
);
|
|
36210
36210
|
return bounded;
|
|
@@ -36611,7 +36611,7 @@ function ensureReplaySafeUserTurn(assembled, sourceMessages, logger, tokenBudget
|
|
|
36611
36611
|
if (hasReplaySafeUserTurn(assembled.messages)) return assembled;
|
|
36612
36612
|
const fallbackUser = findLastReplaySafeUserMessage(sourceMessages);
|
|
36613
36613
|
if (!fallbackUser) return assembled;
|
|
36614
|
-
logger?.
|
|
36614
|
+
logger?.info?.(
|
|
36615
36615
|
"LibraVDB assemble produced no replay-safe user turn; reinjecting the latest user message for provider compatibility."
|
|
36616
36616
|
);
|
|
36617
36617
|
const baseEstimatedTokens = Math.max(
|
|
@@ -36673,6 +36673,20 @@ function normalizeAssembleResult(result, sourceMessages) {
|
|
|
36673
36673
|
const systemPromptWasReduced = rawSystemPromptAddition.length > systemPromptAddition.length;
|
|
36674
36674
|
const messages = [];
|
|
36675
36675
|
const extractedMemoryItems = [];
|
|
36676
|
+
let lastProviderReplayKey;
|
|
36677
|
+
let lastSourceIndex;
|
|
36678
|
+
const pushProviderReplayMessage = (message, sourceIndex) => {
|
|
36679
|
+
const key = `${message.role}\0${message.content}`;
|
|
36680
|
+
if (key === lastProviderReplayKey) {
|
|
36681
|
+
if (lastSourceIndex !== void 0 && sourceIndex !== void 0 && lastSourceIndex >= 0 && sourceIndex >= 0 && lastSourceIndex !== sourceIndex) {
|
|
36682
|
+
} else {
|
|
36683
|
+
return;
|
|
36684
|
+
}
|
|
36685
|
+
}
|
|
36686
|
+
messages.push(message);
|
|
36687
|
+
lastProviderReplayKey = key;
|
|
36688
|
+
lastSourceIndex = sourceIndex;
|
|
36689
|
+
};
|
|
36676
36690
|
const pushMemoryItem = (args) => {
|
|
36677
36691
|
if (args.content.trim().length === 0) return;
|
|
36678
36692
|
const roleAttr = args.role ? ` role="${escapeMemoryFactText(args.role)}"` : "";
|
|
@@ -36683,6 +36697,7 @@ function normalizeAssembleResult(result, sourceMessages) {
|
|
|
36683
36697
|
if (Array.isArray(result.messages)) {
|
|
36684
36698
|
const lastUserIndex = sourceMessages ? findLastUserMessageIndex(sourceMessages) : -1;
|
|
36685
36699
|
let liveSourceCursor = sourceMessages ? lastUserIndex + 1 : void 0;
|
|
36700
|
+
let providerReplaySourceCursor = sourceMessages ? 0 : void 0;
|
|
36686
36701
|
for (const message of result.messages) {
|
|
36687
36702
|
const content = normalizeKernelContent(message.content);
|
|
36688
36703
|
const historicalToolSource = getHistoricalToolSource(message.role, message.content, content);
|
|
@@ -36726,11 +36741,18 @@ function normalizeAssembleResult(result, sourceMessages) {
|
|
|
36726
36741
|
}
|
|
36727
36742
|
continue;
|
|
36728
36743
|
}
|
|
36729
|
-
|
|
36730
|
-
|
|
36731
|
-
|
|
36732
|
-
|
|
36733
|
-
|
|
36744
|
+
const providerReplaySourceIndex = sourceMessages ? findMatchingSourceMessageIndex(message, content, sourceMessages, providerReplaySourceCursor) : void 0;
|
|
36745
|
+
pushProviderReplayMessage(
|
|
36746
|
+
{
|
|
36747
|
+
role: message.role,
|
|
36748
|
+
content: sanitizedContent,
|
|
36749
|
+
...typeof message.id === "string" ? { id: message.id } : {}
|
|
36750
|
+
},
|
|
36751
|
+
providerReplaySourceIndex
|
|
36752
|
+
);
|
|
36753
|
+
if (providerReplaySourceCursor !== void 0 && providerReplaySourceIndex !== void 0 && providerReplaySourceIndex >= 0) {
|
|
36754
|
+
providerReplaySourceCursor = providerReplaySourceIndex + 1;
|
|
36755
|
+
}
|
|
36734
36756
|
} else {
|
|
36735
36757
|
if (liveSourceCursor !== void 0 && sourceMessages) {
|
|
36736
36758
|
const idx = findMatchingSourceMessageIndex(message, content, sourceMessages, liveSourceCursor);
|
|
@@ -37349,7 +37371,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37349
37371
|
reason: compactionResult.reason
|
|
37350
37372
|
});
|
|
37351
37373
|
if (!compactionResult.ok) {
|
|
37352
|
-
logger.
|
|
37374
|
+
logger.info?.(
|
|
37353
37375
|
`LibraVDB predictive compaction blocked assemble path at ${currentContextTokens} tokens (threshold=${dynamicCompactThreshold}): ${compactionResult.reason ?? "compaction failed"}`
|
|
37354
37376
|
);
|
|
37355
37377
|
return ensureReplaySafeUserTurn(
|
|
@@ -49023,6 +49045,26 @@ function enrichStartupError(error2, healthMessage) {
|
|
|
49023
49045
|
return new Error(`${prefix}. ${daemonProvisioningHint()}`);
|
|
49024
49046
|
}
|
|
49025
49047
|
|
|
49048
|
+
// src/types.ts
|
|
49049
|
+
var LOG_LEVEL_RANK = {
|
|
49050
|
+
error: 0,
|
|
49051
|
+
warn: 1,
|
|
49052
|
+
info: 2,
|
|
49053
|
+
debug: 3
|
|
49054
|
+
};
|
|
49055
|
+
function levelFilteredLogger(base, logLevel) {
|
|
49056
|
+
const minRank = LOG_LEVEL_RANK[logLevel ?? "warn"];
|
|
49057
|
+
return {
|
|
49058
|
+
error: (msg) => base.error(msg),
|
|
49059
|
+
warn: (msg) => {
|
|
49060
|
+
if (LOG_LEVEL_RANK.warn <= minRank) base.warn?.(msg);
|
|
49061
|
+
},
|
|
49062
|
+
info: (msg) => {
|
|
49063
|
+
if (LOG_LEVEL_RANK.info <= minRank) base.info?.(msg);
|
|
49064
|
+
}
|
|
49065
|
+
};
|
|
49066
|
+
}
|
|
49067
|
+
|
|
49026
49068
|
// src/index.ts
|
|
49027
49069
|
var MEMORY_ID = "libravdb-memory";
|
|
49028
49070
|
var LIGHTWEIGHT_MODES = /* @__PURE__ */ new Set(["cli-metadata", "setup-only"]);
|
|
@@ -49032,7 +49074,8 @@ function shouldShutdownRuntimeForLifecycleCleanup(reason) {
|
|
|
49032
49074
|
}
|
|
49033
49075
|
function register(api) {
|
|
49034
49076
|
const registrationMode = api.registrationMode;
|
|
49035
|
-
const
|
|
49077
|
+
const baseLogger = api.logger ?? console;
|
|
49078
|
+
const logger = levelFilteredLogger(baseLogger, api.pluginConfig?.logLevel);
|
|
49036
49079
|
if (registrationMode === "cli-metadata") {
|
|
49037
49080
|
registerMemoryCliMetadata(api);
|
|
49038
49081
|
return;
|
|
@@ -49139,7 +49182,7 @@ function register(api) {
|
|
|
49139
49182
|
}
|
|
49140
49183
|
api.registerContextEngine(
|
|
49141
49184
|
MEMORY_ID,
|
|
49142
|
-
() => buildContextEngineFactory(runtime, cfg,
|
|
49185
|
+
() => buildContextEngineFactory(runtime, cfg, logger)
|
|
49143
49186
|
);
|
|
49144
49187
|
api.registerCompactionProvider?.({
|
|
49145
49188
|
id: MEMORY_ID,
|
|
@@ -49153,15 +49196,15 @@ function register(api) {
|
|
|
49153
49196
|
return result.summaryText;
|
|
49154
49197
|
}
|
|
49155
49198
|
});
|
|
49156
|
-
const markdownIngestion = createMarkdownIngestionHandle(cfg, runtime.getClient,
|
|
49157
|
-
const dreamPromotion = createDreamPromotionHandle(cfg, runtime.getClient,
|
|
49199
|
+
const markdownIngestion = createMarkdownIngestionHandle(cfg, runtime.getClient, logger);
|
|
49200
|
+
const dreamPromotion = createDreamPromotionHandle(cfg, runtime.getClient, logger);
|
|
49158
49201
|
api.registerService?.({
|
|
49159
49202
|
id: "libravdb-markdown-ingestion",
|
|
49160
49203
|
async start() {
|
|
49161
49204
|
try {
|
|
49162
49205
|
await markdownIngestion.start();
|
|
49163
49206
|
} catch (error2) {
|
|
49164
|
-
|
|
49207
|
+
logger.warn?.(`LibraVDB markdown ingestion failed to start: ${error2 instanceof Error ? error2.message : String(error2)}`);
|
|
49165
49208
|
}
|
|
49166
49209
|
},
|
|
49167
49210
|
async stop() {
|
|
@@ -49174,7 +49217,7 @@ function register(api) {
|
|
|
49174
49217
|
try {
|
|
49175
49218
|
await dreamPromotion.start();
|
|
49176
49219
|
} catch (error2) {
|
|
49177
|
-
|
|
49220
|
+
logger.warn?.(`LibraVDB dream promotion failed to start: ${error2 instanceof Error ? error2.message : String(error2)}`);
|
|
49178
49221
|
}
|
|
49179
49222
|
},
|
|
49180
49223
|
async stop() {
|
|
@@ -49204,8 +49247,8 @@ function register(api) {
|
|
|
49204
49247
|
const sessionId = ctx?.sessionId;
|
|
49205
49248
|
if (sessionId) clearSessionTrigger(sessionId);
|
|
49206
49249
|
});
|
|
49207
|
-
api.on("before_reset", createBeforeResetHook(runtime,
|
|
49208
|
-
api.on("session_end", createSessionEndHook(runtime,
|
|
49250
|
+
api.on("before_reset", createBeforeResetHook(runtime, logger));
|
|
49251
|
+
api.on("session_end", createSessionEndHook(runtime, logger));
|
|
49209
49252
|
api.on("gateway_stop", async () => {
|
|
49210
49253
|
await runtime.shutdown();
|
|
49211
49254
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -186,3 +186,5 @@ export interface PredictedContext {
|
|
|
186
186
|
text: string;
|
|
187
187
|
reason: string;
|
|
188
188
|
}
|
|
189
|
+
/** Wraps a LoggerLike with logLevel filtering. Levels below configured min are dropped. */
|
|
190
|
+
export declare function levelFilteredLogger(base: LoggerLike, logLevel: PluginConfig["logLevel"]): LoggerLike;
|
package/dist/types.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
const LOG_LEVEL_RANK = {
|
|
2
|
+
error: 0,
|
|
3
|
+
warn: 1,
|
|
4
|
+
info: 2,
|
|
5
|
+
debug: 3,
|
|
6
|
+
};
|
|
7
|
+
/** Wraps a LoggerLike with logLevel filtering. Levels below configured min are dropped. */
|
|
8
|
+
export function levelFilteredLogger(base, logLevel) {
|
|
9
|
+
const minRank = LOG_LEVEL_RANK[logLevel ?? "warn"];
|
|
10
|
+
return {
|
|
11
|
+
error: (msg) => base.error(msg),
|
|
12
|
+
warn: (msg) => { if (LOG_LEVEL_RANK.warn <= minRank)
|
|
13
|
+
base.warn?.(msg); },
|
|
14
|
+
info: (msg) => { if (LOG_LEVEL_RANK.info <= minRank)
|
|
15
|
+
base.info?.(msg); },
|
|
16
|
+
};
|
|
17
|
+
}
|
package/openclaw.plugin.json
CHANGED