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

An input of only a blank-id custom_tool_call and its blank-id output now drops
both, 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:17:47 -03:00
committed by diegosouzapw
parent 8274bfbc3a
commit eadb47a9d4
2 changed files with 14 additions and 0 deletions

View File

@@ -939,6 +939,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

@@ -94,3 +94,11 @@ test("Responses -> Chat: a custom_tool_call with a call_id is untouched", () =>
]
);
});
test("Responses -> Chat: when the blank-id pair is the whole input, one placeholder message stays", () => {
const messages = toChat([
{ type: "custom_tool_call", call_id: "", name: "apply_patch", input: "x" },
{ type: "custom_tool_call_output", call_id: "", output: "patched text" },
]);
assert.deepEqual(messages, [{ role: "user", content: "..." }]);
});