mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 12:38:34 +00:00
fix(models): infer codex weekly usage labels from reset cadence
This commit is contained in:
committed by
Peter Steinberger
parent
479095bcfb
commit
16e7fc2563
@@ -19,6 +19,31 @@ type CodexUsageResponse = {
|
||||
credits?: { balance?: number | string | null };
|
||||
};
|
||||
|
||||
const WEEKLY_RESET_GAP_SECONDS = 3 * 24 * 60 * 60;
|
||||
|
||||
function resolveSecondaryWindowLabel(params: {
|
||||
windowHours: number;
|
||||
secondaryResetAt?: number;
|
||||
primaryResetAt?: number;
|
||||
}): string {
|
||||
if (params.windowHours >= 168) {
|
||||
return "Week";
|
||||
}
|
||||
if (params.windowHours < 24) {
|
||||
return `${params.windowHours}h`;
|
||||
}
|
||||
// Codex occasionally reports a 24h secondary window while exposing a
|
||||
// weekly reset cadence in reset timestamps. Prefer cadence in that case.
|
||||
if (
|
||||
typeof params.secondaryResetAt === "number" &&
|
||||
typeof params.primaryResetAt === "number" &&
|
||||
params.secondaryResetAt - params.primaryResetAt >= WEEKLY_RESET_GAP_SECONDS
|
||||
) {
|
||||
return "Week";
|
||||
}
|
||||
return "Day";
|
||||
}
|
||||
|
||||
export async function fetchCodexUsage(
|
||||
token: string,
|
||||
accountId: string | undefined,
|
||||
@@ -65,7 +90,11 @@ export async function fetchCodexUsage(
|
||||
if (data.rate_limit?.secondary_window) {
|
||||
const sw = data.rate_limit.secondary_window;
|
||||
const windowHours = Math.round((sw.limit_window_seconds || 86400) / 3600);
|
||||
const label = windowHours >= 168 ? "Week" : windowHours >= 24 ? "Day" : `${windowHours}h`;
|
||||
const label = resolveSecondaryWindowLabel({
|
||||
windowHours,
|
||||
primaryResetAt: data.rate_limit?.primary_window?.reset_at,
|
||||
secondaryResetAt: sw.reset_at,
|
||||
});
|
||||
windows.push({
|
||||
label,
|
||||
usedPercent: clampPercent(sw.used_percent || 0),
|
||||
|
||||
Reference in New Issue
Block a user