fix: align ZAI thinking toggles

This commit is contained in:
Peter Steinberger
2026-01-16 22:25:51 +00:00
parent 3567dc4a47
commit 500c75b4f0
14 changed files with 134 additions and 562 deletions

View File

@@ -1,5 +1,10 @@
import { describe, expect, it } from "vitest";
import { listThinkingLevels, normalizeReasoningLevel, normalizeThinkLevel } from "./thinking.js";
import {
listThinkingLevelLabels,
listThinkingLevels,
normalizeReasoningLevel,
normalizeThinkLevel,
} from "./thinking.js";
describe("normalizeThinkLevel", () => {
it("accepts mid as medium", () => {
@@ -9,6 +14,10 @@ describe("normalizeThinkLevel", () => {
it("accepts xhigh", () => {
expect(normalizeThinkLevel("xhigh")).toBe("xhigh");
});
it("accepts on as low", () => {
expect(normalizeThinkLevel("on")).toBe("low");
});
});
describe("listThinkingLevels", () => {
@@ -25,6 +34,17 @@ describe("listThinkingLevels", () => {
});
});
describe("listThinkingLevelLabels", () => {
it("returns on/off for ZAI", () => {
expect(listThinkingLevelLabels("zai", "glm-4.7")).toEqual(["off", "on"]);
});
it("returns full levels for non-ZAI", () => {
expect(listThinkingLevelLabels("openai", "gpt-4.1-mini")).toContain("low");
expect(listThinkingLevelLabels("openai", "gpt-4.1-mini")).not.toContain("on");
});
});
describe("normalizeReasoningLevel", () => {
it("accepts on/off", () => {
expect(normalizeReasoningLevel("on")).toBe("on");

View File

@@ -4,6 +4,17 @@ export type ElevatedLevel = "off" | "on";
export type ReasoningLevel = "off" | "on" | "stream";
export type UsageDisplayLevel = "off" | "on";
function normalizeProviderId(provider?: string | null): string {
if (!provider) return "";
const normalized = provider.trim().toLowerCase();
if (normalized === "z.ai" || normalized === "z-ai") return "zai";
return normalized;
}
export function isBinaryThinkingProvider(provider?: string | null): boolean {
return normalizeProviderId(provider) === "zai";
}
export const XHIGH_MODEL_REFS = [
"openai/gpt-5.2",
"openai-codex/gpt-5.2-codex",
@@ -22,6 +33,7 @@ export function normalizeThinkLevel(raw?: string | null): ThinkLevel | undefined
if (!raw) return undefined;
const key = raw.toLowerCase();
if (["off"].includes(key)) return "off";
if (["on", "enable", "enabled"].includes(key)) return "low";
if (["min", "minimal"].includes(key)) return "minimal";
if (["low", "thinkhard", "think-hard", "think_hard"].includes(key)) return "low";
if (["mid", "med", "medium", "thinkharder", "think-harder", "harder"].includes(key))
@@ -49,12 +61,20 @@ export function listThinkingLevels(provider?: string | null, model?: string | nu
return levels;
}
export function listThinkingLevelLabels(
provider?: string | null,
model?: string | null,
): string[] {
if (isBinaryThinkingProvider(provider)) return ["off", "on"];
return listThinkingLevels(provider, model);
}
export function formatThinkingLevels(
provider?: string | null,
model?: string | null,
separator = ", ",
): string {
return listThinkingLevels(provider, model).join(separator);
return listThinkingLevelLabels(provider, model).join(separator);
}
export function formatXHighModelHint(): string {