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,37 +37,25 @@
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 key: '',
}else{ comment: '',
childLore = { content: '',
key: '', mode: 'child',
comment: '', insertorder: 100,
content: '', alwaysActive: true,
mode: 'child', secondkey: '',
insertorder: 100, selective: false,
alwaysActive: true, id: book.id,
secondkey: '',
selective: false,
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