Fix {{firstIncludedMessageId}} to not rely on DOM

Up until now, the {{firstIncludedMessageId}} macro relied on searching the DOM for the actual CSS class applied for the context line.
Bad design, as the actual message was maybe not display, with display X messages enabled.

- Use setInContextMessages() that sets the context line on generation to also update a chat metadata field
- Utilize that field inside the macro
- Update docs to clarify that this will only show the mesid that was relevant during last generation
This commit is contained in:
Wolfsblvt
2025-01-09 21:23:18 +01:00
parent b604588638
commit 7a2276c176
3 changed files with 9 additions and 11 deletions

View File

@ -5429,20 +5429,24 @@ async function promptItemize(itemizedPrompts, requestedMesId) {
await popup.show();
}
function setInContextMessages(lastmsg, type) {
function setInContextMessages(msgInContextCount, type) {
$('#chat .mes').removeClass('lastInContext');
if (type === 'swipe' || type === 'regenerate' || type === 'continue') {
lastmsg++;
msgInContextCount++;
}
const lastMessageBlock = $('#chat .mes:not([is_system="true"])').eq(-lastmsg);
const lastMessageBlock = $('#chat .mes:not([is_system="true"])').eq(-msgInContextCount);
lastMessageBlock.addClass('lastInContext');
if (lastMessageBlock.length === 0) {
const firstMessageId = getFirstDisplayedMessageId();
$(`#chat .mes[mesid="${firstMessageId}"`).addClass('lastInContext');
}
const lastMessageId = Math.max(0, chat.length - msgInContextCount);
chat_metadata['lastInContextMessageId'] = lastMessageId;
saveMetadataDebounced();
}
/**