From d5b92311571b1b37a6f435d954c8e6922cb204ae Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 7 Sep 2024 23:00:12 +0200 Subject: [PATCH 01/20] Update toeast message --- public/scripts/bookmarks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index eda6935aa..071d109f8 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -218,7 +218,7 @@ async function createNewBookmark(mesId) { $(`.mes[mesid="${mesId}"]`).attr('bookmark_link', name); await saveChatConditional(); - toastr.success('Click the flag icon in the last message to open the checkpoint chat.', 'Checkpoint created', { timeOut: 10000 }); + toastr.success('Click the flag icon next to the message to open the checkpoint chat.', 'Checkpoint created', { timeOut: 10000 }); } async function backToMainChat() { From f5d164302b6f2a2adf6f0fd10db12ca849df3a6f Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 7 Sep 2024 23:55:34 +0200 Subject: [PATCH 02/20] Remove double flags for bookmarks - Remove the double flag if a checkpoint exists - Add the "replace checkpoint" functionality as a Shift+Click option to the checkpoint flag --- public/index.html | 2 +- public/script.js | 9 ++++++++- public/style.css | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index c949839d8..3dd371e18 100644 --- a/public/index.html +++ b/public/index.html @@ -5777,7 +5777,7 @@
-
+
diff --git a/public/script.js b/public/script.js index 22aa140f3..5ea615aa2 100644 --- a/public/script.js +++ b/public/script.js @@ -10563,7 +10563,14 @@ jQuery(async function () { await duplicateCharacter(); }); - $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function () { + $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) { + // If shift is held down, we are not following the bookmark, but creating a new one + if (e.shiftKey) { + var selectedMesId = $(this).closest('.mes').attr('mesid'); + createNewBookmark(selectedMesId); + return; + } + let file_name = $(this).hasClass('mes_bookmark') ? $(this).closest('.mes').attr('bookmark_link') : $(this).attr('file_name').replace('.jsonl', ''); diff --git a/public/style.css b/public/style.css index 91726dd63..a410df236 100644 --- a/public/style.css +++ b/public/style.css @@ -3963,6 +3963,10 @@ input[type="range"]::-webkit-slider-thumb { display: inline-block; } +.mes:not([bookmark_link='']) .mes_create_bookmark { + display: none; +} + .mes_edit_buttons { display: none; flex-direction: row; From 6a4ba1344f8a0e4b12d8aedb6921467fb278cdcb Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 7 Sep 2024 23:55:45 +0200 Subject: [PATCH 03/20] Remove legacy bookmark messages --- public/script.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/public/script.js b/public/script.js index 5ea615aa2..9985982cc 100644 --- a/public/script.js +++ b/public/script.js @@ -556,8 +556,6 @@ export const system_message_types = { GROUP: 'group', EMPTY: 'empty', GENERIC: 'generic', - BOOKMARK_CREATED: 'bookmark_created', - BOOKMARK_BACK: 'bookmark_back', NARRATOR: 'narrator', COMMENT: 'comment', SLASH_COMMANDS: 'slash_commands', @@ -669,20 +667,6 @@ async function getSystemMessages() { is_system: true, mes: 'Generic system message. User `text` parameter to override the contents', }, - bookmark_created: { - name: systemUserName, - force_avatar: system_avatar, - is_user: false, - is_system: true, - mes: 'Checkpoint created! Click here to open the checkpoint chat: {1}', - }, - bookmark_back: { - name: systemUserName, - force_avatar: system_avatar, - is_user: false, - is_system: true, - mes: 'Click here to return to the previous chat: Return', - }, welcome_prompt: { name: systemUserName, force_avatar: system_avatar, From 3217087b0be9109763136708d6a5e87faa8a5a83 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 8 Sep 2024 00:06:19 +0200 Subject: [PATCH 04/20] Refactor checkpoint popups --- public/scripts/bookmarks.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 071d109f8..78759bcc7 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -59,11 +59,9 @@ async function getExistingChatNames() { async function getBookmarkName() { const chatNames = await getExistingChatNames(); - const popupText = `

Enter the checkpoint name:

- Leave empty to auto-generate.`; - let name = await callPopup(popupText, 'input'); - if (name === false) { + let name = await Popup.show.input('Create Checkpoint', 'Enter Checkpoint Name:(Leave empty to auto-generate)'); + if (name === null) { return null; } else if (name === '') { @@ -190,16 +188,13 @@ async function createNewBookmark(mesId) { } if (lastMes.extra.bookmark_link) { - const confirm = await callPopup('Checkpoint for the last message already exists. Would you like to replace it?', 'confirm'); - + const confirm = await Popup.show.confirm('Replace Checkpoint', 'Checkpoint for the last message already exists.
Would you like to replace it?'); if (!confirm) { return; } } - await delay(250); let name = await getBookmarkName(); - if (!name) { return; } From 6c94297724cf3fdd82f852735916d8a6214fabd8 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 8 Sep 2024 00:20:56 +0200 Subject: [PATCH 05/20] Expand checkpoint tooltip to contain name --- public/index.html | 2 +- public/script.js | 1 + public/scripts/bookmarks.js | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 3dd371e18..abd24c436 100644 --- a/public/index.html +++ b/public/index.html @@ -5777,7 +5777,7 @@

-
+
diff --git a/public/script.js b/public/script.js index 9985982cc..b3c5a7240 100644 --- a/public/script.js +++ b/public/script.js @@ -2102,6 +2102,7 @@ function getMessageFromTemplate({ tokenCount && mes.find('.tokenCounterDisplay').text(`${tokenCount}t`); title && mes.attr('title', title); timerValue && mes.find('.mes_timer').attr('title', timerTitle).text(timerValue); + bookmarkLink && mes.find('.mes_bookmark').attr('title', `Checkpoint\n${bookmarkLink}\n\n${mes.find('.mes_bookmark').data('tooltip')}`); if (power_user.timestamp_model_icon && extra?.api) { insertSVGIcon(mes, extra); diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 78759bcc7..c1adae7f5 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -210,7 +210,10 @@ async function createNewBookmark(mesId) { } lastMes.extra['bookmark_link'] = name; - $(`.mes[mesid="${mesId}"]`).attr('bookmark_link', name); + + const mes = $(`.mes[mesid="${mesId}"]`); + mes.attr('bookmark_link', name); + mes.find('.mes_bookmark').attr('title', `Checkpoint${name}\n\n${(mes.find('.mes_bookmark')).data('tooltip')}`); await saveChatConditional(); toastr.success('Click the flag icon next to the message to open the checkpoint chat.', 'Checkpoint created', { timeOut: 10000 }); From 6c0ecdef69bfc0a7d5f6740cc1d13e22a06f9c45 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 8 Sep 2024 00:34:03 +0200 Subject: [PATCH 06/20] Refactor move bookmark functionality --- public/script.js | 73 +------------------------------- public/scripts/bookmarks.js | 83 ++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 73 deletions(-) diff --git a/public/script.js b/public/script.js index b3c5a7240..0c491f74a 100644 --- a/public/script.js +++ b/public/script.js @@ -117,9 +117,8 @@ import { } from './scripts/nai-settings.js'; import { - createNewBookmark, showBookmarksButtons, - createBranch, + updateBookmarkDisplay, } from './scripts/bookmarks.js'; import { @@ -2102,7 +2101,7 @@ function getMessageFromTemplate({ tokenCount && mes.find('.tokenCounterDisplay').text(`${tokenCount}t`); title && mes.attr('title', title); timerValue && mes.find('.mes_timer').attr('title', timerTitle).text(timerValue); - bookmarkLink && mes.find('.mes_bookmark').attr('title', `Checkpoint\n${bookmarkLink}\n\n${mes.find('.mes_bookmark').data('tooltip')}`); + bookmarkLink && updateBookmarkDisplay(mes); if (power_user.timestamp_model_icon && extra?.api) { insertSVGIcon(mes, extra); @@ -8220,29 +8219,6 @@ function swipe_left() { // when we swipe left..but no generation. } } -/** - * Creates a new branch from the message with the given ID - * @param {number} mesId Message ID - * @returns {Promise} Branch file name - */ -async function branchChat(mesId) { - if (this_chid === undefined && !selected_group) { - toastr.info('No character selected.', 'Branch creation aborted'); - return; - } - - const fileName = await createBranch(mesId); - await saveItemizedPrompts(fileName); - - if (selected_group) { - await openGroupChat(selected_group, fileName); - } else { - await openCharacterChat(fileName); - } - - return fileName; -} - // when we click swipe right button const swipe_right = () => { if (chat.length - 1 === Number(this_edit_mes_id)) { @@ -10548,51 +10524,6 @@ jQuery(async function () { await duplicateCharacter(); }); - $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) { - // If shift is held down, we are not following the bookmark, but creating a new one - if (e.shiftKey) { - var selectedMesId = $(this).closest('.mes').attr('mesid'); - createNewBookmark(selectedMesId); - return; - } - - let file_name = $(this).hasClass('mes_bookmark') - ? $(this).closest('.mes').attr('bookmark_link') - : $(this).attr('file_name').replace('.jsonl', ''); - - if (!file_name) { - return; - } - - try { - showLoader(); - if (selected_group) { - await openGroupChat(selected_group, file_name); - } else { - await openCharacterChat(file_name); - } - } finally { - hideLoader(); - } - - $('#shadow_select_chat_popup').css('display', 'none'); - $('#load_select_chat_div').css('display', 'block'); - }); - - $(document).on('click', '.mes_create_bookmark', async function () { - var selected_mes_id = $(this).closest('.mes').attr('mesid'); - if (selected_mes_id !== undefined) { - createNewBookmark(selected_mes_id); - } - }); - - $(document).on('click', '.mes_create_branch', async function () { - var selected_mes_id = $(this).closest('.mes').attr('mesid'); - if (selected_mes_id !== undefined) { - branchChat(Number(selected_mes_id)); - } - }); - $(document).on('click', '.mes_stop', function () { stopGeneration(); }); diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index c1adae7f5..df1fdfc97 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -24,6 +24,7 @@ import { saveGroupBookmarkChat, selected_group, } from './group-chats.js'; +import { hideLoader, showLoader } from './loader.js'; import { Popup } from './popup.js'; import { createTagMapFromList } from './tags.js'; @@ -212,13 +213,23 @@ async function createNewBookmark(mesId) { lastMes.extra['bookmark_link'] = name; const mes = $(`.mes[mesid="${mesId}"]`); - mes.attr('bookmark_link', name); - mes.find('.mes_bookmark').attr('title', `Checkpoint${name}\n\n${(mes.find('.mes_bookmark')).data('tooltip')}`); + updateBookmarkDisplay(mes, name); await saveChatConditional(); toastr.success('Click the flag icon next to the message to open the checkpoint chat.', 'Checkpoint created', { timeOut: 10000 }); } + +/** + * Updates the display of the bookmark on a chat message. + * @param {JQuery} mes - The message element + * @param {string?} [newBookmarkLink=null] - The new bookmark link (optional) + */ +export function updateBookmarkDisplay(mes, newBookmarkLink = null) { + newBookmarkLink && mes.attr('bookmark_link', newBookmarkLink); + mes.find('.mes_bookmark').attr('title', `Checkpoint\n${mes.attr('bookmark_link')}\n\n${mes.find('.mes_bookmark').data('tooltip')}`); +} + async function backToMainChat() { const mainChatName = getMainChatName(); const allChats = await getExistingChatNames(); @@ -349,8 +360,76 @@ async function convertSoloToGroupChat() { toastr.success('The chat has been successfully converted!'); } +/** + * Creates a new branch from the message with the given ID + * @param {number} mesId Message ID + * @returns {Promise} Branch file name + */ +async function branchChat(mesId) { + if (this_chid === undefined && !selected_group) { + toastr.info('No character selected.', 'Branch creation aborted'); + return; + } + + const fileName = await createBranch(mesId); + await saveItemizedPrompts(fileName); + + if (selected_group) { + await openGroupChat(selected_group, fileName); + } else { + await openCharacterChat(fileName); + } + + return fileName; +} + jQuery(function () { $('#option_new_bookmark').on('click', saveBookmarkMenu); $('#option_back_to_main').on('click', backToMainChat); $('#option_convert_to_group').on('click', convertSoloToGroupChat); + + $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) { + // If shift is held down, we are not following the bookmark, but creating a new one + if (e.shiftKey) { + var selectedMesId = $(this).closest('.mes').attr('mesid'); + createNewBookmark(selectedMesId); + return; + } + + let file_name = $(this).hasClass('mes_bookmark') + ? $(this).closest('.mes').attr('bookmark_link') + : $(this).attr('file_name').replace('.jsonl', ''); + + if (!file_name) { + return; + } + + try { + showLoader(); + if (selected_group) { + await openGroupChat(selected_group, file_name); + } else { + await openCharacterChat(file_name); + } + } finally { + hideLoader(); + } + + $('#shadow_select_chat_popup').css('display', 'none'); + $('#load_select_chat_div').css('display', 'block'); + }); + + $(document).on('click', '.mes_create_bookmark', async function () { + var selected_mes_id = $(this).closest('.mes').attr('mesid'); + if (selected_mes_id !== undefined) { + createNewBookmark(selected_mes_id); + } + }); + + $(document).on('click', '.mes_create_branch', async function () { + var selected_mes_id = $(this).closest('.mes').attr('mesid'); + if (selected_mes_id !== undefined) { + branchChat(Number(selected_mes_id)); + } + }); }); From cb9e73decaa808a85306ca59f26b6211a085a254 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 8 Sep 2024 00:41:14 +0200 Subject: [PATCH 07/20] Refactor bookmarks with correct async and export --- public/scripts/bookmarks.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index df1fdfc97..11cd70160 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -6,7 +6,6 @@ import { this_chid, openCharacterChat, chat_metadata, - callPopup, getRequestHeaders, getThumbnailUrl, getCharacters, @@ -29,15 +28,9 @@ import { Popup } from './popup.js'; import { createTagMapFromList } from './tags.js'; import { - delay, getUniqueName, } from './utils.js'; -export { - createNewBookmark, - showBookmarksButtons, -}; - const bookmarkNameToken = 'Checkpoint #'; async function getExistingChatNames() { @@ -95,7 +88,7 @@ function getMainChatName() { return null; } -function showBookmarksButtons() { +export function showBookmarksButtons() { try { if (selected_group) { $('#option_convert_to_group').hide(); @@ -130,10 +123,10 @@ async function saveBookmarkMenu() { return; } - return createNewBookmark(chat.length - 1); + return await createNewBookmark(chat.length - 1); } -export async function createBranch(mesId) { +async function createBranch(mesId) { if (!chat.length) { toastr.warning('The chat is empty.', 'Branch creation failed'); return; @@ -166,7 +159,7 @@ export async function createBranch(mesId) { return name; } -async function createNewBookmark(mesId) { +export async function createNewBookmark(mesId) { if (this_chid === undefined && !selected_group) { toastr.info('No character selected.', 'Checkpoint creation aborted'); return; @@ -243,7 +236,7 @@ async function backToMainChat() { } } -async function convertSoloToGroupChat() { +export async function convertSoloToGroupChat() { if (selected_group) { console.log('Already in group. No need for conversion'); return; @@ -270,6 +263,7 @@ async function convertSoloToGroupChat() { const activationStrategy = group_activation_strategy.NATURAL; const allowSelfResponses = false; const favChecked = character.fav || character.fav == 'true'; + /** @type {any} */ const metadata = Object.assign({}, chat_metadata); delete metadata.main_chat; @@ -365,7 +359,7 @@ async function convertSoloToGroupChat() { * @param {number} mesId Message ID * @returns {Promise} Branch file name */ -async function branchChat(mesId) { +export async function branchChat(mesId) { if (this_chid === undefined && !selected_group) { toastr.info('No character selected.', 'Branch creation aborted'); return; @@ -392,7 +386,7 @@ jQuery(function () { // If shift is held down, we are not following the bookmark, but creating a new one if (e.shiftKey) { var selectedMesId = $(this).closest('.mes').attr('mesid'); - createNewBookmark(selectedMesId); + await createNewBookmark(selectedMesId); return; } @@ -412,7 +406,7 @@ jQuery(function () { await openCharacterChat(file_name); } } finally { - hideLoader(); + await hideLoader(); } $('#shadow_select_chat_popup').css('display', 'none'); @@ -422,14 +416,14 @@ jQuery(function () { $(document).on('click', '.mes_create_bookmark', async function () { var selected_mes_id = $(this).closest('.mes').attr('mesid'); if (selected_mes_id !== undefined) { - createNewBookmark(selected_mes_id); + await createNewBookmark(selected_mes_id); } }); $(document).on('click', '.mes_create_branch', async function () { var selected_mes_id = $(this).closest('.mes').attr('mesid'); if (selected_mes_id !== undefined) { - branchChat(Number(selected_mes_id)); + await branchChat(Number(selected_mes_id)); } }); }); From 22d2b7d2a2f0f918d2c9de79739395f3b8335e30 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 8 Sep 2024 03:28:54 +0200 Subject: [PATCH 08/20] Add slash commands for checkpoints and branch --- public/script.js | 2 + public/scripts/bookmarks.js | 301 +++++++++++++++++++++++++++++++++--- 2 files changed, 279 insertions(+), 24 deletions(-) diff --git a/public/script.js b/public/script.js index 0c491f74a..b3a558589 100644 --- a/public/script.js +++ b/public/script.js @@ -117,6 +117,7 @@ import { } from './scripts/nai-settings.js'; import { + initBookmarks, showBookmarksButtons, updateBookmarkDisplay, } from './scripts/bookmarks.js'; @@ -936,6 +937,7 @@ async function firstLoadInit() { initDynamicStyles(); initTags(); initOpenai(); + initBookmarks(); await getUserAvatars(true, user_avatar); await getCharacters(); await getBackgrounds(); diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 11cd70160..bfb6abf35 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -24,7 +24,12 @@ import { selected_group, } from './group-chats.js'; import { hideLoader, showLoader } from './loader.js'; +import { getLastMessageId } from './macros.js'; import { Popup } from './popup.js'; +import { SlashCommand } from './slash-commands/SlashCommand.js'; +import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; +import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; +import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; import { createTagMapFromList } from './tags.js'; import { @@ -51,10 +56,10 @@ async function getExistingChatNames() { } } -async function getBookmarkName() { +async function getBookmarkName({ forceName = null } = {}) { const chatNames = await getExistingChatNames(); - let name = await Popup.show.input('Create Checkpoint', 'Enter Checkpoint Name:(Leave empty to auto-generate)'); + let name = forceName || await Popup.show.input('Create Checkpoint', 'Enter Checkpoint Name:(Leave empty to auto-generate)'); if (name === null) { return null; } @@ -159,20 +164,26 @@ async function createBranch(mesId) { return name; } -export async function createNewBookmark(mesId) { +/** + * Creates a new bookmark for a message. + * + * @param {number} mesId - The ID of the message. + * @param {Object} [options={}] - Optional parameters. + * @param {string?} [options.forceName=null] - The name to force for the bookmark. + * @returns {Promise} - A promise that resolves to the bookmark name when the bookmark is created. + */ +export async function createNewBookmark(mesId, { forceName = null } = {}) { if (this_chid === undefined && !selected_group) { - toastr.info('No character selected.', 'Checkpoint creation aborted'); - return; + toastr.info('No character selected.', 'Create Checkpoint'); + return null; } - if (!chat.length) { - toastr.warning('The chat is empty.', 'Checkpoint creation failed'); - return; + toastr.warning('The chat is empty.', 'Create Checkpoint'); + return null; } - - if (mesId < 0 || mesId >= chat.length) { - toastr.warning('Invalid message ID.', 'Checkpoint creation failed'); - return; + if (!chat[mesId]) { + toastr.warning('Invalid message ID.', 'Create Checkpoint'); + return null; } const lastMes = chat[mesId]; @@ -181,16 +192,16 @@ export async function createNewBookmark(mesId) { lastMes.extra = {}; } - if (lastMes.extra.bookmark_link) { + if (lastMes.extra.bookmark_link && !forceName) { const confirm = await Popup.show.confirm('Replace Checkpoint', 'Checkpoint for the last message already exists.
Would you like to replace it?'); if (!confirm) { - return; + return null; } } - let name = await getBookmarkName(); + let name = await getBookmarkName({ forceName: forceName }); if (!name) { - return; + return null; } const mainChat = selected_group ? groups?.find(x => x.id == selected_group)?.chat_id : characters[this_chid].chat; @@ -209,7 +220,8 @@ export async function createNewBookmark(mesId) { updateBookmarkDisplay(mes, name); await saveChatConditional(); - toastr.success('Click the flag icon next to the message to open the checkpoint chat.', 'Checkpoint created', { timeOut: 10000 }); + toastr.success('Click the flag icon next to the message to open the checkpoint chat.', 'Create Checkpoint', { timeOut: 10000 }); + return name; } @@ -233,7 +245,10 @@ async function backToMainChat() { } else { await openCharacterChat(mainChatName); } + return mainChatName; } + + return null; } export async function convertSoloToGroupChat() { @@ -357,12 +372,12 @@ export async function convertSoloToGroupChat() { /** * Creates a new branch from the message with the given ID * @param {number} mesId Message ID - * @returns {Promise} Branch file name + * @returns {Promise} Branch file name */ export async function branchChat(mesId) { if (this_chid === undefined && !selected_group) { - toastr.info('No character selected.', 'Branch creation aborted'); - return; + toastr.info('No character selected.', 'Create Branch'); + return null; } const fileName = await createBranch(mesId); @@ -377,7 +392,243 @@ export async function branchChat(mesId) { return fileName; } -jQuery(function () { +function registerBookmarksSlashCommands() { + /** + * Validates a message ID. (Is a number, exists as a message) + * + * @param {number} mesId - The message ID to validate. + * @param {string} context - The context of the slash command. Will be used as the title of any toasts. + * @returns {boolean} - Returns true if the message ID is valid, otherwise false. + */ + function validateMessageId(mesId, context) { + if (isNaN(mesId)) { + toastr.warning('Invalid message ID was provided', context); + return false; + } + if (!chat[mesId]) { + toastr.warning(`Message for id ${mesId} not found`, context); + return false; + } + return true; + } + + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'branch-create', + returns: 'Name of the new branch', + callback: async (args, text) => { + const mesId = Number(args.mesId ?? text ?? getLastMessageId()); + if (!validateMessageId(mesId, 'Create Branch')) return ''; + + const branchName = await branchChat(mesId); + return branchName ?? ''; + }, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'mes', + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + helpString: ` +
+ Create a new branch from the selected message. If no message id is provided, will use the last message. +
+
+ Creating a branch will automatically choose a name for the branch.
+ After creating the branch, the branch chat will be automatically opened. +
+
+ Use Checkpoints and /checkpoint-create instead if you do not want to jump to the new chat. +
`, + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-create', + returns: 'Name of the new checkpoint', + callback: async (args, text) => { + const mesId = Number(args.mesId ?? getLastMessageId()); + if (!validateMessageId(mesId, 'Create Checkpoint')) return ''; + + if (!text || typeof text !== 'string') { + toastr.warning('Checkpoint name must be provided', 'Create Checkpoint'); + return ''; + } + + const checkPointName = await createNewBookmark(mesId, { forceName: text }); + return checkPointName ?? ''; + }, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'mes', + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Checkpoint name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + }), + ], + helpString: ` +
+ Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message. +
+
+ A created checkpoint will be permanently linked with the message.
+ If a checkpoint already exists, the link to it will be overwritten.
+ After creating the checkpoint, the checkpoint chat can be opened with the checkpoint flag, + using the /go command with the checkpoint name or the /checkpoint-go command on the message. +
+
+ Use Branches and /branch-create instead if you do want to jump to the new chat. +
+
+ Example: +
    +
  • +
    /checkpoint-create mes={{lastCharMessage}} Checkpoint for char reply | /setvar key=rememberCheckpoint {{pipe}}
    + Will create a new checkpoint to the latest message of the current character, and save it as a local variable for future use. +
  • +
+
`, + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-go', + returns: 'Name of the checkpoint', + callback: async (args, text) => { + const mesId = Number(args.mesId ?? text ?? getLastMessageId()); + if (!validateMessageId(mesId, 'Open Checkpoint')) return ''; + + const checkPointName = chat[mesId].extra?.bookmark_link; + if (!checkPointName) { + toastr.warning('No checkpoint is linked to the selected message', 'Open Checkpoint'); + return ''; + } + + if (selected_group) { + await openGroupChat(selected_group, checkPointName); + } else { + await openCharacterChat(checkPointName); + } + + return checkPointName; + }, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'mes', + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + helpString: ` +
+ Open the checkpoint linked to the selected message. If no message id is provided, will use the last message. +
+
+ Use /checkpoint-get if you want to make sure that the selected message has a checkpoint. +
`, + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-exit', + returns: 'The name of the chat exited to. Returns null if not in a checkpoint chat.', + callback: async () => { + const mainChat = await backToMainChat(); + return mainChat ?? ''; + }, + helpString: 'Exit the checkpoint chat.
If not in a checkpoint chat, returns null.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-parent', + returns: 'Name of the parent chat for this checkpoint', + callback: async () => { + const mainChatName = getMainChatName(); + return mainChatName ?? ''; + }, + helpString: 'Get the name of the parent chat for this checkpoint. If not in a checkpoint chat, returns null.', + })) + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-get', + returns: 'Name of the chat', + callback: async (args, text) => { + const mesId = Number(args.mesId ?? text ?? getLastMessageId()); + if (!validateMessageId(mesId, 'Get Checkpoint')) return ''; + + const checkPointName = chat[mesId].extra?.bookmark_link; + return checkPointName ?? ''; + }, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'mes', + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Message ID', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages(), + }), + ], + helpString: ` +
+ Get the name of the checkpoint linked to the selected message. If no message id is provided, will use the last message.
+ If no checkpoint is linked, the result will be empty. +
`, + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'checkpoint-list', + returns: 'JSON array of all existing checkpoints in this chat, as an array', + /** @param {{links?: string}} args @returns {Promise} */ + callback: async (args, _) => { + const result = []; + for (const mesId in chat) { + if (chat[mesId].extra?.bookmark_link) { + result.push(args.links ? chat[mesId].extra.bookmark_link : Number(mesId)); + } + } + return JSON.stringify(result); + }, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'links', + description: 'Get a list of all links / chat names of the checkpoints, instead of the message ids', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), + ], + helpString: ` +
+ List all existing checkpoints in this chat. +
+
+ Returns a list of all message ids that have a checkpoint, or all checkpoint links if links is set to true.
+ The value will be a JSON array. +
`, + })); +} + +export function initBookmarks() { $('#option_new_bookmark').on('click', saveBookmarkMenu); $('#option_back_to_main').on('click', backToMainChat); $('#option_convert_to_group').on('click', convertSoloToGroupChat); @@ -386,7 +637,7 @@ jQuery(function () { // If shift is held down, we are not following the bookmark, but creating a new one if (e.shiftKey) { var selectedMesId = $(this).closest('.mes').attr('mesid'); - await createNewBookmark(selectedMesId); + await createNewBookmark(Number(selectedMesId)); return; } @@ -416,7 +667,7 @@ jQuery(function () { $(document).on('click', '.mes_create_bookmark', async function () { var selected_mes_id = $(this).closest('.mes').attr('mesid'); if (selected_mes_id !== undefined) { - await createNewBookmark(selected_mes_id); + await createNewBookmark(Number(selected_mes_id)); } }); @@ -426,4 +677,6 @@ jQuery(function () { await branchChat(Number(selected_mes_id)); } }); -}); + + registerBookmarksSlashCommands(); +} From 95dd58ad95e76eaf3a12bb9ed2835a1679904a85 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:33:02 +0300 Subject: [PATCH 09/20] Don't use classic Mac line endings --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index abd24c436..9c83bd0c7 100644 --- a/public/index.html +++ b/public/index.html @@ -5777,7 +5777,7 @@
-
+
From 5ab781ab3011556643e037b6a6a11a7d17ecade2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:33:52 +0300 Subject: [PATCH 10/20] Unbreak timelines --- public/scripts/bookmarks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index bfb6abf35..3305e9c22 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -131,7 +131,8 @@ async function saveBookmarkMenu() { return await createNewBookmark(chat.length - 1); } -async function createBranch(mesId) { +// Export is used by Timelines extension. Do not remove. +export async function createBranch(mesId) { if (!chat.length) { toastr.warning('The chat is empty.', 'Branch creation failed'); return; From 27e0905a1bf9943192c69c5fcb081882f5fa77ee Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 10 Sep 2024 21:06:31 +0200 Subject: [PATCH 11/20] Changes based on code review --- public/scripts/bookmarks.js | 50 +++++-------------- .../scripts/templates/createCheckpoint.html | 1 + 2 files changed, 14 insertions(+), 37 deletions(-) create mode 100644 public/scripts/templates/createCheckpoint.html diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 3305e9c22..eb73eb814 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -31,6 +31,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; import { createTagMapFromList } from './tags.js'; +import { renderTemplateAsync } from './templates.js'; import { getUniqueName, @@ -59,7 +60,8 @@ async function getExistingChatNames() { async function getBookmarkName({ forceName = null } = {}) { const chatNames = await getExistingChatNames(); - let name = forceName || await Popup.show.input('Create Checkpoint', 'Enter Checkpoint Name:(Leave empty to auto-generate)'); + const body = await renderTemplateAsync('createCheckpoint'); + let name = forceName || await Popup.show.input('Create Checkpoint', body); if (name === null) { return null; } @@ -233,7 +235,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) { */ export function updateBookmarkDisplay(mes, newBookmarkLink = null) { newBookmarkLink && mes.attr('bookmark_link', newBookmarkLink); - mes.find('.mes_bookmark').attr('title', `Checkpoint\n${mes.attr('bookmark_link')}\n\n${mes.find('.mes_bookmark').data('tooltip')}`); + const bookmarkFlag = mes.find('.mes_bookmark'); + bookmarkFlag.attr('title', `Checkpoint\n${mes.attr('bookmark_link')}\n\n${bookmarkFlag.data('tooltip')}`); } async function backToMainChat() { @@ -423,14 +426,6 @@ function registerBookmarksSlashCommands() { const branchName = await branchChat(mesId); return branchName ?? ''; }, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'mes', - description: 'Message ID', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages(), - }), - ], unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'Message ID', @@ -524,14 +519,6 @@ function registerBookmarksSlashCommands() { return checkPointName; }, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'mes', - description: 'Message ID', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages(), - }), - ], unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'Message ID', @@ -549,12 +536,12 @@ function registerBookmarksSlashCommands() { })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'checkpoint-exit', - returns: 'The name of the chat exited to. Returns null if not in a checkpoint chat.', + returns: 'The name of the chat exited to. Returns an empty string if not in a checkpoint chat.', callback: async () => { const mainChat = await backToMainChat(); return mainChat ?? ''; }, - helpString: 'Exit the checkpoint chat.
If not in a checkpoint chat, returns null.', + helpString: 'Exit the checkpoint chat.
If not in a checkpoint chat, returns empty string.', })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'checkpoint-parent', @@ -563,8 +550,8 @@ function registerBookmarksSlashCommands() { const mainChatName = getMainChatName(); return mainChatName ?? ''; }, - helpString: 'Get the name of the parent chat for this checkpoint. If not in a checkpoint chat, returns null.', - })) + helpString: 'Get the name of the parent chat for this checkpoint.
If not in a checkpoint chat, returns empty string.', + })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'checkpoint-get', returns: 'Name of the chat', @@ -575,14 +562,6 @@ function registerBookmarksSlashCommands() { const checkPointName = chat[mesId].extra?.bookmark_link; return checkPointName ?? ''; }, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'mes', - description: 'Message ID', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages(), - }), - ], unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'Message ID', @@ -601,12 +580,9 @@ function registerBookmarksSlashCommands() { returns: 'JSON array of all existing checkpoints in this chat, as an array', /** @param {{links?: string}} args @returns {Promise} */ callback: async (args, _) => { - const result = []; - for (const mesId in chat) { - if (chat[mesId].extra?.bookmark_link) { - result.push(args.links ? chat[mesId].extra.bookmark_link : Number(mesId)); - } - } + const result = Object.entries(chat) + .filter(([_, message]) => message.extra?.bookmark_link) + .map(([mesId, message]) => args.links ? message.extra.bookmark_link : Number(mesId)); return JSON.stringify(result); }, namedArgumentList: [ @@ -634,7 +610,7 @@ export function initBookmarks() { $('#option_back_to_main').on('click', backToMainChat); $('#option_convert_to_group').on('click', convertSoloToGroupChat); - $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) { + $(document).on('click', '.select_chat_block, .mes_bookmark', async function (e) { // If shift is held down, we are not following the bookmark, but creating a new one if (e.shiftKey) { var selectedMesId = $(this).closest('.mes').attr('mesid'); diff --git a/public/scripts/templates/createCheckpoint.html b/public/scripts/templates/createCheckpoint.html new file mode 100644 index 000000000..4db900deb --- /dev/null +++ b/public/scripts/templates/createCheckpoint.html @@ -0,0 +1 @@ +Enter Checkpoint Name:(Leave empty to auto-generate) \ No newline at end of file From 748005b903600fab5f7718e77e145781a5044afa Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 10 Sep 2024 21:19:35 +0200 Subject: [PATCH 12/20] Remove unnecessary double popup for replace --- public/scripts/bookmarks.js | 13 ++++--------- public/scripts/templates/createCheckpoint.html | 9 ++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index eb73eb814..fa74e7295 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -57,10 +57,10 @@ async function getExistingChatNames() { } } -async function getBookmarkName({ forceName = null } = {}) { +async function getBookmarkName({ isReplace = false, forceName = null } = {}) { const chatNames = await getExistingChatNames(); - const body = await renderTemplateAsync('createCheckpoint'); + const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace }); let name = forceName || await Popup.show.input('Create Checkpoint', body); if (name === null) { return null; @@ -195,14 +195,9 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) { lastMes.extra = {}; } - if (lastMes.extra.bookmark_link && !forceName) { - const confirm = await Popup.show.confirm('Replace Checkpoint', 'Checkpoint for the last message already exists.
Would you like to replace it?'); - if (!confirm) { - return null; - } - } + const isReplace = lastMes.extra.bookmark_link; - let name = await getBookmarkName({ forceName: forceName }); + let name = await getBookmarkName({ isReplace: isReplace, forceName: forceName }); if (!name) { return null; } diff --git a/public/scripts/templates/createCheckpoint.html b/public/scripts/templates/createCheckpoint.html index 4db900deb..98e9bd08b 100644 --- a/public/scripts/templates/createCheckpoint.html +++ b/public/scripts/templates/createCheckpoint.html @@ -1 +1,8 @@ -Enter Checkpoint Name:(Leave empty to auto-generate) \ No newline at end of file +
+ Enter Checkpoint Name:(Leave empty to auto-generate) +
+{{#if isReplace}} +
+ The currently existing checkpoint will be unlinked and replaced with the new checkpoint, but can still be found in the Chat Management. +
+{{/if}} From 73c14711e1b80addf23d0cca4d3bcc12a275cd13 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Thu, 12 Sep 2024 23:34:37 +0200 Subject: [PATCH 13/20] Fix checkpoint create auto generate (and more) - Fix empty checkpoint name on mes click to auto generate - Change /checkpoint-create to not require name and auto generate - Fix popup input type returning empty string instead of null on empty input field --- public/scripts/bookmarks.js | 19 ++++++++++--------- public/scripts/popup.js | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index fa74e7295..5425de5ec 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -61,11 +61,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) { const chatNames = await getExistingChatNames(); const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace }); - let name = forceName || await Popup.show.input('Create Checkpoint', body); - if (name === null) { - return null; - } - else if (name === '') { + let name = forceName ?? await Popup.show.input('Create Checkpoint', body); + // Special handling for confirmed empty input (=> auto-generate name) + if (name === '') { for (let i = chatNames.length; i < 1000; i++) { name = bookmarkNameToken + i; if (!chatNames.includes(name)) { @@ -73,6 +71,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) { } } } + if (!name) { + return null; + } return `${name} - ${humanizedDateTime()}`; } @@ -447,8 +448,8 @@ function registerBookmarksSlashCommands() { const mesId = Number(args.mesId ?? getLastMessageId()); if (!validateMessageId(mesId, 'Create Checkpoint')) return ''; - if (!text || typeof text !== 'string') { - toastr.warning('Checkpoint name must be provided', 'Create Checkpoint'); + if (typeof text !== 'string') { + toastr.warning('Checkpoint name must be a string or empty', 'Create Checkpoint'); return ''; } @@ -467,12 +468,12 @@ function registerBookmarksSlashCommands() { SlashCommandArgument.fromProps({ description: 'Checkpoint name', typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, }), ], helpString: `
- Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message. + Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message.
+ Leave the checkpoint name empty to auto-generate one.
A created checkpoint will be permanently linked with the message.
diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 1a9d9ce36..226bc1c37 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -83,6 +83,9 @@ const showPopupHelper = { const content = PopupUtils.BuildTextWithHeader(header, text); const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions); const value = await popup.show(); + // Return values: If empty string, we explicitly handle that as returning that empty string as "success" provided. + // Otherwise, all non-truthy values (false, null, undefined) are treated as "cancel" and return null. + if (value === '') return ''; return value ? String(value) : null; }, From 084eebf6108d9645d056687552804982d1b854c6 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 20:28:19 +0300 Subject: [PATCH 14/20] Update /caption mesId argument name --- public/scripts/extensions/caption/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/extensions/caption/index.js b/public/scripts/extensions/caption/index.js index 7194abc49..3ec6b8470 100644 --- a/public/scripts/extensions/caption/index.js +++ b/public/scripts/extensions/caption/index.js @@ -358,10 +358,10 @@ function onRefineModeInput() { */ async function captionCommandCallback(args, prompt) { const quiet = isTrueBoolean(args?.quiet); - const id = args?.id; + const mesId = args?.mesId ?? args?.id; - if (!isNaN(Number(id))) { - const message = getContext().chat[id]; + if (!isNaN(Number(mesId))) { + const message = getContext().chat[mesId]; if (message?.extra?.image) { try { const fetchResult = await fetch(message.extra.image); @@ -546,7 +546,7 @@ jQuery(async function () { 'quiet', 'suppress sending a captioned message', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ), SlashCommandNamedArgument.fromProps({ - name: 'id', + name: 'mesId', description: 'get image from a message with this ID', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages(), From dc7bc30f4bd29034e0cb664cbcffa39fe8d4e62f Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 13 Sep 2024 19:29:54 +0200 Subject: [PATCH 15/20] Fix /checkpoint-create "mesId" argument --- public/scripts/bookmarks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 5425de5ec..cfd62dcc3 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -458,7 +458,7 @@ function registerBookmarksSlashCommands() { }, namedArgumentList: [ SlashCommandNamedArgument.fromProps({ - name: 'mes', + name: 'mesId', description: 'Message ID', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages(), From fefa6a0f5ba1b40c926c1295befddd55b674232a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 20:31:50 +0300 Subject: [PATCH 16/20] Update old code style --- public/scripts/bookmarks.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index cfd62dcc3..5d58ac7c9 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -609,25 +609,25 @@ export function initBookmarks() { $(document).on('click', '.select_chat_block, .mes_bookmark', async function (e) { // If shift is held down, we are not following the bookmark, but creating a new one if (e.shiftKey) { - var selectedMesId = $(this).closest('.mes').attr('mesid'); + const selectedMesId = $(this).closest('.mes').attr('mesid'); await createNewBookmark(Number(selectedMesId)); return; } - let file_name = $(this).hasClass('mes_bookmark') + const fileName = $(this).hasClass('mes_bookmark') ? $(this).closest('.mes').attr('bookmark_link') : $(this).attr('file_name').replace('.jsonl', ''); - if (!file_name) { + if (!fileName) { return; } try { showLoader(); if (selected_group) { - await openGroupChat(selected_group, file_name); + await openGroupChat(selected_group, fileName); } else { - await openCharacterChat(file_name); + await openCharacterChat(fileName); } } finally { await hideLoader(); @@ -638,16 +638,16 @@ export function initBookmarks() { }); $(document).on('click', '.mes_create_bookmark', async function () { - var selected_mes_id = $(this).closest('.mes').attr('mesid'); - if (selected_mes_id !== undefined) { - await createNewBookmark(Number(selected_mes_id)); + const mesId = $(this).closest('.mes').attr('mesid'); + if (mesId !== undefined) { + await createNewBookmark(Number(mesId)); } }); $(document).on('click', '.mes_create_branch', async function () { - var selected_mes_id = $(this).closest('.mes').attr('mesid'); - if (selected_mes_id !== undefined) { - await branchChat(Number(selected_mes_id)); + const mesId = $(this).closest('.mes').attr('mesid'); + if (mesId !== undefined) { + await branchChat(Number(mesId)); } }); From 6257f8b7f9f4a72c0ee33b1d4ff02d481445afb8 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 13 Sep 2024 19:44:06 +0200 Subject: [PATCH 17/20] Fix /checkpoints-list with ids --- public/scripts/bookmarks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 5d58ac7c9..08d75879b 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -35,6 +35,7 @@ import { renderTemplateAsync } from './templates.js'; import { getUniqueName, + isTrueBoolean, } from './utils.js'; const bookmarkNameToken = 'Checkpoint #'; @@ -578,7 +579,7 @@ function registerBookmarksSlashCommands() { callback: async (args, _) => { const result = Object.entries(chat) .filter(([_, message]) => message.extra?.bookmark_link) - .map(([mesId, message]) => args.links ? message.extra.bookmark_link : Number(mesId)); + .map(([mesId, message]) => isTrueBoolean(args.links) ? message.extra.bookmark_link : Number(mesId)); return JSON.stringify(result); }, namedArgumentList: [ From a13d3f643c7a8cc52761f36a128710152118b055 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:35:42 +0300 Subject: [PATCH 18/20] Fix shift+click in chat manager --- public/scripts/bookmarks.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 08d75879b..7ce811b9d 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -609,8 +609,9 @@ export function initBookmarks() { $(document).on('click', '.select_chat_block, .mes_bookmark', async function (e) { // If shift is held down, we are not following the bookmark, but creating a new one - if (e.shiftKey) { - const selectedMesId = $(this).closest('.mes').attr('mesid'); + const mes = $(this).closest('.mes'); + if (e.shiftKey && mes.length) { + const selectedMesId = mes.attr('mesid'); await createNewBookmark(Number(selectedMesId)); return; } From 01b83f893bcfb474ef9f01d36a68c3289603645b Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:48:35 +0300 Subject: [PATCH 19/20] Fix translation key removal --- public/scripts/extensions/translate/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/public/scripts/extensions/translate/index.js b/public/scripts/extensions/translate/index.js index e170795ee..c58ef9f08 100644 --- a/public/scripts/extensions/translate/index.js +++ b/public/scripts/extensions/translate/index.js @@ -598,9 +598,20 @@ jQuery(async () => { $(document).on('click', '.mes_translate', onMessageTranslateClick); $('#translate_key_button').on('click', async () => { const optionText = $('#translation_provider option:selected').text(); - const key = await callGenericPopup(`

${optionText} API Key

`, POPUP_TYPE.INPUT); + const key = await callGenericPopup(`

${optionText} API Key

`, POPUP_TYPE.INPUT, '', { + customButtons: [{ + text: 'Remove Key', + appendAtEnd: true, + result: POPUP_RESULT.NEGATIVE, + action: async () => { + await writeSecret(extension_settings.translate.provider, ''); + toastr.success('API Key removed'); + $('#translate_key_button').toggleClass('success', !!secret_state[extension_settings.translate.provider]); + }, + }], + }); - if (key == false) { + if (!key) { return; } @@ -634,7 +645,7 @@ jQuery(async () => { }], }); - if (url == false || url == '') { + if (!url) { return; } From 0ed39d19eccf68ecd2c8f93449cd234c9b65453b Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:51:05 +0300 Subject: [PATCH 20/20] Fix TTS falsy checks --- public/scripts/extensions/tts/azure.js | 4 ++-- public/scripts/extensions/tts/openai-compatible.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/extensions/tts/azure.js b/public/scripts/extensions/tts/azure.js index 967a6bf26..06d3d04cc 100644 --- a/public/scripts/extensions/tts/azure.js +++ b/public/scripts/extensions/tts/azure.js @@ -77,14 +77,14 @@ class AzureTtsProvider { result: POPUP_RESULT.NEGATIVE, action: async () => { await writeSecret(SECRET_KEYS.AZURE_TTS, ''); - $('#azure_tts_key').toggleClass('success', secret_state[SECRET_KEYS.AZURE_TTS]); + $('#azure_tts_key').toggleClass('success', !!secret_state[SECRET_KEYS.AZURE_TTS]); toastr.success('API Key removed'); await this.onRefreshClick(); }, }], }); - if (key == false || key == '') { + if (!key) { return; } diff --git a/public/scripts/extensions/tts/openai-compatible.js b/public/scripts/extensions/tts/openai-compatible.js index 26012056d..9b46d68ee 100644 --- a/public/scripts/extensions/tts/openai-compatible.js +++ b/public/scripts/extensions/tts/openai-compatible.js @@ -86,14 +86,14 @@ class OpenAICompatibleTtsProvider { result: POPUP_RESULT.NEGATIVE, action: async () => { await writeSecret(SECRET_KEYS.CUSTOM_OPENAI_TTS, ''); - $('#openai_compatible_tts_key').toggleClass('success', secret_state[SECRET_KEYS.CUSTOM_OPENAI_TTS]); + $('#openai_compatible_tts_key').toggleClass('success', !!secret_state[SECRET_KEYS.CUSTOM_OPENAI_TTS]); toastr.success('API Key removed'); await this.onRefreshClick(); }, }], }); - if (key == false || key == '') { + if (!key) { return; }