39 lines · 2.0 KBRaw
| 1 | import type { Route } from "./+types/repo-agents"; |
| 2 | import { AgentActivity, HostedAgentsPage, agentsAction, editingFrom } from "../components/hosted-agents"; |
| 3 | import { useLive } from "../components/live"; |
| 4 | import { found, fullName, nowSeconds, signedIn } from "../lib/session"; |
| 5 | |
| 6 | export const meta: Route.MetaFunction = ({ params }) => [{ title: `Agents · ${fullName(params)} · refs` }]; |
| 7 | |
| 8 | async function hostedAgents(context: Route.LoaderArgs["context"], name: string) { |
| 9 | const repo = await found(signedIn(context).repo(name)); |
| 10 | return found(repo.hostedAgents()); |
| 11 | } |
| 12 | |
| 13 | export async function loader({ request, params, context }: Route.LoaderArgs) { |
| 14 | const name = fullName(params); |
| 15 | const repo = await found(signedIn(context).repo(name)); |
| 16 | const open = new URL(request.url).searchParams.get("run"); |
| 17 | const agents = await found(repo.hostedAgents()); |
| 18 | const [list, runs] = await Promise.all([agents.list(), repo.agentRuns(open)]); |
| 19 | return { repo: name, list, runs, open, now: nowSeconds(), canEdit: agents.canEdit, editing: editingFrom(request, list, "repo") }; |
| 20 | } |
| 21 | |
| 22 | export async function action({ request, params, context }: Route.ActionArgs) { |
| 23 | const name = fullName(params); |
| 24 | return agentsAction(await hostedAgents(context, name), request, `/${name}/agents`); |
| 25 | } |
| 26 | |
| 27 | export default function RepoAgents({ loaderData, actionData }: Route.ComponentProps) { |
| 28 | useLive(loaderData.repo); |
| 29 | return ( |
| 30 | <div className="flex flex-col gap-8"> |
| 31 | <p className="m-0 max-w-3xl text-muted">Agents that refs runs for this repository. Mention one as @handle on a pull request, or run one from CI. Shared agents come from the namespace settings; customize one to change it here only.</p> |
| 32 | <AgentActivity runs={loaderData.runs} repo={loaderData.repo} open={loaderData.open} now={loaderData.now} /> |
| 33 | <section className="flex flex-col gap-3"> |
| 34 | <h2 className="m-0 text-base font-semibold">Agents</h2> |
| 35 | <HostedAgentsPage list={loaderData.list} canEdit={loaderData.canEdit} level="repo" editing={loaderData.editing} error={actionData?.error ?? null} /> |
| 36 | </section> |
| 37 | </div> |
| 38 | ); |
| 39 | } |