1// compare/probe.js â model probe/check system 2import state from './state.js'; 3import { WAVE_FRAMES } from './icons.js'; 4import uiModule from '../ui.js'; 5import spinnerModule from '../spinner.js'; 6 7function _clearProbeWaves() { 8 const rows = document.querySelectorAll('.compare-probe-row'); 9 rows.forEach(r => { if (r._waveInterval) { clearInterval(r._waveInterval); r._waveInterval = null; } }); 10} 11 12async function _checkUnprobed() { 13 const unprobed = state._selectedModels.filter(m => !state._probed.has(m.model)); 14 if (unprobed.length === 0) { 15 if (uiModule) uiModule.showToast('All models verified'); 16 return; 17 } 18 19 // Whirlpool loader on the Probe button while the check runs. 20 const _btn = document.getElementById('compare-check-btn'); 21 let _btnHTML = null, _wp = null; 22 if (_btn) { 23 _btnHTML = _btn.innerHTML; 24 _btn.disabled = true; 25 _btn.style.opacity = '0.7'; 26 try { 27 _wp = spinnerModule.createWhirlpool(14); 28 _btn.innerHTML = ''; 29 _btn.appendChild(_wp.element); 30 } catch (_) { /* spinner best-effort */ } 31 } 32 33 // Quick inline probe â show toast with results 34 const isBlind = state._blindMode; 35 let ok = 0, fail = 0; 36 try { 37 for (const m of unprobed) { 38 try { 39 const _imageModelPrefixes = ['dall-e', 'gpt-image', 'chatgpt-image', 'stable-diffusion', 'sdxl', 'flux', 'midjourney']; 40 if (_imageModelPrefixes.some(p => m.model.toLowerCase().includes(p))) { 41 state._probed.add(m.model); 42 ok++; 43 continue; 44 } 45 const res = await fetch(`${state.API_BASE}/api/probe-selected`, { 46 method: 'POST', credentials: 'same-origin', 47 headers: { 'Content-Type': 'application/json' }, 48 body: JSON.stringify({ models: [{ endpoint_id: m.endpointId || '', model: m.model, endpoint: m.endpoint || '' }] }), 49 }); 50 const data = await res.json(); 51 const result = (data.results || [])[0]; 52 if (result && result.status === 'ok') { 53 state._probed.add(m.model); 54 ok++; 55 } else { 56 fail++; 57 const name = isBlind ? 'a model' : (m.name || m.model.split('/').pop()); 58 if (uiModule) uiModule.showToast(`${name} failed: ${result?.error || 'unknown'}`, 5000); 59 } 60 } catch (e) { 61 fail++; 62 } 63 } 64 if (fail === 0) { 65 if (uiModule) uiModule.showToast(`${ok} model${ok > 1 ? 's' : ''} verified`); 66 } 67 } finally { 68 // Restore the Probe button (its label/visibility is refreshed below). 69 if (_btn) { 70 _btn.disabled = false; 71 _btn.style.opacity = ''; 72 if (_btnHTML !== null) _btn.innerHTML = _btnHTML; 73 } 74 if (window._updateCheckBtnState) window._updateCheckBtnState(); 75 } 76} 77 78export { _clearProbeWaves, _checkUnprobed };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.