Migrate all DataBase to DBState
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Sidebar from './lib/SideBars/Sidebar.svelte';
|
||||
import { DynamicGUI, settingsOpen, sideBarStore, ShowRealmFrameStore, openPresetList, openPersonaList, MobileGUI, CustomGUISettingMenuStore } from './ts/stores';
|
||||
import { DataBase, loadedStore } from './ts/storage/database.svelte';
|
||||
import { DBState, loadedStore } from './ts/storage/database.svelte';
|
||||
import ChatScreen from './lib/ChatScreens/ChatScreen.svelte';
|
||||
import AlertComp from './lib/Others/AlertComp.svelte';
|
||||
import RealmPopUp from './lib/UI/Realm/RealmPopUp.svelte';
|
||||
@@ -21,15 +21,9 @@
|
||||
import CustomGUISettingMenu from './lib/Setting/Pages/CustomGUISettingMenu.svelte';
|
||||
|
||||
|
||||
let didFirstSetup: boolean = $state(false)
|
||||
let didFirstSetup: boolean = $derived(DBState.db?.didFirstSetup)
|
||||
let gridOpen = $state(false)
|
||||
|
||||
DataBase.subscribe(db => {
|
||||
if(db.didFirstSetup !== didFirstSetup){
|
||||
didFirstSetup = db.didFirstSetup || false
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<main class="flex bg-bg w-full h-full max-w-100vw text-textcolor">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { onMount, createEventDispatcher } from 'svelte';
|
||||
import { EditIcon, LanguagesIcon } from "lucide-svelte";
|
||||
import { DataBase, DBState } from "../../ts/storage/database.svelte";
|
||||
import { DBState } from "../../ts/storage/database.svelte";
|
||||
import CodeMirror from 'codemirror';
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { get } from 'svelte/store';
|
||||
import { FileAudioIcon, PlusIcon } from "lucide-svelte";
|
||||
import { DataBase, setDatabase, type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import { type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import { getFileSrc, saveAsset } from "src/ts/storage/globalApi";
|
||||
import { selectMultipleFile } from "src/ts/util";
|
||||
interface Props {
|
||||
@@ -48,8 +47,6 @@
|
||||
currentCharacter.additionalAssets.push([name, imgp, extension])
|
||||
currentCharacter = currentCharacter
|
||||
}
|
||||
const db = get(DataBase);
|
||||
setDatabase(db)
|
||||
}
|
||||
}}>
|
||||
<PlusIcon />
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { ParseMarkdown, risuChatParser } from "src/ts/parser";
|
||||
import { DataBase, type Database, type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import { DBState, type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import { moduleBackgroundEmbedding, ReloadGUIPointer, selectedCharID } from "src/ts/stores";
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
let backgroundHTML = $state('')
|
||||
let lastdb:Database
|
||||
let backgroundHTML = $derived(DBState.db?.characters?.[$selectedCharID]?.backgroundHTML)
|
||||
let currentChar:character|groupChat = $state()
|
||||
let selectedId = 0
|
||||
|
||||
function checkUpdate(){
|
||||
if(selectedId > 0 && lastdb){
|
||||
if(lastdb.characters[selectedId] && lastdb.characters[selectedId].backgroundHTML !== backgroundHTML){
|
||||
backgroundHTML = lastdb.characters[selectedId].backgroundHTML
|
||||
currentChar = lastdb.characters[selectedId]
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(backgroundHTML !== ''){
|
||||
backgroundHTML = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unsubDatabase = DataBase.subscribe(v => {
|
||||
lastdb = v
|
||||
checkUpdate()
|
||||
})
|
||||
|
||||
const unsubID = selectedCharID.subscribe(v => {
|
||||
selectedId = v
|
||||
checkUpdate()
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
unsubDatabase()
|
||||
unsubID()
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -140,15 +140,13 @@
|
||||
}
|
||||
if(rerollid < rerolls.length - 1){
|
||||
if(Array.isArray(rerolls[rerollid + 1])){
|
||||
let db = DBState.db
|
||||
rerollid += 1
|
||||
let rerollData = structuredClone(rerolls[rerollid])
|
||||
let msgs = db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message
|
||||
let msgs = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message
|
||||
for(let i = 0; i < rerollData.length; i++){
|
||||
msgs[msgs.length - rerollData.length + i] = rerollData[i]
|
||||
}
|
||||
db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message = msgs
|
||||
DBState.db = db
|
||||
DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message = msgs
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -199,15 +197,13 @@
|
||||
return
|
||||
}
|
||||
if(Array.isArray(rerolls[rerollid - 1])){
|
||||
let db = DBState.db
|
||||
rerollid -= 1
|
||||
let rerollData = structuredClone(rerolls[rerollid])
|
||||
let msgs = db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message
|
||||
let msgs = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message
|
||||
for(let i = 0; i < rerollData.length; i++){
|
||||
msgs[msgs.length - rerollData.length + i] = rerollData[i]
|
||||
}
|
||||
db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message = msgs
|
||||
DBState.db = db
|
||||
DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].message = msgs
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
import PlaygroundSyntax from "./PlaygroundSyntax.svelte";
|
||||
import { findCharacterIndexbyId } from "src/ts/util";
|
||||
import { characterFormatUpdate, createBlankChar } from "src/ts/characters";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase, setDatabase, type character } from "src/ts/storage/database.svelte";
|
||||
import { DBState, type character } from "src/ts/storage/database.svelte";
|
||||
import PlaygroundImageGen from "./PlaygroundImageGen.svelte";
|
||||
import PlaygroundParser from "./PlaygroundParser.svelte";
|
||||
import ToolConvertion from "./ToolConvertion.svelte";
|
||||
@@ -18,17 +17,16 @@
|
||||
let easterEggTouch = $state(0)
|
||||
|
||||
const playgroundChat = () => {
|
||||
let db = get(DataBase)
|
||||
const charIndex = findCharacterIndexbyId('§playground')
|
||||
PlaygroundStore.set(2)
|
||||
|
||||
if (charIndex !== -1) {
|
||||
|
||||
const char = db.characters[charIndex] as character
|
||||
const char = DBState.db.characters[charIndex] as character
|
||||
char.utilityBot = true
|
||||
char.name = 'assistant'
|
||||
char.firstMessage = '{{none}}'
|
||||
db.characters[charIndex] = char
|
||||
DBState.db.characters[charIndex] = char
|
||||
characterFormatUpdate(charIndex)
|
||||
|
||||
selectedCharID.set(charIndex)
|
||||
@@ -38,8 +36,7 @@
|
||||
const character = createBlankChar()
|
||||
character.chaId = '§playground'
|
||||
|
||||
db.characters.push(character)
|
||||
setDatabase(db)
|
||||
DBState.db.characters.push(character)
|
||||
|
||||
playgroundChat()
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
import { language } from "src/lang";
|
||||
import { alertConfirm } from "src/ts/alert";
|
||||
import { checkDriver } from "src/ts/drive/drive";
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { isNodeServer, isTauri } from "src/ts/storage/globalApi";
|
||||
import { persistantStorageRecommended } from "src/ts/storage/persistant";
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
const option = await alertChatOptions()
|
||||
switch(option){
|
||||
case 0:{
|
||||
const newChat = structuredClone(chara.chats[i])
|
||||
const newChat = structuredClone($state.snapshot(chara.chats[i]))
|
||||
newChat.name = `Copy of ${newChat.name}`
|
||||
chara.chats.unshift(newChat)
|
||||
chara.chatPage = 0
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
const da = db.characterOrder[mainIndex.index]
|
||||
if(typeof(da) !== 'string'){
|
||||
mainId = da.id
|
||||
movingFolder = structuredClone(da)
|
||||
movingFolder = structuredClone($state.snapshot(da))
|
||||
if(targetIndex.folder){
|
||||
return
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
if(!latin1.test(enNotes)){
|
||||
alertError("English version of creator notes must contain only Latin-1 characters")
|
||||
}
|
||||
shareRisuHub2(char, {
|
||||
shareRisuHub2($state.snapshot(char) as character, {
|
||||
anon: privateMode,
|
||||
nsfw: nsfwMode,
|
||||
tag: tags,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { sleep } from "./util"
|
||||
import { language } from "../lang"
|
||||
import { isNodeServer, isTauri } from "./storage/globalApi"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
import { DataBase, type MessageGenerationInfo } from "./storage/database.svelte"
|
||||
import { getDatabase, type MessageGenerationInfo } from "./storage/database.svelte"
|
||||
|
||||
interface alertData{
|
||||
type: 'error'|'normal'|'none'|'ask'|'wait'|'selectChar'
|
||||
@@ -27,7 +27,7 @@ export const alertGenerationInfoStore = writable<AlertGenerationInfoStoreData>(n
|
||||
|
||||
export function alertError(msg:string){
|
||||
console.error(msg)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
if(typeof(msg) !== 'string'){
|
||||
try{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get, writable, type Writable } from "svelte/store"
|
||||
import { alertCardExport, alertConfirm, alertError, alertInput, alertMd, alertNormal, alertSelect, alertStore, alertTOS, alertWait } from "./alert"
|
||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook, type triggerscript, importPreset, type groupChat, setCurrentCharacter, getCurrentCharacter } from "./storage/database.svelte"
|
||||
import { defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook, type triggerscript, importPreset, type groupChat, setCurrentCharacter, getCurrentCharacter, getDatabase, setDatabaseLite } from "./storage/database.svelte"
|
||||
import { checkNullish, decryptBuffer, encryptBuffer, isKnownUri, selectFileByDom, selectMultipleFile, sleep } from "./util"
|
||||
import { language } from "src/lang"
|
||||
import { v4 as uuidv4, v4 } from 'uuid';
|
||||
@@ -52,13 +52,13 @@ async function importCharacterProcess(f:{
|
||||
const data = f.data instanceof Uint8Array ? f.data : new Uint8Array(await f.data.arrayBuffer())
|
||||
const da = JSON.parse(Buffer.from(data).toString('utf-8'))
|
||||
if(await importCharacterCardSpec(da)){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
return db.characters.length - 1
|
||||
}
|
||||
if((da.char_name || da.name) && (da.char_persona || da.description) && (da.char_greeting || da.first_mes)){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.characters.push(convertOffSpecCards(da))
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
alertNormal(language.importedCharacter)
|
||||
return
|
||||
}
|
||||
@@ -68,7 +68,7 @@ async function importCharacterProcess(f:{
|
||||
}
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.statics.imports += 1
|
||||
|
||||
if(f.name.endsWith('charx')){
|
||||
@@ -99,7 +99,7 @@ async function importCharacterProcess(f:{
|
||||
card.data.extensions.risuai.customScripts = md.regex ?? []
|
||||
}
|
||||
await importCharacterCardSpec(card, undefined, 'normal', reader.assets)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
return db.characters.length - 1
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ async function importCharacterProcess(f:{
|
||||
const decrypted = await decryptBuffer(encrypted, password)
|
||||
const charaData:CharacterCardV2Risu = JSON.parse(Buffer.from(decrypted).toString('utf-8'))
|
||||
if(await importCharacterCardSpec(charaData, img, "normal", assets)){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
return db.characters.length - 1
|
||||
}
|
||||
else{
|
||||
@@ -210,7 +210,7 @@ async function importCharacterProcess(f:{
|
||||
try {
|
||||
const charaData:CharacterCardV2Risu = JSON.parse(Buffer.from(decrypted).toString('utf-8'))
|
||||
if(await importCharacterCardSpec(charaData, img, "normal", assets)){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
return db.characters.length - 1
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -232,13 +232,13 @@ async function importCharacterProcess(f:{
|
||||
console.log(charaData)
|
||||
const imgp = await saveAsset(await reencodeImage(img))
|
||||
db.characters.push(convertOffSpecCards(charaData, imgp))
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
alertNormal(language.importedCharacter)
|
||||
return db.characters.length - 1
|
||||
}
|
||||
await importCharacterCardSpec(parsed, img, "normal", assets)
|
||||
|
||||
db = get(DataBase)
|
||||
db = getDatabase()
|
||||
return db.characters.length - 1
|
||||
|
||||
}
|
||||
@@ -319,7 +319,7 @@ export async function characterURLImport() {
|
||||
const importData = JSON.parse(Buffer.from(decodeURIComponent(data), 'base64').toString('utf-8'))
|
||||
importData.id = v4()
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(importData.lowLevelAccess){
|
||||
const conf = await alertConfirm(language.lowLevelAccessConfirm)
|
||||
if(!conf){
|
||||
@@ -363,7 +363,7 @@ export async function characterURLImport() {
|
||||
const module = new Uint8Array(await data.arrayBuffer())
|
||||
const md = await readModule(Buffer.from(module))
|
||||
md.id = v4()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.modules.push(md)
|
||||
setDatabase(db)
|
||||
alertNormal(language.successImport)
|
||||
@@ -447,7 +447,7 @@ export async function characterURLImport() {
|
||||
if(name.endsWith('risum')){
|
||||
const md = await readModule(Buffer.from(data))
|
||||
md.id = v4()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.modules.push(md)
|
||||
setDatabase(db)
|
||||
alertNormal(language.successImport)
|
||||
@@ -568,7 +568,7 @@ function convertOffSpecCards(charaData:OldTavernChar|CharacterCardV2Risu, imgp:s
|
||||
}
|
||||
|
||||
export async function exportChar(charaID:number):Promise<string> {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({snapshot: true})
|
||||
let char = structuredClone(db.characters[charaID])
|
||||
|
||||
if(char.type === 'group'){
|
||||
@@ -605,7 +605,7 @@ async function importCharacterCardSpec(card:CharacterCardV2Risu|CharacterCardV3,
|
||||
const data = card.data
|
||||
console.log(card)
|
||||
let im = img ? await saveAsset(await reencodeImage(img)) : undefined
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
const risuext = structuredClone(data.extensions.risuai)
|
||||
let emotions:[string, string][] = []
|
||||
@@ -1434,8 +1434,8 @@ export async function shareRisuHub2(char:character, arg:{
|
||||
headers: {
|
||||
"Content-Type": 'image/png',
|
||||
"x-risu-api-version": "4",
|
||||
"x-risu-token": get(DataBase)?.account?.token,
|
||||
'x-risu-username': arg.anon ? '' : (get(DataBase)?.account?.id),
|
||||
"x-risu-token": getDatabase()?.account?.token,
|
||||
'x-risu-username': arg.anon ? '' : (getDatabase()?.account?.id),
|
||||
'x-risu-debug': 'true',
|
||||
'x-risu-update-id': arg.update ? (char.realmId ?? 'null') : 'null'
|
||||
}
|
||||
@@ -1540,7 +1540,7 @@ export async function downloadRisuHub(id:string, arg:{
|
||||
data: res.body
|
||||
})
|
||||
checkCharOrder()
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.characters[db.characters.length-1] && (db.goCharacterOnImport || arg.forceRedirect)){
|
||||
const index = db.characters.length-1
|
||||
characterFormatUpdate(index);
|
||||
@@ -1557,7 +1557,7 @@ export async function downloadRisuHub(id:string, arg:{
|
||||
|
||||
await importCharacterCardSpec(data, await getHubResources(img), 'hub')
|
||||
checkCharOrder()
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.characters[db.characters.length-1] && (db.goCharacterOnImport || arg.forceRedirect)){
|
||||
const index = db.characters.length-1
|
||||
characterFormatUpdate(index);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc, type loreBook } from "./storage/database.svelte";
|
||||
import { saveImage, setDatabase, type character, type Chat, defaultSdDataFunc, type loreBook, getDatabase } from "./storage/database.svelte";
|
||||
import { alertAddCharacter, alertConfirm, alertError, alertNormal, alertSelect, alertStore, alertWait } from "./alert";
|
||||
import { language } from "../lang";
|
||||
import { decode as decodeMsgpack } from "msgpackr";
|
||||
@@ -16,7 +16,7 @@ import { doingChat } from "./process";
|
||||
import { importCharacter } from "./characterCards";
|
||||
|
||||
export function createNewCharacter() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.characters.push(createBlankChar())
|
||||
setDatabase(db)
|
||||
checkCharOrder()
|
||||
@@ -24,7 +24,7 @@ export function createNewCharacter() {
|
||||
}
|
||||
|
||||
export function createNewGroup(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.characters.push({
|
||||
type: 'group',
|
||||
name: "",
|
||||
@@ -45,7 +45,8 @@ export function createNewGroup(){
|
||||
chaId: uuidv4(),
|
||||
firstMsgIndex: -1,
|
||||
characterTalks: [],
|
||||
characterActive: []
|
||||
characterActive: [],
|
||||
realmId: ''
|
||||
})
|
||||
setDatabase(db)
|
||||
checkCharOrder()
|
||||
@@ -82,7 +83,7 @@ export async function selectCharImg(charIndex:number) {
|
||||
return
|
||||
}
|
||||
const img = selected.data
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const imgp = await saveImage(await reencodeImage(img))
|
||||
dumpCharImage(charIndex)
|
||||
db.characters[charIndex].image = imgp
|
||||
@@ -90,7 +91,7 @@ export async function selectCharImg(charIndex:number) {
|
||||
}
|
||||
|
||||
export function dumpCharImage(charIndex:number) {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const char = db.characters[charIndex] as character
|
||||
if(!char.image || char.image === ''){
|
||||
return
|
||||
@@ -108,7 +109,7 @@ export function dumpCharImage(charIndex:number) {
|
||||
}
|
||||
|
||||
export function changeCharImage(charIndex:number,changeIndex:number) {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const char = db.characters[charIndex] as character
|
||||
const image = char.ccAssets[changeIndex].uri
|
||||
char.ccAssets.splice(changeIndex, 1)
|
||||
@@ -128,7 +129,7 @@ export async function addCharEmotion(charId:number) {
|
||||
addingEmotion.set(false)
|
||||
return
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
for(const f of selected){
|
||||
const img = f.data
|
||||
const imgp = await saveImage(img)
|
||||
@@ -144,7 +145,7 @@ export async function addCharEmotion(charId:number) {
|
||||
}
|
||||
|
||||
export async function rmCharEmotion(charId:number, emotionId:number) {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let dbChar = db.characters[charId]
|
||||
if(dbChar.type !== 'group'){
|
||||
dbChar.emotionImages.splice(emotionId, 1)
|
||||
@@ -161,7 +162,7 @@ export async function exportChat(page:number){
|
||||
const doTranslate = (mode === '2' || mode === '3') ? (await alertSelect([language.translateContent, language.doNotTranslate])) === '0' : false
|
||||
const anonymous = (mode === '2' || mode === '3') ? ((await alertSelect([language.includePersonaName, language.hidePersonaName])) === '1') : false
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const chat = db.characters[selectedID].chats[page]
|
||||
const char = db.characters[selectedID]
|
||||
const date = new Date().toJSON();
|
||||
@@ -335,7 +336,7 @@ export async function importChat(){
|
||||
}
|
||||
try {
|
||||
const selectedID = get(selectedCharID)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
if(dat.name.endsWith('jsonl')){
|
||||
const lines = Buffer.from(dat.data).toString('utf-8').split('\n')
|
||||
@@ -412,14 +413,14 @@ export async function importChat(){
|
||||
}
|
||||
|
||||
function formatTavernChat(chat:string, charName:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return chat.replace(/<([Uu]ser)>|\{\{([Uu]ser)\}\}/g, getUserName()).replace(/((\{\{)|<)([Cc]har)(=.+)?((\}\})|>)/g, charName)
|
||||
}
|
||||
|
||||
export function characterFormatUpdate(index:number|character, arg:{
|
||||
updateInteraction?:boolean,
|
||||
} = {}){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let cha = typeof(index) === 'number' ? db.characters[index] : index
|
||||
if(cha.chats.length === 0){
|
||||
cha.chats = [{
|
||||
@@ -587,7 +588,7 @@ export async function makeGroupImage() {
|
||||
type: 'wait',
|
||||
msg: `Loading..`
|
||||
})
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charID = get(selectedCharID)
|
||||
const group = db.characters[charID]
|
||||
if(group.type !== 'group'){
|
||||
@@ -687,7 +688,7 @@ export async function addDefaultCharacters() {
|
||||
return
|
||||
}
|
||||
let char:character = va.data
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(char.emotionImages && char.emotionImages.length > 0){
|
||||
for(let i=0;i<char.emotionImages.length;i++){
|
||||
await sleep(10)
|
||||
@@ -720,7 +721,7 @@ export async function addDefaultCharacters() {
|
||||
}
|
||||
|
||||
export async function removeChar(index:number,name:string, type:'normal'|'permanent'|'permanentForce' = 'normal'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(type !== 'permanentForce'){
|
||||
const conf = await alertConfirm(language.removeConfirm + name)
|
||||
if(!conf){
|
||||
@@ -771,7 +772,7 @@ export async function addCharacter(arg:{
|
||||
MobileGUIStack.set(1)
|
||||
return
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.characters[db.characters.length-1]){
|
||||
changeChar(db.characters.length-1)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import { requestChatData } from "../process/request";
|
||||
import { checkCharOrder, globalFetch, isNodeServer, isTauri, saveAsset } from "../storage/globalApi";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { createBlankChar } from "../characters";
|
||||
import { DataBase, setDatabase, type character } from "../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { getDatabase, setDatabase, type character } from "../storage/database.svelte";
|
||||
import { sleep } from "../util";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
@@ -306,7 +305,7 @@ async function createBotFromWeb() {
|
||||
})
|
||||
const d = (sel === 0) ? (await createBotFromWebMain(search)) : (await createBotByAI(search))
|
||||
if(d.ok === 'creation'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const cha = d.data
|
||||
const fm = await createFirstMsg(cha.desc)
|
||||
if(fm.type === 'multiline' || fm.type === 'fail' || fm.type === 'streaming'){
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store"
|
||||
import { hubURL } from "../characterCards"
|
||||
import { DataBase } from "../storage/database.svelte"
|
||||
import { getDatabase } from "../storage/database.svelte"
|
||||
import { alertError, alertSelect } from "../alert"
|
||||
|
||||
export async function risuLogin() {
|
||||
@@ -14,7 +13,7 @@ export async function risuLogin() {
|
||||
}
|
||||
|
||||
export async function saveRisuAccountData() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
@@ -33,7 +32,7 @@ export async function saveRisuAccountData() {
|
||||
}
|
||||
|
||||
export async function loadRisuAccountData() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
@@ -52,7 +51,7 @@ export async function loadRisuAccountData() {
|
||||
}
|
||||
|
||||
export async function loadRisuAccountBackup() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
|
||||
@@ -2,9 +2,7 @@ import { BaseDirectory, readFile, readDir, writeFile } from "@tauri-apps/plugin-
|
||||
import { alertError, alertNormal, alertStore, alertWait } from "../alert";
|
||||
import { LocalWriter, forageStorage, isTauri } from "../storage/globalApi";
|
||||
import { decodeRisuSave, encodeRisuSave } from "../storage/risuSave";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { getDatabase, setDatabaseLite } from "../storage/database.svelte";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { sleep } from "../util";
|
||||
import { hubURL } from "../characterCards";
|
||||
@@ -32,7 +30,7 @@ export async function SaveLocalBackup(){
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(get(DataBase)),
|
||||
body: JSON.stringify(getDatabase()),
|
||||
})
|
||||
if(corrupted.status === 400){
|
||||
alertError('Failed, Backup data is corrupted')
|
||||
@@ -70,7 +68,7 @@ export async function SaveLocalBackup(){
|
||||
}
|
||||
}
|
||||
|
||||
const dbData = encodeRisuSave(get(DataBase), 'compression')
|
||||
const dbData = encodeRisuSave(getDatabase(), 'compression')
|
||||
|
||||
alertWait(`Saving local Backup... (Saving database)`)
|
||||
|
||||
@@ -113,7 +111,7 @@ export async function LoadLocalBackup(){
|
||||
if(name === 'database.risudat'){
|
||||
const db = new Uint8Array(data)
|
||||
const dbData = await decodeRisuSave(db)
|
||||
DataBase.set(dbData)
|
||||
setDatabaseLite(dbData)
|
||||
if(isTauri){
|
||||
await writeFile('database/database.bin', db, {baseDir: BaseDirectory.AppData})
|
||||
relaunch()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
|
||||
import { DataBase, type Database } from "../storage/database.svelte";
|
||||
import { getDatabase, type Database } from "../storage/database.svelte";
|
||||
import { forageStorage, getUnpargeables, isTauri, openURL } from "../storage/globalApi";
|
||||
import { BaseDirectory, exists, readFile, readDir, writeFile } from "@tauri-apps/plugin-fs";
|
||||
import { language } from "../../lang";
|
||||
@@ -109,7 +108,7 @@ let BackupDb:Database = null
|
||||
|
||||
|
||||
export async function syncDrive() {
|
||||
BackupDb = structuredClone(get(DataBase))
|
||||
BackupDb = structuredClone(getDatabase())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(get(DataBase)),
|
||||
body: JSON.stringify(getDatabase()),
|
||||
})
|
||||
if(corrupted.status === 400){
|
||||
alertError('Failed, Backup data is corrupted')
|
||||
@@ -177,7 +176,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
}
|
||||
}
|
||||
|
||||
const dbData = encodeRisuSave(get(DataBase), 'compression')
|
||||
const dbData = encodeRisuSave(getDatabase(), 'compression')
|
||||
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
@@ -206,7 +205,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
||||
const files:DriveFile[] = await getFilesInFolder(ACCESS_TOKEN)
|
||||
let foragekeys:string[] = []
|
||||
let loadedForageKeys = false
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
async function checkImageExists(images:string) {
|
||||
if(db?.account?.useSync){
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { getDatabase } from "../storage/database.svelte";
|
||||
|
||||
export function updateAnimationSpeed(){
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
document.documentElement.style.setProperty('--risu-animation-speed', db.animationSpeed + 's');
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, setDatabase } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabase } from "../storage/database.svelte";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { BufferToText, selectSingleFile } from "../util";
|
||||
import { alertError } from "../alert";
|
||||
@@ -115,7 +115,7 @@ export const ColorSchemeTypeStore = writable('dark' as 'dark'|'light')
|
||||
export const colorSchemeList = Object.keys(colorShemes) as (keyof typeof colorShemes)[]
|
||||
|
||||
export function changeColorScheme(colorScheme: string){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(colorScheme !== 'custom'){
|
||||
db.colorScheme = structuredClone(colorShemes[colorScheme])
|
||||
}
|
||||
@@ -125,7 +125,7 @@ export function changeColorScheme(colorScheme: string){
|
||||
}
|
||||
|
||||
export function updateColorScheme(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
let colorScheme = db.colorScheme
|
||||
|
||||
@@ -151,7 +151,7 @@ export function updateColorScheme(){
|
||||
}
|
||||
|
||||
export function exportColorScheme(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let json = JSON.stringify(db.colorScheme)
|
||||
downloadFile('colorScheme.json', json)
|
||||
}
|
||||
@@ -181,7 +181,7 @@ export async function importColorScheme(){
|
||||
return
|
||||
}
|
||||
changeColorScheme('custom')
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.colorScheme = colorScheme
|
||||
setDatabase(db)
|
||||
updateColorScheme()
|
||||
@@ -194,7 +194,7 @@ export async function importColorScheme(){
|
||||
}
|
||||
|
||||
export function updateTextThemeAndCSS(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const root = document.querySelector(':root') as HTMLElement;
|
||||
if(!root){
|
||||
return
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { writable } from "svelte/store";
|
||||
import { getDatabase } from "../storage/database.svelte";
|
||||
|
||||
export let textAreaSize = writable(0)
|
||||
export let sideBarSize = writable(0)
|
||||
export let textAreaTextSize = writable(0)
|
||||
|
||||
export function updateGuisize(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const root = document.querySelector(':root') as HTMLElement;
|
||||
if(!root){
|
||||
return
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { alertSelect, alertToast, doingAlert } from "./alert"
|
||||
import { DataBase, changeToPreset as changeToPreset2 } from "./storage/database.svelte"
|
||||
import { changeToPreset as changeToPreset2, getDatabase } from "./storage/database.svelte"
|
||||
import { MobileGUIStack, MobileSideBar, openPersonaList, openPresetList, SafeModeStore, selectedCharID, settingsOpen } from "./stores"
|
||||
import { language } from "src/lang"
|
||||
import { updateTextThemeAndCSS } from "./gui/colorscheme"
|
||||
@@ -197,7 +197,7 @@ export function initMobileGesture(){
|
||||
|
||||
function changeToPreset(num:number){
|
||||
if(!doingAlert()){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let pres = db.botPresets
|
||||
if(pres.length > num){
|
||||
alertToast(`Changed to Preset: ${pres[num].name}`)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { get } from "svelte/store"
|
||||
import { alertNormal, alertSelect } from "../alert"
|
||||
import { keiServerURL } from "./kei"
|
||||
import { DataBase, setDatabase } from "../storage/database.svelte"
|
||||
import { getDatabase, setDatabase } from "../storage/database.svelte"
|
||||
|
||||
export async function autoServerBackup(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const res = await fetch(keiServerURL() + '/autobackup/list', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -81,7 +80,7 @@ export async function autoServerBackup(){
|
||||
let lastKeiSave = 0
|
||||
export async function saveDbKei() {
|
||||
try{
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.account.kei){
|
||||
if(Date.now() - lastKeiSave < 60000 * 5){
|
||||
return
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { get } from "svelte/store";
|
||||
import { hubURL } from "../characterCards";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { getDatabase } from "../storage/database.svelte";
|
||||
|
||||
export function keiServerURL(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(db.keiServerURL) return db.keiServerURL;
|
||||
return hubURL + "/kei";
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase } from "../storage/database.svelte"
|
||||
import { getDatabase } from "../storage/database.svelte"
|
||||
|
||||
export async function openRouterModels() {
|
||||
try {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let headers = {
|
||||
"Authorization": "Bearer " + db.openrouterKey,
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
import markdownit from 'markdown-it'
|
||||
import { DataBase, getCurrentCharacter, setDatabase, type Database, type Message, type character, type customscript, type groupChat, type triggerscript } from './storage/database.svelte';
|
||||
import { getCurrentCharacter, getDatabase, setDatabase, type Database, type Message, type character, type customscript, type groupChat, type triggerscript } from './storage/database.svelte';
|
||||
import { getFileSrc } from './storage/globalApi';
|
||||
import { processScriptFull } from './process/scripts';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -75,7 +75,7 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
|
||||
|
||||
function renderMarkdown(md:markdownit, data:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let quotes = ['“', '”', '‘', '’']
|
||||
if(db?.customQuotes){
|
||||
quotes = db.customQuotesData ?? quotes
|
||||
@@ -254,7 +254,7 @@ async function renderHighlightableMarkdown(data:string) {
|
||||
export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/g
|
||||
|
||||
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const assetWidthString = (db.assetWidth && db.assetWidth !== -1 || db.assetWidth === 0) ? `max-width:${db.assetWidth}rem;` : ''
|
||||
|
||||
let assetPaths:{[key:string]:{
|
||||
@@ -500,7 +500,7 @@ export async function hasher(data:Uint8Array){
|
||||
}
|
||||
|
||||
export async function convertImage(data:Uint8Array) {
|
||||
if(!get(DataBase).imageCompression){
|
||||
if(!getDatabase().imageCompression){
|
||||
return data
|
||||
}
|
||||
const type = checkImageType(data)
|
||||
@@ -1775,7 +1775,7 @@ export function risuChatParser(da:string, arg:{
|
||||
cbsConditions?:CbsConditions
|
||||
} = {}):string{
|
||||
const chatID = arg.chatID ?? -1
|
||||
const db = arg.db ?? get(DataBase)
|
||||
const db = arg.db ?? getDatabase()
|
||||
const aChara = arg.chara
|
||||
const visualize = arg.visualize ?? false
|
||||
let chara:character|string = null
|
||||
@@ -1797,7 +1797,7 @@ export function risuChatParser(da:string, arg:{
|
||||
}
|
||||
}
|
||||
if(arg.tokenizeAccurate){
|
||||
const db = arg.db ?? get(DataBase)
|
||||
const db = arg.db ?? getDatabase()
|
||||
const selchar = chara ?? db.characters[get(selectedCharID)]
|
||||
if(!selchar){
|
||||
chara = 'bot'
|
||||
@@ -2103,7 +2103,7 @@ export function risuChatParser(da:string, arg:{
|
||||
|
||||
|
||||
export function getChatVar(key:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(!char){
|
||||
@@ -2126,12 +2126,12 @@ export function getChatVar(key:string){
|
||||
}
|
||||
|
||||
export function getGlobalChatVar(key:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.globalChatVariables[key] ?? 'null'
|
||||
}
|
||||
|
||||
export function setChatVar(key:string, value:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, saveImage, setDatabase } from "./storage/database.svelte"
|
||||
import { getDatabase, saveImage, setDatabase } from "./storage/database.svelte"
|
||||
import { getUserName, selectSingleFile, sleep } from "./util"
|
||||
import { alertError, alertNormal, alertStore } from "./alert"
|
||||
import { downloadFile, readImage } from "./storage/globalApi"
|
||||
@@ -14,7 +14,7 @@ export async function selectUserImg() {
|
||||
return
|
||||
}
|
||||
const img = selected.data
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const imgp = await saveImage(img)
|
||||
db.userIcon = imgp
|
||||
db.personas[db.selectedPersona] = {
|
||||
@@ -27,7 +27,7 @@ export async function selectUserImg() {
|
||||
}
|
||||
|
||||
export function saveUserPersona() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.personas[db.selectedPersona].name=db.username
|
||||
db.personas[db.selectedPersona].icon=db.userIcon,
|
||||
db.personas[db.selectedPersona].personaPrompt=db.personaPrompt,
|
||||
@@ -39,7 +39,7 @@ export function changeUserPersona(id:number, save:'save'|'noSave' = 'save') {
|
||||
if(save === 'save'){
|
||||
saveUserPersona()
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const pr = db.personas[id]
|
||||
db.personaPrompt = pr.personaPrompt
|
||||
db.username = pr.name,
|
||||
@@ -56,7 +56,7 @@ interface PersonaCard {
|
||||
}
|
||||
|
||||
export async function exportUserPersona(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase({snapshot: true})
|
||||
if(!db.userIcon){
|
||||
alertError(language.errors.noUserIcon)
|
||||
return
|
||||
@@ -107,7 +107,7 @@ export async function importUserPersona(){
|
||||
}
|
||||
const data:PersonaCard = JSON.parse(Buffer.from(decoded, 'base64').toString('utf-8'))
|
||||
if(data.name && data.personaPrompt){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.personas.push({
|
||||
name: data.name,
|
||||
icon: await saveImage(await reencodeImage(v.data)),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { get } from 'svelte/store'
|
||||
import type { ScriptMode } from '../process/scripts'
|
||||
//@ts-ignore
|
||||
import WorkerUrl from './embedworker?worker&url'
|
||||
import { DataBase, type Message } from '../storage/database.svelte'
|
||||
import { getDatabase, type Message } from '../storage/database.svelte'
|
||||
import { selectedCharID } from '../stores'
|
||||
import { setDatabase } from '../storage/database.svelte'
|
||||
|
||||
@@ -77,14 +77,16 @@ function runVirtualJS(code:string){
|
||||
}
|
||||
|
||||
addWorkerFunction('getChat', async () => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return structuredClone(char.chats[char.chatPage].message)
|
||||
})
|
||||
|
||||
addWorkerFunction('setChat', async (data:Message[]) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
let newChat:Message[] = []
|
||||
for(const dat of data){
|
||||
@@ -117,14 +119,14 @@ addWorkerFunction('setChat', async (data:Message[]) => {
|
||||
})
|
||||
|
||||
addWorkerFunction('getName', async () => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.name
|
||||
})
|
||||
|
||||
addWorkerFunction('setName', async (data:string) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof data !== 'string'){
|
||||
return false
|
||||
@@ -135,7 +137,7 @@ addWorkerFunction('setName', async (data:string) => {
|
||||
})
|
||||
|
||||
addWorkerFunction('getDescription', async () => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(char.type === 'group'){
|
||||
@@ -145,7 +147,7 @@ addWorkerFunction('getDescription', async () => {
|
||||
})
|
||||
|
||||
addWorkerFunction('setDescription', async (data:string) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char =db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -161,14 +163,14 @@ addWorkerFunction('setDescription', async (data:string) => {
|
||||
})
|
||||
|
||||
addWorkerFunction('getCharacterFirstMessage', async () => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.firstMessage
|
||||
})
|
||||
|
||||
addWorkerFunction('setCharacterFirstMessage', async (data:string) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -181,14 +183,14 @@ addWorkerFunction('setCharacterFirstMessage', async (data:string) => {
|
||||
})
|
||||
|
||||
addWorkerFunction('getBackgroundEmbedding', async () => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.backgroundHTML
|
||||
})
|
||||
|
||||
addWorkerFunction('setBackgroundEmbedding', async (data:string) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof data !== 'string'){
|
||||
return false
|
||||
@@ -200,7 +202,7 @@ addWorkerFunction('setBackgroundEmbedding', async (data:string) => {
|
||||
|
||||
|
||||
addWorkerFunction('getState', async (statename) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -208,7 +210,7 @@ addWorkerFunction('getState', async (statename) => {
|
||||
})
|
||||
|
||||
addWorkerFunction('setState', async (statename, data) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -245,7 +247,7 @@ export async function runCharacterJS(arg:{
|
||||
}):Promise<any>{
|
||||
try {
|
||||
if(arg.code === null){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
arg.code = db.characters[selectedChar].virtualscript
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { language } from "../../lang";
|
||||
import { alertError } from "../alert";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabaseLite } from "../storage/database.svelte";
|
||||
import { checkNullish, selectSingleFile, sleep } from "../util";
|
||||
import type { OpenAIChat } from "../process";
|
||||
import { globalFetch } from "../storage/globalApi";
|
||||
@@ -29,7 +29,7 @@ export type RisuPlugin = ProviderPlugin
|
||||
|
||||
export async function importPlugin(){
|
||||
try {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const f = await selectSingleFile(['js'])
|
||||
if(!f){
|
||||
return
|
||||
@@ -96,7 +96,7 @@ export async function importPlugin(){
|
||||
db.plugins ??= []
|
||||
db.plugins.push(pluginData)
|
||||
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
loadPlugins()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
@@ -123,7 +123,7 @@ function postMsgPluginWorker(type:string, body:any){
|
||||
let pluginTranslator = false
|
||||
|
||||
export async function loadPlugins() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(pluginWorker){
|
||||
pluginWorker.terminate()
|
||||
pluginWorker = null
|
||||
@@ -219,7 +219,7 @@ export async function loadPlugins() {
|
||||
}
|
||||
case "getArg":{
|
||||
try {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const arg:string[] = data.body.arg.split('::')
|
||||
for(const plug of db.plugins){
|
||||
if(arg[0] === plug.name){
|
||||
@@ -243,7 +243,7 @@ export async function loadPlugins() {
|
||||
break
|
||||
}
|
||||
case "getChar":{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charid = get(selectedCharID)
|
||||
const char = db.characters[charid]
|
||||
postMsgPluginWorker('fetchData',{
|
||||
@@ -253,7 +253,7 @@ export async function loadPlugins() {
|
||||
break
|
||||
}
|
||||
case "setChar":{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charid = get(selectedCharID)
|
||||
db.characters[charid] = data.body
|
||||
break
|
||||
@@ -303,7 +303,7 @@ export async function pluginProcess(arg:{
|
||||
bias: {[key:string]:string}
|
||||
}|{}){
|
||||
try {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(!pluginWorker){
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentChat, setDatabase } from "../storage/database.svelte";
|
||||
import { selectedCharID } from "../stores";
|
||||
import { alertInput, alertMd, alertNormal, alertSelect, alertToast } from "../alert";
|
||||
import { sayTTS } from "./tts";
|
||||
@@ -40,7 +40,7 @@ export async function processMultiCommand(command:string) {
|
||||
|
||||
|
||||
async function processCommand(command:string, pipe:string):Promise<false | string>{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const currentChar = db.characters[get(selectedCharID)]
|
||||
const currentChat = currentChar.chats[currentChar.chatPage]
|
||||
let {commandName, arg, namedArg} = commandParser(command, pipe)
|
||||
@@ -180,7 +180,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
}
|
||||
case 'setvar':{
|
||||
console.log(namedArg, arg)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -194,7 +194,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
return ''
|
||||
}
|
||||
case 'addvar':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -207,7 +207,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
return ''
|
||||
}
|
||||
case 'getvar':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { DataBase, type Chat, type character } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase, type Chat, type character } from "src/ts/storage/database.svelte";
|
||||
import { HypaProcesser } from '../memory/hypamemory'
|
||||
import type { OpenAIChat } from "..";
|
||||
import { stringlizeChat } from "../stringlize";
|
||||
import { get } from "svelte/store";
|
||||
import { getUserName } from "src/ts/util";
|
||||
|
||||
export async function additionalInformations(char: character,chats:Chat,){
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
const info = char.additionalText
|
||||
if(info){
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import localforage from "localforage";
|
||||
import { selectSingleFile } from "../../util";
|
||||
import { v4 } from "uuid";
|
||||
import { DataBase } from "../../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { getDatabase } from "../../storage/database.svelte";
|
||||
import { checkImageType } from "../../parser";
|
||||
|
||||
const inlayStorage = localforage.createInstance({
|
||||
@@ -85,7 +83,7 @@ export async function getInlayImage(id: string){
|
||||
}
|
||||
|
||||
export function supportsInlayImage(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.aiModel.startsWith('gptv') || db.aiModel === 'gemini-pro-vision' || db.aiModel.startsWith('claude-3') || db.aiModel.startsWith('gpt4_turbo') || db.aiModel.startsWith('gpt5') || db.aiModel.startsWith('gpt4o') ||
|
||||
(db.aiModel === 'reverse_proxy' && (
|
||||
db.proxyRequestModel?.startsWith('gptv') || db.proxyRequestModel === 'gemini-pro-vision' || db.proxyRequestModel?.startsWith('claude-3') || db.proxyRequestModel.startsWith('gpt4_turbo') ||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DataBase, setDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { getDatabase, setDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { selectedCharID } from 'src/ts/stores';
|
||||
import { get } from 'svelte/store';
|
||||
import { doingChat, sendChat } from '..';
|
||||
@@ -19,7 +19,7 @@ async function sendPofile(arg:sendFileArg){
|
||||
let note = ''
|
||||
let speaker = ''
|
||||
let parseMode = 0
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let currentChar = db.characters[get(selectedCharID)]
|
||||
let currentChat = currentChar.chats[currentChar.chatPage]
|
||||
const lines = arg.file.split('\n')
|
||||
|
||||
@@ -3,11 +3,11 @@ import { findCharacterbyId } from "../util";
|
||||
import { alertConfirm, alertError, alertSelectChar } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase, setDatabase } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabase } from "../storage/database.svelte";
|
||||
import { selectedCharID } from "../stores";
|
||||
|
||||
export async function addGroupChar(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedId = get(selectedCharID)
|
||||
let group = db.characters[selectedId]
|
||||
if(group.type === 'group'){
|
||||
@@ -36,7 +36,7 @@ export async function addGroupChar(){
|
||||
|
||||
|
||||
export function rmCharFromGroup(index:number){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedId = get(selectedCharID)
|
||||
let group = db.characters[selectedId]
|
||||
if(group.type === 'group'){
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, setDatabase, type character, type MessageGenerationInfo, type Chat } from "../storage/database.svelte";
|
||||
import { setDatabase, type character, type MessageGenerationInfo, type Chat, getDatabase, setDatabaseLite } from "../storage/database.svelte";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { language } from "../../lang";
|
||||
import { alertError } from "../alert";
|
||||
import { loadLoreBookPrompt, loadLoreBookV3Prompt } from "./lorebook";
|
||||
import { loadLoreBookV3Prompt } from "./lorebook";
|
||||
import { findCharacterbyId, getAuthorNoteDefaultText, getPersonaPrompt, getUserName, isLastCharPunctuation, trimUntilPunctuation } from "../util";
|
||||
import { requestChatData } from "./request";
|
||||
import { stableDiff } from "./stableDiff";
|
||||
@@ -120,7 +120,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
chatProcessStage.set(0)
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.statics.messages += 1
|
||||
let selectedChar = get(selectedCharID)
|
||||
const nowChatroom = db.characters[selectedChar]
|
||||
@@ -783,7 +783,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
currentChat.hypaV2Data = sp.memory ?? currentChat.hypaV2Data
|
||||
db.characters[selectedChar].chats[selectedChat].hypaV2Data = currentChat.hypaV2Data
|
||||
console.log(currentChat.hypaV2Data)
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
}
|
||||
else{
|
||||
const sp = await supaMemory(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer, {
|
||||
@@ -798,7 +798,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
currentChat.supaMemoryData = sp.memory ?? currentChat.supaMemoryData
|
||||
db.characters[selectedChar].chats[selectedChat].supaMemoryData = currentChat.supaMemoryData
|
||||
console.log(currentChat.supaMemoryData)
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
currentChat.lastMemory = sp.lastId ?? currentChat.lastMemory;
|
||||
}
|
||||
chatProcessStage.set(1)
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import { get } from "svelte/store";
|
||||
import {selectedCharID} from '../stores'
|
||||
import { DataBase, setDatabase, type Message, type loreBook } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabase, type Message, type loreBook } from "../storage/database.svelte";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { checkNullish, selectSingleFile } from "../util";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "../../lang";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
import { getModuleLorebooks } from "./modules";
|
||||
import { CCardLib } from "@risuai/ccardlib";
|
||||
|
||||
export function addLorebook(type:number) {
|
||||
let selectedID = get(selectedCharID)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(type === 0){
|
||||
db.characters[selectedID].globalLore.push({
|
||||
key: '',
|
||||
@@ -54,7 +53,7 @@ const rmRegex = / |\n/g
|
||||
export async function loadLoreBookPrompt(){
|
||||
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const char = db.characters[selectedID]
|
||||
const page = char.chatPage
|
||||
const characterLore = char.globalLore ?? []
|
||||
@@ -209,7 +208,7 @@ export async function loadLoreBookPrompt(){
|
||||
|
||||
export async function loadLoreBookV3Prompt(){
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const char = db.characters[selectedID]
|
||||
const page = char.chatPage
|
||||
const characterLore = char.globalLore ?? []
|
||||
@@ -531,7 +530,7 @@ export async function loadLoreBookV3Prompt(){
|
||||
|
||||
export async function importLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
const selectedID = get(selectedCharID)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const page = mode === 'sglobal' ? -1 : db.characters[selectedID].chatPage
|
||||
let lore =
|
||||
mode === 'global' ? db.characters[selectedID].globalLore :
|
||||
@@ -613,7 +612,7 @@ export function convertExternalLorebook(entries:{[key:string]:CCLorebook}){
|
||||
export async function exportLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
try {
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const page = mode === 'sglobal' ? -1 : db.characters[selectedID].chatPage
|
||||
const lore =
|
||||
mode === 'global' ? db.characters[selectedID].globalLore :
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getChatVar, hasher, risuChatParser, setChatVar, type simpleCharacterArgument } from "../parser";
|
||||
import { getChatVar, hasher, setChatVar, type simpleCharacterArgument } from "../parser";
|
||||
import { LuaEngine, LuaFactory } from "wasmoon";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { ReloadGUIPointer, selectedCharID } from "../stores";
|
||||
import { alertError, alertInput, alertNormal } from "../alert";
|
||||
@@ -332,7 +332,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.name
|
||||
@@ -342,7 +342,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof name !== 'string'){
|
||||
throw('Invalid data type')
|
||||
@@ -355,7 +355,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char =db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -373,7 +373,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -389,7 +389,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.firstMessage
|
||||
@@ -399,7 +399,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.backgroundHTML
|
||||
@@ -409,7 +409,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof data !== 'string'){
|
||||
return false
|
||||
|
||||
@@ -3,8 +3,7 @@ import type { OpenAIChat } from "..";
|
||||
import { HypaProcesser } from "./hypamemory";
|
||||
import { language } from "src/lang";
|
||||
import type { ChatTokenizer } from "src/ts/tokenizer";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase } from "src/ts/storage/database.svelte";
|
||||
|
||||
const maxRecentChatQuery = 4;
|
||||
export async function hanuraiMemory(chats:OpenAIChat[],arg:{
|
||||
@@ -12,7 +11,7 @@ export async function hanuraiMemory(chats:OpenAIChat[],arg:{
|
||||
maxContextTokens:number,
|
||||
tokenizer:ChatTokenizer
|
||||
}){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const tokenizer = arg.tokenizer
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
let addTexts:string[] = []
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { DataBase, type Chat, type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase, type Chat, type character, type groupChat } from "src/ts/storage/database.svelte";
|
||||
import type { OpenAIChat } from "..";
|
||||
import type { ChatTokenizer } from "src/ts/tokenizer";
|
||||
import { get } from "svelte/store";
|
||||
import { requestChatData } from "../request";
|
||||
import { HypaProcesser } from "./hypamemory";
|
||||
import { globalFetch } from "src/ts/storage/globalApi";
|
||||
import { runSummarizer } from "../transformers";
|
||||
import { last, remove } from "lodash";
|
||||
|
||||
export interface HypaV2Data {
|
||||
chunks: {
|
||||
@@ -20,7 +18,7 @@ export interface HypaV2Data {
|
||||
}
|
||||
|
||||
async function summary(stringlizedChat: string): Promise<{ success: boolean; data: string }> {
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
console.log("Summarizing");
|
||||
|
||||
if (db.supaModelType === 'distilbart') {
|
||||
@@ -123,7 +121,7 @@ export async function hypaMemoryV2(
|
||||
arg: { asHyper?: boolean, summaryModel?: string, summaryPrompt?: string, hypaModel?: string } = {}
|
||||
): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?: string; memory?: HypaV2Data; }> {
|
||||
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
const data: HypaV2Data = room.hypaV2Data ?? { chunks: [], mainChunks: [] };
|
||||
|
||||
let allocatedTokens = db.hypaAllocatedTokens;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from "..";
|
||||
import { DataBase, type Chat, type character, type groupChat } from "../../storage/database.svelte";
|
||||
import { getDatabase, type Chat, type character, type groupChat } from "../../storage/database.svelte";
|
||||
import { tokenize, type ChatTokenizer } from "../../tokenizer";
|
||||
import { requestChatData } from "../request";
|
||||
import { HypaProcesser } from "./hypamemory";
|
||||
@@ -18,7 +17,7 @@ export async function supaMemory(
|
||||
tokenizer:ChatTokenizer,
|
||||
arg:{asHyper?:boolean} = {}
|
||||
): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string;lastId?:string}>{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
currentTokens += 10
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import { sleep } from "src/ts/util";
|
||||
import * as path from "@tauri-apps/api/path";
|
||||
import { exists, readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { alertClear, alertError, alertMd, alertWait } from "src/ts/alert";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase } from "src/ts/storage/database.svelte";
|
||||
let serverRunning = false;
|
||||
|
||||
export function checkLocalModel():Promise<string>{
|
||||
@@ -130,7 +129,7 @@ export async function loadExllamaFull(){
|
||||
|
||||
|
||||
async function runLocalModelOld(prompt:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
if(!serverRunning){
|
||||
await loadExllamaFull()
|
||||
@@ -273,7 +272,7 @@ export async function runGGUFModel(arg:{
|
||||
|
||||
export async function tokenizeGGUFModel(prompt:string):Promise<number[]> {
|
||||
const key = await getLocalKey()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const modelPath = db.aiModel.replace('local_', '')
|
||||
const b = await fetch("http://localhost:10026/llamacpp/tokenize", {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { getDatabase } from "src/ts/storage/database.svelte";
|
||||
|
||||
export function getGenerationModelString(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
switch (db.aiModel){
|
||||
case 'reverse_proxy':
|
||||
return 'reverse_proxy-' + (db.reverseProxyOobaMode ? 'ooba' : db.proxyRequestModel)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { DataBase, setDatabase } from "src/ts/storage/database.svelte"
|
||||
import { getDatabase, setDatabase } from "src/ts/storage/database.svelte"
|
||||
import type { OpenAIChat } from ".."
|
||||
import { get } from "svelte/store"
|
||||
import { globalFetch } from "src/ts/storage/globalApi"
|
||||
import { alertError, alertInput, alertNormal, alertWait } from "src/ts/alert"
|
||||
import { getUserName, sleep } from "src/ts/util"
|
||||
|
||||
export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued: boolean){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let seperator = db.NAIsettings.seperator.replaceAll("\\n","\n") || '\n'
|
||||
let starter = db.NAIsettings.starter.replaceAll("\\n","\n") || '⁂'
|
||||
let resultString:string[] = []
|
||||
@@ -109,7 +108,7 @@ export const novelLogin = async () => {
|
||||
|
||||
const data = r.data?.accessToken
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.novelai.token = data
|
||||
|
||||
alertNormal('Logged in to NovelAI')
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { language } from "src/lang"
|
||||
import { alertConfirm, alertError, alertModuleSelect, alertNormal, alertStore } from "../alert"
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentCharacter, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database.svelte"
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentCharacter, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database.svelte"
|
||||
import { AppendableBuffer, downloadFile, isNodeServer, isTauri, readImage, saveAsset } from "../storage/globalApi"
|
||||
import { get } from "svelte/store"
|
||||
import { selectSingleFile, sleep } from "../util"
|
||||
import { v4 } from "uuid"
|
||||
import { convertExternalLorebook } from "./lorebook"
|
||||
@@ -171,7 +170,7 @@ export async function importModule(){
|
||||
return
|
||||
}
|
||||
let fileData = f.data
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(f.name.endsWith('.risum')){
|
||||
try {
|
||||
const buf = Buffer.from(fileData)
|
||||
@@ -248,7 +247,7 @@ export async function importModule(){
|
||||
}
|
||||
|
||||
function getModuleById(id:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(let i=0;i<db.modules.length;i++){
|
||||
if(db.modules[i].id === id){
|
||||
return db.modules[i]
|
||||
@@ -259,7 +258,7 @@ function getModuleById(id:string){
|
||||
|
||||
function getModuleByIds(ids:string[]){
|
||||
let modules:RisuModule[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(let i=0;i<ids.length;i++){
|
||||
const module = db.modules.find((m) => m.id === ids[i] || (m.namespace === ids[i] && m.namespace))
|
||||
if(module){
|
||||
@@ -273,7 +272,7 @@ let lastModules = ''
|
||||
let lastModuleData:RisuModule[] = []
|
||||
export function getModules(){
|
||||
const currentChat = getCurrentChat()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let ids = db.enabledModules ?? []
|
||||
if (currentChat){
|
||||
ids = ids.concat(currentChat.modules ?? [])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { tokenizeAccurate } from "../tokenizer";
|
||||
import { DataBase, presetTemplate, setDatabase, type Database } from "../storage/database.svelte";
|
||||
import { getDatabase, presetTemplate, setDatabase, type Database } from "../storage/database.svelte";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import type { OobaChatCompletionRequestParams } from "../model/ooba";
|
||||
|
||||
@@ -383,7 +383,7 @@ export function promptConvertion(files:{ name: string, content: string, type:str
|
||||
if(type === 'STCHAT'){
|
||||
preset.aiModel = 'openrouter'
|
||||
preset.subModel = 'openrouter'
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.botPresets.push(preset)
|
||||
setDatabase(db)
|
||||
|
||||
@@ -461,7 +461,7 @@ export function promptConvertion(files:{ name: string, content: string, type:str
|
||||
preset.name ||= 'Converted from JSON'
|
||||
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.botPresets.push(preset)
|
||||
setDatabase(db)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { MultiModal, OpenAIChat, OpenAIChatFull } from ".";
|
||||
import { DataBase, type character } from "../storage/database.svelte";
|
||||
import { getDatabase, type character } from "../storage/database.svelte";
|
||||
import { pluginProcess } from "../plugins/plugins";
|
||||
import { language } from "../../lang";
|
||||
import { stringlizeAINChat, stringlizeChat, getStopStrings, unstringlizeAIN, unstringlizeChat } from "./stringlize";
|
||||
@@ -88,7 +88,7 @@ type ParameterMap = {
|
||||
};
|
||||
|
||||
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap = {}) {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(const parameter of parameters){
|
||||
let value = 0
|
||||
switch(parameter){
|
||||
@@ -136,7 +136,7 @@ function applyParameters(data: { [key: string]: any }, parameters: Parameter[],
|
||||
}
|
||||
|
||||
export async function requestChatData(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let trys = 0
|
||||
while(true){
|
||||
const da = await requestChatDataMain(arg, model, abortSignal)
|
||||
@@ -178,7 +178,7 @@ export interface OpenAIChatExtra {
|
||||
|
||||
|
||||
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let formated = structuredClone(arg.formated)
|
||||
let maxTokens = arg.maxTokens ??db.maxResponse
|
||||
let temperature = arg.temperature ?? (db.temperature / 100)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { DataBase, setDatabase, type character, type customscript, type groupChat, type Database } from "../storage/database.svelte";
|
||||
import { type character, type customscript, type groupChat, type Database, getDatabase } from "../storage/database.svelte";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
@@ -27,7 +27,7 @@ export async function processScript(char:character|groupChat, data:string, mode:
|
||||
}
|
||||
|
||||
export function exportRegex(s?:customscript[]){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const script = s ?? db.globalscript
|
||||
const data = Buffer.from(JSON.stringify({
|
||||
type: 'regex',
|
||||
@@ -43,7 +43,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
if(!filedata){
|
||||
return o
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
try {
|
||||
const imported= JSON.parse(Buffer.from(filedata).toString('utf-8'))
|
||||
if(imported.type === 'regex' && imported.data){
|
||||
@@ -67,7 +67,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
let bestMatchCache = new Map<string, string>()
|
||||
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||
data = await runCharacterJS({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, type character } from "../storage/database.svelte"
|
||||
import { getDatabase, type character } from "../storage/database.svelte"
|
||||
import { requestChatData } from "./request"
|
||||
import { alertError } from "../alert"
|
||||
import { globalFetch, readImage } from "../storage/globalApi"
|
||||
@@ -8,7 +8,7 @@ import type { OpenAIChat } from "."
|
||||
import { processZip } from "./processzip"
|
||||
import { keiServerURL } from "../kei/kei"
|
||||
export async function stableDiff(currentChar:character,prompt:string){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
if(db.sdProvider === ''){
|
||||
alertError("Stable diffusion is not set in settings.")
|
||||
@@ -56,7 +56,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}
|
||||
|
||||
export async function generateAIImage(genPrompt:string, currentChar:character, neg:string, returnSdData:string):Promise<string|false>{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
console.log(db.sdProvider)
|
||||
if(db.sdProvider === 'webui'){
|
||||
|
||||
@@ -490,7 +490,7 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
}
|
||||
}
|
||||
if(db.sdProvider === 'kei'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let auth = db?.account?.token
|
||||
if(!auth){
|
||||
db.account = JSON.parse(localStorage.getItem("fallbackRisuToken"))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { getDatabase } from "../storage/database.svelte";
|
||||
import { getUserName } from "../util";
|
||||
|
||||
export function multiChatReplacer(){
|
||||
@@ -41,7 +40,7 @@ function appendWhitespace(prefix:string, seperator:string=" ") {
|
||||
return prefix
|
||||
}
|
||||
export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, suggesting:boolean, continued:boolean){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let resultString:string[] = []
|
||||
let { systemPrefix, userPrefix, assistantPrefix, seperator } = db.ooba.formating;
|
||||
systemPrefix = systemPrefix ?? ""
|
||||
@@ -103,7 +102,7 @@ function toTitleCase(s:string){
|
||||
return s[0].toUpperCase() + s.slice(1).toLowerCase()
|
||||
}
|
||||
export function getStopStrings(suggesting:boolean=false){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let { userPrefix, seperator } = db.ooba.formating;
|
||||
if(!seperator){
|
||||
seperator = "\n"
|
||||
@@ -160,7 +159,7 @@ export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string
|
||||
export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:'ain'|'normal' = 'normal'){
|
||||
let chunks:string[] = ["system note:", "system:","system note:", "system:"]
|
||||
let charNames:string[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(char){
|
||||
charNames.push(char)
|
||||
if(mode === 'ain'){
|
||||
@@ -212,7 +211,7 @@ export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:
|
||||
|
||||
export function stringlizeAINChat(formated:OpenAIChat[], char:string, continued: boolean){
|
||||
let resultString:string[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
for(const form of formated){
|
||||
console.log(form)
|
||||
@@ -292,7 +291,7 @@ function extractAINOutputStrings(inputString:string, characters:string[]) {
|
||||
|
||||
export function unstringlizeAIN(data:string,formated:OpenAIChat[], char:string = ''){
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const chunksResult = getUnstringlizerChunks(formated, char ,'ain')
|
||||
const chunks = chunksResult.chunks
|
||||
let result:['char'|'user',string][] = []
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Template } from '@huggingface/jinja';
|
||||
import type { OpenAIChat } from '..';
|
||||
import { get } from 'svelte/store';
|
||||
import { DataBase, getCurrentCharacter } from 'src/ts/storage/database.svelte';
|
||||
import { getCurrentCharacter, getDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { getUserName } from 'src/ts/util';
|
||||
|
||||
export const chatTemplates = {
|
||||
@@ -29,7 +28,7 @@ export const applyChatTemplate = (messages:OpenAIChat[], arg:{
|
||||
type?: string
|
||||
custom?: string
|
||||
} = {}) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const currentChar = getCurrentCharacter()
|
||||
const type = arg.type ?? db.instructChatTemplate
|
||||
if(!type){
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { DataBase, setPreset, type botPreset, setDatabase } from "src/ts/storage/database.svelte";
|
||||
import { setPreset, type botPreset, setDatabase, getDatabase } from "src/ts/storage/database.svelte";
|
||||
import { defaultAutoSuggestPrefixOoba, defaultAutoSuggestPrompt, defaultAutoSuggestPromptOoba } from "src/ts/storage/defaultPrompts";
|
||||
import { get } from "svelte/store";
|
||||
import { prebuiltNAIpresets, prebuiltPresets } from "./templates";
|
||||
import { prebuiltPresets } from "./templates";
|
||||
import { alertConfirm, alertSelect } from "src/ts/alert";
|
||||
import { language } from "src/lang";
|
||||
|
||||
export async function setRecommended(model: string, ask:'ask'|'force') {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!(recommendedPresetExist(model))){
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { risuChatParser } from "src/ts/parser"
|
||||
import { DataBase } from "src/ts/storage/database.svelte"
|
||||
import { get } from "svelte/store"
|
||||
import { getDatabase } from "src/ts/storage/database.svelte"
|
||||
|
||||
export function convertInterfaceToSchema(int:string){
|
||||
if(!int.startsWith('interface ') && !int.startsWith('export interface ')){
|
||||
@@ -122,7 +121,7 @@ export function convertInterfaceToSchema(int:string){
|
||||
}
|
||||
|
||||
export function getOpenAIJSONSchema(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const schema = {
|
||||
"name": "format",
|
||||
"strict": db.strictJsonSchema,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parseChatML, risuChatParser } from "../parser";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, type Chat, type character } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, type Chat, type character } from "../storage/database.svelte";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { getModuleTriggers } from "./modules";
|
||||
import { get } from "svelte/store";
|
||||
@@ -167,7 +167,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
v.lowLevelAccess = CharacterlowLevelAccess
|
||||
return v
|
||||
}).concat(getModuleTriggers())
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
|
||||
let chat = structuredClone(arg.chat ?? char.chats[char.chatPage])
|
||||
if((!triggers) || (triggers.length === 0)){
|
||||
@@ -191,7 +191,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
function setVar(key:string, value:string){
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const currentCharacter = getCurrentCharacter()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
varChanged = true
|
||||
chat.scriptstate ??= {}
|
||||
chat.scriptstate['$' + key] = value
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError } from "../alert";
|
||||
import { DataBase, getCurrentCharacter, type character } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getDatabase, type character } from "../storage/database.svelte";
|
||||
import { runTranslator, translateVox } from "../translator/translator";
|
||||
import { globalFetch, loadAsset } from "../storage/globalApi";
|
||||
import { language } from "src/lang";
|
||||
import { sleep } from "../util";
|
||||
import { registerOnnxModel, runVITS } from "./transformers";
|
||||
import { runVITS } from "./transformers";
|
||||
|
||||
let sourceNode:AudioBufferSourceNode = null
|
||||
|
||||
@@ -23,7 +22,7 @@ export async function sayTTS(character:character,text:string) {
|
||||
return
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
text = text.replace(/\*/g,'')
|
||||
|
||||
if(character.ttsReadOnlyQuoted){
|
||||
@@ -383,7 +382,7 @@ export function getWebSpeechTTSVoices() {
|
||||
}
|
||||
|
||||
export async function getElevenTTSVoices() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
const data = await fetch('https://api.elevenlabs.io/v1/voices', {
|
||||
headers: {
|
||||
@@ -397,7 +396,7 @@ export async function getElevenTTSVoices() {
|
||||
}
|
||||
|
||||
export async function getVOICEVOXVoices() {
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
const speakerData = await fetch(`${db.voicevoxUrl}/speakers`)
|
||||
const speakerList = await speakerData.json()
|
||||
const speakersInfo = speakerList.map((speaker) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get } from "svelte/store";
|
||||
import { exportCharacterCard } from "./characterCards";
|
||||
import { VirtualWriter, isTauri, openURL } from "./storage/globalApi";
|
||||
import { DataBase, getCurrentCharacter, type character } from "./storage/database.svelte";
|
||||
import { getCurrentCharacter, getDatabase, type character } from "./storage/database.svelte";
|
||||
import { alertStore } from "./alert";
|
||||
|
||||
let pong = false;
|
||||
@@ -15,7 +15,7 @@ window.addEventListener("message", (event) => {
|
||||
});
|
||||
|
||||
export async function shareRealmCardData():Promise<{ name: ArrayBuffer; data: ArrayBuffer; }> {
|
||||
const char = structuredClone(getCurrentCharacter()) as character
|
||||
const char = structuredClone(getCurrentCharacter({snapshot:true})) as character
|
||||
const trimedName = char.name.replace(/[^a-zA-Z0-9]/g, '') || 'character';
|
||||
const writer = new VirtualWriter()
|
||||
const namebuf = new TextEncoder().encode(trimedName + '.png')
|
||||
@@ -31,8 +31,8 @@ export async function shareRealmCardData():Promise<{ name: ArrayBuffer; data: Ar
|
||||
}
|
||||
|
||||
export async function openRealm(name:string,data:ArrayBuffer) {
|
||||
const tk = get(DataBase)?.account?.token;
|
||||
const id = get(DataBase)?.account?.id
|
||||
const tk = getDatabase()?.account?.token;
|
||||
const id = getDatabase()?.account?.id
|
||||
const trimedName = name.replace(/[^a-zA-Z0-9]/g, '') || 'character';
|
||||
const filedata = encodeURIComponent(Buffer.from(data).toString('base64')) + `&${trimedName}.png`;
|
||||
const url = `https://realm.risuai.net/upload?token=${tk}&token_id=${id}#filedata=${filedata}`
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { get, writable } from "svelte/store"
|
||||
import { DataBase } from "./database.svelte"
|
||||
import { writable } from "svelte/store"
|
||||
import { getDatabase } from "./database.svelte"
|
||||
import { hubURL } from "../characterCards"
|
||||
import localforage from "localforage"
|
||||
import { alertError, alertLogin, alertStore, alertWait } from "../alert"
|
||||
import { forageStorage, getUnpargeables, replaceDbResources } from "./globalApi"
|
||||
import { alertLogin, alertStore, alertWait } from "../alert"
|
||||
import { forageStorage, getUnpargeables } from "./globalApi"
|
||||
import { encodeRisuSave } from "./risuSave"
|
||||
import { v4 } from "uuid"
|
||||
import { language } from "src/lang"
|
||||
@@ -99,7 +99,7 @@ export class AccountStorage{
|
||||
return Buffer.from(ab)
|
||||
}
|
||||
async keys():Promise<string[]>{
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
return getUnpargeables(db, 'pure')
|
||||
}
|
||||
async removeItem(key:string){
|
||||
@@ -107,7 +107,7 @@ export class AccountStorage{
|
||||
}
|
||||
|
||||
private checkAuth(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
this.auth = db?.account?.token
|
||||
if(!this.auth){
|
||||
db.account = JSON.parse(localStorage.getItem("fallbackRisuToken"))
|
||||
@@ -122,7 +122,7 @@ export class AccountStorage{
|
||||
|
||||
export async function unMigrationAccount() {
|
||||
const keys = await forageStorage.keys()
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let i = 0;
|
||||
const MigrationStorage = localforage.createInstance({name: "risuai"})
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ import { isNodeServer, replaceDbResources } from "./globalApi"
|
||||
import { NodeStorage } from "./nodeStorage"
|
||||
import { OpfsStorage } from "./opfsStorage"
|
||||
import { alertInput, alertSelect, alertStore } from "../alert"
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, type Database } from "./database.svelte"
|
||||
import { getDatabase, type Database } from "./database.svelte"
|
||||
import { AccountStorage } from "./accountStorage"
|
||||
import { decodeRisuSave, encodeRisuSave } from "./risuSave";
|
||||
import { language } from "src/lang"
|
||||
@@ -40,7 +39,7 @@ export class AutoStorage{
|
||||
}
|
||||
|
||||
async checkAccountSync(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(this.isAccount){
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -12,28 +12,13 @@ import { defaultColorScheme, type ColorScheme } from '../gui/colorscheme';
|
||||
import type { PromptItem, PromptSettings } from '../process/prompt';
|
||||
import type { OobaChatCompletionRequestParams } from '../model/ooba';
|
||||
|
||||
export const DataBase = writable({} as any as Database)
|
||||
export const DBState = $state({
|
||||
db: get(DataBase)
|
||||
db: {} as any as Database
|
||||
})
|
||||
export const loadedStore = writable(false)
|
||||
export let appVer = "137.1.0"
|
||||
export let webAppSubVer = '-svelte5-exp'
|
||||
|
||||
DataBase.subscribe(data => {
|
||||
//check it is pointing to the right object
|
||||
if(DBState.db !== data){
|
||||
//if not, update it
|
||||
DBState.db = data
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
//same as above, but for the other way around
|
||||
if(DBState.db !== get(DataBase)){
|
||||
DataBase.set(DBState.db)
|
||||
}
|
||||
})
|
||||
|
||||
export function setDatabase(data:Database){
|
||||
if(checkNullish(data.characters)){
|
||||
@@ -464,21 +449,36 @@ export function setDatabase(data:Database){
|
||||
data.groupOtherBotRole ??= 'user'
|
||||
data.customGUI ??= ''
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
setDatabaseLite(data)
|
||||
}
|
||||
|
||||
export function getCurrentCharacter(){
|
||||
const db = get(DataBase)
|
||||
export function setDatabaseLite(data:Database){
|
||||
DBState.db = data
|
||||
}
|
||||
|
||||
interface getDatabaseOptions{
|
||||
snapshot?:boolean
|
||||
}
|
||||
|
||||
export function getDatabase(options:getDatabaseOptions = {}):Database{
|
||||
if(options.snapshot){
|
||||
return $state.snapshot(DBState.db) as Database
|
||||
}
|
||||
return DBState.db as Database
|
||||
}
|
||||
|
||||
export function getCurrentCharacter(options:getDatabaseOptions = {}):character|groupChat{
|
||||
const db = getDatabase(options)
|
||||
db.characters ??= []
|
||||
const char = db.characters?.[get(selectedCharID)]
|
||||
return char
|
||||
}
|
||||
|
||||
export function setCurrentCharacter(char:character|groupChat){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.characters ??= []
|
||||
db.characters[get(selectedCharID)] = char
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
}
|
||||
|
||||
export function getCurrentChat(){
|
||||
@@ -1328,7 +1328,7 @@ export const defaultSdDataFunc = () =>{
|
||||
}
|
||||
|
||||
export function saveCurrentPreset(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let pres = db.botPresets
|
||||
pres[db.botPresetsId] = {
|
||||
name: pres[db.botPresetsId].name,
|
||||
@@ -1392,7 +1392,7 @@ export function saveCurrentPreset(){
|
||||
|
||||
export function copyPreset(id:number){
|
||||
saveCurrentPreset()
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let pres = db.botPresets
|
||||
const newPres = structuredClone(pres[id])
|
||||
newPres.name += " Copy"
|
||||
@@ -1404,7 +1404,7 @@ export function changeToPreset(id =0, savecurrent = true){
|
||||
if(savecurrent){
|
||||
saveCurrentPreset()
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let pres = db.botPresets
|
||||
const newPres = pres[id]
|
||||
db.botPresetsId = id
|
||||
@@ -1492,7 +1492,7 @@ import { selectedCharID } from '../stores';
|
||||
|
||||
export async function downloadPreset(id:number, type:'json'|'risupreset'|'return' = 'json'){
|
||||
saveCurrentPreset()
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let pres = structuredClone(db.botPresets[id])
|
||||
console.log(pres)
|
||||
pres.openAIKey = ''
|
||||
@@ -1563,7 +1563,7 @@ export async function importPreset(f:{
|
||||
pre = {...presetTemplate,...(JSON.parse(Buffer.from(f.data).toString('utf-8')))}
|
||||
console.log(pre)
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(pre.presetVersion && pre.presetVersion >= 3){
|
||||
//NAI preset
|
||||
const pr = structuredClone(prebuiltPresets.NAI2)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "./database.svelte";
|
||||
import { getDatabase } from "./database.svelte";
|
||||
import { downloadFile } from "./globalApi";
|
||||
import { alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
|
||||
export async function exportAsDataset(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
let dataset = []
|
||||
for(const char of db.characters){
|
||||
|
||||
@@ -13,7 +13,7 @@ import { v4 as uuidv4, v4 } from 'uuid';
|
||||
import { appDataDir, join } from "@tauri-apps/api/path";
|
||||
import { get } from "svelte/store";
|
||||
import {open} from '@tauri-apps/plugin-shell'
|
||||
import { DataBase, loadedStore, setDatabase, type Database, defaultSdDataFunc } from "./database.svelte";
|
||||
import { loadedStore, setDatabase, type Database, defaultSdDataFunc, getDatabase } from "./database.svelte";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { checkRisuUpdate } from "../update";
|
||||
import { MobileGUI, botMakerMode, selectedCharID } from "../stores";
|
||||
@@ -310,12 +310,9 @@ let lastSave = ''
|
||||
* @returns {Promise<void>} - A promise that resolves when the database has been saved.
|
||||
*/
|
||||
export async function saveDb(){
|
||||
lastSave = JSON.stringify(get(DataBase))
|
||||
let changed = false
|
||||
lastSave = JSON.stringify(getDatabase())
|
||||
let changed = true
|
||||
syncDrive()
|
||||
DataBase.subscribe(() => {
|
||||
changed = true
|
||||
})
|
||||
let gotChannel = false
|
||||
const sessionID = v4()
|
||||
let channel:BroadcastChannel
|
||||
@@ -346,8 +343,11 @@ export async function saveDb(){
|
||||
if(channel){
|
||||
channel.postMessage(sessionID)
|
||||
}
|
||||
changed = false
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(!db.characters){
|
||||
await sleep(1000)
|
||||
continue
|
||||
}
|
||||
db.saveTime = Math.floor(Date.now() / 1000)
|
||||
if(isTauri){
|
||||
const dbData = encodeRisuSave(db)
|
||||
@@ -393,7 +393,7 @@ export async function saveDb(){
|
||||
* @returns {Promise<number[]>} - A promise that resolves to an array of backup timestamps.
|
||||
*/
|
||||
async function getDbBackups() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db?.account?.useSync){
|
||||
return []
|
||||
}
|
||||
@@ -547,7 +547,7 @@ export async function loadData() {
|
||||
else{
|
||||
usingSw = false
|
||||
}
|
||||
if(get(DataBase).didFirstSetup){
|
||||
if(getDatabase().didFirstSetup){
|
||||
characterURLImport()
|
||||
}
|
||||
}
|
||||
@@ -557,7 +557,7 @@ export async function loadData() {
|
||||
try {
|
||||
await loadPlugins()
|
||||
} catch (error) {}
|
||||
if(get(DataBase).account){
|
||||
if(getDatabase().account){
|
||||
try {
|
||||
await loadRisuAccountData()
|
||||
} catch (error) {}
|
||||
@@ -572,7 +572,7 @@ export async function loadData() {
|
||||
|
||||
}
|
||||
await checkNewFormat()
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
updateColorScheme()
|
||||
updateTextThemeAndCSS()
|
||||
updateAnimationSpeed()
|
||||
@@ -720,7 +720,7 @@ export function addFetchLog(arg: {
|
||||
*/
|
||||
export async function globalFetch(url: string, arg: GlobalFetchArgs = {}): Promise<GlobalFetchResult> {
|
||||
try {
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
const method = arg.method ?? "POST";
|
||||
db.requestmet = "normal";
|
||||
|
||||
@@ -1056,7 +1056,7 @@ export function replaceDbResources(db: Database, replacer: { [key: string]: stri
|
||||
* @returns {Promise<void>} - A promise that resolves when the database format check and update is complete.
|
||||
*/
|
||||
async function checkNewFormat(): Promise<void> {
|
||||
let db = get(DataBase);
|
||||
let db = getDatabase();
|
||||
|
||||
// Check data integrity
|
||||
db.characters = db.characters.map((v) => {
|
||||
@@ -1147,40 +1147,7 @@ async function checkNewFormat(): Promise<void> {
|
||||
db.formatversion = 3;
|
||||
}
|
||||
if (db.formatversion < 4) {
|
||||
db.modules ??= [];
|
||||
db.enabledModules ??= [];
|
||||
// Convert global lore and global regex to modules
|
||||
if (db.globalscript && db.globalscript.length > 0) {
|
||||
const id = v4();
|
||||
let regexModule: RisuModule = {
|
||||
name: "Global Regex",
|
||||
description: "Converted from legacy global regex",
|
||||
id: id,
|
||||
regex: structuredClone(db.globalscript)
|
||||
};
|
||||
db.modules.push(regexModule);
|
||||
db.enabledModules.push(id);
|
||||
db.globalscript = [];
|
||||
}
|
||||
if (db.loreBook && db.loreBook.length > 0) {
|
||||
const selIndex = db.loreBookPage;
|
||||
for (let i = 0; i < db.loreBook.length; i++) {
|
||||
const id = v4();
|
||||
let lbModule: RisuModule = {
|
||||
name: db.loreBook[i].name || "Unnamed Global Lorebook",
|
||||
description: "Converted from legacy global lorebook",
|
||||
id: id,
|
||||
lorebook: structuredClone(db.loreBook[i].data)
|
||||
};
|
||||
db.modules.push(lbModule);
|
||||
if (i === selIndex) {
|
||||
db.enabledModules.push(id);
|
||||
}
|
||||
db.globalscript = [];
|
||||
}
|
||||
db.loreBook = [];
|
||||
}
|
||||
|
||||
//migration removed due to issues
|
||||
db.formatversion = 4;
|
||||
}
|
||||
if (!db.characterOrder) {
|
||||
@@ -1209,9 +1176,9 @@ async function checkNewFormat(): Promise<void> {
|
||||
* Ensures that all characters are properly ordered and removes any invalid entries.
|
||||
*/
|
||||
export function checkCharOrder() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.characterOrder = db.characterOrder ?? []
|
||||
let ordered = structuredClone(db.characterOrder ?? [])
|
||||
let ordered = []
|
||||
for(let i=0;i<db.characterOrder.length;i++){
|
||||
const folder =db.characterOrder[i]
|
||||
if(typeof(folder) !== 'string' && folder){
|
||||
@@ -1219,6 +1186,9 @@ export function checkCharOrder() {
|
||||
ordered.push(f)
|
||||
}
|
||||
}
|
||||
if(typeof(folder) === 'string'){
|
||||
ordered.push(folder)
|
||||
}
|
||||
}
|
||||
|
||||
let charIdList:string[] = []
|
||||
@@ -1276,7 +1246,7 @@ export function checkCharOrder() {
|
||||
* Removes files from the assets directory that are not in the list of unpargeable items.
|
||||
*/
|
||||
async function pargeChunks(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(db.account?.useSync){
|
||||
return
|
||||
}
|
||||
@@ -1797,7 +1767,7 @@ export async function fetchNative(url:string, arg:{
|
||||
chatId?:string
|
||||
}):Promise<{ body: ReadableStream<Uint8Array>; headers: Headers; status: number }> {
|
||||
let headers = arg.headers ?? {}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let throughProxy = (!isTauri) && (!isNodeServer) && (!db.usePlainFetch)
|
||||
let fetchLogIndex = addFetchLog({
|
||||
body: arg.body,
|
||||
@@ -1977,7 +1947,7 @@ export function trimNonLatin(data:string){
|
||||
* The corresponding CSS variable '--risu-height-size' is set accordingly.
|
||||
*/
|
||||
export function updateHeightMode(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const root = document.querySelector(':root') as HTMLElement;
|
||||
switch(db.heightMode){
|
||||
case 'auto':
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "./database.svelte";
|
||||
import { getDatabase } from "./database.svelte";
|
||||
import { alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { isNodeServer, isTauri } from "./globalApi";
|
||||
@@ -38,7 +38,7 @@ async function requestPersistantStorageMain() {
|
||||
}
|
||||
|
||||
export async function persistantStorageRecommended() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(navigator.storage && navigator.storage.persist && (!isTauri) && (!isNodeServer)) {
|
||||
if(await navigator.storage.persisted()) {
|
||||
return false;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { get, writable, type Writable } from "svelte/store";
|
||||
import { DataBase, getCurrentCharacter, type Chat, type character, type groupChat } from "./storage/database.svelte";
|
||||
import { isEqual } from "lodash";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
import { getDatabase, type Chat, type character, type groupChat } from "./storage/database.svelte";
|
||||
import type { simpleCharacterArgument } from "./parser";
|
||||
import { getUserIcon, getUserIconProtrait, getUserName, sleep } from "./util";
|
||||
import { sleep } from "./util";
|
||||
import { getModules } from "./process/modules";
|
||||
|
||||
function updateSize(){
|
||||
@@ -75,7 +74,7 @@ export function createSimpleCharacter(char:character|groupChat){
|
||||
|
||||
const simpleChar:simpleCharacterArgument = {
|
||||
type: "simple",
|
||||
customscript: structuredClone(char.customscript),
|
||||
customscript: char.customscript,
|
||||
chaId: char.chaId,
|
||||
additionalAssets: char.additionalAssets,
|
||||
virtualscript: char.virtualscript,
|
||||
@@ -89,7 +88,7 @@ export function createSimpleCharacter(char:character|groupChat){
|
||||
|
||||
function trySync(){
|
||||
try {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
CurrentShowMemoryLimit.set(db.showMemoryLimit)
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { v4 } from 'uuid';
|
||||
import { alertError, alertInput, alertNormal, alertStore, alertWait } from '../alert';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { DataBase, setDatabase, type character, saveImage, type Chat, getCurrentChat, setCurrentChat } from '../storage/database.svelte';
|
||||
import { setDatabase, type character, saveImage, type Chat, getCurrentChat, setCurrentChat, getDatabase } from '../storage/database.svelte';
|
||||
import { selectedCharID } from '../stores';
|
||||
import { findCharacterIndexbyId, sleep } from '../util';
|
||||
import type { DataConnection, Peer } from 'peerjs';
|
||||
@@ -79,7 +79,9 @@ export async function createMultiuserRoom(){
|
||||
console.log("new connection", conn)
|
||||
|
||||
async function requestChar(excludeAssets:string[]|null = null){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
if(char.type === 'group'){
|
||||
@@ -127,7 +129,9 @@ export async function createMultiuserRoom(){
|
||||
requestChar()
|
||||
}
|
||||
if(data.type === 'receive-char'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
const recivedChar = data.data
|
||||
@@ -137,7 +141,7 @@ export async function createMultiuserRoom(){
|
||||
char.chats[char.chatPage] = recivedChar.chats[0]
|
||||
}
|
||||
if(data.type === 'request-chat-sync'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = db.characters[selectedCharId]
|
||||
char.chats[char.chatPage] = data.data
|
||||
@@ -157,7 +161,7 @@ export async function createMultiuserRoom(){
|
||||
}
|
||||
}
|
||||
if(data.type === 'request-chat'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = db.characters[selectedCharId]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -285,7 +289,7 @@ export async function joinMultiuserRoom(){
|
||||
switch(data.type){
|
||||
case 'receive-char':{
|
||||
//create temp character
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const cha = data.data
|
||||
cha.chaId = '§temp'
|
||||
cha.chatPage = 0
|
||||
@@ -309,7 +313,9 @@ export async function joinMultiuserRoom(){
|
||||
break
|
||||
}
|
||||
case 'receive-chat':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase({
|
||||
snapshot: true
|
||||
})
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const char = structuredClone(db.characters[selectedCharId])
|
||||
char.chats[char.chatPage] = data.data
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Tiktoken } from "@dqbd/tiktoken";
|
||||
import type { Tokenizer } from "@mlc-ai/web-tokenizers";
|
||||
import { DataBase, type groupChat, type character, type Chat, getCurrentCharacter } from "./storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { type groupChat, type character, type Chat, getCurrentCharacter, getDatabase } from "./storage/database.svelte";
|
||||
import type { MultiModal, OpenAIChat } from "./process";
|
||||
import { supportsInlayImage } from "./process/files/image";
|
||||
import { risuChatParser } from "./parser";
|
||||
@@ -22,7 +21,7 @@ export const tokenizerList = [
|
||||
] as const
|
||||
|
||||
export async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.aiModel === 'openrouter' || db.aiModel === 'reverse_proxy'){
|
||||
switch(db.customTokenizer){
|
||||
case 'mistral':
|
||||
@@ -130,7 +129,7 @@ async function tikJS(text:string, model='cl100k_base') {
|
||||
}
|
||||
|
||||
async function geminiTokenizer(text:string) {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const fetchResult = await globalFetch(`https://generativelanguage.googleapis.com/v1beta/${db.aiModel}:countTextTokens`, {
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
@@ -249,7 +248,7 @@ export class ChatTokenizer {
|
||||
}
|
||||
|
||||
async tokenizeMultiModal(data:MultiModal){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!supportsInlayImage()){
|
||||
return this.chatAdditonalTokens
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store"
|
||||
import { translatorPlugin } from "../plugins/plugins"
|
||||
import { DataBase, type character, type customscript, type groupChat } from "../storage/database.svelte"
|
||||
import { getDatabase, type character, type customscript, type groupChat } from "../storage/database.svelte"
|
||||
import { globalFetch, isTauri } from "../storage/globalApi"
|
||||
import { alertError } from "../alert"
|
||||
import { requestChatData } from "../process/request"
|
||||
@@ -10,7 +10,6 @@ import { selectedCharID } from "../stores"
|
||||
import { getModuleRegexScripts } from "../process/modules"
|
||||
import { getNodetextToSentence, sleep } from "../util"
|
||||
import { processScriptFull } from "../process/scripts"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
|
||||
let cache={
|
||||
origin: [''],
|
||||
@@ -20,7 +19,7 @@ let cache={
|
||||
let waitTrans = 0
|
||||
|
||||
export async function translate(text:string, reverse:boolean) {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const plug = await translatorPlugin(text, reverse ? db.translator: 'en', reverse ? 'en' : db.translator)
|
||||
if(plug){
|
||||
return plug.content
|
||||
@@ -105,7 +104,7 @@ export async function runTranslator(text:string, reverse:boolean, from:string,ta
|
||||
}
|
||||
|
||||
async function translateMain(text:string, arg:{from:string, to:string, host:string}){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(db.translatorType === 'llm'){
|
||||
const tr = db.translator || 'en'
|
||||
return translateLLM(text, {to: tr})
|
||||
@@ -208,7 +207,7 @@ async function jaTrans(text:string) {
|
||||
}
|
||||
|
||||
export function isExpTranslator(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.translatorType === 'llm' || db.translatorType === 'deepl' || db.translatorType === 'deeplX'
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
let alwaysExistChar: character | groupChat | simpleCharacterArgument;
|
||||
if(charArg !== ''){
|
||||
if(typeof(charArg) === 'string'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charId = get(selectedCharID)
|
||||
alwaysExistChar = db.characters[charId]
|
||||
}
|
||||
@@ -232,7 +231,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
chaId: 'simple'
|
||||
}
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let DoingChat = get(doingChat)
|
||||
if(DoingChat){
|
||||
if(isExpTranslator()){
|
||||
@@ -440,7 +439,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
||||
}
|
||||
|
||||
function needSuperChunkedTranslate(){
|
||||
return get(DataBase).translatorType === 'deeplX'
|
||||
return getDatabase().translatorType === 'deeplX'
|
||||
}
|
||||
|
||||
let llmCache = new Map<string, string>()
|
||||
@@ -455,7 +454,7 @@ async function translateLLM(text:string, arg:{to:string}){
|
||||
return `<style-data style-index="${styleDecodes.length-1}"></style-data>`
|
||||
})
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const charIndex = get(selectedCharID)
|
||||
const currentChar = db.characters[charIndex]
|
||||
let translatorNote
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get, writable, type Writable } from "svelte/store"
|
||||
import type { Database, Message } from "./storage/database.svelte"
|
||||
import { DataBase } from "./storage/database.svelte"
|
||||
import { getDatabase } from "./storage/database.svelte"
|
||||
import { selectedCharID } from "./stores"
|
||||
import {open} from '@tauri-apps/plugin-dialog'
|
||||
import { readFile } from "@tauri-apps/plugin-fs"
|
||||
@@ -17,7 +17,7 @@ export interface Messagec extends Message{
|
||||
}
|
||||
|
||||
export function messageForm(arg:Message[], loadPages:number){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedChar = get(selectedCharID)
|
||||
function reformatContent(data:string){
|
||||
return data.trim()
|
||||
@@ -100,7 +100,7 @@ export async function selectMultipleFile(ext:string[]){
|
||||
}
|
||||
|
||||
export const replacePlaceholders = (msg:string, name:string) => {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedChar = get(selectedCharID)
|
||||
let currentChar = db.characters[selectedChar]
|
||||
return msg .replace(/({{char}})|({{Char}})|(<Char>)|(<char>)/gi, currentChar.name)
|
||||
@@ -110,7 +110,7 @@ export const replacePlaceholders = (msg:string, name:string) => {
|
||||
|
||||
function checkPersonaBinded(){
|
||||
try {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const character = db.characters[selectedChar]
|
||||
const chat = character.chats[character.chatPage]
|
||||
@@ -129,7 +129,7 @@ export function getUserName(){
|
||||
if(bindedPersona){
|
||||
return bindedPersona.name
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.username ?? 'User'
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ export function getUserIcon(){
|
||||
if(bindedPersona){
|
||||
return bindedPersona.icon
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.userIcon ?? ''
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ export function getPersonaPrompt(){
|
||||
if(bindedPersona){
|
||||
return bindedPersona.personaPrompt
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.personaPrompt ?? ''
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ export function getUserIconProtrait(){
|
||||
if(bindedPersona){
|
||||
return bindedPersona.largePortrait
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.personas[db.selectedPersona].largePortrait
|
||||
} catch (error) {
|
||||
return false
|
||||
@@ -172,7 +172,7 @@ export function selectFileByDom(allowedExtensions:string[], multiple:'multiple'|
|
||||
const fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
fileInput.multiple = multiple === 'multiple';
|
||||
const acceptAll = (get(DataBase).allowAllExtentionFiles || checkIsIos() || allowedExtensions[0] === '*')
|
||||
const acceptAll = (getDatabase().allowAllExtentionFiles || checkIsIos() || allowedExtensions[0] === '*')
|
||||
if(!acceptAll){
|
||||
if (allowedExtensions && allowedExtensions.length) {
|
||||
fileInput.accept = allowedExtensions.map(ext => `.${ext}`).join(',');
|
||||
@@ -223,7 +223,7 @@ function readFileAsUint8Array(file) {
|
||||
}
|
||||
|
||||
export async function changeFullscreen(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const isFull = await appWindow.isFullscreen()
|
||||
if(db.fullScreen && (!isFull)){
|
||||
await appWindow.setFullscreen(true)
|
||||
@@ -244,7 +244,7 @@ export async function getCustomBackground(db:string){
|
||||
}
|
||||
|
||||
export function findCharacterbyId(id:string) {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(const char of db.characters){
|
||||
if(char.type !== 'group'){
|
||||
if(char.chaId === id){
|
||||
@@ -258,7 +258,7 @@ export function findCharacterbyId(id:string) {
|
||||
}
|
||||
|
||||
export function findCharacterIndexbyId(id:string) {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let i=0;
|
||||
for(const char of db.characters){
|
||||
if(char.chaId === id){
|
||||
@@ -270,7 +270,7 @@ export function findCharacterIndexbyId(id:string) {
|
||||
}
|
||||
|
||||
export function getCharacterIndexObject() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let i=0;
|
||||
let result:{[key:string]:number} = {}
|
||||
for(const char of db.characters){
|
||||
@@ -364,7 +364,7 @@ export async function getEmotion(db:Database,chaEmotion:{[key:string]: [string,
|
||||
}
|
||||
|
||||
export function getAuthorNoteDefaultText(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const template = db.promptTemplate
|
||||
if(!template){
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user