'use client'; import { useEffect, useState } from 'react'; import { ToolCheckResult } from '@/lib/tool-check'; import { RefreshCw, AlertTriangle, CheckCircle } from 'lucide-react'; export function ToolChecker({ children }: { children: React.ReactNode }) { const [result, setResult] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [skipped, setSkipped] = useState(false); const checkTools = async () => { setLoading(true); setError(null); try { const res = await fetch('/api/system/check-tools'); if (!res.ok) { throw new Error('Failed to check tools'); } const data: ToolCheckResult = await res.json(); setResult(data); } catch (err) { setError('Failed to communicate with the server.'); } finally { setLoading(false); } }; useEffect(() => { checkTools(); }, []); const handleSkip = () => { if (confirm("WARNING: Skipping these checks may cause the application to fail or produce corrupt files. Are you sure you want to proceed without the required tools?")) { setSkipped(true); } }; if (loading) { return (

Checking system prerequisites...

); } if (error) { return (

System Check Failed

{error}

); } if (result && !result.allExists && !skipped) { return (

System Check Failed

{result.mkbrrPresetExists === false ? 'The required "red" preset for mkbrr is missing.' : 'Some required CLI tools are missing from your system. Please install them to continue.'}

{result.tools.map((tool) => (
{tool.name}
{tool.exists ? (
Installed
) : (
Missing
)}
))} {result.mkbrrPresetExists === false && (
mkbrr preset: red
Missing

Please create the preset by following the documentation.

View Documentation
)}
); } return <>{children}; }