fix: classify upstream failures and prevent empty billed responses

This commit is contained in:
wlx committed 2026-09-28 04:55:00 +08:00
1 parent b455d8d79f
commit 9acc69d4c7
28 files changed
+1449 -131

No files matched your search

+12 -3
View File
@@ -162,11 +162,20 @@ export interface UsageAuditPage {
export interface AdminUsageSummary {
callsToday: number
callsThisMonth: number
waiting: number
waiting: number | null
costToday: number
costThisMonth: number
series: Array<{ date: string; count: number }>
capacityGroups: Array<{ id: string; name: string; running: number; limit: number; queued: number }>
capacityGroups: Array<{ id: string; name: string; sourceLabel?: string; providerName?: string; mode?: string; routeEnabled?: boolean; running: number | null; limit: number; queued: number | null }>
running?: number | null
capacityConfig?: {
queueWaitMs: number
defaultModelConcurrency: number
defaultKeyConcurrency: number
asyncQueueLimit: number
asyncWorkerIntervalMs: number
synchronousSnapshotAvailable: boolean
}
}
export interface AdminCatalogUser {
@@ -207,7 +216,7 @@ export interface AdminInvitation {
export interface ChatCompletionResult {
id: string
model: string
choices: Array<{ message: { role: string; content: string }; finish_reason: string }>
choices: Array<{ message: { role: string; content?: string | null; reasoning_content?: string; reasoning?: string; [key: string]: unknown }; finish_reason?: string | null }>
usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number }
}
+56 -1
View File
@@ -1,4 +1,59 @@
import type { CatalogModel, LogicalModel } from './catalog'
import type { CatalogModel, CatalogProvider, LogicalModel } from './catalog'
export interface ModelCatalogSummary {
publishedModels: number
readyModels: number
readyRoutes: number
unpricedRoutes: number
}
const capabilityLabels: Record<string, string> = {
text: '文本',
code: '代码',
multimodal: '多模态',
image: '图像',
audio: '音频',
video: '视频',
embedding: '向量',
'3d': '3D',
}
/**
* Build the compact capability text shown for a provider in the admin overview.
* A provider can expose hundreds of route rows, so this must deduplicate by
* capability and keep the rendered label bounded for the summary card.
*/
export function providerCapabilityLabel(types: string[]): string {
const labels = [...new Set(types.map(type => capabilityLabels[type.trim().toLowerCase()] || '其他').filter(Boolean))]
if (!labels.length) return '待配置能力'
if (labels.length <= 3) return labels.join(' · ')
return `${labels.slice(0, 3).join(' · ')} 等 ${labels.length} 类`
}
export function summarizeModelCatalog(
definitions: LogicalModel[],
routes: CatalogModel[],
providers: CatalogProvider[],
): ModelCatalogSummary {
const publishedModelIds = new Set(definitions.filter(model => model.status === 'active').map(model => model.id))
const activeProviderIds = new Set(providers.filter(provider => provider.status === 'active').map(provider => provider.id))
const readyModelIds = new Set<string>()
let readyRoutes = 0
let unpricedRoutes = 0
for (const route of routes) {
if (route.status !== 'active' || !publishedModelIds.has(route.logicalModelId) || !activeProviderIds.has(route.providerId)) continue
if (route.pricingConfigured !== true) {
unpricedRoutes++
continue
}
if (route.billingReady === false || route.executionReady === false) continue
readyRoutes++
readyModelIds.add(route.logicalModelId)
}
return { publishedModels: publishedModelIds.size, readyModels: readyModelIds.size, readyRoutes, unpricedRoutes }
}
// Browse published definitions even when none of their routes are enabled yet.
// Route IDs remain the exact authorization and invocation identifiers.