From 0da9479e08c9b625008342a9488bdb20ccbe16ee Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sat, 28 Nov 2026 01:54:26 +0000 Subject: [PATCH] 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. --- admin.go | 11 +++++-- admin_catalog.go | 18 ++++++----- admin_catalog_test.go | 49 +++++++++++++++++++++++++++++ admin_test.go | 4 +-- registry.go | 23 ++++++++++++++ webui/src/App.vue | 11 +++++++ webui/src/lib/alias-display.spec.ts | 39 +++++++++++++++++++++++ webui/src/lib/alias-display.ts | 8 +++++ webui/src/stores/catalog.ts | 5 +++ webui/src/types/api.ts | 2 ++ webui/src/widgets/ModelName.vue | 7 ++++- 11 files changed, 163 insertions(+), 14 deletions(-) create mode 100644 webui/src/lib/alias-display.spec.ts create mode 100644 webui/src/lib/alias-display.ts diff --git a/admin.go b/admin.go index 7ac179d..8766676 100644 --- a/admin.go +++ b/admin.go @@ -649,6 +649,9 @@ type adminAliasView struct { ModelMeta adminModelMetaView `json:"modelMeta"` Alias string `json:"alias"` Target string `json:"target"` + // ResolvedTarget is Target's canonical "provider/model" id; omitted + // while Target resolves to no known model. + ResolvedTarget string `json:"resolvedTarget,omitempty"` } // adminOverviewResponse is the full body of GET /admin/api/overview (spec @@ -908,10 +911,12 @@ func (g *Gateway) buildAdminAliasViews() []adminAliasView { aliasSnaps := g.registry.aliasSnapshot() aliases := make([]adminAliasView, len(aliasSnaps)) for i, a := range aliasSnaps { + resolved, _ := g.registry.aliasTargetCanonical(a.Target) aliases[i] = adminAliasView{ - Alias: a.Alias, - Target: a.Target, - ModelMeta: buildAdminModelMetaView(g.registry.resolveMetaForAliasName(a.Alias)), + Alias: a.Alias, + Target: a.Target, + ResolvedTarget: resolved, + ModelMeta: buildAdminModelMetaView(g.registry.resolveMetaForAliasName(a.Alias)), } } return aliases diff --git a/admin_catalog.go b/admin_catalog.go index ccd90e6..c6bcb77 100644 --- a/admin_catalog.go +++ b/admin_catalog.go @@ -97,14 +97,16 @@ type adminCatalogResponse struct { func (g *Gateway) buildAdminCatalog() adminCatalogResponse { snaps := g.registry.snapshot() - // aliasesByTarget groups every configured alias by its configured - // Target string (ModelAliases' own doc comment, llmgateway.go: a - // target names a canonical "provider/model" id), so each model's own - // Aliases field below is a single map lookup rather than a full scan - // of the alias list per model. + // aliasesByTarget groups every alias by the canonical id its target + // resolves to (a target may be bare or provider-prefixed), so each + // model's own Aliases field below is a single map lookup. An alias + // whose target resolves to no known model attaches to no model. + aliasViews := g.buildAdminAliasViews() aliasesByTarget := make(map[string][]string) - for _, a := range g.registry.aliasSnapshot() { - aliasesByTarget[a.Target] = append(aliasesByTarget[a.Target], a.Alias) + for _, a := range aliasViews { + if a.ResolvedTarget != "" { + aliasesByTarget[a.ResolvedTarget] = append(aliasesByTarget[a.ResolvedTarget], a.Alias) + } } routers := g.buildAdminRouterViews() @@ -181,7 +183,7 @@ func (g *Gateway) buildAdminCatalog() adminCatalogResponse { } } - return adminCatalogResponse{Providers: providers, Aliases: g.buildAdminAliasViews(), Routers: routers} + return adminCatalogResponse{Providers: providers, Aliases: aliasViews, Routers: routers} } // sortedKeys returns m's keys in ascending order, nil for an empty map. diff --git a/admin_catalog_test.go b/admin_catalog_test.go index e9951b5..691604d 100644 --- a/admin_catalog_test.go +++ b/admin_catalog_test.go @@ -169,6 +169,55 @@ func TestAdminCatalog_AliasesGroupedByTarget(t *testing.T) { } } +// TestAdminCatalog_AliasTargetForms pins that a bare target, a +// provider-prefixed target and an unresolvable target behave as the +// registry's own resolution does: the first two attach to the canonical +// model, the last attaches nowhere but still lists in catalog.aliases. +func TestAdminCatalog_AliasTargetForms(t *testing.T) { + t.Parallel() + cfg := newAdminTestConfig() + cfg.ModelAliases = map[string]string{ + "fast-bare": "z-model", + "fast-prefixed": "zeta/z-model", + "fast-missing": "no-such-model", + } + h, _ := newAdminGatewayHandle(t, cfg) + + rec := httptest.NewRecorder() + h.ServeHTTP(rec, adminRequest(http.MethodGet, adminCatalogPath, "sk-admin1")) + var got adminCatalogResponse + if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil { + t.Fatalf("decode: %v", err) + } + attached := map[string][]string{} + for _, p := range got.Providers { + for _, m := range p.Models { + attached[m.ID] = m.Aliases + } + } + want := []string{"fast-bare", "fast-prefixed"} + if g := attached["zeta/z-model"]; len(g) != 2 || g[0] != want[0] || g[1] != want[1] { + t.Errorf("zeta/z-model Aliases = %v, want %v", g, want) + } + for id, names := range attached { + for _, n := range names { + if n == "fast-missing" { + t.Errorf("unresolvable entry attached to %s", id) + } + } + } + resolved := map[string]string{} + for _, a := range got.Aliases { + resolved[a.Alias] = a.ResolvedTarget + } + if len(resolved) != 3 { + t.Fatalf("top-level Aliases = %v, want 3 entries", resolved) + } + if resolved["fast-bare"] != "zeta/z-model" || resolved["fast-prefixed"] != "zeta/z-model" || resolved["fast-missing"] != "" { + t.Errorf("ResolvedTarget = %v", resolved) + } +} + // --- GET /admin/api/consumers --- func TestAdminConsumers_GateMatrix(t *testing.T) { diff --git a/admin_test.go b/admin_test.go index 1846935..daa7157 100644 --- a/admin_test.go +++ b/admin_test.go @@ -325,8 +325,8 @@ func TestAdminOverview_SortedShapeAndVersion(t *testing.T) { } wantAliases := []adminAliasView{ - {Alias: "aaliased/y", Target: "alpha/a-model-1"}, - {Alias: "zaliased/x", Target: "z-model"}, + {Alias: "aaliased/y", Target: "alpha/a-model-1", ResolvedTarget: "alpha/a-model-1"}, + {Alias: "zaliased/x", Target: "z-model", ResolvedTarget: "zeta/z-model"}, } if len(got.Aliases) != len(wantAliases) { t.Fatalf("aliases = %+v, want exactly %+v", got.Aliases, wantAliases) diff --git a/registry.go b/registry.go index 092b5f5..f097ff3 100644 --- a/registry.go +++ b/registry.go @@ -2414,6 +2414,29 @@ func (m *modelRegistry) aliasSnapshot() []aliasSnapshotEntry { return out } +// aliasTargetCanonical resolves an alias target to the canonical +// "provider/model" id resolveAliasTarget would pick, ignoring group +// authorization: a provider-prefixed target resolves on that provider, +// a bare one on the sorted-first provider that knows it. ok is false for +// a target no provider knows yet. +func (m *modelRegistry) aliasTargetCanonical(target string) (string, bool) { + providerName, model, prefixed := m.splitConfiguredProvider(target) + if !prefixed { + model = target + for _, name := range m.providerNames { + if m.states[name].hasModel(model) { + providerName = name + break + } + } + } + if providerName == "" || !m.states[providerName].hasModel(model) { + return "", false + } + canonical := providerModelScopeID(providerName, model) + return canonical, true +} + // snapshot returns every configured provider's read-only view, sorted by // name (m.providerNames is already sorted at construction) — the admin // dashboard's provider table (spec §4, v0.2). diff --git a/webui/src/App.vue b/webui/src/App.vue index 483f12e..95fae5d 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -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() }) diff --git a/webui/src/lib/alias-display.spec.ts b/webui/src/lib/alias-display.spec.ts new file mode 100644 index 0000000..94b188e --- /dev/null +++ b/webui/src/lib/alias-display.spec.ts @@ -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() + }) +}) diff --git a/webui/src/lib/alias-display.ts b/webui/src/lib/alias-display.ts new file mode 100644 index 0000000..aa0a712 --- /dev/null +++ b/webui/src/lib/alias-display.ts @@ -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 { + const map = new Map() + for (const a of aliases ?? []) map.set(a.alias, a.resolvedTarget || a.target) + return map +} diff --git a/webui/src/stores/catalog.ts b/webui/src/stores/catalog.ts index 763932c..ac73bc7 100644 --- a/webui/src/stores/catalog.ts +++ b/webui/src/stores/catalog.ts @@ -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 { + return aliasTargetMap(state.data?.aliases) + }, }, actions: { /** diff --git a/webui/src/types/api.ts b/webui/src/types/api.ts index 43a8ca9..dfef88f 100644 --- a/webui/src/types/api.ts +++ b/webui/src/types/api.ts @@ -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 diff --git a/webui/src/widgets/ModelName.vue b/webui/src/widgets/ModelName.vue index bb0f7f8..8211f01 100644 --- a/webui/src/widgets/ModelName.vue +++ b/webui/src/widgets/ModelName.vue @@ -1,15 +1,20 @@