import { createDocument, deserializeTags, type AgentDocumentType } from "../../service/agent-document"; import { requireUser } from "#server/utils/context"; import { validate } from "#server/utils/validation"; import { z } from "zod"; const createSchema = z.object({ title: z.string().min(1).max(200), content: z.string().min(1).max(50000), type: z.enum(["memory", "document"]).optional(), tags: z.array(z.string()).optional(), sessionId: z.string().optional(), }); export default defineWrappedResponseHandler(async (event) => { const user = await requireUser(event); const body = await validate(createSchema, await readBody(event)); const created = await createDocument({ userId: user.id, sessionId: body.sessionId ?? null, type: body.type as AgentDocumentType | undefined, title: body.title, content: body.content, tags: body.tags ?? null, }); return R.success({ ...created, tags: deserializeTags(created.tags), }); });