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
6 changes: 5 additions & 1 deletion open-sse/translator/request/openai-to-commandcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { randomUUID } from "crypto";
import { ROLE, OPENAI_BLOCK } from "../schema/index.js";
import { stripThinkingSuffix } from "../concerns/thinkingUnified.js";
import { DEFAULT_MAX_TOKENS } from "../../config/runtimeConfig.js";

function flattenText(content) {
Expand Down Expand Up @@ -136,7 +137,10 @@ function convertTools(tools) {
export function openaiToCommandCodeRequest(model, body, stream /* , credentials */) {
const { messages, system } = convertMessages(body.messages);
const params = {
model,
// Upstream reads params.model and rejects unknown ids — never leak the
// client thinking suffix "model(level)" (chatCore strips only the top-level
// model field; the suffix is consumed by applyThinking, not the wire).
model: stripThinkingSuffix(model),
messages,
stream: stream !== false,
max_tokens: body.max_tokens ?? body.max_output_tokens ?? DEFAULT_MAX_TOKENS,
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/openai-to-commandcode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ describe("openaiToCommandCodeRequest — basic envelope", () => {
});
});

describe("openaiToCommandCodeRequest — thinking suffix stripping", () => {
it("strips a client thinking suffix from params.model (upstream rejects it)", () => {
const out = openaiToCommandCodeRequest("gpt-5.6-luna(max)", {
messages: [{ role: "user", content: "hi" }],
}, true);

expect(out.params.model).toBe("gpt-5.6-luna");
});

it("strips the suffix from family-prefixed ids too", () => {
const out = openaiToCommandCodeRequest("deepseek/deepseek-v4-pro(max)", {
messages: [{ role: "user", content: "hi" }],
}, true);

expect(out.params.model).toBe("deepseek/deepseek-v4-pro");
});

it("leaves plain model ids untouched", () => {
const out = openaiToCommandCodeRequest("deepseek/deepseek-v4-pro", {
messages: [{ role: "user", content: "hi" }],
}, true);

expect(out.params.model).toBe("deepseek/deepseek-v4-pro");
});
});

describe("openaiToCommandCodeRequest — system handling", () => {
it("hoists system messages to params.system (string), not messages[]", () => {
const out = openaiToCommandCodeRequest(MODEL, {
Expand Down