[feat] performace improvement stage 1

This commit is contained in:
kwaroran
2023-08-06 14:58:05 +09:00
parent 31763bb481
commit f3e96d8ba1
10 changed files with 180 additions and 106 deletions

View File

@@ -5,9 +5,9 @@
import { alertConfirm } from "../../ts/alert"; import { alertConfirm } from "../../ts/alert";
import { language } from "../../lang"; import { language } from "../../lang";
import { DataBase, type character, type groupChat } from "../../ts/storage/database"; import { DataBase, type character, type groupChat } from "../../ts/storage/database";
import { selectedCharID } from "../../ts/stores"; import { CurrentChat, selectedCharID } from "../../ts/stores";
import { translate } from "../../ts/translator/translator"; import { translate } from "../../ts/translator/translator";
import { risuChatParser } from "src/ts/process/scripts"; import { risuChatParser } from "src/ts/process/scripts";
export let message = '' export let message = ''
export let name = '' export let name = ''
export let isLastMemory:boolean export let isLastMemory:boolean
@@ -30,27 +30,27 @@
if(rm){ if(rm){
if($DataBase.instantRemove){ if($DataBase.instantRemove){
const r = await alertConfirm(language.instantRemoveConfirm) const r = await alertConfirm(language.instantRemoveConfirm)
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message let msg = $CurrentChat.message
if(!r){ if(!r){
msg = msg.slice(0, idx) msg = msg.slice(0, idx)
} }
else{ else{
msg.splice(idx, 1) msg.splice(idx, 1)
} }
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg $CurrentChat.message = msg
} }
else{ else{
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message let msg = $CurrentChat.message
msg.splice(idx, 1) msg.splice(idx, 1)
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg $CurrentChat.message = msg
} }
} }
} }
async function edit(){ async function edit(){
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message let msg = $CurrentChat.message
msg[idx].data = message msg[idx].data = message
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg $CurrentChat.message = msg
} }
async function displaya(message:string){ async function displaya(message:string){

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { getCustomBackground, getEmotion } from "../../ts/util"; import { getCustomBackground, getEmotion } from "../../ts/util";
import { DataBase } from "../../ts/storage/database"; import { DataBase } from "../../ts/storage/database";
import { CharEmotion, selectedCharID } from "../../ts/stores"; import { CharEmotion, CurrentCharacter, selectedCharID } from "../../ts/stores";
import ResizeBox from './ResizeBox.svelte' import ResizeBox from './ResizeBox.svelte'
import DefaultChatScreen from "./DefaultChatScreen.svelte"; import DefaultChatScreen from "./DefaultChatScreen.svelte";
import defaultWallpaper from '../../etc/bg.jpg' import defaultWallpaper from '../../etc/bg.jpg'
@@ -33,7 +33,7 @@
<BackgroundDom /> <BackgroundDom />
<div style={bgImg} class="h-full w-full" class:max-w-6xl={$DataBase.classicMaxWidth}> <div style={bgImg} class="h-full w-full" class:max-w-6xl={$DataBase.classicMaxWidth}>
{#if $selectedCharID >= 0} {#if $selectedCharID >= 0}
{#if $DataBase.characters[$selectedCharID].viewScreen !== 'none'} {#if $CurrentCharacter.viewScreen !== 'none'}
<ResizeBox /> <ResizeBox />
{/if} {/if}
{/if} {/if}
@@ -45,13 +45,13 @@
<SideBarArrow /> <SideBarArrow />
<BackgroundDom /> <BackgroundDom />
{#if $selectedCharID >= 0} {#if $selectedCharID >= 0}
{#if $DataBase.characters[$selectedCharID].viewScreen !== 'none'} {#if $CurrentCharacter.viewScreen !== 'none'}
<div class="h-full mr-10 flex justify-end halfw" style:width="{42 * ($DataBase.waifuWidth2 / 100)}rem"> <div class="h-full mr-10 flex justify-end halfw" style:width="{42 * ($DataBase.waifuWidth2 / 100)}rem">
<TransitionImage classType="waifu" src={getEmotion($DataBase, $CharEmotion, 'plain')}/> <TransitionImage classType="waifu" src={getEmotion($DataBase, $CharEmotion, 'plain')}/>
</div> </div>
{/if} {/if}
{/if} {/if}
<div class="h-full w-2xl" style:width="{42 * ($DataBase.waifuWidth / 100)}rem" class:halfwp={$selectedCharID >= 0 && $DataBase.characters[$selectedCharID].viewScreen !== 'none'}> <div class="h-full w-2xl" style:width="{42 * ($DataBase.waifuWidth / 100)}rem" class:halfwp={$selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none'}>
<DefaultChatScreen customStyle={`${externalStyles}backdrop-filter: blur(4px);`} bind:openChatList/> <DefaultChatScreen customStyle={`${externalStyles}backdrop-filter: blur(4px);`} bind:openChatList/>
</div> </div>
</div> </div>
@@ -60,13 +60,13 @@
<SideBarArrow /> <SideBarArrow />
<BackgroundDom /> <BackgroundDom />
<div class="w-full absolute z-10 bottom-0 left-0" <div class="w-full absolute z-10 bottom-0 left-0"
class:per33={$selectedCharID >= 0 && $DataBase.characters[$selectedCharID].viewScreen !== 'none'} class:per33={$selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none'}
class:h-full={!($selectedCharID >= 0 && $DataBase.characters[$selectedCharID].viewScreen !== 'none')} class:h-full={!($selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none')}
> >
<DefaultChatScreen customStyle={`${externalStyles}backdrop-filter: blur(4px);`} bind:openChatList/> <DefaultChatScreen customStyle={`${externalStyles}backdrop-filter: blur(4px);`} bind:openChatList/>
</div> </div>
{#if $selectedCharID >= 0} {#if $selectedCharID >= 0}
{#if $DataBase.characters[$selectedCharID].viewScreen !== 'none'} {#if $CurrentCharacter.viewScreen !== 'none'}
<div class="h-full w-full absolute bottom-0 left-0 max-w-full"> <div class="h-full w-full absolute bottom-0 left-0 max-w-full">
<TransitionImage classType="mobile" src={getEmotion($DataBase, $CharEmotion, 'plain')}/> <TransitionImage classType="mobile" src={getEmotion($DataBase, $CharEmotion, 'plain')}/>
</div> </div>

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import Suggestion from './Suggestion.svelte'; import Suggestion from './Suggestion.svelte';
import { CameraIcon, DatabaseIcon, DicesIcon, GlobeIcon, LanguagesIcon, Laugh, MenuIcon, MicOffIcon, RefreshCcwIcon, ReplyIcon, Send } from "lucide-svelte"; import { CameraIcon, DatabaseIcon, DicesIcon, GlobeIcon, LanguagesIcon, Laugh, MenuIcon, MicOffIcon, RefreshCcwIcon, ReplyIcon, Send } from "lucide-svelte";
import { selectedCharID } from "../../ts/stores"; import { CurrentCharacter, CurrentChat, selectedCharID } from "../../ts/stores";
import Chat from "./Chat.svelte"; import Chat from "./Chat.svelte";
import { DataBase, type Message, type character, type groupChat } from "../../ts/storage/database"; import { DataBase, type Message, type character, type groupChat } from "../../ts/storage/database";
import { getCharImage } from "../../ts/characters"; import { getCharImage } from "../../ts/characters";
@@ -18,8 +18,8 @@
import MainMenu from '../UI/MainMenu.svelte'; import MainMenu from '../UI/MainMenu.svelte';
import Help from '../Others/Help.svelte'; import Help from '../Others/Help.svelte';
import AssetInput from './AssetInput.svelte'; import AssetInput from './AssetInput.svelte';
import { downloadFile } from 'src/ts/storage/globalApi'; import { downloadFile } from 'src/ts/storage/globalApi';
import { runTrigger } from 'src/ts/process/triggers'; import { runTrigger } from 'src/ts/process/triggers';
let messageInput:string = '' let messageInput:string = ''
let messageInputTranslate:string = '' let messageInputTranslate:string = ''
@@ -31,7 +31,7 @@
let rerollid = -1 let rerollid = -1
let lastCharId = -1 let lastCharId = -1
let doingChatInputTranslate = false let doingChatInputTranslate = false
let currentCharacter:character|groupChat = $DataBase.characters[$selectedCharID] let currentCharacter:character|groupChat = $CurrentCharacter
let toggleStickers:boolean = false let toggleStickers:boolean = false
async function send() { async function send() {
@@ -103,16 +103,16 @@
if(Array.isArray(rerolls[rerollid + 1])){ if(Array.isArray(rerolls[rerollid + 1])){
let db = $DataBase let db = $DataBase
rerollid += 1 rerollid += 1
db.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = cloneDeep(rerolls[rerollid]) db.characters[$selectedCharID].chats[$CurrentCharacter.chatPage].message = cloneDeep(rerolls[rerollid])
$DataBase = db $DataBase = db
} }
return return
} }
if(rerolls.length === 0){ if(rerolls.length === 0){
rerolls.push($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message) rerolls.push($CurrentChat.message)
rerollid = rerolls.length - 1 rerollid = rerolls.length - 1
} }
let cha = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message let cha = $CurrentChat.message
if(cha.length === 0 ){ if(cha.length === 0 ){
return return
} }
@@ -128,7 +128,7 @@
} }
cha.pop() cha.pop()
} }
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = cha $CurrentChat.message = cha
await sendChatMain() await sendChatMain()
} }
@@ -146,7 +146,7 @@
if(Array.isArray(rerolls[rerollid - 1])){ if(Array.isArray(rerolls[rerollid - 1])){
let db = $DataBase let db = $DataBase
rerollid -= 1 rerollid -= 1
db.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = cloneDeep(rerolls[rerollid]) db.characters[$selectedCharID].chats[$CurrentCharacter.chatPage].message = cloneDeep(rerolls[rerollid])
$DataBase = db $DataBase = db
} }
} }
@@ -162,7 +162,7 @@
console.error(error) console.error(error)
alertError(`${error}`) alertError(`${error}`)
} }
rerolls.push(cloneDeep($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message)) rerolls.push(cloneDeep($CurrentChat.message))
rerollid = rerolls.length - 1 rerollid = rerolls.length - 1
lastCharId = $selectedCharID lastCharId = $selectedCharID
$doingChat = false $doingChat = false
@@ -295,7 +295,7 @@
} }
$: { $: {
currentCharacter = $DataBase.characters[$selectedCharID] currentCharacter = $CurrentCharacter
} }
</script> </script>
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -308,7 +308,7 @@
<div class="h-full w-full flex flex-col-reverse overflow-y-auto relative default-chat-screen" on:scroll={(e) => { <div class="h-full w-full flex flex-col-reverse overflow-y-auto relative default-chat-screen" on:scroll={(e) => {
//@ts-ignore //@ts-ignore
const scrolled = (e.target.scrollHeight - e.target.clientHeight + e.target.scrollTop) const scrolled = (e.target.scrollHeight - e.target.clientHeight + e.target.scrollTop)
if(scrolled < 100 && $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message.length > loadPages){ if(scrolled < 100 && $CurrentChat.message.length > loadPages){
loadPages += 30 loadPages += 30
} }
}}> }}>
@@ -409,19 +409,19 @@
)} {send}/> )} {send}/>
{/if} {/if}
{#each messageForm($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message, loadPages) as chat, i} {#each messageForm($CurrentChat.message, loadPages) as chat, i}
{#if chat.role === 'char'} {#if chat.role === 'char'}
{#if $DataBase.characters[$selectedCharID].type !== 'group'} {#if $CurrentCharacter.type !== 'group'}
<Chat <Chat
idx={chat.index} idx={chat.index}
name={$DataBase.characters[$selectedCharID].name} name={$CurrentCharacter.name}
message={chat.data} message={chat.data}
img={getCharImage($DataBase.characters[$selectedCharID].image, 'css')} img={getCharImage($CurrentCharacter.image, 'css')}
rerollIcon={i === 0} rerollIcon={i === 0}
onReroll={reroll} onReroll={reroll}
unReroll={unReroll} unReroll={unReroll}
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit} isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
character={$DataBase.characters[$selectedCharID]} character={$CurrentCharacter}
/> />
{:else} {:else}
<Chat <Chat
@@ -432,33 +432,33 @@
onReroll={reroll} onReroll={reroll}
unReroll={unReroll} unReroll={unReroll}
img={getCharImage(findCharacterbyId(chat.saying).image, 'css')} img={getCharImage(findCharacterbyId(chat.saying).image, 'css')}
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit} isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
character={findCharacterbyId(chat.saying)} character={findCharacterbyId(chat.saying)}
/> />
{/if} {/if}
{:else} {:else}
<Chat <Chat
character={$DataBase.characters[$selectedCharID]} character={$CurrentCharacter}
idx={chat.index} idx={chat.index}
name={$DataBase.username} name={$DataBase.username}
message={chat.data} message={chat.data}
img={getCharImage($DataBase.userIcon, 'css')} img={getCharImage($DataBase.userIcon, 'css')}
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit} isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
/> />
{/if} {/if}
{/each} {/each}
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message.length <= loadPages} {#if $CurrentChat.message.length <= loadPages}
{#if $DataBase.characters[$selectedCharID].type !== 'group'} {#if $CurrentCharacter.type !== 'group'}
<Chat <Chat
character={$DataBase.characters[$selectedCharID]} character={$CurrentCharacter}
name={$DataBase.characters[$selectedCharID].name} name={$CurrentCharacter.name}
message={$DataBase.characters[$selectedCharID].firstMsgIndex === -1 ? $DataBase.characters[$selectedCharID].firstMessage : message={$CurrentCharacter.firstMsgIndex === -1 ? $CurrentCharacter.firstMessage :
$DataBase.characters[$selectedCharID].alternateGreetings[$DataBase.characters[$selectedCharID].firstMsgIndex]} $CurrentCharacter.alternateGreetings[$CurrentCharacter.firstMsgIndex]}
img={getCharImage($DataBase.characters[$selectedCharID].image, 'css')} img={getCharImage($CurrentCharacter.image, 'css')}
idx={-1} idx={-1}
altGreeting={$DataBase.characters[$selectedCharID].alternateGreetings.length > 0} altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
onReroll={() => { onReroll={() => {
const cha = $DataBase.characters[$selectedCharID] const cha = $CurrentCharacter
if(cha.type !== 'group'){ if(cha.type !== 'group'){
if (cha.firstMsgIndex >= (cha.alternateGreetings.length - 1)){ if (cha.firstMsgIndex >= (cha.alternateGreetings.length - 1)){
cha.firstMsgIndex = -1 cha.firstMsgIndex = -1
@@ -467,10 +467,10 @@
cha.firstMsgIndex += 1 cha.firstMsgIndex += 1
} }
} }
$DataBase.characters[$selectedCharID] = cha $CurrentCharacter = cha
}} }}
unReroll={() => { unReroll={() => {
const cha = $DataBase.characters[$selectedCharID] const cha = $CurrentCharacter
if(cha.type !== 'group'){ if(cha.type !== 'group'){
if (cha.firstMsgIndex === -1){ if (cha.firstMsgIndex === -1){
cha.firstMsgIndex = (cha.alternateGreetings.length - 1) cha.firstMsgIndex = (cha.alternateGreetings.length - 1)
@@ -479,18 +479,18 @@
cha.firstMsgIndex -= 1 cha.firstMsgIndex -= 1
} }
} }
$DataBase.characters[$selectedCharID] = cha $CurrentCharacter = cha
}} }}
isLastMemory={false} isLastMemory={false}
/> />
{#if !$DataBase.characters[$selectedCharID].removedQuotes && $DataBase.characters[$selectedCharID].creatorNotes.length >= 2} {#if !$CurrentCharacter.removedQuotes && $CurrentCharacter.creatorNotes.length >= 2}
<CreatorQuote quote={$DataBase.characters[$selectedCharID].creatorNotes} onRemove={() => { <CreatorQuote quote={$CurrentCharacter.creatorNotes} onRemove={() => {
const cha = $DataBase.characters[$selectedCharID] const cha = $CurrentCharacter
if(cha.type !== 'group'){ if(cha.type !== 'group'){
cha.removedQuotes = true cha.removedQuotes = true
} }
$DataBase.characters[$selectedCharID] = cha $CurrentCharacter = cha
}} /> }} />
{/if} {/if}
{/if} {/if}
@@ -500,7 +500,7 @@
<div class="absolute right-2 bottom-16 p-5 bg-darkbg flex flex-col gap-3 text-textcolor" on:click={(e) => { <div class="absolute right-2 bottom-16 p-5 bg-darkbg flex flex-col gap-3 text-textcolor" on:click={(e) => {
e.stopPropagation() e.stopPropagation()
}}> }}>
{#if $DataBase.characters[$selectedCharID].type === 'group'} {#if $CurrentCharacter.type === 'group'}
<div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" on:click={runAutoMode}> <div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" on:click={runAutoMode}>
<DicesIcon /> <DicesIcon />
<span class="ml-2">{language.autoMode}</span> <span class="ml-2">{language.autoMode}</span>
@@ -509,7 +509,7 @@
<!-- svelte-ignore empty-block --> <!-- svelte-ignore empty-block -->
{#if $DataBase.characters[$selectedCharID].ttsMode === 'webspeech' || $DataBase.characters[$selectedCharID].ttsMode === 'elevenlab'} {#if $CurrentCharacter.ttsMode === 'webspeech' || $CurrentCharacter.ttsMode === 'elevenlab'}
<div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" on:click={() => { <div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" on:click={() => {
stopTTS() stopTTS()
}}> }}>

View File

@@ -2,7 +2,7 @@
import { requestChatData } from "src/ts/process/request"; import { requestChatData } from "src/ts/process/request";
import { doingChat, type OpenAIChat } from "../../ts/process/index"; import { doingChat, type OpenAIChat } from "../../ts/process/index";
import { DataBase, setDatabase, type character, type Message, type groupChat, type Database } from "../../ts/storage/database"; import { DataBase, setDatabase, type character, type Message, type groupChat, type Database } from "../../ts/storage/database";
import { selectedCharID } from "../../ts/stores"; import { CurrentCharacter, selectedCharID } from "../../ts/stores";
import { translate } from "src/ts/translator/translator"; import { translate } from "src/ts/translator/translator";
import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte"; import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
import { alertConfirm } from "src/ts/alert"; import { alertConfirm } from "src/ts/alert";
@@ -15,7 +15,7 @@
export let send: () => any; export let send: () => any;
export let messageInput:(string:string) => any; export let messageInput:(string:string) => any;
let suggestMessages:string[] = $DataBase.characters[$selectedCharID]?.chats[$DataBase.characters[$selectedCharID].chatPage]?.suggestMessages let suggestMessages:string[] = $CurrentCharacter?.chats[$CurrentCharacter.chatPage]?.suggestMessages
let suggestMessagesTranslated:string[] let suggestMessagesTranslated:string[]
let toggleTranslate:boolean = $DataBase.autoTranslate let toggleTranslate:boolean = $DataBase.autoTranslate
let progress:boolean; let progress:boolean;
@@ -25,7 +25,7 @@
$: { $: {
$selectedCharID $selectedCharID
//FIXME add selectedChatPage for optimize render //FIXME add selectedChatPage for optimize render
chatPage = $DataBase.characters[$selectedCharID].chatPage chatPage = $CurrentCharacter.chatPage
updateSuggestions() updateSuggestions()
} }
@@ -35,7 +35,7 @@
progress=false progress=false
abortController?.abort() abortController?.abort()
} }
let currentChar = $DataBase.characters[$selectedCharID]; let currentChar = $CurrentCharacter;
suggestMessages = currentChar?.chats[currentChar.chatPage].suggestMessages suggestMessages = currentChar?.chats[currentChar.chatPage].suggestMessages
} }
} }
@@ -48,7 +48,7 @@
suggestMessages = [] suggestMessages = []
} }
if(!v && $selectedCharID > -1 && (!suggestMessages || suggestMessages.length === 0) && !progress){ if(!v && $selectedCharID > -1 && (!suggestMessages || suggestMessages.length === 0) && !progress){
let currentChar:character|groupChat = $DataBase.characters[$selectedCharID]; let currentChar:character|groupChat = $CurrentCharacter;
let messages:Message[] = [] let messages:Message[] = []
if(currentChar.type !== 'group'){ if(currentChar.type !== 'group'){

View File

@@ -2,7 +2,7 @@
import { alertConfirm, alertError } from "../../ts/alert"; import { alertConfirm, alertError } from "../../ts/alert";
import { language } from "../../lang"; import { language } from "../../lang";
import { DataBase } from "../../ts/storage/database"; import { DataBase } from "../../ts/storage/database";
import { selectedCharID } from "../../ts/stores"; import { CurrentCharacter, selectedCharID } from "../../ts/stores";
import { DownloadIcon, EditIcon, FolderUpIcon, PlusIcon, TrashIcon, XIcon } from "lucide-svelte"; import { DownloadIcon, EditIcon, FolderUpIcon, PlusIcon, TrashIcon, XIcon } from "lucide-svelte";
import { exportChat, importChat } from "../../ts/characters"; import { exportChat, importChat } from "../../ts/characters";
import { findCharacterbyId } from "../../ts/util"; import { findCharacterbyId } from "../../ts/util";
@@ -22,15 +22,15 @@
</button> </button>
</div> </div>
</div> </div>
{#each $DataBase.characters[$selectedCharID].chats as chat, i} {#each $CurrentCharacter.chats as chat, i}
<button on:click={() => { <button on:click={() => {
if(!editMode){ if(!editMode){
$DataBase.characters[$selectedCharID].chatPage = i $CurrentCharacter.chatPage = i
close() close()
} }
}} class="flex items-center text-textcolor border-t-1 border-solid border-0 border-darkborderc p-2 cursor-pointer" class:bg-selected={i === $DataBase.characters[$selectedCharID].chatPage}> }} class="flex items-center text-textcolor border-t-1 border-solid border-0 border-darkborderc p-2 cursor-pointer" class:bg-selected={i === $CurrentCharacter.chatPage}>
{#if editMode} {#if editMode}
<TextInput bind:value={$DataBase.characters[$selectedCharID].chats[i].name} padding={false}/> <TextInput bind:value={$CurrentCharacter.chats[i].name} padding={false}/>
{:else} {:else}
<span>{chat.name}</span> <span>{chat.name}</span>
{/if} {/if}
@@ -43,16 +43,16 @@
</button> </button>
<button class="text-textcolor2 hover:text-green-500 cursor-pointer" on:click={async (e) => { <button class="text-textcolor2 hover:text-green-500 cursor-pointer" on:click={async (e) => {
e.stopPropagation() e.stopPropagation()
if($DataBase.characters[$selectedCharID].chats.length === 1){ if($CurrentCharacter.chats.length === 1){
alertError(language.errors.onlyOneChat) alertError(language.errors.onlyOneChat)
return return
} }
const d = await alertConfirm(`${language.removeConfirm}${chat.name}`) const d = await alertConfirm(`${language.removeConfirm}${chat.name}`)
if(d){ if(d){
$DataBase.characters[$selectedCharID].chatPage = 0 $CurrentCharacter.chatPage = 0
let chats = $DataBase.characters[$selectedCharID].chats let chats = $CurrentCharacter.chats
chats.splice(i, 1) chats.splice(i, 1)
$DataBase.characters[$selectedCharID].chats = chats $CurrentCharacter.chats = chats
} }
}}> }}>
<TrashIcon size={18}/> <TrashIcon size={18}/>
@@ -62,9 +62,9 @@
{/each} {/each}
<div class="flex mt-2 items-center"> <div class="flex mt-2 items-center">
<button class="text-textcolor2 hover:text-green-500 cursor-pointer mr-1" on:click={() => { <button class="text-textcolor2 hover:text-green-500 cursor-pointer mr-1" on:click={() => {
const cha = $DataBase.characters[$selectedCharID] const cha = $CurrentCharacter
const len = $DataBase.characters[$selectedCharID].chats.length const len = $CurrentCharacter.chats.length
let chats = $DataBase.characters[$selectedCharID].chats let chats = $CurrentCharacter.chats
chats.push({ chats.push({
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[] message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
}) })
@@ -77,8 +77,8 @@
}) })
}) })
} }
$DataBase.characters[$selectedCharID].chats = chats $CurrentCharacter.chats = chats
$DataBase.characters[$selectedCharID].chatPage = len $CurrentCharacter.chatPage = len
close() close()
}}> }}>
<PlusIcon/> <PlusIcon/>

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { DataBase, type loreBook } from "src/ts/storage/database"; import { DataBase, type loreBook } from "src/ts/storage/database";
import LoreBookData from "./LoreBookData.svelte"; import LoreBookData from "./LoreBookData.svelte";
import { selectedCharID } from "src/ts/stores"; import { CurrentChat, CurrentCharacter } from "src/ts/stores";
import Sortable from 'sortablejs/modular/sortable.core.esm.js'; import Sortable from 'sortablejs/modular/sortable.core.esm.js';
import { onDestroy, onMount } from "svelte"; import { onDestroy, onMount } from "svelte";
import { sleep } from "src/ts/util"; import { sleep } from "src/ts/util";
@@ -28,16 +28,16 @@
else if(submenu === 1){ else if(submenu === 1){
let newLore:loreBook[] = [] let newLore:loreBook[] = []
idx.forEach((i) => { idx.forEach((i) => {
newLore.push($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]) newLore.push($CurrentChat.localLore[i])
}) })
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = newLore $CurrentChat.localLore = newLore
} }
else{ else{
let newLore:loreBook[] = [] let newLore:loreBook[] = []
idx.forEach((i) => { idx.forEach((i) => {
newLore.push($DataBase.characters[$selectedCharID].globalLore[i]) newLore.push($CurrentCharacter.globalLore[i])
}) })
$DataBase.characters[$selectedCharID].globalLore = newLore $CurrentCharacter.globalLore = newLore
} }
stb.destroy() stb.destroy()
sorted += 1 sorted += 1
@@ -86,26 +86,26 @@
{/each} {/each}
{/if} {/if}
{:else if submenu === 0} {:else if submenu === 0}
{#if $DataBase.characters[$selectedCharID].globalLore.length === 0} {#if $CurrentCharacter.globalLore.length === 0}
<span class="text-textcolor2">No Lorebook</span> <span class="text-textcolor2">No Lorebook</span>
{:else} {:else}
{#each $DataBase.characters[$selectedCharID].globalLore as book, i} {#each $CurrentCharacter.globalLore as book, i}
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].globalLore[i]} idx={i} onRemove={() => { <LoreBookData bind:value={$CurrentCharacter.globalLore[i]} idx={i} onRemove={() => {
let lore = $DataBase.characters[$selectedCharID].globalLore let lore = $CurrentCharacter.globalLore
lore.splice(i, 1) lore.splice(i, 1)
$DataBase.characters[$selectedCharID].globalLore = lore $CurrentCharacter.globalLore = lore
}} onOpen={onOpen} onClose={onClose}/> }} onOpen={onOpen} onClose={onClose}/>
{/each} {/each}
{/if} {/if}
{:else if submenu === 1} {:else if submenu === 1}
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore.length === 0} {#if $CurrentChat.localLore.length === 0}
<span class="text-textcolor2">No Lorebook</span> <span class="text-textcolor2">No Lorebook</span>
{:else} {:else}
{#each $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore as book, i} {#each $CurrentChat.localLore as book, i}
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]} idx={i} onRemove={() => { <LoreBookData bind:value={$CurrentChat.localLore[i]} idx={i} onRemove={() => {
let lore = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore let lore = $CurrentChat.localLore
lore.splice(i, 1) lore.splice(i, 1)
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = lore $CurrentChat.localLore = lore
}} onOpen={onOpen} onClose={onClose}/> }} onOpen={onOpen} onClose={onClose}/>
{/each} {/each}
{/if} {/if}

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { DataBase } from "../../../ts/storage/database"; import { DataBase } from "../../../ts/storage/database";
import { language } from "../../../lang"; import { language } from "../../../lang";
import {selectedCharID} from '../../../ts/stores' import {CurrentCharacter, selectedCharID} from '../../../ts/stores'
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte"; import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook"; import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook";
import Check from "../../UI/GUI/CheckInput.svelte"; import Check from "../../UI/GUI/CheckInput.svelte";
@@ -17,7 +17,7 @@
<button on:click={() => { <button on:click={() => {
submenu = 0 submenu = 0
}} class="p-2 flex-1" class:bg-selected={submenu === 0}> }} class="p-2 flex-1" class:bg-selected={submenu === 0}>
<span>{$DataBase.characters[$selectedCharID].type === 'group' ? language.group : language.character}</span> <span>{$CurrentCharacter.type === 'group' ? language.group : language.character}</span>
</button> </button>
<button on:click={() => { <button on:click={() => {
submenu = 1 submenu = 1
@@ -33,32 +33,32 @@
{/if} {/if}
{#if submenu !== 2} {#if submenu !== 2}
{#if !globalMode} {#if !globalMode}
<span class="text-textcolor2 mt-2 mb-6 text-sm">{submenu === 0 ? $DataBase.characters[$selectedCharID].type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span> <span class="text-textcolor2 mt-2 mb-6 text-sm">{submenu === 0 ? $CurrentCharacter.type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span>
{/if} {/if}
<LoreBookList bind:globalMode bind:submenu /> <LoreBookList bind:globalMode bind:submenu />
{:else} {:else}
{#if $DataBase.characters[$selectedCharID].loreSettings} {#if $CurrentCharacter.loreSettings}
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check check={false} onChange={() => { <Check check={false} onChange={() => {
$DataBase.characters[$selectedCharID].loreSettings = undefined $CurrentCharacter.loreSettings = undefined
}} }}
name={language.useGlobalSettings} name={language.useGlobalSettings}
/> />
</div> </div>
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check bind:check={$DataBase.characters[$selectedCharID].loreSettings.recursiveScanning} name={language.recursiveScanning}/> <Check bind:check={$CurrentCharacter.loreSettings.recursiveScanning} name={language.recursiveScanning}/>
</div> </div>
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check bind:check={$DataBase.characters[$selectedCharID].loreSettings.fullWordMatching} name={language.fullWordMatching}/> <Check bind:check={$CurrentCharacter.loreSettings.fullWordMatching} name={language.fullWordMatching}/>
</div> </div>
<span class="text-textcolor mt-4 mb-2">{language.loreBookDepth}</span> <span class="text-textcolor mt-4 mb-2">{language.loreBookDepth}</span>
<NumberInput size="sm" min={0} max={20} bind:value={$DataBase.characters[$selectedCharID].loreSettings.scanDepth} /> <NumberInput size="sm" min={0} max={20} bind:value={$CurrentCharacter.loreSettings.scanDepth} />
<span class="text-textcolor">{language.loreBookToken}</span> <span class="text-textcolor">{language.loreBookToken}</span>
<NumberInput size="sm" min={0} max={4096} bind:value={$DataBase.characters[$selectedCharID].loreSettings.tokenBudget} /> <NumberInput size="sm" min={0} max={4096} bind:value={$CurrentCharacter.loreSettings.tokenBudget} />
{:else} {:else}
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check check={true} onChange={() => { <Check check={true} onChange={() => {
$DataBase.characters[$selectedCharID].loreSettings = { $CurrentCharacter.loreSettings = {
tokenBudget: $DataBase.loreBookToken, tokenBudget: $DataBase.loreBookToken,
scanDepth:$DataBase.loreBookDepth, scanDepth:$DataBase.loreBookDepth,
recursiveScanning: false recursiveScanning: false

View File

@@ -7,6 +7,7 @@
settingsOpen, settingsOpen,
sideBarClosing, sideBarClosing,
sideBarStore, sideBarStore,
CurrentCharacter
} from "../../ts/stores"; } from "../../ts/stores";
import { DataBase, setDatabase, type folder } from "../../ts/storage/database"; import { DataBase, setDatabase, type folder } from "../../ts/storage/database";
import BarIcon from "./BarIcon.svelte"; import BarIcon from "./BarIcon.svelte";
@@ -626,7 +627,7 @@
{#if $botMakerMode} {#if $botMakerMode}
<CharConfig /> <CharConfig />
{:else} {:else}
<SideChatList bind:chara={ $DataBase.characters[$selectedCharID]} /> <SideChatList bind:chara={ $CurrentCharacter} />
{/if} {/if}
{/if} {/if}
{:else if sideBarMode === 1} {:else if sideBarMode === 1}

View File

@@ -197,7 +197,6 @@ export async function saveAsset(data:Uint8Array, customId:string = '', fileName:
let form = `assets/${id}.${fileExtension}` let form = `assets/${id}.${fileExtension}`
const replacer = await forageStorage.setItem(form, data) const replacer = await forageStorage.setItem(form, data)
if(replacer){ if(replacer){
console.log(replacer)
return replacer return replacer
} }
return form return form
@@ -279,7 +278,6 @@ async function getDbBackups() {
backups.push(parseInt(da)) backups.push(parseInt(da))
} }
} }
console.log(backups)
while(backups.length > 20){ while(backups.length > 20){
const last = backups.pop() const last = backups.pop()
await forageStorage.removeItem(`database/dbbackup-${last}.bin`) await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
@@ -511,8 +509,6 @@ export async function globalFetch(url:string, arg:{
const urlHost = (new URL(url)).hostname const urlHost = (new URL(url)).hostname
let forcePlainFetch = (knownHostes.includes(urlHost) && (!isTauri)) || db.usePlainFetch || arg.plainFetchForce let forcePlainFetch = (knownHostes.includes(urlHost) && (!isTauri)) || db.usePlainFetch || arg.plainFetchForce
console.log(urlHost)
//check if the url is a local url like localhost //check if the url is a local url like localhost
if(urlHost.includes("localhost") || urlHost.includes("172.0.0.1") || urlHost.includes("0.0.0.0")){ if(urlHost.includes("localhost") || urlHost.includes("172.0.0.1") || urlHost.includes("0.0.0.0")){
if((!isTauri) && (!isNodeServer)){ if((!isTauri) && (!isNodeServer)){
@@ -704,7 +700,6 @@ export async function globalFetch(url:string, arg:{
} }
} }
} catch (error) { } catch (error) {
console.log(error)
return { return {
ok:false, ok:false,
data: `${error}`, data: `${error}`,
@@ -969,7 +964,6 @@ export function getRequestLog(){
logString += `## ${log.date}\n\n* Request URL\n\n${b}${log.url}${bend}\n\n* Request Body\n\n${b}${log.body}${bend}\n\n* Request Header\n\n${b}${log.header}${bend}\n\n` logString += `## ${log.date}\n\n* Request URL\n\n${b}${log.url}${bend}\n\n* Request Body\n\n${b}${log.body}${bend}\n\n* Request Header\n\n${b}${log.header}${bend}\n\n`
+ `* Response Body\n\n${b}${log.response}${bend}\n\n* Response Success\n\n${b}${log.success}${bend}\n\n` + `* Response Body\n\n${b}${log.response}${bend}\n\n* Response Success\n\n${b}${log.success}${bend}\n\n`
} }
console.log(logString)
return logString return logString
} }

View File

@@ -1,4 +1,6 @@
import { writable } from "svelte/store"; import { get, writable } from "svelte/store";
import { DataBase } from "./storage/database";
import { cloneDeep, isEqual } from "lodash";
function updateSize(){ function updateSize(){
SizeStore.set({ SizeStore.set({
@@ -21,5 +23,82 @@ export const ViewBoxsize = writable({ width: 12 * 16, height: 12 * 16 }); // Def
export const settingsOpen = writable(false) export const settingsOpen = writable(false)
export const botMakerMode = writable(false) export const botMakerMode = writable(false)
//optimization
let db = get(DataBase)
let currentChar = get(selectedCharID)
let currentCharacter = db.characters ? (db.characters[currentChar]) : null
let currentChat = currentCharacter ? (currentCharacter.chats[currentCharacter.chatPage]) : null
export const CurrentCharacter = writable(cloneDeep(currentCharacter))
export const CurrentChat = writable(cloneDeep(currentChat))
function updateCurrentCharacter(){
const db = get(DataBase)
if(!db.characters){
CurrentCharacter.set(null)
updateCurrentChat()
return
}
const currentCharId = get(selectedCharID)
const currentChar = db.characters[currentCharId]
const gotCharacter = get(CurrentCharacter)
if(isEqual(gotCharacter, currentChar)){
return
}
console.log("Character updated")
CurrentCharacter.set(cloneDeep(currentChar))
updateCurrentChat()
}
function updateCurrentChat(){
const currentChar = get(CurrentCharacter)
if(!currentChar){
CurrentChat.set(null)
return
}
const chat = (currentChar.chats[currentChar.chatPage])
const gotChat = get(CurrentChat)
if(isEqual(gotChat, chat)){
return
}
CurrentChat.set(cloneDeep(chat))
}
DataBase.subscribe((data) => {
updateCurrentCharacter()
})
selectedCharID.subscribe((id) => {
updateCurrentCharacter()
})
CurrentCharacter.subscribe((char) => {
updateCurrentChat()
let db = get(DataBase)
let charId = get(selectedCharID)
if(charId === -1 || charId > db.characters.length){
return
}
let cha = db.characters[charId]
if(isEqual(cha, char)){
return
}
db.characters[charId] = cloneDeep(char)
DataBase.set(db)
})
CurrentChat.subscribe((chat) => {
let currentChar = get(CurrentCharacter)
if(currentChar){
if(isEqual(currentChar.chats[currentChar.chatPage], chat)){
return
}
currentChar.chats[currentChar.chatPage] = cloneDeep(chat)
CurrentCharacter.set(currentChar)
}
})
updateSize() updateSize()
window.addEventListener("resize", updateSize); window.addEventListener("resize", updateSize);