Adjust itemized prompts on message move/delete (#5000)

* Adjust itemized prompts on message move/delete

* Sort itemized prompts on swap

* Remove itemized prompt on regeneration
This commit is contained in:
Cohee
2026-01-12 22:40:33 +02:00
committed by GitHub
parent 69b7a17c77
commit 684b755826
2 changed files with 51 additions and 2 deletions
+8 -1
View File
@@ -272,7 +272,7 @@ import { extractReasoningFromData, extractReasoningSignatureFromData, initReason
import { accountStorage } from './scripts/util/AccountStorage.js';
import { initWelcomeScreen, openPermanentAssistantChat, openPermanentAssistantCard, getPermanentAssistantAvatar } from './scripts/welcome-screen.js';
import { initDataMaid } from './scripts/data-maid.js';
import { clearItemizedPrompts, deleteItemizedPrompts, findItemizedPromptSet, initItemizedPrompts, itemizedParams, itemizedPrompts, loadItemizedPrompts, promptItemize, replaceItemizedPromptText, saveItemizedPrompts } from './scripts/itemized-prompts.js';
import { clearItemizedPrompts, deleteItemizedPromptForMessage, deleteItemizedPrompts, findItemizedPromptSet, initItemizedPrompts, itemizedParams, itemizedPrompts, loadItemizedPrompts, promptItemize, replaceItemizedPromptText, saveItemizedPrompts, swapItemizedPrompts } from './scripts/itemized-prompts.js';
import { getSystemMessageByType, initSystemMessages, SAFETY_CHAT, sendSystemMessage, system_message_types, system_messages } from './scripts/system-messages.js';
import { event_types, eventSource } from './scripts/events.js';
import { initAccessibility } from './scripts/a11y.js';
@@ -1546,6 +1546,7 @@ export async function clearChat() {
}
export async function deleteLastMessage() {
deleteItemizedPromptForMessage(chat.length - 1);
chat.length = chat.length - 1;
chatElement.children('.mes').last().remove();
await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
@@ -1601,6 +1602,7 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi
chat_metadata.tainted = true;
const startIndex = [0, minId].includes(id) ? id : null;
deleteItemizedPromptForMessage(id);
updateViewMessageIds(startIndex);
saveChatDebounced();
@@ -4230,6 +4232,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
//do nothing? why does this check exist?
}
else if (type !== 'quiet' && type !== 'swipe' && !isImpersonate && !dryRun && chat.length) {
deleteItemizedPromptForMessage(chat.length - 1);
chat.length = chat.length - 1;
await removeLastMessage();
await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
@@ -8142,6 +8145,7 @@ async function messageEditMove(sourceId, targetId) {
this_edit_mes_id = targetId;
}
swapItemizedPrompts(sourceId, targetId);
updateViewMessageIds();
refreshSwipeButtons();
await saveChatConditional();
@@ -11450,6 +11454,9 @@ jQuery(async function () {
});
if (this_del_mes >= 0) {
for (let i = (chat.length - 1); i >= this_del_mes; i--) {
deleteItemizedPromptForMessage(i);
}
chatElement.find(`.mes[mesid="${this_del_mes}"]`).nextAll('div').remove();
chatElement.find(`.mes[mesid="${this_del_mes}"]`).remove();
chat.length = this_del_mes;