@rubytech/create-maxy-code 0.1.304 → 0.1.306

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 (35) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +14 -1
  3. package/payload/platform/plugins/docs/references/getting-started.md +13 -0
  4. package/payload/server/public/assets/{AdminLoginScreens-BXKCagZn.js → AdminLoginScreens-Cw882rmm.js} +1 -1
  5. package/payload/server/public/assets/AdminShell-DpWl1uoY.js +1 -0
  6. package/payload/server/public/assets/{Checkbox-BHmeAgrw.js → Checkbox-DAWZItdK.js} +1 -1
  7. package/payload/server/public/assets/{Transcript-DPDJitcb.js → Transcript-DbK2YA3K.js} +1 -1
  8. package/payload/server/public/assets/{admin-DHLuBUtk.js → admin-nQRdn79w.js} +1 -1
  9. package/payload/server/public/assets/audio-attachment-mime-j2VvxEtx.js +30 -0
  10. package/payload/server/public/assets/{browser-DgtLMsM1.js → browser-CHWZDCXt.js} +1 -1
  11. package/payload/server/public/assets/chat-BBK6ulFy.js +1 -0
  12. package/payload/server/public/assets/{data-C317FUk4.js → data-33mdnHv8.js} +1 -1
  13. package/payload/server/public/assets/{file-download-DXFcVkh6.js → file-download-P_qlMCg5.js} +1 -1
  14. package/payload/server/public/assets/{graph-CHf_9bmD.js → graph-Uaa5heM5.js} +2 -2
  15. package/payload/server/public/assets/{graph-labels-BbiX-sz-.js → graph-labels-rG63rHvl.js} +1 -1
  16. package/payload/server/public/assets/{jsx-runtime-BkXvvpkS.css → jsx-runtime-DZkld3Wk.css} +1 -1
  17. package/payload/server/public/assets/operator-CiDwt5I9.js +1 -0
  18. package/payload/server/public/assets/page-BvkaS_tu.js +1 -0
  19. package/payload/server/public/assets/{public-D3G4tgFu.js → public-DBXfM02B.js} +3 -3
  20. package/payload/server/public/assets/{useSelectionMode-DcgaoBP6.js → useSelectionMode-Dky-Stnf.js} +1 -1
  21. package/payload/server/public/browser.html +6 -6
  22. package/payload/server/public/chat.html +9 -9
  23. package/payload/server/public/data.html +5 -5
  24. package/payload/server/public/graph.html +8 -8
  25. package/payload/server/public/index.html +9 -9
  26. package/payload/server/public/operator.html +11 -11
  27. package/payload/server/public/public.html +6 -6
  28. package/payload/server/public/sw.js +24 -0
  29. package/payload/server/server.js +169 -7
  30. package/payload/server/public/assets/AdminShell-CxKd_V3O.js +0 -1
  31. package/payload/server/public/assets/audio-attachment-mime-BxI3Kl4_.js +0 -30
  32. package/payload/server/public/assets/chat-Ib78Kdhg.js +0 -1
  33. package/payload/server/public/assets/operator-BJ5tN5vl.js +0 -1
  34. package/payload/server/public/assets/page-CjuqiMAQ.js +0 -1
  35. /package/payload/server/public/assets/{jsx-runtime-BabLCDgS.js → jsx-runtime-sFVKdwlP.js} +0 -0
@@ -1227,6 +1227,89 @@ import { resolve as resolve29, join as join22, basename as basename8 } from "pat
1227
1227
  import { homedir as homedir3 } from "os";
1228
1228
  import { monitorEventLoopDelay } from "perf_hooks";
1229
1229
 
