@dronedeploy/rocos-js-sdk 4.5.1 → 4.6.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.
Files changed (33) hide show
  1. package/cjs/constants/api.d.ts +2 -0
  2. package/cjs/constants/api.js +4 -2
  3. package/cjs/models/index.d.ts +1 -0
  4. package/cjs/models/index.js +1 -0
  5. package/cjs/models/maps/MapLocation.d.ts +60 -0
  6. package/cjs/models/maps/MapLocation.js +2 -0
  7. package/cjs/services/MapService.d.ts +32 -0
  8. package/cjs/services/MapService.js +35 -0
  9. package/cjs/services/RobotStatusService.d.ts +22 -3
  10. package/cjs/services/RobotStatusService.js +79 -13
  11. package/cjs/services/robot-status/connectivity.d.ts +19 -30
  12. package/cjs/services/robot-status/connectivity.js +16 -58
  13. package/cjs/services/robot-status/reportedStatus.d.ts +11 -4
  14. package/cjs/services/robot-status/reportedStatus.js +14 -9
  15. package/cjs/services/robot-status/sharedStreams.d.ts +28 -0
  16. package/cjs/services/robot-status/sharedStreams.js +52 -0
  17. package/esm/constants/api.d.ts +2 -0
  18. package/esm/constants/api.js +2 -0
  19. package/esm/models/index.d.ts +1 -0
  20. package/esm/models/index.js +1 -0
  21. package/esm/models/maps/MapLocation.d.ts +60 -0
  22. package/esm/models/maps/MapLocation.js +1 -0
  23. package/esm/services/MapService.d.ts +32 -0
  24. package/esm/services/MapService.js +36 -1
  25. package/esm/services/RobotStatusService.d.ts +22 -3
  26. package/esm/services/RobotStatusService.js +82 -16
  27. package/esm/services/robot-status/connectivity.d.ts +19 -30
  28. package/esm/services/robot-status/connectivity.js +14 -56
  29. package/esm/services/robot-status/reportedStatus.d.ts +11 -4
  30. package/esm/services/robot-status/reportedStatus.js +12 -7
  31. package/esm/services/robot-status/sharedStreams.d.ts +28 -0
  32. package/esm/services/robot-status/sharedStreams.js +48 -0
  33. package/package.json +1 -1
@@ -7,6 +7,13 @@ export declare const ROBOT_STATUS_SOURCE = "/diagnostics/robot/status";
7
7
  export declare const LEGACY_HEARTBEAT_SOURCE = "/rocos/agent/telemetry/heartbeat";
8
8
  /** The per-contributor breakdown behind the reported status (health + readiness). */
9
9
  export declare const ROBOT_STATUS_CONTRIBUTORS_SOURCE = "/diagnostics/robot/status/contributors";
