feat: Add support for sending notification after knowledge base processing

This commit is contained in:
n4ze3m 2024-07-16 00:37:50 +05:30
parent f5f0157260
commit 9c8584f1c4
14 changed files with 383 additions and 307 deletions

View File

@ -51,7 +51,7 @@
"chatWithCurrentPage": "Chat with current page",
"beta": "Beta",
"tts": "Read aloud",
"currentChatModelSettings":"Current Chat Model Settings",
"currentChatModelSettings": "Current Chat Model Settings",
"modelSettings": {
"label": "Model Settings",
"description": "Set the model options globally for all chats",

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Restore last used model for previous chats"
},
"sendNotificationAfterIndexing": {
"label": "Send Notification After Finishing Processing the Knowledge Base"
}
},
"webSearch": {

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Restaurar el último modelo utilizado para chats anteriores"
},
"sendNotificationAfterIndexing": {
"label": "Enviar notificación después de terminar el procesamiento de la base de conocimientos"
}
},
"webSearch": {

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Restaurer le dernier modèle utilisé pour les conversations précédentes"
},
"sendNotificationAfterIndexing": {
"label": "Envoyer une notification après avoir terminé le traitement de la base de connaissances"
}
},
"webSearch": {

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Ripristina l'ultimo modello utilizzato per le chat precedenti"
},
"sendNotificationAfterIndexing": {
"label": "Inviare notifica dopo aver terminato l'elaborazione della base di conoscenza"
}
},
"webSearch": {

View File

@ -29,6 +29,9 @@
},
"restoreLastChatModel": {
"label": "以前のチャットで最後に使用したモデルを復元する"
},
"sendNotificationAfterIndexing": {
"label": "ナレッジベースの処理完了後に通知を送信"
}
},
"webSearch": {

View File

@ -29,6 +29,9 @@
},
"restoreLastChatModel": {
"label": "മുൻപത്തെ ചാറ്റുകൾക്കായി അവസാനം ഉപയോഗിച്ച മോഡൽ പുനഃസ്ഥാപിക്കുക"
},
"sendNotificationAfterIndexing": {
"label": "അറിവ് ശേഖരം പ്രോസസ്സ് ചെയ്ത് കഴിഞ്ഞതിന് ശേഷം അറിയിപ്പ് അയയ്ക്കുക"
}
},
"webSearch": {

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Restaurar o último modelo usado para conversas anteriores"
},
"sendNotificationAfterIndexing": {
"label": "Enviar notificação após concluir o processamento da base de conhecimento"
}
},
"webSearch": {

View File

@ -26,6 +26,9 @@
},
"restoreLastChatModel": {
"label": "Восстановить последнюю использованную модель для предыдущих чатов"
},
"sendNotificationAfterIndexing": {
"label": "Отправить уведомление после завершения обработки базы знаний"
}
},
"webSearch": {

View File

@ -29,6 +29,9 @@
},
"restoreLastChatModel": {
"label": "恢复上次用于之前聊天的模型"
},
"sendNotificationAfterIndexing": {
"label": "完成知识库处理后发送通知"
}
},
"webSearch": {

View File

@ -32,6 +32,9 @@ export const GeneralSettings = () => {
const [hideCurrentChatModelSettings, setHideCurrentChatModelSettings] =
useStorage("hideCurrentChatModelSettings", false)
const [sendNotificationAfterIndexing, setSendNotificationAfterIndexing] =
useStorage("sendNotificationAfterIndexing", false)
const queryClient = useQueryClient()
const { mode, toggleDarkMode } = useDarkMode()
@ -124,6 +127,20 @@ export const GeneralSettings = () => {
onChange={(checked) => setRestoreLastChatModel(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.sendNotificationAfterIndexing.label")}
</span>
</div>
<Switch
checked={sendNotificationAfterIndexing}
onChange={setSendNotificationAfterIndexing}
/>
</div>
<div className="flex flex-row justify-between">
<span className="text-gray-700 dark:text-neutral-50 ">
{t("generalSettings.settings.darkMode.label")}

View File

@ -12,6 +12,7 @@ import { PageAssisCSVUrlLoader } from "@/loader/csv"
import { PageAssisTXTUrlLoader } from "@/loader/txt"
import { PageAssistDocxLoader } from "@/loader/docx"
import { cleanUrl } from "./clean-url"
import { sendEmbeddingCompleteNotification } from "./send-notification"
export const processKnowledge = async (msg: any, id: string): Promise<void> => {
@ -102,6 +103,8 @@ export const processKnowledge = async (msg: any, id: string): Promise<void> => {
}
await updateKnowledgeStatus(id, "finished")
await sendEmbeddingCompleteNotification()
} catch (error) {
console.error(`Error processing knowledge with id: ${id}`, error)
await updateKnowledgeStatus(id, "failed")

View File

@ -0,0 +1,27 @@
import { Storage } from "@plasmohq/storage"
const storage = new Storage()
export const sendNotification = async (title: string, message: string) => {
try {
const sendNotificationAfterIndexing = await storage.get<boolean>(
"sendNotificationAfterIndexing"
)
if (sendNotificationAfterIndexing) {
browser.notifications.create({
type: "basic",
iconUrl: browser.runtime.getURL("/icon.png"),
title,
message
})
}
} catch (error) {
console.error(error)
}
}
export const sendEmbeddingCompleteNotification = async () => {
await sendNotification(
"Page Assist - Embedding Completed",
"The knowledge base embedding process is complete. You can now use the knowledge base for chatting."
)
}

View File

@ -11,7 +11,8 @@ const chromeMV3Permissions = [
"action",
"unlimitedStorage",
"contextMenus",
"tts"
"tts",
"notifications"
]
const firefoxMV2Permissions = [
@ -22,6 +23,7 @@ const firefoxMV2Permissions = [
"contextMenus",
"webRequest",
"webRequestBlocking",
"notifications",
"http://*/*",
"https://*/*",
"file://*/*"