@kenkaiiii/gg-ai 5.22.0 → 5.22.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 +20 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -823,9 +823,14 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
823
823
|
continue;
|
|
824
824
|
}
|
|
825
825
|
if (msg.role === "user") {
|
|
826
|
+
if (typeof msg.content === "string") {
|
|
827
|
+
if (msg.content === "") continue;
|
|
828
|
+
} else if (!msg.content.some((p) => !(p.type === "text" && p.text === ""))) {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
826
831
|
out.push({
|
|
827
832
|
role: "user",
|
|
828
|
-
content: typeof msg.content === "string" ? msg.content : msg.content.map((part) => {
|
|
833
|
+
content: typeof msg.content === "string" ? msg.content : msg.content.filter((part) => !(part.type === "text" && part.text === "")).map((part) => {
|
|
829
834
|
if (part.type === "text") return { type: "text", text: part.text };
|
|
830
835
|
if (part.type === "video") {
|
|
831
836
|
return {
|
|
@@ -850,6 +855,7 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
850
855
|
continue;
|
|
851
856
|
}
|
|
852
857
|
if (msg.role === "assistant") {
|
|
858
|
+
if (typeof msg.content === "string" && msg.content === "") continue;
|
|
853
859
|
const content = typeof msg.content === "string" ? msg.content : toAnthropicAssistantContent(msg.content, msgIdx > trajectoryStartIdx, idMap);
|
|
854
860
|
if (Array.isArray(content) && content.length === 0) continue;
|
|
855
861
|
out.push({ role: "assistant", content });
|
|
@@ -970,7 +976,7 @@ function remapToolCallId(id, idMap) {
|
|
|
970
976
|
if (!id.startsWith("toolu_")) return id;
|
|
971
977
|
const existing = idMap.get(id);
|
|
972
978
|
if (existing) return existing;
|
|
973
|
-
const mapped = `call_${id.slice(
|
|
979
|
+
const mapped = `call_${id.slice(6)}`;
|
|
974
980
|
idMap.set(id, mapped);
|
|
975
981
|
return mapped;
|
|
976
982
|
}
|
|
@@ -1580,6 +1586,12 @@ async function* runStream(options) {
|
|
|
1580
1586
|
statusCode: 504
|
|
1581
1587
|
});
|
|
1582
1588
|
}
|
|
1589
|
+
if (stopReason === null) {
|
|
1590
|
+
throw new ProviderError("anthropic", "Stream ended before completion (no stop_reason).", {
|
|
1591
|
+
statusCode: 504,
|
|
1592
|
+
cause: { partialContent: contentParts, outputTokens }
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1583
1595
|
const normalizedStop = normalizeAnthropicStopReason(stopReason);
|
|
1584
1596
|
const response = {
|
|
1585
1597
|
message: {
|
|
@@ -2075,6 +2087,12 @@ async function* runStream2(options) {
|
|
|
2075
2087
|
statusCode: 504
|
|
2076
2088
|
});
|
|
2077
2089
|
}
|
|
2090
|
+
if (finishReason === null) {
|
|
2091
|
+
throw new ProviderError(providerName, "Stream ended before completion (no finish_reason).", {
|
|
2092
|
+
statusCode: 504,
|
|
2093
|
+
cause: { partialText: textAccum, outputTokens }
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2078
2096
|
if (thinkingAccum) {
|
|
2079
2097
|
contentParts.push({ type: "thinking", text: thinkingAccum });
|
|
2080
2098
|
}
|