Skip to content

Commit 391bae1

Browse files
committed
fix(providers): replay DeepSeek reasoning for opencode-zen (#994)
1 parent 0e92714 commit 391bae1

2 files changed

Lines changed: 97 additions & 1 deletion

File tree

‎src/providers/registry.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,22 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
16491649
autoToolChoiceOnlyModels: KIMI_AUTO_TOOL_CHOICE_ONLY_MODELS,
16501650
preserveReasoningContentModels: KIMI_THINKING_MODELS,
16511651
},
1652-
{ id: "opencode-zen", label: "opencode zen", baseUrl: "https://opencode.ai/zen/v1", adapter: "openai-chat", authKind: "key", dashboardUrl: "https://opencode.ai/auth" },
1652+
{
1653+
id: "opencode-zen", label: "opencode zen", baseUrl: "https://opencode.ai/zen/v1", adapter: "openai-chat", authKind: "key", dashboardUrl: "https://opencode.ai/auth",
1654+
// Same opencode.ai/zen/v1 gateway as `opencode-free` (keyed tier): DeepSeek thinking mode
1655+
// requires the assistant's original reasoning_content to be replayed on tool-call
1656+
// continuations, or the gateway answers HTTP 400 (issues #950/#994). Mirror the DeepSeek
1657+
// reasoning + thinking metadata so `opencode-zen/deepseek-v4-flash-free` — and the other
1658+
// Zen DeepSeek thinking models — never serialize a bare tool-call turn.
1659+
modelReasoningEfforts: Object.fromEntries(
1660+
[...DEEPSEEK_THINKING_MODELS, ...OPENCODE_FREE_DEEPSEEK_MODELS].map(id => [id, DEEPSEEK_THINKING_EFFORTS]),
1661+
),
1662+
modelReasoningEffortMap: Object.fromEntries(
1663+
[...DEEPSEEK_THINKING_MODELS, ...OPENCODE_FREE_DEEPSEEK_MODELS].map(id => [id, DEEPSEEK_THINKING_REASONING_MAP]),
1664+
),
1665+
preserveReasoningContentModels: [...DEEPSEEK_THINKING_MODELS, ...OPENCODE_FREE_DEEPSEEK_MODELS],
1666+
noVisionModels: [...DEEPSEEK_THINKING_MODELS, ...OPENCODE_FREE_DEEPSEEK_MODELS],
1667+
},
16531668
{ id: "vercel-ai-gateway", label: "Vercel AI Gateway", baseUrl: "https://ai-gateway.vercel.sh/v1", adapter: "openai-chat", authKind: "key", dashboardUrl: "https://vercel.com/dashboard" },
16541669
{
16551670
id: "opencode-free",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { createOpenAIChatAdapter } from "../src/adapters/openai-chat";
3+
import { routeModel } from "../src/router";
4+
import type { OcxConfig } from "../src/types";
5+
6+
function configFor(modelId: string): OcxConfig {
7+
return {
8+
port: 10110,
9+
defaultProvider: "opencode-zen",
10+
providers: {
11+
"opencode-zen": {
12+
adapter: "openai-chat",
13+
baseUrl: "https://opencode.ai/zen/v1",
14+
apiKey: "key",
15+
models: [modelId],
16+
},
17+
},
18+
};
19+
}
20+
21+
function buildToolCallBody(modelId: string, reasoning?: string): {
22+
reasoning_effort?: string;
23+
messages: Record<string, unknown>[];
24+
} {
25+
const route = routeModel(configFor(modelId), `opencode-zen/${modelId}`);
26+
const req = createOpenAIChatAdapter(route.provider).buildRequest({
27+
modelId: route.modelId,
28+
context: {
29+
messages: [
30+
{ role: "user", content: "inspect the repo", timestamp: 0 },
31+
{ role: "assistant", timestamp: 1, content: [
32+
{ type: "thinking", thinking: "I need to inspect files before answering." },
33+
{ type: "toolCall", id: "call_1", name: "read_file", arguments: { path: "README.md" } },
34+
] },
35+
{
36+
role: "toolResult",
37+
toolCallId: "call_1",
38+
toolName: "read_file",
39+
content: "contents",
40+
isError: false,
41+
timestamp: 2,
42+
},
43+
],
44+
},
45+
stream: true,
46+
options: { reasoning: reasoning ?? "max" },
47+
});
48+
49+
return JSON.parse(req.body as string) as {
50+
reasoning_effort?: string;
51+
messages: Record<string, unknown>[];
52+
};
53+
}
54+
55+
describe("opencode-zen DeepSeek thinking mode", () => {
56+
test.each(["deepseek-v4-flash-free", "deepseek-v4-flash", "deepseek-v4-pro"])(
57+
"%s replays tool-call reasoning_content and maps Codex efforts (issue #950/#994)",
58+
modelId => {
59+
const body = buildToolCallBody(modelId, "xhigh");
60+
61+
expect(body.reasoning_effort).toBe("max");
62+
expect(body.messages[1].reasoning_content).toBe("I need to inspect files before answering.");
63+
expect(body.messages[1]).toMatchObject({
64+
role: "assistant",
65+
content: "",
66+
tool_calls: [{
67+
id: "call_1",
68+
type: "function",
69+
function: { name: "read_file", arguments: JSON.stringify({ path: "README.md" }) },
70+
}],
71+
});
72+
},
73+
);
74+
75+
test("non-DeepSeek opencode-zen models do not replay reasoning_content", () => {
76+
const body = buildToolCallBody("minimax-m2.7");
77+
78+
expect(body.messages[1].reasoning_content).toBeUndefined();
79+
expect(body.messages[1]).toHaveProperty("tool_calls");
80+
});
81+
});

0 commit comments

Comments
 (0)