import { withUser, parseBody, json } from "@/lib/api"; import { LIMITS } from "@/lib/rate-limit"; import { chatAdoptSchema } from "@/lib/chat/schemas"; import { adoptMessage, toPublicMessage } from "@/lib/chat/service"; import { toPublicConversation } from "@/lib/conversations/service"; export const dynamic = "force-dynamic"; /** * POST /api/chat/adopt — "Continue with this model" from an inline Compare / Arena run. * Body: { conversationId?, modelKey, arenaResponseId? | content, userText?, systemPrompt?, settings?, projectId? } * → 201 { conversation, userMessage | null, message, isNewConversation } */ export const POST = withUser( async (ctx) => { const input = await parseBody(ctx.req, chatAdoptSchema, 1_000_000); const res = await adoptMessage({ userId: ctx.user.id, requestId: ctx.requestId, ip: ctx.ip }, input); return json({ conversation: toPublicConversation(res.conversation), userMessage: res.userMessage ? toPublicMessage(res.userMessage) : null, message: toPublicMessage(res.message), isNewConversation: res.isNewConversation }, { status: 201 }); }, { limit: { ...LIMITS.chat, key: "chat-adopt" } }, );