diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 355ac676b..80392bc54 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -108,6 +108,7 @@ const METADATA_KEY = 'world_info'; const DEFAULT_DEPTH = 4; const DEFAULT_WEIGHT = 100; const MAX_SCAN_DEPTH = 1000; +const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'] // Typedef area /** @@ -3531,6 +3532,61 @@ export async function getSortedEntries() { } } + +/** + * Parse decorators from worldinfo content + * @param {string} content The content to parse + * @returns {[string[],string]} The decorators found in the content and the content without decorators +*/ +function parseDecorators(content){ + /** + * Check if the decorator is known + * @param {string} data string to check + * @returns {boolean} true if the decorator is known + */ + const isKnownDecorator = (data) => { + if(data.startsWith('@@@')){ + data = data.substring(1) + } + + for(let i = 0; i 0) { const nameIncluded = entry.characterFilter.names.includes(getCharaFilename()); @@ -3656,6 +3726,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { continue; } + if (Array.isArray(entry.key) && entry.key.length) { //check for keywords existing // If selectiveLogic isn't found, assume it's AND, only do this once per entry const selectiveLogic = entry.selectiveLogic ?? 0; @@ -3748,7 +3819,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { } else { console.debug(`uid:${entry.uid} passed probability check, inserting to prompt`); } // Substitute macros inline, for both this checking and also future processing - entry.content = substituteParams(entry.content); + entry.content = substituteParams(parseDecorators(entry.content)[1]); newContent += `${entry.content}\n`; if ((textToScanTokens + (await getTokenCountAsync(newContent))) >= budget) { diff --git a/src/character-card-parser.js b/src/character-card-parser.js index 7b17f1868..3de1d3764 100644 --- a/src/character-card-parser.js +++ b/src/character-card-parser.js @@ -23,9 +23,24 @@ const write = (image, data) => { } } - // Add new chunks before the IEND chunk + // Add new v2 chunk before the IEND chunk const base64EncodedData = Buffer.from(data, 'utf8').toString('base64'); chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData)); + + // Try adding v3 chunk before the IEND chunk + try { + //change v2 format to v3 + const v3Data = JSON.parse(data); + v3Data.spec = 'chara_card_v3' + v3Data.spec_version = '3.0' + if(v3Data.data && !v3Data.data.group_only_greetings){ + v3Data.data.group_only_greetings = [] + } + + const base64EncodedData = Buffer.from(JSON.stringify(v3Data), 'utf8').toString('base64'); + chunks.splice(-1, 0, PNGtext.encode('ccv3', base64EncodedData)); + } catch (error) {} + const newBuffer = Buffer.from(encode(chunks)); return newBuffer; };