Keep library deletes when a still file is locked, and match LoRAs by engine folder.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+49
-9
@@ -29,10 +29,36 @@ export function loraIdentityKey(name: string) {
|
||||
return loraBasename(name).replace(/^(xai|xia)gen-?/i, '').toLowerCase()
|
||||
}
|
||||
|
||||
function loraSegments(name: string) {
|
||||
return String(name || '').replace(/\\/g, '/').split('/').filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Engine directory immediately under `xaigen/`, `xiagen/`, or `aigen/`.
|
||||
* `aigen/` stays visible on AIGen. Only `xaigen` / `xiagen` are xAIGen-only.
|
||||
*/
|
||||
function loraEngineFolder(name: string): 'flux' | 'krea' | 'moss' | 'minimax' | 'ltx' | 'qwen21' | null {
|
||||
const parts = loraSegments(name)
|
||||
for (let i = 0; i < parts.length - 1; i += 1) {
|
||||
if (!/^(?:xaigen|xiagen|aigen)$/i.test(parts[i])) continue
|
||||
if (/\.(safetensors|sft|ckpt|pt|bin)$/i.test(parts[i + 1])) continue
|
||||
const next = parts[i + 1].toLowerCase()
|
||||
if (next === 'flux' || next === 'klein') return 'flux'
|
||||
if (next === 'krea') return 'krea'
|
||||
if (next === 'moss') return 'moss'
|
||||
if (next === 'minimax') return 'minimax'
|
||||
if (next === 'ltx') return 'ltx'
|
||||
if (next === 'qwen' || next === 'qwen21' || next === 'qwen2') return 'qwen21'
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function isXaigenOnlyLora(name: string) {
|
||||
const base = loraBasename(name)
|
||||
// Include the common `xiagen-` typo so those files stay off AIGen too.
|
||||
return String(name || '').replace(/\\/g, '/').split('/').some(part => /^(xai|xia)gen/i.test(part)) || /klein_snofs|snofs_krea/i.test(base)
|
||||
const parts = loraSegments(name)
|
||||
const base = parts[parts.length - 1] || ''
|
||||
// `aigen` is the AIGen tree. `xaigen` / `xiagen` (typo) and filename prefixes stay xAIGen-only.
|
||||
if (parts.some(part => /^(xai|xia)gen/i.test(part))) return true
|
||||
return /klein_snofs|snofs_krea/i.test(base)
|
||||
}
|
||||
|
||||
/** Pick the real Comfy filename: exact path, then same basename ignoring `xaigen-`, then suffix/contains. */
|
||||
@@ -237,11 +263,8 @@ function hasImageEngineToken(source: string, engine: 'flux' | 'krea' | 'moss') {
|
||||
return new RegExp(`(?:^|[/_.-])${token}`).test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' | 'moss' | null {
|
||||
/** Filename / path-token fallback for flat files that have not moved into an engine folder. */
|
||||
function imageLoraEngineFromTokens(name: string): 'flux' | 'krea' | 'moss' | null {
|
||||
const raw = String(name || '')
|
||||
const base = loraBasename(raw)
|
||||
const id = loraIdentityKey(raw)
|
||||
@@ -266,6 +289,17 @@ export function imageLoraEngineOf(name: string): 'flux' | 'krea' | 'moss' | null
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer the engine folder directly under `xaigen/` or `aigen/`.
|
||||
* Flat `krea-…` / `flux-…` filenames still match through the token fallback.
|
||||
*/
|
||||
export function imageLoraEngineOf(name: string): 'flux' | 'krea' | 'moss' | null {
|
||||
const folder = loraEngineFolder(name)
|
||||
if (folder === 'flux' || folder === 'krea' || folder === 'moss') return folder
|
||||
if (folder) return null
|
||||
return imageLoraEngineFromTokens(name)
|
||||
}
|
||||
|
||||
export function loraMatchesImageEngine(name: string, engine: 'flux' | 'krea' | 'moss') {
|
||||
return imageLoraEngineOf(name) === engine
|
||||
}
|
||||
@@ -299,8 +333,10 @@ export function isSystemGraphLora(name: string) {
|
||||
return false
|
||||
}
|
||||
|
||||
/** Engine tokens in paths or basenames; unlabelled files are not picker options. */
|
||||
/** Engine folder under xaigen/ or aigen/ wins. Otherwise tokens in paths or basenames. */
|
||||
export function inferLoraUse(name: string): LoraUse[] | null {
|
||||
const folder = loraEngineFolder(name)
|
||||
if (folder) return [folder]
|
||||
const value = String(name || '').toLowerCase()
|
||||
const uses: LoraUse[] = []
|
||||
if (/minimax/.test(value)) uses.push('minimax')
|
||||
@@ -320,6 +356,8 @@ export function isQwenImageLora(name: string) {
|
||||
|
||||
export function loraMatchesUse(name: string, use: LoraUse) {
|
||||
if (isSystemGraphLora(name)) return false
|
||||
const folder = loraEngineFolder(name)
|
||||
if (folder) return folder === use
|
||||
if (use === 'qwen21') return isQwenImageLora(name)
|
||||
return !!inferLoraUse(name)?.includes(use)
|
||||
}
|
||||
@@ -329,6 +367,8 @@ export function filterLoraStackForUse(stack: unknown, use: LoraUse, xaigen: bool
|
||||
if (use === 'ltx' && !xaigen) return []
|
||||
return filterLoraStackForStudio(stack, xaigen).filter(item => {
|
||||
if (isSystemGraphLora(item.name)) return false
|
||||
const folder = loraEngineFolder(item.name)
|
||||
if (folder) return folder === use
|
||||
if (use === 'qwen21') return isQwenImageLora(item.name)
|
||||
const uses = inferLoraUse(item.name)
|
||||
return !uses || uses.includes(use)
|
||||
|
||||
Reference in New Issue
Block a user