@magpie-community/opencode-kiro-auth 0.1.9 → 0.1.11

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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/index.mjs +27 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -85,7 +85,8 @@ request:
85
85
  tool calls and usage. When Kiro reports only how full the context is,
86
86
  input tokens are estimated from that.
87
87
  - Thinking (Claude models and Auto) is asked for the way kiro-cli asks, in
88
- the prompt, with a budget: low 10k, medium 20k, high 30k, max 50k. The
88
+ the prompt, with a budget: low 10k, medium 20k, high 30k, xhigh and max
89
+ 50k (as magpie's built-in Kiro: #120). The
89
90
  `<thinking>` block of the reply comes back as thinking.
90
91
  - Kiro's failures keep their meaning:
91
92
  - input too long → 400
package/index.mjs CHANGED
@@ -503,7 +503,9 @@ function account(client) {
503
503
  const windows = new Map() // a model's context, as Kiro last listed it
504
504
 
505
505
  const thinks = (id) => /claude/i.test(id) || id === "auto"
506
- const BUDGETS = { low: 10000, medium: 20000, high: 30000, max: 50000 }
506
+ // the levels a thinking model offers, as the built-in thinks them (xhigh as
507
+ // long as max: #120)
508
+ const BUDGETS = { low: 10000, medium: 20000, high: 30000, xhigh: 50000, max: 50000 }
507
509
 
508
510
  function configModel(m) {
509
511
  return {
@@ -646,6 +648,12 @@ function thinking(req, model) {
646
648
  // buildKiro is the body of a generateAssistantResponse call.
647
649
  function buildKiro(req, model, profile, budget) {
648
650
  const entries = []
651
+ // the messages the caller marked for its prompt cache (cache_control),
652
+ // which go to Kiro as a cachePoint on the message they end up in (#110)
653
+ const marked = new WeakSet()
654
+ const mark = (msg, parts) => {
655
+ if (parts.some((p) => p?.cache_control)) marked.add(msg)
656
+ }
649
657
  const user = () => ({ content: "", modelId: model, origin: "KIRO_CLI" })
650
658
  for (const m of req.messages ?? []) {
651
659
  const parts = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content ?? []
@@ -666,6 +674,7 @@ function buildKiro(req, model, profile, budget) {
666
674
  prev.content = joinNonEmpty(prev.content, a.content)
667
675
  prev.toolUses.push(...a.toolUses)
668
676
  } else entries.push({ assistantResponseMessage: a })
677
+ mark(prev ?? a, parts)
669
678
  continue
670
679
  }
671
680
  const u = user()
@@ -693,6 +702,7 @@ function buildKiro(req, model, profile, budget) {
693
702
  prev.images.push(...u.images)
694
703
  if (results.length) (prev.userInputMessageContext ??= { toolResults: [] }).toolResults.push(...results)
695
704
  } else entries.push({ userInputMessage: u })
705
+ mark(prev ?? u, parts)
696
706
  }
697
707
  // the conversation opens with something the user said: tool results with
698
708
  // no call before them go, and a reply the caller began with
@@ -748,6 +758,7 @@ function buildKiro(req, model, profile, budget) {
748
758
  let system = typeof req.system === "string" ? req.system : textOf(req.system)
749
759
  if (budget) system = `<thinking_mode>enabled</thinking_mode><max_thinking_length>${budget}</max_thinking_length>` + (system ? "\n" + system : "")
750
760
  if (system) entries[0].userInputMessage.content = system + "\n\n" + entries[0].userInputMessage.content
761
+ if (Array.isArray(req.system)) mark(entries[0].userInputMessage, req.system)
751
762
 
752
763
  // the caller's tools, and any the conversation used that it no longer
753
764
  // offers — Kiro rejects a history naming a tool it wasn't given
@@ -760,6 +771,7 @@ function buildKiro(req, model, profile, budget) {
760
771
  const name = toolName(t.name)
761
772
  offered.add(name)
762
773
  tools.push({ toolSpecification: { name, description: t.description || t.name, inputSchema: { json: t.input_schema ?? EMPTY } } })
774
+ if (t.cache_control) tools.push({ cachePoint: { type: "default" } })
763
775
  }
764
776
  for (const e of entries)
765
777
  for (const c of e.assistantResponseMessage?.toolUses ?? [])
@@ -768,6 +780,19 @@ function buildKiro(req, model, profile, budget) {
768
780
  tools.push({ toolSpecification: { name: c.name, description: "Tool", inputSchema: { json: EMPTY } } })
769
781
  }
770
782
  if (tools.length) (current.userInputMessageContext ??= {}).tools = tools
783
+ // Kiro's cachePoint is Bedrock's: it caches the prompt up to the point,
784
+ // and a request may hold 4 at most, as Anthropic's cache_control; past
785
+ // that the last ones are kept, the most of the prompt they cover
786
+ const points = []
787
+ for (const t of tools) if (t.cachePoint) points.push(() => tools.splice(tools.indexOf(t), 1))
788
+ for (const e of entries) {
789
+ const msg = e.userInputMessage ?? e.assistantResponseMessage
790
+ if (marked.has(msg)) {
791
+ msg.cachePoint = { type: "default" }
792
+ points.push(() => delete msg.cachePoint)
793
+ }
794
+ }
795
+ for (const drop of points.slice(0, Math.max(0, points.length - 4))) drop()
771
796
 
772
797
  const state = { chatTriggerType: "MANUAL", agentTaskType: "vibe", conversationId: randomUUID(), currentMessage: { userInputMessage: current } }
773
798
  if (entries.length > 1) state.history = entries.slice(0, -1)
@@ -1493,4 +1518,4 @@ export async function KiroAuthPlugin({ client } = {}) {
1493
1518
  }
1494
1519
 
1495
1520
  // for tests
1496
- export const _internal = { generate, refresh, usageOf, buildKiro, events, reply, failure, toolID, toolName, toolNames, thinking, readCLI, readIDE, regionOf, planName, frames }
1521
+ export const _internal = { generate, refresh, usageOf, buildKiro, events, reply, failure, toolID, toolName, toolNames, thinking, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-kiro-auth",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",