import { z } from "zod"; import { withUser, parseBody, json } from "@/lib/api"; import { attachFiles } from "@/lib/library/service"; export const dynamic = "force-dynamic"; /** * POST /api/library/files/attach { fileIds: string[] } → { attachments: [{ id, kind, name, mimeType, sizeBytes, width, height }] } * Each library file is copied into `message_attachments` as a pending attachment (no message/conversation yet), * i.e. the same shape POST /api/attachments returns, so the composer can send the ids in `message.attachmentIds`. */ export const POST = withUser(async ({ req, user }) => { const body = await parseBody(req, z.object({ fileIds: z.array(z.string().max(64)).min(1).max(10) })); return json({ attachments: await attachFiles(user.id, body.fileIds) }, { status: 201 }); });