From 4e447a59b5ae0e4057f77c8a1b91d0e305fe6c70 Mon Sep 17 00:00:00 2001 From: Risenafis Date: Tue, 11 Jun 2024 00:21:05 +0900 Subject: [PATCH 1/7] fix sbvits2 auto splitting --- public/scripts/extensions/tts/sbvits2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/scripts/extensions/tts/sbvits2.js b/public/scripts/extensions/tts/sbvits2.js index ab41d4f6d..8b9a3bef3 100644 --- a/public/scripts/extensions/tts/sbvits2.js +++ b/public/scripts/extensions/tts/sbvits2.js @@ -276,6 +276,11 @@ class SBVits2TtsProvider { const [model_id, speaker_id, style] = voiceId.split('-'); const params = new URLSearchParams(); + if (this.settings.auto_split) { + // newlines are replaced with spaces + // so, revert for auto_split + inputText = inputText.replace(' ', '\n'); + } params.append('text', inputText); params.append('model_id', model_id); params.append('speaker_id', speaker_id); From 593f9b5832e663ea0927f897966a90a755eee156 Mon Sep 17 00:00:00 2001 From: Risenafis Date: Tue, 11 Jun 2024 01:17:35 +0900 Subject: [PATCH 2/7] fix sbvits2 auto splitting by backup/restore --- public/scripts/extensions/tts/sbvits2.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/public/scripts/extensions/tts/sbvits2.js b/public/scripts/extensions/tts/sbvits2.js index 8b9a3bef3..7f542ca6a 100644 --- a/public/scripts/extensions/tts/sbvits2.js +++ b/public/scripts/extensions/tts/sbvits2.js @@ -19,6 +19,8 @@ class SBVits2TtsProvider { * @returns {string} Processed text */ processText(text) { + // backup for auto_split + text = text.replace(/\n+/g, '
'); return text; } @@ -276,11 +278,8 @@ class SBVits2TtsProvider { const [model_id, speaker_id, style] = voiceId.split('-'); const params = new URLSearchParams(); - if (this.settings.auto_split) { - // newlines are replaced with spaces - // so, revert for auto_split - inputText = inputText.replace(' ', '\n'); - } + // restore for auto_split + inputText = inputText.replaceAll('
', '\n'); params.append('text', inputText); params.append('model_id', model_id); params.append('speaker_id', speaker_id); From 9fb9253dccd83d47a73d34affe43fa0a7581837c Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 11 Jun 2024 01:00:13 +0200 Subject: [PATCH 3/7] Update /persona slash command with arguments --- public/scripts/slash-commands.js | 52 +++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 6e29ea39e..67dda6d3f 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -84,15 +84,21 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ helpString: 'Get help on macros, chat formatting and commands.', })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'name', + name: 'persona', callback: setNameCallback, - unnamedArgumentList: [ - new SlashCommandArgument( - 'persona', [ARGUMENT_TYPE.STRING], true, + namedArgumentList: [ + new SlashCommandNamedArgument( + 'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)', + [ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'], ), ], - helpString: 'Sets user name and persona avatar (if set).', - aliases: ['persona'], + unnamedArgumentList: [ + new SlashCommandArgument( + 'persona name', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.', + aliases: ['name'], })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'sync', @@ -2372,26 +2378,44 @@ function setFlatModeCallback() { $('#chat_display').val(chat_styles.DEFAULT).trigger('change'); } -function setNameCallback(_, name) { +/** + * + * @param {{mode: 'lookup' | 'temp' | 'all'}} namedArgs + * @param {string} name + * @returns + */ +function setNameCallback({ mode = 'all' }, name) { if (!name) { toastr.warning('you must specify a name to change to'); return; } + if (!['lookup', 'temp', 'all'].includes(mode)) { + toastr.warning('mode must be one of "lookup", "temp" or "all"'); + return; + } + name = name.trim(); - // If the name is a persona, auto-select it - for (let persona of Object.values(power_user.personas)) { - if (persona.toLowerCase() === name.toLowerCase()) { - autoSelectPersona(name); + // If the name matches a persona avatar, or a name, auto-select it + if (['lookup', 'all'].includes(mode)) { + let persona = Object.entries(power_user.personas).find(([avatar, _]) => avatar === name)?.[1]; + if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1]; + if (persona) { + autoSelectPersona(persona); retriggerFirstMessageOnEmptyChat(); return; + } else if (mode === 'lookup') { + toastr.warning(`Persona ${name} not found`); + return; } } - // Otherwise, set just the name - setUserName(name); //this prevented quickReply usage - retriggerFirstMessageOnEmptyChat(); + if (['temp', 'all'].includes(mode)) { + // Otherwise, set just the name + setUserName(name); //this prevented quickReply usage + retriggerFirstMessageOnEmptyChat(); + } } async function setNarratorName(_, text) { From 679b3587b51015cf7775a7736344783c3d29e9cb Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 11 Jun 2024 02:54:06 +0200 Subject: [PATCH 4/7] Data attribute for the currently open menu_type - Add data attribute to the right nav panel for the currently open menu type - JSDoc of possible menu_type values - Refactor using the menu_type setter - Remove legacy "settings" menu type, as that one is not part of those really --- public/script.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/public/script.js b/public/script.js index 9f480f291..d8e58bac7 100644 --- a/public/script.js +++ b/public/script.js @@ -744,8 +744,19 @@ const per_page_default = 50; var is_advanced_char_open = false; -export let menu_type = ''; //what is selected in the menu +/** + * The type of the right menu + * @typedef {'characters' | 'character_edit' | 'create' | 'group_edit' | 'group_create' | '' } MenuType + */ + +/** + * The type of the right menu that is currently open + * @type {MenuType} + */ +export let menu_type = ''; + export let selected_button = ''; //which button pressed + //create pole save let create_save = { name: '', @@ -5408,8 +5419,14 @@ export function resetChatState() { characters.length = 0; } +/** + * + * @param {'characters' | 'character_edit' | 'create' | 'group_edit' | 'group_create'} value + */ export function setMenuType(value) { menu_type = value; + // Allow custom CSS to see which menu type is active + document.getElementById('right-nav-panel').dataset.menuType = menu_type; } export function setExternalAbortController(controller) { @@ -6791,7 +6808,7 @@ export function select_selected_character(chid) { //character select //console.log('select_selected_character() -- starting with input of -- ' + chid + ' (name:' + characters[chid].name + ')'); select_rm_create(); - menu_type = 'character_edit'; + setMenuType('character_edit'); $('#delete_button').css('display', 'flex'); $('#export_button').css('display', 'flex'); var display_name = characters[chid].name; @@ -6867,7 +6884,7 @@ export function select_selected_character(chid) { } function select_rm_create() { - menu_type = 'create'; + setMenuType('create'); //console.log('select_rm_Create() -- selected button: '+selected_button); if (selected_button == 'create') { @@ -6928,7 +6945,7 @@ function select_rm_create() { function select_rm_characters() { const doFullRefresh = menu_type === 'characters'; - menu_type = 'characters'; + setMenuType('characters'); selectRightMenuWithAnimation('rm_characters_block'); printCharacters(doFullRefresh); } @@ -8953,7 +8970,6 @@ jQuery(async function () { $('#rm_button_settings').click(function () { selected_button = 'settings'; - menu_type = 'settings'; selectRightMenuWithAnimation('rm_api_block'); }); $('#rm_button_characters').click(function () { From abed49c2778f5e3b5f4c1442a153924f3f8b01be Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 11 Jun 2024 09:55:37 +0300 Subject: [PATCH 5/7] JSDoc, toast capitalization --- public/scripts/slash-commands.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 67dda6d3f..6f7729ce9 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2379,19 +2379,19 @@ function setFlatModeCallback() { } /** - * - * @param {{mode: 'lookup' | 'temp' | 'all'}} namedArgs - * @param {string} name - * @returns + * Sets a persona name and optionally an avatar. + * @param {{mode: 'lookup' | 'temp' | 'all'}} namedArgs Named arguments + * @param {string} name Name to set + * @returns {void} */ function setNameCallback({ mode = 'all' }, name) { if (!name) { - toastr.warning('you must specify a name to change to'); + toastr.warning('You must specify a name to change to'); return; } if (!['lookup', 'temp', 'all'].includes(mode)) { - toastr.warning('mode must be one of "lookup", "temp" or "all"'); + toastr.warning('Mode must be one of "lookup", "temp" or "all"'); return; } From d69263923a34e86d7fc8022ac65523a4572bf257 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:37:00 +0300 Subject: [PATCH 6/7] Include emoji into trim to end sentence --- public/scripts/utils.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/public/scripts/utils.js b/public/scripts/utils.js index b192dd9f1..f688d5aa4 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -481,14 +481,16 @@ export function trimToEndSentence(input, include_newline = false) { return ''; } + const isEmoji = x => /(\p{Emoji_Presentation}|\p{Extended_Pictographic})/gu.test(x); const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '!', '?', '”', ')', '】', '’', '」', '_']); // extend this as you see fit let last = -1; - for (let i = input.length - 1; i >= 0; i--) { - const char = input[i]; + const characters = Array.from(input); + for (let i = characters.length - 1; i >= 0; i--) { + const char = characters[i]; - if (punctuation.has(char)) { - if (i > 0 && /[\s\n]/.test(input[i - 1])) { + if (punctuation.has(char) || isEmoji(char)) { + if (i > 0 && /[\s\n]/.test(characters[i - 1])) { last = i - 1; } else { last = i; @@ -506,7 +508,7 @@ export function trimToEndSentence(input, include_newline = false) { return input.trimEnd(); } - return input.substring(0, last + 1).trimEnd(); + return characters.slice(0, last + 1).join('').trimEnd(); } export function trimToStartSentence(input) { From 9c3176b29f93e9cd2e3e735654d5bc9f087b2f67 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:26:31 +0300 Subject: [PATCH 7/7] Preserve scroll position of the prompt manager --- public/scripts/PromptManager.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 806b5f308..dbf7dd4ed 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -685,6 +685,23 @@ class PromptManager { this.log('Initialized'); } + /** + * Get the scroll position of the prompt manager + * @returns {number} - Scroll position of the prompt manager + */ + #getScrollPosition() { + return document.getElementById(this.configuration.prefix + 'prompt_manager')?.closest('.scrollableInner')?.scrollTop; + } + + /** + * Set the scroll position of the prompt manager + * @param {number} scrollPosition - The scroll position to set + */ + #setScrollPosition(scrollPosition) { + if (scrollPosition === undefined || scrollPosition === null) return; + document.getElementById(this.configuration.prefix + 'prompt_manager')?.closest('.scrollableInner')?.scrollTo(0, scrollPosition); + } + /** * Main rendering function * @@ -703,17 +720,21 @@ class PromptManager { this.tryGenerate().finally(async () => { this.profileEnd('filling context'); this.profileStart('render'); + const scrollPosition = this.#getScrollPosition(); await this.renderPromptManager(); await this.renderPromptManagerListItems(); this.makeDraggable(); + this.#setScrollPosition(scrollPosition); this.profileEnd('render'); }); } else { // Executed during live communication this.profileStart('render'); + const scrollPosition = this.#getScrollPosition(); await this.renderPromptManager(); await this.renderPromptManagerListItems(); this.makeDraggable(); + this.#setScrollPosition(scrollPosition); this.profileEnd('render'); } }).catch(() => {