@joshuaswarren/openclaw-engram 9.0.87 → 9.0.88
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/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42046,7 +42046,22 @@ Use this context naturally when relevant. Never quote or expose this memory cont
|
|
|
42046
42046
|
try {
|
|
42047
42047
|
if (orchestrator.lcmEngine?.enabled) {
|
|
42048
42048
|
try {
|
|
42049
|
-
|
|
42049
|
+
let tokensBefore = 0;
|
|
42050
|
+
if (typeof event.tokenCount === "number") {
|
|
42051
|
+
tokensBefore = event.tokenCount;
|
|
42052
|
+
} else if (Array.isArray(event.messages)) {
|
|
42053
|
+
for (const msg of event.messages) {
|
|
42054
|
+
if (typeof msg.content === "string") {
|
|
42055
|
+
tokensBefore += estimateTokens2(msg.content);
|
|
42056
|
+
} else if (Array.isArray(msg.content)) {
|
|
42057
|
+
for (const block of msg.content) {
|
|
42058
|
+
if (typeof block === "string") tokensBefore += estimateTokens2(block);
|
|
42059
|
+
else if (block && typeof block === "object" && typeof block.text === "string")
|
|
42060
|
+
tokensBefore += estimateTokens2(block.text);
|
|
42061
|
+
}
|
|
42062
|
+
}
|
|
42063
|
+
}
|
|
42064
|
+
}
|
|
42050
42065
|
lcmTokensBefore.set(sessionKey, tokensBefore);
|
|
42051
42066
|
await orchestrator.lcmEngine.preCompactionFlush(sessionKey);
|
|
42052
42067
|
} catch (lcmErr) {
|
|
@@ -42079,7 +42094,18 @@ Use this context naturally when relevant. Never quote or expose this memory cont
|
|
|
42079
42094
|
try {
|
|
42080
42095
|
if (orchestrator.lcmEngine?.enabled) {
|
|
42081
42096
|
try {
|
|
42082
|
-
|
|
42097
|
+
let tokensAfter = 0;
|
|
42098
|
+
if (typeof event.tokenCount === "number") {
|
|
42099
|
+
tokensAfter = event.tokenCount;
|
|
42100
|
+
} else {
|
|
42101
|
+
const storedBefore = lcmTokensBefore.get(sessionKey) ?? 0;
|
|
42102
|
+
const msgCountAfter = typeof event.messageCount === "number" ? event.messageCount : 0;
|
|
42103
|
+
const compacted = typeof event.compactedCount === "number" ? event.compactedCount : 0;
|
|
42104
|
+
const msgCountBefore = msgCountAfter + compacted;
|
|
42105
|
+
if (storedBefore > 0 && msgCountBefore > 0) {
|
|
42106
|
+
tokensAfter = Math.round(storedBefore * (msgCountAfter / msgCountBefore));
|
|
42107
|
+
}
|
|
42108
|
+
}
|
|
42083
42109
|
const tokensBefore = lcmTokensBefore.get(sessionKey) ?? 0;
|
|
42084
42110
|
lcmTokensBefore.delete(sessionKey);
|
|
42085
42111
|
await orchestrator.lcmEngine.recordCompaction(sessionKey, tokensBefore, tokensAfter);
|