chore: Update npm dependency versions and add export/import functions for chat history and knowledge

This commit is contained in:
n4ze3m 2024-05-08 12:13:16 +05:30
parent 88ad1fcab7
commit 11147fd951
5 changed files with 66 additions and 1 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -37,7 +37,7 @@
"langchain": "^0.1.28", "langchain": "^0.1.28",
"lucide-react": "^0.350.0", "lucide-react": "^0.350.0",
"ml-distance": "^4.0.1", "ml-distance": "^4.0.1",
"pdfjs-dist": "^4.0.379", "pdfjs-dist": "4.0.379",
"property-information": "^6.4.1", "property-information": "^6.4.1",
"pubsub-js": "^1.9.4", "pubsub-js": "^1.9.4",
"react": "18.2.0", "react": "18.2.0",

View File

@ -417,3 +417,30 @@ export const getUserId = async () => {
} }
return id return id
} }
export const exportChatHistory = async () => {
const db = new PageAssitDatabase()
const chatHistories = await db.getChatHistories()
const messages = await Promise.all(
chatHistories.map(async (history) => {
const messages = await db.getChatHistory(history.id)
return { history, messages }
})
)
return messages
}
export const importChatHistory = async (
data: {
history: HistoryInfo
messages: MessageHistory
}[]
) => {
const db = new PageAssitDatabase()
for (const { history, messages } of data) {
await db.addChatHistory(history)
for (const message of messages) {
await db.addMessage(message)
}
}
}

View File

@ -190,3 +190,16 @@ export const deleteSource = async (id: string, source_id: string) => {
await db.deleteSource(id, source_id) await db.deleteSource(id, source_id)
await deleteVectorByFileId(`vector:${id}`, source_id) await deleteVectorByFileId(`vector:${id}`, source_id)
} }
export const exportKnowledge = async () => {
const db = new PageAssistKnowledge()
const data = await db.getAll()
return data
}
export const importKnowledge = async (data: Knowledge[]) => {
const db = new PageAssistKnowledge()
for (const d of data) {
await db.create(d)
}
}

View File

@ -100,6 +100,18 @@ export class PageAssistVectorDb {
}) })
}) })
} }
getAll = async (): Promise<VectorData[]> => {
return new Promise((resolve, reject) => {
this.db.get(null, (result) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError)
} else {
resolve(Object.values(result))
}
})
})
}
} }
export const insertVector = async ( export const insertVector = async (
@ -127,3 +139,16 @@ export const deleteVectorByFileId = async (
const db = new PageAssistVectorDb() const db = new PageAssistVectorDb()
return db.deleteVectorByFileId(id, file_id) return db.deleteVectorByFileId(id, file_id)
} }
export const exportVectors = async () => {
const db = new PageAssistVectorDb()
const data = await db.getAll()
return data
}
export const importVectors = async (data: VectorData[]) => {
const db = new PageAssistVectorDb()
for (const d of data) {
await db.insertVector(d.id, d.vectors)
}
}