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

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Genoptag den sidste chat, når du åbner SidePanel (copilot)" "label": "Genoptag den sidste chat, når du åbner SidePanel (copilot)"
}, },
"webUIResumeLastChat": {
"label": "Genoptag den sidste chat, når du åbner Web UI'en"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Skjul nuværende chat model indstillinger" "label": "Skjul nuværende chat model indstillinger"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Letzten Chat beim Öffnen des Seitenpanels fortsetzen (Copilot)" "label": "Letzten Chat beim Öffnen des Seitenpanels fortsetzen (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Letzten Chat beim Öffnen der Web-UI fortsetzen"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Aktuelle Chat-Modell-Einstellungen ausblenden" "label": "Aktuelle Chat-Modell-Einstellungen ausblenden"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Resume the last chat when opening the SidePanel (Copilot)" "label": "Resume the last chat when opening the SidePanel (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Resume the last chat when opening the Web UI"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Hide the current Chat Model Settings" "label": "Hide the current Chat Model Settings"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Retomar el último chat al abrir el Panel Lateral (Copilot)" "label": "Retomar el último chat al abrir el Panel Lateral (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Retomar el último chat al abrir la Interfaz Web"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Ocultar Configuraciones del Modelo de Chat Actual" "label": "Ocultar Configuraciones del Modelo de Chat Actual"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Reprendre la dernière conversation lors de l'ouverture du sidepanel (Copilot)" "label": "Reprendre la dernière conversation lors de l'ouverture du sidepanel (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Reprendre la dernière conversation lors de l'ouverture de l'interface Web"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Masquer les paramètres actuels du modèle de chat" "label": "Masquer les paramètres actuels du modèle de chat"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Riprendi l'ultima chat quando apri il Pannello Laterale (Copilot)" "label": "Riprendi l'ultima chat quando apri il Pannello Laterale (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Riprendi l'ultima chat quando apri l'interfaccia Web"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Nascondi le impostazioni correnti del modello Chat" "label": "Nascondi le impostazioni correnti del modello Chat"
}, },

View File

@ -24,6 +24,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "サイドパネルを開いたときに最後のチャットを再開 (Copilot)" "label": "サイドパネルを開いたときに最後のチャットを再開 (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Web UIを開いたときに最後のチャットを再開"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "現在のチャットモデル設定を非表示" "label": "現在のチャットモデル設定を非表示"
}, },

View File

@ -24,6 +24,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "사이드 패널을 열 때 마지막 채팅 재개 (Copilot)" "label": "사이드 패널을 열 때 마지막 채팅 재개 (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "웹 UI를 열 때 마지막 채팅 재개"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "현재 채팅 모델 설정 숨기기" "label": "현재 채팅 모델 설정 숨기기"
}, },

View File

@ -24,6 +24,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "സൈഡ്പാനൽ തുറക്കുമ്പോൾ അവസാനത്തെ ചാറ്റ് പുനരാരംഭിക്കുക (Copilot)" "label": "സൈഡ്പാനൽ തുറക്കുമ്പോൾ അവസാനത്തെ ചാറ്റ് പുനരാരംഭിക്കുക (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "വെബ് UI തുറക്കുമ്പോൾ അവസാനത്തെ ചാറ്റ് പുനരാരംഭിക്കുക"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "നിലവിലുള്ള ചാറ്റ് മോഡൽ ക്രമീകരണങ്ങൾ മറയ്ക്കുക" "label": "നിലവിലുള്ള ചാറ്റ് മോഡൽ ക്രമീകരണങ്ങൾ മറയ്ക്കുക"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Gjenoppta siste chat ved åpning av SidePanel (copilot)" "label": "Gjenoppta siste chat ved åpning av SidePanel (copilot)"
}, },
"webUIResumeLastChat": {
"label": "Gjenoppta siste chat når Web UI åpnes"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Skjul gjeldende chat modell innstillinger" "label": "Skjul gjeldende chat modell innstillinger"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Retomar o último chat ao abrir o Painel Lateral (Copilot)" "label": "Retomar o último chat ao abrir o Painel Lateral (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Retomar o último chat ao abrir a Interface Web"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Ocultar as Configurações Atuais do Modelo de Chat" "label": "Ocultar as Configurações Atuais do Modelo de Chat"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Возобновить последний чат при открытии боковой панели (Copilot)" "label": "Возобновить последний чат при открытии боковой панели (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Возобновить последний чат при открытии веб-интерфейса"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Скрыть текущие настройки модели чата" "label": "Скрыть текущие настройки модели чата"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Återuppta den senaste chatten när du öppnar sidopanelen (Copilot)" "label": "Återuppta den senaste chatten när du öppnar sidopanelen (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Återuppta den senaste chatten när du öppnar webbgränssnittet"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Göm de nuvarande chattmodellinställningarna" "label": "Göm de nuvarande chattmodellinställningarna"
}, },

View File

@ -21,6 +21,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "Поновити останню розмову при відкритті бічної панелі (Copilot)" "label": "Поновити останню розмову при відкритті бічної панелі (Copilot)"
}, },
"webUIResumeLastChat": {
"label": "Поновити останню розмову при відкритті веб-інтерфейсу"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "Приховати налаштування поточної моделі чату" "label": "Приховати налаштування поточної моделі чату"
}, },

View File

@ -24,6 +24,9 @@
"copilotResumeLastChat": { "copilotResumeLastChat": {
"label": "打开侧边栏时恢复上次聊天Copilot" "label": "打开侧边栏时恢复上次聊天Copilot"
}, },
"webUIResumeLastChat": {
"label": "打开Web UI时恢复上次聊天"
},
"hideCurrentChatModelSettings": { "hideCurrentChatModelSettings": {
"label": "隐藏当前聊天模型设置" "label": "隐藏当前聊天模型设置"
}, },

