import React, { useMemo } from 'react'; import { X, Cpu, Copy, ArrowRight } from '../icons'; import { useToast } from './Toasts/useToast'; export interface OrchestratorInspectorEntry { uuid: string; ts: string; kind: 'traffic' | 'file' | 'email' | string; protocol: string; action: string; src_decky_uuid: string | null; dst_decky_uuid: string; success: boolean; payload: string; // Email-only extras populated when `kind === 'email'`. subject?: string; sender_email?: string; recipient_email?: string; language?: string; thread_id?: string; mail_decky_uuid?: string; message_id?: string; in_reply_to?: string | null; } interface Props { event: OrchestratorInspectorEntry; onClose: () => void; } const renderDeckyId = (id: string | null): string => id ?? '—'; const sourceTag = (id: string | null): 'topology' | 'fleet' | 'shard' | null => { if (!id) return null; // Composite "host_uuid:name" identifies fleet/shard rows; // bare UUIDs (8-4-4-4-12) are MazeNET TopologyDecky.uuid. if (id.includes(':')) return id.startsWith('local:') ? 'fleet' : 'shard'; return /^[0-9a-f]{8}-/i.test(id) ? 'topology' : null; }; const OrchestratorInspector: React.FC = ({ event, onClose }) => { const { push } = useToast(); const prettyPayload = useMemo(() => { try { return JSON.stringify(JSON.parse(event.payload), null, 2); } catch { return event.payload; } }, [event.payload]); const copy = async (text: string, label: string) => { try { await navigator.clipboard.writeText(text); push({ text: `${label} COPIED`, tone: 'matrix', icon: 'copy' }); } catch { push({ text: 'CLIPBOARD BLOCKED', tone: 'alert', icon: 'alert-triangle' }); } }; const copyEvent = () => copy(JSON.stringify(event, null, 2), 'EVENT JSON'); const copyPayload = () => copy(prettyPayload, 'PAYLOAD JSON'); const kindCls = event.kind === 'traffic' || event.kind === 'file' || event.kind === 'email' ? event.kind : ''; const isEmail = event.kind === 'email'; const srcSrc = sourceTag(event.src_decky_uuid); const dstSrc = sourceTag(event.dst_decky_uuid); const isLive = event.uuid.startsWith('live-'); return (
{ if (e.target === e.currentTarget) onClose(); }} >

{isLive ? 'LIVE EVENT' : `EVENT #${event.uuid.slice(0, 8)}`} {event.kind.toUpperCase()}

TS
{new Date(event.ts).toLocaleString()}
PROTOCOL
{event.protocol.toUpperCase()}
{isEmail ? 'SUBJECT' : 'ACTION'}
{event.action}
{isEmail && event.language && ( <>
LANGUAGE
{event.language.toUpperCase()}
)} {isEmail && event.thread_id && ( <>
THREAD
{event.thread_id}
)} {isEmail && event.in_reply_to && ( <>
IN-REPLY-TO
{event.in_reply_to}
)} {isEmail && event.mail_decky_uuid && ( <>
MAIL DECKY
{event.mail_decky_uuid}
)}
OUTCOME
{event.success ? '✓ SUCCESS' : '✗ FAILURE'}
SRC
{event.src_decky_uuid ? ( {renderDeckyId(event.src_decky_uuid)} {srcSrc && {srcSrc.toUpperCase()}} ) : ( )}
{renderDeckyId(event.dst_decky_uuid)} {dstSrc && {dstSrc.toUpperCase()}}
{!isLive && ( <>
EVENT UUID
{event.uuid}
)}
PAYLOAD
{prettyPayload}
EXPORT
); }; export default OrchestratorInspector;