mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:18:27 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -2,20 +2,30 @@ import { clampPercent } from "./provider-usage.shared.js";
|
||||
import type { ProviderUsageSnapshot, UsageSummary, UsageWindow } from "./provider-usage.types.js";
|
||||
|
||||
function formatResetRemaining(targetMs?: number, now?: number): string | null {
|
||||
if (!targetMs) return null;
|
||||
if (!targetMs) {
|
||||
return null;
|
||||
}
|
||||
const base = now ?? Date.now();
|
||||
const diffMs = targetMs - base;
|
||||
if (diffMs <= 0) return "now";
|
||||
if (diffMs <= 0) {
|
||||
return "now";
|
||||
}
|
||||
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
if (diffMins < 60) return `${diffMins}m`;
|
||||
if (diffMins < 60) {
|
||||
return `${diffMins}m`;
|
||||
}
|
||||
|
||||
const hours = Math.floor(diffMins / 60);
|
||||
const mins = diffMins % 60;
|
||||
if (hours < 24) return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;
|
||||
if (hours < 24) {
|
||||
return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;
|
||||
}
|
||||
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days < 7) return `${days}d ${hours % 24}h`;
|
||||
if (days < 7) {
|
||||
return `${days}d ${hours % 24}h`;
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat("en-US", {
|
||||
month: "short",
|
||||
@@ -24,7 +34,9 @@ function formatResetRemaining(targetMs?: number, now?: number): string | null {
|
||||
}
|
||||
|
||||
function pickPrimaryWindow(windows: UsageWindow[]): UsageWindow | undefined {
|
||||
if (windows.length === 0) return undefined;
|
||||
if (windows.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return windows.reduce((best, next) => (next.usedPercent > best.usedPercent ? next : best));
|
||||
}
|
||||
|
||||
@@ -39,8 +51,12 @@ export function formatUsageWindowSummary(
|
||||
snapshot: ProviderUsageSnapshot,
|
||||
opts?: { now?: number; maxWindows?: number; includeResets?: boolean },
|
||||
): string | null {
|
||||
if (snapshot.error) return null;
|
||||
if (snapshot.windows.length === 0) return null;
|
||||
if (snapshot.error) {
|
||||
return null;
|
||||
}
|
||||
if (snapshot.windows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const now = opts?.now ?? Date.now();
|
||||
const maxWindows =
|
||||
typeof opts?.maxWindows === "number" && opts.maxWindows > 0
|
||||
@@ -64,17 +80,23 @@ export function formatUsageSummaryLine(
|
||||
const providers = summary.providers
|
||||
.filter((entry) => entry.windows.length > 0 && !entry.error)
|
||||
.slice(0, opts?.maxProviders ?? summary.providers.length);
|
||||
if (providers.length === 0) return null;
|
||||
if (providers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parts = providers
|
||||
.map((entry) => {
|
||||
const window = pickPrimaryWindow(entry.windows);
|
||||
if (!window) return null;
|
||||
if (!window) {
|
||||
return null;
|
||||
}
|
||||
return `${entry.displayName} ${formatWindowShort(window, opts?.now)}`;
|
||||
})
|
||||
.filter(Boolean) as string[];
|
||||
|
||||
if (parts.length === 0) return null;
|
||||
if (parts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return `📊 Usage: ${parts.join(" · ")}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user