import { useState, type FormEvent } from 'react' import { ExternalLink, RefreshCw, Terminal, X } from 'lucide-react' import type { Agent, FeedEntry, GpuStatus, NodeDetail, TerminalLine, TopologyNode, WorkloadData } from '../../types' import { AGENT_NODE } from '../../lib/constants' import { getAgentMeta } from '../../lib/agentMeta' import { copyShellCommand, resolveInfraNode } from '../../lib/infraCatalog' import { Button } from '../ui/Button' import { Card, CardDescription, CardTitle } from '../ui/Card' import { Input } from '../ui/Input' import { cn } from '../../lib/utils' type Tab = 'overview' | 'apps' | 'terminal' type Props = { node: TopologyNode | null nodeDetail: NodeDetail | null agent: Agent | null agents: Agent[] workload: WorkloadData | null gpu: GpuStatus | null feed: FeedEntry[] lines: TerminalLine[] busy: boolean onProbe: () => void onAsk: (message: string) => void onSelectAgent: (id: string) => void onSendPrompt: (message: string, agentId?: string) => void onClear: () => void onOpenTerminal: (nodeId: string) => void onProbeNodeId: (nodeId: string) => void } export function InspectorPanel({ node, nodeDetail, agent, agents, workload, gpu, feed, lines, busy, onProbe, onAsk, onSelectAgent, onSendPrompt, onClear, onOpenTerminal, onProbeNodeId, }: Props) { const [tab, setTab] = useState('overview') const [input, setInput] = useState('') const [shellCopied, setShellCopied] = useState(false) const d = nodeDetail || node const infra = resolveInfraNode(d?.id || null) const linkedAgent = d ? agents.find((a) => a.id === d.id || AGENT_NODE[a.id] === d.id || a.id === infra?.agentId || a.zone === d.id) : agent const submit = (e: FormEvent) => { e.preventDefault() if (!input.trim() || busy) return onAsk(input.trim()) setInput('') setTab('terminal') if (d?.id) onOpenTerminal(d.id) } const runShell = async () => { if (!infra) return await copyShellCommand(infra.ssh) setShellCopied(true) setTimeout(() => setShellCopied(false), 2000) onOpenTerminal(infra.id) onProbeNodeId(infra.id) setTab('terminal') } return ( ) } function Stat({ label, value, ok }: { label: string; value: string; ok?: boolean }) { return (

{label}

{value}

) }