From ec8f306ad1d7898fc4ec86f91066066c855389b5 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 12 Dec 2025 13:37:30 +0000 Subject: [PATCH] Make AI cost sparklines more informative --- .../src/components/AI/AICostDashboard.tsx | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/frontend-modern/src/components/AI/AICostDashboard.tsx b/frontend-modern/src/components/AI/AICostDashboard.tsx index dae6d65..26738eb 100644 --- a/frontend-modern/src/components/AI/AICostDashboard.tsx +++ b/frontend-modern/src/components/AI/AICostDashboard.tsx @@ -98,8 +98,21 @@ export const AICostDashboard: Component = () => { return map; }); - const dailyTokenValues = createMemo(() => (summary()?.daily_totals ?? []).map((d) => d.total_tokens)); - const dailyUSDValues = createMemo(() => (summary()?.daily_totals ?? []).map((d) => d.estimated_usd ?? 0)); + const dailyTotals = createMemo(() => summary()?.daily_totals ?? []); + const dailyTokenValues = createMemo(() => dailyTotals().map((d) => d.total_tokens)); + const dailyUSDValues = createMemo(() => dailyTotals().map((d) => d.estimated_usd ?? 0)); + + const lastDailyTokens = createMemo(() => { + const values = dailyTokenValues(); + if (values.length === 0) return null; + return values[values.length - 1]; + }); + + const lastDailyUSD = createMemo(() => { + const values = dailyUSDValues(); + if (values.length === 0) return null; + return values[values.length - 1]; + }); const formatUSD = (usd: number) => usdFormatter.format(usd); @@ -406,19 +419,37 @@ export const AICostDashboard: Component = () => {
Daily estimated USD
-
{data().daily_totals.length} points
+
+ —}> + {formatUSD(lastDailyUSD() ?? 0)} + +
- + = 2} + fallback={
No daily USD trend yet.
} + > + +
Daily total tokens
-
{data().daily_totals.length} points
+
+ —}> + {formatNumber(lastDailyTokens() ?? 0)} + +
- + = 2} + fallback={
No daily token trend yet.
} + > + +