mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin): group catalog models by kind
Add a display-only kinds map to the provider config. Each pathBaseUrls key now appears in the admin catalog as an endpoint row. The Models page splits a provider into one sub-section per kind.
This commit is contained in:
@@ -43,6 +43,41 @@ const filtered = computed<ModelCatalogRow[]>(() => filterModelRows(props.rows, p
|
||||
|
||||
const columns = modelCatalogColumns()
|
||||
|
||||
interface CatalogSection {
|
||||
key: string
|
||||
/** '' for the ungrouped (no-kind) rows. */
|
||||
title: string
|
||||
rows: ModelCatalogRow[]
|
||||
}
|
||||
|
||||
/**
|
||||
* sections splits the filtered rows into one table per (provider, kind): a
|
||||
* provider's plain models first, then one sub-section per kind, sorted.
|
||||
* With no kind set anywhere this is a single untitled section, so an
|
||||
* unconfigured catalog renders exactly as the flat table did.
|
||||
*/
|
||||
const sections = computed<CatalogSection[]>(() => {
|
||||
if (!filtered.value.some((r) => r.kind)) return [{ key: 'all', title: '', rows: filtered.value }]
|
||||
const providers: string[] = []
|
||||
const byKey = new Map<string, CatalogSection>()
|
||||
for (const r of filtered.value) {
|
||||
if (!providers.includes(r.providerName)) providers.push(r.providerName)
|
||||
const key = `${r.providerName}\u0000${r.kind}`
|
||||
let sec = byKey.get(key)
|
||||
if (!sec) {
|
||||
sec = { key, title: r.kind ? `${r.providerName} · ${r.kind}` : r.providerName, rows: [] }
|
||||
byKey.set(key, sec)
|
||||
}
|
||||
sec.rows.push(r)
|
||||
}
|
||||
const kindsOf = (provider: string): string[] =>
|
||||
[...byKey.values()]
|
||||
.filter((sec) => sec.rows[0].providerName === provider)
|
||||
.map((sec) => sec.rows[0].kind)
|
||||
.sort((a, b) => (a === '' ? -1 : b === '' ? 1 : a.localeCompare(b)))
|
||||
return providers.flatMap((p) => kindsOf(p).map((k) => byKey.get(`${p}\u0000${k}`) as CatalogSection))
|
||||
})
|
||||
|
||||
/**
|
||||
* catalogLoadState (lib/load-state.ts, verify-ui-states.md #3 fix) now
|
||||
* reads the REAL `error` prop, not a hardcoded ''. A not-yet-loaded (or
|
||||
@@ -87,7 +122,12 @@ const emptyMessage = computed<string>(() => {
|
||||
<SkeletonTable v-if="catalogLoadState === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="catalogLoadState === 'error'" :message="error ?? ''" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="catalogLoadState === 'empty'" title="No models configured." />
|
||||
<DataTable v-else label="Model catalog" :columns="columns" :data="filtered" :empty-message="emptyMessage" />
|
||||
<template v-else>
|
||||
<section v-for="sec in sections" :key="sec.key" class="flex flex-col gap-2">
|
||||
<h3 v-if="sec.title" class="text-sm font-medium text-muted-foreground">{{ sec.title }}</h3>
|
||||
<DataTable :label="sec.title ? `Model catalog: ${sec.title}` : 'Model catalog'" :columns="columns" :data="sec.rows" :empty-message="emptyMessage" />
|
||||
</section>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -8,6 +8,8 @@ function row(overrides: Partial<ModelCatalogRow> = {}): ModelCatalogRow {
|
||||
id: 'openai/gpt-5',
|
||||
model: 'gpt-5',
|
||||
providerName: 'openai',
|
||||
kind: '',
|
||||
endpoint: false,
|
||||
priceSource: 'builtin',
|
||||
aliases: [],
|
||||
requests: 0,
|
||||
|
||||
@@ -13,6 +13,8 @@ function testRow(overrides: Partial<ModelCatalogRow> = {}): ModelCatalogRow {
|
||||
id: 'openai/gpt-5',
|
||||
model: 'gpt-5',
|
||||
providerName: 'openai',
|
||||
kind: '',
|
||||
endpoint: false,
|
||||
priceSource: 'builtin',
|
||||
aliases: [],
|
||||
requests: 0,
|
||||
|
||||
@@ -32,6 +32,10 @@ export interface ModelCatalogRow {
|
||||
/** The bare upstream model id, without the provider prefix (AdminCatalogModel.model). */
|
||||
model: string
|
||||
providerName: string
|
||||
/** AdminCatalogModel.kind — '' when the model has none. */
|
||||
kind: string
|
||||
/** AdminCatalogModel.endpoint — a pathBaseUrls pseudo-model: no price, no context. */
|
||||
endpoint: boolean
|
||||
contextTokens?: number
|
||||
inputPerMTokUsd?: number
|
||||
outputPerMTokUsd?: number
|
||||
@@ -71,6 +75,8 @@ export function buildModelCatalogRows(
|
||||
id: m.id,
|
||||
model: m.model,
|
||||
providerName: provider.name,
|
||||
kind: m.kind ?? '',
|
||||
endpoint: m.endpoint ?? false,
|
||||
contextTokens: m.contextTokens,
|
||||
inputPerMTokUsd: m.inputPerMTokUsd,
|
||||
outputPerMTokUsd: m.outputPerMTokUsd,
|
||||
@@ -101,6 +107,7 @@ const PRICE_SOURCE_LABEL: Record<Extract<PriceSource, 'override' | 'builtin' | '
|
||||
const FREE_SUFFIX_TITLE = "':free' suffix model — display-only, billing follows the price source"
|
||||
|
||||
function priceCell(row: ModelCatalogRow) {
|
||||
if (row.endpoint) return h('span', { class: 'text-muted-foreground' }, EMPTY_CELL)
|
||||
if (row.priceSource === 'unpriced') {
|
||||
return h(
|
||||
Badge,
|
||||
@@ -136,6 +143,7 @@ function priceCell(row: ModelCatalogRow) {
|
||||
* on.
|
||||
*/
|
||||
function priceSortValue(row: ModelCatalogRow): number {
|
||||
if (row.endpoint) return 0
|
||||
if (row.priceSource === 'unpriced') return -1
|
||||
return row.inputPerMTokUsd ?? 0
|
||||
}
|
||||
|
||||
@@ -698,6 +698,10 @@ export interface AdminCatalogModel {
|
||||
priceSource: PriceSource
|
||||
/** True for a ':free' suffix model (routes_unified.go) — display-only relabeling; billing still follows `priceSource` unchanged. */
|
||||
displayFree?: boolean
|
||||
/** Operator label from the provider's `kinds` map (for example 'reranking'); absent for an ordinary model. */
|
||||
kind?: string
|
||||
/** True for a pseudo-model row built from a `pathBaseUrls` key — not a routable model, never priced. */
|
||||
endpoint?: boolean
|
||||
aliases?: string[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user