@kenkaiiii/gg-ai 5.108.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/README.md +2 -2
- package/dist/index.cjs +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +38 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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
|
}
|
|
@@ -2836,6 +2854,7 @@ async function* runStream2(options) {
|
|
|
2836
2854
|
const k3Effort = options.thinking ? toKimiK3Effort(options.thinking) : void 0;
|
|
2837
2855
|
const isKimiK27 = options.provider === "moonshot" && options.model.startsWith("kimi-k2.7-code");
|
|
2838
2856
|
const hasFixedKimiSampling = isKimiK3 || isKimiK27;
|
|
2857
|
+
const isGlmAlwaysThinking = options.provider === "glm" && options.model === "glm-5.3";
|
|
2839
2858
|
const usesThinkingParam = options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot" && !isKimiK3 && !isKimiK27 || options.provider === "xiaomi";
|
|
2840
2859
|
const downgradedImages = downgradeUnsupportedImages(options.messages, options.supportsImages);
|
|
2841
2860
|
const downgradedMessages = downgradeUnsupportedVideos(downgradedImages, options.supportsVideo);
|
|
@@ -2921,11 +2940,9 @@ async function* runStream2(options) {
|
|
|
2921
2940
|
if (options.provider === "deepseek") {
|
|
2922
2941
|
params.reasoning_effort = options.thinking === "low" ? "low" : options.thinking === "medium" || options.thinking === "high" ? "high" : "max";
|
|
2923
2942
|
} else if (options.provider === "glm") {
|
|
2924
|
-
params.reasoning_effort = toGlmReasoningEffort(
|
|
2925
|
-
options.thinking
|
|
2926
|
-
);
|
|
2943
|
+
params.reasoning_effort = options.thinkingLevels?.length ? effortForRequest(options.thinking, options.model, options.thinkingLevels) : toGlmReasoningEffort(options.thinking);
|
|
2927
2944
|
}
|
|
2928
|
-
} else {
|
|
2945
|
+
} else if (!isGlmAlwaysThinking) {
|
|
2929
2946
|
params.thinking = { type: "disabled" };
|
|
2930
2947
|
}
|
|
2931
2948
|
}
|
|
@@ -5574,14 +5591,28 @@ function observedTools(options, messages) {
|
|
|
5574
5591
|
const plan = planDeferredTools(options.tools, options.deferredTools, messages);
|
|
5575
5592
|
return plan ? [...plan.live, ...plan.deferred] : options.tools ?? [];
|
|
5576
5593
|
}
|
|
5594
|
+
var MID_RUN_KINDS = /* @__PURE__ */ new Set([
|
|
5595
|
+
"notification",
|
|
5596
|
+
"steering",
|
|
5597
|
+
"completion_gate",
|
|
5598
|
+
"continuation",
|
|
5599
|
+
"review_follow_up"
|
|
5600
|
+
]);
|
|
5577
5601
|
function stripMessageProvenance(messages) {
|
|
5578
5602
|
let stripped;
|
|
5579
5603
|
for (let index = 0; index < messages.length; index++) {
|
|
5580
5604
|
const message = messages[index];
|
|
5581
|
-
if (!message.provenance) continue;
|
|
5605
|
+
if (!message.provenance && message.cacheAnchor === void 0) continue;
|
|
5582
5606
|
stripped ??= messages.slice();
|
|
5583
|
-
const { provenance, ...
|
|
5584
|
-
|
|
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;
|
|
5585
5616
|
}
|
|
5586
5617
|
return stripped ?? messages;
|
|
5587
5618
|
}
|