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