import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { analyzeSpace, deleteBuild, downloadUrl, getBuild, getLogs, startBuild } from "./api/client"; import { ModeBadge } from "./components/ModeBadge"; import { MODES, TARGET_META, TARGET_ORDER } from "./components/targets"; import type { AnalyzeResponse, BuildStatus, TargetInfo } from "./types"; const PROJECT_TARGETS = new Set(["tauri", "linux_appimage", "android", "arch_pkgbuild"]); function fmtSize(n: number) { return n >= 1048576 ? `${(n / 1048576).toFixed(2)} MB` : `${(n / 1024).toFixed(1)} KB`; } function hw(h: unknown): string { if (!h) return "unknown"; if (typeof h === "object") { const o = h as { current?: string; requested?: string }; return o.current || o.requested || "unknown"; } return String(h); } function modeLabel(m?: string) { return MODES.find((x) => x.id === m)?.label || m || "—"; } export default function App() { const [url, setUrl] = useState("https://huggingface.co/spaces/gradio/hello_world"); const [token, setToken] = useState(""); const [analyzing, setAnalyzing] = useState(false); const [building, setBuilding] = useState(false); const [error, setError] = useState(null); const [analysis, setAnalysis] = useState(null); const [mode, setMode] = useState("hybrid"); const [target, setTarget] = useState(null); const [build, setBuild] = useState(null); const [logs, setLogs] = useState(""); const cancelled = useRef(false); const targets: TargetInfo[] = useMemo(() => { const ts = analysis?.compatibility.targets || []; return [...ts].sort((a, b) => TARGET_ORDER.indexOf(a.id) - TARGET_ORDER.indexOf(b.id)); }, [analysis]); const modeEnabled = (m: string) => targets.some((t) => t.available && t.mode === m); useEffect(() => { const t = targets.find((x) => x.id === target); if (t && t.mode !== mode) setTarget(null); }, [mode, target, targets]); const onAnalyze = useCallback(async () => { setError(null); setBuild(null); setLogs(""); setTarget(null); setAnalyzing(true); try { const res = await analyzeSpace(url.trim(), token.trim() || undefined); setAnalysis(res); const firstMode = ["hybrid", "hosted_wrapper", "local"].find((m) => res.compatibility.targets.some((t) => t.available && t.mode === m)); if (firstMode) setMode(firstMode); } catch (e) { setAnalysis(null); setError(`Analyze failed: ${e instanceof Error ? e.message : String(e)}`); } finally { setAnalyzing(false); } }, [url, token]); const onBuild = useCallback(async () => { if (!target) return; setError(null); setBuilding(true); setLogs(""); cancelled.current = false; try { const { build_id } = await startBuild(url.trim(), target, mode, token.trim() || undefined); let st = await getBuild(build_id); setBuild(st); while ((st.status === "queued" || st.status === "running") && !cancelled.current) { await new Promise((r) => setTimeout(r, 1200)); st = await getBuild(build_id); setBuild(st); setLogs(await getLogs(build_id)); } if (!cancelled.current) setLogs(await getLogs(build_id)); } catch (e) { setError(`Build failed: ${e instanceof Error ? e.message : String(e)}`); } finally { setBuilding(false); } }, [url, target, mode, token]); const onDiscard = useCallback(async () => { if (!build) return; cancelled.current = true; try { await deleteBuild(build.id); setBuild(null); setLogs(""); } catch (e) { setError(`Delete failed: ${e instanceof Error ? e.message : String(e)}`); } }, [build]); const space = analysis?.space; const mf = analysis?.manifest && !analysis.manifest.error ? analysis.manifest : undefined; const pct = Math.round((build?.progress ?? 0) * 100); return (
⬢

SpaceForge

Turn Hugging Face Spaces into Apps

{error ?
{error}
: null}
setUrl(e.target.value)} placeholder="https://huggingface.co/spaces/owner/name" />
setToken(e.target.value)} autoComplete="off" placeholder="Optional HF token for private Spaces (used per request, never stored or bundled)" aria-label="HF token" />
{space ? (
{space.emoji}

{space.title}

{space.repo_id}{space.short_description ? ` · ${space.short_description}` : ""}

Detected

SDK: {space.sdk}{space.sdk_version ? ` ${space.sdk_version}` : ""} Language: {mf?.runtime.language || "unknown"} {space.needs_gpu ? "GPU" : "CPU"} · {hw(space.hardware)} {space.private ? "Private" : "Public"} Runtime: {space.runtime_stage} {mf?.runtime.port ? Port {mf.runtime.port} : null} {mf?.runtime.entrypoint ? Entry: {mf.runtime.entrypoint} : null} {mf?.license ? License: {mf.license} : null}
{mf ? (
{mf.requirements.secrets.length ?
⚠ This Space reads secrets/env vars: {mf.requirements.secrets.join(", ")}. SpaceForge never bundles secrets into packages — the live Space must keep them.
: null} {mf.requirements.models.length ?
Models {mf.requirements.models.join(", ")}
: null} {mf.requirements.datasets.length ?
Datasets {mf.requirements.datasets.join(", ")}
: null} {mf.requirements.heavy_ml ?
ML stack heavy (torch/transformers…) — not packaged locally
: null}
Files scanned {mf.files_detected.join(", ") || "—"}
Internet needed {mf.requirements.internet ? "yes" : "no"}
) : null} {analysis!.compatibility.warnings.map((w) =>
⚠ {w}
)}

Compatibility matrix

{MODES.map((m) => )}{targets.map((t) => ( {MODES.map((m) => )}))}
Target{m.label}
{TARGET_META[t.id]?.label || t.label} {t.mode === m.id ? (t.available ? "✓" : "soon") : "—"}
Each package type has exactly one honest delivery mode; "—" means that combination is not offered.
) : null} {analysis ? (

Conversion mode

{MODES.map((m) => { const en = modeEnabled(m.id); return ( ); })}

Target

{targets.map((t) => { const meta = TARGET_META[t.id]; const inMode = t.mode === mode; const dis = !t.available || !inMode; return ( ); })}
{!target ? Select a target first. : null}
) : null} {build ? (

Build {build.id} — {build.status}

{build.stage || build.status} · {pct}%
{logs ?
{logs.trim().split("\n").map((l) => {
            const bad = /error|timeout|failed|Blocked|status=error/i.test(l);
            const ok = /ok →|finished status=done/.test(l);
            return `${bad ? "✗" : ok ? "✓" : "·"} ${l}`;
          }).join("\n")}
: null} {Object.entries(build.errors).map(([tid, err]) => (
{TARGET_META[tid]?.label || tid} failed: {err}
))} {Object.entries(build.artifacts).map(([tid, a]) => { const project = a.artifact_kind === "project-zip" && PROJECT_TARGETS.has(tid); return (
{a.filename}
≈ {fmtSize(a.size)} · {TARGET_META[tid]?.label || tid} · mode: {" "}· {project ? Buildprojekt (no binary — build on your machine) : a.binary_included ? "binary" : "ZIP package"}
{a.notes ?
{a.notes}
: null}
Source: {space?.repo_id} · License: {mf?.license || "not declared — check the Space before redistributing"} · Expires {new Date(build.expires_at * 1000).toLocaleTimeString()}
{a.mode !== "local" ?
Needs internet: loads the live Space ({space?.embed_url}).
: null}
Download
); })} {build.status !== "queued" && build.status !== "running" ? ( ) : null}
) : null}
); }