Left Sidebar Layout
<body class="wiki-layout"> <header>{{:header|core}}</header> <aside id="sidebar-left"> {{:sidebar|core}} </aside> <article>{{_main|titled;title:_R}}</article> <aside id="sidebar-right">{{*sidebar_right|core}}</aside> <footer>{{:footer|core}}</footer> <script> (function () { function slugify(s) { return (s || "").toString().trim().toLowerCase() .replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""); } function buildInlineToc() { var article = document.querySelector("article"); if (!article) return; if (article.querySelector(".wiki-inline-toc")) return; // idempotent var headings = article.querySelectorAll("h2, h3"); if (!headings.length) return; var toc = document.createElement("nav"); toc.className = "wiki-inline-toc"; toc.setAttribute("aria-label", "On this page"); var heading = document.createElement("p"); heading.className = "wiki-inline-toc-heading"; heading.textContent = "On this page"; toc.appendChild(heading); var ul = document.createElement("ul"); ul.className = "wiki-inline-toc-list"; headings.forEach(function (h) { if (!h.id) h.id = slugify(h.textContent); var li = document.createElement("li"); li.className = "wiki-inline-toc-" + h.tagName.toLowerCase(); var a = document.createElement("a"); a.href = "#" + h.id; a.textContent = (h.textContent || "").trim(); li.appendChild(a); ul.appendChild(li); }); toc.appendChild(ul); var h1 = article.querySelector(":scope > div > .d0-card-header, :scope > .d0-card-header"); if (h1 && h1.parentNode) { h1.parentNode.insertBefore(toc, h1.nextSibling); } else { article.insertBefore(toc, article.firstChild); } } function buildBreadcrumb() { var article = document.querySelector("article"); if (!article) return; if (article.querySelector(".wiki-page-breadcrumb")) return; // idempotent var slot = article.querySelector("#main > [data-card-name]"); if (!slot) return; var _typeName = slot.getAttribute("data-card-type-name"); var _leaf = (slot.getAttribute("data-card-name") || "").split("+").pop(); var _isFull = / Full$/.test(_leaf); var _isDD = / Deep Dive$/.test(_leaf); if (_typeName !== "IndexSubtopic" && !_isFull && !_isDD) return; var name = slot.getAttribute("data-card-name") || ""; var linkName = slot.getAttribute("data-card-link-name") || ""; var parts = name.split("+"); var linkParts = linkName.split("+"); if (parts.length < 2 || linkParts.length < 2) return; var bc = document.createElement("p"); bc.className = "wiki-page-breadcrumb"; var a = document.createElement("a"); a.href = "/" + linkParts[0]; a.textContent = parts[0]; bc.appendChild(a); var _lastPart = parts[parts.length - 1]; var _currentLabel = _isFull ? _lastPart.replace(/ Full$/, "") : (_isDD ? _lastPart.replace(/ Deep Dive$/, "") : _lastPart); if (_isFull) { var _titleSpan = slot.querySelector(":scope > .d0-card-header .card-title"); if (_titleSpan) { _titleSpan.textContent = _currentLabel; _titleSpan.setAttribute("title", _currentLabel); } } if (!((_isFull || _isDD) && _currentLabel === parts[0])) bc.appendChild(document.createTextNode(" / " + _currentLabel)); var header = slot.querySelector(":scope > .d0-card-header"); if (header && header.parentNode) { header.parentNode.insertBefore(bc, header); } else { slot.insertBefore(bc, slot.firstChild); } } function setupExamplesToggle() { var blocks = document.querySelectorAll(".card-slot.TYPE_PLUS_RIGHT-index_subtopic-example"); blocks.forEach(function (block) { if (block.dataset.examplesProcessed) return; block.dataset.examplesProcessed = "1"; var examples = block.querySelectorAll(":scope > .card-slot.TYPE-rich_text"); if (examples.length < 2) return; var n = examples.length - 1; var collapsedLabel = "▾ Read more (" + n + " more example" + (n > 1 ? "s" : "") + ")"; var expandedLabel = "▴ Show less"; for (var i = 1; i < examples.length; i++) { examples[i].classList.add("wiki-example-hidden"); } var toggle = document.createElement("button"); toggle.type = "button"; toggle.className = "wiki-example-toggle"; toggle.textContent = collapsedLabel; var expanded = false; toggle.addEventListener("click", function () { expanded = !expanded; for (var j = 1; j < examples.length; j++) { examples[j].classList.toggle("wiki-example-hidden", !expanded); } toggle.textContent = expanded ? expandedLabel : collapsedLabel; }); block.appendChild(toggle); }); } function setupCodePlayground() { var run = document.getElementById("metta-run"); var reset = document.getElementById("metta-reset"); var code = document.getElementById("metta-code"); var output = document.getElementById("metta-output"); var outputText = document.getElementById("metta-output-text"); if (!run || !code || run.dataset.bound) return; run.dataset.bound = "1"; var initial = code.value; var endpoint = (typeof window !== "undefined" && window.MAGI_PLAYGROUND_URL) || "/api/playground/run"; function clearError() { outputText.classList.remove("hyperon-rc-output-error"); } function markError() { outputText.classList.add("hyperon-rc-output-error"); } function renderEnvelope(env) { var hasOk = !!(env.output || env.stdout); var hasErr = !!env.stderr; var parts = []; if (env.output) parts.push(env.output); if (env.stdout) parts.push(env.stdout); if (hasErr) parts.push(env.stderr); outputText.textContent = parts.join("\n\n") || "(no output)"; if (hasErr && !hasOk) markError(); else clearError(); output.hidden = false; } function stubFallback() { var lines = code.value.split("\n").filter(function (l) { return l.trim().indexOf("!") === 0; }); var results = lines.map(function (line) { if (line.indexOf("greet World") >= 0) return "[(Hello World welcome to Hyperon!)]"; if (line.indexOf("match") >= 0 && line.indexOf("Human") >= 0) return "[Alice, Bob]"; return "[Result of " + line.replace(/^\s*!/, "").trim() + "]"; }); outputText.textContent = results.length ? results.join("\n") : "(no ! queries to evaluate)"; clearError(); output.hidden = false; } run.addEventListener("click", function () { run.disabled = true; outputText.textContent = "(running…)"; clearError(); output.hidden = false; var done = function () { run.disabled = false; }; fetch(endpoint, { method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" }, body: JSON.stringify({ code: code.value }) }).then(function (r) { if (!r.ok) throw new Error("HTTP " + r.status); return r.json(); }).then(function (env) { renderEnvelope(env); done(); }).catch(function (err) { if (typeof console !== "undefined" && console.warn) { console.warn("playground backend unavailable; using stub fallback:", err); } stubFallback(); done(); }); }); if (reset) { reset.addEventListener("click", function () { code.value = initial; output.hidden = true; clearError(); }); } } function setupWikiChat() { var send = document.getElementById("chat-send"); var input = document.getElementById("chat-input"); var messages = document.getElementById("chat-messages"); if (!send || !input || send.dataset.bound) return; send.dataset.bound = "1"; var chatUrl = (typeof window !== "undefined" && window.MAGI_ASSISTANT_URL) || "/api/assistant/chat"; var history = []; var canned = [ { match: /\bmetta\b/i, reply: "MeTTa is the native \"language of thought\" for AGI — a programming language unifying functional, logic, and dependent typing over a dynamic knowledge metagraph (Atomspace)." }, { match: /\bhyperon\b/i, reply: "Hyperon is SingularityNET's AGI technology stack, building on decades of cognitive-architecture research." }, { match: /\bpln\b/i, reply: "PLN (Probabilistic Logic Networks) is Hyperon's reasoning-under-uncertainty algorithm. See /Hyperon_AI_Algorithms+PLN_(Probabilistic_Logic_Networks)" }, { match: /\becan\b/i, reply: "ECAN (Economic Attention Networks) manages limited computational resources via attention allocation. See /Hyperon_AI_Algorithms+ECAN_(Economic_Attention_Networks)" }, { match: /\bmork\b/i, reply: "MORK is the high-performance triemap substrate for Hyperon. See /Knowledge_Representations+MORK_(MeTTa_Optimized_Reduction_Kernel)" }, { match: /\bdas\b/i, reply: "DAS (Distributed AtomSpace) is the distributed knowledge backend. See /Knowledge_Representations+DAS_(Distributed_AtomSpace)" }, { match: /\bpetta\b/i, reply: "PeTTa is a high-performance Prolog-based MeTTa runtime by Patrick Hammer. See /MeTTa_Programming_Language+PeTTa" }, { match: /\bprimus\b/i, reply: "PRIMUS is the cognitive architecture that wires Hyperon's modules into a unified AGI system. See /Cognitive_Architecture_&_Research+PRIMUS_(formerly_CogPrime)" } ]; var defaultFallback = "I can't reach the assistant right now. For deeper questions, try ASI Create — https://create.singularitynet.io/"; function findCanned(q) { for (var i = 0; i < canned.length; i++) { if (canned[i].match.test(q)) return canned[i].reply; } return defaultFallback; } function clearEmpty() { var empty = messages.querySelector(".hyperon-rc-empty"); if (empty) empty.remove(); } function addUserMessage(text) { clearEmpty(); var div = document.createElement("div"); div.className = "hyperon-rc-msg hyperon-rc-msg-user"; div.textContent = text; messages.appendChild(div); messages.scrollTop = messages.scrollHeight; } function addAssistantBubble() { clearEmpty(); var div = document.createElement("div"); div.className = "hyperon-rc-msg hyperon-rc-msg-assistant"; messages.appendChild(div); messages.scrollTop = messages.scrollHeight; return div; } function addToolPill(bubble, name) { if (bubble.querySelector(".hyperon-rc-tool-pill")) return; var pill = document.createElement("span"); pill.className = "hyperon-rc-tool-pill"; pill.textContent = "(searching the wiki…)"; if (name) pill.dataset.tool = name; bubble.appendChild(pill); messages.scrollTop = messages.scrollHeight; } function clearToolPills(bubble) { var pills = bubble.querySelectorAll(".hyperon-rc-tool-pill"); for (var i = 0; i < pills.length; i++) pills[i].remove(); } function safeUrl(u) { if (!u) return null; if (/^https?:\/\//i.test(u)) return u; if (u.charAt(0) === "/" && u.charAt(1) !== "/") return u; return null; } function renderInline(node, text) { var re = /(\*\*([^*]+)\*\*)|(`([^`]+)`)|(\[([^\]]+)\]\(([^)]+)\))/g; var last = 0; var m; while ((m = re.exec(text)) !== null) { if (m.index > last) node.appendChild(document.createTextNode(text.slice(last, m.index))); if (m[2]) { var b = document.createElement("strong"); b.textContent = m[2]; node.appendChild(b); } else if (m[4]) { var c = document.createElement("code"); c.textContent = m[4]; node.appendChild(c); } else if (m[6]) { var url = safeUrl(m[7]); if (url) { var a = document.createElement("a"); a.href = url; a.textContent = m[6]; if (/^https?:\/\//i.test(url)) { a.target = "_blank"; a.rel = "noopener noreferrer"; } node.appendChild(a); } else { node.appendChild(document.createTextNode(m[6])); } } last = re.lastIndex; } if (last < text.length) node.appendChild(document.createTextNode(text.slice(last))); } function renderMarkdownLight(bubble, text) { bubble.textContent = ""; var paras = text.split(/\n\n+/); for (var i = 0; i < paras.length; i++) { var p = document.createElement("p"); var lines = paras[i].split(/\n/); for (var j = 0; j < lines.length; j++) { if (j > 0) p.appendChild(document.createElement("br")); renderInline(p, lines[j]); } bubble.appendChild(p); } } function parseSse(reader, bubble, onDelta) { var decoder = new TextDecoder(); var buf = ""; var full = ""; function processEvent(chunk) { var lines = chunk.split(/\n/); var dataParts = []; for (var i = 0; i < lines.length; i++) { var line = lines[i]; if (line.indexOf("data:") === 0) dataParts.push(line.slice(5).replace(/^ /, "")); } if (!dataParts.length) return; var payload; try { payload = JSON.parse(dataParts.join("\n")); } catch (e) { return; } if (payload.type === "delta" && typeof payload.text === "string") { full += payload.text; onDelta(payload.text, full); } else if (payload.type === "tool_use") { addToolPill(bubble, payload.name); } } function pump() { return reader.read().then(function (r) { if (r.done) { if (buf.trim()) processEvent(buf); return full; } buf += decoder.decode(r.value, { stream: true }); var idx; while ((idx = buf.indexOf("\n\n")) !== -1) { var chunk = buf.slice(0, idx); buf = buf.slice(idx + 2); processEvent(chunk); } return pump(); }); } return pump(); } function doSend() { var q = input.value.trim(); if (!q) return; addUserMessage(q); input.value = ""; history.push({ role: "user", content: q }); var bubble = addAssistantBubble(); function onDelta(piece) { clearToolPills(bubble); bubble.appendChild(document.createTextNode(piece)); messages.scrollTop = messages.scrollHeight; } function showFallback(err) { if (window.console && err) console.warn("[wiki-assistant] fallback:", err); bubble.textContent = ""; renderMarkdownLight(bubble, findCanned(q)); } var hasFetchStream = (typeof window !== "undefined" && typeof window.fetch === "function" && typeof window.ReadableStream === "function"); if (!hasFetchStream) { showFallback("no fetch/stream"); return; } var body = JSON.stringify({ messages: history, model: "claude-sonnet-4-6" }); window.fetch(chatUrl, { method: "POST", headers: { "Content-Type": "application/json", "Accept": "text/event-stream" }, body: body, credentials: "same-origin" }).then(function (resp) { if (!resp.ok || !resp.body) throw new Error("HTTP " + resp.status); return parseSse(resp.body.getReader(), bubble, onDelta); }).then(function (finalText) { clearToolPills(bubble); if (finalText && finalText.trim()) { renderMarkdownLight(bubble, finalText); history.push({ role: "assistant", content: finalText }); } else { showFallback("empty stream"); } }).catch(function (err) { showFallback(err && err.message ? err.message : String(err)); }); } send.addEventListener("click", doSend); input.addEventListener("keydown", function (e) { if (e.key === "Enter") { e.preventDefault(); doSend(); } }); } function setupLinkTooltips() { var article = document.querySelector("article"); if (!article || article.dataset.tooltipsBound) return; article.dataset.tooltipsBound = "1"; var cache = {}; // href -> body html ("" means "no tooltip") var tip = null; // floating popover element (lazy) var showTimer = null; // 150ms hover-intent timer var hideTimer = null; // 200ms grace timer var currentHref = null; function ensureTip() { if (tip) return tip; tip = document.createElement("div"); tip.className = "wiki-tooltip"; tip.setAttribute("role", "tooltip"); tip.style.position = "fixed"; tip.style.display = "none"; tip.addEventListener("mouseenter", function () { if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } }); tip.addEventListener("mouseleave", scheduleHide); document.body.appendChild(tip); return tip; } function hideNow() { if (tip) tip.style.display = "none"; currentHref = null; } function scheduleHide() { if (hideTimer) clearTimeout(hideTimer); hideTimer = setTimeout(hideNow, 200); } function positionTip(target) { var t = ensureTip(); var rect = target.getBoundingClientRect(); // measure off-screen t.style.visibility = "hidden"; t.style.display = "block"; var th = t.offsetHeight, tw = t.offsetWidth; var spaceBelow = window.innerHeight - rect.bottom; var spaceAbove = rect.top; // Default above (Anna feedback #21); flip below only when there isn't // enough room above and there's more room below. var side = "above"; if (spaceAbove < th + 12 && spaceBelow > spaceAbove) { side = "below"; } var top = side === "above" ? rect.top - th - 8 : rect.bottom + 8; var left = rect.left; var maxLeft = window.innerWidth - tw - 8; if (left > maxLeft) left = maxLeft; if (left < 8) left = 8; t.style.top = Math.round(top) + "px"; t.style.left = Math.round(left) + "px"; t.dataset.side = side; t.style.visibility = "visible"; } function fetchBody(href) { if (Object.prototype.hasOwnProperty.call(cache, href)) { return Promise.resolve(cache[href]); } var url = href + (href.indexOf("?") >= 0 ? "&" : "?") + "view=tooltip&format=html&layout=none"; return window.fetch(url, { credentials: "same-origin" }).then(function (r) { return r.ok ? r.text() : ""; }).then(function (html) { var clean = (html || "").trim(); cache[href] = clean; return clean; }).catch(function () { cache[href] = ""; return ""; }); } function show(target) { var href = target.getAttribute("href") || target.getAttribute("data-href"); if (!href) return; currentHref = href; fetchBody(href).then(function (html) { if (currentHref !== href) return; // cursor moved on before fetch resolved if (!html) return; // I-5: no description -> no tooltip var t = ensureTip(); t.innerHTML = html; positionTip(target); }); } // Delegated hover handling, scoped to article prose (I-7). article.addEventListener("mouseover", function (e) { var a = e.target.closest && e.target.closest("a.known-card, .wiki-glossary-term"); if (!a || !article.contains(a)) return; var href = a.getAttribute("href") || a.getAttribute("data-href"); if (!href || href.charAt(0) !== "/") return; // internal card links only if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } if (showTimer) clearTimeout(showTimer); showTimer = setTimeout(function () { show(a); }, 150); }); article.addEventListener("mouseout", function (e) { var a = e.target.closest && e.target.closest("a.known-card, .wiki-glossary-term"); if (!a) return; var to = e.relatedTarget; if (to && a.contains(to)) return; // still inside the same anchor if (showTimer) { clearTimeout(showTimer); showTimer = null; } scheduleHide(); }); } function setupGlossaryHighlight() { var article = document.querySelector("article"); if (!article || article.dataset.glossaryBound) return; var main = article.querySelector("#main"); if (!main) return; if (location.pathname.replace(/\/$/, "") === "/Glossary") return; article.dataset.glossaryBound = "1"; function loadTerms() { try { var c = sessionStorage.getItem("wikiGlossaryTerms"); if (c) return Promise.resolve(JSON.parse(c)); } catch (e) {} return window.fetch("/Glossary", { credentials: "same-origin" }) .then(function (r) { return r.ok ? r.text() : ""; }) .then(function (html) { var doc = new DOMParser().parseFromString(html, "text/html"); var map = {}, links = doc.querySelectorAll("li strong a[href^='/']"); for (var i = 0; i < links.length; i++) { var term = (links[i].textContent || "").trim(), href = links[i].getAttribute("href"); if (term && href && term.length >= 3 && !map[term]) map[term] = href; } try { sessionStorage.setItem("wikiGlossaryTerms", JSON.stringify(map)); } catch (e) {} return map; }).catch(function () { return {}; }); } loadTerms().then(function (map) { var terms = Object.keys(map); if (!terms.length) return; terms.sort(function (a, b) { return b.length - a.length; }); var here = location.pathname, lc = {}; for (var i = 0; i < terms.length; i++) lc[terms[i].toLowerCase()] = terms[i]; function esc(s) { return s.replace(/[.*+?^${}()|[]/g, "\\$&"); } var re = new RegExp("\\b(" + terms.map(esc).join("|") + ")\\b", "gi"); var SKIP = { A:1, H1:1, H2:1, H3:1, H4:1, H5:1, H6:1, CODE:1, PRE:1, SCRIPT:1, STYLE:1, BUTTON:1, TEXTAREA:1 }; function inSkip(node) { var el = node.parentNode; while (el && el !== main && el.nodeType === 1) { if (SKIP[el.tagName]) return true; var cl = (typeof el.className === "string") ? el.className : ""; if (cl.indexOf("wiki-page-breadcrumb") >= 0 || cl.indexOf("wiki-page-tags") >= 0 || cl.indexOf("wiki-glossary-term") >= 0 || cl.indexOf("wiki-tooltip") >= 0 || cl.indexOf("card-menu") >= 0) return true; el = el.parentNode; } return false; } var done = {}, walker = document.createTreeWalker(main, NodeFilter.SHOW_TEXT, null), nodes = [], nn; while ((nn = walker.nextNode())) { if (nn.nodeValue && nn.nodeValue.length >= 3 && !inSkip(nn)) nodes.push(nn); } for (var ni = 0; ni < nodes.length; ni++) { var node = nodes[ni]; if (!node.parentNode) continue; var text = node.nodeValue, m, frag = null, last = 0; re.lastIndex = 0; while ((m = re.exec(text))) { var word = m[1], canon = lc[word.toLowerCase()]; if (!canon || done[canon]) continue; if (map[canon] === here) { done[canon] = true; continue; } done[canon] = true; if (!frag) frag = document.createDocumentFragment(); if (m.index > last) frag.appendChild(document.createTextNode(text.slice(last, m.index))); var span = document.createElement("span"); span.className = "wiki-glossary-term"; span.setAttribute("data-href", map[canon]); span.textContent = word; frag.appendChild(span); last = m.index + word.length; } if (frag) { if (last < text.length) frag.appendChild(document.createTextNode(text.slice(last))); node.parentNode.replaceChild(frag, node); } } }); } function setupTocAnchors() { var main = document.querySelector("article #main"); if (!main || main.dataset.tocAnchorsBound) return; main.dataset.tocAnchorsBound = "1"; var headings = main.querySelectorAll("h2, h3, h4"), byText = {}; for (var i = 0; i < headings.length; i++) { var key = (headings[i].textContent || "").trim().toLowerCase(); if (key && !byText[key]) byText[key] = headings[i]; } var anchors = main.querySelectorAll('a[href^="#"]'); for (var j = 0; j < anchors.length; j++) { var frag = (anchors[j].getAttribute("href") || "").slice(1); if (!frag) continue; var t = (anchors[j].textContent || "").trim().toLowerCase(); var h = byText[t]; if (h && !h.id) h.id = frag; } } function setupPlaygroundToggle() { var pg = document.querySelector(".hyperon-rc-playground"); var btn = document.getElementById("metta-toggle"); if (!pg || !btn || btn.dataset.bound) return; btn.dataset.bound = "1"; try { if (sessionStorage.getItem("mettaPgOpen") === "1") pg.classList.remove("collapsed"); } catch (e) {} function sync() { var open = !pg.classList.contains("collapsed"); btn.textContent = open ? "▾" : "▸"; btn.setAttribute("aria-expanded", open ? "true" : "false"); } sync(); btn.addEventListener("click", function () { pg.classList.toggle("collapsed"); var open = !pg.classList.contains("collapsed"); try { sessionStorage.setItem("mettaPgOpen", open ? "1" : "0"); } catch (e) {} sync(); }); } function buildAll() { [buildBreadcrumb, setupExamplesToggle, setupCodePlayground, setupWikiChat, setupLinkTooltips, setupGlossaryHighlight, setupTocAnchors, setupPlaygroundToggle].forEach(function (f) { try { f(); } catch (e) { if (window.console && console.error) console.error("buildAll step failed:", e); } }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", buildAll); } else { buildAll(); } })(); </script> </body>