@rainbow-robotics/preview-host 0.1.2-dev.8 → 0.10.1-dev.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 (109) hide show
  1. package/README.md +236 -26
  2. package/build.mjs +3 -2
  3. package/dist/assets/AmrCapabilityControl.BsPcogIn.js +1 -0
  4. package/dist/assets/RbLocalizationProvider.OVSr2Odo.js +311 -0
  5. package/dist/assets/__federation_expose_App.DoTw5M1G.js +1356 -0
  6. package/dist/assets/__federation_fn_import.DdkEuT6t.js +23 -0
  7. package/dist/assets/__federation_shared_@emotion/{styled.wOy85H_m.js → styled.ETfwMsQo.js} +1 -1
  8. package/dist/assets/__federation_shared_@tanstack/{react-query.BqXJhb-5.js → react-query.fVz8BOIk.js} +1 -1
  9. package/dist/assets/__federation_shared_react-dom.CHMAxKsQ.js +1 -0
  10. package/dist/assets/{__federation_shared_react-simple-keyboard.BDWRGEbM.js → __federation_shared_react-simple-keyboard.CycbmZUL.js} +3 -3
  11. package/dist/assets/__federation_shared_react.DhiB56zQ.js +1 -0
  12. package/dist/assets/{cssMode.CxPsxiNP.js → cssMode.r5_yWnhF.js} +1 -1
  13. package/dist/assets/{emotion-styled-base.browser.esm.JngGwqgu.js → emotion-styled-base.browser.esm.BIcjgOzg.js} +1 -1
  14. package/dist/assets/{freemarker2.e18W-vVC.js → freemarker2.DCx4k8go.js} +1 -1
  15. package/dist/assets/{handlebars.DpGUQTlC.js → handlebars.BludBZv4.js} +1 -1
  16. package/dist/assets/{html.qS8AwR-R.js → html.C-reJSx7.js} +1 -1
  17. package/dist/assets/{htmlMode.D4pEgAMn.js → htmlMode.HtihP2HZ.js} +1 -1
  18. package/dist/assets/{index.CHuCXVak.js → index.B3zY1kf7.js} +1 -1
  19. package/dist/assets/index.C7SAsNe2.js +26 -0
  20. package/dist/assets/index.DdneTN7b.js +1 -0
  21. package/dist/assets/index.P6snMalu.js +9 -0
  22. package/dist/assets/index.UK8d_UfV.js +1 -0
  23. package/dist/assets/{javascript.CIRAbwTJ.js → javascript.BtXUGP6j.js} +1 -1
  24. package/dist/assets/{jsonMode.CJcA6JGm.js → jsonMode.mx3rzMj6.js} +1 -1
  25. package/dist/assets/jsx-runtime.CBqCNPYB.js +9 -0
  26. package/dist/assets/{liquid.Cd_ynsyQ.js → liquid.BKDdGihc.js} +1 -1
  27. package/dist/assets/{lspLanguageFeatures.ZrhgItxw.js → lspLanguageFeatures.CiDbxSjV.js} +1 -1
  28. package/dist/assets/{mdx.E9Mhxtu7.js → mdx.C8GBeJOc.js} +1 -1
  29. package/dist/assets/parseLasPointCloud.worker-BZeU-mt8.js +1 -0
  30. package/dist/assets/{python.BUTzvd2f.js → python.LxZo3-5L.js} +1 -1
  31. package/dist/assets/{razor.CI_gj0Fd.js → razor.D95WY7jF.js} +1 -1
  32. package/dist/assets/remoteEntry.js +1 -1
  33. package/dist/assets/{tsMode.DBpdjX7n.js → tsMode.BbJpvH--.js} +1 -1
  34. package/dist/assets/{typescript.WM3o_g0z.js → typescript.DdC-A9nd.js} +1 -1
  35. package/dist/assets/useFileDownload.DoxMuZkp.js +4753 -0
  36. package/dist/assets/{xml.D7f39jWM.js → xml.DmJRBsLI.js} +1 -1
  37. package/dist/assets/{yaml.BLLpRCf_.js → yaml.Du5J4UhC.js} +1 -1
  38. package/dist/data/service-info.json +129 -46
  39. package/dist/imgs/muscat_404.jpg +0 -0
  40. package/dist/imgs/nexus/forms/gripper/g11_help.png +0 -0
  41. package/dist/imgs/nexus/forms/gripper/g7_grip_dir_0.png +0 -0
  42. package/dist/imgs/nexus/forms/gripper/g7_grip_dir_1.png +0 -0
  43. package/dist/imgs/nexus/forms/gripper/g7_offset.png +0 -0
  44. package/dist/imgs/nexus/forms/gripper/g7_orientation_0.png +0 -0
  45. package/dist/imgs/nexus/forms/gripper/g7_orientation_1.png +0 -0
  46. package/dist/imgs/nexus/forms/gripper/g7_tip_width.png +0 -0
  47. package/dist/imgs/nexus/forms/gripper/gripper_10.png +0 -0
  48. package/dist/imgs/nexus/forms/gripper/gripper_11.png +0 -0
  49. package/dist/imgs/nexus/forms/gripper/gripper_12.png +0 -0
  50. package/dist/imgs/nexus/forms/gripper/gripper_13.png +0 -0
  51. package/dist/imgs/nexus/forms/gripper/gripper_14.png +0 -0
  52. package/dist/imgs/nexus/forms/gripper/gripper_15.png +0 -0
  53. package/dist/imgs/nexus/forms/gripper/gripper_16.png +0 -0
  54. package/dist/imgs/nexus/forms/gripper/gripper_17.png +0 -0
  55. package/dist/imgs/nexus/forms/gripper/gripper_18.png +0 -0
  56. package/dist/imgs/nexus/forms/gripper/gripper_19_0.png +0 -0
  57. package/dist/imgs/nexus/forms/gripper/gripper_19_1.png +0 -0
  58. package/dist/imgs/nexus/forms/gripper/gripper_20.png +0 -0
  59. package/dist/imgs/nexus/forms/gripper/gripper_21.png +0 -0
  60. package/dist/imgs/nexus/forms/gripper/gripper_22.png +0 -0
  61. package/dist/imgs/nexus/forms/gripper/gripper_23.png +0 -0
  62. package/dist/imgs/nexus/forms/gripper/gripper_7.png +0 -0
  63. package/dist/imgs/nexus/forms/gripper/gripper_8.png +0 -0
  64. package/dist/imgs/nexus/forms/gripper/gripper_9.png +0 -0
  65. package/dist/imgs/nexus/forms/weaving/weaving_desc.jpg +0 -0
  66. package/dist/imgs/nexus/no-image.png +0 -0
  67. package/dist/index.html +12 -10
  68. package/dist/plugin-shared/plugin-ui_host-ui.js +3 -0
  69. package/dist/plugin-shared/plugin-ui_react.js +3 -0
  70. package/dist/plugin-shared/plugin-ui_sdk.js +3 -0
  71. package/dist/plugin-shared/plugin-ui_ws.js +3 -0
  72. package/dist/plugin-shared/react-dom.js +4 -0
  73. package/dist/plugin-shared/react-dom_client.js +3 -0
  74. package/dist/plugin-shared/react.js +4 -0
  75. package/dist/plugin-shared/react_jsx-dev-runtime.js +3 -0
  76. package/dist/plugin-shared/react_jsx-runtime.js +3 -0
  77. package/package.json +5 -5
  78. package/serve.mjs +159 -42
  79. package/dist/assets/AmrCapabilityControl.BppT8lfW.js +0 -1
  80. package/dist/assets/ConveyorBelt.DYgETvU-.png +0 -0
  81. package/dist/assets/FactoryMap.CBpf9N92.js +0 -4881
  82. package/dist/assets/MapInfo.Bit_2DfJ.js +0 -1
  83. package/dist/assets/__federation_expose_App.DTILpvFM.js +0 -1126
  84. package/dist/assets/__federation_fn_import.Drmbxo5T.js +0 -23
  85. package/dist/assets/__federation_shared_react-dom.znG_qyPl.js +0 -1
  86. package/dist/assets/__federation_shared_react.Wsh8dz5j.js +0 -1
  87. package/dist/assets/_commonjsHelpers.Cpj98o6Y.js +0 -1
  88. package/dist/assets/index.ChsGqxH_.js +0 -9
  89. package/dist/assets/index.Dxudgz78.js +0 -1
  90. package/dist/assets/index.FxRLAiU5.js +0 -1
  91. package/dist/assets/index.ayADrA9_.js +0 -1
  92. package/dist/assets/jsx-runtime.CKZTQYsb.js +0 -9
  93. package/dist/assets/keymapTileIndex.worker-C2HCGd-D.js +0 -1
  94. package/dist/plugin-demo/assets/icon.svg +0 -3
  95. package/dist/plugin-demo/content.js +0 -9149
  96. package/dist/plugin-demo/manifest.json +0 -25
  97. package/dist/plugin-demo/sandbox.html +0 -10
  98. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/chunks/chunk-37HVFFJB.js +0 -1
  99. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/chunks/chunk-4MGSRUAS.js +0 -1
  100. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/chunks/chunk-Q6XGCIPE.js +0 -1
  101. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/connect.js +0 -1
  102. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/elements.js +0 -1
  103. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/react.js +0 -1
  104. package/dist/plugin-runtime/@rainbow-robotics/plugin-ui/sdk.js +0 -1
  105. package/dist/plugin-runtime/vendor/react-dom-client.js +0 -1
  106. package/dist/plugin-runtime/vendor/react-jsx-dev-runtime.js +0 -1
  107. package/dist/plugin-runtime/vendor/react-jsx-runtime.js +0 -1
  108. package/dist/plugin-runtime/vendor/react-runtime.js +0 -65
  109. package/dist/plugin-runtime/vendor/react.js +0 -1
