@kenkaiiii/gg-ai 5.39.0 → 5.39.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 +35 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2090,7 +2090,15 @@ async function* runStream2(options) {
|
|
|
2090
2090
|
if (chunk.usage) {
|
|
2091
2091
|
({ inputTokens, outputTokens, cacheRead, cacheWrite } = extractOpenAIUsage(chunk.usage));
|
|
2092
2092
|
}
|
|
2093
|
-
if (!choice)
|
|
2093
|
+
if (!choice) {
|
|
2094
|
+
const gatewayError = classifyChoicelessFrame(chunk);
|
|
2095
|
+
if (gatewayError) {
|
|
2096
|
+
throw new ProviderError(providerName, gatewayError.message, {
|
|
2097
|
+
statusCode: gatewayError.statusCode
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
continue;
|
|
2101
|
+
}
|
|
2094
2102
|
if (choice.finish_reason) {
|
|
2095
2103
|
finishReason = choice.finish_reason;
|
|
2096
2104
|
}
|
|
@@ -2274,6 +2282,31 @@ function completionToResponse(completion, endpointKey) {
|
|
|
2274
2282
|
}
|
|
2275
2283
|
};
|
|
2276
2284
|
}
|
|
2285
|
+
function classifyChoicelessFrame(frame) {
|
|
2286
|
+
if (!frame || typeof frame !== "object" || Array.isArray(frame)) return null;
|
|
2287
|
+
const rec = frame;
|
|
2288
|
+
if (Array.isArray(rec.choices)) return null;
|
|
2289
|
+
const statusOf = (value) => {
|
|
2290
|
+
const n = typeof value === "string" ? Number(value) : value;
|
|
2291
|
+
return typeof n === "number" && Number.isFinite(n) && n >= 400 && n <= 599 ? n : void 0;
|
|
2292
|
+
};
|
|
2293
|
+
const statusCode = statusOf(rec.status) ?? statusOf(rec.statusCode) ?? statusOf(rec.code);
|
|
2294
|
+
const typeIsError = typeof rec.type === "string" && rec.type.toLowerCase() === "error";
|
|
2295
|
+
let detailText;
|
|
2296
|
+
const detail = rec.detail;
|
|
2297
|
+
if (typeof detail === "string" && detail.trim()) {
|
|
2298
|
+
detailText = detail.trim();
|
|
2299
|
+
} else if (Array.isArray(detail)) {
|
|
2300
|
+
const parts = detail.map(
|
|
2301
|
+
(d) => d && typeof d === "object" && typeof d.msg === "string" ? d.msg : typeof d === "string" ? d : ""
|
|
2302
|
+
).filter(Boolean);
|
|
2303
|
+
if (parts.length) detailText = parts.join("; ");
|
|
2304
|
+
}
|
|
2305
|
+
if (statusCode === void 0 && !typeIsError && !detailText) return null;
|
|
2306
|
+
const rawMessage = (typeof rec.message === "string" && rec.message.trim() ? rec.message.trim() : void 0) ?? detailText ?? (typeof rec.error === "string" && rec.error.trim() ? rec.error.trim() : void 0) ?? (statusCode !== void 0 ? `Gateway returned status ${statusCode}.` : "Gateway error.");
|
|
2307
|
+
const message = rawMessage.slice(0, 500);
|
|
2308
|
+
return { message, statusCode };
|
|
2309
|
+
}
|
|
2277
2310
|
function classifyOpenAICompatLimit(args) {
|
|
2278
2311
|
const { status, code, type, message } = args;
|
|
2279
2312
|
const codeType = `${code ?? ""} ${type ?? ""}`.toLowerCase();
|
|
@@ -2285,6 +2318,7 @@ function classifyOpenAICompatLimit(args) {
|
|
|
2285
2318
|
return null;
|
|
2286
2319
|
}
|
|
2287
2320
|
function toError2(err, provider = "openai") {
|
|
2321
|
+
if (err instanceof ProviderError) return err;
|
|
2288
2322
|
if (err instanceof import_openai.default.APIError) {
|
|
2289
2323
|
const body = err.error;
|
|
2290
2324
|
const bodyMessage = typeof body?.message === "string" && body.message.trim() ? body.message.trim() : void 0;
|