Spaces:
Build error
Build error
import type { RequestHandler } from './$types'; | |
import { collections } from '$lib/server/database'; | |
import { ObjectId } from 'mongodb'; | |
export const POST: RequestHandler = async (input) => { | |
const res = await collections.conversations.insertOne({ | |
_id: new ObjectId(), | |
title: | |
'Untitled ' + | |
((await collections.conversations.countDocuments({ sessionId: input.locals.sessionId })) + 1), | |
messages: [], | |
createdAt: new Date(), | |
updatedAt: new Date(), | |
sessionId: input.locals.sessionId | |
}); | |
return new Response( | |
JSON.stringify({ | |
conversationId: res.insertedId.toString() | |
}), | |
{ headers: { 'Content-Type': 'application/json' } } | |
); | |
}; | |