6b1ca33bf7
- Renamed all functions, types, and constants in @oh-my-pi/snapcompact to namespace-relative names (`snapcompactCompact` → `compact`, `renderSnapcompactFrames` → `renderMany`, `snapcompactFrameCount` → `frames`, `SnapcompactShape` → `Shape`, `SNAPCOMPACT_SHAPES` → `SHAPES`, …). - Converted every consumer to `import * as snapcompact` member access: `agent/compaction.ts`, `coding-agent` `agent-session.ts`/`session-manager.ts`/`snapcompact-inline.ts`, and all affected tests. - Renamed internal `geometry` locals to `geo` in `snapcompact.ts` to avoid TDZ collisions with the new `geometry` export. - Updated `docs/compaction.md` prose and added a Breaking Changes entry to the snapcompact changelog documenting the full rename map.
45 lines
1.6 KiB
TypeScript
45 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 { estimateTokens } from "../src/compaction/compaction";
|
|
import { createCompactionSummaryMessage, defaultConvertToLlm } from "../src/compaction/messages";
|
|
|
|
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("estimateTokens charges per attached frame", () => {
|
|
const bare = createCompactionSummaryMessage("summary text", 1000, new Date().toISOString());
|
|
const withFrames = createCompactionSummaryMessage(
|
|
"summary text",
|
|
1000,
|
|
new Date().toISOString(),
|
|
undefined,
|
|
undefined,
|
|
images,
|
|
);
|
|
expect(estimateTokens(withFrames) - estimateTokens(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(),
|
|
undefined,
|
|
undefined,
|
|
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]);
|
|
});
|
|
});
|