From 6712cc4c2c2be26c5baa2db9af6c530ca950b713 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 29 Sep 2026 00:45:17 -0500 Subject: [PATCH] fix(core): turn off Workers AI thinking through the chat template (#52017) --- packages/core/src/variant.ts | 21 +++++++++++++++++++- packages/core/test/variant.test.ts | 31 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/core/src/variant.ts b/packages/core/src/variant.ts index 1f47d37bf41..c07fcf13cee 100644 --- a/packages/core/src/variant.ts +++ b/packages/core/src/variant.ts @@ -160,6 +160,25 @@ const nvidiaChat: Protocol = (model, support) => { } } +// Workers AI ignores or rejects `reasoning_effort: "none"` on most models. Kimi's chat template reads +// `thinking`; the others read `enable_thinking`, so both are sent. +const workersAITemplate = (thinking: boolean): Overlay => ({ + body: { chat_template_kwargs: { enable_thinking: thinking, thinking } }, +}) + +const workersAIChat: Protocol = (_, support) => { + switch (support.type) { + case "effort": + return efforts(support.values ?? EFFORTS, (effort) => + effort === "none" ? workersAITemplate(false) : { settings: { reasoningEffort: effort } }, + ) + case "toggle": + return toggle(workersAITemplate(false), workersAITemplate(true)) + case "budget_tokens": + return [] + } +} + const basetenTemplate = (enable_thinking: boolean): Overlay => ({ body: { chat_template_args: { enable_thinking } }, }) @@ -552,7 +571,7 @@ const PROTOCOLS: Readonly> = { "@opencode/ai/providers/alibaba/chat": alibabaChat, "@opencode/ai/providers/baseten": basetenChat, "@opencode/ai/providers/cerebras": openaiChat, - "@opencode/ai/providers/cloudflare-workers-ai": openaiChat, + "@opencode/ai/providers/cloudflare-workers-ai": workersAIChat, "@opencode/ai/providers/deepinfra": deepinfraChat, "@opencode/ai/providers/deepseek": deepseekChat, "@opencode/ai/providers/fireworks": openaiChat, diff --git a/packages/core/test/variant.test.ts b/packages/core/test/variant.test.ts index c763b9f17b9..14afa38f265 100644 --- a/packages/core/test/variant.test.ts +++ b/packages/core/test/variant.test.ts @@ -264,6 +264,37 @@ test("caps Alibaba thinking budget variants at 64k", () => { ]) }) +test("spells Workers AI thinking controls through the chat template", () => { + const pkg = "@opencode/ai/providers/cloudflare-workers-ai" + const off = { body: { chat_template_kwargs: { enable_thinking: false, thinking: false } } } + const on = { body: { chat_template_kwargs: { enable_thinking: true, thinking: true } } } + expect( + resolve(model(pkg, "@cf/deepseek-ai/deepseek-v4-flash-0731"), [ + { type: "effort", values: ["none", "low", "high", "max"] }, + ]), + ).toEqual([ + { id: "none", ...off }, + { id: "low", settings: { reasoningEffort: "low" } }, + { id: "high", settings: { reasoningEffort: "high" } }, + { id: "max", settings: { reasoningEffort: "max" } }, + ]) + expect(resolve(model(pkg, "@cf/zai-org/glm-4.7-flash"), [{ type: "toggle" }])).toEqual([ + { id: "none", ...off }, + { id: "thinking", ...on }, + ]) + expect( + resolve(model(pkg, "@cf/qwen/qwen3.8-27b"), [ + { type: "toggle" }, + { type: "effort", values: ["low", "medium", "xhigh"] }, + ]), + ).toEqual([ + { id: "none", ...off }, + { id: "low", settings: { reasoningEffort: "low" } }, + { id: "medium", settings: { reasoningEffort: "medium" } }, + { id: "xhigh", settings: { reasoningEffort: "xhigh" } }, + ]) +}) + test("spells Chat Completions variants for hosting providers", () => { expect( resolve(model("@opencode/ai/providers/openai-compatible", "deepseek-ai/deepseek-v4-pro", undefined, "nvidia"), [