fix(translator): preserve developer instructions in openai-responses conversion (#2434)

Map role="developer" messages to top-level instructions alongside
role="system" in openaiToOpenAIResponsesRequest. Previously developer
messages matched no branch and were silently dropped from the Responses
request, losing GPT-5/Codex system-level prompts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
deranalabs
2026-07-07 11:48:55 +07:00
committed by decolua
parent bf7da67859
commit a3cd7c82bc
2 changed files with 18 additions and 3 deletions

View File

@@ -221,13 +221,14 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
const messages = body.messages || [];
for (const msg of messages) {
if (msg.role === ROLE.SYSTEM) {
// Use first system message as instructions
if (msg.role === ROLE.SYSTEM || msg.role === ROLE.DEVELOPER) {
// Use the first instruction-bearing message as instructions.
// OpenAI recommends role="developer" for GPT-5/Codex as the system-level prompt.
if (!hasSystemMessage) {
result.instructions = typeof msg.content === "string" ? msg.content : "";
hasSystemMessage = true;
}
continue; // Skip system messages in input
continue; // Skip instruction messages in input
}
// Convert user/assistant messages to input items

View File

@@ -46,6 +46,20 @@ describe("Codex CLI Responses → OpenAI", () => {
});
describe("OpenAI → Codex Responses (reverse)", () => {
it("maps developer messages to Responses API instructions", () => {
const out = O2R({
messages: [
{ role: "developer", content: "Follow the project rules." },
{ role: "user", content: "Hello" },
],
});
expect(out.instructions).toBe("Follow the project rules.");
expect(out.input).toEqual([
{ type: "message", role: "user", content: [{ type: "input_text", text: "Hello" }] },
]);
});
// openai-responses.js:13 — clampCallId NOT applied on Responses→Chat; but here Chat→Responses must clamp
it("call_id longer than 64 chars is clamped", () => {
const longId = "call_" + "x".repeat(80);