import { Icon } from "./Icon"; import { useEffect, useState } from "react"; import { get, post } from "../api"; import { toast } from "../dialogs"; import { fmtRelative, useT } from "../i18n"; import { Spinner } from "./Activity"; interface ShellInfo { id: string; command: string; started_at: number; running: boolean; exit_code: number | null; output: string; } /** Header chip with the session's background shells; opens a live output popup. */ export function ShellsChip({ sessionId, busy }: { sessionId: string; busy: boolean }) { const t = useT(); const [shells, setShells] = useState([]); const [open, setOpen] = useState(false); const [selected, setSelected] = useState(); useEffect(() => { let alive = true; const load = () => get(`/sessions/${sessionId}/shells`).then((s) => alive && setShells(s)).catch(() => undefined); void load(); const anyRunning = shells.some((s) => s.running); if (!open && !busy && !anyRunning) return () => void (alive = false); const h = setInterval(load, open ? 1500 : 5000); return () => { alive = false; clearInterval(h); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [sessionId, open, busy, shells.some((s) => s.running)]); const running = shells.filter((s) => s.running).length; if (shells.length === 0) return null; const current = shells.find((s) => s.id === selected) ?? shells[0]; return ( <> {open && (
setOpen(false)}>
e.stopPropagation()}>

{t("shells.title")}

{shells.map((s) => ( ))}
{current.command} · {fmtRelative(current.started_at)} · {current.running ? t("shells.running") : t("shells.exited", { code: current.exit_code ?? "?" })} {current.running && ( )}
{current.output || t("shells.noOutput")}
)} ); }