fix(webui): open provider panel from reliability breakers

This commit is contained in:
2026-11-25 12:11:10 +00:00
parent 62817af834
commit 158a96ea55
4 changed files with 58 additions and 15 deletions
+14 -3
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { formatBucketLabel, formatCompactCount, formatContextWindow, formatCostAxis, formatCostDisplay, formatElapsedAgo, formatLimits, formatLatencyMs, formatModelCostHover, formatPercentAxis, formatUntil, refreshDetailLabel, refreshLabel, ZERO_TIME } from './format'
import { formatBucketLabel, formatCompactCount, formatContextWindow, formatCostAxis, formatCostDisplay, formatElapsedAgo, formatLimits, formatLatencyMs, formatModelCostHover, formatPercentAxis, formatPercentValue, formatUntil, refreshDetailLabel, refreshLabel, ZERO_TIME } from './format'
describe('refreshLabel', () => {
it('reads "discovery off" when discovery is disabled, regardless of lastRefresh', () => {
@@ -50,8 +50,8 @@ describe('refreshDetailLabel', () => {
// Feature v0.23: per-model metadata exposure (context window, per-token
// cost). formatContextWindow is table-driven over good/edge cases;
// formatModelCostHover covers the free/priced split ModelChip's
// hover-detail relies on.
// formatModelCostHover covers the free/priced split of the
// hover-detail.
//
// Review fix: binary-K/M (÷1024) applies ONLY when tokens is an exact
// power of two; a decimal, round-thousands count uses decimal-K/M
@@ -172,6 +172,17 @@ describe('formatCompactCount', () => {
// floor-not-round boundary rule like formatCompactCount above — these are
// averages with no discrete threshold a reader could misinterpret as
// crossed.
describe('formatPercentValue', () => {
it.each([
{ n: 0, want: '0%' },
{ n: 99.5, want: '99.5%' },
{ n: 12.3456, want: '12.35%' },
{ n: 100, want: '100%' },
])('formatPercentValue($n) = $want', ({ n, want }) => {
expect(formatPercentValue(n)).toBe(want)
})
})
describe('formatLatencyMs', () => {
it.each([
{ ms: 0, want: '0ms' },
+11 -6
View File
@@ -90,7 +90,7 @@ export function formatShortDate(d: Date): string {
return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })
}
/** formatExactInt renders a raw integer count with thousands separators ("1,234,567") — the precise value CompactNumber.vue and the usage chart's tooltip carry alongside a compact rendering, never lost. */
/** formatExactInt renders a raw integer count with thousands separators ("1,234,567") — the precise value to pair with a compact rendering. */
export function formatExactInt(n: number): string {
return n.toLocaleString('en-US')
}
@@ -106,7 +106,7 @@ export function formatExactInt(n: number): string {
* count of 999,950 must never display as "1,000k", which would imply a
* boundary the raw value has not actually crossed. This is DISPLAY
* only — every caller pairs it with the exact value via a title/
* aria-label (CompactNumber.vue's own doc comment), and no accessor/sort
* aria-label, and no accessor/sort
* key ever calls this; DataTable columns sort on the raw number.
*/
export function formatCompactCount(n: number): string {
@@ -203,18 +203,18 @@ function roundScaled(value: number): string {
return value < 10 ? String(Math.round(value * 10) / 10) : String(Math.round(value))
}
/** formatUsdPerMTok renders a USD-per-million-tokens float as "$0.19" (2 decimals) — the shared building block for both the visible cost chip and ModelChip's hover detail. */
/** formatUsdPerMTok renders a USD-per-million-tokens float as "$0.19" (2 decimals) — the shared building block for both the visible cost chip and the hover detail. */
function formatUsdPerMTok(usd: number): string {
return `$${usd.toFixed(2)}`
}
/**
* formatModelCostHover renders ModelChip's hover-detail cost phrase
* formatModelCostHover renders the hover-detail cost phrase
* (feature v0.23, hover-detail refinement): "in $0.19 / out $0.51 per
* MTok" for a priced model, or "free" when both sides are exactly 0 (a
* KNOWN zero cost, ModelMetaConfig.Free — distinct from the caller never
* passing a cost at all, which ModelChip's own metaDetail computed
* handles by omitting the phrase entirely rather than calling this).
* passing a cost at all, which callers handle by omitting the
* phrase entirely rather than calling this).
*/
export function formatModelCostHover(inputUsd: number, outputUsd: number): string {
if (inputUsd === 0 && outputUsd === 0) return 'free'
@@ -226,6 +226,11 @@ export function formatPercentAxis(rate: number): string {
return `${Math.round(rate * 1000) / 10}%`
}
/** formatPercentValue renders a 0-100 percentage with up to two decimals ("12.5%"). */
export function formatPercentValue(n: number): string {
return `${Number(n.toFixed(2))}%`
}
/** formatModelPriceShort is the table-cell form of formatModelCostHover: "$1.00 / $2.00" (input / output per MTok). */
export function formatModelPriceShort(inputUsd: number, outputUsd: number): string {
if (inputUsd === 0 && outputUsd === 0) return 'free'
+6 -6
View File
@@ -2,9 +2,10 @@
import { Button, Card, CardAction, CardContent, CardHeader, CardTitle, LineChart, NativeSelect, Pagination, SegmentedControl, StatusBadge } from '@perfect-design/ui'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { useEntityLinks } from '@/composables/useEntityLinks'
import { useNow } from '@/composables/useNow'
import { thinLabels } from '@/lib/chart-labels'
import { formatBucketLabel, formatCompactCount, formatUntil } from '@/lib/format'
import { formatBucketLabel, formatCompactCount, formatLatencyMs, formatPercentValue, formatUntil } from '@/lib/format'
import { loadState } from '@/lib/load-state'
import { pageWindow } from '@/lib/paging'
import { sortThenSlice } from '@/lib/table-sort'
@@ -38,6 +39,7 @@ interface BreakerView extends BreakerRow {
const dashboard = useDashboardStore()
const filters = useFiltersStore()
const nav = useNavStore()
const { openEntity } = useEntityLinks()
const reliability = useReliabilityStore()
const { now, start: startClock, stop: stopClock } = useNow()
@@ -103,8 +105,6 @@ const rejectionLines = computed(() => [
{ name: '402 unpriced', data: reliability.unpriced, tone: 'warning' as const },
])
const formatPercent = (n: number): string => `${Number(n.toFixed(2))}%`
const formatMs = (n: number): string => `${Math.round(n).toLocaleString('en-US')} ms`
const seriesState = computed<ViewState>(() => {
if (providers.value.length === 0 && overview.value !== null) return 'empty'
@@ -243,7 +243,7 @@ const windowUsed = computed(() => hourOrDayWindow(filters.window, filters.span))
:labels="bucketLabels"
:series="activityLines"
:height="220"
:value-formatter="formatPercent"
:value-formatter="formatPercentValue"
:label="`Failure, timeout and failover rate as percent of attempts for ${selected} per ${windowUsed.window}`"
/>
</div>
@@ -266,7 +266,7 @@ const windowUsed = computed(() => hourOrDayWindow(filters.window, filters.span))
:labels="perfLabels"
:series="ttfbLines"
:height="220"
:value-formatter="formatMs"
:value-formatter="formatLatencyMs"
:label="`Time to first byte p50 and p95 for ${selected}`"
/>
</div>
@@ -291,7 +291,7 @@ const windowUsed = computed(() => hourOrDayWindow(filters.window, filters.span))
row-key="provider"
label="Provider circuit breakers"
@update:sort="onBreakerSort"
@row-activate="(row: BreakerView) => nav.openPanel('provider', row.provider)"
@row-activate="(row: BreakerView) => openEntity('provider', row.provider)"
>
<template #cell-status="{ value }">
<StatusBadge :status="value as string" :tones="STATE_TONE" size="sm" />