Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6129,3 +6129,25 @@ describe("CodexAdapterV2 post-settle continuation", () => {
);
});
});

describe("codexDynamicToolOutput", () => {
it("translates inputImage data URLs into image blocks the work log can serve", () => {
const output = CodexAdapterV2.codexDynamicToolOutput({
type: "dynamicToolCall",
id: "exec-image",
tool: "exec",
status: "completed",
arguments: {},
contentItems: [
{ type: "inputText", text: "Script completed" },
{ type: "inputImage", imageUrl: "data:image/png;base64,iVBORw0KGgo=" },
{ type: "inputImage", imageUrl: "https://example.test/remote.png" },
],
} as never);
assert.deepEqual(output, [
{ type: "inputText", text: "Script completed" },
{ type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" },
{ type: "inputImage", imageUrl: "https://example.test/remote.png" },
]);
});
});
20 changes: 18 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,27 @@ function codexMcpAppResourceUri(item: CodexDynamicToolItem): string | undefined
return typeof uri === "string" && uri.startsWith(MCP_APP_RESOURCE_SCHEME) ? uri : undefined;
}

function codexDynamicToolOutput(
const CODEX_IMAGE_DATA_URL = /^data:(image\/[a-z0-9.+-]+);base64,([A-Za-z0-9+/=]+)$/i;

/**
* Codex reports image output as `inputImage` with a data URL; the work log and
* asset routes only recognize the `image` block shape, so translate it here.
*/
function codexContentItemImage<T>(item: T): T | { type: "image"; mimeType: string; data: string } {
if (typeof item !== "object" || item === null) return item;
const { type, imageUrl } = item as { type?: unknown; imageUrl?: unknown };
if (type !== "inputImage" || typeof imageUrl !== "string") return item;
const match = CODEX_IMAGE_DATA_URL.exec(imageUrl);
return match?.[1] && match[2]
? { type: "image", mimeType: match[1].toLowerCase(), data: match[2] }
: item;
}

export function codexDynamicToolOutput(
item: Extract<CodexDynamicToolItem, { readonly type: "dynamicToolCall" }>,
): unknown | undefined {
if (item.contentItems !== null && item.contentItems !== undefined) {
return item.contentItems;
return item.contentItems.map(codexContentItemImage);
}
return item.success === false ? { success: false } : undefined;
}
Expand Down
Loading