Filter LoRA picker options by engine tokens

This commit is contained in:
Towsty
2026-09-12 20:17:58 -05:00
parent e190496eb4
commit 6a6931f04e
2 changed files with 23 additions and 14 deletions
+4 -1
View File
@@ -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<string, string>
aliases?: Record<string, string>
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' }))
})
+19 -13
View File
@@ -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) {