10
+ /** How long without a liveness message before `telemetry-liveness` reports `DISCONNECTED` (ms). */
11
+ export declare const DEFAULT_HEARTBEAT_TIMEOUT_MS = 5000;
12
+ /**
13
+ * The telemetry these streams subscribe through. `RobotStatusService` passes a pooled implementation,
14
+ * so every status stream for a robot shares one subscription per topic.
15
+ */
16
+ export type StatusTelemetry = Pick<TelemetryService, 'subscribe'>;
10
17
  export interface ReportedRobotStatus {
11
18
  health: RobotHealth;
12
19
  readiness: RobotReadiness;
@@ -29,7 +36,7 @@ export declare const parseRobotReadiness: (value: unknown) => RobotReadiness;
29
36
  * preserves today's "online ⇒ green" behaviour for agents not yet emitting the
30
37
  * new topic.
31
38
  */
32
- export declare const getReportedStatusChanges: (telemetry: TelemetryService, projectId: string, callsign: string) => Observable<ReportedRobotStatus>;
39
+ export declare const getReportedStatusChanges: (telemetry: StatusTelemetry, projectId: string, callsign: string) => Observable<ReportedRobotStatus>;
33
40
  /**
34
41
  * Emits the per-contributor breakdown behind the robot's reported health and
35
42
  * readiness, from the agent's `robot/status/contributors` topic. Each
@@ -40,7 +47,7 @@ export declare const getReportedStatusChanges: (telemetry: TelemetryService, pro
40
47
  * emit immediately, and — like {@link getReportedStatusChanges} — a telemetry
41
48
  * error falls back to an empty breakdown rather than terminating the stream.
42
49
  */
43
- export declare const getStatusContributorsChanges: (telemetry: TelemetryService, projectId: string, callsign: string) => Observable<RobotStatusContributors>;
50
+ export declare const getStatusContributorsChanges: (telemetry: StatusTelemetry, projectId: string, callsign: string) => Observable<RobotStatusContributors>;
44
51
  /**
45
52
  * Emits the robot's telemetry latency in milliseconds, once per liveness message (from either the
46
53
  * new `robot/status` topic or the legacy heartbeat — the same messages {@link getTelemetryLiveness}
@@ -52,7 +59,7 @@ export declare const getStatusContributorsChanges: (telemetry: TelemetryService,
52
59
  * {@link getTelemetryLiveness} to tell a stale value from a live one. A telemetry error completes
53
60
  * the stream rather than erroring it.
54
61
  */
55
- export declare const getTelemetryLatencyChanges: (telemetry: TelemetryService, projectId: string, callsign: string, now: () => number) => Observable<number>;
62
+ export declare const getTelemetryLatencyChanges: (telemetry: StatusTelemetry, projectId: string, callsign: string, now: () => number) => Observable<number>;
56
63
  /**
57
64
  * Emits the `telemetry-liveness` connectivity signal: whether a heartbeat (from
58
65
  * either the new `robot/status` topic or the legacy heartbeat) has been received
@@ -60,4 +67,4 @@ export declare const getTelemetryLatencyChanges: (telemetry: TelemetryService, p
60
67
  * but spans both topics and maps onto {@link ServiceConnection} so it can be
61
68
  * folded into connectivity aggregation as just another service entry.
62
69
  */
63
- export declare const getTelemetryLiveness: (telemetry: TelemetryService, projectId: string, callsign: string, heartbeatTimeoutMs?: number, intervalMs?: number) => Observable<ServiceConnection>;
70
+ export declare const getTelemetryLiveness: (telemetry: StatusTelemetry, projectId: string, callsign: string, heartbeatTimeoutMs?: number, intervalMs?: number) => Observable<ServiceConnection>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTelemetryLiveness = exports.getTelemetryLatencyChanges = exports.getStatusContributorsChanges = exports.getReportedStatusChanges = exports.parseRobotReadiness = exports.parseRobotHealth = exports.ROBOT_STATUS_CONTRIBUTORS_SOURCE = exports.LEGACY_HEARTBEAT_SOURCE = exports.ROBOT_STATUS_SOURCE = void 0;
3
+ exports.getTelemetryLiveness = exports.getTelemetryLatencyChanges = exports.getStatusContributorsChanges = exports.getReportedStatusChanges = exports.parseRobotReadiness = exports.parseRobotHealth = exports.DEFAULT_HEARTBEAT_TIMEOUT_MS = exports.ROBOT_STATUS_CONTRIBUTORS_SOURCE = exports.LEGACY_HEARTBEAT_SOURCE = exports.ROBOT_STATUS_SOURCE = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const models_1 = require("../../models");
6
6
  /** The new agent topic carrying health + readiness (replaces the heartbeat). */
@@ -9,8 +9,17 @@ exports.ROBOT_STATUS_SOURCE = '/diagnostics/robot/status';
9
9
  exports.LEGACY_HEARTBEAT_SOURCE = '/rocos/agent/telemetry/heartbeat';
10
10
  /** The per-contributor breakdown behind the reported status (health + readiness). */
11
11
  exports.ROBOT_STATUS_CONTRIBUTORS_SOURCE = `${exports.ROBOT_STATUS_SOURCE}/contributors`;
12
- const DEFAULT_HEARTBEAT_TIMEOUT_MS = 5000;
12
+ /** How long without a liveness message before `telemetry-liveness` reports `DISCONNECTED` (ms). */
13
+ exports.DEFAULT_HEARTBEAT_TIMEOUT_MS = 5000;
13
14
  const DEFAULT_INTERVAL_MS = 2000;
15
+ /**
16
+ * Every liveness message — the new `robot/status` topic or the legacy heartbeat — as one stream. The
17
+ * topics are subscribed separately, so the subscriptions are the same ones
18
+ * {@link getReportedStatusChanges} makes and can be shared with it.
19
+ */
20
+ const getLivenessMessages = (telemetry, projectId, callsign) => {
21
+ return (0, rxjs_1.merge)(telemetry.subscribe({ projectId, callsigns: [callsign], sources: [exports.ROBOT_STATUS_SOURCE] }), telemetry.subscribe({ projectId, callsigns: [callsign], sources: [exports.LEGACY_HEARTBEAT_SOURCE] }));
22
+ };
14
23
  /**
15
24
  * Maps a `robot/status` wire value (integer, or its string equivalent) to a
16
25
  * {@link RobotHealth}. Anything unrecognised — including `0` / `'unknown'` —
@@ -131,9 +140,7 @@ exports.getStatusContributorsChanges = getStatusContributorsChanges;
131
140
  * the stream rather than erroring it.
132
141
  */
133
142
  const getTelemetryLatencyChanges = (telemetry, projectId, callsign, now) => {
134
- return telemetry
135
- .subscribe({ projectId, callsigns: [callsign], sources: [exports.ROBOT_STATUS_SOURCE, exports.LEGACY_HEARTBEAT_SOURCE] })
136
- .pipe((0, rxjs_1.map)((message) => now() - message.createdAt.getTime()), (0, rxjs_1.catchError)(() => rxjs_1.EMPTY));
143
+ return getLivenessMessages(telemetry, projectId, callsign).pipe((0, rxjs_1.map)((message) => now() - message.createdAt.getTime()), (0, rxjs_1.catchError)(() => rxjs_1.EMPTY));
137
144
  };
138
145
  exports.getTelemetryLatencyChanges = getTelemetryLatencyChanges;
139
146
  /**
@@ -143,11 +150,9 @@ exports.getTelemetryLatencyChanges = getTelemetryLatencyChanges;
143
150
  * but spans both topics and maps onto {@link ServiceConnection} so it can be
144
151
  * folded into connectivity aggregation as just another service entry.
145
152
  */
146
- const getTelemetryLiveness = (telemetry, projectId, callsign, heartbeatTimeoutMs = DEFAULT_HEARTBEAT_TIMEOUT_MS, intervalMs = DEFAULT_INTERVAL_MS) => {
153
+ const getTelemetryLiveness = (telemetry, projectId, callsign, heartbeatTimeoutMs = exports.DEFAULT_HEARTBEAT_TIMEOUT_MS, intervalMs = DEFAULT_INTERVAL_MS) => {
147
154
  const startedAt = Date.now();
148
- const lastMessageAt$ = telemetry
149
- .subscribe({ projectId, callsigns: [callsign], sources: [exports.ROBOT_STATUS_SOURCE, exports.LEGACY_HEARTBEAT_SOURCE] })
150
- .pipe((0, rxjs_1.map)(() => Date.now()));
155
+ const lastMessageAt$ = getLivenessMessages(telemetry, projectId, callsign).pipe((0, rxjs_1.map)(() => Date.now()));
151
156
  return (0, rxjs_1.combineLatest)([lastMessageAt$.pipe((0, rxjs_1.startWith)(startedAt)), (0, rxjs_1.interval)(intervalMs)]).pipe((0, rxjs_1.map)(([lastMessageAt]) => {
152
157
  const now = Date.now();
153
158
  // No message yet, but still within the initial grace period.
@@ -0,0 +1,28 @@
1
+ import { Observable } from 'rxjs';
2
+ export interface SharedStreamOptions {
3
+ /**
4
+ * Replay the latest value to a subscriber that joins late. Use it for state (a status, a poll
5
+ * result); leave it off for events (raw telemetry messages), where a replayed message would be
6
+ * mistaken for a fresh one.
7
+ */
8
+ replay: boolean;
9
+ }
10
+ /**
11
+ * Hands out one shared, reference-counted observable per key, so equivalent subscribers (e.g. every
12
+ * status dot for robots in one project) share a single upstream subscription or poll.
13
+ *
14
+ * The upstream is subscribed on the first subscriber and torn down after the last one leaves, at
15
+ * which point the entry is dropped; a later subscriber starts it afresh. An upstream that errors or
16
+ * completes is reset the same way, so one failure never leaves a dead stream in the pool.
17
+ */
18
+ export declare class SharedStreamPool {
19
+ private readonly streams;
20
+ get<T>(key: unknown[], create: () => Observable<T>, options: SharedStreamOptions): Observable<T>;
21
+ /** How many streams are currently pooled (subscribed and live). */
22
+ get size(): number;
23
+ }
24
+ /**
25
+ * The process-wide pool, shared across `RobotStatusService` instances. Keys include the SDK's unique
26
+ * config key, so only equivalent SDK configurations share streams.
27
+ */
28
+ export declare const sharedStreamPool: SharedStreamPool;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sharedStreamPool = exports.SharedStreamPool = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ /**
6
+ * Hands out one shared, reference-counted observable per key, so equivalent subscribers (e.g. every
7
+ * status dot for robots in one project) share a single upstream subscription or poll.
8
+ *
9
+ * The upstream is subscribed on the first subscriber and torn down after the last one leaves, at
10
+ * which point the entry is dropped; a later subscriber starts it afresh. An upstream that errors or
11
+ * completes is reset the same way, so one failure never leaves a dead stream in the pool.
12
+ */
13
+ class SharedStreamPool {
14
+ constructor() {
15
+ this.streams = new Map();
16
+ }
17
+ get(key, create, options) {
18
+ const id = JSON.stringify(key);
19
+ const existing = this.streams.get(id);
20
+ if (existing)
21
+ return existing;
22
+ // Registered only once subscribed, so a stream handed out but never subscribed leaves no entry
23
+ // behind. Until then (or after the pool dropped it, for a caller that held on to it and
24
+ // resubscribes) another stream may have taken the key: join that rather than run a second upstream.
25
+ const shared$ = (0, rxjs_1.defer)(() => {
26
+ const current = this.streams.get(id);
27
+ if (current && current !== shared$)
28
+ return current;
29
+ this.streams.set(id, shared$);
30
+ return create();
31
+ }).pipe((0, rxjs_1.finalize)(() => {
32
+ if (this.streams.get(id) === shared$)
33
+ this.streams.delete(id);
34
+ }), (0, rxjs_1.share)({
35
+ connector: () => (options.replay ? new rxjs_1.ReplaySubject(1) : new rxjs_1.Subject()),
36
+ resetOnError: true,
37
+ resetOnComplete: true,
38
+ resetOnRefCountZero: true,
39
+ }));
40
+ return shared$;
41
+ }
42
+ /** How many streams are currently pooled (subscribed and live). */
43
+ get size() {
44
+ return this.streams.size;
45
+ }
46
+ }
47
+ exports.SharedStreamPool = SharedStreamPool;
48
+ /**
49
+ * The process-wide pool, shared across `RobotStatusService` instances. Keys include the SDK's unique
50
+ * config key, so only equivalent SDK configurations share streams.
51
+ */
52
+ exports.sharedStreamPool = new SharedStreamPool();
@@ -139,6 +139,8 @@ export declare const API_GRAPHS_MAP_EDGES_ADD_URL = "https://{url}/graphs/projec
139
139
  export declare const API_GRAPHS_MAP_EDGES_ADD_TRANSFORM_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/edges/add/transform";
140
140
  export declare const API_GRAPHS_MAP_EDGE_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/edges/{edgeId}";
141
141
  export declare const API_GRAPHS_MAP_PATHS_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths";
142
+ export declare const API_GRAPHS_MAP_PATHS_ADD_LOCATION_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/add-location";
143
+ export declare const API_GRAPHS_MAP_PATHS_ADD_LOCATIONS_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/add-locations";
142
144
  export declare const API_GRAPHS_MAP_PATH_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}";
143
145
  export declare const API_GRAPHS_MAP_PATH_APPEND_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}/append";
144
146
  export declare const API_GRAPHS_MAP_PATH_APPEND_TRANSFORMABLE_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}/append/transformable";
@@ -141,6 +141,8 @@ export const API_GRAPHS_MAP_EDGES_ADD_URL = 'https://{url}/graphs/projects/{proj
141
141
  export const API_GRAPHS_MAP_EDGES_ADD_TRANSFORM_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/edges/add/transform';
142
142
  export const API_GRAPHS_MAP_EDGE_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/edges/{edgeId}';
143
143
  export const API_GRAPHS_MAP_PATHS_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths';
144
+ export const API_GRAPHS_MAP_PATHS_ADD_LOCATION_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/add-location';
145
+ export const API_GRAPHS_MAP_PATHS_ADD_LOCATIONS_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/add-locations';
144
146
  export const API_GRAPHS_MAP_PATH_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}';
145
147
  export const API_GRAPHS_MAP_PATH_APPEND_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}/append';
146
148
  export const API_GRAPHS_MAP_PATH_APPEND_TRANSFORMABLE_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/paths/{pathId}/append/transformable';
@@ -53,6 +53,7 @@ export * from './maps/Map';
53
53
  export * from './maps/MapContent';
54
54
  export * from './maps/MapEdge';
55
55
  export * from './maps/MapNode';
56
+ export * from './maps/MapLocation';
56
57
  export * from './maps/MapPath';
57
58
  export * from './maps/Panorama';
58
59
  export * from './message';
@@ -53,6 +53,7 @@ export * from './maps/Map';
53
53
  export * from './maps/MapContent';
54
54
  export * from './maps/MapEdge';
55
55
  export * from './maps/MapNode';
56
+ export * from './maps/MapLocation';
56
57
  export * from './maps/MapPath';
57
58
  export * from './maps/Panorama';
58
59
  export * from './message';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Where a location comes from: `explore` is a DroneDeploy location, `progress` a Progress AI one.
3
+ * Progress AI is called as the requesting user, so `progress` needs a user token.
4
+ */
5
+ export type LocationKind = 'explore' | 'progress';
6
+ /** Options shared by `MapService.addLocation` and `MapService.addLocations`. */
7
+ export interface LocationPathOptions {
8
+ /** Node type of each vertex; `FRAME` when omitted. Server-managed types are refused (400). */
9
+ nodeType?: string;
10
+ }
11
+ /** Body of `MapService.addLocation`. */
12
+ export interface AddLocationPathRequest extends LocationPathOptions {
13
+ kind: LocationKind;
14
+ /** The location's id, with or without its GraphQL type prefix. */
15
+ locationId: string;
16
+ /**
17
+ * The path's parent node id. When omitted it is `location-<location name>` (slugged, with the
18
+ * location id appended when that id is taken), and a location already written is refused (409).
19
+ * Naming it asks for another path of the same location, and only that id has to be free.
20
+ */
21
+ pathId?: string;
22
+ }
23
+ /** Body of `MapService.addLocations`. */
24
+ export interface AddLocationPathsRequest extends LocationPathOptions {
25
+ /** At least one kind. */
26
+ kinds: LocationKind[];
27
+ /** Only locations on these levels (ids, with or without the `Level:` prefix); every level when omitted. */
28
+ levelIds?: string[];
29
+ }
30
+ /** The closed path written for a location. */
31
+ export interface AddLocationPathResponse {
32
+ pathId: string;
33
+ /** The vertex node ids, in ring order. */
34
+ memberIds: string[];
35
+ kind: LocationKind;
36
+ locationId: string;
37
+ name: string;
38
+ levelId: string;
39
+ /** The level's `overlay-<level>-centroid` frame the vertices are positioned in. */
40
+ frame: string;
41
+ /** Set when the level's alignment is marked unverified. */
42
+ unverifiedAlignment: boolean;
43
+ }
44
+ export type LocationPathStatus = 'created' | 'skipped' | 'failed';
45
+ /**
46
+ * One location's outcome in `MapService.addLocations`. `reason` says why a location was
47
+ * `skipped` or `failed`. A result with no `locationId` reports a failure to list that kind.
48
+ */
49
+ export interface LocationPathResult {
50
+ kind: LocationKind;
51
+ locationId?: string;
52
+ name?: string;
53
+ levelId?: string;
54
+ pathId?: string;
55
+ status: LocationPathStatus;
56
+ reason?: string;
57
+ }
58
+ export interface AddLocationPathsResponse {
59
+ results: LocationPathResult[];
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { AddEdgeRequest, AddEdgeResponse, AddTransformEdgeRequest } from '../models/maps/MapEdge';
2
+ import { AddLocationPathRequest, AddLocationPathResponse, AddLocationPathsRequest, AddLocationPathsResponse } from '../models/maps/MapLocation';
2
3
  import { AddNodeRequest, AddNodeResponse, AddTransformableNodeRequest } from '../models/maps/MapNode';
3
4
  import { AddPanoramaRequest, AddPanoramaResponse, CreateObservation, Observation } from '../models/maps/Panorama';
4
5
  import { AppendPathPointsResponse, AppendToPathRequest, AppendTransformablePointsRequest, ListPathsFilter, MapPath, ReplacePathRequest } from '../models/maps/MapPath';
@@ -447,6 +448,37 @@ export declare class MapService extends BaseServiceAbstract implements IBaseServ
447
448
  * @param body The path's desired state.
448
449
  */
449
450
  replacePath(projectId: string, mapId: string, pathId: string, body: ReplacePathRequest): Promise<void>;
451
+ /**
452
+ * Write one DroneDeploy (`explore`) or Progress AI (`progress`) location into a map as a
453
+ * closed path, positioned in its level's `overlay-<level>-centroid` frame through the
454
+ * level's alignment, so it lands on the plan features it was traced over. See
455
+ * {@link AddLocationPathRequest} for the options.
456
+ *
457
+ * A location that cannot be placed is refused with 409 (exterior or level-less, on a level
458
+ * that is not aligned, or on a level whose alignment has no centroid frame yet), as is one
459
+ * whose path already exists. Use {@link addLocations} to add many and get a per-location
460
+ * outcome instead of an error.
461
+ *
462
+ * @param projectId The ID of the project the map belongs to.
463
+ * @param mapId The ID of the map to add the path to.
464
+ * @param body The location to add.
465
+ * @returns The path written: its id, its vertex node ids and the frame it sits in.
466
+ */
467
+ addLocation(projectId: string, mapId: string, body: AddLocationPathRequest): Promise<AddLocationPathResponse>;
468
+ /**
469
+ * Write every location of the given kinds (or only those on the given levels) into a map as
470
+ * closed paths, one each, placed as {@link addLocation} places one. Runs synchronously on the
471
+ * server and answers 200 whatever the mix: a location that cannot be placed or already has a
472
+ * path is reported `skipped`, other failures `failed`, each with a `reason`. A kind that cannot
473
+ * be listed at all (for example Progress AI is not configured, or the call has no user token)
474
+ * yields one `failed` result for that kind with no `locationId`.
475
+ *
476
+ * @param projectId The ID of the project the map belongs to.
477
+ * @param mapId The ID of the map to add the paths to.
478
+ * @param body The kinds and optional level filter.
479
+ * @returns The outcome for each location.
480
+ */
481
+ addLocations(projectId: string, mapId: string, body: AddLocationPathsRequest): Promise<AddLocationPathsResponse>;
450
482
  /**
451
483
  * Delete a path's structure, mirroring the agent's `paths/delete`: idempotent (a missing
452
484
  * path still returns success), member nodes preserved by default, and the parent node
@@ -1,4 +1,4 @@
1
- import { API_GRAPHS_MAPS_COPY_URL, API_GRAPHS_MAPS_DEPLOYED_URL, API_GRAPHS_MAPS_DEPLOY_URL, API_GRAPHS_MAPS_GEOJSON_URL, API_GRAPHS_MAPS_NEW_URL, API_GRAPHS_MAPS_UNION_URL, API_GRAPHS_MAPS_URL, API_GRAPHS_MAP_CONTENT_URL, API_GRAPHS_MAP_EDGES_ADD_TRANSFORM_URL, API_GRAPHS_MAP_EDGES_ADD_URL, API_GRAPHS_MAP_EDGE_URL, API_GRAPHS_MAP_EXTERNAL_DATA_UPLOAD_URL, API_GRAPHS_MAP_EXTERNAL_DATA_URL, API_GRAPHS_MAP_ID_URL, API_GRAPHS_MAP_METADATA_URL, API_GRAPHS_MAP_NODES_ADD_TRANSFORMABLE_URL, API_GRAPHS_MAP_NODES_ADD_URL, API_GRAPHS_MAP_NODE_URL, API_GRAPHS_MAP_PATHS_URL, API_GRAPHS_MAP_PATH_APPEND_TRANSFORMABLE_URL, API_GRAPHS_MAP_PATH_APPEND_URL, API_GRAPHS_MAP_PATH_URL, API_GRAPHS_OBSERVATIONS_URL, API_GRAPHS_OBSERVATION_KEYS_URL, API_GRAPHS_PANORAMA, API_GRAPHS_PANORAMAS_URL, API_GRAPHS_PANORAMA_OBSERVATIONS_URL, } from '../constants/api';
1
+ import { API_GRAPHS_MAPS_COPY_URL, API_GRAPHS_MAPS_DEPLOYED_URL, API_GRAPHS_MAPS_DEPLOY_URL, API_GRAPHS_MAPS_GEOJSON_URL, API_GRAPHS_MAPS_NEW_URL, API_GRAPHS_MAPS_UNION_URL, API_GRAPHS_MAPS_URL, API_GRAPHS_MAP_CONTENT_URL, API_GRAPHS_MAP_EDGES_ADD_TRANSFORM_URL, API_GRAPHS_MAP_EDGES_ADD_URL, API_GRAPHS_MAP_EDGE_URL, API_GRAPHS_MAP_EXTERNAL_DATA_UPLOAD_URL, API_GRAPHS_MAP_EXTERNAL_DATA_URL, API_GRAPHS_MAP_ID_URL, API_GRAPHS_MAP_METADATA_URL, API_GRAPHS_MAP_NODES_ADD_TRANSFORMABLE_URL, API_GRAPHS_MAP_NODES_ADD_URL, API_GRAPHS_MAP_NODE_URL, API_GRAPHS_MAP_PATHS_ADD_LOCATIONS_URL, API_GRAPHS_MAP_PATHS_ADD_LOCATION_URL, API_GRAPHS_MAP_PATHS_URL, API_GRAPHS_MAP_PATH_APPEND_TRANSFORMABLE_URL, API_GRAPHS_MAP_PATH_APPEND_URL, API_GRAPHS_MAP_PATH_URL, API_GRAPHS_OBSERVATIONS_URL, API_GRAPHS_OBSERVATION_KEYS_URL, API_GRAPHS_PANORAMA, API_GRAPHS_PANORAMAS_URL, API_GRAPHS_PANORAMA_OBSERVATIONS_URL, } from '../constants/api';
2
2
  import { RocosError, errorCodes, } from '../models';
3
3
  import { BaseServiceAbstract } from './BaseServiceAbstract';
4
4
  import { RocosLogger } from '../logger/RocosLogger';
@@ -605,6 +605,41 @@ export class MapService extends BaseServiceAbstract {
605
605
  };
606
606
  await this.callPut(formatServiceUrl(API_GRAPHS_MAP_PATH_URL, { url: this.config.url, projectId, mapId, pathId }, this.config.insecure), wireBody, 'Failed to replace path.');
607
607
  }
608
+ /**
609
+ * Write one DroneDeploy (`explore`) or Progress AI (`progress`) location into a map as a
610
+ * closed path, positioned in its level's `overlay-<level>-centroid` frame through the
611
+ * level's alignment, so it lands on the plan features it was traced over. See
612
+ * {@link AddLocationPathRequest} for the options.
613
+ *
614
+ * A location that cannot be placed is refused with 409 (exterior or level-less, on a level
615
+ * that is not aligned, or on a level whose alignment has no centroid frame yet), as is one
616
+ * whose path already exists. Use {@link addLocations} to add many and get a per-location
617
+ * outcome instead of an error.
618
+ *
619
+ * @param projectId The ID of the project the map belongs to.
620
+ * @param mapId The ID of the map to add the path to.
621
+ * @param body The location to add.
622
+ * @returns The path written: its id, its vertex node ids and the frame it sits in.
623
+ */
624
+ addLocation(projectId, mapId, body) {
625
+ return this.callPost(formatServiceUrl(API_GRAPHS_MAP_PATHS_ADD_LOCATION_URL, { url: this.config.url, projectId, mapId }, this.config.insecure), body, 'Failed to add location.');
626
+ }
627
+ /**
628
+ * Write every location of the given kinds (or only those on the given levels) into a map as
629
+ * closed paths, one each, placed as {@link addLocation} places one. Runs synchronously on the
630
+ * server and answers 200 whatever the mix: a location that cannot be placed or already has a
631
+ * path is reported `skipped`, other failures `failed`, each with a `reason`. A kind that cannot
632
+ * be listed at all (for example Progress AI is not configured, or the call has no user token)
633
+ * yields one `failed` result for that kind with no `locationId`.
634
+ *
635
+ * @param projectId The ID of the project the map belongs to.
636
+ * @param mapId The ID of the map to add the paths to.
637
+ * @param body The kinds and optional level filter.
638
+ * @returns The outcome for each location.
639
+ */
640
+ addLocations(projectId, mapId, body) {
641
+ return this.callPost(formatServiceUrl(API_GRAPHS_MAP_PATHS_ADD_LOCATIONS_URL, { url: this.config.url, projectId, mapId }, this.config.insecure), body, 'Failed to add locations.');
642
+ }
608
643
  /**
609
644
  * Delete a path's structure, mirroring the agent's `paths/delete`: idempotent (a missing
610
645
  * path still returns success), member nodes preserved by default, and the parent node
@@ -1,6 +1,6 @@
1
+ import { ReportedRobotStatus } from './robot-status/reportedStatus';
1
2
  import { IBaseService, IRocosSDKConfig, RobotConnectivityStatus, RobotStatus, RobotStatusContributors, RocosError, ServiceConnection } from '../models';
2
3
  import { Observable } from 'rxjs';
3
- import { ReportedRobotStatus } from './robot-status/reportedStatus';
4
4
  import { BaseServiceAbstract } from './BaseServiceAbstract';
5
5
  /** Per-call tuning for the robot status observables. */
6
6
  export interface RobotStatusOptions {
@@ -49,7 +49,11 @@ export declare class RobotStatusService extends BaseServiceAbstract implements I
49
49
  * from a live one.
50
50
  */
51
51
  getTelemetryLatencyChanges(projectId: string, callsign: string): Observable<number>;
52
- /** Per-service connectivity plus the aggregate verdict, polled. */
52
+ /**
53
+ * Per-service connectivity plus the aggregate verdict, for `opts.expectedServices` plus any
54
+ * `opts.extraServices` (folded in on equal footing). HTTP services are read from their project's
55
+ * shared bulk poll; an unrecognised service id resolves to `UNKNOWN`.
56
+ */
53
57
  getConnectivityChanges(projectId: string, callsign: string, opts?: RobotStatusOptions): Observable<RobotConnectivityStatus>;
54
58
  /** One-shot connectivity snapshot: resolves once every expected service is known, or after a timeout. */
55
59
  getConnectivity(projectId: string, callsign: string, opts?: RobotStatusOptions): Promise<RobotConnectivityStatus>;
@@ -60,5 +64,20 @@ export declare class RobotStatusService extends BaseServiceAbstract implements I
60
64
  getRobotStatusChanges(projectId: string, callsign: string, opts?: RobotStatusOptions): Observable<RobotStatus>;
61
65
  protected getError(e: Error): RocosError;
62
66
  private get telemetryService();
63
- private connectivityDeps;
67
+ /**
68
+ * Shared streams are keyed by this, so equivalent SDK configurations (which `RocosStore` already
69
+ * treats as one SDK) share them, and different ones never do.
70
+ */
71
+ private get configKey();
72
+ /** Telemetry with one pooled subscription per robot and topic, however many status streams use it. */
73
+ private get sharedTelemetry();
74
+ private getTelemetryLiveness;
75
+ /** One service's connection for a callsign. Built-in services win over an injected one of the same id. */
76
+ private getServiceConnection;
77
+ /**
78
+ * A service's bulk (per-project) `connections` endpoint, polled every `pollMs`. One poll per project,
79
+ * service and interval is shared by every callsign and subscriber. A failed poll emits `undefined`
80
+ * rather than erroring, so one bad poll doesn't end the stream.
81
+ */
82
+ private getProjectConnections;
64
83
  }
@@ -1,12 +1,14 @@
1
- import { getConnectivityChanges } from './robot-status/connectivity';
2
- import { RobotHealth, RobotReadiness, RocosError, ServiceConnection, errorCodes, } from '../models';
3
- import { combineLatest, distinctUntilChanged, first, firstValueFrom, map, of, shareReplay, startWith, take, tap, timeout, } from 'rxjs';
4
- import { getReportedStatusChanges, getStatusContributorsChanges, getTelemetryLatencyChanges, getTelemetryLiveness, } from './robot-status/reportedStatus';
1
+ import { CONNECTION_SERVICE_PREFIXES, DEFAULT_CONNECTIVITY_POLL_MS, DEFAULT_EXPECTED_SERVICES, TELEMETRY_LIVENESS_SERVICE, aggregateConnectivity, buildConnectionsUrl, clampPollInterval, connectivityEquals, getCallsignConnection, } from './robot-status/connectivity';
2
+ import { DEFAULT_HEARTBEAT_TIMEOUT_MS, getReportedStatusChanges, getStatusContributorsChanges, getTelemetryLatencyChanges, getTelemetryLiveness, } from './robot-status/reportedStatus';
3
+ import { RobotConnectivity, RobotHealth, RobotReadiness, RocosError, ServiceConnection, errorCodes, } from '../models';
4
+ import { catchError, combineLatest, distinctUntilChanged, first, firstValueFrom, from, map, of, shareReplay, startWith, switchMap, take, tap, timeout, timer, } from 'rxjs';
5
5
  import { BaseServiceAbstract } from './BaseServiceAbstract';
6
6
  import { PlatFormTimeService } from './PlatformTimeService';
7
7
  import { RocosLogger } from '../logger/RocosLogger';
8
8
  import { RocosStore } from '../store/RocosStore';
9
9
  import { getRobotStatusColour } from '../helpers/getRobotStatusColour';
10
+ import { getUniqueConfigKey } from '../helpers/getUniqueConfigKey';
11
+ import { sharedStreamPool } from './robot-status/sharedStreams';
10
12
  /** Upper bound on how long the one-shot {@link RobotStatusService.getConnectivity} waits to settle. */
11
13
  const ONE_SHOT_TIMEOUT_MS = 10000;
12
14
  const isKnown = (status) => {
@@ -39,11 +41,11 @@ export class RobotStatusService extends BaseServiceAbstract {
39
41
  }
40
42
  /** Health + readiness as reported by the robot (new topic, legacy heartbeat fallback). */
41
43
  getReportedStatusChanges(projectId, callsign) {
42
- return getReportedStatusChanges(this.telemetryService, projectId, callsign);
44
+ return sharedStreamPool.get(['reported-status', this.configKey, projectId, callsign], () => getReportedStatusChanges(this.sharedTelemetry, projectId, callsign), { replay: true });
43
45
  }
44
46
  /** Per-contributor breakdown behind the reported health and readiness, with the reason for each. */
45
47
  getStatusContributorsChanges(projectId, callsign) {
46
- return getStatusContributorsChanges(this.telemetryService, projectId, callsign);
48
+ return sharedStreamPool.get(['status-contributors', this.configKey, projectId, callsign], () => getStatusContributorsChanges(this.sharedTelemetry, projectId, callsign), { replay: true });
47
49
  }
48
50
  /**
49
51
  * Telemetry latency in milliseconds — platform time minus when the agent created each liveness
@@ -52,11 +54,34 @@ export class RobotStatusService extends BaseServiceAbstract {
52
54
  * from a live one.
53
55
  */
54
56
  getTelemetryLatencyChanges(projectId, callsign) {
55
- return getTelemetryLatencyChanges(this.telemetryService, projectId, callsign, () => this.platformTime.platformTime);
57
+ return getTelemetryLatencyChanges(this.sharedTelemetry, projectId, callsign, () => this.platformTime.platformTime);
56
58
  }
57
- /** Per-service connectivity plus the aggregate verdict, polled. */
59
+ /**
60
+ * Per-service connectivity plus the aggregate verdict, for `opts.expectedServices` plus any
61
+ * `opts.extraServices` (folded in on equal footing). HTTP services are read from their project's
62
+ * shared bulk poll; an unrecognised service id resolves to `UNKNOWN`.
63
+ */
58
64
  getConnectivityChanges(projectId, callsign, opts) {
59
- return getConnectivityChanges(this.connectivityDeps(projectId, callsign, opts), projectId, callsign, opts?.expectedServices, opts?.connectivityPollMs);
65
+ const expectedServices = opts?.expectedServices ?? DEFAULT_EXPECTED_SERVICES;
66
+ const extraServices = opts?.extraServices ?? {};
67
+ const serviceIds = [
68
+ ...expectedServices,
69
+ ...Object.keys(extraServices).filter((id) => !expectedServices.includes(id)),
70
+ ];
71
+ // combineLatest([]) completes without emitting; emit an explicit empty/offline status instead.
72
+ if (serviceIds.length === 0) {
73
+ return of({ overall: RobotConnectivity.OFFLINE, services: {} });
74
+ }
75
+ const pollMs = clampPollInterval(opts?.connectivityPollMs ?? DEFAULT_CONNECTIVITY_POLL_MS);
76
+ const perService = serviceIds.map((serviceId) => {
77
+ return this.getServiceConnection(projectId, callsign, serviceId, pollMs, opts).pipe(startWith(ServiceConnection.UNKNOWN), map((connection) => ({ serviceId, connection })));
78
+ });
79
+ return combineLatest(perService).pipe(map((entries) => {
80
+ const services = {};
81
+ for (const { serviceId, connection } of entries)
82
+ services[serviceId] = connection;
83
+ return { overall: aggregateConnectivity(services), services };
84
+ }), distinctUntilChanged(connectivityEquals));
60
85
  }
61
86
  /** One-shot connectivity snapshot: resolves once every expected service is known, or after a timeout. */
62
87
  getConnectivity(projectId, callsign, opts) {
@@ -92,15 +117,56 @@ export class RobotStatusService extends BaseServiceAbstract {
92
117
  get telemetryService() {
93
118
  return RocosStore.getSDKInstance(this.config).getTelemetryService();
94
119
  }
95
- connectivityDeps(projectId, callsign, opts) {
120
+ /**
121
+ * Shared streams are keyed by this, so equivalent SDK configurations (which `RocosStore` already
122
+ * treats as one SDK) share them, and different ones never do.
123
+ */
124
+ get configKey() {
125
+ return getUniqueConfigKey(this.config);
126
+ }
127
+ /** Telemetry with one pooled subscription per robot and topic, however many status streams use it. */
128
+ get sharedTelemetry() {
96
129
  return {
97
- httpGet: (url) => {
98
- return this.callGet(url, `Failed to get connection status for ${callsign} in project ${projectId}.`);
130
+ subscribe: (params) => {
131
+ return sharedStreamPool.get(['telemetry', this.configKey, params.projectId, params.callsigns, params.sources], () => this.telemetryService.subscribe(params),
132
+ // Raw messages are events: replaying one to a late subscriber would read as a fresh message.
133
+ { replay: false });
99
134
  },
100
- baseUrl: this.config.url,
101
- insecure: this.config.insecure,
102
- telemetryLiveness$: getTelemetryLiveness(this.telemetryService, projectId, callsign, opts?.heartbeatTimeoutMs),
103
- extraServices: opts?.extraServices,
104
135
  };
105
136
  }
137
+ getTelemetryLiveness(projectId, callsign, heartbeatTimeoutMs = DEFAULT_HEARTBEAT_TIMEOUT_MS) {
138
+ // Key on the resolved timeout, so omitting it shares a stream with passing the default explicitly.
139
+ return sharedStreamPool.get(['telemetry-liveness', this.configKey, projectId, callsign, heartbeatTimeoutMs], () => getTelemetryLiveness(this.sharedTelemetry, projectId, callsign, heartbeatTimeoutMs), { replay: true });
140
+ }
141
+ /** One service's connection for a callsign. Built-in services win over an injected one of the same id. */
142
+ getServiceConnection(projectId, callsign, serviceId, pollMs, opts) {
143
+ if (serviceId === TELEMETRY_LIVENESS_SERVICE) {
144
+ return this.getTelemetryLiveness(projectId, callsign, opts?.heartbeatTimeoutMs);
145
+ }
146
+ if (Object.prototype.hasOwnProperty.call(CONNECTION_SERVICE_PREFIXES, serviceId)) {
147
+ return this.getProjectConnections(projectId, serviceId, pollMs).pipe(map((poll) => getCallsignConnection(poll, callsign)), distinctUntilChanged());
148
+ }
149
+ const extraServices = opts?.extraServices;
150
+ if (extraServices && Object.prototype.hasOwnProperty.call(extraServices, serviceId)) {
151
+ // Contain an injected observable's errors as UNKNOWN, mirroring the built-in sources, so a
152
+ // faulty caller signal can't error out combineLatest and tear down the whole aggregate.
153
+ return extraServices[serviceId].pipe(catchError(() => of(ServiceConnection.UNKNOWN)));
154
+ }
155
+ return of(ServiceConnection.UNKNOWN);
156
+ }
157
+ /**
158
+ * A service's bulk (per-project) `connections` endpoint, polled every `pollMs`. One poll per project,
159
+ * service and interval is shared by every callsign and subscriber. A failed poll emits `undefined`
160
+ * rather than erroring, so one bad poll doesn't end the stream.
161
+ */
162
+ getProjectConnections(projectId, serviceId, pollMs) {
163
+ const url = buildConnectionsUrl(serviceId, this.config.url, projectId, undefined, this.config.insecure);
164
+ return sharedStreamPool.get(['connections', this.configKey, url, pollMs], () => {
165
+ return timer(0, pollMs).pipe(switchMap(() => {
166
+ return from(this.callGet(url, `Failed to get connection statuses for project ${projectId}.`)).pipe(
167
+ // Go encodes an empty map as null: a successful poll in which nobody is connected.
168
+ map((connections) => connections ?? {}), catchError(() => of(undefined)));
169
+ }));
170
+ }, { replay: true });
171
+ }
106
172
  }