@wandelbots/nova-js 3.2.0 → 3.3.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 (104) hide show
  1. package/README.md +32 -136
  2. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts +69 -0
  3. package/dist/AutoReconnectingWebsocket-Qcrbm3Kb.d.cts.map +1 -0
  4. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts +69 -0
  5. package/dist/AutoReconnectingWebsocket-dHe-kceU.d.mts.map +1 -0
  6. package/dist/LoginWithAuth0-CBD9BXXz.cjs +264 -0
  7. package/dist/LoginWithAuth0-CBD9BXXz.cjs.map +1 -0
  8. package/dist/LoginWithAuth0-wQB-Sol1.mjs +217 -0
  9. package/dist/LoginWithAuth0-wQB-Sol1.mjs.map +1 -0
  10. package/dist/NovaClient-B8XM3OPO.mjs +2057 -0
  11. package/dist/NovaClient-B8XM3OPO.mjs.map +1 -0
  12. package/dist/NovaClient-CV7ooIkD.d.cts +349 -0
  13. package/dist/NovaClient-CV7ooIkD.d.cts.map +1 -0
  14. package/dist/NovaClient-D2EItmiH.cjs +2137 -0
  15. package/dist/NovaClient-D2EItmiH.cjs.map +1 -0
  16. package/dist/NovaClient-qJnHcx2s.d.mts +349 -0
  17. package/dist/NovaClient-qJnHcx2s.d.mts.map +1 -0
  18. package/dist/index.cjs +42 -386
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +73 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +73 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +36 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/lib/v1/index.cjs +190 -2940
  27. package/dist/lib/v1/index.cjs.map +1 -1
  28. package/dist/lib/v1/index.d.cts +62 -0
  29. package/dist/lib/v1/index.d.cts.map +1 -0
  30. package/dist/lib/v1/index.d.mts +62 -0
  31. package/dist/lib/v1/index.d.mts.map +1 -0
  32. package/dist/lib/v1/index.mjs +182 -0
  33. package/dist/lib/v1/index.mjs.map +1 -0
  34. package/dist/lib/v2/index.cjs +1821 -1468
  35. package/dist/lib/v2/index.cjs.map +1 -1
  36. package/dist/lib/v2/index.d.cts +118 -0
  37. package/dist/lib/v2/index.d.cts.map +1 -0
  38. package/dist/lib/v2/index.d.mts +118 -0
  39. package/dist/lib/v2/index.d.mts.map +1 -0
  40. package/dist/lib/v2/index.mjs +1822 -0
  41. package/dist/lib/v2/index.mjs.map +1 -0
  42. package/package.json +21 -19
  43. package/src/LoginWithAuth0.ts +12 -12
  44. package/src/index.ts +2 -0
  45. package/src/lib/converters.ts +5 -23
  46. package/src/lib/v1/MotionStreamConnection.ts +0 -1
  47. package/src/lib/v1/NovaClient.ts +18 -0
  48. package/src/lib/v1/index.ts +6 -0
  49. package/src/lib/v1/mock/MockNovaInstance.ts +0 -1
  50. package/src/lib/v1/wandelscriptUtils.ts +22 -0
  51. package/src/lib/v2/NovaClient.ts +14 -7
  52. package/src/lib/v2/index.ts +1 -0
  53. package/src/lib/v2/mock/MockNovaInstance.ts +411 -21
  54. package/src/lib/v2/wandelscriptUtils.ts +27 -0
  55. package/dist/LoginWithAuth0.d.ts +0 -7
  56. package/dist/LoginWithAuth0.d.ts.map +0 -1
  57. package/dist/chunk-B2C22PTK.js +0 -53
  58. package/dist/chunk-B2C22PTK.js.map +0 -1
  59. package/dist/chunk-I3PUV6ZD.js +0 -286
  60. package/dist/chunk-I3PUV6ZD.js.map +0 -1
  61. package/dist/index.d.ts +0 -6
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js +0 -60
  64. package/dist/index.js.map +0 -1
  65. package/dist/lib/AutoReconnectingWebsocket.d.ts +0 -43
  66. package/dist/lib/AutoReconnectingWebsocket.d.ts.map +0 -1
  67. package/dist/lib/availableStorage.d.ts +0 -15
  68. package/dist/lib/availableStorage.d.ts.map +0 -1
  69. package/dist/lib/converters.d.ts +0 -26
  70. package/dist/lib/converters.d.ts.map +0 -1
  71. package/dist/lib/errorHandling.d.ts +0 -15
  72. package/dist/lib/errorHandling.d.ts.map +0 -1
  73. package/dist/lib/v1/ConnectedMotionGroup.d.ts +0 -77
  74. package/dist/lib/v1/ConnectedMotionGroup.d.ts.map +0 -1
  75. package/dist/lib/v1/JoggerConnection.d.ts +0 -94
  76. package/dist/lib/v1/JoggerConnection.d.ts.map +0 -1
  77. package/dist/lib/v1/MotionStreamConnection.d.ts +0 -26
  78. package/dist/lib/v1/MotionStreamConnection.d.ts.map +0 -1
  79. package/dist/lib/v1/NovaCellAPIClient.d.ts +0 -68
  80. package/dist/lib/v1/NovaCellAPIClient.d.ts.map +0 -1
  81. package/dist/lib/v1/NovaClient.d.ts +0 -67
  82. package/dist/lib/v1/NovaClient.d.ts.map +0 -1
  83. package/dist/lib/v1/ProgramStateConnection.d.ts +0 -57
  84. package/dist/lib/v1/ProgramStateConnection.d.ts.map +0 -1
  85. package/dist/lib/v1/getLatestTrajectories.d.ts +0 -4
  86. package/dist/lib/v1/getLatestTrajectories.d.ts.map +0 -1
  87. package/dist/lib/v1/index.d.ts +0 -9
  88. package/dist/lib/v1/index.d.ts.map +0 -1
  89. package/dist/lib/v1/index.js +0 -2653
  90. package/dist/lib/v1/index.js.map +0 -1
  91. package/dist/lib/v1/mock/MockNovaInstance.d.ts +0 -13
  92. package/dist/lib/v1/mock/MockNovaInstance.d.ts.map +0 -1
  93. package/dist/lib/v1/motionStateUpdate.d.ts +0 -4
  94. package/dist/lib/v1/motionStateUpdate.d.ts.map +0 -1
  95. package/dist/lib/v2/NovaCellAPIClient.d.ts +0 -62
  96. package/dist/lib/v2/NovaCellAPIClient.d.ts.map +0 -1
  97. package/dist/lib/v2/NovaClient.d.ts +0 -60
  98. package/dist/lib/v2/NovaClient.d.ts.map +0 -1
  99. package/dist/lib/v2/index.d.ts +0 -4
  100. package/dist/lib/v2/index.d.ts.map +0 -1
  101. package/dist/lib/v2/index.js +0 -1196
  102. package/dist/lib/v2/index.js.map +0 -1
  103. package/dist/lib/v2/mock/MockNovaInstance.d.ts +0 -13
  104. package/dist/lib/v2/mock/MockNovaInstance.d.ts.map +0 -1
@@ -1,1479 +1,1832 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
- var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
36
- };
37
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
38
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
39
- // If the importer is in node compatibility mode or this is not an ESM
40
- // file that has been converted to a CommonJS file using a Babel-
41
- // compatible transform (i.e. "__esModule" has not been set), then set
42
- // "default" to the CommonJS "module.exports" for node compatibility.
43
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
- mod
45
- ));
46
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
- var __async = (__this, __arguments, generator) => {
48
- return new Promise((resolve, reject) => {
49
- var fulfilled = (value) => {
50
- try {
51
- step(generator.next(value));
52
- } catch (e) {
53
- reject(e);
54
- }
55
- };
56
- var rejected = (value) => {
57
- try {
58
- step(generator.throw(value));
59
- } catch (e) {
60
- reject(e);
61
- }
62
- };
63
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
64
- step((generator = generator.apply(__this, __arguments)).next());
65
- });
66
- };
1
+ const require_LoginWithAuth0 = require('../../LoginWithAuth0-CBD9BXXz.cjs');
2
+ let axios = require("axios");
3
+ axios = require_LoginWithAuth0.__toESM(axios);
4
+ let url_join = require("url-join");
5
+ url_join = require_LoginWithAuth0.__toESM(url_join);
6
+ let path_to_regexp = require("path-to-regexp");
7
+ path_to_regexp = require_LoginWithAuth0.__toESM(path_to_regexp);
8
+ let __wandelbots_nova_api_v2 = require("@wandelbots/nova-api/v2");
67
9
 
