Two problems from #538 (zengxiaosong): 1. xhigh and max both became a 50000 <max_thinking_length> budget. The plugin now reads each model's additionalModelRequestFieldsSchema from ListAvailableModels, as Kiro IDE 1.4.62 does: when the schema offers thinking.type "adaptive" and an effort enum under output_config (or reasoning), a level in that enum is sent as additionalModelRequestFields {thinking:{type:"adaptive"}, output_config:{effort}} and the XML budget is left out. A model with no such schema (every model on a Free account today: the schema is null), a level not in the enum, or thinking off, is sent as before. 2. System messages ending the conversation (Claude Code's environment context) were joined into the question. They now go as a user turn before the question, answered by "Understood." (Kiro IDE's placeholder for a missing assistant turn), and the question is the current message. Not moved when the question holds tool results or follows tool calls, so call/result pairs are unchanged. systemPrompt is not used: the reporter's account refuses it. Run (on mote, bun 1.4.2): - bun test packages/kiro: 115 pass. - Full suite as CI, HOME=$(mktemp -d) bun test: 3885 pass, 0 fail; bun scripts/check.mjs: ok. Broken by hand: - nativeFields never finding a model: the two schema tests go red. - contextFirst returning messages as given: the reporter's [user, system] test and the later-question test go red. - The new tests on origin/main's index.mjs: 6 fail (in part only because the new exports are missing there). Not tried: a real Kiro account whose catalog has a non-null schema. The only account here is Free, whose ListAvailableModels gives null for every model, so the schema shape is from Kiro IDE 1.4.62's source, and the fixture follows it.
96 lines
5.5 KiB
JavaScript
96 lines
5.5 KiB
JavaScript
import { test, expect, afterEach } from "bun:test"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
// Claude Code's levels are low, medium, high, xhigh and max: a thinking
|
|
// model offers each, so xhigh isn't routed as max (#120)
|
|
test("a thinking model offers xhigh as its own level", () => {
|
|
const m = { id: "claude-opus-5.5", name: "Claude Opus 5.5", context: 200000 }
|
|
for (const got of [_internal.configModel(m), _internal.runtimeModel(m)]) {
|
|
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)
|
|
// a model that doesn't think offers none
|
|
expect(_internal.configModel({ id: "deepseek-3.2", name: "DeepSeek" }).variants).toBeUndefined()
|
|
})
|
|
|
|
// #538 (zengxiaosong): Claude Code sends adaptive thinking with its level
|
|
// in output_config.effort, and xhigh and max both became one 50000
|
|
// <max_thinking_length>. A model whose Kiro list says it takes the effort
|
|
// as a field (additionalModelRequestFieldsSchema, read as Kiro IDE reads
|
|
// it) is sent each level there instead, and no budget; any other model is
|
|
// sent the budget as before.
|
|
const OPUS_SCHEMA = {
|
|
type: "object",
|
|
properties: {
|
|
thinking: { type: "object", properties: { type: { type: "string", enum: ["adaptive", "disabled"] } } },
|
|
output_config: { type: "object", properties: { effort: { type: "string", enum: ["low", "medium", "high", "xhigh", "max"] } } },
|
|
},
|
|
}
|
|
const listed = (models) => {
|
|
const was = globalThis.fetch
|
|
globalThis.fetch = async (input) => {
|
|
if (new URL(String(input)).pathname !== "/List-Available-Models") throw new Error("no network in tests")
|
|
return Response.json({ defaultModel: { modelId: "auto" }, models })
|
|
}
|
|
return _internal.listModels({ region: "us-east-1", token: "t", tokenType: "", profile: "arn:aws:codewhisperer:us-east-1:1:profile/P" })
|
|
.finally(() => (globalThis.fetch = was))
|
|
}
|
|
const model = (modelId, schema) => ({ modelId, modelName: modelId, tokenLimits: { maxInputTokens: 1000000, maxOutputTokens: 128000 },
|
|
additionalModelRequestFieldsSchema: schema })
|
|
afterEach(() => listed([model("claude-opus-5.5", null), model("claude-sonnet-4.5", null)]))
|
|
|
|
// the reporter's repro, as written in #538
|
|
const repro = (model, effort) => {
|
|
const req = {
|
|
model, system: "SESSION_INSTRUCTIONS",
|
|
thinking: { type: "adaptive" }, output_config: { effort },
|
|
messages: [
|
|
{ role: "user", content: "USER_QUESTION" },
|
|
{ role: "system", content: "ENV_CONTEXT", output_config: { effort } },
|
|
],
|
|
}
|
|
return JSON.parse(_internal.buildKiro(req, model, "", _internal.thinking(req, model)))
|
|
}
|
|
const said = (body) => [...(body.conversationState.history ?? []).map((e) => e.userInputMessage?.content ?? e.assistantResponseMessage?.content),
|
|
body.conversationState.currentMessage.userInputMessage.content].join("\n")
|
|
|
|
test("a model Kiro lists with effort fields is sent xhigh and max as two levels, with no budget", async () => {
|
|
await listed([model("claude-opus-5.5", OPUS_SCHEMA), model("claude-sonnet-4.5", null)])
|
|
const bodies = {}
|
|
for (const effort of ["xhigh", "max"]) {
|
|
const body = repro("claude-opus-5.5", effort)
|
|
expect(body.additionalModelRequestFields).toEqual({ thinking: { type: "adaptive" }, output_config: { effort } })
|
|
expect(said(body)).not.toContain("max_thinking_length")
|
|
expect(said(body)).not.toContain("thinking_mode")
|
|
delete body.conversationState.conversationId
|
|
bodies[effort] = JSON.stringify(body)
|
|
}
|
|
expect(bodies.xhigh).not.toBe(bodies.max)
|
|
// a level the model doesn't list keeps the budget
|
|
const req = { thinking: { type: "adaptive" }, output_config: { effort: "ultra" }, messages: [{ role: "user", content: "q" }] }
|
|
const odd = JSON.parse(_internal.buildKiro(req, "claude-opus-5.5", "", _internal.thinking(req, "claude-opus-5.5")))
|
|
expect(odd.additionalModelRequestFields).toBeUndefined()
|
|
expect(said(odd)).toContain("<max_thinking_length>20000</max_thinking_length>")
|
|
// thinking not asked for: no fields
|
|
const off = { output_config: { effort: "low" }, messages: [{ role: "user", content: "q" }] }
|
|
expect(JSON.parse(_internal.buildKiro(off, "claude-opus-5.5", "", _internal.thinking(off, "claude-opus-5.5"))).additionalModelRequestFields).toBeUndefined()
|
|
})
|
|
|
|
test("a model Kiro lists without effort fields keeps its budget", async () => {
|
|
// the list a Free account got on 2026-10-31: the field there, null
|
|
await listed([model("claude-opus-5.5", OPUS_SCHEMA), model("claude-sonnet-4.5", null)])
|
|
for (const effort of ["xhigh", "max"]) {
|
|
const body = repro("claude-sonnet-4.5", effort)
|
|
expect(body.additionalModelRequestFields).toBeUndefined()
|
|
expect(said(body)).toContain("<thinking_mode>enabled</thinking_mode><max_thinking_length>50000</max_thinking_length>")
|
|
}
|
|
// a schema with effort levels but no adaptive thinking isn't taken as one
|
|
const noAdaptive = { properties: { output_config: OPUS_SCHEMA.properties.output_config } }
|
|
await listed([model("claude-opus-5.5", noAdaptive)])
|
|
expect(repro("claude-opus-5.5", "max").additionalModelRequestFields).toBeUndefined()
|
|
// reasoning.effort, the schema's other place for it, as the IDE reads it
|
|
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" } })
|
|
})
|