From 2298249df5fb496699ea4bb2e04fe668be9c9816 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Fri, 21 Aug 2026 23:23:21 +0100 Subject: [PATCH] feat(webui): rate badges, refresh labels, anchor links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Providers tab (Feature A): a new ProviderRateBadge component renders each provider's day-window success rate (attempts-failures)/attempts — always shown when attempts>0 (100% muted, <99% amber via the chart palette's --color-chart-tokens-out token, <90% destructive, reusing the Badge component's existing secondary/outline/destructive idioms rather than inventing a new variant), a distinct "no traffic" badge when attempts=0, and the live minute-window count in its title attribute. The same component renders beside a ModelChip inside a provider's accordion, but only when that model is degraded (<99% with attempts>0) so a long, healthy model list stays uncluttered. The math and its threshold constants live in lib/provider-rate.ts, unit-tested directly (vitest's node environment needs no component mount). Feature B: a provider's "refreshed ..." label (lib/format.ts's new refreshLabel) now reads "discovery off" when DiscoveryEnabled is false, "pending" when it is true but lastRefresh is still unset, and otherwise the unchanged relative-time text — replacing the misleading "refreshed never" a discovery-disabled provider showed before. Feature C: composables/useTabHash syncs App.vue's active tab to the URL hash (#providers/#usage/#charts/#targets, matching the existing TabsTrigger values) with no router dependency. On load it reads the current hash (falling back to "providers" for an absent or invalid one); on tab change it writes the hash back via history.replaceState (no scroll jump, no new history entry per click); a hashchange listener handles back/forward and hand-edited URLs. hashToTab/tabToHash are exported as pure functions so the mapping is unit-tested directly, independent of window/history/location — every DOM touch inside useTabHash itself is guarded behind one hasWindow check so the module still imports cleanly under vitest's node test environment. AuthGate never reads or writes the hash, so a tab named in the URL survives the unauthenticated -> authenticated transition unchanged. --- webui/src/App.vue | 14 ++- webui/src/components/ProviderRateBadge.vue | 52 ++++++++++ webui/src/components/ProvidersView.vue | 39 +++++++- webui/src/composables/useTabHash.spec.ts | 49 ++++++++++ webui/src/composables/useTabHash.ts | 85 ++++++++++++++++ webui/src/lib/format.spec.ts | 26 +++++ webui/src/lib/format.ts | 19 ++++ webui/src/lib/provider-rate.spec.ts | 108 +++++++++++++++++++++ webui/src/lib/provider-rate.ts | 92 ++++++++++++++++++ webui/src/types/api.ts | 34 +++++++ 10 files changed, 512 insertions(+), 6 deletions(-) create mode 100644 webui/src/components/ProviderRateBadge.vue create mode 100644 webui/src/composables/useTabHash.spec.ts create mode 100644 webui/src/composables/useTabHash.ts create mode 100644 webui/src/lib/format.spec.ts create mode 100644 webui/src/lib/provider-rate.spec.ts create mode 100644 webui/src/lib/provider-rate.ts diff --git a/webui/src/App.vue b/webui/src/App.vue index 3153723..8ac058d 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -1,7 +1,7 @@ + + diff --git a/webui/src/components/ProvidersView.vue b/webui/src/components/ProvidersView.vue index 93a45c1..49143bb 100644 --- a/webui/src/components/ProvidersView.vue +++ b/webui/src/components/ProvidersView.vue @@ -9,6 +9,7 @@ import { computed, h, reactive, watch } from 'vue' import DataTable from '@/components/DataTable.vue' import ModelChip from '@/components/ModelChip.vue' +import ProviderRateBadge from '@/components/ProviderRateBadge.vue' import SearchInput from '@/components/SearchInput.vue' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion' import { Badge } from '@/components/ui/badge' @@ -20,10 +21,11 @@ import { CardTitle, } from '@/components/ui/card' import { useSearchQuery } from '@/composables/useSearchQuery' -import { formatAgo, formatTimestamp, routableModelId } from '@/lib/format' +import { formatAgo, formatTimestamp, refreshLabel, routableModelId } from '@/lib/format' +import { isModelDegraded } from '@/lib/provider-rate' import { type ExpandState, clearExpandOverrides, computeExpandedItems, toggleItemExpand } from '@/lib/search-expand' import { useDashboardStore } from '@/stores/dashboard' -import type { AdminAliasView, AdminProviderView } from '@/types/api' +import type { AdminAliasView, AdminModelRateView, AdminProviderView } from '@/types/api' // This component backs the "Providers" tab (App.vue) — a UI-label rename // only. The data it renders still comes from GET /admin/api/overview @@ -136,6 +138,20 @@ function visibleModels(p: AdminProviderView): string[] { return hasQuery.value ? p.models.filter((m) => modelMatches(p.name, m)) : p.models } +/** ZERO_MODEL_RATE is the fallback ProviderRateBadge reads for a model p.modelRates has no entry for — should not happen (admin.go's buildAdminOverview populates one entry per Models id, unconditionally), but a defensive fallback keeps a stale/mismatched client build from throwing rather than just under-reporting. */ +const ZERO_MODEL_RATE: AdminModelRateView = { attemptsDay: 0, failuresDay: 0, attemptsMinute: 0, failuresMinute: 0 } + +/** modelRateFor looks up one model's counters within p.modelRates (Feature A, v0.22), falling back to ZERO_MODEL_RATE. */ +function modelRateFor(p: AdminProviderView, model: string): AdminModelRateView { + return p.modelRates[model] ?? ZERO_MODEL_RATE +} + +/** modelIsDegraded gates the per-model rate badge (spec: "ONLY when that model is degraded") so a healthy or no-traffic model's ModelChip renders with no badge beside it at all. */ +function modelIsDegraded(p: AdminProviderView, model: string): boolean { + const r = modelRateFor(p, model) + return isModelDegraded(r.attemptsDay, r.failuresDay) +} + // --- model aliases (sortable DataTable, operator directive) --- // // The alias id gets the ModelChip copy treatment (an alias name IS the @@ -244,13 +260,19 @@ const aliasEmptyMessage = computed(() => {{ p.name }} {{ p.type }} {{ p.modelCount }} models +