import { NextRequest, NextResponse } from 'next/server' import { getAllToolsComplete } from '@/lib/tools/index' /** * GET /api/v1/tools * List all available AI tools with their metadata. * No authentication required. * * Query params: * category - filter by category * q - search term * limit - max results (default: 50, max: 200) */ export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url) const category = searchParams.get('category') || '' const q = searchParams.get('q')?.toLowerCase() || '' const limit = Math.min(200, Math.max(1, parseInt(searchParams.get('limit') || '50'))) let tools = getAllToolsComplete() if (category) { tools = tools.filter((t) => t.category.toLowerCase() === category.toLowerCase()) } if (q) { tools = tools.filter( (t) => t.name.toLowerCase().includes(q) || t.description.toLowerCase().includes(q) || t.category.toLowerCase().includes(q), ) } const limited = tools.slice(0, limit) return NextResponse.json({ data: limited.map((t) => ({ slug: t.slug, name: t.name, description: t.description, category: t.category, icon: t.icon, isPremium: t.isPremium ?? false, })), total: limited.length, totalAll: tools.length, }, { headers: { 'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=86400', }, }) } catch (error) { console.error('GET /api/v1/tools error:', error) return NextResponse.json({ error: 'Internal server error' }, { status: 500 }) } }