@kenkaiiii/gg-ai 5.109.0 → 6.0.1

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/README.md CHANGED
@@ -20,7 +20,7 @@ It's the provider layer under [GG Coder](https://github.com/KenKaiii/gg-framewor
20
20
  npm install @kenkaiiii/gg-ai zod
21
21
  ```
22
22
 
23
- Needs Node.js 22 or newer. Ships ESM and CommonJS builds with TypeScript types.
23
+ Needs Node.js 24 or newer. Ships ESM and CommonJS builds with TypeScript types.
24
24
 
25
25
  ## Quick start
26
26
 
package/dist/index.cjs CHANGED
@@ -987,6 +987,17 @@ function opensTurn(message) {
987
987
  return message.role === "user" && !continuesTurn(message);
988
988
  }
989
989
 
990
+ // src/utils/cache-anchor.ts
991
+ var CACHE_ANCHOR = /* @__PURE__ */ Symbol("gg.cacheAnchor");
992
+ function markCacheAnchor(message) {
993
+ const marked = { ...message };
994
+ marked[CACHE_ANCHOR] = true;
995
+ return marked;
996
+ }
997
+ function isCacheAnchor(message) {
998
+ return message[CACHE_ANCHOR] === true;
999
+ }
1000
+
990
1001
  // src/providers/transform.ts
991
1002
  function hasValidThinkingSignature(part) {
992
1003
  return typeof part.signature === "string" && part.signature.trim().length > 0;
@@ -1488,6 +1499,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
1488
1499
  let systemText;
1489
1500
  const out = [];
1490
1501
  const userTurnIdx = [];
1502
+ let anchorHintIdx;
1491
1503
  const idMap = /* @__PURE__ */ new Map();
1492
1504
  const keepFallbackBlocks = options?.fallbackBlocks === true;
1493
1505
  const droppedToolCallIds = /* @__PURE__ */ new Set();
@@ -1512,6 +1524,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
1512
1524
  continue;
1513
1525
  }
1514
1526
  if (opensTurn(msg)) userTurnIdx.push(out.length);
1527
+ if (isCacheAnchor(msg)) anchorHintIdx = out.length;
1515
1528
  out.push({
1516
1529
  role: "user",
1517
1530
  content: typeof msg.content === "string" ? msg.content : msg.content.filter((part) => !(part.type === "text" && part.text === "")).map((part) => {
@@ -1601,6 +1614,7 @@ ${part.text}` } : part
1601
1614
  is_error: void 0
1602
1615
  };
1603
1616
  });
1617
+ if (isCacheAnchor(msg)) anchorHintIdx = out.length;
1604
1618
  out.push({
1605
1619
  role: "user",
1606
1620
  // Cast covers the video and tool_reference blocks, which aren't in this
@@ -1625,6 +1639,10 @@ ${part.text}` } : part
1625
1639
  markAnthropicCacheBreakpoint(out, tail, blocking ? cacheControl : { type: "ephemeral" });
1626
1640
  }
1627
1641
  } else {
1642
+ const opening = userTurnIdx.at(-1);
1643
+ if (anchorHintIdx !== void 0 && anchorHintIdx < tail && (opening === void 0 || anchorHintIdx > opening)) {
1644
+ markAnthropicCacheBreakpoint(out, anchorHintIdx, cacheControl);
1645
+ }
1628
1646
  markAnthropicCacheBreakpoint(out, tail, cacheControl);
1629
1647
  }
1630
1648
  }
@@ -5663,14 +5681,28 @@ function observedTools(options, messages) {
5663
5681
  const plan = planDeferredTools(options.tools, options.deferredTools, messages);
5664
5682
  return plan ? [...plan.live, ...plan.deferred] : options.tools ?? [];
5665
5683
  }
5684
+ var MID_RUN_KINDS = /* @__PURE__ */ new Set([
5685
+ "notification",
5686
+ "steering",
5687
+ "completion_gate",
5688
+ "continuation",
5689
+ "review_follow_up"
5690
+ ]);
5666
5691
  function stripMessageProvenance(messages) {
5667
5692
  let stripped;
5668
5693
  for (let index = 0; index < messages.length; index++) {
5669
5694
  const message = messages[index];
5670
- if (!message.provenance) continue;
5695
+ if (!message.provenance && message.cacheAnchor === void 0) continue;
5671
5696
  stripped ??= messages.slice();
5672
- const { provenance, ...wireMessage } = message;
5673
- stripped[index] = provenance.kind === "notification" && message.role === "user" ? markContinuesTurn(wireMessage) : wireMessage;
5697
+ const { provenance, cacheAnchor, ...rest } = message;
5698
+ let wireMessage = rest;
5699
+ if (cacheAnchor === true && (message.role === "user" || message.role === "tool")) {
5700
+ wireMessage = markCacheAnchor(wireMessage);
5701
+ }
5702
+ if (provenance && MID_RUN_KINDS.has(provenance.kind) && message.role === "user") {
5703
+ wireMessage = markContinuesTurn(wireMessage);
5704
+ }
5705
+ stripped[index] = wireMessage;
5674
5706
  }
5675
5707
  return stripped ?? messages;
5676
5708
  }