mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
refactor: share the default tool services between surfaces
Move the composition of the default tool services from the Node MCP server into gods-eye-view/tools/services, a portable export. Given a fetch that resolves the sources' /api paths, it builds the same services in a browser as on the local MCP server, so other surfaces can compose the same catalog. Queries still read only their services.
This commit is contained in:
1 parent
0dbd6375fc
commit
a8b5860e9f
6 files changed
+141
-65
No files matched your search
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* The default services Core's tools read: the layers' portable source
|
||||
* factories and the application request services. `fetchImpl` must resolve
|
||||
* the sources' relative `/api/...` paths; in a browser the page's own fetch
|
||||
* does, and elsewhere a caller supplies a resolving fetch. `appUrl` is the
|
||||
* address the app is served from.
|
||||
*/
|
||||
|
||||
import { GBFS_CITY_REGISTRY } from '../layers/bikeshare/registry.js';
|
||||
import { createBikeshareSource } from '../layers/bikeshare/source.js';
|
||||
import { createCctvSource } from '../layers/cctv/source.js';
|
||||
import { createCycloneSource } from '../layers/cyclones/source.js';
|
||||
import { createUsgsEarthquakeSource } from '../layers/earthquakes/source.js';
|
||||
import { createFirmsSource } from '../layers/firms/source.js';
|
||||
import { createInstallationSource } from '../layers/installations/source.js';
|
||||
import { createLaunchSource } from '../layers/launches/source.js';
|
||||
import { createWfigsPerimeterSource } from '../layers/perimeters/source.js';
|
||||
import { createRadioSource } from '../layers/radio/source.js';
|
||||
import { createSatelliteSource } from '../layers/satellites/source.js';
|
||||
import { createTrafficSource } from '../layers/traffic/source.js';
|
||||
import { createTransitSource } from '../layers/transit/source.js';
|
||||
import { createApplicationRequestServices } from '../services/requests.js';
|
||||
import {
|
||||
createAdsbLolSource,
|
||||
createAisStreamSource,
|
||||
createOpenSkySource,
|
||||
} from '../sources/live/standalone.js';
|
||||
import {
|
||||
createGeocodePlaceService,
|
||||
createPlaceSearchService,
|
||||
createRouteService,
|
||||
} from './places.js';
|
||||
|
||||
/** Construct every service Core's tools read. */
|
||||
export function createToolServices({ fetchImpl, appUrl }) {
|
||||
if (typeof fetchImpl !== 'function')
|
||||
throw new TypeError('A fetch implementation is required');
|
||||
const requests = createApplicationRequestServices({ fetchImpl });
|
||||
return {
|
||||
app: { baseUrl: appUrl },
|
||||
earthquakes: createUsgsEarthquakeSource({ fetchImpl }),
|
||||
fires: createFirmsSource({ fetchImpl }),
|
||||
launches: createLaunchSource({ fetchImpl }),
|
||||
aircraft: createOpenSkySource({ fetchImpl }),
|
||||
military: createAdsbLolSource({ fetchImpl }),
|
||||
vessels: createAisStreamSource({
|
||||
fetchImpl,
|
||||
origin: () => new URL(appUrl).origin,
|
||||
}),
|
||||
satellites: createSatelliteSource({ fetchImpl }),
|
||||
cctv: createCctvSource({ fetchImpl }),
|
||||
radio: createRadioSource({ fetchImpl }),
|
||||
placeSearch: createPlaceSearchService({ fetchImpl }),
|
||||
routing: createRouteService({ fetchImpl }),
|
||||
bikeshare: {
|
||||
systems: GBFS_CITY_REGISTRY,
|
||||
getStations: createBikeshareSource({ fetchImpl }).getStations,
|
||||
},
|
||||
transit: createTransitSource({ fetchImpl }),
|
||||
traffic: createTrafficSource({ fetchImpl, tileFetchImpl: fetchImpl }),
|
||||
weather: requests.weather,
|
||||
regional: requests.regional,
|
||||
terrain: requests.terrain,
|
||||
summary: requests.summary,
|
||||
features: requests.features,
|
||||
cyclones: createCycloneSource({ fetchImpl }),
|
||||
perimeters: createWfigsPerimeterSource({ fetchImpl }),
|
||||
installations: createInstallationSource({
|
||||
fetchImpl,
|
||||
tileFetchImpl: fetchImpl,
|
||||
}),
|
||||
places: createGeocodePlaceService({ fetchImpl }),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user