peppa/apps/web/components/ProjectSecrets.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

57 lines
4.0 KiB
TypeScript
Raw Permalink 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 { Trash2 } from "lucide-react";
import type { ProjectSecretView } from "@peppa/core";
import { Hidden } from "@/components/cards";
import { ago } from "@/components/common";
import { Button } from "@/components/ui/button";
import { Input, Textarea } from "@/components/ui/input";
import { getT } from "@/lib/i18n";
import { deleteProjectSecretAction, saveProjectSecretAction } from "@/app/(app)/actions";
import { Fragment, type ReactNode } from "react";
/** A translated sentence with {name} placeholders replaced by inline elements. */
function rich(text: string, parts: Record<string, ReactNode>): ReactNode {
return text.split(/\{(\w+)\}/).map((piece, i) => <Fragment key={i}>{i % 2 ? (parts[piece] ?? `{${piece}}`) : piece}</Fragment>);
}
/** PEP-54: the project's secrets for agents and (PEP-112) for the deployed product — names only; values are write-only. */
export async function ProjectSecretsPanel({ projectId, secrets, back }: { projectId: number; secrets: ProjectSecretView[]; back: string }) {
const t = await getT();
return (
<div className="flex flex-col gap-3">
{secrets.length > 0 && (
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm" aria-label={t("Секреты проекта")}>
{secrets.map((s) => (
<li key={s.id} className="flex items-center gap-2 rounded-md border bg-background/40 px-2.5 py-1.5">
<span className="flex min-w-0 flex-1 flex-col">
<span className="truncate font-mono text-[13px]">{s.name}</span>
<span className="text-xs text-muted-foreground">
{t("изменён {ago}", { ago: ago(s.updatedAt, t) })}
{s.updatedBy ? ` · ${s.updatedBy}` : ""} · {s.lastUsedAt ? t("выдан агенту {ago}", { ago: ago(s.lastUsedAt, t) }) : t("агентам ещё не выдавался")}
</span>
</span>
<form action={deleteProjectSecretAction}>
<Hidden fields={{ projectId, name: s.name, back }} />
<Button variant="ghost" size="icon" aria-label={t("Удалить {name}", { name: s.name })} title={t("Удалить {name}", { name: s.name })}>
<Trash2 />
</Button>
</form>
</li>
))}
</ul>
)}
<form action={saveProjectSecretAction} className="flex flex-col gap-2" autoComplete="off">
<Hidden fields={{ projectId, back }} />
<Input name="name" required placeholder="STRIPE_TEST_KEY" aria-label={t("Имя секрета")} pattern="[A-Z][A-Z0-9_]{0,63}" className="font-mono" autoComplete="off" spellCheck={false} />
<Textarea name="value" required rows={2} placeholder={t("Значение — после сохранения его не увидит никто")} aria-label={t("Значение секрета")} className="font-mono" autoComplete="off" spellCheck={false} />
<Button size="sm" className="self-start">{t("Сохранить")}</Button>
</form>
<p className="m-0 text-xs text-muted-foreground">
{rich(
t("Секреты получают агенты проекта (при следующем запуске сессии) и сам выкаченный продукт — как переменные окружения с тем же именем; после изменения Peppa FACTORY через пару минут перезапускает продукт. Имена {a}, {c}, {o} идут только в продукт. Имя существующего секрета заменяет его значение. Значение хранится зашифрованным и больше не показывается; в терминале и ленте шагов оно заменяется на «••••». Агент видит только имена ({list})."),
{ a: <code>ANTHROPIC_…</code>, c: <code>CLAUDE_…</code>, o: <code>OPENCODE_…</code>, list: <code>list_secrets</code> },
)}
</p>
</div>
);
}