fix: Chat trigger on start
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { get, writable } from "svelte/store";
|
import { get, writable } from "svelte/store";
|
||||||
import { type character, type MessageGenerationInfo, type Chat, changeToPreset } from "../storage/database.svelte";
|
import { type character, type MessageGenerationInfo, type Chat, changeToPreset, setCurrentChat } from "../storage/database.svelte";
|
||||||
import { DBState } from '../stores.svelte';
|
import { DBState } from '../stores.svelte';
|
||||||
import { CharEmotion, selectedCharID } from "../stores.svelte";
|
import { CharEmotion, selectedCharID } from "../stores.svelte";
|
||||||
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
||||||
@@ -694,6 +694,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
|||||||
const triggerResult = await runTrigger(currentChar, 'start', {chat: currentChat})
|
const triggerResult = await runTrigger(currentChar, 'start', {chat: currentChat})
|
||||||
if(triggerResult){
|
if(triggerResult){
|
||||||
currentChat = triggerResult.chat
|
currentChat = triggerResult.chat
|
||||||
|
setCurrentChat(currentChat)
|
||||||
ms = currentChat.message
|
ms = currentChat.message
|
||||||
currentTokens += triggerResult.tokens
|
currentTokens += triggerResult.tokens
|
||||||
if(triggerResult.stopSending){
|
if(triggerResult.stopSending){
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ interface LuaEngineState {
|
|||||||
engine: LuaEngine;
|
engine: LuaEngine;
|
||||||
mutex: Mutex;
|
mutex: Mutex;
|
||||||
chat: Chat;
|
chat: Chat;
|
||||||
|
setVar: (key:string, value:string) => void,
|
||||||
|
getVar: (key:string) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
let LuaEngines = new Map<string, LuaEngineState>()
|
let LuaEngines = new Map<string, LuaEngineState>()
|
||||||
@@ -55,12 +57,16 @@ export async function runLua(code:string, arg:{
|
|||||||
code,
|
code,
|
||||||
engine: await luaFactory.createEngine({injectObjects: true}),
|
engine: await luaFactory.createEngine({injectObjects: true}),
|
||||||
mutex: new Mutex(),
|
mutex: new Mutex(),
|
||||||
chat
|
chat,
|
||||||
|
setVar,
|
||||||
|
getVar
|
||||||
}
|
}
|
||||||
LuaEngines.set(mode, luaEngineState)
|
LuaEngines.set(mode, luaEngineState)
|
||||||
wasEmpty = true
|
wasEmpty = true
|
||||||
} else {
|
} else {
|
||||||
luaEngineState.chat = chat
|
luaEngineState.chat = chat
|
||||||
|
luaEngineState.setVar = setVar
|
||||||
|
luaEngineState.getVar = getVar
|
||||||
}
|
}
|
||||||
return await luaEngineState.mutex.runExclusive(async () => {
|
return await luaEngineState.mutex.runExclusive(async () => {
|
||||||
if (wasEmpty || code !== luaEngineState.code) {
|
if (wasEmpty || code !== luaEngineState.code) {
|
||||||
@@ -72,13 +78,13 @@ export async function runLua(code:string, arg:{
|
|||||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setVar(key, value)
|
luaEngineState.setVar(key, value)
|
||||||
})
|
})
|
||||||
luaEngine.global.set('getChatVar', (id:string,key:string) => {
|
luaEngine.global.set('getChatVar', (id:string,key:string) => {
|
||||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return getVar(key)
|
return luaEngineState.getVar(key)
|
||||||
})
|
})
|
||||||
luaEngine.global.set('stopChat', (id:string) => {
|
luaEngine.global.set('stopChat', (id:string) => {
|
||||||
if(!LuaSafeIds.has(id)){
|
if(!LuaSafeIds.has(id)){
|
||||||
|
|||||||
Reference in New Issue
Block a user