Refactor args for context/instruct select

4ba99412af473695225bfccf10c8bc8930479f82

Wolfsblvt <wolfsblvt@gmail.com>

3 files changed, +17 -13Showing whitespace changes
public/script.js+2 -2
@@ -8526,7 +8526,7 @@ async function selectContextCallback(args, name) {
8526 }8526 }
85278527
8528 const foundName = result[0].item;8528 const foundName = result[0].item;
8529 selectContextPreset(foundName, quiet);8529 selectContextPreset(foundName, { quiet: quiet });
8530 return foundName;8530 return foundName;
8531}8531}
85328532
@@ -8546,7 +8546,7 @@ async function selectInstructCallback(args, name) {
8546 }8546 }
85478547
8548 const foundName = result[0].item;8548 const foundName = result[0].item;
8549 selectInstructPreset(foundName, quiet);8549 selectInstructPreset(foundName, { quiet: quiet });
8550 return foundName;8550 return foundName;
8551}8551}
85528552
public/scripts/instruct-mode.js+14 -10
@@ -130,13 +130,15 @@ function highlightDefaultPreset() {
130/**130/**
131 * Select context template if not already selected.131 * Select context template if not already selected.
132 * @param {string} preset Preset name.132 * @param {string} preset Preset name.
133 * @param {boolean} quiet Suppress info message.133 * @param {object} [options={}] Optional arguments.
134 * @param {boolean} [options.quiet=false] Suppress toast messages.
135 * @param {boolean} [options.isAuto=false] Is auto-select.
134 */136 */
135export function selectContextPreset(preset, quiet) {137export function selectContextPreset(preset, { quiet = false, isAuto = false } = {}) {
136 // If context template is not already selected, select it138 // If context template is not already selected, select it
137 if (preset !== power_user.context.preset) {139 if (preset !== power_user.context.preset) {
138 $('#context_presets').val(preset).trigger('change');140 $('#context_presets').val(preset).trigger('change');
139 !quiet && toastr.info(`Context Template: preset "${preset}" auto-selected`);141 !quiet && toastr.info(`Context Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`);
140 }142 }
141143
142 // If instruct mode is disabled, enable it, except for default context template144 // If instruct mode is disabled, enable it, except for default context template
@@ -152,13 +154,15 @@ export function selectContextPreset(preset, quiet) {
152/**154/**
153 * Select instruct preset if not already selected.155 * Select instruct preset if not already selected.
154 * @param {string} preset Preset name.156 * @param {string} preset Preset name.
155 * @param {boolean} quiet Suppress info message.157 * @param {object} [options={}] Optional arguments.
158 * @param {boolean} [options.quiet=false] Suppress toast messages.
159 * @param {boolean} [options.isAuto=false] Is auto-select.
156 */160 */
157export function selectInstructPreset(preset, quiet) {161export function selectInstructPreset(preset, { quiet = false, isAuto = false } = {}) {
158 // If instruct preset is not already selected, select it162 // If instruct preset is not already selected, select it
159 if (preset !== power_user.instruct.preset) {163 if (preset !== power_user.instruct.preset) {
160 $('#instruct_presets').val(preset).trigger('change');164 $('#instruct_presets').val(preset).trigger('change');
161 !quiet && toastr.info(`Instruct Mode: template "${preset}" auto-selected`);165 !quiet && toastr.info(`Instruct Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`);
162 }166 }
163167
164 // If instruct mode is disabled, enable it168 // If instruct mode is disabled, enable it
@@ -189,7 +193,7 @@ export function autoSelectInstructPreset(modelId) {
189 // If instruct preset matches the context template193 // If instruct preset matches the context template
190 if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {194 if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
191 foundMatch = true;195 foundMatch = true;
192 selectInstructPreset(instruct_preset.name);196 selectInstructPreset(instruct_preset.name, { isAuto: true });
193 break;197 break;
194 }198 }
195 }199 }
@@ -203,7 +207,7 @@ export function autoSelectInstructPreset(modelId) {
203207
204 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match208 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match
205 if (regex instanceof RegExp && regex.test(modelId)) {209 if (regex instanceof RegExp && regex.test(modelId)) {
206 selectInstructPreset(preset.name);210 selectInstructPreset(preset.name, { isAuto: true });
207211
208 return true;212 return true;
209 }213 }
@@ -541,13 +545,13 @@ function selectMatchingContextTemplate(name) {
541 // If context template matches the instruct preset545 // If context template matches the instruct preset
542 if (context_preset.name === name) {546 if (context_preset.name === name) {
543 foundMatch = true;547 foundMatch = true;
544 selectContextPreset(context_preset.name);548 selectContextPreset(context_preset.name, { isAuto: true });
545 break;549 break;
546 }550 }
547 }551 }
548 if (!foundMatch) {552 if (!foundMatch) {
549 // If no match was found, select default context preset553 // If no match was found, select default context preset
550 selectContextPreset(power_user.default_context);554 selectContextPreset(power_user.default_context, { isAuto: true });
551 }555 }
552}556}
553557
public/scripts/power-user.js+1 -1
@@ -1798,7 +1798,7 @@ async function loadContextSettings() {
1798 for (const instruct_preset of instruct_presets) {1798 for (const instruct_preset of instruct_presets) {
1799 // If instruct preset matches the context template1799 // If instruct preset matches the context template
1800 if (instruct_preset.name === name) {1800 if (instruct_preset.name === name) {
1801 selectInstructPreset(instruct_preset.name);1801 selectInstructPreset(instruct_preset.name, { isAuto: true });
1802 break;1802 break;
1803 }1803 }
1804 }1804 }