fix: chat memory lost between messages + per-note history
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m11s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m11s
Chat (AIChat floating widget): conversationId was never captured from the API response, so every message created a new conversation with no context. Now creates the conversation upfront before streaming (same pattern as ChatContainer) so the ID persists across messages. Note history: was stored globally in UserAISettings, so enabling history on one note enabled it for ALL notes. Now each Note has its own historyEnabled boolean field. The "Enable history" action only affects the specific note. A migration adds the column with default false. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,7 @@ import { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import { useSearchParams, useRouter } from 'next/navigation'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { Note } from '@/lib/types'
|
||||
import { updateAISettings } from '@/app/actions/ai-settings'
|
||||
import { getAllNotes, searchNotes } from '@/app/actions/notes'
|
||||
import { getAllNotes, searchNotes, enableNoteHistory } from '@/app/actions/notes'
|
||||
import { NoteInput } from '@/components/note-input'
|
||||
import { NotesMainSection, type NotesViewMode } from '@/components/notes-main-section'
|
||||
import { NotesViewToggle } from '@/components/notes-view-toggle'
|
||||
@@ -62,7 +61,6 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
||||
initialNotes.filter(n => n.isPinned)
|
||||
)
|
||||
const [notesViewMode, setNotesViewMode] = useState<NotesViewMode>(initialSettings.notesViewMode)
|
||||
const [noteHistoryEnabled, setNoteHistoryEnabled] = useState(initialSettings.noteHistory)
|
||||
const [noteHistoryMode] = useState<'manual' | 'auto'>(initialSettings.noteHistoryMode)
|
||||
const [editingNote, setEditingNote] = useState<{ note: Note; readOnly?: boolean } | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(false) // false by default — data is pre-loaded
|
||||
@@ -145,9 +143,12 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
||||
setHistoryOpen(true)
|
||||
}, [])
|
||||
|
||||
const handleEnableHistory = useCallback(async () => {
|
||||
await updateAISettings({ noteHistory: true })
|
||||
setNoteHistoryEnabled(true)
|
||||
const handleEnableHistory = useCallback(async (noteId: string) => {
|
||||
await enableNoteHistory(noteId)
|
||||
// Update the specific note in state
|
||||
setNotes((prev) => prev.map((n) => (n.id === noteId ? { ...n, historyEnabled: true } : n)))
|
||||
setPinnedNotes((prev) => prev.map((n) => (n.id === noteId ? { ...n, historyEnabled: true } : n)))
|
||||
setEditingNote((prev) => (prev?.note.id === noteId ? { ...prev, note: { ...prev.note, historyEnabled: true } } : prev))
|
||||
}, [])
|
||||
|
||||
const handleHistoryRestored = useCallback((restored: Note) => {
|
||||
@@ -411,7 +412,6 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
||||
onEdit={(note, readOnly) => setEditingNote({ note, readOnly })}
|
||||
onSizeChange={handleSizeChange}
|
||||
currentNotebookId={searchParams.get('notebook')}
|
||||
noteHistoryEnabled={noteHistoryEnabled}
|
||||
noteHistoryMode={noteHistoryMode}
|
||||
onOpenHistory={handleOpenHistory}
|
||||
onEnableHistory={handleEnableHistory}
|
||||
@@ -469,8 +469,8 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
||||
open={historyOpen}
|
||||
onOpenChange={setHistoryOpen}
|
||||
note={historyNote}
|
||||
enabled={noteHistoryEnabled}
|
||||
onEnableHistory={handleEnableHistory}
|
||||
enabled={!!historyNote?.historyEnabled}
|
||||
onEnableHistory={async () => { if (historyNote) await handleEnableHistory(historyNote.id) }}
|
||||
onRestored={handleHistoryRestored}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user