GeezerVison is showing github.com — fix(server): show Codex tool-output images inline (#23284) · pingdotgg/t3code@f021c21
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2/Adapters
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,7 @@ import * as Effect from "effect/Effect"; | 42 | 42 | import * as Predicate from "effect/Predicate"; | 43 | 43 | import * as FileSystem from "effect/FileSystem"; | 44 | 44 | import { MCP_APP_OUTPUT_KEY, readMcpAppReference } from "@t3tools/shared/mcpApp"; | | 45 | +import { toolOutputImages } from "@t3tools/shared/toolOutput"; | 45 | 46 | import { resolveAttachmentPathById } from "../../attachmentStore.ts"; | 46 | 47 | import * as Fiber from "effect/Fiber"; | 47 | 48 | import * as Layer from "effect/Layer"; | @@ -8375,3 +8376,30 @@ describe("CodexAdapterV2 post-settle continuation", () => { | 8375 | 8376 | ); | 8376 | 8377 | }); | 8377 | 8378 | }); | | 8379 | + | | 8380 | +describe("codexDynamicToolOutput", () => { | | 8381 | + it("translates inputImage data URLs into image blocks the work log can serve", () => { | | 8382 | + const output = CodexAdapterV2.codexDynamicToolOutput({ | | 8383 | + type: "dynamicToolCall", | | 8384 | + id: "exec-image", | | 8385 | + tool: "exec", | | 8386 | + status: "completed", | | 8387 | + arguments: {}, | | 8388 | + contentItems: [ | | 8389 | + { type: "inputText", text: "Script completed" }, | | 8390 | + { type: "inputImage", imageUrl: "data:image/png;base64,iVBORw0KGgo=" }, | | 8391 | + { type: "inputImage", imageUrl: "https://example.test/remote.png" }, | | 8392 | + { type: "inputImage", imageUrl: "data:image/png;base64," }, | | 8393 | + { type: "inputAudio", audioUrl: "data:audio/wav;base64,AAAA" }, | | 8394 | + ], | | 8395 | + }); | | 8396 | + assert.deepEqual(toolOutputImages(output), [{ mimeType: "image/png", data: "iVBORw0KGgo=" }]); | | 8397 | + assert.deepEqual(output, [ | | 8398 | + { type: "inputText", text: "Script completed" }, | | 8399 | + { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" }, | | 8400 | + { type: "inputImage", imageUrl: "https://example.test/remote.png" }, | | 8401 | + { type: "inputImage", imageUrl: "data:image/png;base64," }, | | 8402 | + { type: "inputAudio", audioUrl: "data:audio/wav;base64,AAAA" }, | | 8403 | + ]); | | 8404 | + }); | | 8405 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -491,11 +491,19 @@ function codexMcpAppResourceUri(item: CodexDynamicToolItem): string | undefined | 491 | 491 | return typeof uri === "string" && uri.startsWith(MCP_APP_RESOURCE_SCHEME) ? uri : undefined; | 492 | 492 | } | 493 | 493 |
| 494 | | -function codexDynamicToolOutput( | | 494 | +const CODEX_IMAGE_DATA_URL = /^data:(image\/[a-z0-9.+-]+);base64,([A-Za-z0-9+/=]+)$/i; | | 495 | + | | 496 | +export function codexDynamicToolOutput( | 495 | 497 | item: Extract<CodexDynamicToolItem, { readonly type: "dynamicToolCall" }>, | 496 | 498 | ): unknown | undefined { | 497 | 499 | if (item.contentItems !== null && item.contentItems !== undefined) { | 498 | | - return item.contentItems; | | 500 | + return item.contentItems.map((content) => { | | 501 | + if (content.type !== "inputImage") return content; | | 502 | + const match = CODEX_IMAGE_DATA_URL.exec(content.imageUrl); | | 503 | + return match?.[1] && match[2] | | 504 | + ? { type: "image", mimeType: match[1].toLowerCase(), data: match[2] } | | 505 | + : content; | | 506 | + }); | 499 | 507 | } | 500 | 508 | return item.success === false ? { success: false } : undefined; | 501 | 509 | } | |
|