diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 0f03ce1e4..9438927b7 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -3696,6 +3696,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { } } + /** @type {scan_state} */ let scanState = scan_state.INITIAL; let token_budget_overflowed = false; let count = 0; @@ -3720,6 +3721,14 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() }; } + /** @type {number[]} Represents the delay levels for entries that are delayed until recursion */ + const availableRecursionDelayLevels = [...new Set(sortedEntries + .filter(entry => entry.delayUntilRecursion) + .map(entry => entry.delayUntilRecursion === true ? 1 : entry.delayUntilRecursion) + )].sort((a, b) => a - b); + // Already preset with the first level + let currentRecursionDelayLevel = availableRecursionDelayLevels.shift() ?? 0; + console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`); while (scanState) { @@ -3811,6 +3820,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { continue; } + if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) { + log('suppressed by delay until recursion and having a higher recursion level'); + continue; + } + if (scanState === scan_state.RECURSION && world_info_recursive && entry.excludeRecursion && !isSticky) { log('suppressed by exclude recursion'); continue; @@ -4039,6 +4053,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { } } + // If the scan is done, but we still have open "delay until recursion" levels, we should continue with the next one + if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) { + currentRecursionDelayLevel = availableRecursionDelayLevels.shift(); + } + // Final check if we should really continue scan, and extend the current WI recurse buffer scanState = nextScanState; if (scanState) {