package/serve.mjs CHANGED
@@ -1,16 +1,10 @@
1
1
  #!/usr/bin/env node
2
- // Serves the standalone preview-host bundle: the mini-Muscat shell (dist/) plus
3
- // the developer's built plugin mounted at /plugin-dev/. No robot/back end.
4
- //
5
2
  // Usage:
6
- // rb-preview-host --plugin <built-plugin-dir> [--port 4180] [--dist <dir>]
7
- //
8
- // The plugin dir must contain manifest.json, sandbox.html, content.js and any
9
- // assets/ — i.e. the output of `muscat-pk build`.
3
+ // rb-preview-host --plugin <staged-dir> [--port 4180] [--dist <dir>]
10
4
  import { createServer } from "node:http";
11
- import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
12
- import { createRequire } from "node:module";
13
- import { dirname, extname, join, resolve } from "node:path";
5
+ import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, statSync, watch, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { dirname, extname, join, resolve, sep } from "node:path";
14
8
  import { fileURLToPath } from "node:url";
15
9
 
16
10
  const here = dirname(fileURLToPath(import.meta.url));
@@ -20,26 +14,16 @@ function arg(name, fallback) {
20
14
  return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
21
15
  }
22
16
 
23
- function resolvePluginUiDistBrowser() {
24
- try {
25
- const req = createRequire(import.meta.url);
26
- const pkgPath = req.resolve("@rainbow-robotics/plugin-ui/package.json");
27
- return resolve(dirname(pkgPath), "dist-browser");
28
- } catch {
29
- // fallback for unusual install layouts
30
- return resolve(here, "../plugin-ui/dist-browser");
31
- }
32
- }
33
-
34
17
  const port = Number(arg("port", "4180"));
