Merge pull request #3763 from qvink/empty_message_injection

Fix for generation interceptors messing with WI timed effects
This commit is contained in:
Cohee
2025-03-27 20:53:39 +02:00
committed by GitHub
4 changed files with 27 additions and 1 deletions

View File

@@ -14,3 +14,11 @@ export const debounce_timeout = {
/** [5 sec] For delayed tasks, like auto-saving or completing batch operations that need a significant pause. */
extended: 5000,
};
/**
* Used as an ephemeral key in message extra metadata.
* When set, the message will be excluded from generation
* prompts without affecting the number of chat messages,
* which is needed to preserve world info timed effects.
*/
export const IGNORE_SYMBOL = Symbol.for('ignore');

View File

@@ -75,6 +75,7 @@ import { Popup, POPUP_RESULT } from './popup.js';
import { t } from './i18n.js';
import { ToolManager } from './tool-calling.js';
import { accountStorage } from './util/AccountStorage.js';
import { IGNORE_SYMBOL } from './constants.js';
export {
openai_messages_count,
@@ -523,6 +524,13 @@ function setOpenAIMessages(chat) {
let role = chat[j]['is_user'] ? 'user' : 'assistant';
let content = chat[j]['mes'];
// If this symbol flag is set, completely ignore the message.
// This can be used to hide messages without affecting the number of messages in the chat.
if (chat[j].extra?.[IGNORE_SYMBOL]) {
j++;
continue;
}
// 100% legal way to send a message as system
if (chat[j].extra?.type === system_message_types.NARRATOR) {
role = 'system';

View File

@@ -83,6 +83,7 @@ import { convertCharacterBook, getWorldInfoPrompt, loadWorldInfo, reloadEditor,
import { ChatCompletionService, TextCompletionService } from './custom-request.js';
import { ConnectionManagerRequestService } from './extensions/shared.js';
import { updateReasoningUI, parseReasoningFromString } from './reasoning.js';
import { IGNORE_SYMBOL } from './constants.js';
export function getContext() {
return {
@@ -225,6 +226,9 @@ export function getContext() {
parseReasoningFromString,
unshallowCharacter,
unshallowGroupMembers,
symbols: {
ignore: IGNORE_SYMBOL,
},
};
}