diff --git a/webui/e2e/visual.spec.ts b/webui/e2e/visual.spec.ts index c7eab32..1d96a90 100644 --- a/webui/e2e/visual.spec.ts +++ b/webui/e2e/visual.spec.ts @@ -107,6 +107,27 @@ for (const { page: pageId, kind, scenario = 'live' } of PANEL_PAGES) { } } +// The limits snippet form inside the user panel, opened. +for (const [vp, size] of Object.entries(VIEWPORTS)) { + for (const theme of THEMES) { + test(`users panel snippet limits-hot ${vp} ${theme}`, async ({ page }) => { + await page.setViewportSize(size) + const sel = (await sampleIds(page, 'limits-hot')).user + await visit(page, `#users?sel=${encodeURIComponent(sel)}`, 'limits-hot', theme) + await page.getByRole('button', { name: 'Generate limits snippet' }).click() + await page.getByLabel('Requests/minute').fill('45') + const snippet = page.locator('pre', { hasText: 'requestsPerMinute' }) + await snippet.scrollIntoViewIfNeeded() + await expect(snippet).toBeVisible() + const name = `users-panel-snippet-limits-hot-${vp}-${theme}` + mkdirSync(OUT, { recursive: true }) + await page.screenshot({ path: join(OUT, `${name}.png`), fullPage: true }) + const results = await runChecks(page, []) + for (const r of results) expect.soft(r.ok, `${r.name}: ${r.detail}`).toBe(true) + }) + } +} + // Compare mode: tiles show a delta and the chart adds a dashed previous-period series. for (const theme of THEMES) { test(`overview-cmp live desktop ${theme}`, async ({ page }) => { diff --git a/webui/mock/fixtures/consumers.json b/webui/mock/fixtures/consumers.json index 7dc2b14..7db794b 100644 --- a/webui/mock/fixtures/consumers.json +++ b/webui/mock/fixtures/consumers.json @@ -487,7 +487,7 @@ "total": 0 }, "minimax": { - "allowed": 0, + "allowed": 1, "total": 9 }, "nvidia-nim": { @@ -515,7 +515,7 @@ "total": 0 }, "uni": { - "allowed": 0, + "allowed": 14, "total": 14 }, "xai": { @@ -739,4 +739,4 @@ "memberCount": 1 } ] -} \ No newline at end of file +} diff --git a/webui/mock/scenarios.ts b/webui/mock/scenarios.ts index 0c5192c..36e61ec 100644 --- a/webui/mock/scenarios.ts +++ b/webui/mock/scenarios.ts @@ -31,6 +31,10 @@ const HOT_MINUTE_FRACTION = 0.93 const HOT_DAY_FRACTION = 0.9 const BREAKER_OPEN_MS = 90_000 const HUGE_FACTOR = 3 +/** Each captured user becomes this many in the huge scenario. */ +const HUGE_USER_FACTOR = 20 +const HOT_TOKENS_IN_PER_REQUEST = 1500 +const HOT_TOKENS_OUT_PER_REQUEST = 400 export interface ScenarioContext { now: number @@ -231,7 +235,20 @@ function limitsHot(path: string, body: Obj, ctx: ScenarioContext) { addToGroupAndTotal(body, HOT_GROUP, 'tokensPerMinute', tpm - (u.tokensPerMinute ?? 0)) u.tokensPerMinute = tpm } - if (u.limits.requestsPerDay > 0) u.requestsPerDay = Math.floor(u.limits.requestsPerDay * HOT_DAY_FRACTION) + if (u.limits.requestsPerDay > 0) { + const day = Math.floor(u.limits.requestsPerDay * HOT_DAY_FRACTION) + addToGroupAndTotal(body, HOT_GROUP, 'requestsPerDay', day - u.requestsPerDay) + u.requestsPerDay = day + } + const tokensIn = u.requestsPerDay * HOT_TOKENS_IN_PER_REQUEST + const tokensOut = u.requestsPerDay * HOT_TOKENS_OUT_PER_REQUEST + addToGroupAndTotal(body, HOT_GROUP, 'tokensInPerDay', tokensIn - u.tokensInPerDay) + addToGroupAndTotal(body, HOT_GROUP, 'tokensOutPerDay', tokensOut - u.tokensOutPerDay) + u.tokensInPerDay = tokensIn + u.tokensOutPerDay = tokensOut + u.tokensInPerMonth = Math.max(u.tokensInPerMonth ?? 0, tokensIn) + u.tokensOutPerMonth = Math.max(u.tokensOutPerMonth ?? 0, tokensOut) + u.lastSeen = Math.floor(ctx.now / 1000) u.rejectionsPerDay = Math.max(u.rejectionsPerDay ?? 0, 9) } } else if (path === '/admin/api/events') { @@ -261,6 +278,13 @@ function hugeModelIds(id: string): string[] { const expandRows = (rows: Obj[], ids: (id: string) => string[]): Obj[] => rows.flatMap((r) => ids(r.id).map((id) => ({ ...r, id }))) +/** A clone of one user with a distinct id and a spread of traffic, so rankings and shares differ. */ +function hugeUser(u: Obj, n: number): Obj { + const scale = 1 / (n + 1) + const scaled = (v: unknown) => (typeof v === 'number' ? Math.floor(v * scale) : v) + return { ...u, id: `${u.id}-${n + 1}`, requestsPerDay: scaled(u.requestsPerDay), tokensInPerDay: scaled(u.tokensInPerDay), tokensOutPerDay: scaled(u.tokensOutPerDay) } +} + function huge(path: string, body: Obj) { if (path === '/admin/api/overview') { body.providers = (body.providers as Obj[]).flatMap((p) => @@ -278,6 +302,10 @@ function huge(path: string, body: Obj) { return { ...p, name, models } }), ) + } else if (path === '/admin/api/usage' && Array.isArray(body.users)) { + body.users = (body.users as Obj[]).flatMap((u) => copies(HUGE_USER_FACTOR, (n) => (n === 0 ? u : hugeUser(u, n)))) + } else if (path === '/admin/api/consumers' && Array.isArray(body.users)) { + body.users = (body.users as Obj[]).flatMap((u) => copies(HUGE_USER_FACTOR, (n) => (n === 0 ? u : { ...u, name: `${u.name}-${n + 1}` }))) } else if (path === '/admin/api/usage/models' && Array.isArray(body.models)) { body.models = expandRows(body.models, hugeModelIds) } else if (path === '/admin/api/performance' && Array.isArray(body.rows)) { diff --git a/webui/src/components/SnippetBlock.vue b/webui/src/components/SnippetBlock.vue index f464fdd..c7e687b 100644 --- a/webui/src/components/SnippetBlock.vue +++ b/webui/src/components/SnippetBlock.vue @@ -57,6 +57,6 @@ const BUTTON_LABEL: Record = { {{ BUTTON_LABEL[state] }} -
{{ text }}
+
{{ text }}
diff --git a/webui/src/components/forms/LimitsForm.vue b/webui/src/components/forms/LimitsForm.vue index e9fcd38..d331640 100644 --- a/webui/src/components/forms/LimitsForm.vue +++ b/webui/src/components/forms/LimitsForm.vue @@ -66,24 +66,24 @@ const raw = reactive>({ /** invalidFields lists every field whose entered text is non-empty but fails its own domain check (fieldValid above) — surfaced individually rather than one generic "invalid input" message, so the operator can see exactly which field to fix. Split by INTEGER_FIELDS so the error text is accurate for both: a fraction is invalid for requestsPerMinute etc. but perfectly valid for costPerDayUSD/costPerMonthUSD. */ const invalidFields = computed(() => - FIELDS.filter(({ key }) => raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), + FIELDS.filter(({ key }) => String(raw[key]).trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), ) /** fieldInvalid is the per-input twin of invalidFields, so each input can carry aria-invalid. */ function fieldInvalid(key: (typeof FIELDS)[number]['key']): boolean { - return raw[key].trim() !== '' && !fieldValid(key, Number(raw[key])) + return String(raw[key]).trim() !== '' && !fieldValid(key, Number(raw[key])) } const invalidIntegerFields = computed(() => - FIELDS.filter(({ key }) => INTEGER_FIELDS.has(key) && raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), + FIELDS.filter(({ key }) => INTEGER_FIELDS.has(key) && String(raw[key]).trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), ) const invalidDecimalFields = computed(() => - FIELDS.filter(({ key }) => !INTEGER_FIELDS.has(key) && raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), + FIELDS.filter(({ key }) => !INTEGER_FIELDS.has(key) && String(raw[key]).trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label), ) const limits = computed(() => { const out: LimitsConfig = {} for (const { key } of FIELDS) { const value = Number(raw[key]) - if (raw[key].trim() !== '' && fieldValid(key, value) && value > 0) out[key] = value + if (String(raw[key]).trim() !== '' && fieldValid(key, value) && value > 0) out[key] = value } return out }) diff --git a/webui/src/lib/events-filter.spec.ts b/webui/src/lib/events-filter.spec.ts index bd3a9d5..da3364d 100644 --- a/webui/src/lib/events-filter.spec.ts +++ b/webui/src/lib/events-filter.spec.ts @@ -30,7 +30,7 @@ describe('EVENT_KIND_LABEL', () => { describe('EVENT_KINDS', () => { it('contains every known AdminEventKind, derived from EVENT_KIND_LABEL', () => { expect(EVENT_KINDS).toEqual(Object.keys(EVENT_KIND_LABEL)) - expect(EVENT_KINDS).toEqual(['rate_limit', 'budget', 'store_down', 'upstream', 'timeout', 'unpriced', 'capacity']) + expect(EVENT_KINDS).toEqual(['rate_limit', 'budget', 'store_down', 'upstream', 'timeout', 'unpriced', 'capacity', 'paced']) }) it('every entry has a truthy label (no silently-empty display text)', () => { diff --git a/webui/src/lib/events-filter.ts b/webui/src/lib/events-filter.ts index 9b0ccdb..351e63b 100644 --- a/webui/src/lib/events-filter.ts +++ b/webui/src/lib/events-filter.ts @@ -9,6 +9,7 @@ export const EVENT_KIND_LABEL: Record = { timeout: 'Timeout', unpriced: 'Unpriced model', capacity: 'Capacity', + paced: 'Paced', } /** diff --git a/webui/src/lib/meters.spec.ts b/webui/src/lib/meters.spec.ts index 453133d..8227e99 100644 --- a/webui/src/lib/meters.spec.ts +++ b/webui/src/lib/meters.spec.ts @@ -82,6 +82,11 @@ describe('effectiveLimitRows', () => { expect(rows.find((r) => r.label === 'Requests/day')).toMatchObject({ value: '3,000', source: 'user' }) expect(rows.find((r) => r.label === 'Pacing')).toMatchObject({ value: 'from 80%, up to 10s delay' }) }) + it('formats cost limits with the shared cost format and marks pacing as prose', () => { + const rows = effectiveLimitRows({ costPerMonthUSD: 25, pacing: PACING }, undefined) + expect(rows.find((r) => r.key === 'costPerMonthUSD')?.value).toBe('$25.00') + expect(rows.find((r) => r.key === 'pacing')?.prose).toBe(true) + }) it('returns no rows without limits', () => { expect(effectiveLimitRows(undefined, undefined)).toEqual([]) }) diff --git a/webui/src/lib/meters.ts b/webui/src/lib/meters.ts index 9f93375..1559ecb 100644 --- a/webui/src/lib/meters.ts +++ b/webui/src/lib/meters.ts @@ -1,4 +1,4 @@ -import { formatCompactCount } from '@/lib/format' +import { formatCompactCount, formatCostDisplay, usdToMicros } from '@/lib/format' import type { AdminUsageEntryView, LimitSources, LimitsConfig } from '@/types/api' /** Pacing starts here when a scope sets no pacing block; matches the budget bars' amber tier. */ @@ -75,6 +75,8 @@ export interface LimitRow { label: string value: string source: string + /** Prose rather than a number: the value is not set in mono. */ + prose?: boolean } const LIMIT_FIELDS: Array<{ key: Exclude; label: string; usd?: boolean }> = [ @@ -100,10 +102,10 @@ export function effectiveLimitRows(limits: LimitsConfig | undefined, sources: Li const rows: LimitRow[] = [] for (const f of LIMIT_FIELDS) { const v = limits[f.key] - if (has(v)) rows.push({ key: f.key, label: f.label, value: f.usd ? `$${v}` : formatCompactCount(v), source: sourceLabel(sources?.[f.key]) }) + if (has(v)) rows.push({ key: f.key, label: f.label, value: f.usd ? formatCostDisplay(usdToMicros(v)) : formatCompactCount(v), source: sourceLabel(sources?.[f.key]) }) } if (limits.pacing) { - rows.push({ key: 'pacing', label: 'Pacing', value: `from ${limits.pacing.startPct}%, up to ${limits.pacing.maxDelay} delay`, source: sourceLabel(sources?.pacing) }) + rows.push({ key: 'pacing', label: 'Pacing', value: `from ${limits.pacing.startPct}%, up to ${limits.pacing.maxDelay} delay`, source: sourceLabel(sources?.pacing), prose: true }) } return rows } diff --git a/webui/src/pages/UsersPage.vue b/webui/src/pages/UsersPage.vue index 6852b39..f762fd3 100644 --- a/webui/src/pages/UsersPage.vue +++ b/webui/src/pages/UsersPage.vue @@ -1,5 +1,5 @@