// POST /api/seed/turn // // Per-turn handler for the live seed interview. Stateless — client passes // the running thread + draft + user text; we return the next assistant turn // + an updated draft + a `ready` flag. import { NextResponse } from "next/server"; import { interviewStep, type InterviewTurn, type SeedDraft } from "../../../../lib/llm/seedInterview"; export async function POST(req: Request) { let body: { history?: InterviewTurn[]; userText?: string; draft?: SeedDraft }; try { body = await req.json(); } catch { return NextResponse.json({ error: "invalid json body" }, { status: 400 }); } const history = Array.isArray(body.history) ? body.history : []; const draft: SeedDraft = body.draft ?? { title: "", problem: "", targetUser: "", desiredOutcome: "", }; const userText = body.userText ?? ""; try { const result = await interviewStep({ history, userText, draft }); return NextResponse.json({ assistant: { text: result.text }, draft: result.draft, confidence: result.confidence, ready: result.ready, meta: { provider: result.provider, model: result.model, inputTokens: result.inputTokens, outputTokens: result.outputTokens, }, }); } catch (err) { return NextResponse.json({ error: (err as Error).message }, { status: 500 }); } }