mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 05:00:03 +00:00
[bugfix] Filter model metadata by current widget selection (#4021)
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
@@ -62,6 +62,7 @@ import {
|
||||
findLegacyRerouteNodes,
|
||||
noNativeReroutes
|
||||
} from '@/utils/migration/migrateReroute'
|
||||
import { getSelectedModelsMetadata } from '@/utils/modelMetadataUtil'
|
||||
import { deserialiseAndCreate } from '@/utils/vintageClipboard'
|
||||
|
||||
import { type ComfyApi, PromptExecutionError, api } from './api'
|
||||
@@ -1026,8 +1027,10 @@ export class ComfyApp {
|
||||
}
|
||||
|
||||
// Collect models metadata from node
|
||||
if (n.properties?.models?.length)
|
||||
embeddedModels.push(...n.properties.models)
|
||||
const selectedModels = getSelectedModelsMetadata(n)
|
||||
if (selectedModels?.length) {
|
||||
embeddedModels.push(...selectedModels)
|
||||
}
|
||||
}
|
||||
|
||||
// Merge models from the workflow's root-level 'models' field
|
||||
|
||||
51
src/utils/modelMetadataUtil.ts
Normal file
51
src/utils/modelMetadataUtil.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { ModelFile } from '@/schemas/comfyWorkflowSchema'
|
||||
|
||||
/**
|
||||
* Gets models from the node's `properties.models` field, excluding those
|
||||
* not currently selected in at least 1 of the node's widget values.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const node = {
|
||||
* type: 'CheckpointLoaderSimple',
|
||||
* widgets_values: ['model1', 'model2'],
|
||||
* properties: { models: [{ name: 'model1' }, { name: 'model2' }, { name: 'model3' }] }
|
||||
* ... other properties
|
||||
* }
|
||||
* const selectedModels = getSelectedModelsMetadata(node)
|
||||
* // selectedModels = [{ name: 'model1' }, { name: 'model2' }]
|
||||
* ```
|
||||
*
|
||||
* @param node - The workflow node to process
|
||||
* @returns Filtered array containing only models that are currently selected
|
||||
*/
|
||||
export function getSelectedModelsMetadata(node: {
|
||||
type: string
|
||||
widgets_values?: unknown[] | Record<string, unknown>
|
||||
properties?: { models?: ModelFile[] }
|
||||
}): ModelFile[] | undefined {
|
||||
try {
|
||||
if (!node.properties?.models?.length) return
|
||||
if (!node.widgets_values) return
|
||||
|
||||
const widgetValues = Array.isArray(node.widgets_values)
|
||||
? node.widgets_values
|
||||
: Object.values(node.widgets_values)
|
||||
|
||||
if (!widgetValues.length) return
|
||||
|
||||
const stringWidgetValues = new Set<string>()
|
||||
for (const widgetValue of widgetValues) {
|
||||
if (typeof widgetValue === 'string' && widgetValue.trim()) {
|
||||
stringWidgetValues.add(widgetValue)
|
||||
}
|
||||
}
|
||||
|
||||
// Return the node's models that are present in the widget values
|
||||
return node.properties.models.filter((model) =>
|
||||
stringWidgetValues.has(model.name)
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('Error filtering models by current selection:', error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user