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

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 (2) hide show
  1. package/index.mjs +23 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -646,6 +646,12 @@ function thinking(req, model) {
646
646
  // buildKiro is the body of a generateAssistantResponse call.
647
647
  function buildKiro(req, model, profile, budget) {
648
648
  const entries = []
649
+ // the messages the caller marked for its prompt cache (cache_control),
650
+ // which go to Kiro as a cachePoint on the message they end up in (#110)
651
+ const marked = new WeakSet()
652
+ const mark = (msg, parts) => {
653
+ if (parts.some((p) => p?.cache_control)) marked.add(msg)
654
+ }
649
655
  const user = () => ({ content: "", modelId: model, origin: "KIRO_CLI" })
650
656
  for (const m of req.messages ?? []) {
651
657
  const parts = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content ?? []
@@ -666,6 +672,7 @@ function buildKiro(req, model, profile, budget) {
666
672
  prev.content = joinNonEmpty(prev.content, a.content)
667
673
  prev.toolUses.push(...a.toolUses)
668
674
  } else entries.push({ assistantResponseMessage: a })
675
+ mark(prev ?? a, parts)
669
676
  continue
670
677
  }
671
678
  const u = user()
@@ -693,6 +700,7 @@ function buildKiro(req, model, profile, budget) {
693
700
  prev.images.push(...u.images)
694
701
  if (results.length) (prev.userInputMessageContext ??= { toolResults: [] }).toolResults.push(...results)
695
702
  } else entries.push({ userInputMessage: u })
703
+ mark(prev ?? u, parts)
696
704
  }
697
705
  // the conversation opens with something the user said: tool results with
698
706
  // no call before them go, and a reply the caller began with
@@ -748,6 +756,7 @@ function buildKiro(req, model, profile, budget) {
748
756
  let system = typeof req.system === "string" ? req.system : textOf(req.system)
749
757
  if (budget) system = `<thinking_mode>enabled</thinking_mode><max_thinking_length>${budget}</max_thinking_length>` + (system ? "\n" + system : "")
750
758
  if (system) entries[0].userInputMessage.content = system + "\n\n" + entries[0].userInputMessage.content
759
+ if (Array.isArray(req.system)) mark(entries[0].userInputMessage, req.system)
751
760
 
752
761
  // the caller's tools, and any the conversation used that it no longer
753
762
  // offers — Kiro rejects a history naming a tool it wasn't given
@@ -760,6 +769,7 @@ function buildKiro(req, model, profile, budget) {
760
769
  const name = toolName(t.name)
761
770
  offered.add(name)
762
771
  tools.push({ toolSpecification: { name, description: t.description || t.name, inputSchema: { json: t.input_schema ?? EMPTY } } })
772
+ if (t.cache_control) tools.push({ cachePoint: { type: "default" } })
763
773
  }
764
774
  for (const e of entries)
765
775
  for (const c of e.assistantResponseMessage?.toolUses ?? [])
@@ -768,6 +778,19 @@ function buildKiro(req, model, profile, budget) {
768
778
  tools.push({ toolSpecification: { name: c.name, description: "Tool", inputSchema: { json: EMPTY } } })
769
779
  }
770
780
  if (tools.length) (current.userInputMessageContext ??= {}).tools = tools
781
+ // Kiro's cachePoint is Bedrock's: it caches the prompt up to the point,
782
+ // and a request may hold 4 at most, as Anthropic's cache_control; past
783
+ // that the last ones are kept, the most of the prompt they cover
784
+ const points = []
785
+ for (const t of tools) if (t.cachePoint) points.push(() => tools.splice(tools.indexOf(t), 1))
786
+ for (const e of entries) {
787
+ const msg = e.userInputMessage ?? e.assistantResponseMessage
788
+ if (marked.has(msg)) {
789
+ msg.cachePoint = { type: "default" }
790
+ points.push(() => delete msg.cachePoint)
791
+ }
792
+ }
793
+ for (const drop of points.slice(0, Math.max(0, points.length - 4))) drop()
771
794
 
772
795
  const state = { chatTriggerType: "MANUAL", agentTaskType: "vibe", conversationId: randomUUID(), currentMessage: { userInputMessage: current } }
773
796
  if (entries.length > 1) state.history = entries.slice(0, -1)
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.10",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",