refac
This commit is contained in:
@@ -164,6 +164,7 @@
|
||||
let generating = false;
|
||||
let dragged = false;
|
||||
let generationController = null;
|
||||
let contextCompactionToastId = null;
|
||||
|
||||
let chat = null;
|
||||
let tags = [];
|
||||
@@ -498,6 +499,43 @@
|
||||
}
|
||||
};
|
||||
|
||||
const dismissContextCompactionToast = () => {
|
||||
if (contextCompactionToastId !== null) {
|
||||
toast.dismiss(contextCompactionToastId);
|
||||
contextCompactionToastId = null;
|
||||
}
|
||||
};
|
||||
|
||||
const handleContextCompactionStatus = (status) => {
|
||||
if (status?.action !== 'context_compaction') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (status?.done) {
|
||||
if (contextCompactionToastId !== null) {
|
||||
if (status?.error) {
|
||||
toast.error($i18n.t('Context compaction failed'), {
|
||||
id: contextCompactionToastId,
|
||||
duration: 3000
|
||||
});
|
||||
} else {
|
||||
toast.success($i18n.t('Context compacted'), {
|
||||
id: contextCompactionToastId,
|
||||
duration: 1800
|
||||
});
|
||||
}
|
||||
contextCompactionToastId = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (contextCompactionToastId === null) {
|
||||
contextCompactionToastId = toast.loading($i18n.t('Compacting context'), {
|
||||
duration: Infinity
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const chatEventHandler = async (event, cb) => {
|
||||
console.log(event);
|
||||
|
||||
@@ -515,9 +553,12 @@
|
||||
} else {
|
||||
message.statusHistory = [data];
|
||||
}
|
||||
} else if (type === 'context_compaction') {
|
||||
handleContextCompactionStatus(data);
|
||||
} else if (type === 'chat:completion') {
|
||||
chatCompletionEventHandler(data, message, event.chat_id);
|
||||
} else if (type === 'chat:tasks:cancel') {
|
||||
dismissContextCompactionToast();
|
||||
if (event.message_id === history.currentId) {
|
||||
taskIds = null;
|
||||
// Set all response messages to done
|
||||
@@ -895,6 +936,7 @@
|
||||
selectedFolderSubscribe();
|
||||
window.removeEventListener('message', onMessageHandler);
|
||||
$socket?.off('events', chatEventHandler);
|
||||
dismissContextCompactionToast();
|
||||
audioQueueInstance?.destroy();
|
||||
audioQueue.set(null);
|
||||
} catch (e) {
|
||||
|
||||
@@ -1198,4 +1198,10 @@
|
||||
richColors
|
||||
position="top-right"
|
||||
closeButton
|
||||
toastOptions={{
|
||||
classes: {
|
||||
closeButton:
|
||||
'!bg-white/80 !text-gray-500 !border-gray-200 hover:!bg-gray-50 hover:!text-gray-700 dark:!bg-gray-850 dark:!text-gray-400 dark:!border-gray-700 dark:hover:!bg-gray-800 dark:hover:!text-gray-200'
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user