betterwithage Claude Opus 4.7 commited on
Commit
f47d32b
·
verified ·
1 Parent(s): 8b963e8

deploy(hf): sync szl-holdings/a11oy@main derived COPY set

Browse files

Reusable Dockerfile-COPY-derived deploy from szl-holdings/a11oy main.
Files: 945 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 CHANGED
@@ -177,6 +177,7 @@ const SURFACES = [
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
  { id: "ecosystem", title: "Harness · Ecosystem Status", mod: "/static/3d/surfaces/ecosystem.js" },
 
180
  ];
181
 
182
  const stageEl = document.getElementById("stage");
 
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
  { id: "ecosystem", title: "Harness · Ecosystem Status", mod: "/static/3d/surfaces/ecosystem.js" },
180
+ { id: "brainquery", title: "Brain Query · ask the graph (retrieval)", mod: "/static/3d/surfaces/brainquery.js" },
181
  ];
182
 
183
  const stageEl = document.getElementById("stage");
static/3d/surfaces/brainquery.js ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/brainquery.js — ASK THE BRAIN (WAVE 1). The companion to brain.js:
5
+ // brain.js *renders* the whole estate knowledge graph; this surface makes it
6
+ // QUERYABLE. Type a question → the server retrieves a grounding subgraph
7
+ // (HippoRAG-style Personalized PageRank over the honest graph, merged with
8
+ // GraphRAG community context) and it lights up here in 3D:
9
+ // * node SIZE = salience (PageRank over the full graph)
10
+ // * node GLOW = match score (how strongly the query hit that node)
11
+ // * seeds (direct query hits) ring brightest; PPR-reached nodes fill the halo.
12
+ //
13
+ // HONESTY (Doctrine v11 — labels read VERBATIM, never upgraded):
14
+ // * the grounding subgraph is REAL (retrieved from /brain/ask); it is shown
15
+ // whether or not a sovereign model was reachable.
16
+ // * generated prose is shown ONLY when the endpoint returns one; otherwise the
17
+ // answer pill reads its verbatim UNAVAILABLE — NEVER a fabricated answer.
18
+ // * embeddings tier is shown verbatim (hash-fallback similarity is MODELED,
19
+ // never MEASURED).
20
+ // * Λ = Conjecture 1 → GREY node, never green. locked-proven = exactly 8.
21
+ // * palette: lattice-blue 0x5b8dee · violet-blue 0x8a6bff · proof-teal 0x3af4c8
22
+ // · greys. PURPLE BANNED. 0 runtime CDN (three.js via ctx.THREE).
23
+ //
24
+ // Surface export shape: export default { id, title, endpoints, mount(ctx), unmount() }
25
+ // ctx = { stage, container, live, label, THREE, szl3d }
26
+
27
+ import { createShowcase } from "./_showcase.js";
28
+
29
+ const ID = "brainquery";
30
+ const TITLE = "Brain Query — ask the graph";
31
+
32
+ // same-origin a11oy endpoints (canonical a-11-oy.com in prod; relative here)
33
+ const EP_ASK = "/api/a11oy/v1/brain/ask";
34
+ const EP_INDEX = "/api/a11oy/v1/brain/index";
35
+
36
+ // palette (doctrine v11) — NO purple
37
+ const C_INPUT = 0x5b8dee; // lattice-blue — repos + surfaces (input)
38
+ const C_TOPIC = 0x8a6bff; // violet-blue — topic clusters
39
+ const C_FORMULA = 0x8a6bff; // violet-blue — formulas
40
+ const C_LOCKED = 0x3af4c8; // proof-teal — locked-proven core
41
+ const C_ESTATE = 0x3af4c8; // proof-teal — estate root (output)
42
+ const C_ENDPT = 0x5b8dee; // lattice-blue — live endpoints
43
+ const C_FIELD = 0x3a5a8c; // lattice-blue (dim) — harvested field leaders
44
+ const C_CONJ = 0x5a6570; // GREY — conjectures (Λ) — never green
45
+ const C_EDGE = 0x1b3a44; // dim link
46
+
47
+ const MAX_NODES = 240; // grounding subgraphs are small; cap defensively
48
+ const MAX_EDGES = 900;
49
+
50
+ let _stage = null, _THREE = null, _ctx = null, _group = null, _show = null;
51
+ let _badge = null, _frameReg = false, _t0 = 0, _inFlight = null;
52
+
53
+ // scene objects
54
+ let _sphereGeo = null;
55
+ let _meshes = []; // individual node meshes (labelable)
56
+ let _edges = null, _edgeGeo = null, _edgeMat = null;
57
+ let _pos = {}; // id -> Vector3
58
+
59
+ // query DOM
60
+ let _input = null, _askBtn = null, _answerEl = null, _resultsEl = null;
61
+ let _onKey = null;
62
+
63
+ const S = {
64
+ label: "MODELED", state: "idle",
65
+ query: "", answer: null, answerLabel: "UNAVAILABLE", answerModel: null,
66
+ nodes: null, links: null, seedScore: null,
67
+ retrieval: null, note: null,
68
+ // index tiers (from /brain/index) — honest capability pills
69
+ vectorBackend: null, embedSource: null, embedTier: null, communityAlgo: null,
70
+ };
71
+
72
+ // -------------------------------------------------------------------------- //
73
+ // deterministic layout: golden-angle disc; radius grows for LESS-salient nodes
74
+ // so the most salient sit at the centre. Stable (hash-seeded), no RNG.
75
+ // -------------------------------------------------------------------------- //
76
+ function _hash(str) {
77
+ let h = 2166136261 >>> 0;
78
+ for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619) >>> 0; }
79
+ return h;
80
+ }
81
+
82
+ function _salience(n) { return (n.ppr != null ? n.ppr : (n.salience || 0)); }
83
+
84
+ function _layout(nodes) {
85
+ _pos = {};
86
+ // most salient first → smallest radius (centre); tie-break by id for stability
87
+ const ranked = nodes.slice().sort((a, b) => (_salience(b) - _salience(a)) || (a.id < b.id ? -1 : 1));
88
+ const N = ranked.length || 1;
89
+ const R = 9.0;
90
+ ranked.forEach((n, i) => {
91
+ const r = R * Math.sqrt((i + 0.5) / N);
92
+ const theta = i * 2.399963229728653; // golden angle
93
+ const jz = ((_hash(n.id) % 200) / 200 - 0.5) * 2.4; // depth jitter
94
+ _pos[n.id] = new _THREE.Vector3(r * Math.cos(theta), r * Math.sin(theta), jz);
95
+ });
96
+ }
97
+
98
+ function _isConj(n) { return (n.conjecture != null) || n.formula_id === "F23"; }
99
+
100
+ function _nodeColor(n) {
101
+ if (_isConj(n)) return C_CONJ;
102
+ if (n.kind === "formula") return n.locked ? C_LOCKED : C_FORMULA;
103
+ if (n.kind === "estate") return C_ESTATE;
104
+ if (n.kind === "endpoint") return C_ENDPT;
105
+ if (n.kind === "topic") return C_TOPIC;
106
+ if (n.layer === 0) return C_INPUT;
107
+ if (n.layer === -1) return C_FIELD;
108
+ return C_INPUT;
109
+ }
110
+
111
+ // size grows with salience; salience is normalised per-result so the biggest
112
+ // retrieved node reads clearly regardless of absolute PageRank magnitude.
113
+ let _maxSal = 1e-9;
114
+ function _nodeRadius(n) {
115
+ const s = _salience(n) / _maxSal; // 0..1
116
+ let r = 0.22 + 0.85 * Math.sqrt(Math.max(0, s));
117
+ if (n.kind === "estate") r = Math.max(r, 0.7);
118
+ return Math.min(r, 1.3);
119
+ }
120
+
121
+ // glow (emissiveIntensity) tracks the query MATCH score (seeds glow brightest);
122
+ // non-seed PPR-reached nodes get a dim honest floor.
123
+ function _glow(n) {
124
+ const sc = (S.seedScore && S.seedScore[n.id] != null) ? S.seedScore[n.id] : 0;
125
+ return 0.14 + 0.9 * Math.min(1, sc);
126
+ }
127
+
128
+ // -------------------------------------------------------------------------- //
129
+ // mount
130
+ // -------------------------------------------------------------------------- //
131
+ function mount(ctx) {
132
+ _ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
133
+ _group = new _THREE.Group();
134
+ _stage.scene.add(_group);
135
+ _t0 = (typeof performance !== "undefined" ? performance.now() : Date.now());
136
+ _sphereGeo = new _THREE.SphereGeometry(1, 12, 10);
137
+
138
+ _buildOverlay(ctx);
139
+ if (ctx.live && ctx.live.createBadge) {
140
+ _badge = ctx.live.createBadge();
141
+ if (_show) _show.setBadge(_badge);
142
+ }
143
+
144
+ // one-shot index probe → honest capability pills (vector/embedding/community).
145
+ _fetchIndex();
146
+
147
+ // top-N + hover/tap labels bound to the node meshes.
148
+ if (_show) {
149
+ _show.attachSceneLabels({
150
+ objects: () => _meshes,
151
+ text: (o) => (o.userData && o.userData.node && (o.userData.node.title || o.userData.node.id)) || "",
152
+ weight: (o) => (o.userData && o.userData.node && _salience(o.userData.node)) || 0,
153
+ topN: 10, hover: true, fadeNear: 9, fadeFar: 70,
154
+ });
155
+ }
156
+
157
+ // seed a friendly default query so the surface isn't empty on first open.
158
+ _ask("what proves the estate thesis");
159
+
160
+ if (!_frameReg && _stage.onFrame) { _stage.onFrame(_animate); _frameReg = true; }
161
+ }
162
+
163
+ function _readLabel(j, fallback) {
164
+ const lbl = (j && j.label != null) ? j.label : (fallback || "MODELED");
165
+ return String(lbl).toUpperCase();
166
+ }
167
+
168
+ function _setBadge(state) {
169
+ S.state = state;
170
+ if (_badge && _badge.set) { try { _badge.set(state); } catch (_) {} }
171
+ }
172
+
173
+ // -------------------------------------------------------------------------- //
174
+ // data
175
+ // -------------------------------------------------------------------------- //
176
+ function _fetchIndex() {
177
+ fetch(EP_INDEX, { headers: { accept: "application/json" } })
178
+ .then((r) => (r.ok ? r.json() : Promise.reject(new Error("http " + r.status))))
179
+ .then((j) => {
180
+ S.vectorBackend = j.vector_backend || null;
181
+ S.embedSource = j.embed_source || null;
182
+ S.embedTier = _readLabel(j, "MODELED"); // whole payload is MODELED
183
+ if (j.embed_tier) S.embedTier = String(j.embed_tier).toUpperCase();
184
+ S.communityAlgo = j.community_algo || null;
185
+ _paintOverlay();
186
+ })
187
+ .catch(() => { /* index pills stay "—"; the ask path still works */ });
188
+ }
189
+
190
+ function _ask(q) {
191
+ q = (q || "").trim();
192
+ if (!q) return;
193
+ S.query = q;
194
+ if (_input && _input.value !== q) _input.value = q;
195
+ _setBadge("loading");
196
+ S.state = "loading";
197
+ _paintOverlay();
198
+
199
+ const ctrl = ("AbortController" in window) ? new AbortController() : null;
200
+ if (_inFlight && _inFlight.abort) { try { _inFlight.abort(); } catch (_) {} }
201
+ _inFlight = ctrl;
202
+
203
+ const url = EP_ASK + "?q=" + encodeURIComponent(q);
204
+ fetch(url, { headers: { accept: "application/json" }, signal: ctrl ? ctrl.signal : undefined })
205
+ .then((r) => (r.ok ? r.json() : Promise.reject(new Error("http " + r.status))))
206
+ .then((j) => {
207
+ _inFlight = null;
208
+ _onAsk(j);
209
+ })
210
+ .catch((e) => {
211
+ if (e && e.name === "AbortError") return;
212
+ _inFlight = null;
213
+ S.state = "error";
214
+ _setBadge("error");
215
+ _paintOverlay();
216
+ });
217
+ }
218
+
219
+ function _onAsk(j) {
220
+ if (!j) { S.state = "error"; _setBadge("error"); _paintOverlay(); return; }
221
+ S.label = _readLabel(j, "MODELED");
222
+ const g = j.grounding_subgraph || {};
223
+ S.nodes = Array.isArray(g.nodes) ? g.nodes.slice(0, MAX_NODES) : [];
224
+ const keep = new Set(S.nodes.map((n) => n.id));
225
+ S.links = (Array.isArray(g.links) ? g.links : [])
226
+ .filter((l) => keep.has(l.source) && keep.has(l.target)).slice(0, MAX_EDGES);
227
+
228
+ // seed match scores drive node glow.
229
+ S.seedScore = {};
230
+ (j.seeds || []).forEach((s) => { S.seedScore[s.id] = s.score || 0; });
231
+
232
+ // honest answer handling — NEVER fabricate. Verbatim label from the endpoint.
233
+ S.answer = (j.answer != null && String(j.answer).trim()) ? String(j.answer) : null;
234
+ S.answerLabel = String(j.answer_label || "UNAVAILABLE").toUpperCase();
235
+ S.answerModel = j.answer_model || null;
236
+ S.retrieval = j.retrieval || null;
237
+ S.note = j.note || null;
238
+
239
+ S.state = "live";
240
+ _setBadge("live");
241
+ _rebuild();
242
+ _paintOverlay();
243
+ }
244
+
245
+ // -------------------------------------------------------------------------- //
246
+ // build
247
+ // -------------------------------------------------------------------------- //
248
+ function _rebuild() {
249
+ if (!_group || !S.nodes) return;
250
+ _clearScene();
251
+ if (!S.nodes.length) return;
252
+ _maxSal = Math.max(1e-9, ...S.nodes.map(_salience));
253
+ _layout(S.nodes);
254
+ S.nodes.forEach(_addMesh);
255
+ _buildEdges();
256
+ }
257
+
258
+ function _addMesh(n) {
259
+ const col = _nodeColor(n);
260
+ const conj = _isConj(n);
261
+ const mat = new _THREE.MeshStandardMaterial({
262
+ color: col,
263
+ emissive: conj ? 0x000000 : col,
264
+ emissiveIntensity: conj ? 0.0 : _glow(n),
265
+ metalness: 0.1, roughness: conj ? 0.95 : 0.45,
266
+ transparent: true, opacity: conj ? 0.62 : 0.96,
267
+ });
268
+ const mesh = new _THREE.Mesh(_sphereGeo, mat);
269
+ mesh.scale.setScalar(_nodeRadius(n));
270
+ mesh.position.copy(_pos[n.id]);
271
+ mesh.userData = { node: n, baseGlow: mat.emissiveIntensity, isConj: conj };
272
+ _meshes.push(mesh);
273
+ _group.add(mesh);
274
+ }
275
+
276
+ function _buildEdges() {
277
+ const pts = [];
278
+ for (let i = 0; i < S.links.length; i++) {
279
+ const l = S.links[i];
280
+ const a = _pos[l.source], b = _pos[l.target];
281
+ if (!a || !b) continue;
282
+ pts.push(a.x, a.y, a.z, b.x, b.y, b.z);
283
+ }
284
+ if (!pts.length) return;
285
+ _edgeGeo = new _THREE.BufferGeometry();
286
+ _edgeGeo.setAttribute("position", new _THREE.Float32BufferAttribute(pts, 3));
287
+ _edgeMat = new _THREE.LineBasicMaterial({ color: C_EDGE, transparent: true, opacity: 0.3 });
288
+ _edges = new _THREE.LineSegments(_edgeGeo, _edgeMat);
289
+ _group.add(_edges);
290
+ }
291
+
292
+ function _clearScene() {
293
+ _meshes.forEach((m) => {
294
+ if (m.material && m.material.dispose) m.material.dispose();
295
+ _group.remove(m);
296
+ });
297
+ _meshes = [];
298
+ if (_edges) _group.remove(_edges);
299
+ if (_edgeGeo) _edgeGeo.dispose();
300
+ if (_edgeMat) _edgeMat.dispose();
301
+ _edges = _edgeGeo = _edgeMat = null;
302
+ }
303
+
304
+ // -------------------------------------------------------------------------- //
305
+ // animation: gentle rotation + seed "breathing" glow (conjectures stay flat)
306
+ // -------------------------------------------------------------------------- //
307
+ function _animate() {
308
+ if (!_group) return;
309
+ const now = (typeof performance !== "undefined" ? performance.now() : Date.now());
310
+ const t = (now - _t0) / 1000;
311
+ _group.rotation.y = Math.sin(t * 0.09) * 0.45 + t * 0.02;
312
+ const pulse = 0.5 + 0.5 * Math.sin(t * 1.7);
313
+ _meshes.forEach((m) => {
314
+ if (!m.material || m.userData.isConj) return;
315
+ const base = m.userData.baseGlow || 0.14;
316
+ m.material.emissiveIntensity = base * (0.75 + 0.35 * pulse);
317
+ });
318
+ }
319
+
320
+ // -------------------------------------------------------------------------- //
321
+ // overlay (shared showcase helper) + the query box
322
+ // -------------------------------------------------------------------------- //
323
+ const _el = {};
324
+
325
+ function _buildOverlay(ctx) {
326
+ _show = createShowcase(ctx, {
327
+ id: ID, title: TITLE, accent: "#5b8dee", startExpanded: true,
328
+ chips: [{ label: "MODELED", text: "retrieval", name: "src" }],
329
+ legend: ["MEASURED", "MODELED", "UNAVAILABLE"],
330
+ description:
331
+ "<b>Ask the estate's brain.</b> Your question is answered by RETRIEVAL over the real " +
332
+ "knowledge graph: the server seeds Personalized PageRank (HippoRAG-style) from the nodes " +
333
+ "your query hits, walks the graph to a grounding subgraph, and merges in the relevant " +
334
+ "community context (GraphRAG-style). That subgraph lights up here — node <b>size = salience</b> " +
335
+ "(PageRank), node <b>glow = match</b> to your query. Generated prose appears only if a " +
336
+ "sovereign model is reachable; otherwise the answer is honestly <b>UNAVAILABLE</b> — the " +
337
+ "subgraph is real regardless. Nothing is fabricated.",
338
+ citations:
339
+ "Retrieval is LIVE from /api/a11oy/v1/brain/ask (pure read — no signing on GET) over the " +
340
+ "same honest graph as /brain/graph. Vectors/embeddings/community tiers shown verbatim below. " +
341
+ "Λ = Conjecture 1 (grey, never proven green).",
342
+ plain: { html: _plainHtml },
343
+ });
344
+
345
+ // --- the query box (custom DOM into the collapsible body) ---------------- //
346
+ const wrap = document.createElement("div");
347
+ wrap.style.cssText = "display:flex;flex-direction:column;gap:7px";
348
+ const row = document.createElement("div");
349
+ row.style.cssText = "display:flex;gap:6px";
350
+ _input = document.createElement("input");
351
+ _input.type = "text";
352
+ _input.placeholder = "ask the brain… (e.g. what proves the thesis?)";
353
+ _input.setAttribute("aria-label", "Ask the brain");
354
+ _input.style.cssText =
355
+ "flex:1 1 auto;min-width:0;font:12px ui-monospace,SFMono-Regular,Menlo,monospace;" +
356
+ "padding:7px 9px;border-radius:8px;border:1px solid #1c2836;background:#0a1117;" +
357
+ "color:#e7eef6;outline:none";
358
+ _askBtn = document.createElement("button");
359
+ _askBtn.type = "button";
360
+ _askBtn.textContent = "ask";
361
+ _askBtn.style.cssText =
362
+ "flex:0 0 auto;font:600 12px ui-monospace,Menlo,monospace;padding:7px 13px;border-radius:8px;" +
363
+ "cursor:pointer;border:1px solid #3af4c8;background:#08201a;color:#3af4c8";
364
+ _onKey = (e) => { if (e.key === "Enter") { e.preventDefault(); _ask(_input.value); } };
365
+ _input.addEventListener("keydown", _onKey);
366
+ _askBtn.addEventListener("click", () => _ask(_input.value));
367
+ row.appendChild(_input); row.appendChild(_askBtn);
368
+ wrap.appendChild(row);
369
+
370
+ // honest answer box (prose OR verbatim UNAVAILABLE pill)
371
+ _answerEl = document.createElement("div");
372
+ _answerEl.style.cssText =
373
+ "font-size:11px;color:#c9d6df;line-height:1.5;border:1px dashed #26333f;border-radius:8px;" +
374
+ "padding:8px 10px;min-height:18px";
375
+ wrap.appendChild(_answerEl);
376
+ _show.appendBody(wrap);
377
+
378
+ // KPI rows
379
+ _el.answerLbl = _show.addField("Generated answer");
380
+ _el.grounded = _show.addField("Grounding nodes");
381
+ _el.edges = _show.addField("Grounding edges");
382
+ _el.vectors = _show.addField("Vector backend");
383
+ _el.embed = _show.addField("Embeddings");
384
+ _el.community = _show.addField("Communities via");
385
+
386
+ // top retrieved nodes (cited ids) list
387
+ _resultsEl = document.createElement("div");
388
+ _resultsEl.style.cssText = "display:flex;flex-direction:column;gap:3px;font-size:10.5px;color:#9fb1bf";
389
+ _show.appendBody(_resultsEl);
390
+
391
+ // honest note (verbatim from the endpoint)
392
+ _el.note = document.createElement("div");
393
+ _el.note.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5;margin-top:2px";
394
+ _show.appendBody(_el.note);
395
+ }
396
+
397
+ function _fmt(n) { return (n == null) ? "—" : Number(n).toLocaleString("en-US"); }
398
+
399
+ function _paintOverlay() {
400
+ if (!_show) return;
401
+ _show.setChip("src", S.label || "MODELED", { text: "retrieval" });
402
+
403
+ // honest answer: prose if present, else the verbatim UNAVAILABLE label.
404
+ if (_answerEl) {
405
+ if (S.state === "loading") {
406
+ _answerEl.textContent = "retrieving grounding subgraph…";
407
+ _answerEl.style.color = "#9fb1bf";
408
+ } else if (S.state === "error") {
409
+ _answerEl.textContent = "retrieval error — the brain API did not respond.";
410
+ _answerEl.style.color = "#d78a8a";
411
+ } else if (S.answer) {
412
+ _answerEl.textContent = S.answer;
413
+ _answerEl.style.color = "#c9d6df";
414
+ } else {
415
+ _answerEl.innerHTML =
416
+ "<b style=\"color:#e7eef6\">" + (S.answerLabel || "UNAVAILABLE") + "</b> — no sovereign " +
417
+ "model was reachable, so no answer text is generated. The grounding subgraph shown is " +
418
+ "real; a fabricated answer is never produced.";
419
+ _answerEl.style.color = "#9fb1bf";
420
+ }
421
+ }
422
+
423
+ const set = (k, v) => { if (_el[k]) _el[k].textContent = v; };
424
+ const gN = S.nodes ? S.nodes.length : null;
425
+ const gE = S.links ? S.links.length : null;
426
+ set("answerLbl", S.answer ? (S.answerLabel + (S.answerModel ? " · " + S.answerModel : ""))
427
+ : (S.answerLabel || "UNAVAILABLE"));
428
+ set("grounded", S.state === "loading" ? "loading…" : _fmt(gN));
429
+ set("edges", S.state === "loading" ? "loading…" : _fmt(gE));
430
+ set("vectors", S.vectorBackend || "—");
431
+ set("embed", S.embedSource ? (S.embedSource + " [" + (S.embedTier || "MODELED") + "]") : "—");
432
+ set("community", S.communityAlgo || "—");
433
+ if (_el.note) _el.note.textContent = S.note || "";
434
+
435
+ // cited-node list (top grounding nodes by salience)
436
+ if (_resultsEl) {
437
+ _resultsEl.textContent = "";
438
+ const top = (S.nodes || []).slice()
439
+ .sort((a, b) => (_salience(b) - _salience(a)) || (a.id < b.id ? -1 : 1))
440
+ .slice(0, 8);
441
+ top.forEach((n) => {
442
+ const line = document.createElement("div");
443
+ line.style.cssText = "white-space:nowrap;overflow:hidden;text-overflow:ellipsis";
444
+ const hit = (S.seedScore && S.seedScore[n.id] != null) ? " ●" : "";
445
+ line.textContent = "· " + (n.title || n.id) + " [" + (n.kind || "?") + "]" + hit;
446
+ line.title = n.id;
447
+ _resultsEl.appendChild(line);
448
+ });
449
+ }
450
+
451
+ if (_show.refreshPlain) _show.refreshPlain();
452
+ }
453
+
454
+ function _plainHtml() {
455
+ return (
456
+ "Type a question and our estate's <b>brain</b> answers by looking things up in its own " +
457
+ "knowledge graph — the same real network of repos, formulas, papers and people you can see " +
458
+ "in the Brain surface. It finds the nodes your question touches, follows the connections " +
459
+ "outward to gather the most relevant ones, and lights them up: <b>bigger = more important</b> " +
460
+ "in the graph, <b>brighter = closer match</b> to what you asked. If we have a private AI model " +
461
+ "running, it writes a short answer that only cites those nodes; if not, it honestly says " +
462
+ "<b>UNAVAILABLE</b> instead of making something up — but you still get the real, grounded " +
463
+ "subgraph. Label <b>" + (S.label || "MODELED") + "</b>."
464
+ );
465
+ }
466
+
467
+ // -------------------------------------------------------------------------- //
468
+ // unmount
469
+ // -------------------------------------------------------------------------- //
470
+ function unmount() {
471
+ try { if (_inFlight && _inFlight.abort) _inFlight.abort(); } catch (_) {}
472
+ _inFlight = null;
473
+ try { if (_input && _onKey) _input.removeEventListener("keydown", _onKey); } catch (_) {}
474
+ try { if (_show) _show.destroy(); } catch (_) {}
475
+ try { _clearScene(); } catch (_) {}
476
+ try { if (_sphereGeo) _sphereGeo.dispose(); } catch (_) {}
477
+ try { if (_group && _stage) _stage.scene.remove(_group); } catch (_) {}
478
+ _sphereGeo = null;
479
+ _group = _show = _badge = null;
480
+ _input = _askBtn = _answerEl = _resultsEl = _onKey = null;
481
+ Object.keys(_el).forEach((k) => delete _el[k]);
482
+ _pos = {}; _frameReg = false; _maxSal = 1e-9;
483
+ _stage = _THREE = _ctx = null;
484
+ S.label = "MODELED"; S.state = "idle";
485
+ S.query = ""; S.answer = null; S.answerLabel = "UNAVAILABLE"; S.answerModel = null;
486
+ S.nodes = S.links = S.seedScore = null;
487
+ S.retrieval = S.note = null;
488
+ S.vectorBackend = S.embedSource = S.embedTier = S.communityAlgo = null;
489
+ }
490
+
491
+ export default { id: ID, title: TITLE, endpoints: [EP_ASK, EP_INDEX], mount, unmount };