mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
fix(admin): show aliases, guard the provider filter, tolerate failing upstreams (#23)
* fix(admin): attach model aliases to the model their target resolves to The catalog grouped aliases by the raw target string and looked them up by canonical provider/model id. A bare target never matched, so no model card listed its aliases. Each alias now keys on the canonical id that the registry resolves its target to. The alias view gains an additive resolvedTarget field. Model-id cells in the overview, usage and panels now show an alias badge with the target, using the catalog alias list. * fix(webui): omit the provider filter select until providers load * fix(discovery): tolerate failing modelBaseUrls upstreams A modelBaseUrls upstream that fails /v1/models must not fail the provider. Discovery now fails only when baseUrl fails. The explicit models of the failing upstream stay listed, and the other upstreams still merge. The admin overview reports each failed upstream in the additive upstreamErrors field. The registry logs it at most once per 10 minutes per provider. The README states the new semantics. * chore(webui): regenerate admin assets Rebuilt with make admin-ui for the alias badge and the provider filter changes. * style(auth): order authStore fields for fieldalignment golangci-lint's fieldalignment check reported 240 leading pointer bytes on authStore where 232 is optimal. The bool anonymousAnyKey moves next to the mutexes. No behaviour change.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { aliasTargetMap } from '@/lib/alias-display'
|
||||
import { useCatalogStore } from '@/stores/catalog'
|
||||
import type { AdminAliasView, AdminCatalogResponse } from '@/types/api'
|
||||
|
||||
const meta = {} as AdminAliasView['modelMeta']
|
||||
|
||||
describe('aliasTargetMap', () => {
|
||||
it('prefers the resolved canonical target', () => {
|
||||
const m = aliasTargetMap([{ alias: 'model-fast', target: 'deepseek-v4.1-flash-1017', resolvedTarget: 'uni/deepseek-v4.1-flash-1017', modelMeta: meta }])
|
||||
expect(m.get('model-fast')).toBe('uni/deepseek-v4.1-flash-1017')
|
||||
})
|
||||
|
||||
it('falls back to the configured target when it does not resolve', () => {
|
||||
const m = aliasTargetMap([{ alias: 'ghost', target: 'no-such-model', modelMeta: meta }])
|
||||
expect(m.get('ghost')).toBe('no-such-model')
|
||||
})
|
||||
|
||||
it('is empty for no aliases and ignores non-alias ids', () => {
|
||||
expect(aliasTargetMap(undefined).size).toBe(0)
|
||||
expect(aliasTargetMap([]).get('uni/x')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('useCatalogStore.aliasTargets', () => {
|
||||
it('indexes the fetched catalog aliases', () => {
|
||||
setActivePinia(createPinia())
|
||||
const catalog = useCatalogStore()
|
||||
expect(catalog.aliasTargets.size).toBe(0)
|
||||
catalog.data = {
|
||||
providers: [],
|
||||
aliases: [{ alias: 'model-fast', target: 'x', resolvedTarget: 'uni/x', modelMeta: meta }],
|
||||
} as AdminCatalogResponse
|
||||
expect(catalog.aliasTargets.get('model-fast')).toBe('uni/x')
|
||||
expect(catalog.aliasTargets.get('uni/x')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { AdminAliasView } from '@/types/api'
|
||||
|
||||
/** Maps each alias id to the target a reader should see: the canonical `provider/model` when the gateway resolved it, else the configured target. */
|
||||
export function aliasTargetMap(aliases: readonly AdminAliasView[] | undefined): Map<string, string> {
|
||||
const map = new Map<string, string>()
|
||||
for (const a of aliases ?? []) map.set(a.alias, a.resolvedTarget || a.target)
|
||||
return map
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { groupByProvider, priceStatus, selectModels } from '@/lib/models-view'
|
||||
import { groupByProvider, modelFilterFields, priceStatus, selectModels } from '@/lib/models-view'
|
||||
import type { ModelCatalogRow } from '@/lib/model-table-columns'
|
||||
|
||||
function row(id: string, over: Partial<ModelCatalogRow> = {}): ModelCatalogRow {
|
||||
@@ -68,3 +68,26 @@ describe('groupByProvider', () => {
|
||||
expect(g!.rows.map((r) => r.id)).toEqual(['a/c', 'a/a', 'a/b'])
|
||||
})
|
||||
})
|
||||
|
||||
const selectsWithoutOptions = (fields: ReturnType<typeof modelFilterFields>) =>
|
||||
fields.filter((f) => f.type === 'select' && (!f.options || f.options.length === 0))
|
||||
|
||||
describe('modelFilterFields', () => {
|
||||
it('never yields a select with empty options before data loads', () => {
|
||||
const fields = modelFilterFields([], [])
|
||||
expect(selectsWithoutOptions(fields)).toEqual([])
|
||||
expect(fields.map((f) => f.id)).toEqual(['kind', 'price'])
|
||||
})
|
||||
|
||||
it('adds the provider select once providers are known, sorted and deduplicated', () => {
|
||||
const fields = modelFilterFields(['uni', 'a', 'uni'], ['chat'])
|
||||
const provider = fields.find((f) => f.id === 'provider')
|
||||
expect(provider?.options?.map((o) => o.value)).toEqual(['a', 'uni'])
|
||||
})
|
||||
|
||||
it('keeps a provider from the URL selectable before the data arrives', () => {
|
||||
const fields = modelFilterFields([], [], 'uni')
|
||||
expect(selectsWithoutOptions(fields)).toEqual([])
|
||||
expect(fields.find((f) => f.id === 'provider')?.options).toEqual([{ value: 'uni', label: 'uni' }])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { FilterField } from '@perfect-design/ui'
|
||||
|
||||
import { filterModelRows } from '@/lib/model-filter'
|
||||
import type { ModelCatalogRow } from '@/lib/model-table-columns'
|
||||
|
||||
@@ -50,3 +52,23 @@ export function groupByProvider(rows: ModelCatalogRow[]): ProviderGroup[] {
|
||||
for (const g of groups.values()) g.rows.sort(byTraffic)
|
||||
return [...groups.values()]
|
||||
}
|
||||
|
||||
const PRICE_OPTIONS: Array<{ value: PriceStatus; label: string }> = [
|
||||
{ value: 'priced', label: 'Priced' },
|
||||
{ value: 'unpriced', label: 'Unpriced' },
|
||||
{ value: 'free', label: 'Free' },
|
||||
]
|
||||
|
||||
/**
|
||||
* FilterBar throws on a select without options, so the provider select is
|
||||
* omitted until a provider is known; a provider already in the URL counts as known.
|
||||
*/
|
||||
export function modelFilterFields(providers: string[], kinds: string[], activeProvider?: string): FilterField[] {
|
||||
const names = [...new Set([...providers, ...(activeProvider ? [activeProvider] : [])])].sort()
|
||||
const toOptions = (vs: string[]) => vs.map((v) => ({ value: v, label: v }))
|
||||
return [
|
||||
...(names.length > 0 ? [{ id: 'provider', label: 'Provider', type: 'select' as const, operators: ['eq' as const], options: toOptions(names) }] : []),
|
||||
{ id: 'kind', label: 'Kind', type: 'select', operators: ['eq'], options: [{ value: NO_KIND, label: 'No kind' }, ...toOptions(kinds)] },
|
||||
{ id: 'price', label: 'Price', type: 'select', operators: ['eq'], options: PRICE_OPTIONS },
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user