35
18
  const distDir = resolve(arg("dist", join(here, "dist")));
36
- const runtimeDir = resolve(arg("runtime", resolvePluginUiDistBrowser()));
37
19
  const pluginDir = arg("plugin", "")
38
20
  ? resolve(arg("plugin", ""))
39
21
  : "";
40
22
  const socketUrl = arg("socket-url", "");
23
+ const robotHost = arg("robot-host", "");
24
+ const devServerUrl = arg("dev-server-url", "");
41
25
  const PLUGIN_BASE = "/plugin-dev";
42
- const RUNTIME_BASE = "/plugin-runtime";
26
+ const RELOAD_PATH = "/__preview_reload";
43
27
 
44
28
  const CONTENT_TYPE = {
45
29
  ".html": "text/html; charset=utf-8",
@@ -67,43 +51,177 @@ if (!existsSync(distDir)) {
67
51
  process.exit(1);
68
52
  }
69
53
 
70
- // index.html with the preview-host globals injected (host flag + plugin base).
54
+
55
+ let previewPluginId = "";
56
+ // Core SW category the preview program pretends to run on (command forms are keyed by it).
57
+ let previewBeService = "manipulate";
58
+ if (pluginDir) {
59
+ try {
60
+ const manifest = JSON.parse(readFileSync(resolve(pluginDir, "manifest.json"), "utf8"));
61
+ previewPluginId = manifest.id || "";
62
+ if (Array.isArray(manifest.targetCategorys) && manifest.targetCategorys[0]) {
63
+ previewBeService = manifest.targetCategorys[0];
64
+ }
65
+ } catch {
66
+ /* manifest missing/unreadable — no preview id */
67
+ }
68
+ }
69
+
71
70
  const injectedLines = [
72
71
  " <script>",
73
72
  " window.__RB_PLUGIN_PREVIEW_HOST__ = true;",
74
73
  " window.__RB_ASSETS_BASE_URL__ = window.location.origin;",
75
74
  ` window.__RB_PLUGIN_PREVIEW_BASE__ = ${JSON.stringify(PLUGIN_BASE)};`,
76
75
  ];
76
+ if (previewPluginId) {
77
+ injectedLines.push(` window.__RB_PREVIEW_PLUGIN_ID__ = ${JSON.stringify(previewPluginId)};`);
78
+ }
79
+ injectedLines.push(` window.__RB_PREVIEW_BE_SERVICE__ = ${JSON.stringify(previewBeService)};`);
80
+ if (devServerUrl) {
81
+ injectedLines.push(` window.__RB_PLUGIN_DEV_SERVER_URL__ = ${JSON.stringify(devServerUrl)};`);
82
+ }
77
83
  if (socketUrl) {
78
84
  injectedLines.push(` window.__RB_PLUGIN_PREVIEW_SOCKET_URL__ = ${JSON.stringify(socketUrl)};`);
79
85
  }
80
- injectedLines.push(" </script>", " </head>");
81
- const indexHtml = readFileSync(join(distDir, "index.html"), "utf8").replace(
82
- "</head>",
83
- injectedLines.join("\n"),
84
- );
86
+ if (robotHost) {
87
+
88
+ injectedLines.push(` window.__RB_ROBOT_HOST__ = ${JSON.stringify(robotHost)};`);
89
+ }
90
+ injectedLines.push(" </script>");
91
+
92
+ if (pluginDir) {
93
+ injectedLines.push(
94
+ " <script>",
95
+ ` new EventSource(${JSON.stringify(RELOAD_PATH)}).onmessage = () => location.reload();`,
96
+ " </script>",
97
+ );
98
+ }
99
+ injectedLines.push(" </head>");
100
+
101
+ function renderIndexHtml() {
102
+ return readFileSync(join(distDir, "index.html"), "utf8").replace(
103
+ "</head>",
104
+ injectedLines.join("\n"),
105
+ );
106
+ }
85
107
 
86
- function sendFile(res, filePath) {
108
+ function sendFile(res, filePath, { noStore = false } = {}) {
87
109
  res.setHeader("Access-Control-Allow-Origin", "*");
110
+ if (noStore) res.setHeader("Cache-Control", "no-store");
88
111
  const type = CONTENT_TYPE[extname(filePath)];
89
112
  if (type) res.setHeader("Content-Type", type);
90
113
  createReadStream(filePath).pipe(res);
91
114
  }
92
115
 
93
- function tryServe(res, baseDir, relPath) {
116
+ function tryServe(res, baseDir, relPath, opts) {
94
117
  const filePath = resolve(baseDir, `.${relPath}`);
95
118
  if (!filePath.startsWith(baseDir)) return false;
96
119
  if (existsSync(filePath) && statSync(filePath).isFile()) {
97
- sendFile(res, filePath);
120
+ sendFile(res, filePath, opts);
98
121
  return true;
99
122
  }
100
123
  return false;
101
124
  }
102
125
 
126
+
127
+ // models/ (URDF + meshes, ~800MB) isn't bundled — too large for npm. Each file is fetched from the
128
+ // kit's S3 copy on first use and kept in ~/.muscat-pk/models, so the 3D robot view works with any
129
+ // robot or a local core SW, and offline once a model has been seen.
130
+ // ponytail: cached by path only; a changed model needs ~/.muscat-pk/models cleared.
131
+ // Tried in order: the kit's S3 copy, then the assets server (:5177) of the robot / local Muscat,
132
+ // which has the models that Muscat ships — so a model missing from S3 (or no internet) still shows.
133
+ const MODEL_SOURCES = [
134
+ ...new Set([
135
+ process.env.MUSCAT_PK_MODELS_URL || "https://rainbow-deploy.s3.ap-northeast-2.amazonaws.com/muscat-plugin-kit/models",
136
+ ...(robotHost ? [`http://${robotHost}:5177/models`] : []),
137
+ "http://localhost:5177/models",
138
+ ]),
139
+ ];
140
+ const MODELS_CACHE = resolve(homedir(), ".muscat-pk", "models");
141
+
142
+ const unreachable = new Set(); // a source that didn't answer is skipped from then on
143
+
144
+ async function fetchModel(rel) {
145
+ const path = rel.split("/").map(encodeURIComponent).join("/");
146
+ for (const base of MODEL_SOURCES) {
147
+ if (unreachable.has(base)) continue;
148
+ try {
149
+ const r = await fetch(`${base}/${path}`, { signal: AbortSignal.timeout(15_000) });
150
+ // S3 answers 403 for a missing key; a web server may answer 200 with an HTML fallback page.
151
+ if (r.ok && !(r.headers.get("content-type") ?? "").startsWith("text/html")) return Buffer.from(await r.arrayBuffer());
152
+ } catch {
153
+ unreachable.add(base);
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+
159
+ async function serveModel(res, url) {
160
+ const rel = decodeURIComponent(url.slice("/models/".length));
161
+ const file = resolve(MODELS_CACHE, rel);
162
+ if (!file.startsWith(MODELS_CACHE + sep)) {
163
+ res.statusCode = 400;
164
+ res.end();
165
+ return;
166
+ }
167
+ if (!existsSync(file)) {
168
+ const data = await fetchModel(rel);
169
+ if (!data) {
170
+ res.statusCode = 404;
171
+ res.end(`model file not found: ${rel}`);
172
+ return;
173
+ }
174
+ mkdirSync(dirname(file), { recursive: true });
175
+ const part = `${file}.${process.pid}.part`;
176
+ writeFileSync(part, data);
177
+ renameSync(part, file);
178
+ }
179
+ sendFile(res, file);
180
+ }
181
+
182
+ const reloadClients = new Set();
183
+ if (pluginDir && existsSync(pluginDir)) {
184
+ let timer = null;
185
+ const notify = (_event, file) => {
186
+ if (String(file ?? "").startsWith("sysroot")) return;
187
+ clearTimeout(timer);
188
+ timer = setTimeout(() => {
189
+ for (const c of reloadClients) c.write("data: reload\n\n");
190
+ }, 100);
191
+ };
192
+ // Only what the page uses: the staged root files and assets/. The same dir also holds the editor's
193
+ // C++ SDK headers (sysroot/), which a recursive watch would scan and trip over while it is replaced.
194
+ // A watcher error must not take the preview down.
195
+ watch(pluginDir, notify).on("error", () => {});
196
+ const assetsDir = join(pluginDir, "assets");
197
+ if (existsSync(assetsDir)) {
198
+ try {
199
+ // Recursive: macOS/Windows always, Linux on Node 20.13+.
200
+ watch(assetsDir, { recursive: true }, notify).on("error", () => {});
201
+ } catch {
202
+ watch(assetsDir, notify).on("error", () => {});
203
+ }
204
+ }
205
+ }
206
+
103
207
  const server = createServer((req, res) => {
104
208
  const url = (req.url || "/").split("?")[0];
105
209
 
106
- // Developer's plugin (sandbox.html, content.js, manifest.json, assets/)
210
+
211
+ if (url === RELOAD_PATH) {
212
+ res.writeHead(200, {
213
+ "Content-Type": "text/event-stream",
214
+ "Cache-Control": "no-cache",
215
+ Connection: "keep-alive",
216
+ "Access-Control-Allow-Origin": "*",
217
+ });
218
+ res.write("retry: 1000\n\n");
219
+ reloadClients.add(res);
220
+ req.on("close", () => reloadClients.delete(res));
221
+ return;
222
+ }
223
+
224
+
107
225
  if (url.startsWith(PLUGIN_BASE)) {
108
226
  if (!pluginDir) {
109
227
  res.statusCode = 404;
@@ -111,18 +229,18 @@ const server = createServer((req, res) => {
111
229
  return;
112
230
  }
113
231
  const rel = url.slice(PLUGIN_BASE.length) || "/";
114
- if (tryServe(res, pluginDir, rel)) return;
232
+ // no-store so the browser always re-fetches the freshly staged manifest/assets.
233
+ if (tryServe(res, pluginDir, rel, { noStore: true })) return;
115
234
  res.statusCode = 404;
116
235
  res.end("plugin asset not found");
117
236
  return;
118
237
  }
119
238
 
120
- // Host-provided plugin runtime (@rainbow-robotics/plugin-ui, React).
121
- if (url.startsWith(RUNTIME_BASE)) {
122
- const rel = url.slice(RUNTIME_BASE.length) || "/";
123
- if (tryServe(res, runtimeDir, rel)) return;
124
- res.statusCode = 404;
125
- res.end("plugin runtime asset not found");
239
+ if (url.startsWith("/models/")) {
240
+ serveModel(res, url).catch((e) => {
241
+ res.statusCode = 502;
242
+ res.end(`model download failed: ${e.message}`);
243
+ });
126
244
  return;
127
245
  }
128
246
 
@@ -131,13 +249,12 @@ const server = createServer((req, res) => {
131
249
 
132
250
  // SPA fallback → injected index.html
133
251
  res.setHeader("Content-Type", "text/html; charset=utf-8");
134
- res.end(indexHtml);
252
+ res.end(renderIndexHtml());
135
253
  });
136
254
 
137
255
  server.listen(port, () => {
138
256
  console.log(`[preview-host] mini-Muscat → http://localhost:${port}`);
139
257
  console.log(`[preview-host] dist: ${distDir}`);
140
- console.log(`[preview-host] runtime: ${runtimeDir} → ${RUNTIME_BASE}`);
141
258
  console.log(
142
259
  `[preview-host] plugin: ${pluginDir || "(none — pass --plugin <dir>)"} → ${PLUGIN_BASE}`,
143
260
  );
@@ -1 +0,0 @@
1
- import{ay as u,ao as s,I as a,cw as v,aq as p,K as d,av as i,dy as N,dz as C}from"./FactoryMap.CBpf9N92.js";import{a as S,R as k,b as T}from"./index.ayADrA9_.js";import{importShared as D}from"./__federation_fn_import.Drmbxo5T.js";const{useQuery:I}=await D("@tanstack/react-query"),f=[{key:"dock",endpoint:"/{robot_model}/capability/dock",labelKey:"move.amr.rightPanel.capability.dock"},{key:"io",endpoint:"/{robot_model}/capability/Io",labelKey:"move.amr.rightPanel.capability.io"},{key:"camera",endpoint:"/{robot_model}/capability/camera",labelKey:"move.amr.rightPanel.capability.camera"},{key:"lidar2d",endpoint:"/{robot_model}/capability/lidar2d",labelKey:"move.amr.rightPanel.capability.lidar2d"},{key:"lidar3d",endpoint:"/{robot_model}/capability/lidar3d",labelKey:"move.amr.rightPanel.capability.lidar3d"},{key:"imu",endpoint:"/{robot_model}/capability/imu",labelKey:"move.amr.rightPanel.capability.imu"},{key:"safetyBumper",endpoint:"/{robot_model}/capability/safetyBumper",labelKey:"move.amr.rightPanel.capability.safetyBumper"},{key:"safetyInterlock",endpoint:"/{robot_model}/capability/safetyInterlock",labelKey:"move.amr.rightPanel.capability.safetyInterlock"},{key:"safetyObstacle",endpoint:"/{robot_model}/capability/safetyObstacle",labelKey:"move.amr.rightPanel.capability.safetyObstacle"},{key:"safetyOperationStop",endpoint:"/{robot_model}/capability/safetyOperationStop",labelKey:"move.amr.rightPanel.capability.safetyOperationStop"},{key:"safetySpeedControl",endpoint:"/{robot_model}/capability/safetySpeedControl",labelKey:"move.amr.rightPanel.capability.safetySpeedControl"},{key:"tabos",endpoint:"/{robot_model}/capability/tabos",labelKey:"move.amr.rightPanel.capability.tabos"}],A=e=>typeof e=="object"&&e!==null&&"enabled"in e&&e.enabled===!1,O=e=>{if(e instanceof Error)return e.message;if(typeof e=="object"&&e!==null&&"message"in e){const t=e.message;if(typeof t=="string")return t}},E=async({robot_model:e})=>{const t=await Promise.allSettled(f.map(l=>{const n=l.endpoint.replace("{robot_model}",e);return S.get(n)}));return f.map((l,n)=>{const r=t[n];return r.status==="fulfilled"?{...l,supported:!A(r.value),data:r.value}:{...l,supported:!1,data:null,errorMessage:O(r.reason)}})},P=({robot_model:e,enabled:t=!0})=>I({queryKey:["amrCapabilities",e],queryFn:()=>E({robot_model:e}),enabled:!!e&&t,staleTime:5*1e3,gcTime:60*1e3}),F={0:"NONE",1:"CHARGING",2:"COMPLETE",3:"FAIL",4:"CANCEL"},B={0:"DEFAULT",1:"TABOS"},w={0:"CABLE",1:"CONTACT",2:"INDUCTIVE"},_={0:"RPLIDAR",1:"SICK",2:"LAKI",3:"LIVOX",4:"HOKUYO"},L={0:"ORBBEC"},o=({label:e,children:t})=>s(p,{className:"items-center justify-between gap-3",children:[a("span",{className:"typo-compact-xs-normal text-fg-subtle shrink-0",children:e}),a("span",{className:d("typo-compact-xs-normal text-right",t!=null?"text-fg-default":"text-fg-subtler"),children:t??"—"})]}),K={default:"gray",success:"green",warning:"orange",danger:"red"},c=({label:e,variant:t="default"})=>a(T,{type:"soft",color:K[t],children:e}),y=({label:e,value:t})=>a(o,{label:e,children:a(c,{label:t?"ON":"OFF",variant:t?"success":"default"})}),m=({label:e,bits:t})=>s(i,{className:"gap-1",children:[a("span",{className:"typo-compact-xs-normal text-fg-subtle",children:e}),t?.length?a(p,{className:"gap-1",children:t.map((l,n)=>a("div",{className:d("size-4 rounded-sm border text-center leading-4",l?"border-fg-success bg-fill-success-subtlest":"border-border-subtler bg-fill-disabled"),children:a("span",{className:d("typo-compact-2xs-normal",l?"text-fg-success":"text-fg-subtler"),children:n})},n))}):a("span",{className:"typo-compact-xs-normal text-fg-subtler",children:"—"})]}),g=({label:e,connection:t,rows:l})=>s(i,{className:"bg-fill-disabled gap-1.5 rounded-md p-2.5",children:[a("span",{className:"typo-compact-xs-semibold text-fg-default",children:e}),s(p,{className:"items-center justify-between gap-3",children:[a("span",{className:"typo-compact-xs-normal text-fg-subtle shrink-0",children:"Connection"}),s(p,{className:"items-center gap-1",children:[a(C,{color:t?"green":"gray"}),a("span",{className:"typo-compact-2xs-normal text-fg-subtle",children:t?"Connected":"Disconnected"})]})]}),l.map(({key:n,value:r})=>a(o,{label:n,children:r},n))]}),x=({flags:e})=>a(p,{className:"flex-wrap gap-1.5",children:e.map(({label:t,value:l})=>a(c,{label:t,variant:l?"success":"default"},t))}),R=({data:e})=>{const t=F[e.chargeState??-1]??String(e.chargeState),l=e.chargeState===1?"success":e.chargeState===3?"danger":e.chargeState===4?"warning":"default";return s(i,{className:"gap-2",children:[s(i,{className:"bg-fill-disabled gap-2 rounded-md p-2.5",children:[a(y,{label:"Dock State",value:e.dockState}),a(o,{label:"Charge State",children:a(c,{label:t,variant:l})}),s(o,{label:"Battery",children:[e.batteryPercent?.toFixed(1)," %"]}),s(o,{label:"Charge Current",children:[e.chargeCurrent?.toFixed(2)," A"]}),s(o,{label:"Contact Voltage",children:[e.contactVoltage?.toFixed(2)," V"]}),a(o,{label:"Battery Type",children:a(c,{label:B[e.batteryType??0]??"—"})})]}),s(p,{className:"items-center gap-1.5 px-0.5",children:[a("span",{className:"typo-compact-xs-normal text-fg-subtle shrink-0",children:"Charge Type"}),e.chargeType?.length?a(p,{className:"flex-wrap gap-1.5",children:e.chargeType.map(n=>a(c,{label:w[n]??String(n),variant:"default"},n))}):a("span",{className:"typo-compact-xs-normal text-fg-subtler",children:"—"})]})]})},M=({data:e})=>s(i,{className:"gap-3 p-0.5",children:[a(m,{label:"MCU0 DIO",bits:e.mcu0Dio}),a(m,{label:"MCU1 DIO",bits:e.mcu1Dio}),a(m,{label:"MCU0 DIN",bits:e.mcu0Din}),a(m,{label:"MCU1 DIN",bits:e.mcu1Din})]}),V=({data:e})=>s(i,{className:"gap-2",children:[a(x,{flags:[{label:"Enabled",value:e.enabled},{label:"Obstacle",value:e.enabledObs},{label:"Depth",value:e.enabledDepth},{label:"Filter",value:e.enabledFilter}]}),e.info?.length?e.info.map((t,l)=>{const n=typeof t.type=="number"?L[t.type]??String(t.type):t.type??"—",r=t.camId??t.index??l;return a(g,{label:`Camera ${r}${t.serial?` · ${t.serial}`:""}`,connection:t.connection,rows:[{key:"Type",value:a(c,{label:n})},{key:"TF",value:t.tf?.length?t.tf.map(b=>b.toFixed(2)).join(", "):void 0}]},l)}):a("span",{className:"typo-compact-xs-normal text-fg-subtler px-0.5",children:"—"})]}),h=({data:e,is3d:t=!1})=>s(i,{className:"gap-2",children:[a(x,{flags:[{label:"Enabled",value:e.enabled},{label:"Obstacle",value:e.enabledObs}]}),e.info?.length?e.info.map((l,n)=>a(g,{label:`Lidar ${l.index??n}${l.serial?` · ${l.serial}`:""}`,connection:l.connection,rows:[{key:"Type",value:a(c,{label:_[l.type]??String(l.type??"—")})},...t?[]:[{key:"IP",value:l.ip}],{key:"Safety",value:l.safety!==void 0?a(c,{label:l.safety?"Safety":"Normal",variant:l.safety?"warning":"default"}):void 0},{key:"TF",value:l.tf?.length?l.tf.map(r=>r.toFixed(2)).join(", "):void 0}]},n)):a("span",{className:"typo-compact-xs-normal text-fg-subtler px-0.5",children:"—"})]}),U=({data:e})=>a(i,{className:"gap-2",children:e.info?.length?e.info.map((t,l)=>a(g,{label:`IMU ${t.index??l}${t.serial?` · ${t.serial}`:""}`,connection:t.connection,rows:[{key:"Type",value:a(c,{label:t.type===1?"IMU":"DEFAULT"})}]},l)):a("span",{className:"typo-compact-xs-normal text-fg-subtler px-0.5",children:"—"})}),j=({data:e})=>{const t=[{label:"Bumper State",value:e.bumperState},{label:"Interlock State",value:e.interlockState},{label:"Obstacle Detect",value:e.obsDetect},{label:"Operation Stop",value:e.operationStopState},{label:"Speed Control",value:e.speedControlState}].filter(l=>l.value!==void 0);return s(i,{className:"bg-fill-disabled gap-2 rounded-md p-2.5",children:[a(y,{label:"Enabled",value:e.enabled}),t.map(l=>a(y,{label:l.label,value:l.value},l.label))]})},$=({data:e})=>s(i,{className:"bg-fill-disabled gap-2 rounded-md p-2.5",children:[s(o,{label:"Voltage",children:[e.tabosVoltage?.toFixed(2)," V"]}),s(o,{label:"Current",children:[e.tabosCurrent?.toFixed(2)," A"]}),s(o,{label:"SOC",children:[e.tabosSoc?.toFixed(1)," %"]}),s(o,{label:"SOH",children:[e.tabosSoh?.toFixed(1)," %"]}),s(o,{label:"Temp",children:[e.tabosTemp?.toFixed(1)," °C"]})]}),G=({capKey:e,data:t})=>{switch(e){case"dock":return a(R,{data:t});case"io":return a(M,{data:t});case"camera":return a(V,{data:t});case"lidar2d":return a(h,{data:t});case"lidar3d":return a(h,{data:t,is3d:!0});case"imu":return a(U,{data:t});case"tabos":return a($,{data:t});default:return a(j,{data:t})}},Y=({item:e})=>{const{t}=u();return e.supported?e.data?a("div",{className:"pb-1",children:a(G,{capKey:e.key,data:e.data})}):null:a("p",{className:"typo-compact-xs-normal text-fg-disabled px-1 py-2",children:t("move.amr.rightPanel.capability.status.notSupported")})},H=()=>{const{t:e}=u();return a(N,{className:"flex-1 [&_[data-slot='empty-view-section']]:h-full",type:"icon",icon:a(k,{size:20}),message:e("move.amr.rightPanel.capability.status.loading")})},X=({className:e,robotModel:t})=>{const{t:l}=u(),{data:n,isLoading:r}=P({robot_model:t});return s(i,{className:d("AmrCapabilityControl h-full min-h-0",e),children:[r&&a(H,{}),(n??[]).map(b=>a("div",{className:"border-subtler border-b px-1 py-1",children:a(v,{disabled:!b.supported,title:a(p,{className:"w-full items-center justify-between gap-2",children:a("span",{className:d("typo-compact-sm2-semibold min-w-0 truncate",b.supported?"text-fg-default":"text-fg-disabled"),children:l(b.labelKey)})}),children:a(Y,{item:b})})},b.key))]})};export{X as default};