| 4856 | 4857 | } else { |
| 4857 | 4858 | logNextState('[WI] Scan done. No new entries to prompt. Stopping.'); |
| 4858 | 4859 | } |
| 4860 | + |
| 4861 | + // Fire an event after each scan loop, so extensions can hook into the current scanning state |
| 4862 | + const args = { |
| 4863 | + state: { |
| 4864 | + current: curScanState, |
| 4865 | + next: scanState, |
| 4866 | + loopCount: count, |
| 4867 | + }, |
| 4868 | + new: { |
| 4869 | + all: newEntries, |
| 4870 | + successful: successfulNewEntries, |
| 4871 | + }, |
| 4872 | + activated: { |
| 4873 | + entries: allActivatedEntries, |
| 4874 | + text: allActivatedText, |
| 4875 | + }, |
| 4876 | + sortedEntries, |
| 4877 | + recursionDelay: { |
| 4878 | + availableLevels: availableRecursionDelayLevels, |
| 4879 | + currentLevel: currentRecursionDelayLevel, |
| 4880 | + }, |
| 4881 | + budget: { |
| 4882 | + current: budget, |
| 4883 | + overflowed: token_budget_overflowed, |
| 4884 | + }, |
| 4885 | + timedEffects, |
| 4886 | + }; |
| 4887 | + await eventSource.emit(event_types.WORLDINFO_SCAN_DONE, args); |
| 4888 | + |
| 4889 | + // Some fields are allowed to be changed by listeners, those will be handled here manually. They can be updated via changed the args from the listeners. |
| 4890 | + // Any array provided directly can be modified by updating it's elements, adding or removing elements. This has to be done consistently. |
| 4891 | + if (args.state.next !== scanState) { |
| 4892 | + logNextState('[WI] Scan state changed from', scanState, 'to', args.state.next); |
| 4893 | + scanState = args.state.next; |
| 4894 | + } |
| 4895 | + allActivatedText = args.activated.text; |
| 4896 | + currentRecursionDelayLevel = args.recursionDelay.currentLevel; |
| 4897 | + budget = args.budget.current; |
| 4898 | + token_budget_overflowed = args.budget.overflowed; |
| 4859 | 4899 | } |
| 4860 | 4900 | |
| 4861 | 4901 | console.debug('[WI] --- BUILDING PROMPT ---'); |