mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(admin): show kinds and endpoints in the providers panel
The provider accordion reads the overview response, not the catalog, so the earlier change never reached it. Add kinds and endpoints to the overview provider view and group the accordion rows by kind. Endpoint ids now read gx10/v1/decide, without a doubled slash.
This commit is contained in:
@@ -1647,7 +1647,7 @@ providers:
|
||||
`modelBaseUrls` read the body for this purpose.
|
||||
- **Discovery** polls `baseUrl` only. `modelBaseUrls` ids are static.
|
||||
- **Admin catalog**: each `pathBaseUrls` key appears as a pseudo-model row
|
||||
(`gx10//v1/decide`). It is display only and never routable as a model.
|
||||
(`gx10/v1/decide`). It is display only and never routable as a model.
|
||||
`kinds` labels a model id or a path key. The Models page then groups the
|
||||
provider's rows into one sub-section per kind. Without `kinds`, the table
|
||||
stays flat.
|
||||
|
||||
@@ -411,6 +411,12 @@ type adminProviderView struct {
|
||||
// "[]", not omitted, so the dashboard can tell "no models yet" apart
|
||||
// from a field a stale client build does not know how to read.
|
||||
Models []string `json:"models"`
|
||||
// Kinds is the provider's configured display labels (ProviderConfig.
|
||||
// Kinds), keyed by model id or endpoint path. Omitted when none are set.
|
||||
Kinds map[string]string `json:"kinds,omitempty"`
|
||||
// Endpoints is the sorted pathBaseUrls keys: native passthrough paths
|
||||
// shown beside Models as display-only rows, never routable as models.
|
||||
Endpoints []string `json:"endpoints,omitempty"`
|
||||
// AttemptsDay/FailuresDay/AttemptsMinute/FailuresMinute are this
|
||||
// provider's current-window upstream-attempt counters (Feature A,
|
||||
// v0.22 — see limiter.recordProviderAttempt, limits.go): every
|
||||
@@ -812,7 +818,15 @@ func (g *Gateway) buildAdminOverview() adminOverviewResponse {
|
||||
}
|
||||
modelMeta[model] = buildAdminModelMetaView(g.registry.resolveMetaFor(s.name, model))
|
||||
}
|
||||
var kinds map[string]string
|
||||
var endpoints []string
|
||||
if pc := g.cfg.Providers[s.name]; pc != nil {
|
||||
kinds = pc.Kinds
|
||||
endpoints = sortedKeys(pc.PathBaseURLs)
|
||||
}
|
||||
providers[i] = adminProviderView{
|
||||
Kinds: kinds,
|
||||
Endpoints: endpoints,
|
||||
Name: s.name,
|
||||
Type: s.typeName,
|
||||
BaseURL: sanitizeBaseURL(s.baseURL),
|
||||
|
||||
+30
-30
File diff suppressed because one or more lines are too long
+15
-7
@@ -154,14 +154,9 @@ func (g *Gateway) buildAdminCatalog() adminCatalogResponse {
|
||||
Kind: kinds[model],
|
||||
}
|
||||
}
|
||||
paths := make([]string, 0, len(pathBases))
|
||||
for path := range pathBases {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
for _, path := range paths {
|
||||
for _, path := range sortedKeys(pathBases) {
|
||||
models = append(models, adminCatalogModel{
|
||||
ID: providerModelScopeID(s.name, path),
|
||||
ID: s.name + path, // path starts with "/", so no extra separator
|
||||
Model: path,
|
||||
Kind: kinds[path],
|
||||
PriceSource: priceSourceUnpriced,
|
||||
@@ -182,6 +177,19 @@ func (g *Gateway) buildAdminCatalog() adminCatalogResponse {
|
||||
return adminCatalogResponse{Providers: providers, Aliases: g.buildAdminAliasViews()}
|
||||
}
|
||||
|
||||
// sortedKeys returns m's keys in ascending order, nil for an empty map.
|
||||
func sortedKeys(m map[string]string) []string {
|
||||
if len(m) == 0 {
|
||||
return nil
|
||||
}
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
// serveAdminCatalog writes buildAdminCatalog's result as JSON.
|
||||
func (g *Gateway) serveAdminCatalog(w http.ResponseWriter) {
|
||||
setAdminJSONHeaders(w)
|
||||
|
||||
+32
-2
@@ -375,8 +375,8 @@ func TestAdminCatalog_KindsAndEndpointRows(t *testing.T) {
|
||||
}{
|
||||
{"zeta/z-model", "", false},
|
||||
{"zeta/bge-reranker", "reranking", false},
|
||||
{"zeta//v1/decide", "decision", true},
|
||||
{"zeta//v1/other", "", true},
|
||||
{"zeta/v1/decide", "decision", true},
|
||||
{"zeta/v1/other", "", true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
m, ok := byID[c.id]
|
||||
@@ -399,3 +399,33 @@ func TestKindsValidation(t *testing.T) {
|
||||
t.Fatal("empty kind accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminOverview_KindsAndEndpoints(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := newAdminTestConfig()
|
||||
cfg.Providers["zeta"].PathBaseURLs = map[string]string{"/v1/decide": "http://thx.invalid"}
|
||||
cfg.Providers["zeta"].Kinds = map[string]string{"/v1/decide": "decision"}
|
||||
h, _ := newAdminGatewayHandle(t, cfg)
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, adminRequest(http.MethodGet, adminOverviewPath, "sk-admin1"))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var got adminOverviewResponse
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
for _, p := range got.Providers {
|
||||
switch p.Name {
|
||||
case "zeta":
|
||||
if len(p.Endpoints) != 1 || p.Endpoints[0] != "/v1/decide" || p.Kinds["/v1/decide"] != "decision" {
|
||||
t.Errorf("zeta endpoints=%v kinds=%v", p.Endpoints, p.Kinds)
|
||||
}
|
||||
default:
|
||||
if len(p.Endpoints) != 0 || len(p.Kinds) != 0 {
|
||||
t.Errorf("%s carries endpoints/kinds without config", p.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import DetailField from '@/components/DetailField.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import EntityLink from '@/components/EntityLink.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import { providerSections } from '@/lib/provider-sections'
|
||||
import type { ProviderSection } from '@/lib/provider-sections'
|
||||
import ModelChip from '@/components/ModelChip.vue'
|
||||
import ProviderRateBadge from '@/components/ProviderRateBadge.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
@@ -146,6 +148,14 @@ function visibleModels(p: AdminProviderView): string[] {
|
||||
return hasQuery.value ? p.models.filter((m) => modelMatches(p.name, m)) : p.models
|
||||
}
|
||||
|
||||
function visibleSections(p: AdminProviderView): ProviderSection[] {
|
||||
const sections = providerSections({ models: visibleModels(p), kinds: p.kinds, endpoints: p.endpoints })
|
||||
if (!hasQuery.value) return sections.filter((s) => s.models.length > 0 || s.endpoints.length > 0)
|
||||
return sections
|
||||
.map((s) => ({ ...s, endpoints: s.endpoints.filter((e) => modelMatches(p.name, e)) }))
|
||||
.filter((s) => s.models.length > 0 || s.endpoints.length > 0)
|
||||
}
|
||||
|
||||
const ZERO_MODEL_RATE: AdminModelRateView = { attemptsDay: 0, failuresDay: 0 }
|
||||
|
||||
function modelRateFor(p: AdminProviderView, model: string): AdminModelRateView {
|
||||
@@ -494,28 +504,41 @@ const aliasEmptyMessage = computed(() =>
|
||||
</DetailField>
|
||||
<DetailField v-if="p.lastErr" label="Last error" class="text-destructive">{{ p.lastErr }}</DetailField>
|
||||
</dl>
|
||||
<div v-if="visibleModels(p).length" class="flex flex-wrap gap-1.5">
|
||||
<span v-for="m in visibleModels(p)" :key="m" class="inline-flex min-w-0 max-w-full items-center gap-1">
|
||||
<ModelChip
|
||||
:id="routableModelId(p.name, m)"
|
||||
:context-tokens="modelMetaFor(p, m).contextTokens"
|
||||
:input-per-m-tok-usd="modelMetaFor(p, m).inputPerMTokUsd"
|
||||
:output-per-m-tok-usd="modelMetaFor(p, m).outputPerMTokUsd"
|
||||
/>
|
||||
<EntityLink :label="routableModelId(p.name, m)" kind="model" :id="routableModelId(p.name, m)" class="min-w-0" label-class="truncate" />
|
||||
<span
|
||||
v-if="modelMetaFor(p, m).contextTokens !== undefined"
|
||||
title="context window"
|
||||
class="text-xs text-muted-foreground tabular-nums"
|
||||
>
|
||||
{{ formatContextWindow(modelMetaFor(p, m).contextTokens as number) }}
|
||||
</span>
|
||||
<ProviderRateBadge
|
||||
v-if="modelIsDegraded(p, m)"
|
||||
:attempts-day="modelRateFor(p, m).attemptsDay"
|
||||
:failures-day="modelRateFor(p, m).failuresDay"
|
||||
/>
|
||||
</span>
|
||||
<div v-if="visibleSections(p).length" class="flex flex-col gap-3">
|
||||
<section v-for="sec in visibleSections(p)" :key="sec.title" class="flex flex-col gap-1.5">
|
||||
<h4 v-if="sec.title" class="text-xs font-medium uppercase tracking-wide text-muted-foreground">{{ sec.title }}</h4>
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
<span v-for="m in sec.models" :key="m" class="inline-flex min-w-0 max-w-full items-center gap-1">
|
||||
<ModelChip
|
||||
:id="routableModelId(p.name, m)"
|
||||
:context-tokens="modelMetaFor(p, m).contextTokens"
|
||||
:input-per-m-tok-usd="modelMetaFor(p, m).inputPerMTokUsd"
|
||||
:output-per-m-tok-usd="modelMetaFor(p, m).outputPerMTokUsd"
|
||||
/>
|
||||
<EntityLink :label="routableModelId(p.name, m)" kind="model" :id="routableModelId(p.name, m)" class="min-w-0" label-class="truncate" />
|
||||
<span
|
||||
v-if="modelMetaFor(p, m).contextTokens !== undefined"
|
||||
title="context window"
|
||||
class="text-xs text-muted-foreground tabular-nums"
|
||||
>
|
||||
{{ formatContextWindow(modelMetaFor(p, m).contextTokens as number) }}
|
||||
</span>
|
||||
<ProviderRateBadge
|
||||
v-if="modelIsDegraded(p, m)"
|
||||
:attempts-day="modelRateFor(p, m).attemptsDay"
|
||||
:failures-day="modelRateFor(p, m).failuresDay"
|
||||
/>
|
||||
</span>
|
||||
<code
|
||||
v-for="e in sec.endpoints"
|
||||
:key="e"
|
||||
title="native passthrough path (not a routable model)"
|
||||
class="rounded bg-muted px-1.5 py-0.5 text-xs"
|
||||
>
|
||||
{{ p.name }}{{ e }}
|
||||
</code>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<p v-else class="text-sm text-muted-foreground">no models known yet</p>
|
||||
</AccordionContent>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { providerSections } from '@/lib/provider-sections'
|
||||
|
||||
describe('providerSections', () => {
|
||||
it('returns one untitled section when no kinds or endpoints are set', () => {
|
||||
expect(providerSections({ models: ['a', 'b'] })).toEqual([{ title: '', models: ['a', 'b'], endpoints: [] }])
|
||||
})
|
||||
|
||||
it('groups models and endpoints by kind, plain models first', () => {
|
||||
const got = providerSections({
|
||||
models: ['chat', 'rerank', 'embed'],
|
||||
kinds: { rerank: 'reranking', embed: 'embedding', '/v1/decide': 'decision' },
|
||||
endpoints: ['/v1/decide'],
|
||||
})
|
||||
expect(got).toEqual([
|
||||
{ title: '', models: ['chat'], endpoints: [] },
|
||||
{ title: 'decision', models: [], endpoints: ['/v1/decide'] },
|
||||
{ title: 'embedding', models: ['embed'], endpoints: [] },
|
||||
{ title: 'reranking', models: ['rerank'], endpoints: [] },
|
||||
])
|
||||
})
|
||||
|
||||
it('files an endpoint without a kind under "endpoints"', () => {
|
||||
const got = providerSections({ models: ['chat'], endpoints: ['/v1/other'] })
|
||||
expect(got).toEqual([
|
||||
{ title: '', models: ['chat'], endpoints: [] },
|
||||
{ title: 'endpoints', models: [], endpoints: ['/v1/other'] },
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
export interface ProviderSection {
|
||||
/** Sub-section heading; '' for the untitled plain-model section. */
|
||||
title: string
|
||||
models: string[]
|
||||
endpoints: string[]
|
||||
}
|
||||
|
||||
export interface ProviderSectionInput {
|
||||
models: string[]
|
||||
kinds?: Record<string, string>
|
||||
endpoints?: string[]
|
||||
}
|
||||
|
||||
/** Heading for an endpoint with no configured kind. */
|
||||
export const ENDPOINT_KIND = 'endpoints'
|
||||
|
||||
/**
|
||||
* providerSections splits one provider's rows into sub-sections by kind:
|
||||
* the plain (no-kind) models first, then one section per kind, sorted.
|
||||
* A provider with no kinds and no endpoints yields one untitled section,
|
||||
* so an unconfigured provider renders exactly as the flat list did.
|
||||
*/
|
||||
export function providerSections(p: ProviderSectionInput): ProviderSection[] {
|
||||
const kinds = p.kinds ?? {}
|
||||
const endpoints = p.endpoints ?? []
|
||||
if (endpoints.length === 0 && Object.keys(kinds).length === 0) return [{ title: '', models: p.models, endpoints: [] }]
|
||||
|
||||
const byTitle = new Map<string, ProviderSection>()
|
||||
const section = (title: string): ProviderSection => {
|
||||
let s = byTitle.get(title)
|
||||
if (!s) {
|
||||
s = { title, models: [], endpoints: [] }
|
||||
byTitle.set(title, s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
for (const m of p.models) section(kinds[m] ?? '').models.push(m)
|
||||
for (const e of endpoints) section(kinds[e] ?? ENDPOINT_KIND).endpoints.push(e)
|
||||
return [...byTitle.values()].sort((a, b) => (a.title === '' ? -1 : b.title === '' ? 1 : a.title.localeCompare(b.title)))
|
||||
}
|
||||
@@ -89,6 +89,10 @@ export interface AdminProviderView {
|
||||
lastErr?: string
|
||||
/** Sorted explicit∪discovered model ids (admin.go: adminProviderView.Models) — always an array, never omitted, even when empty. */
|
||||
models: string[]
|
||||
/** Display labels from the provider's `kinds` config, keyed by model id or endpoint path (admin.go: adminProviderView.Kinds). */
|
||||
kinds?: Record<string, string>
|
||||
/** pathBaseUrls keys (admin.go: adminProviderView.Endpoints) — display-only rows, not routable models. */
|
||||
endpoints?: string[]
|
||||
modelCount: number
|
||||
/**
|
||||
* Resolved metadata (context window, per-token cost — feature v0.23)
|
||||
|
||||
Reference in New Issue
Block a user