Kiro answers 400 REQUEST_BODY_INVALID to a tool schema whose root has
properties and no type, or is {}: the root is now sent as type "object"
(copied; nothing under it changed, another explicit root type left alone).
Anthropic's hosted web search (web_search_20250305) is searched with Kiro's
own web_search, sent as kiro-cli 2.35 sends it: InvokeMCP at the runtime's
root (AWS JSON 1.0, x-amz-target AmazonCodeWhispererStreamingService.InvokeMCP),
a JSON-RPC tools/call with {query} only, the profile ARN in the body and in
x-amzn-kiro-profile-arn. The model is offered kiro-cli's own web_search spec
(with __tool_use_purpose, which is stripped before the caller sees it and
never searched). At most 10 searches per request (max_uses honoured), a
turn cap of uses+2 (pause_turn), 30s timeout and a 1 MiB cap per search.
The config hook says searches: true, which the user's own setting overrides.
Other web_search versions are a 400 that names provider.kiro.searches: false.
kiro 0.1.19 -> 0.1.20.
Author: SemonCat (#492)
Run at 993f9bae5628cd3d525a838bdc0319cc58968c03 on mote (macOS, Bun 1.4.2),
HOME=$(mktemp -d) as CI:
- bun test packages/kiro: 94 pass, 0 fail
- bun test (whole repo): 3563 pass, 8 skip, 0 fail
- bun scripts/check.mjs: every package ok, kiro included
- npm pack --dry-run in packages/kiro: 0.1.20, 3 files; node scripts/dist.mjs
into a scratch folder packs opencode-kiro-auth@0.1.20
Broken by hand, each red in packages/kiro: schema root sent raw (5 fail),
profileArn left out of the search body (1), the 10-search cap removed (1),
__tool_use_purpose kept in the caller's input (1).
Checked against kiro-cli 2.35.0's binary: the web_search description, the
query's description and maxLength, the __tool_use_purpose text and the
InvokeMCP target/content type are its strings; the fixture's result fields
(title, url, snippet, publishedDate, domain, id, maxVerbatimWordLimit,
publicDomain) are the output its tool spec documents.
The search goes to the same runtime.<region>.kiro.dev host as inference.
Not tried here: a live search (the author's record has one OAuth account,
Haiku 5.5, us-east-1); an API-key search live.
81 lines
4.1 KiB
JavaScript
81 lines
4.1 KiB
JavaScript
// Kiro turns down a tool whose input schema doesn't say type "object" at
|
|
// its root: {properties: {text: {type: "string"}}, required: ["text"]} is a
|
|
// 400 REQUEST_BODY_INVALID from Haiku 5.5, and the same with type "object"
|
|
// added a tool call; {} is a 400 too. A tool's input is always an object,
|
|
// so the root says so; nothing under it is touched.
|
|
import { expect, test, afterAll, afterEach } from "bun:test"
|
|
import { KiroAuthPlugin, _internal } from "./index.mjs"
|
|
|
|
const real = globalThis.fetch
|
|
const offline = async () => { throw new Error("no network in tests") }
|
|
globalThis.fetch = offline
|
|
afterEach(() => (globalThis.fetch = offline))
|
|
afterAll(() => (globalThis.fetch = real))
|
|
|
|
// sent asks through the plugin's fetch with these tools and gives the tool
|
|
// specifications Kiro was sent
|
|
async function sent(tools) {
|
|
let body
|
|
globalThis.fetch = async (url, init) => {
|
|
if (String(url).includes("generateAssistantResponse")) {
|
|
body = JSON.parse(init.body)
|
|
return new Response(JSON.stringify({ message: "stop here" }), { status: 500 })
|
|
}
|
|
return new Response("{}", { status: 400 }) // GetProfile: a key with no profile
|
|
}
|
|
const hooks = await KiroAuthPlugin({})
|
|
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ksk_test" }))
|
|
await l.fetch("https://kiro.invalid/v1/messages", { method: "POST",
|
|
body: JSON.stringify({ model: "claude-haiku-5.5", messages: [{ role: "user", content: "hi" }], tools }) })
|
|
return body.conversationState.currentMessage.userInputMessage.userInputMessageContext.tools.map((t) => t.toolSpecification.inputSchema.json)
|
|
}
|
|
const tool = (input_schema) => ({ name: "echo", description: "echo", input_schema })
|
|
|
|
test("a root with properties and no type is sent as an object, the rest as given", async () => {
|
|
const schema = { properties: { text: { type: "string" } }, required: ["text"] }
|
|
expect(await sent([tool(schema)])).toEqual([{ type: "object", properties: { text: { type: "string" } }, required: ["text"] }])
|
|
})
|
|
|
|
test("the caller's request object isn't changed", () => {
|
|
const req = { model: "auto", messages: [{ role: "user", content: "hi" }],
|
|
tools: [tool({ properties: { text: { type: "string" } } }), tool({ type: ["object", "null"] }), tool({})] }
|
|
const before = structuredClone(req)
|
|
const json = JSON.parse(_internal.buildKiro(req, "auto", "", 0))
|
|
expect(json.conversationState.currentMessage.userInputMessage.userInputMessageContext.tools[0].toolSpecification.inputSchema.json.type).toBe("object")
|
|
expect(req).toEqual(before)
|
|
})
|
|
|
|
test("an empty or missing schema is an object with no properties", async () => {
|
|
expect(await sent([tool({}), { name: "bare", description: "x" }])).toEqual([
|
|
{ type: "object", properties: {} }, { type: "object", properties: {} }])
|
|
})
|
|
|
|
test("an object root is sent exactly, its nested unions, refs and keywords kept", async () => {
|
|
const schema = {
|
|
type: "object", additionalProperties: false, $defs: { id: { type: "string" } },
|
|
properties: {
|
|
a: { anyOf: [{ type: "string" }, { type: "null" }] },
|
|
b: { oneOf: [{ $ref: "#/$defs/id" }, { type: "integer" }] },
|
|
c: { properties: { d: { type: "string" } } }, // a nested object without type stays so
|
|
e: { type: "string", nullable: true },
|
|
},
|
|
required: ["a"],
|
|
}
|
|
const before = structuredClone(schema)
|
|
expect(await sent([tool(schema)])).toEqual([before])
|
|
})
|
|
|
|
test("a typeless root union says object beside its branches, which are kept", async () => {
|
|
const schema = { anyOf: [{ properties: { x: { type: "string" } }, required: ["x"] }, { properties: { y: { type: "number" } } }] }
|
|
const [got] = await sent([tool(schema)])
|
|
expect(got.type).toBe("object")
|
|
expect(got.anyOf).toEqual(schema.anyOf)
|
|
expect(schema.type).toBeUndefined()
|
|
})
|
|
|
|
test("a nullable object root is an object; another explicit type is left as the caller said it", async () => {
|
|
expect((await sent([tool({ type: ["object", "null"], properties: { x: { type: "string" } } })]))[0])
|
|
.toEqual({ type: "object", properties: { x: { type: "string" } } })
|
|
expect((await sent([tool({ type: "string" })]))[0]).toEqual({ type: "string" })
|
|
})
|