Change first message to chat dependent

This commit is contained in:
kwaroran
2024-09-18 23:25:02 +09:00
parent 6ad841e931
commit 85609e890e
15 changed files with 50 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { ParseMarkdown, risuChatParser } from "src/ts/parser";
import { DataBase, type Database, type character, type groupChat } from "src/ts/storage/database";
import { CurrentVariablePointer, moduleBackgroundEmbedding, ReloadGUIPointer, selectedCharID } from "src/ts/stores";
import { moduleBackgroundEmbedding, ReloadGUIPointer, selectedCharID } from "src/ts/stores";
import { onDestroy } from "svelte";
let backgroundHTML = ''
@@ -43,14 +43,12 @@
{#if backgroundHTML || $moduleBackgroundEmbedding}
{#if $selectedCharID > -1}
{#key $CurrentVariablePointer}
{#key $ReloadGUIPointer}
<div class="absolute top-0 left-0 w-full h-full">
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
{@html md}
{/await}
</div>
{/key}
{#key $ReloadGUIPointer}
<div class="absolute top-0 left-0 w-full h-full">
{#await ParseMarkdown(risuChatParser((backgroundHTML || '') + ($moduleBackgroundEmbedding || ''), {chara:currentChar}), currentChar, 'back') then md}
{@html md}
{/await}
</div>
{/key}
{/if}
{/if}

View File

@@ -5,7 +5,7 @@
import { alertConfirm, alertError, alertRequestData } from "../../ts/alert";
import { language } from "../../lang";
import { DataBase, type MessageGenerationInfo } from "../../ts/storage/database";
import { CurrentCharacter, CurrentChat, CurrentVariablePointer, HideIconStore, ReloadGUIPointer } from "../../ts/stores";
import { CurrentCharacter, CurrentChat, HideIconStore, ReloadGUIPointer } from "../../ts/stores";
import { translateHTML } from "../../ts/translator/translator";
import { risuChatParser } from "src/ts/process/scripts";
import { get, type Unsubscriber } from "svelte/store";
@@ -146,9 +146,6 @@
const unsubscribers:Unsubscriber[] = []
onMount(()=>{
unsubscribers.push(CurrentVariablePointer.subscribe((v) => {
displaya(message)
}))
unsubscribers.push(ReloadGUIPointer.subscribe((v) => {
displaya(message)
}))
@@ -295,13 +292,11 @@
style:line-height="{($DataBase.lineHeight ?? 1.25) * ($DataBase.zoomsize / 100)}rem"
>
{#key $ReloadGUIPointer}
{#key $CurrentVariablePointer}
{#await markParsing(msgDisplay, character, 'normal', idx, translated)}
{@html lastParsed}
{:then md}
{@html md}
{/await}
{/key}
{#await markParsing(msgDisplay, character, 'normal', idx, translated)}
{@html lastParsed}
{:then md}
{@html md}
{/await}
{/key}
</span>
{/if}

View File

@@ -601,32 +601,34 @@
<Chat
character={$CurrentSimpleCharacter}
name={$CurrentCharacter.name}
message={$CurrentCharacter.firstMsgIndex === -1 ? $CurrentCharacter.firstMessage :
$CurrentCharacter.alternateGreetings[$CurrentCharacter.firstMsgIndex]}
message={$CurrentChat.fmIndex === -1 ? $CurrentCharacter.firstMessage :
$CurrentCharacter.alternateGreetings[$CurrentChat.fmIndex]}
img={getCharImage($CurrentCharacter.image, 'css')}
idx={-1}
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
largePortrait={$CurrentCharacter.largePortrait}
onReroll={() => {
const cha = $CurrentCharacter
const chat = $CurrentChat
if(cha.type !== 'group'){
if (cha.firstMsgIndex >= (cha.alternateGreetings.length - 1)){
cha.firstMsgIndex = -1
if (chat.fmIndex >= (cha.alternateGreetings.length - 1)){
chat.fmIndex = -1
}
else{
cha.firstMsgIndex += 1
chat.fmIndex += 1
}
}
$CurrentCharacter = cha
$CurrentChat = chat
}}
unReroll={() => {
const cha = $CurrentCharacter
const chat = $CurrentChat
if(cha.type !== 'group'){
if (cha.firstMsgIndex === -1){
cha.firstMsgIndex = (cha.alternateGreetings.length - 1)
if (chat.fmIndex === -1){
chat.fmIndex = (cha.alternateGreetings.length - 1)
}
else{
cha.firstMsgIndex -= 1
chat.fmIndex -= 1
}
}
$CurrentCharacter = cha

View File

@@ -51,15 +51,6 @@
let currentChar:character|groupChat = $CurrentCharacter;
let messages:Message[] = []
if(currentChar.type !== 'group'){
const firstMsg:string = currentChar.firstMsgIndex === -1 ? currentChar.firstMessage : currentChar.alternateGreetings[currentChar.firstMsgIndex]
messages.push({
role: 'char',
data: await processScript(currentChar,
replacePlaceholders(firstMsg, currentChar.name),
'editprocess')
})
}
messages = [...messages, ...currentChar.chats[currentChar.chatPage].message];
let lastMessages:Message[] = messages.slice(Math.max(messages.length - 10, 0));
if(lastMessages.length === 0)

View File

@@ -2,7 +2,7 @@
import { alertConfirm, alertError } from "../../ts/alert";
import { language } from "../../lang";
import { DataBase } from "../../ts/storage/database";
import { CurrentCharacter, selectedCharID } from "../../ts/stores";
import { CurrentCharacter, ReloadGUIPointer, 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";
@@ -66,7 +66,7 @@
const len = $CurrentCharacter.chats.length
let chats = $CurrentCharacter.chats
chats.unshift({
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[], fmIndex: -1
})
if(cha.type === 'group'){
cha.characters.map((c) => {
@@ -78,6 +78,7 @@
})
}
$CurrentCharacter.chats = chats
$ReloadGUIPointer += 1
$CurrentCharacter.chatPage = len
close()
}}>

View File

@@ -2,7 +2,7 @@
import { language } from "../../lang";
import { tokenizeAccurate } from "../../ts/tokenizer";
import { DataBase, saveImage as saveAsset, type Database, type character, type groupChat } from "../../ts/storage/database";
import { CharConfigSubMenu, MobileGUI, ShowRealmFrameStore, selectedCharID } from "../../ts/stores";
import { CharConfigSubMenu, CurrentChat, MobileGUI, ShowRealmFrameStore, selectedCharID } from "../../ts/stores";
import { PlusIcon, SmileIcon, TrashIcon, UserIcon, ActivityIcon, BookIcon, User, CurlyBraces, Volume2Icon, DownloadIcon, FolderUpIcon } from 'lucide-svelte'
import Check from "../UI/GUI/CheckInput.svelte";
import { addCharEmotion, addingEmotion, getCharImage, rmCharEmotion, selectCharImg, makeGroupImage, removeChar, changeCharImage } from "../../ts/characters";
@@ -966,7 +966,7 @@
<th class="font-medium cursor-pointer w-10">
<button class="hover:text-green-500" on:click={() => {
if(currentChar.type === 'character'){
currentChar.data.firstMsgIndex = -1
$CurrentChat.fmIndex = -1
let alternateGreetings = currentChar.data.alternateGreetings
alternateGreetings.splice(i, 1)
currentChar.data.alternateGreetings = alternateGreetings
@@ -1031,7 +1031,7 @@
<th class="font-medium cursor-pointer w-10">
<button class="hover:text-green-500" on:click={() => {
if(currentChar.type === 'character'){
currentChar.data.firstMsgIndex = -1
$CurrentChat.fmIndex = -1
let additionalAssets = currentChar.data.additionalAssets
additionalAssets.splice(i, 1)
currentChar.data.additionalAssets = additionalAssets

View File

@@ -10,7 +10,7 @@
import { findCharacterbyId, parseKeyValue, sleep, sortableOptions } from "src/ts/util";
import CheckInput from "../UI/GUI/CheckInput.svelte";
import { createMultiuserRoom } from "src/ts/sync/multiuser";
import { CurrentCharacter, MobileGUI } from "src/ts/stores";
import { CurrentCharacter, MobileGUI, ReloadGUIPointer } from "src/ts/stores";
import Sortable from 'sortablejs/modular/sortable.core.esm.js';
import { onDestroy, onMount } from "svelte";
import { v4 } from "uuid";
@@ -69,7 +69,7 @@
const len = chara.chats.length
let chats = chara.chats
chats.unshift({
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[]
message:[], note:'', name:`New Chat ${len + 1}`, localLore:[], fmIndex: -1
})
if(cha.type === 'group'){
cha.characters.map((c) => {
@@ -82,6 +82,7 @@
}
chara.chats = chats
chara.chatPage = 0
$ReloadGUIPointer += 1
}}>New Chat</Button>
<div class="flex flex-col w-full mt-2 overflow-y-auto flex-grow" bind:this={ele}>
{#key sorted}
@@ -89,6 +90,8 @@
<button data-risu-idx={i} on:click={() => {
if(!editMode){
chara.chatPage = i
$ReloadGUIPointer += 1
}
}} class="flex items-center text-textcolor border-solid border-0 border-darkborderc p-2 cursor-pointer rounded-md"class:bg-selected={i === chara.chatPage}>
{#if editMode}
@@ -158,6 +161,7 @@
const d = await alertConfirm(`${language.removeConfirm}${chat.name}`)
if(d){
chara.chatPage = 0
$ReloadGUIPointer += 1
let chats = chara.chats
chats.splice(i, 1)
chara.chats = chats

View File

@@ -249,7 +249,7 @@ export async function exportChat(page:number){
<div class="chat">
<h2>${char.name}</h2>
<div>${await htmlChatParse(
char.firstMsgIndex === -1 ? char.firstMessage : char.alternateGreetings?.[char.firstMsgIndex ?? 0]
chat.fmIndex === -1 ? char.firstMessage : char.alternateGreetings?.[chat.fmIndex ?? 0]
)}</div>
</div>
${chatContentHTML}
@@ -513,6 +513,10 @@ export function characterFormatUpdate(index:number|character, arg:{
db.characters[index] = cha
setDatabase(db)
}
cha.chats = cha.chats.map((v) => {
v.fmIndex ??= cha.firstMsgIndex ?? -1
return v
})
return cha
}

View File

@@ -650,7 +650,7 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
}
pointer--
}
return selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
return chat.fmIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[chat.fmIndex]
}
case 'previous_user_chat':
case 'lastusermessage':{
@@ -664,7 +664,7 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
}
pointer--
}
return selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
return chat.fmIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[chat.fmIndex]
}
return ''
}
@@ -795,7 +795,8 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
}
case 'first_msg_index':{
const selchar = db.characters[get(selectedCharID)]
return selchar.firstMsgIndex.toString()
const chat = selchar.chats[selchar.chatPage]
return chat.fmIndex.toString()
}
case 'blank':
case 'none':{

View File

@@ -612,7 +612,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
}
if(nowChatroom.type !== 'group'){
const firstMsg = nowChatroom.firstMsgIndex === -1 ? nowChatroom.firstMessage : nowChatroom.alternateGreetings[nowChatroom.firstMsgIndex]
const firstMsg = currentChat.fmIndex === -1 ? nowChatroom.firstMessage : nowChatroom.alternateGreetings[currentChat.fmIndex]
const chat:OpenAIChat = {
role: 'assistant',

View File

@@ -383,7 +383,7 @@ export async function loadLoreBookV3Prompt(){
if(Number.isNaN(int)){
return false
}
if(((char.firstMsgIndex ?? -1) + 1) !== int){
if(((char.chats[page].fmIndex ?? -1) + 1) !== int){
activated = false
}
}

View File

@@ -2,7 +2,7 @@ import { getChatVar, hasher, risuChatParser, setChatVar, type simpleCharacterArg
import { LuaEngine, LuaFactory } from "wasmoon";
import { DataBase, setDatabase, type Chat, type character, type groupChat } from "../storage/database";
import { get } from "svelte/store";
import { CurrentCharacter, CurrentChat, CurrentVariablePointer, ReloadGUIPointer, selectedCharID } from "../stores";
import { CurrentCharacter, CurrentChat, ReloadGUIPointer, selectedCharID } from "../stores";
import { alertError, alertInput, alertNormal } from "../alert";
import { HypaProcesser } from "./memory/hypamemory";
import { generateAIImage } from "./stableDiff";

View File

@@ -180,7 +180,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
const v = outScript.split(' ', 2)[1]
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
let lastChat = selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
let lastChat = chat.fmIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[chat.fmIndex]
let pointer = chatID - 1
while(pointer >= 0){
if(chat.message[pointer].role === chat.message[chatID].role){

View File

@@ -1073,6 +1073,7 @@ export interface Chat{
modules?:string[]
id?:string
bindedPersona?:string
fmIndex?:number
}
export interface Message{

View File

@@ -40,7 +40,6 @@ export const CurrentUserIcon = writable('') as Writable<string>
export const CurrentShowMemoryLimit = writable(false) as Writable<boolean>
export const ShowVN = writable(false)
export const SettingsMenuIndex = writable(-1)
export const CurrentVariablePointer = writable({} as {[key:string]: string|number|boolean})
export const ReloadGUIPointer = writable(0)
export const OpenRealmStore = writable(false)
export const ShowRealmFrameStore = writable('')
@@ -231,13 +230,6 @@ async function preInit(){
if(getUserIcon() !== get(CurrentUserIcon)){
CurrentUserIcon.set(getUserIcon())
}
const variablePointer = get(CurrentVariablePointer)
const currentState = structuredClone(chat?.scriptstate)
if(!isEqual(variablePointer, currentState)){
CurrentVariablePointer.set(currentState)
}
})
}