@kenkaiiii/gg-ai 4.3.184 → 4.3.186
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 +49 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -718,6 +718,9 @@ function normalizeOpenAIStopReason(reason) {
|
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
// src/providers/anthropic.ts
|
|
721
|
+
function isJsonObject(value) {
|
|
722
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
723
|
+
}
|
|
721
724
|
function createClient(options) {
|
|
722
725
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
723
726
|
return new Anthropic({
|
|
@@ -876,6 +879,7 @@ async function* runStream(options) {
|
|
|
876
879
|
if (block.type === "tool_use") {
|
|
877
880
|
accum.toolId = block.id;
|
|
878
881
|
accum.toolName = block.name;
|
|
882
|
+
accum.input = block.input;
|
|
879
883
|
} else if (block.type === "server_tool_use") {
|
|
880
884
|
accum.toolId = block.id;
|
|
881
885
|
accum.toolName = block.name;
|
|
@@ -931,10 +935,13 @@ async function* runStream(options) {
|
|
|
931
935
|
});
|
|
932
936
|
yield keepalive;
|
|
933
937
|
} else if (accum.type === "tool_use") {
|
|
934
|
-
let args = {};
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
+
let args = isJsonObject(accum.input) ? accum.input : {};
|
|
939
|
+
if (accum.argsJson) {
|
|
940
|
+
try {
|
|
941
|
+
const parsed = JSON.parse(accum.argsJson);
|
|
942
|
+
args = isJsonObject(parsed) ? parsed : {};
|
|
943
|
+
} catch {
|
|
944
|
+
}
|
|
938
945
|
}
|
|
939
946
|
const tc = {
|
|
940
947
|
type: "tool_call",
|
|
@@ -1132,8 +1139,13 @@ function messageToResponse(message) {
|
|
|
1132
1139
|
}
|
|
1133
1140
|
function toError(err) {
|
|
1134
1141
|
if (err instanceof Anthropic.APIError) {
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1142
|
+
const errorBody = err.error;
|
|
1143
|
+
const nestedError = errorBody?.error;
|
|
1144
|
+
const requestId = err.requestID ?? err.request_id ?? (typeof errorBody?.request_id === "string" ? errorBody.request_id : void 0) ?? (typeof nestedError?.request_id === "string" ? nestedError.request_id : void 0) ?? void 0;
|
|
1145
|
+
const bodyMessage = typeof nestedError?.message === "string" ? nestedError.message : typeof errorBody?.message === "string" ? errorBody.message : void 0;
|
|
1146
|
+
const bodyType = typeof nestedError?.type === "string" ? nestedError.type : typeof errorBody?.type === "string" ? errorBody.type : typeof err.type === "string" ? err.type : void 0;
|
|
1147
|
+
const message = bodyType && bodyMessage ? `${bodyType}: ${bodyMessage}` : bodyMessage ?? err.message;
|
|
1148
|
+
return new ProviderError("anthropic", message, {
|
|
1137
1149
|
statusCode: err.status,
|
|
1138
1150
|
...requestId ? { requestId } : {},
|
|
1139
1151
|
cause: err
|
|
@@ -1147,6 +1159,19 @@ function toError(err) {
|
|
|
1147
1159
|
|
|
1148
1160
|
// src/providers/openai.ts
|
|
1149
1161
|
import OpenAI from "openai";
|
|
1162
|
+
function isJsonObject2(value) {
|
|
1163
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
1164
|
+
}
|
|
1165
|
+
function parseToolArguments(argsJson) {
|
|
1166
|
+
if (!argsJson) return {};
|
|
1167
|
+
try {
|
|
1168
|
+
const parsed = JSON.parse(argsJson);
|
|
1169
|
+
const unwrapped = typeof parsed === "string" ? JSON.parse(parsed) : parsed;
|
|
1170
|
+
return isJsonObject2(unwrapped) ? unwrapped : {};
|
|
1171
|
+
} catch {
|
|
1172
|
+
return {};
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1150
1175
|
function createClient2(options) {
|
|
1151
1176
|
return new OpenAI({
|
|
1152
1177
|
apiKey: options.apiKey,
|
|
@@ -1304,11 +1329,7 @@ async function* runStream2(options) {
|
|
|
1304
1329
|
contentParts.push({ type: "text", text: textAccum });
|
|
1305
1330
|
}
|
|
1306
1331
|
for (const [, tc] of toolCallAccum) {
|
|
1307
|
-
|
|
1308
|
-
try {
|
|
1309
|
-
args = JSON.parse(tc.argsJson);
|
|
1310
|
-
} catch {
|
|
1311
|
-
}
|
|
1332
|
+
const args = parseToolArguments(tc.argsJson);
|
|
1312
1333
|
const toolCall = {
|
|
1313
1334
|
type: "tool_call",
|
|
1314
1335
|
id: tc.id,
|
|
@@ -1361,11 +1382,7 @@ function* synthesizeEventsFromCompletion(completion, thinkingEnabled) {
|
|
|
1361
1382
|
argsJson
|
|
1362
1383
|
};
|
|
1363
1384
|
}
|
|
1364
|
-
|
|
1365
|
-
try {
|
|
1366
|
-
args = JSON.parse(argsJson);
|
|
1367
|
-
} catch {
|
|
1368
|
-
}
|
|
1385
|
+
const args = parseToolArguments(argsJson);
|
|
1369
1386
|
yield {
|
|
1370
1387
|
type: "toolcall_done",
|
|
1371
1388
|
id: tc.id,
|
|
@@ -1393,11 +1410,7 @@ function completionToResponse(completion) {
|
|
|
1393
1410
|
const toolCalls = msg.tool_calls;
|
|
1394
1411
|
if (toolCalls) {
|
|
1395
1412
|
for (const tc of toolCalls) {
|
|
1396
|
-
|
|
1397
|
-
try {
|
|
1398
|
-
args = JSON.parse(tc.function?.arguments ?? "{}");
|
|
1399
|
-
} catch {
|
|
1400
|
-
}
|
|
1413
|
+
const args = parseToolArguments(tc.function?.arguments ?? "");
|
|
1401
1414
|
const toolCall = {
|
|
1402
1415
|
type: "tool_call",
|
|
1403
1416
|
id: tc.id,
|
|
@@ -1472,6 +1485,19 @@ function providerDiag(phase, data) {
|
|
|
1472
1485
|
|
|
1473
1486
|
// src/providers/openai-codex.ts
|
|
1474
1487
|
var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
1488
|
+
function isJsonObject3(value) {
|
|
1489
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
1490
|
+
}
|
|
1491
|
+
function parseToolArguments2(argsJson) {
|
|
1492
|
+
if (!argsJson) return {};
|
|
1493
|
+
try {
|
|
1494
|
+
const parsed = JSON.parse(argsJson);
|
|
1495
|
+
const unwrapped = typeof parsed === "string" ? JSON.parse(parsed) : parsed;
|
|
1496
|
+
return isJsonObject3(unwrapped) ? unwrapped : {};
|
|
1497
|
+
} catch {
|
|
1498
|
+
return {};
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1475
1501
|
function streamOpenAICodex(options) {
|
|
1476
1502
|
return new StreamResult(runStream3(options));
|
|
1477
1503
|
}
|
|
@@ -1644,11 +1670,7 @@ async function* runStream3(options) {
|
|
|
1644
1670
|
const id = `${callId}|${itemId}`;
|
|
1645
1671
|
const tc = toolCalls.get(id);
|
|
1646
1672
|
if (tc) {
|
|
1647
|
-
|
|
1648
|
-
try {
|
|
1649
|
-
args = JSON.parse(tc.argsJson);
|
|
1650
|
-
} catch {
|
|
1651
|
-
}
|
|
1673
|
+
const args = parseToolArguments2(tc.argsJson);
|
|
1652
1674
|
yield {
|
|
1653
1675
|
type: "toolcall_done",
|
|
1654
1676
|
id: tc.id,
|
|
@@ -1672,11 +1694,7 @@ async function* runStream3(options) {
|
|
|
1672
1694
|
contentParts.push({ type: "text", text: textAccum });
|
|
1673
1695
|
}
|
|
1674
1696
|
for (const [, tc] of toolCalls) {
|
|
1675
|
-
|
|
1676
|
-
try {
|
|
1677
|
-
args = JSON.parse(tc.argsJson);
|
|
1678
|
-
} catch {
|
|
1679
|
-
}
|
|
1697
|
+
const args = parseToolArguments2(tc.argsJson);
|
|
1680
1698
|
const toolCall = {
|
|
1681
1699
|
type: "tool_call",
|
|
1682
1700
|
id: tc.id,
|