Spaces:
Running
Running
deploy(hf): sync szl-holdings/a11oy@main derived COPY set
Browse filesReusable Dockerfile-COPY-derived deploy from szl-holdings/a11oy main.
Files: 936 Pruned: 0
Derived from Dockerfile COPY sources (NO hand-maintained allowlist).
Signed-off-by: SZL Holdings <noreply@szlholdings.ai>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- static/3d/holographic.html +1 -0
- static/3d/surfaces/governedrag.js +427 -0
static/3d/holographic.html
CHANGED
|
@@ -175,6 +175,7 @@ const SURFACES = [
|
|
| 175 |
{ id: "supplychain", title: "Model-Artifact Provenance (SLSA / in-toto / Rekor / C2PA)", mod: "/static/3d/surfaces/supplychain.js" },
|
| 176 |
{ id: "hybridssm", title: "HybridSSM · Attention vs State-Space vs Hybrid Frontier (synthesis)", mod: "/static/3d/surfaces/hybridssm.js" },
|
| 177 |
{ id: "governedagent", title: "Governed Agent Loop · plan→act→self-eval→gate→retry", mod: "/static/3d/surfaces/governedagent.js" },
|
|
|
|
| 178 |
];
|
| 179 |
|
| 180 |
const stageEl = document.getElementById("stage");
|
|
|
|
| 175 |
{ id: "supplychain", title: "Model-Artifact Provenance (SLSA / in-toto / Rekor / C2PA)", mod: "/static/3d/surfaces/supplychain.js" },
|
| 176 |
{ id: "hybridssm", title: "HybridSSM · Attention vs State-Space vs Hybrid Frontier (synthesis)", mod: "/static/3d/surfaces/hybridssm.js" },
|
| 177 |
{ id: "governedagent", title: "Governed Agent Loop · plan→act→self-eval→gate→retry", mod: "/static/3d/surfaces/governedagent.js" },
|
| 178 |
+
{ id: "governedrag", title: "Governed RAG · Retrieval-with-Receipts", mod: "/static/3d/surfaces/governedrag.js" },
|
| 179 |
];
|
| 180 |
|
| 181 |
const stageEl = document.getElementById("stage");
|
static/3d/surfaces/governedrag.js
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. Jr. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/governedrag.js — GOVERNED RAG · retrieval-with-receipts holographic surface (Wave J · Dev 4).
|
| 5 |
+
//
|
| 6 |
+
// The differentiator, rendered live: EVERY retrieved answer ships a SIGNED receipt
|
| 7 |
+
// proving WHICH source passages grounded WHICH claims. RAG systems retrieve and
|
| 8 |
+
// generate; almost none emit a machine-checkable, signed per-claim attribution
|
| 9 |
+
// gated on a faithfulness score. That governance layer is what SZL adds on top
|
| 10 |
+
// of the retrieval SOTA.
|
| 11 |
+
//
|
| 12 |
+
// Leaders studied + composed (citable, non-leaked): dense retrieval DPR
|
| 13 |
+
// (arxiv 2004.04906), hybrid BM25+dense with reciprocal-rank fusion, ColBERT
|
| 14 |
+
// late-interaction (arxiv 2004.12832), cross-encoder rerankers (Cohere Rerank),
|
| 15 |
+
// GraphRAG (Microsoft), Anthropic contextual retrieval, citation-grounded
|
| 16 |
+
// generation / ALCE (arxiv 2305.14627), and RAGAS reference-free eval
|
| 17 |
+
// (arxiv 2309.15217). SZL's governed version folds them into ONE deterministic,
|
| 18 |
+
// honest pipeline with a Λ-gate + signed per-claim receipt.
|
| 19 |
+
//
|
| 20 |
+
// EVERY value on screen traces to a REAL a11oy endpoint (doctrine v11 — never fabricate):
|
| 21 |
+
// * GET /api/a11oy/v1/rag/corpus — the embedded demo corpus (id/text/source) + sha256
|
| 22 |
+
// * POST /api/a11oy/v1/rag/query — Λ-gated grounded answer → per-claim citations →
|
| 23 |
+
// signed receipt → /llm/forum (the demo)
|
| 24 |
+
//
|
| 25 |
+
// The scene: a ring of CORPUS-PASSAGE nodes around a central QUERY core; when a
|
| 26 |
+
// query fires, grounding BEAMS light from the passages that grounded each claim to
|
| 27 |
+
// the core (color = grounded/ungrounded), and a floating RECEIPT panel shows the
|
| 28 |
+
// live signed per-claim citation map + RAGAS faithfulness + advisory Λ. Honesty
|
| 29 |
+
// labels are read straight from the JSON. Degrades gracefully; no crash, no fake data.
|
| 30 |
+
//
|
| 31 |
+
// 0 runtime CDN: three resolves through the page importmap to /static/3d/vendor/.
|
| 32 |
+
|
| 33 |
+
const ID = "governedrag";
|
| 34 |
+
const TITLE = "Governed RAG · Retrieval-with-Receipts";
|
| 35 |
+
const EP_CORPUS = "/api/a11oy/v1/rag/corpus";
|
| 36 |
+
const EP_QUERY = "/api/a11oy/v1/rag/query";
|
| 37 |
+
|
| 38 |
+
// palette (matches the estate)
|
| 39 |
+
const C_PASSAGE = 0x39d3c4; // corpus passage — teal
|
| 40 |
+
const C_GROUND = 0x2fd07a; // grounded citation beam — green
|
| 41 |
+
const C_UNGROUND = 0x8a6a3a; // ungrounded — dim gold
|
| 42 |
+
const C_CORE = 0xe8c074; // query core — gold
|
| 43 |
+
const C_BEAM = 0x6fb1ff; // retrieval beam — blue
|
| 44 |
+
|
| 45 |
+
let _stage = null, _THREE = null, _ctx = null;
|
| 46 |
+
let _group = null, _overlay = null, _frameReg = false;
|
| 47 |
+
let _passageNodes = []; // { mesh, label, id }
|
| 48 |
+
let _core = null, _beams = [], _billboard = null;
|
| 49 |
+
let _poll = null, _badge = null;
|
| 50 |
+
|
| 51 |
+
const S = {
|
| 52 |
+
corpus: [],
|
| 53 |
+
label: null, state: "init", degraded: false,
|
| 54 |
+
selectedModel: "", // optional; blank = extractive/MODELED (honest w/o key)
|
| 55 |
+
lastReceipt: null, lastAnswer: null, lastClaims: [], lastRagas: null,
|
| 56 |
+
queryState: "idle",
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
// =========================================================================================
|
| 60 |
+
// mount
|
| 61 |
+
// =========================================================================================
|
| 62 |
+
function mount(ctx) {
|
| 63 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 64 |
+
const THREE = _THREE;
|
| 65 |
+
_group = new THREE.Group();
|
| 66 |
+
_stage.scene.add(_group);
|
| 67 |
+
if (_stage.camera && _stage.camera.position) _stage.camera.position.set(0, 6, 18);
|
| 68 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 69 |
+
|
| 70 |
+
_buildCore();
|
| 71 |
+
try {
|
| 72 |
+
_billboard = ctx.label.billboard(THREE, "MODELED", { text: "retrieval-with-receipts · per-claim citations", scale: 0.6, position: [0, 6.4, 0] });
|
| 73 |
+
_group.add(_billboard);
|
| 74 |
+
} catch (_) {}
|
| 75 |
+
|
| 76 |
+
_buildOverlay();
|
| 77 |
+
|
| 78 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 79 |
+
|
| 80 |
+
// ---- LIVE WIRING (doctrine: every value traces to a real endpoint) ----
|
| 81 |
+
_poll = ctx.live.poll(EP_CORPUS, 12000, _onCorpus, {
|
| 82 |
+
badge: _badge,
|
| 83 |
+
onState: (m) => { S.state = m.state; S.label = m.label || S.label; if (m.state !== "live") _paintOverlay(); },
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
return { id: ID, started: true };
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// =========================================================================================
|
| 90 |
+
// scene builders
|
| 91 |
+
// =========================================================================================
|
| 92 |
+
function _buildCore() {
|
| 93 |
+
const THREE = _THREE;
|
| 94 |
+
_core = new THREE.Group();
|
| 95 |
+
const core = new THREE.Mesh(
|
| 96 |
+
new THREE.IcosahedronGeometry(1.3, 1),
|
| 97 |
+
new THREE.MeshStandardMaterial({ color: C_CORE, emissive: C_CORE, emissiveIntensity: 0.55, metalness: 0.4, roughness: 0.4, transparent: true, opacity: 0.92 }),
|
| 98 |
+
);
|
| 99 |
+
const shell = new THREE.Mesh(
|
| 100 |
+
new THREE.IcosahedronGeometry(1.7, 1),
|
| 101 |
+
new THREE.MeshBasicMaterial({ color: C_CORE, wireframe: true, transparent: true, opacity: 0.28 }),
|
| 102 |
+
);
|
| 103 |
+
_core.add(core, shell);
|
| 104 |
+
_core.core = core;
|
| 105 |
+
_group.add(_core);
|
| 106 |
+
try {
|
| 107 |
+
_core.lbl = _ctx.label.billboard(_THREE, "QUERY", { text: "grounded answer core", scale: 0.5, position: [0, -2.1, 0] });
|
| 108 |
+
_core.add(_core.lbl);
|
| 109 |
+
} catch (_) {}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
function _renderCorpusRing() {
|
| 113 |
+
const THREE = _THREE;
|
| 114 |
+
_passageNodes.forEach((n) => { try { _group.remove(n.mesh); } catch (_) {} try { if (n.label) _group.remove(n.label); } catch (_) {} });
|
| 115 |
+
_passageNodes = [];
|
| 116 |
+
|
| 117 |
+
const ps = S.corpus;
|
| 118 |
+
const R = 6.6;
|
| 119 |
+
ps.forEach((p, i) => {
|
| 120 |
+
const ang = (i / Math.max(ps.length, 1)) * Math.PI * 2;
|
| 121 |
+
const x = Math.cos(ang) * R, z = Math.sin(ang) * R;
|
| 122 |
+
const mesh = new THREE.Mesh(
|
| 123 |
+
new THREE.OctahedronGeometry(0.62, 0),
|
| 124 |
+
new THREE.MeshStandardMaterial({ color: C_PASSAGE, emissive: C_PASSAGE, emissiveIntensity: 0.5, metalness: 0.35, roughness: 0.45, transparent: true, opacity: 0.9 }),
|
| 125 |
+
);
|
| 126 |
+
mesh.position.set(x, 1.2 + (i % 2) * 0.4, z);
|
| 127 |
+
mesh.userData = { id: p.id };
|
| 128 |
+
_group.add(mesh);
|
| 129 |
+
let label = null;
|
| 130 |
+
try {
|
| 131 |
+
label = _ctx.label.billboard(_THREE, p.id, { text: (p.source || "").slice(0, 28), scale: 0.4, position: [x, 2.3 + (i % 2) * 0.4, z] });
|
| 132 |
+
_group.add(label);
|
| 133 |
+
} catch (_) {}
|
| 134 |
+
_passageNodes.push({ mesh, label, id: p.id });
|
| 135 |
+
});
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// =========================================================================================
|
| 139 |
+
// live-data handlers — read REAL values; never invent
|
| 140 |
+
// =========================================================================================
|
| 141 |
+
function _onCorpus(json, meta) {
|
| 142 |
+
S.degraded = !!meta.degraded;
|
| 143 |
+
S.label = meta.label || S.label;
|
| 144 |
+
if (!json || !Array.isArray(json.corpus)) { _paintOverlay(); return; }
|
| 145 |
+
S.corpus = json.corpus;
|
| 146 |
+
_renderCorpusRing();
|
| 147 |
+
_paintOverlay();
|
| 148 |
+
if (_billboard && _ctx) {
|
| 149 |
+
try {
|
| 150 |
+
_group.remove(_billboard);
|
| 151 |
+
_billboard = _ctx.label.billboard(_THREE, "MODELED", {
|
| 152 |
+
text: `corpus: ${json.corpus_size} passages · sha ${(json.corpus_sha256 || "").slice(0, 10)}…`, scale: 0.56, position: [0, 6.4, 0],
|
| 153 |
+
});
|
| 154 |
+
_group.add(_billboard);
|
| 155 |
+
} catch (_) {}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// POST query → grounded answer + per-claim citations + signed receipt (the demo)
|
| 160 |
+
async function _fireQuery() {
|
| 161 |
+
const q = (_el.query && _el.query.value || "").trim();
|
| 162 |
+
if (!q) { S.queryState = "empty query"; _paintOverlay(); return; }
|
| 163 |
+
S.queryState = "querying";
|
| 164 |
+
_paintOverlay();
|
| 165 |
+
try {
|
| 166 |
+
const bodyObj = { query: q, top_k: 4 };
|
| 167 |
+
if (S.selectedModel) bodyObj.model_id = S.selectedModel;
|
| 168 |
+
const res = await fetch(EP_QUERY, {
|
| 169 |
+
method: "POST",
|
| 170 |
+
headers: { "content-type": "application/json" },
|
| 171 |
+
body: JSON.stringify(bodyObj),
|
| 172 |
+
});
|
| 173 |
+
if (!res.ok) { S.queryState = "error(" + res.status + ")"; _paintOverlay(); return; }
|
| 174 |
+
const json = await res.json();
|
| 175 |
+
S.lastReceipt = json.rag_receipt || null;
|
| 176 |
+
S.lastAnswer = json.grounded_answer || null;
|
| 177 |
+
S.lastClaims = Array.isArray(json.claims) ? json.claims : [];
|
| 178 |
+
S.lastRagas = json.ragas || null;
|
| 179 |
+
S.queryState = json.rag_state || "done";
|
| 180 |
+
_fireGroundingBeams();
|
| 181 |
+
_paintOverlay();
|
| 182 |
+
_paintReceipt();
|
| 183 |
+
} catch (e) {
|
| 184 |
+
S.queryState = "error";
|
| 185 |
+
_paintOverlay();
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
// light beams from the passages that grounded each claim into the query core
|
| 190 |
+
function _fireGroundingBeams() {
|
| 191 |
+
_beams.forEach((b) => { try { _group.remove(b); } catch (_) {} });
|
| 192 |
+
_beams = [];
|
| 193 |
+
const THREE = _THREE;
|
| 194 |
+
const grounded = new Set();
|
| 195 |
+
S.lastClaims.forEach((c) => (c.citations || []).forEach((cit) => grounded.add(cit.passage_id)));
|
| 196 |
+
_passageNodes.forEach((n) => {
|
| 197 |
+
const isGround = grounded.has(n.id);
|
| 198 |
+
const from = n.mesh.position.clone();
|
| 199 |
+
const to = new THREE.Vector3(0, 1.2, 0);
|
| 200 |
+
const mid = from.clone().add(to).multiplyScalar(0.5);
|
| 201 |
+
const len = from.distanceTo(to);
|
| 202 |
+
const geo = new THREE.CylinderGeometry(0.03, 0.09, 1, 10, 1, true);
|
| 203 |
+
const mat = new THREE.MeshBasicMaterial({ color: isGround ? C_GROUND : C_BEAM, transparent: true, opacity: isGround ? 0.0 : 0.0, side: THREE.DoubleSide, depthWrite: false });
|
| 204 |
+
const beam = new THREE.Mesh(geo, mat);
|
| 205 |
+
beam.position.copy(mid);
|
| 206 |
+
beam.scale.set(1, len, 1);
|
| 207 |
+
beam.lookAt(to);
|
| 208 |
+
beam.rotateX(Math.PI / 2);
|
| 209 |
+
beam.userData = { t: 0, ground: isGround };
|
| 210 |
+
beam.visible = true;
|
| 211 |
+
_group.add(beam);
|
| 212 |
+
_beams.push(beam);
|
| 213 |
+
// brighten grounded passage nodes
|
| 214 |
+
try { n.mesh.material.emissiveIntensity = isGround ? 0.95 : 0.35; } catch (_) {}
|
| 215 |
+
});
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// =========================================================================================
|
| 219 |
+
// per-frame animation
|
| 220 |
+
// =========================================================================================
|
| 221 |
+
function _onFrame() {
|
| 222 |
+
if (_core && _core.core) {
|
| 223 |
+
_core.rotation.y += 0.004;
|
| 224 |
+
const s = 1 + 0.05 * Math.sin(performance.now() * 0.003);
|
| 225 |
+
_core.core.scale.setScalar(s);
|
| 226 |
+
}
|
| 227 |
+
_passageNodes.forEach((n, i) => { n.mesh.rotation.y += 0.008 + i * 0.0008; });
|
| 228 |
+
_beams.forEach((beam) => {
|
| 229 |
+
beam.userData.t = (beam.userData.t || 0) + 0.03;
|
| 230 |
+
const t = beam.userData.t;
|
| 231 |
+
const peak = beam.userData.ground ? 0.9 : 0.35;
|
| 232 |
+
beam.material.opacity = Math.max(0, peak * (1 - Math.abs(Math.sin(t))));
|
| 233 |
+
});
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
// =========================================================================================
|
| 237 |
+
// DOM overlay (HUD)
|
| 238 |
+
// =========================================================================================
|
| 239 |
+
let _el = {};
|
| 240 |
+
function _buildOverlay() {
|
| 241 |
+
const ctx = _ctx;
|
| 242 |
+
_overlay = document.createElement("div");
|
| 243 |
+
Object.assign(_overlay.style, {
|
| 244 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 245 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 246 |
+
maxWidth: "min(94%,470px)", font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial", color: "#eef3f6",
|
| 247 |
+
});
|
| 248 |
+
|
| 249 |
+
const h = document.createElement("div");
|
| 250 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 251 |
+
h.textContent = TITLE;
|
| 252 |
+
_overlay.appendChild(h);
|
| 253 |
+
|
| 254 |
+
const sub = document.createElement("div");
|
| 255 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.5";
|
| 256 |
+
sub.innerHTML = 'Deterministic <b>hybrid retrieval</b> (dense + BM25 → RRF → ' +
|
| 257 |
+
'ColBERT-style rerank) → <b>per-claim citations</b> → RAGAS faithfulness → ' +
|
| 258 |
+
'Λ-gate → a <span style="color:#2fd07a">SIGNED receipt</span> proving which ' +
|
| 259 |
+
'sources grounded which claims. Λ is <b>advisory</b> (Conjecture 1), never "green".';
|
| 260 |
+
_overlay.appendChild(sub);
|
| 261 |
+
|
| 262 |
+
_badge = ctx.live.createBadge();
|
| 263 |
+
const badgeRow = document.createElement("div");
|
| 264 |
+
badgeRow.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;align-items:center";
|
| 265 |
+
const tag = (t) => { const s = document.createElement("span"); s.textContent = t; s.style.cssText = "font:10px ui-monospace,monospace;color:#6fb1ff"; return s; };
|
| 266 |
+
badgeRow.appendChild(tag("corpus")); badgeRow.appendChild(_badge.el);
|
| 267 |
+
_overlay.appendChild(badgeRow);
|
| 268 |
+
|
| 269 |
+
// query demo controls
|
| 270 |
+
const ctl = document.createElement("div");
|
| 271 |
+
ctl.style.cssText = "display:flex;flex-direction:column;gap:6px;background:#0a1117;border:1px solid #1d2a36;border-radius:8px;padding:8px";
|
| 272 |
+
const cl = document.createElement("div");
|
| 273 |
+
cl.style.cssText = "font:600 11px ui-sans-serif;color:#e8c074"; cl.textContent = "governed RAG query (grounded answer + receipt)";
|
| 274 |
+
ctl.appendChild(cl);
|
| 275 |
+
|
| 276 |
+
_el.query = document.createElement("input");
|
| 277 |
+
_el.query.type = "text"; _el.query.value = "What is RAGAS and how does it measure faithfulness?";
|
| 278 |
+
_el.query.style.cssText = "background:#06090d;color:#eef3f6;border:1px solid #1d2a36;border-radius:6px;padding:6px;font:11px ui-sans-serif";
|
| 279 |
+
ctl.appendChild(_el.query);
|
| 280 |
+
|
| 281 |
+
_el.modelSel = document.createElement("select");
|
| 282 |
+
_el.modelSel.style.cssText = "background:#06090d;color:#eef3f6;border:1px solid #1d2a36;border-radius:6px;padding:5px;font:11px ui-monospace,monospace";
|
| 283 |
+
[["", "(extractive · honest, no model key)"], ["claude_opus_4_8", "claude_opus_4_8 (abstractive MODELED)"], ["gpt_5_5", "gpt_5_5 (abstractive MODELED)"]].forEach(([v, t]) => {
|
| 284 |
+
const o = document.createElement("option"); o.value = v; o.textContent = t; _el.modelSel.appendChild(o);
|
| 285 |
+
});
|
| 286 |
+
_el.modelSel.value = S.selectedModel;
|
| 287 |
+
_el.modelSel.addEventListener("change", () => { S.selectedModel = _el.modelSel.value; });
|
| 288 |
+
ctl.appendChild(_el.modelSel);
|
| 289 |
+
|
| 290 |
+
_el.queryBtn = document.createElement("button");
|
| 291 |
+
_el.queryBtn.textContent = "▶ query (retrieve + ground + Λ-gate + sign + forum)";
|
| 292 |
+
_el.queryBtn.style.cssText = "background:#12202b;color:#eef3f6;border:1px solid #39d3c4;border-radius:7px;padding:7px 10px;cursor:pointer;font:600 11px ui-monospace,monospace";
|
| 293 |
+
_el.queryBtn.addEventListener("click", _fireQuery);
|
| 294 |
+
ctl.appendChild(_el.queryBtn);
|
| 295 |
+
|
| 296 |
+
_el.queryState = document.createElement("div");
|
| 297 |
+
_el.queryState.style.cssText = "font:10.5px ui-monospace,monospace;color:#9fb1bf";
|
| 298 |
+
_el.queryState.textContent = "state: idle";
|
| 299 |
+
ctl.appendChild(_el.queryState);
|
| 300 |
+
_overlay.appendChild(ctl);
|
| 301 |
+
|
| 302 |
+
// grounded answer + per-claim citation panel
|
| 303 |
+
_el.answer = document.createElement("div");
|
| 304 |
+
_el.answer.style.cssText = "font:11px ui-sans-serif;color:#bfe;background:#06090d;border:1px solid #1d2a36;border-radius:7px;padding:8px;line-height:1.5";
|
| 305 |
+
_el.answer.textContent = "— run a query to see the grounded answer + per-claim citations —";
|
| 306 |
+
_overlay.appendChild(_el.answer);
|
| 307 |
+
|
| 308 |
+
// signed receipt panel
|
| 309 |
+
const det = document.createElement("details");
|
| 310 |
+
det.open = true;
|
| 311 |
+
const sum = document.createElement("summary");
|
| 312 |
+
sum.style.cssText = "cursor:pointer;color:#39d3c4;font:11px ui-monospace,monospace";
|
| 313 |
+
sum.textContent = "signed RAG receipt (szl.rag_query.receipt/v1)";
|
| 314 |
+
_el.receipt = document.createElement("div");
|
| 315 |
+
_el.receipt.style.cssText = "white-space:pre-wrap;font:10px ui-monospace,monospace;color:#bfe;background:#06090d;border:1px solid #1d2a36;border-radius:7px;padding:8px;max-height:230px;overflow:auto;margin-top:6px";
|
| 316 |
+
_el.receipt.textContent = "— run a query to see the live signed receipt —";
|
| 317 |
+
det.appendChild(sum); det.appendChild(_el.receipt);
|
| 318 |
+
_overlay.appendChild(det);
|
| 319 |
+
|
| 320 |
+
// honesty legend
|
| 321 |
+
const lg = ctx.label.legend(); lg.style.opacity = "0.85"; _overlay.appendChild(lg);
|
| 322 |
+
|
| 323 |
+
// sources (text only — NOT fetch-shaped, doctrine 0-CDN safe)
|
| 324 |
+
const src = document.createElement("div");
|
| 325 |
+
src.style.cssText = "font-size:9.5px;color:#5b6c78;line-height:1.6;margin-top:2px";
|
| 326 |
+
src.textContent = "Leaders studied + composed: DPR (arXiv:2004.04906) · BM25/RRF hybrid · ColBERT " +
|
| 327 |
+
"(arXiv:2004.12832) · Cohere Rerank cross-encoder · GraphRAG (Microsoft) · Anthropic contextual " +
|
| 328 |
+
"retrieval · citation-grounded generation ALCE (arXiv:2305.14627) · RAGAS reference-free eval " +
|
| 329 |
+
"(arXiv:2309.15217). SZL's governed version adds the layer none ship: a Λ-gated (Conjecture 1, " +
|
| 330 |
+
"never green) SIGNED per-claim receipt proving which sources grounded which claims. Retrieval + " +
|
| 331 |
+
"grounding + scoring + signing are REAL + deterministic; abstractive rewrite is MODELED (honest " +
|
| 332 |
+
"extractive answer with no model key). NOT in the locked-8; trust < 100%.";
|
| 333 |
+
_overlay.appendChild(src);
|
| 334 |
+
|
| 335 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
function _paintOverlay() {
|
| 339 |
+
if (_el.queryState) _el.queryState.textContent = "state: " + S.queryState +
|
| 340 |
+
(S.lastRagas ? " · faithfulness=" + S.lastRagas.faithfulness + " ctx-precision=" + S.lastRagas.context_precision : "");
|
| 341 |
+
if (_el.answer) {
|
| 342 |
+
if (!S.lastAnswer) {
|
| 343 |
+
_el.answer.textContent = S.corpus.length ? "— run a query to see the grounded answer + per-claim citations —" :
|
| 344 |
+
(S.state === "live" ? "corpus empty" : "awaiting live corpus (" + S.state + ")");
|
| 345 |
+
} else {
|
| 346 |
+
_el.answer.innerHTML = "";
|
| 347 |
+
const a = document.createElement("div");
|
| 348 |
+
a.style.cssText = "color:#eef3f6;margin-bottom:6px";
|
| 349 |
+
a.innerHTML = "<b style='color:#e8c074'>grounded answer:</b> " + _esc(S.lastAnswer);
|
| 350 |
+
_el.answer.appendChild(a);
|
| 351 |
+
S.lastClaims.forEach((c) => {
|
| 352 |
+
const row = document.createElement("div");
|
| 353 |
+
row.style.cssText = "border-top:1px solid #12202b;padding-top:5px;margin-top:5px;font-size:10.5px";
|
| 354 |
+
const cited = (c.citations || []).map((x) => x.passage_id + "(" + x.support + ")").join(", ") || "none";
|
| 355 |
+
const col = c.grounded ? "#2fd07a" : "#ff9b6b";
|
| 356 |
+
row.innerHTML = "<span style='color:" + col + "'>" + (c.grounded ? "✓ grounded" : "✗ ungrounded") +
|
| 357 |
+
"</span> — " + _esc(c.claim) + "<br><span style='color:#5b6c78'>grounded by: " + _esc(cited) + "</span>";
|
| 358 |
+
_el.answer.appendChild(row);
|
| 359 |
+
});
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
function _paintReceipt() {
|
| 365 |
+
if (!_el.receipt) return;
|
| 366 |
+
if (!S.lastReceipt) { _el.receipt.textContent = "— run a query to see the live signed receipt —"; return; }
|
| 367 |
+
const r = S.lastReceipt;
|
| 368 |
+
const sig = r.signature || {};
|
| 369 |
+
const gr = r.grounding || {};
|
| 370 |
+
const ra = r.ragas || {};
|
| 371 |
+
const lines = [
|
| 372 |
+
"schema : " + (r.schema || "?"),
|
| 373 |
+
"query : " + (r.query || ""),
|
| 374 |
+
"corpus : " + (r.corpus && r.corpus.origin) + " · size=" + (r.corpus && r.corpus.size),
|
| 375 |
+
"corpus sha256 : " + (r.corpus && r.corpus.sha256),
|
| 376 |
+
"retrieval : " + (r.retrieval && r.retrieval.method),
|
| 377 |
+
"retrieved ids : " + (r.retrieval && (r.retrieval.retrieved_ids || []).join(", ")),
|
| 378 |
+
"── per-claim citation map (the differentiator) ──",
|
| 379 |
+
];
|
| 380 |
+
(gr.per_claim_citations || []).forEach((c, i) => {
|
| 381 |
+
lines.push(" [" + (i + 1) + "] " + (c.grounded ? "grounded" : "UNGROUNDED") +
|
| 382 |
+
" by [" + (c.grounded_by || []).join(",") + "] support=" + c.best_support);
|
| 383 |
+
lines.push(" \"" + (c.claim || "").slice(0, 70) + "\"");
|
| 384 |
+
});
|
| 385 |
+
lines.push("grounded/total: " + gr.grounded_claim_count + "/" + gr.total_claim_count);
|
| 386 |
+
lines.push("RAGAS : faithfulness=" + ra.faithfulness + " ctx-precision=" + ra.context_precision +
|
| 387 |
+
" avg-support=" + ra.avg_grounding_support);
|
| 388 |
+
lines.push("Λ (lambda) : " + r.lambda + " (floor " + r.lambda_floor + ")");
|
| 389 |
+
lines.push("gate_pass : " + r.gate_pass + " [Λ ADVISORY · Conjecture 1 · never 'green']");
|
| 390 |
+
lines.push("rag_state : " + r.rag_state + " honesty_label=" + r.honesty_label);
|
| 391 |
+
lines.push("model_id : " + (r.model_id || "(none · extractive)") + " api_key_wired=" + r.api_key_wired);
|
| 392 |
+
lines.push("signature : " + sig.alg + " / " + sig.envelope + " · signed=" + sig.signed);
|
| 393 |
+
lines.push(" value : " + (sig.value || "?"));
|
| 394 |
+
lines.push(" honesty : " + (sig.honesty || ""));
|
| 395 |
+
lines.push("conjecture : " + r.conjecture_note);
|
| 396 |
+
_el.receipt.textContent = lines.join("\n");
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
function _esc(s) {
|
| 400 |
+
return String(s == null ? "" : s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// =========================================================================================
|
| 404 |
+
// unmount
|
| 405 |
+
// =========================================================================================
|
| 406 |
+
function unmount() {
|
| 407 |
+
try { if (_poll) _poll.stop(); } catch (_) {}
|
| 408 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 409 |
+
try {
|
| 410 |
+
if (_group && _stage) {
|
| 411 |
+
_group.traverse((o) => {
|
| 412 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 413 |
+
if (o.material) {
|
| 414 |
+
const mats = Array.isArray(o.material) ? o.material : [o.material];
|
| 415 |
+
mats.forEach((m) => { if (m.map && m.map.dispose) m.map.dispose(); if (m.dispose) m.dispose(); });
|
| 416 |
+
}
|
| 417 |
+
});
|
| 418 |
+
_stage.scene.remove(_group);
|
| 419 |
+
}
|
| 420 |
+
} catch (_) {}
|
| 421 |
+
_poll = null; _overlay = _group = _core = _billboard = null;
|
| 422 |
+
_passageNodes = []; _beams = []; _badge = null; _el = {};
|
| 423 |
+
S.corpus = []; S.lastReceipt = null; S.lastAnswer = null; S.lastClaims = []; S.lastRagas = null;
|
| 424 |
+
_stage = _THREE = _ctx = null;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
export default { id: ID, title: TITLE, endpoints: [EP_CORPUS, EP_QUERY], mount, unmount };
|