diff --git a/public/script.js b/public/script.js index 780e28dbd..6b3b10e3a 100644 --- a/public/script.js +++ b/public/script.js @@ -2017,6 +2017,20 @@ function getLastMessageId() { return ''; } +/** + * Returns the ID of the first message included in the context. + * @returns {string} The ID of the first message in the context. + */ +function getFirstIncludedMessageId() { + const index = document.querySelector('.lastInContext')?.getAttribute('mesid'); + + if (!isNaN(index) && index >= 0) { + return String(index); + } + + return ''; +} + /** * Returns the last message in the chat. * @returns {string} The last message in the chat. @@ -2119,6 +2133,7 @@ function substituteParams(content, _name1, _name2, _original, _group, _replaceCh content = content.replace(/{{group}}/gi, _group); content = content.replace(/{{lastMessage}}/gi, getLastMessage()); content = content.replace(/{{lastMessageId}}/gi, getLastMessageId()); + content = content.replace(/{{firstIncludedMessageId}}/gi, getFirstIncludedMessageId()); content = content.replace(/{{lastSwipeId}}/gi, getLastSwipeId()); content = content.replace(/{{currentSwipeId}}/gi, getCurrentSwipeId()); diff --git a/public/scripts/templates/macros.html b/public/scripts/templates/macros.html index 2eeb6537c..a3e0e83a0 100644 --- a/public/scripts/templates/macros.html +++ b/public/scripts/templates/macros.html @@ -17,6 +17,7 @@
  • {{char}} – the Character's name
  • {{lastMessage}} - the text of the latest chat message.
  • {{lastMessageId}} – index # of the latest chat message. Useful for slash command batching.
  • +
  • {{firstIncludedMessageId}} - the ID of the first message included in the context. Requires generation to be ran at least once in the current session.
  • {{currentSwipeId}} – the 1-based ID of the current swipe in the last chat message. Empty string if the last message is user or prompt-hidden.
  • {{lastSwipeId}} – the number of swipes in the last chat message. Empty string if the last message is user or prompt-hidden.
  • {{// (note)}} – you can leave a note here, and the macro will be replaced with blank content. Not visible for the AI.