/**
 * POST /api/chat/sessions/<id>/messages → 202 { topic }
 *
 * Proxied to chat-standalone (port 8408), which runs the agent loop
 * asynchronously and fanouts events to both the browser bridge
 * (`chat:<session_id>`) and local SSE subscribers.
 */

import { proxyToChat } from '@/lib/chat/proxy';

export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  return proxyToChat(req, `/api/sessions/${encodeURIComponent(id)}/messages`);
}

// DELETE drops all messages but keeps the session row (used by the main
// chat's "clear" button — main session can't be deleted, only cleared).
export async function DELETE(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  return proxyToChat(req, `/api/sessions/${encodeURIComponent(id)}/messages`);
}
