feat(router): smart routers and per-member rate limits (#9)

Add smart routers: virtual models that score each request and route it to admin-defined model tiers. A retryable failure moves the request to a higher tier. The classifier v2 extracts prose, finds the original ask in long tool loops, adds an uncertainty margin and reads tool-output failures. Sessions, outcome signals, bounded calibration, adaptive selection within a tier, gated saturation downgrade, a first-byte timeout and an opt-in timeout fallback are included. Every new feature is off by default.

Add per-member group limits, a tokensPerMinute window that counts uncached input and output, rate-limit headers in three dialects, soft pacing before the hard limit, and a limitExemptKinds list so embedding and reranking traffic never counts toward or hits a limit.

Fix yaegi named-result state that made smartContentSize grow between calls.
This commit is contained in:
2026-11-25 00:40:30 +00:00
committed by GitHub
parent 6fb048b599
commit 4c61d19a72
154 changed files with 73356 additions and 286 deletions
+4 -1
View File
@@ -6,7 +6,7 @@ import type { ModelCatalogRow } from '@/lib/model-table-columns'
import { useCatalogStore } from '@/stores/catalog'
import { useFiltersStore } from '@/stores/filters'
import { hourOrDayWindow } from '@/stores/reliability'
import type { AdminPerfResponse, AdminPerfRow, AdminUsageModelsResponse, HistoryWindow } from '@/types/api'
import type { AdminPerfResponse, AdminPerfRow, AdminRouterView, AdminUsageModelsResponse, HistoryWindow } from '@/types/api'
/**
* useModelsStore fetches the Models page's own catalog table (redesign-
@@ -29,6 +29,8 @@ import type { AdminPerfResponse, AdminPerfRow, AdminUsageModelsResponse, History
export const useModelsStore = defineStore('models', {
state: () => ({
rows: [] as ModelCatalogRow[],
/** The catalog's configured smart routers, shown read-only by SmartRoutersCard.vue. */
routers: [] as AdminRouterView[],
/** GET /admin/api/performance?kind=provider's own rows (fleet p50/p95, attempts/failures, timeouts, failovers per provider) — ProviderHealthPanel.vue's own doc comment. Keyed by provider name at read time, not here, so this store stays a plain array like `rows` above. */
providerPerf: [] as AdminPerfRow[],
/** The hour/day window + span hourOrDayWindow actually resolved for both performance requests — ProviderHealthPanel.vue's badge titles read this rather than filters.window/span directly whenever a month-range clamp was applied. */
@@ -66,6 +68,7 @@ export const useModelsStore = defineStore('models', {
if (requestId !== this.reqId) return
this.rows = buildModelCatalogRows(catalog.data, rankingRes, perfRes)
this.routers = catalog.data.routers ?? []
this.providerPerf = providerPerfRes.rows ?? []
this.perfWindow = perfWindow
this.latencyEnabled = perfRes.latencyEnabled