Skip to content

Commit 4073c4d

Browse files
committed
fix(desktop): honor model thinking efforts
1 parent b0c169b commit 4073c4d

3 files changed

Lines changed: 121 additions & 45 deletions

File tree

‎apps/kimi-code/src/App.tsx‎

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ import {
7474
loadDesktopState,
7575
projectFromWorkspace,
7676
} from "./store";
77+
import {
78+
normalizeThinkingLevel,
79+
thinkingLevelDescription,
80+
thinkingLevelsForModel,
81+
} from "./modelControls";
7782
import type {
7883
AccountUsage,
7984
AgentChatEvent,
@@ -589,30 +594,6 @@ function omitSessionKeys<T>(
589594
return changed ? next : current;
590595
}
591596

592-
const THINKING_LEVELS = ["low", "medium", "high"] as const;
593-
594-
function thinkingLevelsForModel(model?: Model): string[] {
595-
if (!model?.supportEfforts.length) return [...THINKING_LEVELS];
596-
const supported = THINKING_LEVELS.filter((level) =>
597-
model.supportEfforts.includes(level),
598-
);
599-
return supported.length ? supported : [...THINKING_LEVELS];
600-
}
601-
602-
function normalizeThinkingLevel(
603-
level: string | undefined,
604-
model?: Model,
605-
): string {
606-
const supported = thinkingLevelsForModel(model);
607-
if (level && supported.includes(level)) return level;
608-
if (model?.defaultEffort && supported.includes(model.defaultEffort)) {
609-
return model.defaultEffort;
610-
}
611-
return supported.includes("medium")
612-
? "medium"
613-
: supported[Math.floor(supported.length / 2)];
614-
}
615-
616597
export default function App() {
617598
const [desktop, setDesktop] = useState<DesktopState>({ projects: [] });
618599
const [auth, setAuth] = useState<AuthStatus>({
@@ -681,6 +662,7 @@ export default function App() {
681662
model.id === activeConversation?.modelId ||
682663
model.model === activeConversation?.modelId,
683664
) ?? defaultModel;
665+
const supportedThinkingLevels = thinkingLevelsForModel(selectedModel);
684666
const effort = normalizeThinkingLevel(
685667
activeConversation?.thinkingLevel,
686668
selectedModel,
@@ -1510,7 +1492,8 @@ export default function App() {
15101492
};
15111493

15121494
const chooseEffort = (level: string): void => {
1513-
if (!activeConversation || !activeProject) return;
1495+
if (!activeConversation || !activeProject || modelBusy) return;
1496+
if (!thinkingLevelsForModel(selectedModel).includes(level)) return;
15141497
if (activeAgentScope?.sessionId !== activeConversation.id) {
15151498
showNotice("The conversation is still preparing. Try again in a moment.");
15161499
return;
@@ -2358,28 +2341,23 @@ export default function App() {
23582341
<RefreshCw size={14} />
23592342
</button>
23602343
)}
2361-
{selectedModel?.supportsReasoning && (
2362-
<ToolbarSelect
2363-
className="effort-select"
2364-
ariaLabel="选择思考强度"
2365-
icon={<BrainCircuit size={15} />}
2366-
value={effort}
2367-
label={`思考 · ${effort}`}
2368-
options={thinkingLevelsForModel(selectedModel).map(
2369-
(value) => ({
2344+
{selectedModel?.supportsReasoning &&
2345+
supportedThinkingLevels.length > 0 && (
2346+
<ToolbarSelect
2347+
className="effort-select"
2348+
ariaLabel="选择思考强度"
2349+
icon={<BrainCircuit size={15} />}
2350+
value={effort}
2351+
label={`思考 · ${effort}`}
2352+
disabled={modelBusy || !activeAgentScope}
2353+
options={supportedThinkingLevels.map((value) => ({
23702354
value,
23712355
label: `思考 · ${value}`,
2372-
description:
2373-
value === "low"
2374-
? "快速响应,适合简单任务"
2375-
: value === "high"
2376-
? "更深入分析复杂问题"
2377-
: "速度与推理深度平衡",
2378-
}),
2379-
)}
2380-
onChange={chooseEffort}
2381-
/>
2382-
)}
2356+
description: thinkingLevelDescription(value),
2357+
}))}
2358+
onChange={chooseEffort}
2359+
/>
2360+
)}
23832361
<ToolbarSelect
23842362
className={`permission-select ${
23852363
permissionMode === "yolo"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Model } from "./types";
2+
3+
export function thinkingLevelsForModel(model?: Model): string[] {
4+
return [
5+
...new Set(
6+
(model?.supportEfforts ?? [])
7+
.map((effort) => effort.trim())
8+
.filter(Boolean),
9+
),
10+
];
11+
}
12+
13+
export function normalizeThinkingLevel(
14+
level: string | undefined,
15+
model?: Model,
16+
): string {
17+
const supported = thinkingLevelsForModel(model);
18+
if (!supported.length) return model?.supportsReasoning ? "on" : "off";
19+
if (level && supported.includes(level)) return level;
20+
if (model?.defaultEffort && supported.includes(model.defaultEffort)) {
21+
return model.defaultEffort;
22+
}
23+
return supported[Math.floor(supported.length / 2)];
24+
}
25+
26+
export function thinkingLevelDescription(level: string): string {
27+
switch (level) {
28+
case "low":
29+
return "快速响应,适合简单任务";
30+
case "medium":
31+
return "速度与推理深度平衡";
32+
case "high":
33+
return "更深入分析复杂问题";
34+
case "max":
35+
return "最大思考深度,适合最复杂的任务";
36+
default:
37+
return `模型支持的 ${level} 思考强度`;
38+
}
39+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import {
5+
normalizeThinkingLevel,
6+
thinkingLevelsForModel,
7+
} from "../src/modelControls.ts";
8+
import type { Model } from "../src/types.ts";
9+
10+
function model(overrides: Partial<Model>): Model {
11+
return {
12+
id: "test/model",
13+
model: "model",
14+
providerId: "test",
15+
isDefault: false,
16+
displayName: "Test model",
17+
contextLength: 128_000,
18+
supportsReasoning: true,
19+
supportsImage: false,
20+
supportsVideo: false,
21+
supportsTools: true,
22+
protocol: "openai",
23+
supportEfforts: [],
24+
...overrides,
25+
};
26+
}
27+
28+
test("K3 exposes exactly its configured thinking efforts including max", () => {
29+
const k3 = model({
30+
id: "kimi-code/k3",
31+
model: "k3",
32+
displayName: "K3",
33+
supportEfforts: ["low", "high", "max"],
34+
defaultEffort: "high",
35+
});
36+
37+
assert.deepEqual(thinkingLevelsForModel(k3), ["low", "high", "max"]);
38+
assert.equal(normalizeThinkingLevel("max", k3), "max");
39+
assert.equal(normalizeThinkingLevel("medium", k3), "high");
40+
});
41+
42+
test("a thinking model without support_efforts has no selectable effort", () => {
43+
const kimiForCoding = model({
44+
id: "kimi-code/kimi-for-coding",
45+
model: "kimi-for-coding",
46+
displayName: "K2.7 Coding",
47+
});
48+
49+
assert.deepEqual(thinkingLevelsForModel(kimiForCoding), []);
50+
assert.equal(normalizeThinkingLevel("high", kimiForCoding), "on");
51+
});
52+
53+
test("configured efforts are trimmed, deduplicated, and keep their order", () => {
54+
const configured = model({
55+
supportEfforts: [" low ", "high", "low", "", "max"],
56+
});
57+
58+
assert.deepEqual(thinkingLevelsForModel(configured), ["low", "high", "max"]);
59+
});

0 commit comments

Comments
 (0)