@rainbow-robotics/preview-host 1.3.8-dev.2 → 1.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 (51) hide show
  1. package/README.md +254 -254
  2. package/build.mjs +53 -53
  3. package/dist/assets/{AmrCapabilityControl.C4xiLjRl.js → AmrCapabilityControl.uMKnOOk0.js} +1 -1
  4. package/dist/assets/{RbLocalizationProvider.DXsc16pV.js → RbLocalizationProvider.c-57mWsf.js} +7 -7
  5. package/dist/assets/{__federation_expose_App.BMXng8Ke.js → __federation_expose_App.Cr76Vrqb.js} +297 -292
  6. package/dist/assets/__federation_fn_import.DdkEuT6t.js +2 -2
  7. package/dist/assets/{cssMode.DSgEs3Fy.js → cssMode.DWY0mg29.js} +1 -1
  8. package/dist/assets/{freemarker2.Di820O1V.js → freemarker2.BcQcIHbV.js} +1 -1
  9. package/dist/assets/{handlebars.8PwOoFy6.js → handlebars.apOy76CD.js} +1 -1
  10. package/dist/assets/{html.400C3t45.js → html.FOC5wcqt.js} +1 -1
  11. package/dist/assets/{htmlMode.CRheDnup.js → htmlMode.DZcYEntg.js} +1 -1
  12. package/dist/assets/{index.Da-y1HNK.js → index.Bxmeiw-f.js} +5 -5
  13. package/dist/assets/index.Dzu1iP6J.js +1 -0
  14. package/dist/assets/{index.BP0yBo-w.js → index.G9r3GUil.js} +1 -1
  15. package/dist/assets/{javascript.DXPB8Jbo.js → javascript.CEL3KJ9t.js} +1 -1
  16. package/dist/assets/{jsonMode.DVz0aIDE.js → jsonMode.Clw0nKgf.js} +1 -1
  17. package/dist/assets/{liquid.BP9dP7-Z.js → liquid.JBTTz117.js} +1 -1
  18. package/dist/assets/{lspLanguageFeatures.CpNhcIHE.js → lspLanguageFeatures.Ap43Ejq9.js} +1 -1
  19. package/dist/assets/{mdx.KhufbQQF.js → mdx.B2yIdDo_.js} +1 -1
  20. package/dist/assets/{python.C94rM7lW.js → python.DKT8_C5B.js} +1 -1
  21. package/dist/assets/{razor.DPjaPBcH.js → razor.z656zFnB.js} +1 -1
  22. package/dist/assets/remoteEntry.js +1 -1
  23. package/dist/assets/{tsMode.idfXhycx.js → tsMode.CJn1kWbF.js} +1 -1
  24. package/dist/assets/{typescript.Bg1XCf6a.js → typescript.B27DsFAh.js} +1 -1
  25. package/dist/assets/{useFileDownload.CmIfPP9S.js → useFileDownload.BVrgd27i.js} +199 -199
  26. package/dist/assets/{xml.Bg1Kn9mk.js → xml.D8-DrtSf.js} +1 -1
  27. package/dist/assets/{yaml.DJnG9bGb.js → yaml.c2GnKl-i.js} +1 -1
  28. package/dist/data/joint/joint_data_20250617_101757_1.csv +448 -448
  29. package/dist/data/robots/models.json +47 -47
  30. package/dist/data/robots/test.json +38 -38
  31. package/dist/data/service-info.json +174 -102
  32. package/dist/imgs/nexus/commands_tree_icons/color_folder.svg +9 -9
  33. package/dist/imgs/nexus/forms/gripper/g11_help.png +0 -0
  34. package/dist/imgs/nexus/forms/gripper/gripper_11.png +0 -0
  35. package/dist/imgs/nexus/forms/gripper/gripper_12.png +0 -0
  36. package/dist/imgs/nexus/forms/gripper/gripper_13.png +0 -0
  37. package/dist/imgs/nexus/forms/gripper/gripper_14.png +0 -0
  38. package/dist/imgs/nexus/forms/gripper/gripper_15.png +0 -0
  39. package/dist/imgs/nexus/forms/gripper/gripper_16.png +0 -0
  40. package/dist/imgs/nexus/forms/gripper/gripper_17.png +0 -0
  41. package/dist/imgs/nexus/forms/gripper/gripper_18.png +0 -0
  42. package/dist/imgs/nexus/forms/gripper/gripper_19_0.png +0 -0
  43. package/dist/imgs/nexus/forms/gripper/gripper_19_1.png +0 -0
  44. package/dist/imgs/nexus/forms/gripper/gripper_20.png +0 -0
  45. package/dist/imgs/nexus/forms/gripper/gripper_21.png +0 -0
  46. package/dist/imgs/nexus/forms/gripper/gripper_22.png +0 -0
  47. package/dist/imgs/profile.svg +4 -4
  48. package/dist/index.html +17 -17
  49. package/package.json +1 -1
  50. package/serve.mjs +193 -193
  51. package/dist/assets/index.1ZV6DMoI.js +0 -1
