@tomtom-org/maps-sdk-plugin-agent-toolkit 0.13.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/LICENSE.txt +4 -4
- package/README.md +38 -23
- package/THIRD_PARTY.txt +1 -1
- package/dist/THIRD_PARTY.txt +1 -1
- package/dist/index.d.ts +787 -751
- package/dist/index.es.js +2 -2
- package/dist/third-party.json +1 -1
- package/dist/worker-libs-CUm6Y1-t.js +1 -2
- package/package.json +7 -6
- package/dist/index.es.js.map +0 -1
- package/dist/worker-libs-CUm6Y1-t.js.map +0 -1
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";
|
|
@@ -10,7 +10,7 @@ import { LanguageModel, ModelMessage, PrepareStepFunction, ToolLoopAgent } from
|
|
|
10
10
|
type JobSpec = {
|
|
11
11
|
/** Ids of every entry this job reads. The engine re-runs the job when any of them changes. */
|
|
12
12
|
affectedEntryIds: readonly string[];
|
|
13
|
-
/** The recipe, opaque to the engine
|
|
13
|
+
/** The recipe, opaque to the engine and the single home of the code, compared on re-arm to detect change. */
|
|
14
14
|
code: string;
|
|
15
15
|
/** Whether the engine scans this job. A paused job (`false`) is retained but never run. */
|
|
16
16
|
active: boolean;
|
|
@@ -21,20 +21,20 @@ type JobSpec = {
|
|
|
21
21
|
};
|
|
22
22
|
/** A registered job, handed back to the owner as the reference linking a sink record to its recurrence. */
|
|
23
23
|
interface Job {
|
|
24
|
-
/** Ids of every entry this job reads (immutable
|
|
24
|
+
/** Ids of every entry this job reads (immutable, as a re-arm with different sources is a different job). */
|
|
25
25
|
readonly affectedEntryIds: readonly string[];
|
|
26
|
-
/** The recipe behind this job
|
|
26
|
+
/** The recipe behind this job, which a re-arm compares to decide whether to drop stale history. */
|
|
27
27
|
readonly code: string;
|
|
28
28
|
/** Whether the engine currently scans this job. */
|
|
29
29
|
readonly active: boolean;
|
|
30
|
-
/**
|
|
30
|
+
/** Pauses (`false`) or resumes (`true`) scanning. A paused job keeps its recipe for later promotion. */
|
|
31
31
|
setActive(active: boolean): void;
|
|
32
|
-
/**
|
|
32
|
+
/** Removes the job from the engine. The owner drops its stored reference. */
|
|
33
33
|
unregister(): void;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Session-level recurrence engine
|
|
37
|
-
*
|
|
36
|
+
* Session-level recurrence engine, held on `ToolState` as `state.engine`, which the state factory
|
|
37
|
+
* constructs and wires. Owners ({@link Analyses}, {@link EventsState}) register jobs and keep the returned
|
|
38
38
|
* handles.
|
|
39
39
|
*
|
|
40
40
|
* @group Agent Toolkit
|
|
@@ -45,12 +45,12 @@ declare class JobEngine {
|
|
|
45
45
|
private scanning;
|
|
46
46
|
private scheduled;
|
|
47
47
|
private pending;
|
|
48
|
-
/**
|
|
48
|
+
/** Registers a job and returns its handle, which the owner stores as its reference to the recurrence. */
|
|
49
49
|
register(spec: JobSpec): Job;
|
|
50
50
|
/** @internal — called by {@link JobHandle.unregister}. */
|
|
51
51
|
drop(job: JobHandle): void;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Subscribes the scan to every input slice's `entries-change`, exactly once per session. The state
|
|
54
54
|
* factory calls this at construction (it holds the slices), so every `ToolState` gets a live engine
|
|
55
55
|
* without the job builders having to wire lazily.
|
|
56
56
|
*/
|
|
@@ -61,7 +61,7 @@ declare class JobEngine {
|
|
|
61
61
|
private hasActiveJob;
|
|
62
62
|
private scheduleScan;
|
|
63
63
|
private runScan;
|
|
64
|
-
/**
|
|
64
|
+
/** Drops every job. `destroyState` calls it automatically (duck-typed `reset`). Subscriptions persist
|
|
65
65
|
* (harmless without jobs), mirroring the one-shot `wired` guard. */
|
|
66
66
|
reset(): void;
|
|
67
67
|
}
|
|
@@ -80,8 +80,8 @@ declare class JobHandle implements Job {
|
|
|
80
80
|
//#region src/tools/shared/sandbox-code.d.ts
|
|
81
81
|
export type AnalysisOutputFormat = 'json' | 'chart';
|
|
82
82
|
/**
|
|
83
|
-
* Compact sandbox-code blurb shared by
|
|
84
|
-
* `
|
|
83
|
+
* Compact sandbox-code blurb shared by every code-generation tool, through
|
|
84
|
+
* `buildSandboxToolsDoc`. Keeps the
|
|
85
85
|
* "what's in scope / what's forbidden" rules short and consistent across all
|
|
86
86
|
* code-generation tools so the LLM is prompted the same way each time. Pass
|
|
87
87
|
* the names of the injected identifiers (the params the AsyncFunction body
|
|
@@ -118,11 +118,11 @@ export declare const ANALYSE_OUTPUT_FORMAT_DESCRIPTION: string;
|
|
|
118
118
|
*/
|
|
119
119
|
export declare const buildAnalyseReturnPrompt: (jsonExamples: string, chartLabelExample?: string) => string;
|
|
120
120
|
/**
|
|
121
|
-
* Validates the value returned by
|
|
121
|
+
* Validates the value returned by sandboxed code: rejects
|
|
122
122
|
* `undefined`, JSON-normalizes via `toJsonSafe`, and — when
|
|
123
123
|
* `outputFormat: "chart"` — checks the result is a Chart.js
|
|
124
|
-
* `ChartConfiguration`. Centralises the contract shared by
|
|
125
|
-
*
|
|
124
|
+
* `ChartConfiguration`. Centralises the contract shared by `analyseData` and every
|
|
125
|
+
* recurring re-run (`sandbox-replay.ts`: monitored analyses, trackers, `clusterIncidents` code).
|
|
126
126
|
*
|
|
127
127
|
* @ignore
|
|
128
128
|
*/
|
|
@@ -137,11 +137,11 @@ export declare const sandboxedGlobalShadows: readonly ["fetch", "XMLHttpRequest"
|
|
|
137
137
|
export declare const WORKER_PROVIDED_PARAMS: readonly ["turf", "h3", "routeUtils", "log", "cluster"];
|
|
138
138
|
/**
|
|
139
139
|
* Pluggable strategy for executing sandbox code. The default
|
|
140
|
-
* {@link mainThreadExecutor} compiles
|
|
141
|
-
* executor
|
|
140
|
+
* {@link mainThreadExecutor} compiles and runs in the host realm. An alternative
|
|
141
|
+
* executor, such as the iframe-worker one, can run the same code in a locked-down
|
|
142
142
|
* realm off the main thread while honouring this exact contract.
|
|
143
143
|
*
|
|
144
|
-
* `run` MUST resolve to `{ value }` or `{ error }` and never reject
|
|
144
|
+
* `run` MUST resolve to `{ value }` or `{ error }` and never reject. Execution
|
|
145
145
|
* failures are reported as `{ error }` via {@link formatSandboxExecutionError}.
|
|
146
146
|
*
|
|
147
147
|
* @group Agent Toolkit
|
|
@@ -152,7 +152,7 @@ export type SandboxExecutor = {
|
|
|
152
152
|
} | {
|
|
153
153
|
error: string;
|
|
154
154
|
}>;
|
|
155
|
-
/**
|
|
155
|
+
/** Releases any held resources (iframe / worker). No-op for the main-thread executor. */
|
|
156
156
|
destroy?(): void;
|
|
157
157
|
};
|
|
158
158
|
/**
|
|
@@ -168,7 +168,7 @@ export declare const mainThreadExecutor: SandboxExecutor;
|
|
|
168
168
|
* Compiles `code` as the body of an `async` function that takes the named
|
|
169
169
|
* `paramNames`, sanitises injected redeclarations, runs it with `args`, and
|
|
170
170
|
* returns either `{ value }` or `{ error }`. Centralises the AsyncFunction
|
|
171
|
-
* dance shared by every sandbox-running tool (
|
|
171
|
+
* dance shared by every sandbox-running tool (analyseData, processData, createTracker, clusterIncidents) so
|
|
172
172
|
* each callsite only owns its inputs and result handling.
|
|
173
173
|
*
|
|
174
174
|
* In addition to the caller's `paramNames`, a fixed set of network / storage /
|
|
@@ -207,18 +207,18 @@ export declare const formatSandboxExecutionError: (verb: string, error: unknown)
|
|
|
207
207
|
/**
|
|
208
208
|
* @module agent-toolkit-state
|
|
209
209
|
*
|
|
210
|
-
*
|
|
211
|
-
* subscribers when
|
|
212
|
-
* (`on(type, handler) => unsubscribe`, `off(type)`) so consumers see one consistent pattern across
|
|
213
|
-
* the SDK and the agent toolkit.
|
|
210
|
+
* A tiny typed event emitter that every state slice (PlacesState, RoutingState, ...) uses to notify
|
|
211
|
+
* subscribers when its internals change. Its shape mirrors the SDK's `ModuleEvents` API
|
|
212
|
+
* (`on(type, handler) => unsubscribe`, `off(type)`), so consumers see one consistent pattern across
|
|
213
|
+
* the SDK and the agent toolkit. It plugs straight into React's `useSyncExternalStore`.
|
|
214
214
|
*
|
|
215
215
|
* @group Agent Toolkit
|
|
216
216
|
*/
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
218
|
+
* A generic typed event bus. The `EventMap` parameter declares the event names this emitter supports
|
|
219
|
+
* and each event's payload type, and `on` and `emit` are strongly typed against it.
|
|
220
220
|
*
|
|
221
|
-
*
|
|
221
|
+
* Outside the slice, you can only subscribe:
|
|
222
222
|
* ```ts
|
|
223
223
|
* const unsub = state.places.events.on('entries-change', ({ entries }) => render(entries));
|
|
224
224
|
* // ...
|
|
@@ -230,10 +230,10 @@ export declare const formatSandboxExecutionError: (verb: string, error: unknown)
|
|
|
230
230
|
declare class StateEvents<EventMap extends Record<string, unknown>> {
|
|
231
231
|
private readonly handlers;
|
|
232
232
|
/**
|
|
233
|
-
*
|
|
233
|
+
* Subscribes to an event and returns an unsubscribe function that removes only this handler.
|
|
234
234
|
*/
|
|
235
235
|
on<K extends keyof EventMap>(type: K, handler: (payload: EventMap[K]) => void): () => void;
|
|
236
|
-
/**
|
|
236
|
+
/** Removes all handlers for an event type. To remove one handler, call the unsubscribe `on` returns. */
|
|
237
237
|
off<K extends keyof EventMap>(type: K): void;
|
|
238
238
|
/**
|
|
239
239
|
* Fire an event. Internal — only the owning slice should call this. We don't make it `protected`
|
|
@@ -243,7 +243,7 @@ declare class StateEvents<EventMap extends Record<string, unknown>> {
|
|
|
243
243
|
* @internal
|
|
244
244
|
*/
|
|
245
245
|
emit<K extends keyof EventMap>(type: K, payload: EventMap[K]): void;
|
|
246
|
-
/**
|
|
246
|
+
/** Removes every handler for every type. A slice's `reset()` calls it to detach lingering listeners. */
|
|
247
247
|
clear(): void;
|
|
248
248
|
}
|
|
249
249
|
//#endregion
|
|
@@ -268,12 +268,12 @@ type EntryAnalysis = {
|
|
|
268
268
|
data: unknown;
|
|
269
269
|
};
|
|
270
270
|
/**
|
|
271
|
-
* One analysis tracked by the session-level {@link Analyses} registry
|
|
272
|
-
* `analyseData` analysis, one-shot or monitored, across every entry kind.
|
|
273
|
-
* the bounded result `history`. The recipe (`code` / `inputs`) and recurrence are NOT
|
|
274
|
-
* the analysis's {@link Job} (see `_jobs`). `affectedEntryIds` is the per-entry
|
|
275
|
-
* ({@link Analyses.getAnalysesForEntry})
|
|
276
|
-
* is the current result
|
|
271
|
+
* One analysis tracked by the session-level {@link Analyses} registry, the single home for every
|
|
272
|
+
* `analyseData` analysis, one-shot or monitored, across every entry kind. It is pure sink state,
|
|
273
|
+
* metadata plus the bounded result `history`. The recipe (`code` / `inputs`) and recurrence are NOT
|
|
274
|
+
* here. They live on the analysis's {@link Job} (see `_jobs`). `affectedEntryIds` is the per-entry
|
|
275
|
+
* lookup key ({@link Analyses.getAnalysesForEntry}). `history` is the result timeline (oldest first),
|
|
276
|
+
* whose latest is the current result, threaded back into the sandbox code as `previous`.
|
|
277
277
|
*
|
|
278
278
|
* @group Agent Toolkit
|
|
279
279
|
*/
|
|
@@ -289,8 +289,8 @@ type AnalysisRecord = {
|
|
|
289
289
|
history: EntryAnalysis[];
|
|
290
290
|
};
|
|
291
291
|
/**
|
|
292
|
-
* {@link Analyses.register}
|
|
293
|
-
* results land) and no recipe (that lives on the {@link Job}).
|
|
292
|
+
* The input of {@link Analyses.register}, the record's metadata. It has no `history` (the registry
|
|
293
|
+
* builds that as results land) and no recipe (that lives on the {@link Job}).
|
|
294
294
|
*
|
|
295
295
|
* @group Agent Toolkit
|
|
296
296
|
*/
|
|
@@ -311,15 +311,15 @@ type AnalysesEvents = {
|
|
|
311
311
|
};
|
|
312
312
|
};
|
|
313
313
|
/**
|
|
314
|
-
*
|
|
315
|
-
* `_analyses` stores.
|
|
316
|
-
* its own bounded result history. Entries carry no analysis state
|
|
317
|
-
* {@link getAnalysesForEntry}.
|
|
314
|
+
* The session-level registry of EVERY analysis, the single source of truth that replaces the per-entry
|
|
315
|
+
* `_analyses` stores. It holds one {@link AnalysisRecord} per analysis (keyed by `analysisId`), each
|
|
316
|
+
* with its own bounded result history. Entries carry no analysis state. Per-entry views call
|
|
317
|
+
* {@link getAnalysesForEntry}. `ToolState` holds it as `state.analyses`.
|
|
318
318
|
*
|
|
319
|
-
*
|
|
320
|
-
* registry keeps each monitored analysis's {@link Job} handle in `_jobs` (keyed by `analysisId`)
|
|
321
|
-
* can pause
|
|
322
|
-
* job for later promotion.
|
|
319
|
+
* It is a pure sink of metadata and result history. The recurrence lives on the {@link JobEngine}.
|
|
320
|
+
* This registry keeps each monitored analysis's {@link Job} handle in `_jobs` (keyed by `analysisId`)
|
|
321
|
+
* so it can pause or resume it ({@link job}) or compare its `code` on re-arm. A one-shot analysis keeps
|
|
322
|
+
* a paused job for later promotion.
|
|
323
323
|
*
|
|
324
324
|
* @group Agent Toolkit
|
|
325
325
|
*/
|
|
@@ -327,36 +327,37 @@ declare class Analyses {
|
|
|
327
327
|
private readonly _records;
|
|
328
328
|
/** analysisId → the {@link Job} backing it (one-shot = paused). The reference linking record to engine. */
|
|
329
329
|
private readonly _jobs;
|
|
330
|
-
/**
|
|
330
|
+
/** The {@link AnalysesEvents} emitter, fired whenever a result is attached or recomputed. */
|
|
331
331
|
readonly events: StateEvents<AnalysesEvents>;
|
|
332
332
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* history
|
|
333
|
+
* Inserts or replaces a record's metadata, NOT its result (use {@link attachResult}) or its recipe,
|
|
334
|
+
* which lives on the {@link Job}. Re-registering an existing `analysisId` preserves its result
|
|
335
|
+
* history. Callers drop stale history explicitly with {@link resetHistory} when the recipe changes.
|
|
336
336
|
*/
|
|
337
337
|
register(input: AnalysisRegistration): void;
|
|
338
|
-
/**
|
|
338
|
+
/** Stores the {@link Job} backing an analysis, the reference linking this record to the engine. */
|
|
339
339
|
setJob(analysisId: string, job: Job): void;
|
|
340
340
|
/** The {@link Job} backing an analysis, if monitored or a retained one-shot. */
|
|
341
341
|
job(analysisId: string): Job | undefined;
|
|
342
|
-
/**
|
|
342
|
+
/** Drops an analysis's result history. A re-arm calls it when the recipe changed (stale `previous`). */
|
|
343
343
|
resetHistory(analysisId: string): void;
|
|
344
344
|
/**
|
|
345
|
-
*
|
|
345
|
+
* Appends a result to a record's timeline, evicting the oldest when the per-analysis cap is hit. A
|
|
346
346
|
* same-timestamp re-run (an id-stability re-read of an unchanged snapshot) overwrites the last entry
|
|
347
|
-
* rather than duplicating it.
|
|
347
|
+
* rather than duplicating it. It emits `analysis-change`, unless the `analysisId` is unknown
|
|
348
|
+
* (a no-op).
|
|
348
349
|
*/
|
|
349
350
|
attachResult(analysisId: string, result: EntryAnalysis): void;
|
|
350
351
|
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
352
|
+
* Returns the latest result of every analysis attached to `entryId`, in registration order,
|
|
353
|
+
* replacing the old per-entry `_analyses.results`. It scans records linearly, fine at session scale
|
|
354
|
+
* (one record per distinct analyseData name+sources, plus one per clustered incidents entry).
|
|
354
355
|
*/
|
|
355
356
|
getAnalysesForEntry(entryId: string): readonly EntryAnalysis[];
|
|
356
357
|
/**
|
|
357
|
-
*
|
|
358
|
-
* `record.history.at(-1)` for each one's latest result.
|
|
359
|
-
*
|
|
358
|
+
* Returns every analysis record in registration order, the combined cross-entry view. Read
|
|
359
|
+
* `record.history.at(-1)` for each one's latest result. Tracker verdicts are not analyses, so every
|
|
360
|
+
* record here is operator-facing.
|
|
360
361
|
*/
|
|
361
362
|
all(): readonly AnalysisRecord[];
|
|
362
363
|
/** Full result timeline for one analysis, oldest first. Empty when unknown. */
|
|
@@ -366,14 +367,14 @@ declare class Analyses {
|
|
|
366
367
|
get(analysisId: string): AnalysisRecord | undefined;
|
|
367
368
|
/** Whether the analysis is currently recomputed on source change (its job exists and is active). */
|
|
368
369
|
isMonitored(analysisId: string): boolean;
|
|
369
|
-
/**
|
|
370
|
+
/** Removes an analysis, tearing down its job and dropping the record and handle. */
|
|
370
371
|
remove(analysisId: string): void;
|
|
371
372
|
/**
|
|
372
|
-
*
|
|
373
|
-
* `unregister(name)`
|
|
373
|
+
* Removes every record sharing a `name`, across all source entries, as the old per-entry
|
|
374
|
+
* `unregister(name)` dropped a named analysis wherever it was attached.
|
|
374
375
|
*/
|
|
375
376
|
removeByName(name: string): void;
|
|
376
|
-
/**
|
|
377
|
+
/** Drops every record and job handle. `destroyState` calls it automatically (duck-typed `reset`). */
|
|
377
378
|
reset(): void;
|
|
378
379
|
}
|
|
379
380
|
//#endregion
|
|
@@ -568,39 +569,38 @@ interface FeatureCollection$1<G extends Geometry | null = Geometry, P = GeoJsonP
|
|
|
568
569
|
/**
|
|
569
570
|
* @module agent-toolkit-state
|
|
570
571
|
*
|
|
571
|
-
*
|
|
572
|
-
* custom-geometries
|
|
573
|
-
* history of entries
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
* runtime state).
|
|
572
|
+
* The shared base shape for the per-slice history entries of places, routes, ranges, byod,
|
|
573
|
+
* custom-geometries, traffic-area-analytics and traffic-incidents. Every slice keeps an append-only
|
|
574
|
+
* history of entries that share four fields: an `id`, a `timestamp`, a `label`, and a single `data`
|
|
575
|
+
* payload. They live here, so each slice's entry type is `BaseEntry<TPayload> & { … }` plus only the
|
|
576
|
+
* fields unique to that slice, its per-entry display and runtime state.
|
|
577
577
|
*
|
|
578
578
|
* @group Agent Toolkit
|
|
579
579
|
*/
|
|
580
580
|
/**
|
|
581
|
-
* The fields
|
|
582
|
-
* (`id`), provenance (`timestamp`, `label`)
|
|
583
|
-
* this with its own per-entry display state
|
|
581
|
+
* The fields every history entry shares across the toolkit's state slices, namely identity
|
|
582
|
+
* (`id`), provenance (`timestamp`, `label`) and the slice's payload (`data`). Each slice intersects
|
|
583
|
+
* this with its own per-entry display state, such as `type RoutesEntry = BaseEntry<Routes> & { … }`.
|
|
584
584
|
*
|
|
585
|
-
* @typeParam TData -
|
|
586
|
-
* `TrafficIncident[]
|
|
585
|
+
* @typeParam TData - The entry's payload type, such as `Routes`, `Place[]`, `FeatureCollection` or
|
|
586
|
+
* `TrafficIncident[]`. It is the single result the entry was created to hold.
|
|
587
587
|
*
|
|
588
588
|
* @group Agent Toolkit
|
|
589
589
|
*/
|
|
590
590
|
type BaseEntry<TData> = {
|
|
591
591
|
/**
|
|
592
|
-
*
|
|
593
|
-
* existing entries on collision
|
|
592
|
+
* The stable, slice-unique entry id, such as `places-0` or a caller-supplied id deduped against
|
|
593
|
+
* existing entries on collision. Tools and recall surfaces address the entry by it.
|
|
594
594
|
*/
|
|
595
595
|
id: string;
|
|
596
596
|
/**
|
|
597
|
-
*
|
|
598
|
-
* bumped on each in-place replace
|
|
597
|
+
* The creation or last-refresh time, in milliseconds since the epoch. It is set when the entry is
|
|
598
|
+
* added and bumped on each in-place replace. A monitored re-run stamps the source sample time.
|
|
599
599
|
*/
|
|
600
600
|
timestamp: number;
|
|
601
|
-
/**
|
|
601
|
+
/** A short, human-readable label, shown in recall and recents surfaces. */
|
|
602
602
|
label: string;
|
|
603
|
-
/** The entry's payload
|
|
603
|
+
/** The entry's payload, the single result it was created to hold. */
|
|
604
604
|
data: TData;
|
|
605
605
|
};
|
|
606
606
|
//#endregion
|
|
@@ -700,7 +700,7 @@ type BYODEntry = BaseEntry<FeatureCollection$1> & {
|
|
|
700
700
|
/**
|
|
701
701
|
* State for base map display: style, language, viewport and layers.
|
|
702
702
|
*
|
|
703
|
-
*
|
|
703
|
+
* It exposes the TomTomMap and MapLibre instances directly, alongside
|
|
704
704
|
* lazy-initialized BaseMapModule, StylingFoundationsModule and TerrainModule.
|
|
705
705
|
*
|
|
706
706
|
* @group Agent Toolkit
|
|
@@ -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
|
|
@@ -910,18 +942,18 @@ export declare const applyFitOnMap: (state: ToolState, fit: FitOnMapInput) => z.
|
|
|
910
942
|
//#endregion
|
|
911
943
|
//#region src/tools/shared/geocode-areas.d.ts
|
|
912
944
|
/**
|
|
913
|
-
* Administrative-
|
|
914
|
-
* (`within` mode). Restricting the geocode to these (via `entityTypeSet`)
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
* postcode).
|
|
945
|
+
* Administrative-area geography types accepted when resolving a query to a *containing area*
|
|
946
|
+
* (`within` mode). Restricting the geocode to these (via `entityTypeSet`) stops streets and POIs
|
|
947
|
+
* from drowning the area. Without it, "De Pijp" and "Westminster" geocode to Streets at rank 0.
|
|
948
|
+
* Excludes `Country` (too coarse) and `PostalCodeArea` (homonym noise, such as "A10" matching a
|
|
949
|
+
* Kazakh postcode).
|
|
918
950
|
*/
|
|
919
951
|
export declare const AREA_GEOGRAPHY_TYPES: GeographyType[];
|
|
920
952
|
/**
|
|
921
|
-
* Geocodes `query` restricted to administrative
|
|
953
|
+
* Geocodes `query` restricted to administrative area geographies (not streets/POIs), biased toward
|
|
922
954
|
* `bias` (the map centre). Because `geographyTypes` filters to areas, every result carries a
|
|
923
|
-
* `boundingBox`. Callers choose among the candidates
|
|
924
|
-
* centre bias is used rather than a hard viewport-bbox filter so out-of-view areas still resolve.
|
|
955
|
+
* `boundingBox`. Callers choose among the candidates, for example the one nearest the current view.
|
|
956
|
+
* A centre bias is used rather than a hard viewport-bbox filter, so out-of-view areas still resolve.
|
|
925
957
|
*/
|
|
926
958
|
export declare const geocodeAreas: (query: string, opts?: {
|
|
927
959
|
bias?: Position;
|
|
@@ -937,8 +969,8 @@ export declare const geocodeAreas: (query: string, opts?: {
|
|
|
937
969
|
export type GeometriesIdKind = 'place' | 'places' | 'ranges' | 'customGeometries';
|
|
938
970
|
/**
|
|
939
971
|
* Tagged geometries id. The Zod schema is exposed so tools can plug it
|
|
940
|
-
* straight into their input shape (`z.array(geometriesIdSchema).min(1)`)
|
|
941
|
-
*
|
|
972
|
+
* straight into their input shape (`z.array(geometriesIdSchema).min(1)`),
|
|
973
|
+
* with no string parsing on the way in.
|
|
942
974
|
*
|
|
943
975
|
* @group Agent Toolkit
|
|
944
976
|
*/
|
|
@@ -1007,10 +1039,10 @@ export declare const GEOMETRIES_SOURCE_IDS_DESC = "Tagged input ids that contrib
|
|
|
1007
1039
|
* @module agent-toolkit-tools
|
|
1008
1040
|
*
|
|
1009
1041
|
* Compact schema doc for the geometry polygons consumed/produced by sandboxed
|
|
1010
|
-
* code in `processData` / `analyseData
|
|
1042
|
+
* code in `processData` / `analyseData`, injected per source as
|
|
1011
1043
|
* `geometriesByEntry[key]`. Each item is a
|
|
1012
|
-
* `PolygonFeature<CommonPlaceProps
|
|
1013
|
-
* spelled out here.
|
|
1044
|
+
* `PolygonFeature<CommonPlaceProps>`, and only its non-GeoJSON-standard bits
|
|
1045
|
+
* are spelled out here.
|
|
1014
1046
|
*/
|
|
1015
1047
|
/** @ignore */
|
|
1016
1048
|
export declare const GEOMETRIES_SCHEMA_DOC: string;
|
|
@@ -1029,8 +1061,8 @@ type CustomGeometriesAnalysis = EntryAnalysis;
|
|
|
1029
1061
|
//#endregion
|
|
1030
1062
|
//#region src/state/digest.d.ts
|
|
1031
1063
|
/**
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1064
|
+
* A compact, diffable snapshot of the user-visible parts of `ToolState`. Every field serialises to
|
|
1065
|
+
* JSON and stays stable for `===` comparison while the underlying state is unchanged.
|
|
1034
1066
|
*
|
|
1035
1067
|
* @group Agent Toolkit
|
|
1036
1068
|
*/
|
|
@@ -1040,25 +1072,25 @@ type StateDigest = {
|
|
|
1040
1072
|
shownAsPin: string[];
|
|
1041
1073
|
/** Entry ids currently rendered as base-map POIs, sorted ascending. */
|
|
1042
1074
|
shownAsBaseMap: string[];
|
|
1043
|
-
/**
|
|
1075
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1044
1076
|
entryMode: EntryMode;
|
|
1045
1077
|
};
|
|
1046
1078
|
routes: {
|
|
1047
1079
|
/** Routes-entry ids currently drawn on the map, sorted ascending. */
|
|
1048
1080
|
shown: string[];
|
|
1049
|
-
/**
|
|
1081
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1050
1082
|
entryMode: EntryMode;
|
|
1051
1083
|
};
|
|
1052
1084
|
ranges: {
|
|
1053
1085
|
/** Range-entry ids currently drawn on the map, sorted ascending. */
|
|
1054
1086
|
shown: string[];
|
|
1055
|
-
/**
|
|
1087
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1056
1088
|
entryMode: EntryMode;
|
|
1057
1089
|
};
|
|
1058
1090
|
traffic: {
|
|
1059
1091
|
/** Traffic-area-analytics entry ids currently rendered on the map, sorted ascending. */
|
|
1060
1092
|
shown: string[];
|
|
1061
|
-
/**
|
|
1093
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1062
1094
|
entryMode: EntryMode;
|
|
1063
1095
|
/** Total traffic-area-analytics entries in history (shown + hidden). */
|
|
1064
1096
|
entryCount: number;
|
|
@@ -1068,13 +1100,13 @@ type StateDigest = {
|
|
|
1068
1100
|
shown: string[];
|
|
1069
1101
|
/** Entry ids currently being polled by the per-entry network monitor, sorted ascending. */
|
|
1070
1102
|
monitored: string[];
|
|
1071
|
-
/**
|
|
1103
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1072
1104
|
entryMode: EntryMode;
|
|
1073
1105
|
};
|
|
1074
1106
|
customGeometries: {
|
|
1075
1107
|
/** Custom-geometries entry ids currently rendered on the map, sorted ascending. */
|
|
1076
1108
|
shown: string[];
|
|
1077
|
-
/**
|
|
1109
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1078
1110
|
entryMode: EntryMode;
|
|
1079
1111
|
/** Total custom-geometries entries in history (shown + hidden). */
|
|
1080
1112
|
entryCount: number;
|
|
@@ -1082,23 +1114,23 @@ type StateDigest = {
|
|
|
1082
1114
|
byod: {
|
|
1083
1115
|
/** BYOD entry ids currently rendered on the map, sorted ascending. */
|
|
1084
1116
|
shown: string[];
|
|
1085
|
-
/**
|
|
1117
|
+
/** The slice's display policy, `multiple` (default) or `single`. */
|
|
1086
1118
|
entryMode: EntryMode;
|
|
1087
1119
|
/** Total BYOD entries in history (shown + hidden). */
|
|
1088
1120
|
entryCount: number;
|
|
1089
1121
|
};
|
|
1090
1122
|
};
|
|
1091
1123
|
/**
|
|
1092
|
-
*
|
|
1093
|
-
* "agent-known" baseline
|
|
1124
|
+
* Takes a snapshot of the user-visible state surface. Call it after every assistant turn to record
|
|
1125
|
+
* the "agent-known" baseline, and again before each user prompt to detect what changed since.
|
|
1094
1126
|
*
|
|
1095
1127
|
* @group Agent Toolkit
|
|
1096
1128
|
*/
|
|
1097
1129
|
export declare const getStateDigest: (state: ToolState) => StateDigest;
|
|
1098
1130
|
/**
|
|
1099
|
-
*
|
|
1131
|
+
* Returns a compact, LLM-readable summary of the differences between two digests, or `null` if
|
|
1100
1132
|
* nothing changed. The output is short enough to prepend to a user prompt without bloating the
|
|
1101
|
-
* conversation
|
|
1133
|
+
* conversation, so it deliberately omits longer per-field diffs.
|
|
1102
1134
|
*
|
|
1103
1135
|
* @example
|
|
1104
1136
|
* ```ts
|
|
@@ -1143,12 +1175,12 @@ type PlacesAnalysis = EntryAnalysis;
|
|
|
1143
1175
|
//#endregion
|
|
1144
1176
|
//#region src/state/places/state.d.ts
|
|
1145
1177
|
/**
|
|
1146
|
-
* The marker looks an entry can
|
|
1147
|
-
* pins.
|
|
1148
|
-
* the agent. Every tool enum for marker types derives from this array
|
|
1178
|
+
* The marker looks an entry can render with, namely individual pins, base-map POIs, or clustered
|
|
1179
|
+
* pins. It is a type-checked subset of the SDK's `PlacesMarkerType` that doesn't offer `circle-icon`
|
|
1180
|
+
* to the agent. Every tool enum for marker types derives from this array instead of repeating it.
|
|
1149
1181
|
*/
|
|
1150
1182
|
declare const placesMarkerTypes: readonly ["pin", "base-map", "pin-clustered"];
|
|
1151
|
-
/** How an entry
|
|
1183
|
+
/** How an entry renders on the map, one of {@link placesMarkerTypes}. */
|
|
1152
1184
|
type PlacesMarkerType = (typeof placesMarkerTypes)[number];
|
|
1153
1185
|
/**
|
|
1154
1186
|
* Events fired by {@link PlacesState}. Subscribe via `state.places.events.on(type, handler)`.
|
|
@@ -1157,33 +1189,33 @@ type PlacesMarkerType = (typeof placesMarkerTypes)[number];
|
|
|
1157
1189
|
*/
|
|
1158
1190
|
type PlacesStateEvents = {
|
|
1159
1191
|
/**
|
|
1160
|
-
*
|
|
1161
|
-
* snapshot after the change
|
|
1162
|
-
*
|
|
1163
|
-
* `affectedEntryIds
|
|
1192
|
+
* An entry was added or replaced, or `reset()` cleared the history. `entries` is the full
|
|
1193
|
+
* snapshot after the change, and `changedIds` lists the ids of the entries this change added,
|
|
1194
|
+
* replaced in place, or removed. The {@link JobEngine} matches these against each job's
|
|
1195
|
+
* `affectedEntryIds`.
|
|
1164
1196
|
*/
|
|
1165
1197
|
'entries-change': {
|
|
1166
1198
|
entries: readonly PlacesEntry[];
|
|
1167
1199
|
changedIds: readonly string[];
|
|
1168
1200
|
};
|
|
1169
|
-
/**
|
|
1201
|
+
/** The set of entries rendered on the map, or a marker type, changed. */
|
|
1170
1202
|
'shown-change': ReadonlySet<string>;
|
|
1171
1203
|
/** Boundary polygons were fetched and cached on an entry. */
|
|
1172
1204
|
'geometries-change': {
|
|
1173
1205
|
entryId: string;
|
|
1174
1206
|
count: number;
|
|
1175
1207
|
};
|
|
1176
|
-
/**
|
|
1208
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
1177
1209
|
'mode-change': EntryMode;
|
|
1178
1210
|
};
|
|
1179
1211
|
/**
|
|
1180
|
-
*
|
|
1212
|
+
* The state for the places layer, an append-only history of place results plus per-entry display
|
|
1181
1213
|
* modules.
|
|
1182
1214
|
*
|
|
1183
|
-
* Each entry owns a single PlacesModule
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
* entries can
|
|
1215
|
+
* Each entry owns a single PlacesModule and a dedicated GeometriesModule, both initialised lazily
|
|
1216
|
+
* on first show. An entry renders under one marker type at a time, so `updateConfig` switches its
|
|
1217
|
+
* PlacesModule in place when the marker type changes. Display state lives on the entry, so two
|
|
1218
|
+
* entries can render side by side under different marker types without sharing a single source.
|
|
1187
1219
|
*
|
|
1188
1220
|
* @group Agent Toolkit
|
|
1189
1221
|
*/
|
|
@@ -1191,37 +1223,42 @@ declare class PlacesState implements StateSlice {
|
|
|
1191
1223
|
private readonly _ttMap;
|
|
1192
1224
|
private _entries;
|
|
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
|
-
*
|
|
1199
|
-
* simultaneously
|
|
1200
|
-
*
|
|
1234
|
+
* The display policy. `multiple` (default) keeps every history entry available to render
|
|
1235
|
+
* simultaneously. `single` allows at most one entry on the map at a time and trims the
|
|
1236
|
+
* history to the latest entry whenever it's set.
|
|
1201
1237
|
*/
|
|
1202
1238
|
get entryMode(): EntryMode;
|
|
1203
1239
|
/**
|
|
1204
|
-
*
|
|
1205
|
-
*
|
|
1206
|
-
*
|
|
1240
|
+
* Switches the display policy. Moving from `multiple` to `single` hides every entry older
|
|
1241
|
+
* than the latest, drops them from history, and emits `entries-change` so listeners (the
|
|
1242
|
+
* recents rail, recall tools, …) re-render. Does nothing if the mode hasn't changed.
|
|
1207
1243
|
*/
|
|
1208
1244
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
1209
1245
|
/**
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1246
|
+
* Returns the entry's PlacesModule, created on first call and switched to `markerType`. An entry
|
|
1247
|
+
* renders under only one marker type at a time, so flipping marker types reuses the same module
|
|
1248
|
+
* and calls `updateConfig` in place. Throws if the entry id is unknown.
|
|
1213
1249
|
*/
|
|
1214
1250
|
getEntryPlacesModule(entryId: string, markerType: PlacesMarkerType): Promise<PlacesModule>;
|
|
1215
1251
|
/**
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1252
|
+
* Returns the entry's place-geometries module for POI footprints and municipality outlines,
|
|
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.
|
|
1218
1255
|
*/
|
|
1219
1256
|
getEntryGeometriesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<GeometriesModule>;
|
|
1220
1257
|
private _requireEntry;
|
|
1221
1258
|
get entries(): readonly PlacesEntry[];
|
|
1222
1259
|
/**
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1260
|
+
* Only passes data between tools in a context-dependent way, so it assumes
|
|
1261
|
+
* the most recent entry is the relevant one to show on the map.
|
|
1225
1262
|
*/
|
|
1226
1263
|
get latestPlace(): Place[] | undefined;
|
|
1227
1264
|
addPlaceResult(place: Place | Places, label: string, explicitId?: string, connections?: PlaceConnectionDisplay[], geometries?: PolygonFeature<CommonPlaceProps>[]): Promise<string>;
|
|
@@ -1249,18 +1286,17 @@ declare class PlacesState implements StateSlice {
|
|
|
1249
1286
|
*/
|
|
1250
1287
|
fetchGeometriesForEntry(entryId: string, options?: ToolExecuteOptions): Promise<PolygonFeature<CommonPlaceProps>[]>;
|
|
1251
1288
|
/**
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
* the slice's per-entry hide
|
|
1289
|
+
* Renders the given polygons via the entry's GeometriesModule. The `mode` flag applies to
|
|
1290
|
+
* **this entry's layer only** and doesn't touch other entries. For cross-entry visibility,
|
|
1291
|
+
* use the slice's per-entry hide and show methods.
|
|
1255
1292
|
*
|
|
1256
|
-
* - `mode: 'replace'` (default)
|
|
1257
|
-
* whatever was
|
|
1258
|
-
* - `mode: 'add'`
|
|
1259
|
-
*
|
|
1260
|
-
* no-op.
|
|
1293
|
+
* - `mode: 'replace'` (default) calls `module.show` with exactly these features, replacing
|
|
1294
|
+
* whatever was on this entry's layer before. An empty array clears the layer.
|
|
1295
|
+
* - `mode: 'add'` merges the new features with the polygons shown on this entry's layer,
|
|
1296
|
+
* deduped by `feature.id`, and re-renders the union. An empty array does nothing.
|
|
1261
1297
|
*
|
|
1262
|
-
* `entryId` defaults to the latest entry that owns geometries
|
|
1263
|
-
* render the most
|
|
1298
|
+
* `entryId` defaults to the latest entry that owns geometries, which suits callers that only
|
|
1299
|
+
* render the most recently produced footprints. Pass an explicit id to target an older one.
|
|
1264
1300
|
*/
|
|
1265
1301
|
showPlaceGeometries(features: PolygonFeature<CommonPlaceProps>[], fillStyle?: GeometryFillStyle, mode?: 'add' | 'replace', entryId?: string): Promise<void>;
|
|
1266
1302
|
private _latestGeometriesEntryId;
|
|
@@ -1276,37 +1312,36 @@ declare class PlacesState implements StateSlice {
|
|
|
1276
1312
|
private _idsShownAs;
|
|
1277
1313
|
/** Marker type for a specific entry, or undefined if it is not shown. */
|
|
1278
1314
|
getShownMarkerType(id: string): PlacesMarkerType | undefined;
|
|
1279
|
-
/**
|
|
1315
|
+
/** Returns the union of all features belonging to the shown entries. */
|
|
1280
1316
|
getShownFeatures(): Place[];
|
|
1281
1317
|
/**
|
|
1282
|
-
*
|
|
1283
|
-
* Entries
|
|
1284
|
-
*
|
|
1318
|
+
* Replaces the shown set for `markerType` with exactly these ids and re-renders.
|
|
1319
|
+
* Entries shown as `markerType` but absent from `ids` are hidden. Entries in `ids`
|
|
1320
|
+
* switch to `markerType`, creating their module if needed.
|
|
1285
1321
|
*/
|
|
1286
1322
|
setShownEntries(ids: readonly string[], markerType: PlacesMarkerType): Promise<Place[]>;
|
|
1287
1323
|
/**
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
* marker type).
|
|
1324
|
+
* Adds ids to the shown set under `markerType`. Any id shown as a different
|
|
1325
|
+
* marker type moves, and its module switches to the new marker type.
|
|
1291
1326
|
*
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1327
|
+
* With `entryMode === 'single'`, everything else is hidden first, so in effect
|
|
1328
|
+
* only the last id in the list is shown.
|
|
1294
1329
|
*/
|
|
1295
1330
|
addShownEntries(ids: readonly string[], markerType: PlacesMarkerType): Promise<Place[]>;
|
|
1296
|
-
/**
|
|
1331
|
+
/** Removes ids from the shown set and clears their modules. */
|
|
1297
1332
|
removeShownEntries(ids: readonly string[]): Promise<Place[]>;
|
|
1298
|
-
/**
|
|
1333
|
+
/** Clears everything from the map but leaves the entries history untouched. */
|
|
1299
1334
|
clearShownEntries(): Promise<void>;
|
|
1300
1335
|
/**
|
|
1301
|
-
*
|
|
1302
|
-
* history (`entries`)
|
|
1336
|
+
* Hides every PlacesState rendering, both pins and attached boundary polygons, but leaves
|
|
1337
|
+
* the history (`entries`) untouched. Implements {@link ClearableMapSlice}.
|
|
1303
1338
|
*/
|
|
1304
1339
|
clearShown(): Promise<void>;
|
|
1305
1340
|
clearShownGeometries(ids?: readonly string[]): Promise<void>;
|
|
1306
1341
|
/**
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
1342
|
+
* Drops a single entry from history. It first hides the entry by clearing every module it
|
|
1343
|
+
* owns, then removes it from `_entries`. Emits `entries-change`, plus `shown-change` if the
|
|
1344
|
+
* entry was shown. Does nothing if the id is unknown.
|
|
1310
1345
|
*/
|
|
1311
1346
|
removeEntry(id: string): Promise<void>;
|
|
1312
1347
|
private _showEntryAs;
|
|
@@ -1403,25 +1438,25 @@ type RangesEntry = BaseEntry<ReachableRange[]> & {
|
|
|
1403
1438
|
*/
|
|
1404
1439
|
type RangeStateEvents = {
|
|
1405
1440
|
/**
|
|
1406
|
-
*
|
|
1407
|
-
* after the change
|
|
1408
|
-
*
|
|
1441
|
+
* An entry was added, or `reset()` cleared the range history. `entries` is the full snapshot
|
|
1442
|
+
* after the change, and `changedIds` lists the ids of the entries this change added, replaced
|
|
1443
|
+
* in place, or removed.
|
|
1409
1444
|
*/
|
|
1410
1445
|
'entries-change': {
|
|
1411
1446
|
entries: readonly RangesEntry[];
|
|
1412
1447
|
changedIds: readonly string[];
|
|
1413
1448
|
};
|
|
1414
|
-
/**
|
|
1449
|
+
/** The set of ranges entries rendered on the map changed (multi-show under `multiple`). */
|
|
1415
1450
|
'shown-change': ReadonlySet<string>;
|
|
1416
|
-
/**
|
|
1451
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
1417
1452
|
'mode-change': EntryMode;
|
|
1418
1453
|
};
|
|
1419
1454
|
/**
|
|
1420
1455
|
* State for reachable range results.
|
|
1421
1456
|
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1457
|
+
* It stores semantic summaries of calculated ranges (origin, budgets), plus the raw polygon
|
|
1458
|
+
* geometry internally for geometry searches such as discoverPlaces withinRange.
|
|
1459
|
+
* ReachableRangesModule displays them on the map.
|
|
1425
1460
|
*
|
|
1426
1461
|
* @group Agent Toolkit
|
|
1427
1462
|
*/
|
|
@@ -1429,56 +1464,61 @@ declare class RangeState implements ShownEntriesSlice {
|
|
|
1429
1464
|
private readonly _ttMap;
|
|
1430
1465
|
private _entries;
|
|
1431
1466
|
private _entryMode;
|
|
1432
|
-
/**
|
|
1467
|
+
/** The state change events, listed in {@link RangeStateEvents}. */
|
|
1433
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;
|
|
1434
1475
|
constructor(_ttMap: TomTomMap);
|
|
1435
1476
|
/** Set of ranges-entry ids currently rendered on the map. */
|
|
1436
1477
|
get shownEntryIds(): ReadonlySet<string>;
|
|
1437
1478
|
/**
|
|
1438
|
-
*
|
|
1439
|
-
* by side
|
|
1440
|
-
*
|
|
1479
|
+
* The display policy. `multiple` (default) lets several reachable-area entries render
|
|
1480
|
+
* side by side. `single` allows at most one ranges entry on the map, so `markEntryShown`
|
|
1481
|
+
* first hides any previously-shown entry.
|
|
1441
1482
|
*/
|
|
1442
1483
|
get entryMode(): EntryMode;
|
|
1443
1484
|
/**
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1485
|
+
* Switches the display policy. Moving from `multiple` to `single` hides every non-latest
|
|
1486
|
+
* entry, drops them from history, and emits `entries-change`. Does nothing if the mode
|
|
1487
|
+
* hasn't changed.
|
|
1447
1488
|
*/
|
|
1448
1489
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
1449
1490
|
/**
|
|
1450
|
-
*
|
|
1451
|
-
*
|
|
1491
|
+
* Initialises the entry's ReachableRangesModule for the isochrone/isodistance polygons
|
|
1492
|
+
* lazily and applies the requested fill style. Throws on unknown id.
|
|
1452
1493
|
*/
|
|
1453
1494
|
getEntryRangesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<ReachableRangesModule>;
|
|
1454
1495
|
/**
|
|
1455
|
-
*
|
|
1456
|
-
* your own (per-feature colours, border widths)
|
|
1496
|
+
* Initialises the entry's plain GeometriesModule lazily for drawing the entry's polygons in a
|
|
1497
|
+
* style of your own (per-feature colours, border widths) instead of as reachable-range bands.
|
|
1457
1498
|
* Updates only the fill style when it changes, keeping the styling applied since. Throws on
|
|
1458
1499
|
* unknown id.
|
|
1459
1500
|
*/
|
|
1460
1501
|
getEntryGeometriesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<GeometriesModule>;
|
|
1461
1502
|
/**
|
|
1462
|
-
*
|
|
1463
|
-
* so
|
|
1464
|
-
* overwriting another.
|
|
1503
|
+
* Initialises the entry's origin-pin PlacesModule lazily. Each entry has its own pin module,
|
|
1504
|
+
* so several ranges entries can share the map without one's pins overwriting another's.
|
|
1465
1505
|
*/
|
|
1466
1506
|
getEntryPlacesModule(entryId: string): Promise<PlacesModule>;
|
|
1467
1507
|
/**
|
|
1468
|
-
*
|
|
1469
|
-
* caller
|
|
1470
|
-
*
|
|
1508
|
+
* Marks the entry as shown by recording `_shown = true` and emitting `shown-change`. The
|
|
1509
|
+
* caller pushes features into the lazy modules itself. This method only keeps the `_shown`
|
|
1510
|
+
* flag in sync with what the user sees.
|
|
1471
1511
|
*
|
|
1472
|
-
*
|
|
1512
|
+
* With `entryMode === 'single'`, any other shown entry is hidden first so two range
|
|
1473
1513
|
* layers don't overlap.
|
|
1474
1514
|
*/
|
|
1475
1515
|
markEntryShown(entryId: string): Promise<void>;
|
|
1476
|
-
/**
|
|
1516
|
+
/** Clears every module on the entry. Does nothing if the entry is unknown. */
|
|
1477
1517
|
hideEntry(entryId: string): Promise<void>;
|
|
1478
1518
|
/**
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1519
|
+
* Drops a single entry from history. It clears the entry's ranges and origin-pin modules to
|
|
1520
|
+
* hide it, then removes it from `_entries`. Emits `entries-change`. Does nothing if the id is
|
|
1521
|
+
* unknown.
|
|
1482
1522
|
*/
|
|
1483
1523
|
removeEntry(entryId: string): Promise<void>;
|
|
1484
1524
|
private _requireEntry;
|
|
@@ -1486,8 +1526,8 @@ declare class RangeState implements ShownEntriesSlice {
|
|
|
1486
1526
|
get latestEntry(): RangesEntry | undefined;
|
|
1487
1527
|
addEntry(entry: Omit<RangesEntry, 'id' | 'timestamp'>): Promise<string>;
|
|
1488
1528
|
/**
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1529
|
+
* Hides every reachable-range entry on the map but keeps the history. Implements
|
|
1530
|
+
* {@link ClearableMapSlice}.
|
|
1491
1531
|
*/
|
|
1492
1532
|
clearShown(): Promise<void>;
|
|
1493
1533
|
reset(): void;
|
|
@@ -1516,8 +1556,8 @@ type RouteSnapshot = {
|
|
|
1516
1556
|
routes: Routes;
|
|
1517
1557
|
};
|
|
1518
1558
|
/**
|
|
1519
|
-
*
|
|
1520
|
-
* failed and the timer
|
|
1559
|
+
* The lifecycle state of a per-entry route monitor. `stopped-error` means the last recalculation
|
|
1560
|
+
* failed and the timer was cleared. To retry, start the monitor again.
|
|
1521
1561
|
*
|
|
1522
1562
|
* @group Agent Toolkit
|
|
1523
1563
|
*/
|
|
@@ -1525,11 +1565,11 @@ type RoutePollingStatus = 'idle' | 'running' | 'stopped-error';
|
|
|
1525
1565
|
//#endregion
|
|
1526
1566
|
//#region src/state/routing/monitor/monitor.d.ts
|
|
1527
1567
|
/**
|
|
1528
|
-
*
|
|
1529
|
-
* over `calculateRoute`
|
|
1530
|
-
*
|
|
1568
|
+
* The injected dependencies of a {@link RouteMonitor}. Production code wires `recalculate` to a
|
|
1569
|
+
* closure over `calculateRoute` and the entry's waypoints and params, so each tick re-runs the same
|
|
1570
|
+
* route. Tests pass a deterministic fake and override the timer.
|
|
1531
1571
|
*
|
|
1532
|
-
* The recalculator returns
|
|
1572
|
+
* The recalculator returns only the routes. The monitor stamps `takenAt` itself, so every consumer of
|
|
1533
1573
|
* one tick (entry data, derived analyses) agrees on the same canonical moment.
|
|
1534
1574
|
*
|
|
1535
1575
|
* @group Agent Toolkit
|
|
@@ -1542,21 +1582,21 @@ type RouteMonitorDeps = {
|
|
|
1542
1582
|
};
|
|
1543
1583
|
/**
|
|
1544
1584
|
* Events fired by {@link RouteMonitor}. The slice subscribes once and re-emits translated copies
|
|
1545
|
-
* (`monitor-tick
|
|
1585
|
+
* (`monitor-tick`, `monitor-error`) keyed by entry id.
|
|
1546
1586
|
*/
|
|
1547
1587
|
type RouteMonitorEvents = {
|
|
1548
|
-
/** A recalculation succeeded.
|
|
1588
|
+
/** A recalculation succeeded. The payload is the fresh snapshot. */
|
|
1549
1589
|
tick: RouteSnapshot;
|
|
1550
|
-
/** A recalculation failed
|
|
1590
|
+
/** A recalculation failed, so the monitor cleared its timer and moved to `stopped-error`. */
|
|
1551
1591
|
error: string;
|
|
1552
1592
|
};
|
|
1553
1593
|
/**
|
|
1554
|
-
*
|
|
1555
|
-
* error.
|
|
1594
|
+
* A one-shot polling loop that recalculates a single route on an interval. It owns its timer, status,
|
|
1595
|
+
* and error. Restarting it after `stop()` resets all state.
|
|
1556
1596
|
*
|
|
1557
|
-
* The monitor never knows about the entry that owns it
|
|
1558
|
-
* waypoints
|
|
1559
|
-
* `IncidentMonitor
|
|
1597
|
+
* The monitor never knows about the entry that owns it. The `recalculate` closure captures the
|
|
1598
|
+
* waypoints and params, and the caller decides what to do with each fresh snapshot. It mirrors
|
|
1599
|
+
* `IncidentMonitor`. Routes carry live traffic, so periodic recalculation keeps the entry fresh.
|
|
1560
1600
|
*
|
|
1561
1601
|
* @group Agent Toolkit
|
|
1562
1602
|
*/
|
|
@@ -1569,19 +1609,20 @@ declare class RouteMonitor {
|
|
|
1569
1609
|
private _recalculate?;
|
|
1570
1610
|
get status(): RoutePollingStatus;
|
|
1571
1611
|
get error(): string | undefined;
|
|
1572
|
-
/**
|
|
1612
|
+
/** Whether the monitor is *currently* recalculating on its interval. */
|
|
1573
1613
|
get isRunning(): boolean;
|
|
1574
|
-
/**
|
|
1614
|
+
/** Whether the monitor has any activity (running or stopped-error). */
|
|
1575
1615
|
get isActive(): boolean;
|
|
1576
1616
|
/**
|
|
1577
|
-
*
|
|
1578
|
-
* immediately
|
|
1617
|
+
* Starts polling. It captures `deps` for the lifetime of the run, fires the first recalculation
|
|
1618
|
+
* immediately unless `skipInitialTick` is set, then schedules an interval. Does nothing if
|
|
1619
|
+
* already running.
|
|
1579
1620
|
*
|
|
1580
|
-
* `skipInitialTick`
|
|
1581
|
-
*
|
|
1621
|
+
* Set `skipInitialTick` if you just calculated the route and only want the recurring refresh,
|
|
1622
|
+
* since an eager first tick would duplicate that recalculation.
|
|
1582
1623
|
*/
|
|
1583
1624
|
start(deps: RouteMonitorDeps, intervalMs?: number, skipInitialTick?: boolean): void;
|
|
1584
|
-
/**
|
|
1625
|
+
/** Stops polling and resets state. Does nothing when idle. */
|
|
1585
1626
|
stop(): void;
|
|
1586
1627
|
private _tick;
|
|
1587
1628
|
private _failed;
|
|
@@ -1651,9 +1692,9 @@ type RoutesEntry = BaseEntry<Routes> & {
|
|
|
1651
1692
|
*/
|
|
1652
1693
|
type RoutingStateEvents = {
|
|
1653
1694
|
/**
|
|
1654
|
-
*
|
|
1655
|
-
* `entries` is the full snapshot after the change
|
|
1656
|
-
* this
|
|
1695
|
+
* A calculation was stored, an analysis attached, or `reset()` cleared the history.
|
|
1696
|
+
* `entries` is the full snapshot after the change, and `changedIds` lists the ids of the
|
|
1697
|
+
* entries this change added, replaced in place, or removed.
|
|
1657
1698
|
*/
|
|
1658
1699
|
'entries-change': {
|
|
1659
1700
|
entries: readonly RoutesEntry[];
|
|
@@ -1663,28 +1704,28 @@ type RoutingStateEvents = {
|
|
|
1663
1704
|
'planning-change': readonly PlanningWaypoint[];
|
|
1664
1705
|
/** Route parameters (alternatives, cost model, depart/arrive time) changed. */
|
|
1665
1706
|
'params-change': RouteParams;
|
|
1666
|
-
/**
|
|
1707
|
+
/** The set of routes entries rendered on the map changed (multi-show under `multiple`). */
|
|
1667
1708
|
'shown-change': ReadonlySet<string>;
|
|
1668
|
-
/**
|
|
1709
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
1669
1710
|
'mode-change': EntryMode;
|
|
1670
|
-
/** Monitoring began on an entry (idle → running). Skipped
|
|
1711
|
+
/** Monitoring began on an entry (idle → running). Skipped if already running. */
|
|
1671
1712
|
'monitor-start': {
|
|
1672
1713
|
entryId: string;
|
|
1673
1714
|
};
|
|
1674
1715
|
/**
|
|
1675
|
-
* Monitoring halted on an entry. `reason: 'manual'` covers explicit `stopMonitoring` and
|
|
1676
|
-
* teardown (remove
|
|
1716
|
+
* Monitoring halted on an entry. `reason: 'manual'` covers an explicit `stopMonitoring` and
|
|
1717
|
+
* entry teardown (remove, reset). `reason: 'error'` fires alongside `monitor-error`.
|
|
1677
1718
|
*/
|
|
1678
1719
|
'monitor-stop': {
|
|
1679
1720
|
entryId: string;
|
|
1680
1721
|
reason: 'manual' | 'error';
|
|
1681
1722
|
};
|
|
1682
|
-
/** A monitored route was recalculated
|
|
1723
|
+
/** A monitored route was recalculated on a tick. The entry's data was updated in place. */
|
|
1683
1724
|
'monitor-tick': {
|
|
1684
1725
|
entryId: string;
|
|
1685
1726
|
snap: RouteSnapshot;
|
|
1686
1727
|
};
|
|
1687
|
-
/** A monitored route's recalculation failed
|
|
1728
|
+
/** A monitored route's recalculation failed, so the monitor cleared its timer and stopped. */
|
|
1688
1729
|
'monitor-error': {
|
|
1689
1730
|
entryId: string;
|
|
1690
1731
|
error: string;
|
|
@@ -1694,9 +1735,9 @@ type RoutingStateEvents = {
|
|
|
1694
1735
|
* State for route calculation, waypoint management, and route planning parameters.
|
|
1695
1736
|
*
|
|
1696
1737
|
* Each entry carries its own lazy-initialised RoutingModule (`entry._module`), so display
|
|
1697
|
-
* state lives on the entry instead of a shared slice-level module.
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1738
|
+
* state lives on the entry instead of a shared slice-level module. To render two routes at once,
|
|
1739
|
+
* show both entries. Switching the active route hides the previous entry's module without
|
|
1740
|
+
* disturbing its calculated data.
|
|
1700
1741
|
*
|
|
1701
1742
|
* @group Agent Toolkit
|
|
1702
1743
|
*/
|
|
@@ -1706,46 +1747,42 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1706
1747
|
private _planningSlots;
|
|
1707
1748
|
private _params;
|
|
1708
1749
|
private _entryMode;
|
|
1709
|
-
/**
|
|
1710
|
-
|
|
1711
|
-
* across entry swaps so the rendered route always uses the most recently requested color.
|
|
1712
|
-
* Set via {@link setColor}; persists for the lifetime of the slice (cleared on `reset`).
|
|
1713
|
-
*/
|
|
1714
|
-
private _color?;
|
|
1750
|
+
/** The knobs set on every entry's RoutingModule, `color` and `widthFactor` among them. Cleared on `reset`. */
|
|
1751
|
+
readonly knobs: SliceKnobs;
|
|
1715
1752
|
/**
|
|
1716
1753
|
* The most recently `.showEntry`-ed id. Tracks "who was last brought up" so tools that
|
|
1717
1754
|
* operate on the focused module have a single pointer to read; the authoritative shown
|
|
1718
1755
|
* set is `shownEntryIds` (derived from each entry's `_shown` flag).
|
|
1719
1756
|
*/
|
|
1720
1757
|
private _lastShownEntryId?;
|
|
1721
|
-
/**
|
|
1758
|
+
/** The state change events, listed in {@link RoutingStateEvents}. */
|
|
1722
1759
|
readonly events: StateEvents<RoutingStateEvents>;
|
|
1723
1760
|
constructor(_ttMap: TomTomMap);
|
|
1724
1761
|
/** Set of routes-entry ids currently rendered on the map. */
|
|
1725
1762
|
get shownEntryIds(): ReadonlySet<string>;
|
|
1726
1763
|
/**
|
|
1727
|
-
*
|
|
1728
|
-
* `single`
|
|
1729
|
-
* previously-shown entry
|
|
1764
|
+
* The display policy. `multiple` (default) lets several entries render side-by-side.
|
|
1765
|
+
* `single` allows at most one route on the map, so `showEntry` first hides any
|
|
1766
|
+
* previously-shown entry.
|
|
1730
1767
|
*/
|
|
1731
1768
|
get entryMode(): EntryMode;
|
|
1732
1769
|
/**
|
|
1733
|
-
*
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1770
|
+
* Switches the display policy. Moving from `multiple` to `single` hides every non-latest
|
|
1771
|
+
* entry, drops them from history, and emits `entries-change`. Does nothing if the mode
|
|
1772
|
+
* hasn't changed.
|
|
1736
1773
|
*/
|
|
1737
1774
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
1738
1775
|
/**
|
|
1739
|
-
*
|
|
1740
|
-
*
|
|
1776
|
+
* Returns an entry's RoutingModule, created on first call. Throws on unknown id. To show or
|
|
1777
|
+
* hide it, prefer the higher-level {@link showEntry} and {@link hideEntry}.
|
|
1741
1778
|
*/
|
|
1742
1779
|
getEntryRoutingModule(entryId: string): Promise<RoutingModule>;
|
|
1743
1780
|
/**
|
|
1744
|
-
*
|
|
1781
|
+
* Renders the given entry's routes and waypoints on its own RoutingModule.
|
|
1745
1782
|
*
|
|
1746
|
-
*
|
|
1747
|
-
* layers don't pile up.
|
|
1748
|
-
* rendered,
|
|
1783
|
+
* With `entryMode === 'single'`, any other shown entry is hidden first so two route
|
|
1784
|
+
* layers don't pile up. With `entryMode === 'multiple'`, previously-shown entries stay
|
|
1785
|
+
* rendered, so the caller can overlay several routes at once.
|
|
1749
1786
|
*
|
|
1750
1787
|
* Emits `shown-change` once the new entry is up. Pass `showWaypoints: false` to render the
|
|
1751
1788
|
* route lines without origin/stop/destination pins, and `showSummaryBubbles: false` to drop the
|
|
@@ -1755,29 +1792,19 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1755
1792
|
showWaypoints?: boolean;
|
|
1756
1793
|
showSummaryBubbles?: boolean;
|
|
1757
1794
|
}): Promise<void>;
|
|
1758
|
-
/** Slice-level route colour persisted across entry swaps. Undefined when none has been set. */
|
|
1759
|
-
get color(): string | undefined;
|
|
1760
|
-
/**
|
|
1761
|
-
* Set the slice-level route colour. The colour is applied immediately to every currently-shown
|
|
1762
|
-
* entry's RoutingModule and remembered so that subsequent {@link showEntry} calls apply it
|
|
1763
|
-
* automatically. Pass `undefined` to clear the sticky colour — currently-shown modules keep
|
|
1764
|
-
* their last paint until they're re-shown (MapLibre style restore handles full revert).
|
|
1765
|
-
*/
|
|
1766
|
-
setColor(color: string | undefined): void;
|
|
1767
1795
|
/**
|
|
1768
|
-
*
|
|
1769
|
-
*
|
|
1796
|
+
* Hides the entry's routes and waypoints by clearing its module, which stays cached.
|
|
1797
|
+
* Does nothing if the entry is unknown or already hidden.
|
|
1770
1798
|
*/
|
|
1771
1799
|
hideEntry(entryId: string): Promise<void>;
|
|
1772
1800
|
/**
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1801
|
+
* Drops a single entry from history. It clears the entry's routing module to hide it, then
|
|
1802
|
+
* removes it from `_entries`. Emits `entries-change`. Does nothing if the id is unknown.
|
|
1775
1803
|
*/
|
|
1776
1804
|
removeEntry(entryId: string): Promise<void>;
|
|
1777
1805
|
private _requireEntry;
|
|
1778
1806
|
/**
|
|
1779
|
-
* RoutingModule of the most
|
|
1780
|
-
* entry is currently shown.
|
|
1807
|
+
* The RoutingModule of the most recently shown entry, or undefined if no entry is shown.
|
|
1781
1808
|
*/
|
|
1782
1809
|
get currentEntryModule(): RoutingModule | undefined;
|
|
1783
1810
|
get entries(): readonly RoutesEntry[];
|
|
@@ -1790,15 +1817,15 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1790
1817
|
setWaypointAt(index: number, waypoint: WaypointLike): void;
|
|
1791
1818
|
setParams(params: Partial<RouteParams>): void;
|
|
1792
1819
|
/**
|
|
1793
|
-
*
|
|
1820
|
+
* Replaces a route entry's data in place after a monitor recalculated it. Bumps `_tick`, updates
|
|
1794
1821
|
* `data`/`timestamp`, emits `entries-change`, and re-renders the route on its module when shown.
|
|
1795
|
-
* The `_tick` guard bails if a newer tick overwrote `data` while `showRoutes` awaited.
|
|
1796
|
-
*
|
|
1822
|
+
* The `_tick` guard bails if a newer tick overwrote `data` while `showRoutes` awaited. Returns
|
|
1823
|
+
* false if the entry is unknown. Mirrors `TrafficIncidentsState.replaceEntryData`.
|
|
1797
1824
|
*/
|
|
1798
1825
|
replaceRouteData(entryId: string, routes: Routes, sampledAt: number): Promise<boolean>;
|
|
1799
1826
|
private _createMonitorForEntry;
|
|
1800
1827
|
/**
|
|
1801
|
-
*
|
|
1828
|
+
* Arms background recalculation on an entry. Lazy-creates its monitor, then starts polling with
|
|
1802
1829
|
* the caller-supplied `recalculate` closure. Emits `monitor-start` on the idle → running
|
|
1803
1830
|
* transition. Throws on unknown id.
|
|
1804
1831
|
*/
|
|
@@ -1806,13 +1833,13 @@ declare class RoutingState implements ShownEntriesSlice {
|
|
|
1806
1833
|
intervalMs?: number;
|
|
1807
1834
|
skipInitialTick?: boolean;
|
|
1808
1835
|
}): void;
|
|
1809
|
-
/**
|
|
1836
|
+
/** Stops recalculating an entry but keeps its last data. Emits `monitor-stop`. Does nothing if not running. */
|
|
1810
1837
|
stopMonitoring(entryId: string): void;
|
|
1811
|
-
/**
|
|
1838
|
+
/** Whether the entry is being recalculated on its interval. */
|
|
1812
1839
|
isMonitored(entryId: string): boolean;
|
|
1813
1840
|
/**
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
1841
|
+
* Hides every route and waypoint set on the map but keeps the history (`entries`) intact.
|
|
1842
|
+
* Implements {@link ClearableMapSlice}.
|
|
1816
1843
|
*/
|
|
1817
1844
|
clearShown(): Promise<void>;
|
|
1818
1845
|
reset(): void;
|
|
@@ -1834,10 +1861,10 @@ export interface StateSlice {
|
|
|
1834
1861
|
//#endregion
|
|
1835
1862
|
//#region src/state/trackers.d.ts
|
|
1836
1863
|
/**
|
|
1837
|
-
* The features within
|
|
1838
|
-
* `featureIds` is the matched
|
|
1839
|
-
* logic (proximity, threshold, filter)
|
|
1840
|
-
*
|
|
1864
|
+
* The features within one source entry that matched the rule, the per-entry unit of a {@link Verdict}.
|
|
1865
|
+
* `featureIds` is the matched subset, not the whole entry. A rule selects features by arbitrary sandbox
|
|
1866
|
+
* logic (proximity, threshold, filter). The entry holds every feature, so without re-running the rule
|
|
1867
|
+
* that selection can't be recovered from `entryId` alone, and the verdict records exactly what matched.
|
|
1841
1868
|
* These are the features the UI highlights and the `summary` cites.
|
|
1842
1869
|
*/
|
|
1843
1870
|
type MemberRef = {
|
|
@@ -1845,24 +1872,24 @@ type MemberRef = {
|
|
|
1845
1872
|
featureIds: string[];
|
|
1846
1873
|
};
|
|
1847
1874
|
/**
|
|
1848
|
-
* What a tracker's sandboxed `evaluateCode` returns
|
|
1849
|
-
* and read back by the reducer. `members` groups matches by source entry so a verdict can span
|
|
1850
|
-
*
|
|
1851
|
-
* incidents group
|
|
1875
|
+
* What a tracker's sandboxed `evaluateCode` returns, stored verbatim as the rule analysis's `data`
|
|
1876
|
+
* and read back by the reducer. `members` groups matches by source entry, so a verdict can span
|
|
1877
|
+
* several entry kinds. For example, "an incident within 100m of a hospital" returns a hospitals group
|
|
1878
|
+
* and an incidents group. `summary` is a grounded headline the code produces deterministically.
|
|
1852
1879
|
*/
|
|
1853
1880
|
type Verdict = {
|
|
1854
1881
|
active: boolean;
|
|
1855
1882
|
members: MemberRef[];
|
|
1856
1883
|
summary: string;
|
|
1857
1884
|
};
|
|
1858
|
-
/** Toast-worthy (`alert`)
|
|
1885
|
+
/** Toast-worthy (`alert`) or quietly-logged (`event`), discriminating events in one store. */
|
|
1859
1886
|
type TrackerEventType = 'alert' | 'event';
|
|
1860
|
-
/** Rising edge (`opened`)
|
|
1887
|
+
/** Rising edge (`opened`) or falling edge (`resolved`), the only two statuses in the rising-edge model. */
|
|
1861
1888
|
type TrackerEventStatus = 'opened' | 'resolved';
|
|
1862
|
-
/**
|
|
1889
|
+
/** A tracker crossing an edge, kept as the durable record the feed and toasts render. */
|
|
1863
1890
|
type TrackerEvent = {
|
|
1864
1891
|
id: string;
|
|
1865
|
-
/** Source-data sample time of the recompute that fired it
|
|
1892
|
+
/** Source-data sample time of the recompute that fired it, **not** wall-clock. */
|
|
1866
1893
|
at: number;
|
|
1867
1894
|
trackerId: string;
|
|
1868
1895
|
trackerName: string;
|
|
@@ -1870,39 +1897,39 @@ type TrackerEvent = {
|
|
|
1870
1897
|
kind: TrackerEventStatus;
|
|
1871
1898
|
summary: string;
|
|
1872
1899
|
members: MemberRef[];
|
|
1873
|
-
/**
|
|
1900
|
+
/** The rising-edge time of the episode this closes, present on `resolved`. */
|
|
1874
1901
|
openedAt?: number;
|
|
1875
1902
|
};
|
|
1876
1903
|
/**
|
|
1877
|
-
*
|
|
1878
|
-
* tracker's {@link Job}, not here. `affectedEntryIds` are the entries the rule watches
|
|
1879
|
-
* `members` are the ones that matched.
|
|
1904
|
+
* A tracker is one rule, a natural-language condition plus its rising-edge state. The compiled code
|
|
1905
|
+
* lives on the tracker's {@link Job}, not here. `affectedEntryIds` are the entries the rule watches,
|
|
1906
|
+
* and a verdict's `members` are the ones that matched.
|
|
1880
1907
|
*/
|
|
1881
1908
|
type Tracker = {
|
|
1882
1909
|
id: string;
|
|
1883
1910
|
name: string;
|
|
1884
|
-
/** Natural-language condition (LLM-readable)
|
|
1911
|
+
/** Natural-language condition (LLM-readable). The compiled code lives on the tracker's job. */
|
|
1885
1912
|
rule: string;
|
|
1886
|
-
/**
|
|
1913
|
+
/** The ids of every entry the rule reads, the per-entry lookup key ({@link EventsState.trackersForEntry}). */
|
|
1887
1914
|
affectedEntryIds: readonly string[];
|
|
1888
1915
|
enabled: boolean;
|
|
1889
|
-
/**
|
|
1916
|
+
/** Whether the verdict was active at the last recompute, the one bit of rising-edge memory. */
|
|
1890
1917
|
wasActive: boolean;
|
|
1891
1918
|
/** Rising-edge time of the current open episode, if active. */
|
|
1892
1919
|
openedAt?: number;
|
|
1893
1920
|
};
|
|
1894
1921
|
/** Events emitted by {@link EventsState}. */
|
|
1895
1922
|
type TrackerStateEvents = {
|
|
1896
|
-
/** The tracker set or a tracker's live state changed (create
|
|
1923
|
+
/** The tracker set or a tracker's live state changed (create, clear, enable, edge crossed). */
|
|
1897
1924
|
'trackers-change': readonly Tracker[];
|
|
1898
|
-
/** A tracker crossed an edge
|
|
1925
|
+
/** A tracker crossed an edge. The freshly-logged event drives toasts and feed appends. */
|
|
1899
1926
|
'tracker-event': TrackerEvent;
|
|
1900
1927
|
};
|
|
1901
1928
|
/**
|
|
1902
|
-
* Generic tracker store
|
|
1903
|
-
*
|
|
1904
|
-
* {@link JobEngine}
|
|
1905
|
-
* {@link Job} handle backing each tracker (`_jobs`) so pausing a tracker pauses its job.
|
|
1929
|
+
* Generic tracker store and rising-edge reducer, held on `ToolState` as `state.trackers`. It only
|
|
1930
|
+
* stores and reacts. Tools register and unregister trackers and register their rule jobs on the
|
|
1931
|
+
* {@link JobEngine}, and each job's `run` feeds verdicts here via {@link ingestVerdict}. Keeps the
|
|
1932
|
+
* {@link Job} handle backing each tracker (`_jobs`), so pausing a tracker pauses its job.
|
|
1906
1933
|
*
|
|
1907
1934
|
* @group Agent Toolkit
|
|
1908
1935
|
*/
|
|
@@ -1914,24 +1941,24 @@ declare class EventsState implements StateSlice {
|
|
|
1914
1941
|
private _seq;
|
|
1915
1942
|
readonly events: StateEvents<TrackerStateEvents>;
|
|
1916
1943
|
/**
|
|
1917
|
-
*
|
|
1918
|
-
* (`wasActive: false`) and feeds the arm-time verdict via {@link ingestVerdict}
|
|
1919
|
-
* condition already live at creation crosses false→true and fires one `opened` alert. Emits
|
|
1944
|
+
* Registers a tracker. The caller (createTracker) registers it with the rising-edge bit clear
|
|
1945
|
+
* (`wasActive: false`) and feeds the arm-time verdict via {@link ingestVerdict} after this call. A
|
|
1946
|
+
* condition already live at creation then crosses false→true and fires one `opened` alert. Emits
|
|
1920
1947
|
* `trackers-change`.
|
|
1921
1948
|
*/
|
|
1922
1949
|
register(tracker: Tracker): void;
|
|
1923
|
-
/**
|
|
1950
|
+
/** Stores the {@link Job} backing a tracker, which links it to the engine. */
|
|
1924
1951
|
setJob(trackerId: string, job: Job): void;
|
|
1925
|
-
/**
|
|
1952
|
+
/** Removes a tracker and tears down its job. */
|
|
1926
1953
|
unregister(trackerId: string): void;
|
|
1927
|
-
/**
|
|
1954
|
+
/** Pauses or resumes a tracker and its job. A paused job never recomputes or crosses edges. */
|
|
1928
1955
|
setEnabled(trackerId: string, enabled: boolean): boolean;
|
|
1929
1956
|
/** Live trackers, as copies so external mutation can't corrupt the store. */
|
|
1930
1957
|
get trackers(): readonly Tracker[];
|
|
1931
1958
|
get(trackerId: string): Tracker | undefined;
|
|
1932
1959
|
/**
|
|
1933
|
-
*
|
|
1934
|
-
* "show all trackers for this area" in the UI.
|
|
1960
|
+
* The trackers whose rule reads `entryId`, such as every tracker watching a given incidents area.
|
|
1961
|
+
* Drives "show all trackers for this area" in the UI.
|
|
1935
1962
|
*/
|
|
1936
1963
|
trackersForEntry(entryId: string): readonly Tracker[];
|
|
1937
1964
|
/**
|
|
@@ -1942,13 +1969,14 @@ declare class EventsState implements StateSlice {
|
|
|
1942
1969
|
trackerId?: string;
|
|
1943
1970
|
sinceMs?: number;
|
|
1944
1971
|
}): readonly TrackerEvent[];
|
|
1945
|
-
/**
|
|
1972
|
+
/** Clears all trackers, the log and job handles. `destroyState` calls it automatically. */
|
|
1946
1973
|
reset(): void;
|
|
1947
1974
|
/**
|
|
1948
|
-
*
|
|
1949
|
-
* on each recompute
|
|
1950
|
-
* flipping false→true logs `opened` (alert)
|
|
1951
|
-
*
|
|
1975
|
+
* Feeds a freshly computed verdict through the rising-edge reducer. The tracker's job `run` calls it
|
|
1976
|
+
* on each recompute and once at arm time. It bails fast unless the tracker is live and enabled. A
|
|
1977
|
+
* verdict flipping false→true logs `opened` (alert), and true→false logs `resolved` (event).
|
|
1978
|
+
* Active→active and inactive→inactive change nothing. `at` is the source-data sample time of the
|
|
1979
|
+
* recompute.
|
|
1952
1980
|
*/
|
|
1953
1981
|
ingestVerdict(trackerId: string, verdict: Verdict, at: number): void;
|
|
1954
1982
|
private append;
|
|
@@ -2014,29 +2042,28 @@ type TrafficAreaAnalyticsEntry = BaseEntry<TrafficAreaAnalytics> & {
|
|
|
2014
2042
|
*/
|
|
2015
2043
|
type TrafficAreaAnalyticsStateEvents = {
|
|
2016
2044
|
/**
|
|
2017
|
-
*
|
|
2018
|
-
* snapshot after the change
|
|
2019
|
-
*
|
|
2045
|
+
* An entry was added or removed, or `reset()` cleared the history. `entries` is the full
|
|
2046
|
+
* snapshot after the change, and `changedIds` lists the ids of the entries this change added,
|
|
2047
|
+
* replaced in place, or removed.
|
|
2020
2048
|
*/
|
|
2021
2049
|
'entries-change': {
|
|
2022
2050
|
entries: readonly TrafficAreaAnalyticsEntry[];
|
|
2023
2051
|
changedIds: readonly string[];
|
|
2024
2052
|
};
|
|
2025
|
-
/**
|
|
2053
|
+
/** The set of entries rendered on the map changed. */
|
|
2026
2054
|
'shown-change': ReadonlySet<string>;
|
|
2027
|
-
/**
|
|
2055
|
+
/** An entry's viz config (mode, metric, scaleMode, …) changed. */
|
|
2028
2056
|
'config-change': {
|
|
2029
2057
|
entryId: string;
|
|
2030
2058
|
config: TrafficAreaAnalyticsModuleConfig | undefined;
|
|
2031
2059
|
};
|
|
2032
|
-
/**
|
|
2060
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
2033
2061
|
'mode-change': EntryMode;
|
|
2034
2062
|
};
|
|
2035
2063
|
/**
|
|
2036
|
-
*
|
|
2037
|
-
* rendering.
|
|
2038
|
-
*
|
|
2039
|
-
* `RoutingState` / `CustomGeometriesState`.
|
|
2064
|
+
* An append-only history of traffic-area-analytics aggregations, with per-entry
|
|
2065
|
+
* rendering. As in `RoutingState` and `CustomGeometriesState`, each entry owns a
|
|
2066
|
+
* dedicated {@link TrafficAreaAnalyticsModule}, initialised lazily on first show.
|
|
2040
2067
|
*
|
|
2041
2068
|
* Live tile overlays (flow + incidents) live in {@link TrafficTilesState}.
|
|
2042
2069
|
*
|
|
@@ -2046,8 +2073,14 @@ declare class TrafficAreaAnalyticsState implements ShownEntriesSlice, StateSlice
|
|
|
2046
2073
|
private readonly _ttMap;
|
|
2047
2074
|
private _entries;
|
|
2048
2075
|
private _entryMode;
|
|
2049
|
-
/**
|
|
2076
|
+
/** The state change events, listed in {@link TrafficAreaAnalyticsStateEvents}. */
|
|
2050
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;
|
|
2051
2084
|
constructor(_ttMap: TomTomMap);
|
|
2052
2085
|
get entries(): readonly TrafficAreaAnalyticsEntry[];
|
|
2053
2086
|
get latestEntry(): TrafficAreaAnalyticsEntry | undefined;
|
|
@@ -2056,25 +2089,25 @@ declare class TrafficAreaAnalyticsState implements ShownEntriesSlice, StateSlice
|
|
|
2056
2089
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
2057
2090
|
findById(entryId: string): TrafficAreaAnalyticsEntry | undefined;
|
|
2058
2091
|
/**
|
|
2059
|
-
*
|
|
2060
|
-
*
|
|
2092
|
+
* Appends a new entry and suffixes its id on collision. In `single` mode it replaces every
|
|
2093
|
+
* older one, which is hidden and dropped from history.
|
|
2061
2094
|
*/
|
|
2062
2095
|
addEntry(data: TrafficAreaAnalytics, label: string, params: TrafficAreaAnalyticsParams, explicitId?: string): Promise<string>;
|
|
2063
2096
|
/**
|
|
2064
|
-
*
|
|
2065
|
-
* Throws on unknown id.
|
|
2097
|
+
* Initialises the entry's TrafficAreaAnalyticsModule lazily, wiring its config-change
|
|
2098
|
+
* events. Throws on unknown id.
|
|
2066
2099
|
*/
|
|
2067
2100
|
getEntryModule(entryId: string): Promise<TrafficAreaAnalyticsModule>;
|
|
2068
|
-
/**
|
|
2101
|
+
/** Renders the entry's analytics on its own module. In `single` mode, hides every other shown entry first. */
|
|
2069
2102
|
showEntry(entryId: string): Promise<void>;
|
|
2070
|
-
/**
|
|
2103
|
+
/** Hides the entry's analytics on its module. Does nothing if unknown or already hidden. */
|
|
2071
2104
|
hideEntry(entryId: string): Promise<void>;
|
|
2072
|
-
/**
|
|
2105
|
+
/** Hides a single entry, then drops it from history and emits `entries-change`. Does nothing for an unknown id. */
|
|
2073
2106
|
removeEntry(entryId: string): Promise<void>;
|
|
2074
2107
|
private _requireEntry;
|
|
2075
2108
|
/**
|
|
2076
|
-
*
|
|
2077
|
-
*
|
|
2109
|
+
* Hides every traffic-area-analytics entry on the map but keeps the history. Implements
|
|
2110
|
+
* {@link ClearableMapSlice}.
|
|
2078
2111
|
*/
|
|
2079
2112
|
clearShown(): Promise<void>;
|
|
2080
2113
|
reset(): void;
|
|
@@ -2095,7 +2128,7 @@ type IncidentsAnalysis = EntryAnalysis;
|
|
|
2095
2128
|
//#region src/state/traffic-incidents/clustering.d.ts
|
|
2096
2129
|
/** Direction a cluster's total delay is trending across recent snapshots. */
|
|
2097
2130
|
type ClusterTrend = 'growing' | 'fading' | 'steady' | 'new';
|
|
2098
|
-
/** Tuneable parameters for {@link runClustering}
|
|
2131
|
+
/** Tuneable parameters for {@link runClustering}, all optional with sensible defaults. */
|
|
2099
2132
|
type ClusteringParams = {
|
|
2100
2133
|
/** DBSCAN neighbourhood radius in km. Default: 0.5 */
|
|
2101
2134
|
eps?: number;
|
|
@@ -2107,13 +2140,13 @@ type ClusteringParams = {
|
|
|
2107
2140
|
preFilter?: {
|
|
2108
2141
|
/** Categories to exclude entirely. Default: `['roadworks', 'road-closed']` */
|
|
2109
2142
|
excludeCategories?: string[];
|
|
2110
|
-
/** Incidents with `delayInSeconds` below this are excluded
|
|
2143
|
+
/** Incidents in excludeCategories with `delayInSeconds` below this are excluded. Default: 1 (excludes 0-delay) */
|
|
2111
2144
|
minDelaySeconds?: number;
|
|
2112
2145
|
};
|
|
2113
2146
|
};
|
|
2114
2147
|
/** A single cluster produced by {@link runClustering}. */
|
|
2115
2148
|
type ClusterResult = {
|
|
2116
|
-
/**
|
|
2149
|
+
/** A stable identifier, reused across runs when member overlap >= 50%. */
|
|
2117
2150
|
id: string;
|
|
2118
2151
|
/** Geographic centre of the cluster `[lng, lat]`. */
|
|
2119
2152
|
centroid: [number, number];
|
|
@@ -2131,12 +2164,12 @@ type ClusterResult = {
|
|
|
2131
2164
|
primaryRoads: string[];
|
|
2132
2165
|
/** Most-frequent incident category across members (e.g. "jam"). */
|
|
2133
2166
|
primaryCategory: string;
|
|
2134
|
-
/** Trend across recent snapshots
|
|
2167
|
+
/** Trend across recent snapshots (see {@link classifyTrend}). */
|
|
2135
2168
|
trend: ClusterTrend;
|
|
2136
2169
|
/**
|
|
2137
|
-
* Rolling window of `totalDelaySeconds` across recent matched snapshots
|
|
2138
|
-
*
|
|
2139
|
-
* via the previous run
|
|
2170
|
+
* Rolling window of `totalDelaySeconds` across recent matched snapshots,
|
|
2171
|
+
* bounded to {@link TREND_WINDOW}. Internal trend state threaded forward
|
|
2172
|
+
* via the previous run, not display data.
|
|
2140
2173
|
*/
|
|
2141
2174
|
delaySamples: number[];
|
|
2142
2175
|
};
|
|
@@ -2146,7 +2179,7 @@ type ClusteringOutput = {
|
|
|
2146
2179
|
};
|
|
2147
2180
|
/**
|
|
2148
2181
|
* {@link runClustering} output plus the moment it was computed. The extra `sampledAt` lets the sandbox
|
|
2149
|
-
* `cluster()` primitive thread the trend window forward without the caller juggling timestamps
|
|
2182
|
+
* `cluster()` primitive thread the trend window forward without the caller juggling timestamps. It is
|
|
2150
2183
|
* stamped onto the result and read back off `previous` on the next call.
|
|
2151
2184
|
*
|
|
2152
2185
|
* @group Agent Toolkit
|
|
@@ -2178,8 +2211,8 @@ type IncidentSnapshot = {
|
|
|
2178
2211
|
incidents: TrafficIncident[];
|
|
2179
2212
|
};
|
|
2180
2213
|
/**
|
|
2181
|
-
*
|
|
2182
|
-
* poll failed and the timer
|
|
2214
|
+
* The lifecycle state of a per-entry incidents monitor. `stopped-error` means the last
|
|
2215
|
+
* poll failed and the timer was cleared. To retry, start the monitor again.
|
|
2183
2216
|
*
|
|
2184
2217
|
* @group Agent Toolkit
|
|
2185
2218
|
*/
|
|
@@ -2187,13 +2220,13 @@ type PollingStatus = 'idle' | 'running' | 'stopped-error';
|
|
|
2187
2220
|
//#endregion
|
|
2188
2221
|
//#region src/state/traffic-incidents/monitor/monitor.d.ts
|
|
2189
2222
|
/**
|
|
2190
|
-
*
|
|
2191
|
-
* `fetchIncidents` to `trafficIncidentDetails
|
|
2223
|
+
* The injected dependencies of an {@link IncidentMonitor}. Production code wires
|
|
2224
|
+
* `fetchIncidents` to `trafficIncidentDetails`. Tests can pass a deterministic fake
|
|
2192
2225
|
* and override the timer.
|
|
2193
2226
|
*
|
|
2194
|
-
* The fetcher returns
|
|
2195
|
-
*
|
|
2196
|
-
*
|
|
2227
|
+
* The fetcher returns only the incidents. The monitor stamps `takenAt` itself, so
|
|
2228
|
+
* every consumer of one tick (entry data, derived analyses, sandbox `now`) agrees
|
|
2229
|
+
* on the same canonical moment.
|
|
2197
2230
|
*
|
|
2198
2231
|
* @group Agent Toolkit
|
|
2199
2232
|
*/
|
|
@@ -2205,19 +2238,19 @@ type IncidentMonitorDeps = {
|
|
|
2205
2238
|
};
|
|
2206
2239
|
/**
|
|
2207
2240
|
* Events fired by {@link IncidentMonitor}. The slice subscribes once and re-emits
|
|
2208
|
-
* translated copies (`monitor-tick
|
|
2241
|
+
* translated copies (`monitor-tick`, `monitor-error`) keyed by entry id.
|
|
2209
2242
|
*/
|
|
2210
2243
|
type IncidentMonitorEvents = {
|
|
2211
2244
|
/** A poll succeeded. Payload: the fresh snapshot. */
|
|
2212
2245
|
tick: IncidentSnapshot;
|
|
2213
|
-
/** A poll failed
|
|
2246
|
+
/** A poll failed, so the monitor cleared its timer and moved to `stopped-error`. */
|
|
2214
2247
|
error: string;
|
|
2215
2248
|
};
|
|
2216
2249
|
/**
|
|
2217
|
-
*
|
|
2218
|
-
* and captured area.
|
|
2250
|
+
* A one-shot polling loop scoped to a single bbox. It owns its timer, status, error,
|
|
2251
|
+
* and captured area. Restarting it after `stop()` resets all state.
|
|
2219
2252
|
*
|
|
2220
|
-
* The monitor never knows about the entry that owns it
|
|
2253
|
+
* The monitor never knows about the entry that owns it. It surfaces ticks and errors
|
|
2221
2254
|
* through `events`, and the caller decides what to do with the snapshot.
|
|
2222
2255
|
*
|
|
2223
2256
|
* @group Agent Toolkit
|
|
@@ -2236,25 +2269,26 @@ declare class IncidentMonitor {
|
|
|
2236
2269
|
get monitoredArea(): MonitoredArea | undefined;
|
|
2237
2270
|
get error(): string | undefined;
|
|
2238
2271
|
/**
|
|
2239
|
-
*
|
|
2240
|
-
*
|
|
2241
|
-
*
|
|
2242
|
-
*
|
|
2272
|
+
* Whether the monitor is *currently* polling. Unlike {@link isActive}, it excludes
|
|
2273
|
+
* `stopped-error`, a state where the timer is gone but the monitor still carries an
|
|
2274
|
+
* unacknowledged error. Use this to ask "is the entry being polled right now", and
|
|
2275
|
+
* `isActive` to ask "is there anything to clean up".
|
|
2243
2276
|
*/
|
|
2244
2277
|
get isRunning(): boolean;
|
|
2245
|
-
/**
|
|
2278
|
+
/** Whether the monitor has any polling activity (running or stopped-error). */
|
|
2246
2279
|
get isActive(): boolean;
|
|
2247
2280
|
/**
|
|
2248
|
-
*
|
|
2249
|
-
* immediately
|
|
2281
|
+
* Starts polling. It captures `deps` for the lifetime of the run, fires the first tick
|
|
2282
|
+
* immediately unless `skipInitialTick` is set, then schedules an interval. Does nothing if
|
|
2283
|
+
* already running.
|
|
2250
2284
|
*
|
|
2251
|
-
* `skipInitialTick`
|
|
2252
|
-
* arming monitoring on the entry it just loaded
|
|
2253
|
-
* tick would
|
|
2285
|
+
* Set `skipInitialTick` if you just fetched the data yourself, as getTrafficIncidents does
|
|
2286
|
+
* when arming monitoring on the entry it just loaded. The entry is already fresh, so an eager
|
|
2287
|
+
* first tick would duplicate that fetch. Standalone callers leave it false, so the monitor
|
|
2254
2288
|
* produces an initial snapshot without waiting a full interval.
|
|
2255
2289
|
*/
|
|
2256
2290
|
start(area: MonitoredArea, deps: IncidentMonitorDeps, intervalMs?: number, skipInitialTick?: boolean): void;
|
|
2257
|
-
/**
|
|
2291
|
+
/** Stops polling and resets state. Does nothing when idle. */
|
|
2258
2292
|
stop(): void;
|
|
2259
2293
|
private _tick;
|
|
2260
2294
|
private _failed;
|
|
@@ -2263,12 +2297,12 @@ declare class IncidentMonitor {
|
|
|
2263
2297
|
//#endregion
|
|
2264
2298
|
//#region src/state/traffic-incidents/state.d.ts
|
|
2265
2299
|
/**
|
|
2266
|
-
* Dedicated per-entry clustering state. Incident clustering is
|
|
2300
|
+
* Dedicated per-entry clustering state. Incident clustering is **not** a generic analysis. It is typed,
|
|
2267
2301
|
* first-class incidents state with its own home here. `output` is the latest {@link SandboxClusteringOutput}
|
|
2268
|
-
* (the DBSCAN groups
|
|
2269
|
-
* `tools/state/clusters-runtime.ts`
|
|
2270
|
-
*
|
|
2271
|
-
* tools-agnostic.
|
|
2302
|
+
* (the DBSCAN groups and the moment they were computed). `recipe` is how to recompute it, and
|
|
2303
|
+
* `tools/state/clusters-runtime.ts` reuses it on each monitor tick so clusters stay live. `recipe` is
|
|
2304
|
+
* opaque here (a tools-layer `ClusterRecipe`). The slice never interprets it, which keeps the state
|
|
2305
|
+
* layer tools-agnostic.
|
|
2272
2306
|
*
|
|
2273
2307
|
* @group Agent Toolkit
|
|
2274
2308
|
*/
|
|
@@ -2327,7 +2361,7 @@ type TrafficIncidentsEntry = BaseEntry<TrafficIncident[]> & {
|
|
|
2327
2361
|
_tick?: number;
|
|
2328
2362
|
};
|
|
2329
2363
|
/**
|
|
2330
|
-
* Snapshot of an entry's focus subset
|
|
2364
|
+
* Snapshot of an entry's focus subset, returned by `getFocus` and carried by `focus-change`.
|
|
2331
2365
|
*
|
|
2332
2366
|
* @group Agent Toolkit
|
|
2333
2367
|
*/
|
|
@@ -2337,14 +2371,14 @@ type IncidentFocus = {
|
|
|
2337
2371
|
};
|
|
2338
2372
|
/**
|
|
2339
2373
|
* Events fired by {@link TrafficIncidentsState}. Subscribe via
|
|
2340
|
-
* `state.trafficIncidents.events.on(type, handler)
|
|
2374
|
+
* `state.trafficIncidents.events.on(type, handler)`, which returns an unsubscribe function.
|
|
2341
2375
|
*
|
|
2342
2376
|
* @group Agent Toolkit
|
|
2343
2377
|
*/
|
|
2344
2378
|
type TrafficIncidentsStateEvents = {
|
|
2345
2379
|
/**
|
|
2346
|
-
*
|
|
2347
|
-
* full snapshot after the change
|
|
2380
|
+
* An entry was added, replaced or removed, or `reset()` cleared the history. `entries` is the
|
|
2381
|
+
* full snapshot after the change, and `changedIds` lists the ids of the entries this change
|
|
2348
2382
|
* added, replaced in place, or removed. The {@link JobEngine} and the clustering re-run
|
|
2349
2383
|
* match these against the entries they depend on.
|
|
2350
2384
|
*/
|
|
@@ -2352,46 +2386,46 @@ type TrafficIncidentsStateEvents = {
|
|
|
2352
2386
|
entries: readonly TrafficIncidentsEntry[];
|
|
2353
2387
|
changedIds: readonly string[];
|
|
2354
2388
|
};
|
|
2355
|
-
/**
|
|
2389
|
+
/** The set of entries rendered on the map changed. */
|
|
2356
2390
|
'shown-change': ReadonlySet<TrafficIncidentsEntry['id']>;
|
|
2357
|
-
/**
|
|
2391
|
+
/** An entry's focus subset changed, or was cleared if `focus === null`. */
|
|
2358
2392
|
'focus-change': {
|
|
2359
2393
|
entryId: TrafficIncidentsEntry['id'];
|
|
2360
2394
|
focus: IncidentFocus | null;
|
|
2361
2395
|
};
|
|
2362
|
-
/**
|
|
2396
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
2363
2397
|
'mode-change': EntryMode;
|
|
2364
|
-
/** A monitored entry produced a fresh snapshot
|
|
2398
|
+
/** A monitored entry's tick produced a fresh snapshot. */
|
|
2365
2399
|
'monitor-tick': {
|
|
2366
2400
|
entryId: TrafficIncidentsEntry['id'];
|
|
2367
2401
|
snap: IncidentSnapshot;
|
|
2368
2402
|
};
|
|
2369
|
-
/** A monitored entry's poll failed
|
|
2403
|
+
/** A monitored entry's poll failed, and the slice cleared the timer. */
|
|
2370
2404
|
'monitor-error': {
|
|
2371
2405
|
entryId: TrafficIncidentsEntry['id'];
|
|
2372
2406
|
error: string;
|
|
2373
2407
|
};
|
|
2374
2408
|
/**
|
|
2375
|
-
* Polling began on an entry (idle → running). Skipped
|
|
2376
|
-
*
|
|
2409
|
+
* Polling began on an entry (idle → running). Skipped if `startMonitoring`
|
|
2410
|
+
* found the monitor already running.
|
|
2377
2411
|
*/
|
|
2378
2412
|
'monitor-start': {
|
|
2379
2413
|
entryId: TrafficIncidentsEntry['id'];
|
|
2380
2414
|
};
|
|
2381
2415
|
/**
|
|
2382
|
-
* Polling halted on an entry. `reason: 'manual'` covers explicit
|
|
2383
|
-
* `stopMonitoring` and entry teardown (remove
|
|
2384
|
-
* `reason: 'error'` fires alongside `monitor-error
|
|
2385
|
-
* keep using `monitor-error
|
|
2416
|
+
* Polling halted on an entry. `reason: 'manual'` covers an explicit
|
|
2417
|
+
* `stopMonitoring` and entry teardown (remove, single-mode trim, reset).
|
|
2418
|
+
* `reason: 'error'` fires alongside `monitor-error`. Error-only listeners
|
|
2419
|
+
* keep using `monitor-error`, and lifecycle listeners can rely on this alone.
|
|
2386
2420
|
*/
|
|
2387
2421
|
'monitor-stop': {
|
|
2388
2422
|
entryId: TrafficIncidentsEntry['id'];
|
|
2389
2423
|
reason: 'manual' | 'error';
|
|
2390
2424
|
};
|
|
2391
2425
|
/**
|
|
2392
|
-
* An entry's clustering result
|
|
2393
|
-
* UI that renders cluster pins re-derives
|
|
2394
|
-
* async to the monitor tick, so the fresh result lands here a step later.
|
|
2426
|
+
* An entry's clustering result was set, recomputed on a tick, or cleared (`clusters === null`).
|
|
2427
|
+
* UI that renders cluster pins re-derives from this, not from `entries-change`, because the
|
|
2428
|
+
* clustering re-run is async to the monitor tick, so the fresh result lands here a step later.
|
|
2395
2429
|
*/
|
|
2396
2430
|
'clusters-change': {
|
|
2397
2431
|
entryId: TrafficIncidentsEntry['id'];
|
|
@@ -2399,11 +2433,11 @@ type TrafficIncidentsStateEvents = {
|
|
|
2399
2433
|
};
|
|
2400
2434
|
};
|
|
2401
2435
|
/**
|
|
2402
|
-
* State for traffic incidents
|
|
2403
|
-
* TrafficIncidentDetailsModule. Each entry can be a separate area
|
|
2436
|
+
* State for traffic incidents, with entry history and map rendering via per-entry
|
|
2437
|
+
* TrafficIncidentDetailsModule. Each entry can be a separate area, and in the default
|
|
2404
2438
|
* `multiple` mode several entries can render at once.
|
|
2405
2439
|
*
|
|
2406
|
-
* Each entry owns its own module
|
|
2440
|
+
* Each entry owns its own module, initialised lazily on first show, plus an optional
|
|
2407
2441
|
* background monitor. Subscribe to changes via `events.on('...')`.
|
|
2408
2442
|
*
|
|
2409
2443
|
* @group Agent Toolkit
|
|
@@ -2413,84 +2447,86 @@ declare class TrafficIncidentsState implements StateSlice {
|
|
|
2413
2447
|
private _entries;
|
|
2414
2448
|
private _entryMode;
|
|
2415
2449
|
private readonly _clusters;
|
|
2416
|
-
/**
|
|
2450
|
+
/** The state change events, listed in {@link TrafficIncidentsStateEvents}. */
|
|
2417
2451
|
readonly events: StateEvents<TrafficIncidentsStateEvents>;
|
|
2452
|
+
/** The knobs set on every entry's TrafficIncidentDetailsModule. Cleared on `reset`. */
|
|
2453
|
+
readonly knobs: SliceKnobs;
|
|
2418
2454
|
constructor(_ttMap: TomTomMap);
|
|
2419
2455
|
get entries(): readonly TrafficIncidentsEntry[];
|
|
2420
2456
|
/**
|
|
2421
|
-
*
|
|
2422
|
-
* simultaneously
|
|
2423
|
-
*
|
|
2457
|
+
* The display policy. `multiple` (default) keeps every history entry available to render
|
|
2458
|
+
* simultaneously. `single` allows at most one entry on the map at a time and trims the
|
|
2459
|
+
* history to the latest entry whenever it's set.
|
|
2424
2460
|
*/
|
|
2425
2461
|
get entryMode(): EntryMode;
|
|
2426
2462
|
/**
|
|
2427
|
-
*
|
|
2428
|
-
*
|
|
2429
|
-
* mode hasn't changed.
|
|
2463
|
+
* Switches the display policy. Moving from `multiple` to `single` hides every entry older
|
|
2464
|
+
* than the latest, drops them from history, and emits `entries-change`. Does nothing if
|
|
2465
|
+
* the mode hasn't changed.
|
|
2430
2466
|
*/
|
|
2431
2467
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
2432
2468
|
/** Set of entries currently rendered on the map. */
|
|
2433
2469
|
get shownEntryIds(): ReadonlySet<TrafficIncidentsEntry['id']>;
|
|
2434
2470
|
/**
|
|
2435
|
-
*
|
|
2436
|
-
* older one
|
|
2437
|
-
* data was captured
|
|
2438
|
-
* data ↔ derived analyses) are byte-equal.
|
|
2471
|
+
* Appends a new entry to the history and returns its assigned id. In `single` mode the new
|
|
2472
|
+
* entry replaces every older one and tears down their modules and monitors. `sampledAt` is
|
|
2473
|
+
* the moment the data was captured. Pass one canonical value per "moment" so future joins
|
|
2474
|
+
* (entry data ↔ derived analyses) are byte-equal.
|
|
2439
2475
|
*/
|
|
2440
2476
|
addIncidentsEntry(data: TrafficIncident[], params: TrafficIncidentDetailsByBBoxParams & {
|
|
2441
2477
|
bbox: BBox;
|
|
2442
2478
|
}, label: string, sampledAt: number, explicitId?: string): Promise<string>;
|
|
2443
2479
|
/**
|
|
2444
|
-
*
|
|
2445
|
-
*
|
|
2446
|
-
*
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
* Returns true on success, false
|
|
2480
|
+
* Replaces an entry's data in place and repaints its module without moving the camera.
|
|
2481
|
+
* The per-entry monitor tick uses it so incident geometries and any open detail panel
|
|
2482
|
+
* stay in sync with the freshest snapshot. `sampledAt` is the canonical moment for this
|
|
2483
|
+
* update, propagated to the entry timestamp before the `entries-change` emit. That emit
|
|
2484
|
+
* drives analysis replay. The session-level {@link JobEngine} re-runs every job bound to
|
|
2485
|
+
* this entry off the change **asynchronously**, a microtask later. The slice itself owns
|
|
2486
|
+
* no analysis logic.
|
|
2487
|
+
* Returns true on success, false if the entry is unknown.
|
|
2452
2488
|
*/
|
|
2453
2489
|
replaceEntryData(entryId: TrafficIncidentsEntry['id'], data: TrafficIncident[], sampledAt: number): Promise<boolean>;
|
|
2454
2490
|
/**
|
|
2455
|
-
*
|
|
2456
|
-
* clicks
|
|
2491
|
+
* Returns the entry's TrafficIncidentDetailsModule, created on first call. To handle
|
|
2492
|
+
* clicks, subscribe on the returned module via `module.events.on('click', ...)`.
|
|
2457
2493
|
* Throws on unknown entry id.
|
|
2458
2494
|
*/
|
|
2459
2495
|
getEntryModule(entryId: TrafficIncidentsEntry['id']): Promise<TrafficIncidentDetailsModule>;
|
|
2460
2496
|
/**
|
|
2461
|
-
*
|
|
2462
|
-
*
|
|
2463
|
-
*
|
|
2497
|
+
* Renders an entry on the map. Lazy-inits its module, pushes the entry's incidents, and
|
|
2498
|
+
* fits the camera to the entry's bbox if `fitBounds` is true. Emits `shown-change` once
|
|
2499
|
+
* the entry transitions to shown.
|
|
2464
2500
|
*/
|
|
2465
2501
|
showEntry(entryId: TrafficIncidentsEntry['id'], fitBounds?: boolean): Promise<void>;
|
|
2466
2502
|
/**
|
|
2467
|
-
*
|
|
2468
|
-
* entry for cheap re-show.
|
|
2503
|
+
* Hides an entry by clearing its module and dropping focus. The module reference stays
|
|
2504
|
+
* on the entry for cheap re-show. Does nothing if the entry is unknown or already hidden.
|
|
2469
2505
|
*/
|
|
2470
2506
|
hideEntry(entryId: TrafficIncidentsEntry['id']): Promise<void>;
|
|
2471
2507
|
/**
|
|
2472
|
-
*
|
|
2473
|
-
*
|
|
2474
|
-
*
|
|
2508
|
+
* Drops an entry from history, hiding it from the map and stopping any monitor. Emits
|
|
2509
|
+
* `entries-change`, plus `shown-change` if the entry was shown. Does nothing if the id
|
|
2510
|
+
* is unknown.
|
|
2475
2511
|
*/
|
|
2476
2512
|
removeEntry(entryId: TrafficIncidentsEntry['id']): Promise<void>;
|
|
2477
2513
|
/**
|
|
2478
|
-
*
|
|
2479
|
-
* unknown
|
|
2480
|
-
* and its monitor-tick re-run (`tools/state/clusters-runtime.ts`).
|
|
2514
|
+
* Stores or replaces an entry's clustering record and emits `clusters-change`. Does nothing if the
|
|
2515
|
+
* entry is unknown, because clusters are entry-scoped and an orphan record is meaningless.
|
|
2516
|
+
* `clusterIncidents` and its monitor-tick re-run (`tools/state/clusters-runtime.ts`) call it.
|
|
2481
2517
|
*/
|
|
2482
2518
|
setClusters(entryId: TrafficIncidentsEntry['id'], record: ClustersRecord): void;
|
|
2483
|
-
/**
|
|
2519
|
+
/** The latest clustering output for an entry, or undefined if none was computed. */
|
|
2484
2520
|
getClusters(entryId: TrafficIncidentsEntry['id']): SandboxClusteringOutput | undefined;
|
|
2485
|
-
/**
|
|
2521
|
+
/** The full clustering record (recipe and output) for an entry, which the re-run reads back. */
|
|
2486
2522
|
getClustersRecord(entryId: TrafficIncidentsEntry['id']): ClustersRecord | undefined;
|
|
2487
|
-
/**
|
|
2523
|
+
/** Drops an entry's clustering and emits `clusters-change` with `null`. Does nothing if none is stored. */
|
|
2488
2524
|
clearClusters(entryId: TrafficIncidentsEntry['id']): void;
|
|
2489
|
-
/** Snapshot of an entry's focus subset, or null
|
|
2525
|
+
/** Snapshot of an entry's focus subset, or null if no focus is active or the entry is unknown. */
|
|
2490
2526
|
getFocus(entryId: TrafficIncidentsEntry['id']): IncidentFocus | null;
|
|
2491
2527
|
/**
|
|
2492
|
-
*
|
|
2493
|
-
* incidents
|
|
2528
|
+
* Sets the focus subset on a specific entry. Filters ids against the entry's current
|
|
2529
|
+
* incidents, dropping unknown ones, and pushes the result onto the entry's module.
|
|
2494
2530
|
* Returns the kept count and any dropped ids.
|
|
2495
2531
|
*/
|
|
2496
2532
|
setFocus(entryId: TrafficIncidentsEntry['id'], ids: readonly string[], reason?: string): {
|
|
@@ -2499,46 +2535,46 @@ declare class TrafficIncidentsState implements StateSlice {
|
|
|
2499
2535
|
};
|
|
2500
2536
|
clearFocus(entryId: TrafficIncidentsEntry['id']): void;
|
|
2501
2537
|
/**
|
|
2502
|
-
* The focused incidents in the order passed to {@link setFocus}
|
|
2503
|
-
* active on the entry or
|
|
2504
|
-
*
|
|
2538
|
+
* The focused incidents in the order passed to {@link setFocus}, or empty if no focus is
|
|
2539
|
+
* active on the entry or the entry is unknown. UI layers use it to step through the
|
|
2540
|
+
* focused subset (prev/next).
|
|
2505
2541
|
*/
|
|
2506
2542
|
focusedFeatures(entryId: TrafficIncidentsEntry['id']): TrafficIncident[];
|
|
2507
2543
|
/**
|
|
2508
|
-
*
|
|
2509
|
-
* indices so callers can pass raw prev/next counters.
|
|
2510
|
-
* focus. Line geometries fitBounds
|
|
2544
|
+
* Flies the camera to the i-th focused incident on an entry (0-based). Wraps out-of-range
|
|
2545
|
+
* indices, so callers can pass raw prev/next counters. Does nothing if the entry has no active
|
|
2546
|
+
* focus. Line geometries use fitBounds, points flyTo with a sensible zoom.
|
|
2511
2547
|
*/
|
|
2512
2548
|
navigateFocus(entryId: TrafficIncidentsEntry['id'], index: number): void;
|
|
2513
2549
|
/**
|
|
2514
|
-
*
|
|
2515
|
-
*
|
|
2550
|
+
* Walks entries newest-first to find the one that holds an incident with this id. UI layers
|
|
2551
|
+
* use it when they hold an incident id without remembering which entry produced it.
|
|
2516
2552
|
*/
|
|
2517
2553
|
findEntryWithIncident(incidentId: string): TrafficIncidentsEntry | undefined;
|
|
2518
2554
|
/**
|
|
2519
|
-
*
|
|
2520
|
-
* once, then delegates to {@link IncidentMonitor.start}.
|
|
2555
|
+
* Starts polling for an entry. Lazy-creates an {@link IncidentMonitor}, wires its events
|
|
2556
|
+
* once, then delegates to {@link IncidentMonitor.start}. Does nothing if polling is already
|
|
2521
2557
|
* running. Throws on unknown entry id.
|
|
2522
2558
|
*/
|
|
2523
2559
|
startMonitoring(entryId: TrafficIncidentsEntry['id'], area: MonitoredArea, deps: IncidentMonitorDeps, opts?: {
|
|
2524
2560
|
intervalMs?: number;
|
|
2525
2561
|
skipInitialTick?: boolean;
|
|
2526
2562
|
}): void;
|
|
2527
|
-
/**
|
|
2563
|
+
/** Stops polling. Does nothing if idle or unknown. */
|
|
2528
2564
|
stopMonitoring(entryId: TrafficIncidentsEntry['id']): void;
|
|
2529
2565
|
/**
|
|
2530
|
-
*
|
|
2531
|
-
* `stopped-error` returns false here so the start tool can report a truthful
|
|
2566
|
+
* Whether the entry is *currently* being polled. A monitor stuck in
|
|
2567
|
+
* `stopped-error` returns false here, so the start tool can report a truthful
|
|
2532
2568
|
* `alreadyRunning` and a fresh `start` call actually re-arms the timer
|
|
2533
|
-
* instead of silently
|
|
2569
|
+
* instead of silently doing nothing.
|
|
2534
2570
|
*/
|
|
2535
2571
|
isMonitored(entryId: TrafficIncidentsEntry['id']): boolean;
|
|
2536
2572
|
private _createMonitorForEntry;
|
|
2537
2573
|
private _requireEntry;
|
|
2538
2574
|
private _teardownEntry;
|
|
2539
2575
|
/**
|
|
2540
|
-
*
|
|
2541
|
-
*
|
|
2576
|
+
* Hides every traffic-incidents entry on the map but keeps the history. Implements
|
|
2577
|
+
* {@link ClearableMapSlice}.
|
|
2542
2578
|
*/
|
|
2543
2579
|
clearShown(): Promise<void>;
|
|
2544
2580
|
reset(): void;
|
|
@@ -2546,9 +2582,9 @@ declare class TrafficIncidentsState implements StateSlice {
|
|
|
2546
2582
|
//#endregion
|
|
2547
2583
|
//#region src/state/traffic-tiles/state.d.ts
|
|
2548
2584
|
/**
|
|
2549
|
-
* State for traffic tile overlays
|
|
2550
|
-
* raster/tile layers that the user toggles on top of the base map
|
|
2551
|
-
* per-result rendering for incident *features*
|
|
2585
|
+
* State for traffic tile overlays, the flow tiles and incident overlay tiles. These are
|
|
2586
|
+
* raster/tile layers that the user toggles on top of the base map. Result caching and
|
|
2587
|
+
* per-result rendering for incident *features* live in {@link TrafficIncidentsState},
|
|
2552
2588
|
* and analytics aggregations in {@link TrafficAreaAnalyticsState}.
|
|
2553
2589
|
*
|
|
2554
2590
|
* @group Agent Toolkit
|
|
@@ -2585,15 +2621,15 @@ export declare const hidePreviousShownEntries: (slice: ShownEntriesSlice, keepEn
|
|
|
2585
2621
|
*/
|
|
2586
2622
|
export type QueryAs = 'poi' | 'place';
|
|
2587
2623
|
/**
|
|
2588
|
-
* Resolves a query string to up to `limit` Places
|
|
2589
|
-
* otherwise.
|
|
2624
|
+
* Resolves a query string to up to `limit` Places, using POI search when `queryAs === 'poi'`,
|
|
2625
|
+
* otherwise geocoding. The optional `bias` narrows the search to a region.
|
|
2590
2626
|
*/
|
|
2591
2627
|
export declare const locatePlaces: (query: string, queryAs: QueryAs, options: {
|
|
2592
2628
|
limit: number;
|
|
2593
2629
|
bias?: GeoBias;
|
|
2594
2630
|
}, execOptions?: ToolExecuteOptions) => Promise<Place[]>;
|
|
2595
2631
|
/**
|
|
2596
|
-
*
|
|
2632
|
+
* Finds the best match for a query as the `locatePlace` tool does, for a custom tool that needs one place.
|
|
2597
2633
|
* A failed or cancelled request rejects, so catch it in `execute`.
|
|
2598
2634
|
*
|
|
2599
2635
|
* @param bias - Favours results near a position, such as the map centre from {@link getViewportBias}.
|
|
@@ -2616,7 +2652,7 @@ export declare const locatePlace: (query: string, queryAs: QueryAs, bias?: GeoBi
|
|
|
2616
2652
|
//#region src/tools/shared/location-input.d.ts
|
|
2617
2653
|
/** @ignore */
|
|
2618
2654
|
export type ResolvedLocation = {
|
|
2619
|
-
/**
|
|
2655
|
+
/** A resolved Place with address metadata, or a bare [lng, lat] tuple. */
|
|
2620
2656
|
place: WaypointLike;
|
|
2621
2657
|
position: Position;
|
|
2622
2658
|
name: string;
|
|
@@ -2749,8 +2785,8 @@ export type ResolvedEntries = {
|
|
|
2749
2785
|
trafficAreaAnalytics: TrafficAreaAnalyticsEntry[];
|
|
2750
2786
|
byod: BYODEntry[];
|
|
2751
2787
|
};
|
|
2752
|
-
/** Newest `timestamp` across every resolved source entry, or undefined when none carry one
|
|
2753
|
-
* canonical `sampledAt` for a recurring sandbox run over these inputs. */
|
|
2788
|
+
/** Newest `timestamp` across every resolved source entry, or undefined when none carry one, as
|
|
2789
|
+
* the canonical `sampledAt` for a recurring sandbox run over these inputs. */
|
|
2754
2790
|
export declare const latestTimestamp: (resolved: ResolvedEntries) => number | undefined;
|
|
2755
2791
|
/**
|
|
2756
2792
|
* Sandbox-facing inputs. Each kind is exposed as a single `<kind>ByEntry` record keyed by the entry id
|
|
@@ -2775,9 +2811,9 @@ export type SandboxInputs = {
|
|
|
2775
2811
|
incidentsByEntry: Record<string, TrafficIncident[]> | undefined;
|
|
2776
2812
|
/**
|
|
2777
2813
|
* Per-source polygons collected from every requested source (place / places / ranges / customGeometries).
|
|
2778
|
-
*
|
|
2779
|
-
* `place`
|
|
2780
|
-
* its origin in `properties._source` (`{ kind, id }`).
|
|
2814
|
+
* The key is the tagged source `${kind}:${id}`, not a bare id, since the same id can recur across kinds
|
|
2815
|
+
* (e.g. a `place` and a `customGeometries` entry). This keeps the kind unambiguous. Each feature also
|
|
2816
|
+
* self-describes its origin in `properties._source` (`{ kind, id }`).
|
|
2781
2817
|
*/
|
|
2782
2818
|
geometriesByEntry: Record<string, PolygonFeature[]> | undefined;
|
|
2783
2819
|
/**
|
|
@@ -2787,7 +2823,7 @@ export type SandboxInputs = {
|
|
|
2787
2823
|
*/
|
|
2788
2824
|
trafficAreaAnalyticsByEntry: Record<string, TrafficAreaAnalytics> | undefined;
|
|
2789
2825
|
/**
|
|
2790
|
-
* Per-entry BYOD, keyed by entry id. Each value is a FeatureCollection
|
|
2826
|
+
* Per-entry BYOD, keyed by entry id. Each value is a FeatureCollection. Mixed geometry types are normal
|
|
2791
2827
|
* (BYOD layers can be Point / LineString / Polygon).
|
|
2792
2828
|
*/
|
|
2793
2829
|
byodByEntry: Record<string, FeatureCollection$1> | undefined;
|
|
@@ -2835,21 +2871,20 @@ export declare const prepareMultiInputs: (ids: MultiInputIds, state: ToolState)
|
|
|
2835
2871
|
*/
|
|
2836
2872
|
export declare const BY_ENTRY_VIEWS_DOC: string;
|
|
2837
2873
|
/**
|
|
2838
|
-
* Names injected into the sandbox by analyseData
|
|
2874
|
+
* Names injected into the sandbox by analyseData, processData, createTracker and clusterIncidents, in fixed order.
|
|
2839
2875
|
*
|
|
2840
2876
|
* @ignore
|
|
2841
2877
|
*/
|
|
2842
2878
|
export declare const MULTI_INPUT_SANDBOX_PARAMS: readonly ["placesByEntry", "routesByEntry", "incidentsByEntry", "geometriesByEntry", "trafficAreaAnalyticsByEntry", "byodByEntry", "h3", "turf", "routeUtils", "cluster"];
|
|
2843
2879
|
/**
|
|
2844
2880
|
* Common "tools available in the sandbox" prompt section, shared verbatim by
|
|
2845
|
-
* analyseData and
|
|
2846
|
-
*
|
|
2847
|
-
*
|
|
2848
|
-
* the cross-kind turf cheat-sheet ({@link CROSS_KIND_OPS_DOC})
|
|
2849
|
-
* ({@link ROUTE_UTILS_DOC})
|
|
2850
|
-
*
|
|
2851
|
-
*
|
|
2852
|
-
* a block ending in a blank line, ready to drop straight into either tool's `code` doc.
|
|
2881
|
+
* analyseData, processData, clusterIncidents and createTracker so the injected-library docs
|
|
2882
|
+
* live in ONE place and the tools never drift. It documents `turf` / `h3` (base usage rules
|
|
2883
|
+
* via {@link buildSandboxCodePrompt}) and the per-entry input views. With `scoped`, the helper
|
|
2884
|
+
* docs follow the active kinds: the cross-kind turf cheat-sheet ({@link CROSS_KIND_OPS_DOC})
|
|
2885
|
+
* when more than one is active, `routeUtils` ({@link ROUTE_UTILS_DOC}) with `routes`, and
|
|
2886
|
+
* `cluster` with `incidents`. Returns a block ending in a blank line, ready to drop straight
|
|
2887
|
+
* into a tool's `code` doc.
|
|
2853
2888
|
*
|
|
2854
2889
|
* @ignore
|
|
2855
2890
|
*/
|
|
@@ -3224,7 +3259,7 @@ export declare const areaWhereSchema: z.ZodObject<{
|
|
|
3224
3259
|
widthMeters: z.ZodNumber;
|
|
3225
3260
|
}, z.core.$strip>>;
|
|
3226
3261
|
}, z.core.$strip>;
|
|
3227
|
-
/** The `where` fields resolve-where.ts resolves
|
|
3262
|
+
/** The `where` fields resolve-where.ts resolves, inferred from {@link areaWhereSchema}. */
|
|
3228
3263
|
export type AreaWhere = z.infer<typeof areaWhereSchema>;
|
|
3229
3264
|
//#endregion
|
|
3230
3265
|
//#region src/tools/shared/resolve-where.d.ts
|
|
@@ -3255,8 +3290,8 @@ export declare const resolveGlobal: () => ResolvedBias;
|
|
|
3255
3290
|
export type ResolvedArea = {
|
|
3256
3291
|
bbox: BBox;
|
|
3257
3292
|
polygon?: Polygon | MultiPolygon;
|
|
3258
|
-
/** The
|
|
3259
|
-
* data was actually loaded for,
|
|
3293
|
+
/** The grounded match label (`freeformAddress, <countryCode>` for a `query` area), meaning what the
|
|
3294
|
+
* data was actually loaded for, not the query echo. It lets a consumer surface where a query really
|
|
3260
3295
|
* resolved. */
|
|
3261
3296
|
label?: string;
|
|
3262
3297
|
source: AreaSource;
|
|
@@ -3283,12 +3318,12 @@ export declare const isResolveError: (r: unknown) => r is ResolveError;
|
|
|
3283
3318
|
* @module agent-toolkit-tools
|
|
3284
3319
|
*
|
|
3285
3320
|
* The `routeUtils` namespace injected into sandboxed model-authored code, so a routes input can be
|
|
3286
|
-
* sliced and measured without re-implementing it.
|
|
3287
|
-
* (`sandbox/sdk-utils-worker-entry.ts`) is bundled standalone at SDK build time,
|
|
3321
|
+
* sliced and measured without re-implementing it. It has its own module because the worker entry
|
|
3322
|
+
* (`sandbox/sdk-utils-worker-entry.ts`) is bundled standalone at SDK build time, and importing it
|
|
3288
3323
|
* from `multi-input.ts` would pull that module's prompt text into the worker bundle.
|
|
3289
3324
|
*
|
|
3290
|
-
* Every function here depends only on `@turf/turf`
|
|
3291
|
-
* pure local helpers, which
|
|
3325
|
+
* Every function here depends only on `@turf/turf` (available in the worker as `self.turf`) and
|
|
3326
|
+
* pure local helpers, which makes the set portable into the sandbox.
|
|
3292
3327
|
*/
|
|
3293
3328
|
/**
|
|
3294
3329
|
* @ignore
|
|
@@ -3308,8 +3343,8 @@ export declare const routeUtils: {
|
|
|
3308
3343
|
*
|
|
3309
3344
|
* Compact schema documentation for the `Route` properties shape, reused by
|
|
3310
3345
|
* every tool whose LLM-authored code reads a Routes FeatureCollection
|
|
3311
|
-
* (`analyseData`, `processData`)
|
|
3312
|
-
* Only the non-GeoJSON-standard bits are spelled out
|
|
3346
|
+
* (`analyseData`, `processData`), injected per entry as `routesByEntry[id]`.
|
|
3347
|
+
* Only the non-GeoJSON-standard bits are spelled out, since `Route` is a LineString Feature.
|
|
3313
3348
|
*/
|
|
3314
3349
|
/** @ignore */
|
|
3315
3350
|
export declare const ROUTES_SCHEMA_DOC: string;
|
|
@@ -3348,7 +3383,7 @@ export declare const showResultsOnMap: (state: ToolState, placesEntryIds: readon
|
|
|
3348
3383
|
//#endregion
|
|
3349
3384
|
//#region src/tools/shared/tool-state-where-context.d.ts
|
|
3350
3385
|
/** Adapts the live `ToolState` to the narrow `WhereContext` the resolver depends on. Keeping this
|
|
3351
|
-
* mapping in one place
|
|
3386
|
+
* mapping in one place lets resolveAreas stay testable without a ToolState. */
|
|
3352
3387
|
export declare const toolStateToWhereContext: (state: ToolState, options?: ToolExecuteOptions) => WhereContext;
|
|
3353
3388
|
//#endregion
|
|
3354
3389
|
//#region src/tools/shared/viewport-bias.d.ts
|
|
@@ -3359,8 +3394,8 @@ export declare const toolStateToWhereContext: (state: ToolState, options?: ToolE
|
|
|
3359
3394
|
*/
|
|
3360
3395
|
export declare const MIN_VIEWPORT_BIAS_ZOOM = 6;
|
|
3361
3396
|
/**
|
|
3362
|
-
*
|
|
3363
|
-
* {@link locatePlace}'s `bias`. Below `minZoom
|
|
3397
|
+
* Returns the map centre, to favour search results in view. Pass it as `{ position }` to a service's `geoBias`
|
|
3398
|
+
* or to {@link locatePlace}'s `bias`. Below `minZoom`, the view is too wide to say where the user means.
|
|
3364
3399
|
*
|
|
3365
3400
|
* @param map - The agent's base-map slice, `state.baseMap` in a tool's `execute`.
|
|
3366
3401
|
* @returns The centre as `[longitude, latitude]`, or `undefined` below `minZoom`.
|
|
@@ -3410,8 +3445,6 @@ type CustomGeometriesEntry = BaseEntry<PolygonFeature[]> & {
|
|
|
3410
3445
|
* module. Lazy-initialised via CustomGeometriesState helpers.
|
|
3411
3446
|
*/
|
|
3412
3447
|
_module?: GeometriesModule;
|
|
3413
|
-
/** Fill style that the geometries module is currently configured with. */
|
|
3414
|
-
_shownFillStyle?: GeometryFillStyle;
|
|
3415
3448
|
/** True while this entry's `_module` is rendering on the map. */
|
|
3416
3449
|
_shown?: boolean;
|
|
3417
3450
|
};
|
|
@@ -3425,26 +3458,26 @@ type CustomGeometriesEntry = BaseEntry<PolygonFeature[]> & {
|
|
|
3425
3458
|
*/
|
|
3426
3459
|
type CustomGeometriesStateEvents = {
|
|
3427
3460
|
/**
|
|
3428
|
-
*
|
|
3429
|
-
* the change
|
|
3461
|
+
* An entry was added, or `reset()` cleared the history. `entries` is the full snapshot after
|
|
3462
|
+
* the change, and `changedIds` lists the ids of the entries this change added, replaced in
|
|
3430
3463
|
* place, or removed.
|
|
3431
3464
|
*/
|
|
3432
3465
|
'entries-change': {
|
|
3433
3466
|
entries: readonly CustomGeometriesEntry[];
|
|
3434
3467
|
changedIds: readonly string[];
|
|
3435
3468
|
};
|
|
3436
|
-
/**
|
|
3469
|
+
/** The set of entries rendered on the map changed. */
|
|
3437
3470
|
'shown-change': ReadonlySet<string>;
|
|
3438
|
-
/**
|
|
3471
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
3439
3472
|
'mode-change': EntryMode;
|
|
3440
3473
|
};
|
|
3441
3474
|
/**
|
|
3442
|
-
*
|
|
3475
|
+
* The state for derived or custom geometries, the output of `processData` and any future
|
|
3443
3476
|
* polygon-producing tool whose result doesn't belong to a place or a reachable-range entry.
|
|
3444
3477
|
*
|
|
3445
|
-
*
|
|
3446
|
-
*
|
|
3447
|
-
*
|
|
3478
|
+
* As in {@link RangeState}, each entry owns a dedicated GeometriesModule, initialised lazily
|
|
3479
|
+
* on first show. Provenance metadata captures the input sources (tagged ids) and the
|
|
3480
|
+
* operation that produced the polygons.
|
|
3448
3481
|
*
|
|
3449
3482
|
* @group Agent Toolkit
|
|
3450
3483
|
*/
|
|
@@ -3452,48 +3485,53 @@ declare class CustomGeometriesState implements ShownEntriesSlice, StateSlice {
|
|
|
3452
3485
|
private readonly _ttMap;
|
|
3453
3486
|
private _entries;
|
|
3454
3487
|
private _entryMode;
|
|
3455
|
-
/**
|
|
3488
|
+
/** The state change events, listed in {@link CustomGeometriesStateEvents}. */
|
|
3456
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;
|
|
3457
3492
|
constructor(_ttMap: TomTomMap);
|
|
3458
3493
|
get entries(): readonly CustomGeometriesEntry[];
|
|
3459
3494
|
get latestEntry(): CustomGeometriesEntry | undefined;
|
|
3460
3495
|
/** Set of custom-geometries entry ids currently rendered on the map. */
|
|
3461
3496
|
get shownEntryIds(): ReadonlySet<string>;
|
|
3462
3497
|
/**
|
|
3463
|
-
*
|
|
3464
|
-
* by side
|
|
3498
|
+
* The display policy. `multiple` (default) lets several derived-geometry entries render
|
|
3499
|
+
* side by side. `single` allows at most one entry on the map, and switching to it hides
|
|
3465
3500
|
* older entries.
|
|
3466
3501
|
*/
|
|
3467
3502
|
get entryMode(): EntryMode;
|
|
3468
3503
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
3469
3504
|
findById(entryId: string): CustomGeometriesEntry | undefined;
|
|
3470
3505
|
/**
|
|
3471
|
-
*
|
|
3472
|
-
*
|
|
3506
|
+
* Appends a new entry and returns its assigned id. If `explicitId` collides, the slice adds a
|
|
3507
|
+
* suffix (`-2`, `-3`, ...). In `single` mode the new entry replaces every older one.
|
|
3473
3508
|
*/
|
|
3474
3509
|
addEntry(features: PolygonFeature<CommonPlaceProps>[], provenance: CustomGeometriesEntry['provenance'], label: string, explicitId?: string): Promise<string>;
|
|
3475
|
-
/**
|
|
3510
|
+
/**
|
|
3511
|
+
* Initialises the entry's GeometriesModule lazily. Updates only the fill style when it changes,
|
|
3512
|
+
* keeping the styling applied since.
|
|
3513
|
+
*/
|
|
3476
3514
|
getEntryGeometriesModule(entryId: string, fillStyle?: GeometryFillStyle): Promise<GeometriesModule>;
|
|
3477
3515
|
/**
|
|
3478
|
-
*
|
|
3479
|
-
* - `'replace'` (default)
|
|
3480
|
-
* entry's module
|
|
3481
|
-
* - `'add'`
|
|
3482
|
-
*
|
|
3516
|
+
* Renders the entry's polygons. `mode` applies to this entry's own layer only:
|
|
3517
|
+
* - `'replace'` (default) shows exactly `entry.data` and clears whatever the
|
|
3518
|
+
* entry's module rendered before.
|
|
3519
|
+
* - `'add'` merges `entry.data` with the polygons shown on this entry's layer,
|
|
3520
|
+
* deduped by feature id. It matters mostly when re-showing the same entry.
|
|
3483
3521
|
*
|
|
3484
|
-
*
|
|
3485
|
-
*
|
|
3486
|
-
*
|
|
3522
|
+
* Other entries are handled separately. With `entryMode === 'single'`, other shown
|
|
3523
|
+
* entries are hidden first. Otherwise the caller uses `hideEntry` or the tools'
|
|
3524
|
+
* `hidePreviousEntries` option.
|
|
3487
3525
|
*/
|
|
3488
3526
|
showEntry(entryId: string, fillStyle?: GeometryFillStyle, mode?: 'add' | 'replace'): Promise<void>;
|
|
3489
3527
|
private _hideOthersUnderSingleMode;
|
|
3490
3528
|
hideEntry(entryId: string): Promise<void>;
|
|
3491
|
-
/**
|
|
3529
|
+
/** Clears an entry's module, then drops the entry from history. Does nothing for an unknown id. */
|
|
3492
3530
|
removeEntry(entryId: string): Promise<void>;
|
|
3493
3531
|
private _requireEntry;
|
|
3494
3532
|
/**
|
|
3495
|
-
*
|
|
3496
|
-
*
|
|
3533
|
+
* Hides every custom-geometries entry on the map but keeps the history. Implements
|
|
3534
|
+
* {@link ClearableMapSlice}.
|
|
3497
3535
|
*/
|
|
3498
3536
|
clearShown(): Promise<void>;
|
|
3499
3537
|
reset(): void;
|
|
@@ -3501,16 +3539,16 @@ declare class CustomGeometriesState implements ShownEntriesSlice, StateSlice {
|
|
|
3501
3539
|
//#endregion
|
|
3502
3540
|
//#region src/state/state.d.ts
|
|
3503
3541
|
/**
|
|
3504
|
-
*
|
|
3505
|
-
* map at once
|
|
3506
|
-
* `single` automatically drops every entry except the latest
|
|
3542
|
+
* The per-slice display policy. With `multiple` (default), several history entries can be on the
|
|
3543
|
+
* map at once. With `single`, only the most recent one stays. Switching from `multiple` to
|
|
3544
|
+
* `single` automatically drops every entry except the latest and clears their modules, so
|
|
3507
3545
|
* the map matches the new policy immediately.
|
|
3508
3546
|
*
|
|
3509
3547
|
* @group Agent Toolkit
|
|
3510
3548
|
*/
|
|
3511
3549
|
type EntryMode = 'single' | 'multiple';
|
|
3512
3550
|
/**
|
|
3513
|
-
*
|
|
3551
|
+
* A state slice that owns a history of entries and can be set to `single` or `multiple`
|
|
3514
3552
|
* mode. Every {@link ToolState} slice with `setEntryMode` implements this shape, which lets
|
|
3515
3553
|
* callers (the `setEntryMode` tool, `createMapAgent`'s `dataEntries` option, …) handle the
|
|
3516
3554
|
* whole family uniformly without listing slice names.
|
|
@@ -3525,12 +3563,12 @@ interface EntryModeSlice {
|
|
|
3525
3563
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
3526
3564
|
}
|
|
3527
3565
|
/**
|
|
3528
|
-
*
|
|
3529
|
-
*
|
|
3566
|
+
* The data-entry kind names that `dataEntries` on `createMapAgent` uses. They extend the
|
|
3567
|
+
* analyse/process input kinds (`EntryDataKind`) with `ranges`, which has its own
|
|
3530
3568
|
* entry-mode-supporting slice but is not a top-level input kind for those tools.
|
|
3531
3569
|
*
|
|
3532
|
-
* The kind names are LLM-facing (`routes`, `incidents`)
|
|
3533
|
-
* `trafficIncidents`)
|
|
3570
|
+
* The kind names are LLM-facing (`routes`, `incidents`) instead of slice names (`routing`,
|
|
3571
|
+
* `trafficIncidents`). The slice mapping is internal (see {@link DATA_ENTRY_KIND_TO_SLICE}).
|
|
3534
3572
|
*
|
|
3535
3573
|
* @group Agent Toolkit
|
|
3536
3574
|
*/
|
|
@@ -3543,22 +3581,22 @@ type DataEntryKind = 'places' | 'routes' | 'incidents' | 'customGeometries' | 't
|
|
|
3543
3581
|
type DataEntryConfig = {
|
|
3544
3582
|
/**
|
|
3545
3583
|
* When `false`, the kind is removed from the agent's tool surface entirely:
|
|
3546
|
-
* -
|
|
3547
|
-
* -
|
|
3584
|
+
* - The kind disappears from the `analyseData` and `processData` scope and input fields.
|
|
3585
|
+
* - Related recall, display and fetch tools are dropped from the registry
|
|
3548
3586
|
* (see {@link TOOLS_BY_DATA_ENTRY_KIND}).
|
|
3549
3587
|
*
|
|
3550
|
-
*
|
|
3588
|
+
* Defaults to `true`.
|
|
3551
3589
|
*/
|
|
3552
3590
|
enabled?: boolean;
|
|
3553
3591
|
/**
|
|
3554
|
-
*
|
|
3555
|
-
* entry on the map
|
|
3592
|
+
* The initial entry-display policy for the underlying slice. `single` keeps only the latest
|
|
3593
|
+
* entry on the map and hides the others. `multiple` (default) lets several coexist.
|
|
3556
3594
|
*/
|
|
3557
3595
|
entryMode?: EntryMode;
|
|
3558
3596
|
};
|
|
3559
3597
|
/**
|
|
3560
|
-
*
|
|
3561
|
-
*
|
|
3598
|
+
* Maps each {@link DataEntryKind} (LLM-facing name) to the {@link ToolState} slice key that
|
|
3599
|
+
* owns its entries. `createMapAgent` uses it to apply `entryMode` from
|
|
3562
3600
|
* `dataEntries[kind].entryMode` to the right slice.
|
|
3563
3601
|
*
|
|
3564
3602
|
* @group Agent Toolkit
|
|
@@ -3573,34 +3611,33 @@ export declare const DATA_ENTRY_KIND_TO_SLICE: {
|
|
|
3573
3611
|
readonly ranges: "ranges";
|
|
3574
3612
|
};
|
|
3575
3613
|
/**
|
|
3576
|
-
*
|
|
3577
|
-
* Names match the {@link ToolState} keys exactly
|
|
3578
|
-
* `customGeometries` (not `geometries`)
|
|
3614
|
+
* The compile-time union of {@link ToolState} keys whose slice supports {@link EntryMode}.
|
|
3615
|
+
* Names match the {@link ToolState} keys exactly, such as `routing` (not `routes`) and
|
|
3616
|
+
* `customGeometries` (not `geometries`), so the slice name in the tool API never drifts
|
|
3579
3617
|
* from the property on `state`.
|
|
3580
3618
|
*
|
|
3581
|
-
*
|
|
3582
|
-
*
|
|
3583
|
-
* is added there too.
|
|
3619
|
+
* When a new slice implements `setEntryMode`, the union picks up its key, and the runtime
|
|
3620
|
+
* list {@link ENTRY_MODE_SLICE_NAMES} fails to type-check until the key is added there too.
|
|
3584
3621
|
*
|
|
3585
3622
|
* @group Agent Toolkit
|
|
3586
3623
|
*/
|
|
3587
3624
|
type EntryModeSliceName = { [K in keyof ToolState]: ToolState[K] extends EntryModeSlice ? K : never; }[keyof ToolState];
|
|
3588
3625
|
/**
|
|
3589
|
-
*
|
|
3590
|
-
*
|
|
3591
|
-
*
|
|
3626
|
+
* The runtime list of slice names that support entry mode. Its `satisfies` clause makes
|
|
3627
|
+
* drift a compile error. When a new {@link ToolState} slice gains `setEntryMode`, the
|
|
3628
|
+
* package won't build until this constant is updated.
|
|
3592
3629
|
*
|
|
3593
3630
|
* @group Agent Toolkit
|
|
3594
3631
|
*/
|
|
3595
3632
|
export declare const ENTRY_MODE_SLICE_NAMES: readonly EntryModeSliceName[];
|
|
3596
3633
|
/**
|
|
3597
|
-
*
|
|
3598
|
-
* individually by id and
|
|
3599
|
-
*
|
|
3600
|
-
*
|
|
3634
|
+
* A state slice that owns a set of "entries" (routes, ranges), each of which can be hidden
|
|
3635
|
+
* individually by id, and exposes the shown set. {@link RoutingState} and {@link RangeState}
|
|
3636
|
+
* implement it. Helpers that hide previously-shown entries before rendering a new one
|
|
3637
|
+
* consume it (see `hidePreviousShownEntries`).
|
|
3601
3638
|
*
|
|
3602
|
-
*
|
|
3603
|
-
* (`removeShownEntries(ids)`
|
|
3639
|
+
* {@link PlacesState} doesn't implement it, because it uses a wider per-entry marker-type
|
|
3640
|
+
* model (`removeShownEntries(ids)` instead of `hideEntry(id)`).
|
|
3604
3641
|
*
|
|
3605
3642
|
* @group Agent Toolkit
|
|
3606
3643
|
*/
|
|
@@ -3618,17 +3655,17 @@ interface ShownEntriesSlice extends StateSlice {
|
|
|
3618
3655
|
*/
|
|
3619
3656
|
type BYODStateEvents = {
|
|
3620
3657
|
/**
|
|
3621
|
-
*
|
|
3622
|
-
* snapshot after the change
|
|
3623
|
-
*
|
|
3658
|
+
* An entry was added or removed, or `reset()` cleared the history. `entries` is the full
|
|
3659
|
+
* snapshot after the change, and `changedIds` lists the ids of the entries this change added,
|
|
3660
|
+
* replaced in place, or removed.
|
|
3624
3661
|
*/
|
|
3625
3662
|
'entries-change': {
|
|
3626
3663
|
entries: readonly BYODEntry[];
|
|
3627
3664
|
changedIds: readonly string[];
|
|
3628
3665
|
};
|
|
3629
|
-
/**
|
|
3666
|
+
/** The set of entries rendered on the map changed. */
|
|
3630
3667
|
'shown-change': ReadonlySet<string>;
|
|
3631
|
-
/**
|
|
3668
|
+
/** The display policy switched between `single` and `multiple`. */
|
|
3632
3669
|
'mode-change': EntryMode;
|
|
3633
3670
|
};
|
|
3634
3671
|
/**
|
|
@@ -3638,9 +3675,9 @@ type BYODStateEvents = {
|
|
|
3638
3675
|
*/
|
|
3639
3676
|
type AddBYODEntryOptions = {
|
|
3640
3677
|
/**
|
|
3641
|
-
* Explicit MapLibre layer specs
|
|
3642
|
-
*
|
|
3643
|
-
* they are
|
|
3678
|
+
* Explicit MapLibre layer specs, never derived automatically. You pass them here,
|
|
3679
|
+
* or the agent sets them via `setByodLayers`. Until then the entry renders nothing.
|
|
3680
|
+
* Either way they are only stored, and {@link BYODState.showEntry} renders them.
|
|
3644
3681
|
*/
|
|
3645
3682
|
layers?: CustomGeoJSONLayerSpec[];
|
|
3646
3683
|
/** Provenance for the data. Defaults to `{ kind: 'integrator' }`. */
|
|
@@ -3652,9 +3689,9 @@ type AddBYODEntryOptions = {
|
|
|
3652
3689
|
explicitId?: string;
|
|
3653
3690
|
};
|
|
3654
3691
|
/**
|
|
3655
|
-
*
|
|
3656
|
-
*
|
|
3657
|
-
*
|
|
3692
|
+
* The verdict a {@link ByodSourceUrlValidator} returns. `{ valid: true }` explicitly allows
|
|
3693
|
+
* the fetch, and `{ valid: false, reason }` blocks it and surfaces the `reason` to the model
|
|
3694
|
+
* as the tool error.
|
|
3658
3695
|
*
|
|
3659
3696
|
* @group Agent Toolkit
|
|
3660
3697
|
*/
|
|
@@ -3665,30 +3702,30 @@ type ByodSourceUrlValidation = {
|
|
|
3665
3702
|
reason: string;
|
|
3666
3703
|
};
|
|
3667
3704
|
/**
|
|
3668
|
-
*
|
|
3669
|
-
*
|
|
3670
|
-
*
|
|
3671
|
-
*
|
|
3672
|
-
*
|
|
3673
|
-
*
|
|
3674
|
-
* The toolkit can't enforce SSRF guarantees the host itself can't, so it
|
|
3675
|
-
* the URL surface open
|
|
3676
|
-
*
|
|
3677
|
-
*
|
|
3678
|
-
*
|
|
3705
|
+
* An app-supplied authorization hook for BYOD source URLs. `addByodSource` runs it
|
|
3706
|
+
* after the built-in scheme, size and timeout policy and before the network fetch.
|
|
3707
|
+
* Return `{ valid: true }` to allow the fetch or `{ valid: false, reason }` to
|
|
3708
|
+
* block it (see {@link ByodSourceUrlValidation}). It may be sync or async, such as
|
|
3709
|
+
* an allowlist lookup.
|
|
3710
|
+
*
|
|
3711
|
+
* The toolkit can't enforce SSRF guarantees the host itself can't, so by default it
|
|
3712
|
+
* leaves the URL surface open. This hook lets a deployment add its own policy, such
|
|
3713
|
+
* as refusing cloud-metadata endpoints (`169.254.169.254`) or allowing only known
|
|
3714
|
+
* hosts, without the SDK prescribing one for everyone. Set it via the
|
|
3715
|
+
* `byod.validateSourceUrl` option on `createMapAgent`, or assign
|
|
3679
3716
|
* `state.byod.sourceUrlValidator` directly.
|
|
3680
3717
|
*
|
|
3681
3718
|
* @group Agent Toolkit
|
|
3682
3719
|
*/
|
|
3683
3720
|
type ByodSourceUrlValidator = (url: URL) => ByodSourceUrlValidation | Promise<ByodSourceUrlValidation>;
|
|
3684
3721
|
/**
|
|
3685
|
-
*
|
|
3686
|
-
* data that doesn't fit places
|
|
3687
|
-
*
|
|
3688
|
-
*
|
|
3722
|
+
* The state slice for BYOD (bring-your-own-data) GeoJSON layers, the customer-owned
|
|
3723
|
+
* data that doesn't fit places, routes, ranges or custom geometries. Each entry
|
|
3724
|
+
* wraps a {@link CustomGeoJSONModule} so the agent can render, query, and pipe it
|
|
3725
|
+
* through analyseData or processData.
|
|
3689
3726
|
*
|
|
3690
|
-
*
|
|
3691
|
-
*
|
|
3727
|
+
* As in {@link CustomGeometriesState}, every entry owns its own module, initialised
|
|
3728
|
+
* lazily on first show.
|
|
3692
3729
|
*
|
|
3693
3730
|
* @group Agent Toolkit
|
|
3694
3731
|
*/
|
|
@@ -3696,12 +3733,12 @@ declare class BYODState implements ShownEntriesSlice, StateSlice {
|
|
|
3696
3733
|
private readonly _ttMap;
|
|
3697
3734
|
private _entries;
|
|
3698
3735
|
private _entryMode;
|
|
3699
|
-
/**
|
|
3736
|
+
/** The state change events, listed in {@link BYODStateEvents}. */
|
|
3700
3737
|
readonly events: StateEvents<BYODStateEvents>;
|
|
3701
3738
|
/**
|
|
3702
|
-
*
|
|
3703
|
-
* {@link ByodSourceUrlValidator}.
|
|
3704
|
-
*
|
|
3739
|
+
* The optional authorization hook for `addByodSource` URL fetches (see
|
|
3740
|
+
* {@link ByodSourceUrlValidator}). If unset, only the built-in scheme, size
|
|
3741
|
+
* and timeout policy applies.
|
|
3705
3742
|
*/
|
|
3706
3743
|
sourceUrlValidator?: ByodSourceUrlValidator;
|
|
3707
3744
|
constructor(_ttMap: TomTomMap);
|
|
@@ -3713,35 +3750,35 @@ declare class BYODState implements ShownEntriesSlice, StateSlice {
|
|
|
3713
3750
|
setEntryMode(mode: EntryMode): Promise<void>;
|
|
3714
3751
|
findById(entryId: string): BYODEntry | undefined;
|
|
3715
3752
|
/**
|
|
3716
|
-
*
|
|
3717
|
-
*
|
|
3718
|
-
* rendered on top of a still-visible old one
|
|
3753
|
+
* Appends a new BYOD entry and returns its assigned id. In `single` mode the new entry
|
|
3754
|
+
* replaces every older one. It hides and drops them before pushing the new entry, so the
|
|
3755
|
+
* caller never sees it rendered on top of a still-visible old one.
|
|
3719
3756
|
*/
|
|
3720
3757
|
addEntry(data: FeatureCollection$1, label: string, options?: AddBYODEntryOptions): Promise<string>;
|
|
3721
3758
|
/**
|
|
3722
|
-
*
|
|
3723
|
-
* module
|
|
3724
|
-
*
|
|
3725
|
-
*
|
|
3759
|
+
* Replaces the MapLibre layer specs an entry renders under. If the entry already owns a
|
|
3760
|
+
* module because it was shown at least once, the module's `applyConfig` runtime layer diff
|
|
3761
|
+
* pushes the new specs live, without tear-down or flicker. Otherwise the specs are stored
|
|
3762
|
+
* and the next {@link showEntry} picks them up. Throws on an unknown id.
|
|
3726
3763
|
*/
|
|
3727
3764
|
setEntryLayers(entryId: string, layers: CustomGeoJSONLayerSpec[]): void;
|
|
3728
3765
|
/**
|
|
3729
|
-
*
|
|
3730
|
-
*
|
|
3731
|
-
*
|
|
3732
|
-
*
|
|
3766
|
+
* Initialises the entry's CustomGeoJSONModule lazily. The module has a single
|
|
3767
|
+
* source named `data`, configured with this entry's `layers`. To swap layers
|
|
3768
|
+
* afterwards, call {@link setEntryLayers}, which pushes the new specs into this
|
|
3769
|
+
* module via `applyConfig` instead of recreating it.
|
|
3733
3770
|
*/
|
|
3734
3771
|
getEntryModule(entryId: string): Promise<CustomGeoJSONModule>;
|
|
3735
|
-
/**
|
|
3772
|
+
/** Renders the entry on the map. */
|
|
3736
3773
|
showEntry(entryId: string): Promise<void>;
|
|
3737
3774
|
private _hideOthersUnderSingleMode;
|
|
3738
3775
|
hideEntry(entryId: string): Promise<void>;
|
|
3739
|
-
/**
|
|
3776
|
+
/** Clears an entry's module, then drops the entry from history. Does nothing for an unknown id. */
|
|
3740
3777
|
removeEntry(entryId: string): Promise<void>;
|
|
3741
3778
|
private _requireEntry;
|
|
3742
3779
|
/**
|
|
3743
|
-
*
|
|
3744
|
-
*
|
|
3780
|
+
* Hides every BYOD layer on the map but keeps the history. Implements
|
|
3781
|
+
* {@link ClearableMapSlice}.
|
|
3745
3782
|
*/
|
|
3746
3783
|
clearShown(): Promise<void>;
|
|
3747
3784
|
reset(): void;
|
|
@@ -3751,15 +3788,15 @@ declare class BYODState implements ShownEntriesSlice, StateSlice {
|
|
|
3751
3788
|
/**
|
|
3752
3789
|
* @module agent-toolkit-system-prompt
|
|
3753
3790
|
*
|
|
3754
|
-
*
|
|
3791
|
+
* The behavioural contract (persona, tone, dual-response, cadence) lives here.
|
|
3755
3792
|
*
|
|
3756
|
-
* Tool mechanics
|
|
3757
|
-
* which-tool-next
|
|
3758
|
-
*
|
|
3759
|
-
*
|
|
3760
|
-
*
|
|
3761
|
-
*
|
|
3762
|
-
*
|
|
3793
|
+
* Tool mechanics (call shape, return shape, error handling, when-to-use vs.
|
|
3794
|
+
* which-tool-next) live in each tool's description string and Zod schema. Each
|
|
3795
|
+
* tool re-explains its own role, and the LLM sees those alongside this prompt.
|
|
3796
|
+
* The intent classifier (see `utils/intent-classifier.ts`) also scopes tools per
|
|
3797
|
+
* step, so a tool's description is only in context while that tool is active.
|
|
3798
|
+
* Keep cross-cutting safety rules here, where they are always present, and leave
|
|
3799
|
+
* per-tool mechanics to the tool.
|
|
3763
3800
|
*
|
|
3764
3801
|
* If you find yourself adding lines here to fix an LLM mistake, ask first
|
|
3765
3802
|
* whether the fix belongs in a tool description or a tool error message.
|
|
@@ -3775,14 +3812,14 @@ declare class BYODState implements ShownEntriesSlice, StateSlice {
|
|
|
3775
3812
|
*/
|
|
3776
3813
|
type SystemPromptSection = 'identity' | 'capabilities' | 'rejectionRules' | 'responseFormatting' | 'dataConfidence' | 'toolExecution' | 'sessionState';
|
|
3777
3814
|
/**
|
|
3778
|
-
* Per-section body overrides. Each key replaces that section's body
|
|
3779
|
-
* sections fall back to {@link SYSTEM_PROMPT_SECTIONS}.
|
|
3780
|
-
*
|
|
3815
|
+
* Per-section body overrides. Each key replaces that section's body, and omitted
|
|
3816
|
+
* sections fall back to {@link SYSTEM_PROMPT_SECTIONS}. {@link composeSystemPrompt}
|
|
3817
|
+
* and `MapAgentOptions.systemPrompt` accept them.
|
|
3781
3818
|
*
|
|
3782
3819
|
* @remarks
|
|
3783
3820
|
* To *extend* rather than replace a section, read its current default from the
|
|
3784
|
-
* exported {@link SYSTEM_PROMPT_SECTIONS} map and override with a derived string
|
|
3785
|
-
*
|
|
3821
|
+
* exported {@link SYSTEM_PROMPT_SECTIONS} map and override with a derived string,
|
|
3822
|
+
* e.g. append a rule, prepend a note, or hand the default to a coding agent to
|
|
3786
3823
|
* rewrite under some criteria:
|
|
3787
3824
|
*
|
|
3788
3825
|
* ```typescript
|
|
@@ -3796,35 +3833,35 @@ type SystemPromptSection = 'identity' | 'capabilities' | 'rejectionRules' | 'res
|
|
|
3796
3833
|
*/
|
|
3797
3834
|
type SystemPromptSectionOverrides = Partial<Record<SystemPromptSection, string>>;
|
|
3798
3835
|
/**
|
|
3799
|
-
* The default body text for each base-prompt section
|
|
3836
|
+
* The default body text for each base-prompt section, without its heading.
|
|
3800
3837
|
*
|
|
3801
3838
|
* @remarks
|
|
3802
|
-
* Each value
|
|
3803
|
-
* `RESPONSE FORMATTING:`)
|
|
3804
|
-
*
|
|
3839
|
+
* Each value holds only the section's content. {@link composeSystemPrompt} adds the
|
|
3840
|
+
* structural heading (e.g. `RESPONSE FORMATTING:`), so an override passes just the
|
|
3841
|
+
* body. For example, `composeSystemPrompt({ responseFormatting: 'Reply in Spanish.' })`
|
|
3805
3842
|
* still renders under the `RESPONSE FORMATTING:` heading.
|
|
3806
3843
|
*
|
|
3807
|
-
* The
|
|
3808
|
-
* - `identity` — who the assistant is and its tone of voice
|
|
3844
|
+
* The behavioural prose is split so each concern is overridable on its own:
|
|
3845
|
+
* - `identity` — who the assistant is and its tone of voice, the natural hook to
|
|
3809
3846
|
* rebrand or set a persona.
|
|
3810
3847
|
* - `capabilities` — the map environment plus a compact summary of what the
|
|
3811
|
-
* toolkit can do.
|
|
3812
|
-
* as tools change
|
|
3813
|
-
* classifier prompt. It also gives `rejectionRules` something concrete to
|
|
3814
|
-
* the user back toward.
|
|
3848
|
+
* toolkit can do. It stays at the group level (not per-tool) so it does not
|
|
3849
|
+
* drift as tools change. The exact mechanics live in each tool's description and
|
|
3850
|
+
* the classifier prompt. It also gives `rejectionRules` something concrete to
|
|
3851
|
+
* steer the user back toward.
|
|
3815
3852
|
* - `rejectionRules` — how to handle in-scope / mixed / out-of-scope / illegal
|
|
3816
3853
|
* requests, and the requirement to always explain a rejection.
|
|
3817
3854
|
* - `dataConfidence` — how to surface incomplete, partial, stale, or conflicting
|
|
3818
3855
|
* data instead of presenting it as complete.
|
|
3819
3856
|
*
|
|
3820
3857
|
* Location-reference routing ("near me" → getCurrentLocation, "here" →
|
|
3821
|
-
* getViewport) is intentionally
|
|
3858
|
+
* getViewport) is intentionally **not** a section. It is a tool-selection rule
|
|
3822
3859
|
* already owned by the classifier prompt and the two tools' cross-referencing
|
|
3823
3860
|
* descriptions.
|
|
3824
3861
|
*
|
|
3825
|
-
* This map is the canonical source of the default body text
|
|
3826
|
-
*
|
|
3827
|
-
*
|
|
3862
|
+
* This map is the exported, canonical source of the default body text. A consumer
|
|
3863
|
+
* can read a default and override it with a derived value (extend, prefix, or
|
|
3864
|
+
* rewrite it). See {@link SystemPromptSectionOverrides}.
|
|
3828
3865
|
*
|
|
3829
3866
|
* @group Agent Toolkit
|
|
3830
3867
|
*/
|
|
@@ -3833,8 +3870,8 @@ export declare const SYSTEM_PROMPT_SECTIONS: Record<SystemPromptSection, string>
|
|
|
3833
3870
|
* Composes the base system prompt from {@link SYSTEM_PROMPT_SECTIONS}, applying
|
|
3834
3871
|
* any per-section overrides.
|
|
3835
3872
|
*
|
|
3836
|
-
* @param overrides - Replacement **body** text keyed by section
|
|
3837
|
-
* sections fall back to the default.
|
|
3873
|
+
* @param overrides - Replacement **body** text keyed by section. Omitted
|
|
3874
|
+
* sections fall back to the default. It adds the section heading itself,
|
|
3838
3875
|
* so an override does not repeat it. Pass the result to
|
|
3839
3876
|
* `MapAgentOptions.systemPrompt`.
|
|
3840
3877
|
* @returns The composed system prompt string.
|
|
@@ -3859,9 +3896,9 @@ export declare const composeSystemPrompt: (overrides?: SystemPromptSectionOverri
|
|
|
3859
3896
|
* The base system prompt that teaches the LLM how to use the agent toolkit tools.
|
|
3860
3897
|
*
|
|
3861
3898
|
* @remarks
|
|
3862
|
-
* Equivalent to `composeSystemPrompt()` with no overrides.
|
|
3863
|
-
*
|
|
3864
|
-
*
|
|
3899
|
+
* Equivalent to `composeSystemPrompt()` with no overrides. It is exported so you
|
|
3900
|
+
* can reference or extend it when you provide a custom system prompt via
|
|
3901
|
+
* `MapAgentOptions.systemPrompt`. To replace just one section, use
|
|
3865
3902
|
* {@link composeSystemPrompt} instead of rebuilding the whole string.
|
|
3866
3903
|
*
|
|
3867
3904
|
* @example
|
|
@@ -3915,12 +3952,12 @@ export declare const buildSystemPrompt: ({ customPrompt, prefix, suffix }?: Buil
|
|
|
3915
3952
|
//#endregion
|
|
3916
3953
|
//#region src/tools/tool-registry.d.ts
|
|
3917
3954
|
/**
|
|
3918
|
-
* Default tool set for the agent toolkit. Each entry is a {@link ToolDefinition}
|
|
3919
|
-
*
|
|
3955
|
+
* Default tool set for the agent toolkit. Each entry is a {@link ToolDefinition},
|
|
3956
|
+
* either a static `ToolEntry` or a `ToolEntryBuilder` that tailors the tool to
|
|
3920
3957
|
* {@link ToolBuildOptions} (e.g. feature flags) at agent-creation time.
|
|
3921
3958
|
*
|
|
3922
|
-
*
|
|
3923
|
-
*
|
|
3959
|
+
* createMapAgent includes it automatically unless includeDefaultTools is false.
|
|
3960
|
+
* For manual composition outside createMapAgent, use resolveTools().
|
|
3924
3961
|
*
|
|
3925
3962
|
* @group Agent Toolkit
|
|
3926
3963
|
*/
|
|
@@ -3961,14 +3998,10 @@ export declare const DEFAULT_TOOLS: {
|
|
|
3961
3998
|
getStandardMapStyles: ToolDefinition;
|
|
3962
3999
|
setMapStandardStyle: ToolDefinition;
|
|
3963
4000
|
setLanguage: ToolDefinition;
|
|
3964
|
-
|
|
3965
|
-
toggleTilesBaseMapLayerGroups: ToolDefinition;
|
|
4001
|
+
setGeopoliticalView: ToolDefinition;
|
|
3966
4002
|
setMapStyling: ToolDefinition;
|
|
3967
|
-
toggleTilesTrafficFlow: ToolDefinition;
|
|
3968
|
-
toggleTilesTrafficIncidents: ToolDefinition;
|
|
3969
4003
|
getMapStyleLayers: ToolDefinition;
|
|
3970
|
-
|
|
3971
|
-
setPaintProperties: ToolDefinition;
|
|
4004
|
+
setLayerProperties: ToolDefinition;
|
|
3972
4005
|
setPitchBearing: ToolDefinition;
|
|
3973
4006
|
zoomInOrOut: ToolDefinition;
|
|
3974
4007
|
executeMaplibreCode: ToolDefinition;
|
|
@@ -3995,12 +4028,12 @@ type ToolName = keyof typeof DEFAULT_TOOLS;
|
|
|
3995
4028
|
export declare const TOOL_NAMES: ToolName[];
|
|
3996
4029
|
/**
|
|
3997
4030
|
* Default tool names that should be dropped from the registry when a {@link DataEntryKind}
|
|
3998
|
-
* is disabled. Only default-tool names are listed here
|
|
3999
|
-
* never filtered automatically
|
|
4000
|
-
*
|
|
4031
|
+
* is disabled. Only default-tool names are listed here. User-supplied custom tools are
|
|
4032
|
+
* never filtered automatically. To gate your own tools on enabled kinds, read
|
|
4033
|
+
* `dataEntries` yourself.
|
|
4001
4034
|
*
|
|
4002
4035
|
* Tools that span multiple kinds (`clearMap`, `recallState`, `setEntryMode`, …) are
|
|
4003
|
-
* intentionally absent
|
|
4036
|
+
* intentionally absent, since they keep working regardless of which kinds are disabled.
|
|
4004
4037
|
*
|
|
4005
4038
|
* @group Agent Toolkit
|
|
4006
4039
|
*/
|
|
@@ -4011,7 +4044,7 @@ export declare const TOOLS_BY_DATA_ENTRY_KIND: Record<DataEntryKind, readonly To
|
|
|
4011
4044
|
* tool's default (full-surface) shape. Tools without prompts map to `[]`.
|
|
4012
4045
|
*
|
|
4013
4046
|
* Surface these in chat UIs to keep starter suggestions in sync with what the
|
|
4014
|
-
* tools can actually do
|
|
4047
|
+
* tools can actually do. The registry stays the single source of truth.
|
|
4015
4048
|
*
|
|
4016
4049
|
* @group Agent Toolkit
|
|
4017
4050
|
*/
|
|
@@ -4027,16 +4060,19 @@ type ClassificationResult = {
|
|
|
4027
4060
|
/** Tool names selected by the classifier. */
|
|
4028
4061
|
activeToolNames: string[];
|
|
4029
4062
|
/**
|
|
4030
|
-
*
|
|
4031
|
-
* output for that tool
|
|
4032
|
-
* `
|
|
4033
|
-
* `scopeSchema`, or
|
|
4034
|
-
*
|
|
4063
|
+
* The optional per-tool scope, keyed by tool name. Each value is the raw
|
|
4064
|
+
* classifier output for that tool, which `prepareStep` validates against
|
|
4065
|
+
* the tool's `scopeSchema` before applying any narrowing. Tools without
|
|
4066
|
+
* `scopeSchema`, or with no scope from the classifier, keep their full
|
|
4067
|
+
* description and inputSchema for the turn.
|
|
4035
4068
|
*/
|
|
4036
4069
|
toolScopes?: Record<string, unknown>;
|
|
4037
|
-
/**
|
|
4070
|
+
/** The wall-clock time in ms of the classification step, excluding the agent response. */
|
|
4038
4071
|
timeMs: number;
|
|
4039
|
-
/**
|
|
4072
|
+
/**
|
|
4073
|
+
* Token usage of the classification, summed over its one LLM call, or two when the first
|
|
4074
|
+
* answer fails validation.
|
|
4075
|
+
*/
|
|
4040
4076
|
usage: {
|
|
4041
4077
|
inputTokens: number;
|
|
4042
4078
|
outputTokens: number;
|
|
@@ -4050,8 +4086,8 @@ type ClassificationResult = {
|
|
|
4050
4086
|
*/
|
|
4051
4087
|
type ClassifierOptions = {
|
|
4052
4088
|
/**
|
|
4053
|
-
*
|
|
4054
|
-
*
|
|
4089
|
+
* The language model for structured generation, ideally a fast, low-cost
|
|
4090
|
+
* one such as gpt-4o-mini.
|
|
4055
4091
|
*/
|
|
4056
4092
|
chatModel: LanguageModel;
|
|
4057
4093
|
/** Per-tool metadata used to build the classifier prompt. */
|
|
@@ -4069,10 +4105,10 @@ type ConversationMessage = {
|
|
|
4069
4105
|
content: string;
|
|
4070
4106
|
};
|
|
4071
4107
|
/**
|
|
4072
|
-
*
|
|
4108
|
+
* Classifies a user conversation to pick the tools to activate.
|
|
4073
4109
|
*
|
|
4074
4110
|
* The `conversation` should contain the last user message plus a compaction
|
|
4075
|
-
* of the
|
|
4111
|
+
* of the earlier chat history, each message truncated to save tokens.
|
|
4076
4112
|
*
|
|
4077
4113
|
* @example
|
|
4078
4114
|
* ```typescript
|
|
@@ -4088,14 +4124,14 @@ type ConversationMessage = {
|
|
|
4088
4124
|
export declare const classifyUserIntent: (conversation: ConversationMessage[], options: ClassifierOptions) => Promise<ClassificationResult>;
|
|
4089
4125
|
/**
|
|
4090
4126
|
* Extracts the text content of the last user message in a message array.
|
|
4091
|
-
* Returns null if no user message
|
|
4127
|
+
* Returns `null` if there is no user message or its content has no text.
|
|
4092
4128
|
*
|
|
4093
4129
|
* @group Agent Toolkit
|
|
4094
4130
|
*/
|
|
4095
4131
|
export declare const extractLastUserText: (messages: ReadonlyArray<ModelMessage>) => string | null;
|
|
4096
4132
|
/**
|
|
4097
|
-
* Creates the default LLM-based classifier
|
|
4098
|
-
*
|
|
4133
|
+
* Creates the default LLM-based classifier, which selects the minimal tool set for each user
|
|
4134
|
+
* message with structured generation.
|
|
4099
4135
|
*
|
|
4100
4136
|
* @param options.model - Language model for classification (ideally fast/cheap like gpt-4o-mini)
|
|
4101
4137
|
* @param options.maxHistoryMessages - Max prior turns for context. Default: 8
|
|
@@ -4122,14 +4158,14 @@ type ProviderOptions = Record<string, Record<string, JSONValue | undefined>>;
|
|
|
4122
4158
|
*/
|
|
4123
4159
|
export type ToolNameHint = ToolName | (string & {});
|
|
4124
4160
|
/**
|
|
4125
|
-
* Tool-facing union of state slices that own analysable entries
|
|
4161
|
+
* Tool-facing union of state slices that own analysable entries, the
|
|
4126
4162
|
* vocabulary used by tools that read from multiple slices (`analyseData`,
|
|
4127
4163
|
* `processData`) and by the classifier when proposing per-call scope.
|
|
4128
4164
|
*
|
|
4129
4165
|
* Distinct from {@link EntryModeSliceName}, which uses the literal state-slice
|
|
4130
4166
|
* keys (`routing`, `trafficIncidents`, …) for state-level operations.
|
|
4131
4167
|
*
|
|
4132
|
-
* `ranges` is intentionally excluded
|
|
4168
|
+
* `ranges` is intentionally excluded. It feeds the analysis/processing tools
|
|
4133
4169
|
* only via `geometriesEntryIDs` (its isochrone polygons), not as a direct
|
|
4134
4170
|
* top-level input.
|
|
4135
4171
|
*
|
|
@@ -4137,8 +4173,8 @@ export type ToolNameHint = ToolName | (string & {});
|
|
|
4137
4173
|
*/
|
|
4138
4174
|
export type EntryDataKind = 'places' | 'routes' | 'incidents' | 'customGeometries' | 'trafficAreaAnalytics' | 'byod';
|
|
4139
4175
|
/**
|
|
4140
|
-
* State passed to tool factory functions
|
|
4141
|
-
*
|
|
4176
|
+
* State passed to tool factory functions, organised by feature area.
|
|
4177
|
+
* Each sub-state mixes lazy module access with the current service data
|
|
4142
4178
|
* produced during the session.
|
|
4143
4179
|
*
|
|
4144
4180
|
* @group Agent Toolkit
|
|
@@ -4157,68 +4193,69 @@ export type EntryDataKind = 'places' | 'routes' | 'incidents' | 'customGeometrie
|
|
|
4157
4193
|
* ```
|
|
4158
4194
|
*/
|
|
4159
4195
|
export type ToolState = {
|
|
4160
|
-
/**
|
|
4196
|
+
/** The places layer's PlacesModule and append-only search history. */
|
|
4161
4197
|
places: PlacesState;
|
|
4162
|
-
/** Map POI layer
|
|
4198
|
+
/** Map POI layer visibility, filtering and category management. */
|
|
4163
4199
|
mapPOIs: MapPOIsState;
|
|
4164
4200
|
/** Route calculation, waypoint management, and planning parameter state. */
|
|
4165
4201
|
routing: RoutingState;
|
|
4166
|
-
/**
|
|
4202
|
+
/** The displayed base map's style, language, viewport and layers. */
|
|
4167
4203
|
baseMap: BaseMapState;
|
|
4168
|
-
/** Traffic
|
|
4204
|
+
/** Traffic flow tiles and incident overlay tiles. */
|
|
4169
4205
|
trafficTiles: TrafficTilesState;
|
|
4170
|
-
/** Traffic area analytics
|
|
4206
|
+
/** Traffic area analytics aggregation module, last result and viz config. */
|
|
4171
4207
|
trafficAreaAnalytics: TrafficAreaAnalyticsState;
|
|
4172
|
-
/**
|
|
4208
|
+
/** Fetched traffic incident entry history and per-entry rendering. */
|
|
4173
4209
|
trafficIncidents: TrafficIncidentsState;
|
|
4174
|
-
/** Reachable range results
|
|
4210
|
+
/** Reachable range results, with origin, budgets and bbox summaries. */
|
|
4175
4211
|
ranges: RangeState;
|
|
4176
|
-
/** Derived/custom polygon entries
|
|
4212
|
+
/** Derived/custom polygon entries that `processData` outputs. */
|
|
4177
4213
|
customGeometries: CustomGeometriesState;
|
|
4178
|
-
/** Bring-your-own-data GeoJSON layers
|
|
4214
|
+
/** Bring-your-own-data GeoJSON layers, customer-authored data the agent can read and render. */
|
|
4179
4215
|
byod: BYODState;
|
|
4180
4216
|
/**
|
|
4181
|
-
* Strategy used to run code-generation tools (`analyseData
|
|
4182
|
-
*
|
|
4183
|
-
*
|
|
4217
|
+
* Strategy used to run code-generation tools (`analyseData`, `processData`, `createTracker`,
|
|
4218
|
+
* `clusterIncidents`). `createToolState` initialises it to the env-resolved executor, and
|
|
4219
|
+
* `createMapAgent` re-resolves it with {@link MapAgentOptions.codeExecution}. Tools read this
|
|
4184
4220
|
* to select where sandbox code runs.
|
|
4185
4221
|
*/
|
|
4186
4222
|
codeExecution: SandboxExecutor;
|
|
4187
4223
|
/**
|
|
4188
4224
|
* The single recurrence engine. Owners (`analyses`, `trackers`) register entry-anchored jobs and keep
|
|
4189
|
-
* the returned handles
|
|
4190
|
-
*
|
|
4225
|
+
* the returned handles. The engine re-runs each active job when its source entries change. It is generic
|
|
4226
|
+
* and never interprets a job's recipe (the tools layer builds the run closure). See {@link JobEngine}.
|
|
4191
4227
|
*/
|
|
4192
4228
|
engine: JobEngine;
|
|
4193
4229
|
/**
|
|
4194
4230
|
* Single session-level registry of every analysis (one-shot + recurring) across all entry kinds.
|
|
4195
4231
|
* Results live here, and per-entry views read them on demand via {@link Analyses.getAnalysesForEntry}.
|
|
4196
|
-
* `analyseData` registers a record
|
|
4232
|
+
* `analyseData` registers a record and a job on {@link JobEngine}. `monitorAnalysis` toggles the job's
|
|
4197
4233
|
* active flag.
|
|
4198
4234
|
*/
|
|
4199
4235
|
analyses: Analyses;
|
|
4200
4236
|
/**
|
|
4201
|
-
* Generic trackers
|
|
4202
|
-
* alert/event when its rule's {@link Verdict} crosses an edge (`ingestVerdict`)
|
|
4203
|
-
* {@link TrackerEvent} log.
|
|
4237
|
+
* Generic trackers, rising-edge reducers fed by their own {@link JobEngine} jobs. A tracker fires an
|
|
4238
|
+
* alert/event when its rule's {@link Verdict} crosses an edge (`ingestVerdict`). The slice
|
|
4239
|
+
* keeps the durable {@link TrackerEvent} log.
|
|
4204
4240
|
*/
|
|
4205
4241
|
trackers: EventsState;
|
|
4206
4242
|
};
|
|
4207
4243
|
/**
|
|
4208
|
-
* Tunes
|
|
4209
|
-
*
|
|
4210
|
-
*
|
|
4211
|
-
*
|
|
4212
|
-
*
|
|
4244
|
+
* Tunes the sandbox execution of `analyseData`, `processData`, `createTracker` and
|
|
4245
|
+
* `clusterIncidents` code. **Where** the code runs is
|
|
4246
|
+
* not configurable, since the environment decides. In the browser, it is a
|
|
4247
|
+
* sandboxed, opaque-origin iframe + Web Worker (no DOM/storage access, no network
|
|
4248
|
+
* via CSP, terminable on timeout). In Node / SSR, where that boundary has no
|
|
4249
|
+
* equivalent, it is the main thread. The options below only tune the isolated browser run.
|
|
4213
4250
|
*
|
|
4214
4251
|
* @group Agent Toolkit
|
|
4215
4252
|
*/
|
|
4216
4253
|
export type CodeExecutionConfig = {
|
|
4217
|
-
/** Wall-clock budget per isolated (browser) run, in ms.
|
|
4254
|
+
/** Wall-clock budget per isolated (browser) run, in ms. Defaults to 10000. */
|
|
4218
4255
|
timeoutMs?: number;
|
|
4219
4256
|
/**
|
|
4220
|
-
* Optional override of the worker's library source. By default the SDK loads its own
|
|
4221
|
-
* inlined turf/h3 UMD (a separate lazy chunk), so this is rarely needed
|
|
4257
|
+
* Optional override of the worker's library source. By default, the SDK loads its own
|
|
4258
|
+
* inlined turf/h3 UMD (a separate lazy chunk), so this is rarely needed. Supply it only
|
|
4222
4259
|
* to pin a specific build or add libraries. Return UMD/IIFE JavaScript that defines
|
|
4223
4260
|
* `self.turf` and `self.h3` (string or Promise of one).
|
|
4224
4261
|
*/
|
|
@@ -4227,11 +4264,11 @@ export type CodeExecutionConfig = {
|
|
|
4227
4264
|
/**
|
|
4228
4265
|
* Per-call options handed to a tool's `execute`, separate from its parsed input.
|
|
4229
4266
|
*
|
|
4230
|
-
* `signal` is the AI SDK's own `abortSignal` for the tool call
|
|
4267
|
+
* `signal` is the AI SDK's own `abortSignal` for the tool call, which fires when the model's
|
|
4231
4268
|
* turn is cancelled. Forward it to any `@tomtom-org/maps-sdk/services` call the tool makes
|
|
4232
|
-
* (as `signal`) so a cancelled turn also cancels its in-flight HTTP requests.
|
|
4269
|
+
* (as `signal`), so a cancelled turn also cancels its in-flight HTTP requests.
|
|
4233
4270
|
*
|
|
4234
|
-
* Do NOT forward it into work that outlives the turn
|
|
4271
|
+
* Do NOT forward it into work that outlives the turn, such as a monitor's recurring tick or any
|
|
4235
4272
|
* deferred job. Those fire after the signal has aborted, and a monitor treats a rejected tick
|
|
4236
4273
|
* as fatal (it clears its own interval), so a leaked signal kills the monitor rather than
|
|
4237
4274
|
* cancelling a request.
|
|
@@ -4242,14 +4279,14 @@ export type ToolExecuteOptions = {
|
|
|
4242
4279
|
signal?: AbortSignal;
|
|
4243
4280
|
};
|
|
4244
4281
|
/**
|
|
4245
|
-
* A tool definition
|
|
4246
|
-
*
|
|
4282
|
+
* A tool definition, the universal format for both built-in and third-party tools.
|
|
4283
|
+
* It combines execution (inputSchema + execute) with classifier metadata.
|
|
4247
4284
|
*
|
|
4248
4285
|
* @typeParam S - The ToolState shape this tool requires. Default: base `ToolState`.
|
|
4249
4286
|
* @typeParam Scope - Optional per-tool scope shape. When set via `scopeSchema`, the
|
|
4250
4287
|
* classifier may emit a value of this shape per turn so the tool's `description`
|
|
4251
4288
|
* and `inputSchema` can be rebuilt narrower for that step. Tools without scope
|
|
4252
|
-
* leave this at the default `unknown
|
|
4289
|
+
* leave this at the default `unknown`. `scopeSchema` is then absent and no rebuild
|
|
4253
4290
|
* ever runs for the tool.
|
|
4254
4291
|
*
|
|
4255
4292
|
* @group Agent Toolkit
|
|
@@ -4262,20 +4299,20 @@ export type ToolEntry<S extends ToolState = ToolState, Scope = unknown> = {
|
|
|
4262
4299
|
/** Optional Zod schema describing the tool's structured output. */
|
|
4263
4300
|
outputSchema?: z.ZodType;
|
|
4264
4301
|
/**
|
|
4265
|
-
* Function that executes the tool.
|
|
4302
|
+
* Function that executes the tool. It receives the parsed input and the agent's state.
|
|
4266
4303
|
*
|
|
4267
4304
|
* If this calls a `@tomtom-org/maps-sdk/services` function directly, wrap its params with
|
|
4268
|
-
* `withAgentToolkitHeaders` (`tools/shared/agent-headers.ts`) before passing them in
|
|
4305
|
+
* `withAgentToolkitHeaders` (`tools/shared/agent-headers.ts`) before passing them in, for example
|
|
4269
4306
|
* `const requestParams = withAgentToolkitHeaders({ position }); await reverseGeocode(requestParams);`.
|
|
4270
|
-
* This tags the request so TomTom's traffic analytics attribute it to agent-toolkit
|
|
4271
|
-
*
|
|
4307
|
+
* This tags the request so TomTom's traffic analytics attribute it to agent-toolkit. The guard
|
|
4308
|
+
* test in `tools/shared/tests/agent-headers.test.ts` picks up an untagged call.
|
|
4272
4309
|
*/
|
|
4273
4310
|
execute: (input: any, state: S, options?: ToolExecuteOptions) => Promise<any>;
|
|
4274
4311
|
/** Compact one-liner for the intent classifier prompt. */
|
|
4275
4312
|
classificationPrompt?: string;
|
|
4276
4313
|
/** Category tags (e.g. 'location', 'routing'). */
|
|
4277
4314
|
tags?: string[];
|
|
4278
|
-
/** Usage examples (e.g. 'geocode("Amsterdam")'). */
|
|
4315
|
+
/** Usage examples (e.g. 'geocode("Amsterdam")'), passed on in the metadata a custom classifier receives. */
|
|
4279
4316
|
examples?: string[];
|
|
4280
4317
|
/** Natural language prompts (e.g. 'Where is the Louvre?'). */
|
|
4281
4318
|
examplePrompts?: string[];
|
|
@@ -4284,27 +4321,27 @@ export type ToolEntry<S extends ToolState = ToolState, Scope = unknown> = {
|
|
|
4284
4321
|
/** Tool names that must run before this one. */
|
|
4285
4322
|
dependsOn?: string[];
|
|
4286
4323
|
/**
|
|
4287
|
-
*
|
|
4288
|
-
* unioned into the per-turn `activeTools` set, so the model can always reach it. Use sparingly
|
|
4324
|
+
* Whether this tool stays active on every step regardless of the classifier's selection. Its name is
|
|
4325
|
+
* unioned into the per-turn `activeTools` set, so the model can always reach it. Use it sparingly,
|
|
4289
4326
|
* for tools that may be needed to set up *any* request (e.g. asking the user to clarify intent).
|
|
4290
|
-
*
|
|
4327
|
+
* It has no effect on the fail-open path (when classification is skipped, every tool is active).
|
|
4291
4328
|
*/
|
|
4292
4329
|
alwaysActive?: boolean;
|
|
4293
4330
|
/**
|
|
4294
|
-
*
|
|
4295
|
-
* whose turn must be a single silent tool call (e.g. clarifyIntent rendering a form). Leave unset
|
|
4296
|
-
* let the model take one more step after the tool returns
|
|
4297
|
-
* before the loop stops naturally on a no-tool-call step. A tool that semantically awaits the user
|
|
4331
|
+
* Whether to halt the agent loop on the SAME step that calls this tool, with no trailing step. Use for
|
|
4332
|
+
* tools whose turn must be a single silent tool call (e.g. clarifyIntent rendering a form). Leave unset
|
|
4333
|
+
* to let the model take one more step after the tool returns, for example to present the tool's result
|
|
4334
|
+
* as text before the loop stops naturally on a no-tool-call step. A tool that semantically awaits the user
|
|
4298
4335
|
* conveys that through its own result (e.g. clarifyIntent's `status: 'awaiting_user_response'`), not
|
|
4299
4336
|
* this flag.
|
|
4300
4337
|
*/
|
|
4301
4338
|
endsTurnOnCall?: boolean;
|
|
4302
4339
|
/**
|
|
4303
4340
|
* Optional per-tool scope schema. When set, the classifier may emit a
|
|
4304
|
-
* scope value (validated against this schema) and `prepareStep`
|
|
4305
|
-
*
|
|
4341
|
+
* scope value (validated against this schema), and `prepareStep` then
|
|
4342
|
+
* rebuilds this tool's `description` + `inputSchema` by re-invoking its
|
|
4306
4343
|
* {@link ToolEntryBuilder} with the parsed scope. Tools without a builder
|
|
4307
|
-
* cannot be scoped
|
|
4344
|
+
* cannot be scoped, so `scopeSchema` is only meaningful on builder-produced
|
|
4308
4345
|
* entries.
|
|
4309
4346
|
*/
|
|
4310
4347
|
scopeSchema?: z.ZodType<Scope>;
|
|
@@ -4323,13 +4360,13 @@ export type ToolEntry<S extends ToolState = ToolState, Scope = unknown> = {
|
|
|
4323
4360
|
export type ToolMetadata = {
|
|
4324
4361
|
/** Tool identifier, derived from the config key. */
|
|
4325
4362
|
name: string;
|
|
4326
|
-
/** Description of the tool's purpose
|
|
4363
|
+
/** Description of the tool's purpose, used by the SDK's system prompt. */
|
|
4327
4364
|
description: string;
|
|
4328
4365
|
/** Compact one-liner for the intent classifier prompt. */
|
|
4329
4366
|
classificationPrompt?: string;
|
|
4330
4367
|
/** Category tags used by the help tool for filtering (e.g. 'location', 'routing'). */
|
|
4331
4368
|
tags?: string[];
|
|
4332
|
-
/** Usage examples (e.g. 'geocode("Amsterdam")'). */
|
|
4369
|
+
/** Usage examples (e.g. 'geocode("Amsterdam")'), for a custom classifier. The help tool does not show them. */
|
|
4333
4370
|
examples?: string[];
|
|
4334
4371
|
/** Natural language prompts shown by the help tool (e.g. 'Where is the Louvre?'). */
|
|
4335
4372
|
examplePrompts?: string[];
|
|
@@ -4337,9 +4374,9 @@ export type ToolMetadata = {
|
|
|
4337
4374
|
relatedTools?: ToolNameHint[];
|
|
4338
4375
|
/** Tool names that must run before this one. */
|
|
4339
4376
|
dependsOn?: ToolNameHint[];
|
|
4340
|
-
/**
|
|
4377
|
+
/** Whether this tool stays active on every step regardless of the classifier's selection. */
|
|
4341
4378
|
alwaysActive?: boolean;
|
|
4342
|
-
/**
|
|
4379
|
+
/** Whether to halt the agent loop on the step that calls this tool (no trailing step), e.g. clarifyIntent rendering a form. */
|
|
4343
4380
|
endsTurnOnCall?: boolean;
|
|
4344
4381
|
/** When set, the classifier may emit `toolScopes[name]` for this tool to narrow per-turn. */
|
|
4345
4382
|
scopePrompt?: string;
|
|
@@ -4363,9 +4400,9 @@ export type ClassifierContext = {
|
|
|
4363
4400
|
*/
|
|
4364
4401
|
export type Classifier = (context: ClassifierContext) => Promise<ClassificationResult | null>;
|
|
4365
4402
|
/**
|
|
4366
|
-
* Feature-flag bag for {@link createMapAgent}.
|
|
4367
|
-
* opt-in agent-toolkit behaviour. Individual flags vary in stability
|
|
4368
|
-
*
|
|
4403
|
+
* Feature-flag bag for {@link createMapAgent}. It toggles in-flight or
|
|
4404
|
+
* opt-in agent-toolkit behaviour. Individual flags vary in stability.
|
|
4405
|
+
* Some may graduate to stable public options, and others are internal-only
|
|
4369
4406
|
* experiments that can change or disappear without notice. Check each
|
|
4370
4407
|
* flag's own doc for its current status.
|
|
4371
4408
|
*
|
|
@@ -4385,7 +4422,7 @@ export type FeatureFlags = {
|
|
|
4385
4422
|
readonly [flag: string]: never;
|
|
4386
4423
|
};
|
|
4387
4424
|
/**
|
|
4388
|
-
* Build-time options passed to a {@link ToolEntryBuilder}.
|
|
4425
|
+
* Build-time options passed to a {@link ToolEntryBuilder}. They let each tool
|
|
4389
4426
|
* tailor its description, schema, or executor to flags or per-turn scope
|
|
4390
4427
|
* resolved by the classifier.
|
|
4391
4428
|
*
|
|
@@ -4400,8 +4437,8 @@ export type ToolBuildOptions<Scope = unknown> = {
|
|
|
4400
4437
|
featureFlags?: FeatureFlags;
|
|
4401
4438
|
/**
|
|
4402
4439
|
* Per-turn scope emitted by the classifier (already validated against the
|
|
4403
|
-
* tool's {@link ToolEntry.scopeSchema}). `undefined` at agent-creation
|
|
4404
|
-
* or when the classifier omits a scope for this tool
|
|
4440
|
+
* tool's {@link ToolEntry.scopeSchema}). It is `undefined` at agent-creation
|
|
4441
|
+
* time or when the classifier omits a scope for this tool. Builders should
|
|
4405
4442
|
* treat `undefined` as "produce the full surface".
|
|
4406
4443
|
*/
|
|
4407
4444
|
scope?: Scope;
|
|
@@ -4409,8 +4446,8 @@ export type ToolBuildOptions<Scope = unknown> = {
|
|
|
4409
4446
|
* Subset of {@link EntryDataKind} the agent is configured to expose, derived
|
|
4410
4447
|
* from `createMapAgent`'s `dataEntries` option. Builders for `analyseData`
|
|
4411
4448
|
* and `processData` use this to narrow their static (unscoped) input surface
|
|
4412
|
-
* to the agent's enabled kinds. `undefined` means
|
|
4413
|
-
* every kind stays available
|
|
4449
|
+
* to the agent's enabled kinds. `undefined` means no agent-level filtering, so
|
|
4450
|
+
* every kind stays available.
|
|
4414
4451
|
*/
|
|
4415
4452
|
enabledDataKinds?: readonly EntryDataKind[];
|
|
4416
4453
|
};
|
|
@@ -4430,8 +4467,8 @@ export type ToolEntryBuilder<S extends ToolState = ToolState, Scope = unknown> =
|
|
|
4430
4467
|
/**
|
|
4431
4468
|
* A registered tool definition: either a static {@link ToolEntry} or a
|
|
4432
4469
|
* {@link ToolEntryBuilder} that builds one from {@link ToolBuildOptions} at
|
|
4433
|
-
* agent-creation time.
|
|
4434
|
-
*
|
|
4470
|
+
* agent-creation time. The tool registry, resolver and setup pipeline
|
|
4471
|
+
* accept either form interchangeably.
|
|
4435
4472
|
*
|
|
4436
4473
|
* @typeParam S - The ToolState shape this tool requires. Default: base `ToolState`.
|
|
4437
4474
|
* @typeParam Scope - Optional per-tool scope shape (only relevant for builder
|
|
@@ -4450,7 +4487,7 @@ export type ToolExecutionInfo = {
|
|
|
4450
4487
|
toolName: string;
|
|
4451
4488
|
/** Wall-clock duration of `execute`, in milliseconds (includes any network/IO). */
|
|
4452
4489
|
durationMs: number;
|
|
4453
|
-
/**
|
|
4490
|
+
/** Whether the tool threw or returned the standardized `{ error: string }` shape. */
|
|
4454
4491
|
isError: boolean;
|
|
4455
4492
|
/** Error message when `isError` is true (the thrown message or the returned `error`). */
|
|
4456
4493
|
errorMessage?: string;
|
|
@@ -4492,19 +4529,19 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4492
4529
|
* the exported `SYSTEM_PROMPT_SECTIONS` map and override with a derived value
|
|
4493
4530
|
* (e.g. ``responseFormatting: `${SYSTEM_PROMPT_SECTIONS.responseFormatting}\n- Answer in Spanish.` ``).
|
|
4494
4531
|
*
|
|
4495
|
-
* A full string ignores `systemPromptPrefix` and `systemPromptSuffix
|
|
4496
|
-
*
|
|
4532
|
+
* A full string ignores `systemPromptPrefix` and `systemPromptSuffix`.
|
|
4533
|
+
* Section overrides still honour both.
|
|
4497
4534
|
*/
|
|
4498
4535
|
systemPrompt?: string | SystemPromptSectionOverrides;
|
|
4499
4536
|
/**
|
|
4500
4537
|
* Text prepended above the whole prompt as a preamble, separated by a blank
|
|
4501
|
-
* line and carrying no heading.
|
|
4502
|
-
* overrides
|
|
4538
|
+
* line and carrying no heading. It applies on top of the base prompt or section
|
|
4539
|
+
* overrides, unless `systemPrompt` is a full replacement string.
|
|
4503
4540
|
*/
|
|
4504
4541
|
systemPromptPrefix?: string;
|
|
4505
4542
|
/**
|
|
4506
4543
|
* Additional text appended under an `ADDITIONAL INSTRUCTIONS` heading.
|
|
4507
|
-
*
|
|
4544
|
+
* It applies on top of the base prompt or section overrides, unless
|
|
4508
4545
|
* `systemPrompt` is a full replacement string.
|
|
4509
4546
|
*/
|
|
4510
4547
|
systemPromptSuffix?: string;
|
|
@@ -4540,19 +4577,19 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4540
4577
|
tools?: { [K in ToolNameHint]?: ToolDefinition<CS> | false | undefined; };
|
|
4541
4578
|
/**
|
|
4542
4579
|
* Custom state slices merged alongside built-in state.
|
|
4543
|
-
* Only custom slices need to be provided
|
|
4544
|
-
*
|
|
4580
|
+
* Only custom slices need to be provided, since built-in slices are created automatically.
|
|
4581
|
+
* Custom tools read them in `execute` via the state parameter.
|
|
4545
4582
|
*/
|
|
4546
4583
|
state?: Omit<CS, keyof ToolState>;
|
|
4547
4584
|
/**
|
|
4548
4585
|
* Per-kind data-entry configuration. Each {@link DataEntryKind} accepts
|
|
4549
4586
|
* `{ enabled?, entryMode? }`. Setting `enabled: false` removes the kind from the
|
|
4550
|
-
* agent's tool surface entirely
|
|
4587
|
+
* agent's tool surface entirely. It disappears from `analyseData` / `processData`
|
|
4551
4588
|
* scope and input fields, and its slice-specific display / fetch tools
|
|
4552
|
-
* ({@link TOOLS_BY_DATA_ENTRY_KIND}) are dropped from the registry
|
|
4553
|
-
* `entryMode` is applied to the underlying slice right after the agent state is built
|
|
4589
|
+
* ({@link TOOLS_BY_DATA_ENTRY_KIND}) are dropped from the registry. `recallState` stays.
|
|
4590
|
+
* `entryMode` is applied to the underlying slice right after the agent state is built, before any tool runs.
|
|
4554
4591
|
*
|
|
4555
|
-
* Keys are LLM-facing kind names (`routes`, `incidents`)
|
|
4592
|
+
* Keys are LLM-facing kind names (`routes`, `incidents`), not slice names
|
|
4556
4593
|
* (`routing`, `trafficIncidents`). The slice mapping is internal.
|
|
4557
4594
|
*
|
|
4558
4595
|
* @example
|
|
@@ -4588,17 +4625,17 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4588
4625
|
*/
|
|
4589
4626
|
byod?: {
|
|
4590
4627
|
/**
|
|
4591
|
-
*
|
|
4592
|
-
* {@link ByodSourceUrlValidator}. Return `{ valid: true }` to allow or
|
|
4593
|
-
* `{ valid: false, reason }` to block (sync or async).
|
|
4628
|
+
* Authorises each `addByodSource` URL before it is fetched (see
|
|
4629
|
+
* {@link ByodSourceUrlValidator}). Return `{ valid: true }` to allow or
|
|
4630
|
+
* `{ valid: false, reason }` to block (sync or async). It runs in addition
|
|
4594
4631
|
* to the built-in scheme / size / timeout policy.
|
|
4595
4632
|
*/
|
|
4596
4633
|
validateSourceUrl?: ByodSourceUrlValidator;
|
|
4597
4634
|
};
|
|
4598
4635
|
/**
|
|
4599
|
-
* Tunes
|
|
4600
|
-
*
|
|
4601
|
-
* main thread in Node/SSR)
|
|
4636
|
+
* Tunes the data tools' sandbox execution (see {@link CodeExecutionConfig}).
|
|
4637
|
+
* The environment, not this option, chooses where the code runs (off-thread iframe-worker
|
|
4638
|
+
* in the browser, main thread in Node/SSR). These options only adjust the isolated
|
|
4602
4639
|
* browser run (`timeoutMs`, `loadWorkerLibrarySource`).
|
|
4603
4640
|
*
|
|
4604
4641
|
* @experimental
|
|
@@ -4632,11 +4669,11 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4632
4669
|
* Defaults to `true`. Set to `false` for providers that don't support structured tool outputs.
|
|
4633
4670
|
*/
|
|
4634
4671
|
outputSchemas?: boolean;
|
|
4635
|
-
/**
|
|
4672
|
+
/** Maximum multi-step tool loop iterations. Defaults to 10. */
|
|
4636
4673
|
maxSteps?: number;
|
|
4637
4674
|
/**
|
|
4638
4675
|
* Opt into in-flight or experimental agent-toolkit behaviour. Stability
|
|
4639
|
-
* varies per flag
|
|
4676
|
+
* varies per flag (see {@link FeatureFlags} and each flag's own doc).
|
|
4640
4677
|
*
|
|
4641
4678
|
* @experimental
|
|
4642
4679
|
*/
|
|
@@ -4645,8 +4682,8 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4645
4682
|
* Provider-specific options forwarded to the AI SDK on every step. Keyed by
|
|
4646
4683
|
* provider id (`openai`, `azure`, `anthropic`, ...).
|
|
4647
4684
|
*
|
|
4648
|
-
* Use this to enable reasoning summaries for gpt-5.x via the Responses API
|
|
4649
|
-
*
|
|
4685
|
+
* Use this to enable reasoning summaries for gpt-5.x via the Responses API.
|
|
4686
|
+
* Without `reasoningSummary`, the model thinks but returns no reasoning text.
|
|
4650
4687
|
*
|
|
4651
4688
|
* @example
|
|
4652
4689
|
* ```typescript
|
|
@@ -4661,7 +4698,7 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4661
4698
|
providerOptions?: ProviderOptions;
|
|
4662
4699
|
/**
|
|
4663
4700
|
* Per-step `providerOptions` override. Called once per step with the
|
|
4664
|
-
* classifier-narrowed active toolset
|
|
4701
|
+
* classifier-narrowed active toolset. The returned object is merged on top
|
|
4665
4702
|
* of `providerOptions` for that step. Use it to bump reasoning effort on
|
|
4666
4703
|
* turns that include a code-execution tool without paying the cost on
|
|
4667
4704
|
* simple fetch/toggle turns.
|
|
@@ -4680,15 +4717,15 @@ export type MapAgentOptions<CS extends ToolState = ToolState> = {
|
|
|
4680
4717
|
}) => ProviderOptions | undefined;
|
|
4681
4718
|
};
|
|
4682
4719
|
/**
|
|
4683
|
-
* The return type of createMapAgent()
|
|
4684
|
-
*
|
|
4720
|
+
* The return type of createMapAgent(), a real ToolLoopAgent instance
|
|
4721
|
+
* with state access and cleanup.
|
|
4685
4722
|
*
|
|
4686
4723
|
* @group Agent Toolkit
|
|
4687
4724
|
*/
|
|
4688
4725
|
export type MapAgentInstance<CS extends ToolState = ToolState> = ToolLoopAgent & {
|
|
4689
4726
|
/** Live agent state (built-in + custom slices). */
|
|
4690
4727
|
readonly state: CS;
|
|
4691
|
-
/**
|
|
4728
|
+
/** Tears down by resetting all state slices that have a reset() method. */
|
|
4692
4729
|
destroy(): void;
|
|
4693
4730
|
};
|
|
4694
4731
|
//#endregion
|
|
@@ -4696,13 +4733,12 @@ export type MapAgentInstance<CS extends ToolState = ToolState> = ToolLoopAgent &
|
|
|
4696
4733
|
/**
|
|
4697
4734
|
* Creates a conversational agent toolkit that gives an LLM control over a TomTom map.
|
|
4698
4735
|
*
|
|
4699
|
-
*
|
|
4736
|
+
* It returns a ToolLoopAgent instance (compatible with DirectChatTransport) with
|
|
4700
4737
|
* `state` and `destroy` attached. Classification runs transparently inside
|
|
4701
|
-
* `prepareStep
|
|
4738
|
+
* `prepareStep`, so you need no wrapper type.
|
|
4702
4739
|
*
|
|
4703
|
-
* @param map - The
|
|
4704
|
-
* @
|
|
4705
|
-
* @returns A ToolLoopAgent with state access and cleanup
|
|
4740
|
+
* @param map - The map to control.
|
|
4741
|
+
* @returns A ToolLoopAgent with state access and cleanup.
|
|
4706
4742
|
*
|
|
4707
4743
|
* @example Basic usage
|
|
4708
4744
|
* ```typescript
|
|
@@ -4739,11 +4775,11 @@ export declare const createMapAgent: <CS extends ToolState = ToolState>(map: Tom
|
|
|
4739
4775
|
*
|
|
4740
4776
|
* - `ToolEntry` (or builder) values add or replace tools in `defaults`.
|
|
4741
4777
|
* - `false` values remove tools from `defaults`.
|
|
4742
|
-
* -
|
|
4778
|
+
* - It returns a new object and never mutates `defaults`.
|
|
4743
4779
|
*
|
|
4744
4780
|
* Default entries may be {@link ToolEntryBuilder builders} that produce
|
|
4745
4781
|
* their {@link ToolEntry} from build-time options. Builders pass through
|
|
4746
|
-
* untouched and
|
|
4782
|
+
* untouched, and `setupTools` materializes them later.
|
|
4747
4783
|
*
|
|
4748
4784
|
* @param defaults - Base tool record (typically DEFAULT_TOOLS or empty).
|
|
4749
4785
|
* @param overrides - User-provided additions, replacements, and exclusions.
|
|
@@ -4761,7 +4797,7 @@ export declare const questionSchema: z.ZodObject<{
|
|
|
4761
4797
|
options: z.ZodArray<z.ZodString>;
|
|
4762
4798
|
multiSelect: z.ZodDefault<z.ZodBoolean>;
|
|
4763
4799
|
}, z.core.$strip>;
|
|
4764
|
-
/** One clarification question
|
|
4800
|
+
/** One clarification question, the unit a host UI renders. */
|
|
4765
4801
|
type ClarifyIntentQuestion = z.infer<typeof questionSchema>;
|
|
4766
4802
|
/**
|
|
4767
4803
|
* Input schema for {@link executeClarifyIntent}.
|
|
@@ -4778,8 +4814,8 @@ export declare const clarifyIntentSchema: z.ZodObject<{
|
|
|
4778
4814
|
/**
|
|
4779
4815
|
* Output schema for {@link executeClarifyIntent}. The tool resolves immediately, echoing back the
|
|
4780
4816
|
* `intro` + `questions` (so a host can render the whole form) plus an `awaiting_user_response` status.
|
|
4781
|
-
* No "stop and wait" directive is echoed
|
|
4782
|
-
*
|
|
4817
|
+
* No "stop and wait" directive is echoed, because the description-level usage contract already carries
|
|
4818
|
+
* it. CLARIFY_FORM_PROMPT and CLARIFY_PROSE_PROMPT both tell the agent to STOP and wait, so repeating it
|
|
4783
4819
|
* in the result would be redundant.
|
|
4784
4820
|
*/
|
|
4785
4821
|
export declare const clarifyIntentOutputSchema: z.ZodObject<{
|
|
@@ -4794,7 +4830,7 @@ export declare const clarifyIntentOutputSchema: z.ZodObject<{
|
|
|
4794
4830
|
}, z.core.$strip>;
|
|
4795
4831
|
/** Usage contract appended to the description when the host renders the form: silent turn, questions not restated in prose. */
|
|
4796
4832
|
export declare const CLARIFY_FORM_PROMPT: string;
|
|
4797
|
-
/** Usage contract appended to the description when there is no form
|
|
4833
|
+
/** Usage contract appended to the description when there is no form. The model also writes the questions as prose so any UI shows them. */
|
|
4798
4834
|
export declare const CLARIFY_PROSE_PROMPT: string;
|
|
4799
4835
|
/** Per-call overrides accepted by {@link createClarifyIntentTool}. */
|
|
4800
4836
|
type ClarifyIntentToolOptions = {
|
|
@@ -4807,19 +4843,19 @@ type ClarifyIntentToolOptions = {
|
|
|
4807
4843
|
/** Replace the default natural-language example prompts. */
|
|
4808
4844
|
examplePrompts?: string[];
|
|
4809
4845
|
/**
|
|
4810
|
-
*
|
|
4811
|
-
* to clarify, even mid-task
|
|
4846
|
+
* Whether the tool stays active on every step regardless of the classifier, so the agent can always
|
|
4847
|
+
* ask to clarify, even mid-task. Defaults to `true`. `false` leaves activation to the classifier.
|
|
4812
4848
|
*/
|
|
4813
4849
|
alwaysActive?: boolean;
|
|
4814
4850
|
/**
|
|
4815
|
-
*
|
|
4816
|
-
* the agent narrates the questions as prose so they reach a form-less UI.
|
|
4851
|
+
* Whether your host renders the clarifyIntent form. `true` uses the silent form contract. With
|
|
4852
|
+
* `false` (default), the agent narrates the questions as prose so they reach a form-less UI.
|
|
4817
4853
|
*/
|
|
4818
4854
|
rendersForm?: boolean;
|
|
4819
4855
|
};
|
|
4820
4856
|
/**
|
|
4821
|
-
*
|
|
4822
|
-
* specific domain. The schema and `execute` are fixed
|
|
4857
|
+
* Builds a clarifyIntent {@link ToolEntry}, optionally overriding its description and examples for a
|
|
4858
|
+
* specific domain. The schema and `execute` are fixed. Only the classifier-facing metadata is
|
|
4823
4859
|
* customizable. Pass the result to `createMapAgent`'s `tools` option to replace the built-in default:
|
|
4824
4860
|
*
|
|
4825
4861
|
* ```typescript
|
|
@@ -4839,14 +4875,14 @@ export declare const createClarifyIntentTool: (options?: ClarifyIntentToolOption
|
|
|
4839
4875
|
//#region src/tools/utilities/get-current-location.d.ts
|
|
4840
4876
|
type GetCurrentLocationToolOptions = {
|
|
4841
4877
|
/**
|
|
4842
|
-
*
|
|
4843
|
-
* fresh high-accuracy fix.
|
|
4878
|
+
* Whether the model gets the exact position, the device's accuracy and the fix's timestamp, from a
|
|
4879
|
+
* fresh high-accuracy fix. By default (`false`), the position is rounded to 3 decimals (about
|
|
4844
4880
|
* 100 m) from a fix up to a minute old, with no timestamp.
|
|
4845
4881
|
*/
|
|
4846
4882
|
fullPrecision?: boolean;
|
|
4847
4883
|
};
|
|
4848
4884
|
/**
|
|
4849
|
-
*
|
|
4885
|
+
* Builds a getCurrentLocation {@link ToolEntry}. Pass the result to `createMapAgent`'s `tools` option
|
|
4850
4886
|
* to replace the built-in default, for example to send the exact position:
|
|
4851
4887
|
*
|
|
4852
4888
|
* ```typescript
|