View File

@ -2,11 +2,18 @@ import React from "react"
import { PlaygroundForm } from "./PlaygroundForm" import { PlaygroundForm } from "./PlaygroundForm"
import { PlaygroundChat } from "./PlaygroundChat" import { PlaygroundChat } from "./PlaygroundChat"
import { useMessageOption } from "@/hooks/useMessageOption" import { useMessageOption } from "@/hooks/useMessageOption"
import { webUIResumeLastChat } from "@/services/app"
import {
formatToChatHistory,
formatToMessage,
getRecentChatFromWebUI
} from "@/db"
export const Playground = () => { export const Playground = () => {
const drop = React.useRef<HTMLDivElement>(null) const drop = React.useRef<HTMLDivElement>(null)
const [dropedFile, setDropedFile] = React.useState<File | undefined>() const [dropedFile, setDropedFile] = React.useState<File | undefined>()
const { selectedKnowledge } = useMessageOption() const { selectedKnowledge, messages, setHistoryId, setHistory, setMessages } =
useMessageOption()
const [dropState, setDropState] = React.useState< const [dropState, setDropState] = React.useState<
"idle" | "dragging" | "error" "idle" | "dragging" | "error"
@ -71,6 +78,26 @@ export const Playground = () => {
} }
} }
}, [selectedKnowledge]) }, [selectedKnowledge])
const setRecentMessagesOnLoad = async () => {
const isEnabled = await webUIResumeLastChat()
if (!isEnabled) {
return
}
if (messages.length === 0) {
const recentChat = await getRecentChatFromWebUI()
if (recentChat) {
setHistoryId(recentChat.history.id)
setHistory(formatToChatHistory(recentChat.messages))
setMessages(formatToMessage(recentChat.messages))
}
}
}
React.useEffect(() => {
setRecentMessagesOnLoad()
}, [])
return ( return (
<div <div
ref={drop} ref={drop}
@ -78,7 +105,7 @@ export const Playground = () => {
dropState === "dragging" ? "bg-gray-100 dark:bg-gray-800 z-10" : "" dropState === "dragging" ? "bg-gray-100 dark:bg-gray-800 z-10" : ""
} bg-white dark:bg-[#171717]`}> } bg-white dark:bg-[#171717]`}>
<PlaygroundChat /> <PlaygroundChat />
<div className="flex flex-col items-center"> <div className="flex flex-col items-center">
<div className="flex-grow"> <div className="flex-grow">
<div className="w-full flex justify-center"> <div className="w-full flex justify-center">

View File

@ -27,6 +27,11 @@ export const GeneralSettings = () => {
false false
) )
const [webUIResumeLastChat, setWebUIResumeLastChat] = useStorage(
"webUIResumeLastChat",
false
)
const [restoreLastChatModel, setRestoreLastChatModel] = useStorage( const [restoreLastChatModel, setRestoreLastChatModel] = useStorage(
"restoreLastChatModel", "restoreLastChatModel",
false false
@ -113,6 +118,17 @@ export const GeneralSettings = () => {
onChange={(checked) => setCopilotResumeLastChat(checked)} onChange={(checked) => setCopilotResumeLastChat(checked)}
/> />
</div> </div>
<div className="flex flex-row justify-between">
<div className="inline-flex items-center gap-2">
<span className="text-gray-700 dark:text-neutral-50">
{t("generalSettings.settings.webUIResumeLastChat.label")}
</span>
</div>
<Switch
checked={webUIResumeLastChat}
onChange={(checked) => setWebUIResumeLastChat(checked)}
/>
</div>
<div className="flex flex-row justify-between"> <div className="flex flex-row justify-between">
<div className="inline-flex items-center gap-2"> <div className="inline-flex items-center gap-2">
<span className="text-gray-700 dark:text-neutral-50"> <span className="text-gray-700 dark:text-neutral-50">

View File

@ -356,11 +356,11 @@ export const updateMessageByIndex = async (
message: string message: string
) => { ) => {
try { try {
const db = new PageAssitDatabase() const db = new PageAssitDatabase()
const chatHistory = (await db.getChatHistory(history_id)).reverse() const chatHistory = (await db.getChatHistory(history_id)).reverse()
chatHistory[index].content = message chatHistory[index].content = message
await db.db.set({ [history_id]: chatHistory.reverse() }) await db.db.set({ [history_id]: chatHistory.reverse() })
} catch(e) { } catch (e) {
// temp chat will break // temp chat will break
} }
} }
@ -515,6 +515,20 @@ export const getRecentChatFromCopilot = async () => {
return { history, messages } 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) => { export const getTitleById = async (id: string) => {
const db = new PageAssitDatabase() const db = new PageAssitDatabase()
const title = await db.getChatHistoryTitleById(id) const title = await db.getChatHistoryTitleById(id)

View File

@ -39,6 +39,10 @@ export const copilotResumeLastChat = async () => {
return await storage.get<boolean>("copilotResumeLastChat") return await storage.get<boolean>("copilotResumeLastChat")
} }
export const webUIResumeLastChat = async () => {
return await storage.get<boolean>("webUIResumeLastChat")
}
export const defaultSidebarOpen = async () => { export const defaultSidebarOpen = async () => {
const sidebarOpen = await storage.get("sidebarOpen") const sidebarOpen = await storage.get("sidebarOpen")
if (!sidebarOpen || sidebarOpen === "") { if (!sidebarOpen || sidebarOpen === "") {