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) {
3696 }3696 }
3697 }3697 }
36983698
3699 /** @type {scan_state} */
3699 let scanState = scan_state.INITIAL;3700 let scanState = scan_state.INITIAL;
3700 let token_budget_overflowed = false;3701 let token_budget_overflowed = false;
3701 let count = 0;3702 let count = 0;
@@ -3720,6 +3721,14 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3720 return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() };3721 return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() };
3721 }3722 }
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
3723 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);3732 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);
37243733
3725 while (scanState) {3734 while (scanState) {
@@ -3811,6 +3820,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3811 continue;3820 continue;
3812 }3821 }
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
3814 if (scanState === scan_state.RECURSION && world_info_recursive && entry.excludeRecursion && !isSticky) {3828 if (scanState === scan_state.RECURSION && world_info_recursive && entry.excludeRecursion && !isSticky) {
3815 log('suppressed by exclude recursion');3829 log('suppressed by exclude recursion');
3816 continue;3830 continue;
@@ -4039,6 +4053,11 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
4039 }4053 }
4040 }4054 }
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
4042 // Final check if we should really continue scan, and extend the current WI recurse buffer4061 // Final check if we should really continue scan, and extend the current WI recurse buffer
4043 scanState = nextScanState;4062 scanState = nextScanState;
4044 if (scanState) {4063 if (scanState) {