mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
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:
committed by
decolua
co-authored by
Cursor
parent
bf7da67859
commit
a3cd7c82bc
@@ -221,13 +221,14 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
|
|||||||
const messages = body.messages || [];
|
const messages = body.messages || [];
|
||||||
|
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
if (msg.role === ROLE.SYSTEM) {
|
if (msg.role === ROLE.SYSTEM || msg.role === ROLE.DEVELOPER) {
|
||||||
// Use first system message as instructions
|
// Use the first instruction-bearing message as instructions.
|
||||||
|
// OpenAI recommends role="developer" for GPT-5/Codex as the system-level prompt.
|
||||||
if (!hasSystemMessage) {
|
if (!hasSystemMessage) {
|
||||||
result.instructions = typeof msg.content === "string" ? msg.content : "";
|
result.instructions = typeof msg.content === "string" ? msg.content : "";
|
||||||
hasSystemMessage = true;
|
hasSystemMessage = true;
|
||||||
}
|
}
|
||||||
continue; // Skip system messages in input
|
continue; // Skip instruction messages in input
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert user/assistant messages to input items
|
// Convert user/assistant messages to input items
|
||||||
|
|||||||
@@ -46,6 +46,20 @@ describe("Codex CLI Responses → OpenAI", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("OpenAI → Codex Responses (reverse)", () => {
|
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
|
// 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", () => {
|
it("call_id longer than 64 chars is clamped", () => {
|
||||||
const longId = "call_" + "x".repeat(80);
|
const longId = "call_" + "x".repeat(80);
|
||||||
|
|||||||
Reference in New Issue
Block a user