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.

fix(workflows): support custom I2V inputs and outputs

Kizerfluid6d18d6a13331
diff --git a/src/api/__tests__/workflows-validation.test.ts b/src/api/__tests__/workflows-validation.test.ts
index 6a954f05..b1c41ff3 100644
--- a/src/api/__tests__/workflows-validation.test.ts
+++ b/src/api/__tests__/workflows-validation.test.ts
@@ -1,11 +1,5 @@
import { describe, it, expect } from 'vitest'
-import {
- validateWorkflowJson,
- extractSearchTerms,
- autoDetectParameterMap,
- getBuiltinTemplates,
- parseImportedWorkflow,
-} from '../workflows'
+import { validateWorkflowJson, extractSearchTerms, autoDetectParameterMap, injectParameters, getBuiltinTemplates, parseImportedWorkflow, } from '../workflows'
import type { ModelType } from '../comfyui'
describe('workflows — pure functions', () => {
@@ -70,6 +64,132 @@ describe('workflows — pure functions', () => {
})
})
+it('injects LU dimensions into a legacy ImageResizeKJv2 workflow', async () => {
+ const wf = {
+ '10': {
+ class_type: 'LoadImage',
+ inputs: {
+ image: 'placeholder.png',
+ },
+ },
+ '16': {
+ class_type: 'ImageResizeKJv2',
+ inputs: {
+ width: 512,
+ height: 512,
+ image: ['10', 0],
+ },
+ },
+ '9': {
+ class_type: 'WanImageToVideo',
+ inputs: {
+ width: ['16', 1],
+ height: ['16', 2],
+ start_image: ['16', 0],
+ },
+ },
+ }
+
+ const injected = await injectParameters(
+ wf,
+ {},
+ {
+ prompt: 'test',
+ negativePrompt: '',
+ model: 'test.safetensors',
+ sampler: 'euler',
+ scheduler: 'normal',
+ steps: 20,
+ cfgScale: 5,
+ width: 832,
+ height: 480,
+ seed: 1,
+ batchSize: 1,
+ frames: 81,
+ fps: 16,
+ inputImage: 'source.png',
+ },
+ 'wan',
+ )
+
+ expect(injected['16'].inputs.width).toBe(832)
+ expect(injected['16'].inputs.height).toBe(480)
+
+ // WanImageToVideo must remain connected to the resize node.
+ expect(injected['9'].inputs.width).toEqual(['16', 1])
+ expect(injected['9'].inputs.height).toEqual(['16', 2])
+})
+
+ describe('injectParameters — source image', () => {
+ const videoParams = {
+ model: 'wan2.2_i2v.safetensors',
+ prompt: 'gentle camera movement',
+ negativePrompt: '',
+ sampler: 'euler',
+ scheduler: 'simple',
+ steps: 20,
+ cfgScale: 5,
+ width: 832,
+ height: 480,
+ seed: 7,
+ batchSize: 1,
+ frames: 33,
+ fps: 16,
+ inputImage: 'lu-selected-image.png',
+ }
+
+ it('injects the LU image into the mapped LoadImage node', async () => {
+ const workflow = {
+ '12': {
+ class_type: 'LoadImage',
+ inputs: {
+ image: 'placeholder.png',
+ },
+ },
+ }
+
+ const parameterMap = autoDetectParameterMap(workflow)
+
+ const result = await injectParameters(
+ workflow,
+ parameterMap,
+ videoParams as any,
+ 'wan' as ModelType,
+ )
+
+ expect(result['12'].inputs.image).toBe(
+ 'lu-selected-image.png',
+ )
+
+ // Injection works on a cloned workflow.
+ expect(workflow['12'].inputs.image).toBe(
+ 'placeholder.png',
+ )
+ })
+
+ it('supports older saved maps without inputImage metadata', async () => {
+ const workflow = {
+ '27': {
+ class_type: 'LoadImage',
+ inputs: {
+ image: 'old-image.png',
+ },
+ },
+ }
+
+ const result = await injectParameters(
+ workflow,
+ {},
+ videoParams as any,
+ 'wan' as ModelType,
+ )
+
+ expect(result['27'].inputs.image).toBe(
+ 'lu-selected-image.png',
+ )
+ })
+ })
+
// ─── extractSearchTerms ───
describe('extractSearchTerms', () => {
@@ -124,6 +244,45 @@ describe('workflows — pure functions', () => {
// ─── autoDetectParameterMap ───
+it('detects ImageResizeKJv2 dimensions for custom I2V workflows', () => {
+ const wf = {
+ '10': {
+ class_type: 'LoadImage',
+ inputs: {
+ image: 'placeholder.png',
+ },
+ },
+ '16': {
+ class_type: 'ImageResizeKJv2',
+ inputs: {
+ width: 512,
+ height: 512,
+ image: ['10', 0],
+ },
+ },
+ '9': {
+ class_type: 'WanImageToVideo',
+ inputs: {
+ width: ['16', 1],
+ height: ['16', 2],
+ start_image: ['16', 0],
+ },
+ },
+ }
+
+ const map = autoDetectParameterMap(wf)
+
+ expect(map.width).toEqual({
+ nodeId: '16',
+ inputKey: 'width',
+ })
+
+ expect(map.height).toEqual({
+ nodeId: '16',
+ inputKey: 'height',
+ })
+})
+
describe('autoDetectParameterMap', () => {
it('detects KSampler parameters (seed, steps, cfg, sampler, scheduler)', () => {
const wf = {
diff --git a/src/api/workflows.ts b/src/api/workflows.ts
index 34525070..c3a684bd 100644
--- a/src/api/workflows.ts
+++ b/src/api/workflows.ts
@@ -242,6 +242,16 @@ export function autoDetectParameterMap(workflow: Record<string, any>): Parameter
case 'UNETLoader':
map.model = { nodeId, inputKey: 'unet_name', loaderType: 'unet' }
break
+ case 'LoadImage':
+ // A custom I2I/I2V workflow may contain more than one image
+ // loader. Use the first one as its primary LU source image.
+ if (!map.inputImage) {
+ map.inputImage = {
+ nodeId,
+ inputKey: 'image',
+ }
+ }
+ break
case 'EmptyLatentImage':
case 'EmptySD3LatentImage':
map.width = { nodeId, inputKey: 'width' }
@@ -253,6 +263,21 @@ export function autoDetectParameterMap(workflow: Record<string, any>): Parameter
map.height = { nodeId, inputKey: 'height' }
map.frames = { nodeId, inputKey: 'length' }
break
+ case 'ImageResizeKJv2':
+ if (!map.width && typeof node.inputs?.width === 'number') {
+ map.width = {
+ nodeId,
+ inputKey: 'width',
+ }
+ }
+
+ if (!map.height && typeof node.inputs?.height === 'number') {
+ map.height = {
+ nodeId,
+ inputKey: 'height',
+ }
+ }
+ break
case 'SaveAnimatedWEBP':
map.fps = { nodeId, inputKey: 'fps' }
break
@@ -301,16 +326,86 @@ export async function injectParameters(
inject(paramMap.seed, params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed)
inject(paramMap.steps, params.steps)
inject(paramMap.cfgScale, params.cfgScale)
- inject(paramMap.width, params.width)
- inject(paramMap.height, params.height)
+ let widthMapping = paramMap.width
+ let heightMapping = paramMap.height
+
+ // Older installed custom I2V workflows may predate resize-node
+ // detection. Locate their source resize node at generation time so
+ // users do not have to remove and re-import the workflow.
+ if (!widthMapping || !heightMapping) {
+ const resizeEntry = Object.entries(wf).find(
+ ([, node]) =>
+ node &&
+ typeof node === 'object' &&
+ node.class_type === 'ImageResizeKJv2' &&
+ typeof node.inputs?.width === 'number' &&
+ typeof node.inputs?.height === 'number',
+ )
+
+ if (resizeEntry) {
+ if (!widthMapping) {
+ widthMapping = {
+ nodeId: resizeEntry[0],
+ inputKey: 'width',
+ }
+ }
+
+ if (!heightMapping) {
+ heightMapping = {
+ nodeId: resizeEntry[0],
+ inputKey: 'height',
+ }
+ }
+ }
+ }
+
+ inject(widthMapping, params.width)
+ inject(heightMapping, params.height)
inject(paramMap.batchSize, params.batchSize)
inject(paramMap.sampler, params.sampler)
inject(paramMap.scheduler, params.scheduler)
+ const inputImage =
+ 'inputImage' in params &&
+ typeof params.inputImage === 'string'
+ ? params.inputImage
+ : undefined
+
+ if (inputImage) {
+ let inputImageMapping = paramMap.inputImage
+
+ // Workflows installed before inputImage mapping existed have an older
+ // persisted parameterMap. Detect their LoadImage node at generation time
+ // so users do not have to remove and re-import those workflows.
+ if (!inputImageMapping) {
+ const loadImageEntry = Object.entries(wf).find(
+ ([, node]) =>
+ node &&
+ typeof node === 'object' &&
+ node.class_type === 'LoadImage',
+ )
+
+ if (loadImageEntry) {
+ inputImageMapping = {
+ nodeId: loadImageEntry[0],
+ inputKey: 'image',
+ }
+ }
+ }
+
+ inject(inputImageMapping, inputImage)
+ }
+
if ('frames' in params) {
- inject(paramMap.frames, (params as VideoParams).frames)
- inject(paramMap.fps, (params as VideoParams).fps)
+ inject(paramMap.frames, (params as VideoParams).frames)
+ inject(paramMap.fps, (params as VideoParams).fps)
+
+ for (const node of Object.values(wf)) {
+ if (node?.class_type === 'VHS_VideoCombine' && node.inputs) {
+ node.inputs.save_output = true
+ }
}
+}
log.info('[workflows] Injected workflow nodes', { nodes: Object.entries(wf).map(([id, n]: [string, any]) =>
`${id}: ${n.class_type} (${Object.keys(n.inputs || {}).join(', ')})`
diff --git a/src/components/create/experimental/__tests__/galleryUrl.test.ts b/src/components/create/experimental/__tests__/galleryUrl.test.ts
index b9da3696..289c01c6 100644
--- a/src/components/create/experimental/__tests__/galleryUrl.test.ts
+++ b/src/components/create/experimental/__tests__/galleryUrl.test.ts
@@ -1,4 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { fetchGalleryItemBlob, galleryItemUrl, recoverGalleryUrl, } from '../galleryUrl'
+import { refreshResultUrl, resolveResultUrl } from '../../../../api/cloud/jobs'
+import { useCreateStore, type GalleryItem } from '../../../../stores/createStore'
// zustand persist reads window.localStorage at store-module load (node env
// has no DOM) — same hoisted Map shim as createStore.test.ts.
@@ -18,18 +21,18 @@ vi.hoisted(() => {
})
vi.mock('../../../../api/comfyui', () => ({
- getImageUrl: vi.fn((filename: string, subfolder?: string) => `http://127.0.0.1:8188/view?filename=${filename}&subfolder=${subfolder ?? ''}`),
- classifyModel: vi.fn(() => 'unknown'),
+ getImageUrl: vi.fn((
+ filename: string,
+ subfolder?: string,
+ type: string = 'output',
+) =>
+ `http://127.0.0.1:8188/view?filename=${filename}&subfolder=${subfolder ?? ''}&type=${type}`),
}))
vi.mock('../../../../api/cloud/jobs', () => ({
refreshResultUrl: vi.fn(),
resolveResultUrl: vi.fn(),
}))
-import { fetchGalleryItemBlob, recoverGalleryUrl } from '../galleryUrl'
-import { refreshResultUrl, resolveResultUrl } from '../../../../api/cloud/jobs'
-import { useCreateStore, type GalleryItem } from '../../../../stores/createStore'
-
const baseItem: GalleryItem = {
id: 'g1', filename: 'out.png', subfolder: '', type: 'image', prompt: '',
negativePrompt: '', model: 'm', modelType: 'unknown', seed: 1, steps: 1,
@@ -37,6 +40,26 @@ const baseItem: GalleryItem = {
batchSize: 1, createdAt: 1,
} as GalleryItem
+describe('galleryItemUrl — ComfyUI file location', () => {
+ it('preserves temp outputs from VHS_VideoCombine', () => {
+ const url = galleryItemUrl({
+ ...baseItem,
+ type: 'video',
+ filename: 'AnimateDiff_00002.mp4',
+ comfyType: 'temp',
+ })
+
+ expect(url).toContain('filename=AnimateDiff_00002.mp4')
+ expect(url).toContain('type=temp')
+ })
+
+ it('defaults older gallery entries to output', () => {
+ const url = galleryItemUrl(baseItem)
+
+ expect(url).toContain('type=output')
+ })
+})
+
describe('fetchGalleryItemBlob', () => {
beforeEach(() => {
vi.restoreAllMocks()
diff --git a/src/components/create/experimental/galleryUrl.ts b/src/components/create/experimental/galleryUrl.ts
index e51fc488..e0a8e111 100644
--- a/src/components/create/experimental/galleryUrl.ts
+++ b/src/components/create/experimental/galleryUrl.ts
@@ -7,7 +7,13 @@ import { useCreateStore, type GalleryItem } from '../../../stores/createStore'
* remoteUrl (cloud signed URL) → dataUrl (in-memory self-contained fallback)
* → ComfyUI /view path (filename/subfolder). */
export function galleryItemUrl(item: GalleryItem): string {
- return item.remoteUrl ?? item.dataUrl ?? getImageUrl(item.filename, item.subfolder)
+ return item.remoteUrl
+ ?? item.dataUrl
+ ?? getImageUrl(
+ item.filename,
+ item.subfolder,
+ item.comfyType ?? 'output',
+ )
}
// Cloud signed URLs expire ~1 h after the last read, so a persisted item's
@@ -85,7 +91,13 @@ function guessMime(filename: string): string {
export async function proxiedComfyBlobUrl(item: GalleryItem): Promise<string | null> {
if (!isTauri() || item.jobId || item.remoteUrl || item.dataUrl) return null
try {
- const bytes = await fetchLocalhostBytes(getImageUrl(item.filename, item.subfolder))
+ const bytes = await fetchLocalhostBytes(
+ getImageUrl(
+ item.filename,
+ item.subfolder,
+ item.comfyType ?? 'output',
+ ),
+)
return URL.createObjectURL(new Blob([bytes], { type: guessMime(item.filename) }))
} catch {
return null
diff --git a/src/components/workflows/TagsAndWorkflowsPage.tsx b/src/components/workflows/TagsAndWorkflowsPage.tsx
index 9ffa9661..82c98b6e 100644
--- a/src/components/workflows/TagsAndWorkflowsPage.tsx
+++ b/src/components/workflows/TagsAndWorkflowsPage.tsx
@@ -1,4 +1,4 @@
-import { useMemo, useRef, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
import {
Check,
FileJson,
@@ -56,6 +56,12 @@ export function TagsAndWorkflowsPage() {
fetchModels,
} = useModels()
+// Populate installed ComfyUI models when this page is opened instead of
+// relying on the separate Models page to perform the first refresh.
+useEffect(() => {
+ fetchModels().catch(() => {})
+}, [fetchModels])
+
const [importName, setImportName] = useState('')
const [importJson, setImportJson] = useState('')
const [importError, setImportError] = useState<string | null>(null)
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index b4c877f3..657ccc35 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -814,7 +814,7 @@ export function useCreate() {
found = true
addToGallery({
id: uuid(), type: galleryTypeForFile(file.filename, mode),
- filename: file.filename, subfolder: file.subfolder ?? '',
+ filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',
prompt, negativePrompt, model: activeModel,
modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),
seed: seed === -1 ? 0 : seed,
@@ -912,7 +912,7 @@ export function useCreate() {
found = true
addToGallery({
id: uuid(), type: galleryTypeForFile(file.filename, mode),
- filename: file.filename, subfolder: file.subfolder ?? '',
+ filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',
prompt, negativePrompt, model: activeModel,
modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),
seed: seed === -1 ? 0 : seed,
@@ -1017,7 +1017,7 @@ export function useCreate() {
found = true
addToGallery({
id: uuid(), type: galleryTypeForFile(file.filename, mode),
- filename: file.filename, subfolder: file.subfolder ?? '',
+ filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',
prompt, negativePrompt, model: activeModel,
modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),
seed: seed === -1 ? 0 : seed,
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index 571501d7..69eb8d9a 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -127,6 +127,7 @@ export interface GalleryItem {
id: string
type: 'image' | 'video' | 'audio'
filename: string
+ comfyType?: string
subfolder: string
prompt: string
negativePrompt: string
diff --git a/src/types/workflows.ts b/src/types/workflows.ts
index cfdc9499..497609f3 100644
--- a/src/types/workflows.ts
+++ b/src/types/workflows.ts
@@ -29,6 +29,10 @@ export interface ParameterMap {
batchSize?: ParameterMapping
sampler?: ParameterMapping
scheduler?: ParameterMapping
+
+ // I2I / I2V source image
+ inputImage?: ParameterMapping
+
// Video-specific
frames?: ParameterMapping
fps?: ParameterMapping