/* Copyright 2026 Marimo. All rights reserved. */ import { useAtom, useAtomValue } from "jotai"; import { RefreshCwIcon } from "lucide-react"; import { connectionNoticeAtom } from "@/core/network/connection-notice"; import { Button } from "@/components/ui/button"; import { useRestartKernel } from "@/components/editor/actions/useRestartKernel"; import { isConnectedAtom, startupProgressAtom, } from "@/core/network/connection"; import type { DisplayConnectionNotice } from "@/core/network/useConnectionNotice"; import { preparationAtom, sandboxActionsAtom, sandboxAtom, sandboxSyncAtom, sandboxSyncOperationAtom, } from "@/core/packages/sandbox-state"; import { cn } from "@/utils/cn"; import { usePanelSection } from "./panel-context"; import { sandboxDetailsExpandedAtom } from "./sandbox-details-state"; import { StartupOutput } from "../../alerts/startup-output"; import { ConnectionStatusIcon, StartupProgress, } from "../../alerts/startup-progress"; export function SandboxErrorOutput({ error }: { error: string }) { return (
      {error}
    
); } function SandboxRecovery({ notice }: { notice: DisplayConnectionNotice }) { const sandbox = useAtomValue(sandboxAtom); const actions = useAtomValue(sandboxActionsAtom); const sync = useAtomValue(sandboxSyncAtom); if (notice.pending || notice.ready) { return null; } return ( <>

{notice.description}

{notice.error && }
{notice.kind === "sync" && sync.kind === "restart-required" ? ( ) : ( )}
{sandbox?.manifest == null && (

A manifest will be available once this new notebook starts.

)} ); } function SandboxRestart() { const restartKernel = useRestartKernel(); return ( ); } function SandboxStartupPanel({ notice }: { notice: DisplayConnectionNotice }) { const showSteps = notice.kind === "startup" && (notice.ready || notice.phase === "preparing-environment" || notice.phase === "starting-kernel"); return (
{showSteps ? ( ) : (

{notice.title}

)}
); } function SandboxSyncStatus({ notice }: { notice: DisplayConnectionNotice }) { return (
{notice.title}
); } function SandboxSyncDetails({ notice, }: { notice: DisplayConnectionNotice | null; }) { const operation = useAtomValue(sandboxSyncOperationAtom); if (!operation && !notice) { return null; } return (
{notice ? ( ) : (

Environment synced

)}
); } export function SandboxDetails() { const section = usePanelSection(); const connected = useAtomValue(isConnectedAtom); const notice = useAtomValue(connectionNoticeAtom); const preparation = useAtomValue(preparationAtom); const progress = useAtomValue(startupProgressAtom); const [expanded, setExpanded] = useAtom(sandboxDetailsExpandedAtom); const startup: DisplayConnectionNotice | null = notice?.kind === "startup" ? { ...notice, ready: false } : preparation || progress ? { kind: "startup", sandbox: true, title: "Notebook started", description: "The notebook is ready to run.", pending: false, ready: true, error: null, } : null; return ( ); } function SandboxActions() { const sandbox = useAtomValue(sandboxAtom); const actions = useAtomValue(sandboxActionsAtom); const pending = useAtomValue(sandboxSyncAtom).kind === "running"; return (
); }