mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): models page
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
<script setup lang="ts">
|
||||
import { Badge, Button, DescriptionItem, DescriptionList, Sparkline } from '@perfect-design/ui'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
|
||||
import ModelMetaForm from '@/components/forms/ModelMetaForm.vue'
|
||||
import PricingForm from '@/components/forms/PricingForm.vue'
|
||||
import { adminFetch, isAuthRejection, messageOf } from '@/lib/api'
|
||||
import { formatCompactCount, formatContextWindow, formatLatencyMs, formatModelCostHover } from '@/lib/format'
|
||||
import { priceStatus } from '@/lib/models-view'
|
||||
import { formatSel } from '@/lib/panel-selection'
|
||||
import { providerRateStatus, providerSuccessRate } from '@/lib/provider-rate'
|
||||
import { seriesUrl } from '@/lib/range'
|
||||
import { routersByModel } from '@/lib/router-index'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useModelsStore } from '@/stores/models'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import type { AdminSeriesResponse } from '@/types/api'
|
||||
import DetailPanel from '@/widgets/DetailPanel.vue'
|
||||
import PanelSection from '@/widgets/PanelSection.vue'
|
||||
import StateView from '@/widgets/StateView.vue'
|
||||
import type { ViewState } from '@/widgets/StateView.vue'
|
||||
|
||||
const MIN_SPARK_POINTS = 2
|
||||
const SPARK_WIDTH = 440
|
||||
const SPARK_HEIGHT = 40
|
||||
const PRICE_SOURCE_NOTE: Record<string, string> = {
|
||||
override: 'pricing override in config',
|
||||
builtin: 'built-in price table',
|
||||
litellm: 'LiteLLM price table',
|
||||
free: 'configured free (modelMeta.free)',
|
||||
unpriced: 'no pricing rule matched, billed as $0',
|
||||
}
|
||||
type Snippet = 'meta' | 'price' | null
|
||||
|
||||
const props = defineProps<{ id: string }>()
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
|
||||
const filters = useFiltersStore()
|
||||
const models = useModelsStore()
|
||||
const nav = useNavStore()
|
||||
|
||||
const row = computed(() => models.rows.find((r) => r.id === props.id))
|
||||
const routers = computed(() => {
|
||||
const r = row.value
|
||||
if (!r) return []
|
||||
const index = routersByModel(models.routers)
|
||||
return [...new Set([...(r.routers ?? []), ...(index.get(r.id) ?? [])])].sort()
|
||||
})
|
||||
const status = computed(() => (row.value ? priceStatus(row.value) : 'none'))
|
||||
const priced = computed(() => row.value?.inputPerMTokUsd !== undefined && row.value?.outputPerMTokUsd !== undefined)
|
||||
const successRate = computed(() => (row.value ? providerSuccessRate(row.value.attempts, row.value.failures) : null))
|
||||
|
||||
// --- Usage over the range ----------------------------------------------------------
|
||||
|
||||
const points = ref<number[]>([])
|
||||
const seriesLoading = ref(true)
|
||||
const seriesError = ref('')
|
||||
let reqId = 0
|
||||
|
||||
async function loadSeries(): Promise<void> {
|
||||
const id = ++reqId
|
||||
seriesLoading.value = true
|
||||
try {
|
||||
const res = await adminFetch<AdminSeriesResponse>(seriesUrl({ scope: [`model:${props.id}`], metric: 'req', window: filters.window, span: filters.span }))
|
||||
if (id !== reqId) return
|
||||
points.value = res.series.find((s) => s.scope === `model:${props.id}`)?.points ?? []
|
||||
seriesError.value = ''
|
||||
} catch (err) {
|
||||
if (id !== reqId || isAuthRejection(err)) return
|
||||
points.value = []
|
||||
seriesError.value = messageOf(err)
|
||||
} finally {
|
||||
if (id === reqId) seriesLoading.value = false
|
||||
}
|
||||
}
|
||||
const total = computed(() => points.value.reduce((a, v) => a + v, 0))
|
||||
const sparkState = computed<ViewState>(() => {
|
||||
if (seriesLoading.value && points.value.length === 0) return 'loading'
|
||||
if (seriesError.value) return 'error'
|
||||
return points.value.length >= MIN_SPARK_POINTS && total.value > 0 ? 'ready' : 'empty'
|
||||
})
|
||||
|
||||
watch(() => [props.id, filters.range], () => void loadSeries())
|
||||
onMounted(() => void loadSeries())
|
||||
|
||||
// --- Snippets ------------------------------------------------------------------------
|
||||
|
||||
const snippet = ref<Snippet>(null)
|
||||
watch(() => props.id, () => (snippet.value = null))
|
||||
|
||||
const usd = (v: number): string => `$${v.toFixed(2)}`
|
||||
|
||||
function openRouter(name: string): void {
|
||||
nav.goTo('routers', { sel: formatSel('router', name) }, { replace: false })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DetailPanel kind="model" :id="id" :title="id" @close="emit('close')">
|
||||
<div class="flex flex-col divide-y px-1 pb-4" data-testid="model-panel">
|
||||
<div v-if="!row" class="text-muted-foreground py-3 text-sm">This model is no longer in the catalog.</div>
|
||||
<template v-else>
|
||||
<PanelSection title="Meta">
|
||||
<DescriptionList variant="inline" size="sm" density="compact">
|
||||
<DescriptionItem term="Provider">
|
||||
<button type="button" class="hover:underline font-mono" @click="nav.openPanel('provider', row.providerName)">{{ row.providerName }}</button>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Model"><span class="font-mono break-all">{{ row.model }}</span></DescriptionItem>
|
||||
<DescriptionItem term="Kind">{{ row.kind || '—' }}</DescriptionItem>
|
||||
<DescriptionItem v-if="row.endpoint" term="Type">endpoint path, not a routable model</DescriptionItem>
|
||||
<DescriptionItem term="Context window">
|
||||
<span class="font-mono tabular-nums">{{ row.contextTokens !== undefined ? formatContextWindow(row.contextTokens) : '—' }}</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Aliases">
|
||||
<span v-if="row.aliases.length === 0" class="text-muted-foreground">none</span>
|
||||
<span v-else class="flex flex-wrap justify-end gap-1">
|
||||
<Badge v-for="a in row.aliases" :key="a" tone="neutral" variant="outline" size="sm" class="font-mono">{{ a }}</Badge>
|
||||
</span>
|
||||
</DescriptionItem>
|
||||
</DescriptionList>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Price">
|
||||
<DescriptionList variant="inline" size="sm" density="compact">
|
||||
<DescriptionItem term="Source">
|
||||
<span class="flex flex-col items-end text-right">
|
||||
<Badge :tone="status === 'unpriced' ? 'warning' : 'neutral'" variant="outline" size="sm">{{ row.priceSource }}</Badge>
|
||||
<span class="text-muted-foreground text-xs">{{ PRICE_SOURCE_NOTE[row.priceSource] }}</span>
|
||||
</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Input per MTok">
|
||||
<span class="font-mono tabular-nums">{{ priced ? usd(row.inputPerMTokUsd as number) : '—' }}</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Output per MTok">
|
||||
<span class="font-mono tabular-nums">{{ priced ? usd(row.outputPerMTokUsd as number) : '—' }}</span>
|
||||
</DescriptionItem>
|
||||
</DescriptionList>
|
||||
<p v-if="priced" class="text-muted-foreground m-0 text-xs">{{ formatModelCostHover(row.inputPerMTokUsd as number, row.outputPerMTokUsd as number) }}</p>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Usage in range">
|
||||
<DescriptionList variant="inline" size="sm" density="compact">
|
||||
<DescriptionItem term="Requests"><span class="font-mono tabular-nums">{{ formatCompactCount(row.requests) }}</span></DescriptionItem>
|
||||
<DescriptionItem term="Tokens in / out">
|
||||
<span class="font-mono tabular-nums">{{ formatCompactCount(row.tokensIn) }} / {{ formatCompactCount(row.tokensOut) }}</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Latency p50 / p95">
|
||||
<span class="font-mono tabular-nums">{{ row.p50Ms !== undefined ? formatLatencyMs(row.p50Ms) : '—' }} / {{ row.p95Ms !== undefined ? formatLatencyMs(row.p95Ms) : '—' }}</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Success rate">
|
||||
<span class="font-mono tabular-nums">{{ successRate === null ? '—' : `${Math.round(successRate * 1000) / 10}% (${providerRateStatus(successRate)})` }}</span>
|
||||
</DescriptionItem>
|
||||
</DescriptionList>
|
||||
<StateView :state="sparkState" empty-title="No traffic in this range" :error-message="seriesError" :rows="1" @retry="loadSeries()">
|
||||
<Sparkline :data="points" variant="area" :width="SPARK_WIDTH" :height="SPARK_HEIGHT" class="h-10 w-full" label="Requests per bucket over the selected range" />
|
||||
</StateView>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Routers">
|
||||
<p v-if="routers.length === 0" class="text-muted-foreground m-0 text-sm">No smart router targets this model.</p>
|
||||
<ul v-else class="m-0 flex list-none flex-col p-0" aria-label="Routers using this model">
|
||||
<li v-for="r in routers" :key="r" class="flex h-8 items-center">
|
||||
<button type="button" class="hover:bg-accent w-full truncate rounded px-2 text-left font-mono text-sm" @click="openRouter(r)">{{ r }}</button>
|
||||
</li>
|
||||
</ul>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Change model settings">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="sm" :aria-expanded="snippet === 'meta'" @click="snippet = snippet === 'meta' ? null : 'meta'">
|
||||
{{ snippet === 'meta' ? 'Hide metadata snippet' : 'Generate metadata snippet' }}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" :aria-expanded="snippet === 'price'" @click="snippet = snippet === 'price' ? null : 'price'">
|
||||
{{ snippet === 'price' ? 'Hide price snippet' : 'Generate price override snippet' }}
|
||||
</Button>
|
||||
</div>
|
||||
<ModelMetaForm v-if="snippet === 'meta'" :preset-model-id="id" />
|
||||
<PricingForm v-else-if="snippet === 'price'" :preset-model-id="id" />
|
||||
</PanelSection>
|
||||
</template>
|
||||
</div>
|
||||
</DetailPanel>
|
||||
</template>
|
||||
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import { Button, DescriptionItem, DescriptionList, StatusBadge } from '@perfect-design/ui'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { copyText } from '@/lib/clipboard'
|
||||
import { formatAgo, formatCompactCount, formatLatencyMs, formatUntil } from '@/lib/format'
|
||||
import { breakerRows, providerRateStatus, providerSuccessRate } from '@/lib/provider-rate'
|
||||
import { useCopyFeedback } from '@/composables/useCopyFeedback'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useModelsStore } from '@/stores/models'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import DetailPanel from '@/widgets/DetailPanel.vue'
|
||||
import PanelSection from '@/widgets/PanelSection.vue'
|
||||
|
||||
const MODEL_ROWS = 12
|
||||
const STATE_TONE = { closed: 'success', open: 'danger', 'half-open': 'warning', degraded: 'warning' } as const
|
||||
|
||||
const props = defineProps<{ id: string }>()
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
|
||||
const dashboard = useDashboardStore()
|
||||
const models = useModelsStore()
|
||||
const nav = useNavStore()
|
||||
const copy = useCopyFeedback()
|
||||
const urlEl = ref<HTMLElement | null>(null)
|
||||
|
||||
const provider = computed(() => dashboard.overview?.providers.find((p) => p.name === props.id))
|
||||
const breaker = computed(() => breakerRows(dashboard.overview).find((b) => b.provider === props.id))
|
||||
const status = computed(() => (breaker.value?.degraded ? 'degraded' : (breaker.value?.state ?? 'closed')))
|
||||
const until = computed(() => formatUntil(breaker.value?.openUntil))
|
||||
|
||||
const lastDiscovery = computed(() => formatAgo(provider.value?.lastRefresh).trim().slice(1, -1) || '—')
|
||||
const perf = computed(() => models.providerPerf.find((r) => r.id === props.id))
|
||||
const successRate = computed(() => providerSuccessRate(provider.value?.attemptsDay ?? 0, provider.value?.failuresDay ?? 0))
|
||||
|
||||
const providerModels = computed(() =>
|
||||
models.rows.filter((r) => r.providerName === props.id).sort((a, b) => b.requests - a.requests || a.id.localeCompare(b.id)),
|
||||
)
|
||||
const shownModels = computed(() => providerModels.value.slice(0, MODEL_ROWS))
|
||||
const hiddenModels = computed(() => providerModels.value.length - shownModels.value.length)
|
||||
|
||||
async function copyUrl(): Promise<void> {
|
||||
copy.set(await copyText(provider.value?.baseUrl ?? '', urlEl.value ?? undefined))
|
||||
}
|
||||
const COPY_LABEL = { idle: 'Copy', copied: 'Copied', selected: 'Selected', failed: 'Copy failed' } as const
|
||||
|
||||
function showAll(): void {
|
||||
nav.goTo('models', { provider: props.id })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DetailPanel kind="provider" :id="id" :title="id" @close="emit('close')">
|
||||
<div class="flex flex-col divide-y px-1 pb-4" data-testid="provider-panel">
|
||||
<div v-if="!provider" class="text-muted-foreground py-3 text-sm">This provider is not configured.</div>
|
||||
<template v-else>
|
||||
<PanelSection title="Health">
|
||||
<DescriptionList variant="inline" size="sm" density="compact">
|
||||
<DescriptionItem term="Breaker">
|
||||
<StatusBadge :status="status" :tones="STATE_TONE" size="sm" />
|
||||
</DescriptionItem>
|
||||
<DescriptionItem v-if="until" term="Next probe"><span class="font-mono tabular-nums">{{ until }}</span></DescriptionItem>
|
||||
<DescriptionItem term="Success today">
|
||||
<span class="font-mono tabular-nums">
|
||||
{{ successRate === null ? 'no traffic' : `${Math.round(successRate * 1000) / 10}% (${providerRateStatus(successRate)})` }}
|
||||
</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Attempts / failures">
|
||||
<span class="font-mono tabular-nums">{{ formatCompactCount(provider.attemptsDay) }} / {{ formatCompactCount(provider.failuresDay) }}</span>
|
||||
</DescriptionItem>
|
||||
<DescriptionItem term="Last discovery">{{ provider.discoveryEnabled ? lastDiscovery : 'discovery off' }}</DescriptionItem>
|
||||
</DescriptionList>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Last error">
|
||||
<p v-if="provider.lastErr" class="text-destructive m-0 text-sm break-words whitespace-pre-wrap" data-testid="provider-last-err">{{ provider.lastErr }}</p>
|
||||
<p v-else class="text-muted-foreground m-0 text-sm">No error recorded.</p>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Latency (time to first byte)">
|
||||
<DescriptionList v-if="perf?.ttfbP50Ms !== undefined || perf?.ttfbP95Ms !== undefined" variant="inline" size="sm" density="compact">
|
||||
<DescriptionItem term="p50"><span class="font-mono tabular-nums">{{ perf?.ttfbP50Ms !== undefined ? formatLatencyMs(perf.ttfbP50Ms) : '—' }}</span></DescriptionItem>
|
||||
<DescriptionItem term="p95"><span class="font-mono tabular-nums">{{ perf?.ttfbP95Ms !== undefined ? formatLatencyMs(perf.ttfbP95Ms) : '—' }}</span></DescriptionItem>
|
||||
</DescriptionList>
|
||||
<p v-else-if="!models.latencyEnabled" class="text-muted-foreground m-0 text-sm">Latency stats are off. Enable admin.stats.latency to record them.</p>
|
||||
<p v-else class="text-muted-foreground m-0 text-sm">No latency samples for this provider in the range.</p>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Models">
|
||||
<p v-if="providerModels.length === 0" class="text-muted-foreground m-0 text-sm">No models listed for this provider.</p>
|
||||
<template v-else>
|
||||
<ul class="m-0 flex list-none flex-col p-0" aria-label="Provider models">
|
||||
<li v-for="m in shownModels" :key="m.id">
|
||||
<button type="button" class="hover:bg-accent flex h-8 w-full items-center justify-between gap-3 rounded px-2 text-left text-sm" :title="m.id" @click="nav.openPanel('model', m.id)">
|
||||
<span class="min-w-0 truncate">{{ m.model }}</span>
|
||||
<span class="shrink-0 font-mono text-xs tabular-nums">{{ formatCompactCount(m.requests) }} req</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="hiddenModels > 0">
|
||||
<Button variant="outline" size="sm" @click="showAll">Show all {{ providerModels.length.toLocaleString('en-US') }} in the table</Button>
|
||||
</div>
|
||||
</template>
|
||||
</PanelSection>
|
||||
|
||||
<PanelSection title="Base URL">
|
||||
<div class="flex items-center gap-2">
|
||||
<code ref="urlEl" class="bg-muted min-w-0 flex-1 rounded px-2 py-1 font-mono text-xs break-all">{{ provider.baseUrl }}</code>
|
||||
<Button variant="outline" size="sm" class="shrink-0" :aria-label="`Copy base URL of ${id}`" @click="copyUrl">{{ COPY_LABEL[copy.state.value] }}</Button>
|
||||
</div>
|
||||
</PanelSection>
|
||||
</template>
|
||||
</div>
|
||||
</DetailPanel>
|
||||
</template>
|
||||
Reference in New Issue
Block a user