68
- // src/lib/v2/index.ts
69
- var v2_exports = {};
70
- __export(v2_exports, {
71
- NovaCellAPIClient: () => NovaCellAPIClient,
72
- NovaClient: () => NovaClient
73
- });
74
- module.exports = __toCommonJS(v2_exports);
75
- __reExport(v2_exports, require("@wandelbots/nova-api/v2"), module.exports);
76
-
77
- // src/lib/v2/NovaCellAPIClient.ts
78
- var import_v2 = require("@wandelbots/nova-api/v2");
79
- var import_axios = __toESM(require("axios"), 1);
10
+ //#region src/lib/v2/NovaCellAPIClient.ts
11
+ /**
12
+ * API client providing type-safe access to all the Nova API REST endpoints
13
+ * associated with a specific cell id.
14
+ */
80
15
  var NovaCellAPIClient = class {
81
- constructor(cellId, opts) {
82
- this.cellId = cellId;
83
- this.opts = opts;
84
- this.system = this.withUnwrappedResponsesOnly(import_v2.SystemApi);
85
- this.cell = this.withUnwrappedResponsesOnly(import_v2.CellApi);
86
- this.motionGroup = this.withCellId(import_v2.MotionGroupApi);
87
- this.motionGroupModels = this.withCellId(import_v2.MotionGroupModelsApi);
88
- this.controller = this.withCellId(import_v2.ControllerApi);
89
- this.controllerIOs = this.withCellId(import_v2.ControllerInputsOutputsApi);
90
- this.trajectoryPlanning = this.withCellId(import_v2.TrajectoryPlanningApi);
91
- this.trajectoryExecution = this.withCellId(import_v2.TrajectoryExecutionApi);
92
- this.trajectoryCaching = this.withCellId(import_v2.TrajectoryCachingApi);
93
- this.application = this.withCellId(import_v2.ApplicationApi);
94
- this.applicationGlobal = this.withUnwrappedResponsesOnly(import_v2.ApplicationApi);
95
- this.jogging = this.withCellId(import_v2.JoggingApi);
96
- this.kinematics = this.withCellId(import_v2.KinematicsApi);
97
- this.busInputsOutputs = this.withCellId(import_v2.BUSInputsOutputsApi);
98
- this.virtualController = this.withCellId(import_v2.VirtualControllerApi);
99
- this.virtualControllerBehavior = this.withCellId(
100
- import_v2.VirtualControllerBehaviorApi
101
- );
102
- this.virtualControllerIOs = this.withCellId(
103
- import_v2.VirtualControllerInputsOutputsApi
104
- );
105
- this.storeObject = this.withCellId(import_v2.StoreObjectApi);
106
- this.storeCollisionComponents = this.withCellId(
107
- import_v2.StoreCollisionComponentsApi
108
- );
109
- this.storeCollisionSetups = this.withCellId(import_v2.StoreCollisionSetupsApi);
110
- }
111
- /**
112
- * Some TypeScript sorcery which alters the API class methods so you don't
113
- * have to pass the cell id to every single one, and de-encapsulates the
114
- * response data
115
- */
116
- withCellId(ApiConstructor) {
117
- var _a, _b;
118
- const apiClient = new ApiConstructor(
119
- __spreadProps(__spreadValues({}, this.opts), {
120
- isJsonMime: (mime) => {
121
- return mime === "application/json";
122
- }
123
- }),
124
- (_a = this.opts.basePath) != null ? _a : "",
125
- (_b = this.opts.axiosInstance) != null ? _b : import_axios.default.create()
126
- );
127
- for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
128
- if (key !== "constructor" && typeof apiClient[key] === "function") {
129
- const originalFunction = apiClient[key];
130
- apiClient[key] = (...args) => {
131
- return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
132
- };
133
- }
134
- }
135
- return apiClient;
136
- }
137
- /**
138
- * As withCellId, but only does the response unwrapping
139
- */
140
- withUnwrappedResponsesOnly(ApiConstructor) {
141
- var _a, _b;
142
- const apiClient = new ApiConstructor(
143
- __spreadProps(__spreadValues({}, this.opts), {
144
- isJsonMime: (mime) => {
145
- return mime === "application/json";
146
- }
147
- }),
148
- (_a = this.opts.basePath) != null ? _a : "",
149
- (_b = this.opts.axiosInstance) != null ? _b : import_axios.default.create()
150
- );
151
- for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) {
152
- if (key !== "constructor" && typeof apiClient[key] === "function") {
153
- const originalFunction = apiClient[key];
154
- apiClient[key] = (...args) => {
155
- return originalFunction.apply(apiClient, args).then((res) => res.data);
156
- };
157
- }
158
- }
159
- return apiClient;
160
- }
161
- };
162
-
163
- // src/lib/v2/NovaClient.ts
164
- var import_axios3 = __toESM(require("axios"), 1);
165
- var import_url_join = __toESM(require("url-join"), 1);
166
-
167
- // src/LoginWithAuth0.ts
168
- var DOMAIN_SUFFIX = "wandelbots.io";
169
- var auth0ConfigMap = {
170
- dev: {
171
- domain: `https://auth.portal.dev.${DOMAIN_SUFFIX}`,
172
- clientId: "fLbJD0RLp5r2Dpucm5j8BjwMR6Hunfha"
173
- },
174
- stg: {
175
- domain: `https://auth.portal.stg.${DOMAIN_SUFFIX}`,
176
- clientId: "joVDeD9e786WzFNSGCqoVq7HNkWt5j6s"
177
- },
178
- prod: {
179
- domain: `https://auth.portal.${DOMAIN_SUFFIX}`,
180
- clientId: "J7WJUi38xVQdJAEBNRT9Xw1b0fXDb4J2"
181
- }
182
- };
183
- var getAuth0Config = (instanceUrl) => {
184
- if (instanceUrl.includes(`dev.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.dev;
185
- if (instanceUrl.includes(`stg.${DOMAIN_SUFFIX}`)) return auth0ConfigMap.stg;
186
- if (instanceUrl.includes(DOMAIN_SUFFIX)) return auth0ConfigMap.prod;
187
- throw new Error(
188
- "Unsupported instance URL. Cannot determine Auth0 configuration."
189
- );
16
+ constructor(cellId, opts) {
17
+ this.cellId = cellId;
18
+ this.opts = opts;
19
+ this.system = this.withUnwrappedResponsesOnly(__wandelbots_nova_api_v2.SystemApi);
20
+ this.cell = this.withUnwrappedResponsesOnly(__wandelbots_nova_api_v2.CellApi);
21
+ this.motionGroup = this.withCellId(__wandelbots_nova_api_v2.MotionGroupApi);
22
+ this.motionGroupModels = this.withCellId(__wandelbots_nova_api_v2.MotionGroupModelsApi);
23
+ this.controller = this.withCellId(__wandelbots_nova_api_v2.ControllerApi);
24
+ this.controllerIOs = this.withCellId(__wandelbots_nova_api_v2.ControllerInputsOutputsApi);
25
+ this.trajectoryPlanning = this.withCellId(__wandelbots_nova_api_v2.TrajectoryPlanningApi);
26
+ this.trajectoryExecution = this.withCellId(__wandelbots_nova_api_v2.TrajectoryExecutionApi);
27
+ this.trajectoryCaching = this.withCellId(__wandelbots_nova_api_v2.TrajectoryCachingApi);
28
+ this.application = this.withCellId(__wandelbots_nova_api_v2.ApplicationApi);
29
+ this.applicationGlobal = this.withUnwrappedResponsesOnly(__wandelbots_nova_api_v2.ApplicationApi);
30
+ this.jogging = this.withCellId(__wandelbots_nova_api_v2.JoggingApi);
31
+ this.kinematics = this.withCellId(__wandelbots_nova_api_v2.KinematicsApi);
32
+ this.busInputsOutputs = this.withCellId(__wandelbots_nova_api_v2.BUSInputsOutputsApi);
33
+ this.virtualController = this.withCellId(__wandelbots_nova_api_v2.VirtualControllerApi);
34
+ this.virtualControllerBehavior = this.withCellId(__wandelbots_nova_api_v2.VirtualControllerBehaviorApi);
35
+ this.virtualControllerIOs = this.withCellId(__wandelbots_nova_api_v2.VirtualControllerInputsOutputsApi);
36
+ this.storeObject = this.withCellId(__wandelbots_nova_api_v2.StoreObjectApi);
37
+ this.storeCollisionComponents = this.withCellId(__wandelbots_nova_api_v2.StoreCollisionComponentsApi);
38
+ this.storeCollisionSetups = this.withCellId(__wandelbots_nova_api_v2.StoreCollisionSetupsApi);
39
+ }
40
+ /**
41
+ * Some TypeScript sorcery which alters the API class methods so you don't
42
+ * have to pass the cell id to every single one, and de-encapsulates the
43
+ * response data
44
+ */
45
+ withCellId(ApiConstructor) {
46
+ const apiClient = new ApiConstructor({
47
+ ...this.opts,
48
+ isJsonMime: (mime) => {
49
+ return mime === "application/json";
50
+ }
51
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.default.create());
52
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
53
+ const originalFunction = apiClient[key];
54
+ apiClient[key] = (...args) => {
55
+ return originalFunction.apply(apiClient, [this.cellId, ...args]).then((res) => res.data);
56
+ };
57
+ }
58
+ return apiClient;
59
+ }
60
+ /**
61
+ * As withCellId, but only does the response unwrapping
62
+ */
63
+ withUnwrappedResponsesOnly(ApiConstructor) {
64
+ const apiClient = new ApiConstructor({
65
+ ...this.opts,
66
+ isJsonMime: (mime) => {
67
+ return mime === "application/json";
68
+ }
69
+ }, this.opts.basePath ?? "", this.opts.axiosInstance ?? axios.default.create());
70
+ for (const key of Reflect.ownKeys(Reflect.getPrototypeOf(apiClient))) if (key !== "constructor" && typeof apiClient[key] === "function") {
71
+ const originalFunction = apiClient[key];
72
+ apiClient[key] = (...args) => {
73
+ return originalFunction.apply(apiClient, args).then((res) => res.data);
74
+ };
75
+ }
76
+ return apiClient;
77
+ }
190
78
  };
191
- var loginWithAuth0 = (instanceUrl) => __async(null, null, function* () {
192
- var _a;
193
- if (typeof window === "undefined") {
194
- throw new Error(
195
- `Access token must be set to use NovaClient when not in a browser environment.`
196
- );
197
- }
198
- const auth0Config = getAuth0Config(instanceUrl);
199
- if (new URL(instanceUrl).origin === window.location.origin) {
200
- window.location.reload();
201
- throw new Error(
202
- "Failed to reload page to get auth details, please refresh manually"
203
- );
204
- }
205
- const { Auth0Client } = yield import("@auth0/auth0-spa-js");
206
- const auth0Client = new Auth0Client({
207
- domain: auth0Config.domain,
208
- clientId: (_a = auth0Config.clientId) != null ? _a : "",
209
- useRefreshTokens: false,
210
- authorizationParams: {
211
- audience: "nova-api",
212
- redirect_uri: window.location.origin
213
- }
214
- });
215
- if (window.location.search.includes("code=") && window.location.search.includes("state=")) {
216
- const { appState } = yield auth0Client.handleRedirectCallback();
217
- window.history.replaceState(
218
- {},
219
- document.title,
220
- (appState == null ? void 0 : appState.returnTo) || window.location.pathname
221
- );
222
- } else {
223
- yield auth0Client.loginWithRedirect();
224
- }
225
- const accessToken = yield auth0Client.getTokenSilently();
226
- return accessToken;
227
- });
228
-
229
- // src/lib/AutoReconnectingWebsocket.ts
230
- var import_reconnecting_websocket = __toESM(require("reconnecting-websocket"), 1);
231
- var AutoReconnectingWebsocket = class extends import_reconnecting_websocket.default {
232
- constructor(targetUrl, opts = {}) {
233
- console.log("Opening websocket to", targetUrl);
234
- super(() => this.targetUrl || targetUrl, void 0, {
235
- startClosed: true
236
- });
237
- this.opts = opts;
238
- this.disposed = false;
239
- Object.defineProperty(this, "url", {
240
- get() {
241
- return this.targetUrl;
242
- }
243
- });
244
- this.targetUrl = targetUrl;
245
- this.addEventListener("open", () => {
246
- console.log(`Websocket to ${this.url} opened`);
247
- });
248
- this.addEventListener("message", (ev) => {
249
- if (!this.receivedFirstMessage) {
250
- this.receivedFirstMessage = ev;
251
- }
252
- });
253
- this.addEventListener("close", () => {
254
- console.log(`Websocket to ${this.url} closed`);
255
- });
256
- const origReconnect = this.reconnect;
257
- this.reconnect = () => {
258
- if (this.opts.mock) {
259
- this.opts.mock.handleWebsocketConnection(this);
260
- } else {
261
- origReconnect.apply(this);
262
- }
263
- };
264
- this.reconnect();
265
- }
266
- changeUrl(targetUrl) {
267
- this.receivedFirstMessage = void 0;
268
- this.targetUrl = targetUrl;
269
- this.reconnect();
270
- }
271
- sendJson(data) {
272
- if (this.opts.mock) {
273
- this.opts.mock.handleWebsocketMessage(this, JSON.stringify(data));
274
- } else {
275
- this.send(JSON.stringify(data));
276
- }
277
- }
278
- /**
279
- * Permanently close this websocket and indicate that
280
- * this object should not be used again.
281
- **/
282
- dispose() {
283
- this.close();
284
- this.disposed = true;
285
- if (this.opts.onDispose) {
286
- this.opts.onDispose();
287
- }
288
- }
289
- /**
290
- * Returns a promise that resolves once the websocket
291
- * is in the OPEN state. */
292
- opened() {
293
- return __async(this, null, function* () {
294
- return new Promise((resolve, reject) => {
295
- if (this.readyState === WebSocket.OPEN) {
296
- resolve();
297
- } else {
298
- this.addEventListener("open", () => resolve());
299
- this.addEventListener("error", reject);
300
- }
301
- });
302
- });
303
- }
304
- /**
305
- * Returns a promise that resolves once the websocket
306
- * is in the CLOSED state. */
307
- closed() {
308
- return __async(this, null, function* () {
309
- return new Promise((resolve, reject) => {
310
- if (this.readyState === WebSocket.CLOSED) {
311
- resolve();
312
- } else {
313
- this.addEventListener("close", () => resolve());
314
- this.addEventListener("error", reject);
315
- }
316
- });
317
- });
318
- }
319
- /**
320
- * Returns a promise that resolves when the first message
321
- * is received from the websocket. Resolves immediately if
322
- * the first message has already been received.
323
- */
324
- firstMessage() {
325
- return __async(this, null, function* () {
326
- if (this.receivedFirstMessage) {
327
- return this.receivedFirstMessage;
328
- }
329
- return new Promise((resolve, reject) => {
330
- const onMessage = (ev) => {
331
- this.receivedFirstMessage = ev;
332
- this.removeEventListener("message", onMessage);
333
- this.removeEventListener("error", onError);
334
- resolve(ev);
335
- };
336
- const onError = (ev) => {
337
- this.removeEventListener("message", onMessage);
338
- this.removeEventListener("error", onError);
339
- reject(ev);
340
- };
341
- this.addEventListener("message", onMessage);
342
- this.addEventListener("error", onError);
343
- });
344
- });
345
- }
346
- /**
347
- * Returns a promise that resolves when the next message
348
- * is received from the websocket.
349
- */
350
- nextMessage() {
351
- return __async(this, null, function* () {
352
- return new Promise((resolve, reject) => {
353
- const onMessage = (ev) => {
354
- this.removeEventListener("message", onMessage);
355
- this.removeEventListener("error", onError);
356
- resolve(ev);
357
- };
358
- const onError = (ev) => {
359
- this.removeEventListener("message", onMessage);
360
- this.removeEventListener("error", onError);
361
- reject(ev);
362
- };
363
- this.addEventListener("message", onMessage);
364
- this.addEventListener("error", onError);
365
- });
366
- });
367
- }
368
- };
369
-
370
- // src/lib/availableStorage.ts
371
- var AvailableStorage = class {
372
- constructor() {
373
- this.available = typeof window !== "undefined" && !!window.localStorage;
374
- }
375
- getJSON(key) {
376
- if (!this.available) return null;
377
- const result = window.localStorage.getItem(key);
378
- if (result === null) return null;
379
- try {
380
- return JSON.parse(result);
381
- } catch (err) {
382
- return null;
383
- }
384
- }
385
- setJSON(key, obj) {
386
- if (!this.available) return null;
387
- window.localStorage.setItem(key, JSON.stringify(obj));
388
- }
389
- delete(key) {
390
- if (!this.available) return null;
391
- window.localStorage.removeItem(key);
392
- }
393
- setString(key, value) {
394
- if (!this.available) return null;
395
- window.localStorage.setItem(key, value);
396
- }
397
- getString(key) {
398
- if (!this.available) return null;
399
- return window.localStorage.getItem(key);
400
- }
401
- };
402
- var availableStorage = new AvailableStorage();
403
79
 
404
- // src/lib/v2/mock/MockNovaInstance.ts
405
- var import_axios2 = require("axios");
406
- var pathToRegexp = __toESM(require("path-to-regexp"), 1);
80
+ //#endregion
81
+ //#region src/lib/v2/mock/MockNovaInstance.ts
82
+ /**
83
+ * Ultra-simplified mock Nova server for testing stuff
84
+ */
407
85
  var MockNovaInstance = class {
408
- constructor() {
409
- this.connections = [];
410
- }
411
- handleAPIRequest(config) {
412
- return __async(this, null, function* () {
413
- var _a, _b, _c;
414
- const apiHandlers = [
415
- {
416
- method: "GET",
417
- path: "/cells/:cellId/controllers",
418
- handle() {
419
- return {
420
- controllers: [
421
- {
422
- controller: "mock-ur5e",
423
- model_name: "UniversalRobots::Controller",
424
- host: "mock-ur5e",
425
- allow_software_install_on_controller: true,
426
- motion_groups: [
427
- {
428
- motion_group: "0@mock-ur5e",
429
- name_from_controller: "UR5e",
430
- active: false,
431
- model_from_controller: "UniversalRobots_UR5e"
432
- }
433
- ],
434
- has_error: false,
435
- error_details: ""
436
- }
437
- ]
438
- };
439
- }
440
- },
441
- {
442
- method: "GET",
443
- path: "/cells/:cellId/controllers/:controllerId",
444
- handle() {
445
- return {
446
- configuration: {
447
- kind: "VirtualController",
448
- manufacturer: "universalrobots",
449
- type: "universalrobots-ur5e"
450
- },
451
- name: "mock-ur5"
452
- };
453
- }
454
- },
455
- {
456
- method: "GET",
457
- path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
458
- handle() {
459
- return {
460
- dh_parameters: [
461
- {
462
- alpha: 1.5707963267948966,
463
- theta: 0,
464
- a: 0,
465
- d: 162.25,
466
- reverse_rotation_direction: false
467
- },
468
- {
469
- alpha: 0,
470
- theta: 0,
471
- a: -425,
472
- d: 0,
473
- reverse_rotation_direction: false
474
- },
475
- {
476
- alpha: 0,
477
- theta: 0,
478
- a: -392.2,
479
- d: 0,
480
- reverse_rotation_direction: false
481
- },
482
- {
483
- alpha: 1.5707963267948966,
484
- theta: 0,
485
- a: 0,
486
- d: 133.3,
487
- reverse_rotation_direction: false
488
- },
489
- {
490
- alpha: -1.5707963267948966,
491
- theta: 0,
492
- a: 0,
493
- d: 99.7,
494
- reverse_rotation_direction: false
495
- },
496
- {
497
- alpha: 0,
498
- theta: 0,
499
- a: 0,
500
- d: 99.6,
501
- reverse_rotation_direction: false
502
- }
503
- ],
504
- mechanical_joint_limits: [
505
- {
506
- joint: "JOINTNAME_AXIS_1",
507
- lower_limit: -6.335545063018799,
508
- upper_limit: 6.335545063018799,
509
- unlimited: false
510
- },
511
- {
512
- joint: "JOINTNAME_AXIS_2",
513
- lower_limit: -6.335545063018799,
514
- upper_limit: 6.335545063018799,
515
- unlimited: false
516
- },
517
- {
518
- joint: "JOINTNAME_AXIS_3",
519
- lower_limit: -6.335545063018799,
520
- upper_limit: 6.335545063018799,
521
- unlimited: false
522
- },
523
- {
524
- joint: "JOINTNAME_AXIS_4",
525
- lower_limit: -6.335545063018799,
526
- upper_limit: 6.335545063018799,
527
- unlimited: false
528
- },
529
- {
530
- joint: "JOINTNAME_AXIS_5",
531
- lower_limit: -6.335545063018799,
532
- upper_limit: 6.335545063018799,
533
- unlimited: false
534
- },
535
- {
536
- joint: "JOINTNAME_AXIS_6",
537
- lower_limit: -6.335545063018799,
538
- upper_limit: 6.335545063018799,
539
- unlimited: false
540
- }
541
- ]
542
- };
543
- }
544
- },
545
- {
546
- method: "GET",
547
- path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
548
- handle() {
549
- return {
550
- safety_settings: [
551
- {
552
- safety_state: "SAFETY_NORMAL",
553
- settings: {
554
- joint_position_limits: [
555
- {
556
- joint: "JOINTNAME_AXIS_1",
557
- lower_limit: -2.96705961227417,
558
- upper_limit: 2.96705961227417,
559
- unlimited: false
560
- },
561
- {
562
- joint: "JOINTNAME_AXIS_2",
563
- lower_limit: -1.7453292608261108,
564
- upper_limit: 2.7925267219543457,
565
- unlimited: false
566
- },
567
- {
568
- joint: "JOINTNAME_AXIS_3",
569
- lower_limit: -3.3161256313323975,
570
- upper_limit: 0.40142571926116943,
571
- unlimited: false
572
- },
573
- {
574
- joint: "JOINTNAME_AXIS_4",
575
- lower_limit: -3.4906585216522217,
576
- upper_limit: 3.4906585216522217,
577
- unlimited: false
578
- },
579
- {
580
- joint: "JOINTNAME_AXIS_5",
581
- lower_limit: -2.4434609413146973,
582
- upper_limit: 2.4434609413146973,
583
- unlimited: false
584
- },
585
- {
586
- joint: "JOINTNAME_AXIS_6",
587
- lower_limit: -4.71238899230957,
588
- upper_limit: 4.71238899230957,
589
- unlimited: false
590
- }
591
- ],
592
- joint_velocity_limits: [
593
- {
594
- joint: "JOINTNAME_AXIS_1",
595
- limit: 3.1415927410125732
596
- },
597
- {
598
- joint: "JOINTNAME_AXIS_2",
599
- limit: 3.1415927410125732
600
- },
601
- {
602
- joint: "JOINTNAME_AXIS_3",
603
- limit: 3.4906585216522217
604
- },
605
- {
606
- joint: "JOINTNAME_AXIS_4",
607
- limit: 6.108652591705322
608
- },
609
- {
610
- joint: "JOINTNAME_AXIS_5",
611
- limit: 6.108652591705322
612
- },
613
- {
614
- joint: "JOINTNAME_AXIS_6",
615
- limit: 6.981317043304443
616
- }
617
- ],
618
- joint_acceleration_limits: [],
619
- joint_torque_limits: [],
620
- tcp_velocity_limit: 1800
621
- }
622
- }
623
- ],
624
- safety_zones: [
625
- {
626
- id: 1,
627
- priority: 0,
628
- geometry: {
629
- compound: {
630
- child_geometries: [
631
- {
632
- convex_hull: {
633
- vertices: [
634
- { vertex: [-800, -1330, -1820] },
635
- { vertex: [1650, -1330, -1820] },
636
- { vertex: [1650, 1330, -1820] },
637
- { vertex: [-800, 1330, -1820] }
638
- ]
639
- },
640
- init_pose: {
641
- position: [0, 0, 0],
642
- orientation: [0, 0, 0, 1]
643
- },
644
- id: "box"
645
- },
646
- {
647
- convex_hull: {
648
- vertices: [
649
- {
650
- vertex: [-800, -1330, -1820]
651
- },
652
- {
653
- vertex: [1650, -1330, -1820]
654
- },
655
- {
656
- vertex: [1650, -1330, 1500]
657
- },
658
- {
659
- vertex: [-800, -1330, 1500]
660
- }
661
- ]
662
- },
663
- init_pose: {
664
- position: [0, 0, 0],
665
- orientation: [0, 0, 0, 1]
666
- },
667
- id: "box"
668
- },
669
- {
670
- convex_hull: {
671
- vertices: [
672
- {
673
- vertex: [-800, -1330, -1820]
674
- },
675
- {
676
- vertex: [-800, 1330, -1820]
677
- },
678
- {
679
- vertex: [-800, 1330, 1500]
680
- },
681
- {
682
- vertex: [-800, -1330, 1500]
683
- }
684
- ]
685
- },
686
- init_pose: {
687
- position: [0, 0, 0],
688
- orientation: [0, 0, 0, 1]
689
- },
690
- id: "box"
691
- },
692
- {
693
- convex_hull: {
694
- vertices: [
695
- {
696
- vertex: [1650, 1330, 1500]
697
- },
698
- {
699
- vertex: [-800, 1330, 1500]
700
- },
701
- {
702
- vertex: [-800, -1330, 1500]
703
- },
704
- {
705
- vertex: [1650, -1330, 1500]
706
- }
707
- ]
708
- },
709
- init_pose: {
710
- position: [0, 0, 0],
711
- orientation: [0, 0, 0, 1]
712
- },
713
- id: "box"
714
- },
715
- {
716
- convex_hull: {
717
- vertices: [
718
- {
719
- vertex: [1650, 1330, 1500]
720
- },
721
- {
722
- vertex: [-800, 1330, 1500]
723
- },
724
- {
725
- vertex: [-800, 1330, -1820]
726
- },
727
- {
728
- vertex: [1650, 1330, -1820]
729
- }
730
- ]
731
- },
732
- init_pose: {
733
- position: [0, 0, 0],
734
- orientation: [0, 0, 0, 1]
735
- },
736
- id: "box"
737
- },
738
- {
739
- convex_hull: {
740
- vertices: [
741
- {
742
- vertex: [1650, 1330, 1500]
743
- },
744
- {
745
- vertex: [1650, -1330, 1500]
746
- },
747
- {
748
- vertex: [1650, -1330, -1820]
749
- },
750
- {
751
- vertex: [1650, 1330, -1820]
752
- }
753
- ]
754
- },
755
- init_pose: {
756
- position: [0, 0, 0],
757
- orientation: [0, 0, 0, 1]
758
- },
759
- id: "box"
760
- }
761
- ]
762
- },
763
- init_pose: {
764
- position: [0, 0, 0],
765
- orientation: [0, 0, 0, 1]
766
- },
767
- id: "Cell workzone"
768
- },
769
- motion_group_uid: 1
770
- },
771
- {
772
- id: 2,
773
- priority: 0,
774
- geometry: {
775
- convex_hull: {
776
- vertices: [
777
- {
778
- vertex: [1650, 1330, -1850]
779
- },
780
- {
781
- vertex: [865, 1330, -1850]
782
- },
783
- {
784
- vertex: [865, -720, -1850]
785
- },
786
- {
787
- vertex: [1650, -720, -1850]
788
- },
789
- {
790
- vertex: [1650, 1330, -920]
791
- },
792
- {
793
- vertex: [865, 1330, -920]
794
- },
795
- {
796
- vertex: [865, -720, -920]
797
- },
798
- {
799
- vertex: [1650, -720, -920]
800
- }
801
- ]
802
- },
803
- init_pose: {
804
- position: [0, 0, 0],
805
- orientation: [0, 0, 0, 1]
806
- },
807
- id: "Transport"
808
- },
809
- motion_group_uid: 1
810
- },
811
- {
812
- id: 3,
813
- priority: 0,
814
- geometry: {
815
- convex_hull: {
816
- vertices: [
817
- {
818
- vertex: [1650, 1330, -600]
819
- },
820
- {
821
- vertex: [865, 1330, -600]
822
- },
823
- {
824
- vertex: [865, 430, -600]
825
- },
826
- {
827
- vertex: [1650, 430, -600]
828
- },
829
- {
830
- vertex: [1650, 1330, -1250]
831
- },
832
- {
833
- vertex: [865, 1330, -1250]
834
- },
835
- {
836
- vertex: [865, 430, -1250]
837
- },
838
- {
839
- vertex: [1650, 430, -1250]
840
- }
841
- ]
842
- },
843
- init_pose: {
844
- position: [0, 0, 0],
845
- orientation: [0, 0, 0, 1]
846
- },
847
- id: "Tunel"
848
- },
849
- motion_group_uid: 1
850
- },
851
- {
852
- id: 4,
853
- priority: 0,
854
- geometry: {
855
- convex_hull: {
856
- vertices: [
857
- {
858
- vertex: [1650, -760, -440]
859
- },
860
- {
861
- vertex: [900, -760, -440]
862
- },
863
- {
864
- vertex: [900, -1330, -440]
865
- },
866
- {
867
- vertex: [1650, -1330, -440]
868
- },
869
- {
870
- vertex: [1650, -760, -1800]
871
- },
872
- {
873
- vertex: [900, -760, -1800]
874
- },
875
- {
876
- vertex: [900, -1330, -1800]
877
- },
878
- {
879
- vertex: [1650, -1330, -1800]
880
- }
881
- ]
882
- },
883
- init_pose: {
884
- position: [0, 0, 0],
885
- orientation: [0, 0, 0, 1]
886
- },
887
- id: "Fanuc controller"
888
- },
889
- motion_group_uid: 1
890
- },
891
- {
892
- id: 6,
893
- priority: 0,
894
- geometry: {
895
- convex_hull: {
896
- vertices: [
897
- {
898
- vertex: [-200, -200, -1900]
899
- },
900
- {
901
- vertex: [200, -200, -1900]
902
- },
903
- {
904
- vertex: [200, 200, -1900]
905
- },
906
- {
907
- vertex: [-200, 200, -1900]
908
- },
909
- {
910
- vertex: [-200, -200, -350]
911
- },
912
- {
913
- vertex: [200, -200, -350]
914
- },
915
- {
916
- vertex: [200, 200, -350]
917
- },
918
- {
919
- vertex: [-200, 200, -350]
920
- }
921
- ]
922
- },
923
- init_pose: {
924
- position: [0, 0, 0],
925
- orientation: [0, 0, 0, 1]
926
- },
927
- id: "Robot base"
928
- },
929
- motion_group_uid: 1
930
- }
931
- ],
932
- robot_model_geometries: [
933
- {
934
- link_index: 1,
935
- geometry: {
936
- sphere: {
937
- radius: 270
938
- },
939
- init_pose: {
940
- position: [-70, -70, -50],
941
- orientation: [0, 0, 0, 1]
942
- },
943
- id: "link1_sphere"
944
- }
945
- },
946
- {
947
- link_index: 2,
948
- geometry: {
949
- capsule: {
950
- radius: 160,
951
- cylinder_height: 800
952
- },
953
- init_pose: {
954
- position: [-450, 40, 170],
955
- orientation: [0, -Math.SQRT1_2, 0, Math.SQRT1_2]
956
- },
957
- id: "link2_capsule"
958
- }
959
- },
960
- {
961
- link_index: 3,
962
- geometry: {
963
- sphere: {
964
- radius: 270
965
- },
966
- init_pose: {
967
- position: [-110, 10, -100],
968
- orientation: [0, 0, 0, 1]
969
- },
970
- id: "link3_sphere"
971
- }
972
- },
973
- {
974
- link_index: 4,
975
- geometry: {
976
- capsule: {
977
- radius: 110,
978
- cylinder_height: 600
979
- },
980
- init_pose: {
981
- position: [0, 300, 40],
982
- orientation: [-Math.SQRT1_2, 0, 0, Math.SQRT1_2]
983
- },
984
- id: "link4_capsule"
985
- }
986
- },
987
- {
988
- link_index: 5,
989
- geometry: {
990
- sphere: {
991
- radius: 75
992
- },
993
- init_pose: {
994
- position: [0, 0, -50],
995
- orientation: [0, 0, 0, 1]
996
- },
997
- id: "link5_sphere"
998
- }
999
- }
1000
- ],
1001
- tool_geometries: []
1002
- };
1003
- }
1004
- },
1005
- {
1006
- method: "GET",
1007
- path: "/cells/:cellId/coordinate-systems",
1008
- handle() {
1009
- return {
1010
- coordinatesystems: [
1011
- {
1012
- coordinate_system: "",
1013
- name: "world",
1014
- reference_uid: "",
1015
- position: [0, 0, 0],
1016
- rotation: {
1017
- angles: [0, 0, 0],
1018
- type: "ROTATION_VECTOR"
1019
- }
1020
- }
1021
- ]
1022
- };
1023
- }
1024
- },
1025
- {
1026
- method: "GET",
1027
- path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
1028
- handle() {
1029
- return {
1030
- tcps: [
1031
- {
1032
- id: "Flange",
1033
- readable_name: "Default-Flange",
1034
- position: [0, 0, 0],
1035
- rotation: {
1036
- angles: [0, 0, 0, 0],
1037
- type: "ROTATION_VECTOR"
1038
- }
1039
- },
1040
- {
1041
- id: "complex-tcp-position",
1042
- readable_name: "Complex TCP Position",
1043
- position: [-200, 300, 150],
1044
- rotation: {
1045
- angles: [
1046
- -0.12139440409113832,
1047
- -0.06356210998212003,
1048
- -0.2023240068185639,
1049
- 0
1050
- ],
1051
- type: "ROTATION_VECTOR"
1052
- }
1053
- }
1054
- ]
1055
- };
1056
- }
1057
- }
1058
- ];
1059
- const method = ((_a = config.method) == null ? void 0 : _a.toUpperCase()) || "GET";
1060
- const path = `/cells${(_c = (_b = config.url) == null ? void 0 : _b.split("/cells")[1]) == null ? void 0 : _c.split("?")[0]}`;
1061
- for (const handler of apiHandlers) {
1062
- const match2 = pathToRegexp.match(handler.path)(path || "");
1063
- if (method === handler.method && match2) {
1064
- const json = handler.handle();
1065
- return {
1066
- status: 200,
1067
- statusText: "Success",
1068
- data: JSON.stringify(json),
1069
- headers: {},
1070
- config,
1071
- request: {
1072
- responseURL: config.url
1073
- }
1074
- };
1075
- }
1076
- }
1077
- throw new import_axios2.AxiosError(
1078
- `No mock handler matched this request: ${method} ${path}`,
1079
- "404",
1080
- config
1081
- );
1082
- });
1083
- }
1084
- handleWebsocketConnection(socket) {
1085
- this.connections.push(socket);
1086
- setTimeout(() => {
1087
- socket.dispatchEvent(new Event("open"));
1088
- console.log("Websocket connection opened from", socket.url);
1089
- if (socket.url.includes("/state-stream")) {
1090
- socket.dispatchEvent(
1091
- new MessageEvent("message", {
1092
- data: JSON.stringify(defaultMotionState)
1093
- })
1094
- );
1095
- }
1096
- if (socket.url.includes("/move-joint")) {
1097
- socket.dispatchEvent(
1098
- new MessageEvent("message", {
1099
- data: JSON.stringify({
1100
- result: {
1101
- motion_group: "0@ur",
1102
- state: {
1103
- controller: "ur",
1104
- operation_mode: "OPERATION_MODE_AUTO",
1105
- safety_state: "SAFETY_STATE_NORMAL",
1106
- timestamp: "2024-09-18T12:48:26.096266444Z",
1107
- velocity_override: 100,
1108
- motion_groups: [
1109
- {
1110
- motion_group: "0@ur",
1111
- controller: "ur",
1112
- joint_position: [
1113
- 1.3492152690887451,
1114
- -1.5659207105636597,
1115
- 1.6653711795806885,
1116
- -1.0991662740707397,
1117
- -1.829018235206604,
1118
- 1.264623761177063
1119
- ],
1120
- joint_velocity: {
1121
- joints: [0, 0, 0, 0, 0, 0]
1122
- },
1123
- flange_pose: {
1124
- position: [
1125
- 6.437331889439328,
1126
- -628.4123774830913,
1127
- 577.0569957147832
1128
- ],
1129
- orientation: {
1130
- x: -1.683333649797158,
1131
- y: -1.9783363827298732,
1132
- z: -0.4928031860165713
1133
- },
1134
- coordinate_system: ""
1135
- },
1136
- tcp_pose: {
1137
- position: [
1138
- 6.437331889439328,
1139
- -628.4123774830913,
1140
- 577.0569957147832
1141
- ],
1142
- orientation: {
1143
- x: -1.683333649797158,
1144
- y: -1.9783363827298732,
1145
- z: -0.4928031860165713
1146
- },
1147
- coordinate_system: "",
1148
- tcp: "Flange"
1149
- },
1150
- velocity: {
1151
- linear: {
1152
- x: 0,
1153
- y: 0,
1154
- z: 0
1155
- },
1156
- angular: {
1157
- x: -0,
1158
- y: 0,
1159
- z: 0
1160
- },
1161
- coordinate_system: ""
1162
- },
1163
- force: {
1164
- force: {
1165
- x: 0,
1166
- y: 0,
1167
- z: 0
1168
- },
1169
- moment: {
1170
- x: 0,
1171
- y: 0,
1172
- z: 0
1173
- },
1174
- coordinate_system: ""
1175
- },
1176
- joint_limit_reached: {
1177
- limit_reached: [
1178
- false,
1179
- false,
1180
- false,
1181
- false,
1182
- false,
1183
- false
1184
- ]
1185
- },
1186
- joint_current: {
1187
- joints: [0, 0, 0, 0, 0, 0]
1188
- },
1189
- sequence_number: "671259"
1190
- }
1191
- ],
1192
- sequence_number: "671259"
1193
- },
1194
- movement_state: "MOVEMENT_STATE_MOVING"
1195
- }
1196
- })
1197
- })
1198
- );
1199
- }
1200
- if (socket.url.includes("/move-tcp")) {
1201
- socket.dispatchEvent(
1202
- new MessageEvent("message", {
1203
- data: JSON.stringify({
1204
- result: {
1205
- motion_group: "0@ur",
1206
- state: {
1207
- controller: "ur",
1208
- operation_mode: "OPERATION_MODE_AUTO",
1209
- safety_state: "SAFETY_STATE_NORMAL",
1210
- timestamp: "2024-09-18T12:43:12.188335774Z",
1211
- velocity_override: 100,
1212
- motion_groups: [
1213
- {
1214
- motion_group: "0@ur",
1215
- controller: "ur",
1216
- joint_position: {
1217
- joints: [
1218
- 1.3352527618408203,
1219
- -1.5659207105636597,
1220
- 1.6653711795806885,
1221
- -1.110615611076355,
1222
- -1.829018235206604,
1223
- 1.264623761177063
1224
- ]
1225
- },
1226
- joint_velocity: {
1227
- joints: [0, 0, 0, 0, 0, 0]
1228
- },
1229
- flange_pose: {
1230
- position: [
1231
- -2.763015284002938,
1232
- -630.2151479701106,
1233
- 577.524509114342
1234
- ],
1235
- orientation: {
1236
- x: -1.704794877102097,
1237
- y: -1.9722372952861567,
1238
- z: -0.4852079204210754
1239
- },
1240
- coordinate_system: ""
1241
- },
1242
- tcp_pose: {
1243
- position: [
1244
- -2.763015284002938,
1245
- -630.2151479701106,
1246
- 577.524509114342
1247
- ],
1248
- orientation: {
1249
- x: -1.704794877102097,
1250
- y: -1.9722372952861567,
1251
- z: -0.4852079204210754
1252
- },
1253
- coordinate_system: "",
1254
- tcp: "Flange"
1255
- },
1256
- velocity: {
1257
- linear: {
1258
- x: 0,
1259
- y: 0,
1260
- z: 0
1261
- },
1262
- angular: {
1263
- x: -0,
1264
- y: 0,
1265
- z: 0
1266
- },
1267
- coordinate_system: ""
1268
- },
1269
- force: {
1270
- force: {
1271
- x: 0,
1272
- y: 0,
1273
- z: 0
1274
- },
1275
- moment: {
1276
- x: 0,
1277
- y: 0,
1278
- z: 0
1279
- },
1280
- coordinate_system: ""
1281
- },
1282
- joint_limit_reached: {
1283
- limit_reached: [
1284
- false,
1285
- false,
1286
- false,
1287
- false,
1288
- false,
1289
- false
1290
- ]
1291
- },
1292
- joint_current: {
1293
- joints: [0, 0, 0, 0, 0, 0]
1294
- },
1295
- sequence_number: "627897"
1296
- }
1297
- ],
1298
- sequence_number: "627897"
1299
- },
1300
- movement_state: "MOVEMENT_STATE_MOVING"
1301
- }
1302
- })
1303
- })
1304
- );
1305
- }
1306
- }, 10);
1307
- }
1308
- handleWebsocketMessage(socket, message) {
1309
- console.log(`Received message on ${socket.url}`, message);
1310
- }
1311
- };
1312
- var defaultMotionState = {
1313
- result: {
1314
- motion_group: "0@universalrobots-ur5e",
1315
- controller: "universalrobots-ur5e",
1316
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1317
- sequence_number: 1,
1318
- joint_position: [
1319
- 1.1699999570846558,
1320
- -1.5700000524520874,
1321
- 1.3600000143051147,
1322
- 1.0299999713897705,
1323
- 1.2899999618530273,
1324
- 1.2799999713897705
1325
- ],
1326
- joint_limit_reached: {
1327
- limit_reached: [false, false, false, false, false, false]
1328
- },
1329
- standstill: false,
1330
- flange_pose: {
1331
- position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
1332
- orientation: [
1333
- 1.7564919306270736,
1334
- -1.7542521568325058,
1335
- 0.7326972590614671
1336
- ]
1337
- },
1338
- tcp_pose: {
1339
- position: [1.3300010259703043, -409.2680714682808, 531.0203477065281],
1340
- orientation: [
1341
- 1.7564919306270736,
1342
- -1.7542521568325058,
1343
- 0.7326972590614671
1344
- ]
1345
- }
1346
- }
86
+ constructor() {
87
+ this.connections = [];
88
+ }
89
+ async handleAPIRequest(config) {
90
+ const apiHandlers = [
91
+ {
92
+ method: "GET",
93
+ path: "/cells/:cellId/controllers/:controllerId/state",
94
+ handle() {
95
+ return {
96
+ mode: "MODE_CONTROL",
97
+ last_error: [],
98
+ timestamp: "2025-10-16T09:19:26.634534092Z",
99
+ sequence_number: 1054764,
100
+ controller: "mock-ur5e",
101
+ operation_mode: "OPERATION_MODE_AUTO",
102
+ safety_state: "SAFETY_STATE_NORMAL",
103
+ velocity_override: 100,
104
+ motion_groups: [{
105
+ timestamp: "2025-10-16T09:19:26.634534092Z",
106
+ sequence_number: 1054764,
107
+ motion_group: "0@mock-ur5e",
108
+ controller: "mock-ur5e",
109
+ joint_position: [
110
+ 1.487959623336792,
111
+ -1.8501918315887451,
112
+ 1.8003005981445312,
113
+ 6.034560203552246,
114
+ 1.4921919107437134,
115
+ 1.593459963798523
116
+ ],
117
+ joint_limit_reached: { limit_reached: [
118
+ false,
119
+ false,
120
+ false,
121
+ false,
122
+ false,
123
+ false
124
+ ] },
125
+ joint_torque: [],
126
+ joint_current: [
127
+ 0,
128
+ 0,
129
+ 0,
130
+ 0,
131
+ 0,
132
+ 0
133
+ ],
134
+ flange_pose: {
135
+ position: [
136
+ 107.6452433732927,
137
+ -409.0402987746852,
138
+ 524.2402132330305
139
+ ],
140
+ orientation: [
141
+ .9874434028353319,
142
+ -.986571714997442,
143
+ 1.3336589451098142
144
+ ]
145
+ },
146
+ tcp: "Flange",
147
+ tcp_pose: {
148
+ position: [
149
+ 107.6452433732927,
150
+ -409.0402987746852,
151
+ 524.2402132330305
152
+ ],
153
+ orientation: [
154
+ .9874434028353319,
155
+ -.986571714997442,
156
+ 1.3336589451098142
157
+ ]
158
+ },
159
+ payload: "",
160
+ coordinate_system: "",
161
+ standstill: true
162
+ }]
163
+ };
164
+ }
165
+ },
166
+ {
167
+ method: "GET",
168
+ path: "/cells/:cellId/controllers/:controllerId/coordinate-systems",
169
+ handle() {
170
+ return [{
171
+ coordinate_system: "",
172
+ name: "world",
173
+ reference_coordinate_system: "",
174
+ position: [
175
+ 0,
176
+ 0,
177
+ 0
178
+ ],
179
+ orientation: [
180
+ 0,
181
+ 0,
182
+ 0
183
+ ],
184
+ orientation_type: "ROTATION_VECTOR"
185
+ }, {
186
+ coordinate_system: "CS-0",
187
+ name: "Default-CS",
188
+ reference_coordinate_system: "",
189
+ position: [
190
+ 0,
191
+ 0,
192
+ 0
193
+ ],
194
+ orientation: [
195
+ 0,
196
+ 0,
197
+ 0
198
+ ],
199
+ orientation_type: "ROTATION_VECTOR"
200
+ }];
201
+ }
202
+ },
203
+ {
204
+ method: "GET",
205
+ path: "/cells/:cellId/controllers/:controllerId/motion-groups/:motionGroupId/description",
206
+ handle() {
207
+ return {
208
+ motion_group_model: "UniversalRobots_UR5e",
209
+ mounting: {
210
+ position: [
211
+ 0,
212
+ 0,
213
+ 0
214
+ ],
215
+ orientation: [
216
+ 0,
217
+ 0,
218
+ 0
219
+ ]
220
+ },
221
+ tcps: {
222
+ Flange: {
223
+ name: "Default-Flange",
224
+ pose: {
225
+ position: [
226
+ 0,
227
+ 0,
228
+ 0
229
+ ],
230
+ orientation: [
231
+ 0,
232
+ 0,
233
+ 0
234
+ ]
235
+ }
236
+ },
237
+ "complex-tcp-position": {
238
+ name: "Complex TCP Position",
239
+ pose: {
240
+ position: [
241
+ -200,
242
+ 300,
243
+ 150
244
+ ],
245
+ orientation: [
246
+ -.12139440409113832,
247
+ -.06356210998212003,
248
+ -.2023240068185639
249
+ ]
250
+ }
251
+ },
252
+ "offset-150mm-xy": {
253
+ name: "-150mm XY Offset",
254
+ pose: {
255
+ position: [
256
+ -150,
257
+ -150,
258
+ 0
259
+ ],
260
+ orientation: [
261
+ 0,
262
+ 0,
263
+ 0
264
+ ]
265
+ }
266
+ },
267
+ "rotated-90deg-z": {
268
+ name: "90° Z Axis Rotation",
269
+ pose: {
270
+ position: [
271
+ 0,
272
+ 0,
273
+ 0
274
+ ],
275
+ orientation: [
276
+ 0,
277
+ 0,
278
+ 1.5708
279
+ ]
280
+ }
281
+ }
282
+ },
283
+ payloads: { "FPay-0": {
284
+ name: "FPay-0",
285
+ payload: 0,
286
+ center_of_mass: [
287
+ 0,
288
+ 0,
289
+ 0
290
+ ],
291
+ moment_of_inertia: [
292
+ 0,
293
+ 0,
294
+ 0
295
+ ]
296
+ } },
297
+ cycle_time: 8,
298
+ dh_parameters: [
299
+ {
300
+ alpha: 1.5707963267948966,
301
+ d: 162.25
302
+ },
303
+ { a: -425 },
304
+ { a: -392.2 },
305
+ {
306
+ alpha: 1.5707963267948966,
307
+ d: 133.3
308
+ },
309
+ {
310
+ alpha: -1.5707963267948966,
311
+ d: 99.7
312
+ },
313
+ { d: 99.6 }
314
+ ],
315
+ operation_limits: {
316
+ auto_limits: {
317
+ joints: [
318
+ {
319
+ position: {
320
+ lower_limit: -6.283185307179586,
321
+ upper_limit: 6.283185307179586
322
+ },
323
+ velocity: 3.34159255027771,
324
+ acceleration: 40,
325
+ torque: 150
326
+ },
327
+ {
328
+ position: {
329
+ lower_limit: -6.283185307179586,
330
+ upper_limit: 6.283185307179586
331
+ },
332
+ velocity: 3.34159255027771,
333
+ acceleration: 40,
334
+ torque: 150
335
+ },
336
+ {
337
+ position: {
338
+ lower_limit: -6.283185307179586,
339
+ upper_limit: 6.283185307179586
340
+ },
341
+ velocity: 3.34159255027771,
342
+ acceleration: 40,
343
+ torque: 150
344
+ },
345
+ {
346
+ position: {
347
+ lower_limit: -6.283185307179586,
348
+ upper_limit: 6.283185307179586
349
+ },
350
+ velocity: 3.34159255027771,
351
+ acceleration: 40,
352
+ torque: 28
353
+ },
354
+ {
355
+ position: {
356
+ lower_limit: -6.283185307179586,
357
+ upper_limit: 6.283185307179586
358
+ },
359
+ velocity: 3.34159255027771,
360
+ acceleration: 40,
361
+ torque: 28
362
+ },
363
+ {
364
+ position: {
365
+ lower_limit: -6.283185307179586,
366
+ upper_limit: 6.283185307179586
367
+ },
368
+ velocity: 3.34159255027771,
369
+ acceleration: 40,
370
+ torque: 28
371
+ }
372
+ ],
373
+ tcp: { velocity: 5e3 },
374
+ elbow: { velocity: 5e3 },
375
+ flange: { velocity: 5e3 }
376
+ },
377
+ manual_limits: {
378
+ joints: [
379
+ {
380
+ position: {
381
+ lower_limit: -6.283185307179586,
382
+ upper_limit: 6.283185307179586
383
+ },
384
+ velocity: 3.34159255027771,
385
+ acceleration: 40,
386
+ torque: 150
387
+ },
388
+ {
389
+ position: {
390
+ lower_limit: -6.283185307179586,
391
+ upper_limit: 6.283185307179586
392
+ },
393
+ velocity: 3.34159255027771,
394
+ acceleration: 40,
395
+ torque: 150
396
+ },
397
+ {
398
+ position: {
399
+ lower_limit: -6.283185307179586,
400
+ upper_limit: 6.283185307179586
401
+ },
402
+ velocity: 3.34159255027771,
403
+ acceleration: 40,
404
+ torque: 150
405
+ },
406
+ {
407
+ position: {
408
+ lower_limit: -6.283185307179586,
409
+ upper_limit: 6.283185307179586
410
+ },
411
+ velocity: 3.34159255027771,
412
+ acceleration: 40,
413
+ torque: 28
414
+ },
415
+ {
416
+ position: {
417
+ lower_limit: -6.283185307179586,
418
+ upper_limit: 6.283185307179586
419
+ },
420
+ velocity: 3.34159255027771,
421
+ acceleration: 40,
422
+ torque: 28
423
+ },
424
+ {
425
+ position: {
426
+ lower_limit: -6.283185307179586,
427
+ upper_limit: 6.283185307179586
428
+ },
429
+ velocity: 3.34159255027771,
430
+ acceleration: 40,
431
+ torque: 28
432
+ }
433
+ ],
434
+ tcp: { velocity: 5e3 }
435
+ },
436
+ manual_t1_limits: {
437
+ joints: [
438
+ {
439
+ position: {
440
+ lower_limit: -6.283185307179586,
441
+ upper_limit: 6.283185307179586
442
+ },
443
+ velocity: 3.34159255027771,
444
+ acceleration: 40,
445
+ torque: 150
446
+ },
447
+ {
448
+ position: {
449
+ lower_limit: -6.283185307179586,
450
+ upper_limit: 6.283185307179586
451
+ },
452
+ velocity: 3.34159255027771,
453
+ acceleration: 40,
454
+ torque: 150
455
+ },
456
+ {
457
+ position: {
458
+ lower_limit: -6.283185307179586,
459
+ upper_limit: 6.283185307179586
460
+ },
461
+ velocity: 3.34159255027771,
462
+ acceleration: 40,
463
+ torque: 150
464
+ },
465
+ {
466
+ position: {
467
+ lower_limit: -6.283185307179586,
468
+ upper_limit: 6.283185307179586
469
+ },
470
+ velocity: 3.34159255027771,
471
+ acceleration: 40,
472
+ torque: 28
473
+ },
474
+ {
475
+ position: {
476
+ lower_limit: -6.283185307179586,
477
+ upper_limit: 6.283185307179586
478
+ },
479
+ velocity: 3.34159255027771,
480
+ acceleration: 40,
481
+ torque: 28
482
+ },
483
+ {
484
+ position: {
485
+ lower_limit: -6.283185307179586,
486
+ upper_limit: 6.283185307179586
487
+ },
488
+ velocity: 3.34159255027771,
489
+ acceleration: 40,
490
+ torque: 28
491
+ }
492
+ ],
493
+ tcp: { velocity: 5e3 }
494
+ },
495
+ manual_t2_limits: {
496
+ joints: [
497
+ {
498
+ position: {
499
+ lower_limit: -6.283185307179586,
500
+ upper_limit: 6.283185307179586
501
+ },
502
+ velocity: 3.34159255027771,
503
+ acceleration: 40,
504
+ torque: 150
505
+ },
506
+ {
507
+ position: {
508
+ lower_limit: -6.283185307179586,
509
+ upper_limit: 6.283185307179586
510
+ },
511
+ velocity: 3.34159255027771,
512
+ acceleration: 40,
513
+ torque: 150
514
+ },
515
+ {
516
+ position: {
517
+ lower_limit: -6.283185307179586,
518
+ upper_limit: 6.283185307179586
519
+ },
520
+ velocity: 3.34159255027771,
521
+ acceleration: 40,
522
+ torque: 150
523
+ },
524
+ {
525
+ position: {
526
+ lower_limit: -6.283185307179586,
527
+ upper_limit: 6.283185307179586
528
+ },
529
+ velocity: 3.34159255027771,
530
+ acceleration: 40,
531
+ torque: 28
532
+ },
533
+ {
534
+ position: {
535
+ lower_limit: -6.283185307179586,
536
+ upper_limit: 6.283185307179586
537
+ },
538
+ velocity: 3.34159255027771,
539
+ acceleration: 40,
540
+ torque: 28
541
+ },
542
+ {
543
+ position: {
544
+ lower_limit: -6.283185307179586,
545
+ upper_limit: 6.283185307179586
546
+ },
547
+ velocity: 3.34159255027771,
548
+ acceleration: 40,
549
+ torque: 28
550
+ }
551
+ ],
552
+ tcp: { velocity: 5e3 }
553
+ }
554
+ },
555
+ serial_number: "WBVirtualRobot"
556
+ };
557
+ }
558
+ },
559
+ {
560
+ method: "GET",
561
+ path: "/cells/:cellId/controllers",
562
+ handle() {
563
+ return { controllers: [{
564
+ controller: "mock-ur5e",
565
+ model_name: "UniversalRobots::Controller",
566
+ host: "mock-ur5e",
567
+ allow_software_install_on_controller: true,
568
+ motion_groups: [{
569
+ motion_group: "0@mock-ur5e",
570
+ name_from_controller: "UR5e",
571
+ active: false,
572
+ model_from_controller: "UniversalRobots_UR5e"
573
+ }],
574
+ has_error: false,
575
+ error_details: ""
576
+ }] };
577
+ }
578
+ },
579
+ {
580
+ method: "GET",
581
+ path: "/cells/:cellId/controllers/:controllerId",
582
+ handle() {
583
+ return {
584
+ configuration: {
585
+ kind: "VirtualController",
586
+ manufacturer: "universalrobots",
587
+ type: "universalrobots-ur5e"
588
+ },
589
+ name: "mock-ur5"
590
+ };
591
+ }
592
+ },
593
+ {
594
+ method: "GET",
595
+ path: "/cells/:cellId/motion-groups/:motionGroupId/specification",
596
+ handle() {
597
+ return {
598
+ dh_parameters: [
599
+ {
600
+ alpha: 1.5707963267948966,
601
+ theta: 0,
602
+ a: 0,
603
+ d: 162.25,
604
+ reverse_rotation_direction: false
605
+ },
606
+ {
607
+ alpha: 0,
608
+ theta: 0,
609
+ a: -425,
610
+ d: 0,
611
+ reverse_rotation_direction: false
612
+ },
613
+ {
614
+ alpha: 0,
615
+ theta: 0,
616
+ a: -392.2,
617
+ d: 0,
618
+ reverse_rotation_direction: false
619
+ },
620
+ {
621
+ alpha: 1.5707963267948966,
622
+ theta: 0,
623
+ a: 0,
624
+ d: 133.3,
625
+ reverse_rotation_direction: false
626
+ },
627
+ {
628
+ alpha: -1.5707963267948966,
629
+ theta: 0,
630
+ a: 0,
631
+ d: 99.7,
632
+ reverse_rotation_direction: false
633
+ },
634
+ {
635
+ alpha: 0,
636
+ theta: 0,
637
+ a: 0,
638
+ d: 99.6,
639
+ reverse_rotation_direction: false
640
+ }
641
+ ],
642
+ mechanical_joint_limits: [
643
+ {
644
+ joint: "JOINTNAME_AXIS_1",
645
+ lower_limit: -6.335545063018799,
646
+ upper_limit: 6.335545063018799,
647
+ unlimited: false
648
+ },
649
+ {
650
+ joint: "JOINTNAME_AXIS_2",
651
+ lower_limit: -6.335545063018799,
652
+ upper_limit: 6.335545063018799,
653
+ unlimited: false
654
+ },
655
+ {
656
+ joint: "JOINTNAME_AXIS_3",
657
+ lower_limit: -6.335545063018799,
658
+ upper_limit: 6.335545063018799,
659
+ unlimited: false
660
+ },
661
+ {
662
+ joint: "JOINTNAME_AXIS_4",
663
+ lower_limit: -6.335545063018799,
664
+ upper_limit: 6.335545063018799,
665
+ unlimited: false
666
+ },
667
+ {
668
+ joint: "JOINTNAME_AXIS_5",
669
+ lower_limit: -6.335545063018799,
670
+ upper_limit: 6.335545063018799,
671
+ unlimited: false
672
+ },
673
+ {
674
+ joint: "JOINTNAME_AXIS_6",
675
+ lower_limit: -6.335545063018799,
676
+ upper_limit: 6.335545063018799,
677
+ unlimited: false
678
+ }
679
+ ]
680
+ };
681
+ }
682
+ },
683
+ {
684
+ method: "GET",
685
+ path: "/cells/:cellId/motion-groups/:motionGroupId/safety-setup",
686
+ handle() {
687
+ return {
688
+ safety_settings: [{
689
+ safety_state: "SAFETY_NORMAL",
690
+ settings: {
691
+ joint_position_limits: [
692
+ {
693
+ joint: "JOINTNAME_AXIS_1",
694
+ lower_limit: -2.96705961227417,
695
+ upper_limit: 2.96705961227417,
696
+ unlimited: false
697
+ },
698
+ {
699
+ joint: "JOINTNAME_AXIS_2",
700
+ lower_limit: -1.7453292608261108,
701
+ upper_limit: 2.7925267219543457,
702
+ unlimited: false
703
+ },
704
+ {
705
+ joint: "JOINTNAME_AXIS_3",
706
+ lower_limit: -3.3161256313323975,
707
+ upper_limit: .40142571926116943,
708
+ unlimited: false
709
+ },
710
+ {
711
+ joint: "JOINTNAME_AXIS_4",
712
+ lower_limit: -3.4906585216522217,
713
+ upper_limit: 3.4906585216522217,
714
+ unlimited: false
715
+ },
716
+ {
717
+ joint: "JOINTNAME_AXIS_5",
718
+ lower_limit: -2.4434609413146973,
719
+ upper_limit: 2.4434609413146973,
720
+ unlimited: false
721
+ },
722
+ {
723
+ joint: "JOINTNAME_AXIS_6",
724
+ lower_limit: -4.71238899230957,
725
+ upper_limit: 4.71238899230957,
726
+ unlimited: false
727
+ }
728
+ ],
729
+ joint_velocity_limits: [
730
+ {
731
+ joint: "JOINTNAME_AXIS_1",
732
+ limit: 3.1415927410125732
733
+ },
734
+ {
735
+ joint: "JOINTNAME_AXIS_2",
736
+ limit: 3.1415927410125732
737
+ },
738
+ {
739
+ joint: "JOINTNAME_AXIS_3",
740
+ limit: 3.4906585216522217
741
+ },
742
+ {
743
+ joint: "JOINTNAME_AXIS_4",
744
+ limit: 6.108652591705322
745
+ },
746
+ {
747
+ joint: "JOINTNAME_AXIS_5",
748
+ limit: 6.108652591705322
749
+ },
750
+ {
751
+ joint: "JOINTNAME_AXIS_6",
752
+ limit: 6.981317043304443
753
+ }
754
+ ],
755
+ joint_acceleration_limits: [],
756
+ joint_torque_limits: [],
757
+ tcp_velocity_limit: 1800
758
+ }
759
+ }],
760
+ safety_zones: [
761
+ {
762
+ id: 1,
763
+ priority: 0,
764
+ geometry: {
765
+ compound: { child_geometries: [
766
+ {
767
+ convex_hull: { vertices: [
768
+ { vertex: [
769
+ -800,
770
+ -1330,
771
+ -1820
772
+ ] },
773
+ { vertex: [
774
+ 1650,
775
+ -1330,
776
+ -1820
777
+ ] },
778
+ { vertex: [
779
+ 1650,
780
+ 1330,
781
+ -1820
782
+ ] },
783
+ { vertex: [
784
+ -800,
785
+ 1330,
786
+ -1820
787
+ ] }
788
+ ] },
789
+ init_pose: {
790
+ position: [
791
+ 0,
792
+ 0,
793
+ 0
794
+ ],
795
+ orientation: [
796
+ 0,
797
+ 0,
798
+ 0,
799
+ 1
800
+ ]
801
+ },
802
+ id: "box"
803
+ },
804
+ {
805
+ convex_hull: { vertices: [
806
+ { vertex: [
807
+ -800,
808
+ -1330,
809
+ -1820
810
+ ] },
811
+ { vertex: [
812
+ 1650,
813
+ -1330,
814
+ -1820
815
+ ] },
816
+ { vertex: [
817
+ 1650,
818
+ -1330,
819
+ 1500
820
+ ] },
821
+ { vertex: [
822
+ -800,
823
+ -1330,
824
+ 1500
825
+ ] }
826
+ ] },
827
+ init_pose: {
828
+ position: [
829
+ 0,
830
+ 0,
831
+ 0
832
+ ],
833
+ orientation: [
834
+ 0,
835
+ 0,
836
+ 0,
837
+ 1
838
+ ]
839
+ },
840
+ id: "box"
841
+ },
842
+ {
843
+ convex_hull: { vertices: [
844
+ { vertex: [
845
+ -800,
846
+ -1330,
847
+ -1820
848
+ ] },
849
+ { vertex: [
850
+ -800,
851
+ 1330,
852
+ -1820
853
+ ] },
854
+ { vertex: [
855
+ -800,
856
+ 1330,
857
+ 1500
858
+ ] },
859
+ { vertex: [
860
+ -800,
861
+ -1330,
862
+ 1500
863
+ ] }
864
+ ] },
865
+ init_pose: {
866
+ position: [
867
+ 0,
868
+ 0,
869
+ 0
870
+ ],
871
+ orientation: [
872
+ 0,
873
+ 0,
874
+ 0,
875
+ 1
876
+ ]
877
+ },
878
+ id: "box"
879
+ },
880
+ {
881
+ convex_hull: { vertices: [
882
+ { vertex: [
883
+ 1650,
884
+ 1330,
885
+ 1500
886
+ ] },
887
+ { vertex: [
888
+ -800,
889
+ 1330,
890
+ 1500
891
+ ] },
892
+ { vertex: [
893
+ -800,
894
+ -1330,
895
+ 1500
896
+ ] },
897
+ { vertex: [
898
+ 1650,
899
+ -1330,
900
+ 1500
901
+ ] }
902
+ ] },
903
+ init_pose: {
904
+ position: [
905
+ 0,
906
+ 0,
907
+ 0
908
+ ],
909
+ orientation: [
910
+ 0,
911
+ 0,
912
+ 0,
913
+ 1
914
+ ]
915
+ },
916
+ id: "box"
917
+ },
918
+ {
919
+ convex_hull: { vertices: [
920
+ { vertex: [
921
+ 1650,
922
+ 1330,
923
+ 1500
924
+ ] },
925
+ { vertex: [
926
+ -800,
927
+ 1330,
928
+ 1500
929
+ ] },
930
+ { vertex: [
931
+ -800,
932
+ 1330,
933
+ -1820
934
+ ] },
935
+ { vertex: [
936
+ 1650,
937
+ 1330,
938
+ -1820
939
+ ] }
940
+ ] },
941
+ init_pose: {
942
+ position: [
943
+ 0,
944
+ 0,
945
+ 0
946
+ ],
947
+ orientation: [
948
+ 0,
949
+ 0,
950
+ 0,
951
+ 1
952
+ ]
953
+ },
954
+ id: "box"
955
+ },
956
+ {
957
+ convex_hull: { vertices: [
958
+ { vertex: [
959
+ 1650,
960
+ 1330,
961
+ 1500
962
+ ] },
963
+ { vertex: [
964
+ 1650,
965
+ -1330,
966
+ 1500
967
+ ] },
968
+ { vertex: [
969
+ 1650,
970
+ -1330,
971
+ -1820
972
+ ] },
973
+ { vertex: [
974
+ 1650,
975
+ 1330,
976
+ -1820
977
+ ] }
978
+ ] },
979
+ init_pose: {
980
+ position: [
981
+ 0,
982
+ 0,
983
+ 0
984
+ ],
985
+ orientation: [
986
+ 0,
987
+ 0,
988
+ 0,
989
+ 1
990
+ ]
991
+ },
992
+ id: "box"
993
+ }
994
+ ] },
995
+ init_pose: {
996
+ position: [
997
+ 0,
998
+ 0,
999
+ 0
1000
+ ],
1001
+ orientation: [
1002
+ 0,
1003
+ 0,
1004
+ 0,
1005
+ 1
1006
+ ]
1007
+ },
1008
+ id: "Cell workzone"
1009
+ },
1010
+ motion_group_uid: 1
1011
+ },
1012
+ {
1013
+ id: 2,
1014
+ priority: 0,
1015
+ geometry: {
1016
+ convex_hull: { vertices: [
1017
+ { vertex: [
1018
+ 1650,
1019
+ 1330,
1020
+ -1850
1021
+ ] },
1022
+ { vertex: [
1023
+ 865,
1024
+ 1330,
1025
+ -1850
1026
+ ] },
1027
+ { vertex: [
1028
+ 865,
1029
+ -720,
1030
+ -1850
1031
+ ] },
1032
+ { vertex: [
1033
+ 1650,
1034
+ -720,
1035
+ -1850
1036
+ ] },
1037
+ { vertex: [
1038
+ 1650,
1039
+ 1330,
1040
+ -920
1041
+ ] },
1042
+ { vertex: [
1043
+ 865,
1044
+ 1330,
1045
+ -920
1046
+ ] },
1047
+ { vertex: [
1048
+ 865,
1049
+ -720,
1050
+ -920
1051
+ ] },
1052
+ { vertex: [
1053
+ 1650,
1054
+ -720,
1055
+ -920
1056
+ ] }
1057
+ ] },
1058
+ init_pose: {
1059
+ position: [
1060
+ 0,
1061
+ 0,
1062
+ 0
1063
+ ],
1064
+ orientation: [
1065
+ 0,
1066
+ 0,
1067
+ 0,
1068
+ 1
1069
+ ]
1070
+ },
1071
+ id: "Transport"
1072
+ },
1073
+ motion_group_uid: 1
1074
+ },
1075
+ {
1076
+ id: 3,
1077
+ priority: 0,
1078
+ geometry: {
1079
+ convex_hull: { vertices: [
1080
+ { vertex: [
1081
+ 1650,
1082
+ 1330,
1083
+ -600
1084
+ ] },
1085
+ { vertex: [
1086
+ 865,
1087
+ 1330,
1088
+ -600
1089
+ ] },
1090
+ { vertex: [
1091
+ 865,
1092
+ 430,
1093
+ -600
1094
+ ] },
1095
+ { vertex: [
1096
+ 1650,
1097
+ 430,
1098
+ -600
1099
+ ] },
1100
+ { vertex: [
1101
+ 1650,
1102
+ 1330,
1103
+ -1250
1104
+ ] },
1105
+ { vertex: [
1106
+ 865,
1107
+ 1330,
1108
+ -1250
1109
+ ] },
1110
+ { vertex: [
1111
+ 865,
1112
+ 430,
1113
+ -1250
1114
+ ] },
1115
+ { vertex: [
1116
+ 1650,
1117
+ 430,
1118
+ -1250
1119
+ ] }
1120
+ ] },
1121
+ init_pose: {
1122
+ position: [
1123
+ 0,
1124
+ 0,
1125
+ 0
1126
+ ],
1127
+ orientation: [
1128
+ 0,
1129
+ 0,
1130
+ 0,
1131
+ 1
1132
+ ]
1133
+ },
1134
+ id: "Tunel"
1135
+ },
1136
+ motion_group_uid: 1
1137
+ },
1138
+ {
1139
+ id: 4,
1140
+ priority: 0,
1141
+ geometry: {
1142
+ convex_hull: { vertices: [
1143
+ { vertex: [
1144
+ 1650,
1145
+ -760,
1146
+ -440
1147
+ ] },
1148
+ { vertex: [
1149
+ 900,
1150
+ -760,
1151
+ -440
1152
+ ] },
1153
+ { vertex: [
1154
+ 900,
1155
+ -1330,
1156
+ -440
1157
+ ] },
1158
+ { vertex: [
1159
+ 1650,
1160
+ -1330,
1161
+ -440
1162
+ ] },
1163
+ { vertex: [
1164
+ 1650,
1165
+ -760,
1166
+ -1800
1167
+ ] },
1168
+ { vertex: [
1169
+ 900,
1170
+ -760,
1171
+ -1800
1172
+ ] },
1173
+ { vertex: [
1174
+ 900,
1175
+ -1330,
1176
+ -1800
1177
+ ] },
1178
+ { vertex: [
1179
+ 1650,
1180
+ -1330,
1181
+ -1800
1182
+ ] }
1183
+ ] },
1184
+ init_pose: {
1185
+ position: [
1186
+ 0,
1187
+ 0,
1188
+ 0
1189
+ ],
1190
+ orientation: [
1191
+ 0,
1192
+ 0,
1193
+ 0,
1194
+ 1
1195
+ ]
1196
+ },
1197
+ id: "Fanuc controller"
1198
+ },
1199
+ motion_group_uid: 1
1200
+ },
1201
+ {
1202
+ id: 6,
1203
+ priority: 0,
1204
+ geometry: {
1205
+ convex_hull: { vertices: [
1206
+ { vertex: [
1207
+ -200,
1208
+ -200,
1209
+ -1900
1210
+ ] },
1211
+ { vertex: [
1212
+ 200,
1213
+ -200,
1214
+ -1900
1215
+ ] },
1216
+ { vertex: [
1217
+ 200,
1218
+ 200,
1219
+ -1900
1220
+ ] },
1221
+ { vertex: [
1222
+ -200,
1223
+ 200,
1224
+ -1900
1225
+ ] },
1226
+ { vertex: [
1227
+ -200,
1228
+ -200,
1229
+ -350
1230
+ ] },
1231
+ { vertex: [
1232
+ 200,
1233
+ -200,
1234
+ -350
1235
+ ] },
1236
+ { vertex: [
1237
+ 200,
1238
+ 200,
1239
+ -350
1240
+ ] },
1241
+ { vertex: [
1242
+ -200,
1243
+ 200,
1244
+ -350
1245
+ ] }
1246
+ ] },
1247
+ init_pose: {
1248
+ position: [
1249
+ 0,
1250
+ 0,
1251
+ 0
1252
+ ],
1253
+ orientation: [
1254
+ 0,
1255
+ 0,
1256
+ 0,
1257
+ 1
1258
+ ]
1259
+ },
1260
+ id: "Robot base"
1261
+ },
1262
+ motion_group_uid: 1
1263
+ }
1264
+ ],
1265
+ robot_model_geometries: [
1266
+ {
1267
+ link_index: 1,
1268
+ geometry: {
1269
+ sphere: { radius: 270 },
1270
+ init_pose: {
1271
+ position: [
1272
+ -70,
1273
+ -70,
1274
+ -50
1275
+ ],
1276
+ orientation: [
1277
+ 0,
1278
+ 0,
1279
+ 0,
1280
+ 1
1281
+ ]
1282
+ },
1283
+ id: "link1_sphere"
1284
+ }
1285
+ },
1286
+ {
1287
+ link_index: 2,
1288
+ geometry: {
1289
+ capsule: {
1290
+ radius: 160,
1291
+ cylinder_height: 800
1292
+ },
1293
+ init_pose: {
1294
+ position: [
1295
+ -450,
1296
+ 40,
1297
+ 170
1298
+ ],
1299
+ orientation: [
1300
+ 0,
1301
+ -Math.SQRT1_2,
1302
+ 0,
1303
+ Math.SQRT1_2
1304
+ ]
1305
+ },
1306
+ id: "link2_capsule"
1307
+ }
1308
+ },
1309
+ {
1310
+ link_index: 3,
1311
+ geometry: {
1312
+ sphere: { radius: 270 },
1313
+ init_pose: {
1314
+ position: [
1315
+ -110,
1316
+ 10,
1317
+ -100
1318
+ ],
1319
+ orientation: [
1320
+ 0,
1321
+ 0,
1322
+ 0,
1323
+ 1
1324
+ ]
1325
+ },
1326
+ id: "link3_sphere"
1327
+ }
1328
+ },
1329
+ {
1330
+ link_index: 4,
1331
+ geometry: {
1332
+ capsule: {
1333
+ radius: 110,
1334
+ cylinder_height: 600
1335
+ },
1336
+ init_pose: {
1337
+ position: [
1338
+ 0,
1339
+ 300,
1340
+ 40
1341
+ ],
1342
+ orientation: [
1343
+ -Math.SQRT1_2,
1344
+ 0,
1345
+ 0,
1346
+ Math.SQRT1_2
1347
+ ]
1348
+ },
1349
+ id: "link4_capsule"
1350
+ }
1351
+ },
1352
+ {
1353
+ link_index: 5,
1354
+ geometry: {
1355
+ sphere: { radius: 75 },
1356
+ init_pose: {
1357
+ position: [
1358
+ 0,
1359
+ 0,
1360
+ -50
1361
+ ],
1362
+ orientation: [
1363
+ 0,
1364
+ 0,
1365
+ 0,
1366
+ 1
1367
+ ]
1368
+ },
1369
+ id: "link5_sphere"
1370
+ }
1371
+ }
1372
+ ],
1373
+ tool_geometries: []
1374
+ };
1375
+ }
1376
+ },
1377
+ {
1378
+ method: "GET",
1379
+ path: "/cells/:cellId/motion-groups/:motionGroupId/tcps",
1380
+ handle() {
1381
+ return { tcps: [{
1382
+ id: "Flange",
1383
+ readable_name: "Default-Flange",
1384
+ position: [
1385
+ 0,
1386
+ 0,
1387
+ 0
1388
+ ],
1389
+ rotation: {
1390
+ angles: [
1391
+ 0,
1392
+ 0,
1393
+ 0,
1394
+ 0
1395
+ ],
1396
+ type: "ROTATION_VECTOR"
1397
+ }
1398
+ }, {
1399
+ id: "complex-tcp-position",
1400
+ readable_name: "Complex TCP Position",
1401
+ position: [
1402
+ -200,
1403
+ 300,
1404
+ 150
1405
+ ],
1406
+ rotation: {
1407
+ angles: [
1408
+ -.12139440409113832,
1409
+ -.06356210998212003,
1410
+ -.2023240068185639,
1411
+ 0
1412
+ ],
1413
+ type: "ROTATION_VECTOR"
1414
+ }
1415
+ }] };
1416
+ }
1417
+ }
1418
+ ];
1419
+ const method = config.method?.toUpperCase() || "GET";
1420
+ const path = `/cells${config.url?.split("/cells")[1]?.split("?")[0]}`;
1421
+ for (const handler of apiHandlers) {
1422
+ const match = path_to_regexp.match(handler.path)(path || "");
1423
+ if (method === handler.method && match) {
1424
+ const json = handler.handle();
1425
+ return {
1426
+ status: 200,
1427
+ statusText: "Success",
1428
+ data: JSON.stringify(json),
1429
+ headers: {},
1430
+ config,
1431
+ request: { responseURL: config.url }
1432
+ };
1433
+ }
1434
+ }
1435
+ throw new axios.AxiosError(`No mock handler matched this request: ${method} ${path}`, "404", config);
1436
+ }
1437
+ handleWebsocketConnection(socket) {
1438
+ this.connections.push(socket);
1439
+ setTimeout(() => {
1440
+ socket.dispatchEvent(new Event("open"));
1441
+ console.log("Websocket connection opened from", socket.url);
1442
+ if (socket.url.includes("/state-stream")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify(defaultMotionState) }));
1443
+ if (socket.url.includes("/move-joint")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1444
+ motion_group: "0@ur",
1445
+ state: {
1446
+ controller: "ur",
1447
+ operation_mode: "OPERATION_MODE_AUTO",
1448
+ safety_state: "SAFETY_STATE_NORMAL",
1449
+ timestamp: "2024-09-18T12:48:26.096266444Z",
1450
+ velocity_override: 100,
1451
+ motion_groups: [{
1452
+ motion_group: "0@ur",
1453
+ controller: "ur",
1454
+ joint_position: [
1455
+ 1.3492152690887451,
1456
+ -1.5659207105636597,
1457
+ 1.6653711795806885,
1458
+ -1.0991662740707397,
1459
+ -1.829018235206604,
1460
+ 1.264623761177063
1461
+ ],
1462
+ joint_velocity: { joints: [
1463
+ 0,
1464
+ 0,
1465
+ 0,
1466
+ 0,
1467
+ 0,
1468
+ 0
1469
+ ] },
1470
+ flange_pose: {
1471
+ position: [
1472
+ 6.437331889439328,
1473
+ -628.4123774830913,
1474
+ 577.0569957147832
1475
+ ],
1476
+ orientation: {
1477
+ x: -1.683333649797158,
1478
+ y: -1.9783363827298732,
1479
+ z: -.4928031860165713
1480
+ },
1481
+ coordinate_system: ""
1482
+ },
1483
+ tcp_pose: {
1484
+ position: [
1485
+ 6.437331889439328,
1486
+ -628.4123774830913,
1487
+ 577.0569957147832
1488
+ ],
1489
+ orientation: {
1490
+ x: -1.683333649797158,
1491
+ y: -1.9783363827298732,
1492
+ z: -.4928031860165713
1493
+ },
1494
+ coordinate_system: "",
1495
+ tcp: "Flange"
1496
+ },
1497
+ velocity: {
1498
+ linear: {
1499
+ x: 0,
1500
+ y: 0,
1501
+ z: 0
1502
+ },
1503
+ angular: {
1504
+ x: -0,
1505
+ y: 0,
1506
+ z: 0
1507
+ },
1508
+ coordinate_system: ""
1509
+ },
1510
+ force: {
1511
+ force: {
1512
+ x: 0,
1513
+ y: 0,
1514
+ z: 0
1515
+ },
1516
+ moment: {
1517
+ x: 0,
1518
+ y: 0,
1519
+ z: 0
1520
+ },
1521
+ coordinate_system: ""
1522
+ },
1523
+ joint_limit_reached: { limit_reached: [
1524
+ false,
1525
+ false,
1526
+ false,
1527
+ false,
1528
+ false,
1529
+ false
1530
+ ] },
1531
+ joint_current: { joints: [
1532
+ 0,
1533
+ 0,
1534
+ 0,
1535
+ 0,
1536
+ 0,
1537
+ 0
1538
+ ] },
1539
+ sequence_number: "671259"
1540
+ }],
1541
+ sequence_number: "671259"
1542
+ },
1543
+ movement_state: "MOVEMENT_STATE_MOVING"
1544
+ } }) }));
1545
+ if (socket.url.includes("/move-tcp")) socket.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ result: {
1546
+ motion_group: "0@ur",
1547
+ state: {
1548
+ controller: "ur",
1549
+ operation_mode: "OPERATION_MODE_AUTO",
1550
+ safety_state: "SAFETY_STATE_NORMAL",
1551
+ timestamp: "2024-09-18T12:43:12.188335774Z",
1552
+ velocity_override: 100,
1553
+ motion_groups: [{
1554
+ motion_group: "0@ur",
1555
+ controller: "ur",
1556
+ joint_position: { joints: [
1557
+ 1.3352527618408203,
1558
+ -1.5659207105636597,
1559
+ 1.6653711795806885,
1560
+ -1.110615611076355,
1561
+ -1.829018235206604,
1562
+ 1.264623761177063
1563
+ ] },
1564
+ joint_velocity: { joints: [
1565
+ 0,
1566
+ 0,
1567
+ 0,
1568
+ 0,
1569
+ 0,
1570
+ 0
1571
+ ] },
1572
+ flange_pose: {
1573
+ position: [
1574
+ -2.763015284002938,
1575
+ -630.2151479701106,
1576
+ 577.524509114342
1577
+ ],
1578
+ orientation: {
1579
+ x: -1.704794877102097,
1580
+ y: -1.9722372952861567,
1581
+ z: -.4852079204210754
1582
+ },
1583
+ coordinate_system: ""
1584
+ },
1585
+ tcp_pose: {
1586
+ position: [
1587
+ -2.763015284002938,
1588
+ -630.2151479701106,
1589
+ 577.524509114342
1590
+ ],
1591
+ orientation: {
1592
+ x: -1.704794877102097,
1593
+ y: -1.9722372952861567,
1594
+ z: -.4852079204210754
1595
+ },
1596
+ coordinate_system: "",
1597
+ tcp: "Flange"
1598
+ },
1599
+ velocity: {
1600
+ linear: {
1601
+ x: 0,
1602
+ y: 0,
1603
+ z: 0
1604
+ },
1605
+ angular: {
1606
+ x: -0,
1607
+ y: 0,
1608
+ z: 0
1609
+ },
1610
+ coordinate_system: ""
1611
+ },
1612
+ force: {
1613
+ force: {
1614
+ x: 0,
1615
+ y: 0,
1616
+ z: 0
1617
+ },
1618
+ moment: {
1619
+ x: 0,
1620
+ y: 0,
1621
+ z: 0
1622
+ },
1623
+ coordinate_system: ""
1624
+ },
1625
+ joint_limit_reached: { limit_reached: [
1626
+ false,
1627
+ false,
1628
+ false,
1629
+ false,
1630
+ false,
1631
+ false
1632
+ ] },
1633
+ joint_current: { joints: [
1634
+ 0,
1635
+ 0,
1636
+ 0,
1637
+ 0,
1638
+ 0,
1639
+ 0
1640
+ ] },
1641
+ sequence_number: "627897"
1642
+ }],
1643
+ sequence_number: "627897"
1644
+ },
1645
+ movement_state: "MOVEMENT_STATE_MOVING"
1646
+ } }) }));
1647
+ }, 10);
1648
+ }
1649
+ handleWebsocketMessage(socket, message) {
1650
+ console.log(`Received message on ${socket.url}`, message);
1651
+ }
1347
1652
  };
1653
+ const defaultMotionState = { result: {
1654
+ motion_group: "0@universalrobots-ur5e",
1655
+ controller: "universalrobots-ur5e",
1656
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1657
+ sequence_number: 1,
1658
+ joint_position: [
1659
+ 1.1699999570846558,
1660
+ -1.5700000524520874,
1661
+ 1.3600000143051147,
1662
+ 1.0299999713897705,
1663
+ 1.2899999618530273,
1664
+ 1.2799999713897705
1665
+ ],
1666
+ joint_limit_reached: { limit_reached: [
1667
+ false,
1668
+ false,
1669
+ false,
1670
+ false,
1671
+ false,
1672
+ false
1673
+ ] },
1674
+ standstill: false,
1675
+ flange_pose: {
1676
+ position: [
1677
+ 1.3300010259703043,
1678
+ -409.2680714682808,
1679
+ 531.0203477065281
1680
+ ],
1681
+ orientation: [
1682
+ 1.7564919306270736,
1683
+ -1.7542521568325058,
1684
+ .7326972590614671
1685
+ ]
1686
+ },
1687
+ tcp_pose: {
1688
+ position: [
1689
+ 1.3300010259703043,
1690
+ -409.2680714682808,
1691
+ 531.0203477065281
1692
+ ],
1693
+ orientation: [
1694
+ 1.7564919306270736,
1695
+ -1.7542521568325058,
1696
+ .7326972590614671
1697
+ ]
1698
+ }
1699
+ } };
1348
1700
 
1349
- // src/lib/v2/NovaClient.ts
1701
+ //#endregion
1702
+ //#region src/lib/v2/NovaClient.ts
1703
+ function permissiveInstanceUrlParse(url) {
1704
+ if (!url.startsWith("http")) url = `http://${url}`;
1705
+ return new URL(url).toString();
1706
+ }
1707
+ /**
1708
+ *
1709
+ * Client for connecting to a Nova instance and controlling robots.
1710
+ */
1350
1711
  var NovaClient = class {
1351
- constructor(config) {
1352
- this.authPromise = null;
1353
- this.accessToken = null;
1354
- var _a;
1355
- console.warn("Using experimental NOVA v2 client");
1356
- const cellId = (_a = config.cellId) != null ? _a : "cell";
1357
- this.config = __spreadValues({
1358
- cellId
1359
- }, config);
1360
- this.accessToken = config.accessToken || availableStorage.getString("wbjs.access_token") || null;
1361
- if (this.config.instanceUrl === "https://mock.example.com") {
1362
- this.mock = new MockNovaInstance();
1363
- }
1364
- const axiosInstance = import_axios3.default.create({
1365
- baseURL: (0, import_url_join.default)(this.config.instanceUrl, "/api/v2"),
1366
- // TODO - backend needs to set proper CORS headers for this
1367
- headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : {
1368
- // Identify the client to the backend for logging purposes
1369
- "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK"
1370
- }
1371
- });
1372
- axiosInstance.interceptors.request.use((request) => __async(this, null, function* () {
1373
- if (!request.headers.Authorization) {
1374
- if (this.accessToken) {
1375
- request.headers.Authorization = `Bearer ${this.accessToken}`;
1376
- } else if (this.config.username && this.config.password) {
1377
- request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
1378
- }
1379
- }
1380
- return request;
1381
- }));
1382
- if (typeof window !== "undefined") {
1383
- axiosInstance.interceptors.response.use(
1384
- (r) => r,
1385
- (error) => __async(this, null, function* () {
1386
- var _a2, _b;
1387
- if ((0, import_axios3.isAxiosError)(error)) {
1388
- if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
1389
- try {
1390
- yield this.renewAuthentication();
1391
- if (error.config) {
1392
- if (this.accessToken) {
1393
- error.config.headers.Authorization = `Bearer ${this.accessToken}`;
1394
- } else {
1395
- delete error.config.headers.Authorization;
1396
- }
1397
- return axiosInstance.request(error.config);
1398
- }
1399
- } catch (err) {
1400
- return Promise.reject(err);
1401
- }
1402
- } else if (((_b = error.response) == null ? void 0 : _b.status) === 503) {
1403
- const res = yield fetch(window.location.href);
1404
- if (res.status === 503) {
1405
- window.location.reload();
1406
- }
1407
- }
1408
- }
1409
- return Promise.reject(error);
1410
- })
1411
- );
1412
- }
1413
- this.api = new NovaCellAPIClient(cellId, __spreadProps(__spreadValues({}, config), {
1414
- basePath: (0, import_url_join.default)(this.config.instanceUrl, "/api/v1"),
1415
- isJsonMime: (mime) => {
1416
- return mime === "application/json";
1417
- },
1418
- baseOptions: __spreadValues(__spreadValues({}, this.mock ? {
1419
- adapter: (config2) => {
1420
- return this.mock.handleAPIRequest(config2);
1421
- }
1422
- } : {}), config.baseOptions),
1423
- axiosInstance
1424
- }));
1425
- }
1426
- renewAuthentication() {
1427
- return __async(this, null, function* () {
1428
- if (this.authPromise) {
1429
- return;
1430
- }
1431
- this.authPromise = loginWithAuth0(this.config.instanceUrl);
1432
- try {
1433
- this.accessToken = yield this.authPromise;
1434
- if (this.accessToken) {
1435
- availableStorage.setString("wbjs.access_token", this.accessToken);
1436
- } else {
1437
- availableStorage.delete("wbjs.access_token");
1438
- }
1439
- } finally {
1440
- this.authPromise = null;
1441
- }
1442
- });
1443
- }
1444
- makeWebsocketURL(path) {
1445
- const url = new URL(
1446
- (0, import_url_join.default)(
1447
- this.config.instanceUrl,
1448
- `/api/v1/cells/${this.config.cellId}`,
1449
- path
1450
- )
1451
- );
1452
- url.protocol = url.protocol.replace("http", "ws");
1453
- url.protocol = url.protocol.replace("https", "wss");
1454
- if (this.accessToken) {
1455
- url.searchParams.append("token", this.accessToken);
1456
- } else if (this.config.username && this.config.password) {
1457
- url.username = this.config.username;
1458
- url.password = this.config.password;
1459
- }
1460
- return url.toString();
1461
- }
1462
- /**
1463
- * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
1464
- * If you explicitly want to reconnect an existing websocket, call `reconnect`
1465
- * on the returned object.
1466
- */
1467
- openReconnectingWebsocket(path) {
1468
- return new AutoReconnectingWebsocket(this.makeWebsocketURL(path), {
1469
- mock: this.mock
1470
- });
1471
- }
1712
+ constructor(config) {
1713
+ this.authPromise = null;
1714
+ this.accessToken = null;
1715
+ const cellId = config.cellId ?? "cell";
1716
+ this.config = {
1717
+ cellId,
1718
+ ...config
1719
+ };
1720
+ this.accessToken = config.accessToken || require_LoginWithAuth0.availableStorage.getString("wbjs.access_token") || null;
1721
+ if (this.config.instanceUrl === "https://mock.example.com") this.mock = new MockNovaInstance();
1722
+ else this.config.instanceUrl = permissiveInstanceUrlParse(this.config.instanceUrl);
1723
+ const axiosInstance = axios.default.create({
1724
+ baseURL: (0, url_join.default)(this.config.instanceUrl, "/api/v2"),
1725
+ headers: typeof window !== "undefined" && window.location.origin.includes("localhost") ? {} : { "X-Wandelbots-Client": "Wandelbots-Nova-JS-SDK" }
1726
+ });
1727
+ axiosInstance.interceptors.request.use(async (request) => {
1728
+ if (!request.headers.Authorization) {
1729
+ if (this.accessToken) request.headers.Authorization = `Bearer ${this.accessToken}`;
1730
+ else if (this.config.username && this.config.password) request.headers.Authorization = `Basic ${btoa(`${config.username}:${config.password}`)}`;
1731
+ }
1732
+ return request;
1733
+ });
1734
+ if (typeof window !== "undefined") axiosInstance.interceptors.response.use((r) => r, async (error) => {
1735
+ if ((0, axios.isAxiosError)(error)) {
1736
+ if (error.response?.status === 401) try {
1737
+ await this.renewAuthentication();
1738
+ if (error.config) {
1739
+ if (this.accessToken) error.config.headers.Authorization = `Bearer ${this.accessToken}`;
1740
+ else delete error.config.headers.Authorization;
1741
+ return axiosInstance.request(error.config);
1742
+ }
1743
+ } catch (err) {
1744
+ return Promise.reject(err);
1745
+ }
1746
+ else if (error.response?.status === 503) {
1747
+ if ((await fetch(window.location.href)).status === 503) window.location.reload();
1748
+ }
1749
+ }
1750
+ return Promise.reject(error);
1751
+ });
1752
+ this.api = new NovaCellAPIClient(cellId, {
1753
+ ...config,
1754
+ basePath: (0, url_join.default)(this.config.instanceUrl, "/api/v2"),
1755
+ isJsonMime: (mime) => {
1756
+ return mime === "application/json";
1757
+ },
1758
+ baseOptions: {
1759
+ ...this.mock ? { adapter: (config$1) => {
1760
+ return this.mock.handleAPIRequest(config$1);
1761
+ } } : {},
1762
+ ...config.baseOptions
1763
+ },
1764
+ axiosInstance
1765
+ });
1766
+ }
1767
+ async renewAuthentication() {
1768
+ if (this.authPromise) return;
1769
+ this.authPromise = require_LoginWithAuth0.loginWithAuth0(this.config.instanceUrl);
1770
+ try {
1771
+ this.accessToken = await this.authPromise;
1772
+ if (this.accessToken) require_LoginWithAuth0.availableStorage.setString("wbjs.access_token", this.accessToken);
1773
+ else require_LoginWithAuth0.availableStorage.delete("wbjs.access_token");
1774
+ } finally {
1775
+ this.authPromise = null;
1776
+ }
1777
+ }
1778
+ makeWebsocketURL(path) {
1779
+ const url = new URL((0, url_join.default)(this.config.instanceUrl, `/api/v2/cells/${this.config.cellId}`, path));
1780
+ url.protocol = url.protocol.replace("http", "ws");
1781
+ url.protocol = url.protocol.replace("https", "wss");
1782
+ if (this.accessToken) url.searchParams.append("token", this.accessToken);
1783
+ else if (this.config.username && this.config.password) {
1784
+ url.username = this.config.username;
1785
+ url.password = this.config.password;
1786
+ }
1787
+ return url.toString();
1788
+ }
1789
+ /**
1790
+ * Retrieve an AutoReconnectingWebsocket to the given path on the Nova instance.
1791
+ * If you explicitly want to reconnect an existing websocket, call `reconnect`
1792
+ * on the returned object.
1793
+ */
1794
+ openReconnectingWebsocket(path) {
1795
+ return new require_LoginWithAuth0.AutoReconnectingWebsocket(this.makeWebsocketURL(path), { mock: this.mock });
1796
+ }
1472
1797
  };
1473
- // Annotate the CommonJS export names for ESM import in node:
1474
- 0 && (module.exports = {
1475
- NovaCellAPIClient,
1476
- NovaClient,
1477
- ...require("@wandelbots/nova-api/v2")
1798
+
1799
+ //#endregion
1800
+ //#region src/lib/v2/wandelscriptUtils.ts
1801
+ /**
1802
+ * Convert a Pose object representing a motion group position
1803
+ * into a string which represents that pose in Wandelscript.
1804
+ */
1805
+ function poseToWandelscriptString(pose) {
1806
+ const position = [
1807
+ pose.position?.[0] ?? 0,
1808
+ pose.position?.[1] ?? 0,
1809
+ pose.position?.[2] ?? 0
1810
+ ];
1811
+ const orientation = [
1812
+ pose.orientation?.[0] ?? 0,
1813
+ pose.orientation?.[1] ?? 0,
1814
+ pose.orientation?.[2] ?? 0
1815
+ ];
1816
+ const positionValues = position.map((v) => v.toFixed(1));
1817
+ const rotationValues = orientation.map((v) => v.toFixed(4));
1818
+ return `(${positionValues.concat(rotationValues).join(", ")})`;
1819
+ }
1820
+
1821
+ //#endregion
1822
+ exports.NovaCellAPIClient = NovaCellAPIClient;
1823
+ exports.NovaClient = NovaClient;
1824
+ exports.poseToWandelscriptString = poseToWandelscriptString;
1825
+ Object.keys(__wandelbots_nova_api_v2).forEach(function (k) {
1826
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1827
+ enumerable: true,
1828
+ get: function () { return __wandelbots_nova_api_v2[k]; }
1829
+ });
1478
1830
  });
1831
+
1479
1832
  //# sourceMappingURL=index.cjs.map