import Link from "next/link"; import type { ReactNode } from "react"; import type { Project, Question, SessionView } from "@peppa/core"; import { answerQuestion, messageSession, resumeTaskSession, stopTaskSession } from "@/app/(app)/actions"; const TASK_STATUS: Record = { backlog: "Бэклог", proposing: "Proposal", awaiting_approval: "Ждёт одобрения", in_progress: "В работе", review: "Ревью", done: "Готово", blocked: "Блок", }; const SESSION_STATUS: Record = { starting: "запуск", running: "работает", waiting_input: "ждёт тебя", idle: "простаивает", stalled: "зависла?", rate_limited: "лимит", done: "завершена", failed: "упала", }; const KIND: Record = { approval: "Одобрение proposal", question: "Вопрос", permission: "Разрешение", attention: "Сессия ждёт тебя" }; export function Badge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) { const label = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? status; return {label}; } export function Flash({ error }: { error?: string }) { return error ?

{error}

: null; } export function Notice({ children }: { children: ReactNode }) { return

{children}

; } export function ago(d: Date | null | undefined): string { if (!d) return "—"; const s = Math.round((Date.now() - d.getTime()) / 1000); if (s < 60) return `${s} с назад`; if (s < 3600) return `${Math.round(s / 60)} мин назад`; if (s < 86400) return `${Math.round(s / 3600)} ч назад`; return d.toLocaleDateString("ru-RU"); } export function QuestionCard({ q, taskKey, taskStatus, back }: { q: Question; taskKey?: string | null; taskStatus?: string | null; back: string }) { const review = q.kind === "attention" && taskStatus === "review"; const answered = !!q.answeredAt; return (
{review ? "Готово к ревью" : KIND[q.kind]} {taskKey && ( {taskKey} )} #{q.id} · {ago(q.createdAt)}

{q.text}

{answered ? (

{q.answeredVia === "system" ? "⌛ " : "✅ "} {q.answeredVia === "system" ? q.answer : `Ответ (${q.answeredVia}): ${q.answer}`}

) : (
{q.kind === "approval" && } {q.kind === "permission" && ( <> )} {review && } {q.kind === "attention" && !review && } {(q.options ?? []).map((o) => ( ))}
{q.kind !== "permission" && (
)}
)}
); } export function SessionCard({ s, back, showTitle = false }: { s: SessionView; back: string; showTitle?: boolean }) { const alive = !["done", "failed"].includes(s.status); return (
{s.taskKey ? {s.taskKey} : {s.projectKey}} {showTitle && s.taskTitle && {s.taskTitle}} #{s.id} · {s.provider} · поколение {s.generation} · {ago(s.lastActivityAt)}
tmux attach -t {s.tmuxName}
{alive && (
)} {alive ? (
) : null} {(!alive || ["rate_limited", "stalled"].includes(s.status)) && (
)}
); } export function ProjectList({ projects, userId }: { projects: Project[]; userId: number }) { if (!projects.length) return (

Проектов пока нет. Создать первый

); return (
    {projects.map((p) => (
  • {p.key} {p.name} {p.ownerId !== userId && общий} {p.giteaOwner}/{p.giteaRepo}
  • ))}
); }