kiro 0.1.31: reasoning sent with its signature in one event keeps it; chat as the Kiro IDE

Called as the Kiro IDE (previous commit), Kiro's auto ends a reply with
one reasoningContentEvent holding both text ("...") and a signature
(".KTR~~…"). events() read the text and dropped the signature, so the
reply had a thinking block with an empty one. Both are now kept: the
signature goes on the block the text began, streamed (signature_delta)
or not. The IDE's own reader (extension.js) keeps them together too.

Version 0.1.31 carries this and the IDE identity.

Run on mote: bun test in packages/kiro (152 pass), bun scripts/check.mjs
kiro, in a temp HOME.
Broken by hand: reasoning-signature.test.mjs (the payloads of a real
reply) against the old else-if, 2 of 2 red.
Real use (same sandbox as before): auto answered 200 with the thinking
block's signature kept, a second turn carrying that block back answered
200, and the streamed reply sent the signature_delta.
Not tried: a thinking model with a budget under the new identity.

Reported-by: onemezao
This commit is contained in:
yetone
2026-11-07 20:43:30 +08:00
parent 1d3b537c0d
commit b81000019f
3 changed files with 72 additions and 2 deletions
+4 -1
View File
@@ -1648,10 +1648,13 @@ async function* events(body, model, budget) {
if (budget) yield* think.feed(text)
else if (text) yield { kind: "text", text }
} else if (kind === "reasoningContentEvent") {
// one event may carry the reasoning and its signature together (auto,
// called as the IDE): the signature goes on the block it ends
if (m.text) {
said += m.text.length
yield { kind: "think", text: m.text }
} else if (m.signature) yield { kind: "sig", text: m.signature }
}
if (m.signature) yield { kind: "sig", text: m.signature }
} else if (kind === "toolUseEvent") {
if (m.toolUseId && m.toolUseId !== tool) {
yield* think.end() // the text before a call is all said
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-kiro-auth",
"version": "0.1.30",
"version": "0.1.31",
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
"type": "module",
"main": "./opencode.mjs",
@@ -0,0 +1,67 @@
// Called as the Kiro IDE (AI_EDITOR), Kiro's auto ends a reply with one
// reasoningContentEvent carrying text and its signature together. These are
// the payloads of a real reply (2026-11-07, auto, "Reply with the single word
// OK."); the signature was dropped and the block sent with an empty one.
import { test, expect } from "bun:test"
import { _internal } from "./index.mjs"
const { events, reply } = _internal
function frame(headers, payload) {
const enc = new TextEncoder()
const hs = []
for (const [k, v] of Object.entries(headers)) {
const name = enc.encode(k)
const val = enc.encode(v)
const h = new Uint8Array(1 + name.length + 1 + 2 + val.length)
h[0] = name.length
h.set(name, 1)
h[1 + name.length] = 7
new DataView(h.buffer).setUint16(2 + name.length, val.length)
h.set(val, 4 + name.length)
hs.push(h)
}
const hlen = hs.reduce((n, h) => n + h.length, 0)
const body = enc.encode(JSON.stringify(payload))
const total = 12 + hlen + body.length + 4
const out = new Uint8Array(total)
const v = new DataView(out.buffer)
v.setUint32(0, total)
v.setUint32(4, hlen)
let i = 12
for (const h of hs) {
out.set(h, i)
i += h.length
}
out.set(body, i)
return out
}
const stream = (...fs) =>
new ReadableStream({
start(c) {
for (const f of fs) c.enqueue(f)
c.close()
},
})
const ev = (type, payload) => frame({ ":message-type": "event", ":event-type": type }, payload)
const SIG = ".KTR~~eyJlbmNyeXB0aW9uUmVnaW9uIjpudWxsLCJtaW50ZWRBdE1zIjoxNzk0MDU1MjcyODg0LCJtb2RlbEhhc2giOiJ5RUxWOXhiY2Z3dlUiLCJzbG90cyI6W10sInYiOjF9"
const body = () => stream(
ev("assistantResponseEvent", { content: "OK", modelId: "auto" }),
ev("reasoningContentEvent", { signature: SIG, text: "..." }),
ev("metadataEvent", { stopReason: "END_TURN" }),
)
test("reasoning sent with its signature in one event keeps the signature", async () => {
const res = await reply(events(body(), "auto", 0), "auto", false)
const j = await res.json()
expect(j.content).toEqual([{ type: "text", text: "OK" }, { type: "thinking", thinking: "...", signature: SIG }])
})
test("streamed, the signature follows the reasoning in its block", async () => {
const res = await reply(events(body(), "auto", 0), "auto", true)
const out = await res.text()
expect(out).toContain(JSON.stringify({ type: "thinking_delta", thinking: "..." }))
expect(out).toContain(JSON.stringify({ type: "signature_delta", signature: SIG }))
})