#2467 Fix min activations for non-recursable entries

df67a7cdc49f11ea682013ccf0e185e8f8c3a181

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +33 -10Showing whitespace changes
public/scripts/world-info.js+33 -10
@@ -50,6 +50,24 @@ const world_info_logic = {
5050 AND_ALL: 3,
5151};
5252
53+/**
54+ * @enum {number} Possible states of the WI evaluation
55+ */
56+const scan_state = {
57+ /**
58+ * The scan will be stopped.
59+ */
60+ NONE: 0,
61+ /**
62+ * The scan is triggered by a recursion step. Initial state.
63+ */
64+ RECURSION: 1,
65+ /**
66+ * The scan is triggered by a min activations depth skew.
67+ */
68+ MIN_ACTIVATIONS: 2,
69+};
70+
5371const WI_ENTRY_EDIT_TEMPLATE = $('#entry_edit_template .world_entry');
5472
5573let world_info = {};
@@ -3508,7 +3526,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
35083526 }
35093527 }
35103528
35113529 let needsToScanscanState = truescan_state.RECURSION;
35123530 let token_budget_overflowed = false;
35133531 let count = 0;
35143532 let allActivatedEntries = new Set();
@@ -3532,7 +3550,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
35323550 return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() };
35333551 }
35343552
35353553 while (needsToScanscanState) {
35363554 // Track how many times the loop has run
35373555 count++;
35383556
@@ -3587,7 +3605,12 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
35873605 continue;
35883606 }
35893607
35903608 if (allActivatedEntries.has(entry) || entry.disable == true || (count > 1 && world_info_recursive && entry.excludeRecursion) || (count == 1 && entry.delayUntilRecursion)) {
3609+ continue;
3610+ }
3611+
3612+ // Only use checks for recursion flags if the scan step was activated by recursion
3613+ if (scanState === scan_state.RECURSION && ((count > 1 && world_info_recursive && entry.excludeRecursion) || (count == 1 && entry.delayUntilRecursion))) {
35913614 continue;
35923615 }
35933616
@@ -3665,7 +3688,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
36653688 }
36663689 }
36673690
36683691 needsToScanscanState = world_info_recursive && activatedNow.size > 0 ? scan_state.RECURSION : scan_state.NONE;
36693692 const newEntries = [...activatedNow]
36703693 .sort((a, b) => sortedEntries.indexOf(a) - sortedEntries.indexOf(b));
36713694 let newContent = '';
@@ -3697,7 +3720,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
36973720 console.log('Alerting');
36983721 toastr.warning(`World info budget reached after ${allActivatedEntries.size} entries.`, 'World Info');
36993722 }
37003723 needsToScanscanState = falsescan_state.NONE;
37013724 token_budget_overflowed = true;
37023725 break;
37033726 }
@@ -3710,15 +3733,15 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
37103733
37113734 if ((probabilityChecksAfter - probabilityChecksBefore) === activatedNow.size) {
37123735 console.debug('WI probability checks failed for all activated entries, stopping');
37133736 needsToScanscanState = falsescan_state.NONE;
37143737 }
37153738
37163739 if (newEntries.length === 0) {
37173740 console.debug('No new entries activated, stopping');
37183741 needsToScanscanState = falsescan_state.NONE;
37193742 }
37203743
37213744 if (needsToScanscanState) {
37223745 const text = newEntries
37233746 .filter(x => !failedProbabilityChecks.has(x))
37243747 .filter(x => !x.preventRecursion)
@@ -3728,7 +3751,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
37283751 }
37293752
37303753 // world_info_min_activations
37313754 if (!needsToScanscanState && !token_budget_overflowed) {
37323755 if (world_info_min_activations > 0 && (allActivatedEntries.size < world_info_min_activations)) {
37333756 let over_max = (
37343757 world_info_min_activations_depth_max > 0 &&
@@ -3736,7 +3759,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
37363759 ) || (buffer.getDepth() > chat.length);
37373760
37383761 if (!over_max) {
37393762 needsToScanscanState = truescan_state.MIN_ACTIVATIONS; // loop
37403763 buffer.advanceScanPosition();
37413764 }
37423765 }