[feat] trigger gui
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { get, writable, type Writable } from "svelte/store"
|
||||
import { alertConfirm, alertError, alertMd, alertNormal, alertSelect, alertStore, alertTOS } from "./alert"
|
||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook } from "./storage/database"
|
||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook, type triggerscript } from "./storage/database"
|
||||
import { checkNullish, selectMultipleFile, sleep } from "./util"
|
||||
import { language } from "src/lang"
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -183,7 +183,8 @@ function convertOldTavernAndJSON(charaData:OldTavernChar, imgp:string|undefined
|
||||
personality: charaData.personality ?? '',
|
||||
scenario:charaData.scenario ?? '',
|
||||
firstMsgIndex: -1,
|
||||
replaceGlobalNote: ""
|
||||
replaceGlobalNote: "",
|
||||
triggerscript: []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +344,8 @@ async function importSpecv2(card:CharacterCardV2, img?:Uint8Array, mode?:'hub'|'
|
||||
additionalAssets: extAssets,
|
||||
replaceGlobalNote: data.post_history_instructions ?? '',
|
||||
backgroundHTML: data?.extensions?.risuai?.backgroundHTML,
|
||||
license: data?.extensions?.risuai?.license
|
||||
license: data?.extensions?.risuai?.license,
|
||||
triggerscript: data?.extensions?.risuai?.triggerscript ?? []
|
||||
}
|
||||
|
||||
db.characters.push(char)
|
||||
@@ -685,7 +687,8 @@ type CharacterCardV2 = {
|
||||
sdData?:[string,string][],
|
||||
additionalAssets?:[string,string,string][],
|
||||
backgroundHTML?:string,
|
||||
license?:string
|
||||
license?:string,
|
||||
triggerscript?:triggerscript[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ export function characterFormatUpdate(index:number|character){
|
||||
if(checkNullish(cha.utilityBot)){
|
||||
cha.utilityBot = false
|
||||
}
|
||||
cha.triggerscript = cha.triggerscript ?? []
|
||||
cha.alternateGreetings = cha.alternateGreetings ?? []
|
||||
cha.exampleMessage = cha.exampleMessage ?? ''
|
||||
cha.creatorNotes = cha.creatorNotes ?? ''
|
||||
@@ -388,7 +389,8 @@ export function createBlankChar():character{
|
||||
personality:"",
|
||||
scenario:"",
|
||||
firstMsgIndex: -1,
|
||||
replaceGlobalNote: ""
|
||||
replaceGlobalNote: "",
|
||||
triggerscript: []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,11 @@ export async function importRegex(){
|
||||
export function processScriptFull(char:character|groupChat, data:string, mode:ScriptMode, chatID = -1){
|
||||
let db = get(DataBase)
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript)
|
||||
for (const script of scripts){
|
||||
const globalscripts = (db.globalscript ?? []).concat(char.customscript)
|
||||
if(db.officialplugins.automark && mode === 'editdisplay'){
|
||||
data = autoMarkPlugin(data)
|
||||
}
|
||||
for (const script of globalscripts){
|
||||
if(script.type === mode){
|
||||
const reg = new RegExp(script.in, script.ableFlag ? script.flag : 'g')
|
||||
let outScript2 = script.out.replaceAll("$n", "\n")
|
||||
@@ -141,9 +144,6 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
|
||||
}
|
||||
}
|
||||
}
|
||||
if(db.officialplugins.automark && mode === 'editdisplay'){
|
||||
data = autoMarkPlugin(data)
|
||||
}
|
||||
return {data, emoChanged}
|
||||
}
|
||||
|
||||
|
||||
42
src/ts/process/triggers.ts
Normal file
42
src/ts/process/triggers.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export interface triggerscript{
|
||||
comment: string;
|
||||
type: 'start'|'manual'|'output'
|
||||
conditions: triggerCondition[]
|
||||
effect:triggerEffect[]
|
||||
}
|
||||
|
||||
export type triggerCondition = triggerConditionsVar|triggerConditionsExists
|
||||
|
||||
export type triggerEffect = triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate
|
||||
|
||||
export type triggerConditionsVar = {
|
||||
type:'var'
|
||||
var:string
|
||||
value:string
|
||||
operator:'='|'!='|'>'|'<'|'>='|'<='
|
||||
}
|
||||
|
||||
export type triggerConditionsExists ={
|
||||
type: 'exists'
|
||||
value:string
|
||||
type2: 'strict'|'loose'|'regex',
|
||||
depth: number
|
||||
}
|
||||
|
||||
export interface triggerEffectSetvar{
|
||||
type: 'setvar'
|
||||
var:string
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface triggerEffectSystemPrompt{
|
||||
type: 'systemprompt',
|
||||
location: 'start'|'historyend'|'promptend',
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface triggerEffectImpersonate{
|
||||
type: 'impersonate'
|
||||
role: 'user'|'char',
|
||||
value:string
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { get, writable } from 'svelte/store';
|
||||
import { checkNullish, selectSingleFile } from '../util';
|
||||
import { changeLanguage, language } from '../../lang';
|
||||
import type { RisuPlugin } from '../plugins/plugins';
|
||||
import type {triggerscript as triggerscriptMain} from '../process/triggers';
|
||||
import { downloadFile, saveAsset as saveImageGlobal } from './globalApi';
|
||||
import { clone, cloneDeep } from 'lodash';
|
||||
import { defaultAutoSuggestPrompt, defaultJailbreak, defaultMainPrompt } from './defaultPrompts';
|
||||
@@ -300,6 +301,8 @@ export interface customscript{
|
||||
|
||||
}
|
||||
|
||||
export type triggerscript = triggerscriptMain
|
||||
|
||||
export interface loreBook{
|
||||
key:string
|
||||
secondkey:string
|
||||
@@ -331,6 +334,7 @@ export interface character{
|
||||
chaId: string
|
||||
sdData: [string, string][]
|
||||
customscript: customscript[]
|
||||
triggerscript: triggerscript[]
|
||||
utilityBot: boolean
|
||||
exampleMessage:string
|
||||
removedQuotes?:boolean
|
||||
@@ -540,7 +544,7 @@ export interface Database{
|
||||
token:string,
|
||||
model:string
|
||||
}
|
||||
globalscript: customscript[]
|
||||
globalscript: customscript[],
|
||||
sendWithEnter:boolean
|
||||
clickToEdit: boolean
|
||||
koboldURL:string
|
||||
|
||||
Reference in New Issue
Block a user