Spaces:
Paused
Paused
Add API log panel for debugging generation requests
Browse files- Added collapsible API log panel below preview
- Logs all API calls with method, URL, status code
- Shows error details when requests fail
- Wraps fetch to automatically capture all API activity
- Helps debug cancelled/failed generations
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
277 unmodified lines278279280281282283782 unmodified lines106610671068106910701071396 unmodified lines146814691470147114721473277 unmodified lines.preview-placeholder svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 12px; }.generating-overlay {position: absolute;inset: 0;782 unmodified lines<p style="font-size:12px; margin-top:4px">Write a prompt and click Generate</p></div></div></div></div></div>396 unmodified lineslet trainCaptions = {}; // filename -> caption textlet selectedTrainBackend = 'local';let runpodAvailable = false;let galleryImages = [];let currentLightboxIndex = -1;let galleryOffset = 0;277 unmodified lines278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321782 unmodified lines11041105110611071108110911101111111211131114111511161117111811191120396 unmodified lines15171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602277 unmodified lines.preview-placeholder svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 12px; }.api-log-panel {border-top: 1px solid var(--border);background: var(--bg-primary);}.api-log-header {display: flex;justify-content: space-between;align-items: center;padding: 8px 12px;cursor: pointer;font-size: 12px;color: var(--text-secondary);user-select: none;}.api-log-header:hover { background: var(--bg-hover); }.api-log-content {max-height: 200px;overflow-y: auto;padding: 8px 12px;font-family: 'Consolas', 'Monaco', monospace;font-size: 11px;}.api-log-entry {padding: 4px 0;border-bottom: 1px solid var(--border);line-height: 1.4;}.api-log-entry:last-child { border-bottom: none; }.api-log-time { color: var(--text-secondary); margin-right: 8px; }.api-log-method { font-weight: 600; margin-right: 4px; }.api-log-method.POST { color: var(--green); }.api-log-method.GET { color: var(--blue); }.api-log-url { color: var(--text-primary); }.api-log-status { margin-left: 8px; font-weight: 600; }.api-log-status.ok { color: var(--green); }.api-log-status.error { color: var(--red); }.api-log-detail { color: var(--text-secondary); margin-top: 2px; padding-left: 60px; word-break: break-all; }.generating-overlay {position: absolute;inset: 0;782 unmodified lines<p style="font-size:12px; margin-top:4px">Write a prompt and click Generate</p></div></div><!-- API Log Panel --><div class="api-log-panel"><div class="api-log-header" onclick="toggleApiLog()"><span>API Log</span><svg id="api-log-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:16px;height:16px;transition:transform 0.2s"><polyline points="6 9 12 15 18 9"/></svg></div><div id="api-log-content" class="api-log-content" style="display:none"><div id="api-log-entries"></div><button onclick="clearApiLog()" style="margin-top:8px;padding:4px 8px;font-size:11px;background:var(--bg-hover);border:1px solid var(--border);border-radius:4px;color:var(--text-secondary);cursor:pointer">Clear Log</button></div></div></div></div></div>396 unmodified lineslet trainCaptions = {}; // filename -> caption textlet selectedTrainBackend = 'local';let runpodAvailable = false;let apiLogs = [];const MAX_API_LOGS = 50;// --- API Logging ---function logApi(method, url, status, detail = null) {const now = new Date();const time = now.toLocaleTimeString('en-US', { hour12: false });apiLogs.unshift({ time, method, url, status, detail });if (apiLogs.length > MAX_API_LOGS) apiLogs.pop();renderApiLog();}function renderApiLog() {const container = document.getElementById('api-log-entries');if (!container) return;container.innerHTML = apiLogs.map(log => `<div class="api-log-entry"><span class="api-log-time">${log.time}</span><span class="api-log-method ${log.method}">${log.method}</span><span class="api-log-url">${log.url}</span><span class="api-log-status ${log.status >= 200 && log.status < 300 ? 'ok' : 'error'}">${log.status}</span>${log.detail ? `<div class="api-log-detail">${log.detail}</div>` : ''}</div>`).join('');}function toggleApiLog() {const content = document.getElementById('api-log-content');const chevron = document.getElementById('api-log-chevron');if (content.style.display === 'none') {content.style.display = '';chevron.style.transform = 'rotate(180deg)';} else {content.style.display = 'none';chevron.style.transform = '';}}function clearApiLog() {apiLogs = [];renderApiLog();}// Wrap fetch to log API callsconst originalFetch = window.fetch;window.fetch = async function(url, options = {}) {const method = options.method || 'GET';const urlStr = typeof url === 'string' ? url : url.toString();// Only log API calls, not static resourcesif (!urlStr.includes('/api/')) {return originalFetch.apply(this, arguments);}const shortUrl = urlStr.replace(API, '').split('?')[0];try {const response = await originalFetch.apply(this, arguments);const status = response.status;// Clone response to read body for error detailsif (!response.ok) {try {const clone = response.clone();const data = await clone.json();const detail = data.detail || data.error || JSON.stringify(data).substring(0, 100);logApi(method, shortUrl, status, detail);} catch {logApi(method, shortUrl, status, 'Failed to parse error');}} else {logApi(method, shortUrl, status);}return response;} catch (error) {logApi(method, shortUrl, 'ERR', error.message);throw error;}};let galleryImages = [];let currentLightboxIndex = -1;let galleryOffset = 0;
src/content_engine/api/ui.html+129