import Link from "next/link"; import { Search, SquareTerminal } from "lucide-react"; import { listUserProjects, runnerStories, listUserSessions, RUNNER_FILTERS, sessionSteps, type RunnerFilter, type SessionView } from "@peppa/core"; import { LiveRefresh } from "@/components/LiveRefresh"; import { Empty, Flash, PageHeader } from "@/components/common"; import { RunnerDetails, RunnerRow } from "@/components/RunnerConsole"; import { Input } from "@/components/ui/input"; import { NewRunnerForm } from "@/components/Runners"; import { SettingsDialog } from "@/components/SettingsDialog"; import { Workspace } from "@/components/Workspace"; import { requireUser, subscriptionNamesVisible } from "@/lib/auth"; import { db } from "@/lib/db"; import { inbox, sessionEvents } from "@/lib/queries"; import { cn } from "@/lib/utils"; import { getT } from "@/lib/i18n"; import { m } from "@peppa/shared/i18n"; const FILTERS: Array<{ key: RunnerFilter | undefined; label: string }> = [ { key: undefined, label: m("все") }, { key: "waiting", label: m("ждут вас") }, { key: "working", label: m("работают") }, { key: "stopped", label: m("упали") }, { key: "finished", label: m("готово") }, ]; const inFilter = (s: SessionView, f: RunnerFilter) => (RUNNER_FILTERS[f] as string[]).includes(s.status); const matches = (s: SessionView, q: string) => [s.name, s.taskKey, s.taskTitle, s.projectKey, s.tmuxName, `#${s.id}`].some((v) => v?.toLowerCase().includes(q)); type Params = { error?: string; f?: string; q?: string; id?: string }; export default async function Runners({ searchParams }: { searchParams: Promise }) { const user = await requireUser(); const t = await getT(); const { error, f, q: rawQ, id } = await searchParams; const filter = f && f in RUNNER_FILTERS ? (f as RunnerFilter) : undefined; const q = rawQ?.trim().toLowerCase() ?? ""; const [all, open, projects] = await Promise.all([listUserSessions(db, user.id), inbox(user.id), listUserProjects(db, user.id)]); const asking = new Map(); for (const x of open) if (x.sessionId) asking.set(x.sessionId, [...(asking.get(x.sessionId) ?? []), x]); const needsPm = (s: SessionView) => s.status === "waiting_input" || asking.has(s.id); const found = q ? all.filter((s) => matches(s, q)) : all; const count = (k: RunnerFilter | undefined) => (k ? found.filter((s) => inFilter(s, k)).length : found.length); // Who needs the PM first, then live runners, then finished ones; newest first inside each group. const rank = (s: SessionView) => (needsPm(s) ? 0 : ["done", "failed"].includes(s.status) ? 2 : 1); const shown = (filter ? found.filter((s) => inFilter(s, filter)) : found).sort((a, b) => rank(a) - rank(b) || b.id - a.id); const url = (p: { f?: string; q?: string; id?: number | string }) => { const sp = new URLSearchParams(); if (p.f) sp.set("f", p.f); if (p.q) sp.set("q", p.q); if (p.id) sp.set("id", String(p.id)); const s = sp.toString(); return s ? `/runners?${s}` : "/runners"; }; const base = { f: filter, q: rawQ?.trim() || undefined }; const selected = (id && all.find((s) => s.id === Number(id))) || shown[0]; const back = url({ ...base, id: selected?.id }); const aside = selected ? ( ) : null; return ( 0 && ( {t("Новый терминал")}}> ) } > {t("Агенты в tmux по стори ваших и общих проектов и свободные терминалы: кто ждёт вас, кто работает, что готово.")}
{filter && }
{shown.length === 0 ? ( {q || filter ? t("Таких раннеров нет.") : t("Раннеров пока не было: перенесите стори в «В работе» на доске проекта.")} ) : (
    {shown.map((s) => ( ))}
)}
); }