import { useCallback } from 'react'; import { type ScreenIntelligenceState, useScreenIntelligenceState, } from '../../features/screen-intelligence/useScreenIntelligenceState'; import { useT } from '../../lib/i18n/I18nContext'; const formatBytes = (bytes: number | null | undefined): string => { if (bytes == null) return '-'; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; }; interface ScreenIntelligenceDebugPanelProps { state?: Pick< ScreenIntelligenceState, | 'status' | 'captureTestResult' | 'isCaptureTestRunning' | 'recentVisionSummaries' | 'lastError' | 'refreshStatus' | 'refreshVision' | 'runCaptureTest' >; } const ScreenIntelligenceDebugPanelContent = ({ state: providedState, }: Required>) => { const { t } = useT(); const { status, captureTestResult, isCaptureTestRunning, recentVisionSummaries, lastError, refreshStatus, refreshVision, runCaptureTest, } = providedState; const handleCaptureTest = useCallback(() => { void runCaptureTest(); }, [runCaptureTest]); const handleRefreshStatus = useCallback(() => { void refreshStatus(); void refreshVision(5); }, [refreshStatus, refreshVision]); const permissions = status?.permissions; const session = status?.session; return (

{t('intelligence.screenDebug.title')}

{/* Permissions */}

{t('intelligence.screenDebug.permissions')}

{status?.platform_supported === false ? (

{t('intelligence.screenDebug.platformNotSupported')}

) : (
)}
{/* Session Status */}

{t('intelligence.screenDebug.session')}

{t('intelligence.screenDebug.active')} {session?.active ? t('common.yes') : t('common.no')}
{t('intelligence.screenDebug.frames')} {session?.frames_in_memory ?? 0}
{t('intelligence.screenDebug.visionState')} {session?.vision_state ?? t('intelligence.screenDebug.idle')}
{t('intelligence.screenDebug.visionQueue')} {session?.vision_queue_depth ?? 0}
{session?.last_context && (
{t('intelligence.screenDebug.lastApp')} {session.last_context}
)}
{/* Capture Test */}

{t('intelligence.screenDebug.captureTest')}

{captureTestResult && (
{t('intelligence.screenDebug.status')} {captureTestResult.ok ? t('intelligence.screenDebug.captureSuccess') : t('intelligence.screenDebug.captureFailed')}
{t('intelligence.screenDebug.mode')} {captureTestResult.capture_mode}
{t('intelligence.screenDebug.time')} {captureTestResult.timing_ms}ms
{captureTestResult.bytes_estimate != null && (
{t('intelligence.screenDebug.size')} {formatBytes(captureTestResult.bytes_estimate)}
)} {captureTestResult.context && (
{t('intelligence.screenDebug.app')} {captureTestResult.context.app_name ?? t('intelligence.screenDebug.unknown')}
)} {captureTestResult.context?.bounds_width != null && (
{t('intelligence.screenDebug.bounds')} {captureTestResult.context.bounds_width}x {captureTestResult.context.bounds_height} at ( {captureTestResult.context.bounds_x},{captureTestResult.context.bounds_y})
)}
{captureTestResult.error && (
{captureTestResult.error}
)} {captureTestResult.image_ref && (
{t('intelligence.screenDebug.captureAlt')}
)}
)}
{/* Recent Vision Summaries */} {recentVisionSummaries.length > 0 && (

{t('intelligence.screenDebug.recentVisionSummaries')}

{recentVisionSummaries.map(summary => (
{summary.app_name ?? t('intelligence.screenDebug.unknown')} {new Date(summary.captured_at_ms).toLocaleTimeString()} ·{' '} {(summary.confidence * 100).toFixed(0)}%
{summary.actionable_notes}
))}
)} {/* Error Display */} {lastError && (
{lastError}
)}
); }; const OwnedScreenIntelligenceDebugPanel = () => { const state = useScreenIntelligenceState({ loadVision: true, visionLimit: 5, pollMs: 2000 }); return ; }; const ScreenIntelligenceDebugPanel = ({ state }: ScreenIntelligenceDebugPanelProps) => { if (state) { return ; } return ; }; const PermissionDot = ({ label, value }: { label: string; value?: string }) => { const color = value === 'granted' ? 'bg-green-500' : value === 'denied' ? 'bg-red-500' : 'bg-stone-600'; return (
{label}
); }; export default ScreenIntelligenceDebugPanel;