Fix Assistent Krea gate for modern SwarmUI currentModelHelper.
getCurrentModel() no longer exists, so the gate stayed locked after selecting a checkpoint. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+100
-9
@@ -29,14 +29,81 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function looksLikeKrea(text) {
|
||||||
|
const s = String(text || '');
|
||||||
|
return /krea\s*2|krea2|krea-2/i.test(s) || /krea/i.test(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolve current checkpoint from modern SwarmUI APIs (getCurrentModel is gone). */
|
||||||
|
function resolveCurrentCheckpoint() {
|
||||||
|
const out = {
|
||||||
|
name: null,
|
||||||
|
architecture: null,
|
||||||
|
compat_class: null,
|
||||||
|
title: null,
|
||||||
|
class: null,
|
||||||
|
source: null,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
if (typeof currentModelHelper !== 'undefined' && currentModelHelper) {
|
||||||
|
out.name = currentModelHelper.curModel || null;
|
||||||
|
out.architecture = currentModelHelper.curArch || null;
|
||||||
|
out.compat_class = currentModelHelper.curCompatClass || null;
|
||||||
|
out.source = 'currentModelHelper';
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof getCurrentModel === 'function') {
|
||||||
|
const model = getCurrentModel();
|
||||||
|
if (model) {
|
||||||
|
out.name = out.name || model.name || null;
|
||||||
|
out.title = model.title || null;
|
||||||
|
out.architecture = out.architecture || model.architecture || null;
|
||||||
|
out.class = model.class || null;
|
||||||
|
out.compat_class = out.compat_class || model.compat_class || null;
|
||||||
|
out.source = out.source || 'getCurrentModel';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const sel =
|
||||||
|
document.getElementById('current_model') ||
|
||||||
|
document.getElementById('input_model');
|
||||||
|
if (sel) {
|
||||||
|
const opt = sel.selectedOptions && sel.selectedOptions[0];
|
||||||
|
const hint = [
|
||||||
|
sel.value,
|
||||||
|
opt && opt.text,
|
||||||
|
opt && opt.dataset && opt.dataset.cleanname,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ');
|
||||||
|
if (!out.name && sel.value) {
|
||||||
|
out.name = sel.value;
|
||||||
|
out.source = out.source || 'dropdown';
|
||||||
|
}
|
||||||
|
if (hint && !out.architecture) {
|
||||||
|
out.title = out.title || hint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
function isKreaSelected() {
|
function isKreaSelected() {
|
||||||
try {
|
try {
|
||||||
const model = getCurrentModel && getCurrentModel();
|
const m = resolveCurrentCheckpoint();
|
||||||
if (!model) {
|
const blob = [
|
||||||
return false;
|
m.architecture,
|
||||||
}
|
m.compat_class,
|
||||||
const arch = `${model.architecture || ''} ${model.title || ''} ${model.name || ''} ${model.class || ''}`;
|
m.title,
|
||||||
return /krea\s*2|krea2/i.test(arch) || /krea/i.test(arch);
|
m.name,
|
||||||
|
m.class,
|
||||||
|
].join(' ');
|
||||||
|
return looksLikeKrea(blob);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -48,6 +115,20 @@
|
|||||||
const layout = $('sa_layout');
|
const layout = $('sa_layout');
|
||||||
if (gate) {
|
if (gate) {
|
||||||
gate.hidden = ok;
|
gate.hidden = ok;
|
||||||
|
if (!ok) {
|
||||||
|
const m = resolveCurrentCheckpoint();
|
||||||
|
const seen = [m.architecture, m.compat_class, m.name]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · ');
|
||||||
|
const p = gate.querySelector('p');
|
||||||
|
if (p) {
|
||||||
|
p.innerHTML = seen
|
||||||
|
? `Swarm Assistent is for <strong>Krea 2</strong> models only. Current: <code>${escapeHtml(
|
||||||
|
seen,
|
||||||
|
)}</code> — pick a checkpoint with architecture <code>krea-2</code>.`
|
||||||
|
: 'Swarm Assistent is for <strong>Krea 2</strong> models only. Select a Krea 2 checkpoint on Generate to enable the chat.';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (layout) {
|
if (layout) {
|
||||||
layout.classList.toggle('sa-disabled', !ok);
|
layout.classList.toggle('sa-disabled', !ok);
|
||||||
@@ -55,6 +136,14 @@
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(s) {
|
||||||
|
return String(s)
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"');
|
||||||
|
}
|
||||||
|
|
||||||
function val(id) {
|
function val(id) {
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
return el ? el.value : '';
|
return el ? el.value : '';
|
||||||
@@ -175,11 +264,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const model = getCurrentModel && getCurrentModel();
|
const model = resolveCurrentCheckpoint();
|
||||||
if (model) {
|
if (model.name || model.architecture) {
|
||||||
ctx.checkpoint = {
|
ctx.checkpoint = {
|
||||||
name: model.name || model.title || null,
|
name: model.name || model.title || null,
|
||||||
architecture: model.architecture || model.class || null,
|
architecture: model.architecture || model.compat_class || model.class || null,
|
||||||
title: model.title || null,
|
title: model.title || null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -857,6 +946,8 @@
|
|||||||
clearVisionImage,
|
clearVisionImage,
|
||||||
openAssistentTab,
|
openAssistentTab,
|
||||||
sendToAssistent: (src) => setImageFromSrc(src, { switchTab: true, note: 'Image sent to Assistent' }),
|
sendToAssistent: (src) => setImageFromSrc(src, { switchTab: true, note: 'Image sent to Assistent' }),
|
||||||
|
isKreaSelected,
|
||||||
|
resolveCurrentCheckpoint,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user