From 0bd0af311a60d98e333a5ce37a1174e55840a1c0 Mon Sep 17 00:00:00 2001 From: Yuhan Lei Date: Mon, 18 May 2026 21:21:08 +0800 Subject: [PATCH] fix(provider): widen Kimi anthropic-SDK thinking match to K2.x Cherry-pick from upstream anomalyco/opencode #23696 (commit 58232d896, 2026-04-21). Without this, Kimi for Coding K2.6 (k2p6) on the Anthropic SDK path never gets `thinking` enabled, the request is rejected by Moonshot's coding endpoint, and the user is stuck in a 10-attempt retry loop showing "The engine is currently overloaded, please try again later". Root cause: - `kimi-for-coding` uses `@ai-sdk/anthropic` but Kimi is not an Anthropic model. Moonshot's coding endpoint requires `thinking: enabled` on K2.x reasoning models or it returns a misleading overload-style error. - The existing transform only matched K2.5 ids (`k2p5`, `kimi-k2.5`, `kimi-k2p5`). K2.6 (`k2p6`) had no transform and went out unmodified. Change boundary: - transform.ts: substring match widened from `k2p5` -> `k2p` and from `kimi-k2.5` -> `kimi-k2.` in two places (variants() and options()). Now covers K2.5, K2.6, and future K2.x without further edits. - transform.test.ts: update the existing "Kimi anthropic thinking" block to assert K2.5 and K2.6 both get thinking enabled, while `kimi-k2-preview`, `kimi-k2`, and `kimi-k2-thinking` still don't. Out of scope: - This PR does not touch the OpenAI-compatible Kimi paths (volcengine plan, moonshot.cn, moonshot.ai). Those already have their own reasoning_content handling. --- packages/opencode/src/provider/transform.ts | 6 +++--- packages/opencode/test/provider/transform.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 779c6bad5..7bfee4869 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -683,7 +683,7 @@ export function variants(model: Provider.Model): Record { headers: {}, }) as any - test("enables thinking for the supported Kimi K2.5 anthropic variants", () => { - for (const apiId of ["kimi-k2.5", "kimi-k2p5", "k2p5"]) { + test("enables thinking for supported Kimi K2.x anthropic variants", () => { + for (const apiId of ["kimi-k2.5", "kimi-k2p5", "k2p5", "kimi-k2.6", "kimi-k2p6", "k2p6"]) { const result = ProviderTransform.options({ model: createModel(apiId), sessionID, @@ -493,8 +493,8 @@ describe("ProviderTransform.options - Kimi anthropic thinking", () => { } }) - test("does not broaden thinking to unrelated Kimi K2 or K2P variants", () => { - for (const apiId of ["kimi-k2.6", "kimi-k2-preview", "kimi-k2p6", "k2p6"]) { + test("does not enable thinking for Kimi variants that lack a K2 dot or K2P tag", () => { + for (const apiId of ["kimi-k2-preview", "kimi-k2", "kimi-k2-thinking"]) { const result = ProviderTransform.options({ model: createModel(apiId), sessionID,