Use deepMerge to combine payloads

a3693ccf6d77c36580a345a2f7b6c918d14d6bd7

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +63 -26Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+22 -22
@@ -18,7 +18,7 @@ import {
1818} from '../../../script.js';
1919import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js';
2020import { selected_group } from '../../group-chats.js';
2121import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js';
2222import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
2323import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
2424import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js';
@@ -219,7 +219,7 @@ const defaultSettings = {
219219 // Automatic1111/Horde exclusives
220220 restore_faces: false,
221221 enable_hr: false,
222222 aiFaceDetailer adetailer_face: false,
223223
224224 // Horde settings
225225 horde: false,
@@ -436,7 +436,7 @@ async function loadSettings() {
436436 $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
437437 $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
438438 $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
439439 $('#sd_aiFaceDetailersd_adetailer_face').prop('checked', extension_settings.sd.aiFaceDetaileradetailer_face);
440440 $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
441441 $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
442442 $('#sd_auto_url').val(extension_settings.sd.auto_url);
@@ -855,8 +855,8 @@ function onSamplerChange() {
855855 saveSettingsDebounced();
856856}
857857
858858function onAiFaceDetailerChangeonADetailerFaceChange() {
859859 extension_settings.sd.aiFaceDetaileradetailer_face = !!$('#sd_aiFaceDetailersd_adetailer_face').prop('checked');
860860 saveSettingsDebounced();
861861}
862862
@@ -2955,20 +2955,22 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
29552955 do_not_save_grid: false,
29562956 do_not_save_samples: false,
29572957 };
2958- // Conditionally add the ADetailer if aiFaceDetailer is enabled
2958+
2959- console.log('extension_settings.sd.aiFaceDetailer:', extension_settings.sd.aiFaceDetailer);
2959+ // Conditionally add the ADetailer if adetailer_face is enabled
29602960 if (extension_settings.sd.aiFaceDetaileradetailer_face) {
29612961 payload.alwayson_scripts = deepMerge(payload, {
29622962 ADetaileralwayson_scripts: {
29632963 argsADetailer: [{
2964- true, // ad_enable
2964+ args: [
29652965 true, // skip_img2imgad_enable
2966- {
2966+ true, // skip_img2img
2967- "ad_model": "face_yolov8n.pt"
2967+ {
2968- }
2968+ 'ad_model': 'face_yolov8n.pt',
2969- ]
2969+ },
2970- }
2970+ ],
2971- };
2971+ },
2972+ },
2973+ });
29722974 }
29732975
29742976 // Make the fetch call with the payload
@@ -2978,8 +2980,6 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
29782980 signal: signal,
29792981 body: JSON.stringify(payload),
29802982 });
2981-
2982-
29832983
29842984 if (result.ok) {
29852985 const data = await result.json();
@@ -4210,7 +4210,7 @@ jQuery(async () => {
42104210 $('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
42114211 $('#sd_restore_faces').on('input', onRestoreFacesInput);
42124212 $('#sd_enable_hr').on('input', onHighResFixInput);
42134213 $('#sd_aiFaceDetailersd_adetailer_face').on('change', onAiFaceDetailerChangeonADetailerFaceChange);
42144214 $('#sd_refine_mode').on('input', onRefineModeInput);
42154215 $('#sd_character_prompt').on('input', onCharacterPromptInput);
42164216 $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
public/scripts/extensions/stable-diffusion/settings.html+9 -4
@@ -354,11 +354,16 @@
354354 <small data-i18n="Karras">Karras</small>
355355 <i class="fa-solid fa-info-circle fa-sm opacity50p" data-i18n="[title]Not all samplers supported." title="Not all samplers supported."></i>
356356 </label>
357- <label for="sd_aiFaceDetailer" class="checkbox_label" data-i18n="[title]sd_aiFaceDetailer" title="Use AI Face Detailer in image generation.">
357+ </div>
358- <input id="sd_aiFaceDetailer" type="checkbox" />
359- <small data-i18n="sd_aiFaceDetailer">Use AI Face Detailer</small>
360- </label>
361358
359+ <div class="flex-container marginTopBot5" data-sd-source="auto">
360+ <label for="sd_adetailer_face" class="flex1 checkbox_label" data-i18n="[title]sd_adetailer_face" title="Use ADetailer with face model during the generation. The ADetailer extension must be installed on the backend.">
361+ <input id="sd_adetailer_face" type="checkbox" />
362+ <small data-i18n="Use ADetailer (Face)">Use ADetailer (Face)</small>
363+ </label>
364+ <div class="flex1">
365+ <!-- I will be useful later! -->
366+ </div>
362367 </div>
363368
364369 <div class="flex-container marginTopBot5" data-sd-source="novel">
public/scripts/utils.js+32 -0
@@ -23,6 +23,38 @@ export const navigation_option = {
2323 previous: -1000,
2424};
2525
26+/**
27+ * Determines if a value is an object.
28+ * @param {any} item The item to check.
29+ * @returns {boolean} True if the item is an object, false otherwise.
30+ */
31+function isObject(item) {
32+ return (item && typeof item === 'object' && !Array.isArray(item));
33+}
34+
35+/**
36+ * Merges properties of two objects. If the property is an object, it will be merged recursively.
37+ * @param {object} target The target object
38+ * @param {object} source The source object
39+ * @returns {object} Merged object
40+ */
41+export function deepMerge(target, source) {
42+ let output = Object.assign({}, target);
43+ if (isObject(target) && isObject(source)) {
44+ Object.keys(source).forEach(key => {
45+ if (isObject(source[key])) {
46+ if (!(key in target))
47+ Object.assign(output, { [key]: source[key] });
48+ else
49+ output[key] = deepMerge(target[key], source[key]);
50+ } else {
51+ Object.assign(output, { [key]: source[key] });
52+ }
53+ });
54+ }
55+ return output;
56+}
57+
2658export function escapeHtml(str) {
2759 return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
2860}