diff --git a/lib/transcriptParser.js b/lib/transcriptParser.js index 32280ff..63484ee 100644 --- a/lib/transcriptParser.js +++ b/lib/transcriptParser.js @@ -99,6 +99,23 @@ export async function storeMessagesForSession(sessionId, messages) { await prisma.message.createMany({ data: messageData, }); + + // Extract actual end time from the latest message + const latestMessage = messages.reduce((latest, current) => { + return new Date(current.timestamp) > new Date(latest.timestamp) ? current : latest; + }); + + // Update the session's endTime with the actual conversation end time + await prisma.session.update({ + where: { id: sessionId }, + data: { + endTime: new Date(latestMessage.timestamp), + }, + }); + + process.stdout.write( + `[TranscriptParser] Updated session ${sessionId} endTime to ${latestMessage.timestamp}\n` + ); } process.stdout.write(