Skip to content

Commit a71b46d

Browse files
chitalianJustin Torreclaude
authored
fix: properly render DALL-E/gpt-image responses in request drawer (#5542)
- Add `role: "assistant"` to response messages so ChatOnlyView displays them - Add `request.messages` array with user prompt for proper Chat component rendering - Add `data:image/png;base64,` prefix for base64 images so ImageContent can process them The DALL-E mapper was not properly structuring messages for the UI: 1. Response messages lacked a `role` field, causing them to be filtered out 2. Request didn't include a `messages` array, so the user prompt wasn't shown 3. Raw base64 strings from OpenAI's `b64_json` weren't being recognized as images Co-authored-by: Justin Torre <justin@Justins-MacBook-Pro.local> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bcabf39 commit a71b46d

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

packages/__tests__/llm-mapper/dalle.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@ describe("mapDalleRequest", () => {
3535
json_schema: {},
3636
},
3737
size: "1024x1024",
38+
messages: [
39+
{
40+
role: "user",
41+
content: "A beautiful image of a cat",
42+
_type: "message",
43+
},
44+
],
3845
});
3946

4047
// Test response schema
4148
expect(result.schema.response!.messages![0]).toEqual({
49+
role: "assistant",
4250
content:
4351
"Render a detailed image of a majestic cat poised gracefully on a sun-dappled garden path...",
4452
_type: "image",
45-
image_url: "iVB=",
53+
image_url: "data:image/png;base64,iVB=",
4654
});
4755

4856
// Test preview
@@ -61,7 +69,7 @@ describe("mapDalleRequest", () => {
6169
"Render a detailed image of a majestic cat poised gracefully on a sun-dappled garden path...",
6270
role: "assistant",
6371
_type: "image",
64-
image_url: "iVB=",
72+
image_url: "data:image/png;base64,iVB=",
6573
});
6674
});
6775

@@ -98,6 +106,7 @@ describe("mapDalleRequest", () => {
98106
expect(result.preview.request).toBe("");
99107
expect(result.preview.response).toBe("");
100108
expect(result.schema.response!.messages![0]).toEqual({
109+
role: "assistant",
101110
content: "",
102111
_type: "image",
103112
image_url: "",

packages/llm-mapper/mappers/openai/dalle.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ export const mapDalleRequest: MapperFn<DalleRequestBody, any> = ({
3232
statusCode = 200,
3333
model,
3434
}) => {
35+
// Format the image URL properly - add data URL prefix for base64 images
36+
const rawImageData =
37+
response?.data?.[0]?.b64_json || response?.data?.[0]?.url || "";
38+
const imageUrl = rawImageData
39+
? rawImageData.startsWith("http://") || rawImageData.startsWith("https://")
40+
? rawImageData
41+
: `data:image/png;base64,${rawImageData}`
42+
: "";
43+
3544
const llmSchema: LlmSchema = {
3645
request: {
3746
model: request.model,
@@ -44,14 +53,24 @@ export const mapDalleRequest: MapperFn<DalleRequestBody, any> = ({
4453
json_schema: {},
4554
}
4655
: undefined,
56+
// Add messages array for proper UI rendering
57+
messages: request.prompt
58+
? [
59+
{
60+
role: "user",
61+
content: request.prompt,
62+
_type: "message",
63+
},
64+
]
65+
: [],
4766
},
4867
response: {
4968
messages: [
5069
{
70+
role: "assistant",
5171
content: response?.data?.[0]?.revised_prompt || "",
5272
_type: "image",
53-
image_url:
54-
response?.data?.[0]?.b64_json || response?.data?.[0]?.url || "",
73+
image_url: imageUrl,
5574
},
5675
],
5776
model: model,
@@ -73,8 +92,7 @@ export const mapDalleRequest: MapperFn<DalleRequestBody, any> = ({
7392
content: response?.data?.[0]?.revised_prompt || "",
7493
role: "assistant",
7594
_type: "image",
76-
image_url:
77-
response?.data?.[0]?.b64_json || response?.data?.[0]?.url || "",
95+
image_url: imageUrl,
7896
},
7997
],
8098
},

0 commit comments

Comments
 (0)