Merge pull request #3763 from qvink/empty_message_injection Fix for generation interceptors messing with WI timed effects
Signed| @@ -174,7 +174,7 @@ import { | ||
| 174 | 174 | saveBase64AsFile, |
| 175 | 175 | uuidv4, |
| 176 | 176 | } from './scripts/utils.js'; |
| 177 | 177 | import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js'; |
| 178 | 178 | |
| 179 | 179 | import { doDailyExtensionUpdatesCheck, extension_settings, initExtensions, loadExtensionSettings, runGenerationInterceptors, saveMetadataDebounced } from './scripts/extensions.js'; |
| 180 | 180 | import { COMMENT_NAME_DEFAULT, executeSlashCommandsOnChatInput, getSlashCommandsHelp, initDefaultSlashCommands, isExecutingCommandsFromChatInput, pauseScriptExecution, processChatSlashCommands, stopScriptExecution } from './scripts/slash-commands.js'; |
| @@ -5301,6 +5301,12 @@ function formatMessageHistoryItem(chatItem, isInstruct, forceOutputSequence) { | ||
| 5301 | 5301 | const itemName = chatItem.is_user ? chatItem['name'] : characterName; |
| 5302 | 5302 | const shouldPrependName = !isNarratorType; |
| 5303 | 5303 | |
| 5304 | + // If this symbol flag is set, completely ignore the message. | |
| 5305 | + // This can be used to hide messages without affecting the number of messages in the chat. | |
| 5306 | + if (chatItem.extra?.[IGNORE_SYMBOL]) { | |
| 5307 | + return ''; | |
| 5308 | + } | |
| 5309 | + | |
| 5304 | 5310 | // Don't include a name if it's empty |
| 5305 | 5311 | let textResult = chatItem?.name && shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`; |
| 5306 | 5312 | |
| @@ -14,3 +14,11 @@ export const debounce_timeout = { | ||
| 14 | 14 | /** [5 sec] For delayed tasks, like auto-saving or completing batch operations that need a significant pause. */ |
| 15 | 15 | extended: 5000, |
| 16 | 16 | }; |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Used as an ephemeral key in message extra metadata. | |
| 20 | + * When set, the message will be excluded from generation | |
| 21 | + * prompts without affecting the number of chat messages, | |
| 22 | + * which is needed to preserve world info timed effects. | |
| 23 | + */ | |
| 24 | +export const IGNORE_SYMBOL = Symbol.for('ignore'); | |
| @@ -75,6 +75,7 @@ import { Popup, POPUP_RESULT } from './popup.js'; | ||
| 75 | 75 | import { t } from './i18n.js'; |
| 76 | 76 | import { ToolManager } from './tool-calling.js'; |
| 77 | 77 | import { accountStorage } from './util/AccountStorage.js'; |
| 78 | +import { IGNORE_SYMBOL } from './constants.js'; | |
| 78 | 79 | |
| 79 | 80 | export { |
| 80 | 81 | openai_messages_count, |
| @@ -523,6 +524,13 @@ function setOpenAIMessages(chat) { | ||
| 523 | 524 | let role = chat[j]['is_user'] ? 'user' : 'assistant'; |
| 524 | 525 | let content = chat[j]['mes']; |
| 525 | 526 | |
| 527 | + // If this symbol flag is set, completely ignore the message. | |
| 528 | + // This can be used to hide messages without affecting the number of messages in the chat. | |
| 529 | + if (chat[j].extra?.[IGNORE_SYMBOL]) { | |
| 530 | + j++; | |
| 531 | + continue; | |
| 532 | + } | |
| 533 | + | |
| 526 | 534 | // 100% legal way to send a message as system |
| 527 | 535 | if (chat[j].extra?.type === system_message_types.NARRATOR) { |
| 528 | 536 | role = 'system'; |
| @@ -83,6 +83,7 @@ import { convertCharacterBook, getWorldInfoPrompt, loadWorldInfo, reloadEditor, | ||
| 83 | 83 | import { ChatCompletionService, TextCompletionService } from './custom-request.js'; |
| 84 | 84 | import { ConnectionManagerRequestService } from './extensions/shared.js'; |
| 85 | 85 | import { updateReasoningUI, parseReasoningFromString } from './reasoning.js'; |
| 86 | +import { IGNORE_SYMBOL } from './constants.js'; | |
| 86 | 87 | |
| 87 | 88 | export function getContext() { |
| 88 | 89 | return { |
| @@ -225,6 +226,9 @@ export function getContext() { | ||
| 225 | 226 | parseReasoningFromString, |
| 226 | 227 | unshallowCharacter, |
| 227 | 228 | unshallowGroupMembers, |
| 229 | + symbols: { | |
| 230 | + ignore: IGNORE_SYMBOL, | |
| 231 | + }, | |
| 228 | 232 | }; |
| 229 | 233 | } |
| 230 | 234 | |