openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
25 lines (24 loc) • 953 B
JavaScript
import { x as parseDateFirstTimestampMs } from "./number-coercion-D6u-4YD8.mjs";
import { l as makeZeroUsageSnapshot } from "./usage-CHLnzpJG.mjs";
//#region src/agents/compaction-usage.ts
function stripStaleAssistantUsageBeforeLatestCompaction(e, t = {}) {
const n = e.findLastIndex((e) => e?.role === "compactionSummary");
const r = n !== -1;
if (!r && t.whenMissingCompactionSummary !== "zeroAssistantUsage") return e;
const i = parseDateFirstTimestampMs(e[n]?.timestamp);
let a = e;
for (let o = 0; o < e.length; o += 1) {
const s = e[o];
if (s?.role !== "assistant" || !s.usage || typeof s.usage !== "object") continue;
const c = parseDateFirstTimestampMs(s.timestamp);
if (!(!r || (i !== void 0 && c !== void 0 ? c <= i : o < n))) continue;
if (a === e && !t.mutate) a = [...e];
a[o] = {
...s,
usage: makeZeroUsageSnapshot()
};
}
return a;
}
//#endregion
export { stripStaleAssistantUsageBeforeLatestCompaction as t };