Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

69 lines
1.9 KiB
TypeScript

import * as React from "react";
import {
USAGE_CRITICAL_PERCENT,
USAGE_WARN_PERCENT
} from "./model/agentUsageThresholds";
/**
* Maps a used-percent to a meter bar color: healthy (green) below the warn
* threshold, warning (amber) past it, and critical (red) near the limit.
*/
export function agentUsageBarColor(percentUsed: number): string {
if (percentUsed >= USAGE_CRITICAL_PERCENT) {
return "var(--state-danger)";
}
if (percentUsed >= USAGE_WARN_PERCENT) {
return "var(--state-warning)";
}
return "var(--state-success)";
}
export function AgentUsageMeter({
label,
value,
percent,
barColor,
testId
}: {
label: string;
value: string;
percent: number | null;
/** Overrides the bar fill color; defaults to the neutral primary text color. */
barColor?: string;
testId?: string;
}): React.JSX.Element {
const clampedPercent =
typeof percent === "number" && Number.isFinite(percent)
? Math.max(0, Math.min(100, percent))
: null;
return (
<div className="grid min-w-0 gap-1" data-testid={testId}>
<div className="flex min-w-0 items-center justify-between gap-3">
<span className="min-w-0 truncate text-[var(--text-secondary)]">
{label}
</span>
<span className="shrink-0 whitespace-nowrap text-[var(--text-secondary)]">
{value}
</span>
</div>
{clampedPercent !== null ? (
<span
aria-hidden="true"
className="relative h-1.5 overflow-hidden rounded-full bg-[color-mix(in_srgb,var(--text-primary)_10%,transparent)]"
>
<span
className="absolute inset-y-0 left-0 min-w-0.5 rounded-full"
style={{
width: `${clampedPercent}%`,
background:
barColor ?? "var(--agent-gui-text-primary,var(--text-primary))"
}}
/>
</span>
) : null}
</div>
);
}