refactor(nodes): declare loras widget as LORAS input type on lora nodes

This commit is contained in:
Will Miao
2026-08-20 13:22:11 +08:00
parent e57e11897e
commit b80830913c
15 changed files with 181 additions and 313 deletions
-88
View File
@@ -85,9 +85,6 @@ export function createAutocompleteTextWidgetInstanceId() {
return autocompleteTextWidgetInstanceId
}
// Cache for dynamically loaded addLorasWidget module
let addLorasWidgetCache: any = null
// @ts-ignore
function createLoraPoolWidget(node) {
const container = document.createElement('div')
@@ -876,91 +873,6 @@ app.registerExtension({
CYCLER_CONFIG(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)
// @ts-ignore
AUTOCOMPLETE_TEXT_LORAS(node) {