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,41 @@
|
|
|
1
|
+
import type { Evidence, Sourced } from './core/types.js';
|
|
2
|
+
import type { Oculon } from './index.js';
|
|
3
|
+
export interface PluginApi {
|
|
4
|
+
get: <T = unknown>(url: string, opts?: {
|
|
5
|
+
ttlSec?: number;
|
|
6
|
+
as?: 'json' | 'text';
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}) => Promise<Sourced<T>>;
|
|
9
|
+
signal: (s: {
|
|
10
|
+
title: string;
|
|
11
|
+
score: number;
|
|
12
|
+
evidence?: Evidence[];
|
|
13
|
+
key?: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
graph: {
|
|
16
|
+
upsert: (kind: 'topic' | 'org' | 'domain' | 'event', name: string, attrs?: Record<string, unknown>) => string;
|
|
17
|
+
link: (a: string, b: string, rel: string) => void;
|
|
18
|
+
};
|
|
19
|
+
now: () => Date;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginTool {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
inputSchema?: Record<string, unknown>;
|
|
25
|
+
run: (api: PluginApi, args: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface Plugin {
|
|
28
|
+
name: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
tools: PluginTool[];
|
|
32
|
+
file: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function pluginDir(): string;
|
|
35
|
+
/** Load every valid plugin; invalid ones are reported, never fatal. */
|
|
36
|
+
export declare function loadPlugins(dir?: string): Promise<{
|
|
37
|
+
plugins: Plugin[];
|
|
38
|
+
errors: string[];
|
|
39
|
+
}>;
|
|
40
|
+
export declare function pluginApi(o: Oculon, plugin: string): PluginApi;
|
|
41
|
+
export declare function runPluginTool(o: Oculon, ref: string, args?: Record<string, unknown>): Promise<unknown>;
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugins: drop a .mjs file into ~/.oculon/plugins (or OCULON_PLUGINS) to add tools. Each plugin's tools become
|
|
3
|
+
* CLI commands (`oculon plugin run name.tool`) and MCP tools (`plugin_name_tool`).
|
|
4
|
+
*
|
|
5
|
+
* export default {
|
|
6
|
+
* name: 'hn-show',
|
|
7
|
+
* description: 'Show HN tracker',
|
|
8
|
+
* tools: [{ name: 'top', description: '...', inputSchema: { type: 'object', properties: {} }, run: async (api, args) => ... }],
|
|
9
|
+
* };
|
|
10
|
+
*
|
|
11
|
+
* `api` gives cached, rate-limited, quota-counted HTTP (`api.get`), signal saving (`api.signal`), the entity graph
|
|
12
|
+
* (`api.graph.upsert/link`) and `api.now()`. Plugins run with full Node permissions: install only code you trust.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { pathToFileURL } from 'node:url';
|
|
17
|
+
import { oculonHome } from './core/paths.js';
|
|
18
|
+
import { signalId } from './core/text.js';
|
|
19
|
+
export function pluginDir() {
|
|
20
|
+
return process.env.OCULON_PLUGINS || join(oculonHome(), 'plugins');
|
|
21
|
+
}
|
|
22
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,40}$/;
|
|
23
|
+
/** Load every valid plugin; invalid ones are reported, never fatal. */
|
|
24
|
+
export async function loadPlugins(dir = pluginDir()) {
|
|
25
|
+
const plugins = [];
|
|
26
|
+
const errors = [];
|
|
27
|
+
if (!existsSync(dir))
|
|
28
|
+
return { plugins, errors };
|
|
29
|
+
for (const f of readdirSync(dir).filter((x) => x.endsWith('.mjs') || x.endsWith('.js')).sort()) {
|
|
30
|
+
const file = join(dir, f);
|
|
31
|
+
try {
|
|
32
|
+
const mod = (await import(pathToFileURL(file).href));
|
|
33
|
+
const p = mod.default;
|
|
34
|
+
if (!p || !NAME.test(p.name ?? '') || !Array.isArray(p.tools))
|
|
35
|
+
throw new Error('default export needs { name (a-z0-9-), tools: [] }');
|
|
36
|
+
const tools = p.tools.filter((t) => NAME.test(t?.name ?? '') && typeof t.run === 'function' && typeof t.description === 'string');
|
|
37
|
+
if (plugins.some((x) => x.name === p.name))
|
|
38
|
+
throw new Error(`duplicate plugin name ${p.name}`);
|
|
39
|
+
plugins.push({ ...p, tools, file });
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
errors.push(`${f}: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { plugins, errors };
|
|
46
|
+
}
|
|
47
|
+
export function pluginApi(o, plugin) {
|
|
48
|
+
return {
|
|
49
|
+
get: (url, opts = {}) => o.ctx.http.get(url, { source: `plugin:${plugin}`, ttlSec: opts.ttlSec ?? 600, ...(opts.as ? { as: opts.as } : {}), ...(opts.headers ? { headers: opts.headers } : {}) }),
|
|
50
|
+
signal: (s) => o.ctx.graph.saveSignal({
|
|
51
|
+
id: signalId(`plugin-${plugin}`, s.key ?? s.title),
|
|
52
|
+
module: `plugin:${plugin}`,
|
|
53
|
+
title: String(s.title).slice(0, 200),
|
|
54
|
+
score: Math.max(0, Math.min(100, Number(s.score) || 0)),
|
|
55
|
+
evidence: (s.evidence ?? []).slice(0, 10),
|
|
56
|
+
createdAt: o.ctx.now().toISOString(),
|
|
57
|
+
}),
|
|
58
|
+
graph: { upsert: (kind, name, attrs) => o.ctx.graph.upsert(kind, name, attrs), link: (a, b, rel) => o.ctx.graph.link(a, b, rel, `plugin:${plugin}`) },
|
|
59
|
+
now: () => o.ctx.now(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function runPluginTool(o, ref, args = {}) {
|
|
63
|
+
const [pname, tname] = ref.split('.');
|
|
64
|
+
const { plugins } = await loadPlugins();
|
|
65
|
+
const p = plugins.find((x) => x.name === pname);
|
|
66
|
+
const t = p?.tools.find((x) => x.name === tname);
|
|
67
|
+
if (!p || !t)
|
|
68
|
+
throw new Error(`no plugin tool ${ref}; see \`oculon plugin list\``);
|
|
69
|
+
return t.run(pluginApi(o, p.name), args);
|
|
70
|
+
}
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Signal } from './core/types.js';
|
|
2
|
+
import type { Oculon } from './index.js';
|
|
3
|
+
/** One line per story: titles that differ only in their numbers ("+1663%" vs "+1851%") collapse to the strongest. */
|
|
4
|
+
export declare function dedupeSignals(signals: Signal[]): Signal[];
|
|
5
|
+
export declare function buildReport(o: Oculon, opts?: {
|
|
6
|
+
days?: number;
|
|
7
|
+
out?: string;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
file: string;
|
|
10
|
+
html: string;
|
|
11
|
+
counts: Record<string, number>;
|
|
12
|
+
}>;
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weekly report: a single self-contained HTML file summarizing what Oculon saw over N days: top signals,
|
|
3
|
+
* narratives, case files, watchlist and fence changes, scoops, market disagreements, sanctions hits, company
|
|
4
|
+
* health and calibration. Written locally; nothing is uploaded.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { oculonHome } from './core/paths.js';
|
|
9
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
10
|
+
const safeUrl = (u) => (u && /^https?:\/\//.test(u) ? esc(u) : '');
|
|
11
|
+
/** One line per story: titles that differ only in their numbers ("+1663%" vs "+1851%") collapse to the strongest. */
|
|
12
|
+
export function dedupeSignals(signals) {
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
return signals.filter((s) => {
|
|
15
|
+
const k = `${s.module}|${s.title.replace(/[+\-~]?\d[\d,.]*\s*%?/g, '#').toLowerCase()}`;
|
|
16
|
+
if (seen.has(k))
|
|
17
|
+
return false;
|
|
18
|
+
seen.add(k);
|
|
19
|
+
return true;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function signalList(input, max = 15) {
|
|
23
|
+
const signals = dedupeSignals(input);
|
|
24
|
+
if (!signals.length)
|
|
25
|
+
return '<p class="muted">Nothing in this period.</p>';
|
|
26
|
+
return `<ul>${signals
|
|
27
|
+
.slice(0, max)
|
|
28
|
+
.map((s) => {
|
|
29
|
+
const link = s.evidence.find((e) => e.url)?.url;
|
|
30
|
+
return `<li><span class="score">${Math.round(s.score)}</span> ${esc(s.title)} <span class="muted">${esc(s.module)} · ${esc(s.createdAt.slice(0, 10))}</span>${link ? ` <a href="${safeUrl(link)}">source</a>` : ''}</li>`;
|
|
31
|
+
})
|
|
32
|
+
.join('')}</ul>`;
|
|
33
|
+
}
|
|
34
|
+
export async function buildReport(o, opts = {}) {
|
|
35
|
+
const days = opts.days ?? 7;
|
|
36
|
+
const nowMs = o.ctx.now().getTime();
|
|
37
|
+
const since = nowMs - days * 86_400_000;
|
|
38
|
+
const all = o.ctx.graph.recentSignals(5000).filter((s) => Date.parse(s.createdAt) >= since);
|
|
39
|
+
const by = (m) => all.filter((s) => (Array.isArray(m) ? m.includes(s.module) : s.module === m)).sort((a, b) => b.score - a.score);
|
|
40
|
+
const top = [...all].filter((s) => !['meerkat', 'fence'].includes(s.module)).sort((a, b) => b.score - a.score);
|
|
41
|
+
const { listNarratives } = await import('./modules/narratives.js');
|
|
42
|
+
const narratives = listNarratives(o.ctx, days);
|
|
43
|
+
const cases = (await o.caseList()).filter((k) => Date.parse(k.updatedAt) >= since);
|
|
44
|
+
const scoops = o.scoops();
|
|
45
|
+
const { loadCalibration } = await import('./modules/calibrate.js');
|
|
46
|
+
const cal = loadCalibration(o.ctx);
|
|
47
|
+
const healthRows = o.ctx.store.db.prepare('SELECT company, day, score FROM health WHERE day >= ? ORDER BY day DESC').all(new Date(since).toISOString().slice(0, 10));
|
|
48
|
+
const latestHealth = [...new Map(healthRows.map((h) => [h.company, h])).values()];
|
|
49
|
+
const forecasts = o.scoreboard();
|
|
50
|
+
const from = new Date(since).toISOString().slice(0, 10);
|
|
51
|
+
const to = new Date(nowMs).toISOString().slice(0, 10);
|
|
52
|
+
const section = (title, body) => `<section><h2>${esc(title)}</h2>${body}</section>`;
|
|
53
|
+
const html = `<!doctype html>
|
|
54
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
55
|
+
<title>Oculon report ${esc(from)} to ${esc(to)}</title>
|
|
56
|
+
<style>
|
|
57
|
+
:root{--bg:#0b0e13;--panel:#12161d;--line:#232a35;--text:#e6e9ef;--muted:#8a94a6;--accent:#6ee7b7;--link:#60a5fa}
|
|
58
|
+
@media (prefers-color-scheme: light){:root{--bg:#f5f6f8;--panel:#fff;--line:#dfe3ea;--text:#151a22;--muted:#5d6778;--accent:#059669;--link:#2563eb}}
|
|
59
|
+
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
60
|
+
main{max-width:920px;margin:0 auto;padding:24px 16px 48px}
|
|
61
|
+
h1{font-size:22px;margin:0 0 4px} h1 span{color:var(--accent)}
|
|
62
|
+
h2{font-size:13px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);margin:0 0 10px}
|
|
63
|
+
section{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:14px 18px;margin-top:16px}
|
|
64
|
+
ul{margin:0;padding-left:18px} li{margin:4px 0}
|
|
65
|
+
a{color:var(--link);text-decoration:none} .muted{color:var(--muted);font-size:13px}
|
|
66
|
+
.score{display:inline-block;min-width:26px;font:600 12px ui-monospace,Consolas,monospace;color:var(--accent)}
|
|
67
|
+
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:10px}
|
|
68
|
+
.kpi{border:1px solid var(--line);border-radius:8px;padding:8px 10px} .kpi b{display:block;font:700 20px ui-monospace,Consolas,monospace}
|
|
69
|
+
</style></head><body><main>
|
|
70
|
+
<h1>OCU<span>LON</span> report</h1>
|
|
71
|
+
<p class="muted">${esc(from)} to ${esc(to)} · ${all.length} signals · generated ${esc(new Date(nowMs).toISOString().slice(0, 16).replace('T', ' '))} UTC</p>
|
|
72
|
+
${section('At a glance', `<div class="kpis"><div class="kpi"><b>${all.length}</b>signals</div><div class="kpi"><b>${narratives.length}</b>active narratives</div><div class="kpi"><b>${cases.length}</b>case files updated</div><div class="kpi"><b>${by('meerkat').length + by('fence').length}</b>watch & fence changes</div><div class="kpi"><b>${scoops.oculonFirst}/${scoops.covered}</b>times ahead of media</div><div class="kpi"><b>${forecasts.resolved}</b>forecasts resolved</div></div>`)}
|
|
73
|
+
${section('Top signals', signalList(top, 20))}
|
|
74
|
+
${section('Narratives', narratives.length ? `<ul>${narratives.slice(0, 12).map((n) => `<li><b>${esc(n.name)}</b> <span class="muted">${n.total} stories · ${esc(n.phase.toLowerCase())}</span>${n.latest[0]?.url?.startsWith('http') ? ` <a href="${safeUrl(n.latest[0].url)}">latest</a>` : ''}</li>`).join('')}</ul>` : '<p class="muted">No narratives tracked in this period.</p>')}
|
|
75
|
+
${section('Case files', cases.length ? `<ul>${cases.map((k) => `<li><b>#${k.id} ${esc(k.question)}</b><br>${esc(k.report?.answer ?? '')} <span class="muted">(${esc(k.report?.confidence ?? '-')} confidence, ${k.report?.findings.length ?? 0} findings)</span></li>`).join('')}</ul>` : '<p class="muted">No case files updated.</p>')}
|
|
76
|
+
${section('Watchlist and fence changes', signalList([...by('meerkat'), ...by('fence')].sort((a, b) => b.createdAt.localeCompare(a.createdAt)), 25))}
|
|
77
|
+
${section('Sanctions', signalList(by('sanctions')))}
|
|
78
|
+
${section('Robinhood Chain', signalList(by('heron')))}
|
|
79
|
+
${section('Markets and launches', signalList([...by('lynx'), ...by('launch')]))}
|
|
80
|
+
${section('Company health', latestHealth.length ? `<ul>${latestHealth.map((h) => `<li><b>${esc(h.company)}</b> ${h.score}/100 <span class="muted">${esc(h.day)}</span></li>`).join('')}</ul>` : '<p class="muted">No company scored yet (oculon health <company>).</p>')}
|
|
81
|
+
${section('First to know', `<p>${scoops.checked} signals checked against Guardian, NYT and GNews: Oculon first ${scoops.oculonFirst}, media first ${scoops.mediaFirst}${scoops.medianLeadHours !== null ? `, median lead ${scoops.medianLeadHours}h` : ''}.</p>`)}
|
|
82
|
+
${section('Calibration', cal ? `<p>${cal.samples} replayed radar items over ${cal.days} days; ${cal.materialized} became news within 3 days. Signal threshold: ${cal.best?.threshold ?? 55}${cal.best?.precision != null ? ` (precision ${cal.best.precision}, recall ${cal.best.recall})` : ''}.</p>` : '<p class="muted">Not calibrated yet (oculon calibrate).</p>')}
|
|
83
|
+
<p class="muted">Every item links to its source. Signals are generated automatically from public data; verify before acting on them.</p>
|
|
84
|
+
</main></body></html>`;
|
|
85
|
+
const dir = join(oculonHome(), 'reports');
|
|
86
|
+
mkdirSync(dir, { recursive: true });
|
|
87
|
+
const file = opts.out ?? join(dir, `oculon-report-${to}.html`);
|
|
88
|
+
writeFileSync(file, html);
|
|
89
|
+
return { file, html, counts: { signals: all.length, narratives: narratives.length, cases: cases.length } };
|
|
90
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Signal } from './core/types.js';
|
|
2
|
+
import type { Oculon } from './index.js';
|
|
3
|
+
import { type Delivery } from './modules/personal.js';
|
|
4
|
+
export interface SchedulerOptions {
|
|
5
|
+
scanMinutes?: number;
|
|
6
|
+
watchMinutes?: number;
|
|
7
|
+
briefHour?: number;
|
|
8
|
+
log?: (m: string) => void;
|
|
9
|
+
onSignals?: (signals: Signal[]) => Promise<void> | void;
|
|
10
|
+
onBrief?: (markdown: string) => Promise<void> | void;
|
|
11
|
+
onReport?: (file: string) => Promise<void> | void;
|
|
12
|
+
/** Public address of the install, for links in emails (e.g. https://oculon.live). */
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** Where people manage their monitors (e.g. https://app.oculon.live/#watch). */
|
|
15
|
+
appUrl?: string;
|
|
16
|
+
/** Changes found by personal monitors; emails go out here, Telegram chats through this hook. */
|
|
17
|
+
onPersonal?: (deliveries: Delivery[]) => Promise<void> | void;
|
|
18
|
+
}
|
|
19
|
+
export declare function startScheduler(o: Oculon, opts?: SchedulerOptions): {
|
|
20
|
+
stop: () => void;
|
|
21
|
+
tick: () => Promise<void>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background schedule shared by the dashboard (`oculon serve --watch`) and the Telegram bot.
|
|
3
|
+
* Intervals are chosen to stay inside free-tier quotas; every task is isolated so one failure
|
|
4
|
+
* never stops the others.
|
|
5
|
+
*
|
|
6
|
+
* every scan interval (default 15 min): radar, military air, natural events, space weather, Robinhood Chain
|
|
7
|
+
* every 60 min: watchlist re-check (reports changes only)
|
|
8
|
+
* every 6 h: resolve forecasts whose markets settled
|
|
9
|
+
* once a day: automatic forecasts + Bitcoin timestamp of new forecasts; daily brief from 07:00 local time
|
|
10
|
+
*/
|
|
11
|
+
import { onchainEnabled } from './core/features.js';
|
|
12
|
+
import { emailDeliveries, runPersonal } from './modules/personal.js';
|
|
13
|
+
const MIN = 60_000;
|
|
14
|
+
export function startScheduler(o, opts = {}) {
|
|
15
|
+
const log = opts.log ?? (() => { });
|
|
16
|
+
const scanMs = (opts.scanMinutes ?? 15) * MIN;
|
|
17
|
+
const watchMs = (opts.watchMinutes ?? 60) * MIN;
|
|
18
|
+
const last = {};
|
|
19
|
+
let running = false;
|
|
20
|
+
const due = (name, every) => Date.now() - (last[name] ?? 0) >= every;
|
|
21
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
22
|
+
const doneToday = (name) => o.ctx.store.db.prepare('SELECT 1 FROM scheduler_runs WHERE name = ? AND day = ?').get(name, today()) !== undefined;
|
|
23
|
+
const markToday = (name) => o.ctx.store.db.prepare('INSERT OR REPLACE INTO scheduler_runs (name, day, ran_at) VALUES (?, ?, ?)').run(name, today(), Date.now());
|
|
24
|
+
async function task(name, fn) {
|
|
25
|
+
const t0 = Date.now();
|
|
26
|
+
try {
|
|
27
|
+
const signals = (await fn()) ?? [];
|
|
28
|
+
last[name] = Date.now();
|
|
29
|
+
log(`${name}: ${signals.length} signal(s) in ${((Date.now() - t0) / 1000).toFixed(0)}s`);
|
|
30
|
+
if (signals.length && opts.onSignals)
|
|
31
|
+
await opts.onSignals(signals);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
last[name] = Date.now();
|
|
35
|
+
log(`${name} failed: ${e.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function tick() {
|
|
39
|
+
if (running)
|
|
40
|
+
return;
|
|
41
|
+
running = true;
|
|
42
|
+
try {
|
|
43
|
+
if (due('scan', scanMs)) {
|
|
44
|
+
await task('radar', async () => (await o.radar()).signals);
|
|
45
|
+
await task('military', async () => (await o.military()).signals);
|
|
46
|
+
await task('events', async () => (await o.naturalEvents()).signals);
|
|
47
|
+
// NASA DONKI and NeoWs change slowly: include them every 3 hours, NOAA every scan.
|
|
48
|
+
const nasa = due('space-nasa', 3 * 60 * MIN);
|
|
49
|
+
await task('space', async () => (await o.spaceWeather(7, { nasa })).signals);
|
|
50
|
+
if (nasa)
|
|
51
|
+
last['space-nasa'] = Date.now();
|
|
52
|
+
await task('squawk', async () => (await o.squawks()).signals);
|
|
53
|
+
if (onchainEnabled())
|
|
54
|
+
await task('robinhood', async () => (await o.robinhood()).signals);
|
|
55
|
+
if (o.fenceList().length)
|
|
56
|
+
await task('fences', async () => (await o.fenceCheck()).signals);
|
|
57
|
+
await task('impact', async () => (await o.impact()).signals);
|
|
58
|
+
await task('blackout', async () => (await o.blackout(2)).signals);
|
|
59
|
+
await task('hazards', async () => (await o.hazards(7)).signals);
|
|
60
|
+
await task('cloud', async () => (await o.cloud()).signals);
|
|
61
|
+
last.scan = Date.now();
|
|
62
|
+
}
|
|
63
|
+
if (due('watch', watchMs) && o.watchList().length)
|
|
64
|
+
await task('watch', async () => (await o.watchRun()).signals);
|
|
65
|
+
// Personal monitors: each is re-checked about hourly; this pass picks up the ones that are due.
|
|
66
|
+
if (due('personal', 15 * MIN)) {
|
|
67
|
+
await task('personal', async () => {
|
|
68
|
+
const d = await runPersonal(o.ctx);
|
|
69
|
+
if (!d.length)
|
|
70
|
+
return;
|
|
71
|
+
const mailed = await emailDeliveries(o.ctx, d, opts.baseUrl ?? 'http://127.0.0.1:4747', opts.appUrl ?? 'http://127.0.0.1:4747/app#watch');
|
|
72
|
+
if (opts.onPersonal)
|
|
73
|
+
await opts.onPersonal(d);
|
|
74
|
+
log(`personal: ${d.length} monitor(s) changed, ${mailed} email(s) sent`);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (due('resolve', 6 * 60 * MIN))
|
|
78
|
+
await task('resolve', async () => void (await o.resolveForecasts()));
|
|
79
|
+
if (due('scoops', 6 * 60 * MIN))
|
|
80
|
+
await task('scoops', async () => void (await o.scoopsCheck(6)));
|
|
81
|
+
if (due('markets', 6 * 60 * MIN))
|
|
82
|
+
await task('markets', async () => (await o.markets()).signals);
|
|
83
|
+
if (due('bgp', 60 * MIN))
|
|
84
|
+
await task('bgp', async () => (await o.bgp('world')).signals);
|
|
85
|
+
if (onchainEnabled() && due('defi', 60 * MIN))
|
|
86
|
+
await task('defi', async () => (await o.defi()).signals);
|
|
87
|
+
if (due('vulns', 6 * 60 * MIN))
|
|
88
|
+
await task('vulns', async () => (await o.vulns({ days: 2 })).signals);
|
|
89
|
+
if (due('regs', 6 * 60 * MIN))
|
|
90
|
+
await task('regs', async () => (await o.regs({ days: 2 })).signals);
|
|
91
|
+
if (!doneToday('forecast')) {
|
|
92
|
+
await task('auto-forecast', async () => void (await o.autoForecast()));
|
|
93
|
+
await task('stamp', async () => void (await o.stampProofs()));
|
|
94
|
+
markToday('forecast');
|
|
95
|
+
}
|
|
96
|
+
if (due('narratives', 6 * 60 * MIN))
|
|
97
|
+
await task('narratives', async () => (await o.narrativesRun()).signals);
|
|
98
|
+
if (!doneToday('health')) {
|
|
99
|
+
for (const w of o.watchList().filter((x) => x.kind === 'company').slice(0, 5))
|
|
100
|
+
await task(`health ${w.target}`, async () => (await o.health(w.target)).signals.filter((s) => s.module === 'health'));
|
|
101
|
+
markToday('health');
|
|
102
|
+
}
|
|
103
|
+
// Weekly report on Mondays, sent to Telegram when the bot runs.
|
|
104
|
+
if (new Date().getDay() === 1 && new Date().getHours() >= (opts.briefHour ?? 7) && !doneToday('report')) {
|
|
105
|
+
await task('report', async () => {
|
|
106
|
+
const r = await o.report(7);
|
|
107
|
+
if (opts.onReport)
|
|
108
|
+
await opts.onReport(r.file);
|
|
109
|
+
});
|
|
110
|
+
markToday('report');
|
|
111
|
+
}
|
|
112
|
+
if (!doneToday('prune')) {
|
|
113
|
+
await task('prune cache', async () => void o.ctx.store.pruneCache(14));
|
|
114
|
+
markToday('prune');
|
|
115
|
+
}
|
|
116
|
+
if (!doneToday('cases')) {
|
|
117
|
+
// Watched cases: at most three per day, they are the most quota-hungry task.
|
|
118
|
+
const watched = (await o.caseList()).filter((k) => k.watch).slice(0, 3);
|
|
119
|
+
for (const k of watched)
|
|
120
|
+
await task(`case #${k.id}`, async () => (await o.caseInvestigate({ id: k.id })).signals);
|
|
121
|
+
markToday('cases');
|
|
122
|
+
}
|
|
123
|
+
if (new Date().getHours() >= (opts.briefHour ?? 7) && !doneToday('brief')) {
|
|
124
|
+
await task('brief', async () => {
|
|
125
|
+
const b = await o.brief({ refresh: true });
|
|
126
|
+
if (opts.onBrief)
|
|
127
|
+
await opts.onBrief(b.markdown);
|
|
128
|
+
});
|
|
129
|
+
markToday('brief');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
running = false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
void tick();
|
|
137
|
+
const timer = setInterval(() => void tick(), MIN);
|
|
138
|
+
return { stop: () => clearInterval(timer), tick };
|
|
139
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type Ctx } from '../core/context.js';
|
|
2
|
+
import type { Sourced } from '../core/types.js';
|
|
3
|
+
/** Live state of one aircraft, normalized across ADS-B providers. Altitudes in feet, speed in knots. */
|
|
4
|
+
export interface AircraftState {
|
|
5
|
+
hex: string;
|
|
6
|
+
registration: string | null;
|
|
7
|
+
type: string | null;
|
|
8
|
+
callsign: string | null;
|
|
9
|
+
lat: number | null;
|
|
10
|
+
lon: number | null;
|
|
11
|
+
altFt: number | null;
|
|
12
|
+
onGround: boolean;
|
|
13
|
+
speedKt: number | null;
|
|
14
|
+
track: number | null;
|
|
15
|
+
squawk: string | null;
|
|
16
|
+
/** Seconds since the last message. */
|
|
17
|
+
seenSec: number | null;
|
|
18
|
+
source: 'adsb.lol' | 'opensky';
|
|
19
|
+
/** adsb.lol `emergency` field as the transponder reports it: none, general, lifeguard, minfuel, nordo, unlawful, downed. */
|
|
20
|
+
emergency?: string | null;
|
|
21
|
+
/** adsb.lol database flags: 1 military, 2 interesting, 4 PIA (privacy ICAO address), 8 LADD (FAA limited display). */
|
|
22
|
+
dbFlags?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface AircraftInfo {
|
|
25
|
+
hex: string;
|
|
26
|
+
registration: string | null;
|
|
27
|
+
manufacturer: string | null;
|
|
28
|
+
type: string | null;
|
|
29
|
+
typeCode: string | null;
|
|
30
|
+
owner: string | null;
|
|
31
|
+
}
|
|
32
|
+
interface AdsbLolAc {
|
|
33
|
+
hex: string;
|
|
34
|
+
r?: string;
|
|
35
|
+
t?: string;
|
|
36
|
+
flight?: string;
|
|
37
|
+
lat?: number;
|
|
38
|
+
lon?: number;
|
|
39
|
+
alt_baro?: number | 'ground';
|
|
40
|
+
gs?: number;
|
|
41
|
+
track?: number;
|
|
42
|
+
squawk?: string;
|
|
43
|
+
seen?: number;
|
|
44
|
+
seen_pos?: number;
|
|
45
|
+
desc?: string;
|
|
46
|
+
ownOp?: string;
|
|
47
|
+
emergency?: string;
|
|
48
|
+
dbFlags?: number;
|
|
49
|
+
}
|
|
50
|
+
export declare function fromAdsbLol(a: AdsbLolAc): AircraftState;
|
|
51
|
+
export declare const byHex: (ctx: Ctx, hex: string) => Promise<Sourced<AircraftState[]>>;
|
|
52
|
+
export declare const byRegistration: (ctx: Ctx, reg: string) => Promise<Sourced<AircraftState[]>>;
|
|
53
|
+
/** Aircraft flagged as military in the adsb.lol database, worldwide. */
|
|
54
|
+
export declare const military: (ctx: Ctx) => Promise<Sourced<AircraftState[]>>;
|
|
55
|
+
/** Aircraft broadcasting a callsign (flight number such as "UAE44"). */
|
|
56
|
+
export declare const byCallsign: (ctx: Ctx, callsign: string) => Promise<Sourced<AircraftState[]>>;
|
|
57
|
+
export type EmergencyCode = '7500' | '7600' | '7700';
|
|
58
|
+
/** Transponder emergency codes: 7500 unlawful interference (hijack), 7600 radio failure, 7700 general emergency. */
|
|
59
|
+
export declare const EMERGENCY_CODES: Record<EmergencyCode, string>;
|
|
60
|
+
/** Aircraft currently squawking a given code, worldwide. */
|
|
61
|
+
export declare const bySquawk: (ctx: Ctx, code: string) => Promise<Sourced<AircraftState[]>>;
|
|
62
|
+
/** Aircraft on the FAA LADD list (owner asked to limit public display), worldwide. Large response (~1-2k aircraft). */
|
|
63
|
+
export declare const ladd: (ctx: Ctx) => Promise<Sourced<AircraftState[]>>;
|
|
64
|
+
/** Aircraft using an FAA PIA (privacy ICAO address), i.e. a temporary hex not tied to the real registration. */
|
|
65
|
+
export declare const privacy: (ctx: Ctx) => Promise<Sourced<AircraftState[]>>;
|
|
66
|
+
/** Aircraft within `nm` nautical miles of a point (max 250), with the military flag from adsb.lol's database. */
|
|
67
|
+
export declare function aroundPoint(ctx: Ctx, lat: number, lon: number, nm: number): Promise<Sourced<(AircraftState & {
|
|
68
|
+
military: boolean;
|
|
69
|
+
})[]>>;
|
|
70
|
+
/** Fallback live state from OpenSky (anonymous access). Its altitude is in meters; converted here. */
|
|
71
|
+
export declare function openskyState(ctx: Ctx, hex: string): Promise<Sourced<AircraftState | null>>;
|
|
72
|
+
/** Registration -> ICAO 24-bit address (hex) via hexdb.io. */
|
|
73
|
+
export declare function hexForRegistration(ctx: Ctx, reg: string): Promise<Sourced<string>>;
|
|
74
|
+
export declare function aircraftInfo(ctx: Ctx, hex: string): Promise<Sourced<AircraftInfo>>;
|
|
75
|
+
export declare const isHex: (s: string) => boolean;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { enc } from '../core/context.js';
|
|
2
|
+
export function fromAdsbLol(a) {
|
|
3
|
+
return {
|
|
4
|
+
hex: a.hex.toLowerCase().replace(/^~/, ''),
|
|
5
|
+
registration: a.r?.trim() || null,
|
|
6
|
+
type: a.t?.trim() || null,
|
|
7
|
+
callsign: a.flight?.trim() || null,
|
|
8
|
+
lat: a.lat ?? null,
|
|
9
|
+
lon: a.lon ?? null,
|
|
10
|
+
altFt: typeof a.alt_baro === 'number' ? a.alt_baro : a.alt_baro === 'ground' ? 0 : null,
|
|
11
|
+
onGround: a.alt_baro === 'ground',
|
|
12
|
+
speedKt: a.gs ?? null,
|
|
13
|
+
track: a.track ?? null,
|
|
14
|
+
squawk: a.squawk ?? null,
|
|
15
|
+
seenSec: a.seen_pos ?? a.seen ?? null,
|
|
16
|
+
source: 'adsb.lol',
|
|
17
|
+
...(a.emergency !== undefined ? { emergency: a.emergency } : {}),
|
|
18
|
+
...(a.dbFlags !== undefined ? { dbFlags: a.dbFlags } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const ADSB = 'https://api.adsb.lol/v2';
|
|
22
|
+
async function adsbList(ctx, path, ttlSec = 30) {
|
|
23
|
+
const r = await ctx.http.get(`${ADSB}${path}`, { source: 'adsb.lol', ttlSec, timeoutMs: 30_000 });
|
|
24
|
+
return { data: r.data ? (r.data.ac ?? []).map(fromAdsbLol) : null, prov: r.prov };
|
|
25
|
+
}
|
|
26
|
+
export const byHex = (ctx, hex) => adsbList(ctx, `/hex/${enc(hex.toLowerCase())}`);
|
|
27
|
+
export const byRegistration = (ctx, reg) => adsbList(ctx, `/reg/${enc(reg.toUpperCase())}`);
|
|
28
|
+
/** Aircraft flagged as military in the adsb.lol database, worldwide. */
|
|
29
|
+
export const military = (ctx) => adsbList(ctx, '/mil', 120);
|
|
30
|
+
/** Aircraft broadcasting a callsign (flight number such as "UAE44"). */
|
|
31
|
+
export const byCallsign = (ctx, callsign) => adsbList(ctx, `/callsign/${enc(callsign.trim().toUpperCase())}`);
|
|
32
|
+
/** Transponder emergency codes: 7500 unlawful interference (hijack), 7600 radio failure, 7700 general emergency. */
|
|
33
|
+
export const EMERGENCY_CODES = { '7500': 'hijack / unlawful interference', '7600': 'radio failure', '7700': 'general emergency' };
|
|
34
|
+
/** Aircraft currently squawking a given code, worldwide. */
|
|
35
|
+
export const bySquawk = (ctx, code) => adsbList(ctx, `/sqk/${enc(code)}`, 30);
|
|
36
|
+
/** Aircraft on the FAA LADD list (owner asked to limit public display), worldwide. Large response (~1-2k aircraft). */
|
|
37
|
+
export const ladd = (ctx) => adsbList(ctx, '/ladd', 300);
|
|
38
|
+
/** Aircraft using an FAA PIA (privacy ICAO address), i.e. a temporary hex not tied to the real registration. */
|
|
39
|
+
export const privacy = (ctx) => adsbList(ctx, '/pia', 300);
|
|
40
|
+
/** Aircraft within `nm` nautical miles of a point (max 250), with the military flag from adsb.lol's database. */
|
|
41
|
+
export async function aroundPoint(ctx, lat, lon, nm) {
|
|
42
|
+
const r = await ctx.http.get(`${ADSB}/point/${lat.toFixed(4)}/${lon.toFixed(4)}/${Math.min(250, Math.max(1, Math.round(nm)))}`, {
|
|
43
|
+
source: 'adsb.lol',
|
|
44
|
+
ttlSec: 60,
|
|
45
|
+
timeoutMs: 30_000,
|
|
46
|
+
});
|
|
47
|
+
return { data: r.data ? (r.data.ac ?? []).map((a) => ({ ...fromAdsbLol(a), military: ((a.dbFlags ?? 0) & 1) === 1 })) : null, prov: r.prov };
|
|
48
|
+
}
|
|
49
|
+
/** Fallback live state from OpenSky (anonymous access). Its altitude is in meters; converted here. */
|
|
50
|
+
export async function openskyState(ctx, hex) {
|
|
51
|
+
const r = await ctx.http.get(`https://opensky-network.org/api/states/all?icao24=${enc(hex.toLowerCase())}`, {
|
|
52
|
+
source: 'opensky',
|
|
53
|
+
ttlSec: 30,
|
|
54
|
+
});
|
|
55
|
+
const s = r.data?.states?.[0];
|
|
56
|
+
if (!r.data)
|
|
57
|
+
return { data: null, prov: r.prov };
|
|
58
|
+
if (!s)
|
|
59
|
+
return { data: null, prov: { ...r.prov, note: 'aircraft not currently seen' } };
|
|
60
|
+
const n = (v) => (typeof v === 'number' ? v : null);
|
|
61
|
+
const altM = n(s[7]);
|
|
62
|
+
return {
|
|
63
|
+
data: {
|
|
64
|
+
hex: String(s[0]),
|
|
65
|
+
registration: null,
|
|
66
|
+
type: null,
|
|
67
|
+
callsign: typeof s[1] === 'string' ? s[1].trim() || null : null,
|
|
68
|
+
lon: n(s[5]),
|
|
69
|
+
lat: n(s[6]),
|
|
70
|
+
altFt: altM === null ? null : Math.round(altM * 3.28084),
|
|
71
|
+
onGround: s[8] === true,
|
|
72
|
+
speedKt: n(s[9]) === null ? null : Math.round(n(s[9]) * 1.94384),
|
|
73
|
+
track: n(s[10]),
|
|
74
|
+
squawk: typeof s[14] === 'string' ? s[14] : null,
|
|
75
|
+
seenSec: n(s[4]) === null ? null : Math.max(0, Math.round(Date.now() / 1000 - n(s[4]))),
|
|
76
|
+
source: 'opensky',
|
|
77
|
+
},
|
|
78
|
+
prov: r.prov,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Registration -> ICAO 24-bit address (hex) via hexdb.io. */
|
|
82
|
+
export async function hexForRegistration(ctx, reg) {
|
|
83
|
+
const r = await ctx.http.get(`https://hexdb.io/reg-hex?reg=${enc(reg.toUpperCase())}`, { source: 'hexdb', as: 'text', ttlSec: 30 * 86_400 });
|
|
84
|
+
const hex = r.data?.trim();
|
|
85
|
+
return { data: hex && /^[0-9a-f]{6}$/i.test(hex) ? hex.toLowerCase() : null, prov: r.prov };
|
|
86
|
+
}
|
|
87
|
+
export async function aircraftInfo(ctx, hex) {
|
|
88
|
+
const r = await ctx.http.get(`https://hexdb.io/api/v1/aircraft/${enc(hex.toUpperCase())}`, {
|
|
89
|
+
source: 'hexdb',
|
|
90
|
+
ttlSec: 30 * 86_400,
|
|
91
|
+
});
|
|
92
|
+
const d = r.data;
|
|
93
|
+
if (!d || !d.ModeS)
|
|
94
|
+
return { data: null, prov: r.prov };
|
|
95
|
+
return {
|
|
96
|
+
data: {
|
|
97
|
+
hex: d.ModeS.toLowerCase(),
|
|
98
|
+
registration: d.Registration || null,
|
|
99
|
+
manufacturer: d.Manufacturer || null,
|
|
100
|
+
type: d.Type || null,
|
|
101
|
+
typeCode: d.ICAOTypeCode || null,
|
|
102
|
+
owner: d.RegisteredOwners || null,
|
|
103
|
+
},
|
|
104
|
+
prov: r.prov,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export const isHex = (s) => /^[0-9a-f]{6}$/i.test(s.trim());
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { Provenance } from '../core/types.js';
|
|
3
|
+
export interface Airport {
|
|
4
|
+
ident: string;
|
|
5
|
+
iata: string | null;
|
|
6
|
+
name: string;
|
|
7
|
+
type: 'large_airport' | 'medium_airport';
|
|
8
|
+
lat: number;
|
|
9
|
+
lon: number;
|
|
10
|
+
country: string;
|
|
11
|
+
/** ISO 3166-2 region, e.g. US-AK. */
|
|
12
|
+
region: string;
|
|
13
|
+
city: string;
|
|
14
|
+
}
|
|
15
|
+
/** Minimal RFC 4180 line parser (OurAirports quotes every text field). */
|
|
16
|
+
export declare function parseCsvLine(line: string): string[];
|
|
17
|
+
export declare function parseAirports(csv: string): Airport[];
|
|
18
|
+
/** Large and medium airports worldwide (OurAirports, public domain). Cached for 30 days. */
|
|
19
|
+
export declare function airports(ctx: Ctx): Promise<{
|
|
20
|
+
data: Airport[] | null;
|
|
21
|
+
prov: Provenance;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function haversineKm(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
24
|
+
export declare function nearestAirport(list: Airport[], lat: number, lon: number, filter?: (a: Airport) => boolean): {
|
|
25
|
+
airport: Airport;
|
|
26
|
+
km: number;
|
|
27
|
+
} | null;
|
|
28
|
+
export declare const airportLabel: (a: Airport) => string;
|