@magpie-community/opencode-kiro-auth 0.1.30 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +155 -36
- package/opencode2.mjs +0 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto"
|
|
|
21
21
|
import { execFile } from "node:child_process"
|
|
22
22
|
import { existsSync, statSync } from "node:fs"
|
|
23
23
|
import { readFile, rename, writeFile } from "node:fs/promises"
|
|
24
|
-
import { homedir, hostname } from "node:os"
|
|
24
|
+
import { homedir, hostname, platform, release } from "node:os"
|
|
25
25
|
import { delimiter, join } from "node:path"
|
|
26
26
|
|
|
27
27
|
const ID = "kiro"
|
|
@@ -40,7 +40,10 @@ const CALLBACK_PORTS = [3128, 4649, 6588, 8008, 9091, 49153, 50153, 51153, 52153
|
|
|
40
40
|
const SCOPES = ["codewhisperer:completions", "codewhisperer:analysis", "codewhisperer:conversations",
|
|
41
41
|
"codewhisperer:transformations", "codewhisperer:taskassist"]
|
|
42
42
|
// how the IDE names itself to Kiro's auth service, and when refreshing
|
|
43
|
-
|
|
43
|
+
// MACHINE_ID stands where the IDE puts its machine id (node-machine-id's
|
|
44
|
+
// sha256): one per install, the same on every call.
|
|
45
|
+
const MACHINE_ID = createHash("sha256").update("magpie:" + hostname()).digest("hex")
|
|
46
|
+
const IDE_UA = "KiroIDE-1.1.70-" + MACHINE_ID
|
|
44
47
|
const DESKTOP_UA = "Kiro-Desktop/0.2.13 (darwin; arm64)"
|
|
45
48
|
const SIGN_IN_TIMEOUT = 10 * 60 * 1000
|
|
46
49
|
// A Builder ID sign-in has no profile of its own, and Kiro won't list one
|
|
@@ -704,7 +707,7 @@ function account(client) {
|
|
|
704
707
|
// kiro-cli names no profile in an API key's calls, even one GetProfile
|
|
705
708
|
// found; the profile only says the key's region
|
|
706
709
|
const profile = c.method === "apikey" ? "" : c.profile
|
|
707
|
-
const a = { token: c.access, tokenType: tokenType(c), profile, region: regionOf(c.profile, c.region) }
|
|
710
|
+
const a = { token: c.access, tokenType: tokenType(c), idc: c.method === "idc", profile, region: regionOf(c.profile, c.region) }
|
|
708
711
|
if (!twoRegions(c) || st.builderID || !c.profiles) return a
|
|
709
712
|
// the first enabled region with credits left, in CREDIT_REGIONS' order
|
|
710
713
|
const now = Date.now()
|
|
@@ -1067,14 +1070,14 @@ function inputSchema(s) {
|
|
|
1067
1070
|
|
|
1068
1071
|
// buildKiro is the body of a generateAssistantResponse call, as it is
|
|
1069
1072
|
// before its images are fitted (kiroBody).
|
|
1070
|
-
function buildKiro(req, model, profile, budget) {
|
|
1071
|
-
return JSON.stringify(kiroRequest(req, model, profile, budget))
|
|
1073
|
+
function buildKiro(req, model, profile, budget, conversation) {
|
|
1074
|
+
return JSON.stringify(kiroRequest(req, model, profile, budget, conversation))
|
|
1072
1075
|
}
|
|
1073
1076
|
|
|
1074
1077
|
// kiroBody is the body sent: buildKiro's, with every image it keeps under
|
|
1075
1078
|
// Kiro's size limit.
|
|
1076
|
-
async function kiroBody(req, model, profile, budget) {
|
|
1077
|
-
return JSON.stringify(await fitImages(kiroRequest(req, model, profile, budget)))
|
|
1079
|
+
async function kiroBody(req, model, profile, budget, conversation) {
|
|
1080
|
+
return JSON.stringify(await fitImages(kiroRequest(req, model, profile, budget, conversation)))
|
|
1078
1081
|
}
|
|
1079
1082
|
|
|
1080
1083
|
// UNDERSTOOD is the reply Kiro IDE puts in its history where a turn has
|
|
@@ -1105,7 +1108,7 @@ function contextFirst(messages) {
|
|
|
1105
1108
|
return [...messages.slice(0, start), ...context.map((m) => ({ ...m, role: "user" })), { role: "assistant", content: UNDERSTOOD }, ...turn]
|
|
1106
1109
|
}
|
|
1107
1110
|
|
|
1108
|
-
function kiroRequest(req, model, profile, budget) {
|
|
1111
|
+
function kiroRequest(req, model, profile, budget, conversation) {
|
|
1109
1112
|
const entries = []
|
|
1110
1113
|
// the messages the caller marked for its prompt cache (cache_control),
|
|
1111
1114
|
// which go to Kiro as a cachePoint on the message they end up in (#110)
|
|
@@ -1113,7 +1116,7 @@ function kiroRequest(req, model, profile, budget) {
|
|
|
1113
1116
|
const mark = (msg, parts) => {
|
|
1114
1117
|
if (parts.some((p) => p?.cache_control)) marked.add(msg)
|
|
1115
1118
|
}
|
|
1116
|
-
const user = () => ({ content: "", modelId: model, origin: "
|
|
1119
|
+
const user = () => ({ content: "", modelId: model, origin: "AI_EDITOR" })
|
|
1117
1120
|
const resultsOnly = new WeakSet() // the messages made to carry a reply's web search results
|
|
1118
1121
|
for (const m of contextFirst(req.messages ?? [])) {
|
|
1119
1122
|
const parts = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content ?? []
|
|
@@ -1294,37 +1297,143 @@ function kiroRequest(req, model, profile, budget) {
|
|
|
1294
1297
|
}
|
|
1295
1298
|
for (const drop of points.slice(0, Math.max(0, points.length - 4))) drop()
|
|
1296
1299
|
|
|
1297
|
-
const state = { chatTriggerType: "MANUAL", agentTaskType: "vibe", conversationId:
|
|
1300
|
+
const state = { chatTriggerType: "MANUAL", agentTaskType: "vibe", conversationId: conversationID(conversation), currentMessage: { userInputMessage: current } }
|
|
1298
1301
|
if (entries.length > 1) state.history = entries.slice(0, -1)
|
|
1299
|
-
|
|
1302
|
+
// the agent mode goes as a header (x-amzn-kiro-agent-mode), as the IDE's
|
|
1303
|
+
// client binds it, not in the body
|
|
1304
|
+
const out = { conversationState: state }
|
|
1300
1305
|
if (profile) out.profileArn = profile
|
|
1301
1306
|
if (native) out.additionalModelRequestFields = native
|
|
1302
1307
|
return out
|
|
1303
1308
|
}
|
|
1304
1309
|
|
|
1305
|
-
//
|
|
1306
|
-
//
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
+
// conversationID is the conversationId of a chat call. The IDE keeps one
|
|
1311
|
+
// for a whole conversation; the plugin keeps one for the caller's session
|
|
1312
|
+
// (magpie's X-Magpie-Conversation), the same id on each turn of it, and a
|
|
1313
|
+
// new one when it can't tell the session.
|
|
1314
|
+
function conversationID(key) {
|
|
1315
|
+
if (!key) return randomUUID()
|
|
1316
|
+
const h = createHash("sha256").update("kiro-conversation:" + key).digest("hex")
|
|
1317
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-${"89ab"[parseInt(h[16], 16) & 3]}${h.slice(17, 20)}-${h.slice(20, 32)}`
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// the headers that name the caller's session, the first one sent
|
|
1321
|
+
const SESSION_HEADERS = ["x-magpie-conversation", "x-magpie-session", "x-opencode-session"]
|
|
1322
|
+
function sessionOf(input, init) {
|
|
1323
|
+
const sets = [init?.headers, input instanceof Request ? input.headers : undefined]
|
|
1324
|
+
for (const name of SESSION_HEADERS)
|
|
1325
|
+
for (const h of sets) {
|
|
1326
|
+
if (!h) continue
|
|
1327
|
+
const v = h instanceof Headers ? h.get(name)
|
|
1328
|
+
: Array.isArray(h) ? h.find(([k]) => k.toLowerCase() === name)?.[1]
|
|
1329
|
+
: Object.entries(h).find(([k]) => k.toLowerCase() === name)?.[1]
|
|
1330
|
+
if (v) return String(v)
|
|
1331
|
+
}
|
|
1332
|
+
return ""
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// What Kiro IDE 1.4.121 (its agent, KAS 0.66.89, on Electron 44's Node
|
|
1336
|
+
// 24.22.1) sends on a chat call, read from the IDE's own extension.js. Its
|
|
1337
|
+
// KiroRuntime client (@amzn/kiro-runtime-service-typescript-client 1.0.0)
|
|
1338
|
+
// is the AWS SDK for JavaScript's: the SDK's user agent, m/N for the
|
|
1339
|
+
// endpoint the IDE names itself, then the IDE's own "KiroIDE <version>
|
|
1340
|
+
// <machine id>" with KAS/<version> and acp-client/kiro-ide, spaces made
|
|
1341
|
+
// "-". Its retry budget is 3 tries, said in amz-sdk-request and
|
|
1342
|
+
// x-amzn-kiro-attempt, which count up on each (see paced).
|
|
1343
|
+
const IDE_VERSION = "1.4.121"
|
|
1344
|
+
const IDE_KAS = "0.66.89"
|
|
1345
|
+
const IDE_NODE = "24.22.1"
|
|
1346
|
+
const IDE_APP = `KiroIDE-${IDE_VERSION}-${MACHINE_ID}-KAS/${IDE_KAS} acp-client/kiro-ide`
|
|
1347
|
+
const sdkPart = (s) => String(s).replace(/[^!$%&'*+\-.^_`|~\w#]/g, "-")
|
|
1348
|
+
const IDE_SDK_UA = `aws-sdk-js/1.0.0 ua/2.1 os/${sdkPart(platform())}#${sdkPart(release())} lang/js md/nodejs#${IDE_NODE} api/kiroruntime#1.0.0 m/N ${IDE_APP}`
|
|
1349
|
+
|
|
1350
|
+
// sdkHeaders are the AWS SDK's headers on a call to Kiro's runtime, as the
|
|
1351
|
+
// Kiro IDE's client sends them: who is calling, and as which client. The
|
|
1352
|
+
// IDE names a Builder ID or Identity Center token's kind (SSO_OIDC) too.
|
|
1353
|
+
function sdkHeaders(a, attempt = 1, invocation = randomUUID()) {
|
|
1354
|
+
const h = {
|
|
1310
1355
|
...authHeaders(a),
|
|
1311
|
-
"amz-sdk-invocation-id":
|
|
1312
|
-
"amz-sdk-request":
|
|
1313
|
-
"x-amz-user-agent":
|
|
1314
|
-
"User-Agent":
|
|
1356
|
+
"amz-sdk-invocation-id": invocation,
|
|
1357
|
+
"amz-sdk-request": `attempt=${attempt}; max=${TRIES}`,
|
|
1358
|
+
"x-amz-user-agent": `aws-sdk-js/1.0.0 ${IDE_APP}`,
|
|
1359
|
+
"User-Agent": IDE_SDK_UA,
|
|
1360
|
+
"x-amzn-kiro-client-attribution": "kiro-ide",
|
|
1315
1361
|
}
|
|
1362
|
+
if (!a.tokenType && a.idc) h.tokentype = "SSO_OIDC"
|
|
1363
|
+
return h
|
|
1316
1364
|
}
|
|
1317
1365
|
|
|
1318
|
-
function sendKiro(a, body, signal) {
|
|
1366
|
+
function sendKiro(a, body, signal, attempt = 1, invocation) {
|
|
1319
1367
|
return fetch(runtime(a.region) + "/generateAssistantResponse", {
|
|
1320
1368
|
method: "POST",
|
|
1321
|
-
headers: { ...sdkHeaders(a), "x-amzn-
|
|
1322
|
-
"Content-Type": "application/json", Accept: "application/vnd.amazon.eventstream" },
|
|
1369
|
+
headers: { ...sdkHeaders(a, attempt, invocation), "x-amzn-kiro-attempt": `${attempt};max=${TRIES}`, "x-amzn-codewhisperer-optout": "true",
|
|
1370
|
+
"x-amzn-kiro-agent-mode": "vibe", "Content-Type": "application/json", Accept: "application/vnd.amazon.eventstream" },
|
|
1323
1371
|
body,
|
|
1324
1372
|
signal,
|
|
1325
1373
|
})
|
|
1326
1374
|
}
|
|
1327
1375
|
|
|
1376
|
+
// TRIES is the Kiro IDE's tries of one chat call (its QClientRetryStrategy,
|
|
1377
|
+
// agent 1.1.787, QAf), the first included.
|
|
1378
|
+
const TRIES = 3
|
|
1379
|
+
// PACE is the IDE's pause before the nth try after a throttle (its
|
|
1380
|
+
// throttling backoff: 1s doubling, 20% either way, at most 20s), unless
|
|
1381
|
+
// Kiro said how long (retryAfterMilliseconds and the like).
|
|
1382
|
+
const PACE = { base: 1000, jitter: 0.2, max: 20_000 }
|
|
1383
|
+
const paceOf = (n) => Math.min(PACE.max, PACE.base * 2 ** (n - 1)) * (1 - PACE.jitter + Math.random() * 2 * PACE.jitter)
|
|
1384
|
+
// THROTTLES are the reasons the IDE takes a 429 for a throttle it waits
|
|
1385
|
+
// out and tries again (its C1p and ServiceThrottleError): a throttle
|
|
1386
|
+
// Kiro gives no reason for is one too. A daily, monthly or usage limit
|
|
1387
|
+
// is not (usedUpSaid), nor is INSUFFICIENT_MODEL_CAPACITY.
|
|
1388
|
+
const THROTTLES = new Set(["USER_REQUEST_RATE_EXCEEDED", "CREDIT_CONSUMPTION_RATE_EXCEEDED", "SERVICE_REQUEST_RATE_EXCEEDED"])
|
|
1389
|
+
function throttleSaid(text) {
|
|
1390
|
+
let e = {}
|
|
1391
|
+
try {
|
|
1392
|
+
e = JSON.parse(text) ?? {}
|
|
1393
|
+
} catch {}
|
|
1394
|
+
if (e.reason) return THROTTLES.has(e.reason)
|
|
1395
|
+
return !usedUpSaid(text) && !/INSUFFICIENT_MODEL_CAPACITY/.test(text) && /too many requests|throttl/i.test(text)
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
// timing is how the plugin waits; tests make it instant.
|
|
1399
|
+
const timing = {
|
|
1400
|
+
sleep: (ms, signal) =>
|
|
1401
|
+
new Promise((resolve, reject) => {
|
|
1402
|
+
if (signal?.aborted) return reject(aborted())
|
|
1403
|
+
const t = setTimeout(() => {
|
|
1404
|
+
signal?.removeEventListener("abort", stop)
|
|
1405
|
+
resolve()
|
|
1406
|
+
}, ms)
|
|
1407
|
+
const stop = () => {
|
|
1408
|
+
clearTimeout(t)
|
|
1409
|
+
reject(aborted())
|
|
1410
|
+
}
|
|
1411
|
+
signal?.addEventListener("abort", stop, { once: true })
|
|
1412
|
+
}),
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// paced is sendKiro as the Kiro IDE sends a chat call: a 429 throttle is
|
|
1416
|
+
// waited out and tried again, up to TRIES in all, each try said in
|
|
1417
|
+
// amz-sdk-request and x-amzn-kiro-attempt under one invocation id. The
|
|
1418
|
+
// IDE answers its own USER_REQUEST_RATE_EXCEEDED so ("Retrying in N
|
|
1419
|
+
// seconds"), which is why a burst it rides out reached magpie's agent
|
|
1420
|
+
// as a 429 (onemezao on Discord). A wait Kiro says is longer than PACE.max
|
|
1421
|
+
// isn't held here: the 429 goes back with it, for magpie to rest the
|
|
1422
|
+
// account. The answer of the last try is the answer.
|
|
1423
|
+
async function paced(a, body, signal) {
|
|
1424
|
+
const invocation = randomUUID()
|
|
1425
|
+
for (let n = 1; ; n++) {
|
|
1426
|
+
const res = await sendKiro(a, body, signal, n, invocation)
|
|
1427
|
+
if (res.status !== 429 || n >= TRIES) return res
|
|
1428
|
+
const text = (await res.text()).slice(0, 1 << 20)
|
|
1429
|
+
const again = () => new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers })
|
|
1430
|
+
if (!throttleSaid(text)) return again()
|
|
1431
|
+
const said = saidWait(res.headers, text)
|
|
1432
|
+
if (said > PACE.max) return again()
|
|
1433
|
+
await timing.sleep(said ?? paceOf(n), signal)
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1328
1437
|
// tooLongSaid is whether Kiro's words say the conversation is past the
|
|
1329
1438
|
// model's window: its ValidationException "Input is too long." with reason
|
|
1330
1439
|
// CONTENT_LENGTH_EXCEEDS_THRESHOLD, as an HTTP answer or as an exception
|
|
@@ -1399,6 +1508,14 @@ const requestID = (headers) => headers.get("x-amzn-requestid") || headers.get("x
|
|
|
1399
1508
|
// seconds or as a date. Unsaid, magpie keeps to its own pauses, but for
|
|
1400
1509
|
// an account's request rate (USER_RATE_WAIT).
|
|
1401
1510
|
function waitOf(headers, body) {
|
|
1511
|
+
let w = saidWait(headers, body)
|
|
1512
|
+
if (w === undefined && String(body ?? "").includes(USER_RATE)) w = USER_RATE_WAIT
|
|
1513
|
+
return w
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// saidWait is the wait Kiro itself said, if any (waitOf, but none of
|
|
1517
|
+
// magpie's own).
|
|
1518
|
+
function saidWait(headers, body) {
|
|
1402
1519
|
const ms = (v) => {
|
|
1403
1520
|
const n = v == null || v === "" ? NaN : Number(v)
|
|
1404
1521
|
return Number.isFinite(n) && n > 0 ? n : undefined
|
|
@@ -1413,7 +1530,6 @@ function waitOf(headers, body) {
|
|
|
1413
1530
|
const secs = ms(ra)
|
|
1414
1531
|
w = secs !== undefined ? secs * 1000 : ms(Date.parse(ra) - Date.now())
|
|
1415
1532
|
}
|
|
1416
|
-
if (w === undefined && String(body ?? "").includes(USER_RATE)) w = USER_RATE_WAIT
|
|
1417
1533
|
return w
|
|
1418
1534
|
}
|
|
1419
1535
|
|
|
@@ -1600,10 +1716,13 @@ async function* events(body, model, budget) {
|
|
|
1600
1716
|
if (budget) yield* think.feed(text)
|
|
1601
1717
|
else if (text) yield { kind: "text", text }
|
|
1602
1718
|
} else if (kind === "reasoningContentEvent") {
|
|
1719
|
+
// one event may carry the reasoning and its signature together (auto,
|
|
1720
|
+
// called as the IDE): the signature goes on the block it ends
|
|
1603
1721
|
if (m.text) {
|
|
1604
1722
|
said += m.text.length
|
|
1605
1723
|
yield { kind: "think", text: m.text }
|
|
1606
|
-
}
|
|
1724
|
+
}
|
|
1725
|
+
if (m.signature) yield { kind: "sig", text: m.signature }
|
|
1607
1726
|
} else if (kind === "toolUseEvent") {
|
|
1608
1727
|
if (m.toolUseId && m.toolUseId !== tool) {
|
|
1609
1728
|
yield* think.end() // the text before a call is all said
|
|
@@ -2052,20 +2171,20 @@ function searchAnswer(text, hosted) {
|
|
|
2052
2171
|
// refreshed, when Kiro turns the token down (403). As the built-in: no
|
|
2053
2172
|
// credentials is a 401, a failed refresh after the 403 a 502; none marks
|
|
2054
2173
|
// the account.
|
|
2055
|
-
async function generate(creds, auth, req, signal) {
|
|
2174
|
+
async function generate(creds, auth, req, signal, conversation) {
|
|
2056
2175
|
const model = String(req.model ?? "auto")
|
|
2057
2176
|
const budget = thinking(req, model)
|
|
2058
2177
|
const hosted = hostedSearch(req)
|
|
2059
2178
|
if (hosted?.error) return errorResponse(400, hosted.error)
|
|
2060
|
-
const first = await ask(creds, auth, req, model, budget, signal)
|
|
2179
|
+
const first = await ask(creds, auth, req, model, budget, signal, conversation)
|
|
2061
2180
|
if (!first.res) return errorResponse(first.status, first.message, first.wait)
|
|
2062
|
-
const it = hosted ? searching(creds, auth, req, model, budget, signal, hosted, first) : events(first.res.body, model, budget)
|
|
2181
|
+
const it = hosted ? searching(creds, auth, req, model, budget, signal, hosted, first, conversation) : events(first.res.body, model, budget)
|
|
2063
2182
|
return kept(await reply(it, model, req.stream === true, toolNames(req)))
|
|
2064
2183
|
}
|
|
2065
2184
|
|
|
2066
2185
|
// ask sends one turn to Kiro: { res, a }, a 200, or the { status, message }
|
|
2067
2186
|
// of a failure.
|
|
2068
|
-
async function ask(creds, auth, req, model, budget, signal) {
|
|
2187
|
+
async function ask(creds, auth, req, model, budget, signal, conversation) {
|
|
2069
2188
|
let a
|
|
2070
2189
|
try {
|
|
2071
2190
|
a = await creds(auth)
|
|
@@ -2074,7 +2193,7 @@ async function ask(creds, auth, req, model, budget, signal) {
|
|
|
2074
2193
|
}
|
|
2075
2194
|
let res
|
|
2076
2195
|
try {
|
|
2077
|
-
res = await
|
|
2196
|
+
res = await paced(a, await kiroBody(req, model, a.profile, budget, conversation), signal)
|
|
2078
2197
|
} catch (e) {
|
|
2079
2198
|
if (e?.name === "AbortError") throw e
|
|
2080
2199
|
return { status: 502, message: e.message }
|
|
@@ -2087,7 +2206,7 @@ async function ask(creds, auth, req, model, budget, signal) {
|
|
|
2087
2206
|
return { status: 502, message: e.message }
|
|
2088
2207
|
}
|
|
2089
2208
|
try {
|
|
2090
|
-
res = await
|
|
2209
|
+
res = await paced(a, await kiroBody(req, model, a.profile, budget, conversation), signal)
|
|
2091
2210
|
} catch (e) {
|
|
2092
2211
|
if (e?.name === "AbortError") throw e
|
|
2093
2212
|
return { status: 502, message: e.message }
|
|
@@ -2112,7 +2231,7 @@ async function ask(creds, auth, req, model, budget, signal) {
|
|
|
2112
2231
|
if (tried.has(next.region)) return { status: 429, message: regionsUsedUp(next) + f.message, wait: f.wait }
|
|
2113
2232
|
a = next
|
|
2114
2233
|
try {
|
|
2115
|
-
res = await
|
|
2234
|
+
res = await paced(a, await kiroBody(req, model, a.profile, budget, conversation), signal)
|
|
2116
2235
|
} catch (e) {
|
|
2117
2236
|
if (e?.name === "AbortError") throw e
|
|
2118
2237
|
return { status: 502, message: e.message }
|
|
@@ -2142,7 +2261,7 @@ const aborted = () => Object.assign(new Error("the request was cancelled"), { na
|
|
|
2142
2261
|
// caller's (passed on as ever, the searches of its turn with it), or has
|
|
2143
2262
|
// taken hosted.uses + 2 turns (pause_turn, which the caller may send back
|
|
2144
2263
|
// to go on). Searches past hosted.uses are max_uses_exceeded.
|
|
2145
|
-
async function* searching(creds, auth, req, model, budget, signal, hosted, first) {
|
|
2264
|
+
async function* searching(creds, auth, req, model, budget, signal, hosted, first, conversation) {
|
|
2146
2265
|
let { res, a } = first
|
|
2147
2266
|
const messages = [...(req.messages ?? [])]
|
|
2148
2267
|
const usage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reported: false, searches: 0 }
|
|
@@ -2254,7 +2373,7 @@ async function* searching(creds, auth, req, model, budget, signal, hosted, first
|
|
|
2254
2373
|
return
|
|
2255
2374
|
}
|
|
2256
2375
|
messages.push({ role: "assistant", content: said })
|
|
2257
|
-
const next = await ask(creds, auth, { ...req, messages }, model, budget, signal)
|
|
2376
|
+
const next = await ask(creds, auth, { ...req, messages }, model, budget, signal, conversation)
|
|
2258
2377
|
if (!next.res) {
|
|
2259
2378
|
yield { kind: "error", status: next.status, text: `Kiro, after its web search: ${next.message} (${next.status})` }
|
|
2260
2379
|
return
|
|
@@ -2598,7 +2717,7 @@ export async function KiroAuthPlugin({ client } = {}) {
|
|
|
2598
2717
|
} catch {
|
|
2599
2718
|
return errorResponse(400, "a request that isn't JSON")
|
|
2600
2719
|
}
|
|
2601
|
-
return generate(creds, (await getAuth()) ?? auth, req, init.signal)
|
|
2720
|
+
return generate(creds, (await getAuth()) ?? auth, req, init.signal, sessionOf(input, init))
|
|
2602
2721
|
},
|
|
2603
2722
|
}
|
|
2604
2723
|
},
|
|
@@ -2684,4 +2803,4 @@ export async function KiroAuthPlugin({ client } = {}) {
|
|
|
2684
2803
|
}
|
|
2685
2804
|
|
|
2686
2805
|
// for tests
|
|
2687
|
-
export const _internal = { generate, waitOf, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
|
|
2806
|
+
export const _internal = { generate, waitOf, timing, TRIES, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
|
package/opencode2.mjs
CHANGED
|
@@ -85,7 +85,6 @@ export function fieldsOf(prompts) {
|
|
|
85
85
|
if (p.placeholder) f.placeholder = String(p.placeholder)
|
|
86
86
|
if (p.type === "select" && Array.isArray(p.options))
|
|
87
87
|
f.options = p.options.map((o) => ({ value: String(o.value), label: String(o.label ?? o.value), ...(o.hint ? { description: String(o.hint) } : {}) }))
|
|
88
|
-
// a prompt shown only when another answer says so can't be required
|
|
89
88
|
// a prompt shown only when another answer says so can't be required, and
|
|
90
89
|
// neither can one whose own validate() accepts an empty answer (the
|
|
91
90
|
// browser sign-in's optional API key)
|