@polycode-projects/the-mechanical-code-talker 6.0.1 → 6.0.2
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/package.json +9 -2
- package/src/adapters/corpus/courtesy.mjs +67 -3
- package/src/adapters/corpus/dbpedia-lookup-live.mjs +8 -0
- package/src/adapters/corpus/wikidata-live.mjs +8 -0
- package/src/adapters/corpus/wikipedia-live.mjs +18 -0
- package/src/adapters/corpus/wiktionary-live.mjs +8 -0
- package/src/domain/source-breaker.mjs +259 -0
- package/src/services/chat.mjs +242 -77
- package/src/services/news-viz.mjs +213 -348
- package/src/services/news.mjs +41 -7
- package/src/services/p2p-room.mjs +35 -21
- package/src/surfaces/web/memory-ask-browser.bundle.js +135 -135
- package/src/surfaces/web/news-browser-entry.mjs +204 -464
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
// news-viz.mjs — news.html: a
|
|
2
|
-
// (
|
|
3
|
-
// (src/services/ledger-viz.mjs: `.dash
|
|
4
|
-
// same THEME_TOKENS_CSS palette)
|
|
5
|
-
// (src/services/chat-page-viz.mjs: SEED_STAMP/SEED_BYTES, the tmct.seed
|
|
6
|
-
// phase pill, loadSeedPayload/fetchWithProgress).
|
|
1
|
+
// news-viz.mjs — news.html: a thin client over the row service's news
|
|
2
|
+
// routes (PLAN_MEMORY_BACKEND.md's news.html-goes-thin revision), on the
|
|
3
|
+
// ledger.html dashboard precedent (src/services/ledger-viz.mjs: `.dash`/
|
|
4
|
+
// `.kpirow`/`.tile`/`.tile-bars`, the same THEME_TOKENS_CSS palette).
|
|
7
5
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
6
|
+
// This page carries no engine and no seed. Every card, tile, bar, source
|
|
7
|
+
// status line and request-log row it ever shows is read straight off one
|
|
8
|
+
// document — `GET /api/feed` — and nothing here recomputes any of it. The
|
|
9
|
+
// only client-side work is: mint a session key at the first press, POST the
|
|
10
|
+
// three trigger routes (poll/enrich/ingest) on their own press, wait for the
|
|
11
|
+
// cycle each one starts to materialize, and render the document that comes
|
|
12
|
+
// back. src/surfaces/web/news-browser-entry.mjs is the whole of that; this
|
|
13
|
+
// file is markup, CSS and the inline script wiring DOM to it.
|
|
16
14
|
//
|
|
17
|
-
// Every fetched or user-supplied string this page
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// this page's engine calls.
|
|
15
|
+
// Every fetched or user-supplied string this page ever shows (a card's
|
|
16
|
+
// paragraph, a fact line, a source name, teach-panel text) goes through
|
|
17
|
+
// escapeHtml at render time — the page's one sanitisation layer, since
|
|
18
|
+
// nothing here parses raw prose itself; that already happened server-side,
|
|
19
|
+
// in the worker, before the string ever reached this document.
|
|
23
20
|
import {
|
|
24
21
|
THEME_TOKENS_CSS, MONO_STACK, escapeHtml, embedJson, demoEyebrowHtml, EYEBROW_LINKS_CSS,
|
|
25
22
|
} from "./viz-theme.mjs";
|
|
26
|
-
import { loadSeedPayload, fetchWithProgress, factTripleParts } from "./memory-panel-viz.mjs";
|
|
27
|
-
import { phraseRendererSource, FACT_PREDICATE_PHRASES } from "../domain/fact-phrase.mjs";
|
|
28
23
|
import { NEWS_SOURCE_RECORDS } from "../adapters/corpus/news-sources.mjs";
|
|
29
24
|
|
|
30
|
-
const DEFAULT_TITLE = "tmct news — a
|
|
25
|
+
const DEFAULT_TITLE = "tmct news — a feed the graph only shows what it can ground";
|
|
31
26
|
|
|
32
27
|
const DASH_SANS_STACK = `-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`;
|
|
33
28
|
|
|
34
29
|
/** One `.tile` cell for the KPI row — the zero-state every tile renders in
|
|
35
|
-
* before the first
|
|
36
|
-
* number
|
|
37
|
-
*
|
|
30
|
+
* before the first render call, since the page's own JS overwrites every
|
|
31
|
+
* number the moment a feed document (real or empty) is in hand. Static
|
|
32
|
+
* markup only. */
|
|
38
33
|
function kpiTileHtml(label, id) {
|
|
39
34
|
return `<div class="tile" id="${escapeHtml(id)}">
|
|
40
35
|
<span class="tile-label">${escapeHtml(label)}</span>
|
|
@@ -53,8 +48,13 @@ function barPanelHtml(label, id) {
|
|
|
53
48
|
function sourceRowsHtml(kind) {
|
|
54
49
|
return NEWS_SOURCE_RECORDS.filter((r) => (kind === "kb" ? r.kind === "kb" : r.kind !== "kb")).map((r) => {
|
|
55
50
|
const cls = r.kind === "kb" ? "kb" : "contemporary";
|
|
51
|
+
// Only the contemporary group offers a checkbox: it narrows the NEXT
|
|
52
|
+
// poll trigger's own `{sources:[...]}` body, never a fetch of its own.
|
|
53
|
+
// The kb group has no client-supplied roster in the hosted worker, so
|
|
54
|
+
// it renders as plain status, not a control.
|
|
55
|
+
const toggle = kind === "kb" ? "" : `<input type="checkbox" data-source-toggle value="${escapeHtml(r.id)}" ${r.enabledByDefault ? "checked" : ""}>`;
|
|
56
56
|
return `<label class="sourcerow ${cls}" data-source-id="${escapeHtml(r.id)}">
|
|
57
|
-
|
|
57
|
+
${toggle}
|
|
58
58
|
<span class="sourcename">${escapeHtml(r.name)}</span>
|
|
59
59
|
<a class="sourcehome" href="${escapeHtml(r.homepage)}" target="_blank" rel="noopener">homepage</a>
|
|
60
60
|
<span class="sourcestatus" data-source-status>not yet polled</span>
|
|
@@ -63,18 +63,18 @@ function sourceRowsHtml(kind) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** The one fenced region carrying every third-party URL this page ever
|
|
66
|
-
* names
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
66
|
+
* names — every source's own homepage link, and the embedded source
|
|
67
|
+
* registry the panel reads. No fetch happens because this markup rendered;
|
|
68
|
+
* the worker does the fetching, server-side, and only after a trigger this
|
|
69
|
+
* page's own click sent it. */
|
|
70
70
|
function sourcesConfigBlockHtml() {
|
|
71
71
|
return `<!-- sources:start -->
|
|
72
72
|
<div class="sources" id="sourcesConfig" aria-label="News sources">
|
|
73
|
-
<h2 class="tile-label" id="pollRosterLabel">news feeds —
|
|
73
|
+
<h2 class="tile-label" id="pollRosterLabel">news feeds — the worker polls these when you press start, narrowed to what's checked</h2>
|
|
74
74
|
<div class="sourcegroup" id="pollRoster" aria-labelledby="pollRosterLabel">
|
|
75
75
|
${sourceRowsHtml("contemporary")}
|
|
76
76
|
</div>
|
|
77
|
-
<h2 class="tile-label" id="lookupRosterLabel">reference works —
|
|
77
|
+
<h2 class="tile-label" id="lookupRosterLabel">reference works — the worker looks a term up here to explain it, never polled</h2>
|
|
78
78
|
<div class="sourcegroup" id="lookupRoster" aria-labelledby="lookupRosterLabel">
|
|
79
79
|
${sourceRowsHtml("kb")}
|
|
80
80
|
</div>
|
|
@@ -108,6 +108,9 @@ ${THEME_TOKENS_CSS}
|
|
|
108
108
|
.bbtrack { background: var(--line); border-radius: 99px; height: 5px; overflow: hidden; }
|
|
109
109
|
.bbfill { display: block; height: 100%; background: var(--ink); opacity: .6; border-radius: 99px; }
|
|
110
110
|
.bbn { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
|
|
111
|
+
.privacy { font-size: .78rem; color: var(--muted); margin: 0 0 .8rem; max-width: 46rem; }
|
|
112
|
+
.unavailable { display: none; background: var(--alert-soft); border: 1px solid var(--alert); border-radius: 6px; padding: .6rem .8rem; margin-bottom: 1rem; font-size: .84rem; }
|
|
113
|
+
.unavailable.shown { display: block; }
|
|
111
114
|
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .6rem .7rem; margin-bottom: 1rem; }
|
|
112
115
|
.btn { font-family: ${MONO_STACK}; font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: .3rem .65rem; background: var(--bg); }
|
|
113
116
|
.btn:hover { color: var(--ink); border-color: var(--ink); }
|
|
@@ -118,8 +121,7 @@ ${THEME_TOKENS_CSS}
|
|
|
118
121
|
.btn[aria-busy="true"]::after { content: ""; display: inline-block; width: .5em; height: .5em; margin-left: .45em; border-radius: 50%; background: currentColor; animation: pulse 1s ease-in-out infinite; }
|
|
119
122
|
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
|
|
120
123
|
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::after { animation: none; opacity: .7; } }
|
|
121
|
-
select
|
|
122
|
-
.urlinput { flex: 1 1 12rem; min-width: 8rem; }
|
|
124
|
+
select { font-family: ${MONO_STACK}; font-size: .72rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .3rem .55rem; }
|
|
123
125
|
.sources { display: flex; flex-direction: column; gap: .3rem; margin: .6rem 0; }
|
|
124
126
|
.sources h2 { margin: .6rem 0 .1rem; }
|
|
125
127
|
.sourcegroup { display: flex; flex-direction: column; gap: .3rem; }
|
|
@@ -132,7 +134,7 @@ ${THEME_TOKENS_CSS}
|
|
|
132
134
|
.reqlog { margin-bottom: 1rem; max-width: 100%; overflow-x: auto; }
|
|
133
135
|
.reqlog table { width: 100%; table-layout: fixed; border-collapse: collapse; font-family: ${MONO_STACK}; font-size: .7rem; }
|
|
134
136
|
.reqlog th, .reqlog td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
|
|
135
|
-
.reqlog tbody:empty::after { content: "no requests yet — nothing has
|
|
137
|
+
.reqlog tbody:empty::after { content: "no requests yet — nothing has been polled before you press start"; }
|
|
136
138
|
.feedwrap { margin-bottom: 1.2rem; }
|
|
137
139
|
.feedbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .45rem; }
|
|
138
140
|
.feedbar label { font-family: ${MONO_STACK}; font-size: .66rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
|
|
@@ -146,14 +148,14 @@ ${THEME_TOKENS_CSS}
|
|
|
146
148
|
.item { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; }
|
|
147
149
|
.item .hub { font-weight: 700; font-size: 1.05rem; }
|
|
148
150
|
.item .tier { font-family: ${MONO_STACK}; font-size: .64rem; padding: .05rem .5rem; border-radius: 99px; border: 1px solid var(--line); margin-left: .5rem; }
|
|
149
|
-
.item .
|
|
151
|
+
.item .newtag { font-family: ${MONO_STACK}; font-size: .64rem; color: var(--taught); margin-left: .5rem; }
|
|
150
152
|
.item .paragraph { margin: .4rem 0; }
|
|
151
153
|
.item .sources-links { font-size: .74rem; color: var(--muted); }
|
|
152
154
|
.item details.facts summary { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--corpus); cursor: pointer; }
|
|
153
155
|
.item details.background summary { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--muted); cursor: pointer; }
|
|
154
156
|
.item details.background p { margin: .35rem 0 0; color: var(--muted); }
|
|
155
157
|
.item .factrow { font-family: ${MONO_STACK}; font-size: .68rem; padding: .15rem 0; border-bottom: 1px dotted var(--line); }
|
|
156
|
-
.item .
|
|
158
|
+
.item .factrow.factmore { color: var(--muted); border-bottom: none; }
|
|
157
159
|
.empty { color: var(--muted); font-size: .85rem; border: 1px dashed var(--line); border-radius: 6px; padding: .8rem 1rem; }
|
|
158
160
|
.teach { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .7rem .85rem; margin-bottom: 1rem; }
|
|
159
161
|
.teach textarea { width: 100%; box-sizing: border-box; min-height: 90px; font-family: ${MONO_STACK}; font-size: .76rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; }
|
|
@@ -161,18 +163,13 @@ ${THEME_TOKENS_CSS}
|
|
|
161
163
|
.pagelog { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--muted); max-height: 140px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: .4rem; }
|
|
162
164
|
`;
|
|
163
165
|
|
|
164
|
-
/** `renderNewsHtml({ title
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
* generated page threads even before it has its own digest affordance. */
|
|
172
|
-
export function renderNewsHtml({ title = DEFAULT_TITLE, seedStamp = "", seedBytes = 0, digestStructures = [] } = {}) {
|
|
173
|
-
const digestJson = embedJson(Array.isArray(digestStructures) ? digestStructures : []);
|
|
174
|
-
const factPhrasesJson = embedJson(FACT_PREDICATE_PHRASES);
|
|
175
|
-
|
|
166
|
+
/** `renderNewsHtml({ title })` — one self-contained document: the dashboard,
|
|
167
|
+
* the controls row (start/poll, enrich now, stop & forget), the source
|
|
168
|
+
* panel, the request log, the feed, and the teach panel. Everything below
|
|
169
|
+
* the teach panel is left unclaimed for the chat area this page will grow
|
|
170
|
+
* next — an empty `#chatMount` section, not a placeholder for engine work
|
|
171
|
+
* of its own. */
|
|
172
|
+
export function renderNewsHtml({ title = DEFAULT_TITLE } = {}) {
|
|
176
173
|
return `<!doctype html>
|
|
177
174
|
<html lang="en">
|
|
178
175
|
<head>
|
|
@@ -188,8 +185,12 @@ ${NEWS_STYLE}
|
|
|
188
185
|
</head>
|
|
189
186
|
<body>
|
|
190
187
|
<main>
|
|
191
|
-
<div class="eyebrow"><span>${demoEyebrowHtml("news", "news")}</span><span id="
|
|
192
|
-
<h1 class="visually-hidden">news — a
|
|
188
|
+
<div class="eyebrow"><span>${demoEyebrowHtml("news", "news")}</span><span id="sessionPill" data-sub></span></div>
|
|
189
|
+
<h1 class="visually-hidden">news — a feed the graph only shows what it can ground</h1>
|
|
190
|
+
|
|
191
|
+
<p class="privacy">This session is anonymous. Pressing start keeps a random key for it in this browser; everything you poll or teach here is stored against that key on the server for seven days. Stop & forget hides all of it at once, and the stored copies are gone for good within that same week.</p>
|
|
192
|
+
|
|
193
|
+
<div class="unavailable" id="serviceUnavailable" role="alert">The news service isn't answering right now, so there's nothing to show. Reload the page to try again.</div>
|
|
193
194
|
|
|
194
195
|
<section class="dash" id="dash" aria-label="News metrics">
|
|
195
196
|
<div class="kpirow">
|
|
@@ -197,7 +198,7 @@ ${NEWS_STYLE}
|
|
|
197
198
|
${kpiTileHtml("terms.ungrounded", "tileTermsUngrounded")}
|
|
198
199
|
${kpiTileHtml("facts.from-news", "tileFactsFromNews")}
|
|
199
200
|
${kpiTileHtml("graph.size", "tileGraphSize")}
|
|
200
|
-
${kpiTileHtml("sources.
|
|
201
|
+
${kpiTileHtml("sources.reporting", "tileSourcesLive")}
|
|
201
202
|
</div>
|
|
202
203
|
<div class="barpanels">
|
|
203
204
|
${barPanelHtml("terms.ranked", "panelTermsRanked")}
|
|
@@ -207,28 +208,15 @@ ${NEWS_STYLE}
|
|
|
207
208
|
|
|
208
209
|
<div class="controls" id="controls">
|
|
209
210
|
<button type="button" class="btn primary" id="newsStart">start polling live sources</button>
|
|
210
|
-
<button type="button" class="btn" id="pollOnce">poll once</button>
|
|
211
|
-
<button type="button" class="btn" id="stopPolling" disabled>stop polling</button>
|
|
212
|
-
<label class="mono" for="pollInterval">poll every</label>
|
|
213
|
-
<select id="pollInterval">
|
|
214
|
-
<option value="0">off</option>
|
|
215
|
-
<option value="5">5 min</option>
|
|
216
|
-
<option value="15" selected>15 min</option>
|
|
217
|
-
<option value="60">60 min</option>
|
|
218
|
-
</select>
|
|
219
|
-
<button type="button" class="btn ghost" id="stopForget">stop & forget</button>
|
|
220
211
|
<button type="button" class="btn" id="enrichNow">enrich now</button>
|
|
221
|
-
<
|
|
222
|
-
<button type="button" class="btn" id="addSourceBtn">add</button>
|
|
223
|
-
<button type="button" class="btn" id="replayNyt">replay recorded NYT sample</button>
|
|
224
|
-
<button type="button" class="btn" id="replayWikipedia">replay recorded Wikipedia sample</button>
|
|
212
|
+
<button type="button" class="btn ghost" id="stopForget">stop & forget</button>
|
|
225
213
|
<span class="mono" id="controlsStatus" aria-live="polite"></span>
|
|
226
214
|
</div>
|
|
227
215
|
|
|
228
216
|
${sourcesConfigBlockHtml()}
|
|
229
217
|
|
|
230
218
|
<section class="reqlog" id="requestLog" aria-label="Request log">
|
|
231
|
-
<h2 class="tile-label">request log</h2>
|
|
219
|
+
<h2 class="tile-label">the worker's own request log</h2>
|
|
232
220
|
<table>
|
|
233
221
|
<thead><tr><th>url</th><th>at</th><th>bytes</th><th>status</th></tr></thead>
|
|
234
222
|
<tbody id="requestLogBody"></tbody>
|
|
@@ -247,38 +235,35 @@ ${NEWS_STYLE}
|
|
|
247
235
|
</div>
|
|
248
236
|
<div class="pills" id="feedPills" aria-label="Filter the feed by key term"></div>
|
|
249
237
|
<div class="feed" id="feed" tabindex="0">
|
|
250
|
-
<div class="empty" id="feedEmpty">no news yet — the feed only shows named people, places and events
|
|
238
|
+
<div class="empty" id="feedEmpty">no news yet — the feed only shows named people, places and events the worker has reported. press start to fetch some.</div>
|
|
251
239
|
</div>
|
|
252
240
|
</section>
|
|
253
241
|
|
|
254
242
|
<section class="teach" id="teachPanel">
|
|
255
243
|
<h2 class="tile-label">teach the graph</h2>
|
|
256
|
-
<textarea id="teachText" spellcheck="false" aria-label="Text or fact rows to ingest" placeholder="Paste prose, or drop a .txt/.md/.
|
|
244
|
+
<textarea id="teachText" spellcheck="false" aria-label="Text or fact rows to ingest" placeholder="Paste prose, or drop a .txt/.md/.jsonl file below."></textarea>
|
|
257
245
|
<div class="teachrow">
|
|
258
246
|
<button type="button" class="btn" id="exampleProse">example: prose</button>
|
|
259
247
|
<button type="button" class="btn" id="exampleJsonl">example: facts (.jsonl)</button>
|
|
260
248
|
<button type="button" class="btn" id="teachBrowse">browse…</button>
|
|
261
|
-
<input type="file" id="teachFile" accept=".txt,.md,.
|
|
249
|
+
<input type="file" id="teachFile" accept=".txt,.md,.jsonl" hidden>
|
|
262
250
|
<button type="button" class="btn primary" id="teachIngest">ingest</button>
|
|
263
251
|
<span class="mono" id="teachStatus" aria-live="polite"></span>
|
|
264
252
|
</div>
|
|
265
253
|
</section>
|
|
266
254
|
|
|
255
|
+
<section id="chatMount" aria-label="Chat"></section>
|
|
256
|
+
|
|
267
257
|
<div class="pagelog" id="pageLog" aria-live="polite"></div>
|
|
268
258
|
</main>
|
|
269
|
-
<script>
|
|
270
|
-
const DIGEST_STRUCTURES = ${digestJson};
|
|
271
|
-
const SEED_STAMP = ${JSON.stringify(seedStamp)};
|
|
272
|
-
const SEED_QUERY = SEED_STAMP ? "?b=" + SEED_STAMP : "";
|
|
273
|
-
const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
274
|
-
</script>
|
|
275
259
|
<!--
|
|
276
260
|
news-browser.bundle.js (built by scripts/build-news-bundle.mjs) publishes
|
|
277
261
|
window.tmct — createNewsSession as tmct.open(), every session verb as
|
|
278
262
|
tmct.session.<verb>(). The inline script below only wires DOM to that
|
|
279
|
-
surface; it never touches the network
|
|
280
|
-
|
|
281
|
-
traceable to one of the session's own
|
|
263
|
+
surface; it never touches the network directly (createHttpRowBackend
|
|
264
|
+
inside the session does, over the row service's own routes), so every
|
|
265
|
+
request this page ever makes is traceable to one of the session's own
|
|
266
|
+
methods, each reached only from a click this script handles.
|
|
282
267
|
-->
|
|
283
268
|
<script src="./news-browser.bundle.js"></script>
|
|
284
269
|
<script>
|
|
@@ -286,11 +271,8 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
286
271
|
"use strict";
|
|
287
272
|
const el = (id) => document.getElementById(id);
|
|
288
273
|
const esc = ${escapeHtml.toString()};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const factTripleParts = ${factTripleParts.toString()};
|
|
292
|
-
const fetchWithProgress = ${fetchWithProgress.toString()};
|
|
293
|
-
const loadSeedPayload = ${loadSeedPayload.toString()};
|
|
274
|
+
|
|
275
|
+
const EMPTY_FEED = { items: [], rankedTerms: [], stats: { graphSize: 0, factsFromNews: 0 }, sourceStatus: [], requestLog: [], builtAt: null };
|
|
294
276
|
|
|
295
277
|
function appendLog(text) {
|
|
296
278
|
const line = document.createElement("div");
|
|
@@ -321,79 +303,90 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
321
303
|
node.querySelector("[data-bars]").innerHTML = microbars(items);
|
|
322
304
|
}
|
|
323
305
|
|
|
324
|
-
|
|
306
|
+
// Every network-facing control disables together the moment the service
|
|
307
|
+
// stops answering — none of them has anything left to do until it comes
|
|
308
|
+
// back. Enrich and teach each mint their own session independently of the
|
|
309
|
+
// "start" press, the same way the old page's add-source-by-url ran its
|
|
310
|
+
// own preflight regardless of poll consent — pressing any of them first
|
|
311
|
+
// is exactly what "the page mints the session, at consent" means.
|
|
312
|
+
function setUnavailable(isUnavailable) {
|
|
313
|
+
el("serviceUnavailable").classList.toggle("shown", isUnavailable);
|
|
314
|
+
["newsStart", "enrichNow", "stopForget", "teachIngest", "teachBrowse"].forEach(function (id) {
|
|
315
|
+
el(id).disabled = isUnavailable;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function renderRequestLog(feed) {
|
|
325
320
|
const body = el("requestLogBody");
|
|
326
321
|
body.innerHTML = "";
|
|
327
|
-
for (const row of (
|
|
322
|
+
for (const row of (feed.requestLog || [])) {
|
|
328
323
|
const tr = document.createElement("tr");
|
|
329
324
|
tr.innerHTML = "<td>" + esc(row.url) + "</td><td>" + esc(row.at) + "</td><td>" + esc(String(row.bytes)) + "</td><td>" + esc(row.status) + "</td>";
|
|
330
325
|
body.appendChild(tr);
|
|
331
326
|
}
|
|
332
327
|
}
|
|
333
328
|
|
|
334
|
-
function
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const enabled = new Set(config.sources);
|
|
339
|
-
document.querySelectorAll("[data-source-id]").forEach((row) => {
|
|
340
|
-
const id = row.getAttribute("data-source-id");
|
|
341
|
-
const h = byId.get(id);
|
|
329
|
+
function renderSourcesPanel(feed) {
|
|
330
|
+
const byId = new Map((feed.sourceStatus || []).map(function (h) { return [h.sourceId, h]; }));
|
|
331
|
+
document.querySelectorAll("[data-source-id]").forEach(function (row) {
|
|
332
|
+
const health = byId.get(row.getAttribute("data-source-id"));
|
|
342
333
|
const statusEl = row.querySelector("[data-source-status]");
|
|
343
|
-
let text = "
|
|
344
|
-
if (
|
|
345
|
-
if (
|
|
346
|
-
else if (
|
|
347
|
-
else if (
|
|
348
|
-
else text = "not yet polled";
|
|
334
|
+
let text = "not yet polled";
|
|
335
|
+
if (health) {
|
|
336
|
+
if (health.autoDisabled) text = "auto-disabled";
|
|
337
|
+
else if (health.browserBlocked) text = "source does not permit browser access";
|
|
338
|
+
else if (health.lastStatus) text = health.lastStatus;
|
|
349
339
|
}
|
|
350
340
|
statusEl.textContent = text;
|
|
351
341
|
});
|
|
352
|
-
|
|
342
|
+
setTile("tileSourcesLive", (feed.sourceStatus || []).length, "reported in the last cycle");
|
|
343
|
+
setBars("panelSourcesPerSource", (feed.sourceStatus || []).map(function (h) {
|
|
344
|
+
return { label: h.sourceId, count: h.consecutiveFailures ? 0 : 1 };
|
|
345
|
+
}));
|
|
353
346
|
}
|
|
354
347
|
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
348
|
+
function cardHtml(item) {
|
|
349
|
+
const factLines = item.factLines || [];
|
|
350
|
+
const factsHtml = factLines.map(function (line) { return '<div class="factrow">' + esc(line) + '</div>'; }).join("");
|
|
351
|
+
const moreCount = (item.factCount || 0) - factLines.length;
|
|
352
|
+
const moreHtml = moreCount > 0 ? '<div class="factrow factmore">…and ' + moreCount + ' more</div>' : "";
|
|
353
|
+
const sourcesText = (item.sources || []).map(function (s) { return esc(s.title || s.url || ""); }).filter(Boolean).join(", ");
|
|
354
|
+
const background = item.backgroundParagraph
|
|
355
|
+
? '<details class="background"><summary>what the graph already knew</summary><p>' + esc(item.backgroundParagraph) + '</p></details>'
|
|
356
|
+
: "";
|
|
357
|
+
const newTag = item.newName ? '<span class="newtag">new</span>' : "";
|
|
358
|
+
return '<div class="item" data-item-id="' + esc(item.id) + '">'
|
|
359
|
+
+ '<span class="hub">' + esc(item.hub) + '</span><span class="tier">' + esc(item.tier || "unranked") + '</span>' + newTag
|
|
360
|
+
+ '<p class="paragraph">' + esc(item.paragraph) + '</p>'
|
|
361
|
+
+ background
|
|
362
|
+
+ (sourcesText ? '<p class="sources-links">sources: ' + sourcesText + '</p>' : "")
|
|
363
|
+
+ '<details class="facts"><summary>' + (item.factCount || 0) + ' fact' + (item.factCount === 1 ? "" : "s") + '</summary>' + factsHtml + moreHtml + '</details>'
|
|
364
|
+
+ '</div>';
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
// The last
|
|
368
|
-
// pill toggle re-orders what is already on screen
|
|
369
|
-
//
|
|
367
|
+
// The last-rendered feed's own items and one built card per item, so a
|
|
368
|
+
// sort change or a pill toggle re-orders what is already on screen
|
|
369
|
+
// without asking the server for anything again.
|
|
370
370
|
let feedItems = [];
|
|
371
371
|
const cardsByItemId = new Map();
|
|
372
372
|
const activePillTerms = new Set();
|
|
373
|
-
|
|
374
|
-
// reported nothing newsworthy; the purge line once "stop & forget" has
|
|
375
|
-
// emptied the graph of articles, until the next poll (start or poll once)
|
|
376
|
-
// puts content back and reverts it — the same "next action that puts
|
|
377
|
-
// content back" rule the session's own forgotten flag follows.
|
|
378
|
-
const DEFAULT_EMPTY_FEED_TEXT = "no news yet — the feed only shows named people, places and events from polled sources. press poll once to fetch some.";
|
|
373
|
+
const DEFAULT_EMPTY_FEED_TEXT = "no news yet — the feed only shows named people, places and events the worker has reported. press start to fetch some.";
|
|
379
374
|
let emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
|
|
380
|
-
|
|
381
375
|
const MAX_PILLS = 12;
|
|
382
376
|
|
|
383
377
|
function itemMatchesActivePills(item) {
|
|
384
378
|
if (!activePillTerms.size) return true;
|
|
385
379
|
const haystack = (item.hub + " " + item.paragraph).toLowerCase();
|
|
386
|
-
for (const term of activePillTerms) {
|
|
387
|
-
if (item.hub === term || haystack.indexOf(term) !== -1) return true;
|
|
388
|
-
}
|
|
380
|
+
for (const term of activePillTerms) { if (item.hub === term || haystack.indexOf(term) !== -1) return true; }
|
|
389
381
|
return false;
|
|
390
382
|
}
|
|
391
383
|
|
|
392
384
|
function sortedFeedItems() {
|
|
393
385
|
const mode = el("feedSort").value;
|
|
394
386
|
const items = feedItems.slice();
|
|
395
|
-
if (mode === "facts") items.sort((a, b) => b.
|
|
396
|
-
else if (mode === "changed") items.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1));
|
|
387
|
+
if (mode === "facts") items.sort((a, b) => (b.factCount - a.factCount) || (a.hub < b.hub ? -1 : 1));
|
|
388
|
+
else if (mode === "changed") items.sort((a, b) => (b.changedCount - a.changedCount) || (a.hub < b.hub ? -1 : 1));
|
|
389
|
+
else items.sort((a, b) => (b.observedMs - a.observedMs) || (a.hub < b.hub ? -1 : 1));
|
|
397
390
|
return items;
|
|
398
391
|
}
|
|
399
392
|
|
|
@@ -401,7 +394,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
401
394
|
const pillsEl = el("feedPills");
|
|
402
395
|
const terms = feedItems
|
|
403
396
|
.slice()
|
|
404
|
-
.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1))
|
|
397
|
+
.sort((a, b) => (b.changedCount - a.changedCount) || (a.hub < b.hub ? -1 : 1))
|
|
405
398
|
.map((it) => it.hub)
|
|
406
399
|
.slice(0, MAX_PILLS);
|
|
407
400
|
for (const term of [...activePillTerms]) if (terms.indexOf(term) === -1) activePillTerms.delete(term);
|
|
@@ -439,117 +432,52 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
439
432
|
: (shown.length + " of " + feedItems.length + " articles");
|
|
440
433
|
}
|
|
441
434
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const feed = await window.tmct.session.buildFeed();
|
|
445
|
-
feedItems = feed.items;
|
|
435
|
+
function renderFeed(feed) {
|
|
436
|
+
feedItems = feed.items || [];
|
|
446
437
|
cardsByItemId.clear();
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const card = document.createElement("div");
|
|
452
|
-
card.className = "item";
|
|
453
|
-
const seedTag = feed.seedFallback ? '<span class="seedtag">from the seed graph — start to poll live sources</span>' : "";
|
|
454
|
-
const sourcesText = item.sources.map((s) => esc(s.title || s.url)).join(", ");
|
|
455
|
-
const facts = await factListHtml(item.factIds);
|
|
456
|
-
const background = item.backgroundParagraph
|
|
457
|
-
? '<details class="background"><summary>what the graph already knew</summary><p>' + esc(item.backgroundParagraph) + '</p></details>'
|
|
458
|
-
: "";
|
|
459
|
-
card.innerHTML =
|
|
460
|
-
'<span class="hub">' + esc(item.hub) + '</span><span class="tier">' + esc(item.tier || "unranked") + '</span>' + seedTag
|
|
461
|
-
+ '<p class="paragraph">' + esc(item.paragraph) + '</p>'
|
|
462
|
-
+ background
|
|
463
|
-
+ (sourcesText ? '<p class="sources-links">sources: ' + sourcesText + '</p>' : "")
|
|
464
|
-
+ '<details class="facts"><summary>' + item.factIds.length + ' facts</summary>' + facts + '</details>';
|
|
465
|
-
cardsByItemId.set(item.id, card);
|
|
466
|
-
// Each card shows the moment it is built; the paint below re-orders and
|
|
467
|
-
// filters what is already on screen.
|
|
468
|
-
if (itemMatchesActivePills(item)) { el("feedEmpty").hidden = true; feedEl.appendChild(card); }
|
|
438
|
+
for (const item of feedItems) {
|
|
439
|
+
const wrapper = document.createElement("div");
|
|
440
|
+
wrapper.innerHTML = cardHtml(item);
|
|
441
|
+
cardsByItemId.set(item.id, wrapper.firstElementChild);
|
|
469
442
|
}
|
|
470
443
|
renderPills();
|
|
471
444
|
paintFeed();
|
|
472
|
-
setTile("tileFeedItems",
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
async function renderGraphTiles() {
|
|
476
|
-
const stats = await window.tmct.session.stats();
|
|
477
|
-
setTile("tileFactsFromNews", stats.factsFromNews, stats.factsFromNews ? "polled, replayed or enriched" : "nothing ingested yet");
|
|
478
|
-
setTile("tileGraphSize", stats.graphSize, "facts in this session's graph");
|
|
445
|
+
setTile("tileFeedItems", feedItems.length, feed.trimmed ? "trimmed to fit — each card's own count says how much" : "");
|
|
479
446
|
}
|
|
480
447
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
448
|
+
function renderAll(feed) {
|
|
449
|
+
renderFeed(feed);
|
|
450
|
+
renderSourcesPanel(feed);
|
|
451
|
+
renderRequestLog(feed);
|
|
452
|
+
const ranked = feed.rankedTerms || [];
|
|
453
|
+
setTile("tileTermsUngrounded", ranked.length, ranked.length ? "ranked by occurrence" : "none yet");
|
|
454
|
+
setBars("panelTermsRanked", ranked.map((r) => ({
|
|
485
455
|
label: r.term + (r.vocabGrounded ? " (parseable but knowledge-free)" : " (unknown word)"),
|
|
486
456
|
count: r.count,
|
|
487
457
|
})));
|
|
458
|
+
const stats = feed.stats || { graphSize: 0, factsFromNews: 0 };
|
|
459
|
+
setTile("tileFactsFromNews", stats.factsFromNews, stats.factsFromNews ? "polled or taught" : "nothing ingested yet");
|
|
460
|
+
setTile("tileGraphSize", stats.graphSize, "facts in this session's graph");
|
|
488
461
|
}
|
|
489
462
|
|
|
490
|
-
function
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
async function renderAll() {
|
|
499
|
-
// Chips and tiles are cheap synchronous text writes; they lead so a
|
|
500
|
-
// just-finished poll reads back immediately while the feed's own slower,
|
|
501
|
-
// yielding render catches up behind it.
|
|
502
|
-
renderSourcesPanel();
|
|
503
|
-
await Promise.all([renderFeed(), renderRank(), renderRequestLog(), renderGraphTiles()]);
|
|
504
|
-
renderSourcesPanel();
|
|
505
|
-
window.tmct.news = Object.assign({}, window.tmct.news, {
|
|
506
|
-
phase: window.tmct.session.phase,
|
|
507
|
-
metrics: window.tmct.session.metrics,
|
|
508
|
-
nextPollAt: window.tmct.session.nextPollAt,
|
|
463
|
+
function looksLikeFactRows(text) {
|
|
464
|
+
const lines = String(text || "").split("\\n").map(function (l) { return l.trim(); }).filter(Boolean);
|
|
465
|
+
if (!lines.length) return false;
|
|
466
|
+
return lines.every(function (line) {
|
|
467
|
+
try {
|
|
468
|
+
const row = JSON.parse(line);
|
|
469
|
+
return row && typeof row === "object" && row.subject && row.predicate && row.object;
|
|
470
|
+
} catch { return false; }
|
|
509
471
|
});
|
|
510
|
-
appendLog("phase: " + window.tmct.session.phase);
|
|
511
472
|
}
|
|
512
473
|
|
|
513
474
|
async function boot() {
|
|
514
|
-
window.tmct.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
// every extract runs lexicon-blind and the whole enrich loop misses.
|
|
518
|
-
// Loaded alongside the seed, tolerated as absent the same way chat.html
|
|
519
|
-
// tolerates it, never blocking the page.
|
|
520
|
-
const winkLoad = (async function () {
|
|
521
|
-
try {
|
|
522
|
-
const mod = await Promise.race([
|
|
523
|
-
import("./vendor/wink.js"),
|
|
524
|
-
new Promise(function (resolve, reject) { setTimeout(function () { reject(new Error("wink vendor load timed out")); }, 20000); }),
|
|
525
|
-
]);
|
|
526
|
-
window.tmct.page.registerWinkModel(function () { return { winkNLP: mod.winkNLP, model: mod.model }; });
|
|
527
|
-
appendLog("wink vendor loaded — prose grounding armed");
|
|
528
|
-
} catch (err) {
|
|
529
|
-
appendLog("wink vendor unavailable — prose grounding runs lexicon-blind");
|
|
530
|
-
}
|
|
531
|
-
})();
|
|
532
|
-
const outcome = await loadSeedPayload(fetchWithProgress, "./chat-seed.json", SEED_QUERY, function () {});
|
|
533
|
-
window.tmct.seed = { state: outcome.status.state, facts: outcome.status.facts };
|
|
534
|
-
await winkLoad;
|
|
535
|
-
await window.tmct.open({ seedPayload: outcome.payload, vocabSeeded: Boolean(outcome.payload) });
|
|
536
|
-
|
|
537
|
-
// Every control binds before the phase flips to "seeded": the first feed
|
|
538
|
-
// render is deliberately slow (it yields per card), and a click that
|
|
539
|
-
// lands in that window must already have its listener.
|
|
475
|
+
const session = await window.tmct.open({});
|
|
476
|
+
window.tmct.news = { phase: "seeded" };
|
|
477
|
+
|
|
540
478
|
const startBtn = el("newsStart");
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
// the flag afterwards to decide whether to replay a returning visit's
|
|
544
|
-
// poll would poll a second time on top of the one already running.
|
|
545
|
-
const returningVisit = window.tmct.session.consented;
|
|
546
|
-
startBtn.textContent = returningVisit ? "poll now" : "start polling live sources";
|
|
547
|
-
|
|
548
|
-
el("feedSort").addEventListener("change", paintFeed);
|
|
549
|
-
|
|
550
|
-
// A poll can run for a while, so the button reads back its own state the
|
|
551
|
-
// moment it is pressed and the status line follows the session's phase
|
|
552
|
-
// until it settles.
|
|
479
|
+
startBtn.textContent = session.consented ? "poll now" : "start polling live sources";
|
|
480
|
+
|
|
553
481
|
function markBusy(button, label) {
|
|
554
482
|
button.dataset.idleLabel = button.textContent;
|
|
555
483
|
button.textContent = label;
|
|
@@ -561,133 +489,60 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
561
489
|
button.disabled = false;
|
|
562
490
|
button.removeAttribute("aria-busy");
|
|
563
491
|
}
|
|
564
|
-
// "stop polling" is live whenever there is something to stop: a press
|
|
565
|
-
// still in flight, a cycle running, or a timer armed for the next one.
|
|
566
|
-
// The press counter leads the session's own busy flag — a click must be
|
|
567
|
-
// able to stop the cycle it just started, from the same tick.
|
|
568
|
-
let pressesInFlight = 0;
|
|
569
|
-
function syncStopPolling() {
|
|
570
|
-
const session = window.tmct.session;
|
|
571
|
-
el("stopPolling").disabled = !(pressesInFlight > 0 || (session && (session.busy || session.nextPollAt)));
|
|
572
|
-
}
|
|
573
|
-
function followPhase(label) {
|
|
574
|
-
el("controlsStatus").textContent = label;
|
|
575
|
-
const id = setInterval(function () {
|
|
576
|
-
el("controlsStatus").textContent = window.tmct.session.phase + "…";
|
|
577
|
-
syncStopPolling();
|
|
578
|
-
}, 400);
|
|
579
|
-
return function () { clearInterval(id); el("controlsStatus").textContent = ""; syncStopPolling(); };
|
|
580
|
-
}
|
|
581
492
|
|
|
582
|
-
/** One press that
|
|
583
|
-
* status line
|
|
584
|
-
|
|
493
|
+
/** One press that talks to the service: the button reads back busy at
|
|
494
|
+
* once, the status line carries the outcome, and a network failure
|
|
495
|
+
* flips the page into the unavailable state rather than leaving the
|
|
496
|
+
* button stuck. */
|
|
497
|
+
async function runPress(button, busyLabel, idleLabelFn, work) {
|
|
585
498
|
markBusy(button, busyLabel);
|
|
586
|
-
|
|
587
|
-
syncStopPolling();
|
|
588
|
-
const stopFollowing = followPhase(busyLabel);
|
|
499
|
+
el("controlsStatus").textContent = busyLabel;
|
|
589
500
|
try {
|
|
590
|
-
await work();
|
|
501
|
+
const feed = await work();
|
|
502
|
+
setUnavailable(false);
|
|
503
|
+
renderAll(feed);
|
|
504
|
+
el("controlsStatus").textContent = "";
|
|
505
|
+
return feed;
|
|
506
|
+
} catch (err) {
|
|
507
|
+
el("controlsStatus").textContent = (err && err.message) ? err.message : String(err);
|
|
508
|
+
if (session.unavailable) setUnavailable(true);
|
|
509
|
+
throw err;
|
|
591
510
|
} finally {
|
|
592
|
-
|
|
593
|
-
stopFollowing();
|
|
594
|
-
markIdle(button, idleLabel);
|
|
595
|
-
syncStopPolling();
|
|
511
|
+
markIdle(button, idleLabelFn());
|
|
596
512
|
}
|
|
597
|
-
await renderAll();
|
|
598
513
|
}
|
|
599
514
|
|
|
600
515
|
startBtn.addEventListener("click", function () {
|
|
601
516
|
emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
el("pollOnce").addEventListener("click", function () {
|
|
606
|
-
emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
|
|
607
|
-
const pollOnceBtn = el("pollOnce");
|
|
608
|
-
return runFetchingPress(pollOnceBtn, "polling…", "poll once", function () { return window.tmct.session.pollOnce(); });
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
el("stopPolling").addEventListener("click", function () {
|
|
612
|
-
const result = window.tmct.session.stopPolling();
|
|
613
|
-
el("controlsStatus").textContent = result.wasRunning ? "stopping…" : "polling stopped";
|
|
614
|
-
appendLog(result.wasRunning
|
|
615
|
-
? "stopping — the running cycle finishes the article it is on and stops there"
|
|
616
|
-
: "polling stopped — no cycle was running, the next scheduled poll is cancelled");
|
|
617
|
-
syncStopPolling();
|
|
618
|
-
renderSourcesPanel();
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
// The button stays busy until the purge is finished on screen as well as
|
|
622
|
-
// in the store, so "enabled again" really does mean "the articles are
|
|
623
|
-
// gone" rather than "the store call returned".
|
|
624
|
-
el("stopForget").addEventListener("click", async function () {
|
|
625
|
-
const stopForgetBtn = el("stopForget");
|
|
626
|
-
markBusy(stopForgetBtn, "forgetting…");
|
|
627
|
-
try {
|
|
628
|
-
const result = await window.tmct.session.revokeConsent();
|
|
629
|
-
const removed = (result && result.factsRemoved) || 0;
|
|
630
|
-
startBtn.textContent = "start polling live sources";
|
|
631
|
-
feedItems = [];
|
|
632
|
-
cardsByItemId.clear();
|
|
633
|
-
activePillTerms.clear();
|
|
634
|
-
el("feed").querySelectorAll(".item").forEach(function (n) { n.remove(); });
|
|
635
|
-
emptyFeedText = "the articles are gone — press start or poll once to gather news again.";
|
|
636
|
-
renderPills();
|
|
637
|
-
paintFeed();
|
|
638
|
-
appendLog("stopped and forgot: " + removed + " fact(s) from news dropped, articles cleared, this page reads as first-visit next load");
|
|
639
|
-
await renderAll();
|
|
640
|
-
} finally {
|
|
641
|
-
markIdle(stopForgetBtn, "stop & forget");
|
|
642
|
-
syncStopPolling();
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
el("pollInterval").addEventListener("change", function (ev) {
|
|
647
|
-
const minutes = window.tmct.session.setInterval(Number(ev.target.value));
|
|
648
|
-
ev.target.value = String(minutes);
|
|
649
|
-
syncStopPolling();
|
|
517
|
+
const ids = [].slice.call(document.querySelectorAll("[data-source-toggle]:checked")).map(function (b) { return b.value; });
|
|
518
|
+
runPress(startBtn, "polling…", function () { return session.consented ? "poll now" : "start polling live sources"; }, function () { return session.start(ids); })
|
|
519
|
+
.catch(function () {});
|
|
650
520
|
});
|
|
651
521
|
|
|
652
522
|
el("enrichNow").addEventListener("click", function () {
|
|
653
|
-
|
|
654
|
-
|
|
523
|
+
runPress(el("enrichNow"), "enriching…", function () { return "enrich now"; }, function () { return session.enrich(); })
|
|
524
|
+
.catch(function () {});
|
|
655
525
|
});
|
|
656
526
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
527
|
+
el("stopForget").addEventListener("click", async function () {
|
|
528
|
+
const btn = el("stopForget");
|
|
529
|
+
markBusy(btn, "forgetting…");
|
|
530
|
+
el("controlsStatus").textContent = "forgetting…";
|
|
531
|
+
const result = await session.revokeConsent();
|
|
532
|
+
startBtn.textContent = "start polling live sources";
|
|
533
|
+
feedItems = [];
|
|
534
|
+
cardsByItemId.clear();
|
|
535
|
+
activePillTerms.clear();
|
|
536
|
+
emptyFeedText = "the articles are gone — press start to fetch news again.";
|
|
537
|
+
renderAll(EMPTY_FEED);
|
|
538
|
+
document.querySelectorAll("[data-source-status]").forEach(function (n) { n.textContent = "not yet polled"; });
|
|
539
|
+
appendLog(result.ok
|
|
540
|
+
? "stopped and forgot — this page reads as first-visit on the next load"
|
|
541
|
+
: "stopped and forgot locally; the server-side purge reported: " + result.error);
|
|
542
|
+
markIdle(btn, "stop & forget");
|
|
543
|
+
el("controlsStatus").textContent = "";
|
|
672
544
|
});
|
|
673
545
|
|
|
674
|
-
async function replayFrom(sourceId, fixtureKey) {
|
|
675
|
-
el("controlsStatus").textContent = "replaying…";
|
|
676
|
-
try {
|
|
677
|
-
const res = await fetch("./news-fixtures.json");
|
|
678
|
-
const bundle = res.ok ? await res.json() : null;
|
|
679
|
-
const fixture = bundle && bundle[fixtureKey];
|
|
680
|
-
if (!fixture) { el("controlsStatus").textContent = "fixture unavailable"; return; }
|
|
681
|
-
await window.tmct.session.replayFixture(sourceId, fixture);
|
|
682
|
-
el("controlsStatus").textContent = "replayed " + fixtureKey;
|
|
683
|
-
await renderAll();
|
|
684
|
-
} catch (err) {
|
|
685
|
-
el("controlsStatus").textContent = "fixture unavailable";
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
el("replayNyt").addEventListener("click", function () { replayFrom("nyt-world", "nyt-world"); });
|
|
689
|
-
el("replayWikipedia").addEventListener("click", function () { replayFrom("wikimedia-featured", "wikimedia-featured"); });
|
|
690
|
-
|
|
691
546
|
el("exampleProse").addEventListener("click", function () {
|
|
692
547
|
el("teachText").value = "A ceasefire is a formal agreement to stop fighting. A tariff is a tax on imported goods.";
|
|
693
548
|
});
|
|
@@ -703,26 +558,36 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
703
558
|
if (!file) return;
|
|
704
559
|
el("teachText").value = await file.text();
|
|
705
560
|
el("teachStatus").textContent = "loaded " + file.name + " — press ingest";
|
|
706
|
-
el("teachFile").dataset.name = file.name;
|
|
707
561
|
});
|
|
708
562
|
|
|
709
|
-
window.tmct.news.phase = "seeded";
|
|
710
|
-
appendLog("phase: seeded");
|
|
711
|
-
await renderAll();
|
|
712
|
-
syncStopPolling();
|
|
713
|
-
if (returningVisit) {
|
|
714
|
-
await window.tmct.session.start();
|
|
715
|
-
await renderAll();
|
|
716
|
-
syncStopPolling();
|
|
717
|
-
}
|
|
718
563
|
el("teachIngest").addEventListener("click", async function () {
|
|
719
564
|
const text = el("teachText").value;
|
|
720
565
|
if (!text.trim()) return;
|
|
721
|
-
const
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
566
|
+
const btn = el("teachIngest");
|
|
567
|
+
const graphSizeBefore = Number((el("tileGraphSize").querySelector("[data-value]") || {}).textContent) || 0;
|
|
568
|
+
await runPress(btn, "ingesting…", function () { return "ingest"; }, async function () {
|
|
569
|
+
const feed = looksLikeFactRows(text)
|
|
570
|
+
? await session.ingestRows(window.tmct.page.parseJsonlRows(text))
|
|
571
|
+
: await session.ingestText(text);
|
|
572
|
+
const added = Math.max(0, (feed.stats.graphSize || 0) - graphSizeBefore);
|
|
573
|
+
el("teachStatus").textContent = added + " fact(s) added to the graph";
|
|
574
|
+
return feed;
|
|
575
|
+
}).catch(function (err) { el("teachStatus").textContent = err.message || String(err); });
|
|
725
576
|
});
|
|
577
|
+
|
|
578
|
+
if (session.sessionKey) {
|
|
579
|
+
try {
|
|
580
|
+
const feed = await session.fetchFeed();
|
|
581
|
+
renderAll(feed);
|
|
582
|
+
appendLog("restored the session's last materialized feed");
|
|
583
|
+
} catch (err) {
|
|
584
|
+
setUnavailable(true);
|
|
585
|
+
appendLog("could not load the saved session: " + (err && err.message ? err.message : String(err)));
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
renderAll(EMPTY_FEED);
|
|
589
|
+
appendLog("ready — nothing has been requested yet");
|
|
590
|
+
}
|
|
726
591
|
}
|
|
727
592
|
|
|
728
593
|
boot().catch(function (err) { appendLog("boot failed: " + (err && err.message ? err.message : String(err))); });
|