import { listChatSessions, createChatSession } from '@/lib/runtime.js';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function GET() {
  return Response.json({ sessions: listChatSessions(50) });
}

export async function POST(req) {
  let body = {};
  try { body = await req.json(); } catch {}
  const session = createChatSession({ title: body.title ?? null, model: body.model ?? null });
  return Response.json({ session });
}