package/serve.mjs CHANGED
@@ -1,193 +1,193 @@
1
- #!/usr/bin/env node
2
- // Usage:
3
- // rb-preview-host --plugin <staged-dir> [--port 4180] [--dist <dir>]
4
- import { createServer } from "node:http";
5
- import { createReadStream, existsSync, readFileSync, statSync, watch } from "node:fs";
6
- import { dirname, extname, join, resolve } from "node:path";
7
- import { fileURLToPath } from "node:url";
8
-
9
- const here = dirname(fileURLToPath(import.meta.url));
10
-
11
- function arg(name, fallback) {
12
- const i = process.argv.indexOf(`--${name}`);
13
- return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
14
- }
15
-
16
- const port = Number(arg("port", "4180"));
17
- const distDir = resolve(arg("dist", join(here, "dist")));
18
- const pluginDir = arg("plugin", "")
19
- ? resolve(arg("plugin", ""))
20
- : "";
21
- const socketUrl = arg("socket-url", "");
22
- const robotHost = arg("robot-host", "");
23
- const devServerUrl = arg("dev-server-url", "");
24
- const PLUGIN_BASE = "/plugin-dev";
25
- const RELOAD_PATH = "/__preview_reload";
26
-
27
- const CONTENT_TYPE = {
28
- ".html": "text/html; charset=utf-8",
29
- ".js": "text/javascript; charset=utf-8",
30
- ".mjs": "text/javascript; charset=utf-8",
31
- ".css": "text/css; charset=utf-8",
32
- ".json": "application/json; charset=utf-8",
33
- ".svg": "image/svg+xml",
34
- ".png": "image/png",
35
- ".jpg": "image/jpeg",
36
- ".jpeg": "image/jpeg",
37
- ".webp": "image/webp",
38
- ".gif": "image/gif",
39
- ".woff": "font/woff",
40
- ".woff2": "font/woff2",
41
- ".glb": "model/gltf-binary",
42
- ".mp3": "audio/mpeg",
43
- ".wasm": "application/wasm",
44
- };
45
-
46
- if (!existsSync(distDir)) {
47
- console.error(
48
- `[preview-host] dist not found at ${distDir}. Run \`node build.mjs\` first.`,
49
- );
50
- process.exit(1);
51
- }
52
-
53
-
54
- let previewPluginId = "";
55
- // Core SW category the preview program pretends to run on (command forms are keyed by it).
56
- let previewBeService = "manipulate";
57
- if (pluginDir) {
58
- try {
59
- const manifest = JSON.parse(readFileSync(resolve(pluginDir, "manifest.json"), "utf8"));
60
- previewPluginId = manifest.id || "";
61
- if (Array.isArray(manifest.targetCategorys) && manifest.targetCategorys[0]) {
62
- previewBeService = manifest.targetCategorys[0];
63
- }
64
- } catch {
65
- /* manifest missing/unreadable — no preview id */
66
- }
67
- }
68
-
69
- const injectedLines = [
70
- " <script>",
71
- " window.__RB_PLUGIN_PREVIEW_HOST__ = true;",
72
- " window.__RB_ASSETS_BASE_URL__ = window.location.origin;",
73
- ` window.__RB_PLUGIN_PREVIEW_BASE__ = ${JSON.stringify(PLUGIN_BASE)};`,
74
- ];
75
- if (previewPluginId) {
76
- injectedLines.push(` window.__RB_PREVIEW_PLUGIN_ID__ = ${JSON.stringify(previewPluginId)};`);
77
- }
78
- injectedLines.push(` window.__RB_PREVIEW_BE_SERVICE__ = ${JSON.stringify(previewBeService)};`);
79
- if (devServerUrl) {
80
- injectedLines.push(` window.__RB_PLUGIN_DEV_SERVER_URL__ = ${JSON.stringify(devServerUrl)};`);
81
- }
82
- if (socketUrl) {
83
- injectedLines.push(` window.__RB_PLUGIN_PREVIEW_SOCKET_URL__ = ${JSON.stringify(socketUrl)};`);
84
- }
85
- if (robotHost) {
86
-
87
- injectedLines.push(` window.__RB_ROBOT_HOST__ = ${JSON.stringify(robotHost)};`);
88
- }
89
- injectedLines.push(" </script>");
90
-
91
- if (pluginDir) {
92
- injectedLines.push(
93
- " <script>",
94
- ` new EventSource(${JSON.stringify(RELOAD_PATH)}).onmessage = () => location.reload();`,
95
- " </script>",
96
- );
97
- }
98
- injectedLines.push(" </head>");
99
-
100
- function renderIndexHtml() {
101
- return readFileSync(join(distDir, "index.html"), "utf8").replace(
102
- "</head>",
103
- injectedLines.join("\n"),
104
- );
105
- }
106
-
107
- function sendFile(res, filePath, { noStore = false } = {}) {
108
- res.setHeader("Access-Control-Allow-Origin", "*");
109
- if (noStore) res.setHeader("Cache-Control", "no-store");
110
- const type = CONTENT_TYPE[extname(filePath)];
111
- if (type) res.setHeader("Content-Type", type);
112
- createReadStream(filePath).pipe(res);
113
- }
114
-
115
- function tryServe(res, baseDir, relPath, opts) {
116
- const filePath = resolve(baseDir, `.${relPath}`);
117
- if (!filePath.startsWith(baseDir)) return false;
118
- if (existsSync(filePath) && statSync(filePath).isFile()) {
119
- sendFile(res, filePath, opts);
120
- return true;
121
- }
122
- return false;
123
- }
124
-
125
-
126
- const reloadClients = new Set();
127
- if (pluginDir && existsSync(pluginDir)) {
128
- let timer = null;
129
- const notify = () => {
130
- clearTimeout(timer);
131
- timer = setTimeout(() => {
132
- for (const c of reloadClients) c.write("data: reload\n\n");
133
- }, 100);
134
- };
135
- try {
136
- // Recursive: macOS/Windows always, Linux on Node 20.13+.
137
- watch(pluginDir, { recursive: true }, notify);
138
- } catch {
139
-
140
- watch(pluginDir, notify);
141
- console.warn(
142
- "[preview-host] recursive watch unavailable — live reload limited to plugin root (upgrade to Node 20.13+ for full watch).",
143
- );
144
- }
145
- }
146
-
147
- const server = createServer((req, res) => {
148
- const url = (req.url || "/").split("?")[0];
149
-
150
-
151
- if (url === RELOAD_PATH) {
152
- res.writeHead(200, {
153
- "Content-Type": "text/event-stream",
154
- "Cache-Control": "no-cache",
155
- Connection: "keep-alive",
156
- "Access-Control-Allow-Origin": "*",
157
- });
158
- res.write("retry: 1000\n\n");
159
- reloadClients.add(res);
160
- req.on("close", () => reloadClients.delete(res));
161
- return;
162
- }
163
-
164
-
165
- if (url.startsWith(PLUGIN_BASE)) {
166
- if (!pluginDir) {
167
- res.statusCode = 404;
168
- res.end("no --plugin dir configured");
169
- return;
170
- }
171
- const rel = url.slice(PLUGIN_BASE.length) || "/";
172
- // no-store so the browser always re-fetches the freshly staged manifest/assets.
173
- if (tryServe(res, pluginDir, rel, { noStore: true })) return;
174
- res.statusCode = 404;
175
- res.end("plugin asset not found");
176
- return;
177
- }
178
-
179
- // Static bundle + rb assets
180
- if (url !== "/" && tryServe(res, distDir, url)) return;
181
-
182
- // SPA fallback → injected index.html
183
- res.setHeader("Content-Type", "text/html; charset=utf-8");
184
- res.end(renderIndexHtml());
185
- });
186
-
187
- server.listen(port, () => {
188
- console.log(`[preview-host] mini-Muscat → http://localhost:${port}`);
189
- console.log(`[preview-host] dist: ${distDir}`);
190
- console.log(
191
- `[preview-host] plugin: ${pluginDir || "(none — pass --plugin <dir>)"} → ${PLUGIN_BASE}`,
192
- );
193
- });
1
+ #!/usr/bin/env node
2
+ // Usage:
3
+ // rb-preview-host --plugin <staged-dir> [--port 4180] [--dist <dir>]
4
+ import { createServer } from "node:http";
5
+ import { createReadStream, existsSync, readFileSync, statSync, watch } from "node:fs";
6
+ import { dirname, extname, join, resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const here = dirname(fileURLToPath(import.meta.url));
10
+
11
+ function arg(name, fallback) {
12
+ const i = process.argv.indexOf(`--${name}`);
13
+ return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
14
+ }
15
+
16
+ const port = Number(arg("port", "4180"));
17
+ const distDir = resolve(arg("dist", join(here, "dist")));
18
+ const pluginDir = arg("plugin", "")
19
+ ? resolve(arg("plugin", ""))
20
+ : "";
21
+ const socketUrl = arg("socket-url", "");
22
+ const robotHost = arg("robot-host", "");
23
+ const devServerUrl = arg("dev-server-url", "");
24
+ const PLUGIN_BASE = "/plugin-dev";
25
+ const RELOAD_PATH = "/__preview_reload";
26
+
27
+ const CONTENT_TYPE = {
28
+ ".html": "text/html; charset=utf-8",
29
+ ".js": "text/javascript; charset=utf-8",
30
+ ".mjs": "text/javascript; charset=utf-8",
31
+ ".css": "text/css; charset=utf-8",
32
+ ".json": "application/json; charset=utf-8",
33
+ ".svg": "image/svg+xml",
34
+ ".png": "image/png",
35
+ ".jpg": "image/jpeg",
36
+ ".jpeg": "image/jpeg",
37
+ ".webp": "image/webp",
38
+ ".gif": "image/gif",
39
+ ".woff": "font/woff",
40
+ ".woff2": "font/woff2",
41
+ ".glb": "model/gltf-binary",
42
+ ".mp3": "audio/mpeg",
43
+ ".wasm": "application/wasm",
44
+ };
45
+
46
+ if (!existsSync(distDir)) {
47
+ console.error(
48
+ `[preview-host] dist not found at ${distDir}. Run \`node build.mjs\` first.`,
49
+ );
50
+ process.exit(1);
51
+ }
52
+
53
+
54
+ let previewPluginId = "";
55
+ // Core SW category the preview program pretends to run on (command forms are keyed by it).
56
+ let previewBeService = "manipulate";
57
+ if (pluginDir) {
58
+ try {
59
+ const manifest = JSON.parse(readFileSync(resolve(pluginDir, "manifest.json"), "utf8"));
60
+ previewPluginId = manifest.id || "";
61
+ if (Array.isArray(manifest.targetCategorys) && manifest.targetCategorys[0]) {
62
+ previewBeService = manifest.targetCategorys[0];
63
+ }
64
+ } catch {
65
+ /* manifest missing/unreadable — no preview id */
66
+ }
67
+ }
68
+
69
+ const injectedLines = [
70
+ " <script>",
71
+ " window.__RB_PLUGIN_PREVIEW_HOST__ = true;",
72
+ " window.__RB_ASSETS_BASE_URL__ = window.location.origin;",
73
+ ` window.__RB_PLUGIN_PREVIEW_BASE__ = ${JSON.stringify(PLUGIN_BASE)};`,
74
+ ];
75
+ if (previewPluginId) {
76
+ injectedLines.push(` window.__RB_PREVIEW_PLUGIN_ID__ = ${JSON.stringify(previewPluginId)};`);
77
+ }
78
+ injectedLines.push(` window.__RB_PREVIEW_BE_SERVICE__ = ${JSON.stringify(previewBeService)};`);
79
+ if (devServerUrl) {
80
+ injectedLines.push(` window.__RB_PLUGIN_DEV_SERVER_URL__ = ${JSON.stringify(devServerUrl)};`);
81
+ }
82
+ if (socketUrl) {
83
+ injectedLines.push(` window.__RB_PLUGIN_PREVIEW_SOCKET_URL__ = ${JSON.stringify(socketUrl)};`);
84
+ }
85
+ if (robotHost) {
86
+
87
+ injectedLines.push(` window.__RB_ROBOT_HOST__ = ${JSON.stringify(robotHost)};`);
88
+ }
89
+ injectedLines.push(" </script>");
90
+
91
+ if (pluginDir) {
92
+ injectedLines.push(
93
+ " <script>",
94
+ ` new EventSource(${JSON.stringify(RELOAD_PATH)}).onmessage = () => location.reload();`,
95
+ " </script>",
96
+ );
97
+ }
98
+ injectedLines.push(" </head>");
99
+
100
+ function renderIndexHtml() {
101
+ return readFileSync(join(distDir, "index.html"), "utf8").replace(
102
+ "</head>",
103
+ injectedLines.join("\n"),
104
+ );
105
+ }
106
+
107
+ function sendFile(res, filePath, { noStore = false } = {}) {
108
+ res.setHeader("Access-Control-Allow-Origin", "*");
109
+ if (noStore) res.setHeader("Cache-Control", "no-store");
110
+ const type = CONTENT_TYPE[extname(filePath)];
111
+ if (type) res.setHeader("Content-Type", type);
112
+ createReadStream(filePath).pipe(res);
113
+ }
114
+
115
+ function tryServe(res, baseDir, relPath, opts) {
116
+ const filePath = resolve(baseDir, `.${relPath}`);
117
+ if (!filePath.startsWith(baseDir)) return false;
118
+ if (existsSync(filePath) && statSync(filePath).isFile()) {
119
+ sendFile(res, filePath, opts);
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+
125
+
126
+ const reloadClients = new Set();
127
+ if (pluginDir && existsSync(pluginDir)) {
128
+ let timer = null;
129
+ const notify = () => {
130
+ clearTimeout(timer);
131
+ timer = setTimeout(() => {
132
+ for (const c of reloadClients) c.write("data: reload\n\n");
133
+ }, 100);
134
+ };
135
+ try {
136
+ // Recursive: macOS/Windows always, Linux on Node 20.13+.
137
+ watch(pluginDir, { recursive: true }, notify);
138
+ } catch {
139
+
140
+ watch(pluginDir, notify);
141
+ console.warn(
142
+ "[preview-host] recursive watch unavailable — live reload limited to plugin root (upgrade to Node 20.13+ for full watch).",
143
+ );
144
+ }
145
+ }
146
+
147
+ const server = createServer((req, res) => {
148
+ const url = (req.url || "/").split("?")[0];
149
+
150
+
151
+ if (url === RELOAD_PATH) {
152
+ res.writeHead(200, {
153
+ "Content-Type": "text/event-stream",
154
+ "Cache-Control": "no-cache",
155
+ Connection: "keep-alive",
156
+ "Access-Control-Allow-Origin": "*",
157
+ });
158
+ res.write("retry: 1000\n\n");
159
+ reloadClients.add(res);
160
+ req.on("close", () => reloadClients.delete(res));
161
+ return;
162
+ }
163
+
164
+
165
+ if (url.startsWith(PLUGIN_BASE)) {
166
+ if (!pluginDir) {
167
+ res.statusCode = 404;
168
+ res.end("no --plugin dir configured");
169
+ return;
170
+ }
171
+ const rel = url.slice(PLUGIN_BASE.length) || "/";
172
+ // no-store so the browser always re-fetches the freshly staged manifest/assets.
173
+ if (tryServe(res, pluginDir, rel, { noStore: true })) return;
174
+ res.statusCode = 404;
175
+ res.end("plugin asset not found");
176
+ return;
177
+ }
178
+
179
+ // Static bundle + rb assets
180
+ if (url !== "/" && tryServe(res, distDir, url)) return;
181
+
182
+ // SPA fallback → injected index.html
183
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
184
+ res.end(renderIndexHtml());
185
+ });
186
+
187
+ server.listen(port, () => {
188
+ console.log(`[preview-host] mini-Muscat → http://localhost:${port}`);
189
+ console.log(`[preview-host] dist: ${distDir}`);
190
+ console.log(
191
+ `[preview-host] plugin: ${pluginDir || "(none — pass --plugin <dir>)"} → ${PLUGIN_BASE}`,
192
+ );
193
+ });
@@ -1 +0,0 @@
1
- import{j as m,co as F,U as V,a$ as K,x as _,bg as Y,cw as Q,ek as E,ga as X,db as P,ei as b,cu as Z,gH as u}from"./RbLocalizationProvider.DXsc16pV.js";import{importShared as k}from"./__federation_fn_import.DdkEuT6t.js";const x=()=>!0,L=()=>typeof window<"u"&&window.__RB_ROBOT_HOST__||void 0||void 0,ke=()=>x()&&!!L(),J=()=>x()&&!L(),Le=(e,t)=>e?.find(s=>s.point===t),ye=(e,t)=>{if(typeof e=="string")return e;const s=String(t);return e?.[s]},_e=(e,t)=>{if(typeof e=="string")return e;const s=String(t);return e?.[s]||e?.en},Pe=e=>e.toLocaleLowerCase()==="rainbowrobotics",be=e=>e===void 0?"—":`${e.toFixed(1)}%`,we=e=>{if(e===void 0)return"—";const t=e/1024/1024;return t<1024?`${Math.round(t)} MB`:`${(t/1024).toFixed(1)} GB`};var y=(e=>(e[e.SUPERVISOR=0]="SUPERVISOR",e[e.ADMIN=1]="ADMIN",e[e.MANAGER=2]="MANAGER",e[e.OPERATOR=3]="OPERATOR",e[e.USER=4]="USER",e[e.GUEST=999999]="GUEST",e))(y||{});const Me={SUPERVISOR:0,ADMIN:1,MANAGER:2,OPERATOR:3,USER:4,GUEST:999999};function v(e){try{const t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(atob(t))}catch{return null}}function w(e){if(!e)return null;const t=v(e);return t?t.exp*1e3:null}function O(){const e=c();return e?v(e)?.sid??"":""}const o={isAutoLogin:"isAutoLogin",accessToken:"access_token",refreshToken:"refresh_token"};function A(){localStorage.removeItem(o.accessToken),localStorage.removeItem(o.refreshToken),sessionStorage.removeItem(o.accessToken),sessionStorage.removeItem(o.refreshToken)}function h(){return localStorage.getItem(o.isAutoLogin)==="true"}function Ue(e){localStorage.setItem(o.isAutoLogin,e?"true":"false")}function c(){return h()?localStorage.getItem(o.accessToken):sessionStorage.getItem(o.accessToken)}function p(){return h()?localStorage.getItem(o.refreshToken):sessionStorage.getItem(o.refreshToken)}function ee(e,t,s){s?(localStorage.setItem(o.isAutoLogin,"true"),localStorage.setItem(o.accessToken,e),localStorage.setItem(o.refreshToken,t)):(localStorage.setItem(o.isAutoLogin,"false"),sessionStorage.setItem(o.accessToken,e),sessionStorage.setItem(o.refreshToken,t))}const{useQuery:te}=await k("@tanstack/react-query"),N="/auth/me",se=[N],ne=()=>z.get(N,{}),oe=({enabled:e})=>te({queryKey:se,queryFn:ne,enabled:e}),{createContext:re,useCallback:ae,useContext:ie,useEffect:C,useState:ce}=await k("react"),ue={id:"GUEST",username:"게스트",role:y.SUPERVISOR,sid:""},$=re({isLoggedIn:!1,setLoggedIn:()=>{}});let R=null;function G(e){R?.(e)}function xe({children:e}){const[t,s]=ce(!!c()),n=ae(r=>{s(r)},[]);return C(()=>(R=n,()=>{R=null}),[n]),m($.Provider,{value:{isLoggedIn:t,setLoggedIn:n},children:e})}function le(){const{isLoggedIn:e,setLoggedIn:t}=ie($),s=c(),n=p(),r=h(),{data:a}=oe({enabled:e}),i=a?{id:a.user_id,username:a.username??a.user_id,role:a.role??y.GUEST,sid:O()}:ue;return C(()=>{const f=!!s&&!!n;e!==f&&t(f)},[e,s,n,t]),{isLoggedIn:e,setLoggedIn:t,user:i,accessToken:s,refreshToken:n,isAutoLogin:r,isAtLeast:f=>i.role<=f,hasRole:f=>i.role===f}}const de=({className:e,open:t,onOpenChange:s,onConfirm:n})=>{const{t:r}=F(),a=()=>{s(!1),n()};return m(Y,{className:_(e,"w-100 max-w-full border-none p-0"),enableDimClose:!1,hideCloseButton:!0,open:t,onOpenChange:s,header:{title:r("login.modal.title.sessionExpired")},footer:m(V,{className:_("w-full gap-1","[&_button]:h-8 [&_button]:w-20"),justifyContent:"end",children:m(K,{variant:"brand",size:"sm",onClick:a,children:r("login.modal.button.sessionExpiredConfirm")})}),children:m("div",{className:"px-4 pt-3 pb-0",children:m("span",{className:"text-fg-default typo-compact-sm-normal",children:r("login.modal.desc.sessionExpired")})})})},ve="/muscat/app/log",T="/muscat/app/login",{useMutation:fe}=await k("@tanstack/react-query"),me="/logout",D=async e=>z.post(me,{sid:e}),Oe=()=>{const{setLoggedIn:e,user:t}=le(),s=Q();return fe({mutationFn:async()=>{if(t?.sid)return D(t.sid)},onSettled:()=>{A(),e(!1),s(T)}})},ge=`http://${window.location.hostname}:undefined`,he=1e4,pe=1e4,M=5e3;let H=null,j=null;function Ne(e){H=e}function Ce(e){j=e}let I=!1,B=0;function Se(){return!!(I||Date.now()-B<he)}const U=()=>{if(window.location.pathname===T)return;const e=async()=>{const t=O();if(t)try{await D(t)}catch{}A(),G(!1),j?.(T)};X.openModal({component:de,props:{onConfirm:e,onClose:e},options:{componentName:"SessionExpiredModal"}})};async function W(){if(Se())return null;const e=p();if(!e)return U(),null;I=!0;try{const t=await E.post(`${ge}/common/refresh`,{refresh_token:e}),{access_token:s,refresh_token:n}=t.data;return ee(s,n,h()),G(!0),H?.("auth",{token:s,autoLogin:h()?"true":"false"}),B=Date.now(),S(),s}catch(t){console.log("Token refresh failed:",t);const s=E.isAxiosError(t)?t.response?.status:null;if(s===403||s===401||s===409)return A(),U(),null;throw t}finally{I=!1}}let g=null;function q(){g&&(clearTimeout(g),g=null)}function S(){q();const e=w(c());if(!e)return;const t=Math.max(e-Date.now(),0),s=Math.min(Math.max(e-Date.now()-pe,M),t);g=setTimeout(async()=>{try{if(!p())return;!await W()&&p()&&S()}catch{if(c()){const n=w(c());if(n&&n>Date.now()){const r=Math.min(M*2,n-Date.now());r>0&&(g=setTimeout(S,r))}}}},s)}window.addEventListener("storage",e=>{e.key!==o.accessToken&&e.key!==o.refreshToken||(c()&&p()?S():q())});const l={onRequest({config:e}){if(e.url?.endsWith("/login")||e.url?.endsWith("/logout")||e.url?.endsWith("/refresh")||/^https?:\/\//i.test(e.url??"")&&!e.url?.startsWith(e.baseURL??""))return e;const n=c();return n&&e.headers&&(e.headers.Authorization=`Bearer ${n}`),e},onResponse({response:e}){return e?.data},async onResponseError({error:e}){const t=e.config;if(!t)return Promise.reject(e);if(t.url?.endsWith("/login")||t.url?.endsWith("/logout")||t.url?.endsWith("/refresh"))return A(),Promise.reject(e);if(e.response?.status===401&&!t._retry){t._retry=!0;try{const i=await W();return i?(t.headers.Authorization=`Bearer ${i}`,E(t)):Promise.reject(e)}catch(i){return Promise.reject(i)}}const n=e?.response?.data;P("useSimulator")!=="false"&&P("useSimulator");const r=typeof n=="object"&&"message"in n&&typeof n.message=="string"?n.message:b("common.toast.apiError.content"),a=e.status??e.response?.status;return[502,504].includes(a)||e.code==="ERR_NETWORK"||J()||t.skipErrorToast||Z.openToast({title:e.config.url?`[API Error] ${e.config.url}`:b("common.toast.apiError.title"),content:r,type:"basic",variant:"warning"}),Promise.reject(e)}},Ae=3e3,d=`http://${L()||window.location.hostname}:${Ae}`,z=u({baseURL:`${d}/common`},l),$e=u({baseURL:`${d}/manipulate`},l),Ge=u({baseURL:`${d}/log`},l),De=u({baseURL:`${d}/amr`},l),He=u({baseURL:`${d}/rby1`},l);u({baseURL:`${d}/deploy`},l);const je=u({baseURL:`${d}/host`},l);export{A,D as B,je as C,xe as D,c as E,y as J,ve as L,d as M,Me as R,De as a,ye as b,z as c,_e as d,be as e,Le as f,L as g,we as h,x as i,T as j,Oe as k,Ge as l,$e as m,Ne as n,W as o,q as p,Ce as q,He as r,se as s,ke as t,le as u,Pe as v,ee as w,S as x,h as y,Ue as z};