fix: search every vessel the server retains

Vessel tools read the source's default of the newest 12,000 vessels while
the server keeps up to 50,000, so a lookup could miss a vessel still held.
They now ask for more than any server keeps and receive everything it has.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent ad9a3976a9
commit 41d1352930
2 files changed
+34 -2

No files matched your search

+12 -2
View File
@@ -22,6 +22,7 @@ const MMSI_SCHEMA = Object.freeze({
description: 'Maritime Mobile Service Identity, such as "366999712".',
});
const MAX_TRACK_POINTS = 200;
const ALL_VESSELS = 1_000_000;
const round = (value, digits) =>
Number.isFinite(value) ? Number(value.toFixed(digits)) : null;
@@ -45,6 +46,15 @@ function vesselRow(record, from) {
};
}
/**
* Every vessel the source retains. The source's default is the newest few
* thousand, which can leave out a vessel the server still holds; asking for
* more than any server keeps lets the server return all of them.
*/
function readVessels(services, signal) {
return services.vessels.getSnapshot({ maxRows: ALL_VESSELS }, { signal });
}
function snapshotInfo(snapshot) {
return {
source: snapshot.source ?? null,
@@ -79,7 +89,7 @@ export const vesselsInArea = defineTool({
async run(args, { services, signal }) {
const area = await resolveArea(args.area, { services, signal });
const center = areaCenter(area);
const snapshot = await services.vessels.getSnapshot({}, { signal });
const snapshot = await readVessels(services, signal);
const wanted = args.type?.toLowerCase();
const rows = snapshot.records
.filter(
@@ -130,7 +140,7 @@ export const findVessel = defineTool({
imo: (record) => String(record.imo).replace(/^IMO/i, '') === wanted,
name: (record) => String(record.name).toUpperCase().includes(wanted),
}[key];
const snapshot = await services.vessels.getSnapshot({}, { signal });
const snapshot = await readVessels(services, signal);
const rows = snapshot.records
.filter(matches)
.map((record) => vesselRow(record));