mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): redesign the admin dashboard around admin tasks
A sidebar replaces the flat tabs with seven pages, and one filter bar sets the time range, comparison period and scope for all of them. - Home: spend against budget, forecast, request rate, error rate, open breakers, top users and models, recent events and warnings. - Spend: spend over time with comparison, budget burn-down, an attribution drill-down from group to user to model, pricing health and cost avoided by free models. - Consumers: a directory with last seen and limit bars, an access matrix, and a detail page per user. - Models: the catalog with billing prices, fleet latency and error rates, and provider health. - Reliability: error, timeout, failover, 429 and 402 trends, events, and latency per provider. - Config: the redacted config and a change helper that emits YAML or users.json snippets to paste into git. - MCP & Agents: callers per target. Page state lives in the URL hash, and old tab links map to the new pages. The replaced views are removed. admin_assets_gen.go is regenerated. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { buildAccessMatrix, providerAccessCell, targetAccessCell } from './access-matrix'
|
||||
import type { AdminConsumerGroup, AdminTargetView } from '@/types/api'
|
||||
|
||||
function group(overrides: Partial<AdminConsumerGroup> = {}): AdminConsumerGroup {
|
||||
return {
|
||||
name: 'friends',
|
||||
allowedProviders: [],
|
||||
modelAccess: {},
|
||||
memberCount: 3,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function target(overrides: Partial<AdminTargetView> = {}): AdminTargetView {
|
||||
return {
|
||||
name: 'fetch',
|
||||
url: 'http://mcp-fetch/mcp',
|
||||
counters: { requestsPerMinute: 0, requestsPerDay: 0, requestsPerMonth: 0 },
|
||||
health: { state: 'unknown', consecutiveFailures: 0 },
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('providerAccessCell', () => {
|
||||
it('not allowed when the provider is absent from allowedProviders', () => {
|
||||
const g = group({ allowedProviders: ['minimax'] })
|
||||
expect(providerAccessCell(g, 'uni')).toEqual({ allowed: false })
|
||||
})
|
||||
|
||||
it('allowed with a "n/m models" detail when modelAccess has an entry', () => {
|
||||
const g = group({ allowedProviders: ['minimax'], modelAccess: { minimax: { allowed: 2, total: 5 } } })
|
||||
expect(providerAccessCell(g, 'minimax')).toEqual({ allowed: true, detail: '2/5 models' })
|
||||
})
|
||||
|
||||
it('allowed with no detail when modelAccess has no entry for this provider', () => {
|
||||
const g = group({ allowedProviders: ['minimax'], modelAccess: {} })
|
||||
expect(providerAccessCell(g, 'minimax')).toEqual({ allowed: true, detail: undefined })
|
||||
})
|
||||
|
||||
// P3 item 18: allowed but 0 of the provider's models are reachable
|
||||
// (a `models` glob matching none of it) must NOT render identically to
|
||||
// an ordinary, genuinely-unrestricted allowed cell.
|
||||
it('sets zero: true when the provider is allowed but 0 of its models are reachable', () => {
|
||||
const g = group({ allowedProviders: ['minimax'], modelAccess: { minimax: { allowed: 0, total: 5 } } })
|
||||
expect(providerAccessCell(g, 'minimax')).toEqual({ allowed: true, detail: '0/5 models', zero: true })
|
||||
})
|
||||
|
||||
it('does NOT set zero when the provider itself has 0 total models (unrelated to the grant)', () => {
|
||||
const g = group({ allowedProviders: ['minimax'], modelAccess: { minimax: { allowed: 0, total: 0 } } })
|
||||
expect(providerAccessCell(g, 'minimax')).toEqual({ allowed: true, detail: '0/0 models' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('targetAccessCell', () => {
|
||||
it('allowed for every group when access is undefined (unrestricted)', () => {
|
||||
expect(targetAccessCell(group({ name: 'friends' }), target({ access: undefined }))).toEqual({ allowed: true })
|
||||
})
|
||||
|
||||
it('allowed for every group when access is null (unrestricted)', () => {
|
||||
expect(targetAccessCell(group({ name: 'friends' }), target({ access: null }))).toEqual({ allowed: true })
|
||||
})
|
||||
|
||||
it('not allowed for any group when access is an empty array', () => {
|
||||
expect(targetAccessCell(group({ name: 'friends' }), target({ access: [] }))).toEqual({ allowed: false })
|
||||
})
|
||||
|
||||
it('allowed only for a named group', () => {
|
||||
expect(targetAccessCell(group({ name: 'friends' }), target({ access: ['friends'] }))).toEqual({ allowed: true })
|
||||
expect(targetAccessCell(group({ name: 'home' }), target({ access: ['friends'] }))).toEqual({ allowed: false })
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildAccessMatrix', () => {
|
||||
it('builds one row per group, keyed by column name', () => {
|
||||
const groups = [
|
||||
group({ name: 'home', allowedProviders: ['anthropic', 'openai'], modelAccess: { anthropic: { allowed: 5, total: 5 } } }),
|
||||
group({ name: 'friends', allowedProviders: ['minimax'] }),
|
||||
]
|
||||
const mcp = [target({ name: 'fetch', access: undefined }), target({ name: 'weather', access: ['home'] })]
|
||||
const agents = [target({ name: 'agentkit', access: [] })]
|
||||
const rows = buildAccessMatrix(groups, ['anthropic', 'openai', 'minimax'], mcp, agents)
|
||||
|
||||
expect(rows).toHaveLength(2)
|
||||
expect(rows[0].group).toBe('home')
|
||||
expect(rows[0].providers.anthropic).toEqual({ allowed: true, detail: '5/5 models' })
|
||||
expect(rows[0].providers.openai).toEqual({ allowed: true, detail: undefined })
|
||||
expect(rows[0].providers.minimax).toEqual({ allowed: false })
|
||||
expect(rows[0].mcpServers.fetch).toEqual({ allowed: true })
|
||||
expect(rows[0].mcpServers.weather).toEqual({ allowed: true })
|
||||
expect(rows[0].agents.agentkit).toEqual({ allowed: false })
|
||||
|
||||
expect(rows[1].group).toBe('friends')
|
||||
expect(rows[1].mcpServers.weather).toEqual({ allowed: false })
|
||||
})
|
||||
|
||||
it('returns an empty array for no groups', () => {
|
||||
expect(buildAccessMatrix([], ['anthropic'], [], [])).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user