fix(web): show ai route fallback evidence
This commit is contained in:
@@ -79,12 +79,27 @@ interface RunsResponse {
|
||||
items?: RunSummary[]
|
||||
}
|
||||
|
||||
interface AiRoutePolicyItem {
|
||||
provider_name: string
|
||||
role?: string | null
|
||||
runtime?: string | null
|
||||
}
|
||||
|
||||
interface AiRouteHealthItem {
|
||||
status?: string | null
|
||||
latency_ms?: number | null
|
||||
reason?: string | null
|
||||
checked?: boolean
|
||||
}
|
||||
|
||||
interface AiRouteStatusResponse {
|
||||
policy_order?: AiRoutePolicyItem[]
|
||||
selected_provider?: string | null
|
||||
selected_model?: string | null
|
||||
fallback_chain?: Array<{
|
||||
provider_name: string
|
||||
}>
|
||||
fallback_chain?: AiRoutePolicyItem[]
|
||||
route_reason?: string | null
|
||||
route_error?: string | null
|
||||
health?: Record<string, AiRouteHealthItem>
|
||||
}
|
||||
|
||||
interface EvidenceSnapshot {
|
||||
@@ -137,6 +152,42 @@ function gateLabelKey(gate?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function routeHealthLabelKey(status?: string | null) {
|
||||
if (
|
||||
status === 'healthy' ||
|
||||
status === 'slow' ||
|
||||
status === 'degraded' ||
|
||||
status === 'offline' ||
|
||||
status === 'not_checked'
|
||||
) {
|
||||
return `routeHealth.${status}`
|
||||
}
|
||||
return 'routeHealth.unknown'
|
||||
}
|
||||
|
||||
function providerDisplayName(provider?: string | null) {
|
||||
switch (provider) {
|
||||
case 'ollama_gcp_a':
|
||||
return 'GCP-A'
|
||||
case 'ollama_gcp_b':
|
||||
return 'GCP-B'
|
||||
case 'ollama_local':
|
||||
return '111'
|
||||
case 'gemini':
|
||||
return 'Gemini'
|
||||
default:
|
||||
return provider || '--'
|
||||
}
|
||||
}
|
||||
|
||||
function routeTone(route: AiRouteStatusResponse | null): Tone {
|
||||
if (!route?.selected_provider || route.route_error) return 'warn'
|
||||
const primaryProvider = route.policy_order?.[0]?.provider_name
|
||||
if (primaryProvider && route.selected_provider !== primaryProvider) return 'warn'
|
||||
const primaryStatus = primaryProvider ? route.health?.[primaryProvider]?.status : null
|
||||
return primaryStatus === 'healthy' ? 'good' : 'warn'
|
||||
}
|
||||
|
||||
async function fetchJson<T>(path: string, signal: AbortSignal): Promise<T | null> {
|
||||
const response = await fetch(`${API_BASE}${path}`, { signal })
|
||||
if (!response.ok) return null
|
||||
@@ -254,10 +305,26 @@ export function AutomationEvidenceCard() {
|
||||
|
||||
const topGate = quality?.gate_failures?.[0]
|
||||
const claimReady = Boolean(quality?.production_claim?.can_claim_full_auto_repair)
|
||||
const selectedProvider = snapshot?.route?.selected_provider ?? '--'
|
||||
const fallback = snapshot?.route?.fallback_chain
|
||||
const route = snapshot?.route ?? null
|
||||
const primaryProvider = route?.policy_order?.[0]?.provider_name ?? null
|
||||
const primaryStatus = primaryProvider ? route?.health?.[primaryProvider]?.status : null
|
||||
const selectedProvider = providerDisplayName(route?.selected_provider)
|
||||
const fallback = route?.fallback_chain
|
||||
?.map((item) => item.provider_name)
|
||||
.map(providerDisplayName)
|
||||
.join(' -> ')
|
||||
const routeSummary = route?.route_error
|
||||
? t('routeErrorDetail', { error: route.route_error })
|
||||
: t('routeDetail', {
|
||||
model: route?.selected_model ?? '--',
|
||||
selected: selectedProvider,
|
||||
primary: providerDisplayName(primaryProvider),
|
||||
primaryStatus: t(routeHealthLabelKey(primaryStatus) as never),
|
||||
fallback: fallback || t('routeNoFallback'),
|
||||
})
|
||||
const routeDetail = route?.route_reason && !route.route_error
|
||||
? `${routeSummary}${t('routeReasonSeparator')}${t('routeReason', { reason: route.route_reason })}`
|
||||
: routeSummary
|
||||
|
||||
return {
|
||||
quality,
|
||||
@@ -268,8 +335,10 @@ export function AutomationEvidenceCard() {
|
||||
claimReady,
|
||||
selectedProvider,
|
||||
fallback,
|
||||
routeDetail,
|
||||
routeTone: routeTone(route),
|
||||
}
|
||||
}, [snapshot])
|
||||
}, [snapshot, t])
|
||||
|
||||
const hasData = Boolean(snapshot?.quality || snapshot?.coverage || snapshot?.recurrence)
|
||||
|
||||
@@ -365,11 +434,8 @@ export function AutomationEvidenceCard() {
|
||||
<EvidenceMetric
|
||||
label={t('modelRoute')}
|
||||
value={derived.selectedProvider}
|
||||
detail={t('routeDetail', {
|
||||
model: snapshot?.route?.selected_model ?? '--',
|
||||
fallback: derived.fallback || '--',
|
||||
})}
|
||||
tone="neutral"
|
||||
detail={derived.routeDetail}
|
||||
tone={derived.routeTone}
|
||||
icon={Route}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user