@kenkaiiii/gg-ai 4.3.238 → 4.3.240
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 +62 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -467,8 +467,8 @@ function toAnthropicAssistantPart(part, idMap) {
|
|
|
467
467
|
if (part.type === "raw") return part.data;
|
|
468
468
|
return null;
|
|
469
469
|
}
|
|
470
|
-
function toAnthropicAssistantContent(content,
|
|
471
|
-
if (!
|
|
470
|
+
function toAnthropicAssistantContent(content, preserveThinking, idMap) {
|
|
471
|
+
if (!preserveThinking) {
|
|
472
472
|
return content.filter((part) => {
|
|
473
473
|
if (part.type === "thinking" || isRawThinking(part)) return false;
|
|
474
474
|
if (part.type === "text" && !part.text) return false;
|
|
@@ -585,8 +585,8 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
585
585
|
let systemText;
|
|
586
586
|
const out = [];
|
|
587
587
|
const idMap = /* @__PURE__ */ new Map();
|
|
588
|
-
const
|
|
589
|
-
(last, m, i) => m.role === "
|
|
588
|
+
const trajectoryStartIdx = messages.reduce(
|
|
589
|
+
(last, m, i) => m.role === "user" ? i : last,
|
|
590
590
|
-1
|
|
591
591
|
);
|
|
592
592
|
let msgIdx = -1;
|
|
@@ -624,7 +624,7 @@ function toAnthropicMessages(messages, cacheControl) {
|
|
|
624
624
|
continue;
|
|
625
625
|
}
|
|
626
626
|
if (msg.role === "assistant") {
|
|
627
|
-
const content = typeof msg.content === "string" ? msg.content : toAnthropicAssistantContent(msg.content, msgIdx
|
|
627
|
+
const content = typeof msg.content === "string" ? msg.content : toAnthropicAssistantContent(msg.content, msgIdx > trajectoryStartIdx, idMap);
|
|
628
628
|
if (Array.isArray(content) && content.length === 0) continue;
|
|
629
629
|
out.push({ role: "assistant", content });
|
|
630
630
|
continue;
|
|
@@ -1151,11 +1151,18 @@ async function* runStream(options) {
|
|
|
1151
1151
|
args: tc.args
|
|
1152
1152
|
};
|
|
1153
1153
|
} else if (accum.type === "server_tool_use") {
|
|
1154
|
+
let input = accum.input;
|
|
1155
|
+
if (accum.argsJson) {
|
|
1156
|
+
try {
|
|
1157
|
+
input = JSON.parse(accum.argsJson);
|
|
1158
|
+
} catch {
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1154
1161
|
const stc = {
|
|
1155
1162
|
type: "server_tool_call",
|
|
1156
1163
|
id: accum.toolId,
|
|
1157
1164
|
name: accum.toolName,
|
|
1158
|
-
input
|
|
1165
|
+
input
|
|
1159
1166
|
};
|
|
1160
1167
|
contentParts.push(stc);
|
|
1161
1168
|
yield {
|
|
@@ -1900,6 +1907,7 @@ async function* runStream3(options) {
|
|
|
1900
1907
|
const contentParts = [];
|
|
1901
1908
|
let textAccum = "";
|
|
1902
1909
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
1910
|
+
const orderedItems = [];
|
|
1903
1911
|
const outputItemTypes = /* @__PURE__ */ new Map();
|
|
1904
1912
|
const outputTextByPart = /* @__PURE__ */ new Map();
|
|
1905
1913
|
const pendingOutputTextByPart = /* @__PURE__ */ new Map();
|
|
@@ -2047,12 +2055,26 @@ async function* runStream3(options) {
|
|
|
2047
2055
|
}
|
|
2048
2056
|
if (type === "response.output_item.done") {
|
|
2049
2057
|
const item = event.item;
|
|
2058
|
+
if (item?.type === "reasoning") {
|
|
2059
|
+
const encrypted = item.encrypted_content;
|
|
2060
|
+
const reasoningId = item.id;
|
|
2061
|
+
if (encrypted && reasoningId) {
|
|
2062
|
+
orderedItems.push({
|
|
2063
|
+
kind: "reasoning",
|
|
2064
|
+
part: {
|
|
2065
|
+
type: "raw",
|
|
2066
|
+
data: { ...item, summary: Array.isArray(item.summary) ? item.summary : [] }
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2050
2071
|
if (item?.type === "function_call") {
|
|
2051
2072
|
const callId = item.call_id;
|
|
2052
2073
|
const itemId = item.id;
|
|
2053
2074
|
const id = `${callId}|${itemId}`;
|
|
2054
2075
|
const tc = toolCalls.get(id);
|
|
2055
2076
|
if (tc) {
|
|
2077
|
+
orderedItems.push({ kind: "tool", id });
|
|
2056
2078
|
const args = parseToolArguments(tc.argsJson);
|
|
2057
2079
|
yield {
|
|
2058
2080
|
type: "toolcall_done",
|
|
@@ -2073,19 +2095,41 @@ async function* runStream3(options) {
|
|
|
2073
2095
|
}
|
|
2074
2096
|
}
|
|
2075
2097
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2098
|
+
const seenTool = /* @__PURE__ */ new Set();
|
|
2099
|
+
let textInserted = false;
|
|
2100
|
+
for (const entry of orderedItems) {
|
|
2101
|
+
if (entry.kind === "reasoning") {
|
|
2102
|
+
contentParts.push(entry.part);
|
|
2103
|
+
continue;
|
|
2104
|
+
}
|
|
2105
|
+
if (textAccum && !textInserted) {
|
|
2106
|
+
contentParts.push({ type: "text", text: textAccum });
|
|
2107
|
+
textInserted = true;
|
|
2108
|
+
}
|
|
2109
|
+
const tc = toolCalls.get(entry.id);
|
|
2110
|
+
if (!tc || seenTool.has(entry.id)) continue;
|
|
2111
|
+
seenTool.add(entry.id);
|
|
2081
2112
|
const toolCall = {
|
|
2082
2113
|
type: "tool_call",
|
|
2083
2114
|
id: tc.id,
|
|
2084
2115
|
name: tc.name,
|
|
2085
|
-
args
|
|
2116
|
+
args: parseToolArguments(tc.argsJson)
|
|
2086
2117
|
};
|
|
2087
2118
|
contentParts.push(toolCall);
|
|
2088
2119
|
}
|
|
2120
|
+
if (textAccum && !textInserted) {
|
|
2121
|
+
contentParts.push({ type: "text", text: textAccum });
|
|
2122
|
+
}
|
|
2123
|
+
for (const [id, tc] of toolCalls) {
|
|
2124
|
+
if (seenTool.has(id)) continue;
|
|
2125
|
+
seenTool.add(id);
|
|
2126
|
+
contentParts.push({
|
|
2127
|
+
type: "tool_call",
|
|
2128
|
+
id: tc.id,
|
|
2129
|
+
name: tc.name,
|
|
2130
|
+
args: parseToolArguments(tc.argsJson)
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2089
2133
|
const hasToolCalls = contentParts.some((p) => p.type === "tool_call");
|
|
2090
2134
|
const stopReason = hasToolCalls ? "tool_use" : "end_turn";
|
|
2091
2135
|
const streamResponse = {
|
|
@@ -2117,6 +2161,9 @@ function remapCodexId(id, idMap) {
|
|
|
2117
2161
|
idMap.set(id, mapped);
|
|
2118
2162
|
return mapped;
|
|
2119
2163
|
}
|
|
2164
|
+
function isEncryptedReasoning(data) {
|
|
2165
|
+
return data.type === "reasoning" && typeof data.id === "string" && typeof data.encrypted_content === "string";
|
|
2166
|
+
}
|
|
2120
2167
|
function toCodexInput(messages, options) {
|
|
2121
2168
|
let system;
|
|
2122
2169
|
const input = [];
|
|
@@ -2149,7 +2196,9 @@ function toCodexInput(messages, options) {
|
|
|
2149
2196
|
continue;
|
|
2150
2197
|
}
|
|
2151
2198
|
for (const part of msg.content) {
|
|
2152
|
-
if (part.type === "
|
|
2199
|
+
if (part.type === "raw" && isEncryptedReasoning(part.data)) {
|
|
2200
|
+
input.push(part.data);
|
|
2201
|
+
} else if (part.type === "text") {
|
|
2153
2202
|
input.push({
|
|
2154
2203
|
type: "message",
|
|
2155
2204
|
role: "assistant",
|