mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-28 17:53:36 +00:00
refactor(agents): remove unused runtime transcript rotation wrapper
This commit is contained in:
@@ -6,7 +6,6 @@ import { SessionManager } from "openclaw/plugin-sdk/agent-sessions";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { makeAgentAssistantMessage } from "../test-helpers/agent-message-fixtures.js";
|
||||
import {
|
||||
rotateRuntimeTranscriptAfterCompaction,
|
||||
rotateTranscriptAfterCompaction,
|
||||
rotateTranscriptFileAfterCompaction,
|
||||
shouldRotateCompactionTranscript,
|
||||
@@ -118,24 +117,6 @@ function createCompactedSession(sessionDir: string): {
|
||||
}
|
||||
|
||||
describe("rotateTranscriptAfterCompaction", () => {
|
||||
it("does not create session metadata for missing runtime transcripts", async () => {
|
||||
const dir = await createTmpDir();
|
||||
const storePath = path.join(dir, "sessions.json");
|
||||
await fs.writeFile(storePath, "{}\n", "utf8");
|
||||
|
||||
const result = await rotateRuntimeTranscriptAfterCompaction({
|
||||
scope: {
|
||||
agentId: "main",
|
||||
sessionId: "missing-session",
|
||||
sessionKey: "agent:main:missing",
|
||||
storePath,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.rotated).toBe(false);
|
||||
expect(await fs.readFile(storePath, "utf8")).toBe("{}\n");
|
||||
});
|
||||
|
||||
it("can rotate a persisted transcript without opening a manager", async () => {
|
||||
const dir = await createTmpDir();
|
||||
const { sessionFile } = createCompactedSession(dir);
|
||||
|
||||
@@ -14,10 +14,6 @@ import {
|
||||
TranscriptFileState,
|
||||
writeTranscriptFileAtomic,
|
||||
} from "./transcript-file-state.js";
|
||||
import {
|
||||
resolveRuntimeTranscriptReadTarget,
|
||||
type RuntimeTranscriptScope,
|
||||
} from "./transcript-runtime-state.js";
|
||||
|
||||
type ReadonlySessionManagerForRotation = Pick<
|
||||
TranscriptFileState,
|
||||
@@ -103,33 +99,6 @@ export async function rotateTranscriptFileAfterCompaction(params: {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a runtime transcript after compaction using agent/session identity.
|
||||
*/
|
||||
export async function rotateRuntimeTranscriptAfterCompaction(params: {
|
||||
sessionManager?: ReadonlySessionManagerForRotation;
|
||||
scope: RuntimeTranscriptScope;
|
||||
now?: () => Date;
|
||||
}): Promise<CompactionTranscriptRotation> {
|
||||
const target = await resolveRuntimeTranscriptReadTarget(params.scope);
|
||||
let sessionManager = params.sessionManager;
|
||||
if (!sessionManager) {
|
||||
try {
|
||||
sessionManager = await readTranscriptFileState(target.sessionFile);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "ENOENT") {
|
||||
return { rotated: false, reason: "missing session file" };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return await rotateTranscriptAfterCompaction({
|
||||
sessionManager,
|
||||
sessionFile: target.sessionFile,
|
||||
...(params.now ? { now: params.now } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
function findLatestCompactionIndex(entries: SessionEntry[]): number {
|
||||
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
||||
if (entries[index]?.type === "compaction") {
|
||||
|
||||
Reference in New Issue
Block a user