import { useState } from 'react' import { Link2, Search, Package, Loader2, CheckCircle2, XCircle } from 'lucide-react' interface UrlFlowResp { repo?: string type?: string found_model?: string | null workflow?: { pipeline?: string; steps?: number | null; guidance?: number | null; fps?: number | null; loras?: boolean; quantization?: boolean } examples?: Array<{ images?: string[]; prompt?: string; lora?: string }> installed?: boolean packet_space?: string url?: string imported_examples?: Array<{ images?: string[]; prompt?: string; lora?: string }> status?: string } export default function UrlQuickPanel({ onLog }: { onLog: (msg: string) => void }) { const [url, setUrl] = useState('') const [answer, setAnswer] = useState('') const [busy, setBusy] = useState(null) const run = async (mode: 'find' | 'install') => { if (!url.trim()) { setAnswer('Paste a URL first, e.g. https://huggingface.co/spaces/org/name'); return } setBusy(mode) setAnswer('') try { const res = await fetch('/api/urlflow', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url.trim(), mode }), }) const data: UrlFlowResp = await res.json() if (!res.ok) { setAnswer(`✗ ${(data as unknown as { detail?: string }).detail ?? 'request failed'}`) onLog(`URL flow ${mode} failed: ${(data as unknown as { detail?: string }).detail ?? res.status}`) return } const lines: string[] = [] lines.push(`REPO ${data.repo} (${data.type})`) lines.push(`MODEL ${data.found_model ?? 'no recipe match (found nothing usable yet)'}`) const wf = data.workflow ?? {} lines.push(`WORKFLOW pipeline=${wf.pipeline ?? '?'} steps=${wf.steps ?? '?'} guidance=${wf.guidance ?? '?'} fps=${wf.fps ?? '?'} lora=${wf.loras ? 'yes' : 'no'} quant=${wf.quantization ? 'yes' : 'no'}`) const exs = data.examples ?? [] lines.push(`EXAMPLES found ${exs.length}`) exs.slice(0, 6).forEach(e => lines.push(` - ${(e.images ?? []).join(', ')} ${e.prompt ? '| ' + e.prompt.slice(0, 80) : ''}`)) if (data.installed) { const imp = data.imported_examples ?? [] lines.push(`PACKET INSTALLED ${imp.length} example(s)`) lines.push(`SPACE ${data.packet_space ?? ''} ${data.url ?? ''}`) } else if (mode === 'find') { lines.push('') lines.push('Then press "Install as whole packet" to package all found examples into one private Space.') } setAnswer(lines.join('\n')) if (data.installed) onLog(`Whole packet installed -> ${data.url}`) } catch (e) { setAnswer('✗ ' + String(e)) onLog('URL flow error: ' + e) } finally { setBusy(null) } } return (
URL Quick · 2 windows
setUrl(e.target.value)} placeholder="https://huggingface.co/spaces/org/name" className="w-full bg-[#0A0A0A] border border-[#2E2E2E] rounded-lg px-3 py-2 text-xs text-white placeholder:text-[#5A5A5A] outline-none focus:border-[#FF9D00]" />
            {answer || '…'}
          
) }