Problem
/api/ai maps history entries blindly (m.role, m.content); [null] throws and {role: "user"} forwards the literal string "undefined" upstream. Only prompt is validated.
Where
app/api/ai/route.ts (history mapping).
Acceptance
Add a failing test first POSTing {prompt: "hi?", history: [null]} asserting 400 with a structured error. Then fix.
Problem
/api/aimapshistoryentries blindly (m.role,m.content);[null]throws and{role: "user"}forwards the literal string"undefined"upstream. Onlypromptis validated.Where
app/api/ai/route.ts(history mapping).Acceptance
Add a failing test first POSTing
{prompt: "hi?", history: [null]}asserting 400 with a structured error. Then fix.