fix(kimi): normalize reasoning_effort to backend enum (#2427)

Map auto→high, minimal→low, xhigh→max and whitelist low/medium/high/max
so Kimi/kimchi SGLang backends no longer receive invalid effort values.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whale
2026-07-07 11:56:39 +07:00
committed by decolua
co-authored by Cursor
parent 97a6708651
commit 8c068a1f5c
2 changed files with 21 additions and 2 deletions
@@ -132,6 +132,15 @@ function toGeminiThinkingLevel(cfg) {
return effortToThinkingLevel(raw); return effortToThinkingLevel(raw);
} }
function toKimiReasoningEffort(cfg) {
const level = toLevel(cfg);
if (level === "auto") return "high";
if (level === "minimal") return "low";
if (level === "xhigh") return "max";
if (["low", "medium", "high", "max"].includes(level)) return level;
return null;
}
// Gemini nests thinkingConfig under generationConfig. gemini-cli / antigravity wrap // Gemini nests thinkingConfig under generationConfig. gemini-cli / antigravity wrap
// the whole request in a { request: { generationConfig } } envelope — target the // the whole request in a { request: { generationConfig } } envelope — target the
// envelope's generationConfig when present, else the top-level one. // envelope's generationConfig when present, else the top-level one.
@@ -217,8 +226,8 @@ function applyFormat(fmt, body, cfg, caps) {
} }
case "kimi": { case "kimi": {
if (none && canDisable) { body.thinking = { type: "disabled" }; break; } if (none && canDisable) { body.thinking = { type: "disabled" }; break; }
const level = toLevel(eff); const effort = toKimiReasoningEffort(eff);
if (level) body.reasoning_effort = level === "max" ? "high" : level; if (effort) body.reasoning_effort = effort;
break; break;
} }
case "minimax": { case "minimax": {
+10
View File
@@ -106,6 +106,16 @@ describe("applyThinking per provider format", () => {
const out = apply("openai", "kimi-k2.6", { reasoning_effort: "high" }, "kimi"); const out = apply("openai", "kimi-k2.6", { reasoning_effort: "high" }, "kimi");
expect(out.reasoning_effort).toBe("high"); expect(out.reasoning_effort).toBe("high");
}); });
it("Kimi auto → supported reasoning_effort", () => {
const out = apply("openai", "kimi-k2.7", { reasoning_effort: "auto" }, "kimchi");
expect(out.reasoning_effort).toBe("high");
});
it("Kimi unsupported OpenAI levels → supported reasoning_effort", () => {
const minimal = apply("openai", "kimi-k2.7", { reasoning_effort: "minimal" }, "kimchi");
const xhigh = apply("openai", "kimi-k2.7", { reasoning_effort: "xhigh" }, "kimchi");
expect(minimal.reasoning_effort).toBe("low");
expect(xhigh.reasoning_effort).toBe("max");
});
it("MiniMax M3 → adaptive", () => { it("MiniMax M3 → adaptive", () => {
const out = apply("claude", "MiniMax-M3", { reasoning_effort: "high" }, "minimax"); const out = apply("claude", "MiniMax-M3", { reasoning_effort: "high" }, "minimax");
expect(out.thinking).toEqual({ type: "adaptive" }); expect(out.thinking).toEqual({ type: "adaptive" });