mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:01:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -4,25 +4,39 @@ export const formatKTokens = (value: number) =>
|
||||
`${(value / 1000).toFixed(value >= 10_000 ? 0 : 1)}k`;
|
||||
|
||||
export const formatAge = (ms: number | null | undefined) => {
|
||||
if (!ms || ms < 0) return "unknown";
|
||||
if (!ms || ms < 0) {
|
||||
return "unknown";
|
||||
}
|
||||
const minutes = Math.round(ms / 60_000);
|
||||
if (minutes < 1) return "just now";
|
||||
if (minutes < 60) return `${minutes}m ago`;
|
||||
if (minutes < 1) {
|
||||
return "just now";
|
||||
}
|
||||
if (minutes < 60) {
|
||||
return `${minutes}m ago`;
|
||||
}
|
||||
const hours = Math.round(minutes / 60);
|
||||
if (hours < 48) return `${hours}h ago`;
|
||||
if (hours < 48) {
|
||||
return `${hours}h ago`;
|
||||
}
|
||||
const days = Math.round(hours / 24);
|
||||
return `${days}d ago`;
|
||||
};
|
||||
|
||||
export const formatDuration = (ms: number | null | undefined) => {
|
||||
if (ms == null || !Number.isFinite(ms)) return "unknown";
|
||||
if (ms < 1000) return `${Math.round(ms)}ms`;
|
||||
if (ms == null || !Number.isFinite(ms)) {
|
||||
return "unknown";
|
||||
}
|
||||
if (ms < 1000) {
|
||||
return `${Math.round(ms)}ms`;
|
||||
}
|
||||
return `${(ms / 1000).toFixed(1)}s`;
|
||||
};
|
||||
|
||||
export const shortenText = (value: string, maxLen: number) => {
|
||||
const chars = Array.from(value);
|
||||
if (chars.length <= maxLen) return value;
|
||||
if (chars.length <= maxLen) {
|
||||
return value;
|
||||
}
|
||||
return `${chars.slice(0, Math.max(0, maxLen - 1)).join("")}…`;
|
||||
};
|
||||
|
||||
@@ -31,7 +45,9 @@ export const formatTokensCompact = (
|
||||
) => {
|
||||
const used = sess.totalTokens ?? 0;
|
||||
const ctx = sess.contextTokens;
|
||||
if (!ctx) return `${formatKTokens(used)} used`;
|
||||
if (!ctx) {
|
||||
return `${formatKTokens(used)} used`;
|
||||
}
|
||||
const pctLabel = sess.percentUsed != null ? `${sess.percentUsed}%` : "?%";
|
||||
return `${formatKTokens(used)}/${formatKTokens(ctx)} (${pctLabel})`;
|
||||
};
|
||||
@@ -43,16 +59,22 @@ export const formatDaemonRuntimeShort = (runtime?: {
|
||||
detail?: string;
|
||||
missingUnit?: boolean;
|
||||
}) => {
|
||||
if (!runtime) return null;
|
||||
if (!runtime) {
|
||||
return null;
|
||||
}
|
||||
const status = runtime.status ?? "unknown";
|
||||
const details: string[] = [];
|
||||
if (runtime.pid) details.push(`pid ${runtime.pid}`);
|
||||
if (runtime.pid) {
|
||||
details.push(`pid ${runtime.pid}`);
|
||||
}
|
||||
if (runtime.state && runtime.state.toLowerCase() !== status) {
|
||||
details.push(`state ${runtime.state}`);
|
||||
}
|
||||
const detail = runtime.detail?.replace(/\s+/g, " ").trim() || "";
|
||||
const noisyLaunchctlDetail =
|
||||
runtime.missingUnit === true && detail.toLowerCase().includes("could not find service");
|
||||
if (detail && !noisyLaunchctlDetail) details.push(detail);
|
||||
if (detail && !noisyLaunchctlDetail) {
|
||||
details.push(detail);
|
||||
}
|
||||
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user