UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

30 lines (29 loc) • 1.27 kB
//#region src/auto-reply/reply/agent-runner-compaction-accounting.ts function hasSameCompactionWriter(e, t) { return e !== void 0 && e.agentId === t.agentId && e.sessionKey === t.sessionKey && e.storePath === t.storePath && e.lifecycleRevision === t.lifecycleRevision && e.activeWriterRunId === t.activeWriterRunId; } /** A later opaque candidate may lose freshness, but must never fabricate it. */ function invalidateTurnCompactionContext(e) { e.durable = e.durable.map((e) => ({ ...e, currentContextSnapshot: { tokens: void 0 } })); } /** Fold same-writer facts; only an ordered snapshot may refresh context. */ function recordTurnCompaction(e, t) { if (t.count < 0) return; e.count += t.count; if (t.kind !== "durable") return; const n = e.durable.findIndex(({ target: e }) => hasSameCompactionWriter(e, t.target)); const r = e.durable[n]; if (!r && t.count === 0) return; if (r) e.durable.splice(n, 1); e.durable.push({ ...t, count: (r?.count ?? 0) + t.count, currentContextSnapshot: t.currentContextSnapshot ?? r?.currentContextSnapshot, hostCompactionCommitted: t.hostCompactionCommitted || r?.hostCompactionCommitted }); } //#endregion export { invalidateTurnCompactionContext as n, recordTurnCompaction as r, hasSameCompactionWriter as t };