'use client'; import { useI18n } from '@/lib/i18n'; import type { RuntimeHealthStatus } from '@/lib/runtime-health-status'; import { cn } from '@/lib/utils'; import { CircleAlert, CircleCheck, LoaderCircle } from 'lucide-react'; type RuntimeRequestModeHealth = { mode: string; configuredCredentialCount: number; healthyCredentialCount: number; configuredChannelCount: number; healthyChannelCount: number; }; type RuntimeChannelRoutingSummary = { effectiveRequestModes?: string[]; requestModeHealth?: RuntimeRequestModeHealth[]; }; type RuntimeLastFailure = { scope: 'credential' | 'channel'; status?: number; code?: string; requestId?: string; requestMode?: string; }; type WorkbenchStatusStripProps = { model: string; routeLabel: string; streamStatus: string; parallelBatchEnabled?: boolean; requestSummaryLabel: string; runtimeHealthStatus?: RuntimeHealthStatus; channelRouting?: RuntimeChannelRoutingSummary | null; runtimeLastFailure?: RuntimeLastFailure | null; className?: string; }; export function WorkbenchStatusStrip({ model, routeLabel, streamStatus, parallelBatchEnabled = false, requestSummaryLabel, runtimeHealthStatus = 'runtime-ready', channelRouting, runtimeLastFailure, className }: WorkbenchStatusStripProps) { const { t } = useI18n(); const requestModeHealth = channelRouting?.requestModeHealth ?? []; const effectiveRequestModes = channelRouting?.effectiveRequestModes ?? []; const configuredHealthyModes = requestModeHealth .filter((item) => item.healthyCredentialCount > 0 && item.healthyChannelCount > 0) .map((item) => item.mode); const suggestedRequestModes = configuredHealthyModes.length ? configuredHealthyModes : effectiveRequestModes; const hasRequestModeDetails = requestModeHealth.length > 0 || Boolean(runtimeLastFailure); const hasRouteWarnings = (runtimeHealthStatus !== 'runtime-ready' && runtimeHealthStatus !== 'checking') || requestModeHealth.some((item) => item.configuredCredentialCount > 0 && item.healthyCredentialCount === 0); const runtimeStatusLabel = runtimeHealthStatus === 'custom-override' ? t('app.apiCustomOverride') : runtimeHealthStatus === 'checking' ? t('app.apiRuntimeChecking') : runtimeHealthStatus === 'runtime-ready' ? t('app.apiRuntimeReady') : runtimeHealthStatus === 'route-limited' ? t('app.apiRouteLimited') : t('app.apiDisconnected'); const runtimeStatusColorClass = runtimeHealthStatus === 'custom-override' ? 'text-amber-700 dark:text-amber-300' : runtimeHealthStatus === 'checking' ? 'text-sky-700 dark:text-sky-300' : runtimeHealthStatus === 'runtime-ready' ? 'text-emerald-700 dark:text-emerald-300' : runtimeHealthStatus === 'route-limited' ? 'text-amber-700 dark:text-amber-300' : 'text-slate-600 dark:text-slate-300'; const RuntimeStatusIcon = runtimeHealthStatus === 'checking' ? LoaderCircle : runtimeHealthStatus === 'runtime-ready' ? CircleCheck : CircleAlert; return (
{t('app.recentChannelFailure')}:{' '} {[ runtimeLastFailure.scope, runtimeLastFailure.status ? `HTTP ${runtimeLastFailure.status}` : undefined, runtimeLastFailure.code, runtimeLastFailure.requestMode, runtimeLastFailure.requestId ] .filter(Boolean) .join(' / ')}
)}{t('app.suggestedRequestModes')}:{' '} OPENAI_CHANNEL_N_REQUEST_MODES= {suggestedRequestModes.length ? suggestedRequestModes.join(',') : 'images-non-stream'}