@kenkaiiii/gg-core 5.21.0 → 5.22.0
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 +86 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2322,12 +2322,97 @@ async function fetchCodexUsage(credentials, fetchFn, signal, now) {
|
|
|
2322
2322
|
fetchedAt: now()
|
|
2323
2323
|
};
|
|
2324
2324
|
}
|
|
2325
|
+
function kimiNumber(value) {
|
|
2326
|
+
if (typeof value === "string" && value.trim()) {
|
|
2327
|
+
const parsed = Number(value);
|
|
2328
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
2329
|
+
}
|
|
2330
|
+
return finiteNumber(value);
|
|
2331
|
+
}
|
|
2332
|
+
function kimiUsagePercent(detail) {
|
|
2333
|
+
const used = kimiNumber(detail?.used);
|
|
2334
|
+
const limit = kimiNumber(detail?.limit);
|
|
2335
|
+
if (used === void 0 || limit === void 0 || limit <= 0) return void 0;
|
|
2336
|
+
return Math.min(100, Math.max(0, used / limit * 100));
|
|
2337
|
+
}
|
|
2338
|
+
function kimiWindowMinutes(window) {
|
|
2339
|
+
const duration = kimiNumber(window?.duration);
|
|
2340
|
+
if (duration === void 0 || duration <= 0) return void 0;
|
|
2341
|
+
switch (window?.timeUnit) {
|
|
2342
|
+
case "TIME_UNIT_SECOND":
|
|
2343
|
+
return duration / 60;
|
|
2344
|
+
case "TIME_UNIT_MINUTE":
|
|
2345
|
+
return duration;
|
|
2346
|
+
case "TIME_UNIT_HOUR":
|
|
2347
|
+
return duration * 60;
|
|
2348
|
+
case "TIME_UNIT_DAY":
|
|
2349
|
+
return duration * 24 * 60;
|
|
2350
|
+
default:
|
|
2351
|
+
return void 0;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
async function fetchKimiUsage(credentials, fetchFn, signal, now) {
|
|
2355
|
+
const response = await fetchFn(`${kimiCodeBaseUrl()}/usages`, {
|
|
2356
|
+
method: "GET",
|
|
2357
|
+
signal,
|
|
2358
|
+
headers: {
|
|
2359
|
+
Authorization: "Bearer " + credentials.accessToken,
|
|
2360
|
+
Accept: "application/json",
|
|
2361
|
+
// The managed coding endpoint gates on the kimi-code-cli client identity,
|
|
2362
|
+
// same as model requests.
|
|
2363
|
+
...kimiCodingHeaders()
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
const data = await readUsageResponse(response);
|
|
2367
|
+
const windows = [];
|
|
2368
|
+
const weeklyPercent = kimiUsagePercent(data.usage);
|
|
2369
|
+
if (weeklyPercent !== void 0) {
|
|
2370
|
+
windows.push({
|
|
2371
|
+
kind: "weekly",
|
|
2372
|
+
label: "Weekly",
|
|
2373
|
+
usedPercent: weeklyPercent,
|
|
2374
|
+
resetsAt: isoTimestamp(data.usage?.resetTime)
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
for (const limit of data.limits ?? []) {
|
|
2378
|
+
const minutes = kimiWindowMinutes(limit?.window);
|
|
2379
|
+
const percent = kimiUsagePercent(limit?.detail);
|
|
2380
|
+
if (minutes === void 0 || percent === void 0) continue;
|
|
2381
|
+
if (minutes >= 6 * 24 * 60) {
|
|
2382
|
+
if (!windows.some((window) => window.kind === "weekly")) {
|
|
2383
|
+
windows.push({
|
|
2384
|
+
kind: "weekly",
|
|
2385
|
+
label: "Weekly",
|
|
2386
|
+
usedPercent: percent,
|
|
2387
|
+
resetsAt: isoTimestamp(limit?.detail?.resetTime)
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
continue;
|
|
2391
|
+
}
|
|
2392
|
+
windows.push({
|
|
2393
|
+
kind: "current",
|
|
2394
|
+
label: `${Math.max(1, Math.round(minutes / 60))}-hour`,
|
|
2395
|
+
usedPercent: percent,
|
|
2396
|
+
resetsAt: isoTimestamp(limit?.detail?.resetTime)
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
windows.sort((left, right) => {
|
|
2400
|
+
if (left.kind === right.kind) return 0;
|
|
2401
|
+
return left.kind === "current" ? -1 : 1;
|
|
2402
|
+
});
|
|
2403
|
+
return {
|
|
2404
|
+
provider: "moonshot",
|
|
2405
|
+
displayName: "Kimi",
|
|
2406
|
+
windows,
|
|
2407
|
+
fetchedAt: now()
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2325
2410
|
async function fetchSubscriptionUsage(provider, credentials, options = {}) {
|
|
2326
2411
|
const fetchFn = options.fetchFn ?? fetch;
|
|
2327
2412
|
const now = options.now ?? Date.now;
|
|
2328
2413
|
const signal = AbortSignal.timeout(options.timeoutMs ?? 8e3);
|
|
2329
2414
|
try {
|
|
2330
|
-
return provider === "anthropic" ? await fetchAnthropicUsage(credentials, fetchFn, signal, now) : await fetchCodexUsage(credentials, fetchFn, signal, now);
|
|
2415
|
+
return provider === "anthropic" ? await fetchAnthropicUsage(credentials, fetchFn, signal, now) : provider === "openai" ? await fetchCodexUsage(credentials, fetchFn, signal, now) : await fetchKimiUsage(credentials, fetchFn, signal, now);
|
|
2331
2416
|
} catch (error) {
|
|
2332
2417
|
if (error instanceof SubscriptionUsageError) throw error;
|
|
2333
2418
|
const message = error instanceof Error ? error.message : String(error);
|