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) {
85268526 }
85278527
85288528 const foundName = result[0].item;
85298529 selectContextPreset(foundName, { quiet: quiet });
85308530 return foundName;
85318531}
85328532
@@ -8546,7 +8546,7 @@ async function selectInstructCallback(args, name) {
85468546 }
85478547
85488548 const foundName = result[0].item;
85498549 selectInstructPreset(foundName, { quiet: quiet });
85508550 return foundName;
85518551}
85528552
public/scripts/instruct-mode.js+14 -10
@@ -130,13 +130,15 @@ function highlightDefaultPreset() {
130130/**
131131 * Select context template if not already selected.
132132 * @param {string} preset Preset name.
133133 * @param {booleanobject} quiet Suppress[options={}] infoOptional messagearguments.
134+ * @param {boolean} [options.quiet=false] Suppress toast messages.
135+ * @param {boolean} [options.isAuto=false] Is auto-select.
134136 */
135137export function selectContextPreset(preset, { quiet = false, isAuto = false } = {}) {
136138 // If context template is not already selected, select it
137139 if (preset !== power_user.context.preset) {
138140 $('#context_presets').val(preset).trigger('change');
139141 !quiet && toastr.info(`Context Template: preset "${preset}" ${isAuto ? 'auto-' : ''}selected`);
140142 }
141143
142144 // If instruct mode is disabled, enable it, except for default context template
@@ -152,13 +154,15 @@ export function selectContextPreset(preset, quiet) {
152154/**
153155 * Select instruct preset if not already selected.
154156 * @param {string} preset Preset name.
155157 * @param {booleanobject} quiet Suppress[options={}] infoOptional messagearguments.
158+ * @param {boolean} [options.quiet=false] Suppress toast messages.
159+ * @param {boolean} [options.isAuto=false] Is auto-select.
156160 */
157161export function selectInstructPreset(preset, { quiet = false, isAuto = false } = {}) {
158162 // If instruct preset is not already selected, select it
159163 if (preset !== power_user.instruct.preset) {
160164 $('#instruct_presets').val(preset).trigger('change');
161165 !quiet && toastr.info(`Instruct ModeTemplate: template "${preset}" ${isAuto ? 'auto-' : ''}selected`);
162166 }
163167
164168 // If instruct mode is disabled, enable it
@@ -189,7 +193,7 @@ export function autoSelectInstructPreset(modelId) {
189193 // If instruct preset matches the context template
190194 if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
191195 foundMatch = true;
192196 selectInstructPreset(instruct_preset.name, { isAuto: true });
193197 break;
194198 }
195199 }
@@ -203,7 +207,7 @@ export function autoSelectInstructPreset(modelId) {
203207
204208 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match
205209 if (regex instanceof RegExp && regex.test(modelId)) {
206210 selectInstructPreset(preset.name, { isAuto: true });
207211
208212 return true;
209213 }
@@ -541,13 +545,13 @@ function selectMatchingContextTemplate(name) {
541545 // If context template matches the instruct preset
542546 if (context_preset.name === name) {
543547 foundMatch = true;
544548 selectContextPreset(context_preset.name, { isAuto: true });
545549 break;
546550 }
547551 }
548552 if (!foundMatch) {
549553 // If no match was found, select default context preset
550554 selectContextPreset(power_user.default_context, { isAuto: true });
551555 }
552556}
553557
public/scripts/power-user.js+1 -1
@@ -1798,7 +1798,7 @@ async function loadContextSettings() {
17981798 for (const instruct_preset of instruct_presets) {
17991799 // If instruct preset matches the context template
18001800 if (instruct_preset.name === name) {
18011801 selectInstructPreset(instruct_preset.name, { isAuto: true });
18021802 break;
18031803 }
18041804 }