"use client"; import { useState } from "react"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import type { PluginRecord } from "@/lib/types/plugins"; /** * 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 [showRaw, setShowRaw] = useState(false); return ( Manifest
({ key: w.key, text: 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 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 (
Capabilities
{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) is shown elsewhere and just noise here. */ function manifestOnly(plugin: PluginRecord): Record { const { status: _s, install_path: _i, restart_count: _r, installed_at: _a, ...manifest } = plugin; return manifest; } function formatInstalledAt(installedAt: string): string { const date = new Date(installedAt); return Number.isNaN(date.getTime()) ? installedAt : date.toLocaleString(); }