Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e08d18c783 | ||
|
|
769d40f9f5 | ||
|
|
eef07948ac |
@@ -242,6 +242,9 @@ Preference settings can be found in ComfyUI Settings → Prompt Manager
|
||||
|
||||
## Changelog
|
||||
|
||||
### version 1.12.7
|
||||
- Quality of life improvements and added option to change the Strenght of any Lora in Manager, so we can tweak Extracted Workflows Live.
|
||||
|
||||
### version 1.12.6
|
||||
- Tweak to caching behavior for prompt extractor and prompt manager advanced
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
ComfyUI Prompt Manager - A simple custom node for saving and reusing prompts
|
||||
A prompt management system for ComfyUI with LLM input support
|
||||
"""
|
||||
__version__ = "1.12.6"
|
||||
__version__ = "1.12.7"
|
||||
__author__ = "François Beaudry"
|
||||
__license__ = "MIT"
|
||||
|
||||
|
||||
+24
-10
@@ -342,17 +342,31 @@ app.registerExtension({
|
||||
name: "PromptExtractor",
|
||||
|
||||
async setup() {
|
||||
// Listen for cache refresh requests from Python backend
|
||||
api.addEventListener("prompt-extractor-refresh-cache", (event) => {
|
||||
const { node_id, filename, frame_position } = event.detail;
|
||||
// Listen for frame extraction requests from Python backend
|
||||
api.addEventListener("prompt-extractor-extract-frame", async (event) => {
|
||||
const { filename, frame_position } = event.detail;
|
||||
console.log(`[PromptExtractor] Received extraction request for ${filename} at position ${frame_position}`);
|
||||
|
||||
console.log(`[PromptExtractor] Received cache refresh request for node ${node_id}: ${filename}`);
|
||||
|
||||
// Find the node by ID
|
||||
const node = app.graph._nodes_by_id?.[node_id];
|
||||
if (node && filename) {
|
||||
// Trigger re-extraction
|
||||
loadAndDisplayImage(node, filename);
|
||||
// Find the node with this filename
|
||||
if (app.graph && app.graph._nodes) {
|
||||
for (const node of app.graph._nodes) {
|
||||
if (node.type === "PromptExtractor") {
|
||||
const imageWidget = node.widgets?.find(w => w.name === "image");
|
||||
const frameWidget = node.widgets?.find(w => w.name === "frame_position");
|
||||
|
||||
if (imageWidget && imageWidget.value === filename) {
|
||||
// Update frame position if provided
|
||||
if (frameWidget && frame_position !== undefined) {
|
||||
frameWidget.value = frame_position;
|
||||
}
|
||||
|
||||
// Trigger extraction
|
||||
await loadAndDisplayImage(node, filename);
|
||||
console.log(`[PromptExtractor] Extracted and cached frame for ${filename}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
+363
-19
@@ -6,6 +6,39 @@ import { api } from "../../scripts/api.js";
|
||||
* Extends prompt management with LoRA stack support and toggleable LoRA displays
|
||||
*/
|
||||
|
||||
// ========================
|
||||
// Canvas Wheel Event Helper
|
||||
// ========================
|
||||
|
||||
/**
|
||||
* Forward wheel events from a DOM element to the LiteGraph canvas for zooming
|
||||
* This allows users to zoom the canvas even when hovering over node UI elements
|
||||
*/
|
||||
function forwardWheelToCanvas(element) {
|
||||
element.addEventListener("wheel", (e) => {
|
||||
// Get the LiteGraph canvas element
|
||||
const canvas = app.canvas?.canvas || document.querySelector("canvas.lgraphcanvas");
|
||||
if (canvas) {
|
||||
// Create and dispatch a new wheel event to the canvas
|
||||
const newEvent = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
clientX: e.clientX,
|
||||
clientY: e.clientY,
|
||||
deltaX: e.deltaX,
|
||||
deltaY: e.deltaY,
|
||||
deltaZ: e.deltaZ,
|
||||
deltaMode: e.deltaMode,
|
||||
ctrlKey: e.ctrlKey,
|
||||
shiftKey: e.shiftKey,
|
||||
altKey: e.altKey,
|
||||
metaKey: e.metaKey
|
||||
});
|
||||
canvas.dispatchEvent(newEvent);
|
||||
}
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
// ========================
|
||||
// LoRA Manager Integration
|
||||
// ========================
|
||||
@@ -83,10 +116,19 @@ app.registerExtension({
|
||||
node.currentLorasB = [];
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = []; // Original strengths for reset
|
||||
node.originalLorasB = []; // Original strengths for reset
|
||||
node.currentTriggerWords = []; // From connected input
|
||||
node.savedTriggerWords = []; // From saved prompt
|
||||
node.connectedThumbnail = null; // Thumbnail from connected image (set during execution)
|
||||
|
||||
// Track the last known state of inputs and prompt to detect changes
|
||||
// When any of these change, we clear toggle states and reload fresh
|
||||
node.lastKnownPromptKey = ""; // "category|promptName"
|
||||
node.lastKnownInputLorasA = ""; // Signature of input loras
|
||||
node.lastKnownInputLorasB = ""; // Signature of input loras
|
||||
node.lastKnownPromptInput = ""; // Text from connected prompt input (extractor)
|
||||
|
||||
// Track last saved state for unsaved changes detection
|
||||
node.lastSavedState = {
|
||||
text: "",
|
||||
@@ -131,30 +173,140 @@ app.registerExtension({
|
||||
const newLorasA = event.detail.loras_a || [];
|
||||
const newLorasB = event.detail.loras_b || [];
|
||||
const newTriggerWords = event.detail.trigger_words || [];
|
||||
const inputLorasA = event.detail.input_loras_a || [];
|
||||
const inputLorasB = event.detail.input_loras_b || [];
|
||||
// Explicit list of unavailable lora names from Python
|
||||
const unavailableLorasA = new Set((event.detail.unavailable_loras_a || []).map(n => n.toLowerCase()));
|
||||
const unavailableLorasB = new Set((event.detail.unavailable_loras_b || []).map(n => n.toLowerCase()));
|
||||
|
||||
// Store connected thumbnail for use when saving
|
||||
this.connectedThumbnail = event.detail.connected_thumbnail || null;
|
||||
|
||||
// Simple comparison: if the entire list is identical (same order, same data), no change
|
||||
const lorasAChanged = JSON.stringify(newLorasA) !== JSON.stringify(this.currentLorasA);
|
||||
const lorasBChanged = JSON.stringify(newLorasB) !== JSON.stringify(this.currentLorasB);
|
||||
const newConnectedTriggers = newTriggerWords.filter(t => t.source === 'connected');
|
||||
const triggerWordsChanged = JSON.stringify(newConnectedTriggers) !== JSON.stringify(this.currentTriggerWords);
|
||||
// Get current prompt key from widgets
|
||||
const categoryWidget = this.widgets?.find(w => w.name === "category");
|
||||
const promptWidget = this.widgets?.find(w => w.name === "name");
|
||||
const currentPromptKey = `${categoryWidget?.value || ""}|${promptWidget?.value || ""}`;
|
||||
|
||||
// Update if data changed
|
||||
if (lorasAChanged || lorasBChanged || triggerWordsChanged) {
|
||||
// Update current loras from connected inputs
|
||||
this.currentLorasA = newLorasA;
|
||||
this.currentLorasB = newLorasB;
|
||||
// Create signatures of input loras (just names, sorted)
|
||||
const inputLorasASignature = inputLorasA.map(l => l.name).sort().join('|');
|
||||
const inputLorasBSignature = inputLorasB.map(l => l.name).sort().join('|');
|
||||
|
||||
// Update current trigger words (only connected ones)
|
||||
// Don't merge into savedTriggerWords - keep them separate
|
||||
// savedTriggerWords should only contain what was loaded from the prompt
|
||||
// Get the prompt input text (from extractor)
|
||||
const promptInputText = event.detail.prompt_input || "";
|
||||
|
||||
// Check what has changed
|
||||
const promptChanged = currentPromptKey !== this.lastKnownPromptKey;
|
||||
const inputLorasChanged = inputLorasASignature !== this.lastKnownInputLorasA ||
|
||||
inputLorasBSignature !== this.lastKnownInputLorasB;
|
||||
const promptInputChanged = promptInputText !== this.lastKnownPromptInput;
|
||||
|
||||
// Determine if we should reset:
|
||||
// 1. Prompt dropdown changed → reset
|
||||
// 2. BOTH prompt input text AND loras changed → new extraction, reset
|
||||
// 3. ONLY loras changed → user modified strengths, don't reset
|
||||
const isNewExtraction = promptInputChanged && inputLorasChanged;
|
||||
const shouldReset = promptChanged || isNewExtraction;
|
||||
|
||||
// DEBUG: Always log the state
|
||||
console.log("[PromptManagerAdvanced] Update received:", {
|
||||
promptChanged,
|
||||
inputLorasChanged,
|
||||
promptInputChanged,
|
||||
isNewExtraction,
|
||||
shouldReset,
|
||||
promptInputText: promptInputText.substring(0, 50) + "...",
|
||||
lastKnownPromptInput: this.lastKnownPromptInput.substring(0, 50) + "...",
|
||||
inputLorasASignature,
|
||||
lastKnownInputLorasA: this.lastKnownInputLorasA
|
||||
});
|
||||
|
||||
// Always update tracking signatures
|
||||
this.lastKnownInputLorasA = inputLorasASignature;
|
||||
this.lastKnownInputLorasB = inputLorasBSignature;
|
||||
this.lastKnownPromptInput = promptInputText;
|
||||
|
||||
// Clear and reload when needed
|
||||
if (shouldReset) {
|
||||
console.log("[PromptManagerAdvanced] Resetting - Prompt changed:", promptChanged, "New extraction:", isNewExtraction);
|
||||
|
||||
// Update prompt tracking
|
||||
this.lastKnownPromptKey = currentPromptKey;
|
||||
|
||||
// Clear ALL loras - we'll reload fresh
|
||||
this.currentLorasA = [];
|
||||
this.currentLorasB = [];
|
||||
this.savedLorasA = [];
|
||||
this.savedLorasB = [];
|
||||
this.originalLorasA = []; // Clear original strengths too
|
||||
this.originalLorasB = [];
|
||||
|
||||
// Reload saved loras from prompt to get clean toggle states
|
||||
// Use Python's unavailable list directly - it's the source of truth
|
||||
if (this.prompts && categoryWidget && promptWidget) {
|
||||
const promptData = this.prompts[categoryWidget.value]?.[promptWidget.value];
|
||||
if (promptData) {
|
||||
this.savedLorasA = (promptData.loras_a || []).map(lora => ({
|
||||
...lora,
|
||||
active: lora.active !== false,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0,
|
||||
available: !unavailableLorasA.has(lora.name.toLowerCase())
|
||||
}));
|
||||
this.savedLorasB = (promptData.loras_b || []).map(lora => ({
|
||||
...lora,
|
||||
active: lora.active !== false,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0,
|
||||
available: !unavailableLorasB.has(lora.name.toLowerCase())
|
||||
}));
|
||||
// Store original strengths for reset functionality
|
||||
this.originalLorasA = (promptData.loras_a || []).map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
this.originalLorasB = (promptData.loras_b || []).map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Set current loras from input (these are the loras from connected nodes)
|
||||
this.currentLorasA = inputLorasA.map(l => ({ ...l, source: 'current' }));
|
||||
this.currentLorasB = inputLorasB.map(l => ({ ...l, source: 'current' }));
|
||||
|
||||
// Also store input lora original strengths for reset
|
||||
inputLorasA.forEach(l => {
|
||||
if (!this.originalLorasA.find(o => o.name.toLowerCase() === l.name.toLowerCase())) {
|
||||
this.originalLorasA.push({ name: l.name, strength: l.strength ?? l.model_strength ?? 1.0 });
|
||||
}
|
||||
});
|
||||
inputLorasB.forEach(l => {
|
||||
if (!this.originalLorasB.find(o => o.name.toLowerCase() === l.name.toLowerCase())) {
|
||||
this.originalLorasB.push({ name: l.name, strength: l.strength ?? l.model_strength ?? 1.0 });
|
||||
}
|
||||
});
|
||||
|
||||
// Update connected trigger words
|
||||
const newConnectedTriggers = newTriggerWords.filter(t => t.source === 'connected');
|
||||
this.currentTriggerWords = newConnectedTriggers;
|
||||
|
||||
// Refresh displays (display function handles merging for UI)
|
||||
// Refresh displays
|
||||
updateLoraDisplays(this);
|
||||
updateTriggerWordsDisplay(this);
|
||||
} else {
|
||||
// No major change - just update current loras if they differ
|
||||
const lorasAChanged = JSON.stringify(inputLorasA) !== JSON.stringify(this.currentLorasA.map(l => ({ name: l.name, strength: l.strength })));
|
||||
const lorasBChanged = JSON.stringify(inputLorasB) !== JSON.stringify(this.currentLorasB.map(l => ({ name: l.name, strength: l.strength })));
|
||||
const newConnectedTriggers = newTriggerWords.filter(t => t.source === 'connected');
|
||||
const triggerWordsChanged = JSON.stringify(newConnectedTriggers) !== JSON.stringify(this.currentTriggerWords);
|
||||
|
||||
if (lorasAChanged || lorasBChanged || triggerWordsChanged) {
|
||||
this.currentLorasA = inputLorasA.map(l => ({ ...l, source: 'current' }));
|
||||
this.currentLorasB = inputLorasB.map(l => ({ ...l, source: 'current' }));
|
||||
this.currentTriggerWords = newConnectedTriggers;
|
||||
|
||||
updateLoraDisplays(this);
|
||||
updateTriggerWordsDisplay(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle use_prompt_input toggle state for text widget
|
||||
@@ -245,15 +397,27 @@ app.registerExtension({
|
||||
if (lorasAIndex >= 0 && info.widgets_values[lorasAIndex]) {
|
||||
try {
|
||||
node.savedLorasA = JSON.parse(info.widgets_values[lorasAIndex]);
|
||||
// Store original strengths for reset functionality
|
||||
node.originalLorasA = node.savedLorasA.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
} catch (e) {
|
||||
node.savedLorasA = [];
|
||||
node.originalLorasA = [];
|
||||
}
|
||||
}
|
||||
if (lorasBIndex >= 0 && info.widgets_values[lorasBIndex]) {
|
||||
try {
|
||||
node.savedLorasB = JSON.parse(info.widgets_values[lorasBIndex]);
|
||||
// Store original strengths for reset functionality
|
||||
node.originalLorasB = node.savedLorasB.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
} catch (e) {
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasB = [];
|
||||
}
|
||||
}
|
||||
if (triggerWordsIndex >= 0 && info.widgets_values[triggerWordsIndex]) {
|
||||
@@ -281,9 +445,13 @@ app.registerExtension({
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fresh load - clear current loras
|
||||
// Fresh load - clear current loras and reset tracking
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.lastKnownPromptKey = "";
|
||||
node.lastKnownInputLorasA = "";
|
||||
node.lastKnownInputLorasB = "";
|
||||
// Note: originalLoras are preserved from savedLoras restoration above
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,6 +810,9 @@ function createLoraDisplayContainer(title, stackId, node) {
|
||||
// Prevent default context menu on container (LoRA tags have their own)
|
||||
container.addEventListener("contextmenu", (e) => e.preventDefault());
|
||||
|
||||
// Forward wheel events to canvas for zooming
|
||||
forwardWheelToCanvas(container);
|
||||
|
||||
// Title bar with label
|
||||
const titleBar = document.createElement("div");
|
||||
Object.assign(titleBar.style, {
|
||||
@@ -662,6 +833,29 @@ function createLoraDisplayContainer(title, stackId, node) {
|
||||
});
|
||||
titleBar.appendChild(titleLabel);
|
||||
|
||||
// Button container for Reset and Toggle All
|
||||
const btnContainer = document.createElement("div");
|
||||
Object.assign(btnContainer.style, {
|
||||
display: "flex",
|
||||
gap: "4px"
|
||||
});
|
||||
|
||||
// Reset button to restore original strength values
|
||||
const resetBtn = document.createElement("button");
|
||||
resetBtn.textContent = "Reset Strength";
|
||||
resetBtn.title = "Reset all strength values to their original values";
|
||||
Object.assign(resetBtn.style, {
|
||||
fontSize: "10px",
|
||||
padding: "2px 8px",
|
||||
backgroundColor: "#333",
|
||||
color: "#ccc",
|
||||
border: "1px solid #555",
|
||||
borderRadius: "6px",
|
||||
cursor: "pointer"
|
||||
});
|
||||
resetBtn.onclick = () => resetLoraStrengths(node, stackId);
|
||||
btnContainer.appendChild(resetBtn);
|
||||
|
||||
// Toggle All button
|
||||
const toggleAllBtn = document.createElement("button");
|
||||
toggleAllBtn.textContent = "Toggle All";
|
||||
@@ -675,7 +869,9 @@ function createLoraDisplayContainer(title, stackId, node) {
|
||||
cursor: "pointer"
|
||||
});
|
||||
toggleAllBtn.onclick = () => toggleAllLoras(node, stackId);
|
||||
titleBar.appendChild(toggleAllBtn);
|
||||
btnContainer.appendChild(toggleAllBtn);
|
||||
|
||||
titleBar.appendChild(btnContainer);
|
||||
|
||||
container.appendChild(titleBar);
|
||||
|
||||
@@ -812,7 +1008,7 @@ function createLoraTag(lora, index, stackId, node) {
|
||||
tag.dataset.stackId = stackId;
|
||||
|
||||
const isActive = lora.active !== false;
|
||||
const isAvailable = lora.available !== false;
|
||||
const isAvailable = lora.available === true;
|
||||
const isFromInput = lora.fromInput === true || lora.source === 'current'; // From connected input
|
||||
const strength = parseFloat(lora.strength ?? lora.model_strength ?? 1.0) || 1.0;
|
||||
|
||||
@@ -1215,6 +1411,10 @@ function setLoraStrength(node, stackId, index, newStrength) {
|
||||
|
||||
if (loraList[index]) {
|
||||
loraList[index].strength = newStrength;
|
||||
// Move to saved so the strength persists (connected loras need to become saved to persist changes)
|
||||
if (loraList[index].source === 'current') {
|
||||
loraList[index].source = 'saved';
|
||||
}
|
||||
|
||||
if (!useLoraInput) {
|
||||
// Only update saved loras when use_lora_input is off
|
||||
@@ -1284,6 +1484,57 @@ function toggleAllLoras(node, stackId) {
|
||||
app.graph.setDirtyCanvas(true, true);
|
||||
}
|
||||
|
||||
function resetLoraStrengths(node, stackId) {
|
||||
// Reset all lora strengths to their original values
|
||||
const useLoraInputWidget = node.widgets?.find(w => w.name === "use_lora_input");
|
||||
const useLoraInput = useLoraInputWidget?.value !== false;
|
||||
|
||||
// Get original strengths
|
||||
const originalLoras = stackId === "a" ? (node.originalLorasA || []) : (node.originalLorasB || []);
|
||||
|
||||
// Build a map of original strengths by name (case-insensitive)
|
||||
const originalMap = new Map();
|
||||
originalLoras.forEach(lora => {
|
||||
originalMap.set(lora.name.toLowerCase(), lora.strength);
|
||||
});
|
||||
|
||||
// Get the list that matches what's currently displayed
|
||||
let loraList;
|
||||
if (!useLoraInput) {
|
||||
loraList = stackId === "a" ? [...(node.savedLorasA || [])] : [...(node.savedLorasB || [])];
|
||||
} else {
|
||||
loraList = stackId === "a" ?
|
||||
mergeLoraLists(node.currentLorasA, node.savedLorasA) :
|
||||
mergeLoraLists(node.currentLorasB, node.savedLorasB);
|
||||
}
|
||||
|
||||
// Reset strengths to original values
|
||||
loraList.forEach(lora => {
|
||||
const originalStrength = originalMap.get(lora.name.toLowerCase());
|
||||
if (originalStrength !== undefined) {
|
||||
lora.strength = originalStrength;
|
||||
}
|
||||
});
|
||||
|
||||
// Update the lists
|
||||
if (!useLoraInput) {
|
||||
if (stackId === "a") {
|
||||
node.savedLorasA = loraList;
|
||||
} else {
|
||||
node.savedLorasB = loraList;
|
||||
}
|
||||
} else {
|
||||
if (stackId === "a") {
|
||||
updateLoraListFromMerged(node, "a", loraList);
|
||||
} else {
|
||||
updateLoraListFromMerged(node, "b", loraList);
|
||||
}
|
||||
}
|
||||
|
||||
updateLoraDisplays(node);
|
||||
app.graph.setDirtyCanvas(true, true);
|
||||
}
|
||||
|
||||
function updateLoraListFromMerged(node, stackId, mergedList) {
|
||||
// Separate back into current and saved lists based on source
|
||||
const currentLoras = [];
|
||||
@@ -1417,6 +1668,9 @@ function createTriggerWordsDisplayContainer(title, node) {
|
||||
// Prevent default context menu on container (trigger word tags have their own)
|
||||
container.addEventListener("contextmenu", (e) => e.preventDefault());
|
||||
|
||||
// Forward wheel events to canvas for zooming
|
||||
forwardWheelToCanvas(container);
|
||||
|
||||
// Title bar with label
|
||||
const titleBar = document.createElement("div");
|
||||
Object.assign(titleBar.style, {
|
||||
@@ -1886,6 +2140,9 @@ function addButtonBar(node) {
|
||||
// Prevent default context menu on button bar
|
||||
buttonContainer.addEventListener("contextmenu", (e) => e.preventDefault());
|
||||
|
||||
// Forward wheel events to canvas for zooming
|
||||
forwardWheelToCanvas(buttonContainer);
|
||||
|
||||
// Save Prompt button
|
||||
const savePromptBtn = createButton("Save Prompt", async () => {
|
||||
const categories = Object.keys(node.prompts || {}).sort((a, b) => a.localeCompare(b));
|
||||
@@ -2032,6 +2289,8 @@ function addButtonBar(node) {
|
||||
node.savedLorasB = [];
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.originalLorasA = []; // Clear original strengths too
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
|
||||
@@ -2177,6 +2436,22 @@ function setupCategoryChangeHandler(node) {
|
||||
originalCallback.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Clear all lora and trigger word data BEFORE loading new prompt
|
||||
// This ensures stale toggle states don't persist (same as "New Prompt" button)
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.originalLorasA = []; // Clear original strengths too
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
node.lastKnownPromptKey = "";
|
||||
node.lastKnownInputLorasA = "";
|
||||
node.lastKnownInputLorasB = "";
|
||||
updateLoraDisplays(node);
|
||||
updateTriggerWordsDisplay(node);
|
||||
|
||||
// Reload prompts from server to get latest changes from other tabs
|
||||
await loadPrompts(node);
|
||||
|
||||
@@ -2196,6 +2471,8 @@ function setupCategoryChangeHandler(node) {
|
||||
node.savedLorasB = [];
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
updateLoraDisplays(node);
|
||||
@@ -2258,6 +2535,22 @@ function setupCategoryChangeHandler(node) {
|
||||
originalPromptCallback.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Clear all lora and trigger word data BEFORE loading new prompt
|
||||
// This ensures stale toggle states don't persist (same as "New Prompt" button)
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.originalLorasA = []; // Clear original strengths too
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
node.lastKnownPromptKey = "";
|
||||
node.lastKnownInputLorasA = "";
|
||||
node.lastKnownInputLorasB = "";
|
||||
updateLoraDisplays(node);
|
||||
updateTriggerWordsDisplay(node);
|
||||
|
||||
// Reload prompts from server to get latest changes from other tabs
|
||||
await loadPrompts(node);
|
||||
|
||||
@@ -2395,9 +2688,20 @@ function setupUseExternalToggleHandler(node) {
|
||||
|
||||
node.savedLorasA = lorasA;
|
||||
node.savedLorasB = lorasB;
|
||||
// Store original strengths for reset functionality
|
||||
node.originalLorasA = lorasA.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
node.originalLorasB = lorasB.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
} else {
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2486,9 +2790,16 @@ async function loadPromptData(node, category, promptName) {
|
||||
node.savedLorasB = [];
|
||||
node.currentLorasA = [];
|
||||
node.currentLorasB = [];
|
||||
node.originalLorasA = []; // Clear original strengths too
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
|
||||
// Reset tracking - forces a full reload on next execution
|
||||
node.lastKnownPromptKey = "";
|
||||
node.lastKnownInputLorasA = "";
|
||||
node.lastKnownInputLorasB = "";
|
||||
|
||||
if (!node.prompts || !node.prompts[category] || !node.prompts[category][promptName]) {
|
||||
if (textWidget) textWidget.value = "";
|
||||
updateLoraDisplays(node);
|
||||
@@ -2540,11 +2851,12 @@ async function loadPromptData(node, category, promptName) {
|
||||
|
||||
if (data.success && data.results) {
|
||||
// Update availability status
|
||||
// Use explicit check - if not found in results OR false, mark unavailable
|
||||
lorasA.forEach(lora => {
|
||||
lora.available = data.results[lora.name] !== false;
|
||||
lora.available = data.results[lora.name] === true;
|
||||
});
|
||||
lorasB.forEach(lora => {
|
||||
lora.available = data.results[lora.name] !== false;
|
||||
lora.available = data.results[lora.name] === true;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -2556,6 +2868,16 @@ async function loadPromptData(node, category, promptName) {
|
||||
node.savedLorasB = lorasB;
|
||||
node.savedTriggerWords = triggerWords;
|
||||
|
||||
// Store original strengths for reset functionality
|
||||
node.originalLorasA = lorasA.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
node.originalLorasB = lorasB.map(lora => ({
|
||||
name: lora.name,
|
||||
strength: lora.strength ?? lora.model_strength ?? 1.0
|
||||
}));
|
||||
|
||||
// Update last saved state for change detection
|
||||
updateLastSavedState(node);
|
||||
|
||||
@@ -2659,6 +2981,8 @@ async function createCategory(node, categoryName) {
|
||||
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
updateLoraDisplays(node);
|
||||
@@ -2728,6 +3052,17 @@ async function savePrompt(node, category, name, text, lorasA, lorasB, triggerWor
|
||||
node.savedLorasA = lorasA;
|
||||
node.savedLorasB = lorasB;
|
||||
node.savedTriggerWords = triggerWords || [];
|
||||
|
||||
// Update original strengths to match saved values (Reset now resets to saved state)
|
||||
node.originalLorasA = lorasA.map(l => ({
|
||||
name: l.name,
|
||||
strength: l.strength ?? l.model_strength ?? 1.0
|
||||
}));
|
||||
node.originalLorasB = lorasB.map(l => ({
|
||||
name: l.name,
|
||||
strength: l.strength ?? l.model_strength ?? 1.0
|
||||
}));
|
||||
|
||||
updateLoraDisplays(node);
|
||||
updateTriggerWordsDisplay(node);
|
||||
|
||||
@@ -2756,6 +3091,8 @@ async function deleteCategory(node, category) {
|
||||
node.prompts = data.prompts;
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
updateDropdowns(node);
|
||||
@@ -2790,6 +3127,8 @@ async function deletePrompt(node, category, name) {
|
||||
node.prompts = data.prompts;
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
updateDropdowns(node);
|
||||
@@ -3185,6 +3524,8 @@ async function importPromptsJSON(node) {
|
||||
// Clear current state if no prompt selected
|
||||
node.savedLorasA = [];
|
||||
node.savedLorasB = [];
|
||||
node.originalLorasA = [];
|
||||
node.originalLorasB = [];
|
||||
node.savedTriggerWords = [];
|
||||
node.currentTriggerWords = [];
|
||||
updateLoraDisplays(node);
|
||||
@@ -4063,6 +4404,9 @@ function createPromptSelectorWidget(node) {
|
||||
// Prevent default context menu on prompt selector
|
||||
container.addEventListener("contextmenu", (e) => e.preventDefault());
|
||||
|
||||
// Forward wheel events to canvas for zooming
|
||||
forwardWheelToCanvas(container);
|
||||
|
||||
// Left arrow button
|
||||
const leftArrow = document.createElement("button");
|
||||
leftArrow.textContent = "◀";
|
||||
|
||||
+43
-33
@@ -367,27 +367,27 @@ def base64_to_tensor(base64_data):
|
||||
import base64
|
||||
import io
|
||||
from PIL import Image
|
||||
|
||||
|
||||
# Remove data URL prefix (data:image/png;base64,)
|
||||
if ',' in base64_data:
|
||||
base64_data = base64_data.split(',', 1)[1]
|
||||
|
||||
|
||||
# Decode base64 to bytes
|
||||
img_bytes = base64.b64decode(base64_data)
|
||||
|
||||
|
||||
# Load as PIL Image
|
||||
img = Image.open(io.BytesIO(img_bytes))
|
||||
|
||||
|
||||
# Convert to RGB if needed
|
||||
if img.mode != 'RGB':
|
||||
img = img.convert('RGB')
|
||||
|
||||
|
||||
# Convert to numpy array and normalize to 0-1
|
||||
img_array = np.array(img).astype(np.float32) / 255.0
|
||||
|
||||
|
||||
# Convert to torch tensor with batch dimension (B, H, W, C)
|
||||
img_tensor = torch.from_numpy(img_array).unsqueeze(0)
|
||||
|
||||
|
||||
return img_tensor
|
||||
except Exception as e:
|
||||
print(f"[PromptExtractor] Error converting base64 to tensor: {e}")
|
||||
@@ -399,16 +399,41 @@ def get_cached_video_frame(filename, frame_position):
|
||||
Retrieve cached video frame extracted by JavaScript at the specified position.
|
||||
frame_position: float from 0.0 to 1.0 representing position in video
|
||||
Returns a single frame tensor.
|
||||
If cache is missing, requests extraction from JavaScript and waits briefly.
|
||||
"""
|
||||
import time
|
||||
|
||||
if filename not in _video_frames_cache:
|
||||
print(f"[PromptExtractor] No cached frame for: {filename}")
|
||||
return None
|
||||
|
||||
print(f"[PromptExtractor] Cache missing for: {filename}, requesting extraction...")
|
||||
|
||||
# Broadcast directly to JavaScript clients
|
||||
try:
|
||||
server.PromptServer.instance.send_sync("prompt-extractor-extract-frame", {
|
||||
"filename": filename,
|
||||
"frame_position": frame_position
|
||||
})
|
||||
|
||||
# Wait briefly for JavaScript to extract and cache the frame
|
||||
max_wait = 5 # seconds
|
||||
start_time = time.time()
|
||||
while filename not in _video_frames_cache and (time.time() - start_time) < max_wait:
|
||||
time.sleep(0.1)
|
||||
|
||||
if filename in _video_frames_cache:
|
||||
print(f"[PromptExtractor] Frame cached successfully for: {filename}")
|
||||
else:
|
||||
print(f"[PromptExtractor] Timeout waiting for frame extraction: {filename}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"[PromptExtractor] Error requesting frame extraction: {e}")
|
||||
return None
|
||||
|
||||
frame_data = _video_frames_cache[filename]
|
||||
|
||||
|
||||
# Convert base64 frame to tensor
|
||||
frame_tensor = base64_to_tensor(frame_data)
|
||||
|
||||
|
||||
return frame_tensor
|
||||
|
||||
|
||||
@@ -1426,7 +1451,6 @@ class PromptExtractor:
|
||||
extracted_lora_stack_a = []
|
||||
extracted_lora_stack_b = []
|
||||
image_tensor = None
|
||||
needs_cache_refresh = False
|
||||
|
||||
# Handle None or missing image parameter
|
||||
if image is None:
|
||||
@@ -1491,13 +1515,10 @@ class PromptExtractor:
|
||||
# Get frame cached by JavaScript at the specified position
|
||||
filename = os.path.basename(resolved_path)
|
||||
image_tensor = get_cached_video_frame(filename, frame_position)
|
||||
|
||||
# If no cached data, flag for JavaScript re-extraction
|
||||
if image_tensor is None or prompt_data is None:
|
||||
print("[PromptExtractor] Cache missing - requesting JavaScript to re-extract")
|
||||
needs_cache_refresh = True
|
||||
if image_tensor is None:
|
||||
image_tensor = get_placeholder_image_tensor()
|
||||
|
||||
# If no cached frame, use placeholder (JavaScript will cache before execution)
|
||||
if image_tensor is None:
|
||||
image_tensor = get_placeholder_image_tensor()
|
||||
|
||||
# Parse the extracted data
|
||||
if prompt_data or workflow_data:
|
||||
@@ -1586,14 +1607,6 @@ class PromptExtractor:
|
||||
# Save preview image for display
|
||||
preview_images = self.save_preview_images(image_tensor)
|
||||
|
||||
# If cache was missing, send event to frontend to trigger re-extraction
|
||||
if needs_cache_refresh and unique_id and image:
|
||||
server.PromptServer.instance.send_sync("prompt-extractor-refresh-cache", {
|
||||
"node_id": unique_id,
|
||||
"filename": image,
|
||||
"frame_position": frame_position
|
||||
})
|
||||
|
||||
# Ensure strings are never empty - ComfyUI treats "" as "no connection"
|
||||
# Use single space " " to indicate "connected but no content found"
|
||||
if not positive_prompt:
|
||||
@@ -1637,8 +1650,7 @@ class PromptExtractor:
|
||||
def IS_CHANGED(cls, image, frame_position, **kwargs):
|
||||
"""
|
||||
Check if the file has changed or if frame position changed.
|
||||
Returns a tuple of (file_modification_time, frame_position) to track both changes.
|
||||
Note: float('nan') must NOT be used - NaN != NaN, so ComfyUI would always re-execute.
|
||||
Returns a tuple of (file_modification_time, frame_position) to track changes.
|
||||
"""
|
||||
mtime = "no_file"
|
||||
if image:
|
||||
@@ -1651,7 +1663,5 @@ class PromptExtractor:
|
||||
mtime = os.path.getmtime(potential_path)
|
||||
elif os.path.exists(file_path):
|
||||
mtime = os.path.getmtime(file_path)
|
||||
|
||||
# Return tuple of (file_mtime, frame_position) to track both changes
|
||||
# This ensures re-execution only when file OR frame position changes
|
||||
|
||||
return (mtime, frame_position)
|
||||
|
||||
+119
-72
@@ -78,36 +78,6 @@ def get_available_loras():
|
||||
return lora_files
|
||||
|
||||
|
||||
def resolve_lora_path(lora_name):
|
||||
"""
|
||||
Resolve a LoRA name to its full path using ComfyUI's folder system.
|
||||
Returns (full_path, found) tuple.
|
||||
"""
|
||||
lora_files = get_available_loras()
|
||||
|
||||
# Try exact match first (with extension)
|
||||
for lora_file in lora_files:
|
||||
if lora_file == lora_name:
|
||||
return folder_paths.get_full_path("loras", lora_file), True
|
||||
|
||||
# Try matching by name without extension
|
||||
lora_name_lower = lora_name.lower()
|
||||
for lora_file in lora_files:
|
||||
file_name_no_ext = os.path.splitext(os.path.basename(lora_file))[0]
|
||||
if file_name_no_ext.lower() == lora_name_lower:
|
||||
return folder_paths.get_full_path("loras", lora_file), True
|
||||
|
||||
# Try partial match (lora_name might be just the filename, lora_file might have subdirs)
|
||||
for lora_file in lora_files:
|
||||
file_name = os.path.basename(lora_file)
|
||||
file_name_no_ext = os.path.splitext(file_name)[0]
|
||||
if file_name_no_ext.lower() == lora_name_lower or file_name.lower() == lora_name_lower:
|
||||
return folder_paths.get_full_path("loras", lora_file), True
|
||||
|
||||
# Not found
|
||||
return None, False
|
||||
|
||||
|
||||
def fuzzy_match_lora(lora_name, lora_files):
|
||||
"""
|
||||
Attempt to find a matching LoRA using fuzzy matching.
|
||||
@@ -119,6 +89,17 @@ def fuzzy_match_lora(lora_name, lora_files):
|
||||
"""
|
||||
import re
|
||||
|
||||
# Known LoRA file extensions - only strip these, not arbitrary dots in names
|
||||
lora_extensions = {'.safetensors', '.ckpt', '.pt', '.bin', '.pth'}
|
||||
|
||||
def strip_lora_extension(name):
|
||||
"""Remove only known LoRA file extensions, not arbitrary dots in names."""
|
||||
name_lower = name.lower()
|
||||
for ext in lora_extensions:
|
||||
if name_lower.endswith(ext):
|
||||
return name[:-len(ext)]
|
||||
return name
|
||||
|
||||
# Tokens to remove for fuzzy matching (case-insensitive)
|
||||
# Order matters: remove longer tokens first to avoid partial matches
|
||||
wan_tokens = ['wan_2_2', 'wan22', 'wan2.2', '20epoc', 'a14b', '14b', 'i2v', 't2v']
|
||||
@@ -145,13 +126,17 @@ def fuzzy_match_lora(lora_name, lora_files):
|
||||
parts = [p for p in re.split(r'[_-]', name_lower) if p]
|
||||
return parts
|
||||
|
||||
# Normalize the search name
|
||||
search_parts = normalize_name(os.path.splitext(lora_name)[0])
|
||||
# Normalize the search name - use our extension stripper, not splitext
|
||||
search_parts = normalize_name(strip_lora_extension(lora_name))
|
||||
search_set = set(search_parts)
|
||||
|
||||
# If search_set is empty after normalization, we can't do fuzzy matching
|
||||
if not search_set:
|
||||
return None, False
|
||||
|
||||
candidates = []
|
||||
for lora_file in lora_files:
|
||||
file_name_no_ext = os.path.splitext(os.path.basename(lora_file))[0]
|
||||
file_name_no_ext = strip_lora_extension(os.path.basename(lora_file))
|
||||
file_parts = normalize_name(file_name_no_ext)
|
||||
file_set = set(file_parts)
|
||||
|
||||
@@ -293,7 +278,7 @@ class PromptManagerAdvanced:
|
||||
lora_stack_a = kwargs.get('lora_stack_a', None)
|
||||
lora_stack_b = kwargs.get('lora_stack_b', None)
|
||||
trigger_words = kwargs.get('trigger_words', None)
|
||||
|
||||
|
||||
# Return tuple of all values that should trigger re-execution when changed
|
||||
# Convert lists/objects to strings for hashable comparison
|
||||
return (
|
||||
@@ -441,14 +426,15 @@ class PromptManagerAdvanced:
|
||||
if not isinstance(toggle_data, list):
|
||||
return list(lora_stack)
|
||||
|
||||
# Create a map of toggle states by lora name
|
||||
# Create a map of toggle states by lora name (case-insensitive)
|
||||
toggle_map = {}
|
||||
for item in toggle_data:
|
||||
if isinstance(item, dict):
|
||||
name = item.get('name', '')
|
||||
toggle_map[name] = {
|
||||
toggle_map[name.lower()] = {
|
||||
'active': item.get('active', True),
|
||||
'strength': item.get('strength')
|
||||
'strength': item.get('strength'),
|
||||
'original_name': name # Keep original for debugging
|
||||
}
|
||||
|
||||
# Filter and adjust lora stack
|
||||
@@ -459,8 +445,11 @@ class PromptManagerAdvanced:
|
||||
# Extract lora name from path
|
||||
lora_name = os.path.splitext(os.path.basename(lora_path))[0]
|
||||
|
||||
# Check toggle state
|
||||
toggle_state = toggle_map.get(lora_name, {'active': True, 'strength': None})
|
||||
# Check toggle state (case-insensitive lookup)
|
||||
toggle_state = toggle_map.get(lora_name.lower(), {'active': True, 'strength': None})
|
||||
|
||||
# Debug logging
|
||||
print(f"[PromptManagerAdvanced] Processing LoRA: {lora_name}, original_strength={model_strength}, toggle_strength={toggle_state.get('strength')}, active={toggle_state.get('active')}")
|
||||
|
||||
if not toggle_state['active']:
|
||||
continue # Skip inactive loras
|
||||
@@ -507,31 +496,6 @@ class PromptManagerAdvanced:
|
||||
# Not found
|
||||
return lora_path, False
|
||||
|
||||
def _resolve_lora_path(self, lora_path, lora_files):
|
||||
"""
|
||||
Try to resolve a LoRA path to an available local LoRA.
|
||||
First checks if the exact path exists, then searches by name.
|
||||
|
||||
Args:
|
||||
lora_path: The original path from the stack
|
||||
lora_files: List of available LoRA files
|
||||
|
||||
Returns:
|
||||
Resolved path if found, original path otherwise
|
||||
"""
|
||||
# Check if exact path exists
|
||||
if lora_path in lora_files:
|
||||
return lora_path
|
||||
|
||||
# Try to find by name
|
||||
lora_name = os.path.splitext(os.path.basename(lora_path))[0]
|
||||
found_path, found = get_lora_relative_path(lora_name)
|
||||
if found:
|
||||
return found_path
|
||||
|
||||
# Return original path (will fail at load time, but at least shows in UI)
|
||||
return lora_path
|
||||
|
||||
def get_prompt(self, category, name, use_prompt_input, text="", use_lora_input=True, prompt_input="",
|
||||
lora_stack_a=None, lora_stack_b=None, trigger_words=None, thumbnail_image=None,
|
||||
unique_id=None, loras_a_toggle=None, loras_b_toggle=None, trigger_words_toggle=None):
|
||||
@@ -543,6 +507,12 @@ class PromptManagerAdvanced:
|
||||
else:
|
||||
output_text = text
|
||||
|
||||
# Capture the original input loras BEFORE any processing
|
||||
# These are used by the frontend to detect when inputs change
|
||||
# and clear toggle states accordingly
|
||||
input_loras_a = self._format_loras_for_display(lora_stack_a) if lora_stack_a else []
|
||||
input_loras_b = self._format_loras_for_display(lora_stack_b) if lora_stack_b else []
|
||||
|
||||
# Process trigger words
|
||||
trigger_words_display = self._process_trigger_words(
|
||||
trigger_words, trigger_words_toggle
|
||||
@@ -553,6 +523,10 @@ class PromptManagerAdvanced:
|
||||
preset_stack_a = self._build_stack_from_toggle(loras_a_toggle) if loras_a_toggle else []
|
||||
preset_stack_b = self._build_stack_from_toggle(loras_b_toggle) if loras_b_toggle else []
|
||||
|
||||
# Get ALL preset loras including unavailable ones (for display purposes)
|
||||
all_preset_loras_a = self._get_all_loras_from_toggle(loras_a_toggle) if loras_a_toggle else []
|
||||
all_preset_loras_b = self._get_all_loras_from_toggle(loras_b_toggle) if loras_b_toggle else []
|
||||
|
||||
# When use_lora_input is disabled, ignore connected stacks and use only saved loras
|
||||
if not use_lora_input:
|
||||
lora_stack_a = preset_stack_a
|
||||
@@ -574,16 +548,14 @@ class PromptManagerAdvanced:
|
||||
processed_stack_a = self._process_lora_toggle(lora_stack_a, loras_a_toggle)
|
||||
processed_stack_b = self._process_lora_toggle(lora_stack_b, loras_b_toggle)
|
||||
|
||||
# Display logic depends on use_lora_input mode:
|
||||
# - use_lora_input OFF: Show only preset loras (what will actually be used)
|
||||
# - use_lora_input ON: Show merged loras (preset + connected) so user sees full picture
|
||||
# Display logic: Include ALL loras (available + unavailable) so UI shows complete picture
|
||||
# Build display from available loras first, then add unavailable ones
|
||||
if not use_lora_input:
|
||||
loras_a_display = self._format_loras_for_display(preset_stack_a) if preset_stack_a else []
|
||||
loras_b_display = self._format_loras_for_display(preset_stack_b) if preset_stack_b else []
|
||||
loras_a_display = self._format_loras_for_display_with_unavailable(preset_stack_a, all_preset_loras_a)
|
||||
loras_b_display = self._format_loras_for_display_with_unavailable(preset_stack_b, all_preset_loras_b)
|
||||
else:
|
||||
# Always call _format_loras_for_display even with empty stacks - it handles empty gracefully
|
||||
loras_a_display = self._format_loras_for_display(lora_stack_a)
|
||||
loras_b_display = self._format_loras_for_display(lora_stack_b)
|
||||
loras_a_display = self._format_loras_for_display_with_unavailable(lora_stack_a, all_preset_loras_a)
|
||||
loras_b_display = self._format_loras_for_display_with_unavailable(lora_stack_b, all_preset_loras_b)
|
||||
|
||||
# Convert thumbnail image to base64 if provided
|
||||
thumbnail_base64 = None
|
||||
@@ -593,6 +565,10 @@ class PromptManagerAdvanced:
|
||||
except Exception as e:
|
||||
print(f"[PromptManagerAdvanced] Failed to convert thumbnail image: {e}")
|
||||
|
||||
# Build explicit list of unavailable lora names for frontend
|
||||
unavailable_loras_a = [lora['name'] for lora in all_preset_loras_a if not lora.get('available', False)]
|
||||
unavailable_loras_b = [lora['name'] for lora in all_preset_loras_b if not lora.get('available', False)]
|
||||
|
||||
# Broadcast update to frontend
|
||||
if unique_id is not None:
|
||||
server.PromptServer.instance.send_sync("prompt-manager-advanced-update", {
|
||||
@@ -602,6 +578,10 @@ class PromptManagerAdvanced:
|
||||
"prompt_input": prompt_input,
|
||||
"loras_a": loras_a_display,
|
||||
"loras_b": loras_b_display,
|
||||
"input_loras_a": input_loras_a, # Original input loras for change detection
|
||||
"input_loras_b": input_loras_b, # Original input loras for change detection
|
||||
"unavailable_loras_a": unavailable_loras_a, # Explicit list of unavailable lora names
|
||||
"unavailable_loras_b": unavailable_loras_b, # Explicit list of unavailable lora names
|
||||
"trigger_words": trigger_words_display,
|
||||
"connected_thumbnail": thumbnail_base64
|
||||
})
|
||||
@@ -721,6 +701,73 @@ class PromptManagerAdvanced:
|
||||
|
||||
return display_list
|
||||
|
||||
def _get_all_loras_from_toggle(self, toggle_data):
|
||||
"""
|
||||
Get ALL loras from toggle data including unavailable ones.
|
||||
Returns list of dicts with name, strength, active, and available status.
|
||||
Used for building complete display list.
|
||||
"""
|
||||
if not toggle_data:
|
||||
return []
|
||||
|
||||
try:
|
||||
if isinstance(toggle_data, str):
|
||||
toggle_data = json.loads(toggle_data)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return []
|
||||
|
||||
if not isinstance(toggle_data, list):
|
||||
return []
|
||||
|
||||
all_loras = []
|
||||
for item in toggle_data:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
|
||||
lora_name = item.get('name', '')
|
||||
if not lora_name:
|
||||
continue
|
||||
|
||||
# Check availability using same fuzzy matching as actual loading
|
||||
# UI should match what Python will actually do
|
||||
_, found = get_lora_relative_path(lora_name)
|
||||
|
||||
all_loras.append({
|
||||
"name": lora_name,
|
||||
"strength": float(item.get('strength', 1.0)),
|
||||
"clip_strength": float(item.get('clip_strength', item.get('strength', 1.0))),
|
||||
"active": item.get('active', True),
|
||||
"available": found
|
||||
})
|
||||
|
||||
return all_loras
|
||||
|
||||
def _format_loras_for_display_with_unavailable(self, lora_stack, all_preset_loras):
|
||||
"""
|
||||
Format lora stack for frontend display, including unavailable preset loras.
|
||||
This ensures the UI shows all saved loras even if they're not found locally.
|
||||
"""
|
||||
# Start with the available loras from the stack
|
||||
display_list = self._format_loras_for_display(lora_stack) if lora_stack else []
|
||||
seen_names = set(item['name'].lower() for item in display_list)
|
||||
|
||||
# Add any unavailable preset loras that aren't already in the list
|
||||
for lora in all_preset_loras:
|
||||
lora_name_lower = lora['name'].lower()
|
||||
if lora_name_lower not in seen_names:
|
||||
display_list.append({
|
||||
"name": lora['name'],
|
||||
"path": lora['name'], # Just use name as path for unavailable
|
||||
"model_strength": lora['strength'],
|
||||
"clip_strength": lora['clip_strength'],
|
||||
"active": lora['active'],
|
||||
"strength": lora['strength'],
|
||||
"available": lora['available']
|
||||
})
|
||||
seen_names.add(lora_name_lower)
|
||||
|
||||
return display_list
|
||||
|
||||
def _process_trigger_words(self, connected_trigger_words, toggle_data):
|
||||
"""
|
||||
Process trigger words from connected input and saved toggle states.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "prompt-manager"
|
||||
description = "Prompt Manager extension for ComfyUI, allowing user to both save and generate prompts, as well as save matching loras for each prompt."
|
||||
version = "1.12.6"
|
||||
version = "1.12.7"
|
||||
license = {file = "LICENSE"}
|
||||
# classifiers = [
|
||||
# # For OS-independent nodes (works on all operating systems)
|
||||
|
||||
Reference in New Issue
Block a user