ghc-proxy 0.9.2 → 0.9.3
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/main.mjs +35 -4
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -6780,7 +6780,31 @@ const RECOVERY_EVENT_OPTIONAL_FIELDS = [
|
|
|
6780
6780
|
"nextRetryAt",
|
|
6781
6781
|
"decision"
|
|
6782
6782
|
];
|
|
6783
|
+
function isRoutineRecoveryEvent(fields) {
|
|
6784
|
+
return fields.event === "cooldown" || fields.event === "grant" && fields.queueWaitMs === 0 || fields.event === "retry" && fields.status !== void 0 && fields.decision === "retry";
|
|
6785
|
+
}
|
|
6786
|
+
function formatRecoveryEventLine(fields) {
|
|
6787
|
+
const kind = fields.status === 429 ? "rate limit" : fields.status === 529 ? "overload" : "recovery";
|
|
6788
|
+
const includeQueueState = fields.event === "admission" || fields.event === "grant";
|
|
6789
|
+
return [
|
|
6790
|
+
`Upstream ${kind}`,
|
|
6791
|
+
fields.decision ?? fields.event,
|
|
6792
|
+
fields.status !== void 0 ? `status=${fields.status}` : void 0,
|
|
6793
|
+
fields.effectiveModel ? `model=${JSON.stringify(fields.effectiveModel).slice(1, -1)}` : void 0,
|
|
6794
|
+
fields.scope ? `scope=${fields.scope}` : void 0,
|
|
6795
|
+
fields.retryCount !== void 0 ? `retry=${fields.retryCount}` : void 0,
|
|
6796
|
+
fields.connectionClass ? `connection=${fields.connectionClass}` : void 0,
|
|
6797
|
+
fields.delayMs !== void 0 ? `wait=${formatDurationMs(fields.delayMs)}` : void 0,
|
|
6798
|
+
fields.delaySource ? `source=${fields.delaySource}` : void 0,
|
|
6799
|
+
fields.queueWaitMs !== void 0 && fields.queueWaitMs > 0 ? `queueWait=${formatDurationMs(fields.queueWaitMs)}` : void 0,
|
|
6800
|
+
includeQueueState && fields.activeSlots !== void 0 && fields.maxSlots !== void 0 ? `slots=${fields.activeSlots}/${fields.maxSlots}` : void 0,
|
|
6801
|
+
includeQueueState && fields.pendingDepth !== void 0 && fields.maxPendingDepth !== void 0 ? `queue=${fields.pendingDepth}/${fields.maxPendingDepth}` : void 0,
|
|
6802
|
+
fields.remainingBudgetMs !== void 0 ? `budget=${formatDurationMs(fields.remainingBudgetMs)}` : void 0,
|
|
6803
|
+
`rid=${fields.requestId.slice(0, 8)}`
|
|
6804
|
+
].filter((value) => value !== void 0).join(" ");
|
|
6805
|
+
}
|
|
6783
6806
|
function logRecoveryEvent(input, logger = consola) {
|
|
6807
|
+
if (logger === consola && isRoutineRecoveryEvent(input)) return;
|
|
6784
6808
|
const callerRequestId = sanitizeCallerRequestId(input.callerRequestId);
|
|
6785
6809
|
const fields = {
|
|
6786
6810
|
requestId: input.requestId,
|
|
@@ -6788,6 +6812,10 @@ function logRecoveryEvent(input, logger = consola) {
|
|
|
6788
6812
|
event: input.event
|
|
6789
6813
|
};
|
|
6790
6814
|
for (const key of RECOVERY_EVENT_OPTIONAL_FIELDS) if (input[key] !== void 0) Object.assign(fields, { [key]: input[key] });
|
|
6815
|
+
if (logger === consola) {
|
|
6816
|
+
consola.info(formatRecoveryEventLine(fields));
|
|
6817
|
+
return;
|
|
6818
|
+
}
|
|
6791
6819
|
logger.info("Upstream recovery", fields);
|
|
6792
6820
|
}
|
|
6793
6821
|
function setRequestModelMapping(request, info) {
|
|
@@ -7091,8 +7119,9 @@ var UpstreamRequestQueue = class {
|
|
|
7091
7119
|
discardResponse(response);
|
|
7092
7120
|
lease.release();
|
|
7093
7121
|
recovery.retryCount++;
|
|
7122
|
+
const statusLabel = status === 429 ? "rate limited (429)" : status === 529 ? "overloaded (529)" : String(status);
|
|
7094
7123
|
this.logger.warn([
|
|
7095
|
-
`Upstream ${
|
|
7124
|
+
`Upstream ${statusLabel};`,
|
|
7096
7125
|
`retrying ${formatRequestContext(context)}`,
|
|
7097
7126
|
`in ${formatDurationMs(retryDelay.delayMs)}`,
|
|
7098
7127
|
`(attempt ${recovery.retryCount}/${recovery.retryLimit})`
|
|
@@ -7398,7 +7427,7 @@ var UpstreamRequestQueue = class {
|
|
|
7398
7427
|
maxPendingDepth: this.options.maxQueueDepth
|
|
7399
7428
|
};
|
|
7400
7429
|
if (!this.logger.info) return;
|
|
7401
|
-
|
|
7430
|
+
const eventFields = {
|
|
7402
7431
|
requestId: recovery.requestId,
|
|
7403
7432
|
callerRequestId: recovery.callerRequestId,
|
|
7404
7433
|
event,
|
|
@@ -7409,7 +7438,9 @@ var UpstreamRequestQueue = class {
|
|
|
7409
7438
|
remainingBudgetMs: this.remainingBudget(recovery)
|
|
7410
7439
|
} : {},
|
|
7411
7440
|
...fields
|
|
7412
|
-
}
|
|
7441
|
+
};
|
|
7442
|
+
if (this.logger === consola) logRecoveryEvent(eventFields);
|
|
7443
|
+
else logRecoveryEvent(eventFields, { info: this.logger.info.bind(this.logger) });
|
|
7413
7444
|
}
|
|
7414
7445
|
emitTerminal(event, context, fields) {
|
|
7415
7446
|
if (this.terminalRecoveries.has(context.recovery)) return;
|
|
@@ -8237,7 +8268,7 @@ const checkUsage = defineCommand({
|
|
|
8237
8268
|
});
|
|
8238
8269
|
//#endregion
|
|
8239
8270
|
//#region src/util/version.ts
|
|
8240
|
-
const VERSION = "0.9.
|
|
8271
|
+
const VERSION = "0.9.3";
|
|
8241
8272
|
//#endregion
|
|
8242
8273
|
//#region src/debug.ts
|
|
8243
8274
|
function getRuntimeInfo() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ghc-proxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.3",
|
|
5
5
|
"description": "GitHub Copilot to OpenAI/Anthropic API proxy - Use Copilot with Claude Code, Cursor, and more",
|
|
6
6
|
"author": "wxxb789 <wxxb789@outlook.com>",
|
|
7
7
|
"homepage": "https://github.com/wxxb789/ghc-proxy",
|