diff --git a/src/ts/parser.svelte.ts b/src/ts/parser.svelte.ts index eeeb501f..b241ddef 100644 --- a/src/ts/parser.svelte.ts +++ b/src/ts/parser.svelte.ts @@ -8,7 +8,7 @@ import { get } from 'svelte/store'; import css, { type CssAtRuleAST } from '@adobe/css-tools' import { SizeStore, selectedCharID } from './stores.svelte'; import { calcString } from './process/infunctions'; -import { findCharacterbyId, getPersonaPrompt, getUserIcon, getUserName, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util'; +import { findCharacterbyId, getPersonaPrompt, getUserIcon, getUserName, parseKeyValue, pickHashRand} from './util'; import { getInlayAsset } from './process/files/inlays'; import { getModuleAssets, getModuleLorebooks, getModules } from './process/modules'; import type { OpenAIChat } from './process/index.svelte'; @@ -1949,22 +1949,6 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string } } -function pickHashRand(cid:number,word:string) { - let hashAddress = 5515 - const rand = (word:string) => { - for (let counter = 0; counter { const date = time === 0 ? (new Date()) : (new Date(time)) if(!main){ diff --git a/src/ts/process/lorebook.svelte.ts b/src/ts/process/lorebook.svelte.ts index eb8def18..530be48b 100644 --- a/src/ts/process/lorebook.svelte.ts +++ b/src/ts/process/lorebook.svelte.ts @@ -3,12 +3,13 @@ import {selectedCharID} from '../stores.svelte' import { type Message, type loreBook } from "../storage/database.svelte"; import { DBState } from '../stores.svelte'; import { tokenize } from "../tokenizer"; -import { checkNullish, findCharacterbyId, selectSingleFile } from "../util"; +import { checkNullish, findCharacterbyId, pickHashRand, selectSingleFile, sfc32 } from "../util"; import { alertError, alertNormal } from "../alert"; import { language } from "../../lang"; import { downloadFile } from "../globalApi.svelte"; import { getModuleLorebooks } from "./modules"; import { CCardLib } from "@risuai/ccardlib"; +import { getChatVar, setChatVar } from "../parser.svelte"; export function addLorebook(type:number) { const selectedID = get(selectedCharID) @@ -201,6 +202,8 @@ export async function loadLoreBookV3Prompt(){ let activatedIndexes:number[] = [] let disabledUIPrompts:string[] = [] let matchTimes = 0 + let keepActivateAfterMatch = false + let dontActivateAfterMatch = false while(matching){ matching = false for(let i=0;i { switch(name){ case 'end':{ @@ -267,11 +271,23 @@ export async function loadLoreBookV3Prompt(){ return } case 'keep_activate_after_match':{ - //TODO + const vara = getChatVar('__internal_ka_' + (fullLore[i].id ?? pickHashRand(5555,fullLore[i].content).toString())) + if(vara === 'true'){ + forceState = 'activate' + } + else{ + keepActivateAfterMatch = true + } return false } case 'dont_activate_after_match': { - //TODO + const vara = getChatVar('__internal_da_' + (fullLore[i].id ?? pickHashRand(5555,fullLore[i].content).toString())) + if(vara === 'true'){ + forceState = 'deactivate' + } + else{ + dontActivateAfterMatch = true + } return false } case 'depth': @@ -379,6 +395,15 @@ export async function loadLoreBookV3Prompt(){ priority = parseInt(arg[0]) return } + //We can already do it with search depth, but its more readable and performant this way + case 'unrecursive':{ + itemRecursive = false + return + } + case 'recursive':{ + itemRecursive = true + return + } default:{ return false } @@ -444,7 +469,21 @@ export async function loadLoreBookV3Prompt(){ source: fullLore[i].comment || `lorebook ${i}` }) activatedIndexes.push(i) - if(recursiveScanning){ + + if(keepActivateAfterMatch){ + setChatVar('__internal_ka_' + (fullLore[i].id ?? pickHashRand(5555,fullLore[i].content).toString()), 'true') + } + if(dontActivateAfterMatch){ + setChatVar('__internal_da_' + (fullLore[i].id ?? pickHashRand(5555,fullLore[i].content).toString()), 'true') + } + + + let recursive = recursiveScanning + if(itemRecursive !== 'global'){ + recursive = itemRecursive + } + + if(recursive){ matching = true recursivePrompt.push({ prompt: content, diff --git a/src/ts/util.ts b/src/ts/util.ts index ab538360..c80360a2 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -1050,4 +1050,21 @@ export const sortableOptions = { onMove: (event) => { return event.related.className.indexOf('no-sort') === -1 } -} as const \ No newline at end of file +} as const + + +export function pickHashRand(cid:number,word:string) { + let hashAddress = 5515 + const rand = (word:string) => { + for (let counter = 0; counter