diff --git a/Assets/assistent.js b/Assets/assistent.js index 5f1272b..da7152e 100644 --- a/Assets/assistent.js +++ b/Assets/assistent.js @@ -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() { try { - const model = getCurrentModel && getCurrentModel(); - if (!model) { - return false; - } - const arch = `${model.architecture || ''} ${model.title || ''} ${model.name || ''} ${model.class || ''}`; - return /krea\s*2|krea2/i.test(arch) || /krea/i.test(arch); + const m = resolveCurrentCheckpoint(); + const blob = [ + m.architecture, + m.compat_class, + m.title, + m.name, + m.class, + ].join(' '); + return looksLikeKrea(blob); } catch (e) { return false; } @@ -48,6 +115,20 @@ const layout = $('sa_layout'); if (gate) { 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 Krea 2 models only. Current: ${escapeHtml( + seen, + )} — pick a checkpoint with architecture krea-2.` + : 'Swarm Assistent is for Krea 2 models only. Select a Krea 2 checkpoint on Generate to enable the chat.'; + } + } } if (layout) { layout.classList.toggle('sa-disabled', !ok); @@ -55,6 +136,14 @@ return ok; } + function escapeHtml(s) { + return String(s) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"'); + } + function val(id) { const el = document.getElementById(id); return el ? el.value : ''; @@ -175,11 +264,11 @@ }; try { - const model = getCurrentModel && getCurrentModel(); - if (model) { + const model = resolveCurrentCheckpoint(); + if (model.name || model.architecture) { ctx.checkpoint = { 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, }; } @@ -857,6 +946,8 @@ clearVisionImage, openAssistentTab, sendToAssistent: (src) => setImageFromSrc(src, { switchTab: true, note: 'Image sent to Assistent' }), + isKreaSelected, + resolveCurrentCheckpoint, }; }