fix(ai): preserve default reasoning efforts

This commit is contained in:
Kang committed 2026-09-27 21:12:54 +08:00
1 parent d77b00a90d
commit 84db9f0516
3 files changed
+39 -4

No files matched your search

+23
View File
@@ -105,6 +105,29 @@ describe("AI provider settings", () => {
});
});
it("preserves default reasoning efforts when customizing an unconfigured model", () => {
const initial = settingsWithProviders();
delete initial.models[0].supported_reasoning_efforts;
render(<Harness initial={initial} />);
fireEvent.click(screen.getByRole("button", { name: "ai.editModelConfig" }));
expect(screen.getByRole("button", { name: "none" }).getAttribute("aria-pressed")).toBe("true");
expect(screen.getByRole("button", { name: "minimal" }).getAttribute("aria-pressed")).toBe(
"false",
);
expect(screen.getByRole("button", { name: "low" }).getAttribute("aria-pressed")).toBe("true");
fireEvent.click(screen.getByRole("button", { name: "minimal" }));
expect(currentSettings.models[0].supported_reasoning_efforts).toEqual([
"none",
"minimal",
"low",
"medium",
"high",
"xhigh",
]);
});
it.each([
["Ollama", "ollama"],
["OpenAI-compatible", "openai_compatible"],
+7 -2
View File
@@ -46,6 +46,7 @@ import {
aiModelIdForCredential,
aiModelIdForProvider,
BUILTIN_PROVIDERS,
DEFAULT_MODEL_REASONING_EFFORTS,
getCustomProviderBaseUrlPlaceholder,
getProviderLabel,
isBuiltinProvider,
@@ -1409,7 +1410,9 @@ export function AiModelsTab() {
};
const toggleModelReasoningEffort = (model: AIModelConfigItem, effort: AIModelReasoningEffort) => {
const selected = new Set(model.supported_reasoning_efforts ?? []);
const selected = new Set(
model.supported_reasoning_efforts ?? DEFAULT_MODEL_REASONING_EFFORTS,
);
if (selected.has(effort)) selected.delete(effort);
else selected.add(effort);
updateModel(model.id, {
@@ -2066,7 +2069,9 @@ export function AiModelsTab() {
className="mt-2 flex flex-wrap gap-2"
>
{MODEL_REASONING_EFFORTS.map((effort) => {
const selected = model.supported_reasoning_efforts?.includes(effort);
const selected = (
model.supported_reasoning_efforts ?? DEFAULT_MODEL_REASONING_EFFORTS
).includes(effort);
return (
<Button
key={effort}
+9 -2
View File
@@ -21,9 +21,16 @@ export const MODEL_REASONING_EFFORTS: AIModelReasoningEffort[] = [
"ultra",
];
export const DEFAULT_MODEL_REASONING_EFFORTS: AIModelReasoningEffort[] = [
"none",
"low",
"medium",
"high",
"xhigh",
];
export function getModelReasoningOptions(model: AIModelConfigItem | null): AIReasoningEffort[] {
const supported = model?.supported_reasoning_efforts;
if (!supported) return ["auto", "none", "low", "medium", "high", "xhigh"];
const supported = model?.supported_reasoning_efforts ?? DEFAULT_MODEL_REASONING_EFFORTS;
return ["auto", ...MODEL_REASONING_EFFORTS.filter((effort) => supported.includes(effort))];
}