oculon 0.0.0-stage → 0.1.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 -0
- package/README.md +344 -2
- package/dist/agent.d.ts +47 -0
- package/dist/agent.js +104 -0
- package/dist/cases.d.ts +68 -0
- package/dist/cases.js +158 -0
- package/dist/cli/main.d.ts +12 -0
- package/dist/cli/main.js +1999 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/core/context.d.ts +19 -0
- package/dist/core/context.js +19 -0
- package/dist/core/features.d.ts +22 -0
- package/dist/core/features.js +28 -0
- package/dist/core/graph.d.ts +38 -0
- package/dist/core/graph.js +81 -0
- package/dist/core/http.d.ts +42 -0
- package/dist/core/http.js +266 -0
- package/dist/core/keys.d.ts +8 -0
- package/dist/core/keys.js +22 -0
- package/dist/core/llm.d.ts +93 -0
- package/dist/core/llm.js +180 -0
- package/dist/core/merkle.d.ts +15 -0
- package/dist/core/merkle.js +46 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/png.d.ts +17 -0
- package/dist/core/png.js +101 -0
- package/dist/core/quota.d.ts +15 -0
- package/dist/core/quota.js +90 -0
- package/dist/core/stats.d.ts +24 -0
- package/dist/core/stats.js +67 -0
- package/dist/core/store.d.ts +20 -0
- package/dist/core/store.js +213 -0
- package/dist/core/text.d.ts +9 -0
- package/dist/core/text.js +30 -0
- package/dist/core/types.d.ts +38 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +495 -0
- package/dist/live.d.ts +53 -0
- package/dist/live.js +236 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +651 -0
- package/dist/modules/airport.d.ts +60 -0
- package/dist/modules/airport.js +111 -0
- package/dist/modules/audit.d.ts +73 -0
- package/dist/modules/audit.js +211 -0
- package/dist/modules/bgp.d.ts +147 -0
- package/dist/modules/bgp.js +206 -0
- package/dist/modules/blackout.d.ts +41 -0
- package/dist/modules/blackout.js +98 -0
- package/dist/modules/brief.d.ts +26 -0
- package/dist/modules/brief.js +99 -0
- package/dist/modules/calendar.d.ts +27 -0
- package/dist/modules/calendar.js +145 -0
- package/dist/modules/calibrate.d.ts +46 -0
- package/dist/modules/calibrate.js +92 -0
- package/dist/modules/cloud.d.ts +32 -0
- package/dist/modules/cloud.js +94 -0
- package/dist/modules/condor.d.ts +66 -0
- package/dist/modules/condor.js +214 -0
- package/dist/modules/connect.d.ts +47 -0
- package/dist/modules/connect.js +114 -0
- package/dist/modules/contradictions.d.ts +27 -0
- package/dist/modules/contradictions.js +76 -0
- package/dist/modules/country.d.ts +82 -0
- package/dist/modules/country.js +136 -0
- package/dist/modules/cricket.d.ts +34 -0
- package/dist/modules/cricket.js +166 -0
- package/dist/modules/darkships.d.ts +219 -0
- package/dist/modules/darkships.js +400 -0
- package/dist/modules/defi.d.ts +237 -0
- package/dist/modules/defi.js +512 -0
- package/dist/modules/emailsec.d.ts +47 -0
- package/dist/modules/emailsec.js +146 -0
- package/dist/modules/exposure.d.ts +43 -0
- package/dist/modules/exposure.js +89 -0
- package/dist/modules/factcheck.d.ts +39 -0
- package/dist/modules/factcheck.js +127 -0
- package/dist/modules/falcon.d.ts +58 -0
- package/dist/modules/falcon.js +219 -0
- package/dist/modules/feedback.d.ts +24 -0
- package/dist/modules/feedback.js +37 -0
- package/dist/modules/fence.d.ts +52 -0
- package/dist/modules/fence.js +128 -0
- package/dist/modules/ferret.d.ts +47 -0
- package/dist/modules/ferret.js +220 -0
- package/dist/modules/filings.d.ts +86 -0
- package/dist/modules/filings.js +166 -0
- package/dist/modules/fires.d.ts +56 -0
- package/dist/modules/fires.js +150 -0
- package/dist/modules/hazards.d.ts +37 -0
- package/dist/modules/hazards.js +83 -0
- package/dist/modules/health.d.ts +24 -0
- package/dist/modules/health.js +82 -0
- package/dist/modules/heron.d.ts +68 -0
- package/dist/modules/heron.js +184 -0
- package/dist/modules/hound.d.ts +100 -0
- package/dist/modules/hound.js +301 -0
- package/dist/modules/impact.d.ts +39 -0
- package/dist/modules/impact.js +63 -0
- package/dist/modules/launches.d.ts +24 -0
- package/dist/modules/launches.js +61 -0
- package/dist/modules/listen.d.ts +48 -0
- package/dist/modules/listen.js +125 -0
- package/dist/modules/lynx.d.ts +43 -0
- package/dist/modules/lynx.js +127 -0
- package/dist/modules/magpie.d.ts +70 -0
- package/dist/modules/magpie.js +174 -0
- package/dist/modules/meerkat.d.ts +42 -0
- package/dist/modules/meerkat.js +293 -0
- package/dist/modules/monitor.d.ts +27 -0
- package/dist/modules/monitor.js +105 -0
- package/dist/modules/narratives.d.ts +33 -0
- package/dist/modules/narratives.js +136 -0
- package/dist/modules/owl.d.ts +71 -0
- package/dist/modules/owl.js +290 -0
- package/dist/modules/papers.d.ts +46 -0
- package/dist/modules/papers.js +135 -0
- package/dist/modules/personal.d.ts +54 -0
- package/dist/modules/personal.js +153 -0
- package/dist/modules/pulse.d.ts +19 -0
- package/dist/modules/pulse.js +59 -0
- package/dist/modules/raven.d.ts +80 -0
- package/dist/modules/raven.js +147 -0
- package/dist/modules/recall.d.ts +44 -0
- package/dist/modules/recall.js +123 -0
- package/dist/modules/regs.d.ts +88 -0
- package/dist/modules/regs.js +142 -0
- package/dist/modules/rewind.d.ts +22 -0
- package/dist/modules/rewind.js +68 -0
- package/dist/modules/sanctions.d.ts +62 -0
- package/dist/modules/sanctions.js +173 -0
- package/dist/modules/scam.d.ts +43 -0
- package/dist/modules/scam.js +111 -0
- package/dist/modules/scoop.d.ts +31 -0
- package/dist/modules/scoop.js +74 -0
- package/dist/modules/ships.d.ts +33 -0
- package/dist/modules/ships.js +113 -0
- package/dist/modules/sky.d.ts +47 -0
- package/dist/modules/sky.js +183 -0
- package/dist/modules/squawk.d.ts +46 -0
- package/dist/modules/squawk.js +106 -0
- package/dist/modules/tortoise.d.ts +40 -0
- package/dist/modules/tortoise.js +104 -0
- package/dist/modules/travel.d.ts +94 -0
- package/dist/modules/travel.js +241 -0
- package/dist/modules/urlcheck.d.ts +63 -0
- package/dist/modules/urlcheck.js +223 -0
- package/dist/modules/vulns.d.ts +142 -0
- package/dist/modules/vulns.js +276 -0
- package/dist/plugins.d.ts +41 -0
- package/dist/plugins.js +70 -0
- package/dist/report.d.ts +12 -0
- package/dist/report.js +90 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.js +139 -0
- package/dist/sources/aircraft.d.ts +76 -0
- package/dist/sources/aircraft.js +107 -0
- package/dist/sources/airports.d.ts +28 -0
- package/dist/sources/airports.js +100 -0
- package/dist/sources/ais.d.ts +32 -0
- package/dist/sources/ais.js +111 -0
- package/dist/sources/apify.d.ts +28 -0
- package/dist/sources/apify.js +80 -0
- package/dist/sources/arxiv.d.ts +13 -0
- package/dist/sources/arxiv.js +27 -0
- package/dist/sources/certs.d.ts +12 -0
- package/dist/sources/certs.js +23 -0
- package/dist/sources/corp.d.ts +46 -0
- package/dist/sources/corp.js +60 -0
- package/dist/sources/earth.d.ts +39 -0
- package/dist/sources/earth.js +76 -0
- package/dist/sources/fda.d.ts +77 -0
- package/dist/sources/fda.js +121 -0
- package/dist/sources/finance.d.ts +181 -0
- package/dist/sources/finance.js +270 -0
- package/dist/sources/gdelt.d.ts +19 -0
- package/dist/sources/gdelt.js +33 -0
- package/dist/sources/github.d.ts +17 -0
- package/dist/sources/github.js +33 -0
- package/dist/sources/hackernews.d.ts +20 -0
- package/dist/sources/hackernews.js +37 -0
- package/dist/sources/labels.d.ts +21 -0
- package/dist/sources/labels.js +87 -0
- package/dist/sources/launch.d.ts +16 -0
- package/dist/sources/launch.js +41 -0
- package/dist/sources/ofac.d.ts +29 -0
- package/dist/sources/ofac.js +86 -0
- package/dist/sources/onchain.d.ts +77 -0
- package/dist/sources/onchain.js +189 -0
- package/dist/sources/opentimestamps.d.ts +44 -0
- package/dist/sources/opentimestamps.js +131 -0
- package/dist/sources/polymarket.d.ts +36 -0
- package/dist/sources/polymarket.js +70 -0
- package/dist/sources/predict.d.ts +18 -0
- package/dist/sources/predict.js +59 -0
- package/dist/sources/press.d.ts +30 -0
- package/dist/sources/press.js +111 -0
- package/dist/sources/resend.d.ts +14 -0
- package/dist/sources/resend.js +29 -0
- package/dist/sources/robinhood.d.ts +109 -0
- package/dist/sources/robinhood.js +129 -0
- package/dist/sources/sec.d.ts +67 -0
- package/dist/sources/sec.js +129 -0
- package/dist/sources/sentinel.d.ts +13 -0
- package/dist/sources/sentinel.js +63 -0
- package/dist/sources/signatures.d.ts +14 -0
- package/dist/sources/signatures.js +103 -0
- package/dist/sources/social.d.ts +22 -0
- package/dist/sources/social.js +56 -0
- package/dist/sources/space.d.ts +160 -0
- package/dist/sources/space.js +230 -0
- package/dist/sources/usgs.d.ts +17 -0
- package/dist/sources/usgs.js +24 -0
- package/dist/sources/wayback.d.ts +10 -0
- package/dist/sources/wayback.js +28 -0
- package/dist/sources/websec.d.ts +19 -0
- package/dist/sources/websec.js +40 -0
- package/dist/sources/wikidata.d.ts +11 -0
- package/dist/sources/wikidata.js +30 -0
- package/dist/sources/wikimedia.d.ts +28 -0
- package/dist/sources/wikimedia.js +52 -0
- package/dist/telegram.d.ts +104 -0
- package/dist/telegram.js +927 -0
- package/dist/web/assets/favicon-32.png +0 -0
- package/dist/web/assets/fx.js +178 -0
- package/dist/web/assets/icon-192.png +0 -0
- package/dist/web/assets/icon-512.png +0 -0
- package/dist/web/assets/icon-maskable-512.png +0 -0
- package/dist/web/assets/night-americas.jpg +0 -0
- package/dist/web/assets/night-emea.jpg +0 -0
- package/dist/web/assets/og.png +0 -0
- package/dist/web/assets/redsea-bm.jpg +0 -0
- package/dist/web/docs.html +263 -0
- package/dist/web/index.html +1828 -0
- package/dist/web/insights.d.ts +100 -0
- package/dist/web/insights.js +134 -0
- package/dist/web/landing.html +1143 -0
- package/dist/web/legal.html +176 -0
- package/dist/web/manifest.webmanifest +20 -0
- package/dist/web/mcp.html +104 -0
- package/dist/web/mcphttp.d.ts +10 -0
- package/dist/web/mcphttp.js +67 -0
- package/dist/web/openapi.d.ts +1 -0
- package/dist/web/openapi.js +51 -0
- package/dist/web/public.d.ts +45 -0
- package/dist/web/public.js +135 -0
- package/dist/web/server.d.ts +69 -0
- package/dist/web/server.js +750 -0
- package/dist/web/share.d.ts +35 -0
- package/dist/web/share.js +132 -0
- package/dist/web/sw.js +28 -0
- package/package.json +60 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only views over the local store for the web app: search, entity profiles, Robinhood Chain
|
|
3
|
+
* deployers, source health, accuracy and a signal timeline. Everything here reads data Oculon already
|
|
4
|
+
* collected; nothing calls an external API.
|
|
5
|
+
*/
|
|
6
|
+
import type { Oculon } from '../index.js';
|
|
7
|
+
/** Entities whose name or id contains the query, strongest-linked first. */
|
|
8
|
+
export declare function searchEntities(o: Oculon, q: string, limit?: number): {
|
|
9
|
+
id: string;
|
|
10
|
+
kind: string;
|
|
11
|
+
name: string;
|
|
12
|
+
links: number;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}[];
|
|
15
|
+
/** Everything stored about one entity: attributes, neighbors, signals that name it and recent observations. */
|
|
16
|
+
export declare function entityProfile(o: Oculon, id: string): {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
name: string;
|
|
20
|
+
attrs: Record<string, unknown>;
|
|
21
|
+
firstSeen: string;
|
|
22
|
+
lastSeen: string;
|
|
23
|
+
neighbors: import("../index.js").Neighbor[];
|
|
24
|
+
neighborKinds: Record<string, number>;
|
|
25
|
+
signals: {
|
|
26
|
+
id: string;
|
|
27
|
+
module: string;
|
|
28
|
+
title: string;
|
|
29
|
+
score: number;
|
|
30
|
+
evidence: {
|
|
31
|
+
source: string;
|
|
32
|
+
text: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
}[];
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}[];
|
|
37
|
+
observations: {
|
|
38
|
+
module: string;
|
|
39
|
+
kind: string;
|
|
40
|
+
value: number | null;
|
|
41
|
+
source: string;
|
|
42
|
+
at: string;
|
|
43
|
+
}[];
|
|
44
|
+
sources: string[];
|
|
45
|
+
} | null;
|
|
46
|
+
/** Robinhood Chain deployers Heron has profiled, most prolific first. */
|
|
47
|
+
export declare function rhDeployers(o: Oculon, limit?: number): {
|
|
48
|
+
address: string;
|
|
49
|
+
verdict: string;
|
|
50
|
+
tokens: number;
|
|
51
|
+
dead: number | null;
|
|
52
|
+
contracts: number | null;
|
|
53
|
+
checkedAt: string;
|
|
54
|
+
}[];
|
|
55
|
+
/** Which hosts answered recently (from the response cache), today's budget use, and which key groups are set. Key values are never returned. */
|
|
56
|
+
export declare function sourceHealth(o: Oculon): {
|
|
57
|
+
hosts: {
|
|
58
|
+
host: string;
|
|
59
|
+
cachedResponses: number;
|
|
60
|
+
lastFetch: string;
|
|
61
|
+
state: string;
|
|
62
|
+
}[];
|
|
63
|
+
quota: {
|
|
64
|
+
source: string;
|
|
65
|
+
used: number;
|
|
66
|
+
budget: number | null;
|
|
67
|
+
}[];
|
|
68
|
+
keys: {
|
|
69
|
+
group: string;
|
|
70
|
+
set: number;
|
|
71
|
+
total: number;
|
|
72
|
+
missing: string[];
|
|
73
|
+
}[];
|
|
74
|
+
};
|
|
75
|
+
/** First-to-know lead times, the radar calibration and the forecast scoreboard in one place. */
|
|
76
|
+
export declare function accuracy(o: Oculon): {
|
|
77
|
+
scoops: import("../modules/scoop.js").Scoreboard;
|
|
78
|
+
calibration: import("../modules/calibrate.js").Calibration | null;
|
|
79
|
+
forecasts: import("../index.js").Scoreboard;
|
|
80
|
+
};
|
|
81
|
+
/** Signals from the last `hours` hours, oldest first, for the timeline. */
|
|
82
|
+
export declare function timeline(o: Oculon, hours: number): {
|
|
83
|
+
id: string;
|
|
84
|
+
module: string;
|
|
85
|
+
title: string;
|
|
86
|
+
score: number;
|
|
87
|
+
entity: string | null;
|
|
88
|
+
at: string;
|
|
89
|
+
}[];
|
|
90
|
+
/** Signals stored after `sinceMs`, newest last (used by the live stream). */
|
|
91
|
+
export declare function signalsSince(o: Oculon, sinceMs: number): {
|
|
92
|
+
id: string;
|
|
93
|
+
module: string;
|
|
94
|
+
title: string;
|
|
95
|
+
score: number;
|
|
96
|
+
entity: string | null;
|
|
97
|
+
evidence: unknown[];
|
|
98
|
+
createdAt: string;
|
|
99
|
+
ts: number;
|
|
100
|
+
}[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { loadCalibration } from '../modules/calibrate.js';
|
|
2
|
+
import { isOnchainSource, onchainEnabled } from '../core/features.js';
|
|
3
|
+
const parse = (s) => {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(String(s ?? '{}'));
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/** Entities whose name or id contains the query, strongest-linked first. */
|
|
12
|
+
export function searchEntities(o, q, limit = 12) {
|
|
13
|
+
const db = o.ctx.store.db;
|
|
14
|
+
const like = `%${q.replace(/[%_]/g, '')}%`;
|
|
15
|
+
const rows = db
|
|
16
|
+
.prepare(`SELECT e.id, e.kind, e.name, e.updated_at,
|
|
17
|
+
(SELECT count(*) FROM edges x WHERE x.src = e.id OR x.dst = e.id) AS links
|
|
18
|
+
FROM entities e WHERE e.name LIKE ? OR e.id LIKE ?
|
|
19
|
+
ORDER BY (e.name = ?) DESC, links DESC, e.updated_at DESC LIMIT ?`)
|
|
20
|
+
.all(like, like, q, limit);
|
|
21
|
+
return rows.map((r) => ({ id: String(r.id), kind: String(r.kind), name: String(r.name), links: Number(r.links), updatedAt: new Date(Number(r.updated_at)).toISOString() }));
|
|
22
|
+
}
|
|
23
|
+
/** Everything stored about one entity: attributes, neighbors, signals that name it and recent observations. */
|
|
24
|
+
export function entityProfile(o, id) {
|
|
25
|
+
const db = o.ctx.store.db;
|
|
26
|
+
const e = db.prepare('SELECT * FROM entities WHERE id = ?').get(id);
|
|
27
|
+
if (!e)
|
|
28
|
+
return null;
|
|
29
|
+
const name = String(e.name);
|
|
30
|
+
const neighbors = o.ctx.graph.neighbors(id).slice(0, 80);
|
|
31
|
+
const byKind = {};
|
|
32
|
+
for (const n of neighbors)
|
|
33
|
+
byKind[n.kind] = (byKind[n.kind] ?? 0) + 1;
|
|
34
|
+
// Signals tied to the entity, plus signals whose title names it (short names only match whole titles loosely).
|
|
35
|
+
const needle = name.length >= 3 ? `%${name.replace(/[%_]/g, '')}%` : null;
|
|
36
|
+
const sigRows = db
|
|
37
|
+
.prepare(`SELECT * FROM signals WHERE entity_id = ? ${needle ? 'OR title LIKE ?' : ''} ORDER BY created_at DESC LIMIT 40`)
|
|
38
|
+
.all(...(needle ? [id, needle] : [id]));
|
|
39
|
+
const signals = sigRows.map((r) => ({ id: String(r.id), module: String(r.module), title: String(r.title), score: Number(r.score), evidence: JSON.parse(String(r.evidence)), createdAt: new Date(Number(r.created_at)).toISOString() }));
|
|
40
|
+
const observations = db.prepare('SELECT module, kind, value, source, observed_at FROM observations WHERE entity_id = ? ORDER BY observed_at DESC LIMIT 60').all(id).map((r) => ({
|
|
41
|
+
module: String(r.module),
|
|
42
|
+
kind: String(r.kind),
|
|
43
|
+
value: r.value === null ? null : Number(r.value),
|
|
44
|
+
source: String(r.source),
|
|
45
|
+
at: new Date(Number(r.observed_at)).toISOString(),
|
|
46
|
+
}));
|
|
47
|
+
const sources = [...new Set([...neighbors.map((n) => n.source), ...observations.map((x) => x.source), ...signals.flatMap((s) => s.evidence.map((ev) => ev.source))])].filter(Boolean);
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
kind: String(e.kind),
|
|
51
|
+
name,
|
|
52
|
+
attrs: parse(e.attrs),
|
|
53
|
+
firstSeen: new Date(Number(e.created_at)).toISOString(),
|
|
54
|
+
lastSeen: new Date(Number(e.updated_at)).toISOString(),
|
|
55
|
+
neighbors,
|
|
56
|
+
neighborKinds: byKind,
|
|
57
|
+
signals,
|
|
58
|
+
observations,
|
|
59
|
+
sources,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Robinhood Chain deployers Heron has profiled, most prolific first. */
|
|
63
|
+
export function rhDeployers(o, limit = 25) {
|
|
64
|
+
const rows = o.ctx.store.db.prepare("SELECT name, attrs, updated_at FROM entities WHERE kind = 'event' AND name LIKE 'deployer:%'").all();
|
|
65
|
+
return rows
|
|
66
|
+
.map((r) => {
|
|
67
|
+
const a = parse(r.attrs);
|
|
68
|
+
return { address: String(r.name).slice('deployer:'.length), verdict: a.verdict ?? 'UNKNOWN', tokens: a.tokens ?? 0, dead: typeof a.dead === 'number' ? a.dead : null, contracts: a.contracts ?? null, checkedAt: new Date(Number(r.updated_at)).toISOString() };
|
|
69
|
+
})
|
|
70
|
+
.filter((d) => d.tokens > 0 || d.verdict !== 'UNKNOWN')
|
|
71
|
+
.sort((x, y) => (y.dead ?? 0) - (x.dead ?? 0) || y.tokens - x.tokens)
|
|
72
|
+
.slice(0, limit);
|
|
73
|
+
}
|
|
74
|
+
const KEY_GROUPS = [
|
|
75
|
+
['LLM (ask, case, brief)', ['ANTHROPIC_API_KEY', 'GROQ_API_KEY', 'GEMINI_API_KEY', 'MISTRAL_API_KEY', 'NVIDIA_API_KEY', 'OPENROUTER_API_KEY']],
|
|
76
|
+
['Web search', ['TAVILY_API_KEY', 'EXA_API_KEY', 'JINA_API_KEY', 'FIRECRAWL_API_KEY']],
|
|
77
|
+
['News', ['GNEWS_API_KEY', 'GUARDIAN_API_KEY', 'NYT_API_KEY']],
|
|
78
|
+
['Markets', ['FINNHUB_API_KEY', 'FRED_API_KEY', 'COINGECKO_API_KEY']],
|
|
79
|
+
['On-chain', ['ZERION_API_KEY', 'ETHERSCAN_API_KEY', 'WEBACY_API_KEY', 'HELIUS_API_KEY', 'ROBINHOOD_PUBLIC_RPC_URL']],
|
|
80
|
+
['Routing and outages', ['CLOUDFLARE_API_TOKEN']],
|
|
81
|
+
['Satellites and fires', ['COPERNICUS_CLIENT_ID', 'FIRMS_MAP_KEY', 'NASA_API_KEY']],
|
|
82
|
+
['Ships', ['GFW_API_TOKEN', 'AISSTREAM_API_KEY']],
|
|
83
|
+
['Sanctions', ['OPENSANCTIONS_API_KEY']],
|
|
84
|
+
['Companies', ['ADZUNA_APP_KEY', 'COURTLISTENER_TOKEN', 'COMPANIES_HOUSE_API_KEY', 'BRANDFETCH_API_KEY']],
|
|
85
|
+
['Social and audio', ['APIFY_TOKEN', 'YOUTUBE_API_KEY', 'BLUESKY_APP_PASSWORD', 'DEEPGRAM_API_KEY']],
|
|
86
|
+
['Web security', ['URLSCAN_API_KEY', 'SAFE_BROWSING_KEY', 'ABUSECH_AUTH_KEY']],
|
|
87
|
+
['Fact checks', ['GOOGLE_API_KEY']],
|
|
88
|
+
['Telegram bot', ['TELEGRAM_BOT_TOKEN']],
|
|
89
|
+
];
|
|
90
|
+
/** Which hosts answered recently (from the response cache), today's budget use, and which key groups are set. Key values are never returned. */
|
|
91
|
+
export function sourceHealth(o) {
|
|
92
|
+
const db = o.ctx.store.db;
|
|
93
|
+
const rows = db.prepare("SELECT key, fetched_at FROM cache WHERE key LIKE 'http%'").all();
|
|
94
|
+
const hosts = new Map();
|
|
95
|
+
for (const r of rows) {
|
|
96
|
+
let host;
|
|
97
|
+
try {
|
|
98
|
+
host = new URL(r.key).hostname.replace(/^www\./, '');
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const h = hosts.get(host) ?? { host, responses: 0, last: 0 };
|
|
104
|
+
h.responses++;
|
|
105
|
+
h.last = Math.max(h.last, r.fetched_at);
|
|
106
|
+
hosts.set(host, h);
|
|
107
|
+
}
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
const list = [...hosts.values()]
|
|
110
|
+
.sort((a, b) => b.last - a.last)
|
|
111
|
+
.map((h) => ({ host: h.host, cachedResponses: h.responses, lastFetch: new Date(h.last).toISOString(), state: now - h.last < 3_600_000 ? 'fresh' : now - h.last < 86_400_000 ? 'today' : 'stale' }));
|
|
112
|
+
const on = onchainEnabled();
|
|
113
|
+
const keys = KEY_GROUPS.filter(([group]) => on || group !== 'On-chain').map(([group, names]) => {
|
|
114
|
+
const set = names.filter((n) => process.env[n]?.trim());
|
|
115
|
+
return { group, set: set.length, total: names.length, missing: names.filter((n) => !set.includes(n)) };
|
|
116
|
+
});
|
|
117
|
+
return { hosts: on ? list : list.filter((h) => !isOnchainSource(h.host)), quota: on ? o.quota() : o.quota().filter((q) => !isOnchainSource(q.source)), keys };
|
|
118
|
+
}
|
|
119
|
+
/** First-to-know lead times, the radar calibration and the forecast scoreboard in one place. */
|
|
120
|
+
export function accuracy(o) {
|
|
121
|
+
const cal = loadCalibration(o.ctx);
|
|
122
|
+
return { scoops: o.scoops(), calibration: cal, forecasts: o.scoreboard() };
|
|
123
|
+
}
|
|
124
|
+
/** Signals from the last `hours` hours, oldest first, for the timeline. */
|
|
125
|
+
export function timeline(o, hours) {
|
|
126
|
+
const since = Date.now() - hours * 3_600_000;
|
|
127
|
+
const rows = o.ctx.store.db.prepare('SELECT id, module, title, score, entity_id, created_at FROM signals WHERE created_at >= ? ORDER BY created_at ASC LIMIT 1500').all(since);
|
|
128
|
+
return rows.map((r) => ({ id: String(r.id), module: String(r.module), title: String(r.title), score: Number(r.score), entity: r.entity_id ? String(r.entity_id) : null, at: new Date(Number(r.created_at)).toISOString() }));
|
|
129
|
+
}
|
|
130
|
+
/** Signals stored after `sinceMs`, newest last (used by the live stream). */
|
|
131
|
+
export function signalsSince(o, sinceMs) {
|
|
132
|
+
const rows = o.ctx.store.db.prepare('SELECT * FROM signals WHERE created_at > ? ORDER BY created_at ASC LIMIT 50').all(sinceMs);
|
|
133
|
+
return rows.map((r) => ({ id: String(r.id), module: String(r.module), title: String(r.title), score: Number(r.score), entity: r.entity_id ? String(r.entity_id) : null, evidence: JSON.parse(String(r.evidence)), createdAt: new Date(Number(r.created_at)).toISOString(), ts: Number(r.created_at) }));
|
|
134
|
+
}
|