feat: Add multi-slot support in Recipe Builder for enhanced model management
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+3
-1
@@ -15,6 +15,7 @@ from .nodes.prompt_extractor import PromptExtractor
|
||||
from .nodes.prompt_extractor import WorkflowExtractor as RecipeExtractor
|
||||
from .nodes.recipe_builder import WorkflowBuilder as RecipeBuilder
|
||||
from .nodes.recipe_builder import WorkflowBuilderWan as RecipeBuilderWan
|
||||
from .nodes.recipe_builder import WorkflowBuilderMulti as RecipeBuilderMulti
|
||||
from .nodes.recipe_renderer import WorkflowRenderer as RecipeRenderer
|
||||
from .nodes.recipe_relay import WorkflowRelay as RecipeRelay
|
||||
from .nodes.recipe_model_loader import WorkflowModelLoader as RecipeModelLoader
|
||||
@@ -31,6 +32,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"RecipeExtractor": RecipeExtractor,
|
||||
"RecipeBuilder": RecipeBuilder,
|
||||
"RecipeBuilderWan": RecipeBuilderWan,
|
||||
"RecipeBuilderMulti": RecipeBuilderMulti,
|
||||
"RecipeRenderer": RecipeRenderer,
|
||||
"RecipeRelay": RecipeRelay,
|
||||
"RecipeModelLoader": RecipeModelLoader,
|
||||
@@ -48,6 +50,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"RecipeExtractor": "Recipe Extractor",
|
||||
"RecipeBuilder": "Recipe Builder",
|
||||
"RecipeBuilderWan": "Recipe Builder (WAN)",
|
||||
"RecipeBuilderMulti": "Recipe Builder (Multi Model)",
|
||||
"RecipeRenderer": "Recipe Renderer",
|
||||
"RecipeRelay": "Recipe Relay",
|
||||
"RecipeModelLoader": "Recipe Model Loader",
|
||||
@@ -56,7 +59,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
}
|
||||
|
||||
WEB_DIRECTORY = "./js"
|
||||
|
||||
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY']
|
||||
print("[PromptManager] Nodes registered: Apply LoRA++, Prompt Manager (Basic), Prompt Manager, Prompt Generator, Prompt Generator Options, Prompt Extractor, Recipe Extractor, Recipe Builder, Recipe Builder (WAN), Recipe Merge, Recipe Renderer, Recipe Relay, Recipe Model Loader, Recipe Model Picker, Recipe Manager")
|
||||
|
||||
|
||||
+485
-12
@@ -407,6 +407,60 @@ function _normalizePullModelPairStartKey(v) {
|
||||
return _normalizeModelPairStartKey(key);
|
||||
}
|
||||
|
||||
function _makeEmptySlotProfile() {
|
||||
return {
|
||||
ov: {
|
||||
positive_prompt: "",
|
||||
negative_prompt: "",
|
||||
model_a: "",
|
||||
model_b: "",
|
||||
vae: "",
|
||||
clip_names: [],
|
||||
_family: "sdxl",
|
||||
steps_a: 20,
|
||||
cfg: 5.0,
|
||||
denoise: 1.0,
|
||||
seed_a: 0,
|
||||
sampler_name: "euler",
|
||||
scheduler: "simple",
|
||||
loras_a: [],
|
||||
loras_b: [],
|
||||
_section_locks: {
|
||||
model: false,
|
||||
sampler: false,
|
||||
positive: false,
|
||||
negative: false,
|
||||
loras: false,
|
||||
},
|
||||
},
|
||||
ls: {},
|
||||
};
|
||||
}
|
||||
|
||||
function _emptySlotProfiles() {
|
||||
return {
|
||||
model_a: _makeEmptySlotProfile(),
|
||||
model_b: _makeEmptySlotProfile(),
|
||||
model_c: _makeEmptySlotProfile(),
|
||||
model_d: _makeEmptySlotProfile(),
|
||||
};
|
||||
}
|
||||
|
||||
function _normalizeSlotProfiles(raw) {
|
||||
const out = _emptySlotProfiles();
|
||||
if (!raw || typeof raw !== "object") return out;
|
||||
for (const slot of MODEL_SLOT_KEYS) {
|
||||
const row = raw[slot];
|
||||
if (!row || typeof row !== "object") continue;
|
||||
const ov = (row.ov && typeof row.ov === "object")
|
||||
? { ...out[slot].ov, ...row.ov }
|
||||
: { ...out[slot].ov };
|
||||
const ls = (row.ls && typeof row.ls === "object") ? { ...row.ls } : {};
|
||||
out[slot] = { ov, ls };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function _isLoraAvailableForSort(lora, availabilityMap = null) {
|
||||
if (!lora) return true;
|
||||
if (lora.available === false || lora.found === false) return false;
|
||||
@@ -1137,7 +1191,9 @@ async function updateUI(node) {
|
||||
if (!d) return;
|
||||
|
||||
if (node._wePullModelSlotRow?._inp) {
|
||||
const pullSlot = node._weBuilderVariant === "wan"
|
||||
const pullSlot = node._weUseSlotProfiles
|
||||
? _normalizeModelSlotKey(node._weActiveModelSlot || node._weSendModelSlot || "model_a")
|
||||
: node._weBuilderVariant === "wan"
|
||||
? _normalizePullModelPairStartKey(d.pull_model_slot || d.model_slot || node._wePullModelSlot || NO_PULL_SLOT)
|
||||
: _normalizePullModelSlotKey(d.pull_model_slot || d.model_slot || node._wePullModelSlot || NO_PULL_SLOT);
|
||||
if (node._wePullModelSlotRow._setOriginal) node._wePullModelSlotRow._setOriginal(pullSlot);
|
||||
@@ -1145,12 +1201,15 @@ async function updateUI(node) {
|
||||
node._wePullModelSlot = pullSlot;
|
||||
}
|
||||
if (node._weSendModelSlotRow?._inp) {
|
||||
const sendSlot = node._weBuilderVariant === "wan"
|
||||
const sendSlot = node._weUseSlotProfiles
|
||||
? _normalizeModelSlotKey(node._weActiveModelSlot || d.send_model_slot || "model_a")
|
||||
: node._weBuilderVariant === "wan"
|
||||
? _normalizeModelPairStartKey(d.send_model_slot || node._weSendModelSlot || node._wePullModelSlot || "model_a")
|
||||
: _normalizeModelSlotKey(d.send_model_slot || node._weSendModelSlot || node._wePullModelSlot || "model_a");
|
||||
if (node._weSendModelSlotRow._setOriginal) node._weSendModelSlotRow._setOriginal(sendSlot);
|
||||
node._weSendModelSlotRow._inp.value = sendSlot;
|
||||
node._weSendModelSlot = sendSlot;
|
||||
if (node._weUseSlotProfiles) node._weActiveModelSlot = sendSlot;
|
||||
}
|
||||
|
||||
const sectionLocks = node._weSectionLocks || {};
|
||||
@@ -2030,7 +2089,13 @@ function syncHidden(node) {
|
||||
const persistedLocks = {};
|
||||
const sectionCollapsed = node._weCollapsedSections || {};
|
||||
for (const [key, locked] of Object.entries(sectionLocks)) {
|
||||
if (locked) persistedLocks[key] = true;
|
||||
if (node._weUseSlotProfiles) {
|
||||
// Multi-slot mode: persist explicit lock booleans per slot profile
|
||||
// except resolution, which is shared across all slots.
|
||||
if (key !== "resolution") persistedLocks[key] = !!locked;
|
||||
} else if (locked) {
|
||||
persistedLocks[key] = true;
|
||||
}
|
||||
}
|
||||
if (Object.keys(persistedLocks).length > 0) ov._section_locks = persistedLocks;
|
||||
else delete ov._section_locks;
|
||||
@@ -2065,6 +2130,16 @@ function syncHidden(node) {
|
||||
? _normalizeModelPairStartKey(node._weSendModelSlot)
|
||||
: _normalizeModelSlotKey(node._weSendModelSlot);
|
||||
else delete ov._send_model_slot;
|
||||
|
||||
if (node._weUseSlotProfiles) {
|
||||
const activeSlot = _normalizeModelSlotKey(node._weActiveModelSlot || node._weSendModelSlot || "model_a");
|
||||
node._weActiveModelSlot = activeSlot;
|
||||
ov._active_model_slot = activeSlot;
|
||||
ov._send_model_slot = activeSlot;
|
||||
ov._pull_model_slot = activeSlot;
|
||||
} else {
|
||||
delete ov._active_model_slot;
|
||||
}
|
||||
// Backward compatibility for older saved workflows.
|
||||
delete ov._model_slot;
|
||||
if (node._weShowAllModels) ov._show_all_models = true;
|
||||
@@ -2085,6 +2160,45 @@ function syncHidden(node) {
|
||||
}
|
||||
}
|
||||
|
||||
if (node._weUseSlotProfiles) {
|
||||
const activeSlot = _normalizeModelSlotKey(node._weActiveModelSlot || "model_a");
|
||||
const slotProfiles = _normalizeSlotProfiles(node._weSlotProfiles);
|
||||
|
||||
const slotOv = { ...ov };
|
||||
delete slotOv._slot_profiles;
|
||||
delete slotOv._active_model_slot;
|
||||
|
||||
// Resolution settings are global for multi-slot builder.
|
||||
delete slotOv.width;
|
||||
delete slotOv.height;
|
||||
delete slotOv.batch_size;
|
||||
delete slotOv.length;
|
||||
delete slotOv._ratio;
|
||||
delete slotOv._ratio_landscape;
|
||||
delete slotOv._res_locked;
|
||||
if (slotOv._section_locks && typeof slotOv._section_locks === "object") {
|
||||
const nextLocks = { ...slotOv._section_locks };
|
||||
delete nextLocks.resolution;
|
||||
slotOv._section_locks = nextLocks;
|
||||
}
|
||||
if (slotOv._section_collapsed && typeof slotOv._section_collapsed === "object") {
|
||||
const nextCollapsed = { ...slotOv._section_collapsed };
|
||||
delete nextCollapsed.resolution;
|
||||
slotOv._section_collapsed = nextCollapsed;
|
||||
}
|
||||
|
||||
slotProfiles[activeSlot] = {
|
||||
ov: slotOv,
|
||||
ls: { ...persistedLoraState },
|
||||
};
|
||||
|
||||
node._weSlotProfiles = slotProfiles;
|
||||
ov._slot_profiles = slotProfiles;
|
||||
ov._active_model_slot = activeSlot;
|
||||
} else {
|
||||
delete ov._slot_profiles;
|
||||
}
|
||||
|
||||
wSet("override_data", JSON.stringify(ov));
|
||||
wSet("lora_state", JSON.stringify(persistedLoraState));
|
||||
|
||||
@@ -2137,6 +2251,28 @@ function applyOverrides(node, ovJson, lsJson) {
|
||||
let ov, ls;
|
||||
try { ov = JSON.parse(ovJson || "{}"); } catch { ov = {}; }
|
||||
try { ls = JSON.parse(lsJson || "{}"); } catch { ls = {}; }
|
||||
|
||||
if (node?._weUseSlotProfiles) {
|
||||
const slotProfiles = _normalizeSlotProfiles(ov?._slot_profiles);
|
||||
node._weSlotProfiles = slotProfiles;
|
||||
|
||||
const activeSlot = _normalizeModelSlotKey(ov?._active_model_slot || ov?._send_model_slot || "model_a");
|
||||
node._weActiveModelSlot = activeSlot;
|
||||
|
||||
const activeProfile = slotProfiles?.[activeSlot];
|
||||
if (activeProfile && typeof activeProfile === "object") {
|
||||
if (activeProfile.ov && typeof activeProfile.ov === "object") {
|
||||
ov = { ...ov, ...activeProfile.ov };
|
||||
}
|
||||
if (activeProfile.ls && typeof activeProfile.ls === "object" && Object.keys(activeProfile.ls).length > 0) {
|
||||
ls = { ...activeProfile.ls };
|
||||
}
|
||||
}
|
||||
|
||||
ov._send_model_slot = activeSlot;
|
||||
ov._pull_model_slot = activeSlot;
|
||||
}
|
||||
|
||||
const d = node._weExtracted;
|
||||
if (!d) return;
|
||||
const isEmpty = (o) => !o || Object.keys(o).length === 0;
|
||||
@@ -2146,6 +2282,12 @@ function applyOverrides(node, ovJson, lsJson) {
|
||||
if (!row || ovVal == null || ovVal === "\u2014") return;
|
||||
const sel = row._sel;
|
||||
if (!sel) return;
|
||||
if (ovVal === "") {
|
||||
sel.selectedIndex = 0;
|
||||
sel.style.color = C.textMuted;
|
||||
if (row._resetBtn) row._resetBtn.style.visibility = "hidden";
|
||||
return;
|
||||
}
|
||||
if (![...sel.options].some(o => o.value === ovVal)) {
|
||||
const o = document.createElement("option");
|
||||
o.value = ovVal;
|
||||
@@ -2212,7 +2354,12 @@ function applyOverrides(node, ovJson, lsJson) {
|
||||
if (node._weSendModelSlotRow._setOriginal) node._weSendModelSlotRow._setOriginal(slot);
|
||||
}
|
||||
|
||||
if (ov._section_locks && typeof ov._section_locks === "object") {
|
||||
if (node._weUseSlotProfiles) {
|
||||
const lockSrc = (ov._section_locks && typeof ov._section_locks === "object") ? ov._section_locks : {};
|
||||
for (const key of ["model", "sampler", "positive", "negative", "loras"]) {
|
||||
if (node._weSetSectionLock) node._weSetSectionLock(key, !!lockSrc[key], { sync: false });
|
||||
}
|
||||
} else if (ov._section_locks && typeof ov._section_locks === "object") {
|
||||
for (const key of ["resolution", "model", "sampler", "positive", "negative", "loras"]) {
|
||||
if (Object.prototype.hasOwnProperty.call(ov._section_locks, key) && node._weSetSectionLock) {
|
||||
node._weSetSectionLock(key, !!ov._section_locks[key], { sync: false });
|
||||
@@ -2270,11 +2417,18 @@ function applyOverrides(node, ovJson, lsJson) {
|
||||
if (ov.positive_prompt != null && node._wePosBox) node._wePosBox.value = ov.positive_prompt;
|
||||
if (ov.negative_prompt != null && node._weNegBox) node._weNegBox.value = ov.negative_prompt;
|
||||
|
||||
if (Array.isArray(ov.loras_a)) d.loras_a = [...ov.loras_a];
|
||||
if (Array.isArray(ov.loras_b)) d.loras_b = [...ov.loras_b];
|
||||
if (ov._lora_availability && typeof ov._lora_availability === "object") {
|
||||
d.lora_availability = { ...ov._lora_availability };
|
||||
}
|
||||
|
||||
if (!isEmpty(ls)) {
|
||||
node._weLoraState = ls;
|
||||
updateLoras(node);
|
||||
}
|
||||
|
||||
updateLoras(node);
|
||||
|
||||
updateWanVisibility(node);
|
||||
syncHidden(node);
|
||||
}
|
||||
@@ -2410,6 +2564,138 @@ function parseWorkflowData(jsonStr, modelSlot = "model_a", builderVariant = "sim
|
||||
}
|
||||
}
|
||||
|
||||
function buildSlotProfilesFromWorkflowData(rawWorkflowData) {
|
||||
let d = null;
|
||||
if (rawWorkflowData && typeof rawWorkflowData === "object") {
|
||||
d = rawWorkflowData;
|
||||
} else if (typeof rawWorkflowData === "string" && rawWorkflowData.trim()) {
|
||||
try {
|
||||
d = JSON.parse(rawWorkflowData);
|
||||
} catch {
|
||||
d = null;
|
||||
}
|
||||
}
|
||||
if (!d || typeof d !== "object") return null;
|
||||
if (!(d.models && typeof d.models === "object")) return null;
|
||||
|
||||
const profiles = _emptySlotProfiles();
|
||||
|
||||
const toProfileFromExtracted = (extracted) => {
|
||||
const src = extracted && typeof extracted === "object" ? extracted : {};
|
||||
const sampler = src.sampler && typeof src.sampler === "object" ? src.sampler : {};
|
||||
const loras = Array.isArray(src.loras_a) ? src.loras_a : [];
|
||||
const ls = {};
|
||||
|
||||
for (const lora of loras) {
|
||||
const name = String(lora?.name || "").trim();
|
||||
if (!name) continue;
|
||||
const modelStrength = Number(lora?.model_strength ?? lora?.strength ?? 1.0);
|
||||
const clipStrength = Number(lora?.clip_strength ?? lora?.strength ?? modelStrength);
|
||||
const entry = {
|
||||
active: lora?.active !== false,
|
||||
model_strength: Number.isFinite(modelStrength) ? modelStrength : 1.0,
|
||||
clip_strength: Number.isFinite(clipStrength) ? clipStrength : (Number.isFinite(modelStrength) ? modelStrength : 1.0),
|
||||
};
|
||||
ls[name] = entry;
|
||||
ls[`a:${name}`] = entry;
|
||||
}
|
||||
|
||||
return {
|
||||
ov: {
|
||||
positive_prompt: String(src.positive_prompt || ""),
|
||||
negative_prompt: String(src.negative_prompt || ""),
|
||||
model_a: String(src.model_a || ""),
|
||||
model_b: "",
|
||||
vae: String(src?.vae?.name || ""),
|
||||
clip_names: Array.isArray(src?.clip?.names) ? src.clip.names : [],
|
||||
clip_type: String(src?.clip?.type || ""),
|
||||
loader_type: "",
|
||||
_family: String(src.model_family || "sdxl"),
|
||||
steps_a: Number(sampler.steps_a ?? 20),
|
||||
cfg: Number(sampler.cfg ?? 5.0),
|
||||
denoise: Number(sampler.denoise ?? 1.0),
|
||||
seed_a: Number(sampler.seed_a ?? 0),
|
||||
sampler_name: String(sampler.sampler_name || "euler"),
|
||||
scheduler: String(sampler.scheduler || "simple"),
|
||||
loras_a: loras,
|
||||
loras_b: [],
|
||||
_section_locks: {
|
||||
model: false,
|
||||
sampler: false,
|
||||
positive: false,
|
||||
negative: false,
|
||||
loras: false,
|
||||
},
|
||||
},
|
||||
ls,
|
||||
};
|
||||
};
|
||||
|
||||
for (const slot of MODEL_SLOT_KEYS) {
|
||||
const block = d.models?.[slot];
|
||||
if (!block || typeof block !== "object") {
|
||||
profiles[slot] = _makeEmptySlotProfile();
|
||||
continue;
|
||||
}
|
||||
|
||||
const extracted = parseWorkflowData(JSON.stringify(d), slot, "simple");
|
||||
profiles[slot] = toProfileFromExtracted(extracted);
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
function mergeSlotProfileWithLocks(currentProfile, incomingProfile) {
|
||||
const cur = currentProfile && typeof currentProfile === "object" ? currentProfile : { ov: {}, ls: {} };
|
||||
const inc = incomingProfile && typeof incomingProfile === "object" ? incomingProfile : { ov: {}, ls: {} };
|
||||
const curOv = cur.ov && typeof cur.ov === "object" ? cur.ov : {};
|
||||
const incOv = inc.ov && typeof inc.ov === "object" ? inc.ov : {};
|
||||
const curLs = cur.ls && typeof cur.ls === "object" ? cur.ls : {};
|
||||
const incLs = inc.ls && typeof inc.ls === "object" ? inc.ls : {};
|
||||
|
||||
const locks = (curOv._section_locks && typeof curOv._section_locks === "object")
|
||||
? curOv._section_locks
|
||||
: {};
|
||||
|
||||
const outOv = { ...curOv, ...incOv };
|
||||
outOv._section_locks = {
|
||||
model: !!locks.model,
|
||||
sampler: !!locks.sampler,
|
||||
positive: !!locks.positive,
|
||||
negative: !!locks.negative,
|
||||
loras: !!locks.loras,
|
||||
};
|
||||
|
||||
if (locks.model) {
|
||||
for (const k of ["model_a", "model_b", "vae", "clip_names", "clip_type", "loader_type", "_family"]) {
|
||||
if (Object.prototype.hasOwnProperty.call(curOv, k)) outOv[k] = curOv[k];
|
||||
}
|
||||
}
|
||||
if (locks.sampler) {
|
||||
for (const k of ["steps_a", "steps_b", "cfg", "denoise", "seed_a", "seed_b", "sampler_name", "scheduler"]) {
|
||||
if (Object.prototype.hasOwnProperty.call(curOv, k)) outOv[k] = curOv[k];
|
||||
}
|
||||
}
|
||||
if (locks.positive && Object.prototype.hasOwnProperty.call(curOv, "positive_prompt")) {
|
||||
outOv.positive_prompt = curOv.positive_prompt;
|
||||
}
|
||||
if (locks.negative && Object.prototype.hasOwnProperty.call(curOv, "negative_prompt")) {
|
||||
outOv.negative_prompt = curOv.negative_prompt;
|
||||
}
|
||||
|
||||
let outLs = { ...incLs };
|
||||
if (locks.loras) {
|
||||
if (Object.prototype.hasOwnProperty.call(curOv, "loras_a")) outOv.loras_a = curOv.loras_a;
|
||||
if (Object.prototype.hasOwnProperty.call(curOv, "loras_b")) outOv.loras_b = curOv.loras_b;
|
||||
outLs = { ...curLs };
|
||||
}
|
||||
|
||||
return {
|
||||
ov: outOv,
|
||||
ls: outLs,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ============================================================
|
||||
// --- Main extension ---
|
||||
@@ -2418,14 +2704,16 @@ app.registerExtension({
|
||||
name: "RecipeBuilder",
|
||||
|
||||
async beforeRegisterNodeDef(nodeType, nodeData) {
|
||||
if (nodeData.name !== "RecipeBuilder" && nodeData.name !== "RecipeBuilderWan") return;
|
||||
if (nodeData.name !== "RecipeBuilder" && nodeData.name !== "RecipeBuilderWan" && nodeData.name !== "RecipeBuilderMulti") return;
|
||||
|
||||
const origCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
const r = origCreated?.apply(this, arguments);
|
||||
const node = this;
|
||||
const isWanBuilder = nodeData.name === "RecipeBuilderWan";
|
||||
const isMultiBuilder = nodeData.name === "RecipeBuilderMulti";
|
||||
node._weBuilderVariant = isWanBuilder ? "wan" : "simple";
|
||||
node._weUseSlotProfiles = isMultiBuilder === true;
|
||||
|
||||
const _normalizeInputNameForVariant = (name) => {
|
||||
let key = _canonicalInputName(name);
|
||||
@@ -2678,6 +2966,117 @@ app.registerExtension({
|
||||
sendModelSlotRow.style.marginBottom = "0";
|
||||
node._weSendModelSlotRow = sendModelSlotRow;
|
||||
node._weSendModelSlot = "model_a";
|
||||
node._weActiveModelSlot = "model_a";
|
||||
node._weSlotProfiles = _emptySlotProfiles();
|
||||
|
||||
if (node._weUseSlotProfiles) {
|
||||
sendModelSlotRow._label.textContent = "Model Slot";
|
||||
sendModelSlotRow._inp.title = "Switch between model slots A/B/C/D. Each slot keeps its own Recipe Builder settings.";
|
||||
pullModelSlotRow.style.display = "none";
|
||||
|
||||
const _captureCurrentSlotProfile = () => {
|
||||
const slot = _normalizeModelSlotKey(node._weActiveModelSlot || node._weSendModelSlot || "model_a");
|
||||
const slotProfiles = _normalizeSlotProfiles(node._weSlotProfiles);
|
||||
const ovRaw = node.properties?.we_ui_state || node.properties?.we_override_data || "{}";
|
||||
const lsRaw = node.properties?.we_lora_state || "{}";
|
||||
let ovObj = {};
|
||||
let lsObj = {};
|
||||
try { ovObj = JSON.parse(ovRaw || "{}"); } catch { ovObj = {}; }
|
||||
try { lsObj = JSON.parse(lsRaw || "{}"); } catch { lsObj = {}; }
|
||||
delete ovObj._slot_profiles;
|
||||
delete ovObj._active_model_slot;
|
||||
// Resolution is shared for all model slots.
|
||||
delete ovObj.width;
|
||||
delete ovObj.height;
|
||||
delete ovObj.batch_size;
|
||||
delete ovObj.length;
|
||||
delete ovObj._ratio;
|
||||
delete ovObj._ratio_landscape;
|
||||
delete ovObj._res_locked;
|
||||
if (ovObj._section_locks && typeof ovObj._section_locks === "object") {
|
||||
const nextLocks = { ...ovObj._section_locks };
|
||||
delete nextLocks.resolution;
|
||||
ovObj._section_locks = nextLocks;
|
||||
}
|
||||
if (ovObj._section_collapsed && typeof ovObj._section_collapsed === "object") {
|
||||
const nextCollapsed = { ...ovObj._section_collapsed };
|
||||
delete nextCollapsed.resolution;
|
||||
ovObj._section_collapsed = nextCollapsed;
|
||||
}
|
||||
ovObj._send_model_slot = slot;
|
||||
ovObj._pull_model_slot = slot;
|
||||
slotProfiles[slot] = { ov: ovObj, ls: lsObj };
|
||||
node._weSlotProfiles = slotProfiles;
|
||||
};
|
||||
|
||||
const _loadSlotProfile = (slot) => {
|
||||
const targetSlot = _normalizeModelSlotKey(slot);
|
||||
const slotProfiles = _normalizeSlotProfiles(node._weSlotProfiles);
|
||||
let profile = slotProfiles[targetSlot];
|
||||
if (!profile || typeof profile !== "object") {
|
||||
profile = {
|
||||
ov: {
|
||||
positive_prompt: "",
|
||||
negative_prompt: "",
|
||||
model_a: "",
|
||||
model_b: "",
|
||||
vae: "",
|
||||
clip_names: [],
|
||||
_family: "sdxl",
|
||||
steps_a: 20,
|
||||
cfg: 5.0,
|
||||
denoise: 1.0,
|
||||
seed_a: 0,
|
||||
sampler_name: "euler",
|
||||
scheduler: "simple",
|
||||
loras_a: [],
|
||||
loras_b: [],
|
||||
_section_locks: {
|
||||
model: false,
|
||||
sampler: false,
|
||||
positive: false,
|
||||
negative: false,
|
||||
loras: false,
|
||||
},
|
||||
},
|
||||
ls: {},
|
||||
};
|
||||
slotProfiles[targetSlot] = profile;
|
||||
}
|
||||
const profileOv = (profile.ov && typeof profile.ov === "object") ? { ...profile.ov } : {};
|
||||
profileOv._send_model_slot = targetSlot;
|
||||
profileOv._pull_model_slot = targetSlot;
|
||||
profileOv._active_model_slot = targetSlot;
|
||||
profileOv._slot_profiles = slotProfiles;
|
||||
|
||||
node._weActiveModelSlot = targetSlot;
|
||||
node._weSendModelSlot = targetSlot;
|
||||
node._wePullModelSlot = targetSlot;
|
||||
|
||||
applyOverrides(node, JSON.stringify(profileOv), JSON.stringify(profile.ls || {}));
|
||||
};
|
||||
|
||||
const _onSlotChanged = () => {
|
||||
if (node._weHydrating) {
|
||||
const pickedHydrating = _normalizeModelSlotKey(sendModelSlotRow._inp?.value || "model_a");
|
||||
node._weActiveModelSlot = pickedHydrating;
|
||||
node._weSendModelSlot = pickedHydrating;
|
||||
node._wePullModelSlot = pickedHydrating;
|
||||
_syncS();
|
||||
return;
|
||||
}
|
||||
|
||||
syncHidden(node);
|
||||
_captureCurrentSlotProfile();
|
||||
|
||||
const picked = _normalizeModelSlotKey(sendModelSlotRow._inp?.value || "model_a");
|
||||
_loadSlotProfile(picked);
|
||||
_syncS();
|
||||
};
|
||||
|
||||
sendModelSlotRow._inp.onchange = _onSlotChanged;
|
||||
sendModelSlotRow._inp.oninput = _onSlotChanged;
|
||||
}
|
||||
|
||||
const _findWorkflowDataInput = (targetNode = node) => {
|
||||
const ins = targetNode?.inputs || [];
|
||||
@@ -2730,6 +3129,15 @@ app.registerExtension({
|
||||
const sel = row?._inp;
|
||||
if (!sel) return;
|
||||
|
||||
if (node._weUseSlotProfiles) {
|
||||
const active = _normalizeModelSlotKey(node._weActiveModelSlot || node._weSendModelSlot || "model_a");
|
||||
node._weActiveModelSlot = active;
|
||||
node._wePullModelSlot = active;
|
||||
node._weSendModelSlot = active;
|
||||
sel.value = active;
|
||||
return;
|
||||
}
|
||||
|
||||
const wasConnected = node._weRecipeDataConnectedState;
|
||||
const hasPrevState = typeof wasConnected === "boolean";
|
||||
const connectionChanged = !hasPrevState || wasConnected !== recipeDataConnected;
|
||||
@@ -2832,9 +3240,11 @@ app.registerExtension({
|
||||
updateBtn.onmouseleave = () => { updateBtn.style.background = C.accent; };
|
||||
updateBtn.onclick = async () => {
|
||||
const isWanBuilder = node._weBuilderVariant === "wan";
|
||||
const selectedPullSlot = node._weBuilderVariant === "wan"
|
||||
? _normalizePullModelPairStartKey(node._wePullModelSlotRow?._inp?.value ?? node._wePullModelSlot ?? NO_PULL_SLOT)
|
||||
: _normalizePullModelSlotKey(node._wePullModelSlotRow?._inp?.value ?? node._wePullModelSlot ?? NO_PULL_SLOT);
|
||||
const selectedPullSlot = node._weUseSlotProfiles
|
||||
? _normalizeModelSlotKey(node._weActiveModelSlot || node._weSendModelSlot || "model_a")
|
||||
: node._weBuilderVariant === "wan"
|
||||
? _normalizePullModelPairStartKey(node._wePullModelSlotRow?._inp?.value ?? node._wePullModelSlot ?? NO_PULL_SLOT)
|
||||
: _normalizePullModelSlotKey(node._wePullModelSlotRow?._inp?.value ?? node._wePullModelSlot ?? NO_PULL_SLOT);
|
||||
node._wePullModelSlot = selectedPullSlot;
|
||||
if (node._wePullModelSlotRow?._inp) {
|
||||
node._wePullModelSlotRow._inp.value = selectedPullSlot;
|
||||
@@ -2842,7 +3252,7 @@ app.registerExtension({
|
||||
|
||||
// Explicit clear mode: Pull From = none should clear Builder UI
|
||||
// and must not fetch or infer data from any connected source.
|
||||
if (selectedPullSlot === NO_PULL_SLOT) {
|
||||
if (!node._weUseSlotProfiles && selectedPullSlot === NO_PULL_SLOT) {
|
||||
try {
|
||||
updateBtn.disabled = true;
|
||||
updateBtn.textContent = "Clearing...";
|
||||
@@ -2917,6 +3327,7 @@ app.registerExtension({
|
||||
ccNorm === "recipemanager" || tyNorm === "recipemanager" ||
|
||||
ccNorm === "recipebuilder" || tyNorm === "recipebuilder" ||
|
||||
ccNorm === "recipebuilderwan" || tyNorm === "recipebuilderwan" ||
|
||||
ccNorm === "recipebuildermulti" || tyNorm === "recipebuildermulti" ||
|
||||
ccNorm === "reciperelay" || tyNorm === "reciperelay";
|
||||
};
|
||||
const _isRerouteNode = (n) => {
|
||||
@@ -2968,9 +3379,10 @@ app.registerExtension({
|
||||
updateBtn.textContent = "Fetching...";
|
||||
try {
|
||||
let extracted = null;
|
||||
let pulledSlotProfiles = null;
|
||||
const sourceClass = sourceNode?.comfyClass || sourceNode?.type || "";
|
||||
const sourceClassNorm = _normalizeNodeKind(sourceClass);
|
||||
const isBuilderSource = sourceClassNorm === "recipebuilder" || sourceClassNorm === "recipebuilderwan";
|
||||
const isBuilderSource = sourceClassNorm === "recipebuilder" || sourceClassNorm === "recipebuilderwan" || sourceClassNorm === "recipebuildermulti";
|
||||
const isContextSource = sourceClassNorm === "reciperelay";
|
||||
const isPmaSource = sourceClassNorm === "promptmanageradvanced" || sourceClassNorm === "recipemanager";
|
||||
|
||||
@@ -3090,6 +3502,10 @@ app.registerExtension({
|
||||
return;
|
||||
}
|
||||
|
||||
if (node._weUseSlotProfiles) {
|
||||
pulledSlotProfiles = buildSlotProfilesFromWorkflowData(wfData);
|
||||
}
|
||||
|
||||
const wfJson = (typeof wfData === "string") ? wfData : JSON.stringify(wfData);
|
||||
extracted = parseWorkflowData(wfJson, selectedPullSlot || "model_a", node._weBuilderVariant || "simple");
|
||||
if (!extracted) {
|
||||
@@ -3109,6 +3525,9 @@ app.registerExtension({
|
||||
}
|
||||
|
||||
if (wfData) {
|
||||
if (node._weUseSlotProfiles) {
|
||||
pulledSlotProfiles = buildSlotProfilesFromWorkflowData(wfData);
|
||||
}
|
||||
const wfJson = (typeof wfData === "string") ? wfData : JSON.stringify(wfData);
|
||||
extracted = parseWorkflowData(wfJson, selectedPullSlot || "model_a", node._weBuilderVariant || "simple");
|
||||
}
|
||||
@@ -3290,6 +3709,52 @@ app.registerExtension({
|
||||
const positiveLocked = !!sectionLocks.positive;
|
||||
const negativeLocked = !!sectionLocks.negative;
|
||||
|
||||
if (node._weUseSlotProfiles && pulledSlotProfiles) {
|
||||
const currentProfiles = _normalizeSlotProfiles(node._weSlotProfiles);
|
||||
const incomingProfiles = _normalizeSlotProfiles(pulledSlotProfiles);
|
||||
|
||||
// Preserve per-slot lock maps while replacing slot content.
|
||||
for (const slot of MODEL_SLOT_KEYS) {
|
||||
const curLocks = currentProfiles?.[slot]?.ov?._section_locks;
|
||||
if (curLocks && typeof curLocks === "object") {
|
||||
incomingProfiles[slot].ov._section_locks = {
|
||||
model: !!curLocks.model,
|
||||
sampler: !!curLocks.sampler,
|
||||
positive: !!curLocks.positive,
|
||||
negative: !!curLocks.negative,
|
||||
loras: !!curLocks.loras,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const activeSlot = _normalizeModelSlotKey(selectedPullSlot || node._weActiveModelSlot || "model_a");
|
||||
const activeProfile = incomingProfiles[activeSlot] || _makeEmptySlotProfile();
|
||||
const activeOv = {
|
||||
...(activeProfile.ov || {}),
|
||||
_slot_profiles: incomingProfiles,
|
||||
_active_model_slot: activeSlot,
|
||||
_send_model_slot: activeSlot,
|
||||
_pull_model_slot: activeSlot,
|
||||
};
|
||||
|
||||
node._weSlotProfiles = incomingProfiles;
|
||||
node._weActiveModelSlot = activeSlot;
|
||||
node._weSendModelSlot = activeSlot;
|
||||
node._wePullModelSlot = activeSlot;
|
||||
|
||||
if (processed && typeof processed === "object") {
|
||||
node._weExtracted = processed;
|
||||
node._wePopulated = true;
|
||||
}
|
||||
|
||||
await updateUI(node);
|
||||
applyOverrides(node, JSON.stringify(activeOv), JSON.stringify(activeProfile.ls || {}));
|
||||
syncHidden(node);
|
||||
node.setDirtyCanvas(true, true);
|
||||
app.graph.setDirtyCanvas(true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Populate the UI
|
||||
_showError(node, null);
|
||||
|
||||
@@ -3370,7 +3835,6 @@ app.registerExtension({
|
||||
padding: "4px 8px",
|
||||
});
|
||||
modelSlotBox.appendChild(modelSlotGroup);
|
||||
root.appendChild(modelSlotBox);
|
||||
root.appendChild(updateBtn);
|
||||
|
||||
// -- 1. RESOLUTION section (open) --
|
||||
@@ -3518,6 +3982,11 @@ app.registerExtension({
|
||||
resSec._body.appendChild(resRows[key]);
|
||||
}
|
||||
root.appendChild(resSec);
|
||||
if (node._weUseSlotProfiles) {
|
||||
root.appendChild(modelSlotBox);
|
||||
} else {
|
||||
root.insertBefore(modelSlotBox, updateBtn);
|
||||
}
|
||||
|
||||
node._weResRows = resRows;
|
||||
node._weRatio = "None";
|
||||
@@ -4628,6 +5097,10 @@ app.registerExtension({
|
||||
const cls = String(node.comfyClass || node.type || "");
|
||||
node._weBuilderVariant = cls === "RecipeBuilderWan" ? "wan" : "simple";
|
||||
}
|
||||
if (node._weUseSlotProfiles == null) {
|
||||
const cls = String(node.comfyClass || node.type || "");
|
||||
node._weUseSlotProfiles = cls === "RecipeBuilderMulti";
|
||||
}
|
||||
|
||||
const VALID_INPUTS = new Set([
|
||||
...(node._weBuilderVariant === "wan"
|
||||
|
||||
+136
-1
@@ -1653,11 +1653,139 @@ class WorkflowBuilder:
|
||||
|
||||
simplified_wf[lora_key] = annotated
|
||||
|
||||
# Optional multi-slot profile payload from JS. When present, this node
|
||||
# can author model_a..model_d blocks in one builder instance.
|
||||
base_recipe_for_output = wf_data if isinstance(wf_data, dict) else None
|
||||
slot_profiles = overrides.get('_slot_profiles') if isinstance(overrides, dict) else None
|
||||
if isinstance(slot_profiles, dict):
|
||||
try:
|
||||
if isinstance(base_recipe_for_output, dict) and \
|
||||
int(base_recipe_for_output.get('version', 0) or 0) >= 2 and \
|
||||
isinstance(base_recipe_for_output.get('models'), dict):
|
||||
base_recipe_for_output = dict(base_recipe_for_output)
|
||||
base_recipe_for_output['models'] = {
|
||||
k: dict(v) for k, v in (base_recipe_for_output.get('models') or {}).items()
|
||||
if isinstance(v, dict)
|
||||
}
|
||||
else:
|
||||
base_recipe_for_output = {
|
||||
'_source': 'RecipeBuilder',
|
||||
'version': 2,
|
||||
'models': {},
|
||||
}
|
||||
|
||||
def _norm_num(v, default):
|
||||
try:
|
||||
return float(v)
|
||||
except Exception:
|
||||
return float(default)
|
||||
|
||||
def _norm_int(v, default):
|
||||
try:
|
||||
return int(v)
|
||||
except Exception:
|
||||
return int(default)
|
||||
|
||||
def _norm_loras(raw_list):
|
||||
out = []
|
||||
if not isinstance(raw_list, list):
|
||||
return out
|
||||
for item in raw_list:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
name = str(item.get('name', '')).strip()
|
||||
if not name:
|
||||
continue
|
||||
path = str(item.get('path', name)).strip() or name
|
||||
model_strength = _norm_num(item.get('model_strength', item.get('strength', 1.0)), 1.0)
|
||||
clip_strength = _norm_num(item.get('clip_strength', model_strength), model_strength)
|
||||
out.append({
|
||||
'name': name,
|
||||
'path': path,
|
||||
'model_strength': model_strength,
|
||||
'clip_strength': clip_strength,
|
||||
'active': item.get('active', True) is not False,
|
||||
'available': item.get('available', True) is not False,
|
||||
})
|
||||
return out
|
||||
|
||||
for slot_key in _MODEL_KEYS:
|
||||
raw_profile = slot_profiles.get(slot_key)
|
||||
if not isinstance(raw_profile, dict):
|
||||
continue
|
||||
|
||||
# Current JS shape stores per-slot profile as {ov, ls}; keep
|
||||
# backward compatibility with legacy raw slot payload.
|
||||
ov_profile = raw_profile.get('ov') if isinstance(raw_profile.get('ov'), dict) else None
|
||||
profile = ov_profile if isinstance(ov_profile, dict) else raw_profile
|
||||
|
||||
if isinstance(ov_profile, dict):
|
||||
loras_src = profile.get('loras_a', [])
|
||||
clip_src = profile.get('clip_names', [])
|
||||
sampler_in = {
|
||||
'steps': profile.get('steps_a', 20),
|
||||
'cfg': profile.get('cfg', 5.0),
|
||||
'denoise': profile.get('denoise', 1.0),
|
||||
'seed': profile.get('seed_a', 0),
|
||||
'sampler_name': profile.get('sampler_name', 'euler'),
|
||||
'scheduler': profile.get('scheduler', 'simple'),
|
||||
}
|
||||
resolution_in = {
|
||||
'width': profile.get('width', 768),
|
||||
'height': profile.get('height', 1280),
|
||||
'batch_size': profile.get('batch_size', 1),
|
||||
'length': profile.get('length'),
|
||||
}
|
||||
profile_model = profile.get('model_a', profile.get('model', ''))
|
||||
profile_family = profile.get('_family', profile.get('family', ''))
|
||||
profile_clip_type = profile.get('clip_type', '')
|
||||
profile_loader_type = profile.get('loader_type', '')
|
||||
else:
|
||||
loras_src = profile.get('loras', [])
|
||||
clip_src = profile.get('clip', [])
|
||||
sampler_in = profile.get('sampler', {}) if isinstance(profile.get('sampler'), dict) else {}
|
||||
resolution_in = profile.get('resolution', {}) if isinstance(profile.get('resolution'), dict) else {}
|
||||
profile_model = profile.get('model', '')
|
||||
profile_family = profile.get('family', '')
|
||||
profile_clip_type = profile.get('clip_type', '')
|
||||
profile_loader_type = profile.get('loader_type', '')
|
||||
|
||||
clip_raw = clip_src if isinstance(clip_src, list) else ([clip_src] if clip_src else [])
|
||||
|
||||
slot_block = {
|
||||
'positive_prompt': str(profile.get('positive_prompt', '') or ''),
|
||||
'negative_prompt': str(profile.get('negative_prompt', '') or ''),
|
||||
'family': str(profile_family or ''),
|
||||
'model': str(profile_model or ''),
|
||||
'loras': _norm_loras(loras_src),
|
||||
'clip_type': str(profile_clip_type or ''),
|
||||
'loader_type': str(profile_loader_type or ''),
|
||||
'vae': str(profile.get('vae', '') or ''),
|
||||
'clip': [str(x or '') for x in clip_raw if str(x or '').strip()],
|
||||
'sampler': {
|
||||
'steps': _norm_int(sampler_in.get('steps', 20), 20),
|
||||
'cfg': _norm_num(sampler_in.get('cfg', 5.0), 5.0),
|
||||
'denoise': _norm_num(sampler_in.get('denoise', 1.0), 1.0),
|
||||
'seed': _norm_int(sampler_in.get('seed', 0), 0),
|
||||
'sampler_name': str(sampler_in.get('sampler_name', 'euler') or 'euler'),
|
||||
'scheduler': str(sampler_in.get('scheduler', 'simple') or 'simple'),
|
||||
},
|
||||
'resolution': {
|
||||
'width': _norm_int(resolution_in.get('width', 768), 768),
|
||||
'height': _norm_int(resolution_in.get('height', 1280), 1280),
|
||||
'batch_size': _norm_int(resolution_in.get('batch_size', 1), 1),
|
||||
'length': resolution_in.get('length'),
|
||||
},
|
||||
}
|
||||
base_recipe_for_output['models'][slot_key] = slot_block
|
||||
except Exception as e:
|
||||
print(f"[RecipeBuilder] Warning: failed to apply _slot_profiles: {e}")
|
||||
|
||||
output_wf = _builder_output_to_v2(
|
||||
simplified_wf,
|
||||
mode=builder_mode,
|
||||
send_as_slot=send_model_slot,
|
||||
base_recipe_data=wf_data if isinstance(wf_data, dict) else None,
|
||||
base_recipe_data=base_recipe_for_output,
|
||||
)
|
||||
|
||||
# ── Build UI info for JS (always, even if generation fails) ───────
|
||||
@@ -1905,3 +2033,10 @@ class WorkflowBuilderWan(WorkflowBuilder):
|
||||
prompt=prompt,
|
||||
builder_mode="wan",
|
||||
)
|
||||
|
||||
|
||||
class WorkflowBuilderMulti(WorkflowBuilder):
|
||||
DESCRIPTION = (
|
||||
"Recipe Builder (Multi Model). Single builder UI with 4 model slots "
|
||||
"(A/B/C/D) and per-slot settings."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user