import React from "react"; import { useTranslation } from "react-i18next"; import { ArrowUpCircle, CheckCircle2 } from "lucide-react"; import { compareAgentServerVersions } from "#/api/agent-server-compatibility"; import { getLockedCloudHost } from "#/api/agent-server-config"; import { AGENT_CANVAS_CLIENT_VERSION } from "#/api/client-source"; import { useLatestAgentCanvasVersion } from "#/hooks/query/use-latest-agent-canvas-version"; import { I18nKey } from "#/i18n/declaration"; import { cn } from "#/utils/utils"; import { AgentCanvasVersionModal } from "./agent-canvas-version-modal"; interface AgentCanvasVersionTileProps { className?: string; /** When true, the tile is omitted unless an update is available. */ hideWhenUpToDate?: boolean; } /** * Main-sidebar tile that opens the update-specific version modal. * Hidden when the install is already up to date; settings uses * AgentCanvasUpdateCard instead. */ export function AgentCanvasVersionTile({ className, hideWhenUpToDate = false, }: AgentCanvasVersionTileProps) { const { t } = useTranslation("openhands"); const [isModalOpen, setIsModalOpen] = React.useState(false); const isLockedToCloud = getLockedCloudHost() !== null; const latestVersionQuery = useLatestAgentCanvasVersion({ enabled: !isLockedToCloud, }); if (isLockedToCloud) return null; const installedVersion = AGENT_CANVAS_CLIENT_VERSION; const latestVersion = latestVersionQuery.data ?? null; const comparison = latestVersion !== null ? compareAgentServerVersions(latestVersion, installedVersion) : null; const updateAvailable = comparison === 1; if (hideWhenUpToDate && !updateAvailable) return null; return ( <> {isModalOpen ? ( { void latestVersionQuery.refetch(); }} onClose={() => setIsModalOpen(false)} /> ) : null} ); }