diff --git a/packages/kiro/README.md b/packages/kiro/README.md index b64bf92..e1c644c 100644 --- a/packages/kiro/README.md +++ b/packages/kiro/README.md @@ -145,6 +145,10 @@ request: IDE sends it: `additionalModelRequestFields` with `thinking.type: "adaptive"` and `output_config.effort` (or `reasoning.effort`), and no budget. So xhigh and max stay apart there (#538). + Thinking is asked for only when the request's `thinking` is `enabled` or + `adaptive`. An effort with no `thinking`, or with it `disabled` (Claude + Code's title requests, or a turn with thinking off), is sent with no + thinking at any level. - Anthropic's hosted web search is answered with Kiro's own web search (see [Web search](#web-search)). - Kiro's failures keep their meaning: diff --git a/packages/kiro/effort.test.mjs b/packages/kiro/effort.test.mjs index ceea5bd..888dd0b 100644 --- a/packages/kiro/effort.test.mjs +++ b/packages/kiro/effort.test.mjs @@ -9,7 +9,7 @@ test("a thinking model offers xhigh as its own level", () => { expect(Object.keys(got.variants)).toEqual(["low", "medium", "high", "xhigh", "max"]) expect(got.variants.xhigh).toEqual({ thinking: { type: "enabled", budgetTokens: 50000 } }) } - expect(_internal.thinking({ output_config: { effort: "xhigh" } }, "claude-opus-5.5")).toBe(50000) + expect(_internal.thinking({ thinking: { type: "adaptive" }, output_config: { effort: "xhigh" } }, "claude-opus-5.5")).toBe(50000) // a model that doesn't think offers none expect(_internal.configModel({ id: "deepseek-3.2", name: "DeepSeek" }).variants).toBeUndefined() }) @@ -93,3 +93,39 @@ test("a model Kiro lists without effort fields keeps its budget", async () => { await listed([model("claude-opus-5.5", { properties: { thinking: OPUS_SCHEMA.properties.thinking, reasoning: OPUS_SCHEMA.properties.output_config } })]) expect(repro("claude-opus-5.5", "max").additionalModelRequestFields).toEqual({ thinking: { type: "adaptive" }, reasoning: { effort: "max" } }) }) + +// #538 (zengxiaosong): thinking is asked for by the thinking object alone. +// An effort with no thinking (Claude Code's title requests, or its turn with +// thinking off), or with thinking disabled, was sent a budget, or adaptive +// thinking at that level, for every effort above low. +test("an effort without thinking asked for is sent no thinking, at every level", async () => { + for (const schema of [OPUS_SCHEMA, null]) { + await listed([model("claude-opus-5.5", schema)]) + for (const effort of ["low", "medium", "high", "xhigh", "max"]) + for (const th of [undefined, { type: "disabled" }, { type: "between_tools" }]) { + const req = { ...(th ? { thinking: th } : {}), output_config: { effort }, messages: [{ role: "user", content: "q" }] } + expect(_internal.thinking(req, "claude-opus-5.5")).toBe(0) + const body = JSON.parse(_internal.buildKiro(req, "claude-opus-5.5", "", _internal.thinking(req, "claude-opus-5.5"))) + expect(body.additionalModelRequestFields).toBeUndefined() + expect(said(body)).not.toContain("thinking_mode") + } + } +}) + +// with thinking asked for, every level, low included, reaches Kiro as itself +// when the model lists it, and as the budget otherwise +test("each level with thinking on is the field Kiro lists, or its budget", async () => { + const budgets = { low: 10000, medium: 20000, high: 30000, xhigh: 50000, max: 50000 } + for (const th of [{ type: "adaptive" }, { type: "enabled", budget_tokens: 12345 }]) + for (const [effort, b] of Object.entries(budgets)) { + const req = { thinking: th, output_config: { effort }, messages: [{ role: "user", content: "q" }] } + await listed([model("claude-opus-5.5", OPUS_SCHEMA)]) + let body = JSON.parse(_internal.buildKiro(req, "claude-opus-5.5", "", _internal.thinking(req, "claude-opus-5.5"))) + expect(body.additionalModelRequestFields).toEqual({ thinking: { type: "adaptive" }, output_config: { effort } }) + expect(said(body)).not.toContain("max_thinking_length") + await listed([model("claude-opus-5.5", null)]) + body = JSON.parse(_internal.buildKiro(req, "claude-opus-5.5", "", _internal.thinking(req, "claude-opus-5.5"))) + expect(body.additionalModelRequestFields).toBeUndefined() + expect(said(body)).toContain(`enabled${b}`) + } +}) diff --git a/packages/kiro/index.mjs b/packages/kiro/index.mjs index f495855..6e8303c 100644 --- a/packages/kiro/index.mjs +++ b/packages/kiro/index.mjs @@ -842,10 +842,15 @@ function documentText(p) { } // thinking is whether the model is asked to think aloud, and for how -// long: when the caller asked for it, of a Claude model (or Auto). +// long: when the caller asked for it, of a Claude model (or Auto). Only a +// thinking of type enabled or adaptive asks for it, as Anthropic's API +// reads a request: an effort with no thinking (Claude Code's title and +// other side requests, or its main turn with thinking turned off), or with +// thinking disabled, is sent no thinking at any level (#538), as magpie's +// gateway reads it too. function thinking(req, model) { const effort = req.output_config?.effort ?? "" - const on = req.thinking?.type === "enabled" || req.thinking?.type === "adaptive" || (effort && effort !== "low") + const on = req.thinking?.type === "enabled" || req.thinking?.type === "adaptive" if (!on || !thinks(String(model).toLowerCase())) return 0 const budget = { low: 10000, high: 30000, xhigh: 50000, max: 50000 }[effort] if (budget) return budget diff --git a/packages/kiro/package.json b/packages/kiro/package.json index 793ec83..df42a1c 100644 --- a/packages/kiro/package.json +++ b/packages/kiro/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-kiro-auth", - "version": "0.1.22", + "version": "0.1.23", "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie", "type": "module", "main": "./index.mjs",