refactor: cleanup lore local activation

This commit is contained in:
bangonicdd
2025-02-24 17:00:48 +09:00
parent 0f1d243935
commit a45a3925c2

View File

@@ -37,25 +37,14 @@
let tokens = $state(0) let tokens = $state(0)
function isLocallyActivated(book: loreBook){ function isLocallyActivated(book: loreBook){
return getCurrentChat()?.localLore.some(e => return book.id ? getCurrentChat()?.localLore.some(e => e.id === book.id) : false
e.id === book.id &&
e.alwaysActive
)
} }
function activateLocally(book: loreBook){ function activateLocally(book: loreBook){
const chat = getCurrentChat()
let childLore: loreBook | undefined
if(!book.id){ if(!book.id){
book.id = v4() book.id = v4()
}else{
childLore = chat.localLore.find(e => e.id === book.id)
} }
if(childLore){ const childLore: loreBook = {
childLore.alwaysActive = true
}else{
childLore = {
key: '', key: '',
comment: '', comment: '',
content: '', content: '',
@@ -66,8 +55,7 @@
selective: false, selective: false,
id: book.id, id: book.id,
} }
chat.localLore.push(childLore) getCurrentChat().localLore.push(childLore)
}
} }
function deactivateLocally(book: loreBook){ function deactivateLocally(book: loreBook){
if(!book.id) return if(!book.id) return