Add lorebook import for modules
This commit is contained in:
@@ -320,43 +320,8 @@ export async function importLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
}
|
||||
}
|
||||
else if(importedlore.entries){
|
||||
const entries:{[key:string]:{
|
||||
key:string[]
|
||||
comment:string
|
||||
content:string
|
||||
order:number
|
||||
constant:boolean,
|
||||
name:string,
|
||||
keywords:string[],
|
||||
priority:number
|
||||
entry:string
|
||||
secondary_keys:string[]
|
||||
selective:boolean
|
||||
forceActivation:boolean
|
||||
keys:string[]
|
||||
displayName:string
|
||||
text:string
|
||||
contextConfig?: {
|
||||
budgetPriority:number
|
||||
prefix:string
|
||||
suffix:string
|
||||
}
|
||||
}} = importedlore.entries
|
||||
for(const key in entries){
|
||||
const currentLore = entries[key]
|
||||
lore.push({
|
||||
key: currentLore.key ? currentLore.key.join(', ') :
|
||||
currentLore.keys ? currentLore.keys.join(', ') :
|
||||
currentLore.keywords ? currentLore.keywords.join(', ') : '',
|
||||
insertorder: currentLore.order ?? currentLore.priority ?? currentLore?.contextConfig?.budgetPriority ?? 0,
|
||||
comment: currentLore.comment || currentLore.name || currentLore.displayName || '',
|
||||
content: currentLore.content || currentLore.entry || currentLore.text || '',
|
||||
mode: "normal",
|
||||
alwaysActive: currentLore.constant ?? currentLore.forceActivation ?? false,
|
||||
secondkey: currentLore.secondary_keys ? currentLore.secondary_keys.join(', ') : "",
|
||||
selective: currentLore.selective ?? false
|
||||
})
|
||||
}
|
||||
const entries:{[key:string]:CCLorebook} = importedlore.entries
|
||||
lore.push(...convertExternalLorebook(entries))
|
||||
}
|
||||
if(mode === 'global'){
|
||||
db.characters[selectedID].globalLore = lore
|
||||
@@ -370,6 +335,49 @@ export async function importLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
}
|
||||
}
|
||||
|
||||
interface CCLorebook{
|
||||
key:string[]
|
||||
comment:string
|
||||
content:string
|
||||
order:number
|
||||
constant:boolean,
|
||||
name:string,
|
||||
keywords:string[],
|
||||
priority:number
|
||||
entry:string
|
||||
secondary_keys:string[]
|
||||
selective:boolean
|
||||
forceActivation:boolean
|
||||
keys:string[]
|
||||
displayName:string
|
||||
text:string
|
||||
contextConfig?: {
|
||||
budgetPriority:number
|
||||
prefix:string
|
||||
suffix:string
|
||||
}
|
||||
}
|
||||
|
||||
export function convertExternalLorebook(entries:{[key:string]:CCLorebook}){
|
||||
let lore:loreBook[] = []
|
||||
for(const key in entries){
|
||||
const currentLore = entries[key]
|
||||
lore.push({
|
||||
key: currentLore.key ? currentLore.key.join(', ') :
|
||||
currentLore.keys ? currentLore.keys.join(', ') :
|
||||
currentLore.keywords ? currentLore.keywords.join(', ') : '',
|
||||
insertorder: currentLore.order ?? currentLore.priority ?? currentLore?.contextConfig?.budgetPriority ?? 0,
|
||||
comment: currentLore.comment || currentLore.name || currentLore.displayName || '',
|
||||
content: currentLore.content || currentLore.entry || currentLore.text || '',
|
||||
mode: "normal",
|
||||
alwaysActive: currentLore.constant ?? currentLore.forceActivation ?? false,
|
||||
secondkey: currentLore.secondary_keys ? currentLore.secondary_keys.join(', ') : "",
|
||||
selective: currentLore.selective ?? false
|
||||
})
|
||||
}
|
||||
return lore
|
||||
}
|
||||
|
||||
export async function exportLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
try {
|
||||
const selectedID = get(selectedCharID)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { get } from "svelte/store"
|
||||
import { CurrentChat } from "../stores"
|
||||
import { selectSingleFile } from "../util"
|
||||
import { v4 } from "uuid"
|
||||
import { convertExternalLorebook } from "./lorebook"
|
||||
|
||||
export interface RisuModule{
|
||||
name: string
|
||||
@@ -26,25 +27,50 @@ export async function exportModule(module:RisuModule){
|
||||
}
|
||||
|
||||
export async function importModule(){
|
||||
const f = await selectSingleFile(['json'])
|
||||
const f = await selectSingleFile(['json', 'lorebook'])
|
||||
if(!f){
|
||||
return
|
||||
}
|
||||
const file = f.data
|
||||
const db = get(DataBase)
|
||||
try {
|
||||
const importedModule = JSON.parse(Buffer.from(file).toString())
|
||||
if(importedModule.type === 'risuModule'){
|
||||
const db = get(DataBase)
|
||||
const importData = JSON.parse(Buffer.from(file).toString())
|
||||
if(importData.type === 'risuModule'){
|
||||
if(
|
||||
(!importedModule.name)
|
||||
|| (!importedModule.description)
|
||||
|| (!importedModule.id)
|
||||
(!importData.name)
|
||||
|| (!importData.description)
|
||||
|| (!importData.id)
|
||||
){
|
||||
alertError(language.errors.noData)
|
||||
}
|
||||
importedModule.id = v4()
|
||||
db.modules.push(importedModule)
|
||||
importData.id = v4()
|
||||
db.modules.push(importData)
|
||||
setDatabase(db)
|
||||
return
|
||||
}
|
||||
if(importData.type === 'risu' && importData.data){
|
||||
const lores:loreBook[] = importData.data
|
||||
const importModule = {
|
||||
name: importData.name,
|
||||
description: importData.description,
|
||||
lorebook: lores,
|
||||
id: v4()
|
||||
}
|
||||
db.modules.push(importModule)
|
||||
setDatabase(db)
|
||||
return
|
||||
}
|
||||
if(importData.entries){
|
||||
const lores:loreBook[] = convertExternalLorebook(importData.entries)
|
||||
const importModule = {
|
||||
name: importData.name,
|
||||
description: importData.description,
|
||||
lorebook: lores,
|
||||
id: v4()
|
||||
}
|
||||
db.modules.push(importModule)
|
||||
setDatabase(db)
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
alertNormal(language.errors.noData)
|
||||
|
||||
Reference in New Issue
Block a user