Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,16 @@ export namespace ProviderTransform {
result["chat_template_args"] = { enable_thinking: true }
}

// kilocode_change - some thinking models (e.g. moonshot) require reasoning enabled
// see test/provider/transform.test.ts "thinking models require reasoning enabled"
if (
input.model.api.npm === "@kilocode/kilo-gateway" &&
input.model.capabilities.reasoning &&
input.model.api.id.includes("thinking")
) {
result["reasoning"] = { enabled: true }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Potential reasoning overwrite — the block above (line 771) sets result["reasoning"] = { effort: "high" } for kilo-gateway models whose api.id includes "gemini-3". This new block will overwrite that value with { enabled: true } if a model's api.id contains both "gemini-3" and "thinking" (e.g. a hypothetical google/gemini-3-thinking).

This is unlikely with current model names, but the ordering dependency is fragile. Consider adding an early-return guard (e.g. && !input.model.api.id.includes("gemini-3")) or restructuring to make the precedence explicit.

}

if (["zai", "zhipuai"].includes(input.model.providerID) && input.model.api.npm === "@ai-sdk/openai-compatible") {
result["thinking"] = {
type: "enabled",
Expand Down
75 changes: 75 additions & 0 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2158,5 +2158,80 @@ describe("ProviderTransform.smallOptions", () => {
expect(result).toEqual({ reasoning: { enabled: false } })
})
})

// Some thinking models via Kilo Gateway (observed with moonshot) require reasoning
// to be explicitly enabled. Use "thinking" in model name as heuristic rather than
// hard-coding provider/model names.
describe("thinking models require reasoning enabled", () => {
const sessionID = "test-session"

test("kimi-k2-thinking gets reasoning enabled", () => {
const model = createMockModel({
id: "kilo/moonshotai/kimi-k2-thinking",
providerID: "kilo",
reasoning: true,
api: {
id: "moonshotai/kimi-k2-thinking",
url: "https://gateway.kilo.ai",
npm: "@kilocode/kilo-gateway",
},
})
const result = ProviderTransform.options({ model, sessionID })
expect(result.reasoning).toEqual({ enabled: true })
})

test("any future -thinking model gets reasoning enabled", () => {
const model = createMockModel({
id: "kilo/someprovider/some-model-thinking",
providerID: "kilo",
reasoning: true,
api: {
id: "someprovider/some-model-thinking",
url: "https://gateway.kilo.ai",
npm: "@kilocode/kilo-gateway",
},
})
const result = ProviderTransform.options({ model, sessionID })
expect(result.reasoning).toEqual({ enabled: true })
})

test("non-thinking models do not get reasoning auto-enabled", () => {
const model = createMockModel({
id: "kilo/moonshotai/kimi-k2",
providerID: "kilo",
reasoning: true,
api: {
id: "moonshotai/kimi-k2",
url: "https://gateway.kilo.ai",
npm: "@kilocode/kilo-gateway",
},
})
const result = ProviderTransform.options({ model, sessionID })
expect(result.reasoning).toBeUndefined()
})

test("thinking model without reasoning capability does not get reasoning enabled", () => {
const model = createMockModel({
id: "kilo/someprovider/fake-thinking",
providerID: "kilo",
capabilities: {
temperature: true,
reasoning: false,
attachment: true,
toolcall: true,
input: { text: true, audio: false, image: true, video: false, pdf: false },
output: { text: true, audio: false, image: false, video: false, pdf: false },
interleaved: false,
},
api: {
id: "someprovider/fake-thinking",
url: "https://gateway.kilo.ai",
npm: "@kilocode/kilo-gateway",
},
})
const result = ProviderTransform.options({ model, sessionID })
expect(result.reasoning).toBeUndefined()
})
})
})
// kilocode_change end
Loading