Add MOSS-Image on the Image v2 path and stop the queue calling it Klein.
The bench queue labeled every engine except Krea, Qwen, MiniMax, and LTX as Klein, and the v2 starter treated any engine other than Krea as Flux. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,8 +2,7 @@ import { addStudioJob, kickStudioQueue, listStudioJobs, videoJobsBusy } from '~/
|
||||
import { comfyConfigured } from '~/server/utils/comfy'
|
||||
import {
|
||||
IMAGE_V2_CFG_DEFAULT,
|
||||
IMAGE_V2_KREA_CFG,
|
||||
IMAGE_V2_KREA_STEPS,
|
||||
imageV2SamplingDefaults,
|
||||
IMAGE_V2_STEPS_DEFAULT,
|
||||
IMAGE_V2_TURBO_CFG,
|
||||
IMAGE_V2_TURBO_STEPS,
|
||||
@@ -54,12 +53,13 @@ export default defineEventHandler(async (event) => {
|
||||
const negative = buildAssetPackNegative(
|
||||
String(body?.negative_prompt ?? body?.negative ?? '').trim()
|
||||
)
|
||||
const turbo = parseBool(body?.turbo)
|
||||
const steps = engine === 'krea'
|
||||
? clampImageSteps(body?.steps, IMAGE_V2_KREA_STEPS)
|
||||
const turbo = engine === 'moss' ? false : parseBool(body?.turbo)
|
||||
const sampling = imageV2SamplingDefaults(engine)
|
||||
const steps = engine === 'krea' || engine === 'moss'
|
||||
? clampImageSteps(body?.steps, sampling.steps)
|
||||
: turbo ? IMAGE_V2_TURBO_STEPS : clampImageSteps(body?.steps, IMAGE_V2_STEPS_DEFAULT)
|
||||
const cfg = engine === 'krea'
|
||||
? clampImageCfg(body?.cfg, IMAGE_V2_KREA_CFG)
|
||||
const cfg = engine === 'krea' || engine === 'moss'
|
||||
? clampImageCfg(body?.cfg, sampling.cfg)
|
||||
: turbo ? IMAGE_V2_TURBO_CFG : clampImageCfg(body?.cfg, IMAGE_V2_CFG_DEFAULT)
|
||||
const seed = body?.seed != null && String(body.seed) !== '' && String(body.seed) !== 'random'
|
||||
? Number(body.seed)
|
||||
|
||||
@@ -44,7 +44,7 @@ export default defineEventHandler(async (event) => {
|
||||
// Enqueue + kick after the client has the id — do not block the response on the worker wake path
|
||||
void (async () => {
|
||||
try {
|
||||
const row = await addStudioJob({ ownerKey: owner, kind: ['video', 'extend'].includes(request.mode) ? 'video' : 'edit', familyId: record.familyId, payload: { ...request.settings, studio2Id: id, studio2Request: structuredClone(request), prompt: request.compiledPrompt, folderId: request.folderId, extensions: [], referenceStillIds: [], useIdentityRefs: false, queueAutoRun: true } as StudioJobPayload });
|
||||
const row = await addStudioJob({ ownerKey: owner, kind: ['video', 'extend'].includes(request.mode) ? 'video' : 'edit', familyId: record.familyId, payload: { ...request.settings, engine: request.engine, studio2Id: id, studio2Request: structuredClone(request), prompt: request.compiledPrompt, folderId: request.folderId, extensions: [], referenceStillIds: [], useIdentityRefs: false, queueAutoRun: true } as StudioJobPayload });
|
||||
saveRecord({ ...readRecord(owner, id), queueId: row.id });
|
||||
} catch { /* poll / resume will pick up waiting studio2 records */ }
|
||||
kickStudioQueue();
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
IMAGE_V2_KREA_COMPOSE_DENOISE,
|
||||
IMAGE_V2_KREA_EDIT_DENOISE,
|
||||
IMAGE_V2_KREA_STEPS,
|
||||
IMAGE_V2_MOSS_CFG,
|
||||
IMAGE_V2_MOSS_STEPS,
|
||||
IMAGE_V2_DENOISE_DEFAULT,
|
||||
clampImageV2Denoise,
|
||||
clampImageV2Size,
|
||||
@@ -226,13 +228,23 @@ export default defineEventHandler(async (event) => {
|
||||
const hideThumbnail = parseBool(fields.hideThumbnail)
|
||||
const requestedEngine = parseImageV2Engine(fields.engine, 'flux')
|
||||
const engine = requestedEngine
|
||||
const turbo = parseBool(fields.turbo)
|
||||
if (engine === 'moss' && graphMode !== 'generate') {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'MOSS-Image is text-to-image only. Use Generate, or Klein or Krea for edits.'
|
||||
})
|
||||
}
|
||||
const turbo = engine === 'moss' ? false : parseBool(fields.turbo)
|
||||
const steps = engine === 'krea'
|
||||
? clampImageSteps(fields.steps, IMAGE_V2_KREA_STEPS)
|
||||
: turbo ? IMAGE_V2_TURBO_STEPS : clampImageSteps(fields.steps, IMAGE_V2_STEPS_DEFAULT)
|
||||
: engine === 'moss'
|
||||
? clampImageSteps(fields.steps, IMAGE_V2_MOSS_STEPS)
|
||||
: turbo ? IMAGE_V2_TURBO_STEPS : clampImageSteps(fields.steps, IMAGE_V2_STEPS_DEFAULT)
|
||||
const cfg = engine === 'krea'
|
||||
? clampImageCfg(fields.cfg, IMAGE_V2_KREA_CFG)
|
||||
: turbo ? IMAGE_V2_TURBO_CFG : clampImageCfg(fields.cfg, IMAGE_V2_CFG_DEFAULT)
|
||||
: engine === 'moss'
|
||||
? clampImageCfg(fields.cfg, IMAGE_V2_MOSS_CFG)
|
||||
: turbo ? IMAGE_V2_TURBO_CFG : clampImageCfg(fields.cfg, IMAGE_V2_CFG_DEFAULT)
|
||||
const megapixels = graphMode === 'generate'
|
||||
? 0
|
||||
: fields.scaleToTotalPixels == null
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"4": {
|
||||
"inputs": {
|
||||
"unet_name": "moss_image_sft_int8_convrot.safetensors",
|
||||
"weight_dtype": "default"
|
||||
},
|
||||
"class_type": "UNETLoader",
|
||||
"_meta": { "title": "Load MOSS-Image SFT" }
|
||||
},
|
||||
"5": {
|
||||
"inputs": {
|
||||
"clip_name": "qwen3.5_9b_w4a8_gptq.safetensors",
|
||||
"type": "moss_image",
|
||||
"device": "cpu"
|
||||
},
|
||||
"class_type": "CLIPLoader",
|
||||
"_meta": { "title": "Load Qwen3.5 text encoder" }
|
||||
},
|
||||
"6": {
|
||||
"inputs": { "vae_name": "flux2-vae_small.safetensors" },
|
||||
"class_type": "VAELoader",
|
||||
"_meta": { "title": "Load FLUX.2 VAE" }
|
||||
},
|
||||
"40": {
|
||||
"inputs": {
|
||||
"shift": 5,
|
||||
"model": ["4", 0]
|
||||
},
|
||||
"class_type": "ModelSamplingAuraFlow",
|
||||
"_meta": { "title": "MOSS shift" }
|
||||
},
|
||||
"41": {
|
||||
"inputs": {
|
||||
"model": ["40", 0],
|
||||
"double_layers": "",
|
||||
"single_layers": "22",
|
||||
"start_percent": 0,
|
||||
"end_percent": 1
|
||||
},
|
||||
"class_type": "SkipLayerGuidanceDiTSimple",
|
||||
"_meta": { "title": "Skip layer 22" }
|
||||
},
|
||||
"9": {
|
||||
"inputs": {
|
||||
"text": "",
|
||||
"clip": ["5", 0]
|
||||
},
|
||||
"class_type": "CLIPTextEncode",
|
||||
"_meta": { "title": "Positive Prompt" }
|
||||
},
|
||||
"10": {
|
||||
"inputs": {
|
||||
"text": "",
|
||||
"clip": ["5", 0]
|
||||
},
|
||||
"class_type": "CLIPTextEncode",
|
||||
"_meta": { "title": "Negative Prompt" }
|
||||
},
|
||||
"14": {
|
||||
"inputs": {
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"batch_size": 1
|
||||
},
|
||||
"class_type": "EmptyFlux2LatentImage",
|
||||
"_meta": { "title": "Empty Flux 2 Latent" }
|
||||
},
|
||||
"15": {
|
||||
"inputs": {
|
||||
"seed": 1,
|
||||
"steps": 25,
|
||||
"cfg": 2.5,
|
||||
"sampler_name": "euler",
|
||||
"scheduler": "sgm_uniform",
|
||||
"denoise": 1,
|
||||
"model": ["41", 0],
|
||||
"positive": ["9", 0],
|
||||
"negative": ["10", 0],
|
||||
"latent_image": ["14", 0]
|
||||
},
|
||||
"class_type": "KSampler",
|
||||
"_meta": { "title": "KSampler" }
|
||||
},
|
||||
"20": {
|
||||
"inputs": {
|
||||
"samples": ["15", 0],
|
||||
"vae": ["6", 0]
|
||||
},
|
||||
"class_type": "VAEDecode",
|
||||
"_meta": { "title": "VAE Decode" }
|
||||
},
|
||||
"21": {
|
||||
"inputs": {
|
||||
"filename_prefix": "v2-moss",
|
||||
"images": ["20", 0]
|
||||
},
|
||||
"class_type": "SaveImage",
|
||||
"_meta": { "title": "Save Image" }
|
||||
}
|
||||
}
|
||||
@@ -561,7 +561,7 @@ export function isOurComfyVideo(video: { filename: string; subfolder: string })
|
||||
}
|
||||
|
||||
export function comfySweepNamePrefixes() {
|
||||
const names = new Set(['MiniMax_H3', 'xAIGen', 'XAIgen', 'LTX23', 'AIGen', 'v2-krea', 'v2-generate'])
|
||||
const names = new Set(['MiniMax_H3', 'xAIGen', 'XAIgen', 'LTX23', 'AIGen', 'v2-krea', 'v2-generate', 'v2-moss'])
|
||||
for (const raw of [comfyFilenamePrefix(), comfyAudioPrefix(), comfyImagePrefix()]) {
|
||||
const last = raw.replace(/\/$/, '').split('/').pop()
|
||||
if (last) names.add(last)
|
||||
|
||||
@@ -23,10 +23,9 @@ import {
|
||||
IMAGE_V2_SNOFS_CLIP,
|
||||
IMAGE_V2_SNOFS_MODEL,
|
||||
IMAGE_V2_STEPS_DEFAULT,
|
||||
IMAGE_V2_KREA_CFG,
|
||||
IMAGE_V2_KREA_COMPOSE_DENOISE,
|
||||
IMAGE_V2_KREA_EDIT_DENOISE,
|
||||
IMAGE_V2_KREA_STEPS,
|
||||
imageV2SamplingDefaults,
|
||||
IMAGE_V2_DENOISE_DEFAULT,
|
||||
clampImageV2Denoise,
|
||||
clampImageV2Size,
|
||||
@@ -137,6 +136,7 @@ function sanitizeImageV2Settings(raw: unknown): ImageV2PresetSettings {
|
||||
const mode = parseImageV2Mode(rec.mode) || 'edit'
|
||||
const turbo = rec.turbo === true
|
||||
const engine = parseImageV2Engine(rec.engine, 'flux')
|
||||
const sampling = imageV2SamplingDefaults(engine)
|
||||
return {
|
||||
mode,
|
||||
engine,
|
||||
@@ -147,8 +147,8 @@ function sanitizeImageV2Settings(raw: unknown): ImageV2PresetSettings {
|
||||
snofsClip: isXaigenStudio() ? clampImageV2Strength(rec.snofsClip ?? rec.snofs_clip, IMAGE_V2_SNOFS_CLIP) : 0,
|
||||
consistencyModel: clampImageV2Strength(rec.consistencyModel ?? rec.consistency_model, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_MODEL),
|
||||
consistencyClip: clampImageV2Strength(rec.consistencyClip ?? rec.consistency_clip, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_CLIP),
|
||||
steps: engine === 'krea' ? clampImageSteps(rec.steps, IMAGE_V2_KREA_STEPS) : turbo ? 8 : clampImageSteps(rec.steps, IMAGE_V2_STEPS_DEFAULT),
|
||||
cfg: engine === 'krea' ? clampImageCfg(rec.cfg, IMAGE_V2_KREA_CFG) : turbo ? 1 : clampImageCfg(rec.cfg, IMAGE_V2_CFG_DEFAULT),
|
||||
steps: engine === 'krea' || engine === 'moss' ? clampImageSteps(rec.steps, sampling.steps) : turbo ? 8 : clampImageSteps(rec.steps, IMAGE_V2_STEPS_DEFAULT),
|
||||
cfg: engine === 'krea' || engine === 'moss' ? clampImageCfg(rec.cfg, sampling.cfg) : turbo ? 1 : clampImageCfg(rec.cfg, IMAGE_V2_CFG_DEFAULT),
|
||||
megapixels: mode === 'generate' || rec.scaleToTotalPixels === false ? undefined : clampImageScaleMegapixels(rec.megapixels ?? rec.scaleMegapixels, 1),
|
||||
scaleToTotalPixels: mode === 'generate' ? undefined : rec.scaleToTotalPixels === false ? false : true,
|
||||
turbo,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { createJob, emitJob, type Job } from '~/server/utils/jobs'
|
||||
import { ensureComfyReady } from '~/server/utils/comfyLifecycle'
|
||||
import { assertImageScaleToTotalPixelsNode, comfyImagePrefix, getComfyHost, uploadImage, queuePrompt } from '~/server/utils/comfy'
|
||||
import { withImageComfyHost, waitForImageEdit, downloadEditedImage, purgeImageComfyArtifacts } from '~/server/utils/imageComfy'
|
||||
import { buildImageV2Workflow, IMAGE_V2_NODE_LABELS, resolveKreaGenerateAssets } from '~/server/utils/imageWorkflowV2'
|
||||
import { buildImageV2Workflow, IMAGE_V2_NODE_LABELS, resolveKreaGenerateAssets, resolveMossGenerateAssets } from '~/server/utils/imageWorkflowV2'
|
||||
import { ensureComfyLoraNames, persistLoraFields } from '~/server/utils/loras'
|
||||
import { imageDimensions } from '~/server/utils/resolution'
|
||||
import { emitChainJob } from '~/server/utils/watch'
|
||||
@@ -107,7 +107,10 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
await withImageComfyHost(job.imageComfyHost, async () => {
|
||||
const generate = graphMode === 'generate'
|
||||
const engine = parseImageV2Engine(params.engine, 'flux')
|
||||
const engineLabel = engine === 'krea' ? 'Krea' : 'Flux'
|
||||
if (engine === 'moss' && !generate) {
|
||||
throw new Error('MOSS-Image is text-to-image only. Use Generate, or Klein or Krea for edits.')
|
||||
}
|
||||
const engineLabel = engine === 'krea' ? 'Krea' : engine === 'moss' ? 'MOSS' : 'Flux'
|
||||
const { applyImageFill } = await import('~/server/utils/imagePad')
|
||||
const { composeFillPrompt } = await import('~/utils/imageAspect')
|
||||
let current = params.image || null
|
||||
@@ -120,6 +123,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
await ensureComfyLoraNames('image')
|
||||
if ((!generate && params.megapixels > 0) || (generate && params.reference)) await assertImageScaleToTotalPixelsNode()
|
||||
const krea = engine === 'krea' ? await resolveKreaGenerateAssets() : null
|
||||
const moss = engine === 'moss' ? await resolveMossGenerateAssets() : null
|
||||
if ((graphMode === 'compose' || (generate && engine === 'flux')) && params.reference) {
|
||||
uploadedRef = await uploadImage({
|
||||
...params.reference,
|
||||
@@ -264,6 +268,10 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
kreaClipName: krea?.clip,
|
||||
kreaVaeName: krea?.vae,
|
||||
kreaConceptLora: krea?.conceptLora,
|
||||
mossUnetName: moss?.unet,
|
||||
mossClipName: moss?.clip,
|
||||
mossVaeName: moss?.vae,
|
||||
mossClipDevice: moss?.clipDevice,
|
||||
loraStack: appliedStack
|
||||
})
|
||||
const queued = await queuePrompt(built.graph, job.clientId)
|
||||
|
||||
@@ -7,6 +7,7 @@ import kreaGenerateTemplate from '../assets/krea_v2_generate.json'
|
||||
import kreaEditTemplate from '../assets/krea_v2_edit.json'
|
||||
import kreaComposeTemplate from '../assets/krea_v2_compose.json'
|
||||
import kreaRefineTemplate from '../assets/krea_v2_refine.json'
|
||||
import mossGenerateTemplate from '../assets/moss_v2_generate.json'
|
||||
import { IMAGE_SCALE_TO_TOTAL_PIXELS } from '~/server/utils/comfy'
|
||||
import { imageComfyFetch } from '~/server/utils/imageComfy'
|
||||
import { applyImageV2UserLoras } from '~/server/utils/loras'
|
||||
@@ -23,6 +24,14 @@ import {
|
||||
IMAGE_V2_KREA_STEPS,
|
||||
IMAGE_V2_KREA_UNET_CANDIDATES,
|
||||
IMAGE_V2_KREA_VAE,
|
||||
IMAGE_V2_MOSS_CFG,
|
||||
IMAGE_V2_MOSS_CLIP_CANDIDATES,
|
||||
IMAGE_V2_MOSS_CLIP_TYPE,
|
||||
IMAGE_V2_MOSS_SHIFT,
|
||||
IMAGE_V2_MOSS_SLG_LAYER,
|
||||
IMAGE_V2_MOSS_STEPS,
|
||||
IMAGE_V2_MOSS_UNET,
|
||||
IMAGE_V2_MOSS_VAE_CANDIDATES,
|
||||
IMAGE_V2_DENOISE_DEFAULT,
|
||||
IMAGE_V2_GENERATE_HEIGHT,
|
||||
IMAGE_V2_GENERATE_WIDTH,
|
||||
@@ -58,6 +67,7 @@ export const IMAGE_V2_KREA_GENERATE_WORKFLOW = 'krea_v2_generate.json'
|
||||
export const IMAGE_V2_KREA_EDIT_WORKFLOW = 'krea_v2_edit.json'
|
||||
export const IMAGE_V2_KREA_COMPOSE_WORKFLOW = 'krea_v2_compose.json'
|
||||
export const IMAGE_V2_KREA_REFINE_WORKFLOW = 'krea_v2_refine.json'
|
||||
export const IMAGE_V2_MOSS_GENERATE_WORKFLOW = 'moss_v2_generate.json'
|
||||
|
||||
export interface ImageV2BuildParams {
|
||||
mode: ImageV2Mode
|
||||
@@ -86,6 +96,10 @@ export interface ImageV2BuildParams {
|
||||
kreaClipName?: string
|
||||
kreaVaeName?: string
|
||||
kreaConceptLora?: string
|
||||
mossUnetName?: string
|
||||
mossClipName?: string
|
||||
mossVaeName?: string
|
||||
mossClipDevice?: string
|
||||
loraStack?: LoraStackItem[]
|
||||
}
|
||||
|
||||
@@ -234,6 +248,59 @@ export async function resolveKreaGenerateAssets() {
|
||||
return { unet, clip, vae, conceptLora: configuredKreaConceptLora() }
|
||||
}
|
||||
|
||||
function clipLoaderChoices(clipInfo: unknown, field: string) {
|
||||
const rec = clipInfo && typeof clipInfo === 'object' ? clipInfo as Record<string, unknown> : {}
|
||||
const body = (rec.CLIPLoader && typeof rec.CLIPLoader === 'object' ? rec.CLIPLoader : rec) as {
|
||||
input?: { required?: Record<string, unknown> }
|
||||
}
|
||||
const spec = body.input?.required?.[field]
|
||||
return Array.isArray(spec) && Array.isArray(spec[0])
|
||||
? (spec[0] as unknown[]).map(item => String(item || ''))
|
||||
: []
|
||||
}
|
||||
|
||||
export async function resolveMossGenerateAssets() {
|
||||
const [unets, clips, vaes, clipInfo] = await Promise.all([
|
||||
listComfyModels('diffusion_models'),
|
||||
listComfyModels('text_encoders').then(async (names) => names.length ? names : listComfyModels('clip')),
|
||||
listComfyModels('vae'),
|
||||
imageComfyFetch('/object_info/CLIPLoader', { signal: AbortSignal.timeout(8000) })
|
||||
.then(async (res) => res.ok ? res.json() : null)
|
||||
.catch(() => null)
|
||||
])
|
||||
const unet = pickComfyModel(unets, [IMAGE_V2_MOSS_UNET])
|
||||
if (!unet) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `MOSS diffusion model is missing on Beast Comfy (${IMAGE_V2_MOSS_UNET} in diffusion_models).`
|
||||
})
|
||||
}
|
||||
const clip = pickComfyModel(clips, [...IMAGE_V2_MOSS_CLIP_CANDIDATES])
|
||||
if (!clip) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `MOSS text encoder is missing on Beast Comfy (${IMAGE_V2_MOSS_CLIP_CANDIDATES.join(' or ')}).`
|
||||
})
|
||||
}
|
||||
const vae = pickComfyModel(vaes, [...IMAGE_V2_MOSS_VAE_CANDIDATES])
|
||||
if (!vae) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: `FLUX.2 VAE is missing on Beast Comfy (${IMAGE_V2_MOSS_VAE_CANDIDATES.join(' or ')}).`
|
||||
})
|
||||
}
|
||||
const types = clipLoaderChoices(clipInfo, 'type')
|
||||
if (types.length && !types.includes(IMAGE_V2_MOSS_CLIP_TYPE)) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: 'Beast Comfy CLIPLoader has no moss_image type. Update ComfyUI to 0.42 or later before using MOSS-Image.'
|
||||
})
|
||||
}
|
||||
const devices = clipLoaderChoices(clipInfo, 'device')
|
||||
const clipDevice = !devices.length || devices.includes('cpu') ? 'cpu' : 'default'
|
||||
return { unet, clip, vae, clipDevice }
|
||||
}
|
||||
|
||||
function graphFileNames(graph: WorkflowGraph) {
|
||||
const names: string[] = []
|
||||
for (const node of Object.values(graph)) {
|
||||
@@ -298,12 +365,61 @@ function assertKreaItiGraph(graph: WorkflowGraph, mode: ImageV2Mode) {
|
||||
assertKreaShared(graph)
|
||||
}
|
||||
|
||||
function assertMossGenerateGraph(graph: WorkflowGraph) {
|
||||
const loaders = loadImageNames(graph)
|
||||
if (loaders.length) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'MOSS generate graph has a required LoadImage. Refusing to run.'
|
||||
})
|
||||
}
|
||||
const latent = Object.values(graph).find(node => node.class_type === 'EmptyFlux2LatentImage')
|
||||
if (!latent) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS generate graph is missing EmptyFlux2LatentImage.' })
|
||||
}
|
||||
const clip = graph['5']
|
||||
if (!clip || clip.class_type !== 'CLIPLoader' || String(clip.inputs.type || '') !== IMAGE_V2_MOSS_CLIP_TYPE) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph CLIPLoader type must be moss_image.' })
|
||||
}
|
||||
const shift = Object.values(graph).find(node => node.class_type === 'ModelSamplingAuraFlow')
|
||||
if (!shift || Number(shift.inputs.shift) !== IMAGE_V2_MOSS_SHIFT) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph must set shift 5 with ModelSamplingAuraFlow.' })
|
||||
}
|
||||
const slg = Object.values(graph).find(node => node.class_type === 'SkipLayerGuidanceDiTSimple')
|
||||
const layers = String(slg?.inputs.single_layers || '')
|
||||
if (!slg || !layers.split(/[^\d]+/).includes(IMAGE_V2_MOSS_SLG_LAYER) || String(slg.inputs.double_layers || '').trim()) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph skip-layer guidance must skip layer 22 only.' })
|
||||
}
|
||||
const sampler = graph['15']
|
||||
if (!sampler || sampler.class_type !== 'KSampler') {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph is missing KSampler.' })
|
||||
}
|
||||
if (Object.values(graph).some(node => node.class_type === 'Flux2Scheduler' || node.class_type === 'ReferenceLatent' || node.class_type === 'LoraLoader')) {
|
||||
throw createError({ statusCode: 500, statusMessage: 'MOSS graph contains a Klein scheduler, reference, or LoRA. Refusing to run.' })
|
||||
}
|
||||
const banned = graphFileNames(graph).filter((name) => {
|
||||
const id = modelIdentity(name)
|
||||
return /flux-?2-klein|klein_snofs|krea2_turbo|qwen_3_8b|qwen3vl_4b|full_encoder_small_decoder|qwen_image_vae/i.test(id)
|
||||
})
|
||||
if (banned.length) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'MOSS graph includes a Klein or Krea model. Refusing to run.'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imageBName?: string, engine: ImageV2Engine = 'flux') {
|
||||
const loaders = loadImageNames(graph)
|
||||
if (mode === 'generate' && engine === 'krea') {
|
||||
assertKreaGenerateGraph(graph)
|
||||
} else if (engine === 'krea') {
|
||||
assertKreaItiGraph(graph, mode)
|
||||
} else if (engine === 'moss') {
|
||||
if (mode !== 'generate') {
|
||||
throw createError({ statusCode: 400, statusMessage: 'MOSS-Image is text-to-image only.' })
|
||||
}
|
||||
assertMossGenerateGraph(graph)
|
||||
} else if (mode === 'generate') {
|
||||
if (loaders.length && !(imageBName && loaders.length === 1 && graph['reference:load']?.inputs.image === imageBName)) {
|
||||
throw createError({
|
||||
@@ -503,8 +619,76 @@ function buildKreaGenerateWorkflow(params: ImageV2BuildParams) {
|
||||
return { graph, workflowFile, loaders, prompt, strength: undefined }
|
||||
}
|
||||
|
||||
function requireMossModels(params: ImageV2BuildParams) {
|
||||
if (!params.mossUnetName || !params.mossClipName || !params.mossVaeName) {
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: 'MOSS models were not resolved. Refusing to fall back to Flux or Krea.'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function buildMossGenerateWorkflow(params: ImageV2BuildParams) {
|
||||
if (params.mode !== 'generate') {
|
||||
throw createError({ statusCode: 400, statusMessage: 'MOSS-Image is text-to-image only.' })
|
||||
}
|
||||
requireMossModels(params)
|
||||
const graph = structuredClone(mossGenerateTemplate) as WorkflowGraph
|
||||
const prompt = composeImageV2Prompt('generate', 't2i', params.prompt)
|
||||
const negative = String(params.negative || '')
|
||||
const size = clampImageV2Size(params.width, params.height, params.aspect)
|
||||
const steps = clampImageSteps(params.steps, IMAGE_V2_MOSS_STEPS)
|
||||
const cfg = clampImageCfg(params.cfg, IMAGE_V2_MOSS_CFG)
|
||||
const workflowFile = IMAGE_V2_MOSS_GENERATE_WORKFLOW
|
||||
|
||||
setInput(graph, '4', 'unet_name', params.mossUnetName)
|
||||
setInput(graph, '5', 'clip_name', params.mossClipName)
|
||||
setInput(graph, '5', 'type', IMAGE_V2_MOSS_CLIP_TYPE)
|
||||
setInput(graph, '5', 'device', params.mossClipDevice || 'cpu')
|
||||
setInput(graph, '6', 'vae_name', params.mossVaeName)
|
||||
setInput(graph, '14', 'width', size.width)
|
||||
setInput(graph, '14', 'height', size.height)
|
||||
setInput(graph, '40', 'shift', IMAGE_V2_MOSS_SHIFT)
|
||||
setInput(graph, '41', 'single_layers', IMAGE_V2_MOSS_SLG_LAYER)
|
||||
setInput(graph, '41', 'double_layers', '')
|
||||
setInput(graph, PROMPT, 'text', prompt)
|
||||
setInput(graph, NEGATIVE, 'text', negative)
|
||||
setInput(graph, '15', 'seed', params.seed)
|
||||
setInput(graph, '15', 'steps', steps)
|
||||
setInput(graph, '15', 'cfg', cfg)
|
||||
setInput(graph, '15', 'sampler_name', 'euler')
|
||||
setInput(graph, '15', 'scheduler', 'sgm_uniform')
|
||||
setInput(graph, '15', 'denoise', 1)
|
||||
setInput(graph, SAVE, 'filename_prefix', params.filenamePrefix || 'v2-moss')
|
||||
|
||||
assertImageV2Graph(graph, 'generate', undefined, 'moss')
|
||||
const loaders = loadImageNames(graph)
|
||||
console.log(JSON.stringify({
|
||||
src: 'image-v2',
|
||||
engine: 'moss',
|
||||
workflow: workflowFile,
|
||||
mode: 'generate',
|
||||
task: 't2i',
|
||||
size: { width: size.width, height: size.height },
|
||||
models: {
|
||||
unet: params.mossUnetName,
|
||||
clip: params.mossClipName,
|
||||
vae: params.mossVaeName,
|
||||
clipDevice: params.mossClipDevice || 'cpu'
|
||||
},
|
||||
shift: IMAGE_V2_MOSS_SHIFT,
|
||||
slg: IMAGE_V2_MOSS_SLG_LAYER,
|
||||
upsampler: false,
|
||||
steps,
|
||||
cfg,
|
||||
seed: params.seed
|
||||
}))
|
||||
return { graph, workflowFile, loaders, prompt, strength: undefined }
|
||||
}
|
||||
|
||||
export function buildImageV2Workflow(params: ImageV2BuildParams) {
|
||||
const engine = parseImageV2Engine(params.engine, 'flux')
|
||||
if (engine === 'moss') return buildMossGenerateWorkflow(params)
|
||||
if (engine === 'krea') {
|
||||
return params.mode === 'generate' ? buildKreaGenerateWorkflow(params) : buildKreaItiWorkflow(params)
|
||||
}
|
||||
@@ -602,6 +786,8 @@ export const IMAGE_V2_NODE_LABELS: Record<string, string> = {
|
||||
'33': 'Applying mask',
|
||||
'14': 'Building empty latent',
|
||||
'15': 'Sampling',
|
||||
'40': 'Applying shift',
|
||||
'41': 'Skip-layer guidance',
|
||||
'19': 'Sampling',
|
||||
'20': 'Decoding still',
|
||||
'21': 'Saving still'
|
||||
|
||||
@@ -439,7 +439,8 @@ function linkRef(value: unknown): [string, number] | null {
|
||||
: null
|
||||
}
|
||||
|
||||
export function assertImageV2LoraStack(stack: unknown, engine: 'flux' | 'krea') {
|
||||
export function assertImageV2LoraStack(stack: unknown, engine: 'flux' | 'krea' | 'moss') {
|
||||
if (engine === 'moss') return []
|
||||
const items = normalizeLoraStack(stack)
|
||||
const wrong = items.find((item) => {
|
||||
const tagged = imageLoraEngineOf(item.name)
|
||||
|
||||
@@ -27,7 +27,7 @@ import { readRecord, saveRecord, studio2Root, records } from './store';
|
||||
import { ensureComfyReady } from '../comfyLifecycle';
|
||||
import { comfyFetch, queuePrompt, fetchHistory, extractVideo, freeComfyVram } from '../comfy';
|
||||
import { extractEditedImage } from '../imageComfy';
|
||||
import { buildImageV2Workflow, resolveKreaGenerateAssets } from '../imageWorkflowV2';
|
||||
import { buildImageV2Workflow, resolveKreaGenerateAssets, resolveMossGenerateAssets } from '../imageWorkflowV2';
|
||||
import { resolveGraphLoraNames, applyUserLoraToGraph, ensureComfyLoraNames } from '../loras';
|
||||
import { getClip, getStill, stillPath, clipVideoPath, saveStill, saveClip, downloadComfyImage, downloadComfyVideo, attachStudio2Metadata } from '../library';
|
||||
import { imageDimensions } from '../resolution';
|
||||
@@ -315,6 +315,29 @@ async function prepareGraph(r: any) {
|
||||
r.graphId = 'studio2_minimax_native.json';
|
||||
}
|
||||
}
|
||||
else if (q.engine === 'moss') {
|
||||
if (q.mode !== 'generate')
|
||||
throw new Error('MOSS-Image is text-to-image only.');
|
||||
const moss = await resolveMossGenerateAssets();
|
||||
graph = buildImageV2Workflow({
|
||||
...s,
|
||||
engine: 'moss',
|
||||
mode: 'generate',
|
||||
task: 't2i',
|
||||
prompt: q.compiledPrompt,
|
||||
negative: stylePrompt(q.imageStyles, true),
|
||||
filenamePrefix: prefix + '/image',
|
||||
mossUnetName: moss.unet,
|
||||
mossClipName: moss.clip,
|
||||
mossVaeName: moss.vae,
|
||||
mossClipDevice: moss.clipDevice
|
||||
}).graph;
|
||||
applyResolvedImageSize(graph, s);
|
||||
r.sampleLatent = 'empty latent';
|
||||
r.sampleDenoise = null;
|
||||
r.heroReferenceAttached = false;
|
||||
r.graphId = 'moss_v2_generate.json';
|
||||
}
|
||||
else if (q.engine === 'qwen21') {
|
||||
if (!['generate', 'edit'].includes(q.mode))
|
||||
throw new Error('Qwen 2.1 supports Generate and Edit.')
|
||||
@@ -410,6 +433,8 @@ async function prepareGraph(r: any) {
|
||||
applyUserLoraToGraph(graph, s.loraStack)
|
||||
}
|
||||
else {
|
||||
if (q.engine === 'moss')
|
||||
throw new Error('MOSS-Image does not use the Klein or Krea graph.');
|
||||
const mode = identityPlan?.mode ?? (q.mode === 'iterate' ? (a ? 'edit' : 'generate') : q.mode);
|
||||
const found = q.engine === 'krea' ? await resolveKreaGenerateAssets() : null;
|
||||
const assets = found ? { kreaUnetName: found.unet, kreaClipName: found.clip, kreaVaeName: found.vae, kreaConceptLora: found.conceptLora } : {};
|
||||
|
||||
@@ -9,7 +9,7 @@ import { isLtxWorkflow, isTextToVideo, isXaigenStudio, LTX_DISABLED_MESSAGE, ltx
|
||||
import { persistLoraFields } from '~/server/utils/loras'
|
||||
import { resolveLoraStack } from '~/utils/loras'
|
||||
import { persistPromptWrappers } from '~/utils/promptParts'
|
||||
import { imageV2StackSpecials } from '~/utils/imageV2'
|
||||
import { imageV2StackSpecials, parseImageV2Engine } from '~/utils/imageV2'
|
||||
import { allowIdentityRefs, type PermanenceRef } from '~/utils/globalLocks'
|
||||
|
||||
export type StudioJobStatus = 'waiting' | 'running' | 'held' | 'complete' | 'error' | 'cancelled'
|
||||
@@ -66,7 +66,7 @@ export interface StudioJobPayload {
|
||||
imagePipeline?: 'v1' | 'v2'
|
||||
v2Mode?: 'edit' | 'compose' | 'refine' | 'generate' | 'iterate'
|
||||
v2Task?: 'scene' | 'identity' | 'outfit' | 'face_lock' | 'refine' | 't2i'
|
||||
engine?: 'flux' | 'krea'
|
||||
engine?: 'flux' | 'krea' | 'moss'
|
||||
snofsModel?: number
|
||||
snofsClip?: number
|
||||
consistencyModel?: number
|
||||
@@ -1318,7 +1318,7 @@ async function startStudioEditJob(item: StudioJob) {
|
||||
}
|
||||
})
|
||||
await markStudioLive(item.ownerKey, item.id, live.id)
|
||||
const v2Engine = payload.engine === 'krea' ? 'krea' : 'flux'
|
||||
const v2Engine = parseImageV2Engine(payload.engine, 'flux')
|
||||
const v2Specials = imageV2StackSpecials(payload.loraStack, v2Engine)
|
||||
void runEditV2(live, {
|
||||
mode,
|
||||
|
||||
Reference in New Issue
Block a user