@rubytech/create-maxy-code 0.1.289 → 0.1.290
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/plugins/cloudflare/references/manual-setup.md +9 -5
- package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +9 -0
- package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/notification.js +14 -1
- package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
- package/payload/server/public/assets/{AdminShell-DkP2rJdF.js → AdminShell-CnslFKoX.js} +1 -1
- package/payload/server/public/assets/{Checkbox-CsQq7YPC.js → Checkbox-Dmc64qme.js} +1 -1
- package/payload/server/public/assets/{admin-C_bkVvXh.js → admin-BJYDe3p8.js} +1 -1
- package/payload/server/public/assets/{architectureDiagram-Q4EWVU46-PGePlVpb.js → architectureDiagram-Q4EWVU46-NkTPStkv.js} +1 -1
- package/payload/server/public/assets/{blockDiagram-DXYQGD6D-BJCbJRRs.js → blockDiagram-DXYQGD6D-DKsRoptY.js} +1 -1
- package/payload/server/public/assets/{browser-DynPFG_A.js → browser-CKxPsTlh.js} +1 -1
- package/payload/server/public/assets/{c4Diagram-AHTNJAMY-DcMhi4gF.js → c4Diagram-AHTNJAMY-4SSchEmY.js} +1 -1
- package/payload/server/public/assets/channel-DPRBU48c.js +1 -0
- package/payload/server/public/assets/{chunk-336JU56O-0vhS0MI-.js → chunk-336JU56O-C8szFVD5.js} +2 -2
- package/payload/server/public/assets/{chunk-426QAEUC-DbVU-p-q.js → chunk-426QAEUC-CWj9Y5LE.js} +1 -1
- package/payload/server/public/assets/{chunk-4TB4RGXK-dgx3qIz_.js → chunk-4TB4RGXK-YsoBMSBN.js} +1 -1
- package/payload/server/public/assets/{chunk-5FUZZQ4R-BglTosdT.js → chunk-5FUZZQ4R-fvCSUwuQ.js} +1 -1
- package/payload/server/public/assets/{chunk-5PVQY5BW-hZB3AxUF.js → chunk-5PVQY5BW-BKCeZJLg.js} +1 -1
- package/payload/server/public/assets/{chunk-EDXVE4YY-DXqLJyYa.js → chunk-EDXVE4YY-DhpopONL.js} +1 -1
- package/payload/server/public/assets/{chunk-ENJZ2VHE-BD4I_a54.js → chunk-ENJZ2VHE-CwpQJ9IE.js} +1 -1
- package/payload/server/public/assets/{chunk-ICPOFSXX-BdQx0Ahc.js → chunk-ICPOFSXX-D5p7fCDj.js} +1 -1
- package/payload/server/public/assets/{chunk-OYMX7WX6-BDjtbZvS.js → chunk-OYMX7WX6-DCXhGWX0.js} +1 -1
- package/payload/server/public/assets/{chunk-U2HBQHQK-hYN7A3g_.js → chunk-U2HBQHQK-D6lKmEsB.js} +1 -1
- package/payload/server/public/assets/{chunk-X2U36JSP-D3njJ7WG.js → chunk-X2U36JSP-DiKHy0ar.js} +1 -1
- package/payload/server/public/assets/{chunk-YZCP3GAM-BfZKEcvU.js → chunk-YZCP3GAM-AqHm3K1O.js} +1 -1
- package/payload/server/public/assets/{chunk-ZZ45TVLE-DLJMNqLn.js → chunk-ZZ45TVLE-jDPov-Ao.js} +1 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-BmQz46EF.js +1 -0
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-DyidaYtj.js +1 -0
- package/payload/server/public/assets/clone-D7qj6dUB.js +1 -0
- package/payload/server/public/assets/{dagre-DVLE4-m6.js → dagre-Dyawd5Z2.js} +1 -1
- package/payload/server/public/assets/{dagre-KV5264BT-DGjcX5uz.js → dagre-KV5264BT-DDGXoEYU.js} +1 -1
- package/payload/server/public/assets/{data-D1FFhz2k.js → data-BEDsi4bU.js} +1 -1
- package/payload/server/public/assets/{diagram-5BDNPKRD-CQI2o8Cv.js → diagram-5BDNPKRD-BQ1s5wpz.js} +1 -1
- package/payload/server/public/assets/{diagram-G4DWMVQ6-C8kXsEdQ.js → diagram-G4DWMVQ6-BnBA0Ain.js} +1 -1
- package/payload/server/public/assets/{diagram-MMDJMWI5-DaWrNg_c.js → diagram-MMDJMWI5-BrGASMP1.js} +1 -1
- package/payload/server/public/assets/{diagram-TYMM5635-Ql9QPUxX.js → diagram-TYMM5635-iSPhqW2Q.js} +1 -1
- package/payload/server/public/assets/{erDiagram-SMLLAGMA-B2fBZhPo.js → erDiagram-SMLLAGMA-BCRyIkOj.js} +1 -1
- package/payload/server/public/assets/{flowDiagram-DWJPFMVM-BA0LiOm5.js → flowDiagram-DWJPFMVM-BgMtd8aD.js} +1 -1
- package/payload/server/public/assets/{ganttDiagram-T4ZO3ILL-CBKdEgUk.js → ganttDiagram-T4ZO3ILL-BKpI7Sqx.js} +1 -1
- package/payload/server/public/assets/{gitGraphDiagram-UUTBAWPF-BIyEfuwB.js → gitGraphDiagram-UUTBAWPF-CEx6x6gJ.js} +1 -1
- package/payload/server/public/assets/{graph-BxWBNsFs.js → graph-DDJ3p_3N.js} +1 -1
- package/payload/server/public/assets/{graph-labels-DSLdDXoF.js → graph-labels-Cgd3XiNd.js} +1 -1
- package/payload/server/public/assets/{graphlib-Cv4SvsQN.js → graphlib-Do8h5YVR.js} +1 -1
- package/payload/server/public/assets/{infoDiagram-42DDH7IO-DovHLDHz.js → infoDiagram-42DDH7IO-DGlZXVKh.js} +1 -1
- package/payload/server/public/assets/{ishikawaDiagram-UXIWVN3A-haFza9s4.js → ishikawaDiagram-UXIWVN3A-BmCNGBwK.js} +1 -1
- package/payload/server/public/assets/{journeyDiagram-VCZTEJTY-l-8tJ21z.js → journeyDiagram-VCZTEJTY-C_37fL2K.js} +1 -1
- package/payload/server/public/assets/{kanban-definition-6JOO6SKY-DSZUvFLs.js → kanban-definition-6JOO6SKY-BLFxAQHd.js} +1 -1
- package/payload/server/public/assets/{line-mfTElknw.js → line-FtY_Ltj6.js} +1 -1
- package/payload/server/public/assets/{mermaid-parser.core-4temHHPS.js → mermaid-parser.core-BIr5bg_O.js} +1 -1
- package/payload/server/public/assets/{mermaid.core-DO2iS9my.js → mermaid.core-8XmmGzXJ.js} +3 -3
- package/payload/server/public/assets/{mindmap-definition-QFDTVHPH-Cymf2IGG.js → mindmap-definition-QFDTVHPH-DPKDmfiH.js} +1 -1
- package/payload/server/public/assets/{pieDiagram-DEJITSTG-_2tmuvMb.js → pieDiagram-DEJITSTG-DyuI0jFr.js} +1 -1
- package/payload/server/public/assets/{public-Rz_GzOrN.js → public-n0sHV8JI.js} +3 -3
- package/payload/server/public/assets/{quadrantDiagram-34T5L4WZ-CVCrGnBi.js → quadrantDiagram-34T5L4WZ-B24Cvsjf.js} +1 -1
- package/payload/server/public/assets/{requirementDiagram-MS252O5E-Bc-o8i8Z.js → requirementDiagram-MS252O5E-DpieLND2.js} +1 -1
- package/payload/server/public/assets/{sankeyDiagram-XADWPNL6-DrTBxqE6.js → sankeyDiagram-XADWPNL6-DFSI4LuL.js} +1 -1
- package/payload/server/public/assets/{sequenceDiagram-FGHM5R23-BjVjSsUJ.js → sequenceDiagram-FGHM5R23-3babM9wY.js} +1 -1
- package/payload/server/public/assets/{stateDiagram-FHFEXIEX-DWAJP6ly.js → stateDiagram-FHFEXIEX-DKS3fdXm.js} +1 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-Dh0X-qyv.js +1 -0
- package/payload/server/public/assets/{timeline-definition-GMOUNBTQ-Br_nbteH.js → timeline-definition-GMOUNBTQ-1nRSO-Z9.js} +1 -1
- package/payload/server/public/assets/{useSelectionMode-BLb-o9RX.css → useSelectionMode-CeQtw8Ba.css} +1 -1
- package/payload/server/public/assets/{vennDiagram-DHZGUBPP-D_ozeKV6.js → vennDiagram-DHZGUBPP-Ds6i6j3g.js} +1 -1
- package/payload/server/public/assets/{wardleyDiagram-NUSXRM2D-B87ZKC2B.js → wardleyDiagram-NUSXRM2D-IZMQXgw6.js} +1 -1
- package/payload/server/public/assets/{xychartDiagram-5P7HB3ND-DosRlk2T.js → xychartDiagram-5P7HB3ND-BGZkTooo.js} +1 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/data.html +5 -5
- package/payload/server/public/graph.html +6 -6
- package/payload/server/public/index.html +5 -5
- package/payload/server/public/public.html +4 -4
- package/payload/server/server.js +68 -12
- package/payload/server/public/assets/channel-idaGQqlP.js +0 -1
- package/payload/server/public/assets/classDiagram-6PBFFD2Q-CmRFpirU.js +0 -1
- package/payload/server/public/assets/classDiagram-v2-HSJHXN6E-DFy8xZjP.js +0 -1
- package/payload/server/public/assets/clone-kFPktUPQ.js +0 -1
- package/payload/server/public/assets/stateDiagram-v2-QKLJ7IA2-BHDyrxpj.js +0 -1
- /package/payload/server/public/assets/{useSelectionMode-hZ5bdL8b.js → useSelectionMode-DvBm4di-.js} +0 -0
package/package.json
CHANGED
|
@@ -373,7 +373,7 @@ Prints the UUID from Step 3. If it prints empty or null, the heredoc's env expan
|
|
|
373
373
|
|
|
374
374
|
## Step 6 — Restart the brand's user-space service so it respawns the connector with the new config
|
|
375
375
|
|
|
376
|
-
You do **not** run `cloudflared` manually. The brand's existing user-space systemd unit (`~/.config/systemd/user/${BRAND}.service`) declares `ExecStartPre=/home/<user>/${BRAND}/platform/scripts/resume-tunnel.sh`, and that pre-start script reads `${CFG_DIR}/tunnel.state` and `${CFG_DIR}/config.yml` (the files Steps 5 and 5b just wrote) and spawns the connector in the user's cgroup.
|
|
376
|
+
You do **not** run `cloudflared` manually. The brand's existing user-space systemd unit (`~/.config/systemd/user/${BRAND}.service`) declares `ExecStartPre=/home/<user>/${BRAND}/platform/scripts/resume-tunnel.sh`, and that pre-start script reads `${CFG_DIR}/tunnel.state` and `${CFG_DIR}/config.yml` (the files Steps 5 and 5b just wrote) and spawns the connector in the user's cgroup. On this first provision the connector is not yet running, so the brand-service restart triggers `resume-tunnel.sh`, which spawns it with the new config. (This is the *only* case where a brand-service restart spawns the connector — once it is running, `resume-tunnel.sh` skips by design and a `config.yml` reload requires restarting the connector unit directly; see Step 7.)
|
|
377
377
|
|
|
378
378
|
```
|
|
379
379
|
systemctl --user restart "${BRAND}.service"
|
|
@@ -463,12 +463,16 @@ Expected: `enabled`. If `disabled`, enable it:
|
|
|
463
463
|
systemctl --user enable "${BRAND}.service"
|
|
464
464
|
```
|
|
465
465
|
|
|
466
|
-
**After any change to `${CFG_DIR}/config.yml`, restart the
|
|
466
|
+
**After any change to `${CFG_DIR}/config.yml`, restart the connector unit — not the brand service:**
|
|
467
467
|
|
|
468
468
|
```
|
|
469
|
-
systemctl --user restart "
|
|
469
|
+
systemctl --user restart "cloudflared-${BRAND}.service"
|
|
470
470
|
```
|
|
471
471
|
|
|
472
|
+
With `Restart=always` this is a clean reload: systemd starts a fresh connector under the same unit, reading the edited `config.yml`. The brief ~1s blip is the same one every cloudflared upgrade incurs.
|
|
473
|
+
|
|
474
|
+
**Why not the brand service?** Since Task 602 decoupled the connector into its own unit (and Task 757 made it a supervised `Restart=always` service), `systemctl --user restart "${BRAND}.service"` no longer reaps the connector. Its `ExecStartPre=resume-tunnel.sh` runs, sees the connector already `is-active`, and skips by design (`resume-tunnel.sh` line 65) — so the brand-service restart succeeds while the old connector keeps serving the old ingress. That is a silent no-op, not an error. Restarting the brand service only spawns a connector when none is running (the first-provision case in Step 6).
|
|
475
|
+
|
|
472
476
|
**Success:**
|
|
473
477
|
|
|
474
478
|
```
|
|
@@ -555,7 +559,7 @@ cloudflared --origincert "${CFG_DIR}/cert.pem" \
|
|
|
555
559
|
### 4. Reload the connector
|
|
556
560
|
|
|
557
561
|
```
|
|
558
|
-
systemctl --user restart "
|
|
562
|
+
systemctl --user restart "cloudflared-${BRAND}.service"
|
|
559
563
|
```
|
|
560
564
|
|
|
561
565
|
Cloudflared does not watch `config.yml` for changes (the brand service unit launches it without `--config-watch`). Restart is the deterministic way to pick up the new rule; the brief ~1s connector blip is the same one every cloudflared upgrade incurs.
|
|
@@ -587,7 +591,7 @@ awk -v host="${SURFACE}.${BRAND_HOSTNAME}" '
|
|
|
587
591
|
# Cloudflare → DNS → <zone> → delete CNAME for <surface>.<BRAND_HOSTNAME>.
|
|
588
592
|
|
|
589
593
|
# 4. Restart cloudflared.
|
|
590
|
-
systemctl --user restart "
|
|
594
|
+
systemctl --user restart "cloudflared-${BRAND}.service"
|
|
591
595
|
```
|
|
592
596
|
|
|
593
597
|
---
|
|
@@ -23,6 +23,15 @@ export interface InboundPayload {
|
|
|
23
23
|
* else load the owning skill, else answer directly. Freestyle inline authoring
|
|
24
24
|
* is the `direct` floor, reached only when nothing owns the work — which is why
|
|
25
25
|
* a greeting/confirmation needs no separate skip: it falls through to `direct`.
|
|
26
|
+
*
|
|
27
|
+
* Task 761 — the cadence clause. A long turn (e.g. building a quote across many
|
|
28
|
+
* Write/Bash/Edit steps) was producing one channel message, dispatched only at
|
|
29
|
+
* turn-end, leaving the sender in silence for minutes. The agent's interim
|
|
30
|
+
* narration is surfaced in the dashboard but is never dispatched to the channel;
|
|
31
|
+
* only `reply`-tool calls reach WhatsApp. So the clause directs the agent to use
|
|
32
|
+
* the reply tool for an early acknowledgement and mid-turn progress on slow work,
|
|
33
|
+
* not just for the final result. Outcome, not script.
|
|
34
|
+
*
|
|
26
35
|
* Exported so the unit tests assert the exact wrapped shape.
|
|
27
36
|
*/
|
|
28
37
|
export declare const REFRAME_PREFIX: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAA;IACnB;;;kFAG8E;IAC9E,KAAK,EAAE,YAAY,EAAE,CAAA;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAA;IACnB;;;kFAG8E;IAC9E,KAAK,EAAE,YAAY,EAAE,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,QAQP,CAAA;AAEpB;;;YAGY;AACZ,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,cAAc;;;;;EAOzD;AA0BD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,cAAc,GAAG,eAAe,CAMtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAElF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAEvG;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,GACf;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAIzD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAE3C;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC/B,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GAChF,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED;;;;gCAIgC;AAChC,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAMrE"}
|
|
@@ -8,12 +8,25 @@
|
|
|
8
8
|
* else load the owning skill, else answer directly. Freestyle inline authoring
|
|
9
9
|
* is the `direct` floor, reached only when nothing owns the work — which is why
|
|
10
10
|
* a greeting/confirmation needs no separate skip: it falls through to `direct`.
|
|
11
|
+
*
|
|
12
|
+
* Task 761 — the cadence clause. A long turn (e.g. building a quote across many
|
|
13
|
+
* Write/Bash/Edit steps) was producing one channel message, dispatched only at
|
|
14
|
+
* turn-end, leaving the sender in silence for minutes. The agent's interim
|
|
15
|
+
* narration is surfaced in the dashboard but is never dispatched to the channel;
|
|
16
|
+
* only `reply`-tool calls reach WhatsApp. So the clause directs the agent to use
|
|
17
|
+
* the reply tool for an early acknowledgement and mid-turn progress on slow work,
|
|
18
|
+
* not just for the final result. Outcome, not script.
|
|
19
|
+
*
|
|
11
20
|
* Exported so the unit tests assert the exact wrapped shape.
|
|
12
21
|
*/
|
|
13
22
|
export const REFRAME_PREFIX = 'Choose the installed specialist that owns this request and dispatch it with the Agent tool. ' +
|
|
14
23
|
'If no specialist fits, load the owning skill. ' +
|
|
15
24
|
'If neither fits (a greeting, a quick question, a confirmation, a direct continuation), just answer. ' +
|
|
16
|
-
'Then carry it out.
|
|
25
|
+
'Then carry it out. ' +
|
|
26
|
+
'If carrying it out will take more than a few seconds, call the reply tool right away to acknowledge you are on it, ' +
|
|
27
|
+
'send a brief progress note with the reply tool before each long step, and call the reply tool again with the result — ' +
|
|
28
|
+
'never stay silent until the end. ' +
|
|
29
|
+
'Request follows:';
|
|
17
30
|
/**
|
|
18
31
|
* Shape an inbound WhatsApp payload as a Claude Code channel notification.
|
|
19
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,yEAAyE;AAsBzE
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,yEAAyE;AAsBzE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,8FAA8F;IAC9F,gDAAgD;IAChD,sGAAsG;IACtG,qBAAqB;IACrB,qHAAqH;IACrH,wHAAwH;IACxH,mCAAmC;IACnC,kBAAkB,CAAA;AAWpB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,CAAiB;IACxD,OAAO;QACL,MAAM,EAAE,8BAAuC;QAC/C,MAAM,EAAE;YACN,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,OAAO;SACxC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,CAAiB;IACvC,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;IAClE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,IAAI,CAAA;IACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CACxB,CAAC,CAAC,EAAE,EAAE,CACJ,qBAAqB,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE;QACxC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI;QAC3C,gDAAgD,CACnD,CAAA;IACD,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/B,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAiB;IACnD,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO;QACL,OAAO,EAAE,GAAG,cAAc,OAAO,OAAO,EAAE;QAC1C,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;KACjD,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB,EAAE,CAAuB;IACvE,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAA;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,IAAY;IACjE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,UAAkB,EAClB,KAAe,EACf,OAAgB;IAEhB,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE;QAC1C,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,WAAmB;IAEnB,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA+B,EAC/B,IAAiF;IAEjF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,MAAM,OAAO,EAAE;YAAE,OAAO,IAAI,CAAA;QAChC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;gCAIgC;AAChC,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAa;IAC3D,MAAM,CAAC,GAAG,IAAsD,CAAA;IAChE,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;IAClF,IAAI,CAAC,MAAM;QAAE,OAAO,2BAA2B,MAAM,EAAE,CAAA;IACvD,IAAI,CAAC,EAAE,QAAQ,KAAK,IAAI;QAAE,OAAO,+CAA+C,CAAA;IAChF,OAAO,UAAU,MAAM,EAAE,CAAA;AAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CnGqDkHZ.js";import{d as t,f as n,l as r,m as i,o as a,r as o,t as s,u as c}from"./useSelectionMode-hZ5bdL8b.js";var l=n(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),u=n(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),d=n(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),f=n(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),p=n(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),m=n(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),h=n(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),g=n(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),_=n(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),v=n(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),ee=n(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),y=n(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),b=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),x=n(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),te=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),S=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),C=n(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ne=n(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),w=n(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),re=n(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),ie=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ae=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=n(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=e(i(),1),D=r(),O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return A(t)}catch{}return 264}function oe({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>j()),i=(0,E.useRef)(n);(0,E.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,E.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(A(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(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var M=`maxy-admin-session`,se=typeof BroadcastChannel<`u`;function N(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function P(e){if(!se)return()=>{};let t=new BroadcastChannel(M),n=t=>{if(!N(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var F=`maxy-admin-session-key`;function I(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function L(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function ce(){try{return sessionStorage.getItem(F)}catch{return null}}function R(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,E.useState)(t),a=(0,E.useRef)(t);(0,E.useEffect)(()=>{a.current=r},[r]),(0,E.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,E.useState)(0);(0,E.useEffect)(()=>P(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,E.useCallback)(()=>{try{sessionStorage.removeItem(F)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,E.useCallback)(async(e,t)=>{let r=a.current,o=I(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await L(l);if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=ce();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=I(e,d),p=await fetch(f,t);return p.status===401&&(console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()),p},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var z=(0,E.createContext)(null);function le({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,E.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=I(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await L(o),c=e.slice(-8);if(s===`session-not-registered`){let a=ce();if(a&&a!==e){let e=I(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,D.jsx)(z.Provider,{value:i,children:r})}function B(){return(0,E.useContext)(z)}function ue(e){let t=B();return(0,E.useMemo)(()=>t||(async(t,n)=>fetch(e?I(t,e):t,n)),[t,e])}function V(e){let{businessName:t,onNavigate:n,onToggleSidebar:r,sidebarOpen:i,onLogout:s}=e,[l,u]=(0,E.useState)(!1),d=(0,E.useRef)(null),f=(0,E.useRef)(null),h=ue(null),[v,y]=(0,E.useState)(null),[ne,w]=(0,E.useState)(!1),[ie,ae]=(0,E.useState)(null),[O,k]=(0,E.useState)(null),[A,j]=(0,E.useState)(null),[oe,M]=(0,E.useState)(``);(0,E.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,E.useEffect)(()=>{l&&f.current?.focus()},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=!1;return h(`/api/admin/version`).then(e=>e.json()).then(t=>{e||j(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,h]);let se=(0,E.useCallback)(()=>{u(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),N=(0,E.useCallback)(e=>{u(!1),n(e)},[n]),P=(0,E.useCallback)(async()=>{if(v!==null){y(null),k(null);return}w(!0),ae(null);try{let e=await h(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);y((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),ae(e instanceof Error?e.message:String(e)),y([])}finally{w(!1)}},[v,h]),F=(0,E.useCallback)(e=>{k(null),y(t=>t?.filter(t=>t.slug!==e)??null),h(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[h]),I=(0,E.useCallback)(()=>{u(!1),s()},[s]),L=t||o.productName;return(0,D.jsxs)(`header`,{className:`admin-header`,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":i?`Hide sidebar`:`Show sidebar`,title:i?`Hide sidebar`:`Show sidebar`,"aria-expanded":i,onClick:r,children:i?(0,D.jsx)(S,{size:20,strokeWidth:1.5}):(0,D.jsx)(C,{size:20,strokeWidth:1.5})}),(0,D.jsxs)(`div`,{className:`chat-header-label`,children:[(0,D.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,D.jsx)(`img`,{src:a,alt:``,className:`chat-logo`})}),(0,D.jsx)(`h1`,{className:`chat-tagline`,children:L})]}),(0,D.jsxs)(`div`,{className:`chat-burger-wrap`,ref:d,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:se,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,D.jsx)(te,{size:20})}),l&&(0,D.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,D.jsxs)(`button`,{ref:f,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`data`),children:[(0,D.jsx)(m,{size:14}),` Data`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`graph`),children:[(0,D.jsx)(re,{size:14}),` Graph`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`browser`),children:[(0,D.jsx)(_,{size:14}),` Browser`]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:P,children:[(0,D.jsx)(g,{size:14}),` Public`,ne&&(0,D.jsx)(b,{size:12,className:`spin`})]}),v!==null&&(0,D.jsxs)(`div`,{className:`chat-menu-agents`,children:[ie&&(0,D.jsx)(`span`,{className:`chat-menu-agent-error`,children:ie}),v.length===0&&!ie&&(0,D.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),v.map(e=>(0,D.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,D.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,D.jsxs)(`span`,{className:`agent-text`,children:[(0,D.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,D.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),O===e.slug?(0,D.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>F(e.slug),children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>k(null),children:(0,D.jsx)(T,{size:12})})]}):(0,D.jsxs)(`span`,{className:`agent-actions`,children:[(0,D.jsx)(`a`,{href:`${oe}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>u(!1),children:(0,D.jsx)(g,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>k(e.slug),children:(0,D.jsx)(c,{size:12})})]})]},e.slug))]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,D.jsx)(ee,{size:14}),(0,D.jsxs)(`span`,{className:`version-installed`,children:[A?`v${A.installed}`:`…`,A&&!A.updateAvailable&&(0,D.jsx)(`span`,{className:`version-uptodate-dot`}),A?.updateAvailable&&(0,D.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,D.jsx)(x,{size:14}),` Log out`]})]})]})]})}var de={whatsapp:{fill:`#25D366`,label:`WhatsApp`,path:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.71.306 1.263.489 1.694.625.712.227 1.36.195 1.872.118.571-.085 1.758-.719 2.006-1.413.247-.694.247-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.885-9.885 9.885M20.52 3.449C18.24 1.245 15.24.044 12.045.044 5.463.044.103 5.404.1 11.99c0 2.096.546 4.142 1.588 5.945L0 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.585 0 11.946-5.36 11.949-11.946 0-3.193-1.24-6.19-3.495-8.445`},telegram:{fill:`#229ED9`,label:`Telegram`,path:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`}};function fe({channel:e,size:t=16}){let n=de[e];return(0,D.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,D.jsx)(`path`,{d:n.path})})}var pe=[`whatsapp`,`telegram`];function me(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function H(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var U=`auth-refresh-failed`;function ge({error:e,onClose:t}){if(!e)return null;let n=e.reason===U,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:r}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,D.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function _e(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:c}=e,[l,u]=(0,E.useState)(null);if(!t)return null;let d=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),f=d.at(-1),p=f?.peak_request_pct==null?f?.context_window?Math.round((f.input_tokens+f.cache_creation_tokens+f.cache_read_tokens)/f.context_window*100):0:Math.round(f.peak_request_pct*100),m=d.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),h=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),g=d.reduce((e,t)=>e+(t.total_cost_usd??0),0),_=r?.account?.subscriptionType,v=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,D.jsx)(`span`,{children:`Claude Code`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,D.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:m>0?he(m):`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:H(a)})]}),(o||c)&&(()=>{let e=o??c??``;return(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{u(await s(e)?`copied`:`failed`),setTimeout(()=>u(null),1200)},children:l===`copied`?`copied ✓`:l===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var W=`https://claude.ai/code`,ve=[500,1e3,1500,2e3,2500,3e3,3e3];function ye(e,t,n){let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${W}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function be(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function xe(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:s,onSelectProjects:p,onSelectPeople:m,onSelectTasks:_,onSelectAgents:ee,onCloseMobileDrawer:b,collapsed:x,selectedWhatsappId:te,onSelectWhatsappConversation:S}=e,C=ue(r),re=o.productName,T=typeof a==`string`?a:a===null?`name unavailable`:n||re,O=(T.trim().charAt(0)||`?`).toUpperCase(),[k,A]=(0,E.useState)(`sessions`),[j,oe]=(0,E.useState)([]),[M,se]=(0,E.useState)(!1),[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(!1),[L,ce]=(0,E.useState)(`file`),[R,z]=(0,E.useState)(null),[le,B]=(0,E.useState)(null),[V,de]=(0,E.useState)([]),[H,he]=(0,E.useState)(!1),[U,_e]=(0,E.useState)(null),[W,xe]=(0,E.useState)(!1),[G,K]=(0,E.useState)(!1),[q,Ce]=(0,E.useState)(!1),[we,Te]=(0,E.useState)(null),[J,Y]=(0,E.useState)(new Set),[Ee,De]=(0,E.useState)(new Set),[Oe,ke]=(0,E.useState)(new Set),[Ae,je]=(0,E.useState)(new Set),[X,Me]=(0,E.useState)(!1),[Ne,Pe]=(0,E.useState)([]),[Fe,Ie]=(0,E.useState)(!1),[Le,Re]=(0,E.useState)(null),[ze,Be]=(0,E.useState)(`whatsapp`),Ve=(0,E.useCallback)(e=>{if(b(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),z({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),z({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),me(r,e.downloadPath,e.downloadRoot??`data`),z({message:`Downloading ${e.name}`,failed:!1})},[r,b]);(0,E.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>z(null),2500);return()=>clearTimeout(e)},[R]);let He=(0,E.useCallback)(async()=>{if(r){I(!0),P(null);try{let e=await C(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);oe((await e.json()).artefacts??[]),se(!0)}catch(e){let t=e instanceof Error?e.message:String(e);P(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{I(!1)}}},[r,C]),Z=(0,E.useCallback)(async()=>{if(!r)return null;xe(!0),_e(null);try{let e=await C(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return de(n),Te(t.accountId??null),he(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return _e(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{xe(!1)}},[r,C]),Ue=(0,E.useCallback)(async()=>{if(r){Re(null);try{let e=await C(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Pe((await e.json()).conversations??[]),Ie(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Re(`Couldn't load conversations: ${t}`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[r,C]);(0,E.useEffect)(()=>{!r||H||Z()},[r,H,Z]),(0,E.useEffect)(()=>{r&&Ue()},[r,Ue]);let Q=(0,E.useMemo)(()=>{let e=new Map;for(let t of pe)e.set(t,[]);for(let t of Ne)e.get(t.channel)?.push(t);for(let t of pe)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ne]),We={whatsapp:`WhatsApp`,telegram:`Telegram`},Ge=()=>{S(null),A(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${M?j.length:0} collapsed=${x}`),He()},$=1.5,Ke=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),He()},qe=()=>{S(null),A(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${H?V.length:0} collapsed=${x}`),H||Z()},Je=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Z()},Ye=e=>{A(`whatsapp`),Be(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${Q.get(e)?.length??0} collapsed=${x}`),b()},Xe=(0,E.useCallback)(async e=>{if(e.resumable===!1||Ee.has(e.sessionId))return;De(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=ye(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(b(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),B(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),B({sessionId:e.sessionId,reason:r})}finally{De(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[C,b,Ee]),Ze=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=ve.length;n++){await new Promise(e=>setTimeout(e,ve[n-1]));let r=await Z();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),Qe=(0,E.useCallback)(async()=>{if(X)return;Me(!0);let e=window.open(``,`_blank`);try{let t=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=ye(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?Ze(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),B(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),B({sessionId:null,reason:n})}finally{Me(!1)}},[C,X,Ze]),$e=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!J.has(t.sessionId)){Y(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),z({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),de(e=>e.filter(e=>e.sessionId!==t.sessionId)),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),z({message:`Delete failed: ${n}`,failed:!0})}finally{Y(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,J,Z]),et=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Oe.has(t.sessionId)){ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),z({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),z({message:`Stop failed: ${n}`,failed:!0})}finally{ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Oe,Z]),tt=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ae.has(t.sessionId)){je(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{je(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Ae,Z]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsx)(`div`,{className:`side-new-session-row`,children:(0,D.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:Qe,disabled:X,"aria-busy":X,children:[(0,D.jsx)(ne,{size:14}),(0,D.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,D.jsxs)(`nav`,{className:`side-nav`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),b()},children:[(0,D.jsx)(ae,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`People`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),ee(),b()},children:[(0,D.jsx)(d,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Agents`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),p(),b()},children:[(0,D.jsx)(f,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Projects`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),b()},children:[(0,D.jsx)(y,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`artefacts`?` active`:``}`,onClick:Ge,children:[(0,D.jsx)(t,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`sessions`?` active`:``}`,onClick:qe,children:[(0,D.jsx)(v,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,D.jsx)(`span`,{className:`kbd`})]}),Fe&&pe.filter(e=>Q.get(e).length>0).map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`whatsapp`&&ze===e?` active`:``}`,onClick:()=>Ye(e),children:[(0,D.jsx)(fe,{channel:e,size:16}),(0,D.jsx)(`span`,{className:`label`,children:We[e]}),(0,D.jsx)(`span`,{className:`kbd`})]},e)),Le&&(0,D.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,D.jsx)(`span`,{className:`label`,children:Le})})]}),k===`artefacts`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Artefacts`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ke,disabled:F,children:(0,D.jsx)(w,{size:12,className:F?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:F?`…`:String(j.length)})]})]}),N&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:N}),M&&!N&&j.length>0&&(()=>{let e=j.filter(e=>e.kind===`agent-template`).length,t=j.length-e;return(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:j.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${L===e.key?` active`:``}`,onClick:()=>ce(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,D.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),M&&!N&&j.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),j.filter(e=>L===`all`?!0:L===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?d:t,i=be(e.updatedAt),a=e.downloadPath!==null;return(0,D.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>Ve(e),disabled:!a,style:a?void 0:{cursor:`default`},title:a?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,D.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.name})}),i&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:i})]}),a&&(0,D.jsx)(h,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),k===`sessions`&&(()=>{let e=V.filter(e=>G?!0:!e.isSubagent).filter(e=>q?!0:!e.archived),t=V.some(e=>e.isSubagent),n=V.some(e=>e.archived);return(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Je,disabled:W,children:(0,D.jsx)(w,{size:12,className:W?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:W?`…`:String(e.length)})]})]}),we&&(0,D.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,D.jsx)(`code`,{children:we})}),(t||n)&&(0,D.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${G?` active`:``}`,onClick:()=>K(e=>!e),title:G?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>Ce(e=>!e),title:q?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),U&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:U}),H&&!U&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=be(e.startedAt),n=Ee.has(e.sessionId),r=J.has(e.sessionId),i=Oe.has(e.sessionId),a=Ae.has(e.sessionId);return(0,D.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static`,children:[(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,D.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,D.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,D.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,D.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,D.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,D.jsx)(v,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{Xe(e)},disabled:n||r||i||a,"aria-busy":n,"aria-label":`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,children:(0,D.jsx)(g,{size:12})}),e.live?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(t,e)},disabled:n||r||i||a,"aria-busy":i,"aria-label":`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,children:(0,D.jsx)(ie,{size:12})}):null,e.archived?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{tt(t,e,`unarchive`)},disabled:n||r||i||a,"aria-busy":a,"aria-label":`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,children:(0,D.jsx)(l,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{tt(t,e,`archive`)},disabled:n||r||i||a,"aria-busy":a,"aria-label":`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,children:(0,D.jsx)(u,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{$e(t,e)},disabled:n||r||i||a,"aria-busy":r,"aria-label":`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,children:(0,D.jsx)(c,{size:12})})]})]},e.sessionId)})]})})(),k===`whatsapp`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:We[ze]}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{Ue()},children:(0,D.jsx)(w,{size:12})}),(0,D.jsx)(`span`,{children:String(Q.get(ze).length)})]})]}),Q.get(ze).map(e=>{let t=be(e.lastMessageAt);return(0,D.jsxs)(`button`,{type:`button`,className:`conv${te===e.sessionId?` active`:``}`,onClick:()=>{S(e),b()},title:e.title,children:[(0,D.jsx)(fe,{channel:e.channel,size:14}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.operatorName??e.whatsappName??e.senderId??e.title})}),t&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]},e.sessionId)})]}),(0,D.jsx)(Se,{}),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:s?(0,D.jsx)(`img`,{src:s,alt:T}):O}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:T}),(0,D.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),R&&(0,D.jsx)(`div`,{className:`copy-toast${R.failed?` copy-toast-failed`:``}`,role:`status`,children:R.message}),(0,D.jsx)(ge,{error:le,onClose:()=>B(null)})]})}var G=5e3;function Se(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},G))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,D.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var K=`admin-sidebar-collapsed`,q=`admin-sidebar-drawer-open`;function Ce(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function we(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}function Te(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function J(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}var Y=720;function Ee(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function De(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,operatorName:null,whatsappName:null,lastMessageAt:null}}function Oe(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,E.useState)(()=>Ce()),[d,f]=(0,E.useState)(()=>Te()),[p,m]=(0,E.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Y}px)`).matches),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Y}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _=(0,E.useCallback)(e=>{we(e),u(e)},[]),v=(0,E.useCallback)(e=>{J(e),f(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]),(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=De(window.location.pathname,window.location.search);e&&(g(e),console.info(`[admin-ui] wa-hydrate route=/ sessionId=${e.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let ee=(0,E.useCallback)(e=>{if(e===null){g(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Ee(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?g(e):window.location.href=n.href},[]),y=p?d:!l,b=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),v(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),_(!e)}},[l,d,_,v]),x=(0,E.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`);let t=e===`data`?`/data`:e===`graph`?`/graph`:`/browser`;window.location.href=t},[]),te={collapsed:l,mobileDrawerOpen:d,sidebarOpen:y,onToggleSidebar:b,setMobileDrawerOpen:v,selectedWhatsapp:h,onClearWhatsapp:()=>g(null)};return(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(V,{businessName:n,onNavigate:x,onToggleSidebar:b,sidebarOpen:y,onLogout:r}),(0,D.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(xe,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>v(!1),collapsed:l,mobileDrawerOpen:d,selectedWhatsappId:h?.sessionId??null,onSelectWhatsappConversation:ee}),typeof s==`function`?s(te):s]}),d&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>v(!1)}),c]})}export{ue as a,T as c,ne as d,b as f,m as g,h,le as i,re as l,g as m,_e as n,R as o,_ as p,me as r,oe as s,Oe as t,w as u};
|
|
1
|
+
import{o as e}from"./chunk-CnGqDkHZ.js";import{d as t,f as n,l as r,m as i,o as a,r as o,t as s,u as c}from"./useSelectionMode-DvBm4di-.js";var l=n(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),u=n(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),d=n(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),f=n(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),p=n(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),m=n(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),h=n(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),g=n(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),_=n(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),v=n(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),ee=n(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),y=n(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),b=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),x=n(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),te=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),S=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),C=n(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ne=n(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),w=n(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),re=n(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),ie=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ae=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=n(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=e(i(),1),D=r(),O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return A(t)}catch{}return 264}function oe({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>j()),i=(0,E.useRef)(n);(0,E.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,E.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(A(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(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var M=`maxy-admin-session`,se=typeof BroadcastChannel<`u`;function N(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function P(e){if(!se)return()=>{};let t=new BroadcastChannel(M),n=t=>{if(!N(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var F=`maxy-admin-session-key`;function I(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function L(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function ce(){try{return sessionStorage.getItem(F)}catch{return null}}function R(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,E.useState)(t),a=(0,E.useRef)(t);(0,E.useEffect)(()=>{a.current=r},[r]),(0,E.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,E.useState)(0);(0,E.useEffect)(()=>P(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,E.useCallback)(()=>{try{sessionStorage.removeItem(F)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,E.useCallback)(async(e,t)=>{let r=a.current,o=I(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await L(l);if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=ce();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=I(e,d),p=await fetch(f,t);return p.status===401&&(console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()),p},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var z=(0,E.createContext)(null);function le({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,E.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=I(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await L(o),c=e.slice(-8);if(s===`session-not-registered`){let a=ce();if(a&&a!==e){let e=I(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,D.jsx)(z.Provider,{value:i,children:r})}function B(){return(0,E.useContext)(z)}function ue(e){let t=B();return(0,E.useMemo)(()=>t||(async(t,n)=>fetch(e?I(t,e):t,n)),[t,e])}function V(e){let{businessName:t,onNavigate:n,onToggleSidebar:r,sidebarOpen:i,onLogout:s}=e,[l,u]=(0,E.useState)(!1),d=(0,E.useRef)(null),f=(0,E.useRef)(null),h=ue(null),[v,y]=(0,E.useState)(null),[ne,w]=(0,E.useState)(!1),[ie,ae]=(0,E.useState)(null),[O,k]=(0,E.useState)(null),[A,j]=(0,E.useState)(null),[oe,M]=(0,E.useState)(``);(0,E.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,E.useEffect)(()=>{l&&f.current?.focus()},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=!1;return h(`/api/admin/version`).then(e=>e.json()).then(t=>{e||j(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,h]);let se=(0,E.useCallback)(()=>{u(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),N=(0,E.useCallback)(e=>{u(!1),n(e)},[n]),P=(0,E.useCallback)(async()=>{if(v!==null){y(null),k(null);return}w(!0),ae(null);try{let e=await h(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);y((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),ae(e instanceof Error?e.message:String(e)),y([])}finally{w(!1)}},[v,h]),F=(0,E.useCallback)(e=>{k(null),y(t=>t?.filter(t=>t.slug!==e)??null),h(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[h]),I=(0,E.useCallback)(()=>{u(!1),s()},[s]),L=t||o.productName;return(0,D.jsxs)(`header`,{className:`admin-header`,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":i?`Hide sidebar`:`Show sidebar`,title:i?`Hide sidebar`:`Show sidebar`,"aria-expanded":i,onClick:r,children:i?(0,D.jsx)(S,{size:20,strokeWidth:1.5}):(0,D.jsx)(C,{size:20,strokeWidth:1.5})}),(0,D.jsxs)(`div`,{className:`chat-header-label`,children:[(0,D.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,D.jsx)(`img`,{src:a,alt:``,className:`chat-logo`})}),(0,D.jsx)(`h1`,{className:`chat-tagline`,children:L})]}),(0,D.jsxs)(`div`,{className:`chat-burger-wrap`,ref:d,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:se,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,D.jsx)(te,{size:20})}),l&&(0,D.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,D.jsxs)(`button`,{ref:f,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`data`),children:[(0,D.jsx)(m,{size:14}),` Data`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`graph`),children:[(0,D.jsx)(re,{size:14}),` Graph`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`browser`),children:[(0,D.jsx)(_,{size:14}),` Browser`]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:P,children:[(0,D.jsx)(g,{size:14}),` Public`,ne&&(0,D.jsx)(b,{size:12,className:`spin`})]}),v!==null&&(0,D.jsxs)(`div`,{className:`chat-menu-agents`,children:[ie&&(0,D.jsx)(`span`,{className:`chat-menu-agent-error`,children:ie}),v.length===0&&!ie&&(0,D.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),v.map(e=>(0,D.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,D.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,D.jsxs)(`span`,{className:`agent-text`,children:[(0,D.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,D.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),O===e.slug?(0,D.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>F(e.slug),children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>k(null),children:(0,D.jsx)(T,{size:12})})]}):(0,D.jsxs)(`span`,{className:`agent-actions`,children:[(0,D.jsx)(`a`,{href:`${oe}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>u(!1),children:(0,D.jsx)(g,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>k(e.slug),children:(0,D.jsx)(c,{size:12})})]})]},e.slug))]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,D.jsx)(ee,{size:14}),(0,D.jsxs)(`span`,{className:`version-installed`,children:[A?`v${A.installed}`:`…`,A&&!A.updateAvailable&&(0,D.jsx)(`span`,{className:`version-uptodate-dot`}),A?.updateAvailable&&(0,D.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,D.jsx)(x,{size:14}),` Log out`]})]})]})]})}var de={whatsapp:{fill:`#25D366`,label:`WhatsApp`,path:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.71.306 1.263.489 1.694.625.712.227 1.36.195 1.872.118.571-.085 1.758-.719 2.006-1.413.247-.694.247-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.885-9.885 9.885M20.52 3.449C18.24 1.245 15.24.044 12.045.044 5.463.044.103 5.404.1 11.99c0 2.096.546 4.142 1.588 5.945L0 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.585 0 11.946-5.36 11.949-11.946 0-3.193-1.24-6.19-3.495-8.445`},telegram:{fill:`#229ED9`,label:`Telegram`,path:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`}};function fe({channel:e,size:t=16}){let n=de[e];return(0,D.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,D.jsx)(`path`,{d:n.path})})}var pe=[`whatsapp`,`telegram`];function me(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function H(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var U=`auth-refresh-failed`;function ge({error:e,onClose:t}){if(!e)return null;let n=e.reason===U,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:r}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,D.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function _e(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:c}=e,[l,u]=(0,E.useState)(null);if(!t)return null;let d=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),f=d.at(-1),p=f?.peak_request_pct==null?f?.context_window?Math.round((f.input_tokens+f.cache_creation_tokens+f.cache_read_tokens)/f.context_window*100):0:Math.round(f.peak_request_pct*100),m=d.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),h=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),g=d.reduce((e,t)=>e+(t.total_cost_usd??0),0),_=r?.account?.subscriptionType,v=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,D.jsx)(`span`,{children:`Claude Code`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,D.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:m>0?he(m):`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:H(a)})]}),(o||c)&&(()=>{let e=o??c??``;return(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{u(await s(e)?`copied`:`failed`),setTimeout(()=>u(null),1200)},children:l===`copied`?`copied ✓`:l===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var W=`https://claude.ai/code`,ve=[500,1e3,1500,2e3,2500,3e3,3e3];function ye(e,t,n){let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${W}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function be(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function xe(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:s,onSelectProjects:p,onSelectPeople:m,onSelectTasks:_,onSelectAgents:ee,onCloseMobileDrawer:b,collapsed:x,selectedWhatsappId:te,onSelectWhatsappConversation:S}=e,C=ue(r),re=o.productName,T=typeof a==`string`?a:a===null?`name unavailable`:n||re,O=(T.trim().charAt(0)||`?`).toUpperCase(),[k,A]=(0,E.useState)(`sessions`),[j,oe]=(0,E.useState)([]),[M,se]=(0,E.useState)(!1),[N,P]=(0,E.useState)(null),[F,I]=(0,E.useState)(!1),[L,ce]=(0,E.useState)(`file`),[R,z]=(0,E.useState)(null),[le,B]=(0,E.useState)(null),[V,de]=(0,E.useState)([]),[H,he]=(0,E.useState)(!1),[U,_e]=(0,E.useState)(null),[W,xe]=(0,E.useState)(!1),[G,K]=(0,E.useState)(!1),[q,Ce]=(0,E.useState)(!1),[we,Te]=(0,E.useState)(null),[J,Y]=(0,E.useState)(new Set),[Ee,De]=(0,E.useState)(new Set),[Oe,ke]=(0,E.useState)(new Set),[Ae,je]=(0,E.useState)(new Set),[X,Me]=(0,E.useState)(!1),[Ne,Pe]=(0,E.useState)([]),[Fe,Ie]=(0,E.useState)(!1),[Le,Re]=(0,E.useState)(null),[ze,Be]=(0,E.useState)(`whatsapp`),Ve=(0,E.useCallback)(e=>{if(b(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),z({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),z({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),me(r,e.downloadPath,e.downloadRoot??`data`),z({message:`Downloading ${e.name}`,failed:!1})},[r,b]);(0,E.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>z(null),2500);return()=>clearTimeout(e)},[R]);let He=(0,E.useCallback)(async()=>{if(r){I(!0),P(null);try{let e=await C(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);oe((await e.json()).artefacts??[]),se(!0)}catch(e){let t=e instanceof Error?e.message:String(e);P(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{I(!1)}}},[r,C]),Z=(0,E.useCallback)(async()=>{if(!r)return null;xe(!0),_e(null);try{let e=await C(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return de(n),Te(t.accountId??null),he(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return _e(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{xe(!1)}},[r,C]),Ue=(0,E.useCallback)(async()=>{if(r){Re(null);try{let e=await C(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Pe((await e.json()).conversations??[]),Ie(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Re(`Couldn't load conversations: ${t}`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[r,C]);(0,E.useEffect)(()=>{!r||H||Z()},[r,H,Z]),(0,E.useEffect)(()=>{r&&Ue()},[r,Ue]);let Q=(0,E.useMemo)(()=>{let e=new Map;for(let t of pe)e.set(t,[]);for(let t of Ne)e.get(t.channel)?.push(t);for(let t of pe)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ne]),We={whatsapp:`WhatsApp`,telegram:`Telegram`},Ge=()=>{S(null),A(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${M?j.length:0} collapsed=${x}`),He()},$=1.5,Ke=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),He()},qe=()=>{S(null),A(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${H?V.length:0} collapsed=${x}`),H||Z()},Je=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Z()},Ye=e=>{A(`whatsapp`),Be(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${Q.get(e)?.length??0} collapsed=${x}`)},Xe=(0,E.useCallback)(async e=>{if(e.resumable===!1||Ee.has(e.sessionId))return;De(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=ye(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(b(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),B(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),B({sessionId:e.sessionId,reason:r})}finally{De(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[C,b,Ee]),Ze=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=ve.length;n++){await new Promise(e=>setTimeout(e,ve[n-1]));let r=await Z();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),Qe=(0,E.useCallback)(async()=>{if(X)return;Me(!0);let e=window.open(``,`_blank`);try{let t=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=ye(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?Ze(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),B(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),B({sessionId:null,reason:n})}finally{Me(!1)}},[C,X,Ze]),$e=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!J.has(t.sessionId)){Y(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),z({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),de(e=>e.filter(e=>e.sessionId!==t.sessionId)),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),z({message:`Delete failed: ${n}`,failed:!0})}finally{Y(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,J,Z]),et=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Oe.has(t.sessionId)){ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),z({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),z({message:`Stop failed: ${n}`,failed:!0})}finally{ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Oe,Z]),tt=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ae.has(t.sessionId)){je(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),z({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{je(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Ae,Z]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsx)(`div`,{className:`side-new-session-row`,children:(0,D.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:Qe,disabled:X,"aria-busy":X,children:[(0,D.jsx)(ne,{size:14}),(0,D.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,D.jsxs)(`nav`,{className:`side-nav`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),b()},children:[(0,D.jsx)(ae,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`People`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),ee(),b()},children:[(0,D.jsx)(d,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Agents`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),p(),b()},children:[(0,D.jsx)(f,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Projects`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),b()},children:[(0,D.jsx)(y,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`artefacts`?` active`:``}`,onClick:Ge,children:[(0,D.jsx)(t,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`sessions`?` active`:``}`,onClick:qe,children:[(0,D.jsx)(v,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,D.jsx)(`span`,{className:`kbd`})]}),Fe&&pe.filter(e=>Q.get(e).length>0).map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`whatsapp`&&ze===e?` active`:``}`,onClick:()=>Ye(e),children:[(0,D.jsx)(fe,{channel:e,size:16}),(0,D.jsx)(`span`,{className:`label`,children:We[e]}),(0,D.jsx)(`span`,{className:`kbd`})]},e)),Le&&(0,D.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,D.jsx)(`span`,{className:`label`,children:Le})})]}),k===`artefacts`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Artefacts`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:Ke,disabled:F,children:(0,D.jsx)(w,{size:12,className:F?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:F?`…`:String(j.length)})]})]}),N&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:N}),M&&!N&&j.length>0&&(()=>{let e=j.filter(e=>e.kind===`agent-template`).length,t=j.length-e;return(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:j.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${L===e.key?` active`:``}`,onClick:()=>ce(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,D.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),M&&!N&&j.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),j.filter(e=>L===`all`?!0:L===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?d:t,i=be(e.updatedAt),a=e.downloadPath!==null;return(0,D.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>Ve(e),disabled:!a,style:a?void 0:{cursor:`default`},title:a?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,D.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.name})}),i&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:i})]}),a&&(0,D.jsx)(h,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),k===`sessions`&&(()=>{let e=V.filter(e=>G?!0:!e.isSubagent).filter(e=>q?!0:!e.archived),t=V.some(e=>e.isSubagent),n=V.some(e=>e.archived);return(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Je,disabled:W,children:(0,D.jsx)(w,{size:12,className:W?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:W?`…`:String(e.length)})]})]}),we&&(0,D.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,D.jsx)(`code`,{children:we})}),(t||n)&&(0,D.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${G?` active`:``}`,onClick:()=>K(e=>!e),title:G?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,onClick:()=>Ce(e=>!e),title:q?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),U&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:U}),H&&!U&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=be(e.startedAt),n=Ee.has(e.sessionId),r=J.has(e.sessionId),i=Oe.has(e.sessionId),a=Ae.has(e.sessionId);return(0,D.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static`,children:[(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,D.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,D.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,D.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,D.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,D.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,D.jsx)(v,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{Xe(e)},disabled:n||r||i||a,"aria-busy":n,"aria-label":`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,children:(0,D.jsx)(g,{size:12})}),e.live?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{et(t,e)},disabled:n||r||i||a,"aria-busy":i,"aria-label":`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,children:(0,D.jsx)(ie,{size:12})}):null,e.archived?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{tt(t,e,`unarchive`)},disabled:n||r||i||a,"aria-busy":a,"aria-label":`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,children:(0,D.jsx)(l,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{tt(t,e,`archive`)},disabled:n||r||i||a,"aria-busy":a,"aria-label":`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,children:(0,D.jsx)(u,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{$e(t,e)},disabled:n||r||i||a,"aria-busy":r,"aria-label":`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,children:(0,D.jsx)(c,{size:12})})]})]},e.sessionId)})]})})(),k===`whatsapp`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:We[ze]}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{Ue()},children:(0,D.jsx)(w,{size:12})}),(0,D.jsx)(`span`,{children:String(Q.get(ze).length)})]})]}),Q.get(ze).map(e=>{let t=be(e.lastMessageAt);return(0,D.jsxs)(`button`,{type:`button`,className:`conv${te===e.sessionId?` active`:``}`,onClick:()=>{S(e),b()},title:e.title,children:[(0,D.jsx)(fe,{channel:e.channel,size:14}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.operatorName??e.whatsappName??e.senderId??e.title})}),t&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]},e.sessionId)})]}),(0,D.jsx)(Se,{}),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:s?(0,D.jsx)(`img`,{src:s,alt:T}):O}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:T}),(0,D.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),R&&(0,D.jsx)(`div`,{className:`copy-toast${R.failed?` copy-toast-failed`:``}`,role:`status`,children:R.message}),(0,D.jsx)(ge,{error:le,onClose:()=>B(null)})]})}var G=5e3;function Se(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},G))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,D.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var K=`admin-sidebar-collapsed`,q=`admin-sidebar-drawer-open`;function Ce(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function we(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}function Te(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function J(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}var Y=720;function Ee(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function De(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,operatorName:null,whatsappName:null,lastMessageAt:null}}function Oe(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,E.useState)(()=>Ce()),[d,f]=(0,E.useState)(()=>Te()),[p,m]=(0,E.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Y}px)`).matches),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Y}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _=(0,E.useCallback)(e=>{we(e),u(e)},[]),v=(0,E.useCallback)(e=>{J(e),f(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]),(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=De(window.location.pathname,window.location.search);e&&(g(e),console.info(`[admin-ui] wa-hydrate route=/ sessionId=${e.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let ee=(0,E.useCallback)(e=>{if(e===null){g(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Ee(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?g(e):window.location.href=n.href},[]),y=p?d:!l,b=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),v(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),_(!e)}},[l,d,_,v]),x=(0,E.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`);let t=e===`data`?`/data`:e===`graph`?`/graph`:`/browser`;window.location.href=t},[]),te={collapsed:l,mobileDrawerOpen:d,sidebarOpen:y,onToggleSidebar:b,setMobileDrawerOpen:v,selectedWhatsapp:h,onClearWhatsapp:()=>g(null)};return(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(V,{businessName:n,onNavigate:x,onToggleSidebar:b,sidebarOpen:y,onLogout:r}),(0,D.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(xe,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>v(!1),collapsed:l,mobileDrawerOpen:d,selectedWhatsappId:h?.sessionId??null,onSelectWhatsappConversation:ee}),typeof s==`function`?s(te):s]}),d&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>v(!1)}),c]})}export{ue as a,T as c,ne as d,b as f,m as g,h,le as i,re as l,g as m,_e as n,R as o,_ as p,me as r,oe as s,Oe as t,w as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as e}from"./useSelectionMode-
|
|
1
|
+
import{l as e}from"./useSelectionMode-DvBm4di-.js";var t=e();function n({checked:e,onChange:n,label:r,disabled:i}){return(0,t.jsxs)(`label`,{className:`maxy-checkbox${i?` maxy-checkbox--disabled`:``}`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>n(e.target.checked),disabled:i}),(0,t.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),r&&(0,t.jsx)(`span`,{className:`maxy-checkbox__label`,children:r})]})}export{n as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-hZ5bdL8b.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-DkP2rJdF.js";import{t as f}from"./Checkbox-CsQq7YPC.js";var p=i(),m=e(r(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),o(`open`)},a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>{a.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${a.readyState}`),o(`error`))},()=>a.close()},[e,t,n]),{turns:r,status:a}}var O=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function k(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:O(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:O(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 A(e,t){let[n,r]=(0,m.useState)([]);return(0,m.useEffect)(()=>{if(typeof fetch!=`function`)return;let n=!0,i=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(i).then(e=>e.ok?e.json():{entries:[]}).then(e=>{n&&r(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{n&&r([])}),()=>{n=!1}},[e,t]),n}function j(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function M({label:e,ts:t}){return(0,b.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:e}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(t)})]})}function N({turn:e}){let[t,n]=(0,m.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,b.jsxs)(`div`,{className:i,children:[(0,b.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,b.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,b.jsx)(`span`,{className:`wa-who`,children:a}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(e.ts)})]}),t&&(0,b.jsx)(`pre`,{className:`wa-code`,children:o})]})}function P({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.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,b.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,b.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,b.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,b.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(e.ts)})]}),r&&(0,b.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function F(e,t){switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(M,{label:`Operator`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(M,{label:`Operator (web)`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(M,{label:`Agent`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`tool-call`:case`tool-result`:return(0,b.jsx)(N,{turn:e},t)}}function I(e,t,n){return e.map((e,r)=>e.kind===`turn`?F(e.turn,r):(0,b.jsx)(P,{entry:e.entry,sessionId:t,sessionKey:n},r))}function L({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n),a=k(r,A(e,n)),o=(0,m.useRef)(null),s=(0,m.useRef)(!0),[c,l]=(0,m.useState)(!0),u=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;s.current=t,l(e=>e===t?e:t)};return(0,m.useLayoutEffect)(()=>{let e=o.current;e&&s.current&&(e.scrollTop=e.scrollHeight)},[r]),(0,b.jsxs)(`div`,{className:`wa-reader`,children:[(0,b.jsx)(`div`,{className:`wa-reader-thread`,ref:o,onScroll:()=>{let e=o.current;e&&u(e)},children:(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),I(a,e,n)]})}),!c&&(0,b.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=o.current;e&&(e.scrollTop=e.scrollHeight,s.current=!0,l(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}function R(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{console.info(`[admin-ui] remote-auth sign-out → /__remote-auth/logout`),window.location.href=`/__remote-auth/logout`}}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(L,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(R,{}));
|
|
1
|
+
import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-DvBm4di-.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-CnslFKoX.js";import{t as f}from"./Checkbox-Dmc64qme.js";var p=i(),m=e(r(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),o(`open`)},a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>{a.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${a.readyState}`),o(`error`))},()=>a.close()},[e,t,n]),{turns:r,status:a}}var O=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function k(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:O(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:O(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 A(e,t){let[n,r]=(0,m.useState)([]);return(0,m.useEffect)(()=>{if(typeof fetch!=`function`)return;let n=!0,i=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(i).then(e=>e.ok?e.json():{entries:[]}).then(e=>{n&&r(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{n&&r([])}),()=>{n=!1}},[e,t]),n}function j(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function M(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function N({label:e,ts:t}){return(0,b.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:e}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(t)})]})}function P({turn:e}){let[t,n]=(0,m.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,b.jsxs)(`div`,{className:i,children:[(0,b.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,b.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,b.jsx)(`span`,{className:`wa-who`,children:a}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(e.ts)})]}),t&&(0,b.jsx)(`pre`,{className:`wa-code`,children:o})]})}function F({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.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,b.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,b.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,b.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,b.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,b.jsx)(`time`,{className:`wa-time`,children:j(e.ts)})]}),r&&(0,b.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function I(e,t){switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(N,{label:`Operator`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(N,{label:`Operator (web)`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,b.jsx)(N,{label:`Agent`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(N,{label:`Agent`,ts:e.ts}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(N,{label:`Agent`,ts:e.ts}),(0,b.jsxs)(`p`,{className:`wa-doc`,children:[`📎 sent document(s): `,e.files.map(M).join(`, `)]}),e.caption&&(0,b.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`tool-call`:case`tool-result`:return(0,b.jsx)(P,{turn:e},t)}}function L(e,t,n){return e.map((e,r)=>e.kind===`turn`?I(e.turn,r):(0,b.jsx)(F,{entry:e.entry,sessionId:t,sessionKey:n},r))}function R({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n),a=k(r,A(e,n)),o=(0,m.useRef)(null),s=(0,m.useRef)(!0),[c,l]=(0,m.useState)(!0),u=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;s.current=t,l(e=>e===t?e:t)};return(0,m.useLayoutEffect)(()=>{let e=o.current;e&&s.current&&(e.scrollTop=e.scrollHeight)},[r]),(0,b.jsxs)(`div`,{className:`wa-reader`,children:[(0,b.jsx)(`div`,{className:`wa-reader-thread`,ref:o,onScroll:()=>{let e=o.current;e&&u(e)},children:(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),L(a,e,n)]})}),!c&&(0,b.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=o.current;e&&(e.scrollTop=e.scrollHeight,s.current=!0,l(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}function z(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{console.info(`[admin-ui] remote-auth sign-out → /__remote-auth/logout`),window.location.href=`/__remote-auth/logout`}}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(R,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(z,{}));
|