import { ChevronRightIcon, Loader2Icon, SquareIcon } from "lucide-react"; import { useState, type ReactNode } from "react"; import type { SessionBackgroundCommand } from "@opengeni/sdk"; import type { UseSessionBackgroundCommandsResult } from "../hooks/use-session-background-commands"; import { formatClockTime } from "../lib/format"; import { useErrorMessage } from "../lib/error-message"; import { useOpenGeniText } from "../messages/runtime"; /** The current session's live commands. Settled commands belong to the timeline. */ export function SessionCommandsPanel({ commands: state, readOnly = false, renderMetadata, compact = true, }: { commands: UseSessionBackgroundCommandsResult; readOnly?: boolean; renderMetadata?: (command: SessionBackgroundCommand) => ReactNode; compact?: boolean; }) { const t = useOpenGeniText(); const formatError = useErrorMessage(); const [pending, setPending] = useState(null); const [error, setError] = useState(null); const active = state.commands.filter( (command) => command.state === "running" || command.state === "stopping", ); const stop = async (id: string) => { setPending(id); setError(null); try { await state.cancel(id); } catch (cause) { setError(formatError(cause)); } finally { setPending(null); } }; return (
{state.loading && active.length === 0 ? (

{t("sessionCommandsPanel.loadingCommands")}

) : null} {state.error ? (
{t("sessionCommandsPanel.commandsUnavailable")}
) : null} {!state.loading && !state.error && active.length === 0 ? (

{t("sessionCommandsPanel.noBackgroundCommandsRunning")}

) : null} {active.length > 0 ? (
    {active.map((command) => (
  • {renderMetadata?.(command)}
    {command.commandText ?? (command.commandPreview || t("sessionCommandsPanel.backgroundCommand"))}

    {command.commandText ?? (command.commandPreview || t("sessionCommandsPanel.backgroundCommand"))}

    {command.observationStatus === "unavailable" ? command.state === "stopping" ? t("sessionCommandsPanel.stopRequestedStatusUnavailable") : t("sessionCommandsPanel.commandStatusUnavailable") : command.state === "stopping" ? t("sessionCommandsPanel.stopping") : t("sessionCommandsPanel.running")}

    {!readOnly ? ( ) : null}
  • ))}
) : null} {error ? (

{error}

) : null}
); }