import type { ScheduledJob } from "@umt/contracts"; import { History } from "lucide-react"; import { Link } from "react-router"; import { useScheduleRuns } from "~/api/schedules.ts"; import { DetailSheet } from "~/components/console/detail-sheet.tsx"; import { EmptyState, ErrorState, LoadingState } from "~/components/console/empty-state.tsx"; import { consolePath } from "~/components/console/nav.ts"; import { StatusBadge } from "~/components/console/status-badge.tsx"; import { useListPagination } from "~/components/console/use-list-pagination.ts"; import { Pagination } from "~/components/ui/pagination.tsx"; import { agentRunLabel } from "~/lib/labels.ts"; import { describeSchedule, formatClock, formatMs, RUN_STATUS, TRIGGER_LABEL } from "./labels.ts"; /** 历史抽屉:最近 50 次运行(新→旧) */ export function RunsSheet({ job, onClose }: { job: ScheduledJob | null; onClose: () => void }) { const runs = useScheduleRuns(job?.id ?? null); const items = runs.data?.items ?? []; const paged = useListPagination(items, { resetKey: job?.id }); return ( !o && onClose()} title={job ? `${job.name} · 运行记录` : "运行记录"} description={ job ? `${describeSchedule(job.schedule)} · 累计 ${job.runCount} 次,失败 ${job.failCount} 次` : undefined } > {runs.isPending ? ( ) : runs.isError ? ( runs.refetch()} /> ) : items.length === 0 ? ( ) : (
    {paged.items?.map((r) => { const s = RUN_STATUS[r.status]; return (
  1. {s.label} {TRIGGER_LABEL[r.trigger]} {formatClock(r.startedAt)} {formatMs(r.durationMs)}
    {r.error ? (

    {r.error}

    ) : r.summary ? (

    {r.summary}

    ) : null} {r.agentRunId ? ( 查看智能体会话{r.agentStatus ? `(${agentRunLabel(r.agentStatus).label})` : ""} ) : null}
  2. ); })}
)} {items.length > 0 ? : null}
); }