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

4bda4444e47640788ea72d7d18aece9940f86397

StageDog <aksanajw845@gmail.com>

Signed
6 files changed, +47 -44Showing whitespace changes
public/scripts/extensions/regex/dropdown.html+23 -23
@@ -12,14 +12,14 @@
12 <i class="fa-solid fa-pen-to-square"></i>12 <i class="fa-solid fa-pen-to-square"></i>
13 <small data-i18n="ext_regex_new_global_script">+ Global</small>13 <small data-i18n="ext_regex_new_global_script">+ Global</small>
14 </div>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 <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">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 <i class="fa-solid fa-sliders"></i>16 <i class="fa-solid fa-sliders"></i>
21 <small data-i18n="ext_regex_new_preset_script">+ Preset</small>17 <small data-i18n="ext_regex_new_preset_script">+ Preset</small>
22 </div>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 <div id="import_regex" class="menu_button menu_button_icon">23 <div id="import_regex" class="menu_button menu_button_icon">
24 <i class="fa-solid fa-file-import"></i>24 <i class="fa-solid fa-file-import"></i>
25 <small data-i18n="ext_regex_import_script">Import</small>25 <small data-i18n="ext_regex_import_script">Import</small>
@@ -52,14 +52,14 @@
52 <i class="fa-solid fa-globe"></i>52 <i class="fa-solid fa-globe"></i>
53 <small data-i18n="ext_regex_move_to_global">Move to global scripts</small>53 <small data-i18n="ext_regex_move_to_global">Move to global scripts</small>
54 </div>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 <div id="bulk_regex_move_to_preset" class="menu_button menu_button_icon" hidden>55 <div id="bulk_regex_move_to_preset" class="menu_button menu_button_icon" hidden>
60 <i class="fa-solid fa-sliders"></i>56 <i class="fa-solid fa-sliders"></i>
61 <small data-i18n="ext_regex_move_to_preset">Move to preset scripts</small>57 <small data-i18n="ext_regex_move_to_preset">Move to preset scripts</small>
62 </div>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 <div id="bulk_export_regex" class="menu_button menu_button_icon">63 <div id="bulk_export_regex" class="menu_button menu_button_icon">
64 <i class="fa-solid fa-file-export"></i>64 <i class="fa-solid fa-file-export"></i>
65 <small data-i18n="Export">Export</small>65 <small data-i18n="Export">Export</small>
@@ -96,6 +96,21 @@
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>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 </div>97 </div>
98 <hr />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 <div id="scoped_scripts_block">114 <div id="scoped_scripts_block">
100 <div class="flex-container alignItemsBaseline">115 <div class="flex-container alignItemsBaseline">
101 <strong class="flex1" data-i18n="ext_regex_scoped_scripts">Scoped Scripts</strong>116 <strong class="flex1" data-i18n="ext_regex_scoped_scripts">Scoped Scripts</strong>
@@ -110,21 +125,6 @@
110 </small>125 </small>
111 <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>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 </div>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 </div>128 </div>
129 </div>129 </div>
130</div>130</div>
public/scripts/extensions/regex/engine.js+2 -1
@@ -9,9 +9,10 @@ import { lodash } from '../../../lib.js';
9 * @readonly9 * @readonly
10 */10 */
11export const SCRIPT_TYPES = {11export const SCRIPT_TYPES = {
12 // ORDER MATTERS: defines the regex script priority
12 GLOBAL: 0,13 GLOBAL: 0,
13 SCOPED: 1,
14 PRESET: 2,14 PRESET: 2,
15 SCOPED: 1,
15};16};
1617
17/**18/**
public/scripts/extensions/regex/index.js+8 -8
@@ -1088,7 +1088,7 @@ function populateDebuggerRuleList(container) {
1088 }1088 }
1089 });1089 });
10901090
1091 container.data('allScripts', [...globalScripts, ...scopedScripts, ...presetScripts]);1091 container.data('allScripts', [...globalScripts, ...presetScripts, ...scopedScripts]);
10921092
1093 const renderRule = (script) => {1093 const renderRule = (script) => {
1094 if (!script.id) script.id = uuidv4();1094 if (!script.id) script.id = uuidv4();
@@ -1147,19 +1147,19 @@ function populateDebuggerRuleList(container) {
1147 rulesContainer.append(globalList);1147 rulesContainer.append(globalList);
1148 }1148 }
11491149
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 if (presetScripts.length > 0) {1150 if (presetScripts.length > 0) {
1158 rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Preset Rules` + '</div>');1151 rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Preset Rules` + '</div>');
1159 const presetList = $('<ul id="regex_debugger_rules_preset" class="sortable-list"></ul>');1152 const presetList = $('<ul id="regex_debugger_rules_preset" class="sortable-list"></ul>');
1160 presetScripts.forEach(script => presetList.append(renderRule(script)));1153 presetScripts.forEach(script => presetList.append(renderRule(script)));
1161 rulesContainer.append(presetList);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}
11641164
1165/**1165/**
public/scripts/extensions/regex/scriptTemplate.html+3 -3
@@ -16,12 +16,12 @@
16 <div class="move_to_global menu_button" data-i18n="[title]ext_regex_move_to_global" title="Move to global scripts">16 <div class="move_to_global menu_button" data-i18n="[title]ext_regex_move_to_global" title="Move to global scripts">
17 <i class="fa-solid fa-globe"></i>17 <i class="fa-solid fa-globe"></i>
18 </div>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 <div class="move_to_preset menu_button" data-i18n="[title]ext_regex_move_to_preset" title="Move to preset scripts">19 <div class="move_to_preset menu_button" data-i18n="[title]ext_regex_move_to_preset" title="Move to preset scripts">
23 <i class="fa-solid fa-sliders"></i>20 <i class="fa-solid fa-sliders"></i>
24 </div>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 <div class="export_regex menu_button" data-i18n="[title]ext_regex_export_script" title="Export script">25 <div class="export_regex menu_button" data-i18n="[title]ext_regex_export_script" title="Export script">
26 <i class="fa-solid fa-file-export"></i>26 <i class="fa-solid fa-file-export"></i>
27 </div>27 </div>
public/scripts/openai.js+1 -1
@@ -6275,7 +6275,7 @@ export function initOpenAI() {
62756275
6276 $('#update_oai_preset').on('click', async function () {6276 $('#update_oai_preset').on('click', async function () {
6277 const name = oai_settings.preset_settings_openai;6277 const name = oai_settings.preset_settings_openai;
6278 await saveOpenAIPreset(name, oai_settings);6278 await saveOpenAIPreset(name, oai_settings, false);
6279 toastr.success(t`Preset updated`);6279 toastr.success(t`Preset updated`);
6280 });6280 });
62816281
public/scripts/preset-manager.js+10 -8
@@ -19,12 +19,14 @@ import {
19 this_chid,19 this_chid,
20} from '../script.js';20} from '../script.js';
21import { groups, selected_group } from './group-chats.js';21import { groups, selected_group } from './group-chats.js';
22import { t } from './i18n.js';
22import { instruct_presets } from './instruct-mode.js';23import { instruct_presets } from './instruct-mode.js';
23import { kai_settings } from './kai-settings.js';24import { kai_settings } from './kai-settings.js';
24import { convertNovelPreset } from './nai-settings.js';25import { convertNovelPreset } from './nai-settings.js';
25import { openai_settings, openai_setting_names, oai_settings } from './openai.js';26import { oai_settings, openai_setting_names, openai_settings } from './openai.js';
26import { Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';27import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
27import { context_presets, getContextSettings, power_user } from './power-user.js';28import { context_presets, getContextSettings, power_user } from './power-user.js';
29import { reasoning_templates } from './reasoning.js';
28import { SlashCommand } from './slash-commands/SlashCommand.js';30import { SlashCommand } from './slash-commands/SlashCommand.js';
29import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';31import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
30import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';32import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
@@ -33,13 +35,11 @@ import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
33import { checkForSystemPromptInInstructTemplate, system_prompts } from './sysprompt.js';35import { checkForSystemPromptInInstructTemplate, system_prompts } from './sysprompt.js';
34import { renderTemplateAsync } from './templates.js';36import { renderTemplateAsync } from './templates.js';
35import {37import {
38 textgenerationwebui_settings as textgen_settings,
36 textgenerationwebui_preset_names,39 textgenerationwebui_preset_names,
37 textgenerationwebui_presets,40 textgenerationwebui_presets,
38 textgenerationwebui_settings as textgen_settings,
39} from './textgen-settings.js';41} from './textgen-settings.js';
40import { download, ensurePlainObject, equalsIgnoreCaseAndAccents, getSanitizedFilename, parseJsonFile, waitUntilCondition } from './utils.js';42import { download, ensurePlainObject, equalsIgnoreCaseAndAccents, getSanitizedFilename, parseJsonFile, waitUntilCondition } from './utils.js';
41import { t } from './i18n.js';
42import { reasoning_templates } from './reasoning.js';
4343
44const presetManagers = {};44const presetManagers = {};
4545
@@ -397,8 +397,10 @@ class PresetManager {
397397
398 /**398 /**
399 * Updates the preset select element with the current API presets.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 async updatePreset() {403 async updatePreset(option = { skipUpdate: false }) {
402 const selected = $(this.select).find('option:selected');404 const selected = $(this.select).find('option:selected');
403 console.log(selected);405 console.log(selected);
404406
@@ -408,7 +410,7 @@ class PresetManager {
408 }410 }
409411
410 const name = selected.text();412 const name = selected.text();
411 await this.savePreset(name);413 await this.savePreset(name, null, option);
412414
413 const successToast = !this.isAdvancedFormatting() ? t`Preset updated` : t`Template updated`;415 const successToast = !this.isAdvancedFormatting() ? t`Preset updated` : t`Template updated`;
414 toastr.success(successToast);416 toastr.success(successToast);
@@ -1000,7 +1002,7 @@ export async function initPresetManager() {
1000 return;1002 return;
1001 }1003 }
10021004
1003 await presetManager.updatePreset();1005 await presetManager.updatePreset({ skipUpdate: true });
1004 });1006 });
10051007
1006 $(document).on('click', '[data-preset-manager-new]', async function () {1008 $(document).on('click', '[data-preset-manager-new]', async function () {