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, loraFriendlyName,
loraIdentityKey, loraIdentityKey,
loraMatchesImageEngine, loraMatchesImageEngine,
loraMatchesUse,
type LoraUse,
loraTriggerFor, loraTriggerFor,
makeLoraStackItem, makeLoraStackItem,
type LoraStackItem type LoraStackItem
@@ -130,6 +132,7 @@ const props = withDefaults(defineProps<{
triggers?: Record<string, string> triggers?: Record<string, string>
aliases?: Record<string, string> aliases?: Record<string, string>
engine?: 'flux' | 'krea' | '' engine?: 'flux' | 'krea' | ''
use?: LoraUse
}>(), { }>(), {
label: 'LoRA', label: 'LoRA',
filenameSubtitle: false, filenameSubtitle: false,
@@ -159,7 +162,7 @@ const availableNames = computed(() => {
const engine = props.engine === 'flux' || props.engine === 'krea' ? props.engine : null const engine = props.engine === 'flux' || props.engine === 'krea' ? props.engine : null
return props.names return props.names
.filter(name => !taken.has(loraIdentityKey(name))) .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() .slice()
.sort((a, b) => labelFor(a).localeCompare(labelFor(b), undefined, { sensitivity: 'base' })) .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) { export function isXaigenOnlyLora(name: string) {
const base = loraBasename(name) const base = loraBasename(name)
// Include the common `xiagen-` typo so those files stay off AIGen too. // 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. */ /** 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 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 { export function inferLoraUse(name: string): LoraUse[] | null {
const imageEngine = imageLoraEngineOf(name) const value = String(name || '').toLowerCase()
if (imageEngine) return [imageEngine] const uses: LoraUse[] = []
const id = loraIdentityKey(name) if (/minimax/.test(value)) uses.push('minimax')
if (/(^|[_-])ltx([_-]|$)|ltx-2/i.test(id)) return ['ltx'] if (/ltx/.test(value)) uses.push('ltx')
if (/minimax|h3_fl2v|fl2v_turbo/i.test(id)) return ['minimax'] if (/klein|flux/.test(value)) uses.push('flux')
return null if (/krea/.test(value)) uses.push('krea')
return uses.length ? uses : null
} }
export function loraMatchesUse(name: string, use: LoraUse) { export function loraMatchesUse(name: string, use: LoraUse) {
if (isSystemGraphLora(name)) return false return !isSystemGraphLora(name) && !!inferLoraUse(name)?.includes(use)
if (use === 'flux' || use === 'krea') return imageLoraEngineOf(name) === use }
const inferred = inferLoraUse(name)
if (!inferred) return true /** Saved stacks may contain unlabelled adapters; never carry a known wrong engine. */
return inferred.includes(use) 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) { export function filterLorasForUse(names: string[], use: LoraUse) {