// Desktop panel (#2547): manages a guest desktop session through the Bridge // control API. Effective capabilities are the backend `policy`; there is no // renderer, observer simulation, or terminal replay in this build. import { useDesktopSession, STATUS_TEXT, requestedMode, type DesktopStatus } from '../useDesktopSession'; import type { DesktopPolicy } from '../../../bridge/src/desktop-contract.mjs'; import { fmtId } from '../util'; const NO_TRANSPORT = 'Display transport is not available in this build'; const STATUS_LABEL: Record = { loading: 'loading', not_ready: 'not ready', unavailable: 'unavailable', idle: 'ready', live: 'live', reconnecting: 'reconnecting', disconnected: 'disconnected', expired: 'expired', denied: 'denied', 'guest-ended': 'guest ended', failed: 'failed', stale: 'stale', handoff_waiting: 'handoff waiting', closing: 'closing', }; const POLICY_ROWS: Array<[keyof DesktopPolicy, string]> = [ ['observe', 'Observe'], ['control', 'Control'], ['sharing', 'Sharing'], ['clipboard_copy', 'Clipboard copy'], ['clipboard_paste', 'Clipboard paste'], ['file_transfer', 'File transfer'], ['audio', 'Audio'], ['recording', 'Recording'], ['isolation_tier', 'Isolation tier'], ['generation', 'Policy generation'], ]; function policyValue(value: DesktopPolicy[keyof DesktopPolicy]): string { if (typeof value === 'boolean') return value ? 'granted' : 'not granted'; return String(value); } export function Desktop({ instanceId, onBack, pollMs, backoffMs }: { instanceId: string; onBack: () => void; pollMs?: number; backoffMs?: number }) { const { state, connect, disconnect, reconnect, close, retry } = useDesktopSession(instanceId, pollMs, backoffMs); const { status, reason, capability, session, cleanup } = state; const policy = session?.policy ?? capability?.policy ?? null; const mode = requestedMode(capability); const hasSession = session !== null; const sessionOpen = hasSession && !['guest-ended', 'expired', 'stale', 'denied', 'failed'].includes(status) && session?.state !== 'closed'; return (

Desktop {fmtId(instanceId)}

Guest desktop session managed through the Bridge control API. {NO_TRANSPORT}.

{STATUS_LABEL[status]}{' '} {STATUS_TEXT[status]}{reason ? ` ${reason}` : ''}

{session && (
Session
{fmtId(session.id)}
Guest state
{session.state}
Cleanup
{cleanup ?? 'none'}
VM incarnation
{session.incarnation}
Expires
{new Date(session.absolute_expires_at).toLocaleString()}
{session.retained_until && <>
Retained until
{new Date(session.retained_until).toLocaleString()}
}
)} {policy && (

Effective capabilities (from backend)

    {POLICY_ROWS.map(([key, label]) => (
  • {label}: {policyValue(policy[key])}
  • ))}
)}
{status === 'not_ready' && } {status === 'idle' && ( )} {policy?.observe && ( )} {policy?.control && ( )} {sessionOpen && (status === 'live' || status === 'reconnecting' || status === 'handoff_waiting' || status === 'loading') && ( )} {sessionOpen && status === 'disconnected' && ( )} {sessionOpen && status !== 'closing' && ( <> )} {status === 'stale' && }
); }