Keep image view paths when pruning activity payloads

Payload pruning (#4622) stripped every item field outside the command
allowlist, so image view activities reached clients without the path and
the chat gallery rendered nothing. Preserve the item type and path while
still dropping the base64 image bytes.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and Gabriel De Andrade committed 2026-07-29 16:58:58 -04:00
1 parent cf121a7260
commit efede3661a
2 files changed
+89 -1

No files matched your search

@@ -0,0 +1,63 @@
import { EventId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts";
import { describe, expect, it } from "@effect/vitest";
import { projectActivityPayload } from "./ActivityPayloadProjection.ts";
const makeImageActivity = (item: Record<string, unknown>): OrchestrationThreadActivity => ({
id: EventId.make("activity-image-1"),
tone: "tool",
kind: "tool.completed",
summary: "Image view",
payload: {
itemType: "image_view",
detail: "/tmp/generated.png",
data: { completedAtMs: 1, item },
},
turnId: TurnId.make("turn-1"),
createdAt: "2026-07-27T21:17:50.000Z",
});
const projectedItem = (activity: OrchestrationThreadActivity): Record<string, unknown> => {
const payload = activity.payload as { data?: { item?: Record<string, unknown> } };
return payload.data?.item ?? {};
};
describe("projectActivityPayload", () => {
it("keeps the saved path for generated images while pruning the base64 result", () => {
const projected = projectActivityPayload(
makeImageActivity({
id: "call-1",
type: "imageGeneration",
savedPath: "/Users/test/.codex/generated_images/thread/call.png",
revisedPrompt: "a prompt",
result: "iVBORw0KGgoAAAANSUhEUg",
status: "completed",
}),
);
const item = projectedItem(projected);
expect(item.savedPath).toBe("/Users/test/.codex/generated_images/thread/call.png");
expect(item.type).toBe("imageGeneration");
// The generated image bytes are megabytes per activity and unread by clients.
expect(item.result).toBeUndefined();
expect(item.revisedPrompt).toBeUndefined();
});
it("keeps the viewed path for image view items", () => {
const projected = projectActivityPayload(
makeImageActivity({ id: "call-2", type: "imageView", path: "/tmp/screenshot.png" }),
);
const item = projectedItem(projected);
expect(item.path).toBe("/tmp/screenshot.png");
expect(item.type).toBe("imageView");
});
it("still prunes unrelated tool item payloads", () => {
const projected = projectActivityPayload(
makeImageActivity({ id: "call-3", type: "somethingElse", secret: "value" }),
);
expect(projectedItem(projected)).toEqual({});
});
});
@@ -104,6 +104,31 @@ function projectCommandData(data: Record<string, unknown>): Record<string, unkno
return Object.keys(projectedItem).length > 0 ? projectedItem : undefined;
}
/**
* Image view items carry the on-disk path both clients need to render the
* output gallery. The generated image itself also rides along in `result` as
* base64 — that stays pruned, since it is megabytes per activity and no client
* reads it.
*/
function projectImageViewData(data: Record<string, unknown>): Record<string, unknown> | undefined {
const item = asRecord(data.item);
if (!item) {
return undefined;
}
if (item.type !== "imageView" && item.type !== "imageGeneration") {
return undefined;
}
const projectedItem: Record<string, unknown> = { type: item.type };
if (asTrimmedString(item.path)) {
projectedItem.path = item.path;
}
if (asTrimmedString(item.savedPath)) {
projectedItem.savedPath = item.savedPath;
}
return Object.keys(projectedItem).length > 1 ? projectedItem : undefined;
}
function summarizeToolTextOutput(value: string): string | null {
const lines: string[] = [];
for (const rawLine of value.split(/\r?\n/u)) {
@@ -165,7 +190,7 @@ export function projectActivityPayload(
}
const projectedData: Record<string, unknown> = {};
const item = projectCommandData(data);
const item = projectCommandData(data) ?? projectImageViewData(data);
if (item) {
projectedData.item = item;
}