Add trigger effects and conditions
This commit is contained in:
@@ -417,6 +417,9 @@ export const languageEnglish = {
|
|||||||
triggerEffSetVar: 'Modify Variable',
|
triggerEffSetVar: 'Modify Variable',
|
||||||
triggerEffImperson: 'Send Chat',
|
triggerEffImperson: 'Send Chat',
|
||||||
triggerEffCommand: 'Run Command',
|
triggerEffCommand: 'Run Command',
|
||||||
|
triggerEffRunTrigger: 'Run Trigger',
|
||||||
|
triggerEffStop: 'Stop Sending Prompt',
|
||||||
|
triggerEffCall: 'Call Trigger',
|
||||||
varableName: "Variable Name",
|
varableName: "Variable Name",
|
||||||
role: "Role",
|
role: "Role",
|
||||||
location: 'Location',
|
location: 'Location',
|
||||||
@@ -435,6 +438,7 @@ export const languageEnglish = {
|
|||||||
isNull: "is not set",
|
isNull: "is not set",
|
||||||
ifChatIndex: "If chat index",
|
ifChatIndex: "If chat index",
|
||||||
ifRandom: "If random",
|
ifRandom: "If random",
|
||||||
|
ifValue: "If Value",
|
||||||
hideRealm: "Hide RisuRealm",
|
hideRealm: "Hide RisuRealm",
|
||||||
popularityLevel: "{} Popularity",
|
popularityLevel: "{} Popularity",
|
||||||
colorScheme: "Color Scheme",
|
colorScheme: "Color Scheme",
|
||||||
|
|||||||
@@ -59,10 +59,10 @@
|
|||||||
<span class="text-textcolor mt-4">Conditions
|
<span class="text-textcolor mt-4">Conditions
|
||||||
<button aria-labelledby="Add Conditions" class="float-right text-textcolor2 hover:text-green-500" on:click={() => {
|
<button aria-labelledby="Add Conditions" class="float-right text-textcolor2 hover:text-green-500" on:click={() => {
|
||||||
value.conditions.push({
|
value.conditions.push({
|
||||||
type: 'exists',
|
type: 'value',
|
||||||
value: '',
|
value: '',
|
||||||
type2: 'loose',
|
operator: '=',
|
||||||
depth: 3
|
var: ''
|
||||||
})
|
})
|
||||||
value.conditions = value.conditions
|
value.conditions = value.conditions
|
||||||
|
|
||||||
@@ -93,9 +93,9 @@
|
|||||||
depth: 3
|
depth: 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(cond.type === 'var'){
|
if(cond.type === 'var' || cond.type === 'value'){
|
||||||
cond = {
|
cond = {
|
||||||
type: 'var',
|
type: cond.type,
|
||||||
var: '',
|
var: '',
|
||||||
value: '',
|
value: '',
|
||||||
operator: '='
|
operator: '='
|
||||||
@@ -108,8 +108,8 @@
|
|||||||
operator: '='
|
operator: '='
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}}>
|
}}>
|
||||||
|
<OptionInput value="value">{language.ifValue}</OptionInput>
|
||||||
<OptionInput value="exists">{language.triggerCondExists}</OptionInput>
|
<OptionInput value="exists">{language.triggerCondExists}</OptionInput>
|
||||||
<OptionInput value="var">{language.triggerCondVar}</OptionInput>
|
<OptionInput value="var">{language.triggerCondVar}</OptionInput>
|
||||||
<OptionInput value="chatindex">{language.ifChatIndex}</OptionInput>
|
<OptionInput value="chatindex">{language.ifChatIndex}</OptionInput>
|
||||||
@@ -127,11 +127,14 @@
|
|||||||
<span class="text-textcolor2 text-sm">{language.searchDepth}</span>
|
<span class="text-textcolor2 text-sm">{language.searchDepth}</span>
|
||||||
<NumberInput size="sm" bind:value={cond.depth} />
|
<NumberInput size="sm" bind:value={cond.depth} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if cond.type === 'var' || cond.type === 'chatindex'}
|
{#if cond.type === 'var' || cond.type === 'chatindex' || cond.type === 'value'}
|
||||||
{#if cond.type === 'var'}
|
{#if cond.type === 'var'}
|
||||||
<span class="text-textcolor2 text-sm">{language.varableName}</span>
|
<span class="text-textcolor2 text-sm">{language.varableName}</span>
|
||||||
<TextInput size="sm" bind:value={cond.var} />
|
<TextInput size="sm" bind:value={cond.var} />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if cond.type === 'value'}
|
||||||
|
<TextInput size="sm" bind:value={cond.var} />
|
||||||
|
{/if}
|
||||||
<span class="text-textcolor2 text-sm">{language.value}</span>
|
<span class="text-textcolor2 text-sm">{language.value}</span>
|
||||||
<SelectInput bind:value={cond.operator} size="sm">
|
<SelectInput bind:value={cond.operator} size="sm">
|
||||||
<OptionInput value="=">{language.equal}</OptionInput>
|
<OptionInput value="=">{language.equal}</OptionInput>
|
||||||
@@ -217,19 +220,34 @@
|
|||||||
value: ''
|
value: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(effect.type === 'stop'){
|
||||||
|
effect = {
|
||||||
|
type: 'stop',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(effect.type === 'runtrigger'){
|
||||||
|
effect = {
|
||||||
|
type: 'runtrigger',
|
||||||
|
value: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
{#if effect.type === 'systemprompt' || value.type === 'start'}
|
|
||||||
<OptionInput value="systemprompt">{language.triggerEffSysPrompt}</OptionInput>
|
|
||||||
{/if}
|
|
||||||
<OptionInput value="setvar">{language.triggerEffSetVar}</OptionInput>
|
<OptionInput value="setvar">{language.triggerEffSetVar}</OptionInput>
|
||||||
<OptionInput value="impersonate">{language.triggerEffImperson}</OptionInput>
|
<OptionInput value="impersonate">{language.triggerEffImperson}</OptionInput>
|
||||||
<OptionInput value="command">{language.triggerEffCommand}</OptionInput>
|
<OptionInput value="command">{language.triggerEffCommand}</OptionInput>
|
||||||
|
{#if effect.type === 'systemprompt' || value.type === 'start'}
|
||||||
|
<OptionInput value="systemprompt">{language.triggerEffSysPrompt}</OptionInput>
|
||||||
|
{/if}
|
||||||
|
{#if effect.type === 'stop' || value.type === 'start'}
|
||||||
|
<OptionInput value="stop">{language.triggerEffStop}</OptionInput>
|
||||||
|
{/if}
|
||||||
|
<OptionInput value="runtrigger">{language.triggerEffRunTrigger}</OptionInput>
|
||||||
|
|
||||||
</SelectInput>
|
</SelectInput>
|
||||||
|
{#if value.type !== 'start' && (effect.type === 'systemprompt' || effect.type === 'stop')}
|
||||||
|
<span class="text-red-400 text-sm">{language.invaildTriggerEffect}</span>
|
||||||
|
{/if}
|
||||||
{#if effect.type === 'systemprompt'}
|
{#if effect.type === 'systemprompt'}
|
||||||
{#if value.type !== 'start'}
|
|
||||||
<span class="text-red-400 text-sm">{language.invaildTriggerEffect}</span>
|
|
||||||
{/if}
|
|
||||||
<span class="text-textcolor2 text-sm">{language.location}</span>
|
<span class="text-textcolor2 text-sm">{language.location}</span>
|
||||||
<SelectInput bind:value={effect.location} size="sm">
|
<SelectInput bind:value={effect.location} size="sm">
|
||||||
<OptionInput value="start">{language.promptstart}</OptionInput>
|
<OptionInput value="start">{language.promptstart}</OptionInput>
|
||||||
@@ -254,6 +272,10 @@
|
|||||||
<TextInput size="sm" bind:value={effect.value} />
|
<TextInput size="sm" bind:value={effect.value} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if effect.type === 'runtrigger'}
|
||||||
|
<span class="text-textcolor2 text-sm">{language.name}</span>
|
||||||
|
<TextInput size="sm" bind:value={effect.value} />
|
||||||
|
{/if}
|
||||||
{#if effect.type === 'command'}
|
{#if effect.type === 'command'}
|
||||||
<span class="text-textcolor2 text-sm">{language.value}</span>
|
<span class="text-textcolor2 text-sm">{language.value}</span>
|
||||||
<TextAreaInput size="sm" bind:value={effect.value} />
|
<TextAreaInput size="sm" bind:value={effect.value} />
|
||||||
|
|||||||
@@ -552,6 +552,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
currentChat = triggerResult.chat
|
currentChat = triggerResult.chat
|
||||||
ms = currentChat.message
|
ms = currentChat.message
|
||||||
currentTokens += triggerResult.tokens
|
currentTokens += triggerResult.tokens
|
||||||
|
if(triggerResult.stopSending){
|
||||||
|
doingChat.set(false)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = 0
|
let index = 0
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ export interface triggerscript{
|
|||||||
|
|
||||||
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
|
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
|
||||||
|
|
||||||
export type triggerEffect = triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand
|
export type triggerEffect = triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
|
||||||
|
|
||||||
export type triggerConditionsVar = {
|
export type triggerConditionsVar = {
|
||||||
type:'var'
|
type:'var'|'value'
|
||||||
var:string
|
var:string
|
||||||
value:string
|
value:string
|
||||||
operator:'='|'!='|'>'|'<'|'>='|'<='|'null'
|
operator:'='|'!='|'>'|'<'|'>='|'<='|'null'
|
||||||
@@ -62,6 +62,15 @@ export interface triggerEffectCommand{
|
|||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface triggerEffectRunTrigger{
|
||||||
|
type: 'runtrigger',
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface triggerEffectStop{
|
||||||
|
type: 'stop'
|
||||||
|
}
|
||||||
|
|
||||||
export type additonalSysPrompt = {
|
export type additonalSysPrompt = {
|
||||||
start:string,
|
start:string,
|
||||||
historyend: string,
|
historyend: string,
|
||||||
@@ -69,17 +78,23 @@ export type additonalSysPrompt = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runTrigger(char:character,mode:triggerMode, arg:{
|
export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||||
chat: Chat
|
chat: Chat,
|
||||||
|
recursiveCount?: number
|
||||||
|
additonalSysPrompt?: additonalSysPrompt
|
||||||
|
stopSending?: boolean
|
||||||
|
manualName?: string
|
||||||
}){
|
}){
|
||||||
|
arg.recursiveCount ??= 0
|
||||||
char = cloneDeep(char)
|
char = cloneDeep(char)
|
||||||
let varChanged = false
|
let varChanged = false
|
||||||
let additonalSysPrompt:additonalSysPrompt = {
|
let stopSending = arg.stopSending ?? false
|
||||||
|
let additonalSysPrompt:additonalSysPrompt = arg.additonalSysPrompt ?? {
|
||||||
start:'',
|
start:'',
|
||||||
historyend: '',
|
historyend: '',
|
||||||
promptend: ''
|
promptend: ''
|
||||||
}
|
}
|
||||||
const triggers = char.triggerscript.concat(getModuleTriggers())
|
const triggers = char.triggerscript.concat(getModuleTriggers())
|
||||||
const chat = cloneDeep(arg.chat ?? char.chats[char.chatPage])
|
let chat = cloneDeep(arg.chat ?? char.chats[char.chatPage])
|
||||||
if((!triggers) || (triggers.length === 0)){
|
if((!triggers) || (triggers.length === 0)){
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -96,14 +111,22 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
|||||||
|
|
||||||
|
|
||||||
for(const trigger of triggers){
|
for(const trigger of triggers){
|
||||||
if(mode !== trigger.type){
|
if(arg.manualName){
|
||||||
|
if(trigger.comment !== arg.manualName){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(mode !== trigger.type){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let pass = true
|
let pass = true
|
||||||
for(const condition of trigger.conditions){
|
for(const condition of trigger.conditions){
|
||||||
if(condition.type === 'var' || condition.type === 'chatindex'){
|
if(condition.type === 'var' || condition.type === 'chatindex' || condition.type === 'value'){
|
||||||
let varValue = (condition.type === 'var') ? (getVar(condition.var) ?? 'null') : (chat.message.length.toString())
|
let varValue = (condition.type === 'var') ? (getVar(condition.var) ?? 'null') :
|
||||||
|
(condition.type === 'chatindex') ? (chat.message.length.toString()) :
|
||||||
|
(condition.type === 'value') ? condition.var : null
|
||||||
|
|
||||||
if(varValue === undefined || varValue === null){
|
if(varValue === undefined || varValue === null){
|
||||||
pass = false
|
pass = false
|
||||||
break
|
break
|
||||||
@@ -172,48 +195,76 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for(const effect of trigger.effect){
|
for(const effect of trigger.effect){
|
||||||
if(effect.type === 'setvar'){
|
switch(effect.type){
|
||||||
const effectValue = risuChatParser(effect.value,{chara:char})
|
case'setvar': {
|
||||||
const varKey = risuChatParser(effect.var,{chara:char})
|
const effectValue = risuChatParser(effect.value,{chara:char})
|
||||||
switch(effect.operator){
|
const varKey = risuChatParser(effect.var,{chara:char})
|
||||||
case '=':{
|
switch(effect.operator){
|
||||||
setVar(varKey, effectValue)
|
case '=':{
|
||||||
break
|
setVar(varKey, effectValue)
|
||||||
}
|
break
|
||||||
case '+=':{
|
}
|
||||||
setVar(varKey, (Number(getVar(varKey)) + Number(effectValue)).toString())
|
case '+=':{
|
||||||
break
|
setVar(varKey, (Number(getVar(varKey)) + Number(effectValue)).toString())
|
||||||
}
|
break
|
||||||
case '-=':{
|
}
|
||||||
setVar(varKey, (Number(getVar(varKey)) - Number(effectValue)).toString())
|
case '-=':{
|
||||||
break
|
setVar(varKey, (Number(getVar(varKey)) - Number(effectValue)).toString())
|
||||||
}
|
break
|
||||||
case '*=':{
|
}
|
||||||
setVar(varKey, (Number(getVar(varKey)) * Number(effectValue)).toString())
|
case '*=':{
|
||||||
break
|
setVar(varKey, (Number(getVar(varKey)) * Number(effectValue)).toString())
|
||||||
}
|
break
|
||||||
case '/=':{
|
}
|
||||||
setVar(varKey, (Number(getVar(varKey)) / Number(effectValue)).toString())
|
case '/=':{
|
||||||
break
|
setVar(varKey, (Number(getVar(varKey)) / Number(effectValue)).toString())
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
case 'systemprompt':{
|
||||||
else if(effect.type === 'systemprompt'){
|
const effectValue = risuChatParser(effect.value,{chara:char})
|
||||||
const effectValue = risuChatParser(effect.value,{chara:char})
|
additonalSysPrompt[effect.location] += effectValue + "\n\n"
|
||||||
additonalSysPrompt[effect.location] += effectValue + "\n\n"
|
break
|
||||||
}
|
|
||||||
else if(effect.type === 'impersonate'){
|
|
||||||
const effectValue = risuChatParser(effect.value,{chara:char})
|
|
||||||
if(effect.role === 'user'){
|
|
||||||
chat.message.push({role: 'user', data: effectValue})
|
|
||||||
}
|
}
|
||||||
else if(effect.role === 'char'){
|
case 'impersonate':{
|
||||||
chat.message.push({role: 'char', data: effectValue})
|
const effectValue = risuChatParser(effect.value,{chara:char})
|
||||||
|
if(effect.role === 'user'){
|
||||||
|
chat.message.push({role: 'user', data: effectValue})
|
||||||
|
}
|
||||||
|
else if(effect.role === 'char'){
|
||||||
|
chat.message.push({role: 'char', data: effectValue})
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'command':{
|
||||||
|
const effectValue = risuChatParser(effect.value,{chara:char})
|
||||||
|
await processMultiCommand(effectValue)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'stop':{
|
||||||
|
stopSending = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'runtrigger':{
|
||||||
|
if(arg.recursiveCount < 10){
|
||||||
|
arg.recursiveCount++
|
||||||
|
const r = await runTrigger(char,'manual',{
|
||||||
|
chat,
|
||||||
|
recursiveCount: arg.recursiveCount,
|
||||||
|
additonalSysPrompt,
|
||||||
|
stopSending,
|
||||||
|
manualName: effect.value
|
||||||
|
})
|
||||||
|
if(r){
|
||||||
|
additonalSysPrompt = r.additonalSysPrompt
|
||||||
|
chat = r.chat
|
||||||
|
stopSending = r.stopSending
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(effect.type === 'command'){
|
|
||||||
const effectValue = risuChatParser(effect.value,{chara:char})
|
|
||||||
await processMultiCommand(effectValue)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,6 +286,6 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
|||||||
|
|
||||||
console.log(chat)
|
console.log(chat)
|
||||||
|
|
||||||
return {additonalSysPrompt, chat, tokens:caculatedTokens}
|
return {additonalSysPrompt, chat, tokens:caculatedTokens, stopSending}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user