@kenkaiiii/gg-ai 5.84.1 → 5.84.2
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.cjs +38 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -990,6 +990,37 @@ function applyServerFallbackReplay(content, keepMarkers, droppedToolCallIds) {
|
|
|
990
990
|
});
|
|
991
991
|
return out.every(isServerFallbackBlock) ? [] : out;
|
|
992
992
|
}
|
|
993
|
+
function serverToolUseId(part) {
|
|
994
|
+
if (part.type === "server_tool_call") return part.id;
|
|
995
|
+
if (part.type === "raw" && part.data.type === "server_tool_use" && typeof part.data.id === "string")
|
|
996
|
+
return part.data.id;
|
|
997
|
+
return void 0;
|
|
998
|
+
}
|
|
999
|
+
function unresolvedServerToolUseIds(messages) {
|
|
1000
|
+
const resultIds = /* @__PURE__ */ new Set();
|
|
1001
|
+
let lastAssistantIdx = -1;
|
|
1002
|
+
messages.forEach((msg, idx) => {
|
|
1003
|
+
if (msg.role !== "assistant") return;
|
|
1004
|
+
lastAssistantIdx = idx;
|
|
1005
|
+
if (typeof msg.content === "string") return;
|
|
1006
|
+
for (const part of msg.content) {
|
|
1007
|
+
if (part.type === "server_tool_result") resultIds.add(part.toolUseId);
|
|
1008
|
+
else if (part.type === "raw" && typeof part.data.tool_use_id === "string")
|
|
1009
|
+
resultIds.add(part.data.tool_use_id);
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
const turnStillOpen = messages.slice(lastAssistantIdx + 1).every((m) => m.role === "tool");
|
|
1013
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
1014
|
+
messages.forEach((msg, idx) => {
|
|
1015
|
+
if (msg.role !== "assistant" || typeof msg.content === "string") return;
|
|
1016
|
+
if (idx === lastAssistantIdx && turnStillOpen) return;
|
|
1017
|
+
for (const part of msg.content) {
|
|
1018
|
+
const id = serverToolUseId(part);
|
|
1019
|
+
if (id !== void 0 && !resultIds.has(id)) dropped.add(id);
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
return dropped;
|
|
1023
|
+
}
|
|
993
1024
|
function toAnthropicAssistantPart(part, idMap) {
|
|
994
1025
|
if (part.type === "text") return { type: "text", text: part.text };
|
|
995
1026
|
if (part.type === "thinking") {
|
|
@@ -1352,6 +1383,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
|
|
|
1352
1383
|
const idMap = /* @__PURE__ */ new Map();
|
|
1353
1384
|
const keepFallbackBlocks = options?.fallbackBlocks === true;
|
|
1354
1385
|
const droppedToolCallIds = /* @__PURE__ */ new Set();
|
|
1386
|
+
const unresolvedServerToolIds = unresolvedServerToolUseIds(messages);
|
|
1355
1387
|
const trajectoryStartIdx = messages.reduce(
|
|
1356
1388
|
(last, m, i) => opensTurn(m) ? i : last,
|
|
1357
1389
|
-1
|
|
@@ -1398,8 +1430,12 @@ function toAnthropicMessages(messages, cacheControl, options) {
|
|
|
1398
1430
|
}
|
|
1399
1431
|
if (msg.role === "assistant") {
|
|
1400
1432
|
if (typeof msg.content === "string" && msg.content === "") continue;
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1433
|
+
const replayable = typeof msg.content === "string" || unresolvedServerToolIds.size === 0 ? msg.content : msg.content.filter((part) => {
|
|
1434
|
+
const id = serverToolUseId(part);
|
|
1435
|
+
return id === void 0 || !unresolvedServerToolIds.has(id);
|
|
1436
|
+
});
|
|
1437
|
+
const content = typeof replayable === "string" ? replayable : toAnthropicAssistantContent(
|
|
1438
|
+
applyServerFallbackReplay(replayable, keepFallbackBlocks, droppedToolCallIds),
|
|
1403
1439
|
msgIdx > trajectoryStartIdx,
|
|
1404
1440
|
idMap
|
|
1405
1441
|
);
|