feat: Add option to resume last chat when opening Web UI

This commit is contained in:
n4ze3m
2024-11-30 19:04:45 +05:30
parent 8d12e9152c
commit e5e04c3674
19 changed files with 113 additions and 7 deletions

View File

@@ -356,11 +356,11 @@ export const updateMessageByIndex = async (
message: string
) => {
try {
const db = new PageAssitDatabase()
const chatHistory = (await db.getChatHistory(history_id)).reverse()
chatHistory[index].content = message
await db.db.set({ [history_id]: chatHistory.reverse() })
} catch(e) {
const db = new PageAssitDatabase()
const chatHistory = (await db.getChatHistory(history_id)).reverse()
chatHistory[index].content = message
await db.db.set({ [history_id]: chatHistory.reverse() })
} catch (e) {
// temp chat will break
}
}
@@ -515,6 +515,20 @@ export const getRecentChatFromCopilot = async () => {
return { history, messages }
}
export const getRecentChatFromWebUI = async () => {
const db = new PageAssitDatabase()
const chatHistories = await db.getChatHistories()
if (chatHistories.length === 0) return null
const history = chatHistories.find(
(history) => history.message_source === "web-ui"
)
if (!history) return null
const messages = await db.getChatHistory(history.id)
return { history, messages }
}
export const getTitleById = async (id: string) => {
const db = new PageAssitDatabase()
const title = await db.getChatHistoryTitleById(id)