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:
2026-11-28 02:13:22 +00:00
committed by GitHub
parent 7fade3cdee
commit bfdffc2ab0
19 changed files with 493 additions and 103 deletions
+11
View File
@@ -10,12 +10,14 @@ import { useHashState } from '@/composables/useHashState'
import AppLayout from '@/layout/AppLayout.vue'
import type { PageId } from '@/lib/pages'
import { useAuthStore } from '@/stores/auth'
import { useCatalogStore } from '@/stores/catalog'
import { useConfigStore } from '@/stores/config'
import { useDashboardStore } from '@/stores/dashboard'
import { useNavStore } from '@/stores/nav'
import { resetSessionData } from '@/stores/session'
const auth = useAuthStore()
const catalog = useCatalogStore()
const config = useConfigStore()
const dashboard = useDashboardStore()
const nav = useNavStore()
@@ -65,6 +67,15 @@ watch(
},
)
// Every model-id cell marks an alias from the catalog's alias list, so load it once per key.
watch(
() => auth.apiKey,
() => {
if (auth.isAuthenticated) void catalog.ensureLoaded()
},
{ immediate: true },
)
onMounted(() => {
dashboard.startPolling()
})
+39
View File
@@ -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()
})
})
+8
View File
@@ -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
}
+24 -1
View File
@@ -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' }])
})
})
+22
View File
@@ -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 },
]
}
+3 -12
View File
@@ -5,7 +5,7 @@ import { computed, onMounted, reactive, watch } from 'vue'
import { formatCompactCount, formatContextWindow, formatModelCostHover } from '@/lib/format'
import { loadState } from '@/lib/load-state'
import { NO_KIND, groupByProvider, priceStatus, selectModels } from '@/lib/models-view'
import { groupByProvider, modelFilterFields, priceStatus, selectModels } from '@/lib/models-view'
import type { ModelSelection, PriceStatus } from '@/lib/models-view'
import { pageWindow } from '@/lib/paging'
import { resolveSel } from '@/lib/panel-selection'
@@ -30,11 +30,6 @@ const PAGE_SIZE = 12
const ROUTER_BADGES = 2
const FILTER_KEYS = ['provider', 'kind', 'price'] as const
type FilterKey = (typeof FILTER_KEYS)[number]
const PRICE_OPTIONS: Array<{ value: PriceStatus; label: string }> = [
{ value: 'priced', label: 'Priced' },
{ value: 'unpriced', label: 'Unpriced' },
{ value: 'free', label: 'Free' },
]
const HEALTH_TONE = { healthy: 'success', degraded: 'warning', severe: 'danger' } as const
const BREAKER_TONE = { closed: 'success', open: 'danger', 'half-open': 'warning', degraded: 'warning' } as const
@@ -88,12 +83,8 @@ const filtering = computed(() => query.value.trim() !== '' || FILTER_KEYS.some((
const overviewProviders = computed(() => dashboard.overview?.providers ?? [])
const fields = computed<FilterField[]>(() => {
const kinds = [...new Set(models.rows.map((r) => r.kind).filter((k) => k !== ''))].sort()
const providers = [...new Set([...overviewProviders.value.map((p) => p.name), ...models.rows.map((r) => r.providerName)])].sort()
return [
{ id: 'provider', label: 'Provider', type: 'select', operators: ['eq'], options: providers.map((p) => ({ value: p, label: p })) },
{ id: 'kind', label: 'Kind', type: 'select', operators: ['eq'], options: [{ value: NO_KIND, label: 'No kind' }, ...kinds.map((k) => ({ value: k, label: k }))] },
{ id: 'price', label: 'Price', type: 'select', operators: ['eq'], options: PRICE_OPTIONS },
]
const providers = [...overviewProviders.value.map((p) => p.name), ...models.rows.map((r) => r.providerName)]
return modelFilterFields(providers, kinds, nav.params.provider)
})
const filterItems = computed<FilterItem[]>(() =>
FILTER_KEYS.filter((k) => nav.params[k]).map((k) => ({ id: k, field: k, operator: 'eq', value: nav.params[k]! })),
+5
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia'
import { aliasTargetMap } from '@/lib/alias-display'
import { adminFetch, isAuthRejection, messageOf } from '@/lib/api'
import { useAuthStore } from '@/stores/auth'
import type { AdminCatalogModel, AdminCatalogResponse } from '@/types/api'
@@ -58,6 +59,10 @@ export const useCatalogStore = defineStore('catalog', {
}
return map
},
/** aliasTargets maps each configured alias id to the model it points at, so any view listing a requested model id can mark an alias. */
aliasTargets(state): Map<string, string> {
return aliasTargetMap(state.data?.aliases)
},
},
actions: {
/**
+2
View File
@@ -365,6 +365,8 @@ export interface AdminRouterView {
export interface AdminAliasView {
alias: string
target: string
/** Canonical `provider/model` id the target resolves to; absent while it resolves to no known model. */
resolvedTarget?: string
/**
* The alias's own resolved metadata (admin.go: adminAliasView.
* ModelMeta — feature v0.23): INHERITED from its target unless the
+6 -1
View File
@@ -1,15 +1,20 @@
<script setup lang="ts">
import { Badge } from '@perfect-design/ui'
import { computed } from 'vue'
import { splitModelId } from '@/lib/model-id'
import { useCatalogStore } from '@/stores/catalog'
const props = defineProps<{ id: string; bare?: boolean }>()
const parts = computed(() => splitModelId(props.id))
const catalog = useCatalogStore()
const target = computed(() => catalog.aliasTargets.get(props.id) ?? null)
</script>
<template>
<span class="wb-model" :title="id">
<span class="wb-model" :title="target ? `${id} → ${target}` : id">
<span v-if="parts.provider && !bare" class="wb-model-provider">{{ parts.provider }}</span>
<span class="wb-model-name">{{ parts.model }}</span>
<Badge v-if="target" tone="neutral" variant="outline" size="sm" class="wb-model-alias ml-1 min-w-0 truncate font-mono">alias → {{ target }}</Badge>
</span>
</template>