@kenkaiiii/gg-core 5.22.1 → 5.22.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/index.cjs +15 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2192,9 +2192,10 @@ function getNextThinkingLevel(provider, model, current) {
|
|
|
2192
2192
|
|
|
2193
2193
|
// src/provider-usage.ts
|
|
2194
2194
|
var SubscriptionUsageError = class extends Error {
|
|
2195
|
-
constructor(message, status) {
|
|
2195
|
+
constructor(message, status, retryAfterMs2) {
|
|
2196
2196
|
super(message);
|
|
2197
2197
|
this.status = status;
|
|
2198
|
+
this.retryAfterMs = retryAfterMs2;
|
|
2198
2199
|
this.name = "SubscriptionUsageError";
|
|
2199
2200
|
}
|
|
2200
2201
|
};
|
|
@@ -2244,12 +2245,20 @@ function normalizedCodexWindow(window, fallbackKind, now) {
|
|
|
2244
2245
|
resetsAt: codexResetAt(window, now)
|
|
2245
2246
|
};
|
|
2246
2247
|
}
|
|
2247
|
-
|
|
2248
|
+
function retryAfterMs(response, now) {
|
|
2249
|
+
const value = response.headers.get("retry-after")?.trim();
|
|
2250
|
+
if (!value) return void 0;
|
|
2251
|
+
if (/^\d+(?:\.\d+)?$/.test(value)) return Math.ceil(Number(value) * 1e3);
|
|
2252
|
+
const retryAt = Date.parse(value);
|
|
2253
|
+
return Number.isFinite(retryAt) ? Math.max(0, retryAt - now) : void 0;
|
|
2254
|
+
}
|
|
2255
|
+
async function readUsageResponse(response, now) {
|
|
2248
2256
|
const text = await response.text();
|
|
2249
2257
|
if (!response.ok) {
|
|
2250
2258
|
throw new SubscriptionUsageError(
|
|
2251
2259
|
`Subscription usage request failed with HTTP ${response.status}`,
|
|
2252
|
-
response.status
|
|
2260
|
+
response.status,
|
|
2261
|
+
retryAfterMs(response, now)
|
|
2253
2262
|
);
|
|
2254
2263
|
}
|
|
2255
2264
|
try {
|
|
@@ -2270,7 +2279,7 @@ async function fetchAnthropicUsage(credentials, fetchFn, signal, now) {
|
|
|
2270
2279
|
"User-Agent": "ggcoder"
|
|
2271
2280
|
}
|
|
2272
2281
|
});
|
|
2273
|
-
const data = await readUsageResponse(response);
|
|
2282
|
+
const data = await readUsageResponse(response, now());
|
|
2274
2283
|
const windows = [];
|
|
2275
2284
|
const currentPercent = clampPercent(data.five_hour?.utilization);
|
|
2276
2285
|
if (currentPercent !== void 0) {
|
|
@@ -2306,7 +2315,7 @@ async function fetchCodexUsage(credentials, fetchFn, signal, now) {
|
|
|
2306
2315
|
};
|
|
2307
2316
|
if (credentials.accountId) headers["ChatGPT-Account-Id"] = credentials.accountId;
|
|
2308
2317
|
const response = await fetchFn(CODEX_USAGE_URL, { method: "GET", signal, headers });
|
|
2309
|
-
const data = await readUsageResponse(response);
|
|
2318
|
+
const data = await readUsageResponse(response, now());
|
|
2310
2319
|
const windows = [
|
|
2311
2320
|
normalizedCodexWindow(data.rate_limit?.primary_window, "current", now()),
|
|
2312
2321
|
normalizedCodexWindow(data.rate_limit?.secondary_window, "weekly", now())
|
|
@@ -2363,7 +2372,7 @@ async function fetchKimiUsage(credentials, fetchFn, signal, now) {
|
|
|
2363
2372
|
...kimiCodingHeaders()
|
|
2364
2373
|
}
|
|
2365
2374
|
});
|
|
2366
|
-
const data = await readUsageResponse(response);
|
|
2375
|
+
const data = await readUsageResponse(response, now());
|
|
2367
2376
|
const windows = [];
|
|
2368
2377
|
const weeklyPercent = kimiUsagePercent(data.usage);
|
|
2369
2378
|
if (weeklyPercent !== void 0) {
|