From 6a6931f04e6e9eef45290df0d00de2bb0f096f8e Mon Sep 17 00:00:00 2001 From: Towsty Date: Sat, 12 Sep 2026 20:17:58 -0500 Subject: [PATCH] Filter LoRA picker options by engine tokens --- components/LoraSelect.vue | 5 ++++- utils/loras.ts | 32 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/components/LoraSelect.vue b/components/LoraSelect.vue index 9ac0c0e..a6e1576 100644 --- a/components/LoraSelect.vue +++ b/components/LoraSelect.vue @@ -112,6 +112,8 @@ import { loraFriendlyName, loraIdentityKey, loraMatchesImageEngine, + loraMatchesUse, + type LoraUse, loraTriggerFor, makeLoraStackItem, type LoraStackItem @@ -130,6 +132,7 @@ const props = withDefaults(defineProps<{ triggers?: Record aliases?: Record engine?: 'flux' | 'krea' | '' + use?: LoraUse }>(), { label: 'LoRA', filenameSubtitle: false, @@ -159,7 +162,7 @@ const availableNames = computed(() => { const engine = props.engine === 'flux' || props.engine === 'krea' ? props.engine : null return props.names .filter(name => !taken.has(loraIdentityKey(name))) - .filter(name => !engine || loraMatchesImageEngine(name, engine)) + .filter(name => props.use ? loraMatchesUse(name, props.use) : !engine || loraMatchesImageEngine(name, engine)) .slice() .sort((a, b) => labelFor(a).localeCompare(labelFor(b), undefined, { sensitivity: 'base' })) }) diff --git a/utils/loras.ts b/utils/loras.ts index 2e0b9a5..412164f 100644 --- a/utils/loras.ts +++ b/utils/loras.ts @@ -32,7 +32,7 @@ export function loraIdentityKey(name: string) { export function isXaigenOnlyLora(name: string) { const base = loraBasename(name) // Include the common `xiagen-` typo so those files stay off AIGen too. - return /^(xai|xia)gen/i.test(base) || /klein_snofs|snofs_krea/i.test(base) + return String(name || '').replace(/\\/g, '/').split('/').some(part => /^(xai|xia)gen/i.test(part)) || /klein_snofs|snofs_krea/i.test(base) } /** Pick the real Comfy filename: exact path, then same basename ignoring `xaigen-`, then suffix/contains. */ @@ -293,22 +293,28 @@ export function isSystemGraphLora(name: string) { return false } -/** Filename hints. `null` means the LoRA can appear in any picker. */ +/** Engine tokens in paths or basenames; unlabelled files are not picker options. */ export function inferLoraUse(name: string): LoraUse[] | null { - const imageEngine = imageLoraEngineOf(name) - if (imageEngine) return [imageEngine] - const id = loraIdentityKey(name) - if (/(^|[_-])ltx([_-]|$)|ltx-2/i.test(id)) return ['ltx'] - if (/minimax|h3_fl2v|fl2v_turbo/i.test(id)) return ['minimax'] - return null + const value = String(name || '').toLowerCase() + const uses: LoraUse[] = [] + if (/minimax/.test(value)) uses.push('minimax') + if (/ltx/.test(value)) uses.push('ltx') + if (/klein|flux/.test(value)) uses.push('flux') + if (/krea/.test(value)) uses.push('krea') + return uses.length ? uses : null } export function loraMatchesUse(name: string, use: LoraUse) { - if (isSystemGraphLora(name)) return false - if (use === 'flux' || use === 'krea') return imageLoraEngineOf(name) === use - const inferred = inferLoraUse(name) - if (!inferred) return true - return inferred.includes(use) + return !isSystemGraphLora(name) && !!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 === 'ltx' && !xaigen) return [] + return filterLoraStackForStudio(stack, xaigen).filter(item => { + const uses = inferLoraUse(item.name) + return !isSystemGraphLora(item.name) && (!uses || uses.includes(use)) + }) } export function filterLorasForUse(names: string[], use: LoraUse) {