From 8602d6ed2e827a3e8d459fdab0bfa73376a9171c Mon Sep 17 00:00:00 2001 From: Towsty Date: Thu, 22 Oct 2026 20:28:25 -0500 Subject: [PATCH] Let MOSS use the same LoRA picker and chain those adapters onto its graph. The picker was hidden and the API cleared every stack, so a selected MOSS job could not carry a LoRA. Co-authored-by: Cursor --- components/studio2/Bench.vue | 2 +- docs/image-v2.md | 2 +- pages/studio-1.vue | 7 +++---- server/utils/imageWorkflowV2.ts | 2 ++ server/utils/loras.ts | 3 +-- shared/studio2/contracts.mjs | 2 +- tests/image-v2-moss.test.mjs | 12 ++++++++---- tests/studio2-bench.test.mjs | 7 ++++++- tests/studio2-lora-memory.test.mjs | 2 +- utils/imageV2.ts | 2 +- utils/loras.ts | 25 +++++++++++++------------ 11 files changed, 38 insertions(+), 28 deletions(-) diff --git a/components/studio2/Bench.vue b/components/studio2/Bench.vue index 5e5f7f7..e8b14df 100644 --- a/components/studio2/Bench.vue +++ b/components/studio2/Bench.vue @@ -172,7 +172,7 @@ -
+
LoRA

Krea only lists krea LoRAs. Flux files stay on the Flux engine.

-

MOSS SFT does not load Klein or Krea LoRAs. The prompt upsampler stays off.

+

MOSS lists moss LoRAs. Klein and Krea files stay on those engines. The prompt upsampler stays off.

