feat: Apply preset regexes before scoped regexes + avoid unnecessary popping up (#4672) * feat: apply preset regexes before scoped regexes * feat: apply preset regexes before scoped regexes for debugger list * fix: don't notify reload regexes when save preset through ui button * docs: add comment for SCRIPT_TYPES order * fix: updatePreset is wrongly reset preset
Signed| @@ -12,14 +12,14 @@ | ||
| 12 | 12 | <i class="fa-solid fa-pen-to-square"></i> |
| 13 | 13 | <small data-i18n="ext_regex_new_global_script">+ Global</small> |
| 14 | 14 | </div> |
| 15 | - <div id="open_scoped_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_scoped_script_desc" title="New scoped regex script"> | |
| 16 | - <i class="fa-solid fa-address-card"></i> | |
| 17 | - <small data-i18n="ext_regex_new_scoped_script">+ Scoped</small> | |
| 18 | - </div> | |
| 19 | 15 | <div id="open_preset_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_preset_script_desc" title="New preset regex script"> |
| 20 | 16 | <i class="fa-solid fa-sliders"></i> |
| 21 | 17 | <small data-i18n="ext_regex_new_preset_script">+ Preset</small> |
| 22 | 18 | </div> |
| 19 | + <div id="open_scoped_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_scoped_script_desc" title="New scoped regex script"> | |
| 20 | + <i class="fa-solid fa-address-card"></i> | |
| 21 | + <small data-i18n="ext_regex_new_scoped_script">+ Scoped</small> | |
| 22 | + </div> | |
| 23 | 23 | <div id="import_regex" class="menu_button menu_button_icon"> |
| 24 | 24 | <i class="fa-solid fa-file-import"></i> |
| 25 | 25 | <small data-i18n="ext_regex_import_script">Import</small> |
| @@ -52,14 +52,14 @@ | ||
| 52 | 52 | <i class="fa-solid fa-globe"></i> |
| 53 | 53 | <small data-i18n="ext_regex_move_to_global">Move to global scripts</small> |
| 54 | 54 | </div> |
| 55 | - <div id="bulk_regex_move_to_scoped" class="menu_button menu_button_icon" hidden> | |
| 56 | - <i class="fa-solid fa-address-card"></i> | |
| 57 | - <small data-i18n="ext_regex_move_to_scoped">Move to scoped scripts</small> | |
| 58 | - </div> | |
| 59 | 55 | <div id="bulk_regex_move_to_preset" class="menu_button menu_button_icon" hidden> |
| 60 | 56 | <i class="fa-solid fa-sliders"></i> |
| 61 | 57 | <small data-i18n="ext_regex_move_to_preset">Move to preset scripts</small> |
| 62 | 58 | </div> |
| 59 | + <div id="bulk_regex_move_to_scoped" class="menu_button menu_button_icon" hidden> | |
| 60 | + <i class="fa-solid fa-address-card"></i> | |
| 61 | + <small data-i18n="ext_regex_move_to_scoped">Move to scoped scripts</small> | |
| 62 | + </div> | |
| 63 | 63 | <div id="bulk_export_regex" class="menu_button menu_button_icon"> |
| 64 | 64 | <i class="fa-solid fa-file-export"></i> |
| 65 | 65 | <small data-i18n="Export">Export</small> |
| @@ -96,6 +96,21 @@ | ||
| 96 | 96 | <div id="saved_regex_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div> |
| 97 | 97 | </div> |
| 98 | 98 | <hr /> |
| 99 | + <div id="preset_scripts_block"> | |
| 100 | + <div class="flex-container alignItemsBaseline"> | |
| 101 | + <strong class="flex1" data-i18n="ext_regex_preset_scripts">Preset Scripts</strong> | |
| 102 | + <label id="toggle_preset_regex" class="checkbox flex-container" for="regex_preset_toggle"> | |
| 103 | + <input type="checkbox" id="regex_preset_toggle" class="enable_scoped" /> | |
| 104 | + <span class="regex-toggle-on fa-solid fa-toggle-on fa-lg" data-i18n="[title]ext_regex_disallow_preset" title="Disallow using preset regex"></span> | |
| 105 | + <span class="regex-toggle-off fa-solid fa-toggle-off fa-lg" data-i18n="[title]ext_regex_allow_preset" title="Allow using preset regex"></span> | |
| 106 | + </label> | |
| 107 | + </div> | |
| 108 | + <small data-i18n="ext_regex_preset_scripts_desc"> | |
| 109 | + Only available for this preset. Saved to the preset data. | |
| 110 | + </small> | |
| 111 | + <div id="saved_preset_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div> | |
| 112 | + </div> | |
| 113 | + <hr /> | |
| 99 | 114 | <div id="scoped_scripts_block"> |
| 100 | 115 | <div class="flex-container alignItemsBaseline"> |
| 101 | 116 | <strong class="flex1" data-i18n="ext_regex_scoped_scripts">Scoped Scripts</strong> |
| @@ -110,21 +125,6 @@ | ||
| 110 | 125 | </small> |
| 111 | 126 | <div id="saved_scoped_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div> |
| 112 | 127 | </div> |
| 113 | - <hr /> | |
| 114 | - <div id="preset_scripts_block"> | |
| 115 | - <div class="flex-container alignItemsBaseline"> | |
| 116 | - <strong class="flex1" data-i18n="ext_regex_preset_scripts">Preset Scripts</strong> | |
| 117 | - <label id="toggle_preset_regex" class="checkbox flex-container" for="regex_preset_toggle"> | |
| 118 | - <input type="checkbox" id="regex_preset_toggle" class="enable_scoped" /> | |
| 119 | - <span class="regex-toggle-on fa-solid fa-toggle-on fa-lg" data-i18n="[title]ext_regex_disallow_preset" title="Disallow using preset regex"></span> | |
| 120 | - <span class="regex-toggle-off fa-solid fa-toggle-off fa-lg" data-i18n="[title]ext_regex_allow_preset" title="Allow using preset regex"></span> | |
| 121 | - </label> | |
| 122 | - </div> | |
| 123 | - <small data-i18n="ext_regex_preset_scripts_desc"> | |
| 124 | - Only available for this preset. Saved to the preset data. | |
| 125 | - </small> | |
| 126 | - <div id="saved_preset_scripts" class="flex-container regex-script-container flexFlowColumn"></div> | |
| 127 | - </div> | |
| 128 | 128 | </div> |
| 129 | 129 | </div> |
| 130 | 130 | </div> |
| @@ -9,9 +9,10 @@ import { lodash } from '../../../lib.js'; | ||
| 9 | 9 | * @readonly |
| 10 | 10 | */ |
| 11 | 11 | export const SCRIPT_TYPES = { |
| 12 | + // ORDER MATTERS: defines the regex script priority | |
| 12 | 13 | GLOBAL: 0, |
| 13 | - SCOPED: 1, | |
| 14 | 14 | PRESET: 2, |
| 15 | + SCOPED: 1, | |
| 15 | 16 | }; |
| 16 | 17 | |
| 17 | 18 | /** |
| @@ -1088,7 +1088,7 @@ function populateDebuggerRuleList(container) { | ||
| 1088 | 1088 | } |
| 1089 | 1089 | }); |
| 1090 | 1090 | |
| 1091 | 1091 | container.data('allScripts', [...globalScripts, ...scopedScriptspresetScripts, ...presetScriptsscopedScripts]); |
| 1092 | 1092 | |
| 1093 | 1093 | const renderRule = (script) => { |
| 1094 | 1094 | if (!script.id) script.id = uuidv4(); |
| @@ -1147,19 +1147,19 @@ function populateDebuggerRuleList(container) { | ||
| 1147 | 1147 | rulesContainer.append(globalList); |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - if (scopedScripts.length > 0) { | |
| 1151 | - rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Scoped Rules` + '</div>'); | |
| 1152 | - const scopedList = $('<ul id="regex_debugger_rules_scoped" class="sortable-list"></ul>'); | |
| 1153 | - scopedScripts.forEach(script => scopedList.append(renderRule(script))); | |
| 1154 | - rulesContainer.append(scopedList); | |
| 1155 | - } | |
| 1156 | - | |
| 1157 | 1150 | if (presetScripts.length > 0) { |
| 1158 | 1151 | rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Preset Rules` + '</div>'); |
| 1159 | 1152 | const presetList = $('<ul id="regex_debugger_rules_preset" class="sortable-list"></ul>'); |
| 1160 | 1153 | presetScripts.forEach(script => presetList.append(renderRule(script))); |
| 1161 | 1154 | rulesContainer.append(presetList); |
| 1162 | 1155 | } |
| 1156 | + | |
| 1157 | + if (scopedScripts.length > 0) { | |
| 1158 | + rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Scoped Rules` + '</div>'); | |
| 1159 | + const scopedList = $('<ul id="regex_debugger_rules_scoped" class="sortable-list"></ul>'); | |
| 1160 | + scopedScripts.forEach(script => scopedList.append(renderRule(script))); | |
| 1161 | + rulesContainer.append(scopedList); | |
| 1162 | + } | |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | /** |
| @@ -16,12 +16,12 @@ | ||
| 16 | 16 | <div class="move_to_global menu_button" data-i18n="[title]ext_regex_move_to_global" title="Move to global scripts"> |
| 17 | 17 | <i class="fa-solid fa-globe"></i> |
| 18 | 18 | </div> |
| 19 | - <div class="move_to_scoped menu_button" data-i18n="[title]ext_regex_move_to_scoped" title="Move to scoped scripts"> | |
| 20 | - <i class="fa-solid fa-address-card"></i> | |
| 21 | - </div> | |
| 22 | 19 | <div class="move_to_preset menu_button" data-i18n="[title]ext_regex_move_to_preset" title="Move to preset scripts"> |
| 23 | 20 | <i class="fa-solid fa-sliders"></i> |
| 24 | 21 | </div> |
| 22 | + <div class="move_to_scoped menu_button" data-i18n="[title]ext_regex_move_to_scoped" title="Move to scoped scripts"> | |
| 23 | + <i class="fa-solid fa-address-card"></i> | |
| 24 | + </div> | |
| 25 | 25 | <div class="export_regex menu_button" data-i18n="[title]ext_regex_export_script" title="Export script"> |
| 26 | 26 | <i class="fa-solid fa-file-export"></i> |
| 27 | 27 | </div> |
| @@ -6275,7 +6275,7 @@ export function initOpenAI() { | ||
| 6275 | 6275 | |
| 6276 | 6276 | $('#update_oai_preset').on('click', async function () { |
| 6277 | 6277 | const name = oai_settings.preset_settings_openai; |
| 6278 | 6278 | await saveOpenAIPreset(name, oai_settings, false); |
| 6279 | 6279 | toastr.success(t`Preset updated`); |
| 6280 | 6280 | }); |
| 6281 | 6281 | |
| @@ -19,12 +19,14 @@ import { | ||
| 19 | 19 | this_chid, |
| 20 | 20 | } from '../script.js'; |
| 21 | 21 | import { groups, selected_group } from './group-chats.js'; |
| 22 | +import { t } from './i18n.js'; | |
| 22 | 23 | import { instruct_presets } from './instruct-mode.js'; |
| 23 | 24 | import { kai_settings } from './kai-settings.js'; |
| 24 | 25 | import { convertNovelPreset } from './nai-settings.js'; |
| 25 | 26 | import { openai_settingsoai_settings, openai_setting_names, oai_settingsopenai_settings } from './openai.js'; |
| 26 | 27 | import { Popup, POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js'; |
| 27 | 28 | import { context_presets, getContextSettings, power_user } from './power-user.js'; |
| 29 | +import { reasoning_templates } from './reasoning.js'; | |
| 28 | 30 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| 29 | 31 | import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; |
| 30 | 32 | import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| @@ -33,13 +35,11 @@ import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; | ||
| 33 | 35 | import { checkForSystemPromptInInstructTemplate, system_prompts } from './sysprompt.js'; |
| 34 | 36 | import { renderTemplateAsync } from './templates.js'; |
| 35 | 37 | import { |
| 38 | + textgenerationwebui_settings as textgen_settings, | |
| 36 | 39 | textgenerationwebui_preset_names, |
| 37 | 40 | textgenerationwebui_presets, |
| 38 | - textgenerationwebui_settings as textgen_settings, | |
| 39 | 41 | } from './textgen-settings.js'; |
| 40 | 42 | import { download, ensurePlainObject, equalsIgnoreCaseAndAccents, getSanitizedFilename, parseJsonFile, waitUntilCondition } from './utils.js'; |
| 41 | -import { t } from './i18n.js'; | |
| 42 | -import { reasoning_templates } from './reasoning.js'; | |
| 43 | 43 | |
| 44 | 44 | const presetManagers = {}; |
| 45 | 45 | |
| @@ -397,8 +397,10 @@ class PresetManager { | ||
| 397 | 397 | |
| 398 | 398 | /** |
| 399 | 399 | * Updates the preset select element with the current API presets. |
| 400 | + * @param {object} [options] Options for saving the preset | |
| 401 | + * @param {boolean} [options.skipUpdate=false] If true, skips updating the preset list after saving. | |
| 400 | 402 | */ |
| 401 | 403 | async updatePreset(option = { skipUpdate: false }) { |
| 402 | 404 | const selected = $(this.select).find('option:selected'); |
| 403 | 405 | console.log(selected); |
| 404 | 406 | |
| @@ -408,7 +410,7 @@ class PresetManager { | ||
| 408 | 410 | } |
| 409 | 411 | |
| 410 | 412 | const name = selected.text(); |
| 411 | 413 | await this.savePreset(name, null, option); |
| 412 | 414 | |
| 413 | 415 | const successToast = !this.isAdvancedFormatting() ? t`Preset updated` : t`Template updated`; |
| 414 | 416 | toastr.success(successToast); |
| @@ -1000,7 +1002,7 @@ export async function initPresetManager() { | ||
| 1000 | 1002 | return; |
| 1001 | 1003 | } |
| 1002 | 1004 | |
| 1003 | 1005 | await presetManager.updatePreset({ skipUpdate: true }); |
| 1004 | 1006 | }); |
| 1005 | 1007 | |
| 1006 | 1008 | $(document).on('click', '[data-preset-manager-new]', async function () { |