import Link from "next/link"; import type { Metadata } from "next"; import { revertPushAction } from "@/app/actions/activity"; import { ConfirmButton } from "@/components/confirm-button"; import { ActivityIcon, ChevronLeftIcon, ChevronRightIcon, SparkleIcon } from "@/components/icons"; import { liftRowClass } from "@/components/repo-rows"; import { Blankslate, Box, ButtonLink, Label, PageTitle, Segmented, segmentClass } from "@/components/ui"; import { requireViewer } from "@/lib/auth"; import { describeEvent, eventPath, isRevertable } from "@/lib/event-text"; import { listActiveAgents, listAgentActivity } from "@/lib/events"; import { formatDate, timeAgo } from "@/lib/format"; import { revParse } from "@/lib/git"; import { findRepoById } from "@/lib/repos"; export const metadata: Metadata = { title: "Agent activity" }; const PAGE_SIZE = 40; export default async function AgentActivityPage({ searchParams }: PageProps<"/settings/activity">) { const viewer = await requireViewer("/settings/activity"); const query = await searchParams; const agent = typeof query.agent === "string" ? query.agent : undefined; const page = Math.max(1, Number(query.page) || 1); const [agents, { events, total }] = await Promise.all([ listActiveAgents(viewer.id), listAgentActivity(viewer.id, { agent, page, perPage: PAGE_SIZE }), ]); const repos = new Map(); for (const e of events) { if (!repos.has(e.repoId)) { const r = await findRepoById(e.repoId); repos.set(e.repoId, r ? { base: `/${r.owner}/${r.name}`, name: `${r.owner}/${r.name}`, dir: r.dir } : null); } } // Pushes to branches that are gone can't be undone anymore. const undoable = new Set(); for (const e of events) { const repo = repos.get(e.repoId); if (repo && isRevertable(e) && (await revParse(repo.dir, String(e.payload.ref)))) undoable.add(e.id); } const href = (a?: string, p = 1) => `/settings/activity?${new URLSearchParams({ ...(a ? { agent: a } : {}), ...(p > 1 ? { page: String(p) } : {}) })}`; return (
{agents.length > 1 && ( All agents {agents.map((a) => ( {a.name} ))} )} {events.length === 0 ? ( } title="Nothing yet"> When an agent you connected changes something, it shows up here. ) : (
    {events.map((e) => { const repo = repos.get(e.repoId); const reverted = e.payload.reverted as { commit: string; pull: number | null } | undefined; return (
  • {e.agent?.name}{" "} {repo ? ( {describeEvent(e)} ) : ( describeEvent(e) )}

    {repo ? repo.name : "a deleted repository"} ยท {timeAgo(e.createdAt)}

    {reverted && ( )} {undoable.has(e.id) && ( Undo )}
  • ); })}
)}
{(page > 1 || page * PAGE_SIZE < total) && (
{page > 1 && ( }> Newer )} {page * PAGE_SIZE < total && ( Older )}
)}
); }