* feat(webui): expand settings with autosave and live configuration * feat(memory): add long-term memory and idle compaction switches * refactor(webui): clarify settings hierarchy and align compact controls * refactor(webui): keep only memory consolidation in memory settings * refactor(webui): defer runtime changes until explicit restart * refactor(webui): remove default workspace setting * fix(webui): align model lists and remove preset counters * fix(i18n): use natural Chinese labels for chat platforms * fix(i18n): shorten chat settings navigation label * fix(webui): match settings navigation icons to text size * refactor(webui): remove redundant settings sidebar heading * refactor(webui): use icon-only back navigation in settings * fix(webui): remove back arrow hover hint * refactor(webui): remove redundant overview details * refactor(webui): hide secondary descriptions in settings rows * style(webui): replace settings dividers with rounded highlights * refactor(webui): remove redundant model list subtitles and badges * fix(i18n): restore chat translation namespace boundaries * fix(i18n): complete settings translations for all locales * fix(webui): reveal settings only for enabled capabilities * fix(webui): consolidate capabilities and isolate settings feedback * fix(webui): clear restart notices when settings are reverted * fix(webui): anchor restart controls in settings sidebar * fix(webui): shorten sidebar restart label * fix(webui): align settings spacing and control sizes * refactor(webui): unify settings dialogs and interaction feedback * fix(webui): keep settings option groups on one line without scrolling * refactor(webui): align settings spacing and sidebar icon proportions * style(webui): match main sidebar typography to settings * style(webui): use monospace for sidebar session handles * refactor(webui): remove heartbeat configuration from automations * feat(webui): expose configuration actions beside capability toggles * style(webui): remove ellipsis from configuration actions * refactor(webui): remove redundant app configuration controls * feat(webui): add compact sidebar navigation and shortcut hints * fix(webui): synchronize npm dependency lockfile * test(webui): align input radius expectation with pill styling * feat(webui): show daily token usage and cache breakdown * feat(webui): add model usage details and cache hit rates * feat(webui): chart daily token usage by model * refactor(webui): simplify usage details and model labels * fix(webui): hide usage dialog date range * refactor(webui): consolidate model usage into chart legends * fix(webui): enforce restart choices and correct settings test route * fix(webui): polish settings localization and controls * fix(webui): avoid repeated usage legend labels * fix(webui): skip empty usage columns in keyboard navigation * test(webui): assert settings behavior positively * feat(webui): refine sidebar navigation and add drag resizing * style(webui): soften sidebar scroll edges * style(webui): harmonize sidebar typography and text colors * feat(webui): move channels to the main sidebar * style(webui): remove dotted underlines from settings hints * fix(webui): unify tooltip hover delay * fix(webui): support Seatbelt sandbox settings * fix(webui): remove unused appearance density preference * fix(webui): align settings input values consistently * style(webui): group compact settings controls before inputs * feat(webui): edit multiline settings in compact dialogs * feat(webui): add continuous settings scrolling with gentle snapping * Revert "feat(webui): add continuous settings scrolling with gentle snapping" This reverts commit f0978c261a53c844185eeab4d0c3190fbd196fe6.
48 lines
2.7 KiB
TypeScript
48 lines
2.7 KiB
TypeScript
import { ChevronRight } from "lucide-react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Dialog, DialogContent, DialogLayoutContext, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
|
import type { SettingsPayload } from "@/lib/types";
|
|
import { TokenUsageModelTrend } from "@/components/settings/TokenUsageModelTrend";
|
|
|
|
type Usage = NonNullable<SettingsPayload["usage"]>;
|
|
|
|
export function TokenUsageDetails({ days, models, modelDays }: {
|
|
days: { date: string; usage?: Usage["days"][number] }[];
|
|
models?: Usage["providers_30d"];
|
|
modelDays?: Usage["model_days_30d"];
|
|
}) {
|
|
const { t, i18n } = useTranslation();
|
|
const number = new Intl.NumberFormat(i18n.language, { maximumFractionDigits: 0 });
|
|
const percent = new Intl.NumberFormat(i18n.language, { style: "percent", maximumFractionDigits: 1 });
|
|
const sum = (key: "total_tokens" | "requests" | "cache_read_tokens" | "cache_read_observed_input_tokens") =>
|
|
days.reduce((total, day) => total + (day.usage?.[key] ?? 0), 0);
|
|
const total = sum("total_tokens");
|
|
const observed = sum("cache_read_observed_input_tokens");
|
|
const metrics = [
|
|
[t("settings.usage.totalTokens"), number.format(total)],
|
|
[t("settings.usage.requests"), number.format(sum("requests"))],
|
|
[t("settings.usage.cacheHitRate"), observed ? percent.format(sum("cache_read_tokens") / observed) : "—"],
|
|
];
|
|
return (
|
|
<DialogLayoutContext.Provider value={null}>
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<button type="button" className="settings-hover flex shrink-0 items-center gap-1 rounded-full px-2 py-1 text-xs text-muted-foreground focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring">
|
|
{t("settings.usage.viewDetails")}<ChevronRight className="size-3.5" aria-hidden />
|
|
</button>
|
|
</DialogTrigger>
|
|
<DialogContent className="w-[min(1100px,calc(100vw-32px))] max-w-none gap-5 p-5 pt-10 sm:p-7 sm:pt-10" aria-describedby={undefined}>
|
|
<DialogTitle className="sr-only">{t("settings.usage.shortTitle")}</DialogTitle>
|
|
<dl className="grid grid-cols-3 gap-3">
|
|
{metrics.map(([label, value], index) => <div key={label} title={index === 2 ? t("settings.usage.cacheRateHelp") : undefined}>
|
|
<dt className="text-xs text-muted-foreground">{label}</dt>
|
|
<dd className="mt-1 text-lg font-medium tabular-nums sm:text-2xl">{value}</dd>
|
|
</div>)}
|
|
</dl>
|
|
{modelDays?.length ? <TokenUsageModelTrend days={days} modelDays={modelDays} models={models} /> : <p className="text-sm text-muted-foreground">{t("settings.usage.modelsUnavailable")}</p>}
|
|
</DialogContent>
|
|
</Dialog>
|
|
</DialogLayoutContext.Provider>
|
|
);
|
|
}
|