peppa/apps/web/app/(app)/team/page.tsx
Асель 80a3bb79ad PEP-97: the name users see is «Peppa FACTORY» everywhere
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:34:03 +05:00

97 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Plus } from "lucide-react";
import { AGENT_CHARACTER_MAX, isSuperadmin, listAgents } from "@peppa/core";
import { AgentBadge } from "@/components/AgentBadge";
import { Empty, Flash, Notice, PageHeader, Section } from "@/components/common";
import { Markdown } from "@/components/Markdown";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Input, Label, Textarea } from "@/components/ui/input";
import { Workspace } from "@/components/Workspace";
import { requireUser } from "@/lib/auth";
import { db } from "@/lib/db";
import { addAgentAction, saveAgentAction, toggleAgentAction } from "./actions";
export const metadata = { title: "Команда — Peppa FACTORY" };
/** PEP-75: the platform's team of agents — names and characters. Everyone sees it; a superadmin edits. */
export default async function Team({ searchParams }: { searchParams: Promise<{ error?: string; saved?: string }> }) {
const user = await requireUser();
const { error, saved } = await searchParams;
const [team, admin] = await Promise.all([listAgents(db), isSuperadmin(db, user)]);
return (
<Workspace>
<div className="max-w-3xl">
<Flash error={error} />
{saved && <Notice>Сохранено — агент получит новый характер при следующем запуске или перезапуске.</Notice>}
<PageHeader title="Команда">
Это ИИ-агенты, не люди: у каждого своя кличка и характер, одна команда на все проекты. Свободный агент берёт стори и ведёт её до конца; если все заняты — в
команде появляется новый. Характер добавляется к промпту агента поверх правил Пеппы и AGENTS.md проекта.
</PageHeader>
{admin && (
<Card>
<form action={addAgentAction} className="flex flex-wrap items-end gap-2">
<Label className="min-w-48 flex-1">
Новый агент
<Input name="name" placeholder="Кличка — или пусто: Пеппа выберет сама" maxLength={40} autoComplete="off" />
</Label>
<Button variant="default">
<Plus /> Добавить
</Button>
</form>
</Card>
)}
<Section title="Агенты" count={team.length}>
{team.length === 0 && <Empty>Пока никого: первый агент появится, когда стори уйдёт «В работу».</Empty>}
{team.map((a) => (
<Card key={a.id} id={`agent-${a.id}`} className="gap-3" data-agent={a.name}>
<div className="flex flex-wrap items-center gap-2">
<AgentBadge name={a.name} large />
{a.busy > 0 ? <Badge variant="info">работает{a.busy > 1 ? ` ×${a.busy}` : ""}</Badge> : <Badge variant="muted">свободен</Badge>}
{a.disabledAt && <Badge variant="danger">не в команде</Badge>}
<span className="ml-auto text-xs text-muted-foreground">запусков: {a.runs}</span>
</div>
{admin ? (
<>
<form action={saveAgentAction} className="flex flex-col gap-2">
<input type="hidden" name="id" value={a.id} />
<Label className="max-w-xs">
Кличка
<Input name="name" defaultValue={a.name} required maxLength={40} autoComplete="off" />
</Label>
<Label>
Характер и специализация
<Textarea
name="character"
defaultValue={a.character}
rows={a.character ? 8 : 3}
maxLength={AGENT_CHARACTER_MAX}
placeholder={"Например: педант по безопасности — любой ввод проверяет, секреты ищет в каждом диффе. Пишет коротко и сухо, без извинений."}
className="text-sm"
/>
</Label>
<Button className="self-start" size="sm" variant="default">Сохранить</Button>
</form>
<form action={toggleAgentAction}>
<input type="hidden" name="id" value={a.id} />
<input type="hidden" name="disabled" value={a.disabledAt ? "0" : "1"} />
<Button size="sm" variant="ghost" className="text-muted-foreground">
{a.disabledAt ? "Вернуть в команду" : "Убрать из команды — новые стори не получит"}
</Button>
</form>
</>
) : a.character ? (
<Markdown text={a.character} />
) : (
<p className="m-0 text-sm text-muted-foreground">Характер не задан.</p>
)}
</Card>
))}
</Section>
</div>
</Workspace>
);
}