@xdarkicex/openclaw-memory-libravdb 1.4.68 → 1.4.69
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 +22 -5
- package/dist/index.js +24 -5
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/context-engine.js
CHANGED
|
@@ -275,6 +275,17 @@ function resolvePredictiveCompactionTokenCount(args) {
|
|
|
275
275
|
return (normalizeCurrentTokenCount(args.currentTokenCount) ??
|
|
276
276
|
approximateMessagesTokens(args.messages) + approximateTokenCount(args.prompt ?? ""));
|
|
277
277
|
}
|
|
278
|
+
function resolveAfterTurnPredictiveCompactionTokenCount(args) {
|
|
279
|
+
const currentTokenCount = normalizeCurrentTokenCount(args.currentTokenCount);
|
|
280
|
+
const forwardedMessageTokens = normalizeCurrentTokenCount(approximateMessagesTokens(args.messages));
|
|
281
|
+
if (currentTokenCount == null) {
|
|
282
|
+
return forwardedMessageTokens;
|
|
283
|
+
}
|
|
284
|
+
if (forwardedMessageTokens == null) {
|
|
285
|
+
return currentTokenCount;
|
|
286
|
+
}
|
|
287
|
+
return Math.max(currentTokenCount, forwardedMessageTokens);
|
|
288
|
+
}
|
|
278
289
|
export function normalizeKernelMessage(message) {
|
|
279
290
|
return {
|
|
280
291
|
role: message.role,
|
|
@@ -564,11 +575,15 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
564
575
|
}
|
|
565
576
|
async function performAfterTurnPredictiveCompaction(args) {
|
|
566
577
|
const dynamicCompactThreshold = getDynamicCompactThreshold(args.tokenBudget);
|
|
567
|
-
const
|
|
578
|
+
const currentContextTokens = resolveAfterTurnPredictiveCompactionTokenCount({
|
|
568
579
|
currentTokenCount: args.currentTokenCount,
|
|
580
|
+
messages: args.messages,
|
|
581
|
+
});
|
|
582
|
+
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
583
|
+
currentTokenCount: currentContextTokens,
|
|
569
584
|
threshold: dynamicCompactThreshold,
|
|
570
585
|
});
|
|
571
|
-
if (
|
|
586
|
+
if (currentContextTokens == null ||
|
|
572
587
|
dynamicCompactThreshold == null ||
|
|
573
588
|
predictiveTargetSize == null) {
|
|
574
589
|
return;
|
|
@@ -577,7 +592,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
577
592
|
logger,
|
|
578
593
|
phase: "afterTurn",
|
|
579
594
|
sessionId: args.sessionId,
|
|
580
|
-
currentTokenCount:
|
|
595
|
+
currentTokenCount: currentContextTokens,
|
|
581
596
|
threshold: dynamicCompactThreshold,
|
|
582
597
|
targetSize: predictiveTargetSize,
|
|
583
598
|
tokenBudget: args.tokenBudget,
|
|
@@ -587,13 +602,13 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
587
602
|
targetSize: predictiveTargetSize,
|
|
588
603
|
tokenBudget: args.tokenBudget,
|
|
589
604
|
force: true,
|
|
590
|
-
currentTokenCount:
|
|
605
|
+
currentTokenCount: currentContextTokens,
|
|
591
606
|
});
|
|
592
607
|
logPredictiveCompactionOutcome({
|
|
593
608
|
logger,
|
|
594
609
|
phase: "afterTurn",
|
|
595
610
|
sessionId: args.sessionId,
|
|
596
|
-
currentTokenCount:
|
|
611
|
+
currentTokenCount: currentContextTokens,
|
|
597
612
|
threshold: dynamicCompactThreshold,
|
|
598
613
|
targetSize: predictiveTargetSize,
|
|
599
614
|
tokenBudget: args.tokenBudget,
|
|
@@ -803,6 +818,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
803
818
|
});
|
|
804
819
|
await performAfterTurnPredictiveCompaction({
|
|
805
820
|
sessionId,
|
|
821
|
+
messages,
|
|
806
822
|
tokenBudget: args.tokenBudget,
|
|
807
823
|
currentTokenCount,
|
|
808
824
|
});
|
|
@@ -818,6 +834,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
818
834
|
});
|
|
819
835
|
await performAfterTurnPredictiveCompaction({
|
|
820
836
|
sessionId,
|
|
837
|
+
messages,
|
|
821
838
|
tokenBudget: args.tokenBudget,
|
|
822
839
|
currentTokenCount,
|
|
823
840
|
});
|
package/dist/index.js
CHANGED
|
@@ -33927,6 +33927,19 @@ function buildBudgetFallbackContext(messages, tokenBudget) {
|
|
|
33927
33927
|
function resolvePredictiveCompactionTokenCount(args) {
|
|
33928
33928
|
return normalizeCurrentTokenCount(args.currentTokenCount) ?? approximateMessagesTokens(args.messages) + approximateTokenCount(args.prompt ?? "");
|
|
33929
33929
|
}
|
|
33930
|
+
function resolveAfterTurnPredictiveCompactionTokenCount(args) {
|
|
33931
|
+
const currentTokenCount = normalizeCurrentTokenCount(args.currentTokenCount);
|
|
33932
|
+
const forwardedMessageTokens = normalizeCurrentTokenCount(
|
|
33933
|
+
approximateMessagesTokens(args.messages)
|
|
33934
|
+
);
|
|
33935
|
+
if (currentTokenCount == null) {
|
|
33936
|
+
return forwardedMessageTokens;
|
|
33937
|
+
}
|
|
33938
|
+
if (forwardedMessageTokens == null) {
|
|
33939
|
+
return currentTokenCount;
|
|
33940
|
+
}
|
|
33941
|
+
return Math.max(currentTokenCount, forwardedMessageTokens);
|
|
33942
|
+
}
|
|
33930
33943
|
function normalizeKernelMessage(message) {
|
|
33931
33944
|
return {
|
|
33932
33945
|
role: message.role,
|
|
@@ -34184,18 +34197,22 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
34184
34197
|
}
|
|
34185
34198
|
async function performAfterTurnPredictiveCompaction(args) {
|
|
34186
34199
|
const dynamicCompactThreshold = getDynamicCompactThreshold(args.tokenBudget);
|
|
34187
|
-
const
|
|
34200
|
+
const currentContextTokens = resolveAfterTurnPredictiveCompactionTokenCount({
|
|
34188
34201
|
currentTokenCount: args.currentTokenCount,
|
|
34202
|
+
messages: args.messages
|
|
34203
|
+
});
|
|
34204
|
+
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
34205
|
+
currentTokenCount: currentContextTokens,
|
|
34189
34206
|
threshold: dynamicCompactThreshold
|
|
34190
34207
|
});
|
|
34191
|
-
if (
|
|
34208
|
+
if (currentContextTokens == null || dynamicCompactThreshold == null || predictiveTargetSize == null) {
|
|
34192
34209
|
return;
|
|
34193
34210
|
}
|
|
34194
34211
|
logPredictiveCompactionAttempt({
|
|
34195
34212
|
logger,
|
|
34196
34213
|
phase: "afterTurn",
|
|
34197
34214
|
sessionId: args.sessionId,
|
|
34198
|
-
currentTokenCount:
|
|
34215
|
+
currentTokenCount: currentContextTokens,
|
|
34199
34216
|
threshold: dynamicCompactThreshold,
|
|
34200
34217
|
targetSize: predictiveTargetSize,
|
|
34201
34218
|
tokenBudget: args.tokenBudget
|
|
@@ -34205,13 +34222,13 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
34205
34222
|
targetSize: predictiveTargetSize,
|
|
34206
34223
|
tokenBudget: args.tokenBudget,
|
|
34207
34224
|
force: true,
|
|
34208
|
-
currentTokenCount:
|
|
34225
|
+
currentTokenCount: currentContextTokens
|
|
34209
34226
|
});
|
|
34210
34227
|
logPredictiveCompactionOutcome({
|
|
34211
34228
|
logger,
|
|
34212
34229
|
phase: "afterTurn",
|
|
34213
34230
|
sessionId: args.sessionId,
|
|
34214
|
-
currentTokenCount:
|
|
34231
|
+
currentTokenCount: currentContextTokens,
|
|
34215
34232
|
threshold: dynamicCompactThreshold,
|
|
34216
34233
|
targetSize: predictiveTargetSize,
|
|
34217
34234
|
tokenBudget: args.tokenBudget,
|
|
@@ -34428,6 +34445,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
34428
34445
|
});
|
|
34429
34446
|
await performAfterTurnPredictiveCompaction({
|
|
34430
34447
|
sessionId,
|
|
34448
|
+
messages,
|
|
34431
34449
|
tokenBudget: args.tokenBudget,
|
|
34432
34450
|
currentTokenCount
|
|
34433
34451
|
});
|
|
@@ -34443,6 +34461,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
34443
34461
|
});
|
|
34444
34462
|
await performAfterTurnPredictiveCompaction({
|
|
34445
34463
|
sessionId,
|
|
34464
|
+
messages,
|
|
34446
34465
|
tokenBudget: args.tokenBudget,
|
|
34447
34466
|
currentTokenCount
|
|
34448
34467
|
});
|
package/openclaw.plugin.json
CHANGED