Files
oh-my-pi/packages/agent/test/snapcompact-frames.test.ts
can1357 d820cf75bb feat: implemented token tracking and metadata options for compaction summaries
- Added `CompactionSummaryMessageOptions` interface to support optional fields and metadata in compaction summary messages.
- Included compaction method labels and before-after amount badge rendering in compaction views.
- Updated session maintenance and compaction methods to track and compute post-compaction token counts.
- Updated calls across agent and coding-agent packages to use the new compaction options object.
2026-08-20 07:18:43 +02:00

37 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import type { ImageContent } from "@oh-my-pi/pi-ai";
import * as snapcompact from "@oh-my-pi/snapcompact";
import { createCompactionSummaryMessage, defaultConvertToLlm } from "../src/compaction/messages";
import { Tokenizer } from "../src/tokenizer";
const tokenizer = new Tokenizer();
describe("compaction summary message with snapcompact frames", () => {
const images: ImageContent[] = [
{ type: "image", data: "ZmFrZQ==", mimeType: "image/png" },
{ type: "image", data: "ZmFrZTI=", mimeType: "image/png" },
];
it("countMessage charges per attached frame", () => {
const bare = createCompactionSummaryMessage("summary text", 1000, new Date().toISOString());
const withFrames = createCompactionSummaryMessage("summary text", 1000, new Date().toISOString(), { images });
expect(tokenizer.countMessage(withFrames) - tokenizer.countMessage(bare)).toBe(
2 * snapcompact.FRAME_TOKEN_ESTIMATE,
);
});
it("defaultConvertToLlm appends frames as image blocks after the summary text", () => {
const message = createCompactionSummaryMessage("the snapcompact archive", 1000, new Date().toISOString(), {
images,
});
const [converted] = defaultConvertToLlm([message]);
expect(converted.role).toBe("user");
const content = converted.content as Array<{ type: string; text?: string; data?: string }>;
expect(content.length).toBe(3);
expect(content[0].type).toBe("text");
expect(content[0].text).toContain("the snapcompact archive");
expect(content[1]).toEqual(images[0]);
expect(content[2]).toEqual(images[1]);
});
});