import { useMemo, useState } from "react"; import type { BashRun } from "@/lib/bridge"; type Filter = "recent" | "running" | "done" | "all"; type Props = { runs: BashRun[]; onClose: () => void; }; function fmtDur(r: BashRun): string { const end = r.ended_at ?? Date.now(); const ms = Math.max(0, end - r.started_at); if (ms < 1000) return `${ms}ms`; if (ms < 60_000) return `${Math.round(ms / 1000)}秒`; return `${Math.floor(ms / 60_000)}分${Math.round((ms % 60_000) / 1000)}秒`; } export function BashPanel({ runs, onClose }: Props) { const [filter, setFilter] = useState("recent"); const [openId, setOpenId] = useState(null); const list = useMemo(() => { const sorted = [...runs].sort((a, b) => b.started_at - a.started_at); if (filter === "all") return sorted; if (filter === "running") return sorted.filter((r) => r.status === "running"); if (filter === "done") return sorted.filter((r) => r.status !== "running"); return sorted.slice(0, 20); }, [runs, filter]); const running = runs.filter((r) => r.status === "running").length; return (
后台 Bash · {running} 运行中
{( [ ["recent", "最近"], ["running", "进行中"], ["done", "已完成"], ["all", "全部"], ] as const ).map(([k, label]) => ( ))}
{list.length === 0 ? (
还没有 shell 工具记录。
) : (
    {list.map((r) => (
  • {openId === r.id && r.output ? (
    {r.output}
    ) : null}
  • ))}
)}
); }