WI delay until recursion levels

609439def13d0924277e67f3d1908115894b0808

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +19 -0Ignore whitespace
public/scripts/world-info.js+19 -0
@@ -3696,6 +3696,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
36963696 }
36973697 }
36983698
3699+ /** @type {scan_state} */
36993700 let scanState = scan_state.INITIAL;
37003701 let token_budget_overflowed = false;
37013702 let count = 0;
@@ -3720,6 +3721,14 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
37203721 return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() };
37213722 }
37223723
3724+ /** @type {number[]} Represents the delay levels for entries that are delayed until recursion */
3725+ const availableRecursionDelayLevels = [...new Set(sortedEntries
3726+ .filter(entry => entry.delayUntilRecursion)
3727+ .map(entry => entry.delayUntilRecursion === true ? 1 : entry.delayUntilRecursion)
3728+ )].sort((a, b) => a - b);
3729+ // Already preset with the first level
3730+ let currentRecursionDelayLevel = availableRecursionDelayLevels.shift() ?? 0;
3731+
37233732 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);
37243733
37253734 while (scanState) {
@@ -3811,6 +3820,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
38113820 continue;
38123821 }
38133822
3823+ if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) {
3824+ log('suppressed by delay until recursion and having a higher recursion level');
3825+ continue;
3826+ }
3827+
38143828 if (scanState === scan_state.RECURSION && world_info_recursive && entry.excludeRecursion && !isSticky) {
38153829 log('suppressed by exclude recursion');
38163830 continue;
@@ -4039,6 +4053,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
40394053 }
40404054 }
40414055
4056+ // If the scan is done, but we still have open "delay until recursion" levels, we should continue with the next one
4057+ if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) {
4058+ currentRecursionDelayLevel = availableRecursionDelayLevels.shift();
4059+ }
4060+
40424061 // Final check if we should really continue scan, and extend the current WI recurse buffer
40434062 scanState = nextScanState;
40444063 if (scanState) {