// Domain cards shared by pages: agent questions, runners, project list. import Link from "next/link"; import { BellRing, CircleCheck, CircleHelp, FileCheck, Hourglass, Play, RotateCcw, Send, ShieldQuestion, Square, SquareTerminal } from "lucide-react"; import type { Project, Question, SessionView, StepView } from "@peppa/core"; import { answerQuestion, messageSession, resumeTaskSession, stopTaskSession } from "@/app/(app)/actions"; import { Button } from "@/components/ui/button"; import { AgentBadge } from "@/components/AgentBadge"; import { Input } from "@/components/ui/input"; import { ago, Disclosure, Empty, Key, StatusBadge } from "@/components/common"; import { AgentSteps } from "@/components/AgentSteps"; import { RunnerTerminal } from "@/components/RunnerTerminal"; import { SessionUsageLine } from "@/components/Accounting"; import { cn } from "@/lib/utils"; const KIND = { approval: { label: "Одобрение proposal", icon: FileCheck, border: "border-l-primary" }, question: { label: "Вопрос", icon: CircleHelp, border: "border-l-info" }, permission: { label: "Разрешение", icon: ShieldQuestion, border: "border-l-warn" }, attention: { label: "Сессия ждёт тебя", icon: BellRing, border: "border-l-ok" }, } as const; /** Hidden inputs of a server-action form. */ export function Hidden({ fields }: { fields: Record }) { return ( <> {Object.entries(fields).map(([k, v]) => (v == null ? null : ))} ); } export function QuestionCard({ q, taskKey, taskStatus, back, compact = false }: { q: Question; taskKey?: string | null; taskStatus?: string | null; back: string; compact?: boolean }) { const review = q.kind === "attention" && taskStatus === "review"; const answered = !!q.answeredAt; const k = KIND[q.kind]; const Icon = review ? CircleCheck : k.icon; return (
{review ? "Готово к ревью" : k.label} {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" && (
)} )}
); } /** Message / stop / resume controls of one runner. */ export function SessionActions({ s, back }: { s: SessionView; back: string }) { const alive = !["done", "failed"].includes(s.status); return (
{alive && (
)} {alive && (
)} {(!alive || ["rate_limited", "stalled"].includes(s.status)) && (
)}
); } export function AttachCommand({ name }: { name: string }) { return tmux attach -t {name}; } /** `steps` (PEP-33): the live step feed of the agent, shown with the terminal. */ export function SessionCard({ s, back, showTitle = false, terminal = false, steps }: { s: SessionView; back: string; showTitle?: boolean; terminal?: boolean; steps?: StepView[] }) { return (
{s.taskKey ? {s.taskKey} : {s.projectKey}} {s.agentName && } {showTitle && (s.taskTitle ?? s.name) && {s.taskTitle ?? s.name}} #{s.id} · {s.provider} {s.subscriptionName && <> · {s.subscriptionName}} {s.host && <> · {s.host.name}} {s.container && <> · в контейнере} {s.subscriptionSwitches > 0 && <> · переключений {s.subscriptionSwitches}} · пок. {s.generation} · {ago(s.lastActivityAt)}
{!terminal && !["done", "failed"].includes(s.status) && ( )} {steps && } {terminal && }
); } /** * PEP-89: an agent at work, for a product manager — who, on what, in what state. The run's * number, subscription, terminal command and spend sit under «Подробнее». */ export function AgentAtWork({ s, back }: { s: SessionView; back: string }) { const alive = !["done", "failed"].includes(s.status); const verb = s.status === "running" || s.status === "starting" ? "работает над" : s.status === "waiting_input" ? "спрашивает по" : "вёл"; return (
{ago(s.lastActivityAt)}

{s.taskKey ? ( <> {verb} {s.taskKey} {s.taskTitle} ) : ( <> свободный терминал в проекте {s.projectKey} {s.name && {s.name}} )}

запуск #{s.id} · {s.provider} {s.subscriptionName && <> · {s.subscriptionName}} {s.host && <> · {s.host.name}} {s.container && <> · в контейнере} {s.subscriptionSwitches > 0 && <> · переключений {s.subscriptionSwitches}} · пок. {s.generation} {alive && ( )}
); } export function ProjectList({ projects, userId }: { projects: Array; userId: number }) { if (!projects.length) return ( Проектов пока нет. Создать первый ); return ( ); }