Skip to content

Commit 25bb674

Browse files
committed
fix(opencode-go): enable xhigh/max thinking levels for DeepSeek V4
Add thinkingLevelMap to DeepSeek V4 model catalog entries so getSupportedThinkingLevels() allows xhigh and max selections. Replace hardcoded createDeepSeekV4OpenAICompatibleThinkingWrapper with inline streamWithPayloadPatch that reads thinkingLevelMap from the model definition at runtime. Closes the gap where DeepSeek V4 supports max reasoning_effort but neither the catalog nor the wrapper exposed it.
1 parent a7c5a04 commit 25bb674

2 files changed

Lines changed: 82 additions & 8 deletions

File tree

‎extensions/opencode-go/provider-catalog.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const PROVIDER_ID = "opencode-go";
77
const OPENCODE_GO_OPENAI_BASE_URL = "https://opencode.ai/zen/go/v1";
88
const OPENCODE_GO_ANTHROPIC_BASE_URL = "https://opencode.ai/zen/go";
99

10+
type ProviderRuntimeModelWithThinkingLevelMap = ProviderRuntimeModel & {
11+
thinkingLevelMap?: Record<string, string>;
12+
};
13+
1014
const OPENCODE_GO_SUPPLEMENTAL_MODELS = (
1115
[
1216
{
@@ -30,6 +34,14 @@ const OPENCODE_GO_SUPPLEMENTAL_MODELS = (
3034
supportsReasoningEffort: true,
3135
maxTokensField: "max_tokens",
3236
},
37+
thinkingLevelMap: {
38+
minimal: "high",
39+
low: "high",
40+
medium: "high",
41+
high: "max",
42+
xhigh: "max",
43+
max: "max",
44+
},
3345
},
3446
{
3547
id: "deepseek-v4-flash",
@@ -52,8 +64,16 @@ const OPENCODE_GO_SUPPLEMENTAL_MODELS = (
5264
supportsReasoningEffort: true,
5365
maxTokensField: "max_tokens",
5466
},
67+
thinkingLevelMap: {
68+
minimal: "high",
69+
low: "high",
70+
medium: "high",
71+
high: "max",
72+
xhigh: "max",
73+
max: "max",
74+
},
5575
},
56-
] satisfies ProviderRuntimeModel[]
76+
] satisfies ProviderRuntimeModelWithThinkingLevelMap[]
5777
).map((model) => normalizeModelCompat(model));
5878

5979
export function listOpencodeGoSupplementalModelCatalogEntries(): ModelCatalogEntry[] {

‎extensions/opencode-go/stream.ts‎

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,72 @@
11
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
2-
import { createDeepSeekV4OpenAICompatibleThinkingWrapper } from "openclaw/plugin-sdk/provider-stream-shared";
2+
import { streamWithPayloadPatch } from "openclaw/plugin-sdk/provider-stream-shared";
33

44
function isOpencodeGoDeepSeekV4ModelId(modelId: unknown): boolean {
55
return modelId === "deepseek-v4-flash" || modelId === "deepseek-v4-pro";
66
}
77

8+
function isDisabledDeepSeekV4ThinkingLevel(thinkingLevel: unknown): boolean {
9+
const normalized = typeof thinkingLevel === "string" ? thinkingLevel.toLowerCase() : "";
10+
return normalized === "off" || normalized === "none";
11+
}
12+
813
export function createOpencodeGoDeepSeekV4Wrapper(
914
baseStreamFn: ProviderWrapStreamFnContext["streamFn"],
1015
thinkingLevel: ProviderWrapStreamFnContext["thinkingLevel"],
1116
): ProviderWrapStreamFnContext["streamFn"] {
12-
return createDeepSeekV4OpenAICompatibleThinkingWrapper({
13-
baseStreamFn,
14-
thinkingLevel,
15-
shouldPatchModel: (model) =>
16-
model.provider === "opencode-go" && isOpencodeGoDeepSeekV4ModelId(model.id),
17-
});
17+
if (!baseStreamFn) return undefined;
18+
const underlying = baseStreamFn;
19+
return (model, context, options) => {
20+
if (!(model.provider === "opencode-go" && isOpencodeGoDeepSeekV4ModelId(model.id))) {
21+
return underlying(model, context, options);
22+
}
23+
return streamWithPayloadPatch(underlying, model, context, options, (payload) => {
24+
// Handle disabled thinking
25+
if (isDisabledDeepSeekV4ThinkingLevel(thinkingLevel)) {
26+
payload.thinking = { type: "disabled" };
27+
delete payload.reasoning_effort;
28+
delete payload.reasoning;
29+
if (Array.isArray(payload.messages)) {
30+
for (const msg of payload.messages) {
31+
if (msg && typeof msg === "object") {
32+
delete (msg as Record<string, unknown>).reasoning_content;
33+
}
34+
}
35+
}
36+
return;
37+
}
38+
39+
// Use model.thinkingLevelMap if available, otherwise fall back to hardcoded mapping
40+
const map = (model as unknown as Record<string, unknown>).thinkingLevelMap as
41+
| Record<string, string | null>
42+
| undefined;
43+
const mappedEffort =
44+
typeof map === "object" && map !== null ? map[String(thinkingLevel)] : undefined;
45+
const reasoningEffort =
46+
typeof mappedEffort === "string"
47+
? mappedEffort
48+
: thinkingLevel === "xhigh" || thinkingLevel === "max"
49+
? "max"
50+
: "high";
51+
52+
payload.thinking = { type: "enabled" };
53+
payload.reasoning_effort = reasoningEffort;
54+
55+
// Backfill reasoning_content on assistant messages
56+
if (Array.isArray(payload.messages)) {
57+
for (const message of payload.messages) {
58+
if (
59+
message &&
60+
typeof message === "object" &&
61+
(message as Record<string, unknown>).role === "assistant"
62+
) {
63+
const record = message as Record<string, unknown>;
64+
if (!("reasoning_content" in record)) {
65+
record.reasoning_content = "";
66+
}
67+
}
68+
}
69+
}
70+
});
71+
};
1872
}

0 commit comments

Comments
 (0)