fix(responses): keep a placeholder message when skipped items leave none

An input of only a replayed image_generation_call is skipped item by item,
which left messages:[] and an upstream 400. Apply the empty-input placeholder
after conversion too, when no message survived.
This commit is contained in:
serenity
2026-11-19 00:12:21 -03:00
committed by diegosouzapw
parent 6241ac2524
commit 00e66d2c3e
2 changed files with 13 additions and 0 deletions

View File

@@ -938,6 +938,12 @@ export function openaiResponsesToOpenAIRequest(
];
});
// Upstream providers reject messages:[] (see the empty-input placeholder above). Skipped
// replay items or dropped tool results can still leave nothing: keep the same placeholder.
if (Array.isArray(result.messages) && result.messages.length === 0) {
result.messages = [{ role: "user", content: "..." }];
}
// Translate tool_choice object format: Responses {type,name} → Chat {type,function:{name}}
if (
result.tool_choice &&

View File

@@ -55,3 +55,10 @@ test("other unrepresentable input items are still rejected", () => {
);
}
});
test("an input of only a replayed image_generation_call still sends one message", () => {
const result = translate([
{ type: "image_generation_call", id: "ig_3", status: "completed", result: "Zml4dHVyZQ==" },
]) as { messages?: Array<{ role?: string; content?: unknown }> };
assert.deepEqual(result.messages, [{ role: "user", content: "..." }]);
});