Migrate to svelte 5

This commit is contained in:
kwaroran
2024-10-23 02:31:37 +09:00
parent e434c7ab96
commit c7330719ad
120 changed files with 2398 additions and 2033 deletions

View File

@@ -1,6 +1,6 @@
import { get } from "svelte/store";
import { DataBase, setDatabase } from "../storage/database";
import { CurrentCharacter, CurrentChat, selectedCharID } from "../stores";
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase } from "../storage/database";
import { selectedCharID } from "../stores";
import { alertInput, alertMd, alertNormal, alertSelect, alertToast } from "../alert";
import { sayTTS } from "./tts";
import { risuChatParser } from "../parser";
@@ -222,17 +222,17 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
return JSON.stringify(p)
}
case 'trigger':{
const currentChar = get(CurrentCharacter)
const currentChar = getCurrentCharacter()
if(currentChar.type === 'group'){
return;
}
const triggerResult = await runTrigger(currentChar, 'manual', {
chat: get(CurrentChat),
chat: getCurrentChat(),
manualName: arg
});
if(triggerResult){
CurrentChat.set(triggerResult.chat);
setCurrentChat(triggerResult.chat);
}
return
}

View File

@@ -1,8 +1,8 @@
import { getChatVar, hasher, risuChatParser, setChatVar, type simpleCharacterArgument } from "../parser";
import { LuaEngine, LuaFactory } from "wasmoon";
import { DataBase, setDatabase, type Chat, type character, type groupChat } from "../storage/database";
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database";
import { get } from "svelte/store";
import { CurrentCharacter, CurrentChat, ReloadGUIPointer, selectedCharID } from "../stores";
import { ReloadGUIPointer, selectedCharID } from "../stores";
import { alertError, alertInput, alertNormal } from "../alert";
import { HypaProcesser } from "./memory/hypamemory";
import { generateAIImage } from "./stableDiff";
@@ -35,12 +35,12 @@ export async function runLua(code:string, arg:{
mode?: string,
data?: any
}){
const char = arg.char ?? get(CurrentCharacter)
const char = arg.char ?? getCurrentCharacter()
const setVar = arg.setVar ?? setChatVar
const getVar = arg.getVar ?? getChatVar
const mode = arg.mode ?? 'manual'
const data = arg.data ?? {}
let chat = arg.chat ?? get(CurrentChat)
let chat = arg.chat ?? getCurrentChat()
let stopSending = false
let lowLevelAccess = arg.lowLevelAccess ?? false
@@ -104,75 +104,75 @@ export async function runLua(code:string, arg:{
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
const message = chat.message?.at(index)
if(message){
message.data = value
}
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('setChatRole', (id:string, index:number, value:string) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
const message = chat.message?.at(index)
if(message){
message.role = value === 'user' ? 'user' : 'char'
}
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('cutChat', (id:string, start:number, end:number) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
chat.message = chat.message.slice(start,end)
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('removeChat', (id:string, index:number) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
chat.message.splice(index, 1)
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('addChat', (id:string, role:string, value:string) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
let roleData:'user'|'char' = role === 'user' ? 'user' : 'char'
chat.message.push({role: roleData, data: value})
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('insertChat', (id:string, index:number, role:string, value:string) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
let roleData:'user'|'char' = role === 'user' ? 'user' : 'char'
chat.message.splice(index, 0, {role: roleData, data: value})
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('removeChat', (id:string, index:number) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
chat.message.splice(index, 1)
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('getChatLength', (id:string) => {
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
return chat.message.length
})
luaEngine.global.set('getFullChatMain', (id:string) => {
chat = get(CurrentChat)
chat = getCurrentChat()
const data = JSON.stringify(chat.message.map((v) => {
return {
role: v.role,
@@ -187,14 +187,14 @@ export async function runLua(code:string, arg:{
if(!LuaSafeIds.has(id)){
return
}
chat = get(CurrentChat)
chat = getCurrentChat()
chat.message = realValue.map((v) => {
return {
role: v.role,
data: v.data
}
})
CurrentChat.set(chat)
setCurrentChat(chat)
})
luaEngine.global.set('logMain', (value:string) => {

View File

@@ -1,13 +1,11 @@
import { language } from "src/lang"
import { alertConfirm, alertError, alertModuleSelect, alertNormal, alertStore } from "../alert"
import { DataBase, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database"
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentCharacter, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database"
import { AppendableBuffer, downloadFile, isNodeServer, isTauri, readImage, saveAsset } from "../storage/globalApi"
import { get } from "svelte/store"
import { CurrentCharacter, CurrentChat } from "../stores"
import { selectSingleFile, sleep } from "../util"
import { v4 } from "uuid"
import { convertExternalLorebook } from "./lorebook"
import { encode } from "msgpackr"
import { decodeRPack, encodeRPack } from "../rpack/rpack_bg"
import { convertImage } from "../parser"
import { Capacitor } from "@capacitor/core"
@@ -274,7 +272,7 @@ function getModuleByIds(ids:string[]){
let lastModules = ''
let lastModuleData:RisuModule[] = []
export function getModules(){
const currentChat = get(CurrentChat)
const currentChat = getCurrentChat()
const db = get(DataBase)
let ids = db.enabledModules ?? []
if (currentChat){
@@ -368,7 +366,7 @@ export async function applyModule() {
return
}
const currentChar = get(CurrentCharacter)
const currentChar = getCurrentCharacter()
if (!currentChar) {
return
}
@@ -392,7 +390,7 @@ export async function applyModule() {
}
}
CurrentCharacter.set(currentChar)
setCurrentCharacter(currentChar)
alertNormal(language.successApplyModule)
}

View File

@@ -1,8 +1,7 @@
import { Template } from '@huggingface/jinja';
import type { OpenAIChat } from '..';
import { get } from 'svelte/store';
import { DataBase } from 'src/ts/storage/database';
import { CurrentCharacter } from 'src/ts/stores';
import { DataBase, getCurrentCharacter } from 'src/ts/storage/database';
import { getUserName } from 'src/ts/util';
export const chatTemplates = {
@@ -31,7 +30,7 @@ export const applyChatTemplate = (messages:OpenAIChat[], arg:{
custom?: string
} = {}) => {
const db = get(DataBase)
const currentChar = get(CurrentCharacter)
const currentChar = getCurrentCharacter()
const type = arg.type ?? db.instructChatTemplate
if(!type){
throw new Error('Template type is not set')

View File

@@ -1,9 +1,9 @@
import { parseChatML, risuChatParser } from "../parser";
import { DataBase, type Chat, type character } from "../storage/database";
import { DataBase, getCurrentCharacter, getCurrentChat, type Chat, type character } from "../storage/database";
import { tokenize } from "../tokenizer";
import { getModuleTriggers } from "./modules";
import { get } from "svelte/store";
import { CurrentCharacter, CurrentChat, ReloadGUIPointer, selectedCharID } from "../stores";
import { ReloadGUIPointer, selectedCharID } from "../stores";
import { processMultiCommand } from "./command";
import { parseKeyValue } from "../util";
import { alertError, alertInput, alertNormal, alertSelect } from "../alert";
@@ -157,7 +157,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
let stopSending = arg.stopSending ?? false
const CharacterlowLevelAccess = char.lowLevelAccess ?? false
let sendAIprompt = false
const currentChat = get(CurrentChat)
const currentChat = getCurrentChat()
let additonalSysPrompt:additonalSysPrompt = arg.additonalSysPrompt ?? {
start:'',
historyend: '',
@@ -190,7 +190,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
function setVar(key:string, value:string){
const selectedCharId = get(selectedCharID)
const currentCharacter = get(CurrentCharacter)
const currentCharacter = getCurrentCharacter()
const db = get(DataBase)
varChanged = true
chat.scriptstate ??= {}
@@ -517,7 +517,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
if(triggerCodeResult.stopSending){
stopSending = true
}
chat = get(CurrentChat)
chat = getCurrentChat()
break
}
}
@@ -535,7 +535,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
caculatedTokens += await tokenize(additonalSysPrompt.promptend)
}
if(varChanged){
const currentChat = get(CurrentChat)
const currentChat = getCurrentChat()
currentChat.scriptstate = chat.scriptstate
ReloadGUIPointer.set(get(ReloadGUIPointer) + 1)
}

View File

@@ -1,10 +1,10 @@
import { get } from "svelte/store";
import { alertError } from "../alert";
import { DataBase, type character } from "../storage/database";
import { DataBase, getCurrentCharacter, type character } from "../storage/database";
import { runTranslator, translateVox } from "../translator/translator";
import { globalFetch, loadAsset } from "../storage/globalApi";
import { language } from "src/lang";
import { getCurrentCharacter, sleep } from "../util";
import { sleep } from "../util";
import { registerOnnxModel, runVITS } from "./transformers";
let sourceNode:AudioBufferSourceNode = null