@dronedeploy/rocos-js-sdk 4.5.0 → 4.5.2
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/cjs/constants/api.d.ts +2 -0
- package/cjs/constants/api.js +4 -2
- package/cjs/models/maps/MapContent.d.ts +9 -0
- package/cjs/services/BaseServiceAbstract.d.ts +5 -0
- package/cjs/services/BaseServiceAbstract.js +9 -0
- package/cjs/services/MapService.d.ts +28 -2
- package/cjs/services/MapService.js +37 -0
- package/cjs/services/RobotStatusService.d.ts +22 -3
- package/cjs/services/RobotStatusService.js +79 -13
- package/cjs/services/index.d.ts +1 -0
- package/cjs/services/robot-status/connectivity.d.ts +19 -30
- package/cjs/services/robot-status/connectivity.js +16 -58
- package/cjs/services/robot-status/reportedStatus.d.ts +11 -4
- package/cjs/services/robot-status/reportedStatus.js +14 -9
- package/cjs/services/robot-status/sharedStreams.d.ts +28 -0
- package/cjs/services/robot-status/sharedStreams.js +52 -0
- package/esm/constants/api.d.ts +2 -0
- package/esm/constants/api.js +2 -0
- package/esm/models/maps/MapContent.d.ts +9 -0
- package/esm/services/BaseServiceAbstract.d.ts +5 -0
- package/esm/services/BaseServiceAbstract.js +9 -0
- package/esm/services/MapService.d.ts +28 -2
- package/esm/services/MapService.js +39 -2
- package/esm/services/RobotStatusService.d.ts +22 -3
- package/esm/services/RobotStatusService.js +82 -16
- package/esm/services/index.d.ts +1 -0
- package/esm/services/robot-status/connectivity.d.ts +19 -30
- package/esm/services/robot-status/connectivity.js +14 -56
- package/esm/services/robot-status/reportedStatus.d.ts +11 -4
- package/esm/services/robot-status/reportedStatus.js +12 -7
- package/esm/services/robot-status/sharedStreams.d.ts +28 -0
- package/esm/services/robot-status/sharedStreams.js +48 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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();
|
package/esm/constants/api.d.ts
CHANGED
|
@@ -129,6 +129,8 @@ export declare const API_GRAPHS_MAPS_DEPLOYED_URL = "https://{url}/graphs/projec
|
|
|
129
129
|
export declare const API_GRAPHS_MAPS_UNION_URL = "https://{url}/graphs/projects/{projectId}/maps/union";
|
|
130
130
|
export declare const API_GRAPHS_MAP_ID_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}";
|
|
131
131
|
export declare const API_GRAPHS_MAP_CONTENT_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/content";
|
|
132
|
+
export declare const API_GRAPHS_MAP_EXTERNAL_DATA_UPLOAD_URL = "https://{url}/graphs/projects/{projectId}/maps/externaldata";
|
|
133
|
+
export declare const API_GRAPHS_MAP_EXTERNAL_DATA_URL = "https://{url}/graphs/projects/{projectId}/maps/externaldata/{hash}";
|
|
132
134
|
export declare const API_GRAPHS_MAP_METADATA_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/metadata";
|
|
133
135
|
export declare const API_GRAPHS_MAP_NODES_ADD_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/nodes/add";
|
|
134
136
|
export declare const API_GRAPHS_MAP_NODES_ADD_TRANSFORMABLE_URL = "https://{url}/graphs/projects/{projectId}/maps/{mapId}/nodes/add/transformable";
|
package/esm/constants/api.js
CHANGED
|
@@ -131,6 +131,8 @@ export const API_GRAPHS_MAPS_DEPLOYED_URL = 'https://{url}/graphs/projects/{proj
|
|
|
131
131
|
export const API_GRAPHS_MAPS_UNION_URL = 'https://{url}/graphs/projects/{projectId}/maps/union';
|
|
132
132
|
export const API_GRAPHS_MAP_ID_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}';
|
|
133
133
|
export const API_GRAPHS_MAP_CONTENT_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/content';
|
|
134
|
+
export const API_GRAPHS_MAP_EXTERNAL_DATA_UPLOAD_URL = 'https://{url}/graphs/projects/{projectId}/maps/externaldata';
|
|
135
|
+
export const API_GRAPHS_MAP_EXTERNAL_DATA_URL = 'https://{url}/graphs/projects/{projectId}/maps/externaldata/{hash}';
|
|
134
136
|
export const API_GRAPHS_MAP_METADATA_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/metadata';
|
|
135
137
|
export const API_GRAPHS_MAP_NODES_ADD_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/nodes/add';
|
|
136
138
|
export const API_GRAPHS_MAP_NODES_ADD_TRANSFORMABLE_URL = 'https://{url}/graphs/projects/{projectId}/maps/{mapId}/nodes/add/transformable';
|
|
@@ -24,3 +24,12 @@ export interface MapContentEdge {
|
|
|
24
24
|
data: Record<string, unknown>;
|
|
25
25
|
externalData?: Record<string, unknown>;
|
|
26
26
|
}
|
|
27
|
+
/** What `PUT /graphs/projects/{projectId}/maps/externaldata` returns for stored bytes. */
|
|
28
|
+
export interface ExternalDataUploadResponse {
|
|
29
|
+
/** sha256 of the bytes: the `hash` a node's or edge's `externalData` entry names. */
|
|
30
|
+
hash: string;
|
|
31
|
+
/** How many bytes were stored. */
|
|
32
|
+
bytes: number;
|
|
33
|
+
/** The media type they were stored with. */
|
|
34
|
+
contentType: string;
|
|
35
|
+
}
|
|
@@ -16,6 +16,11 @@ interface RequestConfig {
|
|
|
16
16
|
*/
|
|
17
17
|
responseType?: ResponseType;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Bytes to send as a request body verbatim, rather than JSON-encoded. A view must sit on a plain
|
|
21
|
+
* ArrayBuffer, as fetch requires.
|
|
22
|
+
*/
|
|
23
|
+
export type BinaryPayload = Blob | ArrayBuffer | ArrayBufferView<ArrayBuffer>;
|
|
19
24
|
export declare abstract class BaseServiceAbstract {
|
|
20
25
|
protected config: IRocosSDKConfig;
|
|
21
26
|
protected logger: Logger;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { HttpError, RocosError } from '../models';
|
|
2
2
|
import { getURLSearchParams } from '../helpers';
|
|
3
3
|
import { RocosStore } from '../store/RocosStore';
|
|
4
|
+
const isBinaryPayload = (payload) => {
|
|
5
|
+
if (typeof Blob !== 'undefined' && payload instanceof Blob)
|
|
6
|
+
return true;
|
|
7
|
+
return payload instanceof ArrayBuffer || ArrayBuffer.isView(payload);
|
|
8
|
+
};
|
|
4
9
|
export class BaseServiceAbstract {
|
|
5
10
|
constructor(config) {
|
|
6
11
|
this.config = config;
|
|
@@ -37,6 +42,10 @@ export class BaseServiceAbstract {
|
|
|
37
42
|
if (typeof FormData !== 'undefined' && payload instanceof FormData) {
|
|
38
43
|
requestConfig.body = payload;
|
|
39
44
|
}
|
|
45
|
+
else if (isBinaryPayload(payload)) {
|
|
46
|
+
// Raw bytes go up as-is; the caller names their media type in config.headers.
|
|
47
|
+
requestConfig.body = payload;
|
|
48
|
+
}
|
|
40
49
|
else if (payload) {
|
|
41
50
|
requestConfig.body = JSON.stringify(payload);
|
|
42
51
|
requestConfig.headers = { ...requestConfig.headers, 'Content-Type': 'application/json' };
|
|
@@ -2,8 +2,8 @@ import { AddEdgeRequest, AddEdgeResponse, AddTransformEdgeRequest } from '../mod
|
|
|
2
2
|
import { AddNodeRequest, AddNodeResponse, AddTransformableNodeRequest } from '../models/maps/MapNode';
|
|
3
3
|
import { AddPanoramaRequest, AddPanoramaResponse, CreateObservation, Observation } from '../models/maps/Panorama';
|
|
4
4
|
import { AppendPathPointsResponse, AppendToPathRequest, AppendTransformablePointsRequest, ListPathsFilter, MapPath, ReplacePathRequest } from '../models/maps/MapPath';
|
|
5
|
-
import { Asset, IBaseService, IRocosSDKConfig, Map, MapContent, RocosError } from '../models';
|
|
6
|
-
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
|
5
|
+
import { Asset, ExternalDataUploadResponse, IBaseService, IRocosSDKConfig, Map, MapContent, RocosError } from '../models';
|
|
6
|
+
import { BaseServiceAbstract, BinaryPayload } from './BaseServiceAbstract';
|
|
7
7
|
/**
|
|
8
8
|
* Maps service for managing robot maps in the cloud and on robots
|
|
9
9
|
*/
|
|
@@ -105,6 +105,32 @@ export declare class MapService extends BaseServiceAbstract implements IBaseServ
|
|
|
105
105
|
* @param content Canonical map content to write
|
|
106
106
|
*/
|
|
107
107
|
updateContent(projectId: string, mapId: string, content: MapContent): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Downloads the bytes behind a map node's or edge's `externalData` entry.
|
|
110
|
+
*
|
|
111
|
+
* The entry names the bytes by `hash`; giraffe answers with a redirect to a
|
|
112
|
+
* signed download URL, which `fetch` follows. The returned blob carries the
|
|
113
|
+
* content type the bytes were stored with. An entry whose `encoding` is
|
|
114
|
+
* `b64` holds base64 text, which the caller decodes.
|
|
115
|
+
*
|
|
116
|
+
* @param projectId Project ID
|
|
117
|
+
* @param hash The entry's `hash`
|
|
118
|
+
*/
|
|
119
|
+
getExternalData(projectId: string, hash: string): Promise<Blob>;
|
|
120
|
+
/**
|
|
121
|
+
* Stores bytes as map external data, for a node's or edge's `externalData`
|
|
122
|
+
* entry to name by the returned `hash`.
|
|
123
|
+
*
|
|
124
|
+
* Giraffe hashes the bytes (sha256) and keeps them in the project's map-asset
|
|
125
|
+
* store under that hash with the given media type, which is what
|
|
126
|
+
* {@link getExternalData} later serves. Storing the same bytes twice is
|
|
127
|
+
* harmless. The server caps one item at 64 MiB.
|
|
128
|
+
*
|
|
129
|
+
* @param projectId Project ID
|
|
130
|
+
* @param data The bytes to store
|
|
131
|
+
* @param contentType Their media type; `application/octet-stream` when omitted
|
|
132
|
+
*/
|
|
133
|
+
putExternalData(projectId: string, data: BinaryPayload, contentType?: string): Promise<ExternalDataUploadResponse>;
|
|
108
134
|
/**
|
|
109
135
|
* Begins uploading a map from the agent
|
|
110
136
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
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_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';
|
|
2
|
-
import { RocosError, errorCodes } from '../models';
|
|
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';
|
|
2
|
+
import { RocosError, errorCodes, } from '../models';
|
|
3
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
|
4
4
|
import { RocosLogger } from '../logger/RocosLogger';
|
|
5
5
|
import { formatServiceUrl } from '../helpers/formatServiceUrl';
|
|
@@ -151,6 +151,43 @@ export class MapService extends BaseServiceAbstract {
|
|
|
151
151
|
mapId,
|
|
152
152
|
}, this.config.insecure), content, 'Failed to update map content.');
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Downloads the bytes behind a map node's or edge's `externalData` entry.
|
|
156
|
+
*
|
|
157
|
+
* The entry names the bytes by `hash`; giraffe answers with a redirect to a
|
|
158
|
+
* signed download URL, which `fetch` follows. The returned blob carries the
|
|
159
|
+
* content type the bytes were stored with. An entry whose `encoding` is
|
|
160
|
+
* `b64` holds base64 text, which the caller decodes.
|
|
161
|
+
*
|
|
162
|
+
* @param projectId Project ID
|
|
163
|
+
* @param hash The entry's `hash`
|
|
164
|
+
*/
|
|
165
|
+
async getExternalData(projectId, hash) {
|
|
166
|
+
return this.callGet(formatServiceUrl(API_GRAPHS_MAP_EXTERNAL_DATA_URL, {
|
|
167
|
+
url: this.config.url,
|
|
168
|
+
projectId,
|
|
169
|
+
hash: encodeURIComponent(hash),
|
|
170
|
+
}, this.config.insecure), 'Failed to get map external data.', undefined, { responseType: 'blob' });
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Stores bytes as map external data, for a node's or edge's `externalData`
|
|
174
|
+
* entry to name by the returned `hash`.
|
|
175
|
+
*
|
|
176
|
+
* Giraffe hashes the bytes (sha256) and keeps them in the project's map-asset
|
|
177
|
+
* store under that hash with the given media type, which is what
|
|
178
|
+
* {@link getExternalData} later serves. Storing the same bytes twice is
|
|
179
|
+
* harmless. The server caps one item at 64 MiB.
|
|
180
|
+
*
|
|
181
|
+
* @param projectId Project ID
|
|
182
|
+
* @param data The bytes to store
|
|
183
|
+
* @param contentType Their media type; `application/octet-stream` when omitted
|
|
184
|
+
*/
|
|
185
|
+
async putExternalData(projectId, data, contentType = 'application/octet-stream') {
|
|
186
|
+
return this.callPut(formatServiceUrl(API_GRAPHS_MAP_EXTERNAL_DATA_UPLOAD_URL, {
|
|
187
|
+
url: this.config.url,
|
|
188
|
+
projectId,
|
|
189
|
+
}, this.config.insecure), data, 'Failed to store map external data.', { headers: { 'Content-Type': contentType } });
|
|
190
|
+
}
|
|
154
191
|
/**
|
|
155
192
|
* Begins uploading a map from the agent
|
|
156
193
|
*
|
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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.
|
|
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.
|
|
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.
|
|
57
|
+
return getTelemetryLatencyChanges(this.sharedTelemetry, projectId, callsign, () => this.platformTime.platformTime);
|
|
56
58
|
}
|
|
57
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
return
|
|
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
|
}
|
package/esm/services/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IConnectedCallsign, RobotConnectivity, RobotConnectivityStatus, ServiceConnection } from '../../models';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
2
|
/**
|
|
4
3
|
* Service id → public path prefix, for services that expose the standard
|
|
5
4
|
* `connections` endpoint. New services adopting the convention are added here.
|
|
@@ -9,12 +8,13 @@ import { Observable } from 'rxjs';
|
|
|
9
8
|
export declare const CONNECTION_SERVICE_PREFIXES: Record<string, string>;
|
|
10
9
|
/**
|
|
11
10
|
* The telemetry-liveness signal is derived from heartbeat freshness rather than
|
|
12
|
-
* an HTTP endpoint, so it is handled specially
|
|
13
|
-
* the caller). See `getTelemetryLiveness`.
|
|
11
|
+
* an HTTP endpoint, so it is handled specially. See `getTelemetryLiveness`.
|
|
14
12
|
*/
|
|
15
13
|
export declare const TELEMETRY_LIVENESS_SERVICE = "telemetry-liveness";
|
|
16
14
|
/** The services evaluated by default. */
|
|
17
15
|
export declare const DEFAULT_EXPECTED_SERVICES: string[];
|
|
16
|
+
/** How often the bulk `connections` endpoints are polled by default (ms). */
|
|
17
|
+
export declare const DEFAULT_CONNECTIVITY_POLL_MS = 5000;
|
|
18
18
|
/**
|
|
19
19
|
* Floor for the connections-endpoint poll interval. Guards against a caller
|
|
20
20
|
* passing `0` (or any tiny value), which would otherwise poll the API on every
|
|
@@ -23,8 +23,16 @@ export declare const DEFAULT_EXPECTED_SERVICES: string[];
|
|
|
23
23
|
export declare const MIN_CONNECTIVITY_POLL_MS = 250;
|
|
24
24
|
/** Clamps a requested poll interval up to {@link MIN_CONNECTIVITY_POLL_MS}. */
|
|
25
25
|
export declare const clampPollInterval: (pollMs: number) => number;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A bulk `connections` endpoint response: callsign → connection. A callsign that isn't listed is not
|
|
28
|
+
* connected (Teletubby lists only connected callsigns).
|
|
29
|
+
*/
|
|
30
|
+
export type ProjectConnections = Record<string, IConnectedCallsign>;
|
|
31
|
+
/**
|
|
32
|
+
* One poll of a bulk `connections` endpoint: the project's connections, or `undefined` when the poll
|
|
33
|
+
* failed — distinct from a successful but empty response, in which every callsign is disconnected.
|
|
34
|
+
*/
|
|
35
|
+
export type ProjectConnectionsPoll = ProjectConnections | undefined;
|
|
28
36
|
/**
|
|
29
37
|
* Builds the `connections` endpoint URL for a service — per-callsign when a
|
|
30
38
|
* callsign is given, otherwise the bulk per-project variant.
|
|
@@ -50,29 +58,10 @@ export declare const mapConnectionStatus: (connection?: IConnectedCallsign | nul
|
|
|
50
58
|
*/
|
|
51
59
|
export declare const aggregateConnectivity: (services: Record<string, ServiceConnection>) => RobotConnectivity;
|
|
52
60
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* degraded flash on a transient error.
|
|
57
|
-
*
|
|
58
|
-
* `pollMs` is floored at {@link MIN_CONNECTIVITY_POLL_MS} so the endpoint can't
|
|
59
|
-
* be polled unreasonably fast.
|
|
60
|
-
*/
|
|
61
|
-
export declare const getServiceConnectionChanges: (httpGet: ConnectionsHttpGet, url: string, pollMs?: number) => Observable<ServiceConnection>;
|
|
62
|
-
export interface ConnectivityDeps {
|
|
63
|
-
httpGet: ConnectionsHttpGet;
|
|
64
|
-
baseUrl: string;
|
|
65
|
-
insecure?: boolean;
|
|
66
|
-
/** The telemetry-liveness signal (from `getTelemetryLiveness`), folded in as one service. */
|
|
67
|
-
telemetryLiveness$: Observable<ServiceConnection>;
|
|
68
|
-
/** Caller-injected connectivity signals, keyed by service id, folded in on equal footing. */
|
|
69
|
-
extraServices?: Record<string, Observable<ServiceConnection>>;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Emits the robot's {@link RobotConnectivityStatus} — the per-service breakdown
|
|
73
|
-
* plus the aggregate verdict — for the configured `expectedServices`, plus any
|
|
74
|
-
* caller-injected `extraServices` (folded in on equal footing). HTTP services
|
|
75
|
-
* are polled; `telemetry-liveness` and injected services use their supplied
|
|
76
|
-
* observable; any unrecognised service id resolves to `UNKNOWN`.
|
|
61
|
+
* One callsign's {@link ServiceConnection} from a bulk poll. A failed poll is `UNKNOWN` (held
|
|
62
|
+
* transitional) rather than `DISCONNECTED`, to avoid a spurious degraded flash on a transient error;
|
|
63
|
+
* a callsign missing from a successful poll is `DISCONNECTED`.
|
|
77
64
|
*/
|
|
78
|
-
export declare const
|
|
65
|
+
export declare const getCallsignConnection: (poll: ProjectConnectionsPoll, callsign: string) => ServiceConnection;
|
|
66
|
+
/** Whether two connectivity statuses carry the same verdict and per-service breakdown. */
|
|
67
|
+
export declare const connectivityEquals: (a: RobotConnectivityStatus, b: RobotConnectivityStatus) => boolean;
|