@ensocode/server 0.3.13 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/out/phone/assets/{EditDiff-B3HxLrbF.js → EditDiff-7At9BpWJ.js} +1 -1
  2. package/out/phone/assets/{ReadFileView-BFpGH-kK.js → ReadFileView-CFkjh0Xx.js} +1 -1
  3. package/out/phone/assets/{abnfDiagram-VCTEODGH-BNvyPGoF.js → abnfDiagram-VCTEODGH-D4384sfe.js} +1 -1
  4. package/out/phone/assets/architecture-7GRP2DOG-vDamN_Vr.js +1 -0
  5. package/out/phone/assets/{architectureDiagram-5GKGNRK7-1bhpTEFA.js → architectureDiagram-5GKGNRK7-CjzMXFHb.js} +1 -1
  6. package/out/phone/assets/{blockDiagram-I7D4REHJ-Bo9UMudu.js → blockDiagram-I7D4REHJ-COX4_2NT.js} +1 -1
  7. package/out/phone/assets/{c4Diagram-7LVT6UL2-YS11cig2.js → c4Diagram-7LVT6UL2-C0PHCrzg.js} +1 -1
  8. package/out/phone/assets/channel-TsMJYH0f.js +1 -0
  9. package/out/phone/assets/{chunk-4HAMMTFA-gA-CzNGD.js → chunk-4HAMMTFA-BSqiGn28.js} +1 -1
  10. package/out/phone/assets/{chunk-75Z2AOVW-BL_5b1Dw.js → chunk-75Z2AOVW-7eocu_Pa.js} +1 -1
  11. package/out/phone/assets/{chunk-DU6HZSFF-BpNlAs9R.js → chunk-DU6HZSFF-DMttOQUE.js} +1 -1
  12. package/out/phone/assets/{chunk-F27PBJKO-lsKx96Nt.js → chunk-F27PBJKO-BFNRrOvq.js} +1 -1
  13. package/out/phone/assets/{chunk-GMAD6QVW-CxbljbtE.js → chunk-GMAD6QVW-DPVV1Shj.js} +1 -1
  14. package/out/phone/assets/{chunk-GVQU2GXP-CTO3kTOF.js → chunk-GVQU2GXP-YataTcA_.js} +1 -1
  15. package/out/phone/assets/{chunk-IMKFNOWR-Cq8XlkcB.js → chunk-IMKFNOWR-DBQKd74U.js} +1 -1
  16. package/out/phone/assets/{chunk-L3NEJ4N5-CvIm0JX7.js → chunk-L3NEJ4N5-DXfrfXkv.js} +1 -1
  17. package/out/phone/assets/{chunk-OSK3NFVY-Cj3ilTL-.js → chunk-OSK3NFVY-DWr7pP6Q.js} +1 -1
  18. package/out/phone/assets/{chunk-P2QGCYS3-B-twI_Fz.js → chunk-P2QGCYS3-C_qNKS0g.js} +1 -1
  19. package/out/phone/assets/{chunk-POPQ4Y6H-lPQttJ5s.js → chunk-POPQ4Y6H-BhJK3UtM.js} +1 -1
  20. package/out/phone/assets/{chunk-PWAF6VOD-DjwqZuIR.js → chunk-PWAF6VOD-MmcwGVgC.js} +1 -1
  21. package/out/phone/assets/{chunk-SHT3W25Y-BWRVin1H.js → chunk-SHT3W25Y-BQHA3p2Q.js} +1 -1
  22. package/out/phone/assets/{chunk-SVP7TREG-CGLhvnsS.js → chunk-SVP7TREG-DbQH56Ci.js} +1 -1
  23. package/out/phone/assets/{chunk-TICWLB2K-DkFUa03q.js → chunk-TICWLB2K-pixKba1z.js} +1 -1
  24. package/out/phone/assets/classDiagram-ZZMXUADV-Bhtnzu97.js +1 -0
  25. package/out/phone/assets/classDiagram-v2-VYDZK3BY-Bhtnzu97.js +1 -0
  26. package/out/phone/assets/{codeHighlighter-jQti-W31.js → codeHighlighter-CrZcFhK_.js} +1 -1
  27. package/out/phone/assets/{cynefin-OW5HDTMX-L8oWVu5S.js → cynefin-OW5HDTMX-67ETi-0P.js} +1 -1
  28. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-DH8-4p4N.js → cynefinDiagram-5FMLGOSQ-C3wqlm_-.js} +1 -1
  29. package/out/phone/assets/{dagre-GXQ25YYZ-HhLDmcu9.js → dagre-GXQ25YYZ-DTC1fZsc.js} +1 -1
  30. package/out/phone/assets/desk-B382G0e_.js +52 -0
  31. package/out/phone/assets/{diagram-S7CK7UJ4-CeIbR3Ir.js → diagram-S7CK7UJ4-uqcU7OpS.js} +1 -1
  32. package/out/phone/assets/{diagram-UQ7AKVKN-BQ84Qnq6.js → diagram-UQ7AKVKN-BQ6K9f6g.js} +1 -1
  33. package/out/phone/assets/{diagram-VSXAHHWV-aF_J57fD.js → diagram-VSXAHHWV-CDzRWkI9.js} +1 -1
  34. package/out/phone/assets/{diagram-VX7I27RA-Bg1ZqM4Y.js → diagram-VX7I27RA-CvI10CG1.js} +1 -1
  35. package/out/phone/assets/{diagram-Z3DM3KII-DjTkPAqa.js → diagram-Z3DM3KII-DM8G_CIZ.js} +1 -1
  36. package/out/phone/assets/{ebnfDiagram-PWID7BFC-DPsH5Eky.js → ebnfDiagram-PWID7BFC-BBbLoaIE.js} +1 -1
  37. package/out/phone/assets/{erDiagram-RLTQ6QDP-ExvY7e6T.js → erDiagram-RLTQ6QDP-Dz98FGLq.js} +1 -1
  38. package/out/phone/assets/eventmodeling-NTZA5JFV-BGT2L4_J.js +1 -0
  39. package/out/phone/assets/flowDiagram-HODETNUW-CpTX9nm5.js +1 -0
  40. package/out/phone/assets/{ganttDiagram-EL5Y4UJY-hCe06ucl.js → ganttDiagram-EL5Y4UJY-BADRjlHl.js} +1 -1
  41. package/out/phone/assets/{gitGraph-4MIJSDKK-BuZ6lDat.js → gitGraph-4MIJSDKK-DQGKRsA2.js} +1 -1
  42. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-D-8aVxvj.js → gitGraphDiagram-WWUBYQGX-DrLRujhH.js} +1 -1
  43. package/out/phone/assets/{info-A6RAGUB7-CrZtdoYs.js → info-A6RAGUB7-b7IbwKqs.js} +1 -1
  44. package/out/phone/assets/{infoDiagram-27XIBGKW-BLRFHxtO.js → infoDiagram-27XIBGKW-BNbXaMmR.js} +1 -1
  45. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-D7SYWKoj.js → ishikawaDiagram-5VMMS53U-B3SG131F.js} +1 -1
  46. package/out/phone/assets/{journeyDiagram-3NMN7TZE-BPsg7CQD.js → journeyDiagram-3NMN7TZE-BoRfNykb.js} +1 -1
  47. package/out/phone/assets/{kanban-definition-UXKFOSKX-CbPuNr-E.js → kanban-definition-UXKFOSKX-D0tKrJ8_.js} +1 -1
  48. package/out/phone/assets/{line-CkpKMiqK.js → line-W1HWn4B7.js} +1 -1
  49. package/out/phone/assets/main-Bc8DQVa6.css +2 -0
  50. package/out/phone/assets/main-Bez4gfKe.js +281 -0
  51. package/out/phone/assets/{mermaid-parser.core-RTq_mEm1.js → mermaid-parser.core-CpGE7UgS.js} +3 -3
  52. package/out/phone/assets/{mermaid.core-D9LtIKua.js → mermaid.core-wueTI3u_.js} +4 -4
  53. package/out/phone/assets/{mindmap-definition-YA3MSWOX-8cGgRiRD.js → mindmap-definition-YA3MSWOX-BDctzErY.js} +1 -1
  54. package/out/phone/assets/{packet-AYTQ26CC-D9-eSn0v.js → packet-AYTQ26CC-C0YWsXol.js} +1 -1
  55. package/out/phone/assets/{pegDiagram-XKGWAZYB-DztU_rIE.js → pegDiagram-XKGWAZYB-C97XjNI7.js} +1 -1
  56. package/out/phone/assets/{pie-WAS4IAKB-Bk2Tqaq_.js → pie-WAS4IAKB-BxuJ1GKP.js} +1 -1
  57. package/out/phone/assets/{pieDiagram-E7YTZNPT-Dm_3mJ9_.js → pieDiagram-E7YTZNPT-SP4DeWDw.js} +1 -1
  58. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-lKskzjzu.js → quadrantDiagram-AXDQQJYC-DDHL4rrG.js} +1 -1
  59. package/out/phone/assets/{radar-RG4KPBEZ-B2z8Txd8.js → radar-RG4KPBEZ-AzVB8zoH.js} +1 -1
  60. package/out/phone/assets/{railroad-74A4TZTK-11VmdALq.js → railroad-74A4TZTK-CA2_A72l.js} +1 -1
  61. package/out/phone/assets/railroad-abnf-HS5TGJTU-CTHhRGvc.js +1 -0
  62. package/out/phone/assets/railroad-ebnf-LZEXJU2U-CS68P4fL.js +1 -0
  63. package/out/phone/assets/railroad-peg-WCYAUIDC-BqCcrVdf.js +1 -0
  64. package/out/phone/assets/{railroadDiagram-O6MQD6OU-Dr0NTIA6.js → railroadDiagram-O6MQD6OU-D5zpQ5kq.js} +1 -1
  65. package/out/phone/assets/{requirementDiagram-BXWQKSXE-C0W6h_5I.js → requirementDiagram-BXWQKSXE-DkQKt5hJ.js} +1 -1
  66. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-CVJDathY.js → sankeyDiagram-P5KCCOFB-xeXrVMVr.js} +1 -1
  67. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-BxHQTG6x.js → sequenceDiagram-WJ2MYXX4-BOiNtyS8.js} +1 -1
  68. package/out/phone/assets/shellUpdate-C4yk9AaU.js +1 -0
  69. package/out/phone/assets/{stateDiagram-D77RDMKH-BO5MAjhs.js → stateDiagram-D77RDMKH-Bs8LX9-n.js} +1 -1
  70. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-nBP_YibA.js +1 -0
  71. package/out/phone/assets/{swimlanes-42K2YHIH-DnhDPyy6.js → swimlanes-42K2YHIH-DQVYfgSI.js} +1 -1
  72. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-BkfzXxS-.js +8 -0
  73. package/out/phone/assets/{timeline-definition-24CTP7MA-bLEjS7re.js → timeline-definition-24CTP7MA-BlpgdxeN.js} +1 -1
  74. package/out/phone/assets/{treeView-Q6P3EWNA-Ci-sA9wK.js → treeView-Q6P3EWNA-D0PiggHr.js} +1 -1
  75. package/out/phone/assets/{treemap-WGGIJYW6-BXCjzK65.js → treemap-WGGIJYW6-DA07Kvo0.js} +1 -1
  76. package/out/phone/assets/{vennDiagram-4TSXK5OY-DHsj5dRx.js → vennDiagram-4TSXK5OY-BtvfF1a4.js} +1 -1
  77. package/out/phone/assets/{wardley-WFR3VGLG-d8TdCu-H.js → wardley-WFR3VGLG-Db-UrSZJ.js} +1 -1
  78. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-DQFVP9qu.js → wardleyDiagram-VM6X3IG4-CaBnqFYM.js} +1 -1
  79. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-Dni2Y0ov.js → xychartDiagram-S5SC5T6Z-Bbzz9YwS.js} +1 -1
  80. package/out/phone/desk.html +3 -3
  81. package/out/phone/index.html +4 -4
  82. package/out/phone/sw.js +2 -2
  83. package/out/renderer/assets/{EditDiff-DxxLuCEI.js → EditDiff-C9JBUR0o.js} +1 -1
  84. package/out/renderer/assets/{File-Tz3MUtN6.js → File-BIf-onMm.js} +1 -1
  85. package/out/renderer/assets/{ReadFileView-DFoLPU04.js → ReadFileView-C5AKNlFU.js} +1 -1
  86. package/out/renderer/assets/{SidePanel-D0m4IYxS.css → SidePanel-DN2RL6QD.css} +1 -1
  87. package/out/renderer/assets/SidePanel-DkSc3og9.js +48 -0
  88. package/out/renderer/assets/{Virtualizer-B0uwx_XV.js → Virtualizer-tZu4hGtC.js} +1 -1
  89. package/out/renderer/assets/{abnfDiagram-VCTEODGH-CJ9nn9eH.js → abnfDiagram-VCTEODGH-DxBBUZxF.js} +1 -1
  90. package/out/renderer/assets/{arc-B8im8n0O.js → arc-DXzwxP4j.js} +1 -1
  91. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-BRSi5FBk.js → architectureDiagram-5GKGNRK7-Bcykp-Fb.js} +1 -1
  92. package/out/renderer/assets/{blockDiagram-I7D4REHJ-CQ1wirIl.js → blockDiagram-I7D4REHJ-P7zMiiL3.js} +1 -1
  93. package/out/renderer/assets/{c4Diagram-7LVT6UL2-9HyLIioe.js → c4Diagram-7LVT6UL2-BVD9zEE8.js} +1 -1
  94. package/out/renderer/assets/channel-7bWV5QTy.js +1 -0
  95. package/out/renderer/assets/{chunk-2Q5K7J3B-BwC9g3bx.js → chunk-2Q5K7J3B-BXj05DaP.js} +1 -1
  96. package/out/renderer/assets/{chunk-5VM5RSS4-DMtgxPBL.js → chunk-5VM5RSS4-D-SpodcG.js} +1 -1
  97. package/out/renderer/assets/{chunk-F27PBJKO-DSi_XV5v.js → chunk-F27PBJKO-ORLEQ9sv.js} +1 -1
  98. package/out/renderer/assets/{chunk-IMKFNOWR-Dctc6Apj.js → chunk-IMKFNOWR-1lhHjr20.js} +1 -1
  99. package/out/renderer/assets/{chunk-JWPE2WC7-I2BD5qM7.js → chunk-JWPE2WC7-BgmlC9Vl.js} +1 -1
  100. package/out/renderer/assets/{chunk-POPQ4Y6H-k60pc4eT.js → chunk-POPQ4Y6H-DPEfkZnH.js} +1 -1
  101. package/out/renderer/assets/{chunk-SVP7TREG-zCGemfqm.js → chunk-SVP7TREG-7_S5Geoi.js} +1 -1
  102. package/out/renderer/assets/{chunk-TICWLB2K-CdDiHIq-.js → chunk-TICWLB2K-BKi8yvLf.js} +1 -1
  103. package/out/renderer/assets/{chunk-XXDRQBXY-GYVDxVfN.js → chunk-XXDRQBXY-PfB25f1D.js} +1 -1
  104. package/out/renderer/assets/classDiagram-ZZMXUADV-mgQwYiWM.js +1 -0
  105. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-mgQwYiWM.js +1 -0
  106. package/out/renderer/assets/{cose-bilkent-JH36ORCC-BnSAtUh-.js → cose-bilkent-JH36ORCC-C246yayw.js} +1 -1
  107. package/out/renderer/assets/{cynefin-OW5HDTMX-DnQaS9VN.js → cynefin-OW5HDTMX-Dr9W26Pe.js} +1 -1
  108. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-BNQdw0PV.js → cynefinDiagram-5FMLGOSQ-B3Jtuns2.js} +1 -1
  109. package/out/renderer/assets/{cytoscape-fcose-CzkrRInm.js → cytoscape-fcose-CJat50hU.js} +1 -1
  110. package/out/renderer/assets/{dagre-GXQ25YYZ-fG1vMsyn.js → dagre-GXQ25YYZ-Dt2pulYx.js} +1 -1
  111. package/out/renderer/assets/{diagram-S7CK7UJ4-BcfAFVc2.js → diagram-S7CK7UJ4-Bx-0FuVR.js} +1 -1
  112. package/out/renderer/assets/{diagram-UQ7AKVKN-D8f3Tsx9.js → diagram-UQ7AKVKN-D-8o1p4p.js} +1 -1
  113. package/out/renderer/assets/{diagram-VSXAHHWV-B-U9CIWt.js → diagram-VSXAHHWV-CI0jUOHM.js} +1 -1
  114. package/out/renderer/assets/{diagram-VX7I27RA-CX6ifTkJ.js → diagram-VX7I27RA-Byl54mOd.js} +1 -1
  115. package/out/renderer/assets/{diagram-Z3DM3KII-49dS9s3L.js → diagram-Z3DM3KII-Kf_GIJ7p.js} +1 -1
  116. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-CraGJRI7.js → ebnfDiagram-PWID7BFC-BbOdw7R1.js} +1 -1
  117. package/out/renderer/assets/{erDiagram-RLTQ6QDP-CfMNvEoW.js → erDiagram-RLTQ6QDP-UjxTTQ7M.js} +1 -1
  118. package/out/renderer/assets/{flowDiagram-HODETNUW-C8XM3p4T.js → flowDiagram-HODETNUW-BVuwOxKp.js} +1 -1
  119. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-DlJBMKFX.js → ganttDiagram-EL5Y4UJY-BpBSO-4X.js} +1 -1
  120. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-DvEzDsKF.js → gitGraphDiagram-WWUBYQGX-b72vZ1j2.js} +1 -1
  121. package/out/renderer/assets/globals-2G408HiJ.css +1 -0
  122. package/out/renderer/assets/globals-BqVjlAT_.js +673 -0
  123. package/out/renderer/assets/index-AHhNcASr.js +113 -0
  124. package/out/renderer/assets/{infoDiagram-27XIBGKW-CckfBO-R.js → infoDiagram-27XIBGKW-CtnN4sif.js} +1 -1
  125. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-mUoXchkB.js → ishikawaDiagram-5VMMS53U-B2YfGNEH.js} +1 -1
  126. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-zzLL0HFW.js → journeyDiagram-3NMN7TZE-fUfanA7T.js} +1 -1
  127. package/out/renderer/assets/{kanban-definition-UXKFOSKX-BJ_9aIhB.js → kanban-definition-UXKFOSKX-DU0d3NVH.js} +1 -1
  128. package/out/renderer/assets/{layout-3SRMHY7n.js → layout-C0hE7llw.js} +1 -1
  129. package/out/renderer/assets/{linear-CWpclK_R.js → linear-BXPh0BlC.js} +1 -1
  130. package/out/renderer/assets/{manifest-DOzTaB8J.js → manifest-DoBt8euy.js} +1 -1
  131. package/out/renderer/assets/{mermaid.core-DORpmVi3.js → mermaid.core-DlBAsGZ7.js} +5 -5
  132. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-CYBlCqIB.js → mindmap-definition-YA3MSWOX-DUIiyta9.js} +1 -1
  133. package/out/renderer/assets/{pegDiagram-XKGWAZYB-DhWwLs4v.js → pegDiagram-XKGWAZYB-yP15oXPx.js} +1 -1
  134. package/out/renderer/assets/{pieDiagram-E7YTZNPT-Bzpc57-A.js → pieDiagram-E7YTZNPT-DsaSjWfA.js} +1 -1
  135. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-spKXEbds.js → quadrantDiagram-AXDQQJYC-BpWn5xT_.js} +1 -1
  136. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-Br553px3.js → railroadDiagram-O6MQD6OU-BnXhwCom.js} +1 -1
  137. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-CX-Dqij_.js → requirementDiagram-BXWQKSXE-CMIMPMzx.js} +1 -1
  138. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-Bgx1W6B9.js → sankeyDiagram-P5KCCOFB-CKqneOc7.js} +1 -1
  139. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-CKQv6pcU.js → sequenceDiagram-WJ2MYXX4-azbHkcGk.js} +1 -1
  140. package/out/renderer/assets/{sessionChanges-BLzNhRuv.js → sessionChanges--o0RBCJW.js} +1 -1
  141. package/out/renderer/assets/settings-D5R80op8.js +28 -0
  142. package/out/renderer/assets/{sizeCapture-INFHLROL-DtRedfRe.js → sizeCapture-INFHLROL-C3uhIZ1e.js} +1 -1
  143. package/out/renderer/assets/{stateDiagram-D77RDMKH-CMP5owem.js → stateDiagram-D77RDMKH-CrGab2Ck.js} +1 -1
  144. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-k_H7O8MU.js +1 -0
  145. package/out/renderer/assets/{swimlanes-42K2YHIH-D30AvvmW.js → swimlanes-42K2YHIH-6aX1l7C2.js} +1 -1
  146. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-D2XerlPy.js +8 -0
  147. package/out/renderer/assets/{timeline-definition-24CTP7MA-CsZAMmMZ.js → timeline-definition-24CTP7MA-DdVDUmce.js} +1 -1
  148. package/out/renderer/assets/{vennDiagram-4TSXK5OY-COQ7L1f7.js → vennDiagram-4TSXK5OY-DP6DTjdX.js} +1 -1
  149. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-dqMWLTCs.js → wardleyDiagram-VM6X3IG4-DYJsuZCs.js} +1 -1
  150. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-DX4clIYP.js → xychartDiagram-S5SC5T6Z-CloAJCw-.js} +1 -1
  151. package/out/renderer/index.html +3 -3
  152. package/out/renderer/settings.html +7 -7
  153. package/out/renderer/web-preload.js +1 -51
  154. package/out/server/agent.js +1172 -242
  155. package/out/server/chunks/agentConstants-D4t7d6iS.js +9 -0
  156. package/out/server/chunks/builtinOccupancy-Ci-Szozb.js +93 -0
  157. package/out/server/chunks/dispatchModel-DJxnHup9.js +75 -0
  158. package/out/server/chunks/{gpuBackendInstall-jAzoFq7U.js → gpuBackendInstall-snisWLXN.js} +2 -2
  159. package/out/server/chunks/killTree-T-p6Lr3w.js +787 -0
  160. package/out/server/chunks/{loadProvider-NdOVbsHi.js → loadProvider-Uq3i7kKZ.js} +2 -2
  161. package/out/server/chunks/{manifest-BPXFscqI.js → manifest-CmnE8RBt.js} +4 -2
  162. package/out/server/chunks/menuSkills-BEtW-Is6.js +53 -0
  163. package/out/server/chunks/projectCode-D9lgShsp.js +112 -0
  164. package/out/server/chunks/{registry-BhoHPSKn.js → registry-R2KRdU8n.js} +97 -115
  165. package/out/server/chunks/sendImage-CCjNsa-D.js +499 -0
  166. package/out/server/chunks/{sendImage-BCNW9JRV.js → toolParams-DVs5d3F9.js} +25 -234
  167. package/out/server/chunks/web-BIJOMDlz.js +7773 -0
  168. package/out/server/chunks/{workflowPresets-C2T1BzA2.js → workflowPresets-DVbQh2el.js} +13603 -15626
  169. package/out/server/index.js +8778 -3210
  170. package/out/server/memory-service.js +197 -147
  171. package/out/server/plugin-host.js +44 -18
  172. package/package.json +1 -1
  173. package/out/phone/assets/architecture-7GRP2DOG-Duql1LsL.js +0 -1
  174. package/out/phone/assets/channel-BPoIHov1.js +0 -1
  175. package/out/phone/assets/classDiagram-ZZMXUADV-CIR76lHP.js +0 -1
  176. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CIR76lHP.js +0 -1
  177. package/out/phone/assets/desk-CixRGdTk.js +0 -52
  178. package/out/phone/assets/eventmodeling-NTZA5JFV-DYp-zWcL.js +0 -1
  179. package/out/phone/assets/flowDiagram-HODETNUW-CIU32By5.js +0 -1
  180. package/out/phone/assets/main-BCnf7dVM.js +0 -264
  181. package/out/phone/assets/main-nqB-uD3v.css +0 -2
  182. package/out/phone/assets/railroad-abnf-HS5TGJTU-BkSycwye.js +0 -1
  183. package/out/phone/assets/railroad-ebnf-LZEXJU2U-BsPIU3iV.js +0 -1
  184. package/out/phone/assets/railroad-peg-WCYAUIDC-Cy8G7u5C.js +0 -1
  185. package/out/phone/assets/shellUpdate-DPSfgHG3.js +0 -36
  186. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-B8IHc2bm.js +0 -1
  187. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-dmSDAN2F.js +0 -8
  188. package/out/renderer/assets/SidePanel-CL40W2RY.js +0 -47
  189. package/out/renderer/assets/channel-DjB0ww6b.js +0 -1
  190. package/out/renderer/assets/classDiagram-ZZMXUADV-6SiAw1np.js +0 -1
  191. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-6SiAw1np.js +0 -1
  192. package/out/renderer/assets/globals-BFf1P-Y5.js +0 -715
  193. package/out/renderer/assets/globals-DUBhAVpU.css +0 -1
  194. package/out/renderer/assets/index-L4TTIP10.js +0 -89
  195. package/out/renderer/assets/settings-Bsrw4ERp.js +0 -25
  196. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-6-731AqJ.js +0 -1
  197. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B8KijqIT.js +0 -8
  198. package/out/server/chunks/agent-BbNq8i9j.js +0 -4241
  199. package/out/server/chunks/dispatchModel-CsfmL396.js +0 -20
@@ -1,89 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./EditDiff-DxxLuCEI.js","./globals-BFf1P-Y5.js","./globals-DUBhAVpU.css","./sessionChanges-BLzNhRuv.js","./Virtualizer-B0uwx_XV.js","./ReadFileView-DFoLPU04.js","./File-Tz3MUtN6.js","./SidePanel-CL40W2RY.js","./manifest-DOzTaB8J.js","./SidePanel-D0m4IYxS.css"])))=>i.map(i=>d[i]);
2
- import{r as f,aY as Ue,aX as Xo,j as n,aj as Ke,ht as Gx,hu as Kx,hv as oI,hw as dw,hx as iI,cz as aI,br as xe,bW as os,hy as xu,hz as Cc,hA as lI,hB as cI,ax as _,u as z,fF as Dr,a_ as X,hC as uw,hD as fw,hE as qx,hF as mw,bD as Df,bE as Of,bz as Lo,cG as hw,bC as Lf,hG as rh,fA as Gs,bh as Xn,hH as jd,bt as kd,gL as Ka,b8 as Zt,hI as dI,hJ as Co,hK as ie,hL as uI,hM as oh,dl as Pn,ay as cn,az as dn,aA as un,aB as on,aC as ys,aM as ts,aN as fI,aO as he,bJ as Ie,fX as si,c0 as mI,dK as ih,dL as ah,dM as lh,dN as ch,dO as dh,dP as uh,f_ as pw,bO as Nd,dV as hI,dW as pI,dX as xI,e9 as fh,d2 as _o,dt as Bo,fJ as xw,bj as Ao,hN as gI,hO as Rr,hP as vI,hQ as mh,fe as Ic,bl as fn,aZ as bI,hR as yI,hS as wI,hT as jI,hU as kI,hj as Jr,ff as vi,eN as Eo,hV as Un,gH as NI,gP as gw,cm as Yr,cn as Xr,co as Qr,cp as Yt,em as SI,bs as Gn,hW as CI,dF as hh,t as II,ev as fi,hd as _s,hX as qa,hY as TI,hZ as AI,h_ as EI,h$ as RI,i0 as MI,i1 as PI,i2 as DI,i3 as OI,i4 as LI,i5 as _I,i6 as BI,i7 as FI,i8 as ph,i9 as zI,ia as $I,ib as VI,ic as HI,id as WI,ie as UI,ig as GI,ih as KI,ii as vw,ij as qI,ik as YI,il as XI,im as QI,df as Ya,io as JI,ip as ZI,iq as e5,ir as t5,is as n5,it as s5,dg as r5,iu as o5,iv as i5,iw as a5,ix as l5,g2 as c5,fi as bw,he as Sd,iy as d5,iz as $n,bb as Dn,bd as Xa,gU as Bs,iA as Hn,iB as u5,cA as yw,eh as f5,fg as ww,bm as Bn,iC as m5,iD as jw,iE as h5,iF as p5,iG as x5,fW as Cd,iH as g5,b$ as Zr,iI as v5,iJ as b5,iK as y5,iL as w5,bn as kw,fc as Nw,dD as Qa,ba as ro,iM as Yx,fd as j5,iN as k5,b9 as Bt,iO as Xx,iP as Sw,iQ as N5,iR as Cw,iS as S5,iT as C5,iU as I5,iV as T5,iW as A5,iX as Iw,iY as E5,iZ as R5,i_ as M5,i$ as P5,j0 as D5,j1 as O5,j2 as L5,j3 as _5,j4 as B5,j5 as F5,j6 as z5,j7 as $5,j8 as V5,j9 as Cl,bN as Or,ja as Rs,jb as Ms,jc as Ps,bV as hs,jd as Tw,je as H5,jf as W5,jg as Aw,jh as U5,ji as Qx,eM as G5,jj as K5,jk as Ew,jl as q5,d0 as Y5,jm as X5,jn as Q5,jo as Rw,jp as J5,bM as Fo,jq as Z5,aD as In,jr as Mw,js as Jx,jt as eT,ju as tT,hg as Pw,jv as nT,jw as sT,jx as rT,bv as xh,bP as gh,bw as Ds,eb as _f,h4 as Zx,eJ as vh,ej as _i,bL as Lr,bc as Dw,jy as oT,jz as Ow,jA as iT,jB as aT,jC as lT,jD as cT,jE as Bf,jF as Lw,jG as dT,jH as uT,aQ as vs,jI as fT,jJ as mT,jK as hT,jL as pT,jM as xT,jN as gT,jO as vT,jP as _w,jQ as eg,jR as tg,jS as bT,jT as ng,jU as Ff,jV as zf,jW as Qo,jX as yT,jY as wT,jZ as jT,j_ as sg,j$ as kT,k0 as NT,k1 as ST,k2 as rg,k3 as CT,k4 as gu,k5 as vu,k6 as IT,fY as bi,h3 as Bw,k7 as bh,bQ as Id,bu as Fw,aP as bs,k8 as TT,k9 as AT,ka as ET,kb as RT,kc as MT,kd as PT,ke as DT,cv as yh,d1 as Ro,kf as OT,kg as zw,kh as LT,ki as Tc,kj as $w,kk as Vw,kl as og,fv as Mr,km as _T,kn as BT,ko as FT,kp as Hw,eI as $t,kq as Ww,kr as zT,ks as $T,kt as Pr,ku as VT,kv as Uw,kw as Gw,kx as Kw,ky as Na,kz as HT,kA as WT,kB as UT,kC as $f,kD as GT,kE as KT,kF as qT,kG as YT,kH as XT,kI as QT,kJ as JT,kK as ZT,kL as eA,eU as Lt,ek as wh,e_ as qw,bi as sr,aE as Vt,gT as ig,kM as ag,kN as lg,kO as Sa,f8 as bu,gY as yu,aF as Ks,kP as jh,kQ as tA,kR as Yw,kS as nA,kT as sA,kU as kh,kV as is,kW as rA,cF as Xw,aG as Sr,aH as Cr,aI as Ir,aJ as Tr,aL as or,eT as Nh,kX as Ac,kY as Ec,kZ as Rc,k_ as Qw,eE as Td,eF as Ad,eG as fs,eH as yr,eZ as Jw,k$ as Zw,l0 as ej,l1 as ea,l2 as Mc,l3 as tj,l4 as oA,l5 as iA,gN as aA,l6 as lA,l7 as cA,l8 as Sh,l9 as dA,la as uA,lb as nj,d5 as ur,d6 as fr,d7 as mr,d8 as Cn,lc as sj,ld as rj,le as oj,gB as yi,fh as Ch,lf as ij,lg as Ed,lh as cs,eW as aj,eQ as fA,eR as mA,e$ as hA,li as pA,f1 as xA,lj,lk as gA,ll as vA,lm as bA,ln as yA,lo as cj,lp as wA,lq as jA,lr as kA,bZ as Ih,ls as Th,lt as Qi,lu as Ah,lv as Eh,bq as Mo,bR as Rh,bT as Mh,bk as lr,bS as Ph,cg as wi,lw as NA,lx as dj,ly as uj,lz as SA,lA as ta,cN as CA,cQ as fj,cO as IA,by as Rd,lB as mj,lC as TA,fP as AA,fO as EA,lD as RA,dc as MA,lE as PA,lF as DA,dr as OA,lG as LA,lH as _A,lI as BA,dq as FA,lJ as zA,lK as $A,di as VA,b_ as HA,dj as WA,dk as UA,dm as GA,dn as KA,dp as qA,ds as YA,lL as XA,lM as QA,lN as JA,lO as ZA,lP as eE,lQ as tE,lR as hj,fz as Vs,lS as nE,bg as mi,hi as Vf,lT as sE,lU as rE,lV as Dh,lW as Oh,lX as Lh,lY as _h,cr as Bh,lZ as oE,l_ as iE,l$ as aE,eD as pj,eL as bo,eC as lE,m0 as cE,m1 as dE,m2 as uE,m3 as cg,m4 as xj,m5 as Wo,eK as dg,eP as fE,m6 as mE,eX as ug,d3 as Fh,m7 as fg,hh as hE,cy as pE,bG as xE,be as gE,cj as vE,m8 as bE,m9 as yE,ma as wE,M as gj,mb as jE,fC as Pc,mc as vj,md as bj,me as zh,bo as kE,mf as NE,mg as SE,mh as CE,mi as IE,mj as wu,mk as mg,ml as TE,h9 as yj,mm as AE,mn as $h,h5 as EE,fr as Ss,fs as Cs,mo as wj,mp as RE,mq as ME,mr as PE,ms as DE,mt as OE,hc as Dc,mu as LE,mv as _E,mw as BE,mx as FE,my as jj,mz as kj,mA as zE,mB as $E,fk as VE,mC as HE,mD as WE,gj as Nj,bI as Sj,cE as UE,mE as GE,mF as hg,mG as KE,mH as qE,fM as YE,fL as XE,fZ as QE,hf as Cj,mI as Ij,mJ as Hf,mK as sc,mL as Tj,h8 as JE,bB as pg,mM as ZE,bA as Aj,bF as xg,mN as e3,mO as t3,mP as n3,bH as Ej,mQ as jr,mR as Is,mS as qn,gW as gg,gV as s3,mT as Rj,dT as r3,mU as Oc,dI as o3,dJ as i3,f9 as a3,fq as l3,mV as Mj,mW as Pj,mX as Bi,mY as c3,mZ as d3,m_ as u3,m$ as f3,n0 as m3,n1 as h3,fm as vg,bx as p3,n2 as x3,n3 as g3,n4 as bg,gR as v3,cu as yg,cD as Dj,n5 as b3,ft as y3,h6 as w3,g7 as j3,n6 as k3,gr as N3,gs as S3,fu as C3,n7 as I3,h7 as T3,gX as A3,n8 as E3,n9 as R3,cJ as M3,cl as P3,gQ as D3,na as O3,nb as L3,nc as _3,nd as kr,ne as B3,nf as F3,ng as z3,nh as $3,ni as V3,nj as H3,nk as W3,nl as wg,nm as jg,nn as U3,fE as G3,no as K3,np as q3,nq as Y3,nr as X3,ns as Q3,nt as J3,nu as Z3,g8 as eR,nv as tR,nw as kg,nx as Oj,bY as nR,gD as sR,ny as rR,nz as oR,nA as iR,nB as aR,nC as lR,fn as ju,cP as cR,hq as dR,hr as uR,hn as fR,hs as Ng,ho as mR,fo as hR,dQ as pR,nD as xR,nE as gR,nF as vR,nG as bR,nH as yR,fB as wR,nI as jR,nJ as kR,C as NR,hk as SR,hl as CR,hm as IR}from"./globals-BFf1P-Y5.js";function TR(){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 Md=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ji(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Vh(e){return"nodeType"in e}function ds(e){var t,s;return e?ji(e)?e:Vh(e)&&(t=(s=e.ownerDocument)==null?void 0:s.defaultView)!=null?t:window:window}function Hh(e){const{Document:t}=ds(e);return e instanceof t}function Ja(e){return ji(e)?!1:e instanceof ds(e).HTMLElement}function Lj(e){return e instanceof ds(e).SVGElement}function ki(e){return e?ji(e)?e.document:Vh(e)?Hh(e)?e:Ja(e)||Lj(e)?e.ownerDocument:document:document:document}const qs=Md?f.useLayoutEffect:f.useEffect;function Pd(e){const t=f.useRef(e);return qs(()=>{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 AR(){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 Ca(e,t){t===void 0&&(t=[e]);const s=f.useRef(e);return qs(()=>{s.current!==e&&(s.current=e)},t),s}function Za(e,t){const s=f.useRef();return f.useMemo(()=>{const r=e(s.current);return s.current=r,r},[...t])}function Lc(e){const t=Pd(e),s=f.useRef(null),r=f.useCallback(o=>{o!==s.current&&t?.(o,s.current),s.current=o},[]);return[s,r]}function _c(e){const t=f.useRef();return f.useEffect(()=>{t.current=e},[e]),t.current}let ku={};function el(e,t){return f.useMemo(()=>{if(t)return t;const s=ku[e]==null?0:ku[e]+1;return ku[e]=s,e+"-"+s},[e,t])}function _j(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 ri=_j(1),Bc=_j(-1);function ER(e){return"clientX"in e&&"clientY"in e}function Dd(e){if(!e)return!1;const{KeyboardEvent:t}=ds(e.target);return t&&e instanceof t}function RR(e){if(!e)return!1;const{TouchEvent:t}=ds(e.target);return t&&e instanceof t}function Fc(e){if(RR(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 ER(e)?{x:e.clientX,y:e.clientY}:null}const cr=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[cr.Translate.toString(e),cr.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:s,easing:r}=e;return t+" "+s+"ms "+r}}}),Sg="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function MR(e){return e.matches(Sg)?e:e.querySelector(Sg)}const PR={display:"none"};function DR(e){let{id:t,value:s}=e;return Ue.createElement("div",{id:t,style:PR},s)}function OR(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 Ue.createElement("div",{id:t,style:o,role:"status","aria-live":r,"aria-atomic":!0},s)}function LR(){const[e,t]=f.useState("");return{announce:f.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const Bj=f.createContext(null);function Fj(e){const t=f.useContext(Bj);f.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function _R(){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 BR={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
- `},FR={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 zR(e){let{announcements:t=FR,container:s,hiddenTextDescribedById:r,screenReaderInstructions:o=BR}=e;const{announce:i,announcement:a}=LR(),l=el("DndLiveRegion"),[c,u]=f.useState(!1);if(f.useEffect(()=>{u(!0)},[]),Fj(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=Ue.createElement(Ue.Fragment,null,Ue.createElement(DR,{id:r,value:o.draggable}),Ue.createElement(OR,{id:l,announcement:a}));return s?Xo.createPortal(d,s):d}var Vn;(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"})(Vn||(Vn={}));function zc(){}function $R(e,t){return f.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function VR(){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 HR(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function WR(e,t){const s=Fc(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 UR(e,t){let{data:{value:s}}=e,{data:{value:r}}=t;return s-r}function GR(e,t){let{data:{value:s}}=e,{data:{value:r}}=t;return r-s}function KR(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 qR(e,t){if(!e||e.length===0)return null;const[s]=e;return s[t]}function YR(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 zj=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=YR(l,t);c>0&&o.push({id:a,data:{droppableContainer:i,value:c}})}}return o.sort(GR)};function XR(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 QR=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&&XR(r,l)){const u=KR(l).reduce((m,h)=>m+HR(r,h),0),d=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:i,value:d}})}}return o.sort(UR)};function JR(e,t,s){return{...e,scaleX:t&&s?t.width/s.width:1,scaleY:t&&s?t.height/s.height:1}}function $j(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Ys}function ZR(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 eM=ZR(1);function Vj(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 tM(e,t,s){const r=Vj(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 nM={ignoreTransform:!1};function Ni(e,t){t===void 0&&(t=nM);let s=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=ds(e).getComputedStyle(e);u&&(s=tM(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 Cg(e){return Ni(e,{ignoreTransform:!0})}function sM(e){const t=e.innerWidth,s=e.innerHeight;return{top:0,left:0,right:t,bottom:s,width:t,height:s}}function rM(e,t){return t===void 0&&(t=ds(e).getComputedStyle(e)),t.position==="fixed"}function oM(e,t){t===void 0&&(t=ds(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 Wh(e,t){const s=[];function r(o){if(t!=null&&s.length>=t||!o)return s;if(Hh(o)&&o.scrollingElement!=null&&!s.includes(o.scrollingElement))return s.push(o.scrollingElement),s;if(!Ja(o)||Lj(o)||s.includes(o))return s;const i=ds(e).getComputedStyle(o);return o!==e&&oM(o,i)&&s.push(o),rM(o,i)?s:r(o.parentNode)}return e?r(e):s}function Hj(e){const[t]=Wh(e,1);return t??null}function Nu(e){return!Md||!e?null:ji(e)?e:Vh(e)?Hh(e)||e===ki(e).scrollingElement?window:Ja(e)?e:null:null}function Wj(e){return ji(e)?e.scrollX:e.scrollLeft}function Uj(e){return ji(e)?e.scrollY:e.scrollTop}function Wf(e){return{x:Wj(e),y:Uj(e)}}var Yn;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Yn||(Yn={}));function Gj(e){return!Md||!e?!1:e===document.scrollingElement}function Kj(e){const t={x:0,y:0},s=Gj(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 iM={x:.2,y:.2};function aM(e,t,s,r,o){let{top:i,left:a,right:l,bottom:c}=s;r===void 0&&(r=10),o===void 0&&(o=iM);const{isTop:u,isBottom:d,isLeft:m,isRight:h}=Kj(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=Yn.Backward,g.y=r*Math.abs((t.top+x.height-i)/x.height)):!d&&c>=t.bottom-x.height&&(p.y=Yn.Forward,g.y=r*Math.abs((t.bottom-x.height-c)/x.height)),!h&&l>=t.right-x.width?(p.x=Yn.Forward,g.x=r*Math.abs((t.right-x.width-l)/x.width)):!m&&a<=t.left+x.width&&(p.x=Yn.Backward,g.x=r*Math.abs((t.left+x.width-a)/x.width)),{direction:p,speed:g}}function lM(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 qj(e){return e.reduce((t,s)=>ri(t,Wf(s)),Ys)}function cM(e){return e.reduce((t,s)=>t+Wj(s),0)}function dM(e){return e.reduce((t,s)=>t+Uj(s),0)}function Yj(e,t){if(t===void 0&&(t=Ni),!e)return;const{top:s,left:r,bottom:o,right:i}=t(e);Hj(e)&&(o<=0||i<=0||s>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const uM=[["x",["left","right"],cM],["y",["top","bottom"],dM]];class Uh{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=Wh(s),o=qj(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[i,a,l]of uM)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 na{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 fM(e){const{EventTarget:t}=ds(e);return e instanceof t?e:ki(e)}function Su(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 js;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(js||(js={}));function Ig(e){e.preventDefault()}function mM(e){e.stopPropagation()}var nn;(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"})(nn||(nn={}));const Xj={start:[nn.Space,nn.Enter],cancel:[nn.Esc],end:[nn.Space,nn.Enter,nn.Tab]},hM=(e,t)=>{let{currentCoordinates:s}=t;switch(e.code){case nn.Right:return{...s,x:s.x+25};case nn.Left:return{...s,x:s.x-25};case nn.Down:return{...s,y:s.y+25};case nn.Up:return{...s,y:s.y-25}}};class Qj{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 na(ki(s)),this.windowListeners=new na(ds(s)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(js.Resize,this.handleCancel),this.windowListeners.add(js.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(js.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:s}=this.props,r=t.node.current;r&&Yj(r),s(Ys)}handleKeyDown(t){if(Dd(t)){const{active:s,context:r,options:o}=this.props,{keyboardCodes:i=Xj,coordinateGetter:a=hM,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=Bc(m,d),p={x:0,y:0},{scrollableAncestors:g}=r.current;for(const x of g){const y=t.code,{isTop:j,isRight:w,isLeft:b,isBottom:N,maxScroll:C,minScroll:E}=Kj(x),T=lM(x),k={x:Math.min(y===nn.Right?T.right-T.width/2:T.right,Math.max(y===nn.Right?T.left:T.left+T.width/2,m.x)),y:Math.min(y===nn.Down?T.bottom-T.height/2:T.bottom,Math.max(y===nn.Down?T.top:T.top+T.height/2,m.y))},L=y===nn.Right&&!w||y===nn.Left&&!b,F=y===nn.Down&&!N||y===nn.Up&&!j;if(L&&k.x!==m.x){const A=x.scrollLeft+h.x,D=y===nn.Right&&A<=C.x||y===nn.Left&&A>=E.x;if(D&&!h.y){x.scrollTo({left:A,behavior:l});return}D?p.x=x.scrollLeft-A:p.x=y===nn.Right?x.scrollLeft-C.x:x.scrollLeft-E.x,p.x&&x.scrollBy({left:-p.x,behavior:l});break}else if(F&&k.y!==m.y){const A=x.scrollTop+h.y,D=y===nn.Down&&A<=C.y||y===nn.Up&&A>=E.y;if(D&&!h.x){x.scrollTo({top:A,behavior:l});return}D?p.y=x.scrollTop-A:p.y=y===nn.Down?x.scrollTop-C.y:x.scrollTop-E.y,p.y&&x.scrollBy({top:-p.y,behavior:l});break}}this.handleMove(t,ri(Bc(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()}}Qj.activators=[{eventName:"onKeyDown",handler:(e,t,s)=>{let{keyboardCodes:r=Xj,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 Tg(e){return!!(e&&"distance"in e)}function Ag(e){return!!(e&&"delay"in e)}class Gh{constructor(t,s,r){var o;r===void 0&&(r=fM(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=ki(a),this.documentListeners=new na(this.document),this.listeners=new na(r),this.windowListeners=new na(ds(a)),this.initialCoordinates=(o=Fc(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(js.Resize,this.handleCancel),this.windowListeners.add(js.DragStart,Ig),this.windowListeners.add(js.VisibilityChange,this.handleCancel),this.windowListeners.add(js.ContextMenu,Ig),this.documentListeners.add(js.Keydown,this.handleKeydown),s){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Ag(s)){this.timeoutId=setTimeout(this.handleStart,s.delay),this.handlePending(s);return}if(Tg(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(js.Click,mM,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(js.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=Fc(t))!=null?s:Ys,u=Bc(o,c);if(!r&&l){if(Tg(l)){if(l.tolerance!=null&&Su(u,l.tolerance))return this.handleCancel();if(Su(u,l.distance))return this.handleStart()}if(Ag(l)&&Su(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===nn.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const pM={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Kh extends Gh{constructor(t){const{event:s}=t,r=ki(s.target);super(t,pM,r)}}Kh.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 xM={move:{name:"mousemove"},end:{name:"mouseup"}};var Uf;(function(e){e[e.RightClick=2]="RightClick"})(Uf||(Uf={}));class gM extends Gh{constructor(t){super(t,xM,ki(t.event.target))}}gM.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:s}=e,{onActivation:r}=t;return s.button===Uf.RightClick?!1:(r?.({event:s}),!0)}}];const Cu={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class vM extends Gh{constructor(t){super(t,Cu)}static setup(){return window.addEventListener(Cu.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Cu.move.name,t)};function t(){}}}vM.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 sa;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(sa||(sa={}));var $c;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})($c||($c={}));function bM(e){let{acceleration:t,activator:s=sa.Pointer,canScroll:r,draggingRect:o,enabled:i,interval:a=5,order:l=$c.TreeOrder,pointerCoordinates:c,scrollableAncestors:u,scrollableAncestorRects:d,delta:m,threshold:h}=e;const p=wM({delta:m,disabled:!i}),[g,x]=AR(),y=f.useRef({x:0,y:0}),j=f.useRef({x:0,y:0}),w=f.useMemo(()=>{switch(s){case sa.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case sa.DraggableRect:return o}},[s,o,c]),b=f.useRef(null),N=f.useCallback(()=>{const E=b.current;if(!E)return;const T=y.current.x*j.current.x,k=y.current.y*j.current.y;E.scrollBy(T,k)},[]),C=f.useMemo(()=>l===$c.TreeOrder?[...u].reverse():u,[l,u]);f.useEffect(()=>{if(!i||!u.length||!w){x();return}for(const E of C){if(r?.(E)===!1)continue;const T=u.indexOf(E),k=d[T];if(!k)continue;const{direction:L,speed:F}=aM(E,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(),b.current=E,g(N,a),y.current=F,j.current=L;return}}y.current={x:0,y:0},j.current={x:0,y:0},x()},[t,N,r,x,i,a,JSON.stringify(w),JSON.stringify(p),g,u,C,d,JSON.stringify(h)])}const yM={x:{[Yn.Backward]:!1,[Yn.Forward]:!1},y:{[Yn.Backward]:!1,[Yn.Forward]:!1}};function wM(e){let{delta:t,disabled:s}=e;const r=_c(t);return Za(o=>{if(s||!r||!o)return yM;const i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Yn.Backward]:o.x[Yn.Backward]||i.x===-1,[Yn.Forward]:o.x[Yn.Forward]||i.x===1},y:{[Yn.Backward]:o.y[Yn.Backward]||i.y===-1,[Yn.Forward]:o.y[Yn.Forward]||i.y===1}}},[s,t,r])}function jM(e,t){const s=t!=null?e.get(t):void 0,r=s?s.node.current:null;return Za(o=>{var i;return t==null?null:(i=r??o)!=null?i:null},[r,t])}function kM(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 Ia;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Ia||(Ia={}));var Gf;(function(e){e.Optimized="optimized"})(Gf||(Gf={}));const Eg=new Map;function NM(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=y(),h=Ca(m),p=f.useCallback(function(j){j===void 0&&(j=[]),!h.current&&a(w=>w===null?j:w.concat(j.filter(b=>!w.includes(b))))},[h]),g=f.useRef(null),x=Za(j=>{if(m&&!s)return Eg;if(!j||j===Eg||d.current!==e||i!=null){const w=new Map;for(let b of e){if(!b)continue;if(i&&i.length>0&&!i.includes(b.id)&&b.rect.current){w.set(b.id,b.rect.current);continue}const N=b.node.current,C=N?new Uh(c(N),N):null;b.rect.current=C,C&&w.set(b.id,C)}return w}return j},[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 y(){switch(u){case Ia.Always:return!1;case Ia.BeforeDragging:return s;default:return!s}}}function qh(e,t){return Za(s=>e?s||(typeof t=="function"?t(e):e):null,[t,e])}function SM(e,t){return qh(e,t)}function CM(e){let{callback:t,disabled:s}=e;const r=Pd(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 Od(e){let{callback:t,disabled:s}=e;const r=Pd(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 IM(e){return new Uh(Ni(e),e)}function Rg(e,t,s){t===void 0&&(t=IM);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=CM({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=Od({callback:i});return qs(()=>{i(),e?(l?.observe(e),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[e]),r}function TM(e){const t=qh(e);return $j(e,t)}const Mg=[];function AM(e){const t=f.useRef(e),s=Za(r=>e?r&&r!==Mg&&e&&t.current&&e.parentNode===t.current.parentNode?r:Wh(e):Mg,[e]);return f.useEffect(()=>{t.current=e},[e]),s}function EM(e){const[t,s]=f.useState(null),r=f.useRef(e),o=f.useCallback(i=>{const a=Nu(i.target);a&&s(l=>l?(l.set(a,Wf(a)),new Map(l)):null)},[]);return f.useEffect(()=>{const i=r.current;if(e!==i){a(i);const l=e.map(c=>{const u=Nu(c);return u?(u.addEventListener("scroll",o,{passive:!0}),[u,Wf(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=Nu(c);u?.removeEventListener("scroll",o)})}},[o,e]),f.useMemo(()=>e.length?t?Array.from(t.values()).reduce((i,a)=>ri(i,a),Ys):qj(e):Ys,[e,t])}function Pg(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?Bc(e,s.current):Ys}function RM(e){f.useEffect(()=>{if(!Md)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 MM(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 Jj(e){return f.useMemo(()=>e?sM(e):null,[e])}const Dg=[];function PM(e,t){t===void 0&&(t=Ni);const[s]=e,r=Jj(s?ds(s):null),[o,i]=f.useState(Dg);function a(){i(()=>e.length?e.map(c=>Gj(c)?r:new Uh(t(c),c)):Dg)}const l=Od({callback:a});return qs(()=>{l?.disconnect(),a(),e.forEach(c=>l?.observe(c))},[e]),o}function Zj(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Ja(t)?t:e}function DM(e){let{measure:t}=e;const[s,r]=f.useState(null),o=f.useCallback(u=>{for(const{target:d}of u)if(Ja(d)){r(m=>{const h=t(d);return m?{...m,width:h.width,height:h.height}:h});break}},[t]),i=Od({callback:o}),a=f.useCallback(u=>{const d=Zj(u);i?.disconnect(),d&&i?.observe(d),r(d?t(d):null)},[t,i]),[l,c]=Lc(a);return f.useMemo(()=>({nodeRef:l,rect:s,setRef:c}),[s,l,c])}const OM=[{sensor:Kh,options:{}},{sensor:Qj,options:{}}],LM={current:{}},rc={draggable:{measure:Cg},droppable:{measure:Cg,strategy:Ia.WhileDragging,frequency:Gf.Optimized},dragOverlay:{measure:Ni}};class ra 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 _M={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new ra,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:zc},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:rc,measureDroppableContainers:zc,windowRect:null,measuringScheduled:!1},e1={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:zc,draggableNodes:new Map,over:null,measureDroppableContainers:zc},tl=f.createContext(e1),t1=f.createContext(_M);function BM(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new ra}}}function FM(e,t){switch(t.type){case Vn.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Vn.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 Vn.DragEnd:case Vn.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Vn.RegisterDroppable:{const{element:s}=t,{id:r}=s,o=new ra(e.droppable.containers);return o.set(r,s),{...e,droppable:{...e.droppable,containers:o}}}case Vn.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 ra(e.droppable.containers);return a.set(s,{...i,disabled:o}),{...e,droppable:{...e.droppable,containers:a}}}case Vn.UnregisterDroppable:{const{id:s,key:r}=t,o=e.droppable.containers.get(s);if(!o||r!==o.key)return e;const i=new ra(e.droppable.containers);return i.delete(s),{...e,droppable:{...e.droppable,containers:i}}}default:return e}}function zM(e){let{disabled:t}=e;const{active:s,activatorEvent:r,draggableNodes:o}=f.useContext(tl),i=_c(r),a=_c(s?.id);return f.useEffect(()=>{if(!t&&!r&&i&&a!=null){if(!Dd(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=MR(d);if(m){m.focus();break}}})}},[r,t,o,a,i]),null}function n1(e,t){let{transform:s,...r}=t;return e!=null&&e.length?e.reduce((o,i)=>i({transform:o,...r}),s):s}function $M(e){return f.useMemo(()=>({draggable:{...rc.draggable,...e?.draggable},droppable:{...rc.droppable,...e?.droppable},dragOverlay:{...rc.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function VM(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;qs(()=>{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=$j(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=Hj(u);h&&h.scrollBy({top:m.y,left:m.x})}},[t,a,l,r,s])}const Ld=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 HM=f.memo(function(t){var s,r,o,i;let{id:a,accessibility:l,autoScroll:c=!0,children:u,sensors:d=OM,collisionDetection:m=zj,measuring:h,modifiers:p,...g}=t;const x=f.useReducer(FM,void 0,BM),[y,j]=x,[w,b]=_R(),[N,C]=f.useState(Wr.Uninitialized),E=N===Wr.Initialized,{draggable:{active:T,nodes:k,translate:L},droppable:{containers:F}}=y,A=T!=null?k.get(T):null,D=f.useRef({initial:null,translated:null}),M=f.useMemo(()=>{var gt;return T!=null?{id:T,data:(gt=A?.data)!=null?gt:LM,rect:D}:null},[T,A]),H=f.useRef(null),[G,U]=f.useState(null),[J,$]=f.useState(null),oe=Ca(g,Object.values(g)),Ne=el("DndDescribedBy",a),ce=f.useMemo(()=>F.getEnabled(),[F]),ne=$M(h),{droppableRects:Y,measureDroppableContainers:pe,measuringScheduled:ge}=NM(ce,{dragging:E,dependencies:[L.x,L.y],config:ne.droppable}),we=jM(k,T),V=f.useMemo(()=>J?Fc(J):null,[J]),W=xt(),B=SM(we,ne.draggable.measure);VM({activeNode:T!=null?k.get(T):null,config:W.layoutShiftCompensation,initialRect:B,measure:ne.draggable.measure});const te=Rg(we,ne.draggable.measure,B),Z=Rg(we?we.parentElement:null),ue=f.useRef({activatorEvent:null,active:null,activeNode:we,collisionRect:null,collisions:null,droppableRects:Y,draggableNodes:k,draggingNode:null,draggingNodeRect:null,droppableContainers:F,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),fe=F.getNodeFor((s=ue.current.over)==null?void 0:s.id),Ce=DM({measure:ne.dragOverlay.measure}),de=(r=Ce.nodeRef.current)!=null?r:we,Ee=E?(o=Ce.rect)!=null?o:te:null,me=!!(Ce.nodeRef.current&&Ce.rect),Ve=TM(me?null:te),at=Jj(de?ds(de):null),Fe=AM(E?fe??we:null),tt=PM(Fe),je=n1(p,{transform:{x:L.x-Ve.x,y:L.y-Ve.y,scaleX:1,scaleY:1},activatorEvent:J,active:M,activeNodeRect:te,containerNodeRect:Z,draggingNodeRect:Ee,over:ue.current.over,overlayNodeRect:Ce.rect,scrollableAncestors:Fe,scrollableAncestorRects:tt,windowRect:at}),Je=V?ri(V,L):null,rt=EM(Fe),K=Pg(rt),Q=Pg(rt,[te]),Ae=ri(je,K),pt=Ee?eM(Ee,je):null,Dt=M&&pt?m({active:M,collisionRect:pt,droppableRects:Y,droppableContainers:ce,pointerCoordinates:Je}):null,Xe=qR(Dt,"id"),[kt,mn]=f.useState(null),_e=me?je:ri(je,Q),Nt=JR(_e,(i=kt?.rect)!=null?i:null,te),Ot=f.useRef(null),_t=f.useCallback((gt,Ft)=>{let{sensor:Ht,options:tn}=Ft;if(H.current==null)return;const Jt=k.get(H.current);if(!Jt)return;const Gt=gt.nativeEvent,gn=new Ht({active:H.current,activeNode:Jt,event:Gt,options:tn,context:ue,onAbort(bt){if(!k.get(bt))return;const{onDragAbort:Tn}=oe.current,S={id:bt};Tn?.(S),w({type:"onDragAbort",event:S})},onPending(bt,sn,Tn,S){if(!k.get(bt))return;const{onDragPending:I}=oe.current,v={id:bt,constraint:sn,initialCoordinates:Tn,offset:S};I?.(v),w({type:"onDragPending",event:v})},onStart(bt){const sn=H.current;if(sn==null)return;const Tn=k.get(sn);if(!Tn)return;const{onDragStart:S}=oe.current,P={activatorEvent:Gt,active:{id:sn,data:Tn.data,rect:D}};Xo.unstable_batchedUpdates(()=>{S?.(P),C(Wr.Initializing),j({type:Vn.DragStart,initialCoordinates:bt,active:sn}),w({type:"onDragStart",event:P}),U(Ot.current),$(Gt)})},onMove(bt){j({type:Vn.DragMove,coordinates:bt})},onEnd:Qn(Vn.DragEnd),onCancel:Qn(Vn.DragCancel)});Ot.current=gn;function Qn(bt){return async function(){const{active:Tn,collisions:S,over:P,scrollAdjustedTranslate:I}=ue.current;let v=null;if(Tn&&I){const{cancelDrop:R}=oe.current;v={activatorEvent:Gt,active:Tn,collisions:S,delta:I,over:P},bt===Vn.DragEnd&&typeof R=="function"&&await Promise.resolve(R(v))&&(bt=Vn.DragCancel)}H.current=null,Xo.unstable_batchedUpdates(()=>{j({type:bt}),C(Wr.Uninitialized),mn(null),U(null),$(null),Ot.current=null;const R=bt===Vn.DragEnd?"onDragEnd":"onDragCancel";if(v){const ee=oe.current[R];ee?.(v),w({type:R,event:v})}})}}},[k]),se=f.useCallback((gt,Ft)=>(Ht,tn)=>{const Jt=Ht.nativeEvent,Gt=k.get(tn);if(H.current!==null||!Gt||Jt.dndKit||Jt.defaultPrevented)return;const gn={active:Gt};gt(Ht,Ft.options,gn)===!0&&(Jt.dndKit={capturedBy:Ft.sensor},H.current=tn,_t(Ht,Ft))},[k,_t]),Oe=kM(d,se);RM(d),qs(()=>{te&&N===Wr.Initializing&&C(Wr.Initialized)},[te,N]),f.useEffect(()=>{const{onDragMove:gt}=oe.current,{active:Ft,activatorEvent:Ht,collisions:tn,over:Jt}=ue.current;if(!Ft||!Ht)return;const Gt={active:Ft,activatorEvent:Ht,collisions:tn,delta:{x:Ae.x,y:Ae.y},over:Jt};Xo.unstable_batchedUpdates(()=>{gt?.(Gt),w({type:"onDragMove",event:Gt})})},[Ae.x,Ae.y]),f.useEffect(()=>{const{active:gt,activatorEvent:Ft,collisions:Ht,droppableContainers:tn,scrollAdjustedTranslate:Jt}=ue.current;if(!gt||H.current==null||!Ft||!Jt)return;const{onDragOver:Gt}=oe.current,gn=tn.get(Xe),Qn=gn&&gn.rect.current?{id:gn.id,rect:gn.rect.current,data:gn.data,disabled:gn.disabled}:null,bt={active:gt,activatorEvent:Ft,collisions:Ht,delta:{x:Jt.x,y:Jt.y},over:Qn};Xo.unstable_batchedUpdates(()=>{mn(Qn),Gt?.(bt),w({type:"onDragOver",event:bt})})},[Xe]),qs(()=>{ue.current={activatorEvent:J,active:M,activeNode:we,collisionRect:pt,collisions:Dt,droppableRects:Y,draggableNodes:k,draggingNode:de,draggingNodeRect:Ee,droppableContainers:F,over:kt,scrollableAncestors:Fe,scrollAdjustedTranslate:Ae},D.current={initial:Ee,translated:pt}},[M,we,Dt,pt,k,de,Ee,Y,F,kt,Fe,Ae]),bM({...W,delta:L,draggingRect:pt,pointerCoordinates:Je,scrollableAncestors:Fe,scrollableAncestorRects:tt});const ot=f.useMemo(()=>({active:M,activeNode:we,activeNodeRect:te,activatorEvent:J,collisions:Dt,containerNodeRect:Z,dragOverlay:Ce,draggableNodes:k,droppableContainers:F,droppableRects:Y,over:kt,measureDroppableContainers:pe,scrollableAncestors:Fe,scrollableAncestorRects:tt,measuringConfiguration:ne,measuringScheduled:ge,windowRect:at}),[M,we,te,J,Dt,Z,Ce,k,F,Y,kt,pe,Fe,tt,ne,ge,at]),ct=f.useMemo(()=>({activatorEvent:J,activators:Oe,active:M,activeNodeRect:te,ariaDescribedById:{draggable:Ne},dispatch:j,draggableNodes:k,over:kt,measureDroppableContainers:pe}),[J,Oe,M,te,j,Ne,k,kt,pe]);return Ue.createElement(Bj.Provider,{value:b},Ue.createElement(tl.Provider,{value:ct},Ue.createElement(t1.Provider,{value:ot},Ue.createElement(Ld.Provider,{value:Nt},u)),Ue.createElement(zM,{disabled:l?.restoreFocus===!1})),Ue.createElement(zR,{...l,hiddenTextDescribedById:Ne}));function xt(){const gt=G?.autoScrollEnabled===!1,Ft=typeof c=="object"?c.enabled===!1:c===!1,Ht=E&&!gt&&!Ft;return typeof c=="object"?{...c,enabled:Ht}:{enabled:Ht}}}),WM=f.createContext(null),Og="button",UM="Draggable";function s1(e){let{id:t,data:s,disabled:r=!1,attributes:o}=e;const i=el(UM),{activators:a,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:m,over:h}=f.useContext(tl),{role:p=Og,roleDescription:g="draggable",tabIndex:x=0}=o??{},y=c?.id===t,j=f.useContext(y?Ld:WM),[w,b]=Lc(),[N,C]=Lc(),E=MM(a,t),T=Ca(s);qs(()=>(m.set(t,{id:t,key:i,node:w,activatorNode:N,data:T}),()=>{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":y&&p===Og?!0:void 0,"aria-roledescription":g,"aria-describedby":d.draggable}),[r,p,x,y,g,d.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:k,isDragging:y,listeners:r?void 0:E,node:w,over:h,setNodeRef:b,setActivatorNodeRef:C,transform:j}}function nl(){return f.useContext(t1)}const GM="Droppable",KM={timeout:25};function sl(e){let{data:t,disabled:s=!1,id:r,resizeObserverConfig:o}=e;const i=el(GM),{active:a,dispatch:l,over:c,measureDroppableContainers:u}=f.useContext(tl),d=f.useRef({disabled:s}),m=f.useRef(!1),h=f.useRef(null),p=f.useRef(null),{disabled:g,updateMeasurementsFor:x,timeout:y}={...KM,...o},j=Ca(x??r),w=f.useCallback(()=>{if(!m.current){m.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{u(Array.isArray(j.current)?j.current:[j.current]),p.current=null},y)},[y]),b=Od({callback:w,disabled:g||!a}),N=f.useCallback((k,L)=>{b&&(L&&(b.unobserve(L),m.current=!1),k&&b.observe(k))},[b]),[C,E]=Lc(N),T=Ca(t);return f.useEffect(()=>{!b||!C.current||(b.disconnect(),m.current=!1,b.observe(C.current))},[C,b]),f.useEffect(()=>(l({type:Vn.RegisterDroppable,element:{id:r,key:i,disabled:s,node:C,rect:h,data:T}}),()=>l({type:Vn.UnregisterDroppable,key:i,id:r})),[r]),f.useEffect(()=>{s!==d.current.disabled&&(l({type:Vn.SetDroppableDisabled,id:r,key:i,disabled:s}),d.current.disabled=s)},[r,i,s,l]),{active:a,rect:h,isOver:c?.id===r,node:C,over:c,setNodeRef:E}}function qM(e){let{animation:t,children:s}=e;const[r,o]=f.useState(null),[i,a]=f.useState(null),l=_c(s);return!s&&!r&&l&&o(l),qs(()=>{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]),Ue.createElement(Ue.Fragment,null,s,r?f.cloneElement(r,{ref:a}):null)}const YM={x:0,y:0,scaleX:1,scaleY:1};function XM(e){let{children:t}=e;return Ue.createElement(tl.Provider,{value:e1},Ue.createElement(Ld.Provider,{value:YM},t))}const QM={position:"fixed",touchAction:"none"},JM=e=>Dd(e)?"transform 250ms ease":void 0,ZM=f.forwardRef((e,t)=>{let{as:s,activatorEvent:r,adjustScale:o,children:i,className:a,rect:l,style:c,transform:u,transition:d=JM}=e;if(!l)return null;const m=o?u:{...u,scaleX:1,scaleY:1},h={...QM,width:l.width,height:l.height,top:l.top,left:l.left,transform:cr.Transform.toString(m),transformOrigin:o&&r?WR(r,l):void 0,transition:typeof d=="function"?d(r):d,...c};return Ue.createElement(s,{className:a,style:h,ref:t},i)}),eP=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)}},tP=e=>{let{transform:{initial:t,final:s}}=e;return[{transform:cr.Transform.toString(t)},{transform:cr.Transform.toString(s)}]},nP={duration:250,easing:"ease",keyframes:tP,sideEffects:eP({styles:{active:{opacity:"0"}}})};function sP(e){let{config:t,draggableNodes:s,droppableContainers:r,measuringConfiguration:o}=e;return Pd((i,a)=>{if(t===null)return;const l=s.get(i);if(!l)return;const c=l.node.current;if(!c)return;const u=Zj(a);if(!u)return;const{transform:d}=ds(a).getComputedStyle(a),m=Vj(d);if(!m)return;const h=typeof t=="function"?t:rP(t);return Yj(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 rP(e){const{duration:t,easing:s,sideEffects:r,keyframes:o}={...nP,...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 y=r?.({active:a,dragOverlay:l,...u}),j=l.node.animate(p,{duration:t,easing:s,fill:"forwards"});return new Promise(w=>{j.onfinish=()=>{y?.(),w()}})}}let Lg=0;function oP(e){return f.useMemo(()=>{if(e!=null)return Lg++,Lg},[e])}const iP=Ue.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:y,over:j,measuringConfiguration:w,scrollableAncestors:b,scrollableAncestorRects:N,windowRect:C}=nl(),E=f.useContext(Ld),T=oP(m?.id),k=n1(a,{activatorEvent:d,active:m,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:y.rect,over:j,overlayNodeRect:y.rect,scrollableAncestors:b,scrollableAncestorRects:N,transform:E,windowRect:C}),L=qh(h),F=sP({config:r,draggableNodes:g,droppableContainers:x,measuringConfiguration:w}),A=L?y.setRef:void 0;return Ue.createElement(XM,null,Ue.createElement(qM,{animation:F},m&&T?Ue.createElement(ZM,{key:T,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))}),Yh=f.createContext({});function Xh(e){const t=f.useRef(null);return t.current===null&&(t.current=e()),t.current}const aP=typeof window<"u",Vc=aP?f.useLayoutEffect:f.useEffect,_d=f.createContext(null);function Qh(e,t){e.indexOf(t)===-1&&e.push(t)}function Hc(e,t){const s=e.indexOf(t);s>-1&&e.splice(s,1)}const dr=(e,t,s)=>s>t?t:s<e?e:s;let Bd=()=>{};const eo={},r1=e=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e),o1=e=>typeof e=="object"&&e!==null,i1=e=>/^0[^.\s]+$/u.test(e);function a1(e){let t;return()=>(t===void 0&&(t=e()),t)}const Os=e=>e,rl=(...e)=>e.reduce((t,s)=>r=>s(t(r))),Ta=(e,t,s)=>{const r=t-e;return r?(s-e)/r:1};class Jh{constructor(){this.subscriptions=[]}add(t){return Qh(this.subscriptions,t),()=>Hc(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,Ts=e=>e/1e3,l1=(e,t)=>t?e*(1e3/t):0,c1=(e,t,s)=>(((1-3*s+3*t)*e+(3*s-6*t))*e+3*t)*e,lP=1e-7,cP=12;function dP(e,t,s,r,o){let i,a,l=0;do a=t+(s-t)/2,i=c1(a,r,o)-e,i>0?s=a:t=a;while(Math.abs(i)>lP&&++l<cP);return a}function ol(e,t,s,r){if(e===t&&s===r)return Os;const o=i=>dP(i,0,1,e,s);return i=>i===0||i===1?i:c1(o(i),t,r)}const d1=e=>t=>t<=.5?e(2*t)/2:(2-e(2*(1-t)))/2,u1=e=>t=>1-e(1-t),f1=ol(.33,1.53,.69,.99),Zh=u1(f1),m1=d1(Zh),h1=e=>e>=1?1:(e*=2)<1?.5*Zh(e):.5*(2-Math.pow(2,-10*(e-1))),ep=e=>1-Math.sin(Math.acos(e)),p1=u1(ep),x1=d1(ep),uP=ol(.42,0,1,1),fP=ol(0,0,.58,1),g1=ol(.42,0,.58,1),mP=e=>Array.isArray(e)&&typeof e[0]!="number",v1=e=>Array.isArray(e)&&typeof e[0]=="number",hP={linear:Os,easeIn:uP,easeInOut:g1,easeOut:fP,circIn:ep,circInOut:x1,circOut:p1,backIn:Zh,backInOut:m1,backOut:f1,anticipate:h1},pP=e=>typeof e=="string",_g=e=>{if(v1(e)){Bd(e.length===4);const[t,s,r,o]=e;return ol(t,s,r,o)}else if(pP(e))return hP[e];return e},Il=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function xP(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 gP=40;function b1(e,t){let s=!1,r=!0;const o={delta:0,timestamp:0,isProcessing:!1},i=()=>s=!0,a=Il.reduce((b,N)=>(b[N]=xP(i),b),{}),{setup:l,read:c,resolveKeyframes:u,preUpdate:d,update:m,preRender:h,render:p,postRender:g}=a,x=()=>{const b=eo.useManualTiming,N=b?o.timestamp:performance.now();s=!1,b||(o.delta=r?1e3/60:Math.max(Math.min(N-o.timestamp,gP),1)),o.timestamp=N,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))},y=()=>{s=!0,r=!0,o.isProcessing||e(x)};return{schedule:Il.reduce((b,N)=>{const C=a[N];return b[N]=(E,T=!1,k=!1)=>(s||y(),C.schedule(E,T,k)),b},{}),cancel:b=>{for(let N=0;N<Il.length;N++)a[Il[N]].cancel(b)},state:o,steps:a}}const{schedule:xn,cancel:to,state:Zn,steps:Iu}=b1(typeof requestAnimationFrame<"u"?requestAnimationFrame:Os,!0);let oc;function vP(){oc=void 0}const as={now:()=>(oc===void 0&&as.set(Zn.isProcessing||eo.useManualTiming?Zn.timestamp:performance.now()),oc),set:e=>{oc=e,queueMicrotask(vP)}},y1=e=>t=>typeof t=="string"&&t.startsWith(e),w1=y1("--"),bP=y1("var(--"),tp=e=>bP(e)?yP.test(e.split("/*")[0].trim()):!1,yP=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function Bg(e){return typeof e!="string"?!1:e.split("/*")[0].includes("var(--")}const Si={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},Aa={...Si,transform:e=>dr(0,1,e)},Tl={...Si,default:1},oa=e=>Math.round(e*1e5)/1e5,np=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function wP(e){return e==null}const jP=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,sp=(e,t)=>s=>!!(typeof s=="string"&&jP.test(s)&&s.startsWith(e)||t&&!wP(s)&&Object.prototype.hasOwnProperty.call(s,t)),j1=(e,t,s)=>r=>{if(typeof r!="string")return r;const[o,i,a,l]=r.match(np);return{[e]:parseFloat(o),[t]:parseFloat(i),[s]:parseFloat(a),alpha:l!==void 0?parseFloat(l):1}},kP=e=>dr(0,255,e),Tu={...Si,transform:e=>Math.round(kP(e))},jo={test:sp("rgb","red"),parse:j1("red","green","blue"),transform:({red:e,green:t,blue:s,alpha:r=1})=>"rgba("+Tu.transform(e)+", "+Tu.transform(t)+", "+Tu.transform(s)+", "+oa(Aa.transform(r))+")"};function NP(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 Kf={test:sp("#"),parse:NP,transform:jo.transform},il=e=>({test:t=>typeof t=="string"&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}),vr=il("deg"),ir=il("%"),ut=il("px"),SP=il("vh"),CP=il("vw"),Fg={...ir,parse:e=>ir.parse(e)/100,transform:e=>ir.transform(e*100)},Jo={test:sp("hsl","hue"),parse:j1("hue","saturation","lightness"),transform:({hue:e,saturation:t,lightness:s,alpha:r=1})=>"hsla("+Math.round(e)+", "+ir.transform(oa(t))+", "+ir.transform(oa(s))+", "+oa(Aa.transform(r))+")"},On={test:e=>jo.test(e)||Kf.test(e)||Jo.test(e),parse:e=>jo.test(e)?jo.parse(e):Jo.test(e)?Jo.parse(e):Kf.parse(e),transform:e=>typeof e=="string"?e:e.hasOwnProperty("red")?jo.transform(e):Jo.transform(e),getAnimatableNone:e=>{const t=On.parse(e);return t.alpha=0,On.transform(t)}},IP=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;function TP(e){return isNaN(e)&&typeof e=="string"&&(e.match(np)?.length||0)+(e.match(IP)?.length||0)>0}const k1="number",N1="color",AP="var",EP="var(",zg="${}",RP=/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 hi(e){const t=e.toString(),s=[],r={color:[],number:[],var:[]},o=[];let i=0;const l=t.replace(RP,c=>(On.test(c)?(r.color.push(i),o.push(N1),s.push(On.parse(c))):c.startsWith(EP)?(r.var.push(i),o.push(AP),s.push(c)):(r.number.push(i),o.push(k1),s.push(parseFloat(c))),++i,zg)).split(zg);return{values:s,split:l,indexes:r,types:o}}function MP(e){return hi(e).values}function S1({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===k1?o+=oa(r[i]):a===N1?o+=On.transform(r[i]):o+=r[i]}return o}}function PP(e){return S1(hi(e))}const DP=e=>typeof e=="number"?0:On.test(e)?On.getAnimatableNone(e):e,OP=(e,t)=>typeof e=="number"?t?.trim().endsWith("/")?e:0:DP(e);function LP(e){const t=hi(e);return S1(t)(t.values.map((r,o)=>OP(r,t.split[o])))}const Ws={test:TP,parse:MP,createTransformer:PP,getAnimatableNone:LP};function Au(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 _P({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=Au(c,l,e+1/3),i=Au(c,l,e),a=Au(c,l,e-1/3)}return{red:Math.round(o*255),green:Math.round(i*255),blue:Math.round(a*255),alpha:r}}function Wc(e,t){return s=>s>0?t:e}const pn=(e,t,s)=>e+(t-e)*s,Eu=(e,t,s)=>{const r=e*e,o=s*(t*t-r)+r;return o<0?0:Math.sqrt(o)},BP=[Kf,jo,Jo],FP=e=>BP.find(t=>t.test(e));function $g(e){const t=FP(e);if(!t)return!1;let s=t.parse(e);return t===Jo&&(s=_P(s)),s}const Vg=(e,t)=>{const s=$g(e),r=$g(t);if(!s||!r)return Wc(e,t);const o={...s};return i=>(o.red=Eu(s.red,r.red,i),o.green=Eu(s.green,r.green,i),o.blue=Eu(s.blue,r.blue,i),o.alpha=pn(s.alpha,r.alpha,i),jo.transform(o))},qf=new Set(["none","hidden"]);function zP(e,t){return qf.has(e)?s=>s<=0?e:t:s=>s>=1?t:e}function $P(e,t){return s=>pn(e,t,s)}function rp(e){return typeof e=="number"?$P:typeof e=="string"?tp(e)?Wc:On.test(e)?Vg:WP:Array.isArray(e)?C1:typeof e=="object"?On.test(e)?Vg:VP:Wc}function C1(e,t){const s=[...e],r=s.length,o=e.map((i,a)=>rp(i)(i,t[a]));return i=>{for(let a=0;a<r;a++)s[a]=o[a](i);return s}}function VP(e,t){const s={...e,...t},r={};for(const o in s)e[o]!==void 0&&t[o]!==void 0&&(r[o]=rp(e[o])(e[o],t[o]));return o=>{for(const i in r)s[i]=r[i](o);return s}}function HP(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 WP=(e,t)=>{const s=Ws.createTransformer(t),r=hi(e),o=hi(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?qf.has(e)&&!o.values.length||qf.has(t)&&!r.values.length?zP(e,t):rl(C1(HP(r,o),o.values),s):Wc(e,t)};function I1(e,t,s){return typeof e=="number"&&typeof t=="number"&&typeof s=="number"?pn(e,t,s):rp(e)(e,t)}const UP=e=>{const t=({timestamp:s})=>e(s);return{start:(s=!0)=>xn.update(t,s),stop:()=>to(t),now:()=>Zn.isProcessing?Zn.timestamp:as.now()}},T1=(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)})`},Uc=2e4;function op(e){let t=0;const s=50;let r=e.next(t);for(;!r.done&&t<Uc;)t+=s,r=e.next(t);return t>=Uc?1/0:t}function GP(e,t=100,s){const r=s({...e,keyframes:[0,t]}),o=Math.min(op(r),Uc);return{type:"keyframes",ease:i=>r.next(o*i).value/t,duration:Ts(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 Yf(e,t){return e*Math.sqrt(1-t*t)}const KP=12;function qP(e,t,s){let r=s;for(let o=1;o<KP;o++)r=r-e(r)/t(r);return r}const Ru=.001;function YP({duration:e=En.duration,bounce:t=En.bounce,velocity:s=En.velocity,mass:r=En.mass}){let o,i,a=1-t;a=dr(En.minDamping,En.maxDamping,a),e=dr(En.minDuration,En.maxDuration,Ts(e)),a<1?(o=u=>{const d=u*a,m=d*e,h=d-s,p=Yf(u,a),g=Math.exp(-m);return Ru-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=Yf(Math.pow(u,2),a);return(-o(u)+Ru>0?-1:1)*((h-p)*g)/x}):(o=u=>{const d=Math.exp(-u*e),m=(u-s)*e+1;return-Ru+d*m},i=u=>{const d=Math.exp(-u*e),m=(s-u)*(e*e);return d*m});const l=5/e,c=qP(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 XP=["duration","bounce"],QP=["stiffness","damping","mass"];function Hg(e,t){return t.some(s=>e[s]!==void 0)}function JP(e){let t={velocity:En.velocity,stiffness:En.stiffness,damping:En.damping,mass:En.mass,isResolvedFromDuration:!1,...e};if(!Hg(e,QP)&&Hg(e,XP))if(t.velocity=0,e.visualDuration){const s=e.visualDuration,r=2*Math.PI/(s*1.2),o=r*r,i=2*dr(.05,1,1-(e.bounce||0))*Math.sqrt(o);t={...t,mass:En.mass,stiffness:o,damping:i}}else{const s=YP({...e,velocity:0});t={...t,...s,mass:En.mass},t.isResolvedFromDuration=!0}return t}function Gc(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}=JP({...s,velocity:-Ts(s.velocity||0)}),g=h||0,x=u/(2*Math.sqrt(c*d)),y=a-i,j=Ts(Math.sqrt(c/d)),w=Math.abs(y)<5;r||(r=w?En.restSpeed.granular:En.restSpeed.default),o||(o=w?En.restDelta.granular:En.restDelta.default);let b,N,C,E,T,k;if(x<1)C=Yf(j,x),E=(g+x*j*y)/C,b=F=>{const A=Math.exp(-x*j*F);return a-A*(E*Math.sin(C*F)+y*Math.cos(C*F))},T=x*j*E+y*C,k=x*j*y-E*C,N=F=>Math.exp(-x*j*F)*(T*Math.sin(C*F)+k*Math.cos(C*F));else if(x===1){b=A=>a-Math.exp(-j*A)*(y+(g+j*y)*A);const F=g+j*y;N=A=>Math.exp(-j*A)*(j*F*A-g)}else{const F=j*Math.sqrt(x*x-1);b=H=>{const G=Math.exp(-x*j*H),U=Math.min(F*H,300);return a-G*((g+x*j*y)*Math.sinh(U)+F*y*Math.cosh(U))/F};const A=(g+x*j*y)/F,D=x*j*A-y*F,M=x*j*y-A*F;N=H=>{const G=Math.exp(-x*j*H),U=Math.min(F*H,300);return G*(D*Math.sinh(U)+M*Math.cosh(U))}}const L={calculatedDuration:p&&m||null,velocity:F=>xs(N(F)),next:F=>{if(!p&&x<1){const D=Math.exp(-x*j*F),M=Math.sin(C*F),H=Math.cos(C*F),G=a-D*(E*M+y*H),U=xs(D*(T*M+k*H));return l.done=Math.abs(U)<=r&&Math.abs(a-G)<=o,l.value=l.done?a:G,l}const A=b(F);if(p)l.done=F>=m;else{const D=xs(N(F));l.done=Math.abs(D)<=r&&Math.abs(a-A)<=o}return l.value=l.done?a:A,l},toString:()=>{const F=Math.min(op(L),Uc),A=T1(D=>L.next(F*D).value,F,30);return F+"ms "+A},toTransition:()=>{}};return L}Gc.applyToOptions=e=>{const t=GP(e,100,Gc);return e.ease=t.ease,e.duration=xs(t.duration),e.type="keyframes",e};const ZP=5;function A1(e,t,s){const r=Math.max(t-ZP,0);return l1(s-e(r),t-r)}function Xf({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 y=m+x,j=a===void 0?y:a(y);j!==y&&(x=j-m);const w=k=>-x*Math.exp(-k/r),b=k=>j+w(k),N=k=>{const L=w(k),F=b(k);h.done=Math.abs(L)<=u,h.value=h.done?j:F};let C,E;const T=k=>{p(h.value)&&(C=k,E=Gc({keyframes:[h.value,g(h.value)],velocity:A1(b,k,h.value),damping:o,stiffness:i,restDelta:u,restSpeed:d}))};return T(0),{calculatedDuration:null,next:k=>{let L=!1;return!E&&C===void 0&&(L=!0,N(k),T(k)),C!==void 0&&k>=C?E.next(k-C):(!L&&N(k),h)}}}function eD(e,t,s){const r=[],o=s||eo.mix||I1,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]||Os:t;l=rl(c,l)}r.push(l)}return r}function tD(e,t,{clamp:s=!0,ease:r,mixer:o}={}){const i=e.length;if(Bd(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=eD(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=Ta(e[m],e[m+1],d);return l[m](h)};return s?d=>u(dr(e[0],e[i-1],d)):u}function nD(e,t){const s=e[e.length-1];for(let r=1;r<=t;r++){const o=Ta(0,t,r);e.push(pn(s,1,o))}}function sD(e){const t=[0];return nD(t,e.length-1),t}function rD(e,t){return e.map(s=>s*t)}function oD(e,t){return e.map(()=>t||g1).splice(0,e.length-1)}function ia({duration:e=300,keyframes:t,times:s,ease:r="easeInOut"}){const o=mP(r)?r.map(_g):_g(r),i={done:!1,value:t[0]},a=rD(s&&s.length===t.length?s:sD(t),e),l=tD(a,t,{ease:Array.isArray(o)?o:oD(t,o)});return{calculatedDuration:e,next:c=>(i.value=l(c),i.done=c>=e,i)}}const iD=e=>e!==null;function Fd(e,{repeat:t,repeatType:s="loop"},r,o=1){const i=e.filter(iD),l=o<0||t&&s!=="loop"&&t%2===1?0:i.length-1;return!l||r===void 0?i[l]:r}const aD={decay:Xf,inertia:Xf,tween:ia,keyframes:ia,spring:Gc};function E1(e){typeof e.type=="string"&&(e.type=aD[e.type])}class ip{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 lD=e=>e/100;class Kc extends ip{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;E1(t);const{type:s=ia,repeat:r=0,repeatDelay:o=0,repeatType:i,velocity:a=0}=t;let{keyframes:l}=t;const c=s||ia;c!==ia&&typeof l[0]!="number"&&(this.mixKeyframes=rl(lD,I1(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=op(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:y}=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 j=this.currentTime-u*(this.playbackSpeed>=0?1:-1),w=this.playbackSpeed>=0?j<0:j>o;this.currentTime=Math.max(j,0),this.state==="finished"&&this.holdTime===null&&(this.currentTime=o);let b=this.currentTime,N=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"&&(N=a)),b=dr(0,1,F)*l}let C;w?(this.delayState.value=d[0],C=this.delayState):C=N.next(b),i&&!w&&(C.value=i(C.value));let{done:E}=C;!w&&c!==null&&(E=this.playbackSpeed>=0?this.currentTime>=o:this.currentTime<=0);const T=this.holdTime===null&&(this.state==="finished"||this.state==="running"&&E);return T&&g!==Xf&&(C.value=Fd(d,this.options,y,this.speed)),x&&x(C.value),T&&this.finish(),C}then(t,s){return this.finished.then(t,s)}get duration(){return Ts(this.calculatedDuration)}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+Ts(t)}get time(){return Ts(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 A1(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=Ts(this.currentTime))}play(){if(this.isStopped)return;const{driver:t=UP,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 cD(e){for(let t=1;t<e.length;t++)e[t]??(e[t]=e[t-1])}const ko=e=>e*180/Math.PI,Qf=e=>{const t=ko(Math.atan2(e[1],e[0]));return Jf(t)},dD={x:4,y:5,translateX:4,translateY:5,scaleX:0,scaleY:3,scale:e=>(Math.abs(e[0])+Math.abs(e[3]))/2,rotate:Qf,rotateZ:Qf,skewX:e=>ko(Math.atan(e[1])),skewY:e=>ko(Math.atan(e[2])),skew:e=>(Math.abs(e[1])+Math.abs(e[2]))/2},Jf=e=>(e=e%360,e<0&&(e+=360),e),Wg=Qf,Ug=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]),Gg=e=>Math.sqrt(e[4]*e[4]+e[5]*e[5]),uD={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:Ug,scaleY:Gg,scale:e=>(Ug(e)+Gg(e))/2,rotateX:e=>Jf(ko(Math.atan2(e[6],e[5]))),rotateY:e=>Jf(ko(Math.atan2(-e[2],e[0]))),rotateZ:Wg,rotate:Wg,skewX:e=>ko(Math.atan(e[4])),skewY:e=>ko(Math.atan(e[1])),skew:e=>(Math.abs(e[1])+Math.abs(e[4]))/2};function Zf(e){return e.includes("scale")?1:0}function em(e,t){if(!e||e==="none")return Zf(t);const s=e.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);let r,o;if(s)r=uD,o=s;else{const l=e.match(/^matrix\(([-\d.e\s,]+)\)$/u);r=dD,o=l}if(!o)return Zf(t);const i=r[t],a=o[1].split(",").map(mD);return typeof i=="function"?i(a):a[i]}const fD=(e,t)=>{const{transform:s="none"}=getComputedStyle(e);return em(s,t)};function mD(e){return parseFloat(e.trim())}const Ci=["transformPerspective","x","y","z","translateX","translateY","translateZ","scale","scaleX","scaleY","rotate","rotateX","rotateY","rotateZ","skew","skewX","skewY"],Ii=new Set([...Ci,"pathRotation"]),Kg=e=>e===Si||e===ut,hD=new Set(["x","y","z"]),pD=Ci.filter(e=>!hD.has(e));function xD(e){const t=[];return pD.forEach(s=>{const r=e.getValue(s);r!==void 0&&(t.push([s,r.get()]),r.set(s.startsWith("scale")?1:0))}),t}const qr={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})=>em(t,"x"),y:(e,{transform:t})=>em(t,"y")};qr.translateX=qr.x;qr.translateY=qr.y;const Io=new Set;let tm=!1,nm=!1,sm=!1;function R1(){if(nm){const e=Array.from(Io).filter(r=>r.needsMeasurement),t=new Set(e.map(r=>r.element)),s=new Map;t.forEach(r=>{const o=xD(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,tm=!1,Io.forEach(e=>e.complete(sm)),Io.clear()}function M1(){Io.forEach(e=>{e.readKeyframes(),e.needsMeasurement&&(nm=!0)})}function gD(){sm=!0,M1(),R1(),sm=!1}class ap{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?(Io.add(this),tm||(tm=!0,xn.read(M1),xn.resolveKeyframes(R1))):(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])}cD(t)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(t=!1){this.state="complete",this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,t),Io.delete(this)}cancel(){this.state==="scheduled"&&(Io.delete(this),this.state="pending")}resume(){this.state==="pending"&&this.scheduleResolve()}}const vD=e=>e.startsWith("--");function P1(e,t,s){vD(t)?e.style.setProperty(t,s):e.style[t]=s}const bD={};function D1(e,t){const s=a1(e);return()=>bD[t]??s()}const yD=D1(()=>window.ScrollTimeline!==void 0,"scrollTimeline"),O1=D1(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0},"linearEasing"),Ji=([e,t,s,r])=>`cubic-bezier(${e}, ${t}, ${s}, ${r})`,qg={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:Ji([0,.65,.55,1]),circOut:Ji([.55,0,1,.45]),backIn:Ji([.31,.01,.66,-.59]),backOut:Ji([.33,1.53,.69,.99])};function L1(e,t){if(e)return typeof e=="function"?O1()?T1(e,t):"ease-out":v1(e)?Ji(e):Array.isArray(e)?e.map(s=>L1(s,t)||qg.easeOut):qg[e]}function wD(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=L1(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 _1(e){return typeof e=="function"&&"applyToOptions"in e}function jD({type:e,...t}){return _1(e)&&O1()?e.applyToOptions(t):(t.duration??(t.duration=300),t.ease??(t.ease="easeOut"),t)}class B1 extends ip{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,Bd(typeof t.type!="string");const u=jD(t);this.animation=wD(s,r,o,u,i),u.autoplay===!1&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!i){const d=Fd(o,this.options,l,this.speed);this.updateMotionValue&&this.updateMotionValue(d),P1(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 Ts(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+Ts(t)}get time(){return Ts(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&&yD()?(this.animation.timeline=t,s&&(this.animation.rangeStart=s),r&&(this.animation.rangeEnd=r),Os):o(this)}}const F1={anticipate:h1,backInOut:m1,circInOut:x1};function kD(e){return e in F1}function ND(e){typeof e.ease=="string"&&kD(e.ease)&&(e.ease=F1[e.ease])}const Mu=10;class SD extends B1{constructor(t){ND(t),E1(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 Kc({...a,autoplay:!1}),c=Math.max(Mu,as.now()-this.startTime),u=dr(0,Mu,c-Mu),d=l.sample(c).value,{name:m}=this.options;i&&m&&P1(i,m,d),s.setWithVelocity(l.sample(Math.max(0,c-u)).value,d,u),l.stop()}}const Yg=(e,t)=>t==="zIndex"?!1:!!(typeof e=="number"||Array.isArray(e)||typeof e=="string"&&(Ws.test(e)||e==="0")&&!e.startsWith("url("));function CD(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 ID(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=Yg(o,t),l=Yg(i,t);return!a||!l?!1:CD(e)||(s==="spring"||_1(s))&&r}function rm(e){e.duration=0,e.type="keyframes"}const z1=new Set(["opacity","clipPath","filter","transform","backgroundColor"]),TD=/^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;function AD(e){for(let t=0;t<e.length;t++)if(typeof e[t]=="string"&&TD.test(e[t]))return!0;return!1}const ED=new Set(["color","backgroundColor","outlineColor","fill","stroke","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor"]),RD=a1(()=>Object.hasOwnProperty.call(Element.prototype,"animate"));function MD(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 RD()&&s&&(z1.has(s)||ED.has(s)&&AD(l))&&(s!=="transform"||!d)&&!u&&!r&&o!=="mirror"&&i!==0&&a!=="inertia"}const PD=40;class DD extends ip{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||ap;this.keyframeResolver=new p(l,(g,x,y)=>this.onKeyframesResolved(g,x,h,!y),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;ID(t,i,a,l)||(m=!1,(eo.instantAnimations||!c)&&d?.(Fd(t,r,s)),t[0]=t[t.length-1],rm(r),r.repeat=0);const p={startTime:o?this.resolvedAt?this.resolvedAt-this.createdAt>PD?this.resolvedAt:this.createdAt:this.createdAt:void 0,finalKeyframe:s,...r,keyframes:t},g=m&&!u&&MD(p),x=p.motionValue?.owner?.current;let y;if(g)try{y=new SD({...p,element:x})}catch{y=new Kc(p)}else y=new Kc(p);y.finished.then(()=>{this.notifyFinished()}).catch(Os),this.pendingTimeline&&(this.stopTimeline=y.attachTimeline(this.pendingTimeline),this.pendingTimeline=void 0),this._animation=y}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(),gD()),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 $1(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 Xg=30,OD=e=>!isNaN(parseFloat(e));class LD{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=OD(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 Jh);const r=this.events[t].add(s);return t==="change"?()=>{r(),xn.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>Xg)return 0;const s=Math.min(this.updatedAt-this.prevUpdatedAt,Xg);return l1(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 pi(e,t){return new LD(e,t)}function V1(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?V1(s,e):s}const _D={type:"spring",stiffness:500,damping:25,restSpeed:10},BD=e=>({type:"spring",stiffness:550,damping:e===0?2*Math.sqrt(550):30,restSpeed:10}),FD={type:"keyframes",duration:.8},zD={type:"keyframes",ease:[.25,.1,.35,1],duration:.3},$D=(e,{keyframes:t})=>t.length>2?FD:Ii.has(e)?e.startsWith("scale")?BD(t[1]):_D:zD,VD=new Set(["when","delay","delayChildren","staggerChildren","staggerDirection","repeat","repeatType","repeatDelay","from","elapsed"]);function HD(e){for(const t in e)if(!VD.has(t))return!0;return!1}const cp=(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};HD(l)||Object.assign(d,$D(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)&&(rm(d),d.delay===0&&(m=!0)),(eo.instantAnimations||eo.skipAnimations||o?.shouldSkipAnimations||l.skipAnimations)&&(m=!0,rm(d),d.delay=0),d.allowFlatten=!l.type&&!l.ease,m&&!i&&t.get()!==void 0){const h=Fd(d.keyframes,l);if(h!==void 0){xn.update(()=>{d.onUpdate(h),d.onComplete()});return}}return l.isSync?new Kc(d):new DD(d)},WD=/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;function UD(e){const t=WD.exec(e);if(!t)return[,];const[,s,r,o]=t;return[`--${s??r}`,o]}function H1(e,t,s=1){const[r,o]=UD(e);if(!r)return;const i=window.getComputedStyle(t).getPropertyValue(r);if(i){const a=i.trim();return r1(a)?parseFloat(a):a}return tp(o)?H1(o,t,s+1):o}function Qg(e){const t=[{},{}];return e?.values.forEach((s,r)=>{t[0][r]=s.get(),t[1][r]=s.getVelocity()}),t}function dp(e,t,s,r){if(typeof t=="function"){const[o,i]=Qg(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]=Qg(r);t=t(s!==void 0?s:e.custom,o,i)}return t}function To(e,t,s){const r=e.getProps();return dp(r,t,s!==void 0?s:r.custom,e)}const W1=new Set(["width","height","top","left","right","bottom",...Ci]),om=e=>Array.isArray(e);function GD(e,t,s){e.hasValue(t)?e.getValue(t).set(s):e.addValue(t,pi(s))}function KD(e){return om(e)?e[e.length-1]||0:e}function qD(e,t){const s=To(e,t);let{transitionEnd:r={},transition:o={},...i}=s||{};i={...i,...r};for(const a in i){const l=KD(i[a]);GD(e,a,l)}}const es=e=>!!(e&&e.getVelocity);function YD(e){return!!(es(e)&&e.add)}function im(e,t){const s=e.getValue("willChange");if(YD(s))return s.add(t);if(!s&&eo.WillChange){const r=new eo.WillChange("auto");e.addValue("willChange",r),r.add(t)}}function up(e){return e.replace(/([A-Z])/g,t=>`-${t.toLowerCase()}`)}const XD="framerAppearId",U1="data-"+up(XD);function G1(e){return e.props[U1]}const QD=typeof window<"u";function JD({protectedKeys:e,needsAnimating:t},s){const r=e.hasOwnProperty(s)&&t[s]!==!0;return t[s]=!1,r}function K1(e,t,{delay:s=0,transitionOverride:r,type:o}={}){let{transition:i,transitionEnd:a,...l}=t;const c=e.getDefaultTransition();i=i?V1(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),y=l[g];if(y===void 0||h&&JD(h,g))continue;const j={delay:s,...lp(i||{},g)};d&&(j.skipAnimations=!0);const w=x.get();if(w!==void 0&&!x.isAnimating()&&!Array.isArray(y)&&y===w&&!j.velocity){xn.update(()=>x.set(y));continue}let b=!1;if(QD&&window.MotionHandoffAnimation){const E=G1(e);if(E){const T=window.MotionHandoffAnimation(E,g,xn);T!==null&&(j.startTime=T,b=!0)}}im(e,g);const N=u??e.shouldReduceMotion;x.start(cp(g,x,y,N&&W1.has(g)?{type:!1}:j,e,b));const C=x.animation;C&&m.push(C)}if(a){const g=()=>xn.update(()=>{a&&qD(e,a)});m.length?Promise.all(m).then(g):g()}return m}function am(e,t,s={}){const r=To(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(K1(e,r,s)):()=>Promise.resolve(),a=e.variantChildren&&e.variantChildren.size?(c=0)=>{const{delayChildren:u=0,staggerChildren:d,staggerDirection:m}=o;return ZD(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 ZD(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)+$1(e.variantChildren,c,r,o,i)}).then(()=>c.notify("AnimationComplete",t)));return Promise.all(l)}function e6(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"?To(e,t,s.custom):t;r=Promise.all(K1(e,o,s))}return r.then(()=>{e.notify("AnimationComplete",t)})}const t6={test:e=>e==="auto",parse:e=>e},q1=e=>t=>t.test(e),Y1=[Si,ut,ir,vr,CP,SP,t6],Jg=e=>Y1.find(q1(e));function n6(e){return typeof e=="number"?e===0:e!==null?e==="none"||e==="0"||i1(e):!0}const s6=new Set(["brightness","contrast","saturate","opacity"]);function r6(e){const[t,s]=e.slice(0,-1).split("(");if(t==="drop-shadow")return e;const[r]=s.match(np)||[];if(!r)return e;const o=s.replace(r,"");let i=s6.has(t)?1:0;return r!==s&&(i*=100),t+"("+i+o+")"}const o6=/\b([a-z-]*)\(.*?\)/gu,lm={...Ws,getAnimatableNone:e=>{const t=e.match(o6);return t?t.map(r6).join(" "):e}},cm={...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))}},Zg={...Si,transform:Math.round},i6={rotate:vr,pathRotation:vr,rotateX:vr,rotateY:vr,rotateZ:vr,scale:Tl,scaleX:Tl,scaleY:Tl,scaleZ:Tl,skew:vr,skewX:vr,skewY:vr,distance:ut,translateX:ut,translateY:ut,translateZ:ut,x:ut,y:ut,z:ut,perspective:ut,transformPerspective:ut,opacity:Aa,originX:Fg,originY:Fg,originZ:ut},qc={borderWidth:ut,borderTopWidth:ut,borderRightWidth:ut,borderBottomWidth:ut,borderLeftWidth:ut,borderRadius:ut,borderTopLeftRadius:ut,borderTopRightRadius:ut,borderBottomRightRadius:ut,borderBottomLeftRadius:ut,width:ut,maxWidth:ut,height:ut,maxHeight:ut,top:ut,right:ut,bottom:ut,left:ut,inset:ut,insetBlock:ut,insetBlockStart:ut,insetBlockEnd:ut,insetInline:ut,insetInlineStart:ut,insetInlineEnd:ut,padding:ut,paddingTop:ut,paddingRight:ut,paddingBottom:ut,paddingLeft:ut,paddingBlock:ut,paddingBlockStart:ut,paddingBlockEnd:ut,paddingInline:ut,paddingInlineStart:ut,paddingInlineEnd:ut,margin:ut,marginTop:ut,marginRight:ut,marginBottom:ut,marginLeft:ut,marginBlock:ut,marginBlockStart:ut,marginBlockEnd:ut,marginInline:ut,marginInlineStart:ut,marginInlineEnd:ut,fontSize:ut,backgroundPositionX:ut,backgroundPositionY:ut,...i6,zIndex:Zg,fillOpacity:Aa,strokeOpacity:Aa,numOctaves:Zg},a6={...qc,color:On,backgroundColor:On,outlineColor:On,fill:On,stroke:On,borderColor:On,borderTopColor:On,borderRightColor:On,borderBottomColor:On,borderLeftColor:On,filter:lm,WebkitFilter:lm,mask:cm,WebkitMask:cm},X1=e=>a6[e],l6=new Set([lm,cm]);function Q1(e,t){let s=X1(e);return l6.has(s)||(s=Ws),s.getAnimatableNone?s.getAnimatableNone(t):void 0}const c6=new Set(["auto","none","0"]);function d6(e,t,s){let r=0,o;for(;r<e.length&&!o;){const i=e[r];typeof i=="string"&&!c6.has(i)&&hi(i).values.length&&(o=e[r]),r++}if(o&&s)for(const i of t)e[i]=Q1(s,o)}class u6 extends ap{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(),tp(m))){const h=H1(m,s.current);h!==void 0&&(t[d]=h),d===t.length-1&&(this.finalKeyframe=m)}}if(this.resolveNoneKeyframes(),!W1.has(r)||t.length!==2)return;const[o,i]=t,a=Jg(o),l=Jg(i),c=Bg(o),u=Bg(i);if(c!==u&&qr[r]){this.needsMeasurement=!0;return}if(a!==l)if(Kg(a)&&Kg(l))for(let d=0;d<t.length;d++){const m=t[d];typeof m=="string"&&(t[d]=parseFloat(m))}else qr[r]&&(this.needsMeasurement=!0)}resolveNoneKeyframes(){const{unresolvedKeyframes:t,name:s}=this,r=[];for(let o=0;o<t.length;o++)(t[o]===null||n6(t[o]))&&r.push(o);r.length&&d6(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=qr[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]=qr[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 fp=["borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius"];function J1(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 dm=(e,t)=>t&&typeof e=="number"?t.transform(e):e;function ic(e){return o1(e)&&"offsetHeight"in e&&!("ownerSVGElement"in e)}const{schedule:mp}=b1(queueMicrotask,!1),$s={x:!1,y:!1};function Z1(){return $s.x||$s.y}function f6(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 ek(e,t){const s=J1(e),r=new AbortController,o={passive:!0,...t,signal:r.signal};return[s,o,()=>r.abort()]}function m6(e){return!(e.pointerType==="touch"||Z1())}function h6(e,t,s={}){const[r,o,i]=ek(e,s);return r.forEach(a=>{let l=!1,c=!1,u;const d=()=>{a.removeEventListener("pointerleave",g)},m=y=>{u&&(u(y),u=void 0),d()},h=y=>{l=!1,window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h),c&&(c=!1,m(y))},p=()=>{l=!0,window.addEventListener("pointerup",h,o),window.addEventListener("pointercancel",h,o)},g=y=>{if(y.pointerType!=="touch"){if(l){c=!0;return}m(y)}},x=y=>{if(!m6(y))return;c=!1;const j=t(a,y);typeof j=="function"&&(u=j,a.addEventListener("pointerleave",g,o))};a.addEventListener("pointerenter",x,o),a.addEventListener("pointerdown",p,o)}),i}const tk=(e,t)=>t?e===t?!0:tk(e,t.parentElement):!1,hp=e=>e.pointerType==="mouse"?typeof e.button!="number"||e.button<=0:e.isPrimary!==!1,p6=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);function x6(e){return p6.has(e.tagName)||e.isContentEditable===!0}const g6=new Set(["INPUT","SELECT","TEXTAREA"]);function v6(e){return g6.has(e.tagName)||e.isContentEditable===!0}const ac=new WeakSet;function e0(e){return t=>{t.key==="Enter"&&e(t)}}function Pu(e,t){e.dispatchEvent(new PointerEvent("pointer"+t,{isPrimary:!0,bubbles:!0}))}const b6=(e,t)=>{const s=e.currentTarget;if(!s)return;const r=e0(()=>{if(ac.has(s))return;Pu(s,"down");const o=e0(()=>{Pu(s,"up")}),i=()=>Pu(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 t0(e){return hp(e)&&!Z1()}const n0=new WeakSet;function y6(e,t,s={}){const[r,o,i]=ek(e,s),a=l=>{const c=l.currentTarget;if(!t0(l)||n0.has(l))return;ac.add(c),s.stopPropagation&&n0.add(l);const u=t(c,l),d={...o,capture:!0},m=(g,x)=>{window.removeEventListener("pointerup",h,d),window.removeEventListener("pointercancel",p,d),ac.has(c)&&ac.delete(c),t0(g)&&typeof u=="function"&&u(g,{success:x})},h=g=>{m(g,c===window||c===document||s.useGlobalTarget||tk(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),ic(l)&&(l.addEventListener("focus",u=>b6(u,o)),!x6(l)&&!l.hasAttribute("tabindex")&&(l.tabIndex=0))}),i}function pp(e){return o1(e)&&"ownerSVGElement"in e}const lc=new WeakMap;let cc;const nk=(e,t,s)=>(r,o)=>o&&o[0]?o[0][e+"Size"]:pp(r)&&"getBBox"in r?r.getBBox()[t]:r[s],w6=nk("inline","width","offsetWidth"),j6=nk("block","height","offsetHeight");function k6({target:e,borderBoxSize:t}){lc.get(e)?.forEach(s=>{s(e,{get width(){return w6(e,t)},get height(){return j6(e,t)}})})}function N6(e){e.forEach(k6)}function S6(){typeof ResizeObserver>"u"||(cc=new ResizeObserver(N6))}function C6(e,t){cc||S6();const s=J1(e);return s.forEach(r=>{let o=lc.get(r);o||(o=new Set,lc.set(r,o)),o.add(t),cc?.observe(r)}),()=>{s.forEach(r=>{const o=lc.get(r);o?.delete(t),o?.size||cc?.unobserve(r)})}}const dc=new Set;let Zo;function I6(){Zo=()=>{const e={get width(){return window.innerWidth},get height(){return window.innerHeight}};dc.forEach(t=>t(e))},window.addEventListener("resize",Zo)}function T6(e){return dc.add(e),Zo||I6(),()=>{dc.delete(e),!dc.size&&typeof Zo=="function"&&(window.removeEventListener("resize",Zo),Zo=void 0)}}function s0(e,t){return typeof e=="function"?T6(e):C6(e,t)}function A6(e){return pp(e)&&e.tagName==="svg"}const E6=[...Y1,On,Ws],R6=e=>E6.find(q1(e)),r0=()=>({translate:0,scale:1,origin:0,originPoint:0}),ei=()=>({x:r0(),y:r0()}),o0=()=>({min:0,max:0}),Fn=()=>({x:o0(),y:o0()}),M6=new WeakMap;function zd(e){return e!==null&&typeof e=="object"&&typeof e.start=="function"}function Ea(e){return typeof e=="string"||Array.isArray(e)}const xp=["animate","whileInView","whileFocus","whileHover","whileTap","whileDrag","exit"],gp=["initial",...xp];function $d(e){return zd(e.animate)||gp.some(t=>Ea(e[t]))}function sk(e){return!!($d(e)||e.variants)}function P6(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,pi(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,pi(a!==void 0?a:o,{owner:e}))}}for(const r in s)t[r]===void 0&&e.removeValue(r);return t}const Yc={current:null},vp={current:!1},D6=typeof window<"u";function rk(){if(vp.current=!0,!!D6)if(window.matchMedia){const e=window.matchMedia("(prefers-reduced-motion)"),t=()=>Yc.current=e.matches;e.addEventListener("change",t),t()}else Yc.current=!1}const i0=["AnimationStart","AnimationComplete","Update","BeforeLayoutMeasure","LayoutMeasure","LayoutAnimationStart","LayoutAnimationComplete"];let Xc={};function ok(e){Xc=e}function O6(){return Xc}class L6{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=ap,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,xn.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=$d(s),this.isVariantNode=sk(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,M6.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:(vp.current||rk(),this.shouldReduceMotion=Yc.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&&z1.has(t)&&this.current instanceof HTMLElement){const{factory:a,keyframes:l,times:c,ease:u,duration:d}=s.accelerate,m=new B1({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=Ii.has(t);r&&this.onBindTransform&&this.onBindTransform();const o=s.on("change",a=>{this.latestValues[t]=a,this.props.onUpdate&&xn.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 Xc){const s=Xc[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):Fn()}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<i0.length;r++){const o=i0[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=P6(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=pi(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"&&(r1(r)||i1(r))?r=parseFloat(r):!R6(r)&&Ws.test(s)&&(r=Q1(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=dp(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 Jh),this.events[t].add(s)}notify(t,...s){this.events[t]&&this.events[t].notify(...s)}scheduleRenderMicrotask(){mp.render(this.render)}}class ik extends L6{constructor(){super(...arguments),this.KeyframeResolver=u6}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 oo{constructor(t){this.isMounted=!1,this.node=t}update(){}}function ak({top:e,left:t,right:s,bottom:r}){return{x:{min:t,max:s},y:{min:e,max:r}}}function _6({x:e,y:t}){return{top:t.min,right:e.max,bottom:t.max,left:e.min}}function B6(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 Du(e){return e===void 0||e===1}function um({scale:e,scaleX:t,scaleY:s}){return!Du(e)||!Du(t)||!Du(s)}function yo(e){return um(e)||lk(e)||e.z||e.rotate||e.rotateX||e.rotateY||e.skewX||e.skewY}function lk(e){return a0(e.x)||a0(e.y)}function a0(e){return e&&e!=="0%"}function Qc(e,t,s){const r=e-s,o=t*r;return s+o}function l0(e,t,s,r,o){return o!==void 0&&(e=Qc(e,o,r)),Qc(e,s,r)+t}function fm(e,t=0,s=1,r,o){e.min=l0(e.min,t,s,r,o),e.max=l0(e.max,t,s,r,o)}function ck(e,{x:t,y:s}){fm(e.x,t.translate,t.scale,t.originPoint),fm(e.y,s.translate,s.scale,s.originPoint)}const c0=.999999999999,d0=1.0000000000001;function F6(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&&(er(e.x,-i.scroll.offset.x),er(e.y,-i.scroll.offset.y)),a&&(t.x*=a.x.scale,t.y*=a.y.scale,ck(e,a)),r&&yo(i.latestValues)&&uc(e,i.latestValues,i.layout?.layoutBox))}t.x<d0&&t.x>c0&&(t.x=1),t.y<d0&&t.y>c0&&(t.y=1)}function er(e,t){e.min+=t,e.max+=t}function u0(e,t,s,r,o=.5){const i=pn(e.min,e.max,o);fm(e,t,s,i,r)}function f0(e,t){return typeof e=="string"?parseFloat(e)/100*(t.max-t.min):e}function uc(e,t,s){const r=s??e;u0(e.x,f0(t.x,r.x),t.scaleX,t.scale,t.originX),u0(e.y,f0(t.y,r.y),t.scaleY,t.scale,t.originY)}function dk(e,t){return ak(B6(e.getBoundingClientRect(),t))}function z6(e,t,s){const r=dk(e,s),{scroll:o}=t;return o&&(er(r.x,o.offset.x),er(r.y,o.offset.y)),r}const $6={x:"translateX",y:"translateY",z:"translateZ",transformPerspective:"perspective"},V6=Ci.length;function H6(e,t,s){let r="",o=!0;for(let a=0;a<V6;a++){const l=Ci[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=dm(c,qc[l]);if(!u){o=!1;const m=$6[l]||l;r+=`${m}(${d}) `}s&&(t[l]=d)}}const i=e.pathRotation;return i&&(o=!1,r+=`rotate(${dm(i,qc.pathRotation)}) `),r=r.trim(),s?r=s(t,o?"":r):o&&(r="none"),r}function bp(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(Ii.has(c)){a=!0;continue}else if(w1(c)){o[c]=u;continue}else{const d=dm(u,qc[c]);c.startsWith("origin")?(l=!0,i[c]=d):r[c]=d}}if(t.transform||(a||s?r.transform=H6(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 uk(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 m0(e,t){return t.max===t.min?0:e/(t.max-t.min)*100}const Fi={correct:(e,t)=>{if(!t.target)return e;if(typeof e=="string")if(ut.test(e))e=parseFloat(e);else return e;const s=m0(e,t.target.x),r=m0(e,t.target.y);return`${s}% ${r}%`}},W6={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=pn(l,c,.5);return typeof o[2+a]=="number"&&(o[2+a]/=u),typeof o[3+a]=="number"&&(o[3+a]/=u),i(o)}},mm={borderRadius:{...Fi,applyTo:[...fp]},borderTopLeftRadius:Fi,borderTopRightRadius:Fi,borderBottomLeftRadius:Fi,borderBottomRightRadius:Fi,boxShadow:W6};function fk(e,{layout:t,layoutId:s}){return Ii.has(e)||e.startsWith("origin")||(t||s!==void 0)&&(!!mm[e]||e==="opacity")}function yp(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])||fk(a,e)||s?.getValue(a)?.liveStyle!==void 0)&&(i[a]=r[a]);return i}function U6(e){return window.getComputedStyle(e)}class G6 extends ik{constructor(){super(...arguments),this.type="html",this.renderInstance=uk}mount(t){Bd(!!t.style),super.mount(t)}readValueFromInstance(t,s){if(Ii.has(s))return this.projection?.isProjecting?Zf(s):fD(t,s);{const r=U6(t),o=(w1(s)?r.getPropertyValue(s):r[s])||0;return typeof o=="string"?o.trim():o}}measureInstanceViewportBox(t,{transformPagePoint:s}){return dk(t,s)}build(t,s,r){bp(t,s,r.transformTemplate)}scrapeMotionValuesFromProps(t,s,r){return yp(t,s,r)}}const K6={offset:"stroke-dashoffset",array:"stroke-dasharray"},q6={offset:"strokeDashoffset",array:"strokeDasharray"};function Y6(e,t,s=1,r=0,o=!0){e.pathLength=1;const i=o?K6:q6;e[i.offset]=`${-r}`,e[i.array]=`${t} ${s}`}const mk=["transform","opacity","offsetDistance","offsetPath","offsetRotate","offsetAnchor"];function hk(e,{attrX:t,attrY:s,attrScale:r,pathLength:o,pathSpacing:i=1,pathOffset:a=0,...l},c,u,d){if(bp(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 mk)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&&Y6(m,o,i,a,!1)}const pk=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"]),xk=e=>typeof e=="string"&&e.toLowerCase()==="svg";function X6(e,t,s,r){uk(e,t,void 0,r);for(const o in t.attrs)e.setAttribute(pk.has(o)?o:up(o),t.attrs[o])}function gk(e,t,s){const r=yp(e,t,s);for(const o in e)if(es(e[o])||es(t[o])){const i=Ci.indexOf(o)!==-1?"attr"+o.charAt(0).toUpperCase()+o.substring(1):o;r[i]=e[o]}return r}class Q6 extends ik{constructor(){super(...arguments),this.type="svg",this.isSVGTag=!1,this.measureInstanceViewportBox=Fn}getBaseTargetFromProps(t,s){return t[s]}readValueFromInstance(t,s){if(Ii.has(s)){const r=X1(s);return r&&r.default||0}if(mk.includes(s)){const o=getComputedStyle(t)[s];if(typeof o=="string"&&o)return o.trim()}return s=pk.has(s)?s:up(s),t.getAttribute(s)}scrapeMotionValuesFromProps(t,s,r){return gk(t,s,r)}build(t,s,r){hk(t,s,this.isSVGTag,r.transformTemplate,r.style)}renderInstance(t,s,r,o){X6(t,s,r,o)}mount(t){this.isSVGTag=xk(t.tagName),super.mount(t)}}const J6=gp.length;function vk(e){if(!e)return;if(!e.isControllingVariants){const s=e.parent?vk(e.parent)||{}:{};return e.props.initial!==void 0&&(s.initial=e.props.initial),s}const t={};for(let s=0;s<J6;s++){const r=gp[s],o=e.props[r];(Ea(o)||o===!1)&&(t[r]=o)}return t}function bk(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 Z6=[...xp].reverse(),eO=xp.length;function tO(e){return t=>Promise.all(t.map(({animation:s,options:r})=>e6(e,s,r)))}function nO(e){let t=tO(e),s=h0(),r=!0,o=!1;const i=u=>(d,m)=>{const h=To(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=vk(e.parent)||{},h=[],p=new Set;let g={},x=1/0;for(let j=0;j<eO;j++){const w=Z6[j],b=s[w],N=d[w]!==void 0?d[w]:m[w],C=Ea(N),E=w===u?b.isActive:null;E===!1&&(x=j);let T=N===m[w]&&N!==d[w]&&C;if(T&&(r||o)&&e.manuallyAnimateOnMount&&(T=!1),b.protectedKeys={...g},!b.isActive&&E===null||!N&&!b.prevProp||zd(N)||typeof N=="boolean")continue;if(w==="exit"&&b.isActive&&E!==!0){b.prevResolvedValues&&(g={...g,...b.prevResolvedValues});continue}const k=sO(b.prevProp,N);let L=k||w===u&&b.isActive&&!T&&C||j>x&&C,F=!1;const A=Array.isArray(N)?N:[N];let D=A.reduce(i(w),{});E===!1&&(D={});const{prevResolvedValues:M={}}=b,H={...M,...D},G=$=>{L=!0,p.has($)&&(F=!0,p.delete($)),b.needsAnimating[$]=!0;const oe=e.getValue($);oe&&(oe.liveStyle=!1)};for(const $ in H){const oe=D[$],Ne=M[$];if(g.hasOwnProperty($))continue;let ce=!1;om(oe)&&om(Ne)?ce=!bk(oe,Ne)||k:ce=oe!==Ne,ce?oe!=null?G($):p.add($):oe!==void 0&&p.has($)?G($):b.protectedKeys[$]=!0}b.prevProp=N,b.prevResolvedValues=D,b.isActive&&(g={...g,...D}),(r||o)&&e.blockInitialAnimation&&(L=!1);const U=T&&k;L&&(!U||F)&&h.push(...A.map($=>{const oe={type:w};if(typeof $=="string"&&(r||o)&&!U&&e.manuallyAnimateOnMount&&e.parent){const{parent:Ne}=e,ce=To(Ne,$);if(Ne.enteringChildren&&ce){const{delayChildren:ne}=ce.transition||{};oe.delay=$1(Ne.enteringChildren,e,ne)}}return{animation:$,options:oe}}))}if(p.size){const j={};if(typeof d.initial!="boolean"){const w=To(e,Array.isArray(d.initial)?d.initial[0]:d.initial);w&&w.transition&&(j.transition=w.transition)}p.forEach(w=>{const b=e.getBaseTarget(w),N=e.getValue(w);N&&(N.liveStyle=!0),j[w]=b??null}),h.push({animation:j})}let y=!!h.length;return r&&(d.initial===!1||d.initial===d.animate)&&!e.manuallyAnimateOnMount&&(y=!1),r=!1,o=!1,y?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=h0(),o=!0}}}function sO(e,t){return typeof t=="string"?t!==e:Array.isArray(t)?!bk(t,e):!1}function po(e=!1){return{isActive:e,protectedKeys:{},needsAnimating:{},prevResolvedValues:{}}}function h0(){return{animate:po(!0),whileInView:po(),whileHover:po(),whileTap:po(),whileDrag:po(),whileFocus:po(),exit:po()}}function hm(e,t){e.min=t.min,e.max=t.max}function Fs(e,t){hm(e.x,t.x),hm(e.y,t.y)}function p0(e,t){e.translate=t.translate,e.scale=t.scale,e.originPoint=t.originPoint,e.origin=t.origin}const yk=1e-4,rO=1-yk,oO=1+yk,wk=.01,iO=0-wk,aO=0+wk;function ls(e){return e.max-e.min}function lO(e,t,s){return Math.abs(e-t)<=s}function x0(e,t,s,r=.5){e.origin=r,e.originPoint=pn(t.min,t.max,e.origin),e.scale=ls(s)/ls(t),e.translate=pn(s.min,s.max,e.origin)-e.originPoint,(e.scale>=rO&&e.scale<=oO||isNaN(e.scale))&&(e.scale=1),(e.translate>=iO&&e.translate<=aO||isNaN(e.translate))&&(e.translate=0)}function aa(e,t,s,r){x0(e.x,t.x,s.x,r?r.originX:void 0),x0(e.y,t.y,s.y,r?r.originY:void 0)}function g0(e,t,s,r=0){const o=r?pn(s.min,s.max,r):s.min;e.min=o+t.min,e.max=e.min+ls(t)}function cO(e,t,s,r){g0(e.x,t.x,s.x,r?.x),g0(e.y,t.y,s.y,r?.y)}function v0(e,t,s,r=0){const o=r?pn(s.min,s.max,r):s.min;e.min=t.min-o,e.max=e.min+ls(t)}function Jc(e,t,s,r){v0(e.x,t.x,s.x,r?.x),v0(e.y,t.y,s.y,r?.y)}function b0(e,t,s,r,o){return e-=t,e=Qc(e,1/s,r),o!==void 0&&(e=Qc(e,1/o,r)),e}function dO(e,t=0,s=1,r=.5,o,i=e,a=e){if(ir.test(t)&&(t=parseFloat(t),t=pn(a.min,a.max,t/100)-a.min),typeof t!="number")return;let l=pn(i.min,i.max,r);e===i&&(l-=t),e.min=b0(e.min,t,s,l,o),e.max=b0(e.max,t,s,l,o)}function y0(e,t,[s,r,o],i,a){dO(e,t[s],t[r],t[o],t.scale,i,a)}const uO=["x","scaleX","originX"],fO=["y","scaleY","originY"];function w0(e,t,s,r){y0(e.x,t,uO,s?s.x:void 0,r?r.x:void 0),y0(e.y,t,fO,s?s.y:void 0,r?r.y:void 0)}function j0(e){return e.translate===0&&e.scale===1}function jk(e){return j0(e.x)&&j0(e.y)}function k0(e,t){return e.min===t.min&&e.max===t.max}function mO(e,t){return k0(e.x,t.x)&&k0(e.y,t.y)}function N0(e,t){return Math.round(e.min)===Math.round(t.min)&&Math.round(e.max)===Math.round(t.max)}function kk(e,t){return N0(e.x,t.x)&&N0(e.y,t.y)}function S0(e){return ls(e.x)/ls(e.y)}function C0(e,t){return e.translate===t.translate&&e.scale===t.scale&&e.originPoint===t.originPoint}function Js(e){return[e("x"),e("y")]}function hO(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 pO=fp.length,I0=e=>typeof e=="string"?parseFloat(e):e,T0=e=>typeof e=="number"||ut.test(e);function xO(e,t,s,r,o,i){o?(e.opacity=pn(0,s.opacity??1,gO(r)),e.opacityExit=pn(t.opacity??1,0,vO(r))):i&&(e.opacity=pn(t.opacity??1,s.opacity??1,r));for(let a=0;a<pO;a++){const l=fp[a];let c=A0(t,l),u=A0(s,l);if(c===void 0&&u===void 0)continue;c||(c=0),u||(u=0),c===0||u===0||T0(c)===T0(u)?(e[l]=Math.max(pn(I0(c),I0(u),r),0),(ir.test(u)||ir.test(c))&&(e[l]+="%")):e[l]=u}(t.rotate||s.rotate)&&(e.rotate=pn(t.rotate||0,s.rotate||0,r))}function A0(e,t){return e[t]!==void 0?e[t]:e.borderRadius}const gO=Nk(0,.5,p1),vO=Nk(.5,.95,Os);function Nk(e,t,s){return r=>r<e?0:r>t?1:s(Ta(e,t,r))}function bO(e,t,s){const r=es(e)?e:pi(e);return r.start(cp("",r,t,s)),r.animation}function Ra(e,t,s,r={passive:!0}){return e.addEventListener(t,s,r),()=>e.removeEventListener(t,s,r)}const yO=(e,t)=>e.depth-t.depth;class wO{constructor(){this.children=[],this.isDirty=!1}add(t){Qh(this.children,t),this.isDirty=!0}remove(t){Hc(this.children,t),this.isDirty=!0}forEach(t){this.isDirty&&this.children.sort(yO),this.isDirty=!1,this.children.forEach(t)}}function jO(e,t){const s=as.now(),r=({timestamp:o})=>{const i=o-s;i>=t&&(to(r),e(i-t))};return xn.setup(r,!0),()=>to(r)}function fc(e){return es(e)?e.get():e}class kO{constructor(){this.members=[]}add(t){Qh(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&&(Hc(this.members,r),r.unmount())}t.scheduleRender()}remove(t){if(Hc(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 mc={hasAnimatedSinceResize:!0,hasEverUpdated:!1},Ou=["","X","Y","Z"],NO=1e3;let SO=0;function Lu(e,t,s,r){const{latestValues:o}=t;o[e]&&(s[e]=o[e],t.setStaticValue(e,0),r&&(r[e]=0))}function Sk(e){if(e.hasCheckedOptimisedAppear=!0,e.root===e)return;const{visualElement:t}=e.options;if(!t)return;const s=G1(t);if(window.MotionHasOptimisedAnimation(s,"transform")){const{layout:o,layoutId:i}=e.options;window.MotionCancelOptimisedAnimation(s,"transform",xn,!(o||i))}const{parent:r}=e;r&&!r.hasCheckedOptimisedAppear&&Sk(r)}function Ck({attachResizeListener:e,defaultParent:t,measureScroll:s,checkIsScrollRoot:r,resetTransform:o}){return class{constructor(a={},l=t?.()){this.id=SO++,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(TO),this.nodes.forEach(DO),this.nodes.forEach(OO),this.nodes.forEach(AO)},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 wO)}addEventListener(a,l){return this.eventHandlers.has(a)||this.eventHandlers.set(a,new Jh),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=pp(a)&&!A6(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;xn.read(()=>{m=window.innerWidth}),e(a,()=>{const p=window.innerWidth;p!==m&&(m=p,this.root.updateBlockedByResize=!0,d&&d(),d=jO(h,250),mc.hasAnimatedSinceResize&&(mc.hasAnimatedSinceResize=!1,this.nodes.forEach(M0)))})}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()||zO,{onLayoutAnimationStart:x,onLayoutAnimationComplete:y}=u.getProps(),j=!this.targetLayout||!kk(this.targetLayout,p),w=!m&&h;if(this.options.layoutRoot||this.resumeFrom||w||m&&(j||!this.currentAnimation)){this.resumeFrom&&(this.resumingFrom=this.resumeFrom,this.resumingFrom.resumingFrom=void 0);const b={...lp(g,"layout"),onPlay:x,onComplete:y};(u.shouldReduceMotion||this.options.layoutRoot)&&(b.delay=0,b.type=!1),this.startAnimation(b),this.setAnimationOrigin(d,w,b.path)}else m||M0(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(LO),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&&Sk(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(RO),this.nodes.forEach(E0);return}if(this.animationId<=this.animationCommitId){this.nodes.forEach(R0);return}this.animationCommitId=this.animationId,this.isUpdating?(this.isUpdating=!1,this.nodes.forEach(MO),this.nodes.forEach(PO),this.nodes.forEach(CO),this.nodes.forEach(IO)):this.nodes.forEach(R0),this.clearAllSnapshots();const l=as.now();Zn.delta=dr(0,1e3/60,l-Zn.timestamp),Zn.timestamp=l,Zn.isProcessing=!0,Iu.update.process(Zn),Iu.preRender.process(Zn),Iu.render.process(Zn),Zn.isProcessing=!1}didUpdate(){this.updateScheduled||(this.updateScheduled=!0,mp.read(this.scheduleUpdate))}clearAllSnapshots(){this.nodes.forEach(EO),this.sharedNodes.forEach(_O)}scheduleUpdateProjection(){this.projectionUpdateScheduled||(this.projectionUpdateScheduled=!0,xn.preRender(this.updateProjection,!1,!0))}scheduleCheckAfterUnmount(){xn.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=Fn()),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&&!jk(this.projectionDelta),c=this.getTransformTemplate(),u=c?c(this.latestValues,""):void 0,d=u!==this.prevTransformTemplateValue;a&&this.instance&&(l||yo(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)),$O(c),{animationId:this.root.animationId,measuredBox:l,layoutBox:c,latestValues:{},source:this.id}}measurePageBox(){const{visualElement:a}=this.options;if(!a)return Fn();const l=a.measureViewportBox();if(!(this.scroll?.wasRoot||this.path.some(VO))){const{scroll:u}=this.root;u&&(er(l.x,u.offset.x),er(l.y,u.offset.y))}return l}removeElementScroll(a){const l=Fn();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),er(l.x,d.offset.x),er(l.y,d.offset.y))}return l}applyTransform(a,l=!1,c){const u=c||Fn();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&&(er(u.x,-m.scroll.offset.x),er(u.y,-m.scroll.offset.y)),yo(m.latestValues)&&uc(u,m.latestValues,m.layout?.layoutBox)}return yo(this.latestValues)&&uc(u,this.latestValues,this.layout?.layoutBox),u}removeTransform(a){const l=Fn();Fs(l,a);for(let c=0;c<this.path.length;c++){const u=this.path[c];if(!yo(u.latestValues))continue;let d;u.instance&&(um(u.latestValues)&&u.updateSnapshot(),d=Fn(),Fs(d,u.measurePageBox())),w0(l,u.latestValues,u.snapshot?.layoutBox,d)}return yo(this.latestValues)&&w0(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=Fn(),this.targetWithTransforms=Fn()),this.relativeTarget&&this.relativeTargetOrigin&&this.relativeParent&&this.relativeParent.target?(this.forceRelativeParentToResolveTarget(),cO(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),ck(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||um(this.parent.latestValues)||lk(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=Fn(),this.relativeTargetOrigin=Fn(),Jc(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;F6(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=Fn());const{target:p}=a;if(!p){this.prevProjectionDelta&&(this.createProjectionDeltas(),this.scheduleRender());return}!this.projectionDelta||!this.prevProjectionDelta?this.createProjectionDeltas():(p0(this.prevProjectionDelta.x,this.projectionDelta.x),p0(this.prevProjectionDelta.y,this.projectionDelta.y)),aa(this.projectionDelta,this.layoutCorrected,p,this.latestValues),(this.treeScale.x!==m||this.treeScale.y!==h||!C0(this.projectionDelta.x,this.prevProjectionDelta.x)||!C0(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=ei(),this.projectionDelta=ei(),this.projectionDeltaWithTransform=ei()}setAnimationOrigin(a,l=!1,c){const u=this.snapshot,d=u?u.latestValues:{},m={...this.latestValues},h=ei();(!this.relativeParent||!this.relativeParent.options.layoutRoot)&&(this.relativeTarget=this.relativeTargetOrigin=void 0),this.attemptToResolveRelativeTarget=!l;const p=Fn(),g=u?u.source:void 0,x=this.layout?this.layout.source:void 0,y=g!==x,j=this.getStack(),w=!j||j.members.length<=1,b=!!(y&&!w&&this.options.crossfade===!0&&!this.path.some(FO));this.animationProgress=0;let N;const C=c?.interpolateProjection(a);this.mixTargetDelta=E=>{const T=E/1e3,k=C?.(T);k?(h.x.translate=k.x,h.x.scale=pn(a.x.scale,1,T),h.x.origin=a.x.origin,h.x.originPoint=a.x.originPoint,h.y.translate=k.y,h.y.scale=pn(a.y.scale,1,T),h.y.origin=a.y.origin,h.y.originPoint=a.y.originPoint):(P0(h.x,a.x,T),P0(h.y,a.y,T)),this.setTargetDelta(h),this.relativeTarget&&this.relativeTargetOrigin&&this.layout&&this.relativeParent&&this.relativeParent.layout&&(Jc(p,this.layout.layoutBox,this.relativeParent.layout.layoutBox,this.options.layoutAnchor||void 0),BO(this.relativeTarget,this.relativeTargetOrigin,p,T),N&&mO(this.relativeTarget,N)&&(this.isProjectionDirty=!1),N||(N=Fn()),Fs(N,this.relativeTarget)),y&&(this.animationValues=m,xO(m,d,this.latestValues,T,b,w)),k&&k.rotate!==void 0&&(this.animationValues||(this.animationValues=m),this.animationValues.pathRotation=k.rotate),this.root.scheduleUpdateProjection(),this.scheduleRender(),this.animationProgress=T},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=xn.update(()=>{mc.hasAnimatedSinceResize=!0,this.motionValue||(this.motionValue=pi(0)),this.motionValue.jump(0,!1),this.currentAnimation=bO(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(NO),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&&Ik(this.options.animationType,this.layout.layoutBox,u.layoutBox)){c=this.target||Fn();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),uc(l,d),aa(this.projectionDeltaWithTransform,this.layoutCorrected,l,d)}}registerSharedNode(a,l){this.sharedNodes.has(a)||this.sharedNodes.set(a,new kO),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&&Lu("z",a,u,this.animationValues);for(let d=0;d<Ou.length;d++)Lu(`rotate${Ou[d]}`,a,u,this.animationValues),Lu(`skew${Ou[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=fc(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=fc(l?.pointerEvents)||""),this.hasProjected&&!yo(this.latestValues)&&(a.transform=c?c({},""):"none",this.hasProjected=!1);return}a.visibility="";const d=u.animationValues||u.latestValues;this.applyTransformsToTarget();let m=hO(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 mm){if(d[g]===void 0)continue;const{correct:x,applyTo:y,isCSSVariable:j}=mm[g],w=m==="none"?d[g]:x(d[g],u);if(y){const b=y.length;for(let N=0;N<b;N++)a[y[N]]=w}else j?this.options.visualElement.renderState.vars[g]=w:a[g]=w}this.options.layoutId&&(a.pointerEvents=u===this?fc(l?.pointerEvents)||"":"none")}clearSnapshot(){this.resumeFrom=this.snapshot=void 0}resetTree(){this.root.nodes.forEach(a=>a.currentAnimation?.stop()),this.root.nodes.forEach(E0),this.root.sharedNodes.clear()}}}function CO(e){e.updateLayout()}function IO(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")Js(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";hm(i?t.measuredBox[d]:t.layoutBox[d],s[d])}else Ik(o,t.layoutBox,s)&&Js(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=ei();aa(a,s,t.layoutBox);const l=ei();i?aa(l,e.applyTransform(r,!0),t.measuredBox):aa(l,s,t.layoutBox);const c=!jk(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=Fn();Jc(g,t.layoutBox,m.layoutBox,p);const x=Fn();Jc(x,s,h.layoutBox,p),kk(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 TO(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 AO(e){e.isProjectionDirty=e.isSharedProjectionDirty=e.isTransformDirty=!1}function EO(e){e.clearSnapshot()}function E0(e){e.clearMeasurements()}function RO(e){e.isLayoutDirty=!0,e.updateLayout()}function R0(e){e.isLayoutDirty=!1}function MO(e){e.isAnimationBlocked&&e.layout&&!e.isLayoutDirty&&(e.snapshot=e.layout,e.isLayoutDirty=!0)}function PO(e){const{visualElement:t}=e.options;t&&t.getProps().onBeforeLayoutMeasure&&t.notify("BeforeLayoutMeasure"),e.resetTransform()}function M0(e){e.finishAnimation(),e.targetDelta=e.relativeTarget=e.target=void 0,e.isProjectionDirty=!0}function DO(e){e.resolveTargetDelta()}function OO(e){e.calcProjection()}function LO(e){e.resetSkewAndRotation()}function _O(e){e.removeLeadSnapshot()}function P0(e,t,s){e.translate=pn(t.translate,0,s),e.scale=pn(t.scale,1,s),e.origin=t.origin,e.originPoint=t.originPoint}function D0(e,t,s,r){e.min=pn(t.min,s.min,r),e.max=pn(t.max,s.max,r)}function BO(e,t,s,r){D0(e.x,t.x,s.x,r),D0(e.y,t.y,s.y,r)}function FO(e){return e.animationValues&&e.animationValues.opacityExit!==void 0}const zO={duration:.45,ease:[.4,0,.1,1]},O0=e=>typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().includes(e),L0=O0("applewebkit/")&&!O0("chrome/")?Math.round:Os;function _0(e){e.min=L0(e.min),e.max=L0(e.max)}function $O(e){_0(e.x),_0(e.y)}function Ik(e,t,s){return e==="position"||e==="preserve-aspect"&&!lO(S0(t),S0(s),.2)}function VO(e){return e!==e.root&&e.scroll?.wasRoot}const HO=Ck({attachResizeListener:(e,t)=>Ra(e,"resize",t),measureScroll:()=>({x:document.documentElement.scrollLeft||document.body?.scrollLeft||0,y:document.documentElement.scrollTop||document.body?.scrollTop||0}),checkIsScrollRoot:()=>!0}),_u={current:void 0},Tk=Ck({measureScroll:e=>({x:e.scrollLeft,y:e.scrollTop}),defaultParent:()=>{if(!_u.current){const e=new HO({});e.mount(window),e.setOptions({layoutScroll:!0}),_u.current=e}return _u.current},resetTransform:(e,t)=>{e.style.transform=t!==void 0?t:"none"},checkIsScrollRoot:e=>window.getComputedStyle(e).position==="fixed"}),wp=f.createContext({transformPagePoint:e=>e,isStatic:!1,reducedMotion:"never"});function B0(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function WO(...e){return t=>{let s=!1;const r=e.map(o=>{const i=B0(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():B0(e[o],null)}}}}function UO(...e){return f.useCallback(WO(...e),e)}class GO extends f.Component{getSnapshotBeforeUpdate(t){const s=this.props.childRef.current;if(ic(s)&&t.isPresent&&!this.props.isPresent&&this.props.pop!==!1){const r=s.offsetParent,o=ic(r)&&r.offsetWidth||0,i=ic(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 KO({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(wp),d=i!==!1?e.props?.ref??e?.ref:void 0,m=UO(l,d);return f.useInsertionEffect(()=>{const{width:h,height:p,top:g,left:x,right:y,bottom:j,direction:w}=c.current;if(t||i===!1||!l.current||!h||!p)return;const b=w==="rtl",N=s==="left"?b?`right: ${y}`:`left: ${x}`:b?`left: ${x}`:`right: ${y}`,C=r==="bottom"?`bottom: ${j}`:`top: ${g}`;l.current.dataset.motionPopId=a;const E=document.createElement("style");u&&(E.nonce=u);const T=o??document.head;return T.appendChild(E),E.sheet&&E.sheet.insertRule(`
7
- [data-motion-pop-id="${a}"] {
8
- position: absolute !important;
9
- width: ${h}px !important;
10
- height: ${p}px !important;
11
- ${N}px !important;
12
- ${C}px !important;
13
- }
14
- `),()=>{l.current?.removeAttribute("data-motion-pop-id"),T.contains(E)&&T.removeChild(E)}},[t]),n.jsx(GO,{isPresent:t,childRef:l,sizeRef:c,pop:i,children:i===!1?e:f.cloneElement(e,{ref:m})})}const qO=({children:e,initial:t,isPresent:s,onExitComplete:r,custom:o,presenceAffectsLayout:i,mode:a,anchorX:l,anchorY:c,root:u})=>{const d=Xh(YO),m=f.useId(),h=f.useRef(s),p=f.useRef(r);Vc(()=>{h.current=s,p.current=r});let g=!0,x=f.useMemo(()=>(g=!1,{id:m,initial:t,isPresent:s,custom:o,onExitComplete:y=>{d.set(y,!0);for(const j of d.values())if(!j)return;r&&r()},register:y=>(d.set(y,!1),()=>{d.delete(y),!h.current&&!d.size&&p.current?.()})}),[s,d,r]);return i&&g&&(x={...x}),f.useMemo(()=>{d.forEach((y,j)=>d.set(j,!1))},[s]),f.useEffect(()=>{!s&&!d.size&&r&&r()},[s]),e=n.jsx(KO,{pop:a==="popLayout",isPresent:s,anchorX:l,anchorY:c,root:u,children:e}),n.jsx(_d.Provider,{value:x,children:e})};function YO(){return new Map}function Ak(e=!0){const t=f.useContext(_d);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 Al=e=>e.key||"";function F0(e){const t=[];return f.Children.forEach(e,s=>{f.isValidElement(s)&&t.push(s)}),t}const la=({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]=Ak(a),h=f.useMemo(()=>F0(e),[e]),p=a&&!d?[]:h.map(Al),g=f.useRef(!0),x=f.useRef(h),y=Xh(()=>new Map),j=f.useRef(new Set),[w,b]=f.useState(h),[N,C]=f.useState(h);Vc(()=>{a&&!d&&!N.length&&m?.()},[d,a,N.length,m]),Vc(()=>{g.current=!1,x.current=h;for(let k=0;k<N.length;k++){const L=Al(N[k]);p.includes(L)?(y.delete(L),j.current.delete(L)):y.get(L)!==!0&&y.set(L,!1)}},[N,p.length,p.join("-")]);const E=[];if(h!==w){let k=[...h],L=0;for(const F of N){const A=p.indexOf(Al(F));A===-1?(k.splice(L++,0,F),E.push(F)):L=A+E.length+1}return i==="wait"&&E.length&&(k=E),C(F0(k)),b(h),null}const{forceRender:T}=f.useContext(Yh);return n.jsx(n.Fragment,{children:N.map(k=>{const L=Al(k),F=a&&!d?!1:h===N||p.includes(L),A=()=>{if(j.current.has(L))return;if(y.has(L))j.current.add(L),y.set(L,!0);else return;let D=!0;y.forEach(M=>{M||(D=!1)}),D&&(T?.(),C(x.current),a&&m?.(),r&&r())};return n.jsx(qO,{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)})})},Ek=f.createContext({strict:!1}),z0={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 $0=!1;function XO(){if($0)return;const e={};for(const t in z0)e[t]={isEnabled:s=>z0[t].some(r=>!!s[r])};ok(e),$0=!0}function Rk(){return XO(),O6()}function QO(e){const t=Rk();for(const s in e)t[s]={...t[s],...e[s]};ok(t)}const Vd=f.createContext({});function JO(e,t){if($d(e)){const{initial:s,animate:r}=e;return{initial:s===!1||Ea(s)?s:void 0,animate:Ea(r)?r:void 0}}return e.inherit!==!1?t:{}}function ZO(e){const{initial:t,animate:s}=JO(e,f.useContext(Vd));return f.useMemo(()=>({initial:t,animate:s}),[V0(t),V0(s)])}function V0(e){return Array.isArray(e)?e.join(" "):e}const jp=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function Mk(e,t,s){for(const r in t)!es(t[r])&&!fk(r,s)&&(e[r]=t[r])}function eL({transformTemplate:e},t){return f.useMemo(()=>{const s=jp();return bp(s,t,e),Object.assign({},s.vars,s.style)},[t])}function tL(e,t){const s=e.style||{},r={};return Mk(r,s,e),Object.assign(r,eL(e,t)),r}function nL(e,t){const s={},r=tL(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 Pk=()=>({...jp(),attrs:{}});function sL(e,t,s,r){const o=f.useMemo(()=>{const i=Pk();return hk(i,t,xk(r),e.transformTemplate,e.style),{...i.attrs,style:{...i.style}}},[t]);if(e.style){const i={};Mk(i,e.style,e),o.style={...i,...o.style}}return o}const rL=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 Zc(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||rL.has(e)}function oL(e,t){return e.startsWith("on")?!Zc(e):t?.(e)??!Zc(e)}function iL(e,t,s,r){const o={};for(const i in e)i==="values"&&typeof e.values=="object"||es(e[i])||(oL(i,r)||s===!0&&Zc(i)||!t&&!Zc(i)||e.draggable&&i.startsWith("onDrag"))&&(o[i]=e[i]);return o}const aL=["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 kp(e){return typeof e!="string"||e.includes("-")?!1:!!(aL.indexOf(e)>-1||/[A-Z]/u.test(e))}function lL(e,t,s,{latestValues:r},o,i=!1,a,l){const u=(a??kp(e)?sL:nL)(t,r,o,e),d=iL(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 cL({scrapeMotionValuesFromProps:e,createRenderState:t},s,r,o){return{latestValues:dL(s,r,o,e),renderState:t()}}function dL(e,t,s,r){const o={},i=r(e,{});for(const h in i)o[h]=fc(i[h]);let{initial:a,animate:l}=e;const c=$d(e),u=sk(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"&&!zd(m)){const h=Array.isArray(m)?m:[m];for(let p=0;p<h.length;p++){const g=dp(e,h[p]);if(g){const{transitionEnd:x,transition:y,...j}=g;for(const w in j){let b=j[w];if(Array.isArray(b)){const N=d?b.length-1:0;b=b[N]}b!==null&&(o[w]=b)}for(const w in x)o[w]=x[w]}}}return o}const Dk=e=>(t,s)=>{const r=f.useContext(Vd),o=f.useContext(_d),i=()=>cL(e,t,r,o);return s?i():Xh(i)},uL=Dk({scrapeMotionValuesFromProps:yp,createRenderState:jp}),fL=Dk({scrapeMotionValuesFromProps:gk,createRenderState:Pk}),mL=Symbol.for("motionComponentSymbol");function hL(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 Ok=f.createContext({});function Yo(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function pL(e,t,s,r,o,i){const{visualElement:a}=f.useContext(Vd),l=f.useContext(Ek),c=f.useContext(_d),u=f.useContext(wp),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(Ok);g&&!g.projection&&o&&(g.type==="html"||g.type==="svg")&&xL(h.current,s,o,x);const y=f.useRef(!1);f.useInsertionEffect(()=>{g&&y.current&&g.update(s,c)});const j=s[U1],w=f.useRef(!!j&&typeof window<"u"&&!window.MotionHandoffIsComplete?.(j)&&window.MotionHasOptimisedAnimation?.(j));return Vc(()=>{p.current=!0,g&&(y.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?.(j)}),w.current=!1),g.enteringChildren=void 0)}),g}function xL(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:Lk(e.parent)),e.projection.setOptions({layoutId:o,layout:i,alwaysMeasureLayout:!!a||l&&Yo(l),visualElement:e,animationType:typeof i=="string"?i:"both",initialPromotionConfig:r,crossfade:m,layoutScroll:c,layoutRoot:u,layoutAnchor:d})}function Lk(e){if(e)return e.options.allowProjection!==!1?e.projection:Lk(e.parent)}function Bu(e,{forwardMotionProps:t=!1,type:s}={},r,o){r&&QO(r);const i=s?s==="svg":kp(e),a=i?fL:uL;function l(u,d){let m;const h={...f.useContext(wp),...u,layoutId:gL(u)},{isStatic:p,isValidProp:g}=h,x=ZO(u),y=a(u,p);if(!p&&typeof window<"u"){vL();const j=bL(h);m=j.MeasureLayout,x.visualElement=pL(e,y,h,o,j.ProjectionNode,i)}return n.jsxs(Vd.Provider,{value:x,children:[m&&x.visualElement?n.jsx(m,{visualElement:x.visualElement,...h}):null,lL(e,u,hL(y,x.visualElement,d),y,p,t,i,g)]})}l.displayName=`motion.${typeof e=="string"?e:`create(${e.displayName??e.name??""})`}`;const c=f.forwardRef(l);return c[mL]=e,c}function gL({layoutId:e}){const t=f.useContext(Yh).id;return t&&e!==void 0?t+"-"+e:e}function vL(e,t){f.useContext(Ek).strict}function bL(e){const t=Rk(),{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 yL(e,t){if(typeof Proxy>"u")return Bu;const s=new Map,r=(i,a)=>Bu(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,Bu(a,void 0,e,t)),s.get(a))})}const wL=(e,t)=>t.isSVG??kp(e)?new Q6(t):new G6(t,{allowProjection:e!==f.Fragment});class jL extends oo{constructor(t){super(t),t.animationState||(t.animationState=nO(t))}updateAnimationControlsSubscription(){const{animate:t}=this.node.getProps();zd(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 kL=0;class NL extends oo{constructor(){super(...arguments),this.id=kL++,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=To(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 SL={animation:{Feature:jL},exit:{Feature:NL}};function al(e){return{point:{x:e.pageX,y:e.pageY}}}const CL=e=>t=>hp(t)&&e(t,al(t));function ca(e,t,s,r){return Ra(e,t,CL(s),r)}const _k=({current:e})=>e?e.ownerDocument.defaultView:null,H0=(e,t)=>Math.abs(e-t);function IL(e,t){const s=H0(e.x,t.x),r=H0(e.y,t.y);return Math.sqrt(s**2+r**2)}const W0=new Set(["auto","scroll"]);class Bk{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=El(this.lastRawMoveEventInfo,this.transformPagePoint));const g=Fu(this.lastMoveEventInfo,this.history),x=this.startEvent!==null,y=IL(g.offset,{x:0,y:0})>=this.distanceThreshold;if(!x&&!y)return;const{point:j}=g,{timestamp:w}=Zn;this.history.push({...j,timestamp:w});const{onStart:b,onMove:N}=this.handlers;x||(b&&b(this.lastMoveEvent,g),this.startEvent=this.lastMoveEvent),N&&N(this.lastMoveEvent,g)},this.handlePointerMove=(g,x)=>{this.lastMoveEvent=g,this.lastRawMoveEventInfo=x,this.lastMoveEventInfo=El(x,this.transformPagePoint),xn.update(this.updatePoint,!0)},this.handlePointerUp=(g,x)=>{this.end();const{onEnd:y,onSessionEnd:j,resumeAnimation:w}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&w&&w(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const b=Fu(g.type==="pointercancel"?this.lastMoveEventInfo:El(x,this.transformPagePoint),this.history);this.startEvent&&y&&y(g,b),j&&j(g,b)},!hp(t))return;this.dragSnapToOrigin=i,this.handlers=s,this.transformPagePoint=r,this.distanceThreshold=a,this.contextWindow=o||window;const c=al(t),u=El(c,this.transformPagePoint),{point:d}=u,{timestamp:m}=Zn;this.history=[{...d,timestamp:m}];const{onSessionStart:h}=s;h&&h(t,Fu(u,this.history));const p={passive:!0,capture:!0};this.removeListeners=rl(ca(this.contextWindow,"pointermove",this.handlePointerMove,p),ca(this.contextWindow,"pointerup",this.handlePointerUp,p),ca(this.contextWindow,"pointercancel",this.handlePointerUp,p)),l&&this.startScrollTracking(l)}startScrollTracking(t){let s=t.parentElement;for(;s;){const r=getComputedStyle(s);(W0.has(r.overflowX)||W0.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),xn.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 El(e,t){return t?{point:t(e.point)}:e}function U0(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Fu({point:e},t){return{point:e,delta:U0(e,Fk(t)),offset:U0(e,TL(t)),velocity:AL(t,.1)}}function TL(e){return e[0]}function Fk(e){return e[e.length-1]}function AL(e,t){if(e.length<2)return{x:0,y:0};let s=e.length-1,r=null;const o=Fk(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=Ts(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 EL(e,{min:t,max:s},r){return t!==void 0&&e<t?e=r?pn(t,e,r.min):Math.max(e,t):s!==void 0&&e>s&&(e=r?pn(s,e,r.max):Math.min(e,s)),e}function G0(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 RL(e,{top:t,left:s,bottom:r,right:o}){return{x:G0(e.x,s,o),y:G0(e.y,t,r)}}function K0(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 ML(e,t){return{x:K0(e.x,t.x),y:K0(e.y,t.y)}}function PL(e,t){let s=.5;const r=ls(e),o=ls(t);return o>r?s=Ta(t.min,t.max-r,e.min):r>o&&(s=Ta(e.min,e.max-o,t.min)),dr(0,1,s)}function DL(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 pm=.35;function OL(e=pm){return e===!1?e=0:e===!0&&(e=pm),{x:q0(e,"left","right"),y:q0(e,"top","bottom")}}function q0(e,t,s){return{min:Y0(e,t),max:Y0(e,s)}}function Y0(e,t){return typeof e=="number"?e:e[t]||0}const LL=new WeakMap;class _L{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=Fn(),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(al(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=f6(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),Js(j=>{let w=this.getAxisMotionValue(j).get()||0;if(ir.test(w)){const{projection:b}=this.visualElement;if(b&&b.layout){const N=b.layout.layoutBox[j];N&&(w=ls(N)*(parseFloat(w)/100))}}this.originPoint[j]=w}),x&&xn.update(()=>x(m,h),!1,!0),im(this.visualElement,"transform");const{animationState:y}=this.visualElement;y&&y.setActive("whileDrag",!0)},l=(m,h)=>{this.latestPointerEvent=m,this.latestPanInfo=h;const{dragPropagation:p,dragDirectionLock:g,onDirectionLock:x,onDrag:y}=this.getProps();if(!p&&!this.openDragLock)return;const{offset:j}=h;if(g&&this.currentDirection===null){this.currentDirection=FL(j),this.currentDirection!==null&&x&&x(this.currentDirection);return}this.updateAxis("x",h.point,j),this.updateAxis("y",h.point,j),this.visualElement.render(),y&&xn.update(()=>y(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 Bk(t,{onSessionStart:i,onStart:a,onMove:l,onSessionEnd:c,resumeAnimation:u},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:d,distanceThreshold:r,contextWindow:_k(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&&xn.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||!Rl(t,o,this.currentDirection))return;const i=this.getAxisMotionValue(t);let a=this.originPoint[t]+r[t];this.constraints&&this.constraints[t]&&(a=EL(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&&Yo(t)?this.constraints||(this.constraints=this.resolveRefConstraints()):t&&r?this.constraints=RL(r.layoutBox,t):this.constraints=!1,this.elastic=OL(s),o!==this.constraints&&!Yo(t)&&r&&this.constraints&&!this.hasMutatedConstraints&&Js(i=>{this.constraints!==!1&&this.getAxisMotionValue(i)&&(this.constraints[i]=DL(r.layoutBox[i],this.constraints[i]))})}resolveRefConstraints(){const{dragConstraints:t,onMeasureDragConstraints:s}=this.getProps();if(!t||!Yo(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=z6(r,o.root,this.visualElement.getTransformPagePoint());let a=ML(o.layout.layoutBox,i);if(s){const l=s(_6(a));this.hasMutatedConstraints=!!l,l&&(a=ak(l))}return a}startAnimation(t){const{drag:s,dragMomentum:r,dragElastic:o,dragTransition:i,dragSnapToOrigin:a,onDragTransitionEnd:l}=this.getProps(),c=this.constraints||{},u=Js(d=>{if(!Rl(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 im(this.visualElement,t),r.start(cp(t,r,0,s,this.visualElement,!1))}stopAnimation(){Js(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){Js(s=>{const{drag:r}=this.getProps();if(!Rl(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]-pn(a,l,.5)+c)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:t,dragConstraints:s}=this.getProps(),{projection:r}=this.visualElement;if(!Yo(s)||!r||!this.constraints)return;this.stopAnimation();const o={x:0,y:0};Js(a=>{const l=this.getAxisMotionValue(a);if(l&&this.constraints!==!1){const c=l.get();o[a]=PL({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(),Js(a=>{if(!Rl(a,t,null))return;const l=this.getAxisMotionValue(a),{min:c,max:u}=this.constraints[a];l.set(pn(c,u,o[a]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;LL.set(this.visualElement,this);const t=this.visualElement.current,s=ca(t,"pointerdown",u=>{const{drag:d,dragListener:m=!0}=this.getProps(),h=u.target,p=h!==t&&v6(h);d&&m&&!p&&this.start(u)});let r;const o=()=>{const{dragConstraints:u}=this.getProps();Yo(u)&&u.current&&(this.constraints=this.resolveRefConstraints(),r||(r=BL(t,u.current,()=>this.scalePositionWithinConstraints())))},{projection:i}=this.visualElement,a=i.addEventListener("measure",o);i&&!i.layout&&(i.root&&i.root.updateScroll(),i.updateLayout()),xn.read(o);const l=Ra(window,"resize",()=>this.scalePositionWithinConstraints()),c=i.addEventListener("didUpdate",(({delta:u,hasLayoutChanged:d})=>{this.isDragging&&d&&(Js(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=pm,dragMomentum:l=!0}=t;return{...t,drag:s,dragDirectionLock:r,dragPropagation:o,dragConstraints:i,dragElastic:a,dragMomentum:l}}}function X0(e){let t=!0;return()=>{if(t){t=!1;return}e()}}function BL(e,t,s){const r=s0(e,X0(s)),o=s0(t,X0(s));return()=>{r(),o()}}function Rl(e,t,s){return(t===!0||t===e)&&(s===null||s===e)}function FL(e,t=10){let s=null;return Math.abs(e.y)>t?s="y":Math.abs(e.x)>t&&(s="x"),s}class zL extends oo{constructor(t){super(t),this.removeGroupControls=Os,this.removeListeners=Os,this.controls=new _L(t)}mount(){const{dragControls:t}=this.node.getProps();t&&(this.removeGroupControls=t.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Os}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 zu=e=>(t,s)=>{e&&xn.update(()=>e(t,s),!1,!0)};class $L extends oo{constructor(){super(...arguments),this.removePointerDownListener=Os}onPointerDown(t){this.session=new Bk(t,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:_k(this.node)})}createPanHandlers(){const{onPanSessionStart:t,onPanStart:s,onPan:r,onPanEnd:o}=this.node.getProps();return{onSessionStart:zu(t),onStart:zu(s),onMove:zu(r),onEnd:(i,a)=>{delete this.session,o&&xn.postRender(()=>o(i,a))}}}mount(){this.removePointerDownListener=ca(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 $u=!1;class VL 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),$u&&i.root.didUpdate(),i.addEventListener("animationComplete",()=>{this.safeToRemove()}),i.setOptions({...i.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),mc.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}),$u=!0,o||t.layoutDependency!==s||s===void 0||t.isPresent!==i?a.willUpdate():this.safeToRemove(),t.isPresent!==i&&(i?a.promote():a.relegate()||xn.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(),mp.postRender(()=>{!r.currentAnimation&&r.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:t,layoutGroup:s,switchLayoutGroup:r}=this.props,{projection:o}=t;$u=!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 zk(e){const[t,s]=Ak(),r=f.useContext(Yh);return n.jsx(VL,{...e,layoutGroup:r,switchLayoutGroup:f.useContext(Ok),isPresent:t,safeToRemove:s})}const HL={pan:{Feature:$L},drag:{Feature:zL,ProjectionNode:Tk,MeasureLayout:zk}};function Q0(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&&xn.postRender(()=>i(t,al(t)))}class WL extends oo{mount(){const{current:t}=this.node;t&&(this.unmount=h6(t,(s,r)=>(Q0(this.node,r,"Start"),o=>Q0(this.node,o,"End"))))}unmount(){}}class UL extends oo{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=rl(Ra(this.node.current,"focus",()=>this.onFocus()),Ra(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function J0(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&&xn.postRender(()=>i(t,al(t)))}class GL extends oo{mount(){const{current:t}=this.node;if(!t)return;const{globalTapTarget:s,propagate:r}=this.node.props;this.unmount=y6(t,(o,i)=>(J0(this.node,i,"Start"),(a,{success:l})=>J0(this.node,a,l?"End":"Cancel")),{useGlobalTarget:s,stopPropagation:r?.tap===!1})}unmount(){}}const xm=new WeakMap,Vu=new WeakMap,KL=e=>{const t=xm.get(e.target);t&&t(e)},qL=e=>{e.forEach(KL)};function YL({root:e,...t}){const s=e||document;Vu.has(s)||Vu.set(s,{});const r=Vu.get(s),o=JSON.stringify(t);return r[o]||(r[o]=new IntersectionObserver(qL,{root:e,...t})),r[o]}function XL(e,t,s){const r=YL(t);return xm.set(e,s),r.observe(e),()=>{xm.delete(e),r.unobserve(e)}}const QL={some:0,all:1};class JL extends oo{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:QL[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=XL(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(ZL(t,s))&&this.startObserver()}unmount(){this.stopObserver?.(),this.hasEnteredView=!1,this.isInView=!1}}function ZL({viewport:e={}},{viewport:t={}}={}){return s=>e[s]!==t[s]}const e4={inView:{Feature:JL},tap:{Feature:GL},focus:{Feature:UL},hover:{Feature:WL}},t4={layout:{ProjectionNode:Tk,MeasureLayout:zk}},n4={...SL,...e4,...HL,...t4},ks=yL(n4,wL);function s4(){!vp.current&&rk();const[e]=f.useState(Yc.current);return e}const r4=[["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"}]],$k=Ke("activity",r4);const o4=[["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"}]],Np=Ke("alarm-clock",o4);const i4=[["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"}]],Ma=Ke("archive-restore",i4);const a4=[["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"}]],ar=Ke("archive",a4);const l4=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],c4=Ke("arrow-down-to-line",l4);const d4=[["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"}]],u4=Ke("arrow-right-left",d4);const f4=[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]],Ti=Ke("arrow-up-right",f4);const m4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M4.929 4.929 19.07 19.071",key:"196cmz"}]],h4=Ke("ban",m4);const p4=[["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"}]],ed=Ke("bell-off",p4);const x4=[["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"}]],g4=Ke("bell",x4);const v4=[["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"}]],b4=Ke("bookmark-plus",v4);const y4=[["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"}]],Vk=Ke("bug",y4);const w4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]],j4=Ke("circle-dot",w4);const k4=[["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"}]],N4=Ke("circle-play",k4);const S4=[["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"}]],C4=Ke("circle-question-mark",S4);const I4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],T4=Ke("circle-stop",I4);const A4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Sp=Ke("circle",A4);const E4=[["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"}]],Cp=Ke("clipboard-check",E4);const R4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],Hd=Ke("clock",R4);const M4=[["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"}]],P4=Ke("code-xml",M4);const D4=[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]],O4=Ke("code",D4);const L4=[["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"}]],_4=Ke("coins",L4);const B4=[["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"}]],F4=Ke("compass",B4);const z4=[["path",{d:"m15 10 5 5-5 5",key:"qqa56n"}],["path",{d:"M4 4v7a4 4 0 0 0 4 4h12",key:"z08zvw"}]],$4=Ke("corner-down-right",z4);const V4=[["path",{d:"M14 9 9 4 4 9",key:"1af5af"}],["path",{d:"M20 20h-7a4 4 0 0 1-4-4V4",key:"1blwi3"}]],H4=Ke("corner-left-up",V4);const W4=[["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"}]],Hk=Ke("cpu",W4);const U4=[["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"}]],G4=Ke("database",U4);const K4=[["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"}]],ll=Ke("ellipsis",K4);const q4=[["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"}]],Y4=Ke("file-pen",q4);const X4=[["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"}]],Q4=Ke("file-plus",X4);const J4=[["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"}]],Z4=Ke("file",J4);const e_=[["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"}]],t_=Ke("fold-horizontal",e_);const n_=[["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"}]],s_=Ke("folder-git-2",n_);const r_=[["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"}]],Wk=Ke("folder-input",r_);const o_=[["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"}]],gm=Ke("folder-plus",o_);const i_=[["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"}]],Wd=Ke("folder",i_);const a_=[["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"}]],vm=Ke("folders",a_);const l_=[["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"}]],c_=Ke("funnel",l_);const d_=[["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"}]],u_=Ke("git-branch-plus",d_);const f_=[["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=Ke("git-branch",f_);const m_=[["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"}]],h_=Ke("git-compare",m_);const p_=[["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"}]],x_=Ke("git-merge",p_);const g_=[["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"}]],v_=Ke("git-pull-request",g_);const b_=[["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"}]],Z0=Ke("hand",b_);const y_=[["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"}]],da=Ke("hourglass",y_);const w_=[["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"}]],ev=Ke("house",w_);const j_=[["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"}]],td=Ke("image-off",j_);const k_=[["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"}]],N_=Ke("images",k_);const S_=[["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"}]],Ip=Ke("inbox",S_);const C_=[["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"}]],Uk=Ke("list",C_);const I_=[["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"}]],T_=Ke("mail",I_);const A_=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],E_=Ke("menu",A_);const R_=[["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"}]],bm=Ke("message-circle",R_);const M_=[["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=Ke("message-square-plus",M_);const P_=[["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"}]],D_=Ke("message-square",P_);const O_=[["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"}]],L_=Ke("package-minus",O_);const __=[["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"}]],Tp=Ke("panel-left-close",__);const B_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],Gk=Ke("panel-left",B_);const F_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],z_=Ke("panel-right",F_);const $_=[["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"}]],Kk=Ke("pause",$_);const V_=[["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"}]],nd=Ke("pin-off",V_);const H_=[["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"}]],Ns=Ke("pin",H_);const W_=[["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"}]],U_=Ke("repeat",W_);const G_=[["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"}]],Ud=Ke("send",G_);const K_=[["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"}]],q_=Ke("sliders-horizontal",K_);const Y_=[["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"}]],X_=Ke("square-dashed",Y_);const Q_=[["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"}]],J_=Ke("square-pen",Q_);const Z_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]],qk=Ke("square-slash",Z_);const eB=[["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"}]],tB=Ke("square-x",eB);const nB=[["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"}]],sB=Ke("tag",nB);const rB=[["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"}]],Ai=Ke("target",rB);const oB=[["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"}]],Yk=Ke("text-search",oB);const iB=[["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"}]],Pa=Ke("undo-2",iB);const aB=[["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"}]],lB=Ke("unfold-horizontal",aB);const cB=[["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"}]],dB=Ke("unplug",cB);const uB=[["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"}]],fB=Ke("user-minus",uB);const mB=[["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"}]],Da=Ke("user-plus",mB);const hB=[["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"}]],pB=Ke("user-round-check",hB);const xB=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],Ap=Ke("user-round",xB);const gB=[["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"}]],vB=Ke("wallet",gB),Hu=(e,t)=>e.length>t?`${e.slice(0,t)}…`:e;function bB(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:Hu(r,16e3)};if(o!==void 0&&(c.rewrittenCommand=Hu(o,16e3)),l!==void 0&&(c.reason=Hu(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}const yB=15e3;function wB(e){if(e.length===0)return;const t="0 0, 100% 0, 100% 100%, 0 100%, 0 0",s=e.map(r=>`${jB(r).map(([o,i])=>`${nv(o)}px ${nv(i)}px`).join(", ")}, 0 0`);return`polygon(evenodd, ${[t,...s].join(", ")})`}const tv=6,nv=e=>Math.round(e*100)/100;function jB({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:tv+1},(p,g)=>{const x=(h+90*g/tv)*Math.PI/180;return[d+l*Math.cos(x),m+l*Math.sin(x)]}));return[...u,u[0]]}function sv(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 kB(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 NB(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 SB(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 CB=/^\[Referenced past chat "(.+)" — transcript file: (.+) \(pi session jsonl; read it if relevant\)\]$/,IB=/^@(\S.*)$/;function TB(e){return e.map(t=>t.type==="text"?t.text:t.type==="file"?/\s/.test(t.path)&&!t.path.includes('"')?`@"${t.path}"`:`@${t.path}`:t.type==="chat"?SB(t.label,t.sessionFile):iI(t)).join("")}function rv(e,t){Gx.lastIndex=t,Kx.lastIndex=t;const s=Gx.exec(e),r=Kx.exec(e),o=s?{index:s.index,length:s[0].length,segment:{type:"chat",label:s[1],sessionFile:s[2]}}:null,i=r?oI(r[0]):null,a=r&&i?{index:r.index,length:r[0].length,segment:{type:"ui-element",id:"",...i,imageId:""}}:null;return o&&a?o.index<=a.index?o:a:o??a}function AB(e){const t=[];let s=0,r=rv(e,0);for(;r;){const i=e.slice(s,r.index);for(const a of ov(i))a.type==="text"&&a.text===""||t.push(a);t.push(r.segment),s=r.index+r.length,r=rv(e,s)}const o=e.slice(s);if(o||t.length===0)for(const i of ov(o))i.type==="text"&&i.text===""&&t.length>0||t.push(i);return t}const EB=/^(?:[A-Za-z]:[\\/])?(?:[\p{L}\p{N}_./\\-]*\.[\w-]{1,16}(?:#L\d+(?:-L\d+)?)?|[\p{L}\p{N}_./\\-]+[\\/])$/u,RB=/^"([^"\n]*(?:\.[\w-]{1,16}(?:#L\d+(?:-L\d+)?)?|[\\/]))"/,MB=/#L\d+(?:-L\d+)?$/;function PB(e){return e.replace(MB,"")}function Gd(e){return e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).at(-1)||e}function ov(e){return dw(e).flatMap(t=>t.type==="file"?[t]:DB(t.text))}function DB(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===`
17
- `?RB.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===`
18
- `)&&c&&EB.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 OB(e){const t={body:e,files:[],chats:[]},s=e.split(`
19
- `),r=[],o=[];let i=s.length-1;for(;i>=0;i--){const a=s[i],l=CB.exec(a);if(l){o.unshift({label:l[1],sessionFile:l[2]});continue}if(IB.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(`
20
- `).trimEnd(),files:r,chats:o}}function iv(e){const t=TB(e.segments).trim(),s=e.segments.filter(o=>o.type!=="text").map(o=>o.type==="file"?{kind:"file",id:o.path,label:Gd(o.path),relativePath:PB(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 LB={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 _B(){const e=aI(),t=xe(x=>x.backgroundImageEnabled),s=xe(x=>x.backgroundSourceType),r=xe(x=>x.backgroundImagePath),o=xe(x=>x.backgroundFolderPath),i=xe(x=>x.backgroundUrlPath),a=xe(x=>x.backgroundRandomEnabled),l=xe(x=>x.backgroundRandomInterval),c=xe(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,y=window.setInterval(()=>d(j=>j+1),x);return()=>window.clearInterval(y)},[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(y=>{x||h(y)}),()=>{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 y=m.filter(j=>j!==x);return y[Math.floor(Math.random()*y.length)]})},[m]),n.jsxs(BB,{children:[e?.source==="user"&&n.jsx(FB,{state:{sourceType:s,imagePath:r,folderPick:p,urlPath:i,tick:u},look:e}),e?.source==="theme"&&n.jsxs(Jk,{look:e,children:[n.jsx(Zk,{image:"var(--enso-asset-background)",look:e}),n.jsx(eN,{mask:e.mask})]})]})}function BB({children:e}){const t=os(r=>r.browserHoles),s=wB(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 Xk=({blur:e,brightness:t,saturation:s})=>`blur(${e}px) brightness(${t}) saturate(${s})`,Qk=({blur:e})=>e>0?`-${e*2}px`:"0";function FB({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:Cc(r),video:xu(r)};if(s==="folder"&&o)return{src:Cc(o),video:xu(o)};if(s==="url"){const h=i.trim();if(/^https?:\/\//i.test(h))return{src:lI(h,a),video:xu(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(Jk,{look:t,children:[m?n.jsx("video",{src:d,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"absolute",style:{inset:Qk(t),width:"auto",height:"auto",minWidth:"100%",minHeight:"100%",objectFit:t.size==="contain"?"contain":"cover",filter:Xk(t),transition:"filter 0.3s ease"}},d):n.jsx(Zk,{image:`url("${d}")`,look:t},d),n.jsx(eN,{mask:t.mask})]})}function Jk({look:e,children:t}){return n.jsx("div",{"data-slot":"background-media",className:"absolute inset-0",style:{opacity:cI(e.opacity).wallpaperOpacity},children:t})}function Zk({image:e,look:t}){return n.jsx("div",{className:"absolute",style:{inset:Qk(t),backgroundImage:e,...LB[t.size],filter:Xk(t),transition:"filter 0.3s ease"}})}function eN({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 zB({hidden:e,children:t}){return n.jsx("div",{className:_("flex min-h-0 min-w-0 flex-1 flex-col",e&&"invisible"),children:t})}const $B={sm:"size-2",md:"size-2.5"},VB={sm:"h-3 w-3",md:"h-3.5 w-3.5"};function cl({tone:e,size:t="sm",title:s,className:r,"data-enso":o,"data-status":i}){const{t:a}=z();if(e==="waiting"){const l=a("Waiting for your answer");return n.jsx("span",{role:"img","aria-label":l,title:l,"data-slot":"conversation-status","data-tone":e,"data-enso":o,"data-status":i,className:_("flex shrink-0 items-center text-amber-500",r),children:n.jsx(C4,{className:_(VB[t],"stroke-[2.5]"),"aria-hidden":!0})})}return n.jsx("span",{"data-slot":"conversation-status","data-tone":e,"data-enso":o,"data-status":i,title:s,className:_("shrink-0 rounded-full",$B[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 HB="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.",Ml={enabled:!1,projectId:null,profile:null,persona:"",board:{needsYou:[],running:[],done:[],todos:[]},proposals:{},takeovers:[]};function Wu(e,t){return t&&e.some(s=>s.id===t)?t:e[0]?.id??null}function av(e){mw(Object.values(e).flatMap(t=>t.takeovers.map(s=>s.conversationId)))}function WB(e){return e?jt.getState().secretaries.find(t=>t.projectId===e)?.id??null:null}const jt=Dr()((e,t)=>({secretary:Ml,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]??Ml,welcomeOpen:!1}),r[s]||window.electronAPI.secretary.getState(s).then(i=>{e(a=>({states:{...a.states,[s]:i},...a.focusedId===s?{secretary:i}:{}}))}).catch(()=>{}))},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};av(h);const p=Wu(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=>{qx(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=Wu(u,d.focusedId);return av(h),{secretaries:u,states:h,focusedId:p,secretary:p&&h[p]||(p===d.focusedId?d.secretary:Ml)}})});window.electronAPI.secretary.list().then(async u=>{if(r){qx(u.map(d=>d.id)),e(d=>({secretaries:u,focusedId:Wu(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=>{X.getState().selectConversation(u.conversationId),os.getState().ensureOpen(u.conversationId),u.proposalId&&t().focusProposalCard(u.proposalId)}),c=X.subscribe((u,d)=>{if(u.activeId===d.activeId)return;const m=u.activeId?u.conversations[u.activeId]?.projectId:void 0,h=WB(m);h&&t().focus(h)});return()=>{r=!1,i(),a(),l(),c(),mw([]),e({secretary:Ml,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=xe.getState().projects.find(p=>p.id===l);if(!u)return null;const d=s?.greeting?UB(l):null;if(s?.greeting&&!d)return null;const m=X.getState(),h=await m.newConversation(l);if(!h)return null;if(d){const p=uw(xe.getState().language);await m.send(fw(p,HB),{...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 UB(e){const t=xe.getState(),s=t.projects.find(o=>o.id===e);if(!s)return null;const r=Df({defaultModel:t.defaultModel,...Lf(s,t.projectGroups),providers:hw(),credentials:Of(Lo.getState().snapshot),virtualModels:t.virtualModels});return r.source==="none"?null:{providerId:r.providerId,modelId:r.modelId}}const ms=Dr(()=>({modHeld:!1,headerMounted:!1,activeIds:[],slots:[],dismissed:{}}));function GB(e){ms.setState(t=>({dismissed:{...t.dismissed,[e]:Date.now()}}))}function KB(e){const{dismissed:t}=ms.getState();if(!(e in t))return;const{[e]:s,...r}=t;ms.setState({dismissed:r})}const lv=(e,t)=>e.length===t.length&&e.every((s,r)=>s===t[r]);function qB(e,t){const s=ms.getState();lv(s.activeIds,e)&&lv(s.slots,t)||ms.setState({activeIds:e,slots:t})}function YB(e){return e.messages.at(-1)?.timestamp??e.lastActiveAt}function XB(e,t){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:YB(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:s})=>({status:s})),parentId:e.parentId,sessionFile:e.sessionFile,worktree:e.worktree,secretaryOrigin:e.secretaryOrigin}}function QB(e){return JSON.stringify(e)}let xr=null;function Kd(e){if(xr?.source===e)return xr.value;const t={},s=[];for(const[r,o]of Object.entries(e)){if(!o||o.btwParentId)continue;const i=XB(o,rh({status:o.status??"idle",spawning:o.spawning,subagents:o.subagents,coworkerIds:o.coworkerIds,backgroundTasks:o.backgroundTasks},e));t[r]=i,s.push(`${r}:${QB(i)}`)}return xr&&xr.prints.length===s.length&&xr.prints.every((r,o)=>r===s[o])?(xr={source:e,prints:s,value:xr.value},xr.value):(xr={source:e,prints:s,value:t},t)}let zi=null;function JB(e){if(zi?.source===e)return zi.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=zi?.print===s?zi.value:t;return zi={source:e,print:s,value:r},r}const ZB=[],cv=new WeakMap;function eF(e,t){const s=e[t];if(!s)return ZB;const r=cv.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:c.pendingAsks?.length??0,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 cv.set(s,{source:e,print:i,value:a}),a}function tF({onNew:e}){const{t}=z(),s=ms(g=>g.activeIds),r=ms(g=>g.slots),o=ms(g=>g.modHeld),i=X(g=>Kd(g.conversations)),a=X(g=>g.activeId),l=X(g=>g.selectConversation),c=f.useRef(null),[u,d]=f.useState({left:0,right:0});f.useEffect(()=>(ms.setState({headerMounted:!0}),()=>ms.setState({headerMounted:!1})),[]),f.useLayoutEffect(()=>{const g=c.current,x=document.querySelector('[data-enso="main"]');if(!g||!x)return;const y=()=>{const w=g.getBoundingClientRect(),b=x.getBoundingClientRect(),N=Math.max(0,Math.round(b.left-w.left)),C=Math.max(0,Math.round(w.right-b.right));d(E=>E.left===N&&E.right===C?E:{left:N,right:C})};y();const j=new ResizeObserver(y);return j.observe(x),j.observe(g),()=>j.disconnect()},[]),f.useEffect(()=>{a&&(KB(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),y=m[x+1]??m[x-1];if(!y)return;l(y)}GB(g)},p=g=>g!==a||m.length>1;return n.jsx("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(nF,{id:g,conversation:i[g],active:g===a,hint:o&&x>=0&&x<9?Gs(`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(Xn,{className:"size-3.5"})})]})})}function nF({id:e,conversation:t,active:s,hint:r,untitled:o,closeLabel:i,onSelect:a,onClose:l}){const c=(t.pendingApprovals?.length??0)>0?"attention":jd({status:t.status,spawning:t.spawning,unread:t.unread,pendingAskCount:t.pendingAsks?.length??0,hasRunningChild:t.hasRunningChild}),u=t.title||o,d=jt(p=>p.secretaries.find(g=>g.projectId===t.projectId)?.id??null),m=jt(p=>p.secretary.enabled?d?(p.states[d]??(p.focusedId===d?p.secretary:null))?.profile??p.secretaries.find(x=>x.id===d)??null:p.secretary.projectId===t.projectId?p.secretary.profile:null:null),h=m?.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:p=>{p.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:u,children:[n.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:m&&h?n.jsx(kd,{name:m.name??"",color:h.color,image:h.imageVersion?Ka(h.imageVersion,h.imageHash,d??void 0):void 0,enso:"secretary-tab-avatar",className:"size-3.5 rounded-[4px] text-[8px]"}):c==="idle"?n.jsx(D_,{className:"size-3"}):n.jsx(cl,{tone:c,size:"sm"})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:u}),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(Zt,{className:"size-3"})})]})}let ua=null,fa=null,ma=null,ha=null,pa=null,oi=null,xa=null,ga=null;function sF(e){return ua=e,()=>{ua===e&&(ua=null)}}function rF(e){return ma=e,()=>{ma===e&&(ma=null)}}function oF(e){return fa=e,()=>{fa===e&&(fa=null)}}function Ei(){return ma?(ma(),!0):!1}function iF(e){return ga=e,()=>{ga===e&&(ga=null)}}function aF(e){return ga?ga(e):!1}function dv(e){return ua?(ua(e),!0):!1}function tN(e){return fa?(fa(e),!0):!1}function lF(e){return ha=e,()=>{ha===e&&(ha=null)}}function Ep(e,t){return ha?(ha(e,t),!0):!1}function cF(e){return pa=e,()=>{pa===e&&(pa=null)}}function dF(e){return pa?(pa(e),!0):!1}function uF(e){return oi=e,()=>{oi===e&&(oi=null)}}function fF(){return oi!==null}function mF(e){return oi?(oi(e),!0):!1}function hF(e){return xa=e,()=>{xa===e&&(xa=null)}}function pF(e){return xa?(xa(e),!0):!1}function sd(e,t,s,r){return{left:e,top:t,right:s,bottom:r,x:e,y:t,width:s-e,height:r-t}}function xF(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function nN(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(xF(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:sd(r,o,i,a)}}function sN(e,t,s){return e.findIndex(r=>t>r.left-2&&t<r.right+2&&s>r.top-2&&s<r.bottom+2)}function uv(e){return sd(e.left,e.top,e.right,e.bottom)}function gF(e,t,s){const{lines:r}=nN(e.getClientRects());if(r.length<2)return;const o=sN(r,t,s);return{x:t,y:s,lineIndex:o===-1?void 0:o,element:e}}function vF(e,t,s){const{lines:r,fallback:o}=nN(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 uv(r[s.lineIndex]);if(i!=null&&a!=null){const g=sN(r,i,a);if(g!==-1)return uv(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],y=l==="t"?g:x;return sd(y.left,g.top,y.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 sd(u,h.top,d,p.bottom)}function bF(e){return"contextElement"in e&&e.contextElement?e.contextElement:dI(e)?e:void 0}function yF(e,t){function s(o){rN(e,o.currentTarget,o.clientX,o.clientY)}function r(o){t||s(o)}return{onFocus(){e.current=void 0},onMouseEnter:r,onMouseMove:r}}function rN(e,t,s,r){const o=gF(t,s,r);return e.current=o,o}function wF(e){return{name:"inline",async fn(t){const s=t.elements.reference;if(typeof s?.getClientRects!="function")return{};const r=bF(s),o=e.current,i=o?.element===s||o?.element===r?o:void 0,a=vF(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 rd=10;function jF(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<rd&&s.push(a))}}return{directories:s,skippedFiles:r,truncated:o>rd}}function kF(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 NF(e){const t=jF(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 SF=150;function CF(e,t=SF){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 IF(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 hc="enso-project-order",ym="enso-pinned-order",wr="enso-archived-projects",fv="enso-pinned-projects",wm=new Set;function nr(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 wm)s()}function oN(e){return wm.add(e),()=>wm.delete(e)}const iN="enso-collapsed-projects",jm="enso-collapsed-projects-changed";function km(){try{const e=JSON.parse(localStorage.getItem(iN)??"{}");return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function TF(e){return window.addEventListener(jm,e),()=>window.removeEventListener(jm,e)}function AF(e){localStorage.setItem(iN,JSON.stringify(e)),window.dispatchEvent(new Event(jm))}function EF(){try{const e=localStorage.getItem("enso-selected-project-group");return e?xe.getState().projectGroups.find(t=>t.id===e)?.id:void 0}catch{return}}function RF(e,t){return e.length===t.length&&e.every((s,r)=>s===t[r])}function MF(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 PF(e){const t=e instanceof Error?e.message:String(e);return/not a directory/i.test(t)}let Uu=Promise.resolve();function Nm(e){return Uu=Uu.then(e).catch(()=>{}),Uu}async function aN(e,t){const s=xe.getState(),r=new Set(s.projects.map(l=>l.id)),o=await s.addProject(e,void 0,t??EF());if(!o)return;const i=X.getState(),a=IF({projectId:o.id,knownIds:r,archivedIds:nr(wr),collapsed:km(),latestConversationId:Co(i.order,i.conversations,o.id)[0]});return RF(nr(wr),a.archivedIds)||Hr(wr,a.archivedIds),JSON.stringify(km())!==JSON.stringify(a.collapsed)&&AF(a.collapsed),{project:o,focus:a.focus}}async function lN(e,t){const s=X.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 cN(e,t={}){const s=await aN(e,t.groupId);if(s)return await lN(s,t.onSelect),s.project}const mv="enso-mode",Ar=Dr()(e=>({mode:localStorage.getItem(mv)==="bot"?"bot":"code",setMode:t=>{localStorage.setItem(mv,t),e({mode:t})}}));function hv(){return xe.getState().botModeEnabled&&Ar.getState().mode==="bot"}function DF(){const e=xe(s=>s.botModeEnabled),t=Ar(s=>s.mode);return e&&t==="bot"}async function OF(e){if(!xe.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(),Ar.getState().setMode("bot");const o=uI({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 Rp(){Ar.getState().setMode("code")}const LF=200,_F=15;function BF(e){return window.electronAPI.files.pathForFile(e)}function FF(e){const t=new Set;return e.filter(s=>!t.has(s.path)&&t.add(s.path)).map(s=>s.file)}async function pv(e,t,s){let r=t,o;for(const i of e)try{o=await aN(i)??o}catch(a){if(PF(a)){r+=1;continue}if(MF(a))continue;Ie({type:"error",title:s("Failed to add project"),description:a instanceof Error?a.message:String(a)})}if(o)try{await lN(o),Rp()}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 zF(){const{t:e}=z(),[t,s]=f.useState(!1),[r,o]=f.useState(null);oh(t),f.useEffect(()=>{const c=window.electronAPI;if(c.remote)return;let u=!1,d;const m=(g,x)=>{if(!(u||pF(g))){if(x>=_F){Ie({type:"info",title:e("Open a conversation to add files")});return}d=window.setTimeout(()=>m(g,x+1),LF)}},h=()=>{c.files.takeShelfDrop().then(g=>{for(const{action:x,paths:y,skipped:j=0}of g)if(x==="project"){const w=y.slice(0,rd);Nm(()=>pv(w,j,e))}else y.length>0&&m(y,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=CF(s),u=y=>Array.from(y.dataTransfer?.types??[]).includes("Files"),d=y=>{u(y)&&(y.preventDefault(),c.enter(!0))},m=y=>{u(y)&&(y.preventDefault(),c.over(!0))},h=()=>c.leave(),p=()=>c.cancel(),g=y=>{y.key==="Escape"&&c.cancel()},x=y=>{if(!u(y)||y.defaultPrevented)return;y.preventDefault();const j=kF(y.dataTransfer??{},BF),w=NF(j);if(!w)return;const b=fF();if(w.kind==="files"&&!b){Ie({type:"info",title:e("Open a conversation to add files")});return}o({plan:w,attach:b?FF(j):[]})};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&&mF(r.attach),o(null)},l=()=>{if(i?.kind==="projects"){const{directories:c,skippedFiles:u}=i;Nm(()=>pv(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(gm,{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(on,{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:rd})})]}),n.jsxs(ts,{children:[n.jsx(fI,{render:n.jsx(he,{variant:"outline",size:"sm"}),children:e("Cancel")}),i?.kind==="files"?n.jsx(he,{size:"sm",onClick:a,children:e("Add to current conversation")}):n.jsxs(n.Fragment,{children:[r&&r.attach.length>0&&n.jsx(he,{variant:"outline",size:"sm",onClick:a,children:e("Add to current conversation")}),n.jsx(he,{size:"sm",onClick:l,children:i&&i.directories.length>1?e("Add all"):e("Open as project")})]})]})]})})]})}const $F=2e4,VF=18e4;function dN({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 HF={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."},WF={restart:"Restarting once the current command finishes",update:"Installing the update once the current command finishes",quit:"Quitting once the current command finishes"},dl=Dr(()=>({state:null,shown:{phase:"restarting"},forcing:!1,minimized:!1}));function xv(e,t){dl.setState(s=>({state:e,shown:e??s.shown,forcing:t?!1:s.forcing,minimized:s.minimized&&e?.phase==="waiting"}))}function uN(){dl.setState({forcing:!0}),window.electronAPI.app.forceRestart()}const Sm=e=>dl.setState({minimized:e}),UF=5;function GF(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 KF(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 qF({blockers:e}){const{t}=z(),s=X(i=>i.conversations);if(!e?.length)return null;const r=e.slice(0,UF),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}=GF(s,i.sessionId);return n.jsxs("li",{children:[a," — ",KF(t,i,l)]},i.sessionId)}),o>0?n.jsx("li",{children:t("{{count}} more sessions",{count:o})}):null]})}function YF(){const{t:e}=z(),{state:t,shown:s,forcing:r,minimized:o}=dl();f.useEffect(()=>{if(window.electronAPI.remote)return;let l=!1;const c=window.electronAPI.app.onRestartWaiting(u=>{l=!0,xv(u,!0)});return window.electronAPI.app.getRestartWaiting().then(u=>{l||xv(u,!1)}),c},[]);const i=s.phase==="waiting",a=i&&s.reason==="reply";return n.jsx(ih,{open:t!==null&&!o,children:n.jsxs(ah,{className:"sm:max-w-sm",children:[n.jsxs(lh,{children:[n.jsxs(ch,{className:"flex items-center gap-2 text-base",children:[n.jsx(si,{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(dh,{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:VF/6e4,idle:$F/1e3}):e(HF[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(qF,{blockers:s.blockers})]})]}),i&&n.jsxs(uh,{variant:"bare",children:[n.jsx(he,{variant:"ghost",size:"sm",onClick:()=>Sm(!0),children:e("Minimize")}),n.jsx(he,{variant:"destructive",size:"sm",disabled:r,onClick:uN,children:e("Force quit")})]})]})})}function gv(){const{t:e}=z(),{state:t,forcing:s,minimized:r}=dl();return!r||t?.phase!=="waiting"?null:n.jsxs(dN,{children:[n.jsx(si,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),n.jsxs("button",{type:"button",onClick:()=>Sm(!1),className:"min-w-0 flex-1 truncate text-left",children:[e(WF[t.exit]),t.blockers?.length?e(" · waiting for {{count}} sessions",{count:t.blockers.length}):""]}),n.jsx("button",{type:"button",disabled:s,onClick:uN,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:()=>Sm(!1),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",title:e("Expand"),children:n.jsx(mI,{className:"h-3.5 w-3.5"})})]})}function vv(){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(y=>g&&a(y.host==="desktop")).catch(()=>{});const x=window.electronAPI.updater.onStatus(y=>{s(y),y.status!=="checking"&&y.status!=="not-available"&&o(!1)});return()=>{g=!1,x()}},[]),!t)return null;const u=n.jsx(xI,{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(dN,{children:[h?n.jsx(pw,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}):n.jsx(Nd,{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(hI,{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:()=>{pI(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(Zt,{className:"h-3.5 w-3.5"})})]},"banner"),u]})}const Gu="enso.zoomBanner.dismissedPercent";function XF(e,t){return e!==100&&e!==t}function QF(e){if(e==null||e==="")return null;const t=Number(e);return Number.isFinite(t)?t:null}function Ku(){return window.electronAPI.window.getZoomPercent()}function bv(){const{t:e}=z(),[t,s]=f.useState(Ku),[r,o]=f.useState(()=>QF(localStorage.getItem(Gu)));return f.useEffect(()=>{const i=()=>s(Ku());return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),XF(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:Gs("mod+0")})}),n.jsx("button",{type:"button",onClick:()=>{window.electronAPI.window.resetZoom(),localStorage.removeItem(Gu),o(null),s(Ku())},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(Gu,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(Zt,{className:"h-3.5 w-3.5"})})]})}):null}function Mp({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 Pp({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 io(e){return e.status!=="running"?e.status:e.idle?"idle":e.keep?"kept":"running"}function fN(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 Dp(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 Cm(e){const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function Ri(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 JF={ok:"bg-success/15 text-success",pending:"bg-warning/15 text-warning",neutral:"bg-muted text-muted-foreground"};function ti({tone:e,children:t,className:s}){return n.jsx("span",{className:_("shrink-0 rounded px-1 py-px text-[10px]",JF[e],s),children:t})}function Op(e,t,s){return s("Idle {{duration}}",{duration:fN(t-(e.idle?.since??t),s)})}function mN({task:e,now:t}){const{t:s}=z(),r=io(e);return r==="idle"?n.jsx(ti,{tone:"pending",children:Op(e,t,s)}):r==="kept"?n.jsx(ti,{tone:"neutral",children:s("Kept")}):r==="running"?n.jsx(ti,{tone:"ok",children:s("Running")}):e.interrupted==="restart"?n.jsx(ti,{tone:"pending",children:s("Interrupted by restart")}):null}function Lp({task:e}){return io(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(fh,{className:"size-3"})}):n.jsx(Mp,{icon:_o,state:e.status==="running"?"running":e.status==="failed"?"error":"ok"})}function ZF(e,t){const s=e.keep;if(!s)return;const r=s.reason??Cm(s.at);return s.by==="user"?t("Kept by you · {{detail}}",{detail:r}):t("Kept: {{reason}}",{reason:r})}function _p({task:e,className:t}){const{t:s}=z(),r=io(e)==="kept"?ZF(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(Ns,{className:"size-3 shrink-0"}),n.jsx("span",{className:"truncate",title:r,children:r})]}):null}function Mi(e,t){window.electronAPI.agent.stopTask(e,t)}function Bp(e,t,s){window.electronAPI.agent.keepTask(e,t,s)}function Fp({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 qd({sessionId:e,taskId:t}){const{t:s}=z();return n.jsxs(n.Fragment,{children:[n.jsx(he,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:r=>{r.stopPropagation(),Bp(e,t,"")},children:s("Keep")}),n.jsx(he,{size:"xs",variant:"outline",className:"hover:text-destructive",onClick:r=>{r.stopPropagation(),Mi(e,t)},children:s("Stop")})]})}const Po=Dr(()=>({open:!1,idleOnly:!1}));function hN(e=!1){jt.getState().closeWelcome(),Po.setState({open:!0,idleOnly:e})}function pN(){Po.getState().open&&Po.setState({open:!1})}X.subscribe((e,t)=>{e.activeId!==t.activeId&&pN()});const od=e=>e.status==="running"&&e.idle!==void 0;function e8(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 xN(e){let t=0,s=0;for(const r of e??[])r.status==="running"&&(od(r)?s+=1:t+=1);return{running:t,idle:s}}const ii=(e,t)=>`${e}\0${t}`;function t8(e,t){return e.flatMap(s=>s.tasks.filter(r=>t.has(ii(s.conversationId,r.taskId))).map(r=>({conversationId:s.conversationId,taskId:r.taskId,command:r.command,sessionTitle:s.title,unopened:s.unopened})))}const gN="grid grid-cols-[16px_22px_minmax(0,1fr)_136px_64px_112px] items-center gap-x-3";function n8(){const{t:e}=z(),t=X(x=>x.conversations),s=xe(x=>x.projects),r=Po(x=>x.idleOnly),[o,i]=f.useState(new Set),[a,l]=f.useState(!1),c=f.useMemo(()=>e8(t),[t]),u=f.useMemo(()=>c.map(x=>({...x,tasks:r?x.tasks.filter(od):x.tasks})).filter(x=>x.tasks.length>0),[c,r]),d=c.reduce((x,y)=>x+y.tasks.length,0),m=c.reduce((x,y)=>x+y.tasks.filter(od).length,0),h=t8(u,o),p=x=>s.find(y=>y.id===x)?.name;f.useEffect(()=>{const x=new Set(c.flatMap(y=>y.tasks.map(j=>ii(y.conversationId,j.taskId))));i(y=>[...y].every(j=>x.has(j))?y:new Set([...y].filter(j=>x.has(j))))},[c]),f.useEffect(()=>{h.length===0&&l(!1)},[h.length]);const g=(x,y)=>i(j=>{const w=new Set(j);for(const b of x)y?w.add(b):w.delete(b);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(s8,{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(he,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:()=>i(new Set),children:e("Clear selection")}),n.jsx(he,{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:_(gN,"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(r8,{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(c_,{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(i8,{targets:h,onCancel:()=>l(!1),onConfirm:()=>{for(const x of h)Mi(x.conversationId,x.taskId);i(new Set),l(!1)}})]})})}function s8({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=>Po.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(fh,{className:"size-3 text-warning"}),r("Suspected idle only")," ",n.jsx("span",{className:"tabular-nums opacity-70",children:s})]})]})}function r8({group:e,projectName:t,selected:s,onToggle:r}){const{t:o}=z(),i=X(u=>u.selectConversation),a=e.tasks.map(u=>ii(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(Bo,{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(Ti,{className:"size-3.5"})]})]}),n.jsx("div",{className:"divide-y divide-border/50",children:e.tasks.map(u=>n.jsx(o8,{conversationId:e.conversationId,task:u,checked:s.has(ii(e.conversationId,u.taskId)),onCheck:d=>r([ii(e.conversationId,u.taskId)],d)},u.taskId))})]})}function o8({conversationId:e,task:t,checked:s,onCheck:r}){const{t:o}=z(),i=Ri();return n.jsxs("div",{"data-enso":"background-tasks-row",className:_(gN,"px-3 py-1.5",s&&"bg-brand/[0.06]"),children:[n.jsx(Bo,{checked:s,onCheckedChange:a=>r(a===!0),"aria-label":o("Select task")}),n.jsx(Lp,{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(_p,{task:t,className:"mt-0.5"})]}),n.jsx("div",{children:n.jsx(mN,{task:t,now:i})}),n.jsx("span",{className:"font-mono text-[11px] text-muted-foreground/80 tabular-nums",children:Dp(i-t.startedAt)}),n.jsx("div",{className:"flex items-center justify-end gap-0.5",children:od(t)?n.jsx(qd,{sessionId:e,taskId:t.taskId}):n.jsx(Fp,{onStop:()=>Mi(e,t.taskId)})})]})}function i8({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")})]},ii(i.conversationId,i.taskId)))}),n.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[n.jsx(he,{size:"xs",variant:"ghost",onClick:t,children:r("Cancel")}),n.jsx(he,{size:"xs",variant:"destructive","data-enso":"background-tasks-confirm-stop",onClick:s,children:r("Stop {{count}}",{count:e.length})})]})]})}function a8(e,t){return[t,...e.filter(s=>s.parentId===t.id).sort((s,r)=>s.createdAt-r.createdAt)]}function l8(e,t){return(t.activeThreadId?e.find(r=>r.id===t.activeThreadId&&r.parentId===t.id):void 0)??t}const c8=10,vN=e=>[...e].sort((t,s)=>s.activityAt-t.activityAt);function bN(e,t,s=c8){const r=vN(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 yv(e,t,s){const r=t.trim().toLowerCase();return vN(e).filter(o=>(s==="all"||(s==="unread"?o.unread:o.running))&&(!r||`${o.title}
21
- ${o.preview??""}`.toLowerCase().includes(r)))}function id({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 d8={"external-send":"Protected: external send",delete:"Protected: delete",payment:"Protected: payment",deploy:"Protected: deploy / production",secret:"Protected: secrets",destructive:"Protected: destructive command"};function yN(e,t){return t(d8[e])}function zp(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 $p({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 u8={command:_o,"file-edit":Y4,"file-write":Q4,mcp:xw};function f8({kind:e,summary:t}){const[s,r]=f.useState(null);f.useEffect(()=>{if(e!=="command")return;let a=!0;return vI(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(mh,{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 m8={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."},h8=400;function Vp({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=zp(d?.phase==="reviewing"?void 0:d?.expiresAt,o);if(f.useEffect(()=>{if(!m)return;const j=setTimeout(()=>u(m),h8);return()=>clearTimeout(j)},[m]),!d)return null;const p=u8[d.kind]??Ao,g=d.phase==="reviewing",x=c!==d.requestId||a===d.requestId||h!==void 0&&h<=0,y=j=>{j!=="review"&&l(d.requestId),t(d.requestId,j)};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(Ao,{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&&gI(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:yN(d.protected,i)}),n.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[n.jsx($p,{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(m8[d.reviewFallback])}),d.guard&&n.jsx("p",{className:"mt-1 text-[11px] text-destructive",title:d.guard.ruleId,children:i("dcg: {{reason}}",{reason:d.guard.reason})}),d.summary&&n.jsx(f8,{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:()=>y("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:()=>y("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:()=>y("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:()=>y("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:()=>y("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 wv(e){return e>=0&&e<9?String(e+1):null}function p8(e,t){const s=t===void 0?-1:e?.indexOf(t)??-1;return s>=0?s:0}function x8(e,t,s){return s==="ArrowDown"?Math.min(e+1,t-1):s==="ArrowUp"?Math.max(e-1,0):null}function Hp({asks:e,onAnswer:t,clockOffset:s,autoFocus:r=!0}){const{t:o}=z(),i=f.useRef(null),a=f.useRef([]),[l,c]=f.useState(""),[u,d]=f.useState(null),[m,h]=f.useState(()=>new Set),p=e.filter(k=>k.answered),g=e.find(k=>!k.answered),x=g?.requestId,y=zp(g?.expiresAt,s),j=x!==void 0&&m.has(x),w=g?.options,b=g?.recommended,N=k=>{const L=a.current[k];w&&k<w.length&&L?L.focus():i.current?.focus()};if(f.useEffect(()=>{if(!r||!x||j)return;const k=p8(w,b),L=a.current[k];w&&k<w.length&&L?L.focus():i.current?.focus()},[r,x,j]),!g)return p.length>0?n.jsx(qu,{asks:p}):null;const C=u===g.requestId||y!==void 0&&y<=0,E=k=>{k.trim()&&(d(g.requestId),c(""),t(g.requestId,k.trim()))},T=()=>h(k=>k.has(g.requestId)?k:new Set(k).add(g.requestId));return j?n.jsxs(n.Fragment,{children:[n.jsx(qu,{asks:p}),n.jsxs("button",{type:"button","data-enso":"ask-later",onClick:()=>h(k=>{const L=new Set(k);return L.delete(g.requestId),L}),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(Ic,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:g.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(qu,{asks:p}),n.jsxs("div",{"data-enso":"ask",className:"mb-1 rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2",onKeyDown:k=>{if(k.nativeEvent.isComposing||C)return;if(k.key==="Escape"){k.preventDefault(),T();return}const L=k.target,F=(w?.length??0)+1,A=L===i.current?F-1:a.current.indexOf(L),D=A>=0?x8(A,F,k.key):null;if(D!==null){k.preventDefault(),N(D);return}if(L instanceof HTMLInputElement&&(L.value.length>0||k.key==="Enter"))return;const M=Number(k.key)-1,H=w?.[M];if(wv(M)&&H){k.preventDefault(),E(H);return}L instanceof HTMLButtonElement&&A>=0&&(k.key==="Process"?i.current?.focus():k.key.length===1&&k.key!==" "&&!k.metaKey&&!k.ctrlKey&&!k.altKey&&(k.preventDefault(),c(G=>G+k.key),i.current?.focus()))},children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Ic,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-blue-500"}),n.jsx("span",{className:"min-w-0 flex-1 text-xs leading-relaxed whitespace-pre-wrap",children:g.question}),g.relay&&n.jsx("span",{"data-enso":"ask-relay",className:"shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:o("Handed to {{name}}",{name:g.relay.name})}),n.jsx("button",{type:"button",onClick:T,className:"shrink-0 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($p,{remainingMs:y,expiredLabel:"Timed out · no answer"}),e.length>1&&n.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground tabular-nums",children:["1/",e.length]})]}),w&&w.length>0&&n.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:w.map((k,L)=>{const F=wv(L);return n.jsxs("button",{ref:A=>{a.current[L]=A},type:"button",disabled:C,onClick:()=>E(k),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:[F&&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:F}),n.jsx("span",{className:"min-w-0 flex-1",children:k}),k===b&&n.jsx("span",{className:"shrink-0 rounded bg-success/15 px-1.5 text-[10px] text-success",children:o("Recommended")})]},k)})}),n.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[n.jsx("input",{ref:i,value:l,onChange:k=>c(k.target.value),onKeyDown:k=>{k.nativeEvent.isComposing||k.key==="Enter"&&E(l)},disabled:C,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:C||!l.trim(),onClick:()=>E(l),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(Ud,{className:"h-3.5 w-3.5"})})]})]})]})}function qu({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(Ic,{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 Yd=0,ao=1,Pi=2,wN=4;function jv(e){return()=>e}function g8(e){e()}function jN(e,t){return s=>e(t(s))}function kv(e,t){return()=>e(t)}function v8(e,t){return s=>e(t,s)}function Wp(e){return e!==void 0}function b8(...e){return()=>{e.map(g8)}}function Di(){}function Xd(e,t){return t(e),e}function y8(e,t){return t(e)}function wn(...e){return e}function rn(e,t){return e(ao,t)}function Pt(e,t){e(Yd,t)}function Up(e){e(Pi)}function Sn(e){return e(wN)}function mt(e,t){return rn(e,v8(t,Yd))}function Us(e,t){const s=e(ao,r=>{s(),t(r)});return s}function Nv(e){let t,s;return r=>o=>{t=o,s&&clearTimeout(s),s=setTimeout(()=>{r(t)},e)}}function kN(e,t){return e===t}function yn(e=kN){let t;return s=>r=>{e(t,r)||(t=r,s(r))}}function wt(e){return t=>s=>{e(s)&&t(s)}}function st(e){return t=>jN(t,e)}function tr(e){return t=>()=>{t(e)}}function De(e,...t){const s=w8(...t);return((r,o)=>{switch(r){case Pi:Up(e);return;case ao:return rn(e,s(o))}})}function rr(e,t){return s=>r=>{s(t=e(t,r))}}function Do(e){return t=>s=>{e>0?e--:t(s)}}function Nr(e){let t=null,s;return r=>o=>{t=o,!s&&(s=setTimeout(()=>{s=void 0,r(t)},e))}}function zt(...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;rn(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 w8(...e){return t=>e.reduceRight(y8,t)}function j8(e){let t,s;const r=()=>t?.();return function(o,i){switch(o){case ao:return i?s===i?void 0:(r(),s=i,t=rn(e,i),t):(r(),Di);case Pi:r(),s=null;return}}}function ze(e){let t=e;const s=Xt();return((r,o)=>{switch(r){case Yd:t=o;break;case ao:{o(t);break}case wN:return t}return s(r,o)})}function ss(e,t){return Xd(ze(t),s=>mt(e,s))}function Xt(){const e=[];return((t,s)=>{switch(t){case Yd:e.slice().forEach(r=>{r(s)});return;case Pi:e.splice(0);return;case ao:return e.push(s),()=>{const r=e.indexOf(s);r>-1&&e.splice(r,1)}}})}function gs(e){return Xd(Xt(),t=>mt(e,t))}const k8={singleton:!0};function en(e,t=[],s=k8){const{singleton:r}=s;return{constructor:e,dependencies:t,id:N8(),singleton:r}}const N8=()=>Symbol("id");function S8(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=Xt(),s=Array.from({length:e.length});let r=0;const o=2**e.length-1;return e.forEach((i,a)=>{const l=2**a;rn(i,c=>{s[a]=c,r|=l,r===o&&Pt(t,s)})}),function(i,a){switch(i){case Pi:{Up(t);return}case ao:return r===o&&a(s),rn(t,a)}}}function yt(e,t=kN){return De(e,yn(t))}function Im(...e){return function(t,s){switch(t){case Pi:return;case ao:return b8(...e.map(r=>rn(r,s)))}}}const Wn={DEBUG:0,INFO:1,WARN:2,ERROR:3},C8={[Wn.DEBUG]:"debug",[Wn.ERROR]:"error",[Wn.INFO]:"log",[Wn.WARN]:"warn"},I8=()=>typeof globalThis>"u"?window:globalThis,lo=en(()=>{const e=ze(Wn.ERROR);return{log:ze((t,s,r=Wn.INFO)=>{const o=I8().VIRTUOSO_LOG_LEVEL??Sn(e);r>=o&&console[C8[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,s)}),logLevel:e}},[],{singleton:!0});function T8(e){return"self"in e?e.document.documentElement:e}function NN(e){const t=T8(e);return t.ownerDocument.defaultView.getComputedStyle(t).direction==="rtl"}function No(e,t){return NN(e)?-t:t}function Sv(e,t){return NN(e)?-t:t}function zo(e,t,s){return Gp(e,t,s).callbackRef}function Gp(e,t,s){const r=Ue.useRef(null);let o=a=>{};const i=Ue.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 A8(e,t,s,r,o,i,a,l,c){const u=Ue.useCallback(d=>{const m=E8(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,y=a?l?a.offsetWidth:a.offsetHeight:p?l?g.innerWidth:g.innerHeight:l?h.offsetWidth:h.offsetHeight,j=a?l?No(a,a.scrollLeft):a.scrollTop:p?l?No(g,g.scrollX||g.document.documentElement.scrollLeft):g.scrollY||g.document.documentElement.scrollTop:l?No(h,h.scrollLeft):h.scrollTop;r({scrollHeight:x,scrollTop:Math.max(j,0),viewportHeight:y}),i?.(l?Cv("column-gap",getComputedStyle(d).columnGap,o):Cv("row-gap",getComputedStyle(d).rowGap,o)),m!==null&&e(m)},[e,t,o,i,a,r,l]);return Gp(u,s,c)}function E8(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},Wn.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 Cv(e,t,s){return t!=="normal"&&t?.endsWith("px")!==!0&&s(`${e} was not resolved to pixel value correctly`,t,Wn.WARN),t==="normal"?0:parseInt(t??"0",10)}function SN(e,t,s){const r=Ue.useRef(null),o=Ue.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}=Gp(o,!0,s),l=Ue.useCallback(()=>{o(a.current)},[o,a]);return Ue.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 us=en(()=>{const e=Xt(),t=Xt(),s=ze(0),r=Xt(),o=ze(0),i=Xt(),a=Xt(),l=ze(0),c=ze(0),u=ze(0),d=ze(0),m=Xt(),h=Xt(),p=ze(!1),g=ze(!1),x=ze(!1);return mt(De(e,st(({scrollTop:y})=>y)),t),mt(De(e,st(({scrollHeight:y})=>y)),a),mt(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}),Oa={lvl:0};function CN(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===Oa}function La(e,t){if(!ln(e))return t===e.k?e.v:t<e.k?La(e.l,t):La(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)?AN(t,s,1):t===e.k?zn(e,{k:t,v:s}):t<e.k?Iv(zn(e,{l:ps(e.l,t,s)})):Iv(zn(e,{r:ps(e.r,t,s)}))}function ai(){return Oa}function li(e,t,s){if(ln(e))return[];const r=Xs(e,t)[0];return R8(Am(e,r,s))}function Tm(e,t){if(ln(e))return Oa;const{k:s,l:r,r:o}=e;if(t===s){if(ln(r))return o;if(ln(o))return r;const[i,a]=TN(r);return pc(zn(e,{k:i,l:IN(r),v:a}))}return t<s?pc(zn(e,{l:Tm(r,t)})):pc(zn(e,{r:Tm(o,t)}))}function So(e){return ln(e)?[]:[...So(e.l),{k:e.k,v:e.v},...So(e.r)]}function Am(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(Am(o,t,s))),r>=t&&r<=s&&l.push({k:r,v:a}),r<=s&&(l=l.concat(Am(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(Yu(t))return EN(zn(e,{lvl:s-1}));if(!ln(t)&&!ln(t.r))return zn(t.r,{l:zn(t,{r:t.r.l}),lvl:s,r:zn(e,{l:t.r.r,lvl:s-1})});throw new Error("Unexpected empty nodes")}if(Yu(e))return Em(zn(e,{lvl:s-1}));if(!ln(r)&&!ln(r.l)){const o=r.l,i=Yu(o)?r.lvl-1:r.lvl;return zn(o,{l:zn(e,{lvl:s-1,r:o.l}),lvl:o.lvl+1,r:Em(zn(r,{l:o.r,lvl:i}))})}throw new Error("Unexpected empty nodes")}function zn(e,t){return AN(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 IN(e){return ln(e.r)?e.l:pc(zn(e,{r:IN(e.r)}))}function Yu(e){return ln(e)||e.lvl>e.r.lvl}function TN(e){return ln(e.r)?[e.k,e.v]:TN(e.r)}function AN(e,t,s,r=Oa,o=Oa){return{k:e,l:r,lvl:s,r:o,v:t}}function Iv(e){return Em(EN(e))}function EN(e){const{l:t}=e;return!ln(t)&&t.lvl===e.lvl?zn(t,{r:zn(e,{l:t.r})}):e}function Em(e){const{lvl:t,r:s}=e;return!ln(s)&&!ln(s.r)&&s.lvl===t&&s.r.lvl===t?zn(s,{l:zn(e,{r:s.l}),lvl:t+1}):e}function R8(e){return CN(e,({k:t,v:s})=>({index:t,value:s}))}function RN(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function _a(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Kp=en(()=>({recalcInProgress:ze(!1)}),[],{singleton:!0});function MN(e,t,s){return e[ad(e,t,s)]}function ad(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 M8(e,t,s,r){const o=ad(e,t,r),i=ad(e,s,r,o);return e.slice(o,i+1)}function so(e,t){return Math.round(e.getBoundingClientRect()[t])}function Qd(e){return!ln(e.groupOffsetTree)}function qp({index:e},t){return t===e?0:t<e?-1:1}function P8(){return{groupIndices:[],groupOffsetTree:ai(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ai()}}function D8(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=li(e,a-1,o+1);if(l.some($8(r)))continue;let c=!1,u=!1;for(const{end:d,start:m,value:h}of l)c?(o>=m||i===h)&&(e=Tm(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 O8(e){return e.groupIndex!==void 0}function L8({offset:e},t){return t===e?0:t<e?-1:1}function Ba(e,t,s){if(t.length===0)return 0;const{index:r,offset:o,size:i}=MN(t,e,qp),a=e-r,l=i*a+(a-1)*s+o;return l>0?l+s:l}function PN(e,t){if(!Qd(t))return e;let s=0;for(;t.groupIndices[s]<=e+s;)s++;return e+s}function DN(e,t,s){if(O8(e))return t.groupIndices[e.groupIndex]+1;const r=e.index==="LAST"?s:e.index;let o=PN(r,t);return o=Math.max(0,Math.min(s,o)),o}function _8(e,t,s,r=0){return r>0&&(t=Math.max(t,MN(e,r,qp).offset)),CN(M8(e,t,s,L8),z8)}function B8(e,[t,s,r,o]){t.length>0&&r("received item sizes",t,Wn.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]=D8(a,t);if(a===i)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:m}=Rm(e.offsetTree,l,a,o);return{groupIndices:s,groupOffsetTree:s.reduce((h,p)=>ps(h,p,Ba(p,m,o)),ai()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:m,sizeTree:a}}function F8(e){return So(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 Tv(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 Rm(e,t,s,r){let o=e,i=0,a=0,l=0,c=0;if(t===0)o=[];else{c=ad(o,t-1,qp),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 li(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 z8(e){return{index:e.index,value:e}}function $8(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 V8={offsetHeight:"height",offsetWidth:"width"},hr=en(([{log:e},{recalcInProgress:t}])=>{const s=Xt(),r=Xt(),o=ss(r,0),i=Xt(),a=Xt(),l=ze(0),c=ze([]),u=ze(void 0),d=ze(void 0),m=ze(void 0),h=ze(void 0),p=ze((T,k)=>so(T,V8[k])),g=ze(void 0),x=ze(0),y=P8(),j=ss(De(s,zt(c,e,x),rr(B8,y),yn()),y),w=ss(De(c,yn(),rr((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),st(({prev:T})=>T)),[]);mt(De(c,wt(T=>T.length>0),zt(j,x),st(([T,k,L])=>{const F=T.reduce((A,D,M)=>ps(A,D,Ba(D,k.offsetTree,L)||M),ai());return{...k,groupIndices:T,groupOffsetTree:F}})),j),mt(De(r,zt(j),wt(([T,{lastIndex:k}])=>T<k),st(([T,{lastIndex:k,lastSize:L}])=>[{endIndex:k,size:L,startIndex:T}])),s),mt(u,d);const b=ss(De(u,st(T=>T===void 0)),!0);mt(De(d,wt(T=>T!==void 0&&ln(Sn(j).sizeTree)),st(T=>{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:T,startIndex:1}]:[]:[{endIndex:0,size:T,startIndex:0}]})),s),mt(De(h,wt(T=>T!==void 0&&T.length>0&&ln(Sn(j).sizeTree)),st(T=>{const k=[];let L=T[0],F=0;for(let A=1;A<T.length;A++){const D=T[A];D!==L&&(k.push({endIndex:A-1,size:L,startIndex:F}),L=D,F=A)}return k.push({endIndex:T.length-1,size:L,startIndex:F}),k})),s),mt(De(c,zt(m,d),wt(([,T,k])=>T!==void 0&&k!==void 0),st(([T,k,L])=>{const F=[];for(let A=0;A<T.length;A++){const D=T[A],M=T[A+1];F.push({startIndex:D,endIndex:D,size:k}),M!==void 0&&F.push({startIndex:D+1,endIndex:M-1,size:L})}return F})),s);const N=gs(De(s,zt(j),rr(({sizes:T},[k,L])=>({changed:L!==T,sizes:L}),{changed:!1,sizes:y}),st(T=>T.changed)));rn(De(l,rr((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),st(T=>T.diff)),T=>{const{groupIndices:k}=Sn(j);if(T>0)Pt(t,!0),Pt(i,T+Tv(T,k));else if(T<0){const L=Sn(w);L.length>0&&(T-=Tv(-T,L)),Pt(a,T)}}),rn(De(l,zt(e)),([T,k])=>{T<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},Wn.ERROR)});const C=gs(i);mt(De(i,zt(j),st(([T,k])=>{const L=k.groupIndices.length>0,F=[],A=k.lastSize;if(L){const D=La(k.sizeTree,0);let M=0,H=0;for(;M<T;){const U=k.groupIndices[H],J=k.groupIndices.length===H+1?1/0:k.groupIndices[H+1]-U-1;F.push({endIndex:U,size:D,startIndex:U}),F.push({endIndex:U+1+J-1,size:A,startIndex:U+1}),H++,M+=J+1}const G=So(k.sizeTree);return M!==T&&G.shift(),G.reduce((U,{k:J,v:$})=>{let oe=U.ranges;return U.prevSize!==0&&(oe=[...U.ranges,{endIndex:J+T-1,size:U.prevSize,startIndex:U.prevIndex}]),{prevIndex:J+T,prevSize:$,ranges:oe}},{prevIndex:T,prevSize:0,ranges:F}).ranges}return So(k.sizeTree).reduce((D,{k:M,v:H})=>({prevIndex:M+T,prevSize:H,ranges:[...D.ranges,{endIndex:M+T-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),s);const E=gs(De(a,zt(j,x),st(([T,{offsetTree:k},L])=>{const F=-T;return Ba(F,k,L)})));return mt(De(a,zt(j,x),st(([T,k,L])=>{if(k.groupIndices.length>0){if(ln(k.sizeTree))return k;let A=ai();const D=Sn(w);let M=0,H=0,G=0;for(;M<-T;){G=D[H];const U=D[H+1]-G-1;H++,M+=U+1}if(A=So(k.sizeTree).reduce((U,{k:J,v:$})=>ps(U,Math.max(0,J+T),$),A),M!==-T){const U=La(k.sizeTree,G);A=ps(A,0,U);const J=Xs(k.sizeTree,-T+1)[1];A=ps(A,1,J)}return{...k,sizeTree:A,...Rm(k.offsetTree,0,A,L)}}const F=So(k.sizeTree).reduce((A,{k:D,v:M})=>ps(A,Math.max(0,D+T),M),ai());return{...k,sizeTree:F,...Rm(k.offsetTree,0,F,L)}})),j),{beforeUnshiftWith:C,data:g,defaultItemSize:d,firstItemIndex:l,fixedItemSize:u,fixedGroupSize:m,gap:x,groupIndices:c,heightEstimates:h,itemSize:p,listRefresh:N,shiftWith:a,shiftWithOffset:E,sizeRanges:s,sizes:j,statefulTotalCount:o,totalCount:r,trackItemSizes:b,unshiftWith:i}},wn(lo,Kp),{singleton:!0});function H8(e){return e.reduce((t,s)=>(t.groupIndices.push(t.totalCount),t.totalCount+=s+1,t),{groupIndices:[],totalCount:0})}const ON=en(([{groupIndices:e,sizes:t,totalCount:s},{headerHeight:r,scrollTop:o}])=>{const i=Xt(),a=Xt(),l=gs(De(i,st(H8)));return mt(De(l,st(c=>c.totalCount)),s),mt(De(l,st(c=>c.groupIndices)),e),mt(De(Mn(o,t,r),wt(([c,u])=>Qd(u)),st(([c,u,d])=>Xs(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),yn(),st(c=>[c])),a),{groupCounts:i,topItemsIndexes:a}},wn(hr,us)),co=en(([{log:e}])=>{const t=ze(!1),s=gs(De(t,wt(r=>r),yn()));return rn(t,r=>{r&&Sn(e)("props updated",{},Wn.DEBUG)}),{didMount:s,propsReady:t}},wn(lo),{singleton:!0}),W8=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function LN(e){const t=typeof e=="number"?{index:e}:{...e};return t.align||(t.align="start"),(!t.behavior||!W8)&&(t.behavior="auto"),t.offset===void 0&&(t.offset=0),t}const ul=en(([{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=Xt(),g=Xt(),x=ze(0);let y=null,j=null,w=null;function b(){y!==null&&(y(),y=null),w!==null&&(w(),w=null),j&&(clearTimeout(j),j=null),Pt(c,!1)}return mt(De(p,zt(s,m,r,x,l,a,h),zt(e,i,o),st(([[N,C,E,T,k,L,F,A],D,M,H])=>{const G=LN(N),{align:U,behavior:J,offset:$}=G,oe=T-1,Ne=DN(G,C,oe);let ce=Ba(Ne,C.offsetTree,D)+L;U==="end"?(ce+=M+Xs(C.sizeTree,Ne)[1]-E+H,Ne===oe&&(ce+=F)):U==="center"?ce+=(M+Xs(C.sizeTree,Ne)[1]-E+H)/2:ce-=k,$!==void 0&&$!==0&&(ce+=$);const ne=Y=>{b(),Y?(A("retrying to scroll to",{location:N},Wn.DEBUG),Pt(p,N)):(Pt(g,!0),A("list did not change, scroll successful",{},Wn.DEBUG))};if(b(),J==="smooth"){let Y=!1;w=rn(t,pe=>{Y=Y||pe}),y=Us(d,()=>{ne(Y)})}else y=Us(De(t,U8(150)),ne);return j=setTimeout(()=>{b()},1200),Pt(c,!0),A("scrolling from index to",{behavior:J,index:Ne,top:ce},Wn.DEBUG),{behavior:J,top:ce}})),u),{scrollTargetReached:g,scrollToIndex:p,topListHeight:x}},wn(hr,us,lo),{singleton:!0});function U8(e){return t=>{const s=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(s))}}}function Yp(e,t){e===0?t():requestAnimationFrame(()=>{Yp(e-1,t)})}function Xp(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 Mm(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 fl=en(([{defaultItemSize:e,listRefresh:t,sizes:s},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:i},{didMount:a}])=>{const l=ze(!0),c=ze(0),u=ze(!0);return mt(De(a,zt(c),wt(([d,m])=>!Mm(m)),tr(!1)),l),mt(De(a,zt(c),wt(([d,m])=>!Mm(m)),tr(!1)),u),rn(De(Mn(t,a),zt(l,s,e,u),wt(([[,d],m,{sizeTree:h},p,g])=>d&&(!ln(h)||Wp(p))&&!m&&!g),zt(c)),([,d])=>{if(d===void 0){Pt(l,!0),Pt(u,!0);return}Us(o,()=>{Pt(u,!0)}),Yp(4,()=>{Us(r,()=>{Pt(l,!0)}),Pt(i,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:l}},wn(hr,us,ul,co),{singleton:!0});function _N(e,t){return Math.abs(e-t)<1.01}const Fa="up",va="down",G8="none",K8={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},q8=0,ml=en(([{footerHeight:e,headerHeight:t,scrollBy:s,scrollContainerState:r,scrollTop:o,viewportHeight:i}])=>{const a=ze(!1),l=ze(!0),c=Xt(),u=Xt(),d=ze(4),m=ze(q8),h=ss(De(Im(De(yt(o),Do(1),tr(!0)),De(yt(o),Do(1),tr(!1),Nv(100))),yn()),!1),p=ss(De(Im(De(s,tr(!0)),De(s,tr(!1),Nv(200))),yn()),!1);mt(De(Mn(yt(o),yt(m)),st(([w,b])=>w<=b),yn()),l),mt(De(l,Nr(50)),u);const g=gs(De(Mn(r,yt(i),yt(t),yt(e),yt(d)),rr((w,[{scrollHeight:b,scrollTop:N},C,E,T,k])=>{const L=N+C-b>-k,F={scrollHeight:b,scrollTop:N,viewportHeight:C};if(L){let D,M;return N>w.state.scrollTop?(D="SCROLLED_DOWN",M=w.state.scrollTop-N):(D="SIZE_DECREASED",M=w.state.scrollTop-N||w.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:M,state:F}}let A;return F.scrollHeight>w.state.scrollHeight?A="SIZE_INCREASED":C<w.state.viewportHeight?A="VIEWPORT_HEIGHT_DECREASING":N<w.state.scrollTop?A="SCROLLING_UPWARDS":A="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:A,state:F}},K8),yn((w,b)=>w!==void 0&&w.atBottom===b.atBottom))),x=ss(De(r,rr((w,{scrollHeight:b,scrollTop:N,viewportHeight:C})=>{if(!_N(w.scrollHeight,b)){const E=b-(N+C)<1;return w.scrollTop!==N&&E?{changed:!0,jump:w.scrollTop-N,scrollHeight:b,scrollTop:N}:{changed:!0,jump:0,scrollHeight:b,scrollTop:N}}return{changed:!1,jump:0,scrollHeight:b,scrollTop:N}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),wt(w=>w.changed),st(w=>w.jump)),0);mt(De(g,st(w=>w.atBottom)),a),mt(De(a,Nr(50)),c);const y=ze(va);mt(De(r,st(({scrollTop:w})=>w),yn(),rr((w,b)=>Sn(p)?{direction:w.direction,prevScrollTop:b}:{direction:b<w.prevScrollTop?Fa:va,prevScrollTop:b},{direction:va,prevScrollTop:0}),st(w=>w.direction)),y),mt(De(r,Nr(50),tr(G8)),y);const j=ze(0);return mt(De(h,wt(w=>!w),tr(0)),j),mt(De(o,Nr(100),zt(h),wt(([w,b])=>b),rr(([w,b],[N])=>[b,N],[0,0]),st(([w,b])=>b-w)),j),{atBottomState:g,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:m,isAtBottom:a,isAtTop:l,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:y,scrollVelocity:j}},wn(us)),za="top",$a="bottom",Av="none";function Ev(e,t,s){return typeof e=="number"?s===Fa&&t===za||s===va&&t===$a?e:0:s===Fa?t===za?e.main:e.reverse:t===$a?e.main:e.reverse}function Rv(e,t){return typeof e=="number"?e:e[t]??0}const Qp=en(([{deviation:e,fixedHeaderHeight:t,headerHeight:s,scrollTop:r,viewportHeight:o}])=>{const i=Xt(),a=ze(0),l=ze(0),c=ze(0),u=ss(De(Mn(yt(r),yt(o),yt(s),yt(i,_a),yt(c),yt(a),yt(t),yt(e),yt(l)),st(([d,m,h,[p,g],x,y,j,w,b])=>{const N=d-w,C=y+j,E=Math.max(h-N,0);let T=Av;const k=Rv(b,za),L=Rv(b,$a);return p-=w,p+=h+j,g+=h+j,g-=w,p>d+C-k&&(T=Fa),g<d-E+m+L&&(T=va),T!==Av?[Math.max(N-h-Ev(x,za,T)-k,0),N-E-j+m+Ev(x,$a,T)+L]:null}),wt(d=>d!==null),yn(_a)),[0,0]);return{increaseViewportBy:l,listBoundary:i,overscan:c,topListHeight:a,visibleRange:u}},wn(us),{singleton:!0});function Y8(e,t,s){if(Qd(t)){const r=PN(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 Xu={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function xc(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:Mv(e,o,i),offsetBottom:g,offsetTop:u,top:p,topItems:Mv(t,o,i),topListHeight:t.reduce((x,y)=>y.size+x,0),totalCount:s}}function BN(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=Xp(t,l),u=Array.from({length:l}).map((d,m)=>({data:i[m+c],index:m+c,offset:0,size:0}));return xc(u,[],l,o,s,r)}function Mv(e,t,s){if(e.length===0)return[];if(!Qd(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=li(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 Pv(e,t){return e===void 0?0:typeof e=="number"?e:e[t]??0}const $o=en(([{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=ze([]),y=ze(0),j=Xt(),w=ze(0);mt(i.topItemsIndexes,x);const b=ss(De(Mn(p,g,yt(c,_a),yt(o),yt(r),yt(u),d,yt(x),yt(t),yt(s),yt(w),e),wt(([T,k,,L,,,,,,,,F])=>{const A=F!==void 0&&F.length!==L;return T&&!k&&!A}),st(([,,[T,k],L,F,A,D,M,H,G,U,J])=>{const $=F,{offsetTree:oe,sizeTree:Ne}=$,ce=Sn(y);if(L===0)return{...Xu,totalCount:L};if(T===0&&k===0)return ce===0?{...Xu,totalCount:L}:BN(ce,A,F,H,G,J||[]);if(ln(Ne))return ce>0?null:xc(Y8(Xp(A,L),$,J),[],L,G,$,H);const ne=[];if(M.length>0){const B=M[0],te=M[M.length-1];let Z=0;for(const ue of li(Ne,B,te)){const fe=ue.value,Ce=Math.max(ue.start,B),de=Math.min(ue.end,te);for(let Ee=Ce;Ee<=de;Ee++)ne.push({data:J?.[Ee],index:Ee,offset:Z,size:fe}),Z+=fe}}if(!D)return xc([],ne,L,G,$,H);const Y=M.length>0?M[M.length-1]+1:0,pe=_8(oe,T,k,Y);if(pe.length===0)return null;const ge=L-1,we=Xd([],B=>{for(const te of pe){const Z=te.value;let ue=Z.offset,fe=te.start;const Ce=Z.size;if(Z.offset<T){fe+=Math.floor((T-Z.offset+G)/(Ce+G));const Ee=fe-te.start;ue+=Ee*Ce+Ee*G}fe<Y&&(ue+=(Y-fe)*Ce,fe=Y);const de=Math.min(te.end,ge);for(let Ee=fe;Ee<=de&&!(ue>=k);Ee++)B.push({data:J?.[Ee],index:Ee,offset:ue,size:Ce}),ue+=Ce+G}}),V=Pv(U,za),W=Pv(U,$a);if(we.length>0&&(V>0||W>0)){const B=we[0],te=we[we.length-1];if(V>0&&B.index>Y){const Z=Math.min(V,B.index-Y),ue=[];let fe=B.offset;for(let Ce=B.index-1;Ce>=B.index-Z;Ce--){const de=li(Ne,Ce,Ce)[0]?.value??B.size;fe-=de+G,ue.unshift({data:J?.[Ce],index:Ce,offset:fe,size:de})}we.unshift(...ue)}if(W>0&&te.index<ge){const Z=Math.min(W,ge-te.index);let ue=te.offset+te.size+G;for(let fe=te.index+1;fe<=te.index+Z;fe++){const Ce=li(Ne,fe,fe)[0]?.value??te.size;we.push({data:J?.[fe],index:fe,offset:ue,size:Ce}),ue+=Ce+G}}}return xc(we,ne,L,G,$,H)}),wt(T=>T!==null),yn()),Xu);mt(De(e,wt(Wp),st(T=>T?.length)),o),mt(De(b,st(T=>T.topListHeight)),m),mt(m,l),mt(De(b,st(T=>[T.top,T.bottom])),a),mt(De(b,st(T=>T.items)),j);const N=gs(De(b,wt(({items:T})=>T.length>0),zt(o,e),wt(([{items:T},k])=>T[T.length-1].originalIndex===k-1),st(([,T,k])=>[T-1,k]),yn(_a),st(([T])=>T))),C=gs(De(b,Nr(200),wt(({items:T,topItems:k})=>T.length>0&&T[0].originalIndex===k.length),st(({items:T})=>T[0].index),yn())),E=gs(De(b,wt(({items:T})=>T.length>0),st(({items:T})=>{let k=0,L=T.length-1;for(;T[k].type==="group"&&k<L;)k++;for(;T[L].type==="group"&&L>k;)L--;return{endIndex:T[L].index,startIndex:T[k].index}}),yn(RN)));return{endReached:N,initialItemCount:y,itemsRendered:j,listState:b,minOverscanItemCount:w,rangeChanged:E,startReached:C,topItemsIndexes:x,...h}},wn(hr,ON,Qp,fl,ul,ml,co,Kp),{singleton:!0}),FN=en(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:s,headerHeight:r},{listState:o}])=>{const i=Xt(),a=ss(De(Mn(s,e,r,t,o),st(([l,c,u,d,m])=>l+c+u+d+m.offsetBottom+m.bottom)),0);return mt(yt(a),i),{totalListHeight:a,totalListHeightChanged:i}},wn(us,$o),{singleton:!0}),X8=en(([{viewportHeight:e},{totalListHeight:t}])=>{const s=ze(!1),r=ss(De(Mn(s,e,t),wt(([o])=>o),st(([,o,i])=>Math.max(0,o-i)),Nr(0),yn()),0);return{alignToBottom:s,paddingTopAddition:r}},wn(us,FN),{singleton:!0}),zN=en(()=>({context:ze(null)})),Q8=({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,$N=en(([{gap:e,sizes:t,totalCount:s},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:i,scrollingInProgress:a,scrollTop:l,viewportHeight:c},{scrollToIndex:u}])=>{const d=Xt();return mt(De(d,zt(t,c,s,i,o,r,l),zt(e),st(([[m,h,p,g,x,y,j,w],b])=>{const{calculateViewLocation:N=Q8,done:C,...E}=m,T=DN(m,h,g-1),k=Ba(T,h.offsetTree,b)+x+y,L=k+Xs(h.sizeTree,T)[1],F=w+y,A=w+p-j,D=N({itemBottom:L,itemTop:k,locationParams:E,viewportBottom:A,viewportTop:F});return D===null?C?.():C&&Us(De(a,wt(M=>!M),Do(Sn(a)?1:2)),C),D}),wt(m=>m!==null)),u),{scrollIntoView:d}},wn(hr,us,ul,$o,lo),{singleton:!0});function Dv(e){return e===!1?!1:e==="smooth"?"smooth":"auto"}const J8=(e,t)=>typeof e=="function"?Dv(e(t)):t&&Dv(e),Z8=en(([{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=ze(!1),x=Xt();let y=null;function j(C){Pt(a,{align:"end",behavior:C,index:"LAST"})}rn(De(Mn(De(yt(t),Do(1)),c),zt(yt(g),i,l,m),st(([[C,E],T,k,L,F])=>{let A=E&&L,D="auto";return A&&(D=J8(T,k||F),A=A&&D!==!1),{followOutputBehavior:D,shouldFollow:A,totalCount:C}}),wt(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:E})=>{y!==null&&(y(),y=null),Sn(s)===void 0?y=Us(e,()=>{Sn(d)("following output to ",{totalCount:E},Wn.DEBUG),j(C),y=null}):requestAnimationFrame(()=>{Sn(d)("following output to ",{totalCount:E},Wn.DEBUG),j(C)})});function w(C){const E=Us(o,T=>{C&&!T.atBottom&&T.notAtBottomBecause==="SIZE_INCREASED"&&y===null&&(Sn(d)("scrolling to bottom due to increased size",{},Wn.DEBUG),j("auto"))});setTimeout(E,100)}rn(De(Mn(yt(g),t,u),wt(([C,,E])=>C!==!1&&E),rr(({value:C},[,E])=>({refreshed:C===E,value:E}),{refreshed:!1,value:0}),wt(({refreshed:C})=>C),zt(g,t)),([,C])=>{Sn(l)&&w(C!==!1)}),rn(x,()=>{w(Sn(g)!==!1)}),rn(Mn(yt(g),o),([C,E])=>{C!==!1&&!E.atBottom&&E.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&j("auto")});const b=ze(null),N=Xt();return mt(Im(De(yt(r),st(C=>C?.length??0)),De(yt(t))),N),rn(De(Mn(De(N,Do(1)),c),zt(yt(b),l,m,h),st(([[C,E],T,k,L,F])=>E&&k&&T?.({context:F,totalCount:C,scrollingInProgress:L})),wt(C=>!!C),Nr(0)),C=>{y!==null&&(y(),y=null),Sn(s)===void 0?y=Us(e,()=>{Sn(d)("scrolling into view",{}),Pt(p,C),y=null}):requestAnimationFrame(()=>{Sn(d)("scrolling into view",{}),Pt(p,C)})}),{autoscrollToBottom:x,followOutput:g,scrollIntoViewOnChange:b}},wn(hr,ml,ul,fl,co,lo,us,zN,$N)),ez=en(([{data:e,firstItemIndex:t,gap:s,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:i,listState:a},{didMount:l}])=>(mt(De(l,zt(i),wt(([,c])=>c!==0),zt(o,r,t,s,e),st(([[,c],u,d,m,h,p=[]])=>BN(c,u,d,m,h,p))),a),{}),wn(hr,fl,$o,co),{singleton:!0}),tz=en(([{didMount:e},{scrollTo:t},{listState:s}])=>{const r=ze(0);return rn(De(e,zt(r),wt(([,o])=>o!==0),st(([,o])=>({top:o}))),o=>{Us(De(s,Do(1),wt(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{Pt(t,o)})})}),{initialScrollTop:r}},wn(co,us,$o),{singleton:!0}),VN=en(([{scrollVelocity:e}])=>{const t=ze(!1),s=Xt(),r=ze(!1);return mt(De(e,zt(r,t,s),wt(([o,i])=>i!==!1&&i!==void 0),st(([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),rn(De(Mn(t,e,s),zt(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(ml),{singleton:!0}),Jp=en(([{scrollContainerState:e,scrollTo:t}])=>{const s=Xt(),r=Xt(),o=Xt(),i=ze(!1),a=ze(void 0);return mt(De(Mn(s,r),st(([{scrollTop:l,viewportHeight:c},{offsetTop:u,listHeight:d}])=>({scrollHeight:d,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),mt(De(t,zt(r),st(([l,{offsetTop:c}])=>({...l,top:l.top+c}))),o),{customScrollParent:a,useWindowScroll:i,windowScrollContainerState:s,windowScrollTo:o,windowViewportRect:r}},wn(us)),nz=en(([{sizeRanges:e,sizes:t},{headerHeight:s,scrollTop:r},{initialTopMostItemIndex:o},{didMount:i},{useWindowScroll:a,windowScrollContainerState:l,windowViewportRect:c}])=>{const u=Xt(),d=ze(void 0),m=ze(null),h=ze(null);return mt(l,m),mt(c,h),rn(De(u,zt(t,r,a,m,h,s)),([p,g,x,y,j,w,b])=>{const N=F8(g.sizeTree);y&&j!==null&&w!==null&&(x=j.scrollTop-w.offsetTop),x-=b,p({ranges:N,scrollTop:x})}),mt(De(d,wt(Wp),st(sz)),o),mt(De(i,zt(d),wt(([,p])=>p!==void 0),yn(),st(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},wn(hr,us,fl,co,Jp));function sz(e){return{align:"start",index:0,offset:e.scrollTop}}const rz=en(([{topItemsIndexes:e}])=>{const t=ze(0);return mt(De(t,wt(s=>s>=0),st(s=>Array.from({length:s}).map((r,o)=>o))),e),{topItemCount:t}},wn($o));function HN(e){let t=!1,s;return(()=>(t||(t=!0,s=e()),s))}const oz=HN(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),iz=en(([{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(De(c,zt(a),rr(([,j,w,b],[{bottom:N,items:C,offsetBottom:E,totalCount:T},k])=>{const L=N+E;let F=0;return w===T&&j.length>0&&C.length>0&&(C[0].originalIndex===0&&j[0].originalIndex===0||(F=L-b,F!==0&&(F+=k))),[F,C,T,L]},[0,[],0,0]),wt(([j])=>j!==0),zt(r,l,s,o,p,g),wt(([,j,w,b,,,N])=>!N&&!b&&j!==0&&w===Fa),st(([[j],,,,,w])=>(w("Upward scrolling compensation",{amount:j},Wn.DEBUG),j))));function y(j){j>0?(Pt(t,{behavior:"auto",top:-j}),Pt(e,0)):(Pt(e,0),Pt(t,{behavior:"auto",top:-j}))}return rn(De(x,zt(e,i)),([j,w,b])=>{b&&oz()?Pt(e,w-j):y(-j)}),rn(De(Mn(ss(i,!1),e,g),wt(([j,w,b])=>!j&&!b&&w!==0),st(([j,w])=>w),Nr(1)),y),mt(De(m,st(j=>({top:-j}))),t),rn(De(u,zt(h,d),st(([j,{groupIndices:w,lastSize:b,sizeTree:N},C])=>{function E(A){return A*(b+C)}if(w.length===0)return E(j);let T=0;const k=La(N,0);let L=0,F=0;for(;L<j;){L++,T+=k;let A=w.length===F+1?1/0:w[F+1]-w[F]-1;L+A>j&&(T-=k,A=j-L+1),L+=A,T+=E(A),F++}return T})),j=>{Pt(e,j),requestAnimationFrame(()=>{Pt(t,{top:j}),requestAnimationFrame(()=>{Pt(e,0),Pt(g,!1)})})}),{deviation:e}},wn(us,ml,$o,hr,lo,Kp)),az=en(([e,t,s,r,o,i,a,l,c,u,d])=>({...e,...t,...s,...r,...o,...i,...a,...l,...c,...u,...d}),wn(Qp,ez,co,VN,FN,tz,X8,Jp,$N,lo,zN)),WN=en(([{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:y},j,w,b,N,{scrollToIndex:C},E,{topItemCount:T},{groupCounts:k},L])=>{const{listState:F,minOverscanItemCount:A,topItemsIndexes:D,rangeChanged:M,...H}=N;return mt(M,L.scrollSeekRangeChanged),mt(De(Mn(L.windowViewportRect,j.headerHeight,j.fixedHeaderHeight),st(([G,U,J])=>Math.max(U+J+1,G.visibleHeight))),j.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:s,fixedItemHeight:r,fixedGroupHeight:o,gap:i,groupCounts:k,heightEstimates:l,initialItemFinalLocationReached:g,initialTopMostItemIndex:x,scrolledToInitialItem:y,sizeRanges:u,topItemCount:T,topItemsIndexes:D,totalCount:h,...b,groupIndices:a,itemSize:c,listState:F,minOverscanItemCount:A,scrollToIndex:C,statefulTotalCount:m,trackItemSizes:p,rangeChanged:M,...H,...L,...j,sizes:d,...w}},wn(hr,fl,us,nz,Z8,$o,ul,iz,rz,ON,az));function lz(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 Pl=typeof document>"u"?Ue.useEffect:Ue.useLayoutEffect;function UN(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=Ue.createContext({});function c(y,j){y.propsReady!==void 0&&Pt(y.propsReady,!1);for(const w of r){const b=y[t.required[w]];Pt(b,j[w])}for(const w of o)if(w in j){const b=y[t.optional[w]];Pt(b,j[w])}y.propsReady!==void 0&&Pt(y.propsReady,!0)}function u(y){return i.reduce((j,w)=>(j[w]=b=>{const N=y[t.methods[w]];Pt(N,b)},j),{})}function d(y){return a.reduce((j,w)=>(j[w]=j8(y[t.events[w]]),j),{})}const m=Ue.forwardRef(function(y,j){const{children:w,...b}=y,[N]=Ue.useState(()=>Xd(S8(e),T=>{c(T,b)})),[C]=Ue.useState(kv(d,N));Pl(()=>{for(const T of a)T in b&&rn(C[T],b[T]);return()=>{Object.values(C).map(Up)}},[b,C,N]),Pl(()=>{c(N,b)}),Ue.useImperativeHandle(j,jv(u(N)));const E=s;return n.jsx(l.Provider,{value:N,children:s===void 0?w:n.jsx(E,{...lz([...r,...o,...a],b),children:w})})}),h=y=>{const j=Ue.useContext(l);return Ue.useCallback(w=>{Pt(j[y],w)},[j,y])},p=y=>{const j=Ue.useContext(l)[y],w=Ue.useCallback(b=>rn(j,b),[j]);return Ue.useSyncExternalStore(w,()=>Sn(j),()=>Sn(j))},g=y=>{const j=Ue.useContext(l)[y],[w,b]=Ue.useState(kv(Sn,j));return Pl(()=>rn(j,N=>{N!==w&&b(jv(N))}),[j,w]),w},x=parseInt(Ue.version,10)>=18?p:g;return{Component:m,useEmitter:(y,j)=>{const w=Ue.useContext(l)[y];Pl(()=>rn(w,j),[j,w])},useEmitterValue:x,usePublisher:h}}const GN=Ue.createContext(void 0),KN=Ue.createContext(void 0),Qu="-webkit-sticky",Ov="sticky",Zp=HN(()=>{if(typeof document>"u")return Ov;const e=document.createElement("div");return e.style.position=Qu,e.style.position===Qu?Qu:Ov}),qN=typeof document>"u"?Ue.useEffect:Ue.useLayoutEffect;function Ju(e){return"self"in e}function cz(e){return"body"in e}function YN(e,t,s,r=Di,o,i){const a=Ue.useRef(null),l=Ue.useRef(null),c=Ue.useRef(null),u=Ue.useCallback(h=>{let p,g,x;const y=h.target;if(cz(y)||Ju(y)){const w=Ju(y)?y:y.defaultView;x=i===!0?No(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?No(y,y.scrollLeft):y.scrollTop,p=i===!0?y.scrollWidth:y.scrollHeight,g=i===!0?y.offsetWidth:y.offsetHeight;const j=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:g})};h.suppressFlushSync===!0?j():bI.flushSync(j),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]);Ue.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,y,j;Ju(p)?(y=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,j=i===!0?No(p,p.scrollX):p.scrollY):(y=p[i===!0?"scrollWidth":"scrollHeight"],x=so(p,i===!0?"width":"height"),j=i===!0?No(p,p.scrollLeft):p.scrollTop);const w=y-x;if(h.top===void 0){p.scrollTo(h);return}const b=Math.ceil(Math.max(Math.min(w,h.top),0));if(h.top=b,_N(x,y)||b===j){e({scrollHeight:y,scrollTop:j,viewportHeight:x}),g&&t(!0);return}g?(l.current=b,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:Sv(p,b)}),p.scrollTo(h)}function m(h){i===!0&&(h={...h.behavior===void 0?{}:{behavior:h.behavior},...h.top===void 0?{}:{left:Sv(a.current,h.top)}}),a.current.scrollBy(h)}return{scrollByCallback:m,scrollerRef:a,scrollToCallback:d}}function ex(e){return e}const dz=en(()=>{const e=ze(l=>`Item ${l}`),t=ze(l=>`Group ${l}`),s=ze({}),r=ze(ex),o=ze("div"),i=ze(Di),a=(l,c=null)=>ss(De(s,st(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")}}),uz=en(([e,t])=>({...e,...t}),wn(WN,dz)),fz=({height:e})=>n.jsx("div",{style:{height:e}}),mz={overflowAnchor:"none",position:Zp(),zIndex:1},XN={overflowAnchor:"none"},hz={...XN,display:"inline-block",height:"100%"},Lv=Ue.memo(function({showTopList:e=!1}){const t=It("listState"),s=As("sizeRanges"),r=It("useWindowScroll"),o=It("customScrollParent"),i=As("windowScrollContainerState"),a=As("scrollContainerState"),l=o||r?i:a,c=It("itemContent"),u=It("context"),d=It("groupContent"),m=It("trackItemSizes"),h=It("itemSize"),p=It("log"),g=As("gap"),x=It("horizontalDirection"),{callbackRef:y}=A8(s,h,m,e?Di:l,p,g,o,x,It("skipAnimationFrameInResizeObserver")),[j,w]=Ue.useState(0);nx("deviation",H=>{j!==H&&w(H)});const b=It("EmptyPlaceholder"),N=It("ScrollSeekPlaceholder")??fz,C=It("ListComponent"),E=It("ItemComponent"),T=It("GroupComponent"),k=It("computeItemKey"),L=It("isSeeking"),F=It("groupIndices").length>0,A=It("alignToBottom"),D=It("initialItemFinalLocationReached"),M=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginInlineStart:j===0?A?"auto":0:j,paddingInlineEnd:t.offsetBottom,paddingInlineStart:t.offsetTop,whiteSpace:"nowrap"}:{marginTop:j===0?A?"auto":0:j,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&b!==null&&b!==void 0?n.jsx(b,{...ns(b,u)}):n.jsx(C,{...ns(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:M,children:(e?t.topItems:t.items).map(H=>{const G=H.originalIndex,U=k(G+t.firstItemIndex,H.data,u);return L?f.createElement(N,{...ns(N,u),height:H.size,index:H.index,key:U,type:H.type||"item",...H.type==="group"?{}:{groupIndex:H.groupIndex}}):H.type==="group"?f.createElement(T,{...ns(T,u),"data-index":G,"data-item-index":H.index,"data-known-size":H.size,key:U,style:mz},d(H.index,u)):f.createElement(E,{...ns(E,u),...vz(E,H.data),"data-index":G,"data-item-group-index":H.groupIndex,"data-item-index":H.index,"data-known-size":H.size,key:U,style:x?hz:XN},F?c(H.index,H.groupIndex,H.data,u):c(H.index,H.data,u))})})}),pz={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},xz={outline:"none",overflowX:"auto",position:"relative"},tx=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:void 0}),QN=(e,t,s=0)=>({...tx(e),position:t?"relative":"absolute",top:t?-s:0}),gz={position:Zp(),top:0,width:"100%",zIndex:1};function ns(e,t){if(typeof e!="string")return{context:t}}function vz(e,t){return{item:typeof e=="string"?void 0:t}}const bz=Ue.memo(function(){const e=It("HeaderComponent"),t=As("headerHeight"),s=It("HeaderFooterTag"),r=zo(Ue.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,It("skipAnimationFrameInResizeObserver")),o=It("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null}),yz=Ue.memo(function(){const e=It("FooterComponent"),t=As("footerHeight"),s=It("HeaderFooterTag"),r=zo(Ue.useMemo(()=>i=>{t(so(i,"height"))},[t]),!0,It("skipAnimationFrameInResizeObserver")),o=It("context");return e!=null?n.jsx(s,{ref:r,children:n.jsx(e,{...ns(e,o)})}):null});function JN({useEmitter:e,useEmitterValue:t,usePublisher:s}){return Ue.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}=YN(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?xz:pz,...o},tabIndex:0,...a,...ns(c,i),children:r})})}function ZN({useEmitter:e,useEmitterValue:t,usePublisher:s}){return Ue.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=Ue.useRef(null),g=t("scrollerRef"),{scrollByCallback:x,scrollerRef:y,scrollToCallback:j}=YN(l,u,c,g,h);return qN(()=>(y.current=h??p.current?.ownerDocument.defaultView,()=>{y.current=null}),[y,h]),e("windowScrollTo",j),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 wz=({children:e})=>{const t=Ue.useContext(GN),s=As("viewportHeight"),r=As("fixedItemHeight"),o=It("alignToBottom"),i=It("horizontalDirection"),a=Ue.useMemo(()=>jN(s,c=>so(c,i?"width":"height")),[s,i]),l=zo(a,!0,It("skipAnimationFrameInResizeObserver"));return Ue.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})},jz=({children:e})=>{const t=Ue.useContext(GN),s=As("windowViewportRect"),r=As("fixedItemHeight"),o=It("customScrollParent"),i=It("useWindowScroll"),a=It("topListHeight"),l=SN(s,o,It("skipAnimationFrameInResizeObserver")),c=It("alignToBottom");return Ue.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:QN(c,i,a),children:e})},kz=({children:e})=>{const t=It("TopItemListComponent")??"div",s=It("headerHeight"),r={...gz,marginTop:`${s}px`},o=It("context");return n.jsx(t,{style:r,...ns(t,o),children:e})},Nz=Ue.memo(function(e){const t=It("useWindowScroll"),s=It("topItemsIndexes").length>0,r=It("customScrollParent"),o=It("context");return n.jsxs(r||t?Iz:Cz,{...e,context:o,children:[s&&n.jsx(kz,{children:n.jsx(Lv,{showTopList:!0})}),n.jsxs(r||t?jz:wz,{children:[n.jsx(bz,{}),n.jsx(Lv,{}),n.jsx(yz,{})]})]})}),{Component:Sz,useEmitter:nx,useEmitterValue:It,usePublisher:As}=UN(uz,{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"}},Nz),Cz=JN({useEmitter:nx,useEmitterValue:It,usePublisher:As}),Iz=ZN({useEmitter:nx,useEmitterValue:It,usePublisher:As}),Tz=Sz,Az=en(()=>{const e=ze(u=>n.jsxs("td",{children:["Item $",u]})),t=ze(null),s=ze(u=>n.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=ze(null),o=ze(null),i=ze({}),a=ze(ex),l=ze(Di),c=(u,d=null)=>ss(De(i,st(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(WN,Az);Zp();const _v={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Ez={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Bv,floor:ld,max:ba,min:Zu,round:Fv}=Math;function zv(e,t,s){return Array.from({length:t-e+1}).map((r,o)=>({data:s===null?null:s[o+e],index:o+e}))}function Rz(e){return{...Ez,items:e}}function Dl(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function Mz(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}const Pz=en(([{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:y,useWindowScroll:j,windowScrollContainerState:w,windowScrollTo:b,windowViewportRect:N},C])=>{const E=ze(0),T=ze(0),k=ze(_v),L=ze({height:0,width:0}),F=ze({height:0,width:0}),A=Xt(),D=Xt(),M=ze(0),H=ze(null),G=ze({column:0,row:0}),U=Xt(),J=Xt(),$=ze(!1),oe=ze(0),Ne=ze(!0),ce=ze(!1),ne=ze(!1);rn(De(g,zt(oe),wt(([W,B])=>!Mm(B))),()=>{Pt(Ne,!1)}),rn(De(Mn(g,Ne,F,L,oe,ce),wt(([W,B,te,Z,,ue])=>W&&!B&&te.height!==0&&Z.height!==0&&!ue)),([,,,,W])=>{if(W===void 0){Pt(Ne,!0);return}Pt(ce,!0),Yp(1,()=>{Pt(A,W)}),Us(De(u),()=>{Pt(t,[0,0]),Pt(Ne,!0)})}),mt(De(J,wt(W=>W!=null&&W.scrollTop>0),tr(0)),T),rn(De(g,zt(J),wt(([,W])=>W!=null)),([,W])=>{W&&(Pt(L,W.viewport),Pt(F,W.item),Pt(G,W.gap),W.scrollTop>0&&(Pt($,!0),Us(De(u,Do(1)),B=>{Pt($,!1)}),Pt(c,{top:W.scrollTop})))}),mt(De(L,st(({height:W})=>W)),m),mt(De(Mn(yt(L,Dl),yt(F,Dl),yt(G,(W,B)=>W!==void 0&&W.column===B.column&&W.row===B.row),yt(u)),st(([W,B,te,Z])=>({gap:te,item:B,scrollTop:Z,viewport:W}))),U),mt(De(Mn(yt(E),r,yt(G,Mz),yt(F,Dl),yt(L,Dl),yt(H),yt(T),yt($),yt(Ne),yt(oe)),wt(([,,,,,,,W])=>!W),st(([W,[B,te],Z,ue,fe,Ce,de,,Ee,me])=>{const{column:Ve,row:at}=Z,{height:Fe,width:tt}=ue,{width:je}=fe;if(de===0&&(W===0||je===0))return _v;if(tt===0){const kt=Xp(me,W),mn=kt+Math.max(de-1,0);return Rz(zv(kt,mn,Ce))}const Je=eS(je,tt,Ve);let rt,K;Ee?B===0&&te===0&&de>0?(rt=0,K=de-1):(rt=Je*ld((B+at)/(Fe+at)),K=Je*Bv((te+at)/(Fe+at))-1,K=Zu(W-1,ba(K,Je-1)),rt=Zu(K,ba(0,rt))):(rt=0,K=-1);const Q=zv(rt,K,Ce),{bottom:Ae,top:pt}=$v(fe,Z,ue,Q),Dt=Bv(W/Je),Xe=Dt*Fe+(Dt-1)*at-Ae;return{bottom:Ae,itemHeight:Fe,items:Q,itemWidth:tt,offsetBottom:Xe,offsetTop:pt,top:pt}})),k),mt(De(H,wt(W=>W!==null),st(W=>W.length)),E),mt(De(Mn(L,F,k,G),wt(([W,B,{items:te}])=>te.length>0&&B.height!==0&&W.height!==0),st(([W,B,{items:te},Z])=>{const{bottom:ue,top:fe}=$v(W,Z,B,te);return[fe,ue]}),yn(_a)),t);const Y=ze(!1);mt(De(u,zt(Y),st(([W,B])=>B||W!==0)),Y);const pe=gs(De(Mn(k,E),wt(([{items:W}])=>W.length>0),zt(Y),wt(([[W,B],te])=>{const Z=W.items[W.items.length-1].index===B-1;return(te||W.bottom>0&&W.itemHeight>0&&W.offsetBottom===0&&W.items.length===B)&&Z}),st(([[,W]])=>W-1),yn())),ge=gs(De(yt(k),wt(({items:W})=>W.length>0&&W[0].index===0),tr(0),yn())),we=gs(De(yt(k),zt($),wt(([{items:W},B])=>W.length>0&&!B),st(([{items:W}])=>({endIndex:W[W.length-1].index,startIndex:W[0].index})),yn(RN),Nr(0)));mt(we,p.scrollSeekRangeChanged),mt(De(A,zt(L,F,E,G),st(([W,B,te,Z,ue])=>{const fe=LN(W),{align:Ce,behavior:de,offset:Ee}=fe;let me=fe.index;me==="LAST"&&(me=Z-1),me=ba(0,me,Zu(Z-1,me));let Ve=Pm(B,ue,te,me);return Ce==="end"?Ve=Fv(Ve-B.height+te.height):Ce==="center"&&(Ve=Fv(Ve-B.height/2+te.height/2)),Ee!==void 0&&Ee!==0&&(Ve+=Ee),{behavior:de,top:Ve}})),c);const V=ss(De(k,st(W=>W.offsetBottom+W.bottom)),0);return mt(De(N,st(W=>({height:W.visibleHeight,width:W.visibleWidth}))),L),{customScrollParent:y,data:H,deviation:M,footerHeight:o,gap:G,headerHeight:i,increaseViewportBy:e,initialItemCount:T,itemDimensions:F,overscan:s,restoreStateFrom:J,scrollBy:a,scrollContainerState:l,scrollHeight:D,scrollTo:c,scrollToIndex:A,scrollTop:u,smoothScrollTargetReached:d,totalCount:E,useWindowScroll:j,viewportDimensions:L,windowScrollContainerState:w,windowScrollTo:b,windowViewportRect:N,...p,gridState:k,horizontalDirection:ne,initialTopMostItemIndex:oe,totalListHeight:V,...h,endReached:pe,propsReady:x,rangeChanged:we,startReached:ge,stateChanged:U,stateRestoreInProgress:$,...C}},wn(Qp,us,ml,VN,co,Jp,lo));function eS(e,t,s){return ba(1,ld((e+s)/(ld(t)+s)))}function $v(e,t,s,r){const{height:o}=s;if(o===void 0||r.length===0)return{bottom:0,top:0};const i=Pm(e,t,s,r[0].index);return{bottom:Pm(e,t,s,r[r.length-1].index)+o,top:i}}function Pm(e,t,s,r){const o=eS(e.width,s.width,t.column),i=ld(r/o),a=i*s.height+ba(0,i-1)*t.row;return a>0?a+t.row:a}const Dz=en(()=>{const e=ze(m=>`Item ${m}`),t=ze({}),s=ze(null),r=ze("virtuoso-grid-item"),o=ze("virtuoso-grid-list"),i=ze(ex),a=ze("div"),l=ze(Di),c=(m,h=null)=>ss(De(t,st(p=>p[m]),yn()),h),u=ze(!1),d=ze(!1);return mt(yt(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")}}),Oz=en(([e,t])=>({...e,...t}),wn(Pz,Dz)),Lz=Ue.memo(function(){const e=bn("gridState"),t=bn("listClassName"),s=bn("itemClassName"),r=bn("itemContent"),o=bn("computeItemKey"),i=bn("isSeeking"),a=Es("scrollHeight"),l=bn("ItemComponent"),c=bn("ListComponent"),u=bn("ScrollSeekPlaceholder"),d=bn("context"),m=Es("itemDimensions"),h=Es("gap"),p=bn("log"),g=bn("stateRestoreInProgress"),x=Es("reportReadyState"),y=zo(Ue.useMemo(()=>j=>{const w=j.parentElement.parentElement.scrollHeight;a(w);const b=j.firstChild;if(b!==null){const{height:N,width:C}=b.getBoundingClientRect();m({height:N,width:C})}h({column:Vv("column-gap",getComputedStyle(j).columnGap,p),row:Vv("row-gap",getComputedStyle(j).rowGap,p)})},[a,m,h,p]),!0,!1);return qN(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),g?null:n.jsx(c,{className:t,ref:y,...ns(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(j=>{const w=o(j.index,j.data,d);return i?n.jsx(u,{...ns(u,d),height:e.itemHeight,index:j.index,width:e.itemWidth},w):f.createElement(l,{...ns(l,d),className:s,"data-index":j.index,key:w},r(j.index,j.data,d))})})}),_z=Ue.memo(function(){const e=bn("HeaderComponent"),t=Es("headerHeight"),s=bn("headerFooterTag"),r=zo(Ue.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}),Bz=Ue.memo(function(){const e=bn("FooterComponent"),t=Es("footerHeight"),s=bn("headerFooterTag"),r=zo(Ue.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}),Fz=({children:e})=>{const t=Ue.useContext(KN),s=Es("itemDimensions"),r=Es("viewportDimensions"),o=zo(Ue.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return Ue.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})},zz=({children:e})=>{const t=Ue.useContext(KN),s=Es("windowViewportRect"),r=Es("itemDimensions"),o=bn("customScrollParent"),i=bn("useWindowScroll"),a=SN(s,o,!1);return Ue.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:QN(!1,i),children:e})},$z=Ue.memo(function({...e}){const t=bn("useWindowScroll"),s=bn("customScrollParent"),r=s||t?Hz:Vz,o=s||t?zz:Fz,i=bn("context");return n.jsx(r,{...e,...ns(r,i),children:n.jsxs(o,{children:[n.jsx(_z,{}),n.jsx(Lz,{}),n.jsx(Bz,{})]})})}),{useEmitter:tS,useEmitterValue:bn,usePublisher:Es}=UN(Oz,{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"}},$z),Vz=JN({useEmitter:tS,useEmitterValue:bn,usePublisher:Es}),Hz=ZN({useEmitter:tS,useEmitterValue:bn,usePublisher:Es});function Vv(e,t,s){return t!=="normal"&&t?.endsWith("px")!==!0&&s(`${e} was not resolved to pixel value correctly`,t,Wn.WARN),t==="normal"?0:parseInt(t??"0",10)}function NJ(){const{t:e}=z();return jt(t=>t.secretary.profile?.name.trim())||e("Secretary")}function nS(){const e=jt(r=>r.secretary.enabled?r.secretary.profile:null),t=jt(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:Ka(s,e.avatar.imageHash,t)}:{}}}const Jd=f.createContext(null);function ws(){return f.useContext(Jd)}function Wz({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 Uz={rows:new Set,expanded:new Set};function Gz(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 Kz({loading:e=!1,runStartedAt:t}){if(!e)return t}function qz(e){return e==="right"||e==="off"?e:"left"}function Yz(e,t,s){return e!=="off"&&!t&&s>=2}const Ol=40;function Xz({items:e,activeKey:t,onJump:s}){const r=xe(g=>g.chatWide),o=qz(xe(g=>g.navRailSide)),[i,a]=f.useState(null);if(!Yz(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(Ol/2)),Math.max(0,e.length-Ol)),d=e.slice(u,u+Ol),m=u>0,h=u+Ol<e.length,p=(g,x)=>{const y=x?24:12;if(i===null)return y;const j=Math.abs(g-i),w=Math.max(0,16-j*6);return y+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 y=g.key===t,j=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",y||j?"h-[3px] bg-foreground":"h-[2px] bg-muted-foreground/40"),style:{width:p(x,y)}})},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 gc="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 sS(e){return e.content.filter(t=>t.type==="text").map(t=>t.text??"").join("").trim()}function SJ(e){const t=[];for(const s of e){if(s.role!=="user"&&s.role!=="assistant")continue;const r=sS(s);r&&t.push(`${s.role==="user"?"User":"Assistant"}: ${r}`)}return t.slice(-40).join(`
22
- `)}function CJ(e){for(const t of[...e].reverse()){if(t.role!=="assistant")continue;const s=sS(t);if(s)return s}return""}function IJ(e,t){if(e!=="contextual")return gc;const s=t.trim();return s?`${gc}
23
-
24
- # Main conversation (background only)
25
- ${s}`:gc}function Qz(e){return e.startsWith(gc)}function TJ(e){const t=e.trim();return t?`Treat the following as discussion context from a side conversation, not as work already completed.
26
-
27
- `+t:""}function Jz(e){const t=new Date(e),s=r=>String(r).padStart(2,"0");return`${s(t.getHours())}:${s(t.getMinutes())}:${s(t.getSeconds())}`}const Hv={zh:{quit:"被关闭",update:"被关闭(安装更新)"},en:{quit:"was closed",update:"was closed (installing an update)"}};function Zz(e){const t=Jz(e.at),s=[...new Set(e.unfinishedTools)];if(e.lang==="en"){const i=`The app ${Hv.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} ${Hv.zh[e.kind]},这一轮被中断。`,o=s.length>0?`中断时有 ${s.length} 个工具调用没有结果(${s.join("、")}),可能只执行了一半,继续前请先检查。`:"";return`${r}${o}`}function e$(e){const t=Zz(e);return e.lang==="en"?`${t} You can retry to continue.`:`${t}可以点重试继续。`}new TextEncoder;function ef(e){if(e)try{return decodeURIComponent(e)}catch{return e}}const tf="([A-Za-z0-9._@:+/=%-]+)",t$=new RegExp(String.raw`^\[(?:来自|From) ([^\]\n@·「」]{1,40}?)`+String.raw`(?: (私聊|private|群|group)(?:「([^」\]\n]{1,64})」)?)?`+`(?: chatId=${tf})?(?: topicId=${tf})?(?: senderId=${tf}| (发送者未知|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${jI})*)$`,"u");function n$(e){const t=t$.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,y={chat:ef(i),topic:ef(a),sender:ef(l)},j=yI(g),w=g?wI(g.slice(1)):null;return{channel:h,title:s,...y.chat?{chatId:y.chat}:{},...x?{chatType:x}:{},...x==="group"&&o?{chatTitle:o}:{},...y.topic?{topicId:y.topic}:{},...y.sender?{senderId:y.sender}:{},...c?{senderUnknown:!0}:{},...u?{username:u}:{},...d&&m?{time:`${d}:${m}`}:{},body:p.split("<\\/untrusted-content").join("</untrusted-content"),...j.length?{images:j}:{},...w?.length?{imageLines:w}:{}}}const s$="agent-notification|goal-continuation|coworker-hired|coworker-dismissed|background-task-update|session-updates|secretary-schedule|secretary-message",r$=new RegExp(`<(${s$})>\\n?([\\s\\S]*?)\\n?</\\1>`,"g"),o$=/\n(?=Work toward this goal autonomously\.|Continue working toward it\.)/;function i$(e){const s=(e.split(`
28
- `).map(r=>r.trim()).find(Boolean)??"").split(/(?<=[。!?.!?])\s*/)[0]?.trim()??"";return s.length<=72?s:`${s.slice(0,72)}…`}function a$(e){const t=e.trim(),s=/^(?:Session goal(?: resumed)?:[ \t]*)([\s\S]*)$/.exec(t),r=(s?s[1]:t).trim(),o=r.search(o$);return o<0?{goal:r,instructions:""}:{goal:r.slice(0,o).trim(),instructions:r.slice(o).trim()}}function l$(e){const t=[],s=new RegExp(r$.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",...a$(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 c$=/^<\/?(?:agent-notification|goal-continuation|coworker-hired|coworker-dismissed|background-task-update|session-updates|secretary-schedule|secretary-message)>$/;function sx(e){return e.split(`
29
- `).filter(t=>!c$.test(t.trim())).join(`
30
- `).trim()}function Dm(e){return e.length<=72?e:`${e.slice(0,72)}…`}function d$(e){const t=e.trim(),s=t.indexOf(`
31
- `),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:Dm(i),body:a?`${i}
32
- ${a.trim()}`:i}}}return{summary:Dm(r),body:t}}function u$(e){const t=sx(e);return t?t.split(/\n(?=- \[schedule\])/).map(s=>d$(s.replace(/^- \[schedule\][ \t]?/,""))).filter(s=>s.body.length>0):[]}function f$(e){const t=sx(e).replace(/^- \[[a-z-]+(?: session:[^\]]+)?\][ \t]?/gm,"").trim(),s=t.split(`
33
- `).map(r=>r.trim()).find(Boolean);return{summary:Dm(s??""),body:t}}const m$=/^<(session-updates|secretary-schedule)>\n([\s\S]*?)\n<\/\1>(?:\n|$)/,h$=/^- \[([a-z-]+)(?: (?:session|pending):([^\]\s]+))?\] ([^\n]*)(?:\n|$)/,p$=/^<untrusted-content source="[^"]*">/,Wv="</untrusted-content>";function x$(e){return kI.includes(e)}function g$(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:x$(t)?s?{kind:t,text:r,conversationId:s}:{kind:t,text:r}:null}function v$(e,t){const s=[];let r=t;for(;r;){const o=h$.exec(r),i=o&&g$(e,o[1],o[2],o[3]);if(!o||!i)return null;r=r.slice(o[0].length);const a=p$.exec(r);if(a){const l=r.indexOf(Wv);if(l<0)return null;if(i.detail=r.slice(a[0].length,l).split("<\\/untrusted-content").join("</untrusted-content"),r=r.slice(l+Wv.length),r.startsWith(`
34
- `))r=r.slice(1);else if(r)return null}s.push(i)}return s.length>0?s:null}function rS(e){const t=[];let s=e.trim();for(;s;){const r=m$.exec(s),o=r&&v$(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 b$="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.",y$="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.",w$="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.",j$=new Set([b$,y$,w$]);function k$(e){const t=e.split(`
35
- `);let s=0;for(;s<t.length&&j$.has(t[s].replace(/\r$/,""));)s++;if(s===0)return e;for(;s<t.length&&!t[s].trim();)s++;return t.slice(s).join(`
36
- `)||e}const N$=/^Command exited with code \d+$/,Uv=/^Command (?:aborted|timed out after \d+ seconds|terminated without an exit code)/,S$=/^\[[^\]]+\]/,C$=/^at\s/,I$=/\b(?:error|fatal|panic|exception|failed|failure|cannot|not found|no such file|denied|refused)\b(?!\.\w|\()/i;function T$(e){const t=k$(e).split(/\r?\n/).map(r=>r.trim()),s=t.findLastIndex(r=>N$.test(r)||Uv.test(r));if(s<0)return t.find(Boolean)??"";if(Uv.test(t[s]))return t[s];for(let r=s-1;r>=0;r--){const o=t[r];if(o&&!S$.test(o)&&!C$.test(o)&&I$.test(o))return o}return t[s]}function A$({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"?Hd:e.kind==="group"?Jr:e.kind==="delegation-task"?vi:e.kind==="delegation-retry"||e.kind==="delegation-check-failed"?Eo:$4,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 oS(e,t){const s=await X.getState().reloadConversation(e);s&&Ie({type:"error",title:t("Failed to reload conversation"),description:s})}async function iS(e,t){const s=await X.getState().restartConversation(e);s&&Ie({type:"error",title:t("Failed to restart conversation"),description:s})}function E$(e,t){if(!t)return null;for(const[s,r]of Object.entries(e))if(r?.sessionFile===t)return s;return null}function R$(e,t){if(!t)return"";const s=e.find(r=>r.id===t.providerId);return s?`${s.name} / ${t.modelId}`:t.modelId}const M$=new Set(["session_create","todo_item_dispatch","secretary_profile_propose","skill_propose","tool_propose","session_takeover_propose","cleanup_apply"]);function P$(e){if(!M$.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 Oi={pending:"Waiting for your confirmation",executing:"Creating the session…",succeeded:"Session created",failed:"Failed",rejected:"Rejected",expired:"Expired"},D$={...Oi,executing:"Saving the profile…",succeeded:"Profile saved"};function Oo(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 O$(e){return e.draft.title?.trim()||e.draft.prompt.split(`
37
- `)[0]?.trim()||""}function L$({proposalId:e,prominent:t}){const{t:s}=z(),r=jt(m=>m.secretary.proposals[e]),o=jt(m=>m.resolving[e]===!0),i=jt(m=>m.resolveProposal),a=xe(m=>m.projects),l=xe(m=>m.providers)??[];if(!r)return n.jsx("div",{"data-enso":"secretary-proposal",className:_(Oo(t),"text-[11px] text-muted-foreground"),children:s("Waiting for your confirmation")});if(r.kind==="profile")return n.jsx(_$,{proposal:r,prominent:t});if(r.kind==="skill")return n.jsx(H$,{proposal:r,prominent:t});if(r.kind==="tool")return n.jsx(V$,{proposal:r,prominent:t});if(r.kind==="takeover")return n.jsx($$,{proposal:r,prominent:t});if(r.kind==="cleanup")return n.jsx(q$,{proposal:r,prominent:t});const c=a.find(m=>m.id===r.draft.projectId),u=r.status==="failed",d=R$(l,r.draft.model);return n.jsxs("div",{"data-enso":"secretary-proposal",className:Oo(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")}),c&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:Un(c)}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:O$(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||d||(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})}),d&&n.jsx("span",{"data-enso":"secretary-proposal-model",children:s("Model: {{model}}",{model:d})}),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]",u?"text-destructive":"text-muted-foreground"),children:[s(Oi[r.status]),u&&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 _$({proposal:e,prominent:t}){const{t:s}=z(),r=jt(d=>d.resolving[e.id]===!0),o=jt(d=>d.resolveProposal),[i,a]=f.useState(!1),l=e.draft,c=e.status==="failed",u=f.useMemo(()=>({...NI(null,s("Secretary")),...l}),[l,s]);return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"profile",className:Oo(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(gw,{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(D$[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 B$={...Oi,executing:"Saving the skill…",succeeded:"Skill saved"},F$={...Oi,executing:"Saving the tool…",succeeded:"Tool saved"},z$={...Oi,executing:"Handing it over…",succeeded:"Handed over to the secretary"};function $$({proposal:e,prominent:t}){const{t:s}=z(),r=jt(c=>c.resolving[e.id]===!0),o=jt(c=>c.resolveProposal),a=xe(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:Oo(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:Un(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(z$[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 V$({proposal:e,prominent:t}){const{t:s}=z(),r=jt(l=>l.resolving[e.id]===!0),o=jt(l=>l.resolveProposal),i=e.draft,a=e.status==="failed";return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"tool",className:Oo(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(F$[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 H$({proposal:e,prominent:t}){const{t:s}=z(),r=jt(l=>l.resolving[e.id]===!0),o=jt(l=>l.resolveProposal),i=e.draft,a=e.status==="failed";return n.jsxs("div",{"data-enso":"secretary-proposal","data-kind":"skill",className:Oo(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(B$[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 W$={...Oi,executing:"Cleaning up…",succeeded:"Cleanup done"},Gv={branch:"Branch",worktree:"Worktree",session:"Session"},U$={"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 G$(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 K$=5;function q$({proposal:e,prominent:t}){const{t:s}=z(),r=jt(d=>d.resolving[e.id]===!0),o=jt(d=>d.resolveProposal),i=e.draft.items,a=i.slice(0,K$),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:Oo(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(Gv[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=G$(d.sizeBytes),h=[d.mergedInto?.length?s("merged into {{refs}}",{refs:d.mergedInto.join(", ")}):null,m,d.blocked?s(U$[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(Gv[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(W$[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 Y$(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 X$(e){const t=await Y$(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 hl({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);oh(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=()=>{X$(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(Yt,{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 Q$={"too-large":"over 10 MB, not saved","not-image":"not a png / jpeg / webp / gif image, not saved",unavailable:"could not be saved"};function J$(e){return e.split(/[\\/]/u).pop()??e}function aS({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(hl,{src:Cc(a.path),title:J$(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(SI,{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(Q$[a.rejected])})},a.index))]})}function Z$(e){const s=(e.split(`
38
- `).map(r=>r.replace(/^[#>\-*\s]+/u,"").trim()).find(Boolean)??"").replace(/\s+/gu," ");return s.length>60?`${s.slice(0,60)}…`:s}function eV({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(Ud,{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:Z$(e.body)})]}),n.jsx("div",{className:"mt-1.5 break-words",children:n.jsx(Gn,{text:e.body})})]}),e.imageLines&&n.jsx("div",{className:"mt-1.5",children:n.jsx(aS,{entries:e.imageLines,align:"start"})})]})}const lS=new Map;let ni;function tV(e){if(ni?.revision===e)return ni.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:lS})),s={revision:e,request:t,data:void 0};return ni=s,t.then(r=>{ni===s&&(s.data=r)}),t}function nV(){const e=Lo(r=>r.snapshot.revision),[t,s]=f.useState(()=>ni?.revision===e?ni.data:void 0);return f.useEffect(()=>{let r=!1;return tV(e).then(o=>{r||s(o)}),()=>{r=!0}},[e]),t?.revision===e?t.emails:lS}function Kv(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 sV(e,t,s){return`${e}:${Kv(t)}:${Kv(s,1)}`}const rV=/(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c|$)/g,oV=/(?:\x1b\[|\x9b)[0-?]*[ -/]*(?:[@-~]|$)/g;function Ls(e){return e.replace(rV,"").replace(oV,"")}const Ur=Dr()(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 iV(e,t,s){Ur.getState().open(e,t,s)}const xi=Dr()(()=>({back:null}));function Om(e){return X.getState().conversations[e]?.parentId??e}function qv(e){const t=X.getState().conversations[e]?.projectId;return xe.getState().projects.some(s=>s.id===t&&s.kind==="secretary")}let Yv=!1;function aV(){Yv||(Yv=!0,X.subscribe((e,t)=>{if(e.activeId===t.activeId)return;const{back:s}=xi.getState();s&&(!e.activeId||Om(e.activeId)!==s.to)&&xi.setState({back:null})}))}function Va(e,t){const s=X.getState();if(!s.conversations[e])return;const r=t??s.activeId,o=r?Om(r):null,i=Om(e);aV(),Ur.getState().close(),s.selectConversation(e),xi.setState({back:o&&o!==i&&qv(o)&&!qv(i)?{from:o,to:i}:null})}function lV(){const{back:e}=xi.getState();e&&(xi.setState({back:null}),X.getState().selectConversation(e.from))}function cV(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 dV(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 uV(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 y=x.timing,j=dV(x);j!==void 0&&(l+=j);const w=cV(x);w!==void 0&&(u+=w,d+=1);const b=x.usage?.output??0;j!==void 0&&j>0&&b>0&&(m+=j,h+=b),y&&(p!==null&&(c+=Math.max(0,y.stepStartMs-p)),p=y.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 fV(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 Xv=Dr(e=>({byConversation:{},replace:(t,s)=>e(r=>{const o={...r.byConversation};if(s.length>0)o[t]=s;else if(o[t])delete o[t];else return r;return{byConversation:o}})})),mV={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 hV({value:e}){const t=CI(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(mV[t.reason])]})]})]})}function pV({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(Qv,{selected:o===e.answer,text:o},o)),r!==null&&n.jsx(Qv,{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 Qv({selected:e,text:t,label:s}){const{t:r}=z(),o=e?hh:Sp;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 xV=/^Subagent ".*" \(agentId [^,\s]+, runId [^)\s]+\) \S+ after .+\.$/gm,gV=/^The following is the subagent's report: .*$\n?/m,vV=/<usage>([\s\S]*?)<\/usage>/,bV=/^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 yV(e){const t=e.indexOf(`
39
- `),s=t<0?e:e.slice(0,t);let r=t<0?"":e.slice(t+1),o=null,i=[];const a=vV.exec(r);if(a){const l=bV.exec(r.slice(a.index+a[0].length));l&&(i=l[1].split(`
40
- `).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(gV,"").trim(),usage:o,...i.length>0?{tasks:i}:{}}}function wV(e){const t=e.trim(),s=[...t.matchAll(xV)].map(r=>r.index);return s[0]!==0?null:s.map((r,o)=>yV(t.slice(r,s[o+1]).replace(/\n+---\s*$/,"").trim()))}const jV=["system","memory","tools","skills","files","results","chat"];function cS(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 jV.flatMap(r=>{const o=s.get(r)??0;return o<=0?[]:[{kind:r,tokens:o,width:Math.round(o/t*1e3)/10}]})}const Ll=8,Jv=(e,t)=>e.reduce((s,r)=>s+(r.tag===t?r.n??1:1),0),Zv=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<=Ll)return s;if(t==="chat"){const o=s.filter(c=>c.tag==="compacted"),i=s.filter(c=>c.tag!=="compacted"),a=Ll-o.length-1,l=i.slice(0,i.length-a);return[...o,{name:"earlier",tag:"turns",n:Jv(l,"turns"),tokens:Zv(l)},...i.slice(i.length-a)]}const r=s.slice(Ll-1);return[...s.slice(0,Ll-1),{name:"other",tag:"more",n:Jv(r,"more"),tokens:Zv(r)}]}function kV(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 NV(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 SV(e,t,s){const r=()=>{const o=II(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 dS="rounded-lg border border-border/60 bg-muted/20 px-2.5 py-1.5 text-xs";function uS({className:e}){return n.jsx(Ai,{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",ox=_(rx,"px-3 py-2"),Zd="mt-0.5 h-3.5 w-3.5 shrink-0";function Lm({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(IV,{hit:r,defaultOpen:t},r.id))})}function CV({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(Lm,{hits:[e.memory],defaultOpen:!0}):n.jsx(Lm,{hits:e.candidates})]})}function IV({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(fi,{variant:"secondary",size:"sm",children:e.unitType}),e.space&&n.jsx(fi,{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 TV={"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 eu(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",TV[e])}function AV({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(Zt,{className:"h-3 w-3"})})}function EV({recipient:e,onRemove:t}){const{t:s}=z();return n.jsxs("span",{className:_(eu("agent-type"),"mt-0.5 shrink-0"),children:[n.jsx(_s,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:e.label}),n.jsx(AV,{label:s("Remove Agent recipient"),onRemove:t}),n.jsx("span",{className:"sr-only",children:e.typeKey})]})}const fS=f.createContext(void 0);function pl(e){const t=f.useContext(fS);if(t===void 0&&!e)throw new Error(qa(50));return t}const RV=600,mS=300,MV={...AI,instantType:e=>e.instantType,adaptiveOrigin:e=>e.adaptiveOrigin,closeDelay:e=>e.closeDelay};class PV extends TI{constructor(t,s,r){const o=new PI;super(DV(t,o,s,r),OV(o),MV)}setOpen=(t,s)=>{const{inlineRectCoordsRef:r}=this.context;EI(this,t,s,{onBeforeDispatch(){const o=s.event;t&&s.reason===DI&&s.trigger&&"clientX"in o&&"clientY"in o&&r.current?.element!==s.trigger&&rN(r,s.trigger,o.clientX,o.clientY)}})}}function DV(e,t,s,r=!1){const o={...RI(),instantType:void 0,adaptiveOrigin:void 0,closeDelay:mS,...e};return o.floatingRootContext=MI(t,s,r),o}function OV(e){return{popupRef:f.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e,inlineRectCoordsRef:{current:void 0}}}function tb(e){const{open:t,defaultOpen:s=!1,onOpenChange:r,onOpenChangeComplete:o,actionsRef:i,handle:a,triggerId:l,defaultTriggerId:c=null,children:u}=e,d=_I((j,w)=>new PV({open:s,openProp:t,activeTriggerId:c,triggerIdProp:l},j,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");BI(d,{closeOnActiveTriggerUnmount:!0});const{forceUnmount:x}=FI(m,d,()=>{d.context.inlineRectCoordsRef.current=void 0});ph(()=>{m&&h==null&&d.set("payload",void 0)},[d,h,m]),f.useImperativeHandle(i,()=>({unmount:x,close:()=>d.setOpen(!1,zI($I))}),[x,d]);const y=m||p;return n.jsxs(fS.Provider,{value:d,children:[a&&n.jsx(VI,{handle:a,store:d}),y&&n.jsx(LV,{store:d}),typeof u=="function"?u({payload:g}):u]})}function LV({store:e}){const t=e.useState("floatingRootContext"),s=HI(t);return WI(e,{activeTriggerProps:s.reference,inactiveTriggerProps:s.trigger,popupProps:s.floating}),null}const _V=OI(function(t){return pl(!0)?n.jsx(tb,{...t}):n.jsx(LI,{children:n.jsx(tb,{...t})})}),hS=f.createContext(void 0);function BV(){const e=f.useContext(hS);if(e===void 0)throw new Error(qa(48));return e}const FV=f.forwardRef(function(t,s){const{keepMounted:r=!1,...o}=t;return pl().useState("mounted")||r?n.jsx(hS.Provider,{value:r,children:n.jsx(UI,{ref:s,...o})}):null}),zV=GI(function(t,s){const{render:r,className:o,delay:i,closeDelay:a,id:l,payload:c,handle:u,style:d,...m}=t,h=pl(!0),g=KI(u)??h;if(!g)throw new Error(qa(89));const x=vw(l),y=g.useState("isTriggerActive",x),j=g.useState("isOpenedByTrigger",x),w=g.useState("floatingRootContext"),b=g.context.inlineRectCoordsRef,N=f.useRef(null),C=i??RV,E=a??mS,{registerTrigger:T,isMountedByThisTrigger:k}=qI(x,N,g,{payload:c,closeDelay:E}),L=YI(w,{mouseOnly:!0,move:!1,handleClose:XI(),delay:()=>({open:C,close:E}),triggerElementRef:N,isActiveTrigger:y,isClosing:()=>g.select("transitionStatus")==="ending"}),F=QI(w,{delay:C}),A={open:j},D=g.useState("triggerProps",k),M=yF(b,j);return Ya("a",t,{state:A,ref:[s,T,N],props:[L,F.reference,D,M,{id:x},m],stateAttributesMapping:JI})}),pS=f.createContext(void 0);function $V(){const e=f.useContext(pS);if(e===void 0)throw new Error(qa(49));return e}const VV=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:y=ZI,style:j,...w}=t,b=pl(),N=BV(),C=e5(),E=b.useState("open"),T=b.useState("mounted"),k=b.useState("floatingRootContext"),L=b.useState("instantType"),F=b.useState("transitionStatus"),A=b.useState("adaptiveOrigin"),D=b.context.inlineRectCoordsRef,M=t5({anchor:i,floatingRootContext:k,positionMethod:a,mounted:T,side:l,sideOffset:u,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:h,sticky:g,disableAnchorTracking:x,keepMounted:N,nodeId:C,collisionAvoidance:y,adaptiveOrigin:A,inline:wF(D)}),H=M.update;ph(()=>{E&&T&&H()},[E,T,H]);const G={open:E,side:M.side,align:M.align,anchorHidden:M.anchorHidden,instant:L},U=n5(t,G,{styles:M.positionerStyles,transitionStatus:F,props:w,refs:[s,b.useStateSetter("positionerElement")],hidden:!T,inert:!E});return n.jsx(pS.Provider,{value:M,children:n.jsx(s5,{id:C,children:U})})}),HV=f.forwardRef(function(t,s){const{className:r,render:o,style:i,...a}=t,l=pl(),{side:c,align:u}=$V(),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 r5({open:d,ref:l.context.popupRef,onComplete(){d&&l.context.onOpenChangeComplete?.(!0)}}),o5(g,{closeDelay:x}),Ya("div",t,{state:{open:d,side:c,align:u,instant:m,transitionStatus:h},ref:[s,l.context.popupRef,l.useStateSetter("popupElement")],props:[i5,p,l5(h),a],stateAttributesMapping:a5})}),xl=_V;function gl({...e}){return n.jsx(zV,{"data-slot":"preview-card-trigger",...e})}function tu({className:e,children:t,align:s="center",sideOffset:r=4,...o}){return n.jsx(FV,{children:n.jsx(VV,{align:s,className:"z-50","data-slot":"preview-card-positioner",sideOffset:r,children:n.jsx(HV,{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 nb={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},WV={mask:Sd,warn:Ao,block:bw},UV={mask:"Mask",warn:"Warn only",block:"Block"},GV={system:"System prompt",user:"Your message",tool_result:"Tool output",tool_args:"Tool arguments",assistant:"Earlier replies",tools:"Tool descriptions"};function KV({report:e}){const{t}=z(),s=c5(e);if(!s)return null;const r=WV[s],o=new Set(e.hits.map(i=>i.token)).size;return n.jsxs(xl,{children:[n.jsxs(gl,{render:n.jsx("span",{className:_("inline-flex shrink-0 items-center gap-0.5 text-[11px]",nb[s]),"data-privacy-mask":s}),children:[n.jsx(r,{className:"size-3.5"}),n.jsx("span",{className:"tabular-nums",children:o})]}),n.jsxs(tu,{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:d5(e.hits).map(i=>n.jsxs("li",{className:"flex flex-wrap gap-x-2",children:[n.jsx("span",{className:nb[i.action],children:t(UV[i.action])}),n.jsx("span",{children:i.kind}),n.jsx("span",{className:"text-muted-foreground",children:t(GV[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 qV(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 YV={compressed:"Compressed",unchanged:"Unchanged",pending:"Background task started",bypassed:"Bypassed",unavailable:"Unavailable"};function XV({value:e}){const t=bB(e),{t:s}=z();if(!t)return null;const r=qV(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(YV[t.status])}),r&&n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":"true",children:"·"}),n.jsx("span",{children:s("~{{count}} tokens saved",{count:$n(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:$n(t.inputTokens)})}),n.jsx("dt",{children:s("Output estimate")}),n.jsx("dd",{className:"font-mono text-foreground/80",children:s("{{count}} tokens",{count:$n(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 QV(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 JV(e,t,s=yB){const r=t-e;return r>=s?r:null}const ZV={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"},eH={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."},xS=600;function tH(e){return e?.kind==="deadline"?["background","timeout"]:[]}function nH(e,t,s){const r=`\`\`\`
41
- ${t}
42
- \`\`\``;return e==="background"?s(`Rerun this command with background: true:
43
-
44
- {{command}}`,{command:r}):s(`Rerun this command with timeout: {{seconds}}:
45
-
46
- {{command}}`,{seconds:xS,command:r})}function sH(e,t,s){return t(e)?(s(),!0):!1}function rH(){const[e,t]=f.useState(()=>Date.now());return f.useEffect(()=>{const s=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(s)},[]),e}const _m=5,sb=2*Math.PI*_m;function oH({startedAt:e,deadlineAt:t,output:s}){const{t:r}=z(),o=rH(),i=f.useRef({output:s,at:e??Date.now()});i.current.output!==s&&(i.current={output:s,at:Date.now()});const a=QV(e,t,o),l=JV(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:_m,fill:"none",stroke:"currentColor",opacity:"0.25"}),n.jsx("circle",{cx:"6",cy:"6",r:_m,fill:"none",stroke:"currentColor",strokeDasharray:sb,strokeDashoffset:sb*(1-a.fraction),transform:"rotate(-90 6 6)"})]}),Math.ceil(a.remainingMs/1e3),"s"]})]})}function gS(e,t){return e.kind==="exit_nonzero"&&e.exitCode===void 0?t("Failed"):t(ZV[e.kind],{code:e.exitCode??""})}function iH({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:gS(e,t)})}function aH({failure:e,command:t}){const{t:s}=z(),[r,o]=f.useState(!1);if(!e)return null;const i=eH[e.kind],a=tH(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:gS(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:()=>{sH(nH(l,t,s),tN,Ei)},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:xS})},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(Dn,{className:"h-3 w-3"}):n.jsx(Xa,{className:"h-3 w-3"}),s("Copy command")]})]})}function lH(e){return e.startsWith("/skill:")?"skill":e==="/goal"?"goal":"command"}function cH(e){return e.startsWith("/skill:")?e.slice(7):e.replace(/^\//,"")}function cd(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 dH={skill:Bs,goal:Ai,command:qk},uH={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 vS(e,t=!1){return _("inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 align-middle text-xs font-medium",uH[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 dd({name:e,className:t,interactive:s=!1,trailing:r}){const o=lH(e),i=dH[o];return n.jsxs("span",{className:_(vS(o,s),t),children:[n.jsx(i,{className:"h-3 w-3"}),cH(e),r]})}const fH={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 mH({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(Gn,{text:e.text}),e.kind==="report"&&e.value&&n.jsx(Gn,{text:`\`\`\`json
47
- ${e.value}
48
- \`\`\``}),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(hH,{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 hH({run:e,title:t}){const{t:s}=z(),[r,o]=fH[e.status]??[null,"bg-muted-foreground"],i=e.durationMs===null?"":s("took {{duration}}",{duration:Hn(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 ix=e=>!!e&&typeof e=="object"&&!Array.isArray(e),rb=e=>typeof e=="string"&&e.trim()?e:null;function Bm(e){if(!ix(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 pH=new Set(["closed","parked","creating"]);function xH(e){if(!ix(e))return null;const{agentId:t,status:s,latestRun:r}=e;return typeof t!="string"||typeof s!="string"?null:(pH.has(s)?null:Bm(r))??{agentId:t,runId:"",status:s,durationMs:null}}function gH(e,t){const s=u5(t);if(!s)return null;const{head:r,value:o}=s;if(e==="report"){const l=Bm(o.run);if(!l)return null;const{text:c,value:u,error:d,...m}=o;return{kind:"report",head:r,runs:[l],text:rb(c),value:u==null?null:JSON.stringify(u,null,2),error:rb(d),info:JSON.stringify(m,null,2)}}if(e==="list"){if(!Array.isArray(o.agents))return null;const l=o.agents.flatMap(c=>xH(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(!ix(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=>Bm(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 vH={"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 bH(e){const t=/^([a-z][a-z-]*):\s/u.exec(e?.trim()??"")?.[1];return t&&vH[t]||null}function yH({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:ox,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(da,{className:Zd}),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(wH,{item:a,command:l?.command??a.command,onOpen:l?.status==="running"?s:void 0},a.taskId)})})]})}function wH({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(Ti,{className:"h-3.5 w-3.5"})})]})}function jH({command:e,output:t,failure:s}){const r=xe(a=>a.terminalTheme),o=xe(a=>a.terminalFontFamily),i=yw(r)??f5;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:Ls(t)}),n.jsx(aH,{failure:s,command:e})]})}function kH(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 bS({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(Dn,{className:"mt-0.5 h-3 w-3 shrink-0 text-brand"}):t.status==="in_progress"?n.jsx(j4,{className:"mt-0.5 h-3 w-3 shrink-0 text-brand"}):n.jsx(Sp,{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 yS({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 NH({conversationId:e}){const{t}=z(),s=xe(d=>d.pinUnfinishedTodos),r=X(d=>d.conversations[e]?.messages),o=f.useMemo(()=>s&&r?kH(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(ww,{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(Bn,{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(Zt,{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(yS,{done:c,total:o.todos.length,className:"mb-2"}),n.jsx(bS,{todos:o.todos})]})]})}function wS({image:e,path:t,alt:s}){const{t:r}=z(),o=f.useMemo(()=>h5(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(hl,{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 SH({image:e,output:t}){const{t:s}=z(),r=f.useMemo(()=>m5(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"),jw(r.size)]),n.jsxs("div",{"data-slot":"image-view",className:"space-y-2 px-3 py-2",children:[n.jsx(wS,{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 CH(){const e=X(o=>o.conversations),t=xe(o=>o.projects),s=jt(o=>o.secretary.board.todos),r=jt(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 IH(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 TH({item:e,framed:t=!1}){const{t:s,locale:r}=z(),o=CH(),i=X(m=>m.conversations),a=p5(IH(e),{t:s,locale:r==="zh"?"zh":"en",lookup:o}),l=x5(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(Pp,{state:l}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:a.grouped?a.title:d?.title}),d?.status?n.jsx(jS,{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(AH,{card:m,known:i,onOpen:Va,framed:t},`${m.title}-${h}`)):null,c&&d?n.jsx(kS,{card:d,known:i,onOpen:Va,framed:t}):null]})}function jS({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 AH({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(jS,{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(kS,{card:e,known:t,onOpen:s,framed:r,nested:!0}):null]})}function kS({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(PH,{block:m,known:t,onOpen:s},`${m.kind}-${h}`);if(r){const m=[];e.blocks.forEach((x,y)=>{const j=x.kind==="prompt",w=m.at(-1);!j&&w&&!w.prompt?w.blocks.push([x,y]):m.push({prompt:j,blocks:[[x,y]]})});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,y)=>n.jsxs("div",{className:_("min-w-0",y>0&&"border-t border-border/60",!x.prompt&&"space-y-1.5 px-3 py-2"),children:[x.blocks.map(([j,w])=>j.kind==="prompt"?n.jsx(NS,{label:j.label,text:j.text},w):d(j,w)),!p&&x===h?g:null]},y)),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 EH={"--chat-h1-size":"1em","--chat-h2-size":"1em","--chat-h3-size":"1em","--chat-h4-size":"1em","--chat-code-block-size":"11px"},ib=4;function RH(e){const t=e.split(`
49
- `).filter(s=>s.trim()&&!/^\s*(```|~~~)/.test(s)).map(s=>s.replace(/^\s*#{1,6}\s+/,"").trimEnd());return{preview:t.slice(0,ib).join(`
50
- `),folded:t.length>ib||e.length>320}}function NS({label:e,text:t}){const{t:s}=z(),{preview:r,folded:o}=RH(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(mh,{text:t,label:s("Copy")})]})]}),l?n.jsx("div",{"data-enso":"tool-card-prompt-body",style:EH,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(Gn,{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 MH({row:e}){const{t}=z(),[s,r]=f.useState(!1),o=e.display==="long"&&(e.value.length>120||e.value.includes(`
51
- `));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 PH({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(NS,{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(`
52
- `).find(l=>l.trim())}):n.jsx(Gn,{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(wS,{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(MH,{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 DH={report:()=>{},scroller:{current:null}},SS=f.createContext(DH),OH=SS.Provider;function LH(){return f.useContext(SS)}const ab=f.lazy(()=>Cd(()=>import("./EditDiff-DxxLuCEI.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(e=>({default:e.EditDiff}))),rf=f.lazy(()=>Cd(()=>import("./ReadFileView-DFoLPU04.js"),__vite__mapDeps([5,1,2,6,4]),import.meta.url).then(e=>({default:e.ReadFileView}))),_H=(e,t)=>e===t||!!e&&!!t&&e.runMs===t.runMs&&e.turnMs===t.turnMs&&e.ttftMs===t.ttftMs&&e.tps===t.tps;function BH(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 FH(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"&&_H(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(`
53
- `)===r.ask?.options.join(`
54
- `)&&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&&JSON.stringify(s.args??null)===JSON.stringify(r.args??null)&&BH(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 CS=/^<role>\n?([\s\S]*?)\n?<\/role>\s*/,zH=/^<workspace-migrated>\n?([\s\S]*?)\n?<\/workspace-migrated>\s*/,$H=/^<workspace-branch-changed>\n?([\s\S]*?)\n?<\/workspace-branch-changed>\s*/;function VH({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 IS({items:e}){const t=ws(),s=X(o=>t?void 0:_n(o)?.id),r=X(o=>t?void 0:_n(o)?.backgroundTasks);return n.jsx(yH,{items:e,live:r,onOpen:s?o=>X.setState({pendingAgentOpen:{sessionId:s,agentId:o}}):void 0})}function HH({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 TS({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(vi,{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 AS({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(G5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):n.jsx(Ap,{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 WH({tag:e,body:t}){const s=e==="agent-notification"?wV(t):null;return s?n.jsx(KH,{notices:s}):n.jsx(qH,{tag:e,body:t})}function UH({goal:e,instructions:t}){const{t:s}=z(),[r,o]=f.useState(!1),i=i$(e);return n.jsxs("div",{"data-enso":"goal-continuation","data-open":r?"true":"false",className:_("my-1 w-full min-w-0",dS),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(uS,{}),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 lb({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:ox,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:Zd}),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 GH({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(Zs,{text:l,searchQuery:t,activeNth:s},a):null}if(o.kind==="goal")return n.jsx(UH,{goal:o.goal,instructions:o.instructions},a);if(o.kind==="schedule"){const l=u$(o.raw),c=l.length>0?l:[{summary:"",body:""}];return n.jsx(f.Fragment,{children:c.map((u,d)=>n.jsx(lb,{enso:"secretary-schedule-card",icon:Np,title:u.summary?r("Scheduled: {{summary}}",{summary:u.summary}):r("Scheduled"),body:u.body},d))},a)}if(o.kind==="updates"){const l=rS(o.raw);if(l)return n.jsx(ES,{lines:l},a);const c=f$(o.raw);return n.jsx(lb,{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(WH,{tag:o.tag,body:o.body},a)})})}function KH({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(_s,{className:Zd}),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(Gn,{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:$n(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:Hn(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 qH({tag:e,body:t}){const[s,r]=f.useState(!1),o=sx(t);if(!o)return null;const i=o.indexOf(`
55
- `),a=i>0,l=e.startsWith("coworker-")||e==="agent-notification"?_s:_o;return n.jsxs("div",{className:ox,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:Zd}),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 YH={"goal-complete":Dn,"goal-blocked":Zr,"needs-user":Ap,"turn-ended":Jr,failed:Mw,stalled:da,interrupted:Or,proposal:Cp,schedule:Np,pending:da,"ask-relay":Ic,leftover:da};function ES({lines:e}){return n.jsx("div",{"data-enso":"secretary-updates",className:_(rx,"divide-y divide-border/60"),children:e.map((t,s)=>n.jsx(XH,{line:t,onOpen:Va},s))})}function XH({line:e,onOpen:t}){const{t:s}=z(),[r,o]=f.useState(!1),i=YH[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(Ti,{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 RS=/^<message-from-main-agent>\n?([\s\S]*?)\n?<\/message-from-main-agent>\s*$/;function QH(e){const t=CS.exec(e);return RS.test(t?e.slice(t[0].length):e)}function JH({name:e,content:t}){const{t:s}=z();return n.jsxs(cn,{children:[n.jsxs(Z5,{className:vS("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(on,{className:"text-base",children:[s("Skill")," · ",e]})}),n.jsx(In,{className:"max-h-[50vh] text-sm",children:n.jsx(Gn,{text:t})})]})]})}function Fm({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:t}):null]})}function ZH({blocks:e,hostTaskWrapUp:t}){const s=X5(e.rest),r=t?Q5(e.rest):void 0,o=n.jsx(Fm,{chip:n.jsx("span",{className:"inline-flex flex-wrap gap-1 align-middle",children:e.skills.map(i=>n.jsx(JH,{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(TS,{note:s.plan}),s.unattended&&n.jsx(AS,{note:s.unattended}),r&&n.jsx(IS,{items:r.items}),o]})}function e9({text:e}){const t=Rw(e);if(t.names.length>1)return n.jsx(Fm,{chip:n.jsx("span",{className:"inline-flex flex-wrap gap-1 align-middle",children:t.names.map(r=>n.jsx(dd,{name:`/skill:${r}`},r))}),extra:t.rest});const s=cd(e);return s.slash?n.jsx(Fm,{chip:n.jsx(dd,{name:s.slash}),extra:s.rest.trim()}):null}function t9({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(Y5,{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 Ha({kind:e,label:t,title:s}){const r=e==="file"?Fo:e==="chat"?Or:X_;return n.jsxs("span",{className:_(eu(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 n9({label:e,sessionFile:t}){const s=X(o=>o.conversations),r=E$(s,t);return r?n.jsxs("button",{type:"button","data-enso":"chat-ref",onClick:()=>Va(r),title:t,className:_(eu("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(Ha,{kind:"chat",label:e,title:t})}function _l({text:e,searchQuery:t="",activeNth:s=-1}){const r=AB(K5(e)),o={n:0};return n.jsx("span",{className:"whitespace-pre-wrap",children:r.map((i,a)=>i.type==="file"?n.jsx(Ew,{path:i.path,children:n.jsx(Ha,{kind:"file",label:Gd(i.path),title:i.path})},a):i.type==="chat"?n.jsx(n9,{label:i.label,sessionFile:i.sessionFile},a):i.type==="ui-element"?n.jsx(Ha,{kind:"ui-element",label:i.label,title:`${i.path}${i.text?` · ${i.text}`:""}`},a):n.jsx("span",{children:t.trim()?q5(i.text,t,s,o):i.text},a))})}function s9({files:e,chats:t}){return n.jsxs("span",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[e.map(s=>n.jsx(Ew,{path:s,children:n.jsx(Ha,{kind:"file",label:Gd(s),title:s})},`f:${s}`)),t.map(s=>n.jsx(Ha,{kind:"chat",label:s.label,title:s.sessionFile},`c:${s.sessionFile}`))]})}const vc="max-w-[82%] rounded-[10px] bg-muted px-3.5 py-[9px] text-(length:--chat-body-size) leading-[1.6]";function Zs({text:e,searchQuery:t="",activeNth:s=-1,thumbnails:r=0,align:o="end",hostTaskWrapUp:i=!1}){const{t:a}=z(),l=ws(),c=!!(l?.speaker||l?.botSession),u=P5(e,r);if(u)return n.jsxs(n.Fragment,{children:[u.text&&n.jsx(Zs,{text:u.text,searchQuery:t,activeNth:s,hostTaskWrapUp:i}),n.jsx(aS,{entries:u.entries,thumbnails:r,align:o})]});const d=n$(e);if(d)return n.jsx(eV,{message:d});const m=c?D5(e):null;if(m)return n.jsx(A$,{message:m});const h=c?O5(e):e;if(h!==e)return n.jsx(Zs,{text:h,searchQuery:t,activeNth:s,hostTaskWrapUp:i});const p=c?L5(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(Zs,{text:p.body,searchQuery:t,activeNth:s}),n.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:p.refs.map(H=>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:H.title})]},H.id))})]});const g=_5(e);if(g.note){const H=g.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(TS,{note:g.note}),H&&n.jsx(Zs,{text:H,searchQuery:t,activeNth:s,hostTaskWrapUp:i})]})}const x=B5(e);if(x.note){const H=x.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(AS,{note:x.note}),H&&n.jsx(Zs,{text:H,searchQuery:t,activeNth:s,hostTaskWrapUp:i})]})}const y=i?F5(e):null;if(y){const H=y.rest.trim();return n.jsxs(n.Fragment,{children:[n.jsx(IS,{items:y.items}),H&&n.jsx(Zs,{text:H,searchQuery:t,activeNth:s})]})}const j=$H.exec(e);if(j){const H=e.slice(j[0].length).trim();return n.jsxs(n.Fragment,{children:[n.jsx(VH,{note:j[1]??""}),H&&n.jsx(Zs,{text:H,searchQuery:t,activeNth:s})]})}const w=z5(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(Cp,{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:_(vc,"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(vi,{className:"h-3 w-3"}),a("Plan feedback")]}),n.jsx(_l,{text:w.feedback,searchQuery:t,activeNth:s})]});const b=$5(e);if(b)return n.jsx(t9,{preset:b});const N=OB(e);if(N.files.length>0||N.chats.length>0){const H=cd(N.body);return n.jsxs("div",{className:vc,children:[H.slash?n.jsxs(n.Fragment,{children:[n.jsx(dd,{name:H.slash}),H.rest.trim()?n.jsx("span",{className:"ml-1.5 align-middle",children:n.jsx(_l,{text:H.rest.trim(),searchQuery:t,activeNth:s})}):null]}):n.jsx(_l,{text:N.body,searchQuery:t,activeNth:s}),n.jsx(s9,{files:N.files,chats:N.chats})]})}const E=V5(e);if(E)return n.jsx(ZH,{blocks:E,hostTaskWrapUp:i});if(cd(e).slash)return n.jsx(e9,{text:e});const T=zH.exec(e);if(T){const H=e.slice(T[0].length).trim();return n.jsxs(n.Fragment,{children:[n.jsx(HH,{note:T[1]}),H&&n.jsx(Zs,{text:H,searchQuery:t,activeNth:s})]})}const k=l$(e);if(k)return n.jsx(GH,{segments:k,searchQuery:t,activeNth:s});const L=rS(e);if(L)return n.jsx(ES,{lines:L});const F=CS.exec(e),A=F?e.slice(F[0].length):e,D=RS.exec(A),M=D?D[1]:A;return n.jsxs("div",{className:_(D?"max-w-[80%] rounded-2xl rounded-bl-md border border-blue-500/20 bg-blue-500/8 px-4 py-2.5 text-sm":_(vc,"whitespace-pre-wrap")),children:[D&&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(_s,{className:"h-3 w-3"}),a("From main agent")]}),F?.[1]&&!Qz(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]]}),D?n.jsx(Gn,{text:M,searchQuery:t,activeNth:s}):n.jsx(_l,{text:M,searchQuery:t,activeNth:s})]})}function cb(e){return e.kind==="tool-group"||e.kind==="thinking"||e.kind==="tool"&&Sw(e)}const Er="text-[color:var(--subtle-foreground,var(--muted-foreground))]",ci="animate-pulse motion-reduce:animate-none";function r9({model:e,at:t,privacyMask:s,secretarySession:r=!1,face:o}){const i=ws(),a=nS(),l=r?o??a:null,c=i?.speaker??(i?null:l),u=!i&&l?!0:void 0,d=[e,typeof t=="number"?nu(t):null].filter(Boolean).join(" · ");return!c&&!d&&!s?null:n.jsxs("div",{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(kd,{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]",Er),children:d}),s&&n.jsx(KV,{report:s})]})}const o9=f.memo(function({item:t,secretarySession:s=!1,onToggleGroup:r,onToggleTurn:o}){const i=g5(),a=i.query,l=i.activeKey===t.key?i.activeNth:-1,c=s;switch(t.kind){case"user":{const u=t.text?QH(t.text):!1,d=t.collapsed===!0,m=t.hostTaskWrapUp?w5(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(hl,{src:`data:${h.mimeType};base64,${h.data}`,className:"max-h-48 max-w-full rounded-lg border object-contain"},p)),t.text&&n.jsx(Zs,{text:t.text,searchQuery:a,activeNth:l,thumbnails:t.images.length,align:u?"start":"end",hostTaskWrapUp:t.hostTaskWrapUp===!0}),d?n.jsx(b9,{turnKey:t.key,text:m,timestamp:t.timestamp,turnDurationMs:t.turnDurationMs,onToggle:o}):n.jsx(y9,{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(w9,{item:t,searchQuery:a,activeNth:l});case"thinking":return n.jsx(k9,{itemKey:t.key,text:t.text,streaming:t.streaming,durationMs:t.durationMs,startedAt:t.startedAt});case"tool":{const u=P$(t),d=v5(t.name,c),m=n.jsxs(n.Fragment,{children:[n.jsx(b5,{name:t.name,output:t.output,state:t.state}),d?n.jsx(TH,{item:t,framed:c}):n.jsx(E9,{item:t}),u?n.jsx(L$,{proposalId:u}):null,t.pluginArtifacts?n.jsx(y5,{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(I9,{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(PS,{})]});case"interrupted":return n.jsx(u9,{item:t});case"task-note":return n.jsx(N9,{item:t});case"compaction":case"compaction-notice":return n.jsx(C9,{item:t});case"compaction-progress":return n.jsx(S9,{state:t.state});case"session-custom":return n.jsx(d9,{entry:t.entry});case"plugin-message":return n.jsx(a9,{item:t});case"discarded-turn":return n.jsx(l9,{item:t,onToggle:r});case"resumed-reply":return n.jsx(c9,{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"})]})}},FH),db=e=>{if(typeof e=="string")return e;if(e===void 0)return"—";try{return JSON.stringify(e)}catch{return String(e)}};function i9({entry:e}){const{t}=z(),s=nV(),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(ro,{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 a9({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(kw,{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("p",{className:"whitespace-pre-wrap break-words text-foreground",children:e.text})]})}function l9({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",Er),children:[n.jsx(Nw,{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(kw,{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("p",{className:"whitespace-pre-wrap break-words text-foreground",children:r},o)),e.tools.map((r,o)=>n.jsxs("p",{className:_("truncate",Er),children:[Rr(r.name,s)," ",r.summary]},o))]})]})}function c9({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",Er),children:[n.jsx(Kk,{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",Er),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",Er),children:[Rr(r.name,s)," ",r.summary]},o))]})]})}function d9({entry:e}){const{t}=z();if(e.kind==="oauth-account-selected")return n.jsx(i9,{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(_s,{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(Dn,{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(Qa,{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(Dn,{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:[db(o.previous)," → ",db(o.value)]})]},o.field))})]})]})})}function _n(e){const t=e.activeId?e.conversations[e.activeId]:null;return t?t.activeTabId?e.conversations[t.activeTabId]??t:t:null}const MS=()=>()=>{};function u9({item:e}){const{locale:t}=z(),s=e$({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(f9,{})]})}function f9(){const{t:e}=z();return X(s=>{const r=_n(s);return!!(r&&!r.spawning&&r.status!=="running")})?n.jsxs("button",{type:"button","data-enso":"timeline-interrupted-retry",title:e("Retry"),onClick:()=>{const s=_n(X.getState());s&&X.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(ro,{className:"h-3 w-3"}),e("Retry")]}):null}function PS(){const{t:e}=z(),t=ws(),s=t?.botControls,r=X(l=>{if(t&&(!t.canRetry||t.botControls))return!1;const c=_n(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??MS,o,o);return(s?i:r)?n.jsxs("button",{type:"button",title:e("Retry"),onClick:()=>{if(s)return s.retry();const l=_n(X.getState());l&&X.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(ro,{className:"h-3 w-3"}),e("Retry")]}):null}function m9(e,t){return J5(_n(e),t)}const ax="flex items-center gap-1 text-[11px] text-muted-foreground transition-opacity hover:text-foreground";function h9({messageIndex:e}){const{t}=z(),s=ws();return X(o=>{const i=_n(o);return W5(i,s,i?Aw(o.conversations,i.id):1)})?n.jsxs("button",{type:"button",className:ax,title:t("Keep this session and start a parallel one from here"),onClick:()=>{const o=X.getState(),i=_n(o);if(!i)return;const a=U5(i,e);a!==null&&o.forkFromMessage(i.id,a)},children:[n.jsx(Hs,{className:"h-3 w-3"}),t("Conversation branch")]}):null}function p9({messageIndex:e}){const{t}=z(),s=ws(),r=X(i=>_n(i)?.id),o=X(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 Tw(l)||a.status==="running"&&H5(l)?l?.deliveryId:void 0});return!r||!o?null:n.jsxs("button",{type:"button",title:t("Withdraw message"),onClick:()=>X.getState().withdrawMessage(r,{kind:"delivery",id:o}),className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(Pa,{className:"h-3 w-3"}),t("Withdraw message")]})}function x9(){const{t:e}=z(),t=X(s=>_n(s)?.id);return t?n.jsxs("button",{type:"button",onClick:()=>{iS(t,e)},className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(Eo,{className:"h-3 w-3"}),e("Restart conversation")]}):null}function g9({messageIndex:e}){const{t}=z(),s=ws(),r=X(i=>_n(i)?.id),o=X(i=>{const a=r?i.conversations[r]:void 0;if(s||!a||a.historyOnly)return;const l=a.messages[e-(a.historyBaseIndex??0)];return Tw(l)?l?.deliveryId:void 0});return!r||!o?null:n.jsxs("button",{type:"button",title:t("Resend"),onClick:()=>X.getState().resendMessage(r,o),className:"inline-flex items-center gap-1 hover:text-foreground",children:[n.jsx(ro,{className:"h-3 w-3"}),t("Resend")]})}function v9({messageIndex:e}){const{t}=z(),[s,r]=f.useState(!1),[o,i]=f.useState(null),a=ws(),l=a?.botControls,c=X(x=>{if(a?.botControls)return!1;const y=_n(x);return m9(x,a)&&!!(y&&Cl(y.id,y.id,y,e))}),u=()=>{if(!l||!a?.canRewind||!a.sessionId)return null;const x=l.projection();return!x||x.status==="running"?null:Cl(a.sessionId,a.sessionId,x,e)?.entryId??null},d=f.useSyncExternalStore(l?.subscribe??MS,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 y=_n(X.getState());if(!y)return;const j=Cl(y.id,y.id,y,e);j&&i({restoreFiles:x,conversationId:y.id,entryId:j.entryId})},p=(x,y,j)=>{if(l)return l.rewind(j,x);const w=X.getState(),b=_n(w),N=Cl(y,b?.id,w.conversations[y],e,j);N&&w.rewind(N.conversationId,N.entryId,x)},g=[{icon:Pa,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(Rs,{open:s,onOpenChange:r,children:[n.jsxs(Ms,{className:ax,title:t("Rewind to this message"),children:[n.jsx(Pa,{className:"h-3 w-3"}),t("Rewind")]}),n.jsx(Ps,{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(hs,{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 b9({turnKey:e,text:t,timestamp:s,turnDurationMs:r,onToggle:o}){const{t:i}=z();return n.jsxs("div",{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(DS,{text:t}),typeof s=="number"&&n.jsx("span",{children:nu(s)}),r!==void 0&&n.jsxs("span",{children:["· ",i("took {{duration}}",{duration:Hn(r)})]})]})}function DS({text:e}){return e.trim()?n.jsx("span",{"data-enso":"copy-user-prompt",className:"inline-flex",children:n.jsx(OS,{text:e,className:"opacity-0 transition-opacity group-hover/user:opacity-100 focus-visible:opacity-100"})}):null}function y9({turnKey:e,messageIndex:t,text:s,timestamp:r,canCollapse:o,deliveryState:i,onToggleTurn:a}){const{t:l}=z(),c=xe(u=>u.autoCollapseTurns);return n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/75 select-none",children:[n.jsx(v9,{messageIndex:t}),n.jsx(g9,{messageIndex:t}),n.jsx(p9,{messageIndex:t}),n.jsx(DS,{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(x9,{}),c&&o&&a&&n.jsxs("button",{type:"button",onClick:()=>a(e,!0),className:_(ax,"cursor-pointer opacity-0 group-hover/user:opacity-100"),title:l("Collapse"),children:[n.jsx(Bn,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{children:l("Collapse")})]}),typeof r=="number"&&n.jsx("span",{children:nu(r)})]})}function w9({item:e,searchQuery:t="",activeNth:s=-1}){const{t:r}=z(),o=ws(),i=e.perf?j9(e.perf,r,e.turnDurationMs!==void 0):"",a=X(u=>_n(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(Gn,{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",{className:"mt-1 flex items-center gap-2 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:[n.jsx(Yx,{position:"left",...c}),n.jsx(OS,{text:e.text}),n.jsx(Yx,{position:"right",...c}),e.turnEnd&&n.jsx(h9,{messageIndex:Number(e.key.split("-")[0])}),e.timestamp&&!e.turnEnd&&n.jsx("span",{children:nu(e.timestamp)}),e.turnDurationMs!==void 0&&n.jsxs("span",{children:[e.timestamp&&!e.turnEnd&&"· ",r("took {{duration}}",{duration:Hn(e.turnDurationMs)})]}),i&&n.jsxs("span",{children:["· ",i]})]})]})}function OS({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(Dn,{className:"h-3 w-3"}):n.jsx(Xa,{className:"h-3 w-3"})})}const ub=e=>String(e).padStart(2,"0"),nu=e=>{const t=new Date(e);return`${ub(t.getHours())}:${ub(t.getMinutes())}`},fb=e=>{const t=e/1e3;return t<10?String(Math.round(t*10)/10):String(Math.round(t))};function j9(e,t,s=!1){const r=[];return(!s||e.turnMs!==void 0)&&r.push(`${fb(e.runMs)}s`),e.ttftMs!==void 0&&r.push(`TTFT ${fb(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:Hn(e.turnMs)})),r.join(" · ")}function k9({itemKey:e,text:t,streaming:s,durationMs:r,startedAt:o}){const{t:i}=z(),a=xe(d=>d.expandLiveReasoning),[l,c]=f.useState(null),u=M5(l,s,a);return n.jsxs("div",{"data-enso":"thinking","data-live":s||void 0,children:[n.jsxs("button",{type:"button",onClick:()=>c(!u),className:_("flex min-h-6 items-center gap-2 text-[13px] transition-colors hover:text-foreground",Er),children:[n.jsx("span",{className:"flex size-3 shrink-0 items-center justify-center",children:n.jsx(j5,{className:_("size-3",s&&"animate-pulse text-brand")})}),s?n.jsx("span",{className:_("text-foreground",ci),children:i("Thinking…")}):r!==null?n.jsx("span",{children:i("Thought for {{duration}}",{duration:Hn(r)})}):n.jsx("span",{children:i("Thought process")}),s&&n.jsx(LS,{itemKey:e,since:o}),n.jsx(fn,{className:_("h-3 w-3 transition-transform",u&&"rotate-90")})]}),u&&n.jsx(k5,{text:t,streaming:s,itemKey:e})]})}function N9({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(Dn,{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…"):Ls(o??t("(log unavailable)")):t("(no log available)")})]})]})}function S9({state:e}){const{t}=z();return n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[n.jsx(Bt,{className:"h-3 w-3 animate-spin"}),n.jsx("span",{children:t(e==="queued"?"Compacts after this turn":"Compacting…")})]})}function C9({item:e}){const{t}=z(),[s,r]=f.useState(!1),o=e.kind==="compaction",i=e.tokensBefore===null?null:$n(e.tokensBefore),a=NV(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:$n(e.tokensBefore),after:$n(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(L_,{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 I9({item:e,onToggle:t}){const{t:s}=z(),r=xe(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:Hn(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?.(Xx(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",Er),children:[n.jsx(Pp,{state:e.exploring?"running":"ok"}),n.jsx("span",{className:_("shrink-0 text-muted-foreground group-hover/step:text-foreground",u&&_(ci,"text-foreground"),e.exploring&&"font-medium"),children:m}),n.jsx("span",{className:_("min-w-0 flex-1 truncate",u&&ci),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(Gn,{text:c.report})]}),n.jsxs("button",{type:"button",onClick:()=>t?.(Xx(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 $i({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 T9(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??""}catch{return String(e)}}function A9({source:e,output:t,view:s}){const r=s?.status==="completed"?T9(s.value):s?.error??t;return n.jsxs("div",{className:"space-y-1 px-3 py-1",children:[e?n.jsx(Qx,{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(`
56
- `),children:a?`${l} · ${a.error??"error"}`:l},o)})}):null,r?s?.status==="completed"&&typeof s.value!="string"?n.jsx(Qx,{code:r,language:"json"}):n.jsx("pre",{className:"font-mono text-xs leading-relaxed text-muted-foreground whitespace-pre-wrap",children:Ls(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:Ls(s.console)}):null]})}function mb({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(hl,{src:Cc(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 E9({item:e}){const{t}=z(),s=ws(),r=xe(U=>U.compactReadOnlyTools),o=xe(U=>U.expandLiveEdits),i=r&&e.name!=="bash"&&Sw(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=N5[e.name],p=Cw(e.name),g=e.state!=="error"&&e.todos?.length===0,x=g?t("Todo list cleared"):e.subagentOp?[t(S5[e.subagentOp]),e.summary].filter(Boolean).join(" · "):e.summary,y=e.nestedPending&&e.state==="running"?`${x} · ${e.nestedPending} pending`:u?.calls.length&&e.state!=="error"?C5(u.calls):x,j=!g&&!!(e.output||e.source||d||e.ask),w=e.state==="running"&&e.waiting==="subagent"&&!s,b=a||l||c||j||w||m,N=o&&(a||l||m)&&e.state==="running",[C,E]=f.useState(N),[T,k]=f.useState(!1),L=f.useRef(null),F=LH();f.useEffect(()=>{if(!T)return;const U=L.current;if(!U)return;const J=e.key,$=F.report,oe=new IntersectionObserver(([Ne])=>$(J,Ne?.isIntersecting===!0),{root:F.scroller.current});return oe.observe(U),()=>{oe.disconnect(),$(J,!1)}},[T,e.key,F]);const A=C&&e.name==="memory_search"?I5(e.output):null,D=C&&e.name==="memory_capture"?T5(e.output,e.memoryContent):null,M=C&&e.name==="subagent"&&e.state!=="error"?gH(e.subagentOp,e.output):null,H=e.name==="subagent"&&e.state==="error"?bH(e.output):null,G=f.useRef(c);return f.useEffect(()=>{const U=A5(e,G.current);G.current=c,(N||o&&U)&&E(!0)},[N,o,c,e]),e.todos&&e.todos.length>0?n.jsx(P9,{todos:e.todos}):e.name.startsWith("goal_")?n.jsx(R9,{item:e}):e.plan&&e.state!=="error"?n.jsx(M9,{plan:e.plan}):n.jsxs("div",{ref:L,"data-enso":"tool-row","data-tool-style":i?"compact":"full","data-user-open":T?"true":void 0,children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("button",{type:"button",disabled:!b,onClick:()=>{const U=!C;E(U),k(U),F.report(e.key,U)},className:_("group/step flex min-h-6 min-w-0 flex-1 items-center gap-2 text-left text-[13px]",Er,b&&"cursor-pointer"),children:[n.jsx(Pp,{state:e.state}),n.jsx("span",{className:_("shrink-0 text-muted-foreground transition-colors group-hover/step:text-foreground",e.state==="running"&&_(ci,"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"&&ci),children:e.state==="error"&&e.output?x&&e.name==="apply_patch"&&c?`${y} · ${z9(e.output)}`:H?t(H):T$(Ls(e.output)):x?y: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(iH,{failure:e.shellFailure}),e.state==="reviewing"?n.jsx("span",{className:_("shrink-0 text-[11px] text-foreground",ci),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(F9,{callId:e.callId,startedAt:e.startedAt,output:e.output??""}),n.jsx(LS,{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?Hn(e.durationMs):null].filter(Boolean).join(" · ")}),b&&n.jsx(fn,{className:_("h-3 w-3 shrink-0 text-muted-foreground opacity-0 transition-[opacity,transform] group-hover/step:opacity-100",C&&"rotate-90 opacity-100")})]}),e.state==="running"&&e.callId&&!s&&n.jsx(D9,{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:()=>Iw(),children:n.jsx(h_,{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(U=>n.jsx(mb,{path:U,fallback:n.jsx("p",{className:"break-all px-3 py-2 text-xs text-muted-foreground",children:U})},U))}):null,C&&b&&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(B9,{agentIds:e.subagentTitles?Object.keys(e.subagentTitles):void 0}),a&&e.edits&&n.jsx($i,{follow:e.state==="running",children:n.jsx(f.Suspense,{fallback:null,children:n.jsx(ab,{path:e.summary,blocks:e.edits})})}),c&&e.fileChanges&&n.jsx($i,{follow:e.state==="running",children:e.fileChanges.map((U,J)=>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",(J>0||a)&&"border-t"),children:[n.jsx("span",{className:"uppercase",children:U.type}),n.jsx("span",{className:"min-w-0 flex-1 truncate",title:U.path,children:U.path}),U.truncated&&n.jsx("span",{children:t("Truncated preview")})]}),n.jsx(f.Suspense,{fallback:null,children:n.jsx(ab,{path:U.path,blocks:[U],snapshot:U})})]},`${U.type}:${sV(U.path,U.oldText,U.newText)}`))}),E5(e)&&n.jsx($i,{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:Ls(e.output??"")})}),l&&e.writeContent&&n.jsx($i,{follow:e.state==="running",className:_((a||c)&&"border-t border-border/60"),children:n.jsx(f.Suspense,{fallback:null,children:n.jsx(rf,{path:e.summary,contents:e.writeContent})})}),!a&&!l&&!c&&(j||m)&&n.jsxs($i,{follow:e.state==="running",children:[R5(e.name)?n.jsx(A9,{source:e.source,output:e.output,view:u}):e.name==="bash"||e.name==="powershell"?n.jsx(jH,{command:e.summary,output:e.output??"",failure:e.shellFailure}):e.name==="read"&&m&&e.imagePath?n.jsx(mb,{path:e.imagePath,fallback:n.jsx(f.Suspense,{fallback:null,children:n.jsx(rf,{path:e.summary,contents:e.output??""})})},e.imagePath):e.name==="image_view"&&e.state==="ok"?n.jsx(SH,{image:e.image,output:e.output}):e.name==="read"?n.jsx(f.Suspense,{fallback:null,children:n.jsx(rf,{path:e.summary,contents:e.output??""})}):e.name==="subagent"&&e.state!=="error"&&!d&&!M?n.jsx("div",{className:"px-3 py-2 text-sm",children:n.jsx(Gn,{text:e.output??""})}):A?n.jsx(Lm,{hits:A}):D?n.jsx(CV,{view:D}):n.jsxs(n.Fragment,{children:[e.ask&&n.jsx(pV,{ask:e.ask,waiting:e.state==="running"}),d&&n.jsx("div",{className:"px-3 py-2 text-sm",children:n.jsx(Gn,{text:d})}),M?n.jsx(mH,{view:M,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:Ls(e.output)})]}),n.jsx(XV,{value:e.rtk}),n.jsx(hV,{value:e.approvalReview})]})]})]})}function R9({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(Ai,{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 M9({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(vi,{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(Gn,{text:e.text})})]})}function P9({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(ww,{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(yS,{done:s,total:e.length,className:"mt-1.5 mb-2"}),n.jsx(bS,{todos:e})]})}const hb=new Map;function D9({callId:e,waiting:t}){const{t:s}=z(),r=X(c=>_n(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?Nw:c4;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 O9=5e3,L9=[];function _9(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 B9({agentIds:e}){const{t}=z(),s=X(l=>_n(l)?.id??""),r=Xv(l=>l.byConversation[s]??L9),[o,i]=f.useState(!1);if(f.useEffect(()=>{if(!s)return;let l=!0;const c=h=>{l&&(Xv.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,O9);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:_9(l,t)}),n.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70 tabular-nums",children:Hn(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 LS({itemKey:e,since:t}){const s=ws(),r=X(c=>_n(c)?.id??""),o=s?s.sessionId??"":r,i=f.useRef(null);if(i.current===null){const c=`${o}:${e}`;i.current=t??hb.get(c)??Date.now(),t===void 0&&hb.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:Hn(Date.now()-a)})}function F9({callId:e,startedAt:t,output:s}){const r=ws(),o=X(i=>r?void 0:_n(i)?.toolDeadlineAt?.[e]);return n.jsx(oH,{startedAt:t,deadlineAt:o,output:s})}function pb(e){return e.kind==="tool-group"?!0:e.kind==="tool"&&!e.todos?.length&&!e.name.startsWith("goal_")}const z9=e=>Ls(e.split(`
57
- `,1)[0]??""),$9=100;function V9(e,t,s,r,o=$9){if(r||!s)return{hiddenSince:t,delayMs:null};const i=t??e;return{hiddenSince:i,delayMs:Math.max(0,o-(e-i))}}const H9=1e6;function W9(e,t,s=H9){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 U9(e,t){return t}const G9=new Set(["text","thinking","tool","tool-group"]);function K9(e,t,s,r){const o=f.useRef(Jx),[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?eT(e,t,r,o.current,i):null;o.current=p?.witness??Jx;const g=p?.wakeAt??null,x=tT(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 y=window.setTimeout(()=>a(g),g-i);return()=>window.clearTimeout(y)},[g,i]),x}const q9=[{icon:F4,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:Vk,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:Pw,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 Y9({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:q9.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",xb=1e3;function gb({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 vb=40,X9={index:"LAST",align:"end"},Q9={top:600,bottom:600},J9=e=>e?"auto":!1;function Z9({style:e,...t}){const s=e?.visibility==="hidden",[r,o]=f.useState(!1),i=f.useRef(null);return f.useEffect(()=>{const a=V9(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 lx({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:y,olderCursor:j,searchQuery:w="",activeHit:b=null,secretarySession:N=!1,secretaryFace:C}){const{t:E}=z(),T=ws(),k=nS(),L=N?C??k:null,F=!T&&L?L:null,A=N,D=f.useRef(null),[M,H]=f.useState(!0),[G,U]=f.useState(!1),J=f.useRef(!0),$=f.useRef(null),oe=f.useRef(0),Ne=f.useRef(0),ce=f.useRef(null),ne=f.useRef(!1),Y=f.useRef(!1),pe=f.useRef(0),[ge,we]=f.useState(null),V=f.useRef(0),W=f.useCallback(I=>{cancelAnimationFrame(V.current),V.current=requestAnimationFrame(()=>we(I()))},[]);f.useEffect(()=>()=>cancelAnimationFrame(V.current),[]);const[B,te]=f.useState(new Set),Z=f.useRef(new Set),[ue,fe]=f.useState(()=>new Set),Ce=f.useCallback((I,v)=>{const R=Z.current;v!==R.has(I)&&(v?R.add(I):R.delete(I),fe(new Set(R)))},[]),de=f.useRef({report:Ce,scroller:$});de.current.report=Ce;const Ee=f.useCallback(I=>{te(v=>{const R=new Set(v);return R.has(I)?R.delete(I):R.add(I),R})},[]),[me,Ve]=f.useState(new Map),at=xe(I=>I.autoCollapseTurns),Fe=xe(I=>I.collapseCompletedActivity),tt=xe(I=>I.collapseLiveActivity),je=xe(I=>I.liveActivityFoldDelaySec),Je=xe(I=>I.compactReadOnlyTools),rt=K9(t,o,B,{compact:Je,autoCollapseCompletedTurns:at,collapseCompletedActivity:Fe,collapseLiveActivity:tt,liveActivityFoldDelaySec:je,heldOpenTools:ue,turnOverrides:me,foldToolOnlyTurns:!T&&A,readableToolCards:A}),K=f.useRef({state:Uz,collapse:new Map,reveal:new Map}),Q=f.useMemo(()=>{const I=K.current,v=re=>$.current?.querySelector(`[data-nav-key="${CSS.escape(re)}"]`),R=Gz(I.state,rt,(re,Se)=>{const Re=v(re)?.getBoundingClientRect().top,We=v(Se)?.getBoundingClientRect().bottom;return Re===void 0||We===void 0?0:We-Re}),ee=Date.now();I.state=R.next;for(const{key:re,...Se}of R.collapses)I.collapse.set(re,{at:ee,...Se});for(const re of R.expands)I.reveal.set(re,ee);return R.children},[rt]),Ae=f.useRef(null),pt=f.useRef(0),Dt=f.useRef(null),Xe=W9(Ae.current,rt.map(I=>I.key));Ae.current=Xe.anchor,Xe.remount&&(pt.current+=1,Dt.current=null);const kt=Xe.firstItemIndex,mn=f.useCallback((I,v)=>{Ve(R=>R.get(I)===v?R:new Map(R).set(I,v))},[]),_e=f.useMemo(()=>{const I=[];for(let v=0;v<t.length;v++){const R=t[v];if(R.kind!=="user")continue;let ee="";for(let re=v+1;re<t.length;re++){const Se=t[re];if(Se.kind==="user")break;if(Se.kind==="text"){ee=Se.text;break}}I.push({key:R.key,question:R.text||"[image]",answer:ee})}return I},[t]),Nt=f.useCallback(()=>{const I=$.current;I&&I.scrollHeight-I.scrollTop-I.clientHeight>2&&(ne.current=!0,I.scrollTop=I.scrollHeight)},[]),Ot=f.useCallback(()=>{cancelAnimationFrame(oe.current);const I=Date.now()+1200;let v=null;const R=()=>{cancelAnimationFrame(oe.current),ne.current=!1,v?.removeEventListener("touchstart",R),v?.removeEventListener("wheel",R)},ee=()=>{if(Y.current){R();return}!v&&$.current&&(v=$.current,v.addEventListener("touchstart",R,{passive:!0,once:!0}),v.addEventListener("wheel",R,{passive:!0,once:!0})),Nt(),J.current=!0,H(!0),Date.now()<I?oe.current=requestAnimationFrame(ee):R()};ee(),H(!0),J.current=!0},[Nt]);f.useEffect(()=>()=>{cancelAnimationFrame(oe.current),cancelAnimationFrame(Ne.current),window.clearTimeout(pe.current)},[]);const _t=()=>{Y.current=!0,window.clearTimeout(pe.current)},se=()=>{window.clearTimeout(pe.current),pe.current=window.setTimeout(()=>{Y.current=!1},400)},Oe=()=>{_t(),se()},ot=()=>{cancelAnimationFrame(oe.current),cancelAnimationFrame(Ne.current),ne.current=!1,J.current=!1,H(!1)},ct=f.useCallback(I=>{if(ce.current?.disconnect(),ce.current=null,!I)return;const v=new ResizeObserver(()=>{if(!J.current&&!ne.current)return;cancelAnimationFrame(Ne.current);let R=8;const ee=()=>{Nt();const re=$.current;(re?re.scrollHeight-re.scrollTop-re.clientHeight:0)<=2||(--R>0?Ne.current=requestAnimationFrame(ee):Ot())};ee()});v.observe(I),ce.current=v,Ot()},[Nt,Ot]);f.useEffect(()=>()=>ce.current?.disconnect(),[]);const xt=I=>rt.findIndex(v=>v.key===I||v.kind==="tool-group"&&_S(v,I)),gt=I=>{if(!p){$.current?.querySelector(`[data-nav-key="${CSS.escape(I)}"]`)?.scrollIntoView({block:"center"});return}const v=xt(I);v>=0&&D.current?.scrollToIndex({index:U9(kt,v),align:"center"})},Ft=f.useRef(null),Ht=I=>{if(ot(),xt(I)>=0){Ft.current=null,gt(I);return}let v=null,R=!1;for(const ee of t)if(ee.kind==="user"&&(v=ee.key),ee.key===I){R=!0;break}!R||!v||(Ft.current=I,mn(v,!1))};f.useLayoutEffect(()=>{const I=Ft.current;!I||xt(I)<0||(Ft.current=null,gt(I))},[rt]),f.useImperativeHandle(e,()=>({scrollToBottom:Ot,pinToBottom:Nt,isAtBottom:()=>J.current,getScroller:()=>p?null:$.current,scrollToKey:Ht}));const tn=f.useRef(!1),Jt=`${j}:${kt}`,Gt=f.useRef(Jt);Gt.current!==Jt&&(Gt.current=Jt,tn.current=!1);const gn=()=>{!g||tn.current||(tn.current=!0,g())};f.useEffect(()=>{p&&!x&&Dt.current===kt&&gn()},[j,x]);const Qn=f.useMemo(()=>({query:w,activeKey:b?.key??"",activeNth:b?.nth??-1}),[w,b?.key,b?.nth]),bt=(I,v)=>{const R=rt[v+1];if(R!==void 0&&pb(I)&&pb(R))return"pb-0";if(!Je)return"pb-4";const ee=R!==void 0&&cb(R);return cb(I)?ee?"pb-1":"pb-2":I.kind==="text"&&ee?"pb-1":"pb-4"},sn=(I,v)=>{const R=rt[v-1],ee=R?.kind==="user"&&!R.collapsed&&G9.has(I.kind)?R:void 0,re=Date.now(),Se=K.current.collapse.get(I.key),Re=Se&&re-Se.at<xb?Se:void 0,We=Q.get(I.key),Ge=We&&K.current.reveal.get(We.group),St=We&&Ge!==void 0&&re-Ge<xb;return n.jsxs("div",{"data-nav-key":I.key,"data-fold-collapse":Re?Re.pair?"pair":"toggle":void 0,style:Re?{"--fold-from":`${Re.height}px`}:St?{"--fold-i":We.index}:void 0,className:_(_r,bt(I,v),St&&"t-fold-reveal","[overflow-wrap:anywhere]"),children:[ee&&n.jsx(r9,{model:ee.replyModel,at:ee.replyAt,privacyMask:ee.replyPrivacyMask,secretarySession:A,face:L}),n.jsx(o7,{itemKey:I.key,children:n.jsx(o9,{item:I,secretarySession:A,onToggleGroup:Ee,onToggleTurn:mn})})]},I.key)},Tn=f.useRef(!1);y===!0&&(Tn.current=!0);const S=nT(t.length>0,x,y,Tn.current,!p&&G);f.useLayoutEffect(()=>{if(p){U(!1);return}const I=$.current;U(!!I&&sT(y===!0,x,I.scrollHeight,I.clientHeight))},[p,y,x,kt,rt.length,t.length]);const P={pageChrome:S,onLoadMore:S==="more"?gn:void 0,busy:s,loading:!!r,since:Kz({loading:!!r,runStartedAt:i}),error:l,onRetryResume:m};return n.jsx(rT.Provider,{value:Qn,children:n.jsx(OH,{value:de.current,children:n.jsxs("div",{"data-enso":"timeline",className:"@container relative min-h-0 flex-1",onWheel:Oe,onKeyDown:Oe,onTouchStart:I=>{$.current?.contains(I.target)&&_t()},onTouchEnd:se,onPointerDown:I=>{I.target===$.current&&(_t(),window.addEventListener("pointerup",se,{once:!0}))},children:[n.jsx(Xz,{items:_e,activeKey:ge,onJump:Ht}),t.length===0&&!s?n.jsxs(gb,{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:F?n.jsx(xh,{name:F.name,color:F.color,image:F.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(Wz,{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:E(l)}),m&&n.jsx(he,{size:"sm",variant:"outline",onClick:m,children:E("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:E("Session is not ready yet — no history to show.")}),n.jsx(he,{size:"sm",variant:"outline",onClick:h,children:E("Retry sync")})]}):u!==""?n.jsx("p",{className:"t-stagger-line t-stagger-line--2 text-sm text-muted-foreground",children:u??E("Ask the agent…")}):null,d&&n.jsx("div",{className:"t-stagger-line t-stagger-line--3 mt-5 w-full",children:n.jsx(Y9,{onPick:d})})]})]}):t.length===0&&l?n.jsxs(gb,{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:E(l)}),m&&n.jsx(he,{size:"sm",variant:"outline",onClick:m,children:E("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(Bt,{className:"h-5 w-5 animate-spin text-muted-foreground"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:E("Preparing session…")})]}):p?n.jsx(Tz,{ref:D,data:rt,defaultItemHeight:80,computeItemKey:(I,v)=>v.key,firstItemIndex:kt,startReached:gn,followOutput:J9,atBottomThreshold:vb,atBottomStateChange:I=>{if(!I&&J.current&&!Y.current){Ot();return}H(I),J.current=I},increaseViewportBy:Q9,initialTopMostItemIndex:X9,rangeChanged:({startIndex:I})=>{Dt.current=I,I>kt+4&&(tn.current=!1),W(()=>{const v=Math.max(0,I-kt);let R=null;for(let ee=0;ee<=Math.min(v+1,rt.length-1);ee++)rt[ee]?.kind==="user"&&(R=rt[ee].key);return R})},scrollerRef:I=>{$.current=I instanceof HTMLElement?I:null},className:"h-full select-text",context:P,components:t7,itemContent:(I,v)=>sn(v,I-kt)},pt.current):n.jsx("div",{ref:I=>{$.current=I},onScroll:I=>{const v=I.currentTarget;if(ne.current){ne.current=!1,J.current=!0,H(!0);return}if(!Y.current){J.current&&Nt();return}const R=v.scrollHeight-v.scrollTop-v.clientHeight<=vb;R!==J.current&&(J.current=R,H(R)),g&&(v.scrollTop<80&&!tn.current?(tn.current=!0,g()):v.scrollTop>240&&(tn.current=!1))},className:"h-full select-text overflow-y-auto [overflow-anchor:none]",children:n.jsxs("div",{ref:ct,children:[n.jsx(BS,{context:P}),rt.map((I,v)=>sn(I,v)),n.jsx(FS,{context:P})]})}),!M&&t.length>0&&n.jsxs("button",{type:"button",onClick:Ot,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(gh,{className:"h-3 w-3"}),E("Scroll to bottom")]})]})})})}function _S(e,t){return e.children.some(s=>s.key===t||s.kind==="tool-group"&&_S(s,t))}function e7({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(Bt,{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 BS({context:e}){return n.jsx(e7,{chrome:e.pageChrome,onLoadMore:e.onLoadMore})}function FS({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(n7,{}),n.jsx("span",{className:"animate-pulse text-foreground motion-reduce:animate-none",children:t(r?"Loading…":"Working…")}),o!==void 0&&n.jsx(r7,{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(PS,{}),a&&n.jsx(he,{size:"sm",variant:"outline",onClick:a,children:t("Retry resume")})]})]})}const t7={List:Z9,Header:BS,Footer:FS};function n7(){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 s7=e=>{const t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m${t%60}s`},r7=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:s7(Date.now()-t)})});class o7 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 di={type:"spring",stiffness:400,damping:30},ud={type:"tween",duration:.22,ease:[.2,0,0,1]},of={initial:{height:0,opacity:0},animate:{height:"auto",opacity:1,transition:ud},exit:{height:0,opacity:0,transition:ud}};function AJ(e){return e.resizing?!0:e.previousConversationId!==void 0&&e.conversationId!==void 0&&e.previousConversationId!==e.conversationId}function i7(e){return e.skip?{duration:0}:e.cover||e.targetW===0?ud:di}const a7={ts:_i,tsx:_i,js:_i,jsx:_i,mjs:_i,json:vh,html:O4,css:Zx,scss:Zx,md:Fo,sh:_f,bash:_f,yml:Ds,yaml:Ds,toml:Ds},l7={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 c7(e,t,s=!1){if(t)return s?Lr:Wd;const r=e.split(".").pop()?.toLowerCase()??"";return a7[r]??Z4}function d7(e,t){if(t)return"text-amber-500";const s=e.split(".").pop()?.toLowerCase()??"";return l7[s]??"text-muted-foreground"}const u7=f.lazy(()=>Cd(()=>import("./ReadFileView-DFoLPU04.js"),__vite__mapDeps([5,1,2,6,4]),import.meta.url).then(e=>({default:e.ReadFileView}))),f7={artifacts:[],media:[]},af=new Map,lf=new Map,m7=new Set(["image","markdown","html","text"]),h7=e=>e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`;function p7(e){const t=JSON.stringify(e),[s,r]=f.useState(()=>af.get(t)??f7);return f.useEffect(()=>{if(af.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)&&af.set(t,a),r(a)}).catch(()=>{}),()=>{o=!1}},[t]),s}function x7(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 fd({target:e}){const{artifacts:t,media:s}=p7(e);return n.jsxs(n.Fragment,{children:[s.length>0&&n.jsx(v7,{target:e,media:s}),t.length>0&&n.jsx(w7,{target:e,artifacts:t})]})}function g7(){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 zS(e,t,s){const r=JSON.stringify(e),o=t&&s==="thumb"?lf.get(t):void 0,[i,a]=f.useState(o?{ok:!0,kind:"image",dataUrl:o}:null);return f.useEffect(()=>{const l=t&&s==="thumb"?lf.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"&&lf.set(t,u.dataUrl),c&&a(u)}).catch(()=>c&&a({ok:!1,error:"unavailable"})),()=>{c=!1}},[r,t,s]),i}function v7({target:e,media:t}){const{t:s}=z(),r=g7(),[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(b7,{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(td,{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(y7,{target:e,item:o,label:o?r(o):"",onClose:()=>i(null)})]})}function b7({target:e,item:t,label:s,onOpen:r}){const o=zS(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(td,{className:"m-auto h-4 w-4 text-muted-foreground"}):n.jsx(Bt,{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 y7({target:e,item:t,label:s,onClose:r}){const{t:o}=z(),i=zS(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(on,{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($S,{name:a,content:i})]})})}function w7({target:e,artifacts:t}){const{t:s}=z(),r=x7(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=c7(a.name,!1),c=m7.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",d7(a.name,!1))}),n.jsx("span",{className:"truncate",children:a.name}),n.jsx("span",{className:"shrink-0 text-muted-foreground",children:h7(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(Dw,{className:"h-3.5 w-3.5"})})]},a.rel)}),n.jsx(j7,{target:e,artifact:o,onOpen:r,onClose:()=>i(null)})]})}function j7({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(on,{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(Dw,{className:"h-4 w-4"})})]})]})}),n.jsx($S,{name:t?.name??"",content:i})]})})}function $S({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(Bt,{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(Gn,{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(u7,{path:e,contents:t.text})})})]})}const VS="enso:design-annotations:v1",HS="enso:annotate-prefs:v1",bb=lT(e=>e.pageKey),yb=[],wb=new WeakMap,Gr={annotateHovered:!1,annotateEntered:!1,annotateUseCount:0,annotateSendImmediately:!0};function WS(e){try{return typeof localStorage>"u"?null:localStorage.getItem(e)}catch{return null}}function US(e,t){try{if(typeof localStorage>"u")return;localStorage.setItem(e,t)}catch{}}function k7(){const e=WS(HS);if(!e)return Gr;try{const t=JSON.parse(e);return{annotateHovered:typeof t.annotateHovered=="boolean"?t.annotateHovered:Gr.annotateHovered,annotateEntered:typeof t.annotateEntered=="boolean"?t.annotateEntered:Gr.annotateEntered,annotateUseCount:typeof t.annotateUseCount=="number"&&Number.isFinite(t.annotateUseCount)?t.annotateUseCount:Gr.annotateUseCount,annotateSendImmediately:typeof t.annotateSendImmediately=="boolean"?t.annotateSendImmediately:Gr.annotateSendImmediately}}catch{return Gr}}function Vi(e){US(HS,JSON.stringify(e))}const jb=oT(WS(VS)),N7=k7();function Bl(e,t){US(VS,aT({queues:e,pages:t}))}const Ln=Dr((e,t)=>({...N7,queues:jb.queues,pages:jb.pages,sessions:new Map,familiarity:()=>{const s=t();return iT(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};Vi(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};Vi(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};Vi(o),e({annotateSendImmediately:s})},annotationsFor:(s,r)=>{const o=t().queues.get(s);if(!o||o.items.length===0)return yb;if(!r)return o.items;let i=wb.get(o.items);i||(i=new Map,wb.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?yb:l;return i.set(r,c),c},pageKeyOf:s=>t().pages.get(s),setBrowserUrl:(s,r)=>{if(!r)return;const o=Ow(r),i=t().pages;if(i.get(s)===o)return;const a=new Map(i);a.delete(s),a.set(s,o),Bl(t().queues,a),e({pages:a})},dispatchQueue:(s,r)=>{const o=t(),i=o.queues.get(s)??{items:[]},a=bb(i,r);if(a===i)return;const l=new Map(o.queues);l.delete(s),a.items.length>0&&l.set(s,a),Bl(l,o.pages),e({queues:l})},addAnnotation:(s,r)=>{const o=t(),i=o.queues.get(s)??{items:[]},a=bb(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),Bl(l,o.pages);const c=o.annotateUseCount+1;return Vi({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:()=>{Vi(Gr),Bl(new Map,new Map),e({...Gr,queues:new Map,pages:new Map,sessions:new Map})}})),ui=typeof navigator<"u"&&navigator.platform?navigator.platform.startsWith("Mac"):!0,zm=ui?"⌘⇧D":"Ctrl+Shift+D";function cf({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 S7(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=Qo,o.strokeStyle=Qo,o.lineWidth=zf,o.lineCap="round",o.lineJoin="round";for(const l of e.markup)for(const c of Ff(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 C7({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?pT(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 I7({drawing:e,pick:t,markupTool:s,editorOpen:r,onMarkupToolChange:o,onExit:i}){const a=fT({drawing:e,pick:t?{region:t.region}:null,markupToolHeld:s!==null,editorOpen:r}),c=f.useMemo(()=>mT(ui),[])[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(Sp,{className:"h-3.5 w-3.5"});case"square":return n.jsx(Fw,{className:"h-3.5 w-3.5"});case"arrow-right-up":return n.jsx(Ti,{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 (${zm})`,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(Zt,{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:hT.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 T7({tabId:e,conversationId:t,active:s,disabled:r,queueOpen:o,onQueueOpenChange:i,onToggleDesignMode:a,onOpenPinFromQueue:l,onSendQueue:c}){const{t:u}=z(),d=Ln(C=>C.familiarity()),m=Ln(C=>C.annotateHovered),h=Ln(C=>C.markHovered),p=Ln(C=>C.annotationsFor(t)),g=Ln(C=>C.annotationsFor(t,e)),x=Ln(C=>C.removeAnnotations),y=Ln(C=>C.clearAnnotations),[j,w]=f.useState(!1),b=s?p:g,N=b.length;return N===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 (${zm}) — 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(cf,{}),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"})]}),j&&!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(cf,{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:[N>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(C=>C.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:N})]}),n.jsx("button",{type:"button","aria-label":`Open annotation queue (${N})`,"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(Bn,{className:"h-3 w-3"})})]}):n.jsxs("button",{type:"button",onClick:()=>a(!1),"aria-label":"Annotate","aria-pressed":s,title:`Exit Design Mode (${zm})`,className:"flex h-6 items-center gap-1 rounded bg-[#3a96dd]/15 px-2 text-xs font-medium text-[#3a96dd]",children:[n.jsx(cf,{}),d!=="many"&&n.jsx("span",{children:"Annotate"})]}),o&&N>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:N===1?"1 edit":`${N} edits`}),n.jsx("button",{type:"button",onClick:()=>{y(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:b.map(C=>{const E=C.kind==="region"&&C.images[0]?`data:${C.images[0].mimeType};base64,${C.images[0].data}`:null,T=C.kind==="element"&&C.elements.length>1?C.elements.length-1:0,k=C.comment.trim()||(C.kind==="element"&&C.elements[0]?uT(C.elements[0]):C.kind==="region"?`Screenshot region ${Math.round(C.region.rect.width)} × ${Math.round(C.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(C)},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:C.number}),E&&n.jsx("img",{src:E,alt:"",className:"h-5 w-7 shrink-0 rounded border object-cover"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),T>0&&n.jsxs("span",{className:"shrink-0 rounded bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:["+",T]})]}),n.jsx("button",{type:"button","aria-label":"Delete annotation",onClick:()=>x(t,[C.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"})})]},C.id)})})]})]})}function A7({stage:e,pinned:t,onTogglePinned:s,onClose:r,onStageChange:o}){const[i,a]=f.useState(""),l=f.useMemo(()=>_w(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 ET.filter(h=>RT(h,{rendersText:e.baseline.rendersText,values:c})&&h.name.includes(m))},[i,e.baseline.rendersText,c]),d=m=>{const h=DT(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(Eo,{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(Ns,{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(Zt,{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),y=p?e.baseline.values[m.name]??"":h??e.baseline.values[m.name]??"",j=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:b=>{b.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}),j&&n.jsx("input",{type:"color","aria-label":`${m.name} color picker`,value:/^#[0-9a-fA-F]{6}$/.test(y)?y:"#3a96dd",onChange:b=>d({kind:"edit",property:m.name,value:b.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:y,disabled:p,onChange:b=>d({kind:"edit",property:m.name,value:b.target.value}),onKeyDown:b=>{if(b.key!=="ArrowUp"&&b.key!=="ArrowDown")return;const N=MT(y,b.key==="ArrowUp"?1:-1,b.shiftKey,m);N!==null&&(b.preventDefault(),b.stopPropagation(),d({kind:"edit",property:m.name,value:N}))},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(b=>n.jsx("option",{value:b},b)),e.baseline.variables.lengths.map(b=>n.jsx("option",{value:`var(${b.name})`},b.name)),j&&e.baseline.variables.colors.map(b=>n.jsx("option",{value:`var(${b.name})`},b.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(Eo,{className:"h-2.5 w-2.5"})})]},m.name)})})]})}function E7({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(),y=Ln(se=>se.annotateSendImmediately),j=Ln(se=>se.setSendImmediately),w=Ln(se=>se.addAnnotation),b=Ln(se=>se.updateAnnotation),N=Ln(se=>se.removeAnnotations),C=Ln(se=>se.annotationsFor(t)),E=f.useMemo(()=>o?C.find(se=>se.id===o.id)??null:null,[C,o]),T=f.useMemo(()=>xT(E?.comment??""),[E?.comment]),[k,L]=f.useState(""),[F,A]=f.useState([]),[D,M]=f.useState(!1),[H,G]=f.useState(!1),[U,J]=f.useState(null),[$,oe]=f.useState({x:0,y:0}),[Ne,ce]=f.useState(!1),[ne,Y]=f.useState(null),[pe,ge]=f.useState("move"),[we,V]=f.useState(null),W=f.useRef(null),B=f.useRef(null),te=f.useRef(null),Z=f.useRef(null),ue=f.useId(),fe=o?`pin:${o.id}`:r?"draft":"none";f.useEffect(()=>{L(T.prose),A(E?E.images.slice(1):[]),M(!1),J(null),oe({x:0,y:0}),l(!1),window.setTimeout(()=>te.current?.focus(),10)},[fe]),f.useEffect(()=>{const se=gT(C.filter(Oe=>Oe.browserId===e));window.electronAPI.browser.previewDesignCss(e,"queue",se)},[C,e]);const Ce=f.useMemo(()=>E?E.kind==="element"?E.elements:[]:r?.description.elements??[],[E,r]),de=Ce.length===1?Ce[0]:null,Ee=f.useCallback(async()=>{if(!de)return;if(D){M(!1);return}const se=await window.electronAPI.browser.readDesignCss(e,de.uniqueId);if(!se){Ie({type:"warning",title:x("Could not read CSS for this element")});return}J(vT(se,T.css)),M(!0)},[de,D,e,T.css,x]);f.useEffect(()=>{if(!g||!r?.region)return;const se=Oe=>{if(!(ui?Oe.metaKey:Oe.ctrlKey)||Oe.altKey||Oe.key.toLowerCase()!=="z")return;const ct=document.activeElement===te.current&&k.length>0;if(TT({markCount:r.markup.length+r.redoMarkup.length,toolHeld:i!==null,noteOwnsUndo:ct}))if(Oe.preventDefault(),Oe.stopPropagation(),Oe.shiftKey){const xt=r.redoMarkup.at(-1);if(!xt)return;c({...r,markup:[...r.markup,xt],redoMarkup:r.redoMarkup.slice(0,-1)})}else{const xt=r.markup.at(-1);if(!xt)return;c({...r,markup:r.markup.slice(0,-1),redoMarkup:[...r.redoMarkup,xt]})}};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[g,r,i,k.length,c]),f.useEffect(()=>{if(!ne||!r)return;const se={left:0,top:0,width:s.width,height:s.height},Oe=(xt,gt)=>{const Ft=xt.key===" "?"Space":xt.key==="Shift"||xt.key==="Alt"||xt.key==="Escape"?xt.key:null;Ft&&(Ft==="Space"&&xt.preventDefault(),Y(Ht=>Ht?rg(Ht,{type:"key",key:Ft,down:gt},se):null))},ot=xt=>Oe(xt,!0),ct=xt=>Oe(xt,!1);return window.addEventListener("keydown",ot,!0),window.addEventListener("keyup",ct,!0),()=>{window.removeEventListener("keydown",ot,!0),window.removeEventListener("keyup",ct,!0)}},[ne,r,s.width,s.height]);const me=f.useMemo(()=>U?_w(U):null,[U]),Ve=!!(me&&me.changes.size>0),at=k.trim().length>0,Fe=E!==null,tt=Fe?k.trim()!==T.prose.trim()||!!me?.isDirty:at||Ve||(r?.markup.length??0)>0,je=f.useMemo(()=>me?eg(k,me.changes):T.css.size>0?eg(k,T.css):k.trim(),[k,me,T.css]),Je=Fe?!0:je.length>0||r?.region!==null&&(r?.markup.length??0)>0,rt=AT({sendImmediately:y,isOnStack:Fe}),K=Ve&&!at?tg[rt].css:tg[rt].note,Q=f.useCallback(()=>{const se=Ce;if(se.length===0)return;let Oe=!1;se.forEach((ot,ct)=>{const xt=`ui-${Date.now()}-${ct}`,gt=Bf(ot),Ft=ct===0&&r?.description.image?{data:r.description.image.data,mimeType:r.description.image.mimeType}:void 0;Ep({kind:"ui-element",id:xt,label:gt,path:ot.path||ot.tagName.toLowerCase(),text:(ot.innerText||"").replace(/\s+/g," ").trim().slice(0,200)||Lw(ot),imageId:`img-${xt}`},Ft)&&(Oe=!0)}),Oe?(Ei(),d()):Ie({type:"warning",title:x("No Composer for this selection")})},[Ce,r?.description.image,d,x]),Ae=f.useCallback(async()=>{if(!(Ne||!Je)){ce(!0);try{if(Fe&&E){const gt=E.images.length>0?[E.images[0],...F]:[...F];b(t,E.id,je,gt),window.electronAPI.browser.previewDesignCss(e,"draft",{}),m(),y&&h(new Set([E.id]));return}if(!r)return;const se=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`ann-${Date.now()}`,Oe=Ln.getState().pageKeyOf(e)??"http://localhost/",ot=r.description.image,ct=[];if(ot){const gt=r.region&&r.markup.length>0?await S7({base64:ot.data,markup:r.markup,cropWidth:r.region.width}):ot.data;ct.push({id:`img-${se}`,data:gt,mimeType:ot.mimeType,name:ot.name,width:ot.width,height:ot.height})}ct.push(...F);let xt;if(r.region){const gt=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"}};xt=w(t,{id:se,kind:"region",comment:je,browserId:e,pageKey:Oe,images:ct,region:{rect:r.region,anchor:gt,markup:r.markup}})}else xt=w(t,{id:se,kind:"element",comment:je,browserId:e,pageKey:Oe,images:ct,elements:r.description.elements});window.electronAPI.browser.previewDesignCss(e,"draft",{}),d(),y&&xt&&h(new Set([xt.id]))}finally{ce(!1)}}},[Ne,Je,Fe,E,F,b,t,je,e,m,y,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]),Dt=se=>{for(const Oe of se){if(!Oe.type.startsWith("image/"))continue;const ot=new FileReader;ot.onload=()=>{const ct=ot.result,xt=ct.slice(ct.indexOf(",")+1);A(gt=>[...gt,{id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,data:xt,mimeType:Oe.type,name:Oe.name}])},ot.readAsDataURL(Oe)}},Xe=ne?ne.rect:r?.region??null,kt=Math.min(320,Math.max(240,s.width-16)),mn=D?360:148,_e=f.useMemo(()=>{if(o)return bT(o.badge,s,{width:kt,height:mn});if(Xe)return ng({x:Xe.left,y:Xe.top,width:Xe.width,height:Xe.height},s,kt,mn);if(r&&r.elements.length>0){const se=r.elements.map(Ft=>Ft.rect.x),Oe=r.elements.map(Ft=>Ft.rect.y),ot=r.elements.map(Ft=>Ft.rect.x+Ft.rect.width),ct=r.elements.map(Ft=>Ft.rect.y+Ft.rect.height),xt=Math.min(...se),gt=Math.min(...Oe);return ng({x:xt,y:gt,width:Math.max(...ot)-xt,height:Math.max(...ct)-gt},s,kt,mn)}return{x:16,y:16}},[o,Xe,r,s,kt,mn]),Nt=H?Math.max(8,s.width-kt-8):Math.max(8,Math.min(_e.x+$.x,s.width-kt-8)),Ot=H?8:Math.max(8,Math.min(_e.y+$.y,s.height-120));if(!r&&!o)return null;const _t=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:se=>{se.target===se.currentTarget&&pt()},children:[r&&Xe&&n.jsxs(n.Fragment,{children:[_t&&n.jsx("img",{src:_t,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%, ${Xe.left}px 100%, ${Xe.left}px ${Xe.top}px, ${Xe.left+Xe.width}px ${Xe.top}px, ${Xe.left+Xe.width}px ${Xe.top+Xe.height}px, ${Xe.left}px ${Xe.top+Xe.height}px, ${Xe.left}px 100%, 100% 100%, 100% 0%)`}}),n.jsxs("div",{role:"application","aria-label":"Selected screenshot region",style:{left:Xe.left,top:Xe.top,width:Xe.width,height:Xe.height,cursor:i!==null?"crosshair":CT(ne?ne.handle:pe,ne!==null)},onPointerMove:se=>{const Oe=se.currentTarget.getBoundingClientRect(),ot={x:se.clientX-Oe.left,y:se.clientY-Oe.top};if(i!==null){if(!we||!W.current)return;const ct={x:Math.max(0,Math.min(Xe.width,ot.x)),y:Math.max(0,Math.min(Xe.height,ot.y))};if(we.kind==="pen")V({kind:"pen",points:NT(we.points,ct)});else{const xt=se.shiftKey?ST({kind:we.kind,from:W.current,to:ct}):ct;V({kind:we.kind,from:W.current,to:xt})}return}if(ne){const ct=se.currentTarget.parentElement?.getBoundingClientRect(),xt={x:se.clientX-(ct?.left??0),y:se.clientY-(ct?.top??0)};Y(gt=>gt?rg(gt,{type:"move",point:xt,altKey:se.altKey,shiftKey:se.shiftKey},{left:0,top:0,width:s.width,height:s.height}):null);return}ge(sg(ot,Xe))},onPointerDown:se=>{if(se.button!==0)return;se.preventDefault(),se.stopPropagation(),se.currentTarget.setPointerCapture(se.pointerId);const Oe=se.currentTarget.getBoundingClientRect(),ot={x:Math.max(0,Math.min(Xe.width,se.clientX-Oe.left)),y:Math.max(0,Math.min(Xe.height,se.clientY-Oe.top))};if(i!==null){W.current=ot,p(!0),V(i==="pen"?{kind:"pen",points:[ot]}:{kind:i,from:ot,to:ot});return}const ct=se.currentTarget.parentElement?.getBoundingClientRect(),xt={x:se.clientX-(ct?.left??0),y:se.clientY-(ct?.top??0)},gt=sg(ot,Xe);Y(kT({handle:gt,point:xt,rect:Xe,modifiers:{altKey:se.altKey,shiftKey:se.shiftKey}}))},onPointerUp:async()=>{if(we){const se=yT(r.markup,we);V(null),W.current=null,p(!1),se.length!==r.markup.length&&c({...r,markup:se,redoMarkup:[]});return}if(ne){const se=wT({rect:ne.rect,viewport:s}),Oe=jT({markup:r.markup,from:r.region??se,to:se,markupScale:1});Y(null);const ot=await window.electronAPI.browser.describeSelection(e,{x:se.left,y:se.top,width:se.width,height:se.height});c({...r,region:se,markup:Oe,description:ot.image?ot: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:Xe.width,height:Xe.height,className:"pointer-events-none block h-full w-full overflow-visible",children:[r.markup.map((se,Oe)=>Ff(se,"complete").map((ot,ct)=>n.jsx("path",{d:ot.d,"data-design-markup-stroke":"",fill:ot.paint==="fill"?Qo:"none",stroke:ot.paint==="stroke"?Qo:"none",strokeWidth:ot.paint==="stroke"?zf:void 0,strokeLinecap:"round",strokeLinejoin:"round"},`${Oe}-${ct}`))),we&&Ff(we,"active").map((se,Oe)=>n.jsx("path",{d:se.d,"data-design-markup-stroke":"active",fill:se.paint==="fill"?Qo:"none",stroke:se.paint==="stroke"?Qo:"none",strokeWidth:se.paint==="stroke"?zf:void 0,strokeLinecap:"round",strokeLinejoin:"round"},`active-${Oe}`))]}),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:Nt,top:Ot,width:kt},onMouseDown:se=>se.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:se=>{se.button!==0||H||se.target instanceof Element&&se.target.closest("button, input")||(se.preventDefault(),se.currentTarget.setPointerCapture(se.pointerId),B.current={pointerId:se.pointerId,startX:se.clientX,startY:se.clientY,nudgeX:$.x,nudgeY:$.y})},onPointerMove:se=>{const Oe=B.current;!Oe||Oe.pointerId!==se.pointerId||oe({x:Oe.nudgeX+(se.clientX-Oe.startX),y:Oe.nudgeY+(se.clientY-Oe.startY)})},onPointerUp:()=>{B.current=null},className:_("flex items-center justify-between gap-2 px-3 pt-2.5 pb-1",!H&&"cursor-grab active:cursor-grabbing"),children:[n.jsx("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:Xe||E?.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(Xe?.width??(E?.kind==="region"?E.region.rect.width:0))," ","×"," ",Math.round(Xe?.height??(E?.kind==="region"?E.region.rect.height:0))]})]}):Ce.map((se,Oe)=>{const ot=gu[(se.hueIndex??Oe)%gu.length]??gu[0],ct=vu[(se.hueIndex??Oe)%vu.length]??vu[0];return n.jsxs("span",{style:{backgroundColor:ot.bg,borderColor:ct.stroke,color:ot.border},title:`${IT(se)} — ${se.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:ot.border}}),n.jsx("span",{className:"truncate",children:Bf(se)})]},se.uniqueId||`${se.tagName}-${Oe}`)})}),n.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 rounded-lg bg-muted/50 p-0.5",children:[!Fe&&!Xe&&Ce.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(H4,{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(bi,{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(Bw,{className:"h-3 w-3"})})]}),Ce.length>0&&n.jsx("button",{type:"button",onClick:Q,title:`Add element to chat (${ui?"⌘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"})}),de&&n.jsx("button",{type:"button",onClick:()=>{Ee()},"aria-label":"Edit CSS properties","aria-pressed":D,title:"Edit CSS properties",className:_("flex h-5 w-5 items-center justify-center rounded-md transition-colors",D||Ve?"bg-[#3a96dd]/15 text-[#3a96dd]":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:n.jsx(q_,{className:"h-3 w-3"})}),Fe&&E&&n.jsx("button",{type:"button","aria-label":"Delete annotation",title:"Delete annotation",onClick:()=>{N(t,[E.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(se=>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:${se.mimeType};base64,${se.data}`,alt:"",className:"h-full w-full object-cover"}),n.jsx("button",{type:"button","aria-label":"Remove attached image",onClick:()=>A(Oe=>Oe.filter(ot=>ot.id!==se.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(Zt,{className:"h-2.5 w-2.5"})})]},se.id))}),n.jsxs("div",{className:"px-3 py-1.5",children:[n.jsx("textarea",{ref:te,rows:2,value:k,onChange:se=>{L(se.target.value),a&&l(!1);const Oe=se.currentTarget;Oe.style.height="auto",Oe.style.height=`${Math.min(144,Math.max(44,Oe.scrollHeight))}px`},onPaste:se=>{const Oe=Array.from(se.clipboardData.files);Oe.length>0&&(se.preventDefault(),Dt(Oe))},onKeyDown:se=>{if(se.nativeEvent.isComposing)return;const Oe=ui?se.metaKey:se.ctrlKey;if(Oe&&se.key.toLowerCase()==="l"){se.preventDefault(),se.stopPropagation(),Q();return}if(se.key==="Enter"&&!se.shiftKey){if(Je||Oe){se.preventDefault(),se.stopPropagation(),Ae();return}if(!Fe&&!Xe&&Ce.length>0){se.preventDefault(),se.stopPropagation(),u("child");return}}if(!Je&&!Fe&&!Xe&&Ce.length>0){if(se.key==="Enter"&&se.shiftKey||se.key==="\\"){se.preventDefault(),se.stopPropagation(),u("parent");return}if(se.key==="Tab"){se.preventDefault(),se.stopPropagation(),u(se.shiftKey?"previous":"next");return}}Fe&&E&&!at&&!Ve&&(se.key==="Backspace"||se.key==="Delete")&&!se.altKey&&!se.ctrlKey&&!se.metaKey&&!se.repeat&&(se.preventDefault(),se.stopPropagation(),N(t,[E.id]),m())},placeholder:Ve?"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"}),Ve&&!D&&me&&n.jsx("section",{"aria-label":"CSS edits",className:"mt-1.5 flex flex-wrap gap-1 text-[10px] text-[#3a96dd]",children:[...me.changes].map(([se,Oe])=>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:[se,":"]}),Oe.to===null?n.jsx("span",{children:"removed"}):n.jsxs(n.Fragment,{children:[n.jsx("del",{className:"opacity-65",children:Oe.from}),n.jsx("span",{className:"opacity-60",children:"→"}),n.jsx("ins",{className:"font-semibold no-underline",children:Oe.to})]})]},se))})]}),D&&U&&de&&n.jsx(A7,{stage:U,pinned:H,onTogglePinned:()=>G(se=>!se),onClose:()=>M(!1),onStageChange:(se,Oe)=>{J(se),window.electronAPI.browser.previewDesignCss(e,"draft",{[de.uniqueId]:Oe})}}),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:Z,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:se=>{Dt(Array.from(se.target.files??[])),se.target.value=""}}),n.jsx("button",{type:"button",onClick:()=>Z.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(bh,{className:"h-3.5 w-3.5"})}),n.jsxs("label",{htmlFor:ue,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:ue,type:"checkbox",checked:!y,onChange:se=>j(!se.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",y?"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",y?"translate-x-0.5":"translate-x-3")})}),n.jsx("span",{children:"Batch edits"})]})]}),n.jsxs("button",{type:"button",disabled:Ne||!Je,"aria-label":K,title:`${K} (Enter)`,onClick:()=>{Ae()},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:[rt==="add-to-stack"?n.jsx(Xn,{className:"h-3 w-3"}):rt==="save-note"?n.jsx(Dn,{className:"h-3 w-3"}):n.jsx(Id,{className:"h-3 w-3"}),n.jsx("span",{children:K})]})]})]})]})}function R7({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,y]=f.useState(!1),[j,w]=f.useState(!1),[b,N]=f.useState(!1),C=Ln(G=>G.annotationsFor(t,e)),E=Ln(G=>G.annotationsFor(t)),T=f.useRef(s);f.useEffect(()=>{s&&Ln.getState().setBrowserUrl(e,s),T.current!==s&&(T.current=s,d(null),h(null),w(!1),c(!1),y(!1))},[e,s]);const k=f.useCallback(async G=>{G?Ln.getState().markEntered():(d(null),h(null),g(null),w(!1),c(!1));const U=await window.electronAPI.browser.setDesignMode(e,G);o(U)},[e,o]);f.useEffect(()=>{if(!r||!s)return;const G=Ow(s),U=C.filter(J=>J.pageKey===G).map(cT);window.electronAPI.browser.setAnnotationPins(e,G,U)},[r,s,C,e]);const L=f.useCallback(G=>{if(g(G),G!==null&&u&&u.region===null&&u.elements.length>0){const U=u.elements.map(pe=>pe.rect.x),J=u.elements.map(pe=>pe.rect.y),$=u.elements.map(pe=>pe.rect.x+pe.rect.width),oe=u.elements.map(pe=>pe.rect.y+pe.rect.height),Ne=Math.max(0,Math.min(...U)-12),ce=Math.max(0,Math.min(...J)-12),ne=Math.max(24,Math.max(...$)-Ne+12),Y=Math.max(24,Math.max(...oe)-ce+12);d({...u,region:{left:Ne,top:ce,width:ne,height:Y}})}},[u]);f.useEffect(()=>window.electronAPI.browser.onDesignMode(G=>{if(G.tabId===e){if(G.type==="cancelled"){d(null),h(null),g(null),c(!1);return}if(G.type==="drawing"){c(G.drawing);return}if(G.type==="pins"){Ln.getState().setPinnedIds(e,G.ids);return}if(G.type==="pin-click"){d(null),w(!1),G.pin&&h({id:G.id,badge:G.pin});return}if(G.type==="select"){if(c(!1),h(null),w(!1),G.addToChat&&G.description.elements.length>0){G.description.elements.forEach((U,J)=>{const $=`ui-${Date.now()}-${J}`,oe=Bf(U),Ne=J===0&&G.description.image?{data:G.description.image.data,mimeType:G.description.image.mimeType}:void 0;Ep({kind:"ui-element",id:$,label:oe,path:U.path||U.tagName.toLowerCase(),text:(U.innerText||"").replace(/\s+/g," ").trim().slice(0,200)||Lw(U),imageId:`img-${$}`},Ne)}),Ei(),window.electronAPI.browser.clearSelection(e);return}d({elements:G.elements,region:G.region?{left:G.region.x,top:G.region.y,width:G.region.width,height:G.region.height}:null,viewportWidth:G.viewportWidth,description:G.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]),D=f.useCallback(async G=>{const U=await window.electronAPI.browser.moveSelection(e,G);U.elements.length!==0&&d(J=>J?{...J,elements:U.elements,description:U.description}:null)},[e]),M=f.useCallback(async G=>{if(G.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 U=await window.electronAPI.browser.openAnnotationPin(e,G.id,!0);U&&(d(null),h({id:G.id,badge:U}))},[e,r,k,a]),H=f.useCallback(G=>{const U=Ln.getState(),J=U.annotationsFor(t),$=G?J.filter(ne=>G.has(ne.id)):[...J];if($.length===0)return;const oe=dT($,ne=>ne.pageKey),Ne=oe.ordered.map(ne=>ne.id);if(U.removeAnnotations(t,Ne),!aF({text:oe.text,images:oe.images,mentions:[]})){U.restoreAnnotations(t,oe.ordered),Ie({type:"warning",title:a("Note not sent"),description:a("The note stays in the queue.")});return}U.annotationsFor(t).length===0&&r&&k(!1)},[t,r,k,a]);return f.useEffect(()=>{if(!i)return;const G=U=>{if((ui?U.metaKey:U.ctrlKey)&&U.shiftKey&&!U.altKey&&U.key.toLowerCase()==="d"){U.preventDefault(),U.stopPropagation(),k(!r);return}if(!r||U.key!=="Escape")return;const $=U.target instanceof Element?U.target:null,oe=$?.closest('[role="menu"], [role="listbox"], [role="dialog"], [role="alertdialog"], [aria-expanded="true"], [data-design-owns-escape]')!==null&&$?.closest("[data-design-owns-escape]")!==null,Ne=$?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])')!==null;if(b){U.preventDefault(),U.stopPropagation(),N(!1);return}switch(PT({queueOwnsEscape:b,targetOwnsEscape:oe,targetIsInput:Ne,markupStrokeActive:x,markupToolHeld:p!==null,warningShown:j,draftOpen:u!==null,editorOpen:m!==null})){case"pass-through":return;case"cancel-stroke":U.preventDefault(),U.stopPropagation(),y(!1);return;case"put-down-tool":U.preventDefault(),U.stopPropagation(),g(null);return;case"dismiss-warning":U.preventDefault(),U.stopPropagation(),w(!1);return;case"cancel-draft":U.preventDefault(),U.stopPropagation(),F();return;case"close-editor":U.preventDefault(),U.stopPropagation(),A();return;case"exit":U.preventDefault(),U.stopPropagation(),k(!1);return}};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},[i,r,b,x,p,j,u,m,k,F,A]),{drawing:l,draftPick:u,openPin:m,markupTool:p,warningShown:j,queueOpen:b,allConversationAnnotations:E,setQueueOpen:N,setWarningShown:w,setDraftPick:d,setDesignMode:k,handleMarkupToolChange:L,moveSelection:D,cancelDraft:F,closeOpenPin:A,openPinFromQueue:M,sendQueue:H,setMarkupStrokeActive:y}}const M7=(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,kb=(e,t)=>t.some(s=>M7(e,s)),P7=new Set(["dialog-popup","dialog-viewport","dialog-backdrop","alert-dialog-popup","alert-dialog-viewport","alert-dialog-backdrop"]);function D7(e){if(e.getAttribute("data-enso-float")!==null)return!0;const t=e.getAttribute("data-slot");return t?P7.has(t)||t.endsWith("-popup")||t.endsWith("-positioner"):!1}function Nb(e,t){const s=[];for(const r of Array.from(e.querySelectorAll("*"))){if(!D7(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 GS=f.createContext({visible:!0,active:!0});function EJ({dockConversationId:e,api:t,children:s}){const r=X(d=>d.activeId===e),o=yh(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(GS.Provider,{value:u,children:s})}function O7(){return f.useContext(GS)}const md=new Map,$m=new Set;function Sb(){for(const e of $m)e()}function L7(e){return $m.add(e),()=>{$m.delete(e)}}function _7(e){const t=md.get(e);if(!t?.visible)return!1;let s=0,r;for(const[o,i]of md)i.kind!==t.kind||!i.visible||(s+=1,i.active&&(r=o));return s<=1||r===e}function B7(e,t=!0){const{visible:s,active:r}=O7(),o=f.useRef(null);o.current===null&&(o.current=Symbol(e));const i=o.current;f.useEffect(()=>{if(t)return md.set(i,{kind:e,visible:s,active:r}),Sb(),()=>{md.delete(i),Sb()}},[r,t,i,e,s]);const a=f.useSyncExternalStore(L7,()=>_7(i));return t&&a}const F7={tabId:null,url:"",title:"",favicon:null,loading:!1,canGoBack:!1,canGoForward:!1,locked:!1,devtoolsOpen:!1,designMode:!1,holder:null},df=(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,Cb=80,z7=.42;function Ib(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=$7(e,t.bottom);return r>0?{...s,radius:r}:s}function $7(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 V7(){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(Ro,{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 H7(e){return window.electronAPI.remote?n.jsx(V7,{}):n.jsx(W7,{...e})}function W7({conversationId:e,panelApi:t,active:s}){const{t:r}=z(),o=X(Y=>OT(Y.conversations,e)),i=yh(o),a=X(Y=>Y.activeId===o),l=s??(i&&a),c=B7("browser",s===void 0),u=s??c,[d,m]=f.useState(F7),[h,p]=f.useState(""),[g,x]=f.useState(!1),[y,j]=f.useState(null),[w,b]=f.useState(z7),[N,C]=f.useState({width:800,height:600}),E=f.useRef(null),T=f.useRef(null),k=f.useRef(null),L=f.useRef(void 0),F=f.useRef(!1),A=f.useRef(void 0),D=f.useRef(!1),M=f.useRef(!1);M.current=d.locked;const H=f.useRef(!1);H.current=d.devtoolsOpen;const G=(d.url.startsWith("http")||d.url.startsWith("file:"))&&!d.loading,U=f.useRef(!1);U.current=G;const J=f.useRef(null),$=t.id,oe=R7({tabId:$,conversationId:e,url:d.url,designMode:d.designMode,onDesignModeState:m,active:u});f.useEffect(()=>{const Y=E.current;if(!Y)return;const pe=()=>{const we=Y.getBoundingClientRect();we.width>0&&we.height>0&&C({width:Math.round(we.width),height:Math.round(we.height)})};pe();const ge=new ResizeObserver(pe);return ge.observe(Y),()=>ge.disconnect()},[]),f.useEffect(()=>window.electronAPI.browser.onState(Y=>{Y.tabId===$&&m(Y.state)}),[$]),f.useEffect(()=>window.electronAPI.browser.onDesignMode(Y=>{if(Y.tabId!==$||Y.type==="cancelled"||Y.type==="select"||Y.type==="drawing"||Y.type==="pin-click"||Y.type==="pins")return;let pe=!1;if(Y.type==="annotated")pe=Y.image?dF(Y.image):!1;else{const ge=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`ui-${Date.now()}`;pe=Ep({kind:"ui-element",id:ge,label:Y.payload.label||Y.payload.tag||"element",path:Y.payload.path||Y.payload.tag||"element",text:Y.payload.text||Y.payload.label||Y.payload.tag||"element",imageId:`img-${ge}`},Y.image)}pe?Ei():Ie({type:"warning",title:r("No Composer for this selection")})}),[$,r]),f.useEffect(()=>{g||p(d.url)},[d.url,g]),f.useEffect(()=>{const Y=d.title.trim()||r("Browser");t.setTitle(Y),t.updateParameters({...t.getParameters(),favicon:d.favicon})},[t,d.title,d.favicon,r]),f.useEffect(()=>{let Y=0,pe=!1;document.getElementById("root"),zw();const ge=()=>{if(pe)return;const we=l&&t.isActive&&t.isVisible&&document.visibilityState==="visible",V=we?Ib(E.current):null,W=V!==null&&(M.current||kb(V,Nb(document)));(L.current===void 0||!df(L.current,V)||W!==F.current)&&(L.current=V,F.current=W,window.electronAPI.browser.setViewport($,e,V,W).then(m));const B=U.current?V:null;df(J.current,B)||(J.current=B,os.getState().setBrowserHole(`${$}:guest`,B));const te=we&&H.current?Ib(T.current):null,Z=te!==null&&kb(te,Nb(document));(A.current===void 0||!df(A.current,te)||Z!==D.current)&&(os.getState().setBrowserHole(`${$}:devtools`,te),A.current=te,D.current=Z,window.electronAPI.browser.setDevToolsViewport($,e,te,Z).then(m)),Y=requestAnimationFrame(ge)};return Y=requestAnimationFrame(ge),()=>{pe=!0,cancelAnimationFrame(Y);const{setBrowserHole:we}=os.getState();we(`${$}:guest`,null),we(`${$}:devtools`,null),J.current=null,L.current!==null&&(L.current=null,window.electronAPI.browser.setViewport($,e,null)),A.current!==null&&(A.current=null,window.electronAPI.browser.setDevToolsViewport($,e,null))}},[e,$,t,l]);const Ne=async()=>{x(!1);const Y=h.trim();if(!Y)return;const pe=await window.electronAPI.browser.navigate($,e,Y);j(pe.ok?null:pe.error??r("Navigation failed"))},ce=Y=>{const pe=E.current,ge=T.current;if(!pe||!ge)return;Y.currentTarget.setPointerCapture(Y.pointerId);const we=Y.clientY,V=pe.getBoundingClientRect().height,W=ge.getBoundingClientRect().height,B=V+W,te=ue=>{const fe=Math.min(B-Cb,Math.max(Cb,W-(ue.clientY-we)));b(fe/B)},Z=()=>{window.removeEventListener("pointermove",te),window.removeEventListener("pointerup",Z)};window.addEventListener("pointermove",te),window.addEventListener("pointerup",Z)},ne="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:ne,disabled:d.locked||!d.canGoBack,onClick:()=>{window.electronAPI.browser.goBack($)},"aria-label":r("Back"),children:n.jsx(bi,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",className:ne,disabled:d.locked||!d.canGoForward,onClick:()=>{window.electronAPI.browser.goForward($)},"aria-label":r("Forward"),children:n.jsx(Bw,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",className:ne,disabled:d.locked||!d.tabId,onClick:()=>{window.electronAPI.browser.reload($)},"aria-label":r("Reload"),children:n.jsx(pw,{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:Y=>{Y.preventDefault(),Ne()},children:[n.jsx(Ro,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:Y=>p(Y.target.value),onFocus:Y=>{x(!0),Y.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(T7,{tabId:$,conversationId:e,active:d.designMode,disabled:!d.tabId||d.locked||d.devtoolsOpen,queueOpen:oe.queueOpen,onQueueOpenChange:oe.setQueueOpen,onToggleDesignMode:Y=>{oe.setDesignMode(Y)},onOpenPinFromQueue:Y=>{oe.openPinFromQueue(Y)},onSendQueue:oe.sendQueue}),n.jsx("button",{type:"button",className:_(ne,d.devtoolsOpen&&"bg-muted text-foreground"),disabled:!d.tabId,onClick:()=>{window.electronAPI.browser.setDevTools($,!d.devtoolsOpen).then(m)},"aria-label":r("Toggle Developer Tools"),"aria-pressed":d.devtoolsOpen,children:n.jsx(Vk,{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(Z0,{className:"h-3 w-3"}),r("Enso is in control")]})]}),d.designMode&&n.jsx(I7,{drawing:oe.drawing,pick:oe.draftPick,markupTool:oe.markupTool,editorOpen:oe.openPin!==null,onMarkupToolChange:oe.handleMarkupToolChange,onExit:()=>{oe.setDesignMode(!1)}}),y&&n.jsx("div",{className:"border-b bg-destructive/10 px-3 py-1 text-xs text-destructive",children:y}),n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col","data-slot":"browser-native-stack",children:[n.jsxs("div",{ref:E,className:_("relative min-h-0",d.devtoolsOpen?"shrink-0":"flex-1",G?"bg-transparent":"bg-background"),style:d.devtoolsOpen?{flex:`${1-w} 1 0`}:void 0,children:[n.jsx(C7,{active:d.designMode}),d.designMode&&n.jsx(E7,{tabId:$,conversationId:e,stageSize:N,draftPick:oe.draftPick,openPin:oe.openPin,markupTool:oe.markupTool,warningShown:oe.warningShown,onWarningShownChange:oe.setWarningShown,onDraftPickChange:oe.setDraftPick,onMoveSelection:Y=>{oe.moveSelection(Y)},onCancelDraft:oe.cancelDraft,onCloseOpenPin:oe.closeOpenPin,onSendQueue:oe.sendQueue,onStrokeStateChange:oe.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(Ro,{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(Z0,{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:ce}),n.jsx("div",{ref:T,className:"min-h-0 bg-transparent",style:{flex:`${w} 1 0`}})]})]})]})}function U7({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}
58
- ${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(Ro,{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(Zt,{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(Xn,{className:"h-3.5 w-3.5"})})]}),m&&n.jsx(H7,{conversationId:LT(e),panelApi:m,active:t},m.id)]})}const G7=/[A-Za-z0-9._%+-]/,Tb=/[A-Za-z0-9_-]/,K7=/```[\s\S]*?(?:```|$)|`[^`\n]*`/g;function KS(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 q7(e,t){if(typeof e!="string")return{ids:[],all:!1};const s=e.normalize("NFC").replace(K7,a=>" ".repeat(a.length)),r=[...t.map(a=>({key:Tc(a.name),id:a.id})),...$w.map(a=>({key:Tc(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&&G7.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&&Tb.test(c.at(-1)??"")&&Tb.test(d))});l&&(l.id===null?i=!0:o.includes(l.id)||o.push(l.id))}return{ids:o,all:i}}function Y7(e,t){const s=KS(t),{ids:r,all:o}=q7(e,s);return o?{ids:[...new Set(s.map(i=>i.id))],all:o}:{ids:r,all:o}}function X7(e,t){const s=Tc(typeof e=="string"?e.replace(/^@/,""):"");return KS(t).filter(r=>Tc(r.name).startsWith(s))}function Vm(e,t){return/(?:^|\s)\$([^\s$]*)$/.exec(e.slice(0,t))?.[1]??null}function qS(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 Q7(e,t,s){const r=s??t;if(r===null)return[];const o=r.toLowerCase();return qS(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 YS=["agents","members","chats"];function J7(e){return[...YS.flatMap(t=>e[t].map(s=>({candidate:s,group:t}))),...e.files.map(t=>({candidate:t,group:"files"}))]}function XS(e,t){const s=YS.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"}))]:J7(e).map(r=>({type:"item",candidate:r.candidate,group:r.group}))}const Z7=20;function eW(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,Z7).map(r=>({kind:"chat",id:r.id,label:r.title.split(`
59
- `)[0].trim()||"Untitled chat",sessionFile:r.sessionFile}))}function tW(e){return e.map(t=>({...t,kind:"agent-type",id:t.typeKey,label:t.displayName}))}function nW(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 sW(e,t,s,r=[]){const o=e.trim().toLocaleLowerCase(),i=o?t.filter(c=>`${c.label}
60
- ${c.description}
61
- ${c.source}
62
- ${c.typeKey}`.toLocaleLowerCase().includes(o)):[...t],a=o?s.filter(c=>`${c.label}
63
- ${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 QS(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=Vw(h);m||i(p?tW(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(e,t)).then(p=>{m||l(nW(p))}).catch(()=>{m||l([])})},150);return()=>{m=!0,window.clearTimeout(h)}},[e,t,u]),f.useMemo(()=>t===null?{agents:[],members:[],files:[],chats:[]}:sW(t,o,a,s),[o,a,s,t])}const Ab={bot:"Mention a member",all:"Mention a member",chat:"Reference a chat",file:"Files",skill:"Skills"},rW=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 oW({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,y]=f.useState(()=>og(localStorage,e)),[j,w]=f.useState([]),[b,N]=f.useState(null),[C,E]=f.useState(0),[T,k]=f.useState(!1),L=xe(V=>V.keybindings),{"send-message":F}=Mr(L),{text:A}=x,D=V=>y(W=>({...W,...V}));f.useEffect(()=>{h.current?.focus()},[]),f.useEffect(()=>{_T(localStorage,e,x)},[e,x]),f.useEffect(()=>BT(V=>{V===e&&y(og(localStorage,V))}),[e]),f.useLayoutEffect(()=>{const V=h.current;V&&(V.style.height="auto",V.style.height=`${Math.min(V.scrollHeight,220)}px`)},[A]);const M=f.useCallback(V=>window.electronAPI.bots.searchFiles({chatId:e,query:V}).then(W=>W.ok?W.files:[]),[e]),H=QS(void 0,b?.kind==="at"?b.query:null,[],{searchFiles:M,agents:!1}).files,G=(()=>{if(!b)return[];const V=b.query.toLowerCase();if(b.kind==="skill")return o.filter(B=>B.name.toLowerCase().includes(V)).slice(0,10).map(B=>({kind:"skill",skill:B}));const W=s?X7(b.query,s).map(B=>({kind:"bot",bot:B})):[];return s&&$w.some(B=>B.startsWith(V))&&W.push({kind:"all"}),x.chats.length<FT&&W.push(...r.filter(B=>!x.chats.includes(B.id)&&B.title.toLowerCase().includes(V)).slice(0,6).map(B=>({kind:"chat",chat:B}))),W.push(...H.slice(0,8).map(B=>({kind:"file",path:B.relativePath,name:B.label}))),W})(),U=(V,W)=>{const B=o.length?Vm(V,W):null;if(B!==null){N({kind:"skill",start:W-B.length-1,query:B}),E(0);return}const te=/(^|[^A-Za-z0-9._%+-])@([^\s@]*)$/u.exec(V.slice(0,W));if(!te)return N(null);N({kind:"at",start:W-te[2].length-1,query:te[2]}),E(0)},J=V=>{if(!b)return;const W=h.current,B=W?.selectionStart??A.length,te=A.slice(0,b.start),Z=A.slice(B);let ue="";const fe={};V.kind==="bot"||V.kind==="all"?ue=`@${V.kind==="all"?m("everyone"):V.bot.name} `:V.kind==="file"?(ue=`@${V.path} `,fe.files=[...new Set([...x.files,V.path])]):V.kind==="chat"?fe.chats=[...x.chats,V.chat.id]:fe.skill=V.skill.id,D({...fe,text:te+ue+Z}),N(null);const Ce=te.length+ue.length;requestAnimationFrame(()=>{W?.focus(),W?.setSelectionRange(Ce,Ce)})},$=V=>{for(const W of V){if(!W.type.startsWith("image/"))continue;const B=new FileReader;B.onload=()=>{const te=B.result;w(Z=>[...Z,{data:te.slice(te.indexOf(",")+1),mimeType:W.type}])},B.readAsDataURL(W)}},oe=V=>{const W=h.current,B=W?.selectionStart??A.length,te=W?.selectionEnd??A.length;window.electronAPI.bots.savePastedText({chatId:e,text:V}).catch(()=>({ok:!1,error:"unavailable"})).then(Z=>{const ue=Z.ok?`@${Z.path} `:V;y(fe=>({...fe,text:fe.text.slice(0,B)+ue+fe.text.slice(te)})),requestAnimationFrame(()=>{W?.focus(),W?.setSelectionRange(B+ue.length,B+ue.length)})})},Ne=new Map(r.map(V=>[V.id,V])),ce=x.skill?o.find(V=>V.id===x.skill||V.name===x.skill):void 0,ne=ce&&s?s.filter(V=>Y7(A,s).ids.includes(V.id)&&!ce.owners.includes(V.id)):[],Y=!a&&!T&&(A.trim().length>0||j.length>0||x.chats.length>0||!!x.skill),pe=async()=>{if(!Y)return;const V=x,W=j,B=V.text.trim();y(zT),w([]),N(null),k(!0);try{await u({text:B,images:W,files:V.files.filter(Z=>B.includes(`@${Z}`)),chats:V.chats,...V.skill?{skill:ce?.id??V.skill}:{}})||(y(Z=>Z.text||Z.chats.length||Z.skill?Z:V),w(Z=>Z.length?Z:W))}finally{k(!1)}},ge=V=>{const W=V.nativeEvent.isComposing||g.current;if(b&&G.length>0&&!W){if(V.key==="ArrowDown"||V.key==="ArrowUp"){V.preventDefault();const B=V.key==="ArrowDown"?1:-1;E(te=>(te+B+G.length)%G.length);return}if(V.key==="Enter"||V.key==="Tab"){V.preventDefault(),J(G[Math.min(C,G.length-1)]);return}if(V.key==="Escape"){V.preventDefault(),N(null);return}}!W&&Ww(V,F)&&(V.preventDefault(),pe())},we=V=>(s??[]).filter(W=>V.includes(W.id)).map(W=>W.name).join(", ");return n.jsxs("div",{"data-slot":"composer",className:"relative rounded-2xl border bg-background shadow-float",onDragOver:V=>V.preventDefault(),onDrop:V=>{V.preventDefault(),$([...V.dataTransfer.files])},children:[b&&G.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:G.map((V,W)=>{const B=Ab[V.kind],te=W===0||Ab[G[W-1].kind]!==B;return n.jsxs("div",{children:[te&&n.jsx("div",{className:"px-2 py-1 text-[11px] text-muted-foreground",children:m(B)}),n.jsx("button",{type:"button",onMouseDown:Z=>{Z.preventDefault(),J(V)},onMouseEnter:()=>E(W),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm",W===C&&"bg-muted"),children:n.jsx(iW,{item:V,ownerNames:we,grouped:!!s})})]},rW(V))})}),(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(Eb,{icon:n.jsx(Bs,{className:"h-3 w-3"}),label:ce?.name??x.skill,tone:"skill",onRemove:()=>D({skill:void 0})}),x.chats.map(V=>n.jsx(Eb,{icon:n.jsx(Jr,{className:"h-3 w-3"}),label:Ne.get(V)?.title??m("Unavailable chat"),onRemove:()=>D({chats:x.chats.filter(W=>W!==V)})},V))]}),ne.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:ne.map(V=>V.name).join(", ")})}),j.length>0&&n.jsx("div",{className:"flex flex-wrap gap-2 px-3 pt-3",children:j.map((V,W)=>n.jsxs("div",{className:"group relative h-14 w-14 overflow-hidden rounded-lg border",children:[n.jsx("img",{src:`data:${V.mimeType};base64,${V.data}`,alt:"",className:"h-full w-full object-cover"}),n.jsx("button",{type:"button","aria-label":m("Remove"),onClick:()=>w(B=>B.filter((te,Z)=>Z!==W)),className:"absolute top-0.5 right-0.5 hidden rounded-full bg-background/90 p-0.5 group-hover:block",children:n.jsx(Zt,{className:"h-3 w-3"})})]},W))}),n.jsx("textarea",{ref:h,value:A,rows:1,disabled:a,placeholder:t,onChange:V=>{D({text:V.target.value}),U(V.target.value,V.target.selectionStart)},onSelect:V=>U(V.currentTarget.value,V.currentTarget.selectionStart),onBlur:()=>N(null),onKeyDown:ge,onCompositionStart:()=>{g.current=!0},onCompositionEnd:()=>{g.current=!1},onPaste:V=>{const W=[...V.clipboardData.files].filter(B=>B.type.startsWith("image/"));if(W.length===0){const B=V.clipboardData.getData("text/plain");if(!Hw(B))return;V.preventDefault(),oe(B);return}V.preventDefault(),$(W)},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(bh,{className:"h-4 w-4"})}),n.jsx("input",{ref:p,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:V=>{$([...V.target.files??[]]),V.target.value=""}}),l,n.jsx("div",{className:"min-w-0 flex-1 truncate text-muted-foreground text-xs",children:c}),i&&d&&!Y?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(Fw,{className:"h-3 w-3 fill-current"})}):n.jsx("button",{type:"button",disabled:!Y,onClick:()=>{pe()},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(Id,{className:"h-4 w-4"})})]})]})}function iW({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(Fo,{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 Eb({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(Zt,{className:"h-3 w-3"})})]})}const aW={thinking:"Thinking",typing:"Writing reply",tool:"Calling tools",retrying:"Retrying"},Rb={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"},lW={running:"Running",done:"Done",error:"Error",denied:"Denied",timeout:"Timed out · denied"},cW={running:"text-primary",done:"text-success",error:"text-destructive",denied:"text-warning",timeout:"text-warning"},dW=e=>e<1e4?`${(Math.max(0,e)/1e3).toFixed(1)}s`:Pr(e);function JS({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(()=>$T(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(aW[l.state]):o(a?.reason&&Object.hasOwn(Rb,a.reason)?Rb[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:Pr(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",cW[h.status]),children:o(h.status==="timeout"&&h.name==="ask_user"?"Timed out · no answer":lW[h.status])}),p!==void 0&&n.jsx("span",{className:"shrink-0 tabular-nums",children:dW(p)})]},h.id)})]})]})}const uW=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),fW=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),mW=[],hW={auto:"Automatic",delegator:"By delegator",human:"Manual"};function su({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 ZS({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 vl(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 pW(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 ya(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 ru(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 xW({record:e,delegations:t}){const{t:s}=z(),r=HT(e);if(!r)return null;const o=Kw(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:WT(e)?s("Retrying automatically · attempt {{n}}",{n:o}):s("Retry #{{n}} · {{source}}",{n:o,source:s(hW[r])})})}function ou({record:e,entry:t,retried:s,append:r,taskSeq:o,fill:i,bots:a,onOpenConversation:l}){const{t:c}=z(),u=ie(H=>H.delegations)??mW,d=e?.state??t?.state??"queued",m=ru(!r&&Na(d)),h=a.get(e?.parentBotId??t?.from??""),p=a.get(e?.targetBotId??t?.to??""),g=UT(r?"completed":d),x=VT(e),y=!r&&x&&Na(d),j=!r&&d==="blocked"?e?.blocked:void 0,w=ie(H=>j&&e?.taskId?H.delegations.some(G=>G.taskId===e.taskId&&G.createdAt>e.createdAt):!1),b=ie(H=>H.openTask),N=!!t?.taskId&&!r,[C,E]=f.useState(!N),T=e?Uw(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:vl(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:[N&&n.jsx(fn,{"aria-hidden":!0,className:_("size-3.5 shrink-0 transition-transform",C&&"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})}):y?n.jsx(Gw,{info:x}):n.jsx(su,{state:d,interrupted:e?.failure==="interrupted",autoRetry:T}),e&&!r&&n.jsx(xW,{record:e,delegations:u}),e&&!r&&n.jsx("span",{children:Pr((e.finishedAt??m)-e.createdAt)}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{children:uW(r?.at??t?.at??e?.createdAt??m)})]}),D="flex flex-wrap items-center gap-1.5 whitespace-nowrap text-muted-foreground text-xs",M=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:[N?n.jsx("button",{type:"button","aria-expanded":C,"aria-label":c(C?"Collapse delegation result":"Expand delegation result"),className:_(D,"w-full rounded text-left hover:text-foreground"),onClick:()=>E(H=>!H),children:A}):n.jsx("div",{className:D,children:A}),!C&&M&&n.jsx("div",{className:"mt-1 truncate text-muted-foreground text-xs",children:M}),C&&M&&n.jsx("div",{className:"mt-1.5 line-clamp-3 text-sm [overflow-wrap:anywhere]",children:M}),C&&n.jsxs(n.Fragment,{children:[e?.check&&!r&&n.jsx(ZS,{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}),j&&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:j.need})}),n.jsx("div",{className:"text-muted-foreground",children:w?c("Answered; the work continues"):j.waitFor==="parent"?c("Waiting for {{name}} to reply",{name:h?.name??c("Deleted member")}):c("Waiting for your reply")})]}),T&&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:fW(e.autoRetryAt),n:Kw(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(he,{size:"xs",variant:"ghost",onClick:()=>l(e.childConversationId,F),children:c("View process")}),j&&!w&&e.chatId&&e.taskId&&n.jsx(he,{size:"xs",variant:"outline",onClick:()=>e.chatId&&e.taskId&&b(e.chatId,e.taskId),children:c("Reply")}),g.cancel&&n.jsx(he,{size:"xs",variant:"outline",onClick:()=>pW(e.id,c),children:c("Cancel")}),g.retry&&!s&&n.jsx(he,{size:"xs",variant:"outline",title:T?c("Skip the wait and retry now. The scheduled automatic retry is canceled."):void 0,onClick:()=>ya(e.id,c),children:c(T?"Retry now":"Retry")}),g.resumeOrRestart&&!s&&n.jsxs(n.Fragment,{children:[n.jsx(he,{size:"xs",variant:"outline",onClick:()=>ya(e.id,c,"resume"),children:c("Continue")}),n.jsx(he,{size:"xs",variant:"outline",onClick:()=>ya(e.id,c,"restart"),children:c("Start over")})]})]})]})]})}function eC(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=>KT(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 gW(e,t){const s=eC(e);return f.useMemo(()=>GT(t,s),[t,s])}function vW(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 tC(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 Hi({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 nC({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=vW(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(tu,{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(Gw,{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(Hi,{label:s("Task"),children:n.jsx("span",{className:"line-clamp-2",children:o.task})}),n.jsx(Hi,{label:s("From"),children:r?.name??s("Deleted member")}),n.jsx(Hi,{label:s("Time"),children:Pr((o.finishedAt??Date.now())-o.createdAt)})]}),i&&n.jsx(Hi,{label:s("Waiting on"),children:i}),a&&n.jsx(Hi,{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:Pr(Date.now()-e.quietSince)})}),o&&e.state==="stuck"&&o.state==="failed"&&n.jsx("div",{className:"text-muted-foreground",children:vl(o,s)}),o&&e.state==="done"&&o.result&&n.jsx("div",{className:"line-clamp-3 text-muted-foreground",children:o.result}),l&&n.jsx(he,{size:"xs",className:"mt-1 self-start",onClick:()=>tC(l),children:s("Go handle it")})]})]})}function sC({chatId:e,botId:t,bot:s,size:r="sm"}){const{t:o}=z(),i=gW(e,t);return n.jsxs(xl,{children:[n.jsxs(gl,{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:$f(i,o)})]}),n.jsx(nC,{info:i,bot:s})]})}function bW({chatId:e,memberIds:t,bots:s,onOpenLive:r}){const{t:o}=z(),i=eC(e),a=f.useMemo(()=>qT(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=YT(c),h=XT(c);return n.jsxs(xl,{children:[n.jsxs(gl,{render:n.jsx("button",{type:"button",onClick:()=>h?.kind==="pending"?tC(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,$f(c,o),m].join(" · ")}):n.jsx("span",{className:"sr-only",children:`${d} · ${$f(c,o)}`})]}),n.jsx(nC,{info:c,bot:u})]},l)})})}function yW(e){return{budgetCost:e?.dailyCostUsd!==void 0?String(e.dailyCostUsd):"",budgetTokens:e?.dailyTokens!==void 0?String(e.dailyTokens):""}}function rC(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 wW(e){return{delegationTimeout:e.delegationTimeoutMinutes!==void 0?String(e.delegationTimeoutMinutes):"",maxTurnTokens:e.maxTokensPerTurn!==void 0?String(e.maxTokensPerTurn):""}}function cx(e){const t=e.delegationTimeout.trim()?Number(e.delegationTimeout):null,s=e.maxTurnTokens.trim()?Number(e.maxTurnTokens):null;return t!==null&&!QT(t)||s!==null&&!JT(s)?{ok:!1}:{ok:!0,delegationTimeoutMinutes:t,maxTokensPerTurn:s}}function Mb(e){return[...e.normalize("NFC").trim().replace(/\s+/gu,"_").replace(/[^\p{L}\p{N}_-]/gu,"").replace(/_+/gu,"_").replace(/^_+|_+$/gu,"")].slice(0,eA).join("")}const Kr=e=>typeof e=="string"?e.trim():"",uf=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Pb(e){const t=e.split(`
64
- `).find(r=>r.trim())??"",s=/^.*?[.!?。!?](?=\s|$)/u.exec(t.trim());return(s?s[0]:t.trim()).slice(0,80)}function jW(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 kW(e){return{...typeof e.title=="string"?{title:e.title.trim()}:{},...Kr(e.scope)?{scope:Kr(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}:{},...ZT.includes(e.approvalMode)?{approvalMode:e.approvalMode}:{},...typeof e.memory=="boolean"?{memoryEnabled:e.memory}:{}}}function NW(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=uf(s.data)?s.data:s,o=Kr(r.name);if(!o)return{ok:!1,error:"not-a-card"};const i=uf(r.extensions)?r.extensions.enso:void 0;if(uf(i)){const u=typeof r.description=="string"?r.description:"";return{ok:!0,draft:{name:Mb(o),title:"",scope:Pb(u),persona:u,...kW(i)}}}const a=u=>u.replace(/\{\{char\}\}/giu,o).replace(/\{\{user\}\}/giu,"the user"),l=a(Kr(r.description)),c=[l,Kr(r.personality)&&`Personality: ${a(Kr(r.personality))}`,Kr(r.scenario)&&`Scenario: ${a(Kr(r.scenario))}`].filter(Boolean);return{ok:!0,draft:{name:Mb(o),title:"",scope:Pb(l),persona:c.join(`
65
-
66
- `)}}}const SW=["tools","approvalMode","skillIds","mcpServerIds","canDelegateTo","acceptFrom"],CW=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every(s=>t.includes(s)):e===t;function Db(e,t){return SW.flatMap(s=>{const r=t[s];return!r||CW(e[s],r.value)?[]:[{field:s,from:e[s],to:r.value,reason:r.reason}]})}function IW(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 oC={tools:"all",approvalMode:"auto-edits",skillIds:[],mcpServerIds:[],canDelegateTo:"any",acceptFrom:"any",memoryEnabled:!0,budgetCost:"",budgetTokens:"",delegationTimeout:"",maxTurnTokens:""};function iC({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(TW,{value:e,onApply:t,profile:s,botId:r}),n.jsxs("div",{children:[n.jsx(Lt,{children:i("Tools")}),n.jsx(wh,{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(Lt,{children:i("Approval mode")}),n.jsx(qw,{value:e.approvalMode,onChange:c=>t({approvalMode:c}),zIndex:o})]}),n.jsx(aC,{value:e,onChange:t}),n.jsx(Ob,{label:i("Can delegate to"),value:e.canDelegateTo,bots:l,onChange:c=>t({canDelegateTo:c})}),n.jsx(Ob,{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(sr,{checked:e.memoryEnabled,onCheckedChange:c=>t({memoryEnabled:c})})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:i("Daily budget")}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx(Vt,{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(Vt,{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(Lt,{children:i("Per-turn token limit")}),n.jsx(Vt,{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(Lt,{children:i("Delegation time limit (minutes)")}),n.jsx(Vt,{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 iu(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 TW({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?Db(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:iu(x,o),...x.detail?{description:x.detail}:{}});return}if(Db(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(j=>j.field).filter(j=>!d.includes(j)),y=IW(e,h,x);t(Object.fromEntries(x.map(j=>[j,y[j]]))),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(he,{size:"xs",variant:"outline",disabled:a,onClick:()=>{p()},children:[a?n.jsx(Bt,{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(Bo,{className:"mt-0.5",checked:!d.includes(x.field),onCheckedChange:y=>m(j=>y?j.filter(w=>w!==x.field):[...j,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:AW(x.field,o)}),n.jsx(EW,{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(he,{size:"xs",variant:"outline",onClick:()=>u(null),children:o("Cancel")}),n.jsx(he,{size:"xs",disabled:h.every(x=>d.includes(x.field)),onClick:g,children:o("Apply")})]})]})]})}function AW(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 EW({change:e}){const{t}=z(),s=xe(h=>h.skills),r=xe(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(Sa[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 aC({value:e,onChange:t}){const{t:s}=z(),r=xe(a=>a.skills),o=xe(a=>a.mcpServers),i=(a,l)=>a.includes(l)?a.filter(c=>c!==l):[...a,l];return n.jsxs(n.Fragment,{children:[n.jsx(ig,{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:lg(e.skillIds,a,l)}),placeholder:s("Filter skills..."),renderDetail:a=>n.jsx(ag,{rows:[[s("Source"),a.source],[s("Path"),a.path],[s("Description"),a.description]]})}),n.jsx(ig,{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:lg(e.mcpServerIds,a,l)}),placeholder:s("Filter MCP servers..."),renderDetail:a=>n.jsx(ag,{rows:[[s("Source"),a.source],["Transport",a.transport],["URL",a.url]]})})]})}function Ob({label:e,value:t,bots:s,onChange:r}){const{t:o}=z();return n.jsxs("div",{children:[n.jsx(Lt,{children:e}),n.jsx(wh,{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(Bo,{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 RW({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:yu(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&&`${yu(s.today.cost??0)} / ${yu(o.dailyCostUsd)}`].filter(Boolean).join(" · "),s.exhausted&&` · ${t("Today's budget is used up")}`]})]})}function lC({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(Bt,{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(MW,{item:i,onDeleted:()=>r(a=>a?.filter(l=>l.id!==i.id)??null)},i.id))})}function MW({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(Vt,{size:"sm",value:r.title,placeholder:s("Memory title"),onChange:u=>o({...r,title:u.target.value})}),n.jsx(Ks,{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(he,{size:"xs",variant:"ghost",disabled:i,onClick:()=>o(null),children:s("Cancel")}),n.jsxs(he,{size:"xs",disabled:i||!r.content.trim(),onClick:()=>{c()},children:[i&&n.jsx(Bt,{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(Bt,{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 cC({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(Ks,{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(he,{size:"xs",variant:"ghost",disabled:u,onClick:()=>c(null),children:s("Cancel")}),n.jsx(he,{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(he,{size:"xs",variant:"outline",onClick:()=>c(i.content),children:s("Edit notes")})]}):n.jsx(Bt,{className:"h-4 w-4 animate-spin text-muted-foreground"})}function dC({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:iu(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(he,{size:"xs",variant:"ghost",className:"-my-1 h-6 text-muted-foreground",disabled:o,onClick:()=>{a()},children:[o?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Bs,{}),s("Generate with AI")]})}function Lb(e){const t=jh(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 PW(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 DW(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 OW(e){return e.status==="review"&&!!(e.delegationId&&e.assigneeBotId)}function LW(e,t){return e.filter(s=>s.chatId===t).sort((s,r)=>s.createdAt-r.createdAt)}const Fl=e=>e.finishedAt??e.createdAt;function _W(e,t){const s=e.filter(o=>o.chatId===t),r=o=>Na(o.state)||Uw(o,e);return{active:s.filter(r).sort((o,i)=>o.createdAt-i.createdAt),completed:s.filter(o=>o.state==="completed").sort((o,i)=>Fl(i)-Fl(o)),failed:s.filter(o=>["failed","canceled","blocked"].includes(o.state)&&!r(o)).sort((o,i)=>Fl(i)-Fl(o))}}function BW(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 FW(e,t){const s=tA(e);if(!s)return;const r=t.find(i=>i.id===e.delegationId);if(s.reason==="failed"){const i=Yw(e);return{reason:"failed",...r?{record:r}:{},since:i?.finishedAt??r?.finishedAt??e.updatedAt}}const o=(e.blockedStreak?.[e.assigneeBotId??""]??0)>=nA;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 zW=["0 9 * * *","0 9 * * 1-5","0 9 * * 1","0 * * * *"];function $W(e,t,s){const r=jh(e);if(r)return{source:r.source,description:kh(r,t),next:sA(r,s)}}function VW(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 HW(e){return e.title.trim()?e.prompt.trim()?jh(e.schedule)?e.chatId?null:"chat":"schedule":"prompt":"title"}function hd(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 gi("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?gi(s,t):t("This routine is blocked. Fix the problem and enable it again.");default:return e}}function gi(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 uC(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 dx(){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:hd(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 fC({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:[kh(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 WW({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}=dx(),{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(ux,{routine:u})]}),n.jsx(fC,{routine:u}),e.kind==="blocked"&&n.jsx("div",{className:"mt-1 text-destructive text-xs",children:gi(u.blockedReason,t)}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[m&&n.jsx(he,{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(he,{size:"xs",variant:"outline",disabled:i,onClick:()=>c(u,!0),children:t("Dry run")}),n.jsx(he,{size:"xs",variant:"outline",disabled:i,onClick:()=>a(u,!1),children:t("Reject")}),n.jsx(he,{size:"xs",disabled:i,onClick:()=>a(u,!0),children:t("Approve")})]}):n.jsx(he,{size:"xs",disabled:i,onClick:()=>l(u),children:t("Enable again")})]})]})}function ux({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 UW({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}=dx();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(ux,{routine:r}):n.jsx("span",{className:"text-[11px]",children:s("Routine removed")})]}),r&&n.jsx(fC,{routine:r}),r?.status==="draft"&&n.jsxs("div",{className:"mt-2 flex justify-end gap-1.5",children:[n.jsx(he,{size:"xs",variant:"ghost",disabled:o,onClick:()=>a(r,!0),children:s("Dry run")}),n.jsx(he,{size:"xs",variant:"outline",disabled:o,onClick:()=>i(r,!1),children:s("Reject")}),n.jsx(he,{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 mC(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 GW(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 KW(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 hC({botId:e,chatId:t}){const{t:s,locale:r}=z(),o=ie(b=>b.chats),i=ie(b=>b.bots),[a,l]=f.useState(null),[c,u]=f.useState(null),[d,m]=f.useState(null),[h,p]=f.useState(null),g=dx(),x=f.useCallback(async()=>{const b=await window.electronAPI.bots.routines.list(e?{botId:e}:{}).catch(()=>null),N=b?.ok?b.routines:[];l(t?LW(N,t):N)},[e,t]);f.useEffect(()=>(l(null),x(),window.electronAPI.bots.onEvent(b=>{b.kind==="routine"&&x()})),[x]);const y=async(b,N)=>{const{id:C,title:E,prompt:T,schedule:k}=b,L=await window.electronAPI.bots.routines.save({botId:b.botId,id:C,title:E,prompt:T,schedule:k,chatId:b.chatId,enabled:N});L.ok?L.routine.status==="blocked"&&Ie({type:"error",title:s("Routine blocked"),description:gi(L.routine.blockedReason,s)}):Ie({type:"error",title:s("Routine not saved"),description:hd(L.error,s)}),x()},j=async b=>{m(null);const N=await window.electronAPI.bots.routines.remove({botId:b.botId,id:b.id});N.ok||Ie({type:"error",title:s("Routine not deleted"),description:hd(N.error,s)}),x()};if(a===null)return n.jsx(Bt,{className:"h-4 w-4 animate-spin text-muted-foreground"});const w=b=>i.find(N=>N.id===b)?.name??s("Deleted member");return n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs(he,{size:"xs",variant:"outline",onClick:()=>u("new"),children:[n.jsx(Xn,{}),s("New routine")]}),a.length===0&&n.jsx("p",{className:"text-muted-foreground text-xs",children:s("No routines yet")}),a.map(b=>{const N=o.find(k=>k.id===b.chatId),C=b.status==="draft",E=rA(b)&&(b.status==="enabled"||b.status==="paused"),T=N?s("Posts to {{chat}}",{chat:is(N,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",b.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:b.title}),n.jsx(ux,{routine:b}),!C&&n.jsx(sr,{checked:b.status==="enabled",onCheckedChange:k=>{y(b,k)},title:b.status==="enabled"?s("Enabled"):s("Paused")})]}),n.jsx("div",{className:"mt-0.5 text-muted-foreground",children:[t?w(b.botId):"",kh(b.schedule,r),b.doneBy?s("Done by {{name}}",{name:w(b.doneBy)}):"",t?"":T].filter(Boolean).join(" · ")}),b.proposedBy&&C&&n.jsx("div",{className:"mt-0.5 text-warning",children:s("Proposed by {{name}}, waiting for your approval",{name:w(b.proposedBy)})}),b.status==="blocked"&&n.jsx("div",{className:"mt-0.5 text-destructive",children:gi(b.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:b.lastRunAt?s("Last run {{time}} · {{result}}",{time:fx(b.lastRunAt),result:uC(b.lastResult,s)}):s("Never run")}),b.missed?n.jsx("span",{className:"rounded bg-warning/20 px-1.5 text-warning",children:s("Missed {{n}} times",{n:b.missed})}):null,!b.catchUp&&n.jsx("span",{children:s("No catch-up")})]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap justify-end gap-1",children:[C?n.jsxs(n.Fragment,{children:[n.jsx(he,{size:"xs",variant:"ghost",disabled:g.busy,onClick:()=>{g.review(b,!1)},children:s("Reject")}),n.jsx(he,{size:"xs",disabled:g.busy,onClick:()=>{g.review(b,!0)},children:s("Approve")})]}):n.jsxs(he,{size:"xs",variant:"ghost",disabled:!E||g.busy,onClick:()=>{g.run(b,!1)},children:[n.jsx(Xw,{}),s("Run now")]}),n.jsxs(he,{size:"xs",variant:"ghost",disabled:g.busy,title:s("Run once without affecting the schedule"),onClick:()=>{g.run(b,!0)},children:[n.jsx(Pw,{}),s("Dry run")]}),n.jsxs(he,{size:"xs",variant:h===b.id?"secondary":"ghost",onClick:()=>p(h===b.id?null:b.id),children:[n.jsx(Or,{}),s("History")]}),n.jsxs(he,{size:"xs",variant:"ghost",onClick:()=>u(b),children:[n.jsx(bs,{}),s("Edit")]}),n.jsxs(he,{size:"xs",variant:"ghost",onClick:()=>m(b),children:[n.jsx(vs,{}),s("Delete")]})]}),h===b.id&&n.jsx(qW,{routine:b})]},b.id)}),c&&n.jsx(QW,{botId:e,chatId:t,routine:c==="new"?void 0:c,onClose:b=>{u(null),b&&x()}}),n.jsx(hs,{open:d!==null,onOpenChange:b=>!b&&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 j(d)})]})}function qW({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(Bt,{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:GW(l.trigger,t)}),n.jsxs("span",{className:_(l.result==="ok"&&"text-success",(l.result==="error"||l.result==="blocked"||l.result==="budget")&&"text-destructive"),children:[uC(l.result,t),KW(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"?gi(l.error,t):l.error})]},l.runId))})}const YW=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],_b=e=>String(e).padStart(2,"0");function XW({value:e,onChange:t}){const{t:s,locale:r}=z(),o=Lb(e),[i,a]=f.useState(!o),[l,c]=f.useState(o??{kind:"daily",days:[1],hour:9,minute:0}),u=$W(e,r,Date.now()),d=p=>{c(p);const g=PW(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=Lb(e);p?c(p):d(l),a(!1)};return n.jsxs("div",{children:[n.jsx(Lt,{hint:i?s("cron: minute hour day month weekday, local time"):void 0,action:n.jsx(he,{size:"xs",variant:"ghost",onClick:h,children:s(i?"Simple":"Advanced (cron)")}),children:s("Schedule")}),i?n.jsx(Vt,{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(Sr,{items:m,value:l.kind,onValueChange:p=>d({...l,kind:p,days:l.days.length?l.days:[1]}),children:[n.jsx(Cr,{className:"w-32",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:m.map(p=>n.jsx(or,{value:p.value,children:p.label},p.value))})]}),l.kind==="weekly"&&YW.map((p,g)=>{const x=l.days.includes(g);return n.jsx(he,{size:"xs",variant:x?"default":"outline",onClick:()=>{const y=x?l.days.filter(j=>j!==g):[...l.days,g].sort();y.length&&d({...l,days:y})},children:s(p)},p)}),n.jsx(Vt,{type:"time",className:"w-28",value:`${_b(l.hour)}:${_b(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")}`:mC("schedule",s)})]})}function QW({botId:e,chatId:t,routine:s,onClose:r}){const{t:o}=z(),i=ie(J=>J.chats),a=ie(J=>J.bots),l=f.useMemo(()=>(i.find($=>$.id===t)?.members??[]).flatMap($=>{const oe=a.find(Ne=>Ne.id===$&&Ne.archivedAt===void 0);return oe?[oe]:[]}),[i,a,t]),[c,u]=f.useState(s?.botId??e??l[0]?.id??""),d=f.useMemo(()=>VW(i,c),[i,c]),[m,h]=f.useState(s?.title??""),[p,g]=f.useState(s?.prompt??""),[x,y]=f.useState(s?.schedule??zW[0]),[j,w]=f.useState(s?.chatId??t??d[0]?.id??""),[b,N]=f.useState(s?.doneBy??""),[C,E]=f.useState(s?.catchUp??!0),[T,k]=f.useState(null),[L,F]=f.useState(!1),A=J=>{const $=i.find(oe=>oe.id===J);return $?`${is($,a,o)} · ${$.kind==="group"?o("Group chat"):o("Private chat")}`:o("Target chat missing")},D=d.some(J=>J.id===j)||!j?d.map(J=>J.id):[j,...d.map(J=>J.id)],M=f.useMemo(()=>(i.find($=>$.id===j)?.members??[]).flatMap($=>{const oe=a.find(Ne=>Ne.id===$&&Ne.archivedAt===void 0);return oe&&oe.id!==c?[oe]:[]}),[i,a,j,c]),H=[{value:"",label:o("The member itself")},...M.map(J=>({value:J.id,label:J.name}))],G=M.some(J=>J.id===b)?b:"",U=async()=>{if(!c)return k(o("Choose a member."));const J=HW({title:m,prompt:p,schedule:x,chatId:j});if(J)return k(mC(J,o));F(!0),k(null);try{const $=await window.electronAPI.bots.routines.save({botId:c,title:m,prompt:p,schedule:x,chatId:j,catchUp:C,doneBy:G||null,...s?{id:s.id,enabled:s.status!=="paused"}:{}});$.ok?r(!0):k(hd($.error,o))}finally{F(!1)}};return n.jsx(cn,{open:!0,onOpenChange:J=>!J&&r(!1),children:n.jsxs(dn,{className:"max-h-[85vh] max-w-lg",children:[n.jsx(un,{children:n.jsx(on,{children:o(s?"Edit routine":"New routine")})}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Lt,{children:o("Routine title")}),n.jsx(Vt,{value:m,onChange:J=>h(J.target.value)})]}),n.jsxs("div",{children:[n.jsx(Lt,{hint:o("Sent to the member as the task each time it runs"),children:o("Prompt")}),n.jsx(Ks,{rows:4,value:p,onChange:J=>g(J.target.value)})]}),n.jsx(XW,{value:x,onChange:y}),t?n.jsxs("div",{children:[n.jsx(Lt,{children:o("Member")}),n.jsxs(Sr,{items:l.map(J=>({value:J.id,label:J.name})),value:c,disabled:!!s,onValueChange:J=>u(J),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:l.map(J=>n.jsx(or,{value:J.id,children:J.name},J.id))})]})]}):n.jsxs("div",{children:[n.jsx(Lt,{children:o("Target chat")}),D.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(Sr,{items:D.map(J=>({value:J,label:A(J)})),value:j,onValueChange:J=>w(J),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:D.map(J=>n.jsx(or,{value:J,children:A(J)},J))})]})]}),M.length>0&&n.jsxs("div",{children:[n.jsx(Lt,{hint:o("Another member of the target chat runs it, as a delegation"),children:o("Done by")}),n.jsxs(Sr,{items:H,value:G,onValueChange:J=>N(J),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:H.map(J=>n.jsx(or,{value:J.value,children:J.label},J.value||"self"))})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx(Lt,{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(sr,{checked:C,onCheckedChange:E})]}),T&&n.jsx("p",{className:"text-destructive text-sm",children:T})]}),n.jsxs(ts,{children:[n.jsx(he,{variant:"outline",size:"sm",onClick:()=>r(!1),children:o("Cancel")}),n.jsxs(he,{size:"sm",disabled:L,onClick:()=>{U()},children:[L&&n.jsx(Bt,{className:"animate-spin"}),o("Save")]})]})]})})}function ff(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,...yW(e.budget),...wW(e)}}function JW(e){const t=rC(e),s=cx(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 ZW(e,t){const s=Mc(e),r=s?await fetch(s).then(i=>i.blob()).then(tj).catch(()=>null):null,o=oA(aA(r??await lA(e.name,e.avatar.color)),"chara",iA(JSON.stringify(jW(e,t))),["ccv3"]);if(!o)throw new Error("png");cA(new Blob([new Uint8Array(o)],{type:"image/png"}),`${e.name}.png`)}function eU({botId:e,chat:t,onOpenHistory:s}){const{t:r}=z(),o=ie(A=>A.bots.find(D=>D.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),[y,j]=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(ff(A.bot,A.persona)),m(!1))},[e]);f.useEffect(()=>{l(null),u(null),w()},[w]);const b=f.useMemo(()=>o&&a!==null?ff(o,a):null,[o,a]),N=d&&!!(c&&b&&JSON.stringify(c)!==JSON.stringify(b));if(f.useEffect(()=>{!d&&b&&u(b)},[o?.version]),!o||!c)return n.jsx("div",{className:"flex flex-1 items-center justify-center",children:n.jsx(Bt,{className:"h-4 w-4 animate-spin text-muted-foreground"})});const C=A=>{u(D=>D&&{...D,...A}),m(!0)},E=Nh(c.name,i,r,o.id),T=async A=>{x(!0);try{await ej(o.id,A)||Ie({type:"error",title:r("Avatar update failed")})}finally{x(!1)}},k=()=>{ZW(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=JW(c);if(!A){Ie({type:"error",title:cx(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 D=await window.electronAPI.bots.update({botId:o.id,expectedVersion:o.version,draft:A});if(D.ok){ie.getState().upsertBot(D.bot),l(c.persona),u(ff(D.bot,c.persona)),m(!1);return}Ie({type:"error",title:ea(D.reason,D.error,r),...D.reason==="conflict"?{actions:[{label:r("Refresh"),onClick:()=>{w()}}]}:{}})}finally{p(!1)}},F=async()=>{const A=y;if(j(null),A==="archive"){const M=await window.electronAPI.bots.archive(o.id,!0);M.ok?ie.getState().upsertBot(M.bot):Ie({type:"error",title:ea(M.reason,M.error,r)});return}const D=await window.electronAPI.bots.remove(o.id);if(D.ok){ie.getState().setView(null),await Promise.all([ie.getState().refreshCatalog(),ie.getState().refreshChats()]);return}if(D.reason==="boss"){const M=ie.getState().chats,H=(D.chatIds??[]).map(G=>M.find(U=>U.id===G)).filter(G=>!!G).map(G=>is(G,i,r));Ie({type:"warning",title:r("{{name}} owns group chats",{name:o.name}),description:r("Choose another owner in {{groups}} first.",{groups:H.join("、")})});return}Ie({type:"error",title:ea(D.reason,D.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(Ac,{children:[n.jsxs(Ec,{render:n.jsx(he,{size:"xs",variant:"outline",onClick:k}),children:[n.jsx(Nd,{}),r("Export character card")]}),n.jsx(Rc,{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(Qw,{hasImage:!!o.avatar.image,disabled:g,onPick:A=>{T(A)},onRemove:()=>{T(null)}})]})]})]}),n.jsxs(Td,{defaultValue:"profile",className:"mt-3 flex min-h-0 flex-1 flex-col",children:[n.jsxs(Ad,{variant:"underline",className:"shrink-0 px-2",children:[n.jsx(fs,{value:"profile",children:r("Profile")}),n.jsx(fs,{value:"abilities",children:r("Abilities")}),n.jsx(fs,{value:"memory",children:r("Memory")}),n.jsx(fs,{value:"routines",children:r("Routines")}),n.jsx(fs,{value:"history",children:r("History")})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-3",children:[n.jsxs(yr,{value:"profile",className:"space-y-3",children:[n.jsx(RW,{bot:o}),n.jsxs("div",{children:[n.jsx(Lt,{hint:r("Used for @ in groups; must be unique"),children:r("Name")}),n.jsx(Vt,{value:c.name,onChange:A=>C({name:A.target.value})}),E&&n.jsx("p",{className:"mt-1 text-destructive text-xs",children:E})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:r("Title")}),n.jsx(Vt,{value:c.title,onChange:A=>C({title:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Lt,{hint:r("Used for routing and the delegation directory"),children:r("Responsibilities")}),n.jsx(Ks,{rows:2,value:c.scope,onChange:A=>C({scope:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Lt,{action:n.jsx(dC,{value:c,onApply:C}),children:r("Persona")}),n.jsx(Ks,{rows:8,value:c.persona,onChange:A=>C({persona:A.target.value})})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:r("Avatar color")}),n.jsx(Jw,{value:c.color,onChange:A=>C({color:A})})]}),n.jsxs("div",{className:"flex gap-2 border-t pt-3",children:[n.jsxs(he,{size:"xs",variant:"outline",onClick:()=>j("archive"),children:[n.jsx(ar,{}),r("Archive member")]}),n.jsxs(he,{size:"xs",variant:"destructive-outline",onClick:()=>j("delete"),children:[n.jsx(vs,{}),r("Delete permanently")]})]})]}),n.jsxs(yr,{value:"abilities",className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx(Lt,{children:r("Model")}),n.jsx(Zw,{engine:c.engine,onChange:A=>C({engine:A})})]}),n.jsx(iC,{value:c,onChange:C,profile:c,botId:o.id})]}),n.jsxs(yr,{value:"memory",children:[n.jsxs("div",{className:"mb-4",children:[n.jsx(Lt,{hint:r("Injected into every new conversation"),children:r("Core notes")}),n.jsx(cC,{target:{botId:o.id},emptyText:r("No notes yet. Key preferences and facts are summarized here automatically after memories are organized.")})]}),n.jsx(lC,{spaceId:`bot:${o.id}`,emptyText:r("No memories yet")})]}),n.jsx(yr,{value:"routines",children:n.jsx(hC,{botId:o.id})}),n.jsx(yr,{value:"history",children:n.jsx(tU,{chat:t,botId:o.id,onOpen:A=>s(A,o.name)})})]})]}),N&&n.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t bg-muted/50 px-4 py-2.5",children:[n.jsx(he,{size:"sm",variant:"outline",onClick:()=>{b&&u(b),m(!1)},children:r("Discard")}),n.jsxs(he,{size:"sm",disabled:h||!!E,onClick:()=>{L()},children:[h&&n.jsx(Bt,{className:"animate-spin"}),r("Save")]})]}),n.jsx(hs,{open:y!==null,onOpenChange:A=>!A&&j(null),title:y==="delete"?r("Delete {{name}}?",{name:o.name}):r("Archive {{name}}?",{name:o.name}),description:r(y==="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(y==="delete"?"Delete permanently":"Archive member"),onConfirm:()=>{F()}})]})}function tU({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(Bt,{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 pd(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 pC(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:pd(o.error,r)}),o.ok}function mx({placeholder:e,onSend:t,className:s}){const{t:r}=z(),[o,i]=f.useState(""),[a,l]=f.useState(!1),c=Mr(xe(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(Ks,{value:o,rows:1,size:"sm",maxLength:Sh,placeholder:e,"aria-label":e,title:c?`${r("Send")} ${Gs(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&&Ww(d,c)&&(d.preventDefault(),u())}}),n.jsx(he,{size:"icon-sm",variant:o.trim()?"default":"ghost","aria-label":r("Send reply"),disabled:!o.trim()||a,onClick:()=>{u()},children:a?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Ud,{})})]})}function xC(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 gC=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),vC=(e,t)=>e.ok===void 0?t("Processing"):e.ok?t("Delivered"):t("Not delivered");function nU({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:gC(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:vC(s,t)})]},s.deliveryId))})}function sU({runs:e,bots:t,onOpenConversation:s}){const{t:r}=z(),o=ie(p=>p.delegations),i=ru(e.some(p=>Na(p.state))),[a,l]=f.useState(!1),[c,u]=f.useState(null),d=BW(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 y=p.state==="failed"?vl(g??p,r):void 0,j=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"):xC(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:Pr(x.ms)})}):n.jsxs(n.Fragment,{children:[n.jsx(su,{state:p.state,interrupted:p.failure==="interrupted"}),n.jsx("span",{children:Pr(x.ms)})]}),p.appends&&n.jsx("button",{type:"button","aria-expanded":c===p.id,disabled:!j.length,title:j.map(w=>`${gC(w.at)} ${w.text} · ${vC(w,r)}`).join(`
67
- `),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(he,{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&&j.length>0&&n.jsx(nU,{appends:j}),y&&n.jsx("div",{className:"mt-0.5 line-clamp-2 whitespace-pre-wrap text-destructive",children:y})]},p.id)})}),d.length>m.length&&n.jsx(he,{size:"xs",variant:"ghost",onClick:()=>l(!0),children:r("Show all ({{n}})",{n:d.length})})]})}const Hm=5,rU=e=>new Date(e).toLocaleString([],{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});function br({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(he,{size:"xs",variant:"ghost",className:"mt-1",onClick:()=>a(!0),children:o("Show all ({{n}})",{n:t})})]})}function oU({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),y=ru(!!r?.some(k=>k.status==="blocked")),j=f.useMemo(()=>new Map(o.map(k=>[k.id,k])),[o]),w=e.members.flatMap(k=>{const L=j.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 b=async(k,L)=>{const F=await k();F.ok||Ie({type:"error",title:L,description:pd(F.error??"",s)}),ie.getState().refreshTasks(e.id)},N=window.electronAPI.bots.tasks,C=k=>({chatId:e.id,id:k.id});if(!r)return n.jsx(Bt,{className:"h-4 w-4 animate-spin text-muted-foreground"});const E=DW(r),T=k=>n.jsx(iU,{task:k,bots:j,members:w,onOpenConversation:t,block:FW(k,i),now:y,highlighted:p===k.id,onEdit:()=>l(k),onAssign:L=>{b(()=>N.assign({...C(k),botId:L}),s("Task not assigned"))},onComplete:()=>{b(()=>N.complete(C(k)),s("Task not updated"))},onAccept:()=>{b(()=>N.review({...C(k),accept:!0}),s("Task not updated"))},onReturn:L=>m({task:k,rework:L}),onCancel:()=>{b(()=>N.cancel(C(k)),s("Task not updated"))},onDelete:()=>u(k),onReply:L=>pC(e.id,k.id,L,s)},k.id);return n.jsxs("div",{ref:x,children:[n.jsxs(he,{size:"xs",variant:"outline",className:"mb-3",onClick:()=>l("new"),children:[n.jsx(Xn,{}),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.")}),E.todo.length>0&&n.jsx(br,{title:s("To do"),count:E.todo.length,children:()=>E.todo.map(T)}),E.doing.length>0&&n.jsx(br,{title:s("Doing"),count:E.doing.length,children:()=>E.doing.map(T)}),E.blocked.length>0&&n.jsx(br,{title:s("Stuck tasks"),count:E.blocked.length,children:()=>E.blocked.map(T)}),E.review.length>0&&n.jsx(br,{title:s("Awaiting review"),count:E.review.length,children:()=>E.review.map(T)}),E.done.length>0&&n.jsx(br,{title:s("Completed"),count:E.done.length,limit:Hm,children:k=>E.done.slice(0,k).map(T)}),E.canceled.length>0&&n.jsx(br,{title:s("Canceled"),count:E.canceled.length,limit:0,children:k=>E.canceled.slice(0,k).map(T)}),a&&n.jsx(cU,{chatId:e.id,task:a==="new"?void 0:a,onClose:k=>{l(null),k&&ie.getState().refreshTasks(e.id)}}),d&&n.jsx(lU,{task:d.task,assignee:j.get(d.task.assigneeBotId??"")?.name??s("Deleted member"),rework:d.rework,onClose:()=>m(null),onReturn:k=>N.review({...C(d.task),accept:!1,reason:k,...d.rework?{rework:!0}:{}}).then(L=>(L.ok&&(m(null),ie.getState().refreshTasks(e.id)),L.ok?null:pd(L.error,s)))}),n.jsx(hs,{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&&b(()=>N.remove(C(k)),s("Task not deleted"))}})]})}function iU({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(),y=e.status==="todo"||e.status==="doing"||e.status==="blocked",j=e.status==="review",w=Yw(e),b=e.assigneeBotId?t.get(e.assigneeBotId):void 0,N=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",!y&&!j&&"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(ur,{children:[n.jsx(fr,{className:"rounded p-1 text-muted-foreground opacity-0 hover:bg-muted group-hover:opacity-100 data-popup-open:opacity-100",children:n.jsx(ll,{className:"h-3.5 w-3.5"})}),n.jsxs(mr,{align:"end",children:[n.jsxs(Cn,{onClick:o,children:[n.jsx(bs,{}),x("Edit")]}),y&&(!e.delegationId||e.status==="blocked"||w)&&s.length>0&&n.jsxs(sj,{children:[n.jsxs(rj,{children:[n.jsx(Da,{}),e.assigneeBotId?x("Reassign to"):x("Assign to")]}),n.jsx(oj,{children:s.map(C=>n.jsxs(Cn,{disabled:C.id===e.assigneeBotId,onClick:()=>i(C.id),children:[n.jsx($t,{bot:C,size:"xs"}),C.name]},C.id))})]}),y&&!w&&n.jsxs(Cn,{onClick:a,children:[n.jsx(Dn,{}),x("Mark done")]}),(y||j)&&n.jsxs(Cn,{onClick:u,children:[n.jsx(Zt,{}),x("Cancel task")]}),n.jsx(yi,{}),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(aU,{block:h,now:p,assignee:b,bots:t,members:s,assigneeBotId:e.assigneeBotId,onRetry:()=>w&&ya(w.id,x),onAssign:i,onCancel:u,onReply:m}),!h&&(j||e.status==="doing"&&e.delegationId)&&n.jsx(mx,{placeholder:x(j?"Comment…":"Add to the current run…"),onSend:m}),e.check&&n.jsx(ZS,{check:e.check,className:"mt-1"}),j&&n.jsxs("div",{className:"mt-1.5 flex gap-1.5",children:[n.jsxs(he,{size:"xs",onClick:l,children:[n.jsx(Dn,{}),x("Accept result")]}),n.jsxs(he,{size:"xs",variant:"outline",onClick:()=>c(!1),children:[n.jsx(Pa,{}),x("Return")]}),OW(e)&&n.jsxs(he,{size:"xs",variant:"outline",onClick:()=>c(!0),children:[n.jsx(Ch,{}),x("Return for rework")]})]}),n.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-muted-foreground",children:[b||e.assigneeBotId?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx($t,{bot:b,size:"xs"}),b?.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:N}),children:rU(e.updatedAt)})]}),e.runs&&e.runs.length>0&&n.jsx(sU,{runs:e.runs,bots:t,onOpenConversation:r})]})}function aU({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:Pr(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(mx,{placeholder:d("Answer {{name}}; they continue after your reply…",{name:m}),onSend:u})]})}const p=e.record?.state==="failed"&&vl(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(he,{size:"xs",variant:"outline",onClick:a,children:[n.jsx(Eo,{}),d("Retry")]}),i.length>0&&n.jsxs(ur,{children:[n.jsxs(fr,{render:n.jsx(he,{size:"xs",variant:"outline"}),children:[n.jsx(Da,{}),d("Reassign")]}),n.jsx(mr,{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(he,{size:"xs",variant:"outline",onClick:c,children:[n.jsx(Zt,{}),d("Cancel task")]})]})]})}function lU({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(on,{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(Lt,{children:i("Reason for returning")}),n.jsx(Ks,{rows:4,autoFocus:!0,value:a,maxLength:Sh,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(he,{variant:"outline",size:"sm",onClick:r,children:i("Cancel")}),n.jsxs(he,{size:"sm",disabled:d,onClick:()=>{h()},children:[d&&n.jsx(Bt,{className:"animate-spin"}),i(s?"Return for rework":"Return")]})]})]})})}function cU({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(pd(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(on,{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(Lt,{children:r("Task title")}),n.jsx(Vt,{value:o,maxLength:dA,onChange:x=>i(x.target.value)})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:r("Details")}),n.jsx(Ks,{rows:4,value:a,maxLength:Sh,onChange:x=>l(x.target.value)})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:r("Acceptance check (optional)")}),n.jsx(Vt,{value:c,maxLength:uA,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(he,{variant:"outline",size:"sm",onClick:()=>s(!1),children:r("Cancel")}),n.jsxs(he,{size:"sm",disabled:h,onClick:()=>{g()},children:[h&&n.jsx(Bt,{className:"animate-spin"}),r("Save")]})]})]})})}function dU({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(()=>_W(r,e.id),[r,e.id]),l=c=>n.jsx(ou,{record:c,retried:nj(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(br,{title:s("In progress"),count:a.active.length,children:()=>a.active.map(l)}),a.completed.length>0&&n.jsx(br,{title:s("Completed"),count:a.completed.length,limit:Hm,children:c=>a.completed.slice(0,c).map(l)}),a.failed.length>0&&n.jsx(br,{title:s("Failed · interrupted · canceled"),count:a.failed.length,limit:Hm,children:c=>a.failed.slice(0,c).map(l)})]})}const uU=(e,t)=>e.workspace.kind===t.kind&&(t.kind!=="project"||e.workspace.kind==="project"&&e.workspace.projectId===t.projectId);function bC({chat:e,className:t}){const{t:s}=z(),r=xe(p=>p.projects),o=ie(p=>p.bots),i=ie(p=>p.upsertChat),[a,l]=f.useState(!1),[c,u]=f.useState(null),d=ij(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")},...Ed(r).map(p=>({input:{kind:"project",projectId:p.id},label:Un(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:cs(g.error,s)})};return n.jsxs(n.Fragment,{children:[n.jsxs(Rs,{open:a,onOpenChange:l,children:[n.jsxs(Ms,{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(Wd,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"truncate",children:d}),n.jsx(Bn,{className:"h-3 w-3 shrink-0 opacity-60"})]}),n.jsxs(Ps,{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:cs(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=uU(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(Dn,{className:"h-3.5 w-3.5 shrink-0 text-brand"})]},p.input.kind==="project"?p.input.projectId:p.input.kind)})})]})]}),n.jsx(hs,{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 xo({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 mf({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 yC(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 pA(e,t,s,new Date().toISOString())}async function fU(e,t){const s=await yC(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 mU(e,t){const s=await yC(e,t),r=s&&fA(mA(s.team));return r?hA(o=>({...o,teams:xA(o.teams,r,crypto.randomUUID())})):!1}function hU({chat:e,thread:t=e,onOpenConversation:s}){const{t:r}=z(),o=ie(M=>M.bots),i=ie(M=>M.runtime[t.id]),a=ie(M=>M.upsertChat),l=ie(M=>M.openDirect),c=xe(M=>M.projects),u=f.useMemo(()=>new Map(o.map(M=>[M.id,M])),[o]),[d,m]=f.useState(e.title),[h,p]=f.useState(String(e.routing.maxHops)),[g,x]=f.useState(String(e.routing.maxTurnsPerBot)),[y,j]=f.useState(!1),[w,b]=f.useState("info"),N=ie(M=>M.taskFocus);f.useEffect(()=>{N?.chatId===e.id&&b("board")},[N,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 C=async M=>{const H=await window.electronAPI.bots.updateChat({chatId:e.id,expectedVersion:e.version,...M});H.ok?a(H.chat):(Ie({type:"error",title:cs(H.error,r)}),ie.getState().refreshChats())},E=e.members.map(M=>({id:M,bot:u.get(M)})),T=e.routing.muted??[],k=o.filter(M=>!M.archivedAt&&!e.members.includes(M.id)),L=M=>M?u.get(M)?.name??"?":"—",F=e.workspace.kind==="project"?c.find(M=>e.workspace.kind==="project"&&M.id===e.workspace.projectId):void 0,A=h!==String(e.routing.maxHops)||g!==String(e.routing.maxTurnsPerBot),D=[{value:"boss",label:r("Group owner replies")},{value:"smart",label:r("Smart pick")}];return n.jsxs(Td,{value:w,onValueChange:M=>b(String(M)),className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs(Ad,{variant:"underline",className:"shrink-0 px-2 pt-2",children:[n.jsx(fs,{value:"info",children:r("Group info")}),n.jsx(fs,{value:"board",children:r("Task board")}),n.jsx(fs,{value:"delegations",children:r("Delegations")}),n.jsx(fs,{value:"routines",children:r("Routines")})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:[n.jsx(yr,{value:"board",children:n.jsx(oU,{chat:e,onOpenConversation:s})}),n.jsx(yr,{value:"delegations",children:n.jsx(dU,{chat:t,onOpenConversation:s})}),n.jsx(yr,{value:"routines",children:n.jsx(hC,{chatId:e.id})}),n.jsxs(yr,{value:"info",children:[n.jsx(Vt,{className:"mt-2",value:d,placeholder:r("Group name"),onChange:M=>m(M.target.value),onBlur:()=>d.trim()!==e.title&&void C({title:d.trim()}),onKeyDown:M=>M.key==="Enter"&&M.currentTarget.blur()}),n.jsxs(xo,{title:r("Members"),children:[E.map(({id:M,bot:H})=>n.jsxs("div",{className:"group flex items-center gap-2 rounded-lg py-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{l(M)},className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx(sC,{chatId:t.id,botId:M,bot:H}),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:H?.name??r("Deleted member")}),e.bossBotId===M&&n.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:r("Owner")}),T.includes(M)&&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(ed,{className:"h-2.5 w-2.5"}),r("Muted")]})]}),n.jsx("div",{className:"truncate text-muted-foreground text-xs",children:H?.scope||H?.title})]})]}),n.jsxs(ur,{children:[n.jsx(fr,{className:"rounded p-1 text-muted-foreground opacity-0 hover:bg-muted group-hover:opacity-100 data-popup-open:opacity-100",children:n.jsx(ll,{className:"h-3.5 w-3.5"})}),n.jsxs(mr,{align:"end",children:[n.jsxs(Cn,{disabled:e.bossBotId===M,onClick:()=>{C({bossBotId:M})},children:[n.jsx(aj,{}),r("Make owner")]}),n.jsxs(Cn,{disabled:e.bossBotId===M,onClick:()=>{C({routing:{muted:T.includes(M)?T.filter(G=>G!==M):[...T,M]}})},children:[n.jsx(ed,{}),T.includes(M)?r("Unmute"):r("Mute")]}),n.jsxs(Cn,{disabled:e.bossBotId===M||e.members.length<=2,onClick:()=>{C({members:e.members.filter(G=>G!==M)})},children:[n.jsx(fB,{}),r("Remove from group")]})]})]})]},M)),n.jsxs(Rs,{open:y,onOpenChange:j,children:[n.jsxs(Ms,{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(Xn,{className:"h-3.5 w-3.5"}),r("Add member")]}),n.jsx(Ps,{side:"bottom",align:"start",className:"w-56 [&_[data-slot=popover-viewport]]:p-1",children:k.map(M=>n.jsxs("button",{type:"button",onClick:()=>{j(!1),C({members:[...e.members,M.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:M,size:"sm"}),n.jsx("span",{className:"min-w-0 truncate",children:M.name})]},M.id))})]})]}),n.jsxs(xo,{title:r("Reply queue"),children:[n.jsx(mf,{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(mf,{label:r("Waiting"),value:i?.queue.length?i.queue.map(M=>L(M)).join("、"):"—"}),n.jsx(mf,{label:r("Per-member limit"),value:r("{{n}} replies",{n:e.routing.maxTurnsPerBot})})]}),n.jsx(xo,{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(bC,{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(xo,{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(Sr,{items:D,value:e.routing.mode,onValueChange:M=>{M!==e.routing.mode&&C({routing:{mode:M}})},children:[n.jsx(Cr,{size:"sm",className:"w-40",children:n.jsx(Ir,{})}),n.jsx(Tr,{children:D.map(M=>n.jsx(or,{value:M.value,children:M.label},M.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(Vt,{type:"number",min:1,max:20,value:h,onChange:M=>p(M.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(Vt,{type:"number",min:1,max:10,value:g,onChange:M=>x(M.target.value)})]})]}),A&&n.jsx(he,{size:"xs",className:"mt-2",onClick:()=>{C({routing:{maxHops:Math.round(Number(h))||e.routing.maxHops,maxTurnsPerBot:Math.round(Number(g))||e.routing.maxTurnsPerBot}})},children:r("Save")})]}),n.jsx(xo,{title:r("Group notes"),children:n.jsx(cC,{target:{chatId:e.id},emptyText:r("No group notes yet. Group conventions and decisions are summarized here automatically after memories are organized.")})}),n.jsx(xo,{title:r("Group memory"),children:n.jsx(lC,{spaceId:`chat:${e.id}`,emptyText:r("No group memories yet")})}),n.jsxs(xo,{title:r("Team"),children:[n.jsxs(he,{size:"xs",variant:"outline",onClick:()=>{fU(e,o).then(M=>M||Ie({type:"error",title:r("Export failed")}))},children:[n.jsx(Nd,{}),r("Export team")]}),n.jsxs(he,{size:"xs",variant:"outline",className:"ml-1.5",onClick:()=>{mU(e,o).then(M=>Ie(M?{type:"success",title:r("Saved as team template")}:{type:"error",title:r("Could not save as team template")}))},children:[n.jsx(b4,{}),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 pU(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 xU(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 gU(e,t){const s=String(t),r=`${s}-`;return e.find(o=>o.key===s||o.key.startsWith(r))?.key}function vU(e){return e.earliest===void 0?"wait":e.target>=e.earliest?"scroll":e.loading?"wait":e.hasOlder?"load":"give-up"}function bU(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 yU(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 wU({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(he,{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 jU=(e,t)=>t?e.find(s=>s.conversationId===t):void 0,kU=(e,t)=>Math.max(0,Math.floor((t-e)/1e3));function wC({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:kU(e,s)})})}function jC({conversationId:e,className:t}){const s=ie(r=>jU(r.silences,e)?.since);return s===void 0?null:n.jsx("span",{className:t??"shrink-0 text-warning",children:n.jsx(wC,{since:s})})}const bc=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),NU={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 SU({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),y=f.useRef(m);y.current=m;const j=f.useCallback((de,Ee)=>y.current(de,Ee),[]),w=f.useRef(null),b=f.useRef(!1),N=s?.entries??[],C=f.useRef({chatId:e.id,loaded:N,delegations:o});C.current={chatId:e.id,loaded:N,delegations:o};const E=f.useCallback(de=>{const{chatId:Ee,loaded:me,delegations:Ve}=C.current,at=bA(me,de);if(at!==void 0)return ie.getState().focusSeq(Ee,at);const Fe=Ve.find(tt=>tt.id===de);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]),T=pU(N,e.epochSeq??0),k=s?.history,L=e.epochSeq??0,[F,A]=f.useState(!1);f.useEffect(()=>A(!1),[e.id,L]);const D=L>0&&!F&&!k,M=f.useMemo(()=>D?N.filter(de=>de.seq>=L):N,[N,D,L]),H=f.useMemo(()=>yA(M),[M]),G=()=>{D&&s?.hasOlder&&!s.loading&&!N.some(de=>de.seq<L)&&(we(),l()),A(D)},U=f.useMemo(()=>{const de=new Map;if(!k)for(const Ee of H)Ee.kind==="entry"&&Ee.entry.kind==="bot"&&!Ee.continued&&de.set(Ee.entry.botId,Ee.entry.id);return new Set(de.values())},[H,k]),J=f.useMemo(()=>new Map(o.map(de=>[de.id,{record:de,retried:nj(de,o)}])),[o]),$=f.useMemo(()=>cj(o,e.id),[o,e.id]),oe=f.useMemo(()=>wA(M,jA($)),[M,$]),Ne=ie(de=>de.tasks[e.id]),ce=$.some(de=>de.appends?.length);f.useEffect(()=>{ce&&!Ne&&ie.getState().refreshTasks(e.id)},[ce,Ne,e.id]);const ne=({key:de,record:Ee,append:me})=>n.jsx(ou,{record:Ee,append:me,taskSeq:me&&Ne?.find(Ve=>Ve.id===Ee.taskId)?.seq,fill:!0,bots:t,onOpenConversation:m},de),Y=r?.current?t.get(r.current):void 0,pe=r?.current?e.sessions[r.current]?.conversationId:void 0,ge=ie(de=>pe?de.sessions[pe]?.messages.length:void 0);f.useLayoutEffect(()=>{const de=g.current;de&&(de.scrollTop=de.scrollHeight),x.current=!0},[e.id]);const we=()=>{const de=g.current;if(!de)return;const Ee=de.getBoundingClientRect().top;for(const me of de.querySelectorAll("[data-seq]")){const Ve=me.getBoundingClientRect();if(!(Ve.bottom<=Ee)){w.current={seq:Number(me.dataset.seq),top:Ve.top-Ee};return}}};f.useLayoutEffect(()=>{const de=g.current;if(!de)return;const Ee=w.current;!s?.loading&&!s?.loadingNewer&&(w.current=null);const Ve=b.current&&!k;b.current=!!k;const at=Ee&&de.querySelector(`[data-seq="${Ee.seq}"]`);if(Ee&&at){de.scrollTop+=at.getBoundingClientRect().top-de.getBoundingClientRect().top-Ee.top;return}Ve&&(x.current=!0),x.current&&!k&&(de.scrollTop=de.scrollHeight)},[M,k,s?.loading,s?.loadingNewer,$.length,Y?.id,ge,r?.routing]);const V=()=>{const de=g.current;if(!de||!s)return;const Ee=de.scrollHeight-de.scrollTop-de.clientHeight;x.current=Ee<40,w.current&&we(),!(M.length===0||D&&(N[0]?.seq??0)<=L)&&(de.scrollTop<80&&s.hasOlder&&!s.loading&&(we(),l()),Ee<80&&k&&!s.loadingNewer&&(we(),c()))},[W,B]=f.useState(null),te=f.useRef(null),[Z,ue]=f.useState(null);f.useLayoutEffect(()=>{if(!i||te.current===i.nonce)return;if(D&&i.seq<L){A(!0);return}const de=M[0]?.seq,Ee=M.at(-1)?.seq,me=Z?.nonce===i.nonce?Z:null,Ve=bU({target:i.seq,range:s?de===void 0||Ee===void 0?null:[de,Ee]:void 0,loading:!!(me&&!me.done),jumped:!!me?.done});if(Ve!=="wait"){if(Ve==="jump"){const at=i.nonce;x.current=!1,w.current=null,ue({nonce:at,done:!1}),u(i.seq).finally(()=>ue(Fe=>Fe?.nonce===at?{nonce:at,done:!0}:Fe));return}te.current=i.nonce,a?.(i.nonce),Ve==="scroll"&&(x.current=!1,w.current=null,B(i.seq),g.current?.querySelector(`[data-seq="${i.seq}"]`)?.scrollIntoView({block:"center"}))}},[i,M,s===void 0,Z,D]),f.useEffect(()=>{if(W===null)return;const de=window.setTimeout(()=>B(null),2500);return()=>window.clearTimeout(de)},[W]);const fe=()=>{x.current=!0,w.current=null,d()},Ce=k&&s?s.lastSeq-k.sinceSeq:0;return n.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[n.jsx("div",{ref:g,onScroll:V,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(Bt,{className:"h-4 w-4 animate-spin"})}),s&&!s.hasOlder&&!D&&M.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(Bt,{className:"h-4 w-4 animate-spin"})}),s&&M.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.")}),oe.head.map(ne),H.map(de=>de.kind==="day"?n.jsx("div",{className:"py-1 text-center text-[11px] text-muted-foreground",children:new Date(de.at).toLocaleDateString()},de.key):n.jsxs(f.Fragment,{children:[L>0&&!k&&de.entry.seq===L&&n.jsxs("button",{type:"button",onClick:G,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:[D?n.jsx(fn,{className:"h-3.5 w-3.5"}):n.jsx(Bn,{className:"h-3.5 w-3.5"}),D?p("Earlier conversation · {{n}} messages",{n:L-1}):p("Collapse earlier conversation")]}),n.jsx("div",{"data-seq":de.entry.seq,className:_("-mx-2 flex flex-col rounded-lg px-2 transition-colors duration-500",W===de.entry.seq&&"bg-brand/10"),children:n.jsx(CU,{chatId:e.id,entry:de.entry,continued:de.continued,latest:U.has(de.entry.id),retryable:T.has(de.entry.id)&&e.archivedAt===void 0,retryBusy:!!(r?.current||r?.routing),bots:t,records:J,onOpenConversation:j,onLocateDelegation:E})}),oe.after.get(de.entry.id)?.map(ne)]},de.key)),s?.loadingNewer&&n.jsx("div",{className:"flex justify-center py-1 text-muted-foreground",children:n.jsx(Bt,{className:"h-4 w-4 animate-spin"})}),!k&&!Y&&r?.routing&&n.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[n.jsx(Bb,{}),p("Choosing who replies…")]}),!k&&n.jsx(wU,{chatId:e.id,bots:t}),!k&&Y&&n.jsxs("button",{type:"button",disabled:!pe,title:p("View live"),onClick:()=>pe&&h(pe,Y.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:Y,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:Y.name}),p("Replying")]}),n.jsx(JS,{conversationId:pe,leading:n.jsx(Bb,{}),trailing:n.jsxs(n.Fragment,{children:[n.jsx(jC,{conversationId:pe}),pe&&n.jsx("span",{className:"shrink-0 underline-offset-2 hover:underline",children:p("View live")})]})})]})]})]})})}),k&&n.jsxs("button",{type:"button",onClick:fe,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(gh,{className:"h-3 w-3"}),Ce>0?p("Back to latest · {{n}} new",{n:Ce}):p("Back to latest")]})]})}function Bb(){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 CU=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:cs(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")," · ",bc(s.at),n.jsx("div",{className:"h-px flex-1 bg-border"})]}):s.routine?n.jsx(UW,{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(he,{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:_(vc,"whitespace-pre-wrap break-words"),children:n.jsx(yc,{text:s.text,bots:i})}),s.images?.length?n.jsx(fd,{target:{chatId:t,entryId:s.id}}):null,(s.refs?.skill||s.refs?.chats?.length)&&n.jsx(EU,{refs:s.refs}),!r&&n.jsx("span",{className:"mt-0.5 text-[11px] text-muted-foreground",children:bc(s.at)})]});case"progress":return n.jsx(TU,{chatId:t,entry:s,bots:i,failed:a.get(s.delegationId)?.record.state==="failed"});case"delegation":return n.jsx(ou,{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(sC,{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} · `:"",bc(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(NU[s.routedBy])})]}),n.jsx("div",{className:"text-sm",children:n.jsx(Gn,{text:s.text})}),n.jsx(fd,{target:{chatId:t,entryId:s.id}}),n.jsx(AU,{entry:s,onOpen:()=>l(s.conversationId,x?.name??"")})]})]})}}}),IU={started:{icon:N4,className:"border-brand/50 text-brand"},blocked:{icon:Zr,className:"border-warning/60 text-warning"},failed:{icon:Mw,className:"border-destructive/60 text-destructive"},delivered:{icon:hh,className:"border-success/60 text-success"}};function TU({chatId:e,entry:t,bots:s,failed:r}){const{t:o}=z(),i=ie(d=>d.openTask),a=s.get(t.botId),l=IU[t.phase==="blocked"&&r?"failed":t.phase],c=l.icon,u=xU(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(yc,{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(yc,{text:u[2],bots:s})]}):n.jsx(yc,{text:t.text,bots:s})]}),n.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:bc(t.at)})]})]})}function yc({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 dw(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:_(eu("file"),"mx-0.5 leading-4"),title:r.path,children:[n.jsx(Fo,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"truncate",children:lj})]},o):n.jsx("span",{className:"font-medium underline underline-offset-2",children:r.part},o))})}function AU({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=gA(m,e.text);if(c){if(!h)return a({error:s("No process recorded.")});a({steps:vA(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?Bn: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(Bt,{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 EU({refs:e}){const{t}=z(),s=ie(a=>a.chats),r=ie(a=>a.bots),o=xe(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 kC=f.createContext(null);function NC({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(ro,{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(Zt,{className:"h-3.5 w-3.5"})})]})}function Fb(e,t){return t.projectId?t.projectId:e.workspace.kind==="member-home"?void 0:e.workspace.projectId}function RU(e,t,s){for(const r of e??[])for(const o of Object.values(r.sessions))if(o.conversationId===s)return Fb(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 Fb(o,i)}}function SC(e,t){const s=ie(o=>e?RU(o.chats,o.delegations,e):void 0),r=t??s;return!e||!r?null:{conversationId:e,projectId:r}}function CC(e){const{t}=z(),s=ie(i=>i.delegations),r=e?kA(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:xC(i.trigger,t)})})),[o,t])}const MU=2500;function IC({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=vU({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"?gU(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),MU);return()=>window.clearTimeout(m)},[c]),{searchQuery:c?.query??"",activeHit:c?{key:c.key,nth:0}:null}}function TC({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?Ih(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 y=f.useMemo(()=>()=>{ie.getState().loadOlderSession(e)},[e]),j=IC({focus:i,timelineRef:p,items:x,baseIndex:m?.historyBaseIndex??0,hasMessages:(m?.messages.length??0)>0,loading:h,loadOlder:y,onDone:a}),{name:w,color:b,image:N}=t,C=f.useMemo(()=>({sessionId:e,canRewind:!!c,canRetry:!!c,canFork:!1,speaker:{name:w,color:b,image:N},turnFooter:l,...c?{botControls:c}:{}}),[e,w,b,N,l,c]),E=(m?.historyBaseIndex??0)>0,T=SC(e);return n.jsx(kC.Provider,{value:T,children:n.jsx(Jd.Provider,{value:C,children:n.jsxs("div",{"data-slot":d,className:_("@container flex min-h-0 flex-1 flex-col",o),children:[n.jsx(lx,{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:E,olderCursor:m?.historyBaseIndex,onStartReached:E?()=>{ie.getState().loadOlderSession(e)}:void 0,searchQuery:j.searchQuery,activeHit:j.activeHit},e),m?.retry&&n.jsx("div",{className:_r,children:n.jsx(NC,{retry:m.retry})})]})})})}function AC({conversationId:e,title:t,speaker:s,emptyTitle:r,emptyDescription:o,meta:i,actions:a,children:l,footer:c,dataEnso:u,onClose:d}){const m=CC(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(on,{className:"min-w-0 flex-1",children:t}),a]}):n.jsx(on,{children:t}),i]}),l??(e&&s&&n.jsx(TC,{className:"border-t",conversationId:e,speaker:s,emptyTitle:r??t,emptyDescription:o,runDividers:m})),c&&n.jsx("div",{className:_r,children:c})]})})}function hx({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(),[y,j]=f.useState(!1),w=f.useRef(!1),b=f.useRef(null),N=f.useCallback(G=>i?i(G):window.electronAPI.bots.sessionHistory({conversationId:e??"",...G!==void 0?{beforeIndex:G}:{}}),[e,i]);f.useEffect(()=>{if(m(null),x(void 0),p(void 0),!e)return;let G=!0;return N().then(U=>{G&&(U.ok?(m({messages:U.messages,baseIndex:U.baseIndex}),p(U.projectId)):x(U.code==="not-found"?u("This conversation has no history yet."):U.error))}),()=>{G=!1}},[e,N,u]);const C=f.useCallback(async()=>{if(!(!e||!d||d.baseIndex<=0||w.current)){w.current=!0,j(!0);try{const G=await N(d.baseIndex);G.ok&&G.baseIndex+G.messages.length===d.baseIndex&&m({messages:[...G.messages,...d.messages],baseIndex:G.baseIndex})}finally{w.current=!1,j(!1)}}},[e,N,d]),E=CC(e),T=f.useMemo(()=>d?Ih(d.messages,l,[],void 0,{historyBaseIndex:d.baseIndex,runDividers:E}):[],[d,l,E]),k=f.useCallback(()=>{C()},[C]),L=IC({focus:r,timelineRef:b,items:T,baseIndex:d?.baseIndex??0,hasMessages:!!d?.messages.length,loading:y||d===null,loadOlder:k}),F=s?.name,A=s?.color,D=s?.image,M=f.useMemo(()=>({sessionId:e,canRewind:!1,canRetry:!1,botSession:a,speaker:F&&A?{name:F,color:A,image:D}:void 0,turnFooter:o}),[a,e,F,A,D,o]),H=SC(a?e:null,h);return n.jsx(kC.Provider,{value:H,children:n.jsx(cn,{open:e!==null,onOpenChange:G=>!G&&c(),children:n.jsxs(dn,{className:"flex h-[80vh] max-w-3xl flex-col",children:[n.jsx(un,{children:n.jsx(on,{children:t})}),n.jsx(Jd.Provider,{value:M,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(lx,{ref:b,items:T,busy:d===null,loading:d===null,running:!1,emptyTitle:t,hasOlder:!!(d&&d.baseIndex>0),historyLoading:y,olderCursor:d?.baseIndex,onStartReached:d&&d.baseIndex>0?()=>{C()}:void 0,searchQuery:L.searchQuery,activeHit:L.activeHit})})})]})})})}const Wm="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 PU({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,y=f.useMemo(()=>Object.fromEntries(c.map(k=>[k.id,k.name])),[c]),j=k=>k.threadTitle??(k.parentId?s("New topic"):s("Main topic")),w=a8(r,e).map(k=>{const L=Th(k,{sessions:o,timeline:i[k.id],queue:a,names:y});return{id:k.id,title:j(k),preview:L.preview,activityAt:Math.max(L.activityAt,k.createdAt),unread:k.id!==t.id&&Qi(L.marker,l[L.key]),running:L.running,canRename:!x,canDelete:!!k.parentId}}),b=bN(w,{currentId:t.id,rootId:e.id}),N=w.length-b.length,C=k=>ie.getState().openThread(e.id,k),E=async()=>{await ie.getState().createThread(e.id)||Ie({type:"error",title:s("Could not create topic")})},T=async k=>{const L=await window.electronAPI.bots.deleteThread(k);L.ok||Ie({type:"error",title:cs(L.error,s)}),ie.getState().refreshChats()};return n.jsxs(n.Fragment,{children:[n.jsxs(ur,{children:[n.jsxs(fr,{className:_(Wm,"max-w-56 @max-[28rem]:max-w-32 @max-[21rem]:max-w-24"),children:[n.jsx("span",{className:"truncate",children:j(t)}),w.some(k=>k.unread)&&n.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-info"}),n.jsx(Bn,{className:"h-3.5 w-3.5 shrink-0"})]}),n.jsxs(mr,{align:"end",className:"w-72",children:[n.jsxs(Ah,{children:[n.jsx(Eh,{children:s("Topics")}),b.map(k=>n.jsxs(Cn,{onClick:()=>C(k.id),children:[n.jsx(Dn,{className:_(k.id!==t.id&&"invisible")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k.title}),n.jsx(px,{entry:k})]},k.id))]}),n.jsx(yi,{}),N>0&&n.jsxs(Cn,{onClick:()=>d(!0),children:[n.jsx(Uk,{}),s("All topics ({{n}})",{n:w.length})]}),n.jsxs(Cn,{disabled:x,onClick:()=>{E()},children:[n.jsx(no,{}),s("New topic")]}),n.jsxs(Cn,{disabled:x,onClick:()=>h({id:t.id,title:j(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:()=>{E()},className:_(Wm,"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(EC,{heading:s("Topics"),placeholder:s("Search topics..."),empty:s("No matching topics"),filters:!0,entries:w,currentId:t.id,onClose:()=>d(!1),onOpen:k=>{C(k),d(!1)},onRename:k=>h({id:k.id,title:k.title}),onDelete:k=>g(k.id)}),n.jsx(hs,{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 T(p),zIndexLevel:u?"nested":"base"}),m!==null&&n.jsx(DU,{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:cs(L.error,s)});return}ie.getState().upsertChat(L.chat),h(null)}})]})}function px({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:Mo(e.activityAt,t)})]})}function EC({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=yv(o,m,p),y=w=>yv(o,"",w).length,j="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(on,{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(Rh,{"data-size":"sm",className:"mt-1",children:[n.jsx(Mh,{children:n.jsx(lr,{})}),n.jsx(Ph,{autoFocus:!0,value:m,placeholder:t,onChange:w=>h(w.target.value)})]}),r&&n.jsx(Td,{value:p,onValueChange:w=>g(w),children:n.jsxs(Ad,{children:[n.jsx(fs,{value:"all",children:d("All")}),n.jsxs(fs,{value:"unread",children:[d("Unread"),y("unread")>0&&n.jsx("span",{className:"tabular-nums",children:y("unread")})]}),n.jsxs(fs,{value:"running",children:[d("In progress"),y("running")>0&&n.jsx("span",{className:"tabular-nums",children:y("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(Dn,{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(px,{entry:w})]}),c&&w.canRename&&n.jsx("button",{type:"button",className:j,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:_(j,"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 DU({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(on,{children:o("Rename topic")})}),n.jsx(In,{children:n.jsx(Vt,{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(he,{variant:"outline",size:"sm",onClick:s,children:o("Cancel")}),n.jsx(he,{size:"sm",disabled:!i.trim(),onClick:l,children:o("Save")})]})]})})}function OU({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(b=>{b.ok&&a(b.sessions.filter(N=>N.botId===t))})},[e.id,t]);f.useEffect(h,[h,m,s]);const p=i.map(b=>{const N=b.conversationId===m;return{id:b.conversationId,title:b.title??o(N?"New conversation":"Untitled conversation"),preview:N||b.resumable?"":o("Workspace changed; view only"),activityAt:b.activityAt??(N?Date.now():0),unread:!1,running:N&&s,resumable:b.resumable}}),g=bN(p,{currentId:m??"",rootId:m??""}),x=p.length-g.length,y=p.find(b=>b.id===m)?.title??o("New conversation"),j=async b=>{const N=await window.electronAPI.bots.switchSession(e.id,b);N.ok||Ie({type:"error",title:cs(N.error,o)}),await ie.getState().refreshChats(),h()},w=b=>{const N=p.find(C=>C.id===b);!N||b===m||(N.resumable?s?d(b):j(b):r(b,N.title))};return p.length<2?null:n.jsxs(n.Fragment,{children:[n.jsxs(ur,{onOpenChange:b=>b&&h(),children:[n.jsxs(fr,{className:_(Wm,"max-w-56"),children:[n.jsx("span",{className:"truncate",children:y}),n.jsx(Bn,{className:"h-3.5 w-3.5 shrink-0"})]}),n.jsxs(mr,{align:"end",className:"w-72",children:[n.jsxs(Ah,{children:[n.jsx(Eh,{children:o("Conversations")}),g.map(b=>n.jsxs(Cn,{onClick:()=>w(b.id),children:[n.jsx(Dn,{className:_(b.id!==m&&"invisible")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.title}),!b.resumable&&b.id!==m&&n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:o("Read-only")}),n.jsx(px,{entry:b})]},b.id))]}),x>0&&n.jsxs(n.Fragment,{children:[n.jsx(yi,{}),n.jsxs(Cn,{onClick:()=>c(!0),children:[n.jsx(Uk,{}),o("All conversations ({{n}})",{n:p.length})]})]})]})]}),l&&n.jsx(EC,{heading:o("Conversations"),placeholder:o("Search conversations..."),empty:o("No matching conversations"),entries:p,currentId:m??"",onClose:()=>c(!1),onOpen:b=>{c(!1),w(b)}}),n.jsx(hs,{open:u!==null,onOpenChange:b=>!b&&d(null),title:o("Switch conversation?"),description:o("The reply in progress will be stopped."),confirmLabel:o("Switch"),onConfirm:()=>u&&void j(u)})]})}function RC(e){const{t}=z(),s=Rd(),r=xe(c=>c.virtualModels);if(!e?.engine)return t("Default model");const{providerId:o,modelId:i}=e.engine,a=mj(r,e.engine);return a?a.name:s.find(c=>c.id===o)?.models.find(c=>c.id===i)?.label??i}function LU({chat:e,group:t=e}){const{t:s}=z(),r=ie(Q=>Q.bots),o=ie(Q=>Q.chats),i=ie(Q=>Q.sessions),a=ie(Q=>Q.queue),l=ie(Q=>Q.delegations),c=ie(Q=>Q.timelines[e.id]),u=ie(Q=>Q.runtime[e.id]),d=ie(Q=>Q.markRead),m=ie(Q=>Q.panelOpen),h=ie(Q=>Q.panelTab),p=ie(Q=>Q.browserTabs[t.id]?.tabs.length??0),g=ie(Q=>Q.panelWidth),x=xe(Q=>Q.skills),[y,j]=f.useState(!1),[w,b]=f.useState(0),N=wi(),C=f.useRef(null);f.useEffect(()=>{const Q=C.current?.parentElement;if(!Q)return;const Ae=()=>b(Q.clientWidth);Ae();const pt=new ResizeObserver(Ae);return pt.observe(Q),()=>pt.disconnect()},[]);const E=N?w:IA(g,w),T=m?E:0,k=f.useCallback(Q=>{const Ae=C.current?.parentElement;Ae&&ie.getState().nudgePanelWidth(-Q,Ae.clientWidth)},[]),[L,F]=f.useState(null),[A,D]=f.useState(),[M,H]=f.useState(null),G=ie(Q=>Q.focus?.chatId===e.id?Q.focus:null),U=ie(Q=>Q.clearFocus),J=f.useMemo(()=>new Map(r.map(Q=>[Q.id,Q])),[r]),$=f.useMemo(()=>Object.fromEntries(r.map(Q=>[Q.id,Q.name])),[r]),oe=e.members.map(Q=>J.get(Q)).filter(Q=>!!Q),Ne=oe.map(Q=>`${Q.id}:${Q.skillIds.join(",")}`).join("|"),ce=f.useMemo(()=>x.flatMap(Q=>{const Ae=oe.filter(pt=>pt.skillIds.includes(Q.id)).map(pt=>pt.id);return Ae.length?[{id:Q.id,name:Q.name,description:Q.description,owners:Ae}]:[]}),[x,Ne]),ne=f.useMemo(()=>o.filter(Q=>Q.id!==t.id&&!Q.parentId&&Q.archivedAt===void 0).map(Q=>({id:Q.id,title:is(Q,r,s),kind:Q.kind})),[o,t.id,r,s]),Y=Th(e,{sessions:i,timeline:c,queue:a,names:$}),pe=ie(Q=>Q.reads[Y.key]),ge=e.kind==="group"?NA(c,pe):Y.marker,we=f.useMemo(()=>l.filter(Q=>Q.chatId===e.id),[l,e.id]),V=f.useMemo(()=>dj(i,uj(o,l),e.id),[i,o,l,e.id]),B=L?(Q=>{const Ae=we.find(Xe=>Xe.childConversationId===Q);if(Ae)return J.get(Ae.targetBotId);const pt=Object.entries(e.sessions).find(([,Xe])=>Xe.conversationId===Q)?.[0],Dt=c?.entries.find(Xe=>Xe.kind==="bot"&&Xe.conversationId===Q);return J.get(pt??(Dt?.kind==="bot"?Dt.botId:e.kind==="direct"?e.members[0]:""))})(L.id):void 0,te=M?J.get(M.botId):void 0,Z=M?V.filter(Q=>Q.conversationId===M.id):[],ue=M?.title??te?.name??s("Deleted member"),fe=M&&l.find(Q=>Q.childConversationId===M.id)?.state==="queued",Ce=f.useCallback((Q,Ae)=>{const pt=SA(ie.getState().delegations,Q);pt?(ie.getState().sessions[Q]||ie.getState().trackSession(Q),H({id:Q,botId:pt.botId,title:Ae})):F({id:Q,title:Ae})},[]);f.useEffect(()=>{d(Y.key,ge)},[d,Y.key,ge]),f.useEffect(()=>{if(e.kind==="group"){const Q=ie.getState();Q.timelines[e.id]?.history&&Q.focus?.chatId!==e.id?Q.jumpLatest(e.id):Q.loadLatest(e.id),ie.getState().refreshRuntime(e.id)}},[e.id,e.kind]);const de=e.kind==="direct"?oe[0]:void 0,Ee=de?e.sessions[de.id]?.conversationId:void 0,me=G?.locator,Ve=G&&me?.kind==="session"&&me.conversationId===Ee?{messageIndex:me.messageIndex,query:G.query,nonce:G.nonce}:void 0,at=G&&me?.kind==="timeline"?{seq:me.seq,query:G.query,nonce:G.nonce}:void 0;f.useEffect(()=>{G?.locator.kind==="session"&&G.locator.conversationId!==Ee&&(F({id:G.locator.conversationId,title:s("History")}),D({messageIndex:G.locator.messageIndex,query:G.query,nonce:G.nonce}),U(G.nonce))},[G,Ee,U,s]);const Fe=L?.id,tt=f.useCallback(Q=>e.kind==="direct"&&Fe?n.jsx(fd,{target:{chatId:e.id,conversationId:Fe,messageIndex:Q}}):null,[e.id,e.kind,Fe]),je=e.archivedAt!==void 0,Je=u?.current?J.get(u.current):void 0,rt=(()=>{if(je)return s("This chat is archived. Restore it before sending.");if(e.kind==="group"){const Q=e.routing.mode==="smart"?s("Without @, the best-fit member is picked to reply"):s("Without @, the group owner replies");return Je?`${Q} · ${s("{{name}} is replying; new messages are routed after they finish",{name:Je.name})}`:Q}return Y.running&&de?s("{{name}} is working; your message joins the current turn",{name:de.name}):null})(),K=async({text:Q,images:Ae,...pt})=>{const Dt=await ie.getState().send(e.id,Q,Ae,pt);return Dt.ok?(Dt.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:cs(Dt.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:[de?n.jsx($t,{bot:de,busy:Y.running}):n.jsx(ta,{bots:oe,busy:Y.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:de?n.jsx(BU,{bot:de,running:Y.running,queued:Y.queued,conversationId:e.sessions[de.id]?.conversationId}):s("{{n}} members · Owner {{name}}",{n:oe.length,name:J.get(e.bossBotId??"")?.name??"—"})})]}),n.jsx("div",{className:"flex-1"}),n.jsx(bC,{chat:t}),de?n.jsxs(n.Fragment,{children:[n.jsx(OU,{chat:e,botId:de.id,running:Y.running,onView:(Q,Ae)=>F({id:Q,title:Ae})}),n.jsxs("button",{type:"button",disabled:je,onClick:()=>{window.electronAPI.bots.newSession(e.id).then(Q=>{Q.ok?ie.getState().refreshChats():Ie({type:"error",title:cs(Q.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(PU,{group:t,thread:e})]}),de?n.jsxs(n.Fragment,{children:[n.jsx(_U,{items:cj(we,e.id),bots:J,onOpenConversation:Ce}),n.jsx(zU,{chat:e,bot:de,focus:Ve,onFocusDone:U})]}):n.jsx(SU,{chat:e,bots:J,timeline:c,runtime:u,delegations:we,focus:at,onFocusDone:U,onLoadOlder:()=>{ie.getState().loadOlder(e.id)},onLoadNewer:()=>{ie.getState().loadNewer(e.id)},onLoadAround:Q=>ie.getState().loadAround(e.id,Q),onJumpLatest:()=>{ie.getState().jumpLatest(e.id)},onOpenConversation:Ce,onOpenLive:(Q,Ae)=>H({id:Q,botId:Ae,title:J.get(Ae)?.name??s("Deleted member")})}),n.jsx("div",{className:"@container pt-1",children:n.jsxs("div",{className:_(_r,"pb-4"),children:[de&&(Y.running||Y.queued)&&n.jsx(JS,{conversationId:e.sessions[de.id]?.conversationId,className:"mb-2 rounded-lg border bg-muted/30 px-3 py-2"}),n.jsx(zb,{items:V,bots:J,showNames:e.kind==="group"}),e.kind==="group"&&n.jsx(bW,{chatId:e.id,memberIds:e.members,bots:J,onOpenLive:(Q,Ae)=>H({id:Q,botId:Ae,title:J.get(Ae)?.name??s("Deleted member")})}),n.jsx(oW,{chatId:e.id,placeholder:de?s("Message {{name}}…",{name:de.name}):s("@ a member, or just say it…"),members:e.kind==="group"?oe:void 0,chatOptions:ne,skills:ce,running:Y.running||!!(u?.current||u?.routing),disabled:je,hint:rt,toolbar:de?n.jsx(FU,{bot:de}):null,onSend:K,onStop:()=>{ie.getState().stop(e.id)}},e.id)]})})]}),m&&!N&&n.jsx(id,{onResize:k,onResizingChange:j}),n.jsx(ks.aside,{ref:C,initial:!1,animate:{width:T},style:N?void 0:{maxWidth:`max(0px, calc(100% - ${CA+fj}px))`},transition:i7({skip:y,cover:N,targetW:T}),className:_("flex min-h-0 shrink-0 flex-col overflow-hidden bg-background",N?"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:E},children:[n.jsx("div",{className:"flex h-10 shrink-0 items-center gap-1 border-b px-2",children:["info","browser"].map(Q=>n.jsxs("button",{type:"button",onClick:()=>ie.getState().setPanelTab(Q),className:_("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",h===Q?"bg-brand/10 font-medium text-foreground dark:bg-brand/15":"text-muted-foreground hover:text-foreground"),children:[Q==="info"?n.jsx(Qa,{className:"h-3.5 w-3.5"}):n.jsx(Ro,{className:"h-3.5 w-3.5"}),s(Q==="info"?de?"Member":"Group info":"Browser"),Q==="browser"&&p>0&&n.jsx("span",{className:"text-muted-foreground tabular-nums",children:p})]},Q))}),h==="browser"?n.jsx(U7,{chatId:t.id,visible:m}):de?n.jsx(eU,{botId:de.id,chat:e,onOpenHistory:Ce}):n.jsx(hU,{chat:t,thread:e,onOpenConversation:Ce})]})}),n.jsx(hx,{conversationId:L?.id??null,title:L?.title??"",speaker:B?{name:B.name,color:B.avatar.color,image:Mc(B)}:void 0,focus:A,turnFooter:tt,onClose:()=>{F(null),D(void 0)}}),n.jsx(AC,{conversationId:M?.id??null,title:ue,speaker:{name:te?.name??ue,color:te?.avatar.color??"#64748b",image:te?Mc(te):void 0},emptyTitle:fe?s("Queued and has not started yet"):void 0,emptyDescription:fe?"":void 0,footer:te&&Z.length>0?n.jsx(zb,{items:Z,bots:J,showNames:!1}):void 0,onClose:()=>H(null)})]})}function _U({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(ou,{record:o,bots:t,onOpenConversation:s},o.id))})]})})}function BU({bot:e,running:t,queued:s,conversationId:r}){const{t:o}=z(),i=RC(e),a=o(t?"Working":s?"Queued":"Idle");return n.jsxs(n.Fragment,{children:[[e.title,i,a].filter(Boolean).join(" · "),t&&n.jsx(jC,{conversationId:r,className:"ml-1.5 text-warning"})]})}function FU({bot:e}){const{t}=z(),s=RC(e),r=Sa[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(Sd,{className:"h-3 w-3"}),t(r.labelKey)]})]})}function zU({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:cs(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(fd,{target:{chatId:e.id,conversationId:i,messageIndex:u}}):null,[e.id,i]);return i?n.jsx(TC,{conversationId:i,speaker:{name:t.name,color:t.avatar.color,image:Mc(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 zb({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(Vp,{approvals:d,onRespond:(h,p)=>{window.electronAPI.agent.respondApproval(i,h,p)}}),n.jsx(Hp,{asks:m,onAnswer:(h,p)=>{window.electronAPI.agent.respondAsk(i,h,p)}})]},i)})})}function $U(e,t){const s={pending:[],budgets:[],routines:[],silences:[],interrupted:[],blocked:[],count:0};for(const r of TA(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 VU({write:e,bot:t,chatName:s}){const{t:r}=z(),o=AA(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(he,{size:"xs",variant:"outline",disabled:i,onClick:()=>u("reject"),children:r("Reject")}),n.jsx(he,{size:"xs",disabled:i,onClick:()=>u("approve"),children:r("Approve")})]})]})}function HU(){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(()=>$U(t,{routines:i,delegations:o}),[t,i,o]),u=EA(),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(Ip,{className:"h-6 w-6"}),n.jsx("p",{className:"text-sm",children:e("Nothing needs your attention")})]}),c.pending.map(h=>n.jsx(qU,{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(UU,{item:h,bot:d.get(h.botId??"")},h.key)),u.map(h=>n.jsx(VU,{write:h,bot:h.botId?d.get(h.botId):void 0,chatName:m(h.chatId)},h.id)),c.routines.map(h=>n.jsx(WW,{alert:h},h.routine.id)),c.silences.map(h=>n.jsx(WU,{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(GU,{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(KU,{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(hx,{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 WU({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(wC,{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(he,{size:"xs",variant:"ghost",onClick:()=>{i(e.key)},children:r("Dismiss")}),e.chatId&&n.jsx(he,{size:"xs",variant:"outline",onClick:()=>e.chatId&&o({kind:"chat",chatId:e.chatId}),children:r("Go to chat")})]})]})}function UU({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(he,{size:"xs",variant:"ghost",onClick:()=>{r(e.key)},children:s("Dismiss")}),t&&n.jsx(he,{size:"xs",variant:"outline",onClick:()=>{o(t.id)},children:s("Go to chat")})]})]})}function GU({inboxKey:e,record:t,bots:s,chatName:r}){const{t:o}=z(),i=ie(g=>g.openTask),a=ie(g=>g.dismissInbox),l=ru(!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(su,{state:t.state}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{children:o("Stuck for {{time}}",{time:Pr(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(mx,{placeholder:o("Answer {{name}}; they continue after your reply…",{name:u}),onSend:g=>pC(h,p,g,o)})]}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(he,{size:"xs",variant:"ghost",onClick:()=>{a(e)},children:o("Dismiss")}),h&&p&&n.jsx(he,{size:"xs",variant:"outline",onClick:()=>i(h,p),children:o("Open task card")})]})]})}function KU({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(su,{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:vl(t,i)}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-end gap-1.5",children:[n.jsx(he,{size:"xs",variant:"ghost",onClick:()=>{l(e)},children:i("Dismiss")}),t.chatId&&n.jsx(he,{size:"xs",variant:"ghost",onClick:()=>t.chatId&&a({kind:"chat",chatId:t.chatId}),children:i("Go to chat")}),n.jsx(he,{size:"xs",variant:"outline",onClick:()=>o(i("{{from}} → {{to}} · Delegation",{from:d,to:m})),children:i("View conversation")}),n.jsx(he,{size:"xs",onClick:()=>ya(t.id,i),children:i("Retry")})]})]})}function qU({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:yN(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(he,{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(he,{size:"xs",variant:"outline",disabled:c,onClick:()=>m("deny"),children:o("Deny")}),!e.request.protected&&!e.request.mandatory&&n.jsx(he,{size:"xs",variant:"outline",disabled:c,onClick:()=>m("allowSession"),children:o("Always allow in this session")}),n.jsx(he,{size:"xs",disabled:c,onClick:()=>m("allow"),children:o("Allow")})]}):n.jsxs(n.Fragment,{children:[e.request.options?.map(g=>n.jsx(he,{size:"xs",variant:"outline",disabled:c,onClick:()=>h(g),children:g},g)),n.jsx(Vt,{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(he,{size:"xs",disabled:c||!a.trim(),onClick:()=>h(a),children:o("Reply")})]})]})]})}function YU(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 y=RA({locale:l.locale}),j=f.useMemo(()=>l.filter!==void 0?l.filter:y.contains,[l.filter,y]),w=String(d?s:m).trim(),b=f.useMemo(()=>i!=="both"?u?null:j:j===null?null:(E,T,k)=>j(E,w,k),[j,i,w,u]);function N(E,T){g(""),d||h(E),o?.(E,T)}function C(E,T){e.onItemHighlighted?.(E,T),T.reason!==PA&&g(c&&E!=null?DA(E,a):"")}return n.jsx(MA,{...l,itemToStringLabel:a,openOnInputClick:t,selectionMode:"none",fillInputOnItemPress:!0,filter:b,autoComplete:i,inputValue:x,defaultInputValue:r,onInputValueChange:N,onItemHighlighted:C})}const XU=OA,QU="⁠",JU=200;function ZU(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 eG(){const e=LA(),t=f.useRef(null);return f.useEffect(()=>{if(_A)return;const s=t.current;if(s==null)return;const r=ZU(s);if(r==null)return;const o=r.data,i=`${o}${QU}`;return r.nodeValue=i,e.start(JU,()=>{r.nodeValue===i&&(r.nodeValue=o)}),()=>{e.clear(),r.nodeValue===i&&(r.nodeValue=o)}},[t,e]),t}const MC=f.createContext(void 0);function tG(){const e=f.useContext(MC);if(e===void 0)throw new Error(qa(18));return e}const nG=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=Ya("div",t,{ref:s,props:[{role:"group","aria-labelledby":c},l]}),h=n.jsx(MC.Provider,{value:d,children:m});return a?n.jsx(BA,{items:a,children:h}):h}),sG=f.forwardRef(function(t,s){const{render:r,className:o,style:i,id:a,...l}=t,{setLabelId:c}=tG(),u=vw(a);return ph(()=>(c(u),()=>{c(m=>m===u?void 0:m)}),[u,c]),Ya("div",t,{ref:s,props:[{id:u},l]})}),rG=FA,oG=f.forwardRef(function(t,s){const{render:r,className:o,style:i,children:a,...l}=t,{filteredItems:c}=zA(),u=$A(),d=eG(),m=c.length===0?a:null;return Ya("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 xx=YU,wa=new WeakMap,xd=new WeakMap;function aG(e){const t=wa.get(e);t!==void 0&&window.clearTimeout(t),wa.delete(e);for(const s of xd.get(e)??[])s.cancel();xd.delete(e),e.classList.remove("is-clearing")}function Uo(e,t){const s=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(e));return Number.isFinite(s)?s:t}function wc(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&&aG(e),e.classList.toggle("has-value",r.hasValue),s.textContent=r.mirrorText}function lG(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=wa.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=Uo("--clear-dur",1e3),c=Uo("--clear-out-dur",400),u=Uo("--clear-in-dur",400),d=Uo("--clear-out-fly",12),m=Uo("--clear-in-fly",12),h=Uo("--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"}),y=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"}),j=window.setTimeout(()=>{x.cancel(),y.cancel(),xd.delete(t),t.classList.remove("is-clearing"),r.textContent="",wa.delete(t),wc(t)},Math.max(l,c,u));wa.set(t,j),xd.set(t,[x,y])}function gx({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&&wc(l.current);const c=window.requestAnimationFrame(()=>{l.current&&wc(l.current)});return()=>window.cancelAnimationFrame(c)}),n.jsxs("div",{ref:l,className:"t-clear autocomplete-clear-dissolve relative w-full",onInput:c=>wc(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(VA,{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(Vt,{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(fG,{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(HA,{})}),s&&n.jsx(uG,{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(Zt,{})})]})}function PC({className:e,children:t,sideOffset:s=4,zIndex:r,...o}){return n.jsx(WA,{children:n.jsx(UA,{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(GA,{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 vx({className:e,children:t,...s}){return n.jsx(rG,{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 cG({className:e,...t}){return n.jsx(nG,{className:_("[[role=group]+&]:mt-1.5",e),"data-slot":"autocomplete-group",...t})}function dG({className:e,...t}){return n.jsx(sG,{className:_("px-2 py-1.5 font-medium text-muted-foreground text-xs",e),"data-slot":"autocomplete-group-label",...t})}function bx({className:e,...t}){return n.jsx(oG,{className:_("not-empty:p-2 text-center text-base text-muted-foreground sm:text-sm",e),"data-slot":"autocomplete-empty",...t})}function yx({className:e,...t}){return n.jsx(KA,{scrollbarGutter:!0,scrollFade:!0,children:n.jsx(qA,{className:_("not-empty:scroll-py-1 not-empty:p-1 in-data-has-overflow-y:pe-3",e),"data-slot":"autocomplete-list",...t})})}function uG({className:e,onClickCapture:t,onPointerDownCapture:s,...r}){return n.jsx(YA,{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||lG(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(Zt,{})})}function fG({className:e,...t}){return n.jsx(XU,{className:e,"data-slot":"autocomplete-trigger",...t})}const DC=f.createContext({inputRef:null}),OC=XA,mG=QA;function hG({className:e,...t}){return n.jsx(eE,{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 pG({className:e,...t}){return n.jsx(tE,{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 LC({className:e,children:t,...s}){const r=f.useRef(null);return n.jsxs(mG,{children:[n.jsx(JA,{}),n.jsx(hG,{}),n.jsx(pG,{children:n.jsx(ZA,{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(DC.Provider,{value:{inputRef:r},children:t})})})]})}function _C({autoHighlight:e="always",keepHighlight:t=!0,open:s=!0,...r}){return n.jsx(xx,{autoHighlight:e,keepHighlight:t,open:s,...r})}function BC({className:e,placeholder:t=void 0,endAddon:s,...r}){const{inputRef:o}=f.useContext(DC);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(gx,{className:_("border-transparent! bg-transparent! shadow-none before:hidden has-focus-visible:ring-0",e),placeholder:t,ref:o,size:"lg",startAddon:n.jsx(lr,{}),...r})}),s]})}function FC({className:e,...t}){return n.jsx(yx,{className:_("not-empty:scroll-py-2 not-empty:p-2",e),"data-slot":"command-list",...t})}function zC({className:e,...t}){return n.jsx(bx,{className:_("not-empty:py-6",e),"data-slot":"command-empty",...t})}function $C({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 Go({className:e,...t}){return n.jsx(cG,{className:e,"data-slot":"command-group",...t})}function Ko({className:e,...t}){return n.jsx(dG,{className:e,"data-slot":"command-group-label",...t})}function wo({className:e,...t}){return n.jsx(vx,{className:_("py-1.5",e),"data-slot":"command-item",...t})}function $b({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 VC({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 Vb=e=>e.locator.kind==="timeline"?`${e.chatId}:${e.locator.seq}`:`${e.chatId}:${e.locator.conversationId}:${e.locator.messageIndex}`;function HC({className:e}){const{t}=z(),s=xe(i=>i.keybindings),r=Mr(s)["search-workspace"],o=t("Search messages");return n.jsx("button",{type:"button",className:e,onClick:()=>ie.getState().setSearchOpen(!0),title:r?`${o} (${Gs(r)})`:o,children:n.jsx(lr,{className:"h-4 w-4"})})}function xG(){const{t:e,locale:t}=z(),s=ie(y=>y.searchOpen),r=ie(y=>y.setSearchOpen),o=ie(y=>y.bots),i=ie(y=>y.chats),[a,l]=f.useState(""),[c,u]=f.useState(),d=a.trim(),m=f.useMemo(()=>new Map(o.map(y=>[y.id,y])),[o]),h=f.useMemo(()=>new Map(i.map(y=>[y.id,y])),[i]),p=c?.key===d?c:void 0;f.useEffect(()=>{s||(l(""),u(void 0))},[s]),f.useEffect(()=>{if(!s||!d)return;let y=!1;const j=window.setTimeout(()=>{window.electronAPI.bots.search({query:d}).then(w=>{y||u(w.ok?{key:d,hits:w.hits,truncated:w.truncated}:{key:d,hits:[],truncated:!1})}).catch(()=>{y||u({key:d,hits:[],truncated:!1})})},150);return()=>{y=!0,window.clearTimeout(j)}},[s,d]);const g=y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),r(!1))},x=Date.now();return n.jsx(OC,{open:s,onOpenChange:r,children:n.jsx(LC,{className:"max-h-[min(36rem,calc(100vh-6rem))] max-w-2xl",onKeyDown:g,children:n.jsxs(_C,{children:[n.jsx(BC,{placeholder:e("Search group and direct messages…"),value:a,onChange:y=>l(y.currentTarget.value),onKeyDown:y=>{g(y);const j=p?.hits[0];y.key==="Enter"&&!y.nativeEvent.isComposing&&j&&!document.querySelector('[data-slot="command-dialog-popup"] [data-highlighted]')&&(y.preventDefault(),ie.getState().focusHit(j,d))}}),n.jsxs($C,{children:[d&&p&&p.hits.length===0&&n.jsx(zC,{children:e("No matching messages")}),n.jsxs(FC,{children:[p?.hits.map(y=>{const j=h.get(y.chatId),w=(j?.members??[]).map(C=>m.get(C)).filter(C=>C!==void 0),b=y.speaker.kind==="human"?e("You"):m.get(y.speaker.botId)?.name??e("Deleted member"),N=y.locator.kind==="session"&&!y.locator.current?` · ${e("History")}`:"";return n.jsxs(wo,{value:Vb(y),className:"items-start gap-2.5",onClick:()=>ie.getState().focusHit(y,d),children:[n.jsx("span",{className:"mt-0.5 shrink-0",children:y.chatKind==="direct"?n.jsx($t,{bot:w[0]}):n.jsx(ta,{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:j?is(j,o,e):e("Deleted chat")}),n.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[b,N]})]}),n.jsx("p",{className:"line-clamp-2 break-words text-muted-foreground text-xs",children:yU(y.snippet,y.ranges).map((C,E)=>C.match?n.jsx("mark",{className:"rounded-[3px] bg-brand/14 text-foreground",children:C.text},E):n.jsx("span",{children:C.text},E))})]}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:y.at?Mo(y.at,t,x):""})]},Vb(y))}),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(VC,{children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsxs(hj,{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 gG({chat:e,onOpenChange:t}){const{t:s}=z(),r=ie(p=>p.bots),o=ie(p=>p.chats),i=xe(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(nE(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:cs(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(on,{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(Lt,{children:s("Group name")}),n.jsx(Vt,{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(Lt,{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:ij(e,i,r,s)}):s("A new empty folder, separate from the original")]})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx(Lt,{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(he,{variant:"outline",size:"sm",onClick:()=>t(!1),children:s("Cancel")}),n.jsx(he,{size:"sm",disabled:!a.trim()||c,onClick:()=>{h()},children:s("Clone")})]})]})})}const go="relative flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";function vG({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:Ai,onClick:i},{label:a("New member"),icon:Da,onClick:s},{label:a("New group chat"),icon:mi,onClick:r},{label:a("Create team from template"),icon:Vf,onClick:o}],u=ie(K=>K.bots),d=ie(K=>K.chats),m=ie(K=>K.queue),h=ie(K=>K.sessions),p=ie(K=>K.delegations),g=ie(K=>K.timelines),x=ie(K=>K.reads),y=ie(K=>K.view),j=ie(K=>K.setView),w=ie(K=>K.openDirect),b=ie(K=>K.upsertChat),N=ie(K=>K.upsertBot),[C,E]=f.useState(!1),[T,k]=f.useState(""),[L,F]=f.useState(null),[A,D]=f.useState(null),M=f.useMemo(()=>new Map(u.map(K=>[K.id,K])),[u]),H=f.useMemo(()=>Object.fromEntries(u.map(K=>[K.id,K.name])),[u]),G=f.useMemo(()=>dj(h,uj(d,p)),[h,d,p]),U=f.useMemo(()=>{const K=new Set,Q=new Set;for(const Ae of p)Na(Ae.state)&&(Ae.chatId&&K.add(Ae.chatId),Q.add(Ae.targetBotId));return{chatIds:K,botIds:Q}},[p]),J=f.useMemo(()=>sE(d.map(K=>{const Q=Th(K,{sessions:h,timeline:g[K.id],queue:m,names:H});return{chat:K,summary:{...Q,running:Q.running||(K.kind==="group"?U.chatIds.has(K.id):U.botIds.has(K.members[0])),pending:G.filter(Ae=>Ae.chatId===K.id).length}}}),x),[d,h,g,m,H,G,U,x]),$=J.filter(K=>!K.chat.archivedAt),oe=rE($.filter(K=>K.chat.kind==="group"&&K.chat.settledAt===void 0)),Ne=new Map($.filter(K=>K.chat.kind==="direct").map(K=>[K.chat.members[0],K])),ce=u.filter(K=>K.archivedAt===void 0&&Ne.get(K.id)?.chat.settledAt===void 0).map(K=>({bot:K,row:Ne.get(K.id)})).sort((K,Q)=>{const Ae=Number(Q.row?.chat.pinned??!1)-Number(K.row?.chat.pinned??!1),pt=(K.row?.chat.pinOrder??Number.POSITIVE_INFINITY)-(Q.row?.chat.pinOrder??Number.POSITIVE_INFINITY);return Ae||(K.row?.chat.pinned&&pt?pt:0)||(Q.row?.summary.activityAt??Q.bot.updatedAt)-(K.row?.summary.activityAt??K.bot.updatedAt)}),ne=$.filter(K=>K.chat.settledAt!==void 0&&(K.chat.kind==="group"||M.get(K.chat.members[0])?.archivedAt===void 0)).sort((K,Q)=>(Q.chat.settledAt??0)-(K.chat.settledAt??0)),Y=oe.filter(K=>K.chat.pinned).map(K=>K.chat.id),pe=ce.flatMap(({row:K})=>K?.chat.pinned?[K.chat.id]:[]),[ge,we]=f.useState(null),[V,W]=f.useState(!0),B=J.filter(K=>K.chat.archivedAt!==void 0),te=u.filter(K=>K.archivedAt!==void 0),Z=B.length+te.length,ue=T.trim().toLowerCase(),fe=(...K)=>!ue||K.some(Q=>Q.toLowerCase().includes(ue)),Ce=B.filter(({chat:K,summary:Q})=>fe(is(K,u,a),Q.preview??"")).sort((K,Q)=>(Q.chat.archivedAt??0)-(K.chat.archivedAt??0)),de=te.filter(K=>fe(K.name,K.title,K.scope)).sort((K,Q)=>(Q.archivedAt??0)-(K.archivedAt??0)),Ee=Dh(),me=y?.kind==="chat"?y.chatId:null,Ve=async(K,Q)=>{const Ae=await window.electronAPI.bots.updateChat({chatId:K.id,...Q});Ae.ok?b(Ae.chat):Ie({type:"error",title:cs(Ae.error,a)})},at=K=>Ve(K,K.pinned?{pinned:!1}:{pinned:!0,pinOrder:Math.max(-1,...d.filter(Q=>Q.pinned).map(Q=>Q.pinOrder??0))+1}),Fe=(K,Q,Ae)=>{const pt=Object.fromEntries(d.map(Dt=>[Dt.id,Dt.pinOrder]));for(const Dt of aE(K,Q,Ae,pt)){const Xe=d.find(kt=>kt.id===Dt.chatId);Xe&&Ve(Xe,{pinOrder:Dt.pinOrder})}},tt=(K,Q)=>{const Ae=Q.indexOf(K.id),pt=J.find(Dt=>Dt.chat.id===K.id)?.summary;return{onSettle:()=>{Ve(K,{settled:K.settledAt===void 0})},onSnooze:Dt=>{Ve(K,{snoozedUntil:Dt})},onMarkUnread:pt&&me!==K.id&&!Qi(pt.marker,x[pt.key])&&oE(pt.marker)!==void 0?()=>ie.getState().markUnread(K.id):void 0,onMoveUp:Ae>0?()=>Fe(Q,K.id,Ae-1):void 0,onMoveDown:Ae>=0&&Ae<Q.length-1?()=>Fe(Q,K.id,Ae+1):void 0}},je=(K,Q)=>K?.pinned?{draggable:!0,onDragStart:Ae=>{Ae.dataTransfer.effectAllowed="move",we(K.id)},onDragEnd:()=>we(null),onDragOver:Ae=>{ge&&ge!==K.id&&Q.includes(ge)&&Ae.preventDefault()},onDrop:Ae=>{Ae.preventDefault(),ge&&Q.includes(ge)&&Fe(Q,ge,Q.indexOf(K.id)),we(null)}}:{},Je=async(K,Q)=>{const Ae=await window.electronAPI.bots.archive(K.id,Q);Ae.ok?N(Ae.bot):Ie({type:"error",title:Ae.error})},rt=K=>K?K.running?a("Working"):K.queued?a("Queued"):K.activityAt?Mo(K.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(hf,{title:a("Group chats"),onAdd:r,addLabel:a("New group chat")}),oe.length===0&&n.jsx("p",{className:"px-4 py-1 text-muted-foreground text-xs",children:a("No group chats yet")}),oe.map(({chat:K,summary:Q})=>n.jsx(xf,{chat:K,onPin:()=>{at(K)},onArchive:()=>{Ve(K,{archived:!0})},onDelete:()=>F(K),onClone:()=>D(K),manage:tt(K,Y),children:n.jsx(pf,{...je(K,Y),active:me===K.id,avatar:n.jsx(ta,{bots:K.members.map(Ae=>M.get(Ae)),busy:Q.running}),title:is(K,u,a),pinned:K.pinned,meta:rt(Q),preview:Q.preview,unread:Qi(Q.marker,x[Q.key]),pending:Q.pending,onClick:()=>j({kind:"chat",chatId:K.id})})},K.id)),n.jsx(hf,{title:a("Members"),onAdd:s,addLabel:a("New member")}),ce.length===0&&n.jsx("p",{className:"px-4 py-1 text-muted-foreground text-xs",children:a("No members yet")}),ce.map(({bot:K,row:Q})=>n.jsx(xf,{chat:Q?.chat,onPin:Q?()=>{at(Q.chat)}:void 0,onArchive:Q?()=>{Ve(Q.chat,{archived:!0})}:void 0,onArchiveMember:()=>{Je(K,!0)},manage:Q?tt(Q.chat,pe):void 0,children:n.jsx(pf,{...je(Q?.chat,pe),active:!!(Q&&me===Q.chat.id),avatar:n.jsx($t,{bot:K,busy:Q?.summary.running||U.botIds.has(K.id)}),title:K.name,pinned:Q?.chat.pinned,meta:U.botIds.has(K.id)?a("Working"):rt(Q?.summary),preview:Q?.summary.preview||K.title||K.scope,unread:!!(Q&&Qi(Q.summary.marker,x[Q.summary.key])&&me!==Q.chat.id),pending:Q?.summary.pending??0,onClick:()=>{w(K.id)}})},K.id)),ne.length>0&&n.jsx(hf,{title:`${a("Settled")} · ${ne.length}`,onToggle:()=>W(K=>!K)}),V&&ne.map(({chat:K,summary:Q})=>{const Ae=K.kind==="direct"?M.get(K.members[0]):void 0;return n.jsx(xf,{chat:K,onPin:()=>{at(K)},onArchive:()=>{Ve(K,{archived:!0})},onClone:K.kind==="group"?()=>D(K):void 0,manage:tt(K,[]),children:n.jsx(pf,{className:"opacity-75",active:me===K.id,avatar:Ae?n.jsx($t,{bot:Ae,busy:Q.running}):n.jsx(ta,{bots:K.members.map(pt=>M.get(pt)),busy:Q.running}),title:Ae?Ae.name:is(K,u,a),meta:K.snoozedUntil!==void 0?a("Remind {{time}}",{time:Mo(K.snoozedUntil,l)}):rt(Q),preview:Q.preview,unread:Qi(Q.marker,x[Q.key])&&(K.kind==="group"||me!==K.id),pending:Q.pending,onClick:()=>Ae?void w(Ae.id):j({kind:"chat",chatId:K.id})})},K.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:go,title:a("Collapse sidebar"),children:n.jsx(Tp,{className:"h-4 w-4"})}):n.jsx("span",{}),n.jsxs("div",{className:"flex items-center",children:[n.jsx(HC,{className:go}),c.map(({label:K,icon:Q,onClick:Ae})=>n.jsx("button",{type:"button",className:_(go,"hidden @min-[18.5rem]:flex"),onClick:Ae,title:K,children:n.jsx(Q,{className:"h-4 w-4"})},K)),n.jsxs(ur,{children:[n.jsx(fr,{className:_(go,"@min-[18.5rem]:hidden"),title:a("More actions"),children:n.jsx(ll,{className:"h-4 w-4"})}),n.jsx(mr,{align:"end",side:"top",children:c.map(({label:K,icon:Q,onClick:Ae})=>n.jsxs(Cn,{onClick:Ae,children:[n.jsx(Q,{}),K]},K))})]}),(Ee>0||y?.kind==="inbox")&&n.jsxs("button",{type:"button",className:_(go,y?.kind==="inbox"&&"bg-brand/10 text-foreground hover:bg-brand/10 dark:bg-brand/15 dark:hover:bg-brand/15"),onClick:()=>j({kind:"inbox"}),title:a("Inbox"),children:[n.jsx(Ip,{className:"h-4 w-4"}),Ee>0&&n.jsx(au,{count:Ee,className:"-top-0.5 -right-1 absolute"})]}),Z>0&&n.jsx("button",{type:"button",className:go,onClick:()=>{k(""),E(!0)},title:`${a("Archived")} (${Z})`,children:n.jsx(ar,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:go,onClick:()=>{window.electronAPI.window.openSettings()},title:a("Settings"),children:n.jsx(Ds,{className:"h-4 w-4"})})]})]}),n.jsx(cn,{open:C,onOpenChange:E,children:n.jsxs(dn,{className:"h-[min(40rem,85vh)] max-w-xl",children:[n.jsxs(un,{children:[n.jsxs(on,{className:"flex items-baseline gap-2",children:[a("Archived"),n.jsx("span",{className:"font-sans text-muted-foreground text-sm tabular-nums",children:Z})]}),n.jsxs(Rh,{"data-size":"sm",className:"mt-1",children:[n.jsx(Mh,{children:n.jsx(lr,{})}),n.jsx(Ph,{value:T,placeholder:a("Search conversations..."),onChange:K=>k(K.target.value)})]})]}),n.jsxs(In,{className:"flex flex-col gap-y-3 border-t pt-3!",children:[Ce.length+de.length===0&&n.jsx("p",{className:"py-10 text-center text-muted-foreground text-sm",children:T.trim()?a("No matching conversations"):a("Nothing archived")}),Ce.length>0&&n.jsx(Hb,{title:a("Chat threads"),count:Ce.length,children:Ce.map(({chat:K,summary:Q})=>n.jsx(Wb,{avatar:K.kind==="group"?n.jsx(ta,{bots:K.members.map(Ae=>M.get(Ae))}):n.jsx($t,{bot:M.get(K.members[0])}),title:is(K,u,a),preview:Q.preview,onOpen:()=>{j({kind:"chat",chatId:K.id}),E(!1)},onRestore:()=>{Ve(K,{archived:!1})},onDelete:K.kind==="group"?()=>F(K):void 0},K.id))}),de.length>0&&n.jsx(Hb,{title:a("Members"),count:de.length,children:de.map(K=>n.jsx(Wb,{avatar:n.jsx($t,{bot:K}),title:K.name,preview:K.title||K.scope,onRestore:()=>{Je(K,!1)}},K.id))})]})]})}),n.jsx(hs,{open:L!==null,onOpenChange:K=>!K&&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 K=L;F(null),K&&window.electronAPI.bots.deleteChat(K.id).then(Q=>{Q.ok?(me===K.id&&j(null),ie.getState().refreshChats()):Ie({type:"error",title:cs(Q.error,a)})})}}),n.jsx(gG,{chat:A,onOpenChange:K=>!K&&D(null)})]})}function au({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 Hb({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 Wb({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(Ma,{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 hf({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(Xn,{className:"h-3.5 w-3.5"})})]})}function pf({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(Ns,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"flex-1"}),l>0?n.jsx(au,{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 xf({chat:e,children:t,onPin:s,onArchive:r,onDelete:o,onArchiveMember:i,onClone:a,manage:l}){const{t:c}=z(),u=d=>l?.onSnooze(iE(Date.now())[d]);return n.jsxs(Yr,{children:[n.jsx(Xr,{render:t}),n.jsxs(Qr,{className:"min-w-40",children:[s&&n.jsxs(Yt,{onClick:s,children:[e?.pinned?n.jsx(nd,{}):n.jsx(Ns,{}),e?.pinned?c("Unpin"):c("Pin")]}),l?.onMoveUp&&n.jsxs(Yt,{onClick:l.onMoveUp,children:[n.jsx(Id,{}),c("Move up")]}),l?.onMoveDown&&n.jsxs(Yt,{onClick:l.onMoveDown,children:[n.jsx(gh,{}),c("Move down")]}),l&&n.jsxs(Yt,{onClick:l.onSettle,children:[e?.settledAt!==void 0?n.jsx(Eo,{}):n.jsx(hh,{}),e?.settledAt!==void 0?c("Back to in progress"):c("Settle")]}),l&&n.jsxs(Oh,{children:[n.jsxs(Lh,{children:[n.jsx(Np,{}),c("Remind me later")]}),n.jsxs(_h,{className:"min-w-36",children:[n.jsx(Yt,{onClick:()=>u("hour"),children:c("In 1 hour")}),n.jsx(Yt,{onClick:()=>u("later"),children:c("In 3 hours")}),n.jsx(Yt,{onClick:()=>u("tomorrow"),children:c("Tomorrow 9:00")})]})]}),l?.onMarkUnread&&n.jsxs(Yt,{onClick:l.onMarkUnread,children:[n.jsx(T_,{}),c("Mark as unread")]}),a&&n.jsxs(Yt,{onClick:a,children:[n.jsx(Xa,{}),c("Clone group chat")]}),r&&n.jsxs(Yt,{onClick:r,children:[n.jsx(ar,{}),c("Archive chat")]}),i&&n.jsxs(Yt,{onClick:i,children:[n.jsx(Ma,{}),c("Archive member")]}),o&&n.jsxs(n.Fragment,{children:[n.jsx(Bh,{}),n.jsxs(Yt,{variant:"destructive",onClick:o,children:[n.jsx(vs,{}),c("Delete group chat")]})]})]})]})}const bG=30;function Ub({onPick:e}){const{t,locale:s}=z(),r=s==="zh"?"zh":"en",o=pj(),i=ie(N=>N.bots),[a,l]=f.useState(""),[c,u]=f.useState(!1),[d,m]=f.useState(null),[h,p]=f.useState(null),[g,x]=f.useState(""),y=async()=>{if(!(!a.trim()||c)){u(!0),m(null);try{const N=await window.electronAPI.bots.suggestGoal({goal:a.trim(),language:r,...i.length?{members:i.map(({id:C,name:E,title:T,scope:k})=>({id:C,name:E,title:T,scope:k}))}:{},templates:o.slice(0,bG).map(({id:C,data:E})=>({id:C,title:E.title,summary:E.summary}))});if(!N.ok){m(iu(N,t));return}p(N.suggestion),x(N.suggestion.firstMessage)}finally{u(!1)}}},j=async N=>{if(!c){u(!0),m(null);try{await e(N)}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(Ks,{value:a,autoFocus:!0,rows:3,placeholder:t("e.g. Track competitor news every week and send me a summary"),onChange:N=>l(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.metaKey||N.ctrlKey)&&y()}}),d&&n.jsx("p",{className:"text-destructive text-xs",children:d}),n.jsx("div",{className:"flex justify-end",children:n.jsxs(he,{size:"sm",disabled:!a.trim()||c,onClick:()=>{y()},children:[c?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Bs,{}),t("Recommend")]})})]});const w=h.kind==="team"?o.find(N=>N.id===h.templateId)?.data:void 0,b=h.kind==="existing"?i.find(N=>N.id===h.botId):h.kind==="member"?{...h.member,avatar:{color:bo[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(Ai,{className:"h-3.5 w-3.5"}),h.kind==="team"?t("Recommended: a team"):t("Recommended: one member")]}),b?n.jsxs("div",{className:"flex items-start gap-2.5",children:[n.jsx($t,{bot:b}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{className:"font-medium text-sm",children:[b.name,n.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:b.title})]}),b.scope&&n.jsx("p",{className:"text-muted-foreground text-xs",children:b.scope})]})]}):w&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("div",{className:"-space-x-1.5 flex",children:w.members.map(N=>n.jsx($t,{size:"sm",bot:{name:N.name,avatar:{color:N.color}}},N.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(Ks,{value:g,rows:3,onChange:N=>x(N.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(he,{size:"sm",variant:"ghost",disabled:c,onClick:()=>{p(null),m(null)},children:[n.jsx(bi,{}),t("Back")]}),n.jsxs("div",{className:"flex gap-2",children:[h.kind==="existing"&&n.jsx(he,{size:"sm",variant:"outline",disabled:c,onClick:()=>{j({firstMessage:g})},children:t("Create new instead")}),n.jsx(he,{size:"sm",disabled:c||h.kind==="existing"&&!b,onClick:()=>{j(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 zl=e=>({...oC,name:"",title:"",scope:"",persona:"",color:e,engine:null});function yG({open:e,onOpenChange:t,seed:s,onCreated:r}){const{t:o}=z(),i=ie(D=>D.bots),a=lE(),l=f.useRef(null),[c,u]=f.useState({kind:"template",id:"pm"}),[d,m]=f.useState(()=>zl(bo[0])),[h,p]=f.useState(null),[g,x]=f.useState(null),[y,j]=f.useState(!1),[w,b]=f.useState(!1),[N,C]=f.useState(!1),E=()=>{u({kind:"blank"}),m(zl(bo[i.length%bo.length])),p(null),x(null)},T=D=>{if(!D)return E();const M=cE(D.data);u({kind:"template",id:D.id}),m({...oC,name:M.name??"",title:M.title??"",scope:M.scope??"",persona:M.persona??"",color:M.avatar?.color??bo[0],engine:null,approvalMode:M.approvalMode??"auto-edits",tools:M.tools??"all"}),p(null),x(null)};f.useEffect(()=>{e&&(s?(u({kind:"blank"}),m({...zl(bo[i.length%bo.length]),...s}),p(null),x(null)):T(a[0]),j(!1),b(!1),C(!1))},[e]);const k=D=>{m(M=>({...M,...D})),x(null)},L=async D=>{const M=new Uint8Array(await D.arrayBuffer()),H=dE(M)==="png",G=H?uE(cg(M,"chara")??cg(M,"ccv3")??""):new TextDecoder().decode(M),U=G?NW(G):{ok:!1,error:"not-a-card"};if(!U.ok){x(U.error==="invalid-json"&&!H?o("This file is not valid JSON."):o("This file is not a SillyTavern character card."));return}const{color:J,memoryEnabled:$,...oe}=U.draft;u({kind:"import"}),m({...zl(J??d.color),...oe,...$!==void 0?{memoryEnabled:$}:{}}),p(H?await tj(D).catch(()=>null):null),j(!0),x(null)},F=Nh(d.name,i,o),A=async()=>{if(j(!0),F)return;const D=rC(d);if(!D.ok){x(o("Budget must be a positive number"));return}const M=cx(d);if(!M.ok){x(o("Check the per-turn token limit and delegation time limit"));return}b(!0);try{const H=await window.electronAPI.bots.create({name:d.name.trim(),title:d.title.trim(),scope:d.scope.trim(),...M.delegationTimeoutMinutes?{delegationTimeoutMinutes:M.delegationTimeoutMinutes}:{},...M.maxTokensPerTurn?{maxTokensPerTurn:M.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},...D.budget?{budget:D.budget}:{}});if(!H.ok){x(ea(H.reason,H.error,o));return}ie.getState().upsertBot(H.bot),h&&!await ej(H.bot.id,h)&&Ie({type:"error",title:o("Avatar update failed")}),t(!1);const G=await ie.getState().openDirect(H.bot.id);G&&r?.(G)}finally{b(!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(on,{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(he,{size:"sm",variant:c.kind==="template"?"default":"outline",disabled:a.length===0,onClick:()=>T(a[0]),children:o("From template")}),n.jsx(he,{size:"sm",variant:c.kind==="blank"?"default":"outline",onClick:E,children:o("Blank")}),n.jsxs(he,{size:"sm",variant:c.kind==="import"?"default":"outline",onClick:()=>l.current?.click(),children:[n.jsx(vh,{}),o("Import character card")]}),n.jsx("input",{ref:l,type:"file",accept:".json,.png,application/json,image/png",hidden:!0,onChange:D=>{const M=D.target.files?.[0];D.target.value="",M&&L(M)}})]}),c.kind==="template"&&n.jsxs("div",{className:"grid grid-cols-3 gap-2.5",children:[a.map(D=>n.jsxs("button",{type:"button",onClick:()=>T(D),className:_("flex flex-col items-start gap-1 rounded-xl border bg-card p-3 text-left transition-colors hover:bg-muted",c.id===D.id&&"ring-2 ring-info"),children:[n.jsx($t,{bot:{name:D.data.title,avatar:{color:D.data.color}}}),n.jsx("span",{className:"font-medium text-sm",children:D.data.title}),n.jsx("span",{className:"text-muted-foreground text-xs",children:D.data.summary})]},D.id)),n.jsxs("button",{type:"button",onClick:E,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(Xn,{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(Lt,{hint:o("Used for @ in groups; must be unique"),children:o("Name")}),n.jsx(Vt,{value:d.name,onChange:D=>k({name:D.target.value}),onBlur:()=>j(!0)}),y&&F&&n.jsx("p",{className:"mt-1 text-destructive text-xs",children:F})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:o("Title")}),n.jsx(Vt,{value:d.title,onChange:D=>k({title:D.target.value})})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:o("Model")}),n.jsx(Zw,{engine:d.engine,onChange:D=>k({engine:D}),zIndex:Pn.DROPDOWN_IN_MODAL})]}),n.jsxs("div",{children:[n.jsx(Lt,{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(Jw,{value:d.color,onChange:D=>k({color:D})}),n.jsx(Qw,{nested:!0,hasImage:!!h,onPick:p,onRemove:()=>p(null)})]})]})]}),n.jsxs("div",{className:"col-span-2",children:[n.jsx(Lt,{hint:o("Used for routing and the delegation directory"),children:o("Responsibilities")}),n.jsx(Vt,{value:d.scope,onChange:D=>k({scope:D.target.value})})]}),n.jsxs("div",{className:"col-span-2",children:[n.jsx(Lt,{action:n.jsx(dC,{value:d,onApply:k}),children:o("Persona")}),n.jsx(Ks,{rows:4,value:d.persona,onChange:D=>k({persona:D.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":N,onClick:()=>C(D=>!D),children:[n.jsx(fn,{className:_("h-4 w-4 transition-transform",N&&"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")})]}),N&&n.jsx("div",{className:"border-t px-3 py-3",children:n.jsx(iC,{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(he,{variant:"outline",size:"sm",onClick:()=>t(!1),children:o("Cancel")}),n.jsxs(he,{size:"sm",disabled:w||y&&!!F,onClick:()=>{A()},children:[w&&n.jsx(Bt,{className:"animate-spin"}),o("Create and start chatting")]})]})]})})}function WC({projectId:e,onChange:t}){const{t:s}=z(),r=xe(h=>h.projects),o=xe(h=>h.addProject),i=f.useMemo(()=>Ed(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:Un(p),detail:p.path,projectId:p.id})),...a.filter(p=>!h.has(p.path)).map(p=>({path:p.path,label:xj(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(xx,{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(gx,{placeholder:s("Search Code projects or recent folders..."),showClear:!!c,showTrigger:!0})}),n.jsx(he,{type:"button",variant:"outline",onClick:()=>{window.electronAPI.dialog.selectDirectory().then(h=>{h&&m(h)})},children:s("Browse")})]}),n.jsxs(PC,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(bx,{children:s("No matching projects found")}),n.jsx(yx,{children:h=>n.jsxs(vx,{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 wG({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=Ed(xe(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(""),[y,j]=f.useState(String(Wo.maxHops)),[w,b]=f.useState(String(Wo.maxTurnsPerBot)),[N,C]=f.useState(!1),[E,T]=f.useState(null);f.useEffect(()=>{e&&(l(""),u([]),m(null),p(i.length>0?"project":"chat-home"),x(i[0]?.id??""),j(String(Wo.maxHops)),b(String(Wo.maxTurnsPerBot)),C(!1),T(null))},[e]);const k=(A,D)=>{const M=D?[...c,A]:c.filter(H=>H!==A);u(M),M.includes(d??"")?!d&&M.length&&m(M[0]):m(M[0]??null)},L=c.length>=2&&d!==null&&(h==="chat-home"||!!g),F=async()=>{if(L){C(!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(y))||Wo.maxHops,maxTurnsPerBot:Math.round(Number(w))||Wo.maxTurnsPerBot}});if(!A.ok){T(cs(A.error,s));return}const D=ie.getState();D.upsertChat(A.chat),D.setView({kind:"chat",chatId:A.chat.id}),D.loadLatest(A.chat.id),t(!1)}finally{C(!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(on,{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(Lt,{children:s("Group name")}),n.jsx(Vt,{value:a,onChange:A=>l(A.target.value)})]}),n.jsxs("div",{children:[n.jsx(Lt,{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 D=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(Bo,{checked:D,onCheckedChange:M=>k(A.id,M===!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})]}),D&&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(Lt,{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(WC,{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(Qa,{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(Lt,{children:s("@ relay limit (per message of yours)")}),n.jsx(Vt,{type:"number",min:1,max:20,value:y,onChange:A=>j(A.target.value)})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:s("Max replies per member")}),n.jsx(Vt,{type:"number",min:1,max:10,value:w,onChange:A=>b(A.target.value)})]})]}),E&&n.jsx("p",{className:"text-destructive text-sm",children:E})]}),n.jsxs(ts,{children:[n.jsx(he,{variant:"outline",size:"sm",onClick:()=>t(!1),children:s("Cancel")}),n.jsxs(he,{size:"sm",disabled:!L||N,onClick:()=>{F()},children:[N&&n.jsx(Bt,{className:"animate-spin"}),s("Create")]})]})]})})}const Gb={skillIds:[],mcpServerIds:[]};function jG({open:e,onOpenChange:t,seedTemplateId:s,onCreated:r}){const{t:o,locale:i}=z(),a=ie(ne=>ne.bots),l=pj(),c=Ed(xe(ne=>ne.projects)),u=f.useRef(null),[d,m]=f.useState(null),[h,p]=f.useState("chat-home"),[g,x]=f.useState(""),[y,j]=f.useState(!1),[w,b]=f.useState(null),[N,C]=f.useState({}),[E,T]=f.useState(null),[k,L]=f.useState(!1);f.useEffect(()=>{if(!e)return;m(null),x(c[0]?.id??""),j(!1),b(null),C({}),T(null);const ne=l.find(Y=>Y.id===s);ne&&F({team:dg(ne.data)})},[e]);const F=async ne=>{j(!0),b(null);try{const Y=await window.electronAPI.bots.previewTeam(ne);if(!Y.ok){b(fE(Y.error,o));return}m({team:Y.team,renamed:Y.renamed,picked:Y.team.members.map(pe=>pe.key)}),C({}),T(null),p(Y.team.workspace==="project"&&c.length>0?"project":"chat-home")}finally{j(!1)}},A=ne=>m(Y=>Y&&{...Y,team:ne(Y.team)}),D=(ne,Y)=>A(pe=>({...pe,members:pe.members.map(ge=>ge.key===ne?{...ge,...Y}:ge)})),M=f.useMemo(()=>d?mE(d.team,d.picked):null,[d]),H=f.useMemo(()=>{const ne=new Map;if(!M)return ne;const Y=[...a,...M.members.map(pe=>({id:`team:${pe.key}`,name:pe.name}))];for(const pe of M.members){const ge=Nh(pe.name,Y,o,`team:${pe.key}`);ge&&ne.set(pe.key,ge)}return ne},[M,a,o]),G=M!==null&&H.size===0&&(h==="chat-home"||!!g)&&!y&&!k,U=ne=>N[ne]??Gb,J=(ne,Y)=>C(pe=>({...pe,[ne]:{...pe[ne]??Gb,...Y}})),$=async()=>{if(M){L(!0);try{const ne=i==="zh"?"zh":"en",Y=await Promise.all(M.members.map(async B=>{try{const te=await window.electronAPI.bots.suggestAbilities({name:B.name,title:B.title,scope:B.scope,persona:B.persona,language:ne});return{key:B.key,result:te}}catch{return{key:B.key,result:null}}}));let pe=0,ge=0,we;const V={...N},W=new Map;for(const{key:B,result:te}of Y){if(!te?.ok){ge++,te&&!we&&(we=iu(te,o));continue}const{suggestion:Z}=te,ue={};Z.tools&&(ue.tools=Z.tools.value),Z.approvalMode&&(ue.approvalMode=Z.approvalMode.value),Object.keys(ue).length>0&&W.set(B,ue);const fe=Z.skillIds?.value??U(B).skillIds,Ce=Z.mcpServerIds?.value??U(B).mcpServerIds;V[B]={skillIds:[...fe],mcpServerIds:[...Ce]},(fe.length+Ce.length>0||W.has(B))&&pe++}C(V),W.size>0&&A(B=>({...B,members:B.members.map(te=>({...te,...W.get(te.key)}))})),ge>0&&Ie({type:"error",title:o("Suggestions failed for {{n}} members",{n:ge}),...we?{description:we}:{}}),ge<Y.length&&Ie({type:pe>0?"success":"info",title:pe>0?o("Configured abilities for {{n}} members",{n:pe}):o("Current abilities already match the suggestion.")})}finally{L(!1)}}},oe=async()=>{if(!(!M||!G)){j(!0),b(null);try{const ne=Object.fromEntries(M.members.map(ge=>[ge.key,U(ge.key)]).filter(([,ge])=>ge.skillIds.length+ge.mcpServerIds.length>0)),Y=await window.electronAPI.bots.createTeam({team:{...M,title:M.title.trim()},workspace:h==="project"?{kind:"project",projectId:g}:{kind:"chat-home"},...Object.keys(ne).length>0?{assets:ne}:{}});if(!Y.ok){b(ea(Y.error,cs(Y.error,o),o));return}const pe=ie.getState();for(const ge of Y.bots)pe.upsertBot(ge);pe.upsertChat(Y.chat),pe.setView({kind:"chat",chatId:Y.chat.id}),pe.loadLatest(Y.chat.id),t(!1),r?.(Y.chat.id)}finally{j(!1)}}},Ne=i==="zh"?"zh":"en",ce=ne=>d?.team.members.find(Y=>Y.key===ne)?.name??ne;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(on,{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(Lt,{children:o("Group name")}),n.jsx(Vt,{value:d.team.title,onChange:ne=>{const Y=ne.target.value;A(pe=>({...pe,title:Y}))}})]}),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(he,{size:"xs",variant:"outline",disabled:!M||k||y,onClick:()=>{$()},children:[k?n.jsx(Bt,{className:"animate-spin"}):n.jsx(Bs,{}),o("AI auto-configure")]})]}),n.jsx("div",{className:"space-y-1.5",children:d.team.members.map(ne=>{const Y=d.picked.includes(ne.key),pe=ne.key===d.team.bossKey,ge=d.renamed.find(Z=>Z.key===ne.key),we=Y?H.get(ne.key):void 0,V=ne.delegation.canDelegateTo,W=V==="any"?[]:V.filter(Z=>d.picked.includes(Z)),B=U(ne.key),te=Y&&E===ne.key;return n.jsxs("div",{className:_("flex items-start gap-2.5 rounded-lg border px-2.5 py-2",!Y&&"opacity-60"),children:[n.jsx(Bo,{className:"mt-1.5",checked:Y,disabled:pe,onCheckedChange:Z=>m({...d,picked:Z===!0?[...d.picked,ne.key]:d.picked.filter(ue=>ue!==ne.key)})}),n.jsx($t,{bot:ne,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(Vt,{className:"h-7 w-36",value:ne.name,disabled:!Y,onChange:Z=>{const ue=Z.target.value;A(fe=>({...fe,members:fe.members.map(Ce=>Ce.key===ne.key?{...Ce,name:ue}:Ce)}))}}),n.jsx("span",{className:"truncate text-muted-foreground text-xs",children:ne.title}),pe&&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(aj,{className:"h-3 w-3"}),o("Owner")]})]}),n.jsx("p",{className:"text-muted-foreground text-xs",children:ne.scope}),ge&&ge.to===ne.name&&n.jsx("p",{className:"text-warning text-xs",children:o('"{{from}}" is taken, renamed to "{{to}}"',ge)}),we&&n.jsx("p",{className:"text-destructive text-xs",children:we}),n.jsxs("button",{type:"button",disabled:!Y,onClick:()=>T(te?null:ne.key),className:"flex items-start gap-1 text-left text-[11px] text-muted-foreground hover:text-foreground disabled:pointer-events-none",children:[te?n.jsx(Bn,{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:[ne.tools==="readonly"?o("Read-only"):o("All tools")," · ",o(Sa[ne.approvalMode].labelKey),W.length>0&&` · ${o("Delegates to {{names}}",{names:W.map(ce).join(Ne==="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})]})]}),te&&n.jsxs("div",{className:"space-y-3 rounded-lg bg-muted/40 p-2.5",children:[n.jsxs("div",{children:[n.jsx(Lt,{children:o("Tools")}),n.jsx(wh,{value:ne.tools,options:[{value:"all",label:o("All tools")},{value:"readonly",label:o("Read-only")}],onChange:Z=>D(ne.key,{tools:Z})})]}),n.jsxs("div",{children:[n.jsx(Lt,{children:o("Approval mode")}),n.jsx(qw,{value:ne.approvalMode,onChange:Z=>D(ne.key,{approvalMode:Z}),zIndex:Pn.DROPDOWN_IN_MODAL})]}),n.jsx(ug,{label:o("Can delegate to"),value:ne.delegation.canDelegateTo,options:d.picked.filter(Z=>Z!==ne.key),nameOf:ce,onChange:Z=>D(ne.key,{delegation:{...ne.delegation,canDelegateTo:Z}})}),n.jsx(ug,{label:o("Accepts delegation from"),value:ne.delegation.acceptFrom,options:d.picked.filter(Z=>Z!==ne.key),nameOf:ce,onChange:Z=>D(ne.key,{delegation:{...ne.delegation,acceptFrom:Z}})}),n.jsx(aC,{value:B,onChange:Z=>J(ne.key,Z)})]})]})]},ne.key)})}),!M&&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(Lt,{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(WC,{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(Qa,{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:ne,data:Y})=>n.jsxs("button",{type:"button",disabled:y,onClick:()=>{F({team:dg(Y)})},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:Y.members.map(pe=>n.jsx($t,{size:"sm",bot:{name:pe.name,avatar:{color:pe.color}}},pe.key))}),n.jsx("span",{className:"font-medium text-sm",children:Y.title}),n.jsx("span",{className:"text-muted-foreground text-xs",children:Y.summary})]},ne))}),n.jsxs(he,{size:"sm",variant:"outline",disabled:y,onClick:()=>u.current?.click(),children:[n.jsx(vh,{}),o("Import team (JSON)")]}),n.jsx("input",{ref:u,type:"file",accept:".json,application/json",hidden:!0,onChange:ne=>{const Y=ne.target.files?.[0];ne.target.value="",Y&&Y.text().then(pe=>F({text:pe}))}})]}),w&&n.jsx("p",{className:"text-destructive text-sm",children:w})]}),n.jsxs(ts,{children:[d&&n.jsxs(he,{variant:"ghost",size:"sm",className:"mr-auto",onClick:()=>{m(null),b(null)},children:[n.jsx(bi,{}),o("Back")]}),n.jsx(he,{variant:"outline",size:"sm",onClick:()=>t(!1),children:o("Cancel")}),d&&n.jsxs(he,{size:"sm",disabled:!G,onClick:()=>{oe()},children:[y&&n.jsx(Bt,{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 kG({sidebarWidth:e,collapsed:t,onToggleCollapse:s,onResize:r}){const o=Fh()==="mobile",{t:i}=z(),a=ie(M=>M.view),l=ie(M=>M.chats),c=ie(M=>M.bots),u=ie(M=>M.loaded),d=ie(M=>M.setView),[m,h]=f.useState(!1),[p,g]=f.useState(!1),[x,y]=f.useState(!1),[j,w]=f.useState(!1),[b,N]=f.useState(null),C=f.useRef(""),E=Dh(),T=a?.kind==="chat"?l.find(M=>M.id===a.chatId):void 0,k=T?.kind==="group"?l8(l,T):void 0;f.useEffect(()=>{u&&a?.kind==="chat"&&!T&&d(null)},[u,a,T,d]);const L=async M=>{if(M.botId){const H=ie.getState();if(!H.bots.some(U=>U.id===M.botId))throw new Error("Member not found");const G=await H.openDirect(M.botId);if(!G)throw new Error("Could not open chat");fg(G,M.firstMessage.trim()),w(!1);return}w(!1),N(M),C.current=M.firstMessage.trim(),M.templateId?y(!0):h(!0)},F=M=>{C.current&&fg(M,C.current),C.current=""},A=()=>{N(null),C.current="",h(!0)},D=()=>{N(null),C.current="",y(!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(HC,{className:Vr}),n.jsx("button",{type:"button",className:Vr,onClick:()=>w(!0),title:i("Start from a goal"),children:n.jsx(Ai,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:A,title:i("New member"),children:n.jsx(Da,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:()=>g(!0),title:i("New group chat"),children:n.jsx(mi,{className:"h-4 w-4"})}),n.jsx("button",{type:"button",className:Vr,onClick:D,title:i("Create team from template"),children:n.jsx(Vf,{className:"h-4 w-4"})}),(E>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(Ip,{className:"h-4 w-4"}),E>0&&n.jsx(au,{count:E,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(Ds,{className:"h-4 w-4"})}),o&&n.jsx("button",{type:"button",className:Vr,onClick:s,title:i("Expand sidebar"),children:n.jsx(Gk,{className:"h-4 w-4"})})]}):n.jsxs(n.Fragment,{children:[n.jsx(vG,{width:e,onCollapse:o?s:void 0,onNewMember:A,onNewGroup:()=>g(!0),onNewTeam:D,onStartFromGoal:()=>w(!0)}),n.jsx(id,{onResize:r})]}),a?.kind==="inbox"?n.jsx(HU,{}):T?n.jsx(LU,{chat:k??T,group:T},k?.id??T.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(_s,{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(Ub,{onPick:L}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs(he,{size:"sm",variant:c.length===0?"outline":"default",onClick:A,children:[n.jsx(Da,{}),i("New member")]}),c.length>=2&&n.jsxs(he,{size:"sm",variant:"outline",onClick:()=>g(!0),children:[n.jsx(mi,{}),i("New group chat")]}),n.jsxs(he,{size:"sm",variant:"outline",onClick:D,children:[n.jsx(Vf,{}),i("Create team from template")]})]})]}),n.jsx(yG,{open:m,onOpenChange:h,seed:b?.member,onCreated:F}),n.jsx(wG,{open:p,onOpenChange:g}),n.jsx(xG,{}),n.jsx(jG,{open:x,onOpenChange:y,seedTemplateId:b?.templateId,onCreated:F}),n.jsx(cn,{open:j,onOpenChange:w,children:n.jsxs(dn,{className:"max-w-xl",children:[n.jsxs(un,{children:[n.jsx(on,{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:j&&n.jsx(Ub,{onPick:L})})]})})]})}const Wi=[{value:"code",label:"Code",Icon:_o},{value:"bot",label:"Bot",Icon:hE}],NG={ArrowLeft:-1,ArrowUp:-1,ArrowRight:1,ArrowDown:1},SG={duration:.26,ease:[.22,1,.36,1]},CG={duration:.5,ease:[.34,1.36,.64,1]},IG={duration:.18,ease:[.4,0,.2,1]};function TG({className:e}){const{t}=z(),s=Ar(m=>m.mode),r=Ar(m=>m.setMode),o=Dh(),i=Mr(xe(m=>m.keybindings))["toggle-app-mode"],a=i?`${t("Switch between Code and Bot")} (${Gs(i)})`:void 0,l=s4()??!1,c=f.useId(),u=f.useRef({}),d=m=>{const h=NG[m.key];if(!h)return;m.preventDefault();const p=Wi.findIndex(x=>x.value===s),g=Wi[(p+h+Wi.length)%Wi.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:Wi.map(({value:m,label:h,Icon:p})=>{const g=s===m,x=m==="bot"&&s==="code"&&o>0;return n.jsxs("button",{ref:y=>{u.current[m]=y},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(ks.span,{layoutId:c,"aria-hidden":!0,className:"absolute inset-0 rounded-md bg-background shadow-xs",transition:l?{duration:0}:di}),n.jsx(p,{className:"relative h-3.5 w-3.5"}),n.jsx("span",{className:"relative",children:h}),n.jsx(la,{children:x&&n.jsx(ks.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:SG,children:n.jsx(ks.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:IG},transition:CG,children:n.jsx(au,{count:o,className:"block"})})})})]},m)})})}const Wa="enso:open-chat-find";let Um;function UC(e){Um=e,window.dispatchEvent(new Event(Wa))}function Kb(){const e=Um;return Um=void 0,e}function AG({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(Wa,u),()=>window.removeEventListener(Wa,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(lr,{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(Vt,{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(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:r===0,onClick:o,"aria-label":l("Previous match"),children:n.jsx(pE,{className:"h-3.5 w-3.5"})}),n.jsx(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:r===0,onClick:i,"aria-label":l("Next match"),children:n.jsx(Bn,{className:"h-3.5 w-3.5"})}),n.jsx(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:a,children:n.jsx(Zt,{className:"h-3.5 w-3.5"})})]})}function EG({conversationId:e}){const{t}=z(),s=xi(o=>o.back),r=X(o=>s?!!o.conversations[s.from]:!1);return!s||s.to!==e||!r?null:n.jsxs("button",{type:"button","data-enso":"secretary-return",onClick:lV,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(bi,{className:"size-3.5"}),t("Back to secretary")]})}function RG(e){return[...e.running,...e.needsYou,...e.done]}function MG(e,t,s){for(const[r,o]of Object.entries(e)){if(o.secretaryId&&o.secretaryId!==r)continue;const i=RG(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 GC(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 KC(e){return jt(t=>GC(t.states,e)?.takeover??t.secretary.takeovers.find(s=>s.conversationId===e))}function qC(e){const{t}=z();return jt(r=>{const i=(e?GC(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 PG({conversationId:e}={}){const{t}=z(),s=qC(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 DG({conversationId:e}){const{t}=z(),s=KC(e),[r,o]=f.useState(!1),i=qC(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(pB,{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(Zt,{className:"size-3"})})]}):null}const OG="default",LG={"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 _G(e){const t=X(s=>s.conversations[e]?.secretaryOrigin);return jt(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??OG;return s.secretaries.some(o=>o.id===r)?r:null})}function BG({conversationId:e}){const{t}=z(),s=_G(e),r=jt(d=>d.secretaries),o=jt(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=LG[m.error];Ie({type:"error",title:t("Transfer failed"),description:h?t(h):m.error})}}finally{a(!1)}};return n.jsxs(ur,{children:[n.jsx(fr,{"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(u4,{className:"size-3.5"})}),n.jsx(mr,{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 FG(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=Vw(l)?.candidates.find(u=>u.typeKey===e);a&&i(c?.displayName)}).catch(()=>{}),()=>{a=!1}},[e,s,r]),!!s)return r??o??t("Member")}function zG(e,t){return e?null:t?"empty":"hydrating"}function $G(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 VG(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;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:rh(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:xE(s)}}function HG(){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 WG(){const e=HG(),t=e[0];return t?n.jsx(UG,{request:t,total:e.length},t.id):null}function UG({request:e,total:t}){const{t:s}=z(),[r,o]=f.useState(""),[i,a]=f.useState(!1),l=zp(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(gE,{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($p,{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 GG(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 KG={conversationId:void 0,historyBaseIndex:0,seen:null};function qG(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=GG(t.timeline),l=i!==null&&[...a].some(c=>!i.has(c));return{baseline:{conversationId:s,historyBaseIndex:r,seen:a},added:l}}function YG(e,t){const s=xe(a=>a.openChangesOnFileEdit),r=X(a=>vE((t?a.conversations[t]?.messages:void 0)??[])),o=X(a=>(t?a.conversations[t]?.historyBaseIndex:void 0)??0),i=f.useRef(KG);f.useEffect(()=>{const a=qG(i.current,{conversationId:t,historyBaseIndex:o,authoritative:r,timeline:e});i.current=a.baseline,a.added&&s&&Iw()},[r,t,s,o,e])}function Ui(e,t){const s=e.trim().toLowerCase();return s?t.some(r=>r?.toLowerCase().includes(s)):!0}function XG(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}const QG=[],JG=[],ZG=typeof window<"u"&&!!window.electronAPI?.remote;function YC({conversationId:e,cwd:t,emptyTitle:s,onSuggestion:r,timelineRef:o,peek:i=!1,readOnly:a=!1}){const l=X(Z=>Z.conversations[e]?.projectId),c=xe(Z=>Z.projects.some(ue=>ue.id===l&&ue.kind==="secretary")),u=jt(Z=>c?Z.secretaries.find(ue=>ue.projectId===l)?.id??null:null),d=jt(Z=>u?(Z.states[u]??(Z.focusedId===u?Z.secretary:null))?.profile??null:null),m=f.useMemo(()=>{if(!u||!d)return null;const Z=d.avatar.imageVersion;return{name:d.name.trim()||"·",color:d.avatar.color,...Z?{image:Ka(Z,d.avatar.imageHash,u)}:{}}},[u,d]),h=X(Z=>Z.conversations[e]?.messages??QG),p=X(Z=>Z.conversations[e]?.customEntries??JG),g=X(Z=>Z.conversations[e]?.status==="running"),x=X(Z=>Z.conversations[e]?.compaction),y=X(Z=>Z.conversations[e]?.compactionNoticeAt),j=X(Z=>Z.conversations[e]?.occupancy?.compactionTokensAfter),w=X(Z=>Z.conversations[e]?.historyBaseIndex??0),b=X(Z=>Z.conversations[e]?.toolOutputs),N=X(Z=>Z.conversations[e]?.toolStartedAt),C=X(Z=>Z.conversations[e]?.pendingApprovals),E=X(Z=>Z.conversations[e]?.runStartedAt),T=X(Z=>Z.conversations[e]?.lastOutputAt),k=X(Z=>Z.conversations[e]?.error),L=X(Z=>Z.conversations[e]?.started===!0),F=X(Z=>Z.conversations[e]?.sessionFile),A=X(Z=>Z.conversations[e]?.status),D=X(Z=>Z.conversations[e]?.spawning===!0),M=X(Z=>Z.conversations[e]?.historyLoadAttempted),H=X(Z=>!!Z.conversations[e]?.historyLoading),G=X(Z=>Z.conversations[e]?.syncStalled===!0),U=X(Z=>Z.conversations[e]?.interrupted),J=f.useRef({conversationId:"",items:[]}),$=f.useMemo(()=>{J.current.conversationId!==e&&(J.current={conversationId:e,items:[]});const ue=bE(J.current.items,h,g,w)??Ih(h,g,p,t,{compaction:x,compactionNoticeAt:y,compactionTokensAfter:j,historyBaseIndex:w,toolOutputs:b,toolStartedAt:N,pendingApprovals:C,secretarySession:c,interrupted:U});return J.current.items=ue,ue},[x,y,j,e,t,p,w,U,h,C,g,c,b,N]);YG($,i?void 0:e);const oe=yE({started:L,sessionFile:F,messages:h,spawning:D,status:A,historyLoadAttempted:M,historyLoading:H,syncStalled:G}),[Ne,ce]=f.useState(!1),[ne,Y]=f.useState(""),[pe,ge]=f.useState(0),we=f.useMemo(()=>Ne?XG($,ne):[],[Ne,ne,$]);f.useEffect(()=>{if(i)return;const Z=()=>{const ue=Kb();ce(!0),ue&&(Y(ue),ge(0))};return window.addEventListener(Wa,Z),()=>window.removeEventListener(Wa,Z)},[i]),f.useEffect(()=>{if(i)return;const Z=Kb();if(ge(0),Z){Y(Z),ce(!0);return}e&&(Y(""),ce(!1))},[e,i]),f.useEffect(()=>{if(!Ne||we.length===0)return;const Z=Math.min(pe,we.length-1);o.current?.scrollToKey(we[Z].key)},[Ne,pe,we,o]);const V=f.useCallback(Z=>{we.length!==0&&ge(ue=>(ue+Z+we.length)%we.length)},[we.length]);f.useEffect(()=>{if(!Ne)return;const Z=ue=>{if(ue.key==="Escape"){ue.preventDefault(),ce(!1);return}const fe=Pc(ue);fe==="mod+g"?(ue.preventDefault(),V(1)):fe==="mod+shift+g"&&(ue.preventDefault(),V(-1))};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[Ne,V]);const W=f.useMemo(()=>(wE(),l?{conversationId:e,projectId:l,...t?{cwd:t}:{}}:null),[e,t,l]),B=f.useRef(null),te=f.useCallback(()=>{const Z=o.current?.getScroller();B.current=Z?{height:Z.scrollHeight,top:Z.scrollTop}:null,X.getState().loadOlderHistory(e)},[e,o]);return f.useLayoutEffect(()=>{const Z=o.current?.getScroller(),ue=B.current;!Z||!ue||(B.current=null,Z.scrollTop=ue.top+(Z.scrollHeight-ue.height))},[w]),n.jsxs(gj.Provider,{value:W,children:[Ne&&n.jsx(AG,{query:ne,onQueryChange:Z=>{Y(Z),ge(0)},current:we.length===0?0:Math.min(pe,we.length-1)+1,total:we.length,onPrev:()=>V(-1),onNext:()=>V(1),onClose:()=>{ce(!1),Y("")}}),n.jsx(lx,{virtualize:!ZG,ref:o,items:$,busy:oe!==null,loading:oe==="loading",running:g,runStartedAt:E,lastOutputAt:T,error:jE(h,k),emptyTitle:s,onSuggestion:r,onRetryResume:!a&&!L&&F&&A==="failed"?()=>{X.getState().resumeConversation(e)}:void 0,onRetrySync:!a&&G&&!g?()=>X.getState().retrySessionSync(e):void 0,historyLoading:H,hasOlder:w>0,olderCursor:w,onStartReached:w>0?te:void 0,searchQuery:Ne?ne:"",activeHit:Ne?we[pe]??null:null,secretarySession:c,...m?{secretaryFace:m}:{}},e)]})}const eK=/-([0-9a-f]{8})$/i;function qb(e){const t=e.title?.trim();return t||e.name.replace(eK,"").trim()||e.name}function tK({parentId:e,coworkerIds:t}){const{t:s,locale:r}=z(),o=xe(j=>j.agentTypes),[i,a]=f.useState([]),[l,c]=f.useState(!1),[u,d]=f.useState(null),m=f.useRef(0),h=t.join("\0"),p=X(j=>j.pendingChildRun),g=f.useCallback(()=>{const j=++m.current;return window.electronAPI.agent.listChildRuns(e).then(w=>{j===m.current&&a(w.ok?w.items:[])})},[e]);f.useEffect(()=>{g()},[g,h]);const x=f.useCallback(j=>{const w=u?.childId;return w?window.electronAPI.agent.readChildRun(e,w,j):Promise.resolve({ok:!1,code:"not-found",error:"No child run."})},[e,u?.childId]),y=j=>{if(j.available){if(c(!1),j.live&&t.includes(j.childId)){X.getState().selectTab(e,j.childId);return}d(j)}};return f.useEffect(()=>{if(!p||p.parentId!==e)return;const j=i.find(w=>w.childId===p.childId);if(j&&(X.setState({pendingChildRun:null}),!!j.available)){if(c(!1),j.live&&t.includes(j.childId)){X.getState().selectTab(e,j.childId);return}d(j)}},[p,i,e,t]),n.jsxs(n.Fragment,{children:[i.length>0&&n.jsxs(Rs,{open:l,onOpenChange:j=>{c(j),j&&g()},children:[n.jsxs(Ms,{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(Ps,{align:"end",className:"w-96 [&_[data-slot=popover-viewport]]:p-1",children:n.jsx("ul",{className:"flex flex-col",children:i.map(j=>{const w=qb(j);return n.jsx("li",{children:n.jsxs("button",{type:"button",disabled:!j.available,title:w,className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm",j.available?"hover:bg-muted":"cursor-default text-muted-foreground opacity-40"),onClick:()=>y(j),children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:w}),j.agentType&&n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:vj(j.agentType,o)}),n.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:Mo(j.startedAt,r)}),j.live&&n.jsx(cl,{tone:"running",size:"sm",title:s("Running")})]})},j.childId)})})})]}),n.jsx(hx,{conversationId:u?.childId??null,title:u?qb(u):"",read:x,botSession:!1,running:u?.live===!0,onClose:()=>d(null)})]})}const nK=[{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"}],sK={"/goal":nK};function rK(e,t){if(!e)return null;const s=t.trimStart();return s?s.search(/\s/)>=0?null:s:""}function oK(e,t){if(!e)return[];const s=sK[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 gf=new Set;let Yb=!1;function $l(e,t){t?gf.add(e):gf.delete(e);const s=gf.size>0;s!==Yb&&(Yb=s,window.electronAPI?.updater?.reportUnsentDraft?.(s))}function iK(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 XC=[];const Gm=new Set;function Xb(e){XC=e;for(const t of Gm)t()}function aK(e){return Gm.add(e),()=>Gm.delete(e)}const Qb=()=>XC,lK={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 cK({sessionId:e}){const t=f.useSyncExternalStore(aK,Qb,Qb);return t.length===0?null:n.jsx(n.Fragment,{children:t.map(s=>{const r=s.command?bj().find(a=>a.pluginId===s.pluginId&&a.id===s.command):void 0,o=_("shrink-0 truncate px-1 text-[11px]",lK[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:()=>{zh(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 QC=50,dK=64,uK=120,fK=32*1024,mK=120,Vl=[];function Jb(e){return/(?:^|\s)#([^\s#]*)$/.exec(e)?.[1]??null}function hK(e,t,s){if(!Array.isArray(s))return[];const r=[];for(const o of s){if(r.length>=QC)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,dK),...typeof l=="string"&&l?{detail:l.slice(0,uK)}:{}}})}return r}function pK(e){const t=typeof e=="string"?e:typeof e=="object"&&e!==null?e.text:null;return typeof t=="string"&&t.length<=fK?t:null}let JC=[];const Km=new Set;function Zb(e){JC=e;for(const t of Km)t()}function xK(e){return Km.add(e),()=>Km.delete(e)}const ey=()=>JC;function gK(e,t){const s=f.useSyncExternalStore(xK,ey,ey),[r,o]=f.useState(Vl);return f.useEffect(()=>{if(e===null||s.length===0){o(Vl);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?hK(l,c,u.value):Vl})).then(l=>{i||o(l.flat().slice(0,QC))})},mK);return()=>{i=!0,clearTimeout(a)}},[e,s,t]),e===null?Vl:r}async function vK(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?pK(s.value):null}const jc="composer-drop",ZC="pinned-drop",wx="project-group:__ungrouped__",qm="project:",Ym="project-group:",kc="selector-group:",Xm="pinned-chat:",e2=e=>`${qm}${e}`,t2=e=>`${Ym}${e}`,jx=e=>`${kc}${e}`,bK=e=>`chat:${e}`,n2=e=>`${Xm}${e}`,yK=e=>`active-chat:${e}`;function wK(e){return e.split(`
68
- `)[0].trim()||"Untitled chat"}function ty(e){if(e===wx||e===`${kc}__ungrouped__`)return null;if(e.startsWith(Ym)){const t=e.slice(Ym.length);return t==="__all__"?void 0:t}if(e.startsWith(kc)){const t=e.slice(kc.length);return t==="__all__"?void 0:t}}function jK(e,t,s,r){if(!t)return null;if(e.type==="project-group"){const o=ty(t);return!o||o===e.groupId?null:{kind:"reorder-groups",activeId:e.groupId,overId:o}}if(e.type==="project"){if(t===jc)return{kind:"insert-file-mention",path:e.path,label:e.name};const o=ty(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(qm)){const i=t.slice(qm.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===jc?{kind:"insert-file-mention",path:e.relativePath,label:e.name}:null;if(t===jc)return!e.sessionFile||e.conversationId===s?null:{kind:"insert-chat-mention",conversationId:e.conversationId,label:wK(e.title),sessionFile:e.sessionFile};if(t===ZC)return e.pinned?null:{kind:"pin-conversation",conversationId:e.conversationId};if(t.startsWith(Xm)){const o=t.slice(Xm.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 ny=e=>e.startsWith("/skill:");function kK(e,t){return!ny(t)||!e.every(ny)?[t]:e.includes(t)?[...e]:[...e,t]}function NK(e){const t=Rw(e);if(t.names.length>0)return{slashes:t.names.map(r=>`/skill:${r}`),rest:t.rest};const s=cd(e);return{slashes:s.slash?[s.slash]:[],rest:s.rest}}function SK(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?[{type:"text",text:`${r?`
69
-
70
- `:""}${t.text}`}]:[]],images:[...e.images,...t.images??[]]};const o=NK(t.text??"");return{slashes:o.slashes,segments:o.rest?[{type:"text",text:o.rest}]:[],images:[...s?e.images:[],...t.images??[]]}}const CK={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>'},IK='<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>',TK={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 vf(e){const t=document.createElement("span");t.contentEditable="false",t.dataset.mentionKind=e.type,e.type==="file"?(t.dataset.path=e.path,e.label&&(t.dataset.label=e.label),t.title=e.path):e.type==="chat"?(t.dataset.label=e.label,t.dataset.sessionFile=e.sessionFile,e.conversationId&&(t.dataset.conversationId=e.conversationId)):(t.dataset.id=e.id,t.dataset.label=e.label,t.dataset.path=e.path,t.dataset.text=e.text,t.dataset.imageId=e.imageId,t.title=`${e.path}${e.text?` · ${e.text}`:""}`),t.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",TK[e.type]);const s=document.createElement("span");s.className="shrink-0 inline-flex",s.innerHTML=e.type==="file"&&/[\\/]$/.test(e.path)?IK:CK[e.type],t.appendChild(s);const r=document.createElement("span");return r.className="truncate",r.textContent=e.type==="file"?e.label??Gd(e.path):e.label,t.appendChild(r),t}function s2(e){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 bf(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=s2(o);a&&t.push(a);return}if(o.tagName==="BR"){s(`
71
- `);return}(o.tagName==="DIV"||o.tagName==="P")&&t.length>0&&s(`
72
- `);for(const a of o.childNodes)r(a)};for(const o of e.childNodes)r(o);return t}function yf(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 AK(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 Hl(e){return e instanceof HTMLElement&&!!e.dataset.mentionKind}function Zi(e){return e instanceof Text&&!/[^\s\u00a0]/.test(e.textContent??"")}function EK(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(;Zi(d);)d=d.previousSibling;return Hl(d)?d:null}if(/[^\s\u00a0]/.test(c.slice(o)))return null;let u=r.nextSibling;for(;Zi(u);)u=u.nextSibling;return Hl(u)?u:null}const i=r.childNodes;if(t==="before"){let c=o-1;for(;c>=0&&Zi(i[c]);)c-=1;const u=c>=0?i[c]:null;return Hl(u)?u:null}let a=o;for(;a<i.length&&Zi(i[a]);)a+=1;const l=i[a];return Hl(l)?l:null}function RK(e,t){const s=e.nextSibling;Zi(s)&&s.remove();const r=e.previousSibling;if(e.remove(),r){r2(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 r2(e){const t=window.getSelection();if(!t)return;const s=document.createRange();s.setStartAfter(e),s.collapse(!0),t.removeAllRanges(),t.addRange(s)}const MK=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 p=f.useRef(null),g=f.useRef(null);f.useEffect(()=>{const w=()=>{const b=p.current;if(!b||document.activeElement!==b)return;const N=window.getSelection();if(!N||N.rangeCount===0||!N.isCollapsed)return;const C=N.anchorNode;if(C&&(C===b||b.contains(C))){const k=AK(b,N);k?(N.removeAllRanges(),N.addRange(k)):C.nodeType===Node.TEXT_NODE&&(g.current={node:C,offset:N.anchorOffset});return}const E=g.current,T=document.createRange();E?.node.isConnected&&b.contains(E.node)?(T.setStart(E.node,Math.min(E.offset,E.node.length)),T.collapse(!0)):(T.selectNodeContents(b),T.collapse(!0)),N.removeAllRanges(),N.addRange(T)};return document.addEventListener("selectionchange",w),()=>document.removeEventListener("selectionchange",w)},[]);const x=f.useCallback(()=>{const w=p.current;if(!w)return;const b=bf(w),N=b.map(A=>A.type==="text"?A.text:"").join(""),C=b.some(A=>A.type!=="text");let E=null,T=null,k=null,L=null;const F=yf(w);if(F){const A=F.node.textContent?.slice(0,F.offset)??"";E=sv(A,A.length),E===null&&(k=Vm(A,A.length)),E===null&&k===null&&(L=Jb(A)),E===null&&F.node===w.firstChild&&/^\/[^\s]*$/.test(A)&&(T=A.slice(1))}o({plainText:N,hasMentions:C,segments:b,mentionQuery:E,slashQuery:T,skillQuery:k,pluginQuery:L})},[o]),y=f.useCallback(w=>{const b=p.current;if(!b)return null;const N=yf(b);if(!N)return null;const C=N.node.textContent?.slice(0,N.offset)??"";if(w==="#"){const E=Jb(C);return E===null?null:{node:N.node,start:C.length-E.length-1,end:N.offset}}if(w==="@"||w==="$"){const E=w==="@"?sv(C,C.length):Vm(C,C.length);return E===null?null:{node:N.node,start:C.length-E.length-1,end:N.offset}}return N.node!==b.firstChild||!/^\/[^\s]*$/.test(C)?null:{node:N.node,start:0,end:N.offset}},[]),j=f.useCallback((w,b)=>{const N=p.current;if(!N)return;N.focus();const C=document.createRange(),E=b?y("@"):null;if(E)C.setStart(E.node,E.start),C.setEnd(E.node,E.end),C.deleteContents();else{const L=yf(N);L?(C.setStart(L.node,L.offset),C.collapse(!0)):(C.selectNodeContents(N),C.collapse(!1))}const T=w();C.insertNode(T);const k=document.createTextNode(" ");T.parentNode?.insertBefore(k,T.nextSibling),r2(k),x()},[y,x]);return f.useImperativeHandle(h,()=>({focus:()=>p.current?.focus(),isEmpty:()=>{const w=p.current;return w?!bf(w).some(N=>N.type!=="text"||N.text.trim().length>0):!0},getSegments:()=>p.current?bf(p.current):[],setSegments:w=>{const b=p.current;if(b){b.textContent="";for(const N of w)N.type==="text"?b.appendChild(document.createTextNode(N.text)):b.appendChild(vf(N));x()}},clear:()=>{const w=p.current;w&&(w.textContent="",x())},insertMention:w=>{const b=w.kind==="file"?{type:"file",path:w.relativePath}:w.kind==="chat"?{type:"chat",label:w.label,sessionFile:w.sessionFile,conversationId:w.id}:{type:"ui-element",id:w.id,label:w.label,path:w.path,text:w.text,imageId:w.imageId};j(()=>vf(b),w.kind!=="ui-element")},consumeToken:w=>{const b=y(w);if(!b)return;const N=document.createRange();N.setStart(b.node,b.start),N.setEnd(b.node,b.end),N.deleteContents(),x()},insertFileChip:(w,b)=>{j(()=>vf({type:"file",path:w,...b?{label:b}:{}}),!1)},insertText:w=>{j(()=>document.createTextNode(w),!1)},getMentionAnchorRect:()=>{const w=y("@");if(!w)return null;const b=document.createRange();return b.setStart(w.node,w.start),b.setEnd(w.node,Math.min(w.start+1,w.node.length)),b.getBoundingClientRect()}}),[y,x,j]),n.jsx("div",{ref:p,contentEditable:!s,role:m?.role??"textbox","aria-placeholder":t,"data-placeholder":t,...m,onInput:x,onKeyDown:w=>{if(!w.nativeEvent.isComposing&&(w.key==="Backspace"||w.key==="Delete")){const b=p.current,N=b&&EK(b,w.key==="Backspace"?"before":"after");if(N&&b){w.preventDefault(),RK(N,b),x();return}}i(w)},onClick:w=>{if(!d)return;const b=w.target;if(!(b instanceof Element))return;const N=b.closest("[data-mention-kind]");if(!(N instanceof HTMLElement)||!p.current?.contains(N))return;const C=s2(N);C&&d(C)},onKeyUp:w=>{w.key!=="Escape"&&x()},onMouseUp:x,onPaste:w=>{if(w.clipboardData.files.length>0){a(w);return}w.preventDefault();const b=w.clipboardData.getData("text/plain");b&&(l?.(b)||document.execCommand("insertText",!1,b))},onCompositionStart:c,onCompositionEnd:()=>{u(),x()},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)})}),PK=/[\\/]/;function DK(e){return e.split(PK).filter(t=>t.length>0)}function OK(e){const t=new Map,s=e.map(DK),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 LK({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=wi(),g=f.useMemo(()=>XS(e,t),[e,t]),x=f.useMemo(()=>OK(e.files.map(A=>A.relativePath)),[e.files]),y=f.useRef(new Map),j=f.useRef(new Map),w=g[0]?.type==="folder";if(f.useEffect(()=>{y.current.get(s)?.scrollIntoView({block:"nearest"})},[s]),f.useEffect(()=>{o&&j.current.get(i)?.scrollIntoView({block:"nearest"})},[o,i]),g.length===0)return null;const b={agents:h("Agents"),members:h("Members"),chats:h("Chats")},N={agents:_s,members:mi,chats:Or},C=o?e[o]:[];let E=0;const T=()=>C.map((A,D)=>n.jsx(sy,{ref:M=>{M?j.current.set(D,M):j.current.delete(D)},id:`${u}-sub-${D}`,candidate:A,active:D===i,onHover:()=>l(D),onSelect:()=>c(A)},`sub:${A.id}`)),k=!!(p&&o&&C.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(kE,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 font-medium",children:b[A]})]}),T()]}),F=(A,D)=>{const M=e[A];if(M.length===0)return null;const H=A==="files"?h("Files"):b[A];return n.jsxs("div",{role:"group","aria-label":H,children:[n.jsx("p",{className:_("px-2 pb-1 text-[10px] font-medium tracking-wide text-muted-foreground uppercase",D?"pt-2":"pt-1.5"),children:H}),M.map(G=>{const U=E++;return n.jsx(sy,{ref:J=>{J?y.current.set(U,J):y.current.delete(U)},id:`${u}-option-${U}`,candidate:G,active:U===s,pathLabel:G.kind==="file"?x.get(G.relativePath):void 0,onHover:()=>{r(U),w&&a(null)},onSelect:()=>c(G)},`${A}:${G.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 D=E++,M=N[A.id];return n.jsxs("button",{ref:H=>{H?y.current.set(D,H):y.current.delete(D)},id:`${u}-option-${D}`,type:"button",role:"option","aria-selected":s===D,onClick:()=>{r(D),a(A.id),l(0)},onMouseMove:()=>{r(D),!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===D&&"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(M,{className:"h-3.5 w-3.5 text-muted-foreground"})}),n.jsx("span",{className:"min-w-0 flex-1 font-medium",children:b[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&&C.length>0&&n.jsx("div",{role:"listbox","aria-label":b[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:T()})]})}function sy({ref:e,id:t,candidate:s,active:r,pathLabel:o,onHover:i,onSelect:a}){const{t:l}=z(),c=_K(s),u=s.kind==="agent-type"?s.source==="bot"?mi:_s:s.kind==="chat"?Or:c?Wd:Fo;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(fi,{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(fi,{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 _K(e){return e.kind==="file"&&/[\\/]$/.test(e.relativePath)}function BK(e,t){return e.filter(s=>s!==t)}const ry=new Map,FK=e=>e.images.length>0||e.segments.some(t=>t.type!=="text"||t.text.trim()!==""),zK=()=>!!window.electronAPI?.remote&&window.matchMedia?.("(pointer: coarse)").matches===!0;function $K({cwd:e,commands:t,running:s,busy:r,focusKey:o,pluginPresetId:i=null,autoFocus:a=!window.electronAPI?.remote,enterToSend:l=!zK(),toolbar:c,locked:u=!1,injectedDraft:d,injectedImages:m,injectedDraftAppend:h,onDraftConsumed:p,chatCandidates:g,onActivate:x,onSend:y,onAbort:j,queuedCount:w=0,onSteerQueued:b,isolated:N=!1,placeholder:C,planMode:E=!1,savePastedText:T}){const{t:k}=z(),L=wi(),F=xe(le=>le.keybindings),A=xe(le=>le.privacyMasking),D=Mr(F)["send-message"],M=f.useId(),[H,G]=f.useState([]),[U,J]=f.useState([]),[$,oe]=f.useState(),Ne=f.useRef(o),[ce,ne]=f.useState(!1),{setNodeRef:Y,isOver:pe}=sl({id:N?`isolated-composer:${o??"side"}`:jc,disabled:N}),[ge,we]=f.useState(null),[V,W]=f.useState(null),B=f.useRef(new Set),te=f.useRef(y);te.current=y;const Z=f.useRef(A);Z.current=A,f.useEffect(()=>{if(N)return;const le=sF(lt=>ue.current?.insertMention(lt)),ke=oF(lt=>ue.current?.insertText(lt)),Le=rF(()=>ue.current?.focus()),Be=lF((lt,$e)=>{$e&&G(nt=>[...nt,{...$e,id:lt.imageId}]),ue.current?.insertMention(lt),ue.current?.focus()}),Ze=cF(lt=>{G($e=>[...$e,{data:lt.data,mimeType:lt.mimeType}]),ue.current?.focus()}),ht=iF(lt=>{if(Ee.current)return!1;const $e=Z.current,nt=$e.enabled?wu(lt.text,$e).blocked:[];return nt.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:nt.join(", ")})}),!1):te.current(lt)!==!1});return()=>{le(),ke(),Le(),Be(),Ze(),ht()}},[N,k]);const ue=f.useRef(null),fe=f.useRef(null),Ce=f.useRef(null),de=f.useRef(!1),Ee=f.useRef(u);Ee.current=u,f.useEffect(()=>{if(!(N||!o))return NE({key:o,segments:()=>ue.current?.getSegments()??[],insertText:le=>ue.current?.insertText(le),setText:le=>ue.current?.setSegments(le?[{type:"text",text:le}]:[]),busy:()=>de.current||Ee.current||!ue.current})},[N,o]);const[me,Ve]=f.useState({left:0,flyoutSide:"right"}),[at,Fe]=f.useState(""),[tt,je]=f.useState(!1),Je=f.useRef(Symbol("composer")),rt=at.trim()!==""||tt||H.length>0;f.useEffect(()=>$l(Je.current,rt),[rt]),f.useEffect(()=>()=>$l(Je.current,!1),[]);const[K,Q]=f.useState(null),Ae=QS(e,K,g),pt=f.useMemo(()=>XS(Ae,K??""),[Ae,K]),[Dt,Xe]=f.useState(null),[kt,mn]=f.useState(null),[_e,Nt]=f.useState(null),Ot=gK(_e,o??null),[_t,se]=f.useState(0),[Oe,ot]=f.useState(null),[ct,xt]=f.useState(0),gt=f.useRef(null),Ft=f.useCallback(le=>{(le.plainText.trim()||le.hasMentions)&&x?.(),Fe(le.plainText),je(le.hasMentions);const ke=new Set(le.segments.filter(Be=>Be.type==="ui-element"&&Be.imageId).map(Be=>Be.type==="ui-element"?Be.imageId:"")),Le=[...B.current].filter(Be=>!ke.has(Be));B.current=ke,Le.length>0&&(G(Be=>SE(Be,Le)),we(Be=>Be&&Le.includes(Be.imageId)?null:Be)),Q(Be=>(Be!==le.mentionQuery&&(se(0),ot(null),xt(0)),le.mentionQuery)),Xe(le.slashQuery),mn(le.skillQuery),Nt(le.pluginQuery)},[x]);f.useEffect(()=>{const le=Ne.current;if(le!==o){if(le){const Be={segments:ue.current?.getSegments()??[],images:H,slashes:U,recipient:$};ry.set(le,Be),$l(`draft:${le}`,FK(Be))}const ke=o?ry.get(o):void 0;o&&$l(`draft:${o}`,!1);const Le=o?CE(o):void 0;ue.current?.setSegments(Le?[{type:"text",text:Le}]:ke?.segments??[]),B.current=new Set((ke?.segments??[]).filter(Be=>Be.type==="ui-element"&&Be.imageId).map(Be=>Be.type==="ui-element"?Be.imageId:"")),G(ke?.images??[]),J(ke?.slashes??[]),oe(ke?.recipient),Ne.current=o,Q(null),Xe(null),mn(null),se(0),ot(null),xt(0)}a&&ue.current?.focus()},[o]),f.useEffect(()=>{if(!d&&!m?.length)return;const le=SK({segments:ue.current?.getSegments()??[],images:H,slashes:U},{text:d,images:m},h);J(le.slashes),G(le.images),ue.current?.setSegments(le.segments),p?.(),window.setTimeout(()=>ue.current?.focus(),0)},[d,m,h]);const Ht=U.length===1?U[0]:null,tn=rK(Ht,at.replaceAll("","")),Jt=Q7(t,Dt,kt),Gt=Dt===null&&kt===null&&tn!==null?oK(Ht,tn):[];f.useEffect(()=>{se(0)},[Dt,kt,tn,_e]),f.useEffect(()=>{gt.current?.children[_t]?.scrollIntoView({block:"nearest"})},[_t]);const gn=f.useCallback(le=>{if(le.kind==="agent-type"){ue.current?.consumeToken("@"),oe(le),Q(null);return}ue.current?.insertMention(le),Q(null)},[]),Qn=f.useCallback(le=>{Nt(null),vK(le,o??null).then(ke=>{const Le=ue.current;Le&&(Le.consumeToken("#"),ke&&Le.insertText(ke))})},[o]),bt=K!==null&&pt.length>0?"mention":_e!==null&&Ot.length>0?"plugin":Jt.length>0?"slash":Gt.length>0?"slash-sub":null;f.useLayoutEffect(()=>{if(bt!=="mention")return;const le=fe.current;if(!le)return;const ke=()=>{const Le=le.getBoundingClientRect(),Be=le.querySelector('[data-slot="mention-picker"]'),Ze=Be?.querySelector('[role="listbox"]'),ht=Be?.querySelector('[data-slot="mention-flyout"]'),lt=ue.current?.getMentionAnchorRect(),$e=kB({anchorLeft:lt?lt.left-Le.left:0,containerWidth:Le.width,popupWidth:Ze instanceof HTMLElement?Ze.offsetWidth:280,flyoutWidth:ht instanceof HTMLElement?ht.offsetWidth:252,flyoutGap:4});Ve(nt=>nt.left===$e.left&&nt.flyoutSide===$e.flyoutSide?nt:$e)};return ke(),window.addEventListener("resize",ke),()=>window.removeEventListener("resize",ke)},[K,at,Oe,bt]);const sn=bt==="mention"?pt.length:bt==="plugin"?Ot.length:bt==="slash-sub"?Gt.length:Jt.length,Tn=f.useCallback((le,ke)=>{const Le=[{type:"text",text:le}];if(ue.current?.setSegments(Le),!ke)return;const Be=iv({segments:Le,slashes:U,images:H,recipient:$});y(Be)!==!1&&(ue.current?.clear(),G([]),J([]),oe(void 0),Q(null),Xe(null),mn(null))},[H,y,$,U]),S=f.useCallback(le=>{ue.current?.consumeToken(kt!==null?"$":"/"),Xe(null),mn(null);const ke=IE(le);if(!ke){J(Le=>kK(Le,le));return}zh(ke,N?null:o??null).then(Le=>{Le&&Ie({type:"error",title:k("Plugin command failed"),description:Le})})},[kt,N,o,k]),P=f.useCallback((le=!1)=>{if(bt==="mention"){if(Oe){const Le=Ae[Oe][ct];Le&&gn(Le);return}const ke=pt[_t];ke?.type==="item"&&gn(ke.candidate)}else if(bt==="plugin"){const ke=Ot[_t];ke&&Qn(ke)}else if(bt==="slash"){const ke=Jt[_t];ke&&S(ke.name)}else if(bt==="slash-sub"){const ke=Gt[_t];if(!ke)return;Tn(ke.name,le)}},[_t,ct,Oe,Ae,pt,gn,Qn,Ot,bt,Jt,S,Gt,Tn]),I=at.replaceAll("","").trim(),v=!!(I||U.length>0||H.length>0||tt),R=$!==void 0,ee=r&&!R,re={sessionId:N?null:o??null,draft:at.replaceAll("",""),busy:u,pluginPresetId:i},Se=s&&w>0&&b!==void 0&&l&&!!D,Re=Se&&!v&&!R&&!u,We=f.useMemo(()=>A.enabled&&I?wu(I,A):null,[I,A]),Ge=()=>{if(!v)return;const le=iv({segments:ue.current?.getSegments()??[],slashes:U,images:H,recipient:$}),ke=A.enabled?wu(le.text,A).blocked:[];if(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(", ")})});return}y(le)!==!1&&(ue.current?.clear(),G([]),J([]),oe(void 0),Q(null),Xe(null),mn(null))},St=f.useCallback(le=>{for(const ke of le){if(ke.type.startsWith("image/")){const Ze=new FileReader;Ze.onload=()=>{const ht=Ze.result,lt=ht.slice(ht.indexOf(",")+1);G($e=>[...$e,{data:lt,mimeType:ke.type}])},Ze.readAsDataURL(ke);continue}const Le=window.electronAPI.files.pathForFile(ke),Be=window.electronAPI.remote;if(!Le&&Be){Be.upload(ke).then(Ze=>{Ze&&ue.current?.insertFileChip(Ze)}).catch(()=>{});continue}Le&&ue.current?.insertFileChip(Le)}},[]);f.useEffect(()=>{if(N)return;const le=uF(Le=>{St(Le),ue.current?.focus()}),ke=hF(Le=>{for(const Be of Le)ue.current?.insertFileChip(Be);ue.current?.focus()});return()=>{le(),ke()}},[N,St]);const Qe=le=>{const ke=le.nativeEvent.isComposing||de.current;if(bt){const Be=bt==="mention"?pt[_t]:void 0,Ze=NB({key:le.key,shiftKey:le.shiftKey,isComposing:ke,activeIndex:_t,itemCount:sn,folderOpen:bt==="mention"&&Oe!==null,activeIsFolder:bt==="mention"&&Be?.type==="folder",folderIndex:ct,folderItemCount:Oe?Ae[Oe].length:0});if(Ze.type==="move"){le.preventDefault(),se(Ze.index),ot(null);return}if(Ze.type==="move-folder"){le.preventDefault(),xt(Ze.index);return}if(Ze.type==="open-folder"){le.preventDefault(),Be?.type==="folder"&&ot(Be.id),xt(0);return}if(Ze.type==="close-folder"){le.preventDefault(),ot(null);return}if(Ze.type==="pick"){le.preventDefault(),P(bt==="slash-sub"&&le.key==="Enter");return}if(Ze.type==="close"){le.preventDefault(),Q(null),Xe(null),mn(null),Nt(null),ot(null);return}}if(ke)return;const Le=Pc(le);if(!N&&Le&&Le===Mr(xe.getState().keybindings)["switch-model"]){le.preventDefault(),TE();return}if(le.key==="Backspace"&&U.length>0&&I.length===0&&!tt){le.preventDefault(),J(Be=>Be.slice(0,-1));return}if(le.key==="Backspace"&&$&&ue.current?.isEmpty()&&U.length===0){le.preventDefault(),oe(void 0);return}l&&!bt&&Pc(le,{allowBare:!0})===D&&(le.preventDefault(),Re?b?.():Ge())};return n.jsxs("div",{ref:fe,className:"relative",children:[bt==="mention"&&n.jsx(LK,{id:M,groups:Ae,query:K??"",activeIndex:_t,onActiveIndexChange:se,openFolderId:Oe,folderIndex:ct,onOpenFolderIdChange:ot,onFolderIndexChange:xt,onSelect:gn,left:me.left,flyoutSide:me.flyoutSide}),bt==="plugin"&&n.jsx("div",{ref:gt,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:Ot.map((le,ke)=>n.jsxs("button",{type:"button",role:"option","aria-selected":ke===_t,onMouseDown:Le=>Le.preventDefault(),onClick:()=>Qn(le),onMouseMove:()=>se(ke),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",ke===_t&&"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:le.item.label}),le.item.detail&&n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:le.item.detail})]},le.key))}),(bt==="slash"||bt==="slash-sub")&&n.jsx("div",{ref:gt,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:(bt==="slash"?Jt:Gt).map((le,ke)=>n.jsxs("button",{type:"button",role:"option","aria-selected":ke===_t,onClick:()=>{se(ke),bt==="slash"?S(le.name):Tn(le.name,!1)},onMouseMove:()=>se(ke),className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",ke===_t&&"bg-foreground/10"),children:[n.jsx(qk,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"shrink-0 font-mono font-medium",children:kt!==null?`$${le.name.slice(7)}`:le.name}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:k(le.description)})]},le.name))}),n.jsxs("div",{ref:Y,"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)]",(ce||pe)&&"border-brand/50 bg-brand/5",(R||E)&&"border-primary/35 shadow-primary/5"),onDragOver:le=>{le.dataTransfer.types.includes("Files")&&(le.preventDefault(),ne(!0))},onDragLeave:le=>{le.currentTarget.contains(le.relatedTarget)||ne(!1)},onDrop:le=>{const ke=Array.from(le.dataTransfer.files);ke.length!==0&&(le.preventDefault(),ne(!1),St(ke))},children:[H.filter(le=>!le.id).length>0&&n.jsx("div",{className:"flex flex-wrap gap-2 px-3 pt-3",children:H.filter(le=>!le.id).map((le,ke)=>n.jsxs("div",{className:"group relative",children:[n.jsx("button",{type:"button",onClick:()=>W(le),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:${le.mimeType};base64,${le.data}`,alt:"",className:"h-16 w-16 rounded-md border object-cover"})}),n.jsx("button",{type:"button",onClick:()=>G(Le=>BK(Le,le)),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(Zt,{className:"h-3 w-3"})})]},ke))}),n.jsxs("div",{className:_("flex items-start gap-1.5 px-4",H.length>0?"pt-1.5":"pt-3.5"),children:[$&&n.jsx(EV,{recipient:$,onRemove:()=>oe(void 0)}),U.map(le=>n.jsx(dd,{name:le,className:"mt-0.5 shrink-0",trailing:n.jsx("button",{type:"button",onClick:()=>J(ke=>ke.filter(Le=>Le!==le)),className:"rounded-sm opacity-70 hover:opacity-100","aria-label":k("Remove"),children:n.jsx(Zt,{className:"h-3 w-3"})})},le)),n.jsx(MK,{ref:ue,placeholder:U.length>0?"":u?k("Resolve the pending approval to continue"):R?k("Message the selected Agent…"):Se?k("Press {{key}} to steer the next queued message into this round…",{key:Gs(D)}):C||k(s?"Message will queue until this round finishes…":"Type @ to choose a file or Agent"),disabled:u,onStateChange:Ft,onChipActivate:le=>{le.type==="ui-element"&&we({kind:"ui-element",id:le.id,label:le.label,path:le.path,text:le.text,imageId:le.imageId})},onKeyDown:Qe,onPasteText:le=>!T||!Hw(le)?!1:(T(le).catch(()=>({ok:!1,error:"unavailable"})).then(ke=>{const Le=ue.current;ke.ok?Le?.insertFileChip(ke.path,`${lj} · ${k("{{count}} chars",{count:ke.chars.toLocaleString()})}`):Le?.insertText(le)}),!0),onPaste:le=>{const ke=Array.from(le.clipboardData.files);ke.length!==0&&(le.preventDefault(),St(ke))},onCompositionStart:()=>{de.current=!0},onCompositionEnd:()=>{de.current=!1},ariaProps:{role:"combobox","aria-autocomplete":"list","aria-expanded":bt!==null,"aria-controls":bt==="mention"?M:void 0,"aria-activedescendant":bt==="mention"?Oe?`${M}-sub-${ct}`:`${M}-option-${_t}`:void 0}})]}),R&&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:Ce,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:le=>{St(Array.from(le.target.files??[])),le.target.value=""}}),n.jsx("button",{type:"button",disabled:u,onClick:()=>Ce.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(bh,{className:"h-3.5 w-3.5"})}),n.jsx(mg,{side:"left",...re}),c,!N&&n.jsx(cK,{sessionId:re.sessionId}),n.jsx(mg,{side:"right",...re}),We&&(We.blocked.length>0||We.masked>0)&&n.jsxs("span",{className:_("flex shrink-0 items-center gap-1 text-[11px]",We.blocked.length>0?"text-red-600 dark:text-red-400":"text-sky-600 dark:text-sky-400"),"data-privacy-precheck":!0,children:[We.blocked.length>0?n.jsx(bw,{className:"size-3.5"}):n.jsx(Sd,{className:"size-3.5"}),We.blocked.length>0?k("Will be blocked: {{kinds}}",{kinds:We.blocked.join(", ")}):k("{{count}} will be masked",{count:We.masked})]})]}),ee&&!v?n.jsx(he,{variant:"outline",size:"icon",className:"size-8 shrink-0 rounded-full",onClick:j,"aria-label":k("Stop"),children:n.jsx(T4,{className:"h-4 w-4"})}):n.jsx(he,{size:"icon",className:"size-8 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-35",onClick:Ge,disabled:!v||u,"aria-label":k(R?"Send only to the selected Agent":"Send"),title:R?k("Send only to the selected Agent"):l&&D?`${k("Send")} ${Gs(D)}`:k("Send"),children:n.jsx(Id,{className:"h-4 w-4"})})]})]}),n.jsx(cn,{open:ge!==null,onOpenChange:le=>!le&&we(null),children:n.jsxs(dn,{className:"max-w-md",children:[n.jsx(un,{children:n.jsx(on,{children:ge?.label??k("Selected UI element")})}),n.jsx(In,{className:"space-y-2 text-xs",children:ge&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-muted-foreground break-all",children:ge.path}),ge.text&&n.jsx("p",{children:ge.text}),(()=>{const le=H.find(ke=>ke.id===ge.imageId);return le?n.jsx("img",{src:`data:${le.mimeType};base64,${le.data}`,alt:"",className:"max-h-72 w-full rounded-md border object-contain"}):null})()]})})]})}),n.jsx(cn,{open:V!==null,onOpenChange:le=>!le&&W(null),children:n.jsxs(dn,{className:"max-w-3xl",children:[n.jsx(un,{children:n.jsx(on,{children:k("Preview")})}),n.jsx(In,{children:V&&n.jsx("img",{src:`data:${V.mimeType};base64,${V.data}`,alt:"",className:"max-h-[80vh] w-full rounded-md object-contain"})})]})})]})}function o2({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 VK({parentId:e,displayedId:t,trailing:s}){const{t:r}=z(),o=X(h=>h.conversations[e]?.title??""),i=X(h=>h.conversations[e]?.started===!0),a=X(h=>h.conversations[e]?.reloading===!0),l=X(h=>!!h.conversations[e]?.spawning),c=X(h=>eF(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(yj,{"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(oy,{id:e,label:o||r("New conversation"),className:m(t===e),leading:n.jsx(bm,{className:"h-3 w-3 shrink-0"}),reloadDisabled:a||l,reloading:a,onSelect:()=>X.getState().selectTab(e,void 0)}),c.map(h=>{const p=AE({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(oy,{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($h,{className:"h-3 w-3 shrink-0"}):n.jsx(_s,{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(cl,{tone:p,size:"sm"})}),reloadDisabled:h.reloading||h.spawning,reloading:h.reloading,onSelect:()=>X.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."))&&X.getState().dismissCoworkerFromUI(e,h.id)},children:n.jsx(Zt,{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(Xn,{className:"h-3.5 w-3.5"})})]}),s,u&&n.jsx(HK,{parentId:e,onClose:()=>d(!1)})]})}function oy({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(o2,{title:t,className:"max-w-48 text-xs",onCommit:h=>{X.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(Yt,{onClick:()=>d(!0),children:[n.jsx(bs,{}),c("Rename")]}),n.jsxs(Yt,{disabled:i,onClick:()=>{oS(e,c)},children:[n.jsx(ro,{className:a?"animate-spin":void 0}),c("Reload conversation")]})]})]})}function HK({parentId:e,onClose:t}){const{t:s}=z(),r=xe(x=>x.agentTypes),o=xe(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=[...EE.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 X.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(on,{children:s("Hire coworker")})}),n.jsxs(In,{className:"space-y-4",children:[n.jsxs(Ss,{children:[n.jsx(Cs,{children:s("Name (slug)")}),n.jsx(Vt,{value:i,onChange:x=>a(x.target.value),placeholder:"reviewer",autoFocus:!0})]}),n.jsxs(Ss,{children:[n.jsx(Cs,{children:s("Agent type")}),n.jsxs(Sr,{items:p,value:l,onValueChange:x=>c(x??""),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:p.map(x=>n.jsx(or,{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(he,{variant:"ghost",onClick:t,children:s("Cancel")}),n.jsx(he,{onClick:()=>{g()},disabled:!i.trim(),children:s("Hire")})]})]})})}function WK(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 UK={active:"bg-green-500 animate-pulse",paused:"bg-amber-500",waiting:"bg-amber-500",blocked:"bg-destructive",completed:"bg-blue-500"};function GK({conversationId:e,goal:t}){const{t:s}=z(),r={active:s("working"),paused:s("paused"),waiting:s("waiting"),blocked:s("blocked"),completed:s("completed")};return n.jsxs("div",{className:_("mb-1 flex items-center gap-2",dS),children:[n.jsx(uS,{}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",title:t.note?`${t.text} — ${t.note}`:t.text,children:[t.text,t.note&&n.jsxs("span",{className:"text-muted-foreground",children:[" — ",t.note]})]}),n.jsx("span",{className:_("h-1.5 w-1.5 shrink-0 rounded-full",UK[t.status])}),n.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground tabular-nums",children:[r[t.status],t.status==="active"&&t.autoTurns>0?` · ${t.autoTurns}/25`:""]}),t.status==="active"?n.jsx("button",{type:"button",title:s("Pause goal"),onClick:()=>X.getState().pauseGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Kk,{className:"h-3.5 w-3.5"})}):t.status!=="completed"?n.jsx("button",{type:"button",title:s("Resume goal"),onClick:()=>X.getState().resumeGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Xw,{className:"h-3.5 w-3.5"})}):null,n.jsx("button",{type:"button",title:s("Clear goal"),onClick:()=>X.getState().clearGoal(e),className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-destructive",children:n.jsx(Zt,{className:"h-3.5 w-3.5"})})]})}function KK(e,t){return e.trim().length>0||t>0}function iy(e,t){return e>0?`${e} ${t}`:null}function qK({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=>{KK(i,c.images?.length??0)&&X.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:c.text||"[image]"}),iy(c.images?.length??0,s("attachments"))&&n.jsxs("span",{title:iy(c.images?.length??0,s("attachments"))??void 0,className:"flex shrink-0 items-center gap-0.5 text-muted-foreground",children:[n.jsx(N_,{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(Dn,{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:()=>X.getState().withdrawMessage(e,{kind:"queue",id:c.id}),className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(Pa,{className:"h-3 w-3"})}),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:()=>X.getState().sendQueuedNow(e,c.id),className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(Ud,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",title:s("Interrupt and send now"),onClick:()=>{X.getState().interruptAndSendQueued(e,c.id)},className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:n.jsx(tB,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",title:s("Remove"),onClick:()=>X.getState().removeQueuedMessage(e,c.id),className:"rounded p-0.5 text-muted-foreground hover:text-destructive",children:n.jsx(Zt,{className:"h-3.5 w-3.5"})})]})]},c.id))})}const i2="mb-1 rounded-lg border border-border/60 bg-muted/20 px-2.5 py-2 text-xs";function a2({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(Gn,{text:e.text})})}function YK({conversationId:e,planState:t,approvalMode:s}){const r=wj(t);return r==="awaiting_review"&&t?.pending?n.jsx(XK,{conversationId:e,doc:t.pending,approvalMode:s},t.pending.planId):r==="executing"&&t?.executing?n.jsx(QK,{conversationId:e,doc:t.executing},t.executing.planId):null}function XK({conversationId:e,doc:t,approvalMode:s}){const{t:r}=z(),o=RE(),[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(y,j)=>{g(!0);const w=X.getState();j&&j!==s&&w.setApprovalMode(e,j);const b=await w.respondPlan(e,t.planId,y,y==="revise"?u.trim():void 0);b&&(g(!1),Ie({type:"error",title:r("Plan response failed"),description:b}))};return n.jsxs("div",{className:i2,children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(vi,{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(y=>!y),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(a2,{doc:t}),l&&n.jsx("textarea",{autoFocus:!0,value:u,onChange:y=>d(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&u.trim()&&(y.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(Sa[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(Rs,{open:m,onOpenChange:h,children:[n.jsx(Ms,{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(Bn,{className:"h-3.5 w-3.5"})}),n.jsxs(Ps,{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")}),ME.map(y=>{const j=Sa[y],w=j.icon,b=y==="assistant"&&!o;return n.jsxs("button",{type:"button",disabled:b,onClick:()=>{h(!1),x("approve",y)},className:_("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",y===s?"bg-muted":"hover:bg-muted/60",b&&"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(j.labelKey)}),n.jsx("span",{className:"block text-xs text-muted-foreground",children:r(j.descKey)})]})]},y)})]})]})]})]})]})}function QK({conversationId:e,doc:t}){const{t:s}=z(),[r,o]=f.useState(!1);return n.jsxs("div",{className:_(i2,"py-1.5"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Cp,{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:()=>{X.getState().respondPlan(e,t.planId,"finish")},className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground",children:n.jsx(Zt,{className:"h-3.5 w-3.5"})})]}),r&&n.jsx(a2,{doc:t})]})}function JK({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(vi,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"hidden @min-[28rem]:inline",children:s("Plan")})]})}function ZK({presetId:e,onSelect:t,onModel:s,disabled:r}){const{t:o}=z(),i=xe(m=>m.presets),a=PE(),[l,c]=f.useState(!1),u=[{id:DE,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:OE(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(Dc,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-md:@max-[28rem]:hidden truncate",children:d.name})]}):n.jsxs(Rs,{open:l,onOpenChange:c,children:[n.jsxs(Ms,{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(Dc,{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(Bn,{className:"h-3 w-3 shrink-0"})]}),n.jsx(Ps,{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=LE(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(Dn,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]},m.id)})})]})}const ay=[];function eq({projectId:e,conversationId:t}){const{t:s}=z(),r=xe(h=>h.projects.find(p=>p.id===e)?.trustedProjectCode??ay),o=xe(h=>h.setProjectTrustedCode),[i,a]=f.useState([]),[l,c]=f.useState(!1),[u,d]=f.useState(!1);f.useEffect(()=>{let h=!1;return a(ay),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(Ao,{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(Zt,{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(Ao,{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(`
73
- `),children:m.join(", ")})]}),n.jsx(he,{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(Zt,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})}const tq=70,l2=80,c2={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 d2({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",c2[r.kind],t&&t!==r.kind&&"opacity-25"),style:{width:`${r.width}%`}},r.kind))})}function nq({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>=tq?"bg-warning":"bg-muted-foreground/70"),style:{width:`${e}%`}})})}const sq={system:"System prompt",memory:"Enabled instructions",tools:"Tool definitions",skills:"Enabled skills",files:"Files read",results:"Tool results",chat:"Conversation"};function rq({conversationId:e}){const{t}=z(),s=X(a=>a.conversations[e]?.compaction),r=X(a=>a.conversations[e]?.started),o=X(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:()=>X.getState().compact(e),children:i})}function ly({occupancy:e,conversationId:t,cwd:s,onNavigate:r}){const{t:o}=z(),[i,a]=f.useState(),[l,c]=f.useState(),u=X(x=>!t||Aw(x.conversations,t)<_E);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=cS(e),h=(e.percent??0)>=l2,p=[...m].filter(x=>eb(e.parts,x.kind).length>0).sort((x,y)=>y.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:[$n(e.used),d?` / ${$n(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(d2,{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:$n(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:()=>{X.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:y})=>{const j=e.used>0?Math.round(y/e.used*100):0,w=eb(e.parts,x),b=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?b:void 0,onClick:()=>c(b?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",b&&"rotate-90",w.length===0&&"invisible")}),n.jsx("span",{className:"w-24 shrink-0 truncate text-muted-foreground",children:o(sq[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",c2[x]),style:{width:`${j}%`}})})}),n.jsx("span",{className:"w-10 shrink-0 text-right tabular-nums",children:$n(y)}),n.jsxs("span",{className:"w-8 shrink-0 text-right text-muted-foreground tabular-nums",children:[j,"%"]})]}),b&&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(N=>{const C=kV(N),E=SV(x,N,s),T=k=>{if(k.type==="file"){if(!t)return;BE(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 C?n.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:C.raw,children:C.raw}):n.jsx("span",{className:"min-w-0 flex-1 truncate",children:o(C.key,C.vars)}),E&&(E.type==="settings"||t)?n.jsx("button",{type:"button",onClick:()=>T(E),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(E.type==="file"?"Open":"Settings")}):null,n.jsx("span",{className:_("shrink-0 tabular-nums",E&&"group-hover/item:hidden"),children:$n(N.tokens)})]},`${N.tag}-${N.name}`)})})]},x)})}),t&&n.jsx(rq,{conversationId:t})]})}function oq(e){return e?e.used:null}const kx=90;function u2(e,t){const s=oq(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 iq(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 aq(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:`${$n(a)} · ${l}%`,percent:l,critical:l>=kx}}else s.context={compact:`${$n(i)}·?`,full:`${$n(i)} · ?`}}const r=[],o=[];return t.ttftAvgMs!==void 0&&(r.push(Hn(t.ttftAvgMs)),o.push(e("First token avg {{duration}}",{duration:Hn(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:`↑${$n(t.inputTokens)} ↓${$n(t.outputTokens)}`,full:e("Input {{input}} tok · Output {{output}} tok",{input:$n(t.inputTokens),output:$n(t.outputTokens)})}),t.cacheHitPercent!==void 0&&(s.cache={compact:`${t.cacheHitPercent}%`,full:e("Cache hit {{percent}}%",{percent:t.cacheHitPercent})}),s}function lq(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:wf(t.bytes),full:`${wf(t.bytes)} / ${wf(t.limitBytes)} · ${s}% · ${r}`,critical:t.blocked||s>=kx}}function wf(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 cq({className:e,orientation:t="horizontal",...s}){return n.jsx(FE,{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 dq={minimal:"Minimal",default:"Default",full:"Full"};function uq({icons:e,values:t}){const{t:s}=z(),r=xe(x=>x.statusLineSegments),o=f.useMemo(()=>f2(r),[r]),i=xe(x=>x.toggleStatusLineSegment),a=xe(x=>x.setStatusLineSegments),[l,c]=f.useState(null),[u,d]=f.useState(null),m=jj(o),h=kj.filter(x=>!o.includes(x)),p=()=>{c(null),d(null)},g=()=>{if(l!==null&&u!==null){const x=u>l?u-1:u,y=HE(o,l,x);y!==o&&a([...y])}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:zE.map(x=>n.jsx(he,{variant:m===x?"secondary":"ghost",size:"xs",onClick:()=>a([...$E[x]]),children:s(dq[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,y)=>{const j=e[x],w=t[x];return n.jsxs("div",{children:[l!==null&&u===y&&n.jsx("div",{className:"mx-2 my-0.5 h-0.5 rounded-full bg-primary"}),n.jsxs("div",{onDragOver:b=>{if(l===null)return;b.preventDefault();const N=b.currentTarget.getBoundingClientRect(),C=b.clientY<N.top+N.height/2;d(C?y:y+1)},onDrop:b=>{b.preventDefault(),g()},className:_("flex items-center justify-between gap-3 rounded-md px-2 py-1.5",l===y&&"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:b=>{b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/plain",x),c(y)},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(VE,{className:"h-3.5 w-3.5"})}),n.jsx(j,{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(ja[x])}),n.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:w?.full||s("No data yet")})]})]}),n.jsx(sr,{checked:!0,onCheckedChange:b=>i(x,b)})]})]},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(cq,{className:"my-2"}),h.map(x=>{const y=e[x],j=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(y,{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(ja[x])}),n.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:j?.full||s("No data yet")})]})]}),n.jsx(sr,{checked:!1,onCheckedChange:w=>i(x,w)})]},x)})]})]})]})}const Wl=12,fq=28;function mq(e,t){return t&&jj(e)==="default"?e.filter(s=>s!=="model"):e}function hq({segments:e,widths:t,available:s,triggerWidth:r=0,moreWidth:o=r,mobile:i}){const a=i?[...e]:e.filter((h,p)=>WE(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)*Wl,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(j=>j==="context"),p=j=>e.filter(w=>h.includes(w)||j.includes(w)),g=d(e.filter(j=>!h.includes(j)),j=>u(p(j))+Wl+o<=s),x=p(g);return{inline:x.length>0&&u(x)+Wl+o<=s?x:[],hoverable:[],collapsed:!0}}return{inline:d(a,h=>u(h)+Wl+r<=s),hoverable:[],collapsed:!0}}function pq(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 cy(e,t){return t.critical?"text-destructive":e==="context"&&t.percent!==void 0&&t.percent>=l2?"text-warning":"text-subtle-foreground"}function f2(e){const t=Array.isArray(e)?e:GE,s=new Set(kj),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 ja={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"},xq={minimal:"Min",low:"Low",medium:"Med",high:"High",xhigh:"Extra",max:"Max"},gq={minimal:"Min",low:"Low",medium:"Medium",high:"High",xhigh:"Extra High",max:"Max"},vq={supervised:"Supervised","auto-edits":"Auto-accept edits",full:"Full access",assistant:"Assistant approval"},bq={supervised:XE,"auto-edits":Sd,full:YE,assistant:Bs},yq={model:Hk,context:Cj,requestBody:QE,turns:U_,duration:Hd,sessionTime:da,speed:$h,tokens:_4,cache:G4,cwd:Lr,sessionName:sB,coworkers:mi,usage:vB};function wq(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 jq(e){return e.split(/[\\/]+/).filter(Boolean).at(-1)??e}function Ul(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function dy(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 uy(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 kq(e){return{...yq,approval:bq[e.approvalMode??"full"]}}function Nq(e,t){const[s,r]=f.useState(()=>{if(!e)return;const o=hg.get(e);return o?{key:e,data:o.data}:void 0});return f.useEffect(()=>{if(!e)return;let o=!1;const i=hg.get(e);if(i&&Date.now()-i.fetchedAt<KE){r({key:e,data:i.data});return}return qE(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 Sq(e,t,s,r,o,i,a){const l=uV(s),c={model:void 0,requestBody:lq(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,...aq(e,iq(fV(l),u2(t.occupancy,t.contextWindow)))};if(t.lastModelId){const w=r.find(N=>N.id===t.lastProviderId)?.models.find(N=>N.id===t.lastModelId)?.label??t.lastModelId,b=t.reasoningEnabled?t.thinkingLevel:void 0;c.model={compact:b?`${w} · ${e(xq[b])}`:w,full:b?`${w} · ${e(gq[b])}`:w}}l.steps>0&&(c.turns={compact:`${l.turns}·${l.steps}`,full:e("{{turns}} turns · {{steps}} steps",{turns:l.turns,steps:l.steps})});const u=wq(t,s,i),d=l.llmMs+u.llm,m=l.toolMs+u.tool,h=[],p=[];d>=1e3&&(h.push(Hn(d)),p.push(e("LLM {{duration}}",{duration:Hn(d)}))),m>=1e3&&(h.push(Hn(m)),p.push(e("Tool calls {{duration}}",{duration:Hn(m)}))),h.length>0&&(c.duration={compact:h.join(" · "),full:p.join(" · ")});const g=Math.max(0,i-t.createdAt);c.sessionTime={compact:uy(g),full:uy(g)};const x=o.find(j=>j.id===t.projectId);if(x){const j=jq(x.path);c.cwd={compact:j,full:x.path}}t.title.trim().length>0&&(c.sessionName={compact:Ul(t.title,16),full:Ul(t.title,60)}),c.approval={compact:"",full:e(vq[t.approvalMode??"full"])};const y=t.coworkerIds?.length??0;if(y>0&&(c.coworkers={compact:String(y),full:e("{{count}} coworkers",{count:y})}),a&&!a.error&&a.windows.length>0){const j=a.windows,w=Math.max(...j.map(T=>T.usedPercent)),b=j[0],N=Ul(b.label,24),C=b.resetsAt!==void 0?dy(b.resetsAt-i):void 0,E=j.length>1?` +${j.length-1}`:"";c.usage={compact:`${N} ${Math.round(b.usedPercent)}%${C?`·${C}`:""}${E}`,full:j.map(T=>{const k=T.resetsAt!==void 0?` · ${e("resets in {{remaining}}",{remaining:dy(T.resetsAt-i)})}`:"";return`${Ul(T.label,24)} ${Math.round(T.usedPercent)}%${k}`}).join(" · "),critical:w>=kx}}return c}function Cq({conversationId:e,cwd:t}){const{t:s}=z(),r=X(V=>V.conversations[e]),o=r?.messages??[],i=Rd(),a=xe(V=>V.virtualModels),l=f.useMemo(()=>a.length===0?i:[...i,{id:Nj,models:a.map(V=>({id:V.id,label:V.name}))}],[i,a]),c=xe(V=>V.projects),u=xe(V=>V.statusLineSegments),d=f.useMemo(()=>f2(u),[u]),[m,h]=f.useState(null),[p,g]=f.useState(!1),[x,y]=f.useState(!1),j=wi(),w=f.useRef(null),b=f.useRef(null),[N,C]=f.useState(),E=f.useMemo(()=>{if(d.includes("usage"))return Sj(i,r)?.accountKey},[d,i,r]),[T,k]=f.useState(()=>Date.now()),L=r?.status==="running"&&d.includes("duration"),F=d.includes("sessionTime"),A=d.includes("usage")&&E!==void 0;f.useEffect(()=>{if(!L&&!F&&!A)return;const V=setInterval(()=>k(Date.now()),1e3);return()=>clearInterval(V)},[L,F,A]);const D=Nq(E,T),M=f.useMemo(()=>r?kq(r):null,[r]),H=f.useMemo(()=>r?Sq(s,r,o,l,c,T,D):null,[s,r,o,l,c,T,D]),G=mq(d,j),U=H?G.filter(V=>H[V]).join(","):"";if(f.useLayoutEffect(()=>{const V=w.current,W=b.current;if(!U||!V||!W)return;const B=()=>{const Z={};let ue=0,fe=0;for(const de of Array.from(W.children)){const Ee=de.dataset.measure,me=Math.ceil(de.getBoundingClientRect().width);Ee==="trigger"?ue=me:Ee==="more"?fe=me:Ee&&(Z[Ee]=me)}const Ce={available:V.clientWidth-2*fq,triggerWidth:ue,moreWidth:fe,widths:Z};C(de=>pq(de,Ce)?de:Ce)};if(B(),typeof ResizeObserver>"u")return;const te=new ResizeObserver(B);return te.observe(V),te.observe(W),()=>te.disconnect()},[U]),!r||!M||!H)return null;const J=r.occupancy?cS(r.occupancy):[],$=G.filter(V=>H[V]),oe=hq({segments:$,widths:N?.widths,available:N?.available,triggerWidth:N?.triggerWidth,moreWidth:N?.moreWidth,mobile:j}),Ne=$.filter(V=>oe.inline.includes(V)||oe.hoverable.includes(V)),ce=oe.collapsed&&$.length>0,ne=H.context&&!oe.inline.includes("context")?H.context:void 0,Y=(V,W)=>{const B=M[V];return n.jsxs(n.Fragment,{children:[V==="context"&&W.percent!==void 0?J.length>0?n.jsx(d2,{segments:J}):n.jsx(nq,{percent:W.percent,critical:!!W.critical}):n.jsx(B,{className:"h-3 w-3 shrink-0 opacity-75"}),W.compact&&n.jsx("span",{className:"truncate",children:W.compact})]})},pe=(V,W)=>_("relative flex items-center gap-1 text-[11px] tabular-nums",cy(V,W)),ge=V=>_("flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-[11px] tabular-nums outline-none hover:bg-muted",V?cy("context",V):"text-subtle-foreground"),we=V=>V?n.jsxs(n.Fragment,{children:[n.jsx(Cj,{className:"h-3 w-3 shrink-0 opacity-75"}),n.jsx("span",{children:V.compact})]}):n.jsx(ll,{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:[$.length>0&&n.jsx("div",{"aria-hidden":!0,className:"pointer-events-none invisible absolute inset-0 overflow-hidden",children:n.jsxs("div",{ref:b,className:"absolute top-0 left-0 flex w-max",children:[$.map(V=>{const W=H[V];return W?n.jsx("span",{"data-measure":V,className:pe(V,W),children:Y(V,W)},V):null}),n.jsx("span",{"data-measure":"trigger",className:ge(H.context),children:we(H.context)}),n.jsx("span",{"data-measure":"more",className:ge(void 0),children:we(void 0)})]})}),(Ne.length>0||ce)&&n.jsxs("div",{className:"flex min-w-0 flex-nowrap items-center gap-3 overflow-hidden",children:[Ne.map(V=>{const W=H[V];if(!W)return null;const B=n.jsxs("span",{title:`${s(ja[V])} · ${W.full}`,onMouseEnter:()=>h(V),onMouseLeave:()=>h(te=>te===V?null:te),className:pe(V,W),children:[Y(V,W),m===V&&V!=="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(ja[V])}),n.jsx("span",{className:"ml-1 break-words text-muted-foreground",children:W.full})]})]});return n.jsx("span",{className:_("shrink-0 items-center",p||oe.inline.includes(V)?"flex":"hidden group-focus-within:flex group-hover:flex"),children:V==="context"?n.jsxs(Rs,{open:p,onOpenChange:g,children:[n.jsx(Ms,{className:"rounded-sm outline-none",children:B}),n.jsx(Ps,{side:"top",className:"w-72 [&_[data-slot=popover-viewport]]:p-0",children:n.jsx(ly,{occupancy:r.occupancy,conversationId:r.id,cwd:t,onNavigate:()=>g(!1)})})]}):B},V)}),ce&&n.jsxs(Rs,{open:x,onOpenChange:y,children:[n.jsx(Ms,{"data-slot":"status-line-details","aria-label":s("Session stats"),title:s("Session stats"),className:ge(ne),children:we(ne)}),n.jsxs(Ps,{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:$.filter(V=>V!=="context").map(V=>{const W=H[V];if(!W)return null;const B=M[V];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(ja[V])}),n.jsx("span",{className:_("ml-auto min-w-0 break-words text-right tabular-nums",W.critical&&"text-destructive"),children:W.full})]},V)})}),$.includes("context")&&n.jsx("div",{className:"border-t",children:n.jsx(ly,{occupancy:r.occupancy,conversationId:r.id,cwd:t,onNavigate:()=>y(!1)})})]})]})]}),n.jsxs(Rs,{children:[n.jsx(Ms,{"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(UE,{className:"h-3.5 w-3.5"})}),n.jsx(Ps,{side:"top",align:"end",className:"w-72 [&_[data-slot=popover-viewport]]:p-0",children:n.jsx(uq,{icons:M,values:H})})]})]})}const Iq=["pattern","query","path","file_path"],Tq=["path","file_path","query","pattern"],Aq=["command","cmd","script"],Eq=["path","file_path","pattern","query","command","url","description","summary"],fy=120;function Gi(e){const t=e.replace(/\s+/g," ").trim();return t.length>fy?`${t.slice(0,fy-1)}…`:t}function Rq(e){const t=e.toLowerCase();return t.includes("search")||t.includes("grep")||t==="find"?Iq:t==="read"||t.endsWith("_read")?Tq:t==="bash"||t.includes("shell")||t.includes("terminal")?Aq:Eq}function Mq(e,t){const s=t.trim();if(!s)return"";let r;try{r=JSON.parse(s)}catch{return Gi(s)}if(r===null)return"";if(typeof r!="object"||Array.isArray(r))return Gi(JSON.stringify(r)??String(r));const o=Ij(e,r);if(o.summary!==void 0)return Gi(o.summary);if(!o.args||typeof o.args!="object")return"";const i=o.args;for(const l of Rq(o.name)){const c=i[l];if(typeof c=="string"&&c.trim())return Gi(c)}const a=JSON.stringify(i);return a==="{}"?"":Gi(a)}function Pq(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=24}const m2=new Map,Dq=e=>{const t=m2.get(e);return t?new Set(t):new Set},my=(e,t)=>(m2.set(e,t),t),Qm=new Map,Oq=(e,t)=>{const s=Qm.get(e)??new Set;Qm.set(e,s);for(const r of t)s.add(r);return s},h2="enso:task-bar-expanded",p2=new Map,x2=()=>{try{const e=JSON.parse(window.sessionStorage.getItem(h2)??"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}},Lq=e=>p2.get(e)??x2().includes(e),_q=(e,t)=>{p2.set(e,t);try{const s=x2().filter(r=>r!==e);window.sessionStorage.setItem(h2,JSON.stringify(t?[...s,e]:s))}catch{}return t};function Bq({sessionId:e,tasks:t,subagents:s,readOnly:r}){const o=xe(C=>C.virtualModels),{t:i}=z(),[a,l]=f.useState(()=>Dq(e)),[c,u]=f.useState(null),[d,m]=f.useState(()=>Lq(e)),h=X(C=>C.pendingAgentOpen);f.useEffect(()=>{!h||h.sessionId!==e||(u(h.agentId),X.setState({pendingAgentOpen:null}))},[h,e]);const p=Oq(e,[...t.filter(C=>C.status==="running").map(C=>C.taskId),...s.filter(C=>C.status==="running").map(C=>C.id)]),g=(C,E)=>!a.has(C)&&(E==="running"||p.has(C)),x=t.filter(C=>g(C.taskId,C.status)),y=s.filter(C=>g(C.id,C.status));if(f.useEffect(()=>{const C=Qm.get(e),E=[...t.filter(k=>k.status!=="running").map(k=>k.taskId),...s.filter(k=>k.status!=="running").map(k=>k.id)].filter(k=>C?.has(k)&&!a.has(k)&&k!==c);if(E.length===0)return;const T=setTimeout(()=>{l(k=>{const L=new Set(k);for(const F of E)L.add(F);return my(e,L)})},5e3);return()=>clearTimeout(T)},[e,t,s,a,c]),x.length===0&&y.length===0)return null;const j=C=>{l(E=>my(e,new Set(E).add(C))),c===C&&u(null)},w=x.find(C=>C.taskId===c)??null,b=y.find(C=>C.id===c)??null,N=x.length>=2;return n.jsxs("div",{className:"relative mb-1.5",children:[(w||b)&&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:b?.description,b?.modelId?` · ${Hf(o,b.modelId)}`:""]}),w&&n.jsx(Vq,{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(Zt,{className:"h-3.5 w-3.5"})})]}),w&&n.jsx(Hq,{sessionId:e,task:w,readOnly:r}),b&&n.jsx(Wq,{agent:b},b.id)]}),n.jsxs("div",{className:"flex flex-col gap-0.5 rounded-xl border bg-card p-1 shadow-xs",children:[N&&n.jsx(Fq,{sessionId:e,tasks:x,expanded:d,readOnly:r,onToggle:()=>m(_q(e,!d))}),(!N||d)&&x.map(C=>n.jsx($q,{sessionId:e,task:C,readOnly:r,open:c===C.taskId,onToggle:()=>u(c===C.taskId?null:C.taskId),onDismiss:()=>j(C.taskId)},C.taskId)),y.map(C=>n.jsxs(zq,{icon:_s,status:C.status,meta:n.jsx(Yq,{agent:C}),open:c===C.id,onToggle:()=>u(c===C.id?null:C.id),stopTitle:i("Stop subagent"),onStop:r?void 0:()=>{window.electronAPI.agent.stopSubagent(e,C.id)},onDismiss:()=>j(C.id),children:[C.agentType&&n.jsx("span",{className:"shrink-0 font-medium",children:C.agentType}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:[C.description,C.modelId&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" ","· ",Hf(o,C.modelId)]}),C.status==="running"&&C.currentActivity&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" · ",C.currentActivity]})]})]},C.id))]})]})}function Fq({sessionId:e,tasks:t,expanded:s,readOnly:r,onToggle:o}){const{t:i}=z(),a=Ri(1e3),[l,c]=f.useState(!1),u=t.filter(p=>p.status==="running"),d=t.filter(p=>io(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(Mp,{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)Mi(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:Hn(a-m)})}`]}),d>0&&n.jsx(ti,{tone:"pending",className:"whitespace-nowrap",children:i("{{count}} suspected idle",{count:d})}),n.jsx(Bn,{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 zq({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(Mp,{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(Bn,{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(Zt,{className:"h-3 w-3"})})]})}function $q({sessionId:e,task:t,readOnly:s,open:r,onToggle:o,onDismiss:i}){const{t:a}=z(),l=Ri(),c=io(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(Lp,{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(ti,{tone:"pending",children:Op(t,l,a)})]}),n.jsx(_p,{task:t,className:"mt-0.5"})]}),n.jsx(Xq,{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(Bn,{className:_("h-3 w-3 transition-transform",r&&"rotate-180")})]}),t.status==="running"?s?null:c==="idle"?n.jsx(qd,{sessionId:e,taskId:t.taskId}):n.jsx(Fp,{onStop:()=>Mi(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(Zt,{className:"h-3 w-3"})})]})}function Vq({sessionId:e,task:t,readOnly:s}){const{t:r}=z(),o=Ri(),i=io(t);return n.jsxs(n.Fragment,{children:[n.jsx(mN,{task:t,now:o}),!s&&i==="idle"&&n.jsx(qd,{sessionId:e,taskId:t.taskId}),!s&&i==="kept"&&n.jsx(he,{size:"xs",variant:"ghost",className:"text-muted-foreground",onClick:()=>Bp(e,t.taskId,null),children:r("Unkeep")})]})}function jf({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 hy({children:e}){return n.jsx("div",{className:"text-[11px] text-subtle-foreground tabular-nums",children:e})}function Hq({sessionId:e,task:t,readOnly:s}){const{t:r}=z(),o=Ri(),i=io(t),a=Dp(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(jf,{icon:Hd,label:r("No new output"),value:fN(o-(t.idle?.since??o),r)}),n.jsx(jf,{icon:dB,label:l.length>0?r("Port {{ports}}",{ports:l.join(", ")}):r("Ports"),value:l.length>0?r("No connections"):r("Not listening")}),n.jsx(jf,{icon:Hk,label:"CPU",value:"0%"})]}),n.jsx(hy,{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(Ns,{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??"")&&Bp(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:Cm(t.keep.at)}):r("Kept by you at {{time}}",{time:Cm(t.keep.at)})})]})]}),n.jsx(hy,{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(Qq,{tail:t.tail,outputBytes:t.outputBytes,running:t.status==="running",framed:!c})]})}function Wq({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=Pq(i.currentTarget)},children:[s.map(i=>n.jsx(Uq,{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(`
74
- `)||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(Gn,{text:e.resultText})]})]})}function Uq({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(qq,{text:e.text,markdown:!0})]});const o=Mq(e.toolName,e.argumentsText),i=Ij(e.toolName,e.argumentsText).name,a=Cw(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(Gq,{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(Kq,{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:Ls(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:Ls(e.outputText)})]})]})]})}function Gq({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(lr,{"aria-hidden":"true",className:s}):t==="read"||t==="write"||t==="edit"||t==="apply_patch"||t.endsWith("_read")?n.jsx(Fo,{"aria-hidden":"true",className:s}):t==="bash"||t==="exec"||t==="codemode"||t.includes("shell")||t.includes("terminal")?n.jsx(_f,{"aria-hidden":"true",className:s}):n.jsx(Ch,{"aria-hidden":"true",className:s})}function Kq({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(Bt,{"aria-hidden":"true",className:_(s,"animate-spin")}):e==="done"?n.jsx(Dn,{"aria-hidden":"true",className:s}):e==="failed"?n.jsx(Zr,{"aria-hidden":"true",className:s}):n.jsx(h4,{"aria-hidden":"true",className:s})})}function qq({text:e,label:t,markdown:s=!1}){const{t:r}=z(),o=e.length>800||e.split(`
75
- `).length>16,i=s?n.jsx(Gn,{text:e}):n.jsx("pre",{className:"overflow-x-auto font-mono text-[11px] leading-relaxed whitespace-pre-wrap text-muted-foreground",children:Ls(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 Yq({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"?Hn(Date.now()-e.startedAt):e.status]})}function Xq({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"?Hn(Date.now()-e.startedAt):e.exitCode!==void 0?`exit ${e.exitCode}`:e.status})}function Qq({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:Ls(e)||(t===void 0?o("Loading…"):t>0?o("Output written ({{size}}), not loaded yet",{size:jw(t)}):s?`${o("(no output yet)")}
76
- ${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 Nx(e){return e==="darwin"?"Open in Finder":e==="win32"?"Open in File Explorer":"Open in File Manager"}async function Sx(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 Jq="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 Zq({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"):Un(e),p=f.useCallback(()=>{m&&window.electronAPI.projects.openInApps().then(c).catch(()=>{})},[m]),g=j=>{Sx({projectId:e.id,conversationId:t,...j?{appId:j}:{}},a)},x=l.filter(j=>j.kind==="editor"),y=l.filter(j=>j.kind==="terminal");return n.jsxs(ur,{onOpenChange:j=>j&&p(),children:[n.jsxs(fr,{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(Wd,{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) ${Jq}`,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(mr,{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(Nx(window.electronAPI.env.platform))]}),n.jsx(py,{label:a("Editors"),apps:x,fallback:n.jsx(P4,{}),disabled:o,onOpen:g}),n.jsx(py,{label:a("Terminals"),apps:y,fallback:n.jsx(_o,{}),disabled:o,onOpen:g}),n.jsx(yi,{})]}),n.jsxs(Cn,{onClick:()=>{navigator.clipboard.writeText(s)},children:[n.jsx(Xa,{}),a("Copy Path")]})]})]})}function py({label:e,apps:t,fallback:s,disabled:r,onOpen:o}){return t.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(yi,{}),n.jsxs(Ah,{children:[n.jsx(Eh,{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 eY({conversationId:e}){const{t}=z(),s=X(i=>i.conversations[e]),r=X(i=>i.rebuildWorktree),o=X(i=>i.fallbackToMainWorkspace);return!s?.worktreeMissing||!s.worktree?null:n.jsx(ih,{open:!0,children:n.jsxs(ah,{className:"sm:max-w-md",children:[n.jsxs(lh,{children:[n.jsx(ch,{className:"text-base",children:t("Isolated worktree is missing")}),n.jsx(dh,{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(uh,{variant:"bare",children:[n.jsx(he,{variant:"outline",size:"sm",onClick:()=>{o(e)},children:t("Fall back to main working tree")}),n.jsx(he,{size:"sm",onClick:()=>{r(e).then(i=>{i&&Ie({type:"error",title:t("Failed to rebuild worktree"),description:i})})},children:t("Rebuild worktree")})]})]})})}function gd(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 tY({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(y=>y.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?gd(t.blockedReason,c):t&&!t.headCommit?c("Create a commit before creating a branch from HEAD."):null;return n.jsx(cn,{open:!0,onOpenChange:y=>{!y&&!s&&l()},children:n.jsxs(dn,{className:"max-w-sm",initialFocus:m,finalFocus:i,showCloseButton:!s,children:[n.jsxs(un,{children:[n.jsx(on,{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(Vt,{ref:m,"aria-label":c("Branch name"),"aria-invalid":!!x,"aria-describedby":x||o?h:void 0,value:u,disabled:s,onChange:y=>d(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&(y.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(he,{type:"button",variant:"outline",size:"sm",disabled:s,onClick:l,children:c("Cancel")}),n.jsxs(he,{type:"button",size:"sm",disabled:!!g,onClick:()=>{g||a(u.trim())},children:[s&&n.jsx(Bt,{className:"h-3.5 w-3.5 animate-spin"}),c("Create and switch")]})]})]})})}function nY({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),y=x<0?p.key==="ArrowDown"?0:g.length-1:(x+(p.key==="ArrowDown"?1:-1)+g.length)%g.length;g[y]?.focus()},children:[n.jsxs("div",{className:"relative m-1",children:[n.jsx(lr,{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(Vt,{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:gd(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(Bt,{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,y=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:y?`${p.name}
77
- ${y}`: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}),y&&n.jsx("span",{className:"block text-xs text-muted-foreground",children:y})]}),g&&n.jsx(Dn,{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(Xn,{className:"h-3.5 w-3.5 shrink-0"}),d("Create branch from HEAD…")]})]})}function Nc(e){return e.name?.trim()||e.branch}function sY(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 rY(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 Jm(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[Nc(e),e.branch,e.path,r].join(`
78
- `)}function oY({worktree:e,status:t}){const{t:s}=z();return n.jsx("span",{"data-slot":"worktree-label",title:Jm(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 g2({entity:e,onClose:t}){const{t:s}=z(),r=X(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(on,{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(Vt,{"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(he,{variant:"outline",size:"sm",disabled:a,onClick:t,children:s("Cancel")}),n.jsxs(he,{size:"sm",disabled:a,onClick:()=>{c()},children:[a&&n.jsx(Bt,{className:"h-3.5 w-3.5 animate-spin"}),s("Save")]})]})]})})}function iY({conversationId:e,onBranchChange:t}){const{t:s}=z(),r=X(_e=>_e.conversations[e]),o=X(_e=>_e.moveConversationToWorktree),i=X(_e=>_e.cleanupWorktree),a=X(_e=>_e.refreshWorktreeStatuses),l=X(_e=>_e.conversations),c=X(_e=>_e.worktreeStatuses),u=X(_e=>_e.attachConversationToWorktree),d=X(_e=>_e.newConversation),m=X(_e=>_e.switchWorkspaceBranch),h=X(_e=>_e.workspaceRevisionByConversation[e]??0),[p,g]=f.useState(null),x=f.useMemo(()=>sY(l,r?.projectId??"",c),[l,r?.projectId,c]),[y,j]=f.useState(!1),[w,b]=f.useState(!1),[N,C]=f.useState(!1),[E,T]=f.useState(null),[k,L]=f.useState(!1),F=xe(_e=>r?_e.projects.find(Nt=>Nt.id===r.projectId):void 0),A=!!(r&&!r.parentId&&!r.child&&F?.kind!=="ssh"&&F?.kind!=="scratch"&&F?.kind!=="secretary"),D=`${e}\0${r?.worktree?.path??F?.path??""}`,M=f.useRef(D);M.current=D;const H=f.useRef(0),G=f.useRef(!1),U=f.useRef(null),J=f.useRef(null),$=f.useRef(null);f.useEffect(()=>{y&&(w?J:$).current?.focus()},[y,w]);const[oe,Ne]=f.useState(null),ce=oe?.key===D?oe.data:null,ne=ce?.currentBranch??void 0;f.useEffect(()=>{t?.(ne)},[t,ne]);const[Y,pe]=f.useState(!0),[ge,we]=f.useState(null),[V,W]=f.useState(""),[B,te]=f.useState(null),[Z,ue]=f.useState(null),fe=B===D;f.useEffect(()=>{j(!1),b(!1),W(""),te(null),ue(null)},[D]);const Ce=f.useCallback(async(_e=!1)=>{if(!A)return;const Nt=++H.current;pe(!0),we(null);try{const Ot=await window.electronAPI.worktree.branches(e);if(Nt!==H.current||M.current!==D)return;if(Ot.ok)Ne({key:D,data:Ot.value});else{const _t=gd(Ot.code,s);we(_t),_e&&Ie({type:"error",title:s("Failed to load branches"),description:_t})}}catch(Ot){if(Nt!==H.current||M.current!==D)return;we(s("Failed to load branches")),_e&&Ie({type:"error",title:s("Failed to load branches"),description:String(Ot)})}finally{Nt===H.current&&M.current===D&&pe(!1)}},[e,A,s,D]);if(f.useEffect(()=>{Ce();const _e=()=>{G.current||Ce()};return window.addEventListener("focus",_e),()=>{H.current+=1,window.removeEventListener("focus",_e)}},[Ce,h]),!r||r.parentId||r.child||F?.kind==="ssh")return null;const de=!!r.worktree,Ee=N||r.spawning||r.status==="running"||!!(r.workspaceMigrating||r.reloading),me=r.worktreeMissing||c[e]?.exists===!1,Ve=rY(r),at=ce?ce.currentBranch:r.worktree?.branch,Fe=at??(ce?.headCommit?s("Detached HEAD"):""),tt=r.worktree?Nc(r.worktree):s("Local"),je=Fe&&Fe!==tt&&(!ce?.defaultBranch||at!==ce.defaultBranch)?`${tt} · ${Fe}`:tt,Je=Ee||me||Y||!!ge||!ce||!!ce.blockedReason,rt=async(_e,Nt=!1,Ot)=>{if(Je||G.current)return;G.current=!0,H.current+=1,C(!0),ue(null);const _t=s(Ot?"Failed to create conversation":"Failed to switch branch");try{if(Ot){await d(r.projectId,{worktreeFromConversationId:Ot})?M.current===D&&j(!1):Ie({type:"error",title:_t});return}const se=await m(e,_e,Nt);if(M.current!==D)return;if(se.ok)Ne({key:D,data:se.value}),we(null),te(null),j(!1);else{const Oe=gd(se.code,s);ue(Oe),Ie({type:"error",title:_t,description:se.code==="git-error"?`${Oe}
79
- ${se.error}`:Oe}),Ce()}}catch(se){if(M.current!==D)return;ue(String(se)),Ie({type:"error",title:_t,description:String(se)})}finally{G.current=!1,C(!1)}},K=_e=>{_e.name===ce?.currentBranch||_e.occupied&&!_e.worktreeConversationId||rt(_e.name,!1,_e.occupied?_e.worktreeConversationId:void 0)},Q=async _e=>{if(Ee)return;C(!0);const Nt=s(_e?"Failed to use worktree":"Failed to create conversation");try{if(_e){const Ot=await u(e,_e);Ot&&Ie({type:"error",title:Nt,description:Ot})}else await d(r.projectId,{worktreeFromConversationId:e})||Ie({type:"error",title:Nt})}catch(Ot){Ie({type:"error",title:Nt,description:String(Ot)})}finally{C(!1)}},Ae=async()=>{C(!0);try{const _e=await i(e);_e?Ie({type:"error",title:s("Failed to clean up worktree"),description:_e}):a()}catch(_e){Ie({type:"error",title:s("Failed to clean up worktree"),description:String(_e)})}finally{C(!1)}},pt=async(_e=!1)=>{C(!0);try{const Nt=await o(e,{allowDirtyMainTree:_e});Nt===Tj?L(!0):Nt?Ie({type:"error",title:s("Failed to move to worktree"),description:Nt}):a()}catch(Nt){Ie({type:"error",title:s("Failed to move to worktree"),description:String(Nt)})}finally{C(!1)}},Dt=async()=>{C(!0);try{const _e=await window.electronAPI.worktree.status(e);if(_e.ok&&sc(_e.value)){T(_e.value);return}await Ae()}catch(_e){Ie({type:"error",title:s("Failed to clean up worktree"),description:String(_e)})}finally{C(!1)}},Xe=[{id:"local",selected:!de,icon:n.jsx(ev,{className:"h-3.5 w-3.5 shrink-0"}),name:s("Local workspace"),hint:s("Work directly in the main working tree"),onSelect:()=>{de&&Dt()}},{id:"worktree",selected:de,icon:n.jsx(Hs,{className:"h-3.5 w-3.5 shrink-0"}),name:r.worktree?Nc(r.worktree):s("New isolated worktree"),hint:de?r.worktree?.branch:s("Run this session on its own git worktree"),onSelect:()=>{de||pt()}}],kt=n.jsx(hs,{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)}}),mn=()=>{const _e=[];return E?.dirty&&_e.push(s("Uncommitted changes")),E&&E.ahead>0&&_e.push(s("{{n}} unmerged commits (branch is kept)",{n:E.ahead})),_e.join("; ")};return n.jsxs(n.Fragment,{children:[n.jsxs(Rs,{open:y,onOpenChange:_e=>{N||(j(_e),_e&&(b(!1),W(""),Ce()))},children:[n.jsxs(Ms,{ref:U,disabled:Ee,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?`${je}
80
- ${Jm(r.worktree,c[e],s)}`:je,children:[N?n.jsx(Bt,{className:"h-3 w-3 shrink-0 animate-spin"}):de?n.jsx(Hs,{className:"h-3 w-3 shrink-0"}):n.jsx(ev,{className:"h-3 w-3 shrink-0"}),n.jsx("span",{className:"max-md:@max-[28rem]:hidden min-w-0 truncate",children:je}),n.jsx(Bn,{className:"h-3 w-3 shrink-0"})]}),n.jsx(Ps,{side:"top",align:"start",className:"w-72 [&_[data-slot=popover-viewport]]:p-1",initialFocus:$,finalFocus:fe||p!==null?!1:U,children:w?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:()=>b(!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(bi,{className:"h-3.5 w-3.5 shrink-0"}),s("Local branches")]}),n.jsx(nY,{data:ce,loading:Y,error:ge,disabled:Ee||me,query:V,searchRef:J,onQueryChange:W,onSelect:K,onRetry:()=>{Ce(!0)},onCreate:()=>{Je||!ce?.headCommit||(ue(null),te(D),j(!1))}})]}):n.jsxs(n.Fragment,{children:[Xe.map(_e=>n.jsxs("button",{ref:_e.id==="local"?$:void 0,type:"button",disabled:Ee,onClick:()=>{_e.onSelect(),j(!1)},className:_("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",_e.selected?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[_e.icon,n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate",children:_e.name}),_e.hint&&n.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:_e.hint})]}),_e.selected&&n.jsx(Dn,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]},_e.id)),Ve&&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:_e,worktree:Nt})=>n.jsxs("button",{type:"button",disabled:Ee,title:Jm(Nt,c[_e],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:()=>{j(!1),Q(_e)},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:Nc(Nt)}),n.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:Nt.path})]})]},Nt.path))})]}),r.worktree&&n.jsxs("div",{className:"mt-1 border-t pt-1",children:[n.jsxs("button",{type:"button",disabled:Ee||me,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:()=>{j(!1),Q()},children:[n.jsx(no,{className:"h-3.5 w-3.5"}),s("New conversation in this worktree")]}),n.jsxs("button",{type:"button",disabled:Ee||me,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:()=>{j(!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:Ee,onClick:()=>b(!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(hs,{open:E!==null,onOpenChange:_e=>{_e||T(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:mn()}),confirmLabel:s("Clean up"),onConfirm:()=>{T(null),Ae()}}),fe&&n.jsx(tY,{initialName:V.trim(),data:ce,busy:N,disabled:Je,error:Z,returnFocus:U,onSubmit:_e=>{rt(_e,!0)},onClose:()=>te(null)},D),kt,n.jsx(g2,{entity:p,onClose:()=>g(null)})]})}function aY(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 lY=e=>{tN(e)&&Ei()};function cY(){const{t:e}=z(),t=wi(),s=JE(),r=Rd(),o=xe(je=>je.virtualModels),i=xe(je=>je.agentTypes),a=xe(je=>je.defaultModel),l=xe(je=>je.projects),c=xe(je=>je.projectGroups),u=xe(je=>je.presets),d=f.useSyncExternalStore(je=>X.persist?.onFinishHydration?.(je)??(()=>{}),()=>X.persist?.hasHydrated?.()??!0),m=X(pg(VG)),h=X(je=>je.conversations[m?.parentId??""]?.coworkerIds),p=ZE(m?.presetId,je=>u.find(Je=>Je.id===je)).pluginPresetId??null,g=FG(m?.displayedParentId?m.agentType:void 0),x=Lo(je=>je.snapshot),y=Aj(),j=X(je=>JB(je.conversations)),w=m?.parentId,b=m?.parentProjectId,N=f.useMemo(()=>w!==void 0&&b!==void 0?eW(j,b,w):[],[j,w,b]),C=f.useMemo(()=>l.find(je=>je.id===m?.projectId),[m?.projectId,l]),E=f.useMemo(()=>l.find(je=>je.id===m?.parentProjectId),[m?.parentProjectId,l]),T=f.useMemo(()=>Lf(C,c),[C,c]),k=f.useMemo(()=>Lf(E,c),[E,c]),L=f.useMemo(()=>Df({defaultModel:a,...T,lastProviderId:m?.lastProviderId,lastModelId:m?.lastModelId,providers:r,credentials:Of(x),virtualModels:o}),[m?.lastModelId,m?.lastProviderId,T,a,x,r,o]),F=f.useMemo(()=>Df({defaultModel:a,...k,lastProviderId:m?.parentLastProviderId,lastModelId:m?.parentLastModelId,providers:r,credentials:Of(x),virtualModels:o}),[a,x,m?.parentLastModelId,m?.parentLastProviderId,k,r,o]),A=F.source==="none"?null:{providerId:F.providerId,modelId:F.modelId},D=L.source==="none"?void 0:y.find(je=>je.id===L.providerId),M=L.source==="none"?"":L.modelId,H=L.source==="none"?"":xg(L)?L.providerId:D?.id??"",G=X(je=>xg(L)&&m?.id?aY(je.conversations[m.id]?.messages):void 0),U=X(pg(je=>Sj(r,m?.id?je.conversations[m.id]:void 0))),J=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."):y.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."),$=l.find(je=>je.id===m?.projectId),oe=m?.id,[Ne,ce]=f.useState(),ne=f.useCallback(je=>ce(oe&&je?{id:oe,branch:je}:void 0),[oe]),Y=m?.parentWorktreeBranch??(Ne?.id===m?.parentId?Ne?.branch:void 0),pe=xe(je=>je.skills),ge=xe(je=>je.loadLocalSkills),we=xe(je=>e3(je.disabledBuiltinTools,je.projects,m?.projectId,"plan")),[V,W]=f.useState([]),B=ge?$?.path??"":"",te=m?.presetId;f.useEffect(()=>{let je=!1;return window.electronAPI.assets.listProjectSkills(B,te).then(Je=>{je||W(Je)}).catch(()=>{je||W([])}),()=>{je=!0}},[B,te]);const Z=m?.commands,ue=t3(),fe=f.useMemo(()=>{if(!Z)return[];const je={name:"/goal",description:e("Set a session goal (/goal <objective> · pause · resume · clear)")},Je={name:"/compact",description:e("Compact the context now (/compact [summary focus])")},rt={name:"/plan",description:e("Plan mode: research read-only, then approve a plan (/plan [task] · off)")},K=pe.filter(Ae=>Ae.enabled!==!1).map(Ae=>({name:`/skill:${Ae.name}`,description:Ae.description})),Q=V.map(Ae=>({name:`/skill:${Ae.name}`,description:Ae.description}));return qS([je,Je,...we?[rt]:[],...K,...Q,...Z,...ue])},[e,pe,V,Z,ue,we]),Ce=f.useRef(null),de=!m?.displayedParentId&&["planning","awaiting_review"].includes(wj(m?.planState)),Ee=m?.status==="running",me=m?.busy===!0,Ve=m?.parentWorktreePath??$?.path,at=f.useCallback(()=>{m&&!m.parentStarted&&m.parentSessionFile&&!m.parentWorktreeMissing&&m.parentStatus!=="failed"&&X.getState().resumeConversation(m.parentId)},[m]);f.useEffect(()=>{const je=m?.compactionError;!je||!m||(Ie({type:"error",title:e("Compaction failed"),description:je}),X.getState().clearCompactionError(m.id))},[m,e]);const Fe=zG(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(yj,{"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(dY,{status:m.spawning?"running":m.status,pendingAskCount:(m.pendingAsks??[]).length,hasRunningChild:m.id===m.parentId&&m.parentHasRunningChild});return n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[n.jsx(eY,{conversationId:m.parentId}),n.jsx(VK,{parentId:m.parentId,displayedId:m.id,trailing:n.jsxs("div",{className:"flex min-w-0 shrink-0 items-center gap-1",children:[n.jsx(EG,{conversationId:m.parentId}),n.jsx(DG,{conversationId:m.parentId}),n.jsx(BG,{conversationId:m.parentId}),n.jsx(tK,{parentId:m.parentId,coworkerIds:h??[]}),$?n.jsx(Zq,{project:$,conversationId:m.parentId,path:m.parentWorktreePath??$.path,branch:Y,openDisabled:m.parentWorktreeMissing,children:tt}):n.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:tt})]})}),n.jsx(YC,{conversationId:m.id,cwd:Ve,emptyTitle:$?Un($):"EnsoCode",onSuggestion:$?lY:void 0,timelineRef:Ce}),n.jsx("div",{className:"@container pt-1",children:n.jsxs("div",{className:_r,children:[$&&$.kind!=="ssh"&&$.kind!=="scratch"&&$.kind!=="secretary"&&!m.displayedParentId&&n.jsx(eq,{projectId:$.id,conversationId:m.id},`${$.id}:${m.id}`),m.retry&&n.jsx(NC,{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(Bt,{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(gj.Provider,{value:{conversationId:m.id,projectId:m.projectId,...Ve?{cwd:Ve}:{}},children:n.jsx(Bq,{sessionId:m.id,tasks:m.backgroundTasks??[],subagents:m.subagents??[]},m.id)}),n.jsx(Vp,{approvals:m.pendingApprovals??[],allowSession:m.childLockedProfileId===void 0,onRespond:(je,Je)=>{window.electronAPI.agent.respondApproval(m.id,je,Je)}}),n.jsx(WG,{}),n.jsx(Hp,{asks:m.pendingAsks??[],onAnswer:(je,Je)=>{window.electronAPI.agent.respondAsk(m.id,je,Je)}}),!m.displayedParentId&&n.jsx(YK,{conversationId:m.id,planState:m.planState,approvalMode:m.approvalMode??"full"}),n.jsx(qK,{conversationId:m.id,queued:m.queuedMessages??[]}),m.goal&&n.jsx(GK,{conversationId:m.id,goal:m.goal}),n.jsx(NH,{conversationId:m.id},m.id),!m.displayedParentId&&J&&n.jsx("div",{role:"status",className:"rounded-md border border-dashed px-3 py-2 text-muted-foreground text-xs",children:J}),n.jsx($K,{cwd:$?.path,chatCandidates:N,commands:fe,running:Ee,busy:me,locked:(m.pendingApprovals??[]).length>0||!!(m.rewinding||m.restoringFiles),focusKey:m.id,pluginPresetId:p,planMode:de,savePastedText:$?.kind==="ssh"?void 0:je=>window.electronAPI.files.savePastedText({conversationId:m.id,text:je}),placeholder:de?e("Describe the task — a plan comes first"):void 0,injectedDraft:m.draftText,injectedImages:m.draftImages,injectedDraftAppend:m.draftAppend,onDraftConsumed:()=>X.getState().clearDraft(m.id),queuedCount:m.queuedMessages?.length??0,onSteerQueued:()=>X.getState().steerQueued(m.id),toolbar:n.jsxs(n.Fragment,{children:[!m.displayedParentId&&n.jsxs(n.Fragment,{children:[n.jsx(ZK,{presetId:m.presetId??"default",disabled:m.started,onSelect:je=>X.getState().setPreset(m.id,je),onModel:je=>X.getState().setModel(m.id,je.providerId,je.modelId)}),n.jsx(iY,{conversationId:m.id,onBranchChange:ne}),(we||m.planState?.active)&&n.jsx(JK,{active:m.planState?.active??!1,onToggle:je=>X.getState().setPlanMode(m.id,je)}),n.jsx(n3,{mode:m.approvalMode??"full",autoReject:m.autoRejectApprovals===!0,onSelect:je=>X.getState().setApprovalMode(m.id,je),onToggleAutoReject:je=>X.getState().setAutoRejectApprovals(m.id,je)}),n.jsx(Ej,{listenHotkey:!0,refreshAllModels:!0,recordRecent:!0,compact:t,providers:y,virtualModels:o,routedModelLabel:G,activeAccount:U,providerId:H,modelId:M,reasoningEnabled:m.reasoningEnabled??!1,thinkingLevel:m.thinkingLevel??"medium",onSelect:(je,Je)=>X.getState().setModel(m.id,je,Je),onReasoningChange:je=>X.getState().setReasoning(m.id,je),onThinkingChange:je=>X.getState().setThinking(m.id,je)})]}),m.displayedParentId&&n.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[g??(m.agentType?vj(m.agentType,i):"coworker"),m.lastModelId?` · ${Hf(o,m.lastModelId)}`:""]})]}),onActivate:at,onSend:je=>{if(!je.recipient&&!$||!je.recipient&&!m.displayedParentId&&(!H||!M))return!1;if($?.kind==="secretary"&&!je.recipient){const Je=je.mentions.filter(rt=>rt.kind==="chat").map(rt=>rt.id);Je.length>0&&window.electronAPI.secretary.referenceConversations(m.id,Je).catch(()=>{})}return WK(je,{dispatchAgent:(Je,rt)=>{X.getState().dispatchAgent(Je,rt,A)},sendCoding:(Je,rt)=>{$&&(Ce.current?.scrollToBottom(),X.getState().send(Je,{providerId:H,modelId:M,cwd:$.path},rt))}}),!0},onAbort:()=>{X.getState().abort()}}),n.jsx(Cq,{conversationId:m.id,cwd:Ve})]})})]})}function dY({status:e,pendingAskCount:t=0,hasRunningChild:s=!1}){const r=jd({status:e,pendingAskCount:t,hasRunningChild:s});return n.jsx(cl,{tone:r,title:e})}function v2(e,t,s){const r=e.slice();return r.splice(s<0?r.length+s:s,0,r.splice(t,1)[0]),r}function uY(e,t){return e.reduce((s,r,o)=>{const i=t.get(r);return i&&(s[o]=i),s},Array(e.length))}function Gl(e){return e!==null&&e>=0}function fY(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 mY(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Kl={scaleX:1,scaleY:1},hY=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=pY(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,...Kl}:null}return a>o&&a<=i?{x:-l.width-c,y:0,...Kl}:a<o&&a>=i?{x:l.width+c,y:0,...Kl}:{x:0,y:0,...Kl}};function pY(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 b2=e=>{let{rects:t,activeIndex:s,overIndex:r,index:o}=e;const i=v2(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}},ql={scaleX:1,scaleY:1},xy=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,...ql}:null}const c=xY(i,o,s);return o>s&&o<=a?{x:0,y:-l.height-c,...ql}:o<s&&o>=a?{x:0,y:l.height+c,...ql}:{x:0,y:0,...ql}};function xY(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 y2="Sortable",w2=Ue.createContext({activeIndex:-1,containerId:y2,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:b2,disabled:{draggable:!1,droppable:!1}});function Zm(e){let{children:t,id:s,items:r,strategy:o=b2,disabled:i=!1}=e;const{active:a,dragOverlay:l,droppableRects:c,over:u,measureDroppableContainers:d}=nl(),m=el(y2,s),h=l.rect!==null,p=f.useMemo(()=>r.map(E=>typeof E=="object"&&"id"in E?E.id:E),[r]),g=a!=null,x=a?p.indexOf(a.id):-1,y=u?p.indexOf(u.id):-1,j=f.useRef(p),w=!fY(p,j.current),b=y!==-1&&x===-1||w,N=mY(i);qs(()=>{w&&g&&d(p)},[w,p,g,d]),f.useEffect(()=>{j.current=p},[p]);const C=f.useMemo(()=>({activeIndex:x,containerId:m,disabled:N,disableTransforms:b,items:p,overIndex:y,useDragOverlay:h,sortedRects:uY(p,c),strategy:o}),[x,m,N.draggable,N.droppable,b,p,y,c,h,o]);return Ue.createElement(w2.Provider,{value:C},t)}const gY=e=>{let{id:t,items:s,activeIndex:r,overIndex:o}=e;return v2(s,r,o).indexOf(t)},vY=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},bY={duration:200,easing:"ease"},j2="transform",yY=cr.Transition.toString({property:j2,duration:0,easing:"linear"}),wY={roleDescription:"sortable"};function jY(e){let{disabled:t,index:s,node:r,rect:o}=e;const[i,a]=f.useState(null),l=f.useRef(s);return qs(()=>{if(!t&&s!==l.current&&r.current){const c=o.current;if(c){const u=Ni(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 lu(e){let{animateLayoutChanges:t=vY,attributes:s,disabled:r,data:o,getNewIndex:i=gY,id:a,strategy:l,resizeObserverConfig:c,transition:u=bY}=e;const{items:d,containerId:m,activeIndex:h,disabled:p,disableTransforms:g,sortedRects:x,overIndex:y,useDragOverlay:j,strategy:w}=f.useContext(w2),b=kY(r,p),N=d.indexOf(a),C=f.useMemo(()=>({sortable:{containerId:m,index:N,items:d},...o}),[m,o,N,d]),E=f.useMemo(()=>d.slice(d.indexOf(a)),[d,a]),{rect:T,node:k,isOver:L,setNodeRef:F}=sl({id:a,data:C,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:E,...c}}),{active:A,activatorEvent:D,activeNodeRect:M,attributes:H,setNodeRef:G,listeners:U,isDragging:J,over:$,setActivatorNodeRef:oe,transform:Ne}=s1({id:a,data:C,attributes:{...wY,...s},disabled:b.draggable}),ce=TR(F,G),ne=!!A,Y=ne&&!g&&Gl(h)&&Gl(y),pe=!j&&J,ge=pe&&Y?Ne:null,V=Y?ge??(l??w)({rects:x,activeNodeRect:M,activeIndex:h,overIndex:y,index:N}):null,W=Gl(h)&&Gl(y)?i({id:a,items:d,activeIndex:h,overIndex:y}):N,B=A?.id,te=f.useRef({activeId:B,items:d,newIndex:W,containerId:m}),Z=d!==te.current.items,ue=t({active:A,containerId:m,isDragging:J,isSorting:ne,id:a,index:N,items:d,newIndex:te.current.newIndex,previousItems:te.current.items,previousContainerId:te.current.containerId,transition:u,wasDragging:te.current.activeId!=null}),fe=jY({disabled:!ue,index:N,node:k,rect:T});return f.useEffect(()=>{ne&&te.current.newIndex!==W&&(te.current.newIndex=W),m!==te.current.containerId&&(te.current.containerId=m),d!==te.current.items&&(te.current.items=d)},[ne,W,m,d]),f.useEffect(()=>{if(B===te.current.activeId)return;if(B!=null&&te.current.activeId==null){te.current.activeId=B;return}const de=setTimeout(()=>{te.current.activeId=B},50);return()=>clearTimeout(de)},[B]),{active:A,activeIndex:h,attributes:H,data:C,rect:T,index:N,newIndex:W,items:d,isOver:L,isSorting:ne,isDragging:J,listeners:U,node:k,overIndex:y,over:$,setNodeRef:ce,setActivatorNodeRef:oe,setDroppableNodeRef:F,setDraggableNodeRef:G,transform:fe??V,transition:Ce()};function Ce(){if(fe||Z&&te.current.newIndex===N)return yY;if(!(pe&&!Dd(D)||!u)&&(ne||ue))return cr.Transition.toString({...u,property:j2})}}function kY(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}}nn.Down,nn.Right,nn.Up,nn.Left;const NY="default";function SY(e,t){return e===jr?{kind:"all",fallbackFrom:"recent"}:e===Is?{kind:"ungrouped"}:e!==qn&&t.some(s=>s.id===e)?{kind:"group",groupId:e}:{kind:"all"}}const k2=e=>e?.secretaryOrigin?e.secretaryOrigin.secretaryId??NY:void 0;function kf(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=>k2(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 gy=e=>e.reduce((t,s)=>t+s.ids.length,0);function CY(e,t){const s=new Set;for(const r of e)for(const o of r.ids){const i=k2(t[o]);i&&s.add(i)}return[...s]}const vy=["idle","running","waiting","error"];function N2(e,t){return e?Cx({...e,hasRunningChild:rh({...e,status:e.status??"idle"},t)}):"idle"}function Cx(e){const t=jd({status:e.status??"idle",spawning:e.spawning,pendingAskCount:(e.pendingAsks?.length??0)+(e.pendingApprovals?.length??0),hasRunningChild:e.hasRunningChild});return t==="failed"?"error":t==="unread"?"idle":t}function IY(e){let t=0;for(const s of Object.values(e))!s||s.parentId||s.btwParentId||(t=Math.max(t,vy.indexOf(N2(s,e))));return vy[t]}const TY=[];function AY({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($k,{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(fh,{className:"h-3 w-3","aria-hidden":!0}),t]})]})}function EY({conversationId:e}){const{t}=z(),s=X(d=>d.conversations[e]?.backgroundTasks??TY),r=X(d=>d.conversations[e]?.title),o=X(d=>!d.conversations[e]?.generation),{running:i,idle:a}=xN(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(xl,{children:[n.jsx(gl,{render:n.jsx("span",{"data-enso":"session-task-marker",className:"flex shrink-0 items-center"}),children:n.jsx(AY,{running:i,idle:a})}),n.jsxs(tu,{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(RY,{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:()=>hN(),className:"inline-flex shrink-0 items-center gap-0.5 text-foreground/80 hover:text-foreground",children:[t("All tasks"),n.jsx(Ti,{className:"size-3"})]})]})]})]})}function RY({conversationId:e,task:t}){const{t:s}=z(),r=Ri(),o=io(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(Lp,{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:Op(t,r,s)}):o==="kept"?n.jsx(_p,{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:Dp(r-t.startedAt)})})]}),o==="idle"?n.jsx(qd,{sessionId:e,taskId:t.taskId}):n.jsx(Fp,{onStop:()=>Mi(e,t.taskId)})]})}function by({className:e}){const t=Po(i=>i.open),s=X(i=>{let a=0,l=0;for(const c of Object.values(i.conversations)){const u=xN(c?.backgroundTasks);a+=u.running,l+=u.idle}return`${a}:${l}`}),[r,o]=s.split(":").map(Number);return n.jsx(MY,{running:r,idle:o,active:t,onClick:()=>hN(),className:e})}function MY({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($k,{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 PY=e=>e==="/"?null:e.replace(/\/[^/]+$/,"")||"/";function DY(e,t){const s=e.includes("\\")&&!e.includes("/")?"\\":"/";return e.endsWith(s)?`${e}${t}`:`${e}${s}${t}`}function yy({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,y]=f.useState(""),j=f.useRef(0),w=f.useRef(null),b=f.useRef(e);b.current=e;const N=f.useCallback((F,A=!1)=>{const D=++j.current;d(!0),h(""),b.current(F,A).then(M=>{if(!(D!==j.current||!M)){if("error"in M){h(M.error);return}c(M),w.current=M.path}}).catch(()=>{D===j.current&&h(a("Failed to list remote directory."))}).finally(()=>{D===j.current&&d(!1)})},[a]),C=f.useRef(s);f.useEffect(()=>{N(C.current)},[N]),f.useEffect(()=>{r&&N(w.current??C.current,!0)},[r,N]);const E=l?.path??null,T=l?.dirs??[],k=l?.parent??null,L=()=>{if(!t||!E||p===null||!p.trim())return;const F=++j.current;d(!0),y(""),t(E,p).then(A=>{if(F===j.current){if("error"in A){y(a(A.error));return}g(null),h(""),c(A),w.current=A.path}}).catch(()=>{F===j.current&&y(a("Failed to list remote directory."))}).finally(()=>{F===j.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:E??"…"}),n.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",disabled:!k||u,onClick:()=>k&&N(k),children:a("Up")}),t&&n.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",disabled:!E||u||p!==null,onClick:()=>{g(""),y("")},children:a("New Folder")}),n.jsx(he,{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(Vt,{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(he,{type:"button",size:"sm",className:"h-7 px-2 text-xs",disabled:u||!p.trim(),onClick:L,children:a("Create")}),n.jsx(he,{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}):T.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:T.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:()=>E&&N(DY(E,F)),children:[F,"/"]},F))}),u&&n.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60",children:[n.jsx(Bt,{className:"h-4 w-4 animate-spin text-muted-foreground"}),n.jsx("span",{className:"sr-only",children:a("Loading...")})]})]}),n.jsx(he,{type:"button",variant:"outline",size:"sm",className:"h-7 w-full text-xs",disabled:!E||u,onClick:()=>E&&o(E),children:a("Use this directory")})]})}function OY({open:e,onOpenChange:t,onAdd:s,groups:r=[],defaultGroupId:o}){const{t:i}=z(),a=xe(fe=>fe.projects),[l,c]=f.useState("local"),[u,d]=f.useState(""),[m,h]=f.useState(""),[p,g]=f.useState(""),[x,y]=f.useState([]),[j,w]=f.useState(o),[b,N]=f.useState(!1),[C,E]=f.useState([]),[T,k]=f.useState(""),[L,F]=f.useState(null),[A,D]=f.useState(null),[M,H]=f.useState(0),[G,U]=f.useState(!1),[J,$]=f.useState(!1),oe=f.useRef(0),Ne=f.useMemo(()=>[{value:"",label:i("Ungrouped")},...r.map(fe=>({value:fe.id,label:fe.name}))],[r,i]);f.useEffect(()=>{oe.current+=1,$(!1),e&&(c("local"),d(""),h(""),g(""),w(o),N(!1),k(""),F(null),D(null),H(0),window.electronAPI.sshConnections.list().then(y).catch(()=>y([])),window.electronAPI.projects.getRecent().then(E).catch(()=>E([])))},[e,o]);const ce=f.useMemo(()=>new Set(a.map(fe=>fe.path)),[a]),ne=f.useMemo(()=>C.filter(fe=>!ce.has(fe.path)),[C,ce]),Y=f.useCallback((fe,Ce)=>{if(!Ce)return!0;const de=Ce.toLowerCase();return fe.path.toLowerCase().includes(de)||fe.displayPath.toLowerCase().includes(de)||fe.sourceName.toLowerCase().includes(de)},[]),pe=!!window.electronAPI.remote,ge=async()=>{if(pe){N(Ce=>!Ce);return}const fe=await window.electronAPI.dialog.selectDirectory();fe&&d(fe)},we=f.useCallback(fe=>window.electronAPI.projects.listHostDirs(fe).then(Ce=>Ce.ok?Ce:{error:Ce.error}),[]),V=f.useCallback((fe,Ce)=>window.electronAPI.projects.createHostDir(fe,Ce).then(de=>de.ok?de:{error:de.error}),[]),W=f.useCallback(async(fe,Ce)=>{const de=await window.electronAPI.sshConnections.listDirs(m,fe);if(de.ok)return{path:de.path,parent:PY(de.path),dirs:de.dirs};const Ee=gg(de,x.find(me=>me.id===m));return!Ee||Ce?{error:de.error}:(D("browse"),F(Ee),null)},[m,x]),B=l==="local"?u.trim().length>0:m.length>0&&p.trim().startsWith("/"),te=()=>{const fe=x.find(Ce=>Ce.id===m);s({path:p.trim(),sshConnectionId:m,sshHost:fe?.name,...j?{groupId:j}:{}}),t(!1)},Z=fe=>{if(fe.preventDefault(),!B)return;if(l!=="ssh"){s({path:u.trim(),...j?{groupId:j}:{}}),t(!1);return}if(J)return;$(!0),k("");const Ce=++oe.current,de=x.find(Ee=>Ee.id===m);window.electronAPI.sshConnections.test(m).then(Ee=>{if(Ce===oe.current){if(!Ee.ok){const me=gg(Ee,de);if(me){D("submit"),F(me);return}k(Ee.error);return}te()}}).finally(()=>{Ce===oe.current&&$(!1)})},ue=async()=>{if(!L)return;U(!0);const fe=await window.electronAPI.sshConnections.trustHost(m);if(U(!1),!fe.ok){k(fe.error||i("Could not save host key.")),F(null),D(null);return}const Ce=A;if(F(null),D(null),Ce==="browse"){H(de=>de+1);return}Ce==="submit"&&te()};return n.jsxs(cn,{open:e,onOpenChange:t,children:[n.jsx(dn,{className:"max-w-lg",children:n.jsxs("form",{onSubmit:Z,className:"flex flex-col",children:[n.jsxs(un,{children:[n.jsx(on,{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(Td,{value:l,onValueChange:fe=>{c(fe),N(!1)},children:n.jsxs(Ad,{children:[n.jsx(fs,{value:"local",children:i("Local directory")}),n.jsx(fs,{value:"ssh",children:i("Remote (SSH)")})]})}),l==="ssh"?n.jsxs(n.Fragment,{children:[n.jsxs(Ss,{className:"w-full",children:[n.jsx(Cs,{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(Sr,{items:[{value:"",label:i("Select an SSH connection")},...x.map(fe=>({value:fe.id,label:`${fe.name} (${fe.user?`${fe.user}@`:""}${fe.host})`}))],value:m,onValueChange:fe=>h(fe??""),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsxs(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(or,{value:"",children:i("Select an SSH connection")}),x.map(fe=>n.jsxs(or,{value:fe.id,children:[fe.name," (",fe.user?`${fe.user}@`:"",fe.host,")"]},fe.id))]})]})]}),n.jsxs(Ss,{className:"w-full",children:[n.jsx(Cs,{children:i("Remote directory")}),n.jsxs("div",{className:"flex w-full gap-2",children:[n.jsx(Vt,{value:p,onChange:fe=>g(fe.target.value),placeholder:"/home/user/project",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,className:"min-w-0 flex-1"}),n.jsx(he,{type:"button",variant:"outline",disabled:!m,onClick:()=>N(fe=>!fe),children:i("Browse")})]})]}),b&&m&&n.jsx(yy,{list:W,initialPath:p.trim().startsWith("/")?p.trim():void 0,reloadKey:M,onSelect:fe=>{g(fe),N(!1)},onClose:()=>N(!1)},m),n.jsx("p",{className:"text-xs text-muted-foreground",children:i("Tools run on the remote host; chat history stays local.")}),T&&n.jsx("p",{className:"text-destructive text-xs",children:T})]}):n.jsxs(Ss,{className:"w-full",children:[n.jsx(Cs,{children:i("Working directory")}),n.jsxs(xx,{value:u,onValueChange:fe=>d(fe??""),items:ne,filter:Y,itemToStringValue:fe=>fe.path,children:[n.jsxs("div",{className:"flex w-full gap-2",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(gx,{placeholder:i("Type a path or select from recent projects..."),showClear:!!u,showTrigger:!0})}),n.jsx(he,{type:"button",variant:"outline",onClick:()=>{ge()},children:i("Browse")})]}),n.jsxs(PC,{zIndex:Pn.DROPDOWN_IN_MODAL,children:[n.jsx(bx,{children:i("No matching projects found")}),n.jsx(yx,{children:fe=>n.jsxs(vx,{value:fe,className:"gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",title:fe.path,children:fe.displayPath}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:fe.sourceName})]},fe.path)})]})]}),b&&pe&&n.jsx(yy,{list:we,create:V,initialPath:u.trim()||void 0,onSelect:fe=>{d(fe),N(!1)},onClose:()=>N(!1)})]}),r.length>0&&n.jsxs(Ss,{children:[n.jsx(Cs,{children:i("Project group")}),n.jsxs(Sr,{items:Ne,value:j??"",onValueChange:fe=>w(fe||void 0),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:Ne.map(fe=>n.jsx(or,{value:fe.value,children:fe.label},fe.value||"ungrouped"))})]})]})]}),n.jsxs(ts,{children:[n.jsx(he,{type:"button",variant:"outline",size:"sm",onClick:()=>t(!1),children:i("Cancel")}),n.jsx(he,{type:"submit",size:"sm",disabled:!B||J,children:i("Add")})]})]})}),n.jsx(s3,{challenge:L,nested:!0,busy:G,onTrust:()=>{ue()},onDismiss:()=>{G||(F(null),D(null))}})]})}function wy({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(ar,{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 Nf({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 LY(e,t){return{x:e.left-t,width:Math.max(0,e.width)}}const S2="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",C2="flex size-4.5 shrink-0 items-center justify-center rounded-[5px] text-subtle-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",_Y=24,Ki=20;function BY({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(($,oe)=>$.order-oe.order),x=g.length>0,y=c||a.length>0,j=f.useRef(null),w=f.useRef(null),b=f.useRef(null),N=f.useRef(null),C=f.useRef(null),[E,T]=f.useState({left:!1,right:!1,overflow:!1}),{active:k}=nl(),L=g.find($=>$.id===t),F=t===Is?p("Ungrouped"):L?.name??null,A=F?p("Search in {{group}}...",{group:F}):p("Search conversations..."),D=f.useCallback(()=>{const $=b.current,oe=w.current,Ne=N.current,ce=C.current,ne=oe?.querySelector("[data-selected]");if(!$||!oe||!Ne||!ce||!ne||$.offsetParent===null){ce&&(ce.style.width="0px");return}const Y=oe.getBoundingClientRect(),pe=$.getBoundingClientRect(),ge=ne.getBoundingClientRect(),we=LY(ge,Y.left);Ne.style.left=`${Y.left-pe.left}px`,Ne.style.width=`${Y.width}px`,ce.style.transform=`translateX(${we.x}px)`,ce.style.width=`${we.width}px`},[]),M=f.useCallback(()=>{const $=w.current;D(),!(!$||$.clientWidth===0)&&T(oe=>{const Ne=oe.overflow?_Y:0,ce={left:$.scrollLeft>1,right:$.scrollLeft+$.clientWidth<$.scrollWidth-1,overflow:$.scrollWidth>$.clientWidth+Ne+1};return oe.left===ce.left&&oe.right===ce.right&&oe.overflow===ce.overflow?oe:ce})},[D]);f.useLayoutEffect(()=>{const $=w.current;if(!$)return;M();const oe=new ResizeObserver(M);return oe.observe($),$.firstElementChild&&oe.observe($.firstElementChild),()=>oe.disconnect()},[M]),f.useLayoutEffect(()=>{D()},[D,k,t,y,g.length]),f.useEffect(()=>{const $=w.current;if(!$)return;const oe=Ne=>{Math.abs(Ne.deltaY)<=Math.abs(Ne.deltaX)||$.scrollWidth<=$.clientWidth||($.scrollLeft+=Ne.deltaY,Ne.preventDefault())};return $.addEventListener("wheel",oe,{passive:!1}),()=>$.removeEventListener("wheel",oe)},[]);const H=f.useRef(!1);f.useLayoutEffect(()=>{const $=w.current,oe=$?.querySelector("[data-selected]");if(!$||!oe||$.clientWidth===0)return;const Ne=H.current?"smooth":"auto";H.current=!0;const ce=oe.offsetLeft,ne=ce+oe.offsetWidth;ce<$.scrollLeft+Ki?$.scrollTo({left:ce-Ki,behavior:Ne}):ne>$.scrollLeft+$.clientWidth-Ki&&$.scrollTo({left:ne-$.clientWidth+Ki,behavior:Ne})},[t,x,c]),f.useEffect(()=>{c&&j.current?.focus()},[c]);const G=()=>{l(""),u(!1)},U=$=>$?`${Ki}px`:"0px",J=E.left||E.right?`linear-gradient(to right, transparent, #000 ${U(E.left)}, #000 calc(100% - ${U(E.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:[y&&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(Yk,{className:"size-3.5 shrink-0"}),n.jsx("input",{ref:j,value:a,onChange:$=>l($.target.value),onKeyDown:$=>{$.key==="Escape"&&($.stopPropagation(),G())},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:G,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(Zt,{className:"size-3"})})]}),n.jsxs("div",{ref:b,className:_("relative flex min-w-0 flex-1 items-center gap-1.5",y&&"hidden"),children:[n.jsx("div",{ref:w,onScroll:M,style:{maskImage:J},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===qn||void 0,"data-active":t===qn||void 0,onClick:()=>d(qn),className:vd(t===qn,!1),children:n.jsx(bd,{label:p("All"),count:r})}),n.jsx("button",{type:"button","data-enso":"group-chip","data-selected":t===jr||void 0,"data-active":t===jr||void 0,onClick:()=>d(jr),className:vd(t===jr,!1),children:n.jsx(bd,{label:p("Recent"),count:o})}),n.jsx(Zm,{items:g.map($=>jx($.id)),strategy:hY,children:g.map($=>n.jsx(FY,{group:$,count:s[$.id]??0,selected:t===$.id,onSelect:()=>d($.id)},$.id))}),x&&n.jsx(zY,{label:p("Ungrouped"),count:i,selected:t===Is,onSelect:()=>d(Is)})]})}),n.jsx("span",{ref:N,"aria-hidden":!0,className:"pointer-events-none absolute -bottom-px z-10 h-[1.5px] overflow-hidden",children:n.jsx("span",{ref:C,className:"absolute top-0 left-0 h-full rounded-full bg-foreground"})}),n.jsx("button",{type:"button",onClick:m,className:_(C2,"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(Xn,{className:"size-3"})}),E.overflow&&n.jsx($Y,{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 vd(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 bd({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 I2=e=>e?.type==="project";function FY({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}=lu({id:jx(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:_(vd(s,d&&I2(m?.data.current)),u&&"z-10 cursor-grabbing text-foreground"),...o,...i,children:n.jsx(bd,{label:e.name,count:t,emoji:e.emoji,color:e.color})})}function zY({label:e,count:t,selected:s,onSelect:r}){const{active:o}=nl(),{setNodeRef:i,isOver:a}=sl({id:jx(Is),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:vd(s,a&&I2(o?.data.current)),children:n.jsx(bd,{label:e,count:t})})}function $Y({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(Rs,{open:d,onOpenChange:m,children:[n.jsx(Ms,{className:_(C2,"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(Bn,{className:"size-3"})}),n.jsxs(Ps,{side:"bottom",align:"end",className:"w-56 [&_[data-slot=popover-viewport]]:p-1",children:[n.jsx(Yl,{label:u("All"),count:r,selected:t===qn,onSelect:h(()=>a(qn))}),n.jsx(Yl,{label:u("Recent"),count:o,selected:t===jr,onSelect:h(()=>a(jr))}),e.map(p=>n.jsx(Yl,{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(Yl,{label:u("Ungrouped"),count:i,selected:t===Is,onSelect:h(()=>a(Is))}),n.jsx("div",{className:"my-1 border-t"}),n.jsxs("button",{type:"button",onClick:h(l),className:_(S2,"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[n.jsx(Xn,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:u("New group")})]})]})]})}function Yl({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:_(S2,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(Dn,{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 T2({value:e,reasoningEnabled:t,thinkingLevel:s,onChange:r,onReasoningChange:o,onThinkingChange:i,description:a,inheritLabel:l}){const{t:c}=z(),u=xe(g=>g.virtualModels),d=Aj(),m=e?d.find(g=>g.id===e.providerId):void 0,h=m?.models.find(g=>g.id===e?.modelId),p=mj(u,e);return n.jsxs(Ss,{className:"w-full items-stretch",children:[n.jsx(Cs,{children:c("Default model")}),n.jsx(Rj,{children:a}),d.length>0&&n.jsx("div",{className:"w-full min-w-0",children:n.jsx(Ej,{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:r3,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(he,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:c("Follow default model")})]})}const VY=["#3b82f6","#22c55e","#eab308","#f97316","#ef4444","#a855f7","#06b6d4","#64748b"];function HY({open:e,group:t,projects:s,onOpenChange:r,onSave:o,onDelete:i}){const{t:a}=z(),l=xe(D=>D.defaultReasoningEnabled),c=xe(D=>D.defaultThinkingLevel),[u,d]=f.useState(""),[m,h]=f.useState(),[p,g]=f.useState(null),[x,y]=f.useState(!0),[j,w]=f.useState("medium"),[b,N]=f.useState(new Set),[C,E]=f.useState(""),T=t===null,k=T?s??[]:[],L=C.trim().toLowerCase(),F=L?k.filter(D=>[D.alias??"",D.name].some(M=>M.toLowerCase().includes(L))):k;f.useEffect(()=>{if(!e)return;d(t?.name??""),h(t?.color),g(t?.defaultModel??null);const D=Oc({defaultReasoningEnabled:l,defaultThinkingLevel:c});y(t?.defaultReasoningEnabled??D.reasoningEnabled),w(t?.defaultThinkingLevel??D.thinkingLevel),N(new Set),E("")},[e,t,l,c]);const A=D=>{N(M=>{const H=new Set(M);return H.has(D)?H.delete(D):H.add(D),H})};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:D=>{D.preventDefault();const M=u.trim();M&&(o({name:M,color:m,defaultModel:p,defaultReasoningEnabled:p?x:null,defaultThinkingLevel:p?j:null,...T&&b.size>0?{projectIds:[...b]}:{}}),r(!1))},children:[n.jsxs(un,{children:[n.jsx(on,{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(Ss,{children:[n.jsx(Cs,{children:a("Name")}),n.jsx(Vt,{value:u,onChange:D=>d(D.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(Zt,{className:"h-3 w-3"})}),VY.map(D=>n.jsx("button",{type:"button",className:"h-6 w-6 rounded-full border border-border",style:{backgroundColor:D,outline:m===D?"2px solid var(--color-ring)":void 0,outlineOffset:2},onClick:()=>h(m===D?void 0:D),"aria-label":D},D))]}),n.jsx(T2,{value:p,reasoningEnabled:x,thinkingLevel:j,onChange:D=>{if(g(D),D)return;const M=Oc({defaultReasoningEnabled:l,defaultThinkingLevel:c});y(M.reasoningEnabled),w(M.thinkingLevel)},onReasoningChange:y,onThinkingChange:w,description:a("Used for new conversations in this group."),inheritLabel:a("Follows the global default")}),k.length>0&&n.jsxs(Ss,{className:"w-full items-stretch",children:[n.jsx(Cs,{children:a("Move projects into this group")}),n.jsx(Vt,{value:C,onChange:D=>E(D.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(D=>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(Bo,{checked:b.has(D.id),onCheckedChange:()=>A(D.id)}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:Un(D)})]},D.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(he,{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(he,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:a("Cancel")}),n.jsx(he,{type:"submit",size:"sm",disabled:!u.trim(),children:a("Save")})]})]})]})})})}function WY(e){return e?"copy":"move"}function UY(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 A2(e,t){return!e.some(s=>s.id===t&&s.kind==="secretary")}function E2(e,t){return A2(e,t)?e.filter(s=>s.id!==t&&s.kind!=="scratch"&&s.kind!=="secretary"):[]}const eh={running:"Cannot move a running conversation","worktree-busy":"Cannot move while its worktree is in use","source-secretary":"Secretary conversations cannot be moved"};function GY(e){return Object.hasOwn(eh,e)?eh[e]:"Failed to move conversation"}async function KY(e,t,s){try{const r=await window.electronAPI.settings.moveConversation({conversationId:e,targetProjectId:t});if(!r.ok){Ie({type:"error",title:s(GY(r.error)),...Object.hasOwn(eh,r.error)?{}:{description:r.error}});return}R2([e],t)}catch(r){Ie({type:"error",title:s("Failed to move conversation"),description:String(r)})}}function R2(e,t){e.length!==0&&X.setState(s=>{const r={...s.conversations},o={...s.worktreeStatuses};for(const i of UY(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 qY(e,t){return Object.values(e).filter(s=>s.projectId===t&&!s.parentId&&!s.btwParentId).length}async function YY(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"&&R2(o.imported,t);const i=o.imported.length;if(o.skipped.length>0){const{conversations:a}=X.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 XY(e,t){try{const s=await window.electronAPI.settings.removeEmptyProject({projectId:e});return s.ok?(xe.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 QY({project:e,onClose:t}){const{t:s}=z(),r=xe(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(b=>{!w||!b.ok||(u(b),l(WY(b.sourceExists)))}).catch(()=>{}),()=>{w=!1}},[e,o]);const g=f.useMemo(()=>{if(!e)return[];const{conversations:w}=X.getState();return E2(r,e.id).map(b=>({project:b,count:qY(w,b.id)}))},[e,r]),x=g.find(w=>w.project.id===o),y=async()=>{if(!(!e||!x)){m(!0);try{const w=await YY(x.project.id,e.id,a,s);if(!w)return;w.offerRemoveSource&&p(x.project),t()}finally{m(!1)}}},j=[{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(on,{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:b})=>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:b})})]},w.id))}),x&&n.jsx(o3,{value:a,onValueChange:w=>l(w),className:"grid gap-2","aria-label":s("Import mode"),children:j.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(i3,{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(he,{variant:"outline",onClick:t,children:s("Cancel")}),n.jsxs(he,{onClick:()=>{y()},disabled:d||!x||x.count===0,children:[d?n.jsx(si,{className:"mr-1.5 size-3.5"}):a==="move"?n.jsx(Wk,{className:"mr-1.5 h-3.5 w-3.5"}):n.jsx(Xa,{className:"mr-1.5 h-3.5 w-3.5"}),s(d?a==="move"?"Moving…":"Copying…":a==="move"?"Move here":"Copy here")]})]})]})}),n.jsx(hs,{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&&XY(h.id,s)}})]})}function JY({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(!1);f.useEffect(()=>{if(!e)return;let h=!0;return o(null),a(null),c(null),window.electronAPI.sessionImport.scan(e.path).then(p=>{h&&o(p)}).catch(()=>{h&&o([])}),()=>{h=!1}},[e]),f.useEffect(()=>{if(!i){c(null);return}let h=!0;return c(null),window.electronAPI.sessionImport.read(i.sourceId,i.path).then(p=>{h&&c(p)}).catch(()=>{h&&c([])}),()=>{h=!1}},[i]);const m=async()=>{if(!(!e||!i)){d(!0);try{const h=await window.electronAPI.sessionImport.import(i.sourceId,i.path,e.path);h&&(X.getState().addImportedConversation(e.id,h),t())}finally{d(!1)}}};return n.jsx(cn,{open:e!==null,onOpenChange:h=>!h&&t(),children:n.jsxs(dn,{className:"max-w-3xl",children:[n.jsxs(un,{children:[n.jsx(on,{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(si,{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(h=>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:h.sourceName}),h.sessions.map(p=>n.jsxs("button",{type:"button",onClick:()=>a({sourceId:h.sourceId,path:p.path}),className:_("w-full px-2.5 py-1.5 text-left",i?.path===p.path?"bg-muted":"hover:bg-muted/50"),children:[n.jsx("p",{className:"truncate text-xs",children:p.title||s("Untitled")}),n.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[new Date(p.updatedAt).toLocaleString()," ·"," ",s("{{count}} messages",{count:p.messageCount})]})]},p.path))]},h.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(si,{className:"size-4"})}):n.jsx("div",{className:"flex flex-col gap-2.5",children:l.map((h,p)=>n.jsx("div",{className:_("max-w-[90%] rounded-lg px-2.5 py-1.5 text-xs whitespace-pre-wrap",h.role==="user"?"self-end bg-primary/10":"self-start bg-background border"),children:h.text.length>600?`${h.text.slice(0,600)}…`:h.text},p))}):n.jsx("p",{className:"py-12 text-center text-xs text-muted-foreground",children:s("Select a session to preview")})})]})}),n.jsxs(ts,{children:[n.jsx(he,{variant:"outline",onClick:t,children:s("Cancel")}),n.jsxs(he,{onClick:()=>{m()},disabled:!i||u,children:[u?n.jsx(si,{className:"mr-1.5 size-3.5"}):n.jsx(Nd,{className:"mr-1.5 h-3.5 w-3.5"}),s("Import")]})]})]})})}function ZY({open:e,project:t,onOpenChange:s}){const{t:r}=z(),o=xe(ce=>ce.projectGroups),i=xe(ce=>ce.defaultReasoningEnabled),a=xe(ce=>ce.defaultThinkingLevel),l=xe(ce=>ce.setProjectDefaultModel),c=xe(ce=>ce.setProjectGroupId),u=xe(ce=>ce.setProjectAlias),d=xe(ce=>ce.setProjectDisabledBuiltinTools),m=xe(ce=>ce.setProjectSubagentAllowedModes),h=xe(ce=>ce.setProjectTrustedCode),p=xe(ce=>ce.disabledBuiltinTools),g=xe(ce=>ce.subagentAllowedModes),[x,y]=f.useState(""),[j,w]=f.useState(null),[b,N]=f.useState(!0),[C,E]=f.useState("medium"),[T,k]=f.useState(""),[L,F]=f.useState(!0),[A,D]=f.useState([]),[M,H]=f.useState(!0),[G,U]=f.useState([]),[J,$]=f.useState(!1);f.useEffect(()=>{if(!e)return;$(!1),w(t?.defaultModel??null),k(t?.groupId??""),y(t?.alias??"");const ce=t?.groupId?o.find(ge=>ge.id===t.groupId):void 0,ne=Oc({groupReasoningEnabled:ce?.defaultReasoningEnabled,groupThinkingLevel:ce?.defaultThinkingLevel,defaultReasoningEnabled:i,defaultThinkingLevel:a});N(t?.defaultReasoningEnabled??ne.reasoningEnabled),E(t?.defaultThinkingLevel??ne.thinkingLevel);const Y=t?.disabledBuiltinTools===void 0;F(Y),D(Y?[...p]:[...t?.disabledBuiltinTools??[]]);const pe=t?.subagentAllowedModes===void 0;H(pe),U(pe?[...g]:[...t?.subagentAllowedModes??[]])},[e,t,o,i,a,p,g]);const oe=f.useMemo(()=>[{value:"",label:r("Ungrouped")},...o.slice().sort((ce,ne)=>ce.order-ne.order).map(ce=>({value:ce.id,label:ce.name}))],[o,r]),Ne=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:ce=>{ce.preventDefault(),t&&(l(t.id,j,j?{reasoningEnabled:b,thinkingLevel:C}:null),c(t.id,T||null),u(t.id,x),d(t.id,L?null:A),m(t.id,M?null:G),J&&h(t.id,null),s(!1))},children:[n.jsxs(un,{children:[n.jsx(on,{children:r("Project settings")}),n.jsx(ys,{children:t?Un(t):r("Project")})]}),n.jsxs(In,{className:"max-h-[60vh] space-y-4",children:[n.jsxs(Ss,{className:"w-full items-stretch",children:[n.jsx(Cs,{children:r("Alias")}),n.jsx(Vt,{value:x,onChange:ce=>y(ce.target.value),placeholder:t?Un({...t,alias:void 0}):""}),n.jsx(Rj,{children:r("Shown in the sidebar instead of the folder name. Leave blank to reset.")})]}),n.jsxs(Ss,{className:"w-full items-stretch",children:[n.jsx(Cs,{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:Ne,children:Ne}),n.jsx(mh,{text:Ne,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(Ss,{className:"w-full items-stretch",children:[n.jsx(Cs,{children:r("Project group")}),n.jsxs(Sr,{items:oe,value:T,onValueChange:ce=>k(ce??""),children:[n.jsx(Cr,{className:"w-full",children:n.jsx(Ir,{})}),n.jsx(Tr,{zIndex:Pn.DROPDOWN_IN_MODAL,children:oe.map(ce=>n.jsx(or,{value:ce.value,children:ce.label},ce.value||"ungrouped"))})]})]}),n.jsx(T2,{value:j,reasoningEnabled:b,thinkingLevel:C,onChange:ce=>{if(w(ce),ce)return;const ne=T?o.find(pe=>pe.id===T):void 0,Y=Oc({groupReasoningEnabled:ne?.defaultReasoningEnabled,groupThinkingLevel:ne?.defaultThinkingLevel,defaultReasoningEnabled:i,defaultThinkingLevel:a});N(Y.reasoningEnabled),E(Y.thinkingLevel)},onReasoningChange:N,onThinkingChange:E,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(sr,{checked:L,onCheckedChange:F})]}),!L&&n.jsx("div",{className:"space-y-2",children:a3.map(ce=>n.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5",children:[n.jsx(Ch,{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(ce.name)}),n.jsx("p",{className:"text-muted-foreground text-xs",children:r(ce.description)})]}),n.jsx(sr,{checked:!A.includes(ce.id),onCheckedChange:ne=>D(Y=>ne?Y.filter(pe=>pe!==ce.id):[...new Set([...Y,ce.id])])})]},ce.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(sr,{checked:M,onCheckedChange:ce=>{H(ce),ce||U([...g])}})]}),!M&&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(([ce,ne])=>n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx("span",{className:"text-sm",children:r(ne)}),n.jsx(sr,{checked:G.includes(ce),disabled:(L?p:A).includes("subagent"),onCheckedChange:Y=>U(pe=>Y?[...new Set([...pe,ce])]:pe.filter(ge=>ge!==ce))})]},ce)),(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(Ao,{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(`
81
- `),children:t.trustedProjectCode.join(", ")}),J&&n.jsx("p",{className:"text-muted-foreground text-xs",children:r("No longer loaded after saving, starting with the next session.")})]}),n.jsx(he,{type:"button",size:"xs",variant:"outline",disabled:J,onClick:()=>$(!0),children:r("Revoke trust")})]}):null]}),n.jsxs(ts,{children:[n.jsx(he,{type:"button",variant:"outline",size:"sm",onClick:()=>s(!1),children:r("Cancel")}),n.jsx(he,{type:"submit",size:"sm",disabled:!t,children:r("Save")})]})]})})})}const eX={connecting:"Connecting…","host-offline":"Desktop is offline",unauthorized:"Pairing expired",replaced:"Open in another page",offline:"Reconnecting…"};function tX(e){return e==="online"?"ok":e==="connecting"||e==="offline"?"pending":"error"}function M2(e,t){if(e.state!=="online")return t(eX[e.state]);const s=e.transport==="direct"?t("Direct link"):t("Via relay"),r=l3(e.rttMs);return r?`${t("Connected")} · ${s} · ${r}`:`${t("Connected")} · ${s}`}function nX(){return"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window}function sX(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 rX(e){return e==="AbortError"?"service-unreachable":e==="NotAllowedError"?"permission-denied":"subscribe-failed"}async function oX(e){if(!nX())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:sX(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:rX(o)}}}const P2="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 D2(){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 iX(e,t){return e.pushError?t(O2[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 O2={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 jy(){const{t:e}=z(),t=D2();if(!t)return null;const s=M2(t,e),r=iX(t,e),o=t.pushBusy||t.pushAvailability!=="ok"||!t.pushReady||t.state!=="online"&&!t.pushEnabled;return n.jsxs(Rs,{children:[n.jsx(Ms,{className:P2,title:s,"aria-label":s,children:n.jsx(Qa,{className:"h-4 w-4"})}),n.jsxs(Ps,{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(Mj,{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(sr,{checked:t.pushEnabled,disabled:o,title:r,"aria-label":r,onCheckedChange:()=>{lX(t)}})]}),t.pushError&&n.jsx("p",{className:"mt-2 text-destructive text-xs",children:e(O2[t.pushError])})]})]})}const aX={ok:"bg-success",pending:"bg-warning",error:"bg-destructive"};function ky({compact:e=!1}){const{t}=z(),s=D2();if(!s)return null;const r=`${s.deviceLabel} · ${M2(s,t)}`,o=_("size-1.5 shrink-0 rounded-full",aX[tX(s.state)]);return n.jsxs("button",{type:"button",onClick:()=>window.electronAPI.remote?.openDevices?.(),title:r,"aria-label":`${t("Computers and notifications")} · ${r}`,className:e?_(P2,"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(Mj,{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 lX(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 oX(s);if(!r.ok){t.setPushPending({busy:!1,enabled:!1,error:r.reason});return}t.setPushSubscription(r.subscription)}function cX(e){return!e?.linkStatus||!e.onLinkStatus?null:e.openDevices?"devices":"info"}function dX(e){return!!e?.exitDesk&&!e?.openDevices}const th="default";function uX(e,t){return e&&!t}function fX(e,t){return jt(s=>{const r=e??MG(s.states,t??"")?.secretaryId??(s.secretaries.length===0||!t?s.focusedId??th: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 mX({secretaryId:e=th,conversationId:t,muted:s=!1}){const{t:r}=z(),o=fX(e===th?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(Ac,{children:[n.jsx(Ec,{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(Ap,{className:"size-2.5","aria-hidden":!0})}):n.jsx(kd,{name:i,color:c?.color,image:c?.imageVersion?Ka(c.imageVersion,c.imageHash,e):void 0,enso:"secretary-origin-face",className:"size-3.5 rounded-[4px] text-[8px]"})}),n.jsx(Rc,{side:"top",children:l})]})}function hX(e){return e.kind==="session"?e.secretaryConversationId:e.kind==="pending"?e.pending.secretaryConversationId:e.proposal.secretaryConversationId}function L2(e,t){const s={},r=new Map,o=[];for(const a of e.running){const l=hX(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 pX(e,t,s){const r={};for(const{id:o}of e){const i=t[o];i&&(r[o]=L2(i.board,s))}return r}function Ny(e){return e.kind==="session"?`s:${e.conversationId}`:e.kind==="pending"?`p:${e.pending.id}`:`x:${e.proposal.id}`}function Sy(e){if(e.kind==="session")return e.title;if(e.kind==="pending")return e.pending.draft.title}function xX({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(Bt,{className:"h-3 w-3 animate-spin","aria-hidden":!0}),e]}):null}function gX({label:e,groups:t,titleOf:s,onSelect:r}){const{t:o}=z();return n.jsxs(xl,{children:[n.jsx(gl,{render:n.jsx("span",{"data-enso":"secretary-running-origins",className:"shrink-0"}),children:e}),n.jsx(tu,{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:()=>iV(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:Sy(u)||o("Unnamed")},Ny(u)):n.jsx("div",{className:"truncate pr-1.5 pl-4 text-[11.5px] text-muted-foreground",children:Sy(u)||o("Unnamed")},Ny(u)))]},a??"")})})]})}function Cy(e,t,s){if(!e.enabled)return null;const r=e.profile,o=r?.avatar.imageVersion,i=s??e.secretaryId??void 0;return{name:r?.name.trim()||t("Secretary"),needsYou:e.board.needsYou.length,running:e.board.running.length,configured:r!==null,...r?{color:r.avatar.color}:{},...o?{image:Ka(o,r?.avatar.imageHash,i)}:{}}}function vX({view:e,runningExpanded:t,onToggleRunning:s,origins:r}){const{t:o}=z();return e.configured?e.needsYou===0&&e.running===0?n.jsx(n.Fragment,{children:o("Nothing running")}):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&&e.running>0&&" · ",e.running>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:o("{{n}} running",{n:e.running})}):r?n.jsx(gX,{label:o("{{n}} running",{n:e.running}),...r}):n.jsx("span",{className:"shrink-0",children:o("{{n}} running",{n:e.running})}))]}):n.jsx(n.Fragment,{children:o("Click to finish setup")})}const Sf="flex size-5 shrink-0 items-center justify-center rounded-[5px] text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground";function bX({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(Bn,{"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:yX,children:n.jsx(Xn,{className:"size-3.5"})})]})}const yX="-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 wX(e){return e.filter(t=>t.kind!=="scratch"&&t.kind!=="secretary")}function Iy({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(xh,{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(Bn,{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(vX,{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:Sf,children:n.jsx(Ds,{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:Sf,children:n.jsx(Xn,{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:_(Sf,"hidden [@media(hover:none)]:flex"),children:n.jsx(Bn,{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(Yt,{onClick:o,children:[n.jsx(Xn,{}),h("New conversation")]}),n.jsxs(Yt,{onClick:i,children:[n.jsx(Ds,{}),h("Secretary settings")]}),n.jsxs(Yt,{onClick:a,children:[n.jsx(ro,{}),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 jX({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(xh,{name:e.name,color:e.color,image:e.image,needsYou:e.needsYou,running:e.running,size:"xs"})})}function kX(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 Ty(e,t,s){return e?Co(t,s,e):[]}function Sc(e){const t=typeof e=="string"&&e.length>0?e:void 0,s=jt.getState(),r=X.getState(),o=t?s.secretaries.filter(d=>d.id===t):s.secretaries;let i=null;for(const d of o){const m=kX(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=jt.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){jt.getState().openWelcome();return}jt.getState().newSecretaryConversation({secretaryId:a})}}const Ua=5,_2=15,Ay=9;function Ga(e,t){return e<=0?0:Math.min(e,Ua+Math.max(0,t))}function Ey(e,t){return Ga(e,t)>=e?0:Math.min(Math.max(0,e-Ua),t+_2)}function Ry(e){return Math.max(0,e-_2)}function NX(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=y=>{p.has(y)||h.length>=Ay||(p.add(y),h.push(y))};for(const y of m)g(y);const x=Pj(t,s,r,i);for(const y of c?x.filter(u):x)g(y);for(const y of o){if(h.length>=Ay)break;if(c?!1:a[y]===!0)continue;const w=Co(t,s,y),b=!c||d(y)?w:w.filter(u),N=c?b:b.slice(0,Ga(b.length,l[y]??0));for(const C of N)g(C)}return h}function Ix(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 Xl(e,t,s,r){const o=Ix(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 SX(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 CX(e,t){return e.includes(t)?e.filter(s=>s!==t):[t,...e]}function IX(e,t,s){const r=s.includes(e),o=s.includes(t);return r&&o?"pinned":!r&&!o?"order":null}function Cf(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function My(e){return e==="browser"||typeof e=="string"&&e.startsWith("browser:")}function TX(e){if(typeof e.contentComponent=="string")return e.contentComponent;if(typeof e.component=="string")return e.component}function Py(e){if(!Cf(e)||!Cf(e.panels))return{browsers:0,terminals:0};let t=0,s=0;for(const[r,o]of Object.entries(e.panels)){if(!Cf(o))continue;const i=TX(o);i==="browser"||My(o.id)||My(r)?t+=1:i==="terminal"&&(s+=1)}return{browsers:t,terminals:s}}function AX({conversationId:e}){const{t}=z(),s=os(o=>Py(o.layouts[e]).browsers),r=os(o=>Py(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(Ro,{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 EX="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",RX="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",MX="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",PX=[7,15,30],qi="h-6.5 rounded-lg px-2 text-xs text-subtle-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",Dy="enso-collapsed-scratch",If="enso-collapsed-secretary",Oy="enso-collapsed-secretary-group",Ly="enso-collapsed-secretaries",Ql=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",Tf="-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 _y({width:e,collapsed:t,onToggleCollapse:s,onOpenSearch:r,onNavigate:o}){const{t:i,locale:a}=z(),l=xe(O=>O.projects),u=Fh()==="mobile",d=cX(window.electronAPI.remote),m=dX(window.electronAPI.remote),h=xe(O=>O.scratchSessionsEnabled),p=xe(O=>O.projectGroups),g=xe(O=>O.createProjectGroup),x=xe(O=>O.updateProjectGroup),y=xe(O=>O.removeProjectGroup),j=xe(O=>O.reorderProjectGroups),w=xe(O=>O.setProjectGroupId),b=xe(O=>O.keybindings),N=xe(O=>O.activeRetentionMinutes),C=xe(O=>O.headerRecentMinutes),E=ms(O=>O.dismissed),T=Mr(b)["search-workspace"],k=T?Gs(T):"",L=xe(O=>O.addProject),F=xe(O=>O.removeProject),A=X(O=>Kd(O.conversations)),D=X(O=>O.order),M=X(O=>O.activeId),H=X(O=>O.newConversation),G=X(O=>O.selectConversation),U=f.useRef(o);U.current=o;const J=f.useCallback(O=>{U.current?.(),pN(),G(O)},[G]),$=X(O=>O.removeConversation),oe=X(O=>O.togglePinConversation),Ne=X(O=>O.toggleArchiveConversation),ce=X(O=>O.moveConversationToWorktree),ne=X(O=>O.cleanupWorktree),Y=X(O=>O.refreshWorktreeStatuses),pe=X(O=>O.worktreeStatuses),[ge,we]=f.useState(()=>{try{return JSON.parse(localStorage.getItem("enso-collapsed-projects")??"{}")}catch{return{}}}),V=O=>{we(ae=>{const He={...ae,[O]:!ae[O]};return localStorage.setItem("enso-collapsed-projects",JSON.stringify(He)),He})},[W,B]=f.useState(()=>{try{return localStorage.getItem(Dy)==="1"}catch{return!1}}),te=O=>{try{localStorage.setItem(Dy,O?"1":"0")}catch{}},Z=()=>{B(O=>{const ae=!O;return te(ae),ae})},ue=()=>{B(O=>O&&(te(!1),!1))},[fe,Ce]=f.useState(()=>nr(hc)),de=Ix(wX(l),fe),Ee=l.find(O=>O.kind==="scratch"),me=jt(O=>O.secretary),Ve=jt(O=>O.secretaries),at=jt(O=>O.states),Fe=Ve.length>1,tt=f.useMemo(()=>Cy(me,i),[me,i]),je=f.useMemo(()=>Fe?Ve.flatMap(O=>{const ae=at[O.id],He=ae?Cy(ae,i,O.id):null;return He?[{id:O.id,projectId:O.projectId,view:He}]:[]}):[],[Fe,Ve,at,i]),Je=f.useMemo(()=>{const O=ae=>A[ae]!==void 0;return{single:L2(me.board,O),byId:Fe?pX(Ve,at,O):{}}},[Fe,Ve,at,me.board,A]),rt=O=>O&&{groups:O.groups,titleOf:ae=>A[ae]?.title,onSelect:J},[K,Q]=f.useState(()=>{try{return localStorage.getItem(Oy)==="1"}catch{return!1}}),Ae=()=>{Q(O=>{try{localStorage.setItem(Oy,O?"0":"1")}catch{}return!O})},[pt,Dt]=f.useState(()=>{try{const O=localStorage.getItem(Ly),ae=O?JSON.parse(O):[];return Array.isArray(ae)&&ae.length===0&&localStorage.getItem(If)==="1"?["default"]:Array.isArray(ae)?ae.filter(He=>typeof He=="string"):[]}catch{return[]}}),Xe=O=>{Dt(ae=>{const He=ae.includes(O)?ae.filter(it=>it!==O):[...ae,O];try{localStorage.setItem(Ly,JSON.stringify(He))}catch{}return He})},[kt,mn]=f.useState(()=>{try{return localStorage.getItem(If)==="1"}catch{return!1}}),_e=()=>{mn(O=>{try{localStorage.setItem(If,O?"0":"1")}catch{}return!O})},[Nt,Ot]=f.useState(!1),[_t,se]=f.useState(null),Oe=f.useMemo(()=>Ty(me.projectId,D,A),[D,A,me.projectId]),ot=Nt?Oe:Oe.slice(0,Ql),[ct,xt]=f.useState(()=>nr(wr));f.useEffect(()=>TF(()=>we(km())),[]),f.useEffect(()=>oN(()=>{xt(nr(wr))}),[]);const[gt,Ft]=f.useState(()=>nr(fv)),Ht=O=>{Ft(O),Hr(fv,O)},tn=O=>{if(Ht(CX(gt,O)),!gt.includes(O)&&ct.includes(O)){const ae=ct.filter(He=>He!==O);xt(ae),Hr(wr,ae)}},Jt=O=>{const ae=ct.includes(O)?ct.filter(He=>He!==O):[...ct,O];xt(ae),Hr(wr,ae),!ct.includes(O)&&gt.includes(O)&&Ht(gt.filter(He=>He!==O))},[Gt,gn]=f.useState(()=>{try{return localStorage.getItem("enso-selected-project-group")??qn}catch{return qn}}),[Qn,bt]=f.useState(()=>{try{return JSON.parse(localStorage.getItem("enso-collapsed-project-groups")??"{}")}catch{return{}}}),sn=O=>{gn(O),localStorage.setItem("enso-selected-project-group",O)},Tn=O=>{bt(ae=>{const He={...ae,[O]:!ae[O]};return localStorage.setItem("enso-collapsed-project-groups",JSON.stringify(He)),He})},S=Gt===qn||Gt===jr||Gt===Is||p.some(O=>O.id===Gt)?Gt:qn,P=S===jr,I=p.find(O=>O.id===S)?.id,v=Bi(de,p,ct,S),R=c3(Bi(de,p,ct,qn),D,A,Date.now()),{pinned:ee,rest:re}=P?{pinned:[],rest:R}:SX(v,gt),Se=d3(re,p,[]),Re=[...ee,...re],We=Re.map(O=>O.id),Ge=new Set(We),[St,Qe]=f.useState(()=>nr(ym)),{active:le}=nl(),ke=le?.data.current;Fj({onDragEnd:O=>{const ae=O.active.data.current;if(!ae)return;const He=O.over?String(O.over.id):null,it=jK(ae,He,M??void 0,{projectGroupId:vt=>l.find(vn=>vn.id===vt)?.groupId});if(it)switch(it.kind){case"move-project-to-group":{if(P&&it.beforeProjectId)break;if(w(it.projectId,it.groupId),it.beforeProjectId){const vt=Xl(l,fe,it.projectId,it.beforeProjectId);Ce(vt),Hr(hc,vt)}break}case"reorder-groups":j(it.activeId,it.overId);break;case"reorder-projects":{if(P)break;const vt=IX(it.activeId,it.overId,gt);if(vt==="pinned"){const rs=Xl(gt.map($r=>({id:$r})),gt,it.activeId,it.overId);Ht(rs);break}if(vt!=="order")break;const vn=Xl(l,fe,it.activeId,it.overId);Ce(vn),Hr(hc,vn);break}case"insert-file-mention":dv({kind:"file",id:it.path,label:it.label,relativePath:it.path});break;case"insert-chat-mention":dv({kind:"chat",id:it.conversationId,label:it.label,sessionFile:it.sessionFile});break;case"pin-conversation":oe(it.conversationId);break;case"reorder-pinned":{const vt=Xl(hn.map(vn=>({id:vn})),St,it.activeId,it.overId);Qe(vt),Hr(ym,vt);break}}}});const[Le,Be]=f.useState(null),[Ze,ht]=f.useState(null),[lt,$e]=f.useState(!1),[nt,Ye]=f.useState(!1),[et,dt]=f.useState(null),qe=O=>{if(!O.sshConnectionId){cN(O.path,{groupId:O.groupId??I,onSelect:J}).catch(He=>{Ie({type:"error",title:i("Failed to add project"),description:He instanceof Error?He.message:String(He)})});return}const ae=new Set(l.map(He=>He.id));dt({name:xj(O.path),path:O.path,sshHost:O.sshHost}),L(O.path,{sshConnectionId:O.sshConnectionId},O.groupId??I).then(He=>{if(He){if(ct.includes(He.id)){const it=ct.filter(vt=>vt!==He.id);xt(it),Hr(wr,it)}if(ae.has(He.id)){we(vt=>{if(vt[He.id]!==!0)return vt;const vn={...vt,[He.id]:!1};return localStorage.setItem("enso-collapsed-projects",JSON.stringify(vn)),vn});const it=Co(D,A,He.id)[0];if(it){J(it);return}}H(He.id)}}).catch(He=>{Ie({type:"error",title:i("Failed to add project"),description:He instanceof Error?He.message:String(He)})}).finally(()=>dt(null))},[ve,be]=f.useState(null),[Me,Te]=f.useState(null),[ye,Pe]=f.useState(null),ft=async O=>{const ae=A[O];let He;if(ae?.worktree){const it=await hu(O);sc(it)&&(He=Wx(it))}Pe({kind:"conversation",id:O,worktreeWarning:He})},[Ct,Rt]=f.useState({}),[Tt,q]=f.useState(0),[At,Kt]=f.useState(""),qt=ms(O=>O.modHeld),Et=f.useCallback(O=>{ms.setState({modHeld:O})},[]),[Mt,Wt]=f.useState(()=>Date.now());f.useEffect(()=>{const O=setInterval(()=>Wt(Date.now()),u3);return()=>clearInterval(O)},[]);const jn={now:Mt,ms:N*6e4},Qt=f3(D,A,ct,jn),kn=O=>{const ae=$y(l,A[O].projectId),He=b3(O,A,jn);if(He===void 0)return ae;const it=i("Stays in Active for about {{count}} more min",{count:Math.ceil(He/6e4)});return ae?`${ae}
82
- ${it}`:it},hn=Pj(D,A,St,ct),an=m3(D,A,de.map(O=>O.id),ct).filter(O=>h||O.projectId!==Ee?.id),Ut=At.trim().length>0,An=O=>Ui(At,[A[O]?.title||i("New conversation")]),Nn=Ee?Co(D,A,Ee.id).filter(O=>!Ut||An(O)):[],Rn=Ut?!1:W,Rx=Ut?Nn.length:Ga(Nn.length,Tt),bl=Nn.slice(Rx),yl=O=>{const ae=A[O]?.projectId;return!ae||Ge.has(ae)},wl=(Ut?Qt.filter(An):Qt).filter(yl),J2=NX({order:D,conversations:A,pinnedOrderIds:St,projectIds:We,archivedProjectIds:ct,collapsedProjects:ge,revealedExtras:Ct,searching:Ut,matches:An,projectMatches:O=>{const ae=de.find(He=>He.id===O);return!!(ae&&Ui(At,[ae.alias??"",ae.name,ae.path]))},leadingIds:wl}),jl=h3(Qt.filter(yl),D,A,ct,{now:Mt,ms:C*6e4},yl,E);M&&A[M]&&!A[M].parentId&&(jl.includes(M)||jl.push(M));const kl=ms(O=>O.headerMounted)?jl.slice(0,9):J2,Mx=f.useRef(kl);Mx.current=kl,f.useEffect(()=>qB(jl,kl));const Nl=(Ut?hn.filter(An):hn).filter(yl),Z2=new Set(Nl),eI=new Set(wl),Vo=(O,ae)=>{if(t||!qt)return;const He=kl.indexOf(O);if(!(He<0||(eI.has(O)?"active":Z2.has(O)?"pinned":"project")!==ae))return Gs(`mod+${He+1}`)},[tI,cu]=f.useState(!1),[Li,Px]=f.useState(""),[Dx,Ox]=f.useState(null),Br=SY(S,p),[Lx,Sl]=f.useState(null),Qs=Lx??Br,du={projects:l,projectGroups:p,conversations:A},nI=Li.trim()?an.map(O=>{const ae=l.find(it=>it.id===O.projectId);return O.projectArchived===!0&&!!(ae&&Ui(Li,[ae.alias??"",ae.name,ae.path]))?O:{...O,ids:O.ids.filter(it=>Ui(Li,[A[it]?.title||i("New conversation")]))}}).filter(O=>O.ids.length>0):an,_x=kf(nI,Qs,du),Bx=gy(kf(an,Br,du)),sI=gy(kf(an,Qs,du)),Fx=CY(an,A),zx=O=>(Fe?je.find(ae=>ae.id===O)?.view.name:tt?.name)??i("Secretary"),$x=Br.kind==="group"?p.find(O=>O.id===Br.groupId)?.name??"":Br.kind==="ungrouped"?i("Ungrouped"):i("All archived"),rI=Qs.kind==="group"?i("Archived in group “{{name}}”",{name:$x}):Qs.kind==="ungrouped"?i("Archived in ungrouped projects"):Qs.kind==="secretary"?i("Archived sessions dispatched by {{name}}",{name:zx(Qs.secretaryId)}):Qs.fallbackFrom==="recent"?i("“Recent” has no archive scope; showing all archived"):i("Showing all archived"),Vx=()=>{Px(""),Sl(null),cu(!0)};f.useEffect(()=>{S!==Gt&&(gn(qn),localStorage.setItem("enso-selected-project-group",qn))},[S,Gt]),f.useEffect(()=>{const O=vt=>{const rs=(yg?vt.metaKey:vt.ctrlKey)&&!vt.shiftKey&&!vt.altKey;if(Et(rs),!rs||vt.repeat)return;const $r=Number(vt.key);if($r<1||$r>9)return;const mo=Mx.current[$r-1];mo&&(vt.preventDefault(),J(mo))},ae=vt=>{const vn=yg?vt.metaKey:vt.ctrlKey;Et(vn&&!vt.shiftKey&&!vt.altKey)},He=()=>Et(!1),it=()=>{document.hidden&&He()};return window.addEventListener("keydown",O),window.addEventListener("keyup",ae),window.addEventListener("blur",He),document.addEventListener("visibilitychange",it),()=>{window.removeEventListener("keydown",O),window.removeEventListener("keyup",ae),window.removeEventListener("blur",He),document.removeEventListener("visibilitychange",it)}},[J,Et]),f.useEffect(()=>{Y();const O=setInterval(()=>{Y()},3e4),ae=()=>{Y()};return window.addEventListener("focus",ae),()=>{clearInterval(O),window.removeEventListener("focus",ae)}},[Y]);const[uo,uu]=f.useState(null),[fu,mu]=f.useState(null),hu=async O=>{const ae=await window.electronAPI.worktree.status(O);return ae.ok?ae.value:void 0},pu=async(O,ae)=>{const He=await ne(O);if(He){Ie({type:"error",title:i("Failed to clean up worktree"),description:He});return}ae&&Ne(O),Y()},fo=async O=>{const ae=await hu(O);if(sc(ae)){uu({kind:"cleanup",id:O,status:ae});return}await pu(O,!1)},Fr=async O=>{const ae=A[O];if(!ae)return;if(ae.archived||!ae.worktree){Ne(O);return}const He=await hu(O);if(sc(He)){uu({kind:"archive",id:O,status:He});return}await pu(O,!0)},Hx=async O=>{for(const ae of O)!A[ae]||A[ae].archived||await Fr(ae)},zr=async(O,ae=!1)=>{const He=await ce(O,{allowDirtyMainTree:ae});if(He===Tj){mu(O);return}if(He){Ie({type:"error",title:i("Failed to move to worktree"),description:He});return}Y()},Wx=O=>{const ae=[];return O?.dirty&&ae.push(i("Uncommitted changes")),O&&O.ahead>0&&ae.push(i("{{n}} unmerged commits (branch is kept)",{n:O.ahead})),ae.join("; ")};return n.jsxs(ks.aside,{initial:!1,animate:{width:t?48:e},transition:di,"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?je.length>0:tt)&&n.jsx(jX,{view:Fe&&je[0]?{...je[0].view,needsYou:je.reduce((O,ae)=>O+ae.view.needsYou,0),running:je.reduce((O,ae)=>O+ae.view.running,0)}:tt,onClick:()=>Sc()}),n.jsx("button",{type:"button",onClick:()=>$e(!0),className:zs,title:i("Add project"),children:n.jsx(gm,{className:"h-4 w-4"})}),n.jsx("div",{className:"flex-1"}),d==="devices"&&n.jsx(ky,{compact:!0}),d==="info"&&n.jsx(jy,{}),n.jsx(by,{className:zs}),n.jsx(wy,{count:Bx,onClick:Vx,className:zs}),m&&n.jsx("button",{type:"button",onClick:()=>window.electronAPI.remote?.exitDesk?.(),className:zs,title:i("Compact view"),children:n.jsx(vg,{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(Ds,{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(BY,{groups:p,selectedId:S,counts:Object.fromEntries(p.map(O=>[O.id,Bi(de,p,ct,O.id).length])),totalCount:Bi(de,p,ct,qn).length,recentCount:R.length,ungroupedCount:Bi(de,p,ct,Is).length,query:At,onQueryChange:Kt,searchOpen:nt,onSearchOpenChange:Ye,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&&je.length>0?n.jsxs("div",{children:[n.jsx(bX,{count:je.length,folded:K,needsYou:je.reduce((O,ae)=>O+ae.view.needsYou,0),onToggleFold:Ae,onCreate:()=>{jt.getState().createSecretary()}}),!K&&je.map((O,ae)=>{const He=pt.includes(O.id),it=Ty(O.projectId,D,A),vt=He?[]:it.slice(0,Ql);return n.jsx(Iy,{view:O.view,folded:He,divider:ae===je.length-1,onToggleFold:()=>Xe(O.id),onOpen:()=>Sc(O.id),onNewConversation:()=>{jt.getState().newSecretaryConversation({secretaryId:O.id})},onOpenSettings:()=>p3(O.id),onReset:()=>se(O.id),secretaryId:O.id,keepAvatar:!0,runningOrigins:rt(Je.byId[O.id]),children:vt.map(vn=>n.jsx(vo,{id:vn,conversation:A[vn],active:M===vn,dispatchRunning:Je.byId[O.id]?.counts[vn],switchHint:Vo(vn,"project"),locale:a,nowTick:Mt,hoverTitle:O.view.name,onSelect:J,onTogglePin:oe,onToggleArchive:rs=>{Fr(rs)},onCleanupWorktree:rs=>{fo(rs)},onMoveToWorktree:rs=>{zr(rs)},onRemove:rs=>{ft(rs)}},vn))},O.id)})]}):tt&&n.jsxs(Iy,{view:tt,folded:kt,onToggleFold:_e,onOpen:Sc,onNewConversation:()=>{jt.getState().newSecretaryConversation()},onOpenSettings:()=>{window.electronAPI.window.openSettings({category:"secretary",rowId:"secretary.root"})},onReset:()=>se("default"),runningOrigins:rt(Je.single),children:[ot.map(O=>n.jsx(vo,{id:O,conversation:A[O],active:M===O,dispatchRunning:Je.single.counts[O],switchHint:Vo(O,"project"),locale:a,nowTick:Mt,hoverTitle:tt.name,onSelect:J,onTogglePin:oe,onToggleArchive:ae=>{Fr(ae)},onCleanupWorktree:ae=>{fo(ae)},onMoveToWorktree:ae=>{zr(ae)},onRemove:ae=>{ft(ae)}},O)),!kt&&Oe.length>Ql&&n.jsx("div",{className:"flex items-center gap-1 px-2",children:n.jsx("button",{type:"button",onClick:()=>Ot(O=>!O),className:qi,children:Nt?i("Collapse"):i("Show {{n}} more",{n:Oe.length-Ql})})})]}),de.length===0&&n.jsx("button",{type:"button",onClick:()=>$e(!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")}),de.length===0&&h&&Ee&&n.jsx("button",{type:"button",onClick:()=>{ue(),H(Ee.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")}),wl.length>0&&n.jsxs("div",{"data-slot":"active-section",children:[n.jsx(Yi,{section:"active",children:i("Active")}),n.jsx("div",{className:"flex flex-col",children:wl.map(O=>n.jsx(Fy,{id:O,dragId:yK(O),conversation:A[O],children:n.jsx(vo,{id:O,conversation:A[O],active:M===O,switchHint:Vo(O,"active"),locale:a,nowTick:Mt,hoverTitle:kn(O),worktreeStatus:A[O].worktree?pe[O]:void 0,isolated:!!A[O].worktree,onSelect:J,onTogglePin:oe,onToggleArchive:ae=>{Fr(ae)},onCleanupWorktree:ae=>{fo(ae)},onMoveToWorktree:ae=>{zr(ae)},onRemove:ae=>{ft(ae)}})},O))})]}),hn.length===0&&ke?.type==="chat"&&!ke.pinned&&n.jsx(zy,{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(Ns,{className:"h-3.5 w-3.5"}),i("Drop here to pin")]})}),Nl.length>0&&n.jsxs(zy,{"data-slot":"pinned-section",children:[n.jsx(Yi,{section:"pinned",children:i("Pinned")}),n.jsx("div",{className:"flex flex-col",children:n.jsx(Zm,{items:Nl.map(O=>n2(O)),strategy:xy,children:Nl.map(O=>n.jsx(BX,{id:O,conversation:A[O],children:n.jsx(vo,{id:O,conversation:A[O],active:M===O,switchHint:Vo(O,"pinned"),locale:a,nowTick:Mt,hoverTitle:$y(l,A[O].projectId),worktreeStatus:A[O].worktree?pe[O]:void 0,isolated:!!A[O].worktree,onSelect:J,onTogglePin:oe,onToggleArchive:ae=>{Fr(ae)},onCleanupWorktree:ae=>{fo(ae)},onMoveToWorktree:ae=>{zr(ae)},onRemove:ae=>{ft(ae)}})},O))})})]}),h&&Ee&&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:Z,"aria-expanded":!Rn,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":!Rn||void 0,className:_("size-3 shrink-0 text-subtle-foreground transition-[opacity,transform] duration-150",Rn?"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:Nn.length})]}),n.jsx("button",{type:"button",className:Tf,title:i("Start a temporary chat"),"aria-label":i("Start a temporary chat"),onClick:()=>{ue(),H(Ee.id)},children:n.jsx(Xn,{className:"size-3.25"})})]}),n.jsx(la,{initial:!1,children:!Rn&&n.jsx(ks.div,{initial:"initial",animate:"animate",exit:"exit",variants:of,className:"overflow-hidden",children:n.jsxs("div",{className:"flex flex-col",children:[Nn.slice(0,Rx).map(O=>n.jsx(vo,{id:O,conversation:A[O],active:M===O,switchHint:Vo(O,"project"),locale:a,nowTick:Mt,onSelect:J,onTogglePin:oe,onToggleArchive:ae=>{Fr(ae)},onCleanupWorktree:ae=>{fo(ae)},onMoveToWorktree:ae=>{zr(ae)},onRemove:ae=>{ft(ae)}},O)),!Ut&&Nn.length>Ua&&n.jsxs("div",{className:"flex items-center gap-1 pl-2",children:[bl.length>0&&n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsx("button",{type:"button",onClick:()=>q(O=>Ey(Nn.length,O)),className:qi,children:i("Show {{n}} more",{n:bl.length})})}),n.jsx(Qr,{className:"min-w-36",children:n.jsxs(Yt,{onClick:()=>{Hx(bl)},children:[n.jsx(ar,{}),i("Archive {{n}} conversations",{n:bl.length})]})})]}),Tt>0&&n.jsx("button",{type:"button",onClick:()=>q(Ry),className:qi,children:i("Collapse")})]})]})},"scratch-conversations")})]}),de.length>0&&n.jsx(Yi,{section:"projects",actions:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:()=>Ye(!0),className:_(Tf,(nt||Ut)&&"bg-foreground/5 text-foreground opacity-100"),title:i("Search conversations..."),"aria-label":i("Search conversations..."),children:n.jsx(Yk,{className:"size-3.25"})}),n.jsx("button",{type:"button",onClick:()=>$e(!0),className:Tf,title:i("Add project"),"aria-label":i("Add project"),children:n.jsx(Xn,{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(Bt,{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(Zm,{items:[...S===qn?Se.map(O=>O.groupId===Is?wx:t2(O.groupId)):[],...We.map(O=>e2(O))],strategy:xy,children:(()=>{const O=ae=>{const He=Co(D,A,ae.id),it=Ui(At,[ae.alias??"",ae.name,ae.path]),vt=!Ut||it?He:He.filter(An);if(Ut&&vt.length===0)return null;const vn=Ut?!1:ge[ae.id]===!0,rs=Ct[ae.id]??0,$r=Ut?vt.length:Ga(vt.length,rs),mo=vt.slice($r),Ho=gt.includes(ae.id),Ux=[{kind:"item",key:"pin",label:i(Ho?"Unpin project":"Pin project"),icon:Ho?n.jsx(nd,{}):n.jsx(Ns,{}),onSelect:()=>tn(ae.id)},{kind:"item",key:"settings",label:i("Project settings"),icon:n.jsx(Ds,{}),onSelect:()=>ht(ae.id)},...ae.kind!=="ssh"?[{kind:"item",key:"reveal",label:i(Nx(window.electronAPI.env.platform)),icon:n.jsx(Lr,{}),onSelect:()=>Sx({projectId:ae.id},i)}]:[],{kind:"item",key:"import",label:i("Import session"),icon:n.jsx(y3,{}),onSelect:()=>be(ae)},...ae.kind!=="scratch"&&ae.kind!=="secretary"?[{kind:"item",key:"import-project-sessions",label:i("Import conversations from another project…"),icon:n.jsx(Wk,{}),onSelect:()=>Te(ae)}]:[],{kind:"separator",key:"sep-group"},{kind:"submenu",key:"move-to-group",label:i("Move to group"),icon:n.jsx(Af,{}),items:[{kind:"item",key:"ungrouped",label:i("Ungrouped"),icon:n.jsx(Af,{}),onSelect:()=>w(ae.id,null)},...p.map(pr=>({kind:"item",key:`group-${pr.id}`,label:pr.name,icon:n.jsx(Af,{emoji:pr.emoji,color:pr.color}),onSelect:()=>w(ae.id,pr.id)}))]},{kind:"item",key:"new-group",label:i("New group"),icon:n.jsx(gm,{}),onSelect:()=>Be({mode:"create"})},{kind:"separator",key:"sep-danger"},{kind:"item",key:"archive",label:i("Archive project"),icon:n.jsx(ar,{}),onSelect:()=>Jt(ae.id)},{kind:"item",key:"remove",label:i("Remove project"),icon:n.jsx(vs,{}),destructive:!0,onSelect:()=>Pe({kind:"project",project:ae,conversationIds:He})}];return n.jsx(_X,{project:ae,activitySorted:P,children:pr=>n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsxs("div",{ref:pr.setNodeRef,style:pr.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",...pr.handleProps,children:[n.jsxs("button",{type:"button",onClick:()=>V(ae.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",title:ae.path,children:[n.jsx(B2,{folded:vn}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-[0.9286rem] font-medium text-foreground",title:ae.kind==="ssh"?`${ae.sshHost}:${ae.path}`:ae.path,children:[Un(ae),ae.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:ae.sshConnectionName??ae.sshHost}),P&&n.jsx("span",{className:"ml-1.5 font-normal text-[0.7857rem] text-subtle-foreground",children:p.find(Kn=>Kn.id===ae.groupId)?.name??i("Ungrouped")})]})]}),n.jsx("button",{type:"button",onClick:()=>tn(ae.id),className:"hidden shrink-0 rounded-md p-1 text-muted-foreground group-hover:block hover:bg-muted hover:text-foreground",title:i(Ho?"Unpin project":"Pin project"),children:Ho?n.jsx(nd,{className:"h-3.5 w-3.5"}):n.jsx(Ns,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",onClick:()=>{H(ae.id)},className:RX,title:i("New conversation"),children:n.jsx(no,{className:"h-3.5 w-3.5"})}),n.jsx(zX,{actions:Ux}),(Ho||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:[Ho&&n.jsx(Ns,{className:"h-3.5 w-3.5"}),vn&&He.length]})]}),n.jsx(la,{initial:!1,children:!vn&&n.jsx(ks.div,{initial:"initial",animate:"animate",exit:"exit",variants:of,className:"overflow-hidden",children:n.jsxs("div",{className:"flex flex-col",children:[vt.slice(0,$r).map(Kn=>n.jsx(ks.div,{layout:ke?.type==="project"?!1:"position",transition:di,children:n.jsx(Fy,{id:Kn,conversation:A[Kn],children:n.jsx(vo,{id:Kn,conversation:A[Kn],active:M===Kn,switchHint:Vo(Kn,"project"),locale:a,nowTick:Mt,worktreeStatus:A[Kn].worktree?pe[Kn]:void 0,isolated:!!A[Kn].worktree,onSelect:J,onTogglePin:oe,onToggleArchive:ho=>{Fr(ho)},onCleanupWorktree:ho=>{fo(ho)},onMoveToWorktree:ho=>{zr(ho)},onRemove:ho=>{ft(ho)}})})},Kn)),!Ut&&He.length>Ua&&n.jsxs("div",{className:"flex items-center gap-1 pl-6",children:[mo.length>0&&n.jsxs(Yr,{children:[n.jsx(Xr,{render:n.jsx("button",{type:"button",onClick:()=>Rt(Kn=>({...Kn,[ae.id]:Ey(vt.length,Kn[ae.id]??0)})),className:qi,children:i("Show {{n}} more",{n:mo.length})})}),n.jsx(Qr,{className:"min-w-36",children:n.jsxs(Yt,{onClick:()=>{Hx(mo)},children:[n.jsx(ar,{}),i("Archive {{n}} conversations",{n:mo.length})]})})]}),rs>0&&n.jsx("button",{type:"button",onClick:()=>Rt(Kn=>({...Kn,[ae.id]:Ry(Kn[ae.id]??0)})),className:qi,children:i("Collapse")})]}),vt.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:yd(Ux)})]})},ae.id)};return P&&!Ut&&Re.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:x3})}):!Ut&&de.length>0&&Re.length===0?n.jsx("p",{className:"px-2 py-1.5 text-xs text-subtle-foreground",children:i("No projects in this group yet")}):S===qn&&p.length>0?n.jsxs("div",{children:[ee.length>0&&n.jsxs("div",{children:[n.jsx(Yi,{section:"pinned-projects",children:i("Pinned projects")}),n.jsx("div",{children:ee.map(O)})]}),Se.map(ae=>{const He=Ut?!1:Qn[ae.groupId]===!0;return n.jsxs("div",{children:[n.jsx(DX,{groupId:ae.groupId,name:ae.group?.name??i("Ungrouped"),emoji:ae.group?.emoji,color:ae.group?.color,count:ae.projects.length,folded:He,sortable:ae.groupId!==Is,onToggle:()=>Tn(ae.groupId),onEdit:ae.group?()=>Be({mode:"edit",id:ae.groupId}):void 0}),n.jsx(la,{initial:!1,children:!He&&n.jsx(ks.div,{initial:"initial",animate:"animate",exit:"exit",variants:of,className:"overflow-hidden",children:n.jsx("div",{children:ae.projects.map(O)})},`content-${ae.groupId}`)})]},ae.groupId)})]}):ee.length>0&&re.length>0?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{children:[n.jsx(Yi,{section:"pinned-projects",children:i("Pinned projects")}),n.jsx("div",{children:ee.map(O)})]}),n.jsx("div",{children:re.map(O)})]}):Re.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(ky,{}),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(jy,{})]}):n.jsx(g3,{}),n.jsx(by,{className:zs}),n.jsx(wy,{count:Bx,onClick:Vx,className:zs}),m&&n.jsx("button",{type:"button",onClick:()=>window.electronAPI.remote?.exitDesk?.(),className:zs,title:i("Compact view"),children:n.jsx(vg,{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(Ds,{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(lr,{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(Tp,{className:"h-4 w-4"})})]})]})]}),n.jsx(cn,{open:tI,onOpenChange:cu,children:n.jsxs(dn,{className:"h-[min(40rem,85vh)] max-w-xl",children:[n.jsxs(un,{children:[n.jsxs(on,{className:"flex items-baseline gap-2",children:[i("Archived"),n.jsx("span",{className:"font-sans text-sm text-muted-foreground tabular-nums",children:sI})]}),n.jsx("p",{"data-slot":"archive-scope",className:"text-xs text-muted-foreground",children:rI}),(Br.kind!=="all"||Fx.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[Br.kind!=="all"&&n.jsx(Nf,{label:$x,selected:Lx===null,onClick:()=>Sl(null)}),n.jsx(Nf,{label:i("All archived"),selected:Qs.kind==="all",onClick:()=>Sl(Br.kind==="all"?null:{kind:"all"})}),Fx.map(O=>n.jsx(Nf,{label:i("Dispatched by {{name}}",{name:zx(O)}),selected:Qs.kind==="secretary"&&Qs.secretaryId===O,onClick:()=>Sl({kind:"secretary",secretaryId:O})},O))]}),n.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[n.jsxs(Rh,{"data-size":"sm",children:[n.jsx(Mh,{children:n.jsx(lr,{})}),n.jsx(Ph,{value:Li,placeholder:i("Search conversations..."),onChange:O=>Px(O.target.value)})]}),n.jsx(By,{open:Dx==="*",onOpenChange:O=>Ox(O?"*":null),idsForDays:O=>bg(D,A,O,Date.now()),onPick:(O,ae)=>Pe({kind:"archived",days:O,conversationIds:ae}),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:[_x.length===0&&n.jsx("p",{className:"py-10 text-center text-sm text-muted-foreground",children:Li.trim()?i("No matching conversations"):i("No conversations")}),_x.map(O=>{const ae=l.find(it=>it.id===O.projectId),He=ae?Un(ae):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(s_,{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:He}),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:()=>Jt(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(Ma,{className:"h-3.5 w-3.5"})}):n.jsx(By,{open:Dx===O.projectId,onOpenChange:it=>Ox(it?O.projectId:null),idsForDays:it=>bg(D,A,it,Date.now(),O.projectId),onPick:(it,vt)=>Pe({kind:"archived",days:it,conversationIds:vt,projectName:He})})]}),n.jsx("div",{className:"flex flex-col",children:O.ids.map(it=>n.jsx(ks.div,{layout:"position",transition:di,children:n.jsx(vo,{id:it,conversation:A[it],active:M===it,locale:a,nowTick:Mt,worktreeStatus:A[it].worktree?pe[it]:void 0,isolated:!!A[it].worktree,menuZIndex:Pn.DROPDOWN_IN_MODAL,onSelect:vt=>{J(vt),cu(!1)},onTogglePin:oe,onToggleArchive:vt=>{Fr(vt)},onCleanupWorktree:vt=>{fo(vt)},onMoveToWorktree:vt=>{zr(vt)},onRemove:vt=>{ft(vt)}})},it))})]},O.projectId)})]})]})}),n.jsx(OY,{open:lt,onOpenChange:$e,onAdd:qe,groups:p,defaultGroupId:I}),n.jsx(HY,{open:Le!==null,group:Le?.mode==="edit"?p.find(O=>O.id===Le.id)??null:null,projects:de.filter(O=>!ct.includes(O.id)),onOpenChange:O=>{O||Be(null)},onSave:O=>{if(Le?.mode==="edit"){x(Le.id,O);return}const ae=g(O);for(const He of O.projectIds??[])w(He,ae.id)},onDelete:Le?.mode==="edit"?()=>{const O=Le.id;y(O),Gt===O&&sn(qn)}:void 0}),n.jsx(ZY,{open:Ze!==null,project:l.find(O=>O.id===Ze)??null,onOpenChange:O=>{O||ht(null)}}),n.jsx(JY,{project:ve,onClose:()=>be(null)}),n.jsx(QY,{project:Me,onClose:()=>Te(null)}),n.jsx(hs,{open:uo!==null,onOpenChange:O=>{O||uu(null)},title:uo?.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:Wx(uo?.status)}),confirmLabel:uo?.kind==="archive"?i("Archive"):i("Clean up"),onConfirm:()=>{uo&&pu(uo.id,uo.kind==="archive")}}),n.jsx(hs,{open:fu!==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(!fu)return;const O=fu;mu(null),zr(O,!0)}}),n.jsx(hs,{open:ye!==null,onOpenChange:O=>{O||Pe(null)},title:ye?.kind==="project"?i("Remove project?"):ye?.kind==="archived"?i("Delete archived conversations?"):i("Delete conversation?"),description:ye?.kind==="project"?i('"{{name}}" and its {{count}} conversations will be removed from the list.',{name:Un(ye.project),count:ye.conversationIds.length}):ye?.kind==="archived"?ye.days===0?ye.projectName?i('All {{count}} archived conversations in "{{name}}" will be removed from the list.',{count:ye.conversationIds.length,name:ye.projectName}):i("All {{count}} archived conversations will be removed from the list.",{count:ye.conversationIds.length}):ye.projectName?i('{{count}} conversations in "{{name}}" archived more than {{days}} days ago will be removed from the list.',{count:ye.conversationIds.length,days:ye.days,name:ye.projectName}):i("{{count}} conversations archived more than {{days}} days ago will be removed from the list.",{count:ye.conversationIds.length,days:ye.days}):ye?.kind==="conversation"&&ye.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:ye.worktreeWarning}):i("This conversation will be removed from the list."),confirmLabel:i("Remove"),onConfirm:()=>{if(ye)if(ye.kind==="project"){for(const O of ye.conversationIds)$(O);F(ye.project.id)}else if(ye.kind==="archived")for(const O of ye.conversationIds)$(O);else $(ye.id)}}),Xo.createPortal(n.jsx(iP,{dropAnimation:null,children:ke?.type==="project"?n.jsx(LX,{projectId:ke.projectId,name:OX(l,ke.projectId,ke.name),folded:ge[ke.projectId]===!0,revealedExtra:Ct[ke.projectId]??0,width:e}):(ke?.type==="chat"||ke?.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:[ke.type==="workspace-file"?n.jsx(Fo,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):n.jsx(Ns,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:ke.type==="workspace-file"?ke.name:ke.title.split(`
83
- `)[0].trim()||i("New conversation")})]})}),document.body),n.jsx(v3,{open:_t!==null,secretaryId:_t??void 0,onOpenChange:O=>{O||se(null)}})]})}function DX({groupId:e,name:t,emoji:s,color:r,count:o,folded:i,sortable:a,onToggle:l,onEdit:c}){const u=e===Is?wx:t2(e),d=sl({id:u}),m=lu({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:cr.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:EX,children:n.jsx(bs,{className:"size-3.25"})})]})}function OX(e,t,s){const r=e.find(o=>o.id===t);return r?Un(r):s}function LX({projectId:e,name:t,folded:s,revealedExtra:r,width:o}){const{t:i}=z(),a=X(m=>Kd(m.conversations)),l=X(m=>m.order),c=Co(l,a,e),u=s?[]:c.slice(0,Ga(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(B2,{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(F2,{conversation:h}),n.jsx("span",{className:"min-w-0 truncate",children:h.title||i("New conversation")})]},m):null}),c.length>Ua&&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 _X({project:e,activitySorted:t=!1,children:s}){const{setNodeRef:r,transform:o,transition:i,listeners:a,isDragging:l}=lu({id:e2(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:cr.Transform.toString(o),transition:i,opacity:l?.4:void 0},handleProps:a??{}})}function By({open:e,onOpenChange:t,idsForDays:s,onPick:r,className:o}){const{t:i}=z();return n.jsxs(ur,{open:e,onOpenChange:t,children:[n.jsx(fr,{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(Dj,{className:"h-3.5 w-3.5"})}),n.jsxs(mr,{align:"end",className:"min-w-40",zIndex:Pn.DROPDOWN_IN_MODAL,children:[PX.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 BX({id:e,conversation:t,children:s}){const{setNodeRef:r,transform:o,transition:i,listeners:a,isDragging:l}=lu({id:n2(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:cr.Transform.toString(o),transition:i,opacity:l?.4:void 0},children:s})}function Fy({id:e,conversation:t,children:s,dragId:r}){const{setNodeRef:o,listeners:i,isDragging:a}=s1({id:r??bK(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 zy({children:e,...t}){const{setNodeRef:s,isOver:r,active:o}=sl({id:ZC}),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 vo({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:y,onRemove:j}){const{t:w}=z(),b=xe(W=>W.projects),N=A2(b,t.projectId),C=E2(b,t.projectId),E=xe(W=>W.projects.some(B=>B.id===t.projectId&&B.kind!=="ssh"&&B.kind!=="secretary")),T=xe(W=>W.projects.some(B=>B.id===t.projectId&&B.kind==="scratch")),[k,L]=f.useState(!1),F=KC(e)!==void 0,A=X(W=>W.conversations[e]?.worktree),D=X(W=>!!W.conversations[e]?.workspaceMigrating),M=X(W=>W.conversations[e]?.worktreeMissing),[H,G]=f.useState(!1),[U,J]=f.useState(null),$=H||D||t.spawning||t.status==="running"||t.reloading===!0,oe=async()=>{if(!$){G(!0);try{await X.getState().newConversation(t.projectId,{worktreeFromConversationId:e})||Ie({type:"error",title:w("Failed to create conversation")})}catch(W){Ie({type:"error",title:w("Failed to create conversation"),description:String(W)})}finally{G(!1)}}},Ne=t.pinned===!0,ce=t.archived===!0,ne=X(W=>W.conversations[e]?.muted===!0),Y=Ne?nd:Ns,pe=ne?g4:ed,ge=t.title||w("New conversation"),we=t.forkedFromConversationId?X.getState().conversations[t.forkedFromConversationId]?.title:void 0,V=n.jsxs("div",{"data-slot":"conversation-row","data-pinned":Ne?"true":"false","data-enso":"session-row","data-active":s||void 0,"data-status":Cx(t),"data-unread":t.unread||void 0,"data-muted":ne||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:W=>{W.preventDefault(),W.stopPropagation(),L(!0)},onKeyDown:W=>{W.key==="Enter"&&!k&&h(e)},role:"button",tabIndex:0,title:i,children:[n.jsx(F2,{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:[we&&n.jsx("span",{className:"max-w-1/3 truncate text-[0.7857rem] text-subtle-foreground",children:w("Branched from {{title}}",{title:we})}),k?n.jsx(o2,{title:ge,onCommit:W=>{X.getState().renameConversation(e,W),L(!1)},onCancel:()=>L(!1)}):n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[ge,a&&n.jsx("span",{className:"ml-1.5 text-[0.7857rem] text-subtle-foreground",children:a})]}),uX(ne,t.secretaryOrigin!==void 0)&&!k&&n.jsx(ed,{className:"h-3 w-3 shrink-0 text-subtle-foreground","aria-label":w("Muted"),"data-enso":"session-muted"})]}),t.secretaryOrigin&&n.jsx(mX,{secretaryId:t.secretaryOrigin.secretaryId,conversationId:e,muted:ne}),!t.secretaryOrigin&&F&&n.jsx(PG,{conversationId:e}),c&&A&&n.jsx(oY,{worktree:A,status:u}),n.jsx(AX,{conversationId:e}),n.jsx(EY,{conversationId:e}),n.jsx(xX,{count:l}),!k&&n.jsx(FX,{pending:t.titleSummaryPending,error:t.titleSummaryError,onRetry:()=>X.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:[Ne&&!ce&&n.jsx(Ns,{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:Mo(t.lastActiveAt??t.createdAt,r,o)}),!ce&&n.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),p(e)},className:"hidden shrink-0 rounded p-0.5 text-muted-foreground group-hover:block hover:text-foreground",title:w(Ne?"Unpin":"Pin"),children:n.jsx(Y,{className:"h-3.5 w-3.5"})}),n.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),g(e)},className:"hidden shrink-0 rounded p-0.5 text-muted-foreground group-hover:block hover:text-foreground",title:w(ce?"Unarchive":"Archive"),children:ce?n.jsx(Ma,{className:"h-3.5 w-3.5"}):n.jsx(ar,{className:"h-3.5 w-3.5"})}),ce&&n.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),j(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:V}),n.jsxs(Qr,{className:"min-w-36",zIndex:m,children:[n.jsxs(Yt,{onClick:()=>L(!0),children:[n.jsx(bs,{}),w("Rename")]}),n.jsxs(Yt,{disabled:t.reloading===!0||t.spawning,onClick:()=>{oS(e,w)},children:[n.jsx(ro,{className:t.reloading?"animate-spin":void 0}),w("Reload conversation")]}),n.jsxs(Yt,{disabled:$,onClick:()=>{iS(e,w)},children:[n.jsx(Eo,{}),w("Restart conversation (reload settings)")]}),E&&n.jsxs(Yt,{disabled:D||M||u?.exists===!1,onClick:()=>{Sx({projectId:t.projectId,conversationId:e},w)},children:[n.jsx(Lr,{}),w(Nx(window.electronAPI.env.platform))]}),!ce&&n.jsxs(Yt,{onClick:()=>p(e),children:[n.jsx(Y,{}),w(Ne?"Unpin":"Pin")]}),n.jsxs(Yt,{onClick:()=>g(e),children:[ce?n.jsx(Ma,{}):n.jsx(ar,{}),w(ce?"Unarchive":"Archive")]}),n.jsxs(Yt,{"data-enso":"session-mute",onClick:()=>X.getState().toggleMuteConversation(e),children:[n.jsx(pe,{}),w(ne?"Unmute":"Mute")]}),A&&n.jsxs(n.Fragment,{children:[n.jsxs(Yt,{disabled:$||M||u?.exists===!1,onClick:()=>{oe()},children:[H?n.jsx(Bt,{className:"animate-spin"}):n.jsx(no,{}),w("New conversation in this worktree")]}),n.jsxs(Yt,{disabled:$||M||u?.exists===!1,onClick:()=>J({conversationId:e,worktree:A}),children:[n.jsx(bs,{}),w("Rename worktree")]})]}),!ce&&(c?x&&n.jsxs(Yt,{disabled:$,onClick:()=>x(e),children:[n.jsx(Dj,{}),w("Clean up worktree")]}):y&&E&&!T&&n.jsxs(Yt,{disabled:$,onClick:()=>y(e),children:[n.jsx(u_,{}),w("Move to worktree")]})),N?C.length>0?n.jsxs(Oh,{children:[n.jsxs(Lh,{children:[n.jsx(vm,{}),w(T?"Add to project…":"Move to project…")]}),n.jsx(_h,{className:"min-w-36",children:C.map(W=>n.jsx(Yt,{disabled:$,onClick:()=>{KY(e,W.id,w)},children:Un(W)},W.id))})]}):n.jsxs(Yt,{disabled:!0,children:[n.jsx(vm,{}),w(T?"Add to project…":"Move to project…")]}):null,n.jsx(Bh,{}),n.jsxs(Yt,{variant:"destructive",onClick:()=>j(e),children:[n.jsx(vs,{}),w("Delete")]})]})]}),n.jsx(g2,{entity:U,onClose:()=>J(null)})]})}function FX({pending:e,error:t,onRetry:s}){const{t:r}=z();return e?n.jsxs(Ac,{children:[n.jsx(Ec,{render:n.jsx("span",{role:"status",className:"shrink-0 text-muted-foreground/60","aria-label":r("Summarizing title")}),children:n.jsx(Bt,{className:"h-3 w-3 animate-spin"})}),n.jsx(Rc,{side:"right",children:r("Summarizing title")})]}):t?n.jsxs(Ac,{children:[n.jsx(Ec,{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(Rc,{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 $y(e,t){const s=e.find(r=>r.id===t);return s?Un(s):void 0}function Af({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(vm,{style:t?{color:t}:void 0})}function yd(e,t="context"){return e.map(s=>s.kind==="separator"?t==="menu"?n.jsx(yi,{},s.key):n.jsx(Bh,{},s.key):s.kind==="submenu"?t==="menu"?n.jsxs(sj,{children:[n.jsxs(rj,{children:[s.icon,s.label]}),n.jsx(oj,{className:"min-w-40",children:yd(s.items,"menu")})]},s.key):n.jsxs(Oh,{children:[n.jsxs(Lh,{children:[s.icon,s.label]}),n.jsx(_h,{className:"min-w-40",children:yd(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(Yt,{onClick:s.onSelect,variant:s.destructive?"destructive":"default",children:[s.icon,s.label]},s.key))}function zX({actions:e}){const{t}=z();return n.jsxs(ur,{children:[n.jsx(fr,{"data-enso":"row-menu","aria-label":t("More actions"),className:MX,title:t("More actions"),onPointerDown:s=>s.stopPropagation(),children:n.jsx(ll,{className:"h-3.5 w-3.5"})}),n.jsx(mr,{align:"end",className:"min-w-40",children:yd(e,"menu")})]})}function Yi({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 B2({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 F2({conversation:e}){const t=(e.pendingApprovals?.length??0)>0?"attention":jd({status:e.status,spawning:e.spawning,unread:e.unread,pendingAskCount:e.pendingAsks?.length??0,hasRunningChild:e.hasRunningChild});return n.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:t!=="idle"&&n.jsx(cl,{tone:t,size:"sm","data-enso":"session-status","data-status":Cx(e)})})}const Ef=["welcome","provider","skill","mcp","instruction","preset","agentType","done"];function $X(){const{t:e}=z();oh();const t=xe(E=>E.setOnboarded),s=Rd(),r=xe(E=>E.skills),o=xe(E=>E.mcpServers),i=xe(E=>E.instructions),a=xe(E=>E.presets),[l,c]=f.useState(0),[u,d]=f.useState(null),[m,h]=f.useState(!1),[p,g]=f.useState(!1),[x,y]=f.useState(!1),j=Ef[l],w=()=>t(!0),b=()=>c(E=>Math.min(Ef.length-1,E+1)),N=()=>c(E=>Math.max(0,E-1)),C={provider:{icon:j3,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:xw,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:Dc,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(Zt,{className:"h-4 w-4"})}),n.jsx("div",{className:"mb-5 flex items-center gap-1.5",children:Ef.map((E,T)=>n.jsx("span",{className:_("h-1 flex-1 rounded-full transition-colors",T<=l?"bg-primary":"bg-muted")},E))}),j==="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(w3,{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.")})]}),j!=="welcome"&&j!=="done"&&j!=="preset"&&j!=="agentType"&&n.jsx(Vy,{...C[j],importedLabel:e("{{count}} imported",{count:C[j].count})}),j==="preset"&&n.jsx(Vy,{icon:Dc,title:e("Presets"),desc:e("Bundle skills, MCP servers and an instruction file into a preset (optional)"),count:a.length,onImport:()=>y(!0),importedLabel:e("{{count}} presets",{count:a.length}),importLabel:e("New preset")}),j==="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(_s,{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(k3,{})})]}),j==="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(Dn,{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(he,{variant:"ghost",size:"sm",onClick:N,disabled:l===0,children:e("Back")}),n.jsxs("div",{className:"flex items-center gap-2",children:[j!=="done"&&j!=="welcome"&&n.jsx(he,{variant:"ghost",size:"sm",onClick:b,children:e("Skip")}),j==="done"?n.jsx(he,{size:"sm",onClick:w,children:e("Done")}):n.jsx(he,{size:"sm",onClick:b,children:e(j==="welcome"?"Get started":"Next")})]})]})]}),n.jsx(N3,{open:m,onOpenChange:h}),n.jsx(S3,{open:p,onOpenChange:g}),u&&n.jsx(C3,{kind:u,open:!0,onOpenChange:E=>!E&&d(null)}),x&&n.jsx(I3,{preset:null,onClose:()=>y(!1)})]})}function Vy({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(he,{variant:"outline",size:"sm",onClick:o,children:a}),l&&n.jsx(he,{variant:"ghost",size:"sm",onClick:l.onClick,children:l.label})]}),r>0&&n.jsx("p",{className:"text-xs text-primary",children:i})]})}const Rf=["project","all","all-including-archived"];function Hy(e,t=!1){const s=Rf.length,r=Rf.indexOf(e);return Rf[(r+(t?s-1:1))%s]??"all"}const VX=50,Mf=160,HX=["title","project","id","body","tool"],Tx=/[\p{Letter}\p{Number}]+/gu,WX=/[\u3400-\u9fff]/u,UX=/[^.!?。?!]+[.!?。?!]?/g;function z2(e){return e.toLowerCase().match(Tx)??[]}function Ax(e){return WX.test(e)}function $2(e){return z2(e)}function V2(e,t){if(t.length===0)return!1;const s=e.toLowerCase(),r=z2(e);return t.every(o=>Ax(o)?s.includes(o):r.some(i=>i.startsWith(o)))}function H2(e,t){return e.isDraftEmpty?!1:t.scope==="project"?e.projectId===t.currentProjectId&&!e.archived:t.scope==="all"?!e.archived:!0}function GX(e,t){const s=e.toLowerCase(),r=$2(t);if(r.length===0||s.length!==e.length)return[{text:e,match:!1}];const o=[];for(const l of r){if(Ax(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(Tx))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 KX(e,t){const s=e.toLowerCase();let r=-1;for(const o of t){if(Ax(o)){const i=s.indexOf(o);i>=0&&(r<0||i<r)&&(r=i);continue}for(const i of e.matchAll(Tx))if(i[0].toLowerCase().startsWith(o)&&i.index!==void 0){(r<0||i.index<r)&&(r=i.index);break}}return r}function qX(e,t){if(e.length<=Mf)return e;const s=Math.max(0,KX(e,t)),r=Math.min(s,Math.max(0,e.length-Mf));return e.slice(r,r+Mf)}function YX(e){return(e.match(UX)??[]).map(t=>t.trim()).filter(Boolean)}function XX(e,t){const s=YX(e);if(s.length<=1)return;const r=s.findIndex(i=>V2(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 QX(e,t,s,r){return e.title.trim().toLowerCase()===s.trim().toLowerCase()?0:t==="title"?1:e.projectId===r?2:3}function JX(e,t,s){const r=s.trim().toLowerCase(),o=e.fields.filter(i=>i.field==="id"?i.text.toLowerCase().startsWith(r):V2(i.text,t));if(o.length!==0)return HX.map(i=>o.find(a=>a.field===i)).find(i=>!!i)}function W2(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:QX(e,t.field,s,r),lastActiveAt:e.lastActiveAt}}function U2(e,t=VX){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 ZX(e,t,s){const r=$2(t);if(r.length===0)return[];const o=[];for(const i of e){if(!H2(i,s))continue;const a=JX(i,r,t);if(!a)continue;const l=XX(a.text,r);o.push(W2(i,{field:a.field,snippet:qX(a.text,r),nearby:l},t,s.currentProjectId))}return U2(o,s.limit)}function eQ(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)||!H2(c,o)||a.set(l.conversationId,W2(c,l,r,o.currentProjectId))}return U2([...a.values()],o.limit)}const tQ=120,nQ=8;function G2(e){return!e.started&&!e.sessionFile&&e.messages.length===0}function ka(e){return e.messages.at(-1)?.timestamp??e.lastActiveAt??e.createdAt}function sQ(e,t){return e.filter(s=>s.parentId||G2(s)||s.archived&&t.scope!=="all-including-archived"?!1:t.scope!=="project"||s.projectId===t.currentProjectId).sort((s,r)=>ka(r)-ka(s)).slice(0,t.limit??nQ)}function rQ(e){return e.content.map(t=>t.type==="text"?t.text:"").join(`
84
- `).trim()}function oQ(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,tQ);return`${t.join(" ")} ${s}`.trim()}function iQ(e){const t=[{field:"title",text:e.title},{field:"project",text:e.projectName},{field:"id",text:e.conversationId},{field:"body",text:e.messages.map(rQ).filter(Boolean).join(`
85
- `)}],s=e.messages.map(oQ).filter(r=>!!r);return s.length>0&&t.push({field:"tool",text:s.join(`
86
- `)}),{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 Wy=[],aQ={project:"This project",all:"All projects","all-including-archived":"Include archived"},lQ={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",experimental:"Experimental",bots:"Bot mode",botTemplates:"Bot templates",secretary:"Secretary"};function Xi({text:e,query:t}){let s=0;return GX(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 qo({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 cQ(e){try{return new URL(e).host||e}catch{return e}}function dQ({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=X(B=>B.conversations),x=X(B=>B.activeId),y=xe(B=>B.projects),j=xe(B=>B.scratchSessionsEnabled),w=xe(B=>B.keybindings),b=(x?g[x]?.projectId:void 0)??y[0]?.id??"",N=o.trim(),C=`${a}
87
- ${b}
88
- ${N}`,E=c?.key===C?c.hits:Wy,T=f.useMemo(()=>{if(!e)return[];const te=(x?g[x]:void 0)?.activeTabId,Z=te&&g[te]?te:x;return Object.values(g).map(ue=>{const fe=y.find(Ce=>Ce.id===ue.projectId);return fe?.kind==="secretary"||!j&&fe?.kind==="scratch"?null:iQ({conversationId:ue.id,projectId:ue.projectId,projectName:fe?Un(fe):ue.projectId,title:ue.title,lastActiveAt:ka(ue),archived:ue.archived,isDraftEmpty:G2(ue),isCurrent:ue.id===Z,parentConversationId:ue.parentId,coworkerId:ue.parentId?ue.id:void 0,messages:ue.messages})}).filter(ue=>ue!==null)},[x,g,e,y,j]),k=f.useMemo(()=>N?ZX(T,o,{currentProjectId:b,scope:a}):Wy,[b,T,o,a,N]),L=f.useMemo(()=>e?sQ(Object.values(g),{scope:a,currentProjectId:b}):[],[g,b,e,a]),F=T3(h),A=f.useMemo(()=>N?A3(F,o,{translate:B=>s(B)}):[],[o,F,s,N]),D=f.useMemo(()=>o.trim()?E3(d,o):[],[d,o]),M=f.useMemo(()=>R3(d),[d]);f.useEffect(()=>{if(!e)return;const B=te=>{te.key==="Escape"&&(te.preventDefault(),te.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(te=>!M3(te.conversationId)))).catch(()=>{m([])}),window.electronAPI.sshConnections.list().then(B=>{p(B.map(te=>({id:te.id,name:te.name})))}).catch(()=>{p([])})},[e]),f.useEffect(()=>{if(!e||!N||!b)return;let B=!1;const te=window.setTimeout(()=>{window.electronAPI.workspaceSearch.query({query:N,currentProjectId:b,scope:a}).then(Z=>{B||u({key:C,hits:Z.hits})}).catch(()=>{B||u({key:C,hits:[]})})},80);return()=>{B=!0,window.clearTimeout(te)}},[C,b,e,a,N]);const H=f.useMemo(()=>eQ(T,k,E,o,{currentProjectId:b,scope:a}),[E,b,T,k,o,a]),G=B=>{const te=X.getState(),Z=te.conversations[B.conversationId],ue=B.parentConversationId??Z?.parentId;if(ue&&te.conversations[ue]?(te.selectConversation(ue),te.selectTab(ue,B.coworkerId??B.conversationId)):te.selectConversation(B.conversationId),t(!1),B.field==="body"||B.field==="tool"){const fe=o.trim().split(/\s+/).find(Boolean);fe&&window.setTimeout(()=>UC(fe),0)}},U=B=>{const te=X.getState(),ue=te.conversations[B.conversationId]?.parentId;ue&&te.conversations[ue]?(te.selectConversation(ue),te.selectTab(ue,B.conversationId)):te.selectConversation(B.conversationId),P3({conversationId:B.conversationId,tabId:B.tabId,title:B.title||s("Browser")}),t(!1)},J=B=>{window.electronAPI.window.openSettings({category:B.category,rowId:B.id}),t(!1)},$=N.length>0&&H.length===0&&D.length===0&&A.length===0,oe=B=>{B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),t(!1))},Ne=B=>{if(B.key!=="Tab"||B.nativeEvent.isComposing){oe(B);return}B.altKey||B.ctrlKey||B.metaKey||(B.preventDefault(),l(te=>Hy(te,B.shiftKey)))},ce=Mr(w),ne=Date.now(),Y=B=>{const te=y.find(Z=>Z.id===B);return te?Un(te):""},pe=(B,te)=>[Y(B),te?Mo(te,r,ne):""].filter(Boolean).join(" · "),ge=(B,te)=>n.jsxs(n.Fragment,{children:[B&&n.jsx(fi,{size:"sm",className:"bg-brand/10 text-brand",children:s("Current")}),te&&n.jsx(fi,{variant:"outline",size:"sm",children:s("Archived")})]}),we=B=>{const te=g[B.conversationId],Z=B.parentConversationId??te?.parentId;let ue=bm;Z&&(ue=te?.child?.mode==="task"?$h:_s);const fe=B.title||te?.child?.agentInstanceName||te?.coworkerName||s("New conversation"),Ce=Z?g[Z]?.title||s("New conversation"):void 0,de=B.field==="body"||B.field==="tool"||B.field==="id"?B.snippet.replace(/\s+/g," ").trim():"";return n.jsx(qo,{icon:ue,title:n.jsxs(n.Fragment,{children:[Ce&&n.jsxs("span",{className:"text-muted-foreground",children:[Ce," › "]}),n.jsx(Xi,{text:fe,query:o})]}),badges:ge(B.isCurrent,B.archived),detail:de&&n.jsx(Xi,{text:de,query:o}),meta:pe(B.projectId,te?ka(te):void 0)})},V=(B,te)=>n.jsx(wo,{value:te,className:"gap-2.5",onClick:()=>U(B),children:n.jsx(qo,{icon:Ro,title:n.jsx(Xi,{text:B.title||B.url,query:o}),meta:cQ(B.url)})},te),W=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(te=>Hy(te,B.shiftKey))},children:[s(aQ[a]),n.jsx(Vs,{className:"h-4 min-w-4 text-[10px]",children:"⇥"})]});return n.jsx(OC,{open:e,onOpenChange:t,children:n.jsx(LC,{className:"max-h-[min(36rem,calc(100vh-6rem))] max-w-2xl",onKeyDown:oe,children:n.jsxs(_C,{children:[n.jsx(BC,{placeholder:s("Search conversations, browser tabs, settings…"),value:o,onChange:B=>i(B.currentTarget.value),onKeyDown:Ne,endAddon:W}),n.jsxs($C,{children:[$&&n.jsxs(zC,{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(FC,{children:[!N&&n.jsxs(n.Fragment,{children:[L.length>0&&n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Recent")}),L.map(B=>n.jsx(wo,{value:`recent-${B.id}`,className:"gap-2.5",onClick:()=>G({conversationId:B.id,field:"title",snippet:B.title}),children:n.jsx(qo,{icon:bm,title:B.title||s("New conversation"),badges:ge(B.id===x,B.archived),meta:pe(B.projectId,ka(B))})},B.id))]}),M.length>0&&n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Browser")}),M.map(B=>V(B,`recent-browser-${B.tabId}`))]}),n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Actions")}),n.jsxs(wo,{value:"new-conversation",className:"gap-2.5",onClick:()=>{b&&X.getState().newConversation(b),t(!1)},children:[n.jsx(qo,{icon:Xn,title:n.jsxs(n.Fragment,{children:[s("New conversation"),Y(b)&&n.jsxs("span",{className:"text-muted-foreground",children:[" · ",Y(b)]})]})}),n.jsx($b,{children:Gs(ce["new-conversation"])})]}),n.jsxs(wo,{value:"open-settings",className:"gap-2.5",onClick:()=>{window.electronAPI.window.openSettings(),t(!1)},children:[n.jsx(qo,{icon:Ds,title:s("Open settings")}),n.jsx($b,{children:Gs(ce["open-settings"])})]})]})]}),N.length>0&&H.length>0&&n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Conversations")}),H.map(B=>n.jsx(wo,{value:`conv-${B.conversationId}-${B.field}`,className:"gap-2.5",onClick:()=>G(B),children:we(B)},`${B.conversationId}-${B.field}`))]}),N.length>0&&D.length>0&&n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Browser")}),D.map(B=>V(B,`browser-${B.tabId}`))]}),N.length>0&&A.length>0&&n.jsxs(Go,{children:[n.jsx(Ko,{children:s("Settings")}),A.map(B=>n.jsx(wo,{value:`settings-${B.id}`,className:"gap-2.5",onClick:()=>J(B),children:n.jsx(qo,{icon:Ds,title:n.jsx(Xi,{text:s(B.title),query:o}),detail:B.description&&n.jsx(Xi,{text:s(B.description),query:o}),meta:s(lQ[B.category]??B.category)})},B.id))]})]})]}),n.jsxs(VC,{children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsxs(hj,{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 uQ(){const{t:e}=z(),[t,s]=f.useState("choose"),[r,o]=f.useState(!1),[i,a]=f.useState(null),l=jt(g=>g.focusedId)??void 0,c=jt(g=>g.secretaries),u=l?{secretaryId:l}:{},d=f.useMemo(()=>D3(O3(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 jt.getState().newSecretaryConversation({greeting:!0,...u})){a(e("Could not start the secretary. Try again."));return}jt.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 y=jt.getState();if(!await(l?y.newSecretaryConversation(u):y.newSecretaryConversation())){a(e("Could not start the secretary. Try again."));return}jt.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(kd,{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(gw,{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:()=>jt.getState().closeWelcome(),className:"w-fit text-xs text-muted-foreground transition-colors hover:text-foreground",children:e("Later")})]})})}const fQ=/!\[[^\]]*\]\(\s*<?((?:file:\/\/)?\/[^)>\s]+)>?\s*\)/gu;function mQ(e){if(!e.startsWith("file://"))return e;const t=e.slice(7);try{return decodeURIComponent(t)}catch{return t}}function hQ(e){return e.replace(fQ,(t,s)=>`\`${mQ(s).split("/").pop()||s}\``)}const pQ={OPEN:"PR open",MERGED:"PR merged",CLOSED:"PR closed"},Uy="mb-1.5 text-[12px] font-medium text-muted-foreground",K2="aspect-video w-full overflow-hidden rounded-md border border-border bg-muted/40",Gy=_(K2,"flex flex-col items-center justify-center gap-1 text-[11.5px] text-muted-foreground"),wd=e=>String(e).padStart(2,"0"),q2=e=>{const t=new Date(e);return`${wd(t.getMonth()+1)}-${wd(t.getDate())}`},xQ=e=>{const t=new Date(e);return`${q2(e)} ${wd(t.getHours())}:${wd(t.getMinutes())}`};function Ky(e,t,s){const r=xQ(t.at);if(t.imagesGoneAt===void 0)return e("Completed {{done}}",{done:r});const o=q2(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 gQ({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(y=>{x&&o(y.ok?y.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 y="name"in x?x.name:`missing:${x.label}`,j=(p.get(y)??0)+1;return p.set(y,j),{image:x,key:j>1?`${y}#${j}`:y}});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(x_,{className:"size-3.5 text-brand"}):n.jsx(v_,{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(pQ[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)})]}),c?n.jsx("div",{"data-enso":"done-report-text",className:"min-w-0 text-[13px]",children:n.jsx(Gn,{text:hQ(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:Uy,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(td,{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:Ky(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:y})=>{const j=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:Ky(s,l,x.gone),className:Gy,children:[n.jsx(Hd,{className:"size-4 opacity-70"}),x.gone==="expired"?s("Expired"):s("Cleaned up")]}),j]},y):"name"in x&&!i.has(x.name)?n.jsxs("figure",{className:"min-w-0",children:[n.jsx(hl,{src:L3(e,x.name,l.at),alt:x.label,title:x.label,lazy:!0,frameClassName:_(K2,"block"),className:"size-full object-cover",onError:()=>a(w=>new Set(w).add(x.name))}),j]},y):n.jsxs("figure",{className:"min-w-0",children:[n.jsxs("div",{"data-enso":"done-report-missing",className:Gy,children:[n.jsx(td,{className:"size-4 opacity-70"}),s("Image unavailable")]}),j]},y)})})]}),r?.files&&r.files.length>0&&n.jsxs("section",{"data-enso":"done-report-files",children:[n.jsx("div",{className:Uy,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 vQ={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"}},bQ={active:"working",paused:"paused",waiting:"waiting",blocked:"blocked",completed:"completed"},Jl="shrink-0 rounded px-1.5 py-px text-[11px]",yQ=[{key:"result",label:"Result"},{key:"session",label:"Session"}];function wQ(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 jQ(){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=X(k=>t?k.conversations[t]:void 0),l=xe(k=>a?k.projects.find(L=>L.id===a.projectId):void 0),c=!!a,u=a?.archived===!0;f.useEffect(()=>t&&c?_3(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&&X.getState().toggleArchiveConversation(t),Va(t,h??void 0))},g=a?null:e("This session no longer exists, or you do not have access to it"),x=a?vQ[wQ(a)]:null,y=a?.worktree?.name||a?.worktree?.branch,j=a?.goal,w=a?.pendingApprovals??[],b=a?.pendingAsks??[],N=c&&!u&&t&&(w.length>0||b.length>0),C=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:yQ.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))}),E=(a||C)&&n.jsxs("div",{"data-enso":"session-peek-meta",className:"flex flex-col gap-1.5",children:[C,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:_(Jl,x.className),children:e(x.label)}),l&&n.jsx("span",{"data-enso":"session-peek-project",className:_(Jl,"bg-muted"),children:Un(l)}),y&&n.jsxs("span",{"data-enso":"session-peek-branch",className:_(Jl,"inline-flex items-center gap-1 bg-muted font-mono"),children:[n.jsx(Hs,{className:"size-3"}),y]})]}),j&&n.jsxs("p",{"data-enso":"session-peek-goal",className:"truncate text-[12px] text-muted-foreground",children:[e("Goal")," · ",j.text," · ",e(bQ[j.status]),j.status==="active"&&j.autoTurns>0?` · ${j.autoTurns}/25`:""]})]}),T=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(Ti,{className:"size-3.5"}),e(u?"Restore and open":"Open session")]}),u&&n.jsxs("span",{"data-enso":"session-peek-archived",className:_(Jl,"inline-flex items-center gap-1 bg-muted text-muted-foreground"),children:[n.jsx(ar,{className:"size-3"}),e("Archived · read-only")]})]});return n.jsx(AC,{dataEnso:"session-peek",conversationId:t,title:a?.title||r?.title||e("Unnamed"),meta:E,actions:T,footer:N?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(Ao,{className:"size-3.5"}),e("Needs your approval or answer")]}),n.jsx(Vp,{approvals:w,allowSession:a?.child?.lockedProfileId===void 0,onRespond:(k,L)=>{window.electronAPI.agent.respondApproval(t,k,L)}}),n.jsx(Hp,{asks:b,autoFocus:!1,onAnswer:(k,L)=>{window.electronAPI.agent.respondAsk(t,k,L)}})]}):void 0,onClose:s,children:o==="result"&&t?n.jsx(gQ,{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(Jd.Provider,{value:m,children:n.jsx("div",{className:"@container flex min-h-0 flex-1 flex-col border-t",children:n.jsx(YC,{peek:!0,readOnly:u,conversationId:t,cwd:a?.worktree?.path??l?.path,emptyTitle:a?.title||e("Unnamed"),timelineRef:d})})}):null})}function Ex(){return kr()&&X.persist.hasHydrated()&&xe.persist.hasHydrated()}function qy(e,t){Ex()&&e>0&&(async()=>(t&&await X.getState().refreshWorktreeStatuses(),await X.getState().autoArchiveStaleConversations()))()}function Yy(e){!Ex()||!(e>0)||X.getState().autoDeleteStaleArchived()}function kQ(){const e=xe(r=>r.autoArchiveIdleDays),t=xe(r=>r.autoArchiveMergedWorktrees),s=xe(r=>r.autoDeleteArchivedDays);f.useEffect(()=>{if(Ex()){qy(e,t),Yy(s);return}const r=()=>{qy(e,t),Yy(s)},o=[X.persist.onFinishHydration(r),xe.persist.onFinishHydration(r)];return()=>{for(const i of o)i()}},[e,t,s])}function NQ(){const e=X(t=>Math.min(999,B3(t.order,Kd(t.conversations))));f.useEffect(()=>{window.electronAPI.app.setBadgeCount(e)},[e])}function SQ(){const e=xe(s=>s.generationStallTimeoutMin),{t}=z();f.useEffect(()=>{if(e<=0)return;const s=new Set,r=new Set,o=new Map,i=setInterval(()=>{if(!kr())return;const a=e*6e4,l=Date.now(),c=X.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=F3({shouldAbort:z3({status:u.status,spawning:u.spawning,lastOutputAt:H3(u,c.conversations),now:l,timeoutMs:a,hasLiveWork:$3({...V3(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(Xy(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(Xy(u,t("Stopped after repeated stalls"))))}},1e3);return()=>clearInterval(i)},[e,t])}function Xy(e,t){const s=(e.coworkerName||e.title).split(`
89
- `)[0].trim();return s?{type:"warning",title:s,description:t}:{type:"warning",title:t}}function CQ(e){return{at:e.exitAt,kind:e.kind,unfinishedTools:[...e.unfinishedTools],...e.suppressedError?{suppressedError:e.suppressedError}:{}}}function IQ(e){return e?e.status!=="running":!1}const TQ=3e4;function AQ(e,t=TQ){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=[X.subscribe(o),Lo.subscribe(o),xe.subscribe(o)],a=setTimeout(()=>r(e()),t)})}function EQ(){const e=Lo.getState().snapshot.availability.status;return X.persist.hasHydrated()&&xe.persist.hasHydrated()&&e!=="unloaded"&&e!=="loading"}function RQ(){const{t:e}=z();f.useEffect(()=>{kr()&&(async()=>{const t=await window.electronAPI.agent.takeInterruptedTurns().catch(()=>[]);if(t.length===0||!await AQ(EQ))return;const s=new Set;for(const r of t)IQ(X.getState().conversations[r.conversationId])&&(s.add(r.conversationId),X.setState(o=>{const i=o.conversations[r.conversationId];return!i||i.status==="running"?o:{conversations:{...o.conversations,[r.conversationId]:{...i,status:"interrupted",interrupted:CQ(r),error:void 0}}}}));s.size!==0&&Ie({type:"info",title:e("{{count}} conversation(s) interrupted by app exit",{count:s.size})})})()},[e])}const MQ=3e4;function PQ(e,t=MQ){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=[X.subscribe(o),xe.subscribe(o)],a=setTimeout(()=>r(e()),t)})}function DQ(){return X.persist.hasHydrated()&&xe.persist.hasHydrated()}function OQ(){const{t:e}=z();f.useEffect(()=>{if(!kr())return;const t=()=>{Nm(async()=>{if(!await PQ(DQ))return;const r=await window.electronAPI.window.takeOpenFolders().catch(()=>[]);let o=!1;for(const i of r)try{if(!await cN(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&&Rp()})},s=window.electronAPI.window.onOpenFolderRequested(t);return t(),s},[e])}const Qy="enso-win",Y2="enso-win-flush",Zl="enso-win-pending",Jy="enso-win-native";function LQ(e,t,s){return{maximized:s.maximized?e.maximized:t.maximized,fullscreen:s.fullscreen?e.fullscreen:t.fullscreen}}function _Q(e,t){return e||t}function BQ(e,t){document.documentElement.classList.toggle(Y2,_Q(e,t))}function FQ(){f.useEffect(()=>{if(window.electronAPI?.env.platform!=="win32")return;const e=document.documentElement;e.classList.add(Qy,Zl),e.classList.add(Jy);let t={maximized:!1,fullscreen:!1};const s={maximized:0,fullscreen:0};let r=!1,o=0,i;const a=()=>BQ(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=LQ(t,{maximized:g,fullscreen:x},{maximized:s.maximized!==p.maximized,fullscreen:s.fullscreen!==p.fullscreen}),e.classList.remove(Zl),a())}).catch(()=>{!r&&h===o&&e.classList.remove(Zl)})};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(Qy,Y2,Zl,Jy)}},[])}const Zy=new Set;function zQ(e){return Zy.add(e),()=>Zy.delete(e)}function $Q(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 VQ(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 RJ(e,t){const s=(e.split("/").at(-1)??"").toLowerCase();return t.map(r=>({viewer:r,length:VQ(s,r.extensions)})).filter(r=>r.length>0).sort((r,o)=>o.length-r.length).map(r=>r.viewer)}const MJ=e=>`${e.pluginId}:${e.id}`;let X2=[];const nh=new Set;function ew(e){X2=e;for(const t of nh)t()}function HQ(e){return nh.add(e),()=>nh.delete(e)}const tw=()=>X2;function PJ(){return f.useSyncExternalStore(HQ,tw,tw)}function nw(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 Q2(e,t){try{t?.dispose()}catch(s){console.warn(`[plugin] ${e} 渲染模块卸载失败`,s)}}async function WQ(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||nw(c)!==l.key)&&i.push(a)}for(const a of i)Q2(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=nw(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 UQ(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 GQ={conversation:e=>X.getState().conversations[e]??null,focus:(e,t)=>{const s=X.getState();s.selectConversation(e),t!==e&&s.selectTab(e,t)},focusSubagent:(e,t)=>X.getState().focusSubagent(e,t),openChildRun:(e,t)=>X.getState().openChildRun(e,t),create:(e,t)=>X.getState().newConversation(e,t?{presetId:t}:void 0),prefill:K3,ensure:async e=>{const t=X.getState(),s=t.conversations[e];if(s?.started||s?.spawning)return null;await t.resumeConversation(e,{fresh:!0});const r=X.getState().conversations[e];return r?.started||r?.spawning?null:r?.error??"无法启动会话:请检查默认模型与登录状态"},openPluginView:(e,t)=>Y3({conversationId:e,...t}),closePluginView:(e,t)=>q3({conversationId:e,...t})};function KQ(){return f.useEffect(()=>{const e=Q3(()=>$G(X.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 $Q(c,r))Ie({type:"warning",title:`插件 ${d} 的检查连续失败,已临时放行`,description:`${m} 事件 30 秒内不再经过该插件;详情见设置里的插件日志`});const u=c.filter(d=>d.state==="enabled");U3(Object.fromEntries(c.flatMap(d=>d.icon?[[d.id,d.icon]]:[]))),wg(G3(c)),Xb(iK(c)),jg(u.flatMap(d=>d.views.map(m=>({pluginId:d.id,pluginName:d.name,...m})))),ew(u.flatMap(d=>(d.fileViewers??[]).map(m=>({pluginId:d.id,pluginName:d.name,...m})))),Zb(u.flatMap(d=>d.triggers.filter(m=>m.symbol==="#").map(m=>({pluginId:d.id,name:m.name})))),await WQ(s,c,d=>X3(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"){UQ(l,GQ).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,...W3(l)})});return()=>{t+=1,i(),a(),wg([]),Zb([]),jg([]),ew([]),Xb([]);for(const[l,c]of s)Q2(l,c);s.clear()}},[]),null}function qQ(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 Pf={exports:{}};const YQ={},XQ=Object.freeze(Object.defineProperty({__proto__:null,default:YQ},Symbol.toStringTag,{value:"Module"})),QQ=J3(XQ);var sw;function JQ(){return sw||(sw=1,(function(e){(function(t){var s=function(S){var P,I=new Float64Array(16);if(S)for(P=0;P<S.length;P++)I[P]=S[P];return I},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(S,P,I,v){S[P]=I>>24&255,S[P+1]=I>>16&255,S[P+2]=I>>8&255,S[P+3]=I&255,S[P+4]=v>>24&255,S[P+5]=v>>16&255,S[P+6]=v>>8&255,S[P+7]=v&255}function x(S,P,I,v,R){var ee,re=0;for(ee=0;ee<R;ee++)re|=S[P+ee]^I[v+ee];return(1&re-1>>>8)-1}function y(S,P,I,v){return x(S,P,I,v,16)}function j(S,P,I,v){return x(S,P,I,v,32)}function w(S,P,I,v){for(var R=v[0]&255|(v[1]&255)<<8|(v[2]&255)<<16|(v[3]&255)<<24,ee=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,re=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,Se=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,Re=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,We=v[4]&255|(v[5]&255)<<8|(v[6]&255)<<16|(v[7]&255)<<24,Ge=P[0]&255|(P[1]&255)<<8|(P[2]&255)<<16|(P[3]&255)<<24,St=P[4]&255|(P[5]&255)<<8|(P[6]&255)<<16|(P[7]&255)<<24,Qe=P[8]&255|(P[9]&255)<<8|(P[10]&255)<<16|(P[11]&255)<<24,le=P[12]&255|(P[13]&255)<<8|(P[14]&255)<<16|(P[15]&255)<<24,ke=v[8]&255|(v[9]&255)<<8|(v[10]&255)<<16|(v[11]&255)<<24,Le=I[16]&255|(I[17]&255)<<8|(I[18]&255)<<16|(I[19]&255)<<24,Be=I[20]&255|(I[21]&255)<<8|(I[22]&255)<<16|(I[23]&255)<<24,Ze=I[24]&255|(I[25]&255)<<8|(I[26]&255)<<16|(I[27]&255)<<24,ht=I[28]&255|(I[29]&255)<<8|(I[30]&255)<<16|(I[31]&255)<<24,lt=v[12]&255|(v[13]&255)<<8|(v[14]&255)<<16|(v[15]&255)<<24,$e=R,nt=ee,Ye=re,et=Se,dt=Re,qe=We,ve=Ge,be=St,Me=Qe,Te=le,ye=ke,Pe=Le,ft=Be,Ct=Ze,Rt=ht,Tt=lt,q,At=0;At<20;At+=2)q=$e+ft|0,dt^=q<<7|q>>>25,q=dt+$e|0,Me^=q<<9|q>>>23,q=Me+dt|0,ft^=q<<13|q>>>19,q=ft+Me|0,$e^=q<<18|q>>>14,q=qe+nt|0,Te^=q<<7|q>>>25,q=Te+qe|0,Ct^=q<<9|q>>>23,q=Ct+Te|0,nt^=q<<13|q>>>19,q=nt+Ct|0,qe^=q<<18|q>>>14,q=ye+ve|0,Rt^=q<<7|q>>>25,q=Rt+ye|0,Ye^=q<<9|q>>>23,q=Ye+Rt|0,ve^=q<<13|q>>>19,q=ve+Ye|0,ye^=q<<18|q>>>14,q=Tt+Pe|0,et^=q<<7|q>>>25,q=et+Tt|0,be^=q<<9|q>>>23,q=be+et|0,Pe^=q<<13|q>>>19,q=Pe+be|0,Tt^=q<<18|q>>>14,q=$e+et|0,nt^=q<<7|q>>>25,q=nt+$e|0,Ye^=q<<9|q>>>23,q=Ye+nt|0,et^=q<<13|q>>>19,q=et+Ye|0,$e^=q<<18|q>>>14,q=qe+dt|0,ve^=q<<7|q>>>25,q=ve+qe|0,be^=q<<9|q>>>23,q=be+ve|0,dt^=q<<13|q>>>19,q=dt+be|0,qe^=q<<18|q>>>14,q=ye+Te|0,Pe^=q<<7|q>>>25,q=Pe+ye|0,Me^=q<<9|q>>>23,q=Me+Pe|0,Te^=q<<13|q>>>19,q=Te+Me|0,ye^=q<<18|q>>>14,q=Tt+Rt|0,ft^=q<<7|q>>>25,q=ft+Tt|0,Ct^=q<<9|q>>>23,q=Ct+ft|0,Rt^=q<<13|q>>>19,q=Rt+Ct|0,Tt^=q<<18|q>>>14;$e=$e+R|0,nt=nt+ee|0,Ye=Ye+re|0,et=et+Se|0,dt=dt+Re|0,qe=qe+We|0,ve=ve+Ge|0,be=be+St|0,Me=Me+Qe|0,Te=Te+le|0,ye=ye+ke|0,Pe=Pe+Le|0,ft=ft+Be|0,Ct=Ct+Ze|0,Rt=Rt+ht|0,Tt=Tt+lt|0,S[0]=$e>>>0&255,S[1]=$e>>>8&255,S[2]=$e>>>16&255,S[3]=$e>>>24&255,S[4]=nt>>>0&255,S[5]=nt>>>8&255,S[6]=nt>>>16&255,S[7]=nt>>>24&255,S[8]=Ye>>>0&255,S[9]=Ye>>>8&255,S[10]=Ye>>>16&255,S[11]=Ye>>>24&255,S[12]=et>>>0&255,S[13]=et>>>8&255,S[14]=et>>>16&255,S[15]=et>>>24&255,S[16]=dt>>>0&255,S[17]=dt>>>8&255,S[18]=dt>>>16&255,S[19]=dt>>>24&255,S[20]=qe>>>0&255,S[21]=qe>>>8&255,S[22]=qe>>>16&255,S[23]=qe>>>24&255,S[24]=ve>>>0&255,S[25]=ve>>>8&255,S[26]=ve>>>16&255,S[27]=ve>>>24&255,S[28]=be>>>0&255,S[29]=be>>>8&255,S[30]=be>>>16&255,S[31]=be>>>24&255,S[32]=Me>>>0&255,S[33]=Me>>>8&255,S[34]=Me>>>16&255,S[35]=Me>>>24&255,S[36]=Te>>>0&255,S[37]=Te>>>8&255,S[38]=Te>>>16&255,S[39]=Te>>>24&255,S[40]=ye>>>0&255,S[41]=ye>>>8&255,S[42]=ye>>>16&255,S[43]=ye>>>24&255,S[44]=Pe>>>0&255,S[45]=Pe>>>8&255,S[46]=Pe>>>16&255,S[47]=Pe>>>24&255,S[48]=ft>>>0&255,S[49]=ft>>>8&255,S[50]=ft>>>16&255,S[51]=ft>>>24&255,S[52]=Ct>>>0&255,S[53]=Ct>>>8&255,S[54]=Ct>>>16&255,S[55]=Ct>>>24&255,S[56]=Rt>>>0&255,S[57]=Rt>>>8&255,S[58]=Rt>>>16&255,S[59]=Rt>>>24&255,S[60]=Tt>>>0&255,S[61]=Tt>>>8&255,S[62]=Tt>>>16&255,S[63]=Tt>>>24&255}function b(S,P,I,v){for(var R=v[0]&255|(v[1]&255)<<8|(v[2]&255)<<16|(v[3]&255)<<24,ee=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,re=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,Se=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,Re=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,We=v[4]&255|(v[5]&255)<<8|(v[6]&255)<<16|(v[7]&255)<<24,Ge=P[0]&255|(P[1]&255)<<8|(P[2]&255)<<16|(P[3]&255)<<24,St=P[4]&255|(P[5]&255)<<8|(P[6]&255)<<16|(P[7]&255)<<24,Qe=P[8]&255|(P[9]&255)<<8|(P[10]&255)<<16|(P[11]&255)<<24,le=P[12]&255|(P[13]&255)<<8|(P[14]&255)<<16|(P[15]&255)<<24,ke=v[8]&255|(v[9]&255)<<8|(v[10]&255)<<16|(v[11]&255)<<24,Le=I[16]&255|(I[17]&255)<<8|(I[18]&255)<<16|(I[19]&255)<<24,Be=I[20]&255|(I[21]&255)<<8|(I[22]&255)<<16|(I[23]&255)<<24,Ze=I[24]&255|(I[25]&255)<<8|(I[26]&255)<<16|(I[27]&255)<<24,ht=I[28]&255|(I[29]&255)<<8|(I[30]&255)<<16|(I[31]&255)<<24,lt=v[12]&255|(v[13]&255)<<8|(v[14]&255)<<16|(v[15]&255)<<24,$e=R,nt=ee,Ye=re,et=Se,dt=Re,qe=We,ve=Ge,be=St,Me=Qe,Te=le,ye=ke,Pe=Le,ft=Be,Ct=Ze,Rt=ht,Tt=lt,q,At=0;At<20;At+=2)q=$e+ft|0,dt^=q<<7|q>>>25,q=dt+$e|0,Me^=q<<9|q>>>23,q=Me+dt|0,ft^=q<<13|q>>>19,q=ft+Me|0,$e^=q<<18|q>>>14,q=qe+nt|0,Te^=q<<7|q>>>25,q=Te+qe|0,Ct^=q<<9|q>>>23,q=Ct+Te|0,nt^=q<<13|q>>>19,q=nt+Ct|0,qe^=q<<18|q>>>14,q=ye+ve|0,Rt^=q<<7|q>>>25,q=Rt+ye|0,Ye^=q<<9|q>>>23,q=Ye+Rt|0,ve^=q<<13|q>>>19,q=ve+Ye|0,ye^=q<<18|q>>>14,q=Tt+Pe|0,et^=q<<7|q>>>25,q=et+Tt|0,be^=q<<9|q>>>23,q=be+et|0,Pe^=q<<13|q>>>19,q=Pe+be|0,Tt^=q<<18|q>>>14,q=$e+et|0,nt^=q<<7|q>>>25,q=nt+$e|0,Ye^=q<<9|q>>>23,q=Ye+nt|0,et^=q<<13|q>>>19,q=et+Ye|0,$e^=q<<18|q>>>14,q=qe+dt|0,ve^=q<<7|q>>>25,q=ve+qe|0,be^=q<<9|q>>>23,q=be+ve|0,dt^=q<<13|q>>>19,q=dt+be|0,qe^=q<<18|q>>>14,q=ye+Te|0,Pe^=q<<7|q>>>25,q=Pe+ye|0,Me^=q<<9|q>>>23,q=Me+Pe|0,Te^=q<<13|q>>>19,q=Te+Me|0,ye^=q<<18|q>>>14,q=Tt+Rt|0,ft^=q<<7|q>>>25,q=ft+Tt|0,Ct^=q<<9|q>>>23,q=Ct+ft|0,Rt^=q<<13|q>>>19,q=Rt+Ct|0,Tt^=q<<18|q>>>14;S[0]=$e>>>0&255,S[1]=$e>>>8&255,S[2]=$e>>>16&255,S[3]=$e>>>24&255,S[4]=qe>>>0&255,S[5]=qe>>>8&255,S[6]=qe>>>16&255,S[7]=qe>>>24&255,S[8]=ye>>>0&255,S[9]=ye>>>8&255,S[10]=ye>>>16&255,S[11]=ye>>>24&255,S[12]=Tt>>>0&255,S[13]=Tt>>>8&255,S[14]=Tt>>>16&255,S[15]=Tt>>>24&255,S[16]=ve>>>0&255,S[17]=ve>>>8&255,S[18]=ve>>>16&255,S[19]=ve>>>24&255,S[20]=be>>>0&255,S[21]=be>>>8&255,S[22]=be>>>16&255,S[23]=be>>>24&255,S[24]=Me>>>0&255,S[25]=Me>>>8&255,S[26]=Me>>>16&255,S[27]=Me>>>24&255,S[28]=Te>>>0&255,S[29]=Te>>>8&255,S[30]=Te>>>16&255,S[31]=Te>>>24&255}function N(S,P,I,v){w(S,P,I,v)}function C(S,P,I,v){b(S,P,I,v)}var E=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function T(S,P,I,v,R,ee,re){var Se=new Uint8Array(16),Re=new Uint8Array(64),We,Ge;for(Ge=0;Ge<16;Ge++)Se[Ge]=0;for(Ge=0;Ge<8;Ge++)Se[Ge]=ee[Ge];for(;R>=64;){for(N(Re,Se,re,E),Ge=0;Ge<64;Ge++)S[P+Ge]=I[v+Ge]^Re[Ge];for(We=1,Ge=8;Ge<16;Ge++)We=We+(Se[Ge]&255)|0,Se[Ge]=We&255,We>>>=8;R-=64,P+=64,v+=64}if(R>0)for(N(Re,Se,re,E),Ge=0;Ge<R;Ge++)S[P+Ge]=I[v+Ge]^Re[Ge];return 0}function k(S,P,I,v,R){var ee=new Uint8Array(16),re=new Uint8Array(64),Se,Re;for(Re=0;Re<16;Re++)ee[Re]=0;for(Re=0;Re<8;Re++)ee[Re]=v[Re];for(;I>=64;){for(N(re,ee,R,E),Re=0;Re<64;Re++)S[P+Re]=re[Re];for(Se=1,Re=8;Re<16;Re++)Se=Se+(ee[Re]&255)|0,ee[Re]=Se&255,Se>>>=8;I-=64,P+=64}if(I>0)for(N(re,ee,R,E),Re=0;Re<I;Re++)S[P+Re]=re[Re];return 0}function L(S,P,I,v,R){var ee=new Uint8Array(32);C(ee,v,R,E);for(var re=new Uint8Array(8),Se=0;Se<8;Se++)re[Se]=v[Se+16];return k(S,P,I,re,ee)}function F(S,P,I,v,R,ee,re){var Se=new Uint8Array(32);C(Se,ee,re,E);for(var Re=new Uint8Array(8),We=0;We<8;We++)Re[We]=ee[We+16];return T(S,P,I,v,R,Re,Se)}var A=function(S){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 P,I,v,R,ee,re,Se,Re;P=S[0]&255|(S[1]&255)<<8,this.r[0]=P&8191,I=S[2]&255|(S[3]&255)<<8,this.r[1]=(P>>>13|I<<3)&8191,v=S[4]&255|(S[5]&255)<<8,this.r[2]=(I>>>10|v<<6)&7939,R=S[6]&255|(S[7]&255)<<8,this.r[3]=(v>>>7|R<<9)&8191,ee=S[8]&255|(S[9]&255)<<8,this.r[4]=(R>>>4|ee<<12)&255,this.r[5]=ee>>>1&8190,re=S[10]&255|(S[11]&255)<<8,this.r[6]=(ee>>>14|re<<2)&8191,Se=S[12]&255|(S[13]&255)<<8,this.r[7]=(re>>>11|Se<<5)&8065,Re=S[14]&255|(S[15]&255)<<8,this.r[8]=(Se>>>8|Re<<8)&8191,this.r[9]=Re>>>5&127,this.pad[0]=S[16]&255|(S[17]&255)<<8,this.pad[1]=S[18]&255|(S[19]&255)<<8,this.pad[2]=S[20]&255|(S[21]&255)<<8,this.pad[3]=S[22]&255|(S[23]&255)<<8,this.pad[4]=S[24]&255|(S[25]&255)<<8,this.pad[5]=S[26]&255|(S[27]&255)<<8,this.pad[6]=S[28]&255|(S[29]&255)<<8,this.pad[7]=S[30]&255|(S[31]&255)<<8};A.prototype.blocks=function(S,P,I){for(var v=this.fin?0:2048,R,ee,re,Se,Re,We,Ge,St,Qe,le,ke,Le,Be,Ze,ht,lt,$e,nt,Ye,et=this.h[0],dt=this.h[1],qe=this.h[2],ve=this.h[3],be=this.h[4],Me=this.h[5],Te=this.h[6],ye=this.h[7],Pe=this.h[8],ft=this.h[9],Ct=this.r[0],Rt=this.r[1],Tt=this.r[2],q=this.r[3],At=this.r[4],Kt=this.r[5],qt=this.r[6],Et=this.r[7],Mt=this.r[8],Wt=this.r[9];I>=16;)R=S[P+0]&255|(S[P+1]&255)<<8,et+=R&8191,ee=S[P+2]&255|(S[P+3]&255)<<8,dt+=(R>>>13|ee<<3)&8191,re=S[P+4]&255|(S[P+5]&255)<<8,qe+=(ee>>>10|re<<6)&8191,Se=S[P+6]&255|(S[P+7]&255)<<8,ve+=(re>>>7|Se<<9)&8191,Re=S[P+8]&255|(S[P+9]&255)<<8,be+=(Se>>>4|Re<<12)&8191,Me+=Re>>>1&8191,We=S[P+10]&255|(S[P+11]&255)<<8,Te+=(Re>>>14|We<<2)&8191,Ge=S[P+12]&255|(S[P+13]&255)<<8,ye+=(We>>>11|Ge<<5)&8191,St=S[P+14]&255|(S[P+15]&255)<<8,Pe+=(Ge>>>8|St<<8)&8191,ft+=St>>>5|v,Qe=0,le=Qe,le+=et*Ct,le+=dt*(5*Wt),le+=qe*(5*Mt),le+=ve*(5*Et),le+=be*(5*qt),Qe=le>>>13,le&=8191,le+=Me*(5*Kt),le+=Te*(5*At),le+=ye*(5*q),le+=Pe*(5*Tt),le+=ft*(5*Rt),Qe+=le>>>13,le&=8191,ke=Qe,ke+=et*Rt,ke+=dt*Ct,ke+=qe*(5*Wt),ke+=ve*(5*Mt),ke+=be*(5*Et),Qe=ke>>>13,ke&=8191,ke+=Me*(5*qt),ke+=Te*(5*Kt),ke+=ye*(5*At),ke+=Pe*(5*q),ke+=ft*(5*Tt),Qe+=ke>>>13,ke&=8191,Le=Qe,Le+=et*Tt,Le+=dt*Rt,Le+=qe*Ct,Le+=ve*(5*Wt),Le+=be*(5*Mt),Qe=Le>>>13,Le&=8191,Le+=Me*(5*Et),Le+=Te*(5*qt),Le+=ye*(5*Kt),Le+=Pe*(5*At),Le+=ft*(5*q),Qe+=Le>>>13,Le&=8191,Be=Qe,Be+=et*q,Be+=dt*Tt,Be+=qe*Rt,Be+=ve*Ct,Be+=be*(5*Wt),Qe=Be>>>13,Be&=8191,Be+=Me*(5*Mt),Be+=Te*(5*Et),Be+=ye*(5*qt),Be+=Pe*(5*Kt),Be+=ft*(5*At),Qe+=Be>>>13,Be&=8191,Ze=Qe,Ze+=et*At,Ze+=dt*q,Ze+=qe*Tt,Ze+=ve*Rt,Ze+=be*Ct,Qe=Ze>>>13,Ze&=8191,Ze+=Me*(5*Wt),Ze+=Te*(5*Mt),Ze+=ye*(5*Et),Ze+=Pe*(5*qt),Ze+=ft*(5*Kt),Qe+=Ze>>>13,Ze&=8191,ht=Qe,ht+=et*Kt,ht+=dt*At,ht+=qe*q,ht+=ve*Tt,ht+=be*Rt,Qe=ht>>>13,ht&=8191,ht+=Me*Ct,ht+=Te*(5*Wt),ht+=ye*(5*Mt),ht+=Pe*(5*Et),ht+=ft*(5*qt),Qe+=ht>>>13,ht&=8191,lt=Qe,lt+=et*qt,lt+=dt*Kt,lt+=qe*At,lt+=ve*q,lt+=be*Tt,Qe=lt>>>13,lt&=8191,lt+=Me*Rt,lt+=Te*Ct,lt+=ye*(5*Wt),lt+=Pe*(5*Mt),lt+=ft*(5*Et),Qe+=lt>>>13,lt&=8191,$e=Qe,$e+=et*Et,$e+=dt*qt,$e+=qe*Kt,$e+=ve*At,$e+=be*q,Qe=$e>>>13,$e&=8191,$e+=Me*Tt,$e+=Te*Rt,$e+=ye*Ct,$e+=Pe*(5*Wt),$e+=ft*(5*Mt),Qe+=$e>>>13,$e&=8191,nt=Qe,nt+=et*Mt,nt+=dt*Et,nt+=qe*qt,nt+=ve*Kt,nt+=be*At,Qe=nt>>>13,nt&=8191,nt+=Me*q,nt+=Te*Tt,nt+=ye*Rt,nt+=Pe*Ct,nt+=ft*(5*Wt),Qe+=nt>>>13,nt&=8191,Ye=Qe,Ye+=et*Wt,Ye+=dt*Mt,Ye+=qe*Et,Ye+=ve*qt,Ye+=be*Kt,Qe=Ye>>>13,Ye&=8191,Ye+=Me*At,Ye+=Te*q,Ye+=ye*Tt,Ye+=Pe*Rt,Ye+=ft*Ct,Qe+=Ye>>>13,Ye&=8191,Qe=(Qe<<2)+Qe|0,Qe=Qe+le|0,le=Qe&8191,Qe=Qe>>>13,ke+=Qe,et=le,dt=ke,qe=Le,ve=Be,be=Ze,Me=ht,Te=lt,ye=$e,Pe=nt,ft=Ye,P+=16,I-=16;this.h[0]=et,this.h[1]=dt,this.h[2]=qe,this.h[3]=ve,this.h[4]=be,this.h[5]=Me,this.h[6]=Te,this.h[7]=ye,this.h[8]=Pe,this.h[9]=ft},A.prototype.finish=function(S,P){var I=new Uint16Array(10),v,R,ee,re;if(this.leftover){for(re=this.leftover,this.buffer[re++]=1;re<16;re++)this.buffer[re]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(v=this.h[1]>>>13,this.h[1]&=8191,re=2;re<10;re++)this.h[re]+=v,v=this.h[re]>>>13,this.h[re]&=8191;for(this.h[0]+=v*5,v=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=v,v=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=v,I[0]=this.h[0]+5,v=I[0]>>>13,I[0]&=8191,re=1;re<10;re++)I[re]=this.h[re]+v,v=I[re]>>>13,I[re]&=8191;for(I[9]-=8192,R=(v^1)-1,re=0;re<10;re++)I[re]&=R;for(R=~R,re=0;re<10;re++)this.h[re]=this.h[re]&R|I[re];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,ee=this.h[0]+this.pad[0],this.h[0]=ee&65535,re=1;re<8;re++)ee=(this.h[re]+this.pad[re]|0)+(ee>>>16)|0,this.h[re]=ee&65535;S[P+0]=this.h[0]>>>0&255,S[P+1]=this.h[0]>>>8&255,S[P+2]=this.h[1]>>>0&255,S[P+3]=this.h[1]>>>8&255,S[P+4]=this.h[2]>>>0&255,S[P+5]=this.h[2]>>>8&255,S[P+6]=this.h[3]>>>0&255,S[P+7]=this.h[3]>>>8&255,S[P+8]=this.h[4]>>>0&255,S[P+9]=this.h[4]>>>8&255,S[P+10]=this.h[5]>>>0&255,S[P+11]=this.h[5]>>>8&255,S[P+12]=this.h[6]>>>0&255,S[P+13]=this.h[6]>>>8&255,S[P+14]=this.h[7]>>>0&255,S[P+15]=this.h[7]>>>8&255},A.prototype.update=function(S,P,I){var v,R;if(this.leftover){for(R=16-this.leftover,R>I&&(R=I),v=0;v<R;v++)this.buffer[this.leftover+v]=S[P+v];if(I-=R,P+=R,this.leftover+=R,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(I>=16&&(R=I-I%16,this.blocks(S,P,R),P+=R,I-=R),I){for(v=0;v<I;v++)this.buffer[this.leftover+v]=S[P+v];this.leftover+=I}};function D(S,P,I,v,R,ee){var re=new A(ee);return re.update(I,v,R),re.finish(S,P),0}function M(S,P,I,v,R,ee){var re=new Uint8Array(16);return D(re,0,I,v,R,ee),y(S,P,re,0)}function H(S,P,I,v,R){var ee;if(I<32)return-1;for(F(S,0,P,0,I,v,R),D(S,16,S,32,I-32,S),ee=0;ee<16;ee++)S[ee]=0;return 0}function G(S,P,I,v,R){var ee,re=new Uint8Array(32);if(I<32||(L(re,0,32,v,R),M(P,16,P,32,I-32,re)!==0))return-1;for(F(S,0,P,0,I,v,R),ee=0;ee<32;ee++)S[ee]=0;return 0}function U(S,P){var I;for(I=0;I<16;I++)S[I]=P[I]|0}function J(S){var P,I,v=1;for(P=0;P<16;P++)I=S[P]+v+65535,v=Math.floor(I/65536),S[P]=I-v*65536;S[0]+=v-1+37*(v-1)}function $(S,P,I){for(var v,R=~(I-1),ee=0;ee<16;ee++)v=R&(S[ee]^P[ee]),S[ee]^=v,P[ee]^=v}function oe(S,P){var I,v,R,ee=s(),re=s();for(I=0;I<16;I++)re[I]=P[I];for(J(re),J(re),J(re),v=0;v<2;v++){for(ee[0]=re[0]-65517,I=1;I<15;I++)ee[I]=re[I]-65535-(ee[I-1]>>16&1),ee[I-1]&=65535;ee[15]=re[15]-32767-(ee[14]>>16&1),R=ee[15]>>16&1,ee[14]&=65535,$(re,ee,1-R)}for(I=0;I<16;I++)S[2*I]=re[I]&255,S[2*I+1]=re[I]>>8}function Ne(S,P){var I=new Uint8Array(32),v=new Uint8Array(32);return oe(I,S),oe(v,P),j(I,0,v,0)}function ce(S){var P=new Uint8Array(32);return oe(P,S),P[0]&1}function ne(S,P){var I;for(I=0;I<16;I++)S[I]=P[2*I]+(P[2*I+1]<<8);S[15]&=32767}function Y(S,P,I){for(var v=0;v<16;v++)S[v]=P[v]+I[v]}function pe(S,P,I){for(var v=0;v<16;v++)S[v]=P[v]-I[v]}function ge(S,P,I){var v,R,ee=0,re=0,Se=0,Re=0,We=0,Ge=0,St=0,Qe=0,le=0,ke=0,Le=0,Be=0,Ze=0,ht=0,lt=0,$e=0,nt=0,Ye=0,et=0,dt=0,qe=0,ve=0,be=0,Me=0,Te=0,ye=0,Pe=0,ft=0,Ct=0,Rt=0,Tt=0,q=I[0],At=I[1],Kt=I[2],qt=I[3],Et=I[4],Mt=I[5],Wt=I[6],jn=I[7],Qt=I[8],kn=I[9],hn=I[10],an=I[11],Ut=I[12],An=I[13],Nn=I[14],Rn=I[15];v=P[0],ee+=v*q,re+=v*At,Se+=v*Kt,Re+=v*qt,We+=v*Et,Ge+=v*Mt,St+=v*Wt,Qe+=v*jn,le+=v*Qt,ke+=v*kn,Le+=v*hn,Be+=v*an,Ze+=v*Ut,ht+=v*An,lt+=v*Nn,$e+=v*Rn,v=P[1],re+=v*q,Se+=v*At,Re+=v*Kt,We+=v*qt,Ge+=v*Et,St+=v*Mt,Qe+=v*Wt,le+=v*jn,ke+=v*Qt,Le+=v*kn,Be+=v*hn,Ze+=v*an,ht+=v*Ut,lt+=v*An,$e+=v*Nn,nt+=v*Rn,v=P[2],Se+=v*q,Re+=v*At,We+=v*Kt,Ge+=v*qt,St+=v*Et,Qe+=v*Mt,le+=v*Wt,ke+=v*jn,Le+=v*Qt,Be+=v*kn,Ze+=v*hn,ht+=v*an,lt+=v*Ut,$e+=v*An,nt+=v*Nn,Ye+=v*Rn,v=P[3],Re+=v*q,We+=v*At,Ge+=v*Kt,St+=v*qt,Qe+=v*Et,le+=v*Mt,ke+=v*Wt,Le+=v*jn,Be+=v*Qt,Ze+=v*kn,ht+=v*hn,lt+=v*an,$e+=v*Ut,nt+=v*An,Ye+=v*Nn,et+=v*Rn,v=P[4],We+=v*q,Ge+=v*At,St+=v*Kt,Qe+=v*qt,le+=v*Et,ke+=v*Mt,Le+=v*Wt,Be+=v*jn,Ze+=v*Qt,ht+=v*kn,lt+=v*hn,$e+=v*an,nt+=v*Ut,Ye+=v*An,et+=v*Nn,dt+=v*Rn,v=P[5],Ge+=v*q,St+=v*At,Qe+=v*Kt,le+=v*qt,ke+=v*Et,Le+=v*Mt,Be+=v*Wt,Ze+=v*jn,ht+=v*Qt,lt+=v*kn,$e+=v*hn,nt+=v*an,Ye+=v*Ut,et+=v*An,dt+=v*Nn,qe+=v*Rn,v=P[6],St+=v*q,Qe+=v*At,le+=v*Kt,ke+=v*qt,Le+=v*Et,Be+=v*Mt,Ze+=v*Wt,ht+=v*jn,lt+=v*Qt,$e+=v*kn,nt+=v*hn,Ye+=v*an,et+=v*Ut,dt+=v*An,qe+=v*Nn,ve+=v*Rn,v=P[7],Qe+=v*q,le+=v*At,ke+=v*Kt,Le+=v*qt,Be+=v*Et,Ze+=v*Mt,ht+=v*Wt,lt+=v*jn,$e+=v*Qt,nt+=v*kn,Ye+=v*hn,et+=v*an,dt+=v*Ut,qe+=v*An,ve+=v*Nn,be+=v*Rn,v=P[8],le+=v*q,ke+=v*At,Le+=v*Kt,Be+=v*qt,Ze+=v*Et,ht+=v*Mt,lt+=v*Wt,$e+=v*jn,nt+=v*Qt,Ye+=v*kn,et+=v*hn,dt+=v*an,qe+=v*Ut,ve+=v*An,be+=v*Nn,Me+=v*Rn,v=P[9],ke+=v*q,Le+=v*At,Be+=v*Kt,Ze+=v*qt,ht+=v*Et,lt+=v*Mt,$e+=v*Wt,nt+=v*jn,Ye+=v*Qt,et+=v*kn,dt+=v*hn,qe+=v*an,ve+=v*Ut,be+=v*An,Me+=v*Nn,Te+=v*Rn,v=P[10],Le+=v*q,Be+=v*At,Ze+=v*Kt,ht+=v*qt,lt+=v*Et,$e+=v*Mt,nt+=v*Wt,Ye+=v*jn,et+=v*Qt,dt+=v*kn,qe+=v*hn,ve+=v*an,be+=v*Ut,Me+=v*An,Te+=v*Nn,ye+=v*Rn,v=P[11],Be+=v*q,Ze+=v*At,ht+=v*Kt,lt+=v*qt,$e+=v*Et,nt+=v*Mt,Ye+=v*Wt,et+=v*jn,dt+=v*Qt,qe+=v*kn,ve+=v*hn,be+=v*an,Me+=v*Ut,Te+=v*An,ye+=v*Nn,Pe+=v*Rn,v=P[12],Ze+=v*q,ht+=v*At,lt+=v*Kt,$e+=v*qt,nt+=v*Et,Ye+=v*Mt,et+=v*Wt,dt+=v*jn,qe+=v*Qt,ve+=v*kn,be+=v*hn,Me+=v*an,Te+=v*Ut,ye+=v*An,Pe+=v*Nn,ft+=v*Rn,v=P[13],ht+=v*q,lt+=v*At,$e+=v*Kt,nt+=v*qt,Ye+=v*Et,et+=v*Mt,dt+=v*Wt,qe+=v*jn,ve+=v*Qt,be+=v*kn,Me+=v*hn,Te+=v*an,ye+=v*Ut,Pe+=v*An,ft+=v*Nn,Ct+=v*Rn,v=P[14],lt+=v*q,$e+=v*At,nt+=v*Kt,Ye+=v*qt,et+=v*Et,dt+=v*Mt,qe+=v*Wt,ve+=v*jn,be+=v*Qt,Me+=v*kn,Te+=v*hn,ye+=v*an,Pe+=v*Ut,ft+=v*An,Ct+=v*Nn,Rt+=v*Rn,v=P[15],$e+=v*q,nt+=v*At,Ye+=v*Kt,et+=v*qt,dt+=v*Et,qe+=v*Mt,ve+=v*Wt,be+=v*jn,Me+=v*Qt,Te+=v*kn,ye+=v*hn,Pe+=v*an,ft+=v*Ut,Ct+=v*An,Rt+=v*Nn,Tt+=v*Rn,ee+=38*nt,re+=38*Ye,Se+=38*et,Re+=38*dt,We+=38*qe,Ge+=38*ve,St+=38*be,Qe+=38*Me,le+=38*Te,ke+=38*ye,Le+=38*Pe,Be+=38*ft,Ze+=38*Ct,ht+=38*Rt,lt+=38*Tt,R=1,v=ee+R+65535,R=Math.floor(v/65536),ee=v-R*65536,v=re+R+65535,R=Math.floor(v/65536),re=v-R*65536,v=Se+R+65535,R=Math.floor(v/65536),Se=v-R*65536,v=Re+R+65535,R=Math.floor(v/65536),Re=v-R*65536,v=We+R+65535,R=Math.floor(v/65536),We=v-R*65536,v=Ge+R+65535,R=Math.floor(v/65536),Ge=v-R*65536,v=St+R+65535,R=Math.floor(v/65536),St=v-R*65536,v=Qe+R+65535,R=Math.floor(v/65536),Qe=v-R*65536,v=le+R+65535,R=Math.floor(v/65536),le=v-R*65536,v=ke+R+65535,R=Math.floor(v/65536),ke=v-R*65536,v=Le+R+65535,R=Math.floor(v/65536),Le=v-R*65536,v=Be+R+65535,R=Math.floor(v/65536),Be=v-R*65536,v=Ze+R+65535,R=Math.floor(v/65536),Ze=v-R*65536,v=ht+R+65535,R=Math.floor(v/65536),ht=v-R*65536,v=lt+R+65535,R=Math.floor(v/65536),lt=v-R*65536,v=$e+R+65535,R=Math.floor(v/65536),$e=v-R*65536,ee+=R-1+37*(R-1),R=1,v=ee+R+65535,R=Math.floor(v/65536),ee=v-R*65536,v=re+R+65535,R=Math.floor(v/65536),re=v-R*65536,v=Se+R+65535,R=Math.floor(v/65536),Se=v-R*65536,v=Re+R+65535,R=Math.floor(v/65536),Re=v-R*65536,v=We+R+65535,R=Math.floor(v/65536),We=v-R*65536,v=Ge+R+65535,R=Math.floor(v/65536),Ge=v-R*65536,v=St+R+65535,R=Math.floor(v/65536),St=v-R*65536,v=Qe+R+65535,R=Math.floor(v/65536),Qe=v-R*65536,v=le+R+65535,R=Math.floor(v/65536),le=v-R*65536,v=ke+R+65535,R=Math.floor(v/65536),ke=v-R*65536,v=Le+R+65535,R=Math.floor(v/65536),Le=v-R*65536,v=Be+R+65535,R=Math.floor(v/65536),Be=v-R*65536,v=Ze+R+65535,R=Math.floor(v/65536),Ze=v-R*65536,v=ht+R+65535,R=Math.floor(v/65536),ht=v-R*65536,v=lt+R+65535,R=Math.floor(v/65536),lt=v-R*65536,v=$e+R+65535,R=Math.floor(v/65536),$e=v-R*65536,ee+=R-1+37*(R-1),S[0]=ee,S[1]=re,S[2]=Se,S[3]=Re,S[4]=We,S[5]=Ge,S[6]=St,S[7]=Qe,S[8]=le,S[9]=ke,S[10]=Le,S[11]=Be,S[12]=Ze,S[13]=ht,S[14]=lt,S[15]=$e}function we(S,P){ge(S,P,P)}function V(S,P){var I=s(),v;for(v=0;v<16;v++)I[v]=P[v];for(v=253;v>=0;v--)we(I,I),v!==2&&v!==4&&ge(I,I,P);for(v=0;v<16;v++)S[v]=I[v]}function W(S,P){var I=s(),v;for(v=0;v<16;v++)I[v]=P[v];for(v=250;v>=0;v--)we(I,I),v!==1&&ge(I,I,P);for(v=0;v<16;v++)S[v]=I[v]}function B(S,P,I){var v=new Uint8Array(32),R=new Float64Array(80),ee,re,Se=s(),Re=s(),We=s(),Ge=s(),St=s(),Qe=s();for(re=0;re<31;re++)v[re]=P[re];for(v[31]=P[31]&127|64,v[0]&=248,ne(R,I),re=0;re<16;re++)Re[re]=R[re],Ge[re]=Se[re]=We[re]=0;for(Se[0]=Ge[0]=1,re=254;re>=0;--re)ee=v[re>>>3]>>>(re&7)&1,$(Se,Re,ee),$(We,Ge,ee),Y(St,Se,We),pe(Se,Se,We),Y(We,Re,Ge),pe(Re,Re,Ge),we(Ge,St),we(Qe,Se),ge(Se,We,Se),ge(We,Re,St),Y(St,Se,We),pe(Se,Se,We),we(Re,Se),pe(We,Ge,Qe),ge(Se,We,c),Y(Se,Se,Ge),ge(We,We,Se),ge(Se,Ge,Qe),ge(Ge,Re,R),we(Re,St),$(Se,Re,ee),$(We,Ge,ee);for(re=0;re<16;re++)R[re+16]=Se[re],R[re+32]=We[re],R[re+48]=Re[re],R[re+64]=Ge[re];var le=R.subarray(32),ke=R.subarray(16);return V(le,le),ge(ke,ke,le),oe(S,ke),0}function te(S,P){return B(S,P,i)}function Z(S,P){return r(P,32),te(S,P)}function ue(S,P,I){var v=new Uint8Array(32);return B(v,I,P),C(S,o,v,E)}var fe=H,Ce=G;function de(S,P,I,v,R,ee){var re=new Uint8Array(32);return ue(re,R,ee),fe(S,P,I,v,re)}function Ee(S,P,I,v,R,ee){var re=new Uint8Array(32);return ue(re,R,ee),Ce(S,P,I,v,re)}var me=[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 Ve(S,P,I,v){for(var R=new Int32Array(16),ee=new Int32Array(16),re,Se,Re,We,Ge,St,Qe,le,ke,Le,Be,Ze,ht,lt,$e,nt,Ye,et,dt,qe,ve,be,Me,Te,ye,Pe,ft=S[0],Ct=S[1],Rt=S[2],Tt=S[3],q=S[4],At=S[5],Kt=S[6],qt=S[7],Et=P[0],Mt=P[1],Wt=P[2],jn=P[3],Qt=P[4],kn=P[5],hn=P[6],an=P[7],Ut=0;v>=128;){for(dt=0;dt<16;dt++)qe=8*dt+Ut,R[dt]=I[qe+0]<<24|I[qe+1]<<16|I[qe+2]<<8|I[qe+3],ee[dt]=I[qe+4]<<24|I[qe+5]<<16|I[qe+6]<<8|I[qe+7];for(dt=0;dt<80;dt++)if(re=ft,Se=Ct,Re=Rt,We=Tt,Ge=q,St=At,Qe=Kt,le=qt,ke=Et,Le=Mt,Be=Wt,Ze=jn,ht=Qt,lt=kn,$e=hn,nt=an,ve=qt,be=an,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=(q>>>14|Qt<<18)^(q>>>18|Qt<<14)^(Qt>>>9|q<<23),be=(Qt>>>14|q<<18)^(Qt>>>18|q<<14)^(q>>>9|Qt<<23),Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,ve=q&At^~q&Kt,be=Qt&kn^~Qt&hn,Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,ve=me[dt*2],be=me[dt*2+1],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,ve=R[dt%16],be=ee[dt%16],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,Ye=ye&65535|Pe<<16,et=Me&65535|Te<<16,ve=Ye,be=et,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=(ft>>>28|Et<<4)^(Et>>>2|ft<<30)^(Et>>>7|ft<<25),be=(Et>>>28|ft<<4)^(ft>>>2|Et<<30)^(ft>>>7|Et<<25),Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,ve=ft&Ct^ft&Rt^Ct&Rt,be=Et&Mt^Et&Wt^Mt&Wt,Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,le=ye&65535|Pe<<16,nt=Me&65535|Te<<16,ve=We,be=Ze,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=Ye,be=et,Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,We=ye&65535|Pe<<16,Ze=Me&65535|Te<<16,Ct=re,Rt=Se,Tt=Re,q=We,At=Ge,Kt=St,qt=Qe,ft=le,Mt=ke,Wt=Le,jn=Be,Qt=Ze,kn=ht,hn=lt,an=$e,Et=nt,dt%16===15)for(qe=0;qe<16;qe++)ve=R[qe],be=ee[qe],Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=R[(qe+9)%16],be=ee[(qe+9)%16],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Ye=R[(qe+1)%16],et=ee[(qe+1)%16],ve=(Ye>>>1|et<<31)^(Ye>>>8|et<<24)^Ye>>>7,be=(et>>>1|Ye<<31)^(et>>>8|Ye<<24)^(et>>>7|Ye<<25),Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Ye=R[(qe+14)%16],et=ee[(qe+14)%16],ve=(Ye>>>19|et<<13)^(et>>>29|Ye<<3)^Ye>>>6,be=(et>>>19|Ye<<13)^(Ye>>>29|et<<3)^(et>>>6|Ye<<26),Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,R[qe]=ye&65535|Pe<<16,ee[qe]=Me&65535|Te<<16;ve=ft,be=Et,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[0],be=P[0],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[0]=ft=ye&65535|Pe<<16,P[0]=Et=Me&65535|Te<<16,ve=Ct,be=Mt,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[1],be=P[1],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[1]=Ct=ye&65535|Pe<<16,P[1]=Mt=Me&65535|Te<<16,ve=Rt,be=Wt,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[2],be=P[2],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[2]=Rt=ye&65535|Pe<<16,P[2]=Wt=Me&65535|Te<<16,ve=Tt,be=jn,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[3],be=P[3],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[3]=Tt=ye&65535|Pe<<16,P[3]=jn=Me&65535|Te<<16,ve=q,be=Qt,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[4],be=P[4],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[4]=q=ye&65535|Pe<<16,P[4]=Qt=Me&65535|Te<<16,ve=At,be=kn,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[5],be=P[5],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[5]=At=ye&65535|Pe<<16,P[5]=kn=Me&65535|Te<<16,ve=Kt,be=hn,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[6],be=P[6],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[6]=Kt=ye&65535|Pe<<16,P[6]=hn=Me&65535|Te<<16,ve=qt,be=an,Me=be&65535,Te=be>>>16,ye=ve&65535,Pe=ve>>>16,ve=S[7],be=P[7],Me+=be&65535,Te+=be>>>16,ye+=ve&65535,Pe+=ve>>>16,Te+=Me>>>16,ye+=Te>>>16,Pe+=ye>>>16,S[7]=qt=ye&65535|Pe<<16,P[7]=an=Me&65535|Te<<16,Ut+=128,v-=128}return v}function at(S,P,I){var v=new Int32Array(8),R=new Int32Array(8),ee=new Uint8Array(256),re,Se=I;for(v[0]=1779033703,v[1]=3144134277,v[2]=1013904242,v[3]=2773480762,v[4]=1359893119,v[5]=2600822924,v[6]=528734635,v[7]=1541459225,R[0]=4089235720,R[1]=2227873595,R[2]=4271175723,R[3]=1595750129,R[4]=2917565137,R[5]=725511199,R[6]=4215389547,R[7]=327033209,Ve(v,R,P,I),I%=128,re=0;re<I;re++)ee[re]=P[Se-I+re];for(ee[I]=128,I=256-128*(I<112?1:0),ee[I-9]=0,g(ee,I-8,Se/536870912|0,Se<<3),Ve(v,R,ee,I),re=0;re<8;re++)g(S,8*re,v[re],R[re]);return 0}function Fe(S,P){var I=s(),v=s(),R=s(),ee=s(),re=s(),Se=s(),Re=s(),We=s(),Ge=s();pe(I,S[1],S[0]),pe(Ge,P[1],P[0]),ge(I,I,Ge),Y(v,S[0],S[1]),Y(Ge,P[0],P[1]),ge(v,v,Ge),ge(R,S[3],P[3]),ge(R,R,d),ge(ee,S[2],P[2]),Y(ee,ee,ee),pe(re,v,I),pe(Se,ee,R),Y(Re,ee,R),Y(We,v,I),ge(S[0],re,Se),ge(S[1],We,Re),ge(S[2],Re,Se),ge(S[3],re,We)}function tt(S,P,I){var v;for(v=0;v<4;v++)$(S[v],P[v],I)}function je(S,P){var I=s(),v=s(),R=s();V(R,P[2]),ge(I,P[0],R),ge(v,P[1],R),oe(S,v),S[31]^=ce(I)<<7}function Je(S,P,I){var v,R;for(U(S[0],a),U(S[1],l),U(S[2],l),U(S[3],a),R=255;R>=0;--R)v=I[R/8|0]>>(R&7)&1,tt(S,P,v),Fe(P,S),Fe(S,S),tt(S,P,v)}function rt(S,P){var I=[s(),s(),s(),s()];U(I[0],m),U(I[1],h),U(I[2],l),ge(I[3],m,h),Je(S,I,P)}function K(S,P,I){var v=new Uint8Array(64),R=[s(),s(),s(),s()],ee;for(I||r(P,32),at(v,P,32),v[0]&=248,v[31]&=127,v[31]|=64,rt(R,v),je(S,R),ee=0;ee<32;ee++)P[ee+32]=S[ee];return 0}var Q=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 Ae(S,P){var I,v,R,ee;for(v=63;v>=32;--v){for(I=0,R=v-32,ee=v-12;R<ee;++R)P[R]+=I-16*P[v]*Q[R-(v-32)],I=Math.floor((P[R]+128)/256),P[R]-=I*256;P[R]+=I,P[v]=0}for(I=0,R=0;R<32;R++)P[R]+=I-(P[31]>>4)*Q[R],I=P[R]>>8,P[R]&=255;for(R=0;R<32;R++)P[R]-=I*Q[R];for(v=0;v<32;v++)P[v+1]+=P[v]>>8,S[v]=P[v]&255}function pt(S){var P=new Float64Array(64),I;for(I=0;I<64;I++)P[I]=S[I];for(I=0;I<64;I++)S[I]=0;Ae(S,P)}function Dt(S,P,I,v){var R=new Uint8Array(64),ee=new Uint8Array(64),re=new Uint8Array(64),Se,Re,We=new Float64Array(64),Ge=[s(),s(),s(),s()];at(R,v,32),R[0]&=248,R[31]&=127,R[31]|=64;var St=I+64;for(Se=0;Se<I;Se++)S[64+Se]=P[Se];for(Se=0;Se<32;Se++)S[32+Se]=R[32+Se];for(at(re,S.subarray(32),I+32),pt(re),rt(Ge,re),je(S,Ge),Se=32;Se<64;Se++)S[Se]=v[Se];for(at(ee,S,I+64),pt(ee),Se=0;Se<64;Se++)We[Se]=0;for(Se=0;Se<32;Se++)We[Se]=re[Se];for(Se=0;Se<32;Se++)for(Re=0;Re<32;Re++)We[Se+Re]+=ee[Se]*R[Re];return Ae(S.subarray(32),We),St}function Xe(S,P){var I=s(),v=s(),R=s(),ee=s(),re=s(),Se=s(),Re=s();return U(S[2],l),ne(S[1],P),we(R,S[1]),ge(ee,R,u),pe(R,R,S[2]),Y(ee,S[2],ee),we(re,ee),we(Se,re),ge(Re,Se,re),ge(I,Re,R),ge(I,I,ee),W(I,I),ge(I,I,R),ge(I,I,ee),ge(I,I,ee),ge(S[0],I,ee),we(v,S[0]),ge(v,v,ee),Ne(v,R)&&ge(S[0],S[0],p),we(v,S[0]),ge(v,v,ee),Ne(v,R)?-1:(ce(S[0])===P[31]>>7&&pe(S[0],a,S[0]),ge(S[3],S[0],S[1]),0)}function kt(S,P,I,v){var R,ee=new Uint8Array(32),re=new Uint8Array(64),Se=[s(),s(),s(),s()],Re=[s(),s(),s(),s()];if(I<64||Xe(Re,v))return-1;for(R=0;R<I;R++)S[R]=P[R];for(R=0;R<32;R++)S[R+32]=v[R];if(at(re,S,I),pt(re),Je(Se,Re,re),rt(Re,P.subarray(32)),Fe(Se,Re),je(ee,Se),I-=64,j(P,0,ee,0)){for(R=0;R<I;R++)S[R]=0;return-1}for(R=0;R<I;R++)S[R]=P[R+64];return I}var mn=32,_e=24,Nt=32,Ot=16,_t=32,se=32,Oe=32,ot=32,ct=32,xt=_e,gt=Nt,Ft=Ot,Ht=64,tn=32,Jt=64,Gt=32,gn=64;t.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:F,crypto_stream:L,crypto_stream_salsa20_xor:T,crypto_stream_salsa20:k,crypto_onetimeauth:D,crypto_onetimeauth_verify:M,crypto_verify_16:y,crypto_verify_32:j,crypto_secretbox:H,crypto_secretbox_open:G,crypto_scalarmult:B,crypto_scalarmult_base:te,crypto_box_beforenm:ue,crypto_box_afternm:fe,crypto_box:de,crypto_box_open:Ee,crypto_box_keypair:Z,crypto_hash:at,crypto_sign:Dt,crypto_sign_keypair:K,crypto_sign_open:kt,crypto_secretbox_KEYBYTES:mn,crypto_secretbox_NONCEBYTES:_e,crypto_secretbox_ZEROBYTES:Nt,crypto_secretbox_BOXZEROBYTES:Ot,crypto_scalarmult_BYTES:_t,crypto_scalarmult_SCALARBYTES:se,crypto_box_PUBLICKEYBYTES:Oe,crypto_box_SECRETKEYBYTES:ot,crypto_box_BEFORENMBYTES:ct,crypto_box_NONCEBYTES:xt,crypto_box_ZEROBYTES:gt,crypto_box_BOXZEROBYTES:Ft,crypto_sign_BYTES:Ht,crypto_sign_PUBLICKEYBYTES:tn,crypto_sign_SECRETKEYBYTES:Jt,crypto_sign_SEEDBYTES:Gt,crypto_hash_BYTES:gn,gf:s,D:u,L:Q,pack25519:oe,unpack25519:ne,M:ge,A:Y,S:we,Z:pe,pow2523:W,add:Fe,set25519:U,modL:Ae,scalarmult:Je,scalarbase:rt};function Qn(S,P){if(S.length!==mn)throw new Error("bad key size");if(P.length!==_e)throw new Error("bad nonce size")}function bt(S,P){if(S.length!==Oe)throw new Error("bad public key size");if(P.length!==ot)throw new Error("bad secret key size")}function sn(){for(var S=0;S<arguments.length;S++)if(!(arguments[S]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function Tn(S){for(var P=0;P<S.length;P++)S[P]=0}t.randomBytes=function(S){var P=new Uint8Array(S);return r(P,S),P},t.secretbox=function(S,P,I){sn(S,P,I),Qn(I,P);for(var v=new Uint8Array(Nt+S.length),R=new Uint8Array(v.length),ee=0;ee<S.length;ee++)v[ee+Nt]=S[ee];return H(R,v,v.length,P,I),R.subarray(Ot)},t.secretbox.open=function(S,P,I){sn(S,P,I),Qn(I,P);for(var v=new Uint8Array(Ot+S.length),R=new Uint8Array(v.length),ee=0;ee<S.length;ee++)v[ee+Ot]=S[ee];return v.length<32||G(R,v,v.length,P,I)!==0?null:R.subarray(Nt)},t.secretbox.keyLength=mn,t.secretbox.nonceLength=_e,t.secretbox.overheadLength=Ot,t.scalarMult=function(S,P){if(sn(S,P),S.length!==se)throw new Error("bad n size");if(P.length!==_t)throw new Error("bad p size");var I=new Uint8Array(_t);return B(I,S,P),I},t.scalarMult.base=function(S){if(sn(S),S.length!==se)throw new Error("bad n size");var P=new Uint8Array(_t);return te(P,S),P},t.scalarMult.scalarLength=se,t.scalarMult.groupElementLength=_t,t.box=function(S,P,I,v){var R=t.box.before(I,v);return t.secretbox(S,P,R)},t.box.before=function(S,P){sn(S,P),bt(S,P);var I=new Uint8Array(ct);return ue(I,S,P),I},t.box.after=t.secretbox,t.box.open=function(S,P,I,v){var R=t.box.before(I,v);return t.secretbox.open(S,P,R)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var S=new Uint8Array(Oe),P=new Uint8Array(ot);return Z(S,P),{publicKey:S,secretKey:P}},t.box.keyPair.fromSecretKey=function(S){if(sn(S),S.length!==ot)throw new Error("bad secret key size");var P=new Uint8Array(Oe);return te(P,S),{publicKey:P,secretKey:new Uint8Array(S)}},t.box.publicKeyLength=Oe,t.box.secretKeyLength=ot,t.box.sharedKeyLength=ct,t.box.nonceLength=xt,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(S,P){if(sn(S,P),P.length!==Jt)throw new Error("bad secret key size");var I=new Uint8Array(Ht+S.length);return Dt(I,S,S.length,P),I},t.sign.open=function(S,P){if(sn(S,P),P.length!==tn)throw new Error("bad public key size");var I=new Uint8Array(S.length),v=kt(I,S,S.length,P);if(v<0)return null;for(var R=new Uint8Array(v),ee=0;ee<R.length;ee++)R[ee]=I[ee];return R},t.sign.detached=function(S,P){for(var I=t.sign(S,P),v=new Uint8Array(Ht),R=0;R<v.length;R++)v[R]=I[R];return v},t.sign.detached.verify=function(S,P,I){if(sn(S,P,I),P.length!==Ht)throw new Error("bad signature size");if(I.length!==tn)throw new Error("bad public key size");var v=new Uint8Array(Ht+S.length),R=new Uint8Array(Ht+S.length),ee;for(ee=0;ee<Ht;ee++)v[ee]=P[ee];for(ee=0;ee<S.length;ee++)v[ee+Ht]=S[ee];return kt(R,v,v.length,I)>=0},t.sign.keyPair=function(){var S=new Uint8Array(tn),P=new Uint8Array(Jt);return K(S,P),{publicKey:S,secretKey:P}},t.sign.keyPair.fromSecretKey=function(S){if(sn(S),S.length!==Jt)throw new Error("bad secret key size");for(var P=new Uint8Array(tn),I=0;I<P.length;I++)P[I]=S[32+I];return{publicKey:P,secretKey:new Uint8Array(S)}},t.sign.keyPair.fromSeed=function(S){if(sn(S),S.length!==Gt)throw new Error("bad seed size");for(var P=new Uint8Array(tn),I=new Uint8Array(Jt),v=0;v<32;v++)I[v]=S[v];return K(P,I,!0),{publicKey:P,secretKey:I}},t.sign.publicKeyLength=tn,t.sign.secretKeyLength=Jt,t.sign.seedLength=Gt,t.sign.signatureLength=Ht,t.hash=function(S){sn(S);var P=new Uint8Array(gn);return at(P,S,S.length),P},t.hash.hashLength=gn,t.verify=function(S,P){return sn(S,P),S.length===0||P.length===0||S.length!==P.length?!1:x(S,0,P,0,S.length)===0},t.setPRNG=function(S){r=S},(function(){var S=typeof self<"u"?self.crypto||self.msCrypto:null;if(S&&S.getRandomValues){var P=65536;t.setPRNG(function(I,v){var R,ee=new Uint8Array(v);for(R=0;R<v;R+=P)S.getRandomValues(ee.subarray(R,R+Math.min(v-R,P)));for(R=0;R<v;R++)I[R]=ee[R];Tn(ee)})}else typeof qQ<"u"&&(S=QQ,S&&S.randomBytes&&t.setPRNG(function(I,v){var R,ee=S.randomBytes(v);for(R=0;R<v;R++)I[R]=ee[R];Tn(ee)}))})()})(e.exports?e.exports:self.nacl=self.nacl||{})})(Pf)),Pf.exports}JQ();new TextEncoder;new TextDecoder;function ZQ(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}:{}}:{}}}function eJ(e,t=[]){return JSON.stringify({pinnedOrder:t,entries:e.map(s=>{const{updatedAt:r,...o}=s;return o})})}function tJ(e){return JSON.stringify(e)}function nJ(e,t,s=[]){const r=Z3(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:Nj,name:"Auto",models:o.map(i=>({id:i.id,label:i.name}))}),r}function sJ(e,t,s=[]){const r=nJ(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 rJ(e){return e!=="scratch"&&e!=="secretary"}function oJ(e,t){return new Set(e.filter(s=>s.kind==="secretary"||!t&&s.kind==="scratch").map(s=>s.id))}const iJ=300;let ec=null,rw=!1,sh=null;function aJ(){const e=xe.getState(),t=X.getState(),r=Ix(e.projects,nr(hc)).filter(b=>rJ(b.kind)),o=new Set(nr(wr)),i=fw(uw(e.language),"Temporary chats"),a=new Map(e.projects.map(b=>[b.id,b.kind==="scratch"?i:Un(b)])),l=new Map(e.projects.map(b=>[b.id,b.path])),c=new Map(e.projects.map(b=>[b.id,b.kind])),u=b=>{const N=(b.parentId?t.conversations[b.parentId]:void 0)??b;return c.get(N.projectId)==="scratch"?nR({kind:"scratch",canonicalPath:l.get(N.projectId)??"",conversationId:N.id})??void 0:N.worktree?.path??l.get(b.projectId)},d=e.skills.filter(b=>b.enabled!==!1).map(b=>({name:`/skill:${b.name}`,description:b.description})),m=b=>{const N=u2(b.occupancy,b.contextWindow);return{id:b.id,title:b.parentId&&b.coworkerName||b.title,projectName:a.get(b.projectId)??"",projectId:b.projectId,...u(b)?{cwd:u(b)}:{},status:b.spawning?"running":b.status,updatedAt:Oj(b),...b.parentId?{parentId:b.parentId}:{},...b.pinned===!0?{pinned:!0}:{},...b.archived===!0?{archived:!0}:{},...b.muted===!0?{muted:!0}:{},...b.lastProviderId?{providerId:b.lastProviderId}:{},...b.lastModelId?{modelId:b.lastModelId}:{},...b.reasoningEnabled!==void 0?{reasoningEnabled:b.reasoningEnabled}:{},...b.thinkingLevel?{thinkingLevel:b.thinkingLevel}:{},...b.unread===!0?{unread:!0}:{},...b.pendingAsks&&b.pendingAsks.length>0?{pendingAskCount:b.pendingAsks.length}:{},...b.pendingApprovals&&b.pendingApprovals.length>0?{pendingApprovalCount:b.pendingApprovals.length}:{},...b.queuedMessages?.length?{queued:b.queuedMessages.map(C=>({id:C.id,text:C.text,...C.images?.length?{hasImages:!0}:{}}))}:{},...b.goal?{goal:{text:b.goal.text,status:b.goal.status,...b.goal.note?{note:b.goal.note}:{},autoTurns:b.goal.autoTurns}}:{},...d.length?{slashCommands:d}:{},...N?{context:N}:{},...b.usageTotals?{usageTotals:b.usageTotals}:{}}},h=t.order.map(b=>t.conversations[b]).filter(b=>!!b),p=new Set(t.order),g=Object.values(t.conversations).filter(b=>!!(b?.parentId&&p.has(b.parentId))),x=[...h,...g].map(m),y=oJ(e.projects,e.scratchSessionsEnabled),j=x.filter(b=>!y.has(b.projectId)),w=sJ(hw(),Lo.getState().snapshot,e.virtualModels);return{catalog:j,pinnedOrder:nr(ym),projects:r.map(b=>({...ZQ(b),...o.has(b.id)?{archived:!0}:{}})),projectGroups:e.projectGroups,providers:w.entries,providersSettled:w.settled,projectPaths:e.projects.map(b=>({id:b.id,path:b.path})),theme:e.theme,terminal:yw(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 lJ(e){return tJ({catalog:eJ(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 cJ(){return X.persist.hasHydrated()&&xe.persist.hasHydrated()}function gr(){ec&&clearTimeout(ec),ec=setTimeout(()=>{if(ec=null,!kr()||!cJ())return;const e=aJ(),t=lJ(e);t!==sh&&(sh=t,window.electronAPI.pair.pushCatalog(e))},iJ)}function dJ(){rw||(rw=!0,gr(),X.persist.onFinishHydration(gr),xe.persist.onFinishHydration(gr),X.subscribe((e,t)=>{(e.conversations!==t.conversations||e.order!==t.order)&&gr()}),Lo.subscribe((e,t)=>{e.snapshot!==t.snapshot&&gr()}),eR.subscribe((e,t)=>{e.snapshot!==t.snapshot&&gr()}),xe.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)&&gr()}),oN(gr),tR(e=>{e&&(sh=null,gr())}),window.electronAPI.pair.onResumeSession(e=>{kg(e),kr()&&(X.getState().markConversationRead(e),X.getState().resumeConversation(e))}),window.electronAPI.pair.onSessionCreated(e=>{kg(e.sessionId),kr()&&X.getState().adoptPairSession(e)}),window.electronAPI.pair.onSessionConfig(e=>{if(!kr())return;const t=X.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(!kr())return;const t=X.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 uJ=3e4;async function fJ(e,t=Date.now()){const{order:s,conversations:r,activeId:o}=X.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:Oj(m)}]}),a=sR(i,e,t),l=X.getState();for(const d of a)l.removeConversation(d);const c=Date.now()+uJ,u=()=>a.filter(d=>X.getState().conversations[d]);for(;u().length>0&&Date.now()<c;)await new Promise(d=>setTimeout(d,200));return a.length-u().length}const mJ=f.lazy(()=>Cd(()=>import("./SidePanel-CL40W2RY.js"),__vite__mapDeps([7,1,2,8,4,3,6,9]),import.meta.url).then(e=>({default:e.SidePanel}))),hJ=e=>{const t=QR(e);return t.length>0?t:zj(e)},ow="enso-sidebar-width",iw="enso-sidebar-collapsed";function tc(){const e=X.getState(),s=(e.activeId?e.conversations[e.activeId]:null)?.projectId??xe.getState().projects[0]?.id;s&&e.newConversation(s)}const nc="no-drag flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",aw=200,lw=420;function pJ(){const e=xe(me=>me.onboarded),t=f.useSyncExternalStore(me=>xe.persist?.onFinishHydration?.(me)??(()=>{}),()=>xe.persist?.hasHydrated?.()??!0);rR(),SQ(),kQ(),RQ(),OQ(),NQ();const[s,r]=f.useState(!1),[o,i]=f.useState(null);FQ();const[a,l]=f.useState(()=>{const me=Number(localStorage.getItem(ow));return Number.isFinite(me)&&me>=aw?Math.min(me,lw):280}),[c,u]=f.useState(()=>localStorage.getItem(iw)==="1"),d=wi(),m=oR(),[h,p]=f.useState(!1),g=f.useCallback(()=>p(!1),[]);f.useEffect(()=>{d||p(!1)},[d]),f.useEffect(()=>X.subscribe((me,Ve)=>{me.activeId!==Ve.activeId&&p(!1)}),[]);const{t:x}=z(),y=xe(me=>me.chatWide),j=X(me=>me.activeId),w=yh(j),b=os(me=>me.uiByConversation[j??""]?.width??me.lastWidth),N=os(me=>me.fullscreen),C=os(me=>me.toggleOpen),E=ie(me=>me.panelOpen),T=ie(me=>me.togglePanel);f.useEffect(()=>{N&&!w&&os.getState().setFullscreen(!1)},[w,N]),f.useEffect(()=>iR(),[]),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(me=>{aR().finally(()=>{window.electronAPI.app.respondFlushPersist(me)})}),[]);const k=me=>{const Ve=o;Ve&&(i(null),window.electronAPI.app.respondCloseRequest(Ve,{action:me}))},L=f.useCallback(()=>{lR(window.innerWidth)?p(me=>!me):u(me=>!me)},[]),F=f.useCallback(()=>{window.electronAPI.env.platform==="darwin"&&window.setTimeout(()=>window.electronAPI.window.refreshDragRegions(),400)},[]),A=f.useCallback(()=>{L(),F()},[L,F]);f.useEffect(()=>zQ(A),[A]),f.useEffect(()=>window.electronAPI.window.onToggleSidebar(A),[A]);const[D,M]=f.useState(!1),H=f.useRef(null);f.useEffect(()=>{localStorage.setItem(ow,String(a))},[a]),f.useEffect(()=>{localStorage.setItem(iw,c?"1":"0")},[c]),f.useEffect(()=>window.electronAPI.resources.onSessionsCleanRequest(({requestId:me,request:Ve})=>{fJ(Ve).catch(()=>0).then(at=>window.electronAPI.resources.sessionsCleanDone(me,at))}),[]),f.useEffect(()=>{dJ()},[]),f.useEffect(()=>{const me=window.electronAPI.remote;return me&&!me.nativePlatform?void 0:ju.getState().bind()},[]);const G=ju(me=>me.pairDialogOpen),U=DF(),J=xe(me=>me.botModeEnabled),$=xe(me=>me.headerSessionTabs),oe=Ar(me=>me.mode);f.useEffect(()=>{const me=xe.persist?.hasHydrated?.()??!0;oe==="bot"&&me&&!J&&Ar.getState().setMode("code")},[oe,J]),f.useEffect(()=>{if(!J)return;const me=ie.getState().bind(),Ve=window.electronAPI.bots.onEvent(at=>{at.kind==="open"&&OF(at)});return()=>{me(),Ve()}},[J]);const Ne=xe(me=>me.secretaryEnabled),ce=jt(me=>me.welcomeOpen),ne=Po(me=>me.open);f.useEffect(()=>Ne?jt.getState().bind():void 0,[Ne]),f.useEffect(()=>window.electronAPI.agent.onFocusSession(me=>{X.getState().conversations[me]&&Rp()}),[]);const Y=f.useCallback(me=>{l(Ve=>Math.min(lw,Math.max(aw,Ve+me)))},[]),pe=xe(me=>me.keybindings);f.useEffect(()=>{const me=Mr(pe),Ve=Fe=>{const tt=X.getState(),je=tt.activeId?tt.conversations[tt.activeId]:null;if(!je)return;const Je=[void 0,...je.coworkerIds??[]];if(Je.length<=1)return;const rt=Je.indexOf(je.activeTabId);tt.selectTab(je.id,Je[(rt+Fe+Je.length)%Je.length])},at=Fe=>{const tt=Pc(Fe);if(!tt)return;if(tt===me["toggle-app-mode"]){if(!xe.getState().botModeEnabled)return;Fe.preventDefault();const rt=Ar.getState();rt.setMode(rt.mode==="bot"?"code":"bot");return}const je=hv();if(je&&tt===me["toggle-side-panel"]){Fe.preventDefault(),ie.getState().togglePanel();return}if(je&&tt===me["search-workspace"]){Fe.preventDefault(),ie.getState().setSearchOpen(!0);return}if(!(je&&["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(Je=>tt===me[Je]))){if(tt===me["toggle-sidebar"]){if(Fe.preventDefault(),xR(Fe,tt))return;A()}else if(tt===me["open-settings"])Fe.preventDefault(),window.electronAPI.window.openSettings();else if(tt===me["open-secretary"])xe.getState().secretaryEnabled&&(Fe.preventDefault(),Sc());else if(tt===me["new-conversation"])Fe.preventDefault(),tc();else if(tt===me["new-side-tab"])Fe.preventDefault(),gR(Fe.target)?vR():tc();else if(tt===me["new-btw-tab"])Fe.preventDefault(),bR();else if(tt===me["next-tab"])Fe.preventDefault(),Ve(1);else if(tt===me["prev-tab"])Fe.preventDefault(),Ve(-1);else if(tt===me["toggle-side-panel"])Fe.preventDefault(),os.getState().toggleOpen();else if(tt===me["toggle-side-panel-fullscreen"])Fe.preventDefault(),os.getState().toggleFullscreen();else if(tt===me["close-side-tab"])Fe.preventDefault(),yR();else if(tt===me["focus-composer"])Fe.preventDefault(),Ei();else if(tt===me["find-in-chat"])Fe.preventDefault(),UC();else if(tt===me["search-workspace"])Fe.preventDefault(),r(!0);else if(!je){const Je=wR(bj(),pe,me).byBinding.get(tt);if(!Je)return;Fe.preventDefault();const rt=X.getState(),K=rt.activeId?rt.conversations[rt.activeId]:null;zh(Je,K?K.activeTabId??K.id:null).then(Q=>{Q&&Ie({type:"error",title:Je.title,description:Q})})}}};return window.addEventListener("keydown",at),()=>window.removeEventListener("keydown",at)},[pe,A]),f.useEffect(()=>{if(!w||!N)return;const me=Ve=>{Ve.key==="Escape"&&(hv()||(Ve.preventDefault(),os.getState().setFullscreen(!1)))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[w,N]);const ge=VR($R(Kh,{activationConstraint:{distance:6}})),we=Fh(),V=we!=="mobile"&&!U,W=f.useCallback(me=>{const Ve=H.current;if(!Ve)return;const at=getComputedStyle(Ve),Fe=Ve.clientWidth-parseFloat(at.paddingLeft)-parseFloat(at.paddingRight);os.getState().nudgeWidth(-me,Fe,V?cR:fj)},[V]),B=J?n.jsx(TG,{}):null,te=V&&(we==="mac"||we==="windows"||we==="web"),Z=te&&w&&!d&&!U,ue=$&&V&&!J&&!(Z&&N)?n.jsx(tF,{onNew:tc}):null,fe=n.jsx("button",{type:"button",className:_("flex items-center justify-center rounded-md transition-colors hover:bg-accent/50",d?"h-9 w-9":V?nc:"h-7 w-7",(U?E:w)?"text-foreground":"text-muted-foreground"),onClick:U?T:C,"aria-label":x("Toggle side panel"),title:x("Toggle side panel"),children:n.jsx(z_,{className:"h-4 w-4"})}),Ce=n.jsx("button",{type:"button",className:_("flex h-7 w-7 items-center justify-center rounded-md transition-colors hover:bg-accent/50",y?"text-foreground":"text-muted-foreground",d&&"hidden"),onClick:()=>xe.getState().setChatWide(!y),"aria-label":x(y?"Use reading width":"Use full chat width"),title:x(y?"Use reading width":"Use full chat width"),children:y?n.jsx(t_,{className:"h-4 w-4"}):n.jsx(lB,{className:"h-4 w-4"})}),de=n.jsxs(n.Fragment,{children:[Ce,fe]}),Ee=V?{trailing:Ce}:null;return n.jsxs("div",{"data-enso":"canvas",className:_("relative isolate flex flex-col",d?"h-dvh":"h-screen"),children:[n.jsx(dR,{}),n.jsx(uR,{}),n.jsx(_B,{}),n.jsx(zF,{}),n.jsx(fR,{}),we!=="mobile"?n.jsx(Ng,{leading:n.jsxs("div",{className:"flex items-center gap-0.5",children:[n.jsx("div",{className:_(we!=="mac"&&"flex justify-center",we!=="mac"&&(V?"w-[48px]":"w-12")),children:n.jsx("button",{type:"button","data-enso":"sidebar-toggle",className:nc,onClick:A,title:x(c?"Expand sidebar":"Collapse sidebar"),children:c?n.jsx(Gk,{className:"h-4 w-4"}):n.jsx(Tp,{className:"h-4 w-4"})})}),V&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button","data-enso":"search-button",className:nc,onClick:()=>r(!0),title:x("Search anything"),children:n.jsx(lr,{className:"h-4 w-4"})}),n.jsx("button",{type:"button","data-enso":"new-session",className:nc,onClick:tc,title:x("New conversation"),children:n.jsx(J_,{className:"h-4 w-4"})})]})]}),centered:(Z&&N?null:B)??void 0,middle:ue,className:_(we!=="mac"&&"pl-0",V&&"border-b-0",V&&"bg-transparent",V&&we==="mac"&&"pr-4"),actions:V?Z?void 0:fe:de}):n.jsx(Ng,{title:"EnsoCode",centered:B??void 0,leading:d&&!U?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(E_,{className:"h-5 w-5"})}),!B&&n.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"EnsoCode"})]}):void 0,actions:de}),!V&&n.jsx(gv,{}),!V&&n.jsx(vv,{}),!V&&n.jsx(bv,{}),n.jsx("div",{className:"flex min-h-0 flex-1",children:U?n.jsx(kG,{sidebarWidth:a,collapsed:c,onToggleCollapse:A,onResize:Y}):n.jsxs(HM,{sensors:ge,collisionDetection:hJ,children:[d?n.jsxs(n.Fragment,{children:[n.jsx(la,{children:h&&n.jsx(ks.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(ks.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:di,inert:!h,children:n.jsx(_y,{width:Math.min(320,Math.round(m*.85)),collapsed:!1,onToggleCollapse:g,onOpenSearch:()=>r(!0),onNavigate:g})})]}):n.jsxs(n.Fragment,{children:[n.jsx(_y,{width:c?void 0:a,collapsed:c,onToggleCollapse:A,onOpenSearch:()=>r(!0)}),!c&&n.jsx(id,{edge:V,onResize:Y})]}),n.jsxs("div",{ref:H,className:_("relative flex min-h-0 min-w-0 flex-1",te?"overflow-x-clip":"overflow-hidden",V&&"-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",V&&"overflow-hidden rounded-[10px] shadow-surface",Z&&"rounded-r-none"),style:w&&N?{visibility:"hidden",transition:`visibility 0s ${ud.duration}s`}:void 0,children:[n.jsx(KQ,{}),n.jsx(zB,{hidden:Ne&&ce||ne,children:n.jsx(mR.Provider,{value:Ee,children:n.jsx(cY,{})})}),V&&n.jsx(gv,{}),V&&n.jsx(vv,{}),V&&n.jsx(bv,{}),Ne&&ce&&n.jsx(uQ,{}),ne&&n.jsx(n8,{})]}),w&&!N&&!d&&n.jsx(id,{gap:V&&!Z,onResize:W,onResizingChange:M}),n.jsx(f.Suspense,{fallback:null,children:n.jsx(mJ,{width:b,resizing:D,card:V,titleRow:te})})]})]})}),t&&!e&&!window.electronAPI.remote&&n.jsx($X,{}),n.jsx(dQ,{open:s,onOpenChange:r}),n.jsx(jQ,{}),n.jsx(hR,{open:G,onOpenChange:ju.getState().setPairDialogOpen}),n.jsx(ih,{open:o!==null,onOpenChange:me=>{!me&&o&&k("cancel")},children:n.jsxs(ah,{className:"sm:max-w-sm",children:[n.jsxs(lh,{children:[n.jsx(ch,{className:"text-base",children:x("Confirm exit")}),n.jsx(dh,{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(uh,{variant:"bare",children:[n.jsx(pR,{render:n.jsx(he,{variant:"outline",size:"sm"}),children:x("Cancel")}),n.jsx(he,{size:"sm",onClick:()=>k("tray"),children:x("Minimize to tray")}),n.jsx(he,{variant:"destructive",size:"sm",onClick:()=>k("quit"),children:x("Exit")})]})]})}),n.jsx(YF,{})]})}function xJ(e){return new Worker(""+new URL("worker-DsKBD11i.js",import.meta.url).href,{type:"module",name:e?.name})}const gJ={workerFactory:()=>new xJ,poolSize:2},vJ={theme:NR,langs:[...kR],preferredHighlighter:"shiki-js"};function bJ({children:e}){return n.jsx(jR,{poolOptions:gJ,highlighterOptions:vJ,children:e})}function cw({conversations:e,activeId:t}){const s=document.documentElement.dataset,r=IY(e),o=N2(t?e[t]:void 0,e);s.ensoActivity!==r&&(s.ensoActivity=r),s.ensoSession!==o&&(s.ensoSession=o)}function yJ(){cw(X.getState()),X.subscribe((e,t)=>{(e.conversations!==t.conversations||e.activeId!==t.activeId)&&cw(e)})}SR();yJ();CR();zw();IR.createRoot(document.getElementById("root")).render(n.jsx(f.StrictMode,{children:n.jsx(bJ,{children:n.jsx(pJ,{})})}));export{id as $,Ti as A,qK as B,Hd as C,$K as D,kC as E,Cq as F,TJ as G,tN as H,Ip as I,Ei as J,_p as K,Uk as L,bm as M,Wd as N,O7 as O,Hs as P,c7 as Q,U_ as R,Ud as S,Bq as T,Pa as U,d7 as V,B7 as W,PJ as X,RJ as Y,MJ as Z,dv as _,Op as a,P4 as a0,s1 as a1,AJ as a2,ks as a3,i7 as a4,wB as a5,NJ as a6,h_ as a7,Ns as a8,H7 as a9,z_ as aa,EJ as ab,Mi as b,jt as c,sV as d,Np as e,L$ as f,nS as g,Vp as h,od as i,Hp as j,Bp as k,Va as l,R$ as m,WB as n,iV as o,Cy as p,vX as q,SJ as r,Dp as s,io as t,Ri as u,CJ as v,IJ as w,YC as x,_r as y,NC as z};