1230
+ // app/lib/pwa.ts
1231
+ var PWA_SURFACES = [
1232
+ {
1233
+ surface: "admin",
1234
+ shellFile: "index.html",
1235
+ manifestPath: "/manifest-admin.webmanifest",
1236
+ nameSuffix: "",
1237
+ startUrl: "/",
1238
+ scope: "/",
1239
+ id: "/?pwa=admin"
1240
+ },
1241
+ {
1242
+ surface: "operator",
1243
+ shellFile: "operator.html",
1244
+ manifestPath: "/manifest-operator.webmanifest",
1245
+ nameSuffix: " Operator",
1246
+ startUrl: "/",
1247
+ scope: "/",
1248
+ id: "/?pwa=operator"
1249
+ },
1250
+ {
1251
+ surface: "chat",
1252
+ shellFile: "chat.html",
1253
+ manifestPath: "/manifest-chat.webmanifest",
1254
+ nameSuffix: " Chat",
1255
+ startUrl: "/chat",
1256
+ scope: "/chat",
1257
+ id: "/chat?pwa=chat"
1258
+ }
1259
+ ];
1260
+ var MANIFEST_CONTENT_TYPE = "application/manifest+json";
1261
+ var SW_CONTENT_TYPE = "application/javascript";
1262
+ function pwaSurfaceForShell(file) {
1263
+ return PWA_SURFACES.find((s) => s.shellFile === file);
1264
+ }
1265
+ function buildManifest(s, b) {
1266
+ const name = `${b.productName}${s.nameSuffix}`;
1267
+ return {
1268
+ id: s.id,
1269
+ name,
1270
+ short_name: name,
1271
+ start_url: s.startUrl,
1272
+ scope: s.scope,
1273
+ display: "standalone",
1274
+ theme_color: b.themeColor,
1275
+ background_color: b.backgroundColor,
1276
+ icons: [{ src: b.iconPath, sizes: "any", purpose: "any" }]
1277
+ };
1278
+ }
1279
+ function escAttr(s) {
1280
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1281
+ }
1282
+ function swRegisterScript(s) {
1283
+ return [
1284
+ "<script>",
1285
+ "if('serviceWorker' in navigator){navigator.serviceWorker.register('/sw.js').catch(function(e){",
1286
+ `try{fetch('/api/_client-error',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({kind:'event',source:'pwa',op:'sw-register-fail',surface:'${s.surface}',scope:'${s.scope}',err:String((e&&e.message)||e)}),keepalive:true}).catch(function(){});}catch(_){}`,
1287
+ "});}",
1288
+ "</script>"
1289
+ ].join("\n");
1290
+ }
1291
+ function pwaHeadTags(s, b) {
1292
+ return [
1293
+ `<link rel="manifest" href="${escAttr(s.manifestPath)}">`,
1294
+ `<link rel="apple-touch-icon" href="${escAttr(b.iconPath)}">`,
1295
+ // Both the standards-based and the legacy Apple capable meta: Chromium
1296
+ // deprecates `apple-mobile-web-app-capable` in favour of
1297
+ // `mobile-web-app-capable`, while iOS Safari still reads the apple one.
1298
+ '<meta name="mobile-web-app-capable" content="yes">',
1299
+ '<meta name="apple-mobile-web-app-capable" content="yes">',
1300
+ `<meta name="theme-color" content="${escAttr(b.themeColor)}">`,
1301
+ swRegisterScript(s)
1302
+ ].join("\n");
1303
+ }
1304
+ function pwaCensus(d) {
1305
+ const manifestLinked = PWA_SURFACES.filter((s) => {
1306
+ const html = d.shellHtml(s.shellFile);
1307
+ return html != null && html.includes(`"${s.manifestPath}"`);
1308
+ }).length;
1309
+ const iconsPresent = d.iconExists() ? PWA_SURFACES.length : 0;
1310
+ return { surfaces: PWA_SURFACES.length, manifestLinked, iconsPresent };
1311
+ }
1312
+
1230
1313
  // server/webchat-descriptor.ts
1231
1314
  import { resolve, join as join2 } from "path";
