Upload static/shared/js/max-native-page-wiring.js with huggingface_hub
Browse files19 unmodified lines2021222324253 unmodified lines29303132333435363738394012 unmodified lines5354555657585911 unmodified lines7172737475767778798045 unmodified lines1261271281291301311321331341351361371381391401411 unmodified line14314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419 unmodified lines'diagnostics': 'service-health'};function pageId() {const parts = location.pathname.split('/').filter(Boolean);return MENU_PAGE_ALIASES[parts[0]] || parts[0] || 'dashboard';3 unmodified linesreturn pageId() === 'dashboard';}function ensureStyle() {if (document.getElementById('max-native-page-style')) return;const style = document.createElement('style');style.id = 'max-native-page-style';style.textContent = `.max-native-page{max-width:1180px;margin:18px auto;padding:18px;border:1px solid rgba(99,102,241,.22);border-radius:22px;background:linear-gradient(135deg,rgba(255,255,255,.94),rgba(238,242,255,.82));box-shadow:0 22px 55px rgba(15,23,42,.12);font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#0f172a;}.max-native-page__head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:14px;}.max-native-page__title{font-size:15px;font-weight:900;letter-spacing:.01em;display:flex;gap:8px;align-items:center;}.max-native-page__sub{font-size:11px;color:#64748b;margin-top:4px;line-height:1.45;}12 unmodified lines.max-native-page__item{padding:7px 8px;border-radius:10px;background:#fff;border:1px solid #e2e8f0;}.max-native-page__error{margin-top:10px;color:#991b1b;background:#fef2f2;border:1px solid #fecaca;border-radius:12px;padding:9px 10px;font-size:12px;font-weight:800;}@keyframes maxNativePulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.45;transform:scale(.82)}}@media(max-width:900px){.max-native-page__grid{grid-template-columns:repeat(2,minmax(0,1fr));}.max-native-page{margin:12px;padding:14px}}@media(max-width:560px){.max-native-page__grid,.max-native-page__list{grid-template-columns:1fr}.max-native-page__head{flex-direction:column}}`;document.head.appendChild(style);11 unmodified lines}}function mountTarget() {return document.querySelector('[data-page-root], main, .main-content, .content, .container, #app, body');}function fmt(value) {if (value === null || value === undefined || value === '') return '—';if (typeof value === 'number') return Number.isFinite(value) ? value.toLocaleString(undefined, { maximumFractionDigits: 4 }) : '—';45 unmodified linesreturn metrics.slice(0, 3);}function render(payload) {ensureStyle();if (document.getElementById('max-native-page')) return;const id = pageId();const contract = payload.contract || {};const [mainValue, mainLabel] = primaryMetric(id, payload);const metrics = secondaryMetrics(id, payload);const el = document.createElement('section');el.id = 'max-native-page';el.className = 'max-native-page';const links = [contract.native_endpoint || `/api/max/pages/native/${id}`,'/api/max/app/capabilities',1 unmodified line'/api/max/fallback/plan','/api/max/pressure/status'];el.innerHTML = `<div class="max-native-page__head"><div><div class="max-native-page__title">🧠 Native Service Wiring <span class="max-native-page__pill"><span class="max-native-page__dot"></span>${contract.title || id}</span></div><div class="max-native-page__sub">This page now receives a page-specific payload from the maximum-provider API layer, so the main app can consume the same services through stable endpoints.</div></div><span class="max-native-page__pill">/api/max/pages/native/${id}</span></div><div class="max-native-page__grid"><div class="max-native-page__card"><div class="max-native-page__label">${mainLabel}</div><div class="max-native-page__value small">${fmt(mainValue)}</div></div>${metrics.map(([label, value]) => `<div class="max-native-page__card"><div class="max-native-page__label">${label}</div><div class="max-native-page__value small">${fmt(value)}</div></div>`).join('')}</div><div class="max-native-page__section"><h4>Main-app service contract</h4><div class="max-native-page__list"><div class="max-native-page__item"><strong>Purpose:</strong> ${contract.main_app_service || 'real data service'}</div><div class="max-native-page__item"><strong>Primary APIs:</strong> ${(contract.primary_apis || []).join(', ') || '—'}</div><div class="max-native-page__item"><strong>Data state:</strong> ${fmt((((payload.payload || {}).bundle || {}).data_state) || payload.data_state || 'connected')}</div><div class="max-native-page__item"><strong>Bridge:</strong> native + shared fallback bridge</div></div><div class="max-native-page__links">${links.map(url => `<a href="${url}" target="_blank" rel="noreferrer">${url}</a>`).join('')}</div></div>`;const mount = mountTarget();const first = mount && mount.firstElementChild;if (mount && mount !== document.body && first) mount.insertBefore(el, first.nextSibling || null);else document.body.insertBefore(el, document.body.firstChild);}async function boot() {if (shouldSkip()) return;const id = pageId();try {const payload = await fetchJson(`/api/max/pages/native/${encodeURIComponent(id)}?symbol=BTC`, 26000);window.MAX_NATIVE_PAGE_STATE = payload;render(payload);} catch (error) {ensureStyle();const el = document.createElement('section');el.id = 'max-native-page';el.className = 'max-native-page';el.innerHTML = `<div class="max-native-page__title">Native Service Wiring</div><div class="max-native-page__error">Native payload failed: ${String(error && error.message || error)}</div>`;document.body.insertBefore(el, document.body.firstChild);}}if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);else boot();})();19 unmodified lines202122232425262728293 unmodified lines33343536373839404142434445464748495051525354555612 unmodified lines6970717273747511 unmodified lines87888990919245 unmodified lines1381391401411421431441451461471481491501511521531541551561571581 unmodified line16016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622719 unmodified lines'diagnostics': 'service-health'};function panel() {return window.TopServicePanel;}function pageId() {const parts = location.pathname.split('/').filter(Boolean);return MENU_PAGE_ALIASES[parts[0]] || parts[0] || 'dashboard';3 unmodified linesreturn pageId() === 'dashboard';}function refreshSummary(nativeText) {const tsp = panel();if (!tsp) return;window._topServiceSummary = window._topServiceSummary || {};if (nativeText) window._topServiceSummary.native = nativeText;tsp.setSummary(tsp.buildSummary([`Page: ${pageId()}`,window._topServiceSummary.bridge,window._topServiceSummary.native]));}function ensureStyle() {if (document.getElementById('max-native-page-style')) return;const style = document.createElement('style');style.id = 'max-native-page-style';style.textContent = `.max-native-page{padding:18px;border:1px solid rgba(99,102,241,.22);border-radius:22px;background:linear-gradient(135deg,rgba(255,255,255,.94),rgba(238,242,255,.82));font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#0f172a;}.max-native-page__head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:14px;}.max-native-page__title{font-size:15px;font-weight:900;letter-spacing:.01em;display:flex;gap:8px;align-items:center;}.max-native-page__sub{font-size:11px;color:#64748b;margin-top:4px;line-height:1.45;}12 unmodified lines.max-native-page__item{padding:7px 8px;border-radius:10px;background:#fff;border:1px solid #e2e8f0;}.max-native-page__error{margin-top:10px;color:#991b1b;background:#fef2f2;border:1px solid #fecaca;border-radius:12px;padding:9px 10px;font-size:12px;font-weight:800;}@keyframes maxNativePulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.45;transform:scale(.82)}}@media(max-width:900px){.max-native-page__grid{grid-template-columns:repeat(2,minmax(0,1fr));}.max-native-page{padding:14px}}@media(max-width:560px){.max-native-page__grid,.max-native-page__list{grid-template-columns:1fr}.max-native-page__head{flex-direction:column}}`;document.head.appendChild(style);11 unmodified lines}}function fmt(value) {if (value === null || value === undefined || value === '') return '—';if (typeof value === 'number') return Number.isFinite(value) ? value.toLocaleString(undefined, { maximumFractionDigits: 4 }) : '—';45 unmodified linesreturn metrics.slice(0, 3);}function renderIntoPanel(html, summaryText) {ensureStyle();const tsp = panel();if (!tsp) return;tsp.ensure();tsp.mountSection('max-native-page-section', '', html);refreshSummary(summaryText);}function render(payload) {if (document.getElementById('max-native-page-section')) return;const id = pageId();const contract = payload.contract || {};const [mainValue, mainLabel] = primaryMetric(id, payload);const metrics = secondaryMetrics(id, payload);const links = [contract.native_endpoint || `/api/max/pages/native/${id}`,'/api/max/app/capabilities',1 unmodified line'/api/max/fallback/plan','/api/max/pressure/status'];const html = `<section id="max-native-page" class="max-native-page"><div class="max-native-page__head"><div><div class="max-native-page__title">🧠 Native Service Wiring <span class="max-native-page__pill"><span class="max-native-page__dot"></span>${contract.title || id}</span></div><div class="max-native-page__sub">Page-specific payload from the maximum-provider API layer for stable main-app endpoints.</div></div><span class="max-native-page__pill">/api/max/pages/native/${id}</span></div><div class="max-native-page__grid"><div class="max-native-page__card"><div class="max-native-page__label">${mainLabel}</div><div class="max-native-page__value small">${fmt(mainValue)}</div></div>${metrics.map(([label, value]) => `<div class="max-native-page__card"><div class="max-native-page__label">${label}</div><div class="max-native-page__value small">${fmt(value)}</div></div>`).join('')}</div><div class="max-native-page__section"><h4>Main-app service contract</h4><div class="max-native-page__list"><div class="max-native-page__item"><strong>Purpose:</strong> ${contract.main_app_service || 'real data service'}</div><div class="max-native-page__item"><strong>Primary APIs:</strong> ${(contract.primary_apis || []).join(', ') || '—'}</div><div class="max-native-page__item"><strong>Data state:</strong> ${fmt((((payload.payload || {}).bundle || {}).data_state) || payload.data_state || 'connected')}</div><div class="max-native-page__item"><strong>Bridge:</strong> native + shared fallback bridge</div></div><div class="max-native-page__links">${links.map(url => `<a href="${url}" target="_blank" rel="noreferrer">${url}</a>`).join('')}</div></div></section>`;renderIntoPanel(html, `${mainLabel}: ${fmt(mainValue)}`);}function renderError(error) {const html = `<section id="max-native-page" class="max-native-page"><div class="max-native-page__title">Native Service Wiring</div><div class="max-native-page__error">Native payload failed: ${String(error && error.message || error)}</div></section>`;renderIntoPanel(html, 'Native payload unavailable');}async function boot() {const tsp = panel();if (!tsp || shouldSkip()) return;tsp.ensure(`Page: ${pageId()} · Loading…`);const id = pageId();try {const payload = await fetchJson(`/api/max/pages/native/${encodeURIComponent(id)}?symbol=BTC`, 26000);window.MAX_NATIVE_PAGE_STATE = payload;render(payload);} catch (error) {renderError(error);}}function start() {if (!window.TopServicePanel) {console.warn('TopServicePanel not loaded; native wiring panel skipped');return;}boot();}if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);else start();})();
static/shared/js/max-native-page-wiring.js+77-44