mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-20 04:21:27 -03:00
refactor(nodes): declare loras widget as LORAS input type on lora nodes
This commit is contained in:
@@ -39,6 +39,7 @@ class CreateHookLoraLM:
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
"loras": ("LORAS", {}),
|
||||||
},
|
},
|
||||||
"optional": FlexibleOptionalInputType(any_type),
|
"optional": FlexibleOptionalInputType(any_type),
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ class CreateHookLoraLM:
|
|||||||
RETURN_NAMES = ("HOOKS", "trigger_words", "active_loras")
|
RETURN_NAMES = ("HOOKS", "trigger_words", "active_loras")
|
||||||
FUNCTION = "create_hook"
|
FUNCTION = "create_hook"
|
||||||
|
|
||||||
def create_hook(self, text: str, **kwargs):
|
def create_hook(self, text: str, loras, **kwargs):
|
||||||
"""Create a HookGroup from the selected LoRAs, chained with prev_hooks.
|
"""Create a HookGroup from the selected LoRAs, chained with prev_hooks.
|
||||||
|
|
||||||
Each active LoRA from the widget is loaded and wrapped in a WeightHook
|
Each active LoRA from the widget is loaded and wrapped in a WeightHook
|
||||||
@@ -73,7 +74,7 @@ class CreateHookLoraLM:
|
|||||||
all_trigger_words: list[str] = []
|
all_trigger_words: list[str] = []
|
||||||
active_loras: list[tuple[str, float, float]] = []
|
active_loras: list[tuple[str, float, float]] = []
|
||||||
|
|
||||||
for lora in get_loras_list(kwargs):
|
for lora in get_loras_list({"loras": loras}):
|
||||||
if not lora.get("active", False):
|
if not lora.get("active", False):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ def _collect_stack_entries(lora_stack):
|
|||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|
||||||
def _collect_widget_entries(kwargs):
|
def _collect_widget_entries(loras):
|
||||||
entries = []
|
entries = []
|
||||||
for lora in get_loras_list(kwargs):
|
for lora in get_loras_list({"loras": loras}):
|
||||||
if not lora.get("active", False):
|
if not lora.get("active", False):
|
||||||
continue
|
continue
|
||||||
lora_name = apply_lora_syntax_format(lora["name"])
|
lora_name = apply_lora_syntax_format(lora["name"])
|
||||||
@@ -139,6 +139,7 @@ class LoraLoaderLM:
|
|||||||
"placeholder": "Search LoRAs to add...",
|
"placeholder": "Search LoRAs to add...",
|
||||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||||
}),
|
}),
|
||||||
|
"loras": ("LORAS", {}),
|
||||||
},
|
},
|
||||||
"optional": FlexibleOptionalInputType(any_type),
|
"optional": FlexibleOptionalInputType(any_type),
|
||||||
}
|
}
|
||||||
@@ -152,12 +153,12 @@ class LoraLoaderLM:
|
|||||||
RETURN_NAMES = ("MODEL", "CLIP", "trigger_words", "loaded_loras")
|
RETURN_NAMES = ("MODEL", "CLIP", "trigger_words", "loaded_loras")
|
||||||
FUNCTION = "load_loras"
|
FUNCTION = "load_loras"
|
||||||
|
|
||||||
def load_loras(self, model, text, **kwargs):
|
def load_loras(self, model, text, loras, **kwargs):
|
||||||
"""Loads multiple LoRAs based on the kwargs input and lora_stack."""
|
"""Loads multiple LoRAs based on the widget input and lora_stack."""
|
||||||
del text
|
del text
|
||||||
clip = kwargs.get("clip", None)
|
clip = kwargs.get("clip", None)
|
||||||
lora_entries = _collect_stack_entries(kwargs.get("lora_stack", None))
|
lora_entries = _collect_stack_entries(kwargs.get("lora_stack", None))
|
||||||
lora_entries.extend(_collect_widget_entries(kwargs))
|
lora_entries.extend(_collect_widget_entries(loras))
|
||||||
|
|
||||||
nunchaku_model_kind = detect_nunchaku_model_kind(model)
|
nunchaku_model_kind = detect_nunchaku_model_kind(model)
|
||||||
if nunchaku_model_kind == "flux":
|
if nunchaku_model_kind == "flux":
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class LoraStackerLM:
|
|||||||
"placeholder": "Search LoRAs to add...",
|
"placeholder": "Search LoRAs to add...",
|
||||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||||
}),
|
}),
|
||||||
|
"loras": ("LORAS", {}),
|
||||||
},
|
},
|
||||||
"optional": FlexibleOptionalInputType(any_type),
|
"optional": FlexibleOptionalInputType(any_type),
|
||||||
}
|
}
|
||||||
@@ -31,8 +32,8 @@ class LoraStackerLM:
|
|||||||
RETURN_NAMES = ("LORA_STACK", "trigger_words", "active_loras")
|
RETURN_NAMES = ("LORA_STACK", "trigger_words", "active_loras")
|
||||||
FUNCTION = "stack_loras"
|
FUNCTION = "stack_loras"
|
||||||
|
|
||||||
def stack_loras(self, text, **kwargs):
|
def stack_loras(self, text, loras, **kwargs):
|
||||||
"""Stacks multiple LoRAs based on the kwargs input without loading them."""
|
"""Stacks multiple LoRAs based on the widget input without loading them."""
|
||||||
stack = []
|
stack = []
|
||||||
active_loras = []
|
active_loras = []
|
||||||
all_trigger_words = []
|
all_trigger_words = []
|
||||||
@@ -47,8 +48,8 @@ class LoraStackerLM:
|
|||||||
_, trigger_words = get_lora_info(lora_name)
|
_, trigger_words = get_lora_info(lora_name)
|
||||||
all_trigger_words.extend(trigger_words)
|
all_trigger_words.extend(trigger_words)
|
||||||
|
|
||||||
# Process loras from kwargs with support for both old and new formats
|
# Process loras from the widget with support for both old and new formats
|
||||||
loras_list = get_loras_list(kwargs)
|
loras_list = get_loras_list({"loras": loras})
|
||||||
for lora in loras_list:
|
for lora in loras_list:
|
||||||
if not lora.get('active', False):
|
if not lora.get('active', False):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class WanVideoLoraSelectLM:
|
|||||||
"placeholder": "Search LoRAs to add...",
|
"placeholder": "Search LoRAs to add...",
|
||||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||||
}),
|
}),
|
||||||
|
"loras": ("LORAS", {}),
|
||||||
},
|
},
|
||||||
"optional": FlexibleOptionalInputType(any_type),
|
"optional": FlexibleOptionalInputType(any_type),
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ class WanVideoLoraSelectLM:
|
|||||||
RETURN_NAMES = ("lora", "trigger_words", "active_loras")
|
RETURN_NAMES = ("lora", "trigger_words", "active_loras")
|
||||||
FUNCTION = "process_loras"
|
FUNCTION = "process_loras"
|
||||||
|
|
||||||
def process_loras(self, text, low_mem_load=False, merge_loras=True, **kwargs):
|
def process_loras(self, text, loras, low_mem_load=False, merge_loras=True, **kwargs):
|
||||||
loras_list = []
|
loras_list = []
|
||||||
all_trigger_words = []
|
all_trigger_words = []
|
||||||
active_loras = []
|
active_loras = []
|
||||||
@@ -62,8 +63,8 @@ class WanVideoLoraSelectLM:
|
|||||||
selected_blocks = blocks.get("selected_blocks", {})
|
selected_blocks = blocks.get("selected_blocks", {})
|
||||||
layer_filter = blocks.get("layer_filter", "")
|
layer_filter = blocks.get("layer_filter", "")
|
||||||
|
|
||||||
# Process loras from kwargs with support for both old and new formats
|
# Process loras from the widget with support for both old and new formats
|
||||||
loras_from_widget = get_loras_list(kwargs)
|
loras_from_widget = get_loras_list({"loras": loras})
|
||||||
for lora in loras_from_widget:
|
for lora in loras_from_widget:
|
||||||
if not lora.get('active', False):
|
if not lora.get('active', False):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ const {
|
|||||||
APP_MODULE,
|
APP_MODULE,
|
||||||
API_MODULE,
|
API_MODULE,
|
||||||
UTILS_MODULE,
|
UTILS_MODULE,
|
||||||
LORAS_WIDGET_MODULE,
|
|
||||||
LORA_LOADER_MODULE,
|
LORA_LOADER_MODULE,
|
||||||
} = vi.hoisted(() => ({
|
} = vi.hoisted(() => ({
|
||||||
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
||||||
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
||||||
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
||||||
LORAS_WIDGET_MODULE: new URL("../../../web/comfyui/loras_widget.js", import.meta.url).pathname,
|
|
||||||
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -59,12 +57,6 @@ vi.mock(UTILS_MODULE, () => ({
|
|||||||
LORA_PATTERN: /<lora:([^:]+):([-\d.]+)(?::([-\d.]+))?>/g,
|
LORA_PATTERN: /<lora:([^:]+):([-\d.]+)(?::([-\d.]+))?>/g,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const addLorasWidget = vi.fn();
|
|
||||||
|
|
||||||
vi.mock(LORAS_WIDGET_MODULE, () => ({
|
|
||||||
addLorasWidget,
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("Lora Loader trigger word updates", () => {
|
describe("Lora Loader trigger word updates", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
@@ -82,11 +74,6 @@ describe("Lora Loader trigger word updates", () => {
|
|||||||
|
|
||||||
getWidgetByName.mockClear();
|
getWidgetByName.mockClear();
|
||||||
getWidgetSerializedValue.mockClear();
|
getWidgetSerializedValue.mockClear();
|
||||||
|
|
||||||
addLorasWidget.mockClear();
|
|
||||||
addLorasWidget.mockImplementation((_node, _name, _opts, callback) => ({
|
|
||||||
widget: { value: [], callback },
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("refreshes trigger word toggles after LoRA syntax edits in the input widget", async () => {
|
it("refreshes trigger word toggles after LoRA syntax edits in the input widget", async () => {
|
||||||
@@ -113,9 +100,18 @@ describe("Lora Loader trigger word updates", () => {
|
|||||||
options: {},
|
options: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Declared LORAS input widget, created by the LoraManager.LorasWidget
|
||||||
|
// extension and taken over by the loader's onNodeCreated.
|
||||||
|
const lorasWidget = {
|
||||||
|
name: "loras",
|
||||||
|
value: [],
|
||||||
|
options: {},
|
||||||
|
callback: null, // Will be set by onNodeCreated
|
||||||
|
};
|
||||||
|
|
||||||
const node = {
|
const node = {
|
||||||
comfyClass: "Lora Loader (LoraManager)",
|
comfyClass: "Lora Loader (LoraManager)",
|
||||||
widgets: [metadataWidget, inputWidget],
|
widgets: [metadataWidget, inputWidget, lorasWidget],
|
||||||
addInput: vi.fn(),
|
addInput: vi.fn(),
|
||||||
graph: {},
|
graph: {},
|
||||||
};
|
};
|
||||||
@@ -124,8 +120,9 @@ describe("Lora Loader trigger word updates", () => {
|
|||||||
|
|
||||||
// The widget is now the AUTOCOMPLETE_TEXT_LORAS type, created automatically by Vue widgets
|
// The widget is now the AUTOCOMPLETE_TEXT_LORAS type, created automatically by Vue widgets
|
||||||
expect(node.inputWidget).toBe(inputWidget);
|
expect(node.inputWidget).toBe(inputWidget);
|
||||||
expect(node.lorasWidget).toBeDefined();
|
expect(node.lorasWidget).toBe(lorasWidget);
|
||||||
expect(getWidgetByName).toHaveBeenCalledWith(node, "text");
|
expect(getWidgetByName).toHaveBeenCalledWith(node, "text");
|
||||||
|
expect(typeof lorasWidget.callback).toBe("function");
|
||||||
|
|
||||||
// The callback should have been set up by onNodeCreated
|
// The callback should have been set up by onNodeCreated
|
||||||
const inputCallback = inputWidget.callback;
|
const inputCallback = inputWidget.callback;
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ const {
|
|||||||
APP_MODULE,
|
APP_MODULE,
|
||||||
API_MODULE,
|
API_MODULE,
|
||||||
UTILS_MODULE,
|
UTILS_MODULE,
|
||||||
LORAS_WIDGET_MODULE,
|
|
||||||
LORA_LOADER_MODULE,
|
LORA_LOADER_MODULE,
|
||||||
LORA_STACKER_MODULE,
|
LORA_STACKER_MODULE,
|
||||||
} = vi.hoisted(() => ({
|
} = vi.hoisted(() => ({
|
||||||
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
||||||
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
||||||
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
||||||
LORAS_WIDGET_MODULE: new URL("../../../web/comfyui/loras_widget.js", import.meta.url).pathname,
|
|
||||||
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
||||||
LORA_STACKER_MODULE: new URL("../../../web/comfyui/lora_stacker.js", import.meta.url).pathname,
|
LORA_STACKER_MODULE: new URL("../../../web/comfyui/lora_stacker.js", import.meta.url).pathname,
|
||||||
}));
|
}));
|
||||||
@@ -80,12 +78,6 @@ vi.mock(UTILS_MODULE, async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const addLorasWidget = vi.fn();
|
|
||||||
|
|
||||||
vi.mock(LORAS_WIDGET_MODULE, () => ({
|
|
||||||
addLorasWidget,
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("Node mode change handling", () => {
|
describe("Node mode change handling", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
@@ -109,11 +101,6 @@ describe("Node mode change handling", () => {
|
|||||||
|
|
||||||
getWidgetByName.mockClear();
|
getWidgetByName.mockClear();
|
||||||
getWidgetSerializedValue.mockClear();
|
getWidgetSerializedValue.mockClear();
|
||||||
|
|
||||||
addLorasWidget.mockClear();
|
|
||||||
addLorasWidget.mockImplementation((_node, _name, _opts, callback) => ({
|
|
||||||
widget: { value: [], callback },
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Lora Stacker mode change handling", () => {
|
describe("Lora Stacker mode change handling", () => {
|
||||||
@@ -222,6 +209,13 @@ describe("Node mode change handling", () => {
|
|||||||
options: {},
|
options: {},
|
||||||
callback: null, // Will be set by onNodeCreated
|
callback: null, // Will be set by onNodeCreated
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Declared LORAS input widget, taken over by onNodeCreated
|
||||||
|
name: "loras",
|
||||||
|
value: [],
|
||||||
|
options: {},
|
||||||
|
callback: null,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
addInput: vi.fn(),
|
addInput: vi.fn(),
|
||||||
mode: 0, // Initial mode
|
mode: 0, // Initial mode
|
||||||
|
|||||||
@@ -197,5 +197,6 @@ def test_lora_loader_qwen_model_raises_clear_error_when_helper_import_fails(monk
|
|||||||
loader.load_loras(
|
loader.load_loras(
|
||||||
qwen_model,
|
qwen_model,
|
||||||
"",
|
"",
|
||||||
|
[],
|
||||||
lora_stack=[("stack_qwen.safetensors", 0.6, 0.1)],
|
lora_stack=[("stack_qwen.safetensors", 0.6, 0.1)],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -85,9 +85,6 @@ export function createAutocompleteTextWidgetInstanceId() {
|
|||||||
return autocompleteTextWidgetInstanceId
|
return autocompleteTextWidgetInstanceId
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache for dynamically loaded addLorasWidget module
|
|
||||||
let addLorasWidgetCache: any = null
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
function createLoraPoolWidget(node) {
|
function createLoraPoolWidget(node) {
|
||||||
const container = document.createElement('div')
|
const container = document.createElement('div')
|
||||||
@@ -876,91 +873,6 @@ app.registerExtension({
|
|||||||
CYCLER_CONFIG(node) {
|
CYCLER_CONFIG(node) {
|
||||||
return createLoraCyclerWidget(node)
|
return createLoraCyclerWidget(node)
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
|
||||||
async LORAS(node: any) {
|
|
||||||
if (!addLorasWidgetCache) {
|
|
||||||
// @ts-ignore
|
|
||||||
const module = await import(/* @vite-ignore */ '../loras_widget.js')
|
|
||||||
addLorasWidgetCache = module.addLorasWidget
|
|
||||||
}
|
|
||||||
// Check if this is a randomizer node to enable lock buttons
|
|
||||||
const isRandomizerNode = node.comfyClass === 'Lora Randomizer (LoraManager)'
|
|
||||||
|
|
||||||
// For randomizer nodes, add a callback to update connected trigger words
|
|
||||||
const callback = isRandomizerNode ? () => {
|
|
||||||
updateDownstreamLoaders(node)
|
|
||||||
} : null
|
|
||||||
|
|
||||||
const opts: { isRandomizerNode?: boolean; onSelectionChange?: (selection: any) => void } = {
|
|
||||||
isRandomizerNode,
|
|
||||||
}
|
|
||||||
if (isRandomizerNode) {
|
|
||||||
opts.onSelectionChange = async (selection: any) => {
|
|
||||||
if (!selection?.name || !selection?.active) return
|
|
||||||
|
|
||||||
// Walk outputs to find directly connected Lora Info nodes
|
|
||||||
const infoNodes: any[] = []
|
|
||||||
if (node.outputs) {
|
|
||||||
for (const output of node.outputs) {
|
|
||||||
if (!output?.links?.length) continue
|
|
||||||
for (const linkId of output.links) {
|
|
||||||
const links = node.graph?.links
|
|
||||||
if (!links) continue
|
|
||||||
const link = Array.isArray(links) ? links[linkId] : links.get?.(linkId)
|
|
||||||
if (!link) continue
|
|
||||||
const targetNode = node.graph?.getNodeById?.(link.target_id)
|
|
||||||
if (targetNode?.comfyClass === 'Lora Info (LoraManager)') {
|
|
||||||
infoNodes.push(targetNode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (infoNodes.length === 0) return
|
|
||||||
|
|
||||||
// Bump request token to guard against stale async responses
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
infoNode.__loraInfoReqId = (infoNode.__loraInfoReqId || 0) + 1
|
|
||||||
}
|
|
||||||
const reqIdSnapshot = new Map<any, number>()
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
reqIdSnapshot.set(infoNode, infoNode.__loraInfoReqId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch notes via the real ComfyUI api
|
|
||||||
let infoData: any
|
|
||||||
try {
|
|
||||||
const response = await api.fetchApi(
|
|
||||||
`/lm/loras/get-notes?name=${encodeURIComponent(selection.name)}`,
|
|
||||||
{ method: 'GET' }
|
|
||||||
)
|
|
||||||
if (response?.ok) {
|
|
||||||
const data = await response.json()
|
|
||||||
infoData = {
|
|
||||||
name: selection.name,
|
|
||||||
notes: data?.notes || '',
|
|
||||||
filePath: data?.file_path || '',
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
infoData = { name: selection.name, notes: '[Error loading notes]', filePath: '' }
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
infoData = { name: selection.name, notes: '[Error loading notes]', filePath: '' }
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
if (infoNode.__loraInfoReqId !== reqIdSnapshot.get(infoNode)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (typeof infoNode._setLoraInfo === 'function') {
|
|
||||||
infoNode._setLoraInfo(infoData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return addLorasWidgetCache(node, 'loras', opts, callback)
|
|
||||||
},
|
|
||||||
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
AUTOCOMPLETE_TEXT_LORAS(node) {
|
AUTOCOMPLETE_TEXT_LORAS(node) {
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import {
|
|||||||
getWidgetByName,
|
getWidgetByName,
|
||||||
getWidgetSerializedValue,
|
getWidgetSerializedValue,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import { addLorasWidget } from "./loras_widget.js";
|
|
||||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
|
||||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "LoraManager.CreateHookLora",
|
name: "LoraManager.CreateHookLora",
|
||||||
@@ -62,39 +59,37 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the LoRA list widget
|
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||||
const result = addLorasWidget(
|
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||||
this,
|
const lorasWidget = getWidgetByName(this, "loras");
|
||||||
"loras",
|
if (!lorasWidget) {
|
||||||
{
|
console.warn(
|
||||||
onSelectionChange: (selection) => {
|
"LoRA Manager: loras widget not found for Create Hook LoRA"
|
||||||
applySelectionHighlight(this, selection);
|
);
|
||||||
updateConnectedLoraInfoNodes(this, selection);
|
return;
|
||||||
},
|
}
|
||||||
},
|
this.lorasWidget = lorasWidget;
|
||||||
(value) => {
|
|
||||||
// Prevent recursive calls
|
|
||||||
if (isUpdating) return;
|
|
||||||
isUpdating = true;
|
|
||||||
|
|
||||||
try {
|
lorasWidget.callback = (value) => {
|
||||||
// Update connected trigger word toggles with active LoRA names
|
// Prevent recursive calls
|
||||||
const activeLoraNames = new Set();
|
if (isUpdating) return;
|
||||||
value.forEach((lora) => {
|
isUpdating = true;
|
||||||
if (lora.active) {
|
|
||||||
activeLoraNames.add(lora.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateConnectedTriggerWords(this, activeLoraNames);
|
|
||||||
} finally {
|
|
||||||
isUpdating = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleInputSync(value);
|
try {
|
||||||
|
// Update connected trigger word toggles with active LoRA names
|
||||||
|
const activeLoraNames = new Set();
|
||||||
|
value.forEach((lora) => {
|
||||||
|
if (lora.active) {
|
||||||
|
activeLoraNames.add(lora.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateConnectedTriggerWords(this, activeLoraNames);
|
||||||
|
} finally {
|
||||||
|
isUpdating = false;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
this.lorasWidget = result.widget;
|
scheduleInputSync(value);
|
||||||
|
};
|
||||||
|
|
||||||
// Set up callback for the text input widget to trigger merge logic
|
// Set up callback for the text input widget to trigger merge logic
|
||||||
inputWidget.callback = (value) => {
|
inputWidget.callback = (value) => {
|
||||||
|
|||||||
+22
-27
@@ -10,10 +10,7 @@ import {
|
|||||||
getWidgetByName,
|
getWidgetByName,
|
||||||
getWidgetSerializedValue,
|
getWidgetSerializedValue,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import { addLorasWidget } from "./loras_widget.js";
|
|
||||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
|
||||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "LoraManager.LoraLoader",
|
name: "LoraManager.LoraLoader",
|
||||||
@@ -188,34 +185,32 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the widget object directly from the returned object
|
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||||
this.lorasWidget = addLorasWidget(
|
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||||
this,
|
const lorasWidget = getWidgetByName(this, "loras");
|
||||||
"loras",
|
if (!lorasWidget) {
|
||||||
{
|
console.warn("LoRA Manager: loras widget not found for Lora Loader");
|
||||||
onSelectionChange: (selection) => {
|
return;
|
||||||
applySelectionHighlight(this, selection);
|
}
|
||||||
updateConnectedLoraInfoNodes(this, selection);
|
this.lorasWidget = lorasWidget;
|
||||||
},
|
|
||||||
},
|
|
||||||
(value) => {
|
|
||||||
// Prevent recursive calls
|
|
||||||
if (isUpdating) return;
|
|
||||||
isUpdating = true;
|
|
||||||
|
|
||||||
try {
|
lorasWidget.callback = (value) => {
|
||||||
// Collect all active loras from this node and its input chain
|
// Prevent recursive calls
|
||||||
const allActiveLoraNames = collectActiveLorasFromChain(this);
|
if (isUpdating) return;
|
||||||
|
isUpdating = true;
|
||||||
|
|
||||||
// Update trigger words for connected toggle nodes with the aggregated lora names
|
try {
|
||||||
updateConnectedTriggerWords(this, allActiveLoraNames);
|
// Collect all active loras from this node and its input chain
|
||||||
} finally {
|
const allActiveLoraNames = collectActiveLorasFromChain(this);
|
||||||
isUpdating = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleInputSync(value);
|
// Update trigger words for connected toggle nodes with the aggregated lora names
|
||||||
|
updateConnectedTriggerWords(this, allActiveLoraNames);
|
||||||
|
} finally {
|
||||||
|
isUpdating = false;
|
||||||
}
|
}
|
||||||
).widget;
|
|
||||||
|
scheduleInputSync(value);
|
||||||
|
};
|
||||||
|
|
||||||
// Set up callback for the text input widget to trigger merge logic
|
// Set up callback for the text input widget to trigger merge logic
|
||||||
inputWidget.callback = (value) => {
|
inputWidget.callback = (value) => {
|
||||||
|
|||||||
+31
-36
@@ -8,10 +8,7 @@ import {
|
|||||||
getWidgetByName,
|
getWidgetByName,
|
||||||
getWidgetSerializedValue,
|
getWidgetSerializedValue,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import { addLorasWidget } from "./loras_widget.js";
|
|
||||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
|
||||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "LoraManager.LoraStacker",
|
name: "LoraManager.LoraStacker",
|
||||||
@@ -61,44 +58,42 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = addLorasWidget(
|
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||||
this,
|
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||||
"loras",
|
const lorasWidget = getWidgetByName(this, "loras");
|
||||||
{
|
if (!lorasWidget) {
|
||||||
onSelectionChange: (selection) => {
|
console.warn("LoRA Manager: loras widget not found for Lora Stacker");
|
||||||
applySelectionHighlight(this, selection);
|
return;
|
||||||
updateConnectedLoraInfoNodes(this, selection);
|
}
|
||||||
},
|
this.lorasWidget = lorasWidget;
|
||||||
},
|
|
||||||
(value) => {
|
|
||||||
// Prevent recursive calls
|
|
||||||
if (isUpdating) return;
|
|
||||||
isUpdating = true;
|
|
||||||
|
|
||||||
try {
|
lorasWidget.callback = (value) => {
|
||||||
// Update this stacker's direct trigger toggles with its own active loras
|
// Prevent recursive calls
|
||||||
// Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger)
|
if (isUpdating) return;
|
||||||
const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3;
|
isUpdating = true;
|
||||||
const activeLoraNames = new Set();
|
|
||||||
if (isNodeActive) {
|
|
||||||
value.forEach((lora) => {
|
|
||||||
if (lora.active) {
|
|
||||||
activeLoraNames.add(lora.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
updateConnectedTriggerWords(this, activeLoraNames);
|
|
||||||
|
|
||||||
// Find all Lora Loader nodes in the chain that might need updates
|
try {
|
||||||
updateDownstreamLoaders(this);
|
// Update this stacker's direct trigger toggles with its own active loras
|
||||||
} finally {
|
// Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger)
|
||||||
isUpdating = false;
|
const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3;
|
||||||
|
const activeLoraNames = new Set();
|
||||||
|
if (isNodeActive) {
|
||||||
|
value.forEach((lora) => {
|
||||||
|
if (lora.active) {
|
||||||
|
activeLoraNames.add(lora.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
updateConnectedTriggerWords(this, activeLoraNames);
|
||||||
|
|
||||||
scheduleInputSync(value);
|
// Find all Lora Loader nodes in the chain that might need updates
|
||||||
});
|
updateDownstreamLoaders(this);
|
||||||
|
} finally {
|
||||||
|
isUpdating = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.lorasWidget = result.widget;
|
scheduleInputSync(value);
|
||||||
|
};
|
||||||
|
|
||||||
// Set up callback for the text input widget to trigger merge logic
|
// Set up callback for the text input widget to trigger merge logic
|
||||||
inputWidget.callback = (value) => {
|
inputWidget.callback = (value) => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { app } from "../../scripts/app.js";
|
||||||
import { createToggle, createArrowButton, createDragHandle, updateEntrySelection, createExpandButton, updateExpandButtonState, createLockButton, updateLockButtonState } from "./loras_widget_components.js";
|
import { createToggle, createArrowButton, createDragHandle, updateEntrySelection, createExpandButton, updateExpandButtonState, createLockButton, updateLockButtonState } from "./loras_widget_components.js";
|
||||||
import {
|
import {
|
||||||
parseLoraValue,
|
parseLoraValue,
|
||||||
@@ -10,7 +11,9 @@ import {
|
|||||||
onLibraryChanged
|
onLibraryChanged
|
||||||
} from "./loras_widget_utils.js";
|
} from "./loras_widget_utils.js";
|
||||||
import { initDrag, createContextMenu, initHeaderDrag, initReorderDrag, handleKeyboardNavigation } from "./loras_widget_events.js";
|
import { initDrag, createContextMenu, initHeaderDrag, initReorderDrag, handleKeyboardNavigation } from "./loras_widget_events.js";
|
||||||
import { forwardMiddleMouseToCanvas, forwardWheelToCanvas, enableListWheelScroll } from "./utils.js";
|
import { forwardMiddleMouseToCanvas, forwardWheelToCanvas, enableListWheelScroll, updateDownstreamLoaders } from "./utils.js";
|
||||||
|
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
||||||
|
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||||
import { PreviewTooltip } from "./preview_tooltip.js";
|
import { PreviewTooltip } from "./preview_tooltip.js";
|
||||||
import { ensureLmStyles } from "./lm_styles_loader.js";
|
import { ensureLmStyles } from "./lm_styles_loader.js";
|
||||||
import { getStrengthStepPreference } from "./settings.js";
|
import { getStrengthStepPreference } from "./settings.js";
|
||||||
@@ -885,3 +888,50 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
|
|
||||||
return { minWidth: 400, minHeight: defaultHeight, widget };
|
return { minWidth: 400, minHeight: defaultHeight, widget };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node classes whose declared "loras" input (LORAS widget type) also applies
|
||||||
|
// trigger-word selection highlighting on lora selection.
|
||||||
|
const LORAS_WIDGET_HIGHLIGHT_NODE_CLASSES = new Set([
|
||||||
|
"Lora Loader (LoraManager)",
|
||||||
|
"Lora Stacker (LoraManager)",
|
||||||
|
"Create Hook LoRA (LoraManager)",
|
||||||
|
]);
|
||||||
|
|
||||||
|
app.registerExtension({
|
||||||
|
name: "LoraManager.LorasWidget",
|
||||||
|
|
||||||
|
getCustomWidgets() {
|
||||||
|
return {
|
||||||
|
// Synchronous factory for the declared "loras" input (LORAS type) used by
|
||||||
|
// Lora Loader / Lora Stacker / Create Hook LoRA / WanVideo Lora Select /
|
||||||
|
// Lora Randomizer nodes. ComfyUI calls widget constructors synchronously,
|
||||||
|
// so this must NOT be async.
|
||||||
|
LORAS(node) {
|
||||||
|
const comfyClass = node?.comfyClass;
|
||||||
|
const isRandomizerNode = comfyClass === "Lora Randomizer (LoraManager)";
|
||||||
|
|
||||||
|
const opts = { isRandomizerNode };
|
||||||
|
|
||||||
|
if (isRandomizerNode || comfyClass === "WanVideo Lora Select (LoraManager)") {
|
||||||
|
opts.onSelectionChange = (selection) => {
|
||||||
|
updateConnectedLoraInfoNodes(node, selection);
|
||||||
|
};
|
||||||
|
} else if (LORAS_WIDGET_HIGHLIGHT_NODE_CLASSES.has(comfyClass)) {
|
||||||
|
opts.onSelectionChange = (selection) => {
|
||||||
|
applySelectionHighlight(node, selection);
|
||||||
|
updateConnectedLoraInfoNodes(node, selection);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// The randomizer has no per-node JS extension; update downstream
|
||||||
|
// loaders directly from the widget callback. The other nodes assign
|
||||||
|
// their own widget.callback in their onNodeCreated handlers.
|
||||||
|
const callback = isRandomizerNode
|
||||||
|
? () => updateDownstreamLoaders(node)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return addLorasWidget(node, "loras", opts, callback);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@@ -16070,7 +16070,6 @@ function createAutocompleteTextWidgetInstanceId() {
|
|||||||
autocompleteTextWidgetInstanceId += 1;
|
autocompleteTextWidgetInstanceId += 1;
|
||||||
return autocompleteTextWidgetInstanceId;
|
return autocompleteTextWidgetInstanceId;
|
||||||
}
|
}
|
||||||
let addLorasWidgetCache = null;
|
|
||||||
function createLoraPoolWidget(node) {
|
function createLoraPoolWidget(node) {
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
container.id = `lora-pool-widget-${node.id}`;
|
container.id = `lora-pool-widget-${node.id}`;
|
||||||
@@ -16683,81 +16682,6 @@ app$1.registerExtension({
|
|||||||
CYCLER_CONFIG(node) {
|
CYCLER_CONFIG(node) {
|
||||||
return createLoraCyclerWidget(node);
|
return createLoraCyclerWidget(node);
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
|
||||||
async LORAS(node) {
|
|
||||||
if (!addLorasWidgetCache) {
|
|
||||||
const module = await import(
|
|
||||||
/* @vite-ignore */
|
|
||||||
"../loras_widget.js"
|
|
||||||
);
|
|
||||||
addLorasWidgetCache = module.addLorasWidget;
|
|
||||||
}
|
|
||||||
const isRandomizerNode = node.comfyClass === "Lora Randomizer (LoraManager)";
|
|
||||||
const callback = isRandomizerNode ? () => {
|
|
||||||
updateDownstreamLoaders(node);
|
|
||||||
} : null;
|
|
||||||
const opts = {
|
|
||||||
isRandomizerNode
|
|
||||||
};
|
|
||||||
if (isRandomizerNode) {
|
|
||||||
opts.onSelectionChange = async (selection) => {
|
|
||||||
var _a2, _b, _c, _d, _e2;
|
|
||||||
if (!(selection == null ? void 0 : selection.name) || !(selection == null ? void 0 : selection.active)) return;
|
|
||||||
const infoNodes = [];
|
|
||||||
if (node.outputs) {
|
|
||||||
for (const output of node.outputs) {
|
|
||||||
if (!((_a2 = output == null ? void 0 : output.links) == null ? void 0 : _a2.length)) continue;
|
|
||||||
for (const linkId of output.links) {
|
|
||||||
const links = (_b = node.graph) == null ? void 0 : _b.links;
|
|
||||||
if (!links) continue;
|
|
||||||
const link = Array.isArray(links) ? links[linkId] : (_c = links.get) == null ? void 0 : _c.call(links, linkId);
|
|
||||||
if (!link) continue;
|
|
||||||
const targetNode = (_e2 = (_d = node.graph) == null ? void 0 : _d.getNodeById) == null ? void 0 : _e2.call(_d, link.target_id);
|
|
||||||
if ((targetNode == null ? void 0 : targetNode.comfyClass) === "Lora Info (LoraManager)") {
|
|
||||||
infoNodes.push(targetNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (infoNodes.length === 0) return;
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
infoNode.__loraInfoReqId = (infoNode.__loraInfoReqId || 0) + 1;
|
|
||||||
}
|
|
||||||
const reqIdSnapshot = /* @__PURE__ */ new Map();
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
reqIdSnapshot.set(infoNode, infoNode.__loraInfoReqId);
|
|
||||||
}
|
|
||||||
let infoData;
|
|
||||||
try {
|
|
||||||
const response = await api$1.fetchApi(
|
|
||||||
`/lm/loras/get-notes?name=${encodeURIComponent(selection.name)}`,
|
|
||||||
{ method: "GET" }
|
|
||||||
);
|
|
||||||
if (response == null ? void 0 : response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
infoData = {
|
|
||||||
name: selection.name,
|
|
||||||
notes: (data == null ? void 0 : data.notes) || "",
|
|
||||||
filePath: (data == null ? void 0 : data.file_path) || ""
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
infoData = { name: selection.name, notes: "[Error loading notes]", filePath: "" };
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
infoData = { name: selection.name, notes: "[Error loading notes]", filePath: "" };
|
|
||||||
}
|
|
||||||
for (const infoNode of infoNodes) {
|
|
||||||
if (infoNode.__loraInfoReqId !== reqIdSnapshot.get(infoNode)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (typeof infoNode._setLoraInfo === "function") {
|
|
||||||
infoNode._setLoraInfo(infoData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return addLorasWidgetCache(node, "loras", opts, callback);
|
|
||||||
},
|
|
||||||
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
AUTOCOMPLETE_TEXT_LORAS(node) {
|
AUTOCOMPLETE_TEXT_LORAS(node) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -7,9 +7,7 @@ import {
|
|||||||
getWidgetByName,
|
getWidgetByName,
|
||||||
getWidgetSerializedValue,
|
getWidgetSerializedValue,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
import { addLorasWidget } from "./loras_widget.js";
|
|
||||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "LoraManager.WanVideoLoraSelect",
|
name: "LoraManager.WanVideoLoraSelect",
|
||||||
@@ -64,11 +62,16 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = addLorasWidget(this, "loras", {
|
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||||
onSelectionChange: (selection) => {
|
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||||
updateConnectedLoraInfoNodes(this, selection);
|
const lorasWidget = getWidgetByName(this, "loras");
|
||||||
},
|
if (!lorasWidget) {
|
||||||
}, (value) => {
|
console.warn("LoRA Manager: loras widget not found for WanVideo Lora Select");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lorasWidget = lorasWidget;
|
||||||
|
|
||||||
|
lorasWidget.callback = (value) => {
|
||||||
// Prevent recursive calls
|
// Prevent recursive calls
|
||||||
if (isUpdating) return;
|
if (isUpdating) return;
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
@@ -87,9 +90,7 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleInputSync(value);
|
scheduleInputSync(value);
|
||||||
});
|
};
|
||||||
|
|
||||||
this.lorasWidget = result.widget;
|
|
||||||
|
|
||||||
// Set up callback for the text input widget to trigger merge logic
|
// Set up callback for the text input widget to trigger merge logic
|
||||||
inputWidget.callback = (value) => {
|
inputWidget.callback = (value) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user