Open-source, local-first AI agent for real work.
TypeScript agent-toolsai-agentbyokcoding-agentcross-platformdesktop-appdeveloper-toolselectronharnessknowledge-basellmwikilocal-firstmcpplugin-systemprivacy-firstskillstypescriptvettaworkflow-automation
import { Button } from "@vetta-org/ui/button";
import { cn } from "@vetta-org/ui/utils";
import type { JSX, ReactNode } from "react";
import { formatFileSize } from "../knowledge/types";
/** 图上方的读数:指到哪一项就读哪一项,不用浮层;三行高度固定,内容变化时不会跳动。 */
export function StorageReadout({
title,
bytes,
share,
hint,
scanning,
disabled,
scanningLabel,
rescanLabel,
onRescan,
}: {
readonly title: ReactNode;
/** null 表示首次扫描还没有结果。 */
readonly bytes: number | null;
/** 占整体的比例;不需要时不传。 */
readonly share?: number;
readonly hint: string;
readonly scanning: boolean;
readonly disabled: boolean;
readonly scanningLabel: string;
readonly rescanLabel: string;
readonly onRescan: () => void;
}): JSX.Element {
const [amount, unit] = bytes === null ? [] : formatFileSize(bytes).split(" ");
const refreshLabel = scanning ? scanningLabel : rescanLabel;
return (
<div className="flex items-start justify-between gap-4">
<div className="min-w-0 flex-1">
<div className="flex h-5 items-center text-[12px] text-muted-foreground">{title}</div>
<div className="mt-1.5 -ml-0.5 flex items-baseline gap-1.5">
{bytes === null ? (
<span className="ml-0.5 text-[20px] leading-10 text-muted-foreground">{scanning ? scanningLabel : "—"}</span>
) : (
<span className="text-[40px] leading-none font-semibold tracking-tight text-foreground">{amount}</span>
)}
<span className="text-[15px] text-muted-foreground">{unit}</span>
{share !== undefined && (
<span className="ml-1.5 text-[13px] text-muted-foreground">
{share < 0.01 ? "<1%" : `${Math.round(share * 100)}%`}
</span>
)}
</div>
<div className="mt-2.5 h-4 truncate text-[12px] text-muted-foreground">{hint}</div>
</div>
<Button
variant="ghost"
size="icon-sm"
className="-mr-1.5"
title={refreshLabel}
aria-label={refreshLabel}
disabled={scanning || disabled}
onClick={onRescan}
>
<span aria-hidden="true" className={cn("icon-[solar--refresh-linear] h-4 w-4", scanning && "animate-spin")} />
</Button>
</div>
);
}