@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/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
|
|
23
|
+
Needs Node.js 24 or newer. Ships ESM and CommonJS builds with TypeScript types.
|
|
24
24
|
|
|
25
25
|
## Quick start
|
|
26
26
|
|
|
@@ -83,7 +83,7 @@ gg-ai makes one model call. To run the tools and send results back until the mod
|
|
|
83
83
|
| `gemini` | Gemini 3.1 Pro (Preview), 3.8 / 3.5 Flash, 3.5 / 3.1 Flash Lite | Google AI Studio key on the public Gemini API. Native video input |
|
|
84
84
|
| `xai` | Grok 4.7 | API key |
|
|
85
85
|
| `moonshot` | Kimi K3, K2.8 Preview, K2.7 Code, K2.7 Code HighSpeed | Moonshot key, or a Kimi Code plan key with its `baseUrl`. Native video input |
|
|
86
|
-
| `glm` | GLM-5.3, GLM-5.3-Flash
|
|
86
|
+
| `glm` | GLM-5.4, GLM-5.3, GLM-5.3-Flash | Z.AI Coding Plan or standard (pay-per-token) endpoint |
|
|
87
87
|
| `minimax` | MiniMax M3.1 Flash, M3 | Anthropic-compatible endpoint. Native video input |
|
|
88
88
|
| `xiaomi` | MiMo-V2.6-Pro, MiMo-V2.6-Flash, MiMo-V2.6-Pro-UltraSpeed | Native video input |
|
|
89
89
|
| `deepseek` | DeepSeek V4 Pro, V4.1 Flash | |
|
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
|
}
|
|
@@ -2926,6 +2944,7 @@ async function* runStream2(options) {
|
|
|
2926
2944
|
const k3Effort = options.thinking ? toKimiK3Effort(options.thinking) : void 0;
|
|
2927
2945
|
const isKimiK27 = options.provider === "moonshot" && options.model.startsWith("kimi-k2.7-code");
|
|
2928
2946
|
const hasFixedKimiSampling = isKimiK3 || isKimiK27;
|
|
2947
|
+
const isGlmAlwaysThinking = options.provider === "glm" && options.model === "glm-5.3";
|
|
2929
2948
|
const usesThinkingParam = options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot" && !isKimiK3 && !isKimiK27 || options.provider === "xiaomi";
|
|
2930
2949
|
const downgradedImages = downgradeUnsupportedImages(options.messages, options.supportsImages);
|
|
2931
2950
|
const downgradedMessages = downgradeUnsupportedVideos(downgradedImages, options.supportsVideo);
|
|
@@ -3011,11 +3030,9 @@ async function* runStream2(options) {
|
|
|
3011
3030
|
if (options.provider === "deepseek") {
|
|
3012
3031
|
params.reasoning_effort = options.thinking === "low" ? "low" : options.thinking === "medium" || options.thinking === "high" ? "high" : "max";
|
|
3013
3032
|
} else if (options.provider === "glm") {
|
|
3014
|
-
params.reasoning_effort = toGlmReasoningEffort(
|
|
3015
|
-
options.thinking
|
|
3016
|
-
);
|
|
3033
|
+
params.reasoning_effort = options.thinkingLevels?.length ? effortForRequest(options.thinking, options.model, options.thinkingLevels) : toGlmReasoningEffort(options.thinking);
|
|
3017
3034
|
}
|
|
3018
|
-
} else {
|
|
3035
|
+
} else if (!isGlmAlwaysThinking) {
|
|
3019
3036
|
params.thinking = { type: "disabled" };
|
|
3020
3037
|
}
|
|
3021
3038
|
}
|
|
@@ -5664,14 +5681,28 @@ function observedTools(options, messages) {
|
|
|
5664
5681
|
const plan = planDeferredTools(options.tools, options.deferredTools, messages);
|
|
5665
5682
|
return plan ? [...plan.live, ...plan.deferred] : options.tools ?? [];
|
|
5666
5683
|
}
|
|
5684
|
+
var MID_RUN_KINDS = /* @__PURE__ */ new Set([
|
|
5685
|
+
"notification",
|
|
5686
|
+
"steering",
|
|
5687
|
+
"completion_gate",
|
|
5688
|
+
"continuation",
|
|
5689
|
+
"review_follow_up"
|
|
5690
|
+
]);
|
|
5667
5691
|
function stripMessageProvenance(messages) {
|
|
5668
5692
|
let stripped;
|
|
5669
5693
|
for (let index = 0; index < messages.length; index++) {
|
|
5670
5694
|
const message = messages[index];
|
|
5671
|
-
if (!message.provenance) continue;
|
|
5695
|
+
if (!message.provenance && message.cacheAnchor === void 0) continue;
|
|
5672
5696
|
stripped ??= messages.slice();
|
|
5673
|
-
const { provenance, ...
|
|
5674
|
-
|
|
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;
|
|
5675
5706
|
}
|
|
5676
5707
|
return stripped ?? messages;
|
|
5677
5708
|
}
|