Skip to content

Commit a97d97f

Browse files
fix(opencode-go): expose DeepSeek V4 max thinking (#99643)
Preserve existing lower-level high effort while making xhigh/max available before runtime activation. Co-authored-by: Peter Steinberger <[email protected]>
1 parent b1deaf8 commit a97d97f

7 files changed

Lines changed: 250 additions & 23 deletions

File tree

‎extensions/opencode-go/index.test.ts‎

Lines changed: 151 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Opencode Go tests cover index plugin behavior.
2+
import { clampThinkingLevel } from "openclaw/plugin-sdk/llm";
23
import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry";
34
import {
45
registerProviderPlugin,
@@ -42,6 +43,36 @@ function requireCatalogEntry(entries: readonly unknown[] | null | undefined, id:
4243
return requireRecord(entry, `supplemental catalog entry ${id}`);
4344
}
4445

46+
const deepSeekV4ThinkingProfileLevelIds = [
47+
"off",
48+
"minimal",
49+
"low",
50+
"medium",
51+
"high",
52+
"xhigh",
53+
"max",
54+
] as const;
55+
const deepSeekV4ThinkingProfile = {
56+
levels: deepSeekV4ThinkingProfileLevelIds.map((id) => ({ id })),
57+
defaultLevel: "high",
58+
};
59+
const deepSeekV4ThinkingLevelMap = {
60+
minimal: "high",
61+
low: "high",
62+
medium: "high",
63+
high: "high",
64+
xhigh: "max",
65+
max: "max",
66+
};
67+
68+
function expectDeepSeekV4ThinkingLevels(model: ProviderRuntimeModel) {
69+
expect(model.thinkingLevelMap).toEqual(deepSeekV4ThinkingLevelMap);
70+
expect(clampThinkingLevel(model, "off")).toBe("off");
71+
expect(clampThinkingLevel(model, "high")).toBe("high");
72+
expect(clampThinkingLevel(model, "xhigh")).toBe("xhigh");
73+
expect(clampThinkingLevel(model, "max")).toBe("max");
74+
}
75+
4576
describe("opencode-go provider plugin", () => {
4677
beforeEach(() => {
4778
clearLiveCatalogCacheForTests();
@@ -114,6 +145,17 @@ describe("opencode-go provider plugin", () => {
114145
models.set(model.id, model);
115146
}
116147
expect([...models.keys()]).toEqual(expectedModelIds);
148+
expectDeepSeekV4ThinkingLevels(requireMapEntry(models, "deepseek-v4-pro"));
149+
expectDeepSeekV4ThinkingLevels(requireMapEntry(models, "deepseek-v4-flash"));
150+
expect(
151+
provider.resolveThinkingProfile?.({ provider: "opencode-go", modelId: "deepseek-v4-pro" }),
152+
).toEqual(deepSeekV4ThinkingProfile);
153+
expect(
154+
provider.resolveThinkingProfile?.({ provider: "opencode-go", modelId: "deepseek-v4-flash" }),
155+
).toEqual(deepSeekV4ThinkingProfile);
156+
expect(
157+
provider.resolveThinkingProfile?.({ provider: "opencode-go", modelId: "glm-5" }),
158+
).toBeUndefined();
117159
const supplemental = await provider.augmentModelCatalog?.({
118160
entries: [...models.values()].map((model) => ({
119161
provider: model.provider,
@@ -242,6 +284,19 @@ describe("opencode-go provider plugin", () => {
242284
it("loads OpenCode Go model discovery through the provider runtime", () => {
243285
expect(manifest.providerCatalogEntry).toBe("./provider-discovery.ts");
244286
expect(manifest.modelCatalog.discovery["opencode-go"]).toBe("runtime");
287+
const manifestProvider = requireRecord(
288+
manifest.modelCatalog.providers["opencode-go"],
289+
"manifest provider",
290+
);
291+
if (!Array.isArray(manifestProvider.models)) {
292+
throw new Error("expected manifest models");
293+
}
294+
expect(
295+
requireCatalogEntry(manifestProvider.models, "deepseek-v4-pro").thinkingLevelMap,
296+
).toEqual(deepSeekV4ThinkingLevelMap);
297+
expect(
298+
requireCatalogEntry(manifestProvider.models, "deepseek-v4-flash").thinkingLevelMap,
299+
).toEqual(deepSeekV4ThinkingLevelMap);
245300
});
246301

247302
it("exposes the complete offline catalog through provider discovery", async () => {
@@ -250,13 +305,21 @@ describe("opencode-go provider plugin", () => {
250305
throw new Error("expected OpenCode Go static provider");
251306
}
252307
const deepSeekPro = result.provider.models.find((model) => model.id === "deepseek-v4-pro");
308+
const deepSeekFlash = result.provider.models.find((model) => model.id === "deepseek-v4-flash");
253309
const glm52 = result.provider.models.find((model) => model.id === "glm-5.2");
254310

255311
expect(result.provider.models).toHaveLength(18);
256312
expect(deepSeekPro).toMatchObject({
257313
provider: "opencode-go",
258314
contextWindow: 1_000_000,
259315
maxTokens: 384_000,
316+
thinkingLevelMap: deepSeekV4ThinkingLevelMap,
317+
});
318+
expect(deepSeekFlash).toMatchObject({
319+
provider: "opencode-go",
320+
contextWindow: 1_000_000,
321+
maxTokens: 384_000,
322+
thinkingLevelMap: deepSeekV4ThinkingLevelMap,
260323
});
261324
expect(glm52).toMatchObject({
262325
provider: "opencode-go",
@@ -386,15 +449,93 @@ describe("opencode-go provider plugin", () => {
386449
expect(fallback.models.map((model) => model.id)).toContain("minimax-m3");
387450
});
388451

389-
it("disables invalid DeepSeek V4 reasoning_effort off payloads on OpenCode Go", async () => {
452+
it.each(["deepseek-v4-pro", "deepseek-v4-flash"] as const)(
453+
"disables invalid DeepSeek V4 reasoning_effort off payloads on OpenCode Go for %s",
454+
async (modelId) => {
455+
const provider = await registerSingleProviderPlugin(plugin);
456+
const capturedPayloads: Record<string, unknown>[] = [];
457+
const baseStreamFn = (_model: unknown, _context: unknown, options: unknown) => {
458+
const payload = {
459+
model: modelId,
460+
reasoning_effort: "off",
461+
reasoning: "off",
462+
};
463+
(options as { onPayload?: (payload: Record<string, unknown>) => void })?.onPayload?.(
464+
payload,
465+
);
466+
capturedPayloads.push(payload);
467+
return {} as never;
468+
};
469+
470+
const streamFn = provider.wrapStreamFn?.({
471+
streamFn: baseStreamFn as never,
472+
providerId: "opencode-go",
473+
modelId,
474+
thinkingLevel: "off",
475+
} as never);
476+
477+
expect(streamFn).toBeTypeOf("function");
478+
await streamFn?.({ provider: "opencode-go", id: modelId } as never, {} as never, {});
479+
480+
expect(capturedPayloads).toEqual([
481+
{
482+
model: modelId,
483+
thinking: { type: "disabled" },
484+
},
485+
]);
486+
},
487+
);
488+
489+
it.each([
490+
["minimal", "high"],
491+
["low", "high"],
492+
["medium", "high"],
493+
["high", "high"],
494+
["xhigh", "max"],
495+
["max", "max"],
496+
] as const)(
497+
"maps OpenCode Go DeepSeek V4 %s thinking to %s reasoning effort",
498+
async (thinkingLevel, reasoningEffort) => {
499+
const provider = await registerSingleProviderPlugin(plugin);
500+
const capturedPayloads: Record<string, unknown>[] = [];
501+
const baseStreamFn = (_model: unknown, _context: unknown, options: unknown) => {
502+
const payload = { model: "deepseek-v4-flash" };
503+
(options as { onPayload?: (payload: Record<string, unknown>) => void })?.onPayload?.(
504+
payload,
505+
);
506+
capturedPayloads.push(payload);
507+
return {} as never;
508+
};
509+
510+
const streamFn = provider.wrapStreamFn?.({
511+
streamFn: baseStreamFn as never,
512+
providerId: "opencode-go",
513+
modelId: "deepseek-v4-flash",
514+
thinkingLevel,
515+
} as never);
516+
517+
expect(streamFn).toBeTypeOf("function");
518+
await streamFn?.(
519+
{ provider: "opencode-go", id: "deepseek-v4-flash" } as never,
520+
{} as never,
521+
{},
522+
);
523+
524+
expect(capturedPayloads).toEqual([
525+
{
526+
model: "deepseek-v4-flash",
527+
thinking: { type: "enabled" },
528+
reasoning_effort: reasoningEffort,
529+
},
530+
]);
531+
},
532+
);
533+
534+
it("does not apply DeepSeek V4 thinking payloads to unrelated OpenCode Go models", async () => {
390535
const provider = await registerSingleProviderPlugin(plugin);
391536
const capturedPayloads: Record<string, unknown>[] = [];
392537
const baseStreamFn = (_model: unknown, _context: unknown, options: unknown) => {
393-
const payload = {
394-
model: "deepseek-v4-flash",
395-
reasoning_effort: "off",
396-
reasoning: "off",
397-
};
538+
const payload = { model: "glm-5", reasoning_effort: "max" };
398539
(options as { onPayload?: (payload: Record<string, unknown>) => void })?.onPayload?.(payload);
399540
capturedPayloads.push(payload);
400541
return {} as never;
@@ -403,23 +544,14 @@ describe("opencode-go provider plugin", () => {
403544
const streamFn = provider.wrapStreamFn?.({
404545
streamFn: baseStreamFn as never,
405546
providerId: "opencode-go",
406-
modelId: "deepseek-v4-flash",
407-
thinkingLevel: "off",
547+
modelId: "glm-5",
548+
thinkingLevel: "max",
408549
} as never);
409550

410551
expect(streamFn).toBeTypeOf("function");
411-
await streamFn?.(
412-
{ provider: "opencode-go", id: "deepseek-v4-flash" } as never,
413-
{} as never,
414-
{},
415-
);
552+
await streamFn?.({ provider: "opencode-go", id: "glm-5" } as never, {} as never, {});
416553

417-
expect(capturedPayloads).toEqual([
418-
{
419-
model: "deepseek-v4-flash",
420-
thinking: { type: "disabled" },
421-
},
422-
]);
554+
expect(capturedPayloads).toEqual([{ model: "glm-5", reasoning_effort: "max" }]);
423555
});
424556

425557
it("strips unsupported Kimi reasoning payloads on OpenCode Go", async () => {

‎extensions/opencode-go/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
normalizeOpencodeGoResolvedModel,
1313
resolveOpencodeGoModel,
1414
} from "./provider-catalog.js";
15+
import { resolveThinkingProfile } from "./provider-policy-api.js";
1516
import { createOpencodeGoWrapper } from "./stream.js";
1617

1718
const PROVIDER_ID = "opencode-go";
@@ -136,6 +137,7 @@ export default definePluginEntry({
136137
},
137138
augmentModelCatalog: () => listOpencodeGoModelCatalogEntries(),
138139
...buildProviderReplayFamilyHooks({ family: "passthrough-gemini" }),
140+
resolveThinkingProfile,
139141
wrapStreamFn: (ctx) => createOpencodeGoWrapper(ctx.streamFn, ctx.thinkingLevel),
140142
isModernModelRef: () => true,
141143
});

‎extensions/opencode-go/openclaw.plugin.json‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"id": "deepseek-v4-pro",
3131
"name": "DeepSeek V4 Pro",
3232
"reasoning": true,
33+
"thinkingLevelMap": {
34+
"minimal": "high",
35+
"low": "high",
36+
"medium": "high",
37+
"high": "high",
38+
"xhigh": "max",
39+
"max": "max"
40+
},
3341
"input": ["text"],
3442
"contextWindow": 1000000,
3543
"maxTokens": 384000,
@@ -49,6 +57,14 @@
4957
"id": "deepseek-v4-flash",
5058
"name": "DeepSeek V4 Flash",
5159
"reasoning": true,
60+
"thinkingLevelMap": {
61+
"minimal": "high",
62+
"low": "high",
63+
"medium": "high",
64+
"high": "high",
65+
"xhigh": "max",
66+
"max": "max"
67+
},
5268
"input": ["text"],
5369
"contextWindow": 1000000,
5470
"maxTokens": 384000,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const OPENCODE_GO_KIMI_NO_REASONING_MODEL_IDS = new Set([
2323
const OPENCODE_GO_MODELS_ENDPOINT = "https://opencode.ai/zen/go/v1/models";
2424
const OPENCODE_GO_MODELS_TIMEOUT_MS = 5_000;
2525
const OPENCODE_GO_MODELS_CACHE_TTL_MS = 60_000;
26+
// OpenCode Go exposes only high/max provider effort for DeepSeek V4. Lower
27+
// OpenClaw levels retain their existing high-effort behavior.
28+
const OPENCODE_GO_DEEPSEEK_V4_THINKING_LEVEL_MAP = {
29+
minimal: "high",
30+
low: "high",
31+
medium: "high",
32+
high: "high",
33+
xhigh: "max",
34+
max: "max",
35+
} as const;
2636

2737
type OpencodeGoModelDefinition = ModelDefinitionConfig & {
2838
provider: typeof PROVIDER_ID;
@@ -40,6 +50,7 @@ const OPENCODE_GO_MODELS = (
4050
provider: PROVIDER_ID,
4151
baseUrl: OPENCODE_GO_OPENAI_BASE_URL,
4252
reasoning: true,
53+
thinkingLevelMap: OPENCODE_GO_DEEPSEEK_V4_THINKING_LEVEL_MAP,
4354
input: ["text"],
4455
cost: {
4556
input: 1.74,
@@ -62,6 +73,7 @@ const OPENCODE_GO_MODELS = (
6273
provider: PROVIDER_ID,
6374
baseUrl: OPENCODE_GO_OPENAI_BASE_URL,
6475
reasoning: true,
76+
thinkingLevelMap: OPENCODE_GO_DEEPSEEK_V4_THINKING_LEVEL_MAP,
6577
input: ["text"],
6678
cost: {
6779
input: 0.14,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// OpenCode Go policy module exposes thinking controls before runtime registration.
2+
import type {
3+
ProviderDefaultThinkingPolicyContext,
4+
ProviderThinkingProfile,
5+
} from "openclaw/plugin-sdk/plugin-entry";
6+
7+
const OPENCODE_GO_DEEPSEEK_V4_MODEL_IDS = new Set(["deepseek-v4-flash", "deepseek-v4-pro"]);
8+
const OPENCODE_GO_DEEPSEEK_V4_THINKING_LEVEL_IDS = [
9+
"off",
10+
"minimal",
11+
"low",
12+
"medium",
13+
"high",
14+
"xhigh",
15+
"max",
16+
] as const;
17+
const OPENCODE_GO_DEEPSEEK_V4_THINKING_PROFILE = {
18+
levels: OPENCODE_GO_DEEPSEEK_V4_THINKING_LEVEL_IDS.map((id) => ({ id })),
19+
defaultLevel: "high",
20+
} satisfies ProviderThinkingProfile;
21+
22+
export function isOpencodeGoDeepSeekV4ModelId(modelId: unknown): boolean {
23+
return (
24+
typeof modelId === "string" &&
25+
OPENCODE_GO_DEEPSEEK_V4_MODEL_IDS.has(modelId.trim().toLowerCase())
26+
);
27+
}
28+
29+
export function resolveOpencodeGoThinkingProfile(
30+
modelId: string,
31+
): ProviderThinkingProfile | undefined {
32+
return isOpencodeGoDeepSeekV4ModelId(modelId)
33+
? OPENCODE_GO_DEEPSEEK_V4_THINKING_PROFILE
34+
: undefined;
35+
}
36+
37+
export function resolveThinkingProfile(
38+
context: ProviderDefaultThinkingPolicyContext,
39+
): ProviderThinkingProfile | undefined {
40+
return context.provider.trim().toLowerCase() === "opencode-go"
41+
? resolveOpencodeGoThinkingProfile(context.modelId)
42+
: undefined;
43+
}

‎extensions/opencode-go/stream.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import {
55
streamWithPayloadPatch,
66
} from "openclaw/plugin-sdk/provider-stream-shared";
77
import { isOpencodeGoKimiNoReasoningModelId } from "./provider-catalog.js";
8+
import { isOpencodeGoDeepSeekV4ModelId } from "./provider-policy-api.js";
89
import { stripOpencodeGoKimiReasoningPayload } from "./reasoning-sanitizer.js";
910
import {
1011
createOpencodeGoStalledStreamWrapper,
1112
OPENCODE_GO_STREAM_FIRST_EVENT_TIMEOUT_MS_DEFAULT,
1213
OPENCODE_GO_STREAM_IDLE_TIMEOUT_MS_DEFAULT,
1314
} from "./stream-termination.js";
1415

15-
function isOpencodeGoDeepSeekV4ModelId(modelId: unknown): boolean {
16-
return modelId === "deepseek-v4-flash" || modelId === "deepseek-v4-pro";
17-
}
18-
1916
function createOpencodeGoDeepSeekV4Wrapper(
2017
baseStreamFn: ProviderWrapStreamFnContext["streamFn"],
2118
thinkingLevel: ProviderWrapStreamFnContext["thinkingLevel"],

0 commit comments

Comments
 (0)