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 { Textarea } from "@/components/ui/input"; import { SecretNameHint } from "@/components/SecretNameHint"; import { getT } from "@/lib/i18n"; import { deleteProjectSecretAction, saveProjectSecretAction, secretToConnectionAction, setAgentSecretsAction, setSecretAudienceAction } 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): ReactNode { return text.split(/\{(\w+)\}/).map((piece, i) => {i % 2 ? (parts[piece] ?? `{${piece}}`) : piece}); } /** * PEP-54: the project's secrets for agents and (PEP-112) for the deployed product — names only; values are write-only. * PEP-253: where each secret goes (only the product / also agents), the project setting «Агенты получают секреты * в окружение», and keys of catalog services with «Сделать подключением». */ export async function ProjectSecretsPanel({ projectId, secrets, back, agentsEnabled, services, hints, engineer, }: { projectId: number; secrets: ProjectSecretView[]; back: string; agentsEnabled: boolean; /** secret name → the recognised catalog service and the connection it became. */ services: Map; hints: Array<{ prefix: string; exact: boolean; service: string }>; engineer: boolean; }) { const t = await getT(); return (
{t("Агенты получают секреты в окружение")}: {agentsEnabled ? t("да") : t("нет")} {agentsEnabled ? t("Агент видит ключи с пометкой «агенту и продукту» и может их напечатать или унести. Внешние сервисы безопаснее давать подключениями.") : t("Агенты не получают ни одного секрета; продукт получает все. Внешние сервисы агентам — через подключения.")} {secrets.length > 0 && (
    {secrets.map((s) => { const svc = services.get(s.name); const toAgent = s.agentEnv && agentsEnabled; const canMove = !!svc?.serviceName && !s.connectionId; return (
  • {s.name} {s.agentEnv ? t("агенту и продукту") : t("только продукту")} {s.agentEnv && !agentsEnabled ? " (" + t("агентам секреты не выдаются") + ")" : ""} {" · "} {t("изменён {ago}", { ago: ago(s.updatedAt, t) })} {s.updatedBy ? ` · ${s.updatedBy}` : ""} {toAgent ? " · " + (s.lastUsedAt ? t("выдан агенту {ago}", { ago: ago(s.lastUsedAt, t) }) : t("агентам ещё не выдавался")) : ""}
    {svc?.connectionName && {t("Стал подключением «{name}»: агент работает с сервисом, не видя ключа.", { name: svc.connectionName })}} {canMove && ( {toAgent ? t("Это ключ {service}, и агент его видит. Сделайте подключение: агент будет работать с сервисом, не видя ключа, продукт получит ключ как раньше.", { service: svc!.serviceName! }) : t("Это ключ {service}. Агенту его можно дать подключением — ключ он не увидит.", { service: svc!.serviceName! })} )}
    {canMove && (
    )}
  • ); })}
)}