@@ -7490,7 +7489,7 @@ async function editImageV2() { const tagged = imageLoraEngineOf(item.name) return tagged != null && tagged !== v2Engine.value }) - if (v2Engine.value !== 'moss' && wrongEngine) { + if (wrongEngine) { toast(imageLoraEngineMismatchMessage(wrongEngine.name, v2Engine.value)) return } diff --git a/server/utils/imageWorkflowV2.ts b/server/utils/imageWorkflowV2.ts index 144713a..2f810f9 100644 --- a/server/utils/imageWorkflowV2.ts +++ b/server/utils/imageWorkflowV2.ts @@ -662,6 +662,7 @@ function buildMossGenerateWorkflow(params: ImageV2BuildParams) { setInput(graph, SAVE, 'filename_prefix', params.filenamePrefix || 'v2-moss') assertImageV2Graph(graph, 'generate', undefined, 'moss') + const userLoras = applyImageV2UserLoras(graph, imageV2UserStack(params, 'moss'), 'moss') const loaders = loadImageNames(graph) console.log(JSON.stringify({ src: 'image-v2', @@ -678,6 +679,7 @@ function buildMossGenerateWorkflow(params: ImageV2BuildParams) { }, shift: IMAGE_V2_MOSS_SHIFT, slg: IMAGE_V2_MOSS_SLG_LAYER, + loras: { user: userLoras }, upsampler: false, steps, cfg, diff --git a/server/utils/loras.ts b/server/utils/loras.ts index 61f64b7..b2b75ee 100644 --- a/server/utils/loras.ts +++ b/server/utils/loras.ts @@ -440,7 +440,6 @@ function linkRef(value: unknown): [string, number] | null { } 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) @@ -482,7 +481,7 @@ function clipConsumers(graph: WorkflowGraph) { export function applyImageV2UserLoras( graph: WorkflowGraph, stack?: unknown, - engine: 'flux' | 'krea' = 'flux' + engine: 'flux' | 'krea' | 'moss' = 'flux' ) { stripExistingLoraLoaders(graph) diff --git a/shared/studio2/contracts.mjs b/shared/studio2/contracts.mjs index acf7131..6f911f7 100644 --- a/shared/studio2/contracts.mjs +++ b/shared/studio2/contracts.mjs @@ -82,7 +82,7 @@ export function validateRequest(raw, xaigen = false) { photos: Array.isArray(raw.photos) ? raw.photos : [], startFrameSource: raw.startClipId ? {kind:'previous-last-frame',clipId:raw.startClipId} : {kind:'still',stillId:raw.imageAId || ''}, promptSections, compiledPrompt:compilePrompt(promptSections,video,{...raw,engine,lockFace:quietLocks?false:raw.lockFace,lockOutfit:quietLocks?false:raw.lockOutfit}), - settings: { aspect, fps:number('fps',24,1,60), width, height, steps, cfg, seedMode:raw.settings?.seedMode==='locked'?'locked':'random',seed:shotSeeds[0],duration:number('duration',5,1,15),turbo:moss ? false : raw.settings?.turbo !== false, loraStack:moss ? [] : (Array.isArray(raw.settings?.loraStack)?raw.settings.loraStack:[]) }, + settings: { aspect, fps:number('fps',24,1,60), width, height, steps, cfg, seedMode:raw.settings?.seedMode==='locked'?'locked':'random',seed:shotSeeds[0],duration:number('duration',5,1,15),turbo:moss ? false : raw.settings?.turbo !== false, loraStack:Array.isArray(raw.settings?.loraStack)?raw.settings.loraStack:[] }, guides: (Array.isArray(raw.guides)?raw.guides:[]).slice(0,8).map(g=>{ if (!g.stillId || !Number.isInteger(g.frame) || g.frame<1 || g.frame>=frames) fail('Each guide requires a still and positive frame index.'); return {stillId:String(g.stillId),frame:g.frame} }), batch: (Array.isArray(raw.batch)?raw.batch:[]).slice(0,30).map(s=>{const next=sectionsFrom({...promptSections,...(typeof s==='string'?{action:s}:s)});if(!next.action.trim())fail('Every shot needs an action prompt.');return video?next:{action:next.action}}) } } diff --git a/tests/image-v2-moss.test.mjs b/tests/image-v2-moss.test.mjs index 7d2edf4..66e7e05 100644 --- a/tests/image-v2-moss.test.mjs +++ b/tests/image-v2-moss.test.mjs @@ -8,8 +8,9 @@ import ts from 'typescript' const stub = ` export function filterLoraStackForImageEngine(stack, engine) { - if (engine === 'moss') return [] - return Array.isArray(stack) ? stack : [] + const items = Array.isArray(stack) ? stack : [] + if (engine !== 'moss') return items + return items.filter(item => /(^|[\\/_.-])moss/i.test(String(item?.name || ''))) } export function loraIdentityKey(name) { return String(name || '').replace(/\\\\/g, '/').split('/').pop().toLowerCase() @@ -47,11 +48,14 @@ test('MOSS is a generate engine with its own workflow and sampling defaults', () assert.deepEqual(api.imageV2SamplingDefaults('krea'), { steps: 8, cfg: 1 }) assert.deepEqual(api.imageV2SamplingDefaults('flux'), { steps: 24, cfg: 4 }) assert.deepEqual(api.defaultImageV2LoraStack({ engine: 'moss', mode: 'generate', xaigen: true }), []) - assert.deepEqual(api.mergeLegacyImageV2Loras([{ name: 'klein.safetensors', strengthModel: 1, strengthClip: 1 }], { + assert.deepEqual(api.mergeLegacyImageV2Loras([ + { name: 'klein.safetensors', strengthModel: 1, strengthClip: 1 }, + { name: 'moss-style.safetensors', strengthModel: 0.8, strengthClip: 0.8 } + ], { engine: 'moss', mode: 'generate', xaigen: true - }), []) + }), [{ name: 'moss-style.safetensors', strengthModel: 0.8, strengthClip: 0.8 }]) }) test('MOSS look settings stay separate from Klein and Krea', () => { diff --git a/tests/studio2-bench.test.mjs b/tests/studio2-bench.test.mjs index 7054cee..90bc0b9 100644 --- a/tests/studio2-bench.test.mjs +++ b/tests/studio2-bench.test.mjs @@ -7,6 +7,7 @@ import {useAsHero,useAsSource,restoreAll,hydrateStudio2Job} from '../shared/stud import {toggleStyle,parseBatch,parseBatchDoubleBlank,stylePrompt} from '../shared/studio2/styles.mjs' import {compilePrompt,validateRequest} from '../shared/studio2/contracts.mjs' import {queueEngineLabel} from '../shared/studio2/queue-view.mjs' +import {filterLorasForUse,filterLoraStackForUse,loraMatchesImageEngine} from '../utils/loras.ts' import {cachedLoras} from '../shared/studio2/lora-cache.mjs' import {resolveQwen21Size} from '../shared/studio2/qwen21-size.mjs' import {ensureQwen21EditPrompt,stitchQwen21PeEditPrompt,QWEN21_EDIT_KEEP_CHANGE} from '../shared/studio2/qwen21-edit.mjs' @@ -105,7 +106,11 @@ test('moss is generate-only with its own steps and CFG',()=>{ assert.equal(q.settings.height,1024) assert.equal(q.turbo,false) assert.equal(q.enhancePrompt,false) - assert.deepEqual(q.settings.loraStack,[]) + assert.deepEqual(q.settings.loraStack,[{name:'klein-anime.safetensors'}]) + assert.deepEqual(filterLoraStackForUse(q.settings.loraStack,'moss',true),[]) + assert.deepEqual(filterLorasForUse(['moss-style.safetensors','klein-anime.safetensors','krea-look.safetensors'],'moss'),['moss-style.safetensors']) + assert.equal(loraMatchesImageEngine('moss-style.safetensors','moss'),true) + assert.equal(loraMatchesImageEngine('klein-anime.safetensors','moss'),false) assert.equal(q.identityStillId,'') const fresh=validateRequest({mode:'generate',engine:'moss',folderId:'f',promptSections:{action:'cup'},settings:{aspect:'auto'}}) assert.equal(fresh.settings.steps,25) diff --git a/tests/studio2-lora-memory.test.mjs b/tests/studio2-lora-memory.test.mjs index 10064df..a5af468 100644 --- a/tests/studio2-lora-memory.test.mjs +++ b/tests/studio2-lora-memory.test.mjs @@ -7,7 +7,7 @@ import {restoreAll,restoreAsset,bindClip,extendSelected,useAsHero,useAsSource} f const stack=name=>[{name:name+'.safetensors',strengthModel:.6,strengthClip:.35}] test('engine token matrix uses paths and names, omits unknown and system picker entries',()=>{ - const cases={'xaigen-klein_car':'flux','klein/style':'flux','XAIgen-flux_test':'flux','Flux2-Klein/test':'flux','MiniMax/car':'minimax','folder/LTX_style':'ltx','xiagen-Krea_look':'krea','xaigen-krea/style':'krea','unlabelled':null} + const cases={'xaigen-klein_car':'flux','klein/style':'flux','XAIgen-flux_test':'flux','Flux2-Klein/test':'flux','MiniMax/car':'minimax','folder/LTX_style':'ltx','xiagen-Krea_look':'krea','xaigen-krea/style':'krea','moss-style':'moss','folder/MOSS_look':'moss','unlabelled':null} for(const [name,use] of Object.entries(cases)) { assert.deepEqual(inferLoraUse(name+'.safetensors'),use?[use]:null) for(const current of ['flux','krea','minimax','ltx']) assert.equal(filterLorasForUse([name+'.safetensors'],current).length,use===current?1:0) diff --git a/utils/imageV2.ts b/utils/imageV2.ts index c4ed61a..9d7c70b 100644 --- a/utils/imageV2.ts +++ b/utils/imageV2.ts @@ -338,7 +338,7 @@ export function mergeLegacyImageV2Loras(stack: unknown, opts: { consistencyClip?: number kreaConcept?: string }): LoraStackItem[] { - if (opts.engine === 'moss') return [] + if (opts.engine === 'moss') return filterLoraStackForImageEngine(stack, 'moss') let items = filterLoraStackForImageEngine(stack, opts.engine) if (opts.engine === 'krea') { const name = String(opts.kreaConcept || '').trim() diff --git a/utils/loras.ts b/utils/loras.ts index be6d8fe..4327b7b 100644 --- a/utils/loras.ts +++ b/utils/loras.ts @@ -230,10 +230,10 @@ export function isKleinImageLora(name: string) { return /flux-?2-klein|klein_snofs|flux2-klein-9b-consistency|(^|[^a-z0-9])klein([^a-z0-9]|$)/i.test(id) } -function hasImageEngineToken(source: string, engine: 'flux' | 'krea') { +function hasImageEngineToken(source: string, engine: 'flux' | 'krea' | 'moss') { const value = String(source || '').replace(/\\/g, '/').toLowerCase() if (!value) return false - const token = engine === 'krea' ? 'krea' : 'flux' + const token = engine === 'krea' ? 'krea' : engine === 'moss' ? 'moss' : 'flux' return new RegExp(`(?:^|[/_.-])${token}`).test(value) } @@ -241,10 +241,15 @@ function hasImageEngineToken(source: string, engine: 'flux' | 'krea') { * Image engine from the filename: `xaigen-flux-…` / `flux-…` vs `xaigen-krea-…` / `krea-…`. * Klein / SNOFS files without that prefix still count as Flux or Krea. */ -export function imageLoraEngineOf(name: string): 'flux' | 'krea' | null { +export function imageLoraEngineOf(name: string): 'flux' | 'krea' | 'moss' | null { const raw = String(name || '') const base = loraBasename(raw) const id = loraIdentityKey(raw) + if ( + hasImageEngineToken(raw, 'moss') + || hasImageEngineToken(base, 'moss') + || hasImageEngineToken(id, 'moss') + ) return 'moss' if ( hasImageEngineToken(raw, 'krea') || hasImageEngineToken(base, 'krea') @@ -262,25 +267,22 @@ export function imageLoraEngineOf(name: string): 'flux' | 'krea' | null { } export function loraMatchesImageEngine(name: string, engine: 'flux' | 'krea' | 'moss') { - if (engine === 'moss') return false return imageLoraEngineOf(name) === engine } export function filterLorasForImageEngine(names: string[], engine: 'flux' | 'krea' | 'moss') { - if (engine === 'moss') return [] return names.filter(name => loraMatchesImageEngine(name, engine)) } export function filterLoraStackForImageEngine(stack: unknown, engine: 'flux' | 'krea' | 'moss') { - if (engine === 'moss') return [] return normalizeLoraStack(stack).filter(item => loraMatchesImageEngine(item.name, engine)) } export function imageLoraEngineMismatchMessage(name: string, engine: 'flux' | 'krea' | 'moss') { - if (engine === 'moss') return `${loraDisplayName(name)} cannot be used with MOSS-Image.` - const other = engine === 'krea' ? 'Flux' : 'Krea' - const current = engine === 'krea' ? 'Krea' : 'Flux' - return `${loraDisplayName(name)} is a ${other} LoRA and cannot be used with ${current}.` + const labels = { flux: 'Flux', krea: 'Krea', moss: 'MOSS-Image' } as const + const tagged = imageLoraEngineOf(name) + const other = tagged ? labels[tagged] : 'other' + return `${loraDisplayName(name)} is a ${other} LoRA and cannot be used with ${labels[engine]}.` } export function kleinLoraOnKreaMessage(name: string) { @@ -305,6 +307,7 @@ export function inferLoraUse(name: string): LoraUse[] | null { if (/ltx/.test(value)) uses.push('ltx') if (/klein|flux/.test(value)) uses.push('flux') if (/krea/.test(value)) uses.push('krea') + if (/moss/.test(value)) uses.push('moss') if (/qwen/.test(value)) uses.push('qwen21') return uses.length ? uses : null } @@ -317,14 +320,12 @@ export function isQwenImageLora(name: string) { export function loraMatchesUse(name: string, use: LoraUse) { if (isSystemGraphLora(name)) return false - if (use === 'moss') return false if (use === 'qwen21') return isQwenImageLora(name) return !!inferLoraUse(name)?.includes(use) } /** Saved stacks may contain unlabelled adapters; never carry a known wrong engine. */ export function filterLoraStackForUse(stack: unknown, use: LoraUse, xaigen: boolean) { - if (use === 'moss') return [] if (use === 'ltx' && !xaigen) return [] return filterLoraStackForStudio(stack, xaigen).filter(item => { if (isSystemGraphLora(item.name)) return false