nextbillion-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +11 -0
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/core/server.d.ts +13 -0
- package/dist/core/server.js +62 -0
- package/dist/core/server.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +7 -0
- package/dist/log.js +13 -0
- package/dist/log.js.map +1 -0
- package/dist/nbclient/client.d.ts +39 -0
- package/dist/nbclient/client.js +124 -0
- package/dist/nbclient/client.js.map +1 -0
- package/dist/nbclient/errors.d.ts +13 -0
- package/dist/nbclient/errors.js +36 -0
- package/dist/nbclient/errors.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.js +35 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/maps/static-map-image.d.ts +25 -0
- package/dist/tools/maps/static-map-image.js +31 -0
- package/dist/tools/maps/static-map-image.js.map +1 -0
- package/dist/tools/maps/static-route-map.d.ts +28 -0
- package/dist/tools/maps/static-route-map.js +71 -0
- package/dist/tools/maps/static-route-map.js.map +1 -0
- package/dist/tools/maps/static-shared.d.ts +32 -0
- package/dist/tools/maps/static-shared.js +57 -0
- package/dist/tools/maps/static-shared.js.map +1 -0
- package/dist/tools/places/geocode-batch.d.ts +35 -0
- package/dist/tools/places/geocode-batch.js +52 -0
- package/dist/tools/places/geocode-batch.js.map +1 -0
- package/dist/tools/places/geocode-reverse.d.ts +30 -0
- package/dist/tools/places/geocode-reverse.js +33 -0
- package/dist/tools/places/geocode-reverse.js.map +1 -0
- package/dist/tools/places/geocode-structured.d.ts +32 -0
- package/dist/tools/places/geocode-structured.js +59 -0
- package/dist/tools/places/geocode-structured.js.map +1 -0
- package/dist/tools/places/place-lookup.d.ts +19 -0
- package/dist/tools/places/place-lookup.js +24 -0
- package/dist/tools/places/place-lookup.js.map +1 -0
- package/dist/tools/places/postcode-lookup.d.ts +13 -0
- package/dist/tools/places/postcode-lookup.js +56 -0
- package/dist/tools/places/postcode-lookup.js.map +1 -0
- package/dist/tools/places/text-search.d.ts +118 -0
- package/dist/tools/places/text-search.js +66 -0
- package/dist/tools/places/text-search.js.map +1 -0
- package/dist/tools/routing/directions.d.ts +58 -0
- package/dist/tools/routing/directions.js +109 -0
- package/dist/tools/routing/directions.js.map +1 -0
- package/dist/tools/routing/distance-matrix.d.ts +42 -0
- package/dist/tools/routing/distance-matrix.js +76 -0
- package/dist/tools/routing/distance-matrix.js.map +1 -0
- package/dist/tools/routing/isochrone.d.ts +22 -0
- package/dist/tools/routing/isochrone.js +67 -0
- package/dist/tools/routing/isochrone.js.map +1 -0
- package/dist/tools/routing/search-along-route.d.ts +17 -0
- package/dist/tools/routing/search-along-route.js +58 -0
- package/dist/tools/routing/search-along-route.js.map +1 -0
- package/dist/tools/shared/geo.d.ts +81 -0
- package/dist/tools/shared/geo.js +94 -0
- package/dist/tools/shared/geo.js.map +1 -0
- package/dist/tools/types.d.ts +39 -0
- package/dist/tools/types.js +13 -0
- package/dist/tools/types.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { CoordinateSchema } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, ToolInputError } from '../types.js';
|
|
4
|
+
import { fetchImageResult, markerParam, StaticImageShape, staticImagePath, } from './static-shared.js';
|
|
5
|
+
const Schema = z.object({
|
|
6
|
+
encoded_polyline: z
|
|
7
|
+
.string()
|
|
8
|
+
.optional()
|
|
9
|
+
.describe('Route geometry as a Google encoded polyline (precision 5) — exactly what the directions ' +
|
|
10
|
+
'tool returns with its default geometry setting'),
|
|
11
|
+
route_points: z
|
|
12
|
+
.array(CoordinateSchema)
|
|
13
|
+
.min(2)
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('Alternative to encoded_polyline: the route as an ordered list of coordinates'),
|
|
16
|
+
markers: z
|
|
17
|
+
.array(CoordinateSchema.extend({ color: z.string().optional() }))
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Extra markers, e.g. origin and destination, with optional color'),
|
|
20
|
+
stroke_color: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Route line color (e.g. "blue", "#ff0000"; default blue)'),
|
|
24
|
+
stroke_width: z
|
|
25
|
+
.number()
|
|
26
|
+
.int()
|
|
27
|
+
.min(1)
|
|
28
|
+
.max(20)
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('Route line width in pixels (default 4)'),
|
|
31
|
+
padding: z
|
|
32
|
+
.number()
|
|
33
|
+
.min(0)
|
|
34
|
+
.max(1)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Margin around the route as a fraction of image size (default 0.1)'),
|
|
37
|
+
...StaticImageShape,
|
|
38
|
+
});
|
|
39
|
+
export const staticRouteMap = {
|
|
40
|
+
name: 'static_route_map',
|
|
41
|
+
title: 'Static Route Map',
|
|
42
|
+
description: 'Render a static map image with a route drawn on it, auto-fitted to show the whole route. ' +
|
|
43
|
+
'Pass the encoded polyline from the directions tool (preferred), or a list of route points. ' +
|
|
44
|
+
'Returns the image directly.',
|
|
45
|
+
inputSchema: Schema,
|
|
46
|
+
annotations: READ_ONLY,
|
|
47
|
+
async run(args, nb) {
|
|
48
|
+
if (!args.encoded_polyline && !args.route_points) {
|
|
49
|
+
throw new ToolInputError('Provide `encoded_polyline` (preferred) or `route_points`.');
|
|
50
|
+
}
|
|
51
|
+
if (args.encoded_polyline && args.route_points) {
|
|
52
|
+
throw new ToolInputError('Provide either `encoded_polyline` or `route_points`, not both.');
|
|
53
|
+
}
|
|
54
|
+
const styleSegments = [
|
|
55
|
+
`stroke:${args.stroke_color ?? 'blue'}`,
|
|
56
|
+
`width:${args.stroke_width ?? 4}`,
|
|
57
|
+
'fill:none',
|
|
58
|
+
];
|
|
59
|
+
// Path coordinates are `lat,lng`; `enc:` consumes the rest of the parameter value.
|
|
60
|
+
const geometry = args.encoded_polyline
|
|
61
|
+
? `enc:${args.encoded_polyline}`
|
|
62
|
+
: args.route_points.map((p) => `${p.latitude},${p.longitude}`).join('|');
|
|
63
|
+
const path = `${styleSegments.join('|')}|${geometry}`;
|
|
64
|
+
return fetchImageResult(nb, staticImagePath('auto', args), {
|
|
65
|
+
path,
|
|
66
|
+
markers: args.markers?.length ? markerParam(args.markers) : undefined,
|
|
67
|
+
padding: args.padding !== undefined ? String(args.padding) : undefined,
|
|
68
|
+
}, `Route map rendered${args.markers?.length ? ` with ${args.markers.length} marker(s)` : ''}.`, args);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=static-route-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-route-map.js","sourceRoot":"","sources":["../../../src/tools/maps/static-route-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,gBAAgB,EAAE,CAAC;SAChB,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,0FAA0F;QACxF,gDAAgD,CACnD;IACH,YAAY,EAAE,CAAC;SACZ,KAAK,CAAC,gBAAgB,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CAAC,8EAA8E,CAAC;IAC3F,OAAO,EAAE,CAAC;SACP,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MA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AM,QAAQ,GAAG,IAAI,CAAC,gBAAgB;YACpC,CAAC,CAAC,OAAO,IAAI,CAAC,gBAAgB,EAAE;YAChC,CAAC,CAAC,IAAI,CAAC,YAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5E,MAAM,IAAI,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;QACtD,OAAO,gBAAgB,CACrB,EAAE,EACF,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,EAC7B;YACE,IAAI;YACJ,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;YACrE,OAAO,EAAE,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;SACvE,EACD,qBAAqB,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,EAC5F,IAAI,CACL,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import type { NbClient } from '../../nbclient/client.js';
|
|
3
|
+
import type { Coordinate } from '../shared/geo.js';
|
|
4
|
+
import type { ToolResult } from '../types.js';
|
|
5
|
+
export declare const StaticImageShape: {
|
|
6
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
style: z.ZodOptional<z.ZodString>;
|
|
9
|
+
format: z.ZodOptional<z.ZodEnum<{
|
|
10
|
+
jpg: "jpg";
|
|
11
|
+
png: "png";
|
|
12
|
+
webp: "webp";
|
|
13
|
+
}>>;
|
|
14
|
+
retina: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
};
|
|
16
|
+
export interface StaticImageArgs {
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
style?: string;
|
|
20
|
+
format?: 'png' | 'jpg' | 'webp';
|
|
21
|
+
retina?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Build the `/maps/{style}/static/{position}/{size}.{format}` path. */
|
|
24
|
+
export declare function staticImagePath(positionSegment: string, args: StaticImageArgs): string;
|
|
25
|
+
/**
|
|
26
|
+
* The `markers` query parameter uses `longitude,latitude` order — the one NextBillion
|
|
27
|
+
* parameter with flipped coordinates (paths and centers are `lat,lng`).
|
|
28
|
+
*/
|
|
29
|
+
export declare function markerParam(markers: Array<Coordinate & {
|
|
30
|
+
color?: string;
|
|
31
|
+
}>): string;
|
|
32
|
+
export declare function fetchImageResult(nb: NbClient, path: string, query: Record<string, string | undefined>, caption: string, args: StaticImageArgs): Promise<ToolResult>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
export const StaticImageShape = {
|
|
3
|
+
width: z
|
|
4
|
+
.number()
|
|
5
|
+
.int()
|
|
6
|
+
.min(16)
|
|
7
|
+
.max(2048)
|
|
8
|
+
.optional()
|
|
9
|
+
.describe('Image width in pixels (default 512)'),
|
|
10
|
+
height: z
|
|
11
|
+
.number()
|
|
12
|
+
.int()
|
|
13
|
+
.min(16)
|
|
14
|
+
.max(2048)
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Image height in pixels (default 512)'),
|
|
17
|
+
style: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Map style id: "streets", "light", "dark", or "hybrid" (default streets)'),
|
|
21
|
+
format: z.enum(['png', 'jpg', 'webp']).optional().describe('Image format (default png)'),
|
|
22
|
+
retina: z.boolean().optional().describe('Render at @2x resolution for high-DPI displays'),
|
|
23
|
+
};
|
|
24
|
+
const MIME_TYPES = {
|
|
25
|
+
png: 'image/png',
|
|
26
|
+
jpg: 'image/jpeg',
|
|
27
|
+
webp: 'image/webp',
|
|
28
|
+
};
|
|
29
|
+
/** Build the `/maps/{style}/static/{position}/{size}.{format}` path. */
|
|
30
|
+
export function staticImagePath(positionSegment, args) {
|
|
31
|
+
const style = args.style ?? 'streets';
|
|
32
|
+
const size = `${args.width ?? 512}x${args.height ?? 512}${args.retina ? '@2x' : ''}`;
|
|
33
|
+
const format = args.format ?? 'png';
|
|
34
|
+
return `/maps/${encodeURIComponent(style)}/static/${positionSegment}/${size}.${format}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The `markers` query parameter uses `longitude,latitude` order — the one NextBillion
|
|
38
|
+
* parameter with flipped coordinates (paths and centers are `lat,lng`).
|
|
39
|
+
*/
|
|
40
|
+
export function markerParam(markers) {
|
|
41
|
+
return markers
|
|
42
|
+
.map((m) => `${m.longitude},${m.latitude}${m.color ? `,${m.color}` : ''}`)
|
|
43
|
+
.join('|');
|
|
44
|
+
}
|
|
45
|
+
export async function fetchImageResult(nb, path, query, caption, args) {
|
|
46
|
+
const image = await nb.getBinary(path, query);
|
|
47
|
+
const mimeType = image.contentType.startsWith('image/')
|
|
48
|
+
? image.contentType
|
|
49
|
+
: MIME_TYPES[args.format ?? 'png'];
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{ type: 'image', data: Buffer.from(image.data).toString('base64'), mimeType },
|
|
53
|
+
{ type: 'text', text: caption },
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=static-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-shared.js","sourceRoot":"","sources":["../../../src/tools/maps/static-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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odObject<{
|
|
6
|
+
latitude: z.ZodNumber;
|
|
7
|
+
longitude: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
radius_m: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
country_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
bounding_box: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
west: z.ZodNumber;
|
|
13
|
+
south: z.ZodNumber;
|
|
14
|
+
east: z.ZodNumber;
|
|
15
|
+
north: z.ZodNumber;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
language: z.ZodOptional<z.ZodString>;
|
|
19
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
AR: "AR";
|
|
21
|
+
CN: "CN";
|
|
22
|
+
IL: "IL";
|
|
23
|
+
IN: "IN";
|
|
24
|
+
MA: "MA";
|
|
25
|
+
PK: "PK";
|
|
26
|
+
RU: "RU";
|
|
27
|
+
TR: "TR";
|
|
28
|
+
TW: "TW";
|
|
29
|
+
Unified: "Unified";
|
|
30
|
+
}>>;
|
|
31
|
+
query: z.ZodString;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const geocodeBatch: NbTool<typeof Schema>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { placesFilterQuery, PlacesFilterShape } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, textResult } from '../types.js';
|
|
4
|
+
const BatchQuerySchema = z.object({
|
|
5
|
+
query: z.string().min(1).describe('Free-text search query for this entry'),
|
|
6
|
+
...PlacesFilterShape,
|
|
7
|
+
});
|
|
8
|
+
const Schema = z.object({
|
|
9
|
+
queries: z
|
|
10
|
+
.array(BatchQuerySchema)
|
|
11
|
+
.min(1)
|
|
12
|
+
.max(100)
|
|
13
|
+
.describe('Up to 100 forward-geocode queries resolved in a single request'),
|
|
14
|
+
});
|
|
15
|
+
export const geocodeBatch = {
|
|
16
|
+
name: 'geocode_batch',
|
|
17
|
+
title: 'Batch Geocode',
|
|
18
|
+
description: 'Forward-geocode up to 100 free-text queries in one request; returns one ranked result set ' +
|
|
19
|
+
'per query, in input order. Strongly prefer this over repeated geocode_forward calls when ' +
|
|
20
|
+
'resolving several addresses — this endpoint has a dedicated (low) rate limit of 60 requests ' +
|
|
21
|
+
'per minute, so batch as much as possible into each call.',
|
|
22
|
+
inputSchema: Schema,
|
|
23
|
+
annotations: READ_ONLY,
|
|
24
|
+
async run(args, nb) {
|
|
25
|
+
const body = args.queries.map((entry) => {
|
|
26
|
+
const filters = placesFilterQuery(entry);
|
|
27
|
+
return {
|
|
28
|
+
q: entry.query,
|
|
29
|
+
at: filters.at,
|
|
30
|
+
in: filters.in,
|
|
31
|
+
limit: filters.limit,
|
|
32
|
+
lang: filters.lang,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const response = await nb.postJson('/geocode/batch', {}, body);
|
|
36
|
+
const resultSets = Array.isArray(response) ? response : [response];
|
|
37
|
+
const lines = resultSets.map((set, index) => {
|
|
38
|
+
const items = set?.items ?? [];
|
|
39
|
+
const top = items[0];
|
|
40
|
+
const address = top?.address;
|
|
41
|
+
const position = top?.position;
|
|
42
|
+
const summary = top
|
|
43
|
+
? `${address?.label ?? top.title} (${position?.lat}, ${position?.lng})`
|
|
44
|
+
: 'no match';
|
|
45
|
+
return `${index + 1}. "${args.queries[index]?.query}" → ${summary}${items.length > 1 ? ` [+${items.length - 1} more]` : ''}`;
|
|
46
|
+
});
|
|
47
|
+
return textResult(`Resolved ${resultSets.length} queries:\n${lines.join('\n')}`, {
|
|
48
|
+
results: resultSets,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=geocode-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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+
import * as z from 'zod/v4';
|
|
2
|
+
import { type NbTool } from '../types.js';
|
|
3
|
+
declare const Schema: z.ZodObject<{
|
|
4
|
+
coordinate: z.ZodObject<{
|
|
5
|
+
latitude: z.ZodNumber;
|
|
6
|
+
longitude: z.ZodNumber;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
country_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
9
|
+
bounding_box: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
west: z.ZodNumber;
|
|
11
|
+
south: z.ZodNumber;
|
|
12
|
+
east: z.ZodNumber;
|
|
13
|
+
north: z.ZodNumber;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
language: z.ZodOptional<z.ZodString>;
|
|
16
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
17
|
+
AR: "AR";
|
|
18
|
+
CN: "CN";
|
|
19
|
+
IL: "IL";
|
|
20
|
+
IN: "IN";
|
|
21
|
+
MA: "MA";
|
|
22
|
+
PK: "PK";
|
|
23
|
+
RU: "RU";
|
|
24
|
+
TR: "TR";
|
|
25
|
+
TW: "TW";
|
|
26
|
+
Unified: "Unified";
|
|
27
|
+
}>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export declare const geocodeReverse: NbTool<typeof Schema>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { BoundingBoxSchema, CoordinateSchema, CountryCodesSchema, summarizePlaces, toLatLng, ViewSchema, } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, textResult } from '../types.js';
|
|
4
|
+
const Schema = z.object({
|
|
5
|
+
coordinate: CoordinateSchema.describe('The location to reverse geocode'),
|
|
6
|
+
country_codes: CountryCodesSchema.optional(),
|
|
7
|
+
bounding_box: BoundingBoxSchema.optional().describe('Hard-limit results to this bounding box'),
|
|
8
|
+
language: z.string().optional().describe('Result language as a BCP 47 tag, e.g. "en-US"'),
|
|
9
|
+
view: ViewSchema.optional(),
|
|
10
|
+
});
|
|
11
|
+
export const geocodeReverse = {
|
|
12
|
+
name: 'geocode_reverse',
|
|
13
|
+
title: 'Reverse Geocode',
|
|
14
|
+
description: 'Find the nearest address for a geographic coordinate. Returns the full postal address, ' +
|
|
15
|
+
'the matched position, and a bounding box.',
|
|
16
|
+
inputSchema: Schema,
|
|
17
|
+
annotations: READ_ONLY,
|
|
18
|
+
async run(args, nb) {
|
|
19
|
+
const inFilter = args.country_codes
|
|
20
|
+
? `countryCode:${args.country_codes.map((c) => c.toUpperCase()).join(',')}`
|
|
21
|
+
: args.bounding_box
|
|
22
|
+
? `bbox:${args.bounding_box.west},${args.bounding_box.south},${args.bounding_box.east},${args.bounding_box.north}`
|
|
23
|
+
: undefined;
|
|
24
|
+
const response = await nb.getJson('/revgeocode', {
|
|
25
|
+
at: toLatLng(args.coordinate),
|
|
26
|
+
in: inFilter,
|
|
27
|
+
lang: args.language,
|
|
28
|
+
view: args.view,
|
|
29
|
+
});
|
|
30
|
+
return textResult(summarizePlaces(response, 'address'), response);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=geocode-reverse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocode-reverse.js","sourceRoot":"","sources":["../../../src/tools/places/geocode-reverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,UAAU,EAAE,gBAAgB,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IACxE,aAAa,EAAE,kBAAkB,CAAC,QAAQ,EAAE;I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;IACpE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { type NbTool } from '../types.js';
|
|
3
|
+
declare const Schema: z.ZodObject<{
|
|
4
|
+
country_code: z.ZodString;
|
|
5
|
+
state: z.ZodOptional<z.ZodString>;
|
|
6
|
+
county: z.ZodOptional<z.ZodString>;
|
|
7
|
+
city: z.ZodOptional<z.ZodString>;
|
|
8
|
+
suburb: z.ZodOptional<z.ZodString>;
|
|
9
|
+
neighborhood: z.ZodOptional<z.ZodString>;
|
|
10
|
+
street: z.ZodOptional<z.ZodString>;
|
|
11
|
+
house_number: z.ZodOptional<z.ZodString>;
|
|
12
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
13
|
+
near: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
latitude: z.ZodNumber;
|
|
15
|
+
longitude: z.ZodNumber;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
AR: "AR";
|
|
20
|
+
CN: "CN";
|
|
21
|
+
IL: "IL";
|
|
22
|
+
IN: "IN";
|
|
23
|
+
MA: "MA";
|
|
24
|
+
PK: "PK";
|
|
25
|
+
RU: "RU";
|
|
26
|
+
TR: "TR";
|
|
27
|
+
TW: "TW";
|
|
28
|
+
Unified: "Unified";
|
|
29
|
+
}>>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export declare const geocodeStructured: NbTool<typeof Schema>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { CoordinateSchema, summarizePlaces, toLatLng, ViewSchema } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, textResult, ToolInputError } from '../types.js';
|
|
4
|
+
const Schema = z.object({
|
|
5
|
+
country_code: z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^[A-Za-z]{3}$/, 'ISO 3166-1 alpha-3 code, e.g. USA')
|
|
8
|
+
.describe('Country of the address (required, ISO 3166-1 alpha-3, e.g. "USA")'),
|
|
9
|
+
state: z.string().optional(),
|
|
10
|
+
county: z.string().optional(),
|
|
11
|
+
city: z.string().optional(),
|
|
12
|
+
suburb: z.string().optional(),
|
|
13
|
+
neighborhood: z.string().optional(),
|
|
14
|
+
street: z.string().optional(),
|
|
15
|
+
house_number: z.string().optional(),
|
|
16
|
+
postal_code: z.string().optional(),
|
|
17
|
+
near: CoordinateSchema.optional().describe('Search-context center for ranking'),
|
|
18
|
+
limit: z.number().int().min(1).max(100).optional().describe('Maximum results (default 10)'),
|
|
19
|
+
view: ViewSchema.optional(),
|
|
20
|
+
});
|
|
21
|
+
export const geocodeStructured = {
|
|
22
|
+
name: 'geocode_structured',
|
|
23
|
+
title: 'Structured Geocode',
|
|
24
|
+
description: 'Geocode an address given as separate structured fields (country, state, city, street, ' +
|
|
25
|
+
'house number, postal code) instead of one free-text string. Searches addresses and ' +
|
|
26
|
+
'administrative areas only — no POIs. Use when the address components are already known ' +
|
|
27
|
+
'and precision matters; otherwise use geocode_forward.',
|
|
28
|
+
inputSchema: Schema,
|
|
29
|
+
annotations: READ_ONLY,
|
|
30
|
+
async run(args, nb) {
|
|
31
|
+
const hasComponent = args.state ??
|
|
32
|
+
args.county ??
|
|
33
|
+
args.city ??
|
|
34
|
+
args.suburb ??
|
|
35
|
+
args.neighborhood ??
|
|
36
|
+
args.street ??
|
|
37
|
+
args.house_number ??
|
|
38
|
+
args.postal_code;
|
|
39
|
+
if (!hasComponent) {
|
|
40
|
+
throw new ToolInputError('Provide at least one address component besides country_code (state, city, street, postal_code, …).');
|
|
41
|
+
}
|
|
42
|
+
const response = await nb.getJson('/geocode/structured', {
|
|
43
|
+
countryCode: args.country_code.toUpperCase(),
|
|
44
|
+
state: args.state,
|
|
45
|
+
county: args.county,
|
|
46
|
+
city: args.city,
|
|
47
|
+
suburb: args.suburb,
|
|
48
|
+
neighborhood: args.neighborhood,
|
|
49
|
+
street: args.street,
|
|
50
|
+
houseNumber: args.house_number,
|
|
51
|
+
postalCode: args.postal_code,
|
|
52
|
+
at: args.near ? toLatLng(args.near) : undefined,
|
|
53
|
+
limit: args.limit,
|
|
54
|
+
view: args.view,
|
|
55
|
+
});
|
|
56
|
+
return textResult(summarizePlaces(response, 'match'), response);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=geocode-structured.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocode-structured.js","sourceRoot":"","sources":["../../../src/tools/places/geocode-structured.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AAEjF,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,YAAY,EAAE,CAAC;SACZ,MAAM,EAAE;SACR,KAAK,CAAC,eAAe,EAAE,mCAAmC,CAAC;SAC3D,QAAQ,CAAC,mEAAmE,CAAC;IAChF,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE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AAM;YACnB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YAC/C,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { type NbTool } from '../types.js';
|
|
3
|
+
declare const Schema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
AR: "AR";
|
|
7
|
+
CN: "CN";
|
|
8
|
+
IL: "IL";
|
|
9
|
+
IN: "IN";
|
|
10
|
+
MA: "MA";
|
|
11
|
+
PK: "PK";
|
|
12
|
+
RU: "RU";
|
|
13
|
+
TR: "TR";
|
|
14
|
+
TW: "TW";
|
|
15
|
+
Unified: "Unified";
|
|
16
|
+
}>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export declare const placeLookup: NbTool<typeof Schema>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { summarizePlaces, ViewSchema } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, textResult } from '../types.js';
|
|
4
|
+
const Schema = z.object({
|
|
5
|
+
id: z.string().min(1).describe('Unique place id, as returned by the other place/geocoding tools'),
|
|
6
|
+
view: ViewSchema.optional(),
|
|
7
|
+
});
|
|
8
|
+
export const placeLookup = {
|
|
9
|
+
name: 'place_lookup',
|
|
10
|
+
title: 'Place Lookup',
|
|
11
|
+
description: 'Fetch the full details (address, position, access points, categories, contacts) of a place ' +
|
|
12
|
+
'by its unique id. Ids come from the results of place_search, geocode_forward, autosuggest, ' +
|
|
13
|
+
'autocomplete, or search_along_route.',
|
|
14
|
+
inputSchema: Schema,
|
|
15
|
+
annotations: READ_ONLY,
|
|
16
|
+
async run(args, nb) {
|
|
17
|
+
const response = await nb.getJson('/lookup', {
|
|
18
|
+
id: args.id,
|
|
19
|
+
view: args.view,
|
|
20
|
+
});
|
|
21
|
+
return textResult(summarizePlaces(response, 'place'), response);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=place-lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"place-lookup.js","sourceRoot":"","sources":["../../../src/tools/places/place-lookup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,iEAAiE,CAAC;IACjG,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAA0B;IAChD,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,6FAA6F;QAC7F,6FAA6F;QAC7F,sCAAsC;IACxC,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,SAAS;IACtB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,OAAO,CAA0B,SAAS,EAAE;YACpE,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { type NbTool } from '../types.js';
|
|
3
|
+
declare const Schema: z.ZodObject<{
|
|
4
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
5
|
+
country: z.ZodOptional<z.ZodString>;
|
|
6
|
+
coordinate: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
latitude: z.ZodNumber;
|
|
8
|
+
longitude: z.ZodNumber;
|
|
9
|
+
}, z.core.$strip>>;
|
|
10
|
+
geojson_boundary: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export declare const postcodeLookup: NbTool<typeof Schema>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { CoordinateSchema } from '../shared/geo.js';
|
|
3
|
+
import { READ_ONLY, textResult, ToolInputError } from '../types.js';
|
|
4
|
+
const Schema = z.object({
|
|
5
|
+
postal_code: z
|
|
6
|
+
.string()
|
|
7
|
+
.optional()
|
|
8
|
+
.describe('Postal/ZIP code to look up (requires `country`; do not combine with `coordinate`)'),
|
|
9
|
+
country: z
|
|
10
|
+
.string()
|
|
11
|
+
.optional()
|
|
12
|
+
.describe('Country of the postal code — name, alpha-2, or alpha-3 ISO code. Required with `postal_code`'),
|
|
13
|
+
coordinate: CoordinateSchema.optional().describe('Find the postal code containing this location (alternative to `postal_code`)'),
|
|
14
|
+
geojson_boundary: z
|
|
15
|
+
.boolean()
|
|
16
|
+
.optional()
|
|
17
|
+
.describe('Return the boundary polygon in GeoJSON format instead of the default point-list format'),
|
|
18
|
+
});
|
|
19
|
+
const SUPPORTED_COUNTRIES = 'USA, India, UK, Netherlands, Austria, Germany, Indonesia, France, Singapore, Philippines, ' +
|
|
20
|
+
'Canada, Australia, New Zealand, Italy, Brazil, Mexico, Spain';
|
|
21
|
+
export const postcodeLookup = {
|
|
22
|
+
name: 'postcode_lookup',
|
|
23
|
+
title: 'Postcode Lookup',
|
|
24
|
+
description: 'Get the centroid and boundary polygon of a postal/ZIP code, or find which postal code a ' +
|
|
25
|
+
`coordinate belongs to. One lookup per call. Supported countries: ${SUPPORTED_COUNTRIES}.`,
|
|
26
|
+
inputSchema: Schema,
|
|
27
|
+
annotations: READ_ONLY,
|
|
28
|
+
async run(args, nb) {
|
|
29
|
+
if (args.postal_code && args.coordinate) {
|
|
30
|
+
throw new ToolInputError('Provide either `postal_code` or `coordinate`, not both.');
|
|
31
|
+
}
|
|
32
|
+
if (!args.postal_code && !args.coordinate) {
|
|
33
|
+
throw new ToolInputError('Provide `postal_code` (with `country`) or `coordinate`.');
|
|
34
|
+
}
|
|
35
|
+
if (args.postal_code && !args.country) {
|
|
36
|
+
throw new ToolInputError('`country` is required when `postal_code` is provided.');
|
|
37
|
+
}
|
|
38
|
+
const response = await nb.postJson('/postalcode', {}, {
|
|
39
|
+
postalcode: args.postal_code,
|
|
40
|
+
country: args.country,
|
|
41
|
+
at: args.coordinate
|
|
42
|
+
? { lat: args.coordinate.latitude, lng: args.coordinate.longitude }
|
|
43
|
+
: undefined,
|
|
44
|
+
format: args.geojson_boundary ? 'geojson' : undefined,
|
|
45
|
+
});
|
|
46
|
+
const places = response.places;
|
|
47
|
+
const place = Array.isArray(places) ? places[0] : undefined;
|
|
48
|
+
const geopoint = place?.geopoint;
|
|
49
|
+
const summary = place
|
|
50
|
+
? `Postal code ${place.postalCode} (${place.address ?? place.country}), centroid ` +
|
|
51
|
+
`(${geopoint?.lat}, ${geopoint?.lng}), boundary included in structured content.`
|
|
52
|
+
: 'No postal code found.';
|
|
53
|
+
return textResult(summary, response);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=postcode-lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode-lookup.js","sourceRoot":"","sources":["../../../src/tools/places/postcode-lookup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;AAEjF,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,mFAAmF,CAAC;IAChG,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,8FAA8F,CAC/F;IACH,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAC9C,8EAA8E,CAC/E;IACD,gBAAgB,EAAE,CAAC;SAChB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CACP,wFAAwF,CACzF;CACJ,CAAC,CAAC;AAEH,MAAM,mBAAmB,GACvB,4FAA4F;IAC5F,8DAA8D,CAAC;AAEjE,MAAM,CAAC,MAAM,cAAc,GAA0B;IACnD,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,0FAA0F;QAC1F,oEAAoE,mBAAmB,GAAG;IAC5F,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,SAAS;IACtB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE;QAChB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,IAAI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