import Link from "next/link"; import { ExternalLink, PlugZap, Search } from "lucide-react"; import { CATALOG_KIND_TEXT, CATALOG_KINDS, catalogService, CONNECTION_CHECK_TEXT, CONNECTION_REASON_TEXT, connectionJournal, JOURNAL_VERIFY_SCRIPT, grantableAgents, listConnections, listUserProjects, searchCatalog, type CatalogKind, type CatalogService, type ConnectionGrantView, type ConnectionLogView, type ConnectionReason, type ConnectionView, type GrantMode, type GatewayProtocol, GATEWAY_PROTOCOLS, } 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, uiMode } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import { m, type Translator } from "@peppa/shared/i18n"; import { checkConnectionAction, createConnectionAction, deleteConnectionAction, grantConnectionAction, replaceConnectionSecretAction, resetHostKeyAction, revokeConnectionAction, revokeGrantAction } from "../actions"; export async function generateMetadata() { const t = await getT(); return { title: t("Подключения — FORGE") }; } type Params = { error?: string; created?: string; checked?: string; check?: string; service?: string; q?: string; kind?: 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 }) { // PEP-254: the call is written before the service answers; no result after a while — a crash in the middle. if (row.state === "running") return {t("выполняется")}; if (row.state === "unfinished") return {t("начато, итога нет")}; 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]) : ""); const kindText = (k: CatalogKind, t: Translator) => t.text(CATALOG_KIND_TEXT[k]); /** «ключ работает» / «ключ не подходит» / «сервис не отвечает» / «ещё не проверялся». */ function KeyState({ c, t }: { c: ConnectionView; t: Translator }) { if (c.status !== "active") return {t("доступ отозван")}; if (!c.checkStatus) return {t("ключ ещё не проверялся")}; const text = t.text(CONNECTION_CHECK_TEXT[c.checkStatus]); return {text}; } function modeText(m: GrantMode, t: Translator): string { return m === "auto" ? t("сразу") : m === "ask" ? t("спрашивать меня") : t("нет"); } function GrantLine({ g, engineer, t }: { g: ConnectionGrantView; engineer: boolean; t: Translator }) { return (
  • {g.projectKey} · {g.agentName ? t("агент {name}", { name: g.agentName }) : t("любой агент проекта")} · {t("чтение: {mode}", { mode: modeText(g.readMode, t) })} · {t("запись: {mode}", { mode: modeText(g.writeMode, t) })} {engineer && g.operations.length > 0 && {g.operations.join(", ")}}
  • ); } function ModeSelect({ name, label, def, t }: { name: string; label: string; def: GrantMode; t: Translator }) { return ( ); } function GrantForm({ c, projects, agents, engineer, t }: { c: ConnectionView; projects: Array<{ id: number; key: string; name: string }>; agents: Array<{ id: number; name: string }>; engineer: boolean; t: Translator }) { return (
    {/* PEP-251: changing a database and sending letters ask the owner by default. */}

    {c.protocol === "http" ? t("Чтение — смотреть данные, ничего не меняя. Запись — создавать, менять, удалять и отправлять. «Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.") : t.text(PROTOCOL_TEXT[c.protocol as GatewayProtocol].modes)} {c.protocol !== "http" && <> {t("«Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.")}}

    {engineer && c.protocol === "http" && (
    {t("Тонкая настройка")}