Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

frontend: reconcile cost trend average, cap model table, pair budget controls

rcourtman0155bc45c0ff
diff --git a/frontend-modern/src/components/AI/AICostDashboard.tsx b/frontend-modern/src/components/AI/AICostDashboard.tsx
index 497d3c5c0b..7b9f16cdd7 100644
--- a/frontend-modern/src/components/AI/AICostDashboard.tsx
+++ b/frontend-modern/src/components/AI/AICostDashboard.tsx
@@ -99,6 +99,7 @@ export const AICostDashboard: Component = () => {
const [loading, setLoading] = createSignal(false);
const [loadError, setLoadError] = createSignal<string | null>(null);
const [summary, setSummary] = createSignal<AICostSummary | null>(null);
+ const [showAllModels, setShowAllModels] = createSignal(false);
let requestSeq = 0;
const anyPricingKnown = createMemo(() => {
@@ -139,19 +140,22 @@ export const AICostDashboard: Component = () => {
const dailyTokenValues = createMemo(() => dailyTotals().map((d) => d.total_tokens));
const dailyUSDValues = createMemo(() => dailyTotals().map((d) => d.estimated_usd ?? 0));
- // Trend cards characterise the range by its daily average, not the last
- // data point. Showing the last point read as "you spent $0 today" when
- // earlier days in the range carried the actual spend.
- const avgDailyTokens = createMemo(() => {
- const values = dailyTokenValues();
- if (values.length === 0) return null;
- return Math.round(values.reduce((sum, v) => sum + v, 0) / values.length);
+ // Trend cards average over the selected range (effective_days) so that
+ // avg/day x days reconciles with the headline total. Averaging only the
+ // days that recorded activity previously overstated the run-rate (e.g.
+ // $0.05/day next to a $0.50/30d total that implied $0.02/day).
+ const avgDailyUSD = createMemo(() => {
+ const total = estimatedTotalUSD();
+ const days = summary()?.effective_days;
+ if (total == null || !days || days <= 0) return null;
+ return total / days;
});
- const avgDailyUSD = createMemo(() => {
- const values = dailyUSDValues();
- if (values.length === 0) return null;
- return values.reduce((sum, v) => sum + v, 0) / values.length;
+ const avgDailyTokens = createMemo(() => {
+ const data = summary();
+ const days = data?.effective_days;
+ if (!data || !days || days <= 0) return null;
+ return Math.round(data.totals.total_tokens / days);
});
// Surface the real cost driver first: priced models by spend (desc),
@@ -169,6 +173,15 @@ export const AICostDashboard: Component = () => {
});
});
+ // Keep the default view on the rows that carry the cost signal; the long
+ // tail of flat / unpriced rows stays one click away.
+ const VISIBLE_MODEL_ROWS = 10;
+ const visibleProviderModels = createMemo(() => {
+ const all = sortedProviderModels();
+ if (showAllModels() || all.length <= VISIBLE_MODEL_ROWS) return all;
+ return all.slice(0, VISIBLE_MODEL_ROWS);
+ });
+
const formatUSD = (usd: number) => usdFormatter.format(usd);
const loadSummary = async (rangeDays: number) => {
@@ -551,7 +564,7 @@ export const AICostDashboard: Component = () => {
</TableRow>
</TableHeader>
<TableBody>
- <For each={sortedProviderModels()}>
+ <For each={visibleProviderModels()}>
{(pm) => (
<TableRow class="border-b border-border-subtle">
<TableCell class="py-2 pr-4 font-medium text-base-content">
@@ -582,6 +595,17 @@ export const AICostDashboard: Component = () => {
</For>
</TableBody>
</Table>
+ <Show when={sortedProviderModels().length > VISIBLE_MODEL_ROWS}>
+ <button
+ type="button"
+ class="self-start text-xs text-blue-600 dark:text-blue-400 hover:underline"
+ onClick={() => setShowAllModels(!showAllModels())}
+ >
+ {showAllModels()
+ ? 'Show less'
+ : `Show all ${sortedProviderModels().length} models`}
+ </button>
+ </Show>
</>
)}
</Show>
diff --git a/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx b/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
index 5b55834b9d..77a9247e5e 100644
--- a/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
+++ b/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
@@ -678,16 +678,17 @@ describe('AICostDashboard', () => {
expect(svgs.length).toBeGreaterThanOrEqual(2);
});
- it('labels trend cards with the daily average, not a single last point', async () => {
- // daily_totals fixture: two days, $0.21 each → avg $0.21/day. A last-point
- // label previously read as the headline and could misleadingly show $0.
+ it('labels the spend trend with a range average that reconciles with the total', async () => {
+ // fixture: $0.42 total over effective_days=30 → ~$0.01/day. The avg must
+ // be total / range days (not an average over active days only), so it no
+ // longer contradicts the headline spend.
renderDashboard();
await waitFor(() => {
expect(screen.getByText('Spend trend')).toBeInTheDocument();
});
const spendCard = screen.getByText('Spend trend').closest('.p-3')!;
expect(spendCard.textContent).toMatch(/avg\/day/);
- expect(spendCard.textContent).toMatch(/0\.21/);
+ expect(spendCard.textContent).toMatch(/0\.01/);
});
it('shows the shared daily token empty state when less than 2 daily totals', async () => {
diff --git a/frontend-modern/src/components/Settings/AIRuntimeControlsSection.tsx b/frontend-modern/src/components/Settings/AIRuntimeControlsSection.tsx
index 2ce994b3de..33e5f01d3d 100644
--- a/frontend-modern/src/components/Settings/AIRuntimeControlsSection.tsx
+++ b/frontend-modern/src/components/Settings/AIRuntimeControlsSection.tsx
@@ -173,7 +173,7 @@ export const AIProviderRuntimeControlsSection: Component<AIRuntimeControlsSectio
const { state } = props;
return (
- <>
+ <div class="grid gap-3 lg:grid-cols-2">
<div class="flex items-center gap-3 p-3 rounded-md border border-border bg-surface-alt">
<svg
class="w-4 h-4 text-muted flex-shrink-0"
@@ -212,48 +212,50 @@ export const AIProviderRuntimeControlsSection: Component<AIRuntimeControlsSectio
</Show>
</div>
- <div class="flex items-center gap-3 p-3 rounded-md border border-border bg-surface-alt">
- <svg
- class="w-4 h-4 text-muted flex-shrink-0"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
+ <div class="flex flex-col gap-1">
+ <div class="flex items-center gap-3 p-3 rounded-md border border-border bg-surface-alt">
+ <svg
+ class="w-4 h-4 text-muted flex-shrink-0"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
+ />
+ </svg>
+ <label class="text-xs font-medium text-base-content">Request Timeout</label>
+ <input
+ type="number"
+ class="w-20 min-h-10 sm:min-h-9 px-2 py-2 text-sm border border-border rounded bg-surface"
+ value={state.form.requestTimeoutSeconds}
+ onInput={(e) => {
+ const value = parseInt(e.currentTarget.value, 10);
+ if (!isNaN(value) && value > 0) {
+ state.setForm('requestTimeoutSeconds', value);
+ }
+ }}
+ min={30}
+ max={3600}
+ step={30}
+ disabled={state.saving()}
/>
- </svg>
- <label class="text-xs font-medium text-base-content">Request Timeout</label>
- <input
- type="number"
- class="w-20 min-h-10 sm:min-h-9 px-2 py-2 text-sm border border-border rounded bg-surface"
- value={state.form.requestTimeoutSeconds}
- onInput={(e) => {
- const value = parseInt(e.currentTarget.value, 10);
- if (!isNaN(value) && value > 0) {
- state.setForm('requestTimeoutSeconds', value);
- }
- }}
- min={30}
- max={3600}
- step={30}
- disabled={state.saving()}
- />
- <span class="text-xs">seconds</span>
- <Show when={state.form.requestTimeoutSeconds !== 300}>
- <span class="text-[10px] text-blue-600 dark:text-blue-400">Custom</span>
- </Show>
- <Show when={state.form.requestTimeoutSeconds === 300}>
- <span class="text-[10px] text-muted">default</span>
- </Show>
+ <span class="text-xs">seconds</span>
+ <Show when={state.form.requestTimeoutSeconds !== 300}>
+ <span class="text-[10px] text-blue-600 dark:text-blue-400">Custom</span>
+ </Show>
+ <Show when={state.form.requestTimeoutSeconds === 300}>
+ <span class="text-[10px] text-muted">default</span>
+ </Show>
+ </div>
+ <p class="text-[10px] text-muted ml-1">
+ Increase for slower Ollama hardware (default: 300s / 5 min)
+ </p>
</div>
- <p class="text-[10px] text-muted -mt-4 ml-1">
- Increase for slower Ollama hardware (default: 300s / 5 min)
- </p>
- </>
+ </div>
);
};