diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/buildFLUXGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/buildFLUXGraph.ts index c97b34a174..6aec9cad23 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/buildFLUXGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/buildFLUXGraph.ts @@ -3,6 +3,8 @@ import { getPrefixedId } from 'features/controlLayers/konva/util'; import { selectMainModelConfig, selectParamsSlice } from 'features/controlLayers/store/paramsSlice'; import { selectRefImagesSlice } from 'features/controlLayers/store/refImagesSlice'; import { selectCanvasMetadata, selectCanvasSlice } from 'features/controlLayers/store/selectors'; +import { isFluxKontextReferenceImageConfig } from 'features/controlLayers/store/types'; +import { getGlobalReferenceImageWarnings } from 'features/controlLayers/store/validators'; import { addFLUXFill } from 'features/nodes/util/graph/generation/addFLUXFill'; import { addFLUXLoRAs } from 'features/nodes/util/graph/generation/addFLUXLoRAs'; import { addFLUXReduxes } from 'features/nodes/util/graph/generation/addFLUXRedux'; @@ -88,10 +90,9 @@ export const buildFLUXGraph = async (arg: GraphBuilderArg): Promise entity.isEnabled) + .filter((entity) => isFluxKontextReferenceImageConfig(entity.config)) + .filter((entity) => getGlobalReferenceImageWarnings(entity, model).length === 0); + + // FLUX Kontext supports only a single conditioning image - we'll just take the first one. + // In the future, we can explore concatenating multiple conditioning images in image or latent space. + const firstValidFLUXKontextConfig = validFLUXKontextConfigs[0]; + + if (firstValidFLUXKontextConfig) { + const { image } = firstValidFLUXKontextConfig.config; + + assert(image, 'getGlobalReferenceImageWarnings checks if the image is there, this should never raise'); + + const kontextConditioning = g.addNode({ + type: 'flux_kontext', + id: getPrefixedId('flux_kontext'), + image, + }); + g.addEdge(kontextConditioning, 'kontext_cond', denoise, 'kontext_conditioning'); + } } g.addEdge(modelLoader, 'transformer', denoise, 'transformer');