"use client"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import { formatDateTime } from "@/lib/i18n/formats"; import type { PluginRecord } from "@/lib/types/plugins"; import { SETTINGS_TYPOGRAPHY } from "@/components/settings/settings-typography"; import { isPublicWebhook } from "./plugin-manifest-model"; /** * Read-only view of the plugin's manifest: identity, capabilities, declared * webhooks, and a collapsible raw JSON dump for anything the summary * rows don't surface. */ export function PluginManifestCard({ plugin }: { plugin: PluginRecord }) { const { t } = useTranslation(); const [showRaw, setShowRaw] = useState(false); return ( {t("plugins:manifest")}
{/* Row VALUES are manifest data — the plugin id, its version, its author — and are never translated. Only the row labels are copy. */}
({ key: w.key, text: isPublicWebhook(plugin.api_version, w.access) ? t("plugins:manifestWebhookPublic", { key: w.key }) : w.key, }))} /> {showRaw && (
            {JSON.stringify(manifestOnly(plugin), null, 2)}
          
)}
); } function ManifestRow({ label, value, mono }: { label: string; value: string; mono?: boolean }) { return (
{label} {value}
); } function CapabilityBadges({ plugin }: { plugin: PluginRecord }) { const { t } = useTranslation(); const caps = plugin.capabilities ?? {}; const badges: string[] = [ ...(caps.events ?? []).map((e) => `events:${e}`), ...(caps.api_read ?? []).map((r) => `read:${r}`), ...(caps.api_write ?? []).map((w) => `write:${w}`), ...(caps.state ? ["state"] : []), ...(caps.secrets ? ["secrets"] : []), ]; if (badges.length === 0) return null; return (
{/* The badges are permission scopes (`events:*`, `read:*`) — the contract the plugin declared, so they stay verbatim. */}
{t("plugins:manifestCapabilities")}
{badges.map((badge) => ( {badge} ))}
); } function DeclarationList({ label, items, }: { label: string; items: { key: string; text: string }[]; }) { if (items.length === 0) return null; return (
{label}
{items.map((item) => ( {item.text} ))}
); } /** The manifest-declared fields only — runtime bookkeeping (status, install * path, restart counter, and failure diagnostic) is shown elsewhere and just * noise here. */ function manifestOnly(plugin: PluginRecord): Record { const { status: _s, install_path: _i, restart_count: _r, installed_at: _a, last_error: _e, last_error_at: _ea, ...manifest } = plugin; return manifest; } function formatInstalledAt(installedAt: string): string { const date = new Date(installedAt); return Number.isNaN(date.getTime()) ? installedAt : formatDateTime(date); }