Add decorators
This commit is contained in:
@@ -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<word.length; counter++){
|
||||
hashAddress = ((hashAddress << 5) + hashAddress) + word.charCodeAt(counter)
|
||||
}
|
||||
return hashAddress
|
||||
}
|
||||
const randF = sfc32(rand(word), rand(word), rand(word), rand(word))
|
||||
const v = cid % 1000
|
||||
for (let i = 0; i < v; i++){
|
||||
randF()
|
||||
}
|
||||
return randF()
|
||||
}
|
||||
|
||||
const dateTimeFormat = (main:string, time = 0) => {
|
||||
const date = time === 0 ? (new Date()) : (new Date(time))
|
||||
if(!main){
|
||||
|
||||
@@ -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<fullLore.length;i++){
|
||||
@@ -239,6 +242,7 @@ export async function loadLoreBookV3Prompt(){
|
||||
}
|
||||
}
|
||||
}
|
||||
let itemRecursive:'global'|true|false = 'global'
|
||||
const content = CCardLib.decorator.parse(fullLore[i].content, (name, arg) => {
|
||||
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,
|
||||
|
||||
@@ -1050,4 +1050,21 @@ export const sortableOptions = {
|
||||
onMove: (event) => {
|
||||
return event.related.className.indexOf('no-sort') === -1
|
||||
}
|
||||
} as const
|
||||
} as const
|
||||
|
||||
|
||||
export function pickHashRand(cid:number,word:string) {
|
||||
let hashAddress = 5515
|
||||
const rand = (word:string) => {
|
||||
for (let counter = 0; counter<word.length; counter++){
|
||||
hashAddress = ((hashAddress << 5) + hashAddress) + word.charCodeAt(counter)
|
||||
}
|
||||
return hashAddress
|
||||
}
|
||||
const randF = sfc32(rand(word), rand(word), rand(word), rand(word))
|
||||
const v = cid % 1000
|
||||
for (let i = 0; i < v; i++){
|
||||
randF()
|
||||
}
|
||||
return randF()
|
||||
}
|
||||
Reference in New Issue
Block a user