kiro 0.1.12: a request's structured output (output_config.format) is told in the system prompt, as the built-in told it

Kiro's generateAssistantResponse has no field for the answer's format, so
magpie's built-in Kiro (internal/gateway/kiro.go, req.inSystem()) told
the model the schema at the end of the system prompt: "Respond with a
single JSON value and nothing else, matching this JSON schema:\n<schema>."
The plugin dropped output_config.format, and magpie's generic plugin path
falls back to inSystem only when an upstream answers 400 naming the
format, which the plugin never did, so a moved user asking for JSON got
prose. buildKiro now says the schema the same way, after the caller's
system prompt and before the thinking budget prefix. The AI SDK's
output_format is read too. A JSON object with no schema needs nothing
here: magpie's Anthropic body already tells it in the system prompt.

Run: HOME=$(mktemp -d) bun test in packages/kiro: 46 pass, 0 fail.
structured-output.test.mjs: 3 of its 4 tests red with the index.mjs
change taken out (the fourth checks a request with no format is
unchanged). bun scripts/check.mjs kiro: ok.
Not run: a real Kiro account, nor magpie end to end.
This commit is contained in:
yetone
2026-10-16 17:32:22 +08:00
parent fe5631c1cb
commit 060bda8f65
3 changed files with 55 additions and 1 deletions
+15
View File
@@ -645,6 +645,17 @@ function thinking(req, model) {
return 20000
}
// formatText is the structured output a request asks for, said in words:
// Anthropic's output_config.format (or the AI SDK's output_format) with a
// JSON schema, "" when it asks for none. A JSON object with no schema
// reaches the plugin already told in the system prompt, as Messages has no
// field for it.
function formatText(req) {
const f = req.output_config?.format ?? req.output_format
if (f?.type !== "json_schema" || !f.schema || typeof f.schema !== "object") return ""
return "Respond with a single JSON value and nothing else, matching this JSON schema:\n" + JSON.stringify(f.schema) + "."
}
// buildKiro is the body of a generateAssistantResponse call.
function buildKiro(req, model, profile, budget) {
const entries = []
@@ -756,6 +767,10 @@ function buildKiro(req, model, profile, budget) {
for (const e of entries) if (e.assistantResponseMessage && !e.assistantResponseMessage.toolUses.length) delete e.assistantResponseMessage.toolUses
// the instructions go at the head of the first message
let system = typeof req.system === "string" ? req.system : textOf(req.system)
// Kiro has no field for the answer's format: it is told in words, at the
// end of the instructions, as magpie's built-in tells it (inSystem)
const format = formatText(req)
if (format) system = system ? system + "\n\n" + format : format
if (budget) system = `<thinking_mode>enabled</thinking_mode><max_thinking_length>${budget}</max_thinking_length>` + (system ? "\n" + system : "")
if (system) entries[0].userInputMessage.content = system + "\n\n" + entries[0].userInputMessage.content
if (Array.isArray(req.system)) mark(entries[0].userInputMessage, req.system)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-kiro-auth",
"version": "0.1.11",
"version": "0.1.12",
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",
+39
View File
@@ -0,0 +1,39 @@
// A request's structured output reaches Kiro in words. Kiro's
// generateAssistantResponse has no field for the answer's format, so
// magpie's built-in told the model the schema in the system prompt
// (internal/gateway/kiro.go: req.inSystem(), format.go's instruction). The
// plugin dropped output_config.format, so a caller asking for JSON got
// prose back.
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { buildKiro } = _internal
const first = (r, budget = 0) => {
const s = JSON.parse(buildKiro(r, "claude-sonnet-4.5", "", budget)).conversationState
return (s.history?.[0] ?? s.currentMessage).userInputMessage.content
}
const schema = { type: "object", properties: { answer: { type: "string" } }, required: ["answer"], additionalProperties: false }
const told = 'Respond with a single JSON value and nothing else, matching this JSON schema:\n{"type":"object","properties":{"answer":{"type":"string"}},"required":["answer"],"additionalProperties":false}.'
test("output_config.format's schema is told at the end of the system prompt, as the built-in told it", () => {
const req = { system: "Be brief.", messages: [{ role: "user", content: "hi" }], output_config: { format: { type: "json_schema", schema } } }
expect(first(req)).toBe("Be brief.\n\n" + told + "\n\nhi")
})
test("with no system prompt the schema is the whole of it, after a thinking budget", () => {
const req = { messages: [{ role: "user", content: "hi" }], output_config: { effort: "high", format: { type: "json_schema", schema } } }
expect(first(req)).toBe(told + "\n\nhi")
expect(first(req, 30000)).toBe("<thinking_mode>enabled</thinking_mode><max_thinking_length>30000</max_thinking_length>\n" + told + "\n\nhi")
})
test("the AI SDK's output_format is told too", () => {
const req = { system: [{ type: "text", text: "Be brief." }], messages: [{ role: "user", content: "hi" }], output_format: { type: "json_schema", schema } }
expect(first(req)).toBe("Be brief.\n\n" + told + "\n\nhi")
})
test("a request with no format, or one with no schema, is sent as before", () => {
for (const extra of [{}, { output_config: { effort: "low" } }, { output_config: { format: { type: "json_schema" } } }, { output_config: { format: { type: "text" } } }]) {
const req = { system: "Be brief.", messages: [{ role: "user", content: "hi" }], ...extra }
expect(first(req)).toBe("Be brief.\n\nhi")
}
})