Fix role cbs and add isfirstmsg cbs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ArrowLeft, ArrowRight, PencilIcon, LanguagesIcon, RefreshCcwIcon, TrashIcon, CopyIcon, Volume2Icon, BotIcon, ArrowLeftRightIcon, UserIcon } from "lucide-svelte";
|
import { ArrowLeft, ArrowRight, PencilIcon, LanguagesIcon, RefreshCcwIcon, TrashIcon, CopyIcon, Volume2Icon, BotIcon, ArrowLeftRightIcon, UserIcon } from "lucide-svelte";
|
||||||
import { ParseMarkdown, postTranslationParse, type simpleCharacterArgument } from "../../ts/parser";
|
import { type CbsConditions, ParseMarkdown, postTranslationParse, type simpleCharacterArgument } from "../../ts/parser";
|
||||||
import AutoresizeArea from "../UI/GUI/TextAreaResizable.svelte";
|
import AutoresizeArea from "../UI/GUI/TextAreaResizable.svelte";
|
||||||
import { alertConfirm, alertError, alertRequestData } from "../../ts/alert";
|
import { alertConfirm, alertError, alertRequestData } from "../../ts/alert";
|
||||||
import { language } from "../../lang";
|
import { language } from "../../lang";
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
export let onReroll = () => {}
|
export let onReroll = () => {}
|
||||||
export let unReroll = () => {}
|
export let unReroll = () => {}
|
||||||
export let character:simpleCharacterArgument|string|null = null
|
export let character:simpleCharacterArgument|string|null = null
|
||||||
|
export let firstMessage = false
|
||||||
let translating = false
|
let translating = false
|
||||||
try {
|
try {
|
||||||
translating = get(DataBase).autoTranslate
|
translating = get(DataBase).autoTranslate
|
||||||
@@ -73,8 +74,16 @@
|
|||||||
$CurrentChat.message = msg
|
$CurrentChat.message = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCbsCondition(){
|
||||||
|
const cbsConditions:CbsConditions = {
|
||||||
|
firstmsg: firstMessage ?? false,
|
||||||
|
chatRole: $CurrentChat?.message?.[idx]?.role ?? null,
|
||||||
|
}
|
||||||
|
return cbsConditions
|
||||||
|
}
|
||||||
|
|
||||||
function displaya(message:string){
|
function displaya(message:string){
|
||||||
msgDisplay = risuChatParser(message, {chara: name, chatID: idx, rmVar: true, visualize: true})
|
msgDisplay = risuChatParser(message, {chara: name, chatID: idx, rmVar: true, visualize: true, cbsConditions: getCbsCondition()})
|
||||||
}
|
}
|
||||||
|
|
||||||
const setStatusMessage = (message:string, timeout:number = 0)=>{
|
const setStatusMessage = (message:string, timeout:number = 0)=>{
|
||||||
@@ -106,7 +115,7 @@
|
|||||||
}
|
}
|
||||||
if(translateText){
|
if(translateText){
|
||||||
if(!$DataBase.legacyTranslation){
|
if(!$DataBase.legacyTranslation){
|
||||||
const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID)
|
const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID, getCbsCondition())
|
||||||
translating = true
|
translating = true
|
||||||
const translated = await postTranslationParse(await translateHTML(marked, false, charArg, chatID))
|
const translated = await postTranslationParse(await translateHTML(marked, false, charArg, chatID))
|
||||||
translating = false
|
translating = false
|
||||||
@@ -115,7 +124,7 @@
|
|||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
const marked = await ParseMarkdown(data, charArg, mode, chatID, getCbsCondition())
|
||||||
translating = true
|
translating = true
|
||||||
const translated = await translateHTML(marked, false, charArg, chatID)
|
const translated = await translateHTML(marked, false, charArg, chatID)
|
||||||
translating = false
|
translating = false
|
||||||
@@ -125,7 +134,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
const marked = await ParseMarkdown(data, charArg, mode, chatID, getCbsCondition())
|
||||||
lastParsed = marked
|
lastParsed = marked
|
||||||
lastCharArg = charArg
|
lastCharArg = charArg
|
||||||
return marked
|
return marked
|
||||||
|
|||||||
@@ -607,6 +607,7 @@
|
|||||||
idx={-1}
|
idx={-1}
|
||||||
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
|
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
|
||||||
largePortrait={$CurrentCharacter.largePortrait}
|
largePortrait={$CurrentCharacter.largePortrait}
|
||||||
|
firstMessage={true}
|
||||||
onReroll={() => {
|
onReroll={() => {
|
||||||
const cha = $CurrentCharacter
|
const cha = $CurrentCharacter
|
||||||
const chat = $CurrentChat
|
const chat = $CurrentChat
|
||||||
|
|||||||
@@ -5,16 +5,12 @@ import { getFileSrc } from './storage/globalApi';
|
|||||||
import { processScriptFull } from './process/scripts';
|
import { processScriptFull } from './process/scripts';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import css, { type CssAtRuleAST } from '@adobe/css-tools'
|
import css, { type CssAtRuleAST } from '@adobe/css-tools'
|
||||||
import { CurrentCharacter, CurrentChat, SizeStore, selectedCharID } from './stores';
|
import { CurrentCharacter, SizeStore, selectedCharID } from './stores';
|
||||||
import { calcString } from './process/infunctions';
|
import { calcString } from './process/infunctions';
|
||||||
import { findCharacterbyId, getPersonaPrompt, getUserIcon, getUserName, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
import { findCharacterbyId, getPersonaPrompt, getUserIcon, getUserName, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
||||||
import { getInlayImage, writeInlayImage } from './process/files/image';
|
import { getInlayImage } from './process/files/image';
|
||||||
import { getModuleAssets, getModuleLorebooks } from './process/modules';
|
import { getModuleAssets, getModuleLorebooks } from './process/modules';
|
||||||
import { HypaProcesser } from './process/memory/hypamemory';
|
|
||||||
import { generateAIImage } from './process/stableDiff';
|
|
||||||
import { requestChatData } from './process/request';
|
|
||||||
import type { OpenAIChat } from './process';
|
import type { OpenAIChat } from './process';
|
||||||
import { alertInput, alertNormal } from './alert';
|
|
||||||
import hljs from 'highlight.js/lib/core'
|
import hljs from 'highlight.js/lib/core'
|
||||||
import 'highlight.js/styles/atom-one-dark.min.css'
|
import 'highlight.js/styles/atom-one-dark.min.css'
|
||||||
|
|
||||||
@@ -386,7 +382,13 @@ export interface simpleCharacterArgument{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function ParseMarkdown(data:string, charArg:(character|simpleCharacterArgument | groupChat | string) = null, mode:'normal'|'back'|'pretranslate' = 'normal', chatID=-1) {
|
export async function ParseMarkdown(
|
||||||
|
data:string,
|
||||||
|
charArg:(character|simpleCharacterArgument | groupChat | string) = null,
|
||||||
|
mode:'normal'|'back'|'pretranslate' = 'normal',
|
||||||
|
chatID=-1,
|
||||||
|
cbsConditions:CbsConditions = {}
|
||||||
|
) {
|
||||||
let firstParsed = ''
|
let firstParsed = ''
|
||||||
const additionalAssetMode = (mode === 'back') ? 'back' : 'normal'
|
const additionalAssetMode = (mode === 'back') ? 'back' : 'normal'
|
||||||
let char = (typeof(charArg) === 'string') ? (findCharacterbyId(charArg)) : (charArg)
|
let char = (typeof(charArg) === 'string') ? (findCharacterbyId(charArg)) : (charArg)
|
||||||
@@ -395,7 +397,7 @@ export async function ParseMarkdown(data:string, charArg:(character|simpleCharac
|
|||||||
firstParsed = data
|
firstParsed = data
|
||||||
}
|
}
|
||||||
if(char){
|
if(char){
|
||||||
data = (await processScriptFull(char, data, 'editdisplay', chatID)).data
|
data = (await processScriptFull(char, data, 'editdisplay', chatID, cbsConditions)).data
|
||||||
}
|
}
|
||||||
if(firstParsed !== data && char && char.type !== 'group'){
|
if(firstParsed !== data && char && char.type !== 'group'){
|
||||||
data = await parseAdditionalAssets(data, char, additionalAssetMode, 'post')
|
data = await parseAdditionalAssets(data, char, additionalAssetMode, 'post')
|
||||||
@@ -625,6 +627,12 @@ type matcherArg = {
|
|||||||
text?:string,
|
text?:string,
|
||||||
recursiveCount?:number
|
recursiveCount?:number
|
||||||
lowLevelAccess?:boolean
|
lowLevelAccess?:boolean
|
||||||
|
cbsConditions:CbsConditions
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CbsConditions = {
|
||||||
|
firstmsg?:boolean
|
||||||
|
chatRole?:string
|
||||||
}
|
}
|
||||||
function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string}|null = null ):{
|
function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string}|null = null ):{
|
||||||
text:string,
|
text:string,
|
||||||
@@ -958,11 +966,26 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
|
|||||||
return db.subModel
|
return db.subModel
|
||||||
}
|
}
|
||||||
case 'role': {
|
case 'role': {
|
||||||
|
if(matcherArg.cbsConditions.chatRole){
|
||||||
|
return matcherArg.cbsConditions.chatRole
|
||||||
|
}
|
||||||
|
if(matcherArg.cbsConditions.firstmsg){
|
||||||
|
return 'char'
|
||||||
|
}
|
||||||
if (chatID !== -1) {
|
if (chatID !== -1) {
|
||||||
const selchar = db.characters[get(selectedCharID)]
|
const selchar = db.characters[get(selectedCharID)]
|
||||||
return selchar.chats[selchar.chatPage].message[chatID].role;
|
return selchar.chats[selchar.chatPage].message[chatID].role;
|
||||||
}
|
}
|
||||||
return matcherArg.role ?? 'role'
|
return matcherArg.role ?? 'null'
|
||||||
|
}
|
||||||
|
case 'isfirstmsg':
|
||||||
|
case 'is_first_msg':
|
||||||
|
case 'is_first_message':
|
||||||
|
case 'isfirstmessage':{
|
||||||
|
if(matcherArg.cbsConditions.firstmsg){
|
||||||
|
return '1'
|
||||||
|
}
|
||||||
|
return '0'
|
||||||
}
|
}
|
||||||
case 'jbtoggled':{
|
case 'jbtoggled':{
|
||||||
return db.jailbreakToggle ? '1' : '0'
|
return db.jailbreakToggle ? '1' : '0'
|
||||||
@@ -1740,6 +1763,7 @@ export function risuChatParser(da:string, arg:{
|
|||||||
runVar?:boolean
|
runVar?:boolean
|
||||||
functions?:Map<string,{data:string,arg:string[]}>
|
functions?:Map<string,{data:string,arg:string[]}>
|
||||||
callStack?:number
|
callStack?:number
|
||||||
|
cbsConditions?:CbsConditions
|
||||||
} = {}):string{
|
} = {}):string{
|
||||||
const chatID = arg.chatID ?? -1
|
const chatID = arg.chatID ?? -1
|
||||||
const db = arg.db ?? get(DataBase)
|
const db = arg.db ?? get(DataBase)
|
||||||
@@ -1798,6 +1822,7 @@ export function risuChatParser(da:string, arg:{
|
|||||||
role: arg.role,
|
role: arg.role,
|
||||||
runVar: arg.runVar ?? false,
|
runVar: arg.runVar ?? false,
|
||||||
consistantChar: arg.consistantChar ?? false,
|
consistantChar: arg.consistantChar ?? false,
|
||||||
|
cbsConditions: arg.cbsConditions ?? {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -644,7 +644,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
|||||||
|
|
||||||
let index = 0
|
let index = 0
|
||||||
for(const msg of ms){
|
for(const msg of ms){
|
||||||
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, role: msg.role}), 'editprocess')
|
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, role: msg.role}), 'editprocess', {
|
||||||
|
chatRole: msg.role,
|
||||||
|
})
|
||||||
let name = ''
|
let name = ''
|
||||||
if(msg.role === 'char'){
|
if(msg.role === 'char'){
|
||||||
if(msg.saying){
|
if(msg.saying){
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { downloadFile } from "../storage/globalApi";
|
|||||||
import { alertError, alertNormal } from "../alert";
|
import { alertError, alertNormal } from "../alert";
|
||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import { selectSingleFile } from "../util";
|
import { selectSingleFile } from "../util";
|
||||||
import { assetRegex, risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
import { assetRegex, type CbsConditions, risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||||
import { runCharacterJS } from "../plugins/embedscript";
|
import { runCharacterJS } from "../plugins/embedscript";
|
||||||
import { getModuleAssets, getModuleRegexScripts } from "./modules";
|
import { getModuleAssets, getModuleRegexScripts } from "./modules";
|
||||||
import { HypaProcesser } from "./memory/hypamemory";
|
import { HypaProcesser } from "./memory/hypamemory";
|
||||||
@@ -22,8 +22,8 @@ type pScript = {
|
|||||||
actions: string[]
|
actions: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function processScript(char:character|groupChat, data:string, mode:ScriptMode){
|
export async function processScript(char:character|groupChat, data:string, mode:ScriptMode, cbsConditions:CbsConditions = {}){
|
||||||
return (await processScriptFull(char, data, mode)).data
|
return (await processScriptFull(char, data, mode, -1, cbsConditions)).data
|
||||||
}
|
}
|
||||||
|
|
||||||
export function exportRegex(s?:customscript[]){
|
export function exportRegex(s?:customscript[]){
|
||||||
@@ -66,7 +66,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
|||||||
|
|
||||||
let bestMatchCache = new Map<string, string>()
|
let bestMatchCache = new Map<string, string>()
|
||||||
|
|
||||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||||
let db = get(DataBase)
|
let db = get(DataBase)
|
||||||
let emoChanged = false
|
let emoChanged = false
|
||||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||||
@@ -102,7 +102,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
|
|
||||||
let input = script.in
|
let input = script.in
|
||||||
if(pscript.actions.includes('cbs')){
|
if(pscript.actions.includes('cbs')){
|
||||||
input = risuChatParser(input, { chatID: chatID })
|
input = risuChatParser(input, { chatID: chatID, cbsConditions })
|
||||||
}
|
}
|
||||||
|
|
||||||
const reg = new RegExp(input, flag)
|
const reg = new RegExp(input, flag)
|
||||||
@@ -172,7 +172,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID })
|
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID, cbsConditions })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -215,7 +215,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID })
|
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID, cbsConditions })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user