@tomtom-org/maps-sdk-plugin-agent-toolkit 0.2.7 → 0.2.11

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 CHANGED
@@ -4,7 +4,7 @@ A headless conversational agent that gives Large Language Models tool-based cont
4
4
 
5
5
  No UI is included — bring your own chat interface. No LLM provider is bundled — supply any AI SDK-compatible model.
6
6
 
7
- > **Full documentation** — guides, architecture diagrams, and tutorials are available at [docs.tomtom.com](https://docs.tomtom.com/maps-sdk-js/guides/plugins/agent-toolkit).
7
+ > **Full documentation** — guides, architecture diagrams, and tutorials are available at [docs.tomtom.com](https://docs.tomtom.com/maps-sdk-js/guides/plugins/agent-toolkit/overview).
8
8
 
9
9
  ## Installation
10
10
 
@@ -49,8 +49,7 @@ console.log(result.text);
49
49
  ### With React (`useChat`)
50
50
 
51
51
  ```typescript
52
- import { DirectChatTransport } from 'ai/react';
53
- import { useChat } from 'ai/react';
52
+ import { DirectChatTransport, useChat } from 'ai/react';
54
53
 
55
54
  const agent = createMapAgent(map, { model: openai('gpt-4o') });
56
55
 
@@ -74,89 +73,113 @@ See [`examples/map-chat-agent`](../../examples/map-chat-agent) for a full workin
74
73
 
75
74
  ## Tools reference
76
75
 
77
- The plugin ships 52 tools organized into five categories. All tools are included by default and can be individually removed or replaced via the [`tools` option](#composing-tool-sets).
76
+ The plugin ships a `DEFAULT_TOOLS` registry covering search, routing, traffic, reachable areas, BYOD GeoJSON, base-map control, MapLibre access, and code-generated analysis. All tools are included by default and can be individually removed or replaced via the [`tools` option](#composing-tool-sets). The full per-tool reference lives in the [Agent Toolkit guide](https://docs.tomtom.com/maps-sdk-js/guides/plugins/agent-toolkit/tools).
78
77
 
79
- ### Service tools — fetch data from TomTom APIs
78
+ ### Location & search
80
79
 
81
80
  | Tool | Description |
82
81
  |---|---|
83
82
  | `locatePlace` | Resolve a location string (landmark, city, address) to a place; optionally stage as a waypoint |
84
83
  | `reverseGeocode` | Convert `[longitude, latitude]` coordinates to an address |
85
84
  | `discoverPlaces` | Search for places by text query or POI category within an area |
85
+ | `getPOICategoryCodes` | Look up TomTom POI category codes from natural-language names |
86
+ | `getCurrentLocation` | Get the user's physical GPS location from the browser |
87
+ | `getViewport` | Get current map center, zoom, and bounding box |
88
+
89
+ ### Routing & reachable areas
90
+
91
+ | Tool | Description |
92
+ |---|---|
86
93
  | `setRoute` | Calculate or recalculate a route — provide `locations` (waypoints), `parameters` (route options), or both |
87
94
  | `addWaypointsToRoute` | Extend the current route — prepend a new origin, append a new destination, and/or insert intermediate stops |
88
95
  | `removeWaypointsFromRoute` | Remove one or more waypoints by index from the current route |
89
96
  | `replaceWaypointInRoute` | Overwrite a single waypoint of the current route in place — origin, destination, or by index |
90
- | `getPOICategoryCodes` | Look up TomTom POI category codes from natural-language names |
91
- | `getTrafficIncidents` | Fetch traffic incidents by bounding box or IDs (one-shot) |
92
- | `startTrafficIncidentsMonitor` | Start the live incident monitor — pairs with `getTrafficIncidents`, refreshes incident state on a configurable cadence so subsequent reads stay fresh |
97
+ | `getCurrentWaypoints` | Get the staged waypoint slots (origin, stops, destination) |
98
+ | `findReachableAreas` | Calculate isochrone/isodistance polygons from one or more origins |
99
+
100
+ ### Traffic
101
+
102
+ | Tool | Description |
103
+ |---|---|
104
+ | `getTrafficIncidents` | Fetch traffic incidents within an area (viewport, named place, route corridor, polygon, IDs) |
105
+ | `startTrafficIncidentsMonitor` | Start a live monitor that refreshes incident state on a configurable cadence |
93
106
  | `stopTrafficIncidentsMonitor` | Stop the live incident monitor |
94
- | `analyseIncidents` | Aggregate / count / chart incidents already in state via dynamic JS (categories, top delays, clusters, …) |
95
107
  | `focusIncidents` | Highlight a subset of incidents (by id / category / severity) on the map and dim the rest |
96
108
  | `getTrafficAreaAnalytics` | Fetch historical traffic analytics (speed, congestion, travel time) for an area |
97
109
  | `queryTrafficAnalytics` | Query cached analytics data or check what is currently displayed |
98
- | `searchAlongRoute` | Search for POIs along a calculated route, ranked by detour cost |
99
- | `findReachableArea` | Calculate isochrone/isodistance polygons from a point |
110
+ | `toggleTilesTrafficFlow` | Toggle the real-time traffic-flow tile overlay |
111
+ | `toggleTilesTrafficIncidents` | Toggle the real-time traffic-incidents tile overlay |
112
+ | `getShownTileIncidents` | List real-time incidents visible in the current viewport |
100
113
 
101
- ### TomTom Map tools — render and inspect map state
114
+ ### Bring-your-own-data (BYOD)
102
115
 
103
116
  | Tool | Description |
104
117
  |---|---|
105
- | `showPlaces` | Display the most recent place results as markers on the map |
106
- | `showRoute` | Render the most recently calculated route and fit the camera |
107
- | `showTrafficAreaAnalytics` | Visualize traffic analytics as hexgrid, heatmap, or tiles |
108
- | `showWaypoints` | Display staged waypoint markers without the route line |
109
- | `clearMap` | Remove displayed places, routes, or all features |
110
- | `getShownPlaces` | List places currently displayed on the map |
111
- | `getShownRoutes` | List routes currently rendered on the map |
112
- | `getShownWaypoints` | List waypoint markers currently shown |
113
- | `getShownRouteSections` | List sections (toll, country, motorway, etc.) of the shown route |
114
- | `getShownRouteTrafficIncidents` | List traffic incidents overlaid on the shown route |
115
- | `getShownIncidents` | List real-time incidents visible in the current viewport |
118
+ | `addByodLayer` | Ingest a customer-authored GeoJSON layer from a URL or inline `FeatureCollection` |
119
+ | `recallByod` | List BYOD entries, or retrieve a single entry's full `FeatureCollection` by id |
120
+ | `updateByodDisplay` | Show, hide, or clear BYOD layers on the map |
121
+
122
+ ### Unified data tools — scope-aware code generation
123
+
124
+ | Tool | Description |
125
+ |---|---|
126
+ | `analyseData` | Aggregate / chart entries (`places`, `routes`, `incidents`, `geometries`, `trafficAreaAnalytics`, `byod`) via dynamic JS; classifier-emitted scope narrows the schema per turn |
127
+ | `processData` | Transform entries into new `places`, `placeConnections`, `geometries`, `byod`, or a `fitOnMap` camera move via dynamic JS |
128
+ | `executeMaplibreCode` | Execute arbitrary MapLibre JS against the live `Map` instance — escape hatch for custom layers, animations, raster overlays |
129
+
130
+ > See the [Code generation](https://docs.tomtom.com/maps-sdk-js/guides/plugins/agent-toolkit/tools#code-generation) section of the guide for the threat model — these tools have no sandbox.
131
+
132
+ ### Map display
133
+
134
+ | Tool | Description |
135
+ |---|---|
136
+ | `updatePlacesDisplay` | Show, hide, or restyle place entries on the map |
137
+ | `updateRoutesDisplay` | Show, hide, or restyle route entries (line color, waypoint icons, fit camera) |
138
+ | `updateWaypointsDisplay` | Show staged waypoint markers without the route line |
139
+ | `updateTrafficAreaAnalyticsDisplay` | Visualize traffic-area-analytics as hexgrid, heatmap, or tiles |
140
+ | `clearMap` | Remove displayed places, routes, BYOD layers, or all features |
141
+
142
+ ### Map control
143
+
144
+ | Tool | Description |
145
+ |---|---|
146
+ | `flyTo` | Move the camera to a position or bounding box |
147
+ | `zoomInOrOut` | Adjust the zoom level by a delta |
148
+ | `setPitchBearing` | Tilt (pitch) and/or rotate (bearing) the camera |
116
149
  | `getStandardMapStyles` | List available standard map style presets |
117
150
  | `setMapStandardStyle` | Switch map style (light, dark, satellite, driving, etc.) |
118
- | `setRouteTheme` | Color the route line and waypoint icons |
119
151
  | `setLanguage` | Change the language for map labels and API responses |
120
- | `toggleBaseMapLayerGroups` | Show/hide named layer groups (buildings3D, roadLabels, water, etc.) |
121
- | `togglePOIs` | Show/hide built-in map POI icons with optional category filtering |
122
- | `toggleTrafficFlow` | Toggle real-time traffic flow overlay |
123
- | `toggleTrafficIncidents` | Toggle real-time traffic incident markers |
124
- | `fitRouteSection` | Fit the camera to a specific route section by type and ID |
152
+ | `toggleTilesBaseMapLayerGroups` | Show/hide named layer groups (buildings3D, roadLabels, water, etc.) |
153
+ | `toggleTilesPOIs` | Show/hide built-in map POI icons with optional category filtering |
125
154
 
126
- ### MapLibre tools — direct map engine access
155
+ ### MapLibre direct access
127
156
 
128
157
  | Tool | Description |
129
158
  |---|---|
130
- | `flyTo` | Move the camera to a position or bounding box |
131
- | `getViewport` | Get current map center, zoom, and bounding box |
132
159
  | `getMapStyleLayers` | List MapLibre layer IDs with their paint/layout properties |
133
160
  | `setLayoutProperties` | Set MapLibre layout properties on named layers |
134
161
  | `setPaintProperties` | Set MapLibre paint properties (colors, widths, opacity) on named layers |
135
- | `setPitchBearing` | Tilt (pitch) and/or rotate (bearing) the camera |
136
- | `zoomInOrOut` | Adjust the zoom level by a delta |
137
- | `executeMaplibreCode` | Execute arbitrary MapLibre JS code for maximum flexibility |
138
162
 
139
- ### State tools — recall session history
163
+ ### State & recall
140
164
 
141
165
  | Tool | Description |
142
166
  |---|---|
143
167
  | `recallPlaces` | Retrieve the history of place lookups from this session |
144
168
  | `recallRoutes` | Retrieve previously calculated routes from this session |
145
- | `recallRanges` | Retrieve stored reachable range results |
146
- | `recallGeometries` | List/inspect every polygon source in state (place footprints, isochrones, custom-geometries) — call before passing IDs to `processGeometries` / `analyseGeometries` |
147
- | `getCurrentWaypoints` | Get the staged waypoint slots (origin, stops, destination) |
169
+ | `recallRanges` | Retrieve stored reachable-range results |
170
+ | `recallGeometries` | Look up polygon sources by `{ kind, id }` across place footprints, isochrones, and `customGeometries` entries |
171
+ | `recallByod` | Retrieve BYOD entries (see [BYOD](#bring-your-own-data-byod)) |
172
+ | `recallState` | Summarize the current contents of every state slice |
173
+ | `setEntryMode` | Switch a slice between `multiple` (default) and `single` entry modes |
174
+ | `resetState` | Reset one or all state slices |
148
175
 
149
- ### Utility tools — pure computation helpers
176
+ ### Utilities
150
177
 
151
178
  | Tool | Description |
152
179
  |---|---|
153
180
  | `calculateBBox` | Compute a bounding box from GeoJSON features or tool results |
154
181
  | `formatDistance` | Format meters into a human-readable string (e.g. "2.5 km") |
155
182
  | `formatDuration` | Format seconds into a human-readable string (e.g. "1 h 30 min") |
156
- | `getCurrentLocation` | Get the user's physical GPS location from the browser |
157
- | `getRouteProgress` | Get the position along the route at a given time or distance |
158
- | `getSectionProgress` | Get the distance and travel time for route sections by type |
159
- | `getSectionBBox` | Get the bounding box of a specific route section |
160
183
  | `help` | List available capabilities in summary or searchable detail mode |
161
184
 
162
185
  ## Customization
@@ -188,6 +211,14 @@ const agent = createMapAgent<MyState>(map, {
188
211
  // Custom state slices — only custom fields needed, built-in slices are created automatically
189
212
  state: { fleet: new FleetState() },
190
213
 
214
+ // Per-kind data-entry config. `enabled: false` removes the kind from the tool surface
215
+ // (drops its recall/display/fetch tools and the kind from analyseData/processData scope).
216
+ // `entryMode` switches the slice between 'multiple' (default) and 'single' (latest only).
217
+ dataEntries: {
218
+ routes: { entryMode: 'single' },
219
+ byod: { enabled: false },
220
+ },
221
+
191
222
  // Intent classifier: omit for default LLM-based, false to disable
192
223
  classifier: createDefaultClassifier({ model: openai('gpt-4o-mini') }),
193
224
 
@@ -202,6 +233,20 @@ const agent = createMapAgent<MyState>(map, {
202
233
 
203
234
  // Max tool-loop iterations (default: 10)
204
235
  maxSteps: 15,
236
+
237
+ // Opt into experimental features (subject to change without notice)
238
+ featureFlags: { experimentalSearch: true },
239
+
240
+ // Provider-specific options forwarded to the AI SDK on every step
241
+ providerOptions: {
242
+ openai: { reasoningEffort: 'low', reasoningSummary: 'auto' },
243
+ },
244
+
245
+ // Per-step providerOptions override — e.g. bump reasoning only on code-exec turns
246
+ stepProviderOptions: ({ activeTools }) =>
247
+ activeTools?.includes('processData')
248
+ ? { openai: { reasoningEffort: 'medium' } }
249
+ : undefined,
205
250
  });
206
251
  ```
207
252
 
@@ -253,7 +298,7 @@ const fleetTools = {
253
298
  return { vehicleId, position };
254
299
  },
255
300
  tags: ['fleet'],
256
- relatedTools: ['showPlaces'],
301
+ relatedTools: ['updatePlacesDisplay'],
257
302
  },
258
303
  } satisfies Record<string, ToolEntry>;
