@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.d.cts
CHANGED
|
@@ -41,6 +41,21 @@ interface ToolResult {
|
|
|
41
41
|
toolCallId: string;
|
|
42
42
|
content: ToolResultContent;
|
|
43
43
|
isError?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Set when the agent loop trimmed `content` to fit a per-result or per-turn
|
|
46
|
+
* budget. The provider (model input) and the persistent transcript both see
|
|
47
|
+
* the trimmed `content`, but the live `tool_call_end` event carried the FULL
|
|
48
|
+
* preview — so this marker makes that divergence explicit and reconcilable.
|
|
49
|
+
* Internal metadata only: it is never serialized onto the provider wire.
|
|
50
|
+
*/
|
|
51
|
+
capped?: {
|
|
52
|
+
/** Length of the original, untrimmed string content. */
|
|
53
|
+
originalChars: number;
|
|
54
|
+
/** Length of the trimmed content actually sent to the model. */
|
|
55
|
+
keptChars: number;
|
|
56
|
+
/** Which budget triggered the trim. */
|
|
57
|
+
scope: "per-result" | "per-turn";
|
|
58
|
+
};
|
|
44
59
|
}
|
|
45
60
|
interface ServerToolCall {
|
|
46
61
|
type: "server_tool_call";
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,21 @@ interface ToolResult {
|
|
|
41
41
|
toolCallId: string;
|
|
42
42
|
content: ToolResultContent;
|
|
43
43
|
isError?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Set when the agent loop trimmed `content` to fit a per-result or per-turn
|
|
46
|
+
* budget. The provider (model input) and the persistent transcript both see
|
|
47
|
+
* the trimmed `content`, but the live `tool_call_end` event carried the FULL
|
|
48
|
+
* preview — so this marker makes that divergence explicit and reconcilable.
|
|
49
|
+
* Internal metadata only: it is never serialized onto the provider wire.
|
|
50
|
+
*/
|
|
51
|
+
capped?: {
|
|
52
|
+
/** Length of the original, untrimmed string content. */
|
|
53
|
+
originalChars: number;
|
|
54
|
+
/** Length of the trimmed content actually sent to the model. */
|
|
55
|
+
keptChars: number;
|
|
56
|
+
/** Which budget triggered the trim. */
|
|
57
|
+
scope: "per-result" | "per-turn";
|
|
58
|
+
};
|
|
44
59
|
}
|
|
45
60
|
interface ServerToolCall {
|
|
46
61
|
type: "server_tool_call";
|
package/dist/index.js
CHANGED
|
@@ -763,9 +763,14 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
763
763
|
continue;
|
|
764
764
|
}
|
|
765
765
|
if (msg.role === "user") {
|
|
766
|
+
if (typeof msg.content === "string") {
|
|
767
|
+
if (msg.content === "") continue;
|
|
768
|
+
} else if (!msg.content.some((p) => !(p.type === "text" && p.text === ""))) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
766
771
|
out.push({
|
|
767
772
|
role: "user",
|
|
768
|
-
content: typeof msg.content === "string" ? msg.content : msg.content.map((part) => {
|
|
773
|
+
content: typeof msg.content === "string" ? msg.content : msg.content.filter((part) => !(part.type === "text" && part.text === "")).map((part) => {
|
|
769
774
|
if (part.type === "text") return { type: "text", text: part.text };
|
|
770
775
|
if (part.type === "video") {
|
|
771
776
|
return {
|
|
@@ -790,6 +795,7 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
790
795
|
continue;
|
|
791
796
|
}
|
|
792
797
|
if (msg.role === "assistant") {
|
|
798
|
+
if (typeof msg.content === "string" && msg.content === "") continue;
|
|
793
799
|
const content = typeof msg.content === "string" ? msg.content : toAnthropicAssistantContent(msg.content, msgIdx > trajectoryStartIdx, idMap);
|
|
794
800
|
if (Array.isArray(content) && content.length === 0) continue;
|
|
795
801
|
out.push({ role: "assistant", content });
|
|
@@ -910,7 +916,7 @@ function remapToolCallId(id, idMap) {
|
|
|
910
916
|
if (!id.startsWith("toolu_")) return id;
|
|
911
917
|
const existing = idMap.get(id);
|
|
912
918
|
if (existing) return existing;
|
|
913
|
-
const mapped = `call_${id.slice(
|
|
919
|
+
const mapped = `call_${id.slice(6)}`;
|
|
914
920
|
idMap.set(id, mapped);
|
|
915
921
|
return mapped;
|
|
916
922
|
}
|
|
@@ -1520,6 +1526,12 @@ async function* runStream(options) {
|
|
|
1520
1526
|
statusCode: 504
|
|
1521
1527
|
});
|
|
1522
1528
|
}
|
|
1529
|
+
if (stopReason === null) {
|
|
1530
|
+
throw new ProviderError("anthropic", "Stream ended before completion (no stop_reason).", {
|
|
1531
|
+
statusCode: 504,
|
|
1532
|
+
cause: { partialContent: contentParts, outputTokens }
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1523
1535
|
const normalizedStop = normalizeAnthropicStopReason(stopReason);
|
|
1524
1536
|
const response = {
|
|
1525
1537
|
message: {
|
|
@@ -2015,6 +2027,12 @@ async function* runStream2(options) {
|
|
|
2015
2027
|
statusCode: 504
|
|
2016
2028
|
});
|
|
2017
2029
|
}
|
|
2030
|
+
if (finishReason === null) {
|
|
2031
|
+
throw new ProviderError(providerName, "Stream ended before completion (no finish_reason).", {
|
|
2032
|
+
statusCode: 504,
|
|
2033
|
+
cause: { partialText: textAccum, outputTokens }
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2018
2036
|
if (thinkingAccum) {
|
|
2019
2037
|
contentParts.push({ type: "thinking", text: thinkingAccum });
|
|
2020
2038
|
}
|