@kenkaiiii/gg-ai 5.109.0 → 6.0.0

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/dist/index.d.cts CHANGED
@@ -107,6 +107,16 @@ interface MessageProvenance {
107
107
  }
108
108
  interface MessageMetadata {
109
109
  provenance?: MessageProvenance;
110
+ /**
111
+ * Host hint, never sent: nothing up to and including this message will change
112
+ * again during the current run (for example, everything older was already
113
+ * pruned). On a 5-minute cache route the Anthropic encoder adds a cache
114
+ * breakpoint at the latest such user/tool message when it is newer than the
115
+ * turn's opening message, so a later edit after it re-sends only what follows
116
+ * instead of the whole conversation. `stream()` removes it before provider
117
+ * dispatch.
118
+ */
119
+ cacheAnchor?: boolean;
110
120
  }
111
121
  interface SystemMessage extends MessageMetadata {
112
122
  role: "system";
package/dist/index.d.ts CHANGED
@@ -107,6 +107,16 @@ interface MessageProvenance {
107
107
  }
108
108
  interface MessageMetadata {
109
109
  provenance?: MessageProvenance;
110
+ /**
111
+ * Host hint, never sent: nothing up to and including this message will change
112
+ * again during the current run (for example, everything older was already
113
+ * pruned). On a 5-minute cache route the Anthropic encoder adds a cache
114
+ * breakpoint at the latest such user/tool message when it is newer than the
115
+ * turn's opening message, so a later edit after it re-sends only what follows
116
+ * instead of the whole conversation. `stream()` removes it before provider
117
+ * dispatch.
118
+ */
119
+ cacheAnchor?: boolean;
110
120
  }
111
121
  interface SystemMessage extends MessageMetadata {
112
122
  role: "system";
package/dist/index.js CHANGED
@@ -897,6 +897,17 @@ function opensTurn(message) {
897
897
  return message.role === "user" && !continuesTurn(message);
898
898
  }
899
899
 
900
+ // src/utils/cache-anchor.ts
901
+ var CACHE_ANCHOR = /* @__PURE__ */ Symbol("gg.cacheAnchor");
902
+ function markCacheAnchor(message) {
903
+ const marked = { ...message };
904
+ marked[CACHE_ANCHOR] = true;
905
+ return marked;
906
+ }
907
+ function isCacheAnchor(message) {
908
+ return message[CACHE_ANCHOR] === true;
909
+ }
910
+
900
911
  // src/providers/transform.ts
901
912
  function hasValidThinkingSignature(part) {
902
913
  return typeof part.signature === "string" && part.signature.trim().length > 0;
@@ -1398,6 +1409,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
1398
1409
  let systemText;
1399
1410
  const out = [];
1400
1411
  const userTurnIdx = [];
1412
+ let anchorHintIdx;
1401
1413
  const idMap = /* @__PURE__ */ new Map();
1402
1414
  const keepFallbackBlocks = options?.fallbackBlocks === true;
1403
1415
  const droppedToolCallIds = /* @__PURE__ */ new Set();
@@ -1422,6 +1434,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
1422
1434
  continue;
1423
1435
  }
1424
1436
  if (opensTurn(msg)) userTurnIdx.push(out.length);
1437
+ if (isCacheAnchor(msg)) anchorHintIdx = out.length;
1425
1438
  out.push({
1426
1439
  role: "user",
1427
1440
  content: typeof msg.content === "string" ? msg.content : msg.content.filter((part) => !(part.type === "text" && part.text === "")).map((part) => {
@@ -1511,6 +1524,7 @@ ${part.text}` } : part
1511
1524
  is_error: void 0
1512
1525
  };
1513
1526
  });
1527
+ if (isCacheAnchor(msg)) anchorHintIdx = out.length;
1514
1528
  out.push({
1515
1529
  role: "user",
1516
1530
  // Cast covers the video and tool_reference blocks, which aren't in this
@@ -1535,6 +1549,10 @@ ${part.text}` } : part
1535
1549
  markAnthropicCacheBreakpoint(out, tail, blocking ? cacheControl : { type: "ephemeral" });
1536
1550
  }
1537
1551
  } else {
1552
+ const opening = userTurnIdx.at(-1);
1553
+ if (anchorHintIdx !== void 0 && anchorHintIdx < tail && (opening === void 0 || anchorHintIdx > opening)) {
1554
+ markAnthropicCacheBreakpoint(out, anchorHintIdx, cacheControl);
1555
+ }
1538
1556
  markAnthropicCacheBreakpoint(out, tail, cacheControl);
1539
1557
  }
1540
1558
  }
@@ -5573,14 +5591,28 @@ function observedTools(options, messages) {
5573
5591
  const plan = planDeferredTools(options.tools, options.deferredTools, messages);
5574
5592
  return plan ? [...plan.live, ...plan.deferred] : options.tools ?? [];
5575
5593
  }
5594
+ var MID_RUN_KINDS = /* @__PURE__ */ new Set([
5595
+ "notification",
5596
+ "steering",
5597
+ "completion_gate",
5598
+ "continuation",
5599
+ "review_follow_up"
5600
+ ]);
5576
5601
  function stripMessageProvenance(messages) {
5577
5602
  let stripped;
5578
5603
  for (let index = 0; index < messages.length; index++) {
5579
5604
  const message = messages[index];
5580
- if (!message.provenance) continue;
5605
+ if (!message.provenance && message.cacheAnchor === void 0) continue;
5581
5606
  stripped ??= messages.slice();
5582
- const { provenance, ...wireMessage } = message;
5583
- stripped[index] = provenance.kind === "notification" && message.role === "user" ? markContinuesTurn(wireMessage) : wireMessage;
5607
+ const { provenance, cacheAnchor, ...rest } = message;
5608
+ let wireMessage = rest;
5609
+ if (cacheAnchor === true && (message.role === "user" || message.role === "tool")) {
5610
+ wireMessage = markCacheAnchor(wireMessage);
5611
+ }
5612
+ if (provenance && MID_RUN_KINDS.has(provenance.kind) && message.role === "user") {
5613
+ wireMessage = markContinuesTurn(wireMessage);
5614
+ }
5615
+ stripped[index] = wireMessage;
5584
5616
  }
5585
5617
  return stripped ?? messages;
5586
5618
  }