Implement AI chat history system with enhanced memory (Phases 1 & 2)
Phase 1 - Database Schema & Basic API: - Add ChatConversation and ChatMessage tables with proper relationships - Create conversation CRUD API endpoints with authentication - Update chat API to support persistent conversations - Implement auto-generated conversation titles and language separation - Add conversation soft delete and user-specific access control Phase 2 - Enhanced Memory System: - Implement intelligent context selection beyond simple chronological order - Add relevance scoring for older messages based on keyword overlap and biblical references - Create automatic message summarization for very long conversations - Optimize token usage with smart context management (1500 token budget) - Add biblical awareness with Romanian/English book name detection - Implement time-based relevance decay for better context prioritization Frontend Improvements: - Add chat history button to floating chat header - Create basic history panel UI with placeholder content - Maintain backward compatibility for anonymous users Database Changes: - Enhanced schema with conversation relationships and message roles - Proper indexing for performance and user-specific queries - Migration completed successfully with prisma db push 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,7 @@ model User {
|
||||
chapterBookmarks ChapterBookmark[]
|
||||
notes Note[]
|
||||
chatMessages ChatMessage[]
|
||||
chatConversations ChatConversation[]
|
||||
prayerRequests PrayerRequest[]
|
||||
userPrayers UserPrayer[]
|
||||
readingHistory ReadingHistory[]
|
||||
@@ -126,17 +127,43 @@ model BiblePassage {
|
||||
@@index([testament])
|
||||
}
|
||||
|
||||
model ChatConversation {
|
||||
id String @id @default(uuid())
|
||||
userId String? // Optional for anonymous users
|
||||
title String // Auto-generated from first message
|
||||
language String // 'ro' or 'en'
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
lastMessageAt DateTime @default(now())
|
||||
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
messages ChatMessage[]
|
||||
|
||||
@@index([userId, language, lastMessageAt])
|
||||
@@index([isActive, lastMessageAt])
|
||||
}
|
||||
|
||||
model ChatMessage {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
role String // 'user' or 'assistant'
|
||||
content String @db.Text
|
||||
metadata Json? // Store verse references, etc.
|
||||
createdAt DateTime @default(now())
|
||||
id String @id @default(uuid())
|
||||
conversationId String
|
||||
userId String? // Keep for backward compatibility
|
||||
role ChatMessageRole
|
||||
content String @db.Text
|
||||
metadata Json? // Store verse references, etc.
|
||||
timestamp DateTime @default(now())
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
conversation ChatConversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId, createdAt])
|
||||
@@index([conversationId, timestamp])
|
||||
@@index([userId, timestamp])
|
||||
}
|
||||
|
||||
enum ChatMessageRole {
|
||||
USER
|
||||
ASSISTANT
|
||||
SYSTEM
|
||||
}
|
||||
|
||||
model Bookmark {
|
||||
|
||||
Reference in New Issue
Block a user