fix(kiro): preserve inline images in OpenAI MITM
Forward Kiro userInputMessage.images as OpenAI-compatible image_url content parts.
This commit is contained in:
@@ -180,6 +180,14 @@ function withInitialFrame(state, frames) {
|
||||
|
||||
// ─── CodeWhisperer → OpenAI conversion ───────────────────────────────────────
|
||||
|
||||
const INLINE_IMAGE_MIME_BY_FORMAT = new Map([
|
||||
["png", "image/png"],
|
||||
["jpeg", "image/jpeg"],
|
||||
["jpg", "image/jpeg"],
|
||||
["gif", "image/gif"],
|
||||
["webp", "image/webp"],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Safely stringify a tool-call input value.
|
||||
* OpenAI expects `function.arguments` to be a JSON string, never an object.
|
||||
@@ -214,9 +222,32 @@ function convertUserInputMessage(uim) {
|
||||
});
|
||||
}
|
||||
|
||||
const images = Array.isArray(uim.images) ? uim.images : [];
|
||||
const imageParts = images
|
||||
.filter(image => image !== null
|
||||
&& typeof image === "object"
|
||||
&& !Array.isArray(image)
|
||||
&& image.source !== null
|
||||
&& typeof image.source === "object"
|
||||
&& !Array.isArray(image.source)
|
||||
&& INLINE_IMAGE_MIME_BY_FORMAT.has(image.format)
|
||||
&& typeof image.source.bytes === "string"
|
||||
&& image.source.bytes.length > 0)
|
||||
.map(image => ({
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: `data:${INLINE_IMAGE_MIME_BY_FORMAT.get(image.format)};base64,${image.source.bytes}`,
|
||||
},
|
||||
}));
|
||||
|
||||
// Emit user text only if it exists alongside OR when there are no tool results
|
||||
const text = (uim.content || "").trim();
|
||||
if (text || toolResults.length === 0) {
|
||||
if (imageParts.length > 0) {
|
||||
const content = [];
|
||||
if (text) content.push({ type: "text", text });
|
||||
content.push(...imageParts);
|
||||
out.push({ role: "user", content });
|
||||
} else if (text || toolResults.length === 0) {
|
||||
out.push({ role: "user", content: text });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user