import { useState, type ReactNode } from "react"; import { createPortal } from "react-dom"; import { invoke } from "@tauri-apps/api/core"; import { useDashboard, type DashboardRange } from "../../hooks/useDashboard"; import { useCurrency } from "../../hooks/useCurrency"; import { useTranslation } from "../../i18n"; import { fmtInt, fmtPct, fmtTime, fmtTokens } from "../../lib/dashboard-format"; import { DailyBars } from "./DailyBars"; import { DailyDetailModal } from "./DailyDetailModal"; import { Heatmap } from "./Heatmap"; import { TrendLineChart } from "./TrendLineChart"; import type { DailyRow, HeatmapCell } from "../../types/dashboard"; const RANGES: DashboardRange[] = ["today", "7d", "30d", "all"]; /** Per-request cache hit rate: cached tokens / total input tokens. */ function cacheHitOf(r: { inputOther: number; inputCacheRead: number }): number { const denom = r.inputOther + r.inputCacheRead; return denom > 0 ? r.inputCacheRead / denom : 0; } function Card({ title, subtitle, children, className, }: { title: string; subtitle?: string; children: ReactNode; className?: string; }) { return (
| {t("colModel")} | {t("requests")} | {t("colTokens")} | {t("colCacheHit")} | {t("cost")} |
|---|---|---|---|---|
|
{m.isSecondary ? t("subagentModel") : m.modelDisplay || m.model}
{m.costEstimated && (
({t("estimate")})
)}
|
{fmtInt(m.requests)} | {fmtTokens(m.totalTokens)} | {fmtPct(m.cacheHitRate)} | {money(m.costUsd)} |
| {t("colTime")} | {t("colModel")} | {t("colInput")} | {t("colOutput")} | {t("colCacheRead")} | {t("colCacheHit")} | {t("cost")} |
|---|---|---|---|---|---|---|
| {fmtTime(r.time)} | {r.isSecondary ? t("subagentModel") : r.modelDisplay || r.model} | {fmtTokens(r.inputOther)} | {fmtTokens(r.output)} | {fmtTokens(r.inputCacheRead)} | {fmtPct(cacheHitOf(r))} | {money(r.costUsd)} |