@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.js
CHANGED
|
@@ -905,6 +905,37 @@ function applyServerFallbackReplay(content, keepMarkers, droppedToolCallIds) {
|
|
|
905
905
|
});
|
|
906
906
|
return out.every(isServerFallbackBlock) ? [] : out;
|
|
907
907
|
}
|
|
908
|
+
function serverToolUseId(part) {
|
|
909
|
+
if (part.type === "server_tool_call") return part.id;
|
|
910
|
+
if (part.type === "raw" && part.data.type === "server_tool_use" && typeof part.data.id === "string")
|
|
911
|
+
return part.data.id;
|
|
912
|
+
return void 0;
|
|
913
|
+
}
|
|
914
|
+
function unresolvedServerToolUseIds(messages) {
|
|
915
|
+
const resultIds = /* @__PURE__ */ new Set();
|
|
916
|
+
let lastAssistantIdx = -1;
|
|
917
|
+
messages.forEach((msg, idx) => {
|
|
918
|
+
if (msg.role !== "assistant") return;
|
|
919
|
+
lastAssistantIdx = idx;
|
|
920
|
+
if (typeof msg.content === "string") return;
|
|
921
|
+
for (const part of msg.content) {
|
|
922
|
+
if (part.type === "server_tool_result") resultIds.add(part.toolUseId);
|
|
923
|
+
else if (part.type === "raw" && typeof part.data.tool_use_id === "string")
|
|
924
|
+
resultIds.add(part.data.tool_use_id);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
const turnStillOpen = messages.slice(lastAssistantIdx + 1).every((m) => m.role === "tool");
|
|
928
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
929
|
+
messages.forEach((msg, idx) => {
|
|
930
|
+
if (msg.role !== "assistant" || typeof msg.content === "string") return;
|
|
931
|
+
if (idx === lastAssistantIdx && turnStillOpen) return;
|
|
932
|
+
for (const part of msg.content) {
|
|
933
|
+
const id = serverToolUseId(part);
|
|
934
|
+
if (id !== void 0 && !resultIds.has(id)) dropped.add(id);
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
return dropped;
|
|
938
|
+
}
|
|
908
939
|
function toAnthropicAssistantPart(part, idMap) {
|
|
909
940
|
if (part.type === "text") return { type: "text", text: part.text };
|
|
910
941
|
if (part.type === "thinking") {
|
|
@@ -1267,6 +1298,7 @@ function toAnthropicMessages(messages, cacheControl, options) {
|
|
|
1267
1298
|
const idMap = /* @__PURE__ */ new Map();
|
|
1268
1299
|
const keepFallbackBlocks = options?.fallbackBlocks === true;
|
|
1269
1300
|
const droppedToolCallIds = /* @__PURE__ */ new Set();
|
|
1301
|
+
const unresolvedServerToolIds = unresolvedServerToolUseIds(messages);
|
|
1270
1302
|
const trajectoryStartIdx = messages.reduce(
|
|
1271
1303
|
(last, m, i) => opensTurn(m) ? i : last,
|
|
1272
1304
|
-1
|
|
@@ -1313,8 +1345,12 @@ function toAnthropicMessages(messages, cacheControl, options) {
|
|
|
1313
1345
|
}
|
|
1314
1346
|
if (msg.role === "assistant") {
|
|
1315
1347
|
if (typeof msg.content === "string" && msg.content === "") continue;
|
|
1316
|
-
const
|
|
1317
|
-
|
|
1348
|
+
const replayable = typeof msg.content === "string" || unresolvedServerToolIds.size === 0 ? msg.content : msg.content.filter((part) => {
|
|
1349
|
+
const id = serverToolUseId(part);
|
|
1350
|
+
return id === void 0 || !unresolvedServerToolIds.has(id);
|
|
1351
|
+
});
|
|
1352
|
+
const content = typeof replayable === "string" ? replayable : toAnthropicAssistantContent(
|
|
1353
|
+
applyServerFallbackReplay(replayable, keepFallbackBlocks, droppedToolCallIds),
|
|
1318
1354
|
msgIdx > trajectoryStartIdx,
|
|
1319
1355
|
idMap
|
|
1320
1356
|
);
|