@kenkaiiii/gg-core 5.13.2 → 5.14.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 +25 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2002,6 +2002,23 @@ function currentWindowLabel(seconds, fallbackHours) {
|
|
|
2002
2002
|
const hours = Math.max(1, Math.round((duration ?? fallbackHours * 3600) / 3600));
|
|
2003
2003
|
return `${hours}-hour`;
|
|
2004
2004
|
}
|
|
2005
|
+
function codexWindowKind(window, fallback) {
|
|
2006
|
+
const duration = finiteNumber(window.limit_window_seconds);
|
|
2007
|
+
if (duration === void 0) return fallback;
|
|
2008
|
+
return duration >= 6 * 24 * 60 * 60 ? "weekly" : "current";
|
|
2009
|
+
}
|
|
2010
|
+
function normalizedCodexWindow(window, fallbackKind, now) {
|
|
2011
|
+
if (!window) return null;
|
|
2012
|
+
const usedPercent = clampPercent(window.used_percent);
|
|
2013
|
+
if (usedPercent === void 0) return null;
|
|
2014
|
+
const kind = codexWindowKind(window, fallbackKind);
|
|
2015
|
+
return {
|
|
2016
|
+
kind,
|
|
2017
|
+
label: kind === "weekly" ? "Weekly" : currentWindowLabel(window.limit_window_seconds, 5),
|
|
2018
|
+
usedPercent,
|
|
2019
|
+
resetsAt: codexResetAt(window, now)
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2005
2022
|
async function readUsageResponse(response) {
|
|
2006
2023
|
const text = await response.text();
|
|
2007
2024
|
if (!response.ok) {
|
|
@@ -2065,27 +2082,14 @@ async function fetchCodexUsage(credentials, fetchFn, signal, now) {
|
|
|
2065
2082
|
if (credentials.accountId) headers["ChatGPT-Account-Id"] = credentials.accountId;
|
|
2066
2083
|
const response = await fetchFn(CODEX_USAGE_URL, { method: "GET", signal, headers });
|
|
2067
2084
|
const data = await readUsageResponse(response);
|
|
2068
|
-
const windows = [
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
resetsAt: codexResetAt(current, now())
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
const weekly = data.rate_limit?.secondary_window;
|
|
2080
|
-
const weeklyPercent = clampPercent(weekly?.used_percent);
|
|
2081
|
-
if (weekly && weeklyPercent !== void 0) {
|
|
2082
|
-
windows.push({
|
|
2083
|
-
kind: "weekly",
|
|
2084
|
-
label: "Weekly",
|
|
2085
|
-
usedPercent: weeklyPercent,
|
|
2086
|
-
resetsAt: codexResetAt(weekly, now())
|
|
2087
|
-
});
|
|
2088
|
-
}
|
|
2085
|
+
const windows = [
|
|
2086
|
+
normalizedCodexWindow(data.rate_limit?.primary_window, "current", now()),
|
|
2087
|
+
normalizedCodexWindow(data.rate_limit?.secondary_window, "weekly", now())
|
|
2088
|
+
].filter((window) => window !== null);
|
|
2089
|
+
windows.sort((left, right) => {
|
|
2090
|
+
if (left.kind === right.kind) return 0;
|
|
2091
|
+
return left.kind === "current" ? -1 : 1;
|
|
2092
|
+
});
|
|
2089
2093
|
return {
|
|
2090
2094
|
provider: "openai",
|
|
2091
2095
|
displayName: "Codex",
|