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:
@@ -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)))
|
||||
}
|
||||
Reference in New Issue
Block a user