@rubytech/create-maxy-code 0.1.342 → 0.1.343
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.
- package/package.json +1 -1
- package/payload/platform/config/brand.json +4 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +88 -1
- package/payload/platform/plugins/cloudflare/skills/calendar-site/SKILL.md +82 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/functions/api/book.ts +112 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/public/booking.css +100 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/public/booking.js +155 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/public/index.html +47 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/schema.sql +18 -0
- package/payload/platform/plugins/cloudflare/skills/calendar-site/template/wrangler.toml +14 -0
- package/payload/platform/plugins/docs/PLUGIN.md +1 -0
- package/payload/platform/plugins/docs/references/admin-ui.md +26 -0
- package/payload/platform/plugins/docs/references/calendar-booking.md +56 -0
- package/payload/platform/plugins/scheduling/PLUGIN.md +10 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-notify.test.d.ts +2 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-notify.test.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-notify.test.js +45 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-notify.test.js.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.d.ts +2 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.js +89 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.js.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-notify.d.ts +22 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-notify.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-notify.js +31 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-notify.js.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.d.ts +28 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.js +70 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.js.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.d.ts +21 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js +280 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js.map +1 -0
- package/payload/server/{chunk-5BG6CHGH.js → chunk-QAKVFSEJ.js} +15 -0
- package/payload/server/maxy-edge.js +1 -1
- package/payload/server/public/assets/AdminLoginScreens-KVvngpT2.js +1 -0
- package/payload/server/public/assets/AdminShell-DDKZhJRo.js +1 -0
- package/payload/server/public/assets/Checkbox-BJlS0tR2.js +1 -0
- package/payload/server/public/assets/OperatorConversations-_P3_KmAW.js +1 -0
- package/payload/server/public/assets/admin-BTQWgciK.js +1 -0
- package/payload/server/public/assets/{OperatorConversations-BMIZQR9t.css → admin-auth-fetch-9JCQ2FFm.css} +1 -1
- package/payload/server/public/assets/admin-auth-fetch-BMOxrEnl.js +9 -0
- package/payload/server/public/assets/{arc-CxLB9WCE.js → arc-Crkz45LN.js} +1 -1
- package/payload/server/public/assets/architecture-YZFGNWBL-Dma4Bgha.js +1 -0
- package/payload/server/public/assets/{architectureDiagram-Q4EWVU46-D-EdJPSY.js → architectureDiagram-Q4EWVU46-C9JThHgP.js} +1 -1
- package/payload/server/public/assets/{blockDiagram-DXYQGD6D-CXx9RgCm.js → blockDiagram-DXYQGD6D-DpsV_HXT.js} +1 -1
- package/payload/server/public/assets/browser-CpOL9dN0.js +1 -0
- package/payload/server/public/assets/{c4Diagram-AHTNJAMY-RFBXEe0B.js → c4Diagram-AHTNJAMY-CTm_6aKi.js} +1 -1
- package/payload/server/public/assets/calendar-dRLyhghx.js +1 -0
- package/payload/server/public/assets/channel-B_-5bau1.js +1 -0
- package/payload/server/public/assets/chat-prZCVWvK.js +1 -0
- package/payload/server/public/assets/{chunk-2KRD3SAO-DBqAFwK9.js → chunk-2KRD3SAO-1KSJW1q6.js} +1 -1
- package/payload/server/public/assets/{chunk-336JU56O-DdnFEz6R.js → chunk-336JU56O-C3t08Ip-.js} +2 -2
- package/payload/server/public/assets/chunk-426QAEUC-Dirxdwjh.js +1 -0
- package/payload/server/public/assets/{chunk-4BX2VUAB-cnw-3Gbs.js → chunk-4BX2VUAB-kl1ze33n.js} +1 -1
- package/payload/server/public/assets/{chunk-4TB4RGXK-BnqJ0bDc.js → chunk-4TB4RGXK-DxpoDoHg.js} +1 -1
- package/payload/server/public/assets/{chunk-55IACEB6-BwyHvvzo.js → chunk-55IACEB6-WM9VJzha.js} +1 -1
- package/payload/server/public/assets/{chunk-5FUZZQ4R-DXA9U02I.js → chunk-5FUZZQ4R-CLH63ZH3.js} +1 -1
- package/payload/server/public/assets/{chunk-5PVQY5BW-D78bZ_8D.js → chunk-5PVQY5BW-DCTb8IAT.js} +1 -1
- package/payload/server/public/assets/{chunk-67CJDMHE-CtE_Mgv7.js → chunk-67CJDMHE-BSYzyaoH.js} +1 -1
- package/payload/server/public/assets/{chunk-7N4EOEYR-CUZDaySl.js → chunk-7N4EOEYR-CarJ7O2P.js} +1 -1
- package/payload/server/public/assets/{chunk-AA7GKIK3-CYQ3jO4X.js → chunk-AA7GKIK3-DTNLyBpH.js} +1 -1
- package/payload/server/public/assets/{chunk-BSJP7CBP-BbA_HyTR.js → chunk-BSJP7CBP-BFmHflHY.js} +1 -1
- package/payload/server/public/assets/{chunk-CIAEETIT-D7_YqRhG.js → chunk-CIAEETIT-BpjG0IzU.js} +1 -1
- package/payload/server/public/assets/{chunk-EDXVE4YY-B23LrtSw.js → chunk-EDXVE4YY-2fSowhlW.js} +1 -1
- package/payload/server/public/assets/{chunk-ENJZ2VHE-D3fTHYKN.js → chunk-ENJZ2VHE-ClcranGV.js} +1 -1
- package/payload/server/public/assets/{chunk-FMBD7UC4-DFAA2tyh.js → chunk-FMBD7UC4-DLq4BItQ.js} +1 -1
- package/payload/server/public/assets/{chunk-FOC6F5B3-BF4IHvlI.js → chunk-FOC6F5B3-B9QI3Guz.js} +1 -1
- package/payload/server/public/assets/{chunk-ICPOFSXX-DBUGemHy.js → chunk-ICPOFSXX-BAr-Mv1Z.js} +2 -2
- package/payload/server/public/assets/{chunk-K5T4RW27-rMMs08Eh.js → chunk-K5T4RW27-8PvAHasY.js} +1 -1
- package/payload/server/public/assets/{chunk-KGLVRYIC-BD2r8R2G.js → chunk-KGLVRYIC--aGaDRH5.js} +1 -1
- package/payload/server/public/assets/{chunk-LIHQZDEY-D4sYTTwM.js → chunk-LIHQZDEY-BrWj7mw2.js} +1 -1
- package/payload/server/public/assets/{chunk-ORNJ4GCN-CAs_uFzb.js → chunk-ORNJ4GCN-kYQmkMTi.js} +1 -1
- package/payload/server/public/assets/{chunk-OYMX7WX6-Fkp-2ORc.js → chunk-OYMX7WX6-CIsryCWH.js} +1 -1
- package/payload/server/public/assets/chunk-QZHKN3VN-Duipo1kI.js +1 -0
- package/payload/server/public/assets/{chunk-U2HBQHQK-D_pxZh25.js → chunk-U2HBQHQK-68X653e3.js} +1 -1
- package/payload/server/public/assets/{chunk-X2U36JSP-CeVmvvRf.js → chunk-X2U36JSP-v3v9soX3.js} +1 -1
- package/payload/server/public/assets/{chunk-XPW4576I-iWP54fKp.js → chunk-XPW4576I-CW5DPpop.js} +1 -1
- package/payload/server/public/assets/{chunk-YZCP3GAM-CNtbWJNN.js → chunk-YZCP3GAM-B1VP7Rl2.js} +1 -1
- package/payload/server/public/assets/{chunk-ZZ45TVLE-BmlFjU_9.js → chunk-ZZ45TVLE-DiJrujNY.js} +1 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-B3kX5SuB.js +1 -0
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-D761c7Lr.js +1 -0
- package/payload/server/public/assets/clone-BrhFv6Tb.js +1 -0
- package/payload/server/public/assets/{cose-bilkent-S5V4N54A-C7YmF1Pg.js → cose-bilkent-S5V4N54A-BscXxLMc.js} +1 -1
- package/payload/server/public/assets/{dagre-KV5264BT-Ca3ESJhc.js → dagre-KV5264BT-DVgGlTQ1.js} +1 -1
- package/payload/server/public/assets/{dagre-BAmiDDtR.js → dagre-MBv6WlCS.js} +1 -1
- package/payload/server/public/assets/data-CeUT45cU.js +1 -0
- package/payload/server/public/assets/{diagram-5BDNPKRD-BgT1ORf2.js → diagram-5BDNPKRD-BmhCaO0a.js} +1 -1
- package/payload/server/public/assets/{diagram-G4DWMVQ6-BTaUIiem.js → diagram-G4DWMVQ6-ChU9L8vz.js} +1 -1
- package/payload/server/public/assets/{diagram-MMDJMWI5-Bdb2g6Uo.js → diagram-MMDJMWI5-Oy409Zc_.js} +1 -1
- package/payload/server/public/assets/{diagram-TYMM5635-CkLGC0zZ.js → diagram-TYMM5635-Cn1YByqk.js} +1 -1
- package/payload/server/public/assets/{dist-Bkbhs3jw.js → dist-B0CkUodR.js} +1 -1
- package/payload/server/public/assets/{erDiagram-SMLLAGMA-D_sj4DMg.js → erDiagram-SMLLAGMA-e17yfLvr.js} +1 -1
- package/payload/server/public/assets/{flatten-E2Sr0FeD.js → flatten-Cl1Bc3dR.js} +1 -1
- package/payload/server/public/assets/{flowDiagram-DWJPFMVM-iLERoZTe.js → flowDiagram-DWJPFMVM-Dqt7sCVZ.js} +1 -1
- package/payload/server/public/assets/{ganttDiagram-T4ZO3ILL-D60hjMBy.js → ganttDiagram-T4ZO3ILL-B4IhwS2r.js} +1 -1
- package/payload/server/public/assets/gitGraph-7Q5UKJZL-BCQAqtLy.js +1 -0
- package/payload/server/public/assets/{gitGraphDiagram-UUTBAWPF-Di0XM6fi.js → gitGraphDiagram-UUTBAWPF-BDw-PKcI.js} +1 -1
- package/payload/server/public/assets/{graph-Bnsvbnkf.js → graph-B8h8YAJu.js} +3 -3
- package/payload/server/public/assets/graph-labels-BFrQ5kyH.js +1 -0
- package/payload/server/public/assets/{graphlib-C8fUP7uV.js → graphlib-DPIYk_sg.js} +1 -1
- package/payload/server/public/assets/info-OMHHGYJF-qU7hK50T.js +1 -0
- package/payload/server/public/assets/infoDiagram-42DDH7IO-KGdcJeTs.js +2 -0
- package/payload/server/public/assets/{isEmpty-CLz-UprQ.js → isEmpty-D1pGOD1J.js} +1 -1
- package/payload/server/public/assets/{ishikawaDiagram-UXIWVN3A-CwgI4B5Z.js → ishikawaDiagram-UXIWVN3A-BRIHsB3G.js} +1 -1
- package/payload/server/public/assets/{journeyDiagram-VCZTEJTY-CxBu-tze.js → journeyDiagram-VCZTEJTY-aKNgmoHd.js} +1 -1
- package/payload/server/public/assets/{kanban-definition-6JOO6SKY-D2qlheA5.js → kanban-definition-6JOO6SKY-cwBwT-nm.js} +1 -1
- package/payload/server/public/assets/{line-Bdod7uzQ.js → line-DVtVRzUA.js} +1 -1
- package/payload/server/public/assets/{linear-BiVe6QzC.js → linear-DtoOFPO2.js} +1 -1
- package/payload/server/public/assets/{mermaid-parser.core-xZN7hC6M.js → mermaid-parser.core-G7YD_zO3.js} +2 -2
- package/payload/server/public/assets/{mermaid.core-D0IylAac.js → mermaid.core-DpFyndHm.js} +3 -3
- package/payload/server/public/assets/{mindmap-definition-QFDTVHPH-J_Szhwf1.js → mindmap-definition-QFDTVHPH-CYXK_Pvz.js} +1 -1
- package/payload/server/public/assets/operator-D3fRwMfE.js +1 -0
- package/payload/server/public/assets/{ordinal-5RtyPJVt.js → ordinal-CBZeH4Yp.js} +1 -1
- package/payload/server/public/assets/packet-4T2RLAQJ-DiU2yS9m.js +1 -0
- package/payload/server/public/assets/page-D0hQWIIV.js +30 -0
- package/payload/server/public/assets/pie-ZZUOXDRM-zHUKKlVv.js +1 -0
- package/payload/server/public/assets/{pieDiagram-DEJITSTG-CV5DxUVx.js → pieDiagram-DEJITSTG-DFo4N6WH.js} +1 -1
- package/payload/server/public/assets/public-DX4z0sCJ.js +1 -0
- package/payload/server/public/assets/{quadrantDiagram-34T5L4WZ-BsFMVizF.js → quadrantDiagram-34T5L4WZ-BlH5iIhl.js} +1 -1
- package/payload/server/public/assets/radar-PYXPWWZC-BUnVoaPg.js +1 -0
- package/payload/server/public/assets/{reduce-B3Mw_0s1.js → reduce-PuPlFPRX.js} +1 -1
- package/payload/server/public/assets/{requirementDiagram-MS252O5E-C5eRRvGc.js → requirementDiagram-MS252O5E-D5WLty8A.js} +1 -1
- package/payload/server/public/assets/{sankeyDiagram-XADWPNL6-CJYv5gpw.js → sankeyDiagram-XADWPNL6-vB85IxHG.js} +1 -1
- package/payload/server/public/assets/{sequenceDiagram-FGHM5R23-B25563_2.js → sequenceDiagram-FGHM5R23-Cxraa0Ee.js} +1 -1
- package/payload/server/public/assets/{src-BKOAoFQc.js → src-CR_MU8uy.js} +1 -1
- package/payload/server/public/assets/{stateDiagram-FHFEXIEX-BLyNJYOA.js → stateDiagram-FHFEXIEX-BBPssYBx.js} +1 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-BWmmUwDt.js +1 -0
- package/payload/server/public/assets/{timeline-definition-GMOUNBTQ-D-HgOM6Q.js → timeline-definition-GMOUNBTQ-Bgk6PT62.js} +1 -1
- package/payload/server/public/assets/treeView-SZITEDCU-C3Y-Q52h.js +1 -0
- package/payload/server/public/assets/treemap-W4RFUUIX-Dk0qZpAg.js +1 -0
- package/payload/server/public/assets/{vennDiagram-DHZGUBPP-Cw1JElYp.js → vennDiagram-DHZGUBPP-B-APTs3L.js} +1 -1
- package/payload/server/public/assets/wardley-RL74JXVD-BAWI02OA.js +1 -0
- package/payload/server/public/assets/{wardleyDiagram-NUSXRM2D-BqMWzEko.js → wardleyDiagram-NUSXRM2D-CkXJSs_i.js} +1 -1
- package/payload/server/public/assets/{xychartDiagram-5P7HB3ND-DBp71TLT.js → xychartDiagram-5P7HB3ND-BkyshPMV.js} +1 -1
- package/payload/server/public/brand/maxy-app-icon-192.png +0 -0
- package/payload/server/public/brand/maxy-app-icon-512.png +0 -0
- package/payload/server/public/brand/maxy-app-icon-maskable-512.png +0 -0
- package/payload/server/public/browser.html +6 -5
- package/payload/server/public/calendar.html +16 -0
- package/payload/server/public/chat.html +9 -8
- package/payload/server/public/data.html +6 -5
- package/payload/server/public/graph.html +8 -7
- package/payload/server/public/index.html +9 -8
- package/payload/server/public/operator.html +11 -10
- package/payload/server/public/public.html +9 -8
- package/payload/server/server.js +598 -190
- package/payload/server/public/assets/AdminLoginScreens-Brx8CmXN.js +0 -1
- package/payload/server/public/assets/AdminShell-CHZMDX2u.js +0 -1
- package/payload/server/public/assets/Checkbox-aePjWzRH.js +0 -1
- package/payload/server/public/assets/OperatorConversations-DpjPPIOp.js +0 -9
- package/payload/server/public/assets/admin-DIDvfti6.js +0 -1
- package/payload/server/public/assets/architecture-YZFGNWBL-DN-MYxff.js +0 -1
- package/payload/server/public/assets/browser-Bp5kGgyr.js +0 -1
- package/payload/server/public/assets/channel-y27xl53N.js +0 -1
- package/payload/server/public/assets/chat-C0IWx7FL.js +0 -1
- package/payload/server/public/assets/chunk-426QAEUC-D8Iwaegm.js +0 -1
- package/payload/server/public/assets/chunk-QZHKN3VN-qHqDpwz3.js +0 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-DgVoYWhO.js +0 -1
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-C0WNP3uN.js +0 -1
- package/payload/server/public/assets/clone-D50F_pvg.js +0 -1
- package/payload/server/public/assets/data-RsMye_06.js +0 -1
- package/payload/server/public/assets/gitGraph-7Q5UKJZL-D-L2yzYf.js +0 -1
- package/payload/server/public/assets/graph-labels-jduMtwXb.js +0 -1
- package/payload/server/public/assets/info-OMHHGYJF-BQn6jndO.js +0 -1
- package/payload/server/public/assets/infoDiagram-42DDH7IO-BwMdbiXg.js +0 -2
- package/payload/server/public/assets/operator-9K-TElDd.js +0 -1
- package/payload/server/public/assets/packet-4T2RLAQJ-DmkQBx4h.js +0 -1
- package/payload/server/public/assets/page-BT9hkXHm.js +0 -30
- package/payload/server/public/assets/pie-ZZUOXDRM-DDnxYUBm.js +0 -1
- package/payload/server/public/assets/public-DvL1Zov1.js +0 -1
- package/payload/server/public/assets/radar-PYXPWWZC-7H4k0ChM.js +0 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-BSVuxZxz.js +0 -1
- package/payload/server/public/assets/treeView-SZITEDCU-BLXWTQtW.js +0 -1
- package/payload/server/public/assets/treemap-W4RFUUIX-DiePDF5d.js +0 -1
- package/payload/server/public/assets/wardley-RL74JXVD-OSUWK5LN.js +0 -1
- /package/payload/server/public/assets/{_baseFor-DVaNaTfF.js → _baseFor-brRjpUOX.js} +0 -0
- /package/payload/server/public/assets/{admin-types-CJrGd46U.js → admin-types-Dg11L4MQ.js} +0 -0
- /package/payload/server/public/assets/{array-8_H1156C.js → array-BGFCBI0e.js} +0 -0
- /package/payload/server/public/assets/{chunk-Pqm5yXtL.js → chunk-CAM3fms7.js} +0 -0
- /package/payload/server/public/assets/{cytoscape.esm-h10p_6j-.js → cytoscape.esm-TvRJ2tGX.js} +0 -0
- /package/payload/server/public/assets/{defaultLocale-pD7tFa1r.js → defaultLocale-CRZydyG6.js} +0 -0
- /package/payload/server/public/assets/{init-CwJ4b81e.js → init-B8gtcn7T.js} +0 -0
- /package/payload/server/public/assets/{katex-DJPjIBAI.js → katex-RxgSu_dy.js} +0 -0
- /package/payload/server/public/assets/{path-CK8wrAxY.js → path-DZF-JdEe.js} +0 -0
- /package/payload/server/public/assets/{preload-helper-Bf_JiD2A.js → preload-helper-CQ36nxok.js} +0 -0
- /package/payload/server/public/assets/{rough.esm-Dwml_la6.js → rough.esm-6CnTHTkH.js} +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatcher script: reconcile-bookings
|
|
3
|
+
*
|
|
4
|
+
* Self-contained, like check-due-events. Pulls accepted booking rows from each
|
|
5
|
+
* account's Cloudflare D1 `bookings` table (written by the booking site's Pages
|
|
6
|
+
* Function), writes each into Neo4j as a :Meeting so it appears on the admin
|
|
7
|
+
* calendar, links the booker as a :Person, and notifies the admin. Marks each
|
|
8
|
+
* row swept so it reconciles exactly once. Ends with the standing audit.
|
|
9
|
+
*
|
|
10
|
+
* The Pi has no running periodic surface today (the legacy cron was removed and
|
|
11
|
+
* the desktop-scheduled-task replacement is not wired), so this binary is armed
|
|
12
|
+
* by the always-running platform/ui server on an interval. A PID lock prevents
|
|
13
|
+
* overlapping runs.
|
|
14
|
+
*
|
|
15
|
+
* Observability — one [calendar-booking] line per step keyed by bookingId, plus
|
|
16
|
+
* one [calendar-reconcile] audit line per account per run.
|
|
17
|
+
*
|
|
18
|
+
* PLATFORM_ROOT=... NEO4J_URI=... node dist/scripts/reconcile-bookings.js
|
|
19
|
+
*/
|
|
20
|
+
import neo4j from "neo4j-driver";
|
|
21
|
+
import { spawnSync } from "node:child_process";
|
|
22
|
+
import { readFileSync, writeFileSync, existsSync, unlinkSync, mkdirSync, readdirSync } from "node:fs";
|
|
23
|
+
import { resolve, join } from "node:path";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { reconcileOne, auditCounts } from "../lib/booking-reconcile.js";
|
|
26
|
+
import { notifyBooking } from "../lib/booking-notify.js";
|
|
27
|
+
function resolveConfigDir() {
|
|
28
|
+
const platformRoot = process.env.PLATFORM_ROOT;
|
|
29
|
+
if (!platformRoot)
|
|
30
|
+
throw new Error("PLATFORM_ROOT environment variable is required");
|
|
31
|
+
const brandPath = resolve(platformRoot, "config", "brand.json");
|
|
32
|
+
if (!existsSync(brandPath))
|
|
33
|
+
throw new Error(`brand.json not found at ${brandPath}`);
|
|
34
|
+
const brand = JSON.parse(readFileSync(brandPath, "utf-8"));
|
|
35
|
+
if (!brand.configDir)
|
|
36
|
+
throw new Error(`brand.json at ${brandPath} is missing configDir`);
|
|
37
|
+
return brand.configDir;
|
|
38
|
+
}
|
|
39
|
+
const CONFIG_DIR = resolve(homedir(), resolveConfigDir());
|
|
40
|
+
const LOCK_FILE = resolve(CONFIG_DIR, "reconcile-bookings.lock");
|
|
41
|
+
function acquireLock() {
|
|
42
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
43
|
+
if (existsSync(LOCK_FILE)) {
|
|
44
|
+
const storedPid = readFileSync(LOCK_FILE, "utf-8").trim();
|
|
45
|
+
try {
|
|
46
|
+
process.kill(Number(storedPid), 0);
|
|
47
|
+
return false; // a run is in progress
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
unlinkSync(LOCK_FILE); // stale
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
writeFileSync(LOCK_FILE, String(process.pid));
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function releaseLock() {
|
|
57
|
+
try {
|
|
58
|
+
if (existsSync(LOCK_FILE) && readFileSync(LOCK_FILE, "utf-8").trim() === String(process.pid)) {
|
|
59
|
+
unlinkSync(LOCK_FILE);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
/* best effort */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function connectNeo4j() {
|
|
67
|
+
const platformRoot = process.env.PLATFORM_ROOT;
|
|
68
|
+
let password;
|
|
69
|
+
if (process.env.NEO4J_PASSWORD) {
|
|
70
|
+
password = process.env.NEO4J_PASSWORD;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const passwordFile = resolve(platformRoot, "config/.neo4j-password");
|
|
74
|
+
try {
|
|
75
|
+
password = readFileSync(passwordFile, "utf-8").trim();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error(`Neo4j password not found at ${passwordFile}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const uri = process.env.NEO4J_URI;
|
|
82
|
+
if (!uri)
|
|
83
|
+
throw new Error("[calendar-reconcile] NEO4J_URI unset — refusing to default");
|
|
84
|
+
const user = process.env.NEO4J_USER ?? "neo4j";
|
|
85
|
+
return neo4j.driver(uri, neo4j.auth.basic(user, password));
|
|
86
|
+
}
|
|
87
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
88
|
+
/** Read `KEY=value` pairs from a secrets env file without polluting process.env. */
|
|
89
|
+
function readEnvFile(path) {
|
|
90
|
+
const out = {};
|
|
91
|
+
if (!existsSync(path))
|
|
92
|
+
return out;
|
|
93
|
+
for (const line of readFileSync(path, "utf-8").split("\n")) {
|
|
94
|
+
const m = line.match(/^([A-Z0-9_]+)=(.*)$/);
|
|
95
|
+
if (m)
|
|
96
|
+
out[m[1]] = m[2];
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/** Run a D1 SQL statement via wrangler with the per-scope token. Returns parsed rows. */
|
|
101
|
+
function d1Query(dbName, sql, env) {
|
|
102
|
+
const res = spawnSync("wrangler", ["d1", "execute", dbName, "--remote", "--json", "--command", sql], {
|
|
103
|
+
env: { ...process.env, ...env },
|
|
104
|
+
encoding: "utf-8",
|
|
105
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
106
|
+
// Bound each call so a stalled wrangler/network cannot wedge the whole
|
|
107
|
+
// run (which would hold the PID lock and silently stall reconcile).
|
|
108
|
+
timeout: 60_000,
|
|
109
|
+
});
|
|
110
|
+
if (res.status !== 0) {
|
|
111
|
+
throw new Error(`wrangler d1 execute failed (status ${res.status}${res.signal ? `, signal ${res.signal}` : ""})`);
|
|
112
|
+
}
|
|
113
|
+
// wrangler --json prints an array of result objects, each with a `results` array.
|
|
114
|
+
const parsed = JSON.parse(res.stdout || "[]");
|
|
115
|
+
const first = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
116
|
+
return (first && Array.isArray(first.results) ? first.results : []);
|
|
117
|
+
}
|
|
118
|
+
/** Resolve an email sender from the sibling email plugin, defensively. */
|
|
119
|
+
async function resolveEmailNotify(accountId) {
|
|
120
|
+
const platformRoot = process.env.PLATFORM_ROOT;
|
|
121
|
+
const smtpPath = resolve(platformRoot, "plugins/email/mcp/dist/lib/smtp.js");
|
|
122
|
+
const credPath = resolve(platformRoot, "plugins/email/mcp/dist/lib/credentials.js");
|
|
123
|
+
if (!existsSync(smtpPath) || !existsSync(credPath))
|
|
124
|
+
return {};
|
|
125
|
+
try {
|
|
126
|
+
const smtp = await import(smtpPath);
|
|
127
|
+
const cred = await import(credPath);
|
|
128
|
+
const config = await cred.readConfig(accountId);
|
|
129
|
+
if (!config)
|
|
130
|
+
return {};
|
|
131
|
+
const password = cred.readPassword();
|
|
132
|
+
return {
|
|
133
|
+
adminEmail: config.address,
|
|
134
|
+
sendEmail: async ({ to, subject, body }) => {
|
|
135
|
+
await smtp.sendEmail(config, password, { to: [to], subject, text: body });
|
|
136
|
+
},
|
|
137
|
+
// WhatsApp notify is intentionally not wired: the platform forbids
|
|
138
|
+
// agent-initiated cold first contact, and there is no known-thread
|
|
139
|
+
// resolution in scope. Email is the reliable channel.
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
console.error(`[calendar-booking] op=notify channel=email dispatched=false reason=dispatcher-unavailable err="${err.message}"`);
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function reconcileAccount(driver, accountId, accountDir) {
|
|
148
|
+
const availPath = join(accountDir, "calendar-availability.json");
|
|
149
|
+
if (!existsSync(availPath))
|
|
150
|
+
return; // no booking site for this account
|
|
151
|
+
let avail;
|
|
152
|
+
try {
|
|
153
|
+
avail = JSON.parse(readFileSync(availPath, "utf-8"));
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
console.error(`[calendar-reconcile] account=${accountId} skip reason=bad-availability-json`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const dbName = avail.bookingDbName;
|
|
160
|
+
if (!dbName) {
|
|
161
|
+
console.error(`[calendar-reconcile] account=${accountId} skip reason=no-booking-db`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const secrets = readEnvFile(join(accountDir, "secrets", "cloudflare.env"));
|
|
165
|
+
const token = secrets.CF_PAGES_D1_TOKEN;
|
|
166
|
+
if (!token) {
|
|
167
|
+
console.error(`[calendar-reconcile] account=${accountId} skip reason=no-pages-d1-token`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const wranglerEnv = {
|
|
171
|
+
CLOUDFLARE_API_TOKEN: token,
|
|
172
|
+
...(secrets.CLOUDFLARE_ACCOUNT_ID ? { CLOUDFLARE_ACCOUNT_ID: secrets.CLOUDFLARE_ACCOUNT_ID } : {}),
|
|
173
|
+
};
|
|
174
|
+
let pending;
|
|
175
|
+
try {
|
|
176
|
+
pending = d1Query(dbName, "SELECT bookingId, slotStart, slotEnd, name, email, note FROM bookings WHERE status='accepted' AND swept=0 ORDER BY id", wranglerEnv);
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
console.error(`[calendar-reconcile] account=${accountId} d1-read-failed err="${err.message}"`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const notifyDeps = pending.length > 0 ? await resolveEmailNotify(accountId) : {};
|
|
183
|
+
for (const row of pending) {
|
|
184
|
+
const bookingId = String(row.bookingId);
|
|
185
|
+
// bookingId is written by the Pages Function as crypto.randomUUID(); a row
|
|
186
|
+
// whose id is not a UUID was not written by us, so refuse to interpolate it
|
|
187
|
+
// into the sweep statement (defence in depth against a non-parameterized id).
|
|
188
|
+
if (!UUID_RE.test(bookingId)) {
|
|
189
|
+
console.error(`[calendar-reconcile] account=${accountId} skip-row reason=non-uuid-bookingId`);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const booking = {
|
|
193
|
+
bookingId,
|
|
194
|
+
slotStart: String(row.slotStart),
|
|
195
|
+
slotEnd: String(row.slotEnd),
|
|
196
|
+
name: String(row.name),
|
|
197
|
+
email: String(row.email),
|
|
198
|
+
note: row.note == null ? undefined : String(row.note),
|
|
199
|
+
};
|
|
200
|
+
const started = Date.now();
|
|
201
|
+
console.error(`[calendar-booking] op=reconcile-claim bookingId=${booking.bookingId} accountId=${accountId}`);
|
|
202
|
+
const session = driver.session();
|
|
203
|
+
try {
|
|
204
|
+
const result = await reconcileOne(session, accountId, booking);
|
|
205
|
+
console.error(`[calendar-booking] op=meeting-write bookingId=${booking.bookingId} meetingId=${result.meetingId} created=${result.created}`);
|
|
206
|
+
// Notify only when the meeting was freshly created. An idempotent re-run
|
|
207
|
+
// (created=false, e.g. a prior pass wrote the meeting but the sweep
|
|
208
|
+
// failed) must not re-email the admin.
|
|
209
|
+
if (result.created) {
|
|
210
|
+
const notes = await notifyBooking(notifyDeps, booking);
|
|
211
|
+
for (const n of notes) {
|
|
212
|
+
console.error(`[calendar-booking] op=notify bookingId=${booking.bookingId} channel=${n.channel} dispatched=${n.dispatched}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Mark swept only after a successful meeting write, so a reconcile crash
|
|
216
|
+
// leaves the row for the next run rather than dropping it silently.
|
|
217
|
+
d1Query(dbName, `UPDATE bookings SET swept=1 WHERE bookingId='${booking.bookingId}'`, wranglerEnv);
|
|
218
|
+
console.error(`[calendar-booking] op=booked bookingId=${booking.bookingId} ms=${Date.now() - started}`);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
console.error(`[calendar-booking] op=reconcile-failed bookingId=${booking.bookingId} err="${err.message}"`);
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
await session.close();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Standing audit — covers the no-event failure no per-request line can reveal.
|
|
228
|
+
const auditSession = driver.session();
|
|
229
|
+
try {
|
|
230
|
+
let acceptedIds = [];
|
|
231
|
+
try {
|
|
232
|
+
const accepted = d1Query(dbName, "SELECT bookingId FROM bookings WHERE status='accepted'", wranglerEnv);
|
|
233
|
+
acceptedIds = accepted.map((r) => String(r.bookingId));
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
/* audit degrades to graph-only when D1 is unreachable */
|
|
237
|
+
}
|
|
238
|
+
const counts = await auditCounts(auditSession, accountId, acceptedIds);
|
|
239
|
+
console.error(`[calendar-reconcile] account=${accountId} pendingUnreconciled=${counts.pendingUnreconciled} orphanMeetings=${counts.orphanMeetings}`);
|
|
240
|
+
}
|
|
241
|
+
finally {
|
|
242
|
+
await auditSession.close();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function main() {
|
|
246
|
+
if (!acquireLock()) {
|
|
247
|
+
console.error("[calendar-reconcile] another run holds the lock — exiting");
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
let driver = null;
|
|
251
|
+
try {
|
|
252
|
+
const platformRoot = process.env.PLATFORM_ROOT;
|
|
253
|
+
const accountsDir = resolve(platformRoot, "..", "data/accounts");
|
|
254
|
+
if (!existsSync(accountsDir))
|
|
255
|
+
return;
|
|
256
|
+
const accountIds = readdirSync(accountsDir).filter((d) => existsSync(join(accountsDir, d, "account.json")));
|
|
257
|
+
if (accountIds.length === 0)
|
|
258
|
+
return;
|
|
259
|
+
driver = connectNeo4j();
|
|
260
|
+
for (const accountId of accountIds) {
|
|
261
|
+
try {
|
|
262
|
+
await reconcileAccount(driver, accountId, join(accountsDir, accountId));
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
console.error(`[calendar-reconcile] account=${accountId} run-failed err="${err.message}"`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
if (driver)
|
|
271
|
+
await driver.close();
|
|
272
|
+
releaseLock();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
main().catch((err) => {
|
|
276
|
+
console.error(`[calendar-reconcile] fatal err="${err instanceof Error ? err.message : String(err)}"`);
|
|
277
|
+
releaseLock();
|
|
278
|
+
process.exit(1);
|
|
279
|
+
});
|
|
280
|
+
//# sourceMappingURL=reconcile-bookings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile-bookings.js","sourceRoot":"","sources":["../../src/scripts/reconcile-bookings.ts"],"names":[],"mappings":"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"}
|
|
@@ -3116,6 +3116,9 @@ function renderLoginPage(opts) {
|
|
|
3116
3116
|
const tagline = opts?.tagline ?? "";
|
|
3117
3117
|
const origin = opts?.origin ?? "";
|
|
3118
3118
|
const ogCardPath = opts?.ogCardPath ?? "";
|
|
3119
|
+
const manifestPath = opts?.manifestPath ?? "";
|
|
3120
|
+
const appleTouchIconPath = opts?.appleTouchIconPath ?? "";
|
|
3121
|
+
const pwaThemeColor = opts?.themeColor ?? "";
|
|
3119
3122
|
const ogBlock = origin && ogCardPath ? [
|
|
3120
3123
|
`<meta property="og:title" content="Sign in \u2014 ${escapeHtml(productName)}">`,
|
|
3121
3124
|
`<meta property="og:description" content="${escapeHtml(tagline)}">`,
|
|
@@ -3129,6 +3132,13 @@ function renderLoginPage(opts) {
|
|
|
3129
3132
|
`<meta name="twitter:description" content="${escapeHtml(tagline)}">`,
|
|
3130
3133
|
`<meta name="twitter:image" content="${escapeHtml(origin + ogCardPath)}">`
|
|
3131
3134
|
].join("\n ") : "";
|
|
3135
|
+
const pwaInstallBlock = manifestPath && appleTouchIconPath ? [
|
|
3136
|
+
`<link rel="manifest" href="${escapeHtml(manifestPath)}">`,
|
|
3137
|
+
`<link rel="apple-touch-icon" href="${escapeHtml(appleTouchIconPath)}">`,
|
|
3138
|
+
`<meta name="mobile-web-app-capable" content="yes">`,
|
|
3139
|
+
`<meta name="apple-mobile-web-app-capable" content="yes">`,
|
|
3140
|
+
pwaThemeColor ? `<meta name="theme-color" content="${escapeHtml(pwaThemeColor)}">` : ""
|
|
3141
|
+
].filter(Boolean).join("\n ") : "";
|
|
3132
3142
|
const errorHtml = error ? `<p class="msg msg--error">${escapeHtml(error)}</p>` : "";
|
|
3133
3143
|
const changeErrorHtml = changeError ? `<p class="msg msg--error">${escapeHtml(changeError)}</p>` : "";
|
|
3134
3144
|
const successHtml = success ? `<p class="msg msg--success">${escapeHtml(success)}</p>` : "";
|
|
@@ -3164,6 +3174,7 @@ function renderLoginPage(opts) {
|
|
|
3164
3174
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
3165
3175
|
<title>Sign in \u2014 ${escapeHtml(productName)}</title>
|
|
3166
3176
|
<link rel="icon" href="${escapeHtml(faviconPath)}">
|
|
3177
|
+
${pwaInstallBlock}
|
|
3167
3178
|
${ogBlock}
|
|
3168
3179
|
${googleFontsLink}
|
|
3169
3180
|
<style>
|
|
@@ -3565,6 +3576,10 @@ var PUBLIC_ALLOWED_PREFIXES = [
|
|
|
3565
3576
|
"/api/public-reader/",
|
|
3566
3577
|
"/api/access/",
|
|
3567
3578
|
"/api/health",
|
|
3579
|
+
// Public free/busy for the booking page. Open slots only, no :Meeting detail
|
|
3580
|
+
// (server/routes/calendar-public.ts). Admitted on public hosts; on the brand
|
|
3581
|
+
// host the remote-auth gate bypasses the same path (server/index.ts).
|
|
3582
|
+
"/api/calendar/free-busy",
|
|
3568
3583
|
"/api/telegram/",
|
|
3569
3584
|
// QuickBooks OAuth consent callback. Intuit redirects the operator's browser
|
|
3570
3585
|
// here with no admin cookie; the route authenticates by validating the OAuth
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{d as t,i as n,r,s as i}from"./admin-auth-fetch-BMOxrEnl.js";import{i as a}from"./admin-types-Dg11L4MQ.js";import{g as o,u as s}from"./AdminShell-DDKZhJRo.js";import{v as c,y as l}from"./OperatorConversations-_P3_KmAW.js";import{t as u}from"./Checkbox-BJlS0tR2.js";var d=`admin-landing-redirected`,f=`/graph`;function p(e){return e.variant===`operator`?!1:e.appState===`chat`&&!e.alreadyRedirected}var m=e(t(),1);function h(e=`admin`){let[t,n]=(0,m.useState)(`loading`),[r,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,h]=(0,m.useState)(``),[g,_]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(!1),[E,D]=(0,m.useState)(null),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(void 0),[M,N]=(0,m.useState)(null),[P,F]=(0,m.useState)(void 0),[I,L]=(0,m.useState)(null),[ee,R]=(0,m.useState)(null),[z,B]=(0,m.useState)([]),[V,H]=(0,m.useState)(!1),[U,W]=(0,m.useState)(void 0),G=(0,m.useRef)(void 0),[K,q]=(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&&q(!0)}).catch(()=>{})},[]);let J=(0,m.useRef)(null),Y=(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 t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.json();D(r.session_key),R(r.sessionId??null),j(r.businessName),N(r.role??null),F(r.userName===void 0?null:r.userName),L(r.avatar??null);let i=a(r.thinkingView);return G.current=i,W(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}if(!a.claude_authenticated){n(`connect-claude`);return}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,m.useEffect)(()=>{t===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&k(e)}).catch(()=>{})},[t]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let n=!1;try{n=sessionStorage.getItem(d)===`1`}catch{}if(p({appState:t,alreadyRedirected:n,variant:e})){try{sessionStorage.setItem(d,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${f}`),window.location.replace(f)}},[t,e]);let X=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();if(t.auth_status===`dead`||t.auth_status===`missing`){n(`connect-claude`);return}}}catch{}if(E)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(E)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;if(t===`remote-auth-required`){i(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),X.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,E]),(0,m.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&n(`enter-pin`)}).catch(()=>{})},[t]);async function Z(e,t){y(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){h((await r.json().catch(()=>({}))).error||`Invalid PIN`);return}let i=await r.json();if(i.accounts&&!i.session_key){console.log(`[admin] account picker shown: userId=${i.userId} accountCount=${i.accounts.length}`),B(i.accounts),n(`account-picker`);return}D(i.session_key),R(i.sessionId??null),j(i.businessName),N(i.role??null),F(i.userName===void 0?null:i.userName),L(i.avatar??null);let o=a(i.thinkingView);if(G.current=o,W(o),t)try{sessionStorage.setItem(`maxy-account-id`,t)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,i.session_key)}catch{}s(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1),H(!1)}}let Q=(0,m.useCallback)(async e=>{if(e.preventDefault(),v)return;h(``);let t=c.trim();if(!t){h(`Please enter your name.`);return}if(r.length<4){h(`PIN must be at least 4 characters.`);return}let i=r;y(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:i,name:t})});if(!e.ok){let t=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?n(`enter-pin`):r.pin_configured?n(`connect-claude`):h(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}h(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await Z(i);return}s(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1)}},[r,v,c]),te=(0,m.useCallback)(async e=>{e.preventDefault(),h(``),await Z(r)},[r]),ne=(0,m.useCallback)(async()=>{T(!0);try{if(!await o())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}return n(`connect-claude`),!0}finally{T(!1)}},[]),$=(0,m.useCallback)(()=>{D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}s(``),h(``),n(`enter-pin`)},[]);return(0,m.useEffect)(()=>{X.current=$},[$]),{appState:t,setAppState:n,pin:r,setPin:s,operatorName:c,setOperatorName:l,pinError:u,setPinError:h,showPin:g,setShowPin:_,pinLoading:v,authPolling:b,setAuthPolling:x,authLoading:S,setAuthLoading:C,disconnecting:w,cacheKey:E,setCacheKey:D,claudeInfo:O,setClaudeInfo:k,businessName:A,role:M,userName:P,userAvatar:I,sessionId:ee,setSessionId:R,accounts:z,accountPickerLoading:V,expandAll:U,setExpandAll:W,expandAllDefaultRef:G,remoteAuthEnabled:K,pinInputRef:J,setPinFormRef:Y,handleSetPin:Q,handleLogin:te,handleAccountSelect:(0,m.useCallback)(async e=>{H(!0),h(``),await Z(r,e)},[r]),handleDisconnect:ne,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!r){h(`Enter your current PIN first.`);return}y(!0),h(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:r})});if(!e.ok){h((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}s(``),h(``),n(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),h(e instanceof Error?e.message:String(e))}finally{y(!1)}},[r])}}var g=r();function _({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,g.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,g.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 v(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:o,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:l,alt:c.productName,className:`connect-logo connect-logo--maxy`}),!c.logoContainsName&&(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,c.productName]}),(0,g.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,c.productName,` who you are, then choose a PIN.`]}),(0,g.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.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,g.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r}),(0,g.jsx)(s,{variant:`send`,type:`submit`,disabled:!t||!m.trim(),loading:a,"aria-label":`Set PIN`,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsx)(u,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`})]}),o&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:o})]})})}function y(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:o,pinInputRef:d,onSubmit:f,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,g.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,g.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:l,alt:c.productName,className:`connect-logo connect-logo--maxy`}),!c.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:c.productName}),(0,g.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,g.jsx)(s,{variant:`send`,type:`submit`,disabled:!t,loading:a,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsxs)(`div`,{className:`pin-options`,children:[(0,g.jsx)(u,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`}),(0,g.jsx)(s,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),o&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:o})]})]})}function b(e){let{accounts:t,loading:r,error:i,onSelect:a}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:l,alt:c.productName,className:`connect-logo connect-logo--maxy`}),!c.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:c.productName}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,g.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,g.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>a(e.accountId),disabled:r,type:`button`,children:[(0,g.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,g.jsx)(`span`,{className:`account-picker-role`,children:e.role}),r&&(0,g.jsx)(n,{className:`account-picker-spinner`,size:16})]},e.accountId))}),i&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:i})]})})}function x(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:i,pinError:a,setPinError:o,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function _(){h(!0),o(``);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&&o(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),o(`Could not launch browser.`)}h(!1)}async function v(){i(!0),o(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){n(!0),f(!0),i(!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}o(`Timed out waiting for sign-in. Try again.`),n(!1)}else e.error&&o(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),o(`Could not start auth flow.`)}i(!1)}async function y(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),o(``)}return t||d?(0,g.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,g.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,g.jsx)(`button`,{onClick:y,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,g.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,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,g.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,g.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,g.jsx)(`div`,{style:{marginTop:`12px`},children:(0,g.jsx)(s,{variant:`primary`,onClick:v,disabled:r,children:r?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,g.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,g.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),a&&(0,g.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:a})]}):(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsxs)(`div`,{className:`connect-logos`,children:[(0,g.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,g.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,g.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,g.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,g.jsx)(`img`,{src:l,alt:c.productName,className:`connect-logo connect-logo--maxy`}),!c.logoContainsName&&(0,g.jsx)(`span`,{className:`connect-logo-label`,children:c.productName})]})]}),(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,c.productName]}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,g.jsx)(s,{variant:`primary`,onClick:v,disabled:r,children:r?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,g.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,g.jsx)(`button`,{onClick:_,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`}),a&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:a})]})})}function S({auth:e}){return e.appState===`loading`?(0,g.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,g.jsx)(v,{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,g.jsx)(x,{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,g.jsx)(y,{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:()=>{console.info(`[admin-ui] remote-auth sign-out → /__remote-auth/logout`),window.location.href=`/__remote-auth/logout`}}):e.appState===`account-picker`?(0,g.jsx)(b,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):null}export{h as n,S as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{d as t,i as n,n as r,o as i,r as a,u as o}from"./admin-auth-fetch-BMOxrEnl.js";import{A as s,O as c,S as l,T as u,_ as d,b as f,f as p,g as m,h,j as g,k as ee,m as te,t as ne,v as re,w as _}from"./OperatorConversations-_P3_KmAW.js";async function v(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var ie=i(`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`}]]),ae=i(`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`}]]),y=i(`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`}]]),oe=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),b=i(`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`}]]),x=i(`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`}]]),se=i(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),ce=i(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),le=i(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),S=i(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ue=i(`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`}]]),C=e(t(),1),w=a(),T={sm:14,md:16,lg:18},E={sm:30,md:38,lg:46};function de({variant:e=`primary`,size:t=`md`,icon:n,iconPosition:r=`leading`,loading:i=!1,fullWidth:a=!1,disabled:o=!1,type:s=`button`,onClick:c,"aria-label":l,style:u,className:d,children:f}){let p=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,d].filter(Boolean).join(` `),m=T[t],h={...e===`send`?{width:E[t],height:E[t]}:{},...u},g=Object.keys(h).length>0;return(0,w.jsxs)(`button`,{type:s,className:p,disabled:i||o,onClick:c,"aria-label":l,style:g?h:void 0,children:[(0,w.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,w.jsx)(n,{size:m}),f,n&&r===`trailing`&&(0,w.jsx)(n,{size:m})]}),i&&(0,w.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var D=`maxy-shell-side-px`;function fe(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function O(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-fe());return Math.min(Math.max(e,248),n)}function pe(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(D);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return O(t)}catch{}return 264}function me({targetSelector:e=`.platform`}){let t=(0,C.useRef)(null),[n,r]=(0,C.useState)(()=>pe()),i=(0,C.useRef)(n);(0,C.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,C.useCallback)(()=>{r(e=>{let t=O(e);return t===e?e:t})},[]);(0,C.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(O(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(D,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=O(264);r(e);try{window.localStorage.removeItem(D)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,w.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var k=o();function he({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,children:a}){let o=(0,C.useRef)(null),[s,c]=(0,C.useState)({position:`fixed`,visibility:`hidden`}),l=(0,C.useCallback)(()=>{let t=e.current,n=o.current;if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=r.right-i.width;a<4&&(a=4);let s=window.innerHeight-r.bottom<i.height+8&&r.top>i.height+8?r.top-i.height:r.bottom;c({position:`fixed`,left:a,top:s,visibility:`visible`})},[e]);return(0,C.useLayoutEffect)(()=>{if(l(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>l());return o.current&&e.observe(o.current),()=>e.disconnect()},[l]),(0,C.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||o.current?.contains(r)||t()},i=n=>{let r=e.current;r&&n.target instanceof Node&&n.target.contains(r)&&t()},a=()=>t();return document.addEventListener(`keydown`,n),document.addEventListener(`pointerdown`,r),window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,a),()=>{document.removeEventListener(`keydown`,n),document.removeEventListener(`pointerdown`,r),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,a)}},[e,t]),(0,k.createPortal)((0,w.jsx)(`div`,{ref:o,className:n,role:r,"aria-label":i,style:s,children:a}),document.body)}function A({action:e,disabled:t,open:n,onToggle:r,onClose:i}){let a=(0,C.useRef)(null);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{ref:a,type:`button`,className:`conv-action`,onClick:r,disabled:t,"aria-haspopup":`dialog`,"aria-expanded":n,"aria-label":e.label,title:e.title,children:e.icon}),n&&(0,w.jsx)(he,{anchorRef:a,onClose:i,className:e.panelClassName,role:`dialog`,ariaLabel:e.label,children:e.panel()})]})}function ge({actions:e,disabled:t,collapsed:n}){let[r,i]=(0,C.useState)(null),[a,o]=(0,C.useState)(!1),[c,l]=(0,C.useState)(null),u=(0,C.useRef)(null);(0,C.useEffect)(()=>{i(null),o(!1),l(null)},[n]);let d=(0,C.useCallback)(()=>{o(!1),l(null)},[]);return n?(0,w.jsxs)(`div`,{className:`conv-actions`,children:[(0,w.jsx)(`button`,{ref:u,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>o(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":a,"aria-label":`Session actions`,title:`Session actions`,children:(0,w.jsx)(s,{size:12})}),a&&(0,w.jsx)(he,{anchorRef:u,onClose:d,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,w.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,w.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":c===e.key,disabled:t,onClick:()=>l(t=>t===e.key?null:e.key),children:[e.icon,(0,w.jsx)(`span`,{children:e.menuLabel})]}),c===e.key&&(0,w.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,w.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),d()},children:[e.icon,(0,w.jsx)(`span`,{children:e.menuLabel})]},e.key))})]}):(0,w.jsx)(`div`,{className:`conv-actions`,children:e.map(e=>e.panel?(0,w.jsx)(A,{action:e,disabled:t,open:r===e.key,onToggle:()=>i(t=>t===e.key?null:e.key),onClose:()=>i(null)},e.key):(0,w.jsx)(`button`,{type:`button`,className:e.danger?`conv-action conv-action-danger`:`conv-action`,onClick:e.onClick,disabled:t,"aria-busy":e.busy,"aria-label":e.label,title:e.title,children:e.icon},e.key))})}var j=`claude-opus-4-8[1m]`,M=`claude-sonnet-4-6`,N=`claude-haiku-4-5`,P={[j]:`Opus 4.8 (1M context)`,[M]:`Sonnet 4.6`,[N]:`Haiku 4.5`};function _e(e){return P[e]??e}var F=[j,M,N];function I(e){return e.replace(/\[1m\]$/,``)}function ve(e){return F.find(t=>I(t)===I(e))??e}var ye=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],L=[`low`,`medium`,`high`,`xhigh`];[...ye],[...L],[...L];var be=[j,M,N],R={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},z=ye.map(e=>({value:e,label:R[e]??e})),xe={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},B=L.map(e=>({value:e,label:xe[e]??e}));function V(e){if(e){let t=be.find(t=>I(t)===I(e));if(t)return t}return j}function Se({row:e,adminFetch:t,onError:r}){let[i,a]=(0,C.useState)(()=>V(e.model)),[o,s]=(0,C.useState)(``),[c,l]=(0,C.useState)(``),[u,d]=(0,C.useState)(!1),f=(0,C.useRef)(!1);(0,C.useEffect)(()=>{a(V(e.model))},[e.model]);let p=async()=>{if(!f.current){f.current=!0,d(!0);try{let n=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:i,...o?{permissionMode:o}:{},...c?{effort:c}:{}})});if(!n.ok){r(`Could not reset ${e.title} (status ${n.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${n.status}`),f.current=!1,d(!1);return}let a=await n.json().catch(()=>({}));a.target?window.location.assign(a.target):(r(`Reset of ${e.title} returned no target`),f.current=!1,d(!1))}catch(t){r(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),f.current=!1,d(!1)}}};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Model`}),(0,w.jsx)(`select`,{"data-kind":`model`,value:i,disabled:u,onChange:e=>a(e.target.value),children:be.map(e=>(0,w.jsx)(`option`,{value:e,children:_e(e)},e))})]}),(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Mode`}),(0,w.jsxs)(`select`,{"data-kind":`mode`,value:o,disabled:u,onChange:e=>s(e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Keep current`}),z.map(e=>(0,w.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Effort`}),(0,w.jsxs)(`select`,{"data-kind":`effort`,value:c,disabled:u,onChange:e=>l(e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Keep current`}),B.map(e=>(0,w.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,w.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:u,"aria-busy":u,onClick:()=>void p(),children:u?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(n,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}var Ce=[`whatsapp`,`telegram`];function we(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 H(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}async function Te(e){if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Ee({target:e,onConfirm:t,onCancel:n}){return e?(0,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete session`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:`Delete this conversation?`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`,e.live&&(0,w.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,w.jsx)(de,{variant:`danger`,size:`sm`,style:{flex:1},onClick:t,children:`Delete`}),(0,w.jsx)(de,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:n,children:`Cancel`})]})]})}):null}var De=`auth-refresh-failed`;function Oe({error:e,onClose:t}){if(!e)return null;let n=e.reason===De,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,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:r}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,w.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function ke(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,C.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),m=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),h=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),g=r?.account?.subscriptionType,ee=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,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,w.jsx)(`span`,{children:`Claude Code`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,w.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:ee(m.resetsAt)})]}),m.isUsingOverage&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:p>0?H(p):`—`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:we(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await Te(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var U=`https://claude.ai/code`,Ae=200,je=[500,1e3,1500,2e3,2500,3e3,3e3];function Me(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target,sameOrigin:!0};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${U}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function Ne(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function Pe(e){let{businessName:t,cacheKey:n,role:i,userName:a,userAvatar:o,onSelectProjects:s,onSelectPeople:d,onSelectTasks:ne,onSelectAgents:v,onCloseMobileDrawer:T,collapsed:E,selectedWhatsappId:de,onSelectWhatsappConversation:D,initialWhatsappSurface:fe=!1}=e,O=r(n),pe=(0,C.useCallback)(e=>({key:`reseat`,label:`Reset session ${e.title} (model, mode, effort)`,menuLabel:`Reset`,title:`Reset — move this session onto a chosen model, mode, and effort`,icon:(0,w.jsx)(le,{size:12}),panelClassName:`reseat-panel`,panel:()=>(0,w.jsx)(Se,{row:e,adminFetch:O,onError:e=>z({message:e,failed:!0})})}),[O]),me=re.productName,k=typeof a==`string`?a:a===null?`name unavailable`:t||me,he=(k.trim().charAt(0)||`?`).toUpperCase(),[A,j]=(0,C.useState)(fe?`whatsapp`:`sessions`),[M,N]=(0,C.useState)([]),[P,_e]=(0,C.useState)(!1),[F,I]=(0,C.useState)(null),[ve,ye]=(0,C.useState)(!1),[L,be]=(0,C.useState)(`file`),[R,z]=(0,C.useState)(null),[xe,B]=(0,C.useState)(null),[V,we]=(0,C.useState)([]),[H,Te]=(0,C.useState)(!1),[De,ke]=(0,C.useState)(null),[U,Pe]=(0,C.useState)(!1),[W,G]=(0,C.useState)(!1),[K,Re]=(0,C.useState)(!1),[q,ze]=(0,C.useState)(null),[J,Be]=(0,C.useState)([]),[Y,Ve]=(0,C.useState)(null),[He,Ue]=(0,C.useState)(new Set),[We,Ge]=(0,C.useState)(null),[Ke,qe]=(0,C.useState)(new Set),[Je,Ye]=(0,C.useState)(new Set),[Xe,Ze]=(0,C.useState)(new Set),[Qe,$e]=(0,C.useState)(null),[et,X]=(0,C.useState)(``),[tt,nt]=(0,C.useState)(!1),[Z,rt]=(0,C.useState)(!1),it=(0,C.useRef)(null),at=(0,C.useRef)(0),[ot,st]=(0,C.useState)(0);(0,C.useEffect)(()=>{let e=it.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.width??0;st(e=>Math.abs(e-t)<1?e:t)});return t.observe(e),()=>t.disconnect()},[A]);let ct=ot>0&&ot<400,[lt,ut]=(0,C.useState)([]),[dt,ft]=(0,C.useState)(!1),[pt,mt]=(0,C.useState)(null),[ht,gt]=(0,C.useState)(`whatsapp`),_t=(0,C.useCallback)(e=>{if(T(),!n){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}`),p(n,e.downloadPath,e.downloadRoot??`data`),z({message:`Downloading ${e.name}`,failed:!1})},[n,T]);(0,C.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>z(null),2500);return()=>clearTimeout(e)},[R]);let vt=(0,C.useCallback)(async()=>{if(n){ye(!0),I(null);try{let e=await O(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);N((await e.json()).artefacts??[]),_e(!0)}catch(e){let t=e instanceof Error?e.message:String(e);I(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ye(!1)}}},[n,O]),Q=(0,C.useCallback)(async()=>{if(!n)return null;let e=++at.current;Pe(!0),ke(null);try{let t=await O(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===at.current?(we(r),ze(n.accountId??null),Be(n.accounts??[]),Ve(e=>e??n.accountId??null),Te(!0),r):(console.info(`[admin-ui] sidebar-sessions-stale-response-dropped token=${e}`),r)}catch(t){let n=t instanceof Error?t.message:String(t);return e===at.current&&ke(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===at.current&&Pe(!1)}},[n,O]),yt=(0,C.useCallback)(async()=>{if(n){mt(null);try{let e=await O(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);ut((await e.json()).conversations??[]),ft(!0)}catch(e){let t=e instanceof Error?e.message:String(e);mt(`Couldn't load conversations.`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[n,O]);(0,C.useEffect)(()=>{!n||H||Q()},[n,H,Q]),(0,C.useEffect)(()=>{if(!n)return;let e=null;return yt(),e=setInterval(()=>{yt()},Fe),()=>{e!==null&&clearInterval(e)}},[n,yt]),(0,C.useEffect)(()=>{if(!n)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Q()}function r(){e===null&&(e=setInterval(t,Ie))}function i(){e!==null&&(clearInterval(e),e=null)}function a(){document.hidden?i():(t(),r())}return document.hidden||r(),document.addEventListener(`visibilitychange`,a),()=>{i(),document.removeEventListener(`visibilitychange`,a)}},[n,Q]);let bt=(0,C.useMemo)(()=>{let e=new Map;for(let t of Ce)e.set(t,[]);for(let t of lt)e.get(t.channel)?.push(t);for(let t of Ce)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[lt]),xt={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`},St=()=>{D(null),j(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${P?M.length:0} collapsed=${E}`),vt()},$=1.5,Ct=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),vt()},wt=()=>{D(null),j(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${H?V.length:0} collapsed=${E}`),H||Q()},Tt=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Q()},Et=e=>{j(`whatsapp`),gt(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${bt.get(e)?.length??0} collapsed=${E}`)},Dt=(0,C.useCallback)(async e=>{if(Ke.has(e.sessionId))return;qe(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await O(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId,...e.accountId?{targetAccountId:e.accountId}:{}})}),r=await n.json().catch(()=>({})),i=Me(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`?(T(),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{qe(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[O,T,Ke]),Ot=(0,C.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=je.length;n++){await new Promise(e=>setTimeout(e,je[n-1]));let r=await Q();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}`)},[Q]),kt=(0,C.useCallback)(async()=>{if(!Z){rt(!0);try{let e=await O(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(J.length>1&&Y?{targetAccountId:Y}:{})}),t=await e.json().catch(()=>({})),n=Me(e.ok,e.status,t);console.info(`[admin-ui] sidebar-new-session-spawned status=${e.status} outcome=${n.kind} slug=${t.slug??t.bridgeSessionId??`none`}`),n.kind===`navigate`?n.sameOrigin?window.location.assign(n.url):(window.open(n.url,`_blank`),t.sessionId?Ot(t.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(console.error(`[admin-ui] sidebar-new-session-failed status=${e.status} reason=${n.reason}`),B(n))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),B({sessionId:null,reason:t})}finally{rt(!1)}}},[O,Z,Ot,Y,J]),At=(0,C.useCallback)((e,t)=>{e.stopPropagation(),Ge(t)},[]),jt=(0,C.useCallback)(async e=>{if(!He.has(e.sessionId)){Ue(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await O(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),z({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0});return}let n=await t.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),we(t=>t.filter(t=>t.sessionId!==e.sessionId)),Q()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),z({message:`Delete failed: ${n}`,failed:!0})}finally{Ue(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}}},[O,He,Q]),Mt=(0,C.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Je.has(t.sessionId)){Ye(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await O(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),z({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Q()}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{Ye(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[O,Je,Q]),Nt=(0,C.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Xe.has(t.sessionId)){Ze(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await O(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Q()}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{Ze(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[O,Xe,Q]),Pt=(0,C.useCallback)(async e=>{let t=et.trim();if(!t){z({message:`Title can’t be empty`,failed:!0});return}if(t.length>Ae){z({message:`Title too long (max ${Ae})`,failed:!0});return}nt(!0);try{let n=await O(`/api/admin/session-rename`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,title:t})});if(!n.ok){let t=await n.json().catch(()=>({})),r=t.reason??t.error??`status ${n.status}`;console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${r}`),z({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),$e(null),X(``),Q()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${n}`),z({message:`Rename failed: ${n}`,failed:!0})}finally{nt(!1)}},[O,et,Q]);return(0,w.jsxs)(`aside`,{className:`side`,children:[(0,w.jsx)(`div`,{className:`side-new-session-row`,children:(0,w.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:kt,disabled:Z,"aria-busy":Z,children:[(0,w.jsx)(ce,{size:14}),(0,w.jsx)(`span`,{children:Z?`Spawning…`:`New session`})]})}),(0,w.jsxs)(`nav`,{className:`side-nav`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),d(),T()},children:[(0,w.jsx)(ue,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:`People`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),v(),T()},children:[(0,w.jsx)(y,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:`Agents`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),s(),T()},children:[(0,w.jsx)(oe,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:f().term}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),ne(),T()},children:[(0,w.jsx)(x,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${A===`artefacts`?` active`:``}`,onClick:St,children:[(0,w.jsx)(c,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${A===`sessions`?` active`:``}`,onClick:wt,children:[(0,w.jsx)(b,{size:20,strokeWidth:$}),(0,w.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,w.jsx)(`span`,{className:`kbd`})]}),dt&&Ce.filter(e=>bt.get(e).length>0).map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${A===`whatsapp`&&ht===e?` active`:``}`,onClick:()=>Et(e),children:[(0,w.jsx)(h,{channel:e,size:16}),(0,w.jsx)(`span`,{className:`label`,children:xt[e]}),(0,w.jsx)(`span`,{className:`kbd`})]},e)),pt&&(0,w.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,w.jsx)(`span`,{className:`label`,children:pt})})]}),A===`artefacts`&&(0,w.jsxs)(`div`,{className:`side-list`,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:`Artefacts`}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ct,disabled:ve,children:(0,w.jsx)(_,{size:12,className:ve?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:ve?`…`:String(M.length)})]})]}),F&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:F}),P&&!F&&M.length>0&&(()=>{let e=M.filter(e=>e.kind===`agent-template`).length,t=M.length-e;return(0,w.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,w.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${L===e.key?` active`:``}`,onClick:()=>be(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,w.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),P&&!F&&M.length===0&&(0,w.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 t=e.kind===`agent-template`,n=t?y:c,r=Ne(e.updatedAt),i=e.downloadPath!==null;return(0,w.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>_t(e),disabled:!i,style:i?void 0:{cursor:`default`},title:i?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,w.jsx)(n,{size:14,className:`conv-icon`,"data-kind":t?`agent`:`file`,"aria-label":t?`agent template`:`file`}),(0,w.jsxs)(`span`,{className:`conv-stack`,children:[(0,w.jsx)(`span`,{className:`conv-name-line`,children:(0,w.jsx)(`span`,{className:`conv-name`,children:e.name})}),r&&(0,w.jsx)(`span`,{className:`conv-timestamp`,children:r})]}),i&&(0,w.jsx)(g,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),A===`sessions`&&(()=>{let e=J.find(e=>e.isHouse)?.accountId??q,t=J.length>1,n=V.filter(e=>W?!0:!e.isSubagent).filter(e=>K?!0:!e.archived).filter(n=>!t||!Y?!0:(n.accountId??e)===Y),r=V.some(e=>e.isSubagent),i=V.some(e=>e.archived);return(0,w.jsxs)(`div`,{className:`side-list`,ref:it,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:`Sessions`}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Tt,disabled:U,children:(0,w.jsx)(_,{size:12,className:U?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:U?`…`:String(n.length)})]})]}),t&&(0,w.jsxs)(`div`,{className:`side-account-switcher`,children:[(0,w.jsx)(ue,{size:12,"aria-hidden":`true`}),(0,w.jsx)(`select`,{"aria-label":`Active account`,title:`The active account. A new session spawns under it, and the list below is scoped to it.`,value:Y??``,onChange:e=>Ve(e.target.value||null),children:J.map(e=>(0,w.jsxs)(`option`,{value:e.accountId,children:[e.businessName||(e.isHouse?`House`:`Client`),` · `,e.accountId.slice(0,8)]},e.accountId))})]}),q&&(0,w.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,w.jsx)(`code`,{children:q})}),(r||i)&&(0,w.jsxs)(`div`,{className:`artefact-filter-chips`,children:[r&&(0,w.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${W?` active`:``}`,"aria-pressed":W,onClick:()=>G(e=>!e),title:W?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),i&&(0,w.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${K?` active`:``}`,"aria-pressed":K,onClick:()=>Re(e=>!e),title:K?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),De&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:De}),H&&!De&&n.length===0&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),n.map(e=>{let t=Ne(e.startedAt),n=Ke.has(e.sessionId),r=He.has(e.sessionId),i=Je.has(e.sessionId),a=Xe.has(e.sessionId),o=n||r||i||a,s=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,menuLabel:`Resume in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,w.jsx)(ee,{size:12}),busy:n,onClick:()=>{Dt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,w.jsx)(se,{size:12}),onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,w.jsx)(S,{size:12}),busy:i,onClick:t=>{Mt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,w.jsx)(ie,{size:12}),busy:a,onClick:t=>{Nt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,w.jsx)(ae,{size:12}),busy:a,onClick:t=>{Nt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,w.jsx)(u,{size:12}),busy:tt&&Qe===e.sessionId,onClick:t=>{t.stopPropagation(),$e(e.sessionId),X(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,w.jsx)(l,{size:12}),danger:!0,busy:r,onClick:t=>{At(t,e)}},pe({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})];return(0,w.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,w.jsxs)(`div`,{className:`conv-main-static`,children:[(0,w.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,w.jsxs)(`span`,{className:`conv-stack`,children:[(0,w.jsxs)(`span`,{className:`conv-name-line`,children:[e.channel&&(0,w.jsx)(m,{channel:e.channel,size:13}),Qe===e.sessionId?(0,w.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,value:et,disabled:tt,"aria-label":`New title for session ${e.title}`,onChange:e=>X(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),Pt(e)):t.key===`Escape`&&(t.preventDefault(),$e(null),X(``))},onBlur:()=>{Qe===e.sessionId&&!tt&&($e(null),X(``))}}):(0,w.jsx)(`span`,{className:`conv-name`,title:e.personName??e.title,children:e.personName??e.title})]}),(0,w.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,w.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),t&&(0,w.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,w.jsx)(ge,{actions:s,disabled:o,collapsed:ct})]},e.sessionId)})]})})(),A===`whatsapp`&&(0,w.jsxs)(`div`,{className:`side-list`,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:xt[ht]}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{yt()},children:(0,w.jsx)(_,{size:12})}),(0,w.jsx)(`span`,{children:String(bt.get(ht).length)})]})]}),bt.get(ht).map(e=>{let t=Ne(e.lastMessageAt);return(0,w.jsxs)(`div`,{className:`conv conv-with-actions${de===e.sessionId?` active`:``}`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`conv-main-static conv-main-btn`,onClick:()=>{D(e),T()},title:e.title,children:[(0,w.jsx)(h,{channel:e.channel,size:14}),(0,w.jsxs)(`span`,{className:`conv-stack`,children:[(0,w.jsxs)(`span`,{className:`conv-name-line`,children:[(0,w.jsx)(`span`,{className:`conv-name`,children:te(e)}),e.role===`public`&&(0,w.jsx)(`span`,{className:`conv-tag conv-tag-public`,children:`Public`})]}),t&&(0,w.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]}),(0,w.jsx)(ge,{actions:[pe({sessionId:e.sessionId,model:e.model,title:e.title})],disabled:!1,collapsed:ct})]},e.sessionId)})]}),(0,w.jsx)(Le,{}),(0,w.jsxs)(`div`,{className:`side-foot`,children:[(0,w.jsx)(`div`,{className:`avatar`,children:o?(0,w.jsx)(`img`,{src:o,alt:k}):he}),(0,w.jsxs)(`div`,{className:`who`,children:[(0,w.jsx)(`span`,{className:`name`,children:k}),(0,w.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),R&&(0,w.jsx)(`div`,{className:`copy-toast${R.failed?` copy-toast-failed`:``}`,role:`status`,children:R.message}),(0,w.jsx)(Oe,{error:xe,onClose:()=>B(null)}),(0,w.jsx)(Ee,{target:We,onCancel:()=>Ge(null),onConfirm:()=>{let e=We;Ge(null),e&&jt(e)}})]})}var W=5e3,Fe=3e4,Ie=3e4;function Le(){let[e,t]=(0,C.useState)(null);if((0,C.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()},W))}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,w.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,w.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,w.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,w.jsx)(`div`,{className:`system-stats__bar`,children:(0,w.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,w.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,w.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,w.jsx)(`div`,{className:`system-stats__bar`,children:(0,w.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var G=`admin-sidebar-collapsed`,K=`admin-sidebar-drawer-open`;function Re(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(G)===`1`}catch{return!1}}function q(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(G,`1`):window.sessionStorage.removeItem(G)}catch{}}function ze(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function J(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}var Be=720;function Y(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function Ve(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`admin`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1,model:null}}function He(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`chat`?`/chat`:`/browser`}function Ue(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,userName:s,userAvatar:c,role:l,children:u,footer:p}=e,[m,h]=(0,C.useState)(()=>Re()),[g,ee]=(0,C.useState)(()=>ze()),[te,re]=(0,C.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Be}px)`).matches),[_,v]=(0,C.useState)(()=>typeof window>`u`?null:Ve(window.location.pathname,window.location.search)),[ie]=(0,C.useState)(()=>_!==null);(0,C.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Be}px)`),t=e=>re(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let ae=(0,C.useCallback)(e=>{q(e),h(e)},[]),y=(0,C.useCallback)(e=>{J(e),ee(e)},[]);(0,C.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${m} drawer=${g}`)},[]),(0,C.useEffect)(()=>{typeof window>`u`||!_||(console.info(`[admin-ui] wa-hydrate route=/ sessionId=${_.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let oe=(0,C.useCallback)(e=>{if(e===null){v(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Y(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?v(e):window.location.href=n.href},[]),b=te?g:!m,x=(0,C.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Be}px)`).matches){let e=g;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),y(!e)}else{let e=m;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),ae(!e)}},[m,g,ae,y]),se=(0,C.useCallback)(e=>{let t=He(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),[ce,le]=(0,C.useState)(`chat`),[S,ue]=(0,C.useState)([]);(0,C.useEffect)(()=>{if(r!==`operator`||!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||ue(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[r,t]);let T=(0,C.useMemo)(()=>[...new Set(S.map(e=>e.channel))],[S]),E={collapsed:m,mobileDrawerOpen:g,sidebarOpen:b,onToggleSidebar:x,setMobileDrawerOpen:y,selectedWhatsapp:_,onClearWhatsapp:()=>v(null)};return r===`operator`?(0,w.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,w.jsx)(d,{businessName:n,variant:r,onNavigate:se,conversationsCount:S.length,conversationsChannels:T,onOpenConversations:()=>le(`conversations`),onToggleSidebar:x,sidebarOpen:b,onLogout:i,onDisconnect:a,disconnecting:o}),(0,w.jsx)(`div`,{className:`platform platform-operator`,children:ce===`conversations`?(0,w.jsx)(ne,{conversations:S,sessionKey:t??``,onBack:()=>le(`chat`)}):typeof u==`function`?u(E):u}),p]}):(0,w.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,w.jsx)(d,{businessName:n,variant:r,onNavigate:se,onToggleSidebar:x,sidebarOpen:b,onLogout:i,onDisconnect:a,disconnecting:o}),(0,w.jsxs)(`div`,{className:`platform${g?` menu-open`:``}${m?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,w.jsx)(Pe,{businessName:n,cacheKey:t,role:l??null,userName:s,userAvatar:c??null,onSelectProjects:()=>{window.location.href=`/graph?label=${f().label}`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>y(!1),collapsed:m,mobileDrawerOpen:g,selectedWhatsappId:_?.sessionId??null,onSelectWhatsappConversation:oe,initialWhatsappSurface:ie}),!te&&(0,w.jsx)(me,{}),typeof u==`function`?u(E):u]}),g&&(0,w.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>y(!1)}),p]})}export{N as a,ve as c,ue as d,le as f,v as g,y as h,Te as i,_e as l,x as m,Me as n,j as o,ce as p,ke as r,M as s,Ue as t,de as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./admin-auth-fetch-BMOxrEnl.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{a as t,d as n,i as r,n as i,o as a,r as o}from"./admin-auth-fetch-BMOxrEnl.js";var s=a(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),c=a(`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`}]]),l=a(`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`}]]),u=a(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),d=a(`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`}]]),f=a(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),p=a(`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`}]]),m=a(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),h=a(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),ee=a(`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`}]]),g=a(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),_=a(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),v=a(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),y=a(`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`}]]),te=a(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),b=a(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),x=a(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),S=a(`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`}]]),C=a(`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`}]]),w=a(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),T=a(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ne=a(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),E=a(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),D={label:`Project`,term:`Projects`},O={productName:`Maxy`,hostname:`maxy`,marketingUrl:`https://getmaxy.com`,logo:`/brand/maxy-monochrome.png`,icon:`/brand/maxy-monochrome.png`,logoContainsName:!1,primaryContainer:D},k=typeof window<`u`&&window.__BRAND__||O,A={...k,primaryContainer:k.primaryContainer??D};function j(){return(typeof window<`u`?window.__BRAND__?.primaryContainer:void 0)??D}var M=A.logo,re=A.icon;A.marketingUrl,A.marketingUrl.replace(/^https?:\/\//,``).replace(/\/$/,``);var N=e(n(),1),P=o();function F(e){let{businessName:t,variant:n=`admin`,onNavigate:a,conversationsCount:o=0,conversationsChannels:l,onOpenConversations:u,onToggleSidebar:f,sidebarOpen:_,onLogout:b,onDisconnect:x,disconnecting:S}=e,[T,D]=(0,N.useState)(!1),O=(0,N.useRef)(null),k=(0,N.useRef)(null),j=i(null),[M,F]=(0,N.useState)(null),[ie,I]=(0,N.useState)(!1),[L,R]=(0,N.useState)(null),[ae,z]=(0,N.useState)(null),[oe,B]=(0,N.useState)(!1),[V,H]=(0,N.useState)(null),[U,se]=(0,N.useState)(null),[ce,W]=(0,N.useState)(``);(0,N.useEffect)(()=>{W(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,N.useEffect)(()=>{if(!T)return;let e=e=>{O.current&&!O.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[T]),(0,N.useEffect)(()=>{if(!T)return;let e=e=>{e.key===`Escape`&&D(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[T]),(0,N.useEffect)(()=>{T&&k.current?.focus()},[T]),(0,N.useEffect)(()=>{if(!T||n!==`admin`)return;let e=!1;return j(`/api/admin/version`).then(e=>e.json()).then(t=>{e||se(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[T,n,j]);let G=(0,N.useCallback)(()=>{D(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t&&n===`operator`&&console.info(`[operator-ui] op=conversations-menu present=${o>0} channels=[${(l??[]).join(`,`)}] count=${o}`),t})},[n,o,l]),K=(0,N.useCallback)(e=>{D(!1),a(e)},[a]),q=(0,N.useCallback)(async()=>{if(M!==null){F(null),z(null);return}I(!0),R(null);try{let e=await j(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);F((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),R(e instanceof Error?e.message:String(e)),F([])}finally{I(!1)}},[M,j]),J=(0,N.useCallback)(e=>{z(null),F(t=>t?.filter(t=>t.slug!==e)??null),j(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[j]),le=(0,N.useCallback)(()=>{D(!1),b()},[b]),ue=(0,N.useCallback)(async()=>{H(null),await x()?(B(!1),D(!1)):H(`Disconnect failed — credentials still present. Try again.`)},[x]),Y=t||A.productName;return(0,P.jsxs)(`header`,{className:`admin-header`,children:[n===`admin`?(0,P.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":_?`Hide sidebar`:`Show sidebar`,title:_?`Hide sidebar`:`Show sidebar`,"aria-expanded":_,onClick:f,children:_?(0,P.jsx)(y,{size:20,strokeWidth:1.5}):(0,P.jsx)(te,{size:20,strokeWidth:1.5})}):(0,P.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,P.jsx)(`img`,{src:re,alt:``,className:`chat-logo`})}),n===`admin`?(0,P.jsxs)(`div`,{className:`chat-header-label`,children:[(0,P.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,P.jsx)(`img`,{src:re,alt:``,className:`chat-logo`})}),(0,P.jsx)(`h1`,{className:`chat-tagline`,children:Y})]}):(0,P.jsx)(`h1`,{className:`chat-tagline`,children:Y}),(0,P.jsxs)(`div`,{className:`chat-burger-wrap`,ref:O,children:[(0,P.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:G,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":T,children:(0,P.jsx)(g,{size:20})}),T&&(0,P.jsxs)(`div`,{className:`admin-menu${n===`operator`?` admin-menu-operator`:``}`,role:`menu`,children:[n===`admin`&&(0,P.jsxs)(`button`,{ref:k,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`dashboard`),children:[(0,P.jsx)(h,{size:14}),` Dashboard`]}),n===`operator`&&(0,P.jsxs)(`button`,{ref:k,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`chat`),children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),n===`operator`&&o>0&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>{D(!1),u?.()},children:[(0,P.jsx)(v,{size:14}),` Conversations`]}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`data`),children:[(0,P.jsx)(c,{size:14}),` Data`]}),n===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`graph`),children:[(0,P.jsx)(C,{size:14}),` Graph`]}),n===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`browser`),children:[(0,P.jsx)(p,{size:14}),` Browser`]}),n===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`chat`),children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),n===`admin`&&(0,P.jsx)(`div`,{className:`chat-menu-divider`}),n===`admin`&&(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:q,children:[(0,P.jsx)(d,{size:14}),` Public`,ie&&(0,P.jsx)(r,{size:12,className:`spin`})]}),n===`admin`&&M!==null&&(0,P.jsxs)(`div`,{className:`chat-menu-agents`,children:[L&&(0,P.jsx)(`span`,{className:`chat-menu-agent-error`,children:L}),M.length===0&&!L&&(0,P.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),M.map(e=>(0,P.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,P.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,P.jsxs)(`span`,{className:`agent-text`,children:[(0,P.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,P.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),ae===e.slug?(0,P.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>J(e.slug),children:(0,P.jsx)(s,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>z(null),children:(0,P.jsx)(E,{size:12})})]}):(0,P.jsxs)(`span`,{className:`agent-actions`,children:[(0,P.jsx)(`a`,{href:`${ce}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>D(!1),children:(0,P.jsx)(d,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>z(e.slug),children:(0,P.jsx)(w,{size:12})})]})]},e.slug))]}),n===`admin`&&(0,P.jsx)(`div`,{className:`chat-menu-divider`}),n===`admin`&&(0,P.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,P.jsx)(m,{size:14}),(0,P.jsxs)(`span`,{className:`version-installed`,children:[U?`v${U.installed}`:`…`,U&&!U.updateAvailable&&(0,P.jsx)(`span`,{className:`version-uptodate-dot`}),U?.updateAvailable&&(0,P.jsx)(`span`,{className:`version-update-dot`})]})]}),n===`admin`&&(oe?(0,P.jsxs)(`div`,{className:`chat-menu-item chat-menu-disconnect`,children:[(0,P.jsx)(`span`,{children:`Disconnect Claude?`}),(0,P.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm disconnect`,disabled:S,onClick:ue,children:S?(0,P.jsx)(r,{size:12,className:`spin`}):(0,P.jsx)(s,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel disconnect`,disabled:S,onClick:()=>{B(!1),H(null)},children:(0,P.jsx)(E,{size:12})})]})]}):(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item chat-menu-disconnect`,role:`menuitem`,onClick:()=>{H(null),B(!0)},children:[(0,P.jsx)(ne,{size:14}),` Disconnect Claude`]})),n===`admin`&&V&&(0,P.jsx)(`span`,{className:`chat-menu-agent-error`,children:V}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:le,children:[(0,P.jsx)(ee,{size:14}),` Log out`]})]})]})]})}var ie={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 I({channel:e,size:t=16}){let n=ie[e];return(0,P.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:n.fill,role:`img`,"aria-label":n.label,className:`channel-icon`,children:(0,P.jsx)(`path`,{d:n.path})})}var L={whatsapp:`whatsapp`,telegram:`telegram`};function R({channel:e,size:t=13}){let n=L[e];return n?(0,P.jsx)(I,{channel:n,size:t}):e===`webchat`?(0,P.jsx)(p,{size:t,className:`channel-icon`,role:`img`,"aria-label":`Web chat`,style:{color:`var(--text-tertiary)`}}):(0,P.jsx)(_,{size:t,className:`channel-icon`,role:`img`,"aria-label":e,style:{color:`var(--text-tertiary)`}})}var ae=[`whatsapp`,`telegram`,`webchat`],z={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function oe(e){return ae.map(t=>({channel:t,label:z[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function B(e){let t=e.operatorName??e.whatsappName;return t?e.senderId?`${t} ${e.senderId}`:t:e.senderId??e.title}function V(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,t){let n=new URLSearchParams;n.set(`session_key`,e);for(let e of t)n.append(`path`,e);let r=document.createElement(`a`);r.href=`/api/admin/files/download-zip?${n.toString()}`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove()}function U(e,t,n=`data`){return`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&disposition=inline`+(n===`data`?``:`&root=${encodeURIComponent(n)}`)}var se={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},ce={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function W(e,t=`admin`){return t===`public`?ce[e]:se[e]}function G(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}function K(e,t,n,r=`/api/whatsapp-reader/stream`,i=e){let[a,o]=(0,N.useState)([]),[s,c]=(0,N.useState)(`open`),[l,u]=(0,N.useState)(null),d=(0,N.useRef)([]);return(0,N.useEffect)(()=>{d.current=a},[a]),(0,N.useEffect)(()=>{o([]),d.current=[],u(null)},[i,t,n,r]),(0,N.useEffect)(()=>{c(`open`);let i=d.current.slice(),a=i.map(q),s=0,l=i.length>0,f=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,p=new EventSource(f);return p.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),c(`open`)},p.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(l){if(s<a.length&&q(t)===a[s]){s+=1;return}l=!1}o(e=>[...e,t])},p.addEventListener(`activity`,e=>{try{u(JSON.parse(e.data))}catch{}}),p.addEventListener(`activity-clear`,()=>u(null)),p.onerror=()=>{p.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${p.readyState}`),c(`error`))},()=>p.close()},[e,t,n,r,i]),{turns:a,status:s,subagentActivity:l}}function q(e){return JSON.stringify(e)}var J=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function le(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:J(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:J(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function ue(e,t,n=!0){let[r,i]=(0,N.useState)([]);return(0,N.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var Y=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`]);function X(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function Z(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var de=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],fe=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Q(e){let t=String(e.getMonth()+1).padStart(2,`0`),n=String(e.getDate()).padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function pe(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:Q(t)}function me(e,t=new Date){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Q(n);if(r===Q(t))return`Today`;let i=new Date(t);return i.setDate(i.getDate()-1),r===Q(i)?`Yesterday`:`${de[n.getDay()]} ${n.getDate()} ${fe[n.getMonth()]} ${n.getFullYear()}`}function he(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function ge({ts:e}){return(0,P.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,P.jsx)(`span`,{className:`day-divider-label`,children:me(e)})})}function $({label:e,ts:t}){return(0,P.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,P.jsx)(`span`,{className:`wa-who`,children:e}),(0,P.jsx)(`time`,{className:`wa-time`,children:X(t)})]})}function _e({turn:e}){let[t,n]=(0,N.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,P.jsxs)(`div`,{className:i,children:[(0,P.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,P.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,P.jsx)(`span`,{className:`wa-who`,children:a}),(0,P.jsx)(`time`,{className:`wa-time`,children:X(e.ts)})]}),t&&(0,P.jsx)(`pre`,{className:`wa-code`,children:o})]})}function ve({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,N.useState)(!1),[a,o]=(0,N.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/whatsapp-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,P.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,P.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,P.jsx)(`time`,{className:`wa-time`,children:X(e.ts)})]}),r&&(0,P.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function ye(e,t){switch(e.kind){case`operator-inbound`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,P.jsx)($,{label:`Operator${G(e.source)}`,ts:e.ts}),(0,P.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,P.jsx)($,{label:`Operator (web)`,ts:e.ts}),(0,P.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,P.jsx)($,{label:`Agent`,ts:e.ts}),(0,P.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,P.jsx)($,{label:`Agent`,ts:e.ts}),(0,P.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,P.jsx)($,{label:`Agent`,ts:e.ts}),(0,P.jsxs)(`p`,{className:`wa-doc`,children:[(0,P.jsx)(b,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(Z).join(`, `)]}),e.caption&&(0,P.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,P.jsx)($,{label:`Agent`,ts:e.ts}),(0,P.jsxs)(`p`,{className:`wa-doc`,children:[(0,P.jsx)(b,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent file(s): `,e.files.map(Z).join(`, `)]}),e.caption&&(0,P.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`tool-call`:case`tool-result`:return(0,P.jsx)(_e,{turn:e},t);case`agent-error`:return(0,P.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,P.jsx)($,{label:`Agent`,ts:e.ts}),(0,P.jsx)(`p`,{className:`wa-body wa-error-body`,children:W(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,P.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function be(e,t,n){let r=[],i=null;return e.forEach((e,a)=>{let o=he(e),s=pe(o);s!==null&&s!==i&&(r.push((0,P.jsx)(ge,{ts:o},`day-${a}`)),i=s),r.push(e.kind===`turn`?ye(e.turn,a):(0,P.jsx)(ve,{entry:e.entry,sessionId:t,sessionKey:n},a))}),r}var xe=`maxy:whatsapp-reader:clean-view`;function Se(e){return e.filter(e=>e.kind===`turn`&&Y.has(e.turn.kind))}function Ce({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=be,cleanViewToggle:i=!1,clean:a,onToggleClean:o,forceDeliveredOnly:s=!1,streamEndpoint:c=`/api/whatsapp-reader/stream`,suppressDirectives:l=!1,tail:u=null,resetKey:d,onTurnsChange:f,onUserMessagesChange:p,onActivityChange:m}){let{turns:h,status:ee,subagentActivity:g}=K(e,t,n,c,d);(0,N.useEffect)(()=>{m?.(g)},[g,m]),(0,N.useEffect)(()=>{f?.(h.length)},[h.length,f]),(0,N.useEffect)(()=>{if(!p)return;let e=[];for(let t of h)if(t.kind===`operator-inbound`){let n=t.rawBody??t.text;n&&e.push(n)}else t.kind===`operator-typed`&&t.text&&e.push(t.text);p(e)},[h,p]);let _=le(h,ue(e,n,!l)),v=o!=null,[y,te]=(0,N.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(xe)===`1`}catch{return!1}}),b=()=>te(e=>{let t=!e;try{window.localStorage.setItem(xe,t?`1`:`0`)}catch{}return t}),x=v?!!a:i&&y,S=s||x?Se(_):_,C=(0,N.useRef)(null),w=(0,N.useRef)(!0),[T,ne]=(0,N.useState)(!0),E=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;w.current=t,ne(e=>e===t?e:t)};return(0,N.useLayoutEffect)(()=>{let e=C.current;e&&w.current&&(e.scrollTop=e.scrollHeight)},[h,x,u!=null]),(0,P.jsxs)(`div`,{className:`wa-reader${i?` wa-reader--clean-toggle`:``}`,children:[(0,P.jsx)(`div`,{className:`wa-reader-thread`,ref:C,onScroll:()=>{let e=C.current;e&&E(e)},children:(0,P.jsxs)(`div`,{className:`wa-thread-scroll`,children:[ee===`error`&&(0,P.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),h.length===0&&ee===`open`&&(0,P.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(S,e,n),u]})}),!T&&(0,P.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=C.current;e&&(e.scrollTop=e.scrollHeight,w.current=!0,ne(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`}),i&&!s&&!v&&(0,P.jsxs)(`button`,{type:`button`,className:`wa-clean-toggle${y?` is-active`:``}`,role:`switch`,"aria-checked":y,onClick:b,title:y?`Showing delivered messages only — click to show tool calls, results, and narration`:`Hide tool calls, results, and narration — show delivered messages only`,children:[(0,P.jsx)(`span`,{className:`wa-clean-label`,children:`Messages only`}),(0,P.jsx)(`span`,{className:`wa-switch`,"aria-hidden":`true`,children:(0,P.jsx)(`span`,{className:`wa-switch-thumb`})})]})]})}function we(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function Te({conversations:e,sessionKey:n,onBack:r}){let[i,a]=(0,N.useState)(null),o=oe(e);return i?(0,P.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>a(null),"aria-label":`Back to conversations`,children:[(0,P.jsx)(t,{size:16}),` Back`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:B(i)})]}),(0,P.jsx)(Ce,{sessionId:i.sessionId,projectDir:i.projectDir,sessionKey:n,forceDeliveredOnly:!0},i.sessionId)]}):(0,P.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:r,"aria-label":`Back to chat`,children:[(0,P.jsx)(t,{size:16}),` Chat`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),o.map(e=>(0,P.jsxs)(`div`,{className:`op-conv-group`,children:[(0,P.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,P.jsx)(R,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} session=${e.sessionId.slice(0,8)} readonly=true`),a(e)},children:[(0,P.jsx)(`span`,{className:`op-conv-name`,children:B(e)}),e.modelGated&&(0,P.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,P.jsx)(T,{size:13})}),(0,P.jsx)(`span`,{className:`op-conv-when`,children:we(e.lastMessageAt)})]},e.sessionId))]},e.channel))]})}export{u as A,C,p as D,b as E,s as M,f as O,w as S,x as T,F as _,Z as a,j as b,he as c,U as d,V as f,R as g,I as h,Ce as i,l as j,d as k,G as l,B as m,ge as n,pe as o,H as p,ve as r,X as s,Te as t,W as u,A as v,S as w,E as x,M as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{d as t,l as n,r,t as i}from"./admin-auth-fetch-BMOxrEnl.js";import{n as a,t as o}from"./AdminLoginScreens-KVvngpT2.js";import"./admin-types-Dg11L4MQ.js";import{r as s,t as c}from"./AdminShell-DDKZhJRo.js";import{i as l}from"./OperatorConversations-_P3_KmAW.js";import"./Checkbox-BJlS0tR2.js";var u=n(),d=e(t(),1),f=r();function p({onOpen:e}){return(0,f.jsx)(`footer`,{className:`admin-footer`,children:(0,f.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,f.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,f.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function m(){let e=a(),[t,n]=(0,d.useState)(!1);(0,d.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,d.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]),u=(0,d.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===`chat`?(0,f.jsx)(i,{cacheKey:e.cacheKey,onSessionExpired:u,surface:`chat`,children:(0,f.jsx)(c,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(p,{onOpen:r}),(0,f.jsx)(s,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,f.jsx)(f.Fragment,{children:t.selectedWhatsapp&&e.cacheKey?(0,f.jsx)(l,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,cleanViewToggle:!0},t.selectedWhatsapp.sessionId):(0,f.jsx)(`main`,{})})})}):(0,f.jsx)(o,{auth:e})}(0,u.createRoot)(document.getElementById(`root`)).render((0,f.jsx)(m,{}));
|