@tomtom-org/maps-sdk-plugin-agent-toolkit 0.14.0 → 0.15.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/README.md +24 -15
- package/dist/index.d.ts +62 -23
- package/dist/index.es.js +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agent Toolkit Plugin
|
|
2
2
|
|
|
3
3
|
A headless conversational agent that gives Large Language Models tool-based control over a [TomTom Map](https://docs.tomtom.com/maps-sdk-js/guides/map/tomtom-map) and TomTom location services, powered by [Vercel AI SDK v6](https://ai-sdk.dev/).
|
|
4
4
|
|
|
@@ -18,16 +18,18 @@ No UI is included — bring your own chat interface. No LLM provider is bundled
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
pnpm add @tomtom-org/maps-sdk @tomtom-org/maps-sdk-plugin-agent-toolkit ai zod maplibre-gl @turf/turf chart.js h3-js
|
|
21
|
+
pnpm add @tomtom-org/maps-sdk @tomtom-org/maps-sdk-plugin-agent-toolkit @tomtom-org/maps-sdk-plugin-map-theme ai zod maplibre-gl @turf/turf chart.js h3-js
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Install at least one AI SDK provider:
|
|
24
|
+
Install at least one AI SDK provider, plus `@ai-sdk/react` for the `useChat` example below:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
# Pick one (or more)
|
|
28
28
|
pnpm add @ai-sdk/openai
|
|
29
29
|
pnpm add @ai-sdk/anthropic
|
|
30
30
|
pnpm add @ai-sdk/azure
|
|
31
|
+
|
|
32
|
+
pnpm add @ai-sdk/react
|
|
31
33
|
```
|
|
32
34
|
|
|
33
35
|
## Quick start
|
|
@@ -79,7 +81,7 @@ function ChatPanel() {
|
|
|
79
81
|
}
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
See [
|
|
84
|
+
See the [traffic agent example](https://docs.tomtom.com/maps-sdk-js/examples/map-traffic-agent-react) for a full working example.
|
|
83
85
|
|
|
84
86
|
## Tools reference
|
|
85
87
|
|
|
@@ -118,6 +120,7 @@ The plugin ships a `DEFAULT_TOOLS` registry covering search, routing, traffic, r
|
|
|
118
120
|
| `clusterIncidents` | Group loaded incidents into hotspots (DBSCAN) with road and category labels, delay totals and trends |
|
|
119
121
|
| `focusIncidents` | Highlight a subset of incidents (by id / category / severity) on the map and dim the rest |
|
|
120
122
|
| `getTrafficAreaAnalytics` | Fetch historical traffic analytics (speed, congestion, travel time) for an area |
|
|
123
|
+
|
|
121
124
|
### Trackers
|
|
122
125
|
|
|
123
126
|
| Tool | Description |
|
|
@@ -164,9 +167,9 @@ const agent = createMapAgent(map, {
|
|
|
164
167
|
| Tool | Description |
|
|
165
168
|
|---|---|
|
|
166
169
|
| `updatePlacesDisplay` | Show, hide, or restyle place entries on the map |
|
|
167
|
-
| `updateRoutesDisplay` | Show, hide, or
|
|
170
|
+
| `updateRoutesDisplay` | Show, hide, or swap route entries, switch the highlighted alternative, fit the camera |
|
|
168
171
|
| `updateWaypointsDisplay` | Show staged waypoint markers without the route line |
|
|
169
|
-
| `updateTrafficAreaAnalyticsDisplay` |
|
|
172
|
+
| `updateTrafficAreaAnalyticsDisplay` | Show, hide, or swap traffic-area-analytics entries |
|
|
170
173
|
| `clearMap` | Remove displayed places, routes, BYOD layers, or all features |
|
|
171
174
|
|
|
172
175
|
### Map control
|
|
@@ -180,15 +183,14 @@ const agent = createMapAgent(map, {
|
|
|
180
183
|
| `setMapStandardStyle` | Switch map style (light, dark, satellite, driving, etc.) |
|
|
181
184
|
| `setLanguage` | Change the language for map labels and API responses |
|
|
182
185
|
| `setGeopoliticalView` | Show disputed borders and territory names from a country's view, for the map and later searches |
|
|
183
|
-
| `setMapStyling` | Set or reset what the base map shows and how it looks, by knob id — layer groups such as 3D buildings, the built-in POI icons and their categories, the live traffic overlays and their filters, the hillshade and 3D terrain, sizes, colours, map presets, or a whole theme from a few colours or an image |
|
|
186
|
+
| `setMapStyling` | Set or reset what the base map shows and how it looks, by knob id — layer groups such as 3D buildings, the built-in POI icons and their categories, the live traffic overlays and their filters, the hillshade and 3D terrain, sizes, colours, map presets, or a whole theme from a few colours or an image — and the look of every layer the agent drew: places, routes and their sections, polygons, reachable areas, area analytics and fetched incidents; the classifier scope lists only the knob families a turn touches |
|
|
184
187
|
|
|
185
188
|
### MapLibre direct access
|
|
186
189
|
|
|
187
190
|
| Tool | Description |
|
|
188
191
|
|---|---|
|
|
189
192
|
| `getMapStyleLayers` | List MapLibre layer IDs with their paint/layout properties |
|
|
190
|
-
| `
|
|
191
|
-
| `setPaintProperties` | Set MapLibre paint properties (colors, widths, opacity) on named layers |
|
|
193
|
+
| `setLayerProperties` | Set MapLibre paint (colors, widths, opacity) and layout (visibility, text, sizes) properties on named layers |
|
|
192
194
|
|
|
193
195
|
### State & recall
|
|
194
196
|
|
|
@@ -334,11 +336,12 @@ createMapAgent(map, { model, tools: fleetTools });
|
|
|
334
336
|
Every tool (built-in or custom) follows the `ToolEntry` interface:
|
|
335
337
|
|
|
336
338
|
```typescript
|
|
337
|
-
type ToolEntry<S extends ToolState = ToolState> = {
|
|
339
|
+
type ToolEntry<S extends ToolState = ToolState, Scope = unknown> = {
|
|
338
340
|
description: string; // Operational contract for the LLM
|
|
339
341
|
inputSchema: z.ZodType; // Zod schema for input validation
|
|
340
342
|
outputSchema?: z.ZodType; // Optional structured output schema
|
|
341
|
-
|
|
343
|
+
// options.signal is the turn's AbortSignal: forward it to the services calls the tool makes
|
|
344
|
+
execute: (input, state: S, options?: ToolExecuteOptions) => Promise<any>;
|
|
342
345
|
|
|
343
346
|
// Classifier metadata (optional)
|
|
344
347
|
classificationPrompt?: string; // One-liner for the intent classifier
|
|
@@ -347,6 +350,12 @@ type ToolEntry<S extends ToolState = ToolState> = {
|
|
|
347
350
|
examplePrompts?: string[]; // Natural language prompt examples
|
|
348
351
|
relatedTools?: string[]; // Tools often used together
|
|
349
352
|
dependsOn?: string[]; // Tools that must run before this one
|
|
353
|
+
scopeSchema?: z.ZodType<Scope>; // Per-turn scope the classifier may emit to narrow the tool
|
|
354
|
+
scopePrompt?: string; // Classifier hint on when and how to scope the tool
|
|
355
|
+
|
|
356
|
+
// Loop control (optional)
|
|
357
|
+
alwaysActive?: boolean; // Visible on every step, whatever the classifier picks
|
|
358
|
+
endsTurnOnCall?: boolean; // Stop the loop on the step that calls this tool
|
|
350
359
|
};
|
|
351
360
|
```
|
|
352
361
|
|
|
@@ -516,8 +525,7 @@ const agent = createMapAgent(map, {
|
|
|
516
525
|
tools: {
|
|
517
526
|
setMapStandardStyle: false,
|
|
518
527
|
setLanguage: false,
|
|
519
|
-
|
|
520
|
-
setPaintProperties: false,
|
|
528
|
+
setLayerProperties: false,
|
|
521
529
|
setMapStyling: false,
|
|
522
530
|
},
|
|
523
531
|
});
|
|
@@ -544,7 +552,8 @@ For the complete, always-current list of exports — factories, tool-registry he
|
|
|
544
552
|
|
|
545
553
|
| Type | Package | Purpose |
|
|
546
554
|
|---|---|---|
|
|
547
|
-
| Peer | `@tomtom-org/maps-sdk` | TomTom Maps SDK (types, services, map modules) |
|
|
555
|
+
| Peer | `@tomtom-org/maps-sdk@>=1.0.0-rc.0 <1.0.0` | TomTom Maps SDK (types, services, map modules) — its 1.0.0 release candidates |
|
|
556
|
+
| Peer | `@tomtom-org/maps-sdk-plugin-map-theme@>=0.3.0` | Theming the map from a few colours or an image in `setMapStyling` |
|
|
548
557
|
| Peer | `ai@^6` | Vercel AI SDK (ToolLoopAgent, tool types) |
|
|
549
558
|
| Peer | `zod@^4` | Schema validation |
|
|
550
559
|
| Peer | `maplibre-gl@^6` | Map rendering engine |
|
|
@@ -564,7 +573,7 @@ For the complete, always-current list of exports — factories, tool-registry he
|
|
|
564
573
|
- [Bring your own data](https://docs.tomtom.com/maps-sdk-js/guides/plugins/agent-toolkit/byod) — ingest customer GeoJSON layers
|
|
565
574
|
- [AI SDK v6 documentation](https://ai-sdk.dev/)
|
|
566
575
|
- [TomTom Maps SDK documentation](https://docs.tomtom.com/maps-sdk-js)
|
|
567
|
-
- [Example application](
|
|
576
|
+
- [Example application](https://docs.tomtom.com/maps-sdk-js/examples/map-traffic-agent-react) — full chat interface implementation
|
|
568
577
|
|
|
569
578
|
## License
|
|
570
579
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseMapModule, CustomGeoJSONLayerSpec, CustomGeoJSONModule, GeometriesModule, GeometryFillStyle, POIsModule, PlaceConnectionDisplay, PlacesModule, PlanningWaypoint, ReachableRangesModule, RoutingModule, StylingFoundationsModule, TerrainModule, TomTomMap, TrafficAreaAnalyticsModule, TrafficAreaAnalyticsModuleConfig, TrafficFlowModule, TrafficIncidentDetailsModule, TrafficIncidentsModule } from "@tomtom-org/maps-sdk/map";
|
|
1
|
+
import { BaseMapModule, CustomGeoJSONLayerSpec, CustomGeoJSONModule, GeometriesModule, GeometryFillStyle, KnobEntry, KnobTarget, POIsModule, PlaceConnectionDisplay, PlacesModule, PlanningWaypoint, ReachableRangesModule, RoutingModule, StylingFoundationsModule, TerrainModule, TomTomMap, TrafficAreaAnalyticsModule, TrafficAreaAnalyticsModuleConfig, TrafficFlowModule, TrafficIncidentDetailsModule, TrafficIncidentsModule } from "@tomtom-org/maps-sdk/map";
|
|
2
2
|
import { BBox, CommonPlaceProps, GeographyType, Place, Places, PolygonFeature, PolygonFeatures, ReachableRangeBudget, Route, Routes, TrafficAreaAnalytics, TrafficIncident, WaypointLike } from "@tomtom-org/maps-sdk/core";
|
|
3
3
|
import { ChartConfiguration } from "chart.js";
|
|
4
4
|
import { Map as Map$1 } from "maplibre-gl";
|
|
@@ -719,6 +719,38 @@ declare class BaseMapState implements StateSlice {
|
|
|
719
719
|
reset(): void;
|
|
720
720
|
}
|
|
721
721
|
//#endregion
|
|
722
|
+
//#region src/state/slice-knobs.d.ts
|
|
723
|
+
/**
|
|
724
|
+
* The knobs set on every module of one kind a slice holds: the modules it holds now, and each one
|
|
725
|
+
* it creates later through {@link SliceKnobs.applyTo}. `setMapStyling` sets the knobs of the
|
|
726
|
+
* places, routes, geometries, ranges and traffic modules the agent drew through it.
|
|
727
|
+
*
|
|
728
|
+
* @group Agent Toolkit
|
|
729
|
+
*/
|
|
730
|
+
declare class SliceKnobs {
|
|
731
|
+
readonly catalogue: readonly KnobEntry<string>[];
|
|
732
|
+
private readonly modules;
|
|
733
|
+
private readonly _values;
|
|
734
|
+
/**
|
|
735
|
+
* @param catalogue - The catalogue of the module kind, e.g. `routingKnobCatalogue`.
|
|
736
|
+
* @param modules - The modules of that kind the slice holds now.
|
|
737
|
+
*/
|
|
738
|
+
constructor(catalogue: readonly KnobEntry<string>[], modules: () => Iterable<KnobTarget<unknown>>);
|
|
739
|
+
/** Every knob set, by its id in the catalogue. */
|
|
740
|
+
get values(): Readonly<Record<string, unknown>>;
|
|
741
|
+
/** Sets the knob on every module, and remembers it for those created later. Throws on an invalid value. */
|
|
742
|
+
set(id: string, value: unknown): void;
|
|
743
|
+
/** Resets the knob on every module to its default, and forgets it. */
|
|
744
|
+
reset(id: string): void;
|
|
745
|
+
/** Resets every knob set. */
|
|
746
|
+
resetAll(): void;
|
|
747
|
+
/** Forgets every knob set without touching the modules, for a slice dropping them. */
|
|
748
|
+
clear(): void;
|
|
749
|
+
/** Sets every knob remembered on a module the slice just created, and returns it. */
|
|
750
|
+
applyTo<MODULE extends KnobTarget<unknown>>(module: MODULE): MODULE;
|
|
751
|
+
private _knob;
|
|
752
|
+
}
|
|
753
|
+
//#endregion
|
|
722
754
|
//#region src/tools/shared/agent-headers.d.ts
|
|
723
755
|
/**
|
|
724
756
|
* @module agent-toolkit-tools
|
|
@@ -1193,6 +1225,10 @@ declare class PlacesState implements StateSlice {
|
|
|
1193
1225
|
private _entryMode;
|
|
1194
1226
|
/** The state change events, listed in {@link PlacesStateEvents}. */
|
|
1195
1227
|
readonly events: StateEvents<PlacesStateEvents>;
|
|
1228
|
+
/** The knobs set on every entry's PlacesModule, such as `color` and `label.size`. Cleared on `reset`. */
|
|
1229
|
+
readonly knobs: SliceKnobs;
|
|
1230
|
+
/** The knobs set on every entry's boundary GeometriesModule. Cleared on `reset`. */
|
|
1231
|
+
readonly geometriesKnobs: SliceKnobs;
|
|
1196
1232
|
constructor(_ttMap: TomTomMap);
|
|
1197
1233
|
/**
|
|
1198
1234
|
* The display policy. `multiple` (default) keeps every history entry available to render
|
|
@@ -1214,8 +1250,8 @@ declare class PlacesState implements StateSlice {
|
|
|
1214
1250
|
getEntryPlacesModule(entryId: string, markerType: PlacesMarkerType): Promise<PlacesModule>;
|
|
1215
1251
|
/**
|
|
1216
1252
|
* Returns the entry's place-geometries module for POI footprints and municipality outlines,
|
|
1217
|
-
* created on first call.
|
|
1218
|
-
* unknown entry id.
|
|
1253
|
+
* created on first call. Updates only the fill style when it changes, keeping the styling
|
|
1254
|
+
* applied since. Throws on an unknown entry id.
|
|
1219
1255
|
*/
|
|
1220
1256
|
getEntryGeometriesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<GeometriesModule>;
|
|
1221
1257
|
private _requireEntry;
|
|
@@ -1430,6 +1466,12 @@ declare class RangeState implements ShownEntriesSlice {
|
|
|
1430
1466
|
private _entryMode;
|
|
1431
1467
|
/** The state change events, listed in {@link RangeStateEvents}. */
|
|
1432
1468
|
readonly events: StateEvents<RangeStateEvents>;
|
|
1469
|
+
/** The knobs set on every entry's ReachableRangesModule, such as `fill.opacity`. Cleared on `reset`. */
|
|
1470
|
+
readonly knobs: SliceKnobs;
|
|
1471
|
+
/** The knobs set on every entry's GeometriesModule, the one drawing in a style of your own. Cleared on `reset`. */
|
|
1472
|
+
readonly geometriesKnobs: SliceKnobs;
|
|
1473
|
+
/** The knobs set on every entry's origin-pin PlacesModule. Cleared on `reset`. */
|
|
1474
|
+
readonly placesKnobs: SliceKnobs;
|
|
1433
1475
|
constructor(_ttMap: TomTomMap);
|
|
1434
1476
|
/** Set of ranges-entry ids currently rendered on the map. */
|
|
1435
1477
|
get shownEntryIds(): ReadonlySet<string>;
|
|
@@ -1705,12 +1747,8 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1705
1747
|
private _planningSlots;
|
|
1706
1748
|
private _params;
|
|
1707
1749
|
private _entryMode;
|
|
1708
|
-
/**
|
|
1709
|
-
|
|
1710
|
-
* across entry swaps so the rendered route always uses the most recently requested color.
|
|
1711
|
-
* Set via {@link setColor}; persists for the lifetime of the slice (cleared on `reset`).
|
|
1712
|
-
*/
|
|
1713
|
-
private _color?;
|
|
1750
|
+
/** The knobs set on every entry's RoutingModule, `color` and `widthFactor` among them. Cleared on `reset`. */
|
|
1751
|
+
readonly knobs: SliceKnobs;
|
|
1714
1752
|
/**
|
|
1715
1753
|
* The most recently `.showEntry`-ed id. Tracks "who was last brought up" so tools that
|
|
1716
1754
|
* operate on the focused module have a single pointer to read; the authoritative shown
|
|
@@ -1754,15 +1792,6 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1754
1792
|
showWaypoints?: boolean;
|
|
1755
1793
|
showSummaryBubbles?: boolean;
|
|
1756
1794
|
}): Promise<void>;
|
|
1757
|
-
/** The slice-level route colour, persisted across entry swaps. Undefined if none was set. */
|
|
1758
|
-
get color(): string | undefined;
|
|
1759
|
-
/**
|
|
1760
|
-
* Sets the slice-level route colour. It applies immediately to every shown entry's
|
|
1761
|
-
* RoutingModule, and later {@link showEntry} calls apply it automatically. Pass `undefined` to
|
|
1762
|
-
* clear the sticky colour. Shown modules then keep their last paint until they're re-shown,
|
|
1763
|
-
* and MapLibre style restore handles the full revert.
|
|
1764
|
-
*/
|
|
1765
|
-
setColor(color: string | undefined): void;
|
|
1766
1795
|
/**
|
|
1767
1796
|
* Hides the entry's routes and waypoints by clearing its module, which stays cached.
|
|
1768
1797
|
* Does nothing if the entry is unknown or already hidden.
|
|
@@ -2046,6 +2075,12 @@ declare class TrafficAreaAnalyticsState implements ShownEntriesSlice, StateSlice
|
|
|
2046
2075
|
private _entryMode;
|
|
2047
2076
|
/** The state change events, listed in {@link TrafficAreaAnalyticsStateEvents}. */
|
|
2048
2077
|
readonly events: StateEvents<TrafficAreaAnalyticsStateEvents>;
|
|
2078
|
+
/**
|
|
2079
|
+
* The knobs set on every entry's TrafficAreaAnalyticsModule, such as `displayMode` and
|
|
2080
|
+
* `metrics.congestionLevel.palette`. An entry that did not fetch the `activeMetric` set shows
|
|
2081
|
+
* the first metric it fetched. Cleared on `reset`.
|
|
2082
|
+
*/
|
|
2083
|
+
readonly knobs: SliceKnobs;
|
|
2049
2084
|
constructor(_ttMap: TomTomMap);
|
|
2050
2085
|
get entries(): readonly TrafficAreaAnalyticsEntry[];
|
|
2051
2086
|
get latestEntry(): TrafficAreaAnalyticsEntry | undefined;
|
|
@@ -2414,6 +2449,8 @@ declare class TrafficIncidentsState implements StateSlice {
|
|
|
2414
2449
|
private readonly _clusters;
|
|
2415
2450
|
/** The state change events, listed in {@link TrafficIncidentsStateEvents}. */
|
|
2416
2451
|
readonly events: StateEvents<TrafficIncidentsStateEvents>;
|
|
2452
|
+
/** The knobs set on every entry's TrafficIncidentDetailsModule. Cleared on `reset`. */
|
|
2453
|
+
readonly knobs: SliceKnobs;
|
|
2417
2454
|
constructor(_ttMap: TomTomMap);
|
|
2418
2455
|
get entries(): readonly TrafficIncidentsEntry[];
|
|
2419
2456
|
/**
|
|
@@ -3408,8 +3445,6 @@ type CustomGeometriesEntry = BaseEntry<PolygonFeature[]> & {
|
|
|
3408
3445
|
* module. Lazy-initialised via CustomGeometriesState helpers.
|
|
3409
3446
|
*/
|
|
3410
3447
|
_module?: GeometriesModule;
|
|
3411
|
-
/** Fill style that the geometries module is currently configured with. */
|
|
3412
|
-
_shownFillStyle?: GeometryFillStyle;
|
|
3413
3448
|
/** True while this entry's `_module` is rendering on the map. */
|
|
3414
3449
|
_shown?: boolean;
|
|
3415
3450
|
};
|
|
@@ -3452,6 +3487,8 @@ declare class CustomGeometriesState implements ShownEntriesSlice, StateSlice {
|
|
|
3452
3487
|
private _entryMode;
|
|
3453
3488
|
/** The state change events, listed in {@link CustomGeometriesStateEvents}. */
|
|
3454
3489
|
readonly events: StateEvents<CustomGeometriesStateEvents>;
|
|
3490
|
+
/** The knobs set on every entry's GeometriesModule, such as `line.width`. Cleared on `reset`. */
|
|
3491
|
+
readonly knobs: SliceKnobs;
|
|
3455
3492
|
constructor(_ttMap: TomTomMap);
|
|
3456
3493
|
get entries(): readonly CustomGeometriesEntry[];
|
|
3457
3494
|
get latestEntry(): CustomGeometriesEntry | undefined;
|
|
@@ -3470,7 +3507,10 @@ declare class CustomGeometriesState implements ShownEntriesSlice, StateSlice {
|
|
|
3470
3507
|
* suffix (`-2`, `-3`, ...). In `single` mode the new entry replaces every older one.
|
|
3471
3508
|
*/
|
|
3472
3509
|
addEntry(features: PolygonFeature<CommonPlaceProps>[], provenance: CustomGeometriesEntry['provenance'], label: string, explicitId?: string): Promise<string>;
|
|
3473
|
-
/**
|
|
3510
|
+
/**
|
|
3511
|
+
* Initialises the entry's GeometriesModule lazily. Updates only the fill style when it changes,
|
|
3512
|
+
* keeping the styling applied since.
|
|
3513
|
+
*/
|
|
3474
3514
|
getEntryGeometriesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<GeometriesModule>;
|
|
3475
3515
|
/**
|
|
3476
3516
|
* Renders the entry's polygons. `mode` applies to this entry's own layer only:
|
|
@@ -3961,8 +4001,7 @@ export declare const DEFAULT_TOOLS: {
|
|
|
3961
4001
|
setGeopoliticalView: ToolDefinition;
|
|
3962
4002
|
setMapStyling: ToolDefinition;
|
|
3963
4003
|
getMapStyleLayers: ToolDefinition;
|
|
3964
|
-
|
|
3965
|
-
setPaintProperties: ToolDefinition;
|
|
4004
|
+
setLayerProperties: ToolDefinition;
|
|
3966
4005
|
setPitchBearing: ToolDefinition;
|
|
3967
4006
|
zoomInOrOut: ToolDefinition;
|
|
3968
4007
|
executeMaplibreCode: ToolDefinition;
|