@kenkaiiii/gg-ai 4.3.239 → 4.3.241
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 +54 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -12
- 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;
|
|
@@ -1907,6 +1907,7 @@ async function* runStream3(options) {
|
|
|
1907
1907
|
const contentParts = [];
|
|
1908
1908
|
let textAccum = "";
|
|
1909
1909
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
1910
|
+
const orderedItems = [];
|
|
1910
1911
|
const outputItemTypes = /* @__PURE__ */ new Map();
|
|
1911
1912
|
const outputTextByPart = /* @__PURE__ */ new Map();
|
|
1912
1913
|
const pendingOutputTextByPart = /* @__PURE__ */ new Map();
|
|
@@ -2054,12 +2055,26 @@ async function* runStream3(options) {
|
|
|
2054
2055
|
}
|
|
2055
2056
|
if (type === "response.output_item.done") {
|
|
2056
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
|
+
}
|
|
2057
2071
|
if (item?.type === "function_call") {
|
|
2058
2072
|
const callId = item.call_id;
|
|
2059
2073
|
const itemId = item.id;
|
|
2060
2074
|
const id = `${callId}|${itemId}`;
|
|
2061
2075
|
const tc = toolCalls.get(id);
|
|
2062
2076
|
if (tc) {
|
|
2077
|
+
orderedItems.push({ kind: "tool", id });
|
|
2063
2078
|
const args = parseToolArguments(tc.argsJson);
|
|
2064
2079
|
yield {
|
|
2065
2080
|
type: "toolcall_done",
|
|
@@ -2080,19 +2095,41 @@ async function* runStream3(options) {
|
|
|
2080
2095
|
}
|
|
2081
2096
|
}
|
|
2082
2097
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
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);
|
|
2088
2112
|
const toolCall = {
|
|
2089
2113
|
type: "tool_call",
|
|
2090
2114
|
id: tc.id,
|
|
2091
2115
|
name: tc.name,
|
|
2092
|
-
args
|
|
2116
|
+
args: parseToolArguments(tc.argsJson)
|
|
2093
2117
|
};
|
|
2094
2118
|
contentParts.push(toolCall);
|
|
2095
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
|
+
}
|
|
2096
2133
|
const hasToolCalls = contentParts.some((p) => p.type === "tool_call");
|
|
2097
2134
|
const stopReason = hasToolCalls ? "tool_use" : "end_turn";
|
|
2098
2135
|
const streamResponse = {
|
|
@@ -2124,6 +2161,9 @@ function remapCodexId(id, idMap) {
|
|
|
2124
2161
|
idMap.set(id, mapped);
|
|
2125
2162
|
return mapped;
|
|
2126
2163
|
}
|
|
2164
|
+
function isEncryptedReasoning(data) {
|
|
2165
|
+
return data.type === "reasoning" && typeof data.id === "string" && typeof data.encrypted_content === "string";
|
|
2166
|
+
}
|
|
2127
2167
|
function toCodexInput(messages, options) {
|
|
2128
2168
|
let system;
|
|
2129
2169
|
const input = [];
|
|
@@ -2156,7 +2196,9 @@ function toCodexInput(messages, options) {
|
|
|
2156
2196
|
continue;
|
|
2157
2197
|
}
|
|
2158
2198
|
for (const part of msg.content) {
|
|
2159
|
-
if (part.type === "
|
|
2199
|
+
if (part.type === "raw" && isEncryptedReasoning(part.data)) {
|
|
2200
|
+
input.push(part.data);
|
|
2201
|
+
} else if (part.type === "text") {
|
|
2160
2202
|
input.push({
|
|
2161
2203
|
type: "message",
|
|
2162
2204
|
role: "assistant",
|