1232
1315
  function webchatGatewayUrl() {
@@ -9153,7 +9236,7 @@ app9.post("/", async (c) => {
9153
9236
  const safe = typeof v === "string" ? truncate(v, 200) : typeof v === "number" || typeof v === "boolean" ? String(v) : JSON.stringify(v).slice(0, 200);
9154
9237
  return `${k}=${safe}`;
9155
9238
  }).join(" ");
9156
- const TAGGED_PREFIX_SOURCES = /* @__PURE__ */ new Set(["stream-log-click"]);
9239
+ const TAGGED_PREFIX_SOURCES = /* @__PURE__ */ new Set(["stream-log-click", "pwa"]);
9157
9240
  if (TAGGED_PREFIX_SOURCES.has(source)) {
9158
9241
  console.log(
9159
9242
  `[${source}] ts=${ts} ip=${ip} version=${version || "unknown"}${extra ? " " + extra : ""}`
@@ -11804,6 +11887,32 @@ function sortDirEntries(entries) {
11804
11887
  return aKey.localeCompare(bKey);
11805
11888
  });
11806
11889
  }
11890
+ var PROTECTED_DELETE_SEGMENTS = {
11891
+ ".git": "git",
11892
+ ".claude": "claude",
11893
+ secrets: "secrets",
11894
+ agents: "agents",
11895
+ specialists: "specialists",
11896
+ state: "state"
11897
+ };
11898
+ var PROTECTED_DELETE_BASENAMES = {
11899
+ "account.json": "account-json",
11900
+ "wa-channel-bindings.json": "channel-bindings",
11901
+ "webchat-channel-bindings.json": "channel-bindings"
11902
+ };
11903
+ function isProtectedFromDeletion(relPath) {
11904
+ const segments = relPath.split("/").filter(Boolean);
11905
+ for (const seg of segments) {
11906
+ if (Object.hasOwn(PROTECTED_DELETE_SEGMENTS, seg)) {
11907
+ return { protected: true, rule: PROTECTED_DELETE_SEGMENTS[seg] };
11908
+ }
11909
+ }
11910
+ const base = segments[segments.length - 1];
11911
+ if (base && Object.hasOwn(PROTECTED_DELETE_BASENAMES, base)) {
11912
+ return { protected: true, rule: PROTECTED_DELETE_BASENAMES[base] };
11913
+ }
11914
+ return { protected: false };
11915
+ }
11807
11916
  async function knowledgeDocOwnedByAccount(accountId, attachmentId) {
11808
11917
  if (!attachmentId) return false;
11809
11918
  const session = getSession();
@@ -12035,9 +12144,9 @@ app19.delete("/", requireAdminSession, async (c) => {
12035
12144
  return c.json({ error: "Not found" }, 404);
12036
12145
  }
12037
12146
  const base = basename6(absolute);
12038
- const segments = relPath.split("/").filter(Boolean);
12039
- if (base === "account.json" || segments.includes(".git")) {
12040
- console.error(`[data] file-delete blocked path="${relPath}" reason="protected"`);
12147
+ const protection = isProtectedFromDeletion(relPath);
12148
+ if (protection.protected) {
12149
+ console.error(`[data] file-delete blocked path="${relPath}" reason="protected" rule="${protection.rule}"`);
12041
12150
  return c.json({ error: "Protected file \u2014 refusing to delete" }, 403);
12042
12151
  }
12043
12152
  try {
@@ -18188,10 +18297,11 @@ app49.post("/api/remote-auth/set-password", async (c) => {
18188
18297
  });
18189
18298
  app49.route("/api/_client-error", client_error_default);
18190
18299
  console.log("[client-error-route] mounted");
18300
+ var PWA_PUBLIC_PATHS = /* @__PURE__ */ new Set(["/sw.js", ...PWA_SURFACES.map((s) => s.manifestPath)]);
18191
18301
  app49.use("*", async (c, next) => {
18192
18302
  const host = (c.req.header("host") ?? "").split(":")[0];
18193
18303
  const path2 = c.req.path;
18194
- if (path2 === "/favicon.ico" || path2.startsWith("/assets/") || path2.startsWith("/brand/")) {
18304
+ if (path2 === "/favicon.ico" || path2.startsWith("/assets/") || path2.startsWith("/brand/") || PWA_PUBLIC_PATHS.has(path2)) {
18195
18305
  await next();
18196
18306
  return;
18197
18307
  }
@@ -18338,6 +18448,17 @@ var brandScript = `<script>window.__BRAND__=${JSON.stringify({
18338
18448
  icon: brandIconPath,
18339
18449
  logoContainsName: !!BRAND.logoContainsName
18340
18450
  })}</script>`;
18451
+ var brandThemeColor = BRAND.defaultColors?.primary ?? "#000000";
18452
+ var brandBackgroundColor = BRAND.defaultColors?.background ?? "#ffffff";
18453
+ var brandIconFsPath = resolve29(process.cwd(), "public", brandIconPath.replace(/^\//, ""));
18454
+ var brandIconExists = existsSync27(brandIconFsPath);
18455
+ var SW_SOURCE = (() => {
18456
+ try {
18457
+ return readFileSync26(resolve29(process.cwd(), "public", "sw.js"), "utf-8");
18458
+ } catch {
18459
+ return null;
18460
+ }
18461
+ })();
18341
18462
  function readInstalledVersion() {
18342
18463
  try {
18343
18464
  if (!PLATFORM_ROOT9) return "unknown";
@@ -18388,11 +18509,13 @@ function cachedHtml(file) {
18388
18509
  const productNameEsc = escapeHtml(BRAND.productName);
18389
18510
  html = html.replace(/<title>([^<]*)<\/title>/, (_match, inner) => `<title>${escapeHtml(inner).replace(/Maxy/g, productNameEsc)}</title>`);
18390
18511
  html = html.replace('href="/favicon.ico"', `href="${escapeHtml(brandFaviconPath)}"`);
18391
- const headInjection = file === "index.html" ? `${brandScript}
18512
+ const pwaSurface = pwaSurfaceForShell(file);
18513
+ const pwaHead = pwaSurface ? "\n" + pwaHeadTags(pwaSurface, { iconPath: brandIconPath, themeColor: brandThemeColor }) + "\n" : "";
18514
+ const headInjection = (file === "index.html" ? `${brandScript}
18392
18515
  ${versionScript}
18393
18516
  ${clientErrorReporterScript}
18394
18517
  ` : `${brandScript}
18395
- `;
18518
+ `) + pwaHead;
18396
18519
  html = html.replace("</head>", `${headInjection}</head>`);
18397
18520
  htmlCache.set(file, html);
18398
18521
  }
@@ -18534,6 +18657,30 @@ app49.post("/api/vnc/client-event", async (c) => {
18534
18657
  app49.get("/g/:slug", (c) => {
18535
18658
  return c.html(brandedPublicHtml());
18536
18659
  });
18660
+ for (const pwa of PWA_SURFACES) {
18661
+ app49.get(pwa.manifestPath, (c) => {
18662
+ const manifest = buildManifest(pwa, {
18663
+ productName: BRAND.productName,
18664
+ iconPath: brandIconPath,
18665
+ themeColor: brandThemeColor,
18666
+ backgroundColor: brandBackgroundColor
18667
+ });
18668
+ c.header("Content-Type", MANIFEST_CONTENT_TYPE);
18669
+ console.log(
18670
+ `[pwa] op=manifest surface=${pwa.surface} brand=${BRAND.productName} status=200 ct=${MANIFEST_CONTENT_TYPE} icon=${brandIconPath} iconExists=${brandIconExists}`
18671
+ );
18672
+ return c.body(JSON.stringify(manifest));
18673
+ });
18674
+ }
18675
+ app49.get("/sw.js", (c) => {
18676
+ if (SW_SOURCE == null) {
18677
+ console.error("[pwa] op=sw status=500 reason=sw-source-missing");
18678
+ return c.text("Service worker unavailable", 500);
18679
+ }
18680
+ c.header("Content-Type", SW_CONTENT_TYPE);
18681
+ console.log(`[pwa] op=sw status=200 ct=${SW_CONTENT_TYPE}`);
18682
+ return c.body(SW_SOURCE);
18683
+ });
18537
18684
  app49.get("/graph", (c) => {
18538
18685
  const host = (c.req.header("host") ?? "").split(":")[0];
18539
18686
  if (isPublicHost(host) || isOperatorHost(host, getOperatorDomains())) return c.text("Not found", 404);
@@ -18591,6 +18738,21 @@ var port = requirePortEnv("MAXY_UI_INTERNAL_PORT", { tag: "ui-server" });
18591
18738
  var hostname = process.env.HOSTNAME ?? "127.0.0.1";
18592
18739
  var httpServer = serve({ fetch: app49.fetch, port, hostname });
18593
18740
  console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
18741
+ {
18742
+ const census = pwaCensus({
18743
+ shellHtml: (file) => {
18744
+ try {
18745
+ return cachedHtml(file);
18746
+ } catch {
18747
+ return null;
18748
+ }
18749
+ },
18750
+ iconExists: () => brandIconExists
18751
+ });
18752
+ console.log(
18753
+ `[pwa-census] surfaces=${census.surfaces} manifest-linked=${census.manifestLinked} icons-present=${census.iconsPresent}`
18754
+ );
18755
+ }
18594
18756
  startAuthHealthHeartbeat();
18595
18757
  {
18596
18758
  const loopHist = monitorEventLoopDelay({ resolution: 50 });
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-Pqm5yXtL.js";import{a as t,n,r,t as i}from"./jsx-runtime-BabLCDgS.js";import{a,i as o,o as s,r as c,s as l,t as u}from"./file-download-DXFcVkh6.js";import{l as d,o as f,r as p,t as m}from"./useSelectionMode-DcgaoBP6.js";async function h(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var g=r(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),_=r(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),v=r(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),y=r(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),b=r(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),x=r(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),S=r(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),C=r(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),w=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),T=r(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),E=r(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),D=r(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),ee=r(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),O=r(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),te=r(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),ne=r(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),k=r(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),A=r(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),re=r(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),ie=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),j=r(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),M=r(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),N=e(t(),1),P=i();function F(e){let{businessName:t,variant:r=`admin`,onNavigate:i,onToggleSidebar:a,sidebarOpen:l,onLogout:u,onDisconnect:d,disconnecting:m}=e,[h,g]=(0,N.useState)(!1),_=(0,N.useRef)(null),v=(0,N.useRef)(null),y=c(null),[w,D]=(0,N.useState)(null),[te,A]=(0,N.useState)(!1),[ie,M]=(0,N.useState)(null),[F,I]=(0,N.useState)(null),[ae,L]=(0,N.useState)(!1),[oe,R]=(0,N.useState)(null),[z,se]=(0,N.useState)(null),[ce,B]=(0,N.useState)(``);(0,N.useEffect)(()=>{B(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,N.useEffect)(()=>{if(!h)return;let e=e=>{_.current&&!_.current.contains(e.target)&&g(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]),(0,N.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`&&g(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[h]),(0,N.useEffect)(()=>{h&&v.current?.focus()},[h]),(0,N.useEffect)(()=>{if(!h||r!==`admin`)return;let e=!1;return y(`/api/admin/version`).then(e=>e.json()).then(t=>{e||se(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[h,r,y]);let V=(0,N.useCallback)(()=>{g(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),H=(0,N.useCallback)(e=>{g(!1),i(e)},[i]),le=(0,N.useCallback)(async()=>{if(w!==null){D(null),I(null);return}A(!0),M(null);try{let e=await y(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);D((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),M(e instanceof Error?e.message:String(e)),D([])}finally{A(!1)}},[w,y]),ue=(0,N.useCallback)(e=>{I(null),D(t=>t?.filter(t=>t.slug!==e)??null),y(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[y]),U=(0,N.useCallback)(()=>{g(!1),u()},[u]),de=(0,N.useCallback)(async()=>{R(null),await d()?(L(!1),g(!1)):R(`Disconnect failed — credentials still present. Try again.`)},[d]),fe=t||p.productName;return(0,P.jsxs)(`header`,{className:`admin-header`,children:[r===`admin`&&(0,P.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":l?`Hide sidebar`:`Show sidebar`,title:l?`Hide sidebar`:`Show sidebar`,"aria-expanded":l,onClick:a,children:l?(0,P.jsx)(ne,{size:20,strokeWidth:1.5}):(0,P.jsx)(k,{size:20,strokeWidth:1.5})}),(0,P.jsxs)(`div`,{className:`chat-header-label`,children:[(0,P.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,P.jsx)(`img`,{src:f,alt:``,className:`chat-logo`})}),(0,P.jsx)(`h1`,{className:`chat-tagline`,children:fe})]}),(0,P.jsxs)(`div`,{className:`chat-burger-wrap`,ref:_,children:[(0,P.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:V,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":h,children:(0,P.jsx)(O,{size:20})}),h&&(0,P.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[r===`admin`&&(0,P.jsxs)(`button`,{ref:v,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`dashboard`),children:[(0,P.jsx)(E,{size:14}),` Dashboard`]}),r===`operator`&&(0,P.jsxs)(`button`,{ref:v,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`chat`),children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`data`),children:[(0,P.jsx)(x,{size:14}),` Data`]}),r===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`graph`),children:[(0,P.jsx)(re,{size:14}),` Graph`]}),r===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`browser`),children:[(0,P.jsx)(C,{size:14}),` Browser`]}),r===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>H(`chat`),children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`admin`&&(0,P.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:le,children:[(0,P.jsx)(S,{size:14}),` Public`,te&&(0,P.jsx)(s,{size:12,className:`spin`})]}),r===`admin`&&w!==null&&(0,P.jsxs)(`div`,{className:`chat-menu-agents`,children:[ie&&(0,P.jsx)(`span`,{className:`chat-menu-agent-error`,children:ie}),w.length===0&&!ie&&(0,P.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),w.map(e=>(0,P.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,P.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,P.jsxs)(`span`,{className:`agent-text`,children:[(0,P.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,P.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),F===e.slug?(0,P.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>ue(e.slug),children:(0,P.jsx)(b,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>I(null),children:(0,P.jsx)(o,{size:12})})]}):(0,P.jsxs)(`span`,{className:`agent-actions`,children:[(0,P.jsx)(`a`,{href:`${ce}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>g(!1),children:(0,P.jsx)(S,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>I(e.slug),children:(0,P.jsx)(n,{size:12})})]})]},e.slug))]}),r===`admin`&&(0,P.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,P.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,P.jsx)(T,{size:14}),(0,P.jsxs)(`span`,{className:`version-installed`,children:[z?`v${z.installed}`:`…`,z&&!z.updateAvailable&&(0,P.jsx)(`span`,{className:`version-uptodate-dot`}),z?.updateAvailable&&(0,P.jsx)(`span`,{className:`version-update-dot`})]})]}),r===`admin`&&(ae?(0,P.jsxs)(`div`,{className:`chat-menu-item chat-menu-disconnect`,children:[(0,P.jsx)(`span`,{children:`Disconnect Claude account?`}),(0,P.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm disconnect`,disabled:m,onClick:de,children:m?(0,P.jsx)(s,{size:12,className:`spin`}):(0,P.jsx)(b,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel disconnect`,disabled:m,onClick:()=>{L(!1),R(null)},children:(0,P.jsx)(o,{size:12})})]})]}):(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item chat-menu-disconnect`,role:`menuitem`,onClick:()=>{R(null),L(!0)},children:[(0,P.jsx)(j,{size:14}),` Disconnect Claude account`]})),r===`admin`&&oe&&(0,P.jsx)(`span`,{className:`chat-menu-agent-error`,children:oe}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:U,children:[(0,P.jsx)(ee,{size:14}),` Log out`]})]})]})]})}var I=`maxy-shell-side-px`;function ae(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function L(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-ae());return Math.min(Math.max(e,248),n)}function oe(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(I);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return L(t)}catch{}return 264}function R({targetSelector:e=`.platform`}){let t=(0,N.useRef)(null),[n,r]=(0,N.useState)(()=>oe()),i=(0,N.useRef)(n);(0,N.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,N.useCallback)(()=>{r(e=>{let t=L(e);return t===e?e:t})},[]);(0,N.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(L(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(I,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=L(264);r(e);try{window.localStorage.removeItem(I)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,P.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var z={whatsapp:{fill:`#25D366`,label:`WhatsApp`,path:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.71.306 1.263.489 1.694.625.712.227 1.36.195 1.872.118.571-.085 1.758-.719 2.006-1.413.247-.694.247-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.885-9.885 9.885M20.52 3.449C18.24 1.245 15.24.044 12.045.044 5.463.044.103 5.404.1 11.99c0 2.096.546 4.142 1.588 5.945L0 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.585 0 11.946-5.36 11.949-11.946 0-3.193-1.24-6.19-3.495-8.445`},telegram:{fill:`#229ED9`,label:`Telegram`,path:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`}};function se({channel:e,size:t=16}){let n=z[e];return(0,P.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:n.fill,role:`img`,"aria-label":n.label,className:`channel-icon`,children:(0,P.jsx)(`path`,{d:n.path})})}var ce=[`whatsapp`,`telegram`];function B(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function V(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var H=`auth-refresh-failed`;function le({error:e,onClose:t}){if(!e)return null;let n=e.reason===H,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:r}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,P.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function ue(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,N.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),h=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),g=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),_=r?.account?.subscriptionType,v=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,P.jsx)(`span`,{children:`Claude Code`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,P.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:p>0?V(p):`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:B(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await m(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var U=`https://claude.ai/code`,de=[500,1e3,1500,2e3,2500,3e3,3e3];function fe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${U}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function pe(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function W(e){let{businessName:t,cacheKey:r,role:i,userName:o,userAvatar:s,onSelectProjects:f,onSelectPeople:m,onSelectTasks:h,onSelectAgents:b,onCloseMobileDrawer:x,collapsed:C,selectedWhatsappId:T,onSelectWhatsappConversation:E,initialWhatsappSurface:ee=!1}=e,O=c(r),ne=p.productName,k=typeof o==`string`?o:o===null?`name unavailable`:t||ne,re=(k.trim().charAt(0)||`?`).toUpperCase(),[j,F]=(0,N.useState)(ee?`whatsapp`:`sessions`),[I,ae]=(0,N.useState)([]),[L,oe]=(0,N.useState)(!1),[R,z]=(0,N.useState)(null),[B,V]=(0,N.useState)(!1),[H,ue]=(0,N.useState)(`file`),[U,W]=(0,N.useState)(null),[me,G]=(0,N.useState)(null),[K,_e]=(0,N.useState)([]),[q,ve]=(0,N.useState)(!1),[J,Y]=(0,N.useState)(null),[ye,be]=(0,N.useState)(!1),[xe,Se]=(0,N.useState)(!1),[Ce,we]=(0,N.useState)(!1),[Te,Ee]=(0,N.useState)(null),[De,Oe]=(0,N.useState)(new Set),[ke,Ae]=(0,N.useState)(new Set),[je,Me]=(0,N.useState)(new Set),[Ne,Pe]=(0,N.useState)(new Set),[X,Fe]=(0,N.useState)(!1),[Ie,Le]=(0,N.useState)([]),[Re,ze]=(0,N.useState)(!1),[Be,Ve]=(0,N.useState)(null),[He,Ue]=(0,N.useState)(`whatsapp`),We=(0,N.useCallback)(e=>{if(x(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),W({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),W({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),u(r,e.downloadPath,e.downloadRoot??`data`),W({message:`Downloading ${e.name}`,failed:!1})},[r,x]);(0,N.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>W(null),2500);return()=>clearTimeout(e)},[U]);let Ge=(0,N.useCallback)(async()=>{if(r){V(!0),z(null);try{let e=await O(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);ae((await e.json()).artefacts??[]),oe(!0)}catch(e){let t=e instanceof Error?e.message:String(e);z(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{V(!1)}}},[r,O]),Z=(0,N.useCallback)(async()=>{if(!r)return null;be(!0),Y(null);try{let e=await O(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return _e(n),Ee(t.accountId??null),ve(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return Y(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{be(!1)}},[r,O]),Q=(0,N.useCallback)(async()=>{if(r){Ve(null);try{let e=await O(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Le((await e.json()).conversations??[]),ze(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Ve(`Couldn't load conversations.`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[r,O]);(0,N.useEffect)(()=>{!r||q||Z()},[r,q,Z]),(0,N.useEffect)(()=>{if(!r)return;let e=null;return Q(),e=setInterval(()=>{Q()},he),()=>{e!==null&&clearInterval(e)}},[r,Q]);let Ke=(0,N.useMemo)(()=>{let e=new Map;for(let t of ce)e.set(t,[]);for(let t of Ie)e.get(t.channel)?.push(t);for(let t of ce)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ie]),qe={whatsapp:`WhatsApp`,telegram:`Telegram`},Je=()=>{E(null),F(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${L?I.length:0} collapsed=${C}`),Ge()},$=1.5,Ye=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),Ge()},Xe=()=>{E(null),F(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${q?K.length:0} collapsed=${C}`),q||Z()},Ze=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Z()},Qe=e=>{F(`whatsapp`),Ue(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${Ke.get(e)?.length??0} collapsed=${C}`)},$e=(0,N.useCallback)(async e=>{if(e.resumable===!1||ke.has(e.sessionId))return;Ae(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await O(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=fe(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(x(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),G(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),G({sessionId:e.sessionId,reason:r})}finally{Ae(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[O,x,ke]),et=(0,N.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=de.length;n++){await new Promise(e=>setTimeout(e,de[n-1]));let r=await Z();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),tt=(0,N.useCallback)(async()=>{if(X)return;Fe(!0);let e=window.open(``,`_blank`);try{let t=await O(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=fe(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?et(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),G(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),G({sessionId:null,reason:n})}finally{Fe(!1)}},[O,X,et]),nt=(0,N.useCallback)(async(e,t)=>{if(e.stopPropagation(),!De.has(t.sessionId)){Oe(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await O(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),W({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),_e(e=>e.filter(e=>e.sessionId!==t.sessionId)),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),W({message:`Delete failed: ${n}`,failed:!0})}finally{Oe(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[O,De,Z]),rt=(0,N.useCallback)(async(e,t)=>{if(e.stopPropagation(),!je.has(t.sessionId)){Me(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await O(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),W({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),W({message:`Stop failed: ${n}`,failed:!0})}finally{Me(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[O,je,Z]),it=(0,N.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ne.has(t.sessionId)){Pe(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await O(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),W({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),W({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Pe(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[O,Ne,Z]);return(0,P.jsxs)(`aside`,{className:`side`,children:[(0,P.jsx)(`div`,{className:`side-new-session-row`,children:(0,P.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:tt,disabled:X,"aria-busy":X,children:[(0,P.jsx)(A,{size:14}),(0,P.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,P.jsxs)(`nav`,{className:`side-nav`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),x()},children:[(0,P.jsx)(M,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`People`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),b(),x()},children:[(0,P.jsx)(v,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`Agents`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),f(),x()},children:[(0,P.jsx)(y,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`Projects`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),h(),x()},children:[(0,P.jsx)(D,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row${j===`artefacts`?` active`:``}`,onClick:Je,children:[(0,P.jsx)(d,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row${j===`sessions`?` active`:``}`,onClick:Xe,children:[(0,P.jsx)(w,{size:20,strokeWidth:$}),(0,P.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,P.jsx)(`span`,{className:`kbd`})]}),Re&&ce.filter(e=>Ke.get(e).length>0).map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`nav-row${j===`whatsapp`&&He===e?` active`:``}`,onClick:()=>Qe(e),children:[(0,P.jsx)(se,{channel:e,size:16}),(0,P.jsx)(`span`,{className:`label`,children:qe[e]}),(0,P.jsx)(`span`,{className:`kbd`})]},e)),Be&&(0,P.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,P.jsx)(`span`,{className:`label`,children:Be})})]}),j===`artefacts`&&(0,P.jsxs)(`div`,{className:`side-list`,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:`Artefacts`}),(0,P.jsxs)(`span`,{className:`group-head-meta`,children:[(0,P.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ye,disabled:B,children:(0,P.jsx)(a,{size:12,className:B?`spinning`:void 0})}),(0,P.jsx)(`span`,{children:B?`…`:String(I.length)})]})]}),R&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:R}),L&&!R&&I.length>0&&(()=>{let e=I.filter(e=>e.kind===`agent-template`).length,t=I.length-e;return(0,P.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:I.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${H===e.key?` active`:``}`,onClick:()=>ue(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,P.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),L&&!R&&I.length===0&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),I.filter(e=>H===`all`?!0:H===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let t=e.kind===`agent-template`,n=t?v:d,r=pe(e.updatedAt),i=e.downloadPath!==null;return(0,P.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>We(e),disabled:!i,style:i?void 0:{cursor:`default`},title:i?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,P.jsx)(n,{size:14,className:`conv-icon`,"data-kind":t?`agent`:`file`,"aria-label":t?`agent template`:`file`}),(0,P.jsxs)(`span`,{className:`conv-stack`,children:[(0,P.jsx)(`span`,{className:`conv-name-line`,children:(0,P.jsx)(`span`,{className:`conv-name`,children:e.name})}),r&&(0,P.jsx)(`span`,{className:`conv-timestamp`,children:r})]}),i&&(0,P.jsx)(l,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),j===`sessions`&&(()=>{let e=K.filter(e=>xe?!0:!e.isSubagent).filter(e=>Ce?!0:!e.archived),t=K.some(e=>e.isSubagent),r=K.some(e=>e.archived);return(0,P.jsxs)(`div`,{className:`side-list`,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:`Sessions`}),(0,P.jsxs)(`span`,{className:`group-head-meta`,children:[(0,P.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Ze,disabled:ye,children:(0,P.jsx)(a,{size:12,className:ye?`spinning`:void 0})}),(0,P.jsx)(`span`,{children:ye?`…`:String(e.length)})]})]}),Te&&(0,P.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,P.jsx)(`code`,{children:Te})}),(t||r)&&(0,P.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,P.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${xe?` active`:``}`,onClick:()=>Se(e=>!e),title:xe?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),r&&(0,P.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Ce?` active`:``}`,onClick:()=>we(e=>!e),title:Ce?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),J&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:J}),q&&!J&&e.length===0&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=pe(e.startedAt),r=ke.has(e.sessionId),i=De.has(e.sessionId),a=je.has(e.sessionId),o=Ne.has(e.sessionId);return(0,P.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,P.jsxs)(`div`,{className:`conv-main-static`,children:[(0,P.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,P.jsxs)(`span`,{className:`conv-stack`,children:[(0,P.jsx)(`span`,{className:`conv-name-line`,children:(0,P.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,P.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,P.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),t&&(0,P.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,P.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,P.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,P.jsx)(w,{size:12})}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{$e(e)},disabled:r||i||a||o,"aria-busy":r,"aria-label":`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,children:(0,P.jsx)(S,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)},disabled:r||i||a||o,"aria-label":`Open session ${e.title} in admin webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,children:(0,P.jsx)(te,{size:12})})]}),e.live?(0,P.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{rt(t,e)},disabled:r||i||a||o,"aria-busy":a,"aria-label":`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,children:(0,P.jsx)(ie,{size:12})}):null,e.archived?(0,P.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{it(t,e,`unarchive`)},disabled:r||i||a||o,"aria-busy":o,"aria-label":`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,children:(0,P.jsx)(g,{size:12})}):(0,P.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{it(t,e,`archive`)},disabled:r||i||a||o,"aria-busy":o,"aria-label":`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,children:(0,P.jsx)(_,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{nt(t,e)},disabled:r||i||a||o,"aria-busy":i,"aria-label":`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,children:(0,P.jsx)(n,{size:12})})]})]},e.sessionId)})]})})(),j===`whatsapp`&&(0,P.jsxs)(`div`,{className:`side-list`,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:qe[He]}),(0,P.jsxs)(`span`,{className:`group-head-meta`,children:[(0,P.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{Q()},children:(0,P.jsx)(a,{size:12})}),(0,P.jsx)(`span`,{children:String(Ke.get(He).length)})]})]}),Ke.get(He).map(e=>{let t=pe(e.lastMessageAt);return(0,P.jsxs)(`button`,{type:`button`,className:`conv${T===e.sessionId?` active`:``}`,onClick:()=>{E(e),x()},title:e.title,children:[(0,P.jsx)(se,{channel:e.channel,size:14}),(0,P.jsxs)(`span`,{className:`conv-stack`,children:[(0,P.jsx)(`span`,{className:`conv-name-line`,children:(0,P.jsx)(`span`,{className:`conv-name`,children:e.operatorName??e.whatsappName??e.senderId??e.title})}),t&&(0,P.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]},e.sessionId)})]}),(0,P.jsx)(ge,{}),(0,P.jsxs)(`div`,{className:`side-foot`,children:[(0,P.jsx)(`div`,{className:`avatar`,children:s?(0,P.jsx)(`img`,{src:s,alt:k}):re}),(0,P.jsxs)(`div`,{className:`who`,children:[(0,P.jsx)(`span`,{className:`name`,children:k}),(0,P.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),U&&(0,P.jsx)(`div`,{className:`copy-toast${U.failed?` copy-toast-failed`:``}`,role:`status`,children:U.message}),(0,P.jsx)(le,{error:me,onClose:()=>G(null)})]})}var me=5e3,he=3e4;function ge(){let[e,t]=(0,N.useState)(null);if((0,N.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},me))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,P.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,P.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,P.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,P.jsx)(`div`,{className:`system-stats__bar`,children:(0,P.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,P.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,P.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,P.jsx)(`div`,{className:`system-stats__bar`,children:(0,P.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var G=`admin-sidebar-collapsed`,K=`admin-sidebar-drawer-open`;function _e(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(G)===`1`}catch{return!1}}function q(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(G,`1`):window.sessionStorage.removeItem(G)}catch{}}function ve(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function J(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}var Y=720;function ye(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function be(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,operatorName:null,whatsappName:null,lastMessageAt:null}}function xe(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`chat`?`/chat`:`/browser`}function Se(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,userName:s,userAvatar:c,role:l,children:u,footer:d}=e,[f,p]=(0,N.useState)(()=>_e()),[m,h]=(0,N.useState)(()=>ve()),[g,_]=(0,N.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Y}px)`).matches),[v,y]=(0,N.useState)(()=>typeof window>`u`?null:be(window.location.pathname,window.location.search)),[b]=(0,N.useState)(()=>v!==null);(0,N.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Y}px)`),t=e=>_(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let x=(0,N.useCallback)(e=>{q(e),p(e)},[]),S=(0,N.useCallback)(e=>{J(e),h(e)},[]);(0,N.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${f} drawer=${m}`)},[]),(0,N.useEffect)(()=>{typeof window>`u`||!v||(console.info(`[admin-ui] wa-hydrate route=/ sessionId=${v.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let C=(0,N.useCallback)(e=>{if(e===null){y(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=ye(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?y(e):window.location.href=n.href},[]),w=g?m:!f,T=(0,N.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=m;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),S(!e)}else{let e=f;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),x(!e)}},[f,m,x,S]),E=(0,N.useCallback)(e=>{let t=xe(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),D={collapsed:f,mobileDrawerOpen:m,sidebarOpen:w,onToggleSidebar:T,setMobileDrawerOpen:S,selectedWhatsapp:v,onClearWhatsapp:()=>y(null)};return r===`operator`?(0,P.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,P.jsx)(F,{businessName:n,variant:r,onNavigate:E,onToggleSidebar:T,sidebarOpen:w,onLogout:i,onDisconnect:a,disconnecting:o}),(0,P.jsx)(`div`,{className:`platform platform-operator`,children:typeof u==`function`?u(D):u}),d]}):(0,P.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,P.jsx)(F,{businessName:n,variant:r,onNavigate:E,onToggleSidebar:T,sidebarOpen:w,onLogout:i,onDisconnect:a,disconnecting:o}),(0,P.jsxs)(`div`,{className:`platform${m?` menu-open`:``}${f?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,P.jsx)(W,{businessName:n,cacheKey:t,role:l??null,userName:s,userAvatar:c??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>S(!1),collapsed:f,mobileDrawerOpen:m,selectedWhatsappId:v?.sessionId??null,onSelectWhatsappConversation:C,initialWhatsappSurface:b}),!g&&(0,P.jsx)(R,{}),typeof u==`function`?u(D):u]}),m&&(0,P.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>S(!1)}),d]})}export{A as a,S as c,re as i,b as l,ue as n,D as o,M as r,C as s,Se as t,h as u};