@ensocode/server 0.3.14 → 0.3.15-beta.234
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/README.md +11 -1
- package/out/phone/assets/{EditDiff-7At9BpWJ.js → EditDiff-DlIQ0NvB.js} +1 -1
- package/out/phone/assets/{ReadFileView-CFkjh0Xx.js → ReadFileView-hlSV-q1S.js} +1 -1
- package/out/phone/assets/{abnfDiagram-VCTEODGH-D4384sfe.js → abnfDiagram-VCTEODGH-cWLl_02_.js} +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-WvHUAPXe.js +1 -0
- package/out/phone/assets/{architectureDiagram-5GKGNRK7-CjzMXFHb.js → architectureDiagram-5GKGNRK7-QEXMUvv5.js} +1 -1
- package/out/phone/assets/{blockDiagram-I7D4REHJ-COX4_2NT.js → blockDiagram-I7D4REHJ-FzQ3vEDv.js} +1 -1
- package/out/phone/assets/{c4Diagram-7LVT6UL2-C0PHCrzg.js → c4Diagram-7LVT6UL2-6iRtBvvT.js} +1 -1
- package/out/phone/assets/channel-t2MFK_dg.js +1 -0
- package/out/phone/assets/{chunk-4HAMMTFA-BSqiGn28.js → chunk-4HAMMTFA-4eZjiClJ.js} +1 -1
- package/out/phone/assets/{chunk-75Z2AOVW-7eocu_Pa.js → chunk-75Z2AOVW-BTVSMC3k.js} +1 -1
- package/out/phone/assets/{chunk-DU6HZSFF-DMttOQUE.js → chunk-DU6HZSFF-Ca9U1rWL.js} +1 -1
- package/out/phone/assets/{chunk-F27PBJKO-BFNRrOvq.js → chunk-F27PBJKO-iUczI4_Q.js} +1 -1
- package/out/phone/assets/{chunk-GMAD6QVW-DPVV1Shj.js → chunk-GMAD6QVW-DlbCwmvq.js} +1 -1
- package/out/phone/assets/{chunk-GVQU2GXP-YataTcA_.js → chunk-GVQU2GXP-DlijzCAw.js} +1 -1
- package/out/phone/assets/{chunk-IMKFNOWR-DBQKd74U.js → chunk-IMKFNOWR-B1BOj8O6.js} +1 -1
- package/out/phone/assets/{chunk-L3NEJ4N5-DXfrfXkv.js → chunk-L3NEJ4N5-Fr_w5bRg.js} +1 -1
- package/out/phone/assets/{chunk-OSK3NFVY-DWr7pP6Q.js → chunk-OSK3NFVY-CccDEhXi.js} +1 -1
- package/out/phone/assets/{chunk-P2QGCYS3-C_qNKS0g.js → chunk-P2QGCYS3-Dn46j2El.js} +1 -1
- package/out/phone/assets/{chunk-POPQ4Y6H-BhJK3UtM.js → chunk-POPQ4Y6H-BQchiHrQ.js} +1 -1
- package/out/phone/assets/{chunk-PWAF6VOD-MmcwGVgC.js → chunk-PWAF6VOD-BENw9N2v.js} +1 -1
- package/out/phone/assets/{chunk-SHT3W25Y-BQHA3p2Q.js → chunk-SHT3W25Y-C93BlEB0.js} +1 -1
- package/out/phone/assets/{chunk-SVP7TREG-DbQH56Ci.js → chunk-SVP7TREG-wfL37BUq.js} +1 -1
- package/out/phone/assets/{chunk-TICWLB2K-pixKba1z.js → chunk-TICWLB2K-C9-wZ6kk.js} +1 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-CM29lfur.js +1 -0
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-CM29lfur.js +1 -0
- package/out/phone/assets/{codeHighlighter-CrZcFhK_.js → codeHighlighter-DQ-g-VWX.js} +1 -1
- package/out/phone/assets/{cynefin-OW5HDTMX-67ETi-0P.js → cynefin-OW5HDTMX-DamvwfM9.js} +1 -1
- package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-C3wqlm_-.js → cynefinDiagram-5FMLGOSQ-Coz1le1N.js} +1 -1
- package/out/phone/assets/{dagre-GXQ25YYZ-DTC1fZsc.js → dagre-GXQ25YYZ-ByJC9Z6k.js} +1 -1
- package/out/phone/assets/desk-XkzvZXuU.js +70 -0
- package/out/phone/assets/{diagram-S7CK7UJ4-uqcU7OpS.js → diagram-S7CK7UJ4-BabBefXt.js} +1 -1
- package/out/phone/assets/{diagram-UQ7AKVKN-BQ6K9f6g.js → diagram-UQ7AKVKN-DEX56Otl.js} +1 -1
- package/out/phone/assets/{diagram-VSXAHHWV-CDzRWkI9.js → diagram-VSXAHHWV-GeNN1ZwW.js} +1 -1
- package/out/phone/assets/{diagram-VX7I27RA-CvI10CG1.js → diagram-VX7I27RA-DkclPqXj.js} +1 -1
- package/out/phone/assets/{diagram-Z3DM3KII-DM8G_CIZ.js → diagram-Z3DM3KII-CDKrxb7_.js} +1 -1
- package/out/phone/assets/{ebnfDiagram-PWID7BFC-BBbLoaIE.js → ebnfDiagram-PWID7BFC-B-lRq0nU.js} +1 -1
- package/out/phone/assets/{erDiagram-RLTQ6QDP-Dz98FGLq.js → erDiagram-RLTQ6QDP-2PdYpZdI.js} +1 -1
- package/out/phone/assets/eventmodeling-NTZA5JFV-DBO84WXk.js +1 -0
- package/out/phone/assets/flowDiagram-HODETNUW-89Bcp6BV.js +1 -0
- package/out/phone/assets/{ganttDiagram-EL5Y4UJY-BADRjlHl.js → ganttDiagram-EL5Y4UJY-XG84VKNq.js} +1 -1
- package/out/phone/assets/{gitGraph-4MIJSDKK-DQGKRsA2.js → gitGraph-4MIJSDKK-BqrA_WVv.js} +1 -1
- package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-DrLRujhH.js → gitGraphDiagram-WWUBYQGX-BAIxr-mN.js} +1 -1
- package/out/phone/assets/{info-A6RAGUB7-b7IbwKqs.js → info-A6RAGUB7-DE-jKSbG.js} +1 -1
- package/out/phone/assets/{infoDiagram-27XIBGKW-BNbXaMmR.js → infoDiagram-27XIBGKW-BSTxH5Al.js} +1 -1
- package/out/phone/assets/{ishikawaDiagram-5VMMS53U-B3SG131F.js → ishikawaDiagram-5VMMS53U-zOO97Npq.js} +1 -1
- package/out/phone/assets/{journeyDiagram-3NMN7TZE-BoRfNykb.js → journeyDiagram-3NMN7TZE-dSMVlg_5.js} +1 -1
- package/out/phone/assets/{kanban-definition-UXKFOSKX-D0tKrJ8_.js → kanban-definition-UXKFOSKX-DHok-qdM.js} +1 -1
- package/out/phone/assets/{line-W1HWn4B7.js → line-C5TJMvf6.js} +1 -1
- package/out/phone/assets/main-Bk2Gcz5l.css +2 -0
- package/out/phone/assets/main-DNK2uR8l.js +277 -0
- package/out/phone/assets/{mermaid-parser.core-CpGE7UgS.js → mermaid-parser.core-CrJ82mWd.js} +3 -3
- package/out/phone/assets/{mermaid.core-wueTI3u_.js → mermaid.core-CkfKqc8K.js} +4 -4
- package/out/phone/assets/{mindmap-definition-YA3MSWOX-BDctzErY.js → mindmap-definition-YA3MSWOX-DD-W0NPL.js} +1 -1
- package/out/phone/assets/{packet-AYTQ26CC-C0YWsXol.js → packet-AYTQ26CC-DEZk6B2e.js} +1 -1
- package/out/phone/assets/{pegDiagram-XKGWAZYB-C97XjNI7.js → pegDiagram-XKGWAZYB-KND-JwT0.js} +1 -1
- package/out/phone/assets/{pie-WAS4IAKB-BxuJ1GKP.js → pie-WAS4IAKB-DS5oCOdm.js} +1 -1
- package/out/phone/assets/{pieDiagram-E7YTZNPT-SP4DeWDw.js → pieDiagram-E7YTZNPT-CfWh8T4Z.js} +1 -1
- package/out/phone/assets/{quadrantDiagram-AXDQQJYC-DDHL4rrG.js → quadrantDiagram-AXDQQJYC-CbquaKYM.js} +1 -1
- package/out/phone/assets/{radar-RG4KPBEZ-AzVB8zoH.js → radar-RG4KPBEZ-C0kqKhsd.js} +1 -1
- package/out/phone/assets/{railroad-74A4TZTK-CA2_A72l.js → railroad-74A4TZTK-C5WV19mk.js} +1 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-BqkB5NuR.js +1 -0
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-DF9ncZF9.js +1 -0
- package/out/phone/assets/railroad-peg-WCYAUIDC-CrvTMEVw.js +1 -0
- package/out/phone/assets/{railroadDiagram-O6MQD6OU-D5zpQ5kq.js → railroadDiagram-O6MQD6OU-CmkCOdfu.js} +1 -1
- package/out/phone/assets/{requirementDiagram-BXWQKSXE-DkQKt5hJ.js → requirementDiagram-BXWQKSXE-CrQKPUwx.js} +1 -1
- package/out/phone/assets/{sankeyDiagram-P5KCCOFB-xeXrVMVr.js → sankeyDiagram-P5KCCOFB-CBCG-Eyn.js} +1 -1
- package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-BOiNtyS8.js → sequenceDiagram-WJ2MYXX4-D9oVD380.js} +1 -1
- package/out/phone/assets/shellUpdate-2rxcUhg5.js +5 -0
- package/out/phone/assets/{stateDiagram-D77RDMKH-Bs8LX9-n.js → stateDiagram-D77RDMKH-VNnCDAvS.js} +1 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Qadztnwb.js +1 -0
- package/out/phone/assets/{swimlanes-42K2YHIH-DQVYfgSI.js → swimlanes-42K2YHIH-DFtKlQwi.js} +1 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-BG4PsK7t.js +8 -0
- package/out/phone/assets/{timeline-definition-24CTP7MA-BlpgdxeN.js → timeline-definition-24CTP7MA-BwrAy7Qu.js} +1 -1
- package/out/phone/assets/{treeView-Q6P3EWNA-D0PiggHr.js → treeView-Q6P3EWNA-BLyQtiYC.js} +1 -1
- package/out/phone/assets/{treemap-WGGIJYW6-DA07Kvo0.js → treemap-WGGIJYW6-gub1bjDX.js} +1 -1
- package/out/phone/assets/{vennDiagram-4TSXK5OY-BtvfF1a4.js → vennDiagram-4TSXK5OY-DayfmvoI.js} +1 -1
- package/out/phone/assets/{wardley-WFR3VGLG-Db-UrSZJ.js → wardley-WFR3VGLG-B5_pluIE.js} +1 -1
- package/out/phone/assets/{wardleyDiagram-VM6X3IG4-CaBnqFYM.js → wardleyDiagram-VM6X3IG4-CHS5ryk0.js} +1 -1
- package/out/phone/assets/{xychartDiagram-S5SC5T6Z-Bbzz9YwS.js → xychartDiagram-S5SC5T6Z-C21zSdz1.js} +1 -1
- package/out/phone/desk.html +3 -3
- package/out/phone/index.html +4 -4
- package/out/phone/sw.js +2 -2
- package/out/renderer/assets/EditDiff-DJaW24DH.js +1 -0
- package/out/renderer/assets/ReadFileView-B1RfgY1_.js +4 -0
- package/out/renderer/assets/SidePanel-CXOSOIj_.js +48 -0
- package/out/renderer/assets/abnfDiagram-VCTEODGH-DteC7eOG.js +1 -0
- package/out/renderer/assets/{arc-DXzwxP4j.js → arc-BafilblL.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-5GKGNRK7-Bcykp-Fb.js → architectureDiagram-5GKGNRK7-BXxAIsNI.js} +2 -2
- package/out/renderer/assets/{blockDiagram-I7D4REHJ-P7zMiiL3.js → blockDiagram-I7D4REHJ-Bt4I5z76.js} +1 -1
- package/out/renderer/assets/{c4Diagram-7LVT6UL2-BVD9zEE8.js → c4Diagram-7LVT6UL2-Dg1rhQSn.js} +1 -1
- package/out/renderer/assets/channel-CpN2DlDo.js +1 -0
- package/out/renderer/assets/{chunk-2Q5K7J3B-BXj05DaP.js → chunk-2Q5K7J3B-Bea4O-pP.js} +1 -1
- package/out/renderer/assets/{chunk-5VM5RSS4-D-SpodcG.js → chunk-5VM5RSS4-9g4O6TgX.js} +1 -1
- package/out/renderer/assets/{chunk-F27PBJKO-ORLEQ9sv.js → chunk-F27PBJKO-CQFAhmZp.js} +1 -1
- package/out/renderer/assets/{chunk-IMKFNOWR-1lhHjr20.js → chunk-IMKFNOWR-DZKvnXil.js} +1 -1
- package/out/renderer/assets/{chunk-JWPE2WC7-BgmlC9Vl.js → chunk-JWPE2WC7-UkNkhirX.js} +1 -1
- package/out/renderer/assets/{chunk-POPQ4Y6H-DPEfkZnH.js → chunk-POPQ4Y6H-D3CSUp94.js} +1 -1
- package/out/renderer/assets/{chunk-SVP7TREG-7_S5Geoi.js → chunk-SVP7TREG-F3dgPzel.js} +1 -1
- package/out/renderer/assets/{chunk-TICWLB2K-BKi8yvLf.js → chunk-TICWLB2K-URu59zvj.js} +1 -1
- package/out/renderer/assets/{chunk-XXDRQBXY-PfB25f1D.js → chunk-XXDRQBXY-DRFxCPER.js} +1 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-D-KG_eK-.js +1 -0
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-D-KG_eK-.js +1 -0
- package/out/renderer/assets/cose-bilkent-JH36ORCC-Bx5VqEhK.js +1 -0
- package/out/renderer/assets/{cynefin-OW5HDTMX-Dr9W26Pe.js → cynefin-OW5HDTMX-YKYl0dFh.js} +1 -1
- package/out/renderer/assets/cynefinDiagram-5FMLGOSQ-DaHqCls4.js +62 -0
- package/out/renderer/assets/{dagre-GXQ25YYZ-Dt2pulYx.js → dagre-GXQ25YYZ-CRqSls6Q.js} +1 -1
- package/out/renderer/assets/{diagram-S7CK7UJ4-Bx-0FuVR.js → diagram-S7CK7UJ4-_oJhPbvH.js} +1 -1
- package/out/renderer/assets/diagram-UQ7AKVKN-B7P-4UYL.js +41 -0
- package/out/renderer/assets/{diagram-VSXAHHWV-CI0jUOHM.js → diagram-VSXAHHWV--0uBugR7.js} +1 -1
- package/out/renderer/assets/diagram-VX7I27RA-IaMWXRBT.js +24 -0
- package/out/renderer/assets/diagram-Z3DM3KII-BLCY3C4h.js +24 -0
- package/out/renderer/assets/ebnfDiagram-PWID7BFC-CUYHhexz.js +1 -0
- package/out/renderer/assets/{erDiagram-RLTQ6QDP-UjxTTQ7M.js → erDiagram-RLTQ6QDP-BIOsECZV.js} +1 -1
- package/out/renderer/assets/{flowDiagram-HODETNUW-BVuwOxKp.js → flowDiagram-HODETNUW-DjggEdce.js} +1 -1
- package/out/renderer/assets/ganttDiagram-EL5Y4UJY-Dik61bQB.js +292 -0
- package/out/renderer/assets/gitGraphDiagram-WWUBYQGX-BrPFNa7W.js +106 -0
- package/out/renderer/assets/index-CtOLwaEJ.css +1 -0
- package/out/renderer/assets/index-mVE4g58q.js +3003 -0
- package/out/renderer/assets/infoDiagram-27XIBGKW-ZfCvFQE5.js +2 -0
- package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-B2YfGNEH.js → ishikawaDiagram-5VMMS53U-BhteuTmM.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-3NMN7TZE-fUfanA7T.js → journeyDiagram-3NMN7TZE-BJyr-G3R.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UXKFOSKX-DU0d3NVH.js → kanban-definition-UXKFOSKX-CJyl9IUl.js} +1 -1
- package/out/renderer/assets/{layout-C0hE7llw.js → layout-oTkojEy1.js} +1 -1
- package/out/renderer/assets/{linear-BXPh0BlC.js → linear-qICDecPr.js} +1 -1
- package/out/renderer/assets/{mermaid.core-DlBAsGZ7.js → mermaid.core-F0flUThf.js} +5 -5
- package/out/renderer/assets/{mindmap-definition-YA3MSWOX-DUIiyta9.js → mindmap-definition-YA3MSWOX-pG7PXlKk.js} +1 -1
- package/out/renderer/assets/pegDiagram-XKGWAZYB-CwO9p66t.js +1 -0
- package/out/renderer/assets/{pieDiagram-E7YTZNPT-DsaSjWfA.js → pieDiagram-E7YTZNPT-BpqTKO7A.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-BpWn5xT_.js → quadrantDiagram-AXDQQJYC-Ci1QOcG6.js} +1 -1
- package/out/renderer/assets/railroadDiagram-O6MQD6OU-Be-ymk25.js +1 -0
- package/out/renderer/assets/{requirementDiagram-BXWQKSXE-CMIMPMzx.js → requirementDiagram-BXWQKSXE-Dotur23i.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-CKqneOc7.js → sankeyDiagram-P5KCCOFB-BlTTRpKU.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-azbHkcGk.js → sequenceDiagram-WJ2MYXX4-C_llXVvH.js} +1 -1
- package/out/renderer/assets/{sessionChanges--o0RBCJW.js → sessionChanges-BpPkx6v0.js} +5 -5
- package/out/renderer/assets/sizeCapture-INFHLROL-xhuCXQI9.js +1 -0
- package/out/renderer/assets/stateDiagram-D77RDMKH-BfESnkCR.js +1 -0
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-C7QWw0La.js +1 -0
- package/out/renderer/assets/swimlanes-42K2YHIH-DX8_KJTt.js +1 -0
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B7JGQCYf.js +8 -0
- package/out/renderer/assets/{timeline-definition-24CTP7MA-DdVDUmce.js → timeline-definition-24CTP7MA-DIoNEHAB.js} +1 -1
- package/out/renderer/assets/{vennDiagram-4TSXK5OY-DP6DTjdX.js → vennDiagram-4TSXK5OY-KrS4uyWo.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-DYJsuZCs.js → wardleyDiagram-VM6X3IG4-D4i6zXyf.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-CloAJCw-.js → xychartDiagram-S5SC5T6Z-DpCpSTPN.js} +1 -1
- package/out/renderer/index.html +2 -3
- package/out/renderer/web-preload.js +1 -1
- package/out/server/agent.js +258 -82
- package/out/server/chunks/{builtinOccupancy-Ci-Szozb.js → builtinOccupancy-zo5-z-s5.js} +6 -6
- package/out/server/chunks/{dispatchModel-DJxnHup9.js → dispatchModel-D7papgSj.js} +4 -3
- package/out/server/chunks/{gpuBackendInstall-snisWLXN.js → gpuBackendInstall-xFEdr70P.js} +2 -2
- package/out/server/chunks/{loadProvider-Uq3i7kKZ.js → loadProvider-ChfeR5km.js} +2 -2
- package/out/server/chunks/{menuSkills-BEtW-Is6.js → menuSkills-DC4qs2MC.js} +5 -4
- package/out/server/chunks/{projectCode-D9lgShsp.js → projectCode-BAgpkYYS.js} +2 -2
- package/out/server/chunks/{registry-R2KRdU8n.js → registry-G4AKEQtl.js} +3 -3
- package/out/server/chunks/{sendImage-CCjNsa-D.js → sendImage-BmenO8Vx.js} +208 -61
- package/out/server/chunks/{toolParams-DVs5d3F9.js → toolParams-0GakTs9V.js} +2 -2
- package/out/server/chunks/{web-BIJOMDlz.js → web-9MujZLkq.js} +30 -16
- package/out/server/chunks/{workflowPresets-DVbQh2el.js → workflowPresets-CTv2r-Sh.js} +242 -158
- package/out/server/index.js +1664 -732
- package/out/server/memory-service.js +12 -5
- package/package.json +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-vDamN_Vr.js +0 -1
- package/out/phone/assets/channel-TsMJYH0f.js +0 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-Bhtnzu97.js +0 -1
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-Bhtnzu97.js +0 -1
- package/out/phone/assets/desk-B382G0e_.js +0 -52
- package/out/phone/assets/eventmodeling-NTZA5JFV-BGT2L4_J.js +0 -1
- package/out/phone/assets/flowDiagram-HODETNUW-CpTX9nm5.js +0 -1
- package/out/phone/assets/main-Bc8DQVa6.css +0 -2
- package/out/phone/assets/main-Bez4gfKe.js +0 -281
- package/out/phone/assets/railroad-abnf-HS5TGJTU-CTHhRGvc.js +0 -1
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-CS68P4fL.js +0 -1
- package/out/phone/assets/railroad-peg-WCYAUIDC-BqCcrVdf.js +0 -1
- package/out/phone/assets/shellUpdate-C4yk9AaU.js +0 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-nBP_YibA.js +0 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-BkfzXxS-.js +0 -8
- package/out/renderer/assets/EditDiff-C9JBUR0o.js +0 -1
- package/out/renderer/assets/File-BIf-onMm.js +0 -1
- package/out/renderer/assets/ReadFileView-C5AKNlFU.js +0 -4
- package/out/renderer/assets/SidePanel-DkSc3og9.js +0 -48
- package/out/renderer/assets/Virtualizer-tZu4hGtC.js +0 -1345
- package/out/renderer/assets/abnfDiagram-VCTEODGH-DxBBUZxF.js +0 -1
- package/out/renderer/assets/channel-7bWV5QTy.js +0 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-mgQwYiWM.js +0 -1
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-mgQwYiWM.js +0 -1
- package/out/renderer/assets/cose-bilkent-JH36ORCC-C246yayw.js +0 -1
- package/out/renderer/assets/cynefinDiagram-5FMLGOSQ-B3Jtuns2.js +0 -62
- package/out/renderer/assets/cytoscape-fcose-CJat50hU.js +0 -1
- package/out/renderer/assets/cytoscape.esm-DzSz-X2X.js +0 -321
- package/out/renderer/assets/diagram-UQ7AKVKN-D-8o1p4p.js +0 -41
- package/out/renderer/assets/diagram-VX7I27RA-Byl54mOd.js +0 -24
- package/out/renderer/assets/diagram-Z3DM3KII-Kf_GIJ7p.js +0 -24
- package/out/renderer/assets/ebnfDiagram-PWID7BFC-BbOdw7R1.js +0 -1
- package/out/renderer/assets/ganttDiagram-EL5Y4UJY-BpBSO-4X.js +0 -292
- package/out/renderer/assets/gitGraphDiagram-WWUBYQGX-b72vZ1j2.js +0 -106
- package/out/renderer/assets/globals-2G408HiJ.css +0 -1
- package/out/renderer/assets/globals-BqVjlAT_.js +0 -673
- package/out/renderer/assets/index-AHhNcASr.js +0 -113
- package/out/renderer/assets/infoDiagram-27XIBGKW-CtnN4sif.js +0 -2
- package/out/renderer/assets/manifest-DoBt8euy.js +0 -525
- package/out/renderer/assets/pegDiagram-XKGWAZYB-yP15oXPx.js +0 -1
- package/out/renderer/assets/railroadDiagram-O6MQD6OU-BnXhwCom.js +0 -1
- package/out/renderer/assets/settings-D5R80op8.js +0 -28
- package/out/renderer/assets/sizeCapture-INFHLROL-C3uhIZ1e.js +0 -1
- package/out/renderer/assets/stateDiagram-D77RDMKH-CrGab2Ck.js +0 -1
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-k_H7O8MU.js +0 -1
- package/out/renderer/assets/swimlanes-42K2YHIH-6aX1l7C2.js +0 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-D2XerlPy.js +0 -8
- package/out/renderer/settings.html +0 -23
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./EditDiff-C9JBUR0o.js","./globals-BqVjlAT_.js","./globals-2G408HiJ.css","./sessionChanges--o0RBCJW.js","./Virtualizer-tZu4hGtC.js","./ReadFileView-C5AKNlFU.js","./File-BIf-onMm.js","./SidePanel-DkSc3og9.js","./manifest-DoBt8euy.js","./SidePanel-DN2RL6QD.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as f,aY as qe,aX as So,j as n,aj as Ge,hz as bg,hA as yg,hB as em,hC as YI,hD as Vw,hE as Hw,hF as XI,hG as QI,cK as JI,bt as pe,c4 as os,hH as Ou,hI as Wc,hJ as ZI,hK as e5,ax as _,hL as t5,u as z,hM as bi,hN as yi,hO as wi,fL as ro,a_ as J,hP as Ww,fX as Uw,hQ as wg,hR as qw,bI as tm,bJ as nm,bE as zo,cR as Gw,bH as sm,hS as Ah,hT as Po,fG as qs,bh as Qn,hU as Bd,bx as Fd,gR as ll,b8 as Jt,hV as Eo,hW as ie,hX as n5,hY as Eh,dt as Pn,ay as cn,az as dn,aA as un,aB as rn,aC as ys,aM as ts,aN as s5,aO as fe,bO as Ie,g2 as di,ca as r5,dQ as Rh,dR as Mh,dS as Ph,dT as Dh,dU as Oh,dV as Lh,g5 as Kw,bT as zd,d$ as o5,e0 as i5,e1 as a5,ef as _h,dd as $o,dA as Vo,fP as Yw,bj as Do,hZ as l5,h_ as Rr,fo as Xw,h$ as $d,i0 as c5,fj as Uc,bl as fn,aZ as d5,cq as Ho,i1 as u5,i2 as f5,i3 as Qw,i4 as m5,i5 as h5,hp as Jr,fk as Ai,bv as Mr,bK as rm,i6 as qc,i7 as qn,gN as p5,gV as Jw,cw as Yr,cx as Xr,cy as Qr,cz as Kt,es as x5,bw as Dn,i8 as g5,by as Bh,t as v5,eB as ji,hj as ws,i9 as cl,ia as b5,ib as y5,ic as w5,id as j5,ie as k5,ig as N5,ih as S5,ii as C5,ij as I5,ik as T5,il as A5,im as E5,io as Fh,ip as R5,iq as M5,ir as P5,is as D5,it as O5,iu as L5,iv as _5,iw as B5,ix as Zw,iy as F5,iz as z5,iA as $5,iB as V5,dm as dl,iC as H5,iD as W5,iE as U5,iF as q5,iG as G5,iH as K5,dn as Y5,iI as X5,iJ as Q5,iK as J5,iL as Z5,g9 as eT,fn as ej,hk as Vd,iM as tT,iN as Vn,bb as On,bd as ul,g_ as Bs,iO as Wn,iP as nT,cL as tj,en as sT,fl as nj,bm as Fn,iQ as rT,iR as sj,iS as oT,iT,iU as aT,g1 as Hd,iV as lT,c9 as Zr,iW as cT,iX as dT,iY as uT,iZ as fT,bn as rj,fh as oj,dK as fl,ba as oo,i_ as zh,i$ as jg,fi as mT,j0 as hT,cJ as ij,b9 as _t,j1 as kg,j2 as aj,j3 as pT,j4 as lj,j5 as xT,j6 as gT,j7 as vT,j8 as bT,j9 as yT,ja as cj,jb as wT,jc as jT,jd as om,je as kT,jf as NT,jg as ST,jh as CT,ji as IT,jj as TT,jk as AT,jl as ET,jm as RT,jn as MT,jo as PT,jp as Hl,bS as Or,jq as Ms,jr as Ps,js as Ds,c3 as cs,jt as dj,ju as DT,jv as OT,jw as uj,jx as Ng,eS as LT,jy as _T,jz as fj,jA as BT,db as FT,jB as zT,jC as $T,jD as mj,jE as VT,bR as Wo,jF as HT,aD as In,jG as hj,jH as Sg,jI as WT,jJ as UT,hm as pj,jK as qT,jL as GT,jM as KT,jN as YT,bA as $h,bU as Vh,bB as Os,eh as im,ha as Cg,eP as Hh,ep as Gi,bQ as Lr,bc as xj,jO as XT,jP as gj,jQ as QT,jR as JT,jS as ZT,jT as eA,jU as am,jV as vj,jW as tA,jX as nA,aQ as vs,jY as sA,jZ as rA,j_ as oA,j$ as iA,k0 as aA,k1 as lA,k2 as cA,k3 as bj,k4 as Ig,k5 as Tg,k6 as dA,k7 as Ag,k8 as lm,k9 as cm,ka as si,kb as uA,kc as fA,kd as mA,ke as Eg,kf as hA,kg as pA,kh as xA,ki as Rg,kj as gA,kk as Lu,kl as _u,km as vA,g3 as Ei,h9 as yj,kn as Wh,bV as Wd,bz as Uh,aP as bs,ko as bA,kp as yA,kq as wA,kr as jA,ks as kA,kt as NA,ku as SA,cF as qh,dc as Oo,kv as CA,kw as wj,kx as IA,ky as Gc,kz as jj,kA as kj,kB as Mg,fB as Pr,kC as TA,kD as AA,kE as EA,kF as Nj,eO as $t,kG as Sj,kH as RA,kI as MA,kJ as Dr,kK as PA,kL as Cj,kM as Ij,kN as Tj,kO as _a,kP as DA,kQ as OA,kR as LA,kS as dm,kT as _A,kU as BA,kV as FA,kW as zA,kX as $A,kY as VA,kZ as HA,k_ as WA,k$ as UA,eZ as Ot,eq as Gh,f3 as Aj,bi as rr,aE as Ht,gZ as Pg,l0 as Dg,l1 as Og,l2 as Ba,fd as Bu,h2 as Fu,aF as Gs,l3 as Kh,l4 as qA,l5 as Ej,l6 as GA,l7 as KA,l8 as Yh,l9 as is,la as YA,cQ as Rj,aG as Cr,aH as Ir,aI as Tr,aJ as Ar,aL as ir,eY as Xh,lb as Mj,eK as Ud,eL as qd,eM as ms,eN as wr,f2 as Pj,lc as Dj,ld as Oj,le as fa,lf as Kc,lg as Lj,lh as XA,li as QA,gT as JA,lj as ZA,lk as eE,ll as Qh,lm as tE,ln as nE,lo as _j,b_ as mr,b$ as hr,c0 as pr,c1 as Cn,lp as Bj,lq as Fj,lr as zj,c2 as Ri,fm as Jh,ls as $j,lt as Gd,lu as ds,e$ as Vj,eV as sE,eW as rE,f4 as oE,lv as iE,f6 as aE,lw as Hj,lx as lE,ly as cE,lz as dE,lA as uE,lB as Wj,lC as fE,lD as mE,lE as hE,c7 as Zh,lF as ep,lG as la,lH as tp,lI as np,bp as Lo,bW as sp,bY as rp,bk as dr,bX as op,lJ as pE,lK as Uj,lL as qj,lM as xE,lN as ma,cY as gE,c$ as Gj,cZ as vE,bD as Kd,lO as Kj,lP as bE,fV as yE,fU as wE,lQ as jE,dj as kE,lR as NE,lS as SE,dy as CE,lT as IE,lU as TE,lV as AE,dx as EE,lW as RE,lX as ME,dq as PE,c8 as DE,dr as OE,ds as LE,du as _E,dv as BE,dw as FE,dz as zE,lY as $E,lZ as VE,l_ as HE,l$ as WE,m0 as UE,m1 as qE,m2 as Yj,fF as Vs,m3 as GE,bg as ki,ho as um,m4 as KE,m5 as YE,m6 as ip,m7 as ap,m8 as lp,m9 as cp,cB as dp,ma as XE,mb as QE,mc as JE,eJ as Xj,eR as jo,eI as ZE,md as eR,me as tR,mf as nR,mg as Lg,mh as Qj,mi as Xo,eQ as _g,eU as sR,mj as rR,f0 as Bg,de as up,mk as Fg,hn as oR,c6 as fp,bL as iR,be as aR,ct as lR,ml as cR,mm as dR,mn as uR,mo as fR,mp as mR,M as Jj,mq as hR,fI as Yc,mr as Zj,ms as e1,mt as mp,bq as pR,mu as xR,mv as gR,mw as vR,mx as bR,my as zu,mz as zg,mA as yR,hf as t1,mB as wR,mC as hp,hb as jR,fx as Cs,fy as Is,mD as Fa,mE as Yd,bu as Ni,bs as Xd,br as n1,mF as kR,mG as s1,mH as NR,mI as SR,mJ as CR,mK as IR,mL as TR,hi as Xc,mM as AR,mN as ER,mO as RR,mP as MR,mQ as r1,mR as o1,mS as PR,mT as DR,fq as OR,mU as LR,mV as _R,gq as i1,bN as a1,cP as BR,mW as FR,mX as $g,mY as zR,mZ as $R,fS as VR,fR as HR,g4 as WR,hl as l1,m_ as c1,m$ as wc,n0 as d1,he as UR,bG as Vg,n1 as qR,bF as u1,n2 as GR,n3 as KR,n4 as YR,bM as f1,n5 as kr,n6 as Ts,n7 as Yn,h0 as Hg,g$ as XR,n8 as m1,dZ as QR,n9 as Qc,dO as JR,dP as ZR,fe as e3,fw as t3,na as h1,nb as p1,nc as Ki,nd as n3,ne as s3,nf as r3,ng as pp,nh as x1,ni as o3,nj as i3,nk as a3,fs as Wg,bC as l3,nl as c3,nm as d3,nn as Ug,gX as u3,cE as qg,cO as g1,no as f3,fz as m3,hc as h3,ge as p3,np as x3,gy as g3,gz as v3,fA as b3,nq as y3,hd as w3,h1 as j3,nr as k3,ns as N3,cU as S3,cv as C3,gW as I3,nt as T3,nu as A3,nv as E3,nw as Nr,nx as R3,ny as M3,nz as P3,nA as D3,nB as O3,nC as L3,nD as _3,nE as Gg,nF as Kg,nG as B3,fK as F3,nH as z3,nI as $3,nJ as V3,nK as H3,nL as W3,nM as U3,nN as q3,nO as G3,gf as K3,nP as Y3,nQ as Yg,nR as v1,gJ as X3,nS as Q3,nT as J3,nU as Z3,nV as eM,nW as tM,ft as $u,c_ as nM,hw as sM,hx as rM,ht as oM,hy as Xg,hu as iM,fu as aM,dW as lM,nX as cM,nY as dM,nZ as uM,n_ as fM,n$ as mM,fH as hM,o0 as pM,o1 as xM,C as gM,hq as vM,hr as bM,hs as yM}from"./globals-BqVjlAT_.js";function wM(){for(var e=arguments.length,t=new Array(e),s=0;s<e;s++)t[s]=arguments[s];return f.useMemo(()=>r=>{t.forEach(o=>o(r))},t)}const Qd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Mi(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function xp(e){return"nodeType"in e}function us(e){var t,s;return e?Mi(e)?e:xp(e)&&(t=(s=e.ownerDocument)==null?void 0:s.defaultView)!=null?t:window:window}function gp(e){const{Document:t}=us(e);return e instanceof t}function ml(e){return Mi(e)?!1:e instanceof us(e).HTMLElement}function b1(e){return e instanceof us(e).SVGElement}function Pi(e){return e?Mi(e)?e.document:xp(e)?gp(e)?e:ml(e)||b1(e)?e.ownerDocument:document:document:document}const Ks=Qd?f.useLayoutEffect:f.useEffect;function Jd(e){const t=f.useRef(e);return Ks(()=>{t.current=e}),f.useCallback(function(){for(var s=arguments.length,r=new Array(s),o=0;o<s;o++)r[o]=arguments[o];return t.current==null?void 0:t.current(...r)},[])}function jM(){const e=f.useRef(null),t=f.useCallback((r,o)=>{e.current=setInterval(r,o)},[]),s=f.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,s]}function za(e,t){t===void 0&&(t=[e]);const s=f.useRef(e);return Ks(()=>{s.current!==e&&(s.current=e)},t),s}function hl(e,t){const s=f.useRef();return f.useMemo(()=>{const r=e(s.current);return s.current=r,r},[...t])}function Jc(e){const t=Jd(e),s=f.useRef(null),r=f.useCallback(o=>{o!==s.current&&t?.(o,s.current),s.current=o},[]);return[s,r]}function Zc(e){const t=f.useRef();return f.useEffect(()=>{t.current=e},[e]),t.current}let Vu={};function pl(e,t){return f.useMemo(()=>{if(t)return t;const s=Vu[e]==null?0:Vu[e]+1;return Vu[e]=s,e+"-"+s},[e,t])}function y1(e){return function(t){for(var s=arguments.length,r=new Array(s>1?s-1:0),o=1;o<s;o++)r[o-1]=arguments[o];return r.reduce((i,a)=>{const l=Object.entries(a);for(const[c,u]of l){const d=i[c];d!=null&&(i[c]=d+e*u)}return i},{...t})}}const ui=y1(1),ed=y1(-1);function kM(e){return"clientX"in e&&"clientY"in e}function Zd(e){if(!e)return!1;const{KeyboardEvent:t}=us(e.target);return t&&e instanceof t}function NM(e){if(!e)return!1;const{TouchEvent:t}=us(e.target);return t&&e instanceof t}function td(e){if(NM(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:s}=e.touches[0];return{x:t,y:s}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:s}=e.changedTouches[0];return{x:t,y:s}}}return kM(e)?{x:e.clientX,y:e.clientY}:null}const ur=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:s}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(s?Math.round(s):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:s}=e;return"scaleX("+t+") scaleY("+s+")"}},Transform:{toString(e){if(e)return[ur.Translate.toString(e),ur.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:s,easing:r}=e;return t+" "+s+"ms "+r}}}),Qg="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function SM(e){return e.matches(Qg)?e:e.querySelector(Qg)}const CM={display:"none"};function IM(e){let{id:t,value:s}=e;return qe.createElement("div",{id:t,style:CM},s)}function TM(e){let{id:t,announcement:s,ariaLiveType:r="assertive"}=e;const o={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return qe.createElement("div",{id:t,style:o,role:"status","aria-live":r,"aria-atomic":!0},s)}function AM(){const[e,t]=f.useState("");return{announce:f.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const w1=f.createContext(null);function j1(e){const t=f.useContext(w1);f.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function EM(){const[e]=f.useState(()=>new Set),t=f.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[f.useCallback(r=>{let{type:o,event:i}=r;e.forEach(a=>{var l;return(l=a[o])==null?void 0:l.call(a,i)})},[e]),t]}const RM={draggable:`
|
|
3
|
-
To pick up a draggable item, press the space bar.
|
|
4
|
-
While dragging, use the arrow keys to move the item.
|
|
5
|
-
Press space again to drop the item in its new position, or press escape to cancel.
|
|
6
|
-
`},MM={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:s}=e;return s?"Draggable item "+t.id+" was moved over droppable area "+s.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:s}=e;return s?"Draggable item "+t.id+" was dropped over droppable area "+s.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function PM(e){let{announcements:t=MM,container:s,hiddenTextDescribedById:r,screenReaderInstructions:o=RM}=e;const{announce:i,announcement:a}=AM(),l=pl("DndLiveRegion"),[c,u]=f.useState(!1);if(f.useEffect(()=>{u(!0)},[]),j1(f.useMemo(()=>({onDragStart(m){let{active:h}=m;i(t.onDragStart({active:h}))},onDragMove(m){let{active:h,over:p}=m;t.onDragMove&&i(t.onDragMove({active:h,over:p}))},onDragOver(m){let{active:h,over:p}=m;i(t.onDragOver({active:h,over:p}))},onDragEnd(m){let{active:h,over:p}=m;i(t.onDragEnd({active:h,over:p}))},onDragCancel(m){let{active:h,over:p}=m;i(t.onDragCancel({active:h,over:p}))}}),[i,t])),!c)return null;const d=qe.createElement(qe.Fragment,null,qe.createElement(IM,{id:r,value:o.draggable}),qe.createElement(TM,{id:l,announcement:a}));return s?So.createPortal(d,s):d}var Hn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Hn||(Hn={}));function nd(){}function DM(e,t){return f.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function OM(){for(var e=arguments.length,t=new Array(e),s=0;s<e;s++)t[s]=arguments[s];return f.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const Ys=Object.freeze({x:0,y:0});function LM(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function _M(e,t){const s=td(e);if(!s)return"0 0";const r={x:(s.x-t.left)/t.width*100,y:(s.y-t.top)/t.height*100};return r.x+"% "+r.y+"%"}function BM(e,t){let{data:{value:s}}=e,{data:{value:r}}=t;return s-r}function FM(e,t){let{data:{value:s}}=e,{data:{value:r}}=t;return r-s}function zM(e){let{left:t,top:s,height:r,width:o}=e;return[{x:t,y:s},{x:t+o,y:s},{x:t,y:s+r},{x:t+o,y:s+r}]}function $M(e,t){if(!e||e.length===0)return null;const[s]=e;return s[t]}function VM(e,t){const s=Math.max(t.top,e.top),r=Math.max(t.left,e.left),o=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),a=o-r,l=i-s;if(r<o&&s<i){const c=t.width*t.height,u=e.width*e.height,d=a*l,m=d/(c+u-d);return Number(m.toFixed(4))}return 0}const k1=e=>{let{collisionRect:t,droppableRects:s,droppableContainers:r}=e;const o=[];for(const i of r){const{id:a}=i,l=s.get(a);if(l){const c=VM(l,t);c>0&&o.push({id:a,data:{droppableContainer:i,value:c}})}}return o.sort(FM)};function HM(e,t){const{top:s,left:r,bottom:o,right:i}=t;return s<=e.y&&e.y<=o&&r<=e.x&&e.x<=i}const WM=e=>{let{droppableContainers:t,droppableRects:s,pointerCoordinates:r}=e;if(!r)return[];const o=[];for(const i of t){const{id:a}=i,l=s.get(a);if(l&&HM(r,l)){const u=zM(l).reduce((m,h)=>m+LM(r,h),0),d=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:i,value:d}})}}return o.sort(BM)};function UM(e,t,s){return{...e,scaleX:t&&s?t.width/s.width:1,scaleY:t&&s?t.height/s.height:1}}function N1(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Ys}function qM(e){return function(s){for(var r=arguments.length,o=new Array(r>1?r-1:0),i=1;i<r;i++)o[i-1]=arguments[i];return o.reduce((a,l)=>({...a,top:a.top+e*l.y,bottom:a.bottom+e*l.y,left:a.left+e*l.x,right:a.right+e*l.x}),{...s})}}const GM=qM(1);function S1(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function KM(e,t,s){const r=S1(t);if(!r)return e;const{scaleX:o,scaleY:i,x:a,y:l}=r,c=e.left-a-(1-o)*parseFloat(s),u=e.top-l-(1-i)*parseFloat(s.slice(s.indexOf(" ")+1)),d=o?e.width/o:e.width,m=i?e.height/i:e.height;return{width:d,height:m,top:u,right:c+d,bottom:u+m,left:c}}const YM={ignoreTransform:!1};function Di(e,t){t===void 0&&(t=YM);let s=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=us(e).getComputedStyle(e);u&&(s=KM(s,u,d))}const{top:r,left:o,width:i,height:a,bottom:l,right:c}=s;return{top:r,left:o,width:i,height:a,bottom:l,right:c}}function Jg(e){return Di(e,{ignoreTransform:!0})}function XM(e){const t=e.innerWidth,s=e.innerHeight;return{top:0,left:0,right:t,bottom:s,width:t,height:s}}function QM(e,t){return t===void 0&&(t=us(e).getComputedStyle(e)),t.position==="fixed"}function JM(e,t){t===void 0&&(t=us(e).getComputedStyle(e));const s=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(o=>{const i=t[o];return typeof i=="string"?s.test(i):!1})}function vp(e,t){const s=[];function r(o){if(t!=null&&s.length>=t||!o)return s;if(gp(o)&&o.scrollingElement!=null&&!s.includes(o.scrollingElement))return s.push(o.scrollingElement),s;if(!ml(o)||b1(o)||s.includes(o))return s;const i=us(e).getComputedStyle(o);return o!==e&&JM(o,i)&&s.push(o),QM(o,i)?s:r(o.parentNode)}return e?r(e):s}function C1(e){const[t]=vp(e,1);return t??null}function Hu(e){return!Qd||!e?null:Mi(e)?e:xp(e)?gp(e)||e===Pi(e).scrollingElement?window:ml(e)?e:null:null}function I1(e){return Mi(e)?e.scrollX:e.scrollLeft}function T1(e){return Mi(e)?e.scrollY:e.scrollTop}function fm(e){return{x:I1(e),y:T1(e)}}var Xn;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Xn||(Xn={}));function A1(e){return!Qd||!e?!1:e===document.scrollingElement}function E1(e){const t={x:0,y:0},s=A1(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-s.width,y:e.scrollHeight-s.height},o=e.scrollTop<=t.y,i=e.scrollLeft<=t.x,a=e.scrollTop>=r.y,l=e.scrollLeft>=r.x;return{isTop:o,isLeft:i,isBottom:a,isRight:l,maxScroll:r,minScroll:t}}const ZM={x:.2,y:.2};function eP(e,t,s,r,o){let{top:i,left:a,right:l,bottom:c}=s;r===void 0&&(r=10),o===void 0&&(o=ZM);const{isTop:u,isBottom:d,isLeft:m,isRight:h}=E1(e),p={x:0,y:0},g={x:0,y:0},x={height:t.height*o.y,width:t.width*o.x};return!u&&i<=t.top+x.height?(p.y=Xn.Backward,g.y=r*Math.abs((t.top+x.height-i)/x.height)):!d&&c>=t.bottom-x.height&&(p.y=Xn.Forward,g.y=r*Math.abs((t.bottom-x.height-c)/x.height)),!h&&l>=t.right-x.width?(p.x=Xn.Forward,g.x=r*Math.abs((t.right-x.width-l)/x.width)):!m&&a<=t.left+x.width&&(p.x=Xn.Backward,g.x=r*Math.abs((t.left+x.width-a)/x.width)),{direction:p,speed:g}}function tP(e){if(e===document.scrollingElement){const{innerWidth:i,innerHeight:a}=window;return{top:0,left:0,right:i,bottom:a,width:i,height:a}}const{top:t,left:s,right:r,bottom:o}=e.getBoundingClientRect();return{top:t,left:s,right:r,bottom:o,width:e.clientWidth,height:e.clientHeight}}function R1(e){return e.reduce((t,s)=>ui(t,fm(s)),Ys)}function nP(e){return e.reduce((t,s)=>t+I1(s),0)}function sP(e){return e.reduce((t,s)=>t+T1(s),0)}function M1(e,t){if(t===void 0&&(t=Di),!e)return;const{top:s,left:r,bottom:o,right:i}=t(e);C1(e)&&(o<=0||i<=0||s>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const rP=[["x",["left","right"],nP],["y",["top","bottom"],sP]];class bp{constructor(t,s){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=vp(s),o=R1(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[i,a,l]of rP)for(const c of a)Object.defineProperty(this,c,{get:()=>{const u=l(r),d=o[i]-u;return this.rect[c]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class ha{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(s=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...s)})},this.target=t}add(t,s,r){var o;(o=this.target)==null||o.addEventListener(t,s,r),this.listeners.push([t,s,r])}}function oP(e){const{EventTarget:t}=us(e);return e instanceof t?e:Pi(e)}function Wu(e,t){const s=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(s**2+r**2)>t:"x"in t&&"y"in t?s>t.x&&r>t.y:"x"in t?s>t.x:"y"in t?r>t.y:!1}var ks;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(ks||(ks={}));function Zg(e){e.preventDefault()}function iP(e){e.stopPropagation()}var tn;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(tn||(tn={}));const P1={start:[tn.Space,tn.Enter],cancel:[tn.Esc],end:[tn.Space,tn.Enter,tn.Tab]},aP=(e,t)=>{let{currentCoordinates:s}=t;switch(e.code){case tn.Right:return{...s,x:s.x+25};case tn.Left:return{...s,x:s.x-25};case tn.Down:return{...s,y:s.y+25};case tn.Up:return{...s,y:s.y-25}}};class D1{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:s}}=t;this.props=t,this.listeners=new ha(Pi(s)),this.windowListeners=new ha(us(s)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ks.Resize,this.handleCancel),this.windowListeners.add(ks.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ks.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:s}=this.props,r=t.node.current;r&&M1(r),s(Ys)}handleKeyDown(t){if(Zd(t)){const{active:s,context:r,options:o}=this.props,{keyboardCodes:i=P1,coordinateGetter:a=aP,scrollBehavior:l="smooth"}=o,{code:c}=t;if(i.end.includes(c)){this.handleEnd(t);return}if(i.cancel.includes(c)){this.handleCancel(t);return}const{collisionRect:u}=r.current,d=u?{x:u.left,y:u.top}:Ys;this.referenceCoordinates||(this.referenceCoordinates=d);const m=a(t,{active:s,context:r.current,currentCoordinates:d});if(m){const h=ed(m,d),p={x:0,y:0},{scrollableAncestors:g}=r.current;for(const x of g){const v=t.code,{isTop:b,isRight:w,isLeft:j,isBottom:T,maxScroll:N,minScroll:S}=E1(x),I=tP(x),k={x:Math.min(v===tn.Right?I.right-I.width/2:I.right,Math.max(v===tn.Right?I.left:I.left+I.width/2,m.x)),y:Math.min(v===tn.Down?I.bottom-I.height/2:I.bottom,Math.max(v===tn.Down?I.top:I.top+I.height/2,m.y))},L=v===tn.Right&&!w||v===tn.Left&&!j,F=v===tn.Down&&!T||v===tn.Up&&!b;if(L&&k.x!==m.x){const A=x.scrollLeft+h.x,M=v===tn.Right&&A<=N.x||v===tn.Left&&A>=S.x;if(M&&!h.y){x.scrollTo({left:A,behavior:l});return}M?p.x=x.scrollLeft-A:p.x=v===tn.Right?x.scrollLeft-N.x:x.scrollLeft-S.x,p.x&&x.scrollBy({left:-p.x,behavior:l});break}else if(F&&k.y!==m.y){const A=x.scrollTop+h.y,M=v===tn.Down&&A<=N.y||v===tn.Up&&A>=S.y;if(M&&!h.x){x.scrollTo({top:A,behavior:l});return}M?p.y=x.scrollTop-A:p.y=v===tn.Down?x.scrollTop-N.y:x.scrollTop-S.y,p.y&&x.scrollBy({top:-p.y,behavior:l});break}}this.handleMove(t,ui(ed(m,this.referenceCoordinates),p))}}}handleMove(t,s){const{onMove:r}=this.props;t.preventDefault(),r(s)}handleEnd(t){const{onEnd:s}=this.props;t.preventDefault(),this.detach(),s()}handleCancel(t){const{onCancel:s}=this.props;t.preventDefault(),this.detach(),s()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}D1.activators=[{eventName:"onKeyDown",handler:(e,t,s)=>{let{keyboardCodes:r=P1,onActivation:o}=t,{active:i}=s;const{code:a}=e.nativeEvent;if(r.start.includes(a)){const l=i.activatorNode.current;return l&&e.target!==l?!1:(e.preventDefault(),o?.({event:e.nativeEvent}),!0)}return!1}}];function e0(e){return!!(e&&"distance"in e)}function t0(e){return!!(e&&"delay"in e)}class yp{constructor(t,s,r){var o;r===void 0&&(r=oP(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=s;const{event:i}=t,{target:a}=i;this.props=t,this.events=s,this.document=Pi(a),this.documentListeners=new ha(this.document),this.listeners=new ha(r),this.windowListeners=new ha(us(a)),this.initialCoordinates=(o=td(i))!=null?o:Ys,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:s,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(ks.Resize,this.handleCancel),this.windowListeners.add(ks.DragStart,Zg),this.windowListeners.add(ks.VisibilityChange,this.handleCancel),this.windowListeners.add(ks.ContextMenu,Zg),this.documentListeners.add(ks.Keydown,this.handleKeydown),s){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(t0(s)){this.timeoutId=setTimeout(this.handleStart,s.delay),this.handlePending(s);return}if(e0(s)){this.handlePending(s);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,s){const{active:r,onPending:o}=this.props;o(r,t,this.initialCoordinates,s)}handleStart(){const{initialCoordinates:t}=this,{onStart:s}=this.props;t&&(this.activated=!0,this.documentListeners.add(ks.Click,iP,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ks.SelectionChange,this.removeTextSelection),s(t))}handleMove(t){var s;const{activated:r,initialCoordinates:o,props:i}=this,{onMove:a,options:{activationConstraint:l}}=i;if(!o)return;const c=(s=td(t))!=null?s:Ys,u=ed(o,c);if(!r&&l){if(e0(l)){if(l.tolerance!=null&&Wu(u,l.tolerance))return this.handleCancel();if(Wu(u,l.distance))return this.handleStart()}if(t0(l)&&Wu(u,l.tolerance))return this.handleCancel();this.handlePending(l,u);return}t.cancelable&&t.preventDefault(),a(c)}handleEnd(){const{onAbort:t,onEnd:s}=this.props;this.detach(),this.activated||t(this.props.active),s()}handleCancel(){const{onAbort:t,onCancel:s}=this.props;this.detach(),this.activated||t(this.props.active),s()}handleKeydown(t){t.code===tn.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const lP={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class wp extends yp{constructor(t){const{event:s}=t,r=Pi(s.target);super(t,lP,r)}}wp.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:s}=e,{onActivation:r}=t;return!s.isPrimary||s.button!==0?!1:(r?.({event:s}),!0)}}];const cP={move:{name:"mousemove"},end:{name:"mouseup"}};var mm;(function(e){e[e.RightClick=2]="RightClick"})(mm||(mm={}));class dP extends yp{constructor(t){super(t,cP,Pi(t.event.target))}}dP.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:s}=e,{onActivation:r}=t;return s.button===mm.RightClick?!1:(r?.({event:s}),!0)}}];const Uu={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class uP extends yp{constructor(t){super(t,Uu)}static setup(){return window.addEventListener(Uu.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Uu.move.name,t)};function t(){}}}uP.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:s}=e,{onActivation:r}=t;const{touches:o}=s;return o.length>1?!1:(r?.({event:s}),!0)}}];var pa;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(pa||(pa={}));var sd;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(sd||(sd={}));function fP(e){let{acceleration:t,activator:s=pa.Pointer,canScroll:r,draggingRect:o,enabled:i,interval:a=5,order:l=sd.TreeOrder,pointerCoordinates:c,scrollableAncestors:u,scrollableAncestorRects:d,delta:m,threshold:h}=e;const p=hP({delta:m,disabled:!i}),[g,x]=jM(),v=f.useRef({x:0,y:0}),b=f.useRef({x:0,y:0}),w=f.useMemo(()=>{switch(s){case pa.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case pa.DraggableRect:return o}},[s,o,c]),j=f.useRef(null),T=f.useCallback(()=>{const S=j.current;if(!S)return;const I=v.current.x*b.current.x,k=v.current.y*b.current.y;S.scrollBy(I,k)},[]),N=f.useMemo(()=>l===sd.TreeOrder?[...u].reverse():u,[l,u]);f.useEffect(()=>{if(!i||!u.length||!w){x();return}for(const S of N){if(r?.(S)===!1)continue;const I=u.indexOf(S),k=d[I];if(!k)continue;const{direction:L,speed:F}=eP(S,k,w,t,h);for(const A of["x","y"])p[A][L[A]]||(F[A]=0,L[A]=0);if(F.x>0||F.y>0){x(),j.current=S,g(T,a),v.current=F,b.current=L;return}}v.current={x:0,y:0},b.current={x:0,y:0},x()},[t,T,r,x,i,a,JSON.stringify(w),JSON.stringify(p),g,u,N,d,JSON.stringify(h)])}const mP={x:{[Xn.Backward]:!1,[Xn.Forward]:!1},y:{[Xn.Backward]:!1,[Xn.Forward]:!1}};function hP(e){let{delta:t,disabled:s}=e;const r=Zc(t);return hl(o=>{if(s||!r||!o)return mP;const i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Xn.Backward]:o.x[Xn.Backward]||i.x===-1,[Xn.Forward]:o.x[Xn.Forward]||i.x===1},y:{[Xn.Backward]:o.y[Xn.Backward]||i.y===-1,[Xn.Forward]:o.y[Xn.Forward]||i.y===1}}},[s,t,r])}function pP(e,t){const s=t!=null?e.get(t):void 0,r=s?s.node.current:null;return hl(o=>{var i;return t==null?null:(i=r??o)!=null?i:null},[r,t])}function xP(e,t){return f.useMemo(()=>e.reduce((s,r)=>{const{sensor:o}=r,i=o.activators.map(a=>({eventName:a.eventName,handler:t(a.handler,r)}));return[...s,...i]},[]),[e,t])}var $a;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})($a||($a={}));var hm;(function(e){e.Optimized="optimized"})(hm||(hm={}));const n0=new Map;function gP(e,t){let{dragging:s,dependencies:r,config:o}=t;const[i,a]=f.useState(null),{frequency:l,measure:c,strategy:u}=o,d=f.useRef(e),m=v(),h=za(m),p=f.useCallback(function(b){b===void 0&&(b=[]),!h.current&&a(w=>w===null?b:w.concat(b.filter(j=>!w.includes(j))))},[h]),g=f.useRef(null),x=hl(b=>{if(m&&!s)return n0;if(!b||b===n0||d.current!==e||i!=null){const w=new Map;for(let j of e){if(!j)continue;if(i&&i.length>0&&!i.includes(j.id)&&j.rect.current){w.set(j.id,j.rect.current);continue}const T=j.node.current,N=T?new bp(c(T),T):null;j.rect.current=N,N&&w.set(j.id,N)}return w}return b},[e,i,s,m,c]);return f.useEffect(()=>{d.current=e},[e]),f.useEffect(()=>{m||p()},[s,m]),f.useEffect(()=>{i&&i.length>0&&a(null)},[JSON.stringify(i)]),f.useEffect(()=>{m||typeof l!="number"||g.current!==null||(g.current=setTimeout(()=>{p(),g.current=null},l))},[l,m,p,...r]),{droppableRects:x,measureDroppableContainers:p,measuringScheduled:i!=null};function v(){switch(u){case $a.Always:return!1;case $a.BeforeDragging:return s;default:return!s}}}function jp(e,t){return hl(s=>e?s||(typeof t=="function"?t(e):e):null,[t,e])}function vP(e,t){return jp(e,t)}function bP(e){let{callback:t,disabled:s}=e;const r=Jd(t),o=f.useMemo(()=>{if(s||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(r)},[r,s]);return f.useEffect(()=>()=>o?.disconnect(),[o]),o}function eu(e){let{callback:t,disabled:s}=e;const r=Jd(t),o=f.useMemo(()=>{if(s||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(r)},[s]);return f.useEffect(()=>()=>o?.disconnect(),[o]),o}function yP(e){return new bp(Di(e),e)}function s0(e,t,s){t===void 0&&(t=yP);const[r,o]=f.useState(null);function i(){o(c=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=c??s)!=null?u:null}const d=t(e);return JSON.stringify(c)===JSON.stringify(d)?c:d})}const a=bP({callback(c){if(e)for(const u of c){const{type:d,target:m}=u;if(d==="childList"&&m instanceof HTMLElement&&m.contains(e)){i();break}}}}),l=eu({callback:i});return Ks(()=>{i(),e?(l?.observe(e),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[e]),r}function wP(e){const t=jp(e);return N1(e,t)}const r0=[];function jP(e){const t=f.useRef(e),s=hl(r=>e?r&&r!==r0&&e&&t.current&&e.parentNode===t.current.parentNode?r:vp(e):r0,[e]);return f.useEffect(()=>{t.current=e},[e]),s}function kP(e){const[t,s]=f.useState(null),r=f.useRef(e),o=f.useCallback(i=>{const a=Hu(i.target);a&&s(l=>l?(l.set(a,fm(a)),new Map(l)):null)},[]);return f.useEffect(()=>{const i=r.current;if(e!==i){a(i);const l=e.map(c=>{const u=Hu(c);return u?(u.addEventListener("scroll",o,{passive:!0}),[u,fm(u)]):null}).filter(c=>c!=null);s(l.length?new Map(l):null),r.current=e}return()=>{a(e),a(i)};function a(l){l.forEach(c=>{const u=Hu(c);u?.removeEventListener("scroll",o)})}},[o,e]),f.useMemo(()=>e.length?t?Array.from(t.values()).reduce((i,a)=>ui(i,a),Ys):R1(e):Ys,[e,t])}function o0(e,t){t===void 0&&(t=[]);const s=f.useRef(null);return f.useEffect(()=>{s.current=null},t),f.useEffect(()=>{const r=e!==Ys;r&&!s.current&&(s.current=e),!r&&s.current&&(s.current=null)},[e]),s.current?ed(e,s.current):Ys}function NP(e){f.useEffect(()=>{if(!Qd)return;const t=e.map(s=>{let{sensor:r}=s;return r.setup==null?void 0:r.setup()});return()=>{for(const s of t)s?.()}},e.map(t=>{let{sensor:s}=t;return s}))}function SP(e,t){return f.useMemo(()=>e.reduce((s,r)=>{let{eventName:o,handler:i}=r;return s[o]=a=>{i(a,t)},s},{}),[e,t])}function O1(e){return f.useMemo(()=>e?XM(e):null,[e])}const i0=[];function CP(e,t){t===void 0&&(t=Di);const[s]=e,r=O1(s?us(s):null),[o,i]=f.useState(i0);function a(){i(()=>e.length?e.map(c=>A1(c)?r:new bp(t(c),c)):i0)}const l=eu({callback:a});return Ks(()=>{l?.disconnect(),a(),e.forEach(c=>l?.observe(c))},[e]),o}function L1(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return ml(t)?t:e}function IP(e){let{measure:t}=e;const[s,r]=f.useState(null),o=f.useCallback(u=>{for(const{target:d}of u)if(ml(d)){r(m=>{const h=t(d);return m?{...m,width:h.width,height:h.height}:h});break}},[t]),i=eu({callback:o}),a=f.useCallback(u=>{const d=L1(u);i?.disconnect(),d&&i?.observe(d),r(d?t(d):null)},[t,i]),[l,c]=Jc(a);return f.useMemo(()=>({nodeRef:l,rect:s,setRef:c}),[s,l,c])}const TP=[{sensor:wp,options:{}},{sensor:D1,options:{}}],AP={current:{}},jc={draggable:{measure:Jg},droppable:{measure:Jg,strategy:$a.WhileDragging,frequency:hm.Optimized},dragOverlay:{measure:Di}};class xa extends Map{get(t){var s;return t!=null&&(s=super.get(t))!=null?s:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:s}=t;return!s})}getNodeFor(t){var s,r;return(s=(r=this.get(t))==null?void 0:r.node.current)!=null?s:void 0}}const EP={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new xa,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:nd},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:jc,measureDroppableContainers:nd,windowRect:null,measuringScheduled:!1},_1={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:nd,draggableNodes:new Map,over:null,measureDroppableContainers:nd},xl=f.createContext(_1),B1=f.createContext(EP);function RP(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new xa}}}function MP(e,t){switch(t.type){case Hn.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Hn.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Hn.DragEnd:case Hn.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Hn.RegisterDroppable:{const{element:s}=t,{id:r}=s,o=new xa(e.droppable.containers);return o.set(r,s),{...e,droppable:{...e.droppable,containers:o}}}case Hn.SetDroppableDisabled:{const{id:s,key:r,disabled:o}=t,i=e.droppable.containers.get(s);if(!i||r!==i.key)return e;const a=new xa(e.droppable.containers);return a.set(s,{...i,disabled:o}),{...e,droppable:{...e.droppable,containers:a}}}case Hn.UnregisterDroppable:{const{id:s,key:r}=t,o=e.droppable.containers.get(s);if(!o||r!==o.key)return e;const i=new xa(e.droppable.containers);return i.delete(s),{...e,droppable:{...e.droppable,containers:i}}}default:return e}}function PP(e){let{disabled:t}=e;const{active:s,activatorEvent:r,draggableNodes:o}=f.useContext(xl),i=Zc(r),a=Zc(s?.id);return f.useEffect(()=>{if(!t&&!r&&i&&a!=null){if(!Zd(i)||document.activeElement===i.target)return;const l=o.get(a);if(!l)return;const{activatorNode:c,node:u}=l;if(!c.current&&!u.current)return;requestAnimationFrame(()=>{for(const d of[c.current,u.current]){if(!d)continue;const m=SM(d);if(m){m.focus();break}}})}},[r,t,o,a,i]),null}function F1(e,t){let{transform:s,...r}=t;return e!=null&&e.length?e.reduce((o,i)=>i({transform:o,...r}),s):s}function DP(e){return f.useMemo(()=>({draggable:{...jc.draggable,...e?.draggable},droppable:{...jc.droppable,...e?.droppable},dragOverlay:{...jc.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function OP(e){let{activeNode:t,measure:s,initialRect:r,config:o=!0}=e;const i=f.useRef(!1),{x:a,y:l}=typeof o=="boolean"?{x:o,y:o}:o;Ks(()=>{if(!a&&!l||!t){i.current=!1;return}if(i.current||!r)return;const u=t?.node.current;if(!u||u.isConnected===!1)return;const d=s(u),m=N1(d,r);if(a||(m.x=0),l||(m.y=0),i.current=!0,Math.abs(m.x)>0||Math.abs(m.y)>0){const h=C1(u);h&&h.scrollBy({top:m.y,left:m.x})}},[t,a,l,r,s])}const tu=f.createContext({...Ys,scaleX:1,scaleY:1});var Wr;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Wr||(Wr={}));const LP=f.memo(function(t){var s,r,o,i;let{id:a,accessibility:l,autoScroll:c=!0,children:u,sensors:d=TP,collisionDetection:m=k1,measuring:h,modifiers:p,...g}=t;const x=f.useReducer(MP,void 0,RP),[v,b]=x,[w,j]=EM(),[T,N]=f.useState(Wr.Uninitialized),S=T===Wr.Initialized,{draggable:{active:I,nodes:k,translate:L},droppable:{containers:F}}=v,A=I!=null?k.get(I):null,M=f.useRef({initial:null,translated:null}),R=f.useMemo(()=>{var xt;return I!=null?{id:I,data:(xt=A?.data)!=null?xt:AP,rect:M}:null},[I,A]),$=f.useRef(null),[U,q]=f.useState(null),[te,V]=f.useState(null),se=za(g,Object.values(g)),Ce=pl("DndDescribedBy",a),de=f.useMemo(()=>F.getEnabled(),[F]),re=DP(h),{droppableRects:Z,measureDroppableContainers:me,measuringScheduled:xe}=gP(de,{dragging:S,dependencies:[L.x,L.y],config:re.droppable}),Se=pP(k,I),W=f.useMemo(()=>te?td(te):null,[te]),H=gt(),B=vP(Se,re.draggable.measure);OP({activeNode:I!=null?k.get(I):null,config:H.layoutShiftCompensation,initialRect:B,measure:re.draggable.measure});const ne=s0(Se,re.draggable.measure,B),ve=s0(Se?Se.parentElement:null),he=f.useRef({activatorEvent:null,active:null,activeNode:Se,collisionRect:null,collisions:null,droppableRects:Z,draggableNodes:k,draggingNode:null,draggingNodeRect:null,droppableContainers:F,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),G=F.getNodeFor((s=he.current.over)==null?void 0:s.id),we=IP({measure:re.dragOverlay.measure}),ce=(r=we.nodeRef.current)!=null?r:Se,Re=S?(o=we.rect)!=null?o:ne:null,ue=!!(we.nodeRef.current&&we.rect),We=wP(ue?null:ne),it=O1(ce?us(ce):null),Fe=jP(S?G??Se:null),tt=CP(Fe),ke=F1(p,{transform:{x:L.x-We.x,y:L.y-We.y,scaleX:1,scaleY:1},activatorEvent:te,active:R,activeNodeRect:ne,containerNodeRect:ve,draggingNodeRect:Re,over:he.current.over,overlayNodeRect:we.rect,scrollableAncestors:Fe,scrollableAncestorRects:tt,windowRect:it}),nt=W?ui(W,L):null,mt=kP(Fe),X=o0(mt),K=o0(mt,[ne]),Ee=ui(ke,X),pt=Re?GM(Re,ke):null,Pt=R&&pt?m({active:R,collisionRect:pt,droppableRects:Z,droppableContainers:de,pointerCoordinates:nt}):null,Je=$M(Pt,"id"),[Lt,on]=f.useState(null),Pe=ue?ke:ui(ke,K),Dt=UM(Pe,(i=Lt?.rect)!=null?i:null,ne),Vt=f.useRef(null),Et=f.useCallback((xt,zt)=>{let{sensor:Wt,options:an}=zt;if($.current==null)return;const en=k.get($.current);if(!en)return;const Bt=xt.nativeEvent,pn=new Wt({active:$.current,activeNode:en,event:Bt,options:an,context:he,onAbort(vt){if(!k.get(vt))return;const{onDragAbort:Rn}=se.current,C={id:vt};Rn?.(C),w({type:"onDragAbort",event:C})},onPending(vt,sn,Rn,C){if(!k.get(vt))return;const{onDragPending:P}=se.current,y={id:vt,constraint:sn,initialCoordinates:Rn,offset:C};P?.(y),w({type:"onDragPending",event:y})},onStart(vt){const sn=$.current;if(sn==null)return;const Rn=k.get(sn);if(!Rn)return;const{onDragStart:C}=se.current,D={activatorEvent:Bt,active:{id:sn,data:Rn.data,rect:M}};So.unstable_batchedUpdates(()=>{C?.(D),N(Wr.Initializing),b({type:Hn.DragStart,initialCoordinates:vt,active:sn}),w({type:"onDragStart",event:D}),q(Vt.current),V(Bt)})},onMove(vt){b({type:Hn.DragMove,coordinates:vt})},onEnd:Gn(Hn.DragEnd),onCancel:Gn(Hn.DragCancel)});Vt.current=pn;function Gn(vt){return async function(){const{active:Rn,collisions:C,over:D,scrollAdjustedTranslate:P}=he.current;let y=null;if(Rn&&P){const{cancelDrop:E}=se.current;y={activatorEvent:Bt,active:Rn,collisions:C,delta:P,over:D},vt===Hn.DragEnd&&typeof E=="function"&&await Promise.resolve(E(y))&&(vt=Hn.DragCancel)}$.current=null,So.unstable_batchedUpdates(()=>{b({type:vt}),N(Wr.Uninitialized),on(null),q(null),V(null),Vt.current=null;const E=vt===Hn.DragEnd?"onDragEnd":"onDragCancel";if(y){const Y=se.current[E];Y?.(y),w({type:E,event:y})}})}}},[k]),oe=f.useCallback((xt,zt)=>(Wt,an)=>{const en=Wt.nativeEvent,Bt=k.get(an);if($.current!==null||!Bt||en.dndKit||en.defaultPrevented)return;const pn={active:Bt};xt(Wt,zt.options,pn)===!0&&(en.dndKit={capturedBy:zt.sensor},$.current=an,Et(Wt,zt))},[k,Et]),Le=xP(d,oe);NP(d),Ks(()=>{ne&&T===Wr.Initializing&&N(Wr.Initialized)},[ne,T]),f.useEffect(()=>{const{onDragMove:xt}=se.current,{active:zt,activatorEvent:Wt,collisions:an,over:en}=he.current;if(!zt||!Wt)return;const Bt={active:zt,activatorEvent:Wt,collisions:an,delta:{x:Ee.x,y:Ee.y},over:en};So.unstable_batchedUpdates(()=>{xt?.(Bt),w({type:"onDragMove",event:Bt})})},[Ee.x,Ee.y]),f.useEffect(()=>{const{active:xt,activatorEvent:zt,collisions:Wt,droppableContainers:an,scrollAdjustedTranslate:en}=he.current;if(!xt||$.current==null||!zt||!en)return;const{onDragOver:Bt}=se.current,pn=an.get(Je),Gn=pn&&pn.rect.current?{id:pn.id,rect:pn.rect.current,data:pn.data,disabled:pn.disabled}:null,vt={active:xt,activatorEvent:zt,collisions:Wt,delta:{x:en.x,y:en.y},over:Gn};So.unstable_batchedUpdates(()=>{on(Gn),Bt?.(vt),w({type:"onDragOver",event:vt})})},[Je]),Ks(()=>{he.current={activatorEvent:te,active:R,activeNode:Se,collisionRect:pt,collisions:Pt,droppableRects:Z,draggableNodes:k,draggingNode:ce,draggingNodeRect:Re,droppableContainers:F,over:Lt,scrollableAncestors:Fe,scrollAdjustedTranslate:Ee},M.current={initial:Re,translated:pt}},[R,Se,Pt,pt,k,ce,Re,Z,F,Lt,Fe,Ee]),fP({...H,delta:L,draggingRect:pt,pointerCoordinates:nt,scrollableAncestors:Fe,scrollableAncestorRects:tt});const st=f.useMemo(()=>({active:R,activeNode:Se,activeNodeRect:ne,activatorEvent:te,collisions:Pt,containerNodeRect:ve,dragOverlay:we,draggableNodes:k,droppableContainers:F,droppableRects:Z,over:Lt,measureDroppableContainers:me,scrollableAncestors:Fe,scrollableAncestorRects:tt,measuringConfiguration:re,measuringScheduled:xe,windowRect:it}),[R,Se,ne,te,Pt,ve,we,k,F,Z,Lt,me,Fe,tt,re,xe,it]),at=f.useMemo(()=>({activatorEvent:te,activators:Le,active:R,activeNodeRect:ne,ariaDescribedById:{draggable:Ce},dispatch:b,draggableNodes:k,over:Lt,measureDroppableContainers:me}),[te,Le,R,ne,b,Ce,k,Lt,me]);return qe.createElement(w1.Provider,{value:j},qe.createElement(xl.Provider,{value:at},qe.createElement(B1.Provider,{value:st},qe.createElement(tu.Provider,{value:Dt},u)),qe.createElement(PP,{disabled:l?.restoreFocus===!1})),qe.createElement(PM,{...l,hiddenTextDescribedById:Ce}));function gt(){const xt=U?.autoScrollEnabled===!1,zt=typeof c=="object"?c.enabled===!1:c===!1,Wt=S&&!xt&&!zt;return typeof c=="object"?{...c,enabled:Wt}:{enabled:Wt}}}),_P=f.createContext(null),a0="button",BP="Draggable";function z1(e){let{id:t,data:s,disabled:r=!1,attributes:o}=e;const i=pl(BP),{activators:a,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:m,over:h}=f.useContext(xl),{role:p=a0,roleDescription:g="draggable",tabIndex:x=0}=o??{},v=c?.id===t,b=f.useContext(v?tu:_P),[w,j]=Jc(),[T,N]=Jc(),S=SP(a,t),I=za(s);Ks(()=>(m.set(t,{id:t,key:i,node:w,activatorNode:T,data:I}),()=>{const L=m.get(t);L&&L.key===i&&m.delete(t)}),[m,t]);const k=f.useMemo(()=>({role:p,tabIndex:x,"aria-disabled":r,"aria-pressed":v&&p===a0?!0:void 0,"aria-roledescription":g,"aria-describedby":d.draggable}),[r,p,x,v,g,d.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:k,isDragging:v,listeners:r?void 0:S,node:w,over:h,setNodeRef:j,setActivatorNodeRef:N,transform:b}}function gl(){return f.useContext(B1)}const FP="Droppable",zP={timeout:25};function vl(e){let{data:t,disabled:s=!1,id:r,resizeObserverConfig:o}=e;const i=pl(FP),{active:a,dispatch:l,over:c,measureDroppableContainers:u}=f.useContext(xl),d=f.useRef({disabled:s}),m=f.useRef(!1),h=f.useRef(null),p=f.useRef(null),{disabled:g,updateMeasurementsFor:x,timeout:v}={...zP,...o},b=za(x??r),w=f.useCallback(()=>{if(!m.current){m.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{u(Array.isArray(b.current)?b.current:[b.current]),p.current=null},v)},[v]),j=eu({callback:w,disabled:g||!a}),T=f.useCallback((k,L)=>{j&&(L&&(j.unobserve(L),m.current=!1),k&&j.observe(k))},[j]),[N,S]=Jc(T),I=za(t);return f.useEffect(()=>{!j||!N.current||(j.disconnect(),m.current=!1,j.observe(N.current))},[N,j]),f.useEffect(()=>(l({type:Hn.RegisterDroppable,element:{id:r,key:i,disabled:s,node:N,rect:h,data:I}}),()=>l({type:Hn.UnregisterDroppable,key:i,id:r})),[r]),f.useEffect(()=>{s!==d.current.disabled&&(l({type:Hn.SetDroppableDisabled,id:r,key:i,disabled:s}),d.current.disabled=s)},[r,i,s,l]),{active:a,rect:h,isOver:c?.id===r,node:N,over:c,setNodeRef:S}}function $P(e){let{animation:t,children:s}=e;const[r,o]=f.useState(null),[i,a]=f.useState(null),l=Zc(s);return!s&&!r&&l&&o(l),Ks(()=>{if(!i)return;const c=r?.key,u=r?.props.id;if(c==null||u==null){o(null);return}Promise.resolve(t(u,i)).then(()=>{o(null)})},[t,r,i]),qe.createElement(qe.Fragment,null,s,r?f.cloneElement(r,{ref:a}):null)}const VP={x:0,y:0,scaleX:1,scaleY:1};function HP(e){let{children:t}=e;return qe.createElement(xl.Provider,{value:_1},qe.createElement(tu.Provider,{value:VP},t))}const WP={position:"fixed",touchAction:"none"},UP=e=>Zd(e)?"transform 250ms ease":void 0,qP=f.forwardRef((e,t)=>{let{as:s,activatorEvent:r,adjustScale:o,children:i,className:a,rect:l,style:c,transform:u,transition:d=UP}=e;if(!l)return null;const m=o?u:{...u,scaleX:1,scaleY:1},h={...WP,width:l.width,height:l.height,top:l.top,left:l.left,transform:ur.Transform.toString(m),transformOrigin:o&&r?_M(r,l):void 0,transition:typeof d=="function"?d(r):d,...c};return qe.createElement(s,{className:a,style:h,ref:t},i)}),GP=e=>t=>{let{active:s,dragOverlay:r}=t;const o={},{styles:i,className:a}=e;if(i!=null&&i.active)for(const[l,c]of Object.entries(i.active))c!==void 0&&(o[l]=s.node.style.getPropertyValue(l),s.node.style.setProperty(l,c));if(i!=null&&i.dragOverlay)for(const[l,c]of Object.entries(i.dragOverlay))c!==void 0&&r.node.style.setProperty(l,c);return a!=null&&a.active&&s.node.classList.add(a.active),a!=null&&a.dragOverlay&&r.node.classList.add(a.dragOverlay),function(){for(const[c,u]of Object.entries(o))s.node.style.setProperty(c,u);a!=null&&a.active&&s.node.classList.remove(a.active)}},KP=e=>{let{transform:{initial:t,final:s}}=e;return[{transform:ur.Transform.toString(t)},{transform:ur.Transform.toString(s)}]},YP={duration:250,easing:"ease",keyframes:KP,sideEffects:GP({styles:{active:{opacity:"0"}}})};function XP(e){let{config:t,draggableNodes:s,droppableContainers:r,measuringConfiguration:o}=e;return Jd((i,a)=>{if(t===null)return;const l=s.get(i);if(!l)return;const c=l.node.current;if(!c)return;const u=L1(a);if(!u)return;const{transform:d}=us(a).getComputedStyle(a),m=S1(d);if(!m)return;const h=typeof t=="function"?t:QP(t);return M1(c,o.draggable.measure),h({active:{id:i,data:l.data,node:c,rect:o.draggable.measure(c)},draggableNodes:s,dragOverlay:{node:a,rect:o.dragOverlay.measure(u)},droppableContainers:r,measuringConfiguration:o,transform:m})})}function QP(e){const{duration:t,easing:s,sideEffects:r,keyframes:o}={...YP,...e};return i=>{let{active:a,dragOverlay:l,transform:c,...u}=i;if(!t)return;const d={x:l.rect.left-a.rect.left,y:l.rect.top-a.rect.top},m={scaleX:c.scaleX!==1?a.rect.width*c.scaleX/l.rect.width:1,scaleY:c.scaleY!==1?a.rect.height*c.scaleY/l.rect.height:1},h={x:c.x-d.x,y:c.y-d.y,...m},p=o({...u,active:a,dragOverlay:l,transform:{initial:c,final:h}}),[g]=p,x=p[p.length-1];if(JSON.stringify(g)===JSON.stringify(x))return;const v=r?.({active:a,dragOverlay:l,...u}),b=l.node.animate(p,{duration:t,easing:s,fill:"forwards"});return new Promise(w=>{b.onfinish=()=>{v?.(),w()}})}}let l0=0;function JP(e){return f.useMemo(()=>{if(e!=null)return l0++,l0},[e])}const ZP=qe.memo(e=>{let{adjustScale:t=!1,children:s,dropAnimation:r,style:o,transition:i,modifiers:a,wrapperElement:l="div",className:c,zIndex:u=999}=e;const{activatorEvent:d,active:m,activeNodeRect:h,containerNodeRect:p,draggableNodes:g,droppableContainers:x,dragOverlay:v,over:b,measuringConfiguration:w,scrollableAncestors:j,scrollableAncestorRects:T,windowRect:N}=gl(),S=f.useContext(tu),I=JP(m?.id),k=F1(a,{activatorEvent:d,active:m,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:v.rect,over:b,overlayNodeRect:v.rect,scrollableAncestors:j,scrollableAncestorRects:T,transform:S,windowRect:N}),L=jp(h),F=XP({config:r,draggableNodes:g,droppableContainers:x,measuringConfiguration:w}),A=L?v.setRef:void 0;return qe.createElement(HP,null,qe.createElement($P,{animation:F},m&&I?qe.createElement(qP,{key:I,id:m.id,ref:A,as:l,activatorEvent:d,adjustScale:t,className:c,transition:i,rect:L,style:{zIndex:u,...o},transform:k},s):null))}),kp=f.createContext({});function Np(e){const t=f.useRef(null);return t.current===null&&(t.current=e()),t.current}const eD=typeof window<"u",rd=eD?f.useLayoutEffect:f.useEffect,nu=f.createContext(null);function Sp(e,t){e.indexOf(t)===-1&&e.push(t)}function od(e,t){const s=e.indexOf(t);s>-1&&e.splice(s,1)}const fr=(e,t,s)=>s>t?t:s<e?e:s;let su=()=>{};const eo={},$1=e=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e),V1=e=>typeof e=="object"&&e!==null,H1=e=>/^0[^.\s]+$/u.test(e);function W1(e){let t;return()=>(t===void 0&&(t=e()),t)}const Ls=e=>e,bl=(...e)=>e.reduce((t,s)=>r=>s(t(r))),Va=(e,t,s)=>{const r=t-e;return r?(s-e)/r:1};class Cp{constructor(){this.subscriptions=[]}add(t){return Sp(this.subscriptions,t),()=>od(this.subscriptions,t)}notify(t,s,r){const o=this.subscriptions.length;if(o)if(o===1)this.subscriptions[0](t,s,r);else for(let i=0;i<o;i++){const a=this.subscriptions[i];a&&a(t,s,r)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}}const xs=e=>e*1e3,As=e=>e/1e3,U1=(e,t)=>t?e*(1e3/t):0,q1=(e,t,s)=>(((1-3*s+3*t)*e+(3*s-6*t))*e+3*t)*e,tD=1e-7,nD=12;function sD(e,t,s,r,o){let i,a,l=0;do a=t+(s-t)/2,i=q1(a,r,o)-e,i>0?s=a:t=a;while(Math.abs(i)>tD&&++l<nD);return a}function yl(e,t,s,r){if(e===t&&s===r)return Ls;const o=i=>sD(i,0,1,e,s);return i=>i===0||i===1?i:q1(o(i),t,r)}const G1=e=>t=>t<=.5?e(2*t)/2:(2-e(2*(1-t)))/2,K1=e=>t=>1-e(1-t),Y1=yl(.33,1.53,.69,.99),Ip=K1(Y1),X1=G1(Ip),Q1=e=>e>=1?1:(e*=2)<1?.5*Ip(e):.5*(2-Math.pow(2,-10*(e-1))),Tp=e=>1-Math.sin(Math.acos(e)),J1=K1(Tp),Z1=G1(Tp),rD=yl(.42,0,1,1),oD=yl(0,0,.58,1),ek=yl(.42,0,.58,1),iD=e=>Array.isArray(e)&&typeof e[0]!="number",tk=e=>Array.isArray(e)&&typeof e[0]=="number",aD={linear:Ls,easeIn:rD,easeInOut:ek,easeOut:oD,circIn:Tp,circInOut:Z1,circOut:J1,backIn:Ip,backInOut:X1,backOut:Y1,anticipate:Q1},lD=e=>typeof e=="string",c0=e=>{if(tk(e)){su(e.length===4);const[t,s,r,o]=e;return yl(t,s,r,o)}else if(lD(e))return aD[e];return e},Wl=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function cD(e){let t=new Set,s=new Set,r=!1,o=!1;const i=new WeakSet;let a={delta:0,timestamp:0,isProcessing:!1};function l(u){i.has(u)&&(c.schedule(u),e()),u(a)}const c={schedule:(u,d=!1,m=!1)=>{const p=m&&r?t:s;return d&&i.add(u),p.add(u),u},cancel:u=>{s.delete(u),i.delete(u)},process:u=>{if(a=u,r){o=!0;return}r=!0;const d=t;t=s,s=d,t.forEach(l),t.clear(),r=!1,o&&(o=!1,c.process(u))}};return c}const dD=40;function nk(e,t){let s=!1,r=!0;const o={delta:0,timestamp:0,isProcessing:!1},i=()=>s=!0,a=Wl.reduce((j,T)=>(j[T]=cD(i),j),{}),{setup:l,read:c,resolveKeyframes:u,preUpdate:d,update:m,preRender:h,render:p,postRender:g}=a,x=()=>{const j=eo.useManualTiming,T=j?o.timestamp:performance.now();s=!1,j||(o.delta=r?1e3/60:Math.max(Math.min(T-o.timestamp,dD),1)),o.timestamp=T,o.isProcessing=!0,l.process(o),c.process(o),u.process(o),d.process(o),m.process(o),h.process(o),p.process(o),g.process(o),o.isProcessing=!1,s&&t&&(r=!1,e(x))},v=()=>{s=!0,r=!0,o.isProcessing||e(x)};return{schedule:Wl.reduce((j,T)=>{const N=a[T];return j[T]=(S,I=!1,k=!1)=>(s||v(),N.schedule(S,I,k)),j},{}),cancel:j=>{for(let T=0;T<Wl.length;T++)a[Wl[T]].cancel(j)},state:o,steps:a}}const{schedule:hn,cancel:to,state:Zn,steps:qu}=nk(typeof requestAnimationFrame<"u"?requestAnimationFrame:Ls,!0);let kc;function uD(){kc=void 0}const as={now:()=>(kc===void 0&&as.set(Zn.isProcessing||eo.useManualTiming?Zn.timestamp:performance.now()),kc),set:e=>{kc=e,queueMicrotask(uD)}},sk=e=>t=>typeof t=="string"&&t.startsWith(e),rk=sk("--"),fD=sk("var(--"),Ap=e=>fD(e)?mD.test(e.split("/*")[0].trim()):!1,mD=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function d0(e){return typeof e!="string"?!1:e.split("/*")[0].includes("var(--")}const Oi={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},Ha={...Oi,transform:e=>fr(0,1,e)},Ul={...Oi,default:1},ga=e=>Math.round(e*1e5)/1e5,Ep=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function hD(e){return e==null}const pD=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,Rp=(e,t)=>s=>!!(typeof s=="string"&&pD.test(s)&&s.startsWith(e)||t&&!hD(s)&&Object.prototype.hasOwnProperty.call(s,t)),ok=(e,t,s)=>r=>{if(typeof r!="string")return r;const[o,i,a,l]=r.match(Ep);return{[e]:parseFloat(o),[t]:parseFloat(i),[s]:parseFloat(a),alpha:l!==void 0?parseFloat(l):1}},xD=e=>fr(0,255,e),Gu={...Oi,transform:e=>Math.round(xD(e))},Co={test:Rp("rgb","red"),parse:ok("red","green","blue"),transform:({red:e,green:t,blue:s,alpha:r=1})=>"rgba("+Gu.transform(e)+", "+Gu.transform(t)+", "+Gu.transform(s)+", "+ga(Ha.transform(r))+")"};function gD(e){let t="",s="",r="",o="";return e.length>5?(t=e.substring(1,3),s=e.substring(3,5),r=e.substring(5,7),o=e.substring(7,9)):(t=e.substring(1,2),s=e.substring(2,3),r=e.substring(3,4),o=e.substring(4,5),t+=t,s+=s,r+=r,o+=o),{red:parseInt(t,16),green:parseInt(s,16),blue:parseInt(r,16),alpha:o?parseInt(o,16)/255:1}}const pm={test:Rp("#"),parse:gD,transform:Co.transform},wl=e=>({test:t=>typeof t=="string"&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}),br=wl("deg"),ar=wl("%"),ct=wl("px"),vD=wl("vh"),bD=wl("vw"),u0={...ar,parse:e=>ar.parse(e)/100,transform:e=>ar.transform(e*100)},ri={test:Rp("hsl","hue"),parse:ok("hue","saturation","lightness"),transform:({hue:e,saturation:t,lightness:s,alpha:r=1})=>"hsla("+Math.round(e)+", "+ar.transform(ga(t))+", "+ar.transform(ga(s))+", "+ga(Ha.transform(r))+")"},Ln={test:e=>Co.test(e)||pm.test(e)||ri.test(e),parse:e=>Co.test(e)?Co.parse(e):ri.test(e)?ri.parse(e):pm.parse(e),transform:e=>typeof e=="string"?e:e.hasOwnProperty("red")?Co.transform(e):ri.transform(e),getAnimatableNone:e=>{const t=Ln.parse(e);return t.alpha=0,Ln.transform(t)}},yD=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;function wD(e){return isNaN(e)&&typeof e=="string"&&(e.match(Ep)?.length||0)+(e.match(yD)?.length||0)>0}const ik="number",ak="color",jD="var",kD="var(",f0="${}",ND=/var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;function Si(e){const t=e.toString(),s=[],r={color:[],number:[],var:[]},o=[];let i=0;const l=t.replace(ND,c=>(Ln.test(c)?(r.color.push(i),o.push(ak),s.push(Ln.parse(c))):c.startsWith(kD)?(r.var.push(i),o.push(jD),s.push(c)):(r.number.push(i),o.push(ik),s.push(parseFloat(c))),++i,f0)).split(f0);return{values:s,split:l,indexes:r,types:o}}function SD(e){return Si(e).values}function lk({split:e,types:t}){const s=e.length;return r=>{let o="";for(let i=0;i<s;i++)if(o+=e[i],r[i]!==void 0){const a=t[i];a===ik?o+=ga(r[i]):a===ak?o+=Ln.transform(r[i]):o+=r[i]}return o}}function CD(e){return lk(Si(e))}const ID=e=>typeof e=="number"?0:Ln.test(e)?Ln.getAnimatableNone(e):e,TD=(e,t)=>typeof e=="number"?t?.trim().endsWith("/")?e:0:ID(e);function AD(e){const t=Si(e);return lk(t)(t.values.map((r,o)=>TD(r,t.split[o])))}const Ws={test:wD,parse:SD,createTransformer:CD,getAnimatableNone:AD};function Ku(e,t,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?e+(t-e)*6*s:s<1/2?t:s<2/3?e+(t-e)*(2/3-s)*6:e}function ED({hue:e,saturation:t,lightness:s,alpha:r}){e/=360,t/=100,s/=100;let o=0,i=0,a=0;if(!t)o=i=a=s;else{const l=s<.5?s*(1+t):s+t-s*t,c=2*s-l;o=Ku(c,l,e+1/3),i=Ku(c,l,e),a=Ku(c,l,e-1/3)}return{red:Math.round(o*255),green:Math.round(i*255),blue:Math.round(a*255),alpha:r}}function id(e,t){return s=>s>0?t:e}const mn=(e,t,s)=>e+(t-e)*s,Yu=(e,t,s)=>{const r=e*e,o=s*(t*t-r)+r;return o<0?0:Math.sqrt(o)},RD=[pm,Co,ri],MD=e=>RD.find(t=>t.test(e));function m0(e){const t=MD(e);if(!t)return!1;let s=t.parse(e);return t===ri&&(s=ED(s)),s}const h0=(e,t)=>{const s=m0(e),r=m0(t);if(!s||!r)return id(e,t);const o={...s};return i=>(o.red=Yu(s.red,r.red,i),o.green=Yu(s.green,r.green,i),o.blue=Yu(s.blue,r.blue,i),o.alpha=mn(s.alpha,r.alpha,i),Co.transform(o))},xm=new Set(["none","hidden"]);function PD(e,t){return xm.has(e)?s=>s<=0?e:t:s=>s>=1?t:e}function DD(e,t){return s=>mn(e,t,s)}function Mp(e){return typeof e=="number"?DD:typeof e=="string"?Ap(e)?id:Ln.test(e)?h0:_D:Array.isArray(e)?ck:typeof e=="object"?Ln.test(e)?h0:OD:id}function ck(e,t){const s=[...e],r=s.length,o=e.map((i,a)=>Mp(i)(i,t[a]));return i=>{for(let a=0;a<r;a++)s[a]=o[a](i);return s}}function OD(e,t){const s={...e,...t},r={};for(const o in s)e[o]!==void 0&&t[o]!==void 0&&(r[o]=Mp(e[o])(e[o],t[o]));return o=>{for(const i in r)s[i]=r[i](o);return s}}function LD(e,t){const s=[],r={color:0,var:0,number:0};for(let o=0;o<t.values.length;o++){const i=t.types[o],a=e.indexes[i][r[i]],l=e.values[a]??0;s[o]=l,r[i]++}return s}const _D=(e,t)=>{const s=Ws.createTransformer(t),r=Si(e),o=Si(t);return r.indexes.var.length===o.indexes.var.length&&r.indexes.color.length===o.indexes.color.length&&r.indexes.number.length>=o.indexes.number.length?xm.has(e)&&!o.values.length||xm.has(t)&&!r.values.length?PD(e,t):bl(ck(LD(r,o),o.values),s):id(e,t)};function dk(e,t,s){return typeof e=="number"&&typeof t=="number"&&typeof s=="number"?mn(e,t,s):Mp(e)(e,t)}const BD=e=>{const t=({timestamp:s})=>e(s);return{start:(s=!0)=>hn.update(t,s),stop:()=>to(t),now:()=>Zn.isProcessing?Zn.timestamp:as.now()}},uk=(e,t,s=10)=>{let r="";const o=Math.max(Math.round(t/s),2);for(let i=0;i<o;i++)r+=Math.round(e(i/(o-1))*1e4)/1e4+", ";return`linear(${r.substring(0,r.length-2)})`},ad=2e4;function Pp(e){let t=0;const s=50;let r=e.next(t);for(;!r.done&&t<ad;)t+=s,r=e.next(t);return t>=ad?1/0:t}function FD(e,t=100,s){const r=s({...e,keyframes:[0,t]}),o=Math.min(Pp(r),ad);return{type:"keyframes",ease:i=>r.next(o*i).value/t,duration:As(o)}}const En={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1};function gm(e,t){return e*Math.sqrt(1-t*t)}const zD=12;function $D(e,t,s){let r=s;for(let o=1;o<zD;o++)r=r-e(r)/t(r);return r}const Xu=.001;function VD({duration:e=En.duration,bounce:t=En.bounce,velocity:s=En.velocity,mass:r=En.mass}){let o,i,a=1-t;a=fr(En.minDamping,En.maxDamping,a),e=fr(En.minDuration,En.maxDuration,As(e)),a<1?(o=u=>{const d=u*a,m=d*e,h=d-s,p=gm(u,a),g=Math.exp(-m);return Xu-h/p*g},i=u=>{const m=u*a*e,h=m*s+s,p=Math.pow(a,2)*Math.pow(u,2)*e,g=Math.exp(-m),x=gm(Math.pow(u,2),a);return(-o(u)+Xu>0?-1:1)*((h-p)*g)/x}):(o=u=>{const d=Math.exp(-u*e),m=(u-s)*e+1;return-Xu+d*m},i=u=>{const d=Math.exp(-u*e),m=(s-u)*(e*e);return d*m});const l=5/e,c=$D(o,i,l);if(e=xs(e),isNaN(c))return{stiffness:En.stiffness,damping:En.damping,duration:e};{const u=Math.pow(c,2)*r;return{stiffness:u,damping:a*2*Math.sqrt(r*u),duration:e}}}const HD=["duration","bounce"],WD=["stiffness","damping","mass"];function p0(e,t){return t.some(s=>e[s]!==void 0)}function UD(e){let t={velocity:En.velocity,stiffness:En.stiffness,damping:En.damping,mass:En.mass,isResolvedFromDuration:!1,...e};if(!p0(e,WD)&&p0(e,HD))if(t.velocity=0,e.visualDuration){const s=e.visualDuration,r=2*Math.PI/(s*1.2),o=r*r,i=2*fr(.05,1,1-(e.bounce||0))*Math.sqrt(o);t={...t,mass:En.mass,stiffness:o,damping:i}}else{const s=VD({...e,velocity:0});t={...t,...s,mass:En.mass},t.isResolvedFromDuration=!0}return t}function ld(e=En.visualDuration,t=En.bounce){const s=typeof e!="object"?{visualDuration:e,keyframes:[0,1],bounce:t}:e;let{restSpeed:r,restDelta:o}=s;const i=s.keyframes[0],a=s.keyframes[s.keyframes.length-1],l={done:!1,value:i},{stiffness:c,damping:u,mass:d,duration:m,velocity:h,isResolvedFromDuration:p}=UD({...s,velocity:-As(s.velocity||0)}),g=h||0,x=u/(2*Math.sqrt(c*d)),v=a-i,b=As(Math.sqrt(c/d)),w=Math.abs(v)<5;r||(r=w?En.restSpeed.granular:En.restSpeed.default),o||(o=w?En.restDelta.granular:En.restDelta.default);let j,T,N,S,I,k;if(x<1)N=gm(b,x),S=(g+x*b*v)/N,j=F=>{const A=Math.exp(-x*b*F);return a-A*(S*Math.sin(N*F)+v*Math.cos(N*F))},I=x*b*S+v*N,k=x*b*v-S*N,T=F=>Math.exp(-x*b*F)*(I*Math.sin(N*F)+k*Math.cos(N*F));else if(x===1){j=A=>a-Math.exp(-b*A)*(v+(g+b*v)*A);const F=g+b*v;T=A=>Math.exp(-b*A)*(b*F*A-g)}else{const F=b*Math.sqrt(x*x-1);j=$=>{const U=Math.exp(-x*b*$),q=Math.min(F*$,300);return a-U*((g+x*b*v)*Math.sinh(q)+F*v*Math.cosh(q))/F};const A=(g+x*b*v)/F,M=x*b*A-v*F,R=x*b*v-A*F;T=$=>{const U=Math.exp(-x*b*$),q=Math.min(F*$,300);return U*(M*Math.sinh(q)+R*Math.cosh(q))}}const L={calculatedDuration:p&&m||null,velocity:F=>xs(T(F)),next:F=>{if(!p&&x<1){const M=Math.exp(-x*b*F),R=Math.sin(N*F),$=Math.cos(N*F),U=a-M*(S*R+v*$),q=xs(M*(I*R+k*$));return l.done=Math.abs(q)<=r&&Math.abs(a-U)<=o,l.value=l.done?a:U,l}const A=j(F);if(p)l.done=F>=m;else{const M=xs(T(F));l.done=Math.abs(M)<=r&&Math.abs(a-A)<=o}return l.value=l.done?a:A,l},toString:()=>{const F=Math.min(Pp(L),ad),A=uk(M=>L.next(F*M).value,F,30);return F+"ms "+A},toTransition:()=>{}};return L}ld.applyToOptions=e=>{const t=FD(e,100,ld);return e.ease=t.ease,e.duration=xs(t.duration),e.type="keyframes",e};const qD=5;function fk(e,t,s){const r=Math.max(t-qD,0);return U1(s-e(r),t-r)}function vm({keyframes:e,velocity:t=0,power:s=.8,timeConstant:r=325,bounceDamping:o=10,bounceStiffness:i=500,modifyTarget:a,min:l,max:c,restDelta:u=.5,restSpeed:d}){const m=e[0],h={done:!1,value:m},p=k=>l!==void 0&&k<l||c!==void 0&&k>c,g=k=>l===void 0?c:c===void 0||Math.abs(l-k)<Math.abs(c-k)?l:c;let x=s*t;const v=m+x,b=a===void 0?v:a(v);b!==v&&(x=b-m);const w=k=>-x*Math.exp(-k/r),j=k=>b+w(k),T=k=>{const L=w(k),F=j(k);h.done=Math.abs(L)<=u,h.value=h.done?b:F};let N,S;const I=k=>{p(h.value)&&(N=k,S=ld({keyframes:[h.value,g(h.value)],velocity:fk(j,k,h.value),damping:o,stiffness:i,restDelta:u,restSpeed:d}))};return I(0),{calculatedDuration:null,next:k=>{let L=!1;return!S&&N===void 0&&(L=!0,T(k),I(k)),N!==void 0&&k>=N?S.next(k-N):(!L&&T(k),h)}}}function GD(e,t,s){const r=[],o=s||eo.mix||dk,i=e.length-1;for(let a=0;a<i;a++){let l=o(e[a],e[a+1]);if(t){const c=Array.isArray(t)?t[a]||Ls:t;l=bl(c,l)}r.push(l)}return r}function KD(e,t,{clamp:s=!0,ease:r,mixer:o}={}){const i=e.length;if(su(i===t.length),i===1)return()=>t[0];if(i===2&&t[0]===t[1])return()=>t[1];const a=e[0]===e[1];e[0]>e[i-1]&&(e=[...e].reverse(),t=[...t].reverse());const l=GD(t,r,o),c=l.length,u=d=>{if(a&&d<e[0])return t[0];let m=0;if(c>1)for(;m<e.length-2&&!(d<e[m+1]);m++);const h=Va(e[m],e[m+1],d);return l[m](h)};return s?d=>u(fr(e[0],e[i-1],d)):u}function YD(e,t){const s=e[e.length-1];for(let r=1;r<=t;r++){const o=Va(0,t,r);e.push(mn(s,1,o))}}function XD(e){const t=[0];return YD(t,e.length-1),t}function QD(e,t){return e.map(s=>s*t)}function JD(e,t){return e.map(()=>t||ek).splice(0,e.length-1)}function va({duration:e=300,keyframes:t,times:s,ease:r="easeInOut"}){const o=iD(r)?r.map(c0):c0(r),i={done:!1,value:t[0]},a=QD(s&&s.length===t.length?s:XD(t),e),l=KD(a,t,{ease:Array.isArray(o)?o:JD(t,o)});return{calculatedDuration:e,next:c=>(i.value=l(c),i.done=c>=e,i)}}const ZD=e=>e!==null;function ru(e,{repeat:t,repeatType:s="loop"},r,o=1){const i=e.filter(ZD),l=o<0||t&&s!=="loop"&&t%2===1?0:i.length-1;return!l||r===void 0?i[l]:r}const e6={decay:vm,inertia:vm,tween:va,keyframes:va,spring:ld};function mk(e){typeof e.type=="string"&&(e.type=e6[e.type])}class Dp{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(t=>{this.resolve=t})}notifyFinished(){this.resolve()}then(t,s){return this.finished.then(t,s)}}const t6=e=>e/100;class cd extends Dp{constructor(t){super(),this.state="idle",this.startTime=null,this.isStopped=!1,this.currentTime=0,this.holdTime=null,this.playbackSpeed=1,this.delayState={done:!1,value:void 0},this.stop=()=>{const{motionValue:s}=this.options;s&&s.updatedAt!==as.now()&&this.tick(as.now()),this.isStopped=!0,this.state!=="idle"&&(this.teardown(),this.options.onStop?.())},this.options=t,this.initAnimation(),this.play(),t.autoplay===!1&&this.pause()}initAnimation(){const{options:t}=this;mk(t);const{type:s=va,repeat:r=0,repeatDelay:o=0,repeatType:i,velocity:a=0}=t;let{keyframes:l}=t;const c=s||va;c!==va&&typeof l[0]!="number"&&(this.mixKeyframes=bl(t6,dk(l[0],l[1])),l=[0,100]);const u=c({...t,keyframes:l});i==="mirror"&&(this.mirroredGenerator=c({...t,keyframes:[...l].reverse(),velocity:-a})),u.calculatedDuration===null&&(u.calculatedDuration=Pp(u));const{calculatedDuration:d}=u;this.calculatedDuration=d,this.resolvedDuration=d+o,this.totalDuration=this.resolvedDuration*(r+1)-o,this.generator=u}updateTime(t){const s=Math.round(t-this.startTime)*this.playbackSpeed;this.holdTime!==null?this.currentTime=this.holdTime:this.currentTime=s}tick(t,s=!1){const{generator:r,totalDuration:o,mixKeyframes:i,mirroredGenerator:a,resolvedDuration:l,calculatedDuration:c}=this;if(this.startTime===null)return r.next(0);const{delay:u=0,keyframes:d,repeat:m,repeatType:h,repeatDelay:p,type:g,onUpdate:x,finalKeyframe:v}=this.options;this.speed>0?this.startTime=Math.min(this.startTime,t):this.speed<0&&(this.startTime=Math.min(t-o/this.speed,this.startTime)),s?this.currentTime=t:this.updateTime(t);const b=this.currentTime-u*(this.playbackSpeed>=0?1:-1),w=this.playbackSpeed>=0?b<0:b>o;this.currentTime=Math.max(b,0),this.state==="finished"&&this.holdTime===null&&(this.currentTime=o);let j=this.currentTime,T=r;if(m){const k=Math.min(this.currentTime,o)/l;let L=Math.floor(k),F=k%1;!F&&k>=1&&(F=1),F===1&&L--,L=Math.min(L,m+1),L%2&&(h==="reverse"?(F=1-F,p&&(F-=p/l)):h==="mirror"&&(T=a)),j=fr(0,1,F)*l}let N;w?(this.delayState.value=d[0],N=this.delayState):N=T.next(j),i&&!w&&(N.value=i(N.value));let{done:S}=N;!w&&c!==null&&(S=this.playbackSpeed>=0?this.currentTime>=o:this.currentTime<=0);const I=this.holdTime===null&&(this.state==="finished"||this.state==="running"&&S);return I&&g!==vm&&(N.value=ru(d,this.options,v,this.speed)),x&&x(N.value),I&&this.finish(),N}then(t,s){return this.finished.then(t,s)}get duration(){return As(this.calculatedDuration)}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+As(t)}get time(){return As(this.currentTime)}set time(t){t=xs(t),this.currentTime=t,this.startTime===null||this.holdTime!==null||this.playbackSpeed===0?this.holdTime=t:this.driver&&(this.startTime=this.driver.now()-t/this.playbackSpeed),this.driver?this.driver.start(!1):(this.startTime=0,this.state="paused",this.holdTime=t,this.tick(t))}getGeneratorVelocity(){const t=this.currentTime;if(t<=0)return this.options.velocity||0;if(this.generator.velocity)return this.generator.velocity(t);const s=this.generator.next(t).value;return fk(r=>this.generator.next(r).value,t,s)}get speed(){return this.playbackSpeed}set speed(t){const s=this.playbackSpeed!==t;s&&this.driver&&this.updateTime(as.now()),this.playbackSpeed=t,s&&this.driver&&(this.time=As(this.currentTime))}play(){if(this.isStopped)return;const{driver:t=BD,startTime:s}=this.options;this.driver||(this.driver=t(o=>this.tick(o))),this.options.onPlay?.();const r=this.driver.now();this.state==="finished"?(this.updateFinished(),this.startTime=r):this.holdTime!==null?this.startTime=r-this.holdTime:this.startTime||(this.startTime=s??r),this.state==="finished"&&this.speed<0&&(this.startTime+=this.calculatedDuration),this.holdTime=null,this.state="running",this.driver.start()}pause(){this.state="paused",this.updateTime(as.now()),this.holdTime=this.currentTime}complete(){this.state!=="running"&&this.play(),this.state="finished",this.holdTime=null}finish(){this.notifyFinished(),this.teardown(),this.state="finished",this.options.onComplete?.()}cancel(){this.holdTime=null,this.startTime=0,this.tick(0),this.teardown(),this.options.onCancel?.()}teardown(){this.state="idle",this.stopDriver(),this.startTime=this.holdTime=null}stopDriver(){this.driver&&(this.driver.stop(),this.driver=void 0)}sample(t){return this.startTime=0,this.tick(t,!0)}attachTimeline(t){return this.options.allowFlatten&&(this.options.type="keyframes",this.options.ease="linear",this.initAnimation()),this.driver?.stop(),t.observe(this)}}function n6(e){for(let t=1;t<e.length;t++)e[t]??(e[t]=e[t-1])}const Io=e=>e*180/Math.PI,bm=e=>{const t=Io(Math.atan2(e[1],e[0]));return ym(t)},s6={x:4,y:5,translateX:4,translateY:5,scaleX:0,scaleY:3,scale:e=>(Math.abs(e[0])+Math.abs(e[3]))/2,rotate:bm,rotateZ:bm,skewX:e=>Io(Math.atan(e[1])),skewY:e=>Io(Math.atan(e[2])),skew:e=>(Math.abs(e[1])+Math.abs(e[2]))/2},ym=e=>(e=e%360,e<0&&(e+=360),e),x0=bm,g0=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]),v0=e=>Math.sqrt(e[4]*e[4]+e[5]*e[5]),r6={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:g0,scaleY:v0,scale:e=>(g0(e)+v0(e))/2,rotateX:e=>ym(Io(Math.atan2(e[6],e[5]))),rotateY:e=>ym(Io(Math.atan2(-e[2],e[0]))),rotateZ:x0,rotate:x0,skewX:e=>Io(Math.atan(e[4])),skewY:e=>Io(Math.atan(e[1])),skew:e=>(Math.abs(e[1])+Math.abs(e[4]))/2};function wm(e){return e.includes("scale")?1:0}function jm(e,t){if(!e||e==="none")return wm(t);const s=e.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);let r,o;if(s)r=r6,o=s;else{const l=e.match(/^matrix\(([-\d.e\s,]+)\)$/u);r=s6,o=l}if(!o)return wm(t);const i=r[t],a=o[1].split(",").map(i6);return typeof i=="function"?i(a):a[i]}const o6=(e,t)=>{const{transform:s="none"}=getComputedStyle(e);return jm(s,t)};function i6(e){return parseFloat(e.trim())}const Li=["transformPerspective","x","y","z","translateX","translateY","translateZ","scale","scaleX","scaleY","rotate","rotateX","rotateY","rotateZ","skew","skewX","skewY"],_i=new Set([...Li,"pathRotation"]),b0=e=>e===Oi||e===ct,a6=new Set(["x","y","z"]),l6=Li.filter(e=>!a6.has(e));function c6(e){const t=[];return l6.forEach(s=>{const r=e.getValue(s);r!==void 0&&(t.push([s,r.get()]),r.set(s.startsWith("scale")?1:0))}),t}const Kr={width:({x:e},{paddingLeft:t="0",paddingRight:s="0",boxSizing:r})=>{const o=e.max-e.min;return r==="border-box"?o:o-parseFloat(t)-parseFloat(s)},height:({y:e},{paddingTop:t="0",paddingBottom:s="0",boxSizing:r})=>{const o=e.max-e.min;return r==="border-box"?o:o-parseFloat(t)-parseFloat(s)},top:(e,{top:t})=>parseFloat(t),left:(e,{left:t})=>parseFloat(t),bottom:({y:e},{top:t})=>parseFloat(t)+(e.max-e.min),right:({x:e},{left:t})=>parseFloat(t)+(e.max-e.min),x:(e,{transform:t})=>jm(t,"x"),y:(e,{transform:t})=>jm(t,"y")};Kr.translateX=Kr.x;Kr.translateY=Kr.y;const Ro=new Set;let km=!1,Nm=!1,Sm=!1;function hk(){if(Nm){const e=Array.from(Ro).filter(r=>r.needsMeasurement),t=new Set(e.map(r=>r.element)),s=new Map;t.forEach(r=>{const o=c6(r);o.length&&(s.set(r,o),r.render())}),e.forEach(r=>r.measureInitialState()),t.forEach(r=>{r.render();const o=s.get(r);o&&o.forEach(([i,a])=>{r.getValue(i)?.set(a)})}),e.forEach(r=>r.measureEndState()),e.forEach(r=>{r.suspendedScrollY!==void 0&&window.scrollTo(0,r.suspendedScrollY)})}Nm=!1,km=!1,Ro.forEach(e=>e.complete(Sm)),Ro.clear()}function pk(){Ro.forEach(e=>{e.readKeyframes(),e.needsMeasurement&&(Nm=!0)})}function d6(){Sm=!0,pk(),hk(),Sm=!1}class Op{constructor(t,s,r,o,i,a=!1){this.state="pending",this.isAsync=!1,this.needsMeasurement=!1,this.unresolvedKeyframes=[...t],this.onComplete=s,this.name=r,this.motionValue=o,this.element=i,this.isAsync=a}scheduleResolve(){this.state="scheduled",this.isAsync?(Ro.add(this),km||(km=!0,hn.read(pk),hn.resolveKeyframes(hk))):(this.readKeyframes(),this.complete())}readKeyframes(){const{unresolvedKeyframes:t,name:s,element:r,motionValue:o}=this;if(t[0]===null){const i=o?.get(),a=t[t.length-1];if(i!==void 0)t[0]=i;else if(r&&s){const l=r.readValue(s,a);l!=null&&(t[0]=l)}t[0]===void 0&&(t[0]=a),o&&i===void 0&&o.set(t[0])}n6(t)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(t=!1){this.state="complete",this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,t),Ro.delete(this)}cancel(){this.state==="scheduled"&&(Ro.delete(this),this.state="pending")}resume(){this.state==="pending"&&this.scheduleResolve()}}const u6=e=>e.startsWith("--");function xk(e,t,s){u6(t)?e.style.setProperty(t,s):e.style[t]=s}const f6={};function gk(e,t){const s=W1(e);return()=>f6[t]??s()}const m6=gk(()=>window.ScrollTimeline!==void 0,"scrollTimeline"),vk=gk(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0},"linearEasing"),ca=([e,t,s,r])=>`cubic-bezier(${e}, ${t}, ${s}, ${r})`,y0={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:ca([0,.65,.55,1]),circOut:ca([.55,0,1,.45]),backIn:ca([.31,.01,.66,-.59]),backOut:ca([.33,1.53,.69,.99])};function bk(e,t){if(e)return typeof e=="function"?vk()?uk(e,t):"ease-out":tk(e)?ca(e):Array.isArray(e)?e.map(s=>bk(s,t)||y0.easeOut):y0[e]}function h6(e,t,s,{delay:r=0,duration:o=300,repeat:i=0,repeatType:a="loop",ease:l="easeOut",times:c}={},u=void 0){const d={[t]:s};c&&(d.offset=c);const m=bk(l,o);Array.isArray(m)&&(d.easing=m);const h={delay:r,duration:o,easing:Array.isArray(m)?"linear":m,fill:"both",iterations:i+1,direction:a==="reverse"?"alternate":"normal"};return u&&(h.pseudoElement=u),e.animate(d,h)}function yk(e){return typeof e=="function"&&"applyToOptions"in e}function p6({type:e,...t}){return yk(e)&&vk()?e.applyToOptions(t):(t.duration??(t.duration=300),t.ease??(t.ease="easeOut"),t)}class wk extends Dp{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:s,name:r,keyframes:o,pseudoElement:i,allowFlatten:a=!1,finalKeyframe:l,onComplete:c}=t;this.isPseudoElement=!!i,this.allowFlatten=a,this.options=t,su(typeof t.type!="string");const u=p6(t);this.animation=h6(s,r,o,u,i),u.autoplay===!1&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!i){const d=ru(o,this.options,l,this.speed);this.updateMotionValue&&this.updateMotionValue(d),xk(s,r,d),this.animation.cancel()}c?.(),this.notifyFinished()}}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),this.state==="finished"&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch{}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;t==="idle"||t==="finished"||(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){const t=this.options?.element;!this.isPseudoElement&&t?.isConnected&&this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return As(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+As(t)}get time(){return As(Number(this.animation.currentTime)||0)}set time(t){const s=this.finishedTime!==null;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=xs(t),s&&this.animation.pause()}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return this.finishedTime!==null?"finished":this.animation.playState}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,rangeStart:s,rangeEnd:r,observe:o}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&m6()?(this.animation.timeline=t,s&&(this.animation.rangeStart=s),r&&(this.animation.rangeEnd=r),Ls):o(this)}}const jk={anticipate:Q1,backInOut:X1,circInOut:Z1};function x6(e){return e in jk}function g6(e){typeof e.ease=="string"&&x6(e.ease)&&(e.ease=jk[e.ease])}const Qu=10;class v6 extends wk{constructor(t){g6(t),mk(t),super(t),t.startTime!==void 0&&t.autoplay!==!1&&(this.startTime=t.startTime),this.options=t}updateMotionValue(t){const{motionValue:s,onUpdate:r,onComplete:o,element:i,...a}=this.options;if(!s)return;if(t!==void 0){s.set(t);return}const l=new cd({...a,autoplay:!1}),c=Math.max(Qu,as.now()-this.startTime),u=fr(0,Qu,c-Qu),d=l.sample(c).value,{name:m}=this.options;i&&m&&xk(i,m,d),s.setWithVelocity(l.sample(Math.max(0,c-u)).value,d,u),l.stop()}}const w0=(e,t)=>t==="zIndex"?!1:!!(typeof e=="number"||Array.isArray(e)||typeof e=="string"&&(Ws.test(e)||e==="0")&&!e.startsWith("url("));function b6(e){const t=e[0];if(e.length===1)return!0;for(let s=0;s<e.length;s++)if(e[s]!==t)return!0}function y6(e,t,s,r){const o=e[0];if(o===null)return!1;if(t==="display"||t==="visibility")return!0;const i=e[e.length-1],a=w0(o,t),l=w0(i,t);return!a||!l?!1:b6(e)||(s==="spring"||yk(s))&&r}function Cm(e){e.duration=0,e.type="keyframes"}const kk=new Set(["opacity","clipPath","filter","transform","backgroundColor"]),w6=/^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;function j6(e){for(let t=0;t<e.length;t++)if(typeof e[t]=="string"&&w6.test(e[t]))return!0;return!1}const k6=new Set(["color","backgroundColor","outlineColor","fill","stroke","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor"]),N6=W1(()=>Object.hasOwnProperty.call(Element.prototype,"animate"));function S6(e){const{motionValue:t,name:s,repeatDelay:r,repeatType:o,damping:i,type:a,keyframes:l}=e,c=t?.owner?.current;if(!(c instanceof HTMLElement)&&!(c instanceof SVGElement))return!1;const{onUpdate:u,transformTemplate:d}=t.owner.getProps();return N6()&&s&&(kk.has(s)||k6.has(s)&&j6(l))&&(s!=="transform"||!d)&&!u&&!r&&o!=="mirror"&&i!==0&&a!=="inertia"}const C6=40;class I6 extends Dp{constructor({autoplay:t=!0,delay:s=0,type:r="keyframes",repeat:o=0,repeatDelay:i=0,repeatType:a="loop",keyframes:l,name:c,motionValue:u,element:d,...m}){super(),this.stop=()=>{this._animation&&(this._animation.stop(),this.stopTimeline?.()),this.keyframeResolver?.cancel()},this.createdAt=as.now();const h={autoplay:t,delay:s,type:r,repeat:o,repeatDelay:i,repeatType:a,name:c,motionValue:u,element:d,...m},p=d?.KeyframeResolver||Op;this.keyframeResolver=new p(l,(g,x,v)=>this.onKeyframesResolved(g,x,h,!v),c,u,d),this.keyframeResolver?.scheduleResolve()}onKeyframesResolved(t,s,r,o){this.keyframeResolver=void 0;const{name:i,type:a,velocity:l,delay:c,isHandoff:u,onUpdate:d}=r;this.resolvedAt=as.now();let m=!0;y6(t,i,a,l)||(m=!1,(eo.instantAnimations||!c)&&d?.(ru(t,r,s)),t[0]=t[t.length-1],Cm(r),r.repeat=0);const p={startTime:o?this.resolvedAt?this.resolvedAt-this.createdAt>C6?this.resolvedAt:this.createdAt:this.createdAt:void 0,finalKeyframe:s,...r,keyframes:t},g=m&&!u&&S6(p),x=p.motionValue?.owner?.current;let v;if(g)try{v=new v6({...p,element:x})}catch{v=new cd(p)}else v=new cd(p);v.finished.then(()=>{this.notifyFinished()}).catch(Ls),this.pendingTimeline&&(this.stopTimeline=v.attachTimeline(this.pendingTimeline),this.pendingTimeline=void 0),this._animation=v}get finished(){return this._animation?this.animation.finished:this._finished}then(t,s){return this.finished.finally(t).then(()=>{})}get animation(){return this._animation||(this.keyframeResolver?.resume(),d6()),this._animation}get duration(){return this.animation.duration}get iterationDuration(){return this.animation.iterationDuration}get time(){return this.animation.time}set time(t){this.animation.time=t}get speed(){return this.animation.speed}get state(){return this.animation.state}set speed(t){this.animation.speed=t}get startTime(){return this.animation.startTime}attachTimeline(t){return this._animation?this.stopTimeline=this.animation.attachTimeline(t):this.pendingTimeline=t,()=>this.stop()}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.complete()}cancel(){this._animation&&this.animation.cancel(),this.keyframeResolver?.cancel()}}function Nk(e,t,s,r=0,o=1){const i=Array.from(e).sort((u,d)=>u.sortNodePosition(d)).indexOf(t),a=e.size,l=(a-1)*r;return typeof s=="function"?s(i,a):o===1?i*r:l-i*r}const j0=30,T6=e=>!isNaN(parseFloat(e));class A6{constructor(t,s={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=r=>{const o=as.now();if(this.updatedAt!==o&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(r),this.current!==this.prev&&(this.events.change?.notify(this.current),this.dependents))for(const i of this.dependents)i.dirty()},this.hasAnimated=!1,this.setCurrent(t),this.owner=s.owner}setCurrent(t){this.current=t,this.updatedAt=as.now(),this.canTrackVelocity===null&&t!==void 0&&(this.canTrackVelocity=T6(this.current))}setPrevFrameValue(t=this.current){this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt}onChange(t){return this.on("change",t)}on(t,s){this.events[t]||(this.events[t]=new Cp);const r=this.events[t].add(s);return t==="change"?()=>{r(),hn.read(()=>{this.events.change.getSize()||this.stop()})}:r}clearListeners(){for(const t in this.events)this.events[t].clear()}attach(t,s){this.passiveEffect=t,this.stopPassiveEffect=s}set(t){this.passiveEffect?this.passiveEffect(t,this.updateAndNotify):this.updateAndNotify(t)}setWithVelocity(t,s,r){this.set(s),this.prev=void 0,this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt-r}jump(t,s=!0){this.updateAndNotify(t),this.prev=t,this.prevUpdatedAt=this.prevFrameValue=void 0,s&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){this.events.change?.notify(this.current)}addDependent(t){this.dependents||(this.dependents=new Set),this.dependents.add(t)}removeDependent(t){this.dependents&&this.dependents.delete(t)}get(){return this.current}getPrevious(){return this.prev}getVelocity(){const t=as.now();if(!this.canTrackVelocity||this.prevFrameValue===void 0||t-this.updatedAt>j0)return 0;const s=Math.min(this.updatedAt-this.prevUpdatedAt,j0);return U1(parseFloat(this.current)-parseFloat(this.prevFrameValue),s)}start(t){return this.stop(),new Promise(s=>{this.hasAnimated=!0,this.animation=t(s),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function Ci(e,t){return new A6(e,t)}function Sk(e,t){if(e?.inherit&&t){const{inherit:s,...r}=e;return{...t,...r}}return e}function Lp(e,t){const s=e?.[t]??e?.default??e;return s!==e?Sk(s,e):s}const E6={type:"spring",stiffness:500,damping:25,restSpeed:10},R6=e=>({type:"spring",stiffness:550,damping:e===0?2*Math.sqrt(550):30,restSpeed:10}),M6={type:"keyframes",duration:.8},P6={type:"keyframes",ease:[.25,.1,.35,1],duration:.3},D6=(e,{keyframes:t})=>t.length>2?M6:_i.has(e)?e.startsWith("scale")?R6(t[1]):E6:P6,O6=new Set(["when","delay","delayChildren","staggerChildren","staggerDirection","repeat","repeatType","repeatDelay","from","elapsed"]);function L6(e){for(const t in e)if(!O6.has(t))return!0;return!1}const _p=(e,t,s,r={},o,i)=>a=>{const l=Lp(r,e)||{},c=l.delay||r.delay||0;let{elapsed:u=0}=r;u=u-xs(c);const d={keyframes:Array.isArray(s)?s:[null,s],ease:"easeOut",velocity:t.getVelocity(),...l,delay:-u,onUpdate:h=>{t.set(h),l.onUpdate&&l.onUpdate(h)},onComplete:()=>{a(),l.onComplete&&l.onComplete()},name:e,motionValue:t,element:i?void 0:o};L6(l)||Object.assign(d,D6(e,d)),d.duration&&(d.duration=xs(d.duration)),d.repeatDelay&&(d.repeatDelay=xs(d.repeatDelay)),d.from!==void 0&&(d.keyframes[0]=d.from);let m=!1;if((d.type===!1||d.duration===0&&!d.repeatDelay)&&(Cm(d),d.delay===0&&(m=!0)),(eo.instantAnimations||eo.skipAnimations||o?.shouldSkipAnimations||l.skipAnimations)&&(m=!0,Cm(d),d.delay=0),d.allowFlatten=!l.type&&!l.ease,m&&!i&&t.get()!==void 0){const h=ru(d.keyframes,l);if(h!==void 0){hn.update(()=>{d.onUpdate(h),d.onComplete()});return}}return l.isSync?new cd(d):new I6(d)},_6=/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;function B6(e){const t=_6.exec(e);if(!t)return[,];const[,s,r,o]=t;return[`--${s??r}`,o]}function Ck(e,t,s=1){const[r,o]=B6(e);if(!r)return;const i=window.getComputedStyle(t).getPropertyValue(r);if(i){const a=i.trim();return $1(a)?parseFloat(a):a}return Ap(o)?Ck(o,t,s+1):o}function k0(e){const t=[{},{}];return e?.values.forEach((s,r)=>{t[0][r]=s.get(),t[1][r]=s.getVelocity()}),t}function Bp(e,t,s,r){if(typeof t=="function"){const[o,i]=k0(r);t=t(s!==void 0?s:e.custom,o,i)}if(typeof t=="string"&&(t=e.variants&&e.variants[t]),typeof t=="function"){const[o,i]=k0(r);t=t(s!==void 0?s:e.custom,o,i)}return t}function Mo(e,t,s){const r=e.getProps();return Bp(r,t,s!==void 0?s:r.custom,e)}const Ik=new Set(["width","height","top","left","right","bottom",...Li]),Im=e=>Array.isArray(e);function F6(e,t,s){e.hasValue(t)?e.getValue(t).set(s):e.addValue(t,Ci(s))}function z6(e){return Im(e)?e[e.length-1]||0:e}function $6(e,t){const s=Mo(e,t);let{transitionEnd:r={},transition:o={},...i}=s||{};i={...i,...r};for(const a in i){const l=z6(i[a]);F6(e,a,l)}}const es=e=>!!(e&&e.getVelocity);function V6(e){return!!(es(e)&&e.add)}function Tm(e,t){const s=e.getValue("willChange");if(V6(s))return s.add(t);if(!s&&eo.WillChange){const r=new eo.WillChange("auto");e.addValue("willChange",r),r.add(t)}}function Fp(e){return e.replace(/([A-Z])/g,t=>`-${t.toLowerCase()}`)}const H6="framerAppearId",Tk="data-"+Fp(H6);function Ak(e){return e.props[Tk]}const W6=typeof window<"u";function U6({protectedKeys:e,needsAnimating:t},s){const r=e.hasOwnProperty(s)&&t[s]!==!0;return t[s]=!1,r}function Ek(e,t,{delay:s=0,transitionOverride:r,type:o}={}){let{transition:i,transitionEnd:a,...l}=t;const c=e.getDefaultTransition();i=i?Sk(i,c):c;const u=i?.reduceMotion,d=i?.skipAnimations;r&&(i=r);const m=[],h=o&&e.animationState&&e.animationState.getState()[o],p=i?.path;p&&p.animateVisualElement(e,l,i,s,m);for(const g in l){const x=e.getValue(g,e.latestValues[g]??null),v=l[g];if(v===void 0||h&&U6(h,g))continue;const b={delay:s,...Lp(i||{},g)};d&&(b.skipAnimations=!0);const w=x.get();if(w!==void 0&&!x.isAnimating()&&!Array.isArray(v)&&v===w&&!b.velocity){hn.update(()=>x.set(v));continue}let j=!1;if(W6&&window.MotionHandoffAnimation){const S=Ak(e);if(S){const I=window.MotionHandoffAnimation(S,g,hn);I!==null&&(b.startTime=I,j=!0)}}Tm(e,g);const T=u??e.shouldReduceMotion;x.start(_p(g,x,v,T&&Ik.has(g)?{type:!1}:b,e,j));const N=x.animation;N&&m.push(N)}if(a){const g=()=>hn.update(()=>{a&&$6(e,a)});m.length?Promise.all(m).then(g):g()}return m}function Am(e,t,s={}){const r=Mo(e,t,s.type==="exit"?e.presenceContext?.custom:void 0);let{transition:o=e.getDefaultTransition()||{}}=r||{};s.transitionOverride&&(o=s.transitionOverride);const i=r?()=>Promise.all(Ek(e,r,s)):()=>Promise.resolve(),a=e.variantChildren&&e.variantChildren.size?(c=0)=>{const{delayChildren:u=0,staggerChildren:d,staggerDirection:m}=o;return q6(e,t,c,u,d,m,s)}:()=>Promise.resolve(),{when:l}=o;if(l){const[c,u]=l==="beforeChildren"?[i,a]:[a,i];return c().then(()=>u())}else return Promise.all([i(),a(s.delay)])}function q6(e,t,s=0,r=0,o=0,i=1,a){const l=[];for(const c of e.variantChildren)c.notify("AnimationStart",t),l.push(Am(c,t,{...a,delay:s+(typeof r=="function"?0:r)+Nk(e.variantChildren,c,r,o,i)}).then(()=>c.notify("AnimationComplete",t)));return Promise.all(l)}function G6(e,t,s={}){e.notify("AnimationStart",t);let r;if(Array.isArray(t)){const o=t.map(i=>Am(e,i,s));r=Promise.all(o)}else if(typeof t=="string")r=Am(e,t,s);else{const o=typeof t=="function"?Mo(e,t,s.custom):t;r=Promise.all(Ek(e,o,s))}return r.then(()=>{e.notify("AnimationComplete",t)})}const K6={test:e=>e==="auto",parse:e=>e},Rk=e=>t=>t.test(e),Mk=[Oi,ct,ar,br,bD,vD,K6],N0=e=>Mk.find(Rk(e));function Y6(e){return typeof e=="number"?e===0:e!==null?e==="none"||e==="0"||H1(e):!0}const X6=new Set(["brightness","contrast","saturate","opacity"]);function Q6(e){const[t,s]=e.slice(0,-1).split("(");if(t==="drop-shadow")return e;const[r]=s.match(Ep)||[];if(!r)return e;const o=s.replace(r,"");let i=X6.has(t)?1:0;return r!==s&&(i*=100),t+"("+i+o+")"}const J6=/\b([a-z-]*)\(.*?\)/gu,Em={...Ws,getAnimatableNone:e=>{const t=e.match(J6);return t?t.map(Q6).join(" "):e}},Rm={...Ws,getAnimatableNone:e=>{const t=Ws.parse(e);return Ws.createTransformer(e)(t.map(r=>typeof r=="number"?0:typeof r=="object"?{...r,alpha:1}:r))}},S0={...Oi,transform:Math.round},Z6={rotate:br,pathRotation:br,rotateX:br,rotateY:br,rotateZ:br,scale:Ul,scaleX:Ul,scaleY:Ul,scaleZ:Ul,skew:br,skewX:br,skewY:br,distance:ct,translateX:ct,translateY:ct,translateZ:ct,x:ct,y:ct,z:ct,perspective:ct,transformPerspective:ct,opacity:Ha,originX:u0,originY:u0,originZ:ct},dd={borderWidth:ct,borderTopWidth:ct,borderRightWidth:ct,borderBottomWidth:ct,borderLeftWidth:ct,borderRadius:ct,borderTopLeftRadius:ct,borderTopRightRadius:ct,borderBottomRightRadius:ct,borderBottomLeftRadius:ct,width:ct,maxWidth:ct,height:ct,maxHeight:ct,top:ct,right:ct,bottom:ct,left:ct,inset:ct,insetBlock:ct,insetBlockStart:ct,insetBlockEnd:ct,insetInline:ct,insetInlineStart:ct,insetInlineEnd:ct,padding:ct,paddingTop:ct,paddingRight:ct,paddingBottom:ct,paddingLeft:ct,paddingBlock:ct,paddingBlockStart:ct,paddingBlockEnd:ct,paddingInline:ct,paddingInlineStart:ct,paddingInlineEnd:ct,margin:ct,marginTop:ct,marginRight:ct,marginBottom:ct,marginLeft:ct,marginBlock:ct,marginBlockStart:ct,marginBlockEnd:ct,marginInline:ct,marginInlineStart:ct,marginInlineEnd:ct,fontSize:ct,backgroundPositionX:ct,backgroundPositionY:ct,...Z6,zIndex:S0,fillOpacity:Ha,strokeOpacity:Ha,numOctaves:S0},eO={...dd,color:Ln,backgroundColor:Ln,outlineColor:Ln,fill:Ln,stroke:Ln,borderColor:Ln,borderTopColor:Ln,borderRightColor:Ln,borderBottomColor:Ln,borderLeftColor:Ln,filter:Em,WebkitFilter:Em,mask:Rm,WebkitMask:Rm},Pk=e=>eO[e],tO=new Set([Em,Rm]);function Dk(e,t){let s=Pk(e);return tO.has(s)||(s=Ws),s.getAnimatableNone?s.getAnimatableNone(t):void 0}const nO=new Set(["auto","none","0"]);function sO(e,t,s){let r=0,o;for(;r<e.length&&!o;){const i=e[r];typeof i=="string"&&!nO.has(i)&&Si(i).values.length&&(o=e[r]),r++}if(o&&s)for(const i of t)e[i]=Dk(s,o)}class rO extends Op{constructor(t,s,r,o,i){super(t,s,r,o,i,!0)}readKeyframes(){const{unresolvedKeyframes:t,element:s,name:r}=this;if(!s||!s.current)return;super.readKeyframes();for(let d=0;d<t.length;d++){let m=t[d];if(typeof m=="string"&&(m=m.trim(),Ap(m))){const h=Ck(m,s.current);h!==void 0&&(t[d]=h),d===t.length-1&&(this.finalKeyframe=m)}}if(this.resolveNoneKeyframes(),!Ik.has(r)||t.length!==2)return;const[o,i]=t,a=N0(o),l=N0(i),c=d0(o),u=d0(i);if(c!==u&&Kr[r]){this.needsMeasurement=!0;return}if(a!==l)if(b0(a)&&b0(l))for(let d=0;d<t.length;d++){const m=t[d];typeof m=="string"&&(t[d]=parseFloat(m))}else Kr[r]&&(this.needsMeasurement=!0)}resolveNoneKeyframes(){const{unresolvedKeyframes:t,name:s}=this,r=[];for(let o=0;o<t.length;o++)(t[o]===null||Y6(t[o]))&&r.push(o);r.length&&sO(t,r,s)}measureInitialState(){const{element:t,unresolvedKeyframes:s,name:r}=this;if(!t||!t.current)return;r==="height"&&(this.suspendedScrollY=window.pageYOffset),this.measuredOrigin=Kr[r](t.measureViewportBox(),window.getComputedStyle(t.current)),s[0]=this.measuredOrigin;const o=s[s.length-1];o!==void 0&&t.getValue(r,o).jump(o,!1)}measureEndState(){const{element:t,name:s,unresolvedKeyframes:r}=this;if(!t||!t.current)return;const o=t.getValue(s);o&&o.jump(this.measuredOrigin,!1);const i=r.length-1,a=r[i];r[i]=Kr[s](t.measureViewportBox(),window.getComputedStyle(t.current)),a!==null&&this.finalKeyframe===void 0&&(this.finalKeyframe=a),this.removedTransforms?.length&&this.removedTransforms.forEach(([l,c])=>{t.getValue(l).set(c)}),this.resolveNoneKeyframes()}}const zp=["borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius"];function Ok(e,t,s){if(e==null)return[];if(e instanceof EventTarget)return[e];if(typeof e=="string"){let r=document;const o=s?.[e]??r.querySelectorAll(e);return o?Array.from(o):[]}return Array.from(e).filter(r=>r!=null)}const Mm=(e,t)=>t&&typeof e=="number"?t.transform(e):e;function Nc(e){return V1(e)&&"offsetHeight"in e&&!("ownerSVGElement"in e)}const{schedule:$p}=nk(queueMicrotask,!1),$s={x:!1,y:!1};function Lk(){return $s.x||$s.y}function oO(e){return e==="x"||e==="y"?$s[e]?null:($s[e]=!0,()=>{$s[e]=!1}):$s.x||$s.y?null:($s.x=$s.y=!0,()=>{$s.x=$s.y=!1})}function _k(e,t){const s=Ok(e),r=new AbortController,o={passive:!0,...t,signal:r.signal};return[s,o,()=>r.abort()]}function iO(e){return!(e.pointerType==="touch"||Lk())}function aO(e,t,s={}){const[r,o,i]=_k(e,s);return r.forEach(a=>{let l=!1,c=!1,u;const d=()=>{a.removeEventListener("pointerleave",g)},m=v=>{u&&(u(v),u=void 0),d()},h=v=>{l=!1,window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h),c&&(c=!1,m(v))},p=()=>{l=!0,window.addEventListener("pointerup",h,o),window.addEventListener("pointercancel",h,o)},g=v=>{if(v.pointerType!=="touch"){if(l){c=!0;return}m(v)}},x=v=>{if(!iO(v))return;c=!1;const b=t(a,v);typeof b=="function"&&(u=b,a.addEventListener("pointerleave",g,o))};a.addEventListener("pointerenter",x,o),a.addEventListener("pointerdown",p,o)}),i}const Bk=(e,t)=>t?e===t?!0:Bk(e,t.parentElement):!1,Vp=e=>e.pointerType==="mouse"?typeof e.button!="number"||e.button<=0:e.isPrimary!==!1,lO=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);function cO(e){return lO.has(e.tagName)||e.isContentEditable===!0}const dO=new Set(["INPUT","SELECT","TEXTAREA"]);function uO(e){return dO.has(e.tagName)||e.isContentEditable===!0}const Sc=new WeakSet;function C0(e){return t=>{t.key==="Enter"&&e(t)}}function Ju(e,t){e.dispatchEvent(new PointerEvent("pointer"+t,{isPrimary:!0,bubbles:!0}))}const fO=(e,t)=>{const s=e.currentTarget;if(!s)return;const r=C0(()=>{if(Sc.has(s))return;Ju(s,"down");const o=C0(()=>{Ju(s,"up")}),i=()=>Ju(s,"cancel");s.addEventListener("keyup",o,t),s.addEventListener("blur",i,t)});s.addEventListener("keydown",r,t),s.addEventListener("blur",()=>s.removeEventListener("keydown",r),t)};function I0(e){return Vp(e)&&!Lk()}const T0=new WeakSet;function mO(e,t,s={}){const[r,o,i]=_k(e,s),a=l=>{const c=l.currentTarget;if(!I0(l)||T0.has(l))return;Sc.add(c),s.stopPropagation&&T0.add(l);const u=t(c,l),d={...o,capture:!0},m=(g,x)=>{window.removeEventListener("pointerup",h,d),window.removeEventListener("pointercancel",p,d),Sc.has(c)&&Sc.delete(c),I0(g)&&typeof u=="function"&&u(g,{success:x})},h=g=>{m(g,c===window||c===document||s.useGlobalTarget||Bk(c,g.target))},p=g=>{m(g,!1)};window.addEventListener("pointerup",h,d),window.addEventListener("pointercancel",p,d)};return r.forEach(l=>{(s.useGlobalTarget?window:l).addEventListener("pointerdown",a,o),Nc(l)&&(l.addEventListener("focus",u=>fO(u,o)),!cO(l)&&!l.hasAttribute("tabindex")&&(l.tabIndex=0))}),i}function Hp(e){return V1(e)&&"ownerSVGElement"in e}const Cc=new WeakMap;let Ic;const Fk=(e,t,s)=>(r,o)=>o&&o[0]?o[0][e+"Size"]:Hp(r)&&"getBBox"in r?r.getBBox()[t]:r[s],hO=Fk("inline","width","offsetWidth"),pO=Fk("block","height","offsetHeight");function xO({target:e,borderBoxSize:t}){Cc.get(e)?.forEach(s=>{s(e,{get width(){return hO(e,t)},get height(){return pO(e,t)}})})}function gO(e){e.forEach(xO)}function vO(){typeof ResizeObserver>"u"||(Ic=new ResizeObserver(gO))}function bO(e,t){Ic||vO();const s=Ok(e);return s.forEach(r=>{let o=Cc.get(r);o||(o=new Set,Cc.set(r,o)),o.add(t),Ic?.observe(r)}),()=>{s.forEach(r=>{const o=Cc.get(r);o?.delete(t),o?.size||Ic?.unobserve(r)})}}const Tc=new Set;let oi;function yO(){oi=()=>{const e={get width(){return window.innerWidth},get height(){return window.innerHeight}};Tc.forEach(t=>t(e))},window.addEventListener("resize",oi)}function wO(e){return Tc.add(e),oi||yO(),()=>{Tc.delete(e),!Tc.size&&typeof oi=="function"&&(window.removeEventListener("resize",oi),oi=void 0)}}function A0(e,t){return typeof e=="function"?wO(e):bO(e,t)}function jO(e){return Hp(e)&&e.tagName==="svg"}const kO=[...Mk,Ln,Ws],NO=e=>kO.find(Rk(e)),E0=()=>({translate:0,scale:1,origin:0,originPoint:0}),ii=()=>({x:E0(),y:E0()}),R0=()=>({min:0,max:0}),zn=()=>({x:R0(),y:R0()}),SO=new WeakMap;function ou(e){return e!==null&&typeof e=="object"&&typeof e.start=="function"}function Wa(e){return typeof e=="string"||Array.isArray(e)}const Wp=["animate","whileInView","whileFocus","whileHover","whileTap","whileDrag","exit"],Up=["initial",...Wp];function iu(e){return ou(e.animate)||Up.some(t=>Wa(e[t]))}function zk(e){return!!(iu(e)||e.variants)}function CO(e,t,s){for(const r in t){const o=t[r],i=s[r];if(es(o))e.addValue(r,o);else if(es(i))e.addValue(r,Ci(o,{owner:e}));else if(i!==o)if(e.hasValue(r)){const a=e.getValue(r);a.liveStyle===!0?a.jump(o):a.hasAnimated||a.set(o)}else{const a=e.getStaticValue(r);e.addValue(r,Ci(a!==void 0?a:o,{owner:e}))}}for(const r in s)t[r]===void 0&&e.removeValue(r);return t}const ud={current:null},qp={current:!1},IO=typeof window<"u";function $k(){if(qp.current=!0,!!IO)if(window.matchMedia){const e=window.matchMedia("(prefers-reduced-motion)"),t=()=>ud.current=e.matches;e.addEventListener("change",t),t()}else ud.current=!1}const M0=["AnimationStart","AnimationComplete","Update","BeforeLayoutMeasure","LayoutMeasure","LayoutAnimationStart","LayoutAnimationComplete"];let fd={};function Vk(e){fd=e}function TO(){return fd}class AO{scrapeMotionValuesFromProps(t,s,r){return{}}constructor({parent:t,props:s,presenceContext:r,reducedMotionConfig:o,skipAnimations:i,blockInitialAnimation:a,visualState:l},c={}){this.current=null,this.children=new Set,this.isVariantNode=!1,this.isControllingVariants=!1,this.shouldReduceMotion=null,this.shouldSkipAnimations=!1,this.values=new Map,this.KeyframeResolver=Op,this.features={},this.valueSubscriptions=new Map,this.prevMotionValues={},this.hasBeenMounted=!1,this.events={},this.propEventSubscriptions={},this.notifyUpdate=()=>this.notify("Update",this.latestValues),this.render=()=>{this.current&&(this.triggerBuild(),this.renderInstance(this.current,this.renderState,this.props.style,this.projection))},this.renderScheduledAt=0,this.scheduleRender=()=>{const p=as.now();this.renderScheduledAt<p&&(this.renderScheduledAt=p,hn.render(this.render,!1,!0))};const{latestValues:u,renderState:d}=l;this.latestValues=u,this.baseTarget={...u},this.initialValues=s.initial?{...u}:{},this.renderState=d,this.parent=t,this.props=s,this.presenceContext=r,this.depth=t?t.depth+1:0,this.reducedMotionConfig=o,this.skipAnimationsConfig=i,this.options=c,this.blockInitialAnimation=!!a,this.isControllingVariants=iu(s),this.isVariantNode=zk(s),this.isVariantNode&&(this.variantChildren=new Set),this.manuallyAnimateOnMount=!!(t&&t.current);const{willChange:m,...h}=this.scrapeMotionValuesFromProps(s,{},this);for(const p in h){const g=h[p];u[p]!==void 0&&es(g)&&g.set(u[p])}}mount(t){if(this.hasBeenMounted)for(const s in this.initialValues)this.values.get(s)?.jump(this.initialValues[s]),this.latestValues[s]=this.initialValues[s];this.current=t,SO.set(t,this),this.projection&&!this.projection.instance&&this.projection.mount(t),this.parent&&this.isVariantNode&&!this.isControllingVariants&&(this.removeFromVariantTree=this.parent.addVariantChild(this)),this.values.forEach((s,r)=>this.bindToMotionValue(r,s)),this.reducedMotionConfig==="never"?this.shouldReduceMotion=!1:this.reducedMotionConfig==="always"?this.shouldReduceMotion=!0:(qp.current||$k(),this.shouldReduceMotion=ud.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,this.parent?.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){this.projection&&this.projection.unmount(),to(this.notifyUpdate),to(this.render),this.valueSubscriptions.forEach(t=>t()),this.valueSubscriptions.clear(),this.removeFromVariantTree&&this.removeFromVariantTree(),this.parent?.removeChild(this);for(const t in this.events)this.events[t].clear();for(const t in this.features){const s=this.features[t];s&&(s.unmount(),s.isMounted=!1)}this.current=null}addChild(t){this.children.add(t),this.enteringChildren??(this.enteringChildren=new Set),this.enteringChildren.add(t)}removeChild(t){this.children.delete(t),this.enteringChildren&&this.enteringChildren.delete(t)}bindToMotionValue(t,s){if(this.valueSubscriptions.has(t)&&this.valueSubscriptions.get(t)(),s.accelerate&&kk.has(t)&&this.current instanceof HTMLElement){const{factory:a,keyframes:l,times:c,ease:u,duration:d}=s.accelerate,m=new wk({element:this.current,name:t,keyframes:l,times:c,ease:u,duration:xs(d)}),h=a(m);this.valueSubscriptions.set(t,()=>{h(),m.cancel()});return}const r=_i.has(t);r&&this.onBindTransform&&this.onBindTransform();const o=s.on("change",a=>{this.latestValues[t]=a,this.props.onUpdate&&hn.preRender(this.notifyUpdate),r&&this.projection&&(this.projection.isTransformDirty=!0),this.scheduleRender()});let i;typeof window<"u"&&window.MotionCheckAppearSync&&(i=window.MotionCheckAppearSync(this,t,s)),this.valueSubscriptions.set(t,()=>{o(),i&&i()})}sortNodePosition(t){return!this.current||!this.sortInstanceNodePosition||this.type!==t.type?0:this.sortInstanceNodePosition(this.current,t.current)}updateFeatures(){let t="animation";for(t in fd){const s=fd[t];if(!s)continue;const{isEnabled:r,Feature:o}=s;if(!this.features[t]&&o&&r(this.props)&&(this.features[t]=new o(this)),this.features[t]){const i=this.features[t];i.isMounted?i.update():(i.mount(),i.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):zn()}getStaticValue(t){return this.latestValues[t]}setStaticValue(t,s){this.latestValues[t]=s}update(t,s){(t.transformTemplate||this.props.transformTemplate)&&this.scheduleRender(),this.prevProps=this.props,this.props=t,this.prevPresenceContext=this.presenceContext,this.presenceContext=s;for(let r=0;r<M0.length;r++){const o=M0[r];this.propEventSubscriptions[o]&&(this.propEventSubscriptions[o](),delete this.propEventSubscriptions[o]);const i="on"+o,a=t[i];a&&(this.propEventSubscriptions[o]=this.on(o,a))}this.prevMotionValues=CO(this,this.scrapeMotionValuesFromProps(t,this.prevProps||{},this),this.prevMotionValues),this.handleChildMotionValue&&this.handleChildMotionValue()}getProps(){return this.props}getVariant(t){return this.props.variants?this.props.variants[t]:void 0}getDefaultTransition(){return this.props.transition}getTransformPagePoint(){return this.props.transformPagePoint}getClosestVariantNode(){return this.isVariantNode?this:this.parent?this.parent.getClosestVariantNode():void 0}addVariantChild(t){const s=this.getClosestVariantNode();if(s)return s.variantChildren&&s.variantChildren.add(t),()=>s.variantChildren.delete(t)}addValue(t,s){const r=this.values.get(t);s!==r&&(r&&this.removeValue(t),this.bindToMotionValue(t,s),this.values.set(t,s),this.latestValues[t]=s.get())}removeValue(t){this.values.delete(t);const s=this.valueSubscriptions.get(t);s&&(s(),this.valueSubscriptions.delete(t)),delete this.latestValues[t],this.removeValueFromRenderState(t,this.renderState)}hasValue(t){return this.values.has(t)}getValue(t,s){if(this.props.values&&this.props.values[t])return this.props.values[t];let r=this.values.get(t);return r===void 0&&s!==void 0&&(r=Ci(s===null?void 0:s,{owner:this}),this.addValue(t,r)),r}readValue(t,s){let r=this.latestValues[t]!==void 0||!this.current?this.latestValues[t]:this.getBaseTargetFromProps(this.props,t)??this.readValueFromInstance(this.current,t,this.options);return r!=null&&(typeof r=="string"&&($1(r)||H1(r))?r=parseFloat(r):!NO(r)&&Ws.test(s)&&(r=Dk(t,s)),this.setBaseTarget(t,es(r)?r.get():r)),es(r)?r.get():r}setBaseTarget(t,s){this.baseTarget[t]=s}getBaseTarget(t){const{initial:s}=this.props;let r;if(typeof s=="string"||typeof s=="object"){const i=Bp(this.props,s,this.presenceContext?.custom);i&&(r=i[t])}if(s&&r!==void 0)return r;const o=this.getBaseTargetFromProps(this.props,t);return o!==void 0&&!es(o)?o:this.initialValues[t]!==void 0&&r===void 0?void 0:this.baseTarget[t]}on(t,s){return this.events[t]||(this.events[t]=new Cp),this.events[t].add(s)}notify(t,...s){this.events[t]&&this.events[t].notify(...s)}scheduleRenderMicrotask(){$p.render(this.render)}}class Hk extends AO{constructor(){super(...arguments),this.KeyframeResolver=rO}sortInstanceNodePosition(t,s){return t.compareDocumentPosition(s)&2?1:-1}getBaseTargetFromProps(t,s){const r=t.style;return r?r[s]:void 0}removeValueFromRenderState(t,{vars:s,style:r}){delete s[t],delete r[t]}handleChildMotionValue(){this.childSubscription&&(this.childSubscription(),delete this.childSubscription);const{children:t}=this.props;es(t)&&(this.childSubscription=t.on("change",s=>{this.current&&(this.current.textContent=`${s}`)}))}}class io{constructor(t){this.isMounted=!1,this.node=t}update(){}}function Wk({top:e,left:t,right:s,bottom:r}){return{x:{min:t,max:s},y:{min:e,max:r}}}function EO({x:e,y:t}){return{top:t.min,right:e.max,bottom:t.max,left:e.min}}function RO(e,t){if(!t)return e;const s=t({x:e.left,y:e.top}),r=t({x:e.right,y:e.bottom});return{top:s.y,left:s.x,bottom:r.y,right:r.x}}function Zu(e){return e===void 0||e===1}function Pm({scale:e,scaleX:t,scaleY:s}){return!Zu(e)||!Zu(t)||!Zu(s)}function ko(e){return Pm(e)||Uk(e)||e.z||e.rotate||e.rotateX||e.rotateY||e.skewX||e.skewY}function Uk(e){return P0(e.x)||P0(e.y)}function P0(e){return e&&e!=="0%"}function md(e,t,s){const r=e-s,o=t*r;return s+o}function D0(e,t,s,r,o){return o!==void 0&&(e=md(e,o,r)),md(e,s,r)+t}function Dm(e,t=0,s=1,r,o){e.min=D0(e.min,t,s,r,o),e.max=D0(e.max,t,s,r,o)}function qk(e,{x:t,y:s}){Dm(e.x,t.translate,t.scale,t.originPoint),Dm(e.y,s.translate,s.scale,s.originPoint)}const O0=.999999999999,L0=1.0000000000001;function MO(e,t,s,r=!1){const o=s.length;if(!o)return;t.x=t.y=1;let i,a;for(let l=0;l<o;l++){i=s[l],a=i.projectionDelta;const{visualElement:c}=i.options;c&&c.props.style&&c.props.style.display==="contents"||(r&&i.options.layoutScroll&&i.scroll&&i!==i.root&&(tr(e.x,-i.scroll.offset.x),tr(e.y,-i.scroll.offset.y)),a&&(t.x*=a.x.scale,t.y*=a.y.scale,qk(e,a)),r&&ko(i.latestValues)&&Ac(e,i.latestValues,i.layout?.layoutBox))}t.x<L0&&t.x>O0&&(t.x=1),t.y<L0&&t.y>O0&&(t.y=1)}function tr(e,t){e.min+=t,e.max+=t}function _0(e,t,s,r,o=.5){const i=mn(e.min,e.max,o);Dm(e,t,s,i,r)}function B0(e,t){return typeof e=="string"?parseFloat(e)/100*(t.max-t.min):e}function Ac(e,t,s){const r=s??e;_0(e.x,B0(t.x,r.x),t.scaleX,t.scale,t.originX),_0(e.y,B0(t.y,r.y),t.scaleY,t.scale,t.originY)}function Gk(e,t){return Wk(RO(e.getBoundingClientRect(),t))}function PO(e,t,s){const r=Gk(e,s),{scroll:o}=t;return o&&(tr(r.x,o.offset.x),tr(r.y,o.offset.y)),r}const DO={x:"translateX",y:"translateY",z:"translateZ",transformPerspective:"perspective"},OO=Li.length;function LO(e,t,s){let r="",o=!0;for(let a=0;a<OO;a++){const l=Li[a],c=e[l];if(c===void 0)continue;let u=!0;if(typeof c=="number")u=c===(l.startsWith("scale")?1:0);else{const d=parseFloat(c);u=l.startsWith("scale")?d===1:d===0}if(!u||s){const d=Mm(c,dd[l]);if(!u){o=!1;const m=DO[l]||l;r+=`${m}(${d}) `}s&&(t[l]=d)}}const i=e.pathRotation;return i&&(o=!1,r+=`rotate(${Mm(i,dd.pathRotation)}) `),r=r.trim(),s?r=s(t,o?"":r):o&&(r="none"),r}function Gp(e,t,s){const{style:r,vars:o,transformOrigin:i}=e;let a=!1,l=!1;for(const c in t){const u=t[c];if(_i.has(c)){a=!0;continue}else if(rk(c)){o[c]=u;continue}else{const d=Mm(u,dd[c]);c.startsWith("origin")?(l=!0,i[c]=d):r[c]=d}}if(t.transform||(a||s?r.transform=LO(t,e.transform,s):r.transform&&(r.transform="none")),l){const{originX:c="50%",originY:u="50%",originZ:d=0}=i;r.transformOrigin=`${c} ${u} ${d}`}}function Kk(e,{style:t,vars:s},r,o){const i=e.style;let a;for(a in t)i[a]=t[a];o?.applyProjectionStyles(i,r);for(a in s)i.setProperty(a,s[a])}function F0(e,t){return t.max===t.min?0:e/(t.max-t.min)*100}const Yi={correct:(e,t)=>{if(!t.target)return e;if(typeof e=="string")if(ct.test(e))e=parseFloat(e);else return e;const s=F0(e,t.target.x),r=F0(e,t.target.y);return`${s}% ${r}%`}},_O={correct:(e,{treeScale:t,projectionDelta:s})=>{const r=e,o=Ws.parse(e);if(o.length>5)return r;const i=Ws.createTransformer(e),a=typeof o[0]!="number"?1:0,l=s.x.scale*t.x,c=s.y.scale*t.y;o[0+a]/=l,o[1+a]/=c;const u=mn(l,c,.5);return typeof o[2+a]=="number"&&(o[2+a]/=u),typeof o[3+a]=="number"&&(o[3+a]/=u),i(o)}},Om={borderRadius:{...Yi,applyTo:[...zp]},borderTopLeftRadius:Yi,borderTopRightRadius:Yi,borderBottomLeftRadius:Yi,borderBottomRightRadius:Yi,boxShadow:_O};function Yk(e,{layout:t,layoutId:s}){return _i.has(e)||e.startsWith("origin")||(t||s!==void 0)&&(!!Om[e]||e==="opacity")}function Kp(e,t,s){const r=e.style,o=t?.style,i={};if(!r)return i;for(const a in r)(es(r[a])||o&&es(o[a])||Yk(a,e)||s?.getValue(a)?.liveStyle!==void 0)&&(i[a]=r[a]);return i}function BO(e){return window.getComputedStyle(e)}class FO extends Hk{constructor(){super(...arguments),this.type="html",this.renderInstance=Kk}mount(t){su(!!t.style),super.mount(t)}readValueFromInstance(t,s){if(_i.has(s))return this.projection?.isProjecting?wm(s):o6(t,s);{const r=BO(t),o=(rk(s)?r.getPropertyValue(s):r[s])||0;return typeof o=="string"?o.trim():o}}measureInstanceViewportBox(t,{transformPagePoint:s}){return Gk(t,s)}build(t,s,r){Gp(t,s,r.transformTemplate)}scrapeMotionValuesFromProps(t,s,r){return Kp(t,s,r)}}const zO={offset:"stroke-dashoffset",array:"stroke-dasharray"},$O={offset:"strokeDashoffset",array:"strokeDasharray"};function VO(e,t,s=1,r=0,o=!0){e.pathLength=1;const i=o?zO:$O;e[i.offset]=`${-r}`,e[i.array]=`${t} ${s}`}const Xk=["transform","opacity","offsetDistance","offsetPath","offsetRotate","offsetAnchor"];function Qk(e,{attrX:t,attrY:s,attrScale:r,pathLength:o,pathSpacing:i=1,pathOffset:a=0,...l},c,u,d){if(Gp(e,l,u),c){e.style.viewBox&&(e.attrs.viewBox=e.style.viewBox);return}e.attrs=e.style,e.style={};const{attrs:m,style:h}=e;for(const p of Xk)m[p]!==void 0&&(h[p]=m[p],delete m[p]);(h.transform||m.transformOrigin)&&(h.transformOrigin=m.transformOrigin??"50% 50%",delete m.transformOrigin),h.transform&&(h.transformBox=d?.transformBox??"fill-box",delete m.transformBox),t!==void 0&&(m.x=t),s!==void 0&&(m.y=s),r!==void 0&&(m.scale=r),o!==void 0&&VO(m,o,i,a,!1)}const Jk=new Set(["baseFrequency","diffuseConstant","kernelMatrix","kernelUnitLength","keySplines","keyTimes","limitingConeAngle","markerHeight","markerWidth","numOctaves","targetX","targetY","surfaceScale","specularConstant","specularExponent","stdDeviation","tableValues","viewBox","gradientTransform","pathLength","startOffset","textLength","lengthAdjust"]),Zk=e=>typeof e=="string"&&e.toLowerCase()==="svg";function HO(e,t,s,r){Kk(e,t,void 0,r);for(const o in t.attrs)e.setAttribute(Jk.has(o)?o:Fp(o),t.attrs[o])}function eN(e,t,s){const r=Kp(e,t,s);for(const o in e)if(es(e[o])||es(t[o])){const i=Li.indexOf(o)!==-1?"attr"+o.charAt(0).toUpperCase()+o.substring(1):o;r[i]=e[o]}return r}class WO extends Hk{constructor(){super(...arguments),this.type="svg",this.isSVGTag=!1,this.measureInstanceViewportBox=zn}getBaseTargetFromProps(t,s){return t[s]}readValueFromInstance(t,s){if(_i.has(s)){const r=Pk(s);return r&&r.default||0}if(Xk.includes(s)){const o=getComputedStyle(t)[s];if(typeof o=="string"&&o)return o.trim()}return s=Jk.has(s)?s:Fp(s),t.getAttribute(s)}scrapeMotionValuesFromProps(t,s,r){return eN(t,s,r)}build(t,s,r){Qk(t,s,this.isSVGTag,r.transformTemplate,r.style)}renderInstance(t,s,r,o){HO(t,s,r,o)}mount(t){this.isSVGTag=Zk(t.tagName),super.mount(t)}}const UO=Up.length;function tN(e){if(!e)return;if(!e.isControllingVariants){const s=e.parent?tN(e.parent)||{}:{};return e.props.initial!==void 0&&(s.initial=e.props.initial),s}const t={};for(let s=0;s<UO;s++){const r=Up[s],o=e.props[r];(Wa(o)||o===!1)&&(t[r]=o)}return t}function nN(e,t){if(!Array.isArray(t))return!1;const s=t.length;if(s!==e.length)return!1;for(let r=0;r<s;r++)if(t[r]!==e[r])return!1;return!0}const qO=[...Wp].reverse(),GO=Wp.length;function KO(e){return t=>Promise.all(t.map(({animation:s,options:r})=>G6(e,s,r)))}function YO(e){let t=KO(e),s=z0(),r=!0,o=!1;const i=u=>(d,m)=>{const h=Mo(e,m,u==="exit"?e.presenceContext?.custom:void 0);if(h){const{transition:p,transitionEnd:g,...x}=h;d={...d,...x,...g}}return d};function a(u){t=u(e)}function l(u){const{props:d}=e,m=tN(e.parent)||{},h=[],p=new Set;let g={},x=1/0;for(let b=0;b<GO;b++){const w=qO[b],j=s[w],T=d[w]!==void 0?d[w]:m[w],N=Wa(T),S=w===u?j.isActive:null;S===!1&&(x=b);let I=T===m[w]&&T!==d[w]&&N;if(I&&(r||o)&&e.manuallyAnimateOnMount&&(I=!1),j.protectedKeys={...g},!j.isActive&&S===null||!T&&!j.prevProp||ou(T)||typeof T=="boolean")continue;if(w==="exit"&&j.isActive&&S!==!0){j.prevResolvedValues&&(g={...g,...j.prevResolvedValues});continue}const k=XO(j.prevProp,T);let L=k||w===u&&j.isActive&&!I&&N||b>x&&N,F=!1;const A=Array.isArray(T)?T:[T];let M=A.reduce(i(w),{});S===!1&&(M={});const{prevResolvedValues:R={}}=j,$={...R,...M},U=V=>{L=!0,p.has(V)&&(F=!0,p.delete(V)),j.needsAnimating[V]=!0;const se=e.getValue(V);se&&(se.liveStyle=!1)};for(const V in $){const se=M[V],Ce=R[V];if(g.hasOwnProperty(V))continue;let de=!1;Im(se)&&Im(Ce)?de=!nN(se,Ce)||k:de=se!==Ce,de?se!=null?U(V):p.add(V):se!==void 0&&p.has(V)?U(V):j.protectedKeys[V]=!0}j.prevProp=T,j.prevResolvedValues=M,j.isActive&&(g={...g,...M}),(r||o)&&e.blockInitialAnimation&&(L=!1);const q=I&&k;L&&(!q||F)&&h.push(...A.map(V=>{const se={type:w};if(typeof V=="string"&&(r||o)&&!q&&e.manuallyAnimateOnMount&&e.parent){const{parent:Ce}=e,de=Mo(Ce,V);if(Ce.enteringChildren&&de){const{delayChildren:re}=de.transition||{};se.delay=Nk(Ce.enteringChildren,e,re)}}return{animation:V,options:se}}))}if(p.size){const b={};if(typeof d.initial!="boolean"){const w=Mo(e,Array.isArray(d.initial)?d.initial[0]:d.initial);w&&w.transition&&(b.transition=w.transition)}p.forEach(w=>{const j=e.getBaseTarget(w),T=e.getValue(w);T&&(T.liveStyle=!0),b[w]=j??null}),h.push({animation:b})}let v=!!h.length;return r&&(d.initial===!1||d.initial===d.animate)&&!e.manuallyAnimateOnMount&&(v=!1),r=!1,o=!1,v?t(h):Promise.resolve()}function c(u,d){if(s[u].isActive===d)return Promise.resolve();e.variantChildren?.forEach(h=>h.animationState?.setActive(u,d)),s[u].isActive=d;const m=l(u);for(const h in s)s[h].protectedKeys={};return m}return{animateChanges:l,setActive:c,setAnimateFunction:a,getState:()=>s,reset:()=>{s=z0(),o=!0}}}function XO(e,t){return typeof t=="string"?t!==e:Array.isArray(t)?!nN(t,e):!1}function go(e=!1){return{isActive:e,protectedKeys:{},needsAnimating:{},prevResolvedValues:{}}}function z0(){return{animate:go(!0),whileInView:go(),whileHover:go(),whileTap:go(),whileDrag:go(),whileFocus:go(),exit:go()}}function Lm(e,t){e.min=t.min,e.max=t.max}function Fs(e,t){Lm(e.x,t.x),Lm(e.y,t.y)}function $0(e,t){e.translate=t.translate,e.scale=t.scale,e.originPoint=t.originPoint,e.origin=t.origin}const sN=1e-4,QO=1-sN,JO=1+sN,rN=.01,ZO=0-rN,eL=0+rN;function ls(e){return e.max-e.min}function tL(e,t,s){return Math.abs(e-t)<=s}function V0(e,t,s,r=.5){e.origin=r,e.originPoint=mn(t.min,t.max,e.origin),e.scale=ls(s)/ls(t),e.translate=mn(s.min,s.max,e.origin)-e.originPoint,(e.scale>=QO&&e.scale<=JO||isNaN(e.scale))&&(e.scale=1),(e.translate>=ZO&&e.translate<=eL||isNaN(e.translate))&&(e.translate=0)}function ba(e,t,s,r){V0(e.x,t.x,s.x,r?r.originX:void 0),V0(e.y,t.y,s.y,r?r.originY:void 0)}function H0(e,t,s,r=0){const o=r?mn(s.min,s.max,r):s.min;e.min=o+t.min,e.max=e.min+ls(t)}function nL(e,t,s,r){H0(e.x,t.x,s.x,r?.x),H0(e.y,t.y,s.y,r?.y)}function W0(e,t,s,r=0){const o=r?mn(s.min,s.max,r):s.min;e.min=t.min-o,e.max=e.min+ls(t)}function hd(e,t,s,r){W0(e.x,t.x,s.x,r?.x),W0(e.y,t.y,s.y,r?.y)}function U0(e,t,s,r,o){return e-=t,e=md(e,1/s,r),o!==void 0&&(e=md(e,1/o,r)),e}function sL(e,t=0,s=1,r=.5,o,i=e,a=e){if(ar.test(t)&&(t=parseFloat(t),t=mn(a.min,a.max,t/100)-a.min),typeof t!="number")return;let l=mn(i.min,i.max,r);e===i&&(l-=t),e.min=U0(e.min,t,s,l,o),e.max=U0(e.max,t,s,l,o)}function q0(e,t,[s,r,o],i,a){sL(e,t[s],t[r],t[o],t.scale,i,a)}const rL=["x","scaleX","originX"],oL=["y","scaleY","originY"];function G0(e,t,s,r){q0(e.x,t,rL,s?s.x:void 0,r?r.x:void 0),q0(e.y,t,oL,s?s.y:void 0,r?r.y:void 0)}function K0(e){return e.translate===0&&e.scale===1}function oN(e){return K0(e.x)&&K0(e.y)}function Y0(e,t){return e.min===t.min&&e.max===t.max}function iL(e,t){return Y0(e.x,t.x)&&Y0(e.y,t.y)}function X0(e,t){return Math.round(e.min)===Math.round(t.min)&&Math.round(e.max)===Math.round(t.max)}function iN(e,t){return X0(e.x,t.x)&&X0(e.y,t.y)}function Q0(e){return ls(e.x)/ls(e.y)}function J0(e,t){return e.translate===t.translate&&e.scale===t.scale&&e.originPoint===t.originPoint}function Zs(e){return[e("x"),e("y")]}function aL(e,t,s){let r="";const o=e.x.translate/t.x,i=e.y.translate/t.y,a=s?.z||0;if((o||i||a)&&(r=`translate3d(${o}px, ${i}px, ${a}px) `),(t.x!==1||t.y!==1)&&(r+=`scale(${1/t.x}, ${1/t.y}) `),s){const{transformPerspective:u,rotate:d,pathRotation:m,rotateX:h,rotateY:p,skewX:g,skewY:x}=s;u&&(r=`perspective(${u}px) ${r}`),d&&(r+=`rotate(${d}deg) `),m&&(r+=`rotate(${m}deg) `),h&&(r+=`rotateX(${h}deg) `),p&&(r+=`rotateY(${p}deg) `),g&&(r+=`skewX(${g}deg) `),x&&(r+=`skewY(${x}deg) `)}const l=e.x.scale*t.x,c=e.y.scale*t.y;return(l!==1||c!==1)&&(r+=`scale(${l}, ${c})`),r||"none"}const lL=zp.length,Z0=e=>typeof e=="string"?parseFloat(e):e,ev=e=>typeof e=="number"||ct.test(e);function cL(e,t,s,r,o,i){o?(e.opacity=mn(0,s.opacity??1,dL(r)),e.opacityExit=mn(t.opacity??1,0,uL(r))):i&&(e.opacity=mn(t.opacity??1,s.opacity??1,r));for(let a=0;a<lL;a++){const l=zp[a];let c=tv(t,l),u=tv(s,l);if(c===void 0&&u===void 0)continue;c||(c=0),u||(u=0),c===0||u===0||ev(c)===ev(u)?(e[l]=Math.max(mn(Z0(c),Z0(u),r),0),(ar.test(u)||ar.test(c))&&(e[l]+="%")):e[l]=u}(t.rotate||s.rotate)&&(e.rotate=mn(t.rotate||0,s.rotate||0,r))}function tv(e,t){return e[t]!==void 0?e[t]:e.borderRadius}const dL=aN(0,.5,J1),uL=aN(.5,.95,Ls);function aN(e,t,s){return r=>r<e?0:r>t?1:s(Va(e,t,r))}function fL(e,t,s){const r=es(e)?e:Ci(e);return r.start(_p("",r,t,s)),r.animation}function Ua(e,t,s,r={passive:!0}){return e.addEventListener(t,s,r),()=>e.removeEventListener(t,s,r)}const mL=(e,t)=>e.depth-t.depth;class hL{constructor(){this.children=[],this.isDirty=!1}add(t){Sp(this.children,t),this.isDirty=!0}remove(t){od(this.children,t),this.isDirty=!0}forEach(t){this.isDirty&&this.children.sort(mL),this.isDirty=!1,this.children.forEach(t)}}function pL(e,t){const s=as.now(),r=({timestamp:o})=>{const i=o-s;i>=t&&(to(r),e(i-t))};return hn.setup(r,!0),()=>to(r)}function Ec(e){return es(e)?e.get():e}class xL{constructor(){this.members=[]}add(t){Sp(this.members,t);for(let s=this.members.length-1;s>=0;s--){const r=this.members[s];if(r===t||r===this.lead||r===this.prevLead)continue;const o=r.instance;(!o||o.isConnected===!1)&&!r.snapshot&&(od(this.members,r),r.unmount())}t.scheduleRender()}remove(t){if(od(this.members,t),t===this.prevLead&&(this.prevLead=void 0),t===this.lead){const s=this.members[this.members.length-1];s&&this.promote(s)}}relegate(t){for(let s=this.members.indexOf(t)-1;s>=0;s--){const r=this.members[s];if(r.isPresent!==!1&&r.instance?.isConnected!==!1)return this.promote(r),!0}return!1}promote(t,s){const r=this.lead;if(t!==r&&(this.prevLead=r,this.lead=t,t.show(),r)){r.updateSnapshot(),t.scheduleRender();const{layoutDependency:o}=r.options,{layoutDependency:i}=t.options;(o===void 0||o!==i)&&(t.resumeFrom=r,s&&(r.preserveOpacity=!0),r.snapshot&&(t.snapshot=r.snapshot,t.snapshot.latestValues=r.animationValues||r.latestValues),t.root?.isUpdating&&(t.isLayoutDirty=!0)),t.options.crossfade===!1&&r.hide()}}exitAnimationComplete(){this.members.forEach(t=>{t.options.onExitComplete?.(),t.resumingFrom?.options.onExitComplete?.()})}scheduleRender(){this.members.forEach(t=>t.instance&&t.scheduleRender(!1))}removeLeadSnapshot(){this.lead?.snapshot&&(this.lead.snapshot=void 0)}}const Rc={hasAnimatedSinceResize:!0,hasEverUpdated:!1},ef=["","X","Y","Z"],gL=1e3;let vL=0;function tf(e,t,s,r){const{latestValues:o}=t;o[e]&&(s[e]=o[e],t.setStaticValue(e,0),r&&(r[e]=0))}function lN(e){if(e.hasCheckedOptimisedAppear=!0,e.root===e)return;const{visualElement:t}=e.options;if(!t)return;const s=Ak(t);if(window.MotionHasOptimisedAnimation(s,"transform")){const{layout:o,layoutId:i}=e.options;window.MotionCancelOptimisedAnimation(s,"transform",hn,!(o||i))}const{parent:r}=e;r&&!r.hasCheckedOptimisedAppear&&lN(r)}function cN({attachResizeListener:e,defaultParent:t,measureScroll:s,checkIsScrollRoot:r,resetTransform:o}){return class{constructor(a={},l=t?.()){this.id=vL++,this.animationId=0,this.animationCommitId=0,this.children=new Set,this.options={},this.isTreeAnimating=!1,this.isAnimationBlocked=!1,this.isLayoutDirty=!1,this.isProjectionDirty=!1,this.isSharedProjectionDirty=!1,this.isTransformDirty=!1,this.updateManuallyBlocked=!1,this.updateBlockedByResize=!1,this.isUpdating=!1,this.isSVG=!1,this.needsReset=!1,this.shouldResetTransform=!1,this.hasCheckedOptimisedAppear=!1,this.treeScale={x:1,y:1},this.eventHandlers=new Map,this.hasTreeAnimated=!1,this.layoutVersion=0,this.updateScheduled=!1,this.scheduleUpdate=()=>this.update(),this.projectionUpdateScheduled=!1,this.checkUpdateFailed=()=>{this.isUpdating&&(this.isUpdating=!1,this.clearAllSnapshots())},this.updateProjection=()=>{this.projectionUpdateScheduled=!1,this.nodes.forEach(wL),this.nodes.forEach(IL),this.nodes.forEach(TL),this.nodes.forEach(jL)},this.resolvedRelativeTargetAt=0,this.linkedParentVersion=0,this.hasProjected=!1,this.isVisible=!0,this.animationProgress=0,this.sharedNodes=new Map,this.latestValues=a,this.root=l?l.root||l:this,this.path=l?[...l.path,l]:[],this.parent=l,this.depth=l?l.depth+1:0;for(let c=0;c<this.path.length;c++)this.path[c].shouldResetTransform=!0;this.root===this&&(this.nodes=new hL)}addEventListener(a,l){return this.eventHandlers.has(a)||this.eventHandlers.set(a,new Cp),this.eventHandlers.get(a).add(l)}notifyListeners(a,...l){const c=this.eventHandlers.get(a);c&&c.notify(...l)}hasListeners(a){return this.eventHandlers.has(a)}mount(a){if(this.instance)return;this.isSVG=Hp(a)&&!jO(a),this.instance=a;const{layoutId:l,layout:c,visualElement:u}=this.options;if(u&&!u.current&&u.mount(a),this.root.nodes.add(this),this.parent&&this.parent.children.add(this),this.root.hasTreeAnimated&&(c||l)&&(this.isLayoutDirty=!0),e){let d,m=0;const h=()=>this.root.updateBlockedByResize=!1;hn.read(()=>{m=window.innerWidth}),e(a,()=>{const p=window.innerWidth;p!==m&&(m=p,this.root.updateBlockedByResize=!0,d&&d(),d=pL(h,250),Rc.hasAnimatedSinceResize&&(Rc.hasAnimatedSinceResize=!1,this.nodes.forEach(rv)))})}l&&this.root.registerSharedNode(l,this),this.options.animate!==!1&&u&&(l||c)&&this.addEventListener("didUpdate",({delta:d,hasLayoutChanged:m,hasRelativeLayoutChanged:h,layout:p})=>{if(this.isTreeAnimationBlocked()){this.target=void 0,this.relativeTarget=void 0;return}const g=this.options.transition||u.getDefaultTransition()||PL,{onLayoutAnimationStart:x,onLayoutAnimationComplete:v}=u.getProps(),b=!this.targetLayout||!iN(this.targetLayout,p),w=!m&&h;if(this.options.layoutRoot||this.resumeFrom||w||m&&(b||!this.currentAnimation)){this.resumeFrom&&(this.resumingFrom=this.resumeFrom,this.resumingFrom.resumingFrom=void 0);const j={...Lp(g,"layout"),onPlay:x,onComplete:v};(u.shouldReduceMotion||this.options.layoutRoot)&&(j.delay=0,j.type=!1),this.startAnimation(j),this.setAnimationOrigin(d,w,j.path)}else m||rv(this),this.isLead()&&this.options.onExitComplete&&this.options.onExitComplete();this.targetLayout=p})}unmount(){this.options.layoutId&&this.willUpdate(),this.root.nodes.remove(this);const a=this.getStack();a&&a.remove(this),this.parent&&this.parent.children.delete(this),this.instance=void 0,this.eventHandlers.clear(),to(this.updateProjection)}blockUpdate(){this.updateManuallyBlocked=!0}unblockUpdate(){this.updateManuallyBlocked=!1}isUpdateBlocked(){return this.updateManuallyBlocked||this.updateBlockedByResize}isTreeAnimationBlocked(){return this.isAnimationBlocked||this.parent&&this.parent.isTreeAnimationBlocked()||!1}startUpdate(){this.isUpdateBlocked()||(this.isUpdating=!0,this.nodes&&this.nodes.forEach(AL),this.animationId++)}getTransformTemplate(){const{visualElement:a}=this.options;return a&&a.getProps().transformTemplate}willUpdate(a=!0){if(this.root.hasTreeAnimated=!0,this.root.isUpdateBlocked()){this.options.onExitComplete&&this.options.onExitComplete();return}if(window.MotionCancelOptimisedAnimation&&!this.hasCheckedOptimisedAppear&&lN(this),!this.root.isUpdating&&this.root.startUpdate(),this.isLayoutDirty)return;this.isLayoutDirty=!0;for(let d=0;d<this.path.length;d++){const m=this.path[d];m.shouldResetTransform=!0,(typeof m.latestValues.x=="string"||typeof m.latestValues.y=="string")&&(m.isLayoutDirty=!0),m.updateScroll("snapshot"),m.options.layoutRoot&&m.willUpdate(!1)}const{layoutId:l,layout:c}=this.options;if(l===void 0&&!c)return;const u=this.getTransformTemplate();this.prevTransformTemplateValue=u?u(this.latestValues,""):void 0,this.updateSnapshot(),a&&this.notifyListeners("willUpdate")}update(){if(this.updateScheduled=!1,this.isUpdateBlocked()){const c=this.updateBlockedByResize;this.unblockUpdate(),this.updateBlockedByResize=!1,this.clearAllSnapshots(),c&&this.nodes.forEach(NL),this.nodes.forEach(nv);return}if(this.animationId<=this.animationCommitId){this.nodes.forEach(sv);return}this.animationCommitId=this.animationId,this.isUpdating?(this.isUpdating=!1,this.nodes.forEach(SL),this.nodes.forEach(CL),this.nodes.forEach(bL),this.nodes.forEach(yL)):this.nodes.forEach(sv),this.clearAllSnapshots();const l=as.now();Zn.delta=fr(0,1e3/60,l-Zn.timestamp),Zn.timestamp=l,Zn.isProcessing=!0,qu.update.process(Zn),qu.preRender.process(Zn),qu.render.process(Zn),Zn.isProcessing=!1}didUpdate(){this.updateScheduled||(this.updateScheduled=!0,$p.read(this.scheduleUpdate))}clearAllSnapshots(){this.nodes.forEach(kL),this.sharedNodes.forEach(EL)}scheduleUpdateProjection(){this.projectionUpdateScheduled||(this.projectionUpdateScheduled=!0,hn.preRender(this.updateProjection,!1,!0))}scheduleCheckAfterUnmount(){hn.postRender(()=>{this.isLayoutDirty?this.root.didUpdate():this.root.checkUpdateFailed()})}updateSnapshot(){this.snapshot||!this.instance||(this.snapshot=this.measure(),this.snapshot&&!ls(this.snapshot.measuredBox.x)&&!ls(this.snapshot.measuredBox.y)&&(this.snapshot=void 0))}updateLayout(){if(!this.instance||(this.updateScroll(),!(this.options.alwaysMeasureLayout&&this.isLead())&&!this.isLayoutDirty))return;if(this.resumeFrom&&!this.resumeFrom.instance)for(let c=0;c<this.path.length;c++)this.path[c].updateScroll();const a=this.layout;this.layout=this.measure(!1),this.layoutVersion++,this.layoutCorrected||(this.layoutCorrected=zn()),this.isLayoutDirty=!1,this.projectionDelta=void 0,this.notifyListeners("measure",this.layout.layoutBox);const{visualElement:l}=this.options;l&&l.notify("LayoutMeasure",this.layout.layoutBox,a?a.layoutBox:void 0)}updateScroll(a="measure"){let l=!!(this.options.layoutScroll&&this.instance);if(this.scroll&&this.scroll.animationId===this.root.animationId&&this.scroll.phase===a&&(l=!1),l&&this.instance){const c=r(this.instance);this.scroll={animationId:this.root.animationId,phase:a,isRoot:c,offset:s(this.instance),wasRoot:this.scroll?this.scroll.isRoot:c}}}resetTransform(){if(!o)return;const a=this.isLayoutDirty||this.shouldResetTransform||this.options.alwaysMeasureLayout,l=this.projectionDelta&&!oN(this.projectionDelta),c=this.getTransformTemplate(),u=c?c(this.latestValues,""):void 0,d=u!==this.prevTransformTemplateValue;a&&this.instance&&(l||ko(this.latestValues)||d)&&(o(this.instance,u),this.shouldResetTransform=!1,this.scheduleRender())}measure(a=!0){const l=this.measurePageBox();let c=this.removeElementScroll(l);return a&&(c=this.removeTransform(c)),DL(c),{animationId:this.root.animationId,measuredBox:l,layoutBox:c,latestValues:{},source:this.id}}measurePageBox(){const{visualElement:a}=this.options;if(!a)return zn();const l=a.measureViewportBox();if(!(this.scroll?.wasRoot||this.path.some(OL))){const{scroll:u}=this.root;u&&(tr(l.x,u.offset.x),tr(l.y,u.offset.y))}return l}removeElementScroll(a){const l=zn();if(Fs(l,a),this.scroll?.wasRoot)return l;for(let c=0;c<this.path.length;c++){const u=this.path[c],{scroll:d,options:m}=u;u!==this.root&&d&&m.layoutScroll&&(d.wasRoot&&Fs(l,a),tr(l.x,d.offset.x),tr(l.y,d.offset.y))}return l}applyTransform(a,l=!1,c){const u=c||zn();Fs(u,a);for(let d=0;d<this.path.length;d++){const m=this.path[d];!l&&m.options.layoutScroll&&m.scroll&&m!==m.root&&(tr(u.x,-m.scroll.offset.x),tr(u.y,-m.scroll.offset.y)),ko(m.latestValues)&&Ac(u,m.latestValues,m.layout?.layoutBox)}return ko(this.latestValues)&&Ac(u,this.latestValues,this.layout?.layoutBox),u}removeTransform(a){const l=zn();Fs(l,a);for(let c=0;c<this.path.length;c++){const u=this.path[c];if(!ko(u.latestValues))continue;let d;u.instance&&(Pm(u.latestValues)&&u.updateSnapshot(),d=zn(),Fs(d,u.measurePageBox())),G0(l,u.latestValues,u.snapshot?.layoutBox,d)}return ko(this.latestValues)&&G0(l,this.latestValues),l}setTargetDelta(a){this.targetDelta=a,this.root.scheduleUpdateProjection(),this.isProjectionDirty=!0}setOptions(a){this.options={...this.options,...a,crossfade:a.crossfade!==void 0?a.crossfade:!0}}clearMeasurements(){this.scroll=void 0,this.layout=void 0,this.snapshot=void 0,this.prevTransformTemplateValue=void 0,this.targetDelta=void 0,this.target=void 0,this.isLayoutDirty=!1}forceRelativeParentToResolveTarget(){this.relativeParent&&this.relativeParent.resolvedRelativeTargetAt!==Zn.timestamp&&this.relativeParent.resolveTargetDelta(!0)}resolveTargetDelta(a=!1){const l=this.getLead();this.isProjectionDirty||(this.isProjectionDirty=l.isProjectionDirty),this.isTransformDirty||(this.isTransformDirty=l.isTransformDirty),this.isSharedProjectionDirty||(this.isSharedProjectionDirty=l.isSharedProjectionDirty);const c=!!this.resumingFrom||this!==l;if(!(a||c&&this.isSharedProjectionDirty||this.isProjectionDirty||this.parent?.isProjectionDirty||this.attemptToResolveRelativeTarget||this.root.updateBlockedByResize))return;const{layout:d,layoutId:m}=this.options;if(!this.layout||!(d||m))return;this.resolvedRelativeTargetAt=Zn.timestamp;const h=this.getClosestProjectingParent();h&&this.linkedParentVersion!==h.layoutVersion&&!h.options.layoutRoot&&this.removeRelativeTarget(),!this.targetDelta&&!this.relativeTarget&&(this.options.layoutAnchor!==!1&&h&&h.layout?this.createRelativeTarget(h,this.layout.layoutBox,h.layout.layoutBox):this.removeRelativeTarget()),!(!this.relativeTarget&&!this.targetDelta)&&(this.target||(this.target=zn(),this.targetWithTransforms=zn()),this.relativeTarget&&this.relativeTargetOrigin&&this.relativeParent&&this.relativeParent.target?(this.forceRelativeParentToResolveTarget(),nL(this.target,this.relativeTarget,this.relativeParent.target,this.options.layoutAnchor||void 0)):this.targetDelta?(this.resumingFrom?this.applyTransform(this.layout.layoutBox,!1,this.target):Fs(this.target,this.layout.layoutBox),qk(this.target,this.targetDelta)):Fs(this.target,this.layout.layoutBox),this.attemptToResolveRelativeTarget&&(this.attemptToResolveRelativeTarget=!1,this.options.layoutAnchor!==!1&&h&&!!h.resumingFrom==!!this.resumingFrom&&!h.options.layoutScroll&&h.target&&this.animationProgress!==1?this.createRelativeTarget(h,this.target,h.target):this.relativeParent=this.relativeTarget=void 0))}getClosestProjectingParent(){if(!(!this.parent||Pm(this.parent.latestValues)||Uk(this.parent.latestValues)))return this.parent.isProjecting()?this.parent:this.parent.getClosestProjectingParent()}isProjecting(){return!!((this.relativeTarget||this.targetDelta||this.options.layoutRoot)&&this.layout)}createRelativeTarget(a,l,c){this.relativeParent=a,this.linkedParentVersion=a.layoutVersion,this.forceRelativeParentToResolveTarget(),this.relativeTarget=zn(),this.relativeTargetOrigin=zn(),hd(this.relativeTargetOrigin,l,c,this.options.layoutAnchor||void 0),Fs(this.relativeTarget,this.relativeTargetOrigin)}removeRelativeTarget(){this.relativeParent=this.relativeTarget=void 0}calcProjection(){const a=this.getLead(),l=!!this.resumingFrom||this!==a;let c=!0;if((this.isProjectionDirty||this.parent?.isProjectionDirty)&&(c=!1),l&&(this.isSharedProjectionDirty||this.isTransformDirty)&&(c=!1),this.resolvedRelativeTargetAt===Zn.timestamp&&(c=!1),c)return;const{layout:u,layoutId:d}=this.options;if(this.isTreeAnimating=!!(this.parent&&this.parent.isTreeAnimating||this.currentAnimation||this.pendingAnimation),this.isTreeAnimating||(this.targetDelta=this.relativeTarget=void 0),!this.layout||!(u||d))return;Fs(this.layoutCorrected,this.layout.layoutBox);const m=this.treeScale.x,h=this.treeScale.y;MO(this.layoutCorrected,this.treeScale,this.path,l),a.layout&&!a.target&&(this.treeScale.x!==1||this.treeScale.y!==1)&&(a.target=a.layout.layoutBox,a.targetWithTransforms=zn());const{target:p}=a;if(!p){this.prevProjectionDelta&&(this.createProjectionDeltas(),this.scheduleRender());return}!this.projectionDelta||!this.prevProjectionDelta?this.createProjectionDeltas():($0(this.prevProjectionDelta.x,this.projectionDelta.x),$0(this.prevProjectionDelta.y,this.projectionDelta.y)),ba(this.projectionDelta,this.layoutCorrected,p,this.latestValues),(this.treeScale.x!==m||this.treeScale.y!==h||!J0(this.projectionDelta.x,this.prevProjectionDelta.x)||!J0(this.projectionDelta.y,this.prevProjectionDelta.y))&&(this.hasProjected=!0,this.scheduleRender(),this.notifyListeners("projectionUpdate",p))}hide(){this.isVisible=!1}show(){this.isVisible=!0}scheduleRender(a=!0){if(this.options.visualElement?.scheduleRender(),a){const l=this.getStack();l&&l.scheduleRender()}this.resumingFrom&&!this.resumingFrom.instance&&(this.resumingFrom=void 0)}createProjectionDeltas(){this.prevProjectionDelta=ii(),this.projectionDelta=ii(),this.projectionDeltaWithTransform=ii()}setAnimationOrigin(a,l=!1,c){const u=this.snapshot,d=u?u.latestValues:{},m={...this.latestValues},h=ii();(!this.relativeParent||!this.relativeParent.options.layoutRoot)&&(this.relativeTarget=this.relativeTargetOrigin=void 0),this.attemptToResolveRelativeTarget=!l;const p=zn(),g=u?u.source:void 0,x=this.layout?this.layout.source:void 0,v=g!==x,b=this.getStack(),w=!b||b.members.length<=1,j=!!(v&&!w&&this.options.crossfade===!0&&!this.path.some(ML));this.animationProgress=0;let T;const N=c?.interpolateProjection(a);this.mixTargetDelta=S=>{const I=S/1e3,k=N?.(I);k?(h.x.translate=k.x,h.x.scale=mn(a.x.scale,1,I),h.x.origin=a.x.origin,h.x.originPoint=a.x.originPoint,h.y.translate=k.y,h.y.scale=mn(a.y.scale,1,I),h.y.origin=a.y.origin,h.y.originPoint=a.y.originPoint):(ov(h.x,a.x,I),ov(h.y,a.y,I)),this.setTargetDelta(h),this.relativeTarget&&this.relativeTargetOrigin&&this.layout&&this.relativeParent&&this.relativeParent.layout&&(hd(p,this.layout.layoutBox,this.relativeParent.layout.layoutBox,this.options.layoutAnchor||void 0),RL(this.relativeTarget,this.relativeTargetOrigin,p,I),T&&iL(this.relativeTarget,T)&&(this.isProjectionDirty=!1),T||(T=zn()),Fs(T,this.relativeTarget)),v&&(this.animationValues=m,cL(m,d,this.latestValues,I,j,w)),k&&k.rotate!==void 0&&(this.animationValues||(this.animationValues=m),this.animationValues.pathRotation=k.rotate),this.root.scheduleUpdateProjection(),this.scheduleRender(),this.animationProgress=I},this.mixTargetDelta(this.options.layoutRoot?1e3:0)}startAnimation(a){this.notifyListeners("animationStart"),this.currentAnimation?.stop(),this.resumingFrom?.currentAnimation?.stop(),this.pendingAnimation&&(to(this.pendingAnimation),this.pendingAnimation=void 0),this.pendingAnimation=hn.update(()=>{Rc.hasAnimatedSinceResize=!0,this.motionValue||(this.motionValue=Ci(0)),this.motionValue.jump(0,!1),this.currentAnimation=fL(this.motionValue,[0,1e3],{...a,velocity:0,isSync:!0,onUpdate:l=>{this.mixTargetDelta(l),a.onUpdate&&a.onUpdate(l)},onComplete:()=>{a.onComplete&&a.onComplete(),this.completeAnimation()}}),this.resumingFrom&&(this.resumingFrom.currentAnimation=this.currentAnimation),this.pendingAnimation=void 0})}completeAnimation(){this.resumingFrom&&(this.resumingFrom.currentAnimation=void 0,this.resumingFrom.preserveOpacity=void 0);const a=this.getStack();a&&a.exitAnimationComplete(),this.resumingFrom=this.currentAnimation=this.animationValues=void 0,this.notifyListeners("animationComplete")}finishAnimation(){this.currentAnimation&&(this.mixTargetDelta&&this.mixTargetDelta(gL),this.currentAnimation.stop()),this.completeAnimation()}applyTransformsToTarget(){const a=this.getLead();let{targetWithTransforms:l,target:c,layout:u,latestValues:d}=a;if(!(!l||!c||!u)){if(this!==a&&this.layout&&u&&dN(this.options.animationType,this.layout.layoutBox,u.layoutBox)){c=this.target||zn();const m=ls(this.layout.layoutBox.x);c.x.min=a.target.x.min,c.x.max=c.x.min+m;const h=ls(this.layout.layoutBox.y);c.y.min=a.target.y.min,c.y.max=c.y.min+h}Fs(l,c),Ac(l,d),ba(this.projectionDeltaWithTransform,this.layoutCorrected,l,d)}}registerSharedNode(a,l){this.sharedNodes.has(a)||this.sharedNodes.set(a,new xL),this.sharedNodes.get(a).add(l);const u=l.options.initialPromotionConfig;l.promote({transition:u?u.transition:void 0,preserveFollowOpacity:u&&u.shouldPreserveFollowOpacity?u.shouldPreserveFollowOpacity(l):void 0})}isLead(){const a=this.getStack();return a?a.lead===this:!0}getLead(){const{layoutId:a}=this.options;return a?this.getStack()?.lead||this:this}getPrevLead(){const{layoutId:a}=this.options;return a?this.getStack()?.prevLead:void 0}getStack(){const{layoutId:a}=this.options;if(a)return this.root.sharedNodes.get(a)}promote({needsReset:a,transition:l,preserveFollowOpacity:c}={}){const u=this.getStack();u&&u.promote(this,c),a&&(this.projectionDelta=void 0,this.needsReset=!0),l&&this.setOptions({transition:l})}relegate(){const a=this.getStack();return a?a.relegate(this):!1}resetSkewAndRotation(){const{visualElement:a}=this.options;if(!a)return;let l=!1;const{latestValues:c}=a;if((c.z||c.rotate||c.rotateX||c.rotateY||c.rotateZ||c.skewX||c.skewY)&&(l=!0),!l)return;const u={};c.z&&tf("z",a,u,this.animationValues);for(let d=0;d<ef.length;d++)tf(`rotate${ef[d]}`,a,u,this.animationValues),tf(`skew${ef[d]}`,a,u,this.animationValues);a.render();for(const d in u)a.setStaticValue(d,u[d]),this.animationValues&&(this.animationValues[d]=u[d]);a.scheduleRender()}applyProjectionStyles(a,l){if(!this.instance||this.isSVG)return;if(!this.isVisible){a.visibility="hidden";return}const c=this.getTransformTemplate();if(this.needsReset){this.needsReset=!1,a.visibility="",a.opacity="",a.pointerEvents=Ec(l?.pointerEvents)||"",a.transform=c?c(this.latestValues,""):"none";return}const u=this.getLead();if(!this.projectionDelta||!this.layout||!u.target){this.options.layoutId&&(a.opacity=this.latestValues.opacity!==void 0?this.latestValues.opacity:1,a.pointerEvents=Ec(l?.pointerEvents)||""),this.hasProjected&&!ko(this.latestValues)&&(a.transform=c?c({},""):"none",this.hasProjected=!1);return}a.visibility="";const d=u.animationValues||u.latestValues;this.applyTransformsToTarget();let m=aL(this.projectionDeltaWithTransform,this.treeScale,d);c&&(m=c(d,m)),a.transform=m;const{x:h,y:p}=this.projectionDelta;a.transformOrigin=`${h.origin*100}% ${p.origin*100}% 0`,u.animationValues?a.opacity=u===this?d.opacity??this.latestValues.opacity??1:this.preserveOpacity?this.latestValues.opacity:d.opacityExit:a.opacity=u===this?d.opacity!==void 0?d.opacity:"":d.opacityExit!==void 0?d.opacityExit:0;for(const g in Om){if(d[g]===void 0)continue;const{correct:x,applyTo:v,isCSSVariable:b}=Om[g],w=m==="none"?d[g]:x(d[g],u);if(v){const j=v.length;for(let T=0;T<j;T++)a[v[T]]=w}else b?this.options.visualElement.renderState.vars[g]=w:a[g]=w}this.options.layoutId&&(a.pointerEvents=u===this?Ec(l?.pointerEvents)||"":"none")}clearSnapshot(){this.resumeFrom=this.snapshot=void 0}resetTree(){this.root.nodes.forEach(a=>a.currentAnimation?.stop()),this.root.nodes.forEach(nv),this.root.sharedNodes.clear()}}}function bL(e){e.updateLayout()}function yL(e){const t=e.resumeFrom?.snapshot||e.snapshot;if(e.isLead()&&e.layout&&t&&e.hasListeners("didUpdate")){const{layoutBox:s,measuredBox:r}=e.layout,{animationType:o}=e.options,i=t.source!==e.layout.source;if(o==="size")Zs(d=>{const m=i?t.measuredBox[d]:t.layoutBox[d],h=ls(m);m.min=s[d].min,m.max=m.min+h});else if(o==="x"||o==="y"){const d=o==="x"?"y":"x";Lm(i?t.measuredBox[d]:t.layoutBox[d],s[d])}else dN(o,t.layoutBox,s)&&Zs(d=>{const m=i?t.measuredBox[d]:t.layoutBox[d],h=ls(s[d]);m.max=m.min+h,e.relativeTarget&&!e.currentAnimation&&(e.isProjectionDirty=!0,e.relativeTarget[d].max=e.relativeTarget[d].min+h)});const a=ii();ba(a,s,t.layoutBox);const l=ii();i?ba(l,e.applyTransform(r,!0),t.measuredBox):ba(l,s,t.layoutBox);const c=!oN(a);let u=!1;if(!e.resumeFrom){const d=e.getClosestProjectingParent();if(d&&!d.resumeFrom){const{snapshot:m,layout:h}=d;if(m&&h){const p=e.options.layoutAnchor||void 0,g=zn();hd(g,t.layoutBox,m.layoutBox,p);const x=zn();hd(x,s,h.layoutBox,p),iN(g,x)||(u=!0),d.options.layoutRoot&&(e.relativeTarget=x,e.relativeTargetOrigin=g,e.relativeParent=d)}}}e.notifyListeners("didUpdate",{layout:s,snapshot:t,delta:l,layoutDelta:a,hasLayoutChanged:c,hasRelativeLayoutChanged:u})}else if(e.isLead()){const{onExitComplete:s}=e.options;s&&s()}e.options.transition=void 0}function wL(e){e.parent&&(e.isProjecting()||(e.isProjectionDirty=e.parent.isProjectionDirty),e.isSharedProjectionDirty||(e.isSharedProjectionDirty=!!(e.isProjectionDirty||e.parent.isProjectionDirty||e.parent.isSharedProjectionDirty)),e.isTransformDirty||(e.isTransformDirty=e.parent.isTransformDirty))}function jL(e){e.isProjectionDirty=e.isSharedProjectionDirty=e.isTransformDirty=!1}function kL(e){e.clearSnapshot()}function nv(e){e.clearMeasurements()}function NL(e){e.isLayoutDirty=!0,e.updateLayout()}function sv(e){e.isLayoutDirty=!1}function SL(e){e.isAnimationBlocked&&e.layout&&!e.isLayoutDirty&&(e.snapshot=e.layout,e.isLayoutDirty=!0)}function CL(e){const{visualElement:t}=e.options;t&&t.getProps().onBeforeLayoutMeasure&&t.notify("BeforeLayoutMeasure"),e.resetTransform()}function rv(e){e.finishAnimation(),e.targetDelta=e.relativeTarget=e.target=void 0,e.isProjectionDirty=!0}function IL(e){e.resolveTargetDelta()}function TL(e){e.calcProjection()}function AL(e){e.resetSkewAndRotation()}function EL(e){e.removeLeadSnapshot()}function ov(e,t,s){e.translate=mn(t.translate,0,s),e.scale=mn(t.scale,1,s),e.origin=t.origin,e.originPoint=t.originPoint}function iv(e,t,s,r){e.min=mn(t.min,s.min,r),e.max=mn(t.max,s.max,r)}function RL(e,t,s,r){iv(e.x,t.x,s.x,r),iv(e.y,t.y,s.y,r)}function ML(e){return e.animationValues&&e.animationValues.opacityExit!==void 0}const PL={duration:.45,ease:[.4,0,.1,1]},av=e=>typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().includes(e),lv=av("applewebkit/")&&!av("chrome/")?Math.round:Ls;function cv(e){e.min=lv(e.min),e.max=lv(e.max)}function DL(e){cv(e.x),cv(e.y)}function dN(e,t,s){return e==="position"||e==="preserve-aspect"&&!tL(Q0(t),Q0(s),.2)}function OL(e){return e!==e.root&&e.scroll?.wasRoot}const LL=cN({attachResizeListener:(e,t)=>Ua(e,"resize",t),measureScroll:()=>({x:document.documentElement.scrollLeft||document.body?.scrollLeft||0,y:document.documentElement.scrollTop||document.body?.scrollTop||0}),checkIsScrollRoot:()=>!0}),nf={current:void 0},uN=cN({measureScroll:e=>({x:e.scrollLeft,y:e.scrollTop}),defaultParent:()=>{if(!nf.current){const e=new LL({});e.mount(window),e.setOptions({layoutScroll:!0}),nf.current=e}return nf.current},resetTransform:(e,t)=>{e.style.transform=t!==void 0?t:"none"},checkIsScrollRoot:e=>window.getComputedStyle(e).position==="fixed"}),Yp=f.createContext({transformPagePoint:e=>e,isStatic:!1,reducedMotion:"never"});function dv(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function _L(...e){return t=>{let s=!1;const r=e.map(o=>{const i=dv(o,t);return!s&&typeof i=="function"&&(s=!0),i});if(s)return()=>{for(let o=0;o<r.length;o++){const i=r[o];typeof i=="function"?i():dv(e[o],null)}}}}function BL(...e){return f.useCallback(_L(...e),e)}class FL extends f.Component{getSnapshotBeforeUpdate(t){const s=this.props.childRef.current;if(Nc(s)&&t.isPresent&&!this.props.isPresent&&this.props.pop!==!1){const r=s.offsetParent,o=Nc(r)&&r.offsetWidth||0,i=Nc(r)&&r.offsetHeight||0,a=getComputedStyle(s),l=this.props.sizeRef.current;l.height=parseFloat(a.height),l.width=parseFloat(a.width),l.top=s.offsetTop,l.left=s.offsetLeft,l.right=o-l.width-l.left,l.bottom=i-l.height-l.top,l.direction=a.direction}return null}componentDidUpdate(){}render(){return this.props.children}}function zL({children:e,isPresent:t,anchorX:s,anchorY:r,root:o,pop:i}){const a=f.useId(),l=f.useRef(null),c=f.useRef({width:0,height:0,top:0,left:0,right:0,bottom:0,direction:"ltr"}),{nonce:u}=f.useContext(Yp),d=i!==!1?e.props?.ref??e?.ref:void 0,m=BL(l,d);return f.useInsertionEffect(()=>{const{width:h,height:p,top:g,left:x,right:v,bottom:b,direction:w}=c.current;if(t||i===!1||!l.current||!h||!p)return;const j=w==="rtl",T=s==="left"?j?`right: ${v}`:`left: ${x}`:j?`left: ${x}`:`right: ${v}`,N=r==="bottom"?`bottom: ${b}`:`top: ${g}`;l.current.dataset.motionPopId=a;const S=document.createElement("style");u&&(S.nonce=u);const I=o??document.head;return I.appendChild(S),S.sheet&&S.sheet.insertRule(`
|
|
7
|
-
[data-motion-pop-id="${a}"] {
|
|
8
|
-
position: absolute !important;
|
|
9
|
-
width: ${h}px !important;
|
|
10
|
-
height: ${p}px !important;
|
|
11
|
-
${T}px !important;
|
|
12
|
-
${N}px !important;
|
|
13
|
-
}
|
|
14
|
-
`),()=>{l.current?.removeAttribute("data-motion-pop-id"),I.contains(S)&&I.removeChild(S)}},[t]),n.jsx(FL,{isPresent:t,childRef:l,sizeRef:c,pop:i,children:i===!1?e:f.cloneElement(e,{ref:m})})}const $L=({children:e,initial:t,isPresent:s,onExitComplete:r,custom:o,presenceAffectsLayout:i,mode:a,anchorX:l,anchorY:c,root:u})=>{const d=Np(VL),m=f.useId(),h=f.useRef(s),p=f.useRef(r);rd(()=>{h.current=s,p.current=r});let g=!0,x=f.useMemo(()=>(g=!1,{id:m,initial:t,isPresent:s,custom:o,onExitComplete:v=>{d.set(v,!0);for(const b of d.values())if(!b)return;r&&r()},register:v=>(d.set(v,!1),()=>{d.delete(v),!h.current&&!d.size&&p.current?.()})}),[s,d,r]);return i&&g&&(x={...x}),f.useMemo(()=>{d.forEach((v,b)=>d.set(b,!1))},[s]),f.useEffect(()=>{!s&&!d.size&&r&&r()},[s]),e=n.jsx(zL,{pop:a==="popLayout",isPresent:s,anchorX:l,anchorY:c,root:u,children:e}),n.jsx(nu.Provider,{value:x,children:e})};function VL(){return new Map}function fN(e=!0){const t=f.useContext(nu);if(t===null)return[!0,null];const{isPresent:s,onExitComplete:r,register:o}=t,i=f.useId();f.useEffect(()=>{if(e)return o(i)},[e]);const a=f.useCallback(()=>e&&r&&r(i),[i,r,e]);return!s&&r?[!1,a]:[!0]}const ql=e=>e.key||"";function uv(e){const t=[];return f.Children.forEach(e,s=>{f.isValidElement(s)&&t.push(s)}),t}const ya=({children:e,custom:t,initial:s=!0,onExitComplete:r,presenceAffectsLayout:o=!0,mode:i="sync",propagate:a=!1,anchorX:l="left",anchorY:c="top",root:u})=>{const[d,m]=fN(a),h=f.useMemo(()=>uv(e),[e]),p=a&&!d?[]:h.map(ql),g=f.useRef(!0),x=f.useRef(h),v=Np(()=>new Map),b=f.useRef(new Set),[w,j]=f.useState(h),[T,N]=f.useState(h);rd(()=>{a&&!d&&!T.length&&m?.()},[d,a,T.length,m]),rd(()=>{g.current=!1,x.current=h;for(let k=0;k<T.length;k++){const L=ql(T[k]);p.includes(L)?(v.delete(L),b.current.delete(L)):v.get(L)!==!0&&v.set(L,!1)}},[T,p.length,p.join("-")]);const S=[];if(h!==w){let k=[...h],L=0;for(const F of T){const A=p.indexOf(ql(F));A===-1?(k.splice(L++,0,F),S.push(F)):L=A+S.length+1}return i==="wait"&&S.length&&(k=S),N(uv(k)),j(h),null}const{forceRender:I}=f.useContext(kp);return n.jsx(n.Fragment,{children:T.map(k=>{const L=ql(k),F=a&&!d?!1:h===T||p.includes(L),A=()=>{if(b.current.has(L))return;if(v.has(L))b.current.add(L),v.set(L,!0);else return;let M=!0;v.forEach(R=>{R||(M=!1)}),M&&(I?.(),N(x.current),a&&m?.(),r&&r())};return n.jsx($L,{isPresent:F,initial:!g.current||s?void 0:!1,custom:t,presenceAffectsLayout:o,mode:i,root:u,onExitComplete:F?void 0:A,anchorX:l,anchorY:c,children:k},L)})})},mN=f.createContext({strict:!1}),fv={animation:["animate","variants","whileHover","whileTap","exit","whileInView","whileFocus","whileDrag"],exit:["exit"],drag:["drag","dragControls"],focus:["whileFocus"],hover:["whileHover","onHoverStart","onHoverEnd"],tap:["whileTap","onTap","onTapStart","onTapCancel"],pan:["onPan","onPanStart","onPanSessionStart","onPanEnd"],inView:["whileInView","onViewportEnter","onViewportLeave"],layout:["layout","layoutId"]};let mv=!1;function HL(){if(mv)return;const e={};for(const t in fv)e[t]={isEnabled:s=>fv[t].some(r=>!!s[r])};Vk(e),mv=!0}function hN(){return HL(),TO()}function WL(e){const t=hN();for(const s in e)t[s]={...t[s],...e[s]};Vk(t)}const au=f.createContext({});function UL(e,t){if(iu(e)){const{initial:s,animate:r}=e;return{initial:s===!1||Wa(s)?s:void 0,animate:Wa(r)?r:void 0}}return e.inherit!==!1?t:{}}function qL(e){const{initial:t,animate:s}=UL(e,f.useContext(au));return f.useMemo(()=>({initial:t,animate:s}),[hv(t),hv(s)])}function hv(e){return Array.isArray(e)?e.join(" "):e}const Xp=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function pN(e,t,s){for(const r in t)!es(t[r])&&!Yk(r,s)&&(e[r]=t[r])}function GL({transformTemplate:e},t){return f.useMemo(()=>{const s=Xp();return Gp(s,t,e),Object.assign({},s.vars,s.style)},[t])}function KL(e,t){const s=e.style||{},r={};return pN(r,s,e),Object.assign(r,GL(e,t)),r}function YL(e,t){const s={},r=KL(e,t);return e.drag&&e.dragListener!==!1&&(s.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=e.drag===!0?"none":`pan-${e.drag==="x"?"y":"x"}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(s.tabIndex=0),s.style=r,s}const xN=()=>({...Xp(),attrs:{}});function XL(e,t,s,r){const o=f.useMemo(()=>{const i=xN();return Qk(i,t,Zk(r),e.transformTemplate,e.style),{...i.attrs,style:{...i.style}}},[t]);if(e.style){const i={};pN(i,e.style,e),o.style={...i,...o.style}}return o}const QL=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","propagate","ignoreStrict","viewport"]);function pd(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||QL.has(e)}function JL(e,t){return e.startsWith("on")?!pd(e):t?.(e)??!pd(e)}function ZL(e,t,s,r){const o={};for(const i in e)i==="values"&&typeof e.values=="object"||es(e[i])||(JL(i,r)||s===!0&&pd(i)||!t&&!pd(i)||e.draggable&&i.startsWith("onDrag"))&&(o[i]=e[i]);return o}const e4=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function Qp(e){return typeof e!="string"||e.includes("-")?!1:!!(e4.indexOf(e)>-1||/[A-Z]/u.test(e))}function t4(e,t,s,{latestValues:r},o,i=!1,a,l){const u=(a??Qp(e)?XL:YL)(t,r,o,e),d=ZL(t,typeof e=="string",i,l),m=e!==f.Fragment?{...d,...u,ref:s}:{},{children:h}=t,p=f.useMemo(()=>es(h)?h.get():h,[h]);return f.createElement(e,{...m,children:p})}function n4({scrapeMotionValuesFromProps:e,createRenderState:t},s,r,o){return{latestValues:s4(s,r,o,e),renderState:t()}}function s4(e,t,s,r){const o={},i=r(e,{});for(const h in i)o[h]=Ec(i[h]);let{initial:a,animate:l}=e;const c=iu(e),u=zk(e);t&&u&&!c&&e.inherit!==!1&&(a===void 0&&(a=t.initial),l===void 0&&(l=t.animate));let d=s?s.initial===!1:!1;d=d||a===!1;const m=d?l:a;if(m&&typeof m!="boolean"&&!ou(m)){const h=Array.isArray(m)?m:[m];for(let p=0;p<h.length;p++){const g=Bp(e,h[p]);if(g){const{transitionEnd:x,transition:v,...b}=g;for(const w in b){let j=b[w];if(Array.isArray(j)){const T=d?j.length-1:0;j=j[T]}j!==null&&(o[w]=j)}for(const w in x)o[w]=x[w]}}}return o}const gN=e=>(t,s)=>{const r=f.useContext(au),o=f.useContext(nu),i=()=>n4(e,t,r,o);return s?i():Np(i)},r4=gN({scrapeMotionValuesFromProps:Kp,createRenderState:Xp}),o4=gN({scrapeMotionValuesFromProps:eN,createRenderState:xN}),i4=Symbol.for("motionComponentSymbol");function a4(e,t,s){const r=f.useRef(s);f.useInsertionEffect(()=>{r.current=s});const o=f.useRef(null);return f.useCallback(i=>{i&&e.onMount?.(i),t&&(i?t.mount(i):t.unmount());const a=r.current;if(typeof a=="function")if(i){const l=a(i);typeof l=="function"&&(o.current=l)}else o.current?(o.current(),o.current=null):a(i);else a&&(a.current=i)},[t])}const vN=f.createContext({});function ni(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function l4(e,t,s,r,o,i){const{visualElement:a}=f.useContext(au),l=f.useContext(mN),c=f.useContext(nu),u=f.useContext(Yp),d=u.reducedMotion,m=u.skipAnimations,h=f.useRef(null),p=f.useRef(!1);r=r||l.renderer,!h.current&&r&&(h.current=r(e,{visualState:t,parent:a,props:s,presenceContext:c,blockInitialAnimation:c?c.initial===!1:!1,reducedMotionConfig:d,skipAnimations:m,isSVG:i}),p.current&&h.current&&(h.current.manuallyAnimateOnMount=!0));const g=h.current,x=f.useContext(vN);g&&!g.projection&&o&&(g.type==="html"||g.type==="svg")&&c4(h.current,s,o,x);const v=f.useRef(!1);f.useInsertionEffect(()=>{g&&v.current&&g.update(s,c)});const b=s[Tk],w=f.useRef(!!b&&typeof window<"u"&&!window.MotionHandoffIsComplete?.(b)&&window.MotionHasOptimisedAnimation?.(b));return rd(()=>{p.current=!0,g&&(v.current=!0,window.MotionIsMounted=!0,g.updateFeatures(),g.scheduleRenderMicrotask(),w.current&&g.animationState&&g.animationState.animateChanges())}),f.useEffect(()=>{g&&(!w.current&&g.animationState&&g.animationState.animateChanges(),w.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(b)}),w.current=!1),g.enteringChildren=void 0)}),g}function c4(e,t,s,r){const{layoutId:o,layout:i,drag:a,dragConstraints:l,layoutScroll:c,layoutRoot:u,layoutAnchor:d,layoutCrossfade:m}=t;e.projection=new s(e.latestValues,t["data-framer-portal-id"]?void 0:bN(e.parent)),e.projection.setOptions({layoutId:o,layout:i,alwaysMeasureLayout:!!a||l&&ni(l),visualElement:e,animationType:typeof i=="string"?i:"both",initialPromotionConfig:r,crossfade:m,layoutScroll:c,layoutRoot:u,layoutAnchor:d})}function bN(e){if(e)return e.options.allowProjection!==!1?e.projection:bN(e.parent)}function sf(e,{forwardMotionProps:t=!1,type:s}={},r,o){r&&WL(r);const i=s?s==="svg":Qp(e),a=i?o4:r4;function l(u,d){let m;const h={...f.useContext(Yp),...u,layoutId:d4(u)},{isStatic:p,isValidProp:g}=h,x=qL(u),v=a(u,p);if(!p&&typeof window<"u"){u4();const b=f4(h);m=b.MeasureLayout,x.visualElement=l4(e,v,h,o,b.ProjectionNode,i)}return n.jsxs(au.Provider,{value:x,children:[m&&x.visualElement?n.jsx(m,{visualElement:x.visualElement,...h}):null,t4(e,u,a4(v,x.visualElement,d),v,p,t,i,g)]})}l.displayName=`motion.${typeof e=="string"?e:`create(${e.displayName??e.name??""})`}`;const c=f.forwardRef(l);return c[i4]=e,c}function d4({layoutId:e}){const t=f.useContext(kp).id;return t&&e!==void 0?t+"-"+e:e}function u4(e,t){f.useContext(mN).strict}function f4(e){const t=hN(),{drag:s,layout:r}=t;if(!s&&!r)return{};const o={...s,...r};return{MeasureLayout:s?.isEnabled(e)||r?.isEnabled(e)?o.MeasureLayout:void 0,ProjectionNode:o.ProjectionNode}}function m4(e,t){if(typeof Proxy>"u")return sf;const s=new Map,r=(i,a)=>sf(i,a,e,t),o=(i,a)=>r(i,a);return new Proxy(o,{get:(i,a)=>a==="create"?r:(s.has(a)||s.set(a,sf(a,void 0,e,t)),s.get(a))})}const h4=(e,t)=>t.isSVG??Qp(e)?new WO(t):new FO(t,{allowProjection:e!==f.Fragment});class p4 extends io{constructor(t){super(t),t.animationState||(t.animationState=YO(t))}updateAnimationControlsSubscription(){const{animate:t}=this.node.getProps();ou(t)&&(this.unmountControls=t.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:t}=this.node.getProps(),{animate:s}=this.node.prevProps||{};t!==s&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let x4=0;class g4 extends io{constructor(){super(...arguments),this.id=x4++,this.isExitComplete=!1}update(){if(!this.node.presenceContext)return;const{isPresent:t,onExitComplete:s}=this.node.presenceContext,{isPresent:r}=this.node.prevPresenceContext||{};if(!this.node.animationState||t===r)return;if(t&&r===!1){if(this.isExitComplete){const{initial:i,custom:a}=this.node.getProps();if(typeof i=="string"||typeof i=="object"&&i!==null&&!Array.isArray(i)){const l=Mo(this.node,i,a);if(l){const{transition:c,transitionEnd:u,...d}=l;for(const m in d)this.node.getValue(m)?.jump(d[m])}}this.node.animationState.reset(),this.node.animationState.animateChanges()}else this.node.animationState.setActive("exit",!1);this.isExitComplete=!1;return}const o=this.node.animationState.setActive("exit",!t);s&&!t&&o.then(()=>{this.isExitComplete=!0,s(this.id)})}mount(){const{register:t,onExitComplete:s}=this.node.presenceContext||{};s&&s(this.id),t&&(this.unmount=t(this.id))}unmount(){}}const v4={animation:{Feature:p4},exit:{Feature:g4}};function jl(e){return{point:{x:e.pageX,y:e.pageY}}}const b4=e=>t=>Vp(t)&&e(t,jl(t));function wa(e,t,s,r){return Ua(e,t,b4(s),r)}const yN=({current:e})=>e?e.ownerDocument.defaultView:null,pv=(e,t)=>Math.abs(e-t);function y4(e,t){const s=pv(e.x,t.x),r=pv(e.y,t.y);return Math.sqrt(s**2+r**2)}const xv=new Set(["auto","scroll"]);class wN{constructor(t,s,{transformPagePoint:r,contextWindow:o=window,dragSnapToOrigin:i=!1,distanceThreshold:a=3,element:l}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.lastRawMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=g=>{this.handleScroll(g.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;this.lastRawMoveEventInfo&&(this.lastMoveEventInfo=Gl(this.lastRawMoveEventInfo,this.transformPagePoint));const g=rf(this.lastMoveEventInfo,this.history),x=this.startEvent!==null,v=y4(g.offset,{x:0,y:0})>=this.distanceThreshold;if(!x&&!v)return;const{point:b}=g,{timestamp:w}=Zn;this.history.push({...b,timestamp:w});const{onStart:j,onMove:T}=this.handlers;x||(j&&j(this.lastMoveEvent,g),this.startEvent=this.lastMoveEvent),T&&T(this.lastMoveEvent,g)},this.handlePointerMove=(g,x)=>{this.lastMoveEvent=g,this.lastRawMoveEventInfo=x,this.lastMoveEventInfo=Gl(x,this.transformPagePoint),hn.update(this.updatePoint,!0)},this.handlePointerUp=(g,x)=>{this.end();const{onEnd:v,onSessionEnd:b,resumeAnimation:w}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&w&&w(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const j=rf(g.type==="pointercancel"?this.lastMoveEventInfo:Gl(x,this.transformPagePoint),this.history);this.startEvent&&v&&v(g,j),b&&b(g,j)},!Vp(t))return;this.dragSnapToOrigin=i,this.handlers=s,this.transformPagePoint=r,this.distanceThreshold=a,this.contextWindow=o||window;const c=jl(t),u=Gl(c,this.transformPagePoint),{point:d}=u,{timestamp:m}=Zn;this.history=[{...d,timestamp:m}];const{onSessionStart:h}=s;h&&h(t,rf(u,this.history));const p={passive:!0,capture:!0};this.removeListeners=bl(wa(this.contextWindow,"pointermove",this.handlePointerMove,p),wa(this.contextWindow,"pointerup",this.handlePointerUp,p),wa(this.contextWindow,"pointercancel",this.handlePointerUp,p)),l&&this.startScrollTracking(l)}startScrollTracking(t){let s=t.parentElement;for(;s;){const r=getComputedStyle(s);(xv.has(r.overflowX)||xv.has(r.overflowY))&&this.scrollPositions.set(s,{x:s.scrollLeft,y:s.scrollTop}),s=s.parentElement}this.scrollPositions.set(window,{x:window.scrollX,y:window.scrollY}),window.addEventListener("scroll",this.onElementScroll,{capture:!0}),window.addEventListener("scroll",this.onWindowScroll),this.removeScrollListeners=()=>{window.removeEventListener("scroll",this.onElementScroll,{capture:!0}),window.removeEventListener("scroll",this.onWindowScroll)}}handleScroll(t){const s=this.scrollPositions.get(t);if(!s)return;const r=t===window,o=r?{x:window.scrollX,y:window.scrollY}:{x:t.scrollLeft,y:t.scrollTop},i={x:o.x-s.x,y:o.y-s.y};i.x===0&&i.y===0||(r?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=i.x,this.lastMoveEventInfo.point.y+=i.y):this.history.length>0&&(this.history[0].x-=i.x,this.history[0].y-=i.y),this.scrollPositions.set(t,o),hn.update(this.updatePoint,!0))}updateHandlers(t){this.handlers=t}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),to(this.updatePoint)}}function Gl(e,t){return t?{point:t(e.point)}:e}function gv(e,t){return{x:e.x-t.x,y:e.y-t.y}}function rf({point:e},t){return{point:e,delta:gv(e,jN(t)),offset:gv(e,w4(t)),velocity:j4(t,.1)}}function w4(e){return e[0]}function jN(e){return e[e.length-1]}function j4(e,t){if(e.length<2)return{x:0,y:0};let s=e.length-1,r=null;const o=jN(e);for(;s>=0&&(r=e[s],!(o.timestamp-r.timestamp>xs(t)));)s--;if(!r)return{x:0,y:0};r===e[0]&&e.length>2&&o.timestamp-r.timestamp>xs(t)*2&&(r=e[1]);const i=As(o.timestamp-r.timestamp);if(i===0)return{x:0,y:0};const a={x:(o.x-r.x)/i,y:(o.y-r.y)/i};return a.x===1/0&&(a.x=0),a.y===1/0&&(a.y=0),a}function k4(e,{min:t,max:s},r){return t!==void 0&&e<t?e=r?mn(t,e,r.min):Math.max(e,t):s!==void 0&&e>s&&(e=r?mn(s,e,r.max):Math.min(e,s)),e}function vv(e,t,s){return{min:t!==void 0?e.min+t:void 0,max:s!==void 0?e.max+s-(e.max-e.min):void 0}}function N4(e,{top:t,left:s,bottom:r,right:o}){return{x:vv(e.x,s,o),y:vv(e.y,t,r)}}function bv(e,t){let s=t.min-e.min,r=t.max-e.max;return t.max-t.min<e.max-e.min&&([s,r]=[r,s]),{min:s,max:r}}function S4(e,t){return{x:bv(e.x,t.x),y:bv(e.y,t.y)}}function C4(e,t){let s=.5;const r=ls(e),o=ls(t);return o>r?s=Va(t.min,t.max-r,e.min):r>o&&(s=Va(e.min,e.max-o,t.min)),fr(0,1,s)}function I4(e,t){const s={};return t.min!==void 0&&(s.min=t.min-e.min),t.max!==void 0&&(s.max=t.max-e.min),s}const _m=.35;function T4(e=_m){return e===!1?e=0:e===!0&&(e=_m),{x:yv(e,"left","right"),y:yv(e,"top","bottom")}}function yv(e,t,s){return{min:wv(e,t),max:wv(e,s)}}function wv(e,t){return typeof e=="number"?e:e[t]||0}const A4=new WeakMap;class E4{constructor(t){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=zn(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=t}start(t,{snapToCursor:s=!1,distanceThreshold:r}={}){const{presenceContext:o}=this.visualElement;if(o&&o.isPresent===!1)return;const i=m=>{s&&this.snapToCursor(jl(m).point),this.stopAnimation()},a=(m,h)=>{const{drag:p,dragPropagation:g,onDragStart:x}=this.getProps();if(p&&!g&&(this.openDragLock&&this.openDragLock(),this.openDragLock=oO(p),!this.openDragLock))return;this.latestPointerEvent=m,this.latestPanInfo=h,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),Zs(b=>{let w=this.getAxisMotionValue(b).get()||0;if(ar.test(w)){const{projection:j}=this.visualElement;if(j&&j.layout){const T=j.layout.layoutBox[b];T&&(w=ls(T)*(parseFloat(w)/100))}}this.originPoint[b]=w}),x&&hn.update(()=>x(m,h),!1,!0),Tm(this.visualElement,"transform");const{animationState:v}=this.visualElement;v&&v.setActive("whileDrag",!0)},l=(m,h)=>{this.latestPointerEvent=m,this.latestPanInfo=h;const{dragPropagation:p,dragDirectionLock:g,onDirectionLock:x,onDrag:v}=this.getProps();if(!p&&!this.openDragLock)return;const{offset:b}=h;if(g&&this.currentDirection===null){this.currentDirection=M4(b),this.currentDirection!==null&&x&&x(this.currentDirection);return}this.updateAxis("x",h.point,b),this.updateAxis("y",h.point,b),this.visualElement.render(),v&&hn.update(()=>v(m,h),!1,!0)},c=(m,h)=>{this.latestPointerEvent=m,this.latestPanInfo=h,this.stop(m,h),this.latestPointerEvent=null,this.latestPanInfo=null},u=()=>{const{dragSnapToOrigin:m}=this.getProps();(m||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:d}=this.getProps();this.panSession=new wN(t,{onSessionStart:i,onStart:a,onMove:l,onSessionEnd:c,resumeAnimation:u},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:d,distanceThreshold:r,contextWindow:yN(this.visualElement),element:this.visualElement.current})}stop(t,s){const r=t||this.latestPointerEvent,o=s||this.latestPanInfo,i=this.isDragging;if(this.cancel(),!i||!o||!r)return;const{velocity:a}=o;this.startAnimation(a);const{onDragEnd:l}=this.getProps();l&&hn.postRender(()=>l(r,o))}cancel(){this.isDragging=!1;const{projection:t,animationState:s}=this.visualElement;t&&(t.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:r}=this.getProps();!r&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),s&&s.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(t,s,r){const{drag:o}=this.getProps();if(!r||!Kl(t,o,this.currentDirection))return;const i=this.getAxisMotionValue(t);let a=this.originPoint[t]+r[t];this.constraints&&this.constraints[t]&&(a=k4(a,this.constraints[t],this.elastic[t])),i.set(a)}resolveConstraints(){const{dragConstraints:t,dragElastic:s}=this.getProps(),r=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,o=this.constraints;t&&ni(t)?this.constraints||(this.constraints=this.resolveRefConstraints()):t&&r?this.constraints=N4(r.layoutBox,t):this.constraints=!1,this.elastic=T4(s),o!==this.constraints&&!ni(t)&&r&&this.constraints&&!this.hasMutatedConstraints&&Zs(i=>{this.constraints!==!1&&this.getAxisMotionValue(i)&&(this.constraints[i]=I4(r.layoutBox[i],this.constraints[i]))})}resolveRefConstraints(){const{dragConstraints:t,onMeasureDragConstraints:s}=this.getProps();if(!t||!ni(t))return!1;const r=t.current,{projection:o}=this.visualElement;if(!o||!o.layout)return!1;o.root&&(o.root.scroll=void 0,o.root.updateScroll());const i=PO(r,o.root,this.visualElement.getTransformPagePoint());let a=S4(o.layout.layoutBox,i);if(s){const l=s(EO(a));this.hasMutatedConstraints=!!l,l&&(a=Wk(l))}return a}startAnimation(t){const{drag:s,dragMomentum:r,dragElastic:o,dragTransition:i,dragSnapToOrigin:a,onDragTransitionEnd:l}=this.getProps(),c=this.constraints||{},u=Zs(d=>{if(!Kl(d,s,this.currentDirection))return;let m=c&&c[d]||{};(a===!0||a===d)&&(m={min:0,max:0});const h=o?200:1e6,p=o?40:1e7,g={type:"inertia",velocity:r?t[d]:0,bounceStiffness:h,bounceDamping:p,timeConstant:750,restDelta:1,restSpeed:10,...i,...m};return this.startAxisValueAnimation(d,g)});return Promise.all(u).then(l)}startAxisValueAnimation(t,s){const r=this.getAxisMotionValue(t);return Tm(this.visualElement,t),r.start(_p(t,r,0,s,this.visualElement,!1))}stopAnimation(){Zs(t=>this.getAxisMotionValue(t).stop())}getAxisMotionValue(t){const s=`_drag${t.toUpperCase()}`,o=this.visualElement.getProps()[s];return o||this.visualElement.getValue(t,this.visualElement.latestValues[t]??0)}snapToCursor(t){Zs(s=>{const{drag:r}=this.getProps();if(!Kl(s,r,this.currentDirection))return;const{projection:o}=this.visualElement,i=this.getAxisMotionValue(s);if(o&&o.layout){const{min:a,max:l}=o.layout.layoutBox[s],c=i.get()||0;i.set(t[s]-mn(a,l,.5)+c)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:t,dragConstraints:s}=this.getProps(),{projection:r}=this.visualElement;if(!ni(s)||!r||!this.constraints)return;this.stopAnimation();const o={x:0,y:0};Zs(a=>{const l=this.getAxisMotionValue(a);if(l&&this.constraints!==!1){const c=l.get();o[a]=C4({min:c,max:c},this.constraints[a])}});const{transformTemplate:i}=this.visualElement.getProps();this.visualElement.current.style.transform=i?i({},""):"none",r.root&&r.root.updateScroll(),r.updateLayout(),this.constraints=!1,this.resolveConstraints(),Zs(a=>{if(!Kl(a,t,null))return;const l=this.getAxisMotionValue(a),{min:c,max:u}=this.constraints[a];l.set(mn(c,u,o[a]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;A4.set(this.visualElement,this);const t=this.visualElement.current,s=wa(t,"pointerdown",u=>{const{drag:d,dragListener:m=!0}=this.getProps(),h=u.target,p=h!==t&&uO(h);d&&m&&!p&&this.start(u)});let r;const o=()=>{const{dragConstraints:u}=this.getProps();ni(u)&&u.current&&(this.constraints=this.resolveRefConstraints(),r||(r=R4(t,u.current,()=>this.scalePositionWithinConstraints())))},{projection:i}=this.visualElement,a=i.addEventListener("measure",o);i&&!i.layout&&(i.root&&i.root.updateScroll(),i.updateLayout()),hn.read(o);const l=Ua(window,"resize",()=>this.scalePositionWithinConstraints()),c=i.addEventListener("didUpdate",(({delta:u,hasLayoutChanged:d})=>{this.isDragging&&d&&(Zs(m=>{const h=this.getAxisMotionValue(m);h&&(this.originPoint[m]+=u[m].translate,h.set(h.get()+u[m].translate))}),this.visualElement.render())}));return()=>{l(),s(),a(),c&&c(),r&&r()}}getProps(){const t=this.visualElement.getProps(),{drag:s=!1,dragDirectionLock:r=!1,dragPropagation:o=!1,dragConstraints:i=!1,dragElastic:a=_m,dragMomentum:l=!0}=t;return{...t,drag:s,dragDirectionLock:r,dragPropagation:o,dragConstraints:i,dragElastic:a,dragMomentum:l}}}function jv(e){let t=!0;return()=>{if(t){t=!1;return}e()}}function R4(e,t,s){const r=A0(e,jv(s)),o=A0(t,jv(s));return()=>{r(),o()}}function Kl(e,t,s){return(t===!0||t===e)&&(s===null||s===e)}function M4(e,t=10){let s=null;return Math.abs(e.y)>t?s="y":Math.abs(e.x)>t&&(s="x"),s}class P4 extends io{constructor(t){super(t),this.removeGroupControls=Ls,this.removeListeners=Ls,this.controls=new E4(t)}mount(){const{dragControls:t}=this.node.getProps();t&&(this.removeGroupControls=t.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Ls}update(){const{dragControls:t}=this.node.getProps(),{dragControls:s}=this.node.prevProps||{};t!==s&&(this.removeGroupControls(),t&&(this.removeGroupControls=t.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const of=e=>(t,s)=>{e&&hn.update(()=>e(t,s),!1,!0)};class D4 extends io{constructor(){super(...arguments),this.removePointerDownListener=Ls}onPointerDown(t){this.session=new wN(t,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:yN(this.node)})}createPanHandlers(){const{onPanSessionStart:t,onPanStart:s,onPan:r,onPanEnd:o}=this.node.getProps();return{onSessionStart:of(t),onStart:of(s),onMove:of(r),onEnd:(i,a)=>{delete this.session,o&&hn.postRender(()=>o(i,a))}}}mount(){this.removePointerDownListener=wa(this.node.current,"pointerdown",t=>this.onPointerDown(t))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let af=!1;class O4 extends f.Component{componentDidMount(){const{visualElement:t,layoutGroup:s,switchLayoutGroup:r,layoutId:o}=this.props,{projection:i}=t;i&&(s.group&&s.group.add(i),r&&r.register&&o&&r.register(i),af&&i.root.didUpdate(),i.addEventListener("animationComplete",()=>{this.safeToRemove()}),i.setOptions({...i.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),Rc.hasEverUpdated=!0}getSnapshotBeforeUpdate(t){const{layoutDependency:s,visualElement:r,drag:o,isPresent:i}=this.props,{projection:a}=r;return a&&(a.isPresent=i,t.layoutDependency!==s&&a.setOptions({...a.options,layoutDependency:s}),af=!0,o||t.layoutDependency!==s||s===void 0||t.isPresent!==i?a.willUpdate():this.safeToRemove(),t.isPresent!==i&&(i?a.promote():a.relegate()||hn.postRender(()=>{const l=a.getStack();(!l||!l.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{visualElement:t,layoutAnchor:s}=this.props,{projection:r}=t;r&&(r.options.layoutAnchor=s,r.root.didUpdate(),$p.postRender(()=>{!r.currentAnimation&&r.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:t,layoutGroup:s,switchLayoutGroup:r}=this.props,{projection:o}=t;af=!0,o&&(o.scheduleCheckAfterUnmount(),s&&s.group&&s.group.remove(o),r&&r.deregister&&r.deregister(o))}safeToRemove(){const{safeToRemove:t}=this.props;t&&t()}render(){return null}}function kN(e){const[t,s]=fN(),r=f.useContext(kp);return n.jsx(O4,{...e,layoutGroup:r,switchLayoutGroup:f.useContext(vN),isPresent:t,safeToRemove:s})}const L4={pan:{Feature:D4},drag:{Feature:P4,ProjectionNode:uN,MeasureLayout:kN}};function kv(e,t,s){const{props:r}=e;e.animationState&&r.whileHover&&e.animationState.setActive("whileHover",s==="Start");const o="onHover"+s,i=r[o];i&&hn.postRender(()=>i(t,jl(t)))}class _4 extends io{mount(){const{current:t}=this.node;t&&(this.unmount=aO(t,(s,r)=>(kv(this.node,r,"Start"),o=>kv(this.node,o,"End"))))}unmount(){}}class B4 extends io{constructor(){super(...arguments),this.isActive=!1}onFocus(){let t=!1;try{t=this.node.current.matches(":focus-visible")}catch{t=!0}!t||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=bl(Ua(this.node.current,"focus",()=>this.onFocus()),Ua(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Nv(e,t,s){const{props:r}=e;if(e.current instanceof HTMLButtonElement&&e.current.disabled)return;e.animationState&&r.whileTap&&e.animationState.setActive("whileTap",s==="Start");const o="onTap"+(s==="End"?"":s),i=r[o];i&&hn.postRender(()=>i(t,jl(t)))}class F4 extends io{mount(){const{current:t}=this.node;if(!t)return;const{globalTapTarget:s,propagate:r}=this.node.props;this.unmount=mO(t,(o,i)=>(Nv(this.node,i,"Start"),(a,{success:l})=>Nv(this.node,a,l?"End":"Cancel")),{useGlobalTarget:s,stopPropagation:r?.tap===!1})}unmount(){}}const Bm=new WeakMap,lf=new WeakMap,z4=e=>{const t=Bm.get(e.target);t&&t(e)},$4=e=>{e.forEach(z4)};function V4({root:e,...t}){const s=e||document;lf.has(s)||lf.set(s,{});const r=lf.get(s),o=JSON.stringify(t);return r[o]||(r[o]=new IntersectionObserver($4,{root:e,...t})),r[o]}function H4(e,t,s){const r=V4(t);return Bm.set(e,s),r.observe(e),()=>{Bm.delete(e),r.unobserve(e)}}const W4={some:0,all:1};class U4 extends io{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.stopObserver?.();const{viewport:t={}}=this.node.getProps(),{root:s,margin:r,amount:o="some",once:i}=t,a={root:s?s.current:void 0,rootMargin:r,threshold:typeof o=="number"?o:W4[o]},l=c=>{const{isIntersecting:u}=c;if(this.isInView===u||(this.isInView=u,i&&!u&&this.hasEnteredView))return;u&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",u);const{onViewportEnter:d,onViewportLeave:m}=this.node.getProps(),h=u?d:m;h&&h(c)};this.stopObserver=H4(this.node.current,a,l)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:t,prevProps:s}=this.node;["amount","margin","root"].some(q4(t,s))&&this.startObserver()}unmount(){this.stopObserver?.(),this.hasEnteredView=!1,this.isInView=!1}}function q4({viewport:e={}},{viewport:t={}}={}){return s=>e[s]!==t[s]}const G4={inView:{Feature:U4},tap:{Feature:F4},focus:{Feature:B4},hover:{Feature:_4}},K4={layout:{ProjectionNode:uN,MeasureLayout:kN}},Y4={...v4,...G4,...L4,...K4},Ns=m4(Y4,h4);function X4(){!qp.current&&$k();const[e]=f.useState(ud.current);return e}const Q4=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],NN=Ge("activity",Q4);const J4=[["circle",{cx:"12",cy:"13",r:"8",key:"3y4lt7"}],["path",{d:"M12 9v4l2 2",key:"1c63tq"}],["path",{d:"M5 3 2 6",key:"18tl5t"}],["path",{d:"m22 6-3-3",key:"1opdir"}],["path",{d:"M6.38 18.7 4 21",key:"17xu3x"}],["path",{d:"M17.64 18.67 20 21",key:"kv2oe2"}]],qa=Ge("alarm-clock",J4);const Z4=[["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"}]],Ga=Ge("archive-restore",Z4);const e_=[["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"}]],lr=Ge("archive",e_);const t_=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],n_=Ge("arrow-down-to-line",t_);const s_=[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]],r_=Ge("arrow-right-left",s_);const o_=[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]],Bi=Ge("arrow-up-right",o_);const i_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M4.929 4.929 19.07 19.071",key:"196cmz"}]],a_=Ge("ban",i_);const l_=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],xd=Ge("bell-off",l_);const c_=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],d_=Ge("bell",c_);const u_=[["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M15 10H9",key:"o6yqo3"}],["path",{d:"M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z",key:"oz39mx"}]],f_=Ge("bookmark-plus",u_);const m_=[["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z",key:"uouzyp"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M21 21a4 4 0 0 0-3.81-4",key:"1b0z45"}],["path",{d:"M21 5a4 4 0 0 1-3.55 3.97",key:"5cxbf6"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M3 21a4 4 0 0 1 3.81-4",key:"1fjd4g"}],["path",{d:"M3 5a4 4 0 0 0 3.55 3.97",key:"1d7oge"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M9 7.13V6a3 3 0 1 1 6 0v1.13",key:"1vgav8"}]],SN=Ge("bug",m_);const h_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],p_=Ge("circle-dot",h_);const x_=[["path",{d:"M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z",key:"kmsa83"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],g_=Ge("circle-play",x_);const v_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],b_=Ge("circle-question-mark",v_);const y_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],w_=Ge("circle-stop",y_);const j_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Jp=Ge("circle",j_);const k_=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]],Zp=Ge("clipboard-check",k_);const N_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],Uo=Ge("clock",N_);const S_=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],C_=Ge("code-xml",S_);const I_=[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]],T_=Ge("code",I_);const A_=[["path",{d:"M13.744 17.736a6 6 0 1 1-7.48-7.48",key:"bq4yh3"}],["path",{d:"M15 6h1v4",key:"11y1tn"}],["path",{d:"m6.134 14.768.866-.5 2 3.464",key:"17snzx"}],["circle",{cx:"16",cy:"8",r:"6",key:"14bfc9"}]],E_=Ge("coins",A_);const R_=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z",key:"9ktpf1"}]],M_=Ge("compass",R_);const P_=[["path",{d:"m15 10 5 5-5 5",key:"qqa56n"}],["path",{d:"M4 4v7a4 4 0 0 0 4 4h12",key:"z08zvw"}]],D_=Ge("corner-down-right",P_);const O_=[["path",{d:"M14 9 9 4 4 9",key:"1af5af"}],["path",{d:"M20 20h-7a4 4 0 0 1-4-4V4",key:"1blwi3"}]],L_=Ge("corner-left-up",O_);const __=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],CN=Ge("cpu",__);const B_=[["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"}]],F_=Ge("database",B_);const z_=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],kl=Ge("ellipsis",z_);const $_=[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],V_=Ge("file-pen",$_);const H_=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]],W_=Ge("file-plus",H_);const U_=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]],q_=Ge("file",U_);const G_=[["path",{d:"M2 12h6",key:"1wqiqv"}],["path",{d:"M22 12h-6",key:"1eg9hc"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m19 9-3 3 3 3",key:"12ol22"}],["path",{d:"m5 15 3-3-3-3",key:"1kdhjc"}]],K_=Ge("fold-horizontal",G_);const Y_=[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]],X_=Ge("folder-git-2",Y_);const Q_=[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]],IN=Ge("folder-input",Q_);const J_=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Fm=Ge("folder-plus",J_);const Z_=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],lu=Ge("folder",Z_);const eB=[["path",{d:"M20 5a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h2.5a1.5 1.5 0 0 1 1.2.6l.6.8a1.5 1.5 0 0 0 1.2.6z",key:"a4852j"}],["path",{d:"M3 8.268a2 2 0 0 0-1 1.738V19a2 2 0 0 0 2 2h11a2 2 0 0 0 1.732-1",key:"yxbcw3"}]],zm=Ge("folders",eB);const tB=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],nB=Ge("funnel",tB);const sB=[["path",{d:"M6 3v12",key:"qpgusn"}],["path",{d:"M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z",key:"1d02ji"}],["path",{d:"M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6z",key:"chk6ph"}],["path",{d:"M15 6a9 9 0 0 0-9 9",key:"or332x"}],["path",{d:"M18 15v6",key:"9wciyi"}],["path",{d:"M21 18h-6",key:"139f0c"}]],rB=Ge("git-branch-plus",sB);const oB=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],Hs=Ge("git-branch",oB);const iB=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]],aB=Ge("git-compare",iB);const lB=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]],cB=Ge("git-merge",lB);const dB=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["line",{x1:"6",x2:"6",y1:"9",y2:"21",key:"rroup"}]],uB=Ge("git-pull-request",dB);const fB=[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]],Sv=Ge("hand",fB);const mB=[["path",{d:"M5 22h14",key:"ehvnwv"}],["path",{d:"M5 2h14",key:"pdyrp9"}],["path",{d:"M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22",key:"1d314k"}],["path",{d:"M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2",key:"1vvvr6"}]],ja=Ge("hourglass",mB);const hB=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],Cv=Ge("house",hB);const pB=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],gd=Ge("image-off",pB);const xB=[["path",{d:"m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16",key:"9kzy35"}],["path",{d:"M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2",key:"1t0f0t"}],["circle",{cx:"13",cy:"7",r:"1",fill:"currentColor",key:"1obus6"}],["rect",{x:"8",y:"2",width:"14",height:"14",rx:"2",key:"1gvhby"}]],gB=Ge("images",xB);const vB=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],ex=Ge("inbox",vB);const bB=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],TN=Ge("list",bB);const yB=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]],wB=Ge("mail",yB);const jB=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],kB=Ge("menu",jB);const NB=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],$m=Ge("message-circle",NB);const SB=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],no=Ge("message-square-plus",SB);const CB=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],IB=Ge("message-square",CB);const TB=[["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"M16 17h6",key:"1ook5g"}],["path",{d:"M21 13V8a2 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.729l7 4a2 2 0 0 0 2 .001l1.675-.955",key:"zu9avd"}],["path",{d:"M3.29 7 12 12l8.71-5",key:"19ckod"}],["path",{d:"m7.5 4.27 8.997 5.148",key:"9yrvtv"}]],AB=Ge("package-minus",TB);const EB=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]],tx=Ge("panel-left-close",EB);const RB=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],AN=Ge("panel-left",RB);const MB=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],PB=Ge("panel-right",MB);const DB=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],EN=Ge("pause",DB);const OB=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]],vd=Ge("pin-off",OB);const LB=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],Ss=Ge("pin",LB);const _B=[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]],BB=Ge("quote",_B);const FB=[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]],zB=Ge("repeat",FB);const $B=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],cu=Ge("send",$B);const VB=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],HB=Ge("sliders-horizontal",VB);const WB=[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]],UB=Ge("square-dashed",WB);const qB=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],GB=Ge("square-pen",qB);const KB=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]],RN=Ge("square-slash",KB);const YB=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],XB=Ge("square-x",YB);const QB=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],JB=Ge("tag",QB);const ZB=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],Fi=Ge("target",ZB);const eF=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M10 12H3",key:"1ulcyk"}],["path",{d:"M10 19H3",key:"108z41"}],["circle",{cx:"17",cy:"15",r:"3",key:"1upz2a"}],["path",{d:"m21 19-1.9-1.9",key:"dwi7p8"}]],MN=Ge("text-search",eF);const tF=[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]],Ka=Ge("undo-2",tF);const nF=[["path",{d:"M16 12h6",key:"15xry1"}],["path",{d:"M8 12H2",key:"1jqql6"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m19 15 3-3-3-3",key:"wjy7rq"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}]],sF=Ge("unfold-horizontal",nF);const rF=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],oF=Ge("unplug",rF);const iF=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],aF=Ge("user-minus",iF);const lF=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],Ya=Ge("user-plus",lF);const cF=[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]],dF=Ge("user-round-check",cF);const uF=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],nx=Ge("user-round",uF);const fF=[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]],mF=Ge("wallet",fF);function hF(e){if(e.length===0)return;const t="0 0, 100% 0, 100% 100%, 0 100%, 0 0",s=e.map(r=>`${pF(r).map(([o,i])=>`${Tv(o)}px ${Tv(i)}px`).join(", ")}, 0 0`);return`polygon(evenodd, ${[t,...s].join(", ")})`}const Iv=6,Tv=e=>Math.round(e*100)/100;function pF({x:e,y:t,width:s,height:r,radius:o=0}){const i=e+s,a=t+r,l=Math.min(o,s/2,r/2);if(l<=0)return[[e,t],[i,t],[i,a],[e,a],[e,t]];const u=[[i-l,t+l,-90],[i-l,a-l,0],[e+l,a-l,90],[e+l,t+l,180]].flatMap(([d,m,h])=>Array.from({length:Iv+1},(p,g)=>{const x=(h+90*g/Iv)*Math.PI/180;return[d+l*Math.cos(x),m+l*Math.sin(x)]}));return[...u,u[0]]}const xF=new Set(["core.filesystem:rm-rf-root-home","core.filesystem:rm-r-f-separate-root-home","core.filesystem:rm-recursive-force-root-home","core.filesystem:find-delete-root-home","core.filesystem:credential-file-write","core.filesystem:fork-bomb","heredoc.posix:pipeline-consumer","system.disk:dd-device","system.disk:mkfs","system.disk:diskutil-erase"]),gF=/^[A-Za-z0-9_.-]+:[A-Za-z0-9_.-]+$/,vF=e=>typeof e=="string"&&e.length<=128&&gF.test(e),bF=e=>vF(e)&&!e.startsWith("enso.")&&!xF.has(e),cf=(e,t)=>e.length>t?`${e.slice(0,t)}…`:e;function yF(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t=e,{status:s,originalCommand:r,rewrittenCommand:o,inputTokens:i,outputTokens:a,reason:l}=t;if(s!=="compressed"&&s!=="unchanged"&&s!=="pending"&&s!=="bypassed"&&s!=="unavailable"||typeof r!="string"||o!==void 0&&typeof o!="string"||l!==void 0&&typeof l!="string")return;const c={status:s,originalCommand:cf(r,16e3)};if(o!==void 0&&(c.rewrittenCommand=cf(o,16e3)),l!==void 0&&(c.reason=cf(l,1e3)),i!==void 0||a!==void 0){if(typeof i!="number"||!Number.isSafeInteger(i)||i<0||typeof a!="number"||!Number.isSafeInteger(a)||a<0)return;c.inputTokens=i,c.outputTokens=a}return c}function wF(e){return(e.needsUser??[]).map(t=>t.trim()).filter(t=>t.length>0)}function jF(e){return e?wF(e.result):[]}function kF(e){return jF(e).length>0}const NF=15e3,SF="enso.windows:temp-root-delete";function Av(e,t){for(let s=t-1;s>=0;s--){const r=e[s];if(r==="@"){const o=s>0?e[s-1]:" ";return o===" "||o===`
|
|
15
|
-
`?e.slice(s+1,t):null}if(r===" "||r===`
|
|
16
|
-
`)return null}return null}function CF(e){const t=Math.max(0,e.containerWidth-e.popupWidth),s=Math.min(Math.max(0,e.anchorLeft),t),r=e.containerWidth-s-e.popupWidth-e.flyoutGap;return{left:s,flyoutSide:r>=e.flyoutWidth?"right":"left"}}function IF(e){if(e.isComposing||e.itemCount===0)return{type:"none"};const t=e.key==="Enter"&&!e.shiftKey||e.key==="Tab";if(e.folderOpen){if(e.key==="Escape"||e.key==="ArrowLeft")return{type:"close-folder"};const s=e.folderItemCount??0;if(s===0)return{type:"none"};const r=e.folderIndex??0;return e.key==="ArrowDown"?{type:"move-folder",index:(r+1)%s}:e.key==="ArrowUp"?{type:"move-folder",index:(r-1+s)%s}:t?{type:"pick"}:{type:"none"}}return e.activeIsFolder&&(e.key==="ArrowRight"||t)?{type:"open-folder"}:e.key==="ArrowDown"?{type:"move",index:(e.activeIndex+1)%e.itemCount}:e.key==="ArrowUp"?{type:"move",index:(e.activeIndex-1+e.itemCount)%e.itemCount}:t?{type:"pick"}:e.key==="Escape"?{type:"close"}:{type:"none"}}function TF(e,t){return`[Referenced past chat "${e.replace(/["[\]\n]/g," ").replace(/\s+/g," ").trim()||"untitled"}" — transcript file: ${t} (pi session jsonl; read it if relevant)]`}const AF=/^\[Referenced past chat "(.+)" — transcript file: (.+) \(pi session jsonl; read it if relevant\)\]$/,EF=/^@(\S.*)$/;function RF(e){let t="";return e.forEach((s,r)=>{const o=e[r-1];t+=s.type==="text"?o?.type==="quote"?s.text.replace(/^[\u00a0 ]/,""):s.text:s.type==="quote"?`${t&&!t.endsWith(`
|
|
17
|
-
`)?`
|
|
18
|
-
`:""}${XI(s)}
|
|
19
|
-
`:s.type==="file"?/\s/.test(s.path)&&!s.path.includes('"')?`@"${s.path}"`:`@${s.path}`:s.type==="chat"?TF(s.label,s.sessionFile):QI(s)}),t}function Ev(e,t){bg.lastIndex=t,yg.lastIndex=t,em.lastIndex=t;const s=bg.exec(e),r=yg.exec(e),o=em.exec(e),i=s?{index:s.index,length:s[0].length,segment:{type:"chat",label:s[1],sessionFile:s[2]}}:null,a=r?YI(r[0]):null,l=r&&a?{index:r.index,length:r[0].length,segment:{type:"ui-element",id:"",...a,imageId:""}}:null;let c=null;if(o){const u=o.index>t&&e[o.index-1]===`
|
|
20
|
-
`?1:0,d=e[o.index+o[0].length]===`
|
|
21
|
-
`?1:0;c={index:o.index-u,length:o[0].length+u+d,segment:{type:"quote",...Vw(o)}}}return[c,i,l].filter(u=>u!==null).sort((u,d)=>u.index-d.index)[0]??null}function Rv(e){const t=[];let s=0;for(const r of e.matchAll(em)){const o=r.index??0,i=o>s&&e[o-1]===`
|
|
22
|
-
`?1:0;o-i>s&&t.push({type:"text",text:e.slice(s,o-i)}),t.push({type:"quote",...Vw(r)}),s=o+r[0].length,e[s]===`
|
|
23
|
-
`&&(s+=1)}return s<e.length?t.push({type:"text",text:e.slice(s)}):t.at(-1)?.type==="quote"&&t.push({type:"text",text:" "}),t}function MF(e){const t=[];let s=0,r=Ev(e,0);for(;r;){const i=e.slice(s,r.index);for(const a of Mv(i))a.type==="text"&&a.text===""||t.push(a);t.push(r.segment),s=r.index+r.length,r=Ev(e,s)}const o=e.slice(s);if(o||t.length===0)for(const i of Mv(o))i.type==="text"&&i.text===""&&t.length>0||t.push(i);return t}const PF=/^(?:[A-Za-z]:[\\/])?(?:[\p{L}\p{N}_./\\-]*\.[\w-]{1,16}(?:#L\d+(?:-L\d+)?)?|[\p{L}\p{N}_./\\-]+[\\/])$/u,DF=/^"([^"\n]*(?:\.[\w-]{1,16}(?:#L\d+(?:-L\d+)?)?|[\\/]))"/,OF=/#L\d+(?:-L\d+)?$/;function LF(e){return e.replace(OF,"")}function du(e){return e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).at(-1)||e}function Mv(e){return Hw(e).flatMap(t=>t.type==="file"?[t]:_F(t.text))}function _F(e){const t=[];let s="",r=0;for(;r<e.length;){const o=e.indexOf("@",r);if(o===-1){s+=e.slice(r);break}const i=o>0?e[o-1]:" ",a=i===" "||i===`
|
|
24
|
-
`?DF.exec(e.slice(o+1)):null;if(a){s+=e.slice(r,o),s&&(t.push({type:"text",text:s}),s=""),t.push({type:"file",path:a[1]}),r=o+1+a[0].length;continue}const c=(/^\S*/.exec(e.slice(o+1))?.[0]??"").replace(/[),.;!?]+$/,"");(i===" "||i===`
|
|
25
|
-
`)&&c&&PF.test(c)?(s+=e.slice(r,o),s&&(t.push({type:"text",text:s}),s=""),t.push({type:"file",path:c}),r=o+1+c.length):(s+=e.slice(r,o+1),r=o+1)}return s&&t.push({type:"text",text:s}),t.length>0?t:[{type:"text",text:e}]}function BF(e){const t={body:e,files:[],chats:[]},s=e.split(`
|
|
26
|
-
`),r=[],o=[];let i=s.length-1;for(;i>=0;i--){const a=s[i],l=AF.exec(a);if(l){o.unshift({label:l[1],sessionFile:l[2]});continue}if(EF.test(a)){r.unshift(a.slice(1));continue}break}return r.length+o.length===0||i<0||s[i].trim()!==""?t:{body:s.slice(0,i).join(`
|
|
27
|
-
`).trimEnd(),files:r,chats:o}}function Pv(e){const t=RF(e.segments).trim(),s=e.segments.filter(o=>o.type!=="text"&&o.type!=="quote").map(o=>o.type==="file"?{kind:"file",id:o.path,label:du(o.path),relativePath:LF(o.path)}:o.type==="chat"?{kind:"chat",id:o.conversationId??o.sessionFile,label:o.label,sessionFile:o.sessionFile}:{kind:"ui-element",id:o.id,label:o.label,path:o.path,text:o.text,imageId:o.imageId});e.recipient&&s.push(e.recipient);const r=e.slashes.join(" ");return{text:r?t?`${r} ${t}`:r:t,images:e.images.map(({data:o,mimeType:i})=>({data:o,mimeType:i})),mentions:s,...e.recipient?{recipient:e.recipient}:{}}}const FF={cover:{backgroundSize:"cover",backgroundRepeat:"no-repeat",backgroundPosition:"center"},contain:{backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"center"},repeat:{backgroundSize:"auto",backgroundRepeat:"repeat",backgroundPosition:"top left"},center:{backgroundSize:"auto",backgroundRepeat:"no-repeat",backgroundPosition:"center"}};function zF(){const e=JI(),t=pe(x=>x.backgroundImageEnabled),s=pe(x=>x.backgroundSourceType),r=pe(x=>x.backgroundImagePath),o=pe(x=>x.backgroundFolderPath),i=pe(x=>x.backgroundUrlPath),a=pe(x=>x.backgroundRandomEnabled),l=pe(x=>x.backgroundRandomInterval),c=pe(x=>x.backgroundRefreshNonce),[u,d]=f.useState(0);f.useEffect(()=>{c>0&&d(x=>x+1)},[c]),f.useEffect(()=>{if(!t||!a||s==="file")return;const x=Math.max(5,l)*1e3,v=window.setInterval(()=>d(b=>b+1),x);return()=>window.clearInterval(v)},[t,a,l,s]);const[m,h]=f.useState([]);f.useEffect(()=>{if(!t||s!=="folder"||!o){h([]);return}let x=!1;return window.electronAPI.files.listMedia(o).then(v=>{x||h(v)}),()=>{x=!0}},[t,s,o,u]);const[p,g]=f.useState("");return f.useEffect(()=>{if(m.length===0){g("");return}g(x=>{if(m.length===1)return m[0];const v=m.filter(b=>b!==x);return v[Math.floor(Math.random()*v.length)]})},[m]),n.jsxs($F,{children:[e?.source==="user"&&n.jsx(VF,{state:{sourceType:s,imagePath:r,folderPick:p,urlPath:i,tick:u},look:e}),e?.source==="theme"&&n.jsxs(ON,{look:e,children:[n.jsx(LN,{image:"var(--enso-asset-background)",look:e}),n.jsx(_N,{mask:e.mask})]})]})}function $F({children:e}){const t=os(r=>r.browserHoles),s=hF(Object.values(t));return f.useLayoutEffect(()=>{const r=document.documentElement;return s?r.style.setProperty("--enso-browser-holes-clip",s):r.style.removeProperty("--enso-browser-holes-clip"),()=>{r.style.removeProperty("--enso-browser-holes-clip")}},[s]),n.jsx("div",{"aria-hidden":!0,"data-slot":"background-layer",className:"pointer-events-none absolute inset-0 -z-10 overflow-hidden",style:{clipPath:s,backgroundColor:"var(--canvas)"},children:e})}const PN=({blur:e,brightness:t,saturation:s})=>`blur(${e}px) brightness(${t}) saturate(${s})`,DN=({blur:e})=>e>0?`-${e*2}px`:"0";function VF({state:e,look:t}){const{sourceType:s,imagePath:r,folderPick:o,urlPath:i,tick:a}=e,l=f.useMemo(()=>{if(s==="file"&&r)return{src:Wc(r),video:Ou(r)};if(s==="folder"&&o)return{src:Wc(o),video:Ou(o)};if(s==="url"){const h=i.trim();if(/^https?:\/\//i.test(h))return{src:ZI(h,a),video:Ou(h)}}return null},[s,r,o,i,a]),[c,u]=f.useState(null);if(f.useEffect(()=>{if(!l){u(null);return}if(l.video){u(l);return}let h=!1;const p=new Image;return p.onload=()=>{h||u(l)},p.src=l.src,()=>{h=!0}},[l]),!c)return null;const{src:d,video:m}=c;return n.jsxs(ON,{look:t,children:[m?n.jsx("video",{src:d,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"absolute",style:{inset:DN(t),width:"auto",height:"auto",minWidth:"100%",minHeight:"100%",objectFit:t.size==="contain"?"contain":"cover",filter:PN(t),transition:"filter 0.3s ease"}},d):n.jsx(LN,{image:`url("${d}")`,look:t},d),n.jsx(_N,{mask:t.mask})]})}function ON({look:e,children:t}){return n.jsx("div",{"data-slot":"background-media",className:"absolute inset-0",style:{opacity:e5(e.opacity).wallpaperOpacity},children:t})}function LN({image:e,look:t}){return n.jsx("div",{className:"absolute",style:{inset:DN(t),backgroundImage:e,...FF[t.size],filter:PN(t),transition:"filter 0.3s ease"}})}function _N({mask:e}){return e<=0?null:n.jsx("div",{"aria-hidden":!0,className:"absolute inset-0",style:{backgroundColor:`color-mix(in oklab, var(--canvas, var(--background)) ${Math.round(Math.min(1,Math.max(0,e))*100)}%, transparent)`}})}function HF({hidden:e,children:t}){return n.jsx("div",{className:_("flex min-h-0 min-w-0 flex-1 flex-col",e&&"invisible"),children:t})}function bd(e,t,s,r){return{left:e,top:t,right:s,bottom:r,x:e,y:t,width:s-e,height:r-t}}function WF(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function BN(e){const t=[];let s,r=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const l of Array.from(e).sort((c,u)=>c.top-u.top)){if(r=Math.min(r,l.left),o=Math.min(o,l.top),i=Math.max(i,l.right),a=Math.max(a,l.bottom),!s||l.top-s.top>s.height/2)t.push(WF(l));else{const c=t[t.length-1];c.left=Math.min(c.left,l.left),c.right=Math.max(c.right,l.right),c.bottom=Math.max(c.bottom,l.bottom),c.width=c.right-c.left,c.height=c.bottom-c.top}s=l}return{lines:t,fallback:bd(r,o,i,a)}}function FN(e,t,s){return e.findIndex(r=>t>r.left-2&&t<r.right+2&&s>r.top-2&&s<r.bottom+2)}function Dv(e){return bd(e.left,e.top,e.right,e.bottom)}function UF(e,t,s){const{lines:r}=BN(e.getClientRects());if(r.length<2)return;const o=FN(r,t,s);return{x:t,y:s,lineIndex:o===-1?void 0:o,element:e}}function qF(e,t,s){const{lines:r,fallback:o}=BN(e.getClientRects());if(r.length<2)return null;const i=s?.x,a=s?.y,l=t[0];if(s?.lineIndex!=null&&r[s.lineIndex])return Dv(r[s.lineIndex]);if(i!=null&&a!=null){const g=FN(r,i,a);if(g!==-1)return Dv(r[g])}if(r.length===2&&r[0].left>r[1].right&&i!=null&&a!=null)return o;if(l==="t"||l==="b"){const g=r[0],x=r[r.length-1],v=l==="t"?g:x;return bd(v.left,g.top,v.right,x.bottom)}const c=l==="l";let u=r[0].left,d=r[0].right,m=c?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY,h=r[0],p=r[0];for(const g of r){u=Math.min(u,g.left),d=Math.max(d,g.right);const x=c?g.left:g.right;c&&x<m||!c&&x>m?(m=x,h=g,p=g):x===m&&(p=g)}return bd(u,h.top,d,p.bottom)}function GF(e){return"contextElement"in e&&e.contextElement?e.contextElement:t5(e)?e:void 0}function KF(e,t){function s(o){zN(e,o.currentTarget,o.clientX,o.clientY)}function r(o){t||s(o)}return{onFocus(){e.current=void 0},onMouseEnter:r,onMouseMove:r}}function zN(e,t,s,r){const o=UF(t,s,r);return e.current=o,o}function YF(e){return{name:"inline",async fn(t){const s=t.elements.reference;if(typeof s?.getClientRects!="function")return{};const r=GF(s),o=e.current,i=o?.element===s||o?.element===r?o:void 0,a=qF(s,t.placement,i);if(!a||typeof t.platform.getElementRects!="function")return{};const l=await t.platform.getElementRects({reference:{contextElement:r,getBoundingClientRect(){return a}},floating:t.elements.floating,strategy:t.strategy});return t.rects.reference.x===l.reference.x&&t.rects.reference.y===l.reference.y&&t.rects.reference.width===l.reference.width&&t.rects.reference.height===l.reference.height?{}:{reset:{rects:l}}}}}const XF={sm:"size-2",md:"size-2.5"},df={sm:"h-3 w-3",md:"h-3.5 w-3.5"};function Nl({tone:e,size:t="sm",title:s,className:r,conversationId:o,"data-enso":i,"data-status":a}){const{t:l}=z();if(e==="waiting"){const c=l("Waiting for your answer");return n.jsx("span",{role:"img","aria-label":c,title:c,"data-slot":"conversation-status","data-tone":e,"data-enso":i,"data-status":a,className:_("flex shrink-0 items-center text-amber-500",r),children:n.jsx(b_,{className:_(df[t],"stroke-[2.5]"),"aria-hidden":!0})})}if(e==="queued"){const c=s??l("Queued");return n.jsxs(bi,{children:[n.jsx(yi,{render:n.jsx("span",{role:"img","aria-label":c,"data-slot":"conversation-status","data-tone":"queued","data-enso":"conversation-queued","data-conversation-id":o,"data-status":a,className:_("flex shrink-0 items-center text-orange-500",r)}),children:n.jsx(qa,{className:_(df[t],"stroke-[2.5]"),"aria-hidden":!0})}),n.jsx(wi,{side:"right","data-enso":"conversation-queued-tooltip",children:c})]})}if(e==="reminder"){const c=s??l("Waiting for reminder");return n.jsxs(bi,{children:[n.jsx(yi,{render:n.jsx("span",{role:"img","aria-label":c,title:c,"data-slot":"conversation-status","data-tone":"reminder","data-enso":i,"data-conversation-id":o,"data-status":a,className:_("flex shrink-0 items-center text-sky-500",r)}),children:n.jsx(Uo,{className:_(df[t],"stroke-[2.2]"),"aria-hidden":!0})}),n.jsx(wi,{side:"right","data-enso":"conversation-reminder-tooltip",children:c})]})}return n.jsx("span",{"data-slot":"conversation-status","data-tone":e,"data-enso":i,"data-status":a,title:s,className:_("shrink-0 rounded-full",XF[t],e==="attention"&&"animate-pulse bg-destructive",e==="running"&&"animate-pulse bg-brand",e==="failed"&&"bg-destructive",e==="unread"&&"bg-green-500",e==="idle"&&"border border-muted-foreground/50",r)})}const QF="Let's set you up. Ask me a few questions about what to call me, which model you should use, and how much you may do on your own. Then submit the draft with secretary_profile_propose and wait for my confirmation.",Yl={enabled:!1,projectId:null,profile:null,persona:"",board:{needsYou:[],running:[],done:[],todos:[]},proposals:{},takeovers:[]};function uf(e,t){return t&&e.some(s=>s.id===t)?t:e[0]?.id??null}function Ov(e){qw(Object.values(e).flatMap(t=>t.takeovers.map(s=>s.conversationId)))}function JF(e){return e?kt.getState().secretaries.find(t=>t.projectId===e)?.id??null:null}const kt=ro()((e,t)=>({secretary:Yl,secretaries:[],states:{},focusedId:null,resolving:{},welcomeOpen:!1,focusProposal:null,focus:s=>{const{states:r,focusedId:o}=t();o===s&&r[s]||(e({focusedId:s,secretary:r[s]??Yl,welcomeOpen:!1}),r[s]||t().reload(s))},reload:async s=>{const r=s??t().focusedId;if(!r)return;const o=await window.electronAPI.secretary.getState(r).catch(()=>null);o&&e(i=>({states:{...i.states,[r]:o},...i.focusedId===r?{secretary:o}:{}}))},createSecretary:async()=>{const s=await window.electronAPI.secretary.create();if(!s.ok)return null;const r=await window.electronAPI.secretary.list();return e({secretaries:r}),t().focus(s.secretaryId),e({welcomeOpen:!0}),s.secretaryId},openWelcome:()=>e({welcomeOpen:!0}),closeWelcome:()=>e({welcomeOpen:!1}),focusProposalCard:s=>e({focusProposal:{proposalId:s,at:Date.now()}}),clearFocusProposal:()=>e({focusProposal:null}),bind:()=>{const s=new Set;let r=!0;const o=u=>{const d=u.secretaryId??t().focusedId;d&&e(m=>{const h={...m.states,[d]:u};Ov(h);const p=uf(m.secretaries,m.focusedId)??d;if(p!==d)return{states:h,focusedId:p};const g=m.states[d]??m.secretary;return{states:h,focusedId:p,secretary:u,welcomeOpen:u.profile?!1:g.profile!==null&&g.enabled?!0:m.welcomeOpen}})},i=window.electronAPI.secretary.onStateChanged(u=>{u.secretaryId&&s.add(u.secretaryId),o(u)}),a=window.electronAPI.secretary.onListChanged(u=>{wg(u.map(d=>d.id)),e(d=>{const m=new Set(u.map(g=>g.id)),h=Object.fromEntries(Object.entries(d.states).filter(([g])=>m.has(g))),p=uf(u,d.focusedId);return Ov(h),{secretaries:u,states:h,focusedId:p,secretary:p&&h[p]||(p===d.focusedId?d.secretary:Yl)}})});window.electronAPI.secretary.list().then(async u=>{if(r){wg(u.map(d=>d.id)),e(d=>({secretaries:u,focusedId:uf(u,d.focusedId)}));for(const d of u){const m=await window.electronAPI.secretary.getState(d.id);!r||s.has(d.id)||o({...m,secretaryId:m.secretaryId??d.id})}}}).catch(()=>{});const l=window.electronAPI.secretary.onOpenConversation(u=>{J.getState().selectConversation(u.conversationId),os.getState().ensureOpen(u.conversationId),u.proposalId&&t().focusProposalCard(u.proposalId)}),c=J.subscribe((u,d)=>{if(u.activeId===d.activeId)return;const m=u.activeId?u.conversations[u.activeId]?.projectId:void 0,h=JF(m);h&&t().focus(h)});return()=>{r=!1,i(),a(),l(),c(),qw([]),e({secretary:Yl,secretaries:[],states:{},focusedId:null,welcomeOpen:!1,focusProposal:null})}},newSecretaryConversation:async s=>{const{states:r,secretary:o,secretaries:i}=t(),a=s?.secretaryId?r[s.secretaryId]:o;s?.secretaryId&&t().focus(s.secretaryId);const l=a?.projectId??(s?.secretaryId?i.find(p=>p.id===s.secretaryId)?.projectId:null);if(!l)return null;const u=pe.getState().projects.find(p=>p.id===l);if(!u)return null;const d=s?.greeting?ZF(l):null;if(s?.greeting&&!d)return null;const m=J.getState(),h=await m.newConversation(l);if(!h)return null;if(d){const p=Ww(pe.getState().language);await m.send(Uw(p,QF),{...d,cwd:u.path},void 0,h)}return h},resolveProposal:async(s,r,o,i)=>{e({resolving:{...t().resolving,[s]:!0}});try{await window.electronAPI.secretary.resolveProposal(s,r,o,i)}catch{}finally{const a={...t().resolving};delete a[s],e({resolving:a})}}}));function ZF(e){const t=pe.getState(),s=t.projects.find(o=>o.id===e);if(!s)return null;const r=tm({defaultModel:t.defaultModel,...sm(s,t.projectGroups),providers:Gw(),credentials:nm(zo.getState().snapshot),virtualModels:t.virtualModels});return r.source==="none"?null:{providerId:r.providerId,modelId:r.modelId}}const hs=ro(()=>({modHeld:!1,headerMounted:!1,activeIds:[],slots:[],dismissed:{}}));function e8(e){hs.setState(t=>({dismissed:{...t.dismissed,[e]:Date.now()}}))}function t8(e){const{dismissed:t}=hs.getState();if(!(e in t))return;const{[e]:s,...r}=t;hs.setState({dismissed:r})}const Lv=(e,t)=>e.length===t.length&&e.every((s,r)=>s===t[r]);function n8(e,t){const s=hs.getState();Lv(s.activeIds,e)&&Lv(s.slots,t)||hs.setState({activeIds:e,slots:t})}const ai=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Xl=e=>typeof e=="number"&&Number.isFinite(e);function Sl(e){if(!ai(e)||!ai(e.queuedStart))return;const t=e.queuedStart;if(!Xl(t.queuedAt)||typeof t.text!="string")return;const s=Array.isArray(t.attachments)?t.attachments.filter(i=>typeof i=="string"):[],r=ai(t.askRelay)&&typeof t.askRelay.name=="string"?{name:t.askRelay.name}:void 0,o=ai(t.failed)&&Xl(t.failed.at)&&typeof t.failed.error=="string"?{at:t.failed.at,error:t.failed.error}:void 0;return{queuedAt:t.queuedAt,text:t.text,...typeof t.goal=="string"&&t.goal?{goal:t.goal}:{},...s.length>0?{attachments:s}:{},...r?{askRelay:r}:{},...Xl(t.startingAt)?{startingAt:t.startingAt}:{},...o?{failed:o}:{},...typeof t.retryCount=="number"&&Number.isInteger(t.retryCount)&&t.retryCount>0?{retryCount:t.retryCount}:{},...Xl(t.nextRetryAt)?{nextRetryAt:t.nextRetryAt}:{},...typeof t.lastError=="string"&&t.lastError?{lastError:t.lastError}:{}}}function s8(e){const t=ai(e)&&ai(e.secretaryOrigin)?e.secretaryOrigin:void 0;return typeof t?.secretaryId=="string"?t.secretaryId:""}function uu(e){const t=new Map;for(const[r,o]of Object.entries(e)){const i=Sl(o);if(!i||i.failed)continue;const a=s8(o),l=t.get(a)??[];l.push({id:r,at:i.queuedAt}),t.set(a,l)}const s=new Map;for(const r of t.values()){r.sort((o,i)=>o.at-i.at||o.id.localeCompare(i.id));for(const[o,i]of r.entries())s.set(i.id,o+1)}return s}function r8(e){return e.messages.at(-1)?.timestamp??e.lastActiveAt}function o8(e,t){const s=Sl(e);return{id:e.id??"",title:e.title,status:e.status??"idle",spawning:e.spawning===!0,hasRunningChild:t,pinned:e.pinned,archived:e.archived,archivedAt:e.archivedAt,muted:e.muted,createdAt:e.createdAt,projectId:e.projectId,lastActiveAt:r8(e),messages:[],forkedFromConversationId:e.forkedFromConversationId,unread:e.unread,activeRenewedAt:e.activeRenewedAt,pendingAsks:e.pendingAsks,pendingApprovals:e.pendingApprovals,coworkerIds:e.coworkerIds,coworkerName:e.coworkerName,child:e.child,subagents:e.subagents,backgroundTasks:e.backgroundTasks?.map(({status:r})=>({status:r})),parentId:e.parentId,sessionFile:e.sessionFile,worktree:e.worktree,secretaryOrigin:e.secretaryOrigin,...e.goal?{goal:{status:e.goal.status,...e.goal.retry?{retry:e.goal.retry}:{}}}:{},...s?{queued:!s.failed,...s.failed?{queueFailed:s.failed.error}:{}}:{}}}function i8(e){return JSON.stringify(e)}let vr=null;function fu(e){if(vr?.source===e)return vr.value;const t={},s=[],r=uu(e);for(const[o,i]of Object.entries(e)){if(!i||i.btwParentId)continue;const a=o8(i,Ah({status:i.status??"idle",spawning:i.spawning,subagents:i.subagents,coworkerIds:i.coworkerIds,backgroundTasks:i.backgroundTasks},e)),l=a.queued?r.get(o):void 0;l&&(a.queuePosition=l),t[o]=a,s.push(`${o}:${i8(a)}`)}return vr&&vr.prints.length===s.length&&vr.prints.every((o,i)=>o===s[i])?(vr={source:e,prints:s,value:vr.value},vr.value):(vr={source:e,prints:s,value:t},t)}let Xi=null;function a8(e){if(Xi?.source===e)return Xi.value;const t=[];for(const[o,i]of Object.entries(e))!i||i.parentId||i.btwParentId||!i.sessionFile||t.push({id:i.id??o,title:i.title,projectId:i.projectId,sessionFile:i.sessionFile,createdAt:i.createdAt});const s=JSON.stringify(t),r=Xi?.print===s?Xi.value:t;return Xi={source:e,print:s,value:r},r}const l8=[],_v=new WeakMap;function c8(e,t){const s=e[t];if(!s)return l8;const r=_v.get(s);if(r?.source===e)return r.value;const o=(s.coworkerIds??[]).flatMap(l=>{const c=e[l];return c?[{id:c.id??l,title:c.title,status:c.status??"idle",spawning:c.spawning===!0,pendingApprovalCount:c.pendingApprovals?.length??0,pendingAskCount:Po(c.pendingAsks),coworkerName:c.coworkerName,child:c.child?.agentInstanceName?{agentInstanceName:c.child.agentInstanceName}:void 0,mode:c.child?.mode==="task"?"task":"coworker",reloading:c.reloading===!0}]:[]}),i=JSON.stringify(o),a=r?.print===i?r.value:o;return _v.set(s,{source:e,print:i,value:a}),a}function d8({onNew:e}){const{t}=z(),s=hs(g=>g.activeIds),r=hs(g=>g.slots),o=hs(g=>g.modHeld),i=J(g=>fu(g.conversations)),a=J(g=>g.activeId),l=J(g=>g.selectConversation),c=f.useRef(null),[u,d]=f.useState({left:0,right:0});f.useEffect(()=>(hs.setState({headerMounted:!0}),()=>hs.setState({headerMounted:!1})),[]),f.useLayoutEffect(()=>{const g=c.current,x=document.querySelector('[data-enso="main"]');if(!g||!x)return;const v=()=>{const w=g.getBoundingClientRect(),j=x.getBoundingClientRect(),T=Math.max(0,Math.round(j.left-w.left)),N=Math.max(0,Math.round(w.right-j.right));d(S=>S.left===T&&S.right===N?S:{left:T,right:N})};v();const b=new ResizeObserver(v);return b.observe(x),b.observe(g),()=>b.disconnect()},[]),f.useEffect(()=>{a&&(t8(a),c.current?.querySelector(`[data-session-tab="${CSS.escape(a)}"]`)?.scrollIntoView({block:"nearest",inline:"nearest"}))},[a]);const m=s.filter(g=>i[g]),h=g=>{if(g===a){const x=m.indexOf(g),v=m[x+1]??m[x-1];if(!v)return;l(v)}e8(g)},p=g=>g!==a||m.length>1;return n.jsxs("div",{ref:c,"data-enso":"header-session-tabs",className:"flex h-full min-w-0 flex-1 items-center gap-1",style:{paddingLeft:u.left,paddingRight:u.right},children:[m.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex min-w-0 items-center gap-1 overflow-x-auto [scrollbar-width:none]",children:m.map(g=>{const x=r.indexOf(g);return n.jsx(u8,{id:g,conversation:i[g],active:g===a,hint:o&&x>=0&&x<9?qs(`mod+${x+1}`):void 0,untitled:t("New conversation"),closeLabel:t("Remove from title bar"),onSelect:l,onClose:p(g)?h:void 0},g)})}),n.jsx("button",{type:"button",className:"no-drag flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-foreground/[0.06] hover:text-foreground",onClick:e,title:t("New conversation"),"aria-label":t("New conversation"),children:n.jsx(Qn,{className:"size-3.5"})})]}),n.jsx("div",{"aria-hidden":!0,className:"drag-region h-full min-w-2 flex-1"})]})}function u8({id:e,conversation:t,active:s,hint:r,untitled:o,closeLabel:i,onSelect:a,onClose:l}){const{t:c}=z(),u=(t.pendingApprovals?.length??0)>0?"attention":Bd({status:t.queueFailed?"failed":t.status,spawning:t.spawning,unread:t.unread,pendingAskCount:Po(t.pendingAsks),hasRunningChild:t.hasRunningChild,queued:t.queued===!0&&!t.queueFailed}),d=t.title||o,m=t.queueFailed?t.queueFailed:t.queued?c("Queued · #{{n}}, starts automatically when a slot opens",{n:t.queuePosition??1}):void 0,h=kt(x=>x.secretaries.find(v=>v.projectId===t.projectId)?.id??null),p=kt(x=>x.secretary.enabled?h?(x.states[h]??(x.focusedId===h?x.secretary:null))?.profile??x.secretaries.find(b=>b.id===h)??null:x.secretary.projectId===t.projectId?x.secretary.profile:null:null),g=p?.avatar;return n.jsxs("div",{"data-session-tab":e,"data-active":s||void 0,className:_("group/tab no-drag box-border flex h-7 w-[202.5px] min-w-[80px] shrink items-center rounded-md border-[0.5px] border-foreground/10 text-[0.8125rem] transition-colors",s?"bg-background text-foreground":"bg-foreground/[0.04] text-muted-foreground hover:bg-foreground/[0.07] hover:text-foreground"),onAuxClick:x=>{x.button===1&&l&&l(e)},children:[n.jsxs("button",{type:"button",className:_("flex h-full min-w-0 flex-1 items-center gap-1.5 pl-2.5",l?"pr-1":"pr-2.5"),onClick:()=>a(e),title:d,children:[n.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:p&&g?n.jsx(Fd,{name:p.name??"",color:g.color,image:g.imageVersion?ll(g.imageVersion,g.imageHash,h??void 0):void 0,enso:"secretary-tab-avatar",className:"size-3.5 rounded-[4px] text-[8px]"}):u==="idle"?n.jsx(IB,{className:"size-3"}):n.jsx(Nl,{tone:u,size:"sm",title:m,conversationId:e})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:d}),r&&n.jsx("span",{className:"shrink-0 text-[10px] leading-none text-subtle-foreground tabular-nums",children:r})]}),l&&n.jsx("button",{type:"button",className:_("mr-1 flex size-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:bg-foreground/[0.08] hover:text-foreground focus-visible:opacity-100",s?"opacity-100":"opacity-0 group-hover/tab:opacity-100"),onClick:()=>l(e),title:i,"aria-label":i,children:n.jsx(Jt,{className:"size-3"})})]})}let ka=null,Na=null,Sa=null,Ca=null,Ia=null,Ta=null,fi=null,Aa=null,Ea=null;function f8(e){return ka=e,()=>{ka===e&&(ka=null)}}function m8(e){return Ca=e,()=>{Ca===e&&(Ca=null)}}function h8(e){return Na=e,()=>{Na===e&&(Na=null)}}function zi(){return Ca?(Ca(),!0):!1}function p8(e){return Sa=e,()=>{Sa===e&&(Sa=null)}}function x8(e){return Sa?(Sa(e),!0):!1}function g8(e){return Ea=e,()=>{Ea===e&&(Ea=null)}}function v8(e){return Ea?Ea(e):!1}function Bv(e){return ka?(ka(e),!0):!1}function $N(e){return Na?(Na(e),!0):!1}function b8(e){return Ia=e,()=>{Ia===e&&(Ia=null)}}function sx(e,t){return Ia?(Ia(e,t),!0):!1}function y8(e){return Ta=e,()=>{Ta===e&&(Ta=null)}}function w8(e){return Ta?(Ta(e),!0):!1}function j8(e){return fi=e,()=>{fi===e&&(fi=null)}}function k8(){return fi!==null}function N8(e){return fi?(fi(e),!0):!1}function S8(e){return Aa=e,()=>{Aa===e&&(Aa=null)}}function C8(e){return Aa?(Aa(e),!0):!1}const yd=10;function I8(e){const t=new Set,s=[];let r=0,o=0;for(const i of e){const a=i.path.trim();if(a){if(!i.isDirectory){r+=1;continue}t.has(a)||(t.add(a),o+=1,s.length<yd&&s.push(a))}}return{directories:s,skippedFiles:r,truncated:o>yd}}function T8(e,t){const s=a=>{try{return t(a).trim()}catch{return""}},r=a=>a.size===0&&a.type==="",o=[],i=e.items;if(i&&i.length>0){for(let a=0;a<i.length;a+=1){const l=i[a];if(l.kind!=="file")continue;const c=l.getAsFile();if(!c)continue;const u=s(c);if(!u)continue;const d=l.webkitGetAsEntry?.();o.push({path:u,isDirectory:d?d.isDirectory:r(c),file:c})}return o}for(const a of Array.from(e.files??[])){const l=s(a);l&&o.push({path:l,isDirectory:r(a),file:a})}return o}function A8(e){const t=I8(e);if(t.directories.length>0)return{kind:"projects",...t};const s=new Set,r=[],o=[];for(const i of e){const a=i.path.trim();!a||i.isDirectory||s.has(a)||(s.add(a),r.push(i.file),o.push(a.split(/[\\/]/).filter(Boolean).at(-1)??a))}return r.length>0?{kind:"files",files:r,names:o}:null}const E8=150;function R8(e,t=E8){let s=0,r=!1,o;const i=()=>{o!==void 0&&(clearTimeout(o),o=void 0)},a=()=>{i(),s=0,r&&(r=!1,e(!1))},l=()=>{r||(r=!0,e(!0)),i(),o=setTimeout(a,t)};return{enter(c){c&&(s+=1,l())},over(c){c&&(s=Math.max(s,1),l())},leave(){r&&(s=Math.max(0,s-1),s===0&&a())},cancel:a,dispose:i}}function M8(e){const t=e.archivedIds.filter(o=>o!==e.projectId),s={...e.collapsed},r=e.knownIds.has(e.projectId);return r&&s[e.projectId]===!0&&(s[e.projectId]=!1),r&&e.latestConversationId?{archivedIds:t,collapsed:s,focus:{kind:"select",conversationId:e.latestConversationId}}:{archivedIds:t,collapsed:s,focus:{kind:"new"}}}const Mc="enso-project-order",Vm="enso-pinned-order",jr="enso-archived-projects",Fv="enso-pinned-projects",Hm=new Set;function sr(e){try{const t=JSON.parse(localStorage.getItem(e)??"[]");return Array.isArray(t)?t:[]}catch{return[]}}function Hr(e,t){localStorage.setItem(e,JSON.stringify(t));for(const s of Hm)s()}function VN(e){return Hm.add(e),()=>Hm.delete(e)}const HN="enso-collapsed-projects",Wm="enso-collapsed-projects-changed";function Um(){try{const e=JSON.parse(localStorage.getItem(HN)??"{}");return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function P8(e){return window.addEventListener(Wm,e),()=>window.removeEventListener(Wm,e)}function D8(e){localStorage.setItem(HN,JSON.stringify(e)),window.dispatchEvent(new Event(Wm))}function O8(){try{const e=localStorage.getItem("enso-selected-project-group");return e?pe.getState().projectGroups.find(t=>t.id===e)?.id:void 0}catch{return}}function L8(e,t){return e.length===t.length&&e.every((s,r)=>s===t[r])}function _8(e){const t=e instanceof Error?e.message:String(e);return/not a directory/i.test(t)||/ENOENT|no such file/i.test(t)}function B8(e){const t=e instanceof Error?e.message:String(e);return/not a directory/i.test(t)}let ff=Promise.resolve();function qm(e){return ff=ff.then(e).catch(()=>{}),ff}async function WN(e,t){const s=pe.getState(),r=new Set(s.projects.map(l=>l.id)),o=await s.addProject(e,void 0,t??O8());if(!o)return;const i=J.getState(),a=M8({projectId:o.id,knownIds:r,archivedIds:sr(jr),collapsed:Um(),latestConversationId:Eo(i.order,i.conversations,o.id)[0]});return L8(sr(jr),a.archivedIds)||Hr(jr,a.archivedIds),JSON.stringify(Um())!==JSON.stringify(a.collapsed)&&D8(a.collapsed),{project:o,focus:a.focus}}async function UN(e,t){const s=J.getState();if(e.focus.kind==="select"){await(t??s.selectConversation)(e.focus.conversationId);return}if(!await s.newConversation(e.project.id))throw new Error("Failed to create a conversation for the project.")}async function qN(e,t={}){const s=await WN(e,t.groupId);if(s)return await UN(s,t.onSelect),s.project}const zv="enso-mode",Er=ro()(e=>({mode:localStorage.getItem(zv)==="bot"?"bot":"code",setMode:t=>{localStorage.setItem(zv,t),e({mode:t})}}));function $v(){return pe.getState().botModeEnabled&&Er.getState().mode==="bot"}function F8(){const e=pe(s=>s.botModeEnabled),t=Er(s=>s.mode);return e&&t==="bot"}async function z8(e){if(!pe.getState().botModeEnabled)return;const t=typeof e.chatId=="string"?e.chatId:void 0,s=typeof e.conversationId=="string"?e.conversationId:void 0,r=ie.getState();t||await r.refreshDelegations(),Er.getState().setMode("bot");const o=n5({chatId:t,conversationId:s},ie.getState().delegations);if(o.kind==="chat"){const i=r.chats.find(a=>a.id===o.chatId);i?.kind==="group"&&r.openThread(i.parentId??i.id,i.id)}r.setView(o)}function rx(){Er.getState().setMode("code")}const $8=200,V8=15;function H8(e){return window.electronAPI.files.pathForFile(e)}function W8(e){const t=new Set;return e.filter(s=>!t.has(s.path)&&t.add(s.path)).map(s=>s.file)}async function Vv(e,t,s){let r=t,o;for(const i of e)try{o=await WN(i)??o}catch(a){if(B8(a)){r+=1;continue}if(_8(a))continue;Ie({type:"error",title:s("Failed to add project"),description:a instanceof Error?a.message:String(a)})}if(o)try{await UN(o),rx()}catch(i){Ie({type:"error",title:s("Failed to add project"),description:i instanceof Error?i.message:String(i)})}r>0&&Ie({type:"info",title:s("Only folders can be added as projects")})}function U8(){const{t:e}=z(),[t,s]=f.useState(!1),[r,o]=f.useState(null);Eh(t),f.useEffect(()=>{const c=window.electronAPI;if(c.remote)return;let u=!1,d;const m=(g,x)=>{if(!(u||C8(g))){if(x>=V8){Ie({type:"info",title:e("Open a conversation to add files")});return}d=window.setTimeout(()=>m(g,x+1),$8)}},h=()=>{c.files.takeShelfDrop().then(g=>{for(const{action:x,paths:v,skipped:b=0}of g)if(x==="project"){const w=v.slice(0,yd);qm(()=>Vv(w,b,e))}else v.length>0&&m(v,0)})};h();const p=c.files.onShelfDrop(h);return()=>{u=!0,window.clearTimeout(d),p()}},[e]),f.useEffect(()=>{const c=document.documentElement;return c.toggleAttribute("data-file-dragging",t),()=>c.removeAttribute("data-file-dragging")},[t]),f.useEffect(()=>{if(window.electronAPI.remote)return;const c=R8(s),u=v=>Array.from(v.dataTransfer?.types??[]).includes("Files"),d=v=>{u(v)&&(v.preventDefault(),c.enter(!0))},m=v=>{u(v)&&(v.preventDefault(),c.over(!0))},h=()=>c.leave(),p=()=>c.cancel(),g=v=>{v.key==="Escape"&&c.cancel()},x=v=>{if(!u(v)||v.defaultPrevented)return;v.preventDefault();const b=T8(v.dataTransfer??{},H8),w=A8(b);if(!w)return;const j=k8();if(w.kind==="files"&&!j){Ie({type:"info",title:e("Open a conversation to add files")});return}o({plan:w,attach:j?W8(b):[]})};return window.addEventListener("dragenter",d,!0),window.addEventListener("dragover",m,!0),window.addEventListener("dragleave",h,!0),window.addEventListener("drop",p,!0),window.addEventListener("drop",x),window.addEventListener("dragend",p,!0),window.addEventListener("blur",p),window.addEventListener("keydown",g,!0),()=>{window.removeEventListener("dragenter",d,!0),window.removeEventListener("dragover",m,!0),window.removeEventListener("dragleave",h,!0),window.removeEventListener("drop",p,!0),window.removeEventListener("drop",x),window.removeEventListener("dragend",p,!0),window.removeEventListener("blur",p),window.removeEventListener("keydown",g,!0),c.dispose()}},[e]);const i=r?.plan,a=()=>{r&&N8(r.attach),o(null)},l=()=>{if(i?.kind==="projects"){const{directories:c,skippedFiles:u}=i;qm(()=>Vv(c,u,e))}o(null)};return n.jsxs(n.Fragment,{children:[t&&n.jsxs("div",{className:"pointer-events-none fixed inset-0 flex items-center justify-center bg-background/70 backdrop-blur-[2px]",style:{zIndex:Pn.MODAL_BACKDROP},children:[n.jsx("div",{className:"absolute inset-3 rounded-2xl border-2 border-dashed border-brand"}),n.jsxs("div",{className:"flex flex-col items-center gap-3 text-brand",children:[n.jsx(Fm,{className:"h-10 w-10"}),n.jsx("p",{className:"text-sm font-medium",children:e("Release to add")})]})]}),n.jsx(cn,{open:r!==null,onOpenChange:c=>!c&&o(null),children:n.jsxs(dn,{className:"max-w-md",showCloseButton:!1,children:[n.jsxs(un,{children:[n.jsx(rn,{children:i?.kind==="files"?e("Add to current conversation"):i&&i.directories.length>1?e("Add {{count}} projects",{count:i.directories.length}):e("Open as project")}),n.jsx(ys,{className:"break-all",children:i?.kind==="files"?i.names.join(", "):i?.directories[0]}),i?.kind==="projects"&&i.truncated&&n.jsx("p",{className:"text-xs text-muted-foreground",children:e("At most {{count}} folders can be added at once",{count:yd})})]}),n.jsxs(ts,{children:[n.jsx(s5,{render:n.jsx(fe,{variant:"outline",size:"sm"}),children:e("Cancel")}),i?.kind==="files"?n.jsx(fe,{size:"sm",onClick:a,children:e("Add to current conversation")}):n.jsxs(n.Fragment,{children:[r&&r.attach.length>0&&n.jsx(fe,{variant:"outline",size:"sm",onClick:a,children:e("Add to current conversation")}),n.jsx(fe,{size:"sm",onClick:l,children:i&&i.directories.length>1?e("Add all"):e("Open as project")})]})]})]})})]})}const q8=2e4,G8=18e4;function GN({children:e}){return n.jsx("div",{className:"border-b border-blue-500/20 bg-background",children:n.jsx("div",{className:"flex items-center gap-2 bg-blue-500/8 px-4 py-1.5 text-xs",children:e})})}const K8={restart:"EnsoCode will restart once the current command finishes.",update:"EnsoCode will install the update once the current command finishes.",quit:"EnsoCode will quit once the current command finishes."},Y8={restart:"Restarting once the current command finishes",update:"Installing the update once the current command finishes",quit:"Quitting once the current command finishes"},Cl=ro(()=>({state:null,shown:{phase:"restarting"},forcing:!1,minimized:!1}));function Hv(e,t){Cl.setState(s=>({state:e,shown:e??s.shown,forcing:t?!1:s.forcing,minimized:s.minimized&&e?.phase==="waiting"}))}function KN(){Cl.setState({forcing:!0}),window.electronAPI.app.forceRestart()}const Gm=e=>Cl.setState({minimized:e}),X8=5;function Q8(e,t){const s=t.indexOf("::"),r=s!==-1,o=r?t.slice(0,s):t;return{title:e[o]?.title.trim()||t.slice(0,8),child:r}}function J8(e,t,s){if(t.kind==="tool"){const r=t.tools?.join(", ")??"";return s?e("A subagent is running {{tool}}",{tool:r}):e("Running {{tool}}",{tool:r})}return t.kind==="background"?e(s?"A subagent still has a background command running":"A background command is still running"):t.kind==="reply"?e(s?"A subagent is writing a reply":"Writing a reply"):t.kind==="starting"?e(s?"A subagent is opening the session":"Opening the session"):e(s?"A subagent is finishing the turn":"Finishing the turn")}function Z8({blockers:e}){const{t}=z(),s=J(i=>i.conversations);if(!e?.length)return null;const r=e.slice(0,X8),o=e.length-r.length;return n.jsxs("ul",{className:"mt-2 space-y-0.5 text-left text-xs text-muted-foreground",children:[r.map(i=>{const{title:a,child:l}=Q8(s,i.sessionId);return n.jsxs("li",{children:[a," — ",J8(t,i,l)]},i.sessionId)}),o>0?n.jsx("li",{children:t("{{count}} more sessions",{count:o})}):null]})}function ez(){const{t:e}=z(),{state:t,shown:s,forcing:r,minimized:o}=Cl();f.useEffect(()=>{if(window.electronAPI.remote)return;let l=!1;const c=window.electronAPI.app.onRestartWaiting(u=>{l=!0,Hv(u,!0)});return window.electronAPI.app.getRestartWaiting().then(u=>{l||Hv(u,!1)}),c},[]);const i=s.phase==="waiting",a=i&&s.reason==="reply";return n.jsx(Rh,{open:t!==null&&!o,children:n.jsxs(Mh,{className:"sm:max-w-sm",children:[n.jsxs(Ph,{children:[n.jsxs(Dh,{className:"flex items-center gap-2 text-base",children:[n.jsx(di,{className:"size-4 text-muted-foreground"}),i?e(a?"Waiting for the current reply to finish":"Waiting for the current command to finish"):s.phase==="resuming"?e("Restoring sessions…"):e("Restarting EnsoCode…")]}),i&&n.jsxs(n.Fragment,{children:[n.jsxs(Oh,{children:[a?e("A session is still writing its reply. EnsoCode waits up to {{minutes}} minutes; if it stops producing output for more than {{idle}} seconds, it is stopped first and continues automatically after the restart.",{minutes:G8/6e4,idle:q8/1e3}):e(K8[s.exit]),s.reason==="background-not-detachable"&&n.jsxs(n.Fragment,{children:[" ",e("A command moved to the background cannot keep running without EnsoCode (for example a remote or Windows command), so EnsoCode waits for it.")]})]}),n.jsx(Z8,{blockers:s.blockers})]})]}),i&&n.jsxs(Lh,{variant:"bare",children:[n.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>Gm(!0),children:e("Minimize")}),n.jsx(fe,{variant:"destructive",size:"sm",disabled:r,onClick:KN,children:e("Force quit")})]})]})})}function Wv(){const{t:e}=z(),{state:t,forcing:s,minimized:r}=Cl();return!r||t?.phase!=="waiting"?null:n.jsxs(GN,{children:[n.jsx(di,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),n.jsxs("button",{type:"button",onClick:()=>Gm(!1),className:"min-w-0 flex-1 truncate text-left",children:[e(Y8[t.exit]),t.blockers?.length?e(" · waiting for {{count}} sessions",{count:t.blockers.length}):""]}),n.jsx("button",{type:"button",disabled:s,onClick:KN,className:"shrink-0 rounded-md bg-destructive px-2.5 py-1 text-white transition-colors hover:bg-destructive/90 disabled:opacity-60",children:e("Force quit")}),n.jsx("button",{type:"button",onClick:()=>Gm(!1),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",title:e("Expand"),children:n.jsx(r5,{className:"h-3.5 w-3.5"})})]})}function Uv(){const{t:e}=z(),[t,s]=f.useState(null),[r,o]=f.useState(!1),[i,a]=f.useState(!1),[l,c]=f.useState(!1);if(f.useEffect(()=>{let g=!0;window.electronAPI.updater.getState().then(v=>g&&a(v.host==="desktop")).catch(()=>{});const x=window.electronAPI.updater.onStatus(v=>{s(v),v.status!=="checking"&&v.status!=="not-available"&&o(!1)});return()=>{g=!1,x()}},[]),!t)return null;const u=n.jsx(a5,{open:l,onOpenChange:c,status:t},"notes"),d=t.status==="available"&&i;if(r||t.status!=="downloaded"&&t.status!=="downloading"&&!d)return n.jsx(n.Fragment,{children:u});const m=t.info?.version,h=t.status==="downloaded",p=d?t.manualInstall:void 0;return n.jsxs(n.Fragment,{children:[n.jsxs(GN,{children:[h?n.jsx(Kw,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}):n.jsx(zd,{className:"h-3.5 w-3.5 shrink-0 animate-pulse text-blue-500"}),n.jsx("span",{className:"min-w-0 flex-1",children:h?e("New version {{version}} is downloaded. Restarting waits for the current tool to finish; background commands keep running.",{version:m??""}):p?e("New version {{version}} found. This local build can't install it automatically.",{version:m??""}):d?e("New version {{version}} found",{version:m??""}):e("Downloading update… {{percent}}%",{percent:Math.round(t.progress?.percent??0)})}),(h||d)&&n.jsx("button",{type:"button",onClick:()=>c(!0),className:"shrink-0 rounded-md px-2 py-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:e("Release notes")}),p&&n.jsx(o5,{manualInstall:p,size:"xs"}),d&&!p&&n.jsx("button",{type:"button",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0 rounded-md bg-primary px-2.5 py-1 text-primary-foreground transition-colors hover:bg-primary/90",children:e("Download update")}),h&&n.jsx("button",{type:"button",onClick:()=>{i5(e)},className:"shrink-0 rounded-md bg-primary px-2.5 py-1 text-primary-foreground transition-colors hover:bg-primary/90",children:e("Restart to update")}),n.jsx("button",{type:"button",onClick:()=>o(!0),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",title:e("Close"),children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]},"banner"),u]})}const mf="enso.zoomBanner.dismissedPercent";function tz(e,t){return e!==100&&e!==t}function nz(e){if(e==null||e==="")return null;const t=Number(e);return Number.isFinite(t)?t:null}function hf(){return window.electronAPI.window.getZoomPercent()}function qv(){const{t:e}=z(),[t,s]=f.useState(hf),[r,o]=f.useState(()=>nz(localStorage.getItem(mf)));return f.useEffect(()=>{const i=()=>s(hf());return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),tz(t,r)?n.jsx("div",{className:"border-b border-blue-500/20 bg-background",children:n.jsxs("div",{className:"flex items-center gap-2 bg-blue-500/8 px-4 py-1.5 text-xs",children:[n.jsx("span",{className:"min-w-0 flex-1",children:e("Interface is zoomed to {{percent}}% · {{shortcut}}",{percent:t,shortcut:qs("mod+0")})}),n.jsx("button",{type:"button",onClick:()=>{window.electronAPI.window.resetZoom(),localStorage.removeItem(mf),o(null),s(hf())},className:"shrink-0 rounded-md bg-primary px-2.5 py-1 text-primary-foreground transition-colors hover:bg-primary/90",children:e("Restore 100%")}),n.jsx("button",{type:"button",onClick:()=>{localStorage.setItem(mf,String(t)),o(t)},className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",title:e("Close"),"aria-label":e("Close"),children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]})}):null}function ox({icon:e,state:t}){const s=t==="running"||t==="reviewing";return n.jsxs("span",{className:_("relative flex size-[22px] shrink-0 items-center justify-center rounded-full border text-muted-foreground",s&&"border-transparent text-brand",t==="error"&&"border-destructive/40 text-destructive"),children:[n.jsx(e,{className:"size-3"}),s&&n.jsx("span",{className:"absolute -inset-px animate-spin rounded-full border-[1.5px] border-brand/20 border-t-brand"})]})}function ix({state:e}){const t=e==="running"||e==="reviewing";return n.jsx("span",{className:"flex size-3 shrink-0 items-center justify-center",children:t?n.jsx("span",{className:"size-2.5 animate-spin rounded-full border-[1.5px] border-border border-t-brand"}):e==="error"?n.jsx("span",{className:"size-1.5 rounded-full bg-destructive"}):n.jsx("span",{className:"size-1 rounded-full bg-current opacity-60"})})}function ao(e){return e.status!=="running"?e.status:e.idle?"idle":e.keep?"kept":"running"}function YN(e,t){const s=Math.max(0,Math.floor(e/6e4));if(s<60)return t("{{n}} min",{n:s});const r=Math.floor(s/60),o=s%60;return o===0?t("{{n}} h",{n:r}):t("{{h}} h {{m}} min",{h:r,m:o})}function ax(e){const t=Math.max(0,Math.floor(e/6e4));return t<60?`${t}m`:`${Math.floor(t/60)}h ${String(t%60).padStart(2,"0")}m`}function Km(e){const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function $i(e=3e4){const[t,s]=f.useState(()=>Date.now());return f.useEffect(()=>{const r=setInterval(()=>s(Date.now()),e);return()=>clearInterval(r)},[e]),t}const sz={ok:"bg-success/15 text-success",pending:"bg-warning/15 text-warning",neutral:"bg-muted text-muted-foreground"};function li({tone:e,children:t,className:s}){return n.jsx("span",{className:_("shrink-0 rounded px-1 py-px text-[10px]",sz[e],s),children:t})}function lx(e,t,s){return s("Idle {{duration}}",{duration:YN(t-(e.idle?.since??t),s)})}function XN({task:e,now:t}){const{t:s}=z(),r=ao(e);return r==="idle"?n.jsx(li,{tone:"pending",children:lx(e,t,s)}):r==="kept"?n.jsx(li,{tone:"neutral",children:s("Kept")}):r==="running"?n.jsx(li,{tone:"ok",children:s("Running")}):e.interrupted==="restart"?n.jsx(li,{tone:"pending",children:s("Interrupted by restart")}):null}function cx({task:e}){return ao(e)==="idle"?n.jsx("span",{className:"relative flex size-[22px] shrink-0 items-center justify-center rounded-full border border-dashed border-warning/60 text-warning",children:n.jsx(_h,{className:"size-3"})}):n.jsx(ox,{icon:$o,state:e.status==="running"?"running":e.status==="failed"?"error":"ok"})}function rz(e,t){const s=e.keep;if(!s)return;const r=s.reason??Km(s.at);return s.by==="user"?t("Kept by you · {{detail}}",{detail:r}):t("Kept: {{reason}}",{reason:r})}function dx({task:e,className:t}){const{t:s}=z(),r=ao(e)==="kept"?rz(e,s):void 0;return r?n.jsxs("div",{className:_("flex min-w-0 items-center gap-1 text-[11px] text-muted-foreground/85",t),children:[n.jsx(Ss,{className:"size-3 shrink-0"}),n.jsx("span",{className:"truncate",title:r,children:r})]}):null}function Vi(e,t){window.electronAPI.agent.stopTask(e,t)}function ux(e,t,s){window.electronAPI.agent.keepTask(e,t,s)}function fx({onStop:e,className:t}){const{t:s}=z();return n.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),e()},title:s("Stop task"),className:_("flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",t),children:s("Stop")})}function mu({sessionId:e,taskId:t}){const{t:s}=z();return n.jsxs(n.Fragment,{children:[n.jsx(fe,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:r=>{r.stopPropagation(),ux(e,t,"")},children:s("Keep")}),n.jsx(fe,{size:"xs",variant:"outline",className:"hover:text-destructive",onClick:r=>{r.stopPropagation(),Vi(e,t)},children:s("Stop")})]})}const _o=ro(()=>({open:!1,idleOnly:!1}));function QN(e=!1){kt.getState().closeWelcome(),_o.setState({open:!0,idleOnly:e})}function JN(){_o.getState().open&&_o.setState({open:!1})}J.subscribe((e,t)=>{e.activeId!==t.activeId&&JN()});const wd=e=>e.status==="running"&&e.idle!==void 0;function oz(e){const t=[];for(const[s,r]of Object.entries(e)){const o=(r?.backgroundTasks??[]).filter(i=>i.status==="running");!r||o.length===0||t.push({conversationId:s,title:r.title??"",...r.projectId?{projectId:r.projectId}:{},unopened:!r.generation,tasks:[...o].sort((i,a)=>i.startedAt-a.startedAt),at:r.lastActiveAt??r.createdAt??0})}return t.sort((s,r)=>r.at-s.at).map(({at:s,...r})=>r)}function ZN(e){let t=0,s=0;for(const r of e??[])r.status==="running"&&(wd(r)?s+=1:t+=1);return{running:t,idle:s}}const mi=(e,t)=>`${e}\0${t}`;function iz(e,t){return e.flatMap(s=>s.tasks.filter(r=>t.has(mi(s.conversationId,r.taskId))).map(r=>({conversationId:s.conversationId,taskId:r.taskId,command:r.command,sessionTitle:s.title,unopened:s.unopened})))}const eS="grid grid-cols-[16px_22px_minmax(0,1fr)_136px_64px_112px] items-center gap-x-3";function az(){const{t:e}=z(),t=J(x=>x.conversations),s=pe(x=>x.projects),r=_o(x=>x.idleOnly),[o,i]=f.useState(new Set),[a,l]=f.useState(!1),c=f.useMemo(()=>oz(t),[t]),u=f.useMemo(()=>c.map(x=>({...x,tasks:r?x.tasks.filter(wd):x.tasks})).filter(x=>x.tasks.length>0),[c,r]),d=c.reduce((x,v)=>x+v.tasks.length,0),m=c.reduce((x,v)=>x+v.tasks.filter(wd).length,0),h=iz(u,o),p=x=>s.find(v=>v.id===x)?.name;f.useEffect(()=>{const x=new Set(c.flatMap(v=>v.tasks.map(b=>mi(v.conversationId,b.taskId))));i(v=>[...v].every(b=>x.has(b))?v:new Set([...v].filter(b=>x.has(b))))},[c]),f.useEffect(()=>{h.length===0&&l(!1)},[h.length]);const g=(x,v)=>i(b=>{const w=new Set(b);for(const j of x)v?w.add(j):w.delete(j);return w});return n.jsx("div",{"data-enso":"background-tasks-page",className:"absolute inset-0 z-10 overflow-y-auto bg-background",children:n.jsxs("div",{className:"relative px-8 pt-6 pb-8",children:[n.jsxs("div",{className:"flex items-baseline gap-3",children:[n.jsx("h1",{className:"text-[18px] font-semibold",children:e("Background tasks")}),d>0&&n.jsxs("span",{className:"text-[12.5px] text-muted-foreground",children:[e("{{count}} running",{count:d}),m>0&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("span",{className:"text-warning",children:e("{{count}} suspected idle",{count:m})})]})," · ",e("from {{count}} sessions",{count:c.length})]})]}),n.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[n.jsx(lz,{idleOnly:r,total:d,idle:m}),n.jsx("span",{className:"flex-1"}),h.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:e("{{count}} selected",{count:h.length})}),n.jsx(fe,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:()=>i(new Set),children:e("Clear selection")}),n.jsx(fe,{size:"xs",variant:"destructive","data-enso":"background-tasks-stop-selected",className:_(a&&"ring-2 ring-destructive/25"),onClick:()=>l(!0),children:e("Stop selected")})]})]}),d===0?n.jsx("div",{className:"mt-10 text-center text-sm text-muted-foreground",children:e("No background tasks are running")}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:_(eS,"mt-3 px-[13px] pb-1.5 text-[11px] text-subtle-foreground"),children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{children:e("Command")}),n.jsx("span",{children:e("Status")}),n.jsx("span",{children:e("Running for")}),n.jsx("span",{})]}),n.jsx("div",{className:"flex flex-col gap-2.5",children:u.map(x=>n.jsx(cz,{group:x,projectName:x.projectId?p(x.projectId):void 0,selected:o,onToggle:g},x.conversationId))}),r&&n.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-[11px] text-subtle-foreground",children:[n.jsx(nB,{className:"size-3"}),e("Rule: no new output for 30 minutes, no active connections on listening ports, CPU near 0, all at once. Kept tasks are excluded for an hour.")]})]}),a&&h.length>0&&n.jsx(uz,{targets:h,onCancel:()=>l(!1),onConfirm:()=>{for(const x of h)Vi(x.conversationId,x.taskId);i(new Set),l(!1)}})]})})}function lz({idleOnly:e,total:t,idle:s}){const{t:r}=z(),o="flex h-6 items-center gap-1 rounded-md px-2.5 text-xs transition-colors",i="bg-background text-foreground shadow-xs dark:bg-foreground/10",a=l=>_o.setState({idleOnly:l});return n.jsxs("div",{className:"inline-flex rounded-lg bg-muted p-0.5 text-muted-foreground",children:[n.jsxs("button",{type:"button",className:_(o,!e&&i),onClick:()=>a(!1),children:[r("All")," ",n.jsx("span",{className:"tabular-nums opacity-70",children:t})]}),n.jsxs("button",{type:"button","data-enso":"background-tasks-idle-only",className:_(o,e&&i),onClick:()=>a(!0),children:[n.jsx(_h,{className:"size-3 text-warning"}),r("Suspected idle only")," ",n.jsx("span",{className:"tabular-nums opacity-70",children:s})]})]})}function cz({group:e,projectName:t,selected:s,onToggle:r}){const{t:o}=z(),i=J(u=>u.selectConversation),a=e.tasks.map(u=>mi(e.conversationId,u.taskId)),l=a.every(u=>s.has(u)),c=a.some(u=>s.has(u));return n.jsxs("div",{"data-enso":"background-tasks-group",className:"overflow-hidden rounded-xl border bg-card shadow-xs",children:[n.jsxs("div",{className:"flex items-center gap-3 border-b border-border/60 px-3 py-2",children:[n.jsx(Vo,{checked:l,indeterminate:c&&!l,onCheckedChange:u=>r(a,u===!0),"aria-label":o("Select all tasks of this session")}),n.jsx("span",{className:"min-w-0 truncate text-[13px] font-medium",children:e.title||o("New conversation")}),t&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[11px] text-muted-foreground",children:t}),e.unopened&&n.jsx("span",{className:"shrink-0 text-[11px] text-subtle-foreground",children:o("Session not open")}),n.jsx("span",{className:"flex-1"}),n.jsxs("button",{type:"button",onClick:()=>i(e.conversationId),className:"inline-flex shrink-0 items-center gap-0.5 text-xs text-muted-foreground hover:text-foreground",children:[o("Open session"),n.jsx(Bi,{className:"size-3.5"})]})]}),n.jsx("div",{className:"divide-y divide-border/50",children:e.tasks.map(u=>n.jsx(dz,{conversationId:e.conversationId,task:u,checked:s.has(mi(e.conversationId,u.taskId)),onCheck:d=>r([mi(e.conversationId,u.taskId)],d)},u.taskId))})]})}function dz({conversationId:e,task:t,checked:s,onCheck:r}){const{t:o}=z(),i=$i();return n.jsxs("div",{"data-enso":"background-tasks-row",className:_(eS,"px-3 py-1.5",s&&"bg-brand/[0.06]"),children:[n.jsx(Vo,{checked:s,onCheckedChange:a=>r(a===!0),"aria-label":o("Select task")}),n.jsx(cx,{task:t}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate font-mono text-xs text-muted-foreground",title:t.command,children:t.command}),n.jsx(dx,{task:t,className:"mt-0.5"})]}),n.jsx("div",{children:n.jsx(XN,{task:t,now:i})}),n.jsx("span",{className:"font-mono text-[11px] text-muted-foreground/80 tabular-nums",children:ax(i-t.startedAt)}),n.jsx("div",{className:"flex items-center justify-end gap-0.5",children:wd(t)?n.jsx(mu,{sessionId:e,taskId:t.taskId}):n.jsx(fx,{onStop:()=>Vi(e,t.taskId)})})]})}function uz({targets:e,onCancel:t,onConfirm:s}){const{t:r}=z(),o=f.useRef(null);return f.useEffect(()=>{const i=l=>{l.key==="Escape"&&t()},a=l=>{o.current&&!o.current.contains(l.target)&&t()};return window.addEventListener("keydown",i),window.addEventListener("mousedown",a),()=>{window.removeEventListener("keydown",i),window.removeEventListener("mousedown",a)}},[t]),n.jsxs("div",{ref:o,role:"dialog","data-enso":"background-tasks-confirm",className:"absolute top-[94px] right-8 z-10 w-[340px] rounded-xl border bg-popover p-3 shadow-float",children:[n.jsx("div",{className:"text-[13px] font-medium",children:r("Stop {{count}} background tasks?",{count:e.length})}),n.jsx("ul",{className:"mt-2 max-h-60 space-y-1 overflow-y-auto",children:e.map(i=>n.jsxs("li",{className:"flex min-w-0 items-baseline gap-2 text-xs",children:[n.jsx("span",{className:"min-w-0 truncate font-mono text-foreground/85",children:i.command}),n.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-subtle-foreground",children:i.unopened?r("{{title}} (not open)",{title:i.sessionTitle||r("New conversation")}):i.sessionTitle||r("New conversation")})]},mi(i.conversationId,i.taskId)))}),n.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:t,children:r("Cancel")}),n.jsx(fe,{size:"xs",variant:"destructive","data-enso":"background-tasks-confirm-stop",onClick:s,children:r("Stop {{count}}",{count:e.length})})]})]})}function fz(e,t){return[t,...e.filter(s=>s.parentId===t.id).sort((s,r)=>s.createdAt-r.createdAt)]}function mz(e,t){return(t.activeThreadId?e.find(r=>r.id===t.activeThreadId&&r.parentId===t.id):void 0)??t}const hz=10,tS=e=>[...e].sort((t,s)=>s.activityAt-t.activityAt);function nS(e,t,s=hz){const r=tS(e),o=a=>a.id===t.currentId||a.id===t.rootId?0:a.unread||a.running?1:2,i=new Set([...r].sort((a,l)=>o(a)-o(l)).slice(0,s).map(a=>a.id));return r.filter(a=>i.has(a.id)).sort((a,l)=>+(l.id===t.rootId)-+(a.id===t.rootId))}function Gv(e,t,s){const r=t.trim().toLowerCase();return tS(e).filter(o=>(s==="all"||(s==="unread"?o.unread:o.running))&&(!r||`${o.title}
|
|
28
|
-
${o.preview??""}`.toLowerCase().includes(r)))}function jd({onResize:e,onResizingChange:t,onReset:s,gap:r=!1,edge:o=!1}){const[i,a]=f.useState(!1),l=f.useRef(0),c=f.useCallback(u=>{u.preventDefault(),a(!0),t?.(!0),l.current=u.clientX;const d=h=>{e(h.clientX-l.current),l.current=h.clientX},m=()=>{a(!1),t?.(!1),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",d),document.addEventListener("mouseup",m)},[e,t]);return n.jsxs("div",{className:_("relative z-20 shrink-0",o?"w-0":r?"w-[8px]":"w-px bg-border"),children:[n.jsx("div",{onMouseDown:c,onDoubleClick:s,className:_("absolute inset-y-0 z-10 cursor-col-resize","after:absolute after:inset-y-0 after:w-px after:transition-colors hover:after:bg-ring",o?"left-0 w-3 after:left-0":r?"inset-x-0 after:left-1/2":"-left-1 -right-1 after:left-1",i&&"after:bg-ring")}),i&&n.jsx("div",{className:"fixed inset-0 z-50 cursor-col-resize"})]})}const pz={"external-send":"Protected: external send",delete:"Protected: delete",payment:"Protected: payment",deploy:"Protected: deploy / production",secret:"Protected: secrets",destructive:"Protected: destructive command"};function sS(e,t){return t(pz[e])}function mx(e,t=0){const[s,r]=f.useState(()=>Date.now());return f.useEffect(()=>{if(e===void 0)return;r(Date.now());const o=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(o)},[e]),e===void 0?void 0:e+t-s}function hx({remainingMs:e,expiredLabel:t}){const{t:s}=z();if(e===void 0)return null;if(e<=0)return n.jsx("span",{className:"shrink-0 text-[10px] text-warning",children:s(t)});const r=Math.ceil(e/1e3),o=`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`;return n.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground tabular-nums",children:s("{{time}} left",{time:o})})}const xz={command:$o,"file-edit":V_,"file-write":W_,mcp:Yw};function gz({kind:e,summary:t}){const[s,r]=f.useState(null);f.useEffect(()=>{if(e!=="command")return;let a=!0;return c5(t,"shellscript").then(l=>{a&&r({summary:t,html:l})}),()=>{a=!1}},[e,t]);const o=s?.summary===t?s.html:null,i=n.jsx($d,{text:t,className:"absolute top-1 right-1 z-10 rounded-md bg-background/80 p-1 text-muted-foreground backdrop-blur"});return e==="command"&&o!=null?n.jsxs("div",{className:"relative mt-1.5",children:[n.jsx("div",{className:"max-h-24 overflow-auto rounded-md text-xs leading-relaxed [&_pre]:m-0 [&_pre]:py-1.5 [&_pre]:pr-7 [&_pre]:pl-2 [&_pre]:font-mono [&_pre]:whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:o}}),i]}):n.jsxs("div",{className:"relative mt-1.5",children:[n.jsx("pre",{className:"max-h-24 overflow-auto rounded-md bg-muted/50 py-1.5 pr-7 pl-2 font-mono text-xs whitespace-pre-wrap",children:t}),i]})}const vz={timeout:"Auto-managed review timed out. Please decide.",error:"Auto-managed review failed. Please decide.",invalid:"Auto-managed review returned no valid decision. Please decide."},Ym=()=>typeof window>"u"||window.electronAPI?.remote?void 0:window.electronAPI?.dcg,bz={critical:"Critical",high:"High",medium:"Medium",low:"Low"};function yz({guard:e}){const{t}=z(),s=e.ruleId===SF;return n.jsxs("div",{className:"mt-1 space-y-0.5 text-[11px]",children:[n.jsxs("p",{className:"text-destructive",children:[t(e.reason)," ",n.jsx("code",{className:"rounded bg-muted/60 px-1 font-mono text-[10px] text-muted-foreground",children:e.ruleId})]}),n.jsx("p",{className:"text-muted-foreground",children:t(s?"Safety floor rule — still requires confirmation in full-access mode. Click Adjust to target a specific subdirectory or session temp folder, or Allow once.":"Blocked by built-in guard — still requires confirmation in full-access mode. Review the command, click Adjust, or Allow once.")})]})}function wz({guard:e}){const{t,locale:s}=z(),[r,o]=f.useState(null),i=e.decision==="warn",a=e.decision===void 0||e.decision==="deny",l=bF(e.ruleId),[c,u]=f.useState(!1);f.useEffect(()=>{if(!a)return;let p=!0;return u(!1),Ym()?.ruleState(e.ruleId).then(g=>{p&&g&&o({ruleId:e.ruleId,state:g})}).catch(()=>{}),()=>{p=!1}},[e.ruleId,a]);const d=r?.ruleId===e.ruleId?r.state:null,m=s==="zh"?Xw(e):{what:e.reason},h=()=>{u(!1),Ym()?.ruleExempt(e.ruleId).then(p=>{p&&o({ruleId:e.ruleId,state:p})}).catch(()=>{})};return n.jsxs("div",{className:"mt-1 space-y-0.5 text-[11px]",children:[n.jsxs("p",{className:i?"text-muted-foreground":"text-destructive",title:e.ruleId,children:[e.severity&&n.jsx("span",{className:"mr-1 rounded bg-muted px-1 text-[10px]",children:t(bz[e.severity])}),t(i?"dcg notice: {{reason}}":"dcg: {{reason}}",{reason:m.what}),n.jsx("code",{className:"ml-1 rounded bg-muted/60 px-1 font-mono text-[10px] text-muted-foreground",children:e.ruleId})]}),!i&&n.jsx("p",{className:"text-muted-foreground",children:l?e.decision==="ask"?t("Guard rule requires confirmation each time — still prompts in full-access mode. Click Adjust for a safer command, or Allow once."):t("Triggered by command guard — still prompts in full-access mode. Click Adjust to change the command or path, or manage exemptions in Settings (auto-suggested after 5 allows)."):t("High-risk safety floor (cannot be exempted) — still requires confirmation in full-access mode. Click Adjust for a safer command or path, or Allow once.")}),e.matched&&n.jsxs("p",{className:"text-muted-foreground",children:[t("Matched"),":"," ",n.jsx("code",{className:"rounded bg-muted/60 px-1 font-mono",children:e.matched})]}),m.why&&n.jsxs("p",{className:"text-muted-foreground",children:[t("Why it is dangerous"),": ",m.why]}),m.alt&&n.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[n.jsxs("span",{children:[t("Safer alternative"),":"]}),n.jsx("code",{className:"rounded bg-muted/60 px-1 font-mono",children:m.alt}),n.jsx($d,{text:m.alt,className:"p-0.5"})]}),e.explanation&&n.jsxs("details",{className:"text-muted-foreground",children:[n.jsx("summary",{className:"cursor-pointer",children:t("dcg explanation")}),n.jsx("p",{className:"whitespace-pre-wrap",children:e.explanation})]}),d?.suggestExempt&&n.jsx("div",{className:"flex flex-wrap items-center gap-2 text-amber-600 dark:text-amber-400",children:c?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:t('Allow "{{rule}}" automatically in new conversations? You can revoke this anytime in Settings.',{rule:e.ruleId})}),n.jsx("button",{type:"button",onClick:h,className:"font-medium underline underline-offset-2",children:t("Confirm exemption")}),n.jsx("button",{type:"button",onClick:()=>u(!1),className:"text-muted-foreground underline underline-offset-2",children:t("Cancel")})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:t("You have allowed this rule {{count}} times. Allow it automatically from now on?",{count:d.allowCount})}),n.jsx("button",{type:"button",onClick:()=>u(!0),className:"underline underline-offset-2",children:t("Always allow this rule")})]})}),d?.exempt&&n.jsx("p",{className:"text-muted-foreground",children:t("This rule is allowed automatically in new conversations until dcg is updated.")})]})}const jz=400;function px({approvals:e,onRespond:t,allowSession:s=!0,handoff:r=!0,clockOffset:o}){const{t:i}=z(),[a,l]=f.useState(null),[c,u]=f.useState(null),d=e[0],m=d?.requestId,h=mx(d?.phase==="reviewing"?void 0:d?.expiresAt,o);if(f.useEffect(()=>{if(!m)return;const b=setTimeout(()=>u(m),jz);return()=>clearTimeout(b)},[m]),!d)return null;const p=xz[d.kind]??Do,g=d.phase==="reviewing",x=c!==d.requestId||a===d.requestId||h!==void 0&&h<=0,v=b=>{b!=="review"&&l(d.requestId),b==="allow"&&d.guard&&(d.guard.decision===void 0||d.guard.decision==="deny")&&!d.guard.ruleId.startsWith("enso.")&&Ym()?.ruleAllowed(d.guard.ruleId).catch(()=>{}),t(d.requestId,b)};return n.jsxs("div",{"data-enso":"approval",className:"mb-1 rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(Do,{className:"h-3.5 w-3.5 shrink-0 text-amber-500"}),n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:i(g?"Assistant reviewing…":"Approval required")}),n.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-muted-foreground",children:[n.jsx(p,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"truncate font-mono",children:d.toolCallId&&l5(d.toolCallId)?`${i("Isolated sandbox")} › ${Rr(d.tool,i)}`:Rr(d.tool,i)})]}),d.protected&&n.jsx("span",{className:"shrink-0 rounded bg-destructive/15 px-1.5 text-[10px] text-destructive",children:sS(d.protected,i)}),n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[n.jsx(hx,{remainingMs:h,expiredLabel:"Timed out · denied"}),e.length>1&&n.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["1/",e.length]})]})]}),d.reviewFallback&&n.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400",children:i(vz[d.reviewFallback])}),d.guard&&(d.guard.ruleId.startsWith("enso.")?n.jsx(yz,{guard:d.guard}):n.jsx(wz,{guard:d.guard})),d.summary&&n.jsx(gz,{kind:d.kind,summary:d.summary}),!g&&n.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[r&&d.kind==="command"&&n.jsx("button",{type:"button",disabled:x,title:i("Send back for a safer command"),onClick:()=>v("revise"),className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:i("Adjust")}),r&&n.jsx("button",{type:"button",disabled:x,title:i("Let the assistant decide"),onClick:()=>v("review"),className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:i("Assistant review")}),n.jsx("button",{type:"button",disabled:x,onClick:()=>v("deny"),className:"rounded-md px-2.5 py-1 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50",children:i("Deny")}),s&&!d.protected&&!d.mandatory&&n.jsx("button",{type:"button",disabled:x,onClick:()=>v("allowSession"),className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:i("Always allow this session")}),n.jsx("button",{type:"button",disabled:x,onClick:()=>v("allow"),className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:i("Allow")})]})]})}function Kv(e){return e>=0&&e<9?String(e+1):null}function kz(e,t){const s=t===void 0?-1:e?.indexOf(t)??-1;return s>=0?s:0}function Nz(e,t,s){return s==="ArrowDown"?Math.min(e+1,t-1):s==="ArrowUp"?Math.max(e-1,0):null}function xx({asks:e,onAnswer:t,clockOffset:s,autoFocus:r=!0}){const{t:o}=z(),i=f.useRef(null),a=f.useRef(null),l=f.useRef([]),[c,u]=f.useState(""),[d,m]=f.useState(!1),[h,p]=f.useState(null),[g,x]=f.useState(()=>new Set),v=e.filter(A=>A.answered),b=e.find(A=>!A.answered),w=b?.requestId,j=mx(b?.expiresAt,s),T=w!==void 0&&g.has(w),N=b?.options,S=b?.recommended,I=A=>{const M=l.current[A];N&&A<N.length&&M?M.focus():i.current?.focus()};if(f.useEffect(()=>{if(!r||!w||T)return;const A=kz(N,S),M=l.current[A];N&&A<N.length&&M?M.focus():i.current?.focus()},[r,w,T]),f.useLayoutEffect(()=>{const A=a.current;if(!A)return;const M=()=>m(A.scrollHeight-A.scrollTop-A.clientHeight>1);M();const R=new ResizeObserver(M);return R.observe(A),A.addEventListener("scroll",M,{passive:!0}),()=>{R.disconnect(),A.removeEventListener("scroll",M)}},[w,T]),!b)return v.length>0?n.jsx(pf,{asks:v}):null;const k=h===b.requestId||j!==void 0&&j<=0,L=A=>{A.trim()&&(p(b.requestId),u(""),t(b.requestId,A.trim()))},F=()=>x(A=>A.has(b.requestId)?A:new Set(A).add(b.requestId));return T?n.jsxs(n.Fragment,{children:[n.jsx(pf,{asks:v}),n.jsxs("button",{type:"button","data-enso":"ask-later",onClick:()=>x(A=>{const M=new Set(A);return M.delete(b.requestId),M}),className:"mb-1 flex w-full items-center gap-2 rounded-lg border border-dashed border-border/60 px-2.5 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground",children:[n.jsx(Uc,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.question}),e.length>1&&n.jsxs("span",{className:"shrink-0 text-[10px] tabular-nums",children:["1/",e.length]}),n.jsx(fn,{className:"h-3 w-3 shrink-0"})]})]}):n.jsxs(n.Fragment,{children:[n.jsx(pf,{asks:v}),n.jsxs("div",{"data-enso":"ask",className:"mb-1 flex max-h-[60dvh] min-h-0 flex-col rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2",onKeyDown:A=>{if(A.nativeEvent.isComposing||k)return;if(A.key==="Escape"){A.preventDefault(),F();return}const M=A.target,R=(N?.length??0)+1,$=M===i.current?R-1:l.current.indexOf(M),U=$>=0?Nz($,R,A.key):null;if(U!==null){A.preventDefault(),I(U);return}if(M instanceof HTMLInputElement&&(M.value.length>0||A.key==="Enter"))return;const q=Number(A.key)-1,te=N?.[q];if(Kv(q)&&te){A.preventDefault(),L(te);return}M instanceof HTMLButtonElement&&$>=0&&(A.key==="Process"?i.current?.focus():A.key.length===1&&A.key!==" "&&!A.metaKey&&!A.ctrlKey&&!A.altKey&&(A.preventDefault(),u(V=>V+A.key),i.current?.focus()))},children:[n.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-x-2 gap-y-1",children:[n.jsx(Uc,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),b.relay&&n.jsx("span",{"data-enso":"ask-relay",className:"min-w-0 rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground [overflow-wrap:anywhere]",children:o("Handed to {{name}}",{name:b.relay.name})}),n.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[n.jsx("button",{type:"button",onClick:F,className:"rounded-md px-1.5 py-0.5 text-[10px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:o("Later")}),n.jsx(hx,{remainingMs:j,expiredLabel:"Timed out · no answer"}),e.length>1&&n.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["1/",e.length]})]})]}),n.jsx("div",{ref:a,"data-enso":"ask-question",className:_("mt-1.5 min-h-5 min-w-0 overflow-y-auto overscroll-contain text-xs leading-relaxed whitespace-pre-wrap [overflow-wrap:anywhere]",d&&"[mask-image:linear-gradient(to_bottom,#000_calc(100%_-_1.5rem),transparent)]"),children:b.question}),N&&N.length>0&&n.jsx("div",{"data-enso":"ask-options",className:"mt-2 flex max-h-[30dvh] shrink-0 flex-col gap-1.5 overflow-y-auto overscroll-contain",children:N.map((A,M)=>{const R=Kv(M);return n.jsxs("button",{ref:$=>{l.current[M]=$},type:"button",disabled:k,onClick:()=>L(A),className:"flex items-center gap-2 rounded-md border border-border/60 px-2 py-1 text-left text-xs text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus:border-ring focus:bg-muted focus:text-foreground disabled:opacity-50",children:[R&&n.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded bg-muted font-mono text-[10px] text-muted-foreground",children:R}),n.jsx("span",{className:"min-w-0 flex-1 [overflow-wrap:anywhere]",children:A}),A===S&&n.jsx("span",{className:"shrink-0 rounded bg-success/15 px-1.5 text-[10px] text-success",children:o("Recommended")})]},A)})}),n.jsxs("div",{className:"mt-2 flex shrink-0 items-center gap-1.5",children:[n.jsx("input",{ref:i,value:c,onChange:A=>u(A.target.value),onKeyDown:A=>{A.nativeEvent.isComposing||A.key==="Enter"&&L(c)},disabled:k,placeholder:o("Type an answer…"),className:"h-7 min-w-0 flex-1 rounded-md border bg-transparent px-2 text-xs outline-none focus:ring-1 focus:ring-ring disabled:opacity-50"}),n.jsx("button",{type:"button",disabled:k||!c.trim(),onClick:()=>L(c),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40",children:n.jsx(cu,{className:"h-3.5 w-3.5"})})]})]})]})}function pf({asks:e}){const{t}=z();return e.length===0?null:n.jsx("div",{"data-enso":"ask-settled",className:"mb-1 space-y-1",children:e.map(s=>{const r=s.answered;if(!r)return null;const o=r.by==="timeout"?t("No answer in time"):r.by==="relay"?t("{{name}} answered: {{answer}}",{name:r.name??t("Secretary"),answer:r.answer??""}):t("Answered: {{answer}}",{answer:r.answer??""});return n.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-dashed border-border/60 px-2.5 py-1.5 text-xs text-muted-foreground",children:[n.jsx(Uc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.question}),n.jsx("span",{className:"shrink-0",children:o})]},s.requestId)})})}const hu=0,lo=1,Hi=2,rS=4;function Yv(e){return()=>e}function Sz(e){e()}function oS(e,t){return s=>e(t(s))}function Xv(e,t){return()=>e(t)}function Cz(e,t){return s=>e(t,s)}function gx(e){return e!==void 0}function Iz(...e){return()=>{e.map(Sz)}}function Wi(){}function pu(e,t){return t(e),e}function Tz(e,t){return t(e)}function wn(...e){return e}function nn(e,t){return e(lo,t)}function Mt(e,t){e(hu,t)}function vx(e){e(Hi)}function Sn(e){return e(rS)}function ut(e,t){return nn(e,Cz(t,hu))}function Us(e,t){const s=e(lo,r=>{s(),t(r)});return s}function Qv(e){let t,s;return r=>o=>{t=o,s&&clearTimeout(s),s=setTimeout(()=>{r(t)},e)}}function iS(e,t){return e===t}function yn(e=iS){let t;return s=>r=>{e(t,r)||(t=r,s(r))}}function jt(e){return t=>s=>{e(s)&&t(s)}}function rt(e){return t=>oS(t,e)}function nr(e){return t=>()=>{t(e)}}function Oe(e,...t){const s=Az(...t);return((r,o)=>{switch(r){case Hi:vx(e);return;case lo:return nn(e,s(o))}})}function or(e,t){return s=>r=>{s(t=e(t,r))}}function Bo(e){return t=>s=>{e>0?e--:t(s)}}function Sr(e){let t=null,s;return r=>o=>{t=o,!s&&(s=setTimeout(()=>{s=void 0,r(t)},e))}}function Ft(...e){const t=Array.from({length:e.length});let s=0,r=null;const o=2**e.length-1;return e.forEach((i,a)=>{const l=2**a;nn(i,c=>{const u=s;s|=l,t[a]=c,u!==o&&s===o&&r&&(r(),r=null)})}),i=>a=>{const l=()=>{i([a].concat(t))};s===o?l():r=l}}function Az(...e){return t=>e.reduceRight(Tz,t)}function Ez(e){let t,s;const r=()=>t?.();return function(o,i){switch(o){case lo:return i?s===i?void 0:(r(),s=i,t=nn(e,i),t):(r(),Wi);case Hi:r(),s=null;return}}}function $e(e){let t=e;const s=Yt();return((r,o)=>{switch(r){case hu:t=o;break;case lo:{o(t);break}case rS:return t}return s(r,o)})}function ss(e,t){return pu($e(t),s=>ut(e,s))}function Yt(){const e=[];return((t,s)=>{switch(t){case hu:e.slice().forEach(r=>{r(s)});return;case Hi:e.splice(0);return;case lo:return e.push(s),()=>{const r=e.indexOf(s);r>-1&&e.splice(r,1)}}})}function gs(e){return pu(Yt(),t=>ut(e,t))}const Rz={singleton:!0};function Zt(e,t=[],s=Rz){const{singleton:r}=s;return{constructor:e,dependencies:t,id:Mz(),singleton:r}}const Mz=()=>Symbol("id");function Pz(e){const t=new Map,s=({constructor:r,dependencies:o,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);const l=r(o.map(c=>s(c)));return a&&t.set(i,l),l};return s(e)}function Mn(...e){const t=Yt(),s=Array.from({length:e.length});let r=0;const o=2**e.length-1;return e.forEach((i,a)=>{const l=2**a;nn(i,c=>{s[a]=c,r|=l,r===o&&Mt(t,s)})}),function(i,a){switch(i){case Hi:{vx(t);return}case lo:return r===o&&a(s),nn(t,a)}}}function wt(e,t=iS){return Oe(e,yn(t))}function Xm(...e){return function(t,s){switch(t){case Hi:return;case lo:return Iz(...e.map(r=>nn(r,s)))}}}const Un={DEBUG:0,INFO:1,WARN:2,ERROR:3},Dz={[Un.DEBUG]:"debug",[Un.ERROR]:"error",[Un.INFO]:"log",[Un.WARN]:"warn"},Oz=()=>typeof globalThis>"u"?window:globalThis,co=Zt(()=>{const e=$e(Un.ERROR);return{log:$e((t,s,r=Un.INFO)=>{const o=Oz().VIRTUOSO_LOG_LEVEL??Sn(e);r>=o&&console[Dz[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,s)}),logLevel:e}},[],{singleton:!0});function Lz(e){return"self"in e?e.document.documentElement:e}function aS(e){const t=Lz(e);return t.ownerDocument.defaultView.getComputedStyle(t).direction==="rtl"}function To(e,t){return aS(e)?-t:t}function Jv(e,t){return aS(e)?-t:t}function qo(e,t,s){return bx(e,t,s).callbackRef}function bx(e,t,s){const r=qe.useRef(null);let o=a=>{};const i=qe.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(a=>{const l=()=>{const c=a[0].target;c.offsetParent!==null&&e(c)};s?l():requestAnimationFrame(l)}):null,[e,s]);return o=a=>{a&&t?(i?.observe(a),r.current=a):(r.current&&i?.unobserve(r.current),r.current=null)},{callbackRef:o,ref:r}}function _z(e,t,s,r,o,i,a,l,c){const u=qe.useCallback(d=>{const m=Bz(d.children,t,l?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;h.dataset.virtuosoScroller===void 0;)h=h.parentElement;const p=h.lastElementChild?.dataset.viewportType==="window";let g;p&&(g=h.ownerDocument.defaultView);const x=a?l?a.scrollWidth:a.scrollHeight:p?l?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:l?h.scrollWidth:h.scrollHeight,v=a?l?a.offsetWidth:a.offsetHeight:p?l?g.innerWidth:g.innerHeight:l?h.offsetWidth:h.offsetHeight,b=a?l?To(a,a.scrollLeft):a.scrollTop:p?l?To(g,g.scrollX||g.document.documentElement.scrollLeft):g.scrollY||g.document.documentElement.scrollTop:l?To(h,h.scrollLeft):h.scrollTop;r({scrollHeight:x,scrollTop:Math.max(b,0),viewportHeight:v}),i?.(l?Zv("column-gap",getComputedStyle(d).columnGap,o):Zv("row-gap",getComputedStyle(d).rowGap,o)),m!==null&&e(m)},[e,t,o,i,a,r,l]);return bx(u,s,c)}function Bz(e,t,s,r){const o=e.length;if(o===0)return null;const i=[];for(let a=0;a<o;a++){const l=e.item(a);if(l.dataset.index===void 0)continue;const c=parseInt(l.dataset.index,10),u=parseFloat(l.dataset.knownSize),d=t(l,s);if(d===0&&r("Zero-sized element, this should not happen",{child:l},Un.ERROR),d===u)continue;const m=i[i.length-1];i.length===0||m.size!==d||m.endIndex!==c-1?i.push({endIndex:c,size:d,startIndex:c}):i[i.length-1].endIndex++}return i}function Zv(e,t,s){return t!=="normal"&&t?.endsWith("px")!==!0&&s(`${e} was not resolved to pixel value correctly`,t,Un.WARN),t==="normal"?0:parseInt(t??"0",10)}function lS(e,t,s){const r=qe.useRef(null),o=qe.useCallback(c=>{if(!c?.offsetParent)return;const u=c.getBoundingClientRect(),d=u.width;let m,h;if(t){const p=t.getBoundingClientRect(),g=u.top-p.top;h=p.height-Math.max(0,g),m=g+t.scrollTop}else{const p=a.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),m=u.top+p.scrollY}r.current={listHeight:u.height,offsetTop:m,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:i,ref:a}=bx(o,!0,s),l=qe.useCallback(()=>{o(a.current)},[o,a]);return qe.useEffect(()=>{if(t){t.addEventListener("scroll",l);const u=new ResizeObserver(()=>{requestAnimationFrame(l)});return u.observe(t),()=>{t.removeEventListener("scroll",l),u.unobserve(t)}}const c=a.current?.ownerDocument.defaultView;return c?.addEventListener("scroll",l),c?.addEventListener("resize",l),()=>{c?.removeEventListener("scroll",l),c?.removeEventListener("resize",l)}},[l,t,a]),i}const fs=Zt(()=>{const e=Yt(),t=Yt(),s=$e(0),r=Yt(),o=$e(0),i=Yt(),a=Yt(),l=$e(0),c=$e(0),u=$e(0),d=$e(0),m=Yt(),h=Yt(),p=$e(!1),g=$e(!1),x=$e(!1);return ut(Oe(e,rt(({scrollTop:v})=>v)),t),ut(Oe(e,rt(({scrollHeight:v})=>v)),a),ut(t,o),{deviation:s,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:l,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:a,scrollingInProgress:p,scrollTo:m,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:i}},[],{singleton:!0}),Xa={lvl:0};function cS(e,t){const s=e.length;if(s===0)return[];let{index:r,value:o}=t(e[0]);const i=[];for(let a=1;a<s;a++){const{index:l,value:c}=t(e[a]);i.push({end:l-1,start:r,value:o}),r=l,o=c}return i.push({end:1/0,start:r,value:o}),i}function ln(e){return e===Xa}function Qa(e,t){if(!ln(e))return t===e.k?e.v:t<e.k?Qa(e.l,t):Qa(e.r,t)}function Xs(e,t,s="k"){if(ln(e))return[-1/0,void 0];if(Number(e[s])===t)return[e.k,e.v];if(Number(e[s])<t){const r=Xs(e.r,t,s);return r[0]===-1/0?[e.k,e.v]:r}return Xs(e.l,t,s)}function ps(e,t,s){return ln(e)?fS(t,s,1):t===e.k?$n(e,{k:t,v:s}):t<e.k?eb($n(e,{l:ps(e.l,t,s)})):eb($n(e,{r:ps(e.r,t,s)}))}function hi(){return Xa}function pi(e,t,s){if(ln(e))return[];const r=Xs(e,t)[0];return Fz(Jm(e,r,s))}function Qm(e,t){if(ln(e))return Xa;const{k:s,l:r,r:o}=e;if(t===s){if(ln(r))return o;if(ln(o))return r;const[i,a]=uS(r);return Pc($n(e,{k:i,l:dS(r),v:a}))}return t<s?Pc($n(e,{l:Qm(r,t)})):Pc($n(e,{r:Qm(o,t)}))}function Ao(e){return ln(e)?[]:[...Ao(e.l),{k:e.k,v:e.v},...Ao(e.r)]}function Jm(e,t,s){if(ln(e))return[];const{k:r,l:o,r:i,v:a}=e;let l=[];return r>t&&(l=l.concat(Jm(o,t,s))),r>=t&&r<=s&&l.push({k:r,v:a}),r<=s&&(l=l.concat(Jm(i,t,s))),l}function Pc(e){const{l:t,lvl:s,r}=e;if(r.lvl>=s-1&&t.lvl>=s-1)return e;if(s>r.lvl+1){if(xf(t))return mS($n(e,{lvl:s-1}));if(!ln(t)&&!ln(t.r))return $n(t.r,{l:$n(t,{r:t.r.l}),lvl:s,r:$n(e,{l:t.r.r,lvl:s-1})});throw new Error("Unexpected empty nodes")}if(xf(e))return Zm($n(e,{lvl:s-1}));if(!ln(r)&&!ln(r.l)){const o=r.l,i=xf(o)?r.lvl-1:r.lvl;return $n(o,{l:$n(e,{lvl:s-1,r:o.l}),lvl:o.lvl+1,r:Zm($n(r,{l:o.r,lvl:i}))})}throw new Error("Unexpected empty nodes")}function $n(e,t){return fS(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function dS(e){return ln(e.r)?e.l:Pc($n(e,{r:dS(e.r)}))}function xf(e){return ln(e)||e.lvl>e.r.lvl}function uS(e){return ln(e.r)?[e.k,e.v]:uS(e.r)}function fS(e,t,s,r=Xa,o=Xa){return{k:e,l:r,lvl:s,r:o,v:t}}function eb(e){return Zm(mS(e))}function mS(e){const{l:t}=e;return!ln(t)&&t.lvl===e.lvl?$n(t,{r:$n(e,{l:t.r})}):e}function Zm(e){const{lvl:t,r:s}=e;return!ln(s)&&!ln(s.r)&&s.lvl===t&&s.r.lvl===t?$n(s,{l:$n(e,{r:s.l}),lvl:t+1}):e}function Fz(e){return cS(e,({k:t,v:s})=>({index:t,value:s}))}function hS(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ja(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const yx=Zt(()=>({recalcInProgress:$e(!1)}),[],{singleton:!0});function pS(e,t,s){return e[kd(e,t,s)]}function kd(e,t,s,r=0){let o=e.length-1;for(;r<=o;){const i=Math.floor((r+o)/2),a=e[i],l=s(a,t);if(l===0)return i;if(l===-1){if(o-r<2)return i-1;o=i-1}else{if(o===r)return i;r=i+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function zz(e,t,s,r){const o=kd(e,t,r),i=kd(e,s,r,o);return e.slice(o,i+1)}function so(e,t){return Math.round(e.getBoundingClientRect()[t])}function xu(e){return!ln(e.groupOffsetTree)}function wx({index:e},t){return t===e?0:t<e?-1:1}function $z(){return{groupIndices:[],groupOffsetTree:hi(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:hi()}}function Vz(e,t){let s=ln(e)?0:1/0;for(const r of t){const{endIndex:o,size:i,startIndex:a}=r;if(s=Math.min(s,a),ln(e)){e=ps(e,0,i);continue}const l=pi(e,a-1,o+1);if(l.some(Yz(r)))continue;let c=!1,u=!1;for(const{end:d,start:m,value:h}of l)c?(o>=m||i===h)&&(e=Qm(e,m)):(u=h!==i,c=!0),d>o&&o>=m&&h!==i&&(e=ps(e,o+1,h));u&&(e=ps(e,a,i))}return[e,s]}function Hz(e){return e.groupIndex!==void 0}function Wz({offset:e},t){return t===e?0:t<e?-1:1}function Za(e,t,s){if(t.length===0)return 0;const{index:r,offset:o,size:i}=pS(t,e,wx),a=e-r,l=i*a+(a-1)*s+o;return l>0?l+s:l}function xS(e,t){if(!xu(t))return e;let s=0;for(;t.groupIndices[s]<=e+s;)s++;return e+s}function gS(e,t,s){if(Hz(e))return t.groupIndices[e.groupIndex]+1;const r=e.index==="LAST"?s:e.index;let o=xS(r,t);return o=Math.max(0,Math.min(s,o)),o}function Uz(e,t,s,r=0){return r>0&&(t=Math.max(t,pS(e,r,wx).offset)),cS(zz(e,t,s,Wz),Kz)}function qz(e,[t,s,r,o]){t.length>0&&r("received item sizes",t,Un.DEBUG);const i=e.sizeTree;let a=i,l=0;if(s.length>0&&ln(i)&&t.length===2){const h=t[0].size,p=t[1].size;a=s.reduce((g,x)=>ps(ps(g,x,h),x+1,p),a)}else[a,l]=Vz(a,t);if(a===i)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:m}=eh(e.offsetTree,l,a,o);return{groupIndices:s,groupOffsetTree:s.reduce((h,p)=>ps(h,p,Za(p,m,o)),hi()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:m,sizeTree:a}}function Gz(e){return Ao(e).map(({k:t,v:s},r,o)=>{const i=o[r+1];return{endIndex:i===void 0?1/0:i.k-1,size:s,startIndex:t}})}function tb(e,t){let s=0,r=0;for(;s<e;)s+=t[r+1]-t[r]-1,r++;return r-(s===e?0:1)}function eh(e,t,s,r){let o=e,i=0,a=0,l=0,c=0;if(t===0)o=[];else{c=kd(o,t-1,wx),l=o[c].offset;const u=Xs(s,t-1);i=u[0],a=u[1],o.length&&o[c].size===Xs(s,t)[1]&&(c-=1),o=o.slice(0,c+1)}for(const{start:u,value:d}of pi(s,t,1/0)){const m=u-i,h=m*a+l+m*r;o.push({index:u,offset:h,size:d}),i=u,l=h,a=d}return{lastIndex:i,lastOffset:l,lastSize:a,offsetTree:o}}function Kz(e){return{index:e.index,value:e}}function Yz(e){const{endIndex:t,size:s,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===s}const Xz={offsetHeight:"height",offsetWidth:"width"},xr=Zt(([{log:e},{recalcInProgress:t}])=>{const s=Yt(),r=Yt(),o=ss(r,0),i=Yt(),a=Yt(),l=$e(0),c=$e([]),u=$e(void 0),d=$e(void 0),m=$e(void 0),h=$e(void 0),p=$e((I,k)=>so(I,Xz[k])),g=$e(void 0),x=$e(0),v=$z(),b=ss(Oe(s,Ft(c,e,x),or(qz,v),yn()),v),w=ss(Oe(c,yn(),or((I,k)=>({current:k,prev:I.current}),{current:[],prev:[]}),rt(({prev:I})=>I)),[]);ut(Oe(c,jt(I=>I.length>0),Ft(b,x),rt(([I,k,L])=>{const F=I.reduce((A,M,R)=>ps(A,M,Za(M,k.offsetTree,L)||R),hi());return{...k,groupIndices:I,groupOffsetTree:F}})),b),ut(Oe(r,Ft(b),jt(([I,{lastIndex:k}])=>I<k),rt(([I,{lastIndex:k,lastSize:L}])=>[{endIndex:k,size:L,startIndex:I}])),s),ut(u,d);const j=ss(Oe(u,rt(I=>I===void 0)),!0);ut(Oe(d,jt(I=>I!==void 0&&ln(Sn(b).sizeTree)),rt(I=>{const k=Sn(m),L=Sn(c).length>0;return k!==void 0&&k!==0?L?[{endIndex:0,size:k,startIndex:0},{endIndex:1,size:I,startIndex:1}]:[]:[{endIndex:0,size:I,startIndex:0}]})),s),ut(Oe(h,jt(I=>I!==void 0&&I.length>0&&ln(Sn(b).sizeTree)),rt(I=>{const k=[];let L=I[0],F=0;for(let A=1;A<I.length;A++){const M=I[A];M!==L&&(k.push({endIndex:A-1,size:L,startIndex:F}),L=M,F=A)}return k.push({endIndex:I.length-1,size:L,startIndex:F}),k})),s),ut(Oe(c,Ft(m,d),jt(([,I,k])=>I!==void 0&&k!==void 0),rt(([I,k,L])=>{const F=[];for(let A=0;A<I.length;A++){const M=I[A],R=I[A+1];F.push({startIndex:M,endIndex:M,size:k}),R!==void 0&&F.push({startIndex:M+1,endIndex:R-1,size:L})}return F})),s);const T=gs(Oe(s,Ft(b),or(({sizes:I},[k,L])=>({changed:L!==I,sizes:L}),{changed:!1,sizes:v}),rt(I=>I.changed)));nn(Oe(l,or((I,k)=>({diff:I.prev-k,prev:k}),{diff:0,prev:0}),rt(I=>I.diff)),I=>{const{groupIndices:k}=Sn(b);if(I>0)Mt(t,!0),Mt(i,I+tb(I,k));else if(I<0){const L=Sn(w);L.length>0&&(I-=tb(-I,L)),Mt(a,I)}}),nn(Oe(l,Ft(e)),([I,k])=>{I<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:l},Un.ERROR)});const N=gs(i);ut(Oe(i,Ft(b),rt(([I,k])=>{const L=k.groupIndices.length>0,F=[],A=k.lastSize;if(L){const M=Qa(k.sizeTree,0);let R=0,$=0;for(;R<I;){const q=k.groupIndices[$],te=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-q-1;F.push({endIndex:q,size:M,startIndex:q}),F.push({endIndex:q+1+te-1,size:A,startIndex:q+1}),$++,R+=te+1}const U=Ao(k.sizeTree);return R!==I&&U.shift(),U.reduce((q,{k:te,v:V})=>{let se=q.ranges;return q.prevSize!==0&&(se=[...q.ranges,{endIndex:te+I-1,size:q.prevSize,startIndex:q.prevIndex}]),{prevIndex:te+I,prevSize:V,ranges:se}},{prevIndex:I,prevSize:0,ranges:F}).ranges}return Ao(k.sizeTree).reduce((M,{k:R,v:$})=>({prevIndex:R+I,prevSize:$,ranges:[...M.ranges,{endIndex:R+I-1,size:M.prevSize,startIndex:M.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),s);const S=gs(Oe(a,Ft(b,x),rt(([I,{offsetTree:k},L])=>{const F=-I;return Za(F,k,L)})));return ut(Oe(a,Ft(b,x),rt(([I,k,L])=>{if(k.groupIndices.length>0){if(ln(k.sizeTree))return k;let A=hi();const M=Sn(w);let R=0,$=0,U=0;for(;R<-I;){U=M[$];const q=M[$+1]-U-1;$++,R+=q+1}if(A=Ao(k.sizeTree).reduce((q,{k:te,v:V})=>ps(q,Math.max(0,te+I),V),A),R!==-I){const q=Qa(k.sizeTree,U);A=ps(A,0,q);const te=Xs(k.sizeTree,-I+1)[1];A=ps(A,1,te)}return{...k,sizeTree:A,...eh(k.offsetTree,0,A,L)}}const F=Ao(k.sizeTree).reduce((A,{k:M,v:R})=>ps(A,Math.max(0,M+I),R),hi());return{...k,sizeTree:F,...eh(k.offsetTree,0,F,L)}})),b),{beforeUnshiftWith:N,data:g,defaultItemSize:d,firstItemIndex:l,fixedItemSize:u,fixedGroupSize:m,gap:x,groupIndices:c,heightEstimates:h,itemSize:p,listRefresh:T,shiftWith:a,shiftWithOffset:S,sizeRanges:s,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:j,unshiftWith:i}},wn(co,yx),{singleton:!0});function Qz(e){return e.reduce((t,s)=>(t.groupIndices.push(t.totalCount),t.totalCount+=s+1,t),{groupIndices:[],totalCount:0})}const vS=Zt(([{groupIndices:e,sizes:t,totalCount:s},{headerHeight:r,scrollTop:o}])=>{const i=Yt(),a=Yt(),l=gs(Oe(i,rt(Qz)));return ut(Oe(l,rt(c=>c.totalCount)),s),ut(Oe(l,rt(c=>c.groupIndices)),e),ut(Oe(Mn(o,t,r),jt(([c,u])=>xu(u)),rt(([c,u,d])=>Xs(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),yn(),rt(c=>[c])),a),{groupCounts:i,topItemsIndexes:a}},wn(xr,fs)),uo=Zt(([{log:e}])=>{const t=$e(!1),s=gs(Oe(t,jt(r=>r),yn()));return nn(t,r=>{r&&Sn(e)("props updated",{},Un.DEBUG)}),{didMount:s,propsReady:t}},wn(co),{singleton:!0}),Jz=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function bS(e){const t=typeof e=="number"?{index:e}:{...e};return t.align||(t.align="start"),(!t.behavior||!Jz)&&(t.behavior="auto"),t.offset===void 0&&(t.offset=0),t}const Il=Zt(([{gap:e,listRefresh:t,sizes:s,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:i,footerHeight:a,headerHeight:l,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:m},{log:h}])=>{const p=Yt(),g=Yt(),x=$e(0);let v=null,b=null,w=null;function j(){v!==null&&(v(),v=null),w!==null&&(w(),w=null),b&&(clearTimeout(b),b=null),Mt(c,!1)}return ut(Oe(p,Ft(s,m,r,x,l,a,h),Ft(e,i,o),rt(([[T,N,S,I,k,L,F,A],M,R,$])=>{const U=bS(T),{align:q,behavior:te,offset:V}=U,se=I-1,Ce=gS(U,N,se);let de=Za(Ce,N.offsetTree,M)+L;q==="end"?(de+=R+Xs(N.sizeTree,Ce)[1]-S+$,Ce===se&&(de+=F)):q==="center"?de+=(R+Xs(N.sizeTree,Ce)[1]-S+$)/2:de-=k,V!==void 0&&V!==0&&(de+=V);const re=Z=>{j(),Z?(A("retrying to scroll to",{location:T},Un.DEBUG),Mt(p,T)):(Mt(g,!0),A("list did not change, scroll successful",{},Un.DEBUG))};if(j(),te==="smooth"){let Z=!1;w=nn(t,me=>{Z=Z||me}),v=Us(d,()=>{re(Z)})}else v=Us(Oe(t,Zz(150)),re);return b=setTimeout(()=>{j()},1200),Mt(c,!0),A("scrolling from index to",{behavior:te,index:Ce,top:de},Un.DEBUG),{behavior:te,top:de}})),u),{scrollTargetReached:g,scrollToIndex:p,topListHeight:x}},wn(xr,fs,co),{singleton:!0});function Zz(e){return t=>{const s=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(s))}}}function jx(e,t){e===0?t():requestAnimationFrame(()=>{jx(e-1,t)})}function kx(e,t){if(e===void 0)return 0;const s=t-1,r=typeof e=="number"?e:e.index==="LAST"?s:e.index;return Math.max(0,Math.min(r,s))}function th(e){return e===void 0?!0:typeof e=="number"?e===0:e.index===0&&(e.align===void 0||e.align==="start")&&(e.offset===void 0||e.offset===0)}const Tl=Zt(([{defaultItemSize:e,listRefresh:t,sizes:s},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:i},{didMount:a}])=>{const l=$e(!0),c=$e(0),u=$e(!0);return ut(Oe(a,Ft(c),jt(([d,m])=>!th(m)),nr(!1)),l),ut(Oe(a,Ft(c),jt(([d,m])=>!th(m)),nr(!1)),u),nn(Oe(Mn(t,a),Ft(l,s,e,u),jt(([[,d],m,{sizeTree:h},p,g])=>d&&(!ln(h)||gx(p))&&!m&&!g),Ft(c)),([,d])=>{if(d===void 0){Mt(l,!0),Mt(u,!0);return}Us(o,()=>{Mt(u,!0)}),jx(4,()=>{Us(r,()=>{Mt(l,!0)}),Mt(i,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:l}},wn(xr,fs,Il,uo),{singleton:!0});function yS(e,t){return Math.abs(e-t)<1.01}const el="up",Ra="down",e$="none",t$={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},n$=0,Al=Zt(([{footerHeight:e,headerHeight:t,scrollBy:s,scrollContainerState:r,scrollTop:o,viewportHeight:i}])=>{const a=$e(!1),l=$e(!0),c=Yt(),u=Yt(),d=$e(4),m=$e(n$),h=ss(Oe(Xm(Oe(wt(o),Bo(1),nr(!0)),Oe(wt(o),Bo(1),nr(!1),Qv(100))),yn()),!1),p=ss(Oe(Xm(Oe(s,nr(!0)),Oe(s,nr(!1),Qv(200))),yn()),!1);ut(Oe(Mn(wt(o),wt(m)),rt(([w,j])=>w<=j),yn()),l),ut(Oe(l,Sr(50)),u);const g=gs(Oe(Mn(r,wt(i),wt(t),wt(e),wt(d)),or((w,[{scrollHeight:j,scrollTop:T},N,S,I,k])=>{const L=T+N-j>-k,F={scrollHeight:j,scrollTop:T,viewportHeight:N};if(L){let M,R;return T>w.state.scrollTop?(M="SCROLLED_DOWN",R=w.state.scrollTop-T):(M="SIZE_DECREASED",R=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:M,scrollTopDelta:R,state:F}}let A;return F.scrollHeight>w.state.scrollHeight?A="SIZE_INCREASED":N<w.state.viewportHeight?A="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?A="SCROLLING_UPWARDS":A="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:A,state:F}},t$),yn((w,j)=>w!==void 0&&w.atBottom===j.atBottom))),x=ss(Oe(r,or((w,{scrollHeight:j,scrollTop:T,viewportHeight:N})=>{if(!yS(w.scrollHeight,j)){const S=j-(T+N)<1;return w.scrollTop!==T&&S?{changed:!0,jump:w.scrollTop-T,scrollHeight:j,scrollTop:T}:{changed:!0,jump:0,scrollHeight:j,scrollTop:T}}return{changed:!1,jump:0,scrollHeight:j,scrollTop:T}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),jt(w=>w.changed),rt(w=>w.jump)),0);ut(Oe(g,rt(w=>w.atBottom)),a),ut(Oe(a,Sr(50)),c);const v=$e(Ra);ut(Oe(r,rt(({scrollTop:w})=>w),yn(),or((w,j)=>Sn(p)?{direction:w.direction,prevScrollTop:j}:{direction:j<w.prevScrollTop?el:Ra,prevScrollTop:j},{direction:Ra,prevScrollTop:0}),rt(w=>w.direction)),v),ut(Oe(r,Sr(50),nr(e$)),v);const b=$e(0);return ut(Oe(h,jt(w=>!w),nr(0)),b),ut(Oe(o,Sr(100),Ft(h),jt(([w,j])=>j),or(([w,j],[T])=>[j,T],[0,0]),rt(([w,j])=>j-w)),b),{atBottomState:g,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:m,isAtBottom:a,isAtTop:l,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:v,scrollVelocity:b}},wn(fs)),tl="top",nl="bottom",nb="none";function sb(e,t,s){return typeof e=="number"?s===el&&t===tl||s===Ra&&t===nl?e:0:s===el?t===tl?e.main:e.reverse:t===nl?e.main:e.reverse}function rb(e,t){return typeof e=="number"?e:e[t]??0}const Nx=Zt(([{deviation:e,fixedHeaderHeight:t,headerHeight:s,scrollTop:r,viewportHeight:o}])=>{const i=Yt(),a=$e(0),l=$e(0),c=$e(0),u=ss(Oe(Mn(wt(r),wt(o),wt(s),wt(i,Ja),wt(c),wt(a),wt(t),wt(e),wt(l)),rt(([d,m,h,[p,g],x,v,b,w,j])=>{const T=d-w,N=v+b,S=Math.max(h-T,0);let I=nb;const k=rb(j,tl),L=rb(j,nl);return p-=w,p+=h+b,g+=h+b,g-=w,p>d+N-k&&(I=el),g<d-S+m+L&&(I=Ra),I!==nb?[Math.max(T-h-sb(x,tl,I)-k,0),T-S-b+m+sb(x,nl,I)+L]:null}),jt(d=>d!==null),yn(Ja)),[0,0]);return{increaseViewportBy:l,listBoundary:i,overscan:c,topListHeight:a,visibleRange:u}},wn(fs),{singleton:!0});function s$(e,t,s){if(xu(t)){const r=xS(e,t);return[{index:Xs(t.groupOffsetTree,r)[0],offset:0,size:0},{data:s?.[0],index:r,offset:0,size:0}]}return[{data:s?.[0],index:e,offset:0,size:0}]}const gf={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Dc(e,t,s,r,o,i){const{lastIndex:a,lastOffset:l,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const m=s-a,h=l+m*c+(m-1)*r,p=u,g=h-d;return{bottom:d,firstItemIndex:i,items:ob(e,o,i),offsetBottom:g,offsetTop:u,top:p,topItems:ob(t,o,i),topListHeight:t.reduce((x,v)=>v.size+x,0),totalCount:s}}function wS(e,t,s,r,o,i){let a=0;if(s.groupIndices.length>0)for(const d of s.groupIndices){if(d-a>=e)break;a++}const l=e+a,c=kx(t,l),u=Array.from({length:l}).map((d,m)=>({data:i[m+c],index:m+c,offset:0,size:0}));return Dc(u,[],l,o,s,r)}function ob(e,t,s){if(e.length===0)return[];if(!xu(t))return e.map(u=>({...u,index:u.index+s,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,i=[],a=pi(t.groupOffsetTree,r,o);let l,c=0;for(const u of e){(!l||l.end<u.index)&&(l=a.shift(),c=t.groupIndices.indexOf(l.start));let d;u.index===l.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+s},i.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return i}function ib(e,t){return e===void 0?0:typeof e=="number"?e:e[t]??0}const Go=Zt(([{data:e,firstItemIndex:t,gap:s,sizes:r,totalCount:o},i,{listBoundary:a,topListHeight:l,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:m},h,{didMount:p},{recalcInProgress:g}])=>{const x=$e([]),v=$e(0),b=Yt(),w=$e(0);ut(i.topItemsIndexes,x);const j=ss(Oe(Mn(p,g,wt(c,Ja),wt(o),wt(r),wt(u),d,wt(x),wt(t),wt(s),wt(w),e),jt(([I,k,,L,,,,,,,,F])=>{const A=F!==void 0&&F.length!==L;return I&&!k&&!A}),rt(([,,[I,k],L,F,A,M,R,$,U,q,te])=>{const V=F,{offsetTree:se,sizeTree:Ce}=V,de=Sn(v);if(L===0)return{...gf,totalCount:L};if(I===0&&k===0)return de===0?{...gf,totalCount:L}:wS(de,A,F,$,U,te||[]);if(ln(Ce))return de>0?null:Dc(s$(kx(A,L),V,te),[],L,U,V,$);const re=[];if(R.length>0){const B=R[0],ne=R[R.length-1];let ve=0;for(const he of pi(Ce,B,ne)){const G=he.value,we=Math.max(he.start,B),ce=Math.min(he.end,ne);for(let Re=we;Re<=ce;Re++)re.push({data:te?.[Re],index:Re,offset:ve,size:G}),ve+=G}}if(!M)return Dc([],re,L,U,V,$);const Z=R.length>0?R[R.length-1]+1:0,me=Uz(se,I,k,Z);if(me.length===0)return null;const xe=L-1,Se=pu([],B=>{for(const ne of me){const ve=ne.value;let he=ve.offset,G=ne.start;const we=ve.size;if(ve.offset<I){G+=Math.floor((I-ve.offset+U)/(we+U));const Re=G-ne.start;he+=Re*we+Re*U}G<Z&&(he+=(Z-G)*we,G=Z);const ce=Math.min(ne.end,xe);for(let Re=G;Re<=ce&&!(he>=k);Re++)B.push({data:te?.[Re],index:Re,offset:he,size:we}),he+=we+U}}),W=ib(q,tl),H=ib(q,nl);if(Se.length>0&&(W>0||H>0)){const B=Se[0],ne=Se[Se.length-1];if(W>0&&B.index>Z){const ve=Math.min(W,B.index-Z),he=[];let G=B.offset;for(let we=B.index-1;we>=B.index-ve;we--){const ce=pi(Ce,we,we)[0]?.value??B.size;G-=ce+U,he.unshift({data:te?.[we],index:we,offset:G,size:ce})}Se.unshift(...he)}if(H>0&&ne.index<xe){const ve=Math.min(H,xe-ne.index);let he=ne.offset+ne.size+U;for(let G=ne.index+1;G<=ne.index+ve;G++){const we=pi(Ce,G,G)[0]?.value??ne.size;Se.push({data:te?.[G],index:G,offset:he,size:we}),he+=we+U}}}return Dc(Se,re,L,U,V,$)}),jt(I=>I!==null),yn()),gf);ut(Oe(e,jt(gx),rt(I=>I?.length)),o),ut(Oe(j,rt(I=>I.topListHeight)),m),ut(m,l),ut(Oe(j,rt(I=>[I.top,I.bottom])),a),ut(Oe(j,rt(I=>I.items)),b);const T=gs(Oe(j,jt(({items:I})=>I.length>0),Ft(o,e),jt(([{items:I},k])=>I[I.length-1].originalIndex===k-1),rt(([,I,k])=>[I-1,k]),yn(Ja),rt(([I])=>I))),N=gs(Oe(j,Sr(200),jt(({items:I,topItems:k})=>I.length>0&&I[0].originalIndex===k.length),rt(({items:I})=>I[0].index),yn())),S=gs(Oe(j,jt(({items:I})=>I.length>0),rt(({items:I})=>{let k=0,L=I.length-1;for(;I[k].type==="group"&&k<L;)k++;for(;I[L].type==="group"&&L>k;)L--;return{endIndex:I[L].index,startIndex:I[k].index}}),yn(hS)));return{endReached:T,initialItemCount:v,itemsRendered:b,listState:j,minOverscanItemCount:w,rangeChanged:S,startReached:N,topItemsIndexes:x,...h}},wn(xr,vS,Nx,Tl,Il,Al,uo,yx),{singleton:!0}),jS=Zt(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:s,headerHeight:r},{listState:o}])=>{const i=Yt(),a=ss(Oe(Mn(s,e,r,t,o),rt(([l,c,u,d,m])=>l+c+u+d+m.offsetBottom+m.bottom)),0);return ut(wt(a),i),{totalListHeight:a,totalListHeightChanged:i}},wn(fs,Go),{singleton:!0}),r$=Zt(([{viewportHeight:e},{totalListHeight:t}])=>{const s=$e(!1),r=ss(Oe(Mn(s,e,t),jt(([o])=>o),rt(([,o,i])=>Math.max(0,o-i)),Sr(0),yn()),0);return{alignToBottom:s,paddingTopAddition:r}},wn(fs,jS),{singleton:!0}),kS=Zt(()=>({context:$e(null)})),o$=({itemBottom:e,itemTop:t,locationParams:{align:s,behavior:r,...o},viewportBottom:i,viewportTop:a})=>t<a?{...o,align:s??"start",...r===void 0?{}:{behavior:r}}:e>i?{...o,align:s??"end",...r===void 0?{}:{behavior:r}}:null,NS=Zt(([{gap:e,sizes:t,totalCount:s},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:i,scrollingInProgress:a,scrollTop:l,viewportHeight:c},{scrollToIndex:u}])=>{const d=Yt();return ut(Oe(d,Ft(t,c,s,i,o,r,l),Ft(e),rt(([[m,h,p,g,x,v,b,w],j])=>{const{calculateViewLocation:T=o$,done:N,...S}=m,I=gS(m,h,g-1),k=Za(I,h.offsetTree,j)+x+v,L=k+Xs(h.sizeTree,I)[1],F=w+v,A=w+p-b,M=T({itemBottom:L,itemTop:k,locationParams:S,viewportBottom:A,viewportTop:F});return M===null?N?.():N&&Us(Oe(a,jt(R=>!R),Bo(Sn(a)?1:2)),N),M}),jt(m=>m!==null)),u),{scrollIntoView:d}},wn(xr,fs,Il,Go,co),{singleton:!0});function ab(e){return e===!1?!1:e==="smooth"?"smooth":"auto"}const i$=(e,t)=>typeof e=="function"?ab(e(t)):t&&ab(e),a$=Zt(([{listRefresh:e,totalCount:t,fixedItemSize:s,data:r},{atBottomState:o,isAtBottom:i},{scrollToIndex:a},{scrolledToInitialItem:l},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:m},{context:h},{scrollIntoView:p}])=>{const g=$e(!1),x=Yt();let v=null;function b(N){Mt(a,{align:"end",behavior:N,index:"LAST"})}nn(Oe(Mn(Oe(wt(t),Bo(1)),c),Ft(wt(g),i,l,m),rt(([[N,S],I,k,L,F])=>{let A=S&&L,M="auto";return A&&(M=i$(I,k||F),A=A&&M!==!1),{followOutputBehavior:M,shouldFollow:A,totalCount:N}}),jt(({shouldFollow:N})=>N)),({followOutputBehavior:N,totalCount:S})=>{v!==null&&(v(),v=null),Sn(s)===void 0?v=Us(e,()=>{Sn(d)("following output to ",{totalCount:S},Un.DEBUG),b(N),v=null}):requestAnimationFrame(()=>{Sn(d)("following output to ",{totalCount:S},Un.DEBUG),b(N)})});function w(N){const S=Us(o,I=>{N&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&v===null&&(Sn(d)("scrolling to bottom due to increased size",{},Un.DEBUG),b("auto"))});setTimeout(S,100)}nn(Oe(Mn(wt(g),t,u),jt(([N,,S])=>N!==!1&&S),or(({value:N},[,S])=>({refreshed:N===S,value:S}),{refreshed:!1,value:0}),jt(({refreshed:N})=>N),Ft(g,t)),([,N])=>{Sn(l)&&w(N!==!1)}),nn(x,()=>{w(Sn(g)!==!1)}),nn(Mn(wt(g),o),([N,S])=>{N!==!1&&!S.atBottom&&S.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&b("auto")});const j=$e(null),T=Yt();return ut(Xm(Oe(wt(r),rt(N=>N?.length??0)),Oe(wt(t))),T),nn(Oe(Mn(Oe(T,Bo(1)),c),Ft(wt(j),l,m,h),rt(([[N,S],I,k,L,F])=>S&&k&&I?.({context:F,totalCount:N,scrollingInProgress:L})),jt(N=>!!N),Sr(0)),N=>{v!==null&&(v(),v=null),Sn(s)===void 0?v=Us(e,()=>{Sn(d)("scrolling into view",{}),Mt(p,N),v=null}):requestAnimationFrame(()=>{Sn(d)("scrolling into view",{}),Mt(p,N)})}),{autoscrollToBottom:x,followOutput:g,scrollIntoViewOnChange:j}},wn(xr,Al,Il,Tl,uo,co,fs,kS,NS)),l$=Zt(([{data:e,firstItemIndex:t,gap:s,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:i,listState:a},{didMount:l}])=>(ut(Oe(l,Ft(i),jt(([,c])=>c!==0),Ft(o,r,t,s,e),rt(([[,c],u,d,m,h,p=[]])=>wS(c,u,d,m,h,p))),a),{}),wn(xr,Tl,Go,uo),{singleton:!0}),c$=Zt(([{didMount:e},{scrollTo:t},{listState:s}])=>{const r=$e(0);return nn(Oe(e,Ft(r),jt(([,o])=>o!==0),rt(([,o])=>({top:o}))),o=>{Us(Oe(s,Bo(1),jt(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{Mt(t,o)})})}),{initialScrollTop:r}},wn(uo,fs,Go),{singleton:!0}),SS=Zt(([{scrollVelocity:e}])=>{const t=$e(!1),s=Yt(),r=$e(!1);return ut(Oe(e,Ft(r,t,s),jt(([o,i])=>i!==!1&&i!==void 0),rt(([o,i,a,l])=>{const{enter:c,exit:u}=i;if(a){if(u(o,l))return!1}else if(c(o,l))return!0;return a}),yn()),t),nn(Oe(Mn(t,e,s),Ft(r)),([[o,i,a],l])=>{o&&l!==!1&&l!==void 0&&l.change&&l.change(i,a)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:s,scrollVelocity:e}},wn(Al),{singleton:!0}),Sx=Zt(([{scrollContainerState:e,scrollTo:t}])=>{const s=Yt(),r=Yt(),o=Yt(),i=$e(!1),a=$e(void 0);return ut(Oe(Mn(s,r),rt(([{scrollTop:l,viewportHeight:c},{offsetTop:u,listHeight:d}])=>({scrollHeight:d,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),ut(Oe(t,Ft(r),rt(([l,{offsetTop:c}])=>({...l,top:l.top+c}))),o),{customScrollParent:a,useWindowScroll:i,windowScrollContainerState:s,windowScrollTo:o,windowViewportRect:r}},wn(fs)),d$=Zt(([{sizeRanges:e,sizes:t},{headerHeight:s,scrollTop:r},{initialTopMostItemIndex:o},{didMount:i},{useWindowScroll:a,windowScrollContainerState:l,windowViewportRect:c}])=>{const u=Yt(),d=$e(void 0),m=$e(null),h=$e(null);return ut(l,m),ut(c,h),nn(Oe(u,Ft(t,r,a,m,h,s)),([p,g,x,v,b,w,j])=>{const T=Gz(g.sizeTree);v&&b!==null&&w!==null&&(x=b.scrollTop-w.offsetTop),x-=j,p({ranges:T,scrollTop:x})}),ut(Oe(d,jt(gx),rt(u$)),o),ut(Oe(i,Ft(d),jt(([,p])=>p!==void 0),yn(),rt(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},wn(xr,fs,Tl,uo,Sx));function u$(e){return{align:"start",index:0,offset:e.scrollTop}}const f$=Zt(([{topItemsIndexes:e}])=>{const t=$e(0);return ut(Oe(t,jt(s=>s>=0),rt(s=>Array.from({length:s}).map((r,o)=>o))),e),{topItemCount:t}},wn(Go));function CS(e){let t=!1,s;return(()=>(t||(t=!0,s=e()),s))}const m$=CS(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),h$=Zt(([{deviation:e,scrollBy:t,scrollingInProgress:s,scrollTop:r},{isAtBottom:o,isScrolling:i,lastJumpDueToItemResize:a,scrollDirection:l},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:m,sizes:h},{log:p},{recalcInProgress:g}])=>{const x=gs(Oe(c,Ft(a),or(([,b,w,j],[{bottom:T,items:N,offsetBottom:S,totalCount:I},k])=>{const L=T+S;let F=0;return w===I&&b.length>0&&N.length>0&&(N[0].originalIndex===0&&b[0].originalIndex===0||(F=L-j,F!==0&&(F+=k))),[F,N,I,L]},[0,[],0,0]),jt(([b])=>b!==0),Ft(r,l,s,o,p,g),jt(([,b,w,j,,,T])=>!T&&!j&&b!==0&&w===el),rt(([[b],,,,,w])=>(w("Upward scrolling compensation",{amount:b},Un.DEBUG),b))));function v(b){b>0?(Mt(t,{behavior:"auto",top:-b}),Mt(e,0)):(Mt(e,0),Mt(t,{behavior:"auto",top:-b}))}return nn(Oe(x,Ft(e,i)),([b,w,j])=>{j&&m$()?Mt(e,w-b):v(-b)}),nn(Oe(Mn(ss(i,!1),e,g),jt(([b,w,j])=>!b&&!j&&w!==0),rt(([b,w])=>w),Sr(1)),v),ut(Oe(m,rt(b=>({top:-b}))),t),nn(Oe(u,Ft(h,d),rt(([b,{groupIndices:w,lastSize:j,sizeTree:T},N])=>{function S(A){return A*(j+N)}if(w.length===0)return S(b);let I=0;const k=Qa(T,0);let L=0,F=0;for(;L<b;){L++,I+=k;let A=w.length===F+1?1/0:w[F+1]-w[F]-1;L+A>b&&(I-=k,A=b-L+1),L+=A,I+=S(A),F++}return I})),b=>{Mt(e,b),requestAnimationFrame(()=>{Mt(t,{top:b}),requestAnimationFrame(()=>{Mt(e,0),Mt(g,!1)})})}),{deviation:e}},wn(fs,Al,Go,xr,co,yx)),p$=Zt(([e,t,s,r,o,i,a,l,c,u,d])=>({...e,...t,...s,...r,...o,...i,...a,...l,...c,...u,...d}),wn(Nx,l$,uo,SS,jS,c$,r$,Sx,NS,co,kS)),IS=Zt(([{data:e,defaultItemSize:t,firstItemIndex:s,fixedItemSize:r,fixedGroupSize:o,gap:i,groupIndices:a,heightEstimates:l,itemSize:c,sizeRanges:u,sizes:d,statefulTotalCount:m,totalCount:h,trackItemSizes:p},{initialItemFinalLocationReached:g,initialTopMostItemIndex:x,scrolledToInitialItem:v},b,w,j,T,{scrollToIndex:N},S,{topItemCount:I},{groupCounts:k},L])=>{const{listState:F,minOverscanItemCount:A,topItemsIndexes:M,rangeChanged:R,...$}=T;return ut(R,L.scrollSeekRangeChanged),ut(Oe(Mn(L.windowViewportRect,b.headerHeight,b.fixedHeaderHeight),rt(([U,q,te])=>Math.max(q+te+1,U.visibleHeight))),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:s,fixedItemHeight:r,fixedGroupHeight:o,gap:i,groupCounts:k,heightEstimates:l,initialItemFinalLocationReached:g,initialTopMostItemIndex:x,scrolledToInitialItem:v,sizeRanges:u,topItemCount:I,topItemsIndexes:M,totalCount:h,...j,groupIndices:a,itemSize:c,listState:F,minOverscanItemCount:A,scrollToIndex:N,statefulTotalCount:m,trackItemSizes:p,rangeChanged:R,...$,...L,...b,sizes:d,...w}},wn(xr,Tl,fs,d$,a$,Go,Il,h$,f$,vS,p$));function x$(e,t){const s={},r={};let o=0;const i=e.length;for(;o<i;)r[e[o]]=1,o+=1;for(const a in t)Object.hasOwn(r,a)||(s[a]=t[a]);return s}const Ql=typeof document>"u"?qe.useEffect:qe.useLayoutEffect;function TS(e,t,s){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),i=Object.keys(t.methods||{}),a=Object.keys(t.events||{}),l=qe.createContext({});function c(v,b){v.propsReady!==void 0&&Mt(v.propsReady,!1);for(const w of r){const j=v[t.required[w]];Mt(j,b[w])}for(const w of o)if(w in b){const j=v[t.optional[w]];Mt(j,b[w])}v.propsReady!==void 0&&Mt(v.propsReady,!0)}function u(v){return i.reduce((b,w)=>(b[w]=j=>{const T=v[t.methods[w]];Mt(T,j)},b),{})}function d(v){return a.reduce((b,w)=>(b[w]=Ez(v[t.events[w]]),b),{})}const m=qe.forwardRef(function(v,b){const{children:w,...j}=v,[T]=qe.useState(()=>pu(Pz(e),I=>{c(I,j)})),[N]=qe.useState(Xv(d,T));Ql(()=>{for(const I of a)I in j&&nn(N[I],j[I]);return()=>{Object.values(N).map(vx)}},[j,N,T]),Ql(()=>{c(T,j)}),qe.useImperativeHandle(b,Yv(u(T)));const S=s;return n.jsx(l.Provider,{value:T,children:s===void 0?w:n.jsx(S,{...x$([...r,...o,...a],j),children:w})})}),h=v=>{const b=qe.useContext(l);return qe.useCallback(w=>{Mt(b[v],w)},[b,v])},p=v=>{const b=qe.useContext(l)[v],w=qe.useCallback(j=>nn(b,j),[b]);return qe.useSyncExternalStore(w,()=>Sn(b),()=>Sn(b))},g=v=>{const b=qe.useContext(l)[v],[w,j]=qe.useState(Xv(Sn,b));return Ql(()=>nn(b,T=>{T!==w&&j(Yv(T))}),[b,w]),w},x=parseInt(qe.version,10)>=18?p:g;return{Component:m,useEmitter:(v,b)=>{const w=qe.useContext(l)[v];Ql(()=>nn(w,b),[b,w])},useEmitterValue:x,usePublisher:h}}const AS=qe.createContext(void 0),ES=qe.createContext(void 0),vf="-webkit-sticky",lb="sticky",Cx=CS(()=>{if(typeof document>"u")return lb;const e=document.createElement("div");return e.style.position=vf,e.style.position===vf?vf:lb}),RS=typeof document>"u"?qe.useEffect:qe.useLayoutEffect;function bf(e){return"self"in e}function g$(e){return"body"in e}function MS(e,t,s,r=Wi,o,i){const a=qe.useRef(null),l=qe.useRef(null),c=qe.useRef(null),u=qe.useCallback(h=>{let p,g,x;const v=h.target;if(g$(v)||bf(v)){const w=bf(v)?v:v.defaultView;x=i===!0?To(w,w.scrollX):w.scrollY,p=i===!0?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,g=i===!0?w.innerWidth:w.innerHeight}else x=i===!0?To(v,v.scrollLeft):v.scrollTop,p=i===!0?v.scrollWidth:v.scrollHeight,g=i===!0?v.offsetWidth:v.offsetHeight;const b=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:g})};h.suppressFlushSync===!0?b():d5.flushSync(b),l.current!==null&&(x===l.current||x<=0||x===p-g)&&(l.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,i]);qe.useEffect(()=>{const h=o??a.current;return r(o??a.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[a,u,s,r,o]);function d(h){const p=a.current;if(!p||(i===!0?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const g=h.behavior==="smooth";let x,v,b;bf(p)?(v=Math.max(so(p.document.documentElement,i===!0?"width":"height"),i===!0?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=i===!0?p.innerWidth:p.innerHeight,b=i===!0?To(p,p.scrollX):p.scrollY):(v=p[i===!0?"scrollWidth":"scrollHeight"],x=so(p,i===!0?"width":"height"),b=i===!0?To(p,p.scrollLeft):p.scrollTop);const w=v-x;if(h.top===void 0){p.scrollTo(h);return}const j=Math.ceil(Math.max(Math.min(w,h.top),0));if(h.top=j,yS(x,v)||j===b){e({scrollHeight:v,scrollTop:b,viewportHeight:x}),g&&t(!0);return}g?(l.current=j,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,l.current=null,t(!0)},1e3)):l.current=null,i===!0&&(h={...h.behavior===void 0?{}:{behavior:h.behavior},left:Jv(p,j)}),p.scrollTo(h)}function m(h){i===!0&&(h={...h.behavior===void 0?{}:{behavior:h.behavior},...h.top===void 0?{}:{left:Jv(a.current,h.top)}}),a.current.scrollBy(h)}return{scrollByCallback:m,scrollerRef:a,scrollToCallback:d}}function Ix(e){return e}const v$=Zt(()=>{const e=$e(l=>`Item ${l}`),t=$e(l=>`Group ${l}`),s=$e({}),r=$e(Ix),o=$e("div"),i=$e(Wi),a=(l,c=null)=>ss(Oe(s,rt(u=>u[l]),yn()),c);return{components:s,computeItemKey:r,EmptyPlaceholder:a("EmptyPlaceholder"),FooterComponent:a("Footer"),GroupComponent:a("Group","div"),groupContent:t,HeaderComponent:a("Header"),HeaderFooterTag:o,ItemComponent:a("Item","div"),itemContent:e,ListComponent:a("List","div"),ScrollerComponent:a("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:a("ScrollSeekPlaceholder"),TopItemListComponent:a("TopItemList")}}),b$=Zt(([e,t])=>({...e,...t}),wn(IS,v$)),y$=({height:e})=>n.jsx("div",{style:{height:e}}),w$={overflowAnchor:"none",position:Cx(),zIndex:1},PS={overflowAnchor:"none"},j$={...PS,display:"inline-block",height:"100%"},cb=qe.memo(function({showTopList:e=!1}){const t=St("listState"),s=Es("sizeRanges"),r=St("useWindowScroll"),o=St("customScrollParent"),i=Es("windowScrollContainerState"),a=Es("scrollContainerState"),l=o||r?i:a,c=St("itemContent"),u=St("context"),d=St("groupContent"),m=St("trackItemSizes"),h=St("itemSize"),p=St("log"),g=Es("gap"),x=St("horizontalDirection"),{callbackRef:v}=_z(s,h,m,e?Wi:l,p,g,o,x,St("skipAnimationFrameInResizeObserver")),[b,w]=qe.useState(0);Ax("deviation",$=>{b!==$&&w($)});const j=St("EmptyPlaceholder"),T=St("ScrollSeekPlaceholder")??y$,N=St("ListComponent"),S=St("ItemComponent"),I=St("GroupComponent"),k=St("computeItemKey"),L=St("isSeeking"),F=St("groupIndices").length>0,A=St("alignToBottom"),M=St("initialItemFinalLocationReached"),R=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginInlineStart:b===0?A?"auto":0:b,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:"nowrap"}:{marginTop:b===0?A?"auto":0:b,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...M?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&j!==null&&j!==void 0?n.jsx(j,{...ns(j,u)}):n.jsx(N,{...ns(N,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:R,children:(e?t.topItems:t.items).map($=>{const U=$.originalIndex,q=k(U+t.firstItemIndex,$.data,u);return L?f.createElement(T,{...ns(T,u),height:$.size,index:$.index,key:q,type:$.type||"item",...$.type==="group"?{}:{groupIndex:$.groupIndex}}):$.type==="group"?f.createElement(I,{...ns(I,u),"data-index":U,"data-item-index":$.index,"data-known-size":$.size,key:q,style:w$},d($.index,u)):f.createElement(S,{...ns(S,u),...C$(S,$.data),"data-index":U,"data-item-group-index":$.groupIndex,"data-item-index":$.index,"data-known-size":$.size,key:q,style:x?j$:PS},F?c($.index,$.groupIndex,$.data,u):c($.index,$.data,u))})})}),k$={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},N$={outline:"none",overflowX:"auto",position:"relative"},Tx=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:void 0}),DS=(e,t,s=0)=>({...Tx(e),position:t?"relative":"absolute",top:t?-s:0}),S$={position:Cx(),top:0,width:"100%",zIndex:1};function ns(e,t){if(typeof e!="string")return{context:t}}function C$(e,t){return{item:typeof e=="string"?void 0:t}}const I$=qe.memo(function(){const e=St("HeaderComponent"),t=Es("headerHeight"),s=St("HeaderFooterTag"),r=qo(qe.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,St("skipAnimationFrameInResizeObserver")),o=St("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null}),T$=qe.memo(function(){const e=St("FooterComponent"),t=Es("footerHeight"),s=St("HeaderFooterTag"),r=qo(qe.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,St("skipAnimationFrameInResizeObserver")),o=St("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null});function OS({useEmitter:e,useEmitterValue:t,usePublisher:s}){return qe.memo(function({children:r,style:o,context:i,...a}){const l=s("scrollContainerState"),c=t("ScrollerComponent"),u=s("smoothScrollTargetReached"),d=t("scrollerRef"),m=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:g}=MS(l,u,c,d,void 0,m);return e("scrollTo",g),e("scrollBy",h),n.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...m?N$:k$,...o},tabIndex:0,...a,...ns(c,i),children:r})})}function LS({useEmitter:e,useEmitterValue:t,usePublisher:s}){return qe.memo(function({children:r,style:o,context:i,...a}){const l=s("windowScrollContainerState"),c=t("ScrollerComponent"),u=s("smoothScrollTargetReached"),d=t("totalListHeight"),m=t("deviation"),h=t("customScrollParent"),p=qe.useRef(null),g=t("scrollerRef"),{scrollByCallback:x,scrollerRef:v,scrollToCallback:b}=MS(l,u,c,g,h);return RS(()=>(v.current=h??p.current?.ownerDocument.defaultView,()=>{v.current=null}),[v,h]),e("windowScrollTo",b),e("scrollBy",x),n.jsx(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d===0?void 0:{height:d+m}},...a,...ns(c,i),children:r})})}const A$=({children:e})=>{const t=qe.useContext(AS),s=Es("viewportHeight"),r=Es("fixedItemHeight"),o=St("alignToBottom"),i=St("horizontalDirection"),a=qe.useMemo(()=>oS(s,c=>so(c,i?"width":"height")),[s,i]),l=qo(a,!0,St("skipAnimationFrameInResizeObserver"));return qe.useEffect(()=>{t&&(s(t.viewportHeight),r(t.itemHeight))},[t,s,r]),n.jsx("div",{"data-viewport-type":"element",ref:l,style:Tx(o),children:e})},E$=({children:e})=>{const t=qe.useContext(AS),s=Es("windowViewportRect"),r=Es("fixedItemHeight"),o=St("customScrollParent"),i=St("useWindowScroll"),a=St("topListHeight"),l=lS(s,o,St("skipAnimationFrameInResizeObserver")),c=St("alignToBottom");return qe.useEffect(()=>{t&&(r(t.itemHeight),s({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,s,r]),n.jsx("div",{"data-viewport-type":"window",ref:l,style:DS(c,i,a),children:e})},R$=({children:e})=>{const t=St("TopItemListComponent")??"div",s=St("headerHeight"),r={...S$,marginTop:`${s}px`},o=St("context");return n.jsx(t,{style:r,...ns(t,o),children:e})},M$=qe.memo(function(e){const t=St("useWindowScroll"),s=St("topItemsIndexes").length>0,r=St("customScrollParent"),o=St("context");return n.jsxs(r||t?O$:D$,{...e,context:o,children:[s&&n.jsx(R$,{children:n.jsx(cb,{showTopList:!0})}),n.jsxs(r||t?E$:A$,{children:[n.jsx(I$,{}),n.jsx(cb,{}),n.jsx(T$,{})]})]})}),{Component:P$,useEmitter:Ax,useEmitterValue:St,usePublisher:Es}=TS(b$,{optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",minOverscanItemCount:"minOverscanItemCount",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedGroupHeight:"fixedGroupHeight",fixedItemHeight:"fixedItemHeight",heightEstimates:"heightEstimates",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},M$),D$=OS({useEmitter:Ax,useEmitterValue:St,usePublisher:Es}),O$=LS({useEmitter:Ax,useEmitterValue:St,usePublisher:Es}),L$=P$,_$=Zt(()=>{const e=$e(u=>n.jsxs("td",{children:["Item $",u]})),t=$e(null),s=$e(u=>n.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=$e(null),o=$e(null),i=$e({}),a=$e(Ix),l=$e(Wi),c=(u,d=null)=>ss(Oe(i,rt(m=>m[u]),yn()),d);return{components:i,computeItemKey:a,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:s,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}});wn(IS,_$);Cx();const db={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},B$={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ub,floor:Nd,max:Ma,min:yf,round:fb}=Math;function mb(e,t,s){return Array.from({length:t-e+1}).map((r,o)=>({data:s===null?null:s[o+e],index:o+e}))}function F$(e){return{...B$,items:e}}function Jl(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function z$(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}const $$=Zt(([{increaseViewportBy:e,listBoundary:t,overscan:s,visibleRange:r},{footerHeight:o,headerHeight:i,scrollBy:a,scrollContainerState:l,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:m},h,p,{didMount:g,propsReady:x},{customScrollParent:v,useWindowScroll:b,windowScrollContainerState:w,windowScrollTo:j,windowViewportRect:T},N])=>{const S=$e(0),I=$e(0),k=$e(db),L=$e({height:0,width:0}),F=$e({height:0,width:0}),A=Yt(),M=Yt(),R=$e(0),$=$e(null),U=$e({column:0,row:0}),q=Yt(),te=Yt(),V=$e(!1),se=$e(0),Ce=$e(!0),de=$e(!1),re=$e(!1);nn(Oe(g,Ft(se),jt(([H,B])=>!th(B))),()=>{Mt(Ce,!1)}),nn(Oe(Mn(g,Ce,F,L,se,de),jt(([H,B,ne,ve,,he])=>H&&!B&&ne.height!==0&&ve.height!==0&&!he)),([,,,,H])=>{if(H===void 0){Mt(Ce,!0);return}Mt(de,!0),jx(1,()=>{Mt(A,H)}),Us(Oe(u),()=>{Mt(t,[0,0]),Mt(Ce,!0)})}),ut(Oe(te,jt(H=>H!=null&&H.scrollTop>0),nr(0)),I),nn(Oe(g,Ft(te),jt(([,H])=>H!=null)),([,H])=>{H&&(Mt(L,H.viewport),Mt(F,H.item),Mt(U,H.gap),H.scrollTop>0&&(Mt(V,!0),Us(Oe(u,Bo(1)),B=>{Mt(V,!1)}),Mt(c,{top:H.scrollTop})))}),ut(Oe(L,rt(({height:H})=>H)),m),ut(Oe(Mn(wt(L,Jl),wt(F,Jl),wt(U,(H,B)=>H!==void 0&&H.column===B.column&&H.row===B.row),wt(u)),rt(([H,B,ne,ve])=>({gap:ne,item:B,scrollTop:ve,viewport:H}))),q),ut(Oe(Mn(wt(S),r,wt(U,z$),wt(F,Jl),wt(L,Jl),wt($),wt(I),wt(V),wt(Ce),wt(se)),jt(([,,,,,,,H])=>!H),rt(([H,[B,ne],ve,he,G,we,ce,,Re,ue])=>{const{column:We,row:it}=ve,{height:Fe,width:tt}=he,{width:ke}=G;if(ce===0&&(H===0||ke===0))return db;if(tt===0){const Lt=kx(ue,H),on=Lt+Math.max(ce-1,0);return F$(mb(Lt,on,we))}const nt=_S(ke,tt,We);let mt,X;Re?B===0&&ne===0&&ce>0?(mt=0,X=ce-1):(mt=nt*Nd((B+it)/(Fe+it)),X=nt*ub((ne+it)/(Fe+it))-1,X=yf(H-1,Ma(X,nt-1)),mt=yf(X,Ma(0,mt))):(mt=0,X=-1);const K=mb(mt,X,we),{bottom:Ee,top:pt}=hb(G,ve,he,K),Pt=ub(H/nt),Je=Pt*Fe+(Pt-1)*it-Ee;return{bottom:Ee,itemHeight:Fe,items:K,itemWidth:tt,offsetBottom:Je,offsetTop:pt,top:pt}})),k),ut(Oe($,jt(H=>H!==null),rt(H=>H.length)),S),ut(Oe(Mn(L,F,k,U),jt(([H,B,{items:ne}])=>ne.length>0&&B.height!==0&&H.height!==0),rt(([H,B,{items:ne},ve])=>{const{bottom:he,top:G}=hb(H,ve,B,ne);return[G,he]}),yn(Ja)),t);const Z=$e(!1);ut(Oe(u,Ft(Z),rt(([H,B])=>B||H!==0)),Z);const me=gs(Oe(Mn(k,S),jt(([{items:H}])=>H.length>0),Ft(Z),jt(([[H,B],ne])=>{const ve=H.items[H.items.length-1].index===B-1;return(ne||H.bottom>0&&H.itemHeight>0&&H.offsetBottom===0&&H.items.length===B)&&ve}),rt(([[,H]])=>H-1),yn())),xe=gs(Oe(wt(k),jt(({items:H})=>H.length>0&&H[0].index===0),nr(0),yn())),Se=gs(Oe(wt(k),Ft(V),jt(([{items:H},B])=>H.length>0&&!B),rt(([{items:H}])=>({endIndex:H[H.length-1].index,startIndex:H[0].index})),yn(hS),Sr(0)));ut(Se,p.scrollSeekRangeChanged),ut(Oe(A,Ft(L,F,S,U),rt(([H,B,ne,ve,he])=>{const G=bS(H),{align:we,behavior:ce,offset:Re}=G;let ue=G.index;ue==="LAST"&&(ue=ve-1),ue=Ma(0,ue,yf(ve-1,ue));let We=nh(B,he,ne,ue);return we==="end"?We=fb(We-B.height+ne.height):we==="center"&&(We=fb(We-B.height/2+ne.height/2)),Re!==void 0&&Re!==0&&(We+=Re),{behavior:ce,top:We}})),c);const W=ss(Oe(k,rt(H=>H.offsetBottom+H.bottom)),0);return ut(Oe(T,rt(H=>({height:H.visibleHeight,width:H.visibleWidth}))),L),{customScrollParent:v,data:$,deviation:R,footerHeight:o,gap:U,headerHeight:i,increaseViewportBy:e,initialItemCount:I,itemDimensions:F,overscan:s,restoreStateFrom:te,scrollBy:a,scrollContainerState:l,scrollHeight:M,scrollTo:c,scrollToIndex:A,scrollTop:u,smoothScrollTargetReached:d,totalCount:S,useWindowScroll:b,viewportDimensions:L,windowScrollContainerState:w,windowScrollTo:j,windowViewportRect:T,...p,gridState:k,horizontalDirection:re,initialTopMostItemIndex:se,totalListHeight:W,...h,endReached:me,propsReady:x,rangeChanged:Se,startReached:xe,stateChanged:q,stateRestoreInProgress:V,...N}},wn(Nx,fs,Al,SS,uo,Sx,co));function _S(e,t,s){return Ma(1,Nd((e+s)/(Nd(t)+s)))}function hb(e,t,s,r){const{height:o}=s;if(o===void 0||r.length===0)return{bottom:0,top:0};const i=nh(e,t,s,r[0].index);return{bottom:nh(e,t,s,r[r.length-1].index)+o,top:i}}function nh(e,t,s,r){const o=_S(e.width,s.width,t.column),i=Nd(r/o),a=i*s.height+Ma(0,i-1)*t.row;return a>0?a+t.row:a}const V$=Zt(()=>{const e=$e(m=>`Item ${m}`),t=$e({}),s=$e(null),r=$e("virtuoso-grid-item"),o=$e("virtuoso-grid-list"),i=$e(Ix),a=$e("div"),l=$e(Wi),c=(m,h=null)=>ss(Oe(t,rt(p=>p[m]),yn()),h),u=$e(!1),d=$e(!1);return ut(wt(d),u),{components:t,computeItemKey:i,context:s,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:a,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),H$=Zt(([e,t])=>({...e,...t}),wn($$,V$)),W$=qe.memo(function(){const e=bn("gridState"),t=bn("listClassName"),s=bn("itemClassName"),r=bn("itemContent"),o=bn("computeItemKey"),i=bn("isSeeking"),a=Rs("scrollHeight"),l=bn("ItemComponent"),c=bn("ListComponent"),u=bn("ScrollSeekPlaceholder"),d=bn("context"),m=Rs("itemDimensions"),h=Rs("gap"),p=bn("log"),g=bn("stateRestoreInProgress"),x=Rs("reportReadyState"),v=qo(qe.useMemo(()=>b=>{const w=b.parentElement.parentElement.scrollHeight;a(w);const j=b.firstChild;if(j!==null){const{height:T,width:N}=j.getBoundingClientRect();m({height:T,width:N})}h({column:pb("column-gap",getComputedStyle(b).columnGap,p),row:pb("row-gap",getComputedStyle(b).rowGap,p)})},[a,m,h,p]),!0,!1);return RS(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),g?null:n.jsx(c,{className:t,ref:v,...ns(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(b=>{const w=o(b.index,b.data,d);return i?n.jsx(u,{...ns(u,d),height:e.itemHeight,index:b.index,width:e.itemWidth},w):f.createElement(l,{...ns(l,d),className:s,"data-index":b.index,key:w},r(b.index,b.data,d))})})}),U$=qe.memo(function(){const e=bn("HeaderComponent"),t=Rs("headerHeight"),s=bn("headerFooterTag"),r=qo(qe.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,!1),o=bn("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null}),q$=qe.memo(function(){const e=bn("FooterComponent"),t=Rs("footerHeight"),s=bn("headerFooterTag"),r=qo(qe.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,!1),o=bn("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null}),G$=({children:e})=>{const t=qe.useContext(ES),s=Rs("itemDimensions"),r=Rs("viewportDimensions"),o=qo(qe.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return qe.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),s({height:t.itemHeight,width:t.itemWidth}))},[t,r,s]),n.jsx("div",{ref:o,style:Tx(!1),children:e})},K$=({children:e})=>{const t=qe.useContext(ES),s=Rs("windowViewportRect"),r=Rs("itemDimensions"),o=bn("customScrollParent"),i=bn("useWindowScroll"),a=lS(s,o,!1);return qe.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),s({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,s,r]),n.jsx("div",{ref:a,style:DS(!1,i),children:e})},Y$=qe.memo(function({...e}){const t=bn("useWindowScroll"),s=bn("customScrollParent"),r=s||t?Q$:X$,o=s||t?K$:G$,i=bn("context");return n.jsx(r,{...e,...ns(r,i),children:n.jsxs(o,{children:[n.jsx(U$,{}),n.jsx(W$,{}),n.jsx(q$,{})]})})}),{useEmitter:BS,useEmitterValue:bn,usePublisher:Rs}=TS(H$,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Y$),X$=OS({useEmitter:BS,useEmitterValue:bn,usePublisher:Rs}),Q$=LS({useEmitter:BS,useEmitterValue:bn,usePublisher:Rs});function pb(e,t,s){return t!=="normal"&&t?.endsWith("px")!==!0&&s(`${e} was not resolved to pixel value correctly`,t,Un.WARN),t==="normal"?0:parseInt(t??"0",10)}function fee(){const{t:e}=z();return kt(t=>t.secretary.profile?.name.trim())||e("Secretary")}function FS(){const e=kt(r=>r.secretary.enabled?r.secretary.profile:null),t=kt(r=>r.secretary.secretaryId??void 0);if(!e)return null;const s=e.avatar.imageVersion;return{name:e.name.trim()||"·",color:e.avatar.color,...s?{image:ll(s,e.avatar.imageHash,t)}:{}}}const gu=f.createContext(null);function js(){return f.useContext(gu)}function J$({className:e}){return n.jsx("svg",{viewBox:"0 0 64 64",fill:"none","aria-hidden":"true",className:_("size-4",e),children:n.jsx("path",{d:"M 38.96 48.86 A 18.24 18.24 0 1 1 48.19 40.4",stroke:"currentColor",strokeWidth:"8.32",strokeLinecap:"round"})})}const Z$={rows:new Set,expanded:new Set};function eV(e,t,s){const r=[],o=[],i=new Map,a=new Set;for(const l of t){if(l.kind!=="tool-group"||!l.explore)continue;const c=e.rows.has(l.key);if(l.explore.steps){a.add(l.key),c&&!e.expanded.has(l.key)&&o.push(l.key),l.children.forEach((p,g)=>{i.set(p.key,{group:l.key,index:g})});continue}const u=l.children[0]?.key??"",d=l.children.at(-1)?.key??"",m=!c&&e.rows.has(u)&&e.rows.has(d);if(!m&&!e.expanded.has(l.key))continue;const h=s(m?u:l.key,d);h>0&&r.push({key:l.key,height:h,pair:m})}return{collapses:r,expands:o,children:i,next:{rows:new Set(t.map(l=>l.key)),expanded:a}}}function tV({loading:e=!1,runStartedAt:t}){if(!e)return t}function nV(e){return e==="right"||e==="off"?e:"left"}function sV(e,t,s){return e!=="off"&&!t&&s>=2}const Zl=40;function rV({items:e,activeKey:t,onJump:s}){const r=pe(g=>g.chatWide),o=nV(pe(g=>g.navRailSide)),[i,a]=f.useState(null);if(!sV(o,r,e.length))return null;const l=o==="right",c=Math.max(0,e.findIndex(g=>g.key===t)),u=Math.min(Math.max(0,c-Math.floor(Zl/2)),Math.max(0,e.length-Zl)),d=e.slice(u,u+Zl),m=u>0,h=u+Zl<e.length,p=(g,x)=>{const v=x?24:12;if(i===null)return v;const b=Math.abs(g-i),w=Math.max(0,16-b*6);return v+w};return n.jsx("div",{className:_("group/rail absolute top-0 z-10 hidden h-full w-14 @min-[52rem]:block",l?"right-0":"left-0"),children:n.jsx("div",{className:_("absolute top-1/2 -translate-y-1/2 opacity-0 transition-opacity duration-200 group-hover/rail:opacity-100",l?"right-2":"left-2"),onMouseLeave:()=>a(null),children:n.jsxs("div",{className:"relative flex flex-col justify-center gap-[5px]",style:{maskImage:m||h?`linear-gradient(to bottom, ${m?"transparent, black 24px":"black"}, ${h?"black calc(100% - 24px), transparent":"black"})`:void 0},children:[d.map((g,x)=>{const v=g.key===t,b=x===i;return n.jsx("button",{type:"button",onClick:()=>s(g.key),onMouseEnter:()=>a(x),className:_("flex h-[7px] w-10 items-center",l&&"justify-end"),children:n.jsx("span",{className:_("rounded-full transition-all duration-150",v||b?"h-[3px] bg-foreground":"h-[2px] bg-muted-foreground/40"),style:{width:p(x,v)}})},g.key)}),i!==null&&d[i]&&n.jsxs("div",{className:_("pointer-events-none absolute w-72 -translate-y-1/2 rounded-xl border bg-popover p-3 shadow-lg",l?"right-10":"left-10"),style:{top:`${(i+.5)/d.length*100}%`},children:[n.jsx("p",{className:"line-clamp-2 text-xs font-semibold",children:d[i].question}),d[i].answer&&n.jsx("p",{className:"mt-1 line-clamp-3 text-xs text-muted-foreground",children:d[i].answer})]})]})})})}const xb=200,gb=2e4,vb=3,oV=/^```/gm,zS=/^```/;function $S(e){return e.split(`
|
|
29
|
-
`).filter(t=>!zS.test(t)).length}function iV(e){const t=e.replace(/\r\n?/g,`
|
|
30
|
-
`).replace(/^\n+|\s+$/g,"");if(!t.trim())return null;const s=t.split(`
|
|
31
|
-
`),r=$S(t);if(r<=xb&&t.length<=gb)return{type:"quote",text:t};let o=0;for(let a=0;o<s.length&&!(!zS.test(s[o])&&++a>xb);o++);let i=s.slice(0,o).join(`
|
|
32
|
-
`).slice(0,gb);return(i.match(oV)?.length??0)%2===1&&(i+="\n```"),{type:"quote",text:i,originalLines:r}}function aV(e){const t=e.split(`
|
|
33
|
-
`);return t.length<=vb?{preview:e,clipped:!1}:{preview:t.slice(0,vb).join(`
|
|
34
|
-
`),clipped:!0}}function lV(e){const t=[];let s=0;for(const o of e.matchAll(/^```[^\n]*\n([\s\S]*?)\n?^```[ \t]*$/gm)){const i=e.slice(s,o.index).replace(/^\n|\n$/g,"");i&&t.push({type:"text",text:i}),t.push({type:"code",code:o[1]}),s=o.index+o[0].length}const r=e.slice(s).replace(/^\n/,"");return(r||t.length===0)&&t.push({type:"text",text:r}),t}const sh='[data-enso="code-block"]',VS="[data-quote-skip]",cV=new Set(["P","DIV","LI","UL","OL","TR","TABLE","BLOCKQUOTE","H1","H2","H3","H4","H5","H6","PRE"]);function wf(e){return e?e.nodeType===1?e:e.parentElement:null}function HS(e,t){return`\`\`\`${t??""}
|
|
35
|
-
${e.replace(/\n+$/,"")}
|
|
36
|
-
\`\`\``}function WS(e){if(e.nodeType===3)return e.textContent??"";if(!(e.nodeType===1||e.nodeType===11))return"";const t=e.nodeType===1?e:null;if(t?.tagName==="BUTTON"||t?.matches(VS))return"";if(t?.tagName==="BR")return`
|
|
37
|
-
`;if(t?.matches(sh)){const r=t.querySelector("pre")?.textContent??t.textContent??"";return`
|
|
38
|
-
${HS(r,t.getAttribute("data-language")??void 0)}
|
|
39
|
-
`}const s=[...e.childNodes].map(WS).join("");return t&&cV.has(t.tagName)?`${s}
|
|
40
|
-
`:s}function dV(e,t){if(!e||e.rangeCount===0||e.isCollapsed)return null;const s=wf(e.anchorNode),r=wf(e.focusNode);if(!s||!r||!t.contains(s)||!t.contains(r))return null;const o=s.closest("[data-nav-key]");if(!o||o!==r.closest("[data-nav-key]"))return null;const i=e.toString();if(!i.trim())return null;const a=e.getRangeAt(0),l=wf(a.commonAncestorContainer)?.closest(sh);if(l)return HS(i,l.getAttribute("data-language")??void 0);const c=a.cloneContents();return c.querySelector(`${sh}, ${VS}`)?WS(c).replace(/\n{3,}/g,`
|
|
41
|
-
|
|
42
|
-
`).trim():i}const vo=8,Qo=6;function uV(e,t,s,r,o=[]){const i=(b,w)=>Math.min(Math.max(vo,b),w),a=t.height-s.height-vo,l=t.width-s.width-vo,c=e.top-s.height-Qo,u=e.bottom+Qo,d=i((e.left+e.right)/2-s.width/2,l),m=(r?[u,c]:[c,u]).filter(b=>b>=vo&&b<=a),h=(b,w)=>o.find(j=>w<j.right&&w+s.width>j.left&&b<j.bottom&&b+s.height>j.top),p=m.map(b=>({top:b,left:d}));for(const b of m){const w=h(b,d);w&&p.push({top:b,left:w.right+Qo},{top:b,left:w.left-s.width-Qo})}const g=i((e.top+e.bottom)/2-s.height/2,a);p.push({top:g,left:e.right+Qo},{top:g,left:e.left-s.width-Qo});const x=({top:b,left:w})=>b>=vo&&b<=a&&w>=vo&&w<=l&&!h(b,w),v=p.find(x);return v||{top:i(r||c<vo?u:c,a),left:d}}const bb={width:72,height:28};function fV(e,t){const s=[];for(const r of e.querySelectorAll("[data-quote-skip]")){const o=r.getBoundingClientRect();o.height>0&&o.bottom>0&&o.top<t&&s.push(o)}return s}function mV({containerRef:e}){const{t}=z(),s=pe(a=>a.quoteSelectionButton),r=Ho(),[o,i]=f.useState(null);return f.useEffect(()=>{if(!s){i(null);return}const a=()=>{const l=e.current,c=window.getSelection(),u=l?dV(c,l):null;if(!u||!c||!l){i(null);return}const d=c.getRangeAt(0).getBoundingClientRect(),m={width:window.innerWidth,height:window.innerHeight},h=fV(l,m.height);i({text:u,...uV(d,m,bb,r,h)})};return document.addEventListener("selectionchange",a),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("selectionchange",a),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[s,r,e]),!s||!o?null:So.createPortal(n.jsxs("button",{type:"button","data-enso":"quote-selection",title:t("Quote into the input box"),onMouseDown:a=>a.preventDefault(),onClick:()=>{const a=iV(o.text);!a||!x8(a)||(window.getSelection()?.removeAllRanges(),i(null))},style:{top:o.top,left:o.left,minWidth:bb.width},className:"fixed z-50 inline-flex h-7 items-center justify-center gap-1 rounded-full border bg-card px-2.5 text-xs text-foreground shadow-float hover:bg-muted",children:[n.jsx(BB,{className:"h-3 w-3"}),t("Quote")]}),document.body)}const Oc="You are a side conversation attached to a coding session. The main agent cannot see this thread. Do not continue the main task unless the user asks you to. Follow the same tool and skill constraints as the main session. Do not spawn subagents, coworkers, or workflows. Answer the user directly.";function US(e){return e.content.filter(t=>t.type==="text").map(t=>t.text??"").join("").trim()}function mee(e){const t=[];for(const s of e){if(s.role!=="user"&&s.role!=="assistant")continue;const r=US(s);r&&t.push(`${s.role==="user"?"User":"Assistant"}: ${r}`)}return t.slice(-40).join(`
|
|
43
|
-
`)}function hee(e){for(const t of[...e].reverse()){if(t.role!=="assistant")continue;const s=US(t);if(s)return s}return""}function pee(e,t){if(e!=="contextual")return Oc;const s=t.trim();return s?`${Oc}
|
|
44
|
-
|
|
45
|
-
# Main conversation (background only)
|
|
46
|
-
${s}`:Oc}function hV(e){return e.startsWith(Oc)}function xee(e){const t=e.trim();return t?`Treat the following as discussion context from a side conversation, not as work already completed.
|
|
47
|
-
|
|
48
|
-
`+t:""}function pV(e){const t=new Date(e),s=r=>String(r).padStart(2,"0");return`${s(t.getHours())}:${s(t.getMinutes())}:${s(t.getSeconds())}`}const yb={zh:{quit:"被关闭",update:"被关闭(安装更新)"},en:{quit:"was closed",update:"was closed (installing an update)"}};function xV(e){const t=pV(e.at),s=[...new Set(e.unfinishedTools)];if(e.lang==="en"){const i=`The app ${yb.en[e.kind]} at ${t} and this turn was interrupted.`,a=s.length>0?` ${s.length} tool call(s) never returned (${s.join(", ")}) and may have run halfway — check the result before continuing.`:"";return`${i}${a}`.trim()}const r=`应用在 ${t} ${yb.zh[e.kind]},这一轮被中断。`,o=s.length>0?`中断时有 ${s.length} 个工具调用没有结果(${s.join("、")}),可能只执行了一半,继续前请先检查。`:"";return`${r}${o}`}function gV(e){const t=xV(e);return e.lang==="en"?`${t} You can retry to continue.`:`${t}可以点重试继续。`}new TextEncoder;function jf(e){if(e)try{return decodeURIComponent(e)}catch{return e}}const kf="([A-Za-z0-9._@:+/=%-]+)",vV=new RegExp(String.raw`^\[(?:来自|From) ([^\]\n@·「」]{1,40}?)`+String.raw`(?: (私聊|private|群|group)(?:「([^」\]\n]{1,64})」)?)?`+`(?: chatId=${kf})?(?: topicId=${kf})?(?: senderId=${kf}| (发送者未知|sender unknown))?`+String.raw`(?: @([^\]\n@·]{1,32}?))?(?: · (\d{2}):(\d{2}))?\]\n`+String.raw`<untrusted-content source="([a-z0-9._:-]+?)(?::@[^"\n]{1,32})?(?: [^"\n]*)?">`+String.raw`([\s\S]*)<\/untrusted-content>((?:\n${m5})*)$`,"u");function bV(e){const t=vV.exec(e);if(!t)return null;const[,s="",r,o,i,a,l,c,u,d,m,h="",p="",g=""]=t,x=r==="私聊"||r==="private"?"private":r?"group":void 0,v={chat:jf(i),topic:jf(a),sender:jf(l)},b=u5(g),w=g?f5(g.slice(1)):null;return{channel:h,title:s,...v.chat?{chatId:v.chat}:{},...x?{chatType:x}:{},...x==="group"&&o?{chatTitle:o}:{},...v.topic?{topicId:v.topic}:{},...v.sender?{senderId:v.sender}:{},...c?{senderUnknown:!0}:{},...u?{username:u}:{},...d&&m?{time:`${d}:${m}`}:{},body:Qw(p),...b.length?{images:b}:{},...w?.length?{imageLines:w}:{}}}const yV="agent-notification|goal-continuation|coworker-hired|coworker-dismissed|background-task-update|session-updates|secretary-schedule|secretary-message",wV=new RegExp(`<(${yV})>\\n?([\\s\\S]*?)\\n?</\\1>`,"g"),jV=/\n(?=Work toward this goal autonomously\.|Continue working toward it\.)/;function kV(e){const s=(e.split(`
|
|
49
|
-
`).map(r=>r.trim()).find(Boolean)??"").split(/(?<=[。!?.!?])\s*/)[0]?.trim()??"";return s.length<=72?s:`${s.slice(0,72)}…`}function NV(e){const t=e.trim(),s=/^(?:Session goal(?: resumed)?:[ \t]*)([\s\S]*)$/.exec(t),r=(s?s[1]:t).trim(),o=r.search(jV);return o<0?{goal:r,instructions:""}:{goal:r.slice(0,o).trim(),instructions:r.slice(o).trim()}}function SV(e){const t=[],s=new RegExp(wV.source,"g");let r=0,o=!1;for(const i of e.matchAll(s)){o=!0;const a=i.index??0;a>r&&t.push({kind:"text",text:e.slice(r,a)});const l=i[1]??"",c=i[2]??"";l==="goal-continuation"?t.push({kind:"goal",...NV(c)}):l==="secretary-schedule"?t.push({kind:"schedule",raw:i[0]}):l==="session-updates"?t.push({kind:"updates",raw:i[0]}):t.push({kind:"notice",tag:l,body:c}),r=a+i[0].length}return o?(r<e.length&&t.push({kind:"text",text:e.slice(r)}),t):null}const CV=/^<\/?(?:agent-notification|goal-continuation|coworker-hired|coworker-dismissed|background-task-update|session-updates|secretary-schedule|secretary-message)>$/;function Ex(e){return e.split(`
|
|
50
|
-
`).filter(t=>!CV.test(t.trim())).join(`
|
|
51
|
-
`).trim()}function rh(e){return e.length<=72?e:`${e.slice(0,72)}…`}function IV(e){const t=e.trim(),s=t.indexOf(`
|
|
52
|
-
`),r=(s<0?t:t.slice(0,s)).trim(),o=r.indexOf(":");if(o>0&&o<=8){const i=r.slice(o+1).trim();if(i){const a=s<0?"":t.slice(s+1);return{summary:rh(i),body:a?`${i}
|
|
53
|
-
${a.trim()}`:i}}}return{summary:rh(r),body:t}}function TV(e){const t=Ex(e);return t?t.split(/\n(?=- \[schedule\])/).map(s=>IV(s.replace(/^- \[schedule\][ \t]?/,""))).filter(s=>s.body.length>0):[]}function AV(e){const t=Ex(e).replace(/^- \[[a-z-]+(?: session:[^\]]+)?\][ \t]?/gm,"").trim(),s=t.split(`
|
|
54
|
-
`).map(r=>r.trim()).find(Boolean);return{summary:rh(s??""),body:t}}const EV=/^<(session-updates|secretary-schedule)>\n([\s\S]*?)\n<\/\1>(?:\n|$)/,RV=/^- \[([a-z-]+)(?: (?:session|pending):([^\]\s]+))?\] ([^\n]*)(?:\n|$)/,MV=/^<untrusted-content source="[^"]*">/,wb="</untrusted-content>";function PV(e){return h5.includes(e)}function DV(e,t,s,r){return e==="secretary-schedule"?t==="schedule"&&!s?{kind:t,text:r}:null:t==="proposal"?s?null:{kind:t,text:r}:t==="pending"?{kind:t,text:r}:t==="ask-relay"?s?{kind:t,text:r,conversationId:s}:null:t==="leftover"?s?{kind:t,text:r,conversationId:s}:null:t==="queued"?s?{kind:t,text:r,conversationId:s}:null:PV(t)?s?{kind:t,text:r,conversationId:s}:{kind:t,text:r}:null}function OV(e,t){const s=[];let r=t;for(;r;){const o=RV.exec(r),i=o&&DV(e,o[1],o[2],o[3]);if(!o||!i)return null;r=r.slice(o[0].length);const a=MV.exec(r);if(a){const l=r.indexOf(wb);if(l<0)return null;if(i.detail=Qw(r.slice(a[0].length,l)),r=r.slice(l+wb.length),r.startsWith(`
|
|
55
|
-
`))r=r.slice(1);else if(r)return null}s.push(i)}return s.length>0?s:null}function qS(e){const t=[];let s=e.trim();for(;s;){const r=EV.exec(s),o=r&&OV(r[1],r[2]);if(!r||!o)return null;t.push(...o),s=s.slice(r[0].length)}return t.length>0?t:null}const LV="Shell read-only shortcut: prefer read (offset/limit) for files, grep for content, find for paths — the dedicated tools handle line ranges and stream far less output.",_V="Sleep-waiting in a foreground command costs a model round per check. Put the whole wait in one command that exits when the condition holds (e.g. `until <check>; do sleep 10; done; <report>`) and run it with background: true — you are notified when it finishes, then end your turn.",BV="timeout only kills the process; it does not keep this call in the foreground. If the command may outlast the yield, set background: true and end your turn — completion wakes you. Do not poll with sleep, ps, pgrep, or task_output loops.",FV=new Set([LV,_V,BV]);function zV(e){const t=e.split(`
|
|
56
|
-
`);let s=0;for(;s<t.length&&FV.has(t[s].replace(/\r$/,""));)s++;if(s===0)return e;for(;s<t.length&&!t[s].trim();)s++;return t.slice(s).join(`
|
|
57
|
-
`)||e}const $V=/^Command exited with code \d+$/,jb=/^Command (?:aborted|timed out after \d+ seconds|terminated without an exit code)/,VV=/^\[[^\]]+\]/,HV=/^at\s/,WV=/\b(?:error|fatal|panic|exception|failed|failure|cannot|not found|no such file|denied|refused)\b(?!\.\w|\()/i;function UV(e){const t=zV(e).split(/\r?\n/).map(r=>r.trim()),s=t.findLastIndex(r=>$V.test(r)||jb.test(r));if(s<0)return t.find(Boolean)??"";if(jb.test(t[s]))return t[s];for(let r=s-1;r>=0;r--){const o=t[r];if(o&&!VV.test(o)&&!HV.test(o)&&WV.test(o))return o}return t[s]}function qV({message:e}){const{t}=z(),s={queued:t("Queued"),running:t("In progress"),completed:t("Completed"),failed:t("Failed"),canceled:t("Canceled")},r=e.kind==="routine"?Uo:e.kind==="group"?Jr:e.kind==="delegation-task"?Ai:e.kind==="delegation-retry"||e.kind==="delegation-check-failed"?Mr:D_,o=e.kind==="routine"?`${e.dryRun?t("Routine dry run"):t("Routine task")} · ${e.title}`:e.kind==="group"?t("Group messages"):e.kind==="delegation-task"?t("Task from {{name}}",{name:e.from}):e.kind==="delegation-results"?t("Delegation results"):e.kind==="delegation-retry"?t("Continue delegated task"):e.kind==="delegation-check-failed"?t("Acceptance check not passed"):t("Result from {{name}}",{name:e.from});return n.jsxs("div",{"data-bot-injection":e.kind,className:"w-full rounded-lg border border-border/60 bg-muted/20 px-3 py-2 text-sm",children:[n.jsxs("div",{className:"mb-1 flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[n.jsx(r,{className:"size-3.5 shrink-0"}),n.jsx("span",{children:o}),e.kind==="delegation-result"&&e.status&&n.jsxs("span",{children:["· ",s[e.status]??e.status]})]}),n.jsx("div",{className:"whitespace-pre-wrap break-words",children:e.kind==="routine"?e.prompt:e.kind==="delegation-task"?e.task:e.kind==="delegation-result"||e.kind==="delegation-retry"||e.kind==="delegation-check-failed"?e.text:e.kind==="delegation-results"?e.results.map((i,a)=>n.jsxs("p",{children:[n.jsxs("span",{className:"font-medium",children:[i.from,i.status&&` · ${s[i.status]??i.status}`,":"]}),i.text]},`${a}:${i.from}`)):e.messages.map((i,a)=>n.jsxs("p",{children:[n.jsxs("span",{className:"font-medium",children:[i.from,":"]}),i.text]},`${a}:${i.from}`))}),e.kind==="delegation-task"&&e.context&&n.jsxs("details",{className:"mt-1.5 text-xs text-muted-foreground",children:[n.jsx("summary",{className:"cursor-pointer",children:t("Context")}),n.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words",children:e.context})]}),e.kind==="group"&&e.instruction&&n.jsxs("details",{className:"mt-1.5 text-xs text-muted-foreground",children:[n.jsx("summary",{className:"cursor-pointer",children:t("Instructions")}),n.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words",children:e.instruction})]}),e.kind==="group"&&!!e.refs?.length&&n.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:e.refs.map(i=>n.jsxs("span",{title:t("Referenced chat"),className:"inline-flex h-6 max-w-56 items-center gap-1 rounded-md bg-muted px-1.5 text-xs",children:[n.jsx(Jr,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:i.title})]},i.id))}),e.kind==="group"&&e.note&&n.jsx("p",{className:"mt-1.5 text-xs text-muted-foreground",children:t("Dispatch hint: {{note}}",{note:e.note})}),e.kind!=="group"&&!!e.group?.length&&n.jsxs("details",{className:"mt-1.5 text-xs text-muted-foreground",children:[n.jsxs("summary",{className:"cursor-pointer",children:[t("Group messages")," · ",e.group.length]}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words",children:e.group.map((i,a)=>n.jsxs("p",{children:[n.jsxs("span",{className:"font-medium",children:[i.from,":"]}),i.text]},`${a}:${i.from}`))})]})]})}async function GS(e,t){const s=await J.getState().reloadConversation(e);s&&Ie({type:"error",title:t("Failed to reload conversation"),description:s})}async function KS(e,t){const s=await J.getState().restartConversation(e);s&&Ie({type:"error",title:t("Failed to restart conversation"),description:s})}function GV(e,t){if(!t)return null;for(const[s,r]of Object.entries(e))if(r?.sessionFile===t)return s;return null}function KV(e,t,s){if(!t)return"";if(rm(t))return qc(s,t.modelId);const r=e.find(o=>o.id===t.providerId);return r?`${r.name} / ${t.modelId}`:t.modelId}const YV=new Set(["session_create","todo_item_dispatch","secretary_profile_propose","skill_propose","tool_propose","session_takeover_propose","cleanup_apply"]);function XV(e){if(!YV.has(e.name)||e.state==="running"||e.state==="error"||!e.output)return null;let t;try{t=JSON.parse(e.output)}catch{return null}if(!t||typeof t!="object")return null;const s=t;return s.status==="awaiting_confirmation"&&typeof s.proposalId=="string"?s.proposalId:null}const Ui={pending:"Waiting for your confirmation",executing:"Creating the session…",succeeded:"Session created",failed:"Failed",rejected:"Rejected",expired:"Expired"},QV={...Ui,executing:"Saving the profile…",succeeded:"Profile saved"};function Fo(e){return _("mb-1 w-full rounded-lg border px-2.5 py-2",e?"border-warning/40 bg-warning/5":"border-border/60 bg-muted/20")}function JV(e){return e.draft.title?.trim()||e.draft.prompt.split(`
|
|
58
|
-
`)[0]?.trim()||""}function ZV({proposalId:e,prominent:t}){const{t:s}=z(),r=kt(h=>h.secretary.proposals[e]),o=kt(h=>h.resolving[e]===!0),i=kt(h=>h.resolveProposal),a=pe(h=>h.projects),l=pe(h=>h.providers)??[],c=pe(h=>h.virtualModels);if(!r)return n.jsx("div",{"data-enso":"secretary-proposal",className:_(Fo(t),"text-[11px] text-muted-foreground"),children:s("Waiting for your confirmation")});if(r.kind==="profile")return n.jsx(eH,{proposal:r,prominent:t});if(r.kind==="skill")return n.jsx(iH,{proposal:r,prominent:t});if(r.kind==="tool")return n.jsx(oH,{proposal:r,prominent:t});if(r.kind==="takeover")return n.jsx(rH,{proposal:r,prominent:t});if(r.kind==="cleanup")return n.jsx(uH,{proposal:r,prominent:t});const u=a.find(h=>h.id===r.draft.projectId),d=r.status==="failed",m=KV(l,r.draft.model,c);return n.jsxs("div",{"data-enso":"secretary-proposal",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Dispatch")}),u&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:qn(u)}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:JV(r)}),n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:r.draft.worktree?s("Isolated worktree"):s("Project checkout")})]}),(r.draft.branch||r.draft.baseRef||m||(r.draft.after?.length??0)>0)&&n.jsxs("div",{"data-enso":"secretary-proposal-base",className:"mt-1 flex flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[r.draft.branch&&n.jsx("span",{children:r.draft.branch}),r.draft.baseRef&&n.jsx("span",{children:s("from {{ref}}",{ref:r.draft.baseRef})}),m&&n.jsx("span",{"data-enso":"secretary-proposal-model",children:s("Model: {{model}}",{model:m})}),r.draft.after&&r.draft.after.length>0&&n.jsx("span",{children:s("After {{ids}}",{ids:r.draft.after.join(", ")})})]}),n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",d?"text-destructive":"text-muted-foreground"),children:[s(Ui[r.status]),d&&r.error?` · ${r.error}`:""]}),r.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button",disabled:o,onClick:()=>{i(r.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Confirm dispatch")}),n.jsx("button",{type:"button",disabled:o,onClick:()=>{i(r.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")})]})]})]})}function eH({proposal:e,prominent:t}){const{t:s}=z(),r=kt(d=>d.resolving[e.id]===!0),o=kt(d=>d.resolveProposal),[i,a]=f.useState(!1),l=e.draft,c=e.status==="failed",u=f.useMemo(()=>({...p5(null,s("Secretary")),...l}),[l,s]);return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"profile",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Profile")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:l.name??s("Secretary")})]}),n.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[n.jsx("span",{children:s("Up to {{n}} at a time",{n:l.maxRunningDispatches??3})}),n.jsx("span",{"aria-hidden":!0,children:"·"}),n.jsx("span",{children:s(l.patrolEnabled===!1?"Patrol off":"Patrol on")}),n.jsx("span",{children:s(l.cleanupSkipConfirm?"Cleanup without confirmation":"Cleanup asks first")})]}),i?n.jsx("div",{className:"mt-2 border-t border-border/60 pt-2",children:n.jsx(Jw,{initialDraft:u,submitLabel:s("Confirm"),busy:r,onSubmit:d=>{a(!1),o(e.id,"confirm",void 0,d)},onCancel:()=>a(!1)})}):n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",c?"text-destructive":"text-muted-foreground"),children:[s(QV[e.status]),c&&e.error?` · ${e.error}`:""]}),e.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Confirm")}),n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")}),n.jsx("button",{type:"button","data-enso":"secretary-proposal-edit",disabled:r,onClick:()=>a(!0),className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Edit here")})]})]})]})}const tH={...Ui,executing:"Saving the skill…",succeeded:"Skill saved"},nH={...Ui,executing:"Saving the tool…",succeeded:"Tool saved"},sH={...Ui,executing:"Handing it over…",succeeded:"Handed over to the secretary"};function rH({proposal:e,prominent:t}){const{t:s}=z(),r=kt(c=>c.resolving[e.id]===!0),o=kt(c=>c.resolveProposal),a=pe(c=>c.projects).find(c=>c.id===e.draft.projectId),l=e.status==="failed";return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"takeover",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Take over")}),a&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:qn(a)}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e.draft.title??s("Unnamed")})]}),n.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground",children:[s("The secretary asks to manage this session: it may message and stop it like its own."),e.draft.reason?` ${e.draft.reason}`:""]}),n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",l?"text-destructive":"text-muted-foreground"),children:[s(sH[e.status]),l&&e.error?` · ${e.error}`:""]}),e.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Allow takeover")}),n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")})]})]})]})}function oH({proposal:e,prominent:t}){const{t:s}=z(),r=kt(l=>l.resolving[e.id]===!0),o=kt(l=>l.resolveProposal),i=e.draft,a=e.status==="failed";return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"tool",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Tool")}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:i.name}),n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:i.runtime==="python"?"Python":"Node"}),n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:i.readOnly?s("Read-only"):s("Asks every call")}),n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:e.previous?s("Update"):s("New")})]}),n.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:i.description}),n.jsxs("details",{className:"mt-1.5 rounded border border-border/60 bg-background/40 px-2 py-1",children:[n.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:s("Show the arguments")}),n.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre-wrap text-[11px]",children:JSON.stringify(i.parameters,null,2)})]}),n.jsxs("details",{className:"mt-1 rounded border border-border/60 bg-background/40 px-2 py-1",children:[n.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:s("Show the code")}),n.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre font-mono text-[11px]",children:i.code})]}),e.previous?n.jsxs("details",{className:"mt-1 rounded border border-border/60 bg-background/40 px-2 py-1",children:[n.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:s("Show the current version")}),n.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre font-mono text-[11px]",children:e.previous.code})]}):null,n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",a?"text-destructive":"text-muted-foreground"),children:[s(nH[e.status]),a&&e.error?` · ${e.error}`:""]}),e.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Confirm")}),n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")})]})]})]})}function iH({proposal:e,prominent:t}){const{t:s}=z(),r=kt(l=>l.resolving[e.id]===!0),o=kt(l=>l.resolveProposal),i=e.draft,a=e.status==="failed";return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"skill",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Skill")}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:i.name}),n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:e.previous?s("Update"):s("New")})]}),n.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:i.description}),n.jsxs("details",{className:"mt-1.5 rounded border border-border/60 bg-background/40 px-2 py-1",children:[n.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:s("Show the content")}),n.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre-wrap text-[11px]",children:i.body})]}),e.previous?n.jsxs("details",{className:"mt-1 rounded border border-border/60 bg-background/40 px-2 py-1",children:[n.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:s("Show the current version")}),n.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre-wrap text-[11px]",children:e.previous.body})]}):null,n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",a?"text-destructive":"text-muted-foreground"),children:[s(tH[e.status]),a&&e.error?` · ${e.error}`:""]}),e.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Confirm")}),n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")})]})]})]})}const aH={...Ui,executing:"Cleaning up…",succeeded:"Cleanup done"},kb={branch:"Branch",worktree:"Worktree",session:"Session"},lH={"not-merged":"Not merged yet","current-branch":"Currently checked out","used-by-worktree":"Used by a worktree","detached-head":"Detached HEAD","uncommitted-changes":"Has uncommitted changes"};function cH(e){return e===void 0?null:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${Math.round(e/1024)} KB`:`${e} B`}const dH=5;function uH({proposal:e,prominent:t}){const{t:s}=z(),r=kt(d=>d.resolving[e.id]===!0),o=kt(d=>d.resolveProposal),i=e.draft.items,a=i.slice(0,dH),l=i.length-a.length,c=e.status==="failed",u=i.reduce((d,m)=>(d[m.kind]=(d[m.kind]??0)+1,d),{});return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"cleanup",className:Fo(t),children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Clean up")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s("{{count}} items",{count:i.length})}),["branch","worktree","session"].map(d=>u[d]?n.jsxs("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[u[d]," ",s(kb[d])]},d):null)]}),n.jsxs("ul",{"data-enso":"secretary-cleanup-items",className:"mt-1.5 space-y-0.5",children:[a.map(d=>{const m=cH(d.sizeBytes),h=[d.mergedInto?.length?s("merged into {{refs}}",{refs:d.mergedInto.join(", ")}):null,m,d.blocked?s(lH[d.blocked]??d.blocked):null].filter(Boolean);return n.jsxs("li",{className:"flex min-w-0 items-baseline gap-1.5 text-[11px]",children:[n.jsx("span",{"data-enso":"secretary-cleanup-kind",className:"shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:s(kb[d.kind])}),n.jsx("span",{className:"min-w-0 truncate font-mono",children:d.name}),h.length>0&&n.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:h.join(" · ")})]},d.id)}),l>0&&n.jsx("li",{"data-enso":"secretary-cleanup-rest",className:"text-[11px] text-muted-foreground",children:s("and {{count}} more",{count:l})})]}),n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsxs("span",{className:_("text-[11px]",c?"text-destructive":"text-muted-foreground"),children:[s(aH[e.status]),c&&e.error?` · ${e.error}`:"",e.report?` · ${e.report}`:""]}),e.status==="pending"&&n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[n.jsx("button",{type:"button","data-enso":"secretary-cleanup-confirm",disabled:r,onClick:()=>{o(e.id,"confirm")},className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Confirm cleanup")}),n.jsx("button",{type:"button",disabled:r,onClick:()=>{o(e.id,"reject")},className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:s("Reject")})]})]})]})}async function fH(e){const t=/^data:([^;,]+);base64,(.*)$/s.exec(e);if(!t)return(await fetch(e)).blob();const s=atob(t[2]),r=new Uint8Array(s.length);for(let o=0;o<s.length;o++)r[o]=s.charCodeAt(o);return new Blob([r],{type:t[1]})}async function mH(e){const t=await fH(e);let s=t;if(t.type!=="image/png"){const r=await createImageBitmap(t),o=new OffscreenCanvas(r.width,r.height);o.getContext("2d")?.drawImage(r,0,0),r.close(),s=await o.convertToBlob({type:"image/png"})}await navigator.clipboard.write([new ClipboardItem({"image/png":s})])}function El({src:e,className:t,frameClassName:s,onError:r,alt:o="",lazy:i=!1,children:a,title:l}){const{t:c}=z(),[u,d]=f.useState(!1);Eh(u),f.useEffect(()=>{if(!u)return;const h=p=>{p.key==="Escape"&&d(!1)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[u]);const m=()=>{mH(e).then(()=>Ie({type:"success",title:c("Image copied")}),h=>Ie({type:"error",title:c("Could not copy image"),description:h instanceof Error?h.message:String(h)}))};return n.jsxs(n.Fragment,{children:[n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsx("button",{type:"button",onClick:()=>d(!0),title:l,className:_("cursor-zoom-in",s),children:a??n.jsx("img",{src:e,alt:o,className:t,onError:r,...i?{loading:"lazy",decoding:"async"}:{}})}),onContextMenu:h=>h.stopPropagation()}),n.jsx(Qr,{className:"min-w-36",children:n.jsx(Kt,{closeOnClick:!0,onClick:m,children:c("Copy image")})})]}),u&&n.jsx("button",{type:"button",onClick:()=>d(!1),className:_("fixed inset-0 flex cursor-zoom-out items-center justify-center bg-black/75"),style:{zIndex:Pn.NESTED_MODAL_BACKDROP},"data-enso-float":"",children:n.jsx("img",{src:e,alt:"",className:"max-h-[92vh] max-w-[92vw] rounded-lg object-contain"})})]})}const hH={"too-large":"over 10 MB, not saved","not-image":"not a png / jpeg / webp / gif image, not saved",unavailable:"could not be saved"};function pH(e){return e.split(/[\\/]/u).pop()??e}function YS({entries:e,thumbnails:t=0,align:s="end"}){const{t:r}=z(),o=e.filter(a=>"path"in a&&a.index>t),i=e.filter(a=>"rejected"in a);return o.length===0&&i.length===0?null:n.jsxs("div",{"data-enso":"inbound-images",className:_("flex flex-col gap-1",s==="end"?"items-end":"items-start"),children:[o.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.map(a=>n.jsxs(El,{src:Wc(a.path),title:pH(a.path),frameClassName:"inline-flex h-6 items-center gap-1 rounded-md bg-muted px-1.5 text-xs text-muted-foreground hover:text-foreground",children:[n.jsx(x5,{className:"size-3 shrink-0"}),n.jsx("span",{children:r("Image {{n}}",{n:a.index})})]},a.index))}),i.map(a=>n.jsx("p",{className:"text-xs text-muted-foreground",children:r("Image {{n}} not accepted: {{reason}}",{n:a.index,reason:r(hH[a.rejected])})},a.index))]})}function xH(e){const s=(e.split(`
|
|
59
|
-
`).map(r=>r.replace(/^[#>\-*\s]+/u,"").trim()).find(Boolean)??"").replace(/\s+/gu," ");return s.length>60?`${s.slice(0,60)}…`:s}function gH({message:e}){const{t}=z(),s=e.username?`@${e.username}`:"";return n.jsxs("div",{"data-telegram-inbound":e.channel,className:"w-full rounded-lg border border-border/60 bg-muted/20 px-3 py-2 text-sm",children:[n.jsxs("details",{className:"group",children:[n.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[n.jsx(cu,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"shrink-0",children:e.channel==="telegram"?t("From Telegram"):t("From {{name}}",{name:e.title})}),s&&n.jsx("span",{className:"shrink-0 text-foreground",children:s}),e.time&&n.jsxs("span",{className:"shrink-0",children:["· ",e.time]}),n.jsx("span",{className:"min-w-0 truncate font-normal group-open:hidden",children:xH(e.body)})]}),n.jsx("div",{className:"mt-1.5 break-words",children:n.jsx(Dn,{text:e.body})})]}),e.imageLines&&n.jsx("div",{className:"mt-1.5",children:n.jsx(YS,{entries:e.imageLines,align:"start"})})]})}const XS=new Map;let ci;function vH(e){if(ci?.revision===e)return ci.request;const t=window.electronAPI.providers.listOauth().then(r=>{const o=new Map;for(const i of r)for(const a of i.accounts){if(typeof a.email!="string")continue;let l="";for(const c of a.email){const u=c.codePointAt(0)??0;u>=32&&u!==127&&(l+=c)}l=l.trim(),l&&o.set(a.key,l)}return{revision:e,emails:o}}).catch(r=>(console.error("Failed to load OAuth account metadata",r),{revision:e,emails:XS})),s={revision:e,request:t,data:void 0};return ci=s,t.then(r=>{ci===s&&(s.data=r)}),t}function bH(){const e=zo(r=>r.snapshot.revision),[t,s]=f.useState(()=>ci?.revision===e?ci.data:void 0);return f.useEffect(()=>{let r=!1;return vH(e).then(o=>{r||s(o)}),()=>{r=!0}},[e]),t?.revision===e?t.emails:XS}function Nb(e,t=0){let s=3735928559^t,r=1103547991^t;for(let o=0;o<e.length;o++){const i=e.charCodeAt(o);s=Math.imul(s^i,2654435761),r=Math.imul(r^i,1597334677)}return s=Math.imul(s^s>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(s^s>>>13,3266489909),(4294967296*(2097151&r)+(s>>>0)).toString(36)}function yH(e,t,s){return`${e}:${Nb(t)}:${Nb(s,1)}`}const wH=/(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c|$)/g,jH=/(?:\x1b\[|\x9b)[0-?]*[ -/]*(?:[@-~]|$)/g;function _s(e){return e.replace(wH,"").replace(jH,"")}const Ur=ro()(e=>({conversationId:null,result:null,tab:"session",from:null,open:(t,s,r)=>e({conversationId:t,result:s??null,tab:s?"result":"session",from:r??null}),setTab:t=>e({tab:t}),close:()=>e({conversationId:null,result:null,tab:"session",from:null})}));function kH(e,t,s){Ur.getState().open(e,t,s)}const Ii=ro()(()=>({back:null}));function oh(e){return J.getState().conversations[e]?.parentId??e}function Sb(e){const t=J.getState().conversations[e]?.projectId;return pe.getState().projects.some(s=>s.id===t&&s.kind==="secretary")}let Cb=!1;function NH(){Cb||(Cb=!0,J.subscribe((e,t)=>{if(e.activeId===t.activeId)return;const{back:s}=Ii.getState();s&&(!e.activeId||oh(e.activeId)!==s.to)&&Ii.setState({back:null})}))}function sl(e,t){const s=J.getState();if(!s.conversations[e])return;const r=t??s.activeId,o=r?oh(r):null,i=oh(e);NH(),Ur.getState().close(),s.selectConversation(e),Ii.setState({back:o&&o!==i&&Sb(o)&&!Sb(i)?{from:o,to:i}:null})}function SH(){const{back:e}=Ii.getState();e&&(Ii.setState({back:null}),J.getState().selectConversation(e.from))}function CH(e){if(typeof e.ttft=="number"&&e.ttft>0)return e.ttft;const t=e.timing;if(!(!t||t.firstTokenMs===void 0))return Math.max(0,t.firstTokenMs-t.stepStartMs)}function IH(e){if(typeof e.duration=="number"&&e.duration>0)return e.duration;const t=e.timing;if(!(!t||t.completedMs===void 0))return Math.max(0,t.completedMs-t.stepStartMs)}function TH(e){let t=0,s=0,r=0,o=0,i=0,a=0,l=0,c=0,u=0,d=0,m=0,h=0,p=null;for(const x of e){if(x.role==="user"&&(t+=1,p=null),x.role!=="assistant")continue;s+=1,x.usage&&(r+=x.usage.input,o+=x.usage.output,i+=x.usage.cacheRead,a+=x.usage.cacheWrite);const v=x.timing,b=IH(x);b!==void 0&&(l+=b);const w=CH(x);w!==void 0&&(u+=w,d+=1);const j=x.usage?.output??0;b!==void 0&&b>0&&j>0&&(m+=b,h+=j),v&&(p!==null&&(c+=Math.max(0,v.stepStartMs-p)),p=v.completedMs??null)}const g=r+i+a;return{turns:t,steps:s,llmMs:l,toolMs:c,inputTokens:g,outputTokens:o,cacheHitPercent:g===0?null:Math.round(i/g*100),ttftAvgMs:d>0?u/d:null,tokensPerSecond:m>0&&h>0?Math.round(h/(m/1e3)*10)/10:null}}function AH(e){return{inputTokens:e.inputTokens,outputTokens:e.outputTokens,...e.cacheHitPercent!==null?{cacheHitPercent:e.cacheHitPercent}:{},...e.ttftAvgMs!==null?{ttftAvgMs:e.ttftAvgMs}:{},...e.tokensPerSecond!==null?{tokensPerSecond:e.tokensPerSecond}:{}}}const EH={read_only:"Read-only",regenerable:"Regenerable output",reversible_workspace_change:"Reversible workspace change",data_loss:"Possible data loss",system_state:"Changes system state",exfiltration:"Sends data externally",unclear_target:"Unclear target or intent"};function RH({value:e}){const t=g5(e),{t:s}=z();if(!t)return null;const r=`allow ${t.allow.toFixed(2)} · ask ${t.ask.toFixed(2)} · block ${t.block.toFixed(2)}`;return n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 border-border/60 border-t px-3 py-1 text-[10px] text-muted-foreground","data-approval-review":t.verdict,children:[n.jsx("span",{className:"font-semibold tracking-wide text-foreground/75",children:t.verdict==="allow"?s("Auto-managed · allowed"):s("Auto-managed · denied")}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{className:"font-mono",children:t.model}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{className:"font-mono",children:r}),t.reason&&n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsxs("span",{children:[s("Reason"),": ",s(EH[t.reason])]})]})]})}function MH({ask:e,waiting:t}){const{t:s}=z(),r=e.answer!==null&&!e.options.includes(e.answer)?e.answer:null;return n.jsxs("div",{className:"space-y-1.5 px-3 py-2 text-xs",children:[n.jsx("p",{className:"whitespace-pre-wrap break-words leading-relaxed text-foreground",children:e.question}),(e.options.length>0||r!==null)&&n.jsxs("ul",{className:"space-y-0.5",children:[e.options.map(o=>n.jsx(Ib,{selected:o===e.answer,text:o},o)),r!==null&&n.jsx(Ib,{selected:!0,text:r,label:e.options.length>0&&!e.autoSelected?s("Custom answer"):void 0})]}),e.autoSelected&&n.jsx("p",{className:"text-muted-foreground",children:s("No answer in time; the default was selected")}),t&&e.answer===null&&n.jsx("p",{className:"text-muted-foreground",children:s("Waiting for your answer")})]})}function Ib({selected:e,text:t,label:s}){const{t:r}=z(),o=e?Bh:Jp;return n.jsxs("li",{"data-selected":e||void 0,className:_("flex items-start gap-1.5 rounded-md px-2 py-1 leading-relaxed",e?"bg-primary/10 text-foreground":"text-muted-foreground"),children:[n.jsx(o,{className:_("mt-0.5 h-3.5 w-3.5 shrink-0",e?"text-primary":"opacity-40")}),n.jsxs("span",{className:"min-w-0 whitespace-pre-wrap break-words",children:[s&&n.jsx("span",{className:"mr-1.5 text-muted-foreground",children:s}),t]}),e&&n.jsx("span",{className:"sr-only",children:r("Selected")})]})}const PH=/^Subagent ".*" \(agentId [^,\s]+, runId [^)\s]+\) \S+ after .+\.$/gm,DH=/^The following is the subagent's report: .*$\n?/m,OH=/<usage>([\s\S]*?)<\/usage>/,LH=/^Background tasks this subagent started\b.*\n((?:- .*(?:\n|$))+)/m,Nf=(e,t)=>{const s=new RegExp(`^${t}: (\\d+)$`,"m").exec(e);return s?Number(s[1]):null};function _H(e){const t=e.indexOf(`
|
|
60
|
-
`),s=t<0?e:e.slice(0,t);let r=t<0?"":e.slice(t+1),o=null,i=[];const a=OH.exec(r);if(a){const l=LH.exec(r.slice(a.index+a[0].length));l&&(i=l[1].split(`
|
|
61
|
-
`).filter(m=>m.startsWith("- ")).map(m=>m.slice(2))),r=r.slice(0,a.index);const c=Nf(a[1],"subagent_tokens"),u=Nf(a[1],"tool_uses"),d=Nf(a[1],"duration_ms");c!==null&&u!==null&&d!==null&&(o={tokens:c,toolUses:u,durationMs:d})}return{header:s,report:r.replace(DH,"").trim(),usage:o,...i.length>0?{tasks:i}:{}}}function BH(e){const t=e.trim(),s=[...t.matchAll(PH)].map(r=>r.index);return s[0]!==0?null:s.map((r,o)=>_H(t.slice(r,s[o+1]).replace(/\n+---\s*$/,"").trim()))}const FH=["system","memory","tools","skills","files","results","chat"];function QS(e){const t=e.contextWindow&&e.contextWindow>0?e.contextWindow:e.used;if(!(t>0))return[];const s=new Map;if(e.parts&&e.parts.length>0)for(const r of e.parts)s.set(r.kind,r.tokens);else{const{buckets:r}=e;s.set("system",r.system),s.set("memory",r.instructions+r.reminders),s.set("tools",r.tools),s.set("skills",r.skills),s.set("chat",r.conversation+r.compaction)}return FH.flatMap(r=>{const o=s.get(r)??0;return o<=0?[]:[{kind:r,tokens:o,width:Math.round(o/t*1e3)/10}]})}const ec=8,Tb=(e,t)=>e.reduce((s,r)=>s+(r.tag===t?r.n??1:1),0),Ab=e=>e.reduce((t,s)=>t+s.tokens,0);function Eb(e,t){const s=e?.find(o=>o.kind===t)?.items??[];if(s.length<=ec)return s;if(t==="chat"){const o=s.filter(c=>c.tag==="compacted"),i=s.filter(c=>c.tag!=="compacted"),a=ec-o.length-1,l=i.slice(0,i.length-a);return[...o,{name:"earlier",tag:"turns",n:Tb(l,"turns"),tokens:Ab(l)},...i.slice(i.length-a)]}const r=s.slice(ec-1);return[...s.slice(0,ec-1),{name:"other",tag:"more",n:Tb(r,"more"),tokens:Ab(r)}]}function zH(e){switch(e.tag){case"more":return{key:"{{count}} more",vars:{count:e.n??0}};case"turns":return{key:"Earlier {{count}} turns",vars:{count:e.n??0}};case"turn":return{key:"Turn {{count}}",vars:{count:e.name}};case"compacted":return{key:"Compacted summary"};case"reminder":return{key:"System reminders"};default:return{raw:e.name}}}function $H(e,t){return!e||e<=0||t===void 0||t>=e?null:Math.round((1-t/e)*100)}const Sf=e=>({type:"settings",link:{category:e,rowId:`${e}.root`}});function VH(e,t,s){const r=()=>{const o=v5(t.name,s);return o?{type:"file",rel:o}:null};switch(e){case"files":return t.tag==="read"||t.tag==="shell"?r():null;case"memory":return t.tag==="project"?r()??Sf("instructions"):null;case"tools":return t.tag==="more"?null:Sf(t.tag==="mcp"?"mcp":"tools");case"skills":return t.tag==="more"?null:Sf("skills");default:return null}}const JS="rounded-lg border border-border/60 bg-muted/20 px-2.5 py-1.5 text-xs";function ZS({className:e}){return n.jsx(Fi,{className:_("h-3.5 w-3.5 shrink-0 text-muted-foreground",e)})}const Rx="w-full overflow-hidden rounded-lg border border-dashed border-border/60 text-xs text-muted-foreground",Mx=_(Rx,"px-3 py-2"),vu="mt-0.5 h-3.5 w-3.5 shrink-0";function ih({hits:e,defaultOpen:t=!1}){const{t:s}=z();return e.length===0?n.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("No results")}):n.jsx("ul",{className:"divide-y divide-border/60",children:e.map(r=>n.jsx(WH,{hit:r,defaultOpen:t},r.id))})}function HH({view:e}){const{t}=z(),s=e.written?e.deduplicated&&t("Identical memory already exists, nothing new was written"):t("Similar memories already exist, nothing was written");return n.jsxs(n.Fragment,{children:[s&&n.jsx("p",{className:"px-3 pt-2 text-xs text-muted-foreground",children:s}),e.written?n.jsx(ih,{hits:[e.memory],defaultOpen:!0}):n.jsx(ih,{hits:e.candidates})]})}function WH({hit:e,defaultOpen:t}){const{t:s}=z(),[r,o]=f.useState(t);return n.jsx("li",{children:n.jsxs("button",{type:"button","aria-expanded":r,onClick:i=>{const a=window.getSelection();a?.toString()&&i.currentTarget.contains(a.anchorNode)||o(l=>!l)},className:"block w-full cursor-pointer px-3 py-2 text-left transition-colors hover:bg-muted/40",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx("span",{className:_("min-w-0 flex-1 font-medium text-foreground text-xs",r?"break-words":"truncate"),children:e.title}),e.unitType&&n.jsx(ji,{variant:"secondary",size:"sm",children:e.unitType}),e.space&&n.jsx(ji,{variant:"outline",size:"sm",children:s(e.space==="global"?"Global":"Project")}),e.relevance!==null&&n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",title:s("Semantic similarity"),children:e.relevance.toFixed(2)})]}),n.jsx("span",{className:_("mt-0.5 whitespace-pre-wrap break-words text-muted-foreground text-xs leading-relaxed",r?"block":"line-clamp-2"),children:e.content})]})})}const UH={"agent-type":"bg-purple-500/15 text-purple-600 dark:text-purple-400",file:"bg-success/15 text-success",chat:"bg-warning/25 text-warning-foreground dark:bg-warning/15 dark:text-warning","ui-element":"bg-purple-500/15 text-purple-600 dark:text-purple-400"};function bu(e){return _("inline-flex max-w-52 items-center gap-1 rounded-md px-1.5 py-0.5 align-middle text-xs font-medium",UH[e])}function qH({label:e,onRemove:t}){return n.jsx("button",{type:"button",onClick:t,className:"rounded-sm opacity-70 transition-opacity hover:opacity-100","aria-label":e,children:n.jsx(Jt,{className:"h-3 w-3"})})}function GH({recipient:e,onRemove:t}){const{t:s}=z();return n.jsxs("span",{className:_(bu("agent-type"),"mt-0.5 shrink-0"),children:[n.jsx(ws,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:e.label}),n.jsx(qH,{label:s("Remove Agent recipient"),onRemove:t}),n.jsx("span",{className:"sr-only",children:e.typeKey})]})}const eC=f.createContext(void 0);function Rl(e){const t=f.useContext(eC);if(t===void 0&&!e)throw new Error(cl(50));return t}const KH=600,tC=300,YH={...y5,instantType:e=>e.instantType,adaptiveOrigin:e=>e.adaptiveOrigin,closeDelay:e=>e.closeDelay};class XH extends b5{constructor(t,s,r){const o=new N5;super(QH(t,o,s,r),JH(o),YH)}setOpen=(t,s)=>{const{inlineRectCoordsRef:r}=this.context;w5(this,t,s,{onBeforeDispatch(){const o=s.event;t&&s.reason===S5&&s.trigger&&"clientX"in o&&"clientY"in o&&r.current?.element!==s.trigger&&zN(r,s.trigger,o.clientX,o.clientY)}})}}function QH(e,t,s,r=!1){const o={...j5(),instantType:void 0,adaptiveOrigin:void 0,closeDelay:tC,...e};return o.floatingRootContext=k5(t,s,r),o}function JH(e){return{popupRef:f.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e,inlineRectCoordsRef:{current:void 0}}}function Rb(e){const{open:t,defaultOpen:s=!1,onOpenChange:r,onOpenChangeComplete:o,actionsRef:i,handle:a,triggerId:l,defaultTriggerId:c=null,children:u}=e,d=T5((b,w)=>new XH({open:s,openProp:t,activeTriggerId:c,triggerIdProp:l},b,w));d.useControlledProp("openProp",t),d.useControlledProp("triggerIdProp",l),d.useContextCallback("onOpenChange",r),d.useContextCallback("onOpenChangeComplete",o);const m=d.useState("open"),h=d.useState("activeTriggerId"),p=d.useState("mounted"),g=d.useState("payload");A5(d,{closeOnActiveTriggerUnmount:!0});const{forceUnmount:x}=E5(m,d,()=>{d.context.inlineRectCoordsRef.current=void 0});Fh(()=>{m&&h==null&&d.set("payload",void 0)},[d,h,m]),f.useImperativeHandle(i,()=>({unmount:x,close:()=>d.setOpen(!1,R5(M5))}),[x,d]);const v=m||p;return n.jsxs(eC.Provider,{value:d,children:[a&&n.jsx(P5,{handle:a,store:d}),v&&n.jsx(ZH,{store:d}),typeof u=="function"?u({payload:g}):u]})}function ZH({store:e}){const t=e.useState("floatingRootContext"),s=D5(t);return O5(e,{activeTriggerProps:s.reference,inactiveTriggerProps:s.trigger,popupProps:s.floating}),null}const e9=C5(function(t){return Rl(!0)?n.jsx(Rb,{...t}):n.jsx(I5,{children:n.jsx(Rb,{...t})})}),nC=f.createContext(void 0);function t9(){const e=f.useContext(nC);if(e===void 0)throw new Error(cl(48));return e}const n9=f.forwardRef(function(t,s){const{keepMounted:r=!1,...o}=t;return Rl().useState("mounted")||r?n.jsx(nC.Provider,{value:r,children:n.jsx(L5,{ref:s,...o})}):null}),s9=_5(function(t,s){const{render:r,className:o,delay:i,closeDelay:a,id:l,payload:c,handle:u,style:d,...m}=t,h=Rl(!0),g=B5(u)??h;if(!g)throw new Error(cl(89));const x=Zw(l),v=g.useState("isTriggerActive",x),b=g.useState("isOpenedByTrigger",x),w=g.useState("floatingRootContext"),j=g.context.inlineRectCoordsRef,T=f.useRef(null),N=i??KH,S=a??tC,{registerTrigger:I,isMountedByThisTrigger:k}=F5(x,T,g,{payload:c,closeDelay:S}),L=z5(w,{mouseOnly:!0,move:!1,handleClose:$5(),delay:()=>({open:N,close:S}),triggerElementRef:T,isActiveTrigger:v,isClosing:()=>g.select("transitionStatus")==="ending"}),F=V5(w,{delay:N}),A={open:b},M=g.useState("triggerProps",k),R=KF(j,b);return dl("a",t,{state:A,ref:[s,I,T],props:[L,F.reference,M,R,{id:x},m],stateAttributesMapping:H5})}),sC=f.createContext(void 0);function r9(){const e=f.useContext(sC);if(e===void 0)throw new Error(cl(49));return e}const o9=f.forwardRef(function(t,s){const{render:r,className:o,anchor:i,positionMethod:a="absolute",side:l="bottom",align:c="center",sideOffset:u=0,alignOffset:d=0,collisionBoundary:m="clipping-ancestors",collisionPadding:h=5,arrowPadding:p=5,sticky:g=!1,disableAnchorTracking:x=!1,collisionAvoidance:v=W5,style:b,...w}=t,j=Rl(),T=t9(),N=U5(),S=j.useState("open"),I=j.useState("mounted"),k=j.useState("floatingRootContext"),L=j.useState("instantType"),F=j.useState("transitionStatus"),A=j.useState("adaptiveOrigin"),M=j.context.inlineRectCoordsRef,R=q5({anchor:i,floatingRootContext:k,positionMethod:a,mounted:I,side:l,sideOffset:u,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:h,sticky:g,disableAnchorTracking:x,keepMounted:T,nodeId:N,collisionAvoidance:v,adaptiveOrigin:A,inline:YF(M)}),$=R.update;Fh(()=>{S&&I&&$()},[S,I,$]);const U={open:S,side:R.side,align:R.align,anchorHidden:R.anchorHidden,instant:L},q=G5(t,U,{styles:R.positionerStyles,transitionStatus:F,props:w,refs:[s,j.useStateSetter("positionerElement")],hidden:!I,inert:!S});return n.jsx(sC.Provider,{value:R,children:n.jsx(K5,{id:N,children:q})})}),i9=f.forwardRef(function(t,s){const{className:r,render:o,style:i,...a}=t,l=Rl(),{side:c,align:u}=r9(),d=l.useState("open"),m=l.useState("instantType"),h=l.useState("transitionStatus"),p=l.useState("popupProps"),g=l.useState("floatingRootContext"),x=l.useState("closeDelay");return Y5({open:d,ref:l.context.popupRef,onComplete(){d&&l.context.onOpenChangeComplete?.(!0)}}),X5(g,{closeDelay:x}),dl("div",t,{state:{open:d,side:c,align:u,instant:m,transitionStatus:h},ref:[s,l.context.popupRef,l.useStateSetter("popupElement")],props:[Q5,p,Z5(h),a],stateAttributesMapping:J5})}),Ml=e9;function Pl({...e}){return n.jsx(s9,{"data-slot":"preview-card-trigger",...e})}function yu({className:e,children:t,align:s="center",sideOffset:r=4,...o}){return n.jsx(n9,{children:n.jsx(o9,{align:s,className:"z-50","data-slot":"preview-card-positioner",sideOffset:r,children:n.jsx(i9,{className:_("relative flex w-64 origin-(--transform-origin) text-balance rounded-lg border bg-popover bg-clip-padding p-4 text-popover-foreground text-sm shadow-lg transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:bg-clip-border dark:before:shadow-[0_-1px_--theme(--color-white/8%)]",e),"data-slot":"preview-card-content",...o,children:t})})})}const Mb={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},a9={mask:Vd,warn:Do,block:ej},l9={mask:"Mask",warn:"Warn only",block:"Block"},c9={system:"System prompt",user:"Your message",tool_result:"Tool output",tool_args:"Tool arguments",assistant:"Earlier replies",tools:"Tool descriptions"};function d9({report:e}){const{t}=z(),s=eT(e);if(!s)return null;const r=a9[s],o=new Set(e.hits.map(i=>i.token)).size;return n.jsxs(Ml,{children:[n.jsxs(Pl,{render:n.jsx("span",{className:_("inline-flex shrink-0 items-center gap-0.5 text-[11px]",Mb[s]),"data-privacy-mask":s}),children:[n.jsx(r,{className:"size-3.5"}),n.jsx("span",{className:"tabular-nums",children:o})]}),n.jsxs(yu,{className:"max-h-(--available-height) w-72 flex-col overflow-y-auto overscroll-contain text-xs",children:[n.jsx("p",{className:"mb-1.5 font-medium",children:t("Privacy masking")}),n.jsx("ul",{className:"space-y-1",children:tT(e.hits).map(i=>n.jsxs("li",{className:"flex flex-wrap gap-x-2",children:[n.jsx("span",{className:Mb[i.action],children:t(l9[i.action])}),n.jsx("span",{children:i.kind}),n.jsx("span",{className:"text-muted-foreground",children:t(c9[i.where]??i.where)}),n.jsx("span",{className:"text-muted-foreground",children:i.values>1?t("{{count}} values",{count:i.values}):i.preview}),i.count>1&&n.jsxs("span",{className:"text-muted-foreground",children:["×",i.count]})]},`${i.action}-${i.kind}-${i.where}`))}),e.restored>0&&n.jsx("p",{className:"mt-1.5 text-muted-foreground",children:t("Restored {{count}} in the reply",{count:e.restored})})]})]})}function u9(e){const{inputTokens:t,outputTokens:s}=e;if(typeof t!="number"||!Number.isFinite(t)||t<0||typeof s!="number"||!Number.isFinite(s)||s<0)return null;const r=Math.max(0,t-s);return{tokens:r,percent:t>0?Math.round(r/t*100):null}}const f9={compressed:"Compressed",unchanged:"Unchanged",pending:"Background task started",bypassed:"Bypassed",unavailable:"Unavailable"};function m9({value:e}){const t=yF(e),{t:s}=z();if(!t)return null;const r=u9(t);return n.jsxs("div",{className:"border-border/60 border-t text-[10px] text-muted-foreground","data-rtk-status":t.status,children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 px-3 py-1",children:[n.jsx("span",{className:"font-semibold tracking-wide text-foreground/75",children:"RTK"}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:s(f9[t.status])}),r&&n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:s("~{{count}} tokens saved",{count:Vn(r.tokens)})}),r.percent!==null&&n.jsxs("span",{children:["(",r.percent,"%)"]})]})]}),n.jsxs("div",{className:"space-y-2 px-3 pb-2",children:[t.status==="pending"&&n.jsx("p",{className:"rounded bg-muted/40 px-2 py-1 text-foreground/80",children:s("This is the startup receipt; see the task_output result for final statistics.")}),(t.inputTokens!==void 0||t.reason)&&n.jsxs("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1",children:[t.inputTokens!==void 0&&t.outputTokens!==void 0&&n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:s("Input estimate")}),n.jsx("dd",{className:"font-mono text-foreground/80",children:s("{{count}} tokens",{count:Vn(t.inputTokens)})}),n.jsx("dt",{children:s("Output estimate")}),n.jsx("dd",{className:"font-mono text-foreground/80",children:s("{{count}} tokens",{count:Vn(t.outputTokens)})})]}),t.reason&&n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:s("Reason")}),n.jsx("dd",{className:"min-w-0 whitespace-pre-wrap text-foreground/80",children:t.reason})]})]})]})]})}function h9(e,t,s){if(e==null||t===void 0||t<=e)return null;const r=Math.max(0,t-s);return{remainingMs:r,fraction:Math.min(1,r/(t-e))}}function p9(e,t,s=NF){const r=t-e;return r>=s?r:null}const x9={exit_nonzero:"Exit {{code}}",deadline:"Killed at timeout",stopped_by_user:"Stopped by you",tty_required:"Needs terminal",auth_required:"Needs login",not_found:"Command not found",not_executable:"Not executable",binary_output:"Binary output",output_truncated:"Log truncated"},g9={deadline:"Killed when its timeout was reached. Raise the timeout or run it in the background.",tty_required:"Needs an interactive terminal. Use a non-interactive flag (such as --yes) or run it in your own terminal.",auth_required:"Needs credentials. Sign in from your own terminal, then retry.",not_found:"The program is not installed or not on PATH."},rC=600;function v9(e){return e?.kind==="deadline"?["background","timeout"]:[]}function b9(e,t,s){const r=`\`\`\`
|
|
62
|
-
${t}
|
|
63
|
-
\`\`\``;return e==="background"?s(`Rerun this command with background: true:
|
|
64
|
-
|
|
65
|
-
{{command}}`,{command:r}):s(`Rerun this command with timeout: {{seconds}}:
|
|
66
|
-
|
|
67
|
-
{{command}}`,{seconds:rC,command:r})}function y9(e,t,s){return t(e)?(s(),!0):!1}function w9(){const[e,t]=f.useState(()=>Date.now());return f.useEffect(()=>{const s=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(s)},[]),e}const ah=5,Pb=2*Math.PI*ah;function j9({startedAt:e,deadlineAt:t,output:s}){const{t:r}=z(),o=w9(),i=f.useRef({output:s,at:e??Date.now()});i.current.output!==s&&(i.current={output:s,at:Date.now()});const a=h9(e,t,o),l=p9(i.current.at,o);return!a&&l===null?null:n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[10px] text-muted-foreground/70 tabular-nums",children:[l!==null&&n.jsx("span",{"data-shell-quiet":!0,className:"rounded bg-muted px-1",children:r("No output for {{seconds}}s",{seconds:Math.floor(l/1e3)})}),a&&a.remainingMs>0&&n.jsxs("span",{className:"flex items-center gap-0.5",title:r("Moves to background in {{seconds}}s",{seconds:Math.ceil(a.remainingMs/1e3)}),children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:[n.jsx("circle",{cx:"6",cy:"6",r:ah,fill:"none",stroke:"currentColor",opacity:"0.25"}),n.jsx("circle",{cx:"6",cy:"6",r:ah,fill:"none",stroke:"currentColor",strokeDasharray:Pb,strokeDashoffset:Pb*(1-a.fraction),transform:"rotate(-90 6 6)"})]}),Math.ceil(a.remainingMs/1e3),"s"]})]})}function oC(e,t){return e.kind==="exit_nonzero"&&e.exitCode===void 0?t("Failed"):t(x9[e.kind],{code:e.exitCode??""})}function k9({failure:e}){const{t}=z();return n.jsx("span",{"data-shell-failure":e.kind,className:_("shrink-0 rounded px-1 text-[10px]",e.retryable?"bg-muted text-muted-foreground":"bg-destructive/10 text-destructive"),children:oC(e,t)})}function N9({warning:e}){const{t,locale:s}=z(),r=s==="zh"?Xw(e):{what:e.reason};return n.jsx("span",{"data-dcg-warning":e.ruleId,title:[r.what,r.why,e.ruleId].filter(Boolean).join(`
|
|
68
|
-
`),className:"shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:t("dcg notice")})}function S9({failure:e,command:t}){const{t:s}=z(),[r,o]=f.useState(!1);if(!e)return null;const i=g9[e.kind],a=v9(e);return n.jsxs("div",{"data-shell-status":e.kind,className:"mt-2 flex items-center gap-2 border-t border-current/10 pt-1.5 text-[11px] opacity-80",children:[n.jsx("span",{className:"shrink-0 font-medium",children:oC(e,s)}),i&&n.jsx("span",{className:"min-w-0 flex-1",children:s(i)}),a.map(l=>n.jsx("button",{type:"button","data-shell-rerun":l,onClick:()=>{y9(b9(l,t,s),$N,zi)},className:"flex shrink-0 items-center gap-1 underline-offset-2 hover:underline hover:opacity-100",children:l==="background"?s("Rerun in background"):s("Rerun with {{seconds}}s timeout",{seconds:rC})},l)),n.jsxs("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1e3)})},className:"ml-auto flex shrink-0 items-center gap-1 hover:opacity-100",title:s("Copy command"),children:[r?n.jsx(On,{className:"h-3 w-3"}):n.jsx(ul,{className:"h-3 w-3"}),s("Copy command")]})]})}function C9(e){return e.startsWith("/skill:")?"skill":e==="/goal"?"goal":"command"}function I9(e){return e.startsWith("/skill:")?e.slice(7):e.replace(/^\//,"")}function Sd(e){const t=/^\/skill:(\S+)(?:\s+([\s\S]*))?$/.exec(e);if(t)return{slash:`/skill:${t[1]}`,rest:t[2]??""};const s=/^\/([A-Za-z][\w:-]*)(?:\s+([\s\S]*))?$/.exec(e);return s?{slash:`/${s[1]}`,rest:s[2]??""}:{slash:null,rest:e}}const T9={skill:Bs,goal:Fi,command:RN},A9={skill:"bg-info/15 text-info",goal:"bg-warning/25 text-warning-foreground dark:bg-warning/15 dark:text-warning",command:"bg-foreground/10 text-foreground"};function iC(e,t=!1){return _("inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 align-middle text-xs font-medium",A9[e],t&&e==="skill"&&"hover:bg-info/25",t&&e==="goal"&&"hover:bg-warning/35 dark:hover:bg-warning/25",t&&e==="command"&&"hover:bg-foreground/15")}function Cd({name:e,className:t,interactive:s=!1,trailing:r}){const o=C9(e),i=T9[o];return n.jsxs("span",{className:_(iC(o,s),t),children:[n.jsx(i,{className:"h-3 w-3"}),I9(e),r]})}const E9={queued:["Queued","bg-muted-foreground"],running:["running","bg-amber-500"],awaiting_input:["awaiting input","bg-amber-500"],validating:["validating","bg-amber-500"],succeeded:["succeeded","bg-emerald-500"],failed:["failed","bg-destructive"],cancelled:["cancelled","bg-muted-foreground"],interrupted:["interrupted","bg-muted-foreground"],creating:["creating","bg-amber-500"],ready:["idle","bg-muted-foreground"],active:["running","bg-amber-500"],parked:["parked","bg-muted-foreground"],closed:["closed","bg-muted-foreground"]};function R9({view:e,titles:t}){const{t:s}=z();return n.jsxs("div",{className:"space-y-2 px-3 py-2 text-sm",children:[e.kind==="report"&&e.text&&n.jsx(Dn,{text:e.text}),e.kind==="report"&&e.value&&n.jsx(Dn,{text:`\`\`\`json
|
|
69
|
-
${e.value}
|
|
70
|
-
\`\`\``}),e.kind==="report"&&e.error&&n.jsx("p",{className:"whitespace-pre-wrap text-destructive",children:e.error}),e.runs.length>0&&n.jsx("ul",{className:"space-y-0.5 text-xs text-muted-foreground",children:e.runs.map(r=>n.jsx(M9,{run:r,title:t?.[r.agentId]},r.runId||r.agentId))}),e.kind==="list"&&e.runs.length===0&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s("No agents")}),e.kind==="wait"&&e.timedOut&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s("Timed out; unfinished agents keep running")}),e.kind==="wait"&&e.interrupted&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s("Wait was interrupted")}),n.jsxs("details",{className:"text-xs text-muted-foreground",children:[n.jsx("summary",{className:"cursor-pointer hover:text-foreground",children:s("Run info")}),n.jsx("pre",{className:"mt-1 whitespace-pre-wrap font-mono",children:e.info})]}),e.head&&n.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:e.head})]})}function M9({run:e,title:t}){const{t:s}=z(),[r,o]=E9[e.status]??[null,"bg-muted-foreground"],i=e.durationMs===null?"":s("took {{duration}}",{duration:Wn(e.durationMs)});return n.jsxs("li",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx("span",{className:_("h-1.5 w-1.5 shrink-0 rounded-full",o)}),t&&n.jsx("span",{className:"truncate text-foreground",children:t}),n.jsx("span",{className:"shrink-0",children:[r?s(r):e.status,i].filter(Boolean).join(" · ")})]})}const Px=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Db=e=>typeof e=="string"&&e.trim()?e:null;function lh(e){if(!Px(e))return null;const{agentId:t,runId:s,status:r,createdAt:o,startedAt:i,finishedAt:a}=e;if(typeof t!="string"||typeof s!="string"||typeof r!="string")return null;const l=typeof i=="number"?i:o;return{agentId:t,runId:s,status:r,durationMs:typeof a=="number"&&typeof l=="number"?Math.max(0,a-l):null}}const P9=new Set(["closed","parked","creating"]);function D9(e){if(!Px(e))return null;const{agentId:t,status:s,latestRun:r}=e;return typeof t!="string"||typeof s!="string"?null:(P9.has(s)?null:lh(r))??{agentId:t,runId:"",status:s,durationMs:null}}function O9(e,t){const s=nT(t);if(!s)return null;const{head:r,value:o}=s;if(e==="report"){const l=lh(o.run);if(!l)return null;const{text:c,value:u,error:d,...m}=o;return{kind:"report",head:r,runs:[l],text:Db(c),value:u==null?null:JSON.stringify(u,null,2),error:Db(d),info:JSON.stringify(m,null,2)}}if(e==="list"){if(!Array.isArray(o.agents))return null;const l=o.agents.flatMap(c=>D9(c)??[]);return l.length===o.agents.length?{kind:"list",head:r,runs:l,info:JSON.stringify(o,null,2)}:null}const i=e==="wait"?o:e===void 0?o.report:null;if(!Px(i)||!Array.isArray(i.runs))return(e===void 0||e==="resume")&&o.report===void 0&&typeof o.agentId=="string"&&typeof o.runId=="string"?{kind:"receipt",head:r,runs:[],info:JSON.stringify(o,null,2)}:null;const a=i.runs.flatMap(l=>lh(l)??[]);return a.length!==i.runs.length?null:{kind:"wait",head:r,runs:a,timedOut:i.timedOut===!0,interrupted:i.interrupted===!0,info:JSON.stringify(o,null,2)}}const L9={"restart-lost":"This subagent was started before EnsoCode restarted, and its record was lost in the restart","other-owner":"This subagent belongs to another conversation and cannot be controlled here","not-found":"This conversation has no subagent with this id (mistyped, or agentId and runId mixed up)"};function _9(e){const t=/^([a-z][a-z-]*):\s/u.exec(e?.trim()??"")?.[1];return t&&L9[t]||null}function B9({items:e,live:t=[],onOpen:s}){const{t:r}=z(),[o,i]=f.useState(!1);return n.jsxs("div",{"data-enso":"task-wrap-up","data-open":o?"true":"false",className:Mx,children:[n.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>i(a=>!a),className:"flex w-full items-start gap-2 text-left hover:text-foreground",children:[n.jsx(ja,{className:vu}),n.jsx("span",{className:"min-w-0 flex-1",children:r("{{count}} background tasks to wrap up: stop them or say why they keep running",{count:e.length})})]}),o&&n.jsx("ul",{className:"mt-1.5 space-y-1.5 border-t border-border/60 pt-1.5",children:e.map(a=>{const l=t.find(c=>c.taskId===a.taskId);return n.jsx(F9,{item:a,command:l?.command??a.command,onOpen:l?.status==="running"?s:void 0},a.taskId)})})]})}function F9({item:e,command:t,onOpen:s}){const{t:r}=z(),[o,i]=f.useState(!1);return n.jsxs("li",{"data-enso":"task-wrap-up-item","data-task-id":e.taskId,className:"flex min-w-0 gap-2",children:[n.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>i(a=>!a),className:"min-w-0 flex-1 text-left hover:text-foreground",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:"min-w-0 truncate font-mono text-[11px] text-foreground",children:e.taskId}),e.ran&&n.jsx("span",{className:"shrink-0",children:r("Running for {{duration}}",{duration:e.ran})})]}),n.jsx("span",{"data-enso":"task-wrap-up-command",title:t,className:_("block font-mono text-[11px]",o?"whitespace-pre-wrap break-all":"truncate"),children:t})]}),s&&n.jsx("button",{type:"button","data-enso":"task-wrap-up-open",title:r("Show in task bar"),"aria-label":r("Show in task bar"),onClick:()=>s(e.taskId),className:"flex size-5 shrink-0 items-center justify-center rounded-[5px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Bi,{className:"h-3.5 w-3.5"})})]})}function z9({command:e,output:t,failure:s}){const r=pe(a=>a.terminalTheme),o=pe(a=>a.terminalFontFamily),i=tj(r)??sT;return n.jsxs("div",{"data-slot":"terminal-output",className:"px-3 py-2 text-xs leading-relaxed",style:{backgroundColor:i.background,"--terminal-bg":i.background,color:i.foreground,fontFamily:o},children:[n.jsxs("div",{className:"whitespace-pre-wrap [overflow-wrap:anywhere]",children:[n.jsx("span",{style:{color:i.green},children:"$ "}),e]}),t&&n.jsx("pre",{className:"mt-1 whitespace-pre-wrap [overflow-wrap:anywhere]",style:{fontFamily:"inherit"},children:_s(t)}),n.jsx(S9,{failure:s,command:e})]})}function $9(e){for(let t=e.length-1;t>=0;t-=1){const s=e[t];if(!(s.role!=="toolResult"||s.toolName!=="todo"||!s.todos))return s.todos.some(r=>r.status!=="completed")?{id:s.toolCallId??String(t),todos:s.todos}:null}return null}function aC({todos:e}){return n.jsx("ul",{className:"space-y-0.5 text-xs",children:e.map(t=>n.jsxs("li",{className:"flex items-start gap-1.5",children:[t.status==="completed"?n.jsx(On,{className:"mt-0.5 h-3 w-3 shrink-0 text-brand"}):t.status==="in_progress"?n.jsx(p_,{className:"mt-0.5 h-3 w-3 shrink-0 text-brand"}):n.jsx(Jp,{className:"mt-0.5 h-3 w-3 shrink-0 text-muted-foreground/50"}),n.jsx("span",{className:_(t.status==="completed"?"text-muted-foreground line-through":t.status==="in_progress"?"font-medium":"text-muted-foreground"),children:t.content})]},t.content))})}function lC({done:e,total:t,className:s}){return n.jsx("div",{className:_("h-0.5 overflow-hidden rounded-full bg-border",s),children:n.jsx("div",{className:"h-full rounded-full bg-brand transition-[width]",style:{width:`${t?e/t*100:0}%`}})})}const Ob=new Set;function V9({conversationId:e}){const{t}=z(),s=pe(d=>d.pinUnfinishedTodos),r=J(d=>d.conversations[e]?.messages),o=f.useMemo(()=>s&&r?$9(r):null,[s,r]),[i,a]=f.useState(!1),[,l]=f.useState(0);if(!o||Ob.has(o.id))return null;const c=o.todos.filter(d=>d.status==="completed").length,u=o.todos.find(d=>d.status==="in_progress")??o.todos.find(d=>d.status==="pending");return n.jsxs("div",{"data-enso":"todo",className:"mb-1.5 rounded-xl border bg-card px-3 py-1.5 text-xs shadow-xs",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>a(d=>!d),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx(nj,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 font-medium",children:t("Todos")}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground tabular-nums",children:[c,"/",o.todos.length]}),!i&&u&&n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:u.content,children:u.content}),i?n.jsx(Fn,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-muted-foreground"}):n.jsx(fn,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),n.jsx("button",{type:"button",title:t("Hide until the todo list updates"),onClick:()=>{Ob.add(o.id),l(d=>d+1)},className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]}),i&&n.jsxs("div",{className:"mt-1.5 max-h-48 overflow-y-auto pb-0.5",children:[n.jsx(lC,{done:c,total:o.todos.length,className:"mb-2"}),n.jsx(aC,{todos:o.todos})]})]})}function cC({image:e,path:t,alt:s}){const{t:r}=z(),o=f.useMemo(()=>oT(e,t),[e,t]),[i,a]=f.useState(!1);return!o||i?n.jsx("p",{"data-slot":"tool-image-missing",className:"text-xs text-muted-foreground",children:r("Image unavailable")}):n.jsx(El,{src:o,alt:s,lazy:!0,onError:()=>a(!0),frameClassName:"block max-w-full",className:"block max-h-64 max-w-full rounded-md border border-border/60 bg-muted/40 object-contain"})}function H9({image:e,output:t}){const{t:s}=z(),r=f.useMemo(()=>rT(t),[t]),o=[];return r?.path&&o.push([s("Path"),r.path]),r?.width&&r.height&&o.push([s("Dimensions"),`${r.width} × ${r.height}`]),r?.size!==null&&r?.size!==void 0&&o.push([s("File size"),sj(r.size)]),n.jsxs("div",{"data-slot":"image-view",className:"space-y-2 px-3 py-2",children:[n.jsx(cC,{image:e,path:r?.path,alt:r?.path??""}),o.length>0?n.jsx("dl",{className:"space-y-0.5 text-xs",children:o.map(([i,a])=>n.jsxs("div",{className:"flex min-w-0 gap-2",children:[n.jsx("dt",{className:"shrink-0 text-muted-foreground",children:i}),n.jsx("dd",{className:"min-w-0 break-all font-mono",children:a})]},i))}):null]})}function W9(){const e=J(o=>o.conversations),t=pe(o=>o.projects),s=kt(o=>o.secretary.board.todos),r=kt(o=>o.secretary.proposals);return{sessionTitle(o){return e[o]?.title?.trim()||void 0},projectName(o){const i=t.find(l=>l.id===o);return i?.alias?.trim()||i?.name?.trim()||void 0},todoText(o){return s.find(i=>i.id===o)?.text},proposal(o){const i=r[o];return i?{status:i.status,kind:i.kind}:void 0}}}function U9(e){const t=e.cardPeers??[];return[{name:e.name,args:e.args??null,output:e.output,state:e.state,...e.image?{image:e.image}:{}},...t.map(s=>({name:e.name,args:s.args??null,output:s.output,state:s.state,...s.image?{image:s.image}:{}}))]}function q9({item:e,framed:t=!1}){const{t:s,locale:r}=z(),o=W9(),i=J(m=>m.conversations),a=iT(U9(e),{t:s,locale:r==="zh"?"zh":"en",lookup:o}),l=aT(a.cards.map(m=>m.state)),[c,u]=f.useState(!1),d=a.grouped?null:a.cards[0]??null;return n.jsxs("div",{"data-enso":"tool-card","data-tool":e.name,"data-open":c?"true":"false","data-grouped":a.grouped?"true":"false","data-count":a.cards.length,className:"my-0.5 w-full min-w-0 text-[13px]",children:[n.jsxs("button",{type:"button","data-enso":"tool-card-expand","aria-expanded":c,onClick:()=>u(m=>!m),className:"group/step flex min-h-6 w-full min-w-0 items-center gap-2 text-left text-[13px] text-muted-foreground",children:[n.jsx(ix,{state:l}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:a.grouped?a.title:d?.title}),d?.status?n.jsx(dC,{status:d.status}):null,n.jsx(fn,{className:_("h-3 w-3 shrink-0 opacity-0 transition-[opacity,transform] group-hover/step:opacity-100",c&&"rotate-90 opacity-100")})]}),c&&a.grouped?a.cards.map((m,h)=>n.jsx(G9,{card:m,known:i,onOpen:sl,framed:t},`${m.title}-${h}`)):null,c&&d?n.jsx(uC,{card:d,known:i,onOpen:sl,framed:t}):null]})}function dC({status:e}){return n.jsx("span",{"data-enso":"tool-card-status","data-tone":e.tone,className:_("shrink-0 rounded px-1 py-px text-[10px]",e.tone==="error"&&"bg-destructive/15 text-destructive",e.tone==="ok"&&"bg-success/15 text-success",(e.tone==="queued"||e.tone==="pending")&&"bg-warning/15 text-warning",e.tone==="neutral"&&"bg-muted text-muted-foreground"),children:e.label})}function G9({card:e,known:t,onOpen:s,framed:r}){const[o,i]=f.useState(!1);return n.jsxs("div",{className:"pl-5",children:[n.jsxs("button",{type:"button","data-enso":"tool-card-expand","aria-expanded":o,onClick:()=>i(a=>!a),className:"group/step flex min-h-6 w-full min-w-0 items-center gap-2 text-left text-[13px] text-muted-foreground",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e.title}),e.status?n.jsx(dC,{status:e.status}):null,n.jsx(fn,{className:_("h-3 w-3 shrink-0 opacity-0 transition-[opacity,transform] group-hover/step:opacity-100",o&&"rotate-90 opacity-100")})]}),o?n.jsx(uC,{card:e,known:t,onOpen:s,framed:r,nested:!0}):null]})}function uC({card:e,known:t,onOpen:s,framed:r,nested:o=!1}){const{t:i}=z(),[a,l]=f.useState(!1),c=n.jsx("button",{type:"button","data-enso":"tool-card-raw","aria-expanded":a,onClick:()=>l(m=>!m),className:"text-[11px] text-muted-foreground hover:text-foreground",children:i("View raw data")}),u=a?n.jsxs("div",{className:_("mt-1 space-y-1",r&&"max-h-60 overflow-auto"),children:[e.rawArgs&&n.jsx("pre",{className:"overflow-auto font-mono text-[10px] leading-relaxed text-muted-foreground whitespace-pre-wrap",children:e.rawArgs}),e.rawOutput&&n.jsx("pre",{className:"overflow-auto font-mono text-[10px] leading-relaxed text-muted-foreground whitespace-pre-wrap",children:e.rawOutput})]}):null,d=(m,h)=>n.jsx(Q9,{block:m,known:t,onOpen:s},`${m.kind}-${h}`);if(r){const m=[];e.blocks.forEach((x,v)=>{const b=x.kind==="prompt",w=m.at(-1);!b&&w&&!w.prompt?w.blocks.push([x,v]):m.push({prompt:b,blocks:[[x,v]]})});const h=m.at(-1),p=!h||h.prompt,g=n.jsxs("div",{children:[c,u]});return n.jsxs("div",{"data-enso":"tool-card-body","data-framed":"true",className:_("mt-1 mb-1.5 min-w-0 overflow-hidden rounded-lg border border-border/70 bg-card text-[12px]",!o&&"ml-5"),children:[m.map((x,v)=>n.jsxs("div",{className:_("min-w-0",v>0&&"border-t border-border/60",!x.prompt&&"space-y-1.5 px-3 py-2"),children:[x.blocks.map(([b,w])=>b.kind==="prompt"?n.jsx(fC,{label:b.label,text:b.text},w):d(b,w)),!p&&x===h?g:null]},v)),p?n.jsx("div",{className:_("px-3 py-2",h&&"border-t border-border/60"),children:g}):null]})}return n.jsxs("div",{"data-enso":"tool-card-body",className:"space-y-1 py-0.5 pl-5 text-[12px]",children:[n.jsx("div",{className:"space-y-1",children:e.blocks.map(d)}),n.jsx("button",{type:"button","data-enso":"tool-card-raw","aria-expanded":a,onClick:()=>l(m=>!m),className:"mt-1 text-[11px] text-muted-foreground hover:text-foreground",children:i("View raw data")}),u]})}const K9={"--chat-h1-size":"1em","--chat-h2-size":"1em","--chat-h3-size":"1em","--chat-h4-size":"1em","--chat-code-block-size":"11px"},Lb=4;function Y9(e){const t=e.split(`
|
|
71
|
-
`).filter(s=>s.trim()&&!/^\s*(```|~~~)/.test(s)).map(s=>s.replace(/^\s*#{1,6}\s+/,"").trimEnd());return{preview:t.slice(0,Lb).join(`
|
|
72
|
-
`),folded:t.length>Lb||e.length>320}}function fC({label:e,text:t}){const{t:s}=z(),{preview:r,folded:o}=Y9(t),[i,a]=f.useState(!1),l=i||!o;return n.jsxs("section",{"data-enso":"tool-card-prompt","data-open":l?"true":"false",className:"min-w-0",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-3 pt-1.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"min-w-0 truncate",children:e}),n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2.5",children:[o&&n.jsx("button",{type:"button","data-enso":"tool-card-prompt-toggle","aria-expanded":i,onClick:()=>a(c=>!c),className:"hover:text-foreground",children:s(i?"Show less":"Show full text")}),n.jsx($d,{text:t,label:s("Copy")})]})]}),l?n.jsx("div",{"data-enso":"tool-card-prompt-body",style:K9,className:"max-h-80 min-w-0 overflow-y-auto overscroll-contain px-3 pt-1 pb-2 text-xs leading-relaxed [&_:is(h1,h2,h3,h4)]:mt-2.5 [&_:is(h1,h2,h3,h4)]:mb-1 [&_[data-enso=code-block]>:first-child]:border-0",children:n.jsx(Dn,{text:t})}):n.jsx("button",{type:"button","data-enso":"tool-card-prompt-preview",onClick:()=>a(!0),className:"line-clamp-4 block w-full min-w-0 px-3 pt-1 pb-2 text-left text-xs leading-relaxed text-muted-foreground break-words whitespace-pre-wrap",children:r})]})}function X9({row:e}){const{t}=z(),[s,r]=f.useState(!1),o=e.display==="long"&&(e.value.length>120||e.value.includes(`
|
|
73
|
-
`));return n.jsxs("div",{className:"contents",children:[n.jsx("dt",{className:"whitespace-nowrap text-muted-foreground",children:e.label}),n.jsxs("dd",{"data-enso":"tool-card-kv-value","data-display":e.display,title:e.display==="path"?e.value:void 0,className:_("min-w-0",e.display==="path"?"truncate":"whitespace-pre-wrap break-words"),children:[o&&!s?n.jsx("span",{className:"line-clamp-2",children:e.value}):e.value,o&&n.jsx("button",{type:"button","data-enso":"tool-card-kv-toggle","aria-expanded":s,onClick:()=>r(i=>!i),className:"block text-[11px] text-muted-foreground hover:text-foreground",children:t(s?"Show less":"Show more")})]})]})}function Q9({block:e,known:t,onOpen:s}){const{t:r}=z(),[o,i]=f.useState(!1);if(e.kind==="error")return n.jsx("p",{className:"rounded-md bg-destructive/10 px-2 py-1 text-destructive text-xs whitespace-pre-wrap",children:e.text});if(e.kind==="note")return n.jsx("p",{className:"whitespace-pre-wrap text-xs",children:e.text});if(e.kind==="prompt")return n.jsx(fC,{label:e.label,text:e.text});if(e.kind==="markdown"){const a=e.collapsed&&!o;return n.jsxs("div",{className:"text-sm",children:[a?n.jsx("p",{className:"truncate text-xs text-muted-foreground",children:e.text.split(`
|
|
74
|
-
`).find(l=>l.trim())}):n.jsx(Dn,{text:e.text}),e.collapsed&&n.jsx("button",{type:"button","data-enso":"tool-card-fold",onClick:()=>i(l=>!l),className:"text-[11px] text-muted-foreground hover:text-foreground",children:r(o?"Show less":"Show more")})]})}return e.kind==="image"?n.jsx("div",{"data-enso":"tool-card-image",children:n.jsx(cC,{image:e.image,path:e.path,alt:e.alt})}):e.kind==="session"?t[e.id]?n.jsx("button",{type:"button","data-enso":"tool-card-session","data-conversation-id":e.id,onClick:()=>s(e.id),className:"truncate text-left text-xs text-foreground underline-offset-2 hover:underline",children:e.label}):n.jsx("p",{className:"text-xs",children:e.label}):e.kind==="kv"?n.jsx("dl",{className:"grid min-w-0 grid-cols-[auto_minmax(0,1fr)] gap-x-2 gap-y-0.5 text-xs",children:e.rows.map(a=>n.jsx(X9,{row:a},a.label))}):e.kind==="diff"?n.jsx("div",{className:"space-y-0.5 text-xs",children:e.rows.map(a=>n.jsxs("p",{className:"min-w-0 break-words",children:[n.jsxs("span",{className:"text-muted-foreground",children:[a.label," "]}),n.jsx("span",{className:"text-muted-foreground line-through",children:a.before}),n.jsxs("span",{children:[" → ",a.after]})]},a.label))}):e.kind!=="list"?null:n.jsx("ul",{className:"space-y-0.5",children:e.items.map((a,l)=>n.jsxs("li",{className:"flex min-w-0 items-baseline gap-1.5 text-xs",children:[a.sessionId&&t[a.sessionId]?n.jsx("button",{type:"button","data-enso":"tool-card-session","data-conversation-id":a.sessionId,onClick:()=>s(a.sessionId),className:"min-w-0 truncate text-left hover:underline",children:a.title}):n.jsx("span",{className:"min-w-0 truncate",children:a.title}),a.badge&&n.jsx("span",{"data-enso":"tool-card-badge","data-tone":a.badgeTone,className:_("shrink-0 rounded px-1 py-px text-[10px]",a.badgeTone==="error"&&"bg-destructive/15 text-destructive",a.badgeTone==="ok"&&"bg-success/15 text-success",a.badgeTone==="pending"&&"bg-warning/15 text-warning",(!a.badgeTone||a.badgeTone==="neutral"||a.badgeTone==="queued")&&"bg-muted text-muted-foreground"),children:a.badge}),a.detail&&n.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:a.detail})]},`${a.title}-${l}`))})}const J9={report:()=>{},scroller:{current:null}},mC=f.createContext(J9),Z9=mC.Provider;function e7(){return f.useContext(mC)}const _b=f.lazy(()=>Hd(()=>import("./EditDiff-C9JBUR0o.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(e=>({default:e.EditDiff}))),Cf=f.lazy(()=>Hd(()=>import("./ReadFileView-C5AKNlFU.js"),__vite__mapDeps([5,1,2,6,4]),import.meta.url).then(e=>({default:e.ReadFileView}))),t7=(e,t)=>e===t||!!e&&!!t&&e.runMs===t.runMs&&e.turnMs===t.turnMs&&e.ttftMs===t.ttftMs&&e.tps===t.tps;function n7(e,t){const s=e??[],r=t??[];return s.length===r.length&&s.every((o,i)=>{const a=r[i];return a!==void 0&&o.key===a.key&&o.state===a.state&&o.output===a.output&&o.image?.data===a.image?.data&&JSON.stringify(o.args??null)===JSON.stringify(a.args??null)})}function s7(e,t){if(e.secretarySession!==t.secretarySession)return!1;const s=e.item,r=t.item;if(s===r)return!0;if(s.kind!==r.kind||s.key!==r.key)return!1;switch(s.kind){case"user":return r.kind!=="user"||s.text!==r.text||s.images.length!==r.images.length||s.timestamp!==r.timestamp||s.deliveryState!==r.deliveryState||s.turnDurationMs!==r.turnDurationMs||s.collapsed!==r.collapsed||s.canCollapse!==r.canCollapse||s.hostTaskWrapUp!==r.hostTaskWrapUp?!1:s.images.every((o,i)=>o===r.images[i]);case"text":case"thinking":return r.kind===s.kind&&s.text===r.text&&s.streaming===r.streaming&&(s.kind!=="text"||r.kind==="text"&&t7(s.perf,r.perf)&&s.timestamp===r.timestamp&&s.turnDurationMs===r.turnDurationMs)&&(s.kind!=="thinking"||r.kind==="thinking"&&s.durationMs===r.durationMs);case"tool":return r.kind==="tool"&&s.state===r.state&&s.name===r.name&&s.summary===r.summary&&s.output===r.output&&s.edits===r.edits&&s.writeContent===r.writeContent&&s.fileChanges===r.fileChanges&&s.imagePath===r.imagePath&&s.image?.data===r.image?.data&&s.image?.mimeType===r.image?.mimeType&&s.generatedImages===r.generatedImages&&s.todos===r.todos&&s.durationMs===r.durationMs&&s.startedAt===r.startedAt&&s.agentMeta===r.agentMeta&&s.source===r.source&&s.nestedPending===r.nestedPending&&JSON.stringify(s.sandbox)===JSON.stringify(r.sandbox)&&s.rtk===r.rtk&&s.approvalReview===r.approvalReview&&s.plan?.title===r.plan?.title&&s.plan?.text===r.plan?.text&&s.sentMessage===r.sentMessage&&s.memoryContent===r.memoryContent&&s.ask?.question===r.ask?.question&&s.ask?.options.join(`
|
|
75
|
-
`)===r.ask?.options.join(`
|
|
76
|
-
`)&&s.ask?.answer===r.ask?.answer&&s.ask?.autoSelected===r.ask?.autoSelected&&s.subagentOp===r.subagentOp&&JSON.stringify(s.subagentTitles)===JSON.stringify(r.subagentTitles)&&s.waiting===r.waiting&&s.pluginArtifacts===r.pluginArtifacts&&s.shellFailure===r.shellFailure&&s.dcgWarning===r.dcgWarning&&JSON.stringify(s.args??null)===JSON.stringify(r.args??null)&&n7(s.cardPeers,r.cardPeers);case"tool-group":return r.kind==="tool-group"&&s.expanded===r.expanded&&s.count===r.count&&s.stats.commands===r.stats.commands&&s.stats.reads===r.stats.reads&&s.stats.searches===r.stats.searches&&s.stats.others===r.stats.others&&s.exploring===r.exploring&&s.live===r.live&&s.activity?.thinking===r.activity?.thinking&&s.activity?.workedMs===r.activity?.workedMs&&s.explore?.goal===r.explore?.goal&&s.explore?.report===r.explore?.report&&s.explore?.steps===r.explore?.steps&&s.notice===r.notice;case"error":return r.kind==="error"&&s.text===r.text;case"interrupted":return r.kind==="interrupted"&&s.at===r.at&&s.exitKind===r.exitKind&&s.unfinishedTools.length===r.unfinishedTools.length;case"task-note":return r.kind==="task-note"&&s.detail===r.detail;case"compaction":case"compaction-notice":return(r.kind==="compaction"||r.kind==="compaction-notice")&&s.kind===r.kind&&s.summary===r.summary&&s.tokensBefore===r.tokensBefore&&s.tokensAfter===r.tokensAfter&&s.verified===r.verified;case"compaction-progress":return r.kind==="compaction-progress"&&s.state===r.state;case"session-custom":return r.kind==="session-custom"&&s.entry===r.entry;case"divider":return r.kind==="divider"&&s.text===r.text;case"plugin-message":return r.kind==="plugin-message"&&s.text===r.text&&s.pluginId===r.pluginId;case"resumed-reply":return r.kind==="resumed-reply"&&s.expanded===r.expanded&&s.text===r.text&&s.thinking===r.thinking&&s.tools.length===r.tools.length;case"discarded-turn":return r.kind==="discarded-turn"&&s.expanded===r.expanded&&s.reason===r.reason&&s.messages.length===r.messages.length&&s.messages.every((o,i)=>o===r.messages[i])&&s.tools.length===r.tools.length}}const hC=/^<role>\n?([\s\S]*?)\n?<\/role>\s*/,r7=/^<workspace-migrated>\n?([\s\S]*?)\n?<\/workspace-migrated>\s*/,o7=/^<workspace-branch-changed>\n?([\s\S]*?)\n?<\/workspace-branch-changed>\s*/;function i7({note:e}){const{t}=z(),s=/on Git branch ("(?:[^"\\]|\\.)*")/.exec(e)?.[1];let r="";try{r=s?String(JSON.parse(s)):""}catch{}return n.jsxs("aside",{title:e,className:"flex w-full items-start gap-2 rounded-lg border border-dashed border-border/60 px-3 py-2 text-xs text-muted-foreground",children:[n.jsx(Hs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 break-all",children:r?t("Workspace switched to branch {{branch}}",{branch:r}):t("Workspace switched branch")})]})}function pC({items:e}){const t=js(),s=J(o=>t?void 0:Bn(o)?.id),r=J(o=>t?void 0:Bn(o)?.backgroundTasks);return n.jsx(B9,{items:e,live:r,onOpen:s?o=>J.setState({pendingAgentOpen:{sessionId:s,agentId:o}}):void 0})}function a7({note:e}){const{t}=z(),s=/(?:moved to|main working tree): (.+)$/m.exec(e)?.[1]?.trim(),r=e.includes("main working tree");return n.jsxs("aside",{title:e,className:"flex w-full items-start gap-2 rounded-lg border border-dashed border-border/60 px-3 py-2 text-xs text-muted-foreground",children:[n.jsx(Hs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsxs("span",{className:"min-w-0",children:[t(r?"Workspace fell back to the main working tree":"Workspace moved to an isolated worktree"),s&&n.jsx("span",{className:"ml-1.5 break-all font-mono text-[11px] opacity-80",children:s})]})]})}function xC({note:e}){const{t}=z();return n.jsxs("aside",{className:"flex w-full items-start gap-2 rounded-lg border border-dashed border-border/60 px-3 py-2 text-xs text-muted-foreground",children:[n.jsx(Ai,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0",children:t(e==="on"?"Plan mode on: read-only research, then a plan for your approval":e==="off"?"Plan mode off":"Context compacted: the approved plan was attached again")})]})}function gC({note:e}){const{t}=z(),s=e==="on";return n.jsxs("aside",{className:"flex w-full items-start gap-2 rounded-lg border border-dashed border-border/60 px-3 py-2 text-xs text-muted-foreground",children:[s?n.jsx(LT,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):n.jsx(nx,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0",children:t(s?"Unattended mode on: no one is watching, so it decides and keeps going":"Unattended mode off: a person is available again")})]})}function l7({tag:e,body:t}){const s=e==="agent-notification"?BH(t):null;return s?n.jsx(u7,{notices:s}):n.jsx(f7,{tag:e,body:t})}function c7({goal:e,instructions:t}){const{t:s}=z(),[r,o]=f.useState(!1),i=kV(e);return n.jsxs("div",{"data-enso":"goal-continuation","data-open":r?"true":"false",className:_("my-1 w-full min-w-0",JS),children:[n.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>o(a=>!a),className:"flex w-full min-w-0 items-center gap-2 text-left text-muted-foreground hover:text-foreground",children:[n.jsx(ZS,{}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s("Continue goal: {{summary}}",{summary:i||e})})]}),r&&n.jsxs("div",{className:"mt-1.5 space-y-1.5 border-t border-border/60 pt-1.5",children:[n.jsx("p",{className:"whitespace-pre-wrap text-foreground",children:e}),t&&n.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-relaxed text-muted-foreground",children:t})]})]})}function Bb({enso:e,icon:t,title:s,body:r}){const[o,i]=f.useState(!1);return n.jsxs("div",{"data-enso":e,"data-open":o?"true":"false",className:Mx,children:[n.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>i(a=>!a),className:"flex w-full items-start gap-2 text-left enabled:hover:text-foreground",children:[n.jsx(t,{className:vu}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:s})]}),o&&r&&n.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-foreground",children:r})]})}function d7({segments:e,searchQuery:t,activeNth:s}){const{t:r}=z();return n.jsx(n.Fragment,{children:e.map((o,i)=>{const a=`${o.kind}-${i}`;if(o.kind==="text"){const l=o.text.trim();return l?n.jsx(er,{text:l,searchQuery:t,activeNth:s},a):null}if(o.kind==="goal")return n.jsx(c7,{goal:o.goal,instructions:o.instructions},a);if(o.kind==="schedule"){const l=TV(o.raw),c=l.length>0?l:[{summary:"",body:""}];return n.jsx(f.Fragment,{children:c.map((u,d)=>n.jsx(Bb,{enso:"secretary-schedule-card",icon:qa,title:u.summary?r("Scheduled: {{summary}}",{summary:u.summary}):r("Scheduled"),body:u.body},d))},a)}if(o.kind==="updates"){const l=qS(o.raw);if(l)return n.jsx(vC,{lines:l},a);const c=AV(o.raw);return n.jsx(Bb,{enso:"session-updates-card",icon:Jr,title:c.summary?r("Session updates: {{summary}}",{summary:c.summary}):r("Session updates"),body:c.body},a)}return n.jsx(l7,{tag:o.tag,body:o.body},a)})})}function u7({notices:e}){const{t}=z(),[s,r]=f.useState(!1);return n.jsxs("div",{className:Rx,children:[n.jsxs("button",{type:"button",onClick:()=>r(o=>!o),className:"flex w-full items-start gap-2 px-3 py-2 text-left hover:text-foreground",children:[n.jsx(ws,{className:vu}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e.map(o=>o.header).join(" · ")})]}),s&&e.map((o,i)=>n.jsxs("div",{className:"border-border/60 border-t",children:[e.length>1&&n.jsx("p",{className:"truncate px-3 pt-2",children:o.header}),o.report&&n.jsx("div",{className:"max-h-80 overflow-auto px-3 py-2 text-sm text-foreground",children:n.jsx(Dn,{text:o.report})}),o.usage&&n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 border-border/60 border-t px-3 py-1 text-[10px]",children:[n.jsx("span",{className:"font-semibold tracking-wide text-foreground/75",children:"Subagent"}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:t("{{count}} tokens",{count:Vn(o.usage.tokens)})}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:t("{{count}} tool calls",{count:o.usage.toolUses})}),n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:Wn(o.usage.durationMs)})]}),o.tasks&&n.jsxs("div",{className:"border-border/60 border-t px-3 py-1 text-[11px]",children:[n.jsx("p",{className:"text-foreground/75",children:t("Background tasks started by this subagent")}),o.tasks.map(a=>n.jsx("p",{className:"truncate font-mono text-muted-foreground",children:a},a))]})]},i))]})}function f7({tag:e,body:t}){const[s,r]=f.useState(!1),o=Ex(t);if(!o)return null;const i=o.indexOf(`
|
|
77
|
-
`),a=i>0,l=e.startsWith("coworker-")||e==="agent-notification"?ws:$o;return n.jsxs("div",{className:Mx,children:[n.jsxs("button",{type:"button",disabled:!a,onClick:()=>r(c=>!c),className:"flex w-full items-start gap-2 text-left enabled:hover:text-foreground",children:[n.jsx(l,{className:vu}),n.jsx("span",{className:_("min-w-0 flex-1",a?"truncate":"whitespace-pre-wrap"),children:a?o.slice(0,i):o})]}),a&&s&&n.jsx("pre",{className:"mt-1.5 max-h-80 overflow-auto font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words",children:o.slice(i+1)})]})}const m7={"goal-complete":On,"goal-blocked":Zr,"needs-user":nx,"turn-ended":Jr,failed:hj,stalled:ja,interrupted:Or,proposal:Zp,schedule:qa,pending:ja,"ask-relay":Uc,leftover:ja,queued:qa};function vC({lines:e}){return n.jsx("div",{"data-enso":"secretary-updates",className:_(Rx,"divide-y divide-border/60"),children:e.map((t,s)=>n.jsx(h7,{line:t,onOpen:sl},s))})}function h7({line:e,onOpen:t}){const{t:s}=z(),[r,o]=f.useState(!1),i=m7[e.kind],a="conversationId"in e?e.conversationId:void 0,l=n.jsxs(n.Fragment,{children:[n.jsx(i,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1",children:e.text})]});return n.jsxs("div",{"data-enso":"secretary-update","data-open":r?"true":"false",className:"px-3 py-2",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[e.detail?n.jsx("button",{type:"button","data-enso":"secretary-update-expand","aria-expanded":r,onClick:()=>o(c=>!c),className:"flex min-w-0 flex-1 items-start gap-2 text-left hover:text-foreground",children:l}):n.jsx("div",{className:"flex min-w-0 flex-1 items-start gap-2",children:l}),a&&t?n.jsx("button",{type:"button","data-enso":"secretary-update-open",title:s("Open session"),"aria-label":s("Open session"),onClick:c=>{c.stopPropagation(),t(a)},className:"-mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-[5px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Bi,{className:"h-3.5 w-3.5"})}):null]}),e.detail&&r&&n.jsx("pre",{className:"mt-1.5 ml-5.5 max-h-60 overflow-auto font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words",children:e.detail})]})}const bC=/^<message-from-main-agent>\n?([\s\S]*?)\n?<\/message-from-main-agent>\s*$/;function p7(e){const t=hC.exec(e);return bC.test(t?e.slice(t[0].length):e)}function x7({name:e,content:t}){const{t:s}=z();return n.jsxs(cn,{children:[n.jsxs(HT,{className:iC("skill",!0),children:[n.jsx(Bs,{className:"h-3 w-3"}),e]}),n.jsxs(dn,{className:"max-w-lg",children:[n.jsx(un,{children:n.jsxs(rn,{className:"text-base",children:[s("Skill")," · ",e]})}),n.jsx(In,{className:"max-h-[50vh] text-sm",children:n.jsx(Dn,{text:t})})]})]})}function ch({chip:e,extra:t}){return n.jsxs("div",{className:"max-w-[80%] rounded-2xl rounded-br-md bg-muted px-4 py-2.5 text-sm",children:[n.jsx("div",{className:"flex flex-wrap items-center gap-1",children:e}),t?n.jsx("div",{className:"mt-1.5 whitespace-pre-wrap break-words leading-relaxed",children:n.jsx(da,{text:t})}):null]})}function g7({blocks:e,hostTaskWrapUp:t}){const s=zT(e.rest),r=t?$T(e.rest):void 0,o=n.jsx(ch,{chip:n.jsx("span",{className:"inline-flex flex-wrap gap-1 align-middle",children:e.skills.map(i=>n.jsx(x7,{name:i.name,content:i.body},i.location))}),extra:s.rest.trim()});return!s.plan&&!s.unattended&&!r?o:n.jsxs(n.Fragment,{children:[s.plan&&n.jsx(xC,{note:s.plan}),s.unattended&&n.jsx(gC,{note:s.unattended}),r&&n.jsx(pC,{items:r.items}),o]})}function v7({text:e}){const t=mj(e);if(t.names.length>1)return n.jsx(ch,{chip:n.jsx("span",{className:"inline-flex flex-wrap gap-1 align-middle",children:t.names.map(r=>n.jsx(Cd,{name:`/skill:${r}`},r))}),extra:t.rest});const s=Sd(e);return s.slash?n.jsx(ch,{chip:n.jsx(Cd,{name:s.slash}),extra:s.rest.trim()}):null}function b7({preset:e}){const{t}=z();return n.jsxs("div",{className:"min-w-64 max-w-[80%] overflow-hidden rounded-2xl rounded-br-md bg-muted text-sm",children:[n.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5",children:[n.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-info/15 text-info",children:n.jsx(FT,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("Workflow preset")}),n.jsx("p",{className:"truncate font-medium",title:e.id,children:e.name||e.id})]})]}),e.args.length>0&&n.jsx("dl",{className:"space-y-1 border-t border-border/60 px-3.5 py-2 text-xs",children:e.args.map(([s,r])=>n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"shrink-0 font-mono text-muted-foreground",children:s}),n.jsx("dd",{className:"min-w-0 whitespace-pre-wrap break-words",children:r})]},s))})]})}function rl({kind:e,label:t,title:s}){const r=e==="file"?Wo:e==="chat"?Or:UB;return n.jsxs("span",{className:_(bu(e),"mx-0.5 max-w-52 rounded-md px-1.5 align-middle leading-4"),title:s,children:[n.jsx(r,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:t})]})}function y7({label:e,sessionFile:t}){const s=J(o=>o.conversations),r=GV(s,t);return r?n.jsxs("button",{type:"button","data-enso":"chat-ref",onClick:()=>sl(r),title:t,className:_(bu("chat"),"mx-0.5 inline-flex max-w-52 items-center gap-1 rounded-md px-1.5 align-middle leading-4 hover:bg-muted"),children:[n.jsx(Or,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:e})]}):n.jsx(rl,{kind:"chat",label:e,title:t})}const Fb=240;function w7({text:e,originalLines:t}){const{t:s}=z(),r=f.useRef(null),[o,i]=f.useState(!1),[a,l]=f.useState(!1);f.useLayoutEffect(()=>{const u=r.current;if(!u)return;const d=()=>i(u.scrollHeight>Fb+1);if(d(),typeof ResizeObserver>"u")return;const m=new ResizeObserver(d);return m.observe(u),()=>m.disconnect()},[]);const c=o&&!a;return n.jsxs("span",{"data-enso":"quote-block",className:"mt-1 mb-2.5 block border-l-2 border-brand/40 pl-2.5 text-muted-foreground",children:[t?n.jsx("span",{"data-quote-truncated":"",className:"mb-0.5 block text-[11px] text-warning",children:s("Truncated · original {{count}} lines",{count:t})}):null,n.jsx("span",{ref:r,"data-quote-body":"","data-clipped":c?"":void 0,style:c?{maxHeight:Fb}:void 0,className:_("block",c&&"overflow-hidden mask-b-from-60%"),children:lV(e).map((u,d)=>u.type==="code"?n.jsx("span",{"data-quote-code":"",className:"my-1 block overflow-x-auto whitespace-pre rounded-md bg-background/60 px-2 py-1 font-mono text-xs",children:u.code},d):n.jsx("span",{children:u.text},d))}),o?n.jsx("button",{type:"button","data-quote-toggle":"","data-quote-skip":"",onClick:()=>l(u=>!u),className:"mt-0.5 text-[11px] text-muted-foreground/80 select-none hover:text-foreground",children:s(a?"Show less":"Show more")}):null]})}function da({text:e,searchQuery:t="",activeNth:s=-1}){const r=MF(_T(e)),o={n:0};return n.jsx("span",{className:"whitespace-pre-wrap",children:r.map((i,a)=>i.type==="file"?n.jsx(fj,{path:i.path,children:n.jsx(rl,{kind:"file",label:du(i.path),title:i.path})},a):i.type==="chat"?n.jsx(y7,{label:i.label,sessionFile:i.sessionFile},a):i.type==="ui-element"?n.jsx(rl,{kind:"ui-element",label:i.label,title:`${i.path}${i.text?` · ${i.text}`:""}`},a):i.type==="quote"?n.jsx(w7,{text:i.text,originalLines:i.originalLines},a):n.jsx("span",{children:t.trim()?BT(i.text,t,s,o):i.text},a))})}function j7({files:e,chats:t}){return n.jsxs("span",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[e.map(s=>n.jsx(fj,{path:s,children:n.jsx(rl,{kind:"file",label:du(s),title:s})},`f:${s}`)),t.map(s=>n.jsx(rl,{kind:"chat",label:s.label,title:s.sessionFile},`c:${s.sessionFile}`))]})}const Lc="max-w-[82%] rounded-[10px] bg-muted px-3.5 py-[9px] text-(length:--chat-body-size) leading-[1.6]";function er({text:e,searchQuery:t="",activeNth:s=-1,thumbnails:r=0,align:o="end",hostTaskWrapUp:i=!1}){const{t:a}=z(),l=js(),c=!!(l?.speaker||l?.botSession),u=NT(e,r);if(u)return n.jsxs(n.Fragment,{children:[u.text&&n.jsx(er,{text:u.text,searchQuery:t,activeNth:s,hostTaskWrapUp:i}),n.jsx(YS,{entries:u.entries,thumbnails:r,align:o})]});const d=bV(e);if(d)return n.jsx(gH,{message:d});const m=c?ST(e):null;if(m)return n.jsx(qV,{message:m});const h=c?CT(e):e;if(h!==e)return n.jsx(er,{text:h,searchQuery:t,activeNth:s,hostTaskWrapUp:i});const p=c?IT(e):null;if(p?.refs.length)return n.jsxs("div",{className:"flex w-full flex-col items-end gap-1.5",children:[p.body&&n.jsx(er,{text:p.body,searchQuery:t,activeNth:s}),n.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:p.refs.map($=>n.jsxs("span",{title:a("Referenced chat"),className:"inline-flex h-6 max-w-56 items-center gap-1 rounded-md bg-muted px-1.5 text-xs",children:[n.jsx(Jr,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:$.title})]},$.id))})]});const g=TT(e);if(g.note){const $=g.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(xC,{note:g.note}),$&&n.jsx(er,{text:$,searchQuery:t,activeNth:s,hostTaskWrapUp:i})]})}const x=AT(e);if(x.note){const $=x.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(gC,{note:x.note}),$&&n.jsx(er,{text:$,searchQuery:t,activeNth:s,hostTaskWrapUp:i})]})}const v=i?ET(e):null;if(v){const $=v.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(pC,{items:v.items}),$&&n.jsx(er,{text:$,searchQuery:t,activeNth:s})]})}const b=o7.exec(e);if(b){const $=e.slice(b[0].length).trim();return n.jsxs(n.Fragment,{children:[n.jsx(i7,{note:b[1]??""}),$&&n.jsx(er,{text:$,searchQuery:t,activeNth:s})]})}const w=RT(e);if(w?.kind==="approved")return n.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-dashed border-border/60 px-3 py-2 text-xs text-muted-foreground",children:[n.jsx(Zp,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsxs("span",{className:"min-w-0",children:[a("Plan approved, executing"),n.jsx("span",{className:"ml-1.5 text-foreground",children:w.title})]})]});if(w?.kind==="feedback")return n.jsxs("div",{className:_(Lc,"whitespace-pre-wrap"),children:[n.jsxs("p",{className:"mb-1 flex items-center gap-1 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:[n.jsx(Ai,{className:"h-3 w-3"}),a("Plan feedback")]}),n.jsx(da,{text:w.feedback,searchQuery:t,activeNth:s})]});const j=MT(e);if(j)return n.jsx(b7,{preset:j});const T=BF(e);if(T.files.length>0||T.chats.length>0){const $=Sd(T.body);return n.jsxs("div",{className:Lc,children:[$.slash?n.jsxs(n.Fragment,{children:[n.jsx(Cd,{name:$.slash}),$.rest.trim()?n.jsx("span",{className:"ml-1.5 align-middle",children:n.jsx(da,{text:$.rest.trim(),searchQuery:t,activeNth:s})}):null]}):n.jsx(da,{text:T.body,searchQuery:t,activeNth:s}),n.jsx(j7,{files:T.files,chats:T.chats})]})}const S=PT(e);if(S)return n.jsx(g7,{blocks:S,hostTaskWrapUp:i});if(Sd(e).slash)return n.jsx(v7,{text:e});const I=r7.exec(e);if(I){const $=e.slice(I[0].length).trim();return n.jsxs(n.Fragment,{children:[n.jsx(a7,{note:I[1]}),$&&n.jsx(er,{text:$,searchQuery:t,activeNth:s})]})}const k=SV(e);if(k)return n.jsx(d7,{segments:k,searchQuery:t,activeNth:s});const L=qS(e);if(L)return n.jsx(vC,{lines:L});const F=hC.exec(e),A=F?e.slice(F[0].length):e,M=bC.exec(A),R=M?M[1]:A;return n.jsxs("div",{className:_(M?"max-w-[80%] rounded-2xl rounded-bl-md border border-blue-500/20 bg-blue-500/8 px-4 py-2.5 text-sm":_(Lc,"whitespace-pre-wrap")),children:[M&&n.jsxs("p",{className:"mb-1 flex items-center gap-1 text-[10px] font-medium tracking-wide text-blue-600 uppercase dark:text-blue-400",children:[n.jsx(ws,{className:"h-3 w-3"}),a("From main agent")]}),F?.[1]&&!hV(F[1])&&n.jsxs("div",{className:"mb-2 rounded-md bg-background/60 px-2.5 py-1.5 text-xs text-muted-foreground",children:[n.jsx("span",{className:"font-semibold",children:a("Role")})," · ",F[1]]}),M?n.jsx(Dn,{text:R,searchQuery:t,activeNth:s}):n.jsx(da,{text:R,searchQuery:t,activeNth:s})]})}function zb(e){return e.kind==="tool-group"||e.kind==="thinking"||e.kind==="tool"&&aj(e)}const cr="text-[color:var(--subtle-foreground,var(--muted-foreground))]",xi="animate-pulse motion-reduce:animate-none";function k7({model:e,at:t,privacyMask:s,secretarySession:r=!1,face:o}){const i=js(),a=FS(),l=r?o??a:null,c=i?.speaker??(i?null:l),u=!i&&l?!0:void 0,d=[e,typeof t=="number"?wu(t):null].filter(Boolean).join(" · ");return!c&&!d&&!s?null:n.jsxs("div",{"data-quote-skip":"",className:"mb-2 flex h-6 min-w-0 items-center gap-2 text-xs select-none",children:[c&&(c.image?n.jsx("img",{"data-enso":u?"secretary-chat-avatar":void 0,"data-image":u?"true":void 0,src:c.image,alt:"",draggable:!1,className:"size-[22px] shrink-0 rounded-full object-cover",style:{backgroundColor:c.color}}):u?n.jsx(Fd,{name:c.name,color:c.color,enso:"secretary-chat-avatar",className:"size-[22px] rounded-full"}):n.jsx("span",{className:"flex size-[22px] shrink-0 items-center justify-center rounded-full font-semibold text-[11px] text-white",style:{backgroundColor:c.color},children:[...c.name.trim()][0]?.toUpperCase()??"?"})),c&&n.jsx("span",{className:"shrink-0 truncate text-[13px] font-semibold text-foreground",children:c.name}),d&&n.jsx("span",{className:_("min-w-0 truncate text-[11.5px]",cr),children:d}),s&&n.jsx(d9,{report:s})]})}const N7=f.memo(function({item:t,secretarySession:s=!1,onToggleGroup:r,onToggleTurn:o}){const i=lT(),a=i.query,l=i.activeKey===t.key?i.activeNth:-1,c=s;switch(t.kind){case"user":{const u=t.text?p7(t.text):!1,d=t.collapsed===!0,m=t.hostTaskWrapUp?fT(t.text):t.text;return n.jsxs("div",{"data-enso":"message-user",className:_("group/user flex flex-col gap-1.5",u?"items-start":"items-end"),children:[t.images.map((h,p)=>n.jsx(El,{src:`data:${h.mimeType};base64,${h.data}`,className:"max-h-48 max-w-full rounded-lg border object-contain"},p)),t.text&&n.jsx(er,{text:t.text,searchQuery:a,activeNth:l,thumbnails:t.images.length,align:u?"start":"end",hostTaskWrapUp:t.hostTaskWrapUp===!0}),d?n.jsx(B7,{turnKey:t.key,text:m,timestamp:t.timestamp,turnDurationMs:t.turnDurationMs,onToggle:o}):n.jsx(F7,{turnKey:t.key,messageIndex:Number(t.key),text:m,timestamp:t.timestamp,deliveryState:t.deliveryState,canCollapse:t.canCollapse,onToggleTurn:o})]})}case"text":return n.jsx(z7,{item:t,searchQuery:a,activeNth:l});case"thinking":return n.jsx(W7,{itemKey:t.key,text:t.text,streaming:t.streaming,durationMs:t.durationMs,startedAt:t.startedAt});case"tool":{const u=XV(t),d=cT(t.name,c),m=n.jsxs(n.Fragment,{children:[n.jsx(dT,{name:t.name,output:t.output,state:t.state}),d?n.jsx(q9,{item:t,framed:c}):n.jsx(Q7,{item:t}),u?n.jsx(ZV,{proposalId:u}):null,t.pluginArtifacts?n.jsx(uT,{artifacts:t.pluginArtifacts,align:d?"card":"tool-row"}):null]});return d?n.jsx("div",{"data-enso":"tool-card-pair",className:"w-full min-w-0",children:m}):m}case"tool-group":return n.jsx(K7,{item:t,onToggle:r});case"error":return n.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[n.jsx(Zr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("p",{className:"min-w-0 flex-1 whitespace-pre-wrap",children:t.text}),n.jsx(jC,{})]});case"interrupted":return n.jsx(E7,{item:t});case"task-note":return n.jsx(U7,{item:t});case"compaction":case"compaction-notice":return n.jsx(G7,{item:t});case"compaction-progress":return n.jsx(q7,{state:t.state});case"session-custom":return n.jsx(A7,{entry:t.entry});case"plugin-message":return n.jsx(C7,{item:t});case"discarded-turn":return n.jsx(I7,{item:t,onToggle:r});case"resumed-reply":return n.jsx(T7,{item:t,onToggle:r});case"divider":return n.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"h-px flex-1 bg-border"}),t.text,n.jsx("span",{className:"h-px flex-1 bg-border"})]})}},s7),$b=e=>{if(typeof e=="string")return e;if(e===void 0)return"—";try{return JSON.stringify(e)}catch{return String(e)}};function S7({entry:e}){const{t}=z(),s=bH(),r=s.get(e.accountKey),o=e.previousAccountKey?s.get(e.previousAccountKey):void 0,i=e.previousAccountKey?o&&r?t("ChatGPT account switched: {{previous}} → {{current}}",{previous:o,current:r}):t("ChatGPT account switched"):r?t("ChatGPT account selected: {{account}}",{account:r}):t("ChatGPT account selected");return n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border/60 bg-muted/20 px-2.5 py-2 text-xs",children:[n.jsx(oo,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-primary"}),n.jsx("p",{className:"min-w-0 break-words text-muted-foreground",children:i})]})}function C7({item:e}){const{t}=z();return n.jsxs("div",{"data-plugin-message":e.pluginId,className:"rounded-md border border-dashed border-border bg-muted/20 px-3 py-2 text-xs",children:[n.jsxs("p",{className:"mb-1 flex items-center gap-1.5 text-muted-foreground",children:[n.jsx(rj,{pluginId:e.pluginId,className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{children:t("From plugin {{name}}",{name:e.pluginName})}),n.jsx("span",{className:"font-mono opacity-70",children:e.pluginId})]}),n.jsx("div",{className:yC,children:n.jsx(Dn,{text:e.text})})]})}const yC="break-words text-foreground [&_p]:whitespace-pre-line";function I7({item:e,onToggle:t}){const{t:s}=z();return n.jsxs("div",{"data-discarded-turn":e.pluginId,children:[n.jsxs("button",{type:"button",onClick:()=>t?.(e.key),"data-enso":"tool-row",className:_("group/step flex min-h-6 w-full items-center gap-2 text-left text-[13px] transition-colors hover:text-foreground",cr),children:[n.jsx(oj,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"shrink-0 text-muted-foreground group-hover/step:text-foreground",children:Rr("turn_discard",s)}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:[e.pluginName,e.reason].filter(Boolean).join(" · ")}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",e.expanded&&"rotate-90")})]}),e.expanded&&n.jsxs("div",{className:"t-acc-reveal mt-1 mb-1.5 ml-5 space-y-2 rounded-md border border-dashed border-border bg-muted/20 px-3 py-2 text-xs",children:[n.jsxs("p",{className:"flex items-center gap-1.5 text-muted-foreground",children:[n.jsx(rj,{pluginId:e.pluginId,className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{children:s("From plugin {{name}}",{name:e.pluginName})})]}),e.messages.map((r,o)=>n.jsx("div",{className:yC,children:n.jsx(Dn,{text:r})},o)),e.tools.map((r,o)=>n.jsxs("p",{className:_("truncate",cr),children:[Rr(r.name,s)," ",r.summary]},o))]})]})}function T7({item:e,onToggle:t}){const{t:s}=z();return n.jsxs("div",{"data-resumed-reply":"",children:[n.jsxs("button",{type:"button",onClick:()=>t?.(e.key),"aria-expanded":e.expanded,"data-enso":"tool-row",className:_("group/step flex min-h-6 w-full items-center gap-2 text-left text-[13px] transition-colors hover:text-foreground",cr),children:[n.jsx(EN,{className:"h-3.5 w-3.5 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[s("Interrupted by a restart, continued below"),n.jsx("span",{className:"ml-1.5 opacity-70",children:e.expanded?s("Hide the interrupted part"):s("Show the interrupted part")})]}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",e.expanded&&"rotate-90")})]}),e.expanded&&n.jsxs("div",{className:"t-acc-reveal mt-1 mb-1.5 ml-5 space-y-2 rounded-md border border-dashed border-border bg-muted/20 px-3 py-2 text-xs",children:[e.thinking&&n.jsx("p",{className:_("whitespace-pre-wrap break-words",cr),children:e.thinking}),e.text&&n.jsx("p",{className:"whitespace-pre-wrap break-words text-foreground",children:e.text}),e.tools.map((r,o)=>n.jsxs("p",{className:_("truncate",cr),children:[Rr(r.name,s)," ",r.summary]},o))]})]})}function A7({entry:e}){const{t}=z();if(e.kind==="oauth-account-selected")return n.jsx(S7,{entry:e});if(e.kind==="agent-dispatch")return n.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border/60 bg-muted/20 px-2.5 py-2 text-xs",children:[n.jsx(ws,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),n.jsx("span",{className:"text-muted-foreground",children:t("Dispatched to")}),n.jsx("span",{className:"font-medium",children:e.child.instanceName})]});if(e.kind==="agent-completed")return n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-emerald-500/20 bg-emerald-500/5 px-2.5 py-2 text-xs",children:[n.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-500"}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{className:"font-medium",children:[e.child.instanceName," · ",t("Completed")]}),e.receiptSummary&&n.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground",children:e.receiptSummary})]})]});if(e.kind==="agent-failed")return n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/20 bg-destructive/5 px-2.5 py-2 text-xs",children:[n.jsx(Zr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive"}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{className:"font-medium",children:[e.child.instanceName," · ",t("Failed")]}),n.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground",children:e.message})]})]});if(e.kind==="tool-batch-label")return null;if(e.kind==="task-wrap-up-nudge")return n.jsxs("div",{"data-enso":"task-wrap-up-nudge",className:"my-1 flex items-center gap-1.5 text-[12px] text-subtle-foreground",children:[n.jsx(fl,{className:"size-3.5 shrink-0"}),t("{{count}} background tasks are still undeclared; the next message asks the agent to stop each one or state why it keeps running",{count:e.count})]});const s=e.receipt,r=s.outcome==="succeeded";return n.jsx("div",{className:_("rounded-md border px-2.5 py-2 text-xs",r?"border-emerald-500/20 bg-emerald-500/5":s.outcome==="failed"?"border-destructive/20 bg-destructive/5":"border-amber-500/20 bg-amber-500/5"),children:n.jsxs("div",{className:"flex items-start gap-2",children:[r?n.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-500"}):n.jsx(Zr,{className:_("mt-0.5 h-3.5 w-3.5 shrink-0",s.outcome==="failed"?"text-destructive":"text-amber-500")}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("p",{className:"font-medium",children:[s.subject.label," · ",t(s.outcome)]}),n.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground",children:s.summary}),s.changes&&s.changes.length>0&&n.jsx("dl",{className:"mt-2 space-y-1 border-t border-border/50 pt-2",children:s.changes.map(o=>n.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto] gap-2",children:[n.jsx("dt",{className:"truncate text-muted-foreground",children:o.field}),n.jsxs("dd",{className:"text-right font-mono",children:[$b(o.previous)," → ",$b(o.value)]})]},o.field))})]})]})})}function Bn(e){const t=e.activeId?e.conversations[e.activeId]:null;return t?t.activeTabId?e.conversations[t.activeTabId]??t:t:null}const wC=()=>()=>{};function E7({item:e}){const{locale:t}=z(),s=gV({at:e.at,kind:e.exitKind,unfinishedTools:e.unfinishedTools,lang:t});return n.jsxs("div",{"data-enso":"timeline-interrupted",className:"flex items-start gap-2 text-sm text-warning",children:[n.jsx(Zr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),n.jsx("p",{className:"min-w-0 flex-1 whitespace-pre-wrap",children:s}),n.jsx(R7,{})]})}function R7(){const{t:e}=z();return J(s=>{const r=Bn(s);return!!(r&&!r.spawning&&r.status!=="running")})?n.jsxs("button",{type:"button","data-enso":"timeline-interrupted-retry",title:e("Retry"),onClick:()=>{const s=Bn(J.getState());s&&J.getState().retryInterrupted(s.id)},className:"mt-0.5 inline-flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground",children:[n.jsx(oo,{className:"h-3 w-3"}),e("Retry")]}):null}function jC(){const{t:e}=z(),t=js(),s=t?.botControls,r=J(l=>{if(t&&(!t.canRetry||t.botControls))return!1;const c=Bn(l);return!!(c?.started&&!c.spawning&&c.status!=="running")}),o=()=>{if(!s||!t?.canRetry)return!1;const l=s.projection();return!!(l&&l.status!=="running")},i=f.useSyncExternalStore(s?.subscribe??wC,o,o);return(s?i:r)?n.jsxs("button",{type:"button",title:e("Retry"),onClick:()=>{if(s)return s.retry();const l=Bn(J.getState());l&&J.getState().retry(l.id)},className:"mt-0.5 inline-flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground",children:[n.jsx(oo,{className:"h-3 w-3"}),e("Retry")]}):null}function M7(e,t){return VT(Bn(e),t)}const Dx="flex items-center gap-1 text-[11px] text-muted-foreground transition-opacity hover:text-foreground";function P7({messageIndex:e}){const{t}=z(),s=js();return J(o=>{const i=Bn(o);return OT(i,s,i?uj(o.conversations,i.id):1)})?n.jsxs("button",{type:"button",className:Dx,title:t("Keep this session and start a parallel one from here"),onClick:()=>{const o=J.getState(),i=Bn(o);i&&o.forkFromTurn(i.id,e)},children:[n.jsx(Hs,{className:"h-3 w-3"}),t("Conversation branch")]}):null}function D7({messageIndex:e}){const{t}=z(),s=js(),r=J(i=>Bn(i)?.id),o=J(i=>{const a=r?i.conversations[r]:void 0;if(s||!a||a.historyOnly||a.rewinding||a.restoringFiles||a.workspaceMigrating)return;const l=a.messages[e-(a.historyBaseIndex??0)];return dj(l)||a.status==="running"&&DT(l)?l?.deliveryId:void 0});return!r||!o?null:n.jsxs("button",{type:"button",title:t("Withdraw message"),onClick:()=>J.getState().withdrawMessage(r,{kind:"delivery",id:o}),className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(Ka,{className:"h-3 w-3"}),t("Withdraw message")]})}function O7(){const{t:e}=z(),t=J(s=>Bn(s)?.id);return t?n.jsxs("button",{type:"button",onClick:()=>{KS(t,e)},className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(Mr,{className:"h-3 w-3"}),e("Restart conversation")]}):null}function L7({messageIndex:e}){const{t}=z(),s=js(),r=J(i=>Bn(i)?.id),o=J(i=>{const a=r?i.conversations[r]:void 0;if(s||!a||a.historyOnly)return;const l=a.messages[e-(a.historyBaseIndex??0)];return dj(l)?l?.deliveryId:void 0});return!r||!o?null:n.jsxs("button",{type:"button",title:t("Resend"),onClick:()=>J.getState().resendMessage(r,o),className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(oo,{className:"h-3 w-3"}),t("Resend")]})}function _7({messageIndex:e}){const{t}=z(),[s,r]=f.useState(!1),[o,i]=f.useState(null),a=js(),l=a?.botControls,c=J(x=>{if(a?.botControls)return!1;const v=Bn(x);return M7(x,a)&&!!(v&&Hl(v.id,v.id,v,e))}),u=()=>{if(!l||!a?.canRewind||!a.sessionId)return null;const x=l.projection();return!x||x.status==="running"?null:Hl(a.sessionId,a.sessionId,x,e)?.entryId??null},d=f.useSyncExternalStore(l?.subscribe??wC,u,u);if(!(l?d!==null:c))return null;const h=x=>{if(l&&a?.sessionId&&d){i({restoreFiles:x,conversationId:a.sessionId,entryId:d});return}const v=Bn(J.getState());if(!v)return;const b=Hl(v.id,v.id,v,e);b&&i({restoreFiles:x,conversationId:v.id,entryId:b.entryId})},p=(x,v,b)=>{if(l)return l.rewind(b,x);const w=J.getState(),j=Bn(w),T=Hl(v,j?.id,w.conversations[v],e,b);T&&w.rewind(T.conversationId,T.entryId,x)},g=[{icon:Ka,label:t("Conversation only"),desc:t("Rewind to this message"),restoreFiles:!1,action:()=>h(!1)},{icon:Or,label:t("Conversation + files"),desc:t("Rewind and restore files to before this turn"),restoreFiles:!0,action:()=>h(!0)}];return n.jsxs(Ms,{open:s,onOpenChange:r,children:[n.jsxs(Ps,{className:Dx,title:t("Rewind to this message"),children:[n.jsx(Ka,{className:"h-3 w-3"}),t("Rewind")]}),n.jsx(Ds,{side:"bottom",align:"end",className:"w-72 [&_[data-slot=popover-viewport]]:p-1",children:g.map(x=>n.jsxs("button",{type:"button",onClick:()=>{r(!1),x.action()},className:"flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-muted/60",children:[n.jsx(x.icon,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block",children:x.label}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:x.desc})]})]},x.label))}),n.jsx(cs,{open:o!==null,onOpenChange:x=>{x||i(null)},title:t("Rewind to this message?"),description:o?.restoreFiles?t("Later messages leave the current branch and working-tree files are restored to before this turn."):t("Later messages leave the current branch; the text returns to the input box."),confirmLabel:t("Rewind"),onConfirm:()=>{o&&p(o.restoreFiles,o.conversationId,o.entryId)}})]})}function B7({turnKey:e,text:t,timestamp:s,turnDurationMs:r,onToggle:o}){const{t:i}=z();return n.jsxs("div",{"data-quote-skip":"",className:"flex items-center gap-1.5 text-[11px] text-muted-foreground/80 select-none",children:[n.jsxs("button",{type:"button",onClick:()=>o?.(e,!1),className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground cursor-pointer border border-border/40",title:i("Expand"),children:[n.jsx(fn,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{children:i("Expand")})]}),n.jsx(kC,{text:t}),typeof s=="number"&&n.jsx("span",{children:wu(s)}),r!==void 0&&n.jsxs("span",{children:["· ",i("took {{duration}}",{duration:Wn(r)})]})]})}function kC({text:e}){return e.trim()?n.jsx("span",{"data-enso":"copy-user-prompt",className:"inline-flex",children:n.jsx(NC,{text:zh(e),className:"opacity-0 transition-opacity group-hover/user:opacity-100 focus-visible:opacity-100"})}):null}function F7({turnKey:e,messageIndex:t,text:s,timestamp:r,canCollapse:o,deliveryState:i,onToggleTurn:a}){const{t:l}=z(),c=pe(u=>u.autoCollapseTurns);return n.jsxs("div",{"data-quote-skip":"",className:"flex items-center gap-2 text-[11px] text-muted-foreground/75 select-none",children:[n.jsx(_7,{messageIndex:t}),n.jsx(L7,{messageIndex:t}),n.jsx(D7,{messageIndex:t}),n.jsx(kC,{text:s}),i&&n.jsx("span",{children:l(i==="stuck"?"Not sent: the previous turn is stuck and could not be interrupted. Restart the conversation, then resend.":i==="rejected"?"Not sent":"Delivery unconfirmed")}),i==="stuck"&&n.jsx(O7,{}),c&&o&&a&&n.jsxs("button",{type:"button",onClick:()=>a(e,!0),className:_(Dx,"cursor-pointer opacity-0 group-hover/user:opacity-100"),title:l("Collapse"),children:[n.jsx(Fn,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{children:l("Collapse")})]}),typeof r=="number"&&n.jsx("span",{children:wu(r)})]})}function z7({item:e,searchQuery:t="",activeNth:s=-1}){const{t:r}=z(),o=js(),i=e.perf?$7(e.perf,r,e.turnDurationMs!==void 0):"",a=J(u=>Bn(u)?.id??null),l=Number(e.key.split("-")[0]),c={text:e.text,messageIndex:l,sessionId:o?o.sessionId:a};return n.jsxs("div",{"data-enso":"message-assistant",className:"group text-(length:--chat-body-size)",children:[n.jsx(Dn,{text:e.text,streaming:e.streaming,searchQuery:t,activeNth:s,leaf:{messageIndex:c.messageIndex,sessionId:c.sessionId}}),e.turnEnd&&!e.streaming&&o?.turnFooter?.(Number(e.key.split("-")[0])),!e.streaming&&n.jsxs("div",{"data-quote-skip":"",className:"mt-1 flex items-center gap-2 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:[n.jsx(jg,{position:"left",...c}),n.jsx(NC,{text:e.text}),n.jsx(jg,{position:"right",...c}),e.turnEnd&&n.jsx(P7,{messageIndex:Number(e.key.split("-")[0])}),e.timestamp&&!e.turnEnd&&n.jsx("span",{children:wu(e.timestamp)}),e.turnDurationMs!==void 0&&n.jsxs("span",{children:[e.timestamp&&!e.turnEnd&&"· ",r("took {{duration}}",{duration:Wn(e.turnDurationMs)})]}),i&&n.jsxs("span",{children:["· ",i]})]})]})}function NC({text:e,className:t}){const{t:s}=z(),[r,o]=f.useState(!1);return n.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!1),1e3)})},className:_("flex items-center gap-1 transition-colors hover:text-foreground",t),title:s("Copy"),children:r?n.jsx(On,{className:"h-3 w-3"}):n.jsx(ul,{className:"h-3 w-3"})})}const Vb=e=>String(e).padStart(2,"0"),wu=e=>{const t=new Date(e);return`${Vb(t.getHours())}:${Vb(t.getMinutes())}`},Hb=e=>{const t=e/1e3;return t<10?String(Math.round(t*10)/10):String(Math.round(t))};function $7(e,t,s=!1){const r=[];return(!s||e.turnMs!==void 0)&&r.push(`${Hb(e.runMs)}s`),e.ttftMs!==void 0&&r.push(`TTFT ${Hb(e.ttftMs)}s`),e.tps!==void 0&&r.push(`${Math.round(e.tps)} tok/s`),!s&&e.turnMs!==void 0&&r.push(t("total {{duration}}",{duration:Wn(e.turnMs)})),r.join(" · ")}function V7(e,t,s=16){return e.top<t.top?e.top-t.top-s:e.bottom>t.bottom?e.bottom-t.bottom+s:0}function H7(e){let t=e.parentElement;for(;t;){if(t.hasAttribute("data-virtuoso-scroller"))return t;const s=typeof window.getComputedStyle=="function"?window.getComputedStyle(t).overflowY:t.style.overflowY;if(s==="auto"||s==="scroll"||s==="overlay")return t;t=t.parentElement}return null}function W7({itemKey:e,text:t,streaming:s,durationMs:r,startedAt:o}){const{t:i}=z(),a=pe(h=>h.expandLiveReasoning),[l,c]=f.useState(null),u=kT(l,s,a),d=f.useRef(null),m=f.useRef(!1);return f.useLayoutEffect(()=>{if(u||!m.current)return;m.current=!1;const h=d.current;if(!h)return;const p=H7(h);if(!p){h.getBoundingClientRect().top<0&&h.scrollIntoView?.({block:"nearest"});return}const g=V7(h.getBoundingClientRect(),p.getBoundingClientRect());g!==0&&(p.scrollTop=Math.max(0,p.scrollTop+g))},[u]),n.jsxs("div",{ref:d,"data-enso":"thinking","data-live":s||void 0,children:[n.jsxs("button",{type:"button","data-quote-skip":"",onClick:()=>c(!u),className:_("flex min-h-6 select-none items-center gap-2 text-[13px] transition-colors hover:text-foreground",cr),children:[n.jsx("span",{className:"flex size-3 shrink-0 items-center justify-center",children:n.jsx(mT,{className:_("size-3",s&&"animate-pulse text-brand")})}),s?n.jsx("span",{className:_("text-foreground",xi),children:i("Thinking…")}):r!==null?n.jsx("span",{children:i("Thought for {{duration}}",{duration:Wn(r)})}):n.jsx("span",{children:i("Thought process")}),s&&n.jsx(SC,{itemKey:e,since:o}),n.jsx(fn,{className:_("h-3 w-3 transition-transform",u&&"rotate-90")})]}),u&&n.jsx(hT,{text:t,streaming:s,itemKey:e}),u&&!s&&n.jsxs("button",{type:"button","data-enso":"thinking-collapse","data-quote-skip":"",onClick:()=>{m.current=!0,c(!1)},className:_("mt-1 ml-[31px] flex min-h-6 select-none items-center gap-1 text-[12px] transition-colors hover:text-foreground",cr),children:[n.jsx(ij,{className:"h-3 w-3"}),n.jsx("span",{children:i("Collapse thinking")})]})]})}function U7({item:e}){const{t}=z(),[s,r]=f.useState(!1),[o,i]=f.useState(void 0),a=/^Background task (\S+) finished \((.+?), ran (.+?)\)/.exec(e.summary),l=a?`${a[1]} · ${a[2]} · ${a[3]}`:e.summary,c=/(?:read ((?:\/|[A-Za-z]:[\\/]).+?\.log) for the complete log|Full log: ((?:\/|[A-Za-z]:[\\/])\S+?\.log))/.exec(e.detail)?.slice(1).find(Boolean)??null;return f.useEffect(()=>{!s||!c||o!==void 0||window.electronAPI.files.read(c).then(u=>{i(typeof u=="string"?u:null)}).catch(()=>i(null))},[s,c,o]),n.jsxs("div",{children:[n.jsxs("button",{type:"button",onClick:()=>r(u=>!u),className:"flex w-full items-center gap-3",title:e.detail,children:[n.jsx("span",{className:"h-px flex-1 bg-border"}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[n.jsx(On,{className:"h-3 w-3 text-green-600 dark:text-green-500"}),l,n.jsx(fn,{className:_("h-3 w-3 transition-transform",s&&"rotate-90")})]}),n.jsx("span",{className:"h-px flex-1 bg-border"})]}),s&&n.jsxs("div",{className:"mt-1.5 rounded-lg border border-border/60 bg-muted/20",children:[n.jsx("pre",{className:"border-b border-border/60 px-3 py-2 font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-muted-foreground",children:e.detail}),n.jsx("pre",{className:"max-h-64 overflow-auto px-3 py-2 font-mono text-xs leading-relaxed whitespace-pre-wrap text-muted-foreground",children:c?o===void 0?t("Loading…"):_s(o??t("(log unavailable)")):t("(no log available)")})]})]})}function q7({state:e}){const{t}=z();return n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[n.jsx(_t,{className:"h-3 w-3 animate-spin"}),n.jsx("span",{children:t(e==="queued"?"Compacts after this turn":"Compacting…")})]})}function G7({item:e}){const{t}=z(),[s,r]=f.useState(!1),o=e.kind==="compaction",i=e.tokensBefore===null?null:Vn(e.tokensBefore),a=$H(e.tokensBefore,e.tokensAfter),l=a!==null&&e.tokensBefore!==null&&e.tokensAfter!==void 0?t("{{kind}} · {{before}} → {{after}} · freed {{percent}}%",{kind:t(e.memory?"Memory context compacted":e.verified?"Verified context compacted":"Context compacted"),before:Vn(e.tokensBefore),after:Vn(e.tokensAfter),percent:a}):e.memory?i===null?t("Memory context compacted"):t("Memory context compacted ({{tokens}} tokens before)",{tokens:i}):e.verified?i===null?t("Verified context compacted"):t("Verified context compacted ({{tokens}} tokens before)",{tokens:i}):i===null?t("Context compacted"):t("Context compacted ({{tokens}} tokens before)",{tokens:i});return n.jsxs("div",{children:[n.jsxs("button",{type:"button",onClick:()=>r(c=>!c),className:_("flex items-center gap-3",o&&"w-full"),title:e.memory?t("Summary rendered from continuous memory. Messages above are no longer in the model context; use recall for sources."):e.verified?t("Verified summary from smart compaction. Messages above are no longer in the model context."):t(o?"Messages above are no longer in the model context; only this summary is.":"Latest compaction summary — expand to read what the model kept."),children:[o&&n.jsx("span",{className:"h-px flex-1 bg-border"}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[n.jsx(AB,{className:"h-3 w-3"}),l,n.jsx(fn,{className:_("h-3 w-3 transition-transform",s&&"rotate-90")})]}),o&&n.jsx("span",{className:"h-px flex-1 bg-border"})]}),s&&n.jsx("pre",{className:"mt-1.5 max-h-80 overflow-auto rounded-lg border border-border/60 bg-muted/20 px-3 py-2 font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-muted-foreground",children:e.summary||t("(summary unavailable)")})]})}function K7({item:e,onToggle:t}){const{t:s}=z(),r=pe(g=>g.compactReadOnlyTools),o=[];e.stats.commands>0&&o.push(s("ran {{count}} commands",{count:e.stats.commands})),e.stats.reads>0&&o.push(s("read {{count}} files",{count:e.stats.reads})),e.stats.searches>0&&o.push(s("searched {{count}} times",{count:e.stats.searches})),e.stats.others>0&&o.push(s("{{count}} other calls",{count:e.stats.others}));const i=[];r&&(e.stats.reads>0&&i.push(s("{{count}} files",{count:e.stats.reads})),e.stats.searches>0&&i.push(s("{{count}} searches",{count:e.stats.searches})));const a=e.activity,l=[];a&&(a.thinking>0&&l.push(s("{{count}} thinking steps",{count:a.thinking})),e.count>0&&l.push(s("{{count}} tool calls",{count:e.count})));const c=e.explore,u=e.exploring||!!(a&&e.live),d=e.notice==="patrol"?s("Patrol clear"):e.notice==="seen"?s("Update seen"):null,m=c?Rr("explore_fold",s):d||(a?s("Worked for {{duration}}",{duration:Wn(a.workedMs)}):r?e.exploring?s("Exploring"):s("Explored"):s("{{count}} tool calls",{count:e.count})),h=c?[c.goal,s("{{count}} tool calls",{count:e.count})].filter(Boolean):d?l:e.summary&&!e.exploring?[e.summary]:a?l:r?i:o,p=n.jsxs("button",{type:"button",onClick:()=>{c?.steps&&t?.(kg(e.key)),t?.(e.key)},title:c?.goal,"data-explore-head":c?"":void 0,"data-enso":"tool-row","data-notice":e.notice,className:_("group/step flex min-h-6 w-full items-center gap-2 text-left text-[13px] transition-colors hover:text-foreground",cr),children:[n.jsx(ix,{state:e.exploring?"running":"ok"}),n.jsx("span",{className:_("shrink-0 text-muted-foreground group-hover/step:text-foreground",u&&_(xi,"text-foreground"),e.exploring&&"font-medium"),children:m}),n.jsx("span",{className:_("min-w-0 flex-1 truncate",u&&xi),children:h.join(" · ")}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",e.expanded&&"rotate-90")})]});return!c||!e.expanded?p:n.jsxs(n.Fragment,{children:[p,n.jsxs("div",{"data-slot":"tool-details",className:"t-acc-reveal mt-1 mb-1.5 ml-5 overflow-hidden rounded-lg border border-border/70 bg-card text-sm shadow-xs",children:[c.goal&&n.jsxs("div",{className:"border-b border-border/60 px-3 py-2",children:[n.jsx("div",{className:"mb-0.5 text-[11px] text-muted-foreground",children:s("Goal")}),n.jsx("p",{className:"whitespace-pre-wrap",children:c.goal})]}),c.report&&n.jsxs("div",{className:"border-b border-border/60 px-3 py-2",children:[n.jsx("div",{className:"mb-0.5 text-[11px] text-muted-foreground",children:s("Result")}),n.jsx(Dn,{text:c.report})]}),n.jsxs("button",{type:"button",onClick:()=>t?.(kg(e.key)),className:"flex w-full items-center gap-1.5 px-3 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground",children:[n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",c.steps&&"rotate-90")}),n.jsx("span",{children:c.steps?s("Hide process"):s("Show process")}),n.jsxs("span",{children:["· ",s("{{count}} tool calls",{count:e.count})]})]})]})]})}function Qi({children:e,className:t,follow:s}){const r=f.useRef(null),o=f.useRef(null),i=f.useRef(s),a=f.useRef(s),l=f.useRef(null),c=f.useRef(null),u=f.useRef(0);a.current=s;const d=f.useCallback(()=>{i.current=!1,l.current=null,cancelAnimationFrame(u.current)},[]),m=f.useCallback(()=>{!a.current||!i.current||(cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{const h=r.current;if(!h||!a.current||!i.current)return;const p=Math.max(0,h.scrollHeight-h.clientHeight);l.current=p,h.scrollTop=p}))},[]);return f.useEffect(()=>{s?(i.current=!0,m()):(l.current=null,cancelAnimationFrame(u.current))},[s,m]),f.useEffect(m),f.useEffect(()=>{const h=o.current;if(!h)return;const p=new ResizeObserver(m);return p.observe(h),()=>p.disconnect()},[m]),f.useEffect(()=>()=>cancelAnimationFrame(u.current),[]),n.jsx("div",{ref:r,onWheel:h=>{h.deltaY<0&&d()},onPointerDown:h=>{h.target===h.currentTarget&&d()},onTouchStart:h=>{c.current=h.touches[0]?.clientY??null},onTouchMove:h=>{const p=h.touches[0]?.clientY;p!==void 0&&c.current!==null&&p>c.current&&d(),c.current=p??null},onTouchEnd:()=>{c.current=null},onScroll:h=>{if(!a.current)return;const p=h.currentTarget;if(p.scrollHeight-p.scrollTop-p.clientHeight<=2){i.current=!0,l.current=null;return}const x=l.current;if(x!==null&&p.scrollTop>=x-2){l.current=null,m();return}d()},className:_("max-h-96 overflow-auto [overflow-anchor:none]",t),children:n.jsx("div",{ref:o,children:e})})}function Y7(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??""}catch{return String(e)}}function X7({source:e,output:t,view:s}){const r=s?.status==="completed"?Y7(s.value):s?.error??t;return n.jsxs("div",{className:"space-y-1 px-3 py-1",children:[e?n.jsx(Ng,{code:e,language:"javascript"}):null,s&&s.calls.length>0?n.jsx("div",{className:"flex flex-wrap gap-1",children:[...new Map(s.calls.map(o=>[o.name,o])).keys()].map(o=>{const i=s.calls.filter(c=>c.name===o),a=i.find(c=>!c.ok),l=`${o} ×${i.length}`;return n.jsx("span",{className:_("rounded-md border px-1.5 py-0.5 font-mono text-[10px]",a?"border-destructive/40 text-destructive":"text-muted-foreground"),title:i.map(c=>c.summary).filter(Boolean).join(`
|
|
78
|
-
`),children:a?`${l} · ${a.error??"error"}`:l},o)})}):null,r?s?.status==="completed"&&typeof s.value!="string"?n.jsx(Ng,{code:r,language:"json"}):n.jsx("pre",{className:"font-mono text-xs leading-relaxed text-muted-foreground whitespace-pre-wrap",children:_s(r)}):null,s?.console?n.jsx("pre",{className:"border-l-2 pl-2 font-mono text-xs leading-relaxed text-muted-foreground whitespace-pre-wrap",children:_s(s.console)}):null]})}function Wb({path:e,fallback:t}){const[s,r]=f.useState(!1);return s?t:n.jsx("div",{"data-slot":"read-image",className:"w-full min-w-0 px-3 py-3",children:n.jsx(El,{src:Wc(e),onError:()=>r(!0),frameClassName:"block w-full",className:"mx-auto block max-h-80 max-w-full rounded-md bg-muted/40 object-contain"})})}function Q7({item:e}){const{t}=z(),s=js(),r=pe(q=>q.compactReadOnlyTools),o=pe(q=>q.expandLiveEdits),i=r&&e.name!=="bash"&&aj(e),a=!!(e.edits&&e.edits.length>0),l=!!e.writeContent,c=!!(e.fileChanges&&e.fileChanges.length>0),u=e.sandbox??null,d=e.state==="error"?null:e.sentMessage,m=!!e.imagePath&&e.state!=="error",h=pT[e.name],p=lj(e.name),g=e.state!=="error"&&e.todos?.length===0,x=g?t("Todo list cleared"):e.subagentOp?[t(xT[e.subagentOp]),e.summary].filter(Boolean).join(" · "):e.summary,v=e.nestedPending&&e.state==="running"?`${x} · ${e.nestedPending} pending`:u?.calls.length&&e.state!=="error"?gT(u.calls):x,b=!g&&!!(e.output||e.source||d||e.ask),w=e.state==="running"&&e.waiting==="subagent"&&!s,j=a||l||c||b||w||m,T=o&&(a||l||m)&&e.state==="running",[N,S]=f.useState(T),[I,k]=f.useState(!1),L=f.useRef(null),F=e7();f.useEffect(()=>{if(!I)return;const q=L.current;if(!q)return;const te=e.key,V=F.report,se=new IntersectionObserver(([Ce])=>V(te,Ce?.isIntersecting===!0),{root:F.scroller.current});return se.observe(q),()=>{se.disconnect(),V(te,!1)}},[I,e.key,F]);const A=N&&e.name==="memory_search"?vT(e.output):null,M=N&&e.name==="memory_capture"?bT(e.output,e.memoryContent):null,R=N&&e.name==="subagent"&&e.state!=="error"?O9(e.subagentOp,e.output):null,$=e.name==="subagent"&&e.state==="error"?_9(e.output):null,U=f.useRef(c);return f.useEffect(()=>{const q=yT(e,U.current);U.current=c,(T||o&&q)&&S(!0)},[T,o,c,e]),e.todos&&e.todos.length>0?n.jsx(eW,{todos:e.todos}):e.name.startsWith("goal_")?n.jsx(J7,{item:e}):e.plan&&e.state!=="error"?n.jsx(Z7,{plan:e.plan}):n.jsxs("div",{ref:L,"data-enso":"tool-row","data-tool-style":i?"compact":"full","data-user-open":I?"true":void 0,children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("button",{type:"button",disabled:!j,onClick:()=>{const q=!N;S(q),k(q),F.report(e.key,q)},className:_("group/step flex min-h-6 min-w-0 flex-1 items-center gap-2 text-left text-[13px]",cr,j&&"cursor-pointer"),children:[n.jsx(ix,{state:e.state}),n.jsx("span",{className:_("shrink-0 text-muted-foreground transition-colors group-hover/step:text-foreground",e.state==="running"&&_(xi,"text-foreground")),children:h?t(h):p?.tool??e.name}),n.jsx("span",{className:_("min-w-0 flex-1 truncate font-mono text-[12px]",e.state==="error"?"text-destructive":"text-muted-foreground",e.state==="running"&&xi),children:e.state==="error"&&e.output?x&&e.name==="apply_patch"&&c?`${v} · ${aW(e.output)}`:$?t($):UV(_s(e.output)):x?v:null}),e.backgroundTaskId&&n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",title:e.backgroundTaskId,children:t("Moved to background")}),e.shellFailure&&e.state!=="running"&&n.jsx(k9,{failure:e.shellFailure}),e.dcgWarning&&n.jsx(N9,{warning:e.dcgWarning}),e.state==="reviewing"?n.jsx("span",{className:_("shrink-0 text-[11px] text-foreground",xi),children:t("Assistant reviewing…")}):e.state==="running"&&e.startedAt!==null?n.jsxs(n.Fragment,{children:[e.callId&&(e.name==="bash"||e.name==="powershell")&&n.jsx(iW,{callId:e.callId,startedAt:e.startedAt,output:e.output??""}),n.jsx(SC,{itemKey:e.key,since:e.startedAt??void 0})]}):(e.agentMeta||e.durationMs!==null)&&n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:[e.agentMeta?.modelId,e.agentMeta?.outputTokens?`${e.agentMeta.outputTokens} tok`:null,e.durationMs!==null?Wn(e.durationMs):null].filter(Boolean).join(" · ")}),j&&n.jsx(fn,{className:_("h-3 w-3 shrink-0 text-muted-foreground opacity-0 transition-[opacity,transform] group-hover/step:opacity-100",N&&"rotate-90 opacity-100")})]}),e.state==="running"&&e.callId&&!s&&n.jsx(tW,{callId:e.callId,waiting:!!e.waiting}),(a||l||c)&&(e.state==="ok"||c)&&n.jsx("button",{type:"button",title:t("Open in side panel"),className:"flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>cj(),children:n.jsx(aB,{className:"h-3 w-3"})})]}),e.generatedImages?.length?n.jsx("div",{"data-slot":"generated-images",className:"mt-2 mb-3 ml-5 grid gap-3",children:e.generatedImages.map(q=>n.jsx(Wb,{path:q,fallback:n.jsx("p",{className:"break-all px-3 py-2 text-xs text-muted-foreground",children:q})},q))}):null,N&&j&&n.jsxs("div",{"data-slot":"tool-details",className:"t-acc-reveal mt-1 mb-1.5 ml-5 overflow-hidden rounded-lg border border-border/70 bg-card shadow-xs",children:[p&&n.jsxs("div",{className:"truncate border-b border-border/60 px-3 py-1 font-mono text-[10px] text-muted-foreground",children:[p.server,".",p.tool]}),w&&n.jsx(oW,{agentIds:e.subagentTitles?Object.keys(e.subagentTitles):void 0}),a&&e.edits&&n.jsx(Qi,{follow:e.state==="running",children:n.jsx(f.Suspense,{fallback:null,children:n.jsx(_b,{path:e.summary,blocks:e.edits})})}),c&&e.fileChanges&&n.jsx(Qi,{follow:e.state==="running",children:e.fileChanges.map((q,te)=>n.jsxs("div",{children:[n.jsxs("div",{className:_("flex items-center gap-2 border-border/60 px-3 py-1 font-mono text-[10px] text-muted-foreground",(te>0||a)&&"border-t"),children:[n.jsx("span",{className:"uppercase",children:q.type}),n.jsx("span",{className:"min-w-0 flex-1 truncate",title:q.path,children:q.path}),q.truncated&&n.jsx("span",{children:t("Truncated preview")})]}),n.jsx(f.Suspense,{fallback:null,children:n.jsx(_b,{path:q.path,blocks:[q],snapshot:q})})]},`${q.type}:${yH(q.path,q.oldText,q.newText)}`))}),wT(e)&&n.jsx(Qi,{follow:!1,className:"border-t border-border/60",children:n.jsx("pre",{className:"px-3 py-2 font-mono text-xs leading-relaxed text-muted-foreground whitespace-pre-wrap",children:_s(e.output??"")})}),l&&e.writeContent&&n.jsx(Qi,{follow:e.state==="running",className:_((a||c)&&"border-t border-border/60"),children:n.jsx(f.Suspense,{fallback:null,children:n.jsx(Cf,{path:e.summary,contents:e.writeContent})})}),!a&&!l&&!c&&(b||m)&&n.jsxs(Qi,{follow:e.state==="running",children:[jT(e.name)?n.jsx(X7,{source:e.source,output:e.output,view:u}):e.name==="bash"||e.name==="powershell"?n.jsx(z9,{command:e.summary,output:e.output??"",failure:e.shellFailure}):e.name==="read"&&m&&e.imagePath?n.jsx(Wb,{path:e.imagePath,fallback:n.jsx(f.Suspense,{fallback:null,children:n.jsx(Cf,{path:e.summary,contents:e.output??""})})},e.imagePath):e.name==="image_view"&&e.state==="ok"?n.jsx(H9,{image:e.image,output:e.output}):e.name==="read"?n.jsx(f.Suspense,{fallback:null,children:n.jsx(Cf,{path:e.summary,contents:e.output??""})}):e.name==="subagent"&&e.state!=="error"&&!d&&!R?n.jsx("div",{className:"px-3 py-2 text-sm",children:n.jsx(Dn,{text:e.output??""})}):A?n.jsx(ih,{hits:A}):M?n.jsx(HH,{view:M}):n.jsxs(n.Fragment,{children:[e.ask&&n.jsx(MH,{ask:e.ask,waiting:e.state==="running"}),d&&n.jsx("div",{className:"px-3 py-2 text-sm",children:n.jsx(Dn,{text:d})}),R?n.jsx(R9,{view:R,titles:e.subagentTitles}):e.output&&n.jsx("pre",{className:"px-3 py-2 font-mono text-xs leading-relaxed text-muted-foreground whitespace-pre-wrap",children:_s(e.output)})]}),n.jsx(m9,{value:e.rtk}),n.jsx(RH,{value:e.approvalReview})]})]})]})}function J7({item:e}){const{t}=z(),s=e.name.replace("goal_",""),r=t(s==="complete"?"Goal completed":s==="blocked"?"Goal blocked":"Goal waiting");return n.jsxs("div",{className:_("flex items-start gap-2 rounded-lg border px-3 py-2 text-sm",s==="complete"&&"border-green-500/50 bg-green-500/5",s==="blocked"&&"border-destructive/50 bg-destructive/5",s==="wait"&&"border-amber-500/50 bg-amber-500/5"),children:[n.jsx(Fi,{className:_("mt-0.5 h-4 w-4 shrink-0",s==="complete"&&"text-green-600 dark:text-green-500",s==="blocked"&&"text-destructive",s==="wait"&&"text-amber-500")}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium",children:r}),e.summary&&n.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground text-xs",children:e.summary})]})]})}function Z7({plan:e}){const{t}=z(),[s,r]=f.useState(!1);return n.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/30 px-3 py-2",children:[n.jsxs("button",{type:"button",onClick:()=>r(o=>!o),className:"flex w-full min-w-0 items-center gap-2 text-left text-xs",children:[n.jsx(Ai,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 font-medium text-muted-foreground",children:t("Plan")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e.title}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")})]}),s&&n.jsx("div",{className:"mt-2 border-border/60 border-t pt-2 text-sm",children:n.jsx(Dn,{text:e.text})})]})}function eW({todos:e}){const{t}=z(),s=e.filter(r=>r.status==="completed").length;return n.jsxs("div",{"data-enso":"todo",className:"rounded-lg border bg-card px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.jsx(nj,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"font-medium text-foreground",children:t("Todos")}),n.jsxs("span",{className:"ml-auto tabular-nums",children:[s,"/",e.length]})]}),n.jsx(lC,{done:s,total:e.length,className:"mt-1.5 mb-2"}),n.jsx(aC,{todos:e})]})}const Ub=new Map;function tW({callId:e,waiting:t}){const{t:s}=z(),r=J(c=>Bn(c)?.id??""),[o,i]=f.useState(!1);if(f.useEffect(()=>{if(!o)return;const c=setTimeout(()=>i(!1),5e3);return()=>clearTimeout(c)},[o]),!r)return null;const a=s(t?o?"Stopping wait…":"Stop waiting":o?"Moving to background…":"Move to background"),l=t?oj:n_;return n.jsxs("button",{type:"button",disabled:o,title:a,className:"flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-60",onClick:()=>{i(!0),window.electronAPI.agent.backgroundTool(r,e).then(c=>{c.ok||i(!1)},()=>i(!1))},children:[n.jsx(l,{className:"h-3 w-3"}),a]})}const nW=5e3,sW=[];function rW(e,t){if(e.status==="queued")return t("Queued");const s=e.activity;return s?.phase==="tool"?[s.tool,s.detail].filter(Boolean).join(" "):s?.phase==="writing"?t("Writing reply…"):t("Thinking…")}function oW({agentIds:e}){const{t}=z(),s=J(l=>Bn(l)?.id??""),r=om(l=>l.byConversation[s]??sW),[o,i]=f.useState(!1);if(f.useEffect(()=>{if(!s)return;let l=!0;const c=h=>{l&&(om.getState().replace(s,h),i(!0))},u=()=>window.electronAPI.agent.subagentProgress(s).then(c,()=>{}),d=window.electronAPI.agent.onSubagentProgress(h=>{h.sessionId===s&&c(h.runs)});u();const m=setInterval(u,nW);return()=>{l=!1,clearInterval(m),d()}},[s]),!o)return null;const a=e?.length?r.filter(l=>e.includes(l.agentId)):r;return n.jsxs("div",{className:"border-b border-border/60 px-3 py-2 text-xs",children:[a.length===0?n.jsx("div",{className:"text-muted-foreground",children:t("No running subagents")}):a.map(l=>n.jsxs("div",{className:"py-0.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"max-w-[40%] shrink-0 truncate font-medium",children:l.title??l.agentId.slice(0,8)}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:rW(l,t)}),n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:Wn(l.elapsedMs)})]}),l.text&&n.jsx("div",{className:"line-clamp-2 break-words pl-2 text-[11px] text-muted-foreground/80",children:l.text.replace(/\s+/g," ")})]},l.runId)),n.jsx("div",{className:"mt-1 text-[11px] text-muted-foreground/80",children:t("Stopping the wait does not stop subagents; the assistant is notified when they finish.")})]})}function SC({itemKey:e,since:t}){const s=js(),r=J(c=>Bn(c)?.id??""),o=s?s.sessionId??"":r,i=f.useRef(null);if(i.current===null){const c=`${o}:${e}`;i.current=t??Ub.get(c)??Date.now(),t===void 0&&Ub.set(c,i.current)}const a=t??i.current,[,l]=f.useState(0);return f.useEffect(()=>{const c=setInterval(()=>l(u=>u+1),1e3);return()=>clearInterval(c)},[]),n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:Wn(Date.now()-a)})}function iW({callId:e,startedAt:t,output:s}){const r=js(),o=J(i=>r?void 0:Bn(i)?.toolDeadlineAt?.[e]);return n.jsx(j9,{startedAt:t,deadlineAt:o,output:s})}function qb(e){return e.kind==="tool-group"?!0:e.kind==="tool"&&!e.todos?.length&&!e.name.startsWith("goal_")}const aW=e=>_s(e.split(`
|
|
79
|
-
`,1)[0]??""),lW=100;function cW(e,t,s,r,o=lW){if(r||!s)return{hiddenSince:t,delayMs:null};const i=t??e;return{hiddenSince:i,delayMs:Math.max(0,o-(e-i))}}const dW=1e6;function uW(e,t,s=dW){if(t.length===0)return{anchor:null,firstItemIndex:s,remount:!1};if(!e)return{anchor:{keys:t,index:s},firstItemIndex:s,remount:!1};const r=new Map(t.map((o,i)=>[o,i]));for(let o=0;o<e.keys.length;o++){const i=r.get(e.keys[o]);if(i===void 0)continue;const a=e.index+o-i;return{anchor:{keys:t,index:a},firstItemIndex:a,remount:!1}}return{anchor:{keys:t,index:s},firstItemIndex:s,remount:!0}}function fW(e,t){return t}const mW=new Set(["text","thinking","tool","tool-group"]);function hW(e,t,s,r){const o=f.useRef(Sg),[i,a]=f.useState(()=>Date.now()),l=r.compact,c=r.autoCollapseCompletedTurns,u=r.collapseCompletedActivity===!0,d=r.collapseLiveActivity===!0,m=r.turnOverrides,h={compact:l,autoCollapseCompletedTurns:c,turnOverrides:m},p=d?WT(e,t,r,o.current,i):null;o.current=p?.witness??Sg;const g=p?.wakeAt??null,x=UT(e,t,s,{...h,collapseCompletedActivity:u,collapseLiveActivity:d,releasedLiveActivity:p?.released,heldOpenTools:r.heldOpenTools,foldToolOnlyTurns:r.foldToolOnlyTurns===!0,readableToolCards:r.readableToolCards===!0});return f.useEffect(()=>{if(g===null||g<=i)return;const v=window.setTimeout(()=>a(g),g-i);return()=>window.clearTimeout(v)},[g,i]),x}const pW=[{icon:M_,title:"Map the project",hint:"Entry points, modules and key dependencies",prompt:"Walk me through this project's structure: entry points, module layout and key dependencies."},{icon:SN,title:"Find potential issues",hint:"Suspicious logic and unhandled edge cases",prompt:"Review this project for potential bugs, suspicious logic and unhandled edge cases, and list them by severity."},{icon:pj,title:"Add unit tests",hint:"Cover the core modules with tests",prompt:"Find the core modules that lack tests and add unit tests for them."},{icon:Or,title:"Summarize recent changes",hint:"A digest based on git log",prompt:"Summarize the recent changes in this repository based on git log."}];function xW({onPick:e}){const{t}=z();return n.jsx("div",{className:"mx-auto grid w-full max-w-[560px] grid-cols-1 gap-2.5 text-left @min-[36rem]:grid-cols-2",children:pW.map(({icon:s,title:r,hint:o,prompt:i})=>n.jsxs("button",{type:"button",onClick:()=>e(t(i)),"data-slot":"welcome-suggestion",className:"group flex items-start gap-3 rounded-xl border bg-card px-3.5 py-3 text-left shadow-xs transition-[border-color,box-shadow,transform] duration-200 hover:-translate-y-px hover:border-brand/25 hover:shadow-float",children:[n.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-lg bg-brand/8 text-brand dark:bg-brand/14",children:n.jsx(s,{className:"size-3.5"})}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block text-[13px] font-medium",children:t(r)}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:t(o)})]})]},r))})}const _r="enso-chat-col mx-auto w-full max-w-2xl px-4 @min-[56rem]:max-w-3xl @min-[72rem]:max-w-4xl @min-[84rem]:max-w-5xl @min-[96rem]:max-w-6xl @min-[112rem]:max-w-7xl",Gb=1e3;function Kb({className:e,children:t}){const[s,r]=f.useState(!1);return f.useEffect(()=>{const o=requestAnimationFrame(()=>r(!0));return()=>cancelAnimationFrame(o)},[]),n.jsx("div",{className:_("t-stagger",s&&"is-shown",e),children:t})}const Yb=40,gW={index:"LAST",align:"end"},vW={top:600,bottom:600},bW=e=>e?"auto":!1;function yW({style:e,...t}){const s=e?.visibility==="hidden",[r,o]=f.useState(!1),i=f.useRef(null);return f.useEffect(()=>{const a=cW(Date.now(),i.current,s,r);if(i.current=a.hiddenSince,a.delayMs===null)return;const l=window.setTimeout(()=>o(!0),a.delayMs);return()=>window.clearTimeout(l)},[s,r]),n.jsx("div",{...t,style:s&&r?{...e,visibility:"visible"}:e})}function Ox({ref:e,items:t,busy:s,loading:r=!1,running:o,runStartedAt:i,lastOutputAt:a,error:l,emptyTitle:c,emptyDescription:u,onSuggestion:d,onRetryResume:m,onRetrySync:h,virtualize:p=!0,onStartReached:g,historyLoading:x=!1,hasOlder:v,olderCursor:b,searchQuery:w="",activeHit:j=null,secretarySession:T=!1,secretaryFace:N,quotable:S=!1}){const{t:I}=z(),k=js(),L=FS(),F=T?N??L:null,A=!k&&F?F:null,M=T,R=f.useRef(null),[$,U]=f.useState(!0),[q,te]=f.useState(!1),V=f.useRef(!0),se=f.useRef(null),Ce=f.useRef(null),de=f.useRef(0),re=f.useRef(0),Z=f.useRef(null),me=f.useRef(!1),xe=f.useRef(!1),Se=f.useRef(0),[W,H]=f.useState(null),B=f.useRef(0),ne=f.useCallback(E=>{cancelAnimationFrame(B.current),B.current=requestAnimationFrame(()=>H(E()))},[]);f.useEffect(()=>()=>cancelAnimationFrame(B.current),[]);const[ve,he]=f.useState(new Set),G=f.useRef(new Set),[we,ce]=f.useState(()=>new Set),Re=f.useCallback((E,Y)=>{const ee=G.current;Y!==ee.has(E)&&(Y?ee.add(E):ee.delete(E),ce(new Set(ee)))},[]),ue=f.useRef({report:Re,scroller:se});ue.current.report=Re;const We=f.useCallback(E=>{he(Y=>{const ee=new Set(Y);return ee.has(E)?ee.delete(E):ee.add(E),ee})},[]),[it,Fe]=f.useState(new Map),tt=pe(E=>E.autoCollapseTurns),ke=pe(E=>E.collapseCompletedActivity),nt=pe(E=>E.collapseLiveActivity),mt=pe(E=>E.liveActivityFoldDelaySec),X=pe(E=>E.compactReadOnlyTools),K=hW(t,o,ve,{compact:X,autoCollapseCompletedTurns:tt,collapseCompletedActivity:ke,collapseLiveActivity:nt,liveActivityFoldDelaySec:mt,heldOpenTools:we,turnOverrides:it,foldToolOnlyTurns:!k&&M,readableToolCards:M}),Ee=f.useRef({state:Z$,collapse:new Map,reveal:new Map}),pt=f.useMemo(()=>{const E=Ee.current,Y=Te=>se.current?.querySelector(`[data-nav-key="${CSS.escape(Te)}"]`),ee=eV(E.state,K,(Te,Ve)=>{const He=Y(Te)?.getBoundingClientRect().top,bt=Y(Ve)?.getBoundingClientRect().bottom;return He===void 0||bt===void 0?0:bt-He}),ge=Date.now();E.state=ee.next;for(const{key:Te,...Ve}of ee.collapses)E.collapse.set(Te,{at:ge,...Ve});for(const Te of ee.expands)E.reveal.set(Te,ge);return ee.children},[K]),Pt=f.useRef(null),Je=f.useRef(0),Lt=f.useRef(null),on=uW(Pt.current,K.map(E=>E.key));Pt.current=on.anchor,on.remount&&(Je.current+=1,Lt.current=null);const Pe=on.firstItemIndex,Dt=f.useCallback((E,Y)=>{Fe(ee=>ee.get(E)===Y?ee:new Map(ee).set(E,Y))},[]),Vt=f.useMemo(()=>{const E=[];for(let Y=0;Y<t.length;Y++){const ee=t[Y];if(ee.kind!=="user")continue;let ge="";for(let Te=Y+1;Te<t.length;Te++){const Ve=t[Te];if(Ve.kind==="user")break;if(Ve.kind==="text"){ge=Ve.text;break}}E.push({key:ee.key,question:qT(ee.text)||"[image]",answer:ge})}return E},[t]),Et=f.useCallback(()=>{const E=se.current;E&&E.scrollHeight-E.scrollTop-E.clientHeight>2&&(me.current=!0,E.scrollTop=E.scrollHeight)},[]),oe=f.useCallback(()=>{cancelAnimationFrame(de.current);const E=Date.now()+1200;let Y=null;const ee=()=>{cancelAnimationFrame(de.current),me.current=!1,Y?.removeEventListener("touchstart",ee),Y?.removeEventListener("wheel",ee)},ge=()=>{if(xe.current){ee();return}!Y&&se.current&&(Y=se.current,Y.addEventListener("touchstart",ee,{passive:!0,once:!0}),Y.addEventListener("wheel",ee,{passive:!0,once:!0})),Et(),V.current=!0,U(!0),Date.now()<E?de.current=requestAnimationFrame(ge):ee()};ge(),U(!0),V.current=!0},[Et]);f.useEffect(()=>()=>{cancelAnimationFrame(de.current),cancelAnimationFrame(re.current),window.clearTimeout(Se.current)},[]);const Le=()=>{xe.current=!0,window.clearTimeout(Se.current)},st=()=>{window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{xe.current=!1},400)},at=()=>{Le(),st()},gt=()=>{cancelAnimationFrame(de.current),cancelAnimationFrame(re.current),me.current=!1,V.current=!1,U(!1)},xt=f.useCallback(E=>{if(Z.current?.disconnect(),Z.current=null,!E)return;const Y=new ResizeObserver(()=>{if(!V.current&&!me.current)return;cancelAnimationFrame(re.current);let ee=8;const ge=()=>{Et();const Te=se.current;(Te?Te.scrollHeight-Te.scrollTop-Te.clientHeight:0)<=2||(--ee>0?re.current=requestAnimationFrame(ge):oe())};ge()});Y.observe(E),Z.current=Y,oe()},[Et,oe]);f.useEffect(()=>()=>Z.current?.disconnect(),[]);const zt=E=>K.findIndex(Y=>Y.key===E||Y.kind==="tool-group"&&CC(Y,E)),Wt=E=>{if(!p){se.current?.querySelector(`[data-nav-key="${CSS.escape(E)}"]`)?.scrollIntoView({block:"center"});return}const Y=zt(E);Y>=0&&R.current?.scrollToIndex({index:fW(Pe,Y),align:"center"})},an=f.useRef(null),en=E=>{if(gt(),zt(E)>=0){an.current=null,Wt(E);return}let Y=null,ee=!1;for(const ge of t)if(ge.kind==="user"&&(Y=ge.key),ge.key===E){ee=!0;break}!ee||!Y||(an.current=E,Dt(Y,!1))};f.useLayoutEffect(()=>{const E=an.current;!E||zt(E)<0||(an.current=null,Wt(E))},[K]),f.useImperativeHandle(e,()=>({scrollToBottom:oe,pinToBottom:Et,isAtBottom:()=>V.current,getScroller:()=>p?null:se.current,scrollToKey:en}));const Bt=f.useRef(!1),pn=`${b}:${Pe}`,Gn=f.useRef(pn);Gn.current!==pn&&(Gn.current=pn,Bt.current=!1);const vt=()=>{!g||Bt.current||(Bt.current=!0,g())};f.useEffect(()=>{p&&!x&&Lt.current===Pe&&vt()},[b,x]);const sn=f.useMemo(()=>({query:w,activeKey:j?.key??"",activeNth:j?.nth??-1}),[w,j?.key,j?.nth]),Rn=(E,Y)=>{const ee=K[Y+1];if(ee!==void 0&&qb(E)&&qb(ee))return"pb-0";if(!X)return"pb-4";const ge=ee!==void 0&&zb(ee);return zb(E)?ge?"pb-1":"pb-2":E.kind==="text"&&ge?"pb-1":"pb-4"},C=(E,Y)=>{const ee=K[Y-1],ge=ee?.kind==="user"&&!ee.collapsed&&mW.has(E.kind)?ee:void 0,Te=Date.now(),Ve=Ee.current.collapse.get(E.key),He=Ve&&Te-Ve.at<Gb?Ve:void 0,bt=pt.get(E.key),Xe=bt&&Ee.current.reveal.get(bt.group),ae=bt&&Xe!==void 0&&Te-Xe<Gb;return n.jsxs("div",{"data-nav-key":E.key,"data-fold-collapse":He?He.pair?"pair":"toggle":void 0,style:He?{"--fold-from":`${He.height}px`}:ae?{"--fold-i":bt.index}:void 0,className:_(_r,Rn(E,Y),ae&&"t-fold-reveal","[overflow-wrap:anywhere]"),children:[ge&&n.jsx(k7,{model:ge.replyModel,at:ge.replyAt,privacyMask:ge.replyPrivacyMask,secretarySession:M,face:F}),n.jsx(CW,{itemKey:E.key,children:n.jsx(N7,{item:E,secretarySession:M,onToggleGroup:We,onToggleTurn:Dt})})]},E.key)},D=f.useRef(!1);v===!0&&(D.current=!0);const P=GT(t.length>0,x,v,D.current,!p&&q);f.useLayoutEffect(()=>{if(p){te(!1);return}const E=se.current;te(!!E&&KT(v===!0,x,E.scrollHeight,E.clientHeight))},[p,v,x,Pe,K.length,t.length]);const y={pageChrome:P,onLoadMore:P==="more"?vt:void 0,busy:s,loading:!!r,since:tV({loading:!!r,runStartedAt:i}),error:l,onRetryResume:m};return n.jsx(YT.Provider,{value:sn,children:n.jsx(Z9,{value:ue.current,children:n.jsxs("div",{ref:Ce,"data-enso":"timeline",className:"@container relative min-h-24 flex-1",onWheel:at,onKeyDown:at,onTouchStart:E=>{se.current?.contains(E.target)&&Le()},onTouchEnd:st,onPointerDown:E=>{E.target===se.current&&(Le(),window.addEventListener("pointerup",st,{once:!0}))},children:[n.jsx(rV,{items:Vt,activeKey:W,onJump:en}),S&&n.jsx(mV,{containerRef:Ce}),t.length===0&&!s?n.jsxs(Kb,{className:"flex h-full flex-col items-center justify-center gap-2 overflow-y-auto px-4 text-center",children:[n.jsx("span",{className:"t-stagger-line t-stagger-line--1 mb-3",children:A?n.jsx($h,{name:A.name,color:A.color,image:A.image,needsYou:0,running:0,size:"lg",enso:"secretary-chat-avatar"}):n.jsx("span",{className:"flex size-11 items-center justify-center rounded-[13px] border border-brand/20 bg-brand/8 text-brand dark:bg-brand/14",children:n.jsx(J$,{className:"size-6"})})}),n.jsx("p",{className:"t-stagger-line t-stagger-line--1 text-[22px] font-semibold tracking-tight",children:c}),l?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"t-stagger-line t-stagger-line--2 max-w-md text-sm text-destructive whitespace-pre-wrap",children:I(l)}),m&&n.jsx(fe,{size:"sm",variant:"outline",onClick:m,children:I("Retry resume")})]}):n.jsxs(n.Fragment,{children:[h?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"t-stagger-line t-stagger-line--2 max-w-md text-sm text-muted-foreground",children:I("Session is not ready yet — no history to show.")}),n.jsx(fe,{size:"sm",variant:"outline",onClick:h,children:I("Retry sync")})]}):u!==""?n.jsx("p",{className:"t-stagger-line t-stagger-line--2 text-sm text-muted-foreground",children:u??I("Ask the agent…")}):null,d&&n.jsx("div",{className:"t-stagger-line t-stagger-line--3 mt-5 w-full",children:n.jsx(xW,{onPick:d})})]})]}):t.length===0&&l?n.jsxs(Kb,{className:"flex h-full flex-col items-center justify-center gap-2 text-center",children:[n.jsx("p",{className:"t-stagger-line t-stagger-line--1 max-w-md text-sm text-destructive whitespace-pre-wrap",children:I(l)}),m&&n.jsx(fe,{size:"sm",variant:"outline",onClick:m,children:I("Retry resume")})]}):t.length===0?n.jsxs("div",{"data-timeline-loading":"",className:"flex h-full flex-col items-center justify-center gap-2.5 text-center",children:[n.jsx(_t,{className:"h-5 w-5 animate-spin text-muted-foreground"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:I("Preparing session…")})]}):p?n.jsx(L$,{ref:R,data:K,defaultItemHeight:80,computeItemKey:(E,Y)=>Y.key,firstItemIndex:Pe,startReached:vt,followOutput:bW,atBottomThreshold:Yb,atBottomStateChange:E=>{if(!E&&V.current&&!xe.current){oe();return}U(E),V.current=E},increaseViewportBy:vW,initialTopMostItemIndex:gW,rangeChanged:({startIndex:E})=>{Lt.current=E,E>Pe+4&&(Bt.current=!1),ne(()=>{const Y=Math.max(0,E-Pe);let ee=null;for(let ge=0;ge<=Math.min(Y+1,K.length-1);ge++)K[ge]?.kind==="user"&&(ee=K[ge].key);return ee})},scrollerRef:E=>{se.current=E instanceof HTMLElement?E:null},className:"h-full select-text",context:y,components:jW,itemContent:(E,Y)=>C(Y,E-Pe)},Je.current):n.jsx("div",{ref:E=>{se.current=E},onScroll:E=>{const Y=E.currentTarget;if(me.current){me.current=!1,V.current=!0,U(!0);return}if(!xe.current){V.current&&Et();return}const ee=Y.scrollHeight-Y.scrollTop-Y.clientHeight<=Yb;ee!==V.current&&(V.current=ee,U(ee)),g&&(Y.scrollTop<80&&!Bt.current?(Bt.current=!0,g()):Y.scrollTop>240&&(Bt.current=!1))},className:"h-full select-text overflow-y-auto [overflow-anchor:none]",children:n.jsxs("div",{ref:xt,children:[n.jsx(IC,{context:y}),K.map((E,Y)=>C(E,Y)),n.jsx(TC,{context:y})]})}),!$&&t.length>0&&n.jsxs("button",{type:"button",onClick:oe,className:"absolute bottom-4 left-1/2 z-10 inline-flex h-7 -translate-x-1/2 items-center gap-1.5 rounded-full border bg-card px-3 text-xs text-muted-foreground shadow-float transition-colors hover:text-foreground",children:[n.jsx(Vh,{className:"h-3 w-3"}),I("Scroll to bottom")]})]})})})}function CC(e,t){return e.children.some(s=>s.key===t||s.kind==="tool-group"&&CC(s,t))}function wW({chrome:e,onLoadMore:t}){const{t:s}=z();return e==="none"?n.jsx("div",{className:"h-6"}):n.jsx("div",{className:_(_r,"flex items-center justify-center gap-2 py-3"),children:e==="loading"?n.jsxs(n.Fragment,{children:[n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:s("Loading earlier messages…")})]}):e==="more"?n.jsx("button",{type:"button",className:"text-xs text-muted-foreground underline-offset-2 hover:underline",onClick:t,children:s("Load earlier messages")}):n.jsx("p",{className:"text-xs text-muted-foreground",children:s("Beginning of conversation")})})}function IC({context:e}){return n.jsx(wW,{chrome:e.pageChrome,onLoadMore:e.onLoadMore})}function TC({context:e}){const{t}=z(),{busy:s,loading:r,since:o,error:i,onRetryResume:a}=e;return n.jsxs("div",{className:_(_r,"pb-6 [overflow-wrap:anywhere]"),children:[s&&n.jsxs("div",{className:"flex min-h-[26px] items-center gap-2 text-[13px]",children:[n.jsx(kW,{}),n.jsx("span",{className:"animate-pulse text-foreground motion-reduce:animate-none",children:t(r?"Loading…":"Working…")}),o!==void 0&&n.jsx(SW,{since:o})]}),i&&n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("p",{className:"min-w-0 flex-1 text-sm text-destructive whitespace-pre-wrap",children:t(i)}),n.jsx(jC,{}),a&&n.jsx(fe,{size:"sm",variant:"outline",onClick:a,children:t("Retry resume")})]})]})}const jW={List:yW,Header:IC,Footer:TC};function kW(){return n.jsxs("span",{className:"relative flex size-[22px] shrink-0 items-center justify-center",children:[n.jsx("span",{className:"absolute size-2 animate-ping rounded-full bg-brand/50"}),n.jsx("span",{className:"relative size-2 rounded-full bg-brand"})]})}const NW=e=>{const t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m${t%60}s`},SW=f.memo(function({since:t}){const[,s]=f.useState(0);return f.useEffect(()=>{const r=setInterval(()=>s(o=>o+1),1e3);return()=>clearInterval(r)},[]),n.jsx("span",{className:"font-mono text-[11px] text-muted-foreground tabular-nums",children:NW(Date.now()-t)})});class CW extends f.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidUpdate(t){t.itemKey!==this.props.itemKey&&this.state.failed&&this.setState({failed:!1})}render(){return this.state.failed?n.jsxs("p",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:["message render failed · ",this.props.itemKey]}):this.props.children}}const gi={type:"spring",stiffness:400,damping:30},Id={type:"tween",duration:.22,ease:[.2,0,0,1]},If={initial:{height:0,opacity:0},animate:{height:"auto",opacity:1,transition:Id},exit:{height:0,opacity:0,transition:Id}};function gee(e){return e.resizing?!0:e.previousConversationId!==void 0&&e.conversationId!==void 0&&e.previousConversationId!==e.conversationId}function IW(e){return e.skip?{duration:0}:e.cover||e.targetW===0?Id:gi}const TW={ts:Gi,tsx:Gi,js:Gi,jsx:Gi,mjs:Gi,json:Hh,html:T_,css:Cg,scss:Cg,md:Wo,sh:im,bash:im,yml:Os,yaml:Os,toml:Os},AW={ts:"text-blue-500",tsx:"text-blue-500",js:"text-yellow-500",jsx:"text-yellow-500",mjs:"text-yellow-500",json:"text-yellow-600",html:"text-orange-500",css:"text-pink-500",scss:"text-pink-500",md:"text-sky-500",sh:"text-muted-foreground"};function EW(e,t,s=!1){if(t)return s?Lr:lu;const r=e.split(".").pop()?.toLowerCase()??"";return TW[r]??q_}function RW(e,t){if(t)return"text-amber-500";const s=e.split(".").pop()?.toLowerCase()??"";return AW[s]??"text-muted-foreground"}const MW=f.lazy(()=>Hd(()=>import("./ReadFileView-C5AKNlFU.js"),__vite__mapDeps([5,1,2,6,4]),import.meta.url).then(e=>({default:e.ReadFileView}))),PW={artifacts:[],media:[]},Tf=new Map,Af=new Map,DW=new Set(["image","markdown","html","text"]),OW=e=>e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`;function LW(e){const t=JSON.stringify(e),[s,r]=f.useState(()=>Tf.get(t)??PW);return f.useEffect(()=>{if(Tf.has(t))return;let o=!0;return window.electronAPI.bots.artifacts.list(JSON.parse(t)).then(i=>{if(!o||!i.ok)return;const a={artifacts:i.artifacts,media:i.media??[]};(a.artifacts.length>0||a.media.length>0)&&Tf.set(t,a),r(a)}).catch(()=>{}),()=>{o=!1}},[t]),s}function _W(e){const{t}=z();return(s,r)=>{window.electronAPI.bots.artifacts.open({...e,rel:s.rel,action:r}).then(o=>{o.ok||Ie({type:"error",title:o.error==="not-openable"?t("This file type is only shown in Finder"):t("Could not open the file")})})}}function Td({target:e}){const{artifacts:t,media:s}=LW(e);return n.jsxs(n.Fragment,{children:[s.length>0&&n.jsx(FW,{target:e,media:s}),t.length>0&&n.jsx(VW,{target:e,artifacts:t})]})}function BW(){const{t:e}=z();return({source:t,name:s})=>t==="upload"?"":t==="web"?e("Web screenshot"):t==="desktop"?e("Desktop screenshot"):s&&/^(?:\/|[A-Za-z]:[\\/])/.test(s)?e("This computer"):e("Workspace image")}function AC(e,t,s){const r=JSON.stringify(e),o=t&&s==="thumb"?Af.get(t):void 0,[i,a]=f.useState(o?{ok:!0,kind:"image",dataUrl:o}:null);return f.useEffect(()=>{const l=t&&s==="thumb"?Af.get(t):void 0;if(a(l?{ok:!0,kind:"image",dataUrl:l}:null),!t||l)return;let c=!0;return window.electronAPI.bots.artifacts.read({...JSON.parse(r),mediaId:t,variant:s}).then(u=>{s==="thumb"&&u.ok&&u.kind==="image"&&Af.set(t,u.dataUrl),c&&a(u)}).catch(()=>c&&a({ok:!1,error:"unavailable"})),()=>{c=!1}},[r,t,s]),i}function FW({target:e,media:t}){const{t:s}=z(),r=BW(),[o,i]=f.useState(null),a=t.some(l=>l.ok&&l.source==="desktop");return n.jsxs("div",{className:"mt-2","data-bot-media":"",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map((l,c)=>l.ok?n.jsx(zW,{target:e,item:l,label:r(l),onOpen:()=>i(l)},l.mediaId):n.jsxs("div",{className:"flex w-40 flex-col gap-1 rounded-lg border border-destructive/60 border-dashed p-2 text-destructive text-xs",children:[n.jsxs("span",{className:"flex items-center gap-1 font-medium",children:[n.jsx(gd,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"truncate",children:l.name??r(l)})]}),n.jsx("span",{children:l.error==="quota"?s("Chat image storage is full (200 MiB); not saved"):s("Not sent: still over 10 MiB after compression")})]},`failed-${c}`))}),a&&n.jsx("p",{className:"mt-1 text-warning text-xs",children:s("Desktop screenshots may capture sensitive content from other windows.")}),n.jsx($W,{target:e,item:o,label:o?r(o):"",onClose:()=>i(null)})]})}function zW({target:e,item:t,label:s,onOpen:r}){const o=AC(e,t.mediaId,"thumb"),i=t.caption??t.name??s;return n.jsxs("button",{type:"button",title:i,onClick:r,className:"relative h-24 w-36 overflow-hidden rounded-lg border bg-muted",children:[o?.ok&&o.kind==="image"?n.jsx("img",{src:o.dataUrl,alt:i,className:"h-full w-full object-cover"}):o?n.jsx(gd,{className:"m-auto h-4 w-4 text-muted-foreground"}):n.jsx(_t,{className:"m-auto h-4 w-4 animate-spin text-muted-foreground"}),s&&n.jsx("span",{className:_("absolute top-1 left-1 rounded px-1 text-[10px] leading-4",t.source==="desktop"?"bg-warning text-warning-foreground":"bg-black/60 text-white"),children:s}),(t.caption||t.name)&&n.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/70 to-transparent px-1.5 pt-3 pb-0.5 text-left text-[10px] text-white",children:t.caption??t.name})]})}function $W({target:e,item:t,label:s,onClose:r}){const{t:o}=z(),i=AC(e,t?.mediaId??null,"full"),a=t?.caption??t?.name??s;return n.jsx(cn,{open:t!==null,onOpenChange:l=>!l&&r(),children:n.jsxs(dn,{className:"flex h-[80vh] max-w-4xl flex-col",children:[n.jsx(un,{children:n.jsxs(rn,{className:"flex min-w-0 items-center gap-2 pr-8",children:[n.jsx("span",{className:"truncate",children:a}),n.jsx("span",{className:"shrink-0 font-normal text-muted-foreground text-xs",children:s})]})}),t?.source==="desktop"&&n.jsx("p",{className:"text-warning text-xs",children:o("Desktop screenshots may capture sensitive content from other windows.")}),t?.source==="file"&&n.jsx("p",{className:"text-muted-foreground text-xs",children:o("Copied into this chat: later edits or deletion of the original do not change it. Deleted together with the chat.")}),n.jsx(EC,{name:a,content:i})]})})}function VW({target:e,artifacts:t}){const{t:s}=z(),r=_W(e),[o,i]=f.useState(null);return n.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1.5","data-bot-artifacts":"",children:[t.map(a=>{const l=EW(a.name,!1),c=DW.has(a.kind)||a.kind==="pdf";return n.jsxs("div",{"data-slot":"bot-card",className:"group/artifact flex max-w-64 items-center gap-1 rounded-lg border bg-card py-1 pr-1 pl-2 text-xs",children:[n.jsxs("button",{type:"button",title:a.rel,disabled:!c,onClick:()=>a.kind==="pdf"?r(a,"preview"):i(a),className:"flex min-w-0 items-center gap-1.5 text-left enabled:hover:underline disabled:cursor-default",children:[n.jsx(l,{className:_("h-3.5 w-3.5 shrink-0",RW(a.name,!1))}),n.jsx("span",{className:"truncate",children:a.name}),n.jsx("span",{className:"shrink-0 text-muted-foreground",children:OW(a.size)})]}),n.jsx("button",{type:"button",title:s("Show in Finder"),onClick:()=>r(a,"reveal"),className:"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Lr,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",title:s("Open with default app"),onClick:()=>r(a,"open"),className:"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(xj,{className:"h-3.5 w-3.5"})})]},a.rel)}),n.jsx(HW,{target:e,artifact:o,onOpen:r,onClose:()=>i(null)})]})}function HW({target:e,artifact:t,onOpen:s,onClose:r}){const{t:o}=z(),[i,a]=f.useState(null),l=t?.rel,c=JSON.stringify(e);return f.useEffect(()=>{if(a(null),!l)return;let u=!0;return window.electronAPI.bots.artifacts.read({...JSON.parse(c),rel:l}).then(d=>u&&a(d)).catch(()=>u&&a({ok:!1,error:"unavailable"})),()=>{u=!1}},[c,l]),n.jsx(cn,{open:t!==null,onOpenChange:u=>!u&&r(),children:n.jsxs(dn,{className:"flex h-[80vh] max-w-4xl flex-col",children:[n.jsx(un,{children:n.jsxs(rn,{className:"flex min-w-0 items-center gap-2 pr-8",children:[n.jsx("span",{className:"truncate",children:t?.name}),n.jsx("span",{className:"truncate font-normal text-muted-foreground text-xs",children:t?.rel}),n.jsx("span",{className:"flex-1"}),t&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",title:o("Show in Finder"),onClick:()=>s(t,"reveal"),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Lr,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",title:o("Open with default app"),onClick:()=>s(t,"open"),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(xj,{className:"h-4 w-4"})})]})]})}),n.jsx(EC,{name:t?.name??"",content:i})]})})}function EC({name:e,content:t}){const{t:s}=z();return n.jsxs("div",{className:"min-h-0 flex-1 select-text overflow-auto border-t","data-bot-artifact-preview":"",children:[!t&&n.jsx("div",{className:"flex justify-center p-6 text-muted-foreground",children:n.jsx(_t,{className:"h-4 w-4 animate-spin"})}),t&&!t.ok&&n.jsx("p",{className:"p-6 text-muted-foreground text-sm",children:t.error==="too-large"?s("The file is too large to preview"):s("Could not open the file")}),t?.ok&&t.kind==="image"&&n.jsx("img",{src:t.dataUrl,alt:e,className:"mx-auto max-h-full max-w-full object-contain p-4"}),t?.ok&&t.kind==="markdown"&&n.jsx("div",{className:"px-6 py-4 text-sm",children:n.jsx(Dn,{text:t.text})}),t?.ok&&t.kind==="html"&&n.jsx("iframe",{title:e,sandbox:"",srcDoc:t.text,className:"h-full w-full bg-white"}),t?.ok&&t.kind==="text"&&n.jsx("div",{className:"p-2 text-xs",children:n.jsx(f.Suspense,{fallback:null,children:n.jsx(MW,{path:e,contents:t.text})})})]})}const RC="enso:design-annotations:v1",MC="enso:annotate-prefs:v1",Xb=ZT(e=>e.pageKey),Qb=[],Jb=new WeakMap,qr={annotateHovered:!1,annotateEntered:!1,annotateUseCount:0,annotateSendImmediately:!0};function PC(e){try{return typeof localStorage>"u"?null:localStorage.getItem(e)}catch{return null}}function DC(e,t){try{if(typeof localStorage>"u")return;localStorage.setItem(e,t)}catch{}}function WW(){const e=PC(MC);if(!e)return qr;try{const t=JSON.parse(e);return{annotateHovered:typeof t.annotateHovered=="boolean"?t.annotateHovered:qr.annotateHovered,annotateEntered:typeof t.annotateEntered=="boolean"?t.annotateEntered:qr.annotateEntered,annotateUseCount:typeof t.annotateUseCount=="number"&&Number.isFinite(t.annotateUseCount)?t.annotateUseCount:qr.annotateUseCount,annotateSendImmediately:typeof t.annotateSendImmediately=="boolean"?t.annotateSendImmediately:qr.annotateSendImmediately}}catch{return qr}}function Ji(e){DC(MC,JSON.stringify(e))}const Zb=XT(PC(RC)),UW=WW();function tc(e,t){DC(RC,JT({queues:e,pages:t}))}const _n=ro((e,t)=>({...UW,queues:Zb.queues,pages:Zb.pages,sessions:new Map,familiarity:()=>{const s=t();return QT(s.annotateEntered,s.annotateUseCount)},markHovered:()=>{const s=t();if(s.annotateHovered)return;const r={annotateHovered:!0,annotateEntered:s.annotateEntered,annotateUseCount:s.annotateUseCount,annotateSendImmediately:s.annotateSendImmediately};Ji(r),e({annotateHovered:!0})},markEntered:()=>{const s=t();if(s.annotateEntered)return;const r={annotateHovered:s.annotateHovered,annotateEntered:!0,annotateUseCount:s.annotateUseCount,annotateSendImmediately:s.annotateSendImmediately};Ji(r),e({annotateEntered:!0})},setSendImmediately:s=>{const r=t();if(r.annotateSendImmediately===s)return;const o={annotateHovered:r.annotateHovered,annotateEntered:r.annotateEntered,annotateUseCount:r.annotateUseCount,annotateSendImmediately:s};Ji(o),e({annotateSendImmediately:s})},annotationsFor:(s,r)=>{const o=t().queues.get(s);if(!o||o.items.length===0)return Qb;if(!r)return o.items;let i=Jb.get(o.items);i||(i=new Map,Jb.set(o.items,i));const a=i.get(r);if(a)return a;const l=o.items.filter(u=>u.browserId===r),c=l.length===0?Qb:l;return i.set(r,c),c},pageKeyOf:s=>t().pages.get(s),setBrowserUrl:(s,r)=>{if(!r)return;const o=gj(r),i=t().pages;if(i.get(s)===o)return;const a=new Map(i);a.delete(s),a.set(s,o),tc(t().queues,a),e({pages:a})},dispatchQueue:(s,r)=>{const o=t(),i=o.queues.get(s)??{items:[]},a=Xb(i,r);if(a===i)return;const l=new Map(o.queues);l.delete(s),a.items.length>0&&l.set(s,a),tc(l,o.pages),e({queues:l})},addAnnotation:(s,r)=>{const o=t(),i=o.queues.get(s)??{items:[]},a=Xb(i,{type:"add",draft:r});if(a===i)return;const l=new Map(o.queues);l.delete(s),a.items.length>0&&l.set(s,a),tc(l,o.pages);const c=o.annotateUseCount+1;return Ji({annotateHovered:o.annotateHovered,annotateEntered:o.annotateEntered,annotateUseCount:c,annotateSendImmediately:o.annotateSendImmediately}),e({queues:l,annotateUseCount:c}),a.items.find(u=>u.id===r.id)},updateAnnotation:(s,r,o,i)=>{t().dispatchQueue(s,{type:"update",id:r,comment:o,images:i})},removeAnnotations:(s,r)=>{t().dispatchQueue(s,{type:"remove",ids:r})},clearAnnotations:(s,r)=>{if(!r){t().dispatchQueue(s,{type:"clear"});return}const o=t().annotationsFor(s,r).map(i=>i.id);o.length>0&&t().dispatchQueue(s,{type:"remove",ids:o})},restoreAnnotations:(s,r)=>{t().dispatchQueue(s,{type:"restore",items:r})},registerSession:(s,{url:r,...o})=>{t().setBrowserUrl(s,r);const i=new Map(t().sessions);return i.set(s,{...o,pinned:new Set}),e({sessions:i}),()=>{const a=t().sessions;if(a.get(s)?.exit!==o.exit)return;const l=new Map(a);l.delete(s),e({sessions:l})}},setPinnedIds:(s,r)=>{const o=t().sessions,i=o.get(s);if(!i)return;const a=new Set(r);if(i.pinned.size===a.size&&[...i.pinned].every(c=>a.has(c)))return;const l=new Map(o);l.set(s,{...i,pinned:a}),e({sessions:l})},exitAgentSessions:s=>{for(const r of t().sessions.values())r.agent===s&&r.exit()},resetForTests:()=>{Ji(qr),tc(new Map,new Map),e({...qr,queues:new Map,pages:new Map,sessions:new Map})}})),vi=typeof navigator<"u"&&navigator.platform?navigator.platform.startsWith("Mac"):!0,dh=vi?"⌘⇧D":"Ctrl+Shift+D";function Ef({className:e}){return n.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",className:_("h-3.5 w-3.5 shrink-0",e),children:n.jsx("path",{d:"M14.434 6.765c.793 0 1.076 1.051.388 1.448l-3.593 2.074v4.15c0 .793-1.052 1.075-1.449.387L5.8 7.93c-.299-.517.075-1.164.672-1.164zM13 .875c1.174 0 2.125.951 2.125 2.125v1c0 .345-.28.625-.625.625s-.625-.28-.625-.625V3c0-.483-.392-.875-.875-.875H3c-.483 0-.875.392-.875.875v10c0 .483.392.875.875.875h3c.345 0 .625.28.625.625s-.28.625-.625.625H3C1.826 15.125.875 14.174.875 13V3C.875 1.826 1.826.875 3 .875zm-5.708 7.14 2.687 4.651v-2.565c0-.331.176-.638.462-.803l2.223-1.283z"})})}async function qW(e){return e.markup.length===0||!e.base64?e.base64:new Promise(t=>{const s=new Image;s.onload=()=>{try{const r=document.createElement("canvas");r.width=Math.max(1,s.naturalWidth||s.width),r.height=Math.max(1,s.naturalHeight||s.height);const o=r.getContext("2d");if(!o){t(e.base64);return}o.drawImage(s,0,0);const i=r.width/Math.max(1,e.cropWidth);o.scale(i,i),o.fillStyle=si,o.strokeStyle=si,o.lineWidth=cm,o.lineCap="round",o.lineJoin="round";for(const l of e.markup)for(const c of lm(l,"complete")){const u=new Path2D(c.d);c.paint==="fill"?o.fill(u):o.stroke(u)}const a=r.toDataURL("image/png");t(a.slice(a.indexOf(",")+1))}catch{t(e.base64)}},s.onerror=()=>t(e.base64),s.src=e.base64.startsWith("data:")?e.base64:`data:image/png;base64,${e.base64}`})}function GW({active:e}){const t=f.useRef(null),[s,r]=f.useState(null),o=f.useRef(e),[i,a]=f.useState({width:0,height:0});f.useEffect(()=>{o.current!==e&&(o.current=e,r(e?"in":"out"))},[e]),f.useEffect(()=>{const c=t.current;if(!c)return;const u=()=>{const m=c.getBoundingClientRect();a({width:Math.round(m.width),height:Math.round(m.height)})};u();const d=new ResizeObserver(u);return d.observe(c),()=>d.disconnect()},[]);const l=f.useMemo(()=>i.width>4&&i.height>4?iA(i.width,i.height,{topLeft:6,topRight:6,bottomRight:6,bottomLeft:6}):null,[i.width,i.height]);return!s&&!e?n.jsx("div",{ref:t,className:"pointer-events-none absolute inset-0"}):n.jsx("div",{ref:t,"aria-hidden":"true","data-component":"design-frame-ring","data-trace":s??(e?"in":"out"),className:"pointer-events-none absolute inset-0 z-20 overflow-hidden",children:l&&n.jsxs("svg",{width:i.width,height:i.height,"aria-hidden":"true",className:"block h-full w-full overflow-visible",onAnimationEnd:()=>{e||r(null)},children:[n.jsx("path",{d:l.right,pathLength:1,fill:"none",stroke:"rgb(58, 150, 221)",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:1,strokeDashoffset:s==="out"?1:0,transition:s==="out"?"stroke-dashoffset 350ms cubic-bezier(0.65, 0, 0.35, 1)":"stroke-dashoffset 550ms cubic-bezier(0.65, 0, 0.35, 1)"}}),n.jsx("path",{d:l.left,pathLength:1,fill:"none",stroke:"rgb(58, 150, 221)",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:1,strokeDashoffset:s==="out"?1:0,transition:s==="out"?"stroke-dashoffset 350ms cubic-bezier(0.65, 0, 0.35, 1)":"stroke-dashoffset 550ms cubic-bezier(0.65, 0, 0.35, 1)"}})]})})}function KW({drawing:e,pick:t,markupTool:s,editorOpen:r,onMarkupToolChange:o,onExit:i}){const a=sA({drawing:e,pick:t?{region:t.region}:null,markupToolHeld:s!==null,editorOpen:r}),c=f.useMemo(()=>rA(vi),[])[a],u=m=>m.map((h,p)=>typeof h=="string"?n.jsx("span",{children:h},p):n.jsx("strong",{className:"font-semibold text-foreground",children:h.key},p)),d=m=>{switch(m){case"pencil":return n.jsx(bs,{className:"h-3.5 w-3.5"});case"circle":return n.jsx(Jp,{className:"h-3.5 w-3.5"});case"square":return n.jsx(Uh,{className:"h-3.5 w-3.5"});case"arrow-right-up":return n.jsx(Bi,{className:"h-3.5 w-3.5"})}};return n.jsxs("div",{"data-component":"design-hint-row",style:{backgroundColor:"var(--background)"},className:"flex h-8 shrink-0 items-center justify-between gap-2 border-b px-2.5 text-xs",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("button",{type:"button",onClick:i,"aria-label":"Exit design mode",title:`Exit Design Mode (${dh})`,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-black/5 hover:text-foreground dark:hover:bg-white/10",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})}),n.jsx("span",{"data-hint":"",className:"truncate text-[12px] text-muted-foreground transition-all duration-150",children:u(c)})]}),n.jsx("div",{role:"toolbar","aria-label":"Screenshot markup tools",className:"flex shrink-0 items-center gap-0.5 rounded-md border bg-background/90 p-0.5 shadow-2xs",children:oA.map(m=>{const h=s===m.tool;return n.jsx("button",{type:"button","aria-label":m.label,"aria-pressed":h,title:m.label,onClick:()=>o(h?null:m.tool),className:_("flex h-5 w-5 items-center justify-center rounded-sm transition-colors",h?"bg-[#3a96dd] text-white":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:d(m.icon)},m.tool)})})]})}function YW({tabId:e,conversationId:t,active:s,disabled:r,queueOpen:o,onQueueOpenChange:i,onToggleDesignMode:a,onOpenPinFromQueue:l,onSendQueue:c}){const{t:u}=z(),d=_n(N=>N.familiarity()),m=_n(N=>N.annotateHovered),h=_n(N=>N.markHovered),p=_n(N=>N.annotationsFor(t)),g=_n(N=>N.annotationsFor(t,e)),x=_n(N=>N.removeAnnotations),v=_n(N=>N.clearAnnotations),[b,w]=f.useState(!1),j=s?p:g,T=j.length;return T===0&&!s?n.jsxs("div",{className:"relative flex shrink-0 items-center",children:[n.jsxs("button",{type:"button",disabled:r,"aria-label":"Annotate","aria-pressed":s,title:`Annotate (${dh}) — Point at anything and tell the agent what to fix`,onPointerEnter:()=>{h(),d==="never"&&w(!0)},onPointerLeave:()=>w(!1),onClick:()=>{w(!1),a(!0)},className:_("relative flex h-6 items-center justify-center gap-1 overflow-hidden rounded text-xs font-medium transition-colors disabled:opacity-40",d==="many"?"w-6 text-muted-foreground hover:bg-muted hover:text-foreground":"px-2 text-foreground hover:bg-muted",d==="never"&&!m&&"border border-sky-500/40 bg-sky-500/10"),children:[n.jsx(Ef,{}),d!=="many"&&n.jsx("span",{children:"Annotate"}),d==="never"&&!m&&!r&&n.jsx("span",{"aria-hidden":"true","data-gradient-sweep":"",className:"pointer-events-none absolute inset-0 bg-linear-to-r from-transparent via-sky-400/20 to-transparent animate-pulse"})]}),b&&!r&&n.jsxs("div",{"data-enso-float":"",role:"tooltip","aria-label":"Try Annotate",className:"absolute top-full right-0 z-50 mt-1.5 w-64 rounded-lg border bg-popover p-3 text-popover-foreground shadow-xl",children:[n.jsx("div",{className:"mb-2 flex h-24 items-center justify-center rounded-md border border-sky-500/20 bg-sky-500/5",children:n.jsxs("div",{className:"flex flex-col items-center gap-1 text-sky-500",children:[n.jsx(Ef,{className:"h-6 w-6"}),n.jsx("span",{className:"rounded bg-sky-500 px-1.5 py-0.5 text-[10px] font-semibold text-white",children:"Click · Drag · Draw · Edit CSS"})]})}),n.jsx("h2",{className:"text-xs font-semibold",children:"Try Annotate"}),n.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Point at anything on the page and tell the agent what to fix."})]})]}):n.jsxs("div",{className:"relative flex shrink-0 items-center","data-design-annotation-queue":"",children:[T>0?n.jsxs("div",{className:"flex h-6 items-center overflow-hidden rounded-md border border-[#3a96dd]/40 bg-[#3a96dd] text-white shadow-2xs",children:[n.jsxs("button",{type:"button",onClick:()=>c(s?void 0:new Set(g.map(N=>N.id))),title:u("Send annotations to chat"),className:"flex h-full items-center gap-1 px-2 text-xs font-medium transition-opacity hover:opacity-90",children:[n.jsx("span",{children:"Send"}),n.jsx("span",{className:"flex h-4 min-w-4 items-center justify-center rounded-full bg-white/20 px-1 text-[10px] font-semibold tabular-nums",children:T})]}),n.jsx("button",{type:"button","aria-label":`Open annotation queue (${T})`,"aria-expanded":o,onClick:()=>i(!o),className:"flex h-full items-center border-l border-white/20 px-1 transition-colors hover:bg-black/10",children:n.jsx(Fn,{className:"h-3 w-3"})})]}):n.jsxs("button",{type:"button",onClick:()=>a(!1),"aria-label":"Annotate","aria-pressed":s,title:`Exit Design Mode (${dh})`,className:"flex h-6 items-center gap-1 rounded bg-[#3a96dd]/15 px-2 text-xs font-medium text-[#3a96dd]",children:[n.jsx(Ef,{}),d!=="many"&&n.jsx("span",{children:"Annotate"})]}),o&&T>0&&n.jsxs("div",{"data-enso-float":"","data-design-owns-escape":"",className:"absolute top-full right-0 z-50 mt-1.5 w-72 overflow-hidden rounded-lg border bg-popover text-popover-foreground shadow-xl",children:[n.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-xs",children:[n.jsx("span",{className:"font-medium text-muted-foreground",children:T===1?"1 edit":`${T} edits`}),n.jsx("button",{type:"button",onClick:()=>{v(t,s?void 0:e),i(!1)},className:"text-[11px] text-muted-foreground transition-colors hover:text-destructive",children:"Clear All"})]}),n.jsx("div",{className:"max-h-64 divide-y overflow-y-auto",children:j.map(N=>{const S=N.kind==="region"&&N.images[0]?`data:${N.images[0].mimeType};base64,${N.images[0].data}`:null,I=N.kind==="element"&&N.elements.length>1?N.elements.length-1:0,k=N.comment.trim()||(N.kind==="element"&&N.elements[0]?nA(N.elements[0]):N.kind==="region"?`Screenshot region ${Math.round(N.region.rect.width)} × ${Math.round(N.region.rect.height)}`:"Annotation");return n.jsxs("div",{className:"group flex items-center gap-2 px-2.5 py-2 text-xs hover:bg-muted/60",children:[n.jsxs("button",{type:"button",onClick:()=>{i(!1),l(N)},className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-t-full rounded-br-full rounded-bl-xs bg-[#3a96dd] text-[11px] font-semibold text-white tabular-nums",children:N.number}),S&&n.jsx("img",{src:S,alt:"",className:"h-5 w-7 shrink-0 rounded border object-cover"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),I>0&&n.jsxs("span",{className:"shrink-0 rounded bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:["+",I]})]}),n.jsx("button",{type:"button","aria-label":"Delete annotation",onClick:()=>x(t,[N.id]),className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:bg-destructive/10 hover:text-destructive",children:n.jsx(vs,{className:"h-3 w-3"})})]},N.id)})})]})]})}function XW({stage:e,pinned:t,onTogglePinned:s,onClose:r,onStageChange:o}){const[i,a]=f.useState(""),l=f.useMemo(()=>bj(e),[e]),c=f.useMemo(()=>{const m={...e.baseline.values};for(const[h,p]of e.edits)p&&(m[h]=p);return m},[e.baseline.values,e.edits]),u=f.useMemo(()=>{const m=i.trim().toLowerCase();return wA.filter(h=>jA(h,{rendersText:e.baseline.rendersText,values:c})&&h.name.includes(m))},[i,e.baseline.rendersText,c]),d=m=>{const h=SA(e,m);o(h.staging,h.filed)};return n.jsxs("div",{className:"flex flex-col border-t bg-background/95",children:[n.jsxs("div",{className:"flex items-center gap-1.5 border-b px-2.5 py-1.5",children:[n.jsx("input",{type:"text",value:i,onChange:m=>a(m.target.value),placeholder:"Filter CSS properties...",className:"min-w-0 flex-1 rounded border bg-muted/40 px-2 py-0.5 text-[11px] outline-none focus:border-ring"}),l.canReset&&n.jsx("button",{type:"button","aria-label":"Reset all CSS edits",title:"Reset all CSS edits",onClick:()=>d({kind:"resetAll"}),className:"flex h-5 w-5 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Mr,{className:"h-3 w-3"})}),n.jsx("button",{type:"button","aria-label":"Pin CSS inspector","aria-pressed":t,title:t?"Unpin inspector":"Pin inspector to top right",onClick:s,className:_("flex h-5 w-5 items-center justify-center rounded transition-colors",t?"bg-[#3a96dd]/15 text-[#3a96dd]":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:n.jsx(Ss,{className:"h-3 w-3"})}),n.jsx("button",{type:"button","aria-label":"Close CSS inspector",onClick:r,className:"flex h-5 w-5 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Jt,{className:"h-3 w-3"})})]}),n.jsx("div",{className:"max-h-52 divide-y overflow-y-auto px-2 py-1 text-[11px]",children:u.map(m=>{const h=e.edits.get(m.name),p=h===null,g=l.isEdited(m.name),x=l.isAuthored(m.name),v=p?e.baseline.values[m.name]??"":h??e.baseline.values[m.name]??"",b=m.name.endsWith("color"),w=`css-presets-${m.name}`;return n.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[n.jsx("input",{type:"checkbox",checked:!p&&(g||x),"aria-label":`Toggle ${m.name}`,onChange:j=>{j.target.checked?d({kind:"enable",property:m.name}):d({kind:"disable",property:m.name})},className:"h-3 w-3 shrink-0 accent-[#3a96dd]"}),n.jsx("span",{className:_("w-28 shrink-0 truncate font-mono text-[10px]",p&&"line-through opacity-50",g?"font-semibold text-[#3a96dd]":x?"text-foreground":"text-muted-foreground"),title:m.name,children:m.name}),b&&n.jsx("input",{type:"color","aria-label":`${m.name} color picker`,value:/^#[0-9a-fA-F]{6}$/.test(v)?v:"#3a96dd",onChange:j=>d({kind:"edit",property:m.name,value:j.target.value}),className:"h-4 w-4 shrink-0 cursor-pointer rounded border bg-transparent p-0"}),n.jsx("input",{type:"text",list:m.presets?.length?w:void 0,value:v,disabled:p,onChange:j=>d({kind:"edit",property:m.name,value:j.target.value}),onKeyDown:j=>{if(j.key!=="ArrowUp"&&j.key!=="ArrowDown")return;const T=kA(v,j.key==="ArrowUp"?1:-1,j.shiftKey,m);T!==null&&(j.preventDefault(),j.stopPropagation(),d({kind:"edit",property:m.name,value:T}))},className:_("min-w-0 flex-1 rounded border bg-transparent px-1.5 py-0.5 font-mono text-[10px] outline-none focus:border-ring",p&&"opacity-40")}),m.presets&&m.presets.length>0&&n.jsxs("datalist",{id:w,children:[m.presets.map(j=>n.jsx("option",{value:j},j)),e.baseline.variables.lengths.map(j=>n.jsx("option",{value:`var(${j.name})`},j.name)),b&&e.baseline.variables.colors.map(j=>n.jsx("option",{value:`var(${j.name})`},j.name))]}),(g||p)&&n.jsx("button",{type:"button","aria-label":`Reset ${m.name}`,title:"Reset property",onClick:()=>d({kind:"reset",property:m.name}),className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Mr,{className:"h-2.5 w-2.5"})})]},m.name)})})]})}function QW({tabId:e,conversationId:t,stageSize:s,draftPick:r,openPin:o,markupTool:i,warningShown:a,onWarningShownChange:l,onDraftPickChange:c,onMoveSelection:u,onCancelDraft:d,onCloseOpenPin:m,onSendQueue:h,onStrokeStateChange:p,active:g}){const{t:x}=z(),v=_n(oe=>oe.annotateSendImmediately),b=_n(oe=>oe.setSendImmediately),w=_n(oe=>oe.addAnnotation),j=_n(oe=>oe.updateAnnotation),T=_n(oe=>oe.removeAnnotations),N=_n(oe=>oe.annotationsFor(t)),S=f.useMemo(()=>o?N.find(oe=>oe.id===o.id)??null:null,[N,o]),I=f.useMemo(()=>aA(S?.comment??""),[S?.comment]),[k,L]=f.useState(""),[F,A]=f.useState([]),[M,R]=f.useState(!1),[$,U]=f.useState(!1),[q,te]=f.useState(null),[V,se]=f.useState({x:0,y:0}),[Ce,de]=f.useState(!1),[re,Z]=f.useState(null),[me,xe]=f.useState("move"),[Se,W]=f.useState(null),H=f.useRef(null),B=f.useRef(null),ne=f.useRef(null),ve=f.useRef(null),he=f.useId(),G=o?`pin:${o.id}`:r?"draft":"none";f.useEffect(()=>{L(I.prose),A(S?S.images.slice(1):[]),R(!1),te(null),se({x:0,y:0}),l(!1),window.setTimeout(()=>ne.current?.focus(),10)},[G]),f.useEffect(()=>{const oe=lA(N.filter(Le=>Le.browserId===e));window.electronAPI.browser.previewDesignCss(e,"queue",oe)},[N,e]);const we=f.useMemo(()=>S?S.kind==="element"?S.elements:[]:r?.description.elements??[],[S,r]),ce=we.length===1?we[0]:null,Re=f.useCallback(async()=>{if(!ce)return;if(M){R(!1);return}const oe=await window.electronAPI.browser.readDesignCss(e,ce.uniqueId);if(!oe){Ie({type:"warning",title:x("Could not read CSS for this element")});return}te(cA(oe,I.css)),R(!0)},[ce,M,e,I.css,x]);f.useEffect(()=>{if(!g||!r?.region)return;const oe=Le=>{if(!(vi?Le.metaKey:Le.ctrlKey)||Le.altKey||Le.key.toLowerCase()!=="z")return;const at=document.activeElement===ne.current&&k.length>0;if(bA({markCount:r.markup.length+r.redoMarkup.length,toolHeld:i!==null,noteOwnsUndo:at}))if(Le.preventDefault(),Le.stopPropagation(),Le.shiftKey){const gt=r.redoMarkup.at(-1);if(!gt)return;c({...r,markup:[...r.markup,gt],redoMarkup:r.redoMarkup.slice(0,-1)})}else{const gt=r.markup.at(-1);if(!gt)return;c({...r,markup:r.markup.slice(0,-1),redoMarkup:[...r.redoMarkup,gt]})}};return window.addEventListener("keydown",oe,!0),()=>window.removeEventListener("keydown",oe,!0)},[g,r,i,k.length,c]),f.useEffect(()=>{if(!re||!r)return;const oe={left:0,top:0,width:s.width,height:s.height},Le=(gt,xt)=>{const zt=gt.key===" "?"Space":gt.key==="Shift"||gt.key==="Alt"||gt.key==="Escape"?gt.key:null;zt&&(zt==="Space"&>.preventDefault(),Z(Wt=>Wt?Rg(Wt,{type:"key",key:zt,down:xt},oe):null))},st=gt=>Le(gt,!0),at=gt=>Le(gt,!1);return window.addEventListener("keydown",st,!0),window.addEventListener("keyup",at,!0),()=>{window.removeEventListener("keydown",st,!0),window.removeEventListener("keyup",at,!0)}},[re,r,s.width,s.height]);const ue=f.useMemo(()=>q?bj(q):null,[q]),We=!!(ue&&ue.changes.size>0),it=k.trim().length>0,Fe=S!==null,tt=Fe?k.trim()!==I.prose.trim()||!!ue?.isDirty:it||We||(r?.markup.length??0)>0,ke=f.useMemo(()=>ue?Ig(k,ue.changes):I.css.size>0?Ig(k,I.css):k.trim(),[k,ue,I.css]),nt=Fe?!0:ke.length>0||r?.region!==null&&(r?.markup.length??0)>0,mt=yA({sendImmediately:v,isOnStack:Fe}),X=We&&!it?Tg[mt].css:Tg[mt].note,K=f.useCallback(()=>{const oe=we;if(oe.length===0)return;let Le=!1;oe.forEach((st,at)=>{const gt=`ui-${Date.now()}-${at}`,xt=am(st),zt=at===0&&r?.description.image?{data:r.description.image.data,mimeType:r.description.image.mimeType}:void 0;sx({kind:"ui-element",id:gt,label:xt,path:st.path||st.tagName.toLowerCase(),text:(st.innerText||"").replace(/\s+/g," ").trim().slice(0,200)||vj(st),imageId:`img-${gt}`},zt)&&(Le=!0)}),Le?(zi(),d()):Ie({type:"warning",title:x("No Composer for this selection")})},[we,r?.description.image,d,x]),Ee=f.useCallback(async()=>{if(!(Ce||!nt)){de(!0);try{if(Fe&&S){const xt=S.images.length>0?[S.images[0],...F]:[...F];j(t,S.id,ke,xt),window.electronAPI.browser.previewDesignCss(e,"draft",{}),m(),v&&h(new Set([S.id]));return}if(!r)return;const oe=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`ann-${Date.now()}`,Le=_n.getState().pageKeyOf(e)??"http://localhost/",st=r.description.image,at=[];if(st){const xt=r.region&&r.markup.length>0?await qW({base64:st.data,markup:r.markup,cropWidth:r.region.width}):st.data;at.push({id:`img-${oe}`,data:xt,mimeType:st.mimeType,name:st.name,width:st.width,height:st.height})}at.push(...F);let gt;if(r.region){const xt=r.description.regionAnchor??{tagName:"BODY",id:"",uniqueId:"region-root",className:"",innerText:"",path:"body",attributes:[],rect:{top:r.region.top,left:r.region.left,width:r.region.width,height:r.region.height},styles:{color:"",backgroundColor:"",fontSize:"",fontFamily:"",display:"block",position:"static"}};gt=w(t,{id:oe,kind:"region",comment:ke,browserId:e,pageKey:Le,images:at,region:{rect:r.region,anchor:xt,markup:r.markup}})}else gt=w(t,{id:oe,kind:"element",comment:ke,browserId:e,pageKey:Le,images:at,elements:r.description.elements});window.electronAPI.browser.previewDesignCss(e,"draft",{}),d(),v&>&&h(new Set([gt.id]))}finally{de(!1)}}},[Ce,nt,Fe,S,F,j,t,ke,e,m,v,h,r,w,d]),pt=f.useCallback(()=>{if(tt&&!a){l(!0);return}l(!1),window.electronAPI.browser.previewDesignCss(e,"draft",{}),Fe?m():d()},[tt,a,l,e,Fe,m,d]),Pt=oe=>{for(const Le of oe){if(!Le.type.startsWith("image/"))continue;const st=new FileReader;st.onload=()=>{const at=st.result,gt=at.slice(at.indexOf(",")+1);A(xt=>[...xt,{id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,data:gt,mimeType:Le.type,name:Le.name}])},st.readAsDataURL(Le)}},Je=re?re.rect:r?.region??null,Lt=Math.min(320,Math.max(240,s.width-16)),on=M?360:148,Pe=f.useMemo(()=>{if(o)return dA(o.badge,s,{width:Lt,height:on});if(Je)return Ag({x:Je.left,y:Je.top,width:Je.width,height:Je.height},s,Lt,on);if(r&&r.elements.length>0){const oe=r.elements.map(zt=>zt.rect.x),Le=r.elements.map(zt=>zt.rect.y),st=r.elements.map(zt=>zt.rect.x+zt.rect.width),at=r.elements.map(zt=>zt.rect.y+zt.rect.height),gt=Math.min(...oe),xt=Math.min(...Le);return Ag({x:gt,y:xt,width:Math.max(...st)-gt,height:Math.max(...at)-xt},s,Lt,on)}return{x:16,y:16}},[o,Je,r,s,Lt,on]),Dt=$?Math.max(8,s.width-Lt-8):Math.max(8,Math.min(Pe.x+V.x,s.width-Lt-8)),Vt=$?8:Math.max(8,Math.min(Pe.y+V.y,s.height-120));if(!r&&!o)return null;const Et=r?.description.frame?`data:${r.description.frame.mimeType};base64,${r.description.frame.data}`:null;return n.jsxs("div",{"data-enso-float":"",className:"absolute inset-0 z-30 select-none overflow-hidden",onMouseDown:oe=>{oe.target===oe.currentTarget&&pt()},children:[r&&Je&&n.jsxs(n.Fragment,{children:[Et&&n.jsx("img",{src:Et,alt:"",draggable:!1,className:"pointer-events-none absolute inset-0 h-full w-full object-fill"}),n.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0 bg-slate-950/35",style:{clipPath:`polygon(0% 0%, 0% 100%, ${Je.left}px 100%, ${Je.left}px ${Je.top}px, ${Je.left+Je.width}px ${Je.top}px, ${Je.left+Je.width}px ${Je.top+Je.height}px, ${Je.left}px ${Je.top+Je.height}px, ${Je.left}px 100%, 100% 100%, 100% 0%)`}}),n.jsxs("div",{role:"application","aria-label":"Selected screenshot region",style:{left:Je.left,top:Je.top,width:Je.width,height:Je.height,cursor:i!==null?"crosshair":gA(re?re.handle:me,re!==null)},onPointerMove:oe=>{const Le=oe.currentTarget.getBoundingClientRect(),st={x:oe.clientX-Le.left,y:oe.clientY-Le.top};if(i!==null){if(!Se||!H.current)return;const at={x:Math.max(0,Math.min(Je.width,st.x)),y:Math.max(0,Math.min(Je.height,st.y))};if(Se.kind==="pen")W({kind:"pen",points:pA(Se.points,at)});else{const gt=oe.shiftKey?xA({kind:Se.kind,from:H.current,to:at}):at;W({kind:Se.kind,from:H.current,to:gt})}return}if(re){const at=oe.currentTarget.parentElement?.getBoundingClientRect(),gt={x:oe.clientX-(at?.left??0),y:oe.clientY-(at?.top??0)};Z(xt=>xt?Rg(xt,{type:"move",point:gt,altKey:oe.altKey,shiftKey:oe.shiftKey},{left:0,top:0,width:s.width,height:s.height}):null);return}xe(Eg(st,Je))},onPointerDown:oe=>{if(oe.button!==0)return;oe.preventDefault(),oe.stopPropagation(),oe.currentTarget.setPointerCapture(oe.pointerId);const Le=oe.currentTarget.getBoundingClientRect(),st={x:Math.max(0,Math.min(Je.width,oe.clientX-Le.left)),y:Math.max(0,Math.min(Je.height,oe.clientY-Le.top))};if(i!==null){H.current=st,p(!0),W(i==="pen"?{kind:"pen",points:[st]}:{kind:i,from:st,to:st});return}const at=oe.currentTarget.parentElement?.getBoundingClientRect(),gt={x:oe.clientX-(at?.left??0),y:oe.clientY-(at?.top??0)},xt=Eg(st,Je);Z(hA({handle:xt,point:gt,rect:Je,modifiers:{altKey:oe.altKey,shiftKey:oe.shiftKey}}))},onPointerUp:async()=>{if(Se){const oe=uA(r.markup,Se);W(null),H.current=null,p(!1),oe.length!==r.markup.length&&c({...r,markup:oe,redoMarkup:[]});return}if(re){const oe=fA({rect:re.rect,viewport:s}),Le=mA({markup:r.markup,from:r.region??oe,to:oe,markupScale:1});Z(null);const st=await window.electronAPI.browser.describeSelection(e,{x:oe.left,y:oe.top,width:oe.width,height:oe.height});c({...r,region:oe,markup:Le,description:st.image?st:r.description})}},className:"absolute box-border border-2 border-[#3a96dd] border-dashed shadow-lg",children:[n.jsxs("svg",{role:"img","aria-label":"Draw on screenshot region",width:Je.width,height:Je.height,className:"pointer-events-none block h-full w-full overflow-visible",children:[r.markup.map((oe,Le)=>lm(oe,"complete").map((st,at)=>n.jsx("path",{d:st.d,"data-design-markup-stroke":"",fill:st.paint==="fill"?si:"none",stroke:st.paint==="stroke"?si:"none",strokeWidth:st.paint==="stroke"?cm:void 0,strokeLinecap:"round",strokeLinejoin:"round"},`${Le}-${at}`))),Se&&lm(Se,"active").map((oe,Le)=>n.jsx("path",{d:oe.d,"data-design-markup-stroke":"active",fill:oe.paint==="fill"?si:"none",stroke:oe.paint==="stroke"?si:"none",strokeWidth:oe.paint==="stroke"?cm:void 0,strokeLinecap:"round",strokeLinejoin:"round"},`active-${Le}`))]}),i===null&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"pointer-events-none absolute -top-1.5 -left-1.5 h-2.5 w-2.5 rounded-xs border border-[#3a96dd] bg-white shadow-2xs"}),n.jsx("span",{className:"pointer-events-none absolute -top-1.5 -right-1.5 h-2.5 w-2.5 rounded-xs border border-[#3a96dd] bg-white shadow-2xs"}),n.jsx("span",{className:"pointer-events-none absolute -bottom-1.5 -left-1.5 h-2.5 w-2.5 rounded-xs border border-[#3a96dd] bg-white shadow-2xs"}),n.jsx("span",{className:"pointer-events-none absolute -right-1.5 -bottom-1.5 h-2.5 w-2.5 rounded-xs border border-[#3a96dd] bg-white shadow-2xs"})]})]})]}),n.jsxs("div",{style:{left:Dt,top:Vt,width:Lt},onMouseDown:oe=>oe.stopPropagation(),className:"glass-browser-design-input absolute z-40 flex flex-col overflow-hidden rounded-2xl border border-border/80 bg-popover/95 text-popover-foreground shadow-[0_14px_38px_-8px_rgba(0,0,0,0.32),0_4px_14px_-2px_rgba(0,0,0,0.16)] backdrop-blur-xl transition-shadow duration-150 focus-within:border-[#3a96dd]/55 focus-within:ring-2 focus-within:ring-[#3a96dd]/15 dark:border-white/12",children:[n.jsxs("div",{onPointerDown:oe=>{oe.button!==0||$||oe.target instanceof Element&&oe.target.closest("button, input")||(oe.preventDefault(),oe.currentTarget.setPointerCapture(oe.pointerId),B.current={pointerId:oe.pointerId,startX:oe.clientX,startY:oe.clientY,nudgeX:V.x,nudgeY:V.y})},onPointerMove:oe=>{const Le=B.current;!Le||Le.pointerId!==oe.pointerId||se({x:Le.nudgeX+(oe.clientX-Le.startX),y:Le.nudgeY+(oe.clientY-Le.startY)})},onPointerUp:()=>{B.current=null},className:_("flex items-center justify-between gap-2 px-3 pt-2.5 pb-1",!$&&"cursor-grab active:cursor-grabbing"),children:[n.jsx("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:Je||S?.kind==="region"?n.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-[#3a96dd]/25 bg-[#3a96dd]/12 px-2 py-0.5 text-[11px] font-medium text-[#3a96dd]",children:[r?.description.image&&n.jsx("img",{src:`data:${r.description.image.mimeType};base64,${r.description.image.data}`,alt:"",className:"h-4 w-5 rounded-[3px] object-cover ring-1 ring-black/10 dark:ring-white/15"}),n.jsxs("span",{children:["Region"," ",Math.round(Je?.width??(S?.kind==="region"?S.region.rect.width:0))," ","×"," ",Math.round(Je?.height??(S?.kind==="region"?S.region.rect.height:0))]})]}):we.map((oe,Le)=>{const st=Lu[(oe.hueIndex??Le)%Lu.length]??Lu[0],at=_u[(oe.hueIndex??Le)%_u.length]??_u[0];return n.jsxs("span",{style:{backgroundColor:st.bg,borderColor:at.stroke,color:st.border},title:`${vA(oe)} — ${oe.path}`,className:"inline-flex max-w-48 items-center gap-1.5 truncate rounded-md border px-2 py-0.5 font-mono text-[11px] font-medium shadow-2xs",children:[n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{backgroundColor:st.border}}),n.jsx("span",{className:"truncate",children:am(oe)})]},oe.uniqueId||`${oe.tagName}-${Le}`)})}),n.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 rounded-lg bg-muted/50 p-0.5",children:[!Fe&&!Je&&we.length===1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:()=>u("parent"),title:"Select parent element (Shift+Enter or \\)","aria-label":"Select parent element",className:"flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-background/80 hover:text-foreground",children:n.jsx(L_,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:()=>u("previous"),title:"Select previous sibling (Shift+Tab)","aria-label":"Select previous sibling",className:"flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-background/80 hover:text-foreground",children:n.jsx(Ei,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",onClick:()=>u("next"),title:"Select next sibling (Tab)","aria-label":"Select next sibling",className:"flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-background/80 hover:text-foreground",children:n.jsx(yj,{className:"h-3 w-3"})})]}),we.length>0&&n.jsx("button",{type:"button",onClick:K,title:`Add element to chat (${vi?"⌘L":"Ctrl+L"})`,"aria-label":"Add element to chat",className:"flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-background/80 hover:text-foreground",children:n.jsx(no,{className:"h-3 w-3"})}),ce&&n.jsx("button",{type:"button",onClick:()=>{Re()},"aria-label":"Edit CSS properties","aria-pressed":M,title:"Edit CSS properties",className:_("flex h-5 w-5 items-center justify-center rounded-md transition-colors",M||We?"bg-[#3a96dd]/15 text-[#3a96dd]":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:n.jsx(HB,{className:"h-3 w-3"})}),Fe&&S&&n.jsx("button",{type:"button","aria-label":"Delete annotation",title:"Delete annotation",onClick:()=>{T(t,[S.id]),m()},className:"flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/15 hover:text-destructive",children:n.jsx(vs,{className:"h-3 w-3"})})]})]}),F.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-1.5",children:F.map(oe=>n.jsxs("div",{className:"group relative h-11 w-15 overflow-hidden rounded-lg border border-border/70 shadow-2xs",children:[n.jsx("img",{src:`data:${oe.mimeType};base64,${oe.data}`,alt:"",className:"h-full w-full object-cover"}),n.jsx("button",{type:"button","aria-label":"Remove attached image",onClick:()=>A(Le=>Le.filter(st=>st.id!==oe.id)),className:"absolute top-0.5 right-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-black/70 text-white opacity-0 transition-opacity group-hover:opacity-100",children:n.jsx(Jt,{className:"h-2.5 w-2.5"})})]},oe.id))}),n.jsxs("div",{className:"px-3 py-1.5",children:[n.jsx("textarea",{ref:ne,rows:2,value:k,onChange:oe=>{L(oe.target.value),a&&l(!1);const Le=oe.currentTarget;Le.style.height="auto",Le.style.height=`${Math.min(144,Math.max(44,Le.scrollHeight))}px`},onPaste:oe=>{const Le=Array.from(oe.clipboardData.files);Le.length>0&&(oe.preventDefault(),Pt(Le))},onKeyDown:oe=>{if(oe.nativeEvent.isComposing)return;const Le=vi?oe.metaKey:oe.ctrlKey;if(Le&&oe.key.toLowerCase()==="l"){oe.preventDefault(),oe.stopPropagation(),K();return}if(oe.key==="Enter"&&!oe.shiftKey){if(nt||Le){oe.preventDefault(),oe.stopPropagation(),Ee();return}if(!Fe&&!Je&&we.length>0){oe.preventDefault(),oe.stopPropagation(),u("child");return}}if(!nt&&!Fe&&!Je&&we.length>0){if(oe.key==="Enter"&&oe.shiftKey||oe.key==="\\"){oe.preventDefault(),oe.stopPropagation(),u("parent");return}if(oe.key==="Tab"){oe.preventDefault(),oe.stopPropagation(),u(oe.shiftKey?"previous":"next");return}}Fe&&S&&!it&&!We&&(oe.key==="Backspace"||oe.key==="Delete")&&!oe.altKey&&!oe.ctrlKey&&!oe.metaKey&&!oe.repeat&&(oe.preventDefault(),oe.stopPropagation(),T(t,[S.id]),m())},placeholder:We?"Add a note (optional)…":"Describe the change…",className:"min-h-[44px] w-full resize-none bg-transparent text-[13px] leading-5 outline-none placeholder:text-muted-foreground/60"}),We&&!M&&ue&&n.jsx("section",{"aria-label":"CSS edits",className:"mt-1.5 flex flex-wrap gap-1 text-[10px] text-[#3a96dd]",children:[...ue.changes].map(([oe,Le])=>n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-[#3a96dd]/20 bg-[#3a96dd]/10 px-1.5 py-0.5 font-mono",children:[n.jsxs("span",{className:"font-medium",children:[oe,":"]}),Le.to===null?n.jsx("span",{children:"removed"}):n.jsxs(n.Fragment,{children:[n.jsx("del",{className:"opacity-65",children:Le.from}),n.jsx("span",{className:"opacity-60",children:"→"}),n.jsx("ins",{className:"font-semibold no-underline",children:Le.to})]})]},oe))})]}),M&&q&&ce&&n.jsx(XW,{stage:q,pinned:$,onTogglePinned:()=>U(oe=>!oe),onClose:()=>R(!1),onStageChange:(oe,Le)=>{te(oe),window.electronAPI.browser.previewDesignCss(e,"draft",{[ce.uniqueId]:Le})}}),a&&n.jsxs("div",{"data-design-input-notice":"",className:"flex items-center justify-between gap-2 border-t bg-amber-500/10 px-2.5 py-1.5 text-[11px]",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("span",{className:"font-semibold text-amber-600 dark:text-amber-400",children:"Discard comment?"})," ",n.jsx("span",{className:"text-muted-foreground",children:"This comment isn't saved yet."})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsx("button",{type:"button",onClick:()=>l(!1),className:"rounded border bg-background px-2 py-0.5 text-[10px] font-medium hover:bg-muted",children:"Keep Editing"}),n.jsx("button",{type:"button",onClick:()=>{l(!1),window.electronAPI.browser.previewDesignCss(e,"draft",{}),Fe?m():d()},className:"rounded bg-destructive px-2 py-0.5 text-[10px] font-medium text-white hover:opacity-90",children:"Discard"})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-border/50 bg-muted/20 px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("input",{ref:ve,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:oe=>{Pt(Array.from(oe.target.files??[])),oe.target.value=""}}),n.jsx("button",{type:"button",onClick:()=>ve.current?.click(),"aria-label":"Attach image to annotation",title:"Attach image",className:"flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Wh,{className:"h-3.5 w-3.5"})}),n.jsxs("label",{htmlFor:he,className:"group flex cursor-pointer items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[n.jsx("input",{id:he,type:"checkbox",checked:!v,onChange:oe=>b(!oe.target.checked),className:"sr-only"}),n.jsx("span",{"aria-hidden":"true",className:_("relative inline-flex h-3.5 w-6 shrink-0 items-center rounded-full transition-colors duration-150",v?"bg-muted-foreground/30":"bg-[#3a96dd]"),children:n.jsx("span",{className:_("inline-block h-2.5 w-2.5 rounded-full bg-white shadow-2xs transition-transform duration-150",v?"translate-x-0.5":"translate-x-3")})}),n.jsx("span",{children:"Batch edits"})]})]}),n.jsxs("button",{type:"button",disabled:Ce||!nt,"aria-label":X,title:`${X} (Enter)`,onClick:()=>{Ee()},className:"flex h-7 items-center gap-1.5 rounded-lg bg-[#3a96dd] px-3 text-[11px] font-medium text-white shadow-xs transition-all hover:bg-[#3286c9] active:scale-[0.98] disabled:bg-muted disabled:text-muted-foreground disabled:opacity-50",children:[mt==="add-to-stack"?n.jsx(Qn,{className:"h-3 w-3"}):mt==="save-note"?n.jsx(On,{className:"h-3 w-3"}):n.jsx(Wd,{className:"h-3 w-3"}),n.jsx("span",{children:X})]})]})]})]})}function JW({tabId:e,conversationId:t,url:s,designMode:r,onDesignModeState:o,active:i}){const{t:a}=z(),[l,c]=f.useState(!1),[u,d]=f.useState(null),[m,h]=f.useState(null),[p,g]=f.useState(null),[x,v]=f.useState(!1),[b,w]=f.useState(!1),[j,T]=f.useState(!1),N=_n(U=>U.annotationsFor(t,e)),S=_n(U=>U.annotationsFor(t)),I=f.useRef(s);f.useEffect(()=>{s&&_n.getState().setBrowserUrl(e,s),I.current!==s&&(I.current=s,d(null),h(null),w(!1),c(!1),v(!1))},[e,s]);const k=f.useCallback(async U=>{U?_n.getState().markEntered():(d(null),h(null),g(null),w(!1),c(!1));const q=await window.electronAPI.browser.setDesignMode(e,U);o(q)},[e,o]);f.useEffect(()=>{if(!r||!s)return;const U=gj(s),q=N.filter(te=>te.pageKey===U).map(eA);window.electronAPI.browser.setAnnotationPins(e,U,q)},[r,s,N,e]);const L=f.useCallback(U=>{if(g(U),U!==null&&u&&u.region===null&&u.elements.length>0){const q=u.elements.map(me=>me.rect.x),te=u.elements.map(me=>me.rect.y),V=u.elements.map(me=>me.rect.x+me.rect.width),se=u.elements.map(me=>me.rect.y+me.rect.height),Ce=Math.max(0,Math.min(...q)-12),de=Math.max(0,Math.min(...te)-12),re=Math.max(24,Math.max(...V)-Ce+12),Z=Math.max(24,Math.max(...se)-de+12);d({...u,region:{left:Ce,top:de,width:re,height:Z}})}},[u]);f.useEffect(()=>window.electronAPI.browser.onDesignMode(U=>{if(U.tabId===e){if(U.type==="cancelled"){d(null),h(null),g(null),c(!1);return}if(U.type==="drawing"){c(U.drawing);return}if(U.type==="pins"){_n.getState().setPinnedIds(e,U.ids);return}if(U.type==="pin-click"){d(null),w(!1),U.pin&&h({id:U.id,badge:U.pin});return}if(U.type==="select"){if(c(!1),h(null),w(!1),U.addToChat&&U.description.elements.length>0){U.description.elements.forEach((q,te)=>{const V=`ui-${Date.now()}-${te}`,se=am(q),Ce=te===0&&U.description.image?{data:U.description.image.data,mimeType:U.description.image.mimeType}:void 0;sx({kind:"ui-element",id:V,label:se,path:q.path||q.tagName.toLowerCase(),text:(q.innerText||"").replace(/\s+/g," ").trim().slice(0,200)||vj(q),imageId:`img-${V}`},Ce)}),zi(),window.electronAPI.browser.clearSelection(e);return}d({elements:U.elements,region:U.region?{left:U.region.x,top:U.region.y,width:U.region.width,height:U.region.height}:null,viewportWidth:U.viewportWidth,description:U.description,markup:[],redoMarkup:[]})}}}),[e]);const F=f.useCallback(()=>{d(null),g(null),w(!1),window.electronAPI.browser.clearSelection(e)},[e]),A=f.useCallback(()=>{h(null),w(!1),window.electronAPI.browser.openAnnotationPin(e,null,!1)},[e]),M=f.useCallback(async U=>{const q=await window.electronAPI.browser.moveSelection(e,U);q.elements.length!==0&&d(te=>te?{...te,elements:q.elements,description:q.description}:null)},[e]),R=f.useCallback(async U=>{if(U.browserId!==e){Ie({type:"info",title:a("Turn on design mode in this note's browser tab to open it")});return}r||await k(!0);const q=await window.electronAPI.browser.openAnnotationPin(e,U.id,!0);q&&(d(null),h({id:U.id,badge:q}))},[e,r,k,a]),$=f.useCallback(U=>{const q=_n.getState(),te=q.annotationsFor(t),V=U?te.filter(re=>U.has(re.id)):[...te];if(V.length===0)return;const se=tA(V,re=>re.pageKey),Ce=se.ordered.map(re=>re.id);if(q.removeAnnotations(t,Ce),!v8({text:se.text,images:se.images,mentions:[]})){q.restoreAnnotations(t,se.ordered),Ie({type:"warning",title:a("Note not sent"),description:a("The note stays in the queue.")});return}q.annotationsFor(t).length===0&&r&&k(!1)},[t,r,k,a]);return f.useEffect(()=>{if(!i)return;const U=q=>{if((vi?q.metaKey:q.ctrlKey)&&q.shiftKey&&!q.altKey&&q.key.toLowerCase()==="d"){q.preventDefault(),q.stopPropagation(),k(!r);return}if(!r||q.key!=="Escape")return;const V=q.target instanceof Element?q.target:null,se=V?.closest('[role="menu"], [role="listbox"], [role="dialog"], [role="alertdialog"], [aria-expanded="true"], [data-design-owns-escape]')!==null&&V?.closest("[data-design-owns-escape]")!==null,Ce=V?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])')!==null;if(j){q.preventDefault(),q.stopPropagation(),T(!1);return}switch(NA({queueOwnsEscape:j,targetOwnsEscape:se,targetIsInput:Ce,markupStrokeActive:x,markupToolHeld:p!==null,warningShown:b,draftOpen:u!==null,editorOpen:m!==null})){case"pass-through":return;case"cancel-stroke":q.preventDefault(),q.stopPropagation(),v(!1);return;case"put-down-tool":q.preventDefault(),q.stopPropagation(),g(null);return;case"dismiss-warning":q.preventDefault(),q.stopPropagation(),w(!1);return;case"cancel-draft":q.preventDefault(),q.stopPropagation(),F();return;case"close-editor":q.preventDefault(),q.stopPropagation(),A();return;case"exit":q.preventDefault(),q.stopPropagation(),k(!1);return}};return window.addEventListener("keydown",U,!0),()=>window.removeEventListener("keydown",U,!0)},[i,r,j,x,p,b,u,m,k,F,A]),{drawing:l,draftPick:u,openPin:m,markupTool:p,warningShown:b,queueOpen:j,allConversationAnnotations:S,setQueueOpen:T,setWarningShown:w,setDraftPick:d,setDesignMode:k,handleMarkupToolChange:L,moveSelection:M,cancelDraft:F,closeOpenPin:A,openPinFromQueue:R,sendQueue:$,setMarkupStrokeActive:v}}const ZW=(e,t)=>e.width>0&&e.height>0&&t.width>0&&t.height>0&&e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,ey=(e,t)=>t.some(s=>ZW(e,s)),eU=new Set(["dialog-popup","dialog-viewport","dialog-backdrop","alert-dialog-popup","alert-dialog-viewport","alert-dialog-backdrop"]);function tU(e){if(e.getAttribute("data-enso-float")!==null)return!0;const t=e.getAttribute("data-slot");return t?eU.has(t)||t.endsWith("-popup")||t.endsWith("-positioner"):!1}function ty(e,t){const s=[];for(const r of Array.from(e.querySelectorAll("*"))){if(!tU(r))continue;const o=r.getBoundingClientRect();o.width>0&&o.height>0&&s.push({x:o.left,y:o.top,width:o.width,height:o.height})}return s}const OC=f.createContext({visible:!0,active:!0});function vee({dockConversationId:e,api:t,children:s}){const r=J(d=>d.activeId===e),o=qh(e),i=f.useCallback(d=>{const m=t.onDidActiveChange(d),h=t.onDidVisibilityChange(d);return()=>{m.dispose(),h.dispose()}},[t]),a=f.useSyncExternalStore(i,()=>t.isActive),l=f.useSyncExternalStore(i,()=>t.isVisible),c=r&&o&&l,u=f.useMemo(()=>({visible:c,active:c&&a}),[c,a]);return n.jsx(OC.Provider,{value:u,children:s})}function nU(){return f.useContext(OC)}const Ad=new Map,uh=new Set;function ny(){for(const e of uh)e()}function sU(e){return uh.add(e),()=>{uh.delete(e)}}function rU(e){const t=Ad.get(e);if(!t?.visible)return!1;let s=0,r;for(const[o,i]of Ad)i.kind!==t.kind||!i.visible||(s+=1,i.active&&(r=o));return s<=1||r===e}function oU(e,t=!0){const{visible:s,active:r}=nU(),o=f.useRef(null);o.current===null&&(o.current=Symbol(e));const i=o.current;f.useEffect(()=>{if(t)return Ad.set(i,{kind:e,visible:s,active:r}),ny(),()=>{Ad.delete(i),ny()}},[r,t,i,e,s]);const a=f.useSyncExternalStore(sU,()=>rU(i));return t&&a}const iU={tabId:null,url:"",title:"",favicon:null,loading:!1,canGoBack:!1,canGoForward:!1,locked:!1,devtoolsOpen:!1,designMode:!1,holder:null},Rf=(e,t)=>e===t||e!==null&&t!==null&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height&&e.radius===t.radius,sy=80,aU=.42;function ry(e){if(!e?.isConnected)return null;const t=e.getBoundingClientRect();if(t.width<1||t.height<1)return null;const s={x:Math.round(t.left),y:Math.round(t.top),width:Math.round(t.width),height:Math.round(t.height)},r=lU(e,t.bottom);return r>0?{...s,radius:r}:s}function lU(e,t){const s=e.closest('[data-slot="side-panel"]');if(!s||Math.abs(s.getBoundingClientRect().bottom-t)>1)return 0;const r=getComputedStyle(s);return Number.parseFloat(r.borderBottomLeftRadius)||Number.parseFloat(r.borderBottomRightRadius)||0}function cU(){const{t:e}=z();return n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-muted-foreground text-sm",children:[n.jsx(Oo,{className:"h-6 w-6"}),n.jsx("p",{children:e("The built-in browser is not available in full view. Check it on the computer.")})]})}function dU(e){return window.electronAPI.remote?n.jsx(cU,{}):n.jsx(uU,{...e})}function uU({conversationId:e,panelApi:t,active:s}){const{t:r}=z(),o=J(Z=>CA(Z.conversations,e)),i=qh(o),a=J(Z=>Z.activeId===o),l=s??(i&&a),c=oU("browser",s===void 0),u=s??c,[d,m]=f.useState(iU),[h,p]=f.useState(""),[g,x]=f.useState(!1),[v,b]=f.useState(null),[w,j]=f.useState(aU),[T,N]=f.useState({width:800,height:600}),S=f.useRef(null),I=f.useRef(null),k=f.useRef(null),L=f.useRef(void 0),F=f.useRef(!1),A=f.useRef(void 0),M=f.useRef(!1),R=f.useRef(!1);R.current=d.locked;const $=f.useRef(!1);$.current=d.devtoolsOpen;const U=(d.url.startsWith("http")||d.url.startsWith("file:"))&&!d.loading,q=f.useRef(!1);q.current=U;const te=f.useRef(null),V=t.id,se=JW({tabId:V,conversationId:e,url:d.url,designMode:d.designMode,onDesignModeState:m,active:u});f.useEffect(()=>{const Z=S.current;if(!Z)return;const me=()=>{const Se=Z.getBoundingClientRect();Se.width>0&&Se.height>0&&N({width:Math.round(Se.width),height:Math.round(Se.height)})};me();const xe=new ResizeObserver(me);return xe.observe(Z),()=>xe.disconnect()},[]),f.useEffect(()=>window.electronAPI.browser.onState(Z=>{Z.tabId===V&&m(Z.state)}),[V]),f.useEffect(()=>window.electronAPI.browser.onDesignMode(Z=>{if(Z.tabId!==V||Z.type==="cancelled"||Z.type==="select"||Z.type==="drawing"||Z.type==="pin-click"||Z.type==="pins")return;let me=!1;if(Z.type==="annotated")me=Z.image?w8(Z.image):!1;else{const xe=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`ui-${Date.now()}`;me=sx({kind:"ui-element",id:xe,label:Z.payload.label||Z.payload.tag||"element",path:Z.payload.path||Z.payload.tag||"element",text:Z.payload.text||Z.payload.label||Z.payload.tag||"element",imageId:`img-${xe}`},Z.image)}me?zi():Ie({type:"warning",title:r("No Composer for this selection")})}),[V,r]),f.useEffect(()=>{g||p(d.url)},[d.url,g]),f.useEffect(()=>{const Z=d.title.trim()||r("Browser");t.setTitle(Z),t.updateParameters({...t.getParameters(),favicon:d.favicon})},[t,d.title,d.favicon,r]),f.useEffect(()=>{let Z=0,me=!1;document.getElementById("root"),wj();const xe=()=>{if(me)return;const Se=l&&t.isActive&&t.isVisible&&document.visibilityState==="visible",W=Se?ry(S.current):null,H=W!==null&&(R.current||ey(W,ty(document)));(L.current===void 0||!Rf(L.current,W)||H!==F.current)&&(L.current=W,F.current=H,window.electronAPI.browser.setViewport(V,e,W,H).then(m));const B=q.current?W:null;Rf(te.current,B)||(te.current=B,os.getState().setBrowserHole(`${V}:guest`,B));const ne=Se&&$.current?ry(I.current):null,ve=ne!==null&&ey(ne,ty(document));(A.current===void 0||!Rf(A.current,ne)||ve!==M.current)&&(os.getState().setBrowserHole(`${V}:devtools`,ne),A.current=ne,M.current=ve,window.electronAPI.browser.setDevToolsViewport(V,e,ne,ve).then(m)),Z=requestAnimationFrame(xe)};return Z=requestAnimationFrame(xe),()=>{me=!0,cancelAnimationFrame(Z);const{setBrowserHole:Se}=os.getState();Se(`${V}:guest`,null),Se(`${V}:devtools`,null),te.current=null,L.current!==null&&(L.current=null,window.electronAPI.browser.setViewport(V,e,null)),A.current!==null&&(A.current=null,window.electronAPI.browser.setDevToolsViewport(V,e,null))}},[e,V,t,l]);const Ce=async()=>{x(!1);const Z=h.trim();if(!Z)return;const me=await window.electronAPI.browser.navigate(V,e,Z);b(me.ok?null:me.error??r("Navigation failed"))},de=Z=>{const me=S.current,xe=I.current;if(!me||!xe)return;Z.currentTarget.setPointerCapture(Z.pointerId);const Se=Z.clientY,W=me.getBoundingClientRect().height,H=xe.getBoundingClientRect().height,B=W+H,ne=he=>{const G=Math.min(B-sy,Math.max(sy,H-(he.clientY-Se)));j(G/B)},ve=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",ve)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",ve)},re="flex h-6 w-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 disabled:hover:bg-transparent";return n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsxs("div",{className:"flex h-[36px] shrink-0 items-center gap-1 border-b bg-background px-2",children:[n.jsx("button",{type:"button",className:re,disabled:d.locked||!d.canGoBack,onClick:()=>{window.electronAPI.browser.goBack(V)},"aria-label":r("Back"),children:n.jsx(Ei,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",className:re,disabled:d.locked||!d.canGoForward,onClick:()=>{window.electronAPI.browser.goForward(V)},"aria-label":r("Forward"),children:n.jsx(yj,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",className:re,disabled:d.locked||!d.tabId,onClick:()=>{window.electronAPI.browser.reload(V)},"aria-label":r("Reload"),children:n.jsx(Kw,{className:_("h-3.5 w-3.5",d.loading&&"animate-spin")})}),n.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-md border bg-background px-2 py-0.5 text-xs focus-within:border-ring",onSubmit:Z=>{Z.preventDefault(),Ce()},children:[n.jsx(Oo,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:Z=>p(Z.target.value),onFocus:Z=>{x(!0),Z.target.select()},onBlur:()=>x(!1),placeholder:r("Enter a URL"),spellCheck:!1,disabled:d.locked,className:"min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:opacity-60"})]}),n.jsx(YW,{tabId:V,conversationId:e,active:d.designMode,disabled:!d.tabId||d.locked||d.devtoolsOpen,queueOpen:se.queueOpen,onQueueOpenChange:se.setQueueOpen,onToggleDesignMode:Z=>{se.setDesignMode(Z)},onOpenPinFromQueue:Z=>{se.openPinFromQueue(Z)},onSendQueue:se.sendQueue}),n.jsx("button",{type:"button",className:_(re,d.devtoolsOpen&&"bg-muted text-foreground"),disabled:!d.tabId,onClick:()=>{window.electronAPI.browser.setDevTools(V,!d.devtoolsOpen).then(m)},"aria-label":r("Toggle Developer Tools"),"aria-pressed":d.devtoolsOpen,children:n.jsx(SN,{className:"h-3.5 w-3.5"})}),d.locked&&n.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded bg-amber-500/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-400",children:[n.jsx(Sv,{className:"h-3 w-3"}),r("Enso is in control")]})]}),d.designMode&&n.jsx(KW,{drawing:se.drawing,pick:se.draftPick,markupTool:se.markupTool,editorOpen:se.openPin!==null,onMarkupToolChange:se.handleMarkupToolChange,onExit:()=>{se.setDesignMode(!1)}}),v&&n.jsx("div",{className:"border-b bg-destructive/10 px-3 py-1 text-xs text-destructive",children:v}),n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col","data-slot":"browser-native-stack",children:[n.jsxs("div",{ref:S,className:_("relative min-h-0",d.devtoolsOpen?"shrink-0":"flex-1",U?"bg-transparent":"bg-background"),style:d.devtoolsOpen?{flex:`${1-w} 1 0`}:void 0,children:[n.jsx(GW,{active:d.designMode}),d.designMode&&n.jsx(QW,{tabId:V,conversationId:e,stageSize:T,draftPick:se.draftPick,openPin:se.openPin,markupTool:se.markupTool,warningShown:se.warningShown,onWarningShownChange:se.setWarningShown,onDraftPickChange:se.setDraftPick,onMoveSelection:Z=>{se.moveSelection(Z)},onCancelDraft:se.cancelDraft,onCloseOpenPin:se.closeOpenPin,onSendQueue:se.sendQueue,onStrokeStateChange:se.setMarkupStrokeActive,active:u}),!d.url.startsWith("http")&&!d.url.startsWith("file:")&&n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-center text-sm text-muted-foreground",children:[n.jsx(Oo,{className:"h-6 w-6 opacity-40"}),n.jsx("p",{children:r("Enter a URL above, or let the agent open a page with browser_navigate.")})]}),d.locked&&n.jsxs("div",{className:"group absolute inset-0 z-10 flex cursor-default items-center justify-center",children:[n.jsx("div",{className:"absolute inset-0 bg-black/0 transition-colors group-hover:bg-black/40"}),n.jsxs("button",{type:"button",className:"relative flex items-center gap-1.5 rounded-full border bg-background px-4 py-2 text-sm shadow-lg opacity-0 transition-opacity group-hover:opacity-100 hover:bg-muted",onClick:()=>{window.electronAPI.browser.setLocked(e,!1)},children:[n.jsx(Sv,{className:"h-3.5 w-3.5"}),r("Take control")]})]})]}),d.devtoolsOpen&&n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:k,className:"h-1.5 shrink-0 cursor-row-resize bg-border hover:bg-ring",onPointerDown:de}),n.jsx("div",{ref:I,className:"min-h-0 bg-transparent",style:{flex:`${w} 1 0`}})]})]})]})}function fU({chatId:e,visible:t}){const{t:s}=z(),r=ie(h=>h.browserTabs[e]),o=ie(h=>h.browserTitles),i=ie(h=>h.browserHolders),{openBrowserTab:a,selectBrowserTab:l,closeBrowserTab:c,setBrowserTitle:u}=ie.getState(),d=r?.active;f.useEffect(()=>{d||a(e)},[d,e,a]);const m=f.useMemo(()=>d?{id:d,isActive:!0,isVisible:!0,setTitle:h=>u(d,h),getParameters:()=>{},updateParameters:()=>{}}:null,[d,u]);return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-0.5 overflow-x-auto border-b px-1.5",children:[r?.tabs.map(h=>{const p=i[h],g=o[h]||s("Browser");return n.jsxs("div",{className:_("flex h-6 min-w-0 max-w-44 shrink items-center rounded-md text-xs",h===d?"bg-brand/10 text-foreground dark:bg-brand/15":"text-muted-foreground hover:bg-muted/60 hover:text-foreground"),children:[n.jsxs("button",{type:"button",title:p?`${g}
|
|
80
|
-
${s("{{name}} is using this tab",{name:p.name})}`:g,onClick:()=>l(e,h),className:"flex h-full min-w-0 items-center gap-1.5 pl-2",children:[n.jsx(Oo,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:g}),p&&n.jsxs("span",{className:"max-w-16 shrink-0 truncate text-muted-foreground",children:["· ",p.name]})]}),n.jsx("button",{type:"button","aria-label":s("Close"),title:s("Close"),onClick:()=>{c(e,h)},className:"mx-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded opacity-60 hover:bg-foreground/10 hover:opacity-100",children:n.jsx(Jt,{className:"h-3 w-3"})})]},h)}),n.jsx("button",{type:"button","aria-label":s("New tab"),title:s("New tab"),onClick:()=>a(e),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground",children:n.jsx(Qn,{className:"h-3.5 w-3.5"})})]}),m&&n.jsx(dU,{conversationId:IA(e),panelApi:m,active:t},m.id)]})}const mU=/[A-Za-z0-9._%+-]/,oy=/[A-Za-z0-9_-]/,hU=/```[\s\S]*?(?:```|$)|`[^`\n]*`/g;function LC(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.id=="string"&&typeof t.name=="string"&&t.name.length>0):[]}function pU(e,t){if(typeof e!="string")return{ids:[],all:!1};const s=e.normalize("NFC").replace(hU,a=>" ".repeat(a.length)),r=[...t.map(a=>({key:Gc(a.name),id:a.id})),...jj.map(a=>({key:Gc(a),id:null}))].sort((a,l)=>l.key.length-a.key.length),o=[];let i=!1;for(let a=s.indexOf("@");a!==-1;a=s.indexOf("@",a+1)){if(a>0&&mU.test(s[a-1]))continue;const l=r.find(({key:c})=>{const u=a+1+c.length;if(s.slice(a+1,u).toLowerCase()!==c)return!1;const d=s[u];return!(d&&oy.test(c.at(-1)??"")&&oy.test(d))});l&&(l.id===null?i=!0:o.includes(l.id)||o.push(l.id))}return{ids:o,all:i}}function xU(e,t){const s=LC(t),{ids:r,all:o}=pU(e,s);return o?{ids:[...new Set(s.map(i=>i.id))],all:o}:{ids:r,all:o}}function gU(e,t){const s=Gc(typeof e=="string"?e.replace(/^@/,""):"");return LC(t).filter(r=>Gc(r.name).startsWith(s))}function fh(e,t){return/(?:^|\s)\$([^\s$]*)$/.exec(e.slice(0,t))?.[1]??null}function _C(e){const t=new Set,s=[];for(const r of e){const o=r.name.trim().toLowerCase();!o||t.has(o)||(t.add(o),s.push(r))}return s}function vU(e,t,s){const r=s??t;if(r===null)return[];const o=r.toLowerCase();return _C(e.filter(i=>s!==null?i.name.startsWith("/skill:")&&i.name.slice(7).toLowerCase().includes(o):i.name.toLowerCase().includes(o))).slice(0,10)}const BC=["agents","members","chats"];function bU(e){return[...BC.flatMap(t=>e[t].map(s=>({candidate:s,group:t}))),...e.files.map(t=>({candidate:t,group:"files"}))]}function FC(e,t){const s=BC.filter(r=>e[r].length>0);return!t.trim()&&s.length>0?[...s.map(r=>({type:"folder",id:r})),...e.files.map(r=>({type:"item",candidate:r,group:"files"}))]:bU(e).map(r=>({type:"item",candidate:r.candidate,group:r.group}))}const yU=20;function wU(e,t,s){return e.filter(r=>r.id!==s&&!r.parentId&&!!r.sessionFile).sort((r,o)=>{const i=r.projectId===t?0:1,a=o.projectId===t?0:1;return i!==a?i-a:o.createdAt-r.createdAt}).slice(0,yU).map(r=>({kind:"chat",id:r.id,label:r.title.split(`
|
|
81
|
-
`)[0].trim()||"Untitled chat",sessionFile:r.sessionFile}))}function jU(e){return e.map(t=>({...t,kind:"agent-type",id:t.typeKey,label:t.displayName}))}function kU(e){const t=new Set,s=[];for(const r of e)!r.relativePath||t.has(r.relativePath)||(t.add(r.relativePath),s.push({kind:"file",id:r.relativePath,label:r.name||r.relativePath.split("/").at(-1)||r.relativePath,relativePath:r.relativePath}));return s}function NU(e,t,s,r=[]){const o=e.trim().toLocaleLowerCase(),i=o?t.filter(c=>`${c.label}
|
|
82
|
-
${c.description}
|
|
83
|
-
${c.source}
|
|
84
|
-
${c.typeKey}`.toLocaleLowerCase().includes(o)):[...t],a=o?s.filter(c=>`${c.label}
|
|
85
|
-
${c.relativePath}`.toLocaleLowerCase().includes(o)):[...s],l=o?r.filter(c=>c.label.toLocaleLowerCase().includes(o)):[...r];return{agents:i.filter(c=>c.source!=="bot"),members:i.filter(c=>c.source==="bot"),files:a,chats:l}}function zC(e,t,s=[],r={}){const[o,i]=f.useState([]),[a,l]=f.useState([]),c=t!==null,{searchFiles:u,agents:d=!0}=r;return f.useEffect(()=>{if(!c||!d)return;i([]);let m=!1;return window.electronAPI.agentRegistry.list().then(h=>{const p=kj(h);m||i(p?jU(p.candidates):[])}).catch(()=>{m||i([])}),()=>{m=!0}},[c,d]),f.useEffect(()=>{if(t===null||!e&&!u){l([]);return}let m=!1;const h=window.setTimeout(()=>{(u?u(t):window.electronAPI.files.search({conversationId:e,query:t})).then(p=>{m||l(kU(p))}).catch(()=>{m||l([])})},150);return()=>{m=!0,window.clearTimeout(h)}},[e,t,u]),f.useMemo(()=>t===null?{agents:[],members:[],files:[],chats:[]}:NU(t,o,a,s),[o,a,s,t])}const iy={bot:"Mention a member",all:"Mention a member",chat:"Reference a chat",file:"Files",skill:"Skills"},SU=e=>{switch(e.kind){case"bot":return`bot:${e.bot.id}`;case"all":return"all";case"chat":return`chat:${e.chat.id}`;case"file":return`file:${e.path}`;case"skill":return`skill:${e.skill.id}`}};function CU({chatId:e,placeholder:t,members:s,chatOptions:r=[],skills:o=[],running:i,disabled:a=!1,toolbar:l,hint:c,onSend:u,onStop:d}){const{t:m}=z(),h=f.useRef(null),p=f.useRef(null),g=f.useRef(!1),[x,v]=f.useState(()=>Mg(localStorage,e)),[b,w]=f.useState([]),[j,T]=f.useState(null),[N,S]=f.useState(0),[I,k]=f.useState(!1),L=pe(W=>W.keybindings),{"send-message":F}=Pr(L),{text:A}=x,M=W=>v(H=>({...H,...W}));f.useEffect(()=>{h.current?.focus()},[]),f.useEffect(()=>{TA(localStorage,e,x)},[e,x]),f.useEffect(()=>AA(W=>{W===e&&v(Mg(localStorage,W))}),[e]),f.useLayoutEffect(()=>{const W=h.current;W&&(W.style.height="auto",W.style.height=`${Math.min(W.scrollHeight,220)}px`)},[A]);const R=f.useCallback(W=>window.electronAPI.bots.searchFiles({chatId:e,query:W}).then(H=>H.ok?H.files:[]),[e]),$=zC(void 0,j?.kind==="at"?j.query:null,[],{searchFiles:R,agents:!1}).files,U=(()=>{if(!j)return[];const W=j.query.toLowerCase();if(j.kind==="skill")return o.filter(B=>B.name.toLowerCase().includes(W)).slice(0,10).map(B=>({kind:"skill",skill:B}));const H=s?gU(j.query,s).map(B=>({kind:"bot",bot:B})):[];return s&&jj.some(B=>B.startsWith(W))&&H.push({kind:"all"}),x.chats.length<EA&&H.push(...r.filter(B=>!x.chats.includes(B.id)&&B.title.toLowerCase().includes(W)).slice(0,6).map(B=>({kind:"chat",chat:B}))),H.push(...$.slice(0,8).map(B=>({kind:"file",path:B.relativePath,name:B.label}))),H})(),q=(W,H)=>{const B=o.length?fh(W,H):null;if(B!==null){T({kind:"skill",start:H-B.length-1,query:B}),S(0);return}const ne=/(^|[^A-Za-z0-9._%+-])@([^\s@]*)$/u.exec(W.slice(0,H));if(!ne)return T(null);T({kind:"at",start:H-ne[2].length-1,query:ne[2]}),S(0)},te=W=>{if(!j)return;const H=h.current,B=H?.selectionStart??A.length,ne=A.slice(0,j.start),ve=A.slice(B);let he="";const G={};W.kind==="bot"||W.kind==="all"?he=`@${W.kind==="all"?m("everyone"):W.bot.name} `:W.kind==="file"?(he=`@${W.path} `,G.files=[...new Set([...x.files,W.path])]):W.kind==="chat"?G.chats=[...x.chats,W.chat.id]:G.skill=W.skill.id,M({...G,text:ne+he+ve}),T(null);const we=ne.length+he.length;requestAnimationFrame(()=>{H?.focus(),H?.setSelectionRange(we,we)})},V=W=>{for(const H of W){if(!H.type.startsWith("image/"))continue;const B=new FileReader;B.onload=()=>{const ne=B.result;w(ve=>[...ve,{data:ne.slice(ne.indexOf(",")+1),mimeType:H.type}])},B.readAsDataURL(H)}},se=W=>{const H=h.current,B=H?.selectionStart??A.length,ne=H?.selectionEnd??A.length;window.electronAPI.bots.savePastedText({chatId:e,text:W}).catch(()=>({ok:!1,error:"unavailable"})).then(ve=>{const he=ve.ok?`@${ve.path} `:W;v(G=>({...G,text:G.text.slice(0,B)+he+G.text.slice(ne)})),requestAnimationFrame(()=>{H?.focus(),H?.setSelectionRange(B+he.length,B+he.length)})})},Ce=new Map(r.map(W=>[W.id,W])),de=x.skill?o.find(W=>W.id===x.skill||W.name===x.skill):void 0,re=de&&s?s.filter(W=>xU(A,s).ids.includes(W.id)&&!de.owners.includes(W.id)):[],Z=!a&&!I&&(A.trim().length>0||b.length>0||x.chats.length>0||!!x.skill),me=async()=>{if(!Z)return;const W=x,H=b,B=W.text.trim();v(RA),w([]),T(null),k(!0);try{await u({text:B,images:H,files:W.files.filter(ve=>B.includes(`@${ve}`)),chats:W.chats,...W.skill?{skill:de?.id??W.skill}:{}})||(v(ve=>ve.text||ve.chats.length||ve.skill?ve:W),w(ve=>ve.length?ve:H))}finally{k(!1)}},xe=W=>{const H=W.nativeEvent.isComposing||g.current;if(j&&U.length>0&&!H){if(W.key==="ArrowDown"||W.key==="ArrowUp"){W.preventDefault();const B=W.key==="ArrowDown"?1:-1;S(ne=>(ne+B+U.length)%U.length);return}if(W.key==="Enter"||W.key==="Tab"){W.preventDefault(),te(U[Math.min(N,U.length-1)]);return}if(W.key==="Escape"){W.preventDefault(),T(null);return}}!H&&Sj(W,F)&&(W.preventDefault(),me())},Se=W=>(s??[]).filter(H=>W.includes(H.id)).map(H=>H.name).join(", ");return n.jsxs("div",{"data-slot":"composer",className:"relative rounded-2xl border bg-background shadow-float",onDragOver:W=>W.preventDefault(),onDrop:W=>{W.preventDefault(),V([...W.dataTransfer.files])},children:[j&&U.length>0&&n.jsx("div",{className:"absolute bottom-full left-3 z-10 mb-1.5 max-h-80 w-80 overflow-y-auto rounded-xl border bg-popover p-1 shadow-lg",children:U.map((W,H)=>{const B=iy[W.kind],ne=H===0||iy[U[H-1].kind]!==B;return n.jsxs("div",{children:[ne&&n.jsx("div",{className:"px-2 py-1 text-[11px] text-muted-foreground",children:m(B)}),n.jsx("button",{type:"button",onMouseDown:ve=>{ve.preventDefault(),te(W)},onMouseEnter:()=>S(H),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm",H===N&&"bg-muted"),children:n.jsx(IU,{item:W,ownerNames:Se,grouped:!!s})})]},SU(W))})}),(x.chats.length>0||x.skill)&&n.jsxs("div",{className:"flex flex-wrap gap-1.5 px-3 pt-3",children:[x.skill&&n.jsx(ay,{icon:n.jsx(Bs,{className:"h-3 w-3"}),label:de?.name??x.skill,tone:"skill",onRemove:()=>M({skill:void 0})}),x.chats.map(W=>n.jsx(ay,{icon:n.jsx(Jr,{className:"h-3 w-3"}),label:Ce.get(W)?.title??m("Unavailable chat"),onRemove:()=>M({chats:x.chats.filter(H=>H!==W)})},W))]}),re.length>0&&n.jsx("div",{className:"px-4 pt-1.5 text-warning text-xs",children:m("{{names}} cannot use this skill; they will be told it is unavailable",{names:re.map(W=>W.name).join(", ")})}),b.length>0&&n.jsx("div",{className:"flex flex-wrap gap-2 px-3 pt-3",children:b.map((W,H)=>n.jsxs("div",{className:"group relative h-14 w-14 overflow-hidden rounded-lg border",children:[n.jsx("img",{src:`data:${W.mimeType};base64,${W.data}`,alt:"",className:"h-full w-full object-cover"}),n.jsx("button",{type:"button","aria-label":m("Remove"),onClick:()=>w(B=>B.filter((ne,ve)=>ve!==H)),className:"absolute top-0.5 right-0.5 hidden rounded-full bg-background/90 p-0.5 group-hover:block",children:n.jsx(Jt,{className:"h-3 w-3"})})]},H))}),n.jsx("textarea",{ref:h,value:A,rows:1,disabled:a,placeholder:t,onChange:W=>{M({text:W.target.value}),q(W.target.value,W.target.selectionStart)},onSelect:W=>q(W.currentTarget.value,W.currentTarget.selectionStart),onBlur:()=>T(null),onKeyDown:xe,onCompositionStart:()=>{g.current=!0},onCompositionEnd:()=>{g.current=!1},onPaste:W=>{const H=[...W.clipboardData.files].filter(B=>B.type.startsWith("image/"));if(H.length===0){const B=W.clipboardData.getData("text/plain");if(!Nj(B))return;W.preventDefault(),se(B);return}W.preventDefault(),V(H)},className:"block max-h-56 min-h-12 w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm outline-none placeholder:text-muted-foreground disabled:opacity-60"}),n.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2",children:[n.jsx("button",{type:"button",onClick:()=>p.current?.click(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground",title:m("Attach image"),"aria-label":m("Attach image"),children:n.jsx(Wh,{className:"h-4 w-4"})}),n.jsx("input",{ref:p,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:W=>{V([...W.target.files??[]]),W.target.value=""}}),l,n.jsx("div",{className:"min-w-0 flex-1 truncate text-muted-foreground text-xs",children:c}),i&&d&&!Z?n.jsx("button",{type:"button",onClick:d,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground",title:m("Stop"),"aria-label":m("Stop"),children:n.jsx(Uh,{className:"h-3 w-3 fill-current"})}):n.jsx("button",{type:"button",disabled:!Z,onClick:()=>{me()},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground disabled:opacity-40",title:m("Send"),"aria-label":m("Send"),children:n.jsx(Wd,{className:"h-4 w-4"})})]})]})}function IU({item:e,ownerNames:t,grouped:s}){const{t:r}=z();switch(e.kind){case"all":return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"grid h-6 w-6 place-items-center rounded-full bg-muted text-[11px]",children:"@"}),n.jsx("span",{children:r("everyone")})]});case"bot":return n.jsxs(n.Fragment,{children:[n.jsx($t,{bot:e.bot,size:"sm"}),n.jsx("span",{className:"min-w-0 truncate",children:e.bot.name}),n.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:e.bot.title})]});case"chat":return n.jsxs(n.Fragment,{children:[n.jsx(Jr,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 truncate",children:e.chat.title}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:e.chat.kind==="group"?r("Group chat"):r("Direct chat")})]});case"file":return n.jsxs(n.Fragment,{children:[n.jsx(Wo,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0",children:e.name}),n.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:e.path})]});case"skill":return n.jsxs(n.Fragment,{children:[n.jsx(Bs,{className:"h-4 w-4 shrink-0 text-info"}),n.jsx("span",{className:"shrink-0",children:e.skill.name}),n.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:s?t(e.skill.owners):e.skill.description})]})}}function ay({icon:e,label:t,tone:s,onRemove:r}){const{t:o}=z();return n.jsxs("span",{className:_("inline-flex h-6 max-w-56 items-center gap-1 rounded-md px-1.5 text-xs",s==="skill"?"bg-info/15 text-info":"bg-muted text-foreground"),children:[e,n.jsx("span",{className:"min-w-0 truncate",children:t}),n.jsx("button",{type:"button","aria-label":o("Remove"),onClick:r,className:"rounded opacity-70 hover:opacity-100",children:n.jsx(Jt,{className:"h-3 w-3"})})]})}const TU={thinking:"Thinking",typing:"Writing reply",tool:"Calling tools",retrying:"Retrying"},ly={turn:"Queued · waiting for the current turn to finish",capacity:"Queued · concurrency limit reached","member-check":"Queued · checking whether tasks can run in parallel","member-serial":"Queued · waiting for the member's current task to finish","member-fifo":"Queued · waiting for the member's earlier tasks","member-stopping":"Queued · waiting for the member to stop"},AU={running:"Running",done:"Done",error:"Error",denied:"Denied",timeout:"Timed out · denied"},EU={running:"text-primary",done:"text-success",error:"text-destructive",denied:"text-warning",timeout:"text-warning"},RU=e=>e<1e4?`${(Math.max(0,e)/1e3).toFixed(1)}s`:Dr(e);function $C({conversationId:e,leading:t,trailing:s,className:r}){const{t:o}=z(),i=ie(h=>e?h.sessions[e]:void 0),a=ie(h=>e?h.queue.find(p=>p.conversationId===e):void 0),l=f.useMemo(()=>MA(i,!!a),[i,a]),c=!!(l&&l.state!=="queued"),[u,d]=f.useState(()=>Date.now());f.useEffect(()=>{if(!c)return;d(Date.now());const h=window.setInterval(()=>d(Date.now()),1e3);return()=>window.clearInterval(h)},[c]);const m=l?l.state!=="queued"?o(TU[l.state]):o(a?.reason&&Object.hasOwn(ly,a.reason)?ly[a.reason]:"Queued"):null;return n.jsxs("div",{className:_("min-w-0 text-muted-foreground text-xs",r),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[t,m&&n.jsx("span",{className:"truncate",children:m}),c&&l?.startedAt!==void 0&&n.jsx("span",{className:"shrink-0 tabular-nums",children:Dr(u-l.startedAt)}),s]}),l&&l.steps.length>0&&n.jsxs("div",{className:"mt-1 flex flex-col gap-0.5",children:[l.more>0&&n.jsxs("span",{children:["+",l.more]}),l.steps.map(h=>{const p=h.durationMs??(h.startedAt!==void 0?u-h.startedAt:void 0);return n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx("span",{className:"shrink-0 font-medium text-foreground",children:Rr(h.name,o)}),h.detail&&n.jsx("span",{className:"truncate font-mono",children:h.detail}),n.jsx("span",{className:_("shrink-0",EU[h.status]),children:o(h.status==="timeout"&&h.name==="ask_user"?"Timed out · no answer":AU[h.status])}),p!==void 0&&n.jsx("span",{className:"shrink-0 tabular-nums",children:RU(p)})]},h.id)})]})]})}const MU=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),PU=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),DU=[],OU={auto:"Automatic",delegator:"By delegator",human:"Manual"};function ju({state:e,interrupted:t,autoRetry:s}){const{t:r}=z();if(s&&e==="failed")return n.jsx("span",{className:"rounded bg-warning/25 px-1.5 text-[11px] text-warning-foreground dark:bg-warning/15 dark:text-warning",children:r("Will retry automatically")});const o=e==="running"||e==="queued"?"bg-info/15 text-info":e==="completed"?"bg-success/15 text-success":e==="failed"?"bg-destructive/15 text-destructive":e==="blocked"?"bg-warning/15 text-warning":"bg-muted text-muted-foreground",i={queued:r("Queued"),running:r("In progress"),completed:r("Completed"),failed:r(t?"Interrupted":"Failed"),canceled:r("Canceled"),blocked:r("Stuck run")};return n.jsx("span",{className:_("rounded px-1.5 text-[11px]",o),children:i[e]??e})}function VC({check:e,className:t}){const{t:s}=z();return n.jsxs("div",{className:_("flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs",t),children:[n.jsx("span",{className:"shrink-0",children:s("Acceptance check")}),n.jsx("code",{className:"min-w-0 truncate rounded bg-muted px-1",title:e.text,children:e.text}),e.passed!==void 0&&n.jsx("span",{className:_("shrink-0 rounded px-1.5 text-[11px]",e.passed?"bg-success/15 text-success":"bg-destructive/15 text-destructive"),children:e.passed?s("Passed"):s("Not passed")})]})}function Dl(e,t){switch(e.failure){case"interrupted":return t("The app restarted before this task finished. It was stopped and will not rerun.");case"timeout":return t("Timed out after {{n}} minutes.",{n:e.timeoutMinutes??240});case"denied":return t("Denied.");case"check":return t('Acceptance check failed: "{{text}}" not found in tool outputs.',{text:e.check?.text??""});default:return e.error==="budget-exceeded"?t("The member's daily budget is used up."):e.error==="turn-token-limit"?t("Stopped: the member's per-turn token limit was exceeded."):e.error}}function LU(e,t){window.electronAPI.bots.cancelDelegation(e).then(s=>{s.ok||Ie({type:"error",title:t("Cancel failed"),description:s.error}),ie.getState().refreshDelegations()})}function Pa(e,t,s){window.electronAPI.bots.retryDelegation(e,s).then(r=>{r.ok?r.warning&&Ie({type:"warning",title:r.warning}):Ie({type:"error",title:t("Retry failed"),description:r.error}),ie.getState().refreshDelegations()})}function ku(e){const[t,s]=f.useState(()=>Date.now());return f.useEffect(()=>{if(!e)return;s(Date.now());const r=setInterval(()=>s(Date.now()),3e4);return()=>clearInterval(r)},[e]),t}function _U({record:e,delegations:t}){const{t:s}=z(),r=DA(e);if(!r)return null;const o=Tj(e,t);return n.jsx("span",{className:"rounded border px-1 py-px text-[10px]",title:e.retryNote?s("Delegator note: {{note}}",{note:e.retryNote}):void 0,children:OA(e)?s("Retrying automatically · attempt {{n}}",{n:o}):s("Retry #{{n}} · {{source}}",{n:o,source:s(OU[r])})})}function Nu({record:e,entry:t,retried:s,append:r,taskSeq:o,fill:i,bots:a,onOpenConversation:l}){const{t:c}=z(),u=ie($=>$.delegations)??DU,d=e?.state??t?.state??"queued",m=ku(!r&&_a(d)),h=a.get(e?.parentBotId??t?.from??""),p=a.get(e?.targetBotId??t?.to??""),g=LA(r?"completed":d),x=PA(e),v=!r&&x&&_a(d),b=!r&&d==="blocked"?e?.blocked:void 0,w=ie($=>b&&e?.taskId?$.delegations.some(U=>U.taskId===e.taskId&&U.createdAt>e.createdAt):!1),j=ie($=>$.openTask),T=!!t?.taskId&&!r,[N,S]=f.useState(!T),I=e?Cj(e,u):!1,k=!r&&e?.chatId&&e.resultSeq!==void 0?{chatId:e.chatId,seq:e.resultSeq}:void 0,L=r||k?void 0:e?d==="completed"?e.result:d==="blocked"?void 0:Dl(e,c):t?.summary,F=c("{{from}} → {{to}} · Delegation",{from:h?.name??c("Deleted member"),to:p?.name??c("Deleted member")}),A=n.jsxs(n.Fragment,{children:[T&&n.jsx(fn,{"aria-hidden":!0,className:_("size-3.5 shrink-0 transition-transform",N&&"rotate-90")}),n.jsx($t,{bot:h,size:"xs"}),n.jsx("span",{className:"min-w-0 truncate text-foreground",title:h?.name,children:h?.name??c("Deleted member")}),n.jsx("span",{children:"→"}),n.jsx($t,{bot:p,size:"xs",presence:x?.state}),n.jsx("span",{className:"min-w-0 truncate text-foreground",title:p?.name,children:p?.name??c("Deleted member")}),n.jsxs("span",{children:["· ",c("Delegation")]}),r?n.jsx("span",{className:"rounded bg-info/15 px-1.5 text-[11px] text-info",children:o===void 0?c("Merged into the current run"):c("Merged into the current run of #{{n}}",{n:o})}):v?n.jsx(Ij,{info:x}):n.jsx(ju,{state:d,interrupted:e?.failure==="interrupted",autoRetry:I}),e&&!r&&n.jsx(_U,{record:e,delegations:u}),e&&!r&&n.jsx("span",{children:Dr((e.finishedAt??m)-e.createdAt)}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{children:MU(r?.at??t?.at??e?.createdAt??m)})]}),M="flex flex-wrap items-center gap-1.5 whitespace-nowrap text-muted-foreground text-xs",R=r?.text??e?.task;return n.jsxs("div",{"data-slot":"bot-card",className:_("rounded-xl border bg-card px-3 py-2.5",i?"w-full min-w-0":"max-w-lg"),children:[T?n.jsx("button",{type:"button","aria-expanded":N,"aria-label":c(N?"Collapse delegation result":"Expand delegation result"),className:_(M,"w-full rounded text-left hover:text-foreground"),onClick:()=>S($=>!$),children:A}):n.jsx("div",{className:M,children:A}),!N&&R&&n.jsx("div",{className:"mt-1 truncate text-muted-foreground text-xs",children:R}),N&&R&&n.jsx("div",{className:"mt-1.5 line-clamp-3 text-sm [overflow-wrap:anywhere]",children:R}),N&&n.jsxs(n.Fragment,{children:[e?.check&&!r&&n.jsx(VC,{check:e.check,className:"mt-1.5"}),L&&n.jsx("div",{className:"mt-1.5 line-clamp-4 whitespace-pre-wrap text-muted-foreground text-xs [overflow-wrap:anywhere]",children:L}),b&&e&&n.jsxs("div",{className:"mt-1.5 rounded-md bg-warning/10 px-2 py-1 text-xs",children:[n.jsx("div",{className:"line-clamp-4 whitespace-pre-wrap",children:c("Blocked · needs: {{need}}",{need:b.need})}),n.jsx("div",{className:"text-muted-foreground",children:w?c("Answered; the work continues"):b.waitFor==="parent"?c("Waiting for {{name}} to reply",{name:h?.name??c("Deleted member")}):c("Waiting for your reply")})]}),I&&e?.autoRetryAt!==void 0&&n.jsx("div",{className:"mt-1 text-warning-foreground text-xs dark:text-warning",children:c("Retrying automatically at {{time}} (attempt {{n}})",{time:PU(e.autoRetryAt),n:Tj(e,u)+1})}),k&&n.jsx("button",{type:"button",onClick:()=>ie.getState().focusSeq(k.chatId,k.seq),className:"mt-1.5 text-muted-foreground text-xs underline-offset-2 hover:text-foreground hover:underline",children:c("Result posted to the group · View")}),e&&n.jsxs("div",{className:"mt-2 flex flex-wrap justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>l(e.childConversationId,F),children:c("View process")}),b&&!w&&e.chatId&&e.taskId&&n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>e.chatId&&e.taskId&&j(e.chatId,e.taskId),children:c("Reply")}),g.cancel&&n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>LU(e.id,c),children:c("Cancel")}),g.retry&&!s&&n.jsx(fe,{size:"xs",variant:"outline",title:I?c("Skip the wait and retry now. The scheduled automatic retry is canceled."):void 0,onClick:()=>Pa(e.id,c),children:c(I?"Retry now":"Retry")}),g.resumeOrRestart&&!s&&n.jsxs(n.Fragment,{children:[n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>Pa(e.id,c,"resume"),children:c("Continue")}),n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>Pa(e.id,c,"restart"),children:c("Start over")})]})]})]})]})}function HC(e){const t=ie(u=>u.chats.find(d=>d.id===e)),s=ie(u=>u.sessions),r=ie(u=>u.queue),o=ie(u=>u.silences),i=ie(u=>u.delegations),a=ie(u=>u.browserHolders),l=ie(u=>u.browserTabs[t?.parentId??e]?.tabs),c=ie(u=>BA(u.timelines[e]?.entries??[]));return f.useMemo(()=>({chat:t??{id:e,sessions:{}},delegations:i,sessions:s,queue:r,silences:o,clearedAt:c,holders:a,tabIds:l??[]}),[t,e,i,s,r,o,c,a,l])}function BU(e,t){const s=HC(e);return f.useMemo(()=>_A(t,s),[t,s])}function FU(e,t){const s=e.wait;switch(s?.kind){case"approval":return t("Your approval: {{title}}",{title:s.title});case"ask":return t("Your answer: {{title}}",{title:s.title});case"file":return t("{{holder}} is editing {{file}}",{holder:s.holder,file:s.file});case"workspace":return t("{{holder}} is running a workspace-wide command",{holder:s.holder});case"capacity":return t("A free slot (concurrency limit, not a person)");case"turn":return t("Its previous turn to finish");case"member-check":return t("Queued · checking whether tasks can run in parallel");case"member-serial":return t("Queued · waiting for the member's current task to finish");case"member-fifo":return t("Queued · waiting for the member's earlier tasks");case"member-stopping":return t("Queued · waiting for the member to stop");default:return}}function WC(e){const t=document.querySelector(`[data-pending-conversation="${CSS.escape(e)}"]`);t?.scrollIntoView({block:"nearest"}),t?.animate([{backgroundColor:"var(--color-warning)"},{backgroundColor:"transparent"}],{duration:1200})}function Zi({label:e,children:t}){return n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"w-12 shrink-0 text-muted-foreground",children:e}),n.jsx("span",{className:"min-w-0 flex-1 break-words",children:t})]})}function UC({info:e,bot:t}){const{t:s}=z(),r=ie(c=>e.delegation?c.bots.find(u=>u.id===e.delegation?.parentBotId):void 0),o=e.delegation,i=FU(e,s),a=ie(c=>e.browserTab?c.browserTitles[e.browserTab]||s("Browser"):void 0),l=e.wait&&"conversationId"in e.wait?e.wait.conversationId:void 0;return n.jsxs(yu,{align:"start",className:"w-72 flex-col gap-1.5 p-3 text-xs",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-semibold text-sm",children:t?.name??s("Deleted member")}),n.jsx(Ij,{info:e})]}),e.state==="idle"?n.jsx("div",{className:"text-muted-foreground",children:s("Nothing in progress")}):n.jsxs(n.Fragment,{children:[o&&n.jsxs(n.Fragment,{children:[n.jsx(Zi,{label:s("Task"),children:n.jsx("span",{className:"line-clamp-2",children:o.task})}),n.jsx(Zi,{label:s("From"),children:r?.name??s("Deleted member")}),n.jsx(Zi,{label:s("Time"),children:Dr((o.finishedAt??Date.now())-o.createdAt)})]}),i&&n.jsx(Zi,{label:s("Waiting on"),children:i}),a&&n.jsx(Zi,{label:s("Browser"),children:n.jsx("span",{className:"line-clamp-1",children:a})}),e.quietSince!==void 0&&n.jsx("div",{className:"text-muted-foreground",children:s("Still running, no output for {{time}}",{time:Dr(Date.now()-e.quietSince)})}),o&&e.state==="stuck"&&o.state==="failed"&&n.jsx("div",{className:"text-muted-foreground",children:Dl(o,s)}),o&&e.state==="done"&&o.result&&n.jsx("div",{className:"line-clamp-3 text-muted-foreground",children:o.result}),l&&n.jsx(fe,{size:"xs",className:"mt-1 self-start",onClick:()=>WC(l),children:s("Go handle it")})]})]})}function qC({chatId:e,botId:t,bot:s,size:r="sm"}){const{t:o}=z(),i=BU(e,t);return n.jsxs(Ml,{children:[n.jsxs(Pl,{render:n.jsx("span",{className:"relative inline-flex shrink-0"}),children:[n.jsx($t,{bot:s,size:r,presence:i.state}),n.jsx("span",{className:"sr-only",children:dm(i,o)})]}),n.jsx(UC,{info:i,bot:s})]})}function zU({chatId:e,memberIds:t,bots:s,onOpenLive:r}){const{t:o}=z(),i=HC(e),a=f.useMemo(()=>FA(t,i),[t,i]);return a.length===0?null:n.jsx("div",{className:"mb-1.5 flex flex-wrap items-center gap-1",children:a.map(({botId:l,info:c})=>{const u=s.get(l),d=u?.name??o("Deleted member"),m=zA(c),h=$A(c);return n.jsxs(Ml,{children:[n.jsxs(Pl,{render:n.jsx("button",{type:"button",onClick:()=>h?.kind==="pending"?WC(h.conversationId):h&&r(h.conversationId,l),className:"flex h-7 min-w-0 items-center gap-1.5 rounded-full px-1 text-muted-foreground text-xs transition-colors hover:bg-muted hover:text-foreground"}),children:[n.jsx($t,{bot:u,size:"xs",presence:c.state}),m?n.jsx("span",{className:"max-w-56 truncate pr-1.5",children:[d,dm(c,o),m].join(" · ")}):n.jsx("span",{className:"sr-only",children:`${d} · ${dm(c,o)}`})]}),n.jsx(UC,{info:c,bot:u})]},l)})})}function $U(e){return{budgetCost:e?.dailyCostUsd!==void 0?String(e.dailyCostUsd):"",budgetTokens:e?.dailyTokens!==void 0?String(e.dailyTokens):""}}function GC(e){const t={},s=e.budgetCost.trim();if(s){const o=Number(s);if(!Number.isFinite(o)||o<=0)return{ok:!1};t.dailyCostUsd=o}const r=e.budgetTokens.trim();if(r){const o=Number(r);if(!Number.isSafeInteger(o)||o<=0)return{ok:!1};t.dailyTokens=o}return{ok:!0,budget:Object.keys(t).length>0?t:null}}function VU(e){return{delegationTimeout:e.delegationTimeoutMinutes!==void 0?String(e.delegationTimeoutMinutes):"",maxTurnTokens:e.maxTokensPerTurn!==void 0?String(e.maxTokensPerTurn):""}}function Lx(e){const t=e.delegationTimeout.trim()?Number(e.delegationTimeout):null,s=e.maxTurnTokens.trim()?Number(e.maxTurnTokens):null;return t!==null&&!VA(t)||s!==null&&!HA(s)?{ok:!1}:{ok:!0,delegationTimeoutMinutes:t,maxTokensPerTurn:s}}function cy(e){return[...e.normalize("NFC").trim().replace(/\s+/gu,"_").replace(/[^\p{L}\p{N}_-]/gu,"").replace(/_+/gu,"_").replace(/^_+|_+$/gu,"")].slice(0,UA).join("")}const Gr=e=>typeof e=="string"?e.trim():"",Mf=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function dy(e){const t=e.split(`
|
|
86
|
-
`).find(r=>r.trim())??"",s=/^.*?[.!?。!?](?=\s|$)/u.exec(t.trim());return(s?s[0]:t.trim()).slice(0,80)}function HU(e,t){return{spec:"chara_card_v2",spec_version:"2.0",data:{name:e.name,description:t,personality:"",scenario:e.scope,first_mes:"",mes_example:"",creator_notes:e.title,system_prompt:"",post_history_instructions:"",alternate_greetings:[],tags:[],creator:"EnsoCode",character_version:"",extensions:{enso:{title:e.title,scope:e.scope,color:e.avatar.color,tools:e.tools,approvalMode:e.approvalMode,memory:e.memory.enabled}}}}}function WU(e){return{...typeof e.title=="string"?{title:e.title.trim()}:{},...Gr(e.scope)?{scope:Gr(e.scope)}:{},...typeof e.color=="string"&&/^#[0-9a-f]{6}$/iu.test(e.color)?{color:e.color}:{},...e.tools==="all"||e.tools==="readonly"?{tools:e.tools}:{},...WA.includes(e.approvalMode)?{approvalMode:e.approvalMode}:{},...typeof e.memory=="boolean"?{memoryEnabled:e.memory}:{}}}function UU(e){let t;try{t=JSON.parse(e)}catch{return{ok:!1,error:"invalid-json"}}if(!t||typeof t!="object"||Array.isArray(t))return{ok:!1,error:"not-a-card"};const s=t,r=Mf(s.data)?s.data:s,o=Gr(r.name);if(!o)return{ok:!1,error:"not-a-card"};const i=Mf(r.extensions)?r.extensions.enso:void 0;if(Mf(i)){const u=typeof r.description=="string"?r.description:"";return{ok:!0,draft:{name:cy(o),title:"",scope:dy(u),persona:u,...WU(i)}}}const a=u=>u.replace(/\{\{char\}\}/giu,o).replace(/\{\{user\}\}/giu,"the user"),l=a(Gr(r.description)),c=[l,Gr(r.personality)&&`Personality: ${a(Gr(r.personality))}`,Gr(r.scenario)&&`Scenario: ${a(Gr(r.scenario))}`].filter(Boolean);return{ok:!0,draft:{name:cy(o),title:"",scope:dy(l),persona:c.join(`
|
|
87
|
-
|
|
88
|
-
`)}}}const qU=["tools","approvalMode","skillIds","mcpServerIds","canDelegateTo","acceptFrom"],GU=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every(s=>t.includes(s)):e===t;function uy(e,t){return qU.flatMap(s=>{const r=t[s];return!r||GU(e[s],r.value)?[]:[{field:s,from:e[s],to:r.value,reason:r.reason}]})}function KU(e,t,s){const r={...e};for(const o of t)s.includes(o.field)&&Object.assign(r,{[o.field]:o.to});return r}const KC={tools:"all",approvalMode:"auto-edits",skillIds:[],mcpServerIds:[],canDelegateTo:"any",acceptFrom:"any",memoryEnabled:!0,budgetCost:"",budgetTokens:"",delegationTimeout:"",maxTurnTokens:""};function YC({value:e,onChange:t,profile:s,botId:r,zIndex:o}){const{t:i}=z(),l=ie(c=>c.bots).filter(c=>c.id!==r&&!c.archivedAt);return n.jsxs("div",{className:"space-y-4",children:[n.jsx(YU,{value:e,onApply:t,profile:s,botId:r}),n.jsxs("div",{children:[n.jsx(Ot,{children:i("Tools")}),n.jsx(Gh,{value:e.tools,options:[{value:"all",label:i("All tools")},{value:"readonly",label:i("Read-only")}],onChange:c=>t({tools:c})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:i("Approval mode")}),n.jsx(Aj,{value:e.approvalMode,onChange:c=>t({approvalMode:c}),zIndex:o})]}),n.jsx(XC,{value:e,onChange:t}),n.jsx(fy,{label:i("Can delegate to"),value:e.canDelegateTo,bots:l,onChange:c=>t({canDelegateTo:c})}),n.jsx(fy,{label:i("Accepts delegation from"),value:e.acceptFrom,bots:l,onChange:c=>t({acceptFrom:c})}),n.jsxs("label",{className:"flex items-center justify-between gap-2 text-sm",children:[n.jsx("span",{children:i("Long-term memory")}),n.jsx(rr,{checked:e.memoryEnabled,onCheckedChange:c=>t({memoryEnabled:c})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:i("Daily budget")}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx(Ht,{type:"number",min:0,step:"0.01",inputMode:"decimal",value:e.budgetCost,placeholder:i("Cost (USD), empty = unlimited"),"aria-label":i("Daily cost limit (USD)"),onChange:c=>t({budgetCost:c.target.value})}),n.jsx(Ht,{type:"number",min:0,step:"1",inputMode:"numeric",value:e.budgetTokens,placeholder:i("Tokens, empty = unlimited"),"aria-label":i("Daily token limit"),onChange:c=>t({budgetTokens:c.target.value})})]}),n.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("Resets at local midnight. Once reached, new messages to this member are refused and a running reply is stopped.")})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:i("Per-turn token limit")}),n.jsx(Ht,{type:"number",min:1,step:"1",inputMode:"numeric",value:e.maxTurnTokens,placeholder:i("Tokens, empty = unlimited"),"aria-label":i("Per-turn token limit"),onChange:c=>t({maxTurnTokens:c.target.value})}),n.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("A single reply that uses more tokens than this (counted while streaming) is stopped.")})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:i("Delegation time limit (minutes)")}),n.jsx(Ht,{type:"number",min:1,max:1440,step:"1",inputMode:"numeric",value:e.delegationTimeout,placeholder:i("Empty = 240"),"aria-label":i("Delegation time limit (minutes)"),onChange:c=>t({delegationTimeout:c.target.value})}),n.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("When other members delegate to this one, the task fails with a timeout after this long. A delegator can ask for less, not more.")})]})]})}function Su(e,t){switch(e.error){case"no-model":return t("No model is available. Set a default model or a Bot assistant model first.");case"timeout":return t("The model did not answer in time. Try again.");case"invalid-reply":return t("The model reply could not be understood. Try again.");case"invalid":return t("Fill in a name, title or responsibilities first.");default:return t("Could not get suggestions")}}function YU({value:e,onApply:t,profile:s,botId:r}){const{t:o,locale:i}=z(),[a,l]=f.useState(!1),[c,u]=f.useState(null),[d,m]=f.useState([]),h=c?uy(e,c):[],p=async()=>{if(![s.name,s.title,s.scope,s.persona].some(x=>x.trim())){Ie({type:"warning",title:o("Fill in a name, title or responsibilities first.")});return}l(!0);try{const x=await window.electronAPI.bots.suggestAbilities({name:s.name,title:s.title,scope:s.scope,persona:s.persona,language:i==="zh"?"zh":"en",...r?{botId:r}:{}});if(!x.ok){Ie({type:"error",title:Su(x,o),...x.detail?{description:x.detail}:{}});return}if(uy(e,x.suggestion).length===0){Ie({type:"info",title:o("Current abilities already match the suggestion.")});return}m([]),u(x.suggestion)}finally{l(!1)}},g=()=>{const x=h.map(b=>b.field).filter(b=>!d.includes(b)),v=KU(e,h,x);t(Object.fromEntries(x.map(b=>[b,v[b]]))),u(null)};return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:o("Let a model suggest abilities from the name, title, responsibilities and persona.")}),n.jsxs(fe,{size:"xs",variant:"outline",disabled:a,onClick:()=>{p()},children:[a?n.jsx(_t,{className:"animate-spin"}):n.jsx(Bs,{}),o("Auto-configure abilities")]})]}),c&&h.length>0&&n.jsxs("div",{className:"space-y-2 rounded-lg border bg-muted/40 p-2.5",children:[n.jsx("p",{className:"font-medium text-xs",children:o("Suggested changes")}),h.map(x=>n.jsxs("label",{className:"flex items-start gap-2 text-xs",children:[n.jsx(Vo,{className:"mt-0.5",checked:!d.includes(x.field),onCheckedChange:v=>m(b=>v?b.filter(w=>w!==x.field):[...b,x.field])}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-1.5",children:[n.jsx("span",{className:"font-medium",children:XU(x.field,o)}),n.jsx(QU,{change:x})]}),x.reason&&n.jsx("p",{className:"text-muted-foreground",children:x.reason})]})]},x.field)),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>u(null),children:o("Cancel")}),n.jsx(fe,{size:"xs",disabled:h.every(x=>d.includes(x.field)),onClick:g,children:o("Apply")})]})]})]})}function XU(e,t){switch(e){case"tools":return t("Tools");case"approvalMode":return t("Approval mode");case"skillIds":return t("Skills");case"mcpServerIds":return t("MCP Servers");case"canDelegateTo":return t("Can delegate to");case"acceptFrom":return t("Accepts delegation from")}}function QU({change:e}){const{t}=z(),s=pe(h=>h.skills),r=pe(h=>h.mcpServers),o=ie(h=>h.bots),i=(h,p)=>n.jsxs("span",{className:"text-muted-foreground",children:[h," → ",n.jsx("span",{className:"text-foreground",children:p})]});if(e.field==="tools"){const h=p=>t(p==="all"?"All tools":"Read-only");return i(h(e.from),h(e.to))}if(e.field==="approvalMode"){const h=p=>t(Ba[p].labelKey);return i(h(e.from),h(e.to))}const a=e.field==="skillIds"?s:e.field==="mcpServerIds"?r:o,l=h=>a.find(p=>p.id===h)?.name??h,c=e.from,u=e.to;if(c==="any"||u==="any"){const h=p=>p==="any"?t("All members"):p.length===0?t("None selected"):p.map(l).join(", ");return i(h(c),h(u))}const d=u.filter(h=>!c.includes(h)),m=c.filter(h=>!u.includes(h));return n.jsxs("span",{className:"space-x-1.5",children:[d.map(h=>n.jsxs("span",{className:"text-success",children:["+",l(h)]},`+${h}`)),m.map(h=>n.jsx("span",{className:"text-destructive line-through",children:l(h)},`-${h}`))]})}function XC({value:e,onChange:t}){const{t:s}=z(),r=pe(a=>a.skills),o=pe(a=>a.mcpServers),i=(a,l)=>a.includes(l)?a.filter(c=>c!==l):[...a,l];return n.jsxs(n.Fragment,{children:[n.jsx(Pg,{title:s("Skills"),emptyText:s("No skills yet"),items:r,getName:a=>a.name,getSource:a=>a.source,isChecked:a=>e.skillIds.includes(a.id),onToggle:a=>t({skillIds:i(e.skillIds,a.id)}),onSetFiltered:(a,l)=>t({skillIds:Og(e.skillIds,a,l)}),placeholder:s("Filter skills..."),renderDetail:a=>n.jsx(Dg,{rows:[[s("Source"),a.source],[s("Path"),a.path],[s("Description"),a.description]]})}),n.jsx(Pg,{title:s("MCP Servers"),emptyText:s("No MCP servers yet"),items:o,getName:a=>a.name,getSource:a=>a.source,isChecked:a=>e.mcpServerIds.includes(a.id),onToggle:a=>t({mcpServerIds:i(e.mcpServerIds,a.id)}),onSetFiltered:(a,l)=>t({mcpServerIds:Og(e.mcpServerIds,a,l)}),placeholder:s("Filter MCP servers..."),renderDetail:a=>n.jsx(Dg,{rows:[[s("Source"),a.source],["Transport",a.transport],["URL",a.url]]})})]})}function fy({label:e,value:t,bots:s,onChange:r}){const{t:o}=z();return n.jsxs("div",{children:[n.jsx(Ot,{children:e}),n.jsx(Gh,{value:t==="any"?"any":"some",options:[{value:"any",label:o("All members")},{value:"some",label:o("Selected members")}],onChange:i=>r(i==="any"?"any":[])}),t!=="any"&&n.jsxs("div",{className:"mt-1.5 space-y-1",children:[s.length===0&&n.jsx("p",{className:"text-muted-foreground text-xs",children:o("No other members")}),s.map(i=>n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx(Vo,{checked:t.includes(i.id),onCheckedChange:a=>r(a?[...t,i.id]:t.filter(l=>l!==i.id))}),n.jsx($t,{bot:i,size:"xs"}),i.name]},i.id))]})]})}function JU({bot:e}){const{t}=z(),s=ie(i=>i.usage?.bots[e.id]);if(f.useEffect(()=>{ie.getState().refreshUsage()},[]),!s)return null;const r=[[t("Today"),s.today],[t("Last 7 days"),s.week],[t("Last 30 days"),s.month]],o=e.budget;return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-lg border bg-card p-3",children:[n.jsx("div",{className:"grid grid-cols-3 gap-2",children:r.map(([i,a])=>n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-muted-foreground text-xs",children:i}),n.jsx("div",{className:"truncate font-medium text-sm tabular-nums",children:Bu(a.tokens)}),n.jsx("div",{className:"truncate text-muted-foreground text-xs tabular-nums",children:Fu(a.cost)})]},i))}),o&&n.jsxs("div",{className:s.exhausted?"mt-2 text-destructive text-xs":"mt-2 text-muted-foreground text-xs",children:[[o.dailyTokens!==void 0&&`${Bu(s.today.tokens)} / ${Bu(o.dailyTokens)} tokens`,o.dailyCostUsd!==void 0&&`${Fu(s.today.cost??0)} / ${Fu(o.dailyCostUsd)}`].filter(Boolean).join(" · "),s.exhausted&&` · ${t("Today's budget is used up")}`]})]})}function QC({spaceId:e,emptyText:t}){const[s,r]=f.useState(null),o=f.useCallback(async()=>{const i=await window.electronAPI.memory.list({spaceId:e,limit:100,offset:0});r(i.items)},[e]);return f.useEffect(()=>(r(null),o(),window.electronAPI.memory.onChanged(()=>{o()})),[o]),s===null?n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"}):s.length===0?n.jsx("p",{className:"text-muted-foreground text-xs",children:t}):n.jsx("div",{className:"space-y-1.5",children:s.map(i=>n.jsx(ZU,{item:i,onDeleted:()=>r(a=>a?.filter(l=>l.id!==i.id)??null)},i.id))})}function ZU({item:e,onDeleted:t}){const{t:s}=z(),[r,o]=f.useState(null),[i,a]=f.useState(!1),l=async()=>{a(!0);const u=await window.electronAPI.memory.detail(e.id);a(!1),u?o({title:u.title,content:u.content}):Ie({type:"error",title:s("Memory not found")})},c=async()=>{if(!r)return;a(!0);const u=await window.electronAPI.memory.update(e.id,r);a(!1),u.ok?o(null):Ie({type:"error",title:s("Save failed"),description:u.error})};return r?n.jsxs("div",{"data-slot":"bot-card",className:"space-y-1.5 rounded-lg border bg-card px-2.5 py-2",children:[n.jsx(Ht,{size:"sm",value:r.title,placeholder:s("Memory title"),onChange:u=>o({...r,title:u.target.value})}),n.jsx(Gs,{rows:5,value:r.content,placeholder:s("Memory content"),onChange:u=>o({...r,content:u.target.value})}),n.jsxs("div",{className:"flex justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",disabled:i,onClick:()=>o(null),children:s("Cancel")}),n.jsxs(fe,{size:"xs",disabled:i||!r.content.trim(),onClick:()=>{c()},children:[i&&n.jsx(_t,{className:"animate-spin"}),s("Save")]})]})]}):n.jsxs("div",{"data-slot":"bot-card",className:"group flex items-start gap-2 rounded-lg border bg-card px-2.5 py-2",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate font-medium text-xs",children:e.title}),n.jsx("div",{className:"line-clamp-3 text-muted-foreground text-xs",children:e.contentSummary})]}),n.jsxs("div",{className:"flex shrink-0 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100",children:[n.jsx("button",{type:"button",title:s("Edit"),"aria-label":s("Edit"),disabled:i,onClick:()=>{l()},className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground",children:i?n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin"}):n.jsx(bs,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",title:s("Delete"),"aria-label":s("Delete"),onClick:()=>{window.electronAPI.memory.delete(e.id).then(u=>{u.ok?t():Ie({type:"error",title:u.error??s("Delete failed")})})},className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-destructive",children:n.jsx(vs,{className:"h-3.5 w-3.5"})})]})]})}function JC({target:e,emptyText:t}){const{t:s}=z(),r="botId"in e?e.botId:void 0,o="chatId"in e?e.chatId:void 0,[i,a]=f.useState(null),[l,c]=f.useState(null),[u,d]=f.useState(!1),m=f.useRef(!1);m.current=l!==null;const h=f.useCallback(async()=>{const g=await window.electronAPI.bots.notes.get(r?{botId:r}:{chatId:o??""});g.ok&&a(g.notes)},[r,o]);f.useEffect(()=>(a(null),c(null),h(),window.electronAPI.bots.onEvent(g=>{g.kind!=="notes"||m.current||(r?!g.chatId:g.chatId===o)&&h()})),[h,r,o]);const p=async()=>{if(!i||l===null)return;d(!0);const g=await window.electronAPI.bots.notes.save({...r?{botId:r}:{chatId:o??""},content:l,version:i.version});if(d(!1),g.ok){a(g.notes),c(null);return}Ie({type:"error",title:g.error==="conflict"?s("Notes were updated elsewhere; reloaded the latest version"):s("Save failed")}),g.error==="conflict"&&(c(null),h())};return i?l!==null?n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Gs,{rows:8,value:l,maxLength:i.maxChars,onChange:g=>c(g.target.value)}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs("span",{className:"mr-auto text-muted-foreground text-xs",children:[l.length," / ",i.maxChars]}),n.jsx(fe,{size:"xs",variant:"ghost",disabled:u,onClick:()=>c(null),children:s("Cancel")}),n.jsx(fe,{size:"xs",disabled:u,onClick:()=>{p()},children:s("Save")})]})]}):n.jsxs("div",{className:"group space-y-1.5",children:[i.content?n.jsx("div",{"data-slot":"bot-card",className:"max-h-64 overflow-y-auto whitespace-pre-wrap rounded-lg border bg-card px-2.5 py-2 text-xs",children:i.content}):n.jsx("p",{className:"text-muted-foreground text-xs",children:t}),n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>c(i.content),children:s("Edit notes")})]}):n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"})}function ZC({value:e,onApply:t}){const{t:s,locale:r}=z(),[o,i]=f.useState(!1),a=async()=>{if(!e.name.trim()||!e.title.trim()){Ie({type:"warning",title:s("Fill in a name and title first.")});return}i(!0);try{const l=await window.electronAPI.bots.suggestPersona({name:e.name,title:e.title,scope:e.scope,persona:e.persona,language:r==="zh"?"zh":"en"});if(!l.ok){Ie({type:"error",title:Su(l,s),...l.detail?{description:l.detail}:{}});return}const{persona:c,scope:u}=l.suggestion,d={persona:e.persona,scope:e.scope};t({persona:c,...u?{scope:u}:{}}),Ie({type:"success",title:s(u?"Persona and responsibilities generated":"Persona generated"),timeout:1e4,actions:[{label:s("Undo"),onClick:()=>t(d)}]})}finally{i(!1)}};return n.jsxs(fe,{size:"xs",variant:"ghost",className:"-my-1 h-6 text-muted-foreground",disabled:o,onClick:()=>{a()},children:[o?n.jsx(_t,{className:"animate-spin"}):n.jsx(Bs,{}),s("Generate with AI")]})}function my(e){const t=Kh(e);if(!t)return;const[s,r,o,i,a]=t.source.split(" ");if(!/^\d+$/u.test(s)||!/^\d+$/u.test(r)||o!=="*"||i!=="*")return;const l={hour:t.hour[0],minute:t.minute[0]};return a==="*"?{kind:"daily",days:[],...l}:a==="1-5"?{kind:"weekdays",days:[],...l}:/^\d+(,\d+)*$/u.test(a)?{kind:"weekly",days:[...new Set(t.dayOfWeek.map(u=>u%7))].sort((u,d)=>u-d),...l}:void 0}function eq(e){const{kind:t,hour:s,minute:r}=e;if(!Number.isInteger(s)||s<0||s>23||!Number.isInteger(r)||r<0||r>59)return;const o=[...new Set(e.days)].filter(a=>Number.isInteger(a)&&a>=0&&a<=6);if(t==="weekly"&&!o.length)return;const i=t==="daily"?"*":t==="weekdays"?"1-5":o.sort().join(",");return`${r} ${s} * * ${i}`}function tq(e){const t={todo:[],doing:[],review:[],done:[],canceled:[],blocked:[]};for(const s of e)t[s.status].push(s);return t.todo.sort((s,r)=>s.seq-r.seq),t.doing.sort((s,r)=>s.seq-r.seq),t.blocked.sort((s,r)=>s.seq-r.seq),t.review.sort((s,r)=>s.seq-r.seq),t.done.sort((s,r)=>r.updatedAt-s.updatedAt),t.canceled.sort((s,r)=>r.updatedAt-s.updatedAt),t}function nq(e){return e.status==="review"&&!!(e.delegationId&&e.assigneeBotId)}function sq(e,t){return e.filter(s=>s.chatId===t).sort((s,r)=>s.createdAt-r.createdAt)}const nc=e=>e.finishedAt??e.createdAt;function rq(e,t){const s=e.filter(o=>o.chatId===t),r=o=>_a(o.state)||Cj(o,e);return{active:s.filter(r).sort((o,i)=>o.createdAt-i.createdAt),completed:s.filter(o=>o.state==="completed").sort((o,i)=>nc(i)-nc(o)),failed:s.filter(o=>["failed","canceled","blocked"].includes(o.state)&&!r(o)).sort((o,i)=>nc(i)-nc(o))}}function oq(e,t,s){const r=new Map(t.map(o=>[o.id,o]));return[...e].sort((o,i)=>o.createdAt-i.createdAt).map(o=>({run:o,record:r.get(o.id),time:o.state==="queued"&&o.startedAt===void 0?{queued:!0,ms:s-o.createdAt}:{queued:!1,ms:(o.finishedAt??s)-(o.startedAt??o.createdAt)}}))}function iq(e,t){const s=qA(e);if(!s)return;const r=t.find(i=>i.id===e.delegationId);if(s.reason==="failed"){const i=Ej(e);return{reason:"failed",...r?{record:r}:{},since:i?.finishedAt??r?.finishedAt??e.updatedAt}}const o=(e.blockedStreak?.[e.assigneeBotId??""]??0)>=GA;return{reason:"need",need:s.need||r?.blocked?.need||"",waitFor:!o&&r?.blocked?.waitFor==="parent"?r.parentBotId:"human",...o?{humanOnly:!0}:{},since:r?.finishedAt??r?.blocked?.at??e.updatedAt}}const aq=["0 9 * * *","0 9 * * 1-5","0 9 * * 1","0 * * * *"];function lq(e,t,s){const r=Kh(e);if(r)return{source:r.source,description:Yh(r,t),next:KA(r,s)}}function cq(e,t){return e.filter(s=>s.archivedAt===void 0&&!s.parentId&&s.members.includes(t)).sort((s,r)=>+(s.kind==="group")-+(r.kind==="group"))}function dq(e){return e.title.trim()?e.prompt.trim()?Kh(e.schedule)?e.chatId?null:"chat":"schedule":"prompt":"title"}function Ed(e,t,s){switch(e){case"invalid":return t("Check the title, prompt and schedule, and that the member is still in the target chat.");case"not-found":return t("This routine no longer exists.");case"unavailable":return t("The member or target chat is archived or unavailable.");case"disabled":return t("Bot mode is off.");case"acl":return Ti("acl",t);case"not-approved":return t("Approve this routine before running it. You can still do a dry run.");case"busy":return t("This routine is already running.");case"blocked":return s?Ti(s,t):t("This routine is blocked. Fix the problem and enable it again.");default:return e}}function Ti(e,t){switch(e){case"executor-missing":return t("The member who runs it was deleted.");case"executor-archived":return t("The member who runs it is archived.");case"chat-missing":return t("The target chat no longer exists.");case"chat-archived":return t("The target chat is archived.");case"not-in-chat":return t("The member who runs it is no longer in the target chat.");case"acl":return t("Delegation permissions do not allow that member to run it.");default:return t("This routine is blocked. Fix the problem and enable it again.")}}function e2(e,t){switch(e){case"ok":return"✓";case"error":return t("Error");case"budget":return t("Over budget");case"skipped-busy":return t("Skipped (still running)");case"interrupted":return t("Interrupted");case"blocked":return t("Blocked");case"skipped":return t("Skipped");default:return t("Running")}}function _x(){const{t:e}=z(),[t,s]=f.useState(!1),r=async(i,a,l)=>{s(!0);try{const c=await a();c.ok?l&&Ie({type:"success",title:l}):Ie({type:"error",title:i,description:Ed(c.error,e,c.reason)})}finally{s(!1)}},o=window.electronAPI.bots.routines;return{busy:t,review:(i,a)=>r(e("Routine not saved"),()=>o.review({botId:i.botId,id:i.id,approve:a})),resume:i=>r(e("Routine not saved"),async()=>{const a=await o.save({botId:i.botId,id:i.id,title:i.title,prompt:i.prompt,schedule:i.schedule,chatId:i.chatId,enabled:!0});return a.ok&&a.routine.status==="blocked"?{ok:!1,error:"blocked",reason:a.routine.blockedReason}:a}),run:(i,a)=>r(e("Routine did not run"),()=>o.runNow({botId:i.botId,id:i.id,dryRun:a}),e(a?"Dry run started":"Routine started"))}}function t2({routine:e}){const{t,locale:s}=z(),r=ie(i=>i.bots),o=e.doneBy?r.find(i=>i.id===e.doneBy):void 0;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"mt-2 font-medium text-sm",children:e.title}),n.jsxs("div",{className:"mt-0.5 text-muted-foreground text-xs",children:[Yh(e.schedule,s),e.doneBy?` · ${t("Done by {{name}}",{name:o?.name??t("Deleted member")})}`:""]}),n.jsx("div",{className:"mt-1 line-clamp-3 whitespace-pre-wrap text-xs",children:e.prompt})]})}function uq({alert:e}){const{t}=z(),s=ie(h=>h.bots),r=ie(h=>h.chats),o=ie(h=>h.setView),{busy:i,review:a,resume:l,run:c}=_x(),{routine:u}=e,d=s.find(h=>h.id===u.botId),m=r.find(h=>h.id===u.chatId);return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx($t,{bot:d,size:"sm"}),n.jsx("span",{className:"text-foreground",children:d?.name??t("Deleted member")}),m?.kind==="group"&&n.jsxs("span",{children:["· ",is(m,s,t)]}),n.jsx(Bx,{routine:u})]}),n.jsx(t2,{routine:u}),e.kind==="blocked"&&n.jsx("div",{className:"mt-1 text-destructive text-xs",children:Ti(u.blockedReason,t)}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[m&&n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>o({kind:"chat",chatId:m.id}),children:t("Go to chat")}),e.kind==="approval"?n.jsxs(n.Fragment,{children:[n.jsx(fe,{size:"xs",variant:"outline",disabled:i,onClick:()=>c(u,!0),children:t("Dry run")}),n.jsx(fe,{size:"xs",variant:"outline",disabled:i,onClick:()=>a(u,!1),children:t("Reject")}),n.jsx(fe,{size:"xs",disabled:i,onClick:()=>a(u,!0),children:t("Approve")})]}):n.jsx(fe,{size:"xs",disabled:i,onClick:()=>l(u),children:t("Enable again")})]})]})}function Bx({routine:e}){const{t}=z(),[s,r]=e.status==="draft"?[t("Pending approval"),"bg-warning/20 text-warning"]:e.status==="blocked"?[t("Blocked"),"bg-destructive/15 text-destructive"]:e.status==="paused"?[t("Paused"),"bg-muted text-muted-foreground"]:[t("Enabled"),"bg-success/15 text-success"];return n.jsx("span",{className:_("rounded px-1.5 text-[11px]",r),children:s})}function fq({text:e,target:t}){const{t:s}=z(),r=ie(l=>l.routines.find(c=>c.id===t.id&&c.botId===t.botId)),{busy:o,review:i,run:a}=_x();return n.jsxs("div",{"data-slot":"bot-card",className:"w-full max-w-md self-center rounded-xl border bg-card px-3 py-2 text-xs",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[n.jsx("span",{className:"min-w-0 flex-1",children:e}),r?n.jsx(Bx,{routine:r}):n.jsx("span",{className:"text-[11px]",children:s("Routine removed")})]}),r&&n.jsx(t2,{routine:r}),r?.status==="draft"&&n.jsxs("div",{className:"mt-2 flex justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",disabled:o,onClick:()=>a(r,!0),children:s("Dry run")}),n.jsx(fe,{size:"xs",variant:"outline",disabled:o,onClick:()=>i(r,!1),children:s("Reject")}),n.jsx(fe,{size:"xs",disabled:o,onClick:()=>i(r,!0),children:s("Approve")})]})]})}const Fx=e=>new Date(e).toLocaleString([],{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});function n2(e,t){switch(e){case"title":return t("Enter a title.");case"prompt":return t("Enter what the member should do.");case"schedule":return t("Invalid cron expression (minute hour day month weekday).");case"chat":return t("Choose a target chat.")}}function mq(e,t){switch(e){case"scheduled":return t("Scheduled");case"manual":return t("Manual");case"catchup":return t("Catch-up");case"dry-run":return t("Dry run")}}function hq(e){if(e.finishedAt===void 0)return"";const t=Math.max(0,Math.round((e.finishedAt-e.startedAt)/1e3));return t<60?` · ${t}s`:` · ${Math.floor(t/60)}m ${t%60}s`}function s2({botId:e,chatId:t}){const{t:s,locale:r}=z(),o=ie(j=>j.chats),i=ie(j=>j.bots),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,m]=f.useState(null),[h,p]=f.useState(null),g=_x(),x=f.useCallback(async()=>{const j=await window.electronAPI.bots.routines.list(e?{botId:e}:{}).catch(()=>null),T=j?.ok?j.routines:[];l(t?sq(T,t):T)},[e,t]);f.useEffect(()=>(l(null),x(),window.electronAPI.bots.onEvent(j=>{j.kind==="routine"&&x()})),[x]);const v=async(j,T)=>{const{id:N,title:S,prompt:I,schedule:k}=j,L=await window.electronAPI.bots.routines.save({botId:j.botId,id:N,title:S,prompt:I,schedule:k,chatId:j.chatId,enabled:T});L.ok?L.routine.status==="blocked"&&Ie({type:"error",title:s("Routine blocked"),description:Ti(L.routine.blockedReason,s)}):Ie({type:"error",title:s("Routine not saved"),description:Ed(L.error,s)}),x()},b=async j=>{m(null);const T=await window.electronAPI.bots.routines.remove({botId:j.botId,id:j.id});T.ok||Ie({type:"error",title:s("Routine not deleted"),description:Ed(T.error,s)}),x()};if(a===null)return n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"});const w=j=>i.find(T=>T.id===j)?.name??s("Deleted member");return n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs(fe,{size:"xs",variant:"outline",onClick:()=>u("new"),children:[n.jsx(Qn,{}),s("New routine")]}),a.length===0&&n.jsx("p",{className:"text-muted-foreground text-xs",children:s("No routines yet")}),a.map(j=>{const T=o.find(k=>k.id===j.chatId),N=j.status==="draft",S=YA(j)&&(j.status==="enabled"||j.status==="paused"),I=T?s("Posts to {{chat}}",{chat:is(T,i,s)}):s("Target chat missing");return n.jsxs("div",{"data-slot":"bot-card",className:_("rounded-lg border bg-card px-2.5 py-2 text-xs",j.status==="paused"&&"opacity-70"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium text-sm",children:j.title}),n.jsx(Bx,{routine:j}),!N&&n.jsx(rr,{checked:j.status==="enabled",onCheckedChange:k=>{v(j,k)},title:j.status==="enabled"?s("Enabled"):s("Paused")})]}),n.jsx("div",{className:"mt-0.5 text-muted-foreground",children:[t?w(j.botId):"",Yh(j.schedule,r),j.doneBy?s("Done by {{name}}",{name:w(j.doneBy)}):"",t?"":I].filter(Boolean).join(" · ")}),j.proposedBy&&N&&n.jsx("div",{className:"mt-0.5 text-warning",children:s("Proposed by {{name}}, waiting for your approval",{name:w(j.proposedBy)})}),j.status==="blocked"&&n.jsx("div",{className:"mt-0.5 text-destructive",children:Ti(j.blockedReason,s)}),n.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-muted-foreground",children:[n.jsx("span",{children:j.lastRunAt?s("Last run {{time}} · {{result}}",{time:Fx(j.lastRunAt),result:e2(j.lastResult,s)}):s("Never run")}),j.missed?n.jsx("span",{className:"rounded bg-warning/20 px-1.5 text-warning",children:s("Missed {{n}} times",{n:j.missed})}):null,!j.catchUp&&n.jsx("span",{children:s("No catch-up")})]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap justify-end gap-1",children:[N?n.jsxs(n.Fragment,{children:[n.jsx(fe,{size:"xs",variant:"ghost",disabled:g.busy,onClick:()=>{g.review(j,!1)},children:s("Reject")}),n.jsx(fe,{size:"xs",disabled:g.busy,onClick:()=>{g.review(j,!0)},children:s("Approve")})]}):n.jsxs(fe,{size:"xs",variant:"ghost",disabled:!S||g.busy,onClick:()=>{g.run(j,!1)},children:[n.jsx(Rj,{}),s("Run now")]}),n.jsxs(fe,{size:"xs",variant:"ghost",disabled:g.busy,title:s("Run once without affecting the schedule"),onClick:()=>{g.run(j,!0)},children:[n.jsx(pj,{}),s("Dry run")]}),n.jsxs(fe,{size:"xs",variant:h===j.id?"secondary":"ghost",onClick:()=>p(h===j.id?null:j.id),children:[n.jsx(Or,{}),s("History")]}),n.jsxs(fe,{size:"xs",variant:"ghost",onClick:()=>u(j),children:[n.jsx(bs,{}),s("Edit")]}),n.jsxs(fe,{size:"xs",variant:"ghost",onClick:()=>m(j),children:[n.jsx(vs,{}),s("Delete")]})]}),h===j.id&&n.jsx(pq,{routine:j})]},j.id)}),c&&n.jsx(vq,{botId:e,chatId:t,routine:c==="new"?void 0:c,onClose:j=>{u(null),j&&x()}}),n.jsx(cs,{open:d!==null,onOpenChange:j=>!j&&m(null),title:s('Delete routine "{{title}}"?',{title:d?.title??""}),description:s("It will no longer run. This cannot be undone."),confirmLabel:s("Delete"),onConfirm:()=>d&&void b(d)})]})}function pq({routine:e}){const{t}=z(),s=ie(l=>l.setView),[r,o]=f.useState(null),{botId:i,id:a}=e;return f.useEffect(()=>{let l=!0;const c=()=>{window.electronAPI.bots.routines.runs({botId:i,id:a}).then(d=>l&&o(d.ok?d.runs:[])).catch(()=>l&&o([]))};c();const u=window.electronAPI.bots.onEvent(d=>{d.kind==="routine"&&c()});return()=>{l=!1,u()}},[i,a]),r===null?n.jsx(_t,{className:"mt-2 h-3.5 w-3.5 animate-spin"}):r.length===0?n.jsx("p",{className:"mt-2 text-muted-foreground",children:t("No runs yet")}):n.jsx("ul",{className:"mt-2 space-y-1 border-t pt-2",children:r.map(l=>n.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 text-muted-foreground",children:[n.jsx("span",{className:"tabular-nums",children:Fx(l.startedAt)}),n.jsx("span",{children:mq(l.trigger,t)}),n.jsxs("span",{className:_(l.result==="ok"&&"text-success",(l.result==="error"||l.result==="blocked"||l.result==="budget")&&"text-destructive"),children:[e2(l.result,t),hq(l)]}),l.conversationId&&n.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>s({kind:"chat",chatId:l.chatId}),children:t("Open chat")}),l.error&&n.jsx("span",{className:"w-full truncate text-destructive",title:l.error,children:l.result==="blocked"?Ti(l.error,t):l.error})]},l.runId))})}const xq=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],hy=e=>String(e).padStart(2,"0");function gq({value:e,onChange:t}){const{t:s,locale:r}=z(),o=my(e),[i,a]=f.useState(!o),[l,c]=f.useState(o??{kind:"daily",days:[1],hour:9,minute:0}),u=lq(e,r,Date.now()),d=p=>{c(p);const g=eq(p);g&&t(g)},m=[{value:"daily",label:s("Every day")},{value:"weekdays",label:s("Weekdays")},{value:"weekly",label:s("Every week on")}],h=()=>{if(!i)return a(!0);const p=my(e);p?c(p):d(l),a(!1)};return n.jsxs("div",{children:[n.jsx(Ot,{hint:i?s("cron: minute hour day month weekday, local time"):void 0,action:n.jsx(fe,{size:"xs",variant:"ghost",onClick:h,children:s(i?"Simple":"Advanced (cron)")}),children:s("Schedule")}),i?n.jsx(Ht,{className:"font-mono",value:e,placeholder:"0 9 * * 1-5",onChange:p=>t(p.target.value)}):n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsxs(Cr,{items:m,value:l.kind,onValueChange:p=>d({...l,kind:p,days:l.days.length?l.days:[1]}),children:[n.jsx(Ir,{className:"w-32",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:m.map(p=>n.jsx(ir,{value:p.value,children:p.label},p.value))})]}),l.kind==="weekly"&&xq.map((p,g)=>{const x=l.days.includes(g);return n.jsx(fe,{size:"xs",variant:x?"default":"outline",onClick:()=>{const v=x?l.days.filter(b=>b!==g):[...l.days,g].sort();v.length&&d({...l,days:v})},children:s(p)},p)}),n.jsx(Ht,{type:"time",className:"w-28",value:`${hy(l.hour)}:${hy(l.minute)}`,onChange:p=>{const[g,x]=p.target.value.split(":").map(Number);Number.isInteger(g)&&Number.isInteger(x)&&d({...l,hour:g,minute:x})}})]}),n.jsx("p",{className:_("mt-1 text-xs",u?"text-muted-foreground":"text-destructive"),children:u?`${u.description} · ${u.next?s("Next run {{time}}",{time:Fx(u.next)}):s("Never runs")}`:n2("schedule",s)})]})}function vq({botId:e,chatId:t,routine:s,onClose:r}){const{t:o}=z(),i=ie(te=>te.chats),a=ie(te=>te.bots),l=f.useMemo(()=>(i.find(V=>V.id===t)?.members??[]).flatMap(V=>{const se=a.find(Ce=>Ce.id===V&&Ce.archivedAt===void 0);return se?[se]:[]}),[i,a,t]),[c,u]=f.useState(s?.botId??e??l[0]?.id??""),d=f.useMemo(()=>cq(i,c),[i,c]),[m,h]=f.useState(s?.title??""),[p,g]=f.useState(s?.prompt??""),[x,v]=f.useState(s?.schedule??aq[0]),[b,w]=f.useState(s?.chatId??t??d[0]?.id??""),[j,T]=f.useState(s?.doneBy??""),[N,S]=f.useState(s?.catchUp??!0),[I,k]=f.useState(null),[L,F]=f.useState(!1),A=te=>{const V=i.find(se=>se.id===te);return V?`${is(V,a,o)} · ${V.kind==="group"?o("Group chat"):o("Private chat")}`:o("Target chat missing")},M=d.some(te=>te.id===b)||!b?d.map(te=>te.id):[b,...d.map(te=>te.id)],R=f.useMemo(()=>(i.find(V=>V.id===b)?.members??[]).flatMap(V=>{const se=a.find(Ce=>Ce.id===V&&Ce.archivedAt===void 0);return se&&se.id!==c?[se]:[]}),[i,a,b,c]),$=[{value:"",label:o("The member itself")},...R.map(te=>({value:te.id,label:te.name}))],U=R.some(te=>te.id===j)?j:"",q=async()=>{if(!c)return k(o("Choose a member."));const te=dq({title:m,prompt:p,schedule:x,chatId:b});if(te)return k(n2(te,o));F(!0),k(null);try{const V=await window.electronAPI.bots.routines.save({botId:c,title:m,prompt:p,schedule:x,chatId:b,catchUp:N,doneBy:U||null,...s?{id:s.id,enabled:s.status!=="paused"}:{}});V.ok?r(!0):k(Ed(V.error,o))}finally{F(!1)}};return n.jsx(cn,{open:!0,onOpenChange:te=>!te&&r(!1),children:n.jsxs(dn,{className:"max-h-[85vh] max-w-lg",children:[n.jsx(un,{children:n.jsx(rn,{children:o(s?"Edit routine":"New routine")})}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:o("Routine title")}),n.jsx(Ht,{value:m,onChange:te=>h(te.target.value)})]}),n.jsxs("div",{children:[n.jsx(Ot,{hint:o("Sent to the member as the task each time it runs"),children:o("Prompt")}),n.jsx(Gs,{rows:4,value:p,onChange:te=>g(te.target.value)})]}),n.jsx(gq,{value:x,onChange:v}),t?n.jsxs("div",{children:[n.jsx(Ot,{children:o("Member")}),n.jsxs(Cr,{items:l.map(te=>({value:te.id,label:te.name})),value:c,disabled:!!s,onValueChange:te=>u(te),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:l.map(te=>n.jsx(ir,{value:te.id,children:te.name},te.id))})]})]}):n.jsxs("div",{children:[n.jsx(Ot,{children:o("Target chat")}),M.length===0?n.jsx("p",{className:"text-muted-foreground text-xs",children:o("This member is not in any chat yet. Start a private chat first.")}):n.jsxs(Cr,{items:M.map(te=>({value:te,label:A(te)})),value:b,onValueChange:te=>w(te),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:M.map(te=>n.jsx(ir,{value:te,children:A(te)},te))})]})]}),R.length>0&&n.jsxs("div",{children:[n.jsx(Ot,{hint:o("Another member of the target chat runs it, as a delegation"),children:o("Done by")}),n.jsxs(Cr,{items:$,value:U,onValueChange:te=>T(te),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:$.map(te=>n.jsx(ir,{value:te.value,children:te.label},te.value||"self"))})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx(Ot,{hint:o("If the app was closed at the scheduled time, run the latest missed one once on startup"),children:o("Catch up missed runs")}),n.jsx(rr,{checked:N,onCheckedChange:S})]}),I&&n.jsx("p",{className:"text-destructive text-sm",children:I})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>r(!1),children:o("Cancel")}),n.jsxs(fe,{size:"sm",disabled:L,onClick:()=>{q()},children:[L&&n.jsx(_t,{className:"animate-spin"}),o("Save")]})]})]})})}function Pf(e,t){return{name:e.name,title:e.title,scope:e.scope,persona:t,color:e.avatar.color,engine:e.engine??null,tools:e.tools,approvalMode:e.approvalMode,skillIds:e.skillIds,mcpServerIds:e.mcpServerIds,canDelegateTo:e.delegation.canDelegateTo,acceptFrom:e.delegation.acceptFrom,memoryEnabled:e.memory.enabled,...$U(e.budget),...VU(e)}}function bq(e){const t=GC(e),s=Lx(e);return!t.ok||!s.ok?null:{name:e.name.trim(),title:e.title.trim(),scope:e.scope.trim(),persona:e.persona,avatar:{color:e.color},engine:e.engine,tools:e.tools,approvalMode:e.approvalMode,skillIds:e.skillIds,mcpServerIds:e.mcpServerIds,delegation:{canDelegateTo:e.canDelegateTo,acceptFrom:e.acceptFrom},memory:{enabled:e.memoryEnabled},budget:t.budget,delegationTimeoutMinutes:s.delegationTimeoutMinutes,maxTokensPerTurn:s.maxTokensPerTurn}}async function yq(e,t){const s=Kc(e),r=s?await fetch(s).then(i=>i.blob()).then(Lj).catch(()=>null):null,o=XA(JA(r??await ZA(e.name,e.avatar.color)),"chara",QA(JSON.stringify(HU(e,t))),["ccv3"]);if(!o)throw new Error("png");eE(new Blob([new Uint8Array(o)],{type:"image/png"}),`${e.name}.png`)}function wq({botId:e,chat:t,onOpenHistory:s}){const{t:r}=z(),o=ie(A=>A.bots.find(M=>M.id===e)),i=ie(A=>A.bots),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,m]=f.useState(!1),[h,p]=f.useState(!1),[g,x]=f.useState(!1),[v,b]=f.useState(null),w=f.useCallback(async()=>{const A=await window.electronAPI.bots.get(e);A.ok&&(ie.getState().upsertBot(A.bot),l(A.persona),u(Pf(A.bot,A.persona)),m(!1))},[e]);f.useEffect(()=>{l(null),u(null),w()},[w]);const j=f.useMemo(()=>o&&a!==null?Pf(o,a):null,[o,a]),T=d&&!!(c&&j&&JSON.stringify(c)!==JSON.stringify(j));if(f.useEffect(()=>{!d&&j&&u(j)},[o?.version]),!o||!c)return n.jsx("div",{className:"flex flex-1 items-center justify-center",children:n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"})});const N=A=>{u(M=>M&&{...M,...A}),m(!0)},S=Xh(c.name,i,r,o.id),I=async A=>{x(!0);try{await Oj(o.id,A)||Ie({type:"error",title:r("Avatar update failed")})}finally{x(!1)}},k=()=>{yq(o,a??"").then(()=>Ie({type:"success",title:r('Persona embedded in the PNG. Restore it in a new member via "Import character card".')})).catch(()=>Ie({type:"error",title:r("Export failed")}))},L=async()=>{const A=bq(c);if(!A){Ie({type:"error",title:Lx(c).ok?r("Budget must be a positive number"):r("Check the per-turn token limit and delegation time limit")});return}p(!0);try{const M=await window.electronAPI.bots.update({botId:o.id,expectedVersion:o.version,draft:A});if(M.ok){ie.getState().upsertBot(M.bot),l(c.persona),u(Pf(M.bot,c.persona)),m(!1);return}Ie({type:"error",title:fa(M.reason,M.error,r),...M.reason==="conflict"?{actions:[{label:r("Refresh"),onClick:()=>{w()}}]}:{}})}finally{p(!1)}},F=async()=>{const A=v;if(b(null),A==="archive"){const R=await window.electronAPI.bots.archive(o.id,!0);R.ok?ie.getState().upsertBot(R.bot):Ie({type:"error",title:fa(R.reason,R.error,r)});return}const M=await window.electronAPI.bots.remove(o.id);if(M.ok){ie.getState().setView(null),await Promise.all([ie.getState().refreshCatalog(),ie.getState().refreshChats()]);return}if(M.reason==="boss"){const R=ie.getState().chats,$=(M.chatIds??[]).map(U=>R.find(q=>q.id===U)).filter(U=>!!U).map(U=>is(U,i,r));Ie({type:"warning",title:r("{{name}} owns group chats",{name:o.name}),description:r("Choose another owner in {{groups}} first.",{groups:$.join("、")})});return}Ie({type:"error",title:fa(M.reason,M.error,r)})};return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 pt-4",children:[n.jsx($t,{bot:{id:o.id,name:c.name||o.name,avatar:{...o.avatar,color:c.color}},size:"lg"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate font-semibold text-base",children:o.name}),n.jsx("div",{className:"truncate text-muted-foreground text-sm",children:o.title}),n.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[n.jsxs(bi,{children:[n.jsxs(yi,{render:n.jsx(fe,{size:"xs",variant:"outline",onClick:k}),children:[n.jsx(zd,{}),r("Export character card")]}),n.jsx(wi,{className:"max-w-72",children:r('Exports a SillyTavern V2 PNG: the avatar as image, persona embedded. Restore it in a new member via "Import character card".')})]}),n.jsx(Mj,{hasImage:!!o.avatar.image,disabled:g,onPick:A=>{I(A)},onRemove:()=>{I(null)}})]})]})]}),n.jsxs(Ud,{defaultValue:"profile",className:"mt-3 flex min-h-0 flex-1 flex-col",children:[n.jsxs(qd,{variant:"underline",className:"shrink-0 px-2",children:[n.jsx(ms,{value:"profile",children:r("Profile")}),n.jsx(ms,{value:"abilities",children:r("Abilities")}),n.jsx(ms,{value:"memory",children:r("Memory")}),n.jsx(ms,{value:"routines",children:r("Routines")}),n.jsx(ms,{value:"history",children:r("History")})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-3",children:[n.jsxs(wr,{value:"profile",className:"space-y-3",children:[n.jsx(JU,{bot:o}),n.jsxs("div",{children:[n.jsx(Ot,{hint:r("Used for @ in groups; must be unique"),children:r("Name")}),n.jsx(Ht,{value:c.name,onChange:A=>N({name:A.target.value})}),S&&n.jsx("p",{className:"mt-1 text-destructive text-xs",children:S})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:r("Title")}),n.jsx(Ht,{value:c.title,onChange:A=>N({title:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Ot,{hint:r("Used for routing and the delegation directory"),children:r("Responsibilities")}),n.jsx(Gs,{rows:2,value:c.scope,onChange:A=>N({scope:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Ot,{action:n.jsx(ZC,{value:c,onApply:N}),children:r("Persona")}),n.jsx(Gs,{rows:8,value:c.persona,onChange:A=>N({persona:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:r("Avatar color")}),n.jsx(Pj,{value:c.color,onChange:A=>N({color:A})})]}),n.jsxs("div",{className:"flex gap-2 border-t pt-3",children:[n.jsxs(fe,{size:"xs",variant:"outline",onClick:()=>b("archive"),children:[n.jsx(lr,{}),r("Archive member")]}),n.jsxs(fe,{size:"xs",variant:"destructive-outline",onClick:()=>b("delete"),children:[n.jsx(vs,{}),r("Delete permanently")]})]})]}),n.jsxs(wr,{value:"abilities",className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:r("Model")}),n.jsx(Dj,{engine:c.engine,onChange:A=>N({engine:A})})]}),n.jsx(YC,{value:c,onChange:N,profile:c,botId:o.id})]}),n.jsxs(wr,{value:"memory",children:[n.jsxs("div",{className:"mb-4",children:[n.jsx(Ot,{hint:r("Injected into every new conversation"),children:r("Core notes")}),n.jsx(JC,{target:{botId:o.id},emptyText:r("No notes yet. Key preferences and facts are summarized here automatically after memories are organized.")})]}),n.jsx(QC,{spaceId:`bot:${o.id}`,emptyText:r("No memories yet")})]}),n.jsx(wr,{value:"routines",children:n.jsx(s2,{botId:o.id})}),n.jsx(wr,{value:"history",children:n.jsx(jq,{chat:t,botId:o.id,onOpen:A=>s(A,o.name)})})]})]}),T&&n.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t bg-muted/50 px-4 py-2.5",children:[n.jsx(fe,{size:"sm",variant:"outline",onClick:()=>{j&&u(j),m(!1)},children:r("Discard")}),n.jsxs(fe,{size:"sm",disabled:h||!!S,onClick:()=>{L()},children:[h&&n.jsx(_t,{className:"animate-spin"}),r("Save")]})]}),n.jsx(cs,{open:v!==null,onOpenChange:A=>!A&&b(null),title:v==="delete"?r("Delete {{name}}?",{name:o.name}):r("Archive {{name}}?",{name:o.name}),description:r(v==="delete"?"The member, their private chats, persona, memories and workspace are deleted. This cannot be undone.":"Archived members stop replying and are hidden from the list. You can restore them later."),confirmLabel:r(v==="delete"?"Delete permanently":"Archive member"),onConfirm:()=>{F()}})]})}function jq({chat:e,botId:t,onOpen:s}){const{t:r}=z(),[o,i]=f.useState(null);return f.useEffect(()=>{let a=!0;return window.electronAPI.bots.chatSessions(e.id).then(l=>{a&&i(l.ok?l.sessions.filter(c=>c.botId===t):[])}),()=>{a=!1}},[e.id,t]),o===null?n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"}):o.length===0?n.jsx("p",{className:"text-muted-foreground text-xs",children:r("No conversations yet")}):n.jsx("div",{className:"space-y-1",children:o.map((a,l)=>n.jsxs("button",{type:"button",onClick:()=>s(a.conversationId),"data-slot":"bot-card-button",className:"flex w-full items-center justify-between rounded-lg border bg-card px-2.5 py-2 text-left text-xs hover:bg-muted",children:[n.jsx("span",{children:r("Conversation {{n}}",{n:o.length-l})}),n.jsx("span",{className:"text-muted-foreground",children:a.current?r("Current"):r("Read-only")})]},a.conversationId))})}function Rd(e,t){switch(e){case"invalid":return t("Check the title and details.");case"disabled":return t("Bot mode is off.");default:return e}}async function r2(e,t,s,r){const o=await window.electronAPI.bots.tasks.reply({chatId:e,id:t,text:s}),i=ie.getState();return i.refreshTasks(e),i.refreshDelegations(),i.refreshInbox(),o.ok||Ie({type:"error",title:r("Reply not sent"),description:Rd(o.error,r)}),o.ok}function zx({placeholder:e,onSend:t,className:s}){const{t:r}=z(),[o,i]=f.useState(""),[a,l]=f.useState(!1),c=Pr(pe(d=>d.keybindings))["send-message"],u=async()=>{const d=o.trim();if(!(!d||a)){l(!0);try{await t(d)&&i("")}finally{l(!1)}}};return n.jsxs("div",{className:_("mt-1.5 flex items-end gap-1",s),children:[n.jsx(Gs,{value:o,rows:1,size:"sm",maxLength:Qh,placeholder:e,"aria-label":e,title:c?`${r("Send")} ${qs(c)}`:void 0,disabled:a,className:"text-xs [&_textarea]:max-h-32 [&_textarea]:min-h-0 [&_textarea]:resize-none",onChange:d=>i(d.target.value),onKeyDown:d=>{!d.nativeEvent.isComposing&&Sj(d,c)&&(d.preventDefault(),u())}}),n.jsx(fe,{size:"icon-sm",variant:o.trim()?"default":"ghost","aria-label":r("Send reply"),disabled:!o.trim()||a,onClick:()=>{u()},children:a?n.jsx(_t,{className:"animate-spin"}):n.jsx(cu,{})})]})}function o2(e,t){switch(e){case"append":return t("Appended");case"reply":return t("Resumed after reply");case"rework":return t("Rework");case"retry":return t("Retry");default:return t("Delegated")}}const i2=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),a2=(e,t)=>e.ok===void 0?t("Processing"):e.ok?t("Delivered"):t("Not delivered");function kq({appends:e}){const{t}=z();return n.jsx("ul",{className:"mt-0.5 ml-6 space-y-0.5",children:e.map(s=>n.jsxs("li",{className:"flex items-center gap-1.5 text-muted-foreground",children:[n.jsx("span",{className:"shrink-0 tabular-nums",children:i2(s.at)}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",title:s.text,children:s.text}),n.jsx("span",{className:_("shrink-0 rounded px-1.5 text-[11px]",s.ok===void 0?"bg-info/15 text-info":s.ok?"bg-success/15 text-success":"bg-destructive/15 text-destructive"),children:a2(s,t)})]},s.deliveryId))})}function Nq({runs:e,bots:t,onOpenConversation:s}){const{t:r}=z(),o=ie(p=>p.delegations),i=ku(e.some(p=>_a(p.state))),[a,l]=f.useState(!1),[c,u]=f.useState(null),d=oq(e,o,i),m=a?d:d.slice(-5),h=p=>t.get(p)?.name??r("Deleted member");return n.jsxs("section",{className:"mt-1.5 border-t pt-1.5",children:[n.jsxs("h5",{className:"mb-1 text-[11px] text-muted-foreground",children:[r("Run history")," · ",d.length]}),n.jsx("ul",{className:"space-y-1",children:m.map(({run:p,record:g,time:x})=>{const v=p.state==="failed"?Dl(g??p,r):void 0,b=g?.appends??[];return n.jsxs("li",{className:_(p.nested&&"ml-3 border-l pl-2"),children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-muted-foreground",children:[n.jsx($t,{bot:t.get(p.botId),size:"xs"}),n.jsx("span",{className:"text-foreground",children:h(p.botId)}),n.jsxs("span",{children:["· ",p.nested?r("Sub-delegation"):o2(p.trigger,r)]}),x.queued?n.jsx("span",{className:"rounded bg-info/15 px-1.5 text-[11px] text-info",children:r("Queued {{time}}",{time:Dr(x.ms)})}):n.jsxs(n.Fragment,{children:[n.jsx(ju,{state:p.state,interrupted:p.failure==="interrupted"}),n.jsx("span",{children:Dr(x.ms)})]}),p.appends&&n.jsx("button",{type:"button","aria-expanded":c===p.id,disabled:!b.length,title:b.map(w=>`${i2(w.at)} ${w.text} · ${a2(w,r)}`).join(`
|
|
89
|
-
`),onClick:()=>u(c===p.id?null:p.id),className:"rounded px-1 text-info hover:bg-info/10 disabled:hover:bg-transparent",children:r("+{{n}} appended",{n:p.appends})}),n.jsx("span",{className:"flex-1"}),g&&n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>s(g.childConversationId,r("{{from}} → {{to}} · Delegation",{from:h(g.parentBotId),to:h(g.targetBotId)})),children:r("View process")})]}),c===p.id&&b.length>0&&n.jsx(kq,{appends:b}),v&&n.jsx("div",{className:"mt-0.5 line-clamp-2 whitespace-pre-wrap text-destructive",children:v})]},p.id)})}),d.length>m.length&&n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>l(!0),children:r("Show all ({{n}})",{n:d.length})})]})}const mh=5,Sq=e=>new Date(e).toLocaleString([],{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});function yr({title:e,count:t,limit:s,children:r}){const{t:o}=z(),[i,a]=f.useState(!1),l=s&&!i?Math.min(s,t):t;return n.jsxs("section",{className:"mt-4 first:mt-0",children:[n.jsxs("h4",{className:"mb-1.5 font-medium text-[11px] text-muted-foreground uppercase tracking-wide",children:[e," · ",t]}),n.jsx("div",{className:"space-y-1.5",children:r(l)}),t>l&&n.jsx(fe,{size:"xs",variant:"ghost",className:"mt-1",onClick:()=>a(!0),children:o("Show all ({{n}})",{n:t})})]})}function Cq({chat:e,onOpenConversation:t}){const{t:s}=z(),r=ie(k=>k.tasks[e.id]),o=ie(k=>k.bots),i=ie(k=>k.delegations),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,m]=f.useState(null),h=ie(k=>k.taskFocus),[p,g]=f.useState(null),x=f.useRef(null),v=ku(!!r?.some(k=>k.status==="blocked")),b=f.useMemo(()=>new Map(o.map(k=>[k.id,k])),[o]),w=e.members.flatMap(k=>{const L=b.get(k);return L&&L.archivedAt===void 0?[L]:[]});f.useEffect(()=>{ie.getState().refreshTasks(e.id)},[e.id]),f.useEffect(()=>{!h||h.chatId!==e.id||!r||(ie.getState().clearTaskFocus(h.nonce),r.some(k=>k.id===h.taskId)&&(g(h.taskId),requestAnimationFrame(()=>x.current?.querySelector(`[data-task-id="${CSS.escape(h.taskId)}"]`)?.scrollIntoView({block:"center",behavior:"smooth"}))))},[h,r,e.id]),f.useEffect(()=>{if(!p)return;const k=setTimeout(()=>g(null),2e3);return()=>clearTimeout(k)},[p]);const j=async(k,L)=>{const F=await k();F.ok||Ie({type:"error",title:L,description:Rd(F.error??"",s)}),ie.getState().refreshTasks(e.id)},T=window.electronAPI.bots.tasks,N=k=>({chatId:e.id,id:k.id});if(!r)return n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"});const S=tq(r),I=k=>n.jsx(Iq,{task:k,bots:b,members:w,onOpenConversation:t,block:iq(k,i),now:v,highlighted:p===k.id,onEdit:()=>l(k),onAssign:L=>{j(()=>T.assign({...N(k),botId:L}),s("Task not assigned"))},onComplete:()=>{j(()=>T.complete(N(k)),s("Task not updated"))},onAccept:()=>{j(()=>T.review({...N(k),accept:!0}),s("Task not updated"))},onReturn:L=>m({task:k,rework:L}),onCancel:()=>{j(()=>T.cancel(N(k)),s("Task not updated"))},onDelete:()=>u(k),onReply:L=>r2(e.id,k.id,L,s)},k.id);return n.jsxs("div",{ref:x,children:[n.jsxs(fe,{size:"xs",variant:"outline",className:"mb-3",onClick:()=>l("new"),children:[n.jsx(Qn,{}),s("New task")]}),r.length===0&&n.jsx("p",{className:"text-muted-foreground text-xs",children:s("No tasks yet. Members can also add and claim tasks with the board tool.")}),S.todo.length>0&&n.jsx(yr,{title:s("To do"),count:S.todo.length,children:()=>S.todo.map(I)}),S.doing.length>0&&n.jsx(yr,{title:s("Doing"),count:S.doing.length,children:()=>S.doing.map(I)}),S.blocked.length>0&&n.jsx(yr,{title:s("Stuck tasks"),count:S.blocked.length,children:()=>S.blocked.map(I)}),S.review.length>0&&n.jsx(yr,{title:s("Awaiting review"),count:S.review.length,children:()=>S.review.map(I)}),S.done.length>0&&n.jsx(yr,{title:s("Completed"),count:S.done.length,limit:mh,children:k=>S.done.slice(0,k).map(I)}),S.canceled.length>0&&n.jsx(yr,{title:s("Canceled"),count:S.canceled.length,limit:0,children:k=>S.canceled.slice(0,k).map(I)}),a&&n.jsx(Eq,{chatId:e.id,task:a==="new"?void 0:a,onClose:k=>{l(null),k&&ie.getState().refreshTasks(e.id)}}),d&&n.jsx(Aq,{task:d.task,assignee:b.get(d.task.assigneeBotId??"")?.name??s("Deleted member"),rework:d.rework,onClose:()=>m(null),onReturn:k=>T.review({...N(d.task),accept:!1,reason:k,...d.rework?{rework:!0}:{}}).then(L=>(L.ok&&(m(null),ie.getState().refreshTasks(e.id)),L.ok?null:Rd(L.error,s)))}),n.jsx(cs,{open:c!==null,onOpenChange:k=>!k&&u(null),title:s("Delete task #{{n}}?",{n:c?.seq??""}),description:s("The task is removed from the board. This cannot be undone."),confirmLabel:s("Delete"),onConfirm:()=>{const k=c;u(null),k&&j(()=>T.remove(N(k)),s("Task not deleted"))}})]})}function Iq({task:e,bots:t,members:s,onOpenConversation:r,onEdit:o,onAssign:i,onComplete:a,onAccept:l,onReturn:c,onCancel:u,onDelete:d,onReply:m,block:h,now:p,highlighted:g}){const{t:x}=z(),v=e.status==="todo"||e.status==="doing"||e.status==="blocked",b=e.status==="review",w=Ej(e),j=e.assigneeBotId?t.get(e.assigneeBotId):void 0,T=e.createdBy==="human"?x("You"):t.get(e.createdBy)?.name??x("Deleted member");return n.jsxs("div",{"data-slot":"bot-card","data-task-id":e.id,className:_("group rounded-lg border bg-card px-2.5 py-2 text-xs transition-shadow",!v&&!b&&"opacity-75",g&&"ring-2 ring-brand/60"),children:[n.jsxs("div",{className:"flex items-start gap-1.5",children:[n.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["#",e.seq]}),n.jsx("span",{className:"min-w-0 flex-1 break-words font-medium text-sm",children:e.title}),n.jsxs(mr,{children:[n.jsx(hr,{className:"rounded p-1 text-muted-foreground opacity-0 hover:bg-muted group-hover:opacity-100 data-popup-open:opacity-100",children:n.jsx(kl,{className:"h-3.5 w-3.5"})}),n.jsxs(pr,{align:"end",children:[n.jsxs(Cn,{onClick:o,children:[n.jsx(bs,{}),x("Edit")]}),v&&(!e.delegationId||e.status==="blocked"||w)&&s.length>0&&n.jsxs(Bj,{children:[n.jsxs(Fj,{children:[n.jsx(Ya,{}),e.assigneeBotId?x("Reassign to"):x("Assign to")]}),n.jsx(zj,{children:s.map(N=>n.jsxs(Cn,{disabled:N.id===e.assigneeBotId,onClick:()=>i(N.id),children:[n.jsx($t,{bot:N,size:"xs"}),N.name]},N.id))})]}),v&&!w&&n.jsxs(Cn,{onClick:a,children:[n.jsx(On,{}),x("Mark done")]}),(v||b)&&n.jsxs(Cn,{onClick:u,children:[n.jsx(Jt,{}),x("Cancel task")]}),n.jsx(Ri,{}),n.jsxs(Cn,{variant:"destructive",onClick:d,children:[n.jsx(vs,{}),x("Delete")]})]})]})]}),e.detail&&n.jsx("div",{className:"mt-1 line-clamp-3 whitespace-pre-wrap text-muted-foreground",children:e.detail}),e.result&&n.jsx("div",{className:_("mt-1 rounded px-1.5 py-1 text-foreground",e.status!=="done"&&e.check?.passed===!1?"bg-destructive/10":"bg-success/10"),children:n.jsx("div",{className:"line-clamp-3 whitespace-pre-wrap",children:e.result})}),e.returnReason&&n.jsx("div",{className:"mt-1 rounded bg-warning/10 px-1.5 py-1 text-foreground",children:n.jsx("div",{className:"line-clamp-3 whitespace-pre-wrap",children:x("Returned: {{reason}}",{reason:e.returnReason})})}),h&&n.jsx(Tq,{block:h,now:p,assignee:j,bots:t,members:s,assigneeBotId:e.assigneeBotId,onRetry:()=>w&&Pa(w.id,x),onAssign:i,onCancel:u,onReply:m}),!h&&(b||e.status==="doing"&&e.delegationId)&&n.jsx(zx,{placeholder:x(b?"Comment…":"Add to the current run…"),onSend:m}),e.check&&n.jsx(VC,{check:e.check,className:"mt-1"}),b&&n.jsxs("div",{className:"mt-1.5 flex gap-1.5",children:[n.jsxs(fe,{size:"xs",onClick:l,children:[n.jsx(On,{}),x("Accept result")]}),n.jsxs(fe,{size:"xs",variant:"outline",onClick:()=>c(!1),children:[n.jsx(Ka,{}),x("Return")]}),nq(e)&&n.jsxs(fe,{size:"xs",variant:"outline",onClick:()=>c(!0),children:[n.jsx(Jh,{}),x("Return for rework")]})]}),n.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-muted-foreground",children:[j||e.assigneeBotId?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx($t,{bot:j,size:"xs"}),j?.name??x("Deleted member")]}):n.jsx("span",{children:x("Unassigned")}),e.delegationId&&n.jsxs("span",{children:["· ",x("Delegation")]}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{title:x("Created by {{name}}",{name:T}),children:Sq(e.updatedAt)})]}),e.runs&&e.runs.length>0&&n.jsx(Nq,{runs:e.runs,bots:t,onOpenConversation:r})]})}function Tq({block:e,now:t,assignee:s,assigneeBotId:r,bots:o,members:i,onRetry:a,onAssign:l,onCancel:c,onReply:u}){const{t:d}=z(),m=s?.name??d("Deleted member"),h=d("Stuck for {{time}}",{time:Dr(t-e.since)});if(e.reason==="need"){const g=e.waitFor==="human"?d("Waiting for your reply"):d("Waiting for {{name}} to reply",{name:o.get(e.waitFor)?.name??d("Deleted member")});return n.jsxs("div",{className:"mt-1.5 rounded-md border border-warning/30 bg-warning/10 px-2 py-1.5 text-foreground",children:[n.jsx("div",{className:"line-clamp-4 whitespace-pre-wrap font-medium",children:d("Blocked · needs: {{need}}",{need:e.need})}),n.jsxs("div",{className:"mt-0.5 text-muted-foreground",children:[g," · ",h]}),e.humanOnly&&n.jsx("div",{className:"mt-0.5 text-muted-foreground",children:d("Stuck several times in a row; only you can answer now.")}),n.jsx(zx,{placeholder:d("Answer {{name}}; they continue after your reply…",{name:m}),onSend:u})]})}const p=e.record?.state==="failed"&&Dl(e.record,d)||d("Failed");return n.jsxs("div",{className:"mt-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-2 py-1.5 text-foreground",children:[n.jsx("div",{className:"line-clamp-4 whitespace-pre-wrap font-medium",children:d("Blocked · run failed: {{reason}}",{reason:p})}),n.jsxs("div",{className:"mt-0.5 text-muted-foreground",children:[d("Waiting for you to handle it")," · ",h]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[n.jsxs(fe,{size:"xs",variant:"outline",onClick:a,children:[n.jsx(Mr,{}),d("Retry")]}),i.length>0&&n.jsxs(mr,{children:[n.jsxs(hr,{render:n.jsx(fe,{size:"xs",variant:"outline"}),children:[n.jsx(Ya,{}),d("Reassign")]}),n.jsx(pr,{align:"start",children:i.map(g=>n.jsxs(Cn,{disabled:g.id===r,onClick:()=>l(g.id),children:[n.jsx($t,{bot:g,size:"xs"}),g.name]},g.id))})]}),n.jsxs(fe,{size:"xs",variant:"outline",onClick:c,children:[n.jsx(Jt,{}),d("Cancel task")]})]})]})}function Aq({task:e,assignee:t,rework:s,onClose:r,onReturn:o}){const{t:i}=z(),[a,l]=f.useState(""),[c,u]=f.useState(null),[d,m]=f.useState(!1),h=async()=>{if(!a.trim())return u(i("Enter a reason."));m(!0);try{u(await o(a.trim()))}finally{m(!1)}};return n.jsx(cn,{open:!0,onOpenChange:p=>!p&&r(),children:n.jsxs(dn,{className:"max-w-lg",children:[n.jsx(un,{children:n.jsx(rn,{children:s?i("Return task #{{n}} for rework",{n:e.seq}):i("Return task #{{n}}",{n:e.seq})})}),n.jsxs(In,{className:"space-y-2",children:[n.jsx(Ot,{children:i("Reason for returning")}),n.jsx(Gs,{rows:4,autoFocus:!0,value:a,maxLength:Qh,onChange:p=>l(p.target.value)}),n.jsx("p",{className:"text-muted-foreground text-xs",children:s?i("{{name}} continues in the same conversation with this reason, and the result comes back for review.",{name:t}):i("The task goes back to To do with this reason and can be reassigned.")}),c&&n.jsx("p",{className:"text-destructive text-sm",children:c})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:r,children:i("Cancel")}),n.jsxs(fe,{size:"sm",disabled:d,onClick:()=>{h()},children:[d&&n.jsx(_t,{className:"animate-spin"}),i(s?"Return for rework":"Return")]})]})]})})}function Eq({chatId:e,task:t,onClose:s}){const{t:r}=z(),[o,i]=f.useState(t?.title??""),[a,l]=f.useState(t?.detail??""),[c,u]=f.useState(t?.check?.text??""),[d,m]=f.useState(null),[h,p]=f.useState(!1),g=async()=>{if(!o.trim())return m(r("Enter a title."));p(!0);try{const x=await window.electronAPI.bots.tasks.save({chatId:e,title:o.trim(),detail:a.trim(),check:c.trim(),...t?{id:t.id}:{}});x.ok?s(!0):m(Rd(x.error,r))}finally{p(!1)}};return n.jsx(cn,{open:!0,onOpenChange:x=>!x&&s(!1),children:n.jsxs(dn,{className:"max-w-lg",children:[n.jsx(un,{children:n.jsx(rn,{children:t?r("Edit task #{{n}}",{n:t.seq}):r("New task")})}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:r("Task title")}),n.jsx(Ht,{value:o,maxLength:tE,onChange:x=>i(x.target.value)})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:r("Details")}),n.jsx(Gs,{rows:4,value:a,maxLength:Qh,onChange:x=>l(x.target.value)})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:r("Acceptance check (optional)")}),n.jsx(Ht,{value:c,maxLength:nE,onChange:x=>u(x.target.value)}),n.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:r("Done only when the member's tool output contains this text, e.g. a command printing ALL_TESTS_PASS.")})]}),d&&n.jsx("p",{className:"text-destructive text-sm",children:d})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>s(!1),children:r("Cancel")}),n.jsxs(fe,{size:"sm",disabled:h,onClick:()=>{g()},children:[h&&n.jsx(_t,{className:"animate-spin"}),r("Save")]})]})]})})}function Rq({chat:e,onOpenConversation:t}){const{t:s}=z(),r=ie(c=>c.delegations),o=ie(c=>c.bots),i=f.useMemo(()=>new Map(o.map(c=>[c.id,c])),[o]),a=f.useMemo(()=>rq(r,e.id),[r,e.id]),l=c=>n.jsx(Nu,{record:c,retried:_j(c,r),bots:i,onOpenConversation:t},c.id);return!a.active.length&&!a.completed.length&&!a.failed.length?n.jsx("p",{className:"text-muted-foreground text-xs",children:s("No delegations in this group yet")}):n.jsxs("div",{children:[a.active.length>0&&n.jsx(yr,{title:s("In progress"),count:a.active.length,children:()=>a.active.map(l)}),a.completed.length>0&&n.jsx(yr,{title:s("Completed"),count:a.completed.length,limit:mh,children:c=>a.completed.slice(0,c).map(l)}),a.failed.length>0&&n.jsx(yr,{title:s("Failed · interrupted · canceled"),count:a.failed.length,limit:mh,children:c=>a.failed.slice(0,c).map(l)})]})}const Mq=(e,t)=>e.workspace.kind===t.kind&&(t.kind!=="project"||e.workspace.kind==="project"&&e.workspace.projectId===t.projectId);function l2({chat:e,className:t}){const{t:s}=z(),r=pe(p=>p.projects),o=ie(p=>p.bots),i=ie(p=>p.upsertChat),[a,l]=f.useState(!1),[c,u]=f.useState(null),d=$j(e,r,o,s),m=[e.kind==="direct"?{input:{kind:"member-home"},label:s("Member's own workspace")}:{input:{kind:"chat-home"},label:s("Standalone workspace")},...Gd(r).map(p=>({input:{kind:"project",projectId:p.id},label:qn(p)}))],h=async p=>{const g=await window.electronAPI.bots.updateChat({chatId:e.id,expectedVersion:e.version,workspace:p});g.ok?i(g.chat):Ie({type:"error",title:ds(g.error,s)})};return n.jsxs(n.Fragment,{children:[n.jsxs(Ms,{open:a,onOpenChange:l,children:[n.jsxs(Ps,{className:_("flex h-7 min-w-0 max-w-56 @max-[28rem]:max-w-32 @max-[21rem]:max-w-24 items-center gap-1.5 whitespace-nowrap rounded-md border px-2 text-muted-foreground text-xs transition-colors hover:bg-muted hover:text-foreground",t),title:s("Workspace"),children:[n.jsx(lu,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"truncate",children:d}),n.jsx(Fn,{className:"h-3 w-3 shrink-0 opacity-60"})]}),n.jsxs(Ds,{side:"bottom",align:"end",className:"w-64 [&_[data-slot=popover-viewport]]:p-1",children:[n.jsxs("button",{type:"button",onClick:()=>{l(!1),window.electronAPI.bots.openWorkspace({chatId:e.id}).then(p=>{p.ok||Ie({type:"error",title:ds(p.error,s)})})},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted",children:[n.jsx(Lr,{className:"h-3.5 w-3.5 shrink-0"}),s("Open folder")]}),n.jsx("div",{className:"my-1 border-t"}),n.jsx("div",{className:"px-2 py-1 text-[11px] text-muted-foreground",children:s("Change workspace")}),n.jsx("div",{className:"max-h-64 overflow-y-auto",children:m.map(p=>{const g=Mq(e,p.input);return n.jsxs("button",{type:"button",onClick:()=>{l(!1),g||u(p.input)},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:p.label}),g&&n.jsx(On,{className:"h-3.5 w-3.5 shrink-0 text-brand"})]},p.input.kind==="project"?p.input.projectId:p.input.kind)})})]})]}),n.jsx(cs,{open:c!==null,onOpenChange:p=>!p&&u(null),title:s("Change workspace?"),description:s("Members start new conversations in the new workspace. Earlier conversations stay readable in history."),confirmLabel:s("Change"),onConfirm:()=>{const p=c;u(null),p&&h(p)}})]})}function bo({title:e,children:t}){return n.jsxs("section",{className:"mt-5",children:[n.jsx("h4",{className:"mb-1.5 font-medium text-[11px] text-muted-foreground uppercase tracking-wide",children:e}),t]})}function Df({label:e,value:t}){return n.jsxs("div",{className:"flex justify-between gap-3 border-b border-dashed py-1.5 text-xs",children:[n.jsx("span",{className:"shrink-0 text-muted-foreground",children:e}),n.jsx("span",{className:"min-w-0 truncate text-right",children:t})]})}async function c2(e,t){const s={};for(const r of e.members){const o=await window.electronAPI.bots.get(r);if(!o.ok)return null;s[r]=o.persona}return iE(e,t,s,new Date().toISOString())}async function Pq(e,t){const s=await c2(e,t);if(!s)return!1;const r=URL.createObjectURL(new Blob([JSON.stringify(s,null,2)],{type:"application/json"})),o=document.createElement("a");return o.href=r,o.download=`${e.title||"team"}.team.json`,o.click(),URL.revokeObjectURL(r),!0}async function Dq(e,t){const s=await c2(e,t),r=s&&sE(rE(s.team));return r?oE(o=>({...o,teams:aE(o.teams,r,crypto.randomUUID())})):!1}function Oq({chat:e,thread:t=e,onOpenConversation:s}){const{t:r}=z(),o=ie(R=>R.bots),i=ie(R=>R.runtime[t.id]),a=ie(R=>R.upsertChat),l=ie(R=>R.openDirect),c=pe(R=>R.projects),u=f.useMemo(()=>new Map(o.map(R=>[R.id,R])),[o]),[d,m]=f.useState(e.title),[h,p]=f.useState(String(e.routing.maxHops)),[g,x]=f.useState(String(e.routing.maxTurnsPerBot)),[v,b]=f.useState(!1),[w,j]=f.useState("info"),T=ie(R=>R.taskFocus);f.useEffect(()=>{T?.chatId===e.id&&j("board")},[T,e.id]),f.useEffect(()=>{m(e.title),p(String(e.routing.maxHops)),x(String(e.routing.maxTurnsPerBot))},[e.title,e.routing.maxHops,e.routing.maxTurnsPerBot]);const N=async R=>{const $=await window.electronAPI.bots.updateChat({chatId:e.id,expectedVersion:e.version,...R});$.ok?a($.chat):(Ie({type:"error",title:ds($.error,r)}),ie.getState().refreshChats())},S=e.members.map(R=>({id:R,bot:u.get(R)})),I=e.routing.muted??[],k=o.filter(R=>!R.archivedAt&&!e.members.includes(R.id)),L=R=>R?u.get(R)?.name??"?":"—",F=e.workspace.kind==="project"?c.find(R=>e.workspace.kind==="project"&&R.id===e.workspace.projectId):void 0,A=h!==String(e.routing.maxHops)||g!==String(e.routing.maxTurnsPerBot),M=[{value:"boss",label:r("Group owner replies")},{value:"smart",label:r("Smart pick")}];return n.jsxs(Ud,{value:w,onValueChange:R=>j(String(R)),className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs(qd,{variant:"underline",className:"shrink-0 px-2 pt-2",children:[n.jsx(ms,{value:"info",children:r("Group info")}),n.jsx(ms,{value:"board",children:r("Task board")}),n.jsx(ms,{value:"delegations",children:r("Delegations")}),n.jsx(ms,{value:"routines",children:r("Routines")})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:[n.jsx(wr,{value:"board",children:n.jsx(Cq,{chat:e,onOpenConversation:s})}),n.jsx(wr,{value:"delegations",children:n.jsx(Rq,{chat:t,onOpenConversation:s})}),n.jsx(wr,{value:"routines",children:n.jsx(s2,{chatId:e.id})}),n.jsxs(wr,{value:"info",children:[n.jsx(Ht,{className:"mt-2",value:d,placeholder:r("Group name"),onChange:R=>m(R.target.value),onBlur:()=>d.trim()!==e.title&&void N({title:d.trim()}),onKeyDown:R=>R.key==="Enter"&&R.currentTarget.blur()}),n.jsxs(bo,{title:r("Members"),children:[S.map(({id:R,bot:$})=>n.jsxs("div",{className:"group flex items-center gap-2 rounded-lg py-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{l(R)},className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx(qC,{chatId:t.id,botId:R,bot:$}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[n.jsx("span",{className:"truncate",children:$?.name??r("Deleted member")}),e.bossBotId===R&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:r("Owner")}),I.includes(R)&&n.jsxs("span",{title:r("Replies only when @-mentioned by name"),className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[n.jsx(xd,{className:"h-2.5 w-2.5"}),r("Muted")]})]}),n.jsx("div",{className:"truncate text-muted-foreground text-xs",children:$?.scope||$?.title})]})]}),n.jsxs(mr,{children:[n.jsx(hr,{className:"rounded p-1 text-muted-foreground opacity-0 hover:bg-muted group-hover:opacity-100 data-popup-open:opacity-100",children:n.jsx(kl,{className:"h-3.5 w-3.5"})}),n.jsxs(pr,{align:"end",children:[n.jsxs(Cn,{disabled:e.bossBotId===R,onClick:()=>{N({bossBotId:R})},children:[n.jsx(Vj,{}),r("Make owner")]}),n.jsxs(Cn,{disabled:e.bossBotId===R,onClick:()=>{N({routing:{muted:I.includes(R)?I.filter(U=>U!==R):[...I,R]}})},children:[n.jsx(xd,{}),I.includes(R)?r("Unmute"):r("Mute")]}),n.jsxs(Cn,{disabled:e.bossBotId===R||e.members.length<=2,onClick:()=>{N({members:e.members.filter(U=>U!==R)})},children:[n.jsx(aF,{}),r("Remove from group")]})]})]})]},R)),n.jsxs(Ms,{open:v,onOpenChange:b,children:[n.jsxs(Ps,{disabled:k.length===0,className:"mt-1 flex h-7 items-center gap-1 rounded-md border px-2 text-muted-foreground text-xs hover:bg-muted hover:text-foreground disabled:opacity-50",children:[n.jsx(Qn,{className:"h-3.5 w-3.5"}),r("Add member")]}),n.jsx(Ds,{side:"bottom",align:"start",className:"w-56 [&_[data-slot=popover-viewport]]:p-1",children:k.map(R=>n.jsxs("button",{type:"button",onClick:()=>{b(!1),N({members:[...e.members,R.id]})},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted",children:[n.jsx($t,{bot:R,size:"sm"}),n.jsx("span",{className:"min-w-0 truncate",children:R.name})]},R.id))})]})]}),n.jsxs(bo,{title:r("Reply queue"),children:[n.jsx(Df,{label:r("Current"),value:i?.current?`${L(i.current)}(${r("relay {{n}}/{{max}}",{n:i.hops,max:e.routing.maxHops})})`:i?.routing?r("Choosing who replies…"):"—"}),n.jsx(Df,{label:r("Waiting"),value:i?.queue.length?i.queue.map(R=>L(R)).join("、"):"—"}),n.jsx(Df,{label:r("Per-member limit"),value:r("{{n}} replies",{n:e.routing.maxTurnsPerBot})})]}),n.jsx(bo,{title:r("Workspace"),children:n.jsxs("div",{"data-slot":"bot-card",className:"rounded-lg border bg-card px-2.5 py-2",children:[n.jsx(l2,{chat:e,className:"w-full max-w-none"}),n.jsxs("p",{className:"mt-1.5 text-muted-foreground text-xs",children:[F?`${F.path} · `:"",r("Shared by all members")]})]})}),n.jsxs(bo,{title:r("Routing limits"),children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:r("Without @")}),n.jsxs(Cr,{items:M,value:e.routing.mode,onValueChange:R=>{R!==e.routing.mode&&N({routing:{mode:R}})},children:[n.jsx(Ir,{size:"sm",className:"w-40",children:n.jsx(Tr,{})}),n.jsx(Ar,{children:M.map(R=>n.jsx(ir,{value:R.value,children:R.label},R.value))})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:r("@ relay limit")}),n.jsx(Ht,{type:"number",min:1,max:20,value:h,onChange:R=>p(R.target.value)})]}),n.jsxs("label",{className:"space-y-1",children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:r("Replies per member")}),n.jsx(Ht,{type:"number",min:1,max:10,value:g,onChange:R=>x(R.target.value)})]})]}),A&&n.jsx(fe,{size:"xs",className:"mt-2",onClick:()=>{N({routing:{maxHops:Math.round(Number(h))||e.routing.maxHops,maxTurnsPerBot:Math.round(Number(g))||e.routing.maxTurnsPerBot}})},children:r("Save")})]}),n.jsx(bo,{title:r("Group notes"),children:n.jsx(JC,{target:{chatId:e.id},emptyText:r("No group notes yet. Group conventions and decisions are summarized here automatically after memories are organized.")})}),n.jsx(bo,{title:r("Group memory"),children:n.jsx(QC,{spaceId:`chat:${e.id}`,emptyText:r("No group memories yet")})}),n.jsxs(bo,{title:r("Team"),children:[n.jsxs(fe,{size:"xs",variant:"outline",onClick:()=>{Pq(e,o).then(R=>R||Ie({type:"error",title:r("Export failed")}))},children:[n.jsx(zd,{}),r("Export team")]}),n.jsxs(fe,{size:"xs",variant:"outline",className:"ml-1.5",onClick:()=>{Dq(e,o).then(R=>Ie(R?{type:"success",title:r("Saved as team template")}:{type:"error",title:r("Could not save as team template")}))},children:[n.jsx(f_,{}),r("Save as team template")]}),n.jsx("p",{className:"mt-1.5 text-muted-foreground text-xs",children:r("Group settings and member personas only. Memory, sessions, timeline, tasks, routines, models, skills and MCP are not included.")})]})]})]})]})}function Lq(e,t=0){const s=new Map;for(const r of e)if(!(r.seq<=t)&&((r.kind==="human"||r.newConversation)&&s.clear(),r.kind==="bot"&&r.botId&&s.delete(r.botId),r.failure&&s.set(r.failure.botId,r.id),r.retryOf))for(const[o,i]of s)i===r.retryOf&&s.delete(o);return new Set(s.values())}function _q(e,t){const s=new RegExp(`#${t}(?!\\d)`).exec(e);if(!s)return;const r=s.index+s[0].length;return[e.slice(0,s.index),s[0],e.slice(r)]}function Bq(e,t){const s=String(t),r=`${s}-`;return e.find(o=>o.key===s||o.key.startsWith(r))?.key}function Fq(e){return e.earliest===void 0?"wait":e.target>=e.earliest?"scroll":e.loading?"wait":e.hasOlder?"load":"give-up"}function zq(e){return e.range===void 0||e.loading?"wait":e.range&&e.target>=e.range[0]&&e.target<=e.range[1]?"scroll":e.jumped?"give-up":"jump"}function $q(e,t){const s=[];let r=0;for(const[o,i]of t)o<r||i<=o||i>e.length||(o>r&&s.push({text:e.slice(r,o),match:!1}),s.push({text:e.slice(o,i),match:!0}),r=i);return r<e.length&&s.push({text:e.slice(r),match:!1}),s}function Vq({chatId:e,bots:t}){const{t:s}=z(),r=ie(a=>a.queue),[o,i]=f.useState(null);return r.filter(a=>a.chatId===e&&a.deliveryId).map(a=>{const l=t.get(a.botId)?.name??s("Deleted member");return n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsxs("span",{children:[l," · ",s("Queued")]}),a.canInterject&&n.jsx(fe,{size:"sm",variant:"ghost",disabled:o!==null,onClick:async()=>{if(a.deliveryId){i(a.deliveryId);try{const c=await window.electronAPI.bots.interjectQueued(e,a.deliveryId);c.ok||Ie({type:"error",title:c.error})}catch{Ie({type:"error",title:s("Failed to send")})}finally{i(null)}}},children:s("Insert into {{name}}’s current task",{name:l})})]},a.deliveryId)})}const Hq=(e,t)=>t?e.find(s=>s.conversationId===t):void 0,Wq=(e,t)=>Math.max(0,Math.floor((t-e)/1e3));function d2({since:e}){const{t}=z(),[s,r]=f.useState(()=>Date.now());return f.useEffect(()=>{const o=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(o)},[]),n.jsx(n.Fragment,{children:t("Quiet for {{n}}s",{n:Wq(e,s)})})}function u2({conversationId:e,className:t}){const s=ie(r=>Hq(r.silences,e)?.since);return s===void 0?null:n.jsx("span",{className:t??"shrink-0 text-warning",children:n.jsx(d2,{since:s})})}const _c=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),Uq={smart:"Smart pick","smart:build":"Smart pick · build","smart:answer":"Smart pick · answer","smart:discuss":"Smart pick · discuss",summary:"Owner summary","wrap-up":"Owner wrap-up"};function qq({chat:e,bots:t,timeline:s,runtime:r,delegations:o,focus:i,onFocusDone:a,onLoadOlder:l,onLoadNewer:c,onLoadAround:u,onJumpLatest:d,onOpenConversation:m,onOpenLive:h}){const{t:p}=z(),g=f.useRef(null),x=f.useRef(!0),v=f.useRef(m);v.current=m;const b=f.useCallback((ce,Re)=>v.current(ce,Re),[]),w=f.useRef(null),j=f.useRef(!1),T=s?.entries??[],N=f.useRef({chatId:e.id,loaded:T,delegations:o});N.current={chatId:e.id,loaded:T,delegations:o};const S=f.useCallback(ce=>{const{chatId:Re,loaded:ue,delegations:We}=N.current,it=dE(ue,ce);if(it!==void 0)return ie.getState().focusSeq(Re,it);const Fe=We.find(tt=>tt.id===ce);Ie({type:"info",title:Fe&&Fe.deliveredAt===void 0?p("The delegation card is posted after the delegator receives the result."):p("The delegation card is not in the loaded messages.")})},[p]),I=Lq(T,e.epochSeq??0),k=s?.history,L=e.epochSeq??0,[F,A]=f.useState(!1);f.useEffect(()=>A(!1),[e.id,L]);const M=L>0&&!F&&!k,R=f.useMemo(()=>M?T.filter(ce=>ce.seq>=L):T,[T,M,L]),$=f.useMemo(()=>uE(R),[R]),U=()=>{M&&s?.hasOlder&&!s.loading&&!T.some(ce=>ce.seq<L)&&(Se(),l()),A(M)},q=f.useMemo(()=>{const ce=new Map;if(!k)for(const Re of $)Re.kind==="entry"&&Re.entry.kind==="bot"&&!Re.continued&&ce.set(Re.entry.botId,Re.entry.id);return new Set(ce.values())},[$,k]),te=f.useMemo(()=>new Map(o.map(ce=>[ce.id,{record:ce,retried:_j(ce,o)}])),[o]),V=f.useMemo(()=>Wj(o,e.id),[o,e.id]),se=f.useMemo(()=>fE(R,mE(V)),[R,V]),Ce=ie(ce=>ce.tasks[e.id]),de=V.some(ce=>ce.appends?.length);f.useEffect(()=>{de&&!Ce&&ie.getState().refreshTasks(e.id)},[de,Ce,e.id]);const re=({key:ce,record:Re,append:ue})=>n.jsx(Nu,{record:Re,append:ue,taskSeq:ue&&Ce?.find(We=>We.id===Re.taskId)?.seq,fill:!0,bots:t,onOpenConversation:m},ce),Z=r?.current?t.get(r.current):void 0,me=r?.current?e.sessions[r.current]?.conversationId:void 0,xe=ie(ce=>me?ce.sessions[me]?.messages.length:void 0);f.useLayoutEffect(()=>{const ce=g.current;ce&&(ce.scrollTop=ce.scrollHeight),x.current=!0},[e.id]);const Se=()=>{const ce=g.current;if(!ce)return;const Re=ce.getBoundingClientRect().top;for(const ue of ce.querySelectorAll("[data-seq]")){const We=ue.getBoundingClientRect();if(!(We.bottom<=Re)){w.current={seq:Number(ue.dataset.seq),top:We.top-Re};return}}};f.useLayoutEffect(()=>{const ce=g.current;if(!ce)return;const Re=w.current;!s?.loading&&!s?.loadingNewer&&(w.current=null);const We=j.current&&!k;j.current=!!k;const it=Re&&ce.querySelector(`[data-seq="${Re.seq}"]`);if(Re&&it){ce.scrollTop+=it.getBoundingClientRect().top-ce.getBoundingClientRect().top-Re.top;return}We&&(x.current=!0),x.current&&!k&&(ce.scrollTop=ce.scrollHeight)},[R,k,s?.loading,s?.loadingNewer,V.length,Z?.id,xe,r?.routing]);const W=()=>{const ce=g.current;if(!ce||!s)return;const Re=ce.scrollHeight-ce.scrollTop-ce.clientHeight;x.current=Re<40,w.current&&Se(),!(R.length===0||M&&(T[0]?.seq??0)<=L)&&(ce.scrollTop<80&&s.hasOlder&&!s.loading&&(Se(),l()),Re<80&&k&&!s.loadingNewer&&(Se(),c()))},[H,B]=f.useState(null),ne=f.useRef(null),[ve,he]=f.useState(null);f.useLayoutEffect(()=>{if(!i||ne.current===i.nonce)return;if(M&&i.seq<L){A(!0);return}const ce=R[0]?.seq,Re=R.at(-1)?.seq,ue=ve?.nonce===i.nonce?ve:null,We=zq({target:i.seq,range:s?ce===void 0||Re===void 0?null:[ce,Re]:void 0,loading:!!(ue&&!ue.done),jumped:!!ue?.done});if(We!=="wait"){if(We==="jump"){const it=i.nonce;x.current=!1,w.current=null,he({nonce:it,done:!1}),u(i.seq).finally(()=>he(Fe=>Fe?.nonce===it?{nonce:it,done:!0}:Fe));return}ne.current=i.nonce,a?.(i.nonce),We==="scroll"&&(x.current=!1,w.current=null,B(i.seq),g.current?.querySelector(`[data-seq="${i.seq}"]`)?.scrollIntoView({block:"center"}))}},[i,R,s===void 0,ve,M]),f.useEffect(()=>{if(H===null)return;const ce=window.setTimeout(()=>B(null),2500);return()=>window.clearTimeout(ce)},[H]);const G=()=>{x.current=!0,w.current=null,d()},we=k&&s?s.lastSeq-k.sinceSeq:0;return n.jsxs("div",{className:"relative flex min-h-24 flex-1 flex-col",children:[n.jsx("div",{ref:g,onScroll:W,className:"min-h-0 flex-1 select-text overflow-y-auto",children:n.jsx("div",{className:"@container",children:n.jsxs("div",{"data-slot":"bot-timeline",className:_(_r,"flex flex-col gap-3 py-4"),children:[s?.loading&&n.jsx("div",{className:"flex justify-center py-1 text-muted-foreground",children:n.jsx(_t,{className:"h-4 w-4 animate-spin"})}),s&&!s.hasOlder&&!M&&R.length>0&&n.jsx("div",{className:"text-center text-[11px] text-muted-foreground",children:p("Beginning of the chat")}),!s&&n.jsx("div",{className:"flex justify-center py-6 text-muted-foreground",children:n.jsx(_t,{className:"h-4 w-4 animate-spin"})}),s&&R.length===0&&n.jsx("p",{className:"py-10 text-center text-muted-foreground text-sm",children:p("Say something. Mention a member with @, or the group owner replies.")}),se.head.map(re),$.map(ce=>ce.kind==="day"?n.jsx("div",{className:"py-1 text-center text-[11px] text-muted-foreground",children:new Date(ce.at).toLocaleDateString()},ce.key):n.jsxs(f.Fragment,{children:[L>0&&!k&&ce.entry.seq===L&&n.jsxs("button",{type:"button",onClick:U,className:"flex items-center gap-1 self-center rounded-md px-2 py-1 text-muted-foreground text-xs hover:bg-muted hover:text-foreground",children:[M?n.jsx(fn,{className:"h-3.5 w-3.5"}):n.jsx(Fn,{className:"h-3.5 w-3.5"}),M?p("Earlier conversation · {{n}} messages",{n:L-1}):p("Collapse earlier conversation")]}),n.jsx("div",{"data-seq":ce.entry.seq,className:_("-mx-2 flex flex-col rounded-lg px-2 transition-colors duration-500",H===ce.entry.seq&&"bg-brand/10"),children:n.jsx(Gq,{chatId:e.id,entry:ce.entry,continued:ce.continued,latest:q.has(ce.entry.id),retryable:I.has(ce.entry.id)&&e.archivedAt===void 0,retryBusy:!!(r?.current||r?.routing),bots:t,records:te,onOpenConversation:b,onLocateDelegation:S})}),se.after.get(ce.entry.id)?.map(re)]},ce.key)),s?.loadingNewer&&n.jsx("div",{className:"flex justify-center py-1 text-muted-foreground",children:n.jsx(_t,{className:"h-4 w-4 animate-spin"})}),!k&&!Z&&r?.routing&&n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx(py,{}),p("Choosing who replies…")]}),!k&&n.jsx(Vq,{chatId:e.id,bots:t}),!k&&Z&&n.jsxs("button",{type:"button",disabled:!me,title:p("View live"),onClick:()=>me&&h(me,Z.id),className:"-mx-2 flex gap-2.5 rounded-lg px-2 py-1 text-left hover:bg-muted/60 disabled:pointer-events-none",children:[n.jsx($t,{bot:Z,size:"sm",busy:!0}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"text-muted-foreground text-xs",children:[n.jsx("span",{className:"mr-1.5 font-semibold text-foreground",children:Z.name}),p("Replying")]}),n.jsx($C,{conversationId:me,leading:n.jsx(py,{}),trailing:n.jsxs(n.Fragment,{children:[n.jsx(u2,{conversationId:me}),me&&n.jsx("span",{className:"shrink-0 underline-offset-2 hover:underline",children:p("View live")})]})})]})]})]})})}),k&&n.jsxs("button",{type:"button",onClick:G,className:"absolute bottom-4 left-1/2 z-10 inline-flex h-7 -translate-x-1/2 items-center gap-1.5 rounded-full border bg-card px-3 text-muted-foreground text-xs shadow-float transition-colors hover:text-foreground",children:[n.jsx(Vh,{className:"h-3 w-3"}),we>0?p("Back to latest · {{n}} new",{n:we}):p("Back to latest")]})]})}function py(){return n.jsx("span",{className:"flex gap-0.5",children:[0,1,2].map(e=>n.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-muted-foreground",style:{animationDelay:`${e*.2}s`}},e))})}const Gq=f.memo(function({chatId:t,entry:s,continued:r,latest:o,bots:i,records:a,onOpenConversation:l,onLocateDelegation:c,retryable:u,retryBusy:d}){const{t:m}=z(),[h,p]=f.useState(!1),g=async()=>{if(!h){p(!0);try{const x=await window.electronAPI.bots.retry(t,s.id);x.ok||Ie({type:"error",title:m("Retry failed"),description:ds(x.error,m)})}catch{Ie({type:"error",title:m("Retry failed")})}finally{p(!1)}}};switch(s.kind){case"system":return s.newConversation?n.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground text-xs",children:[n.jsx("div",{className:"h-px flex-1 bg-border"}),m("New conversation")," · ",_c(s.at),n.jsx("div",{className:"h-px flex-1 bg-border"})]}):s.routine?n.jsx(fq,{text:s.text,target:s.routine}):n.jsxs("div",{"data-slot":"bot-notice",className:"self-center rounded-full bg-muted px-2.5 py-0.5 text-center text-muted-foreground text-xs",children:[s.text,u&&n.jsx(fe,{size:"xs",variant:"outline",className:"ml-2",disabled:d||h,onClick:g,children:m("Retry")})]});case"human":return n.jsxs("div",{className:"flex w-full flex-col items-end",children:[s.text&&n.jsx("div",{className:_(Lc,"whitespace-pre-wrap break-words"),children:n.jsx(Bc,{text:s.text,bots:i})}),s.images?.length?n.jsx(Td,{target:{chatId:t,entryId:s.id}}):null,(s.refs?.skill||s.refs?.chats?.length)&&n.jsx(Qq,{refs:s.refs}),!r&&n.jsx("span",{className:"mt-0.5 text-[11px] text-muted-foreground",children:_c(s.at)})]});case"progress":return n.jsx(Yq,{chatId:t,entry:s,bots:i,failed:a.get(s.delegationId)?.record.state==="failed"});case"delegation":return n.jsx(Nu,{record:a.get(s.delegationId)?.record,retried:a.get(s.delegationId)?.retried,entry:s,fill:!0,bots:i,onOpenConversation:l});case"bot":{const x=i.get(s.botId);return n.jsxs("div",{className:_("flex w-full gap-2.5",r&&"-mt-1.5"),children:[r?n.jsx("span",{className:"w-6 shrink-0"}):o?n.jsx(qC,{chatId:t,botId:s.botId,bot:x}):n.jsx($t,{bot:x,size:"sm"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[!r&&n.jsxs("div",{className:"mb-0.5 text-muted-foreground text-xs",children:[n.jsx("span",{className:"mr-1.5 font-semibold text-foreground",children:x?.name??m("Deleted member")}),x?.title?`${x.title} · `:"",_c(s.at),s.model&&n.jsx("span",{className:"ml-1.5 rounded-md bg-muted px-1.5 py-0.5 font-mono text-[10px]",children:s.model}),s.delegationId&&n.jsx("button",{type:"button",title:m("Locate the delegation card"),onClick:()=>s.delegationId&&c(s.delegationId),className:"ml-1.5 rounded bg-info/15 px-1 py-px text-[10px] text-info hover:bg-info/25",children:m("Delegation result")}),s.routedBy&&n.jsx("span",{title:m(s.routedBy==="summary"?"Asked to sum up after the assigned members replied":"Picked automatically because nobody was @-mentioned"),className:"ml-1.5 rounded border px-1 py-px text-[10px]",children:m(Uq[s.routedBy])})]}),n.jsx("div",{className:"text-sm",children:n.jsx(Dn,{text:s.text})}),n.jsx(Td,{target:{chatId:t,entryId:s.id}}),n.jsx(Xq,{entry:s,onOpen:()=>l(s.conversationId,x?.name??"")})]})]})}}}),Kq={started:{icon:g_,className:"border-brand/50 text-brand"},blocked:{icon:Zr,className:"border-warning/60 text-warning"},failed:{icon:hj,className:"border-destructive/60 text-destructive"},delivered:{icon:Bh,className:"border-success/60 text-success"}};function Yq({chatId:e,entry:t,bots:s,failed:r}){const{t:o}=z(),i=ie(d=>d.openTask),a=s.get(t.botId),l=Kq[t.phase==="blocked"&&r?"failed":t.phase],c=l.icon,u=_q(t.text,t.taskSeq);return n.jsxs("div",{"data-slot":"bot-progress","data-phase":t.phase,className:"flex w-full gap-2.5",children:[n.jsx($t,{bot:a,size:"sm"}),n.jsxs("div",{className:_("flex min-w-0 max-w-lg items-start gap-1.5 rounded-md border-l-2 bg-muted/50 px-2 py-1 text-xs",l.className),children:[n.jsx(c,{"aria-hidden":!0,className:"mt-px size-3.5 shrink-0"}),n.jsxs("div",{className:"line-clamp-2 min-w-0 break-words text-muted-foreground",children:[n.jsx("span",{className:"font-medium text-foreground",children:a?.name??o("Deleted member")})," ",u?n.jsxs(n.Fragment,{children:[n.jsx(Bc,{text:u[0],bots:s}),n.jsx("button",{type:"button","aria-label":o("Open task card #{{n}}",{n:t.taskSeq}),className:"rounded px-0.5 font-medium text-foreground underline decoration-dotted underline-offset-2 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>i(e,t.taskId),children:u[1]}),n.jsx(Bc,{text:u[2],bots:s})]}):n.jsx(Bc,{text:t.text,bots:s})]}),n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:_c(t.at)})]})]})}function Bc({text:e,bots:t}){const s=f.useMemo(()=>{const r=[...t.values()].map(a=>a.name).sort((a,l)=>l.length-a.length),o=r.map(a=>a.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")),i=r.length?new RegExp(`(@(?:${o.join("|")}|所有人|everyone|all))`,"giu"):null;return Hw(e).flatMap(a=>a.type==="file"?[a]:(i?a.text.split(i):[a.text]).map((l,c)=>l.startsWith("@")&&c%2===1?{type:"mention",part:l}:l))},[e,t]);return n.jsx(n.Fragment,{children:s.map((r,o)=>typeof r=="string"?r:r.type==="file"?n.jsxs("span",{className:_(bu("file"),"mx-0.5 leading-4"),title:r.path,children:[n.jsx(Wo,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:Hj})]},o):n.jsx("span",{className:"font-medium underline underline-offset-2",children:r.part},o))})}function Xq({entry:e,onOpen:t}){const{t:s}=z(),[r,o]=f.useState(!1),[i,a]=f.useState(null);f.useEffect(()=>{if(!r||i)return;let c=!0;const u=m=>{const h=lE(m,e.text);if(c){if(!h)return a({error:s("No process recorded.")});a({steps:cE(m.slice(h.start,h.end)),exact:h.exact})}},d=ie.getState().sessions[e.conversationId]?.messages;return d?.some(m=>m.role==="assistant")?u(d):window.electronAPI.bots.sessionHistory({conversationId:e.conversationId}).then(m=>m.ok?u(m.messages):c&&a({error:m.error})),()=>{c=!1}},[r,i,e.conversationId,e.text,s]);const l=r?Fn:fn;return n.jsxs("div",{className:"mt-1",children:[n.jsxs("button",{type:"button",onClick:()=>o(c=>!c),className:"flex items-center gap-1 text-muted-foreground text-xs hover:text-foreground",children:[n.jsx(l,{className:"h-3 w-3"}),s("View process"),i&&"steps"in i&&` · ${s("{{n}} steps",{n:i.steps.length})}`]}),r&&n.jsxs("div",{"data-slot":"bot-card",className:"mt-1.5 rounded-lg border bg-card px-3 py-2 font-mono text-muted-foreground text-xs leading-relaxed",children:[!i&&n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin"}),i&&"error"in i&&n.jsx("span",{children:i.error}),i&&"steps"in i&&n.jsxs(n.Fragment,{children:[!i.exact&&n.jsx("div",{className:"mb-1 font-sans italic",children:s("Could not locate this reply; showing the latest turn.")}),i.steps.length===0&&n.jsx("div",{className:"font-sans",children:s("No tool calls in this turn.")}),i.steps.map(c=>n.jsxs("div",{className:_("truncate",c.error&&"text-destructive"),children:[c.error?"✗":"·"," ",Rr(c.name,s),c.detail&&n.jsxs("span",{className:"text-foreground/80",children:[" ",c.detail]})]},c.id))]}),n.jsx("button",{type:"button",onClick:t,className:"mt-1.5 font-sans text-foreground underline-offset-2 hover:underline",children:s("Open full conversation")})]})]})}function Qq({refs:e}){const{t}=z(),s=ie(a=>a.chats),r=ie(a=>a.bots),o=pe(a=>a.skills),i="inline-flex h-6 max-w-56 items-center gap-1 rounded-md px-1.5 text-xs";return n.jsxs("div",{className:"mt-1 flex flex-wrap justify-end gap-1.5",children:[e.skill&&n.jsxs("span",{className:_(i,"bg-info/15 text-info"),children:[n.jsx(Bs,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:o.find(a=>a.id===e.skill)?.name??e.skill})]}),e.chats?.map(a=>{const l=s.find(c=>c.id===a);return n.jsxs("span",{className:_(i,"bg-muted"),title:t("Referenced chat"),children:[n.jsx(Jr,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:l?is(l,r,t):t("Unavailable chat")})]},a)})]})}const f2=f.createContext(null);function m2({retry:e,onCancel:t}){const{t:s}=z(),[r,o]=f.useState(()=>Date.now());f.useEffect(()=>{const a=setInterval(()=>o(Date.now()),500);return()=>clearInterval(a)},[]);const i=Math.max(0,Math.ceil((e.at+e.delayMs-r)/1e3));return n.jsxs("div",{className:"mb-1 flex items-center gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-2.5 py-1.5 text-xs",children:[n.jsx(oo,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-amber-500 [animation-duration:2s]"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",title:e.error,children:[e.maxAttempts>0?s("Auto-retrying ({{attempt}}/{{max}})",{attempt:e.attempt,max:e.maxAttempts}):s("Auto-retrying ({{attempt}})",{attempt:e.attempt}),n.jsxs("span",{className:"text-muted-foreground",children:[" · ",i>0?s("retrying in {{seconds}}s",{seconds:i}):s("retrying…")," — ",e.error]})]}),t&&n.jsx("button",{type:"button",title:s("Cancel auto-retry"),onClick:t,className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]})}function xy(e,t){return t.projectId?t.projectId:e.workspace.kind==="member-home"?void 0:e.workspace.projectId}function Jq(e,t,s){for(const r of e??[])for(const o of Object.values(r.sessions))if(o.conversationId===s)return xy(r,o);for(const r of t??[]){if(r.childConversationId!==s||!r.chatId)continue;const o=e?.find(a=>a.id===r.chatId),i=o?.sessions[r.targetBotId];if(o&&i)return xy(o,i)}}function h2(e,t){const s=ie(o=>e?Jq(o.chats,o.delegations,e):void 0),r=t??s;return!e||!r?null:{conversationId:e,projectId:r}}function p2(e){const{t}=z(),s=ie(i=>i.delegations),r=e?hE(s,e):[],o=r.map(i=>`${i.key}:${i.at}:${i.trigger}`).join("|");return f.useMemo(()=>r.map(i=>({key:i.key,at:i.at,text:t("Run {{n}} · {{source}}",{n:i.n,source:o2(i.trigger,t)})})),[o,t])}const Zq=2500;function x2({focus:e,timelineRef:t,items:s,baseIndex:r,hasMessages:o,loading:i,loadOlder:a,onDone:l}){const[c,u]=f.useState(null),d=f.useRef(null);return f.useEffect(()=>{if(!e||d.current===e.nonce)return;const m=Fq({target:e.messageIndex,earliest:o?r:void 0,hasOlder:r>0,loading:i});if(m==="wait")return;if(m==="load"){a();return}d.current=e.nonce,l?.(e.nonce);const h=m==="scroll"?Bq(s,e.messageIndex):void 0;h&&(window.setTimeout(()=>t.current?.scrollToKey(h),60),u({key:h,query:e.query}))},[e,s,r,o,i,a,l,t]),f.useEffect(()=>{if(!c)return;const m=window.setTimeout(()=>u(null),Zq);return()=>window.clearTimeout(m)},[c]),{searchQuery:c?.query??"",activeHit:c?{key:c.key,nth:0}:null}}function g2({conversationId:e,speaker:t,emptyTitle:s,emptyDescription:r,className:o,focus:i,onFocusDone:a,turnFooter:l,controls:c,runDividers:u,dataSlot:d}){const m=ie(k=>k.sessions[e]),h=ie(k=>!!k.sessionHistoryLoading[e]),p=f.useRef(null),g=m?.status==="running",x=f.useMemo(()=>m?Zh(m.messages,g,m.customEntries,void 0,{historyBaseIndex:m.historyBaseIndex,toolOutputs:m.toolOutputs,pendingApprovals:m.pendingApprovals,toolStartedAt:m.toolStartedAt,runDividers:u}):[],[m,g,u]);f.useEffect(()=>{p.current?.isAtBottom()&&p.current.pinToBottom()},[x]);const v=f.useMemo(()=>()=>{ie.getState().loadOlderSession(e)},[e]),b=x2({focus:i,timelineRef:p,items:x,baseIndex:m?.historyBaseIndex??0,hasMessages:(m?.messages.length??0)>0,loading:h,loadOlder:v,onDone:a}),{name:w,color:j,image:T}=t,N=f.useMemo(()=>({sessionId:e,canRewind:!!c,canRetry:!!c,canFork:!1,speaker:{name:w,color:j,image:T},turnFooter:l,...c?{botControls:c}:{}}),[e,w,j,T,l,c]),S=(m?.historyBaseIndex??0)>0,I=h2(e);return n.jsx(f2.Provider,{value:I,children:n.jsx(gu.Provider,{value:N,children:n.jsxs("div",{"data-slot":d,className:_("@container flex min-h-0 flex-1 flex-col",o),children:[n.jsx(Ox,{ref:p,items:x,busy:g,loading:!1,running:g,runStartedAt:m?.runStartedAt,lastOutputAt:m?.lastOutputAt,error:m?.status==="failed"?m.error:void 0,emptyTitle:s,emptyDescription:r,historyLoading:h,hasOlder:S,olderCursor:m?.historyBaseIndex,onStartReached:S?()=>{ie.getState().loadOlderSession(e)}:void 0,searchQuery:b.searchQuery,activeHit:b.activeHit},e),m?.retry&&n.jsx("div",{className:_r,children:n.jsx(m2,{retry:m.retry})})]})})})}function v2({conversationId:e,title:t,speaker:s,emptyTitle:r,emptyDescription:o,meta:i,actions:a,children:l,footer:c,dataEnso:u,onClose:d}){const m=p2(e);return n.jsx(cn,{open:e!==null,onOpenChange:h=>!h&&d(),children:n.jsxs(dn,{"data-enso":u,className:"flex h-[80vh] max-w-3xl flex-col",children:[n.jsxs(un,{children:[a?n.jsxs("div",{className:"flex items-start gap-2 pe-8",children:[n.jsx(rn,{className:"min-w-0 flex-1",children:t}),a]}):n.jsx(rn,{children:t}),i]}),l??(e&&s&&n.jsx(g2,{className:"border-t",conversationId:e,speaker:s,emptyTitle:r??t,emptyDescription:o,runDividers:m})),c&&n.jsx("div",{className:_r,children:c})]})})}function $x({conversationId:e,title:t,speaker:s,focus:r,turnFooter:o,read:i,botSession:a=!0,running:l=!1,onClose:c}){const{t:u}=z(),[d,m]=f.useState(null),[h,p]=f.useState(),[g,x]=f.useState(),[v,b]=f.useState(!1),w=f.useRef(!1),j=f.useRef(null),T=f.useCallback(U=>i?i(U):window.electronAPI.bots.sessionHistory({conversationId:e??"",...U!==void 0?{beforeIndex:U}:{}}),[e,i]);f.useEffect(()=>{if(m(null),x(void 0),p(void 0),!e)return;let U=!0;return T().then(q=>{U&&(q.ok?(m({messages:q.messages,baseIndex:q.baseIndex}),p(q.projectId)):x(q.code==="not-found"?u("This conversation has no history yet."):q.error))}),()=>{U=!1}},[e,T,u]);const N=f.useCallback(async()=>{if(!(!e||!d||d.baseIndex<=0||w.current)){w.current=!0,b(!0);try{const U=await T(d.baseIndex);U.ok&&U.baseIndex+U.messages.length===d.baseIndex&&m({messages:[...U.messages,...d.messages],baseIndex:U.baseIndex})}finally{w.current=!1,b(!1)}}},[e,T,d]),S=p2(e),I=f.useMemo(()=>d?Zh(d.messages,l,[],void 0,{historyBaseIndex:d.baseIndex,runDividers:S}):[],[d,l,S]),k=f.useCallback(()=>{N()},[N]),L=x2({focus:r,timelineRef:j,items:I,baseIndex:d?.baseIndex??0,hasMessages:!!d?.messages.length,loading:v||d===null,loadOlder:k}),F=s?.name,A=s?.color,M=s?.image,R=f.useMemo(()=>({sessionId:e,canRewind:!1,canRetry:!1,botSession:a,speaker:F&&A?{name:F,color:A,image:M}:void 0,turnFooter:o}),[a,e,F,A,M,o]),$=h2(a?e:null,h);return n.jsx(f2.Provider,{value:$,children:n.jsx(cn,{open:e!==null,onOpenChange:U=>!U&&c(),children:n.jsxs(dn,{className:"flex h-[80vh] max-w-3xl flex-col",children:[n.jsx(un,{children:n.jsx(rn,{children:t})}),n.jsx(gu.Provider,{value:R,children:n.jsx("div",{className:"@container flex min-h-0 flex-1 flex-col border-t",children:g?n.jsx("p",{className:"p-6 text-muted-foreground text-sm",children:g}):n.jsx(Ox,{ref:j,items:I,busy:d===null,loading:d===null,running:!1,emptyTitle:t,hasOlder:!!(d&&d.baseIndex>0),historyLoading:v,olderCursor:d?.baseIndex,onStartReached:d&&d.baseIndex>0?()=>{N()}:void 0,searchQuery:L.searchQuery,activeHit:L.activeHit})})})]})})})}const hh="flex h-7 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-muted-foreground text-xs transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50";function eG({group:e,thread:t}){const{t:s}=z(),r=ie(k=>k.chats),o=ie(k=>k.sessions),i=ie(k=>k.timelines),a=ie(k=>k.queue),l=ie(k=>k.reads),c=ie(k=>k.bots),[u,d]=f.useState(!1),[m,h]=f.useState(null),[p,g]=f.useState(null),x=e.archivedAt!==void 0,v=f.useMemo(()=>Object.fromEntries(c.map(k=>[k.id,k.name])),[c]),b=k=>k.threadTitle??(k.parentId?s("New topic"):s("Main topic")),w=fz(r,e).map(k=>{const L=ep(k,{sessions:o,timeline:i[k.id],queue:a,names:v});return{id:k.id,title:b(k),preview:L.preview,activityAt:Math.max(L.activityAt,k.createdAt),unread:k.id!==t.id&&la(L.marker,l[L.key]),running:L.running,canRename:!x,canDelete:!!k.parentId}}),j=nS(w,{currentId:t.id,rootId:e.id}),T=w.length-j.length,N=k=>ie.getState().openThread(e.id,k),S=async()=>{await ie.getState().createThread(e.id)||Ie({type:"error",title:s("Could not create topic")})},I=async k=>{const L=await window.electronAPI.bots.deleteThread(k);L.ok||Ie({type:"error",title:ds(L.error,s)}),ie.getState().refreshChats()};return n.jsxs(n.Fragment,{children:[n.jsxs(mr,{children:[n.jsxs(hr,{className:_(hh,"max-w-56 @max-[28rem]:max-w-32 @max-[21rem]:max-w-24"),children:[n.jsx("span",{className:"truncate",children:b(t)}),w.some(k=>k.unread)&&n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-info"}),n.jsx(Fn,{className:"h-3.5 w-3.5 shrink-0"})]}),n.jsxs(pr,{align:"end",className:"w-72",children:[n.jsxs(tp,{children:[n.jsx(np,{children:s("Topics")}),j.map(k=>n.jsxs(Cn,{onClick:()=>N(k.id),children:[n.jsx(On,{className:_(k.id!==t.id&&"invisible")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k.title}),n.jsx(Vx,{entry:k})]},k.id))]}),n.jsx(Ri,{}),T>0&&n.jsxs(Cn,{onClick:()=>d(!0),children:[n.jsx(TN,{}),s("All topics ({{n}})",{n:w.length})]}),n.jsxs(Cn,{disabled:x,onClick:()=>{S()},children:[n.jsx(no,{}),s("New topic")]}),n.jsxs(Cn,{disabled:x,onClick:()=>h({id:t.id,title:b(t)}),children:[n.jsx(bs,{}),s("Rename topic")]}),t.parentId&&n.jsxs(Cn,{variant:"destructive",onClick:()=>g(t.id),children:[n.jsx(vs,{}),s("Delete topic")]})]})]}),n.jsxs("button",{type:"button",disabled:x,onClick:()=>{S()},className:_(hh,"shrink-0"),title:s("New topic"),"aria-label":s("New topic"),children:[n.jsx(no,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"@min-[28rem]:inline hidden",children:s("New topic")})]}),u&&n.jsx(b2,{heading:s("Topics"),placeholder:s("Search topics..."),empty:s("No matching topics"),filters:!0,entries:w,currentId:t.id,onClose:()=>d(!1),onOpen:k=>{N(k),d(!1)},onRename:k=>h({id:k.id,title:k.title}),onDelete:k=>g(k.id)}),n.jsx(cs,{open:p!==null,onOpenChange:k=>!k&&g(null),title:s("Delete this topic?"),description:s("Its messages and member sessions are removed; replies in progress are stopped. Group notes, memory and the task board stay."),confirmLabel:s("Delete"),onConfirm:()=>p&&void I(p),zIndexLevel:u?"nested":"base"}),m!==null&&n.jsx(tG,{initial:m.title,nested:u,onClose:()=>h(null),onSave:async k=>{const L=await window.electronAPI.bots.renameThread(m.id,k);if(!L.ok){Ie({type:"error",title:ds(L.error,s)});return}ie.getState().upsertChat(L.chat),h(null)}})]})}function Vx({entry:e}){const{locale:t}=z();return n.jsxs(n.Fragment,{children:[e.running&&n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-warning"}),e.unread&&n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-info"}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:Lo(e.activityAt,t)})]})}function b2({heading:e,placeholder:t,empty:s,filters:r=!1,entries:o,currentId:i,onClose:a,onOpen:l,onRename:c,onDelete:u}){const{t:d}=z(),[m,h]=f.useState(""),[p,g]=f.useState("all"),x=Gv(o,m,p),v=w=>Gv(o,"",w).length,b="shrink-0 rounded p-1 text-muted-foreground opacity-0 hover:bg-muted hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100";return n.jsx(cn,{open:!0,onOpenChange:w=>!w&&a(),children:n.jsxs(dn,{className:"h-[min(40rem,85vh)] max-w-xl",children:[n.jsxs(un,{children:[n.jsxs(rn,{className:"flex items-baseline gap-2",children:[e,n.jsx("span",{className:"font-sans text-muted-foreground text-sm tabular-nums",children:o.length})]}),n.jsxs(sp,{"data-size":"sm",className:"mt-1",children:[n.jsx(rp,{children:n.jsx(dr,{})}),n.jsx(op,{autoFocus:!0,value:m,placeholder:t,onChange:w=>h(w.target.value)})]}),r&&n.jsx(Ud,{value:p,onValueChange:w=>g(w),children:n.jsxs(qd,{children:[n.jsx(ms,{value:"all",children:d("All")}),n.jsxs(ms,{value:"unread",children:[d("Unread"),v("unread")>0&&n.jsx("span",{className:"tabular-nums",children:v("unread")})]}),n.jsxs(ms,{value:"running",children:[d("In progress"),v("running")>0&&n.jsx("span",{className:"tabular-nums",children:v("running")})]})]})})]}),n.jsxs(In,{className:"flex flex-col gap-y-0.5 border-t pt-3!",children:[x.length===0&&n.jsx("p",{className:"py-10 text-center text-muted-foreground text-sm",children:s}),x.map(w=>n.jsxs("div",{className:"group flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted/60",children:[n.jsxs("button",{type:"button",onClick:()=>l(w.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx(On,{className:_("h-3.5 w-3.5 shrink-0",w.id!==i&&"invisible")}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-sm",children:w.title}),w.preview&&n.jsx("span",{className:"block truncate text-muted-foreground text-xs",children:w.preview})]}),n.jsx(Vx,{entry:w})]}),c&&w.canRename&&n.jsx("button",{type:"button",className:b,onClick:()=>c(w),title:d("Rename topic"),"aria-label":d("Rename topic"),children:n.jsx(bs,{className:"h-3.5 w-3.5"})}),u&&w.canDelete?n.jsx("button",{type:"button",className:_(b,"hover:text-destructive"),onClick:()=>u(w),title:d("Delete topic"),"aria-label":d("Delete topic"),children:n.jsx(vs,{className:"h-3.5 w-3.5"})}):u?n.jsx("span",{className:"w-5.5 shrink-0","aria-hidden":!0}):null]},w.id))]})]})})}function tG({initial:e,nested:t,onClose:s,onSave:r}){const{t:o}=z(),[i,a]=f.useState(e),l=()=>{i.trim()&&r(i.trim())};return n.jsx(cn,{open:!0,onOpenChange:c=>!c&&s(),children:n.jsxs(dn,{className:"max-w-sm",zIndexLevel:t?"nested":"base",children:[n.jsx(un,{children:n.jsx(rn,{children:o("Rename topic")})}),n.jsx(In,{children:n.jsx(Ht,{value:i,autoFocus:!0,maxLength:80,onChange:c=>a(c.target.value),onKeyDown:c=>{c.nativeEvent.isComposing||c.key==="Enter"&&l()}})}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:s,children:o("Cancel")}),n.jsx(fe,{size:"sm",disabled:!i.trim(),onClick:l,children:o("Save")})]})]})})}function nG({chat:e,botId:t,running:s,onView:r}){const{t:o}=z(),[i,a]=f.useState([]),[l,c]=f.useState(!1),[u,d]=f.useState(null),m=e.sessions[t]?.conversationId,h=f.useCallback(()=>{window.electronAPI.bots.chatSessions(e.id).then(j=>{j.ok&&a(j.sessions.filter(T=>T.botId===t))})},[e.id,t]);f.useEffect(h,[h,m,s]);const p=i.map(j=>{const T=j.conversationId===m;return{id:j.conversationId,title:j.title??o(T?"New conversation":"Untitled conversation"),preview:T||j.resumable?"":o("Workspace changed; view only"),activityAt:j.activityAt??(T?Date.now():0),unread:!1,running:T&&s,resumable:j.resumable}}),g=nS(p,{currentId:m??"",rootId:m??""}),x=p.length-g.length,v=p.find(j=>j.id===m)?.title??o("New conversation"),b=async j=>{const T=await window.electronAPI.bots.switchSession(e.id,j);T.ok||Ie({type:"error",title:ds(T.error,o)}),await ie.getState().refreshChats(),h()},w=j=>{const T=p.find(N=>N.id===j);!T||j===m||(T.resumable?s?d(j):b(j):r(j,T.title))};return p.length<2?null:n.jsxs(n.Fragment,{children:[n.jsxs(mr,{onOpenChange:j=>j&&h(),children:[n.jsxs(hr,{className:_(hh,"max-w-56"),children:[n.jsx("span",{className:"truncate",children:v}),n.jsx(Fn,{className:"h-3.5 w-3.5 shrink-0"})]}),n.jsxs(pr,{align:"end",className:"w-72",children:[n.jsxs(tp,{children:[n.jsx(np,{children:o("Conversations")}),g.map(j=>n.jsxs(Cn,{onClick:()=>w(j.id),children:[n.jsx(On,{className:_(j.id!==m&&"invisible")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.title}),!j.resumable&&j.id!==m&&n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:o("Read-only")}),n.jsx(Vx,{entry:j})]},j.id))]}),x>0&&n.jsxs(n.Fragment,{children:[n.jsx(Ri,{}),n.jsxs(Cn,{onClick:()=>c(!0),children:[n.jsx(TN,{}),o("All conversations ({{n}})",{n:p.length})]})]})]})]}),l&&n.jsx(b2,{heading:o("Conversations"),placeholder:o("Search conversations..."),empty:o("No matching conversations"),entries:p,currentId:m??"",onClose:()=>c(!1),onOpen:j=>{c(!1),w(j)}}),n.jsx(cs,{open:u!==null,onOpenChange:j=>!j&&d(null),title:o("Switch conversation?"),description:o("The reply in progress will be stopped."),confirmLabel:o("Switch"),onConfirm:()=>u&&void b(u)})]})}function y2(e){const{t}=z(),s=Kd(),r=pe(c=>c.virtualModels);if(!e?.engine)return t("Default model");const{providerId:o,modelId:i}=e.engine,a=Kj(r,e.engine);return a?a.name:s.find(c=>c.id===o)?.models.find(c=>c.id===i)?.label??i}function sG({chat:e,group:t=e}){const{t:s}=z(),r=ie(K=>K.bots),o=ie(K=>K.chats),i=ie(K=>K.sessions),a=ie(K=>K.queue),l=ie(K=>K.delegations),c=ie(K=>K.timelines[e.id]),u=ie(K=>K.runtime[e.id]),d=ie(K=>K.markRead),m=ie(K=>K.panelOpen),h=ie(K=>K.panelTab),p=ie(K=>K.browserTabs[t.id]?.tabs.length??0),g=ie(K=>K.panelWidth),x=pe(K=>K.skills),[v,b]=f.useState(!1),[w,j]=f.useState(0),T=Ho(),N=f.useRef(null);f.useEffect(()=>{const K=N.current?.parentElement;if(!K)return;const Ee=()=>j(K.clientWidth);Ee();const pt=new ResizeObserver(Ee);return pt.observe(K),()=>pt.disconnect()},[]);const S=T?w:vE(g,w),I=m?S:0,k=f.useCallback(K=>{const Ee=N.current?.parentElement;Ee&&ie.getState().nudgePanelWidth(-K,Ee.clientWidth)},[]),[L,F]=f.useState(null),[A,M]=f.useState(),[R,$]=f.useState(null),U=ie(K=>K.focus?.chatId===e.id?K.focus:null),q=ie(K=>K.clearFocus),te=f.useMemo(()=>new Map(r.map(K=>[K.id,K])),[r]),V=f.useMemo(()=>Object.fromEntries(r.map(K=>[K.id,K.name])),[r]),se=e.members.map(K=>te.get(K)).filter(K=>!!K),Ce=se.map(K=>`${K.id}:${K.skillIds.join(",")}`).join("|"),de=f.useMemo(()=>x.flatMap(K=>{const Ee=se.filter(pt=>pt.skillIds.includes(K.id)).map(pt=>pt.id);return Ee.length?[{id:K.id,name:K.name,description:K.description,owners:Ee}]:[]}),[x,Ce]),re=f.useMemo(()=>o.filter(K=>K.id!==t.id&&!K.parentId&&K.archivedAt===void 0).map(K=>({id:K.id,title:is(K,r,s),kind:K.kind})),[o,t.id,r,s]),Z=ep(e,{sessions:i,timeline:c,queue:a,names:V}),me=ie(K=>K.reads[Z.key]),xe=e.kind==="group"?pE(c,me):Z.marker,Se=f.useMemo(()=>l.filter(K=>K.chatId===e.id),[l,e.id]),W=f.useMemo(()=>Uj(i,qj(o,l),e.id),[i,o,l,e.id]),B=L?(K=>{const Ee=Se.find(Je=>Je.childConversationId===K);if(Ee)return te.get(Ee.targetBotId);const pt=Object.entries(e.sessions).find(([,Je])=>Je.conversationId===K)?.[0],Pt=c?.entries.find(Je=>Je.kind==="bot"&&Je.conversationId===K);return te.get(pt??(Pt?.kind==="bot"?Pt.botId:e.kind==="direct"?e.members[0]:""))})(L.id):void 0,ne=R?te.get(R.botId):void 0,ve=R?W.filter(K=>K.conversationId===R.id):[],he=R?.title??ne?.name??s("Deleted member"),G=R&&l.find(K=>K.childConversationId===R.id)?.state==="queued",we=f.useCallback((K,Ee)=>{const pt=xE(ie.getState().delegations,K);pt?(ie.getState().sessions[K]||ie.getState().trackSession(K),$({id:K,botId:pt.botId,title:Ee})):F({id:K,title:Ee})},[]);f.useEffect(()=>{d(Z.key,xe)},[d,Z.key,xe]),f.useEffect(()=>{if(e.kind==="group"){const K=ie.getState();K.timelines[e.id]?.history&&K.focus?.chatId!==e.id?K.jumpLatest(e.id):K.loadLatest(e.id),ie.getState().refreshRuntime(e.id)}},[e.id,e.kind]);const ce=e.kind==="direct"?se[0]:void 0,Re=ce?e.sessions[ce.id]?.conversationId:void 0,ue=U?.locator,We=U&&ue?.kind==="session"&&ue.conversationId===Re?{messageIndex:ue.messageIndex,query:U.query,nonce:U.nonce}:void 0,it=U&&ue?.kind==="timeline"?{seq:ue.seq,query:U.query,nonce:U.nonce}:void 0;f.useEffect(()=>{U?.locator.kind==="session"&&U.locator.conversationId!==Re&&(F({id:U.locator.conversationId,title:s("History")}),M({messageIndex:U.locator.messageIndex,query:U.query,nonce:U.nonce}),q(U.nonce))},[U,Re,q,s]);const Fe=L?.id,tt=f.useCallback(K=>e.kind==="direct"&&Fe?n.jsx(Td,{target:{chatId:e.id,conversationId:Fe,messageIndex:K}}):null,[e.id,e.kind,Fe]),ke=e.archivedAt!==void 0,nt=u?.current?te.get(u.current):void 0,mt=(()=>{if(ke)return s("This chat is archived. Restore it before sending.");if(e.kind==="group"){const K=e.routing.mode==="smart"?s("Without @, the best-fit member is picked to reply"):s("Without @, the group owner replies");return nt?`${K} · ${s("{{name}} is replying; new messages are routed after they finish",{name:nt.name})}`:K}return Z.running&&ce?s("{{name}} is working; your message joins the current turn",{name:ce.name}):null})(),X=async({text:K,images:Ee,...pt})=>{const Pt=await ie.getState().send(e.id,K,Ee,pt);return Pt.ok?(Pt.queued&&Ie({type:"info",title:s("Queued until a session slot frees up")}),ie.getState().timelines[e.id]?.history&&ie.getState().jumpLatest(e.id),!0):(Ie({type:"error",title:s("Message not sent"),description:ds(Pt.error,s)}),!1)};return n.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col bg-background",children:[n.jsxs("header",{className:"@container flex h-[52px] shrink-0 items-center gap-2.5 border-b px-4",children:[ce?n.jsx($t,{bot:ce,busy:Z.running}):n.jsx(ma,{bots:se,busy:Z.running}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate font-semibold text-sm",children:is(e,r,s)}),n.jsx("div",{className:"truncate text-muted-foreground text-xs",children:ce?n.jsx(oG,{bot:ce,running:Z.running,queued:Z.queued,conversationId:e.sessions[ce.id]?.conversationId}):s("{{n}} members · Owner {{name}}",{n:se.length,name:te.get(e.bossBotId??"")?.name??"—"})})]}),n.jsx("div",{className:"flex-1"}),n.jsx(l2,{chat:t}),ce?n.jsxs(n.Fragment,{children:[n.jsx(nG,{chat:e,botId:ce.id,running:Z.running,onView:(K,Ee)=>F({id:K,title:Ee})}),n.jsxs("button",{type:"button",disabled:ke,onClick:()=>{window.electronAPI.bots.newSession(e.id).then(K=>{K.ok?ie.getState().refreshChats():Ie({type:"error",title:ds(K.error,s)})})},className:"flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-muted-foreground text-xs transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",title:s("New conversation"),"aria-label":s("New conversation"),children:[n.jsx(no,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"@min-[28rem]:inline hidden",children:s("New conversation")})]})]}):n.jsx(eG,{group:t,thread:e})]}),ce?n.jsxs(n.Fragment,{children:[n.jsx(rG,{items:Wj(Se,e.id),bots:te,onOpenConversation:we}),n.jsx(aG,{chat:e,bot:ce,focus:We,onFocusDone:q})]}):n.jsx(qq,{chat:e,bots:te,timeline:c,runtime:u,delegations:Se,focus:it,onFocusDone:q,onLoadOlder:()=>{ie.getState().loadOlder(e.id)},onLoadNewer:()=>{ie.getState().loadNewer(e.id)},onLoadAround:K=>ie.getState().loadAround(e.id,K),onJumpLatest:()=>{ie.getState().jumpLatest(e.id)},onOpenConversation:we,onOpenLive:(K,Ee)=>$({id:K,botId:Ee,title:te.get(Ee)?.name??s("Deleted member")})}),n.jsx("div",{className:"@container flex min-h-0 flex-col pt-1",children:n.jsxs("div",{className:_(_r,"flex min-h-0 flex-col pb-4"),children:[n.jsxs("div",{"data-enso":"composer-stack",className:"flex min-h-0 flex-col overflow-y-auto overscroll-contain",children:[ce&&(Z.running||Z.queued)&&n.jsx($C,{conversationId:e.sessions[ce.id]?.conversationId,className:"mb-2 rounded-lg border bg-muted/30 px-3 py-2"}),n.jsx(gy,{items:W,bots:te,showNames:e.kind==="group"}),e.kind==="group"&&n.jsx(zU,{chatId:e.id,memberIds:e.members,bots:te,onOpenLive:(K,Ee)=>$({id:K,botId:Ee,title:te.get(Ee)?.name??s("Deleted member")})})]}),n.jsx(CU,{chatId:e.id,placeholder:ce?s("Message {{name}}…",{name:ce.name}):s("@ a member, or just say it…"),members:e.kind==="group"?se:void 0,chatOptions:re,skills:de,running:Z.running||!!(u?.current||u?.routing),disabled:ke,hint:mt,toolbar:ce?n.jsx(iG,{bot:ce}):null,onSend:X,onStop:()=>{ie.getState().stop(e.id)}},e.id)]})})]}),m&&!T&&n.jsx(jd,{onResize:k,onResizingChange:b}),n.jsx(Ns.aside,{ref:N,initial:!1,animate:{width:I},style:T?void 0:{maxWidth:`max(0px, calc(100% - ${gE+Gj}px))`},transition:IW({skip:v,cover:T,targetW:I}),className:_("flex min-h-0 shrink-0 flex-col overflow-hidden bg-background",T?"absolute inset-y-0 right-0 z-10":"relative"),children:n.jsxs("div",{className:_("flex h-full min-h-0 flex-col",!m&&"invisible"),style:{width:S},children:[n.jsx("div",{className:"flex h-10 shrink-0 items-center gap-1 border-b px-2",children:["info","browser"].map(K=>n.jsxs("button",{type:"button",onClick:()=>ie.getState().setPanelTab(K),className:_("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",h===K?"bg-brand/10 font-medium text-foreground dark:bg-brand/15":"text-muted-foreground hover:text-foreground"),children:[K==="info"?n.jsx(fl,{className:"h-3.5 w-3.5"}):n.jsx(Oo,{className:"h-3.5 w-3.5"}),s(K==="info"?ce?"Member":"Group info":"Browser"),K==="browser"&&p>0&&n.jsx("span",{className:"text-muted-foreground tabular-nums",children:p})]},K))}),h==="browser"?n.jsx(fU,{chatId:t.id,visible:m}):ce?n.jsx(wq,{botId:ce.id,chat:e,onOpenHistory:we}):n.jsx(Oq,{chat:t,thread:e,onOpenConversation:we})]})}),n.jsx($x,{conversationId:L?.id??null,title:L?.title??"",speaker:B?{name:B.name,color:B.avatar.color,image:Kc(B)}:void 0,focus:A,turnFooter:tt,onClose:()=>{F(null),M(void 0)}}),n.jsx(v2,{conversationId:R?.id??null,title:he,speaker:{name:ne?.name??he,color:ne?.avatar.color??"#64748b",image:ne?Kc(ne):void 0},emptyTitle:G?s("Queued and has not started yet"):void 0,emptyDescription:G?"":void 0,footer:ne&&ve.length>0?n.jsx(gy,{items:ve,bots:te,showNames:!1}):void 0,onClose:()=>$(null)})]})}function rG({items:e,bots:t,onOpenConversation:s}){const{t:r}=z();return e.length===0?null:n.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:n.jsxs("div",{className:_(_r,"py-2"),children:[n.jsx("div",{className:"mb-1.5 text-muted-foreground text-xs",children:r("Delegations in progress · {{n}}",{n:e.length})}),n.jsx("div",{className:"flex max-h-56 flex-col gap-1.5 overflow-y-auto",children:e.map(o=>n.jsx(Nu,{record:o,bots:t,onOpenConversation:s},o.id))})]})})}function oG({bot:e,running:t,queued:s,conversationId:r}){const{t:o}=z(),i=y2(e),a=o(t?"Working":s?"Queued":"Idle");return n.jsxs(n.Fragment,{children:[[e.title,i,a].filter(Boolean).join(" · "),t&&n.jsx(u2,{conversationId:r,className:"ml-1.5 text-warning"})]})}function iG({bot:e}){const{t}=z(),s=y2(e),r=Ba[e.approvalMode];return n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"flex h-6 min-w-0 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs",children:[n.jsx(Bs,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-w-32 truncate",children:s})]}),n.jsxs("span",{className:"flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs",children:[n.jsx(Vd,{className:"h-3 w-3"}),t(r.labelKey)]})]})}function aG({chat:e,bot:t,focus:s,onFocusDone:r}){const{t:o}=z(),i=e.sessions[t.id]?.conversationId,a=e.archivedAt!==void 0,l=f.useMemo(()=>{if(a||!i)return;const u=d=>{d.ok||Ie({type:"error",title:ds(d.error??"unavailable",o)})};return{subscribe:ie.subscribe,projection:()=>ie.getState().sessions[i],rewind:(d,m)=>{ie.getState().rewind(e.id,d,m).then(u)},retry:()=>{ie.getState().retry(e.id).then(u)}}},[e.id,i,a,o]),c=f.useCallback(u=>i?n.jsx(Td,{target:{chatId:e.id,conversationId:i,messageIndex:u}}):null,[e.id,i]);return i?n.jsx(g2,{conversationId:i,speaker:{name:t.name,color:t.avatar.color,image:Kc(t)},emptyTitle:o("Say hi to {{name}}",{name:t.name}),focus:s,onFocusDone:r,turnFooter:c,controls:l,dataSlot:"bot-timeline"}):n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 px-6 text-center",children:[n.jsx($t,{bot:t,size:"lg"}),n.jsx("p",{className:"font-medium text-lg",children:t.name}),n.jsx("p",{className:"max-w-sm text-muted-foreground text-sm",children:t.scope||t.title})]})}function gy({items:e,bots:t,showNames:s}){const{t:r}=z(),o=new Map;for(const i of e)o.set(i.conversationId,[...o.get(i.conversationId)??[],i]);return n.jsx(n.Fragment,{children:[...o.entries()].map(([i,a])=>{const l=t.get(a[0].botId),c=a[0].delegation,u=l?.name??r("Deleted member"),d=a.flatMap(h=>h.kind==="approval"?[h.request]:[]),m=a.flatMap(h=>h.kind==="ask"?[h.request]:[]);return n.jsxs("div",{"data-pending-conversation":i,children:[(s||c)&&n.jsxs("div",{className:"mb-1 flex items-center gap-1.5 text-muted-foreground text-xs",children:[n.jsx($t,{bot:l,size:"xs"}),c?r("{{name}} (on behalf of {{owner}}) needs you",{name:u,owner:t.get(c.parentBotId)?.name??r("Deleted member")}):r("{{name}} needs you",{name:u})]}),n.jsx(px,{approvals:d,onRespond:(h,p)=>{window.electronAPI.agent.respondApproval(i,h,p)}}),n.jsx(xx,{asks:m,onAnswer:(h,p)=>{window.electronAPI.agent.respondAsk(i,h,p)}})]},i)})})}function lG(e,t){const s={pending:[],budgets:[],routines:[],silences:[],interrupted:[],blocked:[],count:0};for(const r of bE(e)){const o={chatId:r.chatId??"",botId:r.botId??"",...r.delegationId&&r.ownerBotId?{delegation:{id:r.delegationId,parentBotId:r.ownerBotId}}:{}};if(r.kind==="approval"&&r.approval&&r.conversationId)s.pending.push({kind:"approval",conversationId:r.conversationId,request:r.approval,...o});else if(r.kind==="ask"&&r.ask&&r.conversationId)s.pending.push({kind:"ask",conversationId:r.conversationId,request:r.ask,...o});else if(r.kind==="budget")s.budgets.push(r);else if(r.kind==="silence")s.silences.push(r);else if(r.kind==="routine-draft"||r.kind==="routine-blocked"){const i=t.routines.find(a=>a.id===r.routine?.id&&a.botId===r.routine.botId);i&&s.routines.push({kind:r.kind==="routine-draft"?"approval":"blocked",routine:i})}else if(r.kind==="delegation-interrupted"||r.kind==="task-blocked"){const i=t.delegations.find(a=>a.id===r.delegationId);i&&s[r.kind==="task-blocked"?"blocked":"interrupted"].push({item:r,record:i})}}return s.count=s.pending.length+s.budgets.length+s.routines.length+s.silences.length+s.interrupted.length+s.blocked.length,s}function cG({write:e,bot:t,chatName:s}){const{t:r}=z(),o=yE(d=>d.review),[i,a]=f.useState(!1),[l,c]=f.useState(null),u=d=>{a(!0),c(null),o(e.id,d).then(m=>{m.ok||c(m.error??r("Failed"))}).finally(()=>a(!1))};return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx($t,{bot:t,size:"sm"}),n.jsx("span",{className:"text-foreground",children:t?.name??r("Deleted member")}),s&&n.jsxs("span",{children:["· ",s]}),n.jsx("span",{className:"rounded bg-warning/20 px-1.5 text-[11px] text-warning",children:r("Memory write")}),n.jsxs("span",{children:["→ ",e.spaceLabel]}),e.redacted&&n.jsxs("span",{children:["· ",r("Secrets redacted")]})]}),e.title&&n.jsx("div",{className:"mt-2 font-medium text-sm",children:e.title}),n.jsx("pre",{className:"mt-1 max-h-32 overflow-auto whitespace-pre-wrap rounded-md bg-muted/60 px-2 py-1.5 text-xs",children:e.content}),l&&n.jsx("div",{className:"mt-1 text-destructive text-xs",children:l}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"outline",disabled:i,onClick:()=>u("reject"),children:r("Reject")}),n.jsx(fe,{size:"xs",disabled:i,onClick:()=>u("approve"),children:r("Approve")})]})]})}function dG(){const{t:e}=z(),t=ie(h=>h.inbox),s=ie(h=>h.chats),r=ie(h=>h.bots),o=ie(h=>h.delegations),i=ie(h=>h.routines),[a,l]=f.useState(null),c=f.useMemo(()=>lG(t,{routines:i,delegations:o}),[t,i,o]),u=wE(),d=f.useMemo(()=>new Map(r.map(h=>[h.id,h])),[r]),m=h=>{const p=s.find(g=>g.id===h);return p?is(p,r,e):""};return n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col bg-background",children:[n.jsxs("header",{className:"flex h-[52px] shrink-0 items-center gap-2.5 border-b px-4",children:[n.jsx("div",{className:"font-semibold text-sm",children:e("Inbox")}),n.jsx("div",{className:"text-muted-foreground text-xs",children:e("Everything members are waiting on you for")})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:n.jsxs("div",{className:"mx-auto w-full max-w-2xl space-y-2.5 px-6 py-4",children:[c.count===0&&u.length===0&&n.jsxs("div",{className:"flex flex-col items-center gap-2 py-16 text-muted-foreground",children:[n.jsx(ex,{className:"h-6 w-6"}),n.jsx("p",{className:"text-sm",children:e("Nothing needs your attention")})]}),c.pending.map(h=>n.jsx(pG,{item:h,bot:d.get(h.botId),owner:h.delegation?d.get(h.delegation.parentBotId):void 0,chatName:m(h.chatId)},`${h.conversationId}:${h.request.requestId}`)),c.budgets.map(h=>n.jsx(fG,{item:h,bot:d.get(h.botId??"")},h.key)),u.map(h=>n.jsx(cG,{write:h,bot:h.botId?d.get(h.botId):void 0,chatName:m(h.chatId)},h.id)),c.routines.map(h=>n.jsx(uq,{alert:h},h.routine.id)),c.silences.map(h=>n.jsx(uG,{item:h,bot:d.get(h.botId??""),chatName:m(h.chatId)},h.key)),c.blocked.length>0&&n.jsx("div",{className:"pt-3 font-medium text-muted-foreground text-xs",children:e("Stuck delegated tasks")}),c.blocked.map(({item:h,record:p})=>n.jsx(mG,{inboxKey:h.key,record:p,bots:d,chatName:m(p.chatId)},h.key)),c.interrupted.length>0&&n.jsx("div",{className:"pt-3 font-medium text-muted-foreground text-xs",children:e("Interrupted delegations")}),c.interrupted.map(({item:h,record:p})=>n.jsx(hG,{inboxKey:h.key,record:p,bots:d,chatName:m(p.chatId),onOpen:g=>l({id:p.childConversationId,title:g,bot:d.get(p.targetBotId)})},h.key))]})}),n.jsx($x,{conversationId:a?.id??null,title:a?.title??"",speaker:a?.bot?{name:a.bot.name,color:a.bot.avatar.color}:void 0,onClose:()=>l(null)})]})}function uG({item:e,bot:t,chatName:s}){const{t:r}=z(),o=ie(l=>l.setView),i=ie(l=>l.dismissInbox),a=t?.name??r("Deleted member");return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx($t,{bot:t,size:"sm",busy:!0}),n.jsx("span",{className:"text-foreground",children:a}),s&&n.jsxs("span",{children:["· ",s]}),e.delegationId&&n.jsxs("span",{children:["· ",r("Delegation")]}),n.jsx("span",{className:"rounded bg-warning/20 px-1.5 text-[11px] text-warning",children:n.jsx(d2,{since:e.since??e.createdAt})})]}),n.jsx("div",{className:"mt-2 text-sm",children:r("{{name}} is still running but has produced no output for a while",{name:a})}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>{i(e.key)},children:r("Dismiss")}),e.chatId&&n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>e.chatId&&o({kind:"chat",chatId:e.chatId}),children:r("Go to chat")})]})]})}function fG({item:e,bot:t}){const{t:s}=z(),r=ie(a=>a.dismissInbox),o=ie(a=>a.openDirect),i=t?.name??s("Deleted member");return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx($t,{bot:t,size:"sm"}),n.jsx("span",{className:"text-foreground",children:i}),n.jsx("span",{className:"rounded bg-destructive/15 px-1.5 text-[11px] text-destructive",children:s("Budget")})]}),n.jsx("div",{className:"mt-2 text-sm",children:s("{{name}}'s budget for today is used up",{name:i})}),n.jsx("div",{className:"mt-1 text-muted-foreground text-xs",children:e.budget?.reason==="cost"?s("Daily cost limit reached. New messages are refused until local midnight."):s("Daily token limit reached. New messages are refused until local midnight.")}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>{r(e.key)},children:s("Dismiss")}),t&&n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>{o(t.id)},children:s("Go to chat")})]})]})}function mG({inboxKey:e,record:t,bots:s,chatName:r}){const{t:o}=z(),i=ie(g=>g.openTask),a=ie(g=>g.dismissInbox),l=ku(!0),c=s.get(t.targetBotId),u=c?.name??o("Deleted member"),d=t.finishedAt??t.blocked?.at??t.createdAt,m=t.blocked?.waitFor==="parent"?o("Waiting for {{name}} to reply",{name:s.get(t.parentBotId)?.name??o("Deleted member")}):o("Waiting for your reply"),{chatId:h,taskId:p}=t;return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground text-xs",children:[n.jsx($t,{bot:c,size:"xs"}),n.jsx("span",{className:"text-foreground",children:u}),r&&n.jsxs("span",{children:["· ",r]}),n.jsx(ju,{state:t.state}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{children:o("Stuck for {{time}}",{time:Dr(l-d)})})]}),n.jsx("div",{className:"mt-2 line-clamp-2 text-muted-foreground text-sm",children:t.task}),n.jsxs("div",{className:"mt-2 rounded-md border border-warning/30 bg-warning/10 px-2 py-1.5 text-xs",children:[n.jsx("div",{className:"line-clamp-4 whitespace-pre-wrap font-medium",children:o("Blocked · needs: {{need}}",{need:t.blocked?.need??""})}),n.jsx("div",{className:"mt-0.5 text-muted-foreground",children:m}),h&&p&&n.jsx(zx,{placeholder:o("Answer {{name}}; they continue after your reply…",{name:u}),onSend:g=>r2(h,p,g,o)})]}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>{a(e)},children:o("Dismiss")}),h&&p&&n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>i(h,p),children:o("Open task card")})]})]})}function hG({inboxKey:e,record:t,bots:s,chatName:r,onOpen:o}){const{t:i}=z(),a=ie(h=>h.setView),l=ie(h=>h.dismissInbox),c=s.get(t.parentBotId),u=s.get(t.targetBotId),d=c?.name??i("Deleted member"),m=u?.name??i("Deleted member");return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground text-xs",children:[n.jsx($t,{bot:c,size:"xs"}),n.jsx("span",{className:"text-foreground",children:d}),n.jsx("span",{children:"→"}),n.jsx($t,{bot:u,size:"xs"}),n.jsx("span",{className:"text-foreground",children:m}),n.jsxs("span",{children:["· ",i("Delegation")]}),r&&n.jsxs("span",{children:["· ",r]}),n.jsx(ju,{state:t.state,interrupted:!0})]}),n.jsx("div",{className:"mt-2 line-clamp-3 text-sm",children:t.task}),n.jsx("div",{className:"mt-1 text-muted-foreground text-xs",children:Dl(t,i)}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>{l(e)},children:i("Dismiss")}),t.chatId&&n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>t.chatId&&a({kind:"chat",chatId:t.chatId}),children:i("Go to chat")}),n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>o(i("{{from}} → {{to}} · Delegation",{from:d,to:m})),children:i("View conversation")}),n.jsx(fe,{size:"xs",onClick:()=>Pa(t.id,i),children:i("Retry")})]})]})}function pG({item:e,bot:t,owner:s,chatName:r}){const{t:o}=z(),i=ie(g=>g.setView),[a,l]=f.useState(""),[c,u]=f.useState(!1),d=g=>{u(!0),g.finally(()=>u(!1))},m=g=>d(window.electronAPI.agent.respondApproval(e.conversationId,e.request.requestId,g)),h=g=>g.trim()&&d(window.electronAPI.agent.respondAsk(e.conversationId,e.request.requestId,g.trim())),p=e.kind==="approval"&&e.request.phase==="reviewing";return n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx($t,{bot:t,size:"sm"}),n.jsx("span",{className:"text-foreground",children:e.delegation?o("{{name}} on behalf of {{owner}}",{name:t?.name??o("Deleted member"),owner:s?.name??o("Deleted member")}):t?.name??o("Deleted member")}),r&&n.jsxs("span",{children:["· ",r]}),n.jsx("span",{className:e.kind==="approval"?"rounded bg-warning/20 px-1.5 text-[11px] text-warning":"rounded bg-info/15 px-1.5 text-[11px] text-info",children:e.kind==="approval"?o("Approval"):o("Question")}),e.kind==="approval"&&e.request.protected&&n.jsx("span",{className:"rounded bg-destructive/15 px-1.5 text-[11px] text-destructive",children:sS(e.request.protected,o)})]}),e.kind==="approval"?n.jsxs("div",{className:"mt-2 text-sm",children:[Rr(e.request.tool,o),n.jsx("pre",{className:"mt-1 max-h-24 overflow-auto whitespace-pre-wrap rounded-md bg-muted/60 px-2 py-1.5 font-mono text-xs",children:e.request.summary})]}):n.jsx("div",{className:"mt-2 whitespace-pre-wrap text-sm",children:e.request.question}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(fe,{size:"xs",variant:"ghost",onClick:()=>i({kind:"chat",chatId:e.chatId}),children:o("Go to chat")}),e.kind==="approval"?p?n.jsx("span",{className:"text-muted-foreground text-xs",children:o("Assistant reviewing…")}):n.jsxs(n.Fragment,{children:[n.jsx(fe,{size:"xs",variant:"outline",disabled:c,onClick:()=>m("deny"),children:o("Deny")}),!e.request.protected&&!e.request.mandatory&&n.jsx(fe,{size:"xs",variant:"outline",disabled:c,onClick:()=>m("allowSession"),children:o("Always allow in this session")}),n.jsx(fe,{size:"xs",disabled:c,onClick:()=>m("allow"),children:o("Allow")})]}):n.jsxs(n.Fragment,{children:[e.request.options?.map(g=>n.jsx(fe,{size:"xs",variant:"outline",disabled:c,onClick:()=>h(g),children:g},g)),n.jsx(Ht,{className:"h-7 w-48",value:a,placeholder:o("Custom answer…"),onChange:g=>l(g.target.value),onKeyDown:g=>{g.nativeEvent.isComposing||c||g.key==="Enter"&&h(a)}}),n.jsx(fe,{size:"xs",disabled:c||!a.trim(),onClick:()=>h(a),children:o("Reply")})]})]})]})}function xG(e){const{openOnInputClick:t=!1,value:s,defaultValue:r,onValueChange:o,mode:i="list",itemToStringValue:a,...l}=e,c=i==="inline"||i==="both",u=i==="inline"||i==="none",d=s!==void 0,[m,h]=f.useState(r??""),[p,g]=f.useState("");f.useEffect(()=>{d&&g("")},[s,d]);let x;c&&p!==""?x=p:d?x=s??"":x=m;const v=jE({locale:l.locale}),b=f.useMemo(()=>l.filter!==void 0?l.filter:v.contains,[l.filter,v]),w=String(d?s:m).trim(),j=f.useMemo(()=>i!=="both"?u?null:b:b===null?null:(S,I,k)=>b(S,w,k),[b,i,w,u]);function T(S,I){g(""),d||h(S),o?.(S,I)}function N(S,I){e.onItemHighlighted?.(S,I),I.reason!==NE&&g(c&&S!=null?SE(S,a):"")}return n.jsx(kE,{...l,itemToStringLabel:a,openOnInputClick:t,selectionMode:"none",fillInputOnItemPress:!0,filter:j,autoComplete:i,inputValue:x,defaultInputValue:r,onInputValueChange:T,onItemHighlighted:N})}const gG=CE,vG="",bG=200;function yG(e){const t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let s=null;for(;t.nextNode();){const r=t.currentNode;r.nodeValue!==""&&(s=r)}return s}function wG(){const e=IE(),t=f.useRef(null);return f.useEffect(()=>{if(TE)return;const s=t.current;if(s==null)return;const r=yG(s);if(r==null)return;const o=r.data,i=`${o}${vG}`;return r.nodeValue=i,e.start(bG,()=>{r.nodeValue===i&&(r.nodeValue=o)}),()=>{e.clear(),r.nodeValue===i&&(r.nodeValue=o)}},[t,e]),t}const w2=f.createContext(void 0);function jG(){const e=f.useContext(w2);if(e===void 0)throw new Error(cl(18));return e}const kG=f.forwardRef(function(t,s){const{render:r,className:o,style:i,items:a,...l}=t,[c,u]=f.useState(),d=f.useMemo(()=>({labelId:c,setLabelId:u,items:a}),[c,u,a]),m=dl("div",t,{ref:s,props:[{role:"group","aria-labelledby":c},l]}),h=n.jsx(w2.Provider,{value:d,children:m});return a?n.jsx(AE,{items:a,children:h}):h}),NG=f.forwardRef(function(t,s){const{render:r,className:o,style:i,id:a,...l}=t,{setLabelId:c}=jG(),u=Zw(a);return Fh(()=>(c(u),()=>{c(m=>m===u?void 0:m)}),[u,c]),dl("div",t,{ref:s,props:[{id:u},l]})}),SG=EE,CG=f.forwardRef(function(t,s){const{render:r,className:o,style:i,children:a,...l}=t,{filteredItems:c}=RE(),u=ME(),d=wG(),m=c.length===0?a:null;return dl("div",t,{ref:[s,u.state.emptyRef,d],props:[{children:m,role:"status","aria-live":"polite","aria-atomic":!0},l]})});function IG(e){const t=e.value.length>0,s=t?e.value.replace(/ /g," "):"",r=e.clearing&&t&&s!==e.mirrorText;return{hasValue:t,mirrorText:s,superseded:r}}const Hx=xG,Da=new WeakMap,Md=new WeakMap;function TG(e){const t=Da.get(e);t!==void 0&&window.clearTimeout(t),Da.delete(e);for(const s of Md.get(e)??[])s.cancel();Md.delete(e),e.classList.remove("is-clearing")}function Jo(e,t){const s=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(e));return Number.isFinite(s)?s:t}function Fc(e){const t=e.querySelector("input"),s=e.querySelector(".t-clear-mirror");if(!t||!s)return;const r=IG({value:t.value,mirrorText:s.textContent??"",clearing:e.classList.contains("is-clearing")});r.superseded&&TG(e),e.classList.toggle("has-value",r.hasValue),s.textContent=r.mirrorText}function AG(e){const t=e.closest(".t-clear"),s=t?.querySelector("input"),r=t?.querySelector(".t-clear-mirror"),o=t?.querySelector(".t-clear-placeholder");if(!t||!s||!r||!o||!s.value)return;const i=Da.get(t);if(i!==void 0&&window.clearTimeout(i),r.textContent=s.value.replace(/ /g," "),o.textContent=s.placeholder,t.classList.remove("has-value"),t.classList.add("is-clearing"),window.matchMedia("(prefers-reduced-motion: reduce)").matches){t.classList.remove("is-clearing"),r.textContent="";return}const a=getComputedStyle(document.documentElement),l=Jo("--clear-dur",1e3),c=Jo("--clear-out-dur",400),u=Jo("--clear-in-dur",400),d=Jo("--clear-out-fly",12),m=Jo("--clear-in-fly",12),h=Jo("--clear-blur",2),p=a.getPropertyValue("--clear-out-ease").trim()||"ease-out",g=a.getPropertyValue("--clear-in-ease").trim()||"ease-out",x=r.animate([{transform:"translateY(0)",opacity:1,filter:"blur(0)"},{transform:`translateY(${d}px)`,opacity:0,filter:`blur(${h}px)`}],{duration:c,easing:p,fill:"forwards"}),v=o.animate([{transform:`translateY(-${m}px)`,opacity:.9,filter:`blur(${h}px)`},{transform:"translateY(0)",opacity:1,filter:"blur(0)"}],{duration:u,easing:g,fill:"forwards"}),b=window.setTimeout(()=>{x.cancel(),v.cancel(),Md.delete(t),t.classList.remove("is-clearing"),r.textContent="",Da.delete(t),Fc(t)},Math.max(l,c,u));Da.set(t,b),Md.set(t,[x,v])}function Wx({className:e,showTrigger:t=!1,showClear:s=!1,startAddon:r,size:o,...i}){const a=o??"default",l=f.useRef(null);return f.useLayoutEffect(()=>{l.current&&Fc(l.current);const c=window.requestAnimationFrame(()=>{l.current&&Fc(l.current)});return()=>window.cancelAnimationFrame(c)}),n.jsxs("div",{ref:l,className:"t-clear autocomplete-clear-dissolve relative w-full",onInput:c=>Fc(c.currentTarget),children:[r&&n.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"autocomplete-start-addon",children:r}),n.jsx(PE,{className:_(r&&"data-[size=sm]:*:data-[slot=autocomplete-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=autocomplete-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=autocomplete-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=autocomplete-input]:ps-[calc(--spacing(8)-1px)]",a==="sm"?"has-[+[data-slot=autocomplete-trigger],+[data-slot=autocomplete-clear]]:*:data-[slot=autocomplete-input]:pe-6.5":"has-[+[data-slot=autocomplete-trigger],+[data-slot=autocomplete-clear]]:*:data-[slot=autocomplete-input]:pe-7",e),"data-slot":"autocomplete-input",render:n.jsx(Ht,{size:a}),...i}),n.jsx("div",{"aria-hidden":"true",className:_("t-clear-mirror px-[calc(--spacing(3)-1px)] text-base sm:text-sm",a==="sm"&&"px-[calc(--spacing(2.5)-1px)]",r&&(a==="sm"?"ps-[calc(--spacing(7.5)-1px)] sm:ps-[calc(--spacing(7)-1px)]":"ps-[calc(--spacing(8.5)-1px)] sm:ps-[calc(--spacing(8)-1px)]"))}),n.jsx("div",{"aria-hidden":"true",className:_("t-clear-placeholder px-[calc(--spacing(3)-1px)] text-base text-muted-foreground/72 opacity-0 sm:text-sm",a==="sm"&&"px-[calc(--spacing(2.5)-1px)]",r&&(a==="sm"?"ps-[calc(--spacing(7.5)-1px)] sm:ps-[calc(--spacing(7)-1px)]":"ps-[calc(--spacing(8.5)-1px)] sm:ps-[calc(--spacing(8)-1px)]")),children:i.placeholder}),n.jsx("div",{"aria-hidden":"true",className:"t-clear-glow"}),t&&n.jsx(PG,{className:_("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-colors pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=autocomplete-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",a==="sm"?"end-0":"end-0.5"),children:n.jsx(DE,{})}),s&&n.jsx(MG,{className:_("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-colors pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=autocomplete-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",a==="sm"?"end-0":"end-0.5"),children:n.jsx(Jt,{})})]})}function j2({className:e,children:t,sideOffset:s=4,zIndex:r,...o}){return n.jsx(OE,{children:n.jsx(LE,{className:"z-[55] select-none",style:r?{zIndex:r}:void 0,"data-slot":"autocomplete-positioner",sideOffset:s,children:n.jsx("span",{className:_("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",e),children:n.jsx(_E,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"autocomplete-popup",...o,children:t})})})})}function Ux({className:e,children:t,...s}){return n.jsx(SG,{className:_("flex min-h-8 cursor-default select-none items-center rounded-sm px-2 py-1 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm",e),"data-slot":"autocomplete-item",...s,children:t})}function EG({className:e,...t}){return n.jsx(kG,{className:_("[[role=group]+&]:mt-1.5",e),"data-slot":"autocomplete-group",...t})}function RG({className:e,...t}){return n.jsx(NG,{className:_("px-2 py-1.5 font-medium text-muted-foreground text-xs",e),"data-slot":"autocomplete-group-label",...t})}function qx({className:e,...t}){return n.jsx(CG,{className:_("not-empty:p-2 text-center text-base text-muted-foreground sm:text-sm",e),"data-slot":"autocomplete-empty",...t})}function Gx({className:e,...t}){return n.jsx(BE,{scrollbarGutter:!0,scrollFade:!0,children:n.jsx(FE,{className:_("not-empty:scroll-py-1 not-empty:p-1 in-data-has-overflow-y:pe-3",e),"data-slot":"autocomplete-list",...t})})}function MG({className:e,onClickCapture:t,onPointerDownCapture:s,...r}){return n.jsx(zE,{className:_("-translate-y-1/2 absolute end-0.5 top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-[color,background-color,box-shadow,opacity] pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",e),"data-slot":"autocomplete-clear",onClickCapture:o=>{t?.(o),o.defaultPrevented||AG(o.currentTarget)},onPointerDownCapture:o=>{s?.(o);const i=o.currentTarget.closest(".t-clear")?.querySelector("input");!o.defaultPrevented&&document.activeElement===i&&o.preventDefault()},...r,children:n.jsx(Jt,{})})}function PG({className:e,...t}){return n.jsx(gG,{className:e,"data-slot":"autocomplete-trigger",...t})}const k2=f.createContext({inputRef:null}),N2=$E,DG=VE;function OG({className:e,...t}){return n.jsx(UE,{className:_("fixed inset-0 z-50 bg-black/32 backdrop-blur-sm transition-all duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0",e),"data-slot":"command-dialog-backdrop",...t})}function LG({className:e,...t}){return n.jsx(qE,{className:_("fixed inset-0 z-50 flex flex-col items-center px-4 py-[max(--spacing(4),4vh)] sm:py-[10vh]",e),"data-slot":"command-dialog-viewport",...t})}function S2({className:e,children:t,...s}){const r=f.useRef(null);return n.jsxs(DG,{children:[n.jsx(HE,{}),n.jsx(OG,{}),n.jsx(LG,{children:n.jsx(WE,{className:_("-translate-y-[calc(1.25rem*var(--nested-dialogs))] relative row-start-2 flex max-h-100 min-h-0 w-full min-w-0 max-w-xl scale-[calc(1-0.1*var(--nested-dialogs))] flex-col rounded-2xl border bg-popover bg-clip-padding text-popover-foreground opacity-[calc(1-0.1*var(--nested-dialogs))] shadow-lg transition-[scale,opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:bg-muted/50 before:shadow-[0_1px_--theme(--color-black/4%)] data-nested:data-ending-style:translate-y-8 data-nested:data-starting-style:translate-y-8 data-nested-dialog-open:origin-top data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 **:data-[slot=scroll-area-viewport]:data-has-overflow-y:pe-1 dark:bg-clip-border dark:before:shadow-[0_-1px_--theme(--color-white/8%)]",e),"data-slot":"command-dialog-popup",initialFocus:r,...s,children:n.jsx(k2.Provider,{value:{inputRef:r},children:t})})})]})}function C2({autoHighlight:e="always",keepHighlight:t=!0,open:s=!0,...r}){return n.jsx(Hx,{autoHighlight:e,keepHighlight:t,open:s,...r})}function I2({className:e,placeholder:t=void 0,endAddon:s,...r}){const{inputRef:o}=f.useContext(k2);return n.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(Wx,{className:_("border-transparent! bg-transparent! shadow-none before:hidden has-focus-visible:ring-0",e),placeholder:t,ref:o,size:"lg",startAddon:n.jsx(dr,{}),...r})}),s]})}function T2({className:e,...t}){return n.jsx(Gx,{className:_("not-empty:scroll-py-2 not-empty:p-2",e),"data-slot":"command-list",...t})}function A2({className:e,...t}){return n.jsx(qx,{className:_("not-empty:py-6",e),"data-slot":"command-empty",...t})}function E2({className:e,...t}){return n.jsx("div",{className:"-mx-px relative min-h-0 rounded-t-xl border bg-popover bg-clip-padding shadow-xs [clip-path:inset(0_1px)] before:pointer-events-none before:absolute before:inset-0 before:rounded-t-[calc(var(--radius-xl)-1px)] **:data-[slot=scroll-area-scrollbar]:mt-2 dark:bg-clip-border dark:before:shadow-[0_-1px_--theme(--color-white/8%)]",...t})}function Zo({className:e,...t}){return n.jsx(EG,{className:e,"data-slot":"command-group",...t})}function ei({className:e,...t}){return n.jsx(RG,{className:e,"data-slot":"command-group-label",...t})}function No({className:e,...t}){return n.jsx(Ux,{className:_("py-1.5",e),"data-slot":"command-item",...t})}function vy({className:e,...t}){return n.jsx("span",{className:_("ms-auto font-medium text-muted-foreground/72 text-xs tracking-widest",e),"data-slot":"command-shortcut",...t})}function R2({className:e,...t}){return n.jsx("div",{className:_("flex items-center justify-between gap-2 rounded-b-[calc(var(--radius-2xl)-1px)] px-5 py-3 text-muted-foreground text-xs",e),"data-slot":"command-footer",...t})}const by=e=>e.locator.kind==="timeline"?`${e.chatId}:${e.locator.seq}`:`${e.chatId}:${e.locator.conversationId}:${e.locator.messageIndex}`;function M2({className:e}){const{t}=z(),s=pe(i=>i.keybindings),r=Pr(s)["search-workspace"],o=t("Search messages");return n.jsx("button",{type:"button",className:e,onClick:()=>ie.getState().setSearchOpen(!0),title:r?`${o} (${qs(r)})`:o,children:n.jsx(dr,{className:"h-4 w-4"})})}function _G(){const{t:e,locale:t}=z(),s=ie(v=>v.searchOpen),r=ie(v=>v.setSearchOpen),o=ie(v=>v.bots),i=ie(v=>v.chats),[a,l]=f.useState(""),[c,u]=f.useState(),d=a.trim(),m=f.useMemo(()=>new Map(o.map(v=>[v.id,v])),[o]),h=f.useMemo(()=>new Map(i.map(v=>[v.id,v])),[i]),p=c?.key===d?c:void 0;f.useEffect(()=>{s||(l(""),u(void 0))},[s]),f.useEffect(()=>{if(!s||!d)return;let v=!1;const b=window.setTimeout(()=>{window.electronAPI.bots.search({query:d}).then(w=>{v||u(w.ok?{key:d,hits:w.hits,truncated:w.truncated}:{key:d,hits:[],truncated:!1})}).catch(()=>{v||u({key:d,hits:[],truncated:!1})})},150);return()=>{v=!0,window.clearTimeout(b)}},[s,d]);const g=v=>{v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),r(!1))},x=Date.now();return n.jsx(N2,{open:s,onOpenChange:r,children:n.jsx(S2,{className:"max-h-[min(36rem,calc(100vh-6rem))] max-w-2xl",onKeyDown:g,children:n.jsxs(C2,{children:[n.jsx(I2,{placeholder:e("Search group and direct messages…"),value:a,onChange:v=>l(v.currentTarget.value),onKeyDown:v=>{g(v);const b=p?.hits[0];v.key==="Enter"&&!v.nativeEvent.isComposing&&b&&!document.querySelector('[data-slot="command-dialog-popup"] [data-highlighted]')&&(v.preventDefault(),ie.getState().focusHit(b,d))}}),n.jsxs(E2,{children:[d&&p&&p.hits.length===0&&n.jsx(A2,{children:e("No matching messages")}),n.jsxs(T2,{children:[p?.hits.map(v=>{const b=h.get(v.chatId),w=(b?.members??[]).map(N=>m.get(N)).filter(N=>N!==void 0),j=v.speaker.kind==="human"?e("You"):m.get(v.speaker.botId)?.name??e("Deleted member"),T=v.locator.kind==="session"&&!v.locator.current?` · ${e("History")}`:"";return n.jsxs(No,{value:by(v),className:"items-start gap-2.5",onClick:()=>ie.getState().focusHit(v,d),children:[n.jsx("span",{className:"mt-0.5 shrink-0",children:v.chatKind==="direct"?n.jsx($t,{bot:w[0]}):n.jsx(ma,{bots:w})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-xs",children:[n.jsx("span",{className:"truncate font-medium",children:b?is(b,o,e):e("Deleted chat")}),n.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[j,T]})]}),n.jsx("p",{className:"line-clamp-2 break-words text-muted-foreground text-xs",children:$q(v.snippet,v.ranges).map((N,S)=>N.match?n.jsx("mark",{className:"rounded-[3px] bg-brand/14 text-foreground",children:N.text},S):n.jsx("span",{children:N.text},S))})]}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:v.at?Lo(v.at,t,x):""})]},by(v))}),p?.truncated&&n.jsx("p",{className:"px-2 py-1.5 text-center text-muted-foreground text-xs",children:e("Showing the latest {{n}} matches",{n:p.hits.length})})]})]}),n.jsxs(R2,{children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsxs(Yj,{children:[n.jsx(Vs,{children:"↑"}),n.jsx(Vs,{children:"↓"})]}),e("Navigate")]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx(Vs,{children:"↵"}),e("Open")]})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx(Vs,{children:"esc"}),e("Close")]})]})]})})})}function BG({chat:e,onOpenChange:t}){const{t:s}=z(),r=ie(p=>p.bots),o=ie(p=>p.chats),i=pe(p=>p.projects),[a,l]=f.useState(""),[c,u]=f.useState(!1);if(f.useEffect(()=>{if(!e)return;const p=o.filter(g=>g.kind==="group").map(g=>g.title);l(GE(s("{{title}} copy",{title:is(e,r,s)}),p)),u(!1)},[e?.id]),!e)return null;const d=p=>r.find(g=>g.id===p)?.name??"—",m=`${e.routing.mode==="smart"?s("Smart pick"):s("Group owner replies")} · ${s("Relay {{hops}} · {{turns}} replies each",{hops:e.routing.maxHops,turns:e.routing.maxTurnsPerBot})}`,h=async()=>{const p=a.trim();if(p){u(!0);try{const g=await window.electronAPI.bots.cloneChat({chatId:e.id,title:p});if(!g.ok){Ie({type:"error",title:ds(g.error,s)});return}const x=ie.getState();x.upsertChat(g.chat),x.setView({kind:"chat",chatId:g.chat.id}),x.loadLatest(g.chat.id),Ie({type:"success",title:s("Cloned. The chat history is empty.")}),t(!1)}finally{u(!1)}}};return n.jsx(cn,{open:!0,onOpenChange:t,children:n.jsxs(dn,{className:"max-w-md",children:[n.jsxs(un,{children:[n.jsx(rn,{children:s("Clone group chat")}),n.jsx(ys,{children:s("Copies the setup of “{{title}}”. The original stays as is; replies in progress are not stopped.",{title:is(e,r,s)})})]}),n.jsxs(In,{className:"space-y-4 text-sm",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:s("Group name")}),n.jsx(Ht,{value:a,autoFocus:!0,onChange:p=>l(p.target.value),onKeyDown:p=>{p.nativeEvent.isComposing||c||p.key==="Enter"&&h()}})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(Ot,{children:s("Will copy")}),n.jsxs("p",{children:[n.jsxs("span",{className:"text-muted-foreground",children:[s("Members"),":"]}),e.members.map(d).join("、")]}),n.jsxs("p",{children:[n.jsxs("span",{className:"text-muted-foreground",children:[s("Owner"),":"]}),d(e.bossBotId)]}),n.jsxs("p",{children:[n.jsxs("span",{className:"text-muted-foreground",children:[s("Routing"),":"]}),m]}),n.jsxs("p",{children:[n.jsxs("span",{className:"text-muted-foreground",children:[s("Workspace"),":"]}),e.workspace.kind==="project"?s("Same project: {{name}}",{name:$j(e,i,r,s)}):s("A new empty folder, separate from the original")]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(Ot,{children:s("Not copied")}),n.jsx("p",{className:"text-muted-foreground",children:s("Chat history, group notes, routines, task board and group memory")})]})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>t(!1),children:s("Cancel")}),n.jsx(fe,{size:"sm",disabled:!a.trim()||c,onClick:()=>{h()},children:s("Clone")})]})]})})}const yo="relative flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";function FG({width:e,onCollapse:t,onNewMember:s,onNewGroup:r,onNewTeam:o,onStartFromGoal:i}){const{t:a,locale:l}=z(),c=[{label:a("Start from a goal"),icon:Fi,onClick:i},{label:a("New member"),icon:Ya,onClick:s},{label:a("New group chat"),icon:ki,onClick:r},{label:a("Create team from template"),icon:um,onClick:o}],u=ie(X=>X.bots),d=ie(X=>X.chats),m=ie(X=>X.queue),h=ie(X=>X.sessions),p=ie(X=>X.delegations),g=ie(X=>X.timelines),x=ie(X=>X.reads),v=ie(X=>X.view),b=ie(X=>X.setView),w=ie(X=>X.openDirect),j=ie(X=>X.upsertChat),T=ie(X=>X.upsertBot),[N,S]=f.useState(!1),[I,k]=f.useState(""),[L,F]=f.useState(null),[A,M]=f.useState(null),R=f.useMemo(()=>new Map(u.map(X=>[X.id,X])),[u]),$=f.useMemo(()=>Object.fromEntries(u.map(X=>[X.id,X.name])),[u]),U=f.useMemo(()=>Uj(h,qj(d,p)),[h,d,p]),q=f.useMemo(()=>{const X=new Set,K=new Set;for(const Ee of p)_a(Ee.state)&&(Ee.chatId&&X.add(Ee.chatId),K.add(Ee.targetBotId));return{chatIds:X,botIds:K}},[p]),te=f.useMemo(()=>KE(d.map(X=>{const K=ep(X,{sessions:h,timeline:g[X.id],queue:m,names:$});return{chat:X,summary:{...K,running:K.running||(X.kind==="group"?q.chatIds.has(X.id):q.botIds.has(X.members[0])),pending:U.filter(Ee=>Ee.chatId===X.id).length}}}),x),[d,h,g,m,$,U,q,x]),V=te.filter(X=>!X.chat.archivedAt),se=YE(V.filter(X=>X.chat.kind==="group"&&X.chat.settledAt===void 0)),Ce=new Map(V.filter(X=>X.chat.kind==="direct").map(X=>[X.chat.members[0],X])),de=u.filter(X=>X.archivedAt===void 0&&Ce.get(X.id)?.chat.settledAt===void 0).map(X=>({bot:X,row:Ce.get(X.id)})).sort((X,K)=>{const Ee=Number(K.row?.chat.pinned??!1)-Number(X.row?.chat.pinned??!1),pt=(X.row?.chat.pinOrder??Number.POSITIVE_INFINITY)-(K.row?.chat.pinOrder??Number.POSITIVE_INFINITY);return Ee||(X.row?.chat.pinned&&pt?pt:0)||(K.row?.summary.activityAt??K.bot.updatedAt)-(X.row?.summary.activityAt??X.bot.updatedAt)}),re=V.filter(X=>X.chat.settledAt!==void 0&&(X.chat.kind==="group"||R.get(X.chat.members[0])?.archivedAt===void 0)).sort((X,K)=>(K.chat.settledAt??0)-(X.chat.settledAt??0)),Z=se.filter(X=>X.chat.pinned).map(X=>X.chat.id),me=de.flatMap(({row:X})=>X?.chat.pinned?[X.chat.id]:[]),[xe,Se]=f.useState(null),[W,H]=f.useState(!0),B=te.filter(X=>X.chat.archivedAt!==void 0),ne=u.filter(X=>X.archivedAt!==void 0),ve=B.length+ne.length,he=I.trim().toLowerCase(),G=(...X)=>!he||X.some(K=>K.toLowerCase().includes(he)),we=B.filter(({chat:X,summary:K})=>G(is(X,u,a),K.preview??"")).sort((X,K)=>(K.chat.archivedAt??0)-(X.chat.archivedAt??0)),ce=ne.filter(X=>G(X.name,X.title,X.scope)).sort((X,K)=>(K.archivedAt??0)-(X.archivedAt??0)),Re=ip(),ue=v?.kind==="chat"?v.chatId:null,We=async(X,K)=>{const Ee=await window.electronAPI.bots.updateChat({chatId:X.id,...K});Ee.ok?j(Ee.chat):Ie({type:"error",title:ds(Ee.error,a)})},it=X=>We(X,X.pinned?{pinned:!1}:{pinned:!0,pinOrder:Math.max(-1,...d.filter(K=>K.pinned).map(K=>K.pinOrder??0))+1}),Fe=(X,K,Ee)=>{const pt=Object.fromEntries(d.map(Pt=>[Pt.id,Pt.pinOrder]));for(const Pt of JE(X,K,Ee,pt)){const Je=d.find(Lt=>Lt.id===Pt.chatId);Je&&We(Je,{pinOrder:Pt.pinOrder})}},tt=(X,K)=>{const Ee=K.indexOf(X.id),pt=te.find(Pt=>Pt.chat.id===X.id)?.summary;return{onSettle:()=>{We(X,{settled:X.settledAt===void 0})},onSnooze:Pt=>{We(X,{snoozedUntil:Pt})},onMarkUnread:pt&&ue!==X.id&&!la(pt.marker,x[pt.key])&&XE(pt.marker)!==void 0?()=>ie.getState().markUnread(X.id):void 0,onMoveUp:Ee>0?()=>Fe(K,X.id,Ee-1):void 0,onMoveDown:Ee>=0&&Ee<K.length-1?()=>Fe(K,X.id,Ee+1):void 0}},ke=(X,K)=>X?.pinned?{draggable:!0,onDragStart:Ee=>{Ee.dataTransfer.effectAllowed="move",Se(X.id)},onDragEnd:()=>Se(null),onDragOver:Ee=>{xe&&xe!==X.id&&K.includes(xe)&&Ee.preventDefault()},onDrop:Ee=>{Ee.preventDefault(),xe&&K.includes(xe)&&Fe(K,xe,K.indexOf(X.id)),Se(null)}}:{},nt=async(X,K)=>{const Ee=await window.electronAPI.bots.archive(X.id,K);Ee.ok?T(Ee.bot):Ie({type:"error",title:Ee.error})},mt=X=>X?X.running?a("Working"):X.queued?a("Queued"):X.activityAt?Lo(X.activityAt,l):null:null;return n.jsxs("aside",{className:"flex shrink-0 flex-col overflow-hidden border-r bg-background",style:{width:e},children:[n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pt-2 pb-2",children:[n.jsx(Of,{title:a("Group chats"),onAdd:r,addLabel:a("New group chat")}),se.length===0&&n.jsx("p",{className:"px-4 py-1 text-muted-foreground text-xs",children:a("No group chats yet")}),se.map(({chat:X,summary:K})=>n.jsx(_f,{chat:X,onPin:()=>{it(X)},onArchive:()=>{We(X,{archived:!0})},onDelete:()=>F(X),onClone:()=>M(X),manage:tt(X,Z),children:n.jsx(Lf,{...ke(X,Z),active:ue===X.id,avatar:n.jsx(ma,{bots:X.members.map(Ee=>R.get(Ee)),busy:K.running}),title:is(X,u,a),pinned:X.pinned,meta:mt(K),preview:K.preview,unread:la(K.marker,x[K.key]),pending:K.pending,onClick:()=>b({kind:"chat",chatId:X.id})})},X.id)),n.jsx(Of,{title:a("Members"),onAdd:s,addLabel:a("New member")}),de.length===0&&n.jsx("p",{className:"px-4 py-1 text-muted-foreground text-xs",children:a("No members yet")}),de.map(({bot:X,row:K})=>n.jsx(_f,{chat:K?.chat,onPin:K?()=>{it(K.chat)}:void 0,onArchive:K?()=>{We(K.chat,{archived:!0})}:void 0,onArchiveMember:()=>{nt(X,!0)},manage:K?tt(K.chat,me):void 0,children:n.jsx(Lf,{...ke(K?.chat,me),active:!!(K&&ue===K.chat.id),avatar:n.jsx($t,{bot:X,busy:K?.summary.running||q.botIds.has(X.id)}),title:X.name,pinned:K?.chat.pinned,meta:q.botIds.has(X.id)?a("Working"):mt(K?.summary),preview:K?.summary.preview||X.title||X.scope,unread:!!(K&&la(K.summary.marker,x[K.summary.key])&&ue!==K.chat.id),pending:K?.summary.pending??0,onClick:()=>{w(X.id)}})},X.id)),re.length>0&&n.jsx(Of,{title:`${a("Settled")} · ${re.length}`,onToggle:()=>H(X=>!X)}),W&&re.map(({chat:X,summary:K})=>{const Ee=X.kind==="direct"?R.get(X.members[0]):void 0;return n.jsx(_f,{chat:X,onPin:()=>{it(X)},onArchive:()=>{We(X,{archived:!0})},onClone:X.kind==="group"?()=>M(X):void 0,manage:tt(X,[]),children:n.jsx(Lf,{className:"opacity-75",active:ue===X.id,avatar:Ee?n.jsx($t,{bot:Ee,busy:K.running}):n.jsx(ma,{bots:X.members.map(pt=>R.get(pt)),busy:K.running}),title:Ee?Ee.name:is(X,u,a),meta:X.snoozedUntil!==void 0?a("Remind {{time}}",{time:Lo(X.snoozedUntil,l)}):mt(K),preview:K.preview,unread:la(K.marker,x[K.key])&&(X.kind==="group"||ue!==X.id),pending:K.pending,onClick:()=>Ee?void w(Ee.id):b({kind:"chat",chatId:X.id})})},X.id)})]}),n.jsxs("div",{className:"@container flex shrink-0 items-center justify-between border-t p-2",children:[t?n.jsx("button",{type:"button",onClick:t,className:yo,title:a("Collapse sidebar"),children:n.jsx(tx,{className:"h-4 w-4"})}):n.jsx("span",{}),n.jsxs("div",{className:"flex items-center",children:[n.jsx(M2,{className:yo}),c.map(({label:X,icon:K,onClick:Ee})=>n.jsx("button",{type:"button",className:_(yo,"hidden @min-[18.5rem]:flex"),onClick:Ee,title:X,children:n.jsx(K,{className:"h-4 w-4"})},X)),n.jsxs(mr,{children:[n.jsx(hr,{className:_(yo,"@min-[18.5rem]:hidden"),title:a("More actions"),children:n.jsx(kl,{className:"h-4 w-4"})}),n.jsx(pr,{align:"end",side:"top",children:c.map(({label:X,icon:K,onClick:Ee})=>n.jsxs(Cn,{onClick:Ee,children:[n.jsx(K,{}),X]},X))})]}),(Re>0||v?.kind==="inbox")&&n.jsxs("button",{type:"button",className:_(yo,v?.kind==="inbox"&&"bg-brand/10 text-foreground hover:bg-brand/10 dark:bg-brand/15 dark:hover:bg-brand/15"),onClick:()=>b({kind:"inbox"}),title:a("Inbox"),children:[n.jsx(ex,{className:"h-4 w-4"}),Re>0&&n.jsx(Cu,{count:Re,className:"-top-0.5 -right-1 absolute"})]}),ve>0&&n.jsx("button",{type:"button",className:yo,onClick:()=>{k(""),S(!0)},title:`${a("Archived")} (${ve})`,children:n.jsx(lr,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:yo,onClick:()=>{window.electronAPI.window.openSettings()},title:a("Settings"),children:n.jsx(Os,{className:"h-4 w-4"})})]})]}),n.jsx(cn,{open:N,onOpenChange:S,children:n.jsxs(dn,{className:"h-[min(40rem,85vh)] max-w-xl",children:[n.jsxs(un,{children:[n.jsxs(rn,{className:"flex items-baseline gap-2",children:[a("Archived"),n.jsx("span",{className:"font-sans text-muted-foreground text-sm tabular-nums",children:ve})]}),n.jsxs(sp,{"data-size":"sm",className:"mt-1",children:[n.jsx(rp,{children:n.jsx(dr,{})}),n.jsx(op,{value:I,placeholder:a("Search conversations..."),onChange:X=>k(X.target.value)})]})]}),n.jsxs(In,{className:"flex flex-col gap-y-3 border-t pt-3!",children:[we.length+ce.length===0&&n.jsx("p",{className:"py-10 text-center text-muted-foreground text-sm",children:I.trim()?a("No matching conversations"):a("Nothing archived")}),we.length>0&&n.jsx(yy,{title:a("Chat threads"),count:we.length,children:we.map(({chat:X,summary:K})=>n.jsx(wy,{avatar:X.kind==="group"?n.jsx(ma,{bots:X.members.map(Ee=>R.get(Ee))}):n.jsx($t,{bot:R.get(X.members[0])}),title:is(X,u,a),preview:K.preview,onOpen:()=>{b({kind:"chat",chatId:X.id}),S(!1)},onRestore:()=>{We(X,{archived:!1})},onDelete:X.kind==="group"?()=>F(X):void 0},X.id))}),ce.length>0&&n.jsx(yy,{title:a("Members"),count:ce.length,children:ce.map(X=>n.jsx(wy,{avatar:n.jsx($t,{bot:X}),title:X.name,preview:X.title||X.scope,onRestore:()=>{nt(X,!1)}},X.id))})]})]})}),n.jsx(cs,{open:L!==null,onOpenChange:X=>!X&&F(null),title:a("Delete group chat?"),description:a("The group timeline and its standalone workspace are deleted. Member sessions stay readable in their history."),confirmLabel:a("Delete"),onConfirm:()=>{const X=L;F(null),X&&window.electronAPI.bots.deleteChat(X.id).then(K=>{K.ok?(ue===X.id&&b(null),ie.getState().refreshChats()):Ie({type:"error",title:ds(K.error,a)})})}}),n.jsx(BG,{chat:A,onOpenChange:X=>!X&&M(null)})]})}function Cu({count:e,className:t}){return n.jsx("span",{className:_("min-w-4 rounded-full bg-destructive px-1 text-center font-medium text-[10px] text-white leading-4",t),children:e>99?"99+":e})}function yy({title:e,count:t,children:s}){return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 pr-0.5 pl-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate py-1 font-medium text-[10px] text-muted-foreground uppercase tracking-wide",children:e}),n.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground tabular-nums",children:t})]}),n.jsx("div",{className:"flex flex-col gap-y-0.5",children:s})]})}function wy({avatar:e,title:t,preview:s,onOpen:r,onRestore:o,onDelete:i}){const{t:a}=z(),l="shrink-0 rounded p-1 text-muted-foreground opacity-0 hover:bg-muted hover:text-foreground group-hover:opacity-100";return n.jsxs("div",{className:"group flex items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-muted/60",children:[n.jsxs("button",{type:"button",disabled:!r,onClick:r,className:"flex min-w-0 flex-1 items-center gap-2.5 text-left disabled:cursor-default",children:[e,n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-sm",children:t}),s&&n.jsx("span",{className:"block truncate text-muted-foreground text-xs",children:s})]})]}),n.jsx("button",{type:"button",className:l,onClick:o,title:a("Unarchive"),children:n.jsx(Ga,{className:"h-3.5 w-3.5"})}),i&&n.jsx("button",{type:"button",className:_(l,"hover:text-destructive"),onClick:i,title:a("Delete"),children:n.jsx(vs,{className:"h-3.5 w-3.5"})})]})}function Of({title:e,onAdd:t,addLabel:s,onToggle:r}){return n.jsxs("div",{className:"flex items-center justify-between px-4 pt-3 pb-1 text-[11px] text-muted-foreground",children:[r?n.jsx("button",{type:"button",onClick:r,className:"hover:text-foreground",children:e}):n.jsx("span",{children:e}),t&&n.jsx("button",{type:"button",onClick:t,title:s,"aria-label":s,className:"rounded p-0.5 transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Qn,{className:"h-3.5 w-3.5"})})]})}function Lf({active:e,avatar:t,title:s,pinned:r,meta:o,preview:i,unread:a,pending:l=0,action:c,className:u,...d}){return n.jsxs("div",{role:"button",tabIndex:0,...d,onKeyDown:m=>{m.key==="Enter"&&d.onClick?.(m)},className:_("mx-1.5 flex cursor-default items-center gap-2.5 rounded-lg px-2.5 py-1.5 transition-colors",e?"bg-brand/10 dark:bg-brand/15":"hover:bg-muted",u),children:[t,n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"min-w-0 truncate font-medium text-sm",children:s}),r&&n.jsx(Ss,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"flex-1"}),l>0?n.jsx(Cu,{count:l}):o&&n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:o})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground text-xs",children:i}),a&&n.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-info"}),c&&n.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),c.onClick()},className:"shrink-0 rounded px-1.5 text-[11px] text-muted-foreground hover:bg-background hover:text-foreground",children:c.label})]})]})]})}function _f({chat:e,children:t,onPin:s,onArchive:r,onDelete:o,onArchiveMember:i,onClone:a,manage:l}){const{t:c}=z(),u=d=>l?.onSnooze(QE(Date.now())[d]);return n.jsxs(Yr,{children:[n.jsx(Xr,{render:t}),n.jsxs(Qr,{className:"min-w-40",children:[s&&n.jsxs(Kt,{onClick:s,children:[e?.pinned?n.jsx(vd,{}):n.jsx(Ss,{}),e?.pinned?c("Unpin"):c("Pin")]}),l?.onMoveUp&&n.jsxs(Kt,{onClick:l.onMoveUp,children:[n.jsx(Wd,{}),c("Move up")]}),l?.onMoveDown&&n.jsxs(Kt,{onClick:l.onMoveDown,children:[n.jsx(Vh,{}),c("Move down")]}),l&&n.jsxs(Kt,{onClick:l.onSettle,children:[e?.settledAt!==void 0?n.jsx(Mr,{}):n.jsx(Bh,{}),e?.settledAt!==void 0?c("Back to in progress"):c("Settle")]}),l&&n.jsxs(ap,{children:[n.jsxs(lp,{children:[n.jsx(qa,{}),c("Remind me later")]}),n.jsxs(cp,{className:"min-w-36",children:[n.jsx(Kt,{onClick:()=>u("hour"),children:c("In 1 hour")}),n.jsx(Kt,{onClick:()=>u("later"),children:c("In 3 hours")}),n.jsx(Kt,{onClick:()=>u("tomorrow"),children:c("Tomorrow 9:00")})]})]}),l?.onMarkUnread&&n.jsxs(Kt,{onClick:l.onMarkUnread,children:[n.jsx(wB,{}),c("Mark as unread")]}),a&&n.jsxs(Kt,{onClick:a,children:[n.jsx(ul,{}),c("Clone group chat")]}),r&&n.jsxs(Kt,{onClick:r,children:[n.jsx(lr,{}),c("Archive chat")]}),i&&n.jsxs(Kt,{onClick:i,children:[n.jsx(Ga,{}),c("Archive member")]}),o&&n.jsxs(n.Fragment,{children:[n.jsx(dp,{}),n.jsxs(Kt,{variant:"destructive",onClick:o,children:[n.jsx(vs,{}),c("Delete group chat")]})]})]})]})}const zG=30;function jy({onPick:e}){const{t,locale:s}=z(),r=s==="zh"?"zh":"en",o=Xj(),i=ie(T=>T.bots),[a,l]=f.useState(""),[c,u]=f.useState(!1),[d,m]=f.useState(null),[h,p]=f.useState(null),[g,x]=f.useState(""),v=async()=>{if(!(!a.trim()||c)){u(!0),m(null);try{const T=await window.electronAPI.bots.suggestGoal({goal:a.trim(),language:r,...i.length?{members:i.map(({id:N,name:S,title:I,scope:k})=>({id:N,name:S,title:I,scope:k}))}:{},templates:o.slice(0,zG).map(({id:N,data:S})=>({id:N,title:S.title,summary:S.summary}))});if(!T.ok){m(Su(T,t));return}p(T.suggestion),x(T.suggestion.firstMessage)}finally{u(!1)}}},b=async T=>{if(!c){u(!0),m(null);try{await e(T)}catch{m(t("Could not open chat. Try again."))}finally{u(!1)}}};if(!h)return n.jsxs("div",{className:"w-full max-w-lg space-y-2 text-left",children:[n.jsx(Gs,{value:a,autoFocus:!0,rows:3,placeholder:t("e.g. Track competitor news every week and send me a summary"),onChange:T=>l(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.metaKey||T.ctrlKey)&&v()}}),d&&n.jsx("p",{className:"text-destructive text-xs",children:d}),n.jsx("div",{className:"flex justify-end",children:n.jsxs(fe,{size:"sm",disabled:!a.trim()||c,onClick:()=>{v()},children:[c?n.jsx(_t,{className:"animate-spin"}):n.jsx(Bs,{}),t("Recommend")]})})]});const w=h.kind==="team"?o.find(T=>T.id===h.templateId)?.data:void 0,j=h.kind==="existing"?i.find(T=>T.id===h.botId):h.kind==="member"?{...h.member,avatar:{color:jo[0]}}:void 0;return n.jsxs("div",{className:"w-full max-w-lg space-y-3 text-left",children:[n.jsxs("div",{"data-slot":"bot-card",className:"rounded-xl border bg-card p-3",children:[n.jsxs("p",{className:"mb-2 flex items-center gap-1.5 text-muted-foreground text-xs",children:[n.jsx(Fi,{className:"h-3.5 w-3.5"}),h.kind==="team"?t("Recommended: a team"):t("Recommended: one member")]}),j?n.jsxs("div",{className:"flex items-start gap-2.5",children:[n.jsx($t,{bot:j}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{className:"font-medium text-sm",children:[j.name,n.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:j.title})]}),j.scope&&n.jsx("p",{className:"text-muted-foreground text-xs",children:j.scope})]})]}):w&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("div",{className:"-space-x-1.5 flex",children:w.members.map(T=>n.jsx($t,{size:"sm",bot:{name:T.name,avatar:{color:T.color}}},T.key))}),n.jsx("p",{className:"font-medium text-sm",children:w.title}),n.jsx("p",{className:"text-muted-foreground text-xs",children:w.summary})]}),h.reason&&n.jsx("p",{className:"mt-2 text-muted-foreground text-xs",children:h.reason})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("p",{className:"text-muted-foreground text-xs",children:t("First message (put into the input box, not sent)")}),n.jsx(Gs,{value:g,rows:3,onChange:T=>x(T.target.value)})]}),d&&n.jsx("p",{className:"text-destructive text-xs",children:d}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(fe,{size:"sm",variant:"ghost",disabled:c,onClick:()=>{p(null),m(null)},children:[n.jsx(Ei,{}),t("Back")]}),n.jsxs("div",{className:"flex gap-2",children:[h.kind==="existing"&&n.jsx(fe,{size:"sm",variant:"outline",disabled:c,onClick:()=>{b({firstMessage:g})},children:t("Create new instead")}),n.jsx(fe,{size:"sm",disabled:c||h.kind==="existing"&&!j,onClick:()=>{b(h.kind==="existing"?{firstMessage:g,botId:h.botId}:h.kind==="member"?{firstMessage:g,member:h.member}:{firstMessage:g,templateId:h.templateId})},children:h.kind==="existing"?t("Use this member"):h.kind==="member"?t("Create this member"):t("Create this team")})]})]})]})}const sc=e=>({...KC,name:"",title:"",scope:"",persona:"",color:e,engine:null});function $G({open:e,onOpenChange:t,seed:s,onCreated:r}){const{t:o}=z(),i=ie(M=>M.bots),a=ZE(),l=f.useRef(null),[c,u]=f.useState({kind:"template",id:"pm"}),[d,m]=f.useState(()=>sc(jo[0])),[h,p]=f.useState(null),[g,x]=f.useState(null),[v,b]=f.useState(!1),[w,j]=f.useState(!1),[T,N]=f.useState(!1),S=()=>{u({kind:"blank"}),m(sc(jo[i.length%jo.length])),p(null),x(null)},I=M=>{if(!M)return S();const R=eR(M.data);u({kind:"template",id:M.id}),m({...KC,name:R.name??"",title:R.title??"",scope:R.scope??"",persona:R.persona??"",color:R.avatar?.color??jo[0],engine:null,approvalMode:R.approvalMode??"auto-edits",tools:R.tools??"all"}),p(null),x(null)};f.useEffect(()=>{e&&(s?(u({kind:"blank"}),m({...sc(jo[i.length%jo.length]),...s}),p(null),x(null)):I(a[0]),b(!1),j(!1),N(!1))},[e]);const k=M=>{m(R=>({...R,...M})),x(null)},L=async M=>{const R=new Uint8Array(await M.arrayBuffer()),$=tR(R)==="png",U=$?nR(Lg(R,"chara")??Lg(R,"ccv3")??""):new TextDecoder().decode(R),q=U?UU(U):{ok:!1,error:"not-a-card"};if(!q.ok){x(q.error==="invalid-json"&&!$?o("This file is not valid JSON."):o("This file is not a SillyTavern character card."));return}const{color:te,memoryEnabled:V,...se}=q.draft;u({kind:"import"}),m({...sc(te??d.color),...se,...V!==void 0?{memoryEnabled:V}:{}}),p($?await Lj(M).catch(()=>null):null),b(!0),x(null)},F=Xh(d.name,i,o),A=async()=>{if(b(!0),F)return;const M=GC(d);if(!M.ok){x(o("Budget must be a positive number"));return}const R=Lx(d);if(!R.ok){x(o("Check the per-turn token limit and delegation time limit"));return}j(!0);try{const $=await window.electronAPI.bots.create({name:d.name.trim(),title:d.title.trim(),scope:d.scope.trim(),...R.delegationTimeoutMinutes?{delegationTimeoutMinutes:R.delegationTimeoutMinutes}:{},...R.maxTokensPerTurn?{maxTokensPerTurn:R.maxTokensPerTurn}:{},persona:d.persona,avatar:{color:d.color},engine:d.engine,approvalMode:d.approvalMode,tools:d.tools,skillIds:d.skillIds,mcpServerIds:d.mcpServerIds,delegation:{canDelegateTo:d.canDelegateTo,acceptFrom:d.acceptFrom},memory:{enabled:d.memoryEnabled},...M.budget?{budget:M.budget}:{}});if(!$.ok){x(fa($.reason,$.error,o));return}ie.getState().upsertBot($.bot),h&&!await Oj($.bot.id,h)&&Ie({type:"error",title:o("Avatar update failed")}),t(!1);const U=await ie.getState().openDirect($.bot.id);U&&r?.(U)}finally{j(!1)}};return n.jsx(cn,{open:e,onOpenChange:t,children:n.jsxs(dn,{className:"max-h-[85vh] max-w-3xl",children:[n.jsxs(un,{children:[n.jsx(rn,{children:o("New member")}),n.jsx(ys,{children:o("Members have their own persona, model, tools and memory. Their name is how you @ them in groups.")})]}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx(fe,{size:"sm",variant:c.kind==="template"?"default":"outline",disabled:a.length===0,onClick:()=>I(a[0]),children:o("From template")}),n.jsx(fe,{size:"sm",variant:c.kind==="blank"?"default":"outline",onClick:S,children:o("Blank")}),n.jsxs(fe,{size:"sm",variant:c.kind==="import"?"default":"outline",onClick:()=>l.current?.click(),children:[n.jsx(Hh,{}),o("Import character card")]}),n.jsx("input",{ref:l,type:"file",accept:".json,.png,application/json,image/png",hidden:!0,onChange:M=>{const R=M.target.files?.[0];M.target.value="",R&&L(R)}})]}),c.kind==="template"&&n.jsxs("div",{className:"grid grid-cols-3 gap-2.5",children:[a.map(M=>n.jsxs("button",{type:"button",onClick:()=>I(M),className:_("flex flex-col items-start gap-1 rounded-xl border bg-card p-3 text-left transition-colors hover:bg-muted",c.id===M.id&&"ring-2 ring-info"),children:[n.jsx($t,{bot:{name:M.data.title,avatar:{color:M.data.color}}}),n.jsx("span",{className:"font-medium text-sm",children:M.data.title}),n.jsx("span",{className:"text-muted-foreground text-xs",children:M.data.summary})]},M.id)),n.jsxs("button",{type:"button",onClick:S,className:"flex items-center justify-center gap-1 rounded-xl border border-dashed p-3 text-muted-foreground text-sm hover:bg-muted",children:[n.jsx(Qn,{className:"h-4 w-4"}),o("Blank member")]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx(Ot,{hint:o("Used for @ in groups; must be unique"),children:o("Name")}),n.jsx(Ht,{value:d.name,onChange:M=>k({name:M.target.value}),onBlur:()=>b(!0)}),v&&F&&n.jsx("p",{className:"mt-1 text-destructive text-xs",children:F})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:o("Title")}),n.jsx(Ht,{value:d.title,onChange:M=>k({title:M.target.value})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:o("Model")}),n.jsx(Dj,{engine:d.engine,onChange:M=>k({engine:M}),zIndex:Pn.DROPDOWN_IN_MODAL})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:o("Avatar color")}),n.jsxs("div",{className:"flex items-start gap-2.5",children:[n.jsx($t,{bot:{name:d.name||"?",avatar:{color:d.color}},src:h??void 0,size:"md"}),n.jsxs("div",{className:"min-w-0 space-y-1.5",children:[n.jsx(Pj,{value:d.color,onChange:M=>k({color:M})}),n.jsx(Mj,{nested:!0,hasImage:!!h,onPick:p,onRemove:()=>p(null)})]})]})]}),n.jsxs("div",{className:"col-span-2",children:[n.jsx(Ot,{hint:o("Used for routing and the delegation directory"),children:o("Responsibilities")}),n.jsx(Ht,{value:d.scope,onChange:M=>k({scope:M.target.value})})]}),n.jsxs("div",{className:"col-span-2",children:[n.jsx(Ot,{action:n.jsx(ZC,{value:d,onApply:k}),children:o("Persona")}),n.jsx(Gs,{rows:4,value:d.persona,onChange:M=>k({persona:M.target.value})})]}),n.jsxs("div",{className:"col-span-2 rounded-lg border",children:[n.jsxs("button",{type:"button",className:"flex w-full items-center gap-1.5 px-3 py-2 text-left text-sm","aria-expanded":T,onClick:()=>N(M=>!M),children:[n.jsx(fn,{className:_("h-4 w-4 transition-transform",T&&"rotate-90")}),n.jsx("span",{className:"font-medium",children:o("Abilities")}),n.jsx("span",{className:"truncate text-muted-foreground text-xs",children:o("Tools, approval, skills, MCP, delegation and memory")})]}),T&&n.jsx("div",{className:"border-t px-3 py-3",children:n.jsx(YC,{value:d,onChange:k,profile:d,zIndex:Pn.DROPDOWN_IN_MODAL})})]})]}),g&&n.jsx("p",{className:"text-destructive text-sm",children:g})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>t(!1),children:o("Cancel")}),n.jsxs(fe,{size:"sm",disabled:w||v&&!!F,onClick:()=>{A()},children:[w&&n.jsx(_t,{className:"animate-spin"}),o("Create and start chatting")]})]})]})})}function P2({projectId:e,onChange:t}){const{t:s}=z(),r=pe(h=>h.projects),o=pe(h=>h.addProject),i=f.useMemo(()=>Gd(r),[r]),[a,l]=f.useState([]),[c,u]=f.useState(()=>i.find(h=>h.id===e)?.path??"");f.useEffect(()=>{window.electronAPI.projects.getRecent().then(l).catch(()=>l([]))},[]),f.useEffect(()=>{const h=i.find(p=>p.id===e)?.path;h&&u(h)},[e,i]);const d=f.useMemo(()=>{const h=new Set(i.map(p=>p.path));return[...i.map(p=>({path:p.path,label:qn(p),detail:p.path,projectId:p.id})),...a.filter(p=>!h.has(p.path)).map(p=>({path:p.path,label:Qj(p.path),detail:`${p.displayPath} · ${p.sourceName}`}))]},[i,a]),m=async h=>{u(h);const p=i.find(g=>g.path===h);if(p)return t(p.id);try{const g=await o(h);if(!g)throw new Error;t(g.id)}catch(g){Ie({type:"error",title:s("Failed to add project"),description:g instanceof Error&&g.message||void 0})}};return n.jsxs(Hx,{value:c,onValueChange:(h,p)=>{u(h??""),p.reason==="item-press"&&h?m(h):e&&t("")},items:d,filter:(h,p)=>{if(!p)return!0;const g=p.toLowerCase();return[h.label,h.path,h.detail].some(x=>x.toLowerCase().includes(g))},itemToStringValue:h=>h.path,children:[n.jsxs("div",{className:"mt-2 flex w-full gap-2",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(Wx,{placeholder:s("Search Code projects or recent folders..."),showClear:!!c,showTrigger:!0})}),n.jsx(fe,{type:"button",variant:"outline",onClick:()=>{window.electronAPI.dialog.selectDirectory().then(h=>{h&&m(h)})},children:s("Browse")})]}),n.jsxs(j2,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(qx,{children:s("No matching projects found")}),n.jsx(Gx,{children:h=>n.jsxs(Ux,{value:h,className:"gap-2",children:[n.jsx("span",{className:"shrink-0",children:h.label}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground text-xs",title:h.path,children:h.detail}),!h.projectId&&n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s("Add")})]},h.path)})]})]})}function VG({open:e,onOpenChange:t}){const{t:s}=z(),r=ie(A=>A.bots),o=f.useMemo(()=>r.filter(A=>A.archivedAt===void 0),[r]),i=Gd(pe(A=>A.projects)),[a,l]=f.useState(""),[c,u]=f.useState([]),[d,m]=f.useState(null),[h,p]=f.useState("project"),[g,x]=f.useState(""),[v,b]=f.useState(String(Xo.maxHops)),[w,j]=f.useState(String(Xo.maxTurnsPerBot)),[T,N]=f.useState(!1),[S,I]=f.useState(null);f.useEffect(()=>{e&&(l(""),u([]),m(null),p(i.length>0?"project":"chat-home"),x(i[0]?.id??""),b(String(Xo.maxHops)),j(String(Xo.maxTurnsPerBot)),N(!1),I(null))},[e]);const k=(A,M)=>{const R=M?[...c,A]:c.filter($=>$!==A);u(R),R.includes(d??"")?!d&&R.length&&m(R[0]):m(R[0]??null)},L=c.length>=2&&d!==null&&(h==="chat-home"||!!g),F=async()=>{if(L){N(!0);try{const A=await window.electronAPI.bots.createChat({kind:"group",title:a.trim(),members:c,bossBotId:d,workspace:h==="project"?{kind:"project",projectId:g}:{kind:"chat-home"},routing:{maxHops:Math.round(Number(v))||Xo.maxHops,maxTurnsPerBot:Math.round(Number(w))||Xo.maxTurnsPerBot}});if(!A.ok){I(ds(A.error,s));return}const M=ie.getState();M.upsertChat(A.chat),M.setView({kind:"chat",chatId:A.chat.id}),M.loadLatest(A.chat.id),t(!1)}finally{N(!1)}}};return n.jsx(cn,{open:e,onOpenChange:t,children:n.jsxs(dn,{className:"max-h-[85vh] max-w-xl",children:[n.jsxs(un,{children:[n.jsx(rn,{children:s("New group chat")}),n.jsx(ys,{children:s("One member replies at a time. Without @, the best-fit member is picked to reply.")})]}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:s("Group name")}),n.jsx(Ht,{value:a,onChange:A=>l(A.target.value)})]}),n.jsxs("div",{children:[n.jsx(Ot,{hint:s("Pick at least two, and one owner"),children:s("Members")}),o.length<2&&n.jsx("p",{className:"text-muted-foreground text-xs",children:s("Create at least two members first.")}),n.jsx("div",{className:"space-y-0.5",children:o.map(A=>{const M=c.includes(A.id);return n.jsxs("div",{className:"flex items-center gap-2.5 rounded-md px-1.5 py-1 hover:bg-muted",children:[n.jsx(Vo,{checked:M,onCheckedChange:R=>k(A.id,R===!0)}),n.jsx($t,{bot:A,size:"sm"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-sm",children:[A.name,A.title&&n.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:A.title})]}),M&&n.jsxs("label",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[n.jsx("input",{type:"radio",name:"group-owner",checked:d===A.id,onChange:()=>m(A.id),className:"accent-primary"}),s("Owner")]})]},A.id)})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:s("Shared workspace")}),n.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[n.jsxs("button",{type:"button",onClick:()=>p("project"),className:_("rounded-xl border bg-card p-3 text-left disabled:opacity-50",h==="project"&&"ring-2 ring-info"),children:[n.jsx("div",{className:"font-medium text-sm",children:s("Based on a Code project")}),n.jsx("div",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Members read and write directly in the project folder")})]}),n.jsxs("button",{type:"button",onClick:()=>p("chat-home"),className:_("rounded-xl border bg-card p-3 text-left",h==="chat-home"&&"ring-2 ring-info"),children:[n.jsx("div",{className:"font-medium text-sm",children:s("Standalone workspace")}),n.jsx("div",{className:"mt-0.5 text-muted-foreground text-xs",children:s("A new empty folder for this group, removed with the group")})]})]}),h==="project"&&n.jsx(P2,{projectId:g,onChange:x}),n.jsxs("div",{className:"mt-2 flex gap-2 rounded-lg border border-warning/40 bg-warning/8 px-3 py-2 text-xs",children:[n.jsx(fl,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-warning"}),n.jsx("span",{children:s("All members share this folder: anyone who can talk to a member can reach its contents through them. You can change it later in group info (members start new conversations).")})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:s("@ relay limit (per message of yours)")}),n.jsx(Ht,{type:"number",min:1,max:20,value:v,onChange:A=>b(A.target.value)})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:s("Max replies per member")}),n.jsx(Ht,{type:"number",min:1,max:10,value:w,onChange:A=>j(A.target.value)})]})]}),S&&n.jsx("p",{className:"text-destructive text-sm",children:S})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>t(!1),children:s("Cancel")}),n.jsxs(fe,{size:"sm",disabled:!L||T,onClick:()=>{F()},children:[T&&n.jsx(_t,{className:"animate-spin"}),s("Create")]})]})]})})}const ky={skillIds:[],mcpServerIds:[]};function HG({open:e,onOpenChange:t,seedTemplateId:s,onCreated:r}){const{t:o,locale:i}=z(),a=ie(re=>re.bots),l=Xj(),c=Gd(pe(re=>re.projects)),u=f.useRef(null),[d,m]=f.useState(null),[h,p]=f.useState("chat-home"),[g,x]=f.useState(""),[v,b]=f.useState(!1),[w,j]=f.useState(null),[T,N]=f.useState({}),[S,I]=f.useState(null),[k,L]=f.useState(!1);f.useEffect(()=>{if(!e)return;m(null),x(c[0]?.id??""),b(!1),j(null),N({}),I(null);const re=l.find(Z=>Z.id===s);re&&F({team:_g(re.data)})},[e]);const F=async re=>{b(!0),j(null);try{const Z=await window.electronAPI.bots.previewTeam(re);if(!Z.ok){j(sR(Z.error,o));return}m({team:Z.team,renamed:Z.renamed,picked:Z.team.members.map(me=>me.key)}),N({}),I(null),p(Z.team.workspace==="project"&&c.length>0?"project":"chat-home")}finally{b(!1)}},A=re=>m(Z=>Z&&{...Z,team:re(Z.team)}),M=(re,Z)=>A(me=>({...me,members:me.members.map(xe=>xe.key===re?{...xe,...Z}:xe)})),R=f.useMemo(()=>d?rR(d.team,d.picked):null,[d]),$=f.useMemo(()=>{const re=new Map;if(!R)return re;const Z=[...a,...R.members.map(me=>({id:`team:${me.key}`,name:me.name}))];for(const me of R.members){const xe=Xh(me.name,Z,o,`team:${me.key}`);xe&&re.set(me.key,xe)}return re},[R,a,o]),U=R!==null&&$.size===0&&(h==="chat-home"||!!g)&&!v&&!k,q=re=>T[re]??ky,te=(re,Z)=>N(me=>({...me,[re]:{...me[re]??ky,...Z}})),V=async()=>{if(R){L(!0);try{const re=i==="zh"?"zh":"en",Z=await Promise.all(R.members.map(async B=>{try{const ne=await window.electronAPI.bots.suggestAbilities({name:B.name,title:B.title,scope:B.scope,persona:B.persona,language:re});return{key:B.key,result:ne}}catch{return{key:B.key,result:null}}}));let me=0,xe=0,Se;const W={...T},H=new Map;for(const{key:B,result:ne}of Z){if(!ne?.ok){xe++,ne&&!Se&&(Se=Su(ne,o));continue}const{suggestion:ve}=ne,he={};ve.tools&&(he.tools=ve.tools.value),ve.approvalMode&&(he.approvalMode=ve.approvalMode.value),Object.keys(he).length>0&&H.set(B,he);const G=ve.skillIds?.value??q(B).skillIds,we=ve.mcpServerIds?.value??q(B).mcpServerIds;W[B]={skillIds:[...G],mcpServerIds:[...we]},(G.length+we.length>0||H.has(B))&&me++}N(W),H.size>0&&A(B=>({...B,members:B.members.map(ne=>({...ne,...H.get(ne.key)}))})),xe>0&&Ie({type:"error",title:o("Suggestions failed for {{n}} members",{n:xe}),...Se?{description:Se}:{}}),xe<Z.length&&Ie({type:me>0?"success":"info",title:me>0?o("Configured abilities for {{n}} members",{n:me}):o("Current abilities already match the suggestion.")})}finally{L(!1)}}},se=async()=>{if(!(!R||!U)){b(!0),j(null);try{const re=Object.fromEntries(R.members.map(xe=>[xe.key,q(xe.key)]).filter(([,xe])=>xe.skillIds.length+xe.mcpServerIds.length>0)),Z=await window.electronAPI.bots.createTeam({team:{...R,title:R.title.trim()},workspace:h==="project"?{kind:"project",projectId:g}:{kind:"chat-home"},...Object.keys(re).length>0?{assets:re}:{}});if(!Z.ok){j(fa(Z.error,ds(Z.error,o),o));return}const me=ie.getState();for(const xe of Z.bots)me.upsertBot(xe);me.upsertChat(Z.chat),me.setView({kind:"chat",chatId:Z.chat.id}),me.loadLatest(Z.chat.id),t(!1),r?.(Z.chat.id)}finally{b(!1)}}},Ce=i==="zh"?"zh":"en",de=re=>d?.team.members.find(Z=>Z.key===re)?.name??re;return n.jsx(cn,{open:e,onOpenChange:t,children:n.jsxs(dn,{className:"max-h-[85vh] max-w-2xl",children:[n.jsxs(un,{children:[n.jsx(rn,{children:o("Create team from template")}),n.jsx(ys,{children:o("Creates the members and their group chat in one go. Members follow the default model; expand a member to set tools, approval, delegation, skills and MCP, or let AI set them.")})]}),n.jsxs(In,{className:"space-y-4",children:[d?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(Ot,{children:o("Group name")}),n.jsx(Ht,{value:d.team.title,onChange:re=>{const Z=re.target.value;A(me=>({...me,title:Z}))}})]}),n.jsxs("div",{children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsxs("span",{className:"flex items-baseline gap-2",children:[n.jsx("span",{className:"text-muted-foreground text-xs",children:o("Members")}),n.jsx("span",{className:"text-[11px] text-muted-foreground/70",children:o("Uncheck members you do not need; the owner stays")})]}),n.jsxs(fe,{size:"xs",variant:"outline",disabled:!R||k||v,onClick:()=>{V()},children:[k?n.jsx(_t,{className:"animate-spin"}):n.jsx(Bs,{}),o("AI auto-configure")]})]}),n.jsx("div",{className:"space-y-1.5",children:d.team.members.map(re=>{const Z=d.picked.includes(re.key),me=re.key===d.team.bossKey,xe=d.renamed.find(ve=>ve.key===re.key),Se=Z?$.get(re.key):void 0,W=re.delegation.canDelegateTo,H=W==="any"?[]:W.filter(ve=>d.picked.includes(ve)),B=q(re.key),ne=Z&&S===re.key;return n.jsxs("div",{className:_("flex items-start gap-2.5 rounded-lg border px-2.5 py-2",!Z&&"opacity-60"),children:[n.jsx(Vo,{className:"mt-1.5",checked:Z,disabled:me,onCheckedChange:ve=>m({...d,picked:ve===!0?[...d.picked,re.key]:d.picked.filter(he=>he!==re.key)})}),n.jsx($t,{bot:re,size:"sm"}),n.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Ht,{className:"h-7 w-36",value:re.name,disabled:!Z,onChange:ve=>{const he=ve.target.value;A(G=>({...G,members:G.members.map(we=>we.key===re.key?{...we,name:he}:we)}))}}),n.jsx("span",{className:"truncate text-muted-foreground text-xs",children:re.title}),me&&n.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[n.jsx(Vj,{className:"h-3 w-3"}),o("Owner")]})]}),n.jsx("p",{className:"text-muted-foreground text-xs",children:re.scope}),xe&&xe.to===re.name&&n.jsx("p",{className:"text-warning text-xs",children:o('"{{from}}" is taken, renamed to "{{to}}"',xe)}),Se&&n.jsx("p",{className:"text-destructive text-xs",children:Se}),n.jsxs("button",{type:"button",disabled:!Z,onClick:()=>I(ne?null:re.key),className:"flex items-start gap-1 text-left text-[11px] text-muted-foreground hover:text-foreground disabled:pointer-events-none",children:[ne?n.jsx(Fn,{className:"mt-px h-3 w-3 shrink-0"}):n.jsx(fn,{className:"mt-px h-3 w-3 shrink-0"}),n.jsxs("span",{children:[re.tools==="readonly"?o("Read-only"):o("All tools")," · ",o(Ba[re.approvalMode].labelKey),H.length>0&&` · ${o("Delegates to {{names}}",{names:H.map(de).join(Ce==="zh"?"、":", ")})}`," · ",B.skillIds.length+B.mcpServerIds.length===0?o("No skills or MCP"):o("{{n}} skills · {{m}} MCP",{n:B.skillIds.length,m:B.mcpServerIds.length})]})]}),ne&&n.jsxs("div",{className:"space-y-3 rounded-lg bg-muted/40 p-2.5",children:[n.jsxs("div",{children:[n.jsx(Ot,{children:o("Tools")}),n.jsx(Gh,{value:re.tools,options:[{value:"all",label:o("All tools")},{value:"readonly",label:o("Read-only")}],onChange:ve=>M(re.key,{tools:ve})})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:o("Approval mode")}),n.jsx(Aj,{value:re.approvalMode,onChange:ve=>M(re.key,{approvalMode:ve}),zIndex:Pn.DROPDOWN_IN_MODAL})]}),n.jsx(Bg,{label:o("Can delegate to"),value:re.delegation.canDelegateTo,options:d.picked.filter(ve=>ve!==re.key),nameOf:de,onChange:ve=>M(re.key,{delegation:{...re.delegation,canDelegateTo:ve}})}),n.jsx(Bg,{label:o("Accepts delegation from"),value:re.delegation.acceptFrom,options:d.picked.filter(ve=>ve!==re.key),nameOf:de,onChange:ve=>M(re.key,{delegation:{...re.delegation,acceptFrom:ve}})}),n.jsx(XC,{value:B,onChange:ve=>te(re.key,ve)})]})]})]},re.key)})}),!R&&n.jsx("p",{className:"mt-1 text-destructive text-xs",children:o("Keep the owner and at least one other member.")})]}),n.jsxs("div",{children:[n.jsx(Ot,{children:o("Shared workspace")}),n.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[n.jsxs("button",{type:"button",onClick:()=>p("chat-home"),className:_("rounded-xl border bg-card p-3 text-left",h==="chat-home"&&"ring-2 ring-info"),children:[n.jsx("div",{className:"font-medium text-sm",children:o("Standalone workspace")}),n.jsx("div",{className:"mt-0.5 text-muted-foreground text-xs",children:o("A new empty folder for this group, removed with the group")})]}),n.jsxs("button",{type:"button",onClick:()=>p("project"),className:_("rounded-xl border bg-card p-3 text-left disabled:opacity-50",h==="project"&&"ring-2 ring-info"),children:[n.jsx("div",{className:"font-medium text-sm",children:o("Based on a Code project")}),n.jsx("div",{className:"mt-0.5 text-muted-foreground text-xs",children:o("Members read and write directly in the project folder")})]})]}),h==="project"&&n.jsx(P2,{projectId:g,onChange:x}),n.jsxs("div",{className:"mt-2 flex gap-2 rounded-lg border border-info/40 bg-info/8 px-3 py-2 text-xs",children:[n.jsx(fl,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-info"}),n.jsx("span",{children:o(d.team.routing.mode==="smart"?"Without @, the best-fit member replies; @ relay limit {{n}}.":"Without @, the owner replies; @ relay limit {{n}}.",{n:d.team.routing.maxHops})})]})]})]}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:l.map(({id:re,data:Z})=>n.jsxs("button",{type:"button",disabled:v,onClick:()=>{F({team:_g(Z)})},className:"flex flex-col items-start gap-1.5 rounded-xl border bg-card p-3 text-left transition-colors hover:bg-muted disabled:opacity-50",children:[n.jsx("div",{className:"-space-x-1.5 flex",children:Z.members.map(me=>n.jsx($t,{size:"sm",bot:{name:me.name,avatar:{color:me.color}}},me.key))}),n.jsx("span",{className:"font-medium text-sm",children:Z.title}),n.jsx("span",{className:"text-muted-foreground text-xs",children:Z.summary})]},re))}),n.jsxs(fe,{size:"sm",variant:"outline",disabled:v,onClick:()=>u.current?.click(),children:[n.jsx(Hh,{}),o("Import team (JSON)")]}),n.jsx("input",{ref:u,type:"file",accept:".json,application/json",hidden:!0,onChange:re=>{const Z=re.target.files?.[0];re.target.value="",Z&&Z.text().then(me=>F({text:me}))}})]}),w&&n.jsx("p",{className:"text-destructive text-sm",children:w})]}),n.jsxs(ts,{children:[d&&n.jsxs(fe,{variant:"ghost",size:"sm",className:"mr-auto",onClick:()=>{m(null),j(null)},children:[n.jsx(Ei,{}),o("Back")]}),n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>t(!1),children:o("Cancel")}),d&&n.jsxs(fe,{size:"sm",disabled:!U,onClick:()=>{se()},children:[v&&n.jsx(_t,{className:"animate-spin"}),o("Create team")]})]})]})})}const Vr="relative flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";function WG({sidebarWidth:e,collapsed:t,onToggleCollapse:s,onResize:r}){const o=up()==="mobile",{t:i}=z(),a=ie(R=>R.view),l=ie(R=>R.chats),c=ie(R=>R.bots),u=ie(R=>R.loaded),d=ie(R=>R.setView),[m,h]=f.useState(!1),[p,g]=f.useState(!1),[x,v]=f.useState(!1),[b,w]=f.useState(!1),[j,T]=f.useState(null),N=f.useRef(""),S=ip(),I=a?.kind==="chat"?l.find(R=>R.id===a.chatId):void 0,k=I?.kind==="group"?mz(l,I):void 0;f.useEffect(()=>{u&&a?.kind==="chat"&&!I&&d(null)},[u,a,I,d]);const L=async R=>{if(R.botId){const $=ie.getState();if(!$.bots.some(q=>q.id===R.botId))throw new Error("Member not found");const U=await $.openDirect(R.botId);if(!U)throw new Error("Could not open chat");Fg(U,R.firstMessage.trim()),w(!1);return}w(!1),T(R),N.current=R.firstMessage.trim(),R.templateId?v(!0):h(!0)},F=R=>{N.current&&Fg(R,N.current),N.current=""},A=()=>{T(null),N.current="",h(!0)},M=()=>{T(null),N.current="",v(!0)};return n.jsxs(n.Fragment,{children:[t?n.jsxs("aside",{className:"flex w-12 shrink-0 flex-col items-center gap-1 border-r bg-background py-2",children:[n.jsx(M2,{className:Vr}),n.jsx("button",{type:"button",className:Vr,onClick:()=>w(!0),title:i("Start from a goal"),children:n.jsx(Fi,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:A,title:i("New member"),children:n.jsx(Ya,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:()=>g(!0),title:i("New group chat"),children:n.jsx(ki,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:M,title:i("Create team from template"),children:n.jsx(um,{className:"h-4 w-4"})}),(S>0||a?.kind==="inbox")&&n.jsxs("button",{type:"button",className:_(Vr,a?.kind==="inbox"&&"bg-brand/10 text-foreground hover:bg-brand/10 dark:bg-brand/15 dark:hover:bg-brand/15"),onClick:()=>d({kind:"inbox"}),title:i("Inbox"),children:[n.jsx(ex,{className:"h-4 w-4"}),S>0&&n.jsx(Cu,{count:S,className:"-top-0.5 -right-1 absolute"})]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{type:"button",className:Vr,onClick:()=>{window.electronAPI.window.openSettings()},title:i("Settings"),children:n.jsx(Os,{className:"h-4 w-4"})}),o&&n.jsx("button",{type:"button",className:Vr,onClick:s,title:i("Expand sidebar"),children:n.jsx(AN,{className:"h-4 w-4"})})]}):n.jsxs(n.Fragment,{children:[n.jsx(FG,{width:e,onCollapse:o?s:void 0,onNewMember:A,onNewGroup:()=>g(!0),onNewTeam:M,onStartFromGoal:()=>w(!0)}),n.jsx(jd,{onResize:r})]}),a?.kind==="inbox"?n.jsx(dG,{}):I?n.jsx(sG,{chat:k??I,group:I},k?.id??I.id):n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col items-center justify-center gap-3 bg-background px-6 text-center",children:[n.jsx(ws,{className:"h-8 w-8 text-muted-foreground"}),n.jsx("p",{className:"font-medium text-lg",children:i("Bot mode")}),n.jsx("p",{className:"max-w-md text-muted-foreground text-sm",children:c.length===0?i("Tell us in one sentence what you want done; we will recommend a member or a team and draft your first message."):i("Pick a member or a group chat on the left.")}),c.length===0&&u&&n.jsx(jy,{onPick:L}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(fe,{size:"sm",variant:c.length===0?"outline":"default",onClick:A,children:[n.jsx(Ya,{}),i("New member")]}),c.length>=2&&n.jsxs(fe,{size:"sm",variant:"outline",onClick:()=>g(!0),children:[n.jsx(ki,{}),i("New group chat")]}),n.jsxs(fe,{size:"sm",variant:"outline",onClick:M,children:[n.jsx(um,{}),i("Create team from template")]})]})]}),n.jsx($G,{open:m,onOpenChange:h,seed:j?.member,onCreated:F}),n.jsx(VG,{open:p,onOpenChange:g}),n.jsx(_G,{}),n.jsx(HG,{open:x,onOpenChange:v,seedTemplateId:j?.templateId,onCreated:F}),n.jsx(cn,{open:b,onOpenChange:w,children:n.jsxs(dn,{className:"max-w-xl",children:[n.jsxs(un,{children:[n.jsx(rn,{children:i("Start from a goal")}),n.jsx(ys,{children:i("Tell us in one sentence what you want done; we will recommend a member or a team and draft your first message.")})]}),n.jsx(In,{className:"flex justify-center pb-4",children:b&&n.jsx(jy,{onPick:L})})]})})]})}const ea=[{value:"code",label:"Code",Icon:$o},{value:"bot",label:"Bot",Icon:oR}],UG={ArrowLeft:-1,ArrowUp:-1,ArrowRight:1,ArrowDown:1},qG={duration:.26,ease:[.22,1,.36,1]},GG={duration:.5,ease:[.34,1.36,.64,1]},KG={duration:.18,ease:[.4,0,.2,1]};function YG({className:e}){const{t}=z(),s=Er(m=>m.mode),r=Er(m=>m.setMode),o=ip(),i=Pr(pe(m=>m.keybindings))["toggle-app-mode"],a=i?`${t("Switch between Code and Bot")} (${qs(i)})`:void 0,l=X4()??!1,c=f.useId(),u=f.useRef({}),d=m=>{const h=UG[m.key];if(!h)return;m.preventDefault();const p=ea.findIndex(x=>x.value===s),g=ea[(p+h+ea.length)%ea.length].value;r(g),u.current[g]?.focus()};return n.jsx("div",{role:"radiogroup","aria-label":t("Switch mode"),onKeyDown:d,className:_("flex h-7 shrink-0 rounded-lg bg-muted/60 p-0.5 text-xs",e),children:ea.map(({value:m,label:h,Icon:p})=>{const g=s===m,x=m==="bot"&&s==="code"&&o>0;return n.jsxs("button",{ref:v=>{u.current[m]=v},type:"button",role:"radio","aria-checked":g,tabIndex:g?0:-1,title:a,onClick:()=>r(m),className:_("relative flex items-center gap-1.5 rounded-md px-2.5 font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",g?"text-foreground":"text-muted-foreground hover:text-foreground"),children:[g&&n.jsx(Ns.span,{layoutId:c,"aria-hidden":!0,className:"absolute inset-0 rounded-md bg-background shadow-xs",transition:l?{duration:0}:gi}),n.jsx(p,{className:"relative h-3.5 w-3.5"}),n.jsx("span",{className:"relative",children:h}),n.jsx(ya,{children:x&&n.jsx(Ns.span,{className:"-top-1.5 -right-1.5 pointer-events-none absolute",initial:l?!1:{x:-8,y:12},animate:{x:0,y:0},transition:qG,children:n.jsx(Ns.span,{className:"block",initial:l?!1:{scale:0,opacity:0,filter:"blur(2px)"},animate:{scale:1,opacity:1,filter:"blur(0px)"},exit:l?{opacity:0,transition:{duration:0}}:{scale:0,opacity:0,filter:"blur(2px)",transition:KG},transition:GG,children:n.jsx(Cu,{count:o,className:"block"})})})})]},m)})})}const ol="enso:open-chat-find";let ph;function D2(e){ph=e,window.dispatchEvent(new Event(ol))}function Ny(){const e=ph;return ph=void 0,e}function XG({query:e,onQueryChange:t,current:s,total:r,onPrev:o,onNext:i,onClose:a}){const{t:l}=z(),c=f.useRef(null);return f.useEffect(()=>{const u=()=>{c.current?.focus(),c.current?.select()};return u(),window.addEventListener(ol,u),()=>window.removeEventListener(ol,u)},[]),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b px-3 py-1.5",children:[n.jsxs("div",{className:"relative min-w-0 flex-1",children:[n.jsx(dr,{className:"pointer-events-none absolute top-1/2 left-2.5 z-10 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx(Ht,{ref:c,value:e,onChange:u=>t(u.target.value),onKeyDown:u=>{if(u.key==="Escape"){u.preventDefault(),a();return}u.key==="Enter"&&(u.preventDefault(),u.shiftKey?o():i())},placeholder:l("Search messages..."),className:"h-8 text-xs [&_input]:pl-8"})]}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs tabular-nums",children:r===0?l("No results"):`${s}/${r}`}),n.jsx(fe,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:r===0,onClick:o,"aria-label":l("Previous match"),children:n.jsx(ij,{className:"h-3.5 w-3.5"})}),n.jsx(fe,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:r===0,onClick:i,"aria-label":l("Next match"),children:n.jsx(Fn,{className:"h-3.5 w-3.5"})}),n.jsx(fe,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:a,children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]})}function QG({conversationId:e}){const{t}=z(),s=Ii(o=>o.back),r=J(o=>s?!!o.conversations[s.from]:!1);return!s||s.to!==e||!r?null:n.jsxs("button",{type:"button","data-enso":"secretary-return",onClick:SH,className:"inline-flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-[12px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[n.jsx(Ei,{className:"size-3.5"}),t("Back to secretary")]})}function JG(e){return[...e.running,...e.needsYou,...e.done]}function ZG(e,t,s){for(const[r,o]of Object.entries(e)){if(o.secretaryId&&o.secretaryId!==r)continue;const i=JG(o.board).find(a=>a.kind==="session"&&a.conversationId===t&&!a.takeover);if(i?.kind==="session")return{secretaryId:r,secretaryConversationId:i.secretaryConversationId}}for(const[r,o]of Object.entries(e))if(!(o.secretaryId&&o.secretaryId!==r)&&o.takeovers.some(i=>i.conversationId===t))return{secretaryId:r};return null}function O2(e,t){for(const[s,r]of Object.entries(e)){if(r.secretaryId&&r.secretaryId!==s)continue;const o=r.takeovers.find(i=>i.conversationId===t);if(o)return{secretaryId:s,takeover:o}}return null}function L2(e){return kt(t=>O2(t.states,e)?.takeover??t.secretary.takeovers.find(s=>s.conversationId===e))}function _2(e){const{t}=z();return kt(r=>{const i=(e?O2(r.states,e)?.secretaryId:null)??r.focusedId,a=i?r.states[i]:void 0;return(i&&r.focusedId===i?r.secretary.profile?.name:a?.profile?.name)??r.secretaries.find(l=>l.id===i)?.name??r.secretary.profile?.name})?.trim()||t("Secretary")}function eK({conversationId:e}={}){const{t}=z(),s=_2(e);return n.jsx("span",{"data-enso":"secretary-takeover",className:"shrink-0 rounded bg-primary/10 px-1 text-[10px] text-primary group-hover:hidden",children:t("Managed by {{name}}",{name:s})})}function tK({conversationId:e}){const{t}=z(),s=L2(e),[r,o]=f.useState(!1),i=_2(e),a=async l=>{o(!0);try{const c=await l();c.ok||Ie({type:"error",title:t("Takeover failed"),description:c.error})}finally{o(!1)}};return s?n.jsxs("span",{"data-enso":"secretary-takeover-chip",className:"flex h-6 shrink-0 items-center gap-1 rounded-full bg-primary/10 pr-0.5 pl-2 text-[11px] text-primary",title:t("{{name}} is managing this session: it may message and stop it.",{name:i}),children:[n.jsx(dF,{className:"size-3.5"}),t("Managed by {{name}}",{name:i}),n.jsx("button",{type:"button","data-enso":"secretary-takeover-revoke",disabled:r,"aria-label":t("Take back from {{name}}",{name:i}),title:t("Take back from {{name}}",{name:i}),onClick:()=>{a(()=>window.electronAPI.secretary.revokeTakeover(e))},className:"flex size-5 items-center justify-center rounded-full hover:bg-primary/15 disabled:opacity-50",children:n.jsx(Jt,{className:"size-3"})})]}):null}const nK="default",sK={"not-visible":"The other secretary cannot see this project.","no-secretary-conversation":"The other secretary has no conversation yet: open it once first.","not-managed":"No secretary manages this session."};function rK(e){const t=J(s=>s.conversations[e]?.secretaryOrigin);return kt(s=>{for(const[o,i]of Object.entries(s.states))if(i.takeovers.some(a=>a.conversationId===e))return o;if(!t)return null;const r=t.secretaryId??nK;return s.secretaries.some(o=>o.id===r)?r:null})}function oK({conversationId:e}){const{t}=z(),s=rK(e),r=kt(d=>d.secretaries),o=kt(d=>d.states),[i,a]=f.useState(!1),l=r.filter(d=>d.id!==s);if(!s||l.length===0)return null;const c=d=>o[d]?.profile?.name??r.find(m=>m.id===d)?.name??d,u=async d=>{a(!0);try{const m=await window.electronAPI.secretary.transfer(e,d);if(m.ok)Ie({type:"success",title:t("Transferred to {{name}}",{name:c(d)})});else{const h=sK[m.error];Ie({type:"error",title:t("Transfer failed"),description:h?t(h):m.error})}}finally{a(!1)}};return n.jsxs(mr,{children:[n.jsx(hr,{"data-enso":"secretary-transfer",disabled:i,"aria-label":t("Transfer to…"),title:t("Transfer to…"),className:"flex size-6 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-muted disabled:opacity-50 data-popup-open:bg-muted",children:n.jsx(r_,{className:"size-3.5"})}),n.jsx(pr,{align:"end",children:l.map(d=>n.jsx(Cn,{"data-enso":"secretary-transfer-target","data-secretary":d.id,onClick:()=>{u(d.id)},children:t("Transfer to {{name}}",{name:c(d.id)})},d.id))})]})}function iK(e){const{t}=z(),s=e?.startsWith("bot:")?e.slice(4):void 0,r=ie(a=>s?a.bots.find(l=>l.id===s)?.name:void 0),[o,i]=f.useState();if(f.useEffect(()=>{if(i(void 0),!e||!s||r)return;let a=!0;return window.electronAPI.agentRegistry.list().then(l=>{const c=kj(l)?.candidates.find(u=>u.typeKey===e);a&&i(c?.displayName)}).catch(()=>{}),()=>{a=!1}},[e,s,r]),!!s)return r??o??t("Member")}function aK(e,t){return e?null:t?"empty":"hydrating"}function lK(e,t){return!e||!t?e?.parentWorktreePath:fp({kind:t.kind,canonicalPath:t.path,conversationId:e.parentId,worktreePath:e.parentWorktreePath})??void 0}function cK(e,t){return t.kind!=="scratch"?t.path:fp({kind:"scratch",canonicalPath:t.path,conversationId:e})??void 0}function dK(e){const t=e.activeId?e.conversations[e.activeId]:void 0;return t?t.activeTabId?e.conversations[t.activeTabId]?.id??t.id:t.id:null}function uK(e){const t=e.activeId?e.conversations[e.activeId]:void 0;if(!t)return null;const s=t.activeTabId?e.conversations[t.activeTabId]??t:t,r=Sl(s);return{id:s.id,parentId:t.id,projectId:s.projectId,parentProjectId:t.projectId,status:s.status,spawning:s.spawning,started:s.started,sessionFile:s.sessionFile,parentStarted:t.started,parentStatus:t.status,parentSessionFile:t.sessionFile,parentWorktreeMissing:t.worktreeMissing,parentWorktreePath:t.worktree?.path,parentWorktreeBranch:t.worktree?.branch,lastProviderId:s.lastProviderId,lastModelId:s.lastModelId,parentLastProviderId:t.lastProviderId,parentLastModelId:t.lastModelId,reasoningEnabled:s.reasoningEnabled,thinkingLevel:s.thinkingLevel,presetId:s.presetId,approvalMode:s.approvalMode,autoRejectApprovals:s.autoRejectApprovals,draftText:s.draftText,draftImages:s.draftImages,draftAppend:s.draftAppend,commands:s.commands,compactionError:s.compactionError,agentType:s.agentType,parentHasRunningChild:Ah(t,e.conversations),retry:s.retry,pendingApprovals:s.pendingApprovals,pendingAsks:s.pendingAsks,backgroundTasks:s.backgroundTasks,subagents:s.subagents,queuedMessages:s.queuedMessages,goal:s.goal,planState:s.planState,rewinding:s.rewinding,restoringFiles:s.restoringFiles,childLockedProfileId:s.child?.lockedProfileId,displayedParentId:s.parentId,busy:iR(s),queued:!!(r&&!r.failed),queuePosition:r&&!r.failed?uu(e.conversations).get(s.id):void 0,queueFailed:r?.failed?.error}}function fK(){const[e,t]=f.useState([]);return f.useEffect(()=>{let s=!0;const r=window.electronAPI.elevation.onChanged(o=>t(o));return window.electronAPI.elevation.pending().then(o=>{s&&t(o)}),()=>{s=!1,r()}},[]),e}function mK(){const e=fK(),t=e[0];return t?n.jsx(hK,{request:t,total:e.length},t.id):null}function hK({request:e,total:t}){const{t:s}=z(),[r,o]=f.useState(""),[i,a]=f.useState(!1),l=mx(e.expiresAt),c=i||l!==void 0&&l<=0,u=d=>{a(!0),o(""),window.electronAPI.elevation.answer(e.id,d)};return n.jsxs("form",{"data-enso":"approval",className:"mb-1 rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2",onSubmit:d=>{d.preventDefault(),r&&!c&&u(r)},children:[n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx(aR,{className:"h-3.5 w-3.5 shrink-0 text-amber-500"}),n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:s("Run as administrator")}),n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[n.jsx(hx,{remainingMs:l,expiredLabel:"Timed out · denied"}),t>1&&n.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:["1/",t]})]})]}),n.jsx("pre",{className:"mt-1.5 max-h-24 overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/60 px-2 py-1.5 font-mono text-xs",children:e.command}),n.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[n.jsx("input",{type:"password",autoFocus:!0,autoComplete:"off",value:r,disabled:c,placeholder:s("Login password"),"aria-invalid":e.retry||void 0,onChange:d=>o(d.currentTarget.value),className:_("h-7 min-w-0 flex-1 rounded-md border bg-background px-2 text-xs outline-none focus-visible:border-ring",e.retry?"border-destructive/60":"border-border/60")}),n.jsx("button",{type:"button",disabled:c,onClick:()=>u(null),className:"rounded-md px-2.5 py-1 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50",children:s("Deny")}),n.jsx("button",{type:"submit",disabled:c||!r,className:"rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:s("Allow")})]}),n.jsx("p",{className:_("mt-1 text-[11px]",e.retry?"text-destructive":"text-muted-foreground"),children:e.retry?s("Incorrect password. Try again."):s("Applies to this command only. The password is never shown to the AI.")})]})}function pK(e){const t=new Set;for(const s of e)if(s.kind==="tool"){if(s.name==="apply_patch"){s.fileChanges?.length&&t.add(s.key);continue}s.state==="ok"&&(s.output===null&&s.durationMs===null||s.name!=="edit"&&s.name!=="write"||s.name==="edit"&&!(s.edits&&s.edits.length>0)||s.name==="write"&&!s.writeContent||t.add(s.key))}return t}const xK={conversationId:void 0,historyBaseIndex:0,seen:null};function gK(e,t){const{conversationId:s,historyBaseIndex:r}=t;if(!t.authoritative)return{baseline:{conversationId:s,historyBaseIndex:r,seen:null},added:!1};const i=e.conversationId===s&&e.historyBaseIndex===r?e.seen:null,a=pK(t.timeline),l=i!==null&&[...a].some(c=>!i.has(c));return{baseline:{conversationId:s,historyBaseIndex:r,seen:a},added:l}}function vK(e,t){const s=pe(a=>a.openChangesOnFileEdit),r=J(a=>lR((t?a.conversations[t]?.messages:void 0)??[])),o=J(a=>(t?a.conversations[t]?.historyBaseIndex:void 0)??0),i=f.useRef(xK);f.useEffect(()=>{const a=gK(i.current,{conversationId:t,historyBaseIndex:o,authoritative:r,timeline:e});i.current=a.baseline,a.added&&s&&cj()},[r,t,s,o,e])}function ta(e,t){const s=e.trim().toLowerCase();return s?t.some(r=>r?.toLowerCase().includes(s)):!0}function bK(e,t){const s=t.trim().toLowerCase();if(!s)return[];const r=[];for(const o of e){if(o.kind!=="user"&&o.kind!=="text")continue;const i=o.text.toLowerCase();let a=0,l=0;for(;;){const c=i.indexOf(s,a);if(c===-1)break;r.push({key:o.key,nth:l}),l+=1,a=c+s.length}}return r}function yK(e){const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return e.slice(t+1)||e}function wK({conversationId:e,failed:t,starting:s=!1}){const{t:r}=z(),[o,i]=f.useState(!1),[a,l]=f.useState(null),[c,u]=f.useState(!1),d=o||s,m=()=>{d||(i(!0),l(null),cR(e).then(p=>{p.ok||l(p.error)}).catch(p=>{l(p instanceof Error?p.message:String(p))}).finally(()=>i(!1)))},h=()=>{d||(i(!0),l(null),dR(e).then(p=>{p.ok||l(p.error)}).catch(p=>{l(p instanceof Error?p.message:String(p))}).finally(()=>i(!1)))};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{type:"button","data-enso":"queued-session-start",disabled:d,onClick:m,className:"rounded-md bg-primary px-2.5 py-1 text-[12px] text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:r(t?"Retry":"Start now")}),n.jsx("button",{type:"button","data-enso":"queued-session-cancel",disabled:d,onClick:()=>u(!0),className:"rounded-md px-2.5 py-1 text-[12px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:r("Cancel queue")})]}),a&&n.jsx("p",{"data-enso":"queued-session-error",className:"text-[12px] text-destructive",children:a}),n.jsx(cs,{open:c,onOpenChange:u,title:r("Cancel queue"),description:r("Cancel this queued session? It has not run and will be deleted."),confirmLabel:r("Cancel queue"),onConfirm:h})]})}function jK({conversationId:e}){const{t}=z(),s=J(l=>l.conversations[e]),r=Sl(s),o=J(l=>uu(l.conversations).get(e)),i=J(l=>l.conversations[e]?.error);if(!r)return null;const a=r.failed?.error;return n.jsx("div",{className:"flex h-full items-center justify-center overflow-y-auto px-4 py-8",children:n.jsxs("div",{"data-enso":"queued-session-card","data-conversation-id":e,className:"flex w-full max-w-lg flex-col gap-3 rounded-xl border bg-card px-4 py-3.5 text-left shadow-xs",children:[n.jsx("p",{className:"text-[13px] font-medium text-orange-600",children:a?t("Queued"):t("Queued · #{{n}}",{n:o??1})}),a&&n.jsx("p",{className:"text-[12.5px] text-destructive",children:a}),r.goal&&n.jsxs("p",{className:"text-[12.5px] text-muted-foreground",children:[n.jsx("span",{className:"text-subtle-foreground",children:t("Goal")})," ",r.goal]}),n.jsx("p",{className:"whitespace-pre-wrap break-words text-[14px]",children:r.text}),r.attachments&&r.attachments.length>0&&n.jsx("ul",{className:"text-[12px] text-muted-foreground",children:r.attachments.map(l=>n.jsx("li",{children:yK(l)},l))}),r.startingAt!==void 0&&n.jsx("p",{className:"text-[12px] text-muted-foreground",children:t("Starting…")}),i&&!a&&n.jsx("p",{className:"text-[12px] text-destructive",children:i}),n.jsx(wK,{conversationId:e,failed:!!a,starting:r.startingAt!==void 0})]})})}const kK=[],NK=[],SK=typeof window<"u"&&!!window.electronAPI?.remote;function B2({conversationId:e,cwd:t,emptyTitle:s,onSuggestion:r,timelineRef:o,peek:i=!1,readOnly:a=!1,quotable:l=!1}){const c=J(G=>G.conversations[e]?.projectId),u=pe(G=>G.projects.some(we=>we.id===c&&we.kind==="secretary")),d=kt(G=>u?G.secretaries.find(we=>we.projectId===c)?.id??null:null),m=kt(G=>d?(G.states[d]??(G.focusedId===d?G.secretary:null))?.profile??null:null),h=f.useMemo(()=>{if(!d||!m)return null;const G=m.avatar.imageVersion;return{name:m.name.trim()||"·",color:m.avatar.color,...G?{image:ll(G,m.avatar.imageHash,d)}:{}}},[d,m]),p=J(G=>G.conversations[e]?.messages??kK),g=J(G=>G.conversations[e]?.customEntries??NK),x=J(G=>G.conversations[e]?.status==="running"),v=J(G=>G.conversations[e]?.compaction),b=J(G=>G.conversations[e]?.compactionNoticeAt),w=J(G=>G.conversations[e]?.occupancy?.compactionTokensAfter),j=J(G=>G.conversations[e]?.historyBaseIndex??0),T=J(G=>G.conversations[e]?.toolOutputs),N=J(G=>G.conversations[e]?.toolStartedAt),S=J(G=>G.conversations[e]?.pendingApprovals),I=J(G=>G.conversations[e]?.runStartedAt),k=J(G=>G.conversations[e]?.lastOutputAt),L=J(G=>G.conversations[e]?.error),F=J(G=>G.conversations[e]?.started===!0),A=J(G=>G.conversations[e]?.sessionFile),M=J(G=>G.conversations[e]?.status),R=J(G=>G.conversations[e]?.spawning===!0),$=J(G=>G.conversations[e]?.historyLoadAttempted),U=J(G=>!!G.conversations[e]?.historyLoading),q=J(G=>G.conversations[e]?.syncStalled===!0),te=J(G=>G.conversations[e]?.queuedStart),V=J(G=>G.conversations[e]?.interrupted),se=f.useRef({conversationId:"",items:[]}),Ce=f.useMemo(()=>{se.current.conversationId!==e&&(se.current={conversationId:e,items:[]});const we=uR(se.current.items,p,x,j)??Zh(p,x,g,t,{compaction:v,compactionNoticeAt:b,compactionTokensAfter:w,historyBaseIndex:j,toolOutputs:T,toolStartedAt:N,pendingApprovals:S,secretarySession:u,interrupted:V});return se.current.items=we,we},[v,b,w,e,t,g,j,V,p,S,x,u,T,N]);vK(Ce,i?void 0:e);const de=fR({started:F,sessionFile:A,messages:p,spawning:R,status:M,historyLoadAttempted:$,historyLoading:U,syncStalled:q}),[re,Z]=f.useState(!1),[me,xe]=f.useState(""),[Se,W]=f.useState(0),H=f.useMemo(()=>re?bK(Ce,me):[],[re,me,Ce]);f.useEffect(()=>{if(i)return;const G=()=>{const we=Ny();Z(!0),we&&(xe(we),W(0))};return window.addEventListener(ol,G),()=>window.removeEventListener(ol,G)},[i]),f.useEffect(()=>{if(i)return;const G=Ny();if(W(0),G){xe(G),Z(!0);return}e&&(xe(""),Z(!1))},[e,i]),f.useEffect(()=>{if(!re||H.length===0)return;const G=Math.min(Se,H.length-1);o.current?.scrollToKey(H[G].key)},[re,Se,H,o]);const B=f.useCallback(G=>{H.length!==0&&W(we=>(we+G+H.length)%H.length)},[H.length]);f.useEffect(()=>{if(!re)return;const G=we=>{if(we.key==="Escape"){we.preventDefault(),Z(!1);return}const ce=Yc(we);ce==="mod+g"?(we.preventDefault(),B(1)):ce==="mod+shift+g"&&(we.preventDefault(),B(-1))};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[re,B]);const ne=f.useMemo(()=>(mR(),c?{conversationId:e,projectId:c,...t?{cwd:t}:{}}:null),[e,t,c]),ve=f.useRef(null),he=f.useCallback(()=>{const G=o.current?.getScroller();ve.current=G?{height:G.scrollHeight,top:G.scrollTop}:null,J.getState().loadOlderHistory(e)},[e,o]);return f.useLayoutEffect(()=>{const G=o.current?.getScroller(),we=ve.current;!G||!we||(ve.current=null,G.scrollTop=we.top+(G.scrollHeight-we.height))},[j]),n.jsxs(Jj.Provider,{value:ne,children:[re&&n.jsx(XG,{query:me,onQueryChange:G=>{xe(G),W(0)},current:H.length===0?0:Math.min(Se,H.length-1)+1,total:H.length,onPrev:()=>B(-1),onNext:()=>B(1),onClose:()=>{Z(!1),xe("")}}),te?n.jsx(jK,{conversationId:e}):n.jsx(Ox,{virtualize:!SK,ref:o,items:Ce,busy:de!==null,loading:de==="loading",running:x,runStartedAt:I,lastOutputAt:k,error:hR(p,L),emptyTitle:s,onSuggestion:r,onRetryResume:!a&&!F&&A&&M==="failed"?()=>{J.getState().resumeConversation(e)}:void 0,onRetrySync:!a&&q&&!x?()=>J.getState().retrySessionSync(e):void 0,historyLoading:U,hasOlder:j>0,olderCursor:j,onStartReached:j>0?he:void 0,searchQuery:re?me:"",quotable:l,activeHit:re?H[Se]??null:null,secretarySession:u,...h?{secretaryFace:h}:{}},e)]})}const CK=/-([0-9a-f]{8})$/i;function Sy(e){const t=e.title?.trim();return t||e.name.replace(CK,"").trim()||e.name}function IK({parentId:e,coworkerIds:t}){const{t:s,locale:r}=z(),o=pe(b=>b.agentTypes),[i,a]=f.useState([]),[l,c]=f.useState(!1),[u,d]=f.useState(null),m=f.useRef(0),h=t.join("\0"),p=J(b=>b.pendingChildRun),g=f.useCallback(()=>{const b=++m.current;return window.electronAPI.agent.listChildRuns(e).then(w=>{b===m.current&&a(w.ok?w.items:[])})},[e]);f.useEffect(()=>{g()},[g,h]);const x=f.useCallback(b=>{const w=u?.childId;return w?window.electronAPI.agent.readChildRun(e,w,b):Promise.resolve({ok:!1,code:"not-found",error:"No child run."})},[e,u?.childId]),v=b=>{if(b.available){if(c(!1),b.live&&t.includes(b.childId)){J.getState().selectTab(e,b.childId);return}d(b)}};return f.useEffect(()=>{if(!p||p.parentId!==e)return;const b=i.find(w=>w.childId===p.childId);if(b&&(J.setState({pendingChildRun:null}),!!b.available)){if(c(!1),b.live&&t.includes(b.childId)){J.getState().selectTab(e,b.childId);return}d(b)}},[p,i,e,t]),n.jsxs(n.Fragment,{children:[i.length>0&&n.jsxs(Ms,{open:l,onOpenChange:b=>{c(b),b&&g()},children:[n.jsxs(Ps,{className:"flex h-6 shrink-0 items-center justify-center gap-1 rounded-full px-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","aria-label":s("Subagent history"),title:s("Subagent history"),children:[n.jsx(Or,{className:"size-3.5"}),n.jsx("span",{className:"text-[11px] tabular-nums leading-none",children:i.length})]}),n.jsx(Ds,{align:"end",className:"w-96 [&_[data-slot=popover-viewport]]:p-1",children:n.jsx("ul",{className:"flex flex-col",children:i.map(b=>{const w=Sy(b);return n.jsx("li",{children:n.jsxs("button",{type:"button",disabled:!b.available,title:w,className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm",b.available?"hover:bg-muted":"cursor-default text-muted-foreground opacity-40"),onClick:()=>v(b),children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:w}),b.agentType&&n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:Zj(b.agentType,o)}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:Lo(b.startedAt,r)}),b.live&&n.jsx(Nl,{tone:"running",size:"sm",title:s("Running")})]})},b.childId)})})})]}),n.jsx($x,{conversationId:u?.childId??null,title:u?Sy(u):"",read:x,botSession:!1,running:u?.live===!0,onClose:()=>d(null)})]})}const TK=[{name:"pause",aliases:[],description:"Pause the current session goal"},{name:"resume",aliases:[],description:"Resume a paused session goal"},{name:"clear",aliases:[],description:"Clear the session goal"}],AK={"/goal":TK};function EK(e,t){if(!e)return null;const s=t.trimStart();return s?s.search(/\s/)>=0?null:s:""}function RK(e,t){if(!e)return[];const s=AK[e]??[],r=t.trim().toLowerCase();return r?s.filter(o=>o.name.toLowerCase().startsWith(r)||o.aliases.some(i=>i.toLowerCase().startsWith(r))):s}const Bf=new Set;let Cy=!1;function rc(e,t){t?Bf.add(e):Bf.delete(e);const s=Bf.size>0;s!==Cy&&(Cy=s,window.electronAPI?.updater?.reportUnsentDraft?.(s))}function MK(e){return e.filter(t=>t.state==="enabled").flatMap(t=>(t.statusItems??[]).filter(s=>s.visible&&s.text.trim().length>0).map(s=>({...s,pluginId:t.id,pluginName:t.name})))}let F2=[];const xh=new Set;function Iy(e){F2=e;for(const t of xh)t()}function PK(e){return xh.add(e),()=>xh.delete(e)}const Ty=()=>F2,DK={neutral:"text-muted-foreground",accent:"text-primary",success:"text-emerald-600 dark:text-emerald-400",warning:"text-amber-600 dark:text-amber-400",danger:"text-red-600 dark:text-red-400"};function OK({sessionId:e}){const t=f.useSyncExternalStore(PK,Ty,Ty);return t.length===0?null:n.jsx(n.Fragment,{children:t.map(s=>{const r=s.command?e1().find(a=>a.pluginId===s.pluginId&&a.id===s.command):void 0,o=_("shrink-0 truncate px-1 text-[11px]",DK[s.tone]),i=s.tooltip?`${s.tooltip} · ${s.pluginName}`:s.pluginName;return r?n.jsx("button",{type:"button",title:i,className:_(o,"rounded hover:bg-accent"),onClick:()=>{mp(r,e).then(a=>{a&&Ie({title:a})})},children:s.text},`${s.pluginId}:${s.id}`):n.jsx("span",{title:i,className:o,children:s.text},`${s.pluginId}:${s.id}`)})})}const z2=50,LK=64,_K=120,BK=32*1024,FK=120,oc=[];function Ay(e){return/(?:^|\s)#([^\s#]*)$/.exec(e)?.[1]??null}function zK(e,t,s){if(!Array.isArray(s))return[];const r=[];for(const o of s){if(r.length>=z2)break;if(typeof o!="object"||o===null)continue;const{id:i,label:a,detail:l}=o;typeof i!="string"||!i||typeof a!="string"||!a||r.push({key:`${e}:${t}:${i}`,pluginId:e,name:t,item:{id:i.slice(0,200),label:a.slice(0,LK),...typeof l=="string"&&l?{detail:l.slice(0,_K)}:{}}})}return r}function $K(e){const t=typeof e=="string"?e:typeof e=="object"&&e!==null?e.text:null;return typeof t=="string"&&t.length<=BK?t:null}let $2=[];const gh=new Set;function Ey(e){$2=e;for(const t of gh)t()}function VK(e){return gh.add(e),()=>gh.delete(e)}const Ry=()=>$2;function HK(e,t){const s=f.useSyncExternalStore(VK,Ry,Ry),[r,o]=f.useState(oc);return f.useEffect(()=>{if(e===null||s.length===0){o(oc);return}let i=!1;const a=setTimeout(()=>{Promise.all(s.map(async({pluginId:l,name:c})=>{const u=await window.electronAPI.extensionPlugins.call({pluginId:l,method:"trigger.candidates",payload:{name:c,query:e},sessionId:t});return u.ok?zK(l,c,u.value):oc})).then(l=>{i||o(l.flat().slice(0,z2))})},FK);return()=>{i=!0,clearTimeout(a)}},[e,s,t]),e===null?oc:r}async function WK(e,t){const s=await window.electronAPI.extensionPlugins.call({pluginId:e.pluginId,method:"trigger.pick",payload:{name:e.name,item:e.item},sessionId:t});return s.ok?$K(s.value):null}const zc="composer-drop",V2="pinned-drop",Kx="project-group:__ungrouped__",vh="project:",bh="project-group:",$c="selector-group:",yh="pinned-chat:",H2=e=>`${vh}${e}`,W2=e=>`${bh}${e}`,Yx=e=>`${$c}${e}`,UK=e=>`chat:${e}`,U2=e=>`${yh}${e}`,qK=e=>`active-chat:${e}`;function GK(e){return e.split(`
|
|
90
|
-
`)[0].trim()||"Untitled chat"}function My(e){if(e===Kx||e===`${$c}__ungrouped__`)return null;if(e.startsWith(bh)){const t=e.slice(bh.length);return t==="__all__"?void 0:t}if(e.startsWith($c)){const t=e.slice($c.length);return t==="__all__"?void 0:t}}function KK(e,t,s,r){if(!t)return null;if(e.type==="project-group"){const o=My(t);return!o||o===e.groupId?null:{kind:"reorder-groups",activeId:e.groupId,overId:o}}if(e.type==="project"){if(t===zc)return{kind:"insert-file-mention",path:e.path,label:e.name};const o=My(t);if(o!==void 0)return(r?.projectGroupId?.(e.projectId)??null)===o?null:{kind:"move-project-to-group",projectId:e.projectId,groupId:o};if(t.startsWith(vh)){const i=t.slice(vh.length);if(i===e.projectId)return null;const a=r?.projectGroupId?.(e.projectId)??null,l=r?.projectGroupId?.(i)??null;return r?.projectGroupId&&a!==l?{kind:"move-project-to-group",projectId:e.projectId,groupId:l,beforeProjectId:i}:{kind:"reorder-projects",activeId:e.projectId,overId:i}}return null}if(e.type==="workspace-file")return t===zc?{kind:"insert-file-mention",path:e.relativePath,label:e.name}:null;if(t===zc)return!e.sessionFile||e.conversationId===s?null:{kind:"insert-chat-mention",conversationId:e.conversationId,label:GK(e.title),sessionFile:e.sessionFile};if(t===V2)return e.pinned?null:{kind:"pin-conversation",conversationId:e.conversationId};if(t.startsWith(yh)){const o=t.slice(yh.length);return o===e.conversationId?null:e.pinned?{kind:"reorder-pinned",activeId:e.conversationId,overId:o}:{kind:"pin-conversation",conversationId:e.conversationId}}return null}const Py=e=>e.startsWith("/skill:");function YK(e,t){return!Py(t)||!e.every(Py)?[t]:e.includes(t)?[...e]:[...e,t]}function XK(e){const t=mj(e);if(t.names.length>0)return{slashes:t.names.map(r=>`/skill:${r}`),rest:t.rest};const s=Sd(e);return{slashes:s.slash?[s.slash]:[],rest:s.rest}}function QK(e,t,s=!1){const r=e.segments.some(i=>i.type!=="text"||i.text.length>0);if(s&&(r||e.slashes.length>0))return{slashes:e.slashes,segments:[...e.segments,...t.text?Rv(`${r?`
|
|
91
|
-
|
|
92
|
-
`:""}${t.text}`):[]],images:[...e.images,...t.images??[]]};const o=XK(t.text??"");return{slashes:o.slashes,segments:o.rest?Rv(o.rest):[],images:[...s?e.images:[],...t.images??[]]}}const JK={file:'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>',chat:'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/></svg>',"ui-element":'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 3a2 2 0 0 0-2 2"/><path d="M19 3a2 2 0 0 1 2 2"/><path d="M21 19a2 2 0 0 1-2 2"/><path d="M5 21a2 2 0 0 1-2-2"/><path d="M9 3h1"/><path d="M9 21h1"/><path d="M14 3h1"/><path d="M14 21h1"/><path d="M3 9v1"/><path d="M21 9v1"/><path d="M3 14v1"/><path d="M21 14v1"/></svg>'},ZK='<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>',eY={file:"bg-success/15 text-success",chat:"bg-warning/25 text-warning-foreground dark:bg-warning/15 dark:text-warning","ui-element":"bg-purple-500/15 text-purple-600 dark:text-purple-400"},tY='<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/><path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/></svg>';function wh(e,t){const s=e.dataset.text??"",r=e.dataset.expanded==="true",{preview:o,clipped:i}=aV(s),a=e.querySelector("[data-quote-body]");if(a&&(a.textContent=r?s:i?`${o}
|
|
93
|
-
…`:o,a.className=_("mt-0.5 block whitespace-pre-wrap break-words text-foreground/80",r?"max-h-32 overflow-y-auto overscroll-contain":"max-h-16 overflow-hidden")),e.querySelector("[data-quote-toggle]")?.remove(),!r&&i){const l=document.createElement("span");l.dataset.quoteToggle="",l.className="shrink-0 text-muted-foreground/80",l.textContent=t.expand,e.querySelector("[data-quote-remove]")?.before(l)}}function nY(e,t){const s=document.createElement("span");s.contentEditable="false",s.dataset.mentionKind="quote",s.dataset.text=e.text,e.originalLines&&(s.dataset.originalLines=String(e.originalLines)),s.className="my-1 block cursor-pointer rounded-md border-l-2 border-brand/50 bg-muted/60 px-2 py-1 text-xs select-none";const r=document.createElement("span");r.className="flex items-center gap-1.5 text-muted-foreground";const o=document.createElement("span");o.className="shrink-0 inline-flex",o.innerHTML=tY;const i=document.createElement("span");if(i.className="min-w-0 flex-1 truncate",i.textContent=t.title($S(e.text)),r.append(o,i),e.originalLines){const c=document.createElement("span");c.dataset.quoteTruncated="",c.className="shrink-0 rounded bg-warning/20 px-1 text-warning-foreground dark:text-warning",c.textContent=t.truncated(e.originalLines),r.appendChild(c)}const a=document.createElement("button");a.type="button",a.dataset.quoteRemove="",a.setAttribute("aria-label",t.remove),a.className="shrink-0 rounded-sm px-1 opacity-70 hover:opacity-100",a.textContent="×",r.appendChild(a);const l=document.createElement("span");return l.dataset.quoteBody="",s.append(r,l),wh(s,t),s}function ic(e,t){if(e.type==="quote")return nY(e,t);const s=document.createElement("span");s.contentEditable="false",s.dataset.mentionKind=e.type,e.type==="file"?(s.dataset.path=e.path,e.label&&(s.dataset.label=e.label),s.title=e.path):e.type==="chat"?(s.dataset.label=e.label,s.dataset.sessionFile=e.sessionFile,e.conversationId&&(s.dataset.conversationId=e.conversationId)):(s.dataset.id=e.id,s.dataset.label=e.label,s.dataset.path=e.path,s.dataset.text=e.text,s.dataset.imageId=e.imageId,s.title=`${e.path}${e.text?` · ${e.text}`:""}`),s.className=_("mx-0.5 inline-flex max-w-52 items-center gap-1 rounded-md px-1.5 py-0.5 align-middle text-xs font-medium leading-4 select-none",eY[e.type]);const r=document.createElement("span");r.className="shrink-0 inline-flex",r.innerHTML=e.type==="file"&&/[\\/]$/.test(e.path)?ZK:JK[e.type],s.appendChild(r);const o=document.createElement("span");return o.className="truncate",o.textContent=e.type==="file"?e.label??du(e.path):e.label,s.appendChild(o),s}function q2(e){if(e.dataset.mentionKind==="quote"&&e.dataset.text){const t=Number(e.dataset.originalLines);return{type:"quote",text:e.dataset.text,...t>0?{originalLines:t}:{}}}return e.dataset.mentionKind==="file"&&e.dataset.path?{type:"file",path:e.dataset.path,...e.dataset.label?{label:e.dataset.label}:{}}:e.dataset.mentionKind==="chat"&&e.dataset.label&&e.dataset.sessionFile?{type:"chat",label:e.dataset.label,sessionFile:e.dataset.sessionFile,...e.dataset.conversationId?{conversationId:e.dataset.conversationId}:{}}:e.dataset.mentionKind==="ui-element"&&e.dataset.label&&e.dataset.path&&e.dataset.text?{type:"ui-element",id:e.dataset.id??"",label:e.dataset.label,path:e.dataset.path,text:e.dataset.text,imageId:e.dataset.imageId??""}:null}function Ff(e){const t=[],s=o=>{if(!o)return;const i=t.at(-1);i?.type==="text"?i.text+=o:t.push({type:"text",text:o})},r=o=>{if(o.nodeType===Node.TEXT_NODE){s(o.textContent??"");return}if(!(o instanceof HTMLElement))return;if(o.dataset.mentionKind){const a=q2(o);a&&t.push(a);return}if(o.tagName==="BR"){s(`
|
|
94
|
-
`);return}(o.tagName==="DIV"||o.tagName==="P")&&t.length>0&&s(`
|
|
95
|
-
`);for(const a of o.childNodes)r(a)};for(const o of e.childNodes)r(o);return t}function zf(e){const t=window.getSelection();if(!t||t.rangeCount===0||!t.isCollapsed)return null;const{anchorNode:s,anchorOffset:r}=t;return!s||!e.contains(s)||s.nodeType!==Node.TEXT_NODE?null:{node:s,offset:r}}function sY(e,t){if(t.rangeCount===0||!t.isCollapsed)return null;const{anchorNode:s,anchorOffset:r}=t;if(!s||s.nodeType===Node.TEXT_NODE||s!==e&&!e.contains(s))return null;const o=s.childNodes,i=o[r],a=r>0?o[r-1]:void 0,l=i?.nodeType===Node.TEXT_NODE?{node:i,offset:0}:a?.nodeType===Node.TEXT_NODE?{node:a,offset:a.length}:null;if(!l)return null;const c=document.createRange();return c.setStart(l.node,l.offset),c.collapse(!0),c}function ac(e){return e instanceof HTMLElement&&!!e.dataset.mentionKind}function ua(e){return e instanceof Text&&!/[^\s\u00a0]/.test(e.textContent??"")}function rY(e,t){const s=window.getSelection();if(!s||s.rangeCount===0||!s.isCollapsed)return null;const{anchorNode:r,anchorOffset:o}=s;if(!r||!e.contains(r))return null;if(r.nodeType===Node.TEXT_NODE){const c=r.textContent??"";if(t==="before"){if(/[^\s\u00a0]/.test(c.slice(0,o)))return null;let d=r.previousSibling;for(;ua(d);)d=d.previousSibling;return ac(d)?d:null}if(/[^\s\u00a0]/.test(c.slice(o)))return null;let u=r.nextSibling;for(;ua(u);)u=u.nextSibling;return ac(u)?u:null}const i=r.childNodes;if(t==="before"){let c=o-1;for(;c>=0&&ua(i[c]);)c-=1;const u=c>=0?i[c]:null;return ac(u)?u:null}let a=o;for(;a<i.length&&ua(i[a]);)a+=1;const l=i[a];return ac(l)?l:null}function Dy(e,t){const s=e.nextSibling;ua(s)&&s.remove();const r=e.previousSibling;if(e.remove(),r){G2(r);return}const o=window.getSelection();if(!o)return;const i=document.createRange();i.setStart(t,0),i.collapse(!0),o.removeAllRanges(),o.addRange(i)}function G2(e){const t=window.getSelection();if(!t)return;const s=document.createRange();s.setStartAfter(e),s.collapse(!0),t.removeAllRanges(),t.addRange(s)}const oY=f.forwardRef(function({placeholder:t,disabled:s,className:r,onStateChange:o,onKeyDown:i,onPaste:a,onPasteText:l,onCompositionStart:c,onCompositionEnd:u,onChipActivate:d,ariaProps:m},h){const{t:p}=z(),g=f.useRef(null),x={title:N=>p("Quote · {{count}} lines",{count:N}),truncated:N=>p("Truncated · original {{count}} lines",{count:N}),expand:p("Click to expand"),remove:p("Remove quote")},v=f.useRef(x);v.current=x;const b=f.useRef(null);f.useEffect(()=>{const N=S=>{const I=S.target;for(const k of g.current?.querySelectorAll('[data-mention-kind="quote"][data-expanded]')??[])I&&k.contains(I)||(delete k.dataset.expanded,wh(k,v.current))};return document.addEventListener("pointerdown",N),()=>document.removeEventListener("pointerdown",N)},[]),f.useEffect(()=>{const N=()=>{const S=g.current;if(!S||document.activeElement!==S)return;const I=window.getSelection();if(!I||I.rangeCount===0||!I.isCollapsed)return;const k=I.anchorNode;if(k&&(k===S||S.contains(k))){const A=sY(S,I);A?(I.removeAllRanges(),I.addRange(A)):k.nodeType===Node.TEXT_NODE&&(b.current={node:k,offset:I.anchorOffset});return}const L=b.current,F=document.createRange();L?.node.isConnected&&S.contains(L.node)?(F.setStart(L.node,Math.min(L.offset,L.node.length)),F.collapse(!0)):(F.selectNodeContents(S),F.collapse(!0)),I.removeAllRanges(),I.addRange(F)};return document.addEventListener("selectionchange",N),()=>document.removeEventListener("selectionchange",N)},[]);const w=f.useCallback(()=>{const N=g.current;if(!N)return;const S=Ff(N),I=S.map($=>$.type==="text"?$.text:"").join(""),k=S.some($=>$.type!=="text");let L=null,F=null,A=null,M=null;const R=zf(N);if(R){const $=R.node.textContent?.slice(0,R.offset)??"";L=Av($,$.length),L===null&&(A=fh($,$.length)),L===null&&A===null&&(M=Ay($)),L===null&&R.node===N.firstChild&&/^\/[^\s]*$/.test($)&&(F=$.slice(1))}o({plainText:I,hasMentions:k,segments:S,mentionQuery:L,slashQuery:F,skillQuery:A,pluginQuery:M})},[o]),j=f.useCallback(N=>{const S=g.current;if(!S)return null;const I=zf(S);if(!I)return null;const k=I.node.textContent?.slice(0,I.offset)??"";if(N==="#"){const L=Ay(k);return L===null?null:{node:I.node,start:k.length-L.length-1,end:I.offset}}if(N==="@"||N==="$"){const L=N==="@"?Av(k,k.length):fh(k,k.length);return L===null?null:{node:I.node,start:k.length-L.length-1,end:I.offset}}return I.node!==S.firstChild||!/^\/[^\s]*$/.test(k)?null:{node:I.node,start:0,end:I.offset}},[]),T=f.useCallback((N,S)=>{const I=g.current;if(!I)return;I.focus();const k=document.createRange(),L=S?j("@"):null;if(L)k.setStart(L.node,L.start),k.setEnd(L.node,L.end),k.deleteContents();else{const M=zf(I);M?(k.setStart(M.node,M.offset),k.collapse(!0)):(k.selectNodeContents(I),k.collapse(!1))}const F=N();k.insertNode(F);const A=document.createTextNode(" ");F.parentNode?.insertBefore(A,F.nextSibling),G2(A),w()},[j,w]);return f.useImperativeHandle(h,()=>({focus:()=>g.current?.focus(),isEmpty:()=>{const N=g.current;return N?!Ff(N).some(I=>I.type!=="text"||I.text.trim().length>0):!0},getSegments:()=>g.current?Ff(g.current):[],setSegments:N=>{const S=g.current;if(S){S.textContent="";for(const I of N)I.type==="text"?S.appendChild(document.createTextNode(I.text)):S.appendChild(ic(I,v.current));w()}},clear:()=>{const N=g.current;N&&(N.textContent="",w())},insertMention:N=>{const S=N.kind==="file"?{type:"file",path:N.relativePath}:N.kind==="chat"?{type:"chat",label:N.label,sessionFile:N.sessionFile,conversationId:N.id}:{type:"ui-element",id:N.id,label:N.label,path:N.path,text:N.text,imageId:N.imageId};T(()=>ic(S,v.current),N.kind!=="ui-element")},consumeToken:N=>{const S=j(N);if(!S)return;const I=document.createRange();I.setStart(S.node,S.start),I.setEnd(S.node,S.end),I.deleteContents(),w()},insertFileChip:(N,S)=>{T(()=>ic({type:"file",path:N,...S?{label:S}:{}},v.current),!1)},insertText:N=>{T(()=>document.createTextNode(N),!1)},insertQuote:N=>{const S=g.current;if(!S)return;const I=document.createTextNode(" ");S.append(ic(N,v.current),I),S.focus(),window.getSelection()?.collapse(I,I.length),S.scrollTop=S.scrollHeight,w()},getMentionAnchorRect:()=>{const N=j("@");if(!N)return null;const S=document.createRange();return S.setStart(N.node,N.start),S.setEnd(N.node,Math.min(N.start+1,N.node.length)),S.getBoundingClientRect()}}),[j,w,T]),n.jsx("div",{ref:g,contentEditable:!s,role:m?.role??"textbox","aria-placeholder":t,"data-placeholder":t,...m,onInput:w,onKeyDown:N=>{if(!N.nativeEvent.isComposing&&(N.key==="Backspace"||N.key==="Delete")){const S=g.current,I=S&&rY(S,N.key==="Backspace"?"before":"after");if(I&&S){N.preventDefault(),Dy(I,S),w();return}}i(N)},onClick:N=>{const S=N.target;if(!(S instanceof Element))return;const I=S.closest("[data-mention-kind]");if(!(I instanceof HTMLElement)||!g.current?.contains(I))return;if(I.dataset.mentionKind==="quote"){S.closest("[data-quote-remove]")?(Dy(I,g.current),w()):I.dataset.expanded!=="true"&&(I.dataset.expanded="true",wh(I,v.current));return}if(!d)return;const k=q2(I);k&&d(k)},onKeyUp:N=>{N.key!=="Escape"&&w()},onMouseUp:w,onPaste:N=>{if(N.clipboardData.files.length>0){a(N);return}N.preventDefault();const S=N.clipboardData.getData("text/plain");S&&(l?.(S)||document.execCommand("insertText",!1,S))},onCompositionStart:c,onCompositionEnd:()=>{u(),w()},className:_("max-h-40 min-h-10 min-w-0 flex-1 overflow-y-auto pt-0.5 text-sm break-words whitespace-pre-wrap outline-none","empty:before:pointer-events-none empty:before:text-muted-foreground empty:before:content-[attr(data-placeholder)]",s&&"opacity-60",r)})}),iY=/[\\/]/;function aY(e){return e.split(iY).filter(t=>t.length>0)}function lY(e){const t=new Map,s=e.map(aY),r=s.map(o=>o.join("/"));for(let o=0;o<e.length;o++){const i=e[o],a=s[o]??[];let l=Math.max(0,a.length-3);for(;l>0;){const u=a.slice(l).join("/");if(!r.some(m=>m!==r[o]&&(m===u||m.endsWith(`/${u}`))))break;l--}const c=a.slice(l).join("/");t.set(i,l>0?`…/${c}`:c)}return t}function cY({groups:e,query:t,activeIndex:s,onActiveIndexChange:r,openFolderId:o,folderIndex:i,onOpenFolderIdChange:a,onFolderIndexChange:l,onSelect:c,id:u="composer-mention-picker",left:d=0,flyoutSide:m="right"}){const{t:h}=z(),p=Ho(),g=f.useMemo(()=>FC(e,t),[e,t]),x=f.useMemo(()=>lY(e.files.map(A=>A.relativePath)),[e.files]),v=f.useRef(new Map),b=f.useRef(new Map),w=g[0]?.type==="folder";if(f.useEffect(()=>{v.current.get(s)?.scrollIntoView({block:"nearest"})},[s]),f.useEffect(()=>{o&&b.current.get(i)?.scrollIntoView({block:"nearest"})},[o,i]),g.length===0)return null;const j={agents:h("Agents"),members:h("Members"),chats:h("Chats")},T={agents:ws,members:ki,chats:Or},N=o?e[o]:[];let S=0;const I=()=>N.map((A,M)=>n.jsx(Oy,{ref:R=>{R?b.current.set(M,R):b.current.delete(M)},id:`${u}-sub-${M}`,candidate:A,active:M===i,onHover:()=>l(M),onSelect:()=>c(A)},`sub:${A.id}`)),k=!!(p&&o&&N.length>0),L=A=>n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button","data-slot":"mention-sheet-back",onClick:()=>a(null),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",children:[n.jsx(pR,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 font-medium",children:j[A]})]}),I()]}),F=(A,M)=>{const R=e[A];if(R.length===0)return null;const $=A==="files"?h("Files"):j[A];return n.jsxs("div",{role:"group","aria-label":$,children:[n.jsx("p",{className:_("px-2 pb-1 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",M?"pt-2":"pt-1.5"),children:$}),R.map(U=>{const q=S++;return n.jsx(Oy,{ref:te=>{te?v.current.set(q,te):v.current.delete(q)},id:`${u}-option-${q}`,candidate:U,active:q===s,pathLabel:U.kind==="file"?x.get(U.relativePath):void 0,onHover:()=>{r(q),w&&a(null)},onSelect:()=>c(U)},`${A}:${U.id}`)})]})};return n.jsxs("div",{"data-slot":"mention-picker",className:p?"absolute inset-x-0 bottom-full z-10 mb-1.5 w-full":"absolute bottom-full z-10 mb-1.5 max-w-full",style:p?void 0:{left:d},children:[n.jsx("div",{id:u,role:"listbox","aria-label":h("Mention suggestions"),className:p?"max-h-[50dvh] w-full overflow-y-auto rounded-lg border bg-popover p-1 shadow-md":"max-h-72 w-80 max-w-full overflow-y-auto rounded-lg border bg-popover p-1 shadow-md",children:k&&o?L(o):w?n.jsxs(n.Fragment,{children:[g.filter(A=>A.type==="folder").map(A=>{const M=S++,R=T[A.id];return n.jsxs("button",{ref:$=>{$?v.current.set(M,$):v.current.delete(M)},id:`${u}-option-${M}`,type:"button",role:"option","aria-selected":s===M,onClick:()=>{r(M),a(A.id),l(0)},onMouseMove:()=>{r(M),!p&&o!==A.id&&(a(A.id),l(0))},className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",s===M&&"bg-foreground/10"),children:[n.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border bg-background",children:n.jsx(R,{className:"h-3.5 w-3.5 text-muted-foreground"})}),n.jsx("span",{className:"min-w-0 flex-1 font-medium",children:j[A.id]}),n.jsx(fn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]},`folder:${A.id}`)}),F("files",!0)]}):n.jsxs(n.Fragment,{children:[F("agents",!1),F("members",e.agents.length>0),F("chats",e.agents.length+e.members.length>0),F("files",e.agents.length+e.members.length+e.chats.length>0)]})}),!p&&o&&N.length>0&&n.jsx("div",{role:"listbox","aria-label":j[o],"data-slot":"mention-flyout",className:_("absolute top-0 z-20 max-h-72 w-72 overflow-y-auto rounded-lg border bg-popover p-1 shadow-md",m==="right"?"left-full ml-1":"right-full mr-1"),children:I()})]})}function Oy({ref:e,id:t,candidate:s,active:r,pathLabel:o,onHover:i,onSelect:a}){const{t:l}=z(),c=dY(s),u=s.kind==="agent-type"?s.source==="bot"?ki:ws:s.kind==="chat"?Or:c?lu:Wo;return n.jsxs("button",{ref:e,id:t,type:"button",role:"option","aria-selected":r,onClick:a,onMouseMove:i,className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",r&&"bg-foreground/10"),children:[n.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border bg-background",children:n.jsx(u,{className:"h-3.5 w-3.5 text-muted-foreground"})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"shrink-0 font-medium",children:s.label}),n.jsx(ji,{variant:"outline",className:"px-1 py-0 text-[9px]",children:s.kind==="agent-type"?l(s.source==="system"?"System":s.source==="builtin"?"Built-in":s.source==="bot"?"Member":"Custom"):s.kind==="chat"?l("Chat"):l(c?"Folder":"File")}),s.kind==="agent-type"&&s.locked&&n.jsx(ji,{variant:"secondary",className:"px-1 py-0 text-[9px]",children:l("Locked")})]}),n.jsx("span",{className:_("block text-muted-foreground",s.kind==="file"?"whitespace-normal break-all":"truncate"),title:s.kind==="file"?s.relativePath:void 0,children:s.kind==="agent-type"?s.source==="bot"?s.description:l(s.description):s.kind==="chat"?s.sessionFile.split("/").at(-1):s.kind==="file"?o??s.relativePath:s.path})]})]})}function dY(e){return e.kind==="file"&&/[\\/]$/.test(e.relativePath)}function uY(e,t){return e.filter(s=>s!==t)}const Ly=new Map,fY=e=>e.images.length>0||e.segments.some(t=>t.type!=="text"||t.text.trim()!==""),mY=()=>!!window.electronAPI?.remote&&window.matchMedia?.("(pointer: coarse)").matches===!0;function hY({mentionConversationId:e,commands:t,running:s,busy:r,focusKey:o,pluginPresetId:i=null,autoFocus:a=!window.electronAPI?.remote,enterToSend:l=!mY(),toolbar:c,locked:u=!1,injectedDraft:d,injectedImages:m,injectedDraftAppend:h,onDraftConsumed:p,chatCandidates:g,onActivate:x,onSend:v,onAbort:b,queuedCount:w=0,onSteerQueued:j,isolated:T=!1,placeholder:N,planMode:S=!1,savePastedText:I}){const{t:k}=z(),L=Ho(),F=pe(ae=>ae.keybindings),A=pe(ae=>ae.privacyMasking),M=Pr(F)["send-message"],R=f.useId(),[$,U]=f.useState([]),[q,te]=f.useState([]),[V,se]=f.useState(),Ce=f.useRef(o),[de,re]=f.useState(!1),{setNodeRef:Z,isOver:me}=vl({id:T?`isolated-composer:${o??"side"}`:zc,disabled:T}),[xe,Se]=f.useState(null),[W,H]=f.useState(null),B=f.useRef(new Set),ne=f.useRef(v);ne.current=v;const ve=f.useRef(A);ve.current=A,f.useEffect(()=>{if(T)return;const ae=f8(ze=>he.current?.insertMention(ze)),Ne=h8(ze=>he.current?.insertText(ze)),_e=p8(ze=>he.current?.insertQuote(ze)),Be=m8(()=>he.current?.focus()),Ze=b8((ze,Qe)=>{Qe&&U(Ke=>[...Ke,{...Qe,id:ze.imageId}]),he.current?.insertMention(ze),he.current?.focus()}),ft=y8(ze=>{U(Qe=>[...Qe,{data:ze.data,mimeType:ze.mimeType}]),he.current?.focus()}),ht=g8(ze=>{if(Re.current)return!1;const Qe=ve.current,Ke=Qe.enabled?zu(ze.text,Qe).blocked:[];return Ke.length>0?(Ie({type:"error",title:k("Message not sent"),description:k("Privacy masking blocks {{kinds}}. Remove it, or change the action or allow list in Settings → Privacy.",{kinds:Ke.join(", ")})}),!1):ne.current(ze)!==!1});return()=>{ae(),Ne(),_e(),Be(),Ze(),ft(),ht()}},[T,k]);const he=f.useRef(null),G=f.useRef(null),we=f.useRef(null),ce=f.useRef(!1),Re=f.useRef(u);Re.current=u,f.useEffect(()=>{if(!(T||!o))return xR({key:o,segments:()=>he.current?.getSegments()??[],insertText:ae=>he.current?.insertText(ae),setText:ae=>he.current?.setSegments(ae?[{type:"text",text:ae}]:[]),busy:()=>ce.current||Re.current||!he.current})},[T,o]);const[ue,We]=f.useState({left:0,flyoutSide:"right"}),[it,Fe]=f.useState(""),[tt,ke]=f.useState(!1),nt=f.useRef(Symbol("composer")),mt=it.trim()!==""||tt||$.length>0;f.useEffect(()=>rc(nt.current,mt),[mt]),f.useEffect(()=>()=>rc(nt.current,!1),[]);const[X,K]=f.useState(null),Ee=zC(e,X,g),pt=f.useMemo(()=>FC(Ee,X??""),[Ee,X]),[Pt,Je]=f.useState(null),[Lt,on]=f.useState(null),[Pe,Dt]=f.useState(null),Vt=HK(Pe,o??null),[Et,oe]=f.useState(0),[Le,st]=f.useState(null),[at,gt]=f.useState(0),xt=f.useRef(null),zt=f.useCallback(ae=>{(ae.plainText.trim()||ae.hasMentions)&&x?.(),Fe(ae.plainText),ke(ae.hasMentions);const Ne=new Set(ae.segments.filter(Be=>Be.type==="ui-element"&&Be.imageId).map(Be=>Be.type==="ui-element"?Be.imageId:"")),_e=[...B.current].filter(Be=>!Ne.has(Be));B.current=Ne,_e.length>0&&(U(Be=>gR(Be,_e)),Se(Be=>Be&&_e.includes(Be.imageId)?null:Be)),K(Be=>(Be!==ae.mentionQuery&&(oe(0),st(null),gt(0)),ae.mentionQuery)),Je(ae.slashQuery),on(ae.skillQuery),Dt(ae.pluginQuery)},[x]);f.useEffect(()=>{const ae=Ce.current;if(ae!==o){if(ae){const Be={segments:he.current?.getSegments()??[],images:$,slashes:q,recipient:V};Ly.set(ae,Be),rc(`draft:${ae}`,fY(Be))}const Ne=o?Ly.get(o):void 0;o&&rc(`draft:${o}`,!1);const _e=o?vR(o):void 0;he.current?.setSegments(_e?[{type:"text",text:_e}]:Ne?.segments??[]),B.current=new Set((Ne?.segments??[]).filter(Be=>Be.type==="ui-element"&&Be.imageId).map(Be=>Be.type==="ui-element"?Be.imageId:"")),U(Ne?.images??[]),te(Ne?.slashes??[]),se(Ne?.recipient),Ce.current=o,K(null),Je(null),on(null),oe(0),st(null),gt(0)}a&&he.current?.focus()},[o]),f.useEffect(()=>{if(!d&&!m?.length)return;const ae=QK({segments:he.current?.getSegments()??[],images:$,slashes:q},{text:d,images:m},h);te(ae.slashes),U(ae.images),he.current?.setSegments(ae.segments),p?.(),window.setTimeout(()=>he.current?.focus(),0)},[d,m,h]);const Wt=q.length===1?q[0]:null,an=EK(Wt,it.replaceAll("","")),en=vU(t,Pt,Lt),Bt=Pt===null&&Lt===null&&an!==null?RK(Wt,an):[];f.useEffect(()=>{oe(0)},[Pt,Lt,an,Pe]),f.useEffect(()=>{xt.current?.children[Et]?.scrollIntoView({block:"nearest"})},[Et]);const pn=f.useCallback(ae=>{if(ae.kind==="agent-type"){he.current?.consumeToken("@"),se(ae),K(null);return}he.current?.insertMention(ae),K(null)},[]),Gn=f.useCallback(ae=>{Dt(null),WK(ae,o??null).then(Ne=>{const _e=he.current;_e&&(_e.consumeToken("#"),Ne&&_e.insertText(Ne))})},[o]),vt=X!==null&&pt.length>0?"mention":Pe!==null&&Vt.length>0?"plugin":en.length>0?"slash":Bt.length>0?"slash-sub":null;f.useLayoutEffect(()=>{if(vt!=="mention")return;const ae=G.current;if(!ae)return;const Ne=()=>{const _e=ae.getBoundingClientRect(),Be=ae.querySelector('[data-slot="mention-picker"]'),Ze=Be?.querySelector('[role="listbox"]'),ft=Be?.querySelector('[data-slot="mention-flyout"]'),ht=he.current?.getMentionAnchorRect(),ze=CF({anchorLeft:ht?ht.left-_e.left:0,containerWidth:_e.width,popupWidth:Ze instanceof HTMLElement?Ze.offsetWidth:280,flyoutWidth:ft instanceof HTMLElement?ft.offsetWidth:252,flyoutGap:4});We(Qe=>Qe.left===ze.left&&Qe.flyoutSide===ze.flyoutSide?Qe:ze)};return Ne(),window.addEventListener("resize",Ne),()=>window.removeEventListener("resize",Ne)},[X,it,Le,vt]);const sn=vt==="mention"?pt.length:vt==="plugin"?Vt.length:vt==="slash-sub"?Bt.length:en.length,Rn=f.useCallback((ae,Ne)=>{const _e=[{type:"text",text:ae}];if(he.current?.setSegments(_e),!Ne)return;const Be=Pv({segments:_e,slashes:q,images:$,recipient:V});v(Be)!==!1&&(he.current?.clear(),U([]),te([]),se(void 0),K(null),Je(null),on(null))},[$,v,V,q]),C=f.useCallback(ae=>{he.current?.consumeToken(Lt!==null?"$":"/"),Je(null),on(null);const Ne=bR(ae);if(!Ne){te(_e=>YK(_e,ae));return}mp(Ne,T?null:o??null).then(_e=>{_e&&Ie({type:"error",title:k("Plugin command failed"),description:_e})})},[Lt,T,o,k]),D=f.useCallback((ae=!1)=>{if(vt==="mention"){if(Le){const _e=Ee[Le][at];_e&&pn(_e);return}const Ne=pt[Et];Ne?.type==="item"&&pn(Ne.candidate)}else if(vt==="plugin"){const Ne=Vt[Et];Ne&&Gn(Ne)}else if(vt==="slash"){const Ne=en[Et];Ne&&C(Ne.name)}else if(vt==="slash-sub"){const Ne=Bt[Et];if(!Ne)return;Rn(Ne.name,ae)}},[Et,at,Le,Ee,pt,pn,Gn,Vt,vt,en,C,Bt,Rn]),P=it.replaceAll("","").trim(),y=!!(P||q.length>0||$.length>0||tt),E=V!==void 0,Y=r&&!E,ee={sessionId:T?null:o??null,draft:it.replaceAll("",""),busy:u,pluginPresetId:i},ge=s&&w>0&&j!==void 0&&l&&!!M,Te=ge&&!y&&!E&&!u,Ve=f.useMemo(()=>A.enabled&&P?zu(P,A):null,[P,A]),He=()=>{if(!y)return;const ae=Pv({segments:he.current?.getSegments()??[],slashes:q,images:$,recipient:V}),Ne=A.enabled?zu(ae.text,A).blocked:[];if(Ne.length>0){Ie({type:"error",title:k("Message not sent"),description:k("Privacy masking blocks {{kinds}}. Remove it, or change the action or allow list in Settings → Privacy.",{kinds:Ne.join(", ")})});return}v(ae)!==!1&&(he.current?.clear(),U([]),te([]),se(void 0),K(null),Je(null),on(null))},bt=f.useCallback(ae=>{for(const Ne of ae){if(Ne.type.startsWith("image/")){const Ze=new FileReader;Ze.onload=()=>{const ft=Ze.result,ht=ft.slice(ft.indexOf(",")+1);U(ze=>[...ze,{data:ht,mimeType:Ne.type}])},Ze.readAsDataURL(Ne);continue}const _e=window.electronAPI.files.pathForFile(Ne),Be=window.electronAPI.remote;if(!_e&&Be){Be.upload(Ne).then(Ze=>{Ze&&he.current?.insertFileChip(Ze)}).catch(()=>{});continue}_e&&he.current?.insertFileChip(_e)}},[]);f.useEffect(()=>{if(T)return;const ae=j8(_e=>{bt(_e),he.current?.focus()}),Ne=S8(_e=>{for(const Be of _e)he.current?.insertFileChip(Be);he.current?.focus()});return()=>{ae(),Ne()}},[T,bt]);const Xe=ae=>{const Ne=ae.nativeEvent.isComposing||ce.current;if(vt){const Be=vt==="mention"?pt[Et]:void 0,Ze=IF({key:ae.key,shiftKey:ae.shiftKey,isComposing:Ne,activeIndex:Et,itemCount:sn,folderOpen:vt==="mention"&&Le!==null,activeIsFolder:vt==="mention"&&Be?.type==="folder",folderIndex:at,folderItemCount:Le?Ee[Le].length:0});if(Ze.type==="move"){ae.preventDefault(),oe(Ze.index),st(null);return}if(Ze.type==="move-folder"){ae.preventDefault(),gt(Ze.index);return}if(Ze.type==="open-folder"){ae.preventDefault(),Be?.type==="folder"&&st(Be.id),gt(0);return}if(Ze.type==="close-folder"){ae.preventDefault(),st(null);return}if(Ze.type==="pick"){ae.preventDefault(),D(vt==="slash-sub"&&ae.key==="Enter");return}if(Ze.type==="close"){ae.preventDefault(),K(null),Je(null),on(null),Dt(null),st(null);return}}if(Ne)return;const _e=Yc(ae);if(!T&&_e&&_e===Pr(pe.getState().keybindings)["switch-model"]){ae.preventDefault(),yR();return}if(ae.key==="Backspace"&&q.length>0&&P.length===0&&!tt){ae.preventDefault(),te(Be=>Be.slice(0,-1));return}if(ae.key==="Backspace"&&V&&he.current?.isEmpty()&&q.length===0){ae.preventDefault(),se(void 0);return}l&&!vt&&Yc(ae,{allowBare:!0})===M&&(ae.preventDefault(),Te?j?.():He())};return n.jsxs("div",{ref:G,className:"relative",children:[vt==="mention"&&n.jsx(cY,{id:R,groups:Ee,query:X??"",activeIndex:Et,onActiveIndexChange:oe,openFolderId:Le,folderIndex:at,onOpenFolderIdChange:st,onFolderIndexChange:gt,onSelect:pn,left:ue.left,flyoutSide:ue.flyoutSide}),vt==="plugin"&&n.jsx("div",{ref:xt,role:"listbox","aria-label":k("Plugin suggestions"),className:"absolute bottom-full left-0 z-10 mb-1.5 max-h-64 w-full overflow-y-auto rounded-lg border bg-popover p-1 shadow-md",children:Vt.map((ae,Ne)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ne===Et,onMouseDown:_e=>_e.preventDefault(),onClick:()=>Gn(ae),onMouseMove:()=>oe(Ne),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",Ne===Et&&"bg-foreground/10"),children:[n.jsx("span",{className:"shrink-0 font-mono text-muted-foreground",children:"#"}),n.jsx("span",{className:"shrink-0 font-medium",children:ae.item.label}),ae.item.detail&&n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:ae.item.detail})]},ae.key))}),(vt==="slash"||vt==="slash-sub")&&n.jsx("div",{ref:xt,role:"listbox","aria-label":k("Command suggestions"),className:"absolute bottom-full left-0 z-10 mb-1.5 max-h-64 w-full overflow-y-auto rounded-lg border bg-popover p-1 shadow-md",children:(vt==="slash"?en:Bt).map((ae,Ne)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ne===Et,onClick:()=>{oe(Ne),vt==="slash"?C(ae.name):Rn(ae.name,!1)},onMouseMove:()=>oe(Ne),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",Ne===Et&&"bg-foreground/10"),children:[n.jsx(RN,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 font-mono font-medium",children:Lt!==null?`$${ae.name.slice(7)}`:ae.name}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:k(ae.description)})]},ae.name))}),n.jsxs("div",{ref:Z,"data-slot":"composer","data-enso":"composer",className:_("rounded-[24px] border bg-card shadow-[0_2px_6px_rgb(0_0_0/0.03),0_12px_32px_rgb(0_0_0/0.07)] transition-[border-color,box-shadow] duration-200 focus-within:border-foreground/20 [.dark_&]:shadow-[0_2px_6px_rgb(0_0_0/0.2),0_12px_32px_rgb(0_0_0/0.3)]",(de||me)&&"border-brand/50 bg-brand/5",(E||S)&&"border-primary/35 shadow-primary/5"),onDragOver:ae=>{ae.dataTransfer.types.includes("Files")&&(ae.preventDefault(),re(!0))},onDragLeave:ae=>{ae.currentTarget.contains(ae.relatedTarget)||re(!1)},onDrop:ae=>{const Ne=Array.from(ae.dataTransfer.files);Ne.length!==0&&(ae.preventDefault(),re(!1),bt(Ne))},children:[$.filter(ae=>!ae.id).length>0&&n.jsx("div",{className:"flex flex-wrap gap-2 px-3 pt-3",children:$.filter(ae=>!ae.id).map((ae,Ne)=>n.jsxs("div",{className:"group relative",children:[n.jsx("button",{type:"button",onClick:()=>H(ae),className:"block rounded-md focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none","aria-label":k("Preview"),children:n.jsx("img",{src:`data:${ae.mimeType};base64,${ae.data}`,alt:"",className:"h-16 w-16 rounded-md border object-cover"})}),n.jsx("button",{type:"button",onClick:()=>U(_e=>uY(_e,ae)),className:"absolute -top-1.5 -right-1.5 rounded-full border bg-background p-0.5 text-muted-foreground shadow-sm transition-opacity hover:text-destructive",children:n.jsx(Jt,{className:"h-3 w-3"})})]},Ne))}),n.jsxs("div",{className:_("flex items-start gap-1.5 px-4",$.length>0?"pt-1.5":"pt-3.5"),children:[V&&n.jsx(GH,{recipient:V,onRemove:()=>se(void 0)}),q.map(ae=>n.jsx(Cd,{name:ae,className:"mt-0.5 shrink-0",trailing:n.jsx("button",{type:"button",onClick:()=>te(Ne=>Ne.filter(_e=>_e!==ae)),className:"rounded-sm opacity-70 hover:opacity-100","aria-label":k("Remove"),children:n.jsx(Jt,{className:"h-3 w-3"})})},ae)),n.jsx(oY,{ref:he,placeholder:q.length>0?"":u?k("Resolve the pending approval to continue"):E?k("Message the selected Agent…"):ge?k("Press {{key}} to steer the next queued message into this round…",{key:qs(M)}):N||k(s?"Message will queue until this round finishes…":"Type @ to choose a file or Agent"),disabled:u,onStateChange:zt,onChipActivate:ae=>{ae.type==="ui-element"&&Se({kind:"ui-element",id:ae.id,label:ae.label,path:ae.path,text:ae.text,imageId:ae.imageId})},onKeyDown:Xe,onPasteText:ae=>!I||!Nj(ae)?!1:(I(ae).catch(()=>({ok:!1,error:"unavailable"})).then(Ne=>{const _e=he.current;Ne.ok?_e?.insertFileChip(Ne.path,`${Hj} · ${k("{{count}} chars",{count:Ne.chars.toLocaleString()})}`):_e?.insertText(ae)}),!0),onPaste:ae=>{const Ne=Array.from(ae.clipboardData.files);Ne.length!==0&&(ae.preventDefault(),bt(Ne))},onCompositionStart:()=>{ce.current=!0},onCompositionEnd:()=>{ce.current=!1},ariaProps:{role:"combobox","aria-autocomplete":"list","aria-expanded":vt!==null,"aria-controls":vt==="mention"?R:void 0,"aria-activedescendant":vt==="mention"?Le?`${R}-sub-${at}`:`${R}-option-${Et}`:void 0}})]}),E&&n.jsx("p",{className:"sr-only",children:k("Send only to the selected Agent")}),n.jsxs("div",{className:"flex items-center justify-between gap-1.5 px-3 pt-0.5 pb-2.5",children:[n.jsxs("div",{className:_("flex min-w-0 flex-1 items-center",L?"gap-0.5 overflow-x-auto [scrollbar-width:none]":"gap-1 overflow-hidden"),children:[n.jsx("input",{ref:we,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ae=>{bt(Array.from(ae.target.files??[])),ae.target.value=""}}),n.jsx("button",{type:"button",disabled:u,onClick:()=>we.current?.click(),"aria-label":k("Attach image"),title:k("Attach image"),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-40 max-md:size-[32px]",children:n.jsx(Wh,{className:"h-3.5 w-3.5"})}),n.jsx(zg,{side:"left",...ee}),c,!T&&n.jsx(OK,{sessionId:ee.sessionId}),n.jsx(zg,{side:"right",...ee}),Ve&&(Ve.blocked.length>0||Ve.masked>0)&&n.jsxs("span",{className:_("flex shrink-0 items-center gap-1 text-[11px]",Ve.blocked.length>0?"text-red-600 dark:text-red-400":"text-sky-600 dark:text-sky-400"),"data-privacy-precheck":!0,children:[Ve.blocked.length>0?n.jsx(ej,{className:"size-3.5"}):n.jsx(Vd,{className:"size-3.5"}),Ve.blocked.length>0?k("Will be blocked: {{kinds}}",{kinds:Ve.blocked.join(", ")}):k("{{count}} will be masked",{count:Ve.masked})]})]}),Y&&!y?n.jsx(fe,{variant:"outline",size:"icon",className:"size-8 shrink-0 rounded-full",onClick:b,"aria-label":k("Stop"),children:n.jsx(w_,{className:"h-4 w-4"})}):n.jsx(fe,{size:"icon",className:"size-8 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-35",onClick:He,disabled:!y||u,"aria-label":k(E?"Send only to the selected Agent":"Send"),title:E?k("Send only to the selected Agent"):l&&M?`${k("Send")} ${qs(M)}`:k("Send"),children:n.jsx(Wd,{className:"h-4 w-4"})})]})]}),n.jsx(cn,{open:xe!==null,onOpenChange:ae=>!ae&&Se(null),children:n.jsxs(dn,{className:"max-w-md",children:[n.jsx(un,{children:n.jsx(rn,{children:xe?.label??k("Selected UI element")})}),n.jsx(In,{className:"space-y-2 text-xs",children:xe&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-muted-foreground break-all",children:xe.path}),xe.text&&n.jsx("p",{children:xe.text}),(()=>{const ae=$.find(Ne=>Ne.id===xe.imageId);return ae?n.jsx("img",{src:`data:${ae.mimeType};base64,${ae.data}`,alt:"",className:"max-h-72 w-full rounded-md border object-contain"}):null})()]})})]})}),n.jsx(cn,{open:W!==null,onOpenChange:ae=>!ae&&H(null),children:n.jsxs(dn,{className:"max-w-3xl",children:[n.jsx(un,{children:n.jsx(rn,{children:k("Preview")})}),n.jsx(In,{children:W&&n.jsx("img",{src:`data:${W.mimeType};base64,${W.data}`,alt:"",className:"max-h-[80vh] w-full rounded-md object-contain"})})]})})]})}function K2({title:e,className:t,onCommit:s,onCancel:r}){const[o,i]=f.useState(e),a=()=>{const l=o.trim();!l||l===e?r():s(l)};return n.jsx("input",{className:_("min-w-0 flex-1 rounded bg-transparent px-0.5 text-inherit outline-none ring-1 ring-ring",t),value:o,autoFocus:!0,onChange:l=>i(l.target.value),onBlur:a,onClick:l=>l.stopPropagation(),onPointerDown:l=>l.stopPropagation(),onKeyDown:l=>{l.stopPropagation(),!l.nativeEvent.isComposing&&(l.key==="Enter"?(l.preventDefault(),a()):l.key==="Escape"&&(l.preventDefault(),r()))}})}function pY({parentId:e,displayedId:t,trailing:s}){const{t:r}=z(),o=J(h=>h.conversations[e]?.title??""),i=J(h=>h.conversations[e]?.started===!0),a=J(h=>h.conversations[e]?.reloading===!0),l=J(h=>!!h.conversations[e]?.spawning),c=J(h=>c8(h.conversations,e)),[u,d]=f.useState(!1),m=h=>_("flex min-w-0 shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs transition-colors",h?"bg-muted font-medium":"text-muted-foreground hover:bg-muted/50");return n.jsxs(t1,{"data-enso":"session-tabs",className:"border-b",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto [scrollbar-width:none]",children:[n.jsx(_y,{id:e,label:o||r("New conversation"),className:m(t===e),leading:n.jsx($m,{className:"h-3 w-3 shrink-0"}),reloadDisabled:a||l,reloading:a,onSelect:()=>J.getState().selectTab(e,void 0)}),c.map(h=>{const p=wR({status:h.status,spawning:h.spawning,pendingApprovalCount:h.pendingApprovalCount,pendingAskCount:h.pendingAskCount});return n.jsxs("div",{className:"group/tab relative shrink-0",children:[n.jsx(_y,{id:h.id,label:h.title||h.child?.agentInstanceName||h.coworkerName||h.id,className:_(m(t===h.id),t!==h.id&&"group-hover/tab:bg-muted/50"),leading:h.mode==="task"?n.jsx(hp,{className:"h-3 w-3 shrink-0"}):n.jsx(ws,{className:"h-3 w-3 shrink-0"}),trailing:n.jsx("span",{className:"inline-flex h-3 w-3 shrink-0 items-center justify-center group-hover/tab:invisible",children:n.jsx(Nl,{tone:p,size:"sm"})}),reloadDisabled:h.reloading||h.spawning,reloading:h.reloading,onSelect:()=>J.getState().selectTab(e,h.id)}),n.jsx("button",{type:"button",title:r("Dismiss coworker"),className:"absolute top-1/2 right-2 hidden h-3 w-3 -translate-y-1/2 items-center justify-center text-muted-foreground hover:text-destructive group-hover/tab:flex",onClick:()=>{window.confirm(r("Dismiss this coworker? Its session will be closed."))&&J.getState().dismissCoworkerFromUI(e,h.id)},children:n.jsx(Jt,{className:"h-3 w-3"})})]},h.id)}),n.jsx("button",{type:"button",title:r("Hire coworker"),disabled:!i,onClick:()=>d(!0),className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40",children:n.jsx(Qn,{className:"h-3.5 w-3.5"})})]}),s,u&&n.jsx(xY,{parentId:e,onClose:()=>d(!1)})]})}function _y({id:e,label:t,className:s,leading:r,trailing:o,reloadDisabled:i,reloading:a,onSelect:l}){const{t:c}=z(),[u,d]=f.useState(!1),m=n.jsxs("button",{type:"button",className:s,onClick:()=>{u||l()},onDoubleClick:h=>{h.preventDefault(),h.stopPropagation(),d(!0)},children:[r,u?n.jsx(K2,{title:t,className:"max-w-48 text-xs",onCommit:h=>{J.getState().renameConversation(e,h),d(!1)},onCancel:()=>d(!1)}):n.jsx("span",{className:"max-w-48 truncate",children:t}),o]});return n.jsxs(Yr,{children:[n.jsx(Xr,{render:m}),n.jsxs(Qr,{className:"min-w-36",children:[n.jsxs(Kt,{onClick:()=>d(!0),children:[n.jsx(bs,{}),c("Rename")]}),n.jsxs(Kt,{disabled:i,onClick:()=>{GS(e,c)},children:[n.jsx(oo,{className:a?"animate-spin":void 0}),c("Reload conversation")]})]})]})}function xY({parentId:e,onClose:t}){const{t:s}=z(),r=pe(x=>x.agentTypes),o=pe(x=>x.disabledBuiltinAgentTypes),[i,a]=f.useState(""),[l,c]=f.useState(""),[u,d]=f.useState(null),m=new Set(r.map(x=>x.name.trim().toLowerCase())),h=[...jR.filter(x=>!o.includes(x.name)&&!m.has(x.name)).map(x=>x.name),...r.map(x=>x.name)],p=[{value:"",label:"general"},...h.map(x=>({value:x,label:x}))],g=async()=>{const x=await J.getState().hireCoworker(e,i.trim(),l||void 0);x?d(x):t()};return n.jsx(cn,{open:!0,onOpenChange:x=>!x&&t(),children:n.jsxs(dn,{className:"max-w-sm",children:[n.jsx(un,{children:n.jsx(rn,{children:s("Hire coworker")})}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs(Cs,{children:[n.jsx(Is,{children:s("Name (slug)")}),n.jsx(Ht,{value:i,onChange:x=>a(x.target.value),placeholder:"reviewer",autoFocus:!0})]}),n.jsxs(Cs,{children:[n.jsx(Is,{children:s("Agent type")}),n.jsxs(Cr,{items:p,value:l,onValueChange:x=>c(x??""),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:p.map(x=>n.jsx(ir,{value:x.value,children:x.label},x.value||"general"))})]})]}),u&&n.jsx("p",{className:"text-destructive text-xs",children:u}),n.jsx("div",{className:"h-1"})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"ghost",onClick:t,children:s("Cancel")}),n.jsx(fe,{onClick:()=>{g()},disabled:!i.trim(),children:s("Hire")})]})]})})}function gY(e,t){return e.recipient?(t.dispatchAgent(e.recipient.typeKey,{text:e.text,images:e.images,fileMentions:e.mentions.filter(s=>s.kind==="file").map(s=>({id:s.id,relativePath:s.relativePath}))}),"agent"):(t.sendCoding(e.text,e.images),"coding")}const vY={active:"bg-green-500 animate-pulse",paused:"bg-amber-500",waiting:"bg-amber-500",blocked:"bg-destructive",completed:"bg-blue-500"};function bY({conversationId:e,goal:t,sessionStatus:s}){const{t:r}=z(),i=Fa(t)?t.retry:void 0,{reminder:a,now:l}=Yd(e,!i&&t.status==="active"&&s!=="running"),c={active:r("working"),paused:r("paused"),waiting:r("waiting"),blocked:r("blocked"),completed:r("completed")},u=i?i.kind==="quota"?r("Quota exhausted · next {{time}}",{time:Ni(i.at)}):r("Waiting for upstream recovery · next {{time}}",{time:Ni(i.at)}):c[t.status],d=a?Xd(a,l,r):void 0;return n.jsxs("div",{className:_("mb-1 flex items-center gap-2",JS),children:[n.jsx(ZS,{}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",title:i?.lastError?`${t.text} — ${i.lastError}`:d?`${t.text} — ${d}`:t.note?`${t.text} — ${t.note}`:t.text,children:[t.text,t.note&&n.jsxs("span",{className:"text-muted-foreground",children:[" — ",t.note]})]}),a?n.jsxs("span",{"data-enso":"goal-reminder-waiting",title:d,className:"inline-flex min-w-0 max-w-[260px] shrink-0 items-center gap-1 rounded bg-sky-500/15 px-1.5 py-0.5 font-mono text-[10px] text-sky-600 tabular-nums dark:text-sky-400",children:[n.jsx(Uo,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),n.jsxs("span",{className:"truncate",children:[r("Waiting for reminder · {{time}}",{time:n1(a.dueAt)}),a.label?` · ${a.label}`:""]})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:_("h-1.5 w-1.5 shrink-0 rounded-full",vY[t.status])}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground tabular-nums",children:[u,t.status==="active"&&t.autoTurns>0?` · ${t.autoTurns}/25`:""]})]}),i?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button","data-enso":"upstream-retry-now",title:r("Retry now"),onClick:()=>{J.getState().retryUpstreamNow(e)},className:"inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-amber-600 transition-colors hover:bg-amber-500/10 dark:text-amber-400",children:[n.jsx(Mr,{className:"h-3 w-3"}),r("Retry now")]}),n.jsx("button",{type:"button","data-enso":"upstream-stop",title:r("Stop auto-retry"),onClick:()=>{J.getState().abort(e)},className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-destructive",children:n.jsx(Uh,{className:"h-3 w-3"})})]}):t.status==="active"?n.jsx("button",{type:"button",title:r("Pause goal"),onClick:()=>J.getState().pauseGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(EN,{className:"h-3.5 w-3.5"})}):t.status!=="completed"?n.jsx("button",{type:"button",title:r("Resume goal"),onClick:()=>J.getState().resumeGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Rj,{className:"h-3.5 w-3.5"})}):null,n.jsx("button",{type:"button",title:r("Clear goal"),onClick:()=>J.getState().clearGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-destructive",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]})}function yY(e,t){return e.trim().length>0||t>0}function By(e,t){return e>0?`${e} ${t}`:null}const wY=zh;function jY(e){return!kR(e)}function kY({conversationId:e,queued:t}){const{t:s}=z(),[r,o]=f.useState(null),[i,a]=f.useState("");if(t.length===0)return null;const l=c=>{yY(i,c.images?.length??0)&&J.getState().updateQueuedMessage(e,c.id,i.trim()),o(null)};return n.jsx("div",{className:"mb-1 flex flex-col gap-0.5",children:t.map(c=>n.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 border-dashed bg-muted/20 px-2.5 py-1.5 text-xs",children:[n.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground uppercase tracking-wide",children:s("Queued")}),r===c.id?n.jsx("input",{value:i,onChange:u=>a(u.target.value),onKeyDown:u=>{u.nativeEvent.isComposing||(u.key==="Enter"&&l(c),u.key==="Escape"&&o(null))},autoFocus:!0,className:"h-6 min-w-0 flex-1 rounded border bg-transparent px-1.5 outline-none focus:ring-1 focus:ring-ring"}):n.jsx("span",{className:"min-w-0 flex-1 truncate",children:wY(c.text)||"[image]"}),By(c.images?.length??0,s("attachments"))&&n.jsxs("span",{title:By(c.images?.length??0,s("attachments"))??void 0,className:"flex shrink-0 items-center gap-0.5 text-muted-foreground",children:[n.jsx(gB,{className:"h-3 w-3"}),c.images?.length]}),r===c.id?n.jsx("button",{type:"button",onClick:()=>l(c),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(On,{className:"h-3.5 w-3.5"})}):n.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[n.jsx("button",{type:"button",title:s("Withdraw message"),"aria-label":s("Withdraw message"),onClick:()=>J.getState().withdrawMessage(e,{kind:"queue",id:c.id}),className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(Ka,{className:"h-3 w-3"})}),jY(c.text)&&n.jsx("button",{type:"button",title:s("Edit"),onClick:()=>{o(c.id),a(c.text)},className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(bs,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",title:s("Send now"),onClick:()=>J.getState().sendQueuedNow(e,c.id),className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(cu,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",title:s("Interrupt and send now"),onClick:()=>{J.getState().interruptAndSendQueued(e,c.id)},className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(XB,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",title:s("Remove"),onClick:()=>J.getState().removeQueuedMessage(e,c.id),className:"rounded p-0.5 text-muted-foreground hover:text-destructive",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]})]},c.id))})}const Y2="mb-1 rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2 text-xs";function X2({doc:e}){return n.jsx("div",{className:"mt-2 max-h-72 overflow-y-auto rounded-md border border-border/60 bg-background/60 px-3 py-2 text-sm",children:n.jsx(Dn,{text:e.text})})}function NY({conversationId:e,planState:t,approvalMode:s}){const r=s1(t);return r==="awaiting_review"&&t?.pending?n.jsx(SY,{conversationId:e,doc:t.pending,approvalMode:s},t.pending.planId):r==="executing"&&t?.executing?n.jsx(CY,{conversationId:e,doc:t.executing},t.executing.planId):null}function SY({conversationId:e,doc:t,approvalMode:s}){const{t:r}=z(),o=NR(),[i,a]=f.useState(!0),[l,c]=f.useState(!1),[u,d]=f.useState(""),[m,h]=f.useState(!1),[p,g]=f.useState(!1),x=async(v,b)=>{g(!0);const w=J.getState();b&&b!==s&&w.setApprovalMode(e,b);const j=await w.respondPlan(e,t.planId,v,v==="revise"?u.trim():void 0);j&&(g(!1),Ie({type:"error",title:r("Plan response failed"),description:j}))};return n.jsxs("div",{className:Y2,children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Ai,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),n.jsx("span",{className:"shrink-0 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:r("Plan awaiting approval")}),n.jsxs("button",{type:"button",onClick:()=>a(v=>!v),className:"flex min-w-0 flex-1 items-center gap-1 text-left font-medium",title:t.title,children:[n.jsx("span",{className:"truncate",children:t.title}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",i&&"rotate-90")})]})]}),i&&n.jsx(X2,{doc:t}),l&&n.jsx("textarea",{autoFocus:!0,value:u,onChange:v=>d(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.metaKey||v.ctrlKey)&&u.trim()&&(v.preventDefault(),x("revise"))},placeholder:r("What should change in this plan?"),className:"mt-2 min-h-16 w-full resize-y rounded-md border border-border/60 bg-background px-2.5 py-1.5 text-sm outline-none focus:border-brand/45"}),n.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[n.jsx("button",{type:"button",disabled:p,onClick:()=>{x("discard")},className:"rounded-md px-2.5 py-1 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50",children:r("Discard and exit plan mode")}),l?n.jsx("button",{type:"button",disabled:p||!u.trim(),onClick:()=>{x("revise")},className:"rounded-md px-2.5 py-1 text-xs text-foreground transition-colors hover:bg-muted disabled:opacity-50",children:r("Send feedback")}):n.jsx("button",{type:"button",disabled:p,onClick:()=>c(!0),className:"rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",children:r("Request changes")}),n.jsxs("div",{className:"flex",children:[n.jsx("button",{type:"button",disabled:p,onClick:()=>{x("approve")},title:r(Ba[s].labelKey),className:"rounded-l-md bg-primary px-2.5 py-1 text-xs text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:r("Approve and execute")}),n.jsxs(Ms,{open:m,onOpenChange:h,children:[n.jsx(Ps,{disabled:p,"aria-label":r("Choose the approval mode for execution"),className:"flex items-center rounded-r-md border-primary-foreground/20 border-l bg-primary px-1 text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:n.jsx(Fn,{className:"h-3.5 w-3.5"})}),n.jsxs(Ds,{side:"top",align:"end",className:"w-80 [&_[data-slot=popover-viewport]]:p-1",children:[n.jsx("p",{className:"px-2 pt-1 pb-1.5 text-muted-foreground text-xs",children:r("Approve and execute with")}),SR.map(v=>{const b=Ba[v],w=b.icon,j=v==="assistant"&&!o;return n.jsxs("button",{type:"button",disabled:j,onClick:()=>{h(!1),x("approve",v)},className:_("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",v===s?"bg-muted":"hover:bg-muted/60",j&&"cursor-not-allowed opacity-50 hover:bg-transparent"),children:[n.jsx(w,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block",children:r(b.labelKey)}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:r(b.descKey)})]})]},v)})]})]})]})]})]})}function CY({conversationId:e,doc:t}){const{t:s}=z(),[r,o]=f.useState(!1);return n.jsxs("div",{className:_(Y2,"py-1.5"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Zp,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 text-muted-foreground",children:s("Executing plan")}),n.jsxs("button",{type:"button",onClick:()=>o(i=>!i),className:"flex min-w-0 flex-1 items-center gap-1 text-left",title:t.title,children:[n.jsx("span",{className:"truncate",children:t.title}),n.jsx(fn,{className:_("h-3 w-3 shrink-0 transition-transform",r&&"rotate-90")})]}),n.jsx("button",{type:"button",title:s("Finish plan"),onClick:()=>{J.getState().respondPlan(e,t.planId,"finish")},className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]}),r&&n.jsx(X2,{doc:t})]})}function IY({active:e,onToggle:t}){const{t:s}=z();return n.jsxs("button",{type:"button","aria-pressed":e,title:s(e?"Plan mode is on: read-only research, then a plan for your approval":"Plan first: research read-only and submit a plan for approval"),onClick:()=>t(!e),className:_("flex h-7 min-w-0 shrink-0 items-center gap-1 rounded-lg px-2 text-xs transition-colors max-md:h-[32px] max-md:min-w-[32px] max-md:justify-center",e?"bg-primary/10 text-primary hover:bg-primary/15":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[n.jsx(Ai,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"hidden @min-[28rem]:inline",children:s("Plan")})]})}function TY({presetId:e,onSelect:t,onModel:s,disabled:r}){const{t:o}=z(),i=pe(m=>m.presets),a=CR(),[l,c]=f.useState(!1),u=[{id:IR,name:o("Global")},...i.map(m=>({id:m.id,name:m.name})),...a.map(m=>({id:m.id,name:m.name}))],d=u.find(m=>m.id===e)??{id:e,name:TR(e)?o("Plugin preset unavailable"):u[0]?.name??""};return r?n.jsxs("span",{className:"flex h-7 min-w-0 max-w-40 shrink items-center gap-1 rounded-lg px-2 text-xs text-muted-foreground max-md:h-[32px] max-md:@max-[28rem]:min-w-[32px] max-md:@max-[28rem]:shrink-0 max-md:@max-[28rem]:justify-center",title:o("Preset is locked after the conversation starts"),children:[n.jsx(Xc,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-md:@max-[28rem]:hidden truncate",children:d.name})]}):n.jsxs(Ms,{open:l,onOpenChange:c,children:[n.jsxs(Ps,{className:"flex h-7 min-w-0 max-w-40 shrink items-center gap-1 rounded-lg px-2 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground max-md:h-[32px] max-md:@max-[28rem]:shrink-0 max-md:@max-[28rem]:gap-0.5 max-md:@max-[28rem]:px-1 max-md:@max-[28rem]:min-w-[32px] max-md:@max-[28rem]:justify-center",title:d.name,children:[n.jsx(Xc,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-md:@max-[28rem]:hidden min-w-0 truncate",children:d.name}),n.jsx(Fn,{className:"h-3 w-3 shrink-0"})]}),n.jsx(Ds,{side:"top",align:"start",className:"w-52 [&_[data-slot=popover-viewport]]:p-1",children:u.map(m=>{const h=m.id===d.id;return n.jsxs("button",{type:"button",onClick:()=>{t(m.id);const p=i.find(x=>x.id===m.id)?.pluginPresetId,g=AR(p??m.id,a);g&&s?.(g),c(!1)},className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",h?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.name}),h&&n.jsx(On,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]},m.id)})})]})}const Fy=[];function AY({projectId:e,conversationId:t}){const{t:s}=z(),r=pe(h=>h.projects.find(p=>p.id===e)?.trustedProjectCode??Fy),o=pe(h=>h.setProjectTrustedCode),[i,a]=f.useState([]),[l,c]=f.useState(!1),[u,d]=f.useState(!1);f.useEffect(()=>{let h=!1;return a(Fy),c(!1),d(!1),window.electronAPI.projects.codeSources({projectId:e,conversationId:t}).then(p=>{h||a(p)}).catch(()=>{h||a([])}),()=>{h=!0}},[e,t]);const m=i.filter(h=>!r.includes(h));return l||m.length===0&&!u?null:m.length===0?n.jsxs("div",{role:"status",className:"mb-1 flex items-center gap-2 rounded-lg border px-2.5 py-1.5 text-muted-foreground text-xs",children:[n.jsx(Do,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1",children:s("Project extensions trusted. They load in new sessions and after this one restarts.")}),n.jsx("button",{type:"button",onClick:()=>c(!0),title:s("Dismiss"),children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]}):n.jsxs("div",{role:"alert",className:"mb-1 flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/5 px-2.5 py-2 text-xs",children:[n.jsx(Do,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-warning"}),n.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[n.jsx("p",{children:s("This project ships pi extension code that runs with your permissions. It was not loaded. Trust it only if you trust this repository.")}),n.jsx("p",{className:"truncate font-mono text-muted-foreground",title:m.join(`
|
|
96
|
-
`),children:m.join(", ")})]}),n.jsx(fe,{size:"xs",variant:"outline",onClick:()=>{o(e,i),d(!0)},children:s("Trust and load")}),n.jsx("button",{type:"button",onClick:()=>c(!0),title:s("Dismiss"),children:n.jsx(Jt,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}const EY=70,Q2=80,J2={system:"bg-brand",memory:"bg-warning",tools:"bg-info",skills:"bg-success",files:"bg-foreground/70",results:"bg-foreground/40",chat:"bg-muted-foreground/70"};function Z2({segments:e,highlight:t,className:s}){return n.jsx("span",{"aria-hidden":!0,className:_("flex h-1 w-16 shrink-0 gap-px overflow-hidden rounded-full bg-muted-foreground/15",s),children:e.map(r=>n.jsx("span",{className:_("block h-full transition-opacity",J2[r.kind],t&&t!==r.kind&&"opacity-25"),style:{width:`${r.width}%`}},r.kind))})}function RY({percent:e,critical:t}){return n.jsx("span",{"aria-hidden":!0,className:"h-1 w-7 shrink-0 overflow-hidden rounded-full bg-muted-foreground/20",children:n.jsx("span",{className:_("block h-full rounded-full",t?"bg-destructive":e>=EY?"bg-warning":"bg-muted-foreground/70"),style:{width:`${e}%`}})})}const MY={system:"System prompt",memory:"Enabled instructions",tools:"Tool definitions",skills:"Enabled skills",files:"Files read",results:"Tool results",chat:"Conversation"};function PY({conversationId:e}){const{t}=z(),s=J(a=>a.conversations[e]?.compaction),r=J(a=>a.conversations[e]?.started),o=J(a=>!!a.conversations[e]?.workspaceMigrating);if(!r)return null;const i=t(s==="running"?"Compacting…":s==="queued"?"Compacts after this turn":o?"Workspace operation in progress":"Compact context");return n.jsx("button",{type:"button",disabled:!!s||o,title:s==="running"?t("Compaction already in progress"):s==="queued"?t("Compaction is queued and runs after this turn"):o?t("Workspace operation in progress — compact again when it finishes"):void 0,className:"w-full rounded-sm border border-border px-2 py-1 text-[11px] text-foreground/90 hover:bg-muted disabled:cursor-default disabled:text-muted-foreground disabled:hover:bg-transparent",onClick:()=>J.getState().compact(e),children:i})}function zy({occupancy:e,conversationId:t,cwd:s,onNavigate:r}){const{t:o}=z(),[i,a]=f.useState(),[l,c]=f.useState(),u=J(x=>!t||uj(x.conversations,t)<ER);if(!e)return n.jsx("p",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:o("Context occupancy unavailable until the session starts")});const d=e.contextWindow,m=QS(e),h=(e.percent??0)>=Q2,p=[...m].filter(x=>Eb(e.parts,x.kind).length>0).sort((x,v)=>v.tokens-x.tokens)[0]?.kind,g=l===void 0?p:l;return n.jsxs("div",{className:"flex flex-col gap-2 px-2 py-1.5",children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-xs",children:[n.jsxs("span",{className:"tabular-nums",children:[Vn(e.used),d?` / ${Vn(d)}`:" · ?",e.percent!==void 0&&n.jsx("span",{className:_(h&&"text-warning"),children:` · ${e.percent}%`})]}),n.jsx("span",{className:"text-muted-foreground",children:o("Estimate")})]}),m.length>0&&n.jsx(Z2,{segments:m,highlight:i,className:"h-1.5 w-full"}),h&&d!==void 0&&n.jsx("p",{className:"text-[11px] text-warning",children:o("About {{tokens}} left",{tokens:Vn(Math.max(0,d-e.used))})}),e.compactionModelMismatch&&n.jsx("p",{className:"text-[11px] text-muted-foreground",children:o("Current summary was produced by another model family")}),e.compactedMessageCount>0&&n.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px] text-muted-foreground",children:[n.jsx("p",{children:o("{{count}} older messages are folded into the summary",{count:e.compactedMessageCount})}),t&&e.compactionEntryId&&u&&n.jsx("button",{type:"button",className:"shrink-0 text-foreground/80 hover:underline",onClick:()=>{J.getState().forkFromEntry(t,e.compactionEntryId)},children:o("Conversation branch")})]}),n.jsx("ul",{className:"flex flex-col gap-1",onMouseLeave:()=>a(void 0),children:m.map(({kind:x,tokens:v})=>{const b=e.used>0?Math.round(v/e.used*100):0,w=Eb(e.parts,x),j=g===x&&w.length>0;return n.jsxs("li",{onMouseEnter:()=>a(x),children:[n.jsxs("button",{type:"button",disabled:w.length===0,"aria-expanded":w.length>0?j:void 0,onClick:()=>c(j?null:x),className:"flex w-full items-center gap-1.5 rounded-sm text-left text-[11px] enabled:hover:bg-muted/60",children:[n.jsx(fn,{className:_("h-3 w-3 shrink-0 text-muted-foreground transition-transform",j&&"rotate-90",w.length===0&&"invisible")}),n.jsx("span",{className:"w-24 shrink-0 truncate text-muted-foreground",children:o(MY[x])}),n.jsx("span",{className:"min-w-0 flex-1",children:n.jsx("span",{className:"block h-1 overflow-hidden rounded-full bg-muted",children:n.jsx("span",{className:_("block h-full",J2[x]),style:{width:`${b}%`}})})}),n.jsx("span",{className:"w-10 shrink-0 text-right tabular-nums",children:Vn(v)}),n.jsxs("span",{className:"w-8 shrink-0 text-right text-muted-foreground tabular-nums",children:[b,"%"]})]}),j&&n.jsx("ul",{className:"mt-0.5 ml-1.5 flex flex-col gap-0.5 border-l border-border pl-2",children:w.map(T=>{const N=zH(T),S=VH(x,T,s),I=k=>{if(k.type==="file"){if(!t)return;RR(t,k.rel)}else window.electronAPI.window.openSettings(k.link);r?.()};return n.jsxs("li",{className:"group/item flex items-center gap-2 rounded-sm text-[11px] text-muted-foreground hover:bg-muted/60 hover:text-foreground",children:["raw"in N?n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:N.raw,children:N.raw}):n.jsx("span",{className:"min-w-0 flex-1 truncate",children:o(N.key,N.vars)}),S&&(S.type==="settings"||t)?n.jsx("button",{type:"button",onClick:()=>I(S),className:"hidden shrink-0 rounded-sm border border-border bg-background px-1.5 text-[10px] leading-4 text-muted-foreground hover:text-foreground group-hover/item:block focus-visible:block",children:o(S.type==="file"?"Open":"Settings")}):null,n.jsx("span",{className:_("shrink-0 tabular-nums",S&&"group-hover/item:hidden"),children:Vn(T.tokens)})]},`${T.tag}-${T.name}`)})})]},x)})}),t&&n.jsx(PY,{conversationId:t})]})}function DY(e){return e?e.used:null}const Xx=90;function eI(e,t){const s=DY(e);if(s===null)return;const r=e?.contextWindow&&e.contextWindow>0?e.contextWindow:t&&t>0?t:0;return r>0?{used:s,window:r}:{used:s}}function OY(e,t){const s={inputTokens:0,outputTokens:0,...e};return t&&(s.contextUsed=t.used,t.window!==void 0&&(s.contextWindow=t.window)),s.inputTokens===0&&s.outputTokens===0&&s.cacheHitPercent===void 0&&s.ttftAvgMs===void 0&&s.tokensPerSecond===void 0&&s.contextUsed===void 0?void 0:s}function LY(e,t){const s={tokens:void 0,cache:void 0,context:void 0,speed:void 0};if(!t)return s;if(t.contextUsed!==void 0){const i=t.contextUsed,a=t.contextWindow??0;if(a>0){const l=Math.min(100,Math.round(i/a*100));s.context={compact:`${l}%`,full:`${Vn(a)} · ${l}%`,percent:l,critical:l>=Xx}}else s.context={compact:`${Vn(i)}·?`,full:`${Vn(i)} · ?`}}const r=[],o=[];return t.ttftAvgMs!==void 0&&(r.push(Wn(t.ttftAvgMs)),o.push(e("First token avg {{duration}}",{duration:Wn(t.ttftAvgMs)}))),t.tokensPerSecond!==void 0&&(r.push(`${t.tokensPerSecond} tok/s`),o.push(e("{{speed}} tok/s",{speed:t.tokensPerSecond}))),r.length>0&&(s.speed={compact:r.join(" · "),full:o.join(" · ")}),(t.inputTokens>0||t.outputTokens>0)&&(s.tokens={compact:`↑${Vn(t.inputTokens)} ↓${Vn(t.outputTokens)}`,full:e("Input {{input}} tok · Output {{output}} tok",{input:Vn(t.inputTokens),output:Vn(t.outputTokens)})}),t.cacheHitPercent!==void 0&&(s.cache={compact:`${t.cacheHitPercent}%`,full:e("Cache hit {{percent}}%",{percent:t.cacheHitPercent})}),s}function _Y(e,t){if(!t)return;const s=Math.round(t.bytes/t.limitBytes*100),r=t.blocked?e("Blocked before send"):t.stage==="wire"?e("Before send"):e("Serialized payload");return{compact:$f(t.bytes),full:`${$f(t.bytes)} / ${$f(t.limitBytes)} · ${s}% · ${r}`,critical:t.blocked||s>=Xx}}function $f(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(2)} KiB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(2)} MiB`:`${(e/(1024*1024*1024)).toFixed(2)} GiB`}function BY({className:e,orientation:t="horizontal",...s}){return n.jsx(MR,{className:_("shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:not-[[class^='h-']]:not-[[class*='_h-']]:self-stretch",e),"data-slot":"separator",orientation:t,...s})}const FY={minimal:"Minimal",default:"Default",full:"Full"};function zY({icons:e,values:t}){const{t:s}=z(),r=pe(x=>x.statusLineSegments),o=f.useMemo(()=>tI(r),[r]),i=pe(x=>x.toggleStatusLineSegment),a=pe(x=>x.setStatusLineSegments),[l,c]=f.useState(null),[u,d]=f.useState(null),m=r1(o),h=o1.filter(x=>!o.includes(x)),p=()=>{c(null),d(null)},g=()=>{if(l!==null&&u!==null){const x=u>l?u-1:u,v=LR(o,l,x);v!==o&&a([...v])}p()};return n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b p-2",children:[n.jsx("div",{className:"flex gap-1",children:PR.map(x=>n.jsx(fe,{variant:m===x?"secondary":"ghost",size:"xs",onClick:()=>a([...DR[x]]),children:s(FY[x])},x))}),m==="custom"&&n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:s("Custom")})]}),n.jsxs("div",{className:"max-h-80 overflow-y-auto p-2",onDragOver:x=>{l!==null&&x.preventDefault()},onDrop:x=>{l!==null&&(x.preventDefault(),g())},children:[o.map((x,v)=>{const b=e[x],w=t[x];return n.jsxs("div",{children:[l!==null&&u===v&&n.jsx("div",{className:"mx-2 my-0.5 h-0.5 rounded-full bg-primary"}),n.jsxs("div",{onDragOver:j=>{if(l===null)return;j.preventDefault();const T=j.currentTarget.getBoundingClientRect(),N=j.clientY<T.top+T.height/2;d(N?v:v+1)},onDrop:j=>{j.preventDefault(),g()},className:_("flex items-center justify-between gap-3 rounded-md px-2 py-1.5",l===v&&"opacity-40"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{role:"button",tabIndex:0,draggable:!0,onDragStart:j=>{j.dataTransfer.effectAllowed="move",j.dataTransfer.setData("text/plain",x),c(v)},onDragEnd:p,"aria-label":s("Drag to reorder"),className:"shrink-0 cursor-grab text-muted-foreground/50 hover:text-foreground active:cursor-grabbing",children:n.jsx(OR,{className:"h-3.5 w-3.5"})}),n.jsx(b,{className:"h-3.5 w-3.5 shrink-0"}),n.jsxs("div",{className:"flex min-w-0 flex-col",children:[n.jsx("span",{className:"text-sm",children:s(Oa[x])}),n.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:w?.full||s("No data yet")})]})]}),n.jsx(rr,{checked:!0,onCheckedChange:j=>i(x,j)})]})]},x)}),l!==null&&u===o.length&&n.jsx("div",{className:"mx-2 my-0.5 h-0.5 rounded-full bg-primary"}),h.length>0&&n.jsxs(n.Fragment,{children:[n.jsx(BY,{className:"my-2"}),h.map(x=>{const v=e[x],b=t[x];return n.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-2 py-1.5",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:"w-3.5 shrink-0"}),n.jsx(v,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/50"}),n.jsxs("div",{className:"flex min-w-0 flex-col",children:[n.jsx("span",{className:"text-sm",children:s(Oa[x])}),n.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?.full||s("No data yet")})]})]}),n.jsx(rr,{checked:!1,onCheckedChange:w=>i(x,w)})]},x)})]})]})]})}const lc=12,$Y=28;function VY(e,t){return t&&r1(e)==="default"?e.filter(s=>s!=="model"):e}function HY({segments:e,widths:t,available:s,triggerWidth:r=0,moreWidth:o=r,mobile:i}){const a=i?[...e]:e.filter((h,p)=>_R(h,p)),l=e.filter(h=>!a.includes(h));if(!(t&&s!==void 0&&e.every(h=>t[h]!=null)))return{inline:a,hoverable:l,collapsed:!1};const u=h=>h.reduce((p,g)=>p+(t[g]??0),0)+Math.max(0,h.length-1)*lc,d=(h,p)=>{const g=[];for(const x of h){if(!p([...g,x]))break;g.push(x)}return g};if(u(a)<=s){const h=d(l,p=>u([...a,...p])<=s);return{inline:a,hoverable:h,collapsed:!1}}if(i){const h=e.filter(b=>b==="context"),p=b=>e.filter(w=>h.includes(w)||b.includes(w)),g=d(e.filter(b=>!h.includes(b)),b=>u(p(b))+lc+o<=s),x=p(g);return{inline:x.length>0&&u(x)+lc+o<=s?x:[],hoverable:[],collapsed:!0}}return{inline:d(a,h=>u(h)+lc+r<=s),hoverable:[],collapsed:!0}}function WY(e,t){if(!e||e.available!==t.available||e.triggerWidth!==t.triggerWidth||e.moreWidth!==t.moreWidth)return!1;const s=Object.keys(t.widths);return s.length===Object.keys(e.widths).length&&s.every(r=>e.widths[r]===t.widths[r])}function $y(e,t){return t.critical?"text-destructive":e==="context"&&t.percent!==void 0&&t.percent>=Q2?"text-warning":"text-subtle-foreground"}function tI(e){const t=Array.isArray(e)?e:FR,s=new Set(o1),r=new Set,o=[];for(const i of t)typeof i=="string"&&s.has(i)&&!r.has(i)&&(r.add(i),o.push(i));return o}const Oa={model:"Model",approval:"Approval mode",cwd:"Working directory",sessionName:"Session name",coworkers:"Coworkers",tokens:"Tokens",cache:"Cache hit rate",context:"Context window",requestBody:"Recent request body",turns:"Turns",speed:"Speed",duration:"Duration",sessionTime:"Session time",usage:"Subscription usage"},UY={minimal:"Min",low:"Low",medium:"Med",high:"High",xhigh:"Extra",max:"Max"},qY={minimal:"Min",low:"Low",medium:"Medium",high:"High",xhigh:"Extra High",max:"Max"},GY={supervised:"Supervised","auto-edits":"Auto-accept edits",full:"Full access",assistant:"Assistant approval"},KY={supervised:HR,"auto-edits":Vd,full:VR,assistant:Bs},YY={model:CN,context:l1,requestBody:WR,turns:zB,duration:Uo,sessionTime:ja,speed:hp,tokens:E_,cache:F_,cwd:Lr,sessionName:JB,coworkers:ki,usage:mF};function XY(e,t,s){if(e.status!=="running")return{llm:0,tool:0};for(let r=t.length-1;r>=0;r--){const o=t[r];if(!(o.role!=="assistant"||!o.timing))return o.timing.completedMs===void 0?{llm:Math.max(0,s-o.timing.stepStartMs),tool:0}:{llm:0,tool:Math.max(0,s-o.timing.completedMs)}}return{llm:0,tool:0}}function QY(e){return e.split(/[\\/]+/).filter(Boolean).at(-1)??e}function cc(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function Vy(e){if(e<=0)return"0m";const t=Math.round(e/6e4),s=Math.floor(t/1440),r=Math.floor(t%1440/60),o=t%60;return s>0?`${s}d${r}h`:r>0?`${r}h${o}m`:`${o}m`}function Hy(e){const t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;const s=Math.floor(t/60);if(s<60)return`${s}m${t%60}s`;const r=Math.floor(s/60);return r<24?`${r}h${s%60}m`:`${Math.floor(r/24)}d${r%24}h`}function JY(e){return{...YY,approval:KY[e.approvalMode??"full"]}}function ZY(e,t){const[s,r]=f.useState(()=>{if(!e)return;const o=$g.get(e);return o?{key:e,data:o.data}:void 0});return f.useEffect(()=>{if(!e)return;let o=!1;const i=$g.get(e);if(i&&Date.now()-i.fetchedAt<zR){r({key:e,data:i.data});return}return $R(e).then(a=>{o||r({key:e,data:a})}).catch(()=>{o||r(a=>a?.key===e?void 0:a)}),()=>{o=!0}},[e,t]),e&&s?.key===e?s.data:void 0}function eX(e,t,s,r,o,i,a){const l=TH(s),c={model:void 0,requestBody:_Y(e,t.requestBody),turns:void 0,duration:void 0,sessionTime:void 0,cwd:void 0,sessionName:void 0,approval:void 0,coworkers:void 0,usage:void 0,...LY(e,OY(AH(l),eI(t.occupancy,t.contextWindow)))};if(t.lastModelId){const j=r.find(N=>N.id===t.lastProviderId)?.models.find(N=>N.id===t.lastModelId)?.label??t.lastModelId,T=t.reasoningEnabled?t.thinkingLevel:void 0;c.model={compact:T?`${j} · ${e(UY[T])}`:j,full:T?`${j} · ${e(qY[T])}`:j}}l.steps>0&&(c.turns={compact:`${l.turns}·${l.steps}`,full:e("{{turns}} turns · {{steps}} steps",{turns:l.turns,steps:l.steps})});const u=XY(t,s,i),d=l.llmMs+u.llm,m=l.toolMs+u.tool,h=[],p=[];d>=1e3&&(h.push(Wn(d)),p.push(e("LLM {{duration}}",{duration:Wn(d)}))),m>=1e3&&(h.push(Wn(m)),p.push(e("Tool calls {{duration}}",{duration:Wn(m)}))),h.length>0&&(c.duration={compact:h.join(" · "),full:p.join(" · ")});const g=Math.max(0,i-t.createdAt);c.sessionTime={compact:Hy(g),full:Hy(g)};const x=o.find(w=>w.id===t.projectId),v=x&&cK(t.parentId??t.id,x);v&&(c.cwd={compact:QY(v),full:v}),t.title.trim().length>0&&(c.sessionName={compact:cc(t.title,16),full:cc(t.title,60)}),c.approval={compact:"",full:e(GY[t.approvalMode??"full"])};const b=t.coworkerIds?.length??0;if(b>0&&(c.coworkers={compact:String(b),full:e("{{count}} coworkers",{count:b})}),a&&!a.error&&a.windows.length>0){const w=a.windows,j=Math.max(...w.map(k=>k.usedPercent)),T=w[0],N=cc(T.label,24),S=T.resetsAt!==void 0?Vy(T.resetsAt-i):void 0,I=w.length>1?` +${w.length-1}`:"";c.usage={compact:`${N} ${Math.round(T.usedPercent)}%${S?`·${S}`:""}${I}`,full:w.map(k=>{const L=k.resetsAt!==void 0?` · ${e("resets in {{remaining}}",{remaining:Vy(k.resetsAt-i)})}`:"";return`${cc(k.label,24)} ${Math.round(k.usedPercent)}%${L}`}).join(" · "),critical:j>=Xx}}return c}function tX({conversationId:e,cwd:t}){const{t:s}=z(),r=J(W=>W.conversations[e]),o=r?.messages??[],i=Kd(),a=pe(W=>W.virtualModels),l=f.useMemo(()=>a.length===0?i:[...i,{id:i1,models:a.map(W=>({id:W.id,label:W.name}))}],[i,a]),c=pe(W=>W.projects),u=pe(W=>W.statusLineSegments),d=f.useMemo(()=>tI(u),[u]),[m,h]=f.useState(null),[p,g]=f.useState(!1),[x,v]=f.useState(!1),b=Ho(),w=f.useRef(null),j=f.useRef(null),[T,N]=f.useState(),S=f.useMemo(()=>{if(d.includes("usage"))return a1(i,r)?.accountKey},[d,i,r]),[I,k]=f.useState(()=>Date.now()),L=r?.status==="running"&&d.includes("duration"),F=d.includes("sessionTime"),A=d.includes("usage")&&S!==void 0;f.useEffect(()=>{if(!L&&!F&&!A)return;const W=setInterval(()=>k(Date.now()),1e3);return()=>clearInterval(W)},[L,F,A]);const M=ZY(S,I),R=f.useMemo(()=>r?JY(r):null,[r]),$=f.useMemo(()=>r?eX(s,r,o,l,c,I,M):null,[s,r,o,l,c,I,M]),U=VY(d,b),q=$?U.filter(W=>$[W]).join(","):"";if(f.useLayoutEffect(()=>{const W=w.current,H=j.current;if(!q||!W||!H)return;const B=()=>{const ve={};let he=0,G=0;for(const ce of Array.from(H.children)){const Re=ce.dataset.measure,ue=Math.ceil(ce.getBoundingClientRect().width);Re==="trigger"?he=ue:Re==="more"?G=ue:Re&&(ve[Re]=ue)}const we={available:W.clientWidth-2*$Y,triggerWidth:he,moreWidth:G,widths:ve};N(ce=>WY(ce,we)?ce:we)};if(B(),typeof ResizeObserver>"u")return;const ne=new ResizeObserver(B);return ne.observe(W),ne.observe(H),()=>ne.disconnect()},[q]),!r||!R||!$)return null;const te=r.occupancy?QS(r.occupancy):[],V=U.filter(W=>$[W]),se=HY({segments:V,widths:T?.widths,available:T?.available,triggerWidth:T?.triggerWidth,moreWidth:T?.moreWidth,mobile:b}),Ce=V.filter(W=>se.inline.includes(W)||se.hoverable.includes(W)),de=se.collapsed&&V.length>0,re=$.context&&!se.inline.includes("context")?$.context:void 0,Z=(W,H)=>{const B=R[W];return n.jsxs(n.Fragment,{children:[W==="context"&&H.percent!==void 0?te.length>0?n.jsx(Z2,{segments:te}):n.jsx(RY,{percent:H.percent,critical:!!H.critical}):n.jsx(B,{className:"h-3 w-3 shrink-0 opacity-75"}),H.compact&&n.jsx("span",{className:"truncate",children:H.compact})]})},me=(W,H)=>_("relative flex items-center gap-1 text-[11px] tabular-nums",$y(W,H)),xe=W=>_("flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-[11px] tabular-nums outline-none hover:bg-muted",W?$y("context",W):"text-subtle-foreground"),Se=W=>W?n.jsxs(n.Fragment,{children:[n.jsx(l1,{className:"h-3 w-3 shrink-0 opacity-75"}),n.jsx("span",{children:W.compact})]}):n.jsx(kl,{className:"h-3.5 w-3.5 shrink-0"});return n.jsxs("div",{ref:w,"data-slot":"stats-line","data-enso":"status-line",className:"group relative flex h-7 items-center justify-center px-1",children:[V.length>0&&n.jsx("div",{"aria-hidden":!0,className:"pointer-events-none invisible absolute inset-0 overflow-hidden",children:n.jsxs("div",{ref:j,className:"absolute top-0 left-0 flex w-max",children:[V.map(W=>{const H=$[W];return H?n.jsx("span",{"data-measure":W,className:me(W,H),children:Z(W,H)},W):null}),n.jsx("span",{"data-measure":"trigger",className:xe($.context),children:Se($.context)}),n.jsx("span",{"data-measure":"more",className:xe(void 0),children:Se(void 0)})]})}),(Ce.length>0||de)&&n.jsxs("div",{className:"flex min-w-0 flex-nowrap items-center gap-3 overflow-hidden",children:[Ce.map(W=>{const H=$[W];if(!H)return null;const B=n.jsxs("span",{title:`${s(Oa[W])} · ${H.full}`,onMouseEnter:()=>h(W),onMouseLeave:()=>h(ne=>ne===W?null:ne),className:me(W,H),children:[Z(W,H),m===W&&W!=="context"&&n.jsxs("div",{style:{zIndex:Pn.TOOLTIP},className:"-translate-x-1/2 pointer-events-none absolute bottom-full left-1/2 mb-1.5 w-max max-w-56 overflow-hidden rounded-md border bg-popover px-2 py-1 text-popover-foreground shadow-md",children:[n.jsx("span",{className:"break-words font-medium",children:s(Oa[W])}),n.jsx("span",{className:"ml-1 break-words text-muted-foreground",children:H.full})]})]});return n.jsx("span",{className:_("shrink-0 items-center",p||se.inline.includes(W)?"flex":"hidden group-focus-within:flex group-hover:flex"),children:W==="context"?n.jsxs(Ms,{open:p,onOpenChange:g,children:[n.jsx(Ps,{className:"rounded-sm outline-none",children:B}),n.jsx(Ds,{side:"top",className:"w-72 [&_[data-slot=popover-viewport]]:p-0",children:n.jsx(zy,{occupancy:r.occupancy,conversationId:r.id,cwd:t,onNavigate:()=>g(!1)})})]}):B},W)}),de&&n.jsxs(Ms,{open:x,onOpenChange:v,children:[n.jsx(Ps,{"data-slot":"status-line-details","aria-label":s("Session stats"),title:s("Session stats"),className:xe(re),children:Se(re)}),n.jsxs(Ds,{side:"top",className:"w-72 [&_[data-slot=popover-viewport]]:p-0",children:[n.jsx("div",{"data-slot":"status-line-details-list",className:"py-1",children:V.filter(W=>W!=="context").map(W=>{const H=$[W];if(!H)return null;const B=R[W];return n.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 text-xs",children:[n.jsx(B,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 text-muted-foreground",children:s(Oa[W])}),n.jsx("span",{className:_("ml-auto min-w-0 break-words text-right tabular-nums",H.critical&&"text-destructive"),children:H.full})]},W)})}),V.includes("context")&&n.jsx("div",{className:"border-t",children:n.jsx(zy,{occupancy:r.occupancy,conversationId:r.id,cwd:t,onNavigate:()=>v(!1)})})]})]})]}),n.jsxs(Ms,{children:[n.jsx(Ps,{"aria-label":s("Status line settings"),className:"-translate-y-1/2 absolute top-1/2 right-1 flex h-5.5 w-5.5 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-muted hover:text-foreground group-hover:opacity-100",children:n.jsx(BR,{className:"h-3.5 w-3.5"})}),n.jsx(Ds,{side:"top",align:"end",className:"w-72 [&_[data-slot=popover-viewport]]:p-0",children:n.jsx(zY,{icons:R,values:$})})]})]})}const nX=["pattern","query","path","file_path"],sX=["path","file_path","query","pattern"],rX=["command","cmd","script"],oX=["path","file_path","pattern","query","command","url","description","summary"],Wy=120;function na(e){const t=e.replace(/\s+/g," ").trim();return t.length>Wy?`${t.slice(0,Wy-1)}…`:t}function iX(e){const t=e.toLowerCase();return t.includes("search")||t.includes("grep")||t==="find"?nX:t==="read"||t.endsWith("_read")?sX:t==="bash"||t.includes("shell")||t.includes("terminal")?rX:oX}function aX(e,t){const s=t.trim();if(!s)return"";let r;try{r=JSON.parse(s)}catch{return na(s)}if(r===null)return"";if(typeof r!="object"||Array.isArray(r))return na(JSON.stringify(r)??String(r));const o=c1(e,r);if(o.summary!==void 0)return na(o.summary);if(!o.args||typeof o.args!="object")return"";const i=o.args;for(const l of iX(o.name)){const c=i[l];if(typeof c=="string"&&c.trim())return na(c)}const a=JSON.stringify(i);return a==="{}"?"":na(a)}function lX(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=24}const nI=new Map,cX=e=>{const t=nI.get(e);return t?new Set(t):new Set},Uy=(e,t)=>(nI.set(e,t),t),jh=new Map,dX=(e,t)=>{const s=jh.get(e)??new Set;jh.set(e,s);for(const r of t)s.add(r);return s},sI="enso:task-bar-expanded",rI=new Map,oI=()=>{try{const e=JSON.parse(window.sessionStorage.getItem(sI)??"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}},uX=e=>rI.get(e)??oI().includes(e),fX=(e,t)=>{rI.set(e,t);try{const s=oI().filter(r=>r!==e);window.sessionStorage.setItem(sI,JSON.stringify(t?[...s,e]:s))}catch{}return t};function mX({sessionId:e,tasks:t,subagents:s,readOnly:r}){const o=pe(N=>N.virtualModels),{t:i}=z(),[a,l]=f.useState(()=>cX(e)),[c,u]=f.useState(null),[d,m]=f.useState(()=>uX(e)),h=J(N=>N.pendingAgentOpen);f.useEffect(()=>{!h||h.sessionId!==e||(u(h.agentId),J.setState({pendingAgentOpen:null}))},[h,e]);const p=dX(e,[...t.filter(N=>N.status==="running").map(N=>N.taskId),...s.filter(N=>N.status==="running").map(N=>N.id)]),g=(N,S)=>!a.has(N)&&(S==="running"||p.has(N)),x=t.filter(N=>g(N.taskId,N.status)),v=s.filter(N=>g(N.id,N.status));if(f.useEffect(()=>{const N=jh.get(e),S=[...t.filter(k=>k.status!=="running").map(k=>k.taskId),...s.filter(k=>k.status!=="running").map(k=>k.id)].filter(k=>N?.has(k)&&!a.has(k)&&k!==c);if(S.length===0)return;const I=setTimeout(()=>{l(k=>{const L=new Set(k);for(const F of S)L.add(F);return Uy(e,L)})},5e3);return()=>clearTimeout(I)},[e,t,s,a,c]),x.length===0&&v.length===0)return null;const b=N=>{l(S=>Uy(e,new Set(S).add(N))),c===N&&u(null)},w=x.find(N=>N.taskId===c)??null,j=v.find(N=>N.id===c)??null,T=x.length>=2;return n.jsxs("div",{className:"relative mb-1.5",children:[(w||j)&&n.jsxs("div",{className:"absolute bottom-full left-0 right-0 z-30 mb-1.5 rounded-xl border bg-card shadow-float",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b px-3 py-1.5 text-xs",children:[n.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:[w?w.command:j?.description,j?.modelId?` · ${qc(o,j.modelId)}`:""]}),w&&n.jsx(gX,{sessionId:e,task:w,readOnly:r}),n.jsx("button",{type:"button",onClick:()=>u(null),className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(Jt,{className:"h-3.5 w-3.5"})})]}),w&&n.jsx(vX,{sessionId:e,task:w,readOnly:r}),j&&n.jsx(bX,{agent:j},j.id)]}),n.jsxs("div",{className:"flex flex-col gap-0.5 rounded-xl border bg-card p-1 shadow-xs",children:[T&&n.jsx(hX,{sessionId:e,tasks:x,expanded:d,readOnly:r,onToggle:()=>m(fX(e,!d))}),(!T||d)&&x.map(N=>n.jsx(xX,{sessionId:e,task:N,readOnly:r,open:c===N.taskId,onToggle:()=>u(c===N.taskId?null:N.taskId),onDismiss:()=>b(N.taskId)},N.taskId)),v.map(N=>n.jsxs(pX,{icon:ws,status:N.status,meta:n.jsx(NX,{agent:N}),open:c===N.id,onToggle:()=>u(c===N.id?null:N.id),stopTitle:i("Stop subagent"),onStop:r?void 0:()=>{window.electronAPI.agent.stopSubagent(e,N.id)},onDismiss:()=>b(N.id),children:[N.agentType&&n.jsx("span",{className:"shrink-0 font-medium",children:N.agentType}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:[N.description,N.modelId&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" ","· ",qc(o,N.modelId)]}),N.status==="running"&&N.currentActivity&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" · ",N.currentActivity]})]})]},N.id))]})]})}function hX({sessionId:e,tasks:t,expanded:s,readOnly:r,onToggle:o}){const{t:i}=z(),a=$i(1e3),[l,c]=f.useState(!1),u=t.filter(p=>p.status==="running"),d=t.filter(p=>ao(p)==="idle").length,m=u.reduce((p,g)=>Math.min(p,g.startedAt),a),h=!r&&u.length>0;return f.useEffect(()=>{h||c(!1)},[h]),n.jsxs("div",{"data-enso":"background-task-summary",className:"flex min-h-[30px] min-w-0 items-center gap-2 rounded-lg px-1 text-[13px]",children:[n.jsx(ox,{icon:$o,state:u.length>0?"running":"ok"}),l?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",children:i("Stop {{count}} background tasks?",{count:u.length})}),n.jsx("button",{type:"button",onClick:()=>c(!1),className:"flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs whitespace-nowrap text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:i("Cancel")}),n.jsx("button",{type:"button","data-enso":"background-task-stop-all-confirm",onClick:()=>{for(const p of u)Vi(e,p.taskId);c(!1)},className:"flex h-6 shrink-0 items-center rounded-md bg-destructive/10 px-1.5 text-xs whitespace-nowrap text-destructive transition-colors hover:bg-destructive/15",children:i("Stop {{count}}",{count:u.length})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button","data-enso":"background-task-summary-toggle",onClick:o,"aria-expanded":s,className:"flex h-6 min-w-0 flex-1 items-center gap-1.5 rounded-md text-left text-xs text-muted-foreground transition-colors hover:text-foreground",children:[n.jsxs("span",{className:"min-w-0 truncate",children:[i("{{count}} background tasks",{count:t.length}),u.length>0&&` · ${i("longest running {{duration}}",{duration:Wn(a-m)})}`]}),d>0&&n.jsx(li,{tone:"pending",className:"whitespace-nowrap",children:i("{{count}} suspected idle",{count:d})}),n.jsx(Fn,{className:_("h-3 w-3 shrink-0 transition-transform",s&&"rotate-180")})]}),h&&n.jsx("button",{type:"button","data-enso":"background-task-stop-all",onClick:()=>c(!0),className:"flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs whitespace-nowrap text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",children:i("Stop all")})]})]})}function pX({icon:e,status:t,meta:s,open:r,onToggle:o,stopTitle:i,onStop:a,onDismiss:l,children:c}){const{t:u}=z();return n.jsxs("div",{className:"flex min-h-[30px] min-w-0 items-center gap-2 px-1 text-[13px]",children:[n.jsx(ox,{icon:e,state:t==="running"?"running":t==="failed"?"error":"ok"}),c,s,n.jsxs("button",{type:"button",onClick:o,"aria-expanded":r,className:"flex h-6 shrink-0 items-center gap-0.5 rounded-md px-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[u("Output"),n.jsx(Fn,{className:_("h-3 w-3 transition-transform",r&&"rotate-180")})]}),t==="running"?a&&n.jsx("button",{type:"button",onClick:a,title:i,className:"flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",children:u("Stop")}):n.jsx("button",{type:"button",onClick:l,className:"flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Jt,{className:"h-3 w-3"})})]})}function xX({sessionId:e,task:t,readOnly:s,open:r,onToggle:o,onDismiss:i}){const{t:a}=z(),l=$i(),c=ao(t);return n.jsxs("div",{"data-enso":"background-task-row","data-view":c,className:_("flex min-h-[30px] min-w-0 items-center gap-2 rounded-lg px-1 text-[13px]",c==="kept"&&"py-1",c==="idle"&&"bg-warning/[0.06]",r&&"bg-muted"),children:[n.jsx(cx,{task:t}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-muted-foreground",title:t.command,children:t.command}),c==="idle"&&n.jsx(li,{tone:"pending",children:lx(t,l,a)})]}),n.jsx(dx,{task:t,className:"mt-0.5"})]}),n.jsx(SX,{task:t}),n.jsxs("button",{type:"button",onClick:o,"aria-expanded":r,className:_("flex h-6 shrink-0 items-center gap-0.5 rounded-md px-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",r&&"bg-foreground/[0.06] text-foreground"),children:[a("Output"),n.jsx(Fn,{className:_("h-3 w-3 transition-transform",r&&"rotate-180")})]}),t.status==="running"?s?null:c==="idle"?n.jsx(mu,{sessionId:e,taskId:t.taskId}):n.jsx(fx,{onStop:()=>Vi(e,t.taskId)}):n.jsx("button",{type:"button",onClick:i,className:"flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:n.jsx(Jt,{className:"h-3 w-3"})})]})}function gX({sessionId:e,task:t,readOnly:s}){const{t:r}=z(),o=$i(),i=ao(t);return n.jsxs(n.Fragment,{children:[n.jsx(XN,{task:t,now:o}),!s&&i==="idle"&&n.jsx(mu,{sessionId:e,taskId:t.taskId}),!s&&i==="kept"&&n.jsx(fe,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:()=>ux(e,t.taskId,null),children:r("Unkeep")})]})}function Vf({icon:e,label:t,value:s}){return n.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md bg-muted px-2 py-1.5",children:[n.jsx(e,{className:"size-3.5 shrink-0 text-warning"}),n.jsx("span",{className:"truncate text-muted-foreground",children:t}),n.jsx("span",{className:"ml-auto shrink-0 font-medium tabular-nums",children:s})]})}function qy({children:e}){return n.jsx("div",{className:"text-[11px] text-subtle-foreground tabular-nums",children:e})}function vX({sessionId:e,task:t,readOnly:s}){const{t:r}=z(),o=$i(),i=ao(t),a=ax(o-t.startedAt),l=t.idle?.ports??[],c=i==="idle"||i==="kept";return n.jsxs(n.Fragment,{children:[i==="idle"&&n.jsxs("div",{className:"space-y-2.5 px-3 py-2.5 text-xs",children:[n.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[n.jsx(Vf,{icon:Uo,label:r("No new output"),value:YN(o-(t.idle?.since??o),r)}),n.jsx(Vf,{icon:oF,label:l.length>0?r("Port {{ports}}",{ports:l.join(", ")}):r("Ports"),value:l.length>0?r("No connections"):r("Not listening")}),n.jsx(Vf,{icon:CN,label:"CPU",value:"0%"})]}),n.jsx(qy,{children:r("Running for {{duration}} · Suspected idle tasks are never stopped automatically",{duration:a})})]}),i==="kept"&&t.keep&&n.jsxs("div",{className:"space-y-2.5 px-3 py-2.5 text-xs",children:[n.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2",children:[n.jsx(Ss,{className:"mt-0.5 size-3.5 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[t.keep.by==="user"&&!s?n.jsx("input",{"data-enso":"background-task-keep-reason",defaultValue:t.keep.reason??"",maxLength:200,placeholder:r("Add a reason (optional)"),className:"w-full bg-transparent text-[13px] outline-none placeholder:text-subtle-foreground",onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur()},onBlur:u=>{const d=u.currentTarget.value.trim();d!==(t.keep?.reason??"")&&ux(e,t.taskId,d)}},t.keep.at):n.jsx("div",{className:"text-[13px]",children:t.keep.reason??"—"}),n.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:t.keep.by==="agent"?r("Kept by the agent at {{time}} when wrapping up",{time:Km(t.keep.at)}):r("Kept by you at {{time}}",{time:Km(t.keep.at)})})]})]}),n.jsx(qy,{children:r("Running for {{duration}}",{duration:a})})]}),c&&n.jsx("div",{className:"flex items-center gap-2 border-t border-border/60 px-3 pt-2 text-[11px] text-subtle-foreground",children:n.jsx("span",{children:r("Recent output")})}),n.jsx(CX,{tail:t.tail,outputBytes:t.outputBytes,running:t.status==="running",framed:!c})]})}function bX({agent:e}){const{t}=z(),s=e.activities??[],r=f.useRef(null),o=f.useRef(!0);return f.useEffect(()=>{const i=r.current;i&&o.current&&(i.scrollTop=i.scrollHeight)},[s,e.resultText]),n.jsxs("div",{ref:r,className:"max-h-96 space-y-2 overflow-auto px-3 py-2 text-sm",onScroll:i=>{o.current=lX(i.currentTarget)},children:[s.map(i=>n.jsx(yX,{activity:i},i.id)),s.length===0&&!e.resultText&&n.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap text-muted-foreground",children:(e.activityLog??[]).join(`
|
|
97
|
-
`)||t("(no output yet)")}),e.detailsPruned&&n.jsx("div",{className:"rounded-md border border-dashed px-2.5 py-2 text-xs text-muted-foreground",children:t("Earlier activity details were cleared; the final report is still available.")}),e.resultText&&e.status!=="running"&&n.jsxs("section",{className:_("rounded-lg border px-3 py-2",e.status==="failed"?"border-destructive/30 bg-destructive/5":"border-blue-500/30 bg-blue-500/5"),children:[n.jsx("div",{className:"mb-1.5 font-medium text-xs text-foreground",children:t("Final report")}),n.jsx(Dn,{text:e.resultText})]})]})}function yX({activity:e}){const{t}=z(),[s,r]=f.useState(!1);if(e.type==="assistant")return n.jsxs("section",{className:"rounded-md bg-muted/30 px-2.5 py-2",children:[n.jsx("div",{className:"mb-1 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:t("Assistant")}),n.jsx(kX,{text:e.text,markdown:!0})]});const o=aX(e.toolName,e.argumentsText),i=c1(e.toolName,e.argumentsText).name,a=lj(i),l=`subagent-tool-${e.id.replace(/[^A-Za-z0-9_-]/g,"-")}`;return n.jsxs("section",{className:"border-b border-border/40 last:border-b-0",children:[n.jsxs("button",{type:"button","aria-controls":l,"aria-expanded":s,onClick:()=>r(c=>!c),className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left text-xs transition-colors hover:bg-muted/50",children:[n.jsx(wX,{toolName:i}),n.jsx("span",{className:"shrink-0 font-medium text-foreground/80",children:a?.tool??i}),o&&n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:o,children:o}),!o&&n.jsx("span",{className:"min-w-0 flex-1"}),n.jsx(jX,{status:e.status,label:t(e.status)}),n.jsx(fn,{"aria-hidden":"true",className:_("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")})]}),s&&n.jsxs("div",{id:l,className:"ml-5 border-border/50 border-l pb-2 pl-2.5",children:[a&&n.jsxs("div",{className:"mb-1 truncate font-mono text-[10px] text-muted-foreground/70",children:[a.server,".",a.tool]}),n.jsx("div",{className:"text-[10px] text-muted-foreground/70",children:t("Arguments")}),n.jsx("pre",{className:"max-h-28 overflow-auto font-mono text-[10px] leading-relaxed whitespace-pre-wrap text-muted-foreground/80",children:_s(e.argumentsText)}),e.outputText&&n.jsxs("div",{className:"mt-1.5 border-border/40 border-t pt-1.5",children:[n.jsx("div",{className:"mb-0.5 text-[10px] text-muted-foreground",children:t("Result")}),n.jsx("pre",{className:"overflow-auto font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-foreground/80",children:_s(e.outputText)})]})]})]})}function wX({toolName:e}){const t=e.toLowerCase(),s="h-3.5 w-3.5 shrink-0 text-muted-foreground";return t.includes("search")||t.includes("grep")||t==="find"?n.jsx(dr,{"aria-hidden":"true",className:s}):t==="read"||t==="write"||t==="edit"||t==="apply_patch"||t.endsWith("_read")?n.jsx(Wo,{"aria-hidden":"true",className:s}):t==="bash"||t==="exec"||t==="codemode"||t.includes("shell")||t.includes("terminal")?n.jsx(im,{"aria-hidden":"true",className:s}):n.jsx(Jh,{"aria-hidden":"true",className:s})}function jX({status:e,label:t}){const s="h-3.5 w-3.5";return n.jsx("span",{role:"status","aria-label":t,title:t,className:_("shrink-0",e==="failed"?"text-destructive":"text-muted-foreground"),children:e==="running"?n.jsx(_t,{"aria-hidden":"true",className:_(s,"animate-spin")}):e==="done"?n.jsx(On,{"aria-hidden":"true",className:s}):e==="failed"?n.jsx(Zr,{"aria-hidden":"true",className:s}):n.jsx(a_,{"aria-hidden":"true",className:s})})}function kX({text:e,label:t,markdown:s=!1}){const{t:r}=z(),o=e.length>800||e.split(`
|
|
98
|
-
`).length>16,i=s?n.jsx(Dn,{text:e}):n.jsx("pre",{className:"overflow-x-auto font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-muted-foreground",children:_s(e)});return o?n.jsxs("details",{className:"group/details",children:[n.jsxs("summary",{className:"cursor-pointer text-[10px] text-muted-foreground hover:text-foreground",children:[t?`${t} · `:"",r("{{count}} chars",{count:e.length})]}),n.jsx("div",{className:"mt-1.5",children:i})]}):n.jsxs("div",{children:[t&&n.jsx("div",{className:"mb-0.5 text-[10px] text-muted-foreground",children:t}),i]})}function NX({agent:e}){const[,t]=f.useState(0);return f.useEffect(()=>{if(e.status!=="running")return;const s=setInterval(()=>t(r=>r+1),1e3);return()=>clearInterval(s)},[e.status]),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:[e.steps>0?`${e.steps} steps · `:"",e.outputTokens?`${e.outputTokens} tok · `:"",e.status==="running"?Wn(Date.now()-e.startedAt):e.status]})}function SX({task:e}){const[,t]=f.useState(0);return f.useEffect(()=>{if(e.status!=="running")return;const s=setInterval(()=>t(r=>r+1),1e3);return()=>clearInterval(s)},[e.status]),n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:e.status==="running"?Wn(Date.now()-e.startedAt):e.exitCode!==void 0?`exit ${e.exitCode}`:e.status})}function CX({tail:e,outputBytes:t,running:s,framed:r=!0}){const{t:o}=z(),i=f.useRef(null);return f.useEffect(()=>{const a=i.current;a&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:i,className:_("max-h-56 overflow-auto font-mono text-xs leading-relaxed whitespace-pre-wrap text-muted-foreground",r?"border-t border-border/60 px-2.5 py-2":"px-3 pt-1 pb-2.5"),children:_s(e)||(t===void 0?o("Loading…"):t>0?o("Output written ({{size}}), not loaded yet",{size:sj(t)}):s?`${o("(no output yet)")}
|
|
99
|
-
${o("The process has not written anything. Without a terminal, some programs buffer output and only write it in blocks or on exit.")}`:o("(no output yet)"))})}function Qx(e){return e==="darwin"?"Open in Finder":e==="win32"?"Open in File Explorer":"Open in File Manager"}async function Jx(e,t){try{const s=await window.electronAPI.projects.reveal(e);s.ok||Ie({type:"error",title:t("Could not complete the file action."),description:s.error})}catch(s){Ie({type:"error",title:t("Could not complete the file action."),description:String(s)})}}const IX="group-hover:grid-cols-[1fr] group-hover:opacity-100 group-focus-visible:grid-cols-[1fr] group-focus-visible:opacity-100 group-data-popup-open:grid-cols-[1fr] group-data-popup-open:opacity-100";function TX({project:e,conversationId:t,path:s,branch:r,openDisabled:o,children:i}){const{t:a}=z(),[l,c]=f.useState([]),u=e.kind==="scratch",d=u||e.kind==="secretary",m=e.kind!=="ssh"&&!d&&!window.electronAPI.remote,h=u?a("Temporary chats"):qn(e),p=f.useCallback(()=>{m&&window.electronAPI.projects.openInApps().then(c).catch(()=>{})},[m]),g=b=>{Jx({projectId:e.id,conversationId:t,...b?{appId:b}:{}},a)},x=l.filter(b=>b.kind==="editor"),v=l.filter(b=>b.kind==="terminal");return n.jsxs(mr,{onOpenChange:b=>b&&p(),children:[n.jsxs(hr,{className:"group ml-1.5 flex h-6 min-w-0 shrink-0 items-center rounded-full border border-border/60 px-2 font-mono text-[11.5px] text-muted-foreground outline-none transition-colors duration-(--duration-quick) hover:border-border focus-visible:border-border data-popup-open:border-border",title:d?h:s,"aria-label":r&&!d?`${h} / ${r}`:h,onPointerEnter:p,children:[n.jsx(lu,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:`grid grid-cols-[0fr] opacity-0 transition-[grid-template-columns,opacity] duration-(--duration-fast) ease-(--ease-smooth-out) ${IX}`,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap pl-1.5",children:[n.jsx("span",{className:"max-w-40 truncate",children:h}),r&&!d&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40",children:"/"}),n.jsx(Hs,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-w-40 truncate",children:r})]})]})}),n.jsx("span",{className:"ml-1.5 flex shrink-0 items-center",children:i})]}),n.jsxs(pr,{align:"end",className:"min-w-48",children:[m&&n.jsxs(n.Fragment,{children:[n.jsxs(Cn,{disabled:o,onClick:()=>g(),children:[n.jsx(Lr,{}),a(Qx(window.electronAPI.env.platform))]}),n.jsx(Gy,{label:a("Editors"),apps:x,fallback:n.jsx(C_,{}),disabled:o,onOpen:g}),n.jsx(Gy,{label:a("Terminals"),apps:v,fallback:n.jsx($o,{}),disabled:o,onOpen:g}),n.jsx(Ri,{})]}),n.jsxs(Cn,{onClick:()=>{navigator.clipboard.writeText(s)},children:[n.jsx(ul,{}),a("Copy Path")]})]})]})}function Gy({label:e,apps:t,fallback:s,disabled:r,onOpen:o}){return t.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(Ri,{}),n.jsxs(tp,{children:[n.jsx(np,{children:e}),t.map(i=>n.jsxs(Cn,{disabled:r,onClick:()=>o(i.id),children:[i.icon?n.jsx("img",{src:i.icon,alt:"",className:"-mx-0.5 size-4 shrink-0"}):s,i.name]},i.id))]})]})}function AX({conversationId:e}){const{t}=z(),s=J(i=>i.conversations[e]),r=J(i=>i.rebuildWorktree),o=J(i=>i.fallbackToMainWorkspace);return!s?.worktreeMissing||!s.worktree?null:n.jsx(Rh,{open:!0,children:n.jsxs(Mh,{className:"sm:max-w-md",children:[n.jsxs(Ph,{children:[n.jsx(Dh,{className:"text-base",children:t("Isolated worktree is missing")}),n.jsx(Oh,{children:t('The worktree of this session was deleted. Rebuild it from branch "{{branch}}" (committed work is preserved), or fall back to the main working tree.',{branch:s.worktree.branch})})]}),n.jsxs(Lh,{variant:"bare",children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:()=>{o(e)},children:t("Fall back to main working tree")}),n.jsx(fe,{size:"sm",onClick:()=>{r(e).then(i=>{i&&Ie({type:"error",title:t("Failed to rebuild worktree"),description:i})})},children:t("Rebuild worktree")})]})]})})}function Pd(e,t){switch(e){case"running":return t("Stop running conversations and coworkers in this workspace before switching branches.");case"dirty":return t("Commit or stash uncommitted changes before switching branches.");case"busy":return t("This workspace is busy. Try again when its conversations are ready.");case"occupied":return t("Branch is checked out in another worktree.");case"invalid-branch":return t("Enter a valid Git branch name.");case"branch-exists":return t("A branch with this name already exists.");case"branch-not-found":return t("This branch no longer exists. Refresh the branch list.");case"same-branch":return t("This workspace is already on that branch.");case"unavailable":return t("Branches are not available for this workspace.");default:return t("Git could not switch branches.")}}function EX({initialName:e,data:t,busy:s,disabled:r,error:o,returnFocus:i,onSubmit:a,onClose:l}){const{t:c}=z(),[u,d]=f.useState(e),m=f.useRef(null),h=f.useId(),p=t?.branches.some(v=>v.name===u.trim()),g=s||r||!t?.headCommit||!!t.blockedReason||!u.trim()||p,x=p?c("A branch with this name already exists."):t?.blockedReason?Pd(t.blockedReason,c):t&&!t.headCommit?c("Create a commit before creating a branch from HEAD."):null;return n.jsx(cn,{open:!0,onOpenChange:v=>{!v&&!s&&l()},children:n.jsxs(dn,{className:"max-w-sm",initialFocus:m,finalFocus:i,showCloseButton:!s,children:[n.jsxs(un,{children:[n.jsx(rn,{children:c("Create branch")}),n.jsx(ys,{children:c("Creates a branch from the current HEAD and switches every conversation in this workspace to it.")})]}),n.jsxs(In,{children:[n.jsx(Ht,{ref:m,"aria-label":c("Branch name"),"aria-invalid":!!x,"aria-describedby":x||o?h:void 0,value:u,disabled:s,onChange:v=>d(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.nativeEvent.isComposing&&(v.preventDefault(),g||a(u.trim()))}}),(x||o)&&n.jsx("p",{id:h,role:"alert",className:"mt-2 break-words text-xs text-destructive",children:x||o})]}),n.jsxs(ts,{children:[n.jsx(fe,{type:"button",variant:"outline",size:"sm",disabled:s,onClick:l,children:c("Cancel")}),n.jsxs(fe,{type:"button",size:"sm",disabled:!!g,onClick:()=>{g||a(u.trim())},children:[s&&n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin"}),c("Create and switch")]})]})]})})}function RX({data:e,loading:t,error:s,disabled:r,query:o,searchRef:i,onQueryChange:a,onSelect:l,onCreate:c,onRetry:u}){const{t:d}=z(),m=r||t||!!s||!e||!!e.blockedReason,h=e?.branches.filter(p=>p.name.toLowerCase().includes(o.trim().toLowerCase()))??[];return n.jsxs("section",{"aria-label":d("Local branches"),className:"pb-1",onKeyDown:p=>{if(p.nativeEvent.isComposing||!["ArrowDown","ArrowUp"].includes(p.key))return;const g=Array.from(p.currentTarget.querySelectorAll("button[data-branch-row]:not(:disabled)"));if(!g.length)return;p.preventDefault();const x=g.indexOf(p.target),v=x<0?p.key==="ArrowDown"?0:g.length-1:(x+(p.key==="ArrowDown"?1:-1)+g.length)%g.length;g[v]?.focus()},children:[n.jsxs("div",{className:"relative m-1",children:[n.jsx(dr,{className:"pointer-events-none absolute left-2 top-1/2 z-10 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx(Ht,{ref:i,value:o,onChange:p=>a(p.target.value),"aria-label":d("Search local branches"),placeholder:d("Search local branches"),className:"h-8 text-xs [&_input]:pl-7"})]}),n.jsx("p",{className:"px-2 py-1 text-[11px] text-muted-foreground",children:d("Switching branches affects all conversations in this workspace.")}),e?.blockedReason&&n.jsx("p",{role:"status",className:"px-2 py-1 text-xs text-warning",children:Pd(e.blockedReason,d)}),t?n.jsxs("div",{role:"status",className:"flex items-center gap-2 px-2 py-3 text-xs text-muted-foreground",children:[n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin"}),d("Loading...")]}):s?n.jsxs("div",{role:"alert",className:"px-2 py-2 text-xs",children:[n.jsx("p",{className:"break-words text-destructive",children:s}),n.jsx("button",{type:"button",disabled:r,onClick:u,className:"mt-1 rounded px-1 py-1 text-foreground hover:bg-muted disabled:opacity-50",children:d("Retry")})]}):n.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[h.map(p=>{const g=p.name===e?.currentBranch,x=p.occupied&&!!p.worktreeConversationId,v=x?d("New conversation in this worktree"):p.occupied?d("Branch is checked out in another worktree."):null;return n.jsxs("button",{type:"button","data-branch-row":"","aria-current":g||void 0,disabled:m||g||p.occupied&&!x,title:v?`${p.name}
|
|
100
|
-
${v}`:p.name,onClick:()=>l(p),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted disabled:opacity-50",g&&"bg-primary/10"),children:[x?n.jsx(no,{className:"h-3.5 w-3.5 shrink-0"}):n.jsx(Hs,{className:"h-3.5 w-3.5 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate",children:p.name}),v&&n.jsx("span",{className:"block text-xs text-muted-foreground",children:v})]}),g&&n.jsx(On,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]},p.name)}),e&&h.length===0&&n.jsx("p",{className:"m-1 rounded-md border border-dashed px-2 py-3 text-center text-xs text-muted-foreground",children:d("No matching local branches.")})]}),n.jsxs("button",{type:"button",disabled:m||!e?.headCommit,onClick:c,title:e&&!e.headCommit?d("Create a commit before creating a branch from HEAD."):void 0,className:"mt-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted disabled:opacity-50",children:[n.jsx(Qn,{className:"h-3.5 w-3.5 shrink-0"}),d("Create branch from HEAD…")]})]})}function Vc(e){return e.name?.trim()||e.branch}function MX(e,t,s){const r=new Set,o=[];for(const[i,a]of Object.entries(e)){const{worktree:l}=a;a.projectId!==t||!l||a.parentId||a.child||a.worktreeMissing||a.ended||a.historyOnly||a.workspaceMigrating||s[i]?.exists===!1||r.has(l.path)||(r.add(l.path),o.push({conversationId:i,worktree:l}))}return o}function PX(e){return!e.worktree&&!e.parentId&&!e.child&&!e.started&&!e.sessionFile&&e.messages.length===0&&!e.spawning&&e.status!=="running"&&!e.workspaceMigrating&&!e.reloading&&!e.ended&&!e.historyOnly&&!e.archived&&!e.forkedFromConversationId}function kh(e,t,s){const r=t?.exists===!1?s("Worktree missing"):t?[t.dirty?s("Uncommitted changes"):s("Working tree clean"),...t.ahead>0?[s("{{n}} unmerged commits",{n:t.ahead})]:[]].join(" · "):s("Worktree status unknown");return[Vc(e),e.branch,e.path,r].join(`
|
|
101
|
-
`)}function DX({worktree:e,status:t}){const{t:s}=z();return n.jsx("span",{"data-slot":"worktree-label",title:kh(e,t,s),className:"flex shrink-0 items-center",children:n.jsx(Hs,{className:_("size-2.75",t?.exists===!1?"text-destructive":t?.dirty?"text-warning":(t?.ahead??0)>0?"text-info":"text-subtle-foreground")})})}function iI({entity:e,onClose:t}){const{t:s}=z(),r=J(u=>u.renameWorktree),[o,i]=f.useState(e?.worktree.name??""),[a,l]=f.useState(!1);f.useEffect(()=>{i(e?.worktree.name??""),l(!1)},[e]);const c=async()=>{if(!(!e||a)){l(!0);try{const u=await r(e.conversationId,o.trim());u?Ie({type:"error",title:s("Failed to rename worktree"),description:u}):t()}catch(u){Ie({type:"error",title:s("Failed to rename worktree"),description:String(u)})}finally{l(!1)}}};return n.jsx(cn,{open:e!==null,onOpenChange:u=>{!u&&!a&&t()},children:n.jsxs(dn,{className:"max-w-sm",children:[n.jsxs(un,{children:[n.jsx(rn,{children:s("Rename worktree")}),n.jsx(ys,{children:s("Only the display name changes, for all sessions in this worktree. Leave empty to use the branch name.")})]}),n.jsx(In,{children:n.jsx(Ht,{"aria-label":s("Worktree name"),maxLength:80,placeholder:e?.worktree.branch,value:o,disabled:a,autoFocus:!0,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.nativeEvent.isComposing&&(u.preventDefault(),c())}})}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",size:"sm",disabled:a,onClick:t,children:s("Cancel")}),n.jsxs(fe,{size:"sm",disabled:a,onClick:()=>{c()},children:[a&&n.jsx(_t,{className:"h-3.5 w-3.5 animate-spin"}),s("Save")]})]})]})})}function OX({conversationId:e,onBranchChange:t}){const{t:s}=z(),r=J(Pe=>Pe.conversations[e]),o=J(Pe=>Pe.moveConversationToWorktree),i=J(Pe=>Pe.cleanupWorktree),a=J(Pe=>Pe.refreshWorktreeStatuses),l=J(Pe=>Pe.conversations),c=J(Pe=>Pe.worktreeStatuses),u=J(Pe=>Pe.attachConversationToWorktree),d=J(Pe=>Pe.newConversation),m=J(Pe=>Pe.switchWorkspaceBranch),h=J(Pe=>Pe.workspaceRevisionByConversation[e]??0),[p,g]=f.useState(null),x=f.useMemo(()=>MX(l,r?.projectId??"",c),[l,r?.projectId,c]),[v,b]=f.useState(!1),[w,j]=f.useState(!1),[T,N]=f.useState(!1),[S,I]=f.useState(null),[k,L]=f.useState(!1),F=pe(Pe=>r?Pe.projects.find(Dt=>Dt.id===r.projectId):void 0),A=!!(r&&!r.parentId&&!r.child&&F?.kind!=="ssh"&&F?.kind!=="scratch"&&F?.kind!=="secretary"),M=`${e}\0${r?.worktree?.path??F?.path??""}`,R=f.useRef(M);R.current=M;const $=f.useRef(0),U=f.useRef(!1),q=f.useRef(null),te=f.useRef(null),V=f.useRef(null);f.useEffect(()=>{v&&(w?te:V).current?.focus()},[v,w]);const[se,Ce]=f.useState(null),de=se?.key===M?se.data:null,re=de?.currentBranch??void 0;f.useEffect(()=>{t?.(re)},[t,re]);const[Z,me]=f.useState(!0),[xe,Se]=f.useState(null),[W,H]=f.useState(""),[B,ne]=f.useState(null),[ve,he]=f.useState(null),G=B===M;f.useEffect(()=>{b(!1),j(!1),H(""),ne(null),he(null)},[M]);const we=f.useCallback(async(Pe=!1)=>{if(!A)return;const Dt=++$.current;me(!0),Se(null);try{const Vt=await window.electronAPI.worktree.branches(e);if(Dt!==$.current||R.current!==M)return;if(Vt.ok)Ce({key:M,data:Vt.value});else{const Et=Pd(Vt.code,s);Se(Et),Pe&&Ie({type:"error",title:s("Failed to load branches"),description:Et})}}catch(Vt){if(Dt!==$.current||R.current!==M)return;Se(s("Failed to load branches")),Pe&&Ie({type:"error",title:s("Failed to load branches"),description:String(Vt)})}finally{Dt===$.current&&R.current===M&&me(!1)}},[e,A,s,M]);if(f.useEffect(()=>{we();const Pe=()=>{U.current||we()};return window.addEventListener("focus",Pe),()=>{$.current+=1,window.removeEventListener("focus",Pe)}},[we,h]),!r||r.parentId||r.child||F?.kind==="ssh")return null;const ce=!!r.worktree,Re=T||r.spawning||r.status==="running"||!!(r.workspaceMigrating||r.reloading),ue=r.worktreeMissing||c[e]?.exists===!1,We=PX(r),it=de?de.currentBranch:r.worktree?.branch,Fe=it??(de?.headCommit?s("Detached HEAD"):""),tt=r.worktree?Vc(r.worktree):s("Local"),ke=Fe&&Fe!==tt&&(!de?.defaultBranch||it!==de.defaultBranch)?`${tt} · ${Fe}`:tt,nt=Re||ue||Z||!!xe||!de||!!de.blockedReason,mt=async(Pe,Dt=!1,Vt)=>{if(nt||U.current)return;U.current=!0,$.current+=1,N(!0),he(null);const Et=s(Vt?"Failed to create conversation":"Failed to switch branch");try{if(Vt){await d(r.projectId,{worktreeFromConversationId:Vt})?R.current===M&&b(!1):Ie({type:"error",title:Et});return}const oe=await m(e,Pe,Dt);if(R.current!==M)return;if(oe.ok)Ce({key:M,data:oe.value}),Se(null),ne(null),b(!1);else{const Le=Pd(oe.code,s);he(Le),Ie({type:"error",title:Et,description:oe.code==="git-error"?`${Le}
|
|
102
|
-
${oe.error}`:Le}),we()}}catch(oe){if(R.current!==M)return;he(String(oe)),Ie({type:"error",title:Et,description:String(oe)})}finally{U.current=!1,N(!1)}},X=Pe=>{Pe.name===de?.currentBranch||Pe.occupied&&!Pe.worktreeConversationId||mt(Pe.name,!1,Pe.occupied?Pe.worktreeConversationId:void 0)},K=async Pe=>{if(Re)return;N(!0);const Dt=s(Pe?"Failed to use worktree":"Failed to create conversation");try{if(Pe){const Vt=await u(e,Pe);Vt&&Ie({type:"error",title:Dt,description:Vt})}else await d(r.projectId,{worktreeFromConversationId:e})||Ie({type:"error",title:Dt})}catch(Vt){Ie({type:"error",title:Dt,description:String(Vt)})}finally{N(!1)}},Ee=async()=>{N(!0);try{const Pe=await i(e);Pe?Ie({type:"error",title:s("Failed to clean up worktree"),description:Pe}):a()}catch(Pe){Ie({type:"error",title:s("Failed to clean up worktree"),description:String(Pe)})}finally{N(!1)}},pt=async(Pe=!1)=>{N(!0);try{const Dt=await o(e,{allowDirtyMainTree:Pe});Dt===d1?L(!0):Dt?Ie({type:"error",title:s("Failed to move to worktree"),description:Dt}):a()}catch(Dt){Ie({type:"error",title:s("Failed to move to worktree"),description:String(Dt)})}finally{N(!1)}},Pt=async()=>{N(!0);try{const Pe=await window.electronAPI.worktree.status(e);if(Pe.ok&&wc(Pe.value)){I(Pe.value);return}await Ee()}catch(Pe){Ie({type:"error",title:s("Failed to clean up worktree"),description:String(Pe)})}finally{N(!1)}},Je=[{id:"local",selected:!ce,icon:n.jsx(Cv,{className:"h-3.5 w-3.5 shrink-0"}),name:s("Local workspace"),hint:s("Work directly in the main working tree"),onSelect:()=>{ce&&Pt()}},{id:"worktree",selected:ce,icon:n.jsx(Hs,{className:"h-3.5 w-3.5 shrink-0"}),name:r.worktree?Vc(r.worktree):s("New isolated worktree"),hint:ce?r.worktree?.branch:s("Run this session on its own git worktree"),onSelect:()=>{ce||pt()}}],Lt=n.jsx(cs,{open:k,onOpenChange:L,title:s("Main working tree has uncommitted changes"),description:s("The new worktree branches off HEAD, so those changes stay in the main working tree and will not follow this session."),confirmLabel:s("Move anyway"),onConfirm:()=>{L(!1),pt(!0)}}),on=()=>{const Pe=[];return S?.dirty&&Pe.push(s("Uncommitted changes")),S&&S.ahead>0&&Pe.push(s("{{n}} unmerged commits (branch is kept)",{n:S.ahead})),Pe.join("; ")};return n.jsxs(n.Fragment,{children:[n.jsxs(Ms,{open:v,onOpenChange:Pe=>{T||(b(Pe),Pe&&(j(!1),H(""),we()))},children:[n.jsxs(Ps,{ref:q,disabled:Re,className:"flex h-7 min-w-0 max-w-52 shrink items-center gap-1 rounded-lg px-2 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50 max-md:h-[32px] max-md:@max-[28rem]:shrink-0 max-md:@max-[28rem]:gap-0.5 max-md:@max-[28rem]:px-1 max-md:@max-[28rem]:min-w-[32px] max-md:@max-[28rem]:justify-center",title:r.worktree?`${ke}
|
|
103
|
-
${kh(r.worktree,c[e],s)}`:ke,children:[T?n.jsx(_t,{className:"h-3 w-3 shrink-0 animate-spin"}):ce?n.jsx(Hs,{className:"h-3 w-3 shrink-0"}):n.jsx(Cv,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-md:@max-[28rem]:hidden min-w-0 truncate",children:ke}),n.jsx(Fn,{className:"h-3 w-3 shrink-0"})]}),n.jsx(Ds,{side:"top",align:"start",className:"w-72 [&_[data-slot=popover-viewport]]:p-1",initialFocus:V,finalFocus:G||p!==null?!1:q,children:w?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:()=>j(!1),"aria-label":s("Back to workspaces"),className:"mb-1 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground",children:[n.jsx(Ei,{className:"h-3.5 w-3.5 shrink-0"}),s("Local branches")]}),n.jsx(RX,{data:de,loading:Z,error:xe,disabled:Re||ue,query:W,searchRef:te,onQueryChange:H,onSelect:X,onRetry:()=>{we(!0)},onCreate:()=>{nt||!de?.headCommit||(he(null),ne(M),b(!1))}})]}):n.jsxs(n.Fragment,{children:[Je.map(Pe=>n.jsxs("button",{ref:Pe.id==="local"?V:void 0,type:"button",disabled:Re,onClick:()=>{Pe.onSelect(),b(!1)},className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",Pe.selected?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[Pe.icon,n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate",children:Pe.name}),Pe.hint&&n.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:Pe.hint})]}),Pe.selected&&n.jsx(On,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]},Pe.id)),We&&x.length>0&&n.jsxs("div",{className:"mt-1 border-t pt-1",children:[n.jsx("p",{className:"px-2 py-1 text-[11px] text-muted-foreground",children:s("Existing worktrees")}),n.jsx("div",{className:"max-h-56 overflow-y-auto",children:x.map(({conversationId:Pe,worktree:Dt})=>n.jsxs("button",{type:"button",disabled:Re,title:kh(Dt,c[Pe],s),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",onClick:()=>{b(!1),K(Pe)},children:[n.jsx(Hs,{className:"h-3.5 w-3.5 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate",children:Vc(Dt)}),n.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:Dt.path})]})]},Dt.path))})]}),r.worktree&&n.jsxs("div",{className:"mt-1 border-t pt-1",children:[n.jsxs("button",{type:"button",disabled:Re||ue,className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted disabled:opacity-50",onClick:()=>{b(!1),K()},children:[n.jsx(no,{className:"h-3.5 w-3.5"}),s("New conversation in this worktree")]}),n.jsxs("button",{type:"button",disabled:Re||ue,className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-muted disabled:opacity-50",onClick:()=>{b(!1),r.worktree&&g({conversationId:e,worktree:r.worktree})},children:[n.jsx(bs,{className:"h-3.5 w-3.5"}),s("Rename worktree")]})]}),n.jsx("div",{className:"mt-1 border-t pt-1",children:n.jsxs("button",{type:"button",disabled:Re,onClick:()=>j(!0),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",children:[n.jsx(Hs,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"flex-1",children:s("Switch branch")}),n.jsx(fn,{className:"h-3.5 w-3.5 shrink-0"})]})})]})})]}),n.jsx(cs,{open:S!==null,onOpenChange:Pe=>{Pe||I(null)},title:s("Clean up worktree?"),description:s("Pending work: {{warning}}. This session returns to the main working tree. The worktree directory and uncommitted changes are removed only when no other sessions use it. The branch is kept.",{warning:on()}),confirmLabel:s("Clean up"),onConfirm:()=>{I(null),Ee()}}),G&&n.jsx(EX,{initialName:W.trim(),data:de,busy:T,disabled:nt,error:ve,returnFocus:q,onSubmit:Pe=>{mt(Pe,!0)},onClose:()=>ne(null)},M),Lt,n.jsx(iI,{entity:p,onClose:()=>g(null)})]})}function LX(e){if(e)for(let t=e.length-1;t>=0;t--){const s=e[t];if(!(s.role!=="assistant"||!s.model)&&!(s.stopReason==="error"||s.stopReason==="aborted"))return s.model}}const _X=e=>{$N(e)&&zi()};function BX(){const{t:e}=z(),t=Ho(),s=UR(),r=Kd(),o=pe(ke=>ke.virtualModels),i=pe(ke=>ke.agentTypes),a=pe(ke=>ke.defaultModel),l=pe(ke=>ke.projects),c=pe(ke=>ke.projectGroups),u=pe(ke=>ke.presets),d=f.useSyncExternalStore(ke=>J.persist?.onFinishHydration?.(ke)??(()=>{}),()=>J.persist?.hasHydrated?.()??!0),m=J(Vg(uK)),h=J(ke=>ke.conversations[m?.parentId??""]?.coworkerIds),p=qR(m?.presetId,ke=>u.find(nt=>nt.id===ke)).pluginPresetId??null,g=iK(m?.displayedParentId?m.agentType:void 0),x=zo(ke=>ke.snapshot),v=u1(),b=J(ke=>a8(ke.conversations)),w=m?.parentId,j=m?.parentProjectId,T=f.useMemo(()=>w!==void 0&&j!==void 0?wU(b,j,w):[],[b,w,j]),N=f.useMemo(()=>l.find(ke=>ke.id===m?.projectId),[m?.projectId,l]),S=f.useMemo(()=>l.find(ke=>ke.id===m?.parentProjectId),[m?.parentProjectId,l]),I=f.useMemo(()=>sm(N,c),[N,c]),k=f.useMemo(()=>sm(S,c),[S,c]),L=f.useMemo(()=>tm({defaultModel:a,...I,lastProviderId:m?.lastProviderId,lastModelId:m?.lastModelId,providers:r,credentials:nm(x),virtualModels:o}),[m?.lastModelId,m?.lastProviderId,I,a,x,r,o]),F=f.useMemo(()=>tm({defaultModel:a,...k,lastProviderId:m?.parentLastProviderId,lastModelId:m?.parentLastModelId,providers:r,credentials:nm(x),virtualModels:o}),[a,x,m?.parentLastModelId,m?.parentLastProviderId,k,r,o]),A=F.source==="none"?null:{providerId:F.providerId,modelId:F.modelId},M=L.source==="none"?void 0:v.find(ke=>ke.id===L.providerId),R=L.source==="none"?"":L.modelId,$=L.source==="none"?"":rm(L)?L.providerId:M?.id??"",U=J(ke=>rm(L)&&m?.id?LX(ke.conversations[m.id]?.messages):void 0),q=J(Vg(ke=>a1(r,m?.id?ke.conversations[m.id]:void 0))),te=L.source!=="none"?null:L.reason==="oauth-credentials-error"?e("Subscription credentials could not be loaded. Choose an API-key model or retry the credential refresh."):L.reason==="oauth-credentials-loading"||L.reason==="oauth-credentials-unloaded"?e("Subscription credentials are loading. Choose an API-key model or wait, then retry."):v.length>0?e("Choose a model for this conversation or set a project, group, or global default before sending."):e("No usable model is available. Configure provider credentials and enable a model first."),V=l.find(ke=>ke.id===m?.projectId),se=m?.id,[Ce,de]=f.useState(),re=f.useCallback(ke=>de(se&&ke?{id:se,branch:ke}:void 0),[se]),Z=m?.parentWorktreeBranch??(Ce?.id===m?.parentId?Ce?.branch:void 0),me=pe(ke=>ke.skills),xe=pe(ke=>ke.loadLocalSkills),Se=pe(ke=>GR(ke.disabledBuiltinTools,ke.projects,m?.projectId,"plan")),[W,H]=f.useState([]),B=xe?V?.path??"":"",ne=m?.presetId;f.useEffect(()=>{let ke=!1;return window.electronAPI.assets.listProjectSkills(B,ne).then(nt=>{ke||H(nt)}).catch(()=>{ke||H([])}),()=>{ke=!0}},[B,ne]);const ve=m?.commands,he=KR(),G=f.useMemo(()=>{if(!ve)return[];const ke={name:"/goal",description:e("Set a session goal (/goal <objective> · pause · resume · clear)")},nt={name:"/compact",description:e("Compact the context now (/compact [summary focus])")},mt={name:"/plan",description:e("Plan mode: research read-only, then approve a plan (/plan [task] · off)")},X=me.filter(Ee=>Ee.enabled!==!1).map(Ee=>({name:`/skill:${Ee.name}`,description:Ee.description})),K=W.map(Ee=>({name:`/skill:${Ee.name}`,description:Ee.description}));return _C([ke,nt,...Se?[mt]:[],...X,...K,...ve,...he])},[e,me,W,ve,he,Se]),we=f.useRef(null),ce=!m?.displayedParentId&&["planning","awaiting_review"].includes(s1(m?.planState)),Re=m?.status==="running",ue=m?.busy===!0,We=lK(m,V),it=f.useCallback(()=>{m&&!m.parentStarted&&m.parentSessionFile&&!m.parentWorktreeMissing&&m.parentStatus!=="failed"&&J.getState().resumeConversation(m.parentId)},[m]);f.useEffect(()=>{const ke=m?.compactionError;!ke||!m||(Ie({type:"error",title:e("Compaction failed"),description:ke}),J.getState().clearCompactionError(m.id))},[m,e]);const Fe=aK(m,d);if(!m)return n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",...Fe==="hydrating"?{"data-timeline-loading":""}:{},children:[s&&n.jsx(t1,{"data-enso":"title-bar"}),Fe==="empty"&&n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-1 text-center",children:[n.jsx("p",{className:"text-lg font-medium",children:"EnsoCode"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:e("Create or select a project to start a conversation")})]})]});const tt=n.jsx(FX,{status:m.spawning?"running":m.status,pendingAskCount:Po(m.pendingAsks),hasRunningChild:m.id===m.parentId&&m.parentHasRunningChild,queued:m.queued,queuePosition:m.queuePosition,queueFailed:m.queueFailed,conversationId:m.id});return n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[n.jsx(AX,{conversationId:m.parentId}),n.jsx(pY,{parentId:m.parentId,displayedId:m.id,trailing:n.jsxs("div",{className:"flex min-w-0 shrink-0 items-center gap-1",children:[n.jsx(QG,{conversationId:m.parentId}),n.jsx(tK,{conversationId:m.parentId}),n.jsx(oK,{conversationId:m.parentId}),n.jsx(IK,{parentId:m.parentId,coworkerIds:h??[]}),V?n.jsx(TX,{project:V,conversationId:m.parentId,path:We??V.path,branch:Z,openDisabled:m.parentWorktreeMissing,children:tt}):n.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:tt})]})}),n.jsx(B2,{conversationId:m.id,cwd:We,emptyTitle:V?qn(V):"EnsoCode",onSuggestion:V?_X:void 0,timelineRef:we,quotable:!0}),n.jsx("div",{className:"@container flex min-h-0 flex-col pt-1",children:n.jsxs("div",{className:`${_r} flex min-h-0 flex-col`,children:[V&&V.kind!=="ssh"&&V.kind!=="scratch"&&V.kind!=="secretary"&&!m.displayedParentId&&n.jsx(AY,{projectId:V.id,conversationId:m.id},`${V.id}:${m.id}`),m.retry&&n.jsx(m2,{retry:m.retry,onCancel:()=>{window.electronAPI.agent.abortRetry(m.id)}}),(m.rewinding||m.restoringFiles)&&n.jsxs("div",{role:"status",className:"mb-1 flex items-center gap-2 rounded-lg border px-2.5 py-1.5 text-muted-foreground text-xs",children:[n.jsx(_t,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}),n.jsx("span",{children:m.restoringFiles&&!m.rewinding?e("Restoring files…"):m.restoringFiles?e("Rewinding conversation and files…"):e("Rewinding…")})]}),n.jsx(Jj.Provider,{value:{conversationId:m.id,projectId:m.projectId,...We?{cwd:We}:{}},children:n.jsx(mX,{sessionId:m.id,tasks:m.backgroundTasks??[],subagents:m.subagents??[]},m.id)}),n.jsxs("div",{"data-enso":"composer-stack",className:"flex min-h-0 flex-col overflow-y-auto overscroll-contain",children:[n.jsx(px,{approvals:m.pendingApprovals??[],allowSession:m.childLockedProfileId===void 0,onRespond:(ke,nt)=>{window.electronAPI.agent.respondApproval(m.id,ke,nt)}}),n.jsx(mK,{}),n.jsx(xx,{asks:m.pendingAsks??[],onAnswer:(ke,nt)=>{window.electronAPI.agent.respondAsk(m.id,ke,nt)}}),!m.displayedParentId&&n.jsx(NY,{conversationId:m.id,planState:m.planState,approvalMode:m.approvalMode??"full"}),n.jsx(kY,{conversationId:m.id,queued:m.queuedMessages??[]}),m.goal&&n.jsx(bY,{conversationId:m.id,goal:m.goal,sessionStatus:m.spawning?"running":m.status}),n.jsx(V9,{conversationId:m.id},m.id),!m.displayedParentId&&te&&n.jsx("div",{role:"status",className:"rounded-md border border-dashed px-3 py-2 text-muted-foreground text-xs",children:te})]}),n.jsx(hY,{mentionConversationId:V?m.parentId:void 0,chatCandidates:T,commands:G,running:Re,busy:ue,locked:(m.pendingApprovals??[]).length>0||!!(m.rewinding||m.restoringFiles),focusKey:m.id,pluginPresetId:p,planMode:ce,savePastedText:V?.kind==="ssh"?void 0:ke=>window.electronAPI.files.savePastedText({conversationId:m.id,text:ke}),placeholder:ce?e("Describe the task — a plan comes first"):void 0,injectedDraft:m.draftText,injectedImages:m.draftImages,injectedDraftAppend:m.draftAppend,onDraftConsumed:()=>J.getState().clearDraft(m.id),queuedCount:m.queuedMessages?.length??0,onSteerQueued:()=>J.getState().steerQueued(m.id),toolbar:n.jsxs(n.Fragment,{children:[!m.displayedParentId&&n.jsxs(n.Fragment,{children:[n.jsx(TY,{presetId:m.presetId??"default",disabled:m.started,onSelect:ke=>J.getState().setPreset(m.id,ke),onModel:ke=>J.getState().setModel(m.id,ke.providerId,ke.modelId)}),n.jsx(OX,{conversationId:m.id,onBranchChange:re}),(Se||m.planState?.active)&&n.jsx(IY,{active:m.planState?.active??!1,onToggle:ke=>J.getState().setPlanMode(m.id,ke)}),n.jsx(YR,{mode:m.approvalMode??"full",autoReject:m.autoRejectApprovals===!0,onSelect:ke=>J.getState().setApprovalMode(m.id,ke),onToggleAutoReject:ke=>J.getState().setAutoRejectApprovals(m.id,ke)}),n.jsx(f1,{listenHotkey:!0,refreshAllModels:!0,recordRecent:!0,compact:t,providers:v,virtualModels:o,routedModelLabel:U,activeAccount:q,providerId:$,modelId:R,reasoningEnabled:m.reasoningEnabled??!1,thinkingLevel:m.thinkingLevel??"medium",onSelect:(ke,nt)=>J.getState().setModel(m.id,ke,nt),onReasoningChange:ke=>J.getState().setReasoning(m.id,ke),onThinkingChange:ke=>J.getState().setThinking(m.id,ke)})]}),m.displayedParentId&&n.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[g??(m.agentType?Zj(m.agentType,i):"coworker"),m.lastModelId?` · ${qc(o,m.lastModelId)}`:""]})]}),onActivate:it,onSend:ke=>{if(!ke.recipient&&!V||!ke.recipient&&!m.displayedParentId&&(!$||!R))return!1;if(V?.kind==="secretary"&&!ke.recipient){const nt=ke.mentions.filter(mt=>mt.kind==="chat").map(mt=>mt.id);nt.length>0&&window.electronAPI.secretary.referenceConversations(m.id,nt).catch(()=>{})}return gY(ke,{dispatchAgent:(nt,mt)=>{J.getState().dispatchAgent(nt,mt,A)},sendCoding:(nt,mt)=>{V&&(we.current?.scrollToBottom(),J.getState().send(nt,{providerId:$,modelId:R,cwd:V.path},mt))}}),!0},onAbort:()=>{J.getState().abort()}}),n.jsx(tX,{conversationId:m.id,cwd:We})]})})]})}function FX({status:e,pendingAskCount:t=0,hasRunningChild:s=!1,queued:r=!1,queuePosition:o,queueFailed:i,conversationId:a}){const{t:l}=z(),{reminder:c,now:u}=Yd(a,e!=="running"&&!s&&!r),d=i?"failed":Bd({status:e,pendingAskCount:t,hasRunningChild:s,queued:r,hasPendingReminder:c!==void 0}),m=i||(r?l("Queued · #{{n}}, starts automatically when a slot opens",{n:o??1}):c?Xd(c,u,l):e);return n.jsx(Nl,{tone:d,title:m,conversationId:a})}function aI(e,t,s){const r=e.slice();return r.splice(s<0?r.length+s:s,0,r.splice(t,1)[0]),r}function zX(e,t){return e.reduce((s,r,o)=>{const i=t.get(r);return i&&(s[o]=i),s},Array(e.length))}function dc(e){return e!==null&&e>=0}function $X(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}function VX(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const uc={scaleX:1,scaleY:1},HX=e=>{var t;let{rects:s,activeNodeRect:r,activeIndex:o,overIndex:i,index:a}=e;const l=(t=s[o])!=null?t:r;if(!l)return null;const c=WX(s,a,o);if(a===o){const u=s[i];return u?{x:o<i?u.left+u.width-(l.left+l.width):u.left-l.left,y:0,...uc}:null}return a>o&&a<=i?{x:-l.width-c,y:0,...uc}:a<o&&a>=i?{x:l.width+c,y:0,...uc}:{x:0,y:0,...uc}};function WX(e,t,s){const r=e[t],o=e[t-1],i=e[t+1];return!r||!o&&!i?0:s<t?o?r.left-(o.left+o.width):i.left-(r.left+r.width):i?i.left-(r.left+r.width):r.left-(o.left+o.width)}const lI=e=>{let{rects:t,activeIndex:s,overIndex:r,index:o}=e;const i=aI(t,r,s),a=t[o],l=i[o];return!l||!a?null:{x:l.left-a.left,y:l.top-a.top,scaleX:l.width/a.width,scaleY:l.height/a.height}},fc={scaleX:1,scaleY:1},Ky=e=>{var t;let{activeIndex:s,activeNodeRect:r,index:o,rects:i,overIndex:a}=e;const l=(t=i[s])!=null?t:r;if(!l)return null;if(o===s){const u=i[a];return u?{x:0,y:s<a?u.top+u.height-(l.top+l.height):u.top-l.top,...fc}:null}const c=UX(i,o,s);return o>s&&o<=a?{x:0,y:-l.height-c,...fc}:o<s&&o>=a?{x:0,y:l.height+c,...fc}:{x:0,y:0,...fc}};function UX(e,t,s){const r=e[t],o=e[t-1],i=e[t+1];return r?s<t?o?r.top-(o.top+o.height):i?i.top-(r.top+r.height):0:i?i.top-(r.top+r.height):o?r.top-(o.top+o.height):0:0}const cI="Sortable",dI=qe.createContext({activeIndex:-1,containerId:cI,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:lI,disabled:{draggable:!1,droppable:!1}});function Nh(e){let{children:t,id:s,items:r,strategy:o=lI,disabled:i=!1}=e;const{active:a,dragOverlay:l,droppableRects:c,over:u,measureDroppableContainers:d}=gl(),m=pl(cI,s),h=l.rect!==null,p=f.useMemo(()=>r.map(S=>typeof S=="object"&&"id"in S?S.id:S),[r]),g=a!=null,x=a?p.indexOf(a.id):-1,v=u?p.indexOf(u.id):-1,b=f.useRef(p),w=!$X(p,b.current),j=v!==-1&&x===-1||w,T=VX(i);Ks(()=>{w&&g&&d(p)},[w,p,g,d]),f.useEffect(()=>{b.current=p},[p]);const N=f.useMemo(()=>({activeIndex:x,containerId:m,disabled:T,disableTransforms:j,items:p,overIndex:v,useDragOverlay:h,sortedRects:zX(p,c),strategy:o}),[x,m,T.draggable,T.droppable,j,p,v,c,h,o]);return qe.createElement(dI.Provider,{value:N},t)}const qX=e=>{let{id:t,items:s,activeIndex:r,overIndex:o}=e;return aI(s,r,o).indexOf(t)},GX=e=>{let{containerId:t,isSorting:s,wasDragging:r,index:o,items:i,newIndex:a,previousItems:l,previousContainerId:c,transition:u}=e;return!u||!r||l!==i&&o===a?!1:s?!0:a!==o&&t===c},KX={duration:200,easing:"ease"},uI="transform",YX=ur.Transition.toString({property:uI,duration:0,easing:"linear"}),XX={roleDescription:"sortable"};function QX(e){let{disabled:t,index:s,node:r,rect:o}=e;const[i,a]=f.useState(null),l=f.useRef(s);return Ks(()=>{if(!t&&s!==l.current&&r.current){const c=o.current;if(c){const u=Di(r.current,{ignoreTransform:!0}),d={x:c.left-u.left,y:c.top-u.top,scaleX:c.width/u.width,scaleY:c.height/u.height};(d.x||d.y)&&a(d)}}s!==l.current&&(l.current=s)},[t,s,r,o]),f.useEffect(()=>{i&&a(null)},[i]),i}function Iu(e){let{animateLayoutChanges:t=GX,attributes:s,disabled:r,data:o,getNewIndex:i=qX,id:a,strategy:l,resizeObserverConfig:c,transition:u=KX}=e;const{items:d,containerId:m,activeIndex:h,disabled:p,disableTransforms:g,sortedRects:x,overIndex:v,useDragOverlay:b,strategy:w}=f.useContext(dI),j=JX(r,p),T=d.indexOf(a),N=f.useMemo(()=>({sortable:{containerId:m,index:T,items:d},...o}),[m,o,T,d]),S=f.useMemo(()=>d.slice(d.indexOf(a)),[d,a]),{rect:I,node:k,isOver:L,setNodeRef:F}=vl({id:a,data:N,disabled:j.droppable,resizeObserverConfig:{updateMeasurementsFor:S,...c}}),{active:A,activatorEvent:M,activeNodeRect:R,attributes:$,setNodeRef:U,listeners:q,isDragging:te,over:V,setActivatorNodeRef:se,transform:Ce}=z1({id:a,data:N,attributes:{...XX,...s},disabled:j.draggable}),de=wM(F,U),re=!!A,Z=re&&!g&&dc(h)&&dc(v),me=!b&&te,xe=me&&Z?Ce:null,W=Z?xe??(l??w)({rects:x,activeNodeRect:R,activeIndex:h,overIndex:v,index:T}):null,H=dc(h)&&dc(v)?i({id:a,items:d,activeIndex:h,overIndex:v}):T,B=A?.id,ne=f.useRef({activeId:B,items:d,newIndex:H,containerId:m}),ve=d!==ne.current.items,he=t({active:A,containerId:m,isDragging:te,isSorting:re,id:a,index:T,items:d,newIndex:ne.current.newIndex,previousItems:ne.current.items,previousContainerId:ne.current.containerId,transition:u,wasDragging:ne.current.activeId!=null}),G=QX({disabled:!he,index:T,node:k,rect:I});return f.useEffect(()=>{re&&ne.current.newIndex!==H&&(ne.current.newIndex=H),m!==ne.current.containerId&&(ne.current.containerId=m),d!==ne.current.items&&(ne.current.items=d)},[re,H,m,d]),f.useEffect(()=>{if(B===ne.current.activeId)return;if(B!=null&&ne.current.activeId==null){ne.current.activeId=B;return}const ce=setTimeout(()=>{ne.current.activeId=B},50);return()=>clearTimeout(ce)},[B]),{active:A,activeIndex:h,attributes:$,data:N,rect:I,index:T,newIndex:H,items:d,isOver:L,isSorting:re,isDragging:te,listeners:q,node:k,overIndex:v,over:V,setNodeRef:de,setActivatorNodeRef:se,setDroppableNodeRef:F,setDraggableNodeRef:U,transform:G??W,transition:we()};function we(){if(G||ve&&ne.current.newIndex===T)return YX;if(!(me&&!Zd(M)||!u)&&(re||he))return ur.Transition.toString({...u,property:uI})}}function JX(e,t){var s,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(s=e?.draggable)!=null?s:t.draggable,droppable:(r=e?.droppable)!=null?r:t.droppable}}tn.Down,tn.Right,tn.Up,tn.Left;const ZX="default";function eQ(e,t){return e===kr?{kind:"all",fallbackFrom:"recent"}:e===Ts?{kind:"ungrouped"}:e!==Yn&&t.some(s=>s.id===e)?{kind:"group",groupId:e}:{kind:"all"}}const fI=e=>e?.secretaryOrigin?e.secretaryOrigin.secretaryId??ZX:void 0;function Hf(e,t,{projects:s,projectGroups:r,conversations:o}){switch(t.kind){case"all":return[...e];case"secretary":return e.map(i=>({...i,ids:i.ids.filter(a=>fI(o[a])===t.secretaryId)})).filter(i=>i.ids.length>0);default:{const i=new Set(r.map(a=>a.id));return e.filter(a=>{const l=s.find(c=>c.id===a.projectId)?.groupId;return t.kind==="group"?l===t.groupId:!l||!i.has(l)})}}}const Yy=e=>e.reduce((t,s)=>t+s.ids.length,0);function tQ(e,t){const s=new Set;for(const r of e)for(const o of r.ids){const i=fI(t[o]);i&&s.add(i)}return[...s]}const Xy=["idle","running","waiting","error"];function mI(e,t){return e?Zx({...e,hasRunningChild:Ah({...e,status:e.status??"idle"},t)}):"idle"}function Zx(e){const t=Bd({status:e.status??"idle",spawning:e.spawning,pendingAskCount:Po(e.pendingAsks)+(e.pendingApprovals?.length??0),hasRunningChild:e.hasRunningChild});return t==="failed"?"error":t==="unread"||t==="queued"||t==="reminder"?"idle":t}function nQ(e){let t=0;for(const s of Object.values(e))!s||s.parentId||s.btwParentId||(t=Math.max(t,Xy.indexOf(mI(s,e))));return Xy[t]}const sQ=[];function rQ({running:e,idle:t}){const{t:s}=z();return e===0&&t===0?null:n.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[10px] tabular-nums text-muted-foreground/70",children:[e>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5",title:s("{{n}} background tasks running",{n:e}),children:[n.jsx(NN,{className:"h-3 w-3","aria-hidden":!0}),e]}),t>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 text-warning",title:s("{{n}} suspected idle",{n:t}),children:[n.jsx(_h,{className:"h-3 w-3","aria-hidden":!0}),t]})]})}function oQ({conversationId:e}){const{t}=z(),s=J(d=>d.conversations[e]?.backgroundTasks??sQ),r=J(d=>d.conversations[e]?.title),o=J(d=>!d.conversations[e]?.generation),{running:i,idle:a}=ZN(s);if(i===0&&a===0)return null;const l=s.filter(d=>d.status==="running"),c=l.find(d=>d.idle),u=c?.idle?.ports??[];return n.jsxs(Ml,{children:[n.jsx(Pl,{render:n.jsx("span",{"data-enso":"session-task-marker",className:"flex shrink-0 items-center"}),children:n.jsx(rQ,{running:i,idle:a})}),n.jsxs(yu,{align:"start",className:"w-[340px] flex-col p-1 text-[13px]",onClick:d=>d.stopPropagation(),onDoubleClick:d=>d.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-1.5 px-1.5 pt-1 pb-1.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"min-w-0 truncate",children:t("Background tasks of {{title}}",{title:r||t("New conversation")})}),o&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1 text-[10px]",children:t("Session not open")})]}),l.map(d=>n.jsx(iQ,{conversationId:e,task:d},d.taskId)),n.jsxs("div",{className:"mt-1 flex items-center gap-3 border-t border-border/60 px-1.5 pt-1.5 pb-0.5 text-[11px] text-muted-foreground",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:c?u.length>0?t("Port {{ports}} has no connections · CPU 0%",{ports:u.join(", ")}):"CPU 0%":""}),n.jsxs("button",{type:"button",onClick:()=>QN(),className:"inline-flex shrink-0 items-center gap-0.5 text-foreground/80 hover:text-foreground",children:[t("All tasks"),n.jsx(Bi,{className:"size-3"})]})]})]})]})}function iQ({conversationId:e,task:t}){const{t:s}=z(),r=$i(),o=ao(t);return n.jsxs("div",{className:"flex min-h-[30px] min-w-0 items-center gap-2 rounded-lg px-1.5 py-0.5",children:[n.jsx(cx,{task:t}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate font-mono text-xs text-muted-foreground",title:t.command,children:t.command}),o==="idle"?n.jsx("div",{className:"mt-0.5 text-[11px] text-warning",children:lx(t,r,s)}):o==="kept"?n.jsx(dx,{task:t,className:"mt-0.5"}):n.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground tabular-nums",children:s("Running for {{duration}}",{duration:ax(r-t.startedAt)})})]}),o==="idle"?n.jsx(mu,{sessionId:e,taskId:t.taskId}):n.jsx(fx,{onStop:()=>Vi(e,t.taskId)})]})}function Qy({className:e}){const t=_o(i=>i.open),s=J(i=>{let a=0,l=0;for(const c of Object.values(i.conversations)){const u=ZN(c?.backgroundTasks);a+=u.running,l+=u.idle}return`${a}:${l}`}),[r,o]=s.split(":").map(Number);return n.jsx(aQ,{running:r,idle:o,active:t,onClick:()=>QN(),className:e})}function aQ({running:e,idle:t,active:s,onClick:r,className:o}){const{t:i}=z(),a=e+t;if(a===0)return null;const l=t>0?`${i("Background tasks")} (${a}) · ${i("{{n}} suspected idle",{n:t})}`:`${i("Background tasks")} (${a})`;return n.jsxs("button",{type:"button","data-enso":"background-tasks-entry","data-active":s||void 0,"aria-pressed":s,onClick:r,className:_("relative",o,s&&"text-foreground"),title:l,"aria-label":l,children:[n.jsx(NN,{className:"h-4 w-4"}),n.jsx("span",{"data-slot":"background-tasks-count","data-idle":t>0||void 0,className:_("absolute top-0.5 right-0 min-w-3.5 rounded-full bg-muted px-[3px] text-center font-medium text-[9px] leading-3.5 tabular-nums",t>0?"text-warning":"text-muted-foreground"),children:a>99?"99+":a})]})}const lQ=e=>e==="/"?null:e.replace(/\/[^/]+$/,"")||"/";function cQ(e,t){const s=e.includes("\\")&&!e.includes("/")?"\\":"/";return e.endsWith(s)?`${e}${t}`:`${e}${s}${t}`}function Jy({list:e,create:t,initialPath:s,reloadKey:r=0,onSelect:o,onClose:i}){const{t:a}=z(),[l,c]=f.useState(null),[u,d]=f.useState(!1),[m,h]=f.useState(""),[p,g]=f.useState(null),[x,v]=f.useState(""),b=f.useRef(0),w=f.useRef(null),j=f.useRef(e);j.current=e;const T=f.useCallback((F,A=!1)=>{const M=++b.current;d(!0),h(""),j.current(F,A).then(R=>{if(!(M!==b.current||!R)){if("error"in R){h(R.error);return}c(R),w.current=R.path}}).catch(()=>{M===b.current&&h(a("Failed to list remote directory."))}).finally(()=>{M===b.current&&d(!1)})},[a]),N=f.useRef(s);f.useEffect(()=>{T(N.current)},[T]),f.useEffect(()=>{r&&T(w.current??N.current,!0)},[r,T]);const S=l?.path??null,I=l?.dirs??[],k=l?.parent??null,L=()=>{if(!t||!S||p===null||!p.trim())return;const F=++b.current;d(!0),v(""),t(S,p).then(A=>{if(F===b.current){if("error"in A){v(a(A.error));return}g(null),h(""),c(A),w.current=A.path}}).catch(()=>{F===b.current&&v(a("Failed to list remote directory."))}).finally(()=>{F===b.current&&d(!1)})};return n.jsxs("div",{className:"w-full space-y-1.5 rounded-md border bg-muted/30 p-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground text-xs",children:S??"…"}),n.jsx(fe,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",disabled:!k||u,onClick:()=>k&&T(k),children:a("Up")}),t&&n.jsx(fe,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",disabled:!S||u||p!==null,onClick:()=>{g(""),v("")},children:a("New Folder")}),n.jsx(fe,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:i,children:a("Close")})]}),p!==null&&n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(Ht,{autoFocus:!0,size:"sm",className:"min-w-0 flex-1 font-mono text-xs",placeholder:a("Folder name"),value:p,disabled:u,onChange:F=>g(F.target.value),onKeyDown:F=>{if(F.key==="Enter"){if(F.nativeEvent.isComposing)return;F.preventDefault(),L()}else F.key==="Escape"&&(F.preventDefault(),F.stopPropagation(),g(null))}}),n.jsx(fe,{type:"button",size:"sm",className:"h-7 px-2 text-xs",disabled:u||!p.trim(),onClick:L,children:a("Create")}),n.jsx(fe,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:u,onClick:()=>g(null),children:a("Cancel")})]}),x&&n.jsx("p",{className:"px-1 text-destructive text-xs",children:x})]}),n.jsxs("div",{className:"relative min-h-16 max-h-56 overflow-y-auto",children:[m?n.jsx("p",{className:"px-1 py-2 text-destructive text-xs",children:m}):I.length===0&&!u?n.jsx("p",{className:"px-1 py-2 text-muted-foreground text-xs",children:a("No subdirectories")}):n.jsx("div",{className:u?"pointer-events-none space-y-0.5 opacity-40":"space-y-0.5",children:I.map(F=>n.jsxs("button",{type:"button",className:"block w-full truncate rounded px-1.5 py-1 text-left font-mono text-xs hover:bg-muted",disabled:u,onClick:()=>S&&T(cQ(S,F)),children:[F,"/"]},F))}),u&&n.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60",children:[n.jsx(_t,{className:"h-4 w-4 animate-spin text-muted-foreground"}),n.jsx("span",{className:"sr-only",children:a("Loading...")})]})]}),n.jsx(fe,{type:"button",variant:"outline",size:"sm",className:"h-7 w-full text-xs",disabled:!S||u,onClick:()=>S&&o(S),children:a("Use this directory")})]})}function dQ({open:e,onOpenChange:t,onAdd:s,groups:r=[],defaultGroupId:o}){const{t:i}=z(),a=pe(G=>G.projects),[l,c]=f.useState("local"),[u,d]=f.useState(""),[m,h]=f.useState(""),[p,g]=f.useState(""),[x,v]=f.useState([]),[b,w]=f.useState(o),[j,T]=f.useState(!1),[N,S]=f.useState([]),[I,k]=f.useState(""),[L,F]=f.useState(null),[A,M]=f.useState(null),[R,$]=f.useState(0),[U,q]=f.useState(!1),[te,V]=f.useState(!1),se=f.useRef(0),Ce=f.useMemo(()=>[{value:"",label:i("Ungrouped")},...r.map(G=>({value:G.id,label:G.name}))],[r,i]);f.useEffect(()=>{se.current+=1,V(!1),e&&(c("local"),d(""),h(""),g(""),w(o),T(!1),k(""),F(null),M(null),$(0),window.electronAPI.sshConnections.list().then(v).catch(()=>v([])),window.electronAPI.projects.getRecent().then(S).catch(()=>S([])))},[e,o]);const de=f.useMemo(()=>new Set(a.map(G=>G.path)),[a]),re=f.useMemo(()=>N.filter(G=>!de.has(G.path)),[N,de]),Z=f.useCallback((G,we)=>{if(!we)return!0;const ce=we.toLowerCase();return G.path.toLowerCase().includes(ce)||G.displayPath.toLowerCase().includes(ce)||G.sourceName.toLowerCase().includes(ce)},[]),me=!!window.electronAPI.remote,xe=async()=>{if(me){T(we=>!we);return}const G=await window.electronAPI.dialog.selectDirectory();G&&d(G)},Se=f.useCallback(G=>window.electronAPI.projects.listHostDirs(G).then(we=>we.ok?we:{error:we.error}),[]),W=f.useCallback((G,we)=>window.electronAPI.projects.createHostDir(G,we).then(ce=>ce.ok?ce:{error:ce.error}),[]),H=f.useCallback(async(G,we)=>{const ce=await window.electronAPI.sshConnections.listDirs(m,G);if(ce.ok)return{path:ce.path,parent:lQ(ce.path),dirs:ce.dirs};const Re=Hg(ce,x.find(ue=>ue.id===m));return!Re||we?{error:ce.error}:(M("browse"),F(Re),null)},[m,x]),B=l==="local"?u.trim().length>0:m.length>0&&p.trim().startsWith("/"),ne=()=>{const G=x.find(we=>we.id===m);s({path:p.trim(),sshConnectionId:m,sshHost:G?.name,...b?{groupId:b}:{}}),t(!1)},ve=G=>{if(G.preventDefault(),!B)return;if(l!=="ssh"){s({path:u.trim(),...b?{groupId:b}:{}}),t(!1);return}if(te)return;V(!0),k("");const we=++se.current,ce=x.find(Re=>Re.id===m);window.electronAPI.sshConnections.test(m).then(Re=>{if(we===se.current){if(!Re.ok){const ue=Hg(Re,ce);if(ue){M("submit"),F(ue);return}k(Re.error);return}ne()}}).finally(()=>{we===se.current&&V(!1)})},he=async()=>{if(!L)return;q(!0);const G=await window.electronAPI.sshConnections.trustHost(m);if(q(!1),!G.ok){k(G.error||i("Could not save host key.")),F(null),M(null);return}const we=A;if(F(null),M(null),we==="browse"){$(ce=>ce+1);return}we==="submit"&&ne()};return n.jsxs(cn,{open:e,onOpenChange:t,children:[n.jsx(dn,{className:"max-w-lg",children:n.jsxs("form",{onSubmit:ve,className:"flex flex-col",children:[n.jsxs(un,{children:[n.jsx(rn,{children:i("Add project")}),n.jsx(ys,{children:i("Add a local directory as the conversation working folder.")})]}),n.jsxs(In,{className:"space-y-4",children:[n.jsx(Ud,{value:l,onValueChange:G=>{c(G),T(!1)},children:n.jsxs(qd,{children:[n.jsx(ms,{value:"local",children:i("Local directory")}),n.jsx(ms,{value:"ssh",children:i("Remote (SSH)")})]})}),l==="ssh"?n.jsxs(n.Fragment,{children:[n.jsxs(Cs,{className:"w-full",children:[n.jsx(Is,{children:i("SSH connection")}),x.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:i("Add an SSH connection in Settings first.")}):n.jsxs(Cr,{items:[{value:"",label:i("Select an SSH connection")},...x.map(G=>({value:G.id,label:`${G.name} (${G.user?`${G.user}@`:""}${G.host})`}))],value:m,onValueChange:G=>h(G??""),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsxs(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(ir,{value:"",children:i("Select an SSH connection")}),x.map(G=>n.jsxs(ir,{value:G.id,children:[G.name," (",G.user?`${G.user}@`:"",G.host,")"]},G.id))]})]})]}),n.jsxs(Cs,{className:"w-full",children:[n.jsx(Is,{children:i("Remote directory")}),n.jsxs("div",{className:"flex w-full gap-2",children:[n.jsx(Ht,{value:p,onChange:G=>g(G.target.value),placeholder:"/home/user/project",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,className:"min-w-0 flex-1"}),n.jsx(fe,{type:"button",variant:"outline",disabled:!m,onClick:()=>T(G=>!G),children:i("Browse")})]})]}),j&&m&&n.jsx(Jy,{list:H,initialPath:p.trim().startsWith("/")?p.trim():void 0,reloadKey:R,onSelect:G=>{g(G),T(!1)},onClose:()=>T(!1)},m),n.jsx("p",{className:"text-xs text-muted-foreground",children:i("Tools run on the remote host; chat history stays local.")}),I&&n.jsx("p",{className:"text-destructive text-xs",children:I})]}):n.jsxs(Cs,{className:"w-full",children:[n.jsx(Is,{children:i("Working directory")}),n.jsxs(Hx,{value:u,onValueChange:G=>d(G??""),items:re,filter:Z,itemToStringValue:G=>G.path,children:[n.jsxs("div",{className:"flex w-full gap-2",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(Wx,{placeholder:i("Type a path or select from recent projects..."),showClear:!!u,showTrigger:!0})}),n.jsx(fe,{type:"button",variant:"outline",onClick:()=>{xe()},children:i("Browse")})]}),n.jsxs(j2,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(qx,{children:i("No matching projects found")}),n.jsx(Gx,{children:G=>n.jsxs(Ux,{value:G,className:"gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",title:G.path,children:G.displayPath}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:G.sourceName})]},G.path)})]})]}),j&&me&&n.jsx(Jy,{list:Se,create:W,initialPath:u.trim()||void 0,onSelect:G=>{d(G),T(!1)},onClose:()=>T(!1)})]}),r.length>0&&n.jsxs(Cs,{children:[n.jsx(Is,{children:i("Project group")}),n.jsxs(Cr,{items:Ce,value:b??"",onValueChange:G=>w(G||void 0),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:Ce.map(G=>n.jsx(ir,{value:G.value,children:G.label},G.value||"ungrouped"))})]})]})]}),n.jsxs(ts,{children:[n.jsx(fe,{type:"button",variant:"outline",size:"sm",onClick:()=>t(!1),children:i("Cancel")}),n.jsx(fe,{type:"submit",size:"sm",disabled:!B||te,children:i("Add")})]})]})}),n.jsx(XR,{challenge:L,nested:!0,busy:U,onTrust:()=>{he()},onDismiss:()=>{U||(F(null),M(null))}})]})}function Zy({count:e,onClick:t,className:s}){const{t:r}=z(),o=e===0,i=`${r("Archived")} (${e})`;return n.jsxs("button",{type:"button","data-slot":"archived-button","data-empty":o||void 0,onClick:t,className:_("relative",s,o&&"opacity-55"),title:i,"aria-label":i,children:[n.jsx(lr,{className:"h-4 w-4"}),!o&&n.jsx("span",{"data-slot":"archived-count",className:"absolute top-0.5 right-0 min-w-3.5 rounded-full bg-muted px-[3px] text-center font-medium text-[9px] text-muted-foreground leading-3.5 tabular-nums",children:e>99?"99+":e})]})}function Wf({label:e,selected:t,onClick:s}){return n.jsx("button",{type:"button","data-slot":"archive-scope-chip","data-selected":t||void 0,onClick:s,className:_("max-w-48 truncate rounded-full border px-2.5 py-0.5 text-xs transition-colors",t?"border-brand/40 bg-brand/10 text-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:e})}function uQ(e,t){return{x:e.left-t,width:Math.max(0,e.width)}}const hI="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",pI="flex size-4.5 shrink-0 items-center justify-center rounded-[5px] text-subtle-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",fQ=24,sa=20;function mQ({groups:e,selectedId:t,counts:s,totalCount:r,recentCount:o,ungroupedCount:i,query:a,onQueryChange:l,searchOpen:c,onSearchOpenChange:u,onSelect:d,onAddGroup:m,onEditGroup:h}){const{t:p}=z(),g=e.slice().sort((V,se)=>V.order-se.order),x=g.length>0,v=c||a.length>0,b=f.useRef(null),w=f.useRef(null),j=f.useRef(null),T=f.useRef(null),N=f.useRef(null),[S,I]=f.useState({left:!1,right:!1,overflow:!1}),{active:k}=gl(),L=g.find(V=>V.id===t),F=t===Ts?p("Ungrouped"):L?.name??null,A=F?p("Search in {{group}}...",{group:F}):p("Search conversations..."),M=f.useCallback(()=>{const V=j.current,se=w.current,Ce=T.current,de=N.current,re=se?.querySelector("[data-selected]");if(!V||!se||!Ce||!de||!re||V.offsetParent===null){de&&(de.style.width="0px");return}const Z=se.getBoundingClientRect(),me=V.getBoundingClientRect(),xe=re.getBoundingClientRect(),Se=uQ(xe,Z.left);Ce.style.left=`${Z.left-me.left}px`,Ce.style.width=`${Z.width}px`,de.style.transform=`translateX(${Se.x}px)`,de.style.width=`${Se.width}px`},[]),R=f.useCallback(()=>{const V=w.current;M(),!(!V||V.clientWidth===0)&&I(se=>{const Ce=se.overflow?fQ:0,de={left:V.scrollLeft>1,right:V.scrollLeft+V.clientWidth<V.scrollWidth-1,overflow:V.scrollWidth>V.clientWidth+Ce+1};return se.left===de.left&&se.right===de.right&&se.overflow===de.overflow?se:de})},[M]);f.useLayoutEffect(()=>{const V=w.current;if(!V)return;R();const se=new ResizeObserver(R);return se.observe(V),V.firstElementChild&&se.observe(V.firstElementChild),()=>se.disconnect()},[R]),f.useLayoutEffect(()=>{M()},[M,k,t,v,g.length]),f.useEffect(()=>{const V=w.current;if(!V)return;const se=Ce=>{Math.abs(Ce.deltaY)<=Math.abs(Ce.deltaX)||V.scrollWidth<=V.clientWidth||(V.scrollLeft+=Ce.deltaY,Ce.preventDefault())};return V.addEventListener("wheel",se,{passive:!1}),()=>V.removeEventListener("wheel",se)},[]);const $=f.useRef(!1);f.useLayoutEffect(()=>{const V=w.current,se=V?.querySelector("[data-selected]");if(!V||!se||V.clientWidth===0)return;const Ce=$.current?"smooth":"auto";$.current=!0;const de=se.offsetLeft,re=de+se.offsetWidth;de<V.scrollLeft+sa?V.scrollTo({left:de-sa,behavior:Ce}):re>V.scrollLeft+V.clientWidth-sa&&V.scrollTo({left:re-V.clientWidth+sa,behavior:Ce})},[t,x,c]),f.useEffect(()=>{c&&b.current?.focus()},[c]);const U=()=>{l(""),u(!1)},q=V=>V?`${sa}px`:"0px",te=S.left||S.right?`linear-gradient(to right, transparent, #000 ${q(S.left)}, #000 calc(100% - ${q(S.right)}), transparent)`:void 0;return n.jsxs("div",{className:"group/bar shrink-0",children:[n.jsxs("div",{className:"relative z-[1] flex h-[35px] items-end gap-1.5 px-3.5",children:[v&&n.jsxs("label",{className:"mb-1 flex h-7 min-w-0 flex-1 cursor-text items-center gap-2 rounded-lg border border-transparent bg-foreground/5 pr-0.5 pl-2.5 text-xs text-muted-foreground transition-colors focus-within:border-brand/45",children:[n.jsx(MN,{className:"size-3.5 shrink-0"}),n.jsx("input",{ref:b,value:a,onChange:V=>l(V.target.value),onKeyDown:V=>{V.key==="Escape"&&(V.stopPropagation(),U())},onBlur:()=>{!a&&document.hasFocus()&&u(!1)},placeholder:A,className:"h-full min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground"}),n.jsx("button",{type:"button",onClick:U,className:"flex size-5 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-foreground/5 hover:text-foreground",title:p("Close"),"aria-label":p("Close"),children:n.jsx(Jt,{className:"size-3"})})]}),n.jsxs("div",{ref:j,className:_("relative flex min-w-0 flex-1 items-center gap-1.5",v&&"hidden"),children:[n.jsx("div",{ref:w,onScroll:R,style:{maskImage:te},className:"min-w-0 overflow-x-auto [scrollbar-width:none]",children:n.jsxs("div",{className:"flex w-max gap-3.5",children:[n.jsx("button",{type:"button","data-enso":"group-chip","data-selected":t===Yn||void 0,"data-active":t===Yn||void 0,onClick:()=>d(Yn),className:Dd(t===Yn,!1),children:n.jsx(Od,{label:p("All"),count:r})}),n.jsx("button",{type:"button","data-enso":"group-chip","data-selected":t===kr||void 0,"data-active":t===kr||void 0,onClick:()=>d(kr),className:Dd(t===kr,!1),children:n.jsx(Od,{label:p("Recent"),count:o})}),n.jsx(Nh,{items:g.map(V=>Yx(V.id)),strategy:HX,children:g.map(V=>n.jsx(hQ,{group:V,count:s[V.id]??0,selected:t===V.id,onSelect:()=>d(V.id)},V.id))}),x&&n.jsx(pQ,{label:p("Ungrouped"),count:i,selected:t===Ts,onSelect:()=>d(Ts)})]})}),n.jsx("span",{ref:T,"aria-hidden":!0,className:"pointer-events-none absolute -bottom-px z-10 h-[1.5px] overflow-hidden",children:n.jsx("span",{ref:N,className:"absolute top-0 left-0 h-full rounded-full bg-foreground"})}),n.jsx("button",{type:"button",onClick:m,className:_(pI,"opacity-0 focus-visible:opacity-100 group-hover/bar:opacity-100 [@media(hover:none)]:opacity-100"),title:p("New group"),"aria-label":p("New group"),children:n.jsx(Qn,{className:"size-3"})}),S.overflow&&n.jsx(xQ,{groups:g,selectedId:t,counts:s,totalCount:r,recentCount:o,ungroupedCount:i,onSelect:d,onAddGroup:m,onEditGroup:h})]})]}),n.jsx("div",{className:"mx-3.5 h-px bg-border"})]})}function Dd(e,t){return _("flex shrink-0 items-center whitespace-nowrap pt-1 pb-[7px] text-[0.8929rem] transition-colors",e?"font-medium text-foreground":"text-subtle-foreground hover:text-foreground",t&&"rounded-t-md bg-foreground/[0.075] text-foreground")}function Od({label:e,count:t,emoji:s,color:r}){return n.jsxs(n.Fragment,{children:[s&&n.jsx("span",{className:"mr-1 text-[13px] leading-none",children:s}),r&&n.jsx("span",{className:"mr-1.5 size-1.5 shrink-0 rounded-full",style:{backgroundColor:r},"aria-hidden":!0}),n.jsx("span",{className:"max-w-32 truncate",children:e}),n.jsx("span",{className:"ml-1 font-normal text-[0.75rem] text-subtle-foreground/75 tabular-nums",children:t})]})}const xI=e=>e?.type==="project";function hQ({group:e,count:t,selected:s,onSelect:r}){const{attributes:o,listeners:i,setNodeRef:a,transform:l,transition:c,isDragging:u,isOver:d,active:m}=Iu({id:Yx(e.id),data:{type:"project-group",groupId:e.id}});return n.jsx("button",{ref:a,type:"button","data-enso":"group-chip","data-selected":s||void 0,"data-active":s||void 0,onClick:r,style:{transform:l?`translate3d(${Math.round(l.x)}px, 0, 0)`:void 0,transition:c},className:_(Dd(s,d&&xI(m?.data.current)),u&&"z-10 cursor-grabbing text-foreground"),...o,...i,children:n.jsx(Od,{label:e.name,count:t,emoji:e.emoji,color:e.color})})}function pQ({label:e,count:t,selected:s,onSelect:r}){const{active:o}=gl(),{setNodeRef:i,isOver:a}=vl({id:Yx(Ts),disabled:o?.data.current?.type==="project-group"});return n.jsx("button",{ref:i,type:"button","data-enso":"group-chip","data-selected":s||void 0,"data-active":s||void 0,onClick:r,className:Dd(s,a&&xI(o?.data.current)),children:n.jsx(Od,{label:e,count:t})})}function xQ({groups:e,selectedId:t,counts:s,totalCount:r,recentCount:o,ungroupedCount:i,onSelect:a,onAddGroup:l,onEditGroup:c}){const{t:u}=z(),[d,m]=f.useState(!1),h=p=>()=>{m(!1),p()};return n.jsxs(Ms,{open:d,onOpenChange:m,children:[n.jsx(Ps,{className:_(pI,"ml-auto data-popup-open:bg-foreground/5 data-popup-open:text-foreground"),title:u("All groups"),"aria-label":u("All groups"),children:n.jsx(Fn,{className:"size-3"})}),n.jsxs(Ds,{side:"bottom",align:"end",className:"w-56 [&_[data-slot=popover-viewport]]:p-1",children:[n.jsx(mc,{label:u("All"),count:r,selected:t===Yn,onSelect:h(()=>a(Yn))}),n.jsx(mc,{label:u("Recent"),count:o,selected:t===kr,onSelect:h(()=>a(kr))}),e.map(p=>n.jsx(mc,{label:p.name,emoji:p.emoji,color:p.color,count:s[p.id]??0,selected:t===p.id,onSelect:h(()=>a(p.id)),onEdit:h(()=>c(p.id))},p.id)),e.length>0&&n.jsx(mc,{label:u("Ungrouped"),count:i,selected:t===Ts,onSelect:h(()=>a(Ts))}),n.jsx("div",{className:"my-1 border-t"}),n.jsxs("button",{type:"button",onClick:h(l),className:_(hI,"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[n.jsx(Qn,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:u("New group")})]})]})]})}function mc({label:e,count:t,emoji:s,color:r,selected:o,onSelect:i,onEdit:a}){const{t:l}=z();return n.jsxs("div",{className:"group/row relative",children:[n.jsxs("button",{type:"button",onClick:i,className:_(hI,o?"bg-brand/10 text-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[n.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center gap-1",children:s?n.jsx("span",{className:"text-[13px] leading-none",children:s}):r?n.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:r},"aria-hidden":!0}):null}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs tabular-nums",children:t}),n.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center",children:o&&n.jsx(On,{className:_("size-3.5 text-brand",a&&"group-hover/row:opacity-0")})})]}),a&&n.jsx("button",{type:"button",onClick:a,className:"absolute inset-y-0 right-2 my-auto flex size-5 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-background hover:text-foreground focus-visible:opacity-100 group-hover/row:opacity-100",title:l("Edit group"),"aria-label":l("Edit group"),children:n.jsx(bs,{className:"size-3.5"})})]})}function gI({value:e,reasoningEnabled:t,thinkingLevel:s,onChange:r,onReasoningChange:o,onThinkingChange:i,description:a,inheritLabel:l}){const{t:c}=z(),u=pe(g=>g.virtualModels),d=u1(),m=e?d.find(g=>g.id===e.providerId):void 0,h=m?.models.find(g=>g.id===e?.modelId),p=Kj(u,e);return n.jsxs(Cs,{className:"w-full items-stretch",children:[n.jsx(Is,{children:c("Default model")}),n.jsx(m1,{children:a}),d.length>0&&n.jsx("div",{className:"w-full min-w-0",children:n.jsx(f1,{providers:d,virtualModels:u,providerId:p?e?.providerId??"":m?.id??"",modelId:p?p.id:h?.id??"",reasoningEnabled:t,thinkingLevel:s,emptyLabel:l,side:"bottom",triggerClassName:QR,zIndex:Pn.DROPDOWN_IN_MODAL,onSelect:(g,x)=>r({providerId:g,modelId:x}),onReasoningChange:o,onThinkingChange:i})}),e&&!p&&(!m||!h)&&n.jsx("p",{className:"text-muted-foreground text-xs",children:c("Selected model is unavailable — falls back to the default model.")}),e&&n.jsx(fe,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:c("Follow default model")})]})}const gQ=["#3b82f6","#22c55e","#eab308","#f97316","#ef4444","#a855f7","#06b6d4","#64748b"];function vQ({open:e,group:t,projects:s,onOpenChange:r,onSave:o,onDelete:i}){const{t:a}=z(),l=pe(M=>M.defaultReasoningEnabled),c=pe(M=>M.defaultThinkingLevel),[u,d]=f.useState(""),[m,h]=f.useState(),[p,g]=f.useState(null),[x,v]=f.useState(!0),[b,w]=f.useState("medium"),[j,T]=f.useState(new Set),[N,S]=f.useState(""),I=t===null,k=I?s??[]:[],L=N.trim().toLowerCase(),F=L?k.filter(M=>[M.alias??"",M.name].some(R=>R.toLowerCase().includes(L))):k;f.useEffect(()=>{if(!e)return;d(t?.name??""),h(t?.color),g(t?.defaultModel??null);const M=Qc({defaultReasoningEnabled:l,defaultThinkingLevel:c});v(t?.defaultReasoningEnabled??M.reasoningEnabled),w(t?.defaultThinkingLevel??M.thinkingLevel),T(new Set),S("")},[e,t,l,c]);const A=M=>{T(R=>{const $=new Set(R);return $.has(M)?$.delete(M):$.add(M),$})};return n.jsx(cn,{open:e,onOpenChange:r,children:n.jsx(dn,{className:"max-w-md",children:n.jsxs("form",{className:"flex flex-col",onSubmit:M=>{M.preventDefault();const R=u.trim();R&&(o({name:R,color:m,defaultModel:p,defaultReasoningEnabled:p?x:null,defaultThinkingLevel:p?b:null,...I&&j.size>0?{projectIds:[...j]}:{}}),r(!1))},children:[n.jsxs(un,{children:[n.jsx(rn,{children:a(t?"Edit group":"New group")}),n.jsx(ys,{children:a("Groups organize projects in the sidebar.")})]}),n.jsxs(In,{className:"space-y-3",children:[n.jsxs(Cs,{children:[n.jsx(Is,{children:a("Name")}),n.jsx(Ht,{value:u,onChange:M=>d(M.target.value),autoFocus:!0})]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.jsx("button",{type:"button",className:"flex h-6 w-6 items-center justify-center rounded-full border border-border bg-background text-muted-foreground",style:{outline:m==null?"2px solid var(--color-ring)":void 0,outlineOffset:2},onClick:()=>h(void 0),"aria-label":a("No color"),children:n.jsx(Jt,{className:"h-3 w-3"})}),gQ.map(M=>n.jsx("button",{type:"button",className:"h-6 w-6 rounded-full border border-border",style:{backgroundColor:M,outline:m===M?"2px solid var(--color-ring)":void 0,outlineOffset:2},onClick:()=>h(m===M?void 0:M),"aria-label":M},M))]}),n.jsx(gI,{value:p,reasoningEnabled:x,thinkingLevel:b,onChange:M=>{if(g(M),M)return;const R=Qc({defaultReasoningEnabled:l,defaultThinkingLevel:c});v(R.reasoningEnabled),w(R.thinkingLevel)},onReasoningChange:v,onThinkingChange:w,description:a("Used for new conversations in this group."),inheritLabel:a("Follows the global default")}),k.length>0&&n.jsxs(Cs,{className:"w-full items-stretch",children:[n.jsx(Is,{children:a("Move projects into this group")}),n.jsx(Ht,{value:N,onChange:M=>S(M.target.value),placeholder:a("Filter projects...")}),n.jsxs("div",{className:"max-h-48 w-full space-y-0.5 overflow-y-auto rounded-md border p-1.5",children:[F.map(M=>n.jsxs("label",{className:"flex w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 hover:bg-accent/50",children:[n.jsx(Vo,{checked:j.has(M.id),onCheckedChange:()=>A(M.id)}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:qn(M)})]},M.id)),F.length===0&&n.jsx("p",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:a("No matching projects found")})]})]})]}),n.jsxs(ts,{className:t?"sm:justify-between":void 0,children:[t&&i?n.jsx(fe,{type:"button",variant:"outline",size:"sm",className:"text-destructive",onClick:()=>{i(),r(!1)},children:a("Delete group")}):n.jsx("span",{}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(fe,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:a("Cancel")}),n.jsx(fe,{type:"submit",size:"sm",disabled:!u.trim(),children:a("Save")})]})]})]})})})}function bQ(e){return e?"copy":"move"}function yQ(e,t){const s=new Set(typeof t=="string"?[t]:t);let r=!0;for(;r;){r=!1;for(const[o,i]of Object.entries(e))!i||s.has(o)||(typeof i.parentId=="string"&&s.has(i.parentId)||typeof i.btwParentId=="string"&&s.has(i.btwParentId))&&(s.add(o),r=!0)}return[...s]}function vI(e,t){return!e.some(s=>s.id===t&&s.kind==="secretary")}function bI(e,t){return vI(e,t)?e.filter(s=>s.id!==t&&s.kind!=="scratch"&&s.kind!=="secretary"):[]}const Sh={running:"Cannot move a running conversation","worktree-busy":"Cannot move while its worktree is in use","source-secretary":"Secretary conversations cannot be moved"};function wQ(e){return Object.hasOwn(Sh,e)?Sh[e]:"Failed to move conversation"}async function jQ(e,t,s){try{const r=await window.electronAPI.settings.moveConversation({conversationId:e,targetProjectId:t});if(!r.ok){Ie({type:"error",title:s(wQ(r.error)),...Object.hasOwn(Sh,r.error)?{}:{description:r.error}});return}yI([e],t)}catch(r){Ie({type:"error",title:s("Failed to move conversation"),description:String(r)})}}function yI(e,t){e.length!==0&&J.setState(s=>{const r={...s.conversations},o={...s.worktreeStatuses};for(const i of yQ(r,e)){const a=r[i];a&&(r[i]={...a,projectId:t})}for(const i of e){const a=r[i];a&&(r[i]={...a,worktree:void 0,worktreeMissing:void 0}),delete o[i]}return{conversations:r,worktreeStatuses:o}})}function kQ(e,t){return Object.values(e).filter(s=>s.projectId===t&&!s.parentId&&!s.btwParentId).length}async function NQ(e,t,s,r){try{const o=await window.electronAPI.settings.importProjectSessions({sourceProjectId:e,targetProjectId:t,mode:s});if(!o.ok)return Ie({type:"error",title:r("Failed to import conversations"),description:o.error}),null;o.mode==="move"&&yI(o.imported,t);const i=o.imported.length;if(o.skipped.length>0){const{conversations:a}=J.getState();Ie({type:"warning",title:o.mode==="move"?r("Imported {{moved}} conversations; {{count}} running or busy ones stay in the original project",{moved:i,count:o.skipped.length}):r("Copied {{moved}} conversations; {{count}} running ones were not copied",{moved:i,count:o.skipped.length}),description:o.skipped.map(({conversationId:l})=>a[l]?.title||r("Untitled")).join("、")})}else Ie({type:i>0?"success":"info",title:i===0?r("No conversations to import"):o.mode==="move"?r("Imported {{count}} conversations",{count:i}):r("Copied {{count}} conversations",{count:i})});return{offerRemoveSource:o.mode==="move"&&o.sourceEmpty}}catch(o){return Ie({type:"error",title:r("Failed to import conversations"),description:String(o)}),null}}async function SQ(e,t){try{const s=await window.electronAPI.settings.removeEmptyProject({projectId:e});return s.ok?(pe.setState(r=>({projects:r.projects.filter(o=>o.id!==e)})),!0):(Ie({type:"error",title:t("Failed to remove project"),description:s.error}),!1)}catch(s){return Ie({type:"error",title:t("Failed to remove project"),description:String(s)}),!1}}function CQ({project:e,onClose:t}){const{t:s}=z(),r=pe(w=>w.projects),[o,i]=f.useState(null),[a,l]=f.useState("copy"),[c,u]=f.useState(null),[d,m]=f.useState(!1),[h,p]=f.useState(null);f.useEffect(()=>{e&&i(null)},[e]),f.useEffect(()=>{if(u(null),!e||!o)return;let w=!0;return window.electronAPI.settings.importProjectSessionsPreview({sourceProjectId:o,targetProjectId:e.id}).then(j=>{!w||!j.ok||(u(j),l(bQ(j.sourceExists)))}).catch(()=>{}),()=>{w=!1}},[e,o]);const g=f.useMemo(()=>{if(!e)return[];const{conversations:w}=J.getState();return bI(r,e.id).map(j=>({project:j,count:kQ(w,j.id)}))},[e,r]),x=g.find(w=>w.project.id===o),v=async()=>{if(!(!e||!x)){m(!0);try{const w=await NQ(x.project.id,e.id,a,s);if(!w)return;w.offerRemoveSource&&p(x.project),t()}finally{m(!1)}}},b=[{value:"move",label:s("Move to this project"),hint:s("The conversations leave the original project and show up only here. Session files stay as they are; nothing is copied or deleted.")},{value:"copy",label:s("Copy to this project"),hint:s("The original project keeps its conversations unchanged; this project gets an independent copy.")}];return n.jsxs(n.Fragment,{children:[n.jsx(cn,{open:e!==null,onOpenChange:w=>!w&&t(),children:n.jsxs(dn,{className:"max-w-lg",children:[n.jsxs(un,{children:[n.jsx(rn,{children:s("Import conversations from another project")}),n.jsx(ys,{children:s("Pick a project. All of its conversations, archived ones included, are brought into {{name}}.",{name:e?e.alias||e.name:""})})]}),n.jsxs(In,{className:"flex flex-col gap-3",children:[g.length===0?n.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:s("No other projects")}):n.jsx("div",{className:"flex max-h-64 flex-col overflow-y-auto rounded-lg border",children:g.map(({project:w,count:j})=>n.jsxs("button",{type:"button",onClick:()=>i(w.id),className:_("flex w-full items-center gap-3 px-3 py-2 text-left",o===w.id?"bg-muted":"hover:bg-muted/50"),children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"truncate text-sm",children:w.alias||w.name}),n.jsx("p",{className:"truncate text-xs text-muted-foreground",children:w.path})]}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:s("{{count}} conversations",{count:j})})]},w.id))}),x&&n.jsx(JR,{value:a,onValueChange:w=>l(w),className:"grid gap-2","aria-label":s("Import mode"),children:b.map(w=>n.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[n.jsx(ZR,{value:w.value,disabled:d}),n.jsxs("span",{children:[n.jsx("span",{className:"block text-sm font-medium",children:w.label}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:w.hint})]})]},w.value))}),x&&c&&!c.sourceExists&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s("The source project folder no longer exists, so moving is preselected.")}),x&&a==="copy"&&c&&c.copies>0&&n.jsx("p",{className:"text-xs text-warning-foreground dark:text-warning",children:s("Already copied here {{count}} times. Copying again adds another independent copy.",{count:c.copies})})]}),n.jsxs(ts,{children:[n.jsx(fe,{variant:"outline",onClick:t,children:s("Cancel")}),n.jsxs(fe,{onClick:()=>{v()},disabled:d||!x||x.count===0,children:[d?n.jsx(di,{className:"mr-1.5 size-3.5"}):a==="move"?n.jsx(IN,{className:"mr-1.5 h-3.5 w-3.5"}):n.jsx(ul,{className:"mr-1.5 h-3.5 w-3.5"}),s(d?a==="move"?"Moving…":"Copying…":a==="move"?"Move here":"Copy here")]})]})]})}),n.jsx(cs,{open:h!==null,onOpenChange:w=>!w&&p(null),title:s("The old project has no conversations left. Remove it from the list?"),description:s('"{{name}}" is only removed from the EnsoCode list. Its folder and files on disk are not deleted.',{name:h?h.alias||h.name:""}),confirmLabel:s("Remove"),cancelLabel:s("Keep"),onConfirm:()=>{h&&SQ(h.id,s)}})]})}const IQ={rescan:"The session list is out of date. Please rescan.",denied:"This session is outside the allowed folders and cannot be read.",empty:"This session has no messages to import."};function TQ({project:e,onClose:t}){const{t:s}=z(),[r,o]=f.useState(null),[i,a]=f.useState(null),[l,c]=f.useState(null),[u,d]=f.useState(null),[m,h]=f.useState(!1),[p,g]=f.useState(0);f.useEffect(()=>{if(!e)return;let v=!0;return o(null),a(null),c(null),d(null),window.electronAPI.sessionImport.scan(e.path).then(b=>{v&&o(b)}).catch(()=>{v&&o([])}),()=>{v=!1}},[e,p]),f.useEffect(()=>{if(!i){c(null);return}let v=!0;return c(null),d(null),window.electronAPI.sessionImport.read(i).then(b=>{v&&(c(b.ok?b.messages:[]),b.ok||d(b.error))}).catch(()=>{v&&c([])}),()=>{v=!1}},[i]);const x=async()=>{if(!(!e||!i)){h(!0);try{const v=await window.electronAPI.sessionImport.import(i);if(!v.ok){d(v.error);return}J.getState().addImportedConversation(e.id,v),t()}finally{h(!1)}}};return n.jsx(cn,{open:e!==null,onOpenChange:v=>!v&&t(),children:n.jsxs(dn,{className:"max-w-3xl",children:[n.jsxs(un,{children:[n.jsx(rn,{children:s("Import session")}),n.jsx(ys,{children:s("Pick a conversation from a local AI app under {{name}}.",{name:e?.name??""})})]}),n.jsx(In,{children:r===null?n.jsx("div",{className:"flex flex-col items-center gap-3 py-12",children:n.jsx(di,{className:"size-5"})}):r.length===0?n.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:s("No sessions found for this project")}):n.jsxs("div",{className:"flex h-96 gap-3",children:[n.jsx("div",{className:"flex w-64 shrink-0 flex-col overflow-y-auto rounded-lg border",children:r.map(v=>n.jsxs("div",{children:[n.jsx("p",{className:"sticky top-0 bg-background px-2.5 pt-2 pb-1 text-[10px] font-semibold tracking-[0.18em] text-muted-foreground uppercase",children:v.sourceName}),v.sessions.map(b=>n.jsxs("button",{type:"button",onClick:()=>a(b.token),className:_("w-full px-2.5 py-1.5 text-left",i===b.token?"bg-muted":"hover:bg-muted/50"),children:[n.jsx("p",{className:"truncate text-xs",children:b.title||s("Untitled")}),n.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[new Date(b.updatedAt).toLocaleString()," ·"," ",s("{{count}} messages",{count:b.messageCount})]})]},b.token))]},v.sourceId))}),n.jsx("div",{className:"min-w-0 flex-1 overflow-y-auto rounded-lg border bg-muted/20 p-3",children:i?l===null?n.jsx("div",{className:"flex justify-center py-12",children:n.jsx(di,{className:"size-4"})}):n.jsx("div",{className:"flex flex-col gap-2.5",children:l.map((v,b)=>n.jsx("div",{className:_("max-w-[90%] rounded-lg px-2.5 py-1.5 text-xs whitespace-pre-wrap",v.role==="user"?"self-end bg-primary/10":"self-start bg-background border"),children:v.text.length>600?`${v.text.slice(0,600)}…`:v.text},b))}):n.jsx("p",{className:"py-12 text-center text-xs text-muted-foreground",children:s("Select a session to preview")})})]})}),n.jsxs(ts,{children:[u&&n.jsx("p",{className:"mr-auto self-center text-xs text-destructive",children:s(IQ[u])}),u==="rescan"&&n.jsx(fe,{variant:"outline",onClick:()=>g(v=>v+1),children:s("Rescan")}),n.jsx(fe,{variant:"outline",onClick:t,children:s("Cancel")}),n.jsxs(fe,{onClick:()=>{x()},disabled:!i||m,children:[m?n.jsx(di,{className:"mr-1.5 size-3.5"}):n.jsx(zd,{className:"mr-1.5 h-3.5 w-3.5"}),s("Import")]})]})]})})}function AQ({open:e,project:t,onOpenChange:s}){const{t:r}=z(),o=pe(de=>de.projectGroups),i=pe(de=>de.defaultReasoningEnabled),a=pe(de=>de.defaultThinkingLevel),l=pe(de=>de.setProjectDefaultModel),c=pe(de=>de.setProjectGroupId),u=pe(de=>de.setProjectAlias),d=pe(de=>de.setProjectDisabledBuiltinTools),m=pe(de=>de.setProjectSubagentAllowedModes),h=pe(de=>de.setProjectTrustedCode),p=pe(de=>de.disabledBuiltinTools),g=pe(de=>de.subagentAllowedModes),[x,v]=f.useState(""),[b,w]=f.useState(null),[j,T]=f.useState(!0),[N,S]=f.useState("medium"),[I,k]=f.useState(""),[L,F]=f.useState(!0),[A,M]=f.useState([]),[R,$]=f.useState(!0),[U,q]=f.useState([]),[te,V]=f.useState(!1);f.useEffect(()=>{if(!e)return;V(!1),w(t?.defaultModel??null),k(t?.groupId??""),v(t?.alias??"");const de=t?.groupId?o.find(xe=>xe.id===t.groupId):void 0,re=Qc({groupReasoningEnabled:de?.defaultReasoningEnabled,groupThinkingLevel:de?.defaultThinkingLevel,defaultReasoningEnabled:i,defaultThinkingLevel:a});T(t?.defaultReasoningEnabled??re.reasoningEnabled),S(t?.defaultThinkingLevel??re.thinkingLevel);const Z=t?.disabledBuiltinTools===void 0;F(Z),M(Z?[...p]:[...t?.disabledBuiltinTools??[]]);const me=t?.subagentAllowedModes===void 0;$(me),q(me?[...g]:[...t?.subagentAllowedModes??[]])},[e,t,o,i,a,p,g]);const se=f.useMemo(()=>[{value:"",label:r("Ungrouped")},...o.slice().sort((de,re)=>de.order-re.order).map(de=>({value:de.id,label:de.name}))],[o,r]),Ce=t?.kind==="ssh"?`${t.sshConnectionName??t.sshHost}:${t.path}`:t?.path??"";return n.jsx(cn,{open:e,onOpenChange:s,children:n.jsx(dn,{className:"max-w-lg",children:n.jsxs("form",{className:"contents",onSubmit:de=>{de.preventDefault(),t&&(l(t.id,b,b?{reasoningEnabled:j,thinkingLevel:N}:null),c(t.id,I||null),u(t.id,x),d(t.id,L?null:A),m(t.id,R?null:U),te&&h(t.id,null),s(!1))},children:[n.jsxs(un,{children:[n.jsx(rn,{children:r("Project settings")}),n.jsx(ys,{children:t?qn(t):r("Project")})]}),n.jsxs(In,{className:"max-h-[60vh] space-y-4",children:[n.jsxs(Cs,{className:"w-full items-stretch",children:[n.jsx(Is,{children:r("Alias")}),n.jsx(Ht,{value:x,onChange:de=>v(de.target.value),placeholder:t?qn({...t,alias:void 0}):""}),n.jsx(m1,{children:r("Shown in the sidebar instead of the folder name. Leave blank to reset.")})]}),n.jsxs(Cs,{className:"w-full items-stretch",children:[n.jsx(Is,{children:r("Path")}),n.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[n.jsx("p",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:Ce,children:Ce}),n.jsx($d,{text:Ce,className:"shrink-0"}),t&&t.kind!=="ssh"&&n.jsx("button",{type:"button",onClick:()=>{window.electronAPI.projects.reveal({projectId:t.id})},className:"shrink-0 transition-colors hover:text-foreground",title:r("Open folder"),children:n.jsx(Lr,{className:"h-3 w-3"})})]})]}),o.length>0&&n.jsxs(Cs,{className:"w-full items-stretch",children:[n.jsx(Is,{children:r("Project group")}),n.jsxs(Cr,{items:se,value:I,onValueChange:de=>k(de??""),children:[n.jsx(Ir,{className:"w-full",children:n.jsx(Tr,{})}),n.jsx(Ar,{zIndex:Pn.DROPDOWN_IN_MODAL,children:se.map(de=>n.jsx(ir,{value:de.value,children:de.label},de.value||"ungrouped"))})]})]}),n.jsx(gI,{value:b,reasoningEnabled:j,thinkingLevel:N,onChange:de=>{if(w(de),de)return;const re=I?o.find(me=>me.id===I):void 0,Z=Qc({groupReasoningEnabled:re?.defaultReasoningEnabled,groupThinkingLevel:re?.defaultThinkingLevel,defaultReasoningEnabled:i,defaultThinkingLevel:a});T(Z.reasoningEnabled),S(Z.thinkingLevel)},onReasoningChange:T,onThinkingChange:S,description:r("Used for new conversations in this project."),inheritLabel:r("Follows group, then global default")}),n.jsx("p",{className:"text-muted-foreground text-xs",children:r("Session choice overrides the project default.")}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"font-medium text-sm",children:r("Follow global built-in tools")}),n.jsx("p",{className:"text-muted-foreground text-xs",children:r("When off, configure built-in tools for this project. They override the global setting on the next session.")})]}),n.jsx(rr,{checked:L,onCheckedChange:F})]}),!L&&n.jsx("div",{className:"space-y-2",children:e3.map(de=>n.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5",children:[n.jsx(Jh,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"text-sm font-medium",children:r(de.name)}),n.jsx("p",{className:"text-muted-foreground text-xs",children:r(de.description)})]}),n.jsx(rr,{checked:!A.includes(de.id),onCheckedChange:re=>M(Z=>re?Z.filter(me=>me!==de.id):[...new Set([...Z,de.id])])})]},de.id))}),n.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"font-medium text-sm",children:r("Follow global unified agent modes")}),n.jsx("p",{className:"text-muted-foreground text-xs",children:r("When off, this project uses its own explicit Agent mode permission mask.")})]}),n.jsx(rr,{checked:R,onCheckedChange:de=>{$(de),de||q([...g])}})]}),!R&&n.jsxs("div",{className:"space-y-2 rounded-lg border px-3 py-2.5",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([de,re])=>n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx("span",{className:"text-sm",children:r(re)}),n.jsx(rr,{checked:U.includes(de),disabled:(L?p:A).includes("subagent"),onCheckedChange:Z=>q(me=>Z?[...new Set([...me,de])]:me.filter(xe=>xe!==de))})]},de)),(L?p:A).includes("subagent")&&n.jsx("p",{className:"text-muted-foreground text-xs",children:r("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]})]}),t?.trustedProjectCode?.length?n.jsxs("div",{className:"flex items-start gap-3 rounded-lg border px-3 py-2.5",children:[n.jsx(Do,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium text-sm",children:r("Trusted project extensions")}),n.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",title:t.trustedProjectCode.join(`
|
|
104
|
-
`),children:t.trustedProjectCode.join(", ")}),te&&n.jsx("p",{className:"text-muted-foreground text-xs",children:r("No longer loaded after saving, starting with the next session.")})]}),n.jsx(fe,{type:"button",size:"xs",variant:"outline",disabled:te,onClick:()=>V(!0),children:r("Revoke trust")})]}):null]}),n.jsxs(ts,{children:[n.jsx(fe,{type:"button",variant:"outline",size:"sm",onClick:()=>s(!1),children:r("Cancel")}),n.jsx(fe,{type:"submit",size:"sm",disabled:!t,children:r("Save")})]})]})})})}function EQ({conversationId:e,running:t,hidden:s=!1}){const{t:r}=z(),{reminder:o,now:i}=Yd(e,!t&&!s);if(!o)return null;const a=Xd(o,i,r);return n.jsxs("span",{"data-enso":"sidebar-reminder-waiting",className:"inline-flex shrink-0 items-center gap-1 rounded bg-sky-500/15 px-1 py-px text-[10px] text-sky-600 tabular-nums dark:text-sky-400",title:a,children:[n.jsx(Uo,{className:"h-2.5 w-2.5 shrink-0","aria-hidden":!0}),n.jsx("span",{children:r("Waiting for reminder · {{time}}",{time:n1(o.dueAt)})})]})}const RQ=3e4;function MQ({conversationId:e}){const{t}=z(),s=om(d=>d.byConversation[e]),[r,o]=f.useState({runs:s,extraMs:0});if(f.useEffect(()=>{if(!s||s.length===0)return;const d=Date.now(),m=setInterval(()=>o({runs:s,extraMs:Date.now()-d}),RQ);return()=>clearInterval(m)},[s]),!s||s.length===0)return null;const i=r.runs===s?r.extraMs:0,a=s.reduce((d,m)=>m.elapsedMs>d.elapsedMs?m:d,s[0]),l=a.title||a.agentId.slice(0,8),c=Math.floor((a.elapsedMs+i)/6e4),u=s.length===1?c>=1?t("Waiting on subagent {{title}} ({{minutes}}m)",{title:l,minutes:c}):t("Waiting on subagent {{title}} (<1m)",{title:l}):c>=1?t("Waiting on {{n}} subagents ({{title}} · {{minutes}}m)",{n:s.length,title:l,minutes:c}):t("Waiting on {{n}} subagents ({{title}} · <1m)",{n:s.length,title:l});return n.jsxs("span",{"data-enso":"session-subagent-marker",className:"flex shrink-0 items-center gap-0.5 text-[10px] tabular-nums text-muted-foreground/80",title:u,children:[n.jsx(ws,{className:"h-3 w-3","aria-hidden":!0}),c>=1?`${c}m`:s.length]})}const PQ={connecting:"Connecting…","host-offline":"Desktop is offline",unauthorized:"Pairing expired",replaced:"Open in another page",offline:"Reconnecting…"};function DQ(e){return e==="online"?"ok":e==="connecting"||e==="offline"?"pending":"error"}function wI(e,t){if(e.state!=="online")return t(PQ[e.state]);const s=e.transport==="direct"?t("Direct link"):t("Via relay"),r=t3(e.rttMs);return r?`${t("Connected")} · ${s} · ${r}`:`${t("Connected")} · ${s}`}function OQ(){return"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window}function LQ(e){const t=e+"=".repeat((4-e.length%4)%4),s=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(s,r=>r.charCodeAt(0))}function _Q(e){return e==="AbortError"?"service-unreachable":e==="NotAllowedError"?"permission-denied":"subscribe-failed"}async function BQ(e){if(!OQ())return{ok:!1,reason:"unsupported"};if(await Notification.requestPermission()!=="granted")return{ok:!1,reason:"permission-denied"};const s=await navigator.serviceWorker.ready;try{const o=(await s.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:LQ(e)})).toJSON();return!o.endpoint||!o.keys?.p256dh||!o.keys?.auth?{ok:!1,reason:"subscribe-failed"}:{ok:!0,subscription:{endpoint:o.endpoint,keys:{p256dh:o.keys.p256dh,auth:o.keys.auth}}}}catch(r){const o=r instanceof Error?r.name:"";return{ok:!1,reason:_Q(o)}}}const jI="flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground disabled:opacity-40";function kI(){const e=window.electronAPI.remote,[t,s]=f.useState(null);return f.useEffect(()=>{if(!(!e?.linkStatus||!e.onLinkStatus))return s(e.linkStatus()),e.onLinkStatus(s)},[e]),t}function FQ(e,t){return e.pushError?t(NI[e.pushError]):e.pushAvailability==="needs-install"?t("Add this app to the Home Screen before notifications can be turned on."):e.pushAvailability==="unsupported"?t("This browser cannot show notifications."):e.pushReady?e.pushBusy?t("Turning on notifications…"):e.pushEnabled?t("Turn off notifications"):t("Turn on notifications"):t("Notifications need a newer desktop app.")}const NI={unsupported:"This browser cannot show notifications.","permission-denied":"Notification permission was denied. Allow notifications for this site and try again.","service-unreachable":"Cannot reach the push service. Check the network or proxy and try again.","subscribe-failed":"Could not turn on notifications."};function ew(){const{t:e}=z(),t=kI();if(!t)return null;const s=wI(t,e),r=FQ(t,e),o=t.pushBusy||t.pushAvailability!=="ok"||!t.pushReady||t.state!=="online"&&!t.pushEnabled;return n.jsxs(Ms,{children:[n.jsx(Ps,{className:jI,title:s,"aria-label":s,children:n.jsx(fl,{className:"h-4 w-4"})}),n.jsxs(Ds,{side:"top",align:"end",className:"w-64 [&_[data-slot=popover-viewport]]:px-3 [&_[data-slot=popover-viewport]]:py-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-md bg-background text-muted-foreground shadow-xs ring-1 ring-border",children:n.jsx(h1,{className:"size-3.5"})}),n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[n.jsx("span",{className:"truncate font-medium text-sm leading-4",children:t.deviceLabel}),n.jsx("span",{className:"truncate text-subtle-foreground text-xs leading-4",children:s})]})]}),n.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t pt-3",children:[n.jsx("span",{className:"text-sm",children:e("Push notifications")}),n.jsx(rr,{checked:t.pushEnabled,disabled:o,title:r,"aria-label":r,onCheckedChange:()=>{$Q(t)}})]}),t.pushError&&n.jsx("p",{className:"mt-2 text-destructive text-xs",children:e(NI[t.pushError])})]})]})}const zQ={ok:"bg-success",pending:"bg-warning",error:"bg-destructive"};function tw({compact:e=!1}){const{t}=z(),s=kI();if(!s)return null;const r=`${s.deviceLabel} · ${wI(s,t)}`,o=_("size-1.5 shrink-0 rounded-full",zQ[DQ(s.state)]);return n.jsxs("button",{type:"button",onClick:()=>window.electronAPI.remote?.openDevices?.(),title:r,"aria-label":`${t("Computers and notifications")} · ${r}`,className:e?_(jI,"relative"):"flex h-8 min-w-0 max-w-40 items-center gap-1.5 rounded-lg px-2 text-foreground text-sm transition-colors hover:bg-foreground/5",children:[n.jsx(h1,{className:"size-4 shrink-0 text-muted-foreground"}),e?n.jsx("span",{className:_(o,"absolute top-1.5 right-1.5")}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"truncate",children:s.deviceLabel}),n.jsx("span",{className:o})]})]})}async function $Q(e){const t=window.electronAPI.remote;if(!t?.setPushSubscription||!t.setPushPending)return;if(e.pushEnabled){t.setPushSubscription(null);return}const s=t.vapidPublicKey?.();if(!s)return;t.setPushPending({busy:!0,enabled:!0,error:null});const r=await BQ(s);if(!r.ok){t.setPushPending({busy:!1,enabled:!1,error:r.reason});return}t.setPushSubscription(r.subscription)}function VQ(e){return!e?.linkStatus||!e.onLinkStatus?null:e.openDevices?"devices":"info"}function HQ(e){return!!e?.exitDesk&&!e?.openDevices}const Ch="default";function WQ(e,t){return e&&!t}function UQ(e,t){return kt(s=>{const r=e??ZG(s.states,t??"")?.secretaryId??(s.secretaries.length===0||!t?s.focusedId??Ch:null);if(!r)return null;if(s.secretaries.length===0)return s.secretary.profile??void 0;const o=s.secretaries.find(a=>a.id===r);return o?(s.states[r]??(s.focusedId===r?s.secretary:null))?.profile??o:null})}function qQ({secretaryId:e=Ch,conversationId:t,muted:s=!1}){const{t:r}=z(),o=UQ(e===Ch?void 0:e,t),i=o?.name?.trim()||r("Secretary"),a=o===null?r("Dispatched by a deleted secretary"):r("Dispatched by {{name}}",{name:i}),l=s?r("{{label}} · muted",{label:a}):a,c=o?.avatar;return n.jsxs(bi,{children:[n.jsx(yi,{render:n.jsx("span",{"data-enso":"secretary-origin","data-secretary":e,"data-deleted":o===null||void 0,role:"img","aria-label":l,className:"flex size-3.5 shrink-0 items-center justify-center"}),children:o===null?n.jsx("span",{className:"flex size-3.5 items-center justify-center rounded-[4px] bg-muted text-subtle-foreground",children:n.jsx(nx,{className:"size-2.5","aria-hidden":!0})}):n.jsx(Fd,{name:i,color:c?.color,image:c?.imageVersion?ll(c.imageVersion,c.imageHash,e):void 0,enso:"secretary-origin-face",className:"size-3.5 rounded-[4px] text-[8px]"})}),n.jsx(wi,{side:"top",children:l})]})}function GQ(e){return e.kind==="session"?e.secretaryConversationId:e.kind==="pending"?e.pending.secretaryConversationId:e.proposal.secretaryConversationId}function SI(e,t){const s={},r=new Map,o=[];for(const a of e.running){const l=GQ(a);if(!l||!t(l)){o.push(a);continue}s[l]=(s[l]??0)+1;const c=r.get(l);c?c.push(a):r.set(l,[a])}const i=[...r].map(([a,l])=>({secretaryConversationId:a,cards:l}));return o.length>0&&i.push({secretaryConversationId:null,cards:o}),{counts:s,groups:i}}function KQ(e,t,s){const r={};for(const{id:o}of e){const i=t[o];i&&(r[o]=SI(i.board,s))}return r}function nw(e){return e.kind==="session"?`s:${e.conversationId}`:e.kind==="pending"?`p:${e.pending.id}`:`x:${e.proposal.id}`}function sw(e){if(e.kind==="session")return e.title;if(e.kind==="pending")return e.pending.draft.title}function YQ({count:e}){const{t}=z();return e?n.jsxs("span",{"data-enso":"secretary-dispatch-running",title:t("{{n}} dispatched tasks running",{n:e}),className:"inline-flex shrink-0 items-center gap-0.5 text-[10px] tabular-nums text-muted-foreground/70",children:[n.jsx(_t,{className:"h-3 w-3 animate-spin","aria-hidden":!0}),e]}):null}function XQ({label:e,groups:t,titleOf:s,onSelect:r}){const{t:o}=z();return n.jsxs(Ml,{children:[n.jsx(Pl,{render:n.jsx("span",{"data-enso":"secretary-running-origins",className:"shrink-0"}),children:e}),n.jsx(yu,{align:"start",className:"w-[260px] flex-col p-1 text-[12.5px]",onClick:i=>i.stopPropagation(),onDoubleClick:i=>i.stopPropagation(),children:t.map(i=>{const a=i.secretaryConversationId,l=a?s(a)||o("New conversation"):o("Unknown source"),c=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:l}),n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground tabular-nums",children:i.cards.length})]});return n.jsxs("div",{"data-enso":"secretary-running-origin",className:"py-0.5",children:[a?n.jsx("button",{type:"button",onClick:()=>r(a),className:"flex w-full items-center gap-2 rounded-md px-1.5 py-1 text-left hover:bg-foreground/5",children:c}):n.jsx("div",{className:"flex items-center gap-2 px-1.5 py-1 text-muted-foreground",children:c}),i.cards.map(u=>u.kind==="session"?n.jsx("button",{type:"button","data-enso":"secretary-running-origin-card",onClick:()=>kH(u.conversationId,void 0,a??void 0),className:"block w-full truncate rounded-md pr-1.5 pl-4 text-left text-[11.5px] text-muted-foreground hover:bg-foreground/5 hover:text-foreground",children:sw(u)||o("Unnamed")},nw(u)):n.jsx("div",{className:"truncate pr-1.5 pl-4 text-[11.5px] text-muted-foreground",children:sw(u)||o("Unnamed")},nw(u)))]},a??"")})})]})}function rw(e,t,s){if(!e.enabled)return null;const r=e.profile,o=r?.avatar.imageVersion,i=s??e.secretaryId??void 0,a=e.board.running.filter(l=>l.kind==="session"&&l.state==="queued").length;return{name:r?.name.trim()||t("Secretary"),needsYou:e.board.needsYou.length,running:e.board.running.length-a,queued:a,configured:r!==null,...r?{color:r.avatar.color}:{},...o?{image:ll(o,r?.avatar.imageHash,i)}:{}}}function QQ({view:e,runningExpanded:t,onToggleRunning:s,origins:r}){const{t:o}=z();if(!e.configured)return n.jsx(n.Fragment,{children:o("Click to finish setup")});const i=e.running+e.queued;if(e.needsYou===0&&i===0)return n.jsx(n.Fragment,{children:o("Nothing running")});const a=[...e.running>0?[o("{{n}} running",{n:e.running})]:[],...e.queued>0?[o("{{n}} queued",{n:e.queued})]:[]].join(" · ");return n.jsxs(n.Fragment,{children:[e.needsYou>0&&n.jsx("span",{"data-enso":"secretary-badge",className:"shrink-0 font-medium text-warning",children:o("{{n}} waiting",{n:e.needsYou})}),e.needsYou>0&&i>0&&" · ",i>0&&(s?n.jsx("button",{type:"button","data-enso":"secretary-running-toggle","aria-expanded":t??!1,onClick:s,className:"shrink-0 rounded px-0.5 transition-colors hover:text-foreground",children:a}):r?n.jsx(XQ,{label:a,...r}):n.jsx("span",{className:"shrink-0",children:a}))]})}const Uf="flex size-5 shrink-0 items-center justify-center rounded-[5px] text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground";function JQ({count:e,folded:t,needsYou:s,onToggleFold:r,onCreate:o}){const{t:i}=z();return n.jsxs("div",{"data-enso":"secretary-group","data-expanded":!t||void 0,className:"group flex w-full items-center gap-1 px-2 py-1",children:[n.jsxs("button",{type:"button","data-enso":"secretary-group-fold",onClick:r,"aria-expanded":!t,className:"flex min-w-0 flex-1 items-center gap-1 text-left text-[11.5px] font-medium text-muted-foreground",children:[n.jsx(Fn,{"data-enso":"secretary-group-chevron",className:_("size-3 shrink-0 text-subtle-foreground transition-[opacity,transform] duration-150",t?"-rotate-90 opacity-100":"opacity-70 group-hover:opacity-100")}),n.jsxs("span",{className:"truncate",children:[i("Secretary")," (",e,")"]})]}),t&&s>0&&n.jsx("span",{"data-enso":"secretary-badge",className:"shrink-0 text-[11px] font-medium text-warning",children:i("{{n}} waiting",{n:s})}),n.jsx("button",{type:"button","data-enso":"secretary-group-create",onClick:o,title:i("New secretary"),"aria-label":i("New secretary"),className:ZQ,children:n.jsx(Qn,{className:"size-3.5"})})]})}const ZQ="-my-0.5 flex size-5 shrink-0 items-center justify-center rounded-[5px] text-subtle-foreground opacity-0 transition-opacity hover:bg-foreground/5 hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100";function eJ(e){return e.filter(t=>t.kind!=="scratch"&&t.kind!=="secretary")}function ow({view:e,folded:t,onToggleFold:s,onOpen:r,onNewConversation:o,onOpenSettings:i,onReset:a,runningOrigins:l,divider:c=!0,secretaryId:u,keepAvatar:d=!1,children:m}){const{t:h}=z(),p=h(t?"Expand":"Collapse"),g=n.jsxs("div",{"data-enso":"secretary-row","data-expanded":!t||void 0,className:"group flex w-full items-center gap-2.5 rounded-[10px] px-2 py-1.5 transition-colors hover:bg-foreground/5",children:[n.jsxs("button",{type:"button","data-enso":"secretary-fold",onClick:s,"aria-expanded":!t,"aria-label":p,title:p,className:_("shrink-0 rounded-[9px]",d&&"relative"),children:[n.jsx("span",{className:_("block",!d&&(t?"hidden [@media(hover:none)]:block":"group-hover:hidden")),children:n.jsx($h,{name:e.name,color:e.color,image:e.image,needsYou:e.needsYou,running:e.running})}),n.jsx("span",{"data-enso":"secretary-fold-icon",className:_("size-7 items-center justify-center rounded-[9px] bg-muted text-muted-foreground [@media(hover:none)]:hidden!",d?"absolute inset-0 hidden group-hover:flex group-has-[:focus-visible]:flex":t?"flex":"hidden group-hover:flex"),children:n.jsx(Fn,{className:_("size-3.5",t&&"-rotate-90")})})]}),n.jsxs("button",{type:"button","data-enso":"secretary-open",onClick:()=>r(),title:e.name,className:"flex min-w-0 flex-1 flex-col items-start text-left",children:[n.jsx("span",{className:"block max-w-full truncate text-[13px] font-medium text-foreground",children:e.name}),n.jsx("span",{"data-enso":"secretary-summary",className:"mt-0.5 flex max-w-full min-w-0 items-center truncate text-[11.5px] text-muted-foreground",children:n.jsx(QQ,{view:e,origins:l})})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100",children:[n.jsx("button",{type:"button","data-enso":"secretary-action","data-action":"settings",onClick:i,title:h("Secretary settings"),"aria-label":h("Secretary settings"),className:Uf,children:n.jsx(Os,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button","data-enso":"secretary-action","data-action":"new",onClick:o,title:h("New conversation"),"aria-label":h("New conversation"),className:Uf,children:n.jsx(Qn,{className:"h-3.5 w-3.5"})})]}),n.jsx("button",{type:"button","data-enso":"secretary-fold-trailing",onClick:s,"aria-expanded":!t,"aria-label":p,title:p,className:_(Uf,"hidden [@media(hover:none)]:flex"),children:n.jsx(Fn,{className:_("h-3.5 w-3.5 transition-transform",t&&"-rotate-90")})})]});return n.jsxs("div",{"data-slot":"secretary-section","data-enso":"secretary-section","data-secretary-id":u,children:[n.jsxs(Yr,{children:[n.jsx(Xr,{render:g}),n.jsxs(Qr,{className:"min-w-40",children:[n.jsxs(Kt,{onClick:o,children:[n.jsx(Qn,{}),h("New conversation")]}),n.jsxs(Kt,{onClick:i,children:[n.jsx(Os,{}),h("Secretary settings")]}),n.jsxs(Kt,{onClick:a,children:[n.jsx(oo,{}),h("Re-run setup")]})]})]}),!t&&n.jsx("div",{className:"flex flex-col",children:m}),c&&n.jsx("div",{"data-enso":"secretary-divider",className:"mx-2 mt-1 border-t border-border"})]})}function tJ({view:e,onClick:t}){return n.jsx("button",{type:"button","data-enso":"secretary-collapsed",onClick:t,title:e.name,"aria-label":e.name,className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",children:n.jsx($h,{name:e.name,color:e.color,image:e.image,needsYou:e.needsYou,running:e.running,size:"xs"})})}function nJ(e,t){if(!e)return null;let s=null,r=Number.NEGATIVE_INFINITY;for(const o of t.order){const i=t.conversations[o];if(!i||i.projectId!==e||i.archived)continue;const a=i.lastActiveAt??0;a>r&&(s=o,r=a)}return s}function iw(e,t,s){return e?Eo(t,s,e):[]}function Hc(e){const t=typeof e=="string"&&e.length>0?e:void 0,s=kt.getState(),r=J.getState(),o=t?s.secretaries.filter(d=>d.id===t):s.secretaries;let i=null;for(const d of o){const m=nJ(d.projectId,r);if(!m)continue;const h=r.conversations[m]?.lastActiveAt??0;(!i||h>i.at)&&(i={id:d.id,conversationId:m,at:h})}if(i){s.focus(i.id),r.selectConversation(i.conversationId);return}const a=t??s.focusedId??s.secretaries[0]?.id;if(!a)return;s.focus(a);const l=kt.getState(),c=l.states[a],u=l.secretaries.find(d=>d.id===a);if(c?.projectId??u?.projectId){if(c?!c.profile:u?.name==null){kt.getState().openWelcome();return}kt.getState().newSecretaryConversation({secretaryId:a})}}const il=5,CI=15,aw=9;function al(e,t){return e<=0?0:Math.min(e,il+Math.max(0,t))}function lw(e,t){return al(e,t)>=e?0:Math.min(Math.max(0,e-il),t+CI)}function cw(e){return Math.max(0,e-CI)}function sJ(e){const{order:t,conversations:s,pinnedOrderIds:r=[],projectIds:o,archivedProjectIds:i=[],collapsedProjects:a={},revealedExtras:l={},searching:c=!1,matches:u=()=>!0,projectMatches:d=()=>!1,leadingIds:m=[]}=e,h=[],p=new Set,g=v=>{p.has(v)||h.length>=aw||(p.add(v),h.push(v))};for(const v of m)g(v);const x=p1(t,s,r,i);for(const v of c?x.filter(u):x)g(v);for(const v of o){if(h.length>=aw)break;if(c?!1:a[v]===!0)continue;const w=Eo(t,s,v),j=!c||d(v)?w:w.filter(u),T=c?j:j.slice(0,al(j.length,l[v]??0));for(const N of T)g(N)}return h}function eg(e,t){const s=new Map(e.map(o=>[o.id,o])),r=[];for(const o of t){const i=s.get(o);i&&(r.push(i),s.delete(o))}for(const o of e)s.has(o.id)&&r.push(o);return r}function hc(e,t,s,r){const o=eg(e,t).map(l=>l.id),i=o.indexOf(s),a=o.indexOf(r);return i===-1||a===-1||i===a||(o.splice(i,1),o.splice(a,0,s)),o}function rJ(e,t){const s=new Map(e.map(i=>[i.id,i])),r=[],o=new Set;for(const i of t){const a=s.get(i);a&&(r.push(a),o.add(i))}return{pinned:r,rest:e.filter(i=>!o.has(i.id))}}function oJ(e,t){return e.includes(t)?e.filter(s=>s!==t):[t,...e]}function iJ(e,t,s){const r=s.includes(e),o=s.includes(t);return r&&o?"pinned":!r&&!o?"order":null}function qf(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function dw(e){return e==="browser"||typeof e=="string"&&e.startsWith("browser:")}function aJ(e){if(typeof e.contentComponent=="string")return e.contentComponent;if(typeof e.component=="string")return e.component}function uw(e){if(!qf(e)||!qf(e.panels))return{browsers:0,terminals:0};let t=0,s=0;for(const[r,o]of Object.entries(e.panels)){if(!qf(o))continue;const i=aJ(o);i==="browser"||dw(o.id)||dw(r)?t+=1:i==="terminal"&&(s+=1)}return{browsers:t,terminals:s}}function lJ({conversationId:e}){const{t}=z(),s=os(o=>uw(o.layouts[e]).browsers),r=os(o=>uw(o.layouts[e]).terminals);return s===0&&r===0?null:n.jsxs("span",{"data-slot":"session-tab-counts",className:"flex shrink-0 items-center gap-1.5 text-[10px] tabular-nums text-muted-foreground/70",children:[s>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5",title:t("{{n}} browsers",{n:s}),children:[n.jsx(Oo,{className:"h-3 w-3","aria-hidden":!0}),s]}),r>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5",title:t("{{n}} terminals",{n:r}),children:[n.jsx($o,{className:"h-3 w-3","aria-hidden":!0}),r]})]})}const cJ="absolute right-1.5 bottom-0.5 flex size-5 items-center justify-center rounded-[5px] opacity-0 transition-opacity hover:bg-foreground/5 hover:text-foreground group-hover:opacity-100 [@media(hover:none)]:static [@media(hover:none)]:-my-[9px] [@media(hover:none)]:-mr-1.5 [@media(hover:none)]:ml-0.5 [@media(hover:none)]:size-[32px] [@media(hover:none)]:opacity-100",dJ="shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:bg-muted hover:text-foreground focus-visible:opacity-100 [@media(hover:none)]:flex [@media(hover:none)]:size-[32px] [@media(hover:none)]:items-center [@media(hover:none)]:justify-center [@media(hover:none)]:opacity-100",uJ="shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:bg-muted hover:text-foreground focus-visible:opacity-100 data-popup-open:bg-muted data-popup-open:text-foreground data-popup-open:opacity-100 [@media(hover:none)]:flex [@media(hover:none)]:size-[32px] [@media(hover:none)]:items-center [@media(hover:none)]:justify-center [@media(hover:none)]:opacity-100",fJ=[7,15,30],ra="h-6.5 rounded-lg px-2 text-xs text-subtle-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",fw="enso-collapsed-scratch",Gf="enso-collapsed-secretary",mw="enso-collapsed-secretary-group",hw="enso-collapsed-secretaries",pc=3,zs="flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",Kf="-my-0.5 flex size-5 shrink-0 items-center justify-center rounded-[5px] text-subtle-foreground opacity-0 transition-opacity hover:bg-foreground/5 hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100";function pw({width:e,collapsed:t,onToggleCollapse:s,onOpenSearch:r,onNavigate:o}){const{t:i,locale:a}=z(),l=pe(O=>O.projects),u=up()==="mobile",d=VQ(window.electronAPI.remote),m=HQ(window.electronAPI.remote),h=pe(O=>O.scratchSessionsEnabled),p=pe(O=>O.projectGroups),g=pe(O=>O.createProjectGroup),x=pe(O=>O.updateProjectGroup),v=pe(O=>O.removeProjectGroup),b=pe(O=>O.reorderProjectGroups),w=pe(O=>O.setProjectGroupId),j=pe(O=>O.keybindings),T=pe(O=>O.activeRetentionMinutes),N=pe(O=>O.headerRecentMinutes),S=hs(O=>O.dismissed),I=Pr(j)["search-workspace"],k=I?qs(I):"",L=pe(O=>O.addProject),F=pe(O=>O.removeProject),A=J(O=>fu(O.conversations)),M=J(O=>O.order),R=J(O=>O.activeId),$=J(O=>O.newConversation),U=J(O=>O.selectConversation),q=f.useRef(o);q.current=o;const te=f.useCallback(O=>{q.current?.(),JN(),U(O)},[U]),V=J(O=>O.removeConversation),se=J(O=>O.togglePinConversation),Ce=J(O=>O.toggleArchiveConversation),de=J(O=>O.moveConversationToWorktree),re=J(O=>O.cleanupWorktree),Z=J(O=>O.refreshWorktreeStatuses),me=J(O=>O.worktreeStatuses),[xe,Se]=f.useState(()=>{try{return JSON.parse(localStorage.getItem("enso-collapsed-projects")??"{}")}catch{return{}}}),W=O=>{Se(le=>{const Ue={...le,[O]:!le[O]};return localStorage.setItem("enso-collapsed-projects",JSON.stringify(Ue)),Ue})},[H,B]=f.useState(()=>{try{return localStorage.getItem(fw)==="1"}catch{return!1}}),ne=O=>{try{localStorage.setItem(fw,O?"1":"0")}catch{}},ve=()=>{B(O=>{const le=!O;return ne(le),le})},he=()=>{B(O=>O&&(ne(!1),!1))},[G,we]=f.useState(()=>sr(Mc)),ce=eg(eJ(l),G),Re=l.find(O=>O.kind==="scratch"),ue=kt(O=>O.secretary),We=kt(O=>O.secretaries),it=kt(O=>O.states),Fe=We.length>1,tt=f.useMemo(()=>rw(ue,i),[ue,i]),ke=f.useMemo(()=>Fe?We.flatMap(O=>{const le=it[O.id],Ue=le?rw(le,i,O.id):null;return Ue?[{id:O.id,projectId:O.projectId,view:Ue}]:[]}):[],[Fe,We,it,i]),nt=f.useMemo(()=>{const O=le=>A[le]!==void 0;return{single:SI(ue.board,O),byId:Fe?KQ(We,it,O):{}}},[Fe,We,it,ue.board,A]),mt=O=>O&&{groups:O.groups,titleOf:le=>A[le]?.title,onSelect:te},[X,K]=f.useState(()=>{try{return localStorage.getItem(mw)==="1"}catch{return!1}}),Ee=()=>{K(O=>{try{localStorage.setItem(mw,O?"0":"1")}catch{}return!O})},[pt,Pt]=f.useState(()=>{try{const O=localStorage.getItem(hw),le=O?JSON.parse(O):[];return Array.isArray(le)&&le.length===0&&localStorage.getItem(Gf)==="1"?["default"]:Array.isArray(le)?le.filter(Ue=>typeof Ue=="string"):[]}catch{return[]}}),Je=O=>{Pt(le=>{const Ue=le.includes(O)?le.filter(ot=>ot!==O):[...le,O];try{localStorage.setItem(hw,JSON.stringify(Ue))}catch{}return Ue})},[Lt,on]=f.useState(()=>{try{return localStorage.getItem(Gf)==="1"}catch{return!1}}),Pe=()=>{on(O=>{try{localStorage.setItem(Gf,O?"0":"1")}catch{}return!O})},[Dt,Vt]=f.useState(!1),[Et,oe]=f.useState(null),Le=f.useMemo(()=>iw(ue.projectId,M,A),[M,A,ue.projectId]),st=Dt?Le:Le.slice(0,pc),[at,gt]=f.useState(()=>sr(jr));f.useEffect(()=>P8(()=>Se(Um())),[]),f.useEffect(()=>VN(()=>{gt(sr(jr))}),[]);const[xt,zt]=f.useState(()=>sr(Fv)),Wt=O=>{zt(O),Hr(Fv,O)},an=O=>{if(Wt(oJ(xt,O)),!xt.includes(O)&&at.includes(O)){const le=at.filter(Ue=>Ue!==O);gt(le),Hr(jr,le)}},en=O=>{const le=at.includes(O)?at.filter(Ue=>Ue!==O):[...at,O];gt(le),Hr(jr,le),!at.includes(O)&&xt.includes(O)&&Wt(xt.filter(Ue=>Ue!==O))},[Bt,pn]=f.useState(()=>{try{return localStorage.getItem("enso-selected-project-group")??Yn}catch{return Yn}}),[Gn,vt]=f.useState(()=>{try{return JSON.parse(localStorage.getItem("enso-collapsed-project-groups")??"{}")}catch{return{}}}),sn=O=>{pn(O),localStorage.setItem("enso-selected-project-group",O)},Rn=O=>{vt(le=>{const Ue={...le,[O]:!le[O]};return localStorage.setItem("enso-collapsed-project-groups",JSON.stringify(Ue)),Ue})},C=Bt===Yn||Bt===kr||Bt===Ts||p.some(O=>O.id===Bt)?Bt:Yn,D=C===kr,P=p.find(O=>O.id===C)?.id,y=Ki(ce,p,at,C),E=n3(Ki(ce,p,at,Yn),M,A,Date.now()),{pinned:Y,rest:ee}=D?{pinned:[],rest:E}:rJ(y,xt),ge=s3(ee,p,[]),Te=[...Y,...ee],Ve=Te.map(O=>O.id),He=new Set(Ve),[bt,Xe]=f.useState(()=>sr(Vm)),{active:ae}=gl(),Ne=ae?.data.current;j1({onDragEnd:O=>{const le=O.active.data.current;if(!le)return;const Ue=O.over?String(O.over.id):null,ot=KK(le,Ue,R??void 0,{projectGroupId:yt=>l.find(vn=>vn.id===yt)?.groupId});if(ot)switch(ot.kind){case"move-project-to-group":{if(D&&ot.beforeProjectId)break;if(w(ot.projectId,ot.groupId),ot.beforeProjectId){const yt=hc(l,G,ot.projectId,ot.beforeProjectId);we(yt),Hr(Mc,yt)}break}case"reorder-groups":b(ot.activeId,ot.overId);break;case"reorder-projects":{if(D)break;const yt=iJ(ot.activeId,ot.overId,xt);if(yt==="pinned"){const rs=hc(xt.map($r=>({id:$r})),xt,ot.activeId,ot.overId);Wt(rs);break}if(yt!=="order")break;const vn=hc(l,G,ot.activeId,ot.overId);we(vn),Hr(Mc,vn);break}case"insert-file-mention":Bv({kind:"file",id:ot.path,label:ot.label,relativePath:ot.path});break;case"insert-chat-mention":Bv({kind:"chat",id:ot.conversationId,label:ot.label,sessionFile:ot.sessionFile});break;case"pin-conversation":se(ot.conversationId);break;case"reorder-pinned":{const yt=hc(Nn.map(vn=>({id:vn})),bt,ot.activeId,ot.overId);Xe(yt),Hr(Vm,yt);break}}}});const[_e,Be]=f.useState(null),[Ze,ft]=f.useState(null),[ht,ze]=f.useState(!1),[Qe,Ke]=f.useState(!1),[et,lt]=f.useState(null),Ye=O=>{if(!O.sshConnectionId){qN(O.path,{groupId:O.groupId??P,onSelect:te}).catch(Ue=>{Ie({type:"error",title:i("Failed to add project"),description:Ue instanceof Error?Ue.message:String(Ue)})});return}const le=new Set(l.map(Ue=>Ue.id));lt({name:Qj(O.path),path:O.path,sshHost:O.sshHost}),L(O.path,{sshConnectionId:O.sshConnectionId},O.groupId??P).then(Ue=>{if(Ue){if(at.includes(Ue.id)){const ot=at.filter(yt=>yt!==Ue.id);gt(ot),Hr(jr,ot)}if(le.has(Ue.id)){Se(yt=>{if(yt[Ue.id]!==!0)return yt;const vn={...yt,[Ue.id]:!1};return localStorage.setItem("enso-collapsed-projects",JSON.stringify(vn)),vn});const ot=Eo(M,A,Ue.id)[0];if(ot){te(ot);return}}$(Ue.id)}}).catch(Ue=>{Ie({type:"error",title:i("Failed to add project"),description:Ue instanceof Error?Ue.message:String(Ue)})}).finally(()=>lt(null))},[be,ye]=f.useState(null),[Me,Ae]=f.useState(null),[je,De]=f.useState(null),dt=async O=>{const le=A[O];let Ue;if(le?.worktree){const ot=await Pu(O);wc(ot)&&(Ue=gg(ot))}De({kind:"conversation",id:O,worktreeWarning:Ue})},[Nt,Rt]=f.useState({}),[Ct,Q]=f.useState(0),[It,qt]=f.useState(""),Gt=hs(O=>O.modHeld),Tt=f.useCallback(O=>{hs.setState({modHeld:O})},[]),[At,Ut]=f.useState(()=>Date.now());f.useEffect(()=>{const O=setInterval(()=>Ut(Date.now()),r3);return()=>clearInterval(O)},[]);const jn={now:At,ms:T*6e4},Qt=pp(O=>O.byConversation),gn=new Set(Object.keys(Qt).filter(O=>x1(Qt[O]??[],At))),xn=o3(M,A,at,jn,gn),kn=O=>{const le=bw(l,A[O].projectId),Ue=f3(O,A,jn,gn);if(Ue===void 0)return le;const ot=i("Stays in Active for about {{count}} more min",{count:Math.ceil(Ue/6e4)});return le?`${le}
|
|
105
|
-
${ot}`:ot},Nn=p1(M,A,bt,at),Tn=i3(M,A,ce.map(O=>O.id),at).filter(O=>h||O.projectId!==Re?.id),Xt=It.trim().length>0,An=O=>ta(It,[A[O]?.title||i("New conversation")]),fo=Re?Eo(M,A,Re.id).filter(O=>!Xt||An(O)):[],Ol=Xt?!1:H,rg=Xt?fo.length:al(fo.length,Ct),Ll=fo.slice(rg),_l=O=>{const le=A[O]?.projectId;return!le||He.has(le)},Bl=(Xt?xn.filter(An):xn).filter(_l),VI=sJ({order:M,conversations:A,pinnedOrderIds:bt,projectIds:Ve,archivedProjectIds:at,collapsedProjects:xe,revealedExtras:Nt,searching:Xt,matches:An,projectMatches:O=>{const le=ce.find(Ue=>Ue.id===O);return!!(le&&ta(It,[le.alias??"",le.name,le.path]))},leadingIds:Bl}),Fl=a3(xn.filter(_l),M,A,at,{now:At,ms:N*6e4},_l,S);R&&A[R]&&!A[R].parentId&&(Fl.includes(R)||Fl.push(R));const zl=hs(O=>O.headerMounted)?Fl.slice(0,9):VI,og=f.useRef(zl);og.current=zl,f.useEffect(()=>n8(Fl,zl));const $l=(Xt?Nn.filter(An):Nn).filter(_l),HI=new Set($l),WI=new Set(Bl),Ko=(O,le)=>{if(t||!Gt)return;const Ue=zl.indexOf(O);if(!(Ue<0||(WI.has(O)?"active":HI.has(O)?"pinned":"project")!==le))return qs(`mod+${Ue+1}`)},[UI,Tu]=f.useState(!1),[qi,ig]=f.useState(""),[ag,lg]=f.useState(null),Br=eQ(C,p),[cg,Vl]=f.useState(null),Qs=cg??Br,Au={projects:l,projectGroups:p,conversations:A},qI=qi.trim()?Tn.map(O=>{const le=l.find(ot=>ot.id===O.projectId);return O.projectArchived===!0&&!!(le&&ta(qi,[le.alias??"",le.name,le.path]))?O:{...O,ids:O.ids.filter(ot=>ta(qi,[A[ot]?.title||i("New conversation")]))}}).filter(O=>O.ids.length>0):Tn,dg=Hf(qI,Qs,Au),ug=Yy(Hf(Tn,Br,Au)),GI=Yy(Hf(Tn,Qs,Au)),fg=tQ(Tn,A),mg=O=>(Fe?ke.find(le=>le.id===O)?.view.name:tt?.name)??i("Secretary"),hg=Br.kind==="group"?p.find(O=>O.id===Br.groupId)?.name??"":Br.kind==="ungrouped"?i("Ungrouped"):i("All archived"),KI=Qs.kind==="group"?i("Archived in group “{{name}}”",{name:hg}):Qs.kind==="ungrouped"?i("Archived in ungrouped projects"):Qs.kind==="secretary"?i("Archived sessions dispatched by {{name}}",{name:mg(Qs.secretaryId)}):Qs.fallbackFrom==="recent"?i("“Recent” has no archive scope; showing all archived"):i("Showing all archived"),pg=()=>{ig(""),Vl(null),Tu(!0)};f.useEffect(()=>{C!==Bt&&(pn(Yn),localStorage.setItem("enso-selected-project-group",Yn))},[C,Bt]),f.useEffect(()=>{const O=yt=>{const rs=(qg?yt.metaKey:yt.ctrlKey)&&!yt.shiftKey&&!yt.altKey;if(Tt(rs),!rs||yt.repeat)return;const $r=Number(yt.key);if($r<1||$r>9)return;const po=og.current[$r-1];po&&(yt.preventDefault(),te(po))},le=yt=>{const vn=qg?yt.metaKey:yt.ctrlKey;Tt(vn&&!yt.shiftKey&&!yt.altKey)},Ue=()=>Tt(!1),ot=()=>{document.hidden&&Ue()};return window.addEventListener("keydown",O),window.addEventListener("keyup",le),window.addEventListener("blur",Ue),document.addEventListener("visibilitychange",ot),()=>{window.removeEventListener("keydown",O),window.removeEventListener("keyup",le),window.removeEventListener("blur",Ue),document.removeEventListener("visibilitychange",ot)}},[te,Tt]),f.useEffect(()=>{Z();const O=setInterval(()=>{Z()},3e4),le=()=>{Z()};return window.addEventListener("focus",le),()=>{clearInterval(O),window.removeEventListener("focus",le)}},[Z]);const[mo,Eu]=f.useState(null),[Ru,Mu]=f.useState(null),Pu=async O=>{const le=await window.electronAPI.worktree.status(O);return le.ok?le.value:void 0},Du=async(O,le)=>{const Ue=await re(O);if(Ue){Ie({type:"error",title:i("Failed to clean up worktree"),description:Ue});return}le&&Ce(O),Z()},ho=async O=>{const le=await Pu(O);if(wc(le)){Eu({kind:"cleanup",id:O,status:le});return}await Du(O,!1)},Fr=async O=>{const le=A[O];if(!le)return;if(le.archived||!le.worktree){Ce(O);return}const Ue=await Pu(O);if(wc(Ue)){Eu({kind:"archive",id:O,status:Ue});return}await Du(O,!0)},xg=async O=>{for(const le of O)!A[le]||A[le].archived||await Fr(le)},zr=async(O,le=!1)=>{const Ue=await de(O,{allowDirtyMainTree:le});if(Ue===d1){Mu(O);return}if(Ue){Ie({type:"error",title:i("Failed to move to worktree"),description:Ue});return}Z()},gg=O=>{const le=[];return O?.dirty&&le.push(i("Uncommitted changes")),O&&O.ahead>0&&le.push(i("{{n}} unmerged commits (branch is kept)",{n:O.ahead})),le.join("; ")};return n.jsxs(Ns.aside,{initial:!1,animate:{width:t?48:e},transition:gi,"data-enso":"sidebar",className:"flex shrink-0 flex-col overflow-hidden",children:[t&&n.jsxs("div",{className:"flex w-full flex-1 flex-col items-center gap-1 py-2",children:[(Fe?ke.length>0:tt)&&n.jsx(tJ,{view:Fe&&ke[0]?{...ke[0].view,needsYou:ke.reduce((O,le)=>O+le.view.needsYou,0),running:ke.reduce((O,le)=>O+le.view.running,0)}:tt,onClick:()=>Hc()}),n.jsx("button",{type:"button",onClick:()=>ze(!0),className:zs,title:i("Add project"),children:n.jsx(Fm,{className:"h-4 w-4"})}),n.jsx("div",{className:"flex-1"}),d==="devices"&&n.jsx(tw,{compact:!0}),d==="info"&&n.jsx(ew,{}),n.jsx(Qy,{className:zs}),n.jsx(Zy,{count:ug,onClick:pg,className:zs}),m&&n.jsx("button",{type:"button",onClick:()=>window.electronAPI.remote?.exitDesk?.(),className:zs,title:i("Compact view"),children:n.jsx(Wg,{className:"h-4 w-4"})}),n.jsx("button",{type:"button","data-enso":"settings-button",onClick:()=>window.electronAPI.window.openSettings(),className:zs,title:i("Settings"),children:n.jsx(Os,{className:"h-4 w-4"})})]}),n.jsxs("div",{className:_("flex h-full min-h-0 flex-col",u&&"pt-3",t&&"hidden"),style:{width:e},children:[n.jsx(mQ,{groups:p,selectedId:C,counts:Object.fromEntries(p.map(O=>[O.id,Ki(ce,p,at,O.id).length])),totalCount:Ki(ce,p,at,Yn).length,recentCount:E.length,ungroupedCount:Ki(ce,p,at,Ts).length,query:It,onQueryChange:qt,searchOpen:Qe,onSearchOpenChange:Ke,onSelect:sn,onAddGroup:()=>Be({mode:"create"}),onEditGroup:O=>Be({mode:"edit",id:O})}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pt-0.5 pb-2 pl-1.5 [scrollbar-gutter:stable]",children:[Fe&&ke.length>0?n.jsxs("div",{children:[n.jsx(JQ,{count:ke.length,folded:X,needsYou:ke.reduce((O,le)=>O+le.view.needsYou,0),onToggleFold:Ee,onCreate:()=>{kt.getState().createSecretary()}}),!X&&ke.map((O,le)=>{const Ue=pt.includes(O.id),ot=iw(O.projectId,M,A),yt=Ue?[]:ot.slice(0,pc);return n.jsx(ow,{view:O.view,folded:Ue,divider:le===ke.length-1,onToggleFold:()=>Je(O.id),onOpen:()=>Hc(O.id),onNewConversation:()=>{kt.getState().newSecretaryConversation({secretaryId:O.id})},onOpenSettings:()=>l3(O.id),onReset:()=>oe(O.id),secretaryId:O.id,keepAvatar:!0,runningOrigins:mt(nt.byId[O.id]),children:yt.map(vn=>n.jsx(wo,{id:vn,conversation:A[vn],active:R===vn,dispatchRunning:nt.byId[O.id]?.counts[vn],switchHint:Ko(vn,"project"),locale:a,nowTick:At,hoverTitle:O.view.name,onSelect:te,onTogglePin:se,onToggleArchive:rs=>{Fr(rs)},onCleanupWorktree:rs=>{ho(rs)},onMoveToWorktree:rs=>{zr(rs)},onRemove:rs=>{dt(rs)}},vn))},O.id)})]}):tt&&n.jsxs(ow,{view:tt,folded:Lt,onToggleFold:Pe,onOpen:Hc,onNewConversation:()=>{kt.getState().newSecretaryConversation()},onOpenSettings:()=>{window.electronAPI.window.openSettings({category:"secretary",rowId:"secretary.root"})},onReset:()=>oe("default"),runningOrigins:mt(nt.single),children:[st.map(O=>n.jsx(wo,{id:O,conversation:A[O],active:R===O,dispatchRunning:nt.single.counts[O],switchHint:Ko(O,"project"),locale:a,nowTick:At,hoverTitle:tt.name,onSelect:te,onTogglePin:se,onToggleArchive:le=>{Fr(le)},onCleanupWorktree:le=>{ho(le)},onMoveToWorktree:le=>{zr(le)},onRemove:le=>{dt(le)}},O)),!Lt&&Le.length>pc&&n.jsx("div",{className:"flex items-center gap-1 px-2",children:n.jsx("button",{type:"button",onClick:()=>Vt(O=>!O),className:ra,children:Dt?i("Collapse"):i("Show {{n}} more",{n:Le.length-pc})})})]}),ce.length===0&&n.jsx("button",{type:"button",onClick:()=>ze(!0),className:"mt-2 w-full rounded-lg border border-dashed px-3 py-6 text-center text-sm text-muted-foreground transition-colors hover:border-brand/50 hover:text-foreground",children:i("Add a project to start")}),ce.length===0&&h&&Re&&n.jsx("button",{type:"button",onClick:()=>{he(),$(Re.id)},className:"mt-1 w-full rounded-lg px-3 py-2 text-center text-sm text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",children:i("Start a temporary chat")}),Bl.length>0&&n.jsxs("div",{"data-slot":"active-section",children:[n.jsx(oa,{section:"active",children:i("Active")}),n.jsx("div",{className:"flex flex-col",children:Bl.map(O=>n.jsx(gw,{id:O,dragId:qK(O),conversation:A[O],children:n.jsx(wo,{id:O,conversation:A[O],active:R===O,switchHint:Ko(O,"active"),locale:a,nowTick:At,hoverTitle:kn(O),worktreeStatus:A[O].worktree?me[O]:void 0,isolated:!!A[O].worktree,onSelect:te,onTogglePin:se,onToggleArchive:le=>{Fr(le)},onCleanupWorktree:le=>{ho(le)},onMoveToWorktree:le=>{zr(le)},onRemove:le=>{dt(le)}})},O))})]}),Nn.length===0&&Ne?.type==="chat"&&!Ne.pinned&&n.jsx(vw,{children:n.jsxs("div",{className:"flex items-center justify-center gap-1.5 rounded-lg border border-dashed px-2 py-2 text-xs text-muted-foreground",children:[n.jsx(Ss,{className:"h-3.5 w-3.5"}),i("Drop here to pin")]})}),$l.length>0&&n.jsxs(vw,{"data-slot":"pinned-section",children:[n.jsx(oa,{section:"pinned",children:i("Pinned")}),n.jsx("div",{className:"flex flex-col",children:n.jsx(Nh,{items:$l.map(O=>U2(O)),strategy:Ky,children:$l.map(O=>n.jsx(gJ,{id:O,conversation:A[O],children:n.jsx(wo,{id:O,conversation:A[O],active:R===O,switchHint:Ko(O,"pinned"),locale:a,nowTick:At,hoverTitle:bw(l,A[O].projectId),worktreeStatus:A[O].worktree?me[O]:void 0,isolated:!!A[O].worktree,onSelect:te,onTogglePin:se,onToggleArchive:le=>{Fr(le)},onCleanupWorktree:le=>{ho(le)},onMoveToWorktree:le=>{zr(le)},onRemove:le=>{dt(le)}})},O))})})]}),h&&Re&&n.jsxs("div",{"data-slot":"scratch-section",children:[n.jsxs("div",{"data-enso":"section-header","data-section":"scratch",className:"group flex items-center gap-1 pt-3.5 pr-1 pb-1 pl-2 text-[0.8214rem] font-medium text-subtle-foreground",children:[n.jsxs("button",{type:"button",onClick:ve,"aria-expanded":!Ol,className:"flex min-w-0 flex-1 items-center gap-1 text-left transition-colors hover:text-foreground",children:[n.jsx("span",{className:"min-w-0 truncate",children:i("Temporary chats")}),n.jsx(fn,{"data-enso":"tree-chevron","data-expanded":!Ol||void 0,className:_("size-3 shrink-0 text-subtle-foreground transition-[opacity,transform] duration-150",Ol?"opacity-100":"rotate-90 opacity-70 group-hover:opacity-100")}),n.jsx("span",{className:"ml-auto shrink-0 font-normal text-[0.7857rem] tabular-nums",children:fo.length})]}),n.jsx("button",{type:"button",className:Kf,title:i("Start a temporary chat"),"aria-label":i("Start a temporary chat"),onClick:()=>{he(),$(Re.id)},children:n.jsx(Qn,{className:"size-3.25"})})]}),n.jsx(ya,{initial:!1,children:!Ol&&n.jsx(Ns.div,{initial:"initial",animate:"animate",exit:"exit",variants:If,className:"overflow-hidden",children:n.jsxs("div",{className:"flex flex-col",children:[fo.slice(0,rg).map(O=>n.jsx(wo,{id:O,conversation:A[O],active:R===O,switchHint:Ko(O,"project"),locale:a,nowTick:At,onSelect:te,onTogglePin:se,onToggleArchive:le=>{Fr(le)},onCleanupWorktree:le=>{ho(le)},onMoveToWorktree:le=>{zr(le)},onRemove:le=>{dt(le)}},O)),!Xt&&fo.length>il&&n.jsxs("div",{className:"flex items-center gap-1 pl-2",children:[Ll.length>0&&n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsx("button",{type:"button",onClick:()=>Q(O=>lw(fo.length,O)),className:ra,children:i("Show {{n}} more",{n:Ll.length})})}),n.jsx(Qr,{className:"min-w-36",children:n.jsxs(Kt,{onClick:()=>{xg(Ll)},children:[n.jsx(lr,{}),i("Archive {{n}} conversations",{n:Ll.length})]})})]}),Ct>0&&n.jsx("button",{type:"button",onClick:()=>Q(cw),className:ra,children:i("Collapse")})]})]})},"scratch-conversations")})]}),ce.length>0&&n.jsx(oa,{section:"projects",actions:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:()=>Ke(!0),className:_(Kf,(Qe||Xt)&&"bg-foreground/5 text-foreground opacity-100"),title:i("Search conversations..."),"aria-label":i("Search conversations..."),children:n.jsx(MN,{className:"size-3.25"})}),n.jsx("button",{type:"button",onClick:()=>ze(!0),className:Kf,title:i("Add project"),"aria-label":i("Add project"),children:n.jsx(Qn,{className:"size-3.25"})})]}),children:i("Projects")}),et&&n.jsxs("div",{className:"flex h-8 w-full items-center gap-2 rounded-lg px-2 text-muted-foreground",children:[n.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:n.jsx(_t,{className:"size-4 animate-spin"})}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-[0.9286rem] font-medium",title:et.path,children:[et.name,et.sshHost&&n.jsx("span",{className:"ml-1.5 rounded bg-muted px-1 py-0.5 text-[10px] font-normal",children:et.sshHost})]}),n.jsx("span",{className:"shrink-0 text-xs",children:i("Adding...")})]}),n.jsx(Nh,{items:[...C===Yn?ge.map(O=>O.groupId===Ts?Kx:W2(O.groupId)):[],...Ve.map(O=>H2(O))],strategy:Ky,children:(()=>{const O=le=>{const Ue=Eo(M,A,le.id),ot=ta(It,[le.alias??"",le.name,le.path]),yt=!Xt||ot?Ue:Ue.filter(An);if(Xt&&yt.length===0)return null;const vn=Xt?!1:xe[le.id]===!0,rs=Nt[le.id]??0,$r=Xt?yt.length:al(yt.length,rs),po=yt.slice($r),Yo=xt.includes(le.id),vg=[{kind:"item",key:"pin",label:i(Yo?"Unpin project":"Pin project"),icon:Yo?n.jsx(vd,{}):n.jsx(Ss,{}),onSelect:()=>an(le.id)},{kind:"item",key:"settings",label:i("Project settings"),icon:n.jsx(Os,{}),onSelect:()=>ft(le.id)},...le.kind!=="ssh"?[{kind:"item",key:"reveal",label:i(Qx(window.electronAPI.env.platform)),icon:n.jsx(Lr,{}),onSelect:()=>Jx({projectId:le.id},i)}]:[],{kind:"item",key:"import",label:i("Import session"),icon:n.jsx(m3,{}),onSelect:()=>ye(le)},...le.kind!=="scratch"&&le.kind!=="secretary"?[{kind:"item",key:"import-project-sessions",label:i("Import conversations from another project…"),icon:n.jsx(IN,{}),onSelect:()=>Ae(le)}]:[],{kind:"separator",key:"sep-group"},{kind:"submenu",key:"move-to-group",label:i("Move to group"),icon:n.jsx(Yf,{}),items:[{kind:"item",key:"ungrouped",label:i("Ungrouped"),icon:n.jsx(Yf,{}),onSelect:()=>w(le.id,null)},...p.map(gr=>({kind:"item",key:`group-${gr.id}`,label:gr.name,icon:n.jsx(Yf,{emoji:gr.emoji,color:gr.color}),onSelect:()=>w(le.id,gr.id)}))]},{kind:"item",key:"new-group",label:i("New group"),icon:n.jsx(Fm,{}),onSelect:()=>Be({mode:"create"})},{kind:"separator",key:"sep-danger"},{kind:"item",key:"archive",label:i("Archive project"),icon:n.jsx(lr,{}),onSelect:()=>en(le.id)},{kind:"item",key:"remove",label:i("Remove project"),icon:n.jsx(vs,{}),destructive:!0,onSelect:()=>De({kind:"project",project:le,conversationIds:Ue})}];return n.jsx(xJ,{project:le,activitySorted:D,children:gr=>n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsxs("div",{ref:gr.setNodeRef,style:gr.style,children:[n.jsxs("div",{"data-enso":"project-row","data-expanded":!vn||void 0,className:"group flex h-8 w-full items-center gap-1 rounded-lg px-2 transition-colors hover:bg-foreground/5",...gr.handleProps,children:[n.jsxs("button",{type:"button",onClick:()=>W(le.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",title:le.path,children:[n.jsx(II,{folded:vn}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-[0.9286rem] font-medium text-foreground",title:le.kind==="ssh"?`${le.sshHost}:${le.path}`:le.path,children:[qn(le),le.kind==="ssh"&&n.jsx("span",{className:"ml-1.5 rounded bg-muted px-1 py-0.5 text-[10px] font-normal text-muted-foreground",children:le.sshConnectionName??le.sshHost}),D&&n.jsx("span",{className:"ml-1.5 font-normal text-[0.7857rem] text-subtle-foreground",children:p.find(Kn=>Kn.id===le.groupId)?.name??i("Ungrouped")})]})]}),n.jsx("button",{type:"button",onClick:()=>an(le.id),className:"hidden shrink-0 rounded-md p-1 text-muted-foreground group-hover:block hover:bg-muted hover:text-foreground",title:i(Yo?"Unpin project":"Pin project"),children:Yo?n.jsx(vd,{className:"h-3.5 w-3.5"}):n.jsx(Ss,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",onClick:()=>{$(le.id)},className:dJ,title:i("New conversation"),children:n.jsx(no,{className:"h-3.5 w-3.5"})}),n.jsx(bJ,{actions:vg}),(Yo||vn)&&n.jsxs("span",{className:"flex shrink-0 items-center justify-center gap-1 py-1 text-[0.7857rem] text-subtle-foreground tabular-nums group-hover:opacity-0","aria-hidden":!0,children:[Yo&&n.jsx(Ss,{className:"h-3.5 w-3.5"}),vn&&Ue.length]})]}),n.jsx(ya,{initial:!1,children:!vn&&n.jsx(Ns.div,{initial:"initial",animate:"animate",exit:"exit",variants:If,className:"overflow-hidden",children:n.jsxs("div",{className:"flex flex-col",children:[yt.slice(0,$r).map(Kn=>n.jsx(Ns.div,{layout:Ne?.type==="project"?!1:"position",transition:gi,children:n.jsx(gw,{id:Kn,conversation:A[Kn],children:n.jsx(wo,{id:Kn,conversation:A[Kn],active:R===Kn,switchHint:Ko(Kn,"project"),locale:a,nowTick:At,worktreeStatus:A[Kn].worktree?me[Kn]:void 0,isolated:!!A[Kn].worktree,onSelect:te,onTogglePin:se,onToggleArchive:xo=>{Fr(xo)},onCleanupWorktree:xo=>{ho(xo)},onMoveToWorktree:xo=>{zr(xo)},onRemove:xo=>{dt(xo)}})})},Kn)),!Xt&&Ue.length>il&&n.jsxs("div",{className:"flex items-center gap-1 pl-6",children:[po.length>0&&n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsx("button",{type:"button",onClick:()=>Rt(Kn=>({...Kn,[le.id]:lw(yt.length,Kn[le.id]??0)})),className:ra,children:i("Show {{n}} more",{n:po.length})})}),n.jsx(Qr,{className:"min-w-36",children:n.jsxs(Kt,{onClick:()=>{xg(po)},children:[n.jsx(lr,{}),i("Archive {{n}} conversations",{n:po.length})]})})]}),rs>0&&n.jsx("button",{type:"button",onClick:()=>Rt(Kn=>({...Kn,[le.id]:cw(Kn[le.id]??0)})),className:ra,children:i("Collapse")})]}),yt.length===0&&n.jsx("p",{className:"py-1.5 pl-8 text-xs text-subtle-foreground",children:i("No conversations yet")})]})})})]})}),n.jsx(Qr,{className:"min-w-40",children:Ld(vg)})]})},le.id)};return D&&!Xt&&Te.length===0?n.jsx("p",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:i("No projects active in the last {{n}} days",{n:c3})}):!Xt&&ce.length>0&&Te.length===0?n.jsx("p",{className:"px-2 py-1.5 text-xs text-subtle-foreground",children:i("No projects in this group yet")}):C===Yn&&p.length>0?n.jsxs("div",{children:[Y.length>0&&n.jsxs("div",{children:[n.jsx(oa,{section:"pinned-projects",children:i("Pinned projects")}),n.jsx("div",{children:Y.map(O)})]}),ge.map(le=>{const Ue=Xt?!1:Gn[le.groupId]===!0;return n.jsxs("div",{children:[n.jsx(mJ,{groupId:le.groupId,name:le.group?.name??i("Ungrouped"),emoji:le.group?.emoji,color:le.group?.color,count:le.projects.length,folded:Ue,sortable:le.groupId!==Ts,onToggle:()=>Rn(le.groupId),onEdit:le.group?()=>Be({mode:"edit",id:le.groupId}):void 0}),n.jsx(ya,{initial:!1,children:!Ue&&n.jsx(Ns.div,{initial:"initial",animate:"animate",exit:"exit",variants:If,className:"overflow-hidden",children:n.jsx("div",{children:le.projects.map(O)})},`content-${le.groupId}`)})]},le.groupId)})]}):Y.length>0&&ee.length>0?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{children:[n.jsx(oa,{section:"pinned-projects",children:i("Pinned projects")}),n.jsx("div",{children:Y.map(O)})]}),n.jsx("div",{children:ee.map(O)})]}):Te.map(O)})()})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 p-1.5",children:[d==="devices"?n.jsxs(n.Fragment,{children:[n.jsx(tw,{}),n.jsx("div",{className:"min-w-0 flex-1"})]}):d==="info"?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"min-w-0 flex-1"}),n.jsx(ew,{})]}):n.jsx(d3,{}),n.jsx(Qy,{className:zs}),n.jsx(Zy,{count:ug,onClick:pg,className:zs}),m&&n.jsx("button",{type:"button",onClick:()=>window.electronAPI.remote?.exitDesk?.(),className:zs,title:i("Compact view"),children:n.jsx(Wg,{className:"h-4 w-4"})}),n.jsx("button",{type:"button","data-enso":"settings-button",onClick:()=>window.electronAPI.window.openSettings(),className:zs,title:i("Settings"),"aria-label":i("Settings"),children:n.jsx(Os,{className:"h-4 w-4"})}),u&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button","data-enso":"search-button",onClick:r,className:zs,title:k?`${i("Search anything")} (${k})`:i("Search anything"),children:n.jsx(dr,{className:"h-4 w-4"})}),n.jsx("button",{type:"button","data-enso":"sidebar-toggle",onClick:s,className:zs,title:i("Collapse sidebar"),children:n.jsx(tx,{className:"h-4 w-4"})})]})]})]}),n.jsx(cn,{open:UI,onOpenChange:Tu,children:n.jsxs(dn,{className:"h-[min(40rem,85vh)] max-w-xl",children:[n.jsxs(un,{children:[n.jsxs(rn,{className:"flex items-baseline gap-2",children:[i("Archived"),n.jsx("span",{className:"font-sans text-sm text-muted-foreground tabular-nums",children:GI})]}),n.jsx("p",{"data-slot":"archive-scope",className:"text-xs text-muted-foreground",children:KI}),(Br.kind!=="all"||fg.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[Br.kind!=="all"&&n.jsx(Wf,{label:hg,selected:cg===null,onClick:()=>Vl(null)}),n.jsx(Wf,{label:i("All archived"),selected:Qs.kind==="all",onClick:()=>Vl(Br.kind==="all"?null:{kind:"all"})}),fg.map(O=>n.jsx(Wf,{label:i("Dispatched by {{name}}",{name:mg(O)}),selected:Qs.kind==="secretary"&&Qs.secretaryId===O,onClick:()=>Vl({kind:"secretary",secretaryId:O})},O))]}),n.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[n.jsxs(sp,{"data-size":"sm",children:[n.jsx(rp,{children:n.jsx(dr,{})}),n.jsx(op,{value:qi,placeholder:i("Search conversations..."),onChange:O=>ig(O.target.value)})]}),n.jsx(xw,{open:ag==="*",onOpenChange:O=>lg(O?"*":null),idsForDays:O=>Ug(M,A,O,Date.now()),onPick:(O,le)=>De({kind:"archived",days:O,conversationIds:le}),className:"h-8 w-8 rounded-md opacity-100 hover:bg-muted"})]})]}),n.jsxs(In,{className:"flex flex-col gap-y-3 border-t pt-3!",children:[dg.length===0&&n.jsx("p",{className:"py-10 text-center text-sm text-muted-foreground",children:qi.trim()?i("No matching conversations"):i("No conversations")}),dg.map(O=>{const le=l.find(ot=>ot.id===O.projectId),Ue=le?qn(le):i("Other");return n.jsxs("div",{children:[n.jsxs("div",{className:"group flex items-center gap-2 rounded-md pr-0.5 pl-2",children:[O.projectArchived&&n.jsx(X_,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate py-1 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",children:Ue}),n.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground tabular-nums",children:O.ids.length}),O.projectArchived?n.jsx("button",{type:"button",onClick:()=>en(O.projectId),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",title:i("Unarchive project"),children:n.jsx(Ga,{className:"h-3.5 w-3.5"})}):n.jsx(xw,{open:ag===O.projectId,onOpenChange:ot=>lg(ot?O.projectId:null),idsForDays:ot=>Ug(M,A,ot,Date.now(),O.projectId),onPick:(ot,yt)=>De({kind:"archived",days:ot,conversationIds:yt,projectName:Ue})})]}),n.jsx("div",{className:"flex flex-col",children:O.ids.map(ot=>n.jsx(Ns.div,{layout:"position",transition:gi,children:n.jsx(wo,{id:ot,conversation:A[ot],active:R===ot,locale:a,nowTick:At,worktreeStatus:A[ot].worktree?me[ot]:void 0,isolated:!!A[ot].worktree,menuZIndex:Pn.DROPDOWN_IN_MODAL,onSelect:yt=>{te(yt),Tu(!1)},onTogglePin:se,onToggleArchive:yt=>{Fr(yt)},onCleanupWorktree:yt=>{ho(yt)},onMoveToWorktree:yt=>{zr(yt)},onRemove:yt=>{dt(yt)}})},ot))})]},O.projectId)})]})]})}),n.jsx(dQ,{open:ht,onOpenChange:ze,onAdd:Ye,groups:p,defaultGroupId:P}),n.jsx(vQ,{open:_e!==null,group:_e?.mode==="edit"?p.find(O=>O.id===_e.id)??null:null,projects:ce.filter(O=>!at.includes(O.id)),onOpenChange:O=>{O||Be(null)},onSave:O=>{if(_e?.mode==="edit"){x(_e.id,O);return}const le=g(O);for(const Ue of O.projectIds??[])w(Ue,le.id)},onDelete:_e?.mode==="edit"?()=>{const O=_e.id;v(O),Bt===O&&sn(Yn)}:void 0}),n.jsx(AQ,{open:Ze!==null,project:l.find(O=>O.id===Ze)??null,onOpenChange:O=>{O||ft(null)}}),n.jsx(TQ,{project:be,onClose:()=>ye(null)}),n.jsx(CQ,{project:Me,onClose:()=>Ae(null)}),n.jsx(cs,{open:mo!==null,onOpenChange:O=>{O||Eu(null)},title:mo?.kind==="archive"?i("Archive session and clean up worktree?"):i("Clean up worktree?"),description:i("Pending work: {{warning}}. This session returns to the main working tree. The worktree directory and uncommitted changes are removed only when no other sessions use it. The branch is kept.",{warning:gg(mo?.status)}),confirmLabel:mo?.kind==="archive"?i("Archive"):i("Clean up"),onConfirm:()=>{mo&&Du(mo.id,mo.kind==="archive")}}),n.jsx(cs,{open:Ru!==null,onOpenChange:O=>{O||Mu(null)},title:i("Main working tree has uncommitted changes"),description:i("The new worktree branches off HEAD, so those changes stay in the main working tree and will not follow this session."),confirmLabel:i("Move anyway"),onConfirm:()=>{if(!Ru)return;const O=Ru;Mu(null),zr(O,!0)}}),n.jsx(cs,{open:je!==null,onOpenChange:O=>{O||De(null)},title:je?.kind==="project"?i("Remove project?"):je?.kind==="archived"?i("Delete archived conversations?"):i("Delete conversation?"),description:je?.kind==="project"?i('"{{name}}" and its {{count}} conversations will be removed from the list.',{name:qn(je.project),count:je.conversationIds.length}):je?.kind==="archived"?je.days===0?je.projectName?i('All {{count}} archived conversations in "{{name}}" will be removed from the list.',{count:je.conversationIds.length,name:je.projectName}):i("All {{count}} archived conversations will be removed from the list.",{count:je.conversationIds.length}):je.projectName?i('{{count}} conversations in "{{name}}" archived more than {{days}} days ago will be removed from the list.',{count:je.conversationIds.length,days:je.days,name:je.projectName}):i("{{count}} conversations archived more than {{days}} days ago will be removed from the list.",{count:je.conversationIds.length,days:je.days}):je?.kind==="conversation"&&je.worktreeWarning?i("Pending work: {{warning}}. This conversation will be removed. Its worktree directory and uncommitted changes are removed only when no other sessions use it. The branch is kept.",{warning:je.worktreeWarning}):i("This conversation will be removed from the list."),confirmLabel:i("Remove"),onConfirm:()=>{if(je)if(je.kind==="project"){for(const O of je.conversationIds)V(O);F(je.project.id)}else if(je.kind==="archived")for(const O of je.conversationIds)V(O);else V(je.id)}}),So.createPortal(n.jsx(ZP,{dropAnimation:null,children:Ne?.type==="project"?n.jsx(pJ,{projectId:Ne.projectId,name:hJ(l,Ne.projectId,Ne.name),folded:xe[Ne.projectId]===!0,revealedExtra:Nt[Ne.projectId]??0,width:e}):(Ne?.type==="chat"||Ne?.type==="workspace-file")&&n.jsxs("div",{className:"flex w-56 items-center gap-2 rounded-lg border bg-background/95 px-3 py-1.5 text-sm shadow-float",children:[Ne.type==="workspace-file"?n.jsx(Wo,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):n.jsx(Ss,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ne.type==="workspace-file"?Ne.name:Ne.title.split(`
|
|
106
|
-
`)[0].trim()||i("New conversation")})]})}),document.body),n.jsx(u3,{open:Et!==null,secretaryId:Et??void 0,onOpenChange:O=>{O||oe(null)}})]})}function mJ({groupId:e,name:t,emoji:s,color:r,count:o,folded:i,sortable:a,onToggle:l,onEdit:c}){const u=e===Ts?Kx:W2(e),d=vl({id:u}),m=Iu({id:u,data:{type:"project-group",groupId:e},disabled:!a}),h=p=>{d.setNodeRef(p),m.setNodeRef(p)};return n.jsxs("div",{ref:h,"data-enso":"section-header","data-section":"group",style:{transform:ur.Transform.toString(m.transform),transition:m.transition,opacity:m.isDragging?.4:void 0},className:_("group relative flex w-full select-none items-center rounded-md pt-3.5 pr-2.5 pb-1 pl-2 text-[0.8214rem] font-medium text-subtle-foreground transition-colors hover:text-foreground",d.isOver&&"bg-foreground/5 text-foreground",a&&"cursor-grab"),...a?m.listeners:{},...a?m.attributes:{},children:[n.jsxs("button",{type:"button",onClick:l,onPointerDown:p=>p.stopPropagation(),className:"flex min-w-0 flex-1 items-center gap-1.5",children:[n.jsx("span",{className:"min-w-0 truncate text-left",children:t}),s&&n.jsx("span",{className:"shrink-0 text-sm leading-none",children:s}),r&&n.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{backgroundColor:r}}),n.jsx(fn,{"data-enso":"tree-chevron","data-expanded":!i||void 0,className:_("size-3 shrink-0 transition-[opacity,transform] duration-150",!i&&"rotate-90 opacity-0 group-hover:opacity-100")}),n.jsx("span",{className:_("ml-auto shrink-0 font-normal text-[0.7857rem] tabular-nums",c&&"transition-opacity group-hover:opacity-0"),children:o})]}),c&&n.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),c()},onPointerDown:p=>p.stopPropagation(),className:cJ,children:n.jsx(bs,{className:"size-3.25"})})]})}function hJ(e,t,s){const r=e.find(o=>o.id===t);return r?qn(r):s}function pJ({projectId:e,name:t,folded:s,revealedExtra:r,width:o}){const{t:i}=z(),a=J(m=>fu(m.conversations)),l=J(m=>m.order),c=Eo(l,a,e),u=s?[]:c.slice(0,al(c.length,r)),d=Math.max(0,c.length-u.length);return n.jsxs("div",{className:"pointer-events-none rounded-lg border bg-background/95 py-0.5 shadow-float",style:{width:o??224},children:[n.jsxs("div",{className:"flex h-8 items-center gap-2 px-2 text-[0.9286rem] font-medium",children:[n.jsx(II,{folded:s}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:t})]}),!s&&n.jsxs("div",{className:"flex flex-col",children:[u.map(m=>{const h=a[m];return h?n.jsxs("div",{className:"flex h-8 items-center gap-2 px-2 text-[0.9286rem] text-foreground/88",children:[n.jsx(TI,{conversation:h}),n.jsx("span",{className:"min-w-0 truncate",children:h.title||i("New conversation")})]},m):null}),c.length>il&&n.jsxs("div",{className:"flex items-center gap-1",children:[d>0&&n.jsx("div",{className:"flex-1 rounded-lg py-1 text-center text-xs text-muted-foreground",children:i("Show {{n}} more",{n:d})}),r>0&&n.jsx("div",{className:"flex-1 rounded-lg py-1 text-center text-xs text-muted-foreground",children:i("Collapse")})]}),c.length===0&&n.jsx("p",{className:"py-1.5 pl-8 text-xs text-muted-foreground",children:i("No conversations yet")})]})]})}function xJ({project:e,activitySorted:t=!1,children:s}){const{setNodeRef:r,transform:o,transition:i,listeners:a,isDragging:l}=Iu({id:H2(e.id),disabled:{droppable:t},data:{type:"project",projectId:e.id,path:e.path,name:e.name}});return s({setNodeRef:r,style:{transform:t?void 0:ur.Transform.toString(o),transition:i,opacity:l?.4:void 0},handleProps:a??{}})}function xw({open:e,onOpenChange:t,idsForDays:s,onPick:r,className:o}){const{t:i}=z();return n.jsxs(mr,{open:e,onOpenChange:t,children:[n.jsx(hr,{className:_("flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:text-destructive",e&&"opacity-100",o),title:i("Clean up archived"),"aria-label":i("Clean up archived"),children:n.jsx(g1,{className:"h-3.5 w-3.5"})}),n.jsxs(pr,{align:"end",className:"min-w-40",zIndex:Pn.DROPDOWN_IN_MODAL,children:[fJ.map(a=>{const l=s(a);return n.jsx(Cn,{variant:"destructive",disabled:l.length===0,onClick:()=>r(a,l),children:i("Older than {{days}} days",{days:a})},a)}),(()=>{const a=s(0);return n.jsx(Cn,{variant:"destructive",disabled:a.length===0,onClick:()=>r(0,a),children:i("Delete all archived")})})()]})]})}function gJ({id:e,conversation:t,children:s}){const{setNodeRef:r,transform:o,transition:i,listeners:a,isDragging:l}=Iu({id:U2(e),data:{type:"chat",conversationId:e,title:t.title,sessionFile:t.sessionFile,pinned:t.pinned===!0}});return n.jsx("div",{ref:r,...a,style:{transform:ur.Transform.toString(o),transition:i,opacity:l?.4:void 0},children:s})}function gw({id:e,conversation:t,children:s,dragId:r}){const{setNodeRef:o,listeners:i,isDragging:a}=z1({id:r??UK(e),data:{type:"chat",conversationId:e,title:t.title,sessionFile:t.sessionFile,pinned:t.pinned===!0}});return n.jsx("div",{ref:o,...i,style:{opacity:a?.4:void 0},children:s})}function vw({children:e,...t}){const{setNodeRef:s,isOver:r,active:o}=vl({id:V2}),i=o?.data.current?.type==="chat";return n.jsx("div",{ref:s,className:_("rounded-lg",r&&i&&"bg-brand/8 ring-1 ring-brand/40"),...t,children:e})}function wo({id:e,conversation:t,active:s,locale:r,nowTick:o,hoverTitle:i,subtitle:a,dispatchRunning:l,isolated:c,worktreeStatus:u,switchHint:d,menuZIndex:m,onSelect:h,onTogglePin:p,onToggleArchive:g,onCleanupWorktree:x,onMoveToWorktree:v,onRemove:b}){const{t:w}=z(),j=pe(H=>H.projects),T=vI(j,t.projectId),N=bI(j,t.projectId),S=pe(H=>H.projects.some(B=>B.id===t.projectId&&B.kind!=="ssh"&&B.kind!=="secretary")),I=pe(H=>H.projects.some(B=>B.id===t.projectId&&B.kind==="scratch")),[k,L]=f.useState(!1),F=L2(e)!==void 0,A=J(H=>H.conversations[e]?.worktree),M=J(H=>!!H.conversations[e]?.workspaceMigrating),R=J(H=>H.conversations[e]?.worktreeMissing),[$,U]=f.useState(!1),[q,te]=f.useState(null),V=$||M||t.spawning||t.status==="running"||t.reloading===!0,se=async()=>{if(!V){U(!0);try{await J.getState().newConversation(t.projectId,{worktreeFromConversationId:e})||Ie({type:"error",title:w("Failed to create conversation")})}catch(H){Ie({type:"error",title:w("Failed to create conversation"),description:String(H)})}finally{U(!1)}}},Ce=t.pinned===!0,de=t.archived===!0,re=J(H=>H.conversations[e]?.muted===!0),Z=Ce?vd:Ss,me=re?d_:xd,xe=t.title||w("New conversation"),Se=t.forkedFromConversationId?J.getState().conversations[t.forkedFromConversationId]?.title:void 0,W=n.jsxs("div",{"data-slot":"conversation-row","data-pinned":Ce?"true":"false","data-enso":"session-row","data-active":s||void 0,"data-status":Zx(t),"data-unread":t.unread||void 0,"data-muted":re||void 0,className:_("group flex h-8 cursor-pointer items-center gap-2 rounded-lg px-2 text-[0.9286rem] transition-colors",s?"bg-foreground/[0.075] text-foreground dark:bg-foreground/10":"text-foreground/88 hover:bg-foreground/5 hover:text-foreground"),onClick:()=>{k||h(e)},onDoubleClick:H=>{H.preventDefault(),H.stopPropagation(),L(!0)},onKeyDown:H=>{H.key==="Enter"&&!k&&h(e)},role:"button",tabIndex:0,title:i,children:[n.jsx(TI,{conversation:t}),n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[Se&&n.jsx("span",{className:"max-w-1/3 truncate text-[0.7857rem] text-subtle-foreground",children:w("Branched from {{title}}",{title:Se})}),k?n.jsx(K2,{title:xe,onCommit:H=>{J.getState().renameConversation(e,H),L(!1)},onCancel:()=>L(!1)}):n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[xe,a&&n.jsx("span",{className:"ml-1.5 text-[0.7857rem] text-subtle-foreground",children:a})]}),WQ(re,t.secretaryOrigin!==void 0)&&!k&&n.jsx(xd,{className:"h-3 w-3 shrink-0 text-subtle-foreground","aria-label":w("Muted"),"data-enso":"session-muted"})]}),t.secretaryOrigin&&n.jsx(qQ,{secretaryId:t.secretaryOrigin.secretaryId,conversationId:e,muted:re}),!t.secretaryOrigin&&F&&n.jsx(eK,{conversationId:e}),c&&A&&n.jsx(DX,{worktree:A,status:u}),n.jsx(lJ,{conversationId:e}),n.jsx(MQ,{conversationId:e}),n.jsx(oQ,{conversationId:e}),n.jsx(YQ,{count:l}),n.jsx(EQ,{conversationId:e,running:t.status==="running"||!!t.spawning||!!t.hasRunningChild,hidden:k||Fa(t.goal)}),!k&&Fa(t.goal)&&n.jsxs("span",{"data-enso":"sidebar-upstream-waiting",className:"inline-flex shrink-0 items-center gap-1 rounded bg-amber-500/15 px-1 py-px text-[10px] text-amber-600 dark:text-amber-400",title:t.goal.retry.kind==="quota"?w("Quota exhausted · next {{time}}",{time:Ni(t.goal.retry.at)}):w("Waiting for upstream recovery · next {{time}}",{time:Ni(t.goal.retry.at)}),children:[n.jsx("span",{children:t.goal.retry.kind==="quota"?w("Quota exhausted"):w("Waiting for upstream recovery")}),n.jsx("button",{type:"button","data-enso":"upstream-retry-now",title:w("Retry now"),"aria-label":w("Retry now"),onClick:H=>{H.stopPropagation(),J.getState().retryUpstreamNow(e)},className:"rounded p-0.5 transition-colors hover:bg-amber-500/20",children:n.jsx(Mr,{className:"h-2.5 w-2.5"})})]}),!k&&n.jsx(vJ,{pending:t.titleSummaryPending,error:t.titleSummaryError,onRetry:()=>J.getState().retryTitleSummary(e)}),!k&&(d?n.jsx("span",{className:"shrink-0 text-[0.7857rem] text-subtle-foreground tabular-nums",children:d}):n.jsxs(n.Fragment,{children:[Ce&&!de&&n.jsx(Ss,{className:"h-3 w-3 shrink-0 text-subtle-foreground group-hover:hidden","aria-hidden":!0}),n.jsx("span",{className:"shrink-0 text-[0.7857rem] text-subtle-foreground tabular-nums group-hover:hidden",children:Lo(t.lastActiveAt??t.createdAt,r,o)}),!de&&n.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),p(e)},className:"hidden shrink-0 rounded p-0.5 text-muted-foreground group-hover:block hover:text-foreground",title:w(Ce?"Unpin":"Pin"),children:n.jsx(Z,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),g(e)},className:"hidden shrink-0 rounded p-0.5 text-muted-foreground group-hover:block hover:text-foreground",title:w(de?"Unarchive":"Archive"),children:de?n.jsx(Ga,{className:"h-3.5 w-3.5"}):n.jsx(lr,{className:"h-3.5 w-3.5"})}),de&&n.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),b(e)},className:"hidden shrink-0 rounded p-0.5 text-muted-foreground group-hover:block hover:text-destructive",title:w("Delete"),children:n.jsx(vs,{className:"h-3.5 w-3.5"})})]}))]})]});return n.jsxs(n.Fragment,{children:[n.jsxs(Yr,{children:[n.jsx(Xr,{render:W}),n.jsxs(Qr,{className:"min-w-36",zIndex:m,children:[n.jsxs(Kt,{onClick:()=>L(!0),children:[n.jsx(bs,{}),w("Rename")]}),n.jsxs(Kt,{disabled:t.reloading===!0||t.spawning,onClick:()=>{GS(e,w)},children:[n.jsx(oo,{className:t.reloading?"animate-spin":void 0}),w("Reload conversation")]}),n.jsxs(Kt,{disabled:V,onClick:()=>{KS(e,w)},children:[n.jsx(Mr,{}),w("Restart conversation (reload settings)")]}),S&&n.jsxs(Kt,{disabled:M||R||u?.exists===!1,onClick:()=>{Jx({projectId:t.projectId,conversationId:e},w)},children:[n.jsx(Lr,{}),w(Qx(window.electronAPI.env.platform))]}),!de&&n.jsxs(Kt,{onClick:()=>p(e),children:[n.jsx(Z,{}),w(Ce?"Unpin":"Pin")]}),n.jsxs(Kt,{onClick:()=>g(e),children:[de?n.jsx(Ga,{}):n.jsx(lr,{}),w(de?"Unarchive":"Archive")]}),n.jsxs(Kt,{"data-enso":"session-mute",onClick:()=>J.getState().toggleMuteConversation(e),children:[n.jsx(me,{}),w(re?"Unmute":"Mute")]}),A&&n.jsxs(n.Fragment,{children:[n.jsxs(Kt,{disabled:V||R||u?.exists===!1,onClick:()=>{se()},children:[$?n.jsx(_t,{className:"animate-spin"}):n.jsx(no,{}),w("New conversation in this worktree")]}),n.jsxs(Kt,{disabled:V||R||u?.exists===!1,onClick:()=>te({conversationId:e,worktree:A}),children:[n.jsx(bs,{}),w("Rename worktree")]})]}),!de&&(c?x&&n.jsxs(Kt,{disabled:V,onClick:()=>x(e),children:[n.jsx(g1,{}),w("Clean up worktree")]}):v&&S&&!I&&n.jsxs(Kt,{disabled:V,onClick:()=>v(e),children:[n.jsx(rB,{}),w("Move to worktree")]})),T?N.length>0?n.jsxs(ap,{children:[n.jsxs(lp,{children:[n.jsx(zm,{}),w(I?"Add to project…":"Move to project…")]}),n.jsx(cp,{className:"min-w-36",children:N.map(H=>n.jsx(Kt,{disabled:V,onClick:()=>{jQ(e,H.id,w)},children:qn(H)},H.id))})]}):n.jsxs(Kt,{disabled:!0,children:[n.jsx(zm,{}),w(I?"Add to project…":"Move to project…")]}):null,n.jsx(dp,{}),n.jsxs(Kt,{variant:"destructive",onClick:()=>b(e),children:[n.jsx(vs,{}),w("Delete")]})]})]}),n.jsx(iI,{entity:q,onClose:()=>te(null)})]})}function vJ({pending:e,error:t,onRetry:s}){const{t:r}=z();return e?n.jsxs(bi,{children:[n.jsx(yi,{render:n.jsx("span",{role:"status",className:"shrink-0 text-muted-foreground/60","aria-label":r("Summarizing title")}),children:n.jsx(_t,{className:"h-3 w-3 animate-spin"})}),n.jsx(wi,{side:"right",children:r("Summarizing title")})]}):t?n.jsxs(bi,{children:[n.jsx(yi,{render:n.jsx("button",{type:"button","aria-label":r("Title summary failed"),className:"shrink-0 rounded p-0.5 text-destructive hover:text-destructive/80",onClick:o=>{o.stopPropagation(),s()}}),children:n.jsx(Zr,{className:"h-3 w-3"})}),n.jsxs(wi,{side:"right",className:"max-w-72",children:[n.jsx("p",{className:"font-medium",children:r("Title summary failed")}),n.jsx("p",{className:"mt-0.5 break-all text-muted-foreground",children:t}),n.jsx("p",{className:"mt-1 text-muted-foreground/70",children:r("Click to retry")})]})]}):null}function bw(e,t){const s=e.find(r=>r.id===t);return s?qn(s):void 0}function Yf({emoji:e,color:t}){return e?n.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-sm leading-none",children:e}):n.jsx(zm,{style:t?{color:t}:void 0})}function Ld(e,t="context"){return e.map(s=>s.kind==="separator"?t==="menu"?n.jsx(Ri,{},s.key):n.jsx(dp,{},s.key):s.kind==="submenu"?t==="menu"?n.jsxs(Bj,{children:[n.jsxs(Fj,{children:[s.icon,s.label]}),n.jsx(zj,{className:"min-w-40",children:Ld(s.items,"menu")})]},s.key):n.jsxs(ap,{children:[n.jsxs(lp,{children:[s.icon,s.label]}),n.jsx(cp,{className:"min-w-40",children:Ld(s.items)})]},s.key):t==="menu"?n.jsxs(Cn,{onClick:s.onSelect,variant:s.destructive?"destructive":"default",children:[s.icon,s.label]},s.key):n.jsxs(Kt,{onClick:s.onSelect,variant:s.destructive?"destructive":"default",children:[s.icon,s.label]},s.key))}function bJ({actions:e}){const{t}=z();return n.jsxs(mr,{children:[n.jsx(hr,{"data-enso":"row-menu","aria-label":t("More actions"),className:uJ,title:t("More actions"),onPointerDown:s=>s.stopPropagation(),children:n.jsx(kl,{className:"h-3.5 w-3.5"})}),n.jsx(pr,{align:"end",className:"min-w-40",children:Ld(e,"menu")})]})}function oa({section:e,children:t,actions:s}){return n.jsxs("div",{"data-enso":"section-header","data-section":e,className:"group flex items-center gap-1 pt-3.5 pr-1 pb-1 pl-2 text-[0.8214rem] font-medium text-subtle-foreground",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),s]})}function II({folded:e}){return n.jsx("span",{"data-enso":"tree-chevron","data-expanded":!e||void 0,className:"flex size-4 shrink-0 items-center justify-center text-subtle-foreground",children:n.jsx(fn,{className:_("size-3.5 transition-transform duration-150",!e&&"rotate-90")})})}function TI({conversation:e}){const{t}=z(),s=Fa(e.goal)?e.goal.retry:void 0,{reminder:r,now:o}=Yd(e.id,e.status!=="running"&&!e.spawning&&!e.hasRunningChild&&!s&&!e.queued),i=(e.pendingApprovals?.length??0)>0?"attention":Bd({status:e.queueFailed?"failed":e.status,spawning:e.spawning,unread:e.unread,pendingAskCount:Po(e.pendingAsks),hasRunningChild:e.hasRunningChild,queued:e.queued===!0&&!e.queueFailed||s!==void 0,hasPendingReminder:r!==void 0}),a=e.queueFailed?e.queueFailed:s?s.kind==="quota"?t("Quota exhausted · next {{time}}",{time:Ni(s.at)}):t("Waiting for upstream recovery · next {{time}}",{time:Ni(s.at)}):e.queued?t("Queued · #{{n}}, starts automatically when a slot opens",{n:e.queuePosition??1}):r?Xd(r,o,t):void 0;return n.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:i!=="idle"&&n.jsx(Nl,{tone:i,title:a,size:"sm","data-enso":"session-status","data-status":Zx(e),conversationId:e.id})})}const Xf=["welcome","provider","skill","mcp","instruction","preset","agentType","done"];function yJ(){const{t:e}=z();Eh();const t=pe(S=>S.setOnboarded),s=Kd(),r=pe(S=>S.skills),o=pe(S=>S.mcpServers),i=pe(S=>S.instructions),a=pe(S=>S.presets),[l,c]=f.useState(0),[u,d]=f.useState(null),[m,h]=f.useState(!1),[p,g]=f.useState(!1),[x,v]=f.useState(!1),b=Xf[l],w=()=>t(!0),j=()=>c(S=>Math.min(Xf.length-1,S+1)),T=()=>c(S=>Math.max(0,S-1)),N={provider:{icon:p3,title:e("Model Providers"),desc:e("Add a provider subscription or API Key, or import providers from local AI apps"),count:s.length,onImport:()=>g(!0),importLabel:e("Add model or provider"),secondary:{label:e("Import from local apps"),onClick:()=>h(!0)}},skill:{icon:Bs,title:e("Skills"),desc:e("Import skills from Claude Code, Codex or Cursor"),count:r.length,onImport:()=>d("skill"),importLabel:e("Scan and import")},mcp:{icon:Yw,title:e("MCP Servers"),desc:e("Import MCP servers configured in local AI apps"),count:o.length,onImport:()=>d("mcp"),importLabel:e("Scan and import")},instruction:{icon:Xc,title:e("Instruction Files"),desc:e("Import global instruction files configured in local AI tools"),count:i.length,onImport:()=>d("instruction"),importLabel:e("Scan and import")}};return n.jsxs("div",{className:"fixed inset-0 z-[45] flex items-center justify-center bg-black/40 backdrop-blur-sm","data-enso-float":"",children:[n.jsxs("div",{className:"relative flex w-[32rem] max-w-[90vw] flex-col rounded-2xl border bg-popover p-6 shadow-xl",children:[n.jsx("button",{type:"button",onClick:w,className:"absolute right-3 top-3 rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","aria-label":e("Close"),children:n.jsx(Jt,{className:"h-4 w-4"})}),n.jsx("div",{className:"mb-5 flex items-center gap-1.5",children:Xf.map((S,I)=>n.jsx("span",{className:_("h-1 flex-1 rounded-full transition-colors",I<=l?"bg-primary":"bg-muted")},S))}),b==="welcome"&&n.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:n.jsx(h3,{className:"h-6 w-6 text-primary"})}),n.jsx("h2",{className:"text-lg font-semibold",children:e("Welcome to EnsoCode")}),n.jsx("p",{className:"text-sm text-muted-foreground",children:e("Import your providers and assets from local AI apps to get started. You can skip any step.")})]}),b!=="welcome"&&b!=="done"&&b!=="preset"&&b!=="agentType"&&n.jsx(yw,{...N[b],importedLabel:e("{{count}} imported",{count:N[b].count})}),b==="preset"&&n.jsx(yw,{icon:Xc,title:e("Presets"),desc:e("Bundle skills, MCP servers and an instruction file into a preset (optional)"),count:a.length,onImport:()=>v(!0),importedLabel:e("{{count}} presets",{count:a.length}),importLabel:e("New preset")}),b==="agentType"&&n.jsxs("div",{className:"flex flex-col gap-3 py-2",children:[n.jsxs("div",{className:"flex flex-col items-center gap-2 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:n.jsx(ws,{className:"h-6 w-6 text-muted-foreground"})}),n.jsx("h2",{className:"text-lg font-semibold",children:e("Agent types")}),n.jsx("p",{className:"text-sm text-muted-foreground",children:e("Give subagents their own model, skills and MCP servers (optional)")})]}),n.jsx("div",{className:"max-h-64 overflow-y-auto pr-1",children:n.jsx(x3,{})})]}),b==="done"&&n.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:n.jsx(On,{className:"h-6 w-6 text-primary"})}),n.jsx("h2",{className:"text-lg font-semibold",children:e("All set")}),n.jsx("p",{className:"text-sm text-muted-foreground",children:e("You can always import more from Settings later.")})]}),n.jsxs("div",{className:"mt-6 flex items-center justify-between",children:[n.jsx(fe,{variant:"ghost",size:"sm",onClick:T,disabled:l===0,children:e("Back")}),n.jsxs("div",{className:"flex items-center gap-2",children:[b!=="done"&&b!=="welcome"&&n.jsx(fe,{variant:"ghost",size:"sm",onClick:j,children:e("Skip")}),b==="done"?n.jsx(fe,{size:"sm",onClick:w,children:e("Done")}):n.jsx(fe,{size:"sm",onClick:j,children:e(b==="welcome"?"Get started":"Next")})]})]})]}),n.jsx(g3,{open:m,onOpenChange:h}),n.jsx(v3,{open:p,onOpenChange:g}),u&&n.jsx(b3,{kind:u,open:!0,onOpenChange:S=>!S&&d(null)}),x&&n.jsx(y3,{preset:null,onClose:()=>v(!1)})]})}function yw({icon:e,title:t,desc:s,count:r,onImport:o,importedLabel:i,importLabel:a,secondary:l}){return n.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:n.jsx(e,{className:"h-6 w-6 text-muted-foreground"})}),n.jsx("h2",{className:"text-lg font-semibold",children:t}),n.jsx("p",{className:"text-sm text-muted-foreground",children:s}),n.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[n.jsx(fe,{variant:"outline",size:"sm",onClick:o,children:a}),l&&n.jsx(fe,{variant:"ghost",size:"sm",onClick:l.onClick,children:l.label})]}),r>0&&n.jsx("p",{className:"text-xs text-primary",children:i})]})}const Qf=["project","all","all-including-archived"];function ww(e,t=!1){const s=Qf.length,r=Qf.indexOf(e);return Qf[(r+(t?s-1:1))%s]??"all"}const wJ=50,Jf=160,jJ=["title","project","id","body","tool"],tg=/[\p{Letter}\p{Number}]+/gu,kJ=/[\u3400-\u9fff]/u,NJ=/[^.!?。?!]+[.!?。?!]?/g;function AI(e){return e.toLowerCase().match(tg)??[]}function ng(e){return kJ.test(e)}function EI(e){return AI(e)}function RI(e,t){if(t.length===0)return!1;const s=e.toLowerCase(),r=AI(e);return t.every(o=>ng(o)?s.includes(o):r.some(i=>i.startsWith(o)))}function MI(e,t){return e.isDraftEmpty?!1:t.scope==="project"?e.projectId===t.currentProjectId&&!e.archived:t.scope==="all"?!e.archived:!0}function SJ(e,t){const s=e.toLowerCase(),r=EI(t);if(r.length===0||s.length!==e.length)return[{text:e,match:!1}];const o=[];for(const l of r){if(ng(l)){for(let c=s.indexOf(l);c>=0;c=s.indexOf(l,c+1))o.push([c,c+l.length]);continue}for(const c of s.matchAll(tg))c.index!==void 0&&c[0].startsWith(l)&&o.push([c.index,c.index+l.length])}if(o.length===0)return[{text:e,match:!1}];o.sort((l,c)=>l[0]-c[0]);const i=[];let a=0;for(const[l,c]of o){if(c<=a)continue;const u=Math.max(l,a);u>a&&i.push({text:e.slice(a,u),match:!1});const d=i.at(-1);d?.match&&u===a?d.text+=e.slice(u,c):i.push({text:e.slice(u,c),match:!0}),a=c}return a<e.length&&i.push({text:e.slice(a),match:!1}),i}function CJ(e,t){const s=e.toLowerCase();let r=-1;for(const o of t){if(ng(o)){const i=s.indexOf(o);i>=0&&(r<0||i<r)&&(r=i);continue}for(const i of e.matchAll(tg))if(i[0].toLowerCase().startsWith(o)&&i.index!==void 0){(r<0||i.index<r)&&(r=i.index);break}}return r}function IJ(e,t){if(e.length<=Jf)return e;const s=Math.max(0,CJ(e,t)),r=Math.min(s,Math.max(0,e.length-Jf));return e.slice(r,r+Jf)}function TJ(e){return(e.match(NJ)??[]).map(t=>t.trim()).filter(Boolean)}function AJ(e,t){const s=TJ(e);if(s.length<=1)return;const r=s.findIndex(i=>RI(i,t));if(r<0)return;const o=[...[s[r-1],s[r-2]].filter(i=>!!i),...[s[r+1],s[r+2]].filter(i=>!!i)];return o.length>0?o:void 0}function EJ(e,t,s,r){return e.title.trim().toLowerCase()===s.trim().toLowerCase()?0:t==="title"?1:e.projectId===r?2:3}function RJ(e,t,s){const r=s.trim().toLowerCase(),i=e.fields.map(a=>a.field==="body"?{...a,text:zh(a.text)}:a).filter(a=>a.field==="id"?a.text.toLowerCase().startsWith(r):RI(a.text,t));if(i.length!==0)return jJ.map(a=>i.find(l=>l.field===a)).find(a=>!!a)}function PI(e,t,s,r){return{conversationId:e.conversationId,projectId:e.projectId,title:e.title,field:t.field,snippet:t.snippet,...t.nearby?{nearby:t.nearby}:{},...e.isCurrent?{isCurrent:!0}:{},...e.archived?{archived:!0}:{},...e.parentConversationId?{parentConversationId:e.parentConversationId}:{},...e.coworkerId?{coworkerId:e.coworkerId}:{},rank:EJ(e,t.field,s,r),lastActiveAt:e.lastActiveAt}}function DI(e,t=wJ){return e.sort((s,r)=>s.rank-r.rank||r.lastActiveAt-s.lastActiveAt),e.slice(0,t).map(({rank:s,lastActiveAt:r,...o})=>o)}function MJ(e,t,s){const r=EI(t);if(r.length===0)return[];const o=[];for(const i of e){if(!MI(i,s))continue;const a=RJ(i,r,t);if(!a)continue;const l=AJ(a.text,r);o.push(PI(i,{field:a.field,snippet:IJ(a.text,r),nearby:l},t,s.currentProjectId))}return DI(o,s.limit)}function PJ(e,t,s,r,o){const i=new Map(e.map(l=>[l.conversationId,l])),a=new Map;for(const l of[...t,...s]){const c=i.get(l.conversationId);!c||a.has(l.conversationId)||!MI(c,o)||a.set(l.conversationId,PI(c,l,r,o.currentProjectId))}return DI([...a.values()],o.limit)}const DJ=120,OJ=8;function OI(e){return!e.started&&!e.sessionFile&&e.messages.length===0}function La(e){return e.messages.at(-1)?.timestamp??e.lastActiveAt??e.createdAt}function LJ(e,t){return e.filter(s=>s.parentId||OI(s)||s.archived&&t.scope!=="all-including-archived"?!1:t.scope!=="project"||s.projectId===t.currentProjectId).sort((s,r)=>La(r)-La(s)).slice(0,t.limit??OJ)}function _J(e){return e.content.map(t=>t.type==="text"?t.text:"").join(`
|
|
107
|
-
`).trim()}function BJ(e){if(e.role!=="toolResult"&&!e.content.some(r=>r.type==="toolCall"))return;const t=[e.toolName,...e.content.flatMap(r=>r.type==="toolCall"?[r.name]:[])].filter(r=>!!r);if(t.length===0)return;const s=e.content.flatMap(r=>r.type==="toolCall"&&r.arguments!=null?[JSON.stringify(r.arguments)]:[]).join(" ").slice(0,DJ);return`${t.join(" ")} ${s}`.trim()}function FJ(e){const t=[{field:"title",text:e.title},{field:"project",text:e.projectName},{field:"id",text:e.conversationId},{field:"body",text:e.messages.map(_J).filter(Boolean).join(`
|
|
108
|
-
`)}],s=e.messages.map(BJ).filter(r=>!!r);return s.length>0&&t.push({field:"tool",text:s.join(`
|
|
109
|
-
`)}),{conversationId:e.conversationId,projectId:e.projectId,projectName:e.projectName,title:e.title,lastActiveAt:e.lastActiveAt,fields:t,...e.archived?{archived:!0}:{},...e.isDraftEmpty?{isDraftEmpty:!0}:{},...e.isCurrent?{isCurrent:!0}:{},...e.parentConversationId?{parentConversationId:e.parentConversationId}:{},...e.coworkerId?{coworkerId:e.coworkerId}:{}}}const jw=[],zJ={project:"This project",all:"All projects","all-including-archived":"Include archived"},$J={general:"General",shortcuts:"Shortcuts",appearance:"Appearance",providers:"Model Providers",skills:"Skills",plugins:"Enso plugins",mcp:"MCP Servers",instructions:"Instruction Files",presets:"Presets",agents:"Agent types",workflows:"Workflows",tools:"Built-in tools",memory:"Memory",privacy:"Privacy",phone:"Devices",ssh:"SSH",usage:"Usage",resources:"Resources",logs:"Logs",experimental:"Experimental",bots:"Bot mode",botTemplates:"Bot templates",secretary:"Secretary"};function ia({text:e,query:t}){let s=0;return SJ(e,t).map(r=>{const o=s;return s+=r.text.length,r.match?n.jsx("mark",{className:"rounded-[3px] bg-brand/14 text-foreground",children:r.text},o):n.jsx("span",{children:r.text},o)})}function ti({icon:e,title:t,badges:s,detail:r,meta:o}){return n.jsxs(n.Fragment,{children:[n.jsx(e,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx("span",{className:"truncate",children:t}),s]}),r&&n.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]}),o&&n.jsx("span",{className:"max-w-48 shrink-0 truncate text-muted-foreground text-xs",children:o})]})}function VJ(e){try{return new URL(e).host||e}catch{return e}}function HJ({open:e,onOpenChange:t}){const{t:s,locale:r}=z(),[o,i]=f.useState(""),[a,l]=f.useState("all"),[c,u]=f.useState(),[d,m]=f.useState([]),[h,p]=f.useState([]),g=J(B=>B.conversations),x=J(B=>B.activeId),v=pe(B=>B.projects),b=pe(B=>B.scratchSessionsEnabled),w=pe(B=>B.keybindings),j=(x?g[x]?.projectId:void 0)??v[0]?.id??"",T=o.trim(),N=`${a}
|
|
110
|
-
${j}
|
|
111
|
-
${T}`,S=c?.key===N?c.hits:jw,I=f.useMemo(()=>{if(!e)return[];const ne=(x?g[x]:void 0)?.activeTabId,ve=ne&&g[ne]?ne:x;return Object.values(g).map(he=>{const G=v.find(we=>we.id===he.projectId);return G?.kind==="secretary"||!b&&G?.kind==="scratch"?null:FJ({conversationId:he.id,projectId:he.projectId,projectName:G?qn(G):he.projectId,title:he.title,lastActiveAt:La(he),archived:he.archived,isDraftEmpty:OI(he),isCurrent:he.id===ve,parentConversationId:he.parentId,coworkerId:he.parentId?he.id:void 0,messages:he.messages})}).filter(he=>he!==null)},[x,g,e,v,b]),k=f.useMemo(()=>T?MJ(I,o,{currentProjectId:j,scope:a}):jw,[j,I,o,a,T]),L=f.useMemo(()=>e?LJ(Object.values(g),{scope:a,currentProjectId:j}):[],[g,j,e,a]),F=w3(h),A=f.useMemo(()=>T?j3(F,o,{translate:B=>s(B)}):[],[o,F,s,T]),M=f.useMemo(()=>o.trim()?k3(d,o):[],[d,o]),R=f.useMemo(()=>N3(d),[d]);f.useEffect(()=>{if(!e)return;const B=ne=>{ne.key==="Escape"&&(ne.preventDefault(),ne.stopPropagation(),t(!1))};return window.addEventListener("keydown",B,!0),()=>window.removeEventListener("keydown",B,!0)},[t,e]),f.useEffect(()=>{if(!e){i(""),l("all"),u(void 0);return}window.electronAPI.browser.listSearchableTabs().then(B=>m(B.filter(ne=>!S3(ne.conversationId)))).catch(()=>{m([])}),window.electronAPI.sshConnections.list().then(B=>{p(B.map(ne=>({id:ne.id,name:ne.name})))}).catch(()=>{p([])})},[e]),f.useEffect(()=>{if(!e||!T||!j)return;let B=!1;const ne=window.setTimeout(()=>{window.electronAPI.workspaceSearch.query({query:T,currentProjectId:j,scope:a}).then(ve=>{B||u({key:N,hits:ve.hits})}).catch(()=>{B||u({key:N,hits:[]})})},80);return()=>{B=!0,window.clearTimeout(ne)}},[N,j,e,a,T]);const $=f.useMemo(()=>PJ(I,k,S,o,{currentProjectId:j,scope:a}),[S,j,I,k,o,a]),U=B=>{const ne=J.getState(),ve=ne.conversations[B.conversationId],he=B.parentConversationId??ve?.parentId;if(he&&ne.conversations[he]?(ne.selectConversation(he),ne.selectTab(he,B.coworkerId??B.conversationId)):ne.selectConversation(B.conversationId),t(!1),B.field==="body"||B.field==="tool"){const G=o.trim().split(/\s+/).find(Boolean);G&&window.setTimeout(()=>D2(G),0)}},q=B=>{const ne=J.getState(),he=ne.conversations[B.conversationId]?.parentId;he&&ne.conversations[he]?(ne.selectConversation(he),ne.selectTab(he,B.conversationId)):ne.selectConversation(B.conversationId),C3({conversationId:B.conversationId,tabId:B.tabId,title:B.title||s("Browser")}),t(!1)},te=B=>{window.electronAPI.window.openSettings({category:B.category,rowId:B.id}),t(!1)},V=T.length>0&&$.length===0&&M.length===0&&A.length===0,se=B=>{B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),t(!1))},Ce=B=>{if(B.key!=="Tab"||B.nativeEvent.isComposing){se(B);return}B.altKey||B.ctrlKey||B.metaKey||(B.preventDefault(),l(ne=>ww(ne,B.shiftKey)))},de=Pr(w),re=Date.now(),Z=B=>{const ne=v.find(ve=>ve.id===B);return ne?qn(ne):""},me=(B,ne)=>[Z(B),ne?Lo(ne,r,re):""].filter(Boolean).join(" · "),xe=(B,ne)=>n.jsxs(n.Fragment,{children:[B&&n.jsx(ji,{size:"sm",className:"bg-brand/10 text-brand",children:s("Current")}),ne&&n.jsx(ji,{variant:"outline",size:"sm",children:s("Archived")})]}),Se=B=>{const ne=g[B.conversationId],ve=B.parentConversationId??ne?.parentId;let he=$m;ve&&(he=ne?.child?.mode==="task"?hp:ws);const G=B.title||ne?.child?.agentInstanceName||ne?.coworkerName||s("New conversation"),we=ve?g[ve]?.title||s("New conversation"):void 0,ce=B.field==="body"||B.field==="tool"||B.field==="id"?B.snippet.replace(/\s+/g," ").trim():"";return n.jsx(ti,{icon:he,title:n.jsxs(n.Fragment,{children:[we&&n.jsxs("span",{className:"text-muted-foreground",children:[we," › "]}),n.jsx(ia,{text:G,query:o})]}),badges:xe(B.isCurrent,B.archived),detail:ce&&n.jsx(ia,{text:ce,query:o}),meta:me(B.projectId,ne?La(ne):void 0)})},W=(B,ne)=>n.jsx(No,{value:ne,className:"gap-2.5",onClick:()=>q(B),children:n.jsx(ti,{icon:Oo,title:n.jsx(ia,{text:B.title||B.url,query:o}),meta:VJ(B.url)})},ne),H=n.jsxs("button",{type:"button",tabIndex:-1,"data-search-scope":a,title:s("Switch scope"),className:"flex h-7 shrink-0 items-center gap-1.5 rounded-md border px-2 text-muted-foreground text-xs transition-colors hover:bg-accent hover:text-foreground",onPointerDown:B=>{B.preventDefault(),B.stopPropagation(),l(ne=>ww(ne,B.shiftKey))},children:[s(zJ[a]),n.jsx(Vs,{className:"h-4 min-w-4 text-[10px]",children:"⇥"})]});return n.jsx(N2,{open:e,onOpenChange:t,children:n.jsx(S2,{className:"max-h-[min(36rem,calc(100vh-6rem))] max-w-2xl",onKeyDown:se,children:n.jsxs(C2,{children:[n.jsx(I2,{placeholder:s("Search conversations, browser tabs, settings…"),value:o,onChange:B=>i(B.currentTarget.value),onKeyDown:Ce,endAddon:H}),n.jsxs(E2,{children:[V&&n.jsxs(A2,{children:[s("No matching results"),a!=="all-including-archived"&&n.jsxs("span",{className:"mt-2 flex items-center justify-center gap-1.5 text-xs",children:[n.jsx(Vs,{children:"⇥"}),s(a==="project"?"Search all projects":"Include archived")]})]}),n.jsxs(T2,{children:[!T&&n.jsxs(n.Fragment,{children:[L.length>0&&n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Recent")}),L.map(B=>n.jsx(No,{value:`recent-${B.id}`,className:"gap-2.5",onClick:()=>U({conversationId:B.id,field:"title",snippet:B.title}),children:n.jsx(ti,{icon:$m,title:B.title||s("New conversation"),badges:xe(B.id===x,B.archived),meta:me(B.projectId,La(B))})},B.id))]}),R.length>0&&n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Browser")}),R.map(B=>W(B,`recent-browser-${B.tabId}`))]}),n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Actions")}),n.jsxs(No,{value:"new-conversation",className:"gap-2.5",onClick:()=>{j&&J.getState().newConversation(j),t(!1)},children:[n.jsx(ti,{icon:Qn,title:n.jsxs(n.Fragment,{children:[s("New conversation"),Z(j)&&n.jsxs("span",{className:"text-muted-foreground",children:[" · ",Z(j)]})]})}),n.jsx(vy,{children:qs(de["new-conversation"])})]}),n.jsxs(No,{value:"open-settings",className:"gap-2.5",onClick:()=>{window.electronAPI.window.openSettings(),t(!1)},children:[n.jsx(ti,{icon:Os,title:s("Open settings")}),n.jsx(vy,{children:qs(de["open-settings"])})]})]})]}),T.length>0&&$.length>0&&n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Conversations")}),$.map(B=>n.jsx(No,{value:`conv-${B.conversationId}-${B.field}`,className:"gap-2.5",onClick:()=>U(B),children:Se(B)},`${B.conversationId}-${B.field}`))]}),T.length>0&&M.length>0&&n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Browser")}),M.map(B=>W(B,`browser-${B.tabId}`))]}),T.length>0&&A.length>0&&n.jsxs(Zo,{children:[n.jsx(ei,{children:s("Settings")}),A.map(B=>n.jsx(No,{value:`settings-${B.id}`,className:"gap-2.5",onClick:()=>te(B),children:n.jsx(ti,{icon:Os,title:n.jsx(ia,{text:s(B.title),query:o}),detail:B.description&&n.jsx(ia,{text:s(B.description),query:o}),meta:s($J[B.category]??B.category)})},B.id))]})]})]}),n.jsxs(R2,{children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsxs(Yj,{children:[n.jsx(Vs,{children:"↑"}),n.jsx(Vs,{children:"↓"})]}),s("Navigate")]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx(Vs,{children:"↵"}),s("Open")]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx(Vs,{children:"⇥"}),s("Switch scope")]})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx(Vs,{children:"esc"}),s("Close")]})]})]})})})}function WJ(){const{t:e}=z(),[t,s]=f.useState("choose"),[r,o]=f.useState(!1),[i,a]=f.useState(null),l=kt(g=>g.focusedId)??void 0,c=kt(g=>g.secretaries),u=l?{secretaryId:l}:{},d=f.useMemo(()=>I3(T3(e("Secretary"),c.filter(g=>g.id!==l).map(g=>g.name))),[e,c,l]),m=g=>g==="name-taken"?e("Another secretary already uses this name."):g,h=async()=>{o(!0),a(null);try{if(!await kt.getState().newSecretaryConversation({greeting:!0,...u})){a(e("Could not start the secretary. Try again."));return}kt.getState().closeWelcome()}catch{a(e("Could not start the secretary. Try again."))}finally{o(!1)}},p=async g=>{o(!0),a(null);try{const x=await window.electronAPI.secretary.saveProfile(g,l);if(!x.ok){a(m(x.error));return}const v=kt.getState();if(!await(l?v.newSecretaryConversation(u):v.newSecretaryConversation())){a(e("Could not start the secretary. Try again."));return}kt.getState().closeWelcome()}catch{a(e("Could not start the secretary. Try again."))}finally{o(!1)}};return n.jsx("div",{"data-enso":"secretary-welcome",className:"absolute inset-0 z-10 overflow-y-auto bg-background",style:{backgroundColor:"var(--background)"},children:n.jsxs("div",{className:"mx-auto flex min-h-full w-full max-w-2xl flex-col justify-center gap-6 px-6 py-10",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(Fd,{name:e("Secretary"),color:d.avatar?.color,className:"size-10"}),n.jsx("h2",{className:"text-lg font-medium",children:e("Set up your secretary")}),n.jsx("p",{className:"max-w-lg text-sm text-muted-foreground",children:e("The secretary is not part of any project. It watches your projects, dispatches sessions and reports results back. It never reads or writes code itself.")})]}),t==="choose"?n.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[n.jsxs("button",{type:"button","data-enso":"secretary-welcome-form",disabled:r,onClick:()=>s("form"),className:"rounded-lg border px-4 py-3 text-left transition-colors hover:border-brand/50 hover:bg-muted/40 disabled:opacity-50",children:[n.jsx("span",{className:"text-sm font-medium",children:e("Set up with a form")}),n.jsx("span",{className:"mt-1 block text-xs text-muted-foreground",children:e("One page: name, avatar, visible projects and patrol. Every field has a default.")})]}),n.jsxs("button",{type:"button","data-enso":"secretary-welcome-chat",disabled:r,onClick:()=>{h()},className:"rounded-lg border px-4 py-3 text-left transition-colors hover:border-brand/50 hover:bg-muted/40 disabled:opacity-50",children:[n.jsx("span",{className:"text-sm font-medium",children:e("Set up by chatting")}),n.jsx("span",{className:"mt-1 block text-xs text-muted-foreground",children:e("The secretary asks a few questions and hands you a profile card to confirm.")})]})]}):n.jsx(Jw,{initialDraft:d,submitLabel:e("Start"),onSubmit:g=>{p(g)},busy:r,error:i,allowDefaults:!0,onCancel:()=>s("choose")}),t==="choose"?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("button",{type:"button","data-enso":"secretary-welcome-defaults",disabled:r,onClick:()=>{p(d)},className:"text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",children:[e("Use all defaults and start")," →"]}),i?n.jsx("p",{className:"text-xs text-destructive",children:i}):null]}):null,n.jsx("button",{type:"button","data-enso":"secretary-welcome-later",onClick:()=>kt.getState().closeWelcome(),className:"w-fit text-xs text-muted-foreground transition-colors hover:text-foreground",children:e("Later")})]})})}const UJ=/!\[[^\]]*\]\(\s*<?((?:file:\/\/)?\/[^)>\s]+)>?\s*\)/gu;function qJ(e){if(!e.startsWith("file://"))return e;const t=e.slice(7);try{return decodeURIComponent(t)}catch{return t}}function GJ(e){return e.replace(UJ,(t,s)=>`\`${qJ(s).split("/").pop()||s}\``)}const aa="inline-flex h-[18px] max-w-full items-center gap-1 rounded-full bg-foreground/[0.06] px-1.5 font-medium",LI={verified:"Verified",mismatch:"Mismatch",unverifiable:"Could not verify"},KJ={verified:"text-success",mismatch:"text-destructive",unverifiable:"text-warning"},YJ={"pr-state":"PR","pr-squash":"squash","pr-branch":"branch",commit:"sha",screenshot:"img",ci:"CI"};function XJ(e){return e.slice(0,7)}function QJ(e,t,s){return e?.find(r=>r.kind===t&&r.ref===s)}function JJ({view:e,detail:t=!1,hideNeedsUser:s=!1}){const{t:r}=z(),o=e.result,i=o.screenshots?.length??0,a=!t&&!s&&kF(e)?(o.needsUser??[]).filter(l=>l.trim()):[];return n.jsxs("div",{"data-enso":"secretary-goal-result",className:"flex flex-col gap-1.5 text-[11.5px]",children:[t&&o.summary&&n.jsx("p",{className:"text-[13px]",children:o.summary}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-muted-foreground",children:[a.length>0&&n.jsxs("span",{"data-enso":"secretary-goal-needs-user",className:_(aa,"text-warning"),title:a.join(`
|
|
112
|
-
`),children:[r("Needs the user"),": ",a[0]]}),(o.prs??[]).map(l=>n.jsxs("a",{href:`https://github.com/${l.repo}/pull/${l.number}`,target:"_blank",rel:"noreferrer",className:_(aa,"text-foreground hover:underline"),children:[l.repo,"#",l.number,t&&l.state?` ${l.state}`:""]},`${l.repo}#${l.number}`)),(o.commits??[]).map(l=>n.jsx("span",{title:l,className:_(aa,"font-mono"),children:XJ(l)},l)),i>0&&n.jsx("span",{className:aa,children:r("{{count}} screenshots",{count:i})}),(e.checks??[]).map(l=>n.jsxs("span",{"data-enso":"secretary-goal-check","data-status":l.status,className:_(aa,KJ[l.status]),title:[l.ref,l.detail].filter(Boolean).join(" · "),children:[YJ[l.kind]," ",r(LI[l.status])]},`${l.kind}:${l.ref}:${l.status}:${l.detail??""}`))]}),t&&n.jsx(ZJ,{result:o,checks:e.checks})]})}function ZJ({result:e,checks:t}){const{t:s}=z(),r=[],o=e.checks?.tests;o&&(o.passed!==void 0||o.failed!==void 0)&&r.push(`${s("Tests")} ${o.passed??0} passed, ${o.failed??0} failed${o.note?` ${o.note}`:""}`);const i=e.checks?.ci;if(i){const a=i.runId?QJ(t,"ci",String(i.runId)):void 0;r.push(["CI",i.runId,i.conclusion,i.repo,a?s(LI[a.status]):""].filter(l=>l!==void 0&&l!=="").join(" "))}if(e.deploy){const a=[e.deploy.needed?"needed":"",e.deploy.phone?"phone":"",e.deploy.relay?"relay":"",e.deploy.note??""].filter(Boolean);a.length>0&&r.push(`${s("Deploy")} ${a.join(" ")}`)}return n.jsxs("div",{className:"flex flex-col gap-1 text-[12px] text-muted-foreground",children:[r.map(a=>n.jsx("p",{children:a},a)),(e.followUps??[]).map(a=>n.jsxs("p",{children:[s("Follow-up"),": ",a]},`follow:${a}`)),(e.needsUser??[]).map(a=>n.jsxs("p",{children:[s("Needs the user"),": ",a]},`need:${a}`))]})}const eZ={OPEN:"PR open",MERGED:"PR merged",CLOSED:"PR closed"},kw="mb-1.5 text-[12px] font-medium text-muted-foreground",_I="aspect-video w-full overflow-hidden rounded-md border border-border bg-muted/40",Nw=_(_I,"flex flex-col items-center justify-center gap-1 text-[11.5px] text-muted-foreground"),_d=e=>String(e).padStart(2,"0"),BI=e=>{const t=new Date(e);return`${_d(t.getMonth()+1)}-${_d(t.getDate())}`},tZ=e=>{const t=new Date(e);return`${BI(e)} ${_d(t.getHours())}:${_d(t.getMinutes())}`};function Sw(e,t,s){const r=tZ(t.at);if(t.imagesGoneAt===void 0)return e("Completed {{done}}",{done:r});const o=BI(t.imagesGoneAt);return s==="expired"&&t.retentionDays?e("Completed {{done}}, kept for {{days}} days, cleaned up on {{gone}}",{done:r,days:t.retentionDays,gone:o}):e("Completed {{done}}, cleaned up on {{gone}}",{done:r,gone:o})}function nZ({conversationId:e,fallback:t}){const{t:s}=z(),[r,o]=f.useState(void 0),[i,a]=f.useState(()=>new Set);f.useEffect(()=>{let x=!0;return o(void 0),a(new Set),window.electronAPI.secretary.doneReport(e).then(v=>{x&&o(v.ok?v.result:null)}).catch(()=>x&&o(null)),()=>{x=!1}},[e]);const l=r?.report??null,c=l?.text??t,u=l?.images??[],d=u.flatMap(x=>"gone"in x&&x.gone?[x.gone]:[]),m=d.length>0&&u.every(x=>!("name"in x)||!!x.gone),h=d.includes("expired")?"expired":"cleared",p=new Map,g=u.filter(x=>!(m&&"gone"in x&&x.gone)).map(x=>{const v="name"in x?x.name:`missing:${x.label}`,b=(p.get(v)??0)+1;return p.set(v,b),{image:x,key:b>1?`${v}#${b}`:v}});return n.jsx("div",{"data-enso":"session-peek-result",className:"min-h-0 flex-1 overflow-y-auto border-t px-6 py-4 max-sm:px-4",children:r===void 0?n.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("Loading…")}):n.jsxs("div",{className:"flex flex-col gap-4",children:[r?.pr&&n.jsxs("div",{"data-enso":"done-report-pr",className:"flex flex-wrap items-center gap-2 text-[12.5px]",children:[r.pr.state==="MERGED"?n.jsx(cB,{className:"size-3.5 text-brand"}):n.jsx(uB,{className:"size-3.5 text-success"}),n.jsxs("a",{href:r.pr.url,target:"_blank",rel:"noreferrer",className:"font-medium underline-offset-2 hover:underline",children:["PR #",r.pr.number]}),r.pr.state&&n.jsx("span",{className:"text-muted-foreground",children:s(eZ[r.pr.state])}),r.pr.mergeSha&&n.jsx("span",{"data-enso":"done-report-sha",title:r.pr.mergeSha,className:"rounded bg-muted px-1.5 font-mono text-[11.5px]",children:r.pr.mergeSha.slice(0,7)})]}),l?.goalResult&&n.jsx(JJ,{view:l.goalResult,detail:!0}),c?n.jsx("div",{"data-enso":"done-report-text",className:"min-w-0 text-[13px]",children:n.jsx(Dn,{text:GJ(c)})}):n.jsx("p",{className:"text-[13px] text-muted-foreground",children:s("No report was saved")}),l&&u.length>0&&n.jsxs("section",{"data-enso":"done-report-images",children:[n.jsx("div",{className:kw,children:s("Screenshots")}),m&&n.jsxs("div",{"data-enso":"done-report-images-gone",className:"flex items-center gap-3 rounded-md border border-dashed border-border bg-muted/40 px-4 py-3",children:[n.jsx(gd,{className:"size-5 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-[13px] font-medium",children:h==="expired"?s("{{count}} screenshots expired",{count:d.length}):s("{{count}} screenshots were cleaned up",{count:d.length})}),n.jsx("div",{className:"text-[12px] text-muted-foreground",children:Sw(s,l,h)})]})]}),g.length>0&&n.jsx("div",{className:_("grid grid-cols-3 gap-2 max-sm:grid-cols-2",m&&"mt-2"),children:g.map(({image:x,key:v})=>{const b=n.jsx("figcaption",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:x.label});return"name"in x&&x.gone?n.jsxs("figure",{className:"min-w-0",children:[n.jsxs("div",{"data-enso":"done-report-expired",title:Sw(s,l,x.gone),className:Nw,children:[n.jsx(Uo,{className:"size-4 opacity-70"}),x.gone==="expired"?s("Expired"):s("Cleaned up")]}),b]},v):"name"in x&&!i.has(x.name)?n.jsxs("figure",{className:"min-w-0",children:[n.jsx(El,{src:A3(e,x.name,l.at),alt:x.label,title:x.label,lazy:!0,frameClassName:_(_I,"block"),className:"size-full object-cover",onError:()=>a(w=>new Set(w).add(x.name))}),b]},v):n.jsxs("figure",{className:"min-w-0",children:[n.jsxs("div",{"data-enso":"done-report-missing",className:Nw,children:[n.jsx(gd,{className:"size-4 opacity-70"}),s("Image unavailable")]}),b]},v)})})]}),r?.files&&r.files.length>0&&n.jsxs("section",{"data-enso":"done-report-files",children:[n.jsx("div",{className:kw,children:s("Changed files ({{count}})",{count:r.files.length+(r.moreFiles??0)})}),n.jsx("ul",{className:"flex flex-col rounded-md border border-border text-[12px]",children:r.files.map(x=>n.jsxs("li",{"data-enso":"done-report-file",className:"flex min-w-0 items-center gap-2 border-b border-border px-2 py-1 last:border-b-0",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:x.path,children:x.path}),x.additions===null?n.jsx("span",{className:"shrink-0 text-muted-foreground",children:s("Binary")}):n.jsxs("span",{className:"shrink-0 font-mono tabular-nums",children:[n.jsxs("span",{className:"text-success",children:["+",x.additions]})," ",n.jsxs("span",{className:"text-destructive",children:["−",x.deletions]})]})]},x.path))}),r.moreFiles?n.jsx("p",{className:"mt-1 text-[11.5px] text-muted-foreground",children:s("{{count}} more files",{count:r.moreFiles})}):null]})]})})}const sZ={waiting:{label:"Waiting for you",className:"bg-warning/15 text-warning"},running:{label:"Running",className:"bg-success/15 text-success"},failed:{label:"Failed",className:"bg-destructive/15 text-destructive"},done:{label:"Completed",className:"bg-muted text-muted-foreground"}},rZ={active:"working",paused:"paused",waiting:"waiting",blocked:"blocked",completed:"completed"},xc="shrink-0 rounded px-1.5 py-px text-[11px]",oZ=[{key:"result",label:"Result"},{key:"session",label:"Session"}];function iZ(e){return(e.pendingApprovals?.length??0)>0||(e.pendingAsks?.length??0)>0?"waiting":e.status==="running"||e.spawning?"running":e.status==="failed"?"failed":"done"}function aZ(){const{t:e}=z(),t=Ur(k=>k.conversationId),s=Ur(k=>k.close),r=Ur(k=>k.result),o=Ur(k=>k.result?k.tab:"session"),i=Ur(k=>k.setTab),a=J(k=>t?k.conversations[t]:void 0),l=pe(k=>a?k.projects.find(L=>L.id===a.projectId):void 0),c=!!a,u=a?.archived===!0;f.useEffect(()=>t&&c?E3(t,{readOnly:u}):void 0,[t,c,u]);const d=f.useRef(null),m=f.useMemo(()=>({sessionId:t,canRewind:!1,canRetry:!1,canFork:!1}),[t]),h=Ur(k=>k.from),p=()=>{t&&(u&&J.getState().toggleArchiveConversation(t),sl(t,h??void 0))},g=a?null:e("This session no longer exists, or you do not have access to it"),x=a?sZ[iZ(a)]:null,v=a?.worktree?.name||a?.worktree?.branch,b=a?.goal,w=a?.pendingApprovals??[],j=a?.pendingAsks??[],T=c&&!u&&t&&(w.length>0||j.length>0),N=r&&n.jsx("div",{role:"tablist","data-enso":"session-peek-tabs",className:"inline-flex w-fit rounded-md bg-muted p-0.5 text-[12px]",children:oZ.map(k=>n.jsx("button",{type:"button",role:"tab","aria-selected":o===k.key,"data-enso":`session-peek-tab-${k.key}`,onClick:()=>i(k.key),className:_("rounded-[5px] px-2.5 py-0.5 transition-colors",o===k.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:e(k.label)},k.key))}),S=(a||N)&&n.jsxs("div",{"data-enso":"session-peek-meta",className:"flex flex-col gap-1.5",children:[N,a&&n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 text-muted-foreground",children:[x&&n.jsx("span",{"data-enso":"session-peek-status",className:_(xc,x.className),children:e(x.label)}),l&&n.jsx("span",{"data-enso":"session-peek-project",className:_(xc,"bg-muted"),children:qn(l)}),v&&n.jsxs("span",{"data-enso":"session-peek-branch",className:_(xc,"inline-flex items-center gap-1 bg-muted font-mono"),children:[n.jsx(Hs,{className:"size-3"}),v]})]}),b&&n.jsxs("p",{"data-enso":"session-peek-goal",className:"truncate text-[12px] text-muted-foreground",children:[e("Goal")," · ",b.text," · ",e(rZ[b.status]),b.status==="active"&&b.autoTurns>0?` · ${b.autoTurns}/25`:""]})]}),I=a&&n.jsxs("div",{"data-enso":"session-peek-actions",className:"flex shrink-0 flex-col items-end gap-1 sm:flex-row-reverse sm:items-center sm:gap-2",children:[n.jsxs("button",{type:"button","data-enso":"session-peek-open",onClick:p,className:"inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[12px] text-primary-foreground transition-colors hover:bg-primary/90",children:[n.jsx(Bi,{className:"size-3.5"}),e(u?"Restore and open":"Open session")]}),u&&n.jsxs("span",{"data-enso":"session-peek-archived",className:_(xc,"inline-flex items-center gap-1 bg-muted text-muted-foreground"),children:[n.jsx(lr,{className:"size-3"}),e("Archived · read-only")]})]});return n.jsx(v2,{dataEnso:"session-peek",conversationId:t,title:a?.title||r?.title||e("Unnamed"),meta:S,actions:I,footer:T?n.jsxs("div",{"data-enso":"session-peek-pending",className:"pb-3",children:[n.jsxs("div",{className:"mb-1 flex items-center gap-1.5 text-[12px] font-medium text-warning",children:[n.jsx(Do,{className:"size-3.5"}),e("Needs your approval or answer")]}),n.jsx(px,{approvals:w,allowSession:a?.child?.lockedProfileId===void 0,onRespond:(k,L)=>{window.electronAPI.agent.respondApproval(t,k,L)}}),n.jsx(xx,{asks:j,autoFocus:!1,onAnswer:(k,L)=>{window.electronAPI.agent.respondAsk(t,k,L)}})]}):void 0,onClose:s,children:o==="result"&&t?n.jsx(nZ,{conversationId:t,fallback:r?.fallback}):g?n.jsx("p",{"data-enso":"session-peek-unavailable",className:"flex flex-1 items-center justify-center border-t px-6 text-center text-[13px] text-muted-foreground",children:g}):t?n.jsx(gu.Provider,{value:m,children:n.jsx("div",{className:"@container flex min-h-0 flex-1 flex-col border-t",children:n.jsx(B2,{peek:!0,readOnly:u,conversationId:t,cwd:a?.worktree?.path??l?.path,emptyTitle:a?.title||e("Unnamed"),timelineRef:d})})}):null})}function sg(){return Nr()&&J.persist.hasHydrated()&&pe.persist.hasHydrated()}function Cw(e,t){sg()&&e>0&&(async()=>(t&&await J.getState().refreshWorktreeStatuses(),await J.getState().autoArchiveStaleConversations()))()}function Iw(e){!sg()||!(e>0)||J.getState().autoDeleteStaleArchived()}function lZ(){const e=pe(r=>r.autoArchiveIdleDays),t=pe(r=>r.autoArchiveMergedWorktrees),s=pe(r=>r.autoDeleteArchivedDays);f.useEffect(()=>{if(sg()){Cw(e,t),Iw(s);return}const r=()=>{Cw(e,t),Iw(s)},o=[J.persist.onFinishHydration(r),pe.persist.onFinishHydration(r)];return()=>{for(const i of o)i()}},[e,t,s])}function cZ(){const e=J(t=>Math.min(999,R3(t.order,fu(t.conversations))));f.useEffect(()=>{window.electronAPI.app.setBadgeCount(e)},[e])}function dZ(){const e=pe(s=>s.generationStallTimeoutMin),{t}=z();f.useEffect(()=>{if(e<=0)return;const s=new Set,r=new Set,o=new Map,i=setInterval(()=>{if(!Nr())return;const a=e*6e4,l=Date.now(),c=J.getState();for(const u of Object.values(c.conversations)){u.status==="running"&&u.lastOutputAt&&o.delete(u.id);const d=(u.coworkerIds??[]).some(h=>!!c.conversations[h]?.spawning),m=M3({shouldAbort:P3({status:u.status,spawning:u.spawning,lastOutputAt:L3(u,c.conversations),now:l,timeoutMs:a,hasLiveWork:D3({...O3(u),spawningCoworker:d})}),status:u.status,spawning:u.spawning,pendingRetry:r.has(u.id),attempts:o.get(u.id)??0});if(m==="abort"){if(s.has(u.id))continue;s.add(u.id),r.add(u.id),window.electronAPI.agent.abort(u.id).finally(()=>{s.delete(u.id)}),Ie(Tw(u,t("No output for {{minutes}} minutes — retrying",{minutes:e})));continue}if(m==="retry"){r.delete(u.id),o.set(u.id,(o.get(u.id)??0)+1),c.retry(u.id);continue}m==="give-up"&&(r.delete(u.id),o.delete(u.id),Ie(Tw(u,t("Stopped after repeated stalls"))))}},1e3);return()=>clearInterval(i)},[e,t])}function Tw(e,t){const s=(e.coworkerName||e.title).split(`
|
|
113
|
-
`)[0].trim();return s?{type:"warning",title:s,description:t}:{type:"warning",title:t}}function uZ(e){return{at:e.exitAt,kind:e.kind,unfinishedTools:[...e.unfinishedTools],...e.suppressedError?{suppressedError:e.suppressedError}:{}}}function fZ(e){return e?e.status!=="running":!1}const mZ=3e4;function hZ(e,t=mZ){return e()?Promise.resolve(!0):new Promise(s=>{const r=l=>{clearTimeout(a);for(const c of i)c();s(l)},o=()=>e()&&r(!0),i=[J.subscribe(o),zo.subscribe(o),pe.subscribe(o)],a=setTimeout(()=>r(e()),t)})}function pZ(){const e=zo.getState().snapshot.availability.status;return J.persist.hasHydrated()&&pe.persist.hasHydrated()&&e!=="unloaded"&&e!=="loading"}function xZ(){const{t:e}=z();f.useEffect(()=>{Nr()&&(async()=>{const t=await window.electronAPI.agent.takeInterruptedTurns().catch(()=>[]);if(t.length===0||!await hZ(pZ))return;const s=new Set;for(const r of t)fZ(J.getState().conversations[r.conversationId])&&(s.add(r.conversationId),J.setState(o=>{const i=o.conversations[r.conversationId];return!i||i.status==="running"?o:{conversations:{...o.conversations,[r.conversationId]:{...i,status:"interrupted",interrupted:uZ(r),error:void 0}}}}));s.size!==0&&Ie({type:"info",title:e("{{count}} conversation(s) interrupted by app exit",{count:s.size})})})()},[e])}const gZ=3e4;function vZ(e,t=gZ){return e()?Promise.resolve(!0):new Promise(s=>{const r=l=>{clearTimeout(a);for(const c of i)c();s(l)},o=()=>e()&&r(!0),i=[J.subscribe(o),pe.subscribe(o)],a=setTimeout(()=>r(e()),t)})}function bZ(){return J.persist.hasHydrated()&&pe.persist.hasHydrated()}function yZ(){const{t:e}=z();f.useEffect(()=>{if(!Nr())return;const t=()=>{qm(async()=>{if(!await vZ(bZ))return;const r=await window.electronAPI.window.takeOpenFolders().catch(()=>[]);let o=!1;for(const i of r)try{if(!await qN(i)){Ie({type:"error",title:e("Failed to add project")});continue}o=!0}catch(a){Ie({type:"error",title:e("Failed to add project"),description:a instanceof Error?a.message:String(a)})}o&&rx()})},s=window.electronAPI.window.onOpenFolderRequested(t);return t(),s},[e])}const Aw="enso-win",FI="enso-win-flush",gc="enso-win-pending",Ew="enso-win-native";function wZ(e,t,s){return{maximized:s.maximized?e.maximized:t.maximized,fullscreen:s.fullscreen?e.fullscreen:t.fullscreen}}function jZ(e,t){return e||t}function kZ(e,t){document.documentElement.classList.toggle(FI,jZ(e,t))}function NZ(){f.useEffect(()=>{if(window.electronAPI?.env.platform!=="win32")return;const e=document.documentElement;e.classList.add(Aw,gc),e.classList.add(Ew);let t={maximized:!1,fullscreen:!1};const s={maximized:0,fullscreen:0};let r=!1,o=0,i;const a=()=>kZ(t.maximized,t.fullscreen),l=window.electronAPI.window,c=()=>{const h=++o,p={...s};Promise.all([l.isMaximized(),l.isFullScreen()]).then(([g,x])=>{r||h!==o||(t=wZ(t,{maximized:g,fullscreen:x},{maximized:s.maximized!==p.maximized,fullscreen:s.fullscreen!==p.fullscreen}),e.classList.remove(gc),a())}).catch(()=>{!r&&h===o&&e.classList.remove(gc)})};c();const u=()=>{i&&clearTimeout(i),i=setTimeout(c,50)};window.addEventListener("resize",u);const d=l.onMaximizedChange(h=>{s.maximized+=1,t.maximized=h,a()}),m=l.onFullScreenChange(h=>{s.fullscreen+=1,t.fullscreen=h,a()});return()=>{r=!0,i&&clearTimeout(i),window.removeEventListener("resize",u),d(),m(),e.classList.remove(Aw,FI,gc,Ew)}},[])}const Rw=new Set;function SZ(e){return Rw.add(e),()=>Rw.delete(e)}function CZ(e,t){const s=new Set,r=[];for(const o of e)for(const i of o.interceptBreakers??[]){const a=`${o.id}:${i.event}:${i.until}`;s.add(a),t.has(a)||r.push({pluginName:o.name,event:i.event})}t.clear();for(const o of s)t.add(o);return r}function IZ(e,t){let s=0;for(const r of t)e.length>r.length&&e.endsWith(r)&&r.length>s&&(s=r.length);return s}function bee(e,t){const s=(e.split("/").at(-1)??"").toLowerCase();return t.map(r=>({viewer:r,length:IZ(s,r.extensions)})).filter(r=>r.length>0).sort((r,o)=>o.length-r.length).map(r=>r.viewer)}const yee=e=>`${e.pluginId}:${e.id}`;let zI=[];const Ih=new Set;function Mw(e){zI=e;for(const t of Ih)t()}function TZ(e){return Ih.add(e),()=>Ih.delete(e)}const Pw=()=>zI;function wee(){return f.useSyncExternalStore(TZ,Pw,Pw)}function Dw(e){const t=e.permissions.includes("composer.draft")?"1":"0";return`${e.id}\0${e.version}\0${e.build}\0${e.renderer??""}\0${t}`}function $I(e,t){try{t?.dispose()}catch(s){console.warn(`[plugin] ${e} 渲染模块卸载失败`,s)}}async function AZ(e,t,s,r){if(!r())return;const o=new Map;for(const a of t)a.state==="enabled"&&a.renderer&&o.set(a.id,{...a,renderer:a.renderer});const i=[];for(const[a,l]of e){const c=o.get(a);(!c||Dw(c)!==l.key)&&i.push(a)}for(const a of i)$I(a,e.get(a)),e.delete(a);await Promise.allSettled([...o.values()].filter(a=>!e.has(a.id)).map(async a=>{if(!r())return;let l;try{l=await s(a)}catch(d){if(!r())return;console.warn(`[plugin] ${a.id} 渲染模块加载失败`,d);return}if(!r()){l.dispose();return}const c=Dw(a),u=e.get(a.id);if(u?.key===c){l.dispose();return}u?.dispose(),e.set(a.id,{key:c,dispose:()=>l.dispose()})}))}const Jn=(e,t)=>({ok:!1,code:e,error:t});async function EZ(e,t){if(e.op==="focusSession"){const a=e.payload.sessionId;if(typeof a!="string"||!a)return Jn("BAD_REQUEST","缺少会话 id");const l=t.conversation(a);if(l)return t.focus(l.parentId??a,a),{ok:!0,value:null};const c=a.indexOf("::");if(c>0){const u=a.slice(0,c);return t.conversation(u)?(t.focusSubagent(u,a),{ok:!0,value:null}):Jn("NOT_FOUND","会话不在本窗口")}return Jn("NOT_FOUND","会话不在本窗口")}if(e.op==="openChildRun"){const a=e.payload.parentId,l=e.payload.childId;return typeof a!="string"||!a?Jn("BAD_REQUEST","缺少父会话 id"):typeof l!="string"||!l?Jn("BAD_REQUEST","缺少子会话 id"):t.conversation(a)?(t.openChildRun(a,l),{ok:!0,value:null}):Jn("NOT_FOUND","会话不在本窗口")}if(e.op==="focusSubagent"){const a=e.payload.sessionId,l=e.payload.agentId;return typeof a!="string"||!t.conversation(a)?Jn("NOT_FOUND","会话不在本窗口"):typeof l!="string"||!l?Jn("BAD_REQUEST","缺少子代理 id"):(t.focusSubagent(a,l),{ok:!0,value:null})}if(e.op==="ensureSession"){const a=t.conversation(e.sessionId);if(!a)return Jn("NOT_FOUND","会话不在本窗口");if(a.parentId)return Jn("UNSUPPORTED","子会话随主会话恢复");const l=await t.ensure(e.sessionId);return l?Jn("SESSION_FAILED",l):{ok:!0,value:null}}if(e.op==="openPluginView"){if(!t.conversation(e.sessionId))return Jn("NOT_FOUND","会话不在本窗口");const{pluginId:a,viewId:l,title:c}=e.payload;return typeof a!="string"||!a||typeof l!="string"||!l||typeof c!="string"||!c?Jn("BAD_REQUEST","缺少视图标识"):(t.openPluginView?.(e.sessionId,{pluginId:a,viewId:l,title:c}),{ok:!0,value:null})}if(e.op==="closePluginView"){if(!t.conversation(e.sessionId))return Jn("NOT_FOUND","会话不在本窗口");const{pluginId:a,viewId:l}=e.payload;return typeof a!="string"||!a||typeof l!="string"||!l?Jn("BAD_REQUEST","缺少视图标识"):(t.closePluginView?.(e.sessionId,{pluginId:a,viewId:l}),{ok:!0,value:null})}const s=t.conversation(e.sessionId);if(!s)return Jn("NO_SESSION","发起调用的会话不在本窗口");const r=typeof e.payload.presetId=="string"?e.payload.presetId:void 0,o=await t.create(s.projectId,r);if(!o)return Jn("CREATE_FAILED","新建会话失败");const i=e.payload.text;return typeof i=="string"&&i&&t.prefill(o,i),{ok:!0,value:{sessionId:o}}}const RZ={conversation:e=>J.getState().conversations[e]??null,focus:(e,t)=>{const s=J.getState();s.selectConversation(e),t!==e&&s.selectTab(e,t)},focusSubagent:(e,t)=>J.getState().focusSubagent(e,t),openChildRun:(e,t)=>J.getState().openChildRun(e,t),create:(e,t)=>J.getState().newConversation(e,t?{presetId:t}:void 0),prefill:$3,ensure:async e=>{const t=J.getState(),s=t.conversations[e];if(s?.started||s?.spawning)return null;await t.resumeConversation(e,{fresh:!0});const r=J.getState().conversations[e];return r?.started||r?.spawning?null:r?.error??"无法启动会话:请检查默认模型与登录状态"},openPluginView:(e,t)=>H3({conversationId:e,...t}),closePluginView:(e,t)=>V3({conversationId:e,...t})};function MZ(){return f.useEffect(()=>{const e=U3(()=>dK(J.getState()));let t=0;const s=new Map,r=new Set,o=()=>{const l=++t;window.electronAPI.extensionPlugins.list().then(async c=>{if(l!==t)return;for(const{pluginName:d,event:m}of CZ(c,r))Ie({type:"warning",title:`插件 ${d} 的检查连续失败,已临时放行`,description:`${m} 事件 30 秒内不再经过该插件;详情见设置里的插件日志`});const u=c.filter(d=>d.state==="enabled");B3(Object.fromEntries(c.flatMap(d=>d.icon?[[d.id,d.icon]]:[]))),Gg(F3(c)),Iy(MK(c)),Kg(u.flatMap(d=>d.views.map(m=>({pluginId:d.id,pluginName:d.name,...m})))),z3(c),Mw(u.flatMap(d=>(d.fileViewers??[]).map(m=>({pluginId:d.id,pluginName:d.name,...m})))),Ey(u.flatMap(d=>d.triggers.filter(m=>m.symbol==="#").map(m=>({pluginId:d.id,name:m.name})))),await AZ(s,c,d=>W3(d.id,d.renderer,e,{draft:d.permissions.includes("composer.draft")}),()=>l===t)})};o();const i=window.electronAPI.extensionPlugins.onChanged(o),a=window.electronAPI.extensionPlugins.onDraftRequest(l=>{if(l.op==="focusSession"||l.op==="focusSubagent"||l.op==="openChildRun"||l.op==="createSession"||l.op==="ensureSession"||l.op==="openPluginView"||l.op==="closePluginView"){EZ(l,RZ).catch(c=>({ok:!1,code:"SESSION_FAILED",error:c instanceof Error?c.message:String(c)})).then(c=>window.electronAPI.extensionPlugins.respondDraft({requestId:l.requestId,...c}));return}window.electronAPI.extensionPlugins.respondDraft({requestId:l.requestId,..._3(l)})});return()=>{t+=1,i(),a(),Gg([]),Ey([]),Kg([]),Mw([]),Iy([]);for(const[l,c]of s)$I(l,c);s.clear()}},[]),null}function PZ(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Zf={exports:{}};const DZ={},OZ=Object.freeze(Object.defineProperty({__proto__:null,default:DZ},Symbol.toStringTag,{value:"Module"})),LZ=q3(OZ);var Ow;function _Z(){return Ow||(Ow=1,(function(e){(function(t){var s=function(C){var D,P=new Float64Array(16);if(C)for(D=0;D<C.length;D++)P[D]=C[D];return P},r=function(){throw new Error("no PRNG")},o=new Uint8Array(16),i=new Uint8Array(32);i[0]=9;var a=s(),l=s([1]),c=s([56129,1]),u=s([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),d=s([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),m=s([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),h=s([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),p=s([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(C,D,P,y){C[D]=P>>24&255,C[D+1]=P>>16&255,C[D+2]=P>>8&255,C[D+3]=P&255,C[D+4]=y>>24&255,C[D+5]=y>>16&255,C[D+6]=y>>8&255,C[D+7]=y&255}function x(C,D,P,y,E){var Y,ee=0;for(Y=0;Y<E;Y++)ee|=C[D+Y]^P[y+Y];return(1&ee-1>>>8)-1}function v(C,D,P,y){return x(C,D,P,y,16)}function b(C,D,P,y){return x(C,D,P,y,32)}function w(C,D,P,y){for(var E=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,Y=P[0]&255|(P[1]&255)<<8|(P[2]&255)<<16|(P[3]&255)<<24,ee=P[4]&255|(P[5]&255)<<8|(P[6]&255)<<16|(P[7]&255)<<24,ge=P[8]&255|(P[9]&255)<<8|(P[10]&255)<<16|(P[11]&255)<<24,Te=P[12]&255|(P[13]&255)<<8|(P[14]&255)<<16|(P[15]&255)<<24,Ve=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,He=D[0]&255|(D[1]&255)<<8|(D[2]&255)<<16|(D[3]&255)<<24,bt=D[4]&255|(D[5]&255)<<8|(D[6]&255)<<16|(D[7]&255)<<24,Xe=D[8]&255|(D[9]&255)<<8|(D[10]&255)<<16|(D[11]&255)<<24,ae=D[12]&255|(D[13]&255)<<8|(D[14]&255)<<16|(D[15]&255)<<24,Ne=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,_e=P[16]&255|(P[17]&255)<<8|(P[18]&255)<<16|(P[19]&255)<<24,Be=P[20]&255|(P[21]&255)<<8|(P[22]&255)<<16|(P[23]&255)<<24,Ze=P[24]&255|(P[25]&255)<<8|(P[26]&255)<<16|(P[27]&255)<<24,ft=P[28]&255|(P[29]&255)<<8|(P[30]&255)<<16|(P[31]&255)<<24,ht=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,ze=E,Qe=Y,Ke=ee,et=ge,lt=Te,Ye=Ve,be=He,ye=bt,Me=Xe,Ae=ae,je=Ne,De=_e,dt=Be,Nt=Ze,Rt=ft,Ct=ht,Q,It=0;It<20;It+=2)Q=ze+dt|0,lt^=Q<<7|Q>>>25,Q=lt+ze|0,Me^=Q<<9|Q>>>23,Q=Me+lt|0,dt^=Q<<13|Q>>>19,Q=dt+Me|0,ze^=Q<<18|Q>>>14,Q=Ye+Qe|0,Ae^=Q<<7|Q>>>25,Q=Ae+Ye|0,Nt^=Q<<9|Q>>>23,Q=Nt+Ae|0,Qe^=Q<<13|Q>>>19,Q=Qe+Nt|0,Ye^=Q<<18|Q>>>14,Q=je+be|0,Rt^=Q<<7|Q>>>25,Q=Rt+je|0,Ke^=Q<<9|Q>>>23,Q=Ke+Rt|0,be^=Q<<13|Q>>>19,Q=be+Ke|0,je^=Q<<18|Q>>>14,Q=Ct+De|0,et^=Q<<7|Q>>>25,Q=et+Ct|0,ye^=Q<<9|Q>>>23,Q=ye+et|0,De^=Q<<13|Q>>>19,Q=De+ye|0,Ct^=Q<<18|Q>>>14,Q=ze+et|0,Qe^=Q<<7|Q>>>25,Q=Qe+ze|0,Ke^=Q<<9|Q>>>23,Q=Ke+Qe|0,et^=Q<<13|Q>>>19,Q=et+Ke|0,ze^=Q<<18|Q>>>14,Q=Ye+lt|0,be^=Q<<7|Q>>>25,Q=be+Ye|0,ye^=Q<<9|Q>>>23,Q=ye+be|0,lt^=Q<<13|Q>>>19,Q=lt+ye|0,Ye^=Q<<18|Q>>>14,Q=je+Ae|0,De^=Q<<7|Q>>>25,Q=De+je|0,Me^=Q<<9|Q>>>23,Q=Me+De|0,Ae^=Q<<13|Q>>>19,Q=Ae+Me|0,je^=Q<<18|Q>>>14,Q=Ct+Rt|0,dt^=Q<<7|Q>>>25,Q=dt+Ct|0,Nt^=Q<<9|Q>>>23,Q=Nt+dt|0,Rt^=Q<<13|Q>>>19,Q=Rt+Nt|0,Ct^=Q<<18|Q>>>14;ze=ze+E|0,Qe=Qe+Y|0,Ke=Ke+ee|0,et=et+ge|0,lt=lt+Te|0,Ye=Ye+Ve|0,be=be+He|0,ye=ye+bt|0,Me=Me+Xe|0,Ae=Ae+ae|0,je=je+Ne|0,De=De+_e|0,dt=dt+Be|0,Nt=Nt+Ze|0,Rt=Rt+ft|0,Ct=Ct+ht|0,C[0]=ze>>>0&255,C[1]=ze>>>8&255,C[2]=ze>>>16&255,C[3]=ze>>>24&255,C[4]=Qe>>>0&255,C[5]=Qe>>>8&255,C[6]=Qe>>>16&255,C[7]=Qe>>>24&255,C[8]=Ke>>>0&255,C[9]=Ke>>>8&255,C[10]=Ke>>>16&255,C[11]=Ke>>>24&255,C[12]=et>>>0&255,C[13]=et>>>8&255,C[14]=et>>>16&255,C[15]=et>>>24&255,C[16]=lt>>>0&255,C[17]=lt>>>8&255,C[18]=lt>>>16&255,C[19]=lt>>>24&255,C[20]=Ye>>>0&255,C[21]=Ye>>>8&255,C[22]=Ye>>>16&255,C[23]=Ye>>>24&255,C[24]=be>>>0&255,C[25]=be>>>8&255,C[26]=be>>>16&255,C[27]=be>>>24&255,C[28]=ye>>>0&255,C[29]=ye>>>8&255,C[30]=ye>>>16&255,C[31]=ye>>>24&255,C[32]=Me>>>0&255,C[33]=Me>>>8&255,C[34]=Me>>>16&255,C[35]=Me>>>24&255,C[36]=Ae>>>0&255,C[37]=Ae>>>8&255,C[38]=Ae>>>16&255,C[39]=Ae>>>24&255,C[40]=je>>>0&255,C[41]=je>>>8&255,C[42]=je>>>16&255,C[43]=je>>>24&255,C[44]=De>>>0&255,C[45]=De>>>8&255,C[46]=De>>>16&255,C[47]=De>>>24&255,C[48]=dt>>>0&255,C[49]=dt>>>8&255,C[50]=dt>>>16&255,C[51]=dt>>>24&255,C[52]=Nt>>>0&255,C[53]=Nt>>>8&255,C[54]=Nt>>>16&255,C[55]=Nt>>>24&255,C[56]=Rt>>>0&255,C[57]=Rt>>>8&255,C[58]=Rt>>>16&255,C[59]=Rt>>>24&255,C[60]=Ct>>>0&255,C[61]=Ct>>>8&255,C[62]=Ct>>>16&255,C[63]=Ct>>>24&255}function j(C,D,P,y){for(var E=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,Y=P[0]&255|(P[1]&255)<<8|(P[2]&255)<<16|(P[3]&255)<<24,ee=P[4]&255|(P[5]&255)<<8|(P[6]&255)<<16|(P[7]&255)<<24,ge=P[8]&255|(P[9]&255)<<8|(P[10]&255)<<16|(P[11]&255)<<24,Te=P[12]&255|(P[13]&255)<<8|(P[14]&255)<<16|(P[15]&255)<<24,Ve=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,He=D[0]&255|(D[1]&255)<<8|(D[2]&255)<<16|(D[3]&255)<<24,bt=D[4]&255|(D[5]&255)<<8|(D[6]&255)<<16|(D[7]&255)<<24,Xe=D[8]&255|(D[9]&255)<<8|(D[10]&255)<<16|(D[11]&255)<<24,ae=D[12]&255|(D[13]&255)<<8|(D[14]&255)<<16|(D[15]&255)<<24,Ne=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,_e=P[16]&255|(P[17]&255)<<8|(P[18]&255)<<16|(P[19]&255)<<24,Be=P[20]&255|(P[21]&255)<<8|(P[22]&255)<<16|(P[23]&255)<<24,Ze=P[24]&255|(P[25]&255)<<8|(P[26]&255)<<16|(P[27]&255)<<24,ft=P[28]&255|(P[29]&255)<<8|(P[30]&255)<<16|(P[31]&255)<<24,ht=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,ze=E,Qe=Y,Ke=ee,et=ge,lt=Te,Ye=Ve,be=He,ye=bt,Me=Xe,Ae=ae,je=Ne,De=_e,dt=Be,Nt=Ze,Rt=ft,Ct=ht,Q,It=0;It<20;It+=2)Q=ze+dt|0,lt^=Q<<7|Q>>>25,Q=lt+ze|0,Me^=Q<<9|Q>>>23,Q=Me+lt|0,dt^=Q<<13|Q>>>19,Q=dt+Me|0,ze^=Q<<18|Q>>>14,Q=Ye+Qe|0,Ae^=Q<<7|Q>>>25,Q=Ae+Ye|0,Nt^=Q<<9|Q>>>23,Q=Nt+Ae|0,Qe^=Q<<13|Q>>>19,Q=Qe+Nt|0,Ye^=Q<<18|Q>>>14,Q=je+be|0,Rt^=Q<<7|Q>>>25,Q=Rt+je|0,Ke^=Q<<9|Q>>>23,Q=Ke+Rt|0,be^=Q<<13|Q>>>19,Q=be+Ke|0,je^=Q<<18|Q>>>14,Q=Ct+De|0,et^=Q<<7|Q>>>25,Q=et+Ct|0,ye^=Q<<9|Q>>>23,Q=ye+et|0,De^=Q<<13|Q>>>19,Q=De+ye|0,Ct^=Q<<18|Q>>>14,Q=ze+et|0,Qe^=Q<<7|Q>>>25,Q=Qe+ze|0,Ke^=Q<<9|Q>>>23,Q=Ke+Qe|0,et^=Q<<13|Q>>>19,Q=et+Ke|0,ze^=Q<<18|Q>>>14,Q=Ye+lt|0,be^=Q<<7|Q>>>25,Q=be+Ye|0,ye^=Q<<9|Q>>>23,Q=ye+be|0,lt^=Q<<13|Q>>>19,Q=lt+ye|0,Ye^=Q<<18|Q>>>14,Q=je+Ae|0,De^=Q<<7|Q>>>25,Q=De+je|0,Me^=Q<<9|Q>>>23,Q=Me+De|0,Ae^=Q<<13|Q>>>19,Q=Ae+Me|0,je^=Q<<18|Q>>>14,Q=Ct+Rt|0,dt^=Q<<7|Q>>>25,Q=dt+Ct|0,Nt^=Q<<9|Q>>>23,Q=Nt+dt|0,Rt^=Q<<13|Q>>>19,Q=Rt+Nt|0,Ct^=Q<<18|Q>>>14;C[0]=ze>>>0&255,C[1]=ze>>>8&255,C[2]=ze>>>16&255,C[3]=ze>>>24&255,C[4]=Ye>>>0&255,C[5]=Ye>>>8&255,C[6]=Ye>>>16&255,C[7]=Ye>>>24&255,C[8]=je>>>0&255,C[9]=je>>>8&255,C[10]=je>>>16&255,C[11]=je>>>24&255,C[12]=Ct>>>0&255,C[13]=Ct>>>8&255,C[14]=Ct>>>16&255,C[15]=Ct>>>24&255,C[16]=be>>>0&255,C[17]=be>>>8&255,C[18]=be>>>16&255,C[19]=be>>>24&255,C[20]=ye>>>0&255,C[21]=ye>>>8&255,C[22]=ye>>>16&255,C[23]=ye>>>24&255,C[24]=Me>>>0&255,C[25]=Me>>>8&255,C[26]=Me>>>16&255,C[27]=Me>>>24&255,C[28]=Ae>>>0&255,C[29]=Ae>>>8&255,C[30]=Ae>>>16&255,C[31]=Ae>>>24&255}function T(C,D,P,y){w(C,D,P,y)}function N(C,D,P,y){j(C,D,P,y)}var S=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function I(C,D,P,y,E,Y,ee){var ge=new Uint8Array(16),Te=new Uint8Array(64),Ve,He;for(He=0;He<16;He++)ge[He]=0;for(He=0;He<8;He++)ge[He]=Y[He];for(;E>=64;){for(T(Te,ge,ee,S),He=0;He<64;He++)C[D+He]=P[y+He]^Te[He];for(Ve=1,He=8;He<16;He++)Ve=Ve+(ge[He]&255)|0,ge[He]=Ve&255,Ve>>>=8;E-=64,D+=64,y+=64}if(E>0)for(T(Te,ge,ee,S),He=0;He<E;He++)C[D+He]=P[y+He]^Te[He];return 0}function k(C,D,P,y,E){var Y=new Uint8Array(16),ee=new Uint8Array(64),ge,Te;for(Te=0;Te<16;Te++)Y[Te]=0;for(Te=0;Te<8;Te++)Y[Te]=y[Te];for(;P>=64;){for(T(ee,Y,E,S),Te=0;Te<64;Te++)C[D+Te]=ee[Te];for(ge=1,Te=8;Te<16;Te++)ge=ge+(Y[Te]&255)|0,Y[Te]=ge&255,ge>>>=8;P-=64,D+=64}if(P>0)for(T(ee,Y,E,S),Te=0;Te<P;Te++)C[D+Te]=ee[Te];return 0}function L(C,D,P,y,E){var Y=new Uint8Array(32);N(Y,y,E,S);for(var ee=new Uint8Array(8),ge=0;ge<8;ge++)ee[ge]=y[ge+16];return k(C,D,P,ee,Y)}function F(C,D,P,y,E,Y,ee){var ge=new Uint8Array(32);N(ge,Y,ee,S);for(var Te=new Uint8Array(8),Ve=0;Ve<8;Ve++)Te[Ve]=Y[Ve+16];return I(C,D,P,y,E,Te,ge)}var A=function(C){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var D,P,y,E,Y,ee,ge,Te;D=C[0]&255|(C[1]&255)<<8,this.r[0]=D&8191,P=C[2]&255|(C[3]&255)<<8,this.r[1]=(D>>>13|P<<3)&8191,y=C[4]&255|(C[5]&255)<<8,this.r[2]=(P>>>10|y<<6)&7939,E=C[6]&255|(C[7]&255)<<8,this.r[3]=(y>>>7|E<<9)&8191,Y=C[8]&255|(C[9]&255)<<8,this.r[4]=(E>>>4|Y<<12)&255,this.r[5]=Y>>>1&8190,ee=C[10]&255|(C[11]&255)<<8,this.r[6]=(Y>>>14|ee<<2)&8191,ge=C[12]&255|(C[13]&255)<<8,this.r[7]=(ee>>>11|ge<<5)&8065,Te=C[14]&255|(C[15]&255)<<8,this.r[8]=(ge>>>8|Te<<8)&8191,this.r[9]=Te>>>5&127,this.pad[0]=C[16]&255|(C[17]&255)<<8,this.pad[1]=C[18]&255|(C[19]&255)<<8,this.pad[2]=C[20]&255|(C[21]&255)<<8,this.pad[3]=C[22]&255|(C[23]&255)<<8,this.pad[4]=C[24]&255|(C[25]&255)<<8,this.pad[5]=C[26]&255|(C[27]&255)<<8,this.pad[6]=C[28]&255|(C[29]&255)<<8,this.pad[7]=C[30]&255|(C[31]&255)<<8};A.prototype.blocks=function(C,D,P){for(var y=this.fin?0:2048,E,Y,ee,ge,Te,Ve,He,bt,Xe,ae,Ne,_e,Be,Ze,ft,ht,ze,Qe,Ke,et=this.h[0],lt=this.h[1],Ye=this.h[2],be=this.h[3],ye=this.h[4],Me=this.h[5],Ae=this.h[6],je=this.h[7],De=this.h[8],dt=this.h[9],Nt=this.r[0],Rt=this.r[1],Ct=this.r[2],Q=this.r[3],It=this.r[4],qt=this.r[5],Gt=this.r[6],Tt=this.r[7],At=this.r[8],Ut=this.r[9];P>=16;)E=C[D+0]&255|(C[D+1]&255)<<8,et+=E&8191,Y=C[D+2]&255|(C[D+3]&255)<<8,lt+=(E>>>13|Y<<3)&8191,ee=C[D+4]&255|(C[D+5]&255)<<8,Ye+=(Y>>>10|ee<<6)&8191,ge=C[D+6]&255|(C[D+7]&255)<<8,be+=(ee>>>7|ge<<9)&8191,Te=C[D+8]&255|(C[D+9]&255)<<8,ye+=(ge>>>4|Te<<12)&8191,Me+=Te>>>1&8191,Ve=C[D+10]&255|(C[D+11]&255)<<8,Ae+=(Te>>>14|Ve<<2)&8191,He=C[D+12]&255|(C[D+13]&255)<<8,je+=(Ve>>>11|He<<5)&8191,bt=C[D+14]&255|(C[D+15]&255)<<8,De+=(He>>>8|bt<<8)&8191,dt+=bt>>>5|y,Xe=0,ae=Xe,ae+=et*Nt,ae+=lt*(5*Ut),ae+=Ye*(5*At),ae+=be*(5*Tt),ae+=ye*(5*Gt),Xe=ae>>>13,ae&=8191,ae+=Me*(5*qt),ae+=Ae*(5*It),ae+=je*(5*Q),ae+=De*(5*Ct),ae+=dt*(5*Rt),Xe+=ae>>>13,ae&=8191,Ne=Xe,Ne+=et*Rt,Ne+=lt*Nt,Ne+=Ye*(5*Ut),Ne+=be*(5*At),Ne+=ye*(5*Tt),Xe=Ne>>>13,Ne&=8191,Ne+=Me*(5*Gt),Ne+=Ae*(5*qt),Ne+=je*(5*It),Ne+=De*(5*Q),Ne+=dt*(5*Ct),Xe+=Ne>>>13,Ne&=8191,_e=Xe,_e+=et*Ct,_e+=lt*Rt,_e+=Ye*Nt,_e+=be*(5*Ut),_e+=ye*(5*At),Xe=_e>>>13,_e&=8191,_e+=Me*(5*Tt),_e+=Ae*(5*Gt),_e+=je*(5*qt),_e+=De*(5*It),_e+=dt*(5*Q),Xe+=_e>>>13,_e&=8191,Be=Xe,Be+=et*Q,Be+=lt*Ct,Be+=Ye*Rt,Be+=be*Nt,Be+=ye*(5*Ut),Xe=Be>>>13,Be&=8191,Be+=Me*(5*At),Be+=Ae*(5*Tt),Be+=je*(5*Gt),Be+=De*(5*qt),Be+=dt*(5*It),Xe+=Be>>>13,Be&=8191,Ze=Xe,Ze+=et*It,Ze+=lt*Q,Ze+=Ye*Ct,Ze+=be*Rt,Ze+=ye*Nt,Xe=Ze>>>13,Ze&=8191,Ze+=Me*(5*Ut),Ze+=Ae*(5*At),Ze+=je*(5*Tt),Ze+=De*(5*Gt),Ze+=dt*(5*qt),Xe+=Ze>>>13,Ze&=8191,ft=Xe,ft+=et*qt,ft+=lt*It,ft+=Ye*Q,ft+=be*Ct,ft+=ye*Rt,Xe=ft>>>13,ft&=8191,ft+=Me*Nt,ft+=Ae*(5*Ut),ft+=je*(5*At),ft+=De*(5*Tt),ft+=dt*(5*Gt),Xe+=ft>>>13,ft&=8191,ht=Xe,ht+=et*Gt,ht+=lt*qt,ht+=Ye*It,ht+=be*Q,ht+=ye*Ct,Xe=ht>>>13,ht&=8191,ht+=Me*Rt,ht+=Ae*Nt,ht+=je*(5*Ut),ht+=De*(5*At),ht+=dt*(5*Tt),Xe+=ht>>>13,ht&=8191,ze=Xe,ze+=et*Tt,ze+=lt*Gt,ze+=Ye*qt,ze+=be*It,ze+=ye*Q,Xe=ze>>>13,ze&=8191,ze+=Me*Ct,ze+=Ae*Rt,ze+=je*Nt,ze+=De*(5*Ut),ze+=dt*(5*At),Xe+=ze>>>13,ze&=8191,Qe=Xe,Qe+=et*At,Qe+=lt*Tt,Qe+=Ye*Gt,Qe+=be*qt,Qe+=ye*It,Xe=Qe>>>13,Qe&=8191,Qe+=Me*Q,Qe+=Ae*Ct,Qe+=je*Rt,Qe+=De*Nt,Qe+=dt*(5*Ut),Xe+=Qe>>>13,Qe&=8191,Ke=Xe,Ke+=et*Ut,Ke+=lt*At,Ke+=Ye*Tt,Ke+=be*Gt,Ke+=ye*qt,Xe=Ke>>>13,Ke&=8191,Ke+=Me*It,Ke+=Ae*Q,Ke+=je*Ct,Ke+=De*Rt,Ke+=dt*Nt,Xe+=Ke>>>13,Ke&=8191,Xe=(Xe<<2)+Xe|0,Xe=Xe+ae|0,ae=Xe&8191,Xe=Xe>>>13,Ne+=Xe,et=ae,lt=Ne,Ye=_e,be=Be,ye=Ze,Me=ft,Ae=ht,je=ze,De=Qe,dt=Ke,D+=16,P-=16;this.h[0]=et,this.h[1]=lt,this.h[2]=Ye,this.h[3]=be,this.h[4]=ye,this.h[5]=Me,this.h[6]=Ae,this.h[7]=je,this.h[8]=De,this.h[9]=dt},A.prototype.finish=function(C,D){var P=new Uint16Array(10),y,E,Y,ee;if(this.leftover){for(ee=this.leftover,this.buffer[ee++]=1;ee<16;ee++)this.buffer[ee]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(y=this.h[1]>>>13,this.h[1]&=8191,ee=2;ee<10;ee++)this.h[ee]+=y,y=this.h[ee]>>>13,this.h[ee]&=8191;for(this.h[0]+=y*5,y=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=y,y=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=y,P[0]=this.h[0]+5,y=P[0]>>>13,P[0]&=8191,ee=1;ee<10;ee++)P[ee]=this.h[ee]+y,y=P[ee]>>>13,P[ee]&=8191;for(P[9]-=8192,E=(y^1)-1,ee=0;ee<10;ee++)P[ee]&=E;for(E=~E,ee=0;ee<10;ee++)this.h[ee]=this.h[ee]&E|P[ee];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,Y=this.h[0]+this.pad[0],this.h[0]=Y&65535,ee=1;ee<8;ee++)Y=(this.h[ee]+this.pad[ee]|0)+(Y>>>16)|0,this.h[ee]=Y&65535;C[D+0]=this.h[0]>>>0&255,C[D+1]=this.h[0]>>>8&255,C[D+2]=this.h[1]>>>0&255,C[D+3]=this.h[1]>>>8&255,C[D+4]=this.h[2]>>>0&255,C[D+5]=this.h[2]>>>8&255,C[D+6]=this.h[3]>>>0&255,C[D+7]=this.h[3]>>>8&255,C[D+8]=this.h[4]>>>0&255,C[D+9]=this.h[4]>>>8&255,C[D+10]=this.h[5]>>>0&255,C[D+11]=this.h[5]>>>8&255,C[D+12]=this.h[6]>>>0&255,C[D+13]=this.h[6]>>>8&255,C[D+14]=this.h[7]>>>0&255,C[D+15]=this.h[7]>>>8&255},A.prototype.update=function(C,D,P){var y,E;if(this.leftover){for(E=16-this.leftover,E>P&&(E=P),y=0;y<E;y++)this.buffer[this.leftover+y]=C[D+y];if(P-=E,D+=E,this.leftover+=E,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(P>=16&&(E=P-P%16,this.blocks(C,D,E),D+=E,P-=E),P){for(y=0;y<P;y++)this.buffer[this.leftover+y]=C[D+y];this.leftover+=P}};function M(C,D,P,y,E,Y){var ee=new A(Y);return ee.update(P,y,E),ee.finish(C,D),0}function R(C,D,P,y,E,Y){var ee=new Uint8Array(16);return M(ee,0,P,y,E,Y),v(C,D,ee,0)}function $(C,D,P,y,E){var Y;if(P<32)return-1;for(F(C,0,D,0,P,y,E),M(C,16,C,32,P-32,C),Y=0;Y<16;Y++)C[Y]=0;return 0}function U(C,D,P,y,E){var Y,ee=new Uint8Array(32);if(P<32||(L(ee,0,32,y,E),R(D,16,D,32,P-32,ee)!==0))return-1;for(F(C,0,D,0,P,y,E),Y=0;Y<32;Y++)C[Y]=0;return 0}function q(C,D){var P;for(P=0;P<16;P++)C[P]=D[P]|0}function te(C){var D,P,y=1;for(D=0;D<16;D++)P=C[D]+y+65535,y=Math.floor(P/65536),C[D]=P-y*65536;C[0]+=y-1+37*(y-1)}function V(C,D,P){for(var y,E=~(P-1),Y=0;Y<16;Y++)y=E&(C[Y]^D[Y]),C[Y]^=y,D[Y]^=y}function se(C,D){var P,y,E,Y=s(),ee=s();for(P=0;P<16;P++)ee[P]=D[P];for(te(ee),te(ee),te(ee),y=0;y<2;y++){for(Y[0]=ee[0]-65517,P=1;P<15;P++)Y[P]=ee[P]-65535-(Y[P-1]>>16&1),Y[P-1]&=65535;Y[15]=ee[15]-32767-(Y[14]>>16&1),E=Y[15]>>16&1,Y[14]&=65535,V(ee,Y,1-E)}for(P=0;P<16;P++)C[2*P]=ee[P]&255,C[2*P+1]=ee[P]>>8}function Ce(C,D){var P=new Uint8Array(32),y=new Uint8Array(32);return se(P,C),se(y,D),b(P,0,y,0)}function de(C){var D=new Uint8Array(32);return se(D,C),D[0]&1}function re(C,D){var P;for(P=0;P<16;P++)C[P]=D[2*P]+(D[2*P+1]<<8);C[15]&=32767}function Z(C,D,P){for(var y=0;y<16;y++)C[y]=D[y]+P[y]}function me(C,D,P){for(var y=0;y<16;y++)C[y]=D[y]-P[y]}function xe(C,D,P){var y,E,Y=0,ee=0,ge=0,Te=0,Ve=0,He=0,bt=0,Xe=0,ae=0,Ne=0,_e=0,Be=0,Ze=0,ft=0,ht=0,ze=0,Qe=0,Ke=0,et=0,lt=0,Ye=0,be=0,ye=0,Me=0,Ae=0,je=0,De=0,dt=0,Nt=0,Rt=0,Ct=0,Q=P[0],It=P[1],qt=P[2],Gt=P[3],Tt=P[4],At=P[5],Ut=P[6],jn=P[7],Qt=P[8],gn=P[9],xn=P[10],kn=P[11],Nn=P[12],Tn=P[13],Xt=P[14],An=P[15];y=D[0],Y+=y*Q,ee+=y*It,ge+=y*qt,Te+=y*Gt,Ve+=y*Tt,He+=y*At,bt+=y*Ut,Xe+=y*jn,ae+=y*Qt,Ne+=y*gn,_e+=y*xn,Be+=y*kn,Ze+=y*Nn,ft+=y*Tn,ht+=y*Xt,ze+=y*An,y=D[1],ee+=y*Q,ge+=y*It,Te+=y*qt,Ve+=y*Gt,He+=y*Tt,bt+=y*At,Xe+=y*Ut,ae+=y*jn,Ne+=y*Qt,_e+=y*gn,Be+=y*xn,Ze+=y*kn,ft+=y*Nn,ht+=y*Tn,ze+=y*Xt,Qe+=y*An,y=D[2],ge+=y*Q,Te+=y*It,Ve+=y*qt,He+=y*Gt,bt+=y*Tt,Xe+=y*At,ae+=y*Ut,Ne+=y*jn,_e+=y*Qt,Be+=y*gn,Ze+=y*xn,ft+=y*kn,ht+=y*Nn,ze+=y*Tn,Qe+=y*Xt,Ke+=y*An,y=D[3],Te+=y*Q,Ve+=y*It,He+=y*qt,bt+=y*Gt,Xe+=y*Tt,ae+=y*At,Ne+=y*Ut,_e+=y*jn,Be+=y*Qt,Ze+=y*gn,ft+=y*xn,ht+=y*kn,ze+=y*Nn,Qe+=y*Tn,Ke+=y*Xt,et+=y*An,y=D[4],Ve+=y*Q,He+=y*It,bt+=y*qt,Xe+=y*Gt,ae+=y*Tt,Ne+=y*At,_e+=y*Ut,Be+=y*jn,Ze+=y*Qt,ft+=y*gn,ht+=y*xn,ze+=y*kn,Qe+=y*Nn,Ke+=y*Tn,et+=y*Xt,lt+=y*An,y=D[5],He+=y*Q,bt+=y*It,Xe+=y*qt,ae+=y*Gt,Ne+=y*Tt,_e+=y*At,Be+=y*Ut,Ze+=y*jn,ft+=y*Qt,ht+=y*gn,ze+=y*xn,Qe+=y*kn,Ke+=y*Nn,et+=y*Tn,lt+=y*Xt,Ye+=y*An,y=D[6],bt+=y*Q,Xe+=y*It,ae+=y*qt,Ne+=y*Gt,_e+=y*Tt,Be+=y*At,Ze+=y*Ut,ft+=y*jn,ht+=y*Qt,ze+=y*gn,Qe+=y*xn,Ke+=y*kn,et+=y*Nn,lt+=y*Tn,Ye+=y*Xt,be+=y*An,y=D[7],Xe+=y*Q,ae+=y*It,Ne+=y*qt,_e+=y*Gt,Be+=y*Tt,Ze+=y*At,ft+=y*Ut,ht+=y*jn,ze+=y*Qt,Qe+=y*gn,Ke+=y*xn,et+=y*kn,lt+=y*Nn,Ye+=y*Tn,be+=y*Xt,ye+=y*An,y=D[8],ae+=y*Q,Ne+=y*It,_e+=y*qt,Be+=y*Gt,Ze+=y*Tt,ft+=y*At,ht+=y*Ut,ze+=y*jn,Qe+=y*Qt,Ke+=y*gn,et+=y*xn,lt+=y*kn,Ye+=y*Nn,be+=y*Tn,ye+=y*Xt,Me+=y*An,y=D[9],Ne+=y*Q,_e+=y*It,Be+=y*qt,Ze+=y*Gt,ft+=y*Tt,ht+=y*At,ze+=y*Ut,Qe+=y*jn,Ke+=y*Qt,et+=y*gn,lt+=y*xn,Ye+=y*kn,be+=y*Nn,ye+=y*Tn,Me+=y*Xt,Ae+=y*An,y=D[10],_e+=y*Q,Be+=y*It,Ze+=y*qt,ft+=y*Gt,ht+=y*Tt,ze+=y*At,Qe+=y*Ut,Ke+=y*jn,et+=y*Qt,lt+=y*gn,Ye+=y*xn,be+=y*kn,ye+=y*Nn,Me+=y*Tn,Ae+=y*Xt,je+=y*An,y=D[11],Be+=y*Q,Ze+=y*It,ft+=y*qt,ht+=y*Gt,ze+=y*Tt,Qe+=y*At,Ke+=y*Ut,et+=y*jn,lt+=y*Qt,Ye+=y*gn,be+=y*xn,ye+=y*kn,Me+=y*Nn,Ae+=y*Tn,je+=y*Xt,De+=y*An,y=D[12],Ze+=y*Q,ft+=y*It,ht+=y*qt,ze+=y*Gt,Qe+=y*Tt,Ke+=y*At,et+=y*Ut,lt+=y*jn,Ye+=y*Qt,be+=y*gn,ye+=y*xn,Me+=y*kn,Ae+=y*Nn,je+=y*Tn,De+=y*Xt,dt+=y*An,y=D[13],ft+=y*Q,ht+=y*It,ze+=y*qt,Qe+=y*Gt,Ke+=y*Tt,et+=y*At,lt+=y*Ut,Ye+=y*jn,be+=y*Qt,ye+=y*gn,Me+=y*xn,Ae+=y*kn,je+=y*Nn,De+=y*Tn,dt+=y*Xt,Nt+=y*An,y=D[14],ht+=y*Q,ze+=y*It,Qe+=y*qt,Ke+=y*Gt,et+=y*Tt,lt+=y*At,Ye+=y*Ut,be+=y*jn,ye+=y*Qt,Me+=y*gn,Ae+=y*xn,je+=y*kn,De+=y*Nn,dt+=y*Tn,Nt+=y*Xt,Rt+=y*An,y=D[15],ze+=y*Q,Qe+=y*It,Ke+=y*qt,et+=y*Gt,lt+=y*Tt,Ye+=y*At,be+=y*Ut,ye+=y*jn,Me+=y*Qt,Ae+=y*gn,je+=y*xn,De+=y*kn,dt+=y*Nn,Nt+=y*Tn,Rt+=y*Xt,Ct+=y*An,Y+=38*Qe,ee+=38*Ke,ge+=38*et,Te+=38*lt,Ve+=38*Ye,He+=38*be,bt+=38*ye,Xe+=38*Me,ae+=38*Ae,Ne+=38*je,_e+=38*De,Be+=38*dt,Ze+=38*Nt,ft+=38*Rt,ht+=38*Ct,E=1,y=Y+E+65535,E=Math.floor(y/65536),Y=y-E*65536,y=ee+E+65535,E=Math.floor(y/65536),ee=y-E*65536,y=ge+E+65535,E=Math.floor(y/65536),ge=y-E*65536,y=Te+E+65535,E=Math.floor(y/65536),Te=y-E*65536,y=Ve+E+65535,E=Math.floor(y/65536),Ve=y-E*65536,y=He+E+65535,E=Math.floor(y/65536),He=y-E*65536,y=bt+E+65535,E=Math.floor(y/65536),bt=y-E*65536,y=Xe+E+65535,E=Math.floor(y/65536),Xe=y-E*65536,y=ae+E+65535,E=Math.floor(y/65536),ae=y-E*65536,y=Ne+E+65535,E=Math.floor(y/65536),Ne=y-E*65536,y=_e+E+65535,E=Math.floor(y/65536),_e=y-E*65536,y=Be+E+65535,E=Math.floor(y/65536),Be=y-E*65536,y=Ze+E+65535,E=Math.floor(y/65536),Ze=y-E*65536,y=ft+E+65535,E=Math.floor(y/65536),ft=y-E*65536,y=ht+E+65535,E=Math.floor(y/65536),ht=y-E*65536,y=ze+E+65535,E=Math.floor(y/65536),ze=y-E*65536,Y+=E-1+37*(E-1),E=1,y=Y+E+65535,E=Math.floor(y/65536),Y=y-E*65536,y=ee+E+65535,E=Math.floor(y/65536),ee=y-E*65536,y=ge+E+65535,E=Math.floor(y/65536),ge=y-E*65536,y=Te+E+65535,E=Math.floor(y/65536),Te=y-E*65536,y=Ve+E+65535,E=Math.floor(y/65536),Ve=y-E*65536,y=He+E+65535,E=Math.floor(y/65536),He=y-E*65536,y=bt+E+65535,E=Math.floor(y/65536),bt=y-E*65536,y=Xe+E+65535,E=Math.floor(y/65536),Xe=y-E*65536,y=ae+E+65535,E=Math.floor(y/65536),ae=y-E*65536,y=Ne+E+65535,E=Math.floor(y/65536),Ne=y-E*65536,y=_e+E+65535,E=Math.floor(y/65536),_e=y-E*65536,y=Be+E+65535,E=Math.floor(y/65536),Be=y-E*65536,y=Ze+E+65535,E=Math.floor(y/65536),Ze=y-E*65536,y=ft+E+65535,E=Math.floor(y/65536),ft=y-E*65536,y=ht+E+65535,E=Math.floor(y/65536),ht=y-E*65536,y=ze+E+65535,E=Math.floor(y/65536),ze=y-E*65536,Y+=E-1+37*(E-1),C[0]=Y,C[1]=ee,C[2]=ge,C[3]=Te,C[4]=Ve,C[5]=He,C[6]=bt,C[7]=Xe,C[8]=ae,C[9]=Ne,C[10]=_e,C[11]=Be,C[12]=Ze,C[13]=ft,C[14]=ht,C[15]=ze}function Se(C,D){xe(C,D,D)}function W(C,D){var P=s(),y;for(y=0;y<16;y++)P[y]=D[y];for(y=253;y>=0;y--)Se(P,P),y!==2&&y!==4&&xe(P,P,D);for(y=0;y<16;y++)C[y]=P[y]}function H(C,D){var P=s(),y;for(y=0;y<16;y++)P[y]=D[y];for(y=250;y>=0;y--)Se(P,P),y!==1&&xe(P,P,D);for(y=0;y<16;y++)C[y]=P[y]}function B(C,D,P){var y=new Uint8Array(32),E=new Float64Array(80),Y,ee,ge=s(),Te=s(),Ve=s(),He=s(),bt=s(),Xe=s();for(ee=0;ee<31;ee++)y[ee]=D[ee];for(y[31]=D[31]&127|64,y[0]&=248,re(E,P),ee=0;ee<16;ee++)Te[ee]=E[ee],He[ee]=ge[ee]=Ve[ee]=0;for(ge[0]=He[0]=1,ee=254;ee>=0;--ee)Y=y[ee>>>3]>>>(ee&7)&1,V(ge,Te,Y),V(Ve,He,Y),Z(bt,ge,Ve),me(ge,ge,Ve),Z(Ve,Te,He),me(Te,Te,He),Se(He,bt),Se(Xe,ge),xe(ge,Ve,ge),xe(Ve,Te,bt),Z(bt,ge,Ve),me(ge,ge,Ve),Se(Te,ge),me(Ve,He,Xe),xe(ge,Ve,c),Z(ge,ge,He),xe(Ve,Ve,ge),xe(ge,He,Xe),xe(He,Te,E),Se(Te,bt),V(ge,Te,Y),V(Ve,He,Y);for(ee=0;ee<16;ee++)E[ee+16]=ge[ee],E[ee+32]=Ve[ee],E[ee+48]=Te[ee],E[ee+64]=He[ee];var ae=E.subarray(32),Ne=E.subarray(16);return W(ae,ae),xe(Ne,Ne,ae),se(C,Ne),0}function ne(C,D){return B(C,D,i)}function ve(C,D){return r(D,32),ne(C,D)}function he(C,D,P){var y=new Uint8Array(32);return B(y,P,D),N(C,o,y,S)}var G=$,we=U;function ce(C,D,P,y,E,Y){var ee=new Uint8Array(32);return he(ee,E,Y),G(C,D,P,y,ee)}function Re(C,D,P,y,E,Y){var ee=new Uint8Array(32);return he(ee,E,Y),we(C,D,P,y,ee)}var ue=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function We(C,D,P,y){for(var E=new Int32Array(16),Y=new Int32Array(16),ee,ge,Te,Ve,He,bt,Xe,ae,Ne,_e,Be,Ze,ft,ht,ze,Qe,Ke,et,lt,Ye,be,ye,Me,Ae,je,De,dt=C[0],Nt=C[1],Rt=C[2],Ct=C[3],Q=C[4],It=C[5],qt=C[6],Gt=C[7],Tt=D[0],At=D[1],Ut=D[2],jn=D[3],Qt=D[4],gn=D[5],xn=D[6],kn=D[7],Nn=0;y>=128;){for(lt=0;lt<16;lt++)Ye=8*lt+Nn,E[lt]=P[Ye+0]<<24|P[Ye+1]<<16|P[Ye+2]<<8|P[Ye+3],Y[lt]=P[Ye+4]<<24|P[Ye+5]<<16|P[Ye+6]<<8|P[Ye+7];for(lt=0;lt<80;lt++)if(ee=dt,ge=Nt,Te=Rt,Ve=Ct,He=Q,bt=It,Xe=qt,ae=Gt,Ne=Tt,_e=At,Be=Ut,Ze=jn,ft=Qt,ht=gn,ze=xn,Qe=kn,be=Gt,ye=kn,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=(Q>>>14|Qt<<18)^(Q>>>18|Qt<<14)^(Qt>>>9|Q<<23),ye=(Qt>>>14|Q<<18)^(Qt>>>18|Q<<14)^(Q>>>9|Qt<<23),Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,be=Q&It^~Q&qt,ye=Qt&gn^~Qt&xn,Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,be=ue[lt*2],ye=ue[lt*2+1],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,be=E[lt%16],ye=Y[lt%16],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,Ke=je&65535|De<<16,et=Me&65535|Ae<<16,be=Ke,ye=et,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=(dt>>>28|Tt<<4)^(Tt>>>2|dt<<30)^(Tt>>>7|dt<<25),ye=(Tt>>>28|dt<<4)^(dt>>>2|Tt<<30)^(dt>>>7|Tt<<25),Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,be=dt&Nt^dt&Rt^Nt&Rt,ye=Tt&At^Tt&Ut^At&Ut,Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,ae=je&65535|De<<16,Qe=Me&65535|Ae<<16,be=Ve,ye=Ze,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=Ke,ye=et,Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,Ve=je&65535|De<<16,Ze=Me&65535|Ae<<16,Nt=ee,Rt=ge,Ct=Te,Q=Ve,It=He,qt=bt,Gt=Xe,dt=ae,At=Ne,Ut=_e,jn=Be,Qt=Ze,gn=ft,xn=ht,kn=ze,Tt=Qe,lt%16===15)for(Ye=0;Ye<16;Ye++)be=E[Ye],ye=Y[Ye],Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=E[(Ye+9)%16],ye=Y[(Ye+9)%16],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ke=E[(Ye+1)%16],et=Y[(Ye+1)%16],be=(Ke>>>1|et<<31)^(Ke>>>8|et<<24)^Ke>>>7,ye=(et>>>1|Ke<<31)^(et>>>8|Ke<<24)^(et>>>7|Ke<<25),Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ke=E[(Ye+14)%16],et=Y[(Ye+14)%16],be=(Ke>>>19|et<<13)^(et>>>29|Ke<<3)^Ke>>>6,ye=(et>>>19|Ke<<13)^(Ke>>>29|et<<3)^(et>>>6|Ke<<26),Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,E[Ye]=je&65535|De<<16,Y[Ye]=Me&65535|Ae<<16;be=dt,ye=Tt,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[0],ye=D[0],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[0]=dt=je&65535|De<<16,D[0]=Tt=Me&65535|Ae<<16,be=Nt,ye=At,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[1],ye=D[1],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[1]=Nt=je&65535|De<<16,D[1]=At=Me&65535|Ae<<16,be=Rt,ye=Ut,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[2],ye=D[2],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[2]=Rt=je&65535|De<<16,D[2]=Ut=Me&65535|Ae<<16,be=Ct,ye=jn,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[3],ye=D[3],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[3]=Ct=je&65535|De<<16,D[3]=jn=Me&65535|Ae<<16,be=Q,ye=Qt,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[4],ye=D[4],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[4]=Q=je&65535|De<<16,D[4]=Qt=Me&65535|Ae<<16,be=It,ye=gn,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[5],ye=D[5],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[5]=It=je&65535|De<<16,D[5]=gn=Me&65535|Ae<<16,be=qt,ye=xn,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[6],ye=D[6],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[6]=qt=je&65535|De<<16,D[6]=xn=Me&65535|Ae<<16,be=Gt,ye=kn,Me=ye&65535,Ae=ye>>>16,je=be&65535,De=be>>>16,be=C[7],ye=D[7],Me+=ye&65535,Ae+=ye>>>16,je+=be&65535,De+=be>>>16,Ae+=Me>>>16,je+=Ae>>>16,De+=je>>>16,C[7]=Gt=je&65535|De<<16,D[7]=kn=Me&65535|Ae<<16,Nn+=128,y-=128}return y}function it(C,D,P){var y=new Int32Array(8),E=new Int32Array(8),Y=new Uint8Array(256),ee,ge=P;for(y[0]=1779033703,y[1]=3144134277,y[2]=1013904242,y[3]=2773480762,y[4]=1359893119,y[5]=2600822924,y[6]=528734635,y[7]=1541459225,E[0]=4089235720,E[1]=2227873595,E[2]=4271175723,E[3]=1595750129,E[4]=2917565137,E[5]=725511199,E[6]=4215389547,E[7]=327033209,We(y,E,D,P),P%=128,ee=0;ee<P;ee++)Y[ee]=D[ge-P+ee];for(Y[P]=128,P=256-128*(P<112?1:0),Y[P-9]=0,g(Y,P-8,ge/536870912|0,ge<<3),We(y,E,Y,P),ee=0;ee<8;ee++)g(C,8*ee,y[ee],E[ee]);return 0}function Fe(C,D){var P=s(),y=s(),E=s(),Y=s(),ee=s(),ge=s(),Te=s(),Ve=s(),He=s();me(P,C[1],C[0]),me(He,D[1],D[0]),xe(P,P,He),Z(y,C[0],C[1]),Z(He,D[0],D[1]),xe(y,y,He),xe(E,C[3],D[3]),xe(E,E,d),xe(Y,C[2],D[2]),Z(Y,Y,Y),me(ee,y,P),me(ge,Y,E),Z(Te,Y,E),Z(Ve,y,P),xe(C[0],ee,ge),xe(C[1],Ve,Te),xe(C[2],Te,ge),xe(C[3],ee,Ve)}function tt(C,D,P){var y;for(y=0;y<4;y++)V(C[y],D[y],P)}function ke(C,D){var P=s(),y=s(),E=s();W(E,D[2]),xe(P,D[0],E),xe(y,D[1],E),se(C,y),C[31]^=de(P)<<7}function nt(C,D,P){var y,E;for(q(C[0],a),q(C[1],l),q(C[2],l),q(C[3],a),E=255;E>=0;--E)y=P[E/8|0]>>(E&7)&1,tt(C,D,y),Fe(D,C),Fe(C,C),tt(C,D,y)}function mt(C,D){var P=[s(),s(),s(),s()];q(P[0],m),q(P[1],h),q(P[2],l),xe(P[3],m,h),nt(C,P,D)}function X(C,D,P){var y=new Uint8Array(64),E=[s(),s(),s(),s()],Y;for(P||r(D,32),it(y,D,32),y[0]&=248,y[31]&=127,y[31]|=64,mt(E,y),ke(C,E),Y=0;Y<32;Y++)D[Y+32]=C[Y];return 0}var K=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function Ee(C,D){var P,y,E,Y;for(y=63;y>=32;--y){for(P=0,E=y-32,Y=y-12;E<Y;++E)D[E]+=P-16*D[y]*K[E-(y-32)],P=Math.floor((D[E]+128)/256),D[E]-=P*256;D[E]+=P,D[y]=0}for(P=0,E=0;E<32;E++)D[E]+=P-(D[31]>>4)*K[E],P=D[E]>>8,D[E]&=255;for(E=0;E<32;E++)D[E]-=P*K[E];for(y=0;y<32;y++)D[y+1]+=D[y]>>8,C[y]=D[y]&255}function pt(C){var D=new Float64Array(64),P;for(P=0;P<64;P++)D[P]=C[P];for(P=0;P<64;P++)C[P]=0;Ee(C,D)}function Pt(C,D,P,y){var E=new Uint8Array(64),Y=new Uint8Array(64),ee=new Uint8Array(64),ge,Te,Ve=new Float64Array(64),He=[s(),s(),s(),s()];it(E,y,32),E[0]&=248,E[31]&=127,E[31]|=64;var bt=P+64;for(ge=0;ge<P;ge++)C[64+ge]=D[ge];for(ge=0;ge<32;ge++)C[32+ge]=E[32+ge];for(it(ee,C.subarray(32),P+32),pt(ee),mt(He,ee),ke(C,He),ge=32;ge<64;ge++)C[ge]=y[ge];for(it(Y,C,P+64),pt(Y),ge=0;ge<64;ge++)Ve[ge]=0;for(ge=0;ge<32;ge++)Ve[ge]=ee[ge];for(ge=0;ge<32;ge++)for(Te=0;Te<32;Te++)Ve[ge+Te]+=Y[ge]*E[Te];return Ee(C.subarray(32),Ve),bt}function Je(C,D){var P=s(),y=s(),E=s(),Y=s(),ee=s(),ge=s(),Te=s();return q(C[2],l),re(C[1],D),Se(E,C[1]),xe(Y,E,u),me(E,E,C[2]),Z(Y,C[2],Y),Se(ee,Y),Se(ge,ee),xe(Te,ge,ee),xe(P,Te,E),xe(P,P,Y),H(P,P),xe(P,P,E),xe(P,P,Y),xe(P,P,Y),xe(C[0],P,Y),Se(y,C[0]),xe(y,y,Y),Ce(y,E)&&xe(C[0],C[0],p),Se(y,C[0]),xe(y,y,Y),Ce(y,E)?-1:(de(C[0])===D[31]>>7&&me(C[0],a,C[0]),xe(C[3],C[0],C[1]),0)}function Lt(C,D,P,y){var E,Y=new Uint8Array(32),ee=new Uint8Array(64),ge=[s(),s(),s(),s()],Te=[s(),s(),s(),s()];if(P<64||Je(Te,y))return-1;for(E=0;E<P;E++)C[E]=D[E];for(E=0;E<32;E++)C[E+32]=y[E];if(it(ee,C,P),pt(ee),nt(ge,Te,ee),mt(Te,D.subarray(32)),Fe(ge,Te),ke(Y,ge),P-=64,b(D,0,Y,0)){for(E=0;E<P;E++)C[E]=0;return-1}for(E=0;E<P;E++)C[E]=D[E+64];return P}var on=32,Pe=24,Dt=32,Vt=16,Et=32,oe=32,Le=32,st=32,at=32,gt=Pe,xt=Dt,zt=Vt,Wt=64,an=32,en=64,Bt=32,pn=64;t.lowlevel={crypto_core_hsalsa20:N,crypto_stream_xor:F,crypto_stream:L,crypto_stream_salsa20_xor:I,crypto_stream_salsa20:k,crypto_onetimeauth:M,crypto_onetimeauth_verify:R,crypto_verify_16:v,crypto_verify_32:b,crypto_secretbox:$,crypto_secretbox_open:U,crypto_scalarmult:B,crypto_scalarmult_base:ne,crypto_box_beforenm:he,crypto_box_afternm:G,crypto_box:ce,crypto_box_open:Re,crypto_box_keypair:ve,crypto_hash:it,crypto_sign:Pt,crypto_sign_keypair:X,crypto_sign_open:Lt,crypto_secretbox_KEYBYTES:on,crypto_secretbox_NONCEBYTES:Pe,crypto_secretbox_ZEROBYTES:Dt,crypto_secretbox_BOXZEROBYTES:Vt,crypto_scalarmult_BYTES:Et,crypto_scalarmult_SCALARBYTES:oe,crypto_box_PUBLICKEYBYTES:Le,crypto_box_SECRETKEYBYTES:st,crypto_box_BEFORENMBYTES:at,crypto_box_NONCEBYTES:gt,crypto_box_ZEROBYTES:xt,crypto_box_BOXZEROBYTES:zt,crypto_sign_BYTES:Wt,crypto_sign_PUBLICKEYBYTES:an,crypto_sign_SECRETKEYBYTES:en,crypto_sign_SEEDBYTES:Bt,crypto_hash_BYTES:pn,gf:s,D:u,L:K,pack25519:se,unpack25519:re,M:xe,A:Z,S:Se,Z:me,pow2523:H,add:Fe,set25519:q,modL:Ee,scalarmult:nt,scalarbase:mt};function Gn(C,D){if(C.length!==on)throw new Error("bad key size");if(D.length!==Pe)throw new Error("bad nonce size")}function vt(C,D){if(C.length!==Le)throw new Error("bad public key size");if(D.length!==st)throw new Error("bad secret key size")}function sn(){for(var C=0;C<arguments.length;C++)if(!(arguments[C]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function Rn(C){for(var D=0;D<C.length;D++)C[D]=0}t.randomBytes=function(C){var D=new Uint8Array(C);return r(D,C),D},t.secretbox=function(C,D,P){sn(C,D,P),Gn(P,D);for(var y=new Uint8Array(Dt+C.length),E=new Uint8Array(y.length),Y=0;Y<C.length;Y++)y[Y+Dt]=C[Y];return $(E,y,y.length,D,P),E.subarray(Vt)},t.secretbox.open=function(C,D,P){sn(C,D,P),Gn(P,D);for(var y=new Uint8Array(Vt+C.length),E=new Uint8Array(y.length),Y=0;Y<C.length;Y++)y[Y+Vt]=C[Y];return y.length<32||U(E,y,y.length,D,P)!==0?null:E.subarray(Dt)},t.secretbox.keyLength=on,t.secretbox.nonceLength=Pe,t.secretbox.overheadLength=Vt,t.scalarMult=function(C,D){if(sn(C,D),C.length!==oe)throw new Error("bad n size");if(D.length!==Et)throw new Error("bad p size");var P=new Uint8Array(Et);return B(P,C,D),P},t.scalarMult.base=function(C){if(sn(C),C.length!==oe)throw new Error("bad n size");var D=new Uint8Array(Et);return ne(D,C),D},t.scalarMult.scalarLength=oe,t.scalarMult.groupElementLength=Et,t.box=function(C,D,P,y){var E=t.box.before(P,y);return t.secretbox(C,D,E)},t.box.before=function(C,D){sn(C,D),vt(C,D);var P=new Uint8Array(at);return he(P,C,D),P},t.box.after=t.secretbox,t.box.open=function(C,D,P,y){var E=t.box.before(P,y);return t.secretbox.open(C,D,E)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var C=new Uint8Array(Le),D=new Uint8Array(st);return ve(C,D),{publicKey:C,secretKey:D}},t.box.keyPair.fromSecretKey=function(C){if(sn(C),C.length!==st)throw new Error("bad secret key size");var D=new Uint8Array(Le);return ne(D,C),{publicKey:D,secretKey:new Uint8Array(C)}},t.box.publicKeyLength=Le,t.box.secretKeyLength=st,t.box.sharedKeyLength=at,t.box.nonceLength=gt,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(C,D){if(sn(C,D),D.length!==en)throw new Error("bad secret key size");var P=new Uint8Array(Wt+C.length);return Pt(P,C,C.length,D),P},t.sign.open=function(C,D){if(sn(C,D),D.length!==an)throw new Error("bad public key size");var P=new Uint8Array(C.length),y=Lt(P,C,C.length,D);if(y<0)return null;for(var E=new Uint8Array(y),Y=0;Y<E.length;Y++)E[Y]=P[Y];return E},t.sign.detached=function(C,D){for(var P=t.sign(C,D),y=new Uint8Array(Wt),E=0;E<y.length;E++)y[E]=P[E];return y},t.sign.detached.verify=function(C,D,P){if(sn(C,D,P),D.length!==Wt)throw new Error("bad signature size");if(P.length!==an)throw new Error("bad public key size");var y=new Uint8Array(Wt+C.length),E=new Uint8Array(Wt+C.length),Y;for(Y=0;Y<Wt;Y++)y[Y]=D[Y];for(Y=0;Y<C.length;Y++)y[Y+Wt]=C[Y];return Lt(E,y,y.length,P)>=0},t.sign.keyPair=function(){var C=new Uint8Array(an),D=new Uint8Array(en);return X(C,D),{publicKey:C,secretKey:D}},t.sign.keyPair.fromSecretKey=function(C){if(sn(C),C.length!==en)throw new Error("bad secret key size");for(var D=new Uint8Array(an),P=0;P<D.length;P++)D[P]=C[32+P];return{publicKey:D,secretKey:new Uint8Array(C)}},t.sign.keyPair.fromSeed=function(C){if(sn(C),C.length!==Bt)throw new Error("bad seed size");for(var D=new Uint8Array(an),P=new Uint8Array(en),y=0;y<32;y++)P[y]=C[y];return X(D,P,!0),{publicKey:D,secretKey:P}},t.sign.publicKeyLength=an,t.sign.secretKeyLength=en,t.sign.seedLength=Bt,t.sign.signatureLength=Wt,t.hash=function(C){sn(C);var D=new Uint8Array(pn);return it(D,C,C.length),D},t.hash.hashLength=pn,t.verify=function(C,D){return sn(C,D),C.length===0||D.length===0||C.length!==D.length?!1:x(C,0,D,0,C.length)===0},t.setPRNG=function(C){r=C},(function(){var C=typeof self<"u"?self.crypto||self.msCrypto:null;if(C&&C.getRandomValues){var D=65536;t.setPRNG(function(P,y){var E,Y=new Uint8Array(y);for(E=0;E<y;E+=D)C.getRandomValues(Y.subarray(E,E+Math.min(y-E,D)));for(E=0;E<y;E++)P[E]=Y[E];Rn(Y)})}else typeof PZ<"u"&&(C=LZ,C&&C.randomBytes&&t.setPRNG(function(P,y){var E,Y=C.randomBytes(y);for(E=0;E<y;E++)P[E]=Y[E];Rn(Y)}))})()})(e.exports?e.exports:self.nacl=self.nacl||{})})(Zf)),Zf.exports}_Z();new TextEncoder;new TextDecoder;function BZ(e){return{id:e.id,name:e.name,path:e.path,...e.alias?.trim()?{alias:e.alias.trim()}:{},...e.groupId?{groupId:e.groupId}:{},...e.kind==="ssh"?{kind:"ssh",...e.sshConnectionName?{sshConnectionName:e.sshConnectionName}:{},...e.sshHost?{sshHost:e.sshHost}:{}}:{}}}const FZ=4096;BigInt(FZ);function zZ(e,t){const s=Sl(e);if(s)return s.failed?{status:"queued",queueFailed:s.failed.error}:{status:"queued",queuePosition:t??1}}function $Z(e,t,s){if(!(e.status==="running"||e.spawning))return Fa(e.goal)?"upstream":t&&x1(t,s)?"reminder":void 0}function VZ(e,t=[]){return JSON.stringify({pinnedOrder:t,entries:e.map(s=>{const{updatedAt:r,...o}=s;return o})})}function HZ(e){return JSON.stringify(e)}function WZ(e,t,s=[]){const r=G3(e,t).map(i=>({id:i.id,name:i.name,models:i.models.map(a=>({id:a.id,...a.label?{label:a.label}:{}}))})),o=s.filter(i=>i.enabled&&r.some(a=>a.id===i.primary.providerId&&a.models.some(l=>l.id===i.primary.modelId)));return o.length>0&&r.unshift({id:i1,name:"Auto",models:o.map(i=>({id:i.id,label:i.name}))}),r}function UZ(e,t,s=[]){const r=WZ(e,t,s),o=t.availability.status,i=o==="unloaded"||o==="loading",a=e.some(l=>l.enabled&&l.oauthAccountKey);return{entries:r,settled:!(i&&a&&r.length===0)}}function qZ(e){return e!=="scratch"&&e!=="secretary"}function GZ(e,t){return new Set(e.filter(s=>s.kind==="secretary"||!t&&s.kind==="scratch").map(s=>s.id))}const KZ=300;let vc=null,Lw=!1,Th=null;function YZ(){const e=pe.getState(),t=J.getState(),r=eg(e.projects,sr(Mc)).filter(S=>qZ(S.kind)),o=new Set(sr(jr)),i=Uw(Ww(e.language),"Temporary chats"),a=new Map(e.projects.map(S=>[S.id,S.kind==="scratch"?i:qn(S)])),l=new Map(e.projects.map(S=>[S.id,S.path])),c=new Map(e.projects.map(S=>[S.id,S.kind])),u=S=>{const I=(S.parentId?t.conversations[S.parentId]:void 0)??S;return c.get(I.projectId)==="scratch"?fp({kind:"scratch",canonicalPath:l.get(I.projectId)??"",conversationId:I.id})??void 0:I.worktree?.path??l.get(S.projectId)},d=e.skills.filter(S=>S.enabled!==!1).map(S=>({name:`/skill:${S.name}`,description:S.description})),m=uu(t.conversations),h=pp.getState().byConversation,p=Date.now(),g=S=>{const I=zZ(S,m.get(S.id)),k=$Z(S,h[S.id],p),L=eI(S.occupancy,S.contextWindow),F={id:S.id,title:S.parentId&&S.coworkerName||S.title,projectName:a.get(S.projectId)??"",projectId:S.projectId,...u(S)?{cwd:u(S)}:{},status:I?.status??(S.spawning?"running":S.status),updatedAt:v1(S),...S.parentId?{parentId:S.parentId}:{},...S.pinned===!0?{pinned:!0}:{},...S.archived===!0?{archived:!0}:{},...S.muted===!0?{muted:!0}:{},...S.lastProviderId?{providerId:S.lastProviderId}:{},...S.lastModelId?{modelId:S.lastModelId}:{},...S.reasoningEnabled!==void 0?{reasoningEnabled:S.reasoningEnabled}:{},...S.thinkingLevel?{thinkingLevel:S.thinkingLevel}:{},...S.unread===!0?{unread:!0}:{},...Po(S.pendingAsks)>0?{pendingAskCount:Po(S.pendingAsks)}:{},...S.pendingApprovals&&S.pendingApprovals.length>0?{pendingApprovalCount:S.pendingApprovals.length}:{},...S.queuedMessages?.length?{queued:S.queuedMessages.map(A=>({id:A.id,text:A.text,...A.images?.length?{hasImages:!0}:{}}))}:{},...S.goal?{goal:{text:S.goal.text,status:S.goal.status,...S.goal.note?{note:S.goal.note}:{},autoTurns:S.goal.autoTurns}}:{},...k?{parked:k}:{},...d.length?{slashCommands:d}:{},...L?{context:L}:{},...S.usageTotals?{usageTotals:S.usageTotals}:{}};return I&&"queuePosition"in I&&Object.assign(F,{queuePosition:I.queuePosition}),I&&"queueFailed"in I&&Object.assign(F,{queueFailed:I.queueFailed}),F},x=t.order.map(S=>t.conversations[S]).filter(S=>!!S),v=new Set(t.order),b=Object.values(t.conversations).filter(S=>!!(S?.parentId&&v.has(S.parentId))),w=[...x,...b].map(g),j=GZ(e.projects,e.scratchSessionsEnabled),T=w.filter(S=>!j.has(S.projectId)),N=UZ(Gw(),zo.getState().snapshot,e.virtualModels);return{catalog:T,pinnedOrder:sr(Vm),projects:r.map(S=>({...BZ(S),...o.has(S.id)?{archived:!0}:{}})),projectGroups:e.projectGroups,providers:N.entries,providersSettled:N.settled,projectPaths:e.projects.map(S=>({id:S.id,path:S.path})),theme:e.theme,terminal:tj(e.terminalTheme),terminalFontFamily:e.terminalFontFamily,compactReadOnlyTools:e.compactReadOnlyTools,expandLiveEdits:e.expandLiveEdits,expandLiveReasoning:e.expandLiveReasoning,autoCollapseTurns:e.autoCollapseTurns,collapseCompletedActivity:e.collapseCompletedActivity,collapseLiveActivity:e.collapseLiveActivity,pinUnfinishedTodos:e.pinUnfinishedTodos}}function XZ(e){return HZ({catalog:VZ(e.catalog,e.pinnedOrder??[]),projects:e.projects,projectGroups:e.projectGroups,providers:e.providers,providersSettled:e.providersSettled,projectPaths:e.projectPaths,theme:e.theme,terminal:e.terminal,terminalFontFamily:e.terminalFontFamily,compactReadOnlyTools:e.compactReadOnlyTools,expandLiveEdits:e.expandLiveEdits,expandLiveReasoning:e.expandLiveReasoning,autoCollapseTurns:e.autoCollapseTurns,collapseCompletedActivity:e.collapseCompletedActivity,collapseLiveActivity:e.collapseLiveActivity,pinUnfinishedTodos:e.pinUnfinishedTodos})}function QZ(){return J.persist.hasHydrated()&&pe.persist.hasHydrated()}function Js(){vc&&clearTimeout(vc),vc=setTimeout(()=>{if(vc=null,!Nr()||!QZ())return;const e=YZ(),t=XZ(e);t!==Th&&(Th=t,window.electronAPI.pair.pushCatalog(e))},KZ)}function JZ(){Lw||(Lw=!0,Js(),J.persist.onFinishHydration(Js),pe.persist.onFinishHydration(Js),J.subscribe((e,t)=>{(e.conversations!==t.conversations||e.order!==t.order)&&Js()}),zo.subscribe((e,t)=>{e.snapshot!==t.snapshot&&Js()}),pp.subscribe((e,t)=>{e.byConversation!==t.byConversation&&Js()}),K3.subscribe((e,t)=>{e.snapshot!==t.snapshot&&Js()}),pe.subscribe((e,t)=>{(e.projects!==t.projects||e.projectGroups!==t.projectGroups||e.providers!==t.providers||e.theme!==t.theme||e.terminalTheme!==t.terminalTheme||e.terminalFontFamily!==t.terminalFontFamily||e.compactReadOnlyTools!==t.compactReadOnlyTools||e.expandLiveEdits!==t.expandLiveEdits||e.expandLiveReasoning!==t.expandLiveReasoning||e.autoCollapseTurns!==t.autoCollapseTurns||e.collapseCompletedActivity!==t.collapseCompletedActivity||e.collapseLiveActivity!==t.collapseLiveActivity||e.pinUnfinishedTodos!==t.pinUnfinishedTodos||e.skills!==t.skills)&&Js()}),VN(Js),Y3(e=>{e&&(Th=null,Js())}),window.electronAPI.pair.onResumeSession(e=>{Yg(e),Nr()&&(J.getState().markConversationRead(e),J.getState().resumeConversation(e))}),window.electronAPI.pair.onSessionCreated(e=>{Yg(e.sessionId),Nr()&&J.getState().adoptPairSession(e)}),window.electronAPI.pair.onSessionConfig(e=>{if(!Nr())return;const t=J.getState();e.type==="set-model"?t.setModel(e.sessionId,e.providerId,e.modelId):e.type==="set-reasoning"?t.setReasoning(e.sessionId,e.enabled):t.setThinking(e.sessionId,e.level)}),window.electronAPI.pair.onQueueAction(e=>{if(!Nr())return;const t=J.getState();switch(e.type){case"enqueue":t.enqueueMessage(e.sessionId,e.text,e.images);break;case"queue-remove":t.removeQueuedMessage(e.sessionId,e.messageId);break;case"queue-update":t.updateQueuedMessage(e.sessionId,e.messageId,e.text);break;case"queue-send-now":t.sendQueuedNow(e.sessionId,e.messageId);break;case"queue-interrupt-send":t.interruptAndSendQueued(e.sessionId,e.messageId);break;case"goal-pause":t.pauseGoal(e.sessionId);break;case"goal-resume":t.resumeGoal(e.sessionId);break;case"goal-clear":t.clearGoal(e.sessionId);break;case"goal-set":t.setGoal(e.sessionId,e.text);break;case"compact":t.compact(e.sessionId,e.instructions,{quiet:!0});break;case"rewind":t.rewind(e.sessionId,e.userIndexFromEnd,e.restoreFiles);break;case"retry":t.retry(e.sessionId);break;case"task-stop":window.electronAPI.agent.stopTask(e.sessionId,e.taskId);break;case"subagent-stop":window.electronAPI.agent.stopSubagent(e.sessionId,e.agentId);break}}))}const ZZ=3e4;async function eee(e,t=Date.now()){const{order:s,conversations:r,activeId:o}=J.getState(),i=s.flatMap(d=>{const m=r[d];return!m||m.parentId?[]:(d===o||m.status==="running"||m.spawning===!0||m.workspaceMigrating===!0||(m.pendingAsks?.length??0)>0||(m.pendingApprovals?.length??0)>0)&&e.kind==="stale"?[]:[{id:d,projectId:m.projectId,archived:m.archived,archivedAt:m.archivedAt,pinned:m.pinned,lastActiveAt:v1(m)}]}),a=X3(i,e,t),l=J.getState();for(const d of a)l.removeConversation(d);const c=Date.now()+ZZ,u=()=>a.filter(d=>J.getState().conversations[d]);for(;u().length>0&&Date.now()<c;)await new Promise(d=>setTimeout(d,200));return a.length-u().length}const tee=f.lazy(()=>Hd(()=>import("./SidePanel-DkSc3og9.js"),__vite__mapDeps([7,1,2,8,4,3,6,9]),import.meta.url).then(e=>({default:e.SidePanel}))),nee=e=>{const t=WM(e);return t.length>0?t:k1(e)},_w="enso-sidebar-width",Bw="enso-sidebar-collapsed";function bc(){const e=J.getState(),s=(e.activeId?e.conversations[e.activeId]:null)?.projectId??pe.getState().projects[0]?.id;s&&e.newConversation(s)}const yc="no-drag flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",Fw=200,zw=420;function see(){const e=pe(ue=>ue.onboarded),t=f.useSyncExternalStore(ue=>pe.persist?.onFinishHydration?.(ue)??(()=>{}),()=>pe.persist?.hasHydrated?.()??!0);Q3(),dZ(),lZ(),xZ(),yZ(),cZ();const[s,r]=f.useState(!1),[o,i]=f.useState(null);NZ();const[a,l]=f.useState(()=>{const ue=Number(localStorage.getItem(_w));return Number.isFinite(ue)&&ue>=Fw?Math.min(ue,zw):280}),[c,u]=f.useState(()=>localStorage.getItem(Bw)==="1"),d=Ho(),m=J3(),[h,p]=f.useState(!1),g=f.useCallback(()=>p(!1),[]);f.useEffect(()=>{d||p(!1)},[d]),f.useEffect(()=>J.subscribe((ue,We)=>{ue.activeId!==We.activeId&&p(!1)}),[]);const{t:x}=z(),v=pe(ue=>ue.chatWide),b=J(ue=>ue.activeId),w=qh(b),j=os(ue=>ue.uiByConversation[b??""]?.width??ue.lastWidth),T=os(ue=>ue.fullscreen),N=os(ue=>ue.toggleOpen),S=ie(ue=>ue.panelOpen),I=ie(ue=>ue.togglePanel);f.useEffect(()=>{T&&!w&&os.getState().setFullscreen(!1)},[w,T]),f.useEffect(()=>Z3(),[]),f.useEffect(()=>(document.documentElement.classList.add("enso-main-shell"),()=>document.documentElement.classList.remove("enso-main-shell")),[]),f.useEffect(()=>window.electronAPI.app.onCloseRequest(i),[]),f.useEffect(()=>window.electronAPI.app.onFlushPersist(ue=>{eM().finally(()=>{window.electronAPI.app.respondFlushPersist(ue)})}),[]);const k=ue=>{const We=o;We&&(i(null),window.electronAPI.app.respondCloseRequest(We,{action:ue}))},L=f.useCallback(()=>{tM(window.innerWidth)?p(ue=>!ue):u(ue=>!ue)},[]),F=f.useCallback(()=>{window.electronAPI.env.platform==="darwin"&&window.setTimeout(()=>window.electronAPI.window.refreshDragRegions(),400)},[]),A=f.useCallback(()=>{L(),F()},[L,F]);f.useEffect(()=>SZ(A),[A]),f.useEffect(()=>window.electronAPI.window.onToggleSidebar(A),[A]);const[M,R]=f.useState(!1),$=f.useRef(null);f.useEffect(()=>{localStorage.setItem(_w,String(a))},[a]),f.useEffect(()=>{localStorage.setItem(Bw,c?"1":"0")},[c]),f.useEffect(()=>window.electronAPI.resources.onSessionsCleanRequest(({requestId:ue,request:We})=>{eee(We).catch(()=>0).then(it=>window.electronAPI.resources.sessionsCleanDone(ue,it))}),[]),f.useEffect(()=>{JZ()},[]),f.useEffect(()=>{const ue=window.electronAPI.remote;return ue&&!ue.nativePlatform?void 0:$u.getState().bind()},[]);const U=$u(ue=>ue.pairDialogOpen),q=F8(),te=pe(ue=>ue.botModeEnabled),V=pe(ue=>ue.headerSessionTabs),se=Er(ue=>ue.mode);f.useEffect(()=>{const ue=pe.persist?.hasHydrated?.()??!0;se==="bot"&&ue&&!te&&Er.getState().setMode("code")},[se,te]),f.useEffect(()=>{if(!te)return;const ue=ie.getState().bind(),We=window.electronAPI.bots.onEvent(it=>{it.kind==="open"&&z8(it)});return()=>{ue(),We()}},[te]);const Ce=pe(ue=>ue.secretaryEnabled),de=kt(ue=>ue.welcomeOpen),re=_o(ue=>ue.open);f.useEffect(()=>Ce?kt.getState().bind():void 0,[Ce]),f.useEffect(()=>window.electronAPI.agent.onFocusSession(ue=>{J.getState().conversations[ue]&&rx()}),[]);const Z=f.useCallback(ue=>{l(We=>Math.min(zw,Math.max(Fw,We+ue)))},[]),me=pe(ue=>ue.keybindings);f.useEffect(()=>{const ue=Pr(me),We=Fe=>{const tt=J.getState(),ke=tt.activeId?tt.conversations[tt.activeId]:null;if(!ke)return;const nt=[void 0,...ke.coworkerIds??[]];if(nt.length<=1)return;const mt=nt.indexOf(ke.activeTabId);tt.selectTab(ke.id,nt[(mt+Fe+nt.length)%nt.length])},it=Fe=>{const tt=Yc(Fe);if(!tt)return;if(tt===ue["toggle-app-mode"]){if(!pe.getState().botModeEnabled)return;Fe.preventDefault();const mt=Er.getState();mt.setMode(mt.mode==="bot"?"code":"bot");return}const ke=$v();if(ke&&tt===ue["toggle-side-panel"]){Fe.preventDefault(),ie.getState().togglePanel();return}if(ke&&tt===ue["search-workspace"]){Fe.preventDefault(),ie.getState().setSearchOpen(!0);return}if(!(ke&&["new-conversation","next-tab","prev-tab","toggle-side-panel","toggle-side-panel-fullscreen","new-side-tab","new-btw-tab","close-side-tab","find-in-chat","search-workspace","open-secretary"].some(nt=>tt===ue[nt]))){if(tt===ue["toggle-sidebar"]){if(Fe.preventDefault(),cM(Fe,tt))return;A()}else if(tt===ue["open-settings"])Fe.preventDefault(),window.electronAPI.window.openSettings();else if(tt===ue["open-secretary"])pe.getState().secretaryEnabled&&(Fe.preventDefault(),Hc());else if(tt===ue["new-conversation"])Fe.preventDefault(),bc();else if(tt===ue["new-side-tab"])Fe.preventDefault(),dM(Fe.target)?uM():bc();else if(tt===ue["new-btw-tab"])Fe.preventDefault(),fM();else if(tt===ue["next-tab"])Fe.preventDefault(),We(1);else if(tt===ue["prev-tab"])Fe.preventDefault(),We(-1);else if(tt===ue["toggle-side-panel"])Fe.preventDefault(),os.getState().toggleOpen();else if(tt===ue["toggle-side-panel-fullscreen"])Fe.preventDefault(),os.getState().toggleFullscreen();else if(tt===ue["close-side-tab"])Fe.preventDefault(),mM();else if(tt===ue["focus-composer"])Fe.preventDefault(),zi();else if(tt===ue["find-in-chat"])Fe.preventDefault(),D2();else if(tt===ue["search-workspace"])Fe.preventDefault(),r(!0);else if(!ke){const nt=hM(e1(),me,ue).byBinding.get(tt);if(!nt)return;Fe.preventDefault();const mt=J.getState(),X=mt.activeId?mt.conversations[mt.activeId]:null;mp(nt,X?X.activeTabId??X.id:null).then(K=>{K&&Ie({type:"error",title:nt.title,description:K})})}}};return window.addEventListener("keydown",it),()=>window.removeEventListener("keydown",it)},[me,A]),f.useEffect(()=>{if(!w||!T)return;const ue=We=>{We.key==="Escape"&&($v()||(We.preventDefault(),os.getState().setFullscreen(!1)))};return window.addEventListener("keydown",ue),()=>window.removeEventListener("keydown",ue)},[w,T]);const xe=OM(DM(wp,{activationConstraint:{distance:6}})),Se=up(),W=Se!=="mobile"&&!q,H=f.useCallback(ue=>{const We=$.current;if(!We)return;const it=getComputedStyle(We),Fe=We.clientWidth-parseFloat(it.paddingLeft)-parseFloat(it.paddingRight);os.getState().nudgeWidth(-ue,Fe,W?nM:Gj)},[W]),B=te?n.jsx(YG,{}):null,ne=W&&(Se==="mac"||Se==="windows"||Se==="web"),ve=ne&&w&&!d&&!q,he=V&&W&&!te&&!(ve&&T)?n.jsx(d8,{onNew:bc}):null,G=n.jsx("button",{type:"button",className:_("flex items-center justify-center rounded-md transition-colors hover:bg-accent/50",d?"h-9 w-9":W?yc:"h-7 w-7",(q?S:w)?"text-foreground":"text-muted-foreground"),onClick:q?I:N,"aria-label":x("Toggle side panel"),title:x("Toggle side panel"),children:n.jsx(PB,{className:"h-4 w-4"})}),we=n.jsx("button",{type:"button",className:_("flex h-7 w-7 items-center justify-center rounded-md transition-colors hover:bg-accent/50",v?"text-foreground":"text-muted-foreground",d&&"hidden"),onClick:()=>pe.getState().setChatWide(!v),"aria-label":x(v?"Use reading width":"Use full chat width"),title:x(v?"Use reading width":"Use full chat width"),children:v?n.jsx(K_,{className:"h-4 w-4"}):n.jsx(sF,{className:"h-4 w-4"})}),ce=n.jsxs(n.Fragment,{children:[we,G]}),Re=W?{trailing:we}:null;return n.jsxs("div",{"data-enso":"canvas",className:_("relative isolate flex flex-col",d?"h-dvh":"h-screen"),children:[n.jsx(sM,{}),n.jsx(rM,{}),n.jsx(zF,{}),n.jsx(U8,{}),n.jsx(oM,{}),Se!=="mobile"?n.jsx(Xg,{leading:n.jsxs("div",{className:"flex items-center gap-0.5",children:[n.jsx("div",{className:_(Se!=="mac"&&"flex justify-center",Se!=="mac"&&(W?"w-[48px]":"w-12")),children:n.jsx("button",{type:"button","data-enso":"sidebar-toggle",className:yc,onClick:A,title:x(c?"Expand sidebar":"Collapse sidebar"),children:c?n.jsx(AN,{className:"h-4 w-4"}):n.jsx(tx,{className:"h-4 w-4"})})}),W&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button","data-enso":"search-button",className:yc,onClick:()=>r(!0),title:x("Search anything"),children:n.jsx(dr,{className:"h-4 w-4"})}),n.jsx("button",{type:"button","data-enso":"new-session",className:yc,onClick:bc,title:x("New conversation"),children:n.jsx(GB,{className:"h-4 w-4"})})]})]}),centered:(ve&&T?null:B)??void 0,middle:he,className:_(Se!=="mac"&&"pl-0",W&&"border-b-0",W&&"bg-transparent",W&&Se==="mac"&&"pr-4"),actions:W?ve?void 0:G:ce}):n.jsx(Xg,{title:"EnsoCode",centered:B??void 0,leading:d&&!q?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{type:"button","data-enso":"sidebar-toggle",className:"-ml-1.5 flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:()=>p(!0),"aria-label":x("Conversations"),title:x("Conversations"),children:n.jsx(kB,{className:"h-5 w-5"})}),!B&&n.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"EnsoCode"})]}):void 0,actions:ce}),!W&&n.jsx(Wv,{}),!W&&n.jsx(Uv,{}),!W&&n.jsx(qv,{}),n.jsx("div",{className:"flex min-h-0 flex-1",children:q?n.jsx(WG,{sidebarWidth:a,collapsed:c,onToggleCollapse:A,onResize:Z}):n.jsxs(LP,{sensors:xe,collisionDetection:nee,children:[d?n.jsxs(n.Fragment,{children:[n.jsx(ya,{children:h&&n.jsx(Ns.div,{className:"fixed inset-0 bg-black/40",style:{zIndex:Pn.MOBILE_DRAWER},initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:g},"drawer-backdrop")}),n.jsx(Ns.div,{className:"fixed inset-y-0 left-0 flex bg-background shadow-xl",style:{zIndex:Pn.MOBILE_DRAWER},initial:!1,animate:{x:h?0:"-105%"},transition:gi,inert:!h,children:n.jsx(pw,{width:Math.min(320,Math.round(m*.85)),collapsed:!1,onToggleCollapse:g,onOpenSearch:()=>r(!0),onNavigate:g})})]}):n.jsxs(n.Fragment,{children:[n.jsx(pw,{width:c?void 0:a,collapsed:c,onToggleCollapse:A,onOpenSearch:()=>r(!0)}),!c&&n.jsx(jd,{edge:W,onResize:Z})]}),n.jsxs("div",{ref:$,className:_("relative flex min-h-0 min-w-0 flex-1",ne?"overflow-x-clip":"overflow-hidden",W&&"-mt-px -ml-px pt-px pr-[8px] pb-[8px] pl-px"),children:[n.jsxs("div",{"data-enso":"main",className:_("relative flex min-h-0 min-w-0 flex-1 flex-col bg-background",W&&"overflow-hidden rounded-[10px] shadow-surface",ve&&"rounded-r-none"),style:w&&T?{visibility:"hidden",transition:`visibility 0s ${Id.duration}s`}:void 0,children:[n.jsx(MZ,{}),n.jsx(HF,{hidden:Ce&&de||re,children:n.jsx(iM.Provider,{value:Re,children:n.jsx(BX,{})})}),W&&n.jsx(Wv,{}),W&&n.jsx(Uv,{}),W&&n.jsx(qv,{}),Ce&&de&&n.jsx(WJ,{}),re&&n.jsx(az,{})]}),w&&!T&&!d&&n.jsx(jd,{gap:W&&!ve,onResize:H,onResizingChange:R}),n.jsx(f.Suspense,{fallback:null,children:n.jsx(tee,{width:j,resizing:M,card:W,titleRow:ne})})]})]})}),t&&!e&&!window.electronAPI.remote&&n.jsx(yJ,{}),n.jsx(HJ,{open:s,onOpenChange:r}),n.jsx(aZ,{}),n.jsx(aM,{open:U,onOpenChange:$u.getState().setPairDialogOpen}),n.jsx(Rh,{open:o!==null,onOpenChange:ue=>{!ue&&o&&k("cancel")},children:n.jsxs(Mh,{className:"sm:max-w-sm",children:[n.jsxs(Ph,{children:[n.jsx(Dh,{className:"text-base",children:x("Confirm exit")}),n.jsx(Oh,{children:x("Exit closes the app completely, so your phone can no longer connect. Minimize to tray keeps the app running in the background so your phone can still connect.")})]}),n.jsxs(Lh,{variant:"bare",children:[n.jsx(lM,{render:n.jsx(fe,{variant:"outline",size:"sm"}),children:x("Cancel")}),n.jsx(fe,{size:"sm",onClick:()=>k("tray"),children:x("Minimize to tray")}),n.jsx(fe,{variant:"destructive",size:"sm",onClick:()=>k("quit"),children:x("Exit")})]})]})}),n.jsx(ez,{})]})}function ree(e){return new Worker(""+new URL("worker-DsKBD11i.js",import.meta.url).href,{type:"module",name:e?.name})}const oee={workerFactory:()=>new ree,poolSize:2},iee={theme:gM,langs:[...xM],preferredHighlighter:"shiki-js"};function aee({children:e}){return n.jsx(pM,{poolOptions:oee,highlighterOptions:iee,children:e})}function $w({conversations:e,activeId:t}){const s=document.documentElement.dataset,r=nQ(e),o=mI(t?e[t]:void 0,e);s.ensoActivity!==r&&(s.ensoActivity=r),s.ensoSession!==o&&(s.ensoSession=o)}function lee(){$w(J.getState()),J.subscribe((e,t)=>{(e.conversations!==t.conversations||e.activeId!==t.activeId)&&$w(e)})}vM();lee();bM();wj();yM.createRoot(document.getElementById("root")).render(n.jsx(f.StrictMode,{children:n.jsx(aee,{children:n.jsx(see,{})})}));export{wee as $,Bi as A,_r as B,Uo as C,m2 as D,f2 as E,kY as F,JJ as G,hY as H,ex as I,tX as J,dx as K,xee as L,$m as M,$N as N,zi as O,TN as P,wK as Q,zB as R,cu as S,mX as T,Ka as U,lu as V,nU as W,Hs as X,EW as Y,RW as Z,oU as _,lx as a,bee as a0,yee as a1,Bv as a2,jd as a3,C_ as a4,z1 as a5,gee as a6,Ns as a7,IW as a8,hF as a9,fee as aa,aB as ab,Ss as ac,PB as ad,dU as ae,vee as af,Vi as b,kt as c,yH as d,qa as e,ZV as f,FS as g,px as h,wd as i,xx as j,ux as k,sl as l,KV as m,uu as n,kH as o,JF as p,Sl as q,rw as r,ax as s,ao as t,$i as u,QQ as v,mee as w,hee as x,pee as y,B2 as z};
|