Accounts signed in to Kiro elsewhere (Kiro Account Manager lists and exports, kiro2api, the Kiro IDE's kiro-auth-token.json with its <clientIdHash>.json client, kiro-cli's tokens) are imported in magpie's "Import accounts from a file…" by their refresh token. Each is renewed where its kind is renewed (Google/GitHub at prod.us-east-1.auth.desktop.kiro.dev, Builder ID / Identity Center at oidc.<region>.amazonaws.com with its client) and named by the email Kiro has for it. Other providers' entries in a sign-in store are skipped, duplicates are renewed once, at most 100 a time. A region or profile ARN read from a file can't pick a host any more, on every route (import, the IDE's file, kiro-cli's DB, a saved sign-in): regionOf takes only Kiro's API regions (us-east-1, eu-central-1) from a profile, arnOf keeps only arn:aws:codewhisperer:<region>:<12 digits>:profile/<id> (else Kiro is asked for it), and oidc/runtime/management/refreshURL refuse a region that isn't an AWS region's shape. Version 0.1.40: #1156 published 0.1.39 first, so main was merged into the branch and the version raised (f8af341f). With arnOf, #1156's test fixture ARN (account "1") was dropped and its reasoning-replay test went red on the merge; every test fixture ARN now has a 12-digit account (0b899428). What was run, on mote with HOME=$(mktemp -d) as CI: - PR head 41938ff0, packages/kiro: bun test, 202 pass, 0 fail. - The earlier review's repro (imported Google sign-in, fresh access token, profileArn arn:aws:codewhisperer:attacker.example/#:1:profile/X): at 41938ff0 every request goes to *.kiro.dev, nothing saved with the crafted ARN. With 5dd9e682's index.mjs put back it and all five profile-host.test.mjs tests are red (hosts [management.attacker.example]). - Merged head f8af341f (main atbaeb95a4): root bun test, 8771 pass, 1 fail (reasoning-replay's fixture, above). - Reviewed head 0b899428: root bun test, 8772 pass, 0 fail, 613 files. Main since gained only2523b43a(packages/agy-cli/test/smoke.mjs). Read for credential safety: no logging; errors carry no token; refresh tokens and client secrets go only to Kiro's auth service and AWS OIDC; an imported sign-in has no dbKey/idePath, so renewing it writes back to no kiro-cli or IDE file. No .github, dependency or new host. Not tried: a real Kiro account imported from a real export.
149 lines
9.0 KiB
JavaScript
149 lines
9.0 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({ 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()
|
|
})
|
|
|
|
// #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:123456789012: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" } })
|
|
})
|
|
|
|
// #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(`<thinking_mode>enabled</thinking_mode><max_thinking_length>${b}</max_thinking_length>`)
|
|
}
|
|
})
|
|
|
|
test("GPT and Grok expose and send their catalog's native reasoning levels", async () => {
|
|
for (const id of ["gpt-5.6-luna", "gpt-5.6-sol", "grok-4.7"]) {
|
|
const levels = id.startsWith("gpt-") ? ["none", "low", "medium", "high", "xhigh", "max"] : ["low", "medium", "high", "xhigh"]
|
|
await listed([model(id, { type: "object", properties: { reasoning: { type: "object", properties: { effort: { type: "string", enum: levels, default: "high" } } } }, additionalProperties: false })])
|
|
for (const m of [_internal.configModel({ id }), _internal.runtimeModel({ id })]) expect(Object.keys(m.variants)).toEqual(levels)
|
|
for (const effort of levels) {
|
|
const body = repro(id, effort)
|
|
expect(body.additionalModelRequestFields).toEqual({ reasoning: { effort } })
|
|
expect(_internal.responsesBody(body).reasoning).toEqual({ effort })
|
|
}
|
|
if (id.startsWith("gpt-")) {
|
|
const req = { thinking: { type: "disabled" }, output_config: { effort: "high" }, messages: [{ role: "user", content: "q" }] }
|
|
expect(JSON.parse(_internal.buildKiro(req, id, "", 0)).additionalModelRequestFields).toEqual({ reasoning: { effort: "none" } })
|
|
}
|
|
}
|
|
})
|