[feat] performace improvement stage 1
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
import { alertConfirm } from "../../ts/alert";
|
||||
import { language } from "../../lang";
|
||||
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 { risuChatParser } from "src/ts/process/scripts";
|
||||
import { risuChatParser } from "src/ts/process/scripts";
|
||||
export let message = ''
|
||||
export let name = ''
|
||||
export let isLastMemory:boolean
|
||||
@@ -30,27 +30,27 @@
|
||||
if(rm){
|
||||
if($DataBase.instantRemove){
|
||||
const r = await alertConfirm(language.instantRemoveConfirm)
|
||||
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message
|
||||
let msg = $CurrentChat.message
|
||||
if(!r){
|
||||
msg = msg.slice(0, idx)
|
||||
}
|
||||
else{
|
||||
msg.splice(idx, 1)
|
||||
}
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg
|
||||
$CurrentChat.message = msg
|
||||
}
|
||||
else{
|
||||
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message
|
||||
let msg = $CurrentChat.message
|
||||
msg.splice(idx, 1)
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg
|
||||
$CurrentChat.message = msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function edit(){
|
||||
let msg = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message
|
||||
let msg = $CurrentChat.message
|
||||
msg[idx].data = message
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = msg
|
||||
$CurrentChat.message = msg
|
||||
}
|
||||
|
||||
async function displaya(message:string){
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { getCustomBackground, getEmotion } from "../../ts/util";
|
||||
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 DefaultChatScreen from "./DefaultChatScreen.svelte";
|
||||
import defaultWallpaper from '../../etc/bg.jpg'
|
||||
@@ -33,7 +33,7 @@
|
||||
<BackgroundDom />
|
||||
<div style={bgImg} class="h-full w-full" class:max-w-6xl={$DataBase.classicMaxWidth}>
|
||||
{#if $selectedCharID >= 0}
|
||||
{#if $DataBase.characters[$selectedCharID].viewScreen !== 'none'}
|
||||
{#if $CurrentCharacter.viewScreen !== 'none'}
|
||||
<ResizeBox />
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -45,13 +45,13 @@
|
||||
<SideBarArrow />
|
||||
<BackgroundDom />
|
||||
{#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">
|
||||
<TransitionImage classType="waifu" src={getEmotion($DataBase, $CharEmotion, 'plain')}/>
|
||||
</div>
|
||||
{/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/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,13 +60,13 @@
|
||||
<SideBarArrow />
|
||||
<BackgroundDom />
|
||||
<div class="w-full absolute z-10 bottom-0 left-0"
|
||||
class:per33={$selectedCharID >= 0 && $DataBase.characters[$selectedCharID].viewScreen !== 'none'}
|
||||
class:h-full={!($selectedCharID >= 0 && $DataBase.characters[$selectedCharID].viewScreen !== 'none')}
|
||||
class:per33={$selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none'}
|
||||
class:h-full={!($selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none')}
|
||||
>
|
||||
<DefaultChatScreen customStyle={`${externalStyles}backdrop-filter: blur(4px);`} bind:openChatList/>
|
||||
</div>
|
||||
{#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">
|
||||
<TransitionImage classType="mobile" src={getEmotion($DataBase, $CharEmotion, 'plain')}/>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Suggestion from './Suggestion.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 { DataBase, type Message, type character, type groupChat } from "../../ts/storage/database";
|
||||
import { getCharImage } from "../../ts/characters";
|
||||
@@ -18,8 +18,8 @@
|
||||
import MainMenu from '../UI/MainMenu.svelte';
|
||||
import Help from '../Others/Help.svelte';
|
||||
import AssetInput from './AssetInput.svelte';
|
||||
import { downloadFile } from 'src/ts/storage/globalApi';
|
||||
import { runTrigger } from 'src/ts/process/triggers';
|
||||
import { downloadFile } from 'src/ts/storage/globalApi';
|
||||
import { runTrigger } from 'src/ts/process/triggers';
|
||||
|
||||
let messageInput:string = ''
|
||||
let messageInputTranslate:string = ''
|
||||
@@ -31,7 +31,7 @@
|
||||
let rerollid = -1
|
||||
let lastCharId = -1
|
||||
let doingChatInputTranslate = false
|
||||
let currentCharacter:character|groupChat = $DataBase.characters[$selectedCharID]
|
||||
let currentCharacter:character|groupChat = $CurrentCharacter
|
||||
let toggleStickers:boolean = false
|
||||
|
||||
async function send() {
|
||||
@@ -103,16 +103,16 @@
|
||||
if(Array.isArray(rerolls[rerollid + 1])){
|
||||
let db = $DataBase
|
||||
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
|
||||
}
|
||||
return
|
||||
}
|
||||
if(rerolls.length === 0){
|
||||
rerolls.push($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message)
|
||||
rerolls.push($CurrentChat.message)
|
||||
rerollid = rerolls.length - 1
|
||||
}
|
||||
let cha = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message
|
||||
let cha = $CurrentChat.message
|
||||
if(cha.length === 0 ){
|
||||
return
|
||||
}
|
||||
@@ -128,7 +128,7 @@
|
||||
}
|
||||
cha.pop()
|
||||
}
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message = cha
|
||||
$CurrentChat.message = cha
|
||||
await sendChatMain()
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
if(Array.isArray(rerolls[rerollid - 1])){
|
||||
let db = $DataBase
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@
|
||||
console.error(error)
|
||||
alertError(`${error}`)
|
||||
}
|
||||
rerolls.push(cloneDeep($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message))
|
||||
rerolls.push(cloneDeep($CurrentChat.message))
|
||||
rerollid = rerolls.length - 1
|
||||
lastCharId = $selectedCharID
|
||||
$doingChat = false
|
||||
@@ -295,7 +295,7 @@
|
||||
}
|
||||
|
||||
$: {
|
||||
currentCharacter = $DataBase.characters[$selectedCharID]
|
||||
currentCharacter = $CurrentCharacter
|
||||
}
|
||||
</script>
|
||||
<!-- 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) => {
|
||||
//@ts-ignore
|
||||
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
|
||||
}
|
||||
}}>
|
||||
@@ -409,19 +409,19 @@
|
||||
)} {send}/>
|
||||
{/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 $DataBase.characters[$selectedCharID].type !== 'group'}
|
||||
{#if $CurrentCharacter.type !== 'group'}
|
||||
<Chat
|
||||
idx={chat.index}
|
||||
name={$DataBase.characters[$selectedCharID].name}
|
||||
name={$CurrentCharacter.name}
|
||||
message={chat.data}
|
||||
img={getCharImage($DataBase.characters[$selectedCharID].image, 'css')}
|
||||
img={getCharImage($CurrentCharacter.image, 'css')}
|
||||
rerollIcon={i === 0}
|
||||
onReroll={reroll}
|
||||
unReroll={unReroll}
|
||||
isLastMemory={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||
character={$DataBase.characters[$selectedCharID]}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||
character={$CurrentCharacter}
|
||||
/>
|
||||
{:else}
|
||||
<Chat
|
||||
@@ -432,33 +432,33 @@
|
||||
onReroll={reroll}
|
||||
unReroll={unReroll}
|
||||
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)}
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<Chat
|
||||
character={$DataBase.characters[$selectedCharID]}
|
||||
character={$CurrentCharacter}
|
||||
idx={chat.index}
|
||||
name={$DataBase.username}
|
||||
message={chat.data}
|
||||
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}
|
||||
{/each}
|
||||
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message.length <= loadPages}
|
||||
{#if $DataBase.characters[$selectedCharID].type !== 'group'}
|
||||
{#if $CurrentChat.message.length <= loadPages}
|
||||
{#if $CurrentCharacter.type !== 'group'}
|
||||
<Chat
|
||||
character={$DataBase.characters[$selectedCharID]}
|
||||
name={$DataBase.characters[$selectedCharID].name}
|
||||
message={$DataBase.characters[$selectedCharID].firstMsgIndex === -1 ? $DataBase.characters[$selectedCharID].firstMessage :
|
||||
$DataBase.characters[$selectedCharID].alternateGreetings[$DataBase.characters[$selectedCharID].firstMsgIndex]}
|
||||
img={getCharImage($DataBase.characters[$selectedCharID].image, 'css')}
|
||||
character={$CurrentCharacter}
|
||||
name={$CurrentCharacter.name}
|
||||
message={$CurrentCharacter.firstMsgIndex === -1 ? $CurrentCharacter.firstMessage :
|
||||
$CurrentCharacter.alternateGreetings[$CurrentCharacter.firstMsgIndex]}
|
||||
img={getCharImage($CurrentCharacter.image, 'css')}
|
||||
idx={-1}
|
||||
altGreeting={$DataBase.characters[$selectedCharID].alternateGreetings.length > 0}
|
||||
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
|
||||
onReroll={() => {
|
||||
const cha = $DataBase.characters[$selectedCharID]
|
||||
const cha = $CurrentCharacter
|
||||
if(cha.type !== 'group'){
|
||||
if (cha.firstMsgIndex >= (cha.alternateGreetings.length - 1)){
|
||||
cha.firstMsgIndex = -1
|
||||
@@ -467,10 +467,10 @@
|
||||
cha.firstMsgIndex += 1
|
||||
}
|
||||
}
|
||||
$DataBase.characters[$selectedCharID] = cha
|
||||
$CurrentCharacter = cha
|
||||
}}
|
||||
unReroll={() => {
|
||||
const cha = $DataBase.characters[$selectedCharID]
|
||||
const cha = $CurrentCharacter
|
||||
if(cha.type !== 'group'){
|
||||
if (cha.firstMsgIndex === -1){
|
||||
cha.firstMsgIndex = (cha.alternateGreetings.length - 1)
|
||||
@@ -479,18 +479,18 @@
|
||||
cha.firstMsgIndex -= 1
|
||||
}
|
||||
}
|
||||
$DataBase.characters[$selectedCharID] = cha
|
||||
$CurrentCharacter = cha
|
||||
}}
|
||||
isLastMemory={false}
|
||||
|
||||
/>
|
||||
{#if !$DataBase.characters[$selectedCharID].removedQuotes && $DataBase.characters[$selectedCharID].creatorNotes.length >= 2}
|
||||
<CreatorQuote quote={$DataBase.characters[$selectedCharID].creatorNotes} onRemove={() => {
|
||||
const cha = $DataBase.characters[$selectedCharID]
|
||||
{#if !$CurrentCharacter.removedQuotes && $CurrentCharacter.creatorNotes.length >= 2}
|
||||
<CreatorQuote quote={$CurrentCharacter.creatorNotes} onRemove={() => {
|
||||
const cha = $CurrentCharacter
|
||||
if(cha.type !== 'group'){
|
||||
cha.removedQuotes = true
|
||||
}
|
||||
$DataBase.characters[$selectedCharID] = cha
|
||||
$CurrentCharacter = cha
|
||||
}} />
|
||||
{/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) => {
|
||||
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}>
|
||||
<DicesIcon />
|
||||
<span class="ml-2">{language.autoMode}</span>
|
||||
@@ -509,7 +509,7 @@
|
||||
|
||||
|
||||
<!-- 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={() => {
|
||||
stopTTS()
|
||||
}}>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { requestChatData } from "src/ts/process/request";
|
||||
import { doingChat, type OpenAIChat } from "../../ts/process/index";
|
||||
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 { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
|
||||
import { alertConfirm } from "src/ts/alert";
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
export let send: () => 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 toggleTranslate:boolean = $DataBase.autoTranslate
|
||||
let progress:boolean;
|
||||
@@ -25,7 +25,7 @@
|
||||
$: {
|
||||
$selectedCharID
|
||||
//FIXME add selectedChatPage for optimize render
|
||||
chatPage = $DataBase.characters[$selectedCharID].chatPage
|
||||
chatPage = $CurrentCharacter.chatPage
|
||||
updateSuggestions()
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
progress=false
|
||||
abortController?.abort()
|
||||
}
|
||||
let currentChar = $DataBase.characters[$selectedCharID];
|
||||
let currentChar = $CurrentCharacter;
|
||||
suggestMessages = currentChar?.chats[currentChar.chatPage].suggestMessages
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@
|
||||
suggestMessages = []
|
||||
}
|
||||
if(!v && $selectedCharID > -1 && (!suggestMessages || suggestMessages.length === 0) && !progress){
|
||||
let currentChar:character|groupChat = $DataBase.characters[$selectedCharID];
|
||||
let currentChar:character|groupChat = $CurrentCharacter;
|
||||
let messages:Message[] = []
|
||||
|
||||
if(currentChar.type !== 'group'){
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { alertConfirm, alertError } from "../../ts/alert";
|
||||
import { language } from "../../lang";
|
||||
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 { exportChat, importChat } from "../../ts/characters";
|
||||
import { findCharacterbyId } from "../../ts/util";
|
||||
@@ -22,15 +22,15 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{#each $DataBase.characters[$selectedCharID].chats as chat, i}
|
||||
{#each $CurrentCharacter.chats as chat, i}
|
||||
<button on:click={() => {
|
||||
if(!editMode){
|
||||
$DataBase.characters[$selectedCharID].chatPage = i
|
||||
$CurrentCharacter.chatPage = i
|
||||
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}
|
||||
<TextInput bind:value={$DataBase.characters[$selectedCharID].chats[i].name} padding={false}/>
|
||||
<TextInput bind:value={$CurrentCharacter.chats[i].name} padding={false}/>
|
||||
{:else}
|
||||
<span>{chat.name}</span>
|
||||
{/if}
|
||||
@@ -43,16 +43,16 @@
|
||||
</button>
|
||||
<button class="text-textcolor2 hover:text-green-500 cursor-pointer" on:click={async (e) => {
|
||||
e.stopPropagation()
|
||||
if($DataBase.characters[$selectedCharID].chats.length === 1){
|
||||
if($CurrentCharacter.chats.length === 1){
|
||||
alertError(language.errors.onlyOneChat)
|
||||
return
|
||||
}
|
||||
const d = await alertConfirm(`${language.removeConfirm}${chat.name}`)
|
||||
if(d){
|
||||
$DataBase.characters[$selectedCharID].chatPage = 0
|
||||
let chats = $DataBase.characters[$selectedCharID].chats
|
||||
$CurrentCharacter.chatPage = 0
|
||||
let chats = $CurrentCharacter.chats
|
||||
chats.splice(i, 1)
|
||||
$DataBase.characters[$selectedCharID].chats = chats
|
||||
$CurrentCharacter.chats = chats
|
||||
}
|
||||
}}>
|
||||
<TrashIcon size={18}/>
|
||||
@@ -62,9 +62,9 @@
|
||||
{/each}
|
||||
<div class="flex mt-2 items-center">
|
||||
<button class="text-textcolor2 hover:text-green-500 cursor-pointer mr-1" on:click={() => {
|
||||
const cha = $DataBase.characters[$selectedCharID]
|
||||
const len = $DataBase.characters[$selectedCharID].chats.length
|
||||
let chats = $DataBase.characters[$selectedCharID].chats
|
||||
const cha = $CurrentCharacter
|
||||
const len = $CurrentCharacter.chats.length
|
||||
let chats = $CurrentCharacter.chats
|
||||
chats.push({
|
||||
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
|
||||
})
|
||||
@@ -77,8 +77,8 @@
|
||||
})
|
||||
})
|
||||
}
|
||||
$DataBase.characters[$selectedCharID].chats = chats
|
||||
$DataBase.characters[$selectedCharID].chatPage = len
|
||||
$CurrentCharacter.chats = chats
|
||||
$CurrentCharacter.chatPage = len
|
||||
close()
|
||||
}}>
|
||||
<PlusIcon/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { DataBase, type loreBook } from "src/ts/storage/database";
|
||||
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 { onDestroy, onMount } from "svelte";
|
||||
import { sleep } from "src/ts/util";
|
||||
@@ -28,16 +28,16 @@
|
||||
else if(submenu === 1){
|
||||
let newLore:loreBook[] = []
|
||||
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{
|
||||
let newLore:loreBook[] = []
|
||||
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()
|
||||
sorted += 1
|
||||
@@ -86,26 +86,26 @@
|
||||
{/each}
|
||||
{/if}
|
||||
{:else if submenu === 0}
|
||||
{#if $DataBase.characters[$selectedCharID].globalLore.length === 0}
|
||||
{#if $CurrentCharacter.globalLore.length === 0}
|
||||
<span class="text-textcolor2">No Lorebook</span>
|
||||
{:else}
|
||||
{#each $DataBase.characters[$selectedCharID].globalLore as book, i}
|
||||
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].globalLore[i]} idx={i} onRemove={() => {
|
||||
let lore = $DataBase.characters[$selectedCharID].globalLore
|
||||
{#each $CurrentCharacter.globalLore as book, i}
|
||||
<LoreBookData bind:value={$CurrentCharacter.globalLore[i]} idx={i} onRemove={() => {
|
||||
let lore = $CurrentCharacter.globalLore
|
||||
lore.splice(i, 1)
|
||||
$DataBase.characters[$selectedCharID].globalLore = lore
|
||||
$CurrentCharacter.globalLore = lore
|
||||
}} onOpen={onOpen} onClose={onClose}/>
|
||||
{/each}
|
||||
{/if}
|
||||
{: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>
|
||||
{:else}
|
||||
{#each $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore as book, i}
|
||||
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]} idx={i} onRemove={() => {
|
||||
let lore = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore
|
||||
{#each $CurrentChat.localLore as book, i}
|
||||
<LoreBookData bind:value={$CurrentChat.localLore[i]} idx={i} onRemove={() => {
|
||||
let lore = $CurrentChat.localLore
|
||||
lore.splice(i, 1)
|
||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = lore
|
||||
$CurrentChat.localLore = lore
|
||||
}} onOpen={onOpen} onClose={onClose}/>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { DataBase } from "../../../ts/storage/database";
|
||||
import { language } from "../../../lang";
|
||||
import {selectedCharID} from '../../../ts/stores'
|
||||
import {CurrentCharacter, selectedCharID} from '../../../ts/stores'
|
||||
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
|
||||
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook";
|
||||
import Check from "../../UI/GUI/CheckInput.svelte";
|
||||
@@ -17,7 +17,7 @@
|
||||
<button on:click={() => {
|
||||
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 on:click={() => {
|
||||
submenu = 1
|
||||
@@ -33,32 +33,32 @@
|
||||
{/if}
|
||||
{#if submenu !== 2}
|
||||
{#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}
|
||||
<LoreBookList bind:globalMode bind:submenu />
|
||||
{:else}
|
||||
{#if $DataBase.characters[$selectedCharID].loreSettings}
|
||||
{#if $CurrentCharacter.loreSettings}
|
||||
<div class="flex items-center mt-4">
|
||||
<Check check={false} onChange={() => {
|
||||
$DataBase.characters[$selectedCharID].loreSettings = undefined
|
||||
$CurrentCharacter.loreSettings = undefined
|
||||
}}
|
||||
name={language.useGlobalSettings}
|
||||
/>
|
||||
</div>
|
||||
<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 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>
|
||||
<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>
|
||||
<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}
|
||||
<div class="flex items-center mt-4">
|
||||
<Check check={true} onChange={() => {
|
||||
$DataBase.characters[$selectedCharID].loreSettings = {
|
||||
$CurrentCharacter.loreSettings = {
|
||||
tokenBudget: $DataBase.loreBookToken,
|
||||
scanDepth:$DataBase.loreBookDepth,
|
||||
recursiveScanning: false
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
settingsOpen,
|
||||
sideBarClosing,
|
||||
sideBarStore,
|
||||
CurrentCharacter
|
||||
} from "../../ts/stores";
|
||||
import { DataBase, setDatabase, type folder } from "../../ts/storage/database";
|
||||
import BarIcon from "./BarIcon.svelte";
|
||||
@@ -626,7 +627,7 @@
|
||||
{#if $botMakerMode}
|
||||
<CharConfig />
|
||||
{:else}
|
||||
<SideChatList bind:chara={ $DataBase.characters[$selectedCharID]} />
|
||||
<SideChatList bind:chara={ $CurrentCharacter} />
|
||||
{/if}
|
||||
{/if}
|
||||
{:else if sideBarMode === 1}
|
||||
|
||||
@@ -197,7 +197,6 @@ export async function saveAsset(data:Uint8Array, customId:string = '', fileName:
|
||||
let form = `assets/${id}.${fileExtension}`
|
||||
const replacer = await forageStorage.setItem(form, data)
|
||||
if(replacer){
|
||||
console.log(replacer)
|
||||
return replacer
|
||||
}
|
||||
return form
|
||||
@@ -279,7 +278,6 @@ async function getDbBackups() {
|
||||
backups.push(parseInt(da))
|
||||
}
|
||||
}
|
||||
console.log(backups)
|
||||
while(backups.length > 20){
|
||||
const last = backups.pop()
|
||||
await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
|
||||
@@ -511,8 +509,6 @@ export async function globalFetch(url:string, arg:{
|
||||
|
||||
const urlHost = (new URL(url)).hostname
|
||||
let forcePlainFetch = (knownHostes.includes(urlHost) && (!isTauri)) || db.usePlainFetch || arg.plainFetchForce
|
||||
|
||||
console.log(urlHost)
|
||||
//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((!isTauri) && (!isNodeServer)){
|
||||
@@ -704,7 +700,6 @@ export async function globalFetch(url:string, arg:{
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
return {
|
||||
ok:false,
|
||||
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`
|
||||
+ `* 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
|
||||
}
|
||||
|
||||
|
||||
@@ -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(){
|
||||
SizeStore.set({
|
||||
@@ -21,5 +23,82 @@ export const ViewBoxsize = writable({ width: 12 * 16, height: 12 * 16 }); // Def
|
||||
export const settingsOpen = 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()
|
||||
window.addEventListener("resize", updateSize);
|
||||
Reference in New Issue
Block a user