feat: save current session before creating new session
- handleNewSession now saves all messages from current session - Saves both user and assistant messages - Then creates new session with timestamp name
This commit is contained in:
@@ -798,6 +798,29 @@ async function handleSelectSession(s: SearchSession) {
|
||||
}
|
||||
|
||||
async function handleNewSession() {
|
||||
// Save current session messages before creating new one
|
||||
if (currentSession.value && messages.value.length > 0) {
|
||||
const lastMsg = messages.value[messages.value.length - 1]
|
||||
// Save user messages
|
||||
for (const msg of messages.value) {
|
||||
if (msg.role === 'user' && msg.query) {
|
||||
await saveMessage(currentSession.value.id, {
|
||||
role: 'user',
|
||||
content: msg.query,
|
||||
mode: msg.mode || mode.value
|
||||
})
|
||||
} else if (msg.role === 'assistant') {
|
||||
await saveMessage(currentSession.value.id, {
|
||||
role: 'assistant',
|
||||
content: msg.message || msg.answer || '',
|
||||
mode: msg.mode || mode.value,
|
||||
results: msg.results
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create new session
|
||||
const now = new Date()
|
||||
const timeStr = `${now.getFullYear()}/${(now.getMonth()+1).toString().padStart(2,'0')}/${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}`
|
||||
const newSession = await createSession(timeStr, mode.value)
|
||||
|
||||
Reference in New Issue
Block a user