WI dry run checks delay - WI dry run now also checks for delays - Better visibility of what a dry run is in the logs
| @@ -400,6 +400,12 @@ class WorldInfoTimedEffects { | ||
| 400 | 400 | #entries = []; |
| 401 | 401 | |
| 402 | 402 | /** |
| 403 | + * Is this a dry run? | |
| 404 | + * @type {boolean} | |
| 405 | + */ | |
| 406 | + #isDryRun = false; | |
| 407 | + | |
| 408 | + /** | |
| 403 | 409 | * Buffer for active timed effects. |
| 404 | 410 | * @type {Record<TimedEffectType, WIScanEntry[]>} |
| 405 | 411 | */ |
| @@ -448,10 +454,12 @@ class WorldInfoTimedEffects { | ||
| 448 | 454 | * Initialize the timed effects with the given messages. |
| 449 | 455 | * @param {string[]} chat Array of chat messages |
| 450 | 456 | * @param {WIScanEntry[]} entries Array of entries |
| 457 | + * @param {boolean} isDryRun Whether the operation is a dry run | |
| 451 | 458 | */ |
| 452 | 459 | constructor(chat, entries, isDryRun = false) { |
| 453 | 460 | this.#chat = chat; |
| 454 | 461 | this.#entries = entries; |
| 462 | + this.#isDryRun = isDryRun; | |
| 455 | 463 | this.#ensureChatMetadata(); |
| 456 | 464 | } |
| 457 | 465 | |
| @@ -583,8 +591,10 @@ class WorldInfoTimedEffects { | ||
| 583 | 591 | * Checks for timed effects on chat messages. |
| 584 | 592 | */ |
| 585 | 593 | checkTimedEffects() { |
| 586 | - this.#checkTimedEffectOfType('sticky', this.#buffer.sticky, this.#onEnded.sticky.bind(this)); | |
| 594 | + if (!this.#isDryRun) { | |
| 587 | 595 | this.#checkTimedEffectOfType('cooldownsticky', this.#buffer.cooldownsticky, this.#onEnded.cooldownsticky.bind(this)); |
| 596 | + this.#checkTimedEffectOfType('cooldown', this.#buffer.cooldown, this.#onEnded.cooldown.bind(this)); | |
| 597 | + } | |
| 588 | 598 | this.#checkDelayEffect(this.#buffer.delay); |
| 589 | 599 | } |
| 590 | 600 | |
| @@ -629,6 +639,7 @@ class WorldInfoTimedEffects { | ||
| 629 | 639 | * @param {WIScanEntry[]} activatedEntries Entries that were activated |
| 630 | 640 | */ |
| 631 | 641 | setTimedEffects(activatedEntries) { |
| 642 | + if (this.#isDryRun) return; | |
| 632 | 643 | for (const entry of activatedEntries) { |
| 633 | 644 | this.#setTimedEffectOfType('sticky', entry); |
| 634 | 645 | this.#setTimedEffectOfType('cooldown', entry); |
| @@ -645,6 +656,9 @@ class WorldInfoTimedEffects { | ||
| 645 | 656 | if (!this.isValidEffectType(type)) { |
| 646 | 657 | return; |
| 647 | 658 | } |
| 659 | + if (this.#isDryRun && type !== 'delay') { | |
| 660 | + return; | |
| 661 | + } | |
| 648 | 662 | |
| 649 | 663 | const key = this.#getEntryKey(entry); |
| 650 | 664 | delete chat_metadata.timedWorldInfo[type][key]; |
| @@ -3847,7 +3861,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3847 | 3861 | const context = getContext(); |
| 3848 | 3862 | const buffer = new WorldInfoBuffer(chat); |
| 3849 | 3863 | |
| 3850 | 3864 | console.debug(`[WI] --- START WI SCAN (on ${chat.length} messages)${isDryRun ? ' (DRY RUN)' : ''} ---`); |
| 3851 | 3865 | |
| 3852 | 3866 | // Combine the chat |
| 3853 | 3867 | |
| @@ -3879,9 +3893,9 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3879 | 3893 | |
| 3880 | 3894 | console.debug(`[WI] Context size: ${maxContext}; WI budget: ${budget} (max% = ${world_info_budget}%, cap = ${world_info_budget_cap})`); |
| 3881 | 3895 | const sortedEntries = await getSortedEntries(); |
| 3882 | 3896 | const timedEffects = new WorldInfoTimedEffects(chat, sortedEntries, isDryRun); |
| 3883 | 3897 | |
| 3884 | 3898 | !isDryRun && timedEffects.checkTimedEffects(); |
| 3885 | 3899 | |
| 3886 | 3900 | if (sortedEntries.length === 0) { |
| 3887 | 3901 | return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() }; |
| @@ -4324,12 +4338,12 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 4324 | 4338 | context.setExtensionPrompt(NOTE_MODULE_NAME, ANWithWI, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan, chat_metadata[metadata_keys.role]); |
| 4325 | 4339 | } |
| 4326 | 4340 | |
| 4327 | 4341 | !isDryRun && timedEffects.setTimedEffects(Array.from(allActivatedEntries.values())); |
| 4328 | 4342 | buffer.resetExternalEffects(); |
| 4329 | 4343 | timedEffects.cleanUp(); |
| 4330 | 4344 | |
| 4331 | 4345 | console.log(`[WI] ${isDryRun ? 'Hyophetically adding' : 'Adding'} ${allActivatedEntries.size} entries to prompt`, Array.from(allActivatedEntries.values())); |
| 4332 | 4346 | console.debug('`[WI] --- DONE${isDryRun ? ' (DRY RUN)' : ''} ---'`); |
| 4333 | 4347 | |
| 4334 | 4348 | return { worldInfoBefore, worldInfoAfter, EMEntries, WIDepthEntries, allActivatedEntries: new Set(allActivatedEntries.values()) }; |
| 4335 | 4349 | } |