peppa/apps/web/app/(app)/team/page.tsx
Асель 9052f3245f Merge main into task/pep-98: PEP-112…124 texts through the dictionary
Main's new wording (PEP-123 «Продакт» words) kept and wrapped in t()/m();
wording(mode, locale) gives English words for {task}/{runner} placeholders;
glossary check (pnpm lint) passes; English for all new keys (en/merge-*.ts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:04:39 +05:00

103 lines
5.8 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, words } from "@/lib/auth";
import { db } from "@/lib/db";
import { getT } from "@/lib/i18n";
import { addAgentAction, saveAgentAction, toggleAgentAction } from "./actions";
export async function generateMetadata() {
const t = await getT();
return { title: t("Команда — 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 t = await getT();
const { error, saved } = await searchParams;
const w = await words();
const [team, admin] = await Promise.all([listAgents(db), isSuperadmin(db, user)]);
return (
<Workspace>
<div className="max-w-3xl">
<Flash error={error} />
{saved && <Notice>{t("Сохранено — агент получит новый характер при следующем запуске или перезапуске.")}</Notice>}
<PageHeader title={t("Команда")}>
{t("Это ИИ-агенты, не люди: у каждого своя кличка и характер, одна команда на все проекты. Свободный агент берёт {task} и ведёт её до конца; если все заняты — в команде появляется новый.", { task: w.task("acc") })}
{w.engineer ? t(" Характер добавляется к промпту агента поверх правил Peppa FACTORY и AGENTS.md проекта.") : t(" Характер влияет на то, как агент работает и пишет вам.")}
</PageHeader>
{admin && (
<Card>
<form action={addAgentAction} className="flex flex-wrap items-end gap-2">
<Label className="min-w-48 flex-1">
{t("Новый агент")}
<Input name="name" placeholder={t("Кличка — или пусто: выберем сами")} maxLength={40} autoComplete="off" />
</Label>
<Button variant="default">
<Plus /> {t("Добавить")}
</Button>
</form>
</Card>
)}
<Section title={t("Агенты")} count={team.length}>
{team.length === 0 && <Empty>{t("Пока никого: первый агент появится, когда {task} уйдёт «В работу».", { task: w.task() })}</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">{t("работает")}{a.busy > 1 ? ` ×${a.busy}` : ""}</Badge> : <Badge variant="muted">{t("свободен")}</Badge>}
{a.disabledAt && <Badge variant="danger">{t("не в команде")}</Badge>}
<span className="ml-auto text-xs text-muted-foreground">{t("запусков: {n}", { n: 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">
{t("Кличка")}
<Input name="name" defaultValue={a.name} required maxLength={40} autoComplete="off" />
</Label>
<Label>
{t("Характер и специализация")}
<Textarea
name="character"
defaultValue={a.character}
rows={a.character ? 8 : 3}
maxLength={AGENT_CHARACTER_MAX}
placeholder={t("Например: педант по безопасности — любой ввод проверяет, секреты ищет в каждом диффе. Пишет коротко и сухо, без извинений.")}
className="text-sm"
/>
</Label>
<Button className="self-start" size="sm" variant="default">{t("Сохранить")}</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 ? t("Вернуть в команду") : t("Убрать из команды — новые {tasks} не получит", { tasks: w.task("accPl") })}
</Button>
</form>
</>
) : a.character ? (
<Markdown text={a.character} />
) : (
<p className="m-0 text-sm text-muted-foreground">{t("Характер не задан.")}</p>
)}
</Card>
))}
</Section>
</div>
</Workspace>
);
}