Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions open-sse/rtk/systemInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export function injectSystemPrompt(body, format, prompt) {
return;
default:
// OpenAI and OpenAI-shaped formats (responses/codex/cursor/kiro/ollama)
injectMessagesSystem(body, prompt);
injectMessagesSystem(body, prompt, format);
}
}

// OpenAI-shaped: messages[] (chat) or input[] (responses) or instructions (responses string)
function injectMessagesSystem(body, prompt) {
// OpenAI Responses API: top-level string field
if (typeof body.instructions === "string") {
function injectMessagesSystem(body, prompt, format) {
// OpenAI Responses API: Codex rejects instruction messages in input[]; use top-level instructions.
if (format === FORMATS.OPENAI_RESPONSES || format === FORMATS.OPENAI_RESPONSE || format === FORMATS.CODEX || typeof body.instructions === "string") {
body.instructions = body.instructions
? `${body.instructions}${SEP}${prompt}`
: prompt;
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/system-inject.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import { injectSystemPrompt } from "../../open-sse/rtk/systemInject.js";
import { FORMATS } from "../../open-sse/translator/formats.js";

describe("injectSystemPrompt", () => {
it("uses top-level instructions for openai-responses when instructions is absent (#2497)", () => {
const body = {
input: [
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "hi" }],
},
],
};

injectSystemPrompt(body, FORMATS.OPENAI_RESPONSES, "respond tersely");

expect(body.instructions).toBe("respond tersely");
expect(body.input).toEqual([
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "hi" }],
},
]);
});

it("appends top-level instructions for openai-responses", () => {
const body = {
instructions: "be helpful",
input: [{ type: "message", role: "user", content: [{ type: "input_text", text: "hi" }] }],
};

injectSystemPrompt(body, FORMATS.OPENAI_RESPONSES, "respond tersely");

expect(body.instructions).toBe("be helpful\n\nrespond tersely");
});

it("keeps chat completions system injection in messages", () => {
const body = { messages: [{ role: "user", content: "hi" }] };

injectSystemPrompt(body, FORMATS.OPENAI, "respond tersely");

expect(body.messages[0]).toEqual({ role: "system", content: "respond tersely" });
expect(body.messages[1]).toEqual({ role: "user", content: "hi" });
});
});