@rubytech/create-maxy-code 0.1.285 → 0.1.286

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 (73) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +2 -2
  3. package/payload/platform/plugins/docs/references/admin-ui.md +1 -1
  4. package/payload/server/public/assets/{AdminShell-DwPVr9K1.js → AdminShell-D06jh8Lz.js} +1 -1
  5. package/payload/server/public/assets/{Checkbox-BdDmGlvK.js → Checkbox-DlwyBGbH.js} +1 -1
  6. package/payload/server/public/assets/{admin-BYtGQJ0d.js → admin-sjHlmwFk.js} +1 -1
  7. package/payload/server/public/assets/{architectureDiagram-Q4EWVU46-CBx_GoUY.js → architectureDiagram-Q4EWVU46-BheZXEzK.js} +1 -1
  8. package/payload/server/public/assets/{blockDiagram-DXYQGD6D-DvWR4fpv.js → blockDiagram-DXYQGD6D-dYNElb4l.js} +1 -1
  9. package/payload/server/public/assets/{browser-2PXsTraZ.js → browser-Dx1D0tI_.js} +1 -1
  10. package/payload/server/public/assets/{c4Diagram-AHTNJAMY-BbSOxeeU.js → c4Diagram-AHTNJAMY-Q6g8vHmX.js} +1 -1
  11. package/payload/server/public/assets/channel-yIp47StE.js +1 -0
  12. package/payload/server/public/assets/{chunk-336JU56O-DJzmXTk5.js → chunk-336JU56O-D-Cn77jA.js} +2 -2
  13. package/payload/server/public/assets/{chunk-426QAEUC-BSwzskM5.js → chunk-426QAEUC-BAE0JfL6.js} +1 -1
  14. package/payload/server/public/assets/{chunk-4TB4RGXK-C-fH8BTZ.js → chunk-4TB4RGXK-BI2HTCey.js} +1 -1
  15. package/payload/server/public/assets/{chunk-5FUZZQ4R-DW-MaiGX.js → chunk-5FUZZQ4R-BsWXvze8.js} +1 -1
  16. package/payload/server/public/assets/{chunk-5PVQY5BW-DlKbwC1X.js → chunk-5PVQY5BW-DWO5wTr8.js} +1 -1
  17. package/payload/server/public/assets/{chunk-EDXVE4YY-DnkdxwAt.js → chunk-EDXVE4YY-BM4DLBML.js} +1 -1
  18. package/payload/server/public/assets/{chunk-ENJZ2VHE-BTfezWsj.js → chunk-ENJZ2VHE-aOt2Re1y.js} +1 -1
  19. package/payload/server/public/assets/{chunk-ICPOFSXX-BGg8uTtu.js → chunk-ICPOFSXX-_ioQjgQ1.js} +1 -1
  20. package/payload/server/public/assets/{chunk-OYMX7WX6-CYJInav8.js → chunk-OYMX7WX6-DkuLduF1.js} +1 -1
  21. package/payload/server/public/assets/{chunk-U2HBQHQK-B6kD6ZHU.js → chunk-U2HBQHQK-1ESGrUQ6.js} +1 -1
  22. package/payload/server/public/assets/{chunk-X2U36JSP-7tvWkjym.js → chunk-X2U36JSP-C0MUqJKJ.js} +1 -1
  23. package/payload/server/public/assets/{chunk-YZCP3GAM-D6NjOb5l.js → chunk-YZCP3GAM-BjIcv7r1.js} +1 -1
  24. package/payload/server/public/assets/{chunk-ZZ45TVLE-Dqz69eJy.js → chunk-ZZ45TVLE-LW116-Vw.js} +1 -1
  25. package/payload/server/public/assets/classDiagram-6PBFFD2Q-DGPa3QR8.js +1 -0
  26. package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-De6lAWAi.js +1 -0
  27. package/payload/server/public/assets/clone-C29IA5qA.js +1 -0
  28. package/payload/server/public/assets/{dagre-di-KHpsq.js → dagre-CxO2ywW2.js} +1 -1
  29. package/payload/server/public/assets/{dagre-KV5264BT-DswETLwm.js → dagre-KV5264BT-DcPqQxUG.js} +1 -1
  30. package/payload/server/public/assets/{data-B6vpe0Zj.js → data-Ca6hPEtp.js} +1 -1
  31. package/payload/server/public/assets/{diagram-5BDNPKRD-DWmq_Zkl.js → diagram-5BDNPKRD-B25vZ2cO.js} +1 -1
  32. package/payload/server/public/assets/{diagram-G4DWMVQ6-BVi6yjLL.js → diagram-G4DWMVQ6-p7maXzYr.js} +1 -1
  33. package/payload/server/public/assets/{diagram-MMDJMWI5-D6XKyUAT.js → diagram-MMDJMWI5-Deu8Io1I.js} +1 -1
  34. package/payload/server/public/assets/{diagram-TYMM5635-sU1d7P6W.js → diagram-TYMM5635-Cp3l9iiP.js} +1 -1
  35. package/payload/server/public/assets/{erDiagram-SMLLAGMA-CY6qPZvu.js → erDiagram-SMLLAGMA-D8_SMZL-.js} +1 -1
  36. package/payload/server/public/assets/{flowDiagram-DWJPFMVM-CE9hd869.js → flowDiagram-DWJPFMVM-pECrNCIH.js} +1 -1
  37. package/payload/server/public/assets/{ganttDiagram-T4ZO3ILL-Cbb885gt.js → ganttDiagram-T4ZO3ILL-DAbNRh0p.js} +1 -1
  38. package/payload/server/public/assets/{gitGraphDiagram-UUTBAWPF-BNzO3jBu.js → gitGraphDiagram-UUTBAWPF-CHVyAvfu.js} +1 -1
  39. package/payload/server/public/assets/{graph-DfegJdnT.js → graph-ChJs-qY8.js} +1 -1
  40. package/payload/server/public/assets/{graph-labels-BG4aqzs6.js → graph-labels-B-BTHvfh.js} +1 -1
  41. package/payload/server/public/assets/{graphlib-CIzKPoW_.js → graphlib-DS0srZLX.js} +1 -1
  42. package/payload/server/public/assets/{infoDiagram-42DDH7IO-DWGtofAT.js → infoDiagram-42DDH7IO-lioeuA4m.js} +1 -1
  43. package/payload/server/public/assets/{ishikawaDiagram-UXIWVN3A-UG1rus6G.js → ishikawaDiagram-UXIWVN3A-Dq2MKHxM.js} +1 -1
  44. package/payload/server/public/assets/{journeyDiagram-VCZTEJTY-CYhHYXmj.js → journeyDiagram-VCZTEJTY-BTC5zuDZ.js} +1 -1
  45. package/payload/server/public/assets/{kanban-definition-6JOO6SKY-CWHj9DHX.js → kanban-definition-6JOO6SKY-DQDOg3tk.js} +1 -1
  46. package/payload/server/public/assets/{line-vMN9CmXx.js → line---rBtN__.js} +1 -1
  47. package/payload/server/public/assets/{mermaid-parser.core-5X7WWCZe.js → mermaid-parser.core-BivSpldT.js} +1 -1
  48. package/payload/server/public/assets/{mermaid.core-B0zUZsT6.js → mermaid.core-2mrA7rmo.js} +3 -3
  49. package/payload/server/public/assets/{mindmap-definition-QFDTVHPH-BGr68ynR.js → mindmap-definition-QFDTVHPH-CduFYM-3.js} +1 -1
  50. package/payload/server/public/assets/{pieDiagram-DEJITSTG-Bo3zU_w2.js → pieDiagram-DEJITSTG-s68UJf6f.js} +1 -1
  51. package/payload/server/public/assets/{public-DCZ92LR9.js → public-B2WWbnkK.js} +3 -3
  52. package/payload/server/public/assets/{quadrantDiagram-34T5L4WZ-o-dLMRj-.js → quadrantDiagram-34T5L4WZ-ykHWuSCg.js} +1 -1
  53. package/payload/server/public/assets/{requirementDiagram-MS252O5E-D_O_ZclX.js → requirementDiagram-MS252O5E-DaRlmBk1.js} +1 -1
  54. package/payload/server/public/assets/{sankeyDiagram-XADWPNL6-Doz7uWIn.js → sankeyDiagram-XADWPNL6-CjSaDmJD.js} +1 -1
  55. package/payload/server/public/assets/{sequenceDiagram-FGHM5R23-r1VW_jgc.js → sequenceDiagram-FGHM5R23-DJcun441.js} +1 -1
  56. package/payload/server/public/assets/{stateDiagram-FHFEXIEX-B7O06aua.js → stateDiagram-FHFEXIEX-DMLxc8L0.js} +1 -1
  57. package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-a-wkzuCq.js +1 -0
  58. package/payload/server/public/assets/{timeline-definition-GMOUNBTQ-WS2AL0yL.js → timeline-definition-GMOUNBTQ-Ls4Sv2EN.js} +1 -1
  59. package/payload/server/public/assets/{useSelectionMode-lFraIQzT.css → useSelectionMode-BiULiLka.css} +1 -1
  60. package/payload/server/public/assets/{vennDiagram-DHZGUBPP-_-FLcVAh.js → vennDiagram-DHZGUBPP-NpboV334.js} +1 -1
  61. package/payload/server/public/assets/{wardleyDiagram-NUSXRM2D-nZ3oO0ih.js → wardleyDiagram-NUSXRM2D-s71AWI0_.js} +1 -1
  62. package/payload/server/public/assets/{xychartDiagram-5P7HB3ND-CqTdRM37.js → xychartDiagram-5P7HB3ND-DYjbwXgQ.js} +1 -1
  63. package/payload/server/public/browser.html +4 -4
  64. package/payload/server/public/data.html +5 -5
  65. package/payload/server/public/graph.html +6 -6
  66. package/payload/server/public/index.html +5 -5
  67. package/payload/server/public/public.html +4 -4
  68. package/payload/server/public/assets/channel-C4NqYS8u.js +0 -1
  69. package/payload/server/public/assets/classDiagram-6PBFFD2Q-CI3_kz04.js +0 -1
  70. package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-UP3RcKH9.js +0 -1
  71. package/payload/server/public/assets/clone-CvAPweMB.js +0 -1
  72. package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-Bo1g66pA.js +0 -1
  73. /package/payload/server/public/assets/{useSelectionMode-mzxTOyBv.js → useSelectionMode-DMNfbxHW.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubytech/create-maxy-code",
3
- "version": "0.1.285",
3
+ "version": "0.1.286",
4
4
  "description": "Install Maxy — AI for Productive People",
5
5
  "bin": {
6
6
  "create-maxy-code": "./dist/index.js"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: platform-architecture
3
3
  description: Use when grounding any documented-surface claim about what Maxy ships — plugins, skills, specialists, install/deploy flows, internals. This is the install catalogue, not evidence of what is enabled on the current account. For install state on this account, call `capabilities-here`; for documented surface, cite the `Source:` URL inline.
4
- content-hash: sha256:cc48ff74e2c0782fd1d36ad2f280495df8124e1bb5e3fff9a3d777db7c48b3de
4
+ content-hash: sha256:57caddb053d6974f88299198468d31050c72eb02f3310a04eaf2a1d81fdb444c
5
5
  brand: maxy-code
6
6
  product-name: Maxy
7
7
  ---
@@ -2444,7 +2444,7 @@ authoritative. This section names the surfaces and what backs each.
2444
2444
  | Nav rows (Chat / People / Agents / Projects / Tasks / Artefacts) | People, Agents, Tasks open the artefact-pane Graph filtered to the matching label. Chat selects the active conversation. Artefacts swaps the list to editable documents. | `graph-search.ts`, `graph-subgraph.ts`, `sidebar-artefacts.ts` |
2445
2445
  | Sessions list (Active / Archived / All) | Live row store driven by SSE; manual reconcile button on the segmented control re-fetches the full id set. | `/claude-sessions/events`, `/claude-sessions` |
2446
2446
  | Channel reader nav rows (WhatsApp / Telegram) | One conditional nav row **per interactive channel that has ≥1 admin session** (Task 738). Each row carries its brand glyph (WhatsApp `#25D366`, Telegram `#229ED9`); a channel with no admin session shows no row, and no install ever shows an always-empty "No conversations" row. The channel list loads **once on sidebar mount** (the per-channel counts must be known before the nav renders), so a failed load shows one muted, non-clickable line instead of channel rows. Clicking a channel row lists that channel's admin conversations; each conversation row shows the **operator display name** (`Person givenName familyName`, resolved server-side from `senderId`; falls back to the raw `senderId` when unbound/unresolved), with the agent session title as the hover tooltip only. | `/whatsapp-reader/conversations` |
2447
- | Channel transcript (`<Transcript>`) | Reads one session's JSONL over SSE (`/whatsapp-reader/stream`) and renders both sides plus tool calls — the turns claude.ai/code hides because channel inbound is stamped `isMeta`. The thread scrolls inside its grid cell (header/sidebar/footer fixed). The stream sends a 20 s heartbeat so an idle Cloudflare tunnel does not idle-drop, tags each frame with a byte-offset `id:`, and resumes from the client's `Last-Event-ID` on reconnect (no duplicate backlog); the client clears the "Stream disconnected" banner on reopen and latches it only on a terminal CLOSED state. | `/whatsapp-reader/stream` |
2447
+ | Channel transcript (`<Transcript>`) | Reads one session's JSONL over SSE (`/whatsapp-reader/stream`) and renders both sides plus tool calls — the turns claude.ai/code hides because channel inbound is stamped `isMeta`. Every turn shows its time-of-day (HH:MM from the turn's `ts`; a null/unparseable `ts` shows no time, never "Invalid Date"). `tool-call`/`tool-result` turns render as **collapsed cards** (chevron + label + time, default collapsed, expandable per card; one card's state never affects another) so the human↔agent text is not buried in JSON; the three conversation kinds always render in full. The thread **follows the tail**: it opens at the newest turn and pins to the bottom on each live append **only while the operator is already within 32 px of the bottom** — a scroll up suppresses the jump so reading history is never yanked. The thread scrolls inside its grid cell (header/sidebar/footer fixed). The stream sends a 20 s heartbeat so an idle Cloudflare tunnel does not idle-drop, tags each frame with a byte-offset `id:`, and resumes from the client's `Last-Event-ID` on reconnect (no duplicate backlog); the client clears the "Stream disconnected" banner on reopen and latches it only on a terminal CLOSED state. | `/whatsapp-reader/stream` |
2448
2448
  | Conversations row hover actions | Inline rename, archive, delete, JSONL view / download per row. The historical `.conversations-modal` CSS block exists in `globals.css` but is no longer mounted from any TSX — Sidebar.tsx now owns every per-row affordance directly. | `claude-sessions.ts` |
2449
2449
  | Artefacts list | Lists every `:FileArtifact` under this account's tree (`relativePath STARTS WITH 'accounts/'`, all file types, excluding the `uploads/<id>/` subtree — Task 684) plus this account's IDENTITY / SOUL / KNOWLEDGE / specialist templates. Click downloads the row's backing file (`downloadPath` → `GET /api/admin/files/download`) so the operator opens it in their local app; rows whose file is outside `DATA_ROOT` (bundled-fallback templates) show a "can't be downloaded" pill. The in-app artefact pane is dead pending removal (Task 518). | `sidebar-artefacts.ts`, `files.ts` |
2450
2450
  | System-stats widget | CPU / RAM widget at the foot of the sidebar. | `system-stats.ts` (see above) |
@@ -217,7 +217,7 @@ authoritative. This section names the surfaces and what backs each.
217
217
  | Nav rows (Chat / People / Agents / Projects / Tasks / Artefacts) | People, Agents, Tasks open the artefact-pane Graph filtered to the matching label. Chat selects the active conversation. Artefacts swaps the list to editable documents. | `graph-search.ts`, `graph-subgraph.ts`, `sidebar-artefacts.ts` |
218
218
  | Sessions list (Active / Archived / All) | Live row store driven by SSE; manual reconcile button on the segmented control re-fetches the full id set. | `/claude-sessions/events`, `/claude-sessions` |
219
219
  | Channel reader nav rows (WhatsApp / Telegram) | One conditional nav row **per interactive channel that has ≥1 admin session** (Task 738). Each row carries its brand glyph (WhatsApp `#25D366`, Telegram `#229ED9`); a channel with no admin session shows no row, and no install ever shows an always-empty "No conversations" row. The channel list loads **once on sidebar mount** (the per-channel counts must be known before the nav renders), so a failed load shows one muted, non-clickable line instead of channel rows. Clicking a channel row lists that channel's admin conversations; each conversation row shows the **operator display name** (`Person givenName familyName`, resolved server-side from `senderId`; falls back to the raw `senderId` when unbound/unresolved), with the agent session title as the hover tooltip only. | `/whatsapp-reader/conversations` |
220
- | Channel transcript (`<Transcript>`) | Reads one session's JSONL over SSE (`/whatsapp-reader/stream`) and renders both sides plus tool calls — the turns claude.ai/code hides because channel inbound is stamped `isMeta`. The thread scrolls inside its grid cell (header/sidebar/footer fixed). The stream sends a 20 s heartbeat so an idle Cloudflare tunnel does not idle-drop, tags each frame with a byte-offset `id:`, and resumes from the client's `Last-Event-ID` on reconnect (no duplicate backlog); the client clears the "Stream disconnected" banner on reopen and latches it only on a terminal CLOSED state. | `/whatsapp-reader/stream` |
220
+ | Channel transcript (`<Transcript>`) | Reads one session's JSONL over SSE (`/whatsapp-reader/stream`) and renders both sides plus tool calls — the turns claude.ai/code hides because channel inbound is stamped `isMeta`. Every turn shows its time-of-day (HH:MM from the turn's `ts`; a null/unparseable `ts` shows no time, never "Invalid Date"). `tool-call`/`tool-result` turns render as **collapsed cards** (chevron + label + time, default collapsed, expandable per card; one card's state never affects another) so the human↔agent text is not buried in JSON; the three conversation kinds always render in full. The thread **follows the tail**: it opens at the newest turn and pins to the bottom on each live append **only while the operator is already within 32 px of the bottom** — a scroll up suppresses the jump so reading history is never yanked. The thread scrolls inside its grid cell (header/sidebar/footer fixed). The stream sends a 20 s heartbeat so an idle Cloudflare tunnel does not idle-drop, tags each frame with a byte-offset `id:`, and resumes from the client's `Last-Event-ID` on reconnect (no duplicate backlog); the client clears the "Stream disconnected" banner on reopen and latches it only on a terminal CLOSED state. | `/whatsapp-reader/stream` |
221
221
  | Conversations row hover actions | Inline rename, archive, delete, JSONL view / download per row. The historical `.conversations-modal` CSS block exists in `globals.css` but is no longer mounted from any TSX — Sidebar.tsx now owns every per-row affordance directly. | `claude-sessions.ts` |
222
222
  | Artefacts list | Lists every `:FileArtifact` under this account's tree (`relativePath STARTS WITH 'accounts/'`, all file types, excluding the `uploads/<id>/` subtree — Task 684) plus this account's IDENTITY / SOUL / KNOWLEDGE / specialist templates. Click downloads the row's backing file (`downloadPath` → `GET /api/admin/files/download`) so the operator opens it in their local app; rows whose file is outside `DATA_ROOT` (bundled-fallback templates) show a "can't be downloaded" pill. The in-app artefact pane is dead pending removal (Task 518). | `sidebar-artefacts.ts`, `files.ts` |
223
223
  | System-stats widget | CPU / RAM widget at the foot of the sidebar. | `system-stats.ts` (see above) |
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CnGqDkHZ.js";import{d as t,f as n,l as r,m as i,o as a,r as o,t as s,u as c}from"./useSelectionMode-mzxTOyBv.js";var l=n(`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`}]]),u=n(`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`}]]),d=n(`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`}]]),f=n(`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`}]]),p=n(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),m=n(`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`}]]),h=n(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),g=n(`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`}]]),_=n(`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`}]]),v=n(`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`}]]),y=n(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),b=n(`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`}]]),x=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),S=n(`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`}]]),ee=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),C=n(`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`}]]),w=n(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),te=n(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),T=n(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),ne=n(`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`}]]),re=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ie=n(`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`}]]),E=n(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),D=e(i(),1),O=r(),k=`maxy-shell-side-px`;function A(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function j(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-A());return Math.min(Math.max(e,248),n)}function M(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(k);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return j(t)}catch{}return 264}function ae({targetSelector:e=`.platform`}){let t=(0,D.useRef)(null),[n,r]=(0,D.useState)(()=>M()),i=(0,D.useRef)(n);(0,D.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,D.useCallback)(()=>{r(e=>{let t=j(e);return t===e?e:t})},[]);(0,D.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(j(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(k,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=j(264);r(e);try{window.localStorage.removeItem(k)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,O.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var N=`maxy-admin-session`,oe=typeof BroadcastChannel<`u`;function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function se(e){if(!oe)return()=>{};let t=new BroadcastChannel(N),n=t=>{if(!P(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var F=`maxy-admin-session-key`;function I(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function L(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function ce(){try{return sessionStorage.getItem(F)}catch{return null}}function R(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,D.useState)(t),a=(0,D.useRef)(t);(0,D.useEffect)(()=>{a.current=r},[r]),(0,D.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,D.useState)(0);(0,D.useEffect)(()=>se(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,D.useCallback)(()=>{try{sessionStorage.removeItem(F)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,D.useCallback)(async(e,t)=>{let r=a.current,o=I(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await L(l);if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=ce();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=I(e,d),p=await fetch(f,t);return p.status===401&&(console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()),p},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var z=(0,D.createContext)(null);function le({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,D.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=I(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await L(o),c=e.slice(-8);if(s===`session-not-registered`){let a=ce();if(a&&a!==e){let e=I(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,O.jsx)(z.Provider,{value:i,children:r})}function B(){return(0,D.useContext)(z)}function ue(e){let t=B();return(0,D.useMemo)(()=>t||(async(t,n)=>fetch(e?I(t,e):t,n)),[t,e])}function V(e){let{businessName:t,onNavigate:n,onToggleSidebar:r,sidebarOpen:i,onLogout:s}=e,[l,u]=(0,D.useState)(!1),d=(0,D.useRef)(null),f=(0,D.useRef)(null),h=ue(null),[v,b]=(0,D.useState)(null),[te,T]=(0,D.useState)(!1),[re,ie]=(0,D.useState)(null),[k,A]=(0,D.useState)(null),[j,M]=(0,D.useState)(null),[ae,N]=(0,D.useState)(``);(0,D.useEffect)(()=>{N(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,D.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,D.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,D.useEffect)(()=>{l&&f.current?.focus()},[l]),(0,D.useEffect)(()=>{if(!l)return;let e=!1;return h(`/api/admin/version`).then(e=>e.json()).then(t=>{e||M(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,h]);let oe=(0,D.useCallback)(()=>{u(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),P=(0,D.useCallback)(e=>{u(!1),n(e)},[n]),se=(0,D.useCallback)(async()=>{if(v!==null){b(null),A(null);return}T(!0),ie(null);try{let e=await h(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);b((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),ie(e instanceof Error?e.message:String(e)),b([])}finally{T(!1)}},[v,h]),F=(0,D.useCallback)(e=>{A(null),b(t=>t?.filter(t=>t.slug!==e)??null),h(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[h]),I=(0,D.useCallback)(()=>{u(!1),s()},[s]),L=t||o.productName;return(0,O.jsxs)(`header`,{className:`admin-header`,children:[(0,O.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":i?`Hide sidebar`:`Show sidebar`,title:i?`Hide sidebar`:`Show sidebar`,"aria-expanded":i,onClick:r,children:i?(0,O.jsx)(C,{size:20,strokeWidth:1.5}):(0,O.jsx)(w,{size:20,strokeWidth:1.5})}),(0,O.jsxs)(`div`,{className:`chat-header-label`,children:[(0,O.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,O.jsx)(`img`,{src:a,alt:``,className:`chat-logo`})}),(0,O.jsx)(`h1`,{className:`chat-tagline`,children:L})]}),(0,O.jsxs)(`div`,{className:`chat-burger-wrap`,ref:d,children:[(0,O.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:oe,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,O.jsx)(ee,{size:20})}),l&&(0,O.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,O.jsxs)(`button`,{ref:f,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`data`),children:[(0,O.jsx)(m,{size:14}),` Data`]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`graph`),children:[(0,O.jsx)(ne,{size:14}),` Graph`]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`browser`),children:[(0,O.jsx)(_,{size:14}),` Browser`]}),(0,O.jsx)(`div`,{className:`chat-menu-divider`}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:se,children:[(0,O.jsx)(g,{size:14}),` Public`,te&&(0,O.jsx)(x,{size:12,className:`spin`})]}),v!==null&&(0,O.jsxs)(`div`,{className:`chat-menu-agents`,children:[re&&(0,O.jsx)(`span`,{className:`chat-menu-agent-error`,children:re}),v.length===0&&!re&&(0,O.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),v.map(e=>(0,O.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,O.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,O.jsxs)(`span`,{className:`agent-text`,children:[(0,O.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,O.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),k===e.slug?(0,O.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>F(e.slug),children:(0,O.jsx)(p,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>A(null),children:(0,O.jsx)(E,{size:12})})]}):(0,O.jsxs)(`span`,{className:`agent-actions`,children:[(0,O.jsx)(`a`,{href:`${ae}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>u(!1),children:(0,O.jsx)(g,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>A(e.slug),children:(0,O.jsx)(c,{size:12})})]})]},e.slug))]}),(0,O.jsx)(`div`,{className:`chat-menu-divider`}),(0,O.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,O.jsx)(y,{size:14}),(0,O.jsxs)(`span`,{className:`version-installed`,children:[j?`v${j.installed}`:`…`,j&&!j.updateAvailable&&(0,O.jsx)(`span`,{className:`version-uptodate-dot`}),j?.updateAvailable&&(0,O.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,O.jsx)(S,{size:14}),` Log out`]})]})]})]})}var de={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 fe({channel:e,size:t=16}){let n=de[e];return(0,O.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,O.jsx)(`path`,{d:n.path})})}var pe=[`whatsapp`,`telegram`];function me(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function H(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 he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var U=`auth-refresh-failed`;function ge({error:e,onClose:t}){if(!e)return null;let n=e.reason===U,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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`span`,{children:r}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,O.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function _e(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:c}=e,[l,u]=(0,D.useState)(null);if(!t)return null;let d=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),f=d.at(-1),p=f?.peak_request_pct==null?f?.context_window?Math.round((f.input_tokens+f.cache_creation_tokens+f.cache_read_tokens)/f.context_window*100):0:Math.round(f.peak_request_pct*100),m=d.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=d.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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,O.jsx)(`span`,{children:`Claude Code`}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,O.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:m>0?he(m):`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:H(a)})]}),(o||c)&&(()=>{let e=o??c??``;return(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{u(await s(e)?`copied`:`failed`),setTimeout(()=>u(null),1200)},children:l===`copied`?`copied ✓`:l===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var W=`https://claude.ai/code`,ve=[500,1e3,1500,2e3,2500,3e3,3e3];function ye(e,t,n){let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${W}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function be(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:s,onSelectProjects:p,onSelectPeople:m,onSelectTasks:_,onSelectAgents:y,onCloseMobileDrawer:x,collapsed:S,selectedWhatsappId:ee,onSelectWhatsappConversation:C}=e,w=ue(r),ne=o.productName,E=typeof a==`string`?a:a===null?`name unavailable`:n||ne,k=(E.trim().charAt(0)||`?`).toUpperCase(),[A,j]=(0,D.useState)(`sessions`),[M,ae]=(0,D.useState)([]),[N,oe]=(0,D.useState)(!1),[P,se]=(0,D.useState)(null),[F,I]=(0,D.useState)(!1),[L,ce]=(0,D.useState)(`file`),[R,z]=(0,D.useState)(null),[le,B]=(0,D.useState)(null),[V,de]=(0,D.useState)([]),[H,he]=(0,D.useState)(!1),[U,_e]=(0,D.useState)(null),[W,be]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,Se]=(0,D.useState)(!1),[Ce,we]=(0,D.useState)(null),[Te,J]=(0,D.useState)(new Set),[Ee,De]=(0,D.useState)(new Set),[Oe,ke]=(0,D.useState)(new Set),[Ae,je]=(0,D.useState)(new Set),[Y,Me]=(0,D.useState)(!1),[Ne,Pe]=(0,D.useState)([]),[Fe,Ie]=(0,D.useState)(!1),[Le,Re]=(0,D.useState)(null),[X,ze]=(0,D.useState)(`whatsapp`),Be=(0,D.useCallback)(e=>{if(x(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),z({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`),z({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}`),me(r,e.downloadPath,e.downloadRoot??`data`),z({message:`Downloading ${e.name}`,failed:!1})},[r,x]);(0,D.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>z(null),2500);return()=>clearTimeout(e)},[R]);let Ve=(0,D.useCallback)(async()=>{if(r){I(!0),se(null);try{let e=await w(`/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);se(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{I(!1)}}},[r,w]),Z=(0,D.useCallback)(async()=>{if(!r)return null;be(!0),_e(null);try{let e=await w(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return de(n),we(t.accountId??null),he(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return _e(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{be(!1)}},[r,w]),He=(0,D.useCallback)(async()=>{if(r){Re(null);try{let e=await w(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Pe((await e.json()).conversations??[]),Ie(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Re(`Couldn't load conversations: ${t}`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[r,w]);(0,D.useEffect)(()=>{!r||H||Z()},[r,H,Z]),(0,D.useEffect)(()=>{r&&He()},[r,He]);let Q=(0,D.useMemo)(()=>{let e=new Map;for(let t of pe)e.set(t,[]);for(let t of Ne)e.get(t.channel)?.push(t);for(let t of pe)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ne]),Ue={whatsapp:`WhatsApp`,telegram:`Telegram`},We=()=>{C(null),j(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${N?M.length:0} collapsed=${S}`),Ve()},$=1.5,Ge=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),Ve()},Ke=()=>{C(null),j(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${H?V.length:0} collapsed=${S}`),H||Z()},qe=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Z()},Je=e=>{j(`whatsapp`),ze(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${Q.get(e)?.length??0} collapsed=${S}`),x()},Ye=(0,D.useCallback)(async e=>{if(e.resumable===!1||Ee.has(e.sessionId))return;De(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await w(`/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=ye(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}`),B(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}`),B({sessionId:e.sessionId,reason:r})}finally{De(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[w,x,Ee]),Xe=(0,D.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=ve.length;n++){await new Promise(e=>setTimeout(e,ve[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]),Ze=(0,D.useCallback)(async()=>{if(Y)return;Me(!0);let e=window.open(``,`_blank`);try{let t=await w(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=ye(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?Xe(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}`),B(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),B({sessionId:null,reason:n})}finally{Me(!1)}},[w,Y,Xe]),Qe=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Te.has(t.sessionId)){J(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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??`?`}`),de(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}`),z({message:`Delete failed: ${n}`,failed:!0})}finally{J(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Te,Z]),$e=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Oe.has(t.sessionId)){ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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}`),z({message:`Stop failed: ${n}`,failed:!0})}finally{ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Oe,Z]),et=(0,D.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ae.has(t.sessionId)){je(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{je(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Ae,Z]);return(0,O.jsxs)(`aside`,{className:`side`,children:[(0,O.jsx)(`div`,{className:`side-new-session-row`,children:(0,O.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:Ze,disabled:Y,"aria-busy":Y,children:[(0,O.jsx)(te,{size:14}),(0,O.jsx)(`span`,{children:Y?`Spawning…`:`New session`})]})}),(0,O.jsxs)(`nav`,{className:`side-nav`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),x()},children:[(0,O.jsx)(ie,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`People`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),x()},children:[(0,O.jsx)(d,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Agents`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),p(),x()},children:[(0,O.jsx)(f,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Projects`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),x()},children:[(0,O.jsx)(b,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`artefacts`?` active`:``}`,onClick:We,children:[(0,O.jsx)(t,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`sessions`?` active`:``}`,onClick:Ke,children:[(0,O.jsx)(v,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,O.jsx)(`span`,{className:`kbd`})]}),Fe&&pe.filter(e=>Q.get(e).length>0).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`whatsapp`&&X===e?` active`:``}`,onClick:()=>Je(e),children:[(0,O.jsx)(fe,{channel:e,size:16}),(0,O.jsx)(`span`,{className:`label`,children:Ue[e]}),(0,O.jsx)(`span`,{className:`kbd`})]},e)),Le&&(0,O.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,O.jsx)(`span`,{className:`label`,children:Le})})]}),A===`artefacts`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Artefacts`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ge,disabled:F,children:(0,O.jsx)(T,{size:12,className:F?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:F?`…`:String(M.length)})]})]}),P&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:P}),N&&!P&&M.length>0&&(()=>{let e=M.filter(e=>e.kind===`agent-template`).length,t=M.length-e;return(0,O.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:M.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${L===e.key?` active`:``}`,onClick:()=>ce(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,O.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),N&&!P&&M.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),M.filter(e=>L===`all`?!0:L===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?d:t,i=Date.parse(e.updatedAt),a=Number.isFinite(i)?new Date(i).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,o=e.downloadPath!==null;return(0,O.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>Be(e),disabled:!o,style:o?void 0:{cursor:`default`},title:o?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,O.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.name})}),a&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:a})]}),o&&(0,O.jsx)(h,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),A===`sessions`&&(()=>{let e=V.filter(e=>G?!0:!e.isSubagent).filter(e=>q?!0:!e.archived),t=V.some(e=>e.isSubagent),n=V.some(e=>e.archived);return(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Sessions`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:qe,disabled:W,children:(0,O.jsx)(T,{size:12,className:W?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:W?`…`:String(e.length)})]})]}),Ce&&(0,O.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,O.jsx)(`code`,{children:Ce})}),(t||n)&&(0,O.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${G?` active`:``}`,onClick:()=>K(e=>!e),title:G?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>Se(e=>!e),title:q?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),U&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:U}),H&&!U&&e.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Date.parse(e.startedAt),n=Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,r=Ee.has(e.sessionId),i=Te.has(e.sessionId),a=Oe.has(e.sessionId),o=Ae.has(e.sessionId);return(0,O.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,O.jsxs)(`div`,{className:`conv-main-static`,children:[(0,O.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,O.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,O.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)}),n&&(0,O.jsxs)(`span`,{children:[` · `,n]})]})]})]}),(0,O.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,O.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,O.jsx)(v,{size:12})}):(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{Ye(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,O.jsx)(g,{size:12})}),e.live?(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{$e(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,O.jsx)(re,{size:12})}):null,e.archived?(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(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,O.jsx)(l,{size:12})}):(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(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,O.jsx)(u,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{Qe(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,O.jsx)(c,{size:12})})]})]},e.sessionId)})]})})(),A===`whatsapp`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:Ue[X]}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{He()},children:(0,O.jsx)(T,{size:12})}),(0,O.jsx)(`span`,{children:String(Q.get(X).length)})]})]}),Q.get(X).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`conv${ee===e.sessionId?` active`:``}`,onClick:()=>{C(e),x()},title:e.title,children:[(0,O.jsx)(fe,{channel:e.channel,size:14}),(0,O.jsx)(`span`,{className:`conv-stack`,children:(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.operatorName??e.senderId??e.title})})})]},e.sessionId))]}),(0,O.jsx)(xe,{}),(0,O.jsxs)(`div`,{className:`side-foot`,children:[(0,O.jsx)(`div`,{className:`avatar`,children:s?(0,O.jsx)(`img`,{src:s,alt:E}):k}),(0,O.jsxs)(`div`,{className:`who`,children:[(0,O.jsx)(`span`,{className:`name`,children:E}),(0,O.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),R&&(0,O.jsx)(`div`,{className:`copy-toast${R.failed?` copy-toast-failed`:``}`,role:`status`,children:R.message}),(0,O.jsx)(ge,{error:le,onClose:()=>B(null)})]})}var G=5e3;function xe(){let[e,t]=(0,D.useState)(null);if((0,D.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()},G))}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,O.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var K=`admin-sidebar-collapsed`,q=`admin-sidebar-drawer-open`;function Se(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function Ce(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}function we(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function Te(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}var J=720;function Ee(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,D.useState)(()=>Se()),[d,f]=(0,D.useState)(()=>we()),[p,m]=(0,D.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${J}px)`).matches),[h,g]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${J}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _=(0,D.useCallback)(e=>{Ce(e),u(e)},[]),v=(0,D.useCallback)(e=>{Te(e),f(e)},[]);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]);let y=p?d:!l,b=(0,D.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${J}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),v(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),_(!e)}},[l,d,_,v]),x=(0,D.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`);let t=e===`data`?`/data`:e===`graph`?`/graph`:`/browser`;window.location.href=t},[]),S={collapsed:l,mobileDrawerOpen:d,sidebarOpen:y,onToggleSidebar:b,setMobileDrawerOpen:v,selectedWhatsapp:h,onClearWhatsapp:()=>g(null)};return(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(V,{businessName:n,onNavigate:x,onToggleSidebar:b,sidebarOpen:y,onLogout:r}),(0,O.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,O.jsx)(be,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??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:()=>v(!1),collapsed:l,mobileDrawerOpen:d,selectedWhatsappId:h?.sessionId??null,onSelectWhatsappConversation:g}),typeof s==`function`?s(S):s]}),d&&(0,O.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>v(!1)}),c]})}export{ue as a,E as c,te as d,x as f,m as g,h,le as i,ne as l,g as m,_e as n,R as o,_ as p,me as r,ae as s,Ee as t,T as u};
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{d as t,f as n,l as r,m as i,o as a,r as o,t as s,u as c}from"./useSelectionMode-DMNfbxHW.js";var l=n(`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`}]]),u=n(`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`}]]),d=n(`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`}]]),f=n(`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`}]]),p=n(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),m=n(`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`}]]),h=n(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),g=n(`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`}]]),_=n(`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`}]]),v=n(`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`}]]),y=n(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),b=n(`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`}]]),x=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),S=n(`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`}]]),ee=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),C=n(`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`}]]),w=n(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),te=n(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),T=n(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),ne=n(`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`}]]),re=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ie=n(`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`}]]),E=n(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),D=e(i(),1),O=r(),k=`maxy-shell-side-px`;function A(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function j(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-A());return Math.min(Math.max(e,248),n)}function M(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(k);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return j(t)}catch{}return 264}function ae({targetSelector:e=`.platform`}){let t=(0,D.useRef)(null),[n,r]=(0,D.useState)(()=>M()),i=(0,D.useRef)(n);(0,D.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,D.useCallback)(()=>{r(e=>{let t=j(e);return t===e?e:t})},[]);(0,D.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(j(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(k,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=j(264);r(e);try{window.localStorage.removeItem(k)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,O.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var N=`maxy-admin-session`,oe=typeof BroadcastChannel<`u`;function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function se(e){if(!oe)return()=>{};let t=new BroadcastChannel(N),n=t=>{if(!P(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var F=`maxy-admin-session-key`;function I(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function L(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function ce(){try{return sessionStorage.getItem(F)}catch{return null}}function R(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,D.useState)(t),a=(0,D.useRef)(t);(0,D.useEffect)(()=>{a.current=r},[r]),(0,D.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,D.useState)(0);(0,D.useEffect)(()=>se(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,D.useCallback)(()=>{try{sessionStorage.removeItem(F)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,D.useCallback)(async(e,t)=>{let r=a.current,o=I(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await L(l);if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=ce();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=I(e,d),p=await fetch(f,t);return p.status===401&&(console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()),p},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var z=(0,D.createContext)(null);function le({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,D.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=I(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await L(o),c=e.slice(-8);if(s===`session-not-registered`){let a=ce();if(a&&a!==e){let e=I(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,O.jsx)(z.Provider,{value:i,children:r})}function B(){return(0,D.useContext)(z)}function ue(e){let t=B();return(0,D.useMemo)(()=>t||(async(t,n)=>fetch(e?I(t,e):t,n)),[t,e])}function V(e){let{businessName:t,onNavigate:n,onToggleSidebar:r,sidebarOpen:i,onLogout:s}=e,[l,u]=(0,D.useState)(!1),d=(0,D.useRef)(null),f=(0,D.useRef)(null),h=ue(null),[v,b]=(0,D.useState)(null),[te,T]=(0,D.useState)(!1),[re,ie]=(0,D.useState)(null),[k,A]=(0,D.useState)(null),[j,M]=(0,D.useState)(null),[ae,N]=(0,D.useState)(``);(0,D.useEffect)(()=>{N(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,D.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,D.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,D.useEffect)(()=>{l&&f.current?.focus()},[l]),(0,D.useEffect)(()=>{if(!l)return;let e=!1;return h(`/api/admin/version`).then(e=>e.json()).then(t=>{e||M(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,h]);let oe=(0,D.useCallback)(()=>{u(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),P=(0,D.useCallback)(e=>{u(!1),n(e)},[n]),se=(0,D.useCallback)(async()=>{if(v!==null){b(null),A(null);return}T(!0),ie(null);try{let e=await h(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);b((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),ie(e instanceof Error?e.message:String(e)),b([])}finally{T(!1)}},[v,h]),F=(0,D.useCallback)(e=>{A(null),b(t=>t?.filter(t=>t.slug!==e)??null),h(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[h]),I=(0,D.useCallback)(()=>{u(!1),s()},[s]),L=t||o.productName;return(0,O.jsxs)(`header`,{className:`admin-header`,children:[(0,O.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":i?`Hide sidebar`:`Show sidebar`,title:i?`Hide sidebar`:`Show sidebar`,"aria-expanded":i,onClick:r,children:i?(0,O.jsx)(C,{size:20,strokeWidth:1.5}):(0,O.jsx)(w,{size:20,strokeWidth:1.5})}),(0,O.jsxs)(`div`,{className:`chat-header-label`,children:[(0,O.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,O.jsx)(`img`,{src:a,alt:``,className:`chat-logo`})}),(0,O.jsx)(`h1`,{className:`chat-tagline`,children:L})]}),(0,O.jsxs)(`div`,{className:`chat-burger-wrap`,ref:d,children:[(0,O.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:oe,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,O.jsx)(ee,{size:20})}),l&&(0,O.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,O.jsxs)(`button`,{ref:f,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`data`),children:[(0,O.jsx)(m,{size:14}),` Data`]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`graph`),children:[(0,O.jsx)(ne,{size:14}),` Graph`]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>P(`browser`),children:[(0,O.jsx)(_,{size:14}),` Browser`]}),(0,O.jsx)(`div`,{className:`chat-menu-divider`}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:se,children:[(0,O.jsx)(g,{size:14}),` Public`,te&&(0,O.jsx)(x,{size:12,className:`spin`})]}),v!==null&&(0,O.jsxs)(`div`,{className:`chat-menu-agents`,children:[re&&(0,O.jsx)(`span`,{className:`chat-menu-agent-error`,children:re}),v.length===0&&!re&&(0,O.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),v.map(e=>(0,O.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,O.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,O.jsxs)(`span`,{className:`agent-text`,children:[(0,O.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,O.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),k===e.slug?(0,O.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>F(e.slug),children:(0,O.jsx)(p,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>A(null),children:(0,O.jsx)(E,{size:12})})]}):(0,O.jsxs)(`span`,{className:`agent-actions`,children:[(0,O.jsx)(`a`,{href:`${ae}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>u(!1),children:(0,O.jsx)(g,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>A(e.slug),children:(0,O.jsx)(c,{size:12})})]})]},e.slug))]}),(0,O.jsx)(`div`,{className:`chat-menu-divider`}),(0,O.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,O.jsx)(y,{size:14}),(0,O.jsxs)(`span`,{className:`version-installed`,children:[j?`v${j.installed}`:`…`,j&&!j.updateAvailable&&(0,O.jsx)(`span`,{className:`version-uptodate-dot`}),j?.updateAvailable&&(0,O.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,O.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,O.jsx)(S,{size:14}),` Log out`]})]})]})]})}var de={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 fe({channel:e,size:t=16}){let n=de[e];return(0,O.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,O.jsx)(`path`,{d:n.path})})}var pe=[`whatsapp`,`telegram`];function me(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function H(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 he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var U=`auth-refresh-failed`;function ge({error:e,onClose:t}){if(!e)return null;let n=e.reason===U,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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`span`,{children:r}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,O.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function _e(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:c}=e,[l,u]=(0,D.useState)(null);if(!t)return null;let d=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),f=d.at(-1),p=f?.peak_request_pct==null?f?.context_window?Math.round((f.input_tokens+f.cache_creation_tokens+f.cache_read_tokens)/f.context_window*100):0:Math.round(f.peak_request_pct*100),m=d.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=d.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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,O.jsx)(`span`,{children:`Claude Code`}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,O.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:m>0?he(m):`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:H(a)})]}),(o||c)&&(()=>{let e=o??c??``;return(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{u(await s(e)?`copied`:`failed`),setTimeout(()=>u(null),1200)},children:l===`copied`?`copied ✓`:l===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var W=`https://claude.ai/code`,ve=[500,1e3,1500,2e3,2500,3e3,3e3];function ye(e,t,n){let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${W}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function be(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:s,onSelectProjects:p,onSelectPeople:m,onSelectTasks:_,onSelectAgents:y,onCloseMobileDrawer:x,collapsed:S,selectedWhatsappId:ee,onSelectWhatsappConversation:C}=e,w=ue(r),ne=o.productName,E=typeof a==`string`?a:a===null?`name unavailable`:n||ne,k=(E.trim().charAt(0)||`?`).toUpperCase(),[A,j]=(0,D.useState)(`sessions`),[M,ae]=(0,D.useState)([]),[N,oe]=(0,D.useState)(!1),[P,se]=(0,D.useState)(null),[F,I]=(0,D.useState)(!1),[L,ce]=(0,D.useState)(`file`),[R,z]=(0,D.useState)(null),[le,B]=(0,D.useState)(null),[V,de]=(0,D.useState)([]),[H,he]=(0,D.useState)(!1),[U,_e]=(0,D.useState)(null),[W,be]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,Se]=(0,D.useState)(!1),[Ce,we]=(0,D.useState)(null),[Te,J]=(0,D.useState)(new Set),[Ee,De]=(0,D.useState)(new Set),[Oe,ke]=(0,D.useState)(new Set),[Ae,je]=(0,D.useState)(new Set),[Y,Me]=(0,D.useState)(!1),[Ne,Pe]=(0,D.useState)([]),[Fe,Ie]=(0,D.useState)(!1),[Le,Re]=(0,D.useState)(null),[X,ze]=(0,D.useState)(`whatsapp`),Be=(0,D.useCallback)(e=>{if(x(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),z({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`),z({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}`),me(r,e.downloadPath,e.downloadRoot??`data`),z({message:`Downloading ${e.name}`,failed:!1})},[r,x]);(0,D.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>z(null),2500);return()=>clearTimeout(e)},[R]);let Ve=(0,D.useCallback)(async()=>{if(r){I(!0),se(null);try{let e=await w(`/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);se(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{I(!1)}}},[r,w]),Z=(0,D.useCallback)(async()=>{if(!r)return null;be(!0),_e(null);try{let e=await w(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return de(n),we(t.accountId??null),he(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return _e(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{be(!1)}},[r,w]),He=(0,D.useCallback)(async()=>{if(r){Re(null);try{let e=await w(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Pe((await e.json()).conversations??[]),Ie(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Re(`Couldn't load conversations: ${t}`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[r,w]);(0,D.useEffect)(()=>{!r||H||Z()},[r,H,Z]),(0,D.useEffect)(()=>{r&&He()},[r,He]);let Q=(0,D.useMemo)(()=>{let e=new Map;for(let t of pe)e.set(t,[]);for(let t of Ne)e.get(t.channel)?.push(t);for(let t of pe)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ne]),Ue={whatsapp:`WhatsApp`,telegram:`Telegram`},We=()=>{C(null),j(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${N?M.length:0} collapsed=${S}`),Ve()},$=1.5,Ge=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),Ve()},Ke=()=>{C(null),j(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${H?V.length:0} collapsed=${S}`),H||Z()},qe=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Z()},Je=e=>{j(`whatsapp`),ze(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${Q.get(e)?.length??0} collapsed=${S}`),x()},Ye=(0,D.useCallback)(async e=>{if(e.resumable===!1||Ee.has(e.sessionId))return;De(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await w(`/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=ye(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}`),B(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}`),B({sessionId:e.sessionId,reason:r})}finally{De(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[w,x,Ee]),Xe=(0,D.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=ve.length;n++){await new Promise(e=>setTimeout(e,ve[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]),Ze=(0,D.useCallback)(async()=>{if(Y)return;Me(!0);let e=window.open(``,`_blank`);try{let t=await w(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=ye(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?Xe(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}`),B(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),B({sessionId:null,reason:n})}finally{Me(!1)}},[w,Y,Xe]),Qe=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Te.has(t.sessionId)){J(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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??`?`}`),de(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}`),z({message:`Delete failed: ${n}`,failed:!0})}finally{J(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Te,Z]),$e=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Oe.has(t.sessionId)){ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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}`),z({message:`Stop failed: ${n}`,failed:!0})}finally{ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Oe,Z]),et=(0,D.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ae.has(t.sessionId)){je(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await w(`/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`}`),z({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}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{je(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[w,Ae,Z]);return(0,O.jsxs)(`aside`,{className:`side`,children:[(0,O.jsx)(`div`,{className:`side-new-session-row`,children:(0,O.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:Ze,disabled:Y,"aria-busy":Y,children:[(0,O.jsx)(te,{size:14}),(0,O.jsx)(`span`,{children:Y?`Spawning…`:`New session`})]})}),(0,O.jsxs)(`nav`,{className:`side-nav`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),x()},children:[(0,O.jsx)(ie,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`People`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),x()},children:[(0,O.jsx)(d,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Agents`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),p(),x()},children:[(0,O.jsx)(f,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Projects`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),x()},children:[(0,O.jsx)(b,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`artefacts`?` active`:``}`,onClick:We,children:[(0,O.jsx)(t,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`sessions`?` active`:``}`,onClick:Ke,children:[(0,O.jsx)(v,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,O.jsx)(`span`,{className:`kbd`})]}),Fe&&pe.filter(e=>Q.get(e).length>0).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${A===`whatsapp`&&X===e?` active`:``}`,onClick:()=>Je(e),children:[(0,O.jsx)(fe,{channel:e,size:16}),(0,O.jsx)(`span`,{className:`label`,children:Ue[e]}),(0,O.jsx)(`span`,{className:`kbd`})]},e)),Le&&(0,O.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,O.jsx)(`span`,{className:`label`,children:Le})})]}),A===`artefacts`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Artefacts`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ge,disabled:F,children:(0,O.jsx)(T,{size:12,className:F?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:F?`…`:String(M.length)})]})]}),P&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:P}),N&&!P&&M.length>0&&(()=>{let e=M.filter(e=>e.kind===`agent-template`).length,t=M.length-e;return(0,O.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:M.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${L===e.key?` active`:``}`,onClick:()=>ce(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,O.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),N&&!P&&M.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),M.filter(e=>L===`all`?!0:L===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?d:t,i=Date.parse(e.updatedAt),a=Number.isFinite(i)?new Date(i).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,o=e.downloadPath!==null;return(0,O.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>Be(e),disabled:!o,style:o?void 0:{cursor:`default`},title:o?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,O.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.name})}),a&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:a})]}),o&&(0,O.jsx)(h,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),A===`sessions`&&(()=>{let e=V.filter(e=>G?!0:!e.isSubagent).filter(e=>q?!0:!e.archived),t=V.some(e=>e.isSubagent),n=V.some(e=>e.archived);return(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Sessions`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:qe,disabled:W,children:(0,O.jsx)(T,{size:12,className:W?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:W?`…`:String(e.length)})]})]}),Ce&&(0,O.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,O.jsx)(`code`,{children:Ce})}),(t||n)&&(0,O.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${G?` active`:``}`,onClick:()=>K(e=>!e),title:G?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>Se(e=>!e),title:q?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),U&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:U}),H&&!U&&e.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Date.parse(e.startedAt),n=Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,r=Ee.has(e.sessionId),i=Te.has(e.sessionId),a=Oe.has(e.sessionId),o=Ae.has(e.sessionId);return(0,O.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,O.jsxs)(`div`,{className:`conv-main-static`,children:[(0,O.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,O.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,O.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)}),n&&(0,O.jsxs)(`span`,{children:[` · `,n]})]})]})]}),(0,O.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,O.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,O.jsx)(v,{size:12})}):(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{Ye(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,O.jsx)(g,{size:12})}),e.live?(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{$e(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,O.jsx)(re,{size:12})}):null,e.archived?(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(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,O.jsx)(l,{size:12})}):(0,O.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(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,O.jsx)(u,{size:12})}),(0,O.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{Qe(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,O.jsx)(c,{size:12})})]})]},e.sessionId)})]})})(),A===`whatsapp`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:Ue[X]}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{He()},children:(0,O.jsx)(T,{size:12})}),(0,O.jsx)(`span`,{children:String(Q.get(X).length)})]})]}),Q.get(X).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`conv${ee===e.sessionId?` active`:``}`,onClick:()=>{C(e),x()},title:e.title,children:[(0,O.jsx)(fe,{channel:e.channel,size:14}),(0,O.jsx)(`span`,{className:`conv-stack`,children:(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.operatorName??e.senderId??e.title})})})]},e.sessionId))]}),(0,O.jsx)(xe,{}),(0,O.jsxs)(`div`,{className:`side-foot`,children:[(0,O.jsx)(`div`,{className:`avatar`,children:s?(0,O.jsx)(`img`,{src:s,alt:E}):k}),(0,O.jsxs)(`div`,{className:`who`,children:[(0,O.jsx)(`span`,{className:`name`,children:E}),(0,O.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),R&&(0,O.jsx)(`div`,{className:`copy-toast${R.failed?` copy-toast-failed`:``}`,role:`status`,children:R.message}),(0,O.jsx)(ge,{error:le,onClose:()=>B(null)})]})}var G=5e3;function xe(){let[e,t]=(0,D.useState)(null);if((0,D.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()},G))}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,O.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var K=`admin-sidebar-collapsed`,q=`admin-sidebar-drawer-open`;function Se(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function Ce(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}function we(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function Te(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}var J=720;function Ee(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,D.useState)(()=>Se()),[d,f]=(0,D.useState)(()=>we()),[p,m]=(0,D.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${J}px)`).matches),[h,g]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${J}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _=(0,D.useCallback)(e=>{Ce(e),u(e)},[]),v=(0,D.useCallback)(e=>{Te(e),f(e)},[]);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]);let y=p?d:!l,b=(0,D.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${J}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),v(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),_(!e)}},[l,d,_,v]),x=(0,D.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`);let t=e===`data`?`/data`:e===`graph`?`/graph`:`/browser`;window.location.href=t},[]),S={collapsed:l,mobileDrawerOpen:d,sidebarOpen:y,onToggleSidebar:b,setMobileDrawerOpen:v,selectedWhatsapp:h,onClearWhatsapp:()=>g(null)};return(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(V,{businessName:n,onNavigate:x,onToggleSidebar:b,sidebarOpen:y,onLogout:r}),(0,O.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,O.jsx)(be,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??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:()=>v(!1),collapsed:l,mobileDrawerOpen:d,selectedWhatsappId:h?.sessionId??null,onSelectWhatsappConversation:g}),typeof s==`function`?s(S):s]}),d&&(0,O.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>v(!1)}),c]})}export{ue as a,E as c,te as d,x as f,m as g,h,le as i,ne as l,g as m,_e as n,R as o,_ as p,me as r,ae as s,Ee as t,T as u};
@@ -1 +1 @@
1
- import{l as e}from"./useSelectionMode-mzxTOyBv.js";var t=e();function n({checked:e,onChange:n,label:r,disabled:i}){return(0,t.jsxs)(`label`,{className:`maxy-checkbox${i?` maxy-checkbox--disabled`:``}`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>n(e.target.checked),disabled:i}),(0,t.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),r&&(0,t.jsx)(`span`,{className:`maxy-checkbox__label`,children:r})]})}export{n as t};
1
+ import{l as e}from"./useSelectionMode-DMNfbxHW.js";var t=e();function n({checked:e,onChange:n,label:r,disabled:i}){return(0,t.jsxs)(`label`,{className:`maxy-checkbox${i?` maxy-checkbox--disabled`:``}`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>n(e.target.checked),disabled:i}),(0,t.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),r&&(0,t.jsx)(`span`,{className:`maxy-checkbox__label`,children:r})]})}export{n as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-mzxTOyBv.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-DwPVr9K1.js";import{t as f}from"./Checkbox-BdDmGlvK.js";var p=i(),m=e(r(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),o(`open`)},a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>{a.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${a.readyState}`),o(`error`))},()=>a.close()},[e,t,n]),{turns:r,status:a}}function O(e){return e.map((e,t)=>{switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator (web)`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Agent`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`tool-call`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-tool`,children:[(0,b.jsxs)(`span`,{className:`wa-who`,children:[`↳ `,e.name]}),(0,b.jsx)(`pre`,{className:`wa-code`,children:JSON.stringify(e.input,null,2)})]},t);case`tool-result`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-result${e.isError?` is-error`:``}`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`result`}),(0,b.jsx)(`pre`,{className:`wa-code`,children:e.text})]},t)}})}function k({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n);return(0,b.jsx)(`div`,{className:`wa-reader-thread`,children:(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),O(r)]})})}function A(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(k,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(A,{}));
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-DMNfbxHW.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-D06jh8Lz.js";import{t as f}from"./Checkbox-DlwyBGbH.js";var p=i(),m=e(r(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),o(`open`)},a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>{a.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${a.readyState}`),o(`error`))},()=>a.close()},[e,t,n]),{turns:r,status:a}}function O(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function k({label:e,ts:t}){return(0,b.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:e}),(0,b.jsx)(`time`,{className:`wa-time`,children:O(t)})]})}function A({turn:e}){let[t,n]=(0,m.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,b.jsxs)(`div`,{className:i,children:[(0,b.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,b.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,b.jsx)(`span`,{className:`wa-who`,children:a}),(0,b.jsx)(`time`,{className:`wa-time`,children:O(e.ts)})]}),t&&(0,b.jsx)(`pre`,{className:`wa-code`,children:o})]})}function j(e){return e.map((e,t)=>{switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(k,{label:`Operator`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(k,{label:`Operator (web)`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(k,{label:`Agent`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`tool-call`:case`tool-result`:return(0,b.jsx)(A,{turn:e},t)}})}function M({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n),a=(0,m.useRef)(null),o=(0,m.useRef)(!0);return(0,m.useLayoutEffect)(()=>{let e=a.current;e&&o.current&&(e.scrollTop=e.scrollHeight)},[r]),(0,b.jsx)(`div`,{className:`wa-reader-thread`,ref:a,onScroll:()=>{let e=a.current;e&&(o.current=e.scrollHeight-e.scrollTop-e.clientHeight<=32)},children:(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),j(r)]})})}function N(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(M,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(N,{}));