mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge commit '0ceee8df40b97c6c693e86a4443794cd4ed1ff35' into HEAD
This commit is contained in:
commit
f878efe22d
306 files changed
+39352
-1624
No files matched your search
@@ -94,7 +94,8 @@ export const getActiveFires = defineTool({
|
||||
name: 'get_active_fires',
|
||||
title: 'Active fires',
|
||||
description:
|
||||
'Satellite fire detections from NASA FIRMS in the last 24 hours within an ' +
|
||||
'Satellite fire detections from NASA FIRMS in the last 24 hours (or the 24 ' +
|
||||
'hours to window_end, when the source names one) within an ' +
|
||||
'area, most intense (fire radiative power) first. Optionally limited to a ' +
|
||||
'minimum fire radiative power in megawatts and a confidence level — the ' +
|
||||
"same filter as the Active Fires layer's intensity controls.",
|
||||
@@ -171,7 +172,10 @@ export const getActiveFires = defineTool({
|
||||
summary:
|
||||
`${countNoun(fires.length, 'fire detection')}` +
|
||||
(filterNotes.length ? ` (${filterNotes.join(', ')})` : '') +
|
||||
` in ${area.label} in the last 24 hours` +
|
||||
` in ${area.label} ` +
|
||||
(Number.isFinite(snapshot.at)
|
||||
? `in the 24 hours to ${isoTime(snapshot.at)}`
|
||||
: 'in the last 24 hours') +
|
||||
(notes.length ? ` (${notes.join('; ')}).` : '.'),
|
||||
data: {
|
||||
view: suggestView(services, { area, layers: ['local-firms'] }),
|
||||
@@ -182,6 +186,7 @@ export const getActiveFires = defineTool({
|
||||
stale,
|
||||
missing_sources: missing,
|
||||
fetched_at: isoTime(snapshot.fetchedAt),
|
||||
window_end: Number.isFinite(snapshot.at) ? isoTime(snapshot.at) : null,
|
||||
...result,
|
||||
rows: result.rows.map((fire) => ({
|
||||
lat: fire.lat,
|
||||
|
||||
@@ -46,29 +46,80 @@ test('fire acquisition timestamps preserve valid leap days and UTC times', async
|
||||
});
|
||||
|
||||
const WEEK = [
|
||||
{ lat: 24.1, lon: 121.1, frp: 864, confidence: 'l', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.2, lon: 121.2, frp: 120, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.3, lon: 121.3, frp: 20, confidence: 'n', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 24.4, lon: 121.4, frp: 2, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{ lat: 30, lon: 100, frp: 500, confidence: 'h', acqDate: '2026-10-01', acqTime: '0100' },
|
||||
{
|
||||
lat: 24.1,
|
||||
lon: 121.1,
|
||||
frp: 864,
|
||||
confidence: 'l',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.2,
|
||||
lon: 121.2,
|
||||
frp: 120,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.3,
|
||||
lon: 121.3,
|
||||
frp: 20,
|
||||
confidence: 'n',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 24.4,
|
||||
lon: 121.4,
|
||||
frp: 2,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
{
|
||||
lat: 30,
|
||||
lon: 100,
|
||||
frp: 500,
|
||||
confidence: 'h',
|
||||
acqDate: '2026-10-01',
|
||||
acqTime: '0100',
|
||||
},
|
||||
];
|
||||
const TAIWAN = { area: { bbox: [120, 23, 122, 25] } };
|
||||
|
||||
test('get_active_fires shows every detection by default and reports the filter it used', async () => {
|
||||
const result = await catalogWith(WEEK).call('get_active_fires', TAIWAN);
|
||||
assert.deepEqual(result.data.rows.map((row) => row.frp_mw), [864, 120, 20, 2]);
|
||||
assert.deepEqual(
|
||||
result.data.rows.map((row) => row.frp_mw),
|
||||
[864, 120, 20, 2],
|
||||
);
|
||||
assert.deepEqual(result.data.filter, { min_frp_mw: 0, confidence: 'all' });
|
||||
assert.match(result.summary, /^4 fire detections in /);
|
||||
});
|
||||
|
||||
test('get_active_fires applies the same minimum-FRP and confidence filter as the layer', async () => {
|
||||
const catalog = catalogWith(WEEK);
|
||||
const strong = await catalog.call('get_active_fires', { ...TAIWAN, min_frp_mw: 20 });
|
||||
assert.deepEqual(strong.data.rows.map((row) => row.frp_mw), [864, 120, 20]);
|
||||
const strong = await catalog.call('get_active_fires', {
|
||||
...TAIWAN,
|
||||
min_frp_mw: 20,
|
||||
});
|
||||
assert.deepEqual(
|
||||
strong.data.rows.map((row) => row.frp_mw),
|
||||
[864, 120, 20],
|
||||
);
|
||||
assert.match(strong.summary, /^3 fire detections \(≥ 20 MW\) in /);
|
||||
|
||||
const nominal = await catalog.call('get_active_fires', { ...TAIWAN, confidence: 'nominal' });
|
||||
assert.deepEqual(nominal.data.rows.map((row) => row.frp_mw), [120, 20, 2], 'the 864 MW low-confidence fire drops');
|
||||
const nominal = await catalog.call('get_active_fires', {
|
||||
...TAIWAN,
|
||||
confidence: 'nominal',
|
||||
});
|
||||
assert.deepEqual(
|
||||
nominal.data.rows.map((row) => row.frp_mw),
|
||||
[120, 20, 2],
|
||||
'the 864 MW low-confidence fire drops',
|
||||
);
|
||||
assert.match(nominal.summary, /\(nominal or high confidence\)/);
|
||||
|
||||
const both = await catalog.call('get_active_fires', {
|
||||
@@ -76,7 +127,27 @@ test('get_active_fires applies the same minimum-FRP and confidence filter as the
|
||||
min_frp_mw: 19.6,
|
||||
confidence: 'high',
|
||||
});
|
||||
assert.deepEqual(both.data.rows.map((row) => row.frp_mw), [120]);
|
||||
assert.deepEqual(
|
||||
both.data.rows.map((row) => row.frp_mw),
|
||||
[120],
|
||||
);
|
||||
assert.deepEqual(both.data.filter, { min_frp_mw: 20, confidence: 'high' });
|
||||
assert.match(both.summary, /\(≥ 20 MW, high confidence\)/);
|
||||
});
|
||||
|
||||
test('get_active_fires names the end of a snapshot that ends at a set time', async () => {
|
||||
const at = Date.UTC(2026, 9, 1, 3);
|
||||
const catalog = composeCatalog({
|
||||
tools: [getActiveFires],
|
||||
services: { fires: { getSnapshot: async () => ({ fires: WEEK, at }) } },
|
||||
});
|
||||
const result = await catalog.call('get_active_fires', TAIWAN);
|
||||
assert.match(
|
||||
result.summary,
|
||||
/in the 24 hours to 2026-10-01T03:00:00\.000Z\.$/,
|
||||
);
|
||||
assert.equal(result.data.window_end, '2026-10-01T03:00:00.000Z');
|
||||
const now = await catalogWith(WEEK).call('get_active_fires', TAIWAN);
|
||||
assert.match(now.summary, /in the last 24 hours\.$/);
|
||||
assert.equal(now.data.window_end, null);
|
||||
});
|
||||
@@ -28,6 +28,14 @@ const MMSI_SCHEMA = Object.freeze({
|
||||
pattern: '^\\d{5,10}$',
|
||||
description: 'Maritime Mobile Service Identity, such as "366999712".',
|
||||
});
|
||||
const VESSEL_ID_SCHEMA = Object.freeze({
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
maxLength: 128,
|
||||
description:
|
||||
'The vessel id a vessel search returned. Vessels can share an MMSI; ' +
|
||||
'the id names one of them.',
|
||||
});
|
||||
const MAX_TRACK_POINTS = 200;
|
||||
const ALL_VESSELS = 1_000_000;
|
||||
|
||||
@@ -47,10 +55,13 @@ const vesselDestination = (value) => {
|
||||
return destination && /\p{L}/u.test(destination) ? destination : null;
|
||||
};
|
||||
|
||||
// `id` is the vessel's key; `mmsi` is its MMSI when known (vessels can share
|
||||
// one), else null.
|
||||
function vesselRow(record, from) {
|
||||
const point = { lat: record.latitude, lon: record.longitude };
|
||||
return {
|
||||
mmsi: record.id,
|
||||
id: record.id,
|
||||
mmsi: text(record.mmsi),
|
||||
name: text(record.name),
|
||||
imo: text(record.imo),
|
||||
type: vesselType(record.type),
|
||||
@@ -194,7 +205,7 @@ export const findVessel = defineTool({
|
||||
const [key] = given;
|
||||
const wanted = args[key].trim().toUpperCase();
|
||||
const matches = {
|
||||
mmsi: (record) => record.id === wanted,
|
||||
mmsi: (record) => String(record.mmsi ?? '') === wanted,
|
||||
imo: (record) => String(record.imo).replace(/^IMO/i, '') === wanted,
|
||||
name: (record) => String(record.name).toUpperCase().includes(wanted),
|
||||
}[key];
|
||||
@@ -227,25 +238,40 @@ export const getVesselTrack = defineTool({
|
||||
name: 'get_vessel_track',
|
||||
title: 'Vessel track',
|
||||
description:
|
||||
'Recent positions of one ship by MMSI, oldest first. Long tracks are ' +
|
||||
`evenly thinned to at most ${MAX_TRACK_POINTS} points.`,
|
||||
'Recent positions of one ship by its vessel id or MMSI, oldest first. ' +
|
||||
`Long tracks are evenly thinned to at most ${MAX_TRACK_POINTS} points.`,
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: { mmsi: MMSI_SCHEMA },
|
||||
required: ['mmsi'],
|
||||
properties: { id: VESSEL_ID_SCHEMA, mmsi: MMSI_SCHEMA },
|
||||
additionalProperties: false,
|
||||
},
|
||||
requires: ['vessels'],
|
||||
async run(args, { services, signal }) {
|
||||
const track = await services.vessels.getTrack(args.mmsi, { signal });
|
||||
const given = ['id', 'mmsi'].filter((key) => args[key] != null);
|
||||
if (given.length !== 1)
|
||||
throw new ToolError(
|
||||
'invalid_arguments',
|
||||
'Give exactly one of id or mmsi',
|
||||
);
|
||||
const [key] = given;
|
||||
const wanted = String(args[key]).trim();
|
||||
// A track is asked for by the source's reference for the vessel, which
|
||||
// for an id is the reported vessel's; an MMSI is passed as it is.
|
||||
let reference = wanted;
|
||||
if (key === 'id') {
|
||||
const snapshot = await readVessels(services, signal);
|
||||
const record = snapshot.records.find((item) => item.id === wanted);
|
||||
reference = record?.reference ?? wanted;
|
||||
}
|
||||
const track = await services.vessels.getTrack(reference, { signal });
|
||||
const points = track.records
|
||||
.filter((point) => Number.isFinite(point.observedAtMs))
|
||||
.sort((a, b) => a.observedAtMs - b.observedAtMs);
|
||||
const kept = thinEvenly(points, MAX_TRACK_POINTS);
|
||||
return {
|
||||
summary: points.length
|
||||
? `${countNoun(points.length, 'position')} for ${args.mmsi} from ${isoTime(points[0].observedAtMs)} to ${isoTime(points.at(-1).observedAtMs)}.`
|
||||
: `No recent track is available for ${args.mmsi}.`,
|
||||
? `${countNoun(points.length, 'position')} for ${wanted} from ${isoTime(points[0].observedAtMs)} to ${isoTime(points.at(-1).observedAtMs)}.`
|
||||
: `No recent track is available for ${wanted}.`,
|
||||
data: {
|
||||
view: kept.length
|
||||
? suggestView(services, {
|
||||
@@ -254,7 +280,7 @@ export const getVesselTrack = defineTool({
|
||||
altitudeM: 20_000,
|
||||
})
|
||||
: null,
|
||||
mmsi: args.mmsi,
|
||||
...(key === 'id' ? { id: wanted } : { mmsi: wanted }),
|
||||
total: points.length,
|
||||
returned: kept.length,
|
||||
thinned: kept.length < points.length,
|
||||
|
||||
@@ -5,8 +5,10 @@ import { LiveSourceError } from '../../sources/live/contract.js';
|
||||
import { createVesselSource } from '../../sources/live/standalone.js';
|
||||
import { AISSTREAM_CACHE_MAX } from '../../../server/providers/vessels/ais-store.js';
|
||||
|
||||
// An AIS source's vessel: keyed by its MMSI, which it also reports.
|
||||
const vessel = (id, latitude, longitude, extra = {}) => ({
|
||||
id,
|
||||
mmsi: id,
|
||||
reference: id,
|
||||
latitude,
|
||||
longitude,
|
||||
@@ -79,6 +81,7 @@ test('vessels in an area are nearest first and filterable by type', async () =>
|
||||
['366999712', '538001234'],
|
||||
);
|
||||
assert.deepEqual(all.data.rows[0], {
|
||||
id: '366999712',
|
||||
mmsi: '366999712',
|
||||
name: 'GOLDEN BEAR',
|
||||
imo: '9123456',
|
||||
@@ -164,6 +167,53 @@ test('vessel tracks are ordered and drop untimed positions', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('vessels sharing an MMSI are found as two, each by its own id', async () => {
|
||||
const shared = [
|
||||
vessel('hull-a', 37.81, -122.41, { mmsi: '366999712', name: 'A' }),
|
||||
vessel('hull-b', 37.79, -122.42, {
|
||||
mmsi: '366999712',
|
||||
name: 'B',
|
||||
reference: 'track:hull-b',
|
||||
}),
|
||||
vessel('hull-c', 37.8, -122.4, { mmsi: undefined, name: 'C' }),
|
||||
];
|
||||
const tracks = [];
|
||||
const catalog = composeCatalog({
|
||||
tools: coreTools,
|
||||
services: {
|
||||
vessels: {
|
||||
getSnapshot: async () => ({ records: shared, freshness: 'current' }),
|
||||
getTrack: async (reference) => {
|
||||
tracks.push(reference);
|
||||
return { records: [] };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const found = await catalog.call('find_vessel', { mmsi: '366999712' });
|
||||
assert.deepEqual(
|
||||
found.data.rows.map((row) => [row.id, row.mmsi]),
|
||||
[
|
||||
['hull-a', '366999712'],
|
||||
['hull-b', '366999712'],
|
||||
],
|
||||
);
|
||||
const area = await catalog.call('vessels_in_area', { area: bay });
|
||||
assert.deepEqual(
|
||||
area.data.rows.find((row) => row.id === 'hull-c').mmsi,
|
||||
null,
|
||||
'a vessel with no MMSI says so',
|
||||
);
|
||||
const track = await catalog.call('get_vessel_track', { id: 'hull-b' });
|
||||
assert.deepEqual(tracks, ['track:hull-b'], "asked by the vessel's reference");
|
||||
assert.equal(track.data.id, 'hull-b');
|
||||
assert.equal(track.summary, 'No recent track is available for hull-b.');
|
||||
await assert.rejects(
|
||||
catalog.call('get_vessel_track', { id: 'hull-b', mmsi: '366999712' }),
|
||||
/exactly one/,
|
||||
);
|
||||
});
|
||||
|
||||
test('a missing AIS key surfaces as an unavailable feed', async () => {
|
||||
const keyless = {
|
||||
getSnapshot: async () => {
|
||||
|
||||
Reference in new issue
Block a user