import { Hono } from 'hono'; import * as webService from '../services/scraper'; const app = new Hono(); // Scrape a URL and extract text content app.post('/scrape', async (c) => { try { const { url, selector } = await c.req.json(); if (!url) { return c.json({ error: 'url required' }, 400); } const result = await webService.scrapeUrl(url, selector); return c.json(result); } catch (error: any) { console.error('[Web] Scrape error:', error.message); const msg = error.message?.includes('private') ? error.message : 'Scrape failed'; return c.json({ error: msg }, 500); } }); // Web search using DuckDuckGo HTML app.get('/search', async (c) => { try { const q = c.req.query('q'); const limit = c.req.query('limit') || '5'; if (!q) { return c.json({ error: 'q (query) parameter required' }, 400); } const parsedLimit = Math.min(Math.max(parseInt(limit) || 5, 1), 20); const result = await webService.searchDuckDuckGo(String(q), parsedLimit); return c.json(result); } catch (error: any) { console.error('[Web] Search error:', error.message); return c.json({ error: 'Search failed' }, 500); } }); // Agentic browse endpoint app.post('/browse', async (c) => { try { const { url } = await c.req.json(); if (!url) { return c.json({ error: 'url required' }, 400); } const result = await webService.agentBrowse(url); return c.json(result); } catch (error: any) { console.error('[Web] Browse error:', error.message); const msg = error.message?.includes('private') ? error.message : 'Browse failed'; return c.json({ error: msg }, 500); } }); export default app;