// Modified in AgentDeskFixes: safe, reviewed setup repairs and honest routing diagnostics. "use client" import { AlertTriangleIcon, CheckCircle2Icon, RefreshCwIcon, ShieldAlertIcon, SparklesIcon, WrenchIcon, } from "lucide-react" import Link from "next/link" import { useCallback, useEffect, useState } from "react" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { useI18n } from "@/i18n/provider" import { fetchSetupReadiness, type SetupReadinessResponse, } from "@/lib/api/setup-readiness" import { cn } from "@/lib/utils" export const SETUP_READINESS_UPDATED_EVENT = "setup-readiness-updated" export function notifySetupReadinessUpdated() { if (typeof window !== "undefined") { window.dispatchEvent(new CustomEvent(SETUP_READINESS_UPDATED_EVENT)) } } export function OperatorReadinessIndicator({ compact = false, }: { compact?: boolean }) { const t = useI18n() const [readiness, setReadiness] = useState(null) const [loading, setLoading] = useState(true) const [open, setOpen] = useState(false) const loadReadiness = useCallback(async () => { try { const data = await fetchSetupReadiness() setReadiness(data) } catch { // Silent background check in header } finally { setLoading(false) } }, []) useEffect(() => { void loadReadiness() const handleUpdated = () => { void loadReadiness() } window.addEventListener(SETUP_READINESS_UPDATED_EVENT, handleUpdated) const interval = window.setInterval(() => { if (document.visibilityState === "visible") void loadReadiness() }, 60000) return () => { window.removeEventListener(SETUP_READINESS_UPDATED_EVENT, handleUpdated) window.clearInterval(interval) } }, [loadReadiness]) if (loading && !readiness) { return null } if (!readiness) { return null } const operatorOk = readiness.current_operator.can_receive_now const chainOk = readiness.can_receive_requests_now const isAllReady = operatorOk && chainOk const blockerCount = readiness.current_operator.blocker_codes.length + (chainOk ? 0 : Math.max(1, readiness.total_steps - readiness.ready_steps)) const canQuickSetupAll = readiness.steps.some((s) => s.quick_fix_actions.includes("quick_setup_all"), ) const canEnableMyProfile = readiness.steps.some((s) => s.quick_fix_actions.includes("enable_my_operator_profile"), ) return ( { setOpen(nextOpen) if (nextOpen) { void loadReadiness() } }} > } > {isAllReady ? ( ) : ( )} {isAllReady ? t("setupWizard.headerIndicator.readyLabel") : t("setupWizard.headerIndicator.blockedLabel", { count: blockerCount, })}

{t("setupWizard.currentOperatorTitle")}

{t("setupWizard.stepsProgress", { ready: readiness.ready_steps, total: readiness.total_steps, })}

{t("setupWizard.currentOperatorTeam", { team: readiness.current_operator.team_name || t("setupWizard.currentOperatorNoTeam"), })} {t("setupWizard.currentOperatorLoad", { active: readiness.current_operator.active_conversation_count, max: readiness.current_operator.max_concurrent_count, })}
{isAllReady ? (

{t("setupWizard.currentOperatorReady")}

) : (

{t("setupWizard.currentOperatorBlocked")}

    {readiness.current_operator.blocker_codes.map((code) => (
  • {t(`setupWizard.operatorBlockers.${code}`)}
  • ))} {!chainOk ? readiness.steps .filter((step) => step.status !== "ok") .map((step) => (
  • {t(`setupWizard.steps.${step.key}.title`)}
  • )) : null}
)}
{(!operatorOk && canEnableMyProfile) || (!chainOk && canQuickSetupAll) ? ( ) : null}
) }