feat: return the view that shows each answer

Tool answers with something to show now include data.view: the view with
the matching layers on, the area framed from above or a single aircraft or
satellite followed, and the link that opens it. Area framing moves to
src/tools/views.js so links and answers frame alike.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 96a8a9addb
commit d6473b6049
20 files changed
+393 -34

No files matched your search

+28 -1
View File
@@ -1,5 +1,6 @@
/** Space queries: launches, satellite passes and satellites overhead. */
import { suggestView } from '../views.js';
import { twoline2satrec } from 'satellite.js';
import {
findNextSatellitePass,
@@ -57,7 +58,15 @@ export const getRecentLaunches = defineTool({
summary:
`${countNoun(rows.length, 'launch', 'launches')} in the last 30 days${rows[0] ? `; latest ${rows[0].name}` : ''}` +
(stale ? ' (data may be stale).' : '.'),
data: { ...result, stale },
data: {
view: suggestView(services, {
point: { lat: 20, lon: 0 },
altitudeM: 15_000_000,
layers: ['rocket-launches'],
}),
...result,
stale,
},
};
},
});
@@ -103,6 +112,17 @@ const round = (value, digits) =>
Number.isFinite(value) ? Number(value.toFixed(digits)) : null;
const nowMs = (services) => services.clock?.now() ?? Date.now();
/** A view following a satellite from above an observer. */
function followSatellite(services, point, satellite) {
return satellite.norad
? suggestView(services, {
point,
altitudeM: 3_000_000,
follow: { kind: 'satellite', id: String(satellite.norad) },
})
: null;
}
async function readCatalog(services, group, signal) {
const result = await services.satellites.readGroup(group, { signal });
if (!result.ok)
@@ -197,6 +217,7 @@ export const nextSatellitePass = defineTool({
return {
summary: `${name} has no ${args.visible_only ? 'visible ' : ''}pass over ${point.label} in the next ${hours} hours${staleNote}.`,
data: {
view: followSatellite(services, point, satellite),
stale,
location: point,
satellite: name,
@@ -210,6 +231,7 @@ export const nextSatellitePass = defineTool({
`peaking at ${Math.round(pass.maxElevDeg)}°` +
`${pass.visible ? '; visible to the naked eye' : ''}${staleNote}.`,
data: {
view: followSatellite(services, point, satellite),
stale,
location: point,
satellite: name,
@@ -273,6 +295,11 @@ export const satellitesOverhead = defineTool({
`${countNoun(rows.length, 'satellite')} from the ${group} group ${rows.length === 1 ? 'is' : 'are'} at least ${minimum}° above ${point.label} at ${isoTime(at)}` +
(stale ? ' (orbit data may be stale).' : '.'),
data: {
view: suggestView(services, {
point,
altitudeM: 3_000_000,
layers: ['satellites'],
}),
...capRows(rows, args.limit),
stale,
location: point,