import Link from "next/link";
import { listUserSessions, RUNNER_FILTERS, type RunnerFilter } from "@peppa/core";
import { AutoRefresh } from "@/components/AutoRefresh";
import { Flash, SessionCard } from "@/components/ui";
import { requireUser } from "@/lib/auth";
import { db } from "@/lib/db";
const FILTERS: Array<{ key: RunnerFilter | undefined; label: string }> = [
{ key: undefined, label: "Все" },
{ key: "waiting", label: "Ждут тебя" },
{ key: "working", label: "Работают" },
{ key: "stopped", label: "Остановлены" },
{ key: "finished", label: "Завершены" },
];
export default async function Runners({ searchParams }: { searchParams: Promise<{ error?: string; f?: string }> }) {
const user = await requireUser();
const { error, f } = await searchParams;
const filter = f && f in RUNNER_FILTERS ? (f as RunnerFilter) : undefined;
const all = await listUserSessions(db, user.id);
const count = (k: RunnerFilter | undefined) => (k ? all.filter((s) => (RUNNER_FILTERS[k] as string[]).includes(s.status)).length : all.length);
const shown = filter ? all.filter((s) => (RUNNER_FILTERS[filter] as string[]).includes(s.status)) : all;
const back = filter ? `/runners?f=${filter}` : "/runners";
return (
<>
Агенты в tmux по задачам твоих и общих проектов. Подключиться к раннеру — команда tmux attach на машине Пеппы.
{shown.length === 0 ?{filter ? "Таких раннеров нет." : "Раннеров пока не было: перенеси задачу в «В работе» на доске проекта."}
: shown.map((s) =>