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.

v1.0.1: Fix image/video model detection and FLUX workflow

PurpleDoubleD89ddffc0284c
diff --git a/src/api/comfyui.ts b/src/api/comfyui.ts
index fa18ea62..2d918ca5 100644
--- a/src/api/comfyui.ts
+++ b/src/api/comfyui.ts
@@ -1,7 +1,4 @@
-export interface ComfyUIModel {
- name: string
- type: 'checkpoint' | 'lora' | 'vae'
-}
+// ─── Types ───
export interface GenerateParams {
prompt: string
@@ -27,8 +24,35 @@ export interface ComfyUIOutput {
type: string
}
+export type ModelType = 'flux' | 'sdxl' | 'sd15' | 'wan' | 'hunyuan' | 'unknown'
export type VideoBackend = 'wan' | 'animatediff' | 'none'
+export interface ClassifiedModel {
+ name: string
+ type: ModelType
+ source: 'checkpoint' | 'diffusion_model'
+}
+
+// ─── Model Classification ───
+
+function classifyModel(name: string): ModelType {
+ const lower = name.toLowerCase()
+ if (lower.includes('flux')) return 'flux'
+ if (lower.includes('wan')) return 'wan'
+ if (lower.includes('hunyuan')) return 'hunyuan'
+ if (lower.includes('sdxl') || lower.includes('xl')) return 'sdxl'
+ if (lower.includes('sd15') || lower.includes('sd_1') || lower.includes('v1-5')) return 'sd15'
+ return 'unknown'
+}
+
+function isImageModel(type: ModelType): boolean {
+ return type === 'flux' || type === 'sdxl' || type === 'sd15' || type === 'unknown'
+}
+
+function isVideoModel(type: ModelType): boolean {
+ return type === 'wan' || type === 'hunyuan'
+}
+
// ─── Connection & Info ───
export async function checkComfyConnection(): Promise<boolean> {
@@ -80,6 +104,17 @@ export async function getCLIPModels(): Promise<string[]> {
}
}
+export async function getTextEncoders(): Promise<string[]> {
+ try {
+ // DualCLIPLoader is used by FLUX for text encoders
+ const res = await fetch('/comfyui/object_info/DualCLIPLoader')
+ const data = await res.json()
+ return data?.DualCLIPLoader?.input?.required?.clip_name1?.[0] || []
+ } catch {
+ return []
+ }
+}
+
export async function getSamplers(): Promise<string[]> {
try {
const res = await fetch('/comfyui/object_info/KSampler')
@@ -100,24 +135,91 @@ export async function getSchedulers(): Promise<string[]> {
}
}
-// ─── Detect available video backend ───
+// ─── Classified Model Lists ───
-export async function detectVideoBackend(): Promise<VideoBackend> {
- try {
- const res = await fetch('/comfyui/object_info')
- const data = await res.json()
- // Check for Wan nodes (built-in, preferred)
- if (data['EmptyHunyuanLatentVideo'] && data['UNETLoader'] && data['CLIPLoader'] && data['VAELoader']) {
- return 'wan'
+export async function getImageModels(): Promise<ClassifiedModel[]> {
+ const [checkpoints, diffModels] = await Promise.all([getCheckpoints(), getDiffusionModels()])
+
+ const result: ClassifiedModel[] = []
+
+ // All checkpoints are image models (SDXL, SD1.5, etc.)
+ for (const name of checkpoints) {
+ const type = classifyModel(name)
+ result.push({ name, type: type === 'unknown' ? 'sdxl' : type, source: 'checkpoint' })
+ }
+
+ // Only FLUX/SD diffusion_models are image models (NOT wan/hunyuan)
+ for (const name of diffModels) {
+ const type = classifyModel(name)
+ if (isImageModel(type)) {
+ result.push({ name, type: type === 'unknown' ? 'flux' : type, source: 'diffusion_model' })
}
- // Check for AnimateDiff nodes (custom, fallback)
- if (data['ADE_LoadAnimateDiffModel'] && data['ADE_UseEvolvedSampling']) {
- return 'animatediff'
+ }
+
+ return result
+}
+
+export async function getVideoModels(): Promise<ClassifiedModel[]> {
+ const diffModels = await getDiffusionModels()
+
+ const result: ClassifiedModel[] = []
+
+ // Only wan/hunyuan diffusion_models are video models
+ for (const name of diffModels) {
+ const type = classifyModel(name)
+ if (isVideoModel(type)) {
+ result.push({ name, type, source: 'diffusion_model' })
}
+ }
+
+ return result
+}
+
+// ─── Detect Video Backend (checks BOTH nodes AND models) ───
+
+export async function detectVideoBackend(): Promise<VideoBackend> {
+ try {
+ const [nodeRes, videoModels] = await Promise.all([
+ fetch('/comfyui/object_info').then(r => r.json()),
+ getVideoModels(),
+ ])
+
+ // Wan: need BOTH the nodes AND actual wan/hunyuan models
+ const hasWanNodes = !!(nodeRes['EmptyHunyuanLatentVideo'] && nodeRes['UNETLoader'] && nodeRes['CLIPLoader'] && nodeRes['VAELoader'])
+ const hasWanModels = videoModels.length > 0
+
+ if (hasWanNodes && hasWanModels) return 'wan'
+
+ // AnimateDiff: need custom nodes
+ if (nodeRes['ADE_LoadAnimateDiffModel'] && nodeRes['ADE_UseEvolvedSampling']) return 'animatediff'
} catch { /* ignore */ }
return 'none'
}
+// ─── Auto-find matching VAE/CLIP for a model ───
+
+async function findMatchingVAE(modelType: ModelType): Promise<string | null> {
+ const vaes = await getVAEModels()
+ const lower = (s: string) => s.toLowerCase()
+
+ if (modelType === 'flux') {
+ return vaes.find(v => lower(v).includes('flux')) || vaes[0] || null
+ }
+ if (modelType === 'wan' || modelType === 'hunyuan') {
+ return vaes.find(v => lower(v).includes('wan') || lower(v).includes('hunyuan')) || vaes[0] || null
+ }
+ return vaes[0] || null
+}
+
+async function findMatchingCLIP(modelType: ModelType): Promise<string | null> {
+ const clips = await getCLIPModels()
+ const textEncoders = await getTextEncoders()
+ const all = [...clips, ...textEncoders]
+
+ if (all.length === 0) return null
+ return all[0]
+}
+
// ─── Workflow Submission ───
export async function submitWorkflow(workflow: Record<string, any>): Promise<string> {
@@ -128,7 +230,7 @@ export async function submitWorkflow(workflow: Record<string, any>): Promise<str
})
if (!res.ok) {
const err = await res.text()
- throw new Error(`Failed to submit workflow: ${err}`)
+ throw new Error(`ComfyUI error: ${err}`)
}
const data = await res.json()
return data.prompt_id
@@ -145,213 +247,140 @@ export function getImageUrl(filename: string, subfolder: string = '', type: stri
return `/comfyui/view?filename=${encodeURIComponent(filename)}&subfolder=${encodeURIComponent(subfolder)}&type=${type}`
}
-// ─── Image Workflow (Standard SDXL/SD) ───
+// ─── Image Workflow: SDXL/SD (CheckpointLoaderSimple) ───
-export function buildTxt2ImgWorkflow(params: GenerateParams): Record<string, any> {
+export function buildSDXLImgWorkflow(params: GenerateParams): Record<string, any> {
const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed
return {
- '1': {
- class_type: 'CheckpointLoaderSimple',
- inputs: { ckpt_name: params.model },
- },
- '2': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.prompt, clip: ['1', 1] },
- },
- '3': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.negativePrompt || '', clip: ['1', 1] },
- },
- '4': {
- class_type: 'EmptyLatentImage',
- inputs: { width: params.width, height: params.height, batch_size: params.batchSize || 1 },
- },
+ '1': { class_type: 'CheckpointLoaderSimple', inputs: { ckpt_name: params.model } },
+ '2': { class_type: 'CLIPTextEncode', inputs: { text: params.prompt, clip: ['1', 1] } },
+ '3': { class_type: 'CLIPTextEncode', inputs: { text: params.negativePrompt || '', clip: ['1', 1] } },
+ '4': { class_type: 'EmptyLatentImage', inputs: { width: params.width, height: params.height, batch_size: params.batchSize || 1 } },
'5': {
class_type: 'KSampler',
inputs: {
- model: ['1', 0],
- positive: ['2', 0],
- negative: ['3', 0],
- latent_image: ['4', 0],
- seed,
- steps: params.steps,
- cfg: params.cfgScale,
- sampler_name: params.sampler,
- scheduler: 'normal',
- denoise: 1.0,
+ model: ['1', 0], positive: ['2', 0], negative: ['3', 0], latent_image: ['4', 0],
+ seed, steps: params.steps, cfg: params.cfgScale,
+ sampler_name: params.sampler, scheduler: 'normal', denoise: 1.0,
},
},
- '6': {
- class_type: 'VAEDecode',
- inputs: { samples: ['5', 0], vae: ['1', 2] },
- },
- '7': {
- class_type: 'SaveImage',
- inputs: { images: ['6', 0], filename_prefix: 'locally_uncensored' },
- },
+ '6': { class_type: 'VAEDecode', inputs: { samples: ['5', 0], vae: ['1', 2] } },
+ '7': { class_type: 'SaveImage', inputs: { images: ['6', 0], filename_prefix: 'locally_uncensored' } },
}
}
-// ─── Video Workflow: Wan 2.1/2.2 (built-in nodes) ───
+// ─── Image Workflow: FLUX (UNETLoader + CLIPLoader + VAELoader) ───
-export function buildWanVideoWorkflow(params: VideoParams): Record<string, any> {
+export async function buildFluxImgWorkflow(params: GenerateParams): Promise<Record<string, any>> {
const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed
- // Auto-detect model files from the selected model name
- // Users select a diffusion model; we try to find matching CLIP and VAE
+ // Find matching VAE and CLIP
+ const vae = await findMatchingVAE('flux')
+ const clip = await findMatchingCLIP('flux')
+
+ if (!vae) throw new Error('No VAE found for FLUX. Add a flux VAE to ComfyUI models/vae/')
+ if (!clip) throw new Error('No text encoder found for FLUX. Add a CLIP/text encoder to ComfyUI models/clip/ or models/text_encoders/')
+
return {
- '1': {
- class_type: 'CLIPLoader',
- inputs: {
- clip_name: params.model.includes('clip') ? params.model : 'umt5_xxl_fp8_e4m3fn_scaled.safetensors',
- type: 'wan',
- device: 'default',
- },
- },
- '2': {
- class_type: 'UNETLoader',
- inputs: {
- unet_name: params.model,
- weight_dtype: 'default',
- },
- },
- '3': {
- class_type: 'VAELoader',
- inputs: {
- vae_name: 'wan_2.1_vae.safetensors',
- },
- },
- '4': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.prompt, clip: ['1', 0] },
- },
- '5': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.negativePrompt || 'static, blurred, low quality, worst quality, deformed', clip: ['1', 0] },
- },
+ '1': { class_type: 'UNETLoader', inputs: { unet_name: params.model, weight_dtype: 'default' } },
+ '2': { class_type: 'CLIPLoader', inputs: { clip_name: clip, type: 'flux', device: 'default' } },
+ '3': { class_type: 'VAELoader', inputs: { vae_name: vae } },
+ '4': { class_type: 'CLIPTextEncode', inputs: { text: params.prompt, clip: ['2', 0] } },
+ '5': { class_type: 'EmptySD3LatentImage', inputs: { width: params.width, height: params.height, batch_size: params.batchSize || 1 } },
'6': {
- class_type: 'EmptyHunyuanLatentVideo',
+ class_type: 'KSampler',
inputs: {
- width: params.width,
- height: params.height,
- length: params.frames,
- batch_size: 1,
+ model: ['1', 0], positive: ['4', 0], negative: ['4', 0], latent_image: ['5', 0],
+ seed, steps: params.steps, cfg: 1.0, // FLUX uses CFG 1.0
+ sampler_name: params.sampler || 'euler', scheduler: 'simple', denoise: 1.0,
},
},
+ '7': { class_type: 'VAEDecode', inputs: { samples: ['6', 0], vae: ['3', 0] } },
+ '8': { class_type: 'SaveImage', inputs: { images: ['7', 0], filename_prefix: 'locally_uncensored' } },
+ }
+}
+
+// ─── Auto-select Image Workflow ───
+
+export async function buildTxt2ImgWorkflow(params: GenerateParams, modelType: ModelType): Promise<Record<string, any>> {
+ if (modelType === 'flux') {
+ return buildFluxImgWorkflow(params)
+ }
+ return buildSDXLImgWorkflow(params)
+}
+
+// ─── Video Workflow: Wan 2.1/2.2 ───
+
+export async function buildWanVideoWorkflow(params: VideoParams): Promise<Record<string, any>> {
+ const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed
+
+ // Dynamically find matching VAE and CLIP
+ const vae = await findMatchingVAE('wan')
+ const clip = await findMatchingCLIP('wan')
+
+ if (!vae) throw new Error('No VAE found for Wan. Add a Wan VAE to ComfyUI models/vae/')
+ if (!clip) throw new Error('No text encoder found for Wan. Add a CLIP model to ComfyUI models/clip/ or models/text_encoders/')
+
+ return {
+ '1': { class_type: 'CLIPLoader', inputs: { clip_name: clip, type: 'wan', device: 'default' } },
+ '2': { class_type: 'UNETLoader', inputs: { unet_name: params.model, weight_dtype: 'default' } },
+ '3': { class_type: 'VAELoader', inputs: { vae_name: vae } },
+ '4': { class_type: 'CLIPTextEncode', inputs: { text: params.prompt, clip: ['1', 0] } },
+ '5': { class_type: 'CLIPTextEncode', inputs: { text: params.negativePrompt || 'static, blurred, low quality, worst quality, deformed', clip: ['1', 0] } },
+ '6': { class_type: 'EmptyHunyuanLatentVideo', inputs: { width: params.width, height: params.height, length: params.frames, batch_size: 1 } },
'7': {
class_type: 'KSampler',
inputs: {
- model: ['2', 0],
- positive: ['4', 0],
- negative: ['5', 0],
- latent_image: ['6', 0],
- seed,
- steps: params.steps,
- cfg: params.cfgScale,
- sampler_name: params.sampler || 'uni_pc',
- scheduler: 'simple',
- denoise: 1.0,
+ model: ['2', 0], positive: ['4', 0], negative: ['5', 0], latent_image: ['6', 0],
+ seed, steps: params.steps, cfg: params.cfgScale,
+ sampler_name: params.sampler || 'uni_pc', scheduler: 'simple', denoise: 1.0,
},
},
- '8': {
- class_type: 'VAEDecode',
- inputs: { samples: ['7', 0], vae: ['3', 0] },
- },
+ '8': { class_type: 'VAEDecode', inputs: { samples: ['7', 0], vae: ['3', 0] } },
'9': {
class_type: 'SaveAnimatedWEBP',
- inputs: {
- images: ['8', 0],
- filename_prefix: 'locally_uncensored_vid',
- fps: params.fps,
- lossless: false,
- quality: 90,
- method: 'default',
- },
+ inputs: { images: ['8', 0], filename_prefix: 'locally_uncensored_vid', fps: params.fps, lossless: false, quality: 90, method: 'default' },
},
}
}
-// ─── Video Workflow: AnimateDiff (requires custom nodes) ───
+// ─── Video Workflow: AnimateDiff ───
export function buildAnimateDiffWorkflow(params: VideoParams): Record<string, any> {
const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed
-
return {
- '1': {
- class_type: 'CheckpointLoaderSimple',
- inputs: { ckpt_name: params.model },
- },
- '2': {
- class_type: 'ADE_LoadAnimateDiffModel',
- inputs: { model_name: 'mm_sd15_v3.safetensors' },
- },
- '3': {
- class_type: 'ADE_ApplyAnimateDiffModelSimple',
- inputs: { motion_model: ['2', 0] },
- },
- '4': {
- class_type: 'ADE_UseEvolvedSampling',
- inputs: {
- model: ['1', 0],
- m_models: ['3', 0],
- beta_schedule: 'autoselect',
- },
- },
- '5': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.prompt, clip: ['1', 1] },
- },
- '6': {
- class_type: 'CLIPTextEncode',
- inputs: { text: params.negativePrompt || 'low quality, blurry, static', clip: ['1', 1] },
- },
- '7': {
- class_type: 'EmptyLatentImage',
- inputs: { width: params.width, height: params.height, batch_size: params.frames },
- },
+ '1': { class_type: 'CheckpointLoaderSimple', inputs: { ckpt_name: params.model } },
+ '2': { class_type: 'ADE_LoadAnimateDiffModel', inputs: { model_name: 'mm_sd15_v3.safetensors' } },
+ '3': { class_type: 'ADE_ApplyAnimateDiffModelSimple', inputs: { motion_model: ['2', 0] } },
+ '4': { class_type: 'ADE_UseEvolvedSampling', inputs: { model: ['1', 0], m_models: ['3', 0], beta_schedule: 'autoselect' } },
+ '5': { class_type: 'CLIPTextEncode', inputs: { text: params.prompt, clip: ['1', 1] } },
+ '6': { class_type: 'CLIPTextEncode', inputs: { text: params.negativePrompt || 'low quality, blurry, static', clip: ['1', 1] } },
+ '7': { class_type: 'EmptyLatentImage', inputs: { width: params.width, height: params.height, batch_size: params.frames } },
'8': {
class_type: 'KSampler',
inputs: {
- model: ['4', 0],
- positive: ['5', 0],
- negative: ['6', 0],
- latent_image: ['7', 0],
- seed,
- steps: params.steps,
- cfg: params.cfgScale,
- sampler_name: params.sampler,
- scheduler: 'normal',
- denoise: 1.0,
+ model: ['4', 0], positive: ['5', 0], negative: ['6', 0], latent_image: ['7', 0],
+ seed, steps: params.steps, cfg: params.cfgScale,
+ sampler_name: params.sampler, scheduler: 'normal', denoise: 1.0,
},
},
- '9': {
- class_type: 'VAEDecode',
- inputs: { samples: ['8', 0], vae: ['1', 2] },
- },
+ '9': { class_type: 'VAEDecode', inputs: { samples: ['8', 0], vae: ['1', 2] } },
'10': {
class_type: 'VHS_VideoCombine',
- inputs: {
- images: ['9', 0],
- frame_rate: params.fps,
- loop_count: 0,
- filename_prefix: 'locally_uncensored_vid',
- format: 'video/h264-mp4',
- pingpong: false,
- save_output: true,
- },
+ inputs: { images: ['9', 0], frame_rate: params.fps, loop_count: 0, filename_prefix: 'locally_uncensored_vid', format: 'video/h264-mp4', pingpong: false, save_output: true },
},
}
}
-// ─── Auto-select the right video workflow ───
+// ─── Auto-select Video Workflow ───
-export function buildTxt2VidWorkflow(params: VideoParams, backend: VideoBackend): Record<string, any> {
+export async function buildTxt2VidWorkflow(params: VideoParams, backend: VideoBackend): Promise<Record<string, any>> {
switch (backend) {
case 'wan':
return buildWanVideoWorkflow(params)
case 'animatediff':
return buildAnimateDiffWorkflow(params)
default:
- throw new Error('No video generation backend available. Install Wan 2.1 models or AnimateDiff nodes in ComfyUI.')
+ throw new Error('No video backend available. Install Wan 2.1 models or AnimateDiff nodes in ComfyUI.')
}
}
diff --git a/src/components/create/CreateView.tsx b/src/components/create/CreateView.tsx
index cba2e1ec..22a39f9e 100644
--- a/src/components/create/CreateView.tsx
+++ b/src/components/create/CreateView.tsx
@@ -16,7 +16,7 @@ interface ComfyStatus {
}
export function CreateView() {
- const { connected, checkpoints, videoModels, samplerList, videoBackend, error, checkConnection, fetchModels, generate, cancel } = useCreate()
+ const { connected, imageModels, videoModels, samplerList, videoBackend, error, checkConnection, fetchModels, generate, cancel } = useCreate()
const { mode, setMode } = useCreateStore()
const [status, setStatus] = useState<ComfyStatus | null>(null)
@@ -132,7 +132,7 @@ export function CreateView() {
{connected === true && (
<div className="flex items-center gap-2 px-4 py-2 bg-green-50 dark:bg-green-500/10 border-b border-green-200 dark:border-green-500/20 text-green-600 dark:text-green-400 text-sm">
<CheckCircle size={16} />
- <span>ComfyUI connected — {checkpoints.length} image model{checkpoints.length !== 1 ? 's' : ''}, {videoModels.length} video model{videoModels.length !== 1 ? 's' : ''}</span>
+ <span>ComfyUI connected — {imageModels.length} image model{imageModels.length !== 1 ? 's' : ''}, {videoModels.length} video model{videoModels.length !== 1 ? 's' : ''}</span>
</div>
)}
@@ -193,7 +193,7 @@ export function CreateView() {
{/* Parameter sidebar */}
<div className="w-64 border-l border-gray-200 dark:border-white/5 bg-gray-50 dark:bg-[#1a1a1a] p-4 overflow-y-auto scrollbar-thin hidden lg:block">
<h3 className="text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-4">Parameters</h3>
- <ParamPanel checkpoints={checkpoints} videoModels={videoModels} samplerList={samplerList} />
+ <ParamPanel imageModels={imageModels} videoModels={videoModels} samplerList={samplerList} />
</div>
</div>
</div>
diff --git a/src/components/create/ParamPanel.tsx b/src/components/create/ParamPanel.tsx
index 1d899013..b12a1cfc 100644
--- a/src/components/create/ParamPanel.tsx
+++ b/src/components/create/ParamPanel.tsx
@@ -1,10 +1,11 @@
import { useCreateStore } from '../../stores/createStore'
import { SliderControl } from '../settings/SliderControl'
import { Dice5 } from 'lucide-react'
+import type { ClassifiedModel, ModelType } from '../../api/comfyui'
interface Props {
- checkpoints: string[]
- videoModels: string[]
+ imageModels: ClassifiedModel[]
+ videoModels: ClassifiedModel[]
samplerList: string[]
}
@@ -23,14 +24,34 @@ const VID_SIZE_PRESETS = [
{ label: '480x768', w: 480, h: 768 },
]
-export function ParamPanel({ checkpoints, videoModels, samplerList }: Props) {
+const TYPE_BADGE: Record<ModelType, { label: string; color: string }> = {
+ flux: { label: 'FLUX', color: 'bg-purple-500/20 text-purple-300' },
+ sdxl: { label: 'SDXL', color: 'bg-blue-500/20 text-blue-300' },
+ sd15: { label: 'SD 1.5', color: 'bg-green-500/20 text-green-300' },
+ wan: { label: 'Wan', color: 'bg-orange-500/20 text-orange-300' },
+ hunyuan: { label: 'Hunyuan', color: 'bg-red-500/20 text-red-300' },
+ unknown: { label: 'Model', color: 'bg-gray-500/20 text-gray-300' },
+}
+
+export function ParamPanel({ imageModels, videoModels, samplerList }: Props) {
const store = useCreateStore()
const isVideo = store.mode === 'video'
const sizePresets = isVideo ? VID_SIZE_PRESETS : IMG_SIZE_PRESETS
- const modelList = isVideo ? videoModels : checkpoints
+ const models = isVideo ? videoModels : imageModels
const selectClass = 'w-full px-3 py-2 rounded-lg bg-gray-100 dark:bg-white/5 border border-gray-300 dark:border-white/10 text-gray-900 dark:text-white text-sm focus:outline-none focus:border-gray-400 dark:focus:border-white/20 appearance-none cursor-pointer'
+ const handleModelChange = (name: string) => {
+ if (isVideo) {
+ store.setVideoModel(name)
+ } else {
+ const model = imageModels.find(m => m.name === name)
+ store.setImageModel(name, model?.type || 'unknown')
+ }
+ }
+
+ const activeModel = isVideo ? store.videoModel : store.imageModel
+
return (
<div className="space-y-4">
{/* Model */}
@@ -38,12 +59,40 @@ export function ParamPanel({ checkpoints, videoModels, samplerList }: Props) {
<label className="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-1.5 block">
{isVideo ? 'Video Model' : 'Image Model'}
</label>
- <select value={store.model} onChange={(e) => store.setModel(e.target.value)} className={selectClass}>
- {modelList.length === 0 && <option value="">No models found</option>}
- {modelList.map((c) => (
- <option key={c} value={c}>{c.replace(/\.[^.]+$/, '')}</option>
- ))}
- </select>
+ {models.length === 0 ? (
+ <div className="px-3 py-2 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-200 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs">
+ {isVideo
+ ? 'No video models found. Add Wan or Hunyuan models to ComfyUI.'
+ : 'No image models found. Add checkpoints or FLUX models to ComfyUI.'}
+ </div>
+ ) : (
+ <select value={activeModel} onChange={(e) => handleModelChange(e.target.value)} className={selectClass}>
+ {models.map((m) => {
+ const badge = TYPE_BADGE[m.type]
+ const shortName = m.name.replace(/\.[^.]+$/, '')
+ return (
+ <option key={m.name} value={m.name}>
+ {shortName} ({badge.label})
+ </option>
+ )
+ })}
+ </select>
+ )}
+ {/* Type badge below dropdown */}
+ {activeModel && models.length > 0 && (
+ <div className="mt-1 flex items-center gap-1">
+ {(() => {
+ const model = models.find(m => m.name === activeModel)
+ if (!model) return null
+ const badge = TYPE_BADGE[model.type]
+ return (
+ <span className={`px-1.5 py-0.5 rounded text-[10px] font-medium ${badge.color}`}>
+ {badge.label}
+ </span>
+ )
+ })()}
+ </div>
+ )}
</div>
{/* Sampler */}
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index a5ffc733..8e4a74e3 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -2,14 +2,15 @@ import { useState, useCallback, useRef } from 'react'
import { v4 as uuid } from 'uuid'
import {
checkComfyConnection,
- getCheckpoints,
- getDiffusionModels,
+ getImageModels,
+ getVideoModels,
getSamplers,
detectVideoBackend,
submitWorkflow,
getHistory,
buildTxt2ImgWorkflow,
buildTxt2VidWorkflow,
+ type ClassifiedModel,
type ComfyUIOutput,
type VideoBackend,
} from '../api/comfyui'
@@ -18,8 +19,8 @@ import { useCreateStore, type GalleryItem } from '../stores/createStore'
export function useCreate() {
const store = useCreateStore()
const [connected, setConnected] = useState<boolean | null>(null)
- const [checkpoints, setCheckpoints] = useState<string[]>([])
- const [videoModels, setVideoModels] = useState<string[]>([])
+ const [imageModels, setImageModels] = useState<ClassifiedModel[]>([])
+ const [videoModelsList, setVideoModelsList] = useState<ClassifiedModel[]>([])
const [samplerList, setSamplerList] = useState<string[]>([])
const [videoBackend, setVideoBackend] = useState<VideoBackend>('none')
const [error, setError] = useState<string | null>(null)
@@ -32,41 +33,50 @@ export function useCreate() {
}, [])
const fetchModels = useCallback(async () => {
- const [ckpts, diffModels, samplers, vBackend] = await Promise.all([
- getCheckpoints(),
- getDiffusionModels(),
+ const [imgModels, vidModels, samplers, vBackend] = await Promise.all([
+ getImageModels(),
+ getVideoModels(),
getSamplers(),
detectVideoBackend(),
])
- setCheckpoints(ckpts)
- setVideoModels(diffModels)
+ setImageModels(imgModels)
+ setVideoModelsList(vidModels)
setSamplerList(samplers)
setVideoBackend(vBackend)
- if (ckpts.length > 0 && !store.model) {
- store.setModel(ckpts[0])
+ // Auto-select first image model if none set
+ if (imgModels.length > 0 && !store.imageModel) {
+ store.setImageModel(imgModels[0].name, imgModels[0].type)
+ }
+ // Auto-select first video model if none set
+ if (vidModels.length > 0 && !store.videoModel) {
+ store.setVideoModel(vidModels[0].name)
}
}, [store])
const generate = useCallback(async () => {
+ const state = useCreateStore.getState()
const {
- mode, prompt, negativePrompt, model, sampler, steps, cfgScale,
- width, height, seed, frames, fps,
+ mode, prompt, negativePrompt, imageModel, imageModelType, videoModel,
+ sampler, steps, cfgScale, width, height, seed, frames, fps,
setIsGenerating, setProgress, setCurrentPromptId, addToGallery,
- } = useCreateStore.getState()
+ } = state
setError(null)
+ const activeModel = mode === 'image' ? imageModel : videoModel
+
if (!prompt.trim()) {
setError('Please enter a prompt.')
return
}
- if (!model) {
- setError('No model selected. Make sure ComfyUI has models installed.')
+ if (!activeModel) {
+ setError(mode === 'image'
+ ? 'No image model selected. Add checkpoints or FLUX models to ComfyUI.'
+ : 'No video model selected. Install Wan 2.1 or AnimateDiff models in ComfyUI.')
return
}
- // Check ComfyUI is actually running
const isRunning = await checkComfyConnection()
if (!isRunning) {
setError('ComfyUI is not running. Wait for it to start or check the connection.')
@@ -77,15 +87,25 @@ export function useCreate() {
setProgress(0)
try {
- const workflow = mode === 'video'
- ? buildTxt2VidWorkflow({ prompt, negativePrompt, model, sampler, steps, cfgScale, width, height, seed, frames, fps }, videoBackend)
- : buildTxt2ImgWorkflow({ prompt, negativePrompt, model, sampler, steps, cfgScale, width, height, seed })
+ let workflow: Record<string, any>
+
+ if (mode === 'video') {
+ workflow = await buildTxt2VidWorkflow(
+ { prompt, negativePrompt, model: activeModel, sampler, steps, cfgScale, width, height, seed, frames, fps },
+ videoBackend
+ )
+ } else {
+ workflow = await buildTxt2ImgWorkflow(
+ { prompt, negativePrompt, model: activeModel, sampler, steps, cfgScale, width, height, seed },
+ imageModelType
+ )
+ }
let promptId: string
try {
promptId = await submitWorkflow(workflow)
} catch (err) {
- setError(`Failed to submit to ComfyUI: ${err instanceof Error ? err.message : String(err)}`)
+ setError(`Failed to submit: ${err instanceof Error ? err.message : String(err)}`)
setIsGenerating(false)
return
}
@@ -133,12 +153,10 @@ export function useCreate() {
subfolder: file.subfolder || '',
prompt,
negativePrompt,
- model,
+ model: activeModel,
+ modelType: mode === 'image' ? imageModelType : 'wan',
seed: seed === -1 ? 0 : seed,
- steps,
- cfgScale,
- width,
- height,
+ steps, cfgScale, width, height,
createdAt: Date.now(),
}
addToGallery(galleryItem)
@@ -150,7 +168,7 @@ export function useCreate() {
resolve()
} else if (history.status?.status_str === 'error') {
clearInterval(pollRef.current!)
- const errMsg = history.status?.messages?.[0]?.[1]?.message || 'Unknown error in ComfyUI'
+ const errMsg = history.status?.messages?.[0]?.[1]?.message || 'Unknown ComfyUI error'
reject(new Error(errMsg))
}
} catch {
@@ -171,9 +189,7 @@ export function useCreate() {
}, [videoBackend])
const cancel = useCallback(() => {
- if (pollRef.current) {
- clearInterval(pollRef.current)
- }
+ if (pollRef.current) clearInterval(pollRef.current)
store.setIsGenerating(false)
store.setProgress(0)
store.setCurrentPromptId(null)
@@ -182,8 +198,8 @@ export function useCreate() {
return {
connected,
- checkpoints,
- videoModels,
+ imageModels,
+ videoModels: videoModelsList,
samplerList,
videoBackend,
error,
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index dacaaaaf..65394238 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -1,5 +1,6 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
+import type { ModelType } from '../api/comfyui'
export interface GalleryItem {
id: string
@@ -9,6 +10,7 @@ export interface GalleryItem {
prompt: string
negativePrompt: string
model: string
+ modelType: ModelType
seed: number
steps: number
cfgScale: number
@@ -21,7 +23,9 @@ interface CreateState {
mode: 'image' | 'video'
prompt: string
negativePrompt: string
- model: string
+ imageModel: string
+ imageModelType: ModelType
+ videoModel: string
sampler: string
steps: number
cfgScale: number
@@ -38,7 +42,8 @@ interface CreateState {
setMode: (mode: 'image' | 'video') => void
setPrompt: (prompt: string) => void
setNegativePrompt: (negativePrompt: string) => void
- setModel: (model: string) => void
+ setImageModel: (model: string, type: ModelType) => void
+ setVideoModel: (model: string) => void
setSampler: (sampler: string) => void
setSteps: (steps: number) => void
setCfgScale: (cfgScale: number) => void
@@ -61,7 +66,9 @@ export const useCreateStore = create<CreateState>()(
mode: 'image',
prompt: '',
negativePrompt: '',
- model: '',
+ imageModel: '',
+ imageModelType: 'unknown' as ModelType,
+ videoModel: '',
sampler: 'euler',
steps: 20,
cfgScale: 7,
@@ -78,7 +85,8 @@ export const useCreateStore = create<CreateState>()(
setMode: (mode) => set({ mode }),
setPrompt: (prompt) => set({ prompt }),
setNegativePrompt: (negativePrompt) => set({ negativePrompt }),
- setModel: (model) => set({ model }),
+ setImageModel: (model, type) => set({ imageModel: model, imageModelType: type }),
+ setVideoModel: (model) => set({ videoModel: model }),
setSampler: (sampler) => set({ sampler }),
setSteps: (steps) => set({ steps }),
setCfgScale: (cfgScale) => set({ cfgScale }),
@@ -98,7 +106,9 @@ export const useCreateStore = create<CreateState>()(
name: 'create-store',
partialize: (state) => ({
mode: state.mode,
- model: state.model,
+ imageModel: state.imageModel,
+ imageModelType: state.imageModelType,
+ videoModel: state.videoModel,
sampler: state.sampler,
steps: state.steps,
cfgScale: state.cfgScale,
diff --git a/vite.config.ts b/vite.config.ts
index 8437dddb..d616f34c 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -5,14 +5,22 @@ import { spawn, execSync, type ChildProcess } from 'child_process'
import { existsSync, readdirSync } from 'fs'
import { resolve, join } from 'path'
import { config } from 'dotenv'
+import { fileURLToPath } from 'url'
+import { dirname } from 'path'
-// Load .env file
-config()
+// Load .env file from project root
+const __dirname = dirname(fileURLToPath(import.meta.url))
+config({ path: resolve(__dirname, '.env') })
function findComfyUI(): string | null {
// 1. Check .env / environment variable
- if (process.env.COMFYUI_PATH && existsSync(resolve(process.env.COMFYUI_PATH, 'main.py'))) {
- return process.env.COMFYUI_PATH
+ const envPath = process.env.COMFYUI_PATH
+ console.log(`[ComfyUI] COMFYUI_PATH env: ${envPath || '(not set)'}`)
+ if (envPath) {
+ // Try the path directly (handles spaces in paths)
+ const mainPy = join(envPath, 'main.py')
+ console.log(`[ComfyUI] Checking: ${mainPy} -> ${existsSync(mainPy)}`)
+ if (existsSync(mainPy)) return envPath
}
const home = process.env.USERPROFILE || process.env.HOME || ''
// 2. Check common locations
@@ -59,9 +67,11 @@ function comfyLauncher(): Plugin {
}
comfyLogs = []
+ console.log(`[ComfyUI] Spawning python in: ${comfyPath}`)
comfyProcess = spawn('python', ['main.py', '--listen', '127.0.0.1', '--port', '8188'], {
cwd: comfyPath,
stdio: ['ignore', 'pipe', 'pipe'],
+ shell: true,
})
comfyProcess.stdout?.on('data', (d) => {
@@ -99,19 +109,25 @@ function comfyLauncher(): Plugin {
name: 'comfy-launcher',
configureServer(server) {
// Auto-start ComfyUI when dev server starts
- isComfyRunning().then(running => {
- if (!running) {
- const comfyPath = findComfyUI()
- if (comfyPath) {
- console.log(`[ComfyUI] Auto-starting from: ${comfyPath}`)
- startComfy(comfyPath)
+ setTimeout(async () => {
+ try {
+ const running = await isComfyRunning()
+ if (!running) {
+ const comfyPath = findComfyUI()
+ if (comfyPath) {
+ console.log(`[ComfyUI] Auto-starting from: ${comfyPath}`)
+ const result = startComfy(comfyPath)
+ console.log(`[ComfyUI] Start result: ${result.status}`)
+ } else {
+ console.log('[ComfyUI] Not found. Set COMFYUI_PATH in .env or install ComfyUI.')
+ }
} else {
- console.log('[ComfyUI] Not found. Set COMFYUI_PATH in .env or install ComfyUI.')
+ console.log('[ComfyUI] Already running on port 8188')
}
- } else {
- console.log('[ComfyUI] Already running on port 8188')
+ } catch (err) {
+ console.error('[ComfyUI] Auto-start error:', err)
}
- })
+ }, 1000)
// Auto-stop ComfyUI when dev server closes
server.httpServer?.on('close', stopComfy)
@@ -154,15 +170,18 @@ function comfyLauncher(): Plugin {
// API: Status + logs
server.middlewares.use('/local-api/comfyui-status', async (_req, res) => {
- const running = await isComfyRunning()
+ let running = false
+ try { running = await isComfyRunning() } catch { /* ignore */ }
const comfyPath = findComfyUI()
+ const processAlive = comfyProcess !== null && !comfyProcess.killed
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({
running,
- starting: comfyProcess !== null && !running,
+ starting: processAlive && !running,
found: comfyPath !== null,
path: comfyPath,
logs: comfyLogs.slice(-20),
+ processAlive,
}))
})
},