Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(create): Edit takes more than one image

purplef280f89342ab
diff --git a/src/api/__tests__/qwen-image-21-workflow.test.ts b/src/api/__tests__/qwen-image-21-workflow.test.ts
index 01bbe830..766fbdcd 100644
--- a/src/api/__tests__/qwen-image-21-workflow.test.ts
+++ b/src/api/__tests__/qwen-image-21-workflow.test.ts
@@ -424,3 +424,43 @@ describe('Qwen-Image 2.1 bundle', () => {
expect(bundle!.customNodes || []).toHaveLength(0)
})
})
+
+// ── Further references (GH #144) ────────────────────────────────────────
+
+describe('buildDynamicWorkflow, Qwen-Image 2.1 edit with further references', () => {
+ beforeEach(() => {
+ vi.mocked(getAllNodeInfo).mockResolvedValue(QWEN_NODES as never)
+ serveEnums()
+ })
+
+ it('the source is image_1 and every reference follows as image_2 and up', async () => {
+ const wf = await buildDynamicWorkflow({
+ ...baseParams, inputImage: 'scene.png', denoise: 0.7, referenceImages: ['person.png', 'outfit.png'],
+ } as never)
+ const enc = nodeOf(wf, 'TextEncodeQwenImage21')![1]
+ const loaded = (slot: string) => {
+ const [id] = enc.inputs[slot] as [string, number]
+ return wf[id].inputs!.image
+ }
+ expect(loaded('images.image_1')).toBe('scene.png')
+ expect(loaded('images.image_2')).toBe('person.png')
+ expect(loaded('images.image_3')).toBe('outfit.png')
+ expect(enc.inputs['images.image_4']).toBeUndefined()
+ expect(nodesOf(wf, 'LoadImage')).toHaveLength(3)
+ })
+
+ it('takes no more than three references besides the source', async () => {
+ const wf = await buildDynamicWorkflow({
+ ...baseParams, inputImage: 'scene.png', denoise: 0.7, referenceImages: ['a.png', 'b.png', 'c.png', 'd.png'],
+ } as never)
+ const enc = nodeOf(wf, 'TextEncodeQwenImage21')![1]
+ expect(enc.inputs['images.image_4']).toBeDefined()
+ expect(enc.inputs['images.image_5']).toBeUndefined()
+ })
+
+ // Negative control: references without a source are not an edit at all.
+ it('a generate run ignores references', async () => {
+ const wf = await buildDynamicWorkflow({ ...baseParams, referenceImages: ['person.png'] } as never)
+ expect(nodeOf(wf, 'LoadImage')).toBeUndefined()
+ })
+})
diff --git a/src/api/__tests__/sniffed-families-workflow.test.ts b/src/api/__tests__/sniffed-families-workflow.test.ts
index 66c91202..24638d5c 100644
--- a/src/api/__tests__/sniffed-families-workflow.test.ts
+++ b/src/api/__tests__/sniffed-families-workflow.test.ts
@@ -97,6 +97,27 @@ describe('each sniffed family builds its official template graph', () => {
expect(classTypes(wf)).not.toContain('TextEncodeQwenImageEditPlus')
})
+ // GH #144: TextEncodeQwenImageEditPlus has image1 to image3, so the source
+ // plus two references, on both sides of the guidance.
+ it('Qwen-Image-Edit: references go in as image2 and image3, a third is dropped', async () => {
+ const wf = await buildDynamicWorkflow(run('qwen_image_edit_2509_fp8_e4m3fn.safetensors', {
+ inputImage: 'house.png', denoise: 0.7, referenceImages: ['door.png', 'cat.png', 'extra.png'],
+ }), 'qwenimage1')
+ const edits = Object.values(wf).filter((n) => n.class_type === 'TextEncodeQwenImageEditPlus')
+ expect(edits).toHaveLength(2)
+ for (const e of edits) {
+ expect(wf[(e.inputs!.image2 as [string, number])[0]].inputs!.image).toBe('door.png')
+ expect(wf[(e.inputs!.image3 as [string, number])[0]].inputs!.image).toBe('cat.png')
+ expect(e.inputs!.image4).toBeUndefined()
+ }
+ })
+
+ // Negative control: a family without reference slots builds as before.
+ it('Qwen-Image 1 (not an edit file) ignores references', async () => {
+ const wf = await buildDynamicWorkflow(run('qwen_image_fp8_e4m3fn.safetensors', { inputImage: 'src.png', denoise: 0.6, referenceImages: ['x.png'] }), 'qwenimage1')
+ expect(Object.values(wf).filter((n) => n.class_type === 'LoadImage')).toHaveLength(1)
+ })
+
it('Qwen-Image-Edit: the source goes through TextEncodeQwenImageEditPlus on both sides, denoise 1, CFGNorm, shift 3', async () => {
const wf = await buildDynamicWorkflow(run('qwen_image_edit_2509_fp8_e4m3fn.safetensors', { inputImage: 'house.png', denoise: 0.7 }), 'qwenimage1')
const edits = Object.values(wf).filter((n) => n.class_type === 'TextEncodeQwenImageEditPlus')
diff --git a/src/api/comfyui.ts b/src/api/comfyui.ts
index bbb91fdd..e528db0b 100644
--- a/src/api/comfyui.ts
+++ b/src/api/comfyui.ts
@@ -52,6 +52,9 @@ export interface GenerateParams {
seed: number
batchSize: number
inputImage?: string // I2I source image filename (uploaded to ComfyUI)
+ /** Edit: further reference images (ComfyUI upload names) after the source,
+ * for the families lib/edit-references names. GH #144. */
+ referenceImages?: string[]
/** What the model file carries besides the diffusion model (header sniff).
* Lets an all-in-one file in models/checkpoints use its own encoder/VAE. */
modelParts?: { textEncoder: boolean; vae: boolean }
diff --git a/src/api/dynamic-workflow.ts b/src/api/dynamic-workflow.ts
index 43616e8b..d313b580 100644
--- a/src/api/dynamic-workflow.ts
+++ b/src/api/dynamic-workflow.ts
@@ -57,6 +57,7 @@ function specDefault(spec: ComfyInputValue | undefined): ComfyInputValue | undef
// dort). Re-Export, damit bestehende Importpfade unverändert bleiben.
export { promptFilenamePrefix, videoDecodeNode } from './comfyui-graph'
import { promptFilenamePrefix, videoDecodeNode } from './comfyui-graph'
+import { extraReferenceSlots, isQwenImageEditModel } from '../lib/edit-references'
// ─── Strategy Detection ───
@@ -382,13 +383,6 @@ const SNIFFED_FAMILY: Partial<Record<WorkflowStrategy, SniffedFamily>> = {
/** Latent spaces that start from EmptySD3LatentImage (16 channels). */
const SD3_LATENT_STRATEGIES = new Set<WorkflowStrategy>(['unet_chroma', 'unet_hidream', 'unet_sd3', 'unet_lumina2', 'unet_qwenimage1'])
-/** Qwen-Image-Edit (2509/2511) and FireRed edit files take the source image
- * through TextEncodeQwenImageEditPlus; plain Qwen-Image does latent img2img. */
-export function isQwenImageEditModel(name: string): boolean {
- const lower = name.toLowerCase()
- return lower.includes('edit') && (lower.includes('qwen') || lower.includes('firered'))
-}
-
/** Verbatim from comfy_extras/nodes_lumina2.py (SYSTEM_PROMPT["superior"]) and
* the negative of the NetaYume Lumina template. */
const LUMINA2_POSITIVE_SYSTEM = 'You are an assistant designed to generate superior images with the superior degree of image-text alignment based on textual prompts or user prompts.'
@@ -1009,6 +1003,11 @@ export async function buildDynamicWorkflow(
// the source goes through TextEncodeQwenImageEditPlus on both sides and is
// the latent itself, sampled at denoise 1.0 like the template.
const isQwen1Edit = !isVideo && strategy === 'unet_qwenimage1' && !!gp.inputImage && isQwenImageEditModel(params.model)
+ // Extra reference images, only for a family that takes them and only as
+ // many as it has slots for (lib/edit-references); anything else ignores them.
+ const references = (isQwenEdit || isQwen1Edit)
+ ? (gp.referenceImages ?? []).slice(0, extraReferenceSlots(type, params.model))
+ : []
if (isQwen1Edit && !allNodes['TextEncodeQwenImageEditPlus']) {
throw new WorkflowUnavailableError(
'Qwen-Image-Edit needs a newer ComfyUI (TextEncodeQwenImageEditPlus). Update ComfyUI, then try again.',
@@ -1047,12 +1046,14 @@ export async function buildDynamicWorkflow(
resolution: qwenEditResolution(params.width, params.height),
}
if (isQwenEdit) {
- const qwenImageId = String(n++)
- workflow[qwenImageId] = {
- class_type: 'LoadImage',
- inputs: { image: gp.inputImage },
+ // The source is image_1 and sets the output shape; the references the
+ // user added follow as image_2 and up, the names the prompt uses.
+ const images = [gp.inputImage!, ...references]
+ for (const [i, image] of images.entries()) {
+ const loadId = String(n++)
+ workflow[loadId] = { class_type: 'LoadImage', inputs: { image } }
+ qwenInputs[`images.image_${i + 1}`] = [loadId, 0]
}
- qwenInputs['images.image_1'] = [qwenImageId, 0]
qwenInputs.vae = [vaeSourceId, vaeOutputSlot]
}
workflow[posId] = { class_type: 'TextEncodeQwenImage21', inputs: qwenInputs }
@@ -1066,8 +1067,16 @@ export async function buildDynamicWorkflow(
workflow[scaleId] = { class_type: 'FluxKontextImageScale', inputs: { image: [loadId, 0] } }
qwen1EditImageRef = [scaleId, 0]
}
+ // References go in unscaled as image2 and image3: the node resizes every
+ // extra image itself, only image1 sets the canvas.
+ const refInputs: ComfyNodeInputs = {}
+ for (const [i, image] of references.entries()) {
+ const refId = String(n++)
+ workflow[refId] = { class_type: 'LoadImage', inputs: { image } }
+ refInputs[`image${i + 2}`] = [refId, 0]
+ }
const editInputs = (prompt: string): ComfyNodeInputs => ({
- clip: [clipSourceId, clipOutputSlot], prompt, vae: [vaeSourceId, vaeOutputSlot], image1: qwen1EditImageRef!,
+ clip: [clipSourceId, clipOutputSlot], prompt, vae: [vaeSourceId, vaeOutputSlot], image1: qwen1EditImageRef!, ...refInputs,
})
workflow[posId] = { class_type: 'TextEncodeQwenImageEditPlus', inputs: editInputs(params.prompt) }
workflow[negId] = { class_type: 'TextEncodeQwenImageEditPlus', inputs: editInputs(params.negativePrompt || '') }
diff --git a/src/components/create/experimental/CreateContext.tsx b/src/components/create/experimental/CreateContext.tsx
index b06a9b58..8e93c324 100644
--- a/src/components/create/experimental/CreateContext.tsx
+++ b/src/components/create/experimental/CreateContext.tsx
@@ -142,6 +142,11 @@ export function CreateExpProvider({ children }: { children: ReactNode }) {
.then((ref) => useCreateStore.getState().setSource(ref))
.catch(() => { /* next generate surfaces the error */ })
}
+ if (s.references.some((r) => !r.filename)) {
+ Promise.all(s.references.map((r, i) => ensureLocalFilename(r, `reference-${i + 2}.png`)))
+ .then((refs) => useCreateStore.getState().setReferences(refs))
+ .catch(() => { /* next generate surfaces the error */ })
+ }
if (s.mask && !s.mask.filename) {
ensureLocalFilename(s.mask, 'mask.png')
.then((ref) => useCreateStore.getState().setMask(ref))
diff --git a/src/components/create/experimental/ReferenceStrip.tsx b/src/components/create/experimental/ReferenceStrip.tsx
new file mode 100644
index 00000000..11ac7bd1
--- /dev/null
+++ b/src/components/create/experimental/ReferenceStrip.tsx
@@ -0,0 +1,128 @@
+// The reference strip under the Edit source (GH #144, Discord s3aldra and
+// tbjdrw, 2026-09-23 to 09-27): Edit took one image, so "put the person from
+// this photo into that scene" could not be asked. Layout picked by David on
+// 2026-10-01: the source stays large, the further images sit as small tiles
+// below it with a "+ Reference" tile, and the prompt names them image 2,
+// image 3. Shown only for a local model that takes more than one image.
+import { useRef, useState } from 'react'
+import { ImagePlus, Loader2, X } from 'lucide-react'
+import { useCreateStore } from '../../../stores/createStore'
+import { classifyModel } from '../../../api/comfyui'
+import { extraReferenceSlots } from '../../../lib/edit-references'
+import { loadImageRef } from './loadImage'
+import { GALLERY_DRAG_TYPE, fetchGalleryItemBlob } from './galleryUrl'
+import { cn } from '../ui/cn'
+
+const TILE = 'w-16 h-16 rounded-lg shrink-0'
+
+export function ReferenceStrip() {
+ const references = useCreateStore((s) => s.references)
+ const addReference = useCreateStore((s) => s.addReference)
+ const removeReference = useCreateStore((s) => s.removeReference)
+ const setError = useCreateStore((s) => s.setError)
+ const gallery = useCreateStore((s) => s.gallery)
+ const backend = useCreateStore((s) => s.backend)
+ const intent = useCreateStore((s) => s.intent())
+ const imageModel = useCreateStore((s) => s.imageModel)
+ const listedType = useCreateStore((s) => s.imageModelList.find((m) => m.name === s.imageModel)?.type)
+ const inputRef = useRef<HTMLInputElement>(null)
+ const [loading, setLoading] = useState(false)
+ const [drag, setDrag] = useState(false)
+
+ // The type from the fetched list carries the header sniff; the name is the
+ // fallback, exactly as useCreate decides the pipeline.
+ const slots = extraReferenceSlots(listedType ?? classifyModel(imageModel), imageModel)
+ if (intent !== 'edit' || backend !== 'local' || slots === 0) return null
+ const shown = references.slice(0, slots)
+ const canAdd = shown.length < slots
+
+ const add = async (load: () => Promise<File>) => {
+ setLoading(true)
+ setError(null)
+ try {
+ addReference(await loadImageRef(await load()))
+ } catch (err) {
+ setError(`Could not load the image: ${err instanceof Error ? err.message : String(err)}`)
+ } finally {
+ setLoading(false)
+ }
+ }
+
+ const addFile = (file: File) => {
+ if (!file.type.startsWith('image/')) {
+ setError('That file type is not supported. Use PNG, JPG or WebP.')
+ return
+ }
+ void add(async () => file)
+ }
+
+ return (
+ <div className="mt-3 flex flex-col items-center gap-2" data-testid="reference-strip">
+ <div
+ className={cn('flex items-center gap-2 rounded-xl p-1 transition-colors', drag && 'bg-blue-500/10')}
+ onDragOver={(e) => { if (canAdd) { e.preventDefault(); setDrag(true) } }}
+ onDragLeave={() => setDrag(false)}
+ onDrop={(e) => {
+ e.preventDefault()
+ setDrag(false)
+ if (!canAdd || loading) return
+ const f = e.dataTransfer.files[0]
+ if (f) { addFile(f); return }
+ const item = gallery.find((g) => g.id === e.dataTransfer.getData(GALLERY_DRAG_TYPE))
+ if (item) {
+ void add(async () => {
+ const blob = await fetchGalleryItemBlob(item)
+ return new File([blob], item.filename || 'reference.png', { type: blob.type || 'image/png' })
+ })
+ }
+ }}
+ >
+ {shown.map((ref, i) => (
+ <div key={`${ref.url.slice(-24)}-${i}`} className={cn(TILE, 'relative')}>
+ <img
+ src={ref.url}
+ alt={`image ${i + 2}`}
+ className={cn(TILE, 'object-cover border border-white/[0.06]')}
+ />
+ <span className="absolute bottom-1 left-1 t-micro text-gray-200 bg-black/60 px-1 rounded">{i + 2}</span>
+ <button
+ onClick={() => removeReference(i)}
+ className="absolute top-1 right-1 w-5 h-5 flex items-center justify-center rounded-md bg-black/60 text-gray-300 hover:text-white"
+ title={`Remove image ${i + 2}`}
+ aria-label={`Remove image ${i + 2}`}
+ >
+ <X size={11} />
+ </button>
+ </div>
+ ))}
+ {canAdd && (
+ <button
+ onClick={() => inputRef.current?.click()}
+ disabled={loading}
+ className={cn(TILE, 'border-2 border-dashed border-white/10 hover:border-white/25 text-gray-500 hover:text-gray-300 flex flex-col items-center justify-center gap-0.5 transition-colors')}
+ title="Add another image the edit can use"
+ >
+ {loading ? <Loader2 size={16} className="animate-spin" /> : <ImagePlus size={16} />}
+ <span className="t-micro">Reference</span>
+ </button>
+ )}
+ </div>
+ <p className="t-label text-gray-600 text-center max-w-sm">
+ {shown.length === 0
+ ? `Add up to ${slots} more images, for example a person or an outfit to bring into this one.`
+ : `Name them in the prompt as ${shown.map((_, i) => `image ${i + 2}`).join(', ')}.`}
+ </p>
+ <input
+ ref={inputRef}
+ type="file"
+ accept="image/*"
+ className="hidden"
+ onChange={(e) => {
+ const f = e.target.files?.[0]
+ e.target.value = ''
+ if (f) addFile(f)
+ }}
+ />
+ </div>
+ )
+}
diff --git a/src/components/create/experimental/Stage.tsx b/src/components/create/experimental/Stage.tsx
index 1f8b30b2..5ebb0168 100644
--- a/src/components/create/experimental/Stage.tsx
+++ b/src/components/create/experimental/Stage.tsx
@@ -21,6 +21,7 @@ import { InstallCancelled } from '../../../lib/bundle-install'
import { isMlxImageHost } from '../../../api/mlx-image'
import { bundleForVideoIntent } from '../../../api/comfyui'
import { getVideoBundles } from '../../../api/discover'
+import { ReferenceStrip } from './ReferenceStrip'
import { MIN_TRAIN_IMAGES, maxTrainImages } from '../../../lib/train-image-cap'
interface Props {
@@ -335,6 +336,7 @@ function SourcePreview({ onOpenMaskEditor }: { onOpenMaskEditor: () => void }) {
<X size={14} />
</button>
</div>
+ <ReferenceStrip />
<div className="flex items-center gap-2 mt-4">
{meta.allowsMask && (
<Button variant="secondary" icon={Wand2} onClick={onOpenMaskEditor}>{mask ? 'Edit mask' : 'Paint mask'}</Button>
diff --git a/src/components/create/experimental/__tests__/edit-takes-more-than-one-image.test.tsx b/src/components/create/experimental/__tests__/edit-takes-more-than-one-image.test.tsx
new file mode 100644
index 00000000..7515eb77
--- /dev/null
+++ b/src/components/create/experimental/__tests__/edit-takes-more-than-one-image.test.tsx
@@ -0,0 +1,76 @@
+// @vitest-environment jsdom
+/**
+ * GH #144 and Discord (s3aldra 2026-09-23 and 09-27, tbjdrw 2026-09-25): Edit
+ * took one image. The strip under the source (layout David picked on
+ * 2026-10-01) adds references for a model that takes them, and only there.
+ *
+ * Run: npx vitest run src/components/create/experimental/__tests__/edit-takes-more-than-one-image.test.tsx
+ */
+import { describe, expect, it, vi, beforeEach } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+vi.mock('../loadImage', () => ({
+ loadImageRef: vi.fn(async (f: File) => ({ filename: `up_${f.name}`, url: `data:image/png;base64,${f.name}`, width: 8, height: 8 })),
+}))
+
+import { ReferenceStrip } from '../ReferenceStrip'
+import { useCreateStore } from '../../../../stores/createStore'
+import { extraReferenceSlots } from '../../../../lib/edit-references'
+
+const SOURCE = { filename: 'scene.png', url: 'data:image/png;base64,scene', width: 8, height: 8 }
+const QWEN21 = 'qwen_image_2.1_int8_convrot.safetensors'
+
+function editWith(model: string, type: string, backend: 'local' | 'cloud' = 'local') {
+ useCreateStore.setState({
+ backend,
+ imageModel: model,
+ imageModelList: [{ name: model, type }] as never,
+ references: [],
+ })
+ useCreateStore.getState().setIntent('edit')
+ useCreateStore.getState().setSource(SOURCE)
+}
+
+beforeEach(() => cleanup())
+
+describe('which models take references', () => {
+ it('Qwen-Image 2.1 takes three besides the source, Qwen-Image-Edit two, SDXL none', () => {
+ expect(extraReferenceSlots('qwenimage', QWEN21)).toBe(3)
+ expect(extraReferenceSlots('qwenimage1', 'qwen_image_edit_2509_fp8.safetensors')).toBe(2)
+ expect(extraReferenceSlots('qwenimage1', 'qwen_image_fp8.safetensors')).toBe(0)
+ expect(extraReferenceSlots('sdxl', 'juggernautXL.safetensors')).toBe(0)
+ })
+})
+
+describe('the reference strip', () => {
+ it('shows under a Qwen-Image 2.1 edit and adds an image as image 2', async () => {
+ editWith(QWEN21, 'qwenimage')
+ render(<ReferenceStrip />)
+ expect(screen.getByText(/Add up to 3 more images/)).toBeTruthy()
+ const input = screen.getByTestId('reference-strip').querySelector('input[type=file]') as HTMLInputElement
+ fireEvent.change(input, { target: { files: [new File(['x'], 'person.png', { type: 'image/png' })] } })
+ await screen.findByAltText('image 2')
+ expect(useCreateStore.getState().references.map((r) => r.filename)).toEqual(['up_person.png'])
+ expect(screen.getByText('Name them in the prompt as image 2.')).toBeTruthy()
+ })
+
+ it('removing the source drops its references too', () => {
+ editWith(QWEN21, 'qwenimage')
+ useCreateStore.getState().addReference(SOURCE)
+ useCreateStore.getState().setSource(null)
+ expect(useCreateStore.getState().references).toEqual([])
+ })
+
+ // Negative controls: a model with one slot, and the cloud backend.
+ it('is not there for an SDXL checkpoint', () => {
+ editWith('juggernautXL.safetensors', 'sdxl')
+ render(<ReferenceStrip />)
+ expect(screen.queryByTestId('reference-strip')).toBeNull()
+ })
+
+ it('is not there on the cloud backend', () => {
+ editWith(QWEN21, 'qwenimage', 'cloud')
+ render(<ReferenceStrip />)
+ expect(screen.queryByTestId('reference-strip')).toBeNull()
+ })
+})
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index 2f90203d..a04b5192 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -584,7 +584,7 @@ export function useCreate() {
mode, prompt, negativePrompt, imageModel, videoModel,
sampler, scheduler, steps, cfgScale, width, height, seed, batchSize, frames, fps, denoise,
hiresFixEnabled, hiresScale, hiresDenoise, hiresSteps, hiresUpscaleMethod, i2iImage, i2vImage,
- source, mask, growMaskBy, removebg, selectedLoras, selectedVae, clipSkip,
+ source, references, mask, growMaskBy, removebg, selectedLoras, selectedVae, clipSkip,
setIsGenerating, setProgress, setCurrentPromptId, setError, addToGallery, addToPromptHistory,
} = state
@@ -963,6 +963,11 @@ export function useCreate() {
// dropped the source without a word. Edit always keeps the source;
// 0.95 is the most it repaints (the slider tops out there too).
...(isI2I && !isRemoveBg && effInputImage ? { inputImage: effInputImage, denoise: Math.min(denoise, EDIT_MAX_DENOISE) } : {}),
+ // GH #144: further references ride along; the builder keeps only as
+ // many as the model's family takes (lib/edit-references).
+ ...(isI2I && !isRemoveBg && effInputImage && references.some((r) => r.filename)
+ ? { referenceImages: references.map((r) => r.filename).filter(Boolean) }
+ : {}),
...(!isRemoveBg && maskFilename ? { maskImage: maskFilename, growMaskBy } : {}),
// Advanced adjustments. LoRA feeds the builder's `lora`/`loraStrength`
// contract (string[] + number[]); the old `loras` key was read by nobody,
diff --git a/src/lib/edit-references.ts b/src/lib/edit-references.ts
new file mode 100644
index 00000000..039314ed
--- /dev/null
+++ b/src/lib/edit-references.ts
@@ -0,0 +1,30 @@
+import type { ModelType } from '../api/comfyui'
+
+/** Qwen-Image-Edit (2509/2511) and FireRed edit files take the source image
+ * through TextEncodeQwenImageEditPlus; plain Qwen-Image does latent img2img. */
+export function isQwenImageEditModel(name: string): boolean {
+ const lower = name.toLowerCase()
+ return lower.includes('edit') && (lower.includes('qwen') || lower.includes('firered'))
+}
+
+/** The most extra references any family takes in LU (Qwen-Image 2.1). */
+export const MAX_EXTRA_REFERENCES = 3
+
+/**
+ * How many reference images an Edit may carry BESIDES the source, for one
+ * local image model. 0 hides the reference strip.
+ *
+ * GH #144 and Discord (s3aldra 2026-09-23 and 09-27, tbjdrw 2026-09-25):
+ * Edit took one image, so "put the person from this photo into that scene"
+ * could not be asked at all. Read off the node schemas:
+ * - TextEncodeQwenImage21 (Qwen-Image 2.1) has an Autogrow group of
+ * reference slots image_1 to image_16. LU offers four images in all, the
+ * range the official edit template and the model card show.
+ * - TextEncodeQwenImageEditPlus (Qwen-Image-Edit 2509/2511) has image1 to
+ * image3, so the source plus two.
+ */
+export function extraReferenceSlots(type: ModelType | null | undefined, modelName: string): number {
+ if (type === 'qwenimage') return MAX_EXTRA_REFERENCES
+ if (type === 'qwenimage1' && isQwenImageEditModel(modelName)) return 2
+ return 0
+}
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index 41b2d1a7..9ab0fed2 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -1,5 +1,6 @@
import { create } from 'zustand'
import { maxTrainImages } from '../lib/train-image-cap'
+import { MAX_EXTRA_REFERENCES } from '../lib/edit-references'
import type { FixupPrompt } from '../lib/render-fixups'
import { persist } from 'zustand/middleware'
import { safeJSONStorage } from '../lib/storage-quota'
@@ -12,7 +13,7 @@ import { isRecord } from '../types/json-guards'
* results, the in-flight flag). Everything else in the blob is a preference.
*/
const RUNTIME_ONLY_KEYS: readonly string[] = [
- 'backend', 'source', 'mask', 'caps', 'isGenerating', 'comfyCorsBlocked',
+ 'backend', 'source', 'mask', 'references', 'caps', 'isGenerating', 'comfyCorsBlocked',
// Ein gespeicherter Preis von gestern ist eine Luege (siehe partialize
// unten): auch wenn ein fremder/aelterer Blob ihn doch mitbringt, darf er
// nie zurueckkommen.
@@ -332,6 +333,9 @@ interface CreateState {
/** Unified Stage input slot (runtime-only). On the local path source.filename
* maps to i2iImage/i2vImage; on the cloud path it is a render-inputs path. */
source: ImageRef | null
+ /** Edit: further reference images after the source, for a model that takes
+ * them (lib/edit-references). Runtime-only like `source`; cleared with it. */
+ references: ImageRef[]
sourceSetAt: number
mask: ImageRef | null
/** Runtime-only: local (Bridge) vs cloud (/api/jobs), derived from session. */
@@ -457,6 +461,9 @@ interface CreateState {
setMusicLyrics: (l: string) => void
setMusicHowtoSeen: (v: boolean) => void
setSource: (img: ImageRef | null) => void
+ addReference: (img: ImageRef) => void
+ removeReference: (index: number) => void
+ setReferences: (refs: ImageRef[]) => void
setMask: (img: ImageRef | null) => void
setBackend: (backend: CreateBackend) => void
setCloudImageModel: (id: string) => void
@@ -621,6 +628,7 @@ export const useCreateStore = create<CreateState>()(
clipSkip: 0,
growMaskBy: 6,
source: null as ImageRef | null,
+ references: [] as ImageRef[],
sourceSetAt: 0,
mask: null as ImageRef | null,
backend: 'local' as CreateBackend,
@@ -750,7 +758,7 @@ export const useCreateStore = create<CreateState>()(
// removebg/animate keep the source but drop a stale mask. Video/animate
// mirror setMode's reset so image resolution never leaks into video.
// A stale error from the previous intent never carries over.
- const dropAll = { source: null, mask: null, sourceSetAt: 0 }
+ const dropAll = { source: null, mask: null, sourceSetAt: 0, references: [] }
const base = { removebg: false, utilityOp: null, cloudOp: null, error: null }
switch (intent) {
// ── 2.5.8 cloud categories. Inputs specific to each (train set,
@@ -886,7 +894,12 @@ export const useCreateStore = create<CreateState>()(
setMusicDuration: (s2) => set({ musicDuration: Math.max(5, Math.min(240, Math.floor(s2))) }),
setMusicLyrics: (musicLyrics) => set({ musicLyrics: musicLyrics.slice(0, 2000) }),
setMusicHowtoSeen: (musicHowtoSeen) => set({ musicHowtoSeen }),
- setSource: (source) => set({ source, sourceSetAt: source ? Date.now() : 0, ...(source ? {} : { mask: null }) }),
+ setSource: (source) => set({ source, sourceSetAt: source ? Date.now() : 0, ...(source ? {} : { mask: null, references: [] }) }),
+ // Capped at the most any family takes (lib/edit-references); the UI
+ // offers fewer for a model with fewer slots and the builder slices.
+ addReference: (img) => set((s) => ({ references: [...s.references, img].slice(0, MAX_EXTRA_REFERENCES) })),
+ removeReference: (index) => set((s) => ({ references: s.references.filter((_, i) => i !== index) })),
+ setReferences: (references) => set({ references }),
setMask: (mask) => set({ mask }),
// Flipping to local clears the intents that have no local lane
// (upscale/eraser plus character training — all hosted-only) so the