import React, { useState, useEffect } from 'react'; import { Play, Download, Monitor, Eye, EyeOff, Sparkles, ArrowRight } from 'lucide-react'; import { WebSocketManager } from '../services/WebSocketManager'; const API_BASE_URL = 'http://localhost:8000'; interface JobFormProps { wsManager: WebSocketManager; onJobCreated: (data: { jobId: string; streaming: boolean; format: string }) => void; } export const JobForm: React.FC = ({ wsManager, onJobCreated }) => { const [prompt, setPrompt] = useState('Navigate to Hacker News and extract the top 10 stories as JSON with titles, URLs, and scores'); const [format, setFormat] = useState('json'); const [headless, setHeadless] = useState(false); const [streaming, setStreaming] = useState(true); const [currentJobId, setCurrentJobId] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); const [detectedFormat, setDetectedFormat] = useState(null); const [isHovered, setIsHovered] = useState(false); useEffect(() => { const detected = detectFormatFromPrompt(prompt); setDetectedFormat(detected); }, [prompt]); const detectFormatFromPrompt = (text: string): string | null => { const lower = text.toLowerCase(); const patterns = { pdf: [/\bpdf\b/, /pdf format/, /save.*pdf/, /as pdf/, /to pdf/], csv: [/\bcsv\b/, /csv format/, /save.*csv/, /as csv/, /to csv/], json: [/\bjson\b/, /json format/, /save.*json/, /as json/, /to json/], html: [/\bhtml\b/, /html format/, /save.*html/, /as html/, /to html/], md: [/\bmarkdown\b/, /md format/, /save.*markdown/, /as markdown/, /to md/], txt: [/\btext\b/, /txt format/, /save.*text/, /as text/, /to txt/, /plain text/] }; for (const [fmt, regexes] of Object.entries(patterns)) { if (regexes.some(regex => regex.test(lower))) { return fmt; } } return null; }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!prompt.trim() || isSubmitting) return; setIsSubmitting(true); const finalFormat = detectedFormat || format; try { const response = await fetch(`${API_BASE_URL}/job`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt, format: finalFormat, headless, enable_streaming: streaming }) }); const data = await response.json(); setCurrentJobId(data.job_id); onJobCreated({ jobId: data.job_id, streaming, format: finalFormat }); } catch (error) { console.error('Error creating job:', error); } finally { setIsSubmitting(false); } }; const handleDownload = async () => { if (!currentJobId) return; try { const response = await fetch(`${API_BASE_URL}/download/${currentJobId}`); if (response.ok) { const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `browserpilot_result_${currentJobId}.${format}`; a.click(); window.URL.revokeObjectURL(url); } } catch (error) { console.error('Download error:', error); } }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} >

Create Automation Task

Describe what you want to accomplish, and BrowserPilot will handle the rest

{/* Task Description */}