feat: add Save Session button
- Added 💾 Save button to history header
- saveCurrentSession saves all messages to current session
- If no session exists, creates one with timestamp name
- Saved sessions appear in history list for selection
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
<div class="bkh">
|
||||
<span class="bkht">History</span>
|
||||
<div class="bkh-actions">
|
||||
<button class="bkh-btn" title="Save Session" @click="saveCurrentSession">💾 Save</button>
|
||||
<button class="bkx" @click="showHistory = false">x</button>
|
||||
</div>
|
||||
<button class="hs-new-btn" @click="handleNewSession">+ New Session</button>
|
||||
@@ -748,6 +749,45 @@ async function startNewChat() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveCurrentSession() {
|
||||
if (messages.value.length === 0) {
|
||||
alert('No messages to save')
|
||||
return
|
||||
}
|
||||
|
||||
// If no current session, create one
|
||||
if (!currentSession.value) {
|
||||
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)
|
||||
if (newSession) {
|
||||
setCurrentSession(newSession)
|
||||
}
|
||||
}
|
||||
|
||||
// Save all messages to current session
|
||||
if (currentSession.value) {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
await loadSessions()
|
||||
alert('Session saved!')
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSessionMenu(id: string) {
|
||||
activeSessionMenu.value = activeSessionMenu.value === id ? null : id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user