feat: Add option to resume last chat when opening Web UI
This commit is contained in:
parent
8d12e9152c
commit
e5e04c3674
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"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": {
|
||||
"label": "Skjul nuværende chat model indstillinger"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Letzten Chat beim Öffnen des Seitenpanels fortsetzen (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Letzten Chat beim Öffnen der Web-UI fortsetzen"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Aktuelle Chat-Modell-Einstellungen ausblenden"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Resume the last chat when opening the SidePanel (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Resume the last chat when opening the Web UI"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Hide the current Chat Model Settings"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Retomar el último chat al abrir el Panel Lateral (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Retomar el último chat al abrir la Interfaz Web"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Ocultar Configuraciones del Modelo de Chat Actual"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"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": {
|
||||
"label": "Masquer les paramètres actuels du modèle de chat"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Riprendi l'ultima chat quando apri il Pannello Laterale (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Riprendi l'ultima chat quando apri l'interfaccia Web"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Nascondi le impostazioni correnti del modello Chat"
|
||||
},
|
||||
|
@ -24,6 +24,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "サイドパネルを開いたときに最後のチャットを再開 (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Web UIを開いたときに最後のチャットを再開"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "現在のチャットモデル設定を非表示"
|
||||
},
|
||||
|
@ -24,6 +24,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "사이드 패널을 열 때 마지막 채팅 재개 (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "웹 UI를 열 때 마지막 채팅 재개"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "현재 채팅 모델 설정 숨기기"
|
||||
},
|
||||
|
@ -24,6 +24,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "സൈഡ്പാനൽ തുറക്കുമ്പോൾ അവസാനത്തെ ചാറ്റ് പുനരാരംഭിക്കുക (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "വെബ് UI തുറക്കുമ്പോൾ അവസാനത്തെ ചാറ്റ് പുനരാരംഭിക്കുക"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "നിലവിലുള്ള ചാറ്റ് മോഡൽ ക്രമീകരണങ്ങൾ മറയ്ക്കുക"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Gjenoppta siste chat ved åpning av SidePanel (copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Gjenoppta siste chat når Web UI åpnes"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Skjul gjeldende chat modell innstillinger"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Retomar o último chat ao abrir o Painel Lateral (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Retomar o último chat ao abrir a Interface Web"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Ocultar as Configurações Atuais do Modelo de Chat"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Возобновить последний чат при открытии боковой панели (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Возобновить последний чат при открытии веб-интерфейса"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Скрыть текущие настройки модели чата"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Återuppta den senaste chatten när du öppnar sidopanelen (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Återuppta den senaste chatten när du öppnar webbgränssnittet"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Göm de nuvarande chattmodellinställningarna"
|
||||
},
|
||||
|
@ -21,6 +21,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "Поновити останню розмову при відкритті бічної панелі (Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "Поновити останню розмову при відкритті веб-інтерфейсу"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "Приховати налаштування поточної моделі чату"
|
||||
},
|
||||
|
@ -24,6 +24,9 @@
|
||||
"copilotResumeLastChat": {
|
||||
"label": "打开侧边栏时恢复上次聊天(Copilot)"
|
||||
},
|
||||
"webUIResumeLastChat": {
|
||||
"label": "打开Web UI时恢复上次聊天"
|
||||
},
|
||||
"hideCurrentChatModelSettings": {
|
||||
"label": "隐藏当前聊天模型设置"
|
||||
},
|
||||
|
@ -2,11 +2,18 @@ import React from "react"
|
||||
import { PlaygroundForm } from "./PlaygroundForm"
|
||||
import { PlaygroundChat } from "./PlaygroundChat"
|
||||
import { useMessageOption } from "@/hooks/useMessageOption"
|
||||
import { webUIResumeLastChat } from "@/services/app"
|
||||
import {
|
||||
formatToChatHistory,
|
||||
formatToMessage,
|
||||
getRecentChatFromWebUI
|
||||
} from "@/db"
|
||||
|
||||
export const Playground = () => {
|
||||
const drop = React.useRef<HTMLDivElement>(null)
|
||||
const [dropedFile, setDropedFile] = React.useState<File | undefined>()
|
||||
const { selectedKnowledge } = useMessageOption()
|
||||
const { selectedKnowledge, messages, setHistoryId, setHistory, setMessages } =
|
||||
useMessageOption()
|
||||
|
||||
const [dropState, setDropState] = React.useState<
|
||||
"idle" | "dragging" | "error"
|
||||
@ -71,6 +78,26 @@ export const Playground = () => {
|
||||
}
|
||||
}
|
||||
}, [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 (
|
||||
<div
|
||||
ref={drop}
|
||||
@ -78,7 +105,7 @@ export const Playground = () => {
|
||||
dropState === "dragging" ? "bg-gray-100 dark:bg-gray-800 z-10" : ""
|
||||
} bg-white dark:bg-[#171717]`}>
|
||||
<PlaygroundChat />
|
||||
|
||||
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="flex-grow">
|
||||
<div className="w-full flex justify-center">
|
||||
|
@ -27,6 +27,11 @@ export const GeneralSettings = () => {
|
||||
false
|
||||
)
|
||||
|
||||
const [webUIResumeLastChat, setWebUIResumeLastChat] = useStorage(
|
||||
"webUIResumeLastChat",
|
||||
false
|
||||
)
|
||||
|
||||
const [restoreLastChatModel, setRestoreLastChatModel] = useStorage(
|
||||
"restoreLastChatModel",
|
||||
false
|
||||
@ -113,6 +118,17 @@ export const GeneralSettings = () => {
|
||||
onChange={(checked) => setCopilotResumeLastChat(checked)}
|
||||
/>
|
||||
</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="inline-flex items-center gap-2">
|
||||
<span className="text-gray-700 dark:text-neutral-50">
|
||||
|
@ -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)
|
||||
|
@ -39,6 +39,10 @@ export const copilotResumeLastChat = async () => {
|
||||
return await storage.get<boolean>("copilotResumeLastChat")
|
||||
}
|
||||
|
||||
export const webUIResumeLastChat = async () => {
|
||||
return await storage.get<boolean>("webUIResumeLastChat")
|
||||
}
|
||||
|
||||
export const defaultSidebarOpen = async () => {
|
||||
const sidebarOpen = await storage.get("sidebarOpen")
|
||||
if (!sidebarOpen || sidebarOpen === "") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user