mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 23:02:10 +03:00
Claude→OpenAI translation was emitting a literal </think> into delta.content for ordinary Chat Completions clients. Reasoning already ships as reasoning_content, so default to suppress and keep x-omniroute-thinking-marker: on as the #4633 opt-in.
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { FORMATS } = await import("../../open-sse/translator/formats.ts");
|
|
const { resolveSuppressThinkClose } = await import("../../open-sse/utils/thinkCloseMarker.ts");
|
|
|
|
// kimi-coding via /v1/responses: the Claude→OpenAI `</think>` close marker
|
|
// (#4633) exists for Chat Completions clients that scan content for the marker
|
|
// (Claude Code / Cursor). Responses API clients receive reasoning as
|
|
// structured reasoning items (responsesTransformer maps reasoning_content
|
|
// natively), so the textual marker has no consumer on this path and always
|
|
// leaks verbatim into `response.output_text.delta`.
|
|
|
|
test("openai-responses client format always suppresses the close marker", () => {
|
|
assert.equal(
|
|
resolveSuppressThinkClose({
|
|
userAgent: "OpenAI/JS 6.26.0",
|
|
thinkingMarkerHeader: null,
|
|
clientResponseFormat: FORMATS.OPENAI_RESPONSES,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
test("openai-responses suppression wins over an explicit keep header", () => {
|
|
// There is no legitimate marker consumer in the Responses API format; an
|
|
// explicit `x-omniroute-thinking-marker: on` would only re-create the leak.
|
|
assert.equal(
|
|
resolveSuppressThinkClose({
|
|
userAgent: null,
|
|
thinkingMarkerHeader: "on",
|
|
clientResponseFormat: FORMATS.OPENAI_RESPONSES,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
test("openai chat format suppresses the marker by default (#8245)", () => {
|
|
assert.equal(
|
|
resolveSuppressThinkClose({
|
|
userAgent: "OpenAI/JS 6.26.0",
|
|
thinkingMarkerHeader: null,
|
|
clientResponseFormat: FORMATS.OPENAI,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
test("absent client format suppresses by default; header on keeps the marker (#8245)", () => {
|
|
assert.equal(
|
|
resolveSuppressThinkClose({ userAgent: "opencode/1.0", thinkingMarkerHeader: null }),
|
|
true
|
|
);
|
|
assert.equal(
|
|
resolveSuppressThinkClose({ userAgent: "unknown-client", thinkingMarkerHeader: null }),
|
|
true
|
|
);
|
|
assert.equal(
|
|
resolveSuppressThinkClose({
|
|
userAgent: "unknown-client",
|
|
thinkingMarkerHeader: "on",
|
|
clientResponseFormat: FORMATS.OPENAI,
|
|
}),
|
|
false
|
|
);
|
|
});
|