Merge upstream main into pr/street-level-show-action

Re-pin the Realtime payload digests for main's control_cockpit wording.
This commit is contained in:
Said Turksever committed 2026-11-06 00:23:42 +00:00
commit 14f7326dbf
118 files changed
+5479 -353

No files matched your search

+60 -4
View File
@@ -4,6 +4,14 @@ import { suggestView } from '../views.js';
import { defineTool, ToolError } from '../catalog.js';
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.js';
import {
FIRMS_CONFIDENCE_MODES,
MIN_FRP_MW_MAX,
MIN_FRP_MW_MIN,
firePassesFilter,
normalizeFireFilter,
} from '../../data/firmsIntensity.js';
import { normalizeConfidence } from '../../data/firmsAdapt.js';
function acquiredMsUtc(acqDate, acqTime) {
if (typeof acqDate !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(acqDate))
@@ -87,10 +95,30 @@ export const getActiveFires = defineTool({
title: 'Active fires',
description:
'Satellite fire detections from NASA FIRMS in the last 24 hours within an ' +
'area, most intense (fire radiative power) first.',
'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.",
inputSchema: {
type: 'object',
properties: { area: AREA_SCHEMA, limit: LIMIT_SCHEMA },
properties: {
area: AREA_SCHEMA,
min_frp_mw: {
type: 'number',
minimum: MIN_FRP_MW_MIN,
maximum: MIN_FRP_MW_MAX,
description:
'Hide detections weaker than this fire radiative power (MW). ' +
'A typical detection is ~6 MW; 20 MW keeps the top tenth, 100 MW the top percent.',
},
confidence: {
type: 'string',
enum: [...FIRMS_CONFIDENCE_MODES],
description:
'"all" (default), "nominal" (nominal and high), or "high". Many of the ' +
'strongest fires are rated low confidence, so prefer "all" unless asked.',
},
limit: LIMIT_SCHEMA,
},
required: ['area'],
additionalProperties: false,
},
@@ -103,9 +131,31 @@ export const getActiveFires = defineTool({
'unavailable',
'Fire detections need a NASA FIRMS key configured for this server',
);
const filter = normalizeFireFilter({
minFrp: args.min_frp_mw,
confidence: args.confidence,
});
const fires = snapshot.fires
.filter((fire) => areaContains(area, fire))
.filter(
(fire) =>
areaContains(area, fire) &&
firePassesFilter(
{
frp: Number(fire.frp),
confidence: normalizeConfidence(fire.confidence),
},
filter,
),
)
.sort((a, b) => (b.frp ?? 0) - (a.frp ?? 0));
const filterNotes = [
...(filter.minFrp > 0 ? [`≥ ${filter.minFrp} MW`] : []),
...(filter.confidence !== 'all'
? [
`${filter.confidence === 'high' ? 'high' : 'nominal or high'} confidence`,
]
: []),
];
const result = capRows(fires, args.limit);
// The proxy serves its last good snapshot when a refresh fails, and marks
// satellites whose download failed.
@@ -119,10 +169,16 @@ export const getActiveFires = defineTool({
];
return {
summary:
`${countNoun(fires.length, 'fire detection')} in ${area.label} in the last 24 hours` +
`${countNoun(fires.length, 'fire detection')}` +
(filterNotes.length ? ` (${filterNotes.join(', ')})` : '') +
` in ${area.label} in the last 24 hours` +
(notes.length ? ` (${notes.join('; ')}).` : '.'),
data: {
view: suggestView(services, { area, layers: ['local-firms'] }),
filter: {
min_frp_mw: filter.minFrp,
confidence: filter.confidence,
},
stale,
missing_sources: missing,
fetched_at: isoTime(snapshot.fetchedAt),
+36
View File
@@ -44,3 +44,39 @@ test('fire acquisition timestamps preserve valid leap days and UTC times', async
assert.equal(result.data.rows[0].acquired, expected);
}
});
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' },
];
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.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]);
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');
assert.match(nominal.summary, /\(nominal or high confidence\)/);
const both = await catalog.call('get_active_fires', {
...TAIWAN,
min_frp_mw: 19.6,
confidence: 'high',
});
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\)/);
});