← back to ClawCoder

src/app/api/profiles/route.ts

34 lines

import { NextResponse } from 'next/server'
import { PROFILES, getProfile, getProfilesByAge, getProfilesBySkill } from '@/lib/profiles/data'
import type { AgeGroup, SkillLevel } from '@/lib/profiles/types'

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url)
  const slug = searchParams.get('slug')
  const age = searchParams.get('age')
  const skill = searchParams.get('skill')

  if (slug) {
    const profile = getProfile(slug)
    return profile
      ? NextResponse.json(profile)
      : NextResponse.json({ error: 'Profile not found' }, { status: 404 })
  }
  if (age) return NextResponse.json(getProfilesByAge(age as AgeGroup))
  if (skill) return NextResponse.json(getProfilesBySkill(skill as SkillLevel))

  // Return summary (not full template content) for listing
  const summaries = PROFILES.map(p => ({
    slug: p.slug,
    ageGroup: p.ageGroup,
    skillLevel: p.skillLevel,
    displayName: p.displayName,
    persona: p.persona,
    ui: p.ui,
    skillCount: p.skillBundle.length,
    mcpCount: p.mcpServers.length,
    subagentCount: p.subagents.length,
  }))
  return NextResponse.json(summaries)
}