import { PlugZap } from "lucide-react"; import { CONNECTION_REASON_TEXT, connectionJournal, grantableAgents, listConnections, listUserProjects, type ConnectionLogView, type ConnectionReason, type ConnectionView } from "@peppa/core"; import { Hidden } from "@/components/cards"; import { ago, Empty, Flash, Notice, PageHeader, Section } from "@/components/common"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Input, Textarea } from "@/components/ui/input"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import type { Translator } from "@peppa/shared/i18n"; import { createConnectionAction, deleteConnectionAction, grantConnectionAction, replaceConnectionSecretAction, revokeConnectionAction, revokeGrantAction } from "../actions"; export async function generateMetadata() { const t = await getT(); return { title: t("Подключения — Peppa FACTORY") }; } type Params = { error?: string; created?: string }; const SELECT = "h-9 rounded-md border border-input bg-background px-2 text-sm"; const BACK = "/connections"; function Decision({ row, t }: { row: ConnectionLogView; t: Translator }) { if (row.decision === "allowed") return {t("разрешено")}; if (row.decision === "denied") return {t("запрещено")}; return {t("не выполнено")}; } const reasonText = (r: string | null, t: Translator) => (r && r in CONNECTION_REASON_TEXT ? t.text(CONNECTION_REASON_TEXT[r as ConnectionReason]) : ""); function ConnectionCard({ c, projects, agents, t }: { c: ConnectionView; projects: Array<{ id: number; key: string; name: string }>; agents: Array<{ id: number; name: string }>; t: Translator }) { const active = c.status === "active"; return (
{c.name} {active ? {t("работает")} : {t("доступ отозван")}} {c.baseUrl} {c.lastUsedAt ? t("последний запрос {ago}", { ago: ago(c.lastUsedAt, t) }) : t("запросов ещё не было")}
{t("Кому разрешено")} {c.grants.length === 0 ? (

{t("Пока никому: агенты не могут пользоваться этим подключением.")}

) : ( )} {active && projects.length > 0 && (