import { withUser, parseBody, json } from "@/lib/api"; import { listPrompts, createPrompt, PROMPT_KINDS, type PromptKind } from "@/lib/prompts/service"; import { promptBodySchema } from "@/lib/prompts/schemas"; export const dynamic = "force-dynamic"; /** * GET /api/prompts?q=&kind=&folder=&tag=&favorite=1&projectId=&limit= * → { prompts, folders, tags, total }. `q` matches name, description, content and tags (used by the command palette). */ export const GET = withUser(async ({ req, user }) => { const p = new URL(req.url).searchParams; const kind = p.get("kind"); return json( await listPrompts(user.id, { q: p.get("q")?.trim() || undefined, kind: kind && (PROMPT_KINDS as readonly string[]).includes(kind) ? (kind as PromptKind) : undefined, folder: p.get("folder") ?? undefined, tag: p.get("tag") ?? undefined, favorite: p.get("favorite") === "1", projectId: p.get("projectId") ?? undefined, limit: p.get("limit") ? Number(p.get("limit")) : undefined, }), ); }); /** POST /api/prompts → 201 { prompt } */ export const POST = withUser(async ({ req, user }) => { const body = await parseBody(req, promptBodySchema); return json({ prompt: await createPrompt(user.id, body) }, { status: 201 }); });