'use client' import { useState } from 'react' import { Globe, Search, ArrowRight, Loader2, ExternalLink, BookOpen } from 'lucide-react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' const QUICK_SEARCHES = [ { label: 'Latest AI News', query: 'latest AI agent developments 2025' }, { label: 'FastAPI Docs', query: 'https://fastapi.tiangolo.com' }, { label: 'Next.js 14', query: 'Next.js 14 app router best practices' }, { label: 'HuggingFace', query: 'https://huggingface.co' }, ] export default function BrowserPanel() { const [query, setQuery] = useState('') const [result, setResult] = useState('') const [loading, setLoading] = useState(false) const [history, setHistory] = useState([]) const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' const search = async (q?: string) => { const searchQuery = q || query.trim() if (!searchQuery || loading) return setLoading(true) setResult('') setHistory(prev => [searchQuery, ...prev.slice(0, 4)]) try { const resp = await fetch(`${apiUrl}/api/v1/browser/research`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: searchQuery, session_id: 'browser' }), }) if (resp.ok) { const data = await resp.json() setResult(data.result || '') } else { setResult('❌ Research failed. Check if the backend is running.') } } catch (e) { setResult('❌ Cannot reach backend. Make sure the API server is running.') } finally { setLoading(false) } } return (
{/* Header */}
Browser Agent Web Research
{/* Search bar */}
setQuery(e.target.value)} onKeyDown={e => e.key === 'Enter' && search()} placeholder="URL or search query..." className="w-full text-xs pl-7 pr-3 py-2 rounded-xl outline-none" style={{ background: 'var(--bg-3)', border: '1px solid var(--border)', color: 'var(--text-primary)', }} />
{/* Quick searches */}
{QUICK_SEARCHES.map(({ label, query: q }) => ( ))}
{/* Result */}
{loading ? (

Researching the web...

) : result ? (
{result}
) : (

Enter a URL or search query
to start web research

)}
{/* History */} {history.length > 0 && (

Recent:

{history.map((h, i) => ( ))}
)}
) }