@facthouse/mcp 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +622 -611
- package/dist/cli/index.d.ts +4 -9
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +50 -48
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init-backfill.d.ts +23 -4
- package/dist/cli/init-backfill.d.ts.map +1 -1
- package/dist/cli/init-backfill.js +33 -12
- package/dist/cli/init-backfill.js.map +1 -1
- package/dist/cli/init-knobs.d.ts +20 -11
- package/dist/cli/init-knobs.d.ts.map +1 -1
- package/dist/cli/init-knobs.js +62 -32
- package/dist/cli/init-knobs.js.map +1 -1
- package/dist/cli/init-wizard.d.ts +2 -0
- package/dist/cli/init-wizard.d.ts.map +1 -1
- package/dist/cli/init-wizard.js +7 -5
- package/dist/cli/init-wizard.js.map +1 -1
- package/dist/cli/init.d.ts +4 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +8 -6
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/inspect-html.js +460 -460
- package/dist/cli/inspect-intelligence.js +70 -70
- package/dist/cli/inspect-payload.js +39 -39
- package/dist/cli/inspect-theme.js +18 -18
- package/dist/cli/query.js +4 -4
- package/dist/cli/settings.d.ts.map +1 -1
- package/dist/cli/settings.js +3 -3
- package/dist/cli/settings.js.map +1 -1
- package/dist/cli/spend-dashboard.js +4 -4
- package/dist/cli/stats-html.js +674 -674
- package/dist/cli/web.d.ts.map +1 -1
- package/dist/cli/web.js +91 -96
- package/dist/cli/web.js.map +1 -1
- package/dist/db/consolidation-lock.js +2 -2
- package/dist/db/consolidations.js +15 -15
- package/dist/db/embeddings.js +10 -10
- package/dist/db/entities.js +26 -26
- package/dist/db/extract-watermarks.js +79 -79
- package/dist/db/facts.js +39 -39
- package/dist/db/inferences.js +8 -8
- package/dist/db/intelligence-runs.js +5 -5
- package/dist/db/postgres-schema.js +323 -323
- package/dist/db/prune.js +17 -17
- package/dist/db/schema.js +530 -530
- package/dist/db/session-facts.js +26 -26
- package/dist/db/sessions.js +10 -10
- package/dist/db/sources.js +1 -1
- package/dist/db/stats.js +10 -10
- package/dist/db/watermarks.js +7 -7
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/intelligence/consolidate.d.ts +7 -1
- package/dist/intelligence/consolidate.d.ts.map +1 -1
- package/dist/intelligence/consolidate.js +54 -40
- package/dist/intelligence/consolidate.js.map +1 -1
- package/dist/intelligence/extract-prompt.js +26 -26
- package/dist/intelligence/token-budget.d.ts +2 -0
- package/dist/intelligence/token-budget.d.ts.map +1 -1
- package/dist/intelligence/token-budget.js +1 -1
- package/dist/intelligence/token-budget.js.map +1 -1
- package/dist/search/episodes.js +14 -14
- package/dist/search/key-facts.js +3 -3
- package/dist/suppress-sqlite-warning.d.ts +2 -0
- package/dist/suppress-sqlite-warning.d.ts.map +1 -0
- package/dist/suppress-sqlite-warning.js +17 -0
- package/dist/suppress-sqlite-warning.js.map +1 -0
- package/dist/tools/fact-manager.d.ts.map +1 -1
- package/dist/tools/fact-manager.js +9 -11
- package/dist/tools/fact-manager.js.map +1 -1
- package/dist/tools/read-tools.js +4 -4
- package/dist/tools/resources.js +3 -3
- package/dist/tools/resources.js.map +1 -1
- package/dist/types/config.d.ts +5 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +7 -1
- package/dist/types/config.js.map +1 -1
- package/package.json +62 -62
- package/dist/cli/log-event.d.ts +0 -55
- package/dist/cli/log-event.d.ts.map +0 -1
- package/dist/cli/log-event.js +0 -149
- package/dist/cli/log-event.js.map +0 -1
- package/dist/db/scheduler-signal.d.ts +0 -20
- package/dist/db/scheduler-signal.d.ts.map +0 -1
- package/dist/db/scheduler-signal.js +0 -32
- package/dist/db/scheduler-signal.js.map +0 -1
- package/dist/schemas/starter-vocabulary.d.ts +0 -34
- package/dist/schemas/starter-vocabulary.d.ts.map +0 -1
- package/dist/schemas/starter-vocabulary.js +0 -91
- package/dist/schemas/starter-vocabulary.js.map +0 -1
- package/dist/search/profile.d.ts +0 -31
- package/dist/search/profile.d.ts.map +0 -1
- package/dist/search/profile.js +0 -43
- package/dist/search/profile.js.map +0 -1
- package/dist/sources/jsonl-ingest.d.ts +0 -58
- package/dist/sources/jsonl-ingest.d.ts.map +0 -1
- package/dist/sources/jsonl-ingest.js +0 -195
- package/dist/sources/jsonl-ingest.js.map +0 -1
- package/dist/sources/pull.d.ts +0 -85
- package/dist/sources/pull.d.ts.map +0 -1
- package/dist/sources/pull.js +0 -145
- package/dist/sources/pull.js.map +0 -1
- package/dist/types.d.ts +0 -115
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/warnings.d.ts.map +0 -1
- package/dist/warnings.js.map +0 -1
package/dist/cli/inspect-html.js
CHANGED
|
@@ -26,466 +26,466 @@ export function renderInspectHtml(payload) {
|
|
|
26
26
|
const json = JSON.stringify(graph).replace(/</g, "\\u003c");
|
|
27
27
|
const spendHtml = renderSpendBoard(spend ?? spendDashboardFromStats(health ?? emptyHealth()));
|
|
28
28
|
const routingHtml = routing ? renderIntelligenceRoutingCard(routing) : "";
|
|
29
|
-
return `<!DOCTYPE html>
|
|
30
|
-
<html lang="en-GB" data-theme="system">
|
|
31
|
-
<head>
|
|
32
|
-
<meta charset="utf-8"/>
|
|
33
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
34
|
-
<title>Facthouse inspect</title>
|
|
35
|
-
<link rel="icon" href="${ledgerFaviconHref()}"/>
|
|
36
|
-
<style>
|
|
37
|
-
${ledgerInspectCss()}
|
|
38
|
-
* { box-sizing: border-box; }
|
|
39
|
-
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
|
|
40
|
-
font: 13px/1.45 "Segoe UI", ui-sans-serif, system-ui, sans-serif; }
|
|
41
|
-
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
42
|
-
#app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
|
|
43
|
-
header { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
|
|
44
|
-
padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
45
|
-
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
46
|
-
.brand-mark { display: block; width: 28px; height: 28px; flex: 0 0 auto; border-radius: 6px;
|
|
47
|
-
overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
|
|
48
|
-
.brand-mark svg { display: block; width: 28px; height: 28px; }
|
|
49
|
-
.brand-copy { min-width: 0; }
|
|
50
|
-
header h1 { font-size: 15px; font-weight: 650; letter-spacing: -0.02em; margin: 0; line-height: 1.2; }
|
|
51
|
-
.brand-sub { margin: 1px 0 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
|
|
52
|
-
color: var(--muted); }
|
|
53
|
-
header .meta { color: var(--muted); font-size: 12px; }
|
|
54
|
-
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
|
|
55
|
-
input, select, button {
|
|
56
|
-
background: var(--input); color: var(--text); border: 1px solid var(--line);
|
|
57
|
-
border-radius: 8px; padding: 7px 10px; font: inherit; }
|
|
58
|
-
input[type="search"] { width: 260px; }
|
|
59
|
-
input[type="range"] { width: 92px; }
|
|
60
|
-
button { cursor: pointer; transition: border-color .12s, color .12s, background .12s; }
|
|
61
|
-
button:hover { border-color: var(--accent); color: var(--accent); }
|
|
62
|
-
.tab.on { border-color: var(--accent); color: var(--accent); }
|
|
63
|
-
.icon-btn { width: 34px; height: 34px; padding: 0; display: flex; align-items: center;
|
|
64
|
-
justify-content: center; background: var(--elev); }
|
|
65
|
-
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor;
|
|
66
|
-
stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
|
67
|
-
#stage { display: grid; min-height: 0; --panel: 420px;
|
|
68
|
-
grid-template-columns: 1fr 6px var(--panel); grid-template-areas: "graph split panel"; }
|
|
69
|
-
#stage.dock-left { grid-template-columns: var(--panel) 6px 1fr;
|
|
70
|
-
grid-template-areas: "panel split graph"; }
|
|
71
|
-
#stage.dock-bottom { grid-template-columns: 1fr; grid-template-rows: 1fr 6px var(--panel);
|
|
72
|
-
grid-template-areas: "graph" "split" "panel"; }
|
|
73
|
-
#stage.dock-top { grid-template-columns: 1fr; grid-template-rows: var(--panel) 6px 1fr;
|
|
74
|
-
grid-template-areas: "panel" "split" "graph"; }
|
|
75
|
-
#graphwrap { grid-area: graph; position: relative; min-width: 0; min-height: 0; }
|
|
76
|
-
#splitter { grid-area: split; background: var(--line); cursor: col-resize; }
|
|
77
|
-
#stage.dock-bottom #splitter, #stage.dock-top #splitter { cursor: row-resize; }
|
|
78
|
-
aside { grid-area: panel; min-width: 0; min-height: 0; background: var(--panel);
|
|
79
|
-
position: relative; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
|
|
80
|
-
#stage.dock-left aside { border-left: 0; border-right: 1px solid var(--line); }
|
|
81
|
-
#stage.dock-top aside, #stage.dock-bottom aside { border-left: 0; }
|
|
82
|
-
canvas { width: 100%; height: 100%; display: block; background:
|
|
83
|
-
radial-gradient(900px 640px at 28% 18%, var(--glow) 0%, var(--bg) 62%); }
|
|
84
|
-
#refocus { position: absolute; top: 14px; right: 14px; z-index: 2;
|
|
85
|
-
background: var(--elev); border: 1px solid var(--accent); color: var(--text);
|
|
86
|
-
border-radius: 8px; padding: 6px 10px; }
|
|
87
|
-
#zoom { position: absolute; bottom: 14px; right: 14px; z-index: 2;
|
|
88
|
-
display: flex; flex-direction: column; gap: 6px; }
|
|
89
|
-
#zoom button { width: 36px; height: 34px; padding: 0; font-size: 16px; background: var(--elev); }
|
|
90
|
-
#graphBar { position: absolute; bottom: 14px; left: 14px; z-index: 2;
|
|
91
|
-
display: flex; align-items: center; gap: 10px; background: var(--elev);
|
|
92
|
-
border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
|
|
93
|
-
box-shadow: 0 8px 24px rgba(0,0,0,.18); }
|
|
94
|
-
#graphBar label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
|
|
95
|
-
.who { padding: 16px 76px 12px 18px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
|
|
96
|
-
.who h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 4px; overflow-wrap: anywhere; }
|
|
97
|
-
.who .type { color: var(--muted); overflow-wrap: anywhere; font-size: 12px; }
|
|
98
|
-
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); flex: 0 0 auto; padding: 0 8px; }
|
|
99
|
-
.tab { flex: 1; min-width: 0; background: transparent; border: 0;
|
|
100
|
-
border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 6px;
|
|
101
|
-
color: var(--muted); font-size: 12px; letter-spacing: .01em; }
|
|
102
|
-
.tab.on { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
|
|
103
|
-
.body { overflow: auto; padding: 14px 18px 28px; flex: 1; min-height: 0; }
|
|
104
|
-
.fact { padding: 12px 0; border-bottom: 1px solid var(--line); }
|
|
105
|
-
.fact.expired, .fact.superseded { opacity: 0.62; }
|
|
106
|
-
.fact.hi { background: var(--elev); margin: 0 -8px; padding-left: 8px; padding-right: 8px;
|
|
107
|
-
border-radius: 8px; box-shadow: inset 3px 0 0 var(--accent); }
|
|
108
|
-
.fact-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
|
|
109
|
-
.fact-left { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; min-width: 0; }
|
|
110
|
-
.fact .when { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; padding-left: 8px; }
|
|
111
|
-
.fact .flag { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--about); }
|
|
112
|
-
.fact .flag.mention { color: var(--mention); }
|
|
113
|
-
.fact .dom, .fact .meta-line { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
|
|
114
|
-
.fact .txt, .fact > div { overflow-wrap: anywhere; }
|
|
115
|
-
.fact-actions { margin-top: 6px; }
|
|
116
|
-
.nlist { list-style: none; padding: 0; margin: 0; }
|
|
117
|
-
.nlist li { padding: 8px 0; border-bottom: 1px solid var(--line); }
|
|
118
|
-
a.link { color: var(--accent); cursor: pointer; text-decoration: none; }
|
|
119
|
-
a.link:hover { text-decoration: underline; }
|
|
120
|
-
.empty, .hint, .conv-head { color: var(--muted); font-size: 12px; }
|
|
121
|
-
.conv-head { margin: 14px 0 6px; font-weight: 600; }
|
|
122
|
-
.filterbar { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start;
|
|
123
|
-
margin-bottom: 10px; padding: 8px 10px; background: var(--elev); border-radius: 8px; }
|
|
124
|
-
.toolbar { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 8px; }
|
|
125
|
-
#details.on { border-color: var(--accent); color: var(--accent); }
|
|
126
|
-
.meters { display: flex; gap: 10px; margin-top: 6px; }
|
|
127
|
-
.meter { width: 56px; }
|
|
128
|
-
.meter span { display: block; font-size: 10px; color: var(--muted); }
|
|
129
|
-
.meter i { display: block; height: 3px; background: var(--chip); border-radius: 2px; margin-top: 2px; }
|
|
130
|
-
.meter i b { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
|
|
131
|
-
.meter.imp i b { background: var(--mention); }
|
|
132
|
-
.meter.quiet { opacity: 0.4; }
|
|
133
|
-
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--chip); font-size: 11px; }
|
|
134
|
-
#panelTools { position: absolute; top: 10px; right: 12px; z-index: 4; display: flex; gap: 4px; }
|
|
135
|
-
#dockWrap { position: relative; }
|
|
136
|
-
#dockBtn { width: 28px; height: 24px; padding: 2px; display: flex; align-items: center; justify-content: center; }
|
|
137
|
-
#dockMenu { display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
|
|
138
|
-
background: var(--elev); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
|
|
139
|
-
grid-template-columns: 1fr 1fr; gap: 4px; }
|
|
140
|
-
#dockMenu.open { display: grid; }
|
|
141
|
-
#dockMenu button { width: 36px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; }
|
|
142
|
-
#dockMenu button.is-current { opacity: 0.35; pointer-events: none; }
|
|
143
|
-
.dock-ico { display: block; width: 16px; height: 12px; position: relative;
|
|
144
|
-
border: 1.5px solid currentColor; border-radius: 2px; }
|
|
145
|
-
.dock-ico::after { content: ""; position: absolute; background: currentColor; }
|
|
146
|
-
.dock-ico.right::after { top: 0; right: 0; bottom: 0; width: 38%; }
|
|
147
|
-
.dock-ico.left::after { top: 0; left: 0; bottom: 0; width: 38%; }
|
|
148
|
-
.dock-ico.bottom::after { left: 0; right: 0; bottom: 0; height: 38%; }
|
|
149
|
-
.dock-ico.top::after { left: 0; right: 0; top: 0; height: 38%; }
|
|
150
|
-
.views { display: inline-flex; gap: 2px; padding: 3px; background: var(--input);
|
|
151
|
-
border: 1px solid var(--line); border-radius: 9px; }
|
|
152
|
-
.view-btn { border: 1px solid transparent; background: transparent; border-radius: 6px;
|
|
153
|
-
padding: 5px 12px; color: var(--muted); }
|
|
154
|
-
.view-btn.on { border-color: transparent; background: var(--elev); color: var(--accent); font-weight: 600; }
|
|
155
|
-
html.view-spend #stage,
|
|
156
|
-
html:has(#spend:target) #stage { display: none; }
|
|
157
|
-
html.view-spend #spend,
|
|
158
|
-
#spend:target { display: block; }
|
|
159
|
-
html.view-spend .graph-only,
|
|
160
|
-
html:has(#spend:target) .graph-only { display: none; }
|
|
161
|
-
#stage, #spend { grid-row: 2; min-height: 0; }
|
|
162
|
-
#spend {
|
|
163
|
-
display: none; overflow: auto; padding: 20px 24px 48px;
|
|
164
|
-
--card: var(--elev); --ink: var(--text); --gold: var(--mention);
|
|
165
|
-
}
|
|
166
|
-
${SPEND_BOARD_CSS}
|
|
167
|
-
${INTELLIGENCE_ROUTING_CSS}
|
|
168
|
-
</style>
|
|
169
|
-
</head>
|
|
170
|
-
<body>
|
|
171
|
-
<div id="app">
|
|
172
|
-
<header>
|
|
173
|
-
<div class="brand">
|
|
174
|
-
<span class="brand-mark">${LEDGER_MARK_SVG}</span>
|
|
175
|
-
<div class="brand-copy">
|
|
176
|
-
<h1>Facthouse</h1>
|
|
177
|
-
<p class="brand-sub">Inspect</p>
|
|
178
|
-
</div>
|
|
179
|
-
</div>
|
|
180
|
-
<div class="views" role="tablist">
|
|
181
|
-
<button type="button" class="view-btn on" data-view="graph" id="viewGraph">Graph</button>
|
|
182
|
-
<button type="button" class="view-btn" data-view="spend" id="viewSpend">Spend</button>
|
|
183
|
-
</div>
|
|
184
|
-
<div class="meta" id="meta"></div>
|
|
185
|
-
<div class="controls">
|
|
186
|
-
<input id="q" class="graph-only" type="search" placeholder="Find an entity by name"/>
|
|
187
|
-
<select id="type" class="graph-only"><option value="">All types</option></select>
|
|
188
|
-
<button type="button" id="themeBtn" class="icon-btn" title="Toggle colour theme">
|
|
189
|
-
<svg id="themeSun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
|
|
190
|
-
<svg id="themeMoon" viewBox="0 0 24 24" hidden><path d="M21 14.3A8.5 8.5 0 1 1 9.7 3 7 7 0 0 0 21 14.3z"/></svg>
|
|
191
|
-
</button>
|
|
192
|
-
</div>
|
|
193
|
-
</header>
|
|
194
|
-
<div id="stage" class="dock-right">
|
|
195
|
-
<div id="graphwrap">
|
|
196
|
-
<canvas id="cv"></canvas>
|
|
197
|
-
<button id="refocus" type="button" hidden>Refocus</button>
|
|
198
|
-
<div id="graphBar">
|
|
199
|
-
<button id="reset" type="button">Reset</button>
|
|
200
|
-
<label>Show <span id="capLabel">50</span>
|
|
201
|
-
<input id="cap" type="range" min="10" max="200" step="5" value="50"/>
|
|
202
|
-
</label>
|
|
203
|
-
</div>
|
|
204
|
-
<div id="zoom">
|
|
205
|
-
<button id="zoomIn" type="button" title="Zoom in">+</button>
|
|
206
|
-
<button id="zoomOut" type="button" title="Zoom out">−</button>
|
|
207
|
-
<button id="zoomFit" type="button" title="Fit">⤢</button>
|
|
208
|
-
</div>
|
|
209
|
-
</div>
|
|
210
|
-
<div id="splitter"></div>
|
|
211
|
-
<aside>
|
|
212
|
-
<div id="panelTools">
|
|
213
|
-
<button type="button" id="details" class="icon-btn" title="Show extra fields on cards">
|
|
214
|
-
<svg viewBox="0 0 24 24"><path d="M4 7h10M4 12h16M4 17h7"/><circle cx="18.5" cy="7" r="2"/></svg>
|
|
215
|
-
</button>
|
|
216
|
-
<div id="dockWrap">
|
|
217
|
-
<button type="button" id="dockBtn" title="Move panel"><span id="dockBtnIco" class="dock-ico right"></span></button>
|
|
218
|
-
<div id="dockMenu" hidden>
|
|
219
|
-
<button type="button" data-dock="left" title="Left"><span class="dock-ico left"></span></button>
|
|
220
|
-
<button type="button" data-dock="right" title="Right"><span class="dock-ico right"></span></button>
|
|
221
|
-
<button type="button" data-dock="top" title="Top"><span class="dock-ico top"></span></button>
|
|
222
|
-
<button type="button" data-dock="bottom" title="Bottom"><span class="dock-ico bottom"></span></button>
|
|
223
|
-
</div>
|
|
224
|
-
</div>
|
|
225
|
-
</div>
|
|
226
|
-
<div class="who" id="who"></div>
|
|
227
|
-
<div class="tabs" id="tabs"></div>
|
|
228
|
-
<div class="body" id="body"></div>
|
|
229
|
-
</aside>
|
|
230
|
-
</div>
|
|
231
|
-
<div id="spend">${spendHtml}${routingHtml}</div>
|
|
232
|
-
</div>
|
|
233
|
-
<script>
|
|
234
|
-
const DATA = ${json};
|
|
235
|
-
function setInspectView(v){
|
|
236
|
-
document.documentElement.classList.toggle("view-spend", v==="spend");
|
|
237
|
-
document.querySelectorAll(".view-btn").forEach(function(b){
|
|
238
|
-
b.classList.toggle("on", b.getAttribute("data-view")===v);
|
|
239
|
-
});
|
|
240
|
-
if (v==="spend") location.hash="spend";
|
|
241
|
-
else if (location.hash==="#spend") location.hash="graph";
|
|
242
|
-
}
|
|
243
|
-
document.querySelectorAll(".view-btn").forEach(function(b){
|
|
244
|
-
b.addEventListener("click", function(){ setInspectView(b.getAttribute("data-view")); });
|
|
245
|
-
});
|
|
246
|
-
window.addEventListener("hashchange", function(){
|
|
247
|
-
setInspectView(location.hash==="#spend" ? "spend" : "graph");
|
|
248
|
-
});
|
|
249
|
-
if (location.hash==="#spend") setInspectView("spend");
|
|
250
|
-
const SUBJECT = "subject_of";
|
|
251
|
-
const NEAR_USER = 8;
|
|
252
|
-
const NEAR_RADIUS = 3;
|
|
253
|
-
function hue(s){let h=0;for(let i=0;i<s.length;i++)h=(h*33+s.charCodeAt(i))>>>0;return h%360;}
|
|
254
|
-
function colour(type){const map={person:"#7eb889",organisation:"#6aa8c9",organization:"#6aa8c9",project:"#c4a35a",place:"#9b8fd4",product:"#d08b6a"};if(map[type])return map[type];return "hsl("+hue(type||"?")+" 28% 48%)";}
|
|
255
|
-
function esc(s){return String(s??"").replace(/[&<>"'']/g,c=>({"&":"&","<":"<",">":">","\\"":""","'":"'"}[c]));}
|
|
256
|
-
const byId=new Map((DATA.nodes||[]).map(n=>[n.id,n]));
|
|
257
|
-
const factById=new Map((DATA.facts||[]).map(f=>[f.id,f]));
|
|
258
|
-
const eventById=new Map((DATA.events||[]).map(e=>[e.id,e]));
|
|
259
|
-
const infoById=new Map((DATA.info||[]).map(i=>[i.id,i]));
|
|
260
|
-
const sourceById=new Map((DATA.sources||[]).map(s=>[s.id,s]));
|
|
261
|
-
const dForI=new Map();
|
|
262
|
-
for(const row of DATA.iToD||[]){if(!dForI.has(row.session_fact_id))dForI.set(row.session_fact_id,[]);dForI.get(row.session_fact_id).push(row);}
|
|
263
|
-
const eventsByConv=new Map();
|
|
264
|
-
for(const e of DATA.events||[]){const c=e.conversation||"";if(!eventsByConv.has(c))eventsByConv.set(c,[]);eventsByConv.get(c).push(e.id);}
|
|
265
|
-
const linksByEntity=new Map();
|
|
266
|
-
for(const l of DATA.links||[]){if(!linksByEntity.has(l.entity_id))linksByEntity.set(l.entity_id,[]);linksByEntity.get(l.entity_id).push(l);}
|
|
267
|
-
const typeSel=document.getElementById("type");
|
|
268
|
-
for(const t of [...new Set((DATA.nodes||[]).map(n=>n.type))].sort()){const o=document.createElement("option");o.value=t;o.textContent=t;typeSel.appendChild(o);}
|
|
269
|
-
document.getElementById("meta").textContent=(DATA.nodes||[]).length+" entities · "+(DATA.facts||[]).length+" facts · "+(DATA.eventCount||0)+" raw events";
|
|
270
|
-
function sharedCount(a,b){const fa=new Set((linksByEntity.get(a)||[]).map(l=>l.fact_id));let n=0;const seen=new Set();for(const l of linksByEntity.get(b)||[]){if(fa.has(l.fact_id)&&!seen.has(l.fact_id)){seen.add(l.fact_id);n++;}}return n;}
|
|
271
|
-
function egoIds(centerId,cap,typeFilter){
|
|
272
|
-
const scores=new Map();
|
|
273
|
-
for(const e of DATA.edges||[]){if(e.from===centerId)scores.set(e.to,(scores.get(e.to)||0)+10*e.strength);if(e.to===centerId)scores.set(e.from,(scores.get(e.from)||0)+10*e.strength);}
|
|
274
|
-
for(const n of DATA.nodes||[]){if(n.id===centerId)continue;const sh=sharedCount(centerId,n.id);if(sh)scores.set(n.id,(scores.get(n.id)||0)+sh);}
|
|
275
|
-
const ranked=[...scores.entries()].sort((a,b)=>b[1]-a[1]).map(([id])=>byId.get(id)).filter(Boolean).filter(n=>!typeFilter||n.type===typeFilter||n.id===centerId);
|
|
276
|
-
const ids=new Set([centerId]);for(const n of ranked){if(ids.size>=cap)break;ids.add(n.id);}return ids;
|
|
277
|
-
}
|
|
278
|
-
function visibleIds(cap,query,typeFilter,center,focused){
|
|
279
|
-
const q=query.trim().toLowerCase();
|
|
280
|
-
let focus=center||null;
|
|
281
|
-
if(!focus&&q){focus=(DATA.nodes||[]).find(n=>n.name.toLowerCase()===q||n.canonical_name===q)||(DATA.nodes||[]).find(n=>n.name.toLowerCase().includes(q)||n.canonical_name.includes(q))||null;}
|
|
282
|
-
if(focused&&focus)return {ids:egoIds(focus.id,cap,typeFilter),focus};
|
|
283
|
-
const ranked=[...(DATA.nodes||[])].sort((a,b)=>b.degree-a.degree||a.name.localeCompare(b.name));
|
|
284
|
-
const ids=new Set();for(const n of ranked){if(ids.size>=cap)break;if(typeFilter&&n.type!==typeFilter)continue;ids.add(n.id);}
|
|
285
|
-
if(focus)ids.add(focus.id);return {ids,focus};
|
|
286
|
-
}
|
|
287
|
-
const cv=document.getElementById("cv");const ctx=cv.getContext("2d");
|
|
288
|
-
let cam={x:0,y:0,k:1},sim=[],selected=null,selectedEdge=null,focusMode=false,focusedId=null,tab="knowledge",tabFilter=null,dataNewest=false,showDetails=false,dragging=null,lastPan=null,down=null,hotSet=null,anim=0,cooling=0,frames=0,fitAfterAnim=false;
|
|
289
|
-
try{showDetails=localStorage.getItem("om-inspect-details")==="1";}catch(e){}
|
|
290
|
-
if(DATA.selectedId)selected=byId.get(DATA.selectedId)||null;
|
|
291
|
-
if(selected)focusMode=true,focusedId=selected.id;
|
|
292
|
-
const capEl=document.getElementById("cap");
|
|
293
|
-
if(DATA.cap){capEl.value=String(Math.min(200,Math.max(10,DATA.cap)));document.getElementById("capLabel").textContent=capEl.value;}
|
|
294
|
-
function radius(n){return 4+Math.min(14,Math.sqrt(n.degree||1)*2.2);}
|
|
295
|
-
function markHot(id){hotSet=new Set([id]);for(const e of DATA.edges||[]){if(e.from===id)hotSet.add(e.to);if(e.to===id)hotSet.add(e.from);}}
|
|
296
|
-
function startLayout(ids,opts){
|
|
297
|
-
const fresh=opts&&opts.fresh;const nodes=[...ids].map(id=>byId.get(id)).filter(Boolean);
|
|
298
|
-
const old=fresh?new Map():new Map(sim.map(p=>[p.id,p]));
|
|
299
|
-
const origin=(selected&&old.get(selected.id))||{x:0,y:0};
|
|
300
|
-
sim=nodes.map((n,i)=>{const p=old.get(n.id);if(p)return {...n,x:p.x,y:p.y,vx:0,vy:0};
|
|
301
|
-
const ang=(i/Math.max(nodes.length,1))*Math.PI*2;
|
|
302
|
-
if(old.size===0)return {...n,x:Math.cos(ang)*280,y:Math.sin(ang)*280,vx:0,vy:0};
|
|
303
|
-
const j=Math.random()*Math.PI*2;return {...n,x:origin.x+Math.cos(j)*24,y:origin.y+Math.sin(j)*24,vx:Math.cos(j)*3,vy:Math.sin(j)*3};});
|
|
304
|
-
cooling=1;frames=0;if(!anim)anim=requestAnimationFrame(tick);
|
|
305
|
-
}
|
|
306
|
-
function stepPhysics(){
|
|
307
|
-
const pmap=new Map(sim.map(p=>[p.id,p]));const idSet=new Set(sim.map(n=>n.id));
|
|
308
|
-
const links=(DATA.edges||[]).filter(e=>idSet.has(e.from)&&idSet.has(e.to));
|
|
309
|
-
for(let i=0;i<sim.length;i++)for(let j=i+1;j<sim.length;j++){
|
|
310
|
-
let dx=sim[j].x-sim[i].x,dy=sim[j].y-sim[i].y,d=Math.hypot(dx,dy)||0.01;
|
|
311
|
-
const minD=radius(sim[i])+radius(sim[j])+22;let f=420/(d*d);if(d<minD)f+=(minD-d)*0.22;
|
|
312
|
-
const fx=f*dx/d,fy=f*dy/d;sim[i].vx-=fx;sim[i].vy-=fy;sim[j].vx+=fx;sim[j].vy+=fy;
|
|
313
|
-
}
|
|
314
|
-
for(const e of links){const a=pmap.get(e.from),b=pmap.get(e.to);if(!a||!b)continue;
|
|
315
|
-
let dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||0.01,f=(d-130)*0.035;
|
|
316
|
-
a.vx+=f*dx/d;a.vy+=f*dy/d;b.vx-=f*dx/d;b.vy-=f*dy/d;}
|
|
317
|
-
let energy=0;for(const p of sim){p.vx*=0.72;p.vy*=0.72;const sp=Math.hypot(p.vx,p.vy);if(sp>18){p.vx*=18/sp;p.vy*=18/sp;}p.x+=p.vx;p.y+=p.vy;energy+=p.vx*p.vx+p.vy*p.vy;}
|
|
318
|
-
return energy;
|
|
319
|
-
}
|
|
320
|
-
function tick(){frames++;let energy=0;for(let s=0;s<8;s++)energy=stepPhysics();cooling*=0.86;draw();
|
|
321
|
-
if(frames<32&&(cooling>0.12||energy>12))anim=requestAnimationFrame(tick);else{anim=0;if(fitAfterAnim){fitView();fitAfterAnim=false;}}}
|
|
322
|
-
function draw(){
|
|
323
|
-
const w=cv.clientWidth,h=cv.clientHeight;ctx.clearRect(0,0,w,h);ctx.save();ctx.translate(w/2+cam.x,h/2+cam.y);ctx.scale(cam.k,cam.k);
|
|
324
|
-
const css=getComputedStyle(document.documentElement);
|
|
325
|
-
const labelBg=css.getPropertyValue("--canvas-label").trim();const labelFg=css.getPropertyValue("--canvas-label-text").trim();const selStroke=css.getPropertyValue("--text").trim();
|
|
326
|
-
const idSet=new Set(sim.map(n=>n.id));const pmap=new Map(sim.map(p=>[p.id,p]));
|
|
327
|
-
for(const e of DATA.edges||[]){if(!idSet.has(e.from)||!idSet.has(e.to))continue;const a=pmap.get(e.from),b=pmap.get(e.to);
|
|
328
|
-
const edgeOn=selectedEdge&&((selectedEdge.from===e.from&&selectedEdge.to===e.to)||(selectedEdge.from===e.to&&selectedEdge.to===e.from));
|
|
329
|
-
const hot=edgeOn||(selected&&(e.from===selected.id||e.to===selected.id));
|
|
330
|
-
const gold=css.getPropertyValue("--accent").trim()||"#c4a35a";const muted=css.getPropertyValue("--muted").trim()||"#9a9486";
|
|
331
|
-
ctx.strokeStyle=edgeOn?gold:hot?gold:muted;ctx.globalAlpha=edgeOn?0.9:hot?0.55:0.22;
|
|
332
|
-
ctx.lineWidth=edgeOn?2.4:hot?1.6:0.6+e.strength;ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.lineTo(b.x,b.y);ctx.stroke();ctx.globalAlpha=1;}
|
|
333
|
-
for(const n of sim){const r=radius(n);ctx.beginPath();ctx.fillStyle=colour(n.type);
|
|
334
|
-
const dim=selected&&selected.id!==n.id&&!selectedEdge&&hotSet&&!hotSet.has(n.id);ctx.globalAlpha=dim?0.35:1;ctx.arc(n.x,n.y,r,0,Math.PI*2);ctx.fill();ctx.globalAlpha=1;
|
|
335
|
-
if((selected&&selected.id===n.id)||(selectedEdge&&(selectedEdge.from===n.id||selectedEdge.to===n.id))){ctx.strokeStyle=selStroke||"#fff";ctx.lineWidth=2;ctx.stroke();}
|
|
336
|
-
if(cam.k>0.85||(selected&&selected.id===n.id)||n.degree>=8){const label=n.name.length>28?n.name.slice(0,27)+"…":n.name;ctx.font="11px ui-sans-serif, system-ui, sans-serif";
|
|
337
|
-
const tw=ctx.measureText(label).width;ctx.fillStyle=labelBg||"rgba(14,18,24,0.75)";ctx.fillRect(n.x+r+3,n.y-8,tw+6,14);ctx.fillStyle=labelFg||"#e7edf5";ctx.fillText(label,n.x+r+6,n.y+3);}}
|
|
338
|
-
ctx.restore();syncRefocus();
|
|
339
|
-
}
|
|
340
|
-
function screenToWorld(sx,sy){return {x:(sx-cv.clientWidth/2-cam.x)/cam.k,y:(sy-cv.clientHeight/2-cam.y)/cam.k};}
|
|
341
|
-
function hitNode(sx,sy){const p=screenToWorld(sx,sy);let best=null,bestD=1e9;for(const n of sim){const d=Math.hypot(n.x-p.x,n.y-p.y);if(d<radius(n)+4&&d<bestD){best=n;bestD=d;}}return best;}
|
|
342
|
-
function hitEdge(sx,sy){const p=screenToWorld(sx,sy);const pmap=new Map(sim.map(n=>[n.id,n]));let best=null,bestD=8/cam.k;
|
|
343
|
-
for(const e of DATA.edges||[]){const a=pmap.get(e.from),b=pmap.get(e.to);if(!a||!b)continue;const dx=b.x-a.x,dy=b.y-a.y,l2=dx*dx+dy*dy||1;let t=((p.x-a.x)*dx+(p.y-a.y)*dy)/l2;t=Math.max(0,Math.min(1,t));
|
|
344
|
-
const d=Math.hypot(p.x-(a.x+t*dx),p.y-(a.y+t*dy));if(d<bestD){best=e;bestD=d;}}return best;}
|
|
345
|
-
function isEndedFact(f){return f.status==="superseded"||!!f.valid_until||f.is_latest===0||f.is_latest===false;}
|
|
346
|
-
function factsForEntity(id){
|
|
347
|
-
const rows=(linksByEntity.get(id)||[]).map(l=>({rel:l.relationship,fact:factById.get(l.fact_id)})).filter(x=>x.fact);
|
|
348
|
-
const seen=new Set(),about=[],mentions=[];
|
|
349
|
-
for(const r of rows){if(seen.has(r.fact.id))continue;seen.add(r.fact.id);const isAbout=rows.some(x=>x.fact.id===r.fact.id&&x.rel===SUBJECT);(isAbout?about:mentions).push(r.fact);}
|
|
350
|
-
const byRank=(a,b)=>{const ae=isEndedFact(a)?1:0,be=isEndedFact(b)?1:0;if(ae!==be)return ae-be;return (b.importance||0)-(a.importance||0);};
|
|
351
|
-
about.sort(byRank);mentions.sort(byRank);return {about,mentions};
|
|
352
|
-
}
|
|
353
|
-
function day(iso){if(!iso)return "";const s=String(iso);if(/T00:00:00/.test(s))return s.slice(0,10);return s.slice(0,19).replace("T"," ");}
|
|
354
|
-
function clock(iso){if(!iso)return "";const s=String(iso);if(/T00:00:00/.test(s))return s.slice(0,10);const m=s.match(/T(\\d{2}:\\d{2})/);return m?m[1]:day(iso);}
|
|
355
|
-
function eventWhen(e){return e.occurred_at||e.created_at||"";}
|
|
356
|
-
function toolLabel(e){if(e.tool_name)return "Tool "+e.tool_name;if(e.event_type==="tool_call"||e.event_type==="tool_result"||e.role==="tool")return "Tool";if(e.role==="user")return "User";if(e.role==="assistant")return "Assistant";return e.role||"event";}
|
|
357
|
-
function pct(n){if(n==null||n==="")return "";const x=Number(n);if(Number.isNaN(x))return esc(n);return Math.round(x*100)+"%";}
|
|
358
|
-
function validityLabel(f){const from=day(f.valid_from);if(f.status==="superseded"||f.valid_until)return (from||day(f.created_at))+" – "+(day(f.valid_until)||"ended");if(from)return from+" – present";return day(f.created_at)||"";}
|
|
359
|
-
function meterHtml(kind,value){if(value==null||value==="")return "";const x=Number(value);if(!Number.isFinite(x))return "";const def=kind==="imp"?0.5:0.7;const quiet=Math.abs(x-def)<0.051?" quiet":"";
|
|
360
|
-
return "<div class='meter"+(kind==="imp"?" imp":"")+quiet+"' title='"+(kind==="imp"?"importance ":"confidence ")+pct(x)+"'><span>"+(kind==="imp"?"imp":"conf")+"</span><i><b style='width:"+Math.round(x*100)+"%'></b></i></div>";}
|
|
361
|
-
function iIdForFact(factId){const fact=factById.get(factId);const src=fact&&sourceById.get(fact.source_id);return (src&&src.session_fact_id)||null;}
|
|
362
|
-
function expandEventIds(ids){const set=new Set(ids);for(const id of ids){const hit=eventById.get(id);if(!hit)continue;let nearest=null;
|
|
363
|
-
for(const eid of eventsByConv.get(hit.conversation||"")||[]){const ev=eventById.get(eid);if(!ev)continue;if(Math.abs(ev.sequence-hit.sequence)<=NEAR_RADIUS)set.add(ev.id);
|
|
364
|
-
if(ev.role==="user"&&ev.sequence<=hit.sequence&&hit.sequence-ev.sequence<=NEAR_USER)nearest=ev;}if(nearest)set.add(nearest.id);}return [...set];}
|
|
365
|
-
const dataIdsCache=new Map();
|
|
366
|
-
function dataIdsForI(iId){const key=iId+":"+(selected?selected.id:"");if(dataIdsCache.has(key))return dataIdsCache.get(key);
|
|
367
|
-
const rows=dForI.get(iId)||[];const primary=rows.filter(r=>r.extraction_type!=="contextual").map(r=>r.event_id).filter(id=>eventById.has(id));
|
|
368
|
-
let ids;if(primary.length)ids=expandEventIds(primary);else{const irow=infoById.get(iId);const conv=irow&&irow.session_id;const convIds=conv?(eventsByConv.get(conv)||[]):[];
|
|
369
|
-
const around=selected?(DATA.dByEntity[selected.id]||[]):[];const aroundSet=new Set(around);const overlap=convIds.filter(id=>aroundSet.has(id));ids=overlap.length?expandEventIds(overlap):[...new Set(convIds)];}
|
|
370
|
-
dataIdsCache.set(key,ids);return ids;}
|
|
371
|
-
function factCard(f,flag,kind){
|
|
372
|
-
const superseded=f.status==="superseded";const expired=!superseded&&!!f.valid_until;const when=validityLabel(f);
|
|
373
|
-
const meters=showDetails?"<div class='meters'>"+meterHtml("conf",f.confidence)+meterHtml("imp",f.importance)+"</div>":"";
|
|
374
|
-
let drill="";if(kind==="k"&&f.source_id){const iid=iIdForFact(f.id);drill=iid&&infoById.has(iid)?" <a class='link jump-i' data-id='"+esc(f.id)+"'>Show Information</a>":"";}
|
|
375
|
-
if(kind==="i"&&f.id){const n=dataIdsForI(f.id).length;drill=n?" <a class='link jump-d' data-iid='"+esc(f.id)+"'>Show Data ("+n+")</a>":" <span class='dom'>No Data in this snapshot</span>";}
|
|
376
|
-
const ended=superseded?"<span class='chip'>superseded</span>":expired?"<span class='chip'>no longer valid</span>":"";
|
|
377
|
-
const klass=superseded?" superseded":expired?" expired":"";
|
|
378
|
-
return "<div class='fact"+klass+"'><div class='fact-head'><div class='fact-left'><span class='flag"+(flag==="mention"?" mention":"")+"'>"+flag+"</span>"+ended+(f.domain||f.domain_hint?"<span class='dom'>"+esc(f.domain||f.domain_hint)+"</span>":"")+"</div>"+(when?"<span class='when'>"+esc(when)+"</span>":"")+"</div><div>"+esc(f.content)+"</div>"+meters+(drill?"<div class='fact-actions'>"+drill+"</div>":"")+"</div>";
|
|
379
|
-
}
|
|
380
|
-
function eventBlock(e,extra){if(!e)return "";const more=e.full?" <a class='link more' data-id='"+esc(e.id)+"'>Expand</a>":"";const chip=extra?"<span class='chip'>"+esc(extra)+"</span>":"";const time=clock(eventWhen(e));
|
|
381
|
-
return "<div class='fact' data-eid='"+esc(e.id)+"'><div class='fact-head'><div class='fact-left'><span class='flag mention'>"+esc(toolLabel(e))+"</span>"+chip+"</div>"+(time?"<span class='when'>"+esc(time)+"</span>":"")+"</div><div class='txt'>"+esc(e.content)+"</div>"+more+"</div>";}
|
|
382
|
-
function convLabel(group){const first=group[0],last=group[group.length-1];const a=day(eventWhen(first)),b=day(eventWhen(last));
|
|
383
|
-
const when=a&&b&&a.slice(0,10)!==b.slice(0,10)?a+" – "+b:(a||b||"Conversation");return when+" · "+group.length+(group.length===1?" line":" lines");}
|
|
384
|
-
function renderEventList(ids,extraById){const seen=new Set(),events=[];for(const id of ids){if(seen.has(id))continue;const e=eventById.get(id);if(!e)continue;seen.add(id);events.push(e);}
|
|
385
|
-
const byConv=new Map();for(const e of events){const c=e.conversation||"";if(!byConv.has(c))byConv.set(c,[]);byConv.get(c).push(e);}
|
|
386
|
-
const groups=[...byConv.values()];for(const g of groups)g.sort((a,b)=>a.sequence-b.sequence);
|
|
387
|
-
groups.sort((a,b)=>(eventWhen(a[0])||"").localeCompare(eventWhen(b[0])||"")||a[0].sequence-b[0].sequence);
|
|
388
|
-
if(dataNewest){groups.reverse();for(const g of groups)g.reverse();}
|
|
389
|
-
if(!groups.length)return "<p class='empty'>No transcript lines in this snapshot.</p>";
|
|
390
|
-
let html="";for(const g of groups){html+="<p class='conv-head'>"+esc(convLabel(g))+"</p>";for(const e of g)html+=eventBlock(e,extraById&&extraById.get(e.id));}return html;}
|
|
391
|
-
function bindPanel(root){root.querySelectorAll("a.more").forEach(a=>a.onclick=ev=>{ev.preventDefault();const e=eventById.get(a.getAttribute("data-id"));const card=a.parentElement&&a.parentElement.querySelector(".txt");if(!e||!card)return;const open=a.textContent==="Expand";card.textContent=open?e.full:e.content;a.textContent=open?"Collapse":"Expand";});
|
|
392
|
-
root.querySelectorAll("a.jump-i").forEach(a=>a.onclick=ev=>{ev.preventDefault();const fact=factById.get(a.getAttribute("data-id"));tabFilter={tab:"information",iId:iIdForFact(fact&&fact.id),fromFactId:fact&&fact.id,snippet:fact?String(fact.content||"").slice(0,88):""};tab="information";render();});
|
|
393
|
-
root.querySelectorAll("a.jump-d").forEach(a=>a.onclick=ev=>{ev.preventDefault();const iId=a.getAttribute("data-iid");const irow=infoById.get(iId);tabFilter={tab:"data",iId,eventIds:dataIdsForI(iId),snippet:irow?String(irow.content||"").slice(0,88):""};tab="data";render();});}
|
|
394
|
-
function render(){syncRefocus();const who=document.getElementById("who"),tabs=document.getElementById("tabs"),body=document.getElementById("body");
|
|
395
|
-
if(selectedEdge){const a=byId.get(selectedEdge.from),b=byId.get(selectedEdge.to);const fa=new Set((linksByEntity.get(selectedEdge.from)||[]).map(l=>l.fact_id));const shared=[];const seen=new Set();
|
|
396
|
-
for(const l of linksByEntity.get(selectedEdge.to)||[]){if(fa.has(l.fact_id)&&!seen.has(l.fact_id)){seen.add(l.fact_id);const f=factById.get(l.fact_id);if(f)shared.push(f);}}
|
|
397
|
-
who.innerHTML="<h2>Link</h2><div class='type'><a class='link go' data-id='"+esc(a&&a.id)+"'>"+esc(a&&a.name)+"</a> ↔ <a class='link go' data-id='"+esc(b&&b.id)+"'>"+esc(b&&b.name)+"</a></div>";
|
|
398
|
-
tabs.innerHTML="";body.innerHTML=shared.length?shared.map(f=>factCard(f,"names both","k")).join(""):"<p class='empty'>No current fact names both.</p>";bindPanel(body);
|
|
399
|
-
who.querySelectorAll("a.go").forEach(el=>el.onclick=()=>{const t=byId.get(el.getAttribute("data-id"));if(!t)return;selected=t;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(t.id);render();draw();});return;}
|
|
400
|
-
if(!selected){who.innerHTML="<h2>Nothing selected</h2><div class='type'>Click a node or an edge, or search by name.</div>";tabs.innerHTML="";
|
|
401
|
-
body.innerHTML="<p>The picture is the entity graph. Knowledge lives on the facts. Select something to read it.</p>";return;}
|
|
402
|
-
const n=selected;const fk=factsForEntity(n.id);const dIds=DATA.dByEntity[n.id]||[];const needle=(n.canonical_name||n.name||"").toLowerCase();
|
|
403
|
-
const info=(DATA.info||[]).filter(p=>(p.content||"").toLowerCase().includes(needle));
|
|
404
|
-
const kNow=fk.about.filter(f=>!isEndedFact(f)).length+fk.mentions.filter(f=>!isEndedFact(f)).length;
|
|
405
|
-
who.innerHTML="<h2>"+esc(n.name)+"</h2><div class='type'>"+esc(n.type)+" · "+n.about+" facts about it · "+n.mentions+" mentions</div>";
|
|
406
|
-
tabs.innerHTML="<button class='tab"+(tab==="knowledge"?" on":"")+"' data-t='knowledge'>Knowledge ("+kNow+")</button>"+
|
|
407
|
-
"<button class='tab"+(tab==="information"?" on":"")+"' data-t='information'>Information ("+info.length+")</button>"+
|
|
408
|
-
"<button class='tab"+(tab==="data"?" on":"")+"' data-t='data'>Data ("+(n.dCount!=null?n.dCount:dIds.length)+")</button>"+
|
|
409
|
-
"<button class='tab"+(tab==="links"?" on":"")+"' data-t='links'>Links</button>";
|
|
410
|
-
tabs.querySelectorAll(".tab").forEach(btn=>btn.onclick=()=>{tab=btn.getAttribute("data-t");if(!tabFilter||tabFilter.tab!==tab)tabFilter=null;render();});
|
|
411
|
-
if(tab==="knowledge"){const aboutNow=fk.about.filter(f=>!isEndedFact(f)),aboutOld=fk.about.filter(f=>isEndedFact(f)),menNow=fk.mentions.filter(f=>!isEndedFact(f)),menOld=fk.mentions.filter(f=>isEndedFact(f));
|
|
412
|
-
let html="";if(aboutNow.length)html+="<p class='hint'>About this entity</p>"+aboutNow.map(f=>factCard(f,"about","k")).join("");
|
|
413
|
-
if(menNow.length)html+="<p class='hint'>Mentions</p>"+menNow.map(f=>factCard(f,"mention","k")).join("");
|
|
414
|
-
if(aboutOld.length||menOld.length)html+="<p class='hint'>No longer current</p>"+aboutOld.concat(menOld).map(f=>factCard(f,f.status==="superseded"?"superseded":"ended","k")).join("");
|
|
415
|
-
if(!html)html="<p class='empty'>No current fact is attached to this entity.</p>";body.innerHTML=html;bindPanel(body);}
|
|
416
|
-
else if(tab==="data"){const filtered=tabFilter&&tabFilter.tab==="data";const showIds=filtered?(tabFilter.eventIds||[]):dIds;
|
|
417
|
-
let html="";if(filtered)html+="<div class='filterbar'><div><div class='filterbar-title'>Showing "+showIds.length+" Data</div></div><button type='button' id='clearFilter'>Clear filter</button></div>";
|
|
418
|
-
html+="<div class='toolbar'><a class='link' id='dataSort'>"+(dataNewest?"Oldest first":"Newest first")+"</a></div>";
|
|
419
|
-
if(!filtered&&n.dCount!=null&&n.dCount!==dIds.length)html+=n.dCount>dIds.length?"<p class='hint'>Listing "+dIds.length+" of "+n.dCount+" lines that name this in the store.</p>":"<p class='hint'>Listing "+dIds.length+" lines; "+n.dCount+" name this, the rest are nearby turns.</p>";
|
|
420
|
-
html+=showIds.length?renderEventList(showIds,null):"<p class='empty'>No raw events in this snapshot mention this name. The store has "+DATA.eventCount+" events; this file includes "+DATA.eventShown+" with text.</p>";
|
|
421
|
-
body.innerHTML=html;bindPanel(body);const cf=document.getElementById("clearFilter");if(cf)cf.onclick=()=>{tabFilter=null;render();};
|
|
422
|
-
const ds=document.getElementById("dataSort");if(ds)ds.onclick=ev=>{ev.preventDefault();dataNewest=!dataNewest;render();};}
|
|
423
|
-
else if(tab==="information"){const card=(p,flag)=>factCard({id:p.id,content:p.content,domain_hint:p.domain_hint,confidence:p.confidence,importance:p.importance,speaker:p.speaker,speaker_role:p.speaker_role,created_at:p.created_at,valid_from:p.valid_from_hint,valid_until:p.valid_until_hint,source_origin:p.source_origin,source_quality:p.source_quality},flag,"i");
|
|
424
|
-
const filtered=tabFilter&&tabFilter.tab==="information";const rows=filtered?(tabFilter.iId&&infoById.get(tabFilter.iId)?[infoById.get(tabFilter.iId)]:[]):info;
|
|
425
|
-
let html="";if(filtered)html+="<div class='filterbar'><div><div class='filterbar-title'>Showing "+rows.length+" of "+info.length+" Information</div></div><button type='button' id='clearFilter'>Clear filter</button></div>";
|
|
426
|
-
if(!rows.length)html+=filtered?"<p class='empty'>No extracted sentence is linked to that Knowledge.</p>":"<p class='empty'>No extracted sentences for this name.</p>";
|
|
427
|
-
else html+=rows.map(p=>card(p,p.consolidation_id?"extracted":"waiting")).join("");
|
|
428
|
-
body.innerHTML=html;bindPanel(body);const cf=document.getElementById("clearFilter");if(cf)cf.onclick=()=>{tabFilter=null;render();};}
|
|
429
|
-
else{const inc=(DATA.edges||[]).filter(e=>e.from===n.id||e.to===n.id).sort((a,b)=>b.strength-a.strength);const seen=new Set();const neigh=[];
|
|
430
|
-
for(const e of inc){const other=e.from===n.id?e.to:e.from;if(seen.has(other))continue;seen.add(other);neigh.push({id:other,edge:e});if(neigh.length>=15)break;}
|
|
431
|
-
if(!neigh.length)body.innerHTML="<p class='empty'>No co-mention edges from this node.</p>";
|
|
432
|
-
else{body.innerHTML="<ul class='nlist'>"+neigh.map(x=>{const o=byId.get(x.id);return "<li><a class='link go' data-id='"+x.id+"'>"+esc(o&&o.name)+"</a> · "+esc(o&&o.type)+" · strength "+x.edge.strength.toFixed(2)+"</li>";}).join("")+"</ul>";
|
|
433
|
-
body.querySelectorAll("a.go").forEach(a=>a.onclick=()=>{const t=byId.get(a.getAttribute("data-id"));if(!t)return;selected=t;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(t.id);render();draw();});}}
|
|
434
|
-
}
|
|
435
|
-
function rebuild(resetCam){const cap=Number(document.getElementById("cap").value);document.getElementById("capLabel").textContent=String(cap);
|
|
436
|
-
const vis=visibleIds(cap,document.getElementById("q").value,document.getElementById("type").value,selected,focusMode);
|
|
437
|
-
startLayout(vis.ids,{fresh:!!resetCam});if(vis.focus)selected=vis.focus;else if(selected&&!vis.ids.has(selected.id))selected=null;syncRefocus();if(resetCam)cam={x:0,y:0,k:1};}
|
|
438
|
-
function selectedOnScreen(){if(!selected)return true;const p=sim.find(n=>n.id===selected.id);if(!p)return false;const sx=cv.clientWidth/2+cam.x+p.x*cam.k,sy=cv.clientHeight/2+cam.y+p.y*cam.k;const m=48;return sx>m&&sy>m&&sx<cv.clientWidth-m&&sy<cv.clientHeight-m;}
|
|
439
|
-
function syncRefocus(){const btn=document.getElementById("refocus");if(!selected){btn.hidden=true;return;}
|
|
440
|
-
if(selected.id!==focusedId){btn.textContent="Refocus";btn.dataset.mode="rebuild";btn.hidden=false;}
|
|
441
|
-
else if(!selectedOnScreen()){btn.textContent="Recentre";btn.dataset.mode="centre";btn.hidden=false;}else btn.hidden=true;}
|
|
442
|
-
function recenter(){if(!selected)return;const p=sim.find(n=>n.id===selected.id);if(!p)return;cam.x=-p.x*cam.k;cam.y=-p.y*cam.k;draw();syncRefocus();}
|
|
443
|
-
function refocus(){if(!selected)return;focusMode=true;focusedId=selected.id;fitAfterAnim=true;rebuild(false);fitView();render();syncRefocus();}
|
|
444
|
-
function fitView(){if(!sim.length)return;let minx=Infinity,maxx=-Infinity,miny=Infinity,maxy=-Infinity;for(const p of sim){const r=radius(p);minx=Math.min(minx,p.x-r);maxx=Math.max(maxx,p.x+r+96);miny=Math.min(miny,p.y-r-10);maxy=Math.max(maxy,p.y+r+10);}
|
|
445
|
-
const pad=16,w=Math.max(cv.clientWidth-pad*2,1),h=Math.max(cv.clientHeight-pad*2,1),bw=Math.max(maxx-minx,1),bh=Math.max(maxy-miny,1);
|
|
446
|
-
cam.k=Math.max(0.2,Math.min(6,Math.min(w/bw,h/bh)));cam.x=-((minx+maxx)/2)*cam.k;cam.y=-((miny+maxy)/2)*cam.k;draw();}
|
|
447
|
-
function zoomBy(f){cam.k=Math.min(8,Math.max(0.15,cam.k*f));draw();}
|
|
448
|
-
function resize(){const r=cv.getBoundingClientRect();cv.width=r.width*devicePixelRatio;cv.height=r.height*devicePixelRatio;ctx.setTransform(devicePixelRatio,0,0,devicePixelRatio,0,0);draw();}
|
|
449
|
-
cv.addEventListener("mousedown",ev=>{const n=hitNode(ev.offsetX,ev.offsetY);down={x:ev.offsetX,y:ev.offsetY,n,e:n?null:hitEdge(ev.offsetX,ev.offsetY)};});
|
|
450
|
-
cv.addEventListener("dblclick",ev=>{ev.preventDefault();const n=hitNode(ev.offsetX,ev.offsetY);if(n){selected=n;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(n.id);refocus();}});
|
|
451
|
-
window.addEventListener("mousemove",ev=>{if(!down&&!dragging&&!lastPan)return;const rect=cv.getBoundingClientRect();const x=ev.clientX-rect.left,y=ev.clientY-rect.top;
|
|
452
|
-
if(down&&!dragging&&!lastPan){if(Math.hypot(x-down.x,y-down.y)<5)return;if(down.n)dragging=down.n;else lastPan={x:down.x,y:down.y};down=null;}
|
|
453
|
-
if(dragging){const p=screenToWorld(x,y);dragging.x=p.x;dragging.y=p.y;draw();}else if(lastPan){cam.x+=x-lastPan.x;cam.y+=y-lastPan.y;lastPan={x,y};draw();}});
|
|
454
|
-
window.addEventListener("mouseup",()=>{if(down){if(down.n){selected=down.n;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(down.n.id);render();syncRefocus();draw();}else if(down.e){selectedEdge={from:down.e.from,to:down.e.to};render();draw();}}down=null;dragging=null;lastPan=null;});
|
|
455
|
-
cv.addEventListener("wheel",ev=>{ev.preventDefault();cam.k=Math.min(8,Math.max(0.15,cam.k*(ev.deltaY<0?1.08:1/1.08)));draw();},{passive:false});
|
|
456
|
-
document.getElementById("q").addEventListener("input",()=>{selectedEdge=null;const q=document.getElementById("q").value.trim().toLowerCase();
|
|
457
|
-
const hit=(DATA.nodes||[]).find(n=>n.name.toLowerCase()===q||n.canonical_name===q)||(DATA.nodes||[]).find(n=>n.name.toLowerCase().includes(q)||n.canonical_name.includes(q));
|
|
458
|
-
selected=hit||null;tabFilter=null;if(selected)markHot(selected.id);syncRefocus();if(selected&&!sim.some(p=>p.id===selected.id)){focusMode=true;rebuild(false);}else draw();render();});
|
|
459
|
-
document.getElementById("type").addEventListener("change",()=>{rebuild(false);render();});
|
|
460
|
-
document.getElementById("cap").addEventListener("input",()=>{document.getElementById("capLabel").textContent=String(document.getElementById("cap").value);});
|
|
461
|
-
document.getElementById("cap").addEventListener("change",()=>{rebuild(false);render();});
|
|
462
|
-
document.getElementById("refocus").addEventListener("click",ev=>{ev.stopPropagation();if(document.getElementById("refocus").dataset.mode==="centre")recenter();else refocus();});
|
|
463
|
-
document.getElementById("details").addEventListener("click",()=>{showDetails=!showDetails;try{localStorage.setItem("om-inspect-details",showDetails?"1":"0");}catch(e){}document.getElementById("details").classList.toggle("on",showDetails);render();});
|
|
464
|
-
document.getElementById("details").classList.toggle("on",showDetails);
|
|
465
|
-
function effectiveTheme(){const mode=document.documentElement.getAttribute("data-theme")||"system";if(mode==="light"||mode==="dark")return mode;return matchMedia("(prefers-color-scheme: light)").matches?"light":"dark";}
|
|
466
|
-
function syncThemeButton(){const light=effectiveTheme()==="light";document.getElementById("themeSun").hidden=light;document.getElementById("themeMoon").hidden=!light;}
|
|
467
|
-
function applyTheme(mode){document.documentElement.setAttribute("data-theme",mode==="light"||mode==="dark"?mode:"system");try{localStorage.setItem("om-inspect-theme",document.documentElement.getAttribute("data-theme"));}catch(e){}syncThemeButton();draw();}
|
|
468
|
-
let theme="system";try{theme=localStorage.getItem("om-inspect-theme")||"system";}catch(e){}applyTheme(theme);
|
|
469
|
-
document.getElementById("themeBtn").addEventListener("click",()=>{const osLight=matchMedia("(prefers-color-scheme: light)").matches;const next=effectiveTheme()==="light"?"dark":"light";applyTheme(next===(osLight?"light":"dark")?"system":next);});
|
|
470
|
-
document.getElementById("zoomIn").addEventListener("click",ev=>{ev.stopPropagation();zoomBy(1.2);});
|
|
471
|
-
document.getElementById("zoomOut").addEventListener("click",ev=>{ev.stopPropagation();zoomBy(1/1.2);});
|
|
472
|
-
document.getElementById("zoomFit").addEventListener("click",ev=>{ev.stopPropagation();fitView();});
|
|
473
|
-
function currentDock(){const c=[...document.getElementById("stage").classList].find(x=>x.startsWith("dock-"));return c?c.slice(5):"right";}
|
|
474
|
-
function closeDockMenu(){const menu=document.getElementById("dockMenu");menu.classList.remove("open");menu.hidden=true;}
|
|
475
|
-
function setDock(side){document.getElementById("stage").className="dock-"+side;document.getElementById("dockBtnIco").className="dock-ico "+side;closeDockMenu();resize();}
|
|
476
|
-
document.getElementById("dockBtn").addEventListener("click",ev=>{ev.stopPropagation();const menu=document.getElementById("dockMenu");const open=!menu.classList.contains("open");menu.classList.toggle("open",open);menu.hidden=!open;});
|
|
477
|
-
document.getElementById("dockMenu").addEventListener("click",ev=>{ev.stopPropagation();const b=ev.target.closest("[data-dock]");if(!b||b.classList.contains("is-current"))return;setDock(b.getAttribute("data-dock"));});
|
|
478
|
-
document.addEventListener("click",()=>closeDockMenu());
|
|
479
|
-
document.addEventListener("keydown",ev=>{if(ev.key==="Escape"){if(tabFilter){tabFilter=null;render();ev.preventDefault();}closeDockMenu();}});
|
|
480
|
-
let splitDrag=null;document.getElementById("splitter").addEventListener("mousedown",ev=>{ev.preventDefault();ev.stopPropagation();splitDrag={dock:currentDock(),rect:document.getElementById("stage").getBoundingClientRect()};});
|
|
481
|
-
window.addEventListener("mousemove",ev=>{if(!splitDrag)return;const {dock,rect}=splitDrag;let size=dock==="right"?rect.right-ev.clientX:dock==="left"?ev.clientX-rect.left:dock==="bottom"?rect.bottom-ev.clientY:ev.clientY-rect.top;
|
|
482
|
-
const max=(dock==="left"||dock==="right")?rect.width*0.7:rect.height*0.7;size=Math.max(220,Math.min(max,size));document.getElementById("stage").style.setProperty("--panel",size+"px");resize();});
|
|
483
|
-
window.addEventListener("mouseup",()=>{splitDrag=null;});
|
|
484
|
-
document.getElementById("reset").addEventListener("click",()=>{document.getElementById("q").value="";document.getElementById("type").value="";document.getElementById("cap").value="50";document.getElementById("capLabel").textContent="50";
|
|
485
|
-
selected=null;selectedEdge=null;focusMode=false;focusedId=null;tab="knowledge";tabFilter=null;hotSet=null;sim=[];rebuild(true);render();});
|
|
486
|
-
window.addEventListener("resize",resize);rebuild(true);render();resize();
|
|
487
|
-
</script>
|
|
488
|
-
</body>
|
|
29
|
+
return `<!DOCTYPE html>
|
|
30
|
+
<html lang="en-GB" data-theme="system">
|
|
31
|
+
<head>
|
|
32
|
+
<meta charset="utf-8"/>
|
|
33
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
34
|
+
<title>Facthouse inspect</title>
|
|
35
|
+
<link rel="icon" href="${ledgerFaviconHref()}"/>
|
|
36
|
+
<style>
|
|
37
|
+
${ledgerInspectCss()}
|
|
38
|
+
* { box-sizing: border-box; }
|
|
39
|
+
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
|
|
40
|
+
font: 13px/1.45 "Segoe UI", ui-sans-serif, system-ui, sans-serif; }
|
|
41
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
42
|
+
#app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
|
|
43
|
+
header { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
|
|
44
|
+
padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
45
|
+
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
46
|
+
.brand-mark { display: block; width: 28px; height: 28px; flex: 0 0 auto; border-radius: 6px;
|
|
47
|
+
overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
|
|
48
|
+
.brand-mark svg { display: block; width: 28px; height: 28px; }
|
|
49
|
+
.brand-copy { min-width: 0; }
|
|
50
|
+
header h1 { font-size: 15px; font-weight: 650; letter-spacing: -0.02em; margin: 0; line-height: 1.2; }
|
|
51
|
+
.brand-sub { margin: 1px 0 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
|
|
52
|
+
color: var(--muted); }
|
|
53
|
+
header .meta { color: var(--muted); font-size: 12px; }
|
|
54
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
|
|
55
|
+
input, select, button {
|
|
56
|
+
background: var(--input); color: var(--text); border: 1px solid var(--line);
|
|
57
|
+
border-radius: 8px; padding: 7px 10px; font: inherit; }
|
|
58
|
+
input[type="search"] { width: 260px; }
|
|
59
|
+
input[type="range"] { width: 92px; }
|
|
60
|
+
button { cursor: pointer; transition: border-color .12s, color .12s, background .12s; }
|
|
61
|
+
button:hover { border-color: var(--accent); color: var(--accent); }
|
|
62
|
+
.tab.on { border-color: var(--accent); color: var(--accent); }
|
|
63
|
+
.icon-btn { width: 34px; height: 34px; padding: 0; display: flex; align-items: center;
|
|
64
|
+
justify-content: center; background: var(--elev); }
|
|
65
|
+
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor;
|
|
66
|
+
stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
|
67
|
+
#stage { display: grid; min-height: 0; --panel: 420px;
|
|
68
|
+
grid-template-columns: 1fr 6px var(--panel); grid-template-areas: "graph split panel"; }
|
|
69
|
+
#stage.dock-left { grid-template-columns: var(--panel) 6px 1fr;
|
|
70
|
+
grid-template-areas: "panel split graph"; }
|
|
71
|
+
#stage.dock-bottom { grid-template-columns: 1fr; grid-template-rows: 1fr 6px var(--panel);
|
|
72
|
+
grid-template-areas: "graph" "split" "panel"; }
|
|
73
|
+
#stage.dock-top { grid-template-columns: 1fr; grid-template-rows: var(--panel) 6px 1fr;
|
|
74
|
+
grid-template-areas: "panel" "split" "graph"; }
|
|
75
|
+
#graphwrap { grid-area: graph; position: relative; min-width: 0; min-height: 0; }
|
|
76
|
+
#splitter { grid-area: split; background: var(--line); cursor: col-resize; }
|
|
77
|
+
#stage.dock-bottom #splitter, #stage.dock-top #splitter { cursor: row-resize; }
|
|
78
|
+
aside { grid-area: panel; min-width: 0; min-height: 0; background: var(--panel);
|
|
79
|
+
position: relative; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
|
|
80
|
+
#stage.dock-left aside { border-left: 0; border-right: 1px solid var(--line); }
|
|
81
|
+
#stage.dock-top aside, #stage.dock-bottom aside { border-left: 0; }
|
|
82
|
+
canvas { width: 100%; height: 100%; display: block; background:
|
|
83
|
+
radial-gradient(900px 640px at 28% 18%, var(--glow) 0%, var(--bg) 62%); }
|
|
84
|
+
#refocus { position: absolute; top: 14px; right: 14px; z-index: 2;
|
|
85
|
+
background: var(--elev); border: 1px solid var(--accent); color: var(--text);
|
|
86
|
+
border-radius: 8px; padding: 6px 10px; }
|
|
87
|
+
#zoom { position: absolute; bottom: 14px; right: 14px; z-index: 2;
|
|
88
|
+
display: flex; flex-direction: column; gap: 6px; }
|
|
89
|
+
#zoom button { width: 36px; height: 34px; padding: 0; font-size: 16px; background: var(--elev); }
|
|
90
|
+
#graphBar { position: absolute; bottom: 14px; left: 14px; z-index: 2;
|
|
91
|
+
display: flex; align-items: center; gap: 10px; background: var(--elev);
|
|
92
|
+
border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
|
|
93
|
+
box-shadow: 0 8px 24px rgba(0,0,0,.18); }
|
|
94
|
+
#graphBar label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
|
|
95
|
+
.who { padding: 16px 76px 12px 18px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
|
|
96
|
+
.who h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 4px; overflow-wrap: anywhere; }
|
|
97
|
+
.who .type { color: var(--muted); overflow-wrap: anywhere; font-size: 12px; }
|
|
98
|
+
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); flex: 0 0 auto; padding: 0 8px; }
|
|
99
|
+
.tab { flex: 1; min-width: 0; background: transparent; border: 0;
|
|
100
|
+
border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 6px;
|
|
101
|
+
color: var(--muted); font-size: 12px; letter-spacing: .01em; }
|
|
102
|
+
.tab.on { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
|
|
103
|
+
.body { overflow: auto; padding: 14px 18px 28px; flex: 1; min-height: 0; }
|
|
104
|
+
.fact { padding: 12px 0; border-bottom: 1px solid var(--line); }
|
|
105
|
+
.fact.expired, .fact.superseded { opacity: 0.62; }
|
|
106
|
+
.fact.hi { background: var(--elev); margin: 0 -8px; padding-left: 8px; padding-right: 8px;
|
|
107
|
+
border-radius: 8px; box-shadow: inset 3px 0 0 var(--accent); }
|
|
108
|
+
.fact-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
|
|
109
|
+
.fact-left { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; min-width: 0; }
|
|
110
|
+
.fact .when { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; padding-left: 8px; }
|
|
111
|
+
.fact .flag { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--about); }
|
|
112
|
+
.fact .flag.mention { color: var(--mention); }
|
|
113
|
+
.fact .dom, .fact .meta-line { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
|
|
114
|
+
.fact .txt, .fact > div { overflow-wrap: anywhere; }
|
|
115
|
+
.fact-actions { margin-top: 6px; }
|
|
116
|
+
.nlist { list-style: none; padding: 0; margin: 0; }
|
|
117
|
+
.nlist li { padding: 8px 0; border-bottom: 1px solid var(--line); }
|
|
118
|
+
a.link { color: var(--accent); cursor: pointer; text-decoration: none; }
|
|
119
|
+
a.link:hover { text-decoration: underline; }
|
|
120
|
+
.empty, .hint, .conv-head { color: var(--muted); font-size: 12px; }
|
|
121
|
+
.conv-head { margin: 14px 0 6px; font-weight: 600; }
|
|
122
|
+
.filterbar { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start;
|
|
123
|
+
margin-bottom: 10px; padding: 8px 10px; background: var(--elev); border-radius: 8px; }
|
|
124
|
+
.toolbar { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 8px; }
|
|
125
|
+
#details.on { border-color: var(--accent); color: var(--accent); }
|
|
126
|
+
.meters { display: flex; gap: 10px; margin-top: 6px; }
|
|
127
|
+
.meter { width: 56px; }
|
|
128
|
+
.meter span { display: block; font-size: 10px; color: var(--muted); }
|
|
129
|
+
.meter i { display: block; height: 3px; background: var(--chip); border-radius: 2px; margin-top: 2px; }
|
|
130
|
+
.meter i b { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
|
|
131
|
+
.meter.imp i b { background: var(--mention); }
|
|
132
|
+
.meter.quiet { opacity: 0.4; }
|
|
133
|
+
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--chip); font-size: 11px; }
|
|
134
|
+
#panelTools { position: absolute; top: 10px; right: 12px; z-index: 4; display: flex; gap: 4px; }
|
|
135
|
+
#dockWrap { position: relative; }
|
|
136
|
+
#dockBtn { width: 28px; height: 24px; padding: 2px; display: flex; align-items: center; justify-content: center; }
|
|
137
|
+
#dockMenu { display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
|
|
138
|
+
background: var(--elev); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
|
|
139
|
+
grid-template-columns: 1fr 1fr; gap: 4px; }
|
|
140
|
+
#dockMenu.open { display: grid; }
|
|
141
|
+
#dockMenu button { width: 36px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; }
|
|
142
|
+
#dockMenu button.is-current { opacity: 0.35; pointer-events: none; }
|
|
143
|
+
.dock-ico { display: block; width: 16px; height: 12px; position: relative;
|
|
144
|
+
border: 1.5px solid currentColor; border-radius: 2px; }
|
|
145
|
+
.dock-ico::after { content: ""; position: absolute; background: currentColor; }
|
|
146
|
+
.dock-ico.right::after { top: 0; right: 0; bottom: 0; width: 38%; }
|
|
147
|
+
.dock-ico.left::after { top: 0; left: 0; bottom: 0; width: 38%; }
|
|
148
|
+
.dock-ico.bottom::after { left: 0; right: 0; bottom: 0; height: 38%; }
|
|
149
|
+
.dock-ico.top::after { left: 0; right: 0; top: 0; height: 38%; }
|
|
150
|
+
.views { display: inline-flex; gap: 2px; padding: 3px; background: var(--input);
|
|
151
|
+
border: 1px solid var(--line); border-radius: 9px; }
|
|
152
|
+
.view-btn { border: 1px solid transparent; background: transparent; border-radius: 6px;
|
|
153
|
+
padding: 5px 12px; color: var(--muted); }
|
|
154
|
+
.view-btn.on { border-color: transparent; background: var(--elev); color: var(--accent); font-weight: 600; }
|
|
155
|
+
html.view-spend #stage,
|
|
156
|
+
html:has(#spend:target) #stage { display: none; }
|
|
157
|
+
html.view-spend #spend,
|
|
158
|
+
#spend:target { display: block; }
|
|
159
|
+
html.view-spend .graph-only,
|
|
160
|
+
html:has(#spend:target) .graph-only { display: none; }
|
|
161
|
+
#stage, #spend { grid-row: 2; min-height: 0; }
|
|
162
|
+
#spend {
|
|
163
|
+
display: none; overflow: auto; padding: 20px 24px 48px;
|
|
164
|
+
--card: var(--elev); --ink: var(--text); --gold: var(--mention);
|
|
165
|
+
}
|
|
166
|
+
${SPEND_BOARD_CSS}
|
|
167
|
+
${INTELLIGENCE_ROUTING_CSS}
|
|
168
|
+
</style>
|
|
169
|
+
</head>
|
|
170
|
+
<body>
|
|
171
|
+
<div id="app">
|
|
172
|
+
<header>
|
|
173
|
+
<div class="brand">
|
|
174
|
+
<span class="brand-mark">${LEDGER_MARK_SVG}</span>
|
|
175
|
+
<div class="brand-copy">
|
|
176
|
+
<h1>Facthouse</h1>
|
|
177
|
+
<p class="brand-sub">Inspect</p>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
<div class="views" role="tablist">
|
|
181
|
+
<button type="button" class="view-btn on" data-view="graph" id="viewGraph">Graph</button>
|
|
182
|
+
<button type="button" class="view-btn" data-view="spend" id="viewSpend">Spend</button>
|
|
183
|
+
</div>
|
|
184
|
+
<div class="meta" id="meta"></div>
|
|
185
|
+
<div class="controls">
|
|
186
|
+
<input id="q" class="graph-only" type="search" placeholder="Find an entity by name"/>
|
|
187
|
+
<select id="type" class="graph-only"><option value="">All types</option></select>
|
|
188
|
+
<button type="button" id="themeBtn" class="icon-btn" title="Toggle colour theme">
|
|
189
|
+
<svg id="themeSun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
|
|
190
|
+
<svg id="themeMoon" viewBox="0 0 24 24" hidden><path d="M21 14.3A8.5 8.5 0 1 1 9.7 3 7 7 0 0 0 21 14.3z"/></svg>
|
|
191
|
+
</button>
|
|
192
|
+
</div>
|
|
193
|
+
</header>
|
|
194
|
+
<div id="stage" class="dock-right">
|
|
195
|
+
<div id="graphwrap">
|
|
196
|
+
<canvas id="cv"></canvas>
|
|
197
|
+
<button id="refocus" type="button" hidden>Refocus</button>
|
|
198
|
+
<div id="graphBar">
|
|
199
|
+
<button id="reset" type="button">Reset</button>
|
|
200
|
+
<label>Show <span id="capLabel">50</span>
|
|
201
|
+
<input id="cap" type="range" min="10" max="200" step="5" value="50"/>
|
|
202
|
+
</label>
|
|
203
|
+
</div>
|
|
204
|
+
<div id="zoom">
|
|
205
|
+
<button id="zoomIn" type="button" title="Zoom in">+</button>
|
|
206
|
+
<button id="zoomOut" type="button" title="Zoom out">−</button>
|
|
207
|
+
<button id="zoomFit" type="button" title="Fit">⤢</button>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
<div id="splitter"></div>
|
|
211
|
+
<aside>
|
|
212
|
+
<div id="panelTools">
|
|
213
|
+
<button type="button" id="details" class="icon-btn" title="Show extra fields on cards">
|
|
214
|
+
<svg viewBox="0 0 24 24"><path d="M4 7h10M4 12h16M4 17h7"/><circle cx="18.5" cy="7" r="2"/></svg>
|
|
215
|
+
</button>
|
|
216
|
+
<div id="dockWrap">
|
|
217
|
+
<button type="button" id="dockBtn" title="Move panel"><span id="dockBtnIco" class="dock-ico right"></span></button>
|
|
218
|
+
<div id="dockMenu" hidden>
|
|
219
|
+
<button type="button" data-dock="left" title="Left"><span class="dock-ico left"></span></button>
|
|
220
|
+
<button type="button" data-dock="right" title="Right"><span class="dock-ico right"></span></button>
|
|
221
|
+
<button type="button" data-dock="top" title="Top"><span class="dock-ico top"></span></button>
|
|
222
|
+
<button type="button" data-dock="bottom" title="Bottom"><span class="dock-ico bottom"></span></button>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
<div class="who" id="who"></div>
|
|
227
|
+
<div class="tabs" id="tabs"></div>
|
|
228
|
+
<div class="body" id="body"></div>
|
|
229
|
+
</aside>
|
|
230
|
+
</div>
|
|
231
|
+
<div id="spend">${spendHtml}${routingHtml}</div>
|
|
232
|
+
</div>
|
|
233
|
+
<script>
|
|
234
|
+
const DATA = ${json};
|
|
235
|
+
function setInspectView(v){
|
|
236
|
+
document.documentElement.classList.toggle("view-spend", v==="spend");
|
|
237
|
+
document.querySelectorAll(".view-btn").forEach(function(b){
|
|
238
|
+
b.classList.toggle("on", b.getAttribute("data-view")===v);
|
|
239
|
+
});
|
|
240
|
+
if (v==="spend") location.hash="spend";
|
|
241
|
+
else if (location.hash==="#spend") location.hash="graph";
|
|
242
|
+
}
|
|
243
|
+
document.querySelectorAll(".view-btn").forEach(function(b){
|
|
244
|
+
b.addEventListener("click", function(){ setInspectView(b.getAttribute("data-view")); });
|
|
245
|
+
});
|
|
246
|
+
window.addEventListener("hashchange", function(){
|
|
247
|
+
setInspectView(location.hash==="#spend" ? "spend" : "graph");
|
|
248
|
+
});
|
|
249
|
+
if (location.hash==="#spend") setInspectView("spend");
|
|
250
|
+
const SUBJECT = "subject_of";
|
|
251
|
+
const NEAR_USER = 8;
|
|
252
|
+
const NEAR_RADIUS = 3;
|
|
253
|
+
function hue(s){let h=0;for(let i=0;i<s.length;i++)h=(h*33+s.charCodeAt(i))>>>0;return h%360;}
|
|
254
|
+
function colour(type){const map={person:"#7eb889",organisation:"#6aa8c9",organization:"#6aa8c9",project:"#c4a35a",place:"#9b8fd4",product:"#d08b6a"};if(map[type])return map[type];return "hsl("+hue(type||"?")+" 28% 48%)";}
|
|
255
|
+
function esc(s){return String(s??"").replace(/[&<>"'']/g,c=>({"&":"&","<":"<",">":">","\\"":""","'":"'"}[c]));}
|
|
256
|
+
const byId=new Map((DATA.nodes||[]).map(n=>[n.id,n]));
|
|
257
|
+
const factById=new Map((DATA.facts||[]).map(f=>[f.id,f]));
|
|
258
|
+
const eventById=new Map((DATA.events||[]).map(e=>[e.id,e]));
|
|
259
|
+
const infoById=new Map((DATA.info||[]).map(i=>[i.id,i]));
|
|
260
|
+
const sourceById=new Map((DATA.sources||[]).map(s=>[s.id,s]));
|
|
261
|
+
const dForI=new Map();
|
|
262
|
+
for(const row of DATA.iToD||[]){if(!dForI.has(row.session_fact_id))dForI.set(row.session_fact_id,[]);dForI.get(row.session_fact_id).push(row);}
|
|
263
|
+
const eventsByConv=new Map();
|
|
264
|
+
for(const e of DATA.events||[]){const c=e.conversation||"";if(!eventsByConv.has(c))eventsByConv.set(c,[]);eventsByConv.get(c).push(e.id);}
|
|
265
|
+
const linksByEntity=new Map();
|
|
266
|
+
for(const l of DATA.links||[]){if(!linksByEntity.has(l.entity_id))linksByEntity.set(l.entity_id,[]);linksByEntity.get(l.entity_id).push(l);}
|
|
267
|
+
const typeSel=document.getElementById("type");
|
|
268
|
+
for(const t of [...new Set((DATA.nodes||[]).map(n=>n.type))].sort()){const o=document.createElement("option");o.value=t;o.textContent=t;typeSel.appendChild(o);}
|
|
269
|
+
document.getElementById("meta").textContent=(DATA.nodes||[]).length+" entities · "+(DATA.facts||[]).length+" facts · "+(DATA.eventCount||0)+" raw events";
|
|
270
|
+
function sharedCount(a,b){const fa=new Set((linksByEntity.get(a)||[]).map(l=>l.fact_id));let n=0;const seen=new Set();for(const l of linksByEntity.get(b)||[]){if(fa.has(l.fact_id)&&!seen.has(l.fact_id)){seen.add(l.fact_id);n++;}}return n;}
|
|
271
|
+
function egoIds(centerId,cap,typeFilter){
|
|
272
|
+
const scores=new Map();
|
|
273
|
+
for(const e of DATA.edges||[]){if(e.from===centerId)scores.set(e.to,(scores.get(e.to)||0)+10*e.strength);if(e.to===centerId)scores.set(e.from,(scores.get(e.from)||0)+10*e.strength);}
|
|
274
|
+
for(const n of DATA.nodes||[]){if(n.id===centerId)continue;const sh=sharedCount(centerId,n.id);if(sh)scores.set(n.id,(scores.get(n.id)||0)+sh);}
|
|
275
|
+
const ranked=[...scores.entries()].sort((a,b)=>b[1]-a[1]).map(([id])=>byId.get(id)).filter(Boolean).filter(n=>!typeFilter||n.type===typeFilter||n.id===centerId);
|
|
276
|
+
const ids=new Set([centerId]);for(const n of ranked){if(ids.size>=cap)break;ids.add(n.id);}return ids;
|
|
277
|
+
}
|
|
278
|
+
function visibleIds(cap,query,typeFilter,center,focused){
|
|
279
|
+
const q=query.trim().toLowerCase();
|
|
280
|
+
let focus=center||null;
|
|
281
|
+
if(!focus&&q){focus=(DATA.nodes||[]).find(n=>n.name.toLowerCase()===q||n.canonical_name===q)||(DATA.nodes||[]).find(n=>n.name.toLowerCase().includes(q)||n.canonical_name.includes(q))||null;}
|
|
282
|
+
if(focused&&focus)return {ids:egoIds(focus.id,cap,typeFilter),focus};
|
|
283
|
+
const ranked=[...(DATA.nodes||[])].sort((a,b)=>b.degree-a.degree||a.name.localeCompare(b.name));
|
|
284
|
+
const ids=new Set();for(const n of ranked){if(ids.size>=cap)break;if(typeFilter&&n.type!==typeFilter)continue;ids.add(n.id);}
|
|
285
|
+
if(focus)ids.add(focus.id);return {ids,focus};
|
|
286
|
+
}
|
|
287
|
+
const cv=document.getElementById("cv");const ctx=cv.getContext("2d");
|
|
288
|
+
let cam={x:0,y:0,k:1},sim=[],selected=null,selectedEdge=null,focusMode=false,focusedId=null,tab="knowledge",tabFilter=null,dataNewest=false,showDetails=false,dragging=null,lastPan=null,down=null,hotSet=null,anim=0,cooling=0,frames=0,fitAfterAnim=false;
|
|
289
|
+
try{showDetails=localStorage.getItem("om-inspect-details")==="1";}catch(e){}
|
|
290
|
+
if(DATA.selectedId)selected=byId.get(DATA.selectedId)||null;
|
|
291
|
+
if(selected)focusMode=true,focusedId=selected.id;
|
|
292
|
+
const capEl=document.getElementById("cap");
|
|
293
|
+
if(DATA.cap){capEl.value=String(Math.min(200,Math.max(10,DATA.cap)));document.getElementById("capLabel").textContent=capEl.value;}
|
|
294
|
+
function radius(n){return 4+Math.min(14,Math.sqrt(n.degree||1)*2.2);}
|
|
295
|
+
function markHot(id){hotSet=new Set([id]);for(const e of DATA.edges||[]){if(e.from===id)hotSet.add(e.to);if(e.to===id)hotSet.add(e.from);}}
|
|
296
|
+
function startLayout(ids,opts){
|
|
297
|
+
const fresh=opts&&opts.fresh;const nodes=[...ids].map(id=>byId.get(id)).filter(Boolean);
|
|
298
|
+
const old=fresh?new Map():new Map(sim.map(p=>[p.id,p]));
|
|
299
|
+
const origin=(selected&&old.get(selected.id))||{x:0,y:0};
|
|
300
|
+
sim=nodes.map((n,i)=>{const p=old.get(n.id);if(p)return {...n,x:p.x,y:p.y,vx:0,vy:0};
|
|
301
|
+
const ang=(i/Math.max(nodes.length,1))*Math.PI*2;
|
|
302
|
+
if(old.size===0)return {...n,x:Math.cos(ang)*280,y:Math.sin(ang)*280,vx:0,vy:0};
|
|
303
|
+
const j=Math.random()*Math.PI*2;return {...n,x:origin.x+Math.cos(j)*24,y:origin.y+Math.sin(j)*24,vx:Math.cos(j)*3,vy:Math.sin(j)*3};});
|
|
304
|
+
cooling=1;frames=0;if(!anim)anim=requestAnimationFrame(tick);
|
|
305
|
+
}
|
|
306
|
+
function stepPhysics(){
|
|
307
|
+
const pmap=new Map(sim.map(p=>[p.id,p]));const idSet=new Set(sim.map(n=>n.id));
|
|
308
|
+
const links=(DATA.edges||[]).filter(e=>idSet.has(e.from)&&idSet.has(e.to));
|
|
309
|
+
for(let i=0;i<sim.length;i++)for(let j=i+1;j<sim.length;j++){
|
|
310
|
+
let dx=sim[j].x-sim[i].x,dy=sim[j].y-sim[i].y,d=Math.hypot(dx,dy)||0.01;
|
|
311
|
+
const minD=radius(sim[i])+radius(sim[j])+22;let f=420/(d*d);if(d<minD)f+=(minD-d)*0.22;
|
|
312
|
+
const fx=f*dx/d,fy=f*dy/d;sim[i].vx-=fx;sim[i].vy-=fy;sim[j].vx+=fx;sim[j].vy+=fy;
|
|
313
|
+
}
|
|
314
|
+
for(const e of links){const a=pmap.get(e.from),b=pmap.get(e.to);if(!a||!b)continue;
|
|
315
|
+
let dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||0.01,f=(d-130)*0.035;
|
|
316
|
+
a.vx+=f*dx/d;a.vy+=f*dy/d;b.vx-=f*dx/d;b.vy-=f*dy/d;}
|
|
317
|
+
let energy=0;for(const p of sim){p.vx*=0.72;p.vy*=0.72;const sp=Math.hypot(p.vx,p.vy);if(sp>18){p.vx*=18/sp;p.vy*=18/sp;}p.x+=p.vx;p.y+=p.vy;energy+=p.vx*p.vx+p.vy*p.vy;}
|
|
318
|
+
return energy;
|
|
319
|
+
}
|
|
320
|
+
function tick(){frames++;let energy=0;for(let s=0;s<8;s++)energy=stepPhysics();cooling*=0.86;draw();
|
|
321
|
+
if(frames<32&&(cooling>0.12||energy>12))anim=requestAnimationFrame(tick);else{anim=0;if(fitAfterAnim){fitView();fitAfterAnim=false;}}}
|
|
322
|
+
function draw(){
|
|
323
|
+
const w=cv.clientWidth,h=cv.clientHeight;ctx.clearRect(0,0,w,h);ctx.save();ctx.translate(w/2+cam.x,h/2+cam.y);ctx.scale(cam.k,cam.k);
|
|
324
|
+
const css=getComputedStyle(document.documentElement);
|
|
325
|
+
const labelBg=css.getPropertyValue("--canvas-label").trim();const labelFg=css.getPropertyValue("--canvas-label-text").trim();const selStroke=css.getPropertyValue("--text").trim();
|
|
326
|
+
const idSet=new Set(sim.map(n=>n.id));const pmap=new Map(sim.map(p=>[p.id,p]));
|
|
327
|
+
for(const e of DATA.edges||[]){if(!idSet.has(e.from)||!idSet.has(e.to))continue;const a=pmap.get(e.from),b=pmap.get(e.to);
|
|
328
|
+
const edgeOn=selectedEdge&&((selectedEdge.from===e.from&&selectedEdge.to===e.to)||(selectedEdge.from===e.to&&selectedEdge.to===e.from));
|
|
329
|
+
const hot=edgeOn||(selected&&(e.from===selected.id||e.to===selected.id));
|
|
330
|
+
const gold=css.getPropertyValue("--accent").trim()||"#c4a35a";const muted=css.getPropertyValue("--muted").trim()||"#9a9486";
|
|
331
|
+
ctx.strokeStyle=edgeOn?gold:hot?gold:muted;ctx.globalAlpha=edgeOn?0.9:hot?0.55:0.22;
|
|
332
|
+
ctx.lineWidth=edgeOn?2.4:hot?1.6:0.6+e.strength;ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.lineTo(b.x,b.y);ctx.stroke();ctx.globalAlpha=1;}
|
|
333
|
+
for(const n of sim){const r=radius(n);ctx.beginPath();ctx.fillStyle=colour(n.type);
|
|
334
|
+
const dim=selected&&selected.id!==n.id&&!selectedEdge&&hotSet&&!hotSet.has(n.id);ctx.globalAlpha=dim?0.35:1;ctx.arc(n.x,n.y,r,0,Math.PI*2);ctx.fill();ctx.globalAlpha=1;
|
|
335
|
+
if((selected&&selected.id===n.id)||(selectedEdge&&(selectedEdge.from===n.id||selectedEdge.to===n.id))){ctx.strokeStyle=selStroke||"#fff";ctx.lineWidth=2;ctx.stroke();}
|
|
336
|
+
if(cam.k>0.85||(selected&&selected.id===n.id)||n.degree>=8){const label=n.name.length>28?n.name.slice(0,27)+"…":n.name;ctx.font="11px ui-sans-serif, system-ui, sans-serif";
|
|
337
|
+
const tw=ctx.measureText(label).width;ctx.fillStyle=labelBg||"rgba(14,18,24,0.75)";ctx.fillRect(n.x+r+3,n.y-8,tw+6,14);ctx.fillStyle=labelFg||"#e7edf5";ctx.fillText(label,n.x+r+6,n.y+3);}}
|
|
338
|
+
ctx.restore();syncRefocus();
|
|
339
|
+
}
|
|
340
|
+
function screenToWorld(sx,sy){return {x:(sx-cv.clientWidth/2-cam.x)/cam.k,y:(sy-cv.clientHeight/2-cam.y)/cam.k};}
|
|
341
|
+
function hitNode(sx,sy){const p=screenToWorld(sx,sy);let best=null,bestD=1e9;for(const n of sim){const d=Math.hypot(n.x-p.x,n.y-p.y);if(d<radius(n)+4&&d<bestD){best=n;bestD=d;}}return best;}
|
|
342
|
+
function hitEdge(sx,sy){const p=screenToWorld(sx,sy);const pmap=new Map(sim.map(n=>[n.id,n]));let best=null,bestD=8/cam.k;
|
|
343
|
+
for(const e of DATA.edges||[]){const a=pmap.get(e.from),b=pmap.get(e.to);if(!a||!b)continue;const dx=b.x-a.x,dy=b.y-a.y,l2=dx*dx+dy*dy||1;let t=((p.x-a.x)*dx+(p.y-a.y)*dy)/l2;t=Math.max(0,Math.min(1,t));
|
|
344
|
+
const d=Math.hypot(p.x-(a.x+t*dx),p.y-(a.y+t*dy));if(d<bestD){best=e;bestD=d;}}return best;}
|
|
345
|
+
function isEndedFact(f){return f.status==="superseded"||!!f.valid_until||f.is_latest===0||f.is_latest===false;}
|
|
346
|
+
function factsForEntity(id){
|
|
347
|
+
const rows=(linksByEntity.get(id)||[]).map(l=>({rel:l.relationship,fact:factById.get(l.fact_id)})).filter(x=>x.fact);
|
|
348
|
+
const seen=new Set(),about=[],mentions=[];
|
|
349
|
+
for(const r of rows){if(seen.has(r.fact.id))continue;seen.add(r.fact.id);const isAbout=rows.some(x=>x.fact.id===r.fact.id&&x.rel===SUBJECT);(isAbout?about:mentions).push(r.fact);}
|
|
350
|
+
const byRank=(a,b)=>{const ae=isEndedFact(a)?1:0,be=isEndedFact(b)?1:0;if(ae!==be)return ae-be;return (b.importance||0)-(a.importance||0);};
|
|
351
|
+
about.sort(byRank);mentions.sort(byRank);return {about,mentions};
|
|
352
|
+
}
|
|
353
|
+
function day(iso){if(!iso)return "";const s=String(iso);if(/T00:00:00/.test(s))return s.slice(0,10);return s.slice(0,19).replace("T"," ");}
|
|
354
|
+
function clock(iso){if(!iso)return "";const s=String(iso);if(/T00:00:00/.test(s))return s.slice(0,10);const m=s.match(/T(\\d{2}:\\d{2})/);return m?m[1]:day(iso);}
|
|
355
|
+
function eventWhen(e){return e.occurred_at||e.created_at||"";}
|
|
356
|
+
function toolLabel(e){if(e.tool_name)return "Tool "+e.tool_name;if(e.event_type==="tool_call"||e.event_type==="tool_result"||e.role==="tool")return "Tool";if(e.role==="user")return "User";if(e.role==="assistant")return "Assistant";return e.role||"event";}
|
|
357
|
+
function pct(n){if(n==null||n==="")return "";const x=Number(n);if(Number.isNaN(x))return esc(n);return Math.round(x*100)+"%";}
|
|
358
|
+
function validityLabel(f){const from=day(f.valid_from);if(f.status==="superseded"||f.valid_until)return (from||day(f.created_at))+" – "+(day(f.valid_until)||"ended");if(from)return from+" – present";return day(f.created_at)||"";}
|
|
359
|
+
function meterHtml(kind,value){if(value==null||value==="")return "";const x=Number(value);if(!Number.isFinite(x))return "";const def=kind==="imp"?0.5:0.7;const quiet=Math.abs(x-def)<0.051?" quiet":"";
|
|
360
|
+
return "<div class='meter"+(kind==="imp"?" imp":"")+quiet+"' title='"+(kind==="imp"?"importance ":"confidence ")+pct(x)+"'><span>"+(kind==="imp"?"imp":"conf")+"</span><i><b style='width:"+Math.round(x*100)+"%'></b></i></div>";}
|
|
361
|
+
function iIdForFact(factId){const fact=factById.get(factId);const src=fact&&sourceById.get(fact.source_id);return (src&&src.session_fact_id)||null;}
|
|
362
|
+
function expandEventIds(ids){const set=new Set(ids);for(const id of ids){const hit=eventById.get(id);if(!hit)continue;let nearest=null;
|
|
363
|
+
for(const eid of eventsByConv.get(hit.conversation||"")||[]){const ev=eventById.get(eid);if(!ev)continue;if(Math.abs(ev.sequence-hit.sequence)<=NEAR_RADIUS)set.add(ev.id);
|
|
364
|
+
if(ev.role==="user"&&ev.sequence<=hit.sequence&&hit.sequence-ev.sequence<=NEAR_USER)nearest=ev;}if(nearest)set.add(nearest.id);}return [...set];}
|
|
365
|
+
const dataIdsCache=new Map();
|
|
366
|
+
function dataIdsForI(iId){const key=iId+":"+(selected?selected.id:"");if(dataIdsCache.has(key))return dataIdsCache.get(key);
|
|
367
|
+
const rows=dForI.get(iId)||[];const primary=rows.filter(r=>r.extraction_type!=="contextual").map(r=>r.event_id).filter(id=>eventById.has(id));
|
|
368
|
+
let ids;if(primary.length)ids=expandEventIds(primary);else{const irow=infoById.get(iId);const conv=irow&&irow.session_id;const convIds=conv?(eventsByConv.get(conv)||[]):[];
|
|
369
|
+
const around=selected?(DATA.dByEntity[selected.id]||[]):[];const aroundSet=new Set(around);const overlap=convIds.filter(id=>aroundSet.has(id));ids=overlap.length?expandEventIds(overlap):[...new Set(convIds)];}
|
|
370
|
+
dataIdsCache.set(key,ids);return ids;}
|
|
371
|
+
function factCard(f,flag,kind){
|
|
372
|
+
const superseded=f.status==="superseded";const expired=!superseded&&!!f.valid_until;const when=validityLabel(f);
|
|
373
|
+
const meters=showDetails?"<div class='meters'>"+meterHtml("conf",f.confidence)+meterHtml("imp",f.importance)+"</div>":"";
|
|
374
|
+
let drill="";if(kind==="k"&&f.source_id){const iid=iIdForFact(f.id);drill=iid&&infoById.has(iid)?" <a class='link jump-i' data-id='"+esc(f.id)+"'>Show Information</a>":"";}
|
|
375
|
+
if(kind==="i"&&f.id){const n=dataIdsForI(f.id).length;drill=n?" <a class='link jump-d' data-iid='"+esc(f.id)+"'>Show Data ("+n+")</a>":" <span class='dom'>No Data in this snapshot</span>";}
|
|
376
|
+
const ended=superseded?"<span class='chip'>superseded</span>":expired?"<span class='chip'>no longer valid</span>":"";
|
|
377
|
+
const klass=superseded?" superseded":expired?" expired":"";
|
|
378
|
+
return "<div class='fact"+klass+"'><div class='fact-head'><div class='fact-left'><span class='flag"+(flag==="mention"?" mention":"")+"'>"+flag+"</span>"+ended+(f.domain||f.domain_hint?"<span class='dom'>"+esc(f.domain||f.domain_hint)+"</span>":"")+"</div>"+(when?"<span class='when'>"+esc(when)+"</span>":"")+"</div><div>"+esc(f.content)+"</div>"+meters+(drill?"<div class='fact-actions'>"+drill+"</div>":"")+"</div>";
|
|
379
|
+
}
|
|
380
|
+
function eventBlock(e,extra){if(!e)return "";const more=e.full?" <a class='link more' data-id='"+esc(e.id)+"'>Expand</a>":"";const chip=extra?"<span class='chip'>"+esc(extra)+"</span>":"";const time=clock(eventWhen(e));
|
|
381
|
+
return "<div class='fact' data-eid='"+esc(e.id)+"'><div class='fact-head'><div class='fact-left'><span class='flag mention'>"+esc(toolLabel(e))+"</span>"+chip+"</div>"+(time?"<span class='when'>"+esc(time)+"</span>":"")+"</div><div class='txt'>"+esc(e.content)+"</div>"+more+"</div>";}
|
|
382
|
+
function convLabel(group){const first=group[0],last=group[group.length-1];const a=day(eventWhen(first)),b=day(eventWhen(last));
|
|
383
|
+
const when=a&&b&&a.slice(0,10)!==b.slice(0,10)?a+" – "+b:(a||b||"Conversation");return when+" · "+group.length+(group.length===1?" line":" lines");}
|
|
384
|
+
function renderEventList(ids,extraById){const seen=new Set(),events=[];for(const id of ids){if(seen.has(id))continue;const e=eventById.get(id);if(!e)continue;seen.add(id);events.push(e);}
|
|
385
|
+
const byConv=new Map();for(const e of events){const c=e.conversation||"";if(!byConv.has(c))byConv.set(c,[]);byConv.get(c).push(e);}
|
|
386
|
+
const groups=[...byConv.values()];for(const g of groups)g.sort((a,b)=>a.sequence-b.sequence);
|
|
387
|
+
groups.sort((a,b)=>(eventWhen(a[0])||"").localeCompare(eventWhen(b[0])||"")||a[0].sequence-b[0].sequence);
|
|
388
|
+
if(dataNewest){groups.reverse();for(const g of groups)g.reverse();}
|
|
389
|
+
if(!groups.length)return "<p class='empty'>No transcript lines in this snapshot.</p>";
|
|
390
|
+
let html="";for(const g of groups){html+="<p class='conv-head'>"+esc(convLabel(g))+"</p>";for(const e of g)html+=eventBlock(e,extraById&&extraById.get(e.id));}return html;}
|
|
391
|
+
function bindPanel(root){root.querySelectorAll("a.more").forEach(a=>a.onclick=ev=>{ev.preventDefault();const e=eventById.get(a.getAttribute("data-id"));const card=a.parentElement&&a.parentElement.querySelector(".txt");if(!e||!card)return;const open=a.textContent==="Expand";card.textContent=open?e.full:e.content;a.textContent=open?"Collapse":"Expand";});
|
|
392
|
+
root.querySelectorAll("a.jump-i").forEach(a=>a.onclick=ev=>{ev.preventDefault();const fact=factById.get(a.getAttribute("data-id"));tabFilter={tab:"information",iId:iIdForFact(fact&&fact.id),fromFactId:fact&&fact.id,snippet:fact?String(fact.content||"").slice(0,88):""};tab="information";render();});
|
|
393
|
+
root.querySelectorAll("a.jump-d").forEach(a=>a.onclick=ev=>{ev.preventDefault();const iId=a.getAttribute("data-iid");const irow=infoById.get(iId);tabFilter={tab:"data",iId,eventIds:dataIdsForI(iId),snippet:irow?String(irow.content||"").slice(0,88):""};tab="data";render();});}
|
|
394
|
+
function render(){syncRefocus();const who=document.getElementById("who"),tabs=document.getElementById("tabs"),body=document.getElementById("body");
|
|
395
|
+
if(selectedEdge){const a=byId.get(selectedEdge.from),b=byId.get(selectedEdge.to);const fa=new Set((linksByEntity.get(selectedEdge.from)||[]).map(l=>l.fact_id));const shared=[];const seen=new Set();
|
|
396
|
+
for(const l of linksByEntity.get(selectedEdge.to)||[]){if(fa.has(l.fact_id)&&!seen.has(l.fact_id)){seen.add(l.fact_id);const f=factById.get(l.fact_id);if(f)shared.push(f);}}
|
|
397
|
+
who.innerHTML="<h2>Link</h2><div class='type'><a class='link go' data-id='"+esc(a&&a.id)+"'>"+esc(a&&a.name)+"</a> ↔ <a class='link go' data-id='"+esc(b&&b.id)+"'>"+esc(b&&b.name)+"</a></div>";
|
|
398
|
+
tabs.innerHTML="";body.innerHTML=shared.length?shared.map(f=>factCard(f,"names both","k")).join(""):"<p class='empty'>No current fact names both.</p>";bindPanel(body);
|
|
399
|
+
who.querySelectorAll("a.go").forEach(el=>el.onclick=()=>{const t=byId.get(el.getAttribute("data-id"));if(!t)return;selected=t;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(t.id);render();draw();});return;}
|
|
400
|
+
if(!selected){who.innerHTML="<h2>Nothing selected</h2><div class='type'>Click a node or an edge, or search by name.</div>";tabs.innerHTML="";
|
|
401
|
+
body.innerHTML="<p>The picture is the entity graph. Knowledge lives on the facts. Select something to read it.</p>";return;}
|
|
402
|
+
const n=selected;const fk=factsForEntity(n.id);const dIds=DATA.dByEntity[n.id]||[];const needle=(n.canonical_name||n.name||"").toLowerCase();
|
|
403
|
+
const info=(DATA.info||[]).filter(p=>(p.content||"").toLowerCase().includes(needle));
|
|
404
|
+
const kNow=fk.about.filter(f=>!isEndedFact(f)).length+fk.mentions.filter(f=>!isEndedFact(f)).length;
|
|
405
|
+
who.innerHTML="<h2>"+esc(n.name)+"</h2><div class='type'>"+esc(n.type)+" · "+n.about+" facts about it · "+n.mentions+" mentions</div>";
|
|
406
|
+
tabs.innerHTML="<button class='tab"+(tab==="knowledge"?" on":"")+"' data-t='knowledge'>Knowledge ("+kNow+")</button>"+
|
|
407
|
+
"<button class='tab"+(tab==="information"?" on":"")+"' data-t='information'>Information ("+info.length+")</button>"+
|
|
408
|
+
"<button class='tab"+(tab==="data"?" on":"")+"' data-t='data'>Data ("+(n.dCount!=null?n.dCount:dIds.length)+")</button>"+
|
|
409
|
+
"<button class='tab"+(tab==="links"?" on":"")+"' data-t='links'>Links</button>";
|
|
410
|
+
tabs.querySelectorAll(".tab").forEach(btn=>btn.onclick=()=>{tab=btn.getAttribute("data-t");if(!tabFilter||tabFilter.tab!==tab)tabFilter=null;render();});
|
|
411
|
+
if(tab==="knowledge"){const aboutNow=fk.about.filter(f=>!isEndedFact(f)),aboutOld=fk.about.filter(f=>isEndedFact(f)),menNow=fk.mentions.filter(f=>!isEndedFact(f)),menOld=fk.mentions.filter(f=>isEndedFact(f));
|
|
412
|
+
let html="";if(aboutNow.length)html+="<p class='hint'>About this entity</p>"+aboutNow.map(f=>factCard(f,"about","k")).join("");
|
|
413
|
+
if(menNow.length)html+="<p class='hint'>Mentions</p>"+menNow.map(f=>factCard(f,"mention","k")).join("");
|
|
414
|
+
if(aboutOld.length||menOld.length)html+="<p class='hint'>No longer current</p>"+aboutOld.concat(menOld).map(f=>factCard(f,f.status==="superseded"?"superseded":"ended","k")).join("");
|
|
415
|
+
if(!html)html="<p class='empty'>No current fact is attached to this entity.</p>";body.innerHTML=html;bindPanel(body);}
|
|
416
|
+
else if(tab==="data"){const filtered=tabFilter&&tabFilter.tab==="data";const showIds=filtered?(tabFilter.eventIds||[]):dIds;
|
|
417
|
+
let html="";if(filtered)html+="<div class='filterbar'><div><div class='filterbar-title'>Showing "+showIds.length+" Data</div></div><button type='button' id='clearFilter'>Clear filter</button></div>";
|
|
418
|
+
html+="<div class='toolbar'><a class='link' id='dataSort'>"+(dataNewest?"Oldest first":"Newest first")+"</a></div>";
|
|
419
|
+
if(!filtered&&n.dCount!=null&&n.dCount!==dIds.length)html+=n.dCount>dIds.length?"<p class='hint'>Listing "+dIds.length+" of "+n.dCount+" lines that name this in the store.</p>":"<p class='hint'>Listing "+dIds.length+" lines; "+n.dCount+" name this, the rest are nearby turns.</p>";
|
|
420
|
+
html+=showIds.length?renderEventList(showIds,null):"<p class='empty'>No raw events in this snapshot mention this name. The store has "+DATA.eventCount+" events; this file includes "+DATA.eventShown+" with text.</p>";
|
|
421
|
+
body.innerHTML=html;bindPanel(body);const cf=document.getElementById("clearFilter");if(cf)cf.onclick=()=>{tabFilter=null;render();};
|
|
422
|
+
const ds=document.getElementById("dataSort");if(ds)ds.onclick=ev=>{ev.preventDefault();dataNewest=!dataNewest;render();};}
|
|
423
|
+
else if(tab==="information"){const card=(p,flag)=>factCard({id:p.id,content:p.content,domain_hint:p.domain_hint,confidence:p.confidence,importance:p.importance,speaker:p.speaker,speaker_role:p.speaker_role,created_at:p.created_at,valid_from:p.valid_from_hint,valid_until:p.valid_until_hint,source_origin:p.source_origin,source_quality:p.source_quality},flag,"i");
|
|
424
|
+
const filtered=tabFilter&&tabFilter.tab==="information";const rows=filtered?(tabFilter.iId&&infoById.get(tabFilter.iId)?[infoById.get(tabFilter.iId)]:[]):info;
|
|
425
|
+
let html="";if(filtered)html+="<div class='filterbar'><div><div class='filterbar-title'>Showing "+rows.length+" of "+info.length+" Information</div></div><button type='button' id='clearFilter'>Clear filter</button></div>";
|
|
426
|
+
if(!rows.length)html+=filtered?"<p class='empty'>No extracted sentence is linked to that Knowledge.</p>":"<p class='empty'>No extracted sentences for this name.</p>";
|
|
427
|
+
else html+=rows.map(p=>card(p,p.consolidation_id?"extracted":"waiting")).join("");
|
|
428
|
+
body.innerHTML=html;bindPanel(body);const cf=document.getElementById("clearFilter");if(cf)cf.onclick=()=>{tabFilter=null;render();};}
|
|
429
|
+
else{const inc=(DATA.edges||[]).filter(e=>e.from===n.id||e.to===n.id).sort((a,b)=>b.strength-a.strength);const seen=new Set();const neigh=[];
|
|
430
|
+
for(const e of inc){const other=e.from===n.id?e.to:e.from;if(seen.has(other))continue;seen.add(other);neigh.push({id:other,edge:e});if(neigh.length>=15)break;}
|
|
431
|
+
if(!neigh.length)body.innerHTML="<p class='empty'>No co-mention edges from this node.</p>";
|
|
432
|
+
else{body.innerHTML="<ul class='nlist'>"+neigh.map(x=>{const o=byId.get(x.id);return "<li><a class='link go' data-id='"+x.id+"'>"+esc(o&&o.name)+"</a> · "+esc(o&&o.type)+" · strength "+x.edge.strength.toFixed(2)+"</li>";}).join("")+"</ul>";
|
|
433
|
+
body.querySelectorAll("a.go").forEach(a=>a.onclick=()=>{const t=byId.get(a.getAttribute("data-id"));if(!t)return;selected=t;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(t.id);render();draw();});}}
|
|
434
|
+
}
|
|
435
|
+
function rebuild(resetCam){const cap=Number(document.getElementById("cap").value);document.getElementById("capLabel").textContent=String(cap);
|
|
436
|
+
const vis=visibleIds(cap,document.getElementById("q").value,document.getElementById("type").value,selected,focusMode);
|
|
437
|
+
startLayout(vis.ids,{fresh:!!resetCam});if(vis.focus)selected=vis.focus;else if(selected&&!vis.ids.has(selected.id))selected=null;syncRefocus();if(resetCam)cam={x:0,y:0,k:1};}
|
|
438
|
+
function selectedOnScreen(){if(!selected)return true;const p=sim.find(n=>n.id===selected.id);if(!p)return false;const sx=cv.clientWidth/2+cam.x+p.x*cam.k,sy=cv.clientHeight/2+cam.y+p.y*cam.k;const m=48;return sx>m&&sy>m&&sx<cv.clientWidth-m&&sy<cv.clientHeight-m;}
|
|
439
|
+
function syncRefocus(){const btn=document.getElementById("refocus");if(!selected){btn.hidden=true;return;}
|
|
440
|
+
if(selected.id!==focusedId){btn.textContent="Refocus";btn.dataset.mode="rebuild";btn.hidden=false;}
|
|
441
|
+
else if(!selectedOnScreen()){btn.textContent="Recentre";btn.dataset.mode="centre";btn.hidden=false;}else btn.hidden=true;}
|
|
442
|
+
function recenter(){if(!selected)return;const p=sim.find(n=>n.id===selected.id);if(!p)return;cam.x=-p.x*cam.k;cam.y=-p.y*cam.k;draw();syncRefocus();}
|
|
443
|
+
function refocus(){if(!selected)return;focusMode=true;focusedId=selected.id;fitAfterAnim=true;rebuild(false);fitView();render();syncRefocus();}
|
|
444
|
+
function fitView(){if(!sim.length)return;let minx=Infinity,maxx=-Infinity,miny=Infinity,maxy=-Infinity;for(const p of sim){const r=radius(p);minx=Math.min(minx,p.x-r);maxx=Math.max(maxx,p.x+r+96);miny=Math.min(miny,p.y-r-10);maxy=Math.max(maxy,p.y+r+10);}
|
|
445
|
+
const pad=16,w=Math.max(cv.clientWidth-pad*2,1),h=Math.max(cv.clientHeight-pad*2,1),bw=Math.max(maxx-minx,1),bh=Math.max(maxy-miny,1);
|
|
446
|
+
cam.k=Math.max(0.2,Math.min(6,Math.min(w/bw,h/bh)));cam.x=-((minx+maxx)/2)*cam.k;cam.y=-((miny+maxy)/2)*cam.k;draw();}
|
|
447
|
+
function zoomBy(f){cam.k=Math.min(8,Math.max(0.15,cam.k*f));draw();}
|
|
448
|
+
function resize(){const r=cv.getBoundingClientRect();cv.width=r.width*devicePixelRatio;cv.height=r.height*devicePixelRatio;ctx.setTransform(devicePixelRatio,0,0,devicePixelRatio,0,0);draw();}
|
|
449
|
+
cv.addEventListener("mousedown",ev=>{const n=hitNode(ev.offsetX,ev.offsetY);down={x:ev.offsetX,y:ev.offsetY,n,e:n?null:hitEdge(ev.offsetX,ev.offsetY)};});
|
|
450
|
+
cv.addEventListener("dblclick",ev=>{ev.preventDefault();const n=hitNode(ev.offsetX,ev.offsetY);if(n){selected=n;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(n.id);refocus();}});
|
|
451
|
+
window.addEventListener("mousemove",ev=>{if(!down&&!dragging&&!lastPan)return;const rect=cv.getBoundingClientRect();const x=ev.clientX-rect.left,y=ev.clientY-rect.top;
|
|
452
|
+
if(down&&!dragging&&!lastPan){if(Math.hypot(x-down.x,y-down.y)<5)return;if(down.n)dragging=down.n;else lastPan={x:down.x,y:down.y};down=null;}
|
|
453
|
+
if(dragging){const p=screenToWorld(x,y);dragging.x=p.x;dragging.y=p.y;draw();}else if(lastPan){cam.x+=x-lastPan.x;cam.y+=y-lastPan.y;lastPan={x,y};draw();}});
|
|
454
|
+
window.addEventListener("mouseup",()=>{if(down){if(down.n){selected=down.n;selectedEdge=null;tab="knowledge";tabFilter=null;markHot(down.n.id);render();syncRefocus();draw();}else if(down.e){selectedEdge={from:down.e.from,to:down.e.to};render();draw();}}down=null;dragging=null;lastPan=null;});
|
|
455
|
+
cv.addEventListener("wheel",ev=>{ev.preventDefault();cam.k=Math.min(8,Math.max(0.15,cam.k*(ev.deltaY<0?1.08:1/1.08)));draw();},{passive:false});
|
|
456
|
+
document.getElementById("q").addEventListener("input",()=>{selectedEdge=null;const q=document.getElementById("q").value.trim().toLowerCase();
|
|
457
|
+
const hit=(DATA.nodes||[]).find(n=>n.name.toLowerCase()===q||n.canonical_name===q)||(DATA.nodes||[]).find(n=>n.name.toLowerCase().includes(q)||n.canonical_name.includes(q));
|
|
458
|
+
selected=hit||null;tabFilter=null;if(selected)markHot(selected.id);syncRefocus();if(selected&&!sim.some(p=>p.id===selected.id)){focusMode=true;rebuild(false);}else draw();render();});
|
|
459
|
+
document.getElementById("type").addEventListener("change",()=>{rebuild(false);render();});
|
|
460
|
+
document.getElementById("cap").addEventListener("input",()=>{document.getElementById("capLabel").textContent=String(document.getElementById("cap").value);});
|
|
461
|
+
document.getElementById("cap").addEventListener("change",()=>{rebuild(false);render();});
|
|
462
|
+
document.getElementById("refocus").addEventListener("click",ev=>{ev.stopPropagation();if(document.getElementById("refocus").dataset.mode==="centre")recenter();else refocus();});
|
|
463
|
+
document.getElementById("details").addEventListener("click",()=>{showDetails=!showDetails;try{localStorage.setItem("om-inspect-details",showDetails?"1":"0");}catch(e){}document.getElementById("details").classList.toggle("on",showDetails);render();});
|
|
464
|
+
document.getElementById("details").classList.toggle("on",showDetails);
|
|
465
|
+
function effectiveTheme(){const mode=document.documentElement.getAttribute("data-theme")||"system";if(mode==="light"||mode==="dark")return mode;return matchMedia("(prefers-color-scheme: light)").matches?"light":"dark";}
|
|
466
|
+
function syncThemeButton(){const light=effectiveTheme()==="light";document.getElementById("themeSun").hidden=light;document.getElementById("themeMoon").hidden=!light;}
|
|
467
|
+
function applyTheme(mode){document.documentElement.setAttribute("data-theme",mode==="light"||mode==="dark"?mode:"system");try{localStorage.setItem("om-inspect-theme",document.documentElement.getAttribute("data-theme"));}catch(e){}syncThemeButton();draw();}
|
|
468
|
+
let theme="system";try{theme=localStorage.getItem("om-inspect-theme")||"system";}catch(e){}applyTheme(theme);
|
|
469
|
+
document.getElementById("themeBtn").addEventListener("click",()=>{const osLight=matchMedia("(prefers-color-scheme: light)").matches;const next=effectiveTheme()==="light"?"dark":"light";applyTheme(next===(osLight?"light":"dark")?"system":next);});
|
|
470
|
+
document.getElementById("zoomIn").addEventListener("click",ev=>{ev.stopPropagation();zoomBy(1.2);});
|
|
471
|
+
document.getElementById("zoomOut").addEventListener("click",ev=>{ev.stopPropagation();zoomBy(1/1.2);});
|
|
472
|
+
document.getElementById("zoomFit").addEventListener("click",ev=>{ev.stopPropagation();fitView();});
|
|
473
|
+
function currentDock(){const c=[...document.getElementById("stage").classList].find(x=>x.startsWith("dock-"));return c?c.slice(5):"right";}
|
|
474
|
+
function closeDockMenu(){const menu=document.getElementById("dockMenu");menu.classList.remove("open");menu.hidden=true;}
|
|
475
|
+
function setDock(side){document.getElementById("stage").className="dock-"+side;document.getElementById("dockBtnIco").className="dock-ico "+side;closeDockMenu();resize();}
|
|
476
|
+
document.getElementById("dockBtn").addEventListener("click",ev=>{ev.stopPropagation();const menu=document.getElementById("dockMenu");const open=!menu.classList.contains("open");menu.classList.toggle("open",open);menu.hidden=!open;});
|
|
477
|
+
document.getElementById("dockMenu").addEventListener("click",ev=>{ev.stopPropagation();const b=ev.target.closest("[data-dock]");if(!b||b.classList.contains("is-current"))return;setDock(b.getAttribute("data-dock"));});
|
|
478
|
+
document.addEventListener("click",()=>closeDockMenu());
|
|
479
|
+
document.addEventListener("keydown",ev=>{if(ev.key==="Escape"){if(tabFilter){tabFilter=null;render();ev.preventDefault();}closeDockMenu();}});
|
|
480
|
+
let splitDrag=null;document.getElementById("splitter").addEventListener("mousedown",ev=>{ev.preventDefault();ev.stopPropagation();splitDrag={dock:currentDock(),rect:document.getElementById("stage").getBoundingClientRect()};});
|
|
481
|
+
window.addEventListener("mousemove",ev=>{if(!splitDrag)return;const {dock,rect}=splitDrag;let size=dock==="right"?rect.right-ev.clientX:dock==="left"?ev.clientX-rect.left:dock==="bottom"?rect.bottom-ev.clientY:ev.clientY-rect.top;
|
|
482
|
+
const max=(dock==="left"||dock==="right")?rect.width*0.7:rect.height*0.7;size=Math.max(220,Math.min(max,size));document.getElementById("stage").style.setProperty("--panel",size+"px");resize();});
|
|
483
|
+
window.addEventListener("mouseup",()=>{splitDrag=null;});
|
|
484
|
+
document.getElementById("reset").addEventListener("click",()=>{document.getElementById("q").value="";document.getElementById("type").value="";document.getElementById("cap").value="50";document.getElementById("capLabel").textContent="50";
|
|
485
|
+
selected=null;selectedEdge=null;focusMode=false;focusedId=null;tab="knowledge";tabFilter=null;hotSet=null;sim=[];rebuild(true);render();});
|
|
486
|
+
window.addEventListener("resize",resize);rebuild(true);render();resize();
|
|
487
|
+
</script>
|
|
488
|
+
</body>
|
|
489
489
|
</html>`;
|
|
490
490
|
}
|
|
491
491
|
//# sourceMappingURL=inspect-html.js.map
|