mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin-ui): hide runaway budget line and link form errors to inputs
The burn-down chart drew the budget line even when it was more than ten times the spend, which flattened the spend curve. The line now hides with a note. Limits, pricing, model metadata and grant forms mark invalid inputs with aria-invalid and aria-describedby.
This commit is contained in:
@@ -5,7 +5,7 @@ import ChartCard from '@/components/ChartCard.vue'
|
||||
import StatItem from '@/components/StatItem.vue'
|
||||
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
|
||||
import type { TimeSeriesDataset } from '@/components/TimeSeriesChart.vue'
|
||||
import { cumulative, runOutDate } from '@/lib/burndown'
|
||||
import { BUDGET_LINE_MAX_RATIO, budgetLineVisible, cumulative, runOutDate } from '@/lib/burndown'
|
||||
import { NOT_ENOUGH_DATA } from '@/lib/forecast'
|
||||
import { formatBucketLabel, formatCostAxis, formatCostDisplay, formatShortDate } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
@@ -53,7 +53,7 @@ const spentMicros = computed<number>(() => cumulativePoints.value.at(-1) ?? 0)
|
||||
const datasets = computed<TimeSeriesDataset[]>(() => [{ label: 'Spent (MTD)', data: cumulativePoints.value, color: '--chart-cost' }])
|
||||
|
||||
const comparisonDatasets = computed<TimeSeriesDataset[]>(() => {
|
||||
if (props.budgetMicros === null) return []
|
||||
if (props.budgetMicros === null || !budgetLineVisible(spentMicros.value, props.budgetMicros)) return []
|
||||
const flat = new Array<number>(cumulativePoints.value.length).fill(props.budgetMicros)
|
||||
return [{ label: 'Budget', data: flat, color: '--destructive' }]
|
||||
})
|
||||
@@ -85,6 +85,9 @@ const willExceed = computed<boolean>(() => props.budgetMicros !== null && spentM
|
||||
</StatItem>
|
||||
</div>
|
||||
<p v-if="budgetMicros === null" class="text-sm text-muted-foreground">No budget configured for this scope.</p>
|
||||
<p v-else-if="comparisonDatasets.length === 0" class="text-sm text-muted-foreground">
|
||||
Budget line hidden: it is more than {{ BUDGET_LINE_MAX_RATIO }}× current spend and would flatten the curve.
|
||||
</p>
|
||||
<TimeSeriesChart
|
||||
:labels="labels"
|
||||
:datasets="datasets"
|
||||
|
||||
@@ -79,7 +79,13 @@ const snippet = computed<string | null>(() => {
|
||||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="grant-providers" class="text-xs font-medium text-muted-foreground">Providers (comma-separated, empty = all)</label>
|
||||
<Input id="grant-providers" v-model="providersRaw" placeholder="anthropic, openai" />
|
||||
<Input
|
||||
id="grant-providers"
|
||||
v-model="providersRaw"
|
||||
placeholder="anthropic, openai"
|
||||
:aria-invalid="grantError ? true : undefined"
|
||||
:aria-describedby="grantError ? 'grant-error' : undefined"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="grant-models" class="text-xs font-medium text-muted-foreground">Models (comma-separated, empty = all)</label>
|
||||
@@ -97,7 +103,7 @@ const snippet = computed<string | null>(() => {
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<Alert v-if="grantError" variant="destructive">
|
||||
<Alert v-if="grantError" id="grant-error" variant="destructive">
|
||||
<AlertDescription>{{ grantError }}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ const raw = reactive<Record<keyof LimitsConfig, string>>({
|
||||
const invalidFields = computed(() =>
|
||||
FIELDS.filter(({ key }) => raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label),
|
||||
)
|
||||
/** fieldInvalid is the per-input twin of invalidFields, so each input can carry aria-invalid. */
|
||||
function fieldInvalid(key: (typeof FIELDS)[number]['key']): boolean {
|
||||
return raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))
|
||||
}
|
||||
const invalidIntegerFields = computed(() =>
|
||||
FIELDS.filter(({ key }) => INTEGER_FIELDS.has(key) && raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label),
|
||||
)
|
||||
@@ -104,11 +108,13 @@ const snippet = computed<string | null>(() => {
|
||||
min="0"
|
||||
:step="INTEGER_FIELDS.has(field.key) ? '1' : 'any'"
|
||||
placeholder="unset"
|
||||
:aria-invalid="fieldInvalid(field.key) || undefined"
|
||||
:aria-describedby="fieldInvalid(field.key) ? 'limits-errors' : undefined"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Alert v-if="invalidFields.length" variant="destructive">
|
||||
<Alert v-if="invalidFields.length" id="limits-errors" variant="destructive">
|
||||
<AlertDescription>
|
||||
<p v-if="invalidIntegerFields.length">Enter a non-negative whole number for: {{ invalidIntegerFields.join(', ') }}.</p>
|
||||
<p v-if="invalidDecimalFields.length">Enter a non-negative number for: {{ invalidDecimalFields.join(', ') }}.</p>
|
||||
|
||||
@@ -46,7 +46,16 @@ const snippet = computed<string | null>(() => {
|
||||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 sm:items-end">
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="modelmeta-context" class="text-xs font-medium text-muted-foreground">Context window (tokens)</label>
|
||||
<Input id="modelmeta-context" v-model="contextRaw" type="number" min="1" step="1" placeholder="131072" />
|
||||
<Input
|
||||
id="modelmeta-context"
|
||||
v-model="contextRaw"
|
||||
type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
placeholder="131072"
|
||||
:aria-invalid="contextEntered && !contextValid ? true : undefined"
|
||||
:aria-describedby="contextEntered && !contextValid ? 'modelmeta-context-error' : undefined"
|
||||
/>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 pb-1.5 text-sm">
|
||||
<input id="modelmeta-free" v-model="free" type="checkbox" class="size-4 rounded border-input" />
|
||||
@@ -54,7 +63,7 @@ const snippet = computed<string | null>(() => {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<Alert v-if="contextEntered && !contextValid" variant="destructive">
|
||||
<Alert v-if="contextEntered && !contextValid" id="modelmeta-context-error" variant="destructive">
|
||||
<AlertDescription>Context window must be a positive whole number of tokens.</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
|
||||
@@ -54,15 +54,33 @@ const snippet = computed<string | null>(() => {
|
||||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="pricing-input" class="text-xs font-medium text-muted-foreground">Input price / MTok (USD)</label>
|
||||
<Input id="pricing-input" v-model="inputRaw" type="number" min="0" step="any" placeholder="0.50" />
|
||||
<Input
|
||||
id="pricing-input"
|
||||
v-model="inputRaw"
|
||||
type="number"
|
||||
min="0"
|
||||
step="any"
|
||||
placeholder="0.50"
|
||||
:aria-invalid="errors.length > 0 && !inputValid ? true : undefined"
|
||||
:aria-describedby="errors.length > 0 && !inputValid ? 'pricing-errors' : undefined"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="pricing-output" class="text-xs font-medium text-muted-foreground">Output price / MTok (USD)</label>
|
||||
<Input id="pricing-output" v-model="outputRaw" type="number" min="0" step="any" placeholder="1.50" />
|
||||
<Input
|
||||
id="pricing-output"
|
||||
v-model="outputRaw"
|
||||
type="number"
|
||||
min="0"
|
||||
step="any"
|
||||
placeholder="1.50"
|
||||
:aria-invalid="errors.length > 0 && !outputValid ? true : undefined"
|
||||
:aria-describedby="errors.length > 0 && !outputValid ? 'pricing-errors' : undefined"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Alert v-if="errors.length" variant="destructive">
|
||||
<Alert v-if="errors.length" id="pricing-errors" variant="destructive">
|
||||
<AlertDescription>
|
||||
<p v-for="(error, index) in errors" :key="index">{{ error }}</p>
|
||||
</AlertDescription>
|
||||
|
||||
Reference in New Issue
Block a user