mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(webui): open provider panel from reliability breakers
This commit is contained in:
@@ -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
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user