TypeScript
fix(server): show Codex tool-output images inline (#23284)
achose369f021c21da2f4
diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsindex e50b6689ef1..a975b8d7272 100644--- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts@@ -42,6 +42,7 @@ import * as Effect from "effect/Effect";import * as Predicate from "effect/Predicate";import * as FileSystem from "effect/FileSystem";import { MCP_APP_OUTPUT_KEY, readMcpAppReference } from "@t3tools/shared/mcpApp";+import { toolOutputImages } from "@t3tools/shared/toolOutput";import { resolveAttachmentPathById } from "../../attachmentStore.ts";import * as Fiber from "effect/Fiber";import * as Layer from "effect/Layer";@@ -8375,3 +8376,30 @@ 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" },+ { type: "inputImage", imageUrl: "data:image/png;base64," },+ { type: "inputAudio", audioUrl: "data:audio/wav;base64,AAAA" },+ ],+ });+ assert.deepEqual(toolOutputImages(output), [{ mimeType: "image/png", data: "iVBORw0KGgo=" }]);+ assert.deepEqual(output, [+ { type: "inputText", text: "Script completed" },+ { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" },+ { type: "inputImage", imageUrl: "https://example.test/remote.png" },+ { type: "inputImage", imageUrl: "data:image/png;base64," },+ { type: "inputAudio", audioUrl: "data:audio/wav;base64,AAAA" },+ ]);+ });+});diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsindex 2e2fdd4331c..96bfdf40b13 100644--- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts+++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts@@ -491,11 +491,19 @@ function codexMcpAppResourceUri(item: CodexDynamicToolItem): string | undefinedreturn 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;++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((content) => {+ if (content.type !== "inputImage") return content;+ const match = CODEX_IMAGE_DATA_URL.exec(content.imageUrl);+ return match?.[1] && match[2]+ ? { type: "image", mimeType: match[1].toLowerCase(), data: match[2] }+ : content;+ });}return item.success === false ? { success: false } : undefined;}