259
304
 
@@ -289,29 +334,15 @@ type ToolEntry<S extends ToolState = ToolState> = {
289
334
  - `PlacesState` — place / geometry entry history
290
335
  - `RoutingState` — route history, planning waypoint slots, route parameters
291
336
  - `RangeState` — reachable-range entries
292
- - `CustomGeometriesState` — derived polygon entries produced by `processGeometries` (union, difference, h3-coverage, …)
337
+ - `CustomGeometriesState` — derived polygon entries produced by `processData` (union, difference, h3-coverage, …)
338
+ - `BYODState` — bring-your-own-data GeoJSON layer entries
293
339
  - `BaseMapState` — viewport, style, language, raw `mapLibreMap`
294
340
  - `TrafficTilesState` — real-time traffic flow + incident tile-overlay visibility
295
- - `TrafficAreaAnalyticsState` — cached traffic-area-analytics result + current visualisation config
296
- - `TrafficIncidentsState` — fetched incident entries, per-entry analyses, focused subsets, and the live `IncidentsMonitor`
341
+ - `TrafficAreaAnalyticsState` — historical traffic-area-analytics entries and per-entry visualisation
342
+ - `TrafficIncidentsState` — fetched incident entries, registered analyses, focused subsets, and the optional polling monitor
297
343
  - `MapPOIsState` — POI category visibility and filters
298
344
 
299
- Create state manually for advanced scenarios:
300
-
301
- ```typescript
302
- import { createToolState, type ToolState } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
303
-
304
- // Base state
305
- const state = createToolState(map);
306
-
307
- // With custom slices
308
- const state = createToolState(map, {
309
- fleet: new FleetState(),
310
- weather: new WeatherCache(),
311
- });
312
- ```
313
-
314
- Custom slices are merged alongside built-in state. When using `createMapAgent`, define an interface extending `ToolState` and pass the type parameter — only custom slices need to be provided:
345
+ Built-in slices are constructed automatically by `createMapAgent`. To add custom slices, define an interface extending `ToolState` and pass the type parameter — only the custom fields need to be provided:
315
346
 
316
347
  ```typescript
317
348
  interface MyState extends ToolState {
@@ -324,7 +355,7 @@ const agent = createMapAgent<MyState>(map, {
324
355
  });
325
356
 
326
357
  agent.state.fleet; // FleetState — custom slice
327
- agent.state.places; // PlacesStates — registry of named place-display buckets
358
+ agent.state.places; // PlacesState — append-only history of place entries
328
359
  ```
329
360
 
330
361
  ## Intent classifier
@@ -374,38 +405,6 @@ const agent = createMapAgent(map, {
374
405
 
375
406
  ## Advanced usage
376
407
 
377
- ### Manual agent setup
378
-
379
- Bypass `createMapAgent` for maximum control:
380
-
381
- ```typescript
382
- import { ToolLoopAgent, stepCountIs, tool } from 'ai';
383
- import { createToolState, DEFAULT_TOOLS, BASE_SYSTEM_PROMPT } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
384
-
385
- const state = createToolState(map);
386
- const { help, ...toolEntries } = DEFAULT_TOOLS; // customize as needed
387
-
388
- // Convert ToolEntry records to AI SDK tools (bind state)
389
- const tools = Object.fromEntries(
390
- Object.entries(toolEntries).map(([name, entry]) => [
391
- name,
392
- tool({
393
- description: entry.description,
394
- inputSchema: entry.inputSchema,
395
- outputSchema: entry.outputSchema,
396
- execute: async (input) => entry.execute(input, state),
397
- }),
398
- ]),
399
- );
400
-
401
- const agent = new ToolLoopAgent({
402
- model: openai('gpt-4o'),
403
- tools,
404
- instructions: BASE_SYSTEM_PROMPT + '\n\nCustom instructions...',
405
- stopWhen: stepCountIs(15),
406
- });
407
- ```
408
-
409
408
  ### Wrapping default tools
410
409
 
411
410
  Add logging, analytics, or custom behavior around existing tools:
@@ -439,7 +438,6 @@ const agent = createMapAgent(map, {
439
438
  removeWaypointsFromRoute: false,
440
439
  replaceWaypointInRoute: false,
441
440
  updateRoutesDisplay: false,
442
- searchAlongRoute: false,
443
441
  },
444
442
  });
445
443
  ```
@@ -454,7 +452,7 @@ const agent = createMapAgent(map, {
454
452
  setLanguage: false,
455
453
  setLayoutProperties: false,
456
454
  setPaintProperties: false,
457
- toggleBaseMapLayerGroups: false,
455
+ toggleTilesBaseMapLayerGroups: false,
458
456
  },
459
457
  });
460
458
  ```
@@ -474,39 +472,75 @@ agent.destroy(); // Reset all state slices (call on unmount)
474
472
 
475
473
  ```typescript
476
474
  // Main factory
477
- export { createMapAgent } from './create-map-agent';
475
+ export { createMapAgent } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
478
476
 
479
- // State
480
- export { createToolState, type StateSlice } from './state';
477
+ // Tool registry and composition
478
+ export {
479
+ DEFAULT_TOOLS,
480
+ getDefaultToolPrompts,
481
+ resolveTools,
482
+ TOOL_NAMES,
483
+ type ToolName,
484
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
481
485
 
482
486
  // System prompt
483
- export { BASE_SYSTEM_PROMPT, buildSystemPrompt } from './system-prompt';
487
+ export { BASE_SYSTEM_PROMPT } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
484
488
 
485
- // Tool registry
486
- export { DEFAULT_TOOLS, TOOL_NAMES, type ToolName } from './tools';
489
+ // Data-entry & entry-mode introspection
490
+ export {
491
+ DATA_ENTRY_KIND_TO_SLICE,
492
+ ENTRY_MODE_SLICE_NAMES,
493
+ TOOLS_BY_DATA_ENTRY_KIND,
494
+ type DataEntryConfig,
495
+ type DataEntryKind,
496
+ type EntryDataKind,
497
+ type EntryMode,
498
+ type EntryModeSlice,
499
+ type EntryModeSliceName,
500
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
501
+
502
+ // Geometries id schema (tagged `{ kind, id }` accepted by analyseData/processData)
503
+ export {
504
+ geometriesIdSchema,
505
+ type GeometriesId,
506
+ type GeometriesIdKind,
507
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
487
508
 
488
- // Tool composition
489
- export { resolveTools } from './resolve-tools';
509
+ // State digest (for dev panels / debug UIs)
510
+ export {
511
+ formatStateDigestDiff,
512
+ getStateDigest,
513
+ type StateDigest,
514
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
490
515
 
491
516
  // Classifier
492
517
  export {
493
- type ClassificationResult,
494
518
  classifyUserIntent,
495
519
  createDefaultClassifier,
496
520
  extractLastUserText,
497
- } from './utils/intent-classifier';
521
+ type ClassificationResult,
522
+ type Classifier,
523
+ type ClassifierContext,
524
+ type ClassifierOptions,
525
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
498
526
 
499
- // Types
527
+ // Traffic-incidents monitor types
500
528
  export type {
501
- Classifier,
502
- ClassifierContext,
503
- MapAgentInstance,
504
- MapAgentOptions,
505
- ToolEntry,
506
- ToolMetadata,
507
- ToolNameHint,
508
- ToolState,
509
- } from './types';
529
+ IncidentSnapshot,
530
+ MonitoredArea,
531
+ PollingStatus,
532
+ } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
533
+
534
+ // Core types — `StateSlice`, `ToolState`, `MapAgentOptions`, `MapAgentInstance`,
535
+ // `ToolEntry`, `ToolEntryBuilder`, `ToolDefinition`, `ToolBuildOptions`,
536
+ // `ToolMetadata`, `ToolName`, `ToolNameHint`, `FeatureFlags`, entry/analysis
537
+ // types (`PlacesEntry`, `PlacesAnalysis`, `RoutesEntry`, `RoutesAnalysis`,
538
+ // `BYODEntry`, `BYODSource`, `CustomGeometriesEntry`, `CustomGeometriesAnalysis`,
539
+ // `GeometryProvenance`, `RangesEntry`, `ReachableRange`, `RouteParams`,
540
+ // `TrafficAreaAnalyticsEntry`, `TrafficAreaAnalyticsAnalysis`,
541
+ // `TrafficAreaAnalyticsParams`, `TrafficIncidentsEntry`, `IncidentsAnalysis`),
542
+ // and more.
543
+ export type * from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
510
544
  ```
511
545
 
512
546
  ## Dependencies