import { NextResponse } from "next/server"; import { loadBeadsData } from "@/lib/parse-beads"; import { discoverBeadsDir } from "@/lib/discover"; export async function GET() { try { const { beadsDir } = discoverBeadsDir(); const data = loadBeadsData(beadsDir); return NextResponse.json(data); } catch (error: any) { // Distinguish discovery errors (404) from data loading errors (500) if (error?.message?.includes("No .beads/ directory found")) { return NextResponse.json( { error: "No .beads directory found", hint: "Run bd init in your project, then start heartbeads from that directory", }, { status: 404 } ); } console.error("Failed to load beads data:", error); return NextResponse.json( { error: "Failed to load beads data" }, { status